@sepveneto/dnde-core 0.6.3 → 0.6.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/{Node-B7pDsvZF.d.cts → capability-Ce3qGTm3.d.cts} +198 -127
- package/dist/{Node-B7pDsvZF.d.ts → capability-Ce3qGTm3.d.ts} +198 -127
- package/dist/capability.cjs +172 -0
- package/dist/capability.d.cts +4 -0
- package/dist/capability.d.ts +4 -0
- package/dist/capability.js +15 -0
- package/dist/{chunk-PRK4NPVH.js → chunk-62FPS6PZ.js} +2 -0
- package/dist/chunk-IQ5LOS7W.js +0 -0
- package/dist/{chunk-KJZSF66T.js → chunk-RLMXVDJK.js} +1 -16
- package/dist/chunk-W7WBD3NX.js +360 -0
- package/dist/chunk-XXR7SKZ3.js +132 -0
- package/dist/class/Container.d.cts +2 -2
- package/dist/class/Container.d.ts +2 -2
- package/dist/class/Node.cjs +2 -18
- package/dist/class/Node.d.cts +1 -1
- package/dist/class/Node.d.ts +1 -1
- package/dist/class/Node.js +3 -5
- package/dist/class/Widget.d.cts +1 -1
- package/dist/class/Widget.d.ts +1 -1
- package/dist/class/index.cjs +0 -16
- package/dist/class/index.d.cts +2 -2
- package/dist/class/index.d.ts +2 -2
- package/dist/class/index.js +4 -5
- package/dist/dsl.cjs +405 -0
- package/dist/dsl.d.cts +85 -0
- package/dist/dsl.d.ts +85 -0
- package/dist/dsl.js +12 -0
- package/dist/helper/index.cjs +2 -0
- package/dist/helper/index.d.cts +1 -1
- package/dist/helper/index.d.ts +1 -1
- package/dist/helper/index.js +1 -1
- package/dist/helper/schema.cjs +2 -0
- package/dist/helper/schema.d.cts +3 -1
- package/dist/helper/schema.d.ts +3 -1
- package/dist/helper/schema.js +1 -1
- package/dist/helper/widget.d.cts +1 -1
- package/dist/helper/widget.d.ts +1 -1
- package/dist/index.cjs +693 -0
- package/dist/index.d.cts +3 -1
- package/dist/index.d.ts +3 -1
- package/dist/index.js +34 -1
- package/dist/internal.d.cts +2 -2
- package/dist/internal.d.ts +2 -2
- package/dist/tokens.d.cts +1 -1
- package/dist/tokens.d.ts +1 -1
- package/dist/types.d.cts +1 -1
- package/dist/types.d.ts +1 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -1,10 +1,12 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
2
3
|
var __defProp = Object.defineProperty;
|
|
3
4
|
var __defProps = Object.defineProperties;
|
|
4
5
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
6
|
var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
|
|
6
7
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
7
8
|
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
9
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
8
10
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
9
11
|
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
10
12
|
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
@@ -32,22 +34,700 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
32
34
|
}
|
|
33
35
|
return to;
|
|
34
36
|
};
|
|
37
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
38
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
39
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
40
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
41
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
42
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
43
|
+
mod
|
|
44
|
+
));
|
|
35
45
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
46
|
+
var __async = (__this, __arguments, generator) => {
|
|
47
|
+
return new Promise((resolve, reject) => {
|
|
48
|
+
var fulfilled = (value) => {
|
|
49
|
+
try {
|
|
50
|
+
step(generator.next(value));
|
|
51
|
+
} catch (e) {
|
|
52
|
+
reject(e);
|
|
53
|
+
}
|
|
54
|
+
};
|
|
55
|
+
var rejected = (value) => {
|
|
56
|
+
try {
|
|
57
|
+
step(generator.throw(value));
|
|
58
|
+
} catch (e) {
|
|
59
|
+
reject(e);
|
|
60
|
+
}
|
|
61
|
+
};
|
|
62
|
+
var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
|
|
63
|
+
step((generator = generator.apply(__this, __arguments)).next());
|
|
64
|
+
});
|
|
65
|
+
};
|
|
36
66
|
|
|
37
67
|
// src/index.ts
|
|
38
68
|
var index_exports = {};
|
|
39
69
|
__export(index_exports, {
|
|
70
|
+
Container: () => Container,
|
|
40
71
|
EventEmitter: () => EventEmitter,
|
|
72
|
+
Node: () => Node,
|
|
73
|
+
Widget: () => Widget,
|
|
74
|
+
createCapabilityCatalog: () => createCapabilityCatalog,
|
|
41
75
|
createCopy: () => createCopy,
|
|
42
76
|
createDelete: () => createDelete,
|
|
43
77
|
editorContextKey: () => editorContextKey,
|
|
78
|
+
findCustomCapability: () => findCustomCapability,
|
|
79
|
+
findFieldCapability: () => findFieldCapability,
|
|
80
|
+
findWidgetCapability: () => findWidgetCapability,
|
|
44
81
|
isBox: () => isBox,
|
|
82
|
+
isKnownScope: () => isKnownScope,
|
|
83
|
+
isStyleField: () => isStyleField,
|
|
84
|
+
listStaticOptions: () => listStaticOptions,
|
|
45
85
|
schema: () => schema,
|
|
86
|
+
validateEditorDsl: () => validateEditorDsl,
|
|
46
87
|
widget: () => widget,
|
|
47
88
|
widgetType: () => widgetType
|
|
48
89
|
});
|
|
49
90
|
module.exports = __toCommonJS(index_exports);
|
|
50
91
|
|
|
92
|
+
// src/class/Widget.ts
|
|
93
|
+
var import_async_validator = __toESM(require("async-validator"), 1);
|
|
94
|
+
var Widget = class _Widget {
|
|
95
|
+
constructor(widget2) {
|
|
96
|
+
this._data = JSON.parse(JSON.stringify(widget2));
|
|
97
|
+
if (widget2.agent)
|
|
98
|
+
this._data.agent = __spreadValues({}, widget2.agent);
|
|
99
|
+
this.name = widget2._name;
|
|
100
|
+
this.view = widget2._view;
|
|
101
|
+
this.container = widget2.container;
|
|
102
|
+
}
|
|
103
|
+
clone() {
|
|
104
|
+
return new _Widget(this._data);
|
|
105
|
+
}
|
|
106
|
+
get icon() {
|
|
107
|
+
return this._data._icon;
|
|
108
|
+
}
|
|
109
|
+
get props() {
|
|
110
|
+
var _a;
|
|
111
|
+
return ((_a = this._data.schema) == null ? void 0 : _a.props) || [];
|
|
112
|
+
}
|
|
113
|
+
get style() {
|
|
114
|
+
var _a;
|
|
115
|
+
return ((_a = this._data.schema) == null ? void 0 : _a.style) || [];
|
|
116
|
+
}
|
|
117
|
+
get defaultStyle() {
|
|
118
|
+
return this._data.style;
|
|
119
|
+
}
|
|
120
|
+
get defaultData() {
|
|
121
|
+
return this._data.data;
|
|
122
|
+
}
|
|
123
|
+
get agent() {
|
|
124
|
+
return this._data.agent;
|
|
125
|
+
}
|
|
126
|
+
get draggable() {
|
|
127
|
+
var _a, _b;
|
|
128
|
+
return (_b = (_a = this._data.meta) == null ? void 0 : _a.draggable) != null ? _b : true;
|
|
129
|
+
}
|
|
130
|
+
get isFixed() {
|
|
131
|
+
var _a;
|
|
132
|
+
const fixed = (_a = this._data.meta) == null ? void 0 : _a.fixed;
|
|
133
|
+
if (fixed === true) {
|
|
134
|
+
return "header";
|
|
135
|
+
} else {
|
|
136
|
+
return fixed;
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
get visible() {
|
|
140
|
+
var _a, _b;
|
|
141
|
+
return (_b = (_a = this._data.meta) == null ? void 0 : _a.visible) != null ? _b : true;
|
|
142
|
+
}
|
|
143
|
+
get validatorProps() {
|
|
144
|
+
var _a, _b;
|
|
145
|
+
const _rules = ((_b = (_a = this._data.schema) == null ? void 0 : _a.props) == null ? void 0 : _b.reduce((all, curr) => {
|
|
146
|
+
all[curr.key] = curr.rules || [];
|
|
147
|
+
return all;
|
|
148
|
+
}, {})) || {};
|
|
149
|
+
const validator = new import_async_validator.default(_rules);
|
|
150
|
+
return validator;
|
|
151
|
+
}
|
|
152
|
+
get validatorStyle() {
|
|
153
|
+
var _a, _b;
|
|
154
|
+
const _rules = ((_b = (_a = this._data.schema) == null ? void 0 : _a.style) == null ? void 0 : _b.reduce((all, curr) => {
|
|
155
|
+
all[curr.key] = curr.rules || [];
|
|
156
|
+
return all;
|
|
157
|
+
}, {})) || {};
|
|
158
|
+
const validator = new import_async_validator.default(_rules);
|
|
159
|
+
return validator;
|
|
160
|
+
}
|
|
161
|
+
};
|
|
162
|
+
|
|
163
|
+
// src/class/Container.ts
|
|
164
|
+
var Container = class extends Widget {
|
|
165
|
+
constructor(data) {
|
|
166
|
+
super(data);
|
|
167
|
+
this.view = "container";
|
|
168
|
+
}
|
|
169
|
+
};
|
|
170
|
+
|
|
171
|
+
// src/class/Node.ts
|
|
172
|
+
var import_uuid = require("uuid");
|
|
173
|
+
var Node = class _Node {
|
|
174
|
+
constructor(widget2, info) {
|
|
175
|
+
this.level = 0;
|
|
176
|
+
this.list = [];
|
|
177
|
+
this.data = {};
|
|
178
|
+
this.style = {};
|
|
179
|
+
this.hovering = false;
|
|
180
|
+
this.dragging = false;
|
|
181
|
+
this.widget = widget2;
|
|
182
|
+
this.wid = (info == null ? void 0 : info.uuid) || (0, import_uuid.v4)();
|
|
183
|
+
this.list = (info == null ? void 0 : info.list) || [];
|
|
184
|
+
this.data = (info == null ? void 0 : info.props) || {};
|
|
185
|
+
this.style = (info == null ? void 0 : info.style) || {};
|
|
186
|
+
}
|
|
187
|
+
get info() {
|
|
188
|
+
return __spreadValues({
|
|
189
|
+
style: this.style
|
|
190
|
+
}, this.data);
|
|
191
|
+
}
|
|
192
|
+
get isContainer() {
|
|
193
|
+
return !!this.widget.container;
|
|
194
|
+
}
|
|
195
|
+
get hasList() {
|
|
196
|
+
return this.list && this.list.length > 0;
|
|
197
|
+
}
|
|
198
|
+
get mouseover() {
|
|
199
|
+
return this.hovering;
|
|
200
|
+
}
|
|
201
|
+
get type() {
|
|
202
|
+
var _a;
|
|
203
|
+
return ((_a = this.widget) == null ? void 0 : _a.view) || "root";
|
|
204
|
+
}
|
|
205
|
+
get name() {
|
|
206
|
+
var _a;
|
|
207
|
+
return ((_a = this.widget) == null ? void 0 : _a.name) || "\u9875\u9762";
|
|
208
|
+
}
|
|
209
|
+
get visible() {
|
|
210
|
+
if ("isShow" in this.data)
|
|
211
|
+
return Boolean(this.data.isShow);
|
|
212
|
+
}
|
|
213
|
+
validate(only = false) {
|
|
214
|
+
return __async(this, null, function* () {
|
|
215
|
+
const valid = yield Promise.all([
|
|
216
|
+
this.widget.validatorProps.validate(this.data),
|
|
217
|
+
this.widget.validatorStyle.validate(this.style)
|
|
218
|
+
]).catch(() => {
|
|
219
|
+
return false;
|
|
220
|
+
});
|
|
221
|
+
if (!valid) {
|
|
222
|
+
return this.wid;
|
|
223
|
+
}
|
|
224
|
+
if (only || !this.list) {
|
|
225
|
+
return;
|
|
226
|
+
}
|
|
227
|
+
for (const item of this.list) {
|
|
228
|
+
const invalid = yield item.validate();
|
|
229
|
+
if (invalid) {
|
|
230
|
+
return invalid;
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
});
|
|
234
|
+
}
|
|
235
|
+
triggerHover(hover) {
|
|
236
|
+
this.hovering = hover;
|
|
237
|
+
}
|
|
238
|
+
setList(list) {
|
|
239
|
+
this.list = list;
|
|
240
|
+
}
|
|
241
|
+
copy() {
|
|
242
|
+
var _a;
|
|
243
|
+
const list = (_a = this.list) == null ? void 0 : _a.map((item) => item.copy());
|
|
244
|
+
const info = {
|
|
245
|
+
props: JSON.parse(JSON.stringify(this.data)),
|
|
246
|
+
style: JSON.parse(JSON.stringify(this.style)),
|
|
247
|
+
list
|
|
248
|
+
};
|
|
249
|
+
return new _Node(this.widget.clone(), info);
|
|
250
|
+
}
|
|
251
|
+
parse() {
|
|
252
|
+
var _a;
|
|
253
|
+
const res = {
|
|
254
|
+
_uuid: this.wid,
|
|
255
|
+
_name: this.name,
|
|
256
|
+
_view: this.type,
|
|
257
|
+
data: this.data,
|
|
258
|
+
style: this.style,
|
|
259
|
+
list: (_a = this.list) == null ? void 0 : _a.map((item) => item.parse())
|
|
260
|
+
};
|
|
261
|
+
return res;
|
|
262
|
+
}
|
|
263
|
+
};
|
|
264
|
+
|
|
265
|
+
// src/capability.ts
|
|
266
|
+
function optionValues(item) {
|
|
267
|
+
if (!("options" in item) || !Array.isArray(item.options))
|
|
268
|
+
return;
|
|
269
|
+
return item.options.map((option) => option && typeof option === "object" ? option.value : void 0).filter((value) => value !== void 0);
|
|
270
|
+
}
|
|
271
|
+
function fieldFromSchema(item, scope) {
|
|
272
|
+
var _a, _b, _c;
|
|
273
|
+
if (item.type === "custom")
|
|
274
|
+
return;
|
|
275
|
+
let valueType = "unknown";
|
|
276
|
+
let enumValues;
|
|
277
|
+
let minimum;
|
|
278
|
+
let maximum;
|
|
279
|
+
switch (item.type) {
|
|
280
|
+
case "input":
|
|
281
|
+
case "colorPicker":
|
|
282
|
+
case "datetimePicker":
|
|
283
|
+
valueType = "string";
|
|
284
|
+
break;
|
|
285
|
+
case "number":
|
|
286
|
+
case "styleNumber":
|
|
287
|
+
valueType = "number";
|
|
288
|
+
minimum = typeof ((_a = item.attrs) == null ? void 0 : _a.min) === "number" ? item.attrs.min : void 0;
|
|
289
|
+
maximum = typeof ((_b = item.attrs) == null ? void 0 : _b.max) === "number" ? item.attrs.max : void 0;
|
|
290
|
+
break;
|
|
291
|
+
case "switch":
|
|
292
|
+
if ("attrs" in item && item.attrs && ("activeValue" in item.attrs || "inactiveValue" in item.attrs)) {
|
|
293
|
+
valueType = "enum";
|
|
294
|
+
enumValues = [
|
|
295
|
+
item.attrs.activeValue,
|
|
296
|
+
item.attrs.inactiveValue
|
|
297
|
+
].filter((value) => value !== void 0);
|
|
298
|
+
} else {
|
|
299
|
+
valueType = "boolean";
|
|
300
|
+
}
|
|
301
|
+
break;
|
|
302
|
+
case "checkbox":
|
|
303
|
+
valueType = "boolean";
|
|
304
|
+
break;
|
|
305
|
+
case "select":
|
|
306
|
+
case "radio":
|
|
307
|
+
case "radioButton":
|
|
308
|
+
valueType = "enum";
|
|
309
|
+
enumValues = optionValues(item);
|
|
310
|
+
break;
|
|
311
|
+
}
|
|
312
|
+
const rules = Array.isArray(item.rules) ? item.rules : item.rules ? [item.rules] : [];
|
|
313
|
+
return {
|
|
314
|
+
source: "prop",
|
|
315
|
+
key: item.key,
|
|
316
|
+
label: item.label,
|
|
317
|
+
valueType,
|
|
318
|
+
scope: (_c = item.scope) != null ? _c : scope,
|
|
319
|
+
required: rules.some((rule) => rule.required === true),
|
|
320
|
+
readOnly: item.readOnly === true,
|
|
321
|
+
enum: enumValues,
|
|
322
|
+
minimum,
|
|
323
|
+
maximum
|
|
324
|
+
};
|
|
325
|
+
}
|
|
326
|
+
function registeredCustomTypes(registration) {
|
|
327
|
+
var _a;
|
|
328
|
+
return ((_a = registration == null ? void 0 : registration.customTypes) != null ? _a : []).map((type) => ({
|
|
329
|
+
type: type.type,
|
|
330
|
+
capabilities: type.capabilities.map((capability) => __spreadValues({}, capability))
|
|
331
|
+
}));
|
|
332
|
+
}
|
|
333
|
+
function schemaCustomTypes(widget2) {
|
|
334
|
+
var _a, _b;
|
|
335
|
+
return ((_b = (_a = widget2.schema) == null ? void 0 : _a.props) != null ? _b : []).filter((item) => item.type === "custom").map((item) => item.name);
|
|
336
|
+
}
|
|
337
|
+
function createCapabilityCatalog(widgets, registry = {}) {
|
|
338
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l;
|
|
339
|
+
const catalog = {
|
|
340
|
+
catalogVersion: "1.0",
|
|
341
|
+
widgets: []
|
|
342
|
+
};
|
|
343
|
+
for (const widget2 of widgets) {
|
|
344
|
+
const registration = registry[widget2._view];
|
|
345
|
+
const declared = registeredCustomTypes(registration);
|
|
346
|
+
const declaredMap = new Map(declared.map((type) => [type.type, type]));
|
|
347
|
+
const customTypes = schemaCustomTypes(widget2).map((type) => {
|
|
348
|
+
var _a2;
|
|
349
|
+
return (_a2 = declaredMap.get(type)) != null ? _a2 : { type, capabilities: [] };
|
|
350
|
+
});
|
|
351
|
+
catalog.widgets.push({
|
|
352
|
+
type: widget2._view,
|
|
353
|
+
name: widget2._name,
|
|
354
|
+
description: (_e = (_d = (_a = widget2.agent) == null ? void 0 : _a.description) != null ? _d : (_c = (_b = widget2.agent) == null ? void 0 : _b.layout) == null ? void 0 : _c.description) != null ? _e : "",
|
|
355
|
+
defaultData: JSON.parse(JSON.stringify((_f = widget2.data) != null ? _f : {})),
|
|
356
|
+
defaultStyle: JSON.parse(JSON.stringify((_g = widget2.style) != null ? _g : {})),
|
|
357
|
+
fields: [
|
|
358
|
+
...((_i = (_h = widget2.schema) == null ? void 0 : _h.props) != null ? _i : []).map((item) => fieldFromSchema(item, "content")).filter((item) => Boolean(item)),
|
|
359
|
+
...((_k = (_j = widget2.schema) == null ? void 0 : _j.style) != null ? _k : []).map((item) => fieldFromSchema(item, "style")).filter((item) => Boolean(item))
|
|
360
|
+
],
|
|
361
|
+
customTypes,
|
|
362
|
+
staticOptions: ((_l = registration == null ? void 0 : registration.staticOptions) != null ? _l : []).map((option) => __spreadProps(__spreadValues({}, option), {
|
|
363
|
+
aliases: [...option.aliases],
|
|
364
|
+
types: [...option.types]
|
|
365
|
+
}))
|
|
366
|
+
});
|
|
367
|
+
}
|
|
368
|
+
return catalog;
|
|
369
|
+
}
|
|
370
|
+
function findWidgetCapability(catalog, type) {
|
|
371
|
+
return catalog.widgets.find((widget2) => widget2.type === type);
|
|
372
|
+
}
|
|
373
|
+
function findFieldCapability(widget2, key) {
|
|
374
|
+
return widget2.fields.find((field) => field.key === key);
|
|
375
|
+
}
|
|
376
|
+
function findCustomCapability(widget2, type, name) {
|
|
377
|
+
var _a;
|
|
378
|
+
return (_a = widget2.customTypes.find((item) => item.type === type)) == null ? void 0 : _a.capabilities.find((capability) => capability.name === name);
|
|
379
|
+
}
|
|
380
|
+
function listStaticOptions(catalog, widgetTypes, types) {
|
|
381
|
+
const selected = (widgetTypes == null ? void 0 : widgetTypes.length) ? catalog.widgets.filter((widget2) => widgetTypes.includes(widget2.type)) : catalog.widgets;
|
|
382
|
+
return selected.flatMap((widget2) => widget2.staticOptions).filter((option) => !(types == null ? void 0 : types.length) || option.types.some((type) => types.includes(type)));
|
|
383
|
+
}
|
|
384
|
+
|
|
385
|
+
// src/dsl.ts
|
|
386
|
+
function asRecord(value) {
|
|
387
|
+
return value && typeof value === "object" && !Array.isArray(value) ? value : {};
|
|
388
|
+
}
|
|
389
|
+
function isScope(value) {
|
|
390
|
+
return value === "style" || value === "content" || value === "layout";
|
|
391
|
+
}
|
|
392
|
+
function allowsScope(mode, scope) {
|
|
393
|
+
if (mode === "any")
|
|
394
|
+
return true;
|
|
395
|
+
return mode === "style_only" && scope === "style" || mode === "content_only" && scope === "content" || mode === "layout_only" && scope === "layout";
|
|
396
|
+
}
|
|
397
|
+
function matchesValueType(field, value) {
|
|
398
|
+
var _a, _b;
|
|
399
|
+
if (!field)
|
|
400
|
+
return false;
|
|
401
|
+
switch (field.valueType) {
|
|
402
|
+
case "string":
|
|
403
|
+
return typeof value === "string";
|
|
404
|
+
case "number":
|
|
405
|
+
return typeof value === "number" && Number.isFinite(value);
|
|
406
|
+
case "integer":
|
|
407
|
+
return Number.isInteger(value);
|
|
408
|
+
case "boolean":
|
|
409
|
+
return typeof value === "boolean";
|
|
410
|
+
case "enum":
|
|
411
|
+
return (_b = (_a = field.enum) == null ? void 0 : _a.some((item) => Object.is(item, value))) != null ? _b : true;
|
|
412
|
+
case "array":
|
|
413
|
+
return Array.isArray(value);
|
|
414
|
+
case "object":
|
|
415
|
+
return Boolean(value) && typeof value === "object" && !Array.isArray(value);
|
|
416
|
+
default:
|
|
417
|
+
return true;
|
|
418
|
+
}
|
|
419
|
+
}
|
|
420
|
+
function validateFieldValue(widget2, key, value, scopeMode, path, issues) {
|
|
421
|
+
const field = findFieldCapability(widget2, key);
|
|
422
|
+
if (!field) {
|
|
423
|
+
issues.push({
|
|
424
|
+
code: "unknown_prop",
|
|
425
|
+
path,
|
|
426
|
+
message: `${widget2.type} \u6CA1\u6709\u767B\u8BB0\u6807\u51C6\u5B57\u6BB5 ${key}`
|
|
427
|
+
});
|
|
428
|
+
return false;
|
|
429
|
+
}
|
|
430
|
+
if (field.readOnly) {
|
|
431
|
+
issues.push({
|
|
432
|
+
code: "read_only_prop",
|
|
433
|
+
path,
|
|
434
|
+
message: `${widget2.type}.${key} \u4E3A\u53EA\u8BFB\u5B57\u6BB5`
|
|
435
|
+
});
|
|
436
|
+
return false;
|
|
437
|
+
}
|
|
438
|
+
if (!allowsScope(scopeMode, field.scope)) {
|
|
439
|
+
issues.push({
|
|
440
|
+
code: "scope_violation",
|
|
441
|
+
path,
|
|
442
|
+
message: `${widget2.type}.${key} \u5C5E\u4E8E ${field.scope}\uFF0C\u5F53\u524D scope \u4E0D\u5141\u8BB8\u5199\u5165`
|
|
443
|
+
});
|
|
444
|
+
return false;
|
|
445
|
+
}
|
|
446
|
+
if (!matchesValueType(field, value)) {
|
|
447
|
+
issues.push({
|
|
448
|
+
code: "invalid_prop_type",
|
|
449
|
+
path,
|
|
450
|
+
message: `${widget2.type}.${key} \u9700\u8981 ${field.valueType} \u7C7B\u578B`
|
|
451
|
+
});
|
|
452
|
+
return false;
|
|
453
|
+
}
|
|
454
|
+
if (typeof value === "number" && field.minimum !== void 0 && value < field.minimum) {
|
|
455
|
+
issues.push({
|
|
456
|
+
code: "prop_below_minimum",
|
|
457
|
+
path,
|
|
458
|
+
message: `${widget2.type}.${key} \u4E0D\u80FD\u5C0F\u4E8E ${field.minimum}`
|
|
459
|
+
});
|
|
460
|
+
return false;
|
|
461
|
+
}
|
|
462
|
+
if (typeof value === "number" && field.maximum !== void 0 && value > field.maximum) {
|
|
463
|
+
issues.push({
|
|
464
|
+
code: "prop_above_maximum",
|
|
465
|
+
path,
|
|
466
|
+
message: `${widget2.type}.${key} \u4E0D\u80FD\u5927\u4E8E ${field.maximum}`
|
|
467
|
+
});
|
|
468
|
+
return false;
|
|
469
|
+
}
|
|
470
|
+
return true;
|
|
471
|
+
}
|
|
472
|
+
function validateProps(widget2, props, container, scopeMode, path, issues) {
|
|
473
|
+
if (props === void 0)
|
|
474
|
+
return;
|
|
475
|
+
if (!props || typeof props !== "object" || Array.isArray(props)) {
|
|
476
|
+
issues.push({
|
|
477
|
+
code: "invalid_props",
|
|
478
|
+
path,
|
|
479
|
+
message: "props \u5FC5\u987B\u662F\u5BF9\u8C61"
|
|
480
|
+
});
|
|
481
|
+
return;
|
|
482
|
+
}
|
|
483
|
+
Object.entries(props).forEach(([key, value]) => {
|
|
484
|
+
const field = findFieldCapability(widget2, key);
|
|
485
|
+
if (field && container === "props" && field.scope === "style") {
|
|
486
|
+
issues.push({
|
|
487
|
+
code: "style_field_in_props",
|
|
488
|
+
path: `${path}.${key}`,
|
|
489
|
+
message: `${widget2.type}.${key} \u662F\u6837\u5F0F\u5B57\u6BB5\uFF0C\u5FC5\u987B\u5199\u5165 style`
|
|
490
|
+
});
|
|
491
|
+
return;
|
|
492
|
+
}
|
|
493
|
+
if (field && container === "style" && field.scope !== "style") {
|
|
494
|
+
issues.push({
|
|
495
|
+
code: "non_style_field_in_style",
|
|
496
|
+
path: `${path}.${key}`,
|
|
497
|
+
message: `${widget2.type}.${key} \u4E0D\u662F\u6837\u5F0F\u5B57\u6BB5\uFF0C\u4E0D\u80FD\u5199\u5165 style`
|
|
498
|
+
});
|
|
499
|
+
return;
|
|
500
|
+
}
|
|
501
|
+
validateFieldValue(widget2, key, value, scopeMode, `${path}.${key}`, issues);
|
|
502
|
+
});
|
|
503
|
+
}
|
|
504
|
+
function validateCustom(widget2, custom, scopeMode, path, issues) {
|
|
505
|
+
if (custom === void 0)
|
|
506
|
+
return;
|
|
507
|
+
if (!Array.isArray(custom)) {
|
|
508
|
+
issues.push({
|
|
509
|
+
code: "invalid_custom_operations",
|
|
510
|
+
path,
|
|
511
|
+
message: "custom \u5FC5\u987B\u662F\u80FD\u529B\u64CD\u4F5C\u6570\u7EC4"
|
|
512
|
+
});
|
|
513
|
+
return;
|
|
514
|
+
}
|
|
515
|
+
custom.forEach((rawOperation, index) => {
|
|
516
|
+
const operation = asRecord(rawOperation);
|
|
517
|
+
const type = typeof operation.type === "string" ? operation.type : "";
|
|
518
|
+
const name = typeof operation.capability === "string" ? operation.capability : "";
|
|
519
|
+
const capability = findCustomCapability(widget2, type, name);
|
|
520
|
+
if (!capability) {
|
|
521
|
+
issues.push({
|
|
522
|
+
code: "unsupported_capability",
|
|
523
|
+
path: `${path}[${index}]`,
|
|
524
|
+
message: `${widget2.type} \u672A\u767B\u8BB0 custom type ${type} \u7684\u80FD\u529B ${name}`
|
|
525
|
+
});
|
|
526
|
+
return;
|
|
527
|
+
}
|
|
528
|
+
if (!allowsScope(scopeMode, capability.writableScope)) {
|
|
529
|
+
issues.push({
|
|
530
|
+
code: "scope_violation",
|
|
531
|
+
path: `${path}[${index}]`,
|
|
532
|
+
message: `\u80FD\u529B ${name} \u5C5E\u4E8E ${capability.writableScope}\uFF0C\u5F53\u524D scope \u4E0D\u5141\u8BB8\u5199\u5165`
|
|
533
|
+
});
|
|
534
|
+
}
|
|
535
|
+
});
|
|
536
|
+
}
|
|
537
|
+
function placementCount(placement) {
|
|
538
|
+
return ["afterUuid", "beforeUuid", "afterKey", "beforeKey"].filter((key) => typeof placement[key] === "string" && placement[key]).length;
|
|
539
|
+
}
|
|
540
|
+
function validateEditorDsl(input, options) {
|
|
541
|
+
const issues = [];
|
|
542
|
+
const dsl = asRecord(input);
|
|
543
|
+
const operations = Array.isArray(dsl.operations) ? dsl.operations : [];
|
|
544
|
+
const scope = asRecord(dsl.scope);
|
|
545
|
+
const scopeMode = scope.mode;
|
|
546
|
+
if (dsl.dslVersion !== "1.1") {
|
|
547
|
+
issues.push({
|
|
548
|
+
code: "unsupported_dsl_version",
|
|
549
|
+
path: "dslVersion",
|
|
550
|
+
message: "\u4EC5\u652F\u6301 dslVersion 1.1"
|
|
551
|
+
});
|
|
552
|
+
}
|
|
553
|
+
if (dsl.baseRevision !== options.snapshot.revision) {
|
|
554
|
+
issues.push({
|
|
555
|
+
code: "stale_revision",
|
|
556
|
+
path: "baseRevision",
|
|
557
|
+
message: `DSL \u57FA\u4E8E revision ${String(dsl.baseRevision)}\uFF0C\u5F53\u524D\u4E3A ${options.snapshot.revision}`
|
|
558
|
+
});
|
|
559
|
+
}
|
|
560
|
+
if (scopeMode !== "style_only" && scopeMode !== "content_only" && scopeMode !== "layout_only" && scopeMode !== "any") {
|
|
561
|
+
issues.push({
|
|
562
|
+
code: "invalid_scope",
|
|
563
|
+
path: "scope.mode",
|
|
564
|
+
message: "scope.mode \u5FC5\u987B\u662F style_only/content_only/layout_only/any"
|
|
565
|
+
});
|
|
566
|
+
}
|
|
567
|
+
const scopeTargets = Array.isArray(scope.targets) ? scope.targets.filter((target) => typeof target === "string") : [];
|
|
568
|
+
if (!operations.length) {
|
|
569
|
+
issues.push({
|
|
570
|
+
code: "empty_operations",
|
|
571
|
+
path: "operations",
|
|
572
|
+
message: "DSL \u81F3\u5C11\u9700\u8981\u4E00\u4E2A\u64CD\u4F5C"
|
|
573
|
+
});
|
|
574
|
+
}
|
|
575
|
+
const nodeUuids = new Set(options.snapshot.nodes.map((node) => node.uuid));
|
|
576
|
+
const addKeys = /* @__PURE__ */ new Set();
|
|
577
|
+
const normalizedOperations = [];
|
|
578
|
+
operations.forEach((rawOperation, index) => {
|
|
579
|
+
var _a, _b;
|
|
580
|
+
const operation = asRecord(rawOperation);
|
|
581
|
+
const path = `operations[${index}]`;
|
|
582
|
+
const op = operation.op;
|
|
583
|
+
if (op !== "add" && op !== "update" && op !== "delete") {
|
|
584
|
+
issues.push({
|
|
585
|
+
code: "unsupported_operation",
|
|
586
|
+
path: `${path}.op`,
|
|
587
|
+
message: `\u4E0D\u652F\u6301\u7684\u64CD\u4F5C ${String(op)}`
|
|
588
|
+
});
|
|
589
|
+
return;
|
|
590
|
+
}
|
|
591
|
+
if (op === "add") {
|
|
592
|
+
const key = typeof operation.key === "string" ? operation.key : "";
|
|
593
|
+
const widgetType2 = typeof operation.widget === "string" ? operation.widget : "";
|
|
594
|
+
const widget3 = findWidgetCapability(options.catalog, widgetType2);
|
|
595
|
+
if (!key) {
|
|
596
|
+
issues.push({ code: "missing_key", path: `${path}.key`, message: "add \u5FC5\u987B\u63D0\u4F9B\u6279\u5185\u552F\u4E00 key" });
|
|
597
|
+
} else if (addKeys.has(key)) {
|
|
598
|
+
issues.push({ code: "duplicate_key", path: `${path}.key`, message: `\u6279\u5185 key \u91CD\u590D\uFF1A${key}` });
|
|
599
|
+
}
|
|
600
|
+
if (!widget3) {
|
|
601
|
+
issues.push({
|
|
602
|
+
code: "unknown_widget",
|
|
603
|
+
path: `${path}.widget`,
|
|
604
|
+
message: `\u7EC4\u4EF6\u80FD\u529B\u76EE\u5F55\u4E2D\u4E0D\u5B58\u5728 ${widgetType2}`
|
|
605
|
+
});
|
|
606
|
+
}
|
|
607
|
+
const placement = asRecord(operation.placement);
|
|
608
|
+
if (placementCount(placement) > 1) {
|
|
609
|
+
issues.push({
|
|
610
|
+
code: "ambiguous_placement",
|
|
611
|
+
path: `${path}.placement`,
|
|
612
|
+
message: "placement \u53EA\u80FD\u6307\u5B9A\u4E00\u4E2A\u76F8\u5BF9\u4F4D\u7F6E"
|
|
613
|
+
});
|
|
614
|
+
}
|
|
615
|
+
for (const keyName of ["afterKey", "beforeKey"]) {
|
|
616
|
+
const reference = typeof placement[keyName] === "string" ? placement[keyName] : "";
|
|
617
|
+
if (reference && !addKeys.has(reference)) {
|
|
618
|
+
issues.push({
|
|
619
|
+
code: "unknown_batch_key",
|
|
620
|
+
path: `${path}.placement.${keyName}`,
|
|
621
|
+
message: `\u6279\u5185 key ${reference} \u5C1A\u672A\u521B\u5EFA`
|
|
622
|
+
});
|
|
623
|
+
}
|
|
624
|
+
}
|
|
625
|
+
for (const uuidName of ["afterUuid", "beforeUuid"]) {
|
|
626
|
+
const reference = typeof placement[uuidName] === "string" ? placement[uuidName] : "";
|
|
627
|
+
if (reference && !nodeUuids.has(reference)) {
|
|
628
|
+
issues.push({
|
|
629
|
+
code: "unknown_node",
|
|
630
|
+
path: `${path}.placement.${uuidName}`,
|
|
631
|
+
message: `\u8282\u70B9 ${reference} \u4E0D\u5B58\u5728`
|
|
632
|
+
});
|
|
633
|
+
}
|
|
634
|
+
}
|
|
635
|
+
if (widget3) {
|
|
636
|
+
const customOperations = operation.custom === void 0 ? [] : operation.custom;
|
|
637
|
+
validateProps(widget3, operation.props, "props", scopeMode, `${path}.props`, issues);
|
|
638
|
+
validateProps(widget3, operation.style, "style", scopeMode, `${path}.style`, issues);
|
|
639
|
+
validateCustom(widget3, customOperations, scopeMode, `${path}.custom`, issues);
|
|
640
|
+
}
|
|
641
|
+
if (key)
|
|
642
|
+
addKeys.add(key);
|
|
643
|
+
normalizedOperations.push({
|
|
644
|
+
op,
|
|
645
|
+
key,
|
|
646
|
+
widget: widgetType2,
|
|
647
|
+
placement,
|
|
648
|
+
props: asRecord(operation.props),
|
|
649
|
+
style: asRecord(operation.style),
|
|
650
|
+
custom: Array.isArray(operation.custom) ? operation.custom : []
|
|
651
|
+
});
|
|
652
|
+
return;
|
|
653
|
+
}
|
|
654
|
+
const uuid = typeof operation.uuid === "string" ? operation.uuid : "";
|
|
655
|
+
const node = options.snapshot.nodes.find((item) => item.uuid === uuid);
|
|
656
|
+
if (!node) {
|
|
657
|
+
issues.push({
|
|
658
|
+
code: "unknown_node",
|
|
659
|
+
path: `${path}.uuid`,
|
|
660
|
+
message: `\u8282\u70B9 ${uuid || "(\u7A7A)"} \u4E0D\u5B58\u5728`
|
|
661
|
+
});
|
|
662
|
+
}
|
|
663
|
+
if (scopeTargets.length && !scopeTargets.includes(uuid)) {
|
|
664
|
+
issues.push({
|
|
665
|
+
code: "target_outside_scope",
|
|
666
|
+
path: `${path}.uuid`,
|
|
667
|
+
message: `\u8282\u70B9 ${uuid} \u4E0D\u5728 scope.targets \u5185`
|
|
668
|
+
});
|
|
669
|
+
}
|
|
670
|
+
if (op === "delete") {
|
|
671
|
+
if (!operation.confirmToken) {
|
|
672
|
+
issues.push({
|
|
673
|
+
code: "delete_confirmation_required",
|
|
674
|
+
path: `${path}.confirmToken`,
|
|
675
|
+
message: "\u5220\u9664\u64CD\u4F5C\u5FC5\u987B\u643A\u5E26\u4E00\u6B21\u6027\u786E\u8BA4\u4EE4\u724C"
|
|
676
|
+
});
|
|
677
|
+
} else if (!((_a = options.snapshot.confirmTokens) == null ? void 0 : _a.includes(String(operation.confirmToken)))) {
|
|
678
|
+
issues.push({
|
|
679
|
+
code: "invalid_confirm_token",
|
|
680
|
+
path: `${path}.confirmToken`,
|
|
681
|
+
message: "\u5220\u9664\u786E\u8BA4\u4EE4\u724C\u65E0\u6548\u6216\u5DF2\u8FC7\u671F"
|
|
682
|
+
});
|
|
683
|
+
}
|
|
684
|
+
normalizedOperations.push({ op, uuid, confirmToken: String((_b = operation.confirmToken) != null ? _b : "") });
|
|
685
|
+
return;
|
|
686
|
+
}
|
|
687
|
+
const widget2 = node ? findWidgetCapability(options.catalog, node.type) : void 0;
|
|
688
|
+
if (node && widget2) {
|
|
689
|
+
validateProps(widget2, operation.props, "props", scopeMode, `${path}.props`, issues);
|
|
690
|
+
validateProps(widget2, operation.style, "style", scopeMode, `${path}.style`, issues);
|
|
691
|
+
validateCustom(widget2, operation.custom, scopeMode, `${path}.custom`, issues);
|
|
692
|
+
}
|
|
693
|
+
normalizedOperations.push({
|
|
694
|
+
op,
|
|
695
|
+
uuid,
|
|
696
|
+
props: asRecord(operation.props),
|
|
697
|
+
style: asRecord(operation.style),
|
|
698
|
+
custom: Array.isArray(operation.custom) ? operation.custom : []
|
|
699
|
+
});
|
|
700
|
+
});
|
|
701
|
+
if (scopeTargets.some((target) => !nodeUuids.has(target))) {
|
|
702
|
+
issues.push({
|
|
703
|
+
code: "unknown_scope_target",
|
|
704
|
+
path: "scope.targets",
|
|
705
|
+
message: "scope.targets \u5305\u542B\u4E0D\u5B58\u5728\u7684\u8282\u70B9"
|
|
706
|
+
});
|
|
707
|
+
}
|
|
708
|
+
return __spreadValues({
|
|
709
|
+
ok: issues.length === 0,
|
|
710
|
+
issues
|
|
711
|
+
}, issues.length ? {} : {
|
|
712
|
+
normalized: {
|
|
713
|
+
dslVersion: "1.1",
|
|
714
|
+
baseRevision: options.snapshot.revision,
|
|
715
|
+
scope: {
|
|
716
|
+
mode: scopeMode,
|
|
717
|
+
targets: scopeTargets
|
|
718
|
+
},
|
|
719
|
+
operations: normalizedOperations
|
|
720
|
+
}
|
|
721
|
+
});
|
|
722
|
+
}
|
|
723
|
+
function isStyleField(widget2, key) {
|
|
724
|
+
var _a;
|
|
725
|
+
return ((_a = findFieldCapability(widget2, key)) == null ? void 0 : _a.scope) === "style";
|
|
726
|
+
}
|
|
727
|
+
function isKnownScope(value) {
|
|
728
|
+
return isScope(value);
|
|
729
|
+
}
|
|
730
|
+
|
|
51
731
|
// src/helper/EventEmitter.ts
|
|
52
732
|
var EventEmitter = class {
|
|
53
733
|
constructor(subscribeFn) {
|
|
@@ -93,6 +773,8 @@ var schema = {
|
|
|
93
773
|
_role: config._role,
|
|
94
774
|
label: config.label,
|
|
95
775
|
key: config.key,
|
|
776
|
+
scope: config.scope,
|
|
777
|
+
readOnly: config.readOnly,
|
|
96
778
|
type,
|
|
97
779
|
formItem: config.formItem,
|
|
98
780
|
rules: normalizeRules(config),
|
|
@@ -259,12 +941,23 @@ function isBox(schema2) {
|
|
|
259
941
|
}
|
|
260
942
|
// Annotate the CommonJS export names for ESM import in node:
|
|
261
943
|
0 && (module.exports = {
|
|
944
|
+
Container,
|
|
262
945
|
EventEmitter,
|
|
946
|
+
Node,
|
|
947
|
+
Widget,
|
|
948
|
+
createCapabilityCatalog,
|
|
263
949
|
createCopy,
|
|
264
950
|
createDelete,
|
|
265
951
|
editorContextKey,
|
|
952
|
+
findCustomCapability,
|
|
953
|
+
findFieldCapability,
|
|
954
|
+
findWidgetCapability,
|
|
266
955
|
isBox,
|
|
956
|
+
isKnownScope,
|
|
957
|
+
isStyleField,
|
|
958
|
+
listStaticOptions,
|
|
267
959
|
schema,
|
|
960
|
+
validateEditorDsl,
|
|
268
961
|
widget,
|
|
269
962
|
widgetType
|
|
270
963
|
});
|