@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
|
@@ -0,0 +1,360 @@
|
|
|
1
|
+
import {
|
|
2
|
+
findCustomCapability,
|
|
3
|
+
findFieldCapability,
|
|
4
|
+
findWidgetCapability
|
|
5
|
+
} from "./chunk-XXR7SKZ3.js";
|
|
6
|
+
import {
|
|
7
|
+
__spreadValues
|
|
8
|
+
} from "./chunk-6FNC3XMI.js";
|
|
9
|
+
|
|
10
|
+
// src/dsl.ts
|
|
11
|
+
function asRecord(value) {
|
|
12
|
+
return value && typeof value === "object" && !Array.isArray(value) ? value : {};
|
|
13
|
+
}
|
|
14
|
+
function isScope(value) {
|
|
15
|
+
return value === "style" || value === "content" || value === "layout";
|
|
16
|
+
}
|
|
17
|
+
function allowsScope(mode, scope) {
|
|
18
|
+
if (mode === "any")
|
|
19
|
+
return true;
|
|
20
|
+
return mode === "style_only" && scope === "style" || mode === "content_only" && scope === "content" || mode === "layout_only" && scope === "layout";
|
|
21
|
+
}
|
|
22
|
+
function matchesValueType(field, value) {
|
|
23
|
+
var _a, _b;
|
|
24
|
+
if (!field)
|
|
25
|
+
return false;
|
|
26
|
+
switch (field.valueType) {
|
|
27
|
+
case "string":
|
|
28
|
+
return typeof value === "string";
|
|
29
|
+
case "number":
|
|
30
|
+
return typeof value === "number" && Number.isFinite(value);
|
|
31
|
+
case "integer":
|
|
32
|
+
return Number.isInteger(value);
|
|
33
|
+
case "boolean":
|
|
34
|
+
return typeof value === "boolean";
|
|
35
|
+
case "enum":
|
|
36
|
+
return (_b = (_a = field.enum) == null ? void 0 : _a.some((item) => Object.is(item, value))) != null ? _b : true;
|
|
37
|
+
case "array":
|
|
38
|
+
return Array.isArray(value);
|
|
39
|
+
case "object":
|
|
40
|
+
return Boolean(value) && typeof value === "object" && !Array.isArray(value);
|
|
41
|
+
default:
|
|
42
|
+
return true;
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
function validateFieldValue(widget, key, value, scopeMode, path, issues) {
|
|
46
|
+
const field = findFieldCapability(widget, key);
|
|
47
|
+
if (!field) {
|
|
48
|
+
issues.push({
|
|
49
|
+
code: "unknown_prop",
|
|
50
|
+
path,
|
|
51
|
+
message: `${widget.type} \u6CA1\u6709\u767B\u8BB0\u6807\u51C6\u5B57\u6BB5 ${key}`
|
|
52
|
+
});
|
|
53
|
+
return false;
|
|
54
|
+
}
|
|
55
|
+
if (field.readOnly) {
|
|
56
|
+
issues.push({
|
|
57
|
+
code: "read_only_prop",
|
|
58
|
+
path,
|
|
59
|
+
message: `${widget.type}.${key} \u4E3A\u53EA\u8BFB\u5B57\u6BB5`
|
|
60
|
+
});
|
|
61
|
+
return false;
|
|
62
|
+
}
|
|
63
|
+
if (!allowsScope(scopeMode, field.scope)) {
|
|
64
|
+
issues.push({
|
|
65
|
+
code: "scope_violation",
|
|
66
|
+
path,
|
|
67
|
+
message: `${widget.type}.${key} \u5C5E\u4E8E ${field.scope}\uFF0C\u5F53\u524D scope \u4E0D\u5141\u8BB8\u5199\u5165`
|
|
68
|
+
});
|
|
69
|
+
return false;
|
|
70
|
+
}
|
|
71
|
+
if (!matchesValueType(field, value)) {
|
|
72
|
+
issues.push({
|
|
73
|
+
code: "invalid_prop_type",
|
|
74
|
+
path,
|
|
75
|
+
message: `${widget.type}.${key} \u9700\u8981 ${field.valueType} \u7C7B\u578B`
|
|
76
|
+
});
|
|
77
|
+
return false;
|
|
78
|
+
}
|
|
79
|
+
if (typeof value === "number" && field.minimum !== void 0 && value < field.minimum) {
|
|
80
|
+
issues.push({
|
|
81
|
+
code: "prop_below_minimum",
|
|
82
|
+
path,
|
|
83
|
+
message: `${widget.type}.${key} \u4E0D\u80FD\u5C0F\u4E8E ${field.minimum}`
|
|
84
|
+
});
|
|
85
|
+
return false;
|
|
86
|
+
}
|
|
87
|
+
if (typeof value === "number" && field.maximum !== void 0 && value > field.maximum) {
|
|
88
|
+
issues.push({
|
|
89
|
+
code: "prop_above_maximum",
|
|
90
|
+
path,
|
|
91
|
+
message: `${widget.type}.${key} \u4E0D\u80FD\u5927\u4E8E ${field.maximum}`
|
|
92
|
+
});
|
|
93
|
+
return false;
|
|
94
|
+
}
|
|
95
|
+
return true;
|
|
96
|
+
}
|
|
97
|
+
function validateProps(widget, props, container, scopeMode, path, issues) {
|
|
98
|
+
if (props === void 0)
|
|
99
|
+
return;
|
|
100
|
+
if (!props || typeof props !== "object" || Array.isArray(props)) {
|
|
101
|
+
issues.push({
|
|
102
|
+
code: "invalid_props",
|
|
103
|
+
path,
|
|
104
|
+
message: "props \u5FC5\u987B\u662F\u5BF9\u8C61"
|
|
105
|
+
});
|
|
106
|
+
return;
|
|
107
|
+
}
|
|
108
|
+
Object.entries(props).forEach(([key, value]) => {
|
|
109
|
+
const field = findFieldCapability(widget, key);
|
|
110
|
+
if (field && container === "props" && field.scope === "style") {
|
|
111
|
+
issues.push({
|
|
112
|
+
code: "style_field_in_props",
|
|
113
|
+
path: `${path}.${key}`,
|
|
114
|
+
message: `${widget.type}.${key} \u662F\u6837\u5F0F\u5B57\u6BB5\uFF0C\u5FC5\u987B\u5199\u5165 style`
|
|
115
|
+
});
|
|
116
|
+
return;
|
|
117
|
+
}
|
|
118
|
+
if (field && container === "style" && field.scope !== "style") {
|
|
119
|
+
issues.push({
|
|
120
|
+
code: "non_style_field_in_style",
|
|
121
|
+
path: `${path}.${key}`,
|
|
122
|
+
message: `${widget.type}.${key} \u4E0D\u662F\u6837\u5F0F\u5B57\u6BB5\uFF0C\u4E0D\u80FD\u5199\u5165 style`
|
|
123
|
+
});
|
|
124
|
+
return;
|
|
125
|
+
}
|
|
126
|
+
validateFieldValue(widget, key, value, scopeMode, `${path}.${key}`, issues);
|
|
127
|
+
});
|
|
128
|
+
}
|
|
129
|
+
function validateCustom(widget, custom, scopeMode, path, issues) {
|
|
130
|
+
if (custom === void 0)
|
|
131
|
+
return;
|
|
132
|
+
if (!Array.isArray(custom)) {
|
|
133
|
+
issues.push({
|
|
134
|
+
code: "invalid_custom_operations",
|
|
135
|
+
path,
|
|
136
|
+
message: "custom \u5FC5\u987B\u662F\u80FD\u529B\u64CD\u4F5C\u6570\u7EC4"
|
|
137
|
+
});
|
|
138
|
+
return;
|
|
139
|
+
}
|
|
140
|
+
custom.forEach((rawOperation, index) => {
|
|
141
|
+
const operation = asRecord(rawOperation);
|
|
142
|
+
const type = typeof operation.type === "string" ? operation.type : "";
|
|
143
|
+
const name = typeof operation.capability === "string" ? operation.capability : "";
|
|
144
|
+
const capability = findCustomCapability(widget, type, name);
|
|
145
|
+
if (!capability) {
|
|
146
|
+
issues.push({
|
|
147
|
+
code: "unsupported_capability",
|
|
148
|
+
path: `${path}[${index}]`,
|
|
149
|
+
message: `${widget.type} \u672A\u767B\u8BB0 custom type ${type} \u7684\u80FD\u529B ${name}`
|
|
150
|
+
});
|
|
151
|
+
return;
|
|
152
|
+
}
|
|
153
|
+
if (!allowsScope(scopeMode, capability.writableScope)) {
|
|
154
|
+
issues.push({
|
|
155
|
+
code: "scope_violation",
|
|
156
|
+
path: `${path}[${index}]`,
|
|
157
|
+
message: `\u80FD\u529B ${name} \u5C5E\u4E8E ${capability.writableScope}\uFF0C\u5F53\u524D scope \u4E0D\u5141\u8BB8\u5199\u5165`
|
|
158
|
+
});
|
|
159
|
+
}
|
|
160
|
+
});
|
|
161
|
+
}
|
|
162
|
+
function placementCount(placement) {
|
|
163
|
+
return ["afterUuid", "beforeUuid", "afterKey", "beforeKey"].filter((key) => typeof placement[key] === "string" && placement[key]).length;
|
|
164
|
+
}
|
|
165
|
+
function validateEditorDsl(input, options) {
|
|
166
|
+
const issues = [];
|
|
167
|
+
const dsl = asRecord(input);
|
|
168
|
+
const operations = Array.isArray(dsl.operations) ? dsl.operations : [];
|
|
169
|
+
const scope = asRecord(dsl.scope);
|
|
170
|
+
const scopeMode = scope.mode;
|
|
171
|
+
if (dsl.dslVersion !== "1.1") {
|
|
172
|
+
issues.push({
|
|
173
|
+
code: "unsupported_dsl_version",
|
|
174
|
+
path: "dslVersion",
|
|
175
|
+
message: "\u4EC5\u652F\u6301 dslVersion 1.1"
|
|
176
|
+
});
|
|
177
|
+
}
|
|
178
|
+
if (dsl.baseRevision !== options.snapshot.revision) {
|
|
179
|
+
issues.push({
|
|
180
|
+
code: "stale_revision",
|
|
181
|
+
path: "baseRevision",
|
|
182
|
+
message: `DSL \u57FA\u4E8E revision ${String(dsl.baseRevision)}\uFF0C\u5F53\u524D\u4E3A ${options.snapshot.revision}`
|
|
183
|
+
});
|
|
184
|
+
}
|
|
185
|
+
if (scopeMode !== "style_only" && scopeMode !== "content_only" && scopeMode !== "layout_only" && scopeMode !== "any") {
|
|
186
|
+
issues.push({
|
|
187
|
+
code: "invalid_scope",
|
|
188
|
+
path: "scope.mode",
|
|
189
|
+
message: "scope.mode \u5FC5\u987B\u662F style_only/content_only/layout_only/any"
|
|
190
|
+
});
|
|
191
|
+
}
|
|
192
|
+
const scopeTargets = Array.isArray(scope.targets) ? scope.targets.filter((target) => typeof target === "string") : [];
|
|
193
|
+
if (!operations.length) {
|
|
194
|
+
issues.push({
|
|
195
|
+
code: "empty_operations",
|
|
196
|
+
path: "operations",
|
|
197
|
+
message: "DSL \u81F3\u5C11\u9700\u8981\u4E00\u4E2A\u64CD\u4F5C"
|
|
198
|
+
});
|
|
199
|
+
}
|
|
200
|
+
const nodeUuids = new Set(options.snapshot.nodes.map((node) => node.uuid));
|
|
201
|
+
const addKeys = /* @__PURE__ */ new Set();
|
|
202
|
+
const normalizedOperations = [];
|
|
203
|
+
operations.forEach((rawOperation, index) => {
|
|
204
|
+
var _a, _b;
|
|
205
|
+
const operation = asRecord(rawOperation);
|
|
206
|
+
const path = `operations[${index}]`;
|
|
207
|
+
const op = operation.op;
|
|
208
|
+
if (op !== "add" && op !== "update" && op !== "delete") {
|
|
209
|
+
issues.push({
|
|
210
|
+
code: "unsupported_operation",
|
|
211
|
+
path: `${path}.op`,
|
|
212
|
+
message: `\u4E0D\u652F\u6301\u7684\u64CD\u4F5C ${String(op)}`
|
|
213
|
+
});
|
|
214
|
+
return;
|
|
215
|
+
}
|
|
216
|
+
if (op === "add") {
|
|
217
|
+
const key = typeof operation.key === "string" ? operation.key : "";
|
|
218
|
+
const widgetType = typeof operation.widget === "string" ? operation.widget : "";
|
|
219
|
+
const widget2 = findWidgetCapability(options.catalog, widgetType);
|
|
220
|
+
if (!key) {
|
|
221
|
+
issues.push({ code: "missing_key", path: `${path}.key`, message: "add \u5FC5\u987B\u63D0\u4F9B\u6279\u5185\u552F\u4E00 key" });
|
|
222
|
+
} else if (addKeys.has(key)) {
|
|
223
|
+
issues.push({ code: "duplicate_key", path: `${path}.key`, message: `\u6279\u5185 key \u91CD\u590D\uFF1A${key}` });
|
|
224
|
+
}
|
|
225
|
+
if (!widget2) {
|
|
226
|
+
issues.push({
|
|
227
|
+
code: "unknown_widget",
|
|
228
|
+
path: `${path}.widget`,
|
|
229
|
+
message: `\u7EC4\u4EF6\u80FD\u529B\u76EE\u5F55\u4E2D\u4E0D\u5B58\u5728 ${widgetType}`
|
|
230
|
+
});
|
|
231
|
+
}
|
|
232
|
+
const placement = asRecord(operation.placement);
|
|
233
|
+
if (placementCount(placement) > 1) {
|
|
234
|
+
issues.push({
|
|
235
|
+
code: "ambiguous_placement",
|
|
236
|
+
path: `${path}.placement`,
|
|
237
|
+
message: "placement \u53EA\u80FD\u6307\u5B9A\u4E00\u4E2A\u76F8\u5BF9\u4F4D\u7F6E"
|
|
238
|
+
});
|
|
239
|
+
}
|
|
240
|
+
for (const keyName of ["afterKey", "beforeKey"]) {
|
|
241
|
+
const reference = typeof placement[keyName] === "string" ? placement[keyName] : "";
|
|
242
|
+
if (reference && !addKeys.has(reference)) {
|
|
243
|
+
issues.push({
|
|
244
|
+
code: "unknown_batch_key",
|
|
245
|
+
path: `${path}.placement.${keyName}`,
|
|
246
|
+
message: `\u6279\u5185 key ${reference} \u5C1A\u672A\u521B\u5EFA`
|
|
247
|
+
});
|
|
248
|
+
}
|
|
249
|
+
}
|
|
250
|
+
for (const uuidName of ["afterUuid", "beforeUuid"]) {
|
|
251
|
+
const reference = typeof placement[uuidName] === "string" ? placement[uuidName] : "";
|
|
252
|
+
if (reference && !nodeUuids.has(reference)) {
|
|
253
|
+
issues.push({
|
|
254
|
+
code: "unknown_node",
|
|
255
|
+
path: `${path}.placement.${uuidName}`,
|
|
256
|
+
message: `\u8282\u70B9 ${reference} \u4E0D\u5B58\u5728`
|
|
257
|
+
});
|
|
258
|
+
}
|
|
259
|
+
}
|
|
260
|
+
if (widget2) {
|
|
261
|
+
const customOperations = operation.custom === void 0 ? [] : operation.custom;
|
|
262
|
+
validateProps(widget2, operation.props, "props", scopeMode, `${path}.props`, issues);
|
|
263
|
+
validateProps(widget2, operation.style, "style", scopeMode, `${path}.style`, issues);
|
|
264
|
+
validateCustom(widget2, customOperations, scopeMode, `${path}.custom`, issues);
|
|
265
|
+
}
|
|
266
|
+
if (key)
|
|
267
|
+
addKeys.add(key);
|
|
268
|
+
normalizedOperations.push({
|
|
269
|
+
op,
|
|
270
|
+
key,
|
|
271
|
+
widget: widgetType,
|
|
272
|
+
placement,
|
|
273
|
+
props: asRecord(operation.props),
|
|
274
|
+
style: asRecord(operation.style),
|
|
275
|
+
custom: Array.isArray(operation.custom) ? operation.custom : []
|
|
276
|
+
});
|
|
277
|
+
return;
|
|
278
|
+
}
|
|
279
|
+
const uuid = typeof operation.uuid === "string" ? operation.uuid : "";
|
|
280
|
+
const node = options.snapshot.nodes.find((item) => item.uuid === uuid);
|
|
281
|
+
if (!node) {
|
|
282
|
+
issues.push({
|
|
283
|
+
code: "unknown_node",
|
|
284
|
+
path: `${path}.uuid`,
|
|
285
|
+
message: `\u8282\u70B9 ${uuid || "(\u7A7A)"} \u4E0D\u5B58\u5728`
|
|
286
|
+
});
|
|
287
|
+
}
|
|
288
|
+
if (scopeTargets.length && !scopeTargets.includes(uuid)) {
|
|
289
|
+
issues.push({
|
|
290
|
+
code: "target_outside_scope",
|
|
291
|
+
path: `${path}.uuid`,
|
|
292
|
+
message: `\u8282\u70B9 ${uuid} \u4E0D\u5728 scope.targets \u5185`
|
|
293
|
+
});
|
|
294
|
+
}
|
|
295
|
+
if (op === "delete") {
|
|
296
|
+
if (!operation.confirmToken) {
|
|
297
|
+
issues.push({
|
|
298
|
+
code: "delete_confirmation_required",
|
|
299
|
+
path: `${path}.confirmToken`,
|
|
300
|
+
message: "\u5220\u9664\u64CD\u4F5C\u5FC5\u987B\u643A\u5E26\u4E00\u6B21\u6027\u786E\u8BA4\u4EE4\u724C"
|
|
301
|
+
});
|
|
302
|
+
} else if (!((_a = options.snapshot.confirmTokens) == null ? void 0 : _a.includes(String(operation.confirmToken)))) {
|
|
303
|
+
issues.push({
|
|
304
|
+
code: "invalid_confirm_token",
|
|
305
|
+
path: `${path}.confirmToken`,
|
|
306
|
+
message: "\u5220\u9664\u786E\u8BA4\u4EE4\u724C\u65E0\u6548\u6216\u5DF2\u8FC7\u671F"
|
|
307
|
+
});
|
|
308
|
+
}
|
|
309
|
+
normalizedOperations.push({ op, uuid, confirmToken: String((_b = operation.confirmToken) != null ? _b : "") });
|
|
310
|
+
return;
|
|
311
|
+
}
|
|
312
|
+
const widget = node ? findWidgetCapability(options.catalog, node.type) : void 0;
|
|
313
|
+
if (node && widget) {
|
|
314
|
+
validateProps(widget, operation.props, "props", scopeMode, `${path}.props`, issues);
|
|
315
|
+
validateProps(widget, operation.style, "style", scopeMode, `${path}.style`, issues);
|
|
316
|
+
validateCustom(widget, operation.custom, scopeMode, `${path}.custom`, issues);
|
|
317
|
+
}
|
|
318
|
+
normalizedOperations.push({
|
|
319
|
+
op,
|
|
320
|
+
uuid,
|
|
321
|
+
props: asRecord(operation.props),
|
|
322
|
+
style: asRecord(operation.style),
|
|
323
|
+
custom: Array.isArray(operation.custom) ? operation.custom : []
|
|
324
|
+
});
|
|
325
|
+
});
|
|
326
|
+
if (scopeTargets.some((target) => !nodeUuids.has(target))) {
|
|
327
|
+
issues.push({
|
|
328
|
+
code: "unknown_scope_target",
|
|
329
|
+
path: "scope.targets",
|
|
330
|
+
message: "scope.targets \u5305\u542B\u4E0D\u5B58\u5728\u7684\u8282\u70B9"
|
|
331
|
+
});
|
|
332
|
+
}
|
|
333
|
+
return __spreadValues({
|
|
334
|
+
ok: issues.length === 0,
|
|
335
|
+
issues
|
|
336
|
+
}, issues.length ? {} : {
|
|
337
|
+
normalized: {
|
|
338
|
+
dslVersion: "1.1",
|
|
339
|
+
baseRevision: options.snapshot.revision,
|
|
340
|
+
scope: {
|
|
341
|
+
mode: scopeMode,
|
|
342
|
+
targets: scopeTargets
|
|
343
|
+
},
|
|
344
|
+
operations: normalizedOperations
|
|
345
|
+
}
|
|
346
|
+
});
|
|
347
|
+
}
|
|
348
|
+
function isStyleField(widget, key) {
|
|
349
|
+
var _a;
|
|
350
|
+
return ((_a = findFieldCapability(widget, key)) == null ? void 0 : _a.scope) === "style";
|
|
351
|
+
}
|
|
352
|
+
function isKnownScope(value) {
|
|
353
|
+
return isScope(value);
|
|
354
|
+
}
|
|
355
|
+
|
|
356
|
+
export {
|
|
357
|
+
validateEditorDsl,
|
|
358
|
+
isStyleField,
|
|
359
|
+
isKnownScope
|
|
360
|
+
};
|
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
import {
|
|
2
|
+
__spreadProps,
|
|
3
|
+
__spreadValues
|
|
4
|
+
} from "./chunk-6FNC3XMI.js";
|
|
5
|
+
|
|
6
|
+
// src/capability.ts
|
|
7
|
+
function optionValues(item) {
|
|
8
|
+
if (!("options" in item) || !Array.isArray(item.options))
|
|
9
|
+
return;
|
|
10
|
+
return item.options.map((option) => option && typeof option === "object" ? option.value : void 0).filter((value) => value !== void 0);
|
|
11
|
+
}
|
|
12
|
+
function fieldFromSchema(item, scope) {
|
|
13
|
+
var _a, _b, _c;
|
|
14
|
+
if (item.type === "custom")
|
|
15
|
+
return;
|
|
16
|
+
let valueType = "unknown";
|
|
17
|
+
let enumValues;
|
|
18
|
+
let minimum;
|
|
19
|
+
let maximum;
|
|
20
|
+
switch (item.type) {
|
|
21
|
+
case "input":
|
|
22
|
+
case "colorPicker":
|
|
23
|
+
case "datetimePicker":
|
|
24
|
+
valueType = "string";
|
|
25
|
+
break;
|
|
26
|
+
case "number":
|
|
27
|
+
case "styleNumber":
|
|
28
|
+
valueType = "number";
|
|
29
|
+
minimum = typeof ((_a = item.attrs) == null ? void 0 : _a.min) === "number" ? item.attrs.min : void 0;
|
|
30
|
+
maximum = typeof ((_b = item.attrs) == null ? void 0 : _b.max) === "number" ? item.attrs.max : void 0;
|
|
31
|
+
break;
|
|
32
|
+
case "switch":
|
|
33
|
+
if ("attrs" in item && item.attrs && ("activeValue" in item.attrs || "inactiveValue" in item.attrs)) {
|
|
34
|
+
valueType = "enum";
|
|
35
|
+
enumValues = [
|
|
36
|
+
item.attrs.activeValue,
|
|
37
|
+
item.attrs.inactiveValue
|
|
38
|
+
].filter((value) => value !== void 0);
|
|
39
|
+
} else {
|
|
40
|
+
valueType = "boolean";
|
|
41
|
+
}
|
|
42
|
+
break;
|
|
43
|
+
case "checkbox":
|
|
44
|
+
valueType = "boolean";
|
|
45
|
+
break;
|
|
46
|
+
case "select":
|
|
47
|
+
case "radio":
|
|
48
|
+
case "radioButton":
|
|
49
|
+
valueType = "enum";
|
|
50
|
+
enumValues = optionValues(item);
|
|
51
|
+
break;
|
|
52
|
+
}
|
|
53
|
+
const rules = Array.isArray(item.rules) ? item.rules : item.rules ? [item.rules] : [];
|
|
54
|
+
return {
|
|
55
|
+
source: "prop",
|
|
56
|
+
key: item.key,
|
|
57
|
+
label: item.label,
|
|
58
|
+
valueType,
|
|
59
|
+
scope: (_c = item.scope) != null ? _c : scope,
|
|
60
|
+
required: rules.some((rule) => rule.required === true),
|
|
61
|
+
readOnly: item.readOnly === true,
|
|
62
|
+
enum: enumValues,
|
|
63
|
+
minimum,
|
|
64
|
+
maximum
|
|
65
|
+
};
|
|
66
|
+
}
|
|
67
|
+
function registeredCustomTypes(registration) {
|
|
68
|
+
var _a;
|
|
69
|
+
return ((_a = registration == null ? void 0 : registration.customTypes) != null ? _a : []).map((type) => ({
|
|
70
|
+
type: type.type,
|
|
71
|
+
capabilities: type.capabilities.map((capability) => __spreadValues({}, capability))
|
|
72
|
+
}));
|
|
73
|
+
}
|
|
74
|
+
function schemaCustomTypes(widget) {
|
|
75
|
+
var _a, _b;
|
|
76
|
+
return ((_b = (_a = widget.schema) == null ? void 0 : _a.props) != null ? _b : []).filter((item) => item.type === "custom").map((item) => item.name);
|
|
77
|
+
}
|
|
78
|
+
function createCapabilityCatalog(widgets, registry = {}) {
|
|
79
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l;
|
|
80
|
+
const catalog = {
|
|
81
|
+
catalogVersion: "1.0",
|
|
82
|
+
widgets: []
|
|
83
|
+
};
|
|
84
|
+
for (const widget of widgets) {
|
|
85
|
+
const registration = registry[widget._view];
|
|
86
|
+
const declared = registeredCustomTypes(registration);
|
|
87
|
+
const declaredMap = new Map(declared.map((type) => [type.type, type]));
|
|
88
|
+
const customTypes = schemaCustomTypes(widget).map((type) => {
|
|
89
|
+
var _a2;
|
|
90
|
+
return (_a2 = declaredMap.get(type)) != null ? _a2 : { type, capabilities: [] };
|
|
91
|
+
});
|
|
92
|
+
catalog.widgets.push({
|
|
93
|
+
type: widget._view,
|
|
94
|
+
name: widget._name,
|
|
95
|
+
description: (_e = (_d = (_a = widget.agent) == null ? void 0 : _a.description) != null ? _d : (_c = (_b = widget.agent) == null ? void 0 : _b.layout) == null ? void 0 : _c.description) != null ? _e : "",
|
|
96
|
+
defaultData: JSON.parse(JSON.stringify((_f = widget.data) != null ? _f : {})),
|
|
97
|
+
defaultStyle: JSON.parse(JSON.stringify((_g = widget.style) != null ? _g : {})),
|
|
98
|
+
fields: [
|
|
99
|
+
...((_i = (_h = widget.schema) == null ? void 0 : _h.props) != null ? _i : []).map((item) => fieldFromSchema(item, "content")).filter((item) => Boolean(item)),
|
|
100
|
+
...((_k = (_j = widget.schema) == null ? void 0 : _j.style) != null ? _k : []).map((item) => fieldFromSchema(item, "style")).filter((item) => Boolean(item))
|
|
101
|
+
],
|
|
102
|
+
customTypes,
|
|
103
|
+
staticOptions: ((_l = registration == null ? void 0 : registration.staticOptions) != null ? _l : []).map((option) => __spreadProps(__spreadValues({}, option), {
|
|
104
|
+
aliases: [...option.aliases],
|
|
105
|
+
types: [...option.types]
|
|
106
|
+
}))
|
|
107
|
+
});
|
|
108
|
+
}
|
|
109
|
+
return catalog;
|
|
110
|
+
}
|
|
111
|
+
function findWidgetCapability(catalog, type) {
|
|
112
|
+
return catalog.widgets.find((widget) => widget.type === type);
|
|
113
|
+
}
|
|
114
|
+
function findFieldCapability(widget, key) {
|
|
115
|
+
return widget.fields.find((field) => field.key === key);
|
|
116
|
+
}
|
|
117
|
+
function findCustomCapability(widget, type, name) {
|
|
118
|
+
var _a;
|
|
119
|
+
return (_a = widget.customTypes.find((item) => item.type === type)) == null ? void 0 : _a.capabilities.find((capability) => capability.name === name);
|
|
120
|
+
}
|
|
121
|
+
function listStaticOptions(catalog, widgetTypes, types) {
|
|
122
|
+
const selected = (widgetTypes == null ? void 0 : widgetTypes.length) ? catalog.widgets.filter((widget) => widgetTypes.includes(widget.type)) : catalog.widgets;
|
|
123
|
+
return selected.flatMap((widget) => widget.staticOptions).filter((option) => !(types == null ? void 0 : types.length) || option.types.some((type) => types.includes(type)));
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
export {
|
|
127
|
+
createCapabilityCatalog,
|
|
128
|
+
findWidgetCapability,
|
|
129
|
+
findFieldCapability,
|
|
130
|
+
findCustomCapability,
|
|
131
|
+
listStaticOptions
|
|
132
|
+
};
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import 'vue';
|
|
1
|
+
import { W as Widget, I as IWidget } from '../capability-Ce3qGTm3.cjs';
|
|
3
2
|
import 'element-plus';
|
|
3
|
+
import 'vue';
|
|
4
4
|
import 'async-validator';
|
|
5
5
|
|
|
6
6
|
declare class Container extends Widget {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import 'vue';
|
|
1
|
+
import { W as Widget, I as IWidget } from '../capability-Ce3qGTm3.js';
|
|
3
2
|
import 'element-plus';
|
|
3
|
+
import 'vue';
|
|
4
4
|
import 'async-validator';
|
|
5
5
|
|
|
6
6
|
declare class Container extends Widget {
|
package/dist/class/Node.cjs
CHANGED
|
@@ -54,8 +54,7 @@ var __async = (__this, __arguments, generator) => {
|
|
|
54
54
|
// src/class/Node.ts
|
|
55
55
|
var Node_exports = {};
|
|
56
56
|
__export(Node_exports, {
|
|
57
|
-
Node: () => Node
|
|
58
|
-
RootNode: () => RootNode
|
|
57
|
+
Node: () => Node
|
|
59
58
|
});
|
|
60
59
|
module.exports = __toCommonJS(Node_exports);
|
|
61
60
|
var import_uuid = require("uuid");
|
|
@@ -150,22 +149,7 @@ var Node = class _Node {
|
|
|
150
149
|
return res;
|
|
151
150
|
}
|
|
152
151
|
};
|
|
153
|
-
var RootNode = class {
|
|
154
|
-
constructor(widget, info) {
|
|
155
|
-
this.level = 0;
|
|
156
|
-
this.list = [];
|
|
157
|
-
this.data = {};
|
|
158
|
-
this.style = {};
|
|
159
|
-
this.hovering = false;
|
|
160
|
-
this.dragging = false;
|
|
161
|
-
this.widget = widget;
|
|
162
|
-
this.wid = (0, import_uuid.v4)();
|
|
163
|
-
this.data = (info == null ? void 0 : info.props) || {};
|
|
164
|
-
this.style = (info == null ? void 0 : info.style) || {};
|
|
165
|
-
}
|
|
166
|
-
};
|
|
167
152
|
// Annotate the CommonJS export names for ESM import in node:
|
|
168
153
|
0 && (module.exports = {
|
|
169
|
-
Node
|
|
170
|
-
RootNode
|
|
154
|
+
Node
|
|
171
155
|
});
|
package/dist/class/Node.d.cts
CHANGED
package/dist/class/Node.d.ts
CHANGED
package/dist/class/Node.js
CHANGED
package/dist/class/Widget.d.cts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export { O as Option,
|
|
1
|
+
export { O as Option, a as RadioButtonOption, R as RadioOption, b as SchemaItem, S as SchemaItemCustom, W as Widget } from '../capability-Ce3qGTm3.cjs';
|
|
2
2
|
import 'vue';
|
|
3
3
|
import 'element-plus';
|
|
4
4
|
import 'async-validator';
|
package/dist/class/Widget.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export { O as Option,
|
|
1
|
+
export { O as Option, a as RadioButtonOption, R as RadioOption, b as SchemaItem, S as SchemaItemCustom, W as Widget } from '../capability-Ce3qGTm3.js';
|
|
2
2
|
import 'vue';
|
|
3
3
|
import 'element-plus';
|
|
4
4
|
import 'async-validator';
|
package/dist/class/index.cjs
CHANGED
|
@@ -66,7 +66,6 @@ var class_exports = {};
|
|
|
66
66
|
__export(class_exports, {
|
|
67
67
|
Container: () => Container,
|
|
68
68
|
Node: () => Node,
|
|
69
|
-
RootNode: () => RootNode,
|
|
70
69
|
Widget: () => Widget
|
|
71
70
|
});
|
|
72
71
|
module.exports = __toCommonJS(class_exports);
|
|
@@ -243,24 +242,9 @@ var Node = class _Node {
|
|
|
243
242
|
return res;
|
|
244
243
|
}
|
|
245
244
|
};
|
|
246
|
-
var RootNode = class {
|
|
247
|
-
constructor(widget, info) {
|
|
248
|
-
this.level = 0;
|
|
249
|
-
this.list = [];
|
|
250
|
-
this.data = {};
|
|
251
|
-
this.style = {};
|
|
252
|
-
this.hovering = false;
|
|
253
|
-
this.dragging = false;
|
|
254
|
-
this.widget = widget;
|
|
255
|
-
this.wid = (0, import_uuid.v4)();
|
|
256
|
-
this.data = (info == null ? void 0 : info.props) || {};
|
|
257
|
-
this.style = (info == null ? void 0 : info.style) || {};
|
|
258
|
-
}
|
|
259
|
-
};
|
|
260
245
|
// Annotate the CommonJS export names for ESM import in node:
|
|
261
246
|
0 && (module.exports = {
|
|
262
247
|
Container,
|
|
263
248
|
Node,
|
|
264
|
-
RootNode,
|
|
265
249
|
Widget
|
|
266
250
|
});
|
package/dist/class/index.d.cts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
export { Container } from './Container.cjs';
|
|
2
|
-
export { N as Node, O as Option,
|
|
3
|
-
import 'vue';
|
|
2
|
+
export { N as Node, O as Option, a as RadioButtonOption, R as RadioOption, b as SchemaItem, S as SchemaItemCustom, W as Widget } from '../capability-Ce3qGTm3.cjs';
|
|
4
3
|
import 'element-plus';
|
|
4
|
+
import 'vue';
|
|
5
5
|
import 'async-validator';
|
package/dist/class/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
export { Container } from './Container.js';
|
|
2
|
-
export { N as Node, O as Option,
|
|
3
|
-
import 'vue';
|
|
2
|
+
export { N as Node, O as Option, a as RadioButtonOption, R as RadioOption, b as SchemaItem, S as SchemaItemCustom, W as Widget } from '../capability-Ce3qGTm3.js';
|
|
4
3
|
import 'element-plus';
|
|
4
|
+
import 'vue';
|
|
5
5
|
import 'async-validator';
|
package/dist/class/index.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
+
import "../chunk-IQ5LOS7W.js";
|
|
2
|
+
import {
|
|
3
|
+
Node
|
|
4
|
+
} from "../chunk-RLMXVDJK.js";
|
|
1
5
|
import {
|
|
2
6
|
Container
|
|
3
7
|
} from "../chunk-VLEUQG7E.js";
|
|
4
|
-
import {
|
|
5
|
-
Node,
|
|
6
|
-
RootNode
|
|
7
|
-
} from "../chunk-KJZSF66T.js";
|
|
8
8
|
import {
|
|
9
9
|
Widget
|
|
10
10
|
} from "../chunk-CI6CS5LG.js";
|
|
@@ -12,6 +12,5 @@ import "../chunk-6FNC3XMI.js";
|
|
|
12
12
|
export {
|
|
13
13
|
Container,
|
|
14
14
|
Node,
|
|
15
|
-
RootNode,
|
|
16
15
|
Widget
|
|
17
16
|
};
|