Skip to content

Commit 0c6bca3

Browse files
authored
Merge pull request alibaba#418 from alibaba/feat/vision-polyfill
feat: add some features
2 parents f30db20 + 18d1a4f commit 0c6bca3

File tree

29 files changed

+320
-40
lines changed

29 files changed

+320
-40
lines changed

packages/designer/src/builtin-simulator/host.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1098,7 +1098,9 @@ export class BuiltinSimulatorHost implements ISimulatorHost<BuiltinSimulatorProp
10981098

10991099
// fix target : 浏览器事件响应目标
11001100
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+
}
11021104
}
11031105

11041106
// 事件已订正
@@ -1156,14 +1158,12 @@ export class BuiltinSimulatorHost implements ISimulatorHost<BuiltinSimulatorProp
11561158
return null;
11571159
}
11581160
const dropContainer = this.getDropContainer(e);
1159-
const canDropIn = dropContainer?.container?.componentMeta?.prototype?.options?.canDropIn;
1161+
const childWhitelist = dropContainer?.container?.componentMeta?.childWhitelist;
11601162
const lockedNode = getClosestNode(dropContainer?.container as Node, (node) => node.isLocked);
11611163
if (lockedNode) return null;
11621164
if (
11631165
!dropContainer ||
1164-
canDropIn === false ||
1165-
// too dirty
1166-
(nodes && typeof canDropIn === 'function' && !canDropIn(operationalNodes[0]))
1166+
(nodes && typeof childWhitelist === 'function' && !childWhitelist(operationalNodes[0]))
11671167
) {
11681168
return null;
11691169
}

packages/designer/src/designer/setting/setting-top-entry.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -226,13 +226,11 @@ export class SettingTopEntry implements SettingEntry {
226226
}
227227

228228

229-
// ==== compatibles for vision =====
230229
getProp(propName: string | number) {
231230
return this.get(propName);
232231
}
233232

234233
// ==== copy some Node api =====
235-
// `VE.Node.getProps`
236234
getStatus() {
237235

238236
}

packages/designer/src/document/document-model.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -642,6 +642,7 @@ export class DocumentModel {
642642
this.rootNodeVisitorMap[visitorName] = visitorResult;
643643
} catch (e) {
644644
console.error('RootNodeVisitor is not valid.');
645+
console.error(e);
645646
}
646647
return visitorResult;
647648
}

packages/designer/src/document/node/props/prop.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -316,6 +316,7 @@ export class Prop implements IPropParent {
316316
const slotSchema: SlotSchema = {
317317
componentName: 'Slot',
318318
title: data.title,
319+
id: data.id,
319320
name: data.name,
320321
params: data.params,
321322
children: data.value,

packages/designer/src/plugin/plugin-context.ts

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import {
2121
PreferenceValueType,
2222
IPluginPreferenceMananger,
2323
} from './plugin-types';
24+
import { isValidPreferenceKey } from './plugin-utils';
2425

2526
export default class PluginContext implements ILowCodePluginContext {
2627
private readonly [editorSymbol]: Editor;
@@ -53,26 +54,22 @@ export default class PluginContext implements ILowCodePluginContext {
5354
this.plugins = plugins;
5455
this.event = new Event(editor, { prefix: 'common' });
5556
this.logger = getLogger({ level: 'warn', bizName: `designer:plugin:${pluginName}` });
57+
58+
const enhancePluginContextHook = engineConfig.get('enhancePluginContextHook');
59+
if (enhancePluginContextHook) {
60+
enhancePluginContextHook(this);
61+
}
5662
}
5763

5864
setPreference(
5965
pluginName: string,
6066
preferenceDeclaration: ILowCodePluginPreferenceDeclaration,
6167
): 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-
7168
const getPreferenceValue = (
7269
key: string,
7370
defaultValue?: PreferenceValueType,
7471
): PreferenceValueType | undefined => {
75-
if (!isValidPreferenceKey(key)) {
72+
if (!isValidPreferenceKey(key, preferenceDeclaration)) {
7673
return undefined;
7774
}
7875
const pluginPreference = this.plugins.getPluginPreference(pluginName) || {};

packages/designer/src/plugin/plugin-manager.ts

Lines changed: 25 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,9 @@ import {
1111
ILowCodePluginConfigMeta,
1212
PluginPreference,
1313
ILowCodePluginPreferenceDeclaration,
14+
isLowCodeRegisterOptions,
1415
} from './plugin-types';
16+
import { filterValidOptions } from './plugin-utils';
1517
import { LowCodePlugin } from './plugin';
1618
import LowCodePluginContext from './plugin-context';
1719
import { invariant } from '../utils';
@@ -41,15 +43,30 @@ export class LowCodePluginManager implements ILowCodePluginManager {
4143
return semverSatisfies(engineVersion, versionExp);
4244
}
4345

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+
*/
4452
async register(
45-
pluginConfigCreator: (ctx: ILowCodePluginContext) => ILowCodePluginConfig,
46-
options?: ILowCodeRegisterOptions,
53+
pluginConfigCreator: (ctx: ILowCodePluginContext, options: any) => ILowCodePluginConfig,
54+
options?: any,
55+
registerOptions?: ILowCodeRegisterOptions,
4756
): 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;
4963
const { preferenceDeclaration, engines } = meta as ILowCodePluginConfigMeta;
5064
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;
5370
invariant(
5471
pluginName,
5572
'pluginConfigCreator.pluginName required',
@@ -58,7 +75,7 @@ export class LowCodePluginManager implements ILowCodePluginManager {
5875

5976
ctx.setPreference(pluginName, (preferenceDeclaration as ILowCodePluginPreferenceDeclaration));
6077

61-
const allowOverride = options?.override === true;
78+
const allowOverride = registerOptions?.override === true;
6279

6380
if (this.pluginsMap.has(pluginName)) {
6481
if (!allowOverride) {
@@ -83,7 +100,8 @@ export class LowCodePluginManager implements ILowCodePluginManager {
83100
}
84101

85102
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) {
87105
await plugin.init();
88106
}
89107
this.plugins.push(plugin);

packages/designer/src/plugin/plugin-types.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ export interface ILowCodePluginPreferenceDeclaration {
4848
export type PluginPreference = Map<string, Record<string, PreferenceValueType>>;
4949

5050
export interface ILowCodePluginConfig {
51+
dep?: string | string[];
5152
init?(): void;
5253
destroy?(): void;
5354
exports?(): any;
@@ -130,6 +131,10 @@ export interface ILowCodePluginManagerCore {
130131

131132
export type ILowCodePluginManager = ILowCodePluginManagerCore & ILowCodePluginManagerPluginAccessor;
132133

134+
export function isLowCodeRegisterOptions(opts: any): opts is ILowCodeRegisterOptions {
135+
return opts && ('autoInit' in opts || 'override' in opts);
136+
}
137+
133138
export interface ILowCodeRegisterOptions {
134139
autoInit?: boolean;
135140
// allow overriding existing plugin with same name when override === true
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
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+
}

packages/designer/src/plugin/plugin.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,11 @@ export class LowCodePlugin implements ILowCodePlugin {
5050
if (typeof this.meta.dependencies === 'string') {
5151
return [this.meta.dependencies];
5252
}
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 || [];
5458
}
5559

5660
get disabled() {

packages/editor-core/src/editor.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import {
1111
RemoteComponentDescription,
1212
GlobalEvent,
1313
} from '@alilc/lowcode-types';
14+
import { engineConfig } from './config';
1415
import { globalLocale } from './intl';
1516
import * as utils from './utils';
1617
import Preference from './utils/preference';
@@ -71,6 +72,8 @@ export class Editor extends (EventEmitter as any) implements IEditor {
7172
this.setAssets(data);
7273
return;
7374
}
75+
// store the data to engineConfig while invoking editor.set()
76+
engineConfig.set(key as any, data);
7477
this.context.set(key, data);
7578
this.notifyGot(key);
7679
}

0 commit comments

Comments
 (0)