@vtj/core 0.1.2 → 0.7.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/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
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
import type { JSExpression, JSFunction, JSONValue } from '../shared';
|
|
2
|
+
/**
|
|
3
|
+
* 低代码组件协议
|
|
4
|
+
*/
|
|
5
|
+
export interface NodeSchema {
|
|
6
|
+
/**
|
|
7
|
+
* 节点标识
|
|
8
|
+
*/
|
|
9
|
+
id?: string;
|
|
10
|
+
/**
|
|
11
|
+
* 节点名称
|
|
12
|
+
*/
|
|
13
|
+
name: string;
|
|
14
|
+
/**
|
|
15
|
+
* 来源
|
|
16
|
+
*/
|
|
17
|
+
from?: NodeFrom;
|
|
18
|
+
/**
|
|
19
|
+
* 锁定
|
|
20
|
+
*/
|
|
21
|
+
locked?: boolean;
|
|
22
|
+
/**
|
|
23
|
+
* 不可见的
|
|
24
|
+
*/
|
|
25
|
+
invisible?: boolean;
|
|
26
|
+
/**
|
|
27
|
+
* 组件属性, 当 name 为 slot 时 props 是 插槽的参数
|
|
28
|
+
*/
|
|
29
|
+
props?: NodeProps;
|
|
30
|
+
/**
|
|
31
|
+
* 绑定事件
|
|
32
|
+
*/
|
|
33
|
+
events?: NodeEvents;
|
|
34
|
+
/**
|
|
35
|
+
* 内置指令
|
|
36
|
+
*/
|
|
37
|
+
directives?: NodeDirective[];
|
|
38
|
+
/**
|
|
39
|
+
* 子组件
|
|
40
|
+
*/
|
|
41
|
+
children?: NodeChildren;
|
|
42
|
+
/**
|
|
43
|
+
* 放置在组件的插槽
|
|
44
|
+
*/
|
|
45
|
+
slot?: string | NodeSlot;
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* 组件来源, 字符串是依赖包名
|
|
49
|
+
*/
|
|
50
|
+
export type NodeFrom = string | NodeFromSchema | NodeFromUrlSchema | NodeFromRemote;
|
|
51
|
+
/**
|
|
52
|
+
* 来源于其他Schema对象
|
|
53
|
+
*/
|
|
54
|
+
export interface NodeFromSchema {
|
|
55
|
+
type: 'Schema';
|
|
56
|
+
/**
|
|
57
|
+
* Block Id
|
|
58
|
+
*/
|
|
59
|
+
id: string;
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* 来源于远程的Schema文件
|
|
63
|
+
*/
|
|
64
|
+
export interface NodeFromUrlSchema {
|
|
65
|
+
type: 'UrlSchema';
|
|
66
|
+
url: string;
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* 来源远程组件
|
|
70
|
+
*/
|
|
71
|
+
export interface NodeFromRemote {
|
|
72
|
+
type: 'Remote';
|
|
73
|
+
urls: string;
|
|
74
|
+
library?: string;
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* 组件属性描述
|
|
78
|
+
*/
|
|
79
|
+
export interface NodeProps {
|
|
80
|
+
key?: string | number | JSExpression;
|
|
81
|
+
ref?: string | JSExpression | JSFunction;
|
|
82
|
+
style?: Record<string, any>;
|
|
83
|
+
class?: string | string[] | JSExpression;
|
|
84
|
+
[index: string]: JSONValue | JSExpression | JSFunction;
|
|
85
|
+
}
|
|
86
|
+
/**
|
|
87
|
+
* 事件描述
|
|
88
|
+
*/
|
|
89
|
+
export interface NodeEvent {
|
|
90
|
+
name: string;
|
|
91
|
+
handler: JSFunction;
|
|
92
|
+
modifiers?: Record<string, boolean>;
|
|
93
|
+
}
|
|
94
|
+
export type NodeEvents = Record<string, NodeEvent>;
|
|
95
|
+
/**
|
|
96
|
+
* 子组件描述
|
|
97
|
+
*/
|
|
98
|
+
export type NodeChildren = string | JSExpression | NodeSchema[];
|
|
99
|
+
/**
|
|
100
|
+
* 插槽描述
|
|
101
|
+
*/
|
|
102
|
+
export interface NodeSlot {
|
|
103
|
+
name: string;
|
|
104
|
+
params?: string[];
|
|
105
|
+
}
|
|
106
|
+
/**
|
|
107
|
+
* 组件指令定义
|
|
108
|
+
*/
|
|
109
|
+
export interface NodeDirective {
|
|
110
|
+
id?: string;
|
|
111
|
+
name: string;
|
|
112
|
+
arg?: string | JSExpression;
|
|
113
|
+
modifiers?: NodeModifiers;
|
|
114
|
+
value?: JSExpression;
|
|
115
|
+
iterator?: {
|
|
116
|
+
item: string;
|
|
117
|
+
index: string;
|
|
118
|
+
};
|
|
119
|
+
}
|
|
120
|
+
/**
|
|
121
|
+
* 循环指令迭代器
|
|
122
|
+
*/
|
|
123
|
+
export interface NodeDirectiveIterator {
|
|
124
|
+
item: string;
|
|
125
|
+
index: string;
|
|
126
|
+
}
|
|
127
|
+
/**
|
|
128
|
+
* 事件/指令修饰符
|
|
129
|
+
*/
|
|
130
|
+
export type NodeModifiers = Record<string, boolean>;
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import type { PageFile, BlockFile } from './file';
|
|
2
|
+
import type { Dependencie } from '../assets';
|
|
3
|
+
import type { ApiSchema } from './dataSource';
|
|
4
|
+
/**
|
|
5
|
+
* 项目描述信息
|
|
6
|
+
*/
|
|
7
|
+
export interface ProjectSchema {
|
|
8
|
+
/**
|
|
9
|
+
* 唯一标识
|
|
10
|
+
*/
|
|
11
|
+
id?: string;
|
|
12
|
+
/**
|
|
13
|
+
* 项目名称,默认取package.json name 字段
|
|
14
|
+
*/
|
|
15
|
+
name: string;
|
|
16
|
+
/**
|
|
17
|
+
* 项目简介
|
|
18
|
+
*/
|
|
19
|
+
description?: string;
|
|
20
|
+
/**
|
|
21
|
+
* 项目页面
|
|
22
|
+
*/
|
|
23
|
+
pages?: PageFile[];
|
|
24
|
+
/**
|
|
25
|
+
* 项目共用区块组件
|
|
26
|
+
*/
|
|
27
|
+
blocks?: BlockFile[];
|
|
28
|
+
/**
|
|
29
|
+
* 首页 pageId
|
|
30
|
+
*/
|
|
31
|
+
homepage?: string;
|
|
32
|
+
/**
|
|
33
|
+
* 项目依赖
|
|
34
|
+
*/
|
|
35
|
+
dependencies?: Dependencie[];
|
|
36
|
+
/**
|
|
37
|
+
* api
|
|
38
|
+
*/
|
|
39
|
+
apis?: ApiSchema[];
|
|
40
|
+
/**
|
|
41
|
+
* 标记
|
|
42
|
+
*/
|
|
43
|
+
__VTJ_PROJECT__?: boolean;
|
|
44
|
+
/**
|
|
45
|
+
* 版本
|
|
46
|
+
*/
|
|
47
|
+
__VERSION__?: string;
|
|
48
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import type { ProjectSchema, BlockSchema, HistorySchema, HistoryItem, PageFile, BlockFile } from './schemas';
|
|
2
|
+
import type { MaterialDescription } from './assets';
|
|
3
|
+
export declare abstract class Service {
|
|
4
|
+
abstract init(project: ProjectSchema): Promise<ProjectSchema>;
|
|
5
|
+
abstract saveProject(project: ProjectSchema): Promise<boolean>;
|
|
6
|
+
abstract saveMaterials(project: ProjectSchema, materials: Map<string, MaterialDescription>): Promise<boolean>;
|
|
7
|
+
abstract saveFile(file: BlockSchema): Promise<boolean>;
|
|
8
|
+
abstract getFile(id: string): Promise<BlockSchema>;
|
|
9
|
+
abstract removeFile(id: string): Promise<boolean>;
|
|
10
|
+
abstract saveHistory(history: HistorySchema): Promise<boolean>;
|
|
11
|
+
abstract removeHistory(id: string): Promise<boolean>;
|
|
12
|
+
abstract getHistory(id: string): Promise<HistorySchema>;
|
|
13
|
+
abstract getHistoryItem(fId: string, id: string): Promise<HistoryItem>;
|
|
14
|
+
abstract saveHistoryItem(fId: string, item: HistoryItem): Promise<boolean>;
|
|
15
|
+
abstract removeHistoryItem(fId: string, ids: string[]): Promise<boolean>;
|
|
16
|
+
abstract publish(project: ProjectSchema): Promise<boolean>;
|
|
17
|
+
abstract publishFile(project: ProjectSchema, file: PageFile | BlockFile): Promise<boolean>;
|
|
18
|
+
abstract getRaw(project: ProjectSchema, dsl: BlockSchema): Promise<string>;
|
|
19
|
+
}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* json属性值
|
|
3
|
+
*/
|
|
4
|
+
export type JSONValue = boolean | string | number | null | undefined | JSONArray | JSONObject;
|
|
5
|
+
/**
|
|
6
|
+
* json 数组
|
|
7
|
+
*/
|
|
8
|
+
export type JSONArray = JSONValue[];
|
|
9
|
+
/**
|
|
10
|
+
* json 对象
|
|
11
|
+
*/
|
|
12
|
+
export interface JSONObject {
|
|
13
|
+
[key: string]: JSONValue;
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* 表达式代码
|
|
17
|
+
*/
|
|
18
|
+
export interface JSExpression {
|
|
19
|
+
type: 'JSExpression';
|
|
20
|
+
id?: string;
|
|
21
|
+
value: string;
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* 函数代码
|
|
25
|
+
*/
|
|
26
|
+
export interface JSFunction {
|
|
27
|
+
type: 'JSFunction';
|
|
28
|
+
id?: string;
|
|
29
|
+
value: string;
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* 数据类型
|
|
33
|
+
*/
|
|
34
|
+
export type DataType = 'String' | 'Boolean' | 'Number' | 'Date' | 'Object' | 'Array' | 'Function';
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { Emitter } from 'mitt';
|
|
2
|
+
import { type ProjectModelEvent, type BlockModel, type NodeModel, type HistoryModelEvent, EVENT_PROJECT_CHANGE, EVENT_PROJECT_ACTIVED, EVENT_PROJECT_DEPS_CHANGE, EVENT_PROJECT_PAGES_CHANGE, EVENT_PROJECT_BLOCKS_CHANGE, EVENT_PROJECT_APIS_CHANGE, EVENT_PROJECT_PUBLISH, EVENT_PROJECT_FILE_PUBLISH, EVENT_BLOCK_CHANGE, EVENT_NODE_CHANGE, EVENT_HISTORY_CHANGE, EVENT_HISTORY_LOAD } from '../models';
|
|
3
|
+
type Events = {
|
|
4
|
+
[EVENT_PROJECT_CHANGE]: ProjectModelEvent;
|
|
5
|
+
[EVENT_PROJECT_ACTIVED]: ProjectModelEvent;
|
|
6
|
+
[EVENT_PROJECT_DEPS_CHANGE]: ProjectModelEvent;
|
|
7
|
+
[EVENT_PROJECT_PAGES_CHANGE]: ProjectModelEvent;
|
|
8
|
+
[EVENT_PROJECT_BLOCKS_CHANGE]: ProjectModelEvent;
|
|
9
|
+
[EVENT_PROJECT_APIS_CHANGE]: ProjectModelEvent;
|
|
10
|
+
[EVENT_PROJECT_PUBLISH]: ProjectModelEvent;
|
|
11
|
+
[EVENT_PROJECT_FILE_PUBLISH]: ProjectModelEvent;
|
|
12
|
+
[EVENT_BLOCK_CHANGE]: BlockModel;
|
|
13
|
+
[EVENT_NODE_CHANGE]: NodeModel;
|
|
14
|
+
[EVENT_HISTORY_CHANGE]: HistoryModelEvent;
|
|
15
|
+
[EVENT_HISTORY_LOAD]: HistoryModelEvent;
|
|
16
|
+
};
|
|
17
|
+
export declare const emitter: Emitter<Events>;
|
|
18
|
+
export type Emitter = {
|
|
19
|
+
on(type: string, listener: (...args: any[]) => void): void;
|
|
20
|
+
off(type: string, listener: (...args: any[]) => void): void;
|
|
21
|
+
emit(type: string, ...args: any[]): void;
|
|
22
|
+
all: {
|
|
23
|
+
clear(): void;
|
|
24
|
+
};
|
|
25
|
+
};
|
|
26
|
+
export type ModelEventType = 'create' | 'update' | 'delete' | 'clone' | 'clear' | 'load' | 'publish';
|
|
27
|
+
export {};
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { BlockModel } from '../models';
|
|
2
|
+
import { type BlockSchema, type NodeSchema } from '../protocols';
|
|
3
|
+
export declare function isBlock(value: unknown): value is BlockModel;
|
|
4
|
+
export declare function isNode(value: unknown): value is BlockModel;
|
|
5
|
+
export declare function isBlockSchema(value: unknown): value is BlockSchema;
|
|
6
|
+
export declare function cloneDsl(dsl: NodeSchema): NodeSchema;
|
package/CHANGELOG.md
DELETED
|
File without changes
|
package/README.md
DELETED
package/index.cjs.js
DELETED
|
@@ -1,60 +0,0 @@
|
|
|
1
|
-
"use strict";var Ne=Object.defineProperty,Ce=Object.defineProperties;var Ie=Object.getOwnPropertyDescriptors;var re=Object.getOwnPropertySymbols;var Me=Object.prototype.hasOwnProperty,Te=Object.prototype.propertyIsEnumerable;var J=(t,e,n)=>e in t?Ne(t,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[e]=n,p=(t,e)=>{for(var n in e||(e={}))Me.call(e,n)&&J(t,n,e[n]);if(re)for(var n of re(e))Te.call(e,n)&&J(t,n,e[n]);return t},b=(t,e)=>Ce(t,Ie(e));var l=(t,e,n)=>(J(t,typeof e!="symbol"?e+"":e,n),n);Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});var oe=require("lodash-es"),Re=require("prettier"),Ve=require("prettier/parser-html"),Be=require("prettier/parser-babel"),Le=require("prettier/parser-postcss"),Fe=require("vue/compiler-sfc");function L(t){return t&&typeof t=="object"&&"default"in t?t:{default:t}}function k(t){if(t&&t.__esModule)return t;var e=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});return t&&Object.keys(t).forEach(function(n){if(n!=="default"){var s=Object.getOwnPropertyDescriptor(t,n);Object.defineProperty(e,n,s.get?s:{enumerable:!0,get:function(){return t[n]}})}}),e.default=t,Object.freeze(e)}var G=L(Re),De=L(Ve),Je=L(Be),qe=L(Le),P=k(Fe);function W(t,e){if(t&&t.toSchema){if(e(t,t.parent)===!1)return;Object.values(t.config).forEach(s=>{Array.isArray(s)?s.forEach(r=>{W(r,e)}):W(s,e)})}}function j(t,e,n=null){if(t&&t.__model_id__){if(e(t,n)===!1)return;Object.values(t).forEach(r=>{Array.isArray(r)?r.forEach(o=>{j(o,e,t)}):j(r,e,t)})}}const B=class{constructor(e,n){l(this,"id");l(this,"config");l(this,"disposed",!1);l(this,"parent",null);l(this,"modelName","Base");this.config=p(p({},oe.cloneDeep(n)),e),this.id=(e==null?void 0:e.__model_id__)||he(),this.defineExtendMethods(),B.instances[this.id]=this}defineExtendMethods(){const e={enumerable:!1,writable:!1,configurable:!1};Object.keys(this.config).forEach(n=>{if(n.startsWith("__"))return;let s=oe.upperFirst(n);Object.defineProperty(this,`get${s}`,b(p({},e),{value:()=>this.get(s)})),Object.defineProperty(this,`set${s}`,b(p({},e),{value:o=>{this.set(s,o)}}));const r=this.config[n];Array.isArray(r)&&(s==="Classes"?s="Class":s=s.endsWith("s")?s.substring(0,s.length-1):s,Object.defineProperty(this,`add${s}`,b(p({},e),{value:(o,i)=>this.add(s,o,i)})),Object.defineProperty(this,`remove${s}`,b(p({},e),{value:(o,i)=>this.remove(s,o,i)})))})}get(e){return this.config[e]}set(e,n){if(!this.disposed)return this.config[e]=n}add(e,n,s){const r=this.get(e);!Array.isArray(r)||(!s||s&&!r.find(s))&&(n.parent=this,r.push(n))}remove(e,n,s){const r=this.get(e);if(!Array.isArray(r))return;const o=r.findIndex(s||(i=>i===n));o>-1&&(r[o].parent=null,r.splice(o,1))}clear(e){const n=this.config[e];!Array.isArray(n)||this.set(e,[])}dispose(){this.disposed=!0,this.parent=null,this.config=Object.create(null),delete B.instances[this.id]}toSchema(){const{config:e,id:n}=this,s=this.modelName,r={};return Object.keys(e).forEach(o=>{const i=e[o];Array.isArray(i)?r[o]=i.map(a=>a&&a.toSchema?a.toSchema():a):r[o]=i&&i.toSchema?i.toSchema():i}),p({__model_id__:n,__model_name__:s},r)}};let f=B;l(f,"instances",{});var A=(t=>(t.META="meta",t.ElementUI="element-ui",t.ElementPlus="element-plus",t.UI="ui",t.BLOCK="block",t.PAGE="page",t.CUSTOM="custom",t))(A||{});const K=class extends f{constructor(n,s){super(n,p(p({},K.defaults),s));l(this,"modelName","Tag");const{name:r}=this.config;this.config.name=r||`model_${this.id}`}dispose(){const n=this.get("props");for(let i of n)i.dispose();const s=this.get("slots");for(let i of s)i.dispose();const r=this.get("events");for(let i of r)i.dispose();const o=this.get("directives");for(let i of o)i.dispose();super.dispose()}append(n,s="default"){const{slots:r}=this.config,o=r.find(i=>i===s||i.config.name===s);o?o.add("children",n):console.error(`slot: ${s} not exist`)}unappend(n,s="default"){const{slots:r}=this.config,o=r.find(i=>i===s||i.config.name===s);o?o.remove("children",n):console.error(`slot: ${s} not exist`)}};let _=K;l(_,"defaults",{type:"div",props:[],events:[],directives:[],slots:[],style:{},classes:[],text:"",origin:"meta",file:"",visible:!0});var T=(t=>(t.DEFAULT="default",t.MODEL="model",t.SYNC="sync",t))(T||{}),x=(t=>(t.DEFAULT="default",t.SLOT="slot",t.DATA_SOURCE="data",t))(x||{}),Q=(t=>(t.STRING="string",t.NUMBER="number",t.BOOLEAN="boolean",t.OBJECT="object",t.ARRAY="array",t.FUNCTION="function",t.UNDEFINED="undefined",t))(Q||{});const Y=class extends f{constructor(n){const{type:s,value:r}=n;s||(n.type=Array.isArray(r)?"array":typeof r);super(n,Y.defaults);l(this,"modelName","Property")}};let O=Y;l(O,"defaults",{binding:{type:"default",source:"default",name:"",code:null}});const X=class extends f{constructor(n){super(n,X.defaults);l(this,"modelName","Slot")}dispose(){const{children:n}=this.config;for(let s of n)s.dispose();super.dispose()}};let E=X;l(E,"defaults",{name:"default",params:[],children:[]});var z=(t=>(t.STOP="stop",t.PREVENT="prevent",t.CAPTURE="capture",t.SELF="self",t.ONCE="once",t.PASSIVE="passive",t))(z||{});const Z=class extends f{constructor(n){super(n,Z.defaults);l(this,"modelName","Event")}};let N=Z;l(N,"defaults",{type:"",handler:"",params:[],modifiers:"",code:null});const ee=class extends f{constructor(n){super(n,ee.defaults);l(this,"modelName","Directive")}};let C=ee;l(C,"defaults",{name:"",value:"",arg:"",modifiers:""});const te=class extends _{constructor(n){super(n,te.defaults);l(this,"modelName","Page")}};let I=te;l(I,"defaults",b(p({},_.defaults),{imports:"",css:"",scoped:!0,dataSources:[],mixin:"",origin:A.PAGE}));var v=(t=>(t.JSON="json",t.CODE="code",t.API="api",t))(v||{});const ne=class extends f{constructor(n){super(n,ne.defaults);l(this,"modelName","DataSource")}};let M=ne;l(M,"defaults",{type:"code",name:"",code:null,api:null});var We=Object.freeze(Object.defineProperty({__proto__:null,Base:f,TagOrigin:A,Tag:_,BindingType:T,BindingSource:x,PropertyDataType:Q,Property:O,Slot:E,EventModifier:z,Event:N,Directive:C,Page:I,DataSourceType:v,DataSource:M},Symbol.toStringTag,{value:"Module"}));function ce(t,e){const n=t.__model_name__,s=We[n];if(s){const r=new s(t);return r.parent=e,r}else console.error(`__model_name__:${n} is not exist`)}function R(t,e=null){if(t.__model_name__){const n=ce(t,e);return Object.entries(n.config).forEach(([s,r])=>{if(Array.isArray(r)){const o=r.filter(i=>i&&i.__model_name__).map(i=>R(i,n));o.length&&n.set(s,o)}else if(r&&r.__model_name__){const o=R(r,n);o&&n.set(s,o)}}),n}}function ae(t){return R(t,null)}function He(t){const e=f.instances;return Object.values(e).filter(t)}function V(t){const{type:e,origin:n,__model_id__:s,slots:r,visible:o}=t,i={type:e,origin:n,__model_id__:s,visible:o,children:[]};if(r.length===0)return i;const a=r.length===1&&r[0].name==="default";return i.children=a?r[0].children.map(u=>V(u)):r.map(u=>({slot:!0,name:u.name,__model_id__:u.__model_id__,children:u.children.map(c=>V(c))})),i}function le(t){return V(t)}function H(t){return G.default.format(t,{parser:"html",bracketSameLine:!1,plugins:[De.default]})}function ue(t){return G.default.format(t,{parser:"babel",singleQuote:!0,semi:!0,trailingComma:"none",bracketSpacing:!0,bracketSameLine:!1,plugins:[Je.default]})}function U(t){return G.default.format(t,{parser:"scss",bracketSameLine:!1,plugins:[qe.default]})}function Ue(t,e){for(;t.length<e;)t="0"+t;return t}function h(t,e){var n,s,r;if(e.length===0)return t;for(n=0,r=e.length;n<r;n++)s=e.charCodeAt(n),t=(t<<5)-t+s,t|=0;return t<0?t*-2:t}function ke(t,e,n){return Object.keys(e).sort().reduce(s,t);function s(r,o){return de(r,e[o],o,n)}}function de(t,e,n,s){var r=h(h(h(t,n),Ge(e)),typeof e);if(e===null)return h(r,"null");if(e===void 0)return h(r,"undefined");if(typeof e=="object"||typeof e=="function"){if(s.indexOf(e)!==-1)return h(r,"[Circular]"+n);s.push(e);var o=ke(r,e,s);if(!("valueOf"in e)||typeof e.valueOf!="function")return o;try{return h(o,String(e.valueOf()))}catch(i){return h(o,"[valueOf exception]"+(i.stack||i.message))}}return h(r,e.toString())}function Ge(t){return Object.prototype.toString.call(t)}function Qe(t){return Ue(de(0,t,"",[]).toString(16),8)}var pe=Qe;function fe(){return"xxxxxxxxxxxx4xxxyxxxxxxxxxxxxxxx".replace(/[xy]/g,function(t){const e=Math.random()*16|0;return(t==="x"?e:e&3|8).toString(16)}).toLowerCase()}function me(t){return!t||typeof t=="string"?t:JSON.stringify(t).replace(/\"/g,"'")}function he(){return pe(fe())}function ge(t){const e=Object.create(null);return new URLSearchParams(t).forEach((s,r)=>{e[r]=s}),e}function _e(t=""){const e=t.indexOf("?"),n=e<=0?"":t.substring(e+1);return ge(n)}async function ye(t){return fetch(t).then(e=>e.json())}async function ve(t){return fetch(t).then(e=>e.text())}const ze=["Page","Tag"];function Ke(t){return t.length===1&&t[0].name==="default"&&t[0].params.length===0}function Ye(t){return t||""}function Xe(t){if(!t)return"";const{name:e,params:n,children:s}=t,r=n.length?`="{${n.join(",")}}"`:"";return`<template v-slot:${e}${r}>
|
|
2
|
-
${be(s)}
|
|
3
|
-
</template>`}function Ze(t){return Ke(t)?be(t[0].children):t.map(e=>Xe(e))}function et(t){const{name:e,modifiers:n}=t,s=t.arg?`:${t.arg}`:"",r=t.value?`="${t.value}"`:"";return`v-${e}${s}${n}${r}`}function tt(t){return t.map(e=>et(e)).join(" ")}function nt(t){return t?`data-model-id="${t}"`:""}function st(t,e,n,s){const o=s&&Object.keys(s).length>0?n||`model_${e}`:"",i=o?[o,...t]:t;return i.length?`class="${i.join(" ")}"`:""}function rt(t){const n=t.filter(c=>c.type!=="function"&&c.binding.type===T.DEFAULT&&c.binding.source===x.DEFAULT).map(c=>`${c.type==="string"?"":":"}${c.name}="${me(c.value)}"`),r=t.filter(c=>c.type==="function"&&c.binding.type===T.DEFAULT).map(c=>`:${c.name}="${c.binding.name||c.value}"`),i=t.filter(c=>c.binding.source===x.SLOT&&!!c.binding.name).map(c=>`:${c.name}="${c.binding.name}"`),u=t.filter(c=>c.binding.source===x.DATA_SOURCE&&!!c.binding.name).map(c=>`:${c.name}="${c.binding.name}"`);return[...n,...i,...r,...u].join(" ")}function ot(t){return t.filter(e=>e.type&&e.handler).map(e=>{const n=e.params.length?`(${e.params.join(",")})`:"";return`@${e.type}${e.modifiers}="${e.handler}${n}"`}).join(" ")}function Se(t){if(ze.includes(t.__model_name__)&&t.visible){const{type:e,text:n,slots:s,directives:r,name:o,classes:i,style:a,props:u,events:c}=t;return`<${e}
|
|
4
|
-
${nt(t.__model_id__)}
|
|
5
|
-
${tt(r)}
|
|
6
|
-
${st(i,t.__model_id__,o,a)}
|
|
7
|
-
${rt(u)}
|
|
8
|
-
${ot(c)}
|
|
9
|
-
>
|
|
10
|
-
${Ye(n)}
|
|
11
|
-
${Ze(s)}
|
|
12
|
-
</${e}>`}return""}function be(t=[]){return t.map(e=>Se(e)).join(`
|
|
13
|
-
`)}function it(t){return Se(t)}function ct(t){if(!t.length)return"{}";const e=t.filter(s=>s.type===v.JSON).map(s=>`${s.name}: ${s.code}`).join(","),n=t.filter(s=>s.type!==v.JSON).map(s=>v.CODE===s.type?`${s.name}: ${s.code}`:v.API===s.type?`${s.name}: createApi({
|
|
14
|
-
url:'${s.api.url}',
|
|
15
|
-
method:'${s.api.method}'
|
|
16
|
-
})`:"").join(",");return`{
|
|
17
|
-
data() {
|
|
18
|
-
return {
|
|
19
|
-
${e}
|
|
20
|
-
}
|
|
21
|
-
},
|
|
22
|
-
methods: {
|
|
23
|
-
${n}
|
|
24
|
-
}
|
|
25
|
-
}`}function at(t){const e=[];return j(t,n=>{n.__model_name__==="Event"&&e.push(n)}),e.filter(n=>n.code&&n.handler).map(n=>`${n.handler}${n.code}`).join(",")}function lt(t){const e={};j(t,(r,o)=>{if([A.ElementPlus,A.ElementUI].includes(r.origin)&&r.visible){const i=e[r.origin];i?i.add(r.type):e[r.origin]=new Set([r.type])}});let n="",s=[];return Object.keys(e).forEach(r=>{const o=Array.from(e[r]);n+=`import {${o.join(",")}} from '${r}';`,s=s.concat(o)}),{imports:n,components:s}}function ut(t){const{imports:e,components:n}=lt(t);return`
|
|
26
|
-
${e}
|
|
27
|
-
${t.imports||""}
|
|
28
|
-
const __mixin = ${t.mixin||"{}"}
|
|
29
|
-
const __dataSources = ${ct(t.dataSources)}
|
|
30
|
-
export default {
|
|
31
|
-
components: {${n.join(",")}},
|
|
32
|
-
mixins:[__dataSources, __mixin],
|
|
33
|
-
data() {
|
|
34
|
-
return {}
|
|
35
|
-
},
|
|
36
|
-
methods: {
|
|
37
|
-
${at(t)}
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
`}function dt(t){const e={};j(t,(s,r)=>{if(s.style&&Object.keys(s.style).length>0){const o=s.name||`model_${s.id}`;e[`.${o}`]=s.style}});let n="";return Object.keys(e).forEach(s=>{const r=e[s]||{};n+=`
|
|
41
|
-
${s} {`,Object.entries(r).forEach(([o,i])=>{n+=`${o}: ${i};`}),n+=`}
|
|
42
|
-
`}),n}function pt(t){return t?"scoped":""}var $=(t=>(t.VUE2="VUE2",t.VUE3="VUE3",t.VUE3_TS="VUE3_TS",t.UNI_APP="UNI_APP",t))($||{});function $e(t="VUE3",e){const n=it(e),s=ut(e),r=dt(e);return H(`
|
|
43
|
-
<template>
|
|
44
|
-
${H(n)}
|
|
45
|
-
</template>
|
|
46
|
-
|
|
47
|
-
<script>
|
|
48
|
-
${ue(s)}
|
|
49
|
-
<\/script>
|
|
50
|
-
|
|
51
|
-
<style lang="css" ${pt(e.scoped)}>
|
|
52
|
-
${U(e==null?void 0:e.css)}
|
|
53
|
-
${U(r)}
|
|
54
|
-
</style>
|
|
55
|
-
`)}async function xe(){return await Promise.resolve().then(function(){return k(require("systemjs"))}).then(async t=>window.System)}async function Oe(){return await Promise.resolve().then(function(){return k(require("systemjs-babel"))})}const ft=/\\/g;function ie(t,e){if(t.indexOf("\\")!==-1&&(t=t.replace(ft,"/")),t[0]==="/"&&t[1]==="/")return e.slice(0,e.indexOf(":")+1)+t;if(t[0]==="."&&(t[1]==="/"||t[1]==="."&&(t[2]==="/"||t.length===2&&(t+="/"))||t.length===1&&(t+="/"))||t[0]==="/"){const n=e.slice(0,e.indexOf(":")+1);let s;if(e[n.length+1]==="/"?n!=="file:"?(s=e.slice(n.length+2),s=s.slice(s.indexOf("/")+1)):s=e.slice(8):s=e.slice(n.length+(e[n.length]==="/")),t[0]==="/")return e.slice(0,e.length-s.length-1)+t;const r=s.slice(0,s.lastIndexOf("/")+1)+t,o=[];let i=-1;for(let a=0;a<r.length;a++)i!==-1?r[a]==="/"&&(o.push(r.slice(i,a+1)),i=-1):r[a]==="."?r[a+1]==="."&&(r[a+2]==="/"||a+2===r.length)?(o.pop(),a+=2):r[a+1]==="/"||a+1===r.length?a+=1:i=a:i=a;return i!==-1&&o.push(r.slice(i)),e.slice(0,e.length-s.length)+o.join("")}}function mt(t,e){return ie(t,e)||(t.indexOf(":")!==-1?t:ie("./"+t,e))}function Ee(t,e){var se;const n=pe(t+e),s="data-v-"+n,o=P.parse(e,{sourceMap:!1}).descriptor,i=o.styles.some(S=>S.scoped),a=P.compileTemplate({id:n,filename:t,source:((se=o.template)==null?void 0:se.content)||"",scoped:i,compilerOptions:{scopeId:i?s:void 0}}),u=P.compileScript(o,{id:n,templateOptions:{scoped:i,compilerOptions:{scopeId:i?s:void 0}}}),c=o.styles,d=[];if(c.length)for(let S=0;S<c.length;S++){const w=c[S];d.push(P.compileStyle({source:w.content,id:s,filename:t,scoped:w.scoped}).code)}let m=d.join(`
|
|
56
|
-
`);const y=t+".css";m=m.replace(/url\(\s*(?:(["'])((?:\\.|[^\n\\"'])+)\1|((?:\\.|[^\s,"'()\\])+))\s*\)/g,function(S,w,we,Pe){return"url("+w+mt(we||Pe,y)+w+")"});const F="_sfc_render",g="_sfc_main",je=a.code.replace(/\nexport (function|const) (render|ssrRender)/,`
|
|
57
|
-
$1 _sfc_$2`),D=[P.rewriteDefault(u.content,g),je,g+".render="+F,"export default "+g];i&&D.push(g+".__scopeId = "+JSON.stringify(s)),D.push(g+".__file = "+JSON.stringify(t));const Ae=D.join(`
|
|
58
|
-
`);return{style:m,script:Ae}}class ht{constructor(e,n){l(this,"model");this.schema=e,this.contentWindow=n,this.model=ae(e)}getSchema(){return this.model.toSchema()}getModel(e){return f.instances[e]}getOutline(){const e=this.getSchema();return[le(e)]}getHoverModel(e=[]){var m,y;const n=e.find(F=>{var g;return(g=F.dataset)==null?void 0:g.modelId});if(!n)return null;const s=(m=n.dataset)==null?void 0:m.modelId,r=this.getModel(s),o=((y=r.parent)==null?void 0:y.get("children"))||[],{width:i,height:a,left:u,top:c}=n.getBoundingClientRect(),d=r.modelName!=="Page";return{el:n,id:s,model:r,props:{id:s,width:i,height:a,left:u,top:c,opacity:1,type:r.get("type"),removeable:d,first:!d||d&&o[0]===r,last:!d||d&&o[o.length-1]===r,label:!0}}}getSelectedById(e){const{contentWindow:n}=this;if(!n)return;const s=n.document.querySelector(`[data-model-id="${e}"]`);if(!!s)return this.getHoverModel([s])}getSelectedModel(e=[]){return this.getHoverModel(e)}getDropModel(e=[]){return this.getHoverModel(e)}async appendModel(e={},n,s="default"){const{path:r,origin:o}=e,i=await ye(r),a=(i.props||[]).map(d=>new O({name:d.name,type:d.type,value:d.value})),u=(i.slots||[]).map(d=>new E(p({},d))),c=new _({type:i.tag,props:a,slots:u,origin:o,text:i.text||"",style:i.style||{},file:r});n.append(c,s)}removeModel(e){const n=e.parent;n&&(n.remove("children",e),e.dispose())}moveNext(e){const n=e.parent;if(!n)return;const s=n.get("children"),r=s.findIndex(i=>i===e),o=s[r+1];!o||(s[r]=o,s[r+1]=e)}movePrev(e){const n=e.parent;if(!n)return;const s=n.get("children"),r=s.findIndex(i=>i===e),o=s[r-1];!o||(s[r]=o,s[r-1]=e)}updateProps(e,n={}){this.getModel(e).get("props").forEach(o=>{const i=o.get("name"),a=n[i];o.set("value",a)})}setVisible(e,n){this.getModel(e).set("visible",n)}}const q={};class gt{constructor(e){l(this,"config");l(this,"system");l(this,"libs",{});l(this,"scriptEl",null);l(this,"app",null);l(this,"helper",null);this.config=p({imports:{},loader:"/engine.js",vue:"/libs/vue3/vue.runtime.esm-browser.prod.js",dslType:$.VUE3},e),this.init()}async init(){this.setImportMap(),await this.initSystem(),await this.prepareEnv();const{onReady:e}=this.config;e&&e(this)}async initSystem(){let e=window==null?void 0:window.System;if(e)return this.system=e,e;e=await xe();const n=e.constructor.prototype;n.shouldFetch=function(o){return!0};const s=n.fetch,{loader:r}=this.config;return n.fetch=(o,i)=>o.includes(r||"")?this.intercepter(o,i):s(o,i),this.system=e,await Oe()}async intercepter(e,n){const{type:s,file:r,id:o}=_e(e)||{};if(s==="lib")if(r.endsWith(".css")){const i=await ve(decodeURIComponent(r));return this.adoptedStyleSheets(r,i),new Response(null)}else{const i=`
|
|
59
|
-
export * from '${decodeURIComponent(r)}';
|
|
60
|
-
`;return Promise.resolve(new Response(new Blob([i],{type:"application/javascript"})))}if(s==="schema"){const i=q[o],a=$e($.VUE3,i);delete q[o];const{script:u,style:c}=Ee(i.name,a);return this.adoptedStyleSheets(o,c),Promise.resolve(new Response(new Blob([u],{type:"application/javascript"})))}return fetch(e,n)}async prepareEnv(){const{system:e,config:n,libs:s}=this,{imports:r,loader:o,vue:i}=n,a=`${o}?type=lib&name=vue&file=${encodeURIComponent(i)}`;await e.import(a).then(c=>{s.Vue=c,e.set("app:vue",c)}),e.prepareImport(!0);const u=Object.entries(r||{});for(let[c,d]of u){const m=`${o}?type=lib&name=${c}&file=${encodeURIComponent(d)}`;await e.import(m).then(y=>{s[c]=y,e.set(`app:${c}`,y)})}e.prepareImport(!0)}setImportMap(){const{scriptEl:e,config:n}=this,{imports:s,vue:r}=n;let o=e;o||(this.scriptEl=o=document.createElement("script"),o.type="systemjs-importmap");const i={vue:"app:vue"};Object.keys(s||{}).forEach(a=>{i[a]=`app:${a}`}),o.innerHTML=JSON.stringify({imports:i}),document.body.appendChild(o)}adoptedStyleSheets(e,n){const{contentWindow:s}=this.config;if(!s)return;const r=new s.CSSStyleSheet;r.id=e,r.replaceSync(n);const o=s.document,i=Array.from(o.adoptedStyleSheets).filter(a=>a.id!==e);o.adoptedStyleSheets=[...i,r]}async load(e){const{config:n,system:s}=this,{loader:r,dslType:o,contentWindow:i,onLoad:a}=n,u=e.__model_id__;q[u]=e,this.helper=new ht(e,i);const c=`${r}?type=schema&dsl=${o}&id=${u}&t=${Date.now()}`;return await s.import(c).then(d=>{const m=this.createApp(d.default);return a&&a(m),m}).catch(d=>{console.warn(d)})}async reload(){var n;const e=(n=this.helper)==null?void 0:n.getSchema();return await this.load(e)}createApp(e){var r;const{dslType:n,contentWindow:s}=this.config;if(n===$.VUE3){(r=this.app)==null||r.unmount();const o=this.libs.Vue.createApp(e);o.mount(s.document.body),this.app=o}return this.app}dispose(){const{scriptEl:e,app:n,config:s}=this,{contentWindow:r,dslType:o}=s;if(e&&e.parentNode&&e.parentNode.removeChild(e),r){const i=r.document;i.adoptedStyleSheets=[]}n&&o===$.VUE3&&(n.unmount(),this.app=null)}}exports.Base=f;exports.BindingSource=x;exports.BindingType=T;exports.DSLType=$;exports.DataSource=M;exports.DataSourceType=v;exports.Directive=C;exports.Engine=gt;exports.Event=N;exports.EventModifier=z;exports.Page=I;exports.Property=O;exports.PropertyDataType=Q;exports.Slot=E;exports.Tag=_;exports.TagOrigin=A;exports.cleanJSON=me;exports.compiler=Ee;exports.craeteOutline=V;exports.createModel=ce;exports.createModelTree=R;exports.cssFormat=U;exports.fetchCSS=ve;exports.fetchJSON=ye;exports.findModel=He;exports.getQuery=_e;exports.hashId=he;exports.htmlFormat=H;exports.loadSystemJs=xe;exports.loadSystemJsBabel=Oe;exports.modelTraverse=W;exports.schemaTraverse=j;exports.scriptFormat=ue;exports.toDSL=$e;exports.toModel=ae;exports.toOutline=le;exports.urlParser=ge;exports.uuid=fe;
|