Skip to content

Commit

Permalink
feat: 添加TreeNode节点
Browse files Browse the repository at this point in the history
  • Loading branch information
TheBeard30 committed Feb 29, 2024
1 parent fe3d62c commit 17a80b6
Show file tree
Hide file tree
Showing 11 changed files with 1,047 additions and 108 deletions.
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
"@angular/platform-browser": "^17.0.0",
"@angular/platform-browser-dynamic": "^17.0.0",
"@angular/router": "^17.0.0",
"@formily/reactive": "^2.3.1",
"jsonpath-plus": "^8.0.0",
"lodash": "^4.17.21",
"rxjs": "~7.8.0",
Expand All @@ -37,6 +38,7 @@
"@angular/cli": "^17.0.7",
"@angular/compiler-cli": "^17.0.0",
"@types/jasmine": "~5.1.0",
"@types/lodash": "^4.14.202",
"@typescript-eslint/eslint-plugin": "6.19.0",
"@typescript-eslint/parser": "6.19.0",
"eslint": "^8.56.0",
Expand Down
24 changes: 24 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 5 additions & 5 deletions src/app/components/widgets/text/text.widget.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Component, Input, OnChanges, SimpleChanges } from '@angular/core';
import { RegistryService } from '@/app/services/registry.service';
import { GlobalRegistry } from '@/app/core/registry';
import { IDesignerMiniLocales } from '@/app/core/types';

@Component({
Expand All @@ -12,7 +12,7 @@ export class TextWidget implements OnChanges {

currentText: string;

constructor(private registry: RegistryService) {}
constructor() {}

ngOnChanges(changes: SimpleChanges): void {
if (changes.title && changes.title.currentValue) {
Expand All @@ -22,13 +22,13 @@ export class TextWidget implements OnChanges {

fixLocaleText(text: string | IDesignerMiniLocales) {
if (typeof text === 'string') {
this.currentText = this.registry.getDesignerMessage(text);
this.currentText = GlobalRegistry.getDesignerMessage(text);
} else {
const takeLocale = (message: string | IDesignerMiniLocales) => {
if (typeof message == 'string') return message;
if (typeof message == 'object') {
const lang = this.registry.getDesignerLanguage();
for (let key in message) {
const lang = GlobalRegistry.getDesignerLanguage();
for (const key in message) {
if (key.toLocaleLowerCase() === lang) return message[key];
}
return '';
Expand Down
9 changes: 8 additions & 1 deletion src/app/core/externals.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { IResource, IResourceCreator } from './types';
import { IBehavior, IBehaviorHost, IResource, IResourceCreator } from './types';

export const createDesigner = () => {};

Expand All @@ -18,3 +18,10 @@ export const createResource = (...sources: IResourceCreator[]): IResource[] => {
export const isResourceList = (val: any): val is IResource[] => Array.isArray(val) && val.every(isResource);

export const isResource = (val: any): val is IResource => val?.node;

export const isBehavior = (val: any): val is IBehavior =>
val?.name || val?.selector || val?.extends || val?.designerProps || val?.designerLocales;

export const isBehaviorHost = (val: any): val is IBehaviorHost => val?.Behavior && isBehaviorList(val.Behavior);

export const isBehaviorList = (val: any): val is IBehavior[] => Array.isArray(val) && val.every(isBehavior);
34 changes: 34 additions & 0 deletions src/app/core/internals.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import { isPlainObj } from '../shared/types';
import _ from 'lodash';
import { globalThisPolyfill } from '../shared/globalThisPolyfill';

export const lowerSnake = (str: string) => {
return String(str).replace(/\s+/g, '_').toLocaleLowerCase();
};

export const mergeLocales = (target: any, source: any) => {
if (isPlainObj(target) && isPlainObj(source)) {
_.each(source, function (value, key) {
const token = lowerSnake(key);
const messages = mergeLocales(target[key] || target[token], value);
target[token] = messages;
});
return target;
} else if (isPlainObj(source)) {
const result = Array.isArray(source) ? [] : {};
_.each(source, function (value, key) {
const messages = mergeLocales(undefined, value);
result[lowerSnake(key)] = messages;
});
return result;
}
return source;
};

export const getBrowserLanguage = () => {
/* istanbul ignore next */
if (!globalThisPolyfill.navigator) {
return 'en';
}
return globalThisPolyfill.navigator['browserlanguage'] || globalThisPolyfill.navigator?.language || 'en';
};
Loading

0 comments on commit 17a80b6

Please sign in to comment.