GeezerVison is showing github.com — feat: add some features · webstager/lowcode-engine@18d1a4f
File treeExpand file treeCollapse file tree Open diff view settings editor-skeleton/src/layouts plugin-outline-pane/src/views
Expand file treeCollapse file tree Open diff view settings Collapse file Copy file name to clipboardExpand all lines: packages/designer/src/builtin-simulator/host.ts +5-5Lines changed: 5 additions & 5 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -1098,7 +1098,9 @@ export class BuiltinSimulatorHost implements ISimulatorHost<BuiltinSimulatorProp | 1098 | 1098 |
| 1099 | 1099 | // fix target : 浏览器事件响应目标 | 1100 | 1100 | if (!e.target || notMyEvent) { | 1101 | | - e.target = this.contentDocument?.elementFromPoint(e.canvasX!, e.canvasY!); | | 1101 | + if (!isNaN(e.canvasX!) && !isNaN(e.canvasY!)) { | | 1102 | + e.target = this.contentDocument?.elementFromPoint(e.canvasX!, e.canvasY!); | | 1103 | + } | 1102 | 1104 | } | 1103 | 1105 |
| 1104 | 1106 | // 事件已订正 | @@ -1156,14 +1158,12 @@ export class BuiltinSimulatorHost implements ISimulatorHost<BuiltinSimulatorProp | 1156 | 1158 | return null; | 1157 | 1159 | } | 1158 | 1160 | const dropContainer = this.getDropContainer(e); | 1159 | | - const canDropIn = dropContainer?.container?.componentMeta?.prototype?.options?.canDropIn; | | 1161 | + const childWhitelist = dropContainer?.container?.componentMeta?.childWhitelist; | 1160 | 1162 | const lockedNode = getClosestNode(dropContainer?.container as Node, (node) => node.isLocked); | 1161 | 1163 | if (lockedNode) return null; | 1162 | 1164 | if ( | 1163 | 1165 | !dropContainer || | 1164 | | - canDropIn === false || | 1165 | | - // too dirty | 1166 | | - (nodes && typeof canDropIn === 'function' && !canDropIn(operationalNodes[0])) | | 1166 | + (nodes && typeof childWhitelist === 'function' && !childWhitelist(operationalNodes[0])) | 1167 | 1167 | ) { | 1168 | 1168 | return null; | 1169 | 1169 | } | |
Collapse file Copy file name to clipboardExpand all lines: packages/designer/src/designer/setting/setting-top-entry.ts -2Lines changed: 0 additions & 2 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -226,13 +226,11 @@ export class SettingTopEntry implements SettingEntry { | 226 | 226 | } | 227 | 227 |
| 228 | 228 |
| 229 | | - // ==== compatibles for vision ===== | 230 | 229 | getProp(propName: string | number) { | 231 | 230 | return this.get(propName); | 232 | 231 | } | 233 | 232 |
| 234 | 233 | // ==== copy some Node api ===== | 235 | | - // `VE.Node.getProps` | 236 | 234 | getStatus() { | 237 | 235 |
| 238 | 236 | } | |
Collapse file Copy file name to clipboardExpand all lines: packages/designer/src/document/document-model.ts +1Lines changed: 1 addition & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -642,6 +642,7 @@ export class DocumentModel { | 642 | 642 | this.rootNodeVisitorMap[visitorName] = visitorResult; | 643 | 643 | } catch (e) { | 644 | 644 | console.error('RootNodeVisitor is not valid.'); | | 645 | + console.error(e); | 645 | 646 | } | 646 | 647 | return visitorResult; | 647 | 648 | } | |
Collapse file Copy file name to clipboardExpand all lines: packages/designer/src/document/node/props/prop.ts +1Lines changed: 1 addition & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -316,6 +316,7 @@ export class Prop implements IPropParent { | 316 | 316 | const slotSchema: SlotSchema = { | 317 | 317 | componentName: 'Slot', | 318 | 318 | title: data.title, | | 319 | + id: data.id, | 319 | 320 | name: data.name, | 320 | 321 | params: data.params, | 321 | 322 | children: data.value, | |
Collapse file Copy file name to clipboardExpand all lines: packages/designer/src/plugin/plugin-context.ts +7-10Lines changed: 7 additions & 10 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -21,6 +21,7 @@ import { | 21 | 21 | PreferenceValueType, | 22 | 22 | IPluginPreferenceMananger, | 23 | 23 | } from './plugin-types'; | | 24 | +import { isValidPreferenceKey } from './plugin-utils'; | 24 | 25 |
| 25 | 26 | export default class PluginContext implements ILowCodePluginContext { | 26 | 27 | private readonly [editorSymbol]: Editor; | @@ -53,26 +54,22 @@ export default class PluginContext implements ILowCodePluginContext { | 53 | 54 | this.plugins = plugins; | 54 | 55 | this.event = new Event(editor, { prefix: 'common' }); | 55 | 56 | this.logger = getLogger({ level: 'warn', bizName: `designer:plugin:${pluginName}` }); | | 57 | + | | 58 | + const enhancePluginContextHook = engineConfig.get('enhancePluginContextHook'); | | 59 | + if (enhancePluginContextHook) { | | 60 | + enhancePluginContextHook(this); | | 61 | + } | 56 | 62 | } | 57 | 63 |
| 58 | 64 | setPreference( | 59 | 65 | pluginName: string, | 60 | 66 | preferenceDeclaration: ILowCodePluginPreferenceDeclaration, | 61 | 67 | ): void { | 62 | | - const isValidPreferenceKey = (key: string): boolean => { | 63 | | - if (!preferenceDeclaration || !Array.isArray(preferenceDeclaration.properties)) { | 64 | | - return false; | 65 | | - } | 66 | | - return preferenceDeclaration.properties.some((prop) => { | 67 | | - return prop.key === key; | 68 | | - }); | 69 | | - }; | 70 | | - | 71 | 68 | const getPreferenceValue = ( | 72 | 69 | key: string, | 73 | 70 | defaultValue?: PreferenceValueType, | 74 | 71 | ): PreferenceValueType | undefined => { | 75 | | - if (!isValidPreferenceKey(key)) { | | 72 | + if (!isValidPreferenceKey(key, preferenceDeclaration)) { | 76 | 73 | return undefined; | 77 | 74 | } | 78 | 75 | const pluginPreference = this.plugins.getPluginPreference(pluginName) || {}; | |
Collapse file Copy file name to clipboardExpand all lines: packages/designer/src/plugin/plugin-manager.ts +25-7Lines changed: 25 additions & 7 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -11,7 +11,9 @@ import { | 11 | 11 | ILowCodePluginConfigMeta, | 12 | 12 | PluginPreference, | 13 | 13 | ILowCodePluginPreferenceDeclaration, | | 14 | + isLowCodeRegisterOptions, | 14 | 15 | } from './plugin-types'; | | 16 | +import { filterValidOptions } from './plugin-utils'; | 15 | 17 | import { LowCodePlugin } from './plugin'; | 16 | 18 | import LowCodePluginContext from './plugin-context'; | 17 | 19 | import { invariant } from '../utils'; | @@ -41,15 +43,30 @@ export class LowCodePluginManager implements ILowCodePluginManager { | 41 | 43 | return semverSatisfies(engineVersion, versionExp); | 42 | 44 | } | 43 | 45 |
| | 46 | + /** | | 47 | + * register a plugin | | 48 | + * @param pluginConfigCreator - a creator function which returns the plugin config | | 49 | + * @param options - the plugin options | | 50 | + * @param registerOptions - the plugin register options | | 51 | + */ | 44 | 52 | async register( | 45 | | - pluginConfigCreator: (ctx: ILowCodePluginContext) => ILowCodePluginConfig, | 46 | | - options?: ILowCodeRegisterOptions, | | 53 | + pluginConfigCreator: (ctx: ILowCodePluginContext, options: any) => ILowCodePluginConfig, | | 54 | + options?: any, | | 55 | + registerOptions?: ILowCodeRegisterOptions, | 47 | 56 | ): Promise<void> { | 48 | | - const { pluginName, meta = {} } = pluginConfigCreator as any; | | 57 | + // registerOptions maybe in the second place | | 58 | + if (isLowCodeRegisterOptions(options)) { | | 59 | + registerOptions = options; | | 60 | + options = {}; | | 61 | + } | | 62 | + let { pluginName, meta = {} } = pluginConfigCreator as any; | 49 | 63 | const { preferenceDeclaration, engines } = meta as ILowCodePluginConfigMeta; | 50 | 64 | const ctx = this._getLowCodePluginContext({ pluginName }); | 51 | | - const config = pluginConfigCreator(ctx); | 52 | | - | | 65 | + const customFilterValidOptions = engineConfig.get('customPluginFilterOptions', filterValidOptions); | | 66 | + const config = pluginConfigCreator(ctx, customFilterValidOptions(options, preferenceDeclaration!)); | | 67 | + // compat the legacy way to declare pluginName | | 68 | + // @ts-ignore | | 69 | + pluginName = pluginName || config.name; | 53 | 70 | invariant( | 54 | 71 | pluginName, | 55 | 72 | 'pluginConfigCreator.pluginName required', | @@ -58,7 +75,7 @@ export class LowCodePluginManager implements ILowCodePluginManager { | 58 | 75 |
| 59 | 76 | ctx.setPreference(pluginName, (preferenceDeclaration as ILowCodePluginPreferenceDeclaration)); | 60 | 77 |
| 61 | | - const allowOverride = options?.override === true; | | 78 | + const allowOverride = registerOptions?.override === true; | 62 | 79 |
| 63 | 80 | if (this.pluginsMap.has(pluginName)) { | 64 | 81 | if (!allowOverride) { | @@ -83,7 +100,8 @@ export class LowCodePluginManager implements ILowCodePluginManager { | 83 | 100 | } | 84 | 101 |
| 85 | 102 | const plugin = new LowCodePlugin(pluginName, this, config, meta); | 86 | | - if (options?.autoInit) { | | 103 | + // support initialization of those plugins which registered after normal initialization by plugin-manager | | 104 | + if (registerOptions?.autoInit) { | 87 | 105 | await plugin.init(); | 88 | 106 | } | 89 | 107 | this.plugins.push(plugin); | |
Collapse file Copy file name to clipboardExpand all lines: packages/designer/src/plugin/plugin-types.ts +5Lines changed: 5 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -48,6 +48,7 @@ export interface ILowCodePluginPreferenceDeclaration { | 48 | 48 | export type PluginPreference = Map<string, Record<string, PreferenceValueType>>; | 49 | 49 |
| 50 | 50 | export interface ILowCodePluginConfig { | | 51 | + dep?: string | string[]; | 51 | 52 | init?(): void; | 52 | 53 | destroy?(): void; | 53 | 54 | exports?(): any; | @@ -130,6 +131,10 @@ export interface ILowCodePluginManagerCore { | 130 | 131 |
| 131 | 132 | export type ILowCodePluginManager = ILowCodePluginManagerCore & ILowCodePluginManagerPluginAccessor; | 132 | 133 |
| | 134 | +export function isLowCodeRegisterOptions(opts: any): opts is ILowCodeRegisterOptions { | | 135 | + return opts && ('autoInit' in opts || 'override' in opts); | | 136 | +} | | 137 | + | 133 | 138 | export interface ILowCodeRegisterOptions { | 134 | 139 | autoInit?: boolean; | 135 | 140 | // allow overriding existing plugin with same name when override === true | |
Collapse file Copy file name to clipboard +28Lines changed: 28 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
| | 1 | +import type { ILowCodePluginPreferenceDeclaration } from './plugin-types'; | | 2 | +import { isPlainObject } from 'lodash'; | | 3 | + | | 4 | +export function isValidPreferenceKey( | | 5 | + key: string, | | 6 | + preferenceDeclaration: ILowCodePluginPreferenceDeclaration, | | 7 | +): boolean { | | 8 | + if (!preferenceDeclaration || !Array.isArray(preferenceDeclaration.properties)) { | | 9 | + return false; | | 10 | + } | | 11 | + return preferenceDeclaration.properties.some((prop) => { | | 12 | + return prop.key === key; | | 13 | + }); | | 14 | +} | | 15 | + | | 16 | +export function filterValidOptions(opts: any, preferenceDeclaration: ILowCodePluginPreferenceDeclaration) { | | 17 | + if (!opts || !isPlainObject(opts)) return opts; | | 18 | + const filteredOpts = {} as any; | | 19 | + Object.keys(opts).forEach(key => { | | 20 | + if (isValidPreferenceKey(key, preferenceDeclaration)) { | | 21 | + const v = opts[key]; | | 22 | + if (v !== undefined && v !== null) { | | 23 | + filteredOpts[key] = v; | | 24 | + } | | 25 | + } | | 26 | + }); | | 27 | + return filteredOpts; | | 28 | +} |
Collapse file Copy file name to clipboardExpand all lines: packages/designer/src/plugin/plugin.ts +5-1Lines changed: 5 additions & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
@@ -50,7 +50,11 @@ export class LowCodePlugin implements ILowCodePlugin { | 50 | 50 | if (typeof this.meta.dependencies === 'string') { | 51 | 51 | return [this.meta.dependencies]; | 52 | 52 | } | 53 | | - return this.meta.dependencies || []; | | 53 | + // compat legacy way to declare dependencies | | 54 | + if (typeof this.config.dep === 'string') { | | 55 | + return [this.config.dep]; | | 56 | + } | | 57 | + return this.meta.dependencies || this.config.dep || []; | 54 | 58 | } | 55 | 59 |
| 56 | 60 | get disabled() { | |
Collapse file Copy file name to clipboardExpand all lines: packages/editor-core/src/editor.ts +3Lines changed: 3 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -11,6 +11,7 @@ import { | 11 | 11 | RemoteComponentDescription, | 12 | 12 | GlobalEvent, | 13 | 13 | } from '@alilc/lowcode-types'; | | 14 | +import { engineConfig } from './config'; | 14 | 15 | import { globalLocale } from './intl'; | 15 | 16 | import * as utils from './utils'; | 16 | 17 | import Preference from './utils/preference'; | @@ -71,6 +72,8 @@ export class Editor extends (EventEmitter as any) implements IEditor { | 71 | 72 | this.setAssets(data); | 72 | 73 | return; | 73 | 74 | } | | 75 | + // store the data to engineConfig while invoking editor.set() | | 76 | + engineConfig.set(key as any, data); | 74 | 77 | this.context.set(key, data); | 75 | 78 | this.notifyGot(key); | 76 | 79 | } | |
|