@vtj/core 0.1.2 → 0.7.0
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/LICENSE +21 -0
- package/dist/index.cjs +7 -0
- package/dist/index.mjs +1281 -0
- package/package.json +37 -45
- package/types/index.d.ts +4 -0
- package/types/models/base.d.ts +7 -0
- package/types/models/block.d.ts +195 -0
- package/types/models/directive.d.ts +32 -0
- package/types/models/event.d.ts +11 -0
- package/types/models/history.d.ts +42 -0
- package/types/models/index.d.ts +8 -0
- package/types/models/node.d.ts +174 -0
- package/types/models/project.d.ts +168 -0
- package/types/models/prop.d.ts +15 -0
- package/types/protocols/assets/dependencie.d.ts +41 -0
- package/types/protocols/assets/index.d.ts +2 -0
- package/types/protocols/assets/material.d.ts +198 -0
- package/types/protocols/index.d.ts +4 -0
- package/types/protocols/schemas/block.d.ts +106 -0
- package/types/protocols/schemas/dataSource.d.ts +75 -0
- package/types/protocols/schemas/file.d.ts +56 -0
- package/types/protocols/schemas/history.d.ts +31 -0
- package/types/protocols/schemas/index.d.ts +6 -0
- package/types/protocols/schemas/node.d.ts +130 -0
- package/types/protocols/schemas/project.d.ts +48 -0
- package/types/protocols/service.d.ts +19 -0
- package/types/protocols/shared.d.ts +34 -0
- package/types/tools/emitter.d.ts +27 -0
- package/types/tools/index.d.ts +2 -0
- package/types/tools/util.d.ts +6 -0
- package/types/version.d.ts +8 -0
- package/CHANGELOG.md +0 -0
- package/README.md +0 -2
- package/index.cjs.js +0 -60
- package/index.es.js +0 -1219
- package/types.d.ts +0 -275
package/index.es.js
DELETED
|
@@ -1,1219 +0,0 @@
|
|
|
1
|
-
var __defProp = Object.defineProperty;
|
|
2
|
-
var __defProps = Object.defineProperties;
|
|
3
|
-
var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
|
|
4
|
-
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
5
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
-
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
7
|
-
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
8
|
-
var __spreadValues = (a, b) => {
|
|
9
|
-
for (var prop in b || (b = {}))
|
|
10
|
-
if (__hasOwnProp.call(b, prop))
|
|
11
|
-
__defNormalProp(a, prop, b[prop]);
|
|
12
|
-
if (__getOwnPropSymbols)
|
|
13
|
-
for (var prop of __getOwnPropSymbols(b)) {
|
|
14
|
-
if (__propIsEnum.call(b, prop))
|
|
15
|
-
__defNormalProp(a, prop, b[prop]);
|
|
16
|
-
}
|
|
17
|
-
return a;
|
|
18
|
-
};
|
|
19
|
-
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
20
|
-
var __publicField = (obj, key, value) => {
|
|
21
|
-
__defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
22
|
-
return value;
|
|
23
|
-
};
|
|
24
|
-
import { cloneDeep, upperFirst } from "lodash-es";
|
|
25
|
-
import prettier from "prettier";
|
|
26
|
-
import htmlParser from "prettier/parser-html";
|
|
27
|
-
import babelParser from "prettier/parser-babel";
|
|
28
|
-
import cssParser from "prettier/parser-postcss";
|
|
29
|
-
import * as VueCompilerSFC from "vue/compiler-sfc";
|
|
30
|
-
function modelTraverse(model, handler) {
|
|
31
|
-
if (model && model.toSchema) {
|
|
32
|
-
const ret = handler(model, model.parent);
|
|
33
|
-
if (ret === false)
|
|
34
|
-
return;
|
|
35
|
-
Object.values(model.config).forEach((v) => {
|
|
36
|
-
if (Array.isArray(v)) {
|
|
37
|
-
v.forEach((n) => {
|
|
38
|
-
modelTraverse(n, handler);
|
|
39
|
-
});
|
|
40
|
-
} else {
|
|
41
|
-
modelTraverse(v, handler);
|
|
42
|
-
}
|
|
43
|
-
});
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
function schemaTraverse(schema, handler, parent = null) {
|
|
47
|
-
if (schema && schema.__model_id__) {
|
|
48
|
-
const ret = handler(schema, parent);
|
|
49
|
-
if (ret === false)
|
|
50
|
-
return;
|
|
51
|
-
Object.values(schema).forEach((v) => {
|
|
52
|
-
if (Array.isArray(v)) {
|
|
53
|
-
v.forEach((n) => {
|
|
54
|
-
schemaTraverse(n, handler, schema);
|
|
55
|
-
});
|
|
56
|
-
} else {
|
|
57
|
-
schemaTraverse(v, handler, schema);
|
|
58
|
-
}
|
|
59
|
-
});
|
|
60
|
-
}
|
|
61
|
-
}
|
|
62
|
-
const _Base = class {
|
|
63
|
-
constructor(config, defaults) {
|
|
64
|
-
__publicField(this, "id");
|
|
65
|
-
__publicField(this, "config");
|
|
66
|
-
__publicField(this, "disposed", false);
|
|
67
|
-
__publicField(this, "parent", null);
|
|
68
|
-
__publicField(this, "modelName", "Base");
|
|
69
|
-
this.config = __spreadValues(__spreadValues({}, cloneDeep(defaults)), config);
|
|
70
|
-
this.id = (config == null ? void 0 : config.__model_id__) || hashId();
|
|
71
|
-
this.defineExtendMethods();
|
|
72
|
-
_Base.instances[this.id] = this;
|
|
73
|
-
}
|
|
74
|
-
defineExtendMethods() {
|
|
75
|
-
const configure = {
|
|
76
|
-
enumerable: false,
|
|
77
|
-
writable: false,
|
|
78
|
-
configurable: false
|
|
79
|
-
};
|
|
80
|
-
Object.keys(this.config).forEach((key) => {
|
|
81
|
-
if (key.startsWith("__"))
|
|
82
|
-
return;
|
|
83
|
-
let name = upperFirst(key);
|
|
84
|
-
Object.defineProperty(this, `get${name}`, __spreadProps(__spreadValues({}, configure), {
|
|
85
|
-
value: () => this.get(name)
|
|
86
|
-
}));
|
|
87
|
-
Object.defineProperty(this, `set${name}`, __spreadProps(__spreadValues({}, configure), {
|
|
88
|
-
value: (v) => {
|
|
89
|
-
this.set(name, v);
|
|
90
|
-
}
|
|
91
|
-
}));
|
|
92
|
-
const value = this.config[key];
|
|
93
|
-
if (Array.isArray(value)) {
|
|
94
|
-
if (name === "Classes") {
|
|
95
|
-
name = "Class";
|
|
96
|
-
} else {
|
|
97
|
-
name = name.endsWith("s") ? name.substring(0, name.length - 1) : name;
|
|
98
|
-
}
|
|
99
|
-
Object.defineProperty(this, `add${name}`, __spreadProps(__spreadValues({}, configure), {
|
|
100
|
-
value: (v, finder) => this.add(name, v, finder)
|
|
101
|
-
}));
|
|
102
|
-
Object.defineProperty(this, `remove${name}`, __spreadProps(__spreadValues({}, configure), {
|
|
103
|
-
value: (v, finder) => this.remove(name, v, finder)
|
|
104
|
-
}));
|
|
105
|
-
}
|
|
106
|
-
});
|
|
107
|
-
}
|
|
108
|
-
get(key) {
|
|
109
|
-
return this.config[key];
|
|
110
|
-
}
|
|
111
|
-
set(key, value) {
|
|
112
|
-
if (this.disposed)
|
|
113
|
-
return;
|
|
114
|
-
return this.config[key] = value;
|
|
115
|
-
}
|
|
116
|
-
add(key, item, finder) {
|
|
117
|
-
const value = this.get(key);
|
|
118
|
-
if (!Array.isArray(value))
|
|
119
|
-
return;
|
|
120
|
-
if (!finder || finder && !value.find(finder)) {
|
|
121
|
-
item.parent = this;
|
|
122
|
-
value.push(item);
|
|
123
|
-
}
|
|
124
|
-
}
|
|
125
|
-
remove(key, item, finder) {
|
|
126
|
-
const value = this.get(key);
|
|
127
|
-
if (!Array.isArray(value))
|
|
128
|
-
return;
|
|
129
|
-
const index = value.findIndex(finder || ((n) => n === item));
|
|
130
|
-
if (index > -1) {
|
|
131
|
-
value[index].parent = null;
|
|
132
|
-
value.splice(index, 1);
|
|
133
|
-
}
|
|
134
|
-
}
|
|
135
|
-
clear(key) {
|
|
136
|
-
const value = this.config[key];
|
|
137
|
-
if (!Array.isArray(value))
|
|
138
|
-
return;
|
|
139
|
-
this.set(key, []);
|
|
140
|
-
}
|
|
141
|
-
dispose() {
|
|
142
|
-
this.disposed = true;
|
|
143
|
-
this.parent = null;
|
|
144
|
-
this.config = /* @__PURE__ */ Object.create(null);
|
|
145
|
-
delete _Base.instances[this.id];
|
|
146
|
-
}
|
|
147
|
-
toSchema() {
|
|
148
|
-
const { config, id } = this;
|
|
149
|
-
const name = this.modelName;
|
|
150
|
-
const json = {};
|
|
151
|
-
Object.keys(config).forEach((key) => {
|
|
152
|
-
const value = config[key];
|
|
153
|
-
if (Array.isArray(value)) {
|
|
154
|
-
json[key] = value.map((n) => {
|
|
155
|
-
return n && n.toSchema ? n.toSchema() : n;
|
|
156
|
-
});
|
|
157
|
-
} else {
|
|
158
|
-
json[key] = value && value.toSchema ? value.toSchema() : value;
|
|
159
|
-
}
|
|
160
|
-
});
|
|
161
|
-
return __spreadValues({
|
|
162
|
-
__model_id__: id,
|
|
163
|
-
__model_name__: name
|
|
164
|
-
}, json);
|
|
165
|
-
}
|
|
166
|
-
};
|
|
167
|
-
let Base = _Base;
|
|
168
|
-
__publicField(Base, "instances", {});
|
|
169
|
-
var TagOrigin = /* @__PURE__ */ ((TagOrigin2) => {
|
|
170
|
-
TagOrigin2["META"] = "meta";
|
|
171
|
-
TagOrigin2["ElementUI"] = "element-ui";
|
|
172
|
-
TagOrigin2["ElementPlus"] = "element-plus";
|
|
173
|
-
TagOrigin2["UI"] = "ui";
|
|
174
|
-
TagOrigin2["BLOCK"] = "block";
|
|
175
|
-
TagOrigin2["PAGE"] = "page";
|
|
176
|
-
TagOrigin2["CUSTOM"] = "custom";
|
|
177
|
-
return TagOrigin2;
|
|
178
|
-
})(TagOrigin || {});
|
|
179
|
-
const _Tag = class extends Base {
|
|
180
|
-
constructor(config, defaults) {
|
|
181
|
-
super(config, __spreadValues(__spreadValues({}, _Tag.defaults), defaults));
|
|
182
|
-
__publicField(this, "modelName", "Tag");
|
|
183
|
-
const { name } = this.config;
|
|
184
|
-
this.config.name = name ? name : `model_${this.id}`;
|
|
185
|
-
}
|
|
186
|
-
dispose() {
|
|
187
|
-
const props = this.get("props");
|
|
188
|
-
for (let item of props) {
|
|
189
|
-
item.dispose();
|
|
190
|
-
}
|
|
191
|
-
const slots = this.get("slots");
|
|
192
|
-
for (let item of slots) {
|
|
193
|
-
item.dispose();
|
|
194
|
-
}
|
|
195
|
-
const events = this.get("events");
|
|
196
|
-
for (let item of events) {
|
|
197
|
-
item.dispose();
|
|
198
|
-
}
|
|
199
|
-
const directives = this.get("directives");
|
|
200
|
-
for (let item of directives) {
|
|
201
|
-
item.dispose();
|
|
202
|
-
}
|
|
203
|
-
super.dispose();
|
|
204
|
-
}
|
|
205
|
-
append(model, place = "default") {
|
|
206
|
-
const { slots } = this.config;
|
|
207
|
-
const slot = slots.find((n) => n === place || n.config.name === place);
|
|
208
|
-
if (slot) {
|
|
209
|
-
slot.add("children", model);
|
|
210
|
-
} else {
|
|
211
|
-
console.error(`slot: ${place} not exist`);
|
|
212
|
-
}
|
|
213
|
-
}
|
|
214
|
-
unappend(model, place = "default") {
|
|
215
|
-
const { slots } = this.config;
|
|
216
|
-
const slot = slots.find((n) => n === place || n.config.name === place);
|
|
217
|
-
if (slot) {
|
|
218
|
-
slot.remove("children", model);
|
|
219
|
-
} else {
|
|
220
|
-
console.error(`slot: ${place} not exist`);
|
|
221
|
-
}
|
|
222
|
-
}
|
|
223
|
-
};
|
|
224
|
-
let Tag = _Tag;
|
|
225
|
-
__publicField(Tag, "defaults", {
|
|
226
|
-
type: "div",
|
|
227
|
-
props: [],
|
|
228
|
-
events: [],
|
|
229
|
-
directives: [],
|
|
230
|
-
slots: [],
|
|
231
|
-
style: {},
|
|
232
|
-
classes: [],
|
|
233
|
-
text: "",
|
|
234
|
-
origin: "meta",
|
|
235
|
-
file: "",
|
|
236
|
-
visible: true
|
|
237
|
-
});
|
|
238
|
-
var BindingType = /* @__PURE__ */ ((BindingType2) => {
|
|
239
|
-
BindingType2["DEFAULT"] = "default";
|
|
240
|
-
BindingType2["MODEL"] = "model";
|
|
241
|
-
BindingType2["SYNC"] = "sync";
|
|
242
|
-
return BindingType2;
|
|
243
|
-
})(BindingType || {});
|
|
244
|
-
var BindingSource = /* @__PURE__ */ ((BindingSource2) => {
|
|
245
|
-
BindingSource2["DEFAULT"] = "default";
|
|
246
|
-
BindingSource2["SLOT"] = "slot";
|
|
247
|
-
BindingSource2["DATA_SOURCE"] = "data";
|
|
248
|
-
return BindingSource2;
|
|
249
|
-
})(BindingSource || {});
|
|
250
|
-
var PropertyDataType = /* @__PURE__ */ ((PropertyDataType2) => {
|
|
251
|
-
PropertyDataType2["STRING"] = "string";
|
|
252
|
-
PropertyDataType2["NUMBER"] = "number";
|
|
253
|
-
PropertyDataType2["BOOLEAN"] = "boolean";
|
|
254
|
-
PropertyDataType2["OBJECT"] = "object";
|
|
255
|
-
PropertyDataType2["ARRAY"] = "array";
|
|
256
|
-
PropertyDataType2["FUNCTION"] = "function";
|
|
257
|
-
PropertyDataType2["UNDEFINED"] = "undefined";
|
|
258
|
-
return PropertyDataType2;
|
|
259
|
-
})(PropertyDataType || {});
|
|
260
|
-
const _Property = class extends Base {
|
|
261
|
-
constructor(config) {
|
|
262
|
-
const { type, value } = config;
|
|
263
|
-
if (!type) {
|
|
264
|
-
config.type = Array.isArray(value) ? "array" : typeof value;
|
|
265
|
-
}
|
|
266
|
-
super(config, _Property.defaults);
|
|
267
|
-
__publicField(this, "modelName", "Property");
|
|
268
|
-
}
|
|
269
|
-
};
|
|
270
|
-
let Property = _Property;
|
|
271
|
-
__publicField(Property, "defaults", {
|
|
272
|
-
binding: {
|
|
273
|
-
type: "default",
|
|
274
|
-
source: "default",
|
|
275
|
-
name: "",
|
|
276
|
-
code: null
|
|
277
|
-
}
|
|
278
|
-
});
|
|
279
|
-
const _Slot = class extends Base {
|
|
280
|
-
constructor(config) {
|
|
281
|
-
super(config, _Slot.defaults);
|
|
282
|
-
__publicField(this, "modelName", "Slot");
|
|
283
|
-
}
|
|
284
|
-
dispose() {
|
|
285
|
-
const { children } = this.config;
|
|
286
|
-
for (let item of children) {
|
|
287
|
-
item.dispose();
|
|
288
|
-
}
|
|
289
|
-
super.dispose();
|
|
290
|
-
}
|
|
291
|
-
};
|
|
292
|
-
let Slot = _Slot;
|
|
293
|
-
__publicField(Slot, "defaults", {
|
|
294
|
-
name: "default",
|
|
295
|
-
params: [],
|
|
296
|
-
children: []
|
|
297
|
-
});
|
|
298
|
-
var EventModifier = /* @__PURE__ */ ((EventModifier2) => {
|
|
299
|
-
EventModifier2["STOP"] = "stop";
|
|
300
|
-
EventModifier2["PREVENT"] = "prevent";
|
|
301
|
-
EventModifier2["CAPTURE"] = "capture";
|
|
302
|
-
EventModifier2["SELF"] = "self";
|
|
303
|
-
EventModifier2["ONCE"] = "once";
|
|
304
|
-
EventModifier2["PASSIVE"] = "passive";
|
|
305
|
-
return EventModifier2;
|
|
306
|
-
})(EventModifier || {});
|
|
307
|
-
const _Event = class extends Base {
|
|
308
|
-
constructor(config) {
|
|
309
|
-
super(config, _Event.defaults);
|
|
310
|
-
__publicField(this, "modelName", "Event");
|
|
311
|
-
}
|
|
312
|
-
};
|
|
313
|
-
let Event = _Event;
|
|
314
|
-
__publicField(Event, "defaults", {
|
|
315
|
-
type: "",
|
|
316
|
-
handler: "",
|
|
317
|
-
params: [],
|
|
318
|
-
modifiers: "",
|
|
319
|
-
code: null
|
|
320
|
-
});
|
|
321
|
-
const _Directive = class extends Base {
|
|
322
|
-
constructor(config) {
|
|
323
|
-
super(config, _Directive.defaults);
|
|
324
|
-
__publicField(this, "modelName", "Directive");
|
|
325
|
-
}
|
|
326
|
-
};
|
|
327
|
-
let Directive = _Directive;
|
|
328
|
-
__publicField(Directive, "defaults", {
|
|
329
|
-
name: "",
|
|
330
|
-
value: "",
|
|
331
|
-
arg: "",
|
|
332
|
-
modifiers: ""
|
|
333
|
-
});
|
|
334
|
-
const _Page = class extends Tag {
|
|
335
|
-
constructor(config) {
|
|
336
|
-
super(config, _Page.defaults);
|
|
337
|
-
__publicField(this, "modelName", "Page");
|
|
338
|
-
}
|
|
339
|
-
};
|
|
340
|
-
let Page = _Page;
|
|
341
|
-
__publicField(Page, "defaults", __spreadProps(__spreadValues({}, Tag.defaults), {
|
|
342
|
-
imports: "",
|
|
343
|
-
css: "",
|
|
344
|
-
scoped: true,
|
|
345
|
-
dataSources: [],
|
|
346
|
-
mixin: "",
|
|
347
|
-
origin: TagOrigin.PAGE
|
|
348
|
-
}));
|
|
349
|
-
var DataSourceType = /* @__PURE__ */ ((DataSourceType2) => {
|
|
350
|
-
DataSourceType2["JSON"] = "json";
|
|
351
|
-
DataSourceType2["CODE"] = "code";
|
|
352
|
-
DataSourceType2["API"] = "api";
|
|
353
|
-
return DataSourceType2;
|
|
354
|
-
})(DataSourceType || {});
|
|
355
|
-
const _DataSource = class extends Base {
|
|
356
|
-
constructor(config) {
|
|
357
|
-
super(config, _DataSource.defaults);
|
|
358
|
-
__publicField(this, "modelName", "DataSource");
|
|
359
|
-
}
|
|
360
|
-
};
|
|
361
|
-
let DataSource = _DataSource;
|
|
362
|
-
__publicField(DataSource, "defaults", {
|
|
363
|
-
type: "code",
|
|
364
|
-
name: "",
|
|
365
|
-
code: null,
|
|
366
|
-
api: null
|
|
367
|
-
});
|
|
368
|
-
var models = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
|
|
369
|
-
__proto__: null,
|
|
370
|
-
Base,
|
|
371
|
-
TagOrigin,
|
|
372
|
-
Tag,
|
|
373
|
-
BindingType,
|
|
374
|
-
BindingSource,
|
|
375
|
-
PropertyDataType,
|
|
376
|
-
Property,
|
|
377
|
-
Slot,
|
|
378
|
-
EventModifier,
|
|
379
|
-
Event,
|
|
380
|
-
Directive,
|
|
381
|
-
Page,
|
|
382
|
-
DataSourceType,
|
|
383
|
-
DataSource
|
|
384
|
-
}, Symbol.toStringTag, { value: "Module" }));
|
|
385
|
-
function createModel(schema, parent) {
|
|
386
|
-
const modelName = schema.__model_name__;
|
|
387
|
-
const Model = models[modelName];
|
|
388
|
-
if (Model) {
|
|
389
|
-
const model = new Model(schema);
|
|
390
|
-
model.parent = parent;
|
|
391
|
-
return model;
|
|
392
|
-
} else {
|
|
393
|
-
console.error(`__model_name__:${modelName} is not exist`);
|
|
394
|
-
}
|
|
395
|
-
}
|
|
396
|
-
function createModelTree(schema, parent = null) {
|
|
397
|
-
if (schema.__model_name__) {
|
|
398
|
-
const model = createModel(schema, parent);
|
|
399
|
-
Object.entries(model.config).forEach(([key, value]) => {
|
|
400
|
-
if (Array.isArray(value)) {
|
|
401
|
-
const items = value.filter((n) => n && n.__model_name__).map((n) => createModelTree(n, model));
|
|
402
|
-
if (items.length) {
|
|
403
|
-
model.set(key, items);
|
|
404
|
-
}
|
|
405
|
-
} else {
|
|
406
|
-
if (value && value.__model_name__) {
|
|
407
|
-
const item = createModelTree(value, model);
|
|
408
|
-
if (item) {
|
|
409
|
-
model.set(key, item);
|
|
410
|
-
}
|
|
411
|
-
}
|
|
412
|
-
}
|
|
413
|
-
});
|
|
414
|
-
return model;
|
|
415
|
-
}
|
|
416
|
-
}
|
|
417
|
-
function toModel(schema) {
|
|
418
|
-
return createModelTree(schema, null);
|
|
419
|
-
}
|
|
420
|
-
function findModel(filter) {
|
|
421
|
-
const instances = Base.instances;
|
|
422
|
-
return Object.values(instances).filter(filter);
|
|
423
|
-
}
|
|
424
|
-
function craeteOutline(schema) {
|
|
425
|
-
const { type, origin, __model_id__, slots, visible } = schema;
|
|
426
|
-
const item = {
|
|
427
|
-
type,
|
|
428
|
-
origin,
|
|
429
|
-
__model_id__,
|
|
430
|
-
visible,
|
|
431
|
-
children: []
|
|
432
|
-
};
|
|
433
|
-
if (slots.length === 0) {
|
|
434
|
-
return item;
|
|
435
|
-
}
|
|
436
|
-
const isOnlyDefault = slots.length === 1 && slots[0].name === "default";
|
|
437
|
-
item.children = isOnlyDefault ? slots[0].children.map((n) => craeteOutline(n)) : slots.map((n) => {
|
|
438
|
-
return {
|
|
439
|
-
slot: true,
|
|
440
|
-
name: n.name,
|
|
441
|
-
__model_id__: n.__model_id__,
|
|
442
|
-
children: n.children.map((m) => craeteOutline(m))
|
|
443
|
-
};
|
|
444
|
-
});
|
|
445
|
-
return item;
|
|
446
|
-
}
|
|
447
|
-
function toOutline(schema) {
|
|
448
|
-
return craeteOutline(schema);
|
|
449
|
-
}
|
|
450
|
-
function htmlFormat(content) {
|
|
451
|
-
return prettier.format(content, {
|
|
452
|
-
parser: "html",
|
|
453
|
-
bracketSameLine: false,
|
|
454
|
-
plugins: [htmlParser]
|
|
455
|
-
});
|
|
456
|
-
}
|
|
457
|
-
function scriptFormat(content) {
|
|
458
|
-
return prettier.format(content, {
|
|
459
|
-
parser: "babel",
|
|
460
|
-
singleQuote: true,
|
|
461
|
-
semi: true,
|
|
462
|
-
trailingComma: "none",
|
|
463
|
-
bracketSpacing: true,
|
|
464
|
-
bracketSameLine: false,
|
|
465
|
-
plugins: [babelParser]
|
|
466
|
-
});
|
|
467
|
-
}
|
|
468
|
-
function cssFormat(content) {
|
|
469
|
-
return prettier.format(content, {
|
|
470
|
-
parser: "scss",
|
|
471
|
-
bracketSameLine: false,
|
|
472
|
-
plugins: [cssParser]
|
|
473
|
-
});
|
|
474
|
-
}
|
|
475
|
-
function pad(hash, len) {
|
|
476
|
-
while (hash.length < len) {
|
|
477
|
-
hash = "0" + hash;
|
|
478
|
-
}
|
|
479
|
-
return hash;
|
|
480
|
-
}
|
|
481
|
-
function fold(hash, text) {
|
|
482
|
-
var i;
|
|
483
|
-
var chr;
|
|
484
|
-
var len;
|
|
485
|
-
if (text.length === 0) {
|
|
486
|
-
return hash;
|
|
487
|
-
}
|
|
488
|
-
for (i = 0, len = text.length; i < len; i++) {
|
|
489
|
-
chr = text.charCodeAt(i);
|
|
490
|
-
hash = (hash << 5) - hash + chr;
|
|
491
|
-
hash |= 0;
|
|
492
|
-
}
|
|
493
|
-
return hash < 0 ? hash * -2 : hash;
|
|
494
|
-
}
|
|
495
|
-
function foldObject(hash, o, seen) {
|
|
496
|
-
return Object.keys(o).sort().reduce(foldKey, hash);
|
|
497
|
-
function foldKey(hash2, key) {
|
|
498
|
-
return foldValue(hash2, o[key], key, seen);
|
|
499
|
-
}
|
|
500
|
-
}
|
|
501
|
-
function foldValue(input, value, key, seen) {
|
|
502
|
-
var hash = fold(fold(fold(input, key), toString(value)), typeof value);
|
|
503
|
-
if (value === null) {
|
|
504
|
-
return fold(hash, "null");
|
|
505
|
-
}
|
|
506
|
-
if (value === void 0) {
|
|
507
|
-
return fold(hash, "undefined");
|
|
508
|
-
}
|
|
509
|
-
if (typeof value === "object" || typeof value === "function") {
|
|
510
|
-
if (seen.indexOf(value) !== -1) {
|
|
511
|
-
return fold(hash, "[Circular]" + key);
|
|
512
|
-
}
|
|
513
|
-
seen.push(value);
|
|
514
|
-
var objHash = foldObject(hash, value, seen);
|
|
515
|
-
if (!("valueOf" in value) || typeof value.valueOf !== "function") {
|
|
516
|
-
return objHash;
|
|
517
|
-
}
|
|
518
|
-
try {
|
|
519
|
-
return fold(objHash, String(value.valueOf()));
|
|
520
|
-
} catch (err) {
|
|
521
|
-
return fold(objHash, "[valueOf exception]" + (err.stack || err.message));
|
|
522
|
-
}
|
|
523
|
-
}
|
|
524
|
-
return fold(hash, value.toString());
|
|
525
|
-
}
|
|
526
|
-
function toString(o) {
|
|
527
|
-
return Object.prototype.toString.call(o);
|
|
528
|
-
}
|
|
529
|
-
function sum(o) {
|
|
530
|
-
return pad(foldValue(0, o, "", []).toString(16), 8);
|
|
531
|
-
}
|
|
532
|
-
var hashSum = sum;
|
|
533
|
-
function uuid() {
|
|
534
|
-
return "xxxxxxxxxxxx4xxxyxxxxxxxxxxxxxxx".replace(/[xy]/g, function(c) {
|
|
535
|
-
const r = Math.random() * 16 | 0;
|
|
536
|
-
const v = c === "x" ? r : r & 3 | 8;
|
|
537
|
-
return v.toString(16);
|
|
538
|
-
}).toLowerCase();
|
|
539
|
-
}
|
|
540
|
-
function cleanJSON(json) {
|
|
541
|
-
if (!json || typeof json === "string")
|
|
542
|
-
return json;
|
|
543
|
-
const str = JSON.stringify(json);
|
|
544
|
-
return str.replace(/\"/g, "'");
|
|
545
|
-
}
|
|
546
|
-
function hashId() {
|
|
547
|
-
return hashSum(uuid());
|
|
548
|
-
}
|
|
549
|
-
function urlParser(querystring) {
|
|
550
|
-
const params = /* @__PURE__ */ Object.create(null);
|
|
551
|
-
const search = new URLSearchParams(querystring);
|
|
552
|
-
search.forEach((val, key) => {
|
|
553
|
-
params[key] = val;
|
|
554
|
-
});
|
|
555
|
-
return params;
|
|
556
|
-
}
|
|
557
|
-
function getQuery(url = "") {
|
|
558
|
-
const index = url.indexOf("?");
|
|
559
|
-
const query = index <= 0 ? "" : url.substring(index + 1);
|
|
560
|
-
return urlParser(query);
|
|
561
|
-
}
|
|
562
|
-
async function fetchJSON(url) {
|
|
563
|
-
return fetch(url).then((res) => res.json());
|
|
564
|
-
}
|
|
565
|
-
async function fetchCSS(url) {
|
|
566
|
-
return fetch(url).then((res) => res.text());
|
|
567
|
-
}
|
|
568
|
-
const TagModelNames = ["Page", "Tag"];
|
|
569
|
-
function isSimpleSlot(slots) {
|
|
570
|
-
return slots.length === 1 && slots[0].name === "default" && slots[0].params.length === 0;
|
|
571
|
-
}
|
|
572
|
-
function __text(text) {
|
|
573
|
-
return text || "";
|
|
574
|
-
}
|
|
575
|
-
function __slot(slot) {
|
|
576
|
-
if (!slot)
|
|
577
|
-
return "";
|
|
578
|
-
const { name, params, children } = slot;
|
|
579
|
-
const paramString = params.length ? `="{${params.join(",")}}"` : "";
|
|
580
|
-
return `<template v-slot:${name}${paramString}>
|
|
581
|
-
${__Tags(children)}
|
|
582
|
-
</template>`;
|
|
583
|
-
}
|
|
584
|
-
function __slots(slots) {
|
|
585
|
-
if (isSimpleSlot(slots)) {
|
|
586
|
-
return __Tags(slots[0].children);
|
|
587
|
-
}
|
|
588
|
-
return slots.map((n) => __slot(n));
|
|
589
|
-
}
|
|
590
|
-
function __directive(directive) {
|
|
591
|
-
const { name, modifiers } = directive;
|
|
592
|
-
const arg = directive.arg ? `:${directive.arg}` : "";
|
|
593
|
-
const value = directive.value ? `="${directive.value}"` : "";
|
|
594
|
-
return `v-${name}${arg}${modifiers}${value}`;
|
|
595
|
-
}
|
|
596
|
-
function __directives(directives) {
|
|
597
|
-
return directives.map((n) => __directive(n)).join(" ");
|
|
598
|
-
}
|
|
599
|
-
function __model_id(id) {
|
|
600
|
-
return id ? `data-model-id="${id}"` : "";
|
|
601
|
-
}
|
|
602
|
-
function __classes(classes, id, name, style) {
|
|
603
|
-
const hasStyle = style && Object.keys(style).length > 0;
|
|
604
|
-
const cls = hasStyle ? name ? name : `model_${id}` : "";
|
|
605
|
-
const clsArray = cls ? [cls, ...classes] : classes;
|
|
606
|
-
return clsArray.length ? `class="${clsArray.join(" ")}"` : "";
|
|
607
|
-
}
|
|
608
|
-
function __props(props) {
|
|
609
|
-
const defaultBinding = props.filter((n) => n.type !== "function" && n.binding.type === BindingType.DEFAULT && n.binding.source === BindingSource.DEFAULT);
|
|
610
|
-
const simpleProps = defaultBinding.map((n) => {
|
|
611
|
-
const flag = n.type === "string" ? "" : ":";
|
|
612
|
-
return `${flag}${n.name}="${cleanJSON(n.value)}"`;
|
|
613
|
-
});
|
|
614
|
-
const functionBinding = props.filter((n) => n.type === "function" && n.binding.type === BindingType.DEFAULT);
|
|
615
|
-
const functionProps = functionBinding.map((n) => {
|
|
616
|
-
return `:${n.name}="${n.binding.name || n.value}"`;
|
|
617
|
-
});
|
|
618
|
-
const slotsBinding = props.filter((n) => n.binding.source === BindingSource.SLOT && !!n.binding.name);
|
|
619
|
-
const slotProps = slotsBinding.map((n) => {
|
|
620
|
-
return `:${n.name}="${n.binding.name}"`;
|
|
621
|
-
});
|
|
622
|
-
const dataBinding = props.filter((n) => n.binding.source === BindingSource.DATA_SOURCE && !!n.binding.name);
|
|
623
|
-
const dataProps = dataBinding.map((n) => {
|
|
624
|
-
return `:${n.name}="${n.binding.name}"`;
|
|
625
|
-
});
|
|
626
|
-
return [...simpleProps, ...slotProps, ...functionProps, ...dataProps].join(" ");
|
|
627
|
-
}
|
|
628
|
-
function __events$1(events) {
|
|
629
|
-
return events.filter((n) => n.type && n.handler).map((n) => {
|
|
630
|
-
const params = n.params.length ? `(${n.params.join(",")})` : "";
|
|
631
|
-
return `@${n.type}${n.modifiers}="${n.handler}${params}"`;
|
|
632
|
-
}).join(" ");
|
|
633
|
-
}
|
|
634
|
-
function __Tag(schema) {
|
|
635
|
-
if (TagModelNames.includes(schema.__model_name__) && schema.visible) {
|
|
636
|
-
const {
|
|
637
|
-
type,
|
|
638
|
-
text,
|
|
639
|
-
slots,
|
|
640
|
-
directives,
|
|
641
|
-
name,
|
|
642
|
-
classes,
|
|
643
|
-
style,
|
|
644
|
-
props,
|
|
645
|
-
events
|
|
646
|
-
} = schema;
|
|
647
|
-
return `<${type}
|
|
648
|
-
${__model_id(schema.__model_id__)}
|
|
649
|
-
${__directives(directives)}
|
|
650
|
-
${__classes(classes, schema.__model_id__, name, style)}
|
|
651
|
-
${__props(props)}
|
|
652
|
-
${__events$1(events)}
|
|
653
|
-
>
|
|
654
|
-
${__text(text)}
|
|
655
|
-
${__slots(slots)}
|
|
656
|
-
</${type}>`;
|
|
657
|
-
}
|
|
658
|
-
return "";
|
|
659
|
-
}
|
|
660
|
-
function __Tags(list = []) {
|
|
661
|
-
return list.map((n) => __Tag(n)).join("\n");
|
|
662
|
-
}
|
|
663
|
-
function parseTemplate(schema) {
|
|
664
|
-
return __Tag(schema);
|
|
665
|
-
}
|
|
666
|
-
function __dataSources(dataSources) {
|
|
667
|
-
if (!dataSources.length)
|
|
668
|
-
return "{}";
|
|
669
|
-
const json = dataSources.filter((n) => n.type === DataSourceType.JSON).map((n) => `${n.name}: ${n.code}`).join(",");
|
|
670
|
-
const others = dataSources.filter((n) => n.type !== DataSourceType.JSON).map((item) => {
|
|
671
|
-
if (DataSourceType.CODE === item.type) {
|
|
672
|
-
return `${item.name}: ${item.code}`;
|
|
673
|
-
}
|
|
674
|
-
if (DataSourceType.API === item.type) {
|
|
675
|
-
return `${item.name}: createApi({
|
|
676
|
-
url:'${item.api.url}',
|
|
677
|
-
method:'${item.api.method}'
|
|
678
|
-
})`;
|
|
679
|
-
}
|
|
680
|
-
return "";
|
|
681
|
-
}).join(",");
|
|
682
|
-
return `{
|
|
683
|
-
data() {
|
|
684
|
-
return {
|
|
685
|
-
${json}
|
|
686
|
-
}
|
|
687
|
-
},
|
|
688
|
-
methods: {
|
|
689
|
-
${others}
|
|
690
|
-
}
|
|
691
|
-
}`;
|
|
692
|
-
}
|
|
693
|
-
function __events(schema) {
|
|
694
|
-
const events = [];
|
|
695
|
-
schemaTraverse(schema, (model) => {
|
|
696
|
-
if (model.__model_name__ === "Event") {
|
|
697
|
-
events.push(model);
|
|
698
|
-
}
|
|
699
|
-
});
|
|
700
|
-
return events.filter((n) => n.code && n.handler).map((n) => {
|
|
701
|
-
return `${n.handler}${n.code}`;
|
|
702
|
-
}).join(",");
|
|
703
|
-
}
|
|
704
|
-
function __elementImports(schema) {
|
|
705
|
-
const origins = {};
|
|
706
|
-
schemaTraverse(schema, (item, parent) => {
|
|
707
|
-
if ([TagOrigin.ElementPlus, TagOrigin.ElementUI].includes(item.origin) && item.visible) {
|
|
708
|
-
const items = origins[item.origin];
|
|
709
|
-
if (!items) {
|
|
710
|
-
origins[item.origin] = /* @__PURE__ */ new Set([item.type]);
|
|
711
|
-
} else {
|
|
712
|
-
items.add(item.type);
|
|
713
|
-
}
|
|
714
|
-
}
|
|
715
|
-
});
|
|
716
|
-
let imports = "";
|
|
717
|
-
let components = [];
|
|
718
|
-
Object.keys(origins).forEach((key) => {
|
|
719
|
-
const values = Array.from(origins[key]);
|
|
720
|
-
imports += `import {${values.join(",")}} from '${key}';`;
|
|
721
|
-
components = components.concat(values);
|
|
722
|
-
});
|
|
723
|
-
return {
|
|
724
|
-
imports,
|
|
725
|
-
components
|
|
726
|
-
};
|
|
727
|
-
}
|
|
728
|
-
function parseScript(schema) {
|
|
729
|
-
const { imports, components } = __elementImports(schema);
|
|
730
|
-
return `
|
|
731
|
-
${imports}
|
|
732
|
-
${schema.imports || ""}
|
|
733
|
-
const __mixin = ${schema.mixin || "{}"}
|
|
734
|
-
const __dataSources = ${__dataSources(schema.dataSources)}
|
|
735
|
-
export default {
|
|
736
|
-
components: {${components.join(",")}},
|
|
737
|
-
mixins:[__dataSources, __mixin],
|
|
738
|
-
data() {
|
|
739
|
-
return {}
|
|
740
|
-
},
|
|
741
|
-
methods: {
|
|
742
|
-
${__events(schema)}
|
|
743
|
-
}
|
|
744
|
-
}
|
|
745
|
-
`;
|
|
746
|
-
}
|
|
747
|
-
function paserStyle(schema) {
|
|
748
|
-
const styles = {};
|
|
749
|
-
schemaTraverse(schema, (item, parent) => {
|
|
750
|
-
if (item.style && Object.keys(item.style).length > 0) {
|
|
751
|
-
const selector = item.name || `model_${item.id}`;
|
|
752
|
-
styles[`.${selector}`] = item.style;
|
|
753
|
-
}
|
|
754
|
-
});
|
|
755
|
-
let content = "";
|
|
756
|
-
Object.keys(styles).forEach((key) => {
|
|
757
|
-
const style = styles[key] || {};
|
|
758
|
-
content += `
|
|
759
|
-
${key} {`;
|
|
760
|
-
Object.entries(style).forEach(([k, v]) => {
|
|
761
|
-
content += `${k}: ${v};`;
|
|
762
|
-
});
|
|
763
|
-
content += "}\n";
|
|
764
|
-
});
|
|
765
|
-
return content;
|
|
766
|
-
}
|
|
767
|
-
function scoped(scoped2) {
|
|
768
|
-
return scoped2 ? "scoped" : "";
|
|
769
|
-
}
|
|
770
|
-
var DSLType = /* @__PURE__ */ ((DSLType2) => {
|
|
771
|
-
DSLType2["VUE2"] = "VUE2";
|
|
772
|
-
DSLType2["VUE3"] = "VUE3";
|
|
773
|
-
DSLType2["VUE3_TS"] = "VUE3_TS";
|
|
774
|
-
DSLType2["UNI_APP"] = "UNI_APP";
|
|
775
|
-
return DSLType2;
|
|
776
|
-
})(DSLType || {});
|
|
777
|
-
function toDSL(dsl = "VUE3", schema) {
|
|
778
|
-
const template = parseTemplate(schema);
|
|
779
|
-
const script = parseScript(schema);
|
|
780
|
-
const style = paserStyle(schema);
|
|
781
|
-
return htmlFormat(`
|
|
782
|
-
<template>
|
|
783
|
-
${htmlFormat(template)}
|
|
784
|
-
</template>
|
|
785
|
-
|
|
786
|
-
<script>
|
|
787
|
-
${scriptFormat(script)}
|
|
788
|
-
<\/script>
|
|
789
|
-
|
|
790
|
-
<style lang="css" ${scoped(schema.scoped)}>
|
|
791
|
-
${cssFormat(schema == null ? void 0 : schema.css)}
|
|
792
|
-
${cssFormat(style)}
|
|
793
|
-
</style>
|
|
794
|
-
`);
|
|
795
|
-
}
|
|
796
|
-
async function loadSystemJs() {
|
|
797
|
-
return await import("systemjs").then(async (_) => {
|
|
798
|
-
return window.System;
|
|
799
|
-
});
|
|
800
|
-
}
|
|
801
|
-
async function loadSystemJsBabel() {
|
|
802
|
-
return await import("systemjs-babel");
|
|
803
|
-
}
|
|
804
|
-
const backslashRegEx = /\\/g;
|
|
805
|
-
function resolveIfNotPlainOrUrl(relUrl, parentUrl) {
|
|
806
|
-
if (relUrl.indexOf("\\") !== -1)
|
|
807
|
-
relUrl = relUrl.replace(backslashRegEx, "/");
|
|
808
|
-
if (relUrl[0] === "/" && relUrl[1] === "/") {
|
|
809
|
-
return parentUrl.slice(0, parentUrl.indexOf(":") + 1) + relUrl;
|
|
810
|
-
} else if (relUrl[0] === "." && (relUrl[1] === "/" || relUrl[1] === "." && (relUrl[2] === "/" || relUrl.length === 2 && (relUrl += "/")) || relUrl.length === 1 && (relUrl += "/")) || relUrl[0] === "/") {
|
|
811
|
-
const parentProtocol = parentUrl.slice(0, parentUrl.indexOf(":") + 1);
|
|
812
|
-
let pathname;
|
|
813
|
-
if (parentUrl[parentProtocol.length + 1] === "/") {
|
|
814
|
-
if (parentProtocol !== "file:") {
|
|
815
|
-
pathname = parentUrl.slice(parentProtocol.length + 2);
|
|
816
|
-
pathname = pathname.slice(pathname.indexOf("/") + 1);
|
|
817
|
-
} else {
|
|
818
|
-
pathname = parentUrl.slice(8);
|
|
819
|
-
}
|
|
820
|
-
} else {
|
|
821
|
-
pathname = parentUrl.slice(parentProtocol.length + (parentUrl[parentProtocol.length] === "/"));
|
|
822
|
-
}
|
|
823
|
-
if (relUrl[0] === "/")
|
|
824
|
-
return parentUrl.slice(0, parentUrl.length - pathname.length - 1) + relUrl;
|
|
825
|
-
const segmented = pathname.slice(0, pathname.lastIndexOf("/") + 1) + relUrl;
|
|
826
|
-
const output = [];
|
|
827
|
-
let segmentIndex = -1;
|
|
828
|
-
for (let i = 0; i < segmented.length; i++) {
|
|
829
|
-
if (segmentIndex !== -1) {
|
|
830
|
-
if (segmented[i] === "/") {
|
|
831
|
-
output.push(segmented.slice(segmentIndex, i + 1));
|
|
832
|
-
segmentIndex = -1;
|
|
833
|
-
}
|
|
834
|
-
} else if (segmented[i] === ".") {
|
|
835
|
-
if (segmented[i + 1] === "." && (segmented[i + 2] === "/" || i + 2 === segmented.length)) {
|
|
836
|
-
output.pop();
|
|
837
|
-
i += 2;
|
|
838
|
-
} else if (segmented[i + 1] === "/" || i + 1 === segmented.length) {
|
|
839
|
-
i += 1;
|
|
840
|
-
} else {
|
|
841
|
-
segmentIndex = i;
|
|
842
|
-
}
|
|
843
|
-
} else {
|
|
844
|
-
segmentIndex = i;
|
|
845
|
-
}
|
|
846
|
-
}
|
|
847
|
-
if (segmentIndex !== -1)
|
|
848
|
-
output.push(segmented.slice(segmentIndex));
|
|
849
|
-
return parentUrl.slice(0, parentUrl.length - pathname.length) + output.join("");
|
|
850
|
-
}
|
|
851
|
-
}
|
|
852
|
-
function resolveUrl(relUrl, parentUrl) {
|
|
853
|
-
return resolveIfNotPlainOrUrl(relUrl, parentUrl) || (relUrl.indexOf(":") !== -1 ? relUrl : resolveIfNotPlainOrUrl("./" + relUrl, parentUrl));
|
|
854
|
-
}
|
|
855
|
-
function compiler(filename, source) {
|
|
856
|
-
var _a;
|
|
857
|
-
const id = hashSum(filename + source);
|
|
858
|
-
const dataVId = "data-v-" + id;
|
|
859
|
-
const parseResult = VueCompilerSFC.parse(source, { sourceMap: false });
|
|
860
|
-
const descriptor = parseResult.descriptor;
|
|
861
|
-
const hasScoped = descriptor.styles.some((s) => s.scoped);
|
|
862
|
-
const template = VueCompilerSFC.compileTemplate({
|
|
863
|
-
id,
|
|
864
|
-
filename,
|
|
865
|
-
source: ((_a = descriptor.template) == null ? void 0 : _a.content) || "",
|
|
866
|
-
scoped: hasScoped,
|
|
867
|
-
compilerOptions: {
|
|
868
|
-
scopeId: hasScoped ? dataVId : void 0
|
|
869
|
-
}
|
|
870
|
-
});
|
|
871
|
-
const script = VueCompilerSFC.compileScript(descriptor, {
|
|
872
|
-
id,
|
|
873
|
-
templateOptions: {
|
|
874
|
-
scoped: hasScoped,
|
|
875
|
-
compilerOptions: {
|
|
876
|
-
scopeId: hasScoped ? dataVId : void 0
|
|
877
|
-
}
|
|
878
|
-
}
|
|
879
|
-
});
|
|
880
|
-
const styles = descriptor.styles;
|
|
881
|
-
const styleCodes = [];
|
|
882
|
-
if (styles.length) {
|
|
883
|
-
for (let i = 0; i < styles.length; i++) {
|
|
884
|
-
const styleItem = styles[i];
|
|
885
|
-
styleCodes.push(VueCompilerSFC.compileStyle({
|
|
886
|
-
source: styleItem.content,
|
|
887
|
-
id: dataVId,
|
|
888
|
-
filename,
|
|
889
|
-
scoped: styleItem.scoped
|
|
890
|
-
}).code);
|
|
891
|
-
}
|
|
892
|
-
}
|
|
893
|
-
let styleCode = styleCodes.join("\n");
|
|
894
|
-
const styleUrl = filename + ".css";
|
|
895
|
-
styleCode = styleCode.replace(/url\(\s*(?:(["'])((?:\\.|[^\n\\"'])+)\1|((?:\\.|[^\s,"'()\\])+))\s*\)/g, function(match, quotes, relUrl1, relUrl2) {
|
|
896
|
-
return "url(" + quotes + resolveUrl(relUrl1 || relUrl2, styleUrl) + quotes + ")";
|
|
897
|
-
});
|
|
898
|
-
const renderName = "_sfc_render";
|
|
899
|
-
const mainName = "_sfc_main";
|
|
900
|
-
const templateCode = template.code.replace(/\nexport (function|const) (render|ssrRender)/, "\n$1 _sfc_$2");
|
|
901
|
-
const scriptCode = VueCompilerSFC.rewriteDefault(script.content, mainName);
|
|
902
|
-
const output = [
|
|
903
|
-
scriptCode,
|
|
904
|
-
templateCode,
|
|
905
|
-
mainName + ".render=" + renderName,
|
|
906
|
-
"export default " + mainName
|
|
907
|
-
];
|
|
908
|
-
if (hasScoped) {
|
|
909
|
-
output.push(mainName + ".__scopeId = " + JSON.stringify(dataVId));
|
|
910
|
-
}
|
|
911
|
-
output.push(mainName + ".__file = " + JSON.stringify(filename));
|
|
912
|
-
const code = output.join("\n");
|
|
913
|
-
return {
|
|
914
|
-
style: styleCode,
|
|
915
|
-
script: code
|
|
916
|
-
};
|
|
917
|
-
}
|
|
918
|
-
class Helper {
|
|
919
|
-
constructor(schema, contentWindow) {
|
|
920
|
-
__publicField(this, "model");
|
|
921
|
-
this.schema = schema;
|
|
922
|
-
this.contentWindow = contentWindow;
|
|
923
|
-
this.model = toModel(schema);
|
|
924
|
-
}
|
|
925
|
-
getSchema() {
|
|
926
|
-
return this.model.toSchema();
|
|
927
|
-
}
|
|
928
|
-
getModel(id) {
|
|
929
|
-
return Base.instances[id];
|
|
930
|
-
}
|
|
931
|
-
getOutline() {
|
|
932
|
-
const schema = this.getSchema();
|
|
933
|
-
return [toOutline(schema)];
|
|
934
|
-
}
|
|
935
|
-
getHoverModel(path = []) {
|
|
936
|
-
var _a, _b;
|
|
937
|
-
const item = path.find((n) => {
|
|
938
|
-
var _a2;
|
|
939
|
-
return (_a2 = n.dataset) == null ? void 0 : _a2.modelId;
|
|
940
|
-
});
|
|
941
|
-
if (!item)
|
|
942
|
-
return null;
|
|
943
|
-
const id = (_a = item.dataset) == null ? void 0 : _a.modelId;
|
|
944
|
-
const model = this.getModel(id);
|
|
945
|
-
const siblings = ((_b = model.parent) == null ? void 0 : _b.get("children")) || [];
|
|
946
|
-
const { width, height, left, top } = item.getBoundingClientRect();
|
|
947
|
-
const removeable = model.modelName !== "Page";
|
|
948
|
-
return {
|
|
949
|
-
el: item,
|
|
950
|
-
id,
|
|
951
|
-
model,
|
|
952
|
-
props: {
|
|
953
|
-
id,
|
|
954
|
-
width,
|
|
955
|
-
height,
|
|
956
|
-
left,
|
|
957
|
-
top,
|
|
958
|
-
opacity: 1,
|
|
959
|
-
type: model.get("type"),
|
|
960
|
-
removeable,
|
|
961
|
-
first: !removeable || removeable && siblings[0] === model,
|
|
962
|
-
last: !removeable || removeable && siblings[siblings.length - 1] === model,
|
|
963
|
-
label: true
|
|
964
|
-
}
|
|
965
|
-
};
|
|
966
|
-
}
|
|
967
|
-
getSelectedById(id) {
|
|
968
|
-
const { contentWindow } = this;
|
|
969
|
-
if (!contentWindow)
|
|
970
|
-
return;
|
|
971
|
-
const el = contentWindow.document.querySelector(`[data-model-id="${id}"]`);
|
|
972
|
-
if (!el)
|
|
973
|
-
return;
|
|
974
|
-
return this.getHoverModel([el]);
|
|
975
|
-
}
|
|
976
|
-
getSelectedModel(path = []) {
|
|
977
|
-
return this.getHoverModel(path);
|
|
978
|
-
}
|
|
979
|
-
getDropModel(path = []) {
|
|
980
|
-
return this.getHoverModel(path);
|
|
981
|
-
}
|
|
982
|
-
async appendModel(defineConfig = {}, target, slotName = "default") {
|
|
983
|
-
const { path, origin } = defineConfig;
|
|
984
|
-
const json = await fetchJSON(path);
|
|
985
|
-
const props = (json.props || []).map((n) => {
|
|
986
|
-
return new Property({
|
|
987
|
-
name: n.name,
|
|
988
|
-
type: n.type,
|
|
989
|
-
value: n.value
|
|
990
|
-
});
|
|
991
|
-
});
|
|
992
|
-
const slots = (json.slots || []).map((n) => {
|
|
993
|
-
return new Slot(__spreadValues({}, n));
|
|
994
|
-
});
|
|
995
|
-
const tag = new Tag({
|
|
996
|
-
type: json.tag,
|
|
997
|
-
props,
|
|
998
|
-
slots,
|
|
999
|
-
origin,
|
|
1000
|
-
text: json.text || "",
|
|
1001
|
-
style: json.style || {},
|
|
1002
|
-
file: path
|
|
1003
|
-
});
|
|
1004
|
-
target.append(tag, slotName);
|
|
1005
|
-
}
|
|
1006
|
-
removeModel(model) {
|
|
1007
|
-
const slot = model.parent;
|
|
1008
|
-
if (slot) {
|
|
1009
|
-
slot.remove("children", model);
|
|
1010
|
-
model.dispose();
|
|
1011
|
-
}
|
|
1012
|
-
}
|
|
1013
|
-
moveNext(model) {
|
|
1014
|
-
const slot = model.parent;
|
|
1015
|
-
if (!slot)
|
|
1016
|
-
return;
|
|
1017
|
-
const children = slot.get("children");
|
|
1018
|
-
const index = children.findIndex((n) => n === model);
|
|
1019
|
-
const next = children[index + 1];
|
|
1020
|
-
if (!next)
|
|
1021
|
-
return;
|
|
1022
|
-
children[index] = next;
|
|
1023
|
-
children[index + 1] = model;
|
|
1024
|
-
}
|
|
1025
|
-
movePrev(model) {
|
|
1026
|
-
const slot = model.parent;
|
|
1027
|
-
if (!slot)
|
|
1028
|
-
return;
|
|
1029
|
-
const children = slot.get("children");
|
|
1030
|
-
const index = children.findIndex((n) => n === model);
|
|
1031
|
-
const prev = children[index - 1];
|
|
1032
|
-
if (!prev)
|
|
1033
|
-
return;
|
|
1034
|
-
children[index] = prev;
|
|
1035
|
-
children[index - 1] = model;
|
|
1036
|
-
}
|
|
1037
|
-
updateProps(id, model = {}) {
|
|
1038
|
-
const instance = this.getModel(id);
|
|
1039
|
-
const props = instance.get("props");
|
|
1040
|
-
props.forEach((prop) => {
|
|
1041
|
-
const name = prop.get("name");
|
|
1042
|
-
const value = model[name];
|
|
1043
|
-
prop.set("value", value);
|
|
1044
|
-
});
|
|
1045
|
-
}
|
|
1046
|
-
setVisible(id, visible) {
|
|
1047
|
-
const instance = this.getModel(id);
|
|
1048
|
-
instance.set("visible", visible);
|
|
1049
|
-
}
|
|
1050
|
-
}
|
|
1051
|
-
const Caches = {};
|
|
1052
|
-
class Engine {
|
|
1053
|
-
constructor(config) {
|
|
1054
|
-
__publicField(this, "config");
|
|
1055
|
-
__publicField(this, "system");
|
|
1056
|
-
__publicField(this, "libs", {});
|
|
1057
|
-
__publicField(this, "scriptEl", null);
|
|
1058
|
-
__publicField(this, "app", null);
|
|
1059
|
-
__publicField(this, "helper", null);
|
|
1060
|
-
this.config = __spreadValues({
|
|
1061
|
-
imports: {},
|
|
1062
|
-
loader: "/engine.js",
|
|
1063
|
-
vue: "/libs/vue3/vue.runtime.esm-browser.prod.js",
|
|
1064
|
-
dslType: DSLType.VUE3
|
|
1065
|
-
}, config);
|
|
1066
|
-
this.init();
|
|
1067
|
-
}
|
|
1068
|
-
async init() {
|
|
1069
|
-
this.setImportMap();
|
|
1070
|
-
await this.initSystem();
|
|
1071
|
-
await this.prepareEnv();
|
|
1072
|
-
const { onReady } = this.config;
|
|
1073
|
-
onReady && onReady(this);
|
|
1074
|
-
}
|
|
1075
|
-
async initSystem() {
|
|
1076
|
-
let system = window == null ? void 0 : window.System;
|
|
1077
|
-
if (system) {
|
|
1078
|
-
this.system = system;
|
|
1079
|
-
return system;
|
|
1080
|
-
}
|
|
1081
|
-
system = await loadSystemJs();
|
|
1082
|
-
const prototype = system.constructor.prototype;
|
|
1083
|
-
prototype.shouldFetch = function(url) {
|
|
1084
|
-
return true;
|
|
1085
|
-
};
|
|
1086
|
-
const fetch2 = prototype.fetch;
|
|
1087
|
-
const { loader } = this.config;
|
|
1088
|
-
prototype.fetch = (url, options) => {
|
|
1089
|
-
if (!url.includes(loader || "")) {
|
|
1090
|
-
return fetch2(url, options);
|
|
1091
|
-
}
|
|
1092
|
-
return this.intercepter(url, options);
|
|
1093
|
-
};
|
|
1094
|
-
this.system = system;
|
|
1095
|
-
return await loadSystemJsBabel();
|
|
1096
|
-
}
|
|
1097
|
-
async intercepter(url, options) {
|
|
1098
|
-
const { type, file, id } = getQuery(url) || {};
|
|
1099
|
-
if (type === "lib") {
|
|
1100
|
-
if (file.endsWith(".css")) {
|
|
1101
|
-
const res = await fetchCSS(decodeURIComponent(file));
|
|
1102
|
-
this.adoptedStyleSheets(file, res);
|
|
1103
|
-
return new Response(null);
|
|
1104
|
-
} else {
|
|
1105
|
-
const script = `
|
|
1106
|
-
export * from '${decodeURIComponent(file)}';
|
|
1107
|
-
`;
|
|
1108
|
-
return Promise.resolve(new Response(new Blob([script], { type: "application/javascript" })));
|
|
1109
|
-
}
|
|
1110
|
-
}
|
|
1111
|
-
if (type === "schema") {
|
|
1112
|
-
const schema = Caches[id];
|
|
1113
|
-
const source = toDSL(DSLType.VUE3, schema);
|
|
1114
|
-
delete Caches[id];
|
|
1115
|
-
const { script, style } = compiler(schema.name, source);
|
|
1116
|
-
this.adoptedStyleSheets(id, style);
|
|
1117
|
-
return Promise.resolve(new Response(new Blob([script], { type: "application/javascript" })));
|
|
1118
|
-
}
|
|
1119
|
-
return fetch(url, options);
|
|
1120
|
-
}
|
|
1121
|
-
async prepareEnv() {
|
|
1122
|
-
const { system, config, libs } = this;
|
|
1123
|
-
const { imports, loader, vue } = config;
|
|
1124
|
-
const coreUrl = `${loader}?type=lib&name=vue&file=${encodeURIComponent(vue)}`;
|
|
1125
|
-
await system.import(coreUrl).then((res) => {
|
|
1126
|
-
libs.Vue = res;
|
|
1127
|
-
system.set("app:vue", res);
|
|
1128
|
-
});
|
|
1129
|
-
system.prepareImport(true);
|
|
1130
|
-
const importItems = Object.entries(imports || {});
|
|
1131
|
-
for (let [name, value] of importItems) {
|
|
1132
|
-
const url = `${loader}?type=lib&name=${name}&file=${encodeURIComponent(value)}`;
|
|
1133
|
-
await system.import(url).then((res) => {
|
|
1134
|
-
libs[name] = res;
|
|
1135
|
-
system.set(`app:${name}`, res);
|
|
1136
|
-
});
|
|
1137
|
-
}
|
|
1138
|
-
system.prepareImport(true);
|
|
1139
|
-
}
|
|
1140
|
-
setImportMap() {
|
|
1141
|
-
const { scriptEl, config } = this;
|
|
1142
|
-
const { imports, vue } = config;
|
|
1143
|
-
let script = scriptEl;
|
|
1144
|
-
if (!script) {
|
|
1145
|
-
this.scriptEl = script = document.createElement("script");
|
|
1146
|
-
script.type = "systemjs-importmap";
|
|
1147
|
-
}
|
|
1148
|
-
const map = {
|
|
1149
|
-
vue: "app:vue"
|
|
1150
|
-
};
|
|
1151
|
-
Object.keys(imports || {}).forEach((name) => {
|
|
1152
|
-
map[name] = `app:${name}`;
|
|
1153
|
-
});
|
|
1154
|
-
script.innerHTML = JSON.stringify({
|
|
1155
|
-
imports: map
|
|
1156
|
-
});
|
|
1157
|
-
document.body.appendChild(script);
|
|
1158
|
-
}
|
|
1159
|
-
adoptedStyleSheets(id, style) {
|
|
1160
|
-
const { contentWindow } = this.config;
|
|
1161
|
-
if (!contentWindow)
|
|
1162
|
-
return;
|
|
1163
|
-
const styleSheet = new contentWindow.CSSStyleSheet();
|
|
1164
|
-
styleSheet.id = id;
|
|
1165
|
-
styleSheet.replaceSync(style);
|
|
1166
|
-
const document2 = contentWindow.document;
|
|
1167
|
-
const sheets = Array.from(document2.adoptedStyleSheets).filter((n) => n.id !== id);
|
|
1168
|
-
document2.adoptedStyleSheets = [...sheets, styleSheet];
|
|
1169
|
-
}
|
|
1170
|
-
async load(schema) {
|
|
1171
|
-
const { config, system } = this;
|
|
1172
|
-
const { loader, dslType, contentWindow, onLoad } = config;
|
|
1173
|
-
const id = schema.__model_id__;
|
|
1174
|
-
Caches[id] = schema;
|
|
1175
|
-
this.helper = new Helper(schema, contentWindow);
|
|
1176
|
-
const url = `${loader}?type=schema&dsl=${dslType}&id=${id}&t=${Date.now()}`;
|
|
1177
|
-
return await system.import(url).then((res) => {
|
|
1178
|
-
const app = this.createApp(res.default);
|
|
1179
|
-
onLoad && onLoad(app);
|
|
1180
|
-
return app;
|
|
1181
|
-
}).catch((e) => {
|
|
1182
|
-
console.warn(e);
|
|
1183
|
-
});
|
|
1184
|
-
}
|
|
1185
|
-
async reload() {
|
|
1186
|
-
var _a;
|
|
1187
|
-
const schema = (_a = this.helper) == null ? void 0 : _a.getSchema();
|
|
1188
|
-
return await this.load(schema);
|
|
1189
|
-
}
|
|
1190
|
-
createApp(component) {
|
|
1191
|
-
var _a;
|
|
1192
|
-
const { dslType, contentWindow } = this.config;
|
|
1193
|
-
if (dslType === DSLType.VUE3) {
|
|
1194
|
-
(_a = this.app) == null ? void 0 : _a.unmount();
|
|
1195
|
-
const app = this.libs.Vue.createApp(component);
|
|
1196
|
-
app.mount(contentWindow.document.body);
|
|
1197
|
-
this.app = app;
|
|
1198
|
-
}
|
|
1199
|
-
return this.app;
|
|
1200
|
-
}
|
|
1201
|
-
dispose() {
|
|
1202
|
-
const { scriptEl, app, config } = this;
|
|
1203
|
-
const { contentWindow, dslType } = config;
|
|
1204
|
-
if (scriptEl && scriptEl.parentNode) {
|
|
1205
|
-
scriptEl.parentNode.removeChild(scriptEl);
|
|
1206
|
-
}
|
|
1207
|
-
if (contentWindow) {
|
|
1208
|
-
const document2 = contentWindow.document;
|
|
1209
|
-
document2.adoptedStyleSheets = [];
|
|
1210
|
-
}
|
|
1211
|
-
if (app) {
|
|
1212
|
-
if (dslType === DSLType.VUE3) {
|
|
1213
|
-
app.unmount();
|
|
1214
|
-
this.app = null;
|
|
1215
|
-
}
|
|
1216
|
-
}
|
|
1217
|
-
}
|
|
1218
|
-
}
|
|
1219
|
-
export { Base, BindingSource, BindingType, DSLType, DataSource, DataSourceType, Directive, Engine, Event, EventModifier, Page, Property, PropertyDataType, Slot, Tag, TagOrigin, cleanJSON, compiler, craeteOutline, createModel, createModelTree, cssFormat, fetchCSS, fetchJSON, findModel, getQuery, hashId, htmlFormat, loadSystemJs, loadSystemJsBabel, modelTraverse, schemaTraverse, scriptFormat, toDSL, toModel, toOutline, urlParser, uuid };
|