@sepveneto/dnde-core 0.6.4 → 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-CnqlVnWy.d.cts → capability-Ce3qGTm3.d.cts} +184 -107
- package/dist/{Node-CnqlVnWy.d.ts → capability-Ce3qGTm3.d.ts} +184 -107
- 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-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.d.cts +1 -1
- package/dist/class/Node.d.ts +1 -1
- package/dist/class/Widget.d.cts +1 -1
- package/dist/class/Widget.d.ts +1 -1
- package/dist/class/index.d.cts +2 -2
- package/dist/class/index.d.ts +2 -2
- package/dist/class/index.js +3 -3
- 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 +484 -0
- package/dist/index.d.cts +3 -2
- package/dist/index.d.ts +3 -2
- package/dist/index.js +24 -4
- 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,172 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __defProps = Object.defineProperties;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
|
|
6
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
7
|
+
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
8
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
9
|
+
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
10
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
11
|
+
var __spreadValues = (a, b) => {
|
|
12
|
+
for (var prop in b || (b = {}))
|
|
13
|
+
if (__hasOwnProp.call(b, prop))
|
|
14
|
+
__defNormalProp(a, prop, b[prop]);
|
|
15
|
+
if (__getOwnPropSymbols)
|
|
16
|
+
for (var prop of __getOwnPropSymbols(b)) {
|
|
17
|
+
if (__propIsEnum.call(b, prop))
|
|
18
|
+
__defNormalProp(a, prop, b[prop]);
|
|
19
|
+
}
|
|
20
|
+
return a;
|
|
21
|
+
};
|
|
22
|
+
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
23
|
+
var __export = (target, all) => {
|
|
24
|
+
for (var name in all)
|
|
25
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
26
|
+
};
|
|
27
|
+
var __copyProps = (to, from, except, desc) => {
|
|
28
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
29
|
+
for (let key of __getOwnPropNames(from))
|
|
30
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
31
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
32
|
+
}
|
|
33
|
+
return to;
|
|
34
|
+
};
|
|
35
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
36
|
+
|
|
37
|
+
// src/capability.ts
|
|
38
|
+
var capability_exports = {};
|
|
39
|
+
__export(capability_exports, {
|
|
40
|
+
createCapabilityCatalog: () => createCapabilityCatalog,
|
|
41
|
+
findCustomCapability: () => findCustomCapability,
|
|
42
|
+
findFieldCapability: () => findFieldCapability,
|
|
43
|
+
findWidgetCapability: () => findWidgetCapability,
|
|
44
|
+
listStaticOptions: () => listStaticOptions
|
|
45
|
+
});
|
|
46
|
+
module.exports = __toCommonJS(capability_exports);
|
|
47
|
+
function optionValues(item) {
|
|
48
|
+
if (!("options" in item) || !Array.isArray(item.options))
|
|
49
|
+
return;
|
|
50
|
+
return item.options.map((option) => option && typeof option === "object" ? option.value : void 0).filter((value) => value !== void 0);
|
|
51
|
+
}
|
|
52
|
+
function fieldFromSchema(item, scope) {
|
|
53
|
+
var _a, _b, _c;
|
|
54
|
+
if (item.type === "custom")
|
|
55
|
+
return;
|
|
56
|
+
let valueType = "unknown";
|
|
57
|
+
let enumValues;
|
|
58
|
+
let minimum;
|
|
59
|
+
let maximum;
|
|
60
|
+
switch (item.type) {
|
|
61
|
+
case "input":
|
|
62
|
+
case "colorPicker":
|
|
63
|
+
case "datetimePicker":
|
|
64
|
+
valueType = "string";
|
|
65
|
+
break;
|
|
66
|
+
case "number":
|
|
67
|
+
case "styleNumber":
|
|
68
|
+
valueType = "number";
|
|
69
|
+
minimum = typeof ((_a = item.attrs) == null ? void 0 : _a.min) === "number" ? item.attrs.min : void 0;
|
|
70
|
+
maximum = typeof ((_b = item.attrs) == null ? void 0 : _b.max) === "number" ? item.attrs.max : void 0;
|
|
71
|
+
break;
|
|
72
|
+
case "switch":
|
|
73
|
+
if ("attrs" in item && item.attrs && ("activeValue" in item.attrs || "inactiveValue" in item.attrs)) {
|
|
74
|
+
valueType = "enum";
|
|
75
|
+
enumValues = [
|
|
76
|
+
item.attrs.activeValue,
|
|
77
|
+
item.attrs.inactiveValue
|
|
78
|
+
].filter((value) => value !== void 0);
|
|
79
|
+
} else {
|
|
80
|
+
valueType = "boolean";
|
|
81
|
+
}
|
|
82
|
+
break;
|
|
83
|
+
case "checkbox":
|
|
84
|
+
valueType = "boolean";
|
|
85
|
+
break;
|
|
86
|
+
case "select":
|
|
87
|
+
case "radio":
|
|
88
|
+
case "radioButton":
|
|
89
|
+
valueType = "enum";
|
|
90
|
+
enumValues = optionValues(item);
|
|
91
|
+
break;
|
|
92
|
+
}
|
|
93
|
+
const rules = Array.isArray(item.rules) ? item.rules : item.rules ? [item.rules] : [];
|
|
94
|
+
return {
|
|
95
|
+
source: "prop",
|
|
96
|
+
key: item.key,
|
|
97
|
+
label: item.label,
|
|
98
|
+
valueType,
|
|
99
|
+
scope: (_c = item.scope) != null ? _c : scope,
|
|
100
|
+
required: rules.some((rule) => rule.required === true),
|
|
101
|
+
readOnly: item.readOnly === true,
|
|
102
|
+
enum: enumValues,
|
|
103
|
+
minimum,
|
|
104
|
+
maximum
|
|
105
|
+
};
|
|
106
|
+
}
|
|
107
|
+
function registeredCustomTypes(registration) {
|
|
108
|
+
var _a;
|
|
109
|
+
return ((_a = registration == null ? void 0 : registration.customTypes) != null ? _a : []).map((type) => ({
|
|
110
|
+
type: type.type,
|
|
111
|
+
capabilities: type.capabilities.map((capability) => __spreadValues({}, capability))
|
|
112
|
+
}));
|
|
113
|
+
}
|
|
114
|
+
function schemaCustomTypes(widget) {
|
|
115
|
+
var _a, _b;
|
|
116
|
+
return ((_b = (_a = widget.schema) == null ? void 0 : _a.props) != null ? _b : []).filter((item) => item.type === "custom").map((item) => item.name);
|
|
117
|
+
}
|
|
118
|
+
function createCapabilityCatalog(widgets, registry = {}) {
|
|
119
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l;
|
|
120
|
+
const catalog = {
|
|
121
|
+
catalogVersion: "1.0",
|
|
122
|
+
widgets: []
|
|
123
|
+
};
|
|
124
|
+
for (const widget of widgets) {
|
|
125
|
+
const registration = registry[widget._view];
|
|
126
|
+
const declared = registeredCustomTypes(registration);
|
|
127
|
+
const declaredMap = new Map(declared.map((type) => [type.type, type]));
|
|
128
|
+
const customTypes = schemaCustomTypes(widget).map((type) => {
|
|
129
|
+
var _a2;
|
|
130
|
+
return (_a2 = declaredMap.get(type)) != null ? _a2 : { type, capabilities: [] };
|
|
131
|
+
});
|
|
132
|
+
catalog.widgets.push({
|
|
133
|
+
type: widget._view,
|
|
134
|
+
name: widget._name,
|
|
135
|
+
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 : "",
|
|
136
|
+
defaultData: JSON.parse(JSON.stringify((_f = widget.data) != null ? _f : {})),
|
|
137
|
+
defaultStyle: JSON.parse(JSON.stringify((_g = widget.style) != null ? _g : {})),
|
|
138
|
+
fields: [
|
|
139
|
+
...((_i = (_h = widget.schema) == null ? void 0 : _h.props) != null ? _i : []).map((item) => fieldFromSchema(item, "content")).filter((item) => Boolean(item)),
|
|
140
|
+
...((_k = (_j = widget.schema) == null ? void 0 : _j.style) != null ? _k : []).map((item) => fieldFromSchema(item, "style")).filter((item) => Boolean(item))
|
|
141
|
+
],
|
|
142
|
+
customTypes,
|
|
143
|
+
staticOptions: ((_l = registration == null ? void 0 : registration.staticOptions) != null ? _l : []).map((option) => __spreadProps(__spreadValues({}, option), {
|
|
144
|
+
aliases: [...option.aliases],
|
|
145
|
+
types: [...option.types]
|
|
146
|
+
}))
|
|
147
|
+
});
|
|
148
|
+
}
|
|
149
|
+
return catalog;
|
|
150
|
+
}
|
|
151
|
+
function findWidgetCapability(catalog, type) {
|
|
152
|
+
return catalog.widgets.find((widget) => widget.type === type);
|
|
153
|
+
}
|
|
154
|
+
function findFieldCapability(widget, key) {
|
|
155
|
+
return widget.fields.find((field) => field.key === key);
|
|
156
|
+
}
|
|
157
|
+
function findCustomCapability(widget, type, name) {
|
|
158
|
+
var _a;
|
|
159
|
+
return (_a = widget.customTypes.find((item) => item.type === type)) == null ? void 0 : _a.capabilities.find((capability) => capability.name === name);
|
|
160
|
+
}
|
|
161
|
+
function listStaticOptions(catalog, widgetTypes, types) {
|
|
162
|
+
const selected = (widgetTypes == null ? void 0 : widgetTypes.length) ? catalog.widgets.filter((widget) => widgetTypes.includes(widget.type)) : catalog.widgets;
|
|
163
|
+
return selected.flatMap((widget) => widget.staticOptions).filter((option) => !(types == null ? void 0 : types.length) || option.types.some((type) => types.includes(type)));
|
|
164
|
+
}
|
|
165
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
166
|
+
0 && (module.exports = {
|
|
167
|
+
createCapabilityCatalog,
|
|
168
|
+
findCustomCapability,
|
|
169
|
+
findFieldCapability,
|
|
170
|
+
findWidgetCapability,
|
|
171
|
+
listStaticOptions
|
|
172
|
+
});
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
export { j as CapabilityCatalog, C as CapabilityValueType, F as FieldScope, f as StaticOption, i as WidgetCapability, g as WidgetCapabilityRegistration, h as WidgetCapabilityRegistry, d as WidgetCustomCapability, e as WidgetCustomTypeCapability, c as WidgetFieldCapability, k as createCapabilityCatalog, n as findCustomCapability, m as findFieldCapability, l as findWidgetCapability, o as listStaticOptions } from './capability-Ce3qGTm3.cjs';
|
|
2
|
+
import 'element-plus';
|
|
3
|
+
import 'vue';
|
|
4
|
+
import 'async-validator';
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
export { j as CapabilityCatalog, C as CapabilityValueType, F as FieldScope, f as StaticOption, i as WidgetCapability, g as WidgetCapabilityRegistration, h as WidgetCapabilityRegistry, d as WidgetCustomCapability, e as WidgetCustomTypeCapability, c as WidgetFieldCapability, k as createCapabilityCatalog, n as findCustomCapability, m as findFieldCapability, l as findWidgetCapability, o as listStaticOptions } from './capability-Ce3qGTm3.js';
|
|
2
|
+
import 'element-plus';
|
|
3
|
+
import 'vue';
|
|
4
|
+
import 'async-validator';
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import {
|
|
2
|
+
createCapabilityCatalog,
|
|
3
|
+
findCustomCapability,
|
|
4
|
+
findFieldCapability,
|
|
5
|
+
findWidgetCapability,
|
|
6
|
+
listStaticOptions
|
|
7
|
+
} from "./chunk-XXR7SKZ3.js";
|
|
8
|
+
import "./chunk-6FNC3XMI.js";
|
|
9
|
+
export {
|
|
10
|
+
createCapabilityCatalog,
|
|
11
|
+
findCustomCapability,
|
|
12
|
+
findFieldCapability,
|
|
13
|
+
findWidgetCapability,
|
|
14
|
+
listStaticOptions
|
|
15
|
+
};
|
|
@@ -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
|
+
};
|