@ethereal-nexus/core 0.3.0 → 0.3.1
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/decorators/index.d.mts +2 -4
- package/dist/decorators/index.d.ts +2 -4
- package/dist/decorators/webcomponent/index.d.mts +2 -4
- package/dist/decorators/webcomponent/index.d.ts +2 -4
- package/dist/decorators/webcomponent/webcomponent.d.mts +1 -3
- package/dist/decorators/webcomponent/webcomponent.d.ts +1 -3
- package/dist/functions/component/component.d.mts +4 -6
- package/dist/functions/component/component.d.ts +4 -6
- package/dist/functions/component/component.js.map +1 -1
- package/dist/functions/component/component.mjs.map +1 -1
- package/dist/functions/component/index.d.mts +2 -4
- package/dist/functions/component/index.d.ts +2 -4
- package/dist/functions/component/index.js.map +1 -1
- package/dist/functions/component/index.mjs.map +1 -1
- package/dist/functions/index.d.mts +2 -4
- package/dist/functions/index.d.ts +2 -4
- package/dist/functions/index.js.map +1 -1
- package/dist/functions/index.mjs.map +1 -1
- package/dist/functions/parse/index.d.mts +2 -4
- package/dist/functions/parse/index.d.ts +2 -4
- package/dist/functions/parse/parse.d.mts +1 -3
- package/dist/functions/parse/parse.d.ts +1 -3
- package/dist/functions/parse/parsePrimitives.d.mts +1 -3
- package/dist/functions/parse/parsePrimitives.d.ts +1 -3
- package/dist/index.d.mts +4 -4
- package/dist/index.d.ts +4 -4
- package/dist/index.js +157 -65
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +157 -65
- package/dist/index.mjs.map +1 -1
- package/dist/schema/calendar/calendar.d.mts +2 -1
- package/dist/schema/calendar/calendar.d.ts +2 -1
- package/dist/schema/calendar/index.d.mts +2 -1
- package/dist/schema/calendar/index.d.ts +2 -1
- package/dist/schema/checkbox/checkbox.d.mts +2 -1
- package/dist/schema/checkbox/checkbox.d.ts +2 -1
- package/dist/schema/checkbox/index.d.mts +2 -1
- package/dist/schema/checkbox/index.d.ts +2 -1
- package/dist/schema/datamodel/datamodel.d.mts +2 -1
- package/dist/schema/datamodel/datamodel.d.ts +2 -1
- package/dist/schema/datamodel/index.d.mts +2 -1
- package/dist/schema/datamodel/index.d.ts +2 -1
- package/dist/schema/datasource/datasource.d.mts +2 -1
- package/dist/schema/datasource/datasource.d.ts +2 -1
- package/dist/schema/datasource/index.d.mts +2 -1
- package/dist/schema/datasource/index.d.ts +2 -1
- package/dist/schema/dialog/condition.d.mts +11 -0
- package/dist/schema/dialog/condition.d.ts +11 -0
- package/dist/schema/dialog/condition.js +72 -0
- package/dist/schema/dialog/condition.js.map +1 -0
- package/dist/schema/dialog/condition.mjs +49 -0
- package/dist/schema/dialog/condition.mjs.map +1 -0
- package/dist/schema/dialog/dialog.d.mts +28 -7
- package/dist/schema/dialog/dialog.d.ts +28 -7
- package/dist/schema/dialog/dialog.js +152 -63
- package/dist/schema/dialog/dialog.js.map +1 -1
- package/dist/schema/dialog/dialog.mjs +153 -64
- package/dist/schema/dialog/dialog.mjs.map +1 -1
- package/dist/schema/dialog/index.d.mts +3 -3
- package/dist/schema/dialog/index.d.ts +3 -3
- package/dist/schema/dialog/index.js +155 -64
- package/dist/schema/dialog/index.js.map +1 -1
- package/dist/schema/dialog/index.mjs +155 -64
- package/dist/schema/dialog/index.mjs.map +1 -1
- package/dist/schema/dialog/tabs.d.mts +20 -0
- package/dist/schema/dialog/tabs.d.ts +20 -0
- package/dist/schema/dialog/tabs.js +74 -0
- package/dist/schema/dialog/tabs.js.map +1 -0
- package/dist/schema/dialog/tabs.mjs +51 -0
- package/dist/schema/dialog/tabs.mjs.map +1 -0
- package/dist/schema/dialog/types.d.mts +3 -0
- package/dist/schema/dialog/types.d.ts +3 -0
- package/dist/schema/dialog/types.js +19 -0
- package/dist/schema/dialog/types.js.map +1 -0
- package/dist/schema/dialog/types.mjs +1 -0
- package/dist/schema/dialog/types.mjs.map +1 -0
- package/dist/schema/dynamic/dynamic.d.mts +2 -1
- package/dist/schema/dynamic/dynamic.d.ts +2 -1
- package/dist/schema/dynamic/index.d.mts +2 -1
- package/dist/schema/dynamic/index.d.ts +2 -1
- package/dist/schema/group/group.d.mts +2 -1
- package/dist/schema/group/group.d.ts +2 -1
- package/dist/schema/group/index.d.mts +2 -1
- package/dist/schema/group/index.d.ts +2 -1
- package/dist/schema/hidden/hidden.d.mts +2 -1
- package/dist/schema/hidden/hidden.d.ts +2 -1
- package/dist/schema/hidden/index.d.mts +2 -1
- package/dist/schema/hidden/index.d.ts +2 -1
- package/dist/schema/image/image.d.mts +2 -1
- package/dist/schema/image/image.d.ts +2 -1
- package/dist/schema/image/index.d.mts +2 -1
- package/dist/schema/image/index.d.ts +2 -1
- package/dist/schema/multifield/index.d.mts +2 -1
- package/dist/schema/multifield/index.d.ts +2 -1
- package/dist/schema/multifield/multifield.d.mts +2 -1
- package/dist/schema/multifield/multifield.d.ts +2 -1
- package/dist/schema/object/index.d.mts +1 -3
- package/dist/schema/object/index.d.ts +1 -3
- package/dist/schema/object/object.d.mts +1 -3
- package/dist/schema/object/object.d.ts +1 -3
- package/dist/schema/optional/index.d.mts +2 -2
- package/dist/schema/optional/index.d.ts +2 -2
- package/dist/schema/optional/optional.d.mts +2 -25
- package/dist/schema/optional/optional.d.ts +2 -25
- package/dist/schema/pathbrowser/index.d.mts +2 -1
- package/dist/schema/pathbrowser/index.d.ts +2 -1
- package/dist/schema/pathbrowser/pathbrowser.d.mts +2 -1
- package/dist/schema/pathbrowser/pathbrowser.d.ts +2 -1
- package/dist/schema/rte/index.d.mts +2 -1
- package/dist/schema/rte/index.d.ts +2 -1
- package/dist/schema/rte/rte.d.mts +2 -1
- package/dist/schema/rte/rte.d.ts +2 -1
- package/dist/schema/select/index.d.mts +2 -1
- package/dist/schema/select/index.d.ts +2 -1
- package/dist/schema/select/index.js +2 -1
- package/dist/schema/select/index.js.map +1 -1
- package/dist/schema/select/index.mjs +2 -1
- package/dist/schema/select/index.mjs.map +1 -1
- package/dist/schema/select/select.d.mts +13 -6
- package/dist/schema/select/select.d.ts +13 -6
- package/dist/schema/select/select.js +2 -1
- package/dist/schema/select/select.js.map +1 -1
- package/dist/schema/select/select.mjs +2 -1
- package/dist/schema/select/select.mjs.map +1 -1
- package/dist/schema/text/index.d.mts +2 -1
- package/dist/schema/text/index.d.ts +2 -1
- package/dist/schema/text/text.d.mts +2 -1
- package/dist/schema/text/text.d.ts +2 -1
- package/dist/types/index.d.mts +2 -2
- package/dist/types/index.d.ts +2 -2
- package/dist/types/infer.d.mts +2 -1
- package/dist/types/infer.d.ts +2 -1
- package/dist/types/object.d.mts +2 -44
- package/dist/types/object.d.ts +2 -44
- package/dist/types/schema.d.mts +3 -44
- package/dist/types/schema.d.ts +3 -44
- package/dist/types/schema.js.map +1 -1
- package/dist/types/utils.d.mts +52 -2
- package/dist/types/utils.d.ts +52 -2
- package/dist/types/utils.js.map +1 -1
- package/dist/types-B8taWezd.d.mts +131 -0
- package/dist/types-rfg_xywc.d.ts +131 -0
- package/dist/utils/pathToArray.d.mts +7 -0
- package/dist/utils/pathToArray.d.ts +7 -0
- package/dist/utils/pathToArray.js +42 -0
- package/dist/utils/pathToArray.js.map +1 -0
- package/dist/utils/pathToArray.mjs +17 -0
- package/dist/utils/pathToArray.mjs.map +1 -0
- package/package.json +2 -2
|
@@ -3,6 +3,7 @@ var __defProp = Object.defineProperty;
|
|
|
3
3
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
4
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
5
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
6
7
|
var __export = (target, all) => {
|
|
7
8
|
for (var name in all)
|
|
8
9
|
__defProp(target, name, { get: all[name], enumerable: true });
|
|
@@ -16,6 +17,7 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
16
17
|
return to;
|
|
17
18
|
};
|
|
18
19
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
20
|
+
var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
19
21
|
|
|
20
22
|
// src/schema/dialog/dialog.ts
|
|
21
23
|
var dialog_exports = {};
|
|
@@ -23,73 +25,160 @@ __export(dialog_exports, {
|
|
|
23
25
|
dialog: () => dialog
|
|
24
26
|
});
|
|
25
27
|
module.exports = __toCommonJS(dialog_exports);
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
type: "tab",
|
|
51
|
-
label: tabKey,
|
|
52
|
-
id: `tab_${tabKey.toLowerCase().replaceAll(" ", "")}`,
|
|
53
|
-
children
|
|
54
|
-
};
|
|
55
|
-
});
|
|
56
|
-
return {
|
|
57
|
-
dialog: [{
|
|
58
|
-
type: "tabs",
|
|
59
|
-
id: "tabs",
|
|
60
|
-
children: tabsArray
|
|
61
|
-
}]
|
|
62
|
-
};
|
|
28
|
+
|
|
29
|
+
// src/schema/dialog/tabs.ts
|
|
30
|
+
var Tabs = class {
|
|
31
|
+
constructor() {
|
|
32
|
+
__publicField(this, "tabs", /* @__PURE__ */ new Map());
|
|
33
|
+
}
|
|
34
|
+
addTab(name, entries) {
|
|
35
|
+
this.tabs.set(name, entries);
|
|
36
|
+
}
|
|
37
|
+
parse(entries) {
|
|
38
|
+
const result = [];
|
|
39
|
+
const usedEntries = /* @__PURE__ */ new Set();
|
|
40
|
+
if (this.tabs.size === 0) {
|
|
41
|
+
return entries;
|
|
42
|
+
}
|
|
43
|
+
for (const [name, mask] of this.tabs) {
|
|
44
|
+
const children = [];
|
|
45
|
+
if (!mask) {
|
|
46
|
+
throw new Error(`Entry "${String(name)}" does not have an appropriate tab configuration.`);
|
|
47
|
+
}
|
|
48
|
+
for (const [key] of Object.entries(mask)) {
|
|
49
|
+
const field = entries.find((f) => f.id === key);
|
|
50
|
+
if (usedEntries.has(key)) {
|
|
51
|
+
throw new Error(`Entry "${String(name)}.${String(key)}" is already used in another tab.`);
|
|
63
52
|
}
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
_parse() {
|
|
67
|
-
const dialog2 = Object.entries(entries).map(([key, entry]) => ({
|
|
68
|
-
id: key,
|
|
69
|
-
name: key,
|
|
70
|
-
...entry._parse()
|
|
71
|
-
})).filter((entry) => {
|
|
72
|
-
if ("type" in entry) {
|
|
73
|
-
return entry.type !== "hidden";
|
|
53
|
+
if (!field) {
|
|
54
|
+
throw new Error(`Field with id "${key}" not found`);
|
|
74
55
|
}
|
|
56
|
+
children.push(entries.find((f) => f.id === key));
|
|
57
|
+
}
|
|
58
|
+
result.push({
|
|
59
|
+
type: "tab",
|
|
60
|
+
label: name,
|
|
61
|
+
id: `tab_${name.toLowerCase().replaceAll(" ", "")}`,
|
|
62
|
+
children
|
|
75
63
|
});
|
|
76
|
-
return {
|
|
77
|
-
dialog: dialog2
|
|
78
|
-
};
|
|
79
|
-
},
|
|
80
|
-
_primitive() {
|
|
81
|
-
return Object.entries(entries).reduce(
|
|
82
|
-
(acc, [key, entry]) => {
|
|
83
|
-
const type = entry._primitive();
|
|
84
|
-
if (typeof type === "string") {
|
|
85
|
-
acc[key] = type;
|
|
86
|
-
}
|
|
87
|
-
return acc;
|
|
88
|
-
},
|
|
89
|
-
{}
|
|
90
|
-
);
|
|
91
64
|
}
|
|
92
|
-
|
|
65
|
+
return [{
|
|
66
|
+
type: "tabs",
|
|
67
|
+
id: "tabs",
|
|
68
|
+
children: result
|
|
69
|
+
}];
|
|
70
|
+
}
|
|
71
|
+
};
|
|
72
|
+
|
|
73
|
+
// src/schema/dialog/condition.ts
|
|
74
|
+
function addConditionToField(fields, path, condition) {
|
|
75
|
+
const keys = path.split(".");
|
|
76
|
+
let currentFields = fields;
|
|
77
|
+
for (let i = 0; i < keys.length; i++) {
|
|
78
|
+
const key = keys[i];
|
|
79
|
+
const field = currentFields.find((f) => f.id === key);
|
|
80
|
+
if (!field) {
|
|
81
|
+
throw new Error(`Field with id "${key}" not found`);
|
|
82
|
+
}
|
|
83
|
+
if (i === keys.length - 1) {
|
|
84
|
+
field.condition = condition;
|
|
85
|
+
} else {
|
|
86
|
+
if (!field.children) {
|
|
87
|
+
throw new Error(`Field with id "${key}" has no children`);
|
|
88
|
+
}
|
|
89
|
+
currentFields = field.children;
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
var Condition = class {
|
|
94
|
+
constructor() {
|
|
95
|
+
__publicField(this, "conditions", /* @__PURE__ */ new Map());
|
|
96
|
+
}
|
|
97
|
+
addCondition(field, condition) {
|
|
98
|
+
const operators = {
|
|
99
|
+
eq: (field2, value) => ({ operator: "eq", field: field2, value }),
|
|
100
|
+
neq: (field2, value) => ({ operator: "neq", field: field2, value }),
|
|
101
|
+
exists: (field2) => ({ operator: "exists", field: field2 }),
|
|
102
|
+
and: (...operations) => ({ operator: "and", value: operations }),
|
|
103
|
+
or: (...operations) => ({ operator: "or", value: operations })
|
|
104
|
+
};
|
|
105
|
+
this.conditions.set(field, condition(operators));
|
|
106
|
+
}
|
|
107
|
+
parse(entries) {
|
|
108
|
+
for (let [key, value] of this.conditions) {
|
|
109
|
+
addConditionToField(entries, key, value);
|
|
110
|
+
}
|
|
111
|
+
return entries;
|
|
112
|
+
}
|
|
113
|
+
};
|
|
114
|
+
|
|
115
|
+
// src/utils/pathToArray.ts
|
|
116
|
+
function pathToArray(obj, parentPath = []) {
|
|
117
|
+
const result = [];
|
|
118
|
+
for (const [key, value] of Object.entries(obj)) {
|
|
119
|
+
const currentPath = [...parentPath, key];
|
|
120
|
+
if (typeof value === "object" && !value.hasOwnProperty("operator") && !Array.isArray(value)) {
|
|
121
|
+
result.push(...pathToArray(value, currentPath));
|
|
122
|
+
} else {
|
|
123
|
+
result.push({ path: currentPath, value });
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
return result;
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
// src/schema/dialog/dialog.ts
|
|
130
|
+
var DialogBuilder = class {
|
|
131
|
+
constructor(entries) {
|
|
132
|
+
__publicField(this, "conditionsModule");
|
|
133
|
+
__publicField(this, "tabsModule");
|
|
134
|
+
__publicField(this, "entries");
|
|
135
|
+
__publicField(this, "type", "dialog");
|
|
136
|
+
this.entries = entries;
|
|
137
|
+
this.conditionsModule = new Condition();
|
|
138
|
+
this.tabsModule = new Tabs();
|
|
139
|
+
}
|
|
140
|
+
conditions(conditions) {
|
|
141
|
+
const conditionsArray = pathToArray(conditions);
|
|
142
|
+
for (const condition of conditionsArray) {
|
|
143
|
+
this.conditionsModule.addCondition(condition.path.join("."), condition.value);
|
|
144
|
+
}
|
|
145
|
+
return this;
|
|
146
|
+
}
|
|
147
|
+
tabs(tabs) {
|
|
148
|
+
for (const [key, tab] of Object.entries(tabs)) {
|
|
149
|
+
this.tabsModule.addTab(key, tab);
|
|
150
|
+
}
|
|
151
|
+
return this;
|
|
152
|
+
}
|
|
153
|
+
_parse() {
|
|
154
|
+
const dialog2 = Object.entries(this.entries).map(([key, entry]) => ({
|
|
155
|
+
id: key,
|
|
156
|
+
name: key,
|
|
157
|
+
...entry._parse()
|
|
158
|
+
})).filter((entry) => {
|
|
159
|
+
if ("type" in entry) {
|
|
160
|
+
return entry.type !== "hidden";
|
|
161
|
+
}
|
|
162
|
+
});
|
|
163
|
+
const dialogWithConditions = this.conditionsModule.parse(dialog2);
|
|
164
|
+
const dialogWithTabs = this.tabsModule.parse(dialogWithConditions);
|
|
165
|
+
return {
|
|
166
|
+
dialog: dialogWithTabs
|
|
167
|
+
};
|
|
168
|
+
}
|
|
169
|
+
_primitive() {
|
|
170
|
+
const result = {};
|
|
171
|
+
for (const [key, entry] of Object.entries(this.entries)) {
|
|
172
|
+
const type = entry._primitive();
|
|
173
|
+
if (typeof type === "string") {
|
|
174
|
+
result[key] = type;
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
return result;
|
|
178
|
+
}
|
|
179
|
+
};
|
|
180
|
+
function dialog(entries) {
|
|
181
|
+
return new DialogBuilder(entries);
|
|
93
182
|
}
|
|
94
183
|
// Annotate the CommonJS export names for ESM import in node:
|
|
95
184
|
0 && (module.exports = {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/schema/dialog/dialog.ts"],"sourcesContent":["import { BaseSchema, EntryMask } from '../../types';\nimport { WebcomponentPropTypes } from '../../types/webcomponent';\nimport {
|
|
1
|
+
{"version":3,"sources":["../../../src/schema/dialog/dialog.ts","../../../src/schema/dialog/tabs.ts","../../../src/schema/dialog/condition.ts","../../../src/utils/pathToArray.ts"],"sourcesContent":["import { BaseSchema, EntryMask, NestedPaths } from '../../types';\nimport { ObjectEntries, ObjectOutput } from '../../types/object';\nimport { Tabs } from './tabs';\nimport { WebcomponentPropTypes } from '../../types/webcomponent';\nimport { Condition } from './condition';\nimport { pathToArray } from '../../utils/pathToArray';\nimport { ConditionsArgument } from './types';\n\nexport interface DialogSchema<TEntries extends ObjectEntries> extends BaseSchema<ObjectOutput<TEntries>> {\n type: 'dialog';\n tabs: (tabs: Record<string, EntryMask<TEntries>>) => DialogSchema<TEntries>;\n conditions: (conditions: ConditionsArgument<TEntries>) => DialogSchema<TEntries>;\n}\n\nclass DialogBuilder<TEntries extends ObjectEntries> implements DialogSchema<TEntries> {\n private conditionsModule: Condition<TEntries>;\n private tabsModule: Tabs<TEntries>;\n private readonly entries: TEntries;\n readonly type = 'dialog';\n\n constructor(entries: TEntries) {\n this.entries = entries;\n this.conditionsModule = new Condition<TEntries>();\n this.tabsModule = new Tabs<TEntries>();\n }\n\n conditions(conditions: ConditionsArgument<TEntries>) {\n const conditionsArray = pathToArray(conditions)\n for (const condition of conditionsArray) {\n this.conditionsModule.addCondition(condition.path.join('.') as NestedPaths<TEntries>, condition.value);\n }\n return this;\n }\n\n tabs(tabs: Record<string, EntryMask<TEntries>>) {\n for (const [key, tab] of Object.entries(tabs)) {\n this.tabsModule.addTab(key as any, tab!);\n }\n return this;\n }\n\n _parse() {\n const dialog = Object.entries(this.entries)\n .map(([key, entry]) => ({\n id: key,\n name: key,\n ...entry._parse(),\n }))\n .filter((entry: object) => {\n if ('type' in entry) {\n return entry.type !== 'hidden';\n }\n });\n\n const dialogWithConditions = this.conditionsModule.parse(dialog);\n const dialogWithTabs = this.tabsModule.parse(dialogWithConditions);\n return {\n dialog: dialogWithTabs\n };\n }\n\n _primitive() {\n const result: Record<string, WebcomponentPropTypes> = {};\n\n for (const [key, entry] of Object.entries(this.entries)) {\n const type = entry._primitive();\n if (typeof type === 'string') {\n result[key] = type;\n }\n }\n\n return result;\n }\n}\n\nexport function dialog<TEntries extends ObjectEntries>(entries: TEntries) {\n return new DialogBuilder(entries)\n}","import { EntryMask } from '../../types';\nimport { Field } from './types';\n\nexport class Tabs<TEntries> {\n private tabs = new Map<string, EntryMask<TEntries>>();\n\n addTab(name: string, entries: EntryMask<TEntries>) {\n this.tabs.set(name, entries);\n }\n\n parse(entries: Field[]) {\n const result = []\n const usedEntries = new Set();\n\n if(this.tabs.size === 0) {\n return entries\n }\n\n for(const [name, mask] of this.tabs) {\n const children = []\n\n if(!mask) {\n throw new Error(`Entry \"${String(name)}\" does not have an appropriate tab configuration.`);\n }\n\n for(const [key,] of Object.entries(mask)) {\n const field = entries.find(f => f.id === key)\n\n if (usedEntries.has(key)) {\n throw new Error(`Entry \"${String(name)}.${String(key)}\" is already used in another tab.`);\n }\n\n if(!field) {\n throw new Error(`Field with id \"${key}\" not found`);\n }\n\n children.push(entries.find(f => f.id === key))\n }\n\n result.push({\n type: 'tab',\n label: name,\n id: `tab_${name.toLowerCase().replaceAll(' ', '')}`,\n children\n })\n }\n\n return [{\n type: 'tabs',\n id: 'tabs',\n children: result\n }]\n }\n}","import { NestedPaths } from '../../types';\nimport { ConditionFn, ConditionOperators, Conditions, Field } from './types';\nimport { ObjectEntries } from '../../types/object';\n\nfunction addConditionToField(fields: Field[], path: string, condition: Conditions): void {\n const keys = path.split('.');\n let currentFields = fields;\n\n for (let i = 0; i < keys.length; i++) {\n const key = keys[i];\n const field = currentFields.find(f => f.id === key);\n\n if (!field) {\n throw new Error(`Field with id \"${key}\" not found`);\n }\n\n if (i === keys.length - 1) {\n field.condition = condition;\n } else {\n if (!field.children) {\n throw new Error(`Field with id \"${key}\" has no children`);\n }\n currentFields = field.children;\n }\n }\n}\n\nexport class Condition<TEntries extends ObjectEntries> {\n private conditions = new Map<string, Conditions>();\n\n addCondition(field: NestedPaths<TEntries>, condition: ConditionFn<TEntries>) {\n const operators: ConditionOperators<TEntries> = {\n eq: (field, value) => ({ operator: 'eq', field, value }),\n neq: (field, value) => ({ operator: 'neq', field, value }),\n exists: (field) => ({ operator: 'exists', field }),\n and: (...operations) => ({ operator: 'and', value: operations }),\n or: (...operations) => ({ operator: 'or', value: operations })\n };\n\n this.conditions.set(field, condition(operators));\n }\n\n parse(entries: Field[]) {\n for (let [key, value] of this.conditions) {\n addConditionToField(entries, key, value)\n }\n\n return entries;\n }\n}\n","interface PathValue {\n path: string[];\n value: any;\n}\n\nexport function pathToArray(obj: Record<string, any>, parentPath: string[] = []): PathValue[] {\n const result: PathValue[] = [];\n\n for (const [key, value] of Object.entries(obj)) {\n const currentPath = [...parentPath, key];\n\n if (typeof value === 'object' && !value.hasOwnProperty('operator') && !Array.isArray(value)) {\n // If the value is an object, recurse into it\n result.push(...pathToArray(value, currentPath));\n } else {\n // If the value is not an object, store the path and value\n result.push({ path: currentPath, value });\n }\n }\n\n return result;\n}"],"mappings":";;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACGO,I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oBAAoB;AACjE,WAAO;AAAA,MACL,QAAQ;AAAA,IACV;AAAA,EACF;AAAA,EAEA,aAAa;AACX,UAAM,SAAgD,CAAC;AAEvD,eAAW,CAAC,KAAK,KAAK,KAAK,OAAO,QAAQ,KAAK,OAAO,GAAG;AACvD,YAAM,OAAO,MAAM,WAAW;AAC9B,UAAI,OAAO,SAAS,UAAU;AAC5B,eAAO,GAAG,IAAI;AAAA,MAChB;AAAA,IACF;AAEA,WAAO;AAAA,EACT;AACF;AAEO,SAAS,OAAuC,SAAmB;AACxE,SAAO,IAAI,cAAc,OAAO;AAClC;","names":["field","dialog"]}
|
|
@@ -1,71 +1,160 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
id: `tab_${tabKey.toLowerCase().replaceAll(" ", "")}`,
|
|
29
|
-
children
|
|
30
|
-
};
|
|
31
|
-
});
|
|
32
|
-
return {
|
|
33
|
-
dialog: [{
|
|
34
|
-
type: "tabs",
|
|
35
|
-
id: "tabs",
|
|
36
|
-
children: tabsArray
|
|
37
|
-
}]
|
|
38
|
-
};
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
3
|
+
var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
4
|
+
|
|
5
|
+
// src/schema/dialog/tabs.ts
|
|
6
|
+
var Tabs = class {
|
|
7
|
+
constructor() {
|
|
8
|
+
__publicField(this, "tabs", /* @__PURE__ */ new Map());
|
|
9
|
+
}
|
|
10
|
+
addTab(name, entries) {
|
|
11
|
+
this.tabs.set(name, entries);
|
|
12
|
+
}
|
|
13
|
+
parse(entries) {
|
|
14
|
+
const result = [];
|
|
15
|
+
const usedEntries = /* @__PURE__ */ new Set();
|
|
16
|
+
if (this.tabs.size === 0) {
|
|
17
|
+
return entries;
|
|
18
|
+
}
|
|
19
|
+
for (const [name, mask] of this.tabs) {
|
|
20
|
+
const children = [];
|
|
21
|
+
if (!mask) {
|
|
22
|
+
throw new Error(`Entry "${String(name)}" does not have an appropriate tab configuration.`);
|
|
23
|
+
}
|
|
24
|
+
for (const [key] of Object.entries(mask)) {
|
|
25
|
+
const field = entries.find((f) => f.id === key);
|
|
26
|
+
if (usedEntries.has(key)) {
|
|
27
|
+
throw new Error(`Entry "${String(name)}.${String(key)}" is already used in another tab.`);
|
|
39
28
|
}
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
_parse() {
|
|
43
|
-
const dialog2 = Object.entries(entries).map(([key, entry]) => ({
|
|
44
|
-
id: key,
|
|
45
|
-
name: key,
|
|
46
|
-
...entry._parse()
|
|
47
|
-
})).filter((entry) => {
|
|
48
|
-
if ("type" in entry) {
|
|
49
|
-
return entry.type !== "hidden";
|
|
29
|
+
if (!field) {
|
|
30
|
+
throw new Error(`Field with id "${key}" not found`);
|
|
50
31
|
}
|
|
32
|
+
children.push(entries.find((f) => f.id === key));
|
|
33
|
+
}
|
|
34
|
+
result.push({
|
|
35
|
+
type: "tab",
|
|
36
|
+
label: name,
|
|
37
|
+
id: `tab_${name.toLowerCase().replaceAll(" ", "")}`,
|
|
38
|
+
children
|
|
51
39
|
});
|
|
52
|
-
return {
|
|
53
|
-
dialog: dialog2
|
|
54
|
-
};
|
|
55
|
-
},
|
|
56
|
-
_primitive() {
|
|
57
|
-
return Object.entries(entries).reduce(
|
|
58
|
-
(acc, [key, entry]) => {
|
|
59
|
-
const type = entry._primitive();
|
|
60
|
-
if (typeof type === "string") {
|
|
61
|
-
acc[key] = type;
|
|
62
|
-
}
|
|
63
|
-
return acc;
|
|
64
|
-
},
|
|
65
|
-
{}
|
|
66
|
-
);
|
|
67
40
|
}
|
|
68
|
-
|
|
41
|
+
return [{
|
|
42
|
+
type: "tabs",
|
|
43
|
+
id: "tabs",
|
|
44
|
+
children: result
|
|
45
|
+
}];
|
|
46
|
+
}
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
// src/schema/dialog/condition.ts
|
|
50
|
+
function addConditionToField(fields, path, condition) {
|
|
51
|
+
const keys = path.split(".");
|
|
52
|
+
let currentFields = fields;
|
|
53
|
+
for (let i = 0; i < keys.length; i++) {
|
|
54
|
+
const key = keys[i];
|
|
55
|
+
const field = currentFields.find((f) => f.id === key);
|
|
56
|
+
if (!field) {
|
|
57
|
+
throw new Error(`Field with id "${key}" not found`);
|
|
58
|
+
}
|
|
59
|
+
if (i === keys.length - 1) {
|
|
60
|
+
field.condition = condition;
|
|
61
|
+
} else {
|
|
62
|
+
if (!field.children) {
|
|
63
|
+
throw new Error(`Field with id "${key}" has no children`);
|
|
64
|
+
}
|
|
65
|
+
currentFields = field.children;
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
var Condition = class {
|
|
70
|
+
constructor() {
|
|
71
|
+
__publicField(this, "conditions", /* @__PURE__ */ new Map());
|
|
72
|
+
}
|
|
73
|
+
addCondition(field, condition) {
|
|
74
|
+
const operators = {
|
|
75
|
+
eq: (field2, value) => ({ operator: "eq", field: field2, value }),
|
|
76
|
+
neq: (field2, value) => ({ operator: "neq", field: field2, value }),
|
|
77
|
+
exists: (field2) => ({ operator: "exists", field: field2 }),
|
|
78
|
+
and: (...operations) => ({ operator: "and", value: operations }),
|
|
79
|
+
or: (...operations) => ({ operator: "or", value: operations })
|
|
80
|
+
};
|
|
81
|
+
this.conditions.set(field, condition(operators));
|
|
82
|
+
}
|
|
83
|
+
parse(entries) {
|
|
84
|
+
for (let [key, value] of this.conditions) {
|
|
85
|
+
addConditionToField(entries, key, value);
|
|
86
|
+
}
|
|
87
|
+
return entries;
|
|
88
|
+
}
|
|
89
|
+
};
|
|
90
|
+
|
|
91
|
+
// src/utils/pathToArray.ts
|
|
92
|
+
function pathToArray(obj, parentPath = []) {
|
|
93
|
+
const result = [];
|
|
94
|
+
for (const [key, value] of Object.entries(obj)) {
|
|
95
|
+
const currentPath = [...parentPath, key];
|
|
96
|
+
if (typeof value === "object" && !value.hasOwnProperty("operator") && !Array.isArray(value)) {
|
|
97
|
+
result.push(...pathToArray(value, currentPath));
|
|
98
|
+
} else {
|
|
99
|
+
result.push({ path: currentPath, value });
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
return result;
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
// src/schema/dialog/dialog.ts
|
|
106
|
+
var DialogBuilder = class {
|
|
107
|
+
constructor(entries) {
|
|
108
|
+
__publicField(this, "conditionsModule");
|
|
109
|
+
__publicField(this, "tabsModule");
|
|
110
|
+
__publicField(this, "entries");
|
|
111
|
+
__publicField(this, "type", "dialog");
|
|
112
|
+
this.entries = entries;
|
|
113
|
+
this.conditionsModule = new Condition();
|
|
114
|
+
this.tabsModule = new Tabs();
|
|
115
|
+
}
|
|
116
|
+
conditions(conditions) {
|
|
117
|
+
const conditionsArray = pathToArray(conditions);
|
|
118
|
+
for (const condition of conditionsArray) {
|
|
119
|
+
this.conditionsModule.addCondition(condition.path.join("."), condition.value);
|
|
120
|
+
}
|
|
121
|
+
return this;
|
|
122
|
+
}
|
|
123
|
+
tabs(tabs) {
|
|
124
|
+
for (const [key, tab] of Object.entries(tabs)) {
|
|
125
|
+
this.tabsModule.addTab(key, tab);
|
|
126
|
+
}
|
|
127
|
+
return this;
|
|
128
|
+
}
|
|
129
|
+
_parse() {
|
|
130
|
+
const dialog2 = Object.entries(this.entries).map(([key, entry]) => ({
|
|
131
|
+
id: key,
|
|
132
|
+
name: key,
|
|
133
|
+
...entry._parse()
|
|
134
|
+
})).filter((entry) => {
|
|
135
|
+
if ("type" in entry) {
|
|
136
|
+
return entry.type !== "hidden";
|
|
137
|
+
}
|
|
138
|
+
});
|
|
139
|
+
const dialogWithConditions = this.conditionsModule.parse(dialog2);
|
|
140
|
+
const dialogWithTabs = this.tabsModule.parse(dialogWithConditions);
|
|
141
|
+
return {
|
|
142
|
+
dialog: dialogWithTabs
|
|
143
|
+
};
|
|
144
|
+
}
|
|
145
|
+
_primitive() {
|
|
146
|
+
const result = {};
|
|
147
|
+
for (const [key, entry] of Object.entries(this.entries)) {
|
|
148
|
+
const type = entry._primitive();
|
|
149
|
+
if (typeof type === "string") {
|
|
150
|
+
result[key] = type;
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
return result;
|
|
154
|
+
}
|
|
155
|
+
};
|
|
156
|
+
function dialog(entries) {
|
|
157
|
+
return new DialogBuilder(entries);
|
|
69
158
|
}
|
|
70
159
|
export {
|
|
71
160
|
dialog
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/schema/dialog/dialog.ts"],"sourcesContent":["import {
|
|
1
|
+
{"version":3,"sources":["../../../src/schema/dialog/tabs.ts","../../../src/schema/dialog/condition.ts","../../../src/utils/pathToArray.ts","../../../src/schema/dialog/dialog.ts"],"sourcesContent":["import { EntryMask } from '../../types';\nimport { Field } from './types';\n\nexport class Tabs<TEntries> {\n private tabs = new Map<string, EntryMask<TEntries>>();\n\n addTab(name: string, entries: EntryMask<TEntries>) {\n this.tabs.set(name, entries);\n }\n\n parse(entries: Field[]) {\n const result = []\n const usedEntries = new Set();\n\n if(this.tabs.size === 0) {\n return entries\n }\n\n for(const [name, mask] of this.tabs) {\n const children = []\n\n if(!mask) {\n throw new Error(`Entry \"${String(name)}\" does not have an appropriate tab configuration.`);\n }\n\n for(const [key,] of Object.entries(mask)) {\n const field = entries.find(f => f.id === key)\n\n if (usedEntries.has(key)) {\n throw new Error(`Entry \"${String(name)}.${String(key)}\" is already used in another tab.`);\n }\n\n if(!field) {\n throw new Error(`Field with id \"${key}\" not found`);\n }\n\n children.push(entries.find(f => f.id === key))\n }\n\n result.push({\n type: 'tab',\n label: name,\n id: `tab_${name.toLowerCase().replaceAll(' ', '')}`,\n children\n })\n }\n\n return [{\n type: 'tabs',\n id: 'tabs',\n children: result\n }]\n }\n}","import { NestedPaths } from '../../types';\nimport { ConditionFn, ConditionOperators, Conditions, Field } from './types';\nimport { ObjectEntries } from '../../types/object';\n\nfunction addConditionToField(fields: Field[], path: string, condition: Conditions): void {\n const keys = path.split('.');\n let currentFields = fields;\n\n for (let i = 0; i < keys.length; i++) {\n const key = keys[i];\n const field = currentFields.find(f => f.id === key);\n\n if (!field) {\n throw new Error(`Field with id \"${key}\" not found`);\n }\n\n if (i === keys.length - 1) {\n field.condition = condition;\n } else {\n if (!field.children) {\n throw new Error(`Field with id \"${key}\" has no children`);\n }\n currentFields = field.children;\n }\n }\n}\n\nexport class Condition<TEntries extends ObjectEntries> {\n private conditions = new Map<string, Conditions>();\n\n addCondition(field: NestedPaths<TEntries>, condition: ConditionFn<TEntries>) {\n const operators: ConditionOperators<TEntries> = {\n eq: (field, value) => ({ operator: 'eq', field, value }),\n neq: (field, value) => ({ operator: 'neq', field, value }),\n exists: (field) => ({ operator: 'exists', field }),\n and: (...operations) => ({ operator: 'and', value: operations }),\n or: (...operations) => ({ operator: 'or', value: operations })\n };\n\n this.conditions.set(field, condition(operators));\n }\n\n parse(entries: Field[]) {\n for (let [key, value] of this.conditions) {\n addConditionToField(entries, key, value)\n }\n\n return entries;\n }\n}\n","interface PathValue {\n path: string[];\n value: any;\n}\n\nexport function pathToArray(obj: Record<string, any>, parentPath: string[] = []): PathValue[] {\n const result: PathValue[] = [];\n\n for (const [key, value] of Object.entries(obj)) {\n const currentPath = [...parentPath, key];\n\n if (typeof value === 'object' && !value.hasOwnProperty('operator') && !Array.isArray(value)) {\n // If the value is an object, recurse into it\n result.push(...pathToArray(value, currentPath));\n } else {\n // If the value is not an object, store the path and value\n result.push({ path: currentPath, value });\n }\n }\n\n return result;\n}","import { BaseSchema, EntryMask, NestedPaths } from '../../types';\nimport { ObjectEntries, ObjectOutput } from '../../types/object';\nimport { Tabs } from './tabs';\nimport { WebcomponentPropTypes } from '../../types/webcomponent';\nimport { Condition } from './condition';\nimport { pathToArray } from '../../utils/pathToArray';\nimport { ConditionsArgument } from './types';\n\nexport interface DialogSchema<TEntries extends ObjectEntries> extends BaseSchema<ObjectOutput<TEntries>> {\n type: 'dialog';\n tabs: (tabs: Record<string, EntryMask<TEntries>>) => DialogSchema<TEntries>;\n conditions: (conditions: ConditionsArgument<TEntries>) => DialogSchema<TEntries>;\n}\n\nclass DialogBuilder<TEntries extends ObjectEntries> implements DialogSchema<TEntries> {\n private conditionsModule: Condition<TEntries>;\n private tabsModule: Tabs<TEntries>;\n private readonly entries: TEntries;\n readonly type = 'dialog';\n\n constructor(entries: TEntries) {\n this.entries = entries;\n this.conditionsModule = new Condition<TEntries>();\n this.tabsModule = new Tabs<TEntries>();\n }\n\n conditions(conditions: ConditionsArgument<TEntries>) {\n const conditionsArray = pathToArray(conditions)\n for (const condition of conditionsArray) {\n this.conditionsModule.addCondition(condition.path.join('.') as NestedPaths<TEntries>, condition.value);\n }\n return this;\n }\n\n tabs(tabs: Record<string, EntryMask<TEntries>>) {\n for (const [key, tab] of Object.entries(tabs)) {\n this.tabsModule.addTab(key as any, tab!);\n }\n return this;\n }\n\n _parse() {\n const dialog = Object.entries(this.entries)\n .map(([key, entry]) => ({\n id: key,\n name: key,\n ...entry._parse(),\n }))\n .filter((entry: object) => {\n if ('type' in entry) {\n return entry.type !== 'hidden';\n }\n });\n\n const dialogWithConditions = this.conditionsModule.parse(dialog);\n const dialogWithTabs = this.tabsModule.parse(dialogWithConditions);\n return {\n dialog: dialogWithTabs\n };\n }\n\n _primitive() {\n const result: Record<string, WebcomponentPropTypes> = {};\n\n for (const [key, entry] of Object.entries(this.entries)) {\n const type = entry._primitive();\n if (typeof type === 'string') {\n result[key] = type;\n }\n }\n\n return result;\n }\n}\n\nexport function dialog<TEntries extends ObjectEntries>(entries: TEntries) {\n return new DialogBuilder(entries)\n}"],"mappings":";;;;;AAGO,IAAM,OAAN,MAAqB;AAAA,EAArB;AACL,wBAAQ,QAAO,oBAAI,IAAiC;AAAA;AAAA,EAEpD,OAAO,MAAc,SAA8B;AACjD,SAAK,KAAK,IAAI,MAAM,OAAO;AAAA,EAC7B;AAAA,EAEA,MAAM,SAAkB;AACtB,UAAM,SAAS,CAAC;AAChB,UAAM,cAAc,oBAAI,IAAI;AAE5B,QAAG,KAAK,KAAK,SAAS,GAAG;AACvB,aAAO;AAAA,IACT;AAEA,eAAU,CAAC,MAAM,IAAI,KAAK,KAAK,MAAM;AACnC,YAAM,WAAW,CAAC;AAElB,UAAG,CAAC,MAAM;AACR,cAAM,IAAI,MAAM,UAAU,OAAO,IAAI,CAAC,mDAAmD;AAAA,MAC3F;AAEA,iBAAU,CAAC,GAAI,KAAK,OAAO,QAAQ,IAAI,GAAG;AACxC,cAAM,QAAQ,QAAQ,KAAK,OAAK,EAAE,OAAO,GAAG;AAE5C,YAAI,YAAY,IAAI,GAAG,GAAG;AACxB,gBAAM,IAAI,MAAM,UAAU,OAAO,IAAI,CAAC,IAAI,OAAO,GAAG,CAAC,mCAAmC;AAAA,QAC1F;AAEA,YAAG,CAAC,OAAO;AACT,gBAAM,IAAI,MAAM,kBAAkB,GAAG,aAAa;AAAA,QACpD;AAEA,iBAAS,KAAK,QAAQ,KAAK,OAAK,EAAE,OAAO,GAAG,CAAC;AAAA,MAC/C;AAEA,aAAO,KAAK;AAAA,QACV,MAAM;AAAA,QACN,OAAO;AAAA,QACP,IAAI,OAAO,KAAK,YAAY,EAAE,WAAW,KAAK,EAAE,CAAC;AAAA,QACjD;AAAA,MACF,CAAC;AAAA,IACH;AAEA,WAAO,CAAC;AAAA,MACN,MAAM;AAAA,MACN,IAAI;AAA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B,UAAI,UAAU,OAAO;AACnB,eAAO,MAAM,SAAS;AAAA,MACxB;AAAA,IACF,CAAC;AAEH,UAAM,uBAAuB,KAAK,iBAAiB,MAAMA,OAAM;AAC/D,UAAM,iBAAiB,KAAK,WAAW,MAAM,oBAAoB;AACjE,WAAO;AAAA,MACL,QAAQ;AAAA,IACV;AAAA,EACF;AAAA,EAEA,aAAa;AACX,UAAM,SAAgD,CAAC;AAEvD,eAAW,CAAC,KAAK,KAAK,KAAK,OAAO,QAAQ,KAAK,OAAO,GAAG;AACvD,YAAM,OAAO,MAAM,WAAW;AAC9B,UAAI,OAAO,SAAS,UAAU;AAC5B,eAAO,GAAG,IAAI;AAAA,MAChB;AAAA,IACF;AAEA,WAAO;AAAA,EACT;AACF;AAEO,SAAS,OAAuC,SAAmB;AACxE,SAAO,IAAI,cAAc,OAAO;AAClC;","names":["field","dialog"]}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
export { DialogSchema, dialog } from './dialog.mjs';
|
|
2
|
+
export { Condition } from './condition.mjs';
|
|
3
|
+
export { b as ConditionFn, a as ConditionOperators, C as Conditions, c as ConditionsArgument, F as Field } from '../../types-B8taWezd.mjs';
|
|
4
|
+
export { Tabs } from './tabs.mjs';
|
|
2
5
|
import '../../types/utils.mjs';
|
|
3
|
-
import '../../types/schema.mjs';
|
|
4
6
|
import '../../types/webcomponent.mjs';
|
|
5
|
-
import '../../types/object.mjs';
|
|
6
|
-
import '../optional/optional.mjs';
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
export { DialogSchema, dialog } from './dialog.js';
|
|
2
|
+
export { Condition } from './condition.js';
|
|
3
|
+
export { b as ConditionFn, a as ConditionOperators, C as Conditions, c as ConditionsArgument, F as Field } from '../../types-rfg_xywc.js';
|
|
4
|
+
export { Tabs } from './tabs.js';
|
|
2
5
|
import '../../types/utils.js';
|
|
3
|
-
import '../../types/schema.js';
|
|
4
6
|
import '../../types/webcomponent.js';
|
|
5
|
-
import '../../types/object.js';
|
|
6
|
-
import '../optional/optional.js';
|