@ostack.tech/kform-scaffolder 0.31.0-SNAPSHOT.20251009153654
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/README.md +3 -0
- package/kform-scaffolder +3 -0
- package/ostack-kform-scaffolder.cjs +1695 -0
- package/ostack-kform-scaffolder.cjs.map +1 -0
- package/ostack-kform-scaffolder.css +199 -0
- package/ostack-kform-scaffolder.js +1678 -0
- package/ostack-kform-scaffolder.js.map +1 -0
- package/package.json +58 -0
- package/types/Schematic.d.ts +13 -0
- package/types/SchematicBuilder.d.ts +19 -0
- package/types/SchematicBuilderConfig.d.ts +5 -0
- package/types/SchematicBuilderContext.d.ts +31 -0
- package/types/SchematicKind.d.ts +44 -0
- package/types/actions/LoadSchematic.d.ts +1 -0
- package/types/actions/SaveSchematic.d.ts +1 -0
- package/types/actions/ScaffoldToZip.d.ts +1 -0
- package/types/configs/UseFileBase64SerializerConfig.d.ts +4 -0
- package/types/configs/UseTableValuesSerializerConfig.d.ts +4 -0
- package/types/configs/util/useConfig.d.ts +7 -0
- package/types/index.d.ts +38 -0
- package/types/main.d.ts +1 -0
- package/types/scaffolding/ScaffoldingData.d.ts +24 -0
- package/types/scaffolding/ScaffoldingFile.d.ts +13 -0
- package/types/scaffolding/configScaffolder.d.ts +4 -0
- package/types/scaffolding/kotlin/KtData.d.ts +5 -0
- package/types/scaffolding/kotlin/KtFile.d.ts +8 -0
- package/types/scaffolding/kotlin/util/annotations.d.ts +4 -0
- package/types/scaffolding/kotlin/util/defaultImports.d.ts +1 -0
- package/types/scaffolding/kotlin/util/simpleKtName.d.ts +1 -0
- package/types/scaffolding/scaffold.d.ts +16 -0
- package/types/scaffolding/scaffolders/scaffoldModels.d.ts +7 -0
- package/types/scaffolding/scaffolders/scaffoldSchemas.d.ts +5 -0
- package/types/scaffolding/scaffolders/scaffoldSerializer.d.ts +3 -0
- package/types/scaffolding/scaffolders/scaffoldValidator.d.ts +3 -0
- package/types/scaffolding/templating/EjsTemplateFile.d.ts +9 -0
- package/types/scaffolding/templating/TemplateFile.d.ts +6 -0
- package/types/scaffolding/templating/util/addEjsTemplateFile.d.ts +3 -0
- package/types/scaffolding/templating/util/addTemplateFile.d.ts +4 -0
- package/types/scaffolding/typescript/TsData.d.ts +5 -0
- package/types/scaffolding/typescript/TsFile.d.ts +7 -0
- package/types/scaffolding/typescript/TsImport.d.ts +44 -0
- package/types/scaffolding/useScaffolder.d.ts +2 -0
- package/types/schematicBuilders/ClassBuilder.d.ts +3 -0
- package/types/schematicBuilders/EnumBuilder.d.ts +3 -0
- package/types/schematicBuilders/ListableBuilder.d.ts +7 -0
- package/types/schematicBuilders/util/ChildMarker.d.ts +1 -0
- package/types/schematicBuilders/util/ChildRemove.d.ts +1 -0
- package/types/schematicBuilders/util/KindSelect.d.ts +1 -0
- package/types/schematicBuilders/util/NullableInput.d.ts +1 -0
- package/types/schematicBuilders/util/PackageNameInput.d.ts +1 -0
- package/types/util/boolDataAttr.d.ts +2 -0
- package/types/util/code.d.ts +2 -0
- package/types/util/join.d.ts +2 -0
- package/types/util/preventDrag.d.ts +6 -0
- package/types/util/useLayoutEffect.d.ts +3 -0
- package/types/util/useMeasure.d.ts +5 -0
- package/webapp/assets/index-BRrBNKA1.js +229 -0
- package/webapp/assets/index-rLmIK8TT.css +1 -0
- package/webapp/index.html +14 -0
|
@@ -0,0 +1,1695 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
|
+
const jsxRuntime = require("react/jsx-runtime");
|
|
4
|
+
const core = require("@dnd-kit/core");
|
|
5
|
+
const React = require("react");
|
|
6
|
+
const zustand = require("zustand");
|
|
7
|
+
const middleware = require("zustand/middleware");
|
|
8
|
+
const browserFsAccess = require("browser-fs-access");
|
|
9
|
+
const changeCase = require("change-case");
|
|
10
|
+
const JSZip = require("jszip");
|
|
11
|
+
const ejs = require("ejs");
|
|
12
|
+
function _interopNamespaceDefault(e) {
|
|
13
|
+
const n = Object.create(null, { [Symbol.toStringTag]: { value: "Module" } });
|
|
14
|
+
if (e) {
|
|
15
|
+
for (const k in e) {
|
|
16
|
+
if (k !== "default") {
|
|
17
|
+
const d = Object.getOwnPropertyDescriptor(e, k);
|
|
18
|
+
Object.defineProperty(n, k, d.get ? d : {
|
|
19
|
+
enumerable: true,
|
|
20
|
+
get: () => e[k]
|
|
21
|
+
});
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
n.default = e;
|
|
26
|
+
return Object.freeze(n);
|
|
27
|
+
}
|
|
28
|
+
const React__namespace = /* @__PURE__ */ _interopNamespaceDefault(React);
|
|
29
|
+
function createSchematic(schematic) {
|
|
30
|
+
return {
|
|
31
|
+
id: self.crypto.randomUUID(),
|
|
32
|
+
kind: "",
|
|
33
|
+
...schematic
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
function moveSchematic(schematic, moveId, parentId, sortBefore) {
|
|
37
|
+
const { schematic: schematicWithoutFrom, removed: fromSchematic } = remove(
|
|
38
|
+
schematic,
|
|
39
|
+
moveId
|
|
40
|
+
);
|
|
41
|
+
return add(schematicWithoutFrom, fromSchematic, parentId, sortBefore);
|
|
42
|
+
}
|
|
43
|
+
function remove(schematic, id) {
|
|
44
|
+
if (schematic.id === id) {
|
|
45
|
+
return { schematic: null, removed: schematic };
|
|
46
|
+
}
|
|
47
|
+
if (!schematic.children) {
|
|
48
|
+
return { schematic, removed: null };
|
|
49
|
+
}
|
|
50
|
+
const newChildren = [];
|
|
51
|
+
let removed = null;
|
|
52
|
+
for (const child of schematic.children) {
|
|
53
|
+
const { schematic: newChild, removed: removedChild } = remove(child, id);
|
|
54
|
+
if (newChild !== null) {
|
|
55
|
+
newChildren.push(newChild);
|
|
56
|
+
}
|
|
57
|
+
if (removedChild !== null) {
|
|
58
|
+
removed = removedChild;
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
return { schematic: { ...schematic, children: newChildren }, removed };
|
|
62
|
+
}
|
|
63
|
+
function add(schematic, toAdd, parentId, sortBefore) {
|
|
64
|
+
if (schematic.id === parentId) {
|
|
65
|
+
const oldChildren = schematic.children ?? [];
|
|
66
|
+
const index = sortBefore === null ? oldChildren.length : oldChildren.findIndex((c) => c.id === sortBefore);
|
|
67
|
+
return {
|
|
68
|
+
...schematic,
|
|
69
|
+
children: [
|
|
70
|
+
...oldChildren.slice(0, index),
|
|
71
|
+
toAdd,
|
|
72
|
+
...oldChildren.slice(index)
|
|
73
|
+
]
|
|
74
|
+
};
|
|
75
|
+
}
|
|
76
|
+
if (!schematic.children) {
|
|
77
|
+
return schematic;
|
|
78
|
+
}
|
|
79
|
+
return {
|
|
80
|
+
...schematic,
|
|
81
|
+
children: schematic.children.map(
|
|
82
|
+
(child) => add(child, toAdd, parentId, sortBefore)
|
|
83
|
+
)
|
|
84
|
+
};
|
|
85
|
+
}
|
|
86
|
+
const DEFAULT_IMPORTS = [
|
|
87
|
+
/^kotlin\.[^.]+$/,
|
|
88
|
+
/^kotlin\.annotation\.[^.]+$/,
|
|
89
|
+
/^kotlin\.collections\.[^.]+$/,
|
|
90
|
+
/^kotlin\.comparisons\.[^.]+$/,
|
|
91
|
+
/^kotlin\.io\.[^.]+$/,
|
|
92
|
+
/^kotlin\.ranges\.[^.]+$/,
|
|
93
|
+
/^kotlin\.sequences\.[^.]+$/,
|
|
94
|
+
/^kotlin\.text\.[^.]+$/
|
|
95
|
+
];
|
|
96
|
+
function isDefaultKtImport(qualifiedName) {
|
|
97
|
+
return DEFAULT_IMPORTS.some((i) => i.test(qualifiedName));
|
|
98
|
+
}
|
|
99
|
+
function ktFile(data) {
|
|
100
|
+
return {
|
|
101
|
+
package: data.currentPackage ?? "",
|
|
102
|
+
imports: /* @__PURE__ */ new Set(),
|
|
103
|
+
declarations: [],
|
|
104
|
+
getContent: ktFileContent
|
|
105
|
+
};
|
|
106
|
+
}
|
|
107
|
+
function ktFileContent() {
|
|
108
|
+
return [
|
|
109
|
+
// Package
|
|
110
|
+
this.package && `package ${this.package}`,
|
|
111
|
+
// Imports
|
|
112
|
+
Array.from(this.imports).filter((i) => !isDefaultKtImport(i)).sort().map((i) => `import ${i}`).join("\n"),
|
|
113
|
+
// Declarations
|
|
114
|
+
...this.declarations
|
|
115
|
+
].filter((s) => s).join("\n\n") + "\n";
|
|
116
|
+
}
|
|
117
|
+
function simpleKtName(qualifiedName) {
|
|
118
|
+
return qualifiedName.substring(qualifiedName.lastIndexOf(".") + 1);
|
|
119
|
+
}
|
|
120
|
+
const JS_EXPORT = "kotlin.js.JsExport";
|
|
121
|
+
const SERIALIZABLE = "kotlinx.serialization.Serializable";
|
|
122
|
+
function annotate(annotations, code2) {
|
|
123
|
+
if (!annotations || annotations.length === 0) {
|
|
124
|
+
return code2;
|
|
125
|
+
}
|
|
126
|
+
return [
|
|
127
|
+
...typeof annotations === "string" ? [annotations] : annotations,
|
|
128
|
+
code2
|
|
129
|
+
].join("\n");
|
|
130
|
+
}
|
|
131
|
+
function jsExport(code2, data) {
|
|
132
|
+
data.currentFile.imports.add(JS_EXPORT);
|
|
133
|
+
return annotate(`@${simpleKtName(JS_EXPORT)}`, code2);
|
|
134
|
+
}
|
|
135
|
+
function serializable(code2, data) {
|
|
136
|
+
data.currentFile.imports.add(SERIALIZABLE);
|
|
137
|
+
return annotate(`@${simpleKtName(SERIALIZABLE)}`, code2);
|
|
138
|
+
}
|
|
139
|
+
function join(s1, s2, separator) {
|
|
140
|
+
return !s1 || !s2 ? s1 || s2 || "" : `${s1}${s1.endsWith(separator) ? "" : separator}${s2}`;
|
|
141
|
+
}
|
|
142
|
+
function joinPaths(path1, path2) {
|
|
143
|
+
return join(path1, path2, "/");
|
|
144
|
+
}
|
|
145
|
+
function joinPackages(pkg1, pkg2) {
|
|
146
|
+
return join(pkg1, pkg2, ".");
|
|
147
|
+
}
|
|
148
|
+
function scaffoldModels(schematic, data) {
|
|
149
|
+
const fileName = joinPaths(data.currentDir, `${schematic.name}.kt`);
|
|
150
|
+
let file = data.files.get(fileName);
|
|
151
|
+
if (!file) {
|
|
152
|
+
data.files.set(fileName, file = ktFile(data));
|
|
153
|
+
}
|
|
154
|
+
scaffoldModelDeclaration(schematic, { ...data, currentFile: file });
|
|
155
|
+
}
|
|
156
|
+
function scaffoldModelDeclaration(schematic, data) {
|
|
157
|
+
const schematicKind = data.schematicKinds.get(schematic.kind);
|
|
158
|
+
if (!schematicKind) {
|
|
159
|
+
throw new Error(`Unknown schematic kind ${schematic.kind}`);
|
|
160
|
+
}
|
|
161
|
+
const nDecls = data.currentFile.declarations.length;
|
|
162
|
+
data.currentFile.declarations.push("");
|
|
163
|
+
const decl = schematicKind.scaffoldModel?.(schematic, data) ?? `typealias ${schematic.name} = ${scaffoldType(schematic, data)}`;
|
|
164
|
+
data.currentFile.declarations[nDecls] = schematicKind.scaffoldModel ? jsExport(serializable(decl, data), data) : decl;
|
|
165
|
+
}
|
|
166
|
+
function scaffoldPropertyAnnotations(schematic, data) {
|
|
167
|
+
const schematicKind = data.schematicKinds.get(schematic.kind);
|
|
168
|
+
if (!schematicKind) {
|
|
169
|
+
throw new Error(`Unknown schematic kind ${schematic.kind}`);
|
|
170
|
+
}
|
|
171
|
+
return typeof schematicKind.propertyAnnotations === "function" ? schematicKind.propertyAnnotations(schematic, data) : schematicKind.propertyAnnotations;
|
|
172
|
+
}
|
|
173
|
+
function scaffoldType(schematic, data) {
|
|
174
|
+
const schematicKind = data.schematicKinds.get(schematic.kind);
|
|
175
|
+
if (!schematicKind) {
|
|
176
|
+
throw new Error(`Unknown schematic kind ${schematic.kind}`);
|
|
177
|
+
}
|
|
178
|
+
const schematicPackage = schematicKind.package ?? joinPackages(data.currentPackage, schematic.packageSuffix);
|
|
179
|
+
const schematicName = schematic.name || schematicKind.name;
|
|
180
|
+
if (schematicPackage !== data.currentPackage) {
|
|
181
|
+
data.currentFile.imports.add(joinPackages(schematicPackage, schematicName));
|
|
182
|
+
}
|
|
183
|
+
if (schematicKind.package == null && schematicPackage !== data.currentPackage) {
|
|
184
|
+
scaffoldModels(schematic, {
|
|
185
|
+
...data,
|
|
186
|
+
currentPackage: joinPackages(
|
|
187
|
+
data.currentPackage,
|
|
188
|
+
schematic.packageSuffix
|
|
189
|
+
),
|
|
190
|
+
currentDir: joinPaths(
|
|
191
|
+
data.currentDir,
|
|
192
|
+
schematic.packageSuffix?.replace(".", "/")
|
|
193
|
+
)
|
|
194
|
+
});
|
|
195
|
+
} else if (schematicKind.scaffoldModel) {
|
|
196
|
+
scaffoldModelDeclaration(schematic, data);
|
|
197
|
+
}
|
|
198
|
+
return (schematicKind.scaffoldType?.(schematic, data) ?? schematicName) + (schematic.nullable ? "?" : "");
|
|
199
|
+
}
|
|
200
|
+
function scaffoldDefaultValue(schematic, data) {
|
|
201
|
+
const schematicKind = data.schematicKinds.get(schematic.kind);
|
|
202
|
+
if (!schematicKind) {
|
|
203
|
+
throw new Error(`Unknown schematic kind ${schematic.kind}`);
|
|
204
|
+
}
|
|
205
|
+
return schematic.nullable ? "null" : typeof schematicKind.defaultValue === "function" ? schematicKind.defaultValue(schematic, data) : schematicKind.defaultValue;
|
|
206
|
+
}
|
|
207
|
+
function scaffoldSchemas(schematic, data) {
|
|
208
|
+
const fileName = joinPaths(data.currentDir, `${schematic.name}Schema.kt`);
|
|
209
|
+
let file = data.files.get(fileName);
|
|
210
|
+
if (!file) {
|
|
211
|
+
data.files.set(fileName, file = ktFile(data));
|
|
212
|
+
data.files.set(
|
|
213
|
+
joinPaths(data.currentDir, `${schematic.name}Validations.kt`),
|
|
214
|
+
ktFile(data)
|
|
215
|
+
);
|
|
216
|
+
}
|
|
217
|
+
scaffoldSchemaDeclaration(schematic, { ...data, currentFile: file });
|
|
218
|
+
}
|
|
219
|
+
function scaffoldSchemaDeclaration(schematic, data) {
|
|
220
|
+
const schematicKind = data.schematicKinds.get(schematic.kind);
|
|
221
|
+
if (!schematicKind) {
|
|
222
|
+
throw new Error(`Unknown schematic kind ${schematic.kind}`);
|
|
223
|
+
}
|
|
224
|
+
const nDecls = data.currentFile.declarations.length;
|
|
225
|
+
data.currentFile.declarations.push("");
|
|
226
|
+
const decl = `val ${schematic.name}Schema = ${schematicKind.scaffoldSchema?.(schematic, data) ?? `${simpleKtName(schematicKind.schema)}()`}`;
|
|
227
|
+
data.currentFile.imports.add(schematicKind.schema);
|
|
228
|
+
data.currentFile.declarations[nDecls] = data.currentPath === "/" ? jsExport(decl, data) : decl;
|
|
229
|
+
}
|
|
230
|
+
function scaffoldSchema(schematic, data) {
|
|
231
|
+
const schematicKind = data.schematicKinds.get(schematic.kind);
|
|
232
|
+
if (!schematicKind) {
|
|
233
|
+
throw new Error(`Unknown schematic kind ${schematic.kind}`);
|
|
234
|
+
}
|
|
235
|
+
const schematicPackage = schematicKind.package ?? joinPackages(data.currentPackage, schematic.packageSuffix);
|
|
236
|
+
let scaffoldedSchema;
|
|
237
|
+
if (schematicKind.package == null && schematicPackage !== data.currentPackage) {
|
|
238
|
+
scaffoldedSchema = `${schematic.name}Schema`;
|
|
239
|
+
data.currentFile.imports.add(`${schematicPackage}.${scaffoldedSchema}`);
|
|
240
|
+
scaffoldSchemas(schematic, {
|
|
241
|
+
...data,
|
|
242
|
+
currentPackage: joinPackages(
|
|
243
|
+
data.currentPackage,
|
|
244
|
+
schematic.packageSuffix
|
|
245
|
+
),
|
|
246
|
+
currentDir: joinPaths(
|
|
247
|
+
data.currentDir,
|
|
248
|
+
schematic.packageSuffix?.replace(".", "/")
|
|
249
|
+
)
|
|
250
|
+
});
|
|
251
|
+
} else {
|
|
252
|
+
scaffoldedSchema = schematicKind.scaffoldSchema?.(schematic, data) ?? `${simpleKtName(schematicKind.schema)}()`;
|
|
253
|
+
data.currentFile.imports.add(schematicKind.schema);
|
|
254
|
+
}
|
|
255
|
+
if (schematic.nullable) {
|
|
256
|
+
data.currentFile.imports.add(NULLABLE_SCHEMA);
|
|
257
|
+
return `${simpleKtName(NULLABLE_SCHEMA)} { ${scaffoldedSchema} }`;
|
|
258
|
+
}
|
|
259
|
+
return scaffoldedSchema;
|
|
260
|
+
}
|
|
261
|
+
function boolDataAttr(condition) {
|
|
262
|
+
return condition ? "" : void 0;
|
|
263
|
+
}
|
|
264
|
+
const preventDrag = {
|
|
265
|
+
onKeyDown: (evt) => evt.stopPropagation(),
|
|
266
|
+
onPointerDown: (evt) => evt.stopPropagation()
|
|
267
|
+
};
|
|
268
|
+
function ChildMarker() {
|
|
269
|
+
const { schematicKinds, useSchematic, setSchematic } = useSchematicBuilderContext();
|
|
270
|
+
const kind = useSchematic((schematic) => schematic.kind);
|
|
271
|
+
const collapsed = useSchematic((schematic) => schematic.collapsed);
|
|
272
|
+
const Builder = schematicKinds.get(kind)?.builder;
|
|
273
|
+
return Builder ? /* @__PURE__ */ jsxRuntime.jsx(
|
|
274
|
+
"button",
|
|
275
|
+
{
|
|
276
|
+
type: "button",
|
|
277
|
+
className: "builder-child-marker",
|
|
278
|
+
title: collapsed ? "Expand" : "Collapse",
|
|
279
|
+
onClick: () => setSchematic((schematic) => ({
|
|
280
|
+
collapsed: !schematic.collapsed
|
|
281
|
+
})),
|
|
282
|
+
...preventDrag,
|
|
283
|
+
children: collapsed ? "▸" : "▾"
|
|
284
|
+
}
|
|
285
|
+
) : /* @__PURE__ */ jsxRuntime.jsx("span", { className: "builder-child-marker", children: "•" });
|
|
286
|
+
}
|
|
287
|
+
function ChildRemove() {
|
|
288
|
+
const { removeSchematic } = useSchematicBuilderContext();
|
|
289
|
+
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
290
|
+
"button",
|
|
291
|
+
{
|
|
292
|
+
className: "builder-icon-button builder-child-remove",
|
|
293
|
+
type: "button",
|
|
294
|
+
title: "Remove",
|
|
295
|
+
onClick: removeSchematic,
|
|
296
|
+
...preventDrag,
|
|
297
|
+
children: "×"
|
|
298
|
+
}
|
|
299
|
+
);
|
|
300
|
+
}
|
|
301
|
+
const KIND_PLACEHOLDER = "--KIND--";
|
|
302
|
+
function KindSelect() {
|
|
303
|
+
const { schematicKinds, useSchematic, setSchematic, parentChildName } = useSchematicBuilderContext();
|
|
304
|
+
const kind = useSchematic((schematic) => schematic.kind);
|
|
305
|
+
return /* @__PURE__ */ jsxRuntime.jsxs(
|
|
306
|
+
"select",
|
|
307
|
+
{
|
|
308
|
+
className: "builder-input builder-schema",
|
|
309
|
+
value: kind,
|
|
310
|
+
onChange: (evt) => {
|
|
311
|
+
const schematicKind = schematicKinds.get(evt.target.value);
|
|
312
|
+
setSchematic({
|
|
313
|
+
kind: evt.target.value,
|
|
314
|
+
packageSuffix: schematicKind?.defaultPackageSuffix?.(
|
|
315
|
+
parentChildName
|
|
316
|
+
),
|
|
317
|
+
name: schematicKind?.defaultName?.(parentChildName),
|
|
318
|
+
collapsed: false,
|
|
319
|
+
nullable: schematicKind?.nullable ?? schematicKind?.defaultNullable,
|
|
320
|
+
children: schematicKind?.initChildren?.(parentChildName)
|
|
321
|
+
});
|
|
322
|
+
},
|
|
323
|
+
required: true,
|
|
324
|
+
style: {
|
|
325
|
+
width: `calc(${(kind || KIND_PLACEHOLDER).length}ch + 1.85rem)`
|
|
326
|
+
},
|
|
327
|
+
...preventDrag,
|
|
328
|
+
children: [
|
|
329
|
+
/* @__PURE__ */ jsxRuntime.jsx("option", { children: KIND_PLACEHOLDER }),
|
|
330
|
+
Array.from(schematicKinds.values()).filter((kind2) => !kind2.internal).map((kind2) => /* @__PURE__ */ jsxRuntime.jsx("option", { value: kind2.kind, children: kind2.kind }, kind2.kind))
|
|
331
|
+
]
|
|
332
|
+
}
|
|
333
|
+
);
|
|
334
|
+
}
|
|
335
|
+
function NullableInput() {
|
|
336
|
+
const { schematicKinds, useSchematic, setSchematic } = useSchematicBuilderContext();
|
|
337
|
+
const kind = useSchematic((schematic) => schematic.kind);
|
|
338
|
+
const nullable = useSchematic((schematic) => !!schematic.nullable);
|
|
339
|
+
const schematicKind = schematicKinds.get(kind);
|
|
340
|
+
const showInput = schematicKind && schematicKind.nullable === void 0;
|
|
341
|
+
return showInput && /* @__PURE__ */ jsxRuntime.jsx(
|
|
342
|
+
"input",
|
|
343
|
+
{
|
|
344
|
+
className: "builder-input builder-nullable",
|
|
345
|
+
type: "checkbox",
|
|
346
|
+
title: "Nullable?",
|
|
347
|
+
checked: nullable,
|
|
348
|
+
onChange: (evt) => setSchematic({ nullable: evt.target.checked }),
|
|
349
|
+
...preventDrag
|
|
350
|
+
}
|
|
351
|
+
);
|
|
352
|
+
}
|
|
353
|
+
const PACKAGE_PLACEHOLDER = "package.suffix";
|
|
354
|
+
const NAME_PLACEHOLDER = "ClassName";
|
|
355
|
+
function PackageNameInput() {
|
|
356
|
+
const { useSchematic, setSchematic, parentPackage } = useSchematicBuilderContext();
|
|
357
|
+
const pkgRef = React__namespace.useRef(null);
|
|
358
|
+
const packageSuffix = useSchematic((schematic) => schematic.packageSuffix);
|
|
359
|
+
const name = useSchematic((schematic) => schematic.name);
|
|
360
|
+
return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "builder-package-name", children: [
|
|
361
|
+
parentPackage && /* @__PURE__ */ jsxRuntime.jsxs("span", { className: "builder-package-prefix", children: [
|
|
362
|
+
parentPackage,
|
|
363
|
+
"."
|
|
364
|
+
] }),
|
|
365
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
366
|
+
"input",
|
|
367
|
+
{
|
|
368
|
+
className: "builder-input builder-package",
|
|
369
|
+
placeholder: PACKAGE_PLACEHOLDER,
|
|
370
|
+
value: packageSuffix ?? "",
|
|
371
|
+
onChange: (evt) => setSchematic({ packageSuffix: evt.target.value }),
|
|
372
|
+
pattern: "(([a-z_][a-z0-9_]*)(\\.([a-z_][a-z0-9_]*))*)?",
|
|
373
|
+
style: { width: `${(packageSuffix || PACKAGE_PLACEHOLDER).length}ch` },
|
|
374
|
+
...preventDrag,
|
|
375
|
+
ref: pkgRef
|
|
376
|
+
}
|
|
377
|
+
),
|
|
378
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
379
|
+
"button",
|
|
380
|
+
{
|
|
381
|
+
type: "button",
|
|
382
|
+
className: "builder-icon-button builder-edit-package",
|
|
383
|
+
onClick: () => {
|
|
384
|
+
const pkgInput = pkgRef.current;
|
|
385
|
+
pkgInput.style.display = "initial";
|
|
386
|
+
pkgInput.focus();
|
|
387
|
+
pkgInput.style.display = "";
|
|
388
|
+
},
|
|
389
|
+
children: "🖉"
|
|
390
|
+
}
|
|
391
|
+
),
|
|
392
|
+
/* @__PURE__ */ jsxRuntime.jsx("span", { className: "builder-operator", children: "." }),
|
|
393
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
394
|
+
"input",
|
|
395
|
+
{
|
|
396
|
+
className: "builder-input builder-name",
|
|
397
|
+
placeholder: NAME_PLACEHOLDER,
|
|
398
|
+
value: name ?? "",
|
|
399
|
+
onChange: (evt) => setSchematic({ name: evt.target.value }),
|
|
400
|
+
required: true,
|
|
401
|
+
pattern: "[a-zA-Z_][a-zA-Z0-9_]*",
|
|
402
|
+
style: { width: `${(name || NAME_PLACEHOLDER).length}ch` },
|
|
403
|
+
...preventDrag
|
|
404
|
+
}
|
|
405
|
+
)
|
|
406
|
+
] });
|
|
407
|
+
}
|
|
408
|
+
const CLASS_DND_TYPE = "class-field";
|
|
409
|
+
function ClassBuilder() {
|
|
410
|
+
const schematicBuilderContext = useSchematicBuilderContext();
|
|
411
|
+
const { useSchematic, setSchematic, draggedSchematic, disableDrop } = schematicBuilderContext;
|
|
412
|
+
const id = useSchematic((schematic) => schematic.id);
|
|
413
|
+
const packageSuffix = useSchematic((schematic) => schematic.packageSuffix);
|
|
414
|
+
const fields = useSchematic((schematic) => schematic.children) ?? [];
|
|
415
|
+
const shouldIgnoreDrop = draggedSchematic != null && draggedSchematic.id === fields.at(-1)?.id;
|
|
416
|
+
const { setNodeRef: setDroppableRef, isOver } = core.useDroppable({
|
|
417
|
+
id: `${id}-append`,
|
|
418
|
+
data: { parentId: id, sortBefore: null, ignored: shouldIgnoreDrop },
|
|
419
|
+
disabled: disableDrop || draggedSchematic?.type !== CLASS_DND_TYPE
|
|
420
|
+
});
|
|
421
|
+
return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "class-builder builder", children: [
|
|
422
|
+
/* @__PURE__ */ jsxRuntime.jsx(PackageNameInput, {}),
|
|
423
|
+
fields.length === 0 && /* @__PURE__ */ jsxRuntime.jsx(
|
|
424
|
+
"div",
|
|
425
|
+
{
|
|
426
|
+
className: "builder-empty",
|
|
427
|
+
"data-over": boolDataAttr(isOver),
|
|
428
|
+
ref: setDroppableRef,
|
|
429
|
+
children: "No fields."
|
|
430
|
+
}
|
|
431
|
+
),
|
|
432
|
+
fields.length > 0 && /* @__PURE__ */ jsxRuntime.jsxs("ul", { className: "builder-children", children: [
|
|
433
|
+
fields.map((field, i) => /* @__PURE__ */ jsxRuntime.jsx(
|
|
434
|
+
SchematicBuilderContext.Provider,
|
|
435
|
+
{
|
|
436
|
+
value: {
|
|
437
|
+
...schematicBuilderContext,
|
|
438
|
+
useSchematic: (selector) => useSchematic((schematic) => selector(schematic.children[i])),
|
|
439
|
+
setSchematic: (toSet) => setSchematic((schematic) => ({
|
|
440
|
+
...schematic,
|
|
441
|
+
children: schematic.children.map(
|
|
442
|
+
(f) => field === f ? {
|
|
443
|
+
...f,
|
|
444
|
+
...typeof toSet === "function" ? toSet(f) : toSet
|
|
445
|
+
} : f
|
|
446
|
+
)
|
|
447
|
+
})),
|
|
448
|
+
removeSchematic: () => setSchematic((schematic) => ({
|
|
449
|
+
...schematic,
|
|
450
|
+
children: schematic.children.filter((f) => f !== field)
|
|
451
|
+
})),
|
|
452
|
+
parentPackage: joinPackages(
|
|
453
|
+
schematicBuilderContext.parentPackage,
|
|
454
|
+
packageSuffix
|
|
455
|
+
),
|
|
456
|
+
parentId: id,
|
|
457
|
+
ignoreDrop: draggedSchematic != null && draggedSchematic.id === fields[i - 1]?.id
|
|
458
|
+
},
|
|
459
|
+
children: /* @__PURE__ */ jsxRuntime.jsx(ClassFieldBuilder, {})
|
|
460
|
+
},
|
|
461
|
+
field.id
|
|
462
|
+
)),
|
|
463
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
464
|
+
"li",
|
|
465
|
+
{
|
|
466
|
+
className: "builder-child-droppable",
|
|
467
|
+
"data-over": boolDataAttr(isOver && !shouldIgnoreDrop),
|
|
468
|
+
ref: setDroppableRef
|
|
469
|
+
}
|
|
470
|
+
)
|
|
471
|
+
] }),
|
|
472
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
473
|
+
"button",
|
|
474
|
+
{
|
|
475
|
+
className: "builder-input builder-new-child",
|
|
476
|
+
type: "button",
|
|
477
|
+
onClick: () => {
|
|
478
|
+
setSchematic((schematic) => ({
|
|
479
|
+
...schematic,
|
|
480
|
+
children: [
|
|
481
|
+
...schematic.children ?? [],
|
|
482
|
+
createSchematic({ childName: "" })
|
|
483
|
+
]
|
|
484
|
+
}));
|
|
485
|
+
},
|
|
486
|
+
...preventDrag,
|
|
487
|
+
children: "Add field"
|
|
488
|
+
}
|
|
489
|
+
)
|
|
490
|
+
] });
|
|
491
|
+
}
|
|
492
|
+
const CHILD_NAME_PLACEHOLDER$1 = "fieldName";
|
|
493
|
+
function ClassFieldBuilder() {
|
|
494
|
+
const schematicBuilderContext = useSchematicBuilderContext();
|
|
495
|
+
const {
|
|
496
|
+
schematicKinds,
|
|
497
|
+
useSchematic,
|
|
498
|
+
setSchematic,
|
|
499
|
+
draggedSchematic,
|
|
500
|
+
parentId,
|
|
501
|
+
disableDrop,
|
|
502
|
+
ignoreDrop
|
|
503
|
+
} = schematicBuilderContext;
|
|
504
|
+
const id = useSchematic((schematic) => schematic.id);
|
|
505
|
+
const childName = useSchematic((schematic) => schematic.childName);
|
|
506
|
+
const kind = useSchematic((schematic) => schematic.kind);
|
|
507
|
+
const nullable = useSchematic((schematic) => schematic.nullable);
|
|
508
|
+
const collapsed = useSchematic((schematic) => schematic.collapsed);
|
|
509
|
+
const Builder = schematicKinds.get(kind)?.builder;
|
|
510
|
+
const {
|
|
511
|
+
attributes,
|
|
512
|
+
listeners,
|
|
513
|
+
setNodeRef: setDraggableRef,
|
|
514
|
+
isDragging
|
|
515
|
+
} = core.useDraggable({
|
|
516
|
+
id,
|
|
517
|
+
data: {
|
|
518
|
+
type: CLASS_DND_TYPE,
|
|
519
|
+
node: /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
|
|
520
|
+
[childName, kind].filter((s) => s).join(": "),
|
|
521
|
+
nullable ? "?" : ""
|
|
522
|
+
] })
|
|
523
|
+
}
|
|
524
|
+
});
|
|
525
|
+
const shouldIgnoreDrop = isDragging || ignoreDrop;
|
|
526
|
+
const { setNodeRef: setDroppableRef, isOver } = core.useDroppable({
|
|
527
|
+
id,
|
|
528
|
+
data: { parentId, sortBefore: id, ignored: shouldIgnoreDrop },
|
|
529
|
+
disabled: disableDrop || draggedSchematic?.type !== CLASS_DND_TYPE
|
|
530
|
+
});
|
|
531
|
+
return /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
|
|
532
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
533
|
+
"li",
|
|
534
|
+
{
|
|
535
|
+
className: "builder-child-droppable",
|
|
536
|
+
"data-over": boolDataAttr(isOver && !shouldIgnoreDrop),
|
|
537
|
+
ref: setDroppableRef
|
|
538
|
+
}
|
|
539
|
+
),
|
|
540
|
+
/* @__PURE__ */ jsxRuntime.jsxs(
|
|
541
|
+
"li",
|
|
542
|
+
{
|
|
543
|
+
className: "builder-child class-builder-field",
|
|
544
|
+
"data-dragging": boolDataAttr(isDragging),
|
|
545
|
+
...listeners,
|
|
546
|
+
...attributes,
|
|
547
|
+
ref: setDraggableRef,
|
|
548
|
+
"data-collapsible": boolDataAttr(Builder != null),
|
|
549
|
+
children: [
|
|
550
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "builder-child-content", children: [
|
|
551
|
+
/* @__PURE__ */ jsxRuntime.jsx(ChildMarker, {}),
|
|
552
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
553
|
+
"input",
|
|
554
|
+
{
|
|
555
|
+
className: "builder-input class-builder-field-id",
|
|
556
|
+
placeholder: CHILD_NAME_PLACEHOLDER$1,
|
|
557
|
+
value: childName,
|
|
558
|
+
onChange: (evt) => setSchematic({ childName: evt.target.value }),
|
|
559
|
+
required: true,
|
|
560
|
+
pattern: "[a-zA-Z_][a-zA-Z0-9_]*",
|
|
561
|
+
style: {
|
|
562
|
+
width: `${(childName || CHILD_NAME_PLACEHOLDER$1).length}ch`
|
|
563
|
+
},
|
|
564
|
+
...preventDrag
|
|
565
|
+
}
|
|
566
|
+
),
|
|
567
|
+
/* @__PURE__ */ jsxRuntime.jsx("span", { className: "builder-operator", children: "∶" }),
|
|
568
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
569
|
+
SchematicBuilderContext.Provider,
|
|
570
|
+
{
|
|
571
|
+
value: { ...schematicBuilderContext, parentChildName: childName },
|
|
572
|
+
children: /* @__PURE__ */ jsxRuntime.jsx(KindSelect, {})
|
|
573
|
+
}
|
|
574
|
+
),
|
|
575
|
+
/* @__PURE__ */ jsxRuntime.jsx(NullableInput, {}),
|
|
576
|
+
/* @__PURE__ */ jsxRuntime.jsx(ChildRemove, {})
|
|
577
|
+
] }),
|
|
578
|
+
Builder && !collapsed && /* @__PURE__ */ jsxRuntime.jsx(
|
|
579
|
+
SchematicBuilderContext.Provider,
|
|
580
|
+
{
|
|
581
|
+
value: {
|
|
582
|
+
...schematicBuilderContext,
|
|
583
|
+
parentChildName: childName,
|
|
584
|
+
disableDrop: disableDrop || isDragging
|
|
585
|
+
},
|
|
586
|
+
children: /* @__PURE__ */ jsxRuntime.jsx(Builder, {})
|
|
587
|
+
}
|
|
588
|
+
)
|
|
589
|
+
]
|
|
590
|
+
}
|
|
591
|
+
)
|
|
592
|
+
] });
|
|
593
|
+
}
|
|
594
|
+
const ENUM_DND_TYPE = "enum-entry";
|
|
595
|
+
function EnumBuilder() {
|
|
596
|
+
const schematicBuilderContext = useSchematicBuilderContext();
|
|
597
|
+
const { useSchematic, setSchematic, draggedSchematic, disableDrop } = schematicBuilderContext;
|
|
598
|
+
const id = useSchematic((schematic) => schematic.id);
|
|
599
|
+
const fields = useSchematic((schematic) => schematic.children) ?? [];
|
|
600
|
+
const shouldIgnoreDrop = draggedSchematic != null && draggedSchematic.id === fields.at(-1)?.id;
|
|
601
|
+
const { setNodeRef: setDroppableRef, isOver } = core.useDroppable({
|
|
602
|
+
id: `${id}-append`,
|
|
603
|
+
data: { parentId: id, sortBefore: null, ignored: shouldIgnoreDrop },
|
|
604
|
+
disabled: disableDrop || draggedSchematic?.type !== ENUM_DND_TYPE
|
|
605
|
+
});
|
|
606
|
+
return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "enum-builder builder", children: [
|
|
607
|
+
/* @__PURE__ */ jsxRuntime.jsx(PackageNameInput, {}),
|
|
608
|
+
fields.length === 0 && /* @__PURE__ */ jsxRuntime.jsx(
|
|
609
|
+
"div",
|
|
610
|
+
{
|
|
611
|
+
className: "builder-empty",
|
|
612
|
+
"data-over": boolDataAttr(isOver),
|
|
613
|
+
ref: setDroppableRef,
|
|
614
|
+
children: "No entries."
|
|
615
|
+
}
|
|
616
|
+
),
|
|
617
|
+
fields.length > 0 && /* @__PURE__ */ jsxRuntime.jsxs("ul", { className: "builder-children", children: [
|
|
618
|
+
fields.map((field, i) => /* @__PURE__ */ jsxRuntime.jsx(
|
|
619
|
+
SchematicBuilderContext.Provider,
|
|
620
|
+
{
|
|
621
|
+
value: {
|
|
622
|
+
...schematicBuilderContext,
|
|
623
|
+
useSchematic: (selector) => useSchematic((schematic) => selector(schematic.children[i])),
|
|
624
|
+
setSchematic: (toSet) => setSchematic((schematic) => ({
|
|
625
|
+
...schematic,
|
|
626
|
+
children: schematic.children.map(
|
|
627
|
+
(f) => field === f ? {
|
|
628
|
+
...f,
|
|
629
|
+
...typeof toSet === "function" ? toSet(f) : toSet
|
|
630
|
+
} : f
|
|
631
|
+
)
|
|
632
|
+
})),
|
|
633
|
+
removeSchematic: () => setSchematic((schematic) => ({
|
|
634
|
+
...schematic,
|
|
635
|
+
children: schematic.children.filter((f) => f !== field)
|
|
636
|
+
})),
|
|
637
|
+
parentId: id,
|
|
638
|
+
ignoreDrop: draggedSchematic != null && draggedSchematic.id === fields[i - 1]?.id
|
|
639
|
+
},
|
|
640
|
+
children: /* @__PURE__ */ jsxRuntime.jsx(EnumEntryBuilder, {})
|
|
641
|
+
},
|
|
642
|
+
field.id
|
|
643
|
+
)),
|
|
644
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
645
|
+
"li",
|
|
646
|
+
{
|
|
647
|
+
className: "builder-child-droppable",
|
|
648
|
+
"data-over": boolDataAttr(isOver && !shouldIgnoreDrop),
|
|
649
|
+
ref: setDroppableRef
|
|
650
|
+
}
|
|
651
|
+
)
|
|
652
|
+
] }),
|
|
653
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
654
|
+
"button",
|
|
655
|
+
{
|
|
656
|
+
className: "builder-input builder-new-child",
|
|
657
|
+
type: "button",
|
|
658
|
+
onClick: () => {
|
|
659
|
+
setSchematic((schematic) => ({
|
|
660
|
+
...schematic,
|
|
661
|
+
children: [
|
|
662
|
+
...schematic.children ?? [],
|
|
663
|
+
createSchematic({ childName: "" })
|
|
664
|
+
]
|
|
665
|
+
}));
|
|
666
|
+
},
|
|
667
|
+
...preventDrag,
|
|
668
|
+
children: "Add entry"
|
|
669
|
+
}
|
|
670
|
+
)
|
|
671
|
+
] });
|
|
672
|
+
}
|
|
673
|
+
const CHILD_NAME_PLACEHOLDER = "ENTRY_NAME";
|
|
674
|
+
function EnumEntryBuilder() {
|
|
675
|
+
const schematicBuilderContext = useSchematicBuilderContext();
|
|
676
|
+
const {
|
|
677
|
+
schematicKinds,
|
|
678
|
+
useSchematic,
|
|
679
|
+
setSchematic,
|
|
680
|
+
draggedSchematic,
|
|
681
|
+
parentId,
|
|
682
|
+
disableDrop,
|
|
683
|
+
ignoreDrop
|
|
684
|
+
} = schematicBuilderContext;
|
|
685
|
+
const id = useSchematic((schematic) => schematic.id);
|
|
686
|
+
const childName = useSchematic((schematic) => schematic.childName);
|
|
687
|
+
const kind = useSchematic((schematic) => schematic.kind);
|
|
688
|
+
const Builder = schematicKinds.get(kind)?.builder;
|
|
689
|
+
const {
|
|
690
|
+
attributes,
|
|
691
|
+
listeners,
|
|
692
|
+
setNodeRef: setDraggableRef,
|
|
693
|
+
isDragging
|
|
694
|
+
} = core.useDraggable({
|
|
695
|
+
id,
|
|
696
|
+
data: {
|
|
697
|
+
type: ENUM_DND_TYPE,
|
|
698
|
+
node: /* @__PURE__ */ jsxRuntime.jsx(jsxRuntime.Fragment, { children: [childName, kind].filter((s) => s).join(": ") })
|
|
699
|
+
}
|
|
700
|
+
});
|
|
701
|
+
const shouldIgnoreDrop = isDragging || ignoreDrop;
|
|
702
|
+
const { setNodeRef: setDroppableRef, isOver } = core.useDroppable({
|
|
703
|
+
id,
|
|
704
|
+
data: { parentId, sortBefore: id, ignored: shouldIgnoreDrop },
|
|
705
|
+
disabled: disableDrop || draggedSchematic?.type !== ENUM_DND_TYPE
|
|
706
|
+
});
|
|
707
|
+
return /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
|
|
708
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
709
|
+
"li",
|
|
710
|
+
{
|
|
711
|
+
className: "builder-child-droppable",
|
|
712
|
+
"data-over": boolDataAttr(isOver && !shouldIgnoreDrop),
|
|
713
|
+
ref: setDroppableRef
|
|
714
|
+
}
|
|
715
|
+
),
|
|
716
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
717
|
+
"li",
|
|
718
|
+
{
|
|
719
|
+
className: "builder-child",
|
|
720
|
+
"data-dragging": boolDataAttr(isDragging),
|
|
721
|
+
...listeners,
|
|
722
|
+
...attributes,
|
|
723
|
+
ref: setDraggableRef,
|
|
724
|
+
"data-collapsible": boolDataAttr(Builder != null),
|
|
725
|
+
children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "builder-child-content", children: [
|
|
726
|
+
/* @__PURE__ */ jsxRuntime.jsx(ChildMarker, {}),
|
|
727
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
728
|
+
"input",
|
|
729
|
+
{
|
|
730
|
+
className: "builder-input enum-builder-entry-id",
|
|
731
|
+
placeholder: CHILD_NAME_PLACEHOLDER,
|
|
732
|
+
value: childName,
|
|
733
|
+
onChange: (evt) => setSchematic({ childName: evt.target.value }),
|
|
734
|
+
required: true,
|
|
735
|
+
pattern: "[a-zA-Z_][a-zA-Z0-9_]*",
|
|
736
|
+
style: {
|
|
737
|
+
width: `${(childName || CHILD_NAME_PLACEHOLDER).length}ch`
|
|
738
|
+
},
|
|
739
|
+
...preventDrag
|
|
740
|
+
}
|
|
741
|
+
),
|
|
742
|
+
/* @__PURE__ */ jsxRuntime.jsx(ChildRemove, {})
|
|
743
|
+
] })
|
|
744
|
+
}
|
|
745
|
+
)
|
|
746
|
+
] });
|
|
747
|
+
}
|
|
748
|
+
function ListableBuilder({
|
|
749
|
+
showKindSelect = true
|
|
750
|
+
}) {
|
|
751
|
+
const schematicBuilderContext = useSchematicBuilderContext();
|
|
752
|
+
const { useSchematic, setSchematic } = schematicBuilderContext;
|
|
753
|
+
const id = useSchematic((schematic) => schematic.id);
|
|
754
|
+
return /* @__PURE__ */ jsxRuntime.jsx("div", { className: "listable-builder builder", children: /* @__PURE__ */ jsxRuntime.jsx(
|
|
755
|
+
SchematicBuilderContext.Provider,
|
|
756
|
+
{
|
|
757
|
+
value: {
|
|
758
|
+
...schematicBuilderContext,
|
|
759
|
+
useSchematic: (selector) => useSchematic((schematic) => selector(schematic.children[0])),
|
|
760
|
+
setSchematic: (toSet) => setSchematic((schematic) => ({
|
|
761
|
+
...schematic,
|
|
762
|
+
children: [
|
|
763
|
+
{
|
|
764
|
+
...schematic.children[0],
|
|
765
|
+
...typeof toSet === "function" ? toSet(schematic.children[0]) : toSet
|
|
766
|
+
}
|
|
767
|
+
]
|
|
768
|
+
})),
|
|
769
|
+
removeSchematic: () => {
|
|
770
|
+
},
|
|
771
|
+
parentId: id
|
|
772
|
+
},
|
|
773
|
+
children: /* @__PURE__ */ jsxRuntime.jsx(ListableItemBuilder, { showKindSelect })
|
|
774
|
+
}
|
|
775
|
+
) });
|
|
776
|
+
}
|
|
777
|
+
function ListableBuilderWithoutKindSelect() {
|
|
778
|
+
return /* @__PURE__ */ jsxRuntime.jsx(ListableBuilder, { showKindSelect: false });
|
|
779
|
+
}
|
|
780
|
+
function ListableItemBuilder({
|
|
781
|
+
showKindSelect = true
|
|
782
|
+
}) {
|
|
783
|
+
const { schematicKinds, useSchematic } = useSchematicBuilderContext();
|
|
784
|
+
const kind = useSchematic((schematic) => schematic.kind);
|
|
785
|
+
const Builder = schematicKinds.get(kind)?.builder;
|
|
786
|
+
return /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
|
|
787
|
+
showKindSelect && /* @__PURE__ */ jsxRuntime.jsx(KindSelect, {}),
|
|
788
|
+
Builder && /* @__PURE__ */ jsxRuntime.jsx(Builder, {})
|
|
789
|
+
] });
|
|
790
|
+
}
|
|
791
|
+
const LF = /\r?\n/;
|
|
792
|
+
const EMPTY_LINE = /^\s*$/;
|
|
793
|
+
const SPACE = /\s/;
|
|
794
|
+
const LF_AFFIX = /(^\r?\n)|(\r?\n$)/g;
|
|
795
|
+
function code(strings, ...values) {
|
|
796
|
+
const minIndent = Math.min(
|
|
797
|
+
...strings.join("").split(LF).filter(isNotEmpty).map(indentWidth)
|
|
798
|
+
);
|
|
799
|
+
let result = "";
|
|
800
|
+
for (let i = 0; i < values.length; ++i) {
|
|
801
|
+
const trimmedString = trimNoninitialLines(strings[i], minIndent);
|
|
802
|
+
result += trimmedString;
|
|
803
|
+
result += indentNoninitialLines(
|
|
804
|
+
String(values[i]),
|
|
805
|
+
indentWidth(trimmedString.split(LF).at(-1))
|
|
806
|
+
);
|
|
807
|
+
}
|
|
808
|
+
result += trimNoninitialLines(strings.at(-1), minIndent);
|
|
809
|
+
return result.replace(LF_AFFIX, "");
|
|
810
|
+
}
|
|
811
|
+
function isNotEmpty(line) {
|
|
812
|
+
return !EMPTY_LINE.test(line);
|
|
813
|
+
}
|
|
814
|
+
function indentWidth(line) {
|
|
815
|
+
let width = 0;
|
|
816
|
+
for (const c of line) {
|
|
817
|
+
if (!SPACE.test(c)) {
|
|
818
|
+
break;
|
|
819
|
+
}
|
|
820
|
+
++width;
|
|
821
|
+
}
|
|
822
|
+
return width;
|
|
823
|
+
}
|
|
824
|
+
function indentNoninitialLines(str, indentWidth2) {
|
|
825
|
+
const lines = str.split(LF);
|
|
826
|
+
const resultLines = [lines[0]];
|
|
827
|
+
for (let i = 1; i < lines.length; ++i) {
|
|
828
|
+
const line = lines[i];
|
|
829
|
+
resultLines.push(line && " ".repeat(indentWidth2) + line);
|
|
830
|
+
}
|
|
831
|
+
return resultLines.join("\n");
|
|
832
|
+
}
|
|
833
|
+
function trimNoninitialLines(str, indentWidth2) {
|
|
834
|
+
const lines = str.split(LF);
|
|
835
|
+
const resultLines = [lines[0]];
|
|
836
|
+
for (let i = 1; i < lines.length; ++i) {
|
|
837
|
+
resultLines.push(lines[i].slice(indentWidth2));
|
|
838
|
+
}
|
|
839
|
+
return resultLines.join("\n");
|
|
840
|
+
}
|
|
841
|
+
const NULLABLE_SCHEMA = "tech.ostack.kform.schemas.NullableSchema";
|
|
842
|
+
const anySchematicKind = {
|
|
843
|
+
kind: "Any",
|
|
844
|
+
package: "kotlin",
|
|
845
|
+
name: "Any",
|
|
846
|
+
schema: "tech.ostack.kform.schemas.AnySchema",
|
|
847
|
+
nullable: false,
|
|
848
|
+
defaultValue: "null",
|
|
849
|
+
scaffoldType: () => "Any?"
|
|
850
|
+
};
|
|
851
|
+
const bigDecimalSchematicKind = {
|
|
852
|
+
kind: "BigDecimal",
|
|
853
|
+
package: "tech.ostack.kform.datatypes",
|
|
854
|
+
name: "BigDecimal",
|
|
855
|
+
schema: "tech.ostack.kform.schemas.BigDecimalSchema",
|
|
856
|
+
defaultNullable: true,
|
|
857
|
+
defaultValue: "BigDecimal.ZERO"
|
|
858
|
+
};
|
|
859
|
+
const bigIntegerSchematicKind = {
|
|
860
|
+
kind: "BigInteger",
|
|
861
|
+
package: "tech.ostack.kform.datatypes",
|
|
862
|
+
name: "BigInteger",
|
|
863
|
+
schema: "tech.ostack.kform.schemas.BigIntegerSchema",
|
|
864
|
+
defaultNullable: true,
|
|
865
|
+
defaultValue: "BigInteger.ZERO"
|
|
866
|
+
};
|
|
867
|
+
const booleanSchematicKind = {
|
|
868
|
+
kind: "Boolean",
|
|
869
|
+
package: "kotlin",
|
|
870
|
+
name: "Boolean",
|
|
871
|
+
schema: "tech.ostack.kform.schemas.BooleanSchema",
|
|
872
|
+
defaultValue: "false"
|
|
873
|
+
};
|
|
874
|
+
const byteSchematicKind = {
|
|
875
|
+
kind: "Byte",
|
|
876
|
+
package: "kotlin",
|
|
877
|
+
name: "Byte",
|
|
878
|
+
schema: "tech.ostack.kform.schemas.ByteSchema",
|
|
879
|
+
defaultNullable: true,
|
|
880
|
+
defaultValue: "0.toByte()"
|
|
881
|
+
};
|
|
882
|
+
const charSchematicKind = {
|
|
883
|
+
kind: "Char",
|
|
884
|
+
package: "kotlin",
|
|
885
|
+
name: "Char",
|
|
886
|
+
schema: "tech.ostack.kform.schemas.CharSchema",
|
|
887
|
+
defaultNullable: true,
|
|
888
|
+
defaultValue: "0.toChar()"
|
|
889
|
+
};
|
|
890
|
+
const classSchematicKind = {
|
|
891
|
+
kind: "Class",
|
|
892
|
+
schema: "tech.ostack.kform.schemas.ClassSchema",
|
|
893
|
+
defaultValue: (schematic) => `${schematic.name}()`,
|
|
894
|
+
builder: ClassBuilder,
|
|
895
|
+
initChildren: () => [],
|
|
896
|
+
defaultPackageSuffix: (childName) => childName.toLowerCase(),
|
|
897
|
+
defaultName: (childName) => changeCase.pascalCase(childName),
|
|
898
|
+
scaffoldModel: (schematic, data) => code`
|
|
899
|
+
data class ${schematic.name}(
|
|
900
|
+
${schematic.children?.map((childSchematic) => {
|
|
901
|
+
const childData = {
|
|
902
|
+
...data,
|
|
903
|
+
currentPath: joinPaths(
|
|
904
|
+
data.currentPath,
|
|
905
|
+
childSchematic.childName
|
|
906
|
+
)
|
|
907
|
+
};
|
|
908
|
+
return annotate(
|
|
909
|
+
scaffoldPropertyAnnotations(childSchematic, childData),
|
|
910
|
+
`var ${childSchematic.childName}: ${scaffoldType(
|
|
911
|
+
childSchematic,
|
|
912
|
+
childData
|
|
913
|
+
)} = ${scaffoldDefaultValue(childSchematic, childData)}`
|
|
914
|
+
);
|
|
915
|
+
}).join(",\n")}
|
|
916
|
+
)
|
|
917
|
+
`,
|
|
918
|
+
scaffoldSchema: (schematic, data) => code`
|
|
919
|
+
ClassSchema {
|
|
920
|
+
${schematic.children?.map(
|
|
921
|
+
(childSchematic) => `${schematic.name}::${childSchematic.childName} { ${scaffoldSchema(
|
|
922
|
+
childSchematic,
|
|
923
|
+
{
|
|
924
|
+
...data,
|
|
925
|
+
currentPath: joinPaths(
|
|
926
|
+
data.currentPath,
|
|
927
|
+
childSchematic.childName
|
|
928
|
+
)
|
|
929
|
+
}
|
|
930
|
+
)} }`
|
|
931
|
+
).join("\n")}
|
|
932
|
+
}
|
|
933
|
+
`
|
|
934
|
+
};
|
|
935
|
+
const doubleSchematicKind = {
|
|
936
|
+
kind: "Double",
|
|
937
|
+
package: "kotlin",
|
|
938
|
+
name: "Double",
|
|
939
|
+
schema: "tech.ostack.kform.schemas.DoubleSchema",
|
|
940
|
+
defaultNullable: true,
|
|
941
|
+
defaultValue: "0.0"
|
|
942
|
+
};
|
|
943
|
+
const enumSchematicKind = {
|
|
944
|
+
kind: "Enum",
|
|
945
|
+
schema: "tech.ostack.kform.schemas.EnumSchema",
|
|
946
|
+
defaultNullable: true,
|
|
947
|
+
defaultValue: (schematic) => `${schematic.name}.${schematic.children?.[0].childName}`,
|
|
948
|
+
builder: EnumBuilder,
|
|
949
|
+
initChildren: () => [],
|
|
950
|
+
defaultName: (childName) => changeCase.pascalCase(childName),
|
|
951
|
+
scaffoldModel: (schematic) => code`
|
|
952
|
+
enum class ${schematic.name} {
|
|
953
|
+
${schematic.children?.map((childSchematic) => childSchematic.childName).join(",\n")}
|
|
954
|
+
}
|
|
955
|
+
`
|
|
956
|
+
};
|
|
957
|
+
const fileSchematicKind = {
|
|
958
|
+
kind: "File",
|
|
959
|
+
package: "tech.ostack.kform.datatypes",
|
|
960
|
+
name: "File",
|
|
961
|
+
schema: "tech.ostack.kform.schemas.FileSchema",
|
|
962
|
+
defaultNullable: true,
|
|
963
|
+
defaultValue: (_schematic, data) => {
|
|
964
|
+
data.currentFile.imports.add(
|
|
965
|
+
"tech.ostack.kform.datatypes.emptyPlaceholderFile"
|
|
966
|
+
);
|
|
967
|
+
return "emptyPlaceholderFile()";
|
|
968
|
+
},
|
|
969
|
+
propertyAnnotations: (_schematic, data) => data.useFileBase64Serializer ? "@Serializable(with = File.Base64Serializer::class)" : void 0
|
|
970
|
+
};
|
|
971
|
+
const floatSchematicKind = {
|
|
972
|
+
kind: "Float",
|
|
973
|
+
package: "kotlin",
|
|
974
|
+
name: "Float",
|
|
975
|
+
schema: "tech.ostack.kform.schemas.FloatSchema",
|
|
976
|
+
defaultNullable: true,
|
|
977
|
+
defaultValue: "0f"
|
|
978
|
+
};
|
|
979
|
+
const instantSchematicKind = {
|
|
980
|
+
kind: "Instant",
|
|
981
|
+
package: "kotlin.time",
|
|
982
|
+
name: "Instant",
|
|
983
|
+
schema: "tech.ostack.kform.schemas.InstantSchema",
|
|
984
|
+
defaultNullable: true,
|
|
985
|
+
defaultValue: "Instant.fromEpochMilliseconds(0)",
|
|
986
|
+
propertyAnnotations: (_schematic, data) => {
|
|
987
|
+
data.currentFile.imports.add("kotlin.OptIn").add("kotlin.time.ExperimentalTime");
|
|
988
|
+
return "@OptIn(ExperimentalTime::class)";
|
|
989
|
+
}
|
|
990
|
+
};
|
|
991
|
+
const intSchematicKind = {
|
|
992
|
+
kind: "Int",
|
|
993
|
+
package: "kotlin",
|
|
994
|
+
name: "Int",
|
|
995
|
+
schema: "tech.ostack.kform.schemas.IntSchema",
|
|
996
|
+
defaultNullable: true,
|
|
997
|
+
defaultValue: "0"
|
|
998
|
+
};
|
|
999
|
+
const listSchematicKind = {
|
|
1000
|
+
kind: "List",
|
|
1001
|
+
package: "kotlin.collections",
|
|
1002
|
+
name: "List",
|
|
1003
|
+
schema: "tech.ostack.kform.schemas.ListSchema",
|
|
1004
|
+
defaultValue: "emptyList()",
|
|
1005
|
+
builder: ListableBuilder,
|
|
1006
|
+
initChildren: () => [createSchematic()],
|
|
1007
|
+
scaffoldType: (schematic, data) => `List<${scaffoldType(schematic.children[0], {
|
|
1008
|
+
...data,
|
|
1009
|
+
currentPath: joinPaths(data.currentPath, "*")
|
|
1010
|
+
})}>`,
|
|
1011
|
+
scaffoldSchema: (schematic, data) => `ListSchema { ${scaffoldSchema(schematic.children[0], {
|
|
1012
|
+
...data,
|
|
1013
|
+
currentPath: joinPaths(data.currentPath, "*")
|
|
1014
|
+
})} }`
|
|
1015
|
+
};
|
|
1016
|
+
const localDateSchematicKind = {
|
|
1017
|
+
kind: "LocalDate",
|
|
1018
|
+
package: "kotlinx.datetime",
|
|
1019
|
+
name: "LocalDate",
|
|
1020
|
+
schema: "tech.ostack.kform.schemas.LocalDateSchema",
|
|
1021
|
+
defaultNullable: true,
|
|
1022
|
+
defaultValue: "LocalDate(1970, 1, 1)"
|
|
1023
|
+
};
|
|
1024
|
+
const localDateTimeSchematicKind = {
|
|
1025
|
+
kind: "LocalDateTime",
|
|
1026
|
+
package: "kotlinx.datetime",
|
|
1027
|
+
name: "LocalDateTime",
|
|
1028
|
+
schema: "tech.ostack.kform.schemas.LocalDateTimeSchema",
|
|
1029
|
+
defaultNullable: true,
|
|
1030
|
+
defaultValue: "LocalDateTime(1970, 1, 1, 0, 0)"
|
|
1031
|
+
};
|
|
1032
|
+
const longSchematicKind = {
|
|
1033
|
+
kind: "Long",
|
|
1034
|
+
package: "kotlin",
|
|
1035
|
+
name: "Long",
|
|
1036
|
+
schema: "tech.ostack.kform.schemas.LongSchema",
|
|
1037
|
+
defaultNullable: true,
|
|
1038
|
+
defaultValue: "0L"
|
|
1039
|
+
};
|
|
1040
|
+
const shortSchematicKind = {
|
|
1041
|
+
kind: "Short",
|
|
1042
|
+
package: "kotlin",
|
|
1043
|
+
name: "Short",
|
|
1044
|
+
schema: "tech.ostack.kform.schemas.ShortSchema",
|
|
1045
|
+
defaultNullable: true,
|
|
1046
|
+
defaultValue: "0.toShort()"
|
|
1047
|
+
};
|
|
1048
|
+
const stringSchematicKind = {
|
|
1049
|
+
kind: "String",
|
|
1050
|
+
package: "kotlin",
|
|
1051
|
+
name: "String",
|
|
1052
|
+
schema: "tech.ostack.kform.schemas.StringSchema",
|
|
1053
|
+
defaultValue: '""'
|
|
1054
|
+
};
|
|
1055
|
+
const tableSchematicKind = {
|
|
1056
|
+
kind: "Table",
|
|
1057
|
+
package: "tech.ostack.kform.datatypes",
|
|
1058
|
+
name: "Table",
|
|
1059
|
+
schema: "tech.ostack.kform.schemas.TableSchema",
|
|
1060
|
+
defaultValue: (_schematic, data) => {
|
|
1061
|
+
data.currentFile.imports.add("tech.ostack.kform.datatypes.tableOf");
|
|
1062
|
+
return "tableOf()";
|
|
1063
|
+
},
|
|
1064
|
+
builder: ListableBuilder,
|
|
1065
|
+
initChildren: () => [createSchematic()],
|
|
1066
|
+
propertyAnnotations: (_schematic, data) => data.useTableValuesSerializer ? "@Serializable(with = Table.ValuesSerializer::class)" : void 0,
|
|
1067
|
+
scaffoldType: (schematic, data) => `Table<${scaffoldType(schematic.children[0], {
|
|
1068
|
+
...data,
|
|
1069
|
+
currentPath: joinPaths(data.currentPath, "*")
|
|
1070
|
+
})}>`,
|
|
1071
|
+
scaffoldSchema: (schematic, data) => `TableSchema { ${scaffoldSchema(schematic.children[0], {
|
|
1072
|
+
...data,
|
|
1073
|
+
currentPath: joinPaths(data.currentPath, "*")
|
|
1074
|
+
})} }`
|
|
1075
|
+
};
|
|
1076
|
+
const defaultSchematicKinds = [
|
|
1077
|
+
anySchematicKind,
|
|
1078
|
+
bigDecimalSchematicKind,
|
|
1079
|
+
bigIntegerSchematicKind,
|
|
1080
|
+
booleanSchematicKind,
|
|
1081
|
+
byteSchematicKind,
|
|
1082
|
+
charSchematicKind,
|
|
1083
|
+
classSchematicKind,
|
|
1084
|
+
doubleSchematicKind,
|
|
1085
|
+
enumSchematicKind,
|
|
1086
|
+
fileSchematicKind,
|
|
1087
|
+
floatSchematicKind,
|
|
1088
|
+
instantSchematicKind,
|
|
1089
|
+
intSchematicKind,
|
|
1090
|
+
listSchematicKind,
|
|
1091
|
+
localDateSchematicKind,
|
|
1092
|
+
localDateTimeSchematicKind,
|
|
1093
|
+
longSchematicKind,
|
|
1094
|
+
shortSchematicKind,
|
|
1095
|
+
stringSchematicKind,
|
|
1096
|
+
tableSchematicKind
|
|
1097
|
+
];
|
|
1098
|
+
function scaffold(schematic, scaffolders, options) {
|
|
1099
|
+
const files = /* @__PURE__ */ new Map();
|
|
1100
|
+
const data = {
|
|
1101
|
+
schematicKinds: options.schematicKinds,
|
|
1102
|
+
rootSchematic: schematic,
|
|
1103
|
+
files,
|
|
1104
|
+
currentPath: options.basePath ?? "/",
|
|
1105
|
+
currentPackage: joinPackages(options.basePackage, schematic.packageSuffix),
|
|
1106
|
+
currentDir: options.baseDir
|
|
1107
|
+
};
|
|
1108
|
+
for (const scaffolder of scaffolders) {
|
|
1109
|
+
scaffolder(schematic, data);
|
|
1110
|
+
}
|
|
1111
|
+
return Array.from(files).map(([path, file]) => ({
|
|
1112
|
+
path,
|
|
1113
|
+
content: file.getContent(),
|
|
1114
|
+
base64: file.base64,
|
|
1115
|
+
binary: file.binary,
|
|
1116
|
+
executable: file.executable
|
|
1117
|
+
}));
|
|
1118
|
+
}
|
|
1119
|
+
const SchematicBuilderContext = React__namespace.createContext(null);
|
|
1120
|
+
function useSchematicBuilderContext() {
|
|
1121
|
+
const context = React__namespace.useContext(SchematicBuilderContext);
|
|
1122
|
+
if (context === null) {
|
|
1123
|
+
throw new Error("Schematic builder not in context.");
|
|
1124
|
+
}
|
|
1125
|
+
return context;
|
|
1126
|
+
}
|
|
1127
|
+
function LoadSchematic() {
|
|
1128
|
+
const { name, setSchematic, latestSchematicFileHandleRef } = useSchematicBuilderContext();
|
|
1129
|
+
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
1130
|
+
"button",
|
|
1131
|
+
{
|
|
1132
|
+
className: "builder-icon-button builder-action builder-load-schematic",
|
|
1133
|
+
type: "button",
|
|
1134
|
+
onClick: async () => {
|
|
1135
|
+
try {
|
|
1136
|
+
const file = await browserFsAccess.fileOpen({
|
|
1137
|
+
extensions: [".json"],
|
|
1138
|
+
mimeTypes: ["application/json"],
|
|
1139
|
+
description: "Form schematic",
|
|
1140
|
+
id: name
|
|
1141
|
+
});
|
|
1142
|
+
if (file.handle) {
|
|
1143
|
+
latestSchematicFileHandleRef.current = file.handle;
|
|
1144
|
+
}
|
|
1145
|
+
const content = JSON.parse(await file.text());
|
|
1146
|
+
setSchematic(() => content);
|
|
1147
|
+
} catch (err) {
|
|
1148
|
+
if (err instanceof DOMException && err.name === "AbortError") {
|
|
1149
|
+
return;
|
|
1150
|
+
}
|
|
1151
|
+
alert(`Unable to load schematic: ${err?.toString()}`);
|
|
1152
|
+
}
|
|
1153
|
+
},
|
|
1154
|
+
title: "Load schematic",
|
|
1155
|
+
"aria-label": "Load schematic",
|
|
1156
|
+
children: "📂"
|
|
1157
|
+
}
|
|
1158
|
+
);
|
|
1159
|
+
}
|
|
1160
|
+
function SaveSchematic() {
|
|
1161
|
+
const { name, getRootSchematic, latestSchematicFileHandleRef } = useSchematicBuilderContext();
|
|
1162
|
+
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
1163
|
+
"button",
|
|
1164
|
+
{
|
|
1165
|
+
className: "builder-icon-button builder-action builder-save-schematic",
|
|
1166
|
+
type: "button",
|
|
1167
|
+
onClick: async () => {
|
|
1168
|
+
try {
|
|
1169
|
+
const schematic = getRootSchematic();
|
|
1170
|
+
latestSchematicFileHandleRef.current = await browserFsAccess.fileSave(
|
|
1171
|
+
new Blob([JSON.stringify(schematic, null, 2)]),
|
|
1172
|
+
{
|
|
1173
|
+
fileName: `${schematic.name}-schematic.json`,
|
|
1174
|
+
extensions: [".json"],
|
|
1175
|
+
mimeTypes: ["application/json"],
|
|
1176
|
+
description: "Form schematic",
|
|
1177
|
+
id: name
|
|
1178
|
+
},
|
|
1179
|
+
latestSchematicFileHandleRef.current
|
|
1180
|
+
);
|
|
1181
|
+
if (browserFsAccess.supported) {
|
|
1182
|
+
alert(
|
|
1183
|
+
`Schematic saved successfully as “${latestSchematicFileHandleRef.current.name}”.`
|
|
1184
|
+
);
|
|
1185
|
+
}
|
|
1186
|
+
} catch (err) {
|
|
1187
|
+
if (err instanceof DOMException && err.name === "AbortError") {
|
|
1188
|
+
return;
|
|
1189
|
+
}
|
|
1190
|
+
alert(`Unable to save schematic: ${err?.toString()}`);
|
|
1191
|
+
}
|
|
1192
|
+
},
|
|
1193
|
+
title: "Save schematic",
|
|
1194
|
+
"aria-label": "Save schematic",
|
|
1195
|
+
children: "💾"
|
|
1196
|
+
}
|
|
1197
|
+
);
|
|
1198
|
+
}
|
|
1199
|
+
function configScaffolder(scaffolder, data) {
|
|
1200
|
+
return (schematic, originalData) => scaffolder(schematic, { ...originalData, ...data });
|
|
1201
|
+
}
|
|
1202
|
+
function useScaffolder() {
|
|
1203
|
+
const {
|
|
1204
|
+
basePath,
|
|
1205
|
+
basePackage,
|
|
1206
|
+
baseDir,
|
|
1207
|
+
schematicKinds,
|
|
1208
|
+
scaffolders,
|
|
1209
|
+
scaffoldingData,
|
|
1210
|
+
getRootSchematic
|
|
1211
|
+
} = useSchematicBuilderContext();
|
|
1212
|
+
return React__namespace.useCallback(() => {
|
|
1213
|
+
const schematic = getRootSchematic();
|
|
1214
|
+
let actualScaffolders = typeof scaffolders === "function" ? scaffolders(schematic) : scaffolders;
|
|
1215
|
+
const actualScaffoldingData = typeof scaffoldingData === "function" ? scaffoldingData(schematic) : scaffoldingData;
|
|
1216
|
+
if (actualScaffoldingData) {
|
|
1217
|
+
actualScaffolders = actualScaffolders.map(
|
|
1218
|
+
(scaffolder) => configScaffolder(scaffolder, actualScaffoldingData)
|
|
1219
|
+
);
|
|
1220
|
+
}
|
|
1221
|
+
return scaffold(schematic, actualScaffolders, {
|
|
1222
|
+
schematicKinds,
|
|
1223
|
+
basePath,
|
|
1224
|
+
basePackage,
|
|
1225
|
+
baseDir: typeof baseDir === "function" ? baseDir(schematic) : baseDir
|
|
1226
|
+
});
|
|
1227
|
+
}, [
|
|
1228
|
+
baseDir,
|
|
1229
|
+
basePackage,
|
|
1230
|
+
basePath,
|
|
1231
|
+
getRootSchematic,
|
|
1232
|
+
scaffolders,
|
|
1233
|
+
scaffoldingData,
|
|
1234
|
+
schematicKinds
|
|
1235
|
+
]);
|
|
1236
|
+
}
|
|
1237
|
+
let latestZipFileHandle = null;
|
|
1238
|
+
function ScaffoldToZip() {
|
|
1239
|
+
const { getRootSchematic, name } = useSchematicBuilderContext();
|
|
1240
|
+
const scaffold2 = useScaffolder();
|
|
1241
|
+
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
1242
|
+
"button",
|
|
1243
|
+
{
|
|
1244
|
+
className: "builder-input builder-action builder-scaffold-zip",
|
|
1245
|
+
type: "submit",
|
|
1246
|
+
onClick: async (evt) => {
|
|
1247
|
+
evt.preventDefault();
|
|
1248
|
+
try {
|
|
1249
|
+
const schematic = getRootSchematic();
|
|
1250
|
+
const files = scaffold2();
|
|
1251
|
+
const zip = new JSZip();
|
|
1252
|
+
for (const { path, content, base64, binary, executable } of files) {
|
|
1253
|
+
zip.file(path, content, {
|
|
1254
|
+
base64,
|
|
1255
|
+
binary,
|
|
1256
|
+
unixPermissions: executable ? "755" : void 0
|
|
1257
|
+
});
|
|
1258
|
+
}
|
|
1259
|
+
latestZipFileHandle = await browserFsAccess.fileSave(
|
|
1260
|
+
zip.generateAsync({ platform: "UNIX", type: "blob" }),
|
|
1261
|
+
{
|
|
1262
|
+
fileName: `${schematic.name}.zip`,
|
|
1263
|
+
extensions: [".zip"],
|
|
1264
|
+
mimeTypes: ["application/zip"],
|
|
1265
|
+
description: "Form scaffolding",
|
|
1266
|
+
id: name
|
|
1267
|
+
},
|
|
1268
|
+
latestZipFileHandle
|
|
1269
|
+
);
|
|
1270
|
+
if (browserFsAccess.supported) {
|
|
1271
|
+
alert(
|
|
1272
|
+
`Project scaffolded successfully in “${latestZipFileHandle.name}”.`
|
|
1273
|
+
);
|
|
1274
|
+
}
|
|
1275
|
+
} catch (err) {
|
|
1276
|
+
if (err instanceof DOMException && err.name === "AbortError") {
|
|
1277
|
+
return;
|
|
1278
|
+
}
|
|
1279
|
+
alert(`Unable to scaffold project: ${err?.toString()}`);
|
|
1280
|
+
}
|
|
1281
|
+
},
|
|
1282
|
+
children: "Scaffold 🏗️"
|
|
1283
|
+
}
|
|
1284
|
+
);
|
|
1285
|
+
}
|
|
1286
|
+
function useConfig(configName, defaultValue) {
|
|
1287
|
+
const { useSchematic, setSchematic } = useSchematicBuilderContext();
|
|
1288
|
+
const configValue = useSchematic(
|
|
1289
|
+
(schematic) => schematic.config?.[configName] ?? defaultValue
|
|
1290
|
+
);
|
|
1291
|
+
const setConfigValue = React__namespace.useCallback(
|
|
1292
|
+
(configValue2) => setSchematic((schematic) => ({
|
|
1293
|
+
config: {
|
|
1294
|
+
...schematic.config,
|
|
1295
|
+
[configName]: typeof configValue2 === "function" ? configValue2(schematic.config?.[configName]) : configValue2
|
|
1296
|
+
}
|
|
1297
|
+
})),
|
|
1298
|
+
[configName, setSchematic]
|
|
1299
|
+
);
|
|
1300
|
+
return React__namespace.useMemo(
|
|
1301
|
+
() => [configValue, setConfigValue],
|
|
1302
|
+
[configValue, setConfigValue]
|
|
1303
|
+
);
|
|
1304
|
+
}
|
|
1305
|
+
function UseFileBase64SerializerConfig({
|
|
1306
|
+
disabled
|
|
1307
|
+
}) {
|
|
1308
|
+
const [config, setConfig] = useConfig("useFileBase64Serializer", false);
|
|
1309
|
+
return /* @__PURE__ */ jsxRuntime.jsx("div", { className: "builder-config-field", children: /* @__PURE__ */ jsxRuntime.jsxs("label", { children: [
|
|
1310
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
1311
|
+
"input",
|
|
1312
|
+
{
|
|
1313
|
+
type: "checkbox",
|
|
1314
|
+
checked: config,
|
|
1315
|
+
onChange: (evt) => setConfig(evt.target.checked),
|
|
1316
|
+
disabled
|
|
1317
|
+
}
|
|
1318
|
+
),
|
|
1319
|
+
"Use ",
|
|
1320
|
+
/* @__PURE__ */ jsxRuntime.jsx("code", { children: "File.Base64Serializer" })
|
|
1321
|
+
] }) });
|
|
1322
|
+
}
|
|
1323
|
+
function UseTableValuesSerializerConfig({
|
|
1324
|
+
disabled
|
|
1325
|
+
}) {
|
|
1326
|
+
const [config, setConfig] = useConfig("useTableValuesSerializer", false);
|
|
1327
|
+
return /* @__PURE__ */ jsxRuntime.jsx("div", { className: "builder-config-field", children: /* @__PURE__ */ jsxRuntime.jsxs("label", { children: [
|
|
1328
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
1329
|
+
"input",
|
|
1330
|
+
{
|
|
1331
|
+
type: "checkbox",
|
|
1332
|
+
checked: config,
|
|
1333
|
+
onChange: (evt) => setConfig(evt.target.checked),
|
|
1334
|
+
disabled
|
|
1335
|
+
}
|
|
1336
|
+
),
|
|
1337
|
+
"Use ",
|
|
1338
|
+
/* @__PURE__ */ jsxRuntime.jsx("code", { children: "Table.ValuesSerializer" })
|
|
1339
|
+
] }) });
|
|
1340
|
+
}
|
|
1341
|
+
const serializerKt = "package <%= filePackage %>\n\nimport kotlin.js.JsExport\nimport kotlin.jvm.JvmOverloads\nimport kotlinx.serialization.json.Json\n\n/** Base JSON configuration. */\nprivate val JSON_CONFIG = Json.Default\n/** Pretty JSON configuration. */\nprivate val JSON_CONFIG_PRETTY = Json(JSON_CONFIG) { prettyPrint = true }\n\n/** JSON configuration. */\n@JvmOverloads\nfun jsonConfig(prettyPrint: Boolean = false): Json =\n if (prettyPrint) JSON_CONFIG_PRETTY else JSON_CONFIG\n\n@JsExport\n@JvmOverloads\nfun encode<%= formClass %>ToString(<%= formVar %>: <%= formClass %>, prettyPrint: Boolean = false): String =\n jsonConfig(prettyPrint).encodeToString(<%= formVar %>)\n\n@JsExport\nfun decode<%= formClass %>FromString(json: String): <%= formClass %> =\n jsonConfig().decodeFromString(json)\n";
|
|
1342
|
+
function templateFile(content, options) {
|
|
1343
|
+
return {
|
|
1344
|
+
...options,
|
|
1345
|
+
content,
|
|
1346
|
+
getContent: templateFileContent
|
|
1347
|
+
};
|
|
1348
|
+
}
|
|
1349
|
+
function templateFileContent() {
|
|
1350
|
+
return this.content;
|
|
1351
|
+
}
|
|
1352
|
+
function ejsTemplateFile(content, ejsData, { base64, binary, executable, ...ejsOptions } = {}) {
|
|
1353
|
+
return {
|
|
1354
|
+
content,
|
|
1355
|
+
ejsData,
|
|
1356
|
+
base64,
|
|
1357
|
+
binary,
|
|
1358
|
+
executable,
|
|
1359
|
+
ejsOptions,
|
|
1360
|
+
getContent: ejsTemplateFileContent
|
|
1361
|
+
};
|
|
1362
|
+
}
|
|
1363
|
+
function ejsTemplateFileContent() {
|
|
1364
|
+
return ejs.render(this.content, this.ejsData, {
|
|
1365
|
+
strict: true,
|
|
1366
|
+
destructuredLocals: Object.keys(this.ejsData ?? {}),
|
|
1367
|
+
...this.ejsOptions
|
|
1368
|
+
});
|
|
1369
|
+
}
|
|
1370
|
+
function addEjsTemplateFile(data, fileName, content, ejsData, options) {
|
|
1371
|
+
data.files.set(
|
|
1372
|
+
joinPaths(data.currentDir, fileName),
|
|
1373
|
+
ejsTemplateFile(content, ejsData, options)
|
|
1374
|
+
);
|
|
1375
|
+
}
|
|
1376
|
+
function scaffoldSerializer(schematic, data) {
|
|
1377
|
+
addEjsTemplateFile(data, `${schematic.name}Serializer.kt`, serializerKt, {
|
|
1378
|
+
filePackage: data.currentPackage,
|
|
1379
|
+
formVar: changeCase.camelCase(schematic.name),
|
|
1380
|
+
formClass: schematic.name
|
|
1381
|
+
});
|
|
1382
|
+
}
|
|
1383
|
+
const validatorKt = "package <%= filePackage %>\n\nimport tech.ostack.kform.ExternalContexts\nimport tech.ostack.kform.FormValidator\nimport tech.ostack.kform.LocatedValidationError\nimport tech.ostack.kform.LocatedValidationWarning\nimport tech.ostack.kform.test.assertContainsMatchingIssue\nimport tech.ostack.kform.test.assertNotContainsMatchingIssue\n\nval <%= formVar %>Validator by lazy { FormValidator(<%= formClass %>Schema) }\n\nfun validate<%= formClass %>(\n <%= formVar %>: <%= formClass %>,\n path: String,\n externalContexts: ExternalContexts = emptyMap(),\n) = <%= formVar %>Validator.validate(<%= formVar %>, path, externalContexts)\n\nsuspend fun assert<%= formClass %>ContainsError(\n path: String,\n code: String,\n <%= formVar %>: <%= formClass %>,\n externalContexts: ExternalContexts = emptyMap(),\n) =\n assertContainsMatchingIssue(\n LocatedValidationError(path, code),\n validate<%= formClass %>(<%= formVar %>, path, externalContexts),\n )\n\nsuspend fun assert<%= formClass %>NotContainsError(\n path: String,\n code: String,\n <%= formVar %>: <%= formClass %>,\n externalContexts: ExternalContexts = emptyMap(),\n) =\n assertNotContainsMatchingIssue(\n LocatedValidationError(path, code),\n validate<%= formClass %>(<%= formVar %>, path, externalContexts),\n )\n\nsuspend fun assert<%= formClass %>ContainsWarning(\n path: String,\n code: String,\n <%= formVar %>: <%= formClass %>,\n externalContexts: ExternalContexts = emptyMap(),\n) =\n assertContainsMatchingIssue(\n LocatedValidationWarning(path, code),\n validate<%= formClass %>(<%= formVar %>, path, externalContexts),\n )\n\nsuspend fun assert<%= formClass %>NotContainsWarning(\n path: String,\n code: String,\n <%= formVar %>: <%= formClass %>,\n externalContexts: ExternalContexts = emptyMap(),\n) =\n assertNotContainsMatchingIssue(\n LocatedValidationWarning(path, code),\n validate<%= formClass %>(<%= formVar %>, path, externalContexts),\n )\n";
|
|
1384
|
+
function scaffoldValidator(schematic, data) {
|
|
1385
|
+
addEjsTemplateFile(data, `${schematic.name}Validator.kt`, validatorKt, {
|
|
1386
|
+
filePackage: data.currentPackage,
|
|
1387
|
+
formVar: changeCase.camelCase(schematic.name),
|
|
1388
|
+
formClass: schematic.name
|
|
1389
|
+
});
|
|
1390
|
+
}
|
|
1391
|
+
const useLayoutEffect = typeof document !== "undefined" ? React__namespace.useLayoutEffect : () => {
|
|
1392
|
+
};
|
|
1393
|
+
function useMeasure(element, setMeasurement) {
|
|
1394
|
+
useLayoutEffect(() => {
|
|
1395
|
+
if (!element) {
|
|
1396
|
+
setMeasurement(void 0);
|
|
1397
|
+
return;
|
|
1398
|
+
}
|
|
1399
|
+
const cb = () => setMeasurement(element.getBoundingClientRect());
|
|
1400
|
+
cb();
|
|
1401
|
+
const observer = new ResizeObserver(([entry]) => entry && cb());
|
|
1402
|
+
observer.observe(element);
|
|
1403
|
+
window.addEventListener("resize", cb);
|
|
1404
|
+
return () => {
|
|
1405
|
+
observer.disconnect();
|
|
1406
|
+
window.removeEventListener("resize", cb);
|
|
1407
|
+
setMeasurement(void 0);
|
|
1408
|
+
};
|
|
1409
|
+
}, [element, setMeasurement]);
|
|
1410
|
+
}
|
|
1411
|
+
function SchematicBuilderConfig({
|
|
1412
|
+
children
|
|
1413
|
+
}) {
|
|
1414
|
+
const [anchorEl, setAnchorEl] = React__namespace.useState(
|
|
1415
|
+
null
|
|
1416
|
+
);
|
|
1417
|
+
const [popoverEl, setPopoverEl] = React__namespace.useState(null);
|
|
1418
|
+
useMeasure(anchorEl, (measurement) => {
|
|
1419
|
+
if (popoverEl && measurement) {
|
|
1420
|
+
popoverEl.style.setProperty("--anchor-top", `${measurement.top}px`);
|
|
1421
|
+
popoverEl.style.setProperty("--anchor-left", `${measurement.left}px`);
|
|
1422
|
+
popoverEl.style.setProperty("--anchor-bottom", `${measurement.bottom}px`);
|
|
1423
|
+
popoverEl.style.setProperty("--anchor-right", `${measurement.right}px`);
|
|
1424
|
+
popoverEl.style.setProperty("--anchor-width", `${measurement.width}px`);
|
|
1425
|
+
popoverEl.style.setProperty("--anchor-height", `${measurement.height}px`);
|
|
1426
|
+
}
|
|
1427
|
+
});
|
|
1428
|
+
useMeasure(popoverEl, (measurement) => {
|
|
1429
|
+
if (popoverEl && measurement) {
|
|
1430
|
+
popoverEl.style.setProperty("--width", `${measurement.width}px`);
|
|
1431
|
+
popoverEl.style.setProperty("--height", `${measurement.height}px`);
|
|
1432
|
+
}
|
|
1433
|
+
});
|
|
1434
|
+
return /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
|
|
1435
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
1436
|
+
"button",
|
|
1437
|
+
{
|
|
1438
|
+
type: "button",
|
|
1439
|
+
className: "builder-icon-button builder-action builder-config-schematic",
|
|
1440
|
+
popoverTarget: "builder-config-popover",
|
|
1441
|
+
title: "Config",
|
|
1442
|
+
"aria-label": "Config",
|
|
1443
|
+
ref: setAnchorEl,
|
|
1444
|
+
children: "⚙️"
|
|
1445
|
+
}
|
|
1446
|
+
),
|
|
1447
|
+
/* @__PURE__ */ jsxRuntime.jsx("div", { popover: "", id: "builder-config-popover", ref: setPopoverEl, children })
|
|
1448
|
+
] });
|
|
1449
|
+
}
|
|
1450
|
+
const kotlinMainData = {
|
|
1451
|
+
currentDir: "shared/src/commonMain/kotlin"
|
|
1452
|
+
};
|
|
1453
|
+
const kotlinTestData = {
|
|
1454
|
+
currentDir: "shared/src/commonTest/kotlin"
|
|
1455
|
+
};
|
|
1456
|
+
function SchematicBuilder({
|
|
1457
|
+
name = "kform",
|
|
1458
|
+
title = document.title,
|
|
1459
|
+
basePath,
|
|
1460
|
+
basePackage,
|
|
1461
|
+
baseDir,
|
|
1462
|
+
defaultRootClassPackage = "org.example",
|
|
1463
|
+
defaultRootClassName = "MyForm",
|
|
1464
|
+
schematicKinds = defaultSchematicKinds,
|
|
1465
|
+
scaffolders = [
|
|
1466
|
+
configScaffolder(scaffoldSchemas, kotlinMainData),
|
|
1467
|
+
configScaffolder(scaffoldModels, kotlinMainData),
|
|
1468
|
+
configScaffolder(scaffoldSerializer, kotlinMainData),
|
|
1469
|
+
configScaffolder(scaffoldValidator, kotlinTestData)
|
|
1470
|
+
],
|
|
1471
|
+
scaffoldingData = (schematic) => schematic.config,
|
|
1472
|
+
actions = /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
|
|
1473
|
+
/* @__PURE__ */ jsxRuntime.jsx(LoadSchematic, {}),
|
|
1474
|
+
/* @__PURE__ */ jsxRuntime.jsx(SaveSchematic, {}),
|
|
1475
|
+
/* @__PURE__ */ jsxRuntime.jsx(ScaffoldToZip, {})
|
|
1476
|
+
] }),
|
|
1477
|
+
configs = /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
|
|
1478
|
+
/* @__PURE__ */ jsxRuntime.jsx(UseFileBase64SerializerConfig, {}),
|
|
1479
|
+
/* @__PURE__ */ jsxRuntime.jsx(UseTableValuesSerializerConfig, {})
|
|
1480
|
+
] })
|
|
1481
|
+
}) {
|
|
1482
|
+
const [useSchematic] = React__namespace.useState(
|
|
1483
|
+
() => zustand.create(
|
|
1484
|
+
middleware.persist(
|
|
1485
|
+
() => createSchematic({
|
|
1486
|
+
kind: classSchematicKind.kind,
|
|
1487
|
+
packageSuffix: defaultRootClassPackage,
|
|
1488
|
+
name: defaultRootClassName,
|
|
1489
|
+
children: []
|
|
1490
|
+
}),
|
|
1491
|
+
{ name }
|
|
1492
|
+
)
|
|
1493
|
+
)
|
|
1494
|
+
);
|
|
1495
|
+
const schematicKindsMap = React__namespace.useMemo(
|
|
1496
|
+
() => new Map(
|
|
1497
|
+
schematicKinds.sort((t1, t2) => t1.kind.localeCompare(t2.kind)).map((t) => [t.kind, t])
|
|
1498
|
+
),
|
|
1499
|
+
[schematicKinds]
|
|
1500
|
+
);
|
|
1501
|
+
const latestSchematicFileHandleRef = React__namespace.useRef(null);
|
|
1502
|
+
const [draggedSchematic, setDraggedSchematic] = React__namespace.useState(null);
|
|
1503
|
+
const sensors = core.useSensors(
|
|
1504
|
+
core.useSensor(core.PointerSensor, {
|
|
1505
|
+
activationConstraint: { distance: 10, delay: 400, tolerance: 20 }
|
|
1506
|
+
}),
|
|
1507
|
+
core.useSensor(core.KeyboardSensor)
|
|
1508
|
+
);
|
|
1509
|
+
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
1510
|
+
SchematicBuilderContext.Provider,
|
|
1511
|
+
{
|
|
1512
|
+
value: {
|
|
1513
|
+
name,
|
|
1514
|
+
basePath,
|
|
1515
|
+
basePackage,
|
|
1516
|
+
baseDir,
|
|
1517
|
+
schematicKinds: schematicKindsMap,
|
|
1518
|
+
scaffolders,
|
|
1519
|
+
scaffoldingData,
|
|
1520
|
+
getRootSchematic: useSchematic.getState,
|
|
1521
|
+
useSchematic,
|
|
1522
|
+
// eslint-disable-next-line @typescript-eslint/unbound-method
|
|
1523
|
+
setSchematic: useSchematic.setState,
|
|
1524
|
+
removeSchematic: () => {
|
|
1525
|
+
},
|
|
1526
|
+
parentPackage: basePackage,
|
|
1527
|
+
draggedSchematic,
|
|
1528
|
+
latestSchematicFileHandleRef
|
|
1529
|
+
},
|
|
1530
|
+
children: /* @__PURE__ */ jsxRuntime.jsxs(
|
|
1531
|
+
core.DndContext,
|
|
1532
|
+
{
|
|
1533
|
+
sensors,
|
|
1534
|
+
collisionDetection: core.closestCenter,
|
|
1535
|
+
onDragStart: (evt) => setDraggedSchematic({
|
|
1536
|
+
id: evt.active.id,
|
|
1537
|
+
...evt.active.data.current
|
|
1538
|
+
}),
|
|
1539
|
+
onDragEnd: (evt) => {
|
|
1540
|
+
const { parentId, sortBefore, ignored } = evt.over?.data.current ?? {};
|
|
1541
|
+
if (!ignored) {
|
|
1542
|
+
useSchematic.setState(
|
|
1543
|
+
(schematic) => moveSchematic(
|
|
1544
|
+
schematic,
|
|
1545
|
+
evt.active.id,
|
|
1546
|
+
parentId,
|
|
1547
|
+
sortBefore
|
|
1548
|
+
)
|
|
1549
|
+
);
|
|
1550
|
+
}
|
|
1551
|
+
setDraggedSchematic(null);
|
|
1552
|
+
},
|
|
1553
|
+
children: [
|
|
1554
|
+
/* @__PURE__ */ jsxRuntime.jsxs("form", { className: "builder-root", children: [
|
|
1555
|
+
/* @__PURE__ */ jsxRuntime.jsxs("header", { className: "builder-header", children: [
|
|
1556
|
+
/* @__PURE__ */ jsxRuntime.jsx("h1", { className: "builder-title", children: title }),
|
|
1557
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "builder-actions", children: [
|
|
1558
|
+
configs && /* @__PURE__ */ jsxRuntime.jsx(SchematicBuilderConfig, { children: configs }),
|
|
1559
|
+
actions
|
|
1560
|
+
] })
|
|
1561
|
+
] }),
|
|
1562
|
+
/* @__PURE__ */ jsxRuntime.jsx(ClassBuilder, {})
|
|
1563
|
+
] }),
|
|
1564
|
+
/* @__PURE__ */ jsxRuntime.jsx(core.DragOverlay, { children: draggedSchematic && /* @__PURE__ */ jsxRuntime.jsx("div", { className: "builder-dragged", children: draggedSchematic.node }) })
|
|
1565
|
+
]
|
|
1566
|
+
}
|
|
1567
|
+
)
|
|
1568
|
+
}
|
|
1569
|
+
);
|
|
1570
|
+
}
|
|
1571
|
+
function addTemplateFile(data, fileName, content, options) {
|
|
1572
|
+
data.files.set(
|
|
1573
|
+
joinPaths(data.currentDir, fileName),
|
|
1574
|
+
templateFile(content, options)
|
|
1575
|
+
);
|
|
1576
|
+
}
|
|
1577
|
+
function tsFile() {
|
|
1578
|
+
return {
|
|
1579
|
+
imports: [],
|
|
1580
|
+
declarations: [],
|
|
1581
|
+
getContent: tsFileContent
|
|
1582
|
+
};
|
|
1583
|
+
}
|
|
1584
|
+
function tsFileContent() {
|
|
1585
|
+
const importStatements = tsImportsToStatements(this.imports);
|
|
1586
|
+
return [
|
|
1587
|
+
// Imports
|
|
1588
|
+
importStatements.sort((i1, i2) => i1.moduleName.localeCompare(i2.moduleName)).map((i) => tsImportStatementToString(i)).join("\n"),
|
|
1589
|
+
// Declarations
|
|
1590
|
+
...this.declarations
|
|
1591
|
+
].filter((s) => s).join("\n\n") + "\n";
|
|
1592
|
+
}
|
|
1593
|
+
function tsImportsToStatements(imports) {
|
|
1594
|
+
const importsStatements = /* @__PURE__ */ new Map();
|
|
1595
|
+
for (const imp of imports) {
|
|
1596
|
+
let statement = importsStatements.get(imp.moduleName);
|
|
1597
|
+
if (!statement) {
|
|
1598
|
+
importsStatements.set(
|
|
1599
|
+
imp.moduleName,
|
|
1600
|
+
statement = { moduleName: imp.moduleName }
|
|
1601
|
+
);
|
|
1602
|
+
}
|
|
1603
|
+
if (imp.isDefault) {
|
|
1604
|
+
statement.defaultImport = imp.name;
|
|
1605
|
+
} else if (imp.isNamespace) {
|
|
1606
|
+
statement.namespaceImport = imp.name;
|
|
1607
|
+
} else if (imp.isType) {
|
|
1608
|
+
(statement.typedImports ??= /* @__PURE__ */ new Set()).add(imp.name);
|
|
1609
|
+
} else if (imp.name) {
|
|
1610
|
+
(statement.namedImports ??= /* @__PURE__ */ new Set()).add(imp.name);
|
|
1611
|
+
}
|
|
1612
|
+
}
|
|
1613
|
+
return Array.from(importsStatements.values());
|
|
1614
|
+
}
|
|
1615
|
+
function tsImportStatementToString(importStatement) {
|
|
1616
|
+
const namedImportsArr = importStatement.namedImports ? Array.from(importStatement.namedImports).sort(
|
|
1617
|
+
(i1, i2) => i1.localeCompare(i2)
|
|
1618
|
+
) : [];
|
|
1619
|
+
const typedImportsArr = importStatement.typedImports ? Array.from(importStatement.typedImports).sort((i1, i2) => i1.localeCompare(i2)).map((i) => `type ${i}`) : [];
|
|
1620
|
+
const namedTypedImports = namedImportsArr.length > 0 || typedImportsArr.length > 0 ? `{ ${[...namedImportsArr, ...typedImportsArr].join(", ")} }` : null;
|
|
1621
|
+
const defaultImport = importStatement.defaultImport || null;
|
|
1622
|
+
const namespaceImport = importStatement.namespaceImport ? `* as ${importStatement.namespaceImport}` : null;
|
|
1623
|
+
const allImports = [defaultImport, namespaceImport, namedTypedImports].filter((s) => s).join(", ");
|
|
1624
|
+
const moduleName = `"${importStatement.moduleName}"`;
|
|
1625
|
+
return allImports ? `import ${allImports} from ${moduleName};` : `import ${moduleName};`;
|
|
1626
|
+
}
|
|
1627
|
+
exports.CLASS_DND_TYPE = CLASS_DND_TYPE;
|
|
1628
|
+
exports.ClassBuilder = ClassBuilder;
|
|
1629
|
+
exports.ClassFieldBuilder = ClassFieldBuilder;
|
|
1630
|
+
exports.ENUM_DND_TYPE = ENUM_DND_TYPE;
|
|
1631
|
+
exports.EnumBuilder = EnumBuilder;
|
|
1632
|
+
exports.EnumEntryBuilder = EnumEntryBuilder;
|
|
1633
|
+
exports.ListableBuilder = ListableBuilder;
|
|
1634
|
+
exports.ListableBuilderWithoutKindSelect = ListableBuilderWithoutKindSelect;
|
|
1635
|
+
exports.ListableItemBuilder = ListableItemBuilder;
|
|
1636
|
+
exports.LoadSchematic = LoadSchematic;
|
|
1637
|
+
exports.NULLABLE_SCHEMA = NULLABLE_SCHEMA;
|
|
1638
|
+
exports.SaveSchematic = SaveSchematic;
|
|
1639
|
+
exports.ScaffoldToZip = ScaffoldToZip;
|
|
1640
|
+
exports.SchematicBuilder = SchematicBuilder;
|
|
1641
|
+
exports.SchematicBuilderContext = SchematicBuilderContext;
|
|
1642
|
+
exports.UseFileBase64SerializerConfig = UseFileBase64SerializerConfig;
|
|
1643
|
+
exports.UseTableValuesSerializerConfig = UseTableValuesSerializerConfig;
|
|
1644
|
+
exports.addEjsTemplateFile = addEjsTemplateFile;
|
|
1645
|
+
exports.addTemplateFile = addTemplateFile;
|
|
1646
|
+
exports.annotate = annotate;
|
|
1647
|
+
exports.anySchematicKind = anySchematicKind;
|
|
1648
|
+
exports.bigDecimalSchematicKind = bigDecimalSchematicKind;
|
|
1649
|
+
exports.bigIntegerSchematicKind = bigIntegerSchematicKind;
|
|
1650
|
+
exports.boolDataAttr = boolDataAttr;
|
|
1651
|
+
exports.booleanSchematicKind = booleanSchematicKind;
|
|
1652
|
+
exports.byteSchematicKind = byteSchematicKind;
|
|
1653
|
+
exports.charSchematicKind = charSchematicKind;
|
|
1654
|
+
exports.classSchematicKind = classSchematicKind;
|
|
1655
|
+
exports.code = code;
|
|
1656
|
+
exports.configScaffolder = configScaffolder;
|
|
1657
|
+
exports.createSchematic = createSchematic;
|
|
1658
|
+
exports.defaultSchematicKinds = defaultSchematicKinds;
|
|
1659
|
+
exports.doubleSchematicKind = doubleSchematicKind;
|
|
1660
|
+
exports.ejsTemplateFile = ejsTemplateFile;
|
|
1661
|
+
exports.enumSchematicKind = enumSchematicKind;
|
|
1662
|
+
exports.fileSchematicKind = fileSchematicKind;
|
|
1663
|
+
exports.floatSchematicKind = floatSchematicKind;
|
|
1664
|
+
exports.instantSchematicKind = instantSchematicKind;
|
|
1665
|
+
exports.intSchematicKind = intSchematicKind;
|
|
1666
|
+
exports.joinPackages = joinPackages;
|
|
1667
|
+
exports.joinPaths = joinPaths;
|
|
1668
|
+
exports.jsExport = jsExport;
|
|
1669
|
+
exports.ktFile = ktFile;
|
|
1670
|
+
exports.listSchematicKind = listSchematicKind;
|
|
1671
|
+
exports.localDateSchematicKind = localDateSchematicKind;
|
|
1672
|
+
exports.localDateTimeSchematicKind = localDateTimeSchematicKind;
|
|
1673
|
+
exports.longSchematicKind = longSchematicKind;
|
|
1674
|
+
exports.moveSchematic = moveSchematic;
|
|
1675
|
+
exports.preventDrag = preventDrag;
|
|
1676
|
+
exports.scaffold = scaffold;
|
|
1677
|
+
exports.scaffoldDefaultValue = scaffoldDefaultValue;
|
|
1678
|
+
exports.scaffoldModels = scaffoldModels;
|
|
1679
|
+
exports.scaffoldPropertyAnnotations = scaffoldPropertyAnnotations;
|
|
1680
|
+
exports.scaffoldSchema = scaffoldSchema;
|
|
1681
|
+
exports.scaffoldSchemas = scaffoldSchemas;
|
|
1682
|
+
exports.scaffoldSerializer = scaffoldSerializer;
|
|
1683
|
+
exports.scaffoldType = scaffoldType;
|
|
1684
|
+
exports.scaffoldValidator = scaffoldValidator;
|
|
1685
|
+
exports.serializable = serializable;
|
|
1686
|
+
exports.shortSchematicKind = shortSchematicKind;
|
|
1687
|
+
exports.simpleKtName = simpleKtName;
|
|
1688
|
+
exports.stringSchematicKind = stringSchematicKind;
|
|
1689
|
+
exports.tableSchematicKind = tableSchematicKind;
|
|
1690
|
+
exports.templateFile = templateFile;
|
|
1691
|
+
exports.tsFile = tsFile;
|
|
1692
|
+
exports.useConfig = useConfig;
|
|
1693
|
+
exports.useScaffolder = useScaffolder;
|
|
1694
|
+
exports.useSchematicBuilderContext = useSchematicBuilderContext;
|
|
1695
|
+
//# sourceMappingURL=ostack-kform-scaffolder.cjs.map
|