@opentiny/genui-sdk-vue 1.3.0 → 1.3.1-alpha.2
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 +11 -2
- package/dist/ConfigProvider-B_1dX_dv.js +131 -0
- package/dist/ConfigProvider-B_1dX_dv.js.map +1 -0
- package/dist/{GenuiChatWithMaterials.vue_vue_type_script_setup_true_lang-CxcSUrjG.js → GenuiChatWithMaterials.vue_vue_type_script_setup_true_lang-zsZgFWJw.js} +3 -3
- package/dist/{GenuiChatWithMaterials.vue_vue_type_script_setup_true_lang-CxcSUrjG.js.map → GenuiChatWithMaterials.vue_vue_type_script_setup_true_lang-zsZgFWJw.js.map} +1 -1
- package/dist/GenuiRenderer-f2_6u1TA.js +141 -0
- package/dist/GenuiRenderer-f2_6u1TA.js.map +1 -0
- package/dist/{GenuiRendererWithMaterials.vue_vue_type_script_setup_true_lang-o5SS6BG6.js → GenuiRendererWithMaterials.vue_vue_type_script_setup_true_lang-CMjFQe5i.js} +3 -3
- package/dist/{GenuiRendererWithMaterials.vue_vue_type_script_setup_true_lang-o5SS6BG6.js.map → GenuiRendererWithMaterials.vue_vue_type_script_setup_true_lang-CMjFQe5i.js.map} +1 -1
- package/dist/chat.d.ts +6 -0
- package/dist/chat.js +17 -15
- package/dist/chat.js.map +1 -1
- package/dist/chat.types-DEDNSs5o.js +1817 -0
- package/dist/chat.types-DEDNSs5o.js.map +1 -0
- package/dist/code-generator.d.ts +139 -0
- package/dist/code-generator.js +6 -0
- package/dist/code-generator.js.map +1 -0
- package/dist/config-provider.d.ts +24 -12
- package/dist/config-provider.js +2 -2
- package/dist/index.d.ts +168 -16
- package/dist/index.js +37 -31
- package/dist/index.js.map +1 -1
- package/dist/injection-tokens-DDgspg4x.js +9067 -0
- package/dist/injection-tokens-DDgspg4x.js.map +1 -0
- package/dist/legacy-chat.d.ts +9 -1
- package/dist/legacy-chat.js +3 -3
- package/dist/legacy-renderer.js +2 -2
- package/dist/picocolors.browser-nFqgZww8.js +50 -0
- package/dist/picocolors.browser-nFqgZww8.js.map +1 -0
- package/dist/renderer.d.ts +2 -2
- package/dist/renderer.js +1 -1
- package/dist/transform-jsx.d.ts +2 -3
- package/dist/transform-jsx.js +147312 -66873
- package/dist/transform-jsx.js.map +1 -1
- package/dist/vue-code-generator-CwPQ3GDh.js +573 -0
- package/dist/vue-code-generator-CwPQ3GDh.js.map +1 -0
- package/package.json +12 -5
- package/dist/ConfigProvider-BzxW9L3f.js +0 -95
- package/dist/ConfigProvider-BzxW9L3f.js.map +0 -1
- package/dist/GenuiRenderer-BVwM5pRp.js +0 -15163
- package/dist/GenuiRenderer-BVwM5pRp.js.map +0 -1
- package/dist/___vite-browser-external_commonjs-proxy-4gYZYw55.js +0 -57
- package/dist/___vite-browser-external_commonjs-proxy-4gYZYw55.js.map +0 -1
- package/dist/chat.types-DsoAmslj.js +0 -1794
- package/dist/chat.types-DsoAmslj.js.map +0 -1
- package/dist/injection-tokens-CuDQs1ne.js +0 -114
- package/dist/injection-tokens-CuDQs1ne.js.map +0 -1
|
@@ -0,0 +1,573 @@
|
|
|
1
|
+
import { parse as R, compileScript as M, compileTemplate as w, compileStyle as V } from "@vue/compiler-sfc";
|
|
2
|
+
import { generateCodeFrame as B } from "@vue/shared";
|
|
3
|
+
const P = {
|
|
4
|
+
start: "#QUOTES_START#",
|
|
5
|
+
end: "#QUOTES_END#"
|
|
6
|
+
}, [y, b, v, T, E] = [
|
|
7
|
+
"JSExpression",
|
|
8
|
+
"JSFunction",
|
|
9
|
+
"i18n",
|
|
10
|
+
"JSResource",
|
|
11
|
+
"JSSlot"
|
|
12
|
+
], x = /\B([A-Z])/g, F = /^on([A-Z]\w*)/, D = /^on(Update:\w+)/, { start: L, end: J } = P, _ = (m = "") => m ? m.charAt(0).toUpperCase() + m.slice(1) : "", I = (m) => m.replace(x, "-$1").toLowerCase(), C = (m) => {
|
|
13
|
+
const e = m.replace(F, "$1");
|
|
14
|
+
return D.test(m) ? e.charAt(0).toLowerCase() + e.slice(1) : I(e);
|
|
15
|
+
}, j = (m) => m.replace(
|
|
16
|
+
new RegExp(`"${L}(.*?)${J}"`, "g"),
|
|
17
|
+
(e, t) => t.replace(/\\"/g, '"').replace(/\\r\\n|\\r|\\n/g, "")
|
|
18
|
+
), A = (m) => m.replace(/"/g, """), U = () => Math.random().toString(36).slice(2, 10), z = (m, e) => {
|
|
19
|
+
const { errors: t, descriptor: n } = R(e, {
|
|
20
|
+
filename: m,
|
|
21
|
+
sourceMap: !1
|
|
22
|
+
});
|
|
23
|
+
if (t.length)
|
|
24
|
+
return t.map((l) => O(e, l));
|
|
25
|
+
const s = U();
|
|
26
|
+
let o;
|
|
27
|
+
try {
|
|
28
|
+
o = M(n, { id: s }).bindings;
|
|
29
|
+
} catch (l) {
|
|
30
|
+
const u = N(l), S = u && typeof u == "object" && "loc" in u ? u.loc : void 0;
|
|
31
|
+
if (S && !S.start && S.line != null) {
|
|
32
|
+
const h = u.message.match(/.*/)[0], { line: d, column: $ } = S;
|
|
33
|
+
return [O(e, { message: h, loc: { start: { line: d, column: $ } } })];
|
|
34
|
+
}
|
|
35
|
+
return [{ message: u.message }];
|
|
36
|
+
}
|
|
37
|
+
const { styles: c, template: a, slotted: r } = n, i = c.some((l) => l.scoped);
|
|
38
|
+
if (a) {
|
|
39
|
+
const l = w({
|
|
40
|
+
source: a.content,
|
|
41
|
+
filename: m,
|
|
42
|
+
id: s,
|
|
43
|
+
scoped: i,
|
|
44
|
+
slotted: r,
|
|
45
|
+
compilerOptions: { bindingMetadata: o }
|
|
46
|
+
});
|
|
47
|
+
if (l.errors.length)
|
|
48
|
+
return l.errors.map(N).map((u) => O(e, u));
|
|
49
|
+
}
|
|
50
|
+
return c.map(({ content: l }) => V({ source: l, filename: m, id: s, scoped: i })).filter(({ errors: l }) => l.length).map(({ errors: l }) => l).flat();
|
|
51
|
+
}, N = (m) => typeof m == "string" ? { message: m } : m, O = (m, e) => {
|
|
52
|
+
let { loc: t, message: n } = e;
|
|
53
|
+
if (t != null && t.start) {
|
|
54
|
+
const { line: s, column: o } = t.start, a = m.split(/\r?\n/)[s - 1];
|
|
55
|
+
if (typeof a != "string")
|
|
56
|
+
return { message: n };
|
|
57
|
+
const r = 50, i = Math.max(0, o - r), p = a.slice(i, o + r);
|
|
58
|
+
n = `${n}
|
|
59
|
+
${B(p, o - i)}`;
|
|
60
|
+
}
|
|
61
|
+
return { message: n };
|
|
62
|
+
}, W = {
|
|
63
|
+
semi: !1,
|
|
64
|
+
singleQuote: !0,
|
|
65
|
+
printWidth: 120,
|
|
66
|
+
trailingComma: "none",
|
|
67
|
+
endOfLine: "auto",
|
|
68
|
+
tabWidth: 2,
|
|
69
|
+
parser: "vue",
|
|
70
|
+
htmlWhitespaceSensitivity: "ignore"
|
|
71
|
+
};
|
|
72
|
+
class k {
|
|
73
|
+
constructor(e = {}) {
|
|
74
|
+
this.generatorOptions = e, this.prettierOpts = {
|
|
75
|
+
...W,
|
|
76
|
+
...e.prettierOpts ?? {}
|
|
77
|
+
}, this.enableCompileValidation = e.enableCompileValidation !== !1;
|
|
78
|
+
}
|
|
79
|
+
replaceThis(e, t = !1) {
|
|
80
|
+
const n = t ? "$1" : "$1.value";
|
|
81
|
+
return e.replace(/this\.refs\.(\w+)/g, n).replace(/this\.(props\.)?/g, "");
|
|
82
|
+
}
|
|
83
|
+
buildScriptSetupStateAccessors(e) {
|
|
84
|
+
return e.description.stateAccessors.map(({ name: t, getterExpr: n, setterExpr: s }) => s ? `const ${t} = computed({ get: ${n}, set: ${s} })` : `const ${t} = computed(${n})`).join(`
|
|
85
|
+
|
|
86
|
+
`);
|
|
87
|
+
}
|
|
88
|
+
buildScriptSetupImports(e) {
|
|
89
|
+
const { componentSet: t } = e.description, n = e.schema.refs, s = !!n && typeof n == "object" && Object.keys(n).length > 0, c = [`import { ${[
|
|
90
|
+
"reactive",
|
|
91
|
+
...e.description.needsComputed ? ["computed"] : [],
|
|
92
|
+
...s ? ["ref"] : []
|
|
93
|
+
].join(", ")} } from "vue"`], a = [...t], r = e.componentsMap.filter((p) => a.includes(p.componentName)), i = {};
|
|
94
|
+
return r.forEach((p) => {
|
|
95
|
+
const { package: f } = p;
|
|
96
|
+
i[f] || (i[f] = []), i[f].push(p);
|
|
97
|
+
}), Object.entries(i).forEach(([p, f]) => {
|
|
98
|
+
const l = f.map((u) => {
|
|
99
|
+
const { componentName: S, exportName: h } = u;
|
|
100
|
+
return h && h !== S ? `${h} as ${S}` : `${S}`;
|
|
101
|
+
});
|
|
102
|
+
c.push(`import { ${l.join(",")} } from '${p}'`);
|
|
103
|
+
}), c.join(`
|
|
104
|
+
`);
|
|
105
|
+
}
|
|
106
|
+
buildScriptSetupRefs(e) {
|
|
107
|
+
const t = e.schema.refs;
|
|
108
|
+
if (!t || typeof t != "object")
|
|
109
|
+
return "";
|
|
110
|
+
const n = Object.entries(t);
|
|
111
|
+
return n.length ? n.map(([s, o]) => {
|
|
112
|
+
const c = o === void 0 ? "null" : j(JSON.stringify(o));
|
|
113
|
+
return `const ${s} = ref(${c})`;
|
|
114
|
+
}).join(`
|
|
115
|
+
`) : "";
|
|
116
|
+
}
|
|
117
|
+
buildScriptSetupDefineProps(e) {
|
|
118
|
+
const { schema: t } = e.schema;
|
|
119
|
+
if (!t)
|
|
120
|
+
return "";
|
|
121
|
+
const { properties: n = [] } = t, s = [];
|
|
122
|
+
return n.forEach(({ content: o = [] }) => {
|
|
123
|
+
o.forEach(({ property: c, type: a, defaultValue: r }) => {
|
|
124
|
+
const i = _(a);
|
|
125
|
+
let p = r;
|
|
126
|
+
i === "String" ? p = JSON.stringify(r) : ["Array", "Object"].includes(i) ? p = `() => (${JSON.stringify(r)})` : i === "Function" && (p = (r == null ? void 0 : r.value) ?? "undefined"), s.push(`${c}: { type: ${i}, default: ${p} }`);
|
|
127
|
+
});
|
|
128
|
+
}), s.length ? `const props = defineProps({${s.join(`,
|
|
129
|
+
`)}})` : "";
|
|
130
|
+
}
|
|
131
|
+
buildScriptSetupDefineEmits(e) {
|
|
132
|
+
const { schema: t } = e.schema;
|
|
133
|
+
if (!t)
|
|
134
|
+
return "";
|
|
135
|
+
const { events: n = {} } = t, s = Object.keys(n).map(C);
|
|
136
|
+
return s.length ? `const emit = defineEmits(${JSON.stringify(s)})` : "";
|
|
137
|
+
}
|
|
138
|
+
buildScriptSetupIconStatement(e) {
|
|
139
|
+
const { componentNames: t, exportNames: n } = e.description.iconComponents;
|
|
140
|
+
return t.length ? `const [${t.join(",")}] = [${n.map((s) => `${s}()`).join(",")}]` : "";
|
|
141
|
+
}
|
|
142
|
+
buildScriptSetupReactiveState(e) {
|
|
143
|
+
const { state: t = {} } = e.schema;
|
|
144
|
+
return `const state = reactive(${j(JSON.stringify(t, null, 2))})`;
|
|
145
|
+
}
|
|
146
|
+
buildScriptSetupMethods(e) {
|
|
147
|
+
const { methods: t = {} } = e.schema;
|
|
148
|
+
return Object.entries(t).map(([s, o]) => {
|
|
149
|
+
const c = this.getFunctionInfo(o.value);
|
|
150
|
+
if (!c)
|
|
151
|
+
return `const ${s} = ${this.replaceThis(o.value)}`;
|
|
152
|
+
const a = c.type ? `${c.type} ` : "", r = this.replaceThis(c.body);
|
|
153
|
+
return `${a}function ${s}(${c.params.join(", ")}) {${r}}`;
|
|
154
|
+
}).join(`
|
|
155
|
+
|
|
156
|
+
`);
|
|
157
|
+
}
|
|
158
|
+
buildScriptSetupCallAction(e) {
|
|
159
|
+
return e.description.needsCallAction ? 'function callAction(name, params) {\n console.warn(`[GenUI] callAction("${name}") is available at runtime via customActions; implement it for exported code.`, params)\n}' : "";
|
|
160
|
+
}
|
|
161
|
+
buildScriptSetupBody(e, t) {
|
|
162
|
+
const n = [], s = /* @__PURE__ */ new Map();
|
|
163
|
+
for (const o of t)
|
|
164
|
+
s.has(o.group) || (s.set(o.group, []), n.push(o.group)), s.get(o.group).push(o.build(e));
|
|
165
|
+
return n.map((o) => s.get(o).filter(Boolean).join(`
|
|
166
|
+
`)).filter(Boolean).join(`
|
|
167
|
+
|
|
168
|
+
`);
|
|
169
|
+
}
|
|
170
|
+
buildSfcTemplateSection(e) {
|
|
171
|
+
return `<template>
|
|
172
|
+
${e}
|
|
173
|
+
</template>`;
|
|
174
|
+
}
|
|
175
|
+
buildSfcScriptSetupSection(e, t = !1) {
|
|
176
|
+
return `<script setup${t ? ' lang="jsx"' : ""}>
|
|
177
|
+
${e}
|
|
178
|
+
<\/script>`;
|
|
179
|
+
}
|
|
180
|
+
buildSfcStyleSection(e) {
|
|
181
|
+
return `<style scoped>
|
|
182
|
+
${e}
|
|
183
|
+
</style>`;
|
|
184
|
+
}
|
|
185
|
+
getScriptSetupSections() {
|
|
186
|
+
return [
|
|
187
|
+
{
|
|
188
|
+
id: "imports",
|
|
189
|
+
group: "imports",
|
|
190
|
+
build: (e) => this.buildScriptSetupImports(e)
|
|
191
|
+
},
|
|
192
|
+
{
|
|
193
|
+
id: "defineProps",
|
|
194
|
+
group: "macro",
|
|
195
|
+
build: (e) => this.buildScriptSetupDefineProps(e)
|
|
196
|
+
},
|
|
197
|
+
{
|
|
198
|
+
id: "defineEmits",
|
|
199
|
+
group: "macro",
|
|
200
|
+
build: (e) => this.buildScriptSetupDefineEmits(e)
|
|
201
|
+
},
|
|
202
|
+
{
|
|
203
|
+
id: "icons",
|
|
204
|
+
group: "icons",
|
|
205
|
+
build: (e) => this.buildScriptSetupIconStatement(e)
|
|
206
|
+
},
|
|
207
|
+
{
|
|
208
|
+
id: "refs",
|
|
209
|
+
group: "refs",
|
|
210
|
+
build: (e) => this.buildScriptSetupRefs(e)
|
|
211
|
+
},
|
|
212
|
+
{
|
|
213
|
+
id: "reactive",
|
|
214
|
+
group: "state",
|
|
215
|
+
build: (e) => this.buildScriptSetupReactiveState(e)
|
|
216
|
+
},
|
|
217
|
+
{
|
|
218
|
+
id: "stateAccessors",
|
|
219
|
+
group: "state",
|
|
220
|
+
build: (e) => this.buildScriptSetupStateAccessors(e)
|
|
221
|
+
},
|
|
222
|
+
{
|
|
223
|
+
id: "callAction",
|
|
224
|
+
group: "actions",
|
|
225
|
+
build: (e) => this.buildScriptSetupCallAction(e)
|
|
226
|
+
},
|
|
227
|
+
{
|
|
228
|
+
id: "methods",
|
|
229
|
+
group: "methods",
|
|
230
|
+
build: (e) => this.buildScriptSetupMethods(e)
|
|
231
|
+
}
|
|
232
|
+
];
|
|
233
|
+
}
|
|
234
|
+
createCodegenMeta() {
|
|
235
|
+
return {
|
|
236
|
+
componentSet: /* @__PURE__ */ new Set(),
|
|
237
|
+
iconComponents: { componentNames: [], exportNames: [] },
|
|
238
|
+
internalTypes: /* @__PURE__ */ new Set(),
|
|
239
|
+
stateAccessors: [],
|
|
240
|
+
needsJsx: !1,
|
|
241
|
+
needsComputed: !1,
|
|
242
|
+
needsCallAction: !1
|
|
243
|
+
};
|
|
244
|
+
}
|
|
245
|
+
resolveRefAttr(e, t) {
|
|
246
|
+
if (!e)
|
|
247
|
+
return null;
|
|
248
|
+
const n = e.trim(), s = n.match(/^(?:this\.)?refs\.(\w+)$/);
|
|
249
|
+
if (s)
|
|
250
|
+
return t ? `ref={${s[1]}}` : `ref="${s[1]}"`;
|
|
251
|
+
const o = n.match(/^(?:this\.)?refs\.(\w+)(\[[\s\S]+\])$/);
|
|
252
|
+
if (o) {
|
|
253
|
+
const [, c, a] = o, r = !t, i = r ? c : `${c}.value`, p = this.replaceThis(a, r), f = `(instance) => (${i}${p} = instance)`;
|
|
254
|
+
return t ? `ref={${f}}` : `:ref="${A(f)}"`;
|
|
255
|
+
}
|
|
256
|
+
return null;
|
|
257
|
+
}
|
|
258
|
+
resolvePropValueType(e) {
|
|
259
|
+
const t = [y, b, v, T, E];
|
|
260
|
+
if (e && typeof e == "object" && "type" in e) {
|
|
261
|
+
const n = e.type;
|
|
262
|
+
if (typeof n == "string" && t.includes(n))
|
|
263
|
+
return n;
|
|
264
|
+
}
|
|
265
|
+
return "literal";
|
|
266
|
+
}
|
|
267
|
+
buildJSFunctionExpression(e, t = !1) {
|
|
268
|
+
const n = this.getFunctionInfo(e);
|
|
269
|
+
return n ? `${n.type ? `${n.type} ` : ""}(${n.params.join(",")}) => { ${this.replaceThis(n.body, t)} }` : this.replaceThis(e, t);
|
|
270
|
+
}
|
|
271
|
+
hoistPropToState(e, t, n, s, o = !1) {
|
|
272
|
+
const c = this.avoidDuplicateString(Object.keys(s), e);
|
|
273
|
+
s[c] = t, n.push(o ? `${e}={state.${c}}` : `:${e}="state.${c}"`);
|
|
274
|
+
}
|
|
275
|
+
isOnEventKey(e) {
|
|
276
|
+
return /^on([A-Z]\w*)/.test(e);
|
|
277
|
+
}
|
|
278
|
+
handleSlotBinding(e) {
|
|
279
|
+
const { name: t, params: n } = e ?? {};
|
|
280
|
+
let s = `#${t || e}`;
|
|
281
|
+
return Array.isArray(n) ? s = `#${t}="{ ${n.join(",")} }"` : typeof n == "string" && (s = `#${t}="${n}"`), s;
|
|
282
|
+
}
|
|
283
|
+
handleEventBinding(e, t, n = !1) {
|
|
284
|
+
var r, i;
|
|
285
|
+
const s = n ? e : C(e), o = !n, c = (p) => `@${s}="${A(p)}"`;
|
|
286
|
+
if ((t == null ? void 0 : t.type) === b) {
|
|
287
|
+
const p = this.buildJSFunctionExpression(t.value ?? "", o);
|
|
288
|
+
if ((r = t.params) != null && r.length) {
|
|
289
|
+
const f = `(...eventArgs) => (${p})(...eventArgs, ${t.params.join(",")})`;
|
|
290
|
+
return n ? `${s}={${f}}` : c(f);
|
|
291
|
+
}
|
|
292
|
+
return n ? `${s}={${p}}` : c(p);
|
|
293
|
+
}
|
|
294
|
+
if ((t == null ? void 0 : t.type) !== y)
|
|
295
|
+
return "";
|
|
296
|
+
const a = this.replaceThis(t.value ?? "", o);
|
|
297
|
+
if ((i = t.params) != null && i.length) {
|
|
298
|
+
const p = `(...eventArgs) => ${a}(eventArgs, ${t.params.join(",")})`;
|
|
299
|
+
return n ? `${s}={${p}}` : c(p);
|
|
300
|
+
}
|
|
301
|
+
return n ? `${s}={${a}}` : c(a);
|
|
302
|
+
}
|
|
303
|
+
avoidDuplicateString(e, t) {
|
|
304
|
+
let n = t, s = 1;
|
|
305
|
+
for (; e.includes(n); )
|
|
306
|
+
n = `${t}${s}`, s++;
|
|
307
|
+
return n;
|
|
308
|
+
}
|
|
309
|
+
handleLiteralBinding(e, t, n, s, o, c = !1) {
|
|
310
|
+
if (typeof t == "string") {
|
|
311
|
+
n.push(`${e}="${t.replace(/"/g, """)}"`);
|
|
312
|
+
return;
|
|
313
|
+
}
|
|
314
|
+
if (t && typeof t == "object") {
|
|
315
|
+
const a = s.internalTypes, r = new Set(a);
|
|
316
|
+
if (s.internalTypes = r, this.traverseState(t, s), r.has("JSFunction") || r.has("JSResource") || r.has("JSSlot")) {
|
|
317
|
+
s.internalTypes = a, this.hoistPropToState(e, t, n, o, c);
|
|
318
|
+
return;
|
|
319
|
+
}
|
|
320
|
+
s.internalTypes = a;
|
|
321
|
+
const p = j(JSON.stringify(t)).replace(/props\./g, "");
|
|
322
|
+
if (c) {
|
|
323
|
+
n.push(`${e}={${p}}`);
|
|
324
|
+
return;
|
|
325
|
+
}
|
|
326
|
+
const f = p.replace(/'/g, "'");
|
|
327
|
+
n.push(`:${e}='${f}'`);
|
|
328
|
+
return;
|
|
329
|
+
}
|
|
330
|
+
n.push(c ? `${e}={${t}}` : `:${e}="${t}"`);
|
|
331
|
+
}
|
|
332
|
+
handleBinding(e, t, n, s, o = !1) {
|
|
333
|
+
Object.entries(e).forEach(([c, a]) => {
|
|
334
|
+
var f;
|
|
335
|
+
let r = c === "className" ? "class" : c;
|
|
336
|
+
if (r === "slot") {
|
|
337
|
+
t.push(this.handleSlotBinding(a));
|
|
338
|
+
return;
|
|
339
|
+
}
|
|
340
|
+
const i = a, p = this.resolvePropValueType(a);
|
|
341
|
+
if (r === "ref" && p === y) {
|
|
342
|
+
const l = this.resolveRefAttr(i.value, o);
|
|
343
|
+
if (l) {
|
|
344
|
+
t.push(l);
|
|
345
|
+
return;
|
|
346
|
+
}
|
|
347
|
+
}
|
|
348
|
+
if (this.isOnEventKey(r)) {
|
|
349
|
+
const l = this.handleEventBinding(r, i, o);
|
|
350
|
+
l && t.push(l);
|
|
351
|
+
return;
|
|
352
|
+
}
|
|
353
|
+
if (p === "literal") {
|
|
354
|
+
this.handleLiteralBinding(r, a, t, n, s, o);
|
|
355
|
+
return;
|
|
356
|
+
}
|
|
357
|
+
if (p === b || p === E) {
|
|
358
|
+
this.hoistPropToState(r, a, t, s, o);
|
|
359
|
+
return;
|
|
360
|
+
}
|
|
361
|
+
if (p === y) {
|
|
362
|
+
const l = this.replaceThis(i.value ?? "", !o);
|
|
363
|
+
if (i.model) {
|
|
364
|
+
const u = (f = i.model) != null && f.prop ? `:${i.model.prop}` : "";
|
|
365
|
+
t.push(o ? `v-model${u}={${l}}` : `v-model${u}="${l}"`);
|
|
366
|
+
return;
|
|
367
|
+
}
|
|
368
|
+
t.push(o ? `${r}={${l}}` : `:${r}="${l}"`);
|
|
369
|
+
}
|
|
370
|
+
});
|
|
371
|
+
}
|
|
372
|
+
recurseChildren(e, t, n, s) {
|
|
373
|
+
if (Array.isArray(e)) {
|
|
374
|
+
s.push(
|
|
375
|
+
e.map((o) => this.generateTemplate(o, t, n, !1)).join("")
|
|
376
|
+
);
|
|
377
|
+
return;
|
|
378
|
+
}
|
|
379
|
+
s.push(e || "");
|
|
380
|
+
}
|
|
381
|
+
isEmptySlotNode(e, t) {
|
|
382
|
+
return e === "template" && !(t != null && t.length) && !(t != null && t.type);
|
|
383
|
+
}
|
|
384
|
+
generateTemplate(e, t, n, s = !0) {
|
|
385
|
+
const o = [], { componentName: c, loop: a, loopArgs: r = ["item"], condition: i, props: p = {}, children: f } = e;
|
|
386
|
+
if (this.isEmptySlotNode(c, f))
|
|
387
|
+
return "";
|
|
388
|
+
const l = s ? "div" : I(c || "div");
|
|
389
|
+
!s && c && n.componentSet.add(c), o.push(`
|
|
390
|
+
<${l} `);
|
|
391
|
+
const u = [];
|
|
392
|
+
if (a) {
|
|
393
|
+
const h = a.type ? this.replaceThis(a.value ?? "", !0) : JSON.stringify(a).replace(/"/g, """);
|
|
394
|
+
u.push(`v-for="(${r.join(",")}) in ${h}"`);
|
|
395
|
+
}
|
|
396
|
+
if (typeof i == "object" || typeof i == "boolean") {
|
|
397
|
+
const h = typeof i == "object" && i !== null, d = i, $ = h && d.type ? this.replaceThis(d.value ?? "", !0) : i, g = h && d.kind || "if";
|
|
398
|
+
u.push(g === "else" ? "v-else" : `v-${g}="${$}"`);
|
|
399
|
+
}
|
|
400
|
+
return this.handleBinding(p, u, n, t), o.push(u.join(" ")), ["img", "input", "br", "hr", "link"].includes(l) ? o.push(" />") : (o.push(">"), this.recurseChildren(f, t, n, o), o.push(`</${l}>`)), o.join("");
|
|
401
|
+
}
|
|
402
|
+
generateSlotTemplate(e, t, n = {}) {
|
|
403
|
+
const s = [], { componentName: o, component: c, props: a = {}, children: r, condition: i } = e, p = o || c || "div";
|
|
404
|
+
t.componentSet.add(p);
|
|
405
|
+
const f = [];
|
|
406
|
+
if (i) {
|
|
407
|
+
const u = i != null && i.type ? this.replaceThis(i.value) : i;
|
|
408
|
+
s.push(`{ ${u} && `);
|
|
409
|
+
}
|
|
410
|
+
return s.push(`<${p} `), this.handleBinding(a, f, t, n, !0), s.push(f.join(" ")), ["img", "input", "br", "hr", "link"].includes(p) ? s.push(" />") : (s.push(">"), Array.isArray(r) ? s.push(r.map((u) => this.generateSlotTemplate(u, t, n)).join("")) : (r == null ? void 0 : r.type) === "JSExpression" ? s.push(`{ ${this.replaceThis(r.value)} }`) : (r == null ? void 0 : r.type) === "i18n" ? s.push(`{t('${r.key}')}`) : s.push(r || ""), s.push(`</${p}>`)), i && s.push(" }"), s.join("");
|
|
411
|
+
}
|
|
412
|
+
getFunctionInfo(e) {
|
|
413
|
+
const n = /(async)?.*?(\w+) *\(([\s\S]*?)\) *\{([\s\S]*)\}/.exec(e);
|
|
414
|
+
return n ? {
|
|
415
|
+
type: n[1] || "",
|
|
416
|
+
params: n[3].split(",").map((s) => s.trim()).filter(Boolean),
|
|
417
|
+
body: n[4]
|
|
418
|
+
} : null;
|
|
419
|
+
}
|
|
420
|
+
transformStateType(e, t, n, s) {
|
|
421
|
+
var u, S;
|
|
422
|
+
const o = e[t];
|
|
423
|
+
if (o != null && o.accessor) {
|
|
424
|
+
const h = ((u = o.accessor.getter) == null ? void 0 : u.value) ?? "function() {}", d = (S = o.accessor.setter) == null ? void 0 : S.value, $ = this.getFunctionInfo(h), g = d ? this.getFunctionInfo(d) : null;
|
|
425
|
+
n.stateAccessors.push({
|
|
426
|
+
name: t,
|
|
427
|
+
getterExpr: $ ? `() => { ${this.replaceThis($.body)} }` : `() => (${this.replaceThis(h)})()`,
|
|
428
|
+
setterExpr: g ? `(${g.params.join(",")}) => { ${this.replaceThis(g.body)} }` : void 0
|
|
429
|
+
}), n.needsComputed = !0, o.defaultValue !== void 0 ? e[t] = o.defaultValue : delete e[t];
|
|
430
|
+
return;
|
|
431
|
+
}
|
|
432
|
+
const c = [y, b, v, T, E], { type: a } = e[t] || {};
|
|
433
|
+
if (!c.includes(a))
|
|
434
|
+
return;
|
|
435
|
+
n.internalTypes.add(a);
|
|
436
|
+
const { start: r, end: i } = P;
|
|
437
|
+
if (a === y) {
|
|
438
|
+
const { value: h = "", computed: d = !1 } = e[t] || {};
|
|
439
|
+
d && (n.needsComputed = !0), e[t] = d ? `${r}computed(${this.replaceThis(h)})${i}` : `${r}${this.replaceThis(h)}${i}`;
|
|
440
|
+
return;
|
|
441
|
+
}
|
|
442
|
+
if (a === b) {
|
|
443
|
+
const { value: h = "" } = e[t] || {}, d = this.getFunctionInfo(h);
|
|
444
|
+
if (!d) {
|
|
445
|
+
e[t] = `${r}${typeof h == "string" ? this.replaceThis(h) : ""}${i}`;
|
|
446
|
+
return;
|
|
447
|
+
}
|
|
448
|
+
const $ = `${d.type} (${d.params.join(",")}) => { ${this.replaceThis(d.body)} }`;
|
|
449
|
+
e[t] = `${r}${$}${i}`;
|
|
450
|
+
return;
|
|
451
|
+
}
|
|
452
|
+
if (a === v) {
|
|
453
|
+
const { key: h = "" } = e[t] || {};
|
|
454
|
+
e[t] = `${r}t("${h}")${i}`;
|
|
455
|
+
return;
|
|
456
|
+
}
|
|
457
|
+
if (a === T) {
|
|
458
|
+
const { value: h = "" } = e[t] || {};
|
|
459
|
+
e[t] = `${r}${this.replaceThis(h)}${i}`;
|
|
460
|
+
return;
|
|
461
|
+
}
|
|
462
|
+
const { value: p = [], params: f = ["row"] } = e[t] || {};
|
|
463
|
+
n.needsJsx = !0;
|
|
464
|
+
const l = p.map((h) => this.generateSlotTemplate(h, n, s)).join("");
|
|
465
|
+
e[t] = `${r}({ ${f.join(",")} }) => ${l || "null"}${i}`;
|
|
466
|
+
}
|
|
467
|
+
traverseState(e, t, n = e) {
|
|
468
|
+
if (!(typeof e != "object" || e === null)) {
|
|
469
|
+
if (Array.isArray(e)) {
|
|
470
|
+
e.forEach((s) => this.traverseState(s, t, n));
|
|
471
|
+
return;
|
|
472
|
+
}
|
|
473
|
+
Object.keys(e).forEach((s) => {
|
|
474
|
+
Object.prototype.hasOwnProperty.call(e, s) && (this.transformStateType(e, s, t, n), this.traverseState(e[s], t, n));
|
|
475
|
+
});
|
|
476
|
+
}
|
|
477
|
+
}
|
|
478
|
+
buildVueSfcSource({
|
|
479
|
+
schema: e,
|
|
480
|
+
componentsMap: t
|
|
481
|
+
}) {
|
|
482
|
+
const n = this.createCodegenMeta();
|
|
483
|
+
n.needsCallAction = /\bthis\.callAction\b/.test(JSON.stringify(e));
|
|
484
|
+
const s = e.state ?? (e.state = {}), o = this.generateTemplate(e, s, n);
|
|
485
|
+
this.traverseState(s, n);
|
|
486
|
+
const c = { schema: e, componentsMap: t, description: n }, a = this.buildScriptSetupBody(c, this.getScriptSetupSections());
|
|
487
|
+
return [
|
|
488
|
+
this.buildSfcTemplateSection(o),
|
|
489
|
+
this.buildSfcScriptSetupSection(a, n.needsJsx),
|
|
490
|
+
this.buildSfcStyleSection(e.css || "")
|
|
491
|
+
].filter(Boolean).join(`
|
|
492
|
+
|
|
493
|
+
`);
|
|
494
|
+
}
|
|
495
|
+
normalizeIncomingSchema(e) {
|
|
496
|
+
if (e == null)
|
|
497
|
+
return { componentName: "Page", children: [] };
|
|
498
|
+
if (typeof e == "string") {
|
|
499
|
+
const t = e.trim();
|
|
500
|
+
if (!t)
|
|
501
|
+
return { componentName: "Page", children: [] };
|
|
502
|
+
try {
|
|
503
|
+
return JSON.parse(t);
|
|
504
|
+
} catch {
|
|
505
|
+
return { componentName: "Page", children: [] };
|
|
506
|
+
}
|
|
507
|
+
}
|
|
508
|
+
return e;
|
|
509
|
+
}
|
|
510
|
+
async generatePageCode({
|
|
511
|
+
pageInfo: e,
|
|
512
|
+
componentsMap: t,
|
|
513
|
+
formatWithPrettier: n = !1
|
|
514
|
+
}) {
|
|
515
|
+
const { schema: s, name: o = "SchemaCard" } = e, c = JSON.parse(JSON.stringify(this.normalizeIncomingSchema(s))), a = this.buildVueSfcSource({ schema: c, name: o, componentsMap: t }), r = `${o}.vue`, i = this.enableCompileValidation ? z(r, a) : [], u = { ...{
|
|
516
|
+
panelName: r,
|
|
517
|
+
panelValue: a,
|
|
518
|
+
panelType: "vue",
|
|
519
|
+
prettierOpts: { ...this.prettierOpts },
|
|
520
|
+
type: "page"
|
|
521
|
+
}, errors: i };
|
|
522
|
+
return n && (u.panelValue = await this.formatWithPrettier(u.panelValue, u.prettierOpts)), u;
|
|
523
|
+
}
|
|
524
|
+
normalizeComponentsMap(e) {
|
|
525
|
+
const t = (e ?? []).filter(({ componentName: s, package: o }) => s && o), n = /* @__PURE__ */ new Map();
|
|
526
|
+
return t.forEach(
|
|
527
|
+
(s) => !n.has(s.componentName) && n.set(s.componentName, s)
|
|
528
|
+
), [...n.values()];
|
|
529
|
+
}
|
|
530
|
+
async formatWithPrettier(e, t) {
|
|
531
|
+
try {
|
|
532
|
+
const [
|
|
533
|
+
{ format: n },
|
|
534
|
+
{ default: s },
|
|
535
|
+
{ default: o },
|
|
536
|
+
{ default: c },
|
|
537
|
+
{ default: a },
|
|
538
|
+
{ default: r }
|
|
539
|
+
] = await Promise.all([
|
|
540
|
+
import("prettier/standalone"),
|
|
541
|
+
import("prettier/plugins/html"),
|
|
542
|
+
import("prettier/plugins/babel"),
|
|
543
|
+
import("prettier/plugins/estree"),
|
|
544
|
+
import("prettier/plugins/postcss"),
|
|
545
|
+
import("prettier/plugins/typescript")
|
|
546
|
+
]);
|
|
547
|
+
return await n(e, {
|
|
548
|
+
...t,
|
|
549
|
+
plugins: [s, o, c, a, r]
|
|
550
|
+
});
|
|
551
|
+
} catch {
|
|
552
|
+
return e;
|
|
553
|
+
}
|
|
554
|
+
}
|
|
555
|
+
async generate({
|
|
556
|
+
pageInfo: e,
|
|
557
|
+
componentsMap: t = [],
|
|
558
|
+
formatWithPrettier: n = !1
|
|
559
|
+
}) {
|
|
560
|
+
const s = this.normalizeComponentsMap(t);
|
|
561
|
+
return this.generatePageCode({
|
|
562
|
+
pageInfo: e,
|
|
563
|
+
componentsMap: s,
|
|
564
|
+
formatWithPrettier: n
|
|
565
|
+
});
|
|
566
|
+
}
|
|
567
|
+
}
|
|
568
|
+
const K = (m) => new k().generate(m);
|
|
569
|
+
export {
|
|
570
|
+
k as V,
|
|
571
|
+
K as g
|
|
572
|
+
};
|
|
573
|
+
//# sourceMappingURL=vue-code-generator-CwPQ3GDh.js.map
|