@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,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 { W as Widget, I as IWidget } from '../
|
|
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 { W as Widget, I as IWidget } from '../
|
|
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.d.cts
CHANGED
package/dist/class/Node.d.ts
CHANGED
package/dist/class/Widget.d.cts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export { O as Option, a as RadioButtonOption, R as RadioOption, b as SchemaItem, S as SchemaItemCustom, W as Widget } from '../
|
|
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, a as RadioButtonOption, R as RadioOption, b as SchemaItem, S as SchemaItemCustom, W as Widget } from '../
|
|
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.d.cts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
export { Container } from './Container.cjs';
|
|
2
|
-
export { N as Node, O as Option, a as RadioButtonOption, R as RadioOption, b as SchemaItem, S as SchemaItemCustom, W as Widget } from '../
|
|
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, a as RadioButtonOption, R as RadioOption, b as SchemaItem, S as SchemaItemCustom, W as Widget } from '../
|
|
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
package/dist/dsl.cjs
ADDED
|
@@ -0,0 +1,405 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
6
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
+
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
8
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
9
|
+
var __spreadValues = (a, b) => {
|
|
10
|
+
for (var prop in b || (b = {}))
|
|
11
|
+
if (__hasOwnProp.call(b, prop))
|
|
12
|
+
__defNormalProp(a, prop, b[prop]);
|
|
13
|
+
if (__getOwnPropSymbols)
|
|
14
|
+
for (var prop of __getOwnPropSymbols(b)) {
|
|
15
|
+
if (__propIsEnum.call(b, prop))
|
|
16
|
+
__defNormalProp(a, prop, b[prop]);
|
|
17
|
+
}
|
|
18
|
+
return a;
|
|
19
|
+
};
|
|
20
|
+
var __export = (target, all) => {
|
|
21
|
+
for (var name in all)
|
|
22
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
23
|
+
};
|
|
24
|
+
var __copyProps = (to, from, except, desc) => {
|
|
25
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
26
|
+
for (let key of __getOwnPropNames(from))
|
|
27
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
28
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
29
|
+
}
|
|
30
|
+
return to;
|
|
31
|
+
};
|
|
32
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
33
|
+
|
|
34
|
+
// src/dsl.ts
|
|
35
|
+
var dsl_exports = {};
|
|
36
|
+
__export(dsl_exports, {
|
|
37
|
+
isKnownScope: () => isKnownScope,
|
|
38
|
+
isStyleField: () => isStyleField,
|
|
39
|
+
validateEditorDsl: () => validateEditorDsl
|
|
40
|
+
});
|
|
41
|
+
module.exports = __toCommonJS(dsl_exports);
|
|
42
|
+
|
|
43
|
+
// src/capability.ts
|
|
44
|
+
function findWidgetCapability(catalog, type) {
|
|
45
|
+
return catalog.widgets.find((widget) => widget.type === type);
|
|
46
|
+
}
|
|
47
|
+
function findFieldCapability(widget, key) {
|
|
48
|
+
return widget.fields.find((field) => field.key === key);
|
|
49
|
+
}
|
|
50
|
+
function findCustomCapability(widget, type, name) {
|
|
51
|
+
var _a;
|
|
52
|
+
return (_a = widget.customTypes.find((item) => item.type === type)) == null ? void 0 : _a.capabilities.find((capability) => capability.name === name);
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
// src/dsl.ts
|
|
56
|
+
function asRecord(value) {
|
|
57
|
+
return value && typeof value === "object" && !Array.isArray(value) ? value : {};
|
|
58
|
+
}
|
|
59
|
+
function isScope(value) {
|
|
60
|
+
return value === "style" || value === "content" || value === "layout";
|
|
61
|
+
}
|
|
62
|
+
function allowsScope(mode, scope) {
|
|
63
|
+
if (mode === "any")
|
|
64
|
+
return true;
|
|
65
|
+
return mode === "style_only" && scope === "style" || mode === "content_only" && scope === "content" || mode === "layout_only" && scope === "layout";
|
|
66
|
+
}
|
|
67
|
+
function matchesValueType(field, value) {
|
|
68
|
+
var _a, _b;
|
|
69
|
+
if (!field)
|
|
70
|
+
return false;
|
|
71
|
+
switch (field.valueType) {
|
|
72
|
+
case "string":
|
|
73
|
+
return typeof value === "string";
|
|
74
|
+
case "number":
|
|
75
|
+
return typeof value === "number" && Number.isFinite(value);
|
|
76
|
+
case "integer":
|
|
77
|
+
return Number.isInteger(value);
|
|
78
|
+
case "boolean":
|
|
79
|
+
return typeof value === "boolean";
|
|
80
|
+
case "enum":
|
|
81
|
+
return (_b = (_a = field.enum) == null ? void 0 : _a.some((item) => Object.is(item, value))) != null ? _b : true;
|
|
82
|
+
case "array":
|
|
83
|
+
return Array.isArray(value);
|
|
84
|
+
case "object":
|
|
85
|
+
return Boolean(value) && typeof value === "object" && !Array.isArray(value);
|
|
86
|
+
default:
|
|
87
|
+
return true;
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
function validateFieldValue(widget, key, value, scopeMode, path, issues) {
|
|
91
|
+
const field = findFieldCapability(widget, key);
|
|
92
|
+
if (!field) {
|
|
93
|
+
issues.push({
|
|
94
|
+
code: "unknown_prop",
|
|
95
|
+
path,
|
|
96
|
+
message: `${widget.type} \u6CA1\u6709\u767B\u8BB0\u6807\u51C6\u5B57\u6BB5 ${key}`
|
|
97
|
+
});
|
|
98
|
+
return false;
|
|
99
|
+
}
|
|
100
|
+
if (field.readOnly) {
|
|
101
|
+
issues.push({
|
|
102
|
+
code: "read_only_prop",
|
|
103
|
+
path,
|
|
104
|
+
message: `${widget.type}.${key} \u4E3A\u53EA\u8BFB\u5B57\u6BB5`
|
|
105
|
+
});
|
|
106
|
+
return false;
|
|
107
|
+
}
|
|
108
|
+
if (!allowsScope(scopeMode, field.scope)) {
|
|
109
|
+
issues.push({
|
|
110
|
+
code: "scope_violation",
|
|
111
|
+
path,
|
|
112
|
+
message: `${widget.type}.${key} \u5C5E\u4E8E ${field.scope}\uFF0C\u5F53\u524D scope \u4E0D\u5141\u8BB8\u5199\u5165`
|
|
113
|
+
});
|
|
114
|
+
return false;
|
|
115
|
+
}
|
|
116
|
+
if (!matchesValueType(field, value)) {
|
|
117
|
+
issues.push({
|
|
118
|
+
code: "invalid_prop_type",
|
|
119
|
+
path,
|
|
120
|
+
message: `${widget.type}.${key} \u9700\u8981 ${field.valueType} \u7C7B\u578B`
|
|
121
|
+
});
|
|
122
|
+
return false;
|
|
123
|
+
}
|
|
124
|
+
if (typeof value === "number" && field.minimum !== void 0 && value < field.minimum) {
|
|
125
|
+
issues.push({
|
|
126
|
+
code: "prop_below_minimum",
|
|
127
|
+
path,
|
|
128
|
+
message: `${widget.type}.${key} \u4E0D\u80FD\u5C0F\u4E8E ${field.minimum}`
|
|
129
|
+
});
|
|
130
|
+
return false;
|
|
131
|
+
}
|
|
132
|
+
if (typeof value === "number" && field.maximum !== void 0 && value > field.maximum) {
|
|
133
|
+
issues.push({
|
|
134
|
+
code: "prop_above_maximum",
|
|
135
|
+
path,
|
|
136
|
+
message: `${widget.type}.${key} \u4E0D\u80FD\u5927\u4E8E ${field.maximum}`
|
|
137
|
+
});
|
|
138
|
+
return false;
|
|
139
|
+
}
|
|
140
|
+
return true;
|
|
141
|
+
}
|
|
142
|
+
function validateProps(widget, props, container, scopeMode, path, issues) {
|
|
143
|
+
if (props === void 0)
|
|
144
|
+
return;
|
|
145
|
+
if (!props || typeof props !== "object" || Array.isArray(props)) {
|
|
146
|
+
issues.push({
|
|
147
|
+
code: "invalid_props",
|
|
148
|
+
path,
|
|
149
|
+
message: "props \u5FC5\u987B\u662F\u5BF9\u8C61"
|
|
150
|
+
});
|
|
151
|
+
return;
|
|
152
|
+
}
|
|
153
|
+
Object.entries(props).forEach(([key, value]) => {
|
|
154
|
+
const field = findFieldCapability(widget, key);
|
|
155
|
+
if (field && container === "props" && field.scope === "style") {
|
|
156
|
+
issues.push({
|
|
157
|
+
code: "style_field_in_props",
|
|
158
|
+
path: `${path}.${key}`,
|
|
159
|
+
message: `${widget.type}.${key} \u662F\u6837\u5F0F\u5B57\u6BB5\uFF0C\u5FC5\u987B\u5199\u5165 style`
|
|
160
|
+
});
|
|
161
|
+
return;
|
|
162
|
+
}
|
|
163
|
+
if (field && container === "style" && field.scope !== "style") {
|
|
164
|
+
issues.push({
|
|
165
|
+
code: "non_style_field_in_style",
|
|
166
|
+
path: `${path}.${key}`,
|
|
167
|
+
message: `${widget.type}.${key} \u4E0D\u662F\u6837\u5F0F\u5B57\u6BB5\uFF0C\u4E0D\u80FD\u5199\u5165 style`
|
|
168
|
+
});
|
|
169
|
+
return;
|
|
170
|
+
}
|
|
171
|
+
validateFieldValue(widget, key, value, scopeMode, `${path}.${key}`, issues);
|
|
172
|
+
});
|
|
173
|
+
}
|
|
174
|
+
function validateCustom(widget, custom, scopeMode, path, issues) {
|
|
175
|
+
if (custom === void 0)
|
|
176
|
+
return;
|
|
177
|
+
if (!Array.isArray(custom)) {
|
|
178
|
+
issues.push({
|
|
179
|
+
code: "invalid_custom_operations",
|
|
180
|
+
path,
|
|
181
|
+
message: "custom \u5FC5\u987B\u662F\u80FD\u529B\u64CD\u4F5C\u6570\u7EC4"
|
|
182
|
+
});
|
|
183
|
+
return;
|
|
184
|
+
}
|
|
185
|
+
custom.forEach((rawOperation, index) => {
|
|
186
|
+
const operation = asRecord(rawOperation);
|
|
187
|
+
const type = typeof operation.type === "string" ? operation.type : "";
|
|
188
|
+
const name = typeof operation.capability === "string" ? operation.capability : "";
|
|
189
|
+
const capability = findCustomCapability(widget, type, name);
|
|
190
|
+
if (!capability) {
|
|
191
|
+
issues.push({
|
|
192
|
+
code: "unsupported_capability",
|
|
193
|
+
path: `${path}[${index}]`,
|
|
194
|
+
message: `${widget.type} \u672A\u767B\u8BB0 custom type ${type} \u7684\u80FD\u529B ${name}`
|
|
195
|
+
});
|
|
196
|
+
return;
|
|
197
|
+
}
|
|
198
|
+
if (!allowsScope(scopeMode, capability.writableScope)) {
|
|
199
|
+
issues.push({
|
|
200
|
+
code: "scope_violation",
|
|
201
|
+
path: `${path}[${index}]`,
|
|
202
|
+
message: `\u80FD\u529B ${name} \u5C5E\u4E8E ${capability.writableScope}\uFF0C\u5F53\u524D scope \u4E0D\u5141\u8BB8\u5199\u5165`
|
|
203
|
+
});
|
|
204
|
+
}
|
|
205
|
+
});
|
|
206
|
+
}
|
|
207
|
+
function placementCount(placement) {
|
|
208
|
+
return ["afterUuid", "beforeUuid", "afterKey", "beforeKey"].filter((key) => typeof placement[key] === "string" && placement[key]).length;
|
|
209
|
+
}
|
|
210
|
+
function validateEditorDsl(input, options) {
|
|
211
|
+
const issues = [];
|
|
212
|
+
const dsl = asRecord(input);
|
|
213
|
+
const operations = Array.isArray(dsl.operations) ? dsl.operations : [];
|
|
214
|
+
const scope = asRecord(dsl.scope);
|
|
215
|
+
const scopeMode = scope.mode;
|
|
216
|
+
if (dsl.dslVersion !== "1.1") {
|
|
217
|
+
issues.push({
|
|
218
|
+
code: "unsupported_dsl_version",
|
|
219
|
+
path: "dslVersion",
|
|
220
|
+
message: "\u4EC5\u652F\u6301 dslVersion 1.1"
|
|
221
|
+
});
|
|
222
|
+
}
|
|
223
|
+
if (dsl.baseRevision !== options.snapshot.revision) {
|
|
224
|
+
issues.push({
|
|
225
|
+
code: "stale_revision",
|
|
226
|
+
path: "baseRevision",
|
|
227
|
+
message: `DSL \u57FA\u4E8E revision ${String(dsl.baseRevision)}\uFF0C\u5F53\u524D\u4E3A ${options.snapshot.revision}`
|
|
228
|
+
});
|
|
229
|
+
}
|
|
230
|
+
if (scopeMode !== "style_only" && scopeMode !== "content_only" && scopeMode !== "layout_only" && scopeMode !== "any") {
|
|
231
|
+
issues.push({
|
|
232
|
+
code: "invalid_scope",
|
|
233
|
+
path: "scope.mode",
|
|
234
|
+
message: "scope.mode \u5FC5\u987B\u662F style_only/content_only/layout_only/any"
|
|
235
|
+
});
|
|
236
|
+
}
|
|
237
|
+
const scopeTargets = Array.isArray(scope.targets) ? scope.targets.filter((target) => typeof target === "string") : [];
|
|
238
|
+
if (!operations.length) {
|
|
239
|
+
issues.push({
|
|
240
|
+
code: "empty_operations",
|
|
241
|
+
path: "operations",
|
|
242
|
+
message: "DSL \u81F3\u5C11\u9700\u8981\u4E00\u4E2A\u64CD\u4F5C"
|
|
243
|
+
});
|
|
244
|
+
}
|
|
245
|
+
const nodeUuids = new Set(options.snapshot.nodes.map((node) => node.uuid));
|
|
246
|
+
const addKeys = /* @__PURE__ */ new Set();
|
|
247
|
+
const normalizedOperations = [];
|
|
248
|
+
operations.forEach((rawOperation, index) => {
|
|
249
|
+
var _a, _b;
|
|
250
|
+
const operation = asRecord(rawOperation);
|
|
251
|
+
const path = `operations[${index}]`;
|
|
252
|
+
const op = operation.op;
|
|
253
|
+
if (op !== "add" && op !== "update" && op !== "delete") {
|
|
254
|
+
issues.push({
|
|
255
|
+
code: "unsupported_operation",
|
|
256
|
+
path: `${path}.op`,
|
|
257
|
+
message: `\u4E0D\u652F\u6301\u7684\u64CD\u4F5C ${String(op)}`
|
|
258
|
+
});
|
|
259
|
+
return;
|
|
260
|
+
}
|
|
261
|
+
if (op === "add") {
|
|
262
|
+
const key = typeof operation.key === "string" ? operation.key : "";
|
|
263
|
+
const widgetType = typeof operation.widget === "string" ? operation.widget : "";
|
|
264
|
+
const widget2 = findWidgetCapability(options.catalog, widgetType);
|
|
265
|
+
if (!key) {
|
|
266
|
+
issues.push({ code: "missing_key", path: `${path}.key`, message: "add \u5FC5\u987B\u63D0\u4F9B\u6279\u5185\u552F\u4E00 key" });
|
|
267
|
+
} else if (addKeys.has(key)) {
|
|
268
|
+
issues.push({ code: "duplicate_key", path: `${path}.key`, message: `\u6279\u5185 key \u91CD\u590D\uFF1A${key}` });
|
|
269
|
+
}
|
|
270
|
+
if (!widget2) {
|
|
271
|
+
issues.push({
|
|
272
|
+
code: "unknown_widget",
|
|
273
|
+
path: `${path}.widget`,
|
|
274
|
+
message: `\u7EC4\u4EF6\u80FD\u529B\u76EE\u5F55\u4E2D\u4E0D\u5B58\u5728 ${widgetType}`
|
|
275
|
+
});
|
|
276
|
+
}
|
|
277
|
+
const placement = asRecord(operation.placement);
|
|
278
|
+
if (placementCount(placement) > 1) {
|
|
279
|
+
issues.push({
|
|
280
|
+
code: "ambiguous_placement",
|
|
281
|
+
path: `${path}.placement`,
|
|
282
|
+
message: "placement \u53EA\u80FD\u6307\u5B9A\u4E00\u4E2A\u76F8\u5BF9\u4F4D\u7F6E"
|
|
283
|
+
});
|
|
284
|
+
}
|
|
285
|
+
for (const keyName of ["afterKey", "beforeKey"]) {
|
|
286
|
+
const reference = typeof placement[keyName] === "string" ? placement[keyName] : "";
|
|
287
|
+
if (reference && !addKeys.has(reference)) {
|
|
288
|
+
issues.push({
|
|
289
|
+
code: "unknown_batch_key",
|
|
290
|
+
path: `${path}.placement.${keyName}`,
|
|
291
|
+
message: `\u6279\u5185 key ${reference} \u5C1A\u672A\u521B\u5EFA`
|
|
292
|
+
});
|
|
293
|
+
}
|
|
294
|
+
}
|
|
295
|
+
for (const uuidName of ["afterUuid", "beforeUuid"]) {
|
|
296
|
+
const reference = typeof placement[uuidName] === "string" ? placement[uuidName] : "";
|
|
297
|
+
if (reference && !nodeUuids.has(reference)) {
|
|
298
|
+
issues.push({
|
|
299
|
+
code: "unknown_node",
|
|
300
|
+
path: `${path}.placement.${uuidName}`,
|
|
301
|
+
message: `\u8282\u70B9 ${reference} \u4E0D\u5B58\u5728`
|
|
302
|
+
});
|
|
303
|
+
}
|
|
304
|
+
}
|
|
305
|
+
if (widget2) {
|
|
306
|
+
const customOperations = operation.custom === void 0 ? [] : operation.custom;
|
|
307
|
+
validateProps(widget2, operation.props, "props", scopeMode, `${path}.props`, issues);
|
|
308
|
+
validateProps(widget2, operation.style, "style", scopeMode, `${path}.style`, issues);
|
|
309
|
+
validateCustom(widget2, customOperations, scopeMode, `${path}.custom`, issues);
|
|
310
|
+
}
|
|
311
|
+
if (key)
|
|
312
|
+
addKeys.add(key);
|
|
313
|
+
normalizedOperations.push({
|
|
314
|
+
op,
|
|
315
|
+
key,
|
|
316
|
+
widget: widgetType,
|
|
317
|
+
placement,
|
|
318
|
+
props: asRecord(operation.props),
|
|
319
|
+
style: asRecord(operation.style),
|
|
320
|
+
custom: Array.isArray(operation.custom) ? operation.custom : []
|
|
321
|
+
});
|
|
322
|
+
return;
|
|
323
|
+
}
|
|
324
|
+
const uuid = typeof operation.uuid === "string" ? operation.uuid : "";
|
|
325
|
+
const node = options.snapshot.nodes.find((item) => item.uuid === uuid);
|
|
326
|
+
if (!node) {
|
|
327
|
+
issues.push({
|
|
328
|
+
code: "unknown_node",
|
|
329
|
+
path: `${path}.uuid`,
|
|
330
|
+
message: `\u8282\u70B9 ${uuid || "(\u7A7A)"} \u4E0D\u5B58\u5728`
|
|
331
|
+
});
|
|
332
|
+
}
|
|
333
|
+
if (scopeTargets.length && !scopeTargets.includes(uuid)) {
|
|
334
|
+
issues.push({
|
|
335
|
+
code: "target_outside_scope",
|
|
336
|
+
path: `${path}.uuid`,
|
|
337
|
+
message: `\u8282\u70B9 ${uuid} \u4E0D\u5728 scope.targets \u5185`
|
|
338
|
+
});
|
|
339
|
+
}
|
|
340
|
+
if (op === "delete") {
|
|
341
|
+
if (!operation.confirmToken) {
|
|
342
|
+
issues.push({
|
|
343
|
+
code: "delete_confirmation_required",
|
|
344
|
+
path: `${path}.confirmToken`,
|
|
345
|
+
message: "\u5220\u9664\u64CD\u4F5C\u5FC5\u987B\u643A\u5E26\u4E00\u6B21\u6027\u786E\u8BA4\u4EE4\u724C"
|
|
346
|
+
});
|
|
347
|
+
} else if (!((_a = options.snapshot.confirmTokens) == null ? void 0 : _a.includes(String(operation.confirmToken)))) {
|
|
348
|
+
issues.push({
|
|
349
|
+
code: "invalid_confirm_token",
|
|
350
|
+
path: `${path}.confirmToken`,
|
|
351
|
+
message: "\u5220\u9664\u786E\u8BA4\u4EE4\u724C\u65E0\u6548\u6216\u5DF2\u8FC7\u671F"
|
|
352
|
+
});
|
|
353
|
+
}
|
|
354
|
+
normalizedOperations.push({ op, uuid, confirmToken: String((_b = operation.confirmToken) != null ? _b : "") });
|
|
355
|
+
return;
|
|
356
|
+
}
|
|
357
|
+
const widget = node ? findWidgetCapability(options.catalog, node.type) : void 0;
|
|
358
|
+
if (node && widget) {
|
|
359
|
+
validateProps(widget, operation.props, "props", scopeMode, `${path}.props`, issues);
|
|
360
|
+
validateProps(widget, operation.style, "style", scopeMode, `${path}.style`, issues);
|
|
361
|
+
validateCustom(widget, operation.custom, scopeMode, `${path}.custom`, issues);
|
|
362
|
+
}
|
|
363
|
+
normalizedOperations.push({
|
|
364
|
+
op,
|
|
365
|
+
uuid,
|
|
366
|
+
props: asRecord(operation.props),
|
|
367
|
+
style: asRecord(operation.style),
|
|
368
|
+
custom: Array.isArray(operation.custom) ? operation.custom : []
|
|
369
|
+
});
|
|
370
|
+
});
|
|
371
|
+
if (scopeTargets.some((target) => !nodeUuids.has(target))) {
|
|
372
|
+
issues.push({
|
|
373
|
+
code: "unknown_scope_target",
|
|
374
|
+
path: "scope.targets",
|
|
375
|
+
message: "scope.targets \u5305\u542B\u4E0D\u5B58\u5728\u7684\u8282\u70B9"
|
|
376
|
+
});
|
|
377
|
+
}
|
|
378
|
+
return __spreadValues({
|
|
379
|
+
ok: issues.length === 0,
|
|
380
|
+
issues
|
|
381
|
+
}, issues.length ? {} : {
|
|
382
|
+
normalized: {
|
|
383
|
+
dslVersion: "1.1",
|
|
384
|
+
baseRevision: options.snapshot.revision,
|
|
385
|
+
scope: {
|
|
386
|
+
mode: scopeMode,
|
|
387
|
+
targets: scopeTargets
|
|
388
|
+
},
|
|
389
|
+
operations: normalizedOperations
|
|
390
|
+
}
|
|
391
|
+
});
|
|
392
|
+
}
|
|
393
|
+
function isStyleField(widget, key) {
|
|
394
|
+
var _a;
|
|
395
|
+
return ((_a = findFieldCapability(widget, key)) == null ? void 0 : _a.scope) === "style";
|
|
396
|
+
}
|
|
397
|
+
function isKnownScope(value) {
|
|
398
|
+
return isScope(value);
|
|
399
|
+
}
|
|
400
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
401
|
+
0 && (module.exports = {
|
|
402
|
+
isKnownScope,
|
|
403
|
+
isStyleField,
|
|
404
|
+
validateEditorDsl
|
|
405
|
+
});
|