@opentiny/tiny-engine-canvas 1.0.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/.eslintrc.js +42 -0
- package/README.md +7 -0
- package/canvas.html +212 -0
- package/dist/index.js +48919 -0
- package/index.html +13 -0
- package/package.json +30 -0
- package/public/favicon.ico +0 -0
- package/src/Design.vue +53 -0
- package/src/assets/logo.png +0 -0
- package/src/canvas.js +34 -0
- package/src/components/builtin/CanvasBox.vue +22 -0
- package/src/components/builtin/CanvasCol.vue +89 -0
- package/src/components/builtin/CanvasCollection.js +278 -0
- package/src/components/builtin/CanvasCollection.vue +106 -0
- package/src/components/builtin/CanvasIcon.vue +30 -0
- package/src/components/builtin/CanvasImg.vue +18 -0
- package/src/components/builtin/CanvasPlaceholder.vue +26 -0
- package/src/components/builtin/CanvasRow.vue +67 -0
- package/src/components/builtin/CanvasRowColContainer.vue +42 -0
- package/src/components/builtin/CanvasSlot.vue +22 -0
- package/src/components/builtin/CanvasText.vue +18 -0
- package/src/components/builtin/builtin.json +955 -0
- package/src/components/builtin/helper.js +46 -0
- package/src/components/builtin/index.js +33 -0
- package/src/components/common/index.js +158 -0
- package/src/components/container/CanvasAction.vue +554 -0
- package/src/components/container/CanvasContainer.vue +244 -0
- package/src/components/container/CanvasDivider.vue +246 -0
- package/src/components/container/CanvasDragItem.vue +38 -0
- package/src/components/container/CanvasFooter.vue +86 -0
- package/src/components/container/CanvasMenu.vue +214 -0
- package/src/components/container/CanvasResize.vue +195 -0
- package/src/components/container/CanvasResizeBorder.vue +219 -0
- package/src/components/container/container.js +791 -0
- package/src/components/container/keyboard.js +147 -0
- package/src/components/container/shortCutPopover.vue +181 -0
- package/src/components/render/CanvasEmpty.vue +14 -0
- package/src/components/render/RenderMain.js +408 -0
- package/src/components/render/context.js +53 -0
- package/src/components/render/render.js +689 -0
- package/src/components/render/runner.js +140 -0
- package/src/i18n/en.json +5 -0
- package/src/i18n/zh.json +5 -0
- package/src/i18n.js +21 -0
- package/src/index.js +96 -0
- package/src/locale.js +19 -0
- package/src/lowcode.js +104 -0
- package/src/main.js +17 -0
- package/test/form.json +690 -0
- package/test/group.json +99 -0
- package/test/jsslot.json +427 -0
- package/vite.config.js +73 -0
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) 2023 - present TinyEngine Authors.
|
|
3
|
+
* Copyright (c) 2023 - present Huawei Cloud Computing Technologies Co., Ltd.
|
|
4
|
+
*
|
|
5
|
+
* Use of this source code is governed by an MIT-style license.
|
|
6
|
+
*
|
|
7
|
+
* THE OPEN SOURCE SOFTWARE IN THIS PRODUCT IS DISTRIBUTED IN THE HOPE THAT IT WILL BE USEFUL,
|
|
8
|
+
* BUT WITHOUT ANY WARRANTY, WITHOUT EVEN THE IMPLIED WARRANTY OF MERCHANTABILITY OR FITNESS FOR
|
|
9
|
+
* A PARTICULAR PURPOSE. SEE THE APPLICABLE LICENSES FOR MORE DETAILS.
|
|
10
|
+
*
|
|
11
|
+
*/
|
|
12
|
+
|
|
13
|
+
export const getStyleValue = (value) => {
|
|
14
|
+
if (typeof value === 'number' || /^\d+\.?\d*$/.test(value)) {
|
|
15
|
+
return `${value}px`
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
if (/^\d+\.?\d*(px|%|pt|em|rem|vw|vh)$/.test(value)) {
|
|
19
|
+
return value
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
return ''
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export const alignMap = {
|
|
26
|
+
'flex-start': 'flex-start',
|
|
27
|
+
'flex-end': 'flex-end',
|
|
28
|
+
center: 'center',
|
|
29
|
+
stretch: 'stretch',
|
|
30
|
+
start: 'start',
|
|
31
|
+
end: 'end'
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
export const justAlignMap = {
|
|
35
|
+
'space-between': 'space-between',
|
|
36
|
+
'space-around': 'space-around',
|
|
37
|
+
'space-evenly': 'space-evenly',
|
|
38
|
+
'flex-start': 'flex-start',
|
|
39
|
+
'flex-end': 'flex-end',
|
|
40
|
+
stretch: 'stretch',
|
|
41
|
+
center: 'center',
|
|
42
|
+
start: 'start',
|
|
43
|
+
end: 'end',
|
|
44
|
+
left: 'left',
|
|
45
|
+
right: 'right'
|
|
46
|
+
}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) 2023 - present TinyEngine Authors.
|
|
3
|
+
* Copyright (c) 2023 - present Huawei Cloud Computing Technologies Co., Ltd.
|
|
4
|
+
*
|
|
5
|
+
* Use of this source code is governed by an MIT-style license.
|
|
6
|
+
*
|
|
7
|
+
* THE OPEN SOURCE SOFTWARE IN THIS PRODUCT IS DISTRIBUTED IN THE HOPE THAT IT WILL BE USEFUL,
|
|
8
|
+
* BUT WITHOUT ANY WARRANTY, WITHOUT EVEN THE IMPLIED WARRANTY OF MERCHANTABILITY OR FITNESS FOR
|
|
9
|
+
* A PARTICULAR PURPOSE. SEE THE APPLICABLE LICENSES FOR MORE DETAILS.
|
|
10
|
+
*
|
|
11
|
+
*/
|
|
12
|
+
|
|
13
|
+
import CanvasText from './CanvasText.vue'
|
|
14
|
+
import CanvasBox from './CanvasBox.vue'
|
|
15
|
+
import CanvasCollection from './CanvasCollection.vue'
|
|
16
|
+
import CanvasIcon from './CanvasIcon.vue'
|
|
17
|
+
import CanvasSlot from './CanvasSlot.vue'
|
|
18
|
+
import CanvasImg from './CanvasImg.vue'
|
|
19
|
+
import CanvasRow from './CanvasRow.vue'
|
|
20
|
+
import CanvasCol from './CanvasCol.vue'
|
|
21
|
+
import CanvasRowColContainer from './CanvasRowColContainer.vue'
|
|
22
|
+
|
|
23
|
+
export {
|
|
24
|
+
CanvasText,
|
|
25
|
+
CanvasBox,
|
|
26
|
+
CanvasCollection,
|
|
27
|
+
CanvasIcon,
|
|
28
|
+
CanvasSlot,
|
|
29
|
+
CanvasImg,
|
|
30
|
+
CanvasRow,
|
|
31
|
+
CanvasCol,
|
|
32
|
+
CanvasRowColContainer
|
|
33
|
+
}
|
|
@@ -0,0 +1,158 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) 2023 - present TinyEngine Authors.
|
|
3
|
+
* Copyright (c) 2023 - present Huawei Cloud Computing Technologies Co., Ltd.
|
|
4
|
+
*
|
|
5
|
+
* Use of this source code is governed by an MIT-style license.
|
|
6
|
+
*
|
|
7
|
+
* THE OPEN SOURCE SOFTWARE IN THIS PRODUCT IS DISTRIBUTED IN THE HOPE THAT IT WILL BE USEFUL,
|
|
8
|
+
* BUT WITHOUT ANY WARRANTY, WITHOUT EVEN THE IMPLIED WARRANTY OF MERCHANTABILITY OR FITNESS FOR
|
|
9
|
+
* A PARTICULAR PURPOSE. SEE THE APPLICABLE LICENSES FOR MORE DETAILS.
|
|
10
|
+
*
|
|
11
|
+
*/
|
|
12
|
+
|
|
13
|
+
export const NODE_UID = 'data-uid'
|
|
14
|
+
export const NODE_TAG = 'data-tag'
|
|
15
|
+
export const NODE_LOOP = 'loop-id'
|
|
16
|
+
|
|
17
|
+
export const addScript = (src, doc = document) => {
|
|
18
|
+
return new Promise((resolve, reject) => {
|
|
19
|
+
const script = doc.createElement('script')
|
|
20
|
+
|
|
21
|
+
script.setAttribute('type', 'text/javascript')
|
|
22
|
+
script.setAttribute('src', src)
|
|
23
|
+
|
|
24
|
+
script.async = false
|
|
25
|
+
|
|
26
|
+
script.onload = resolve
|
|
27
|
+
script.onerror = reject
|
|
28
|
+
|
|
29
|
+
doc.querySelector('head').appendChild(script)
|
|
30
|
+
})
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export const addStyle = (href, doc = document) => {
|
|
34
|
+
return new Promise((resolve, reject) => {
|
|
35
|
+
const link = doc.createElement('link')
|
|
36
|
+
|
|
37
|
+
link.setAttribute('href', href)
|
|
38
|
+
link.setAttribute('rel', 'stylesheet')
|
|
39
|
+
|
|
40
|
+
link.onload = resolve
|
|
41
|
+
link.onerror = reject
|
|
42
|
+
|
|
43
|
+
doc.querySelector('head').appendChild(link)
|
|
44
|
+
})
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
export const copyObject = (node) => {
|
|
48
|
+
if (typeof node === 'object') {
|
|
49
|
+
if (!node) {
|
|
50
|
+
return node
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
if (Array.isArray(node)) {
|
|
54
|
+
return node.map(copyObject)
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
const res = {}
|
|
58
|
+
Object.keys(node).forEach((key) => {
|
|
59
|
+
res[key] = copyObject(node[key])
|
|
60
|
+
})
|
|
61
|
+
|
|
62
|
+
const { componentName, id } = res
|
|
63
|
+
|
|
64
|
+
if (componentName && id) {
|
|
65
|
+
delete res.id
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
return res
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
return node
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
/**
|
|
75
|
+
* 复制节点的schema对象到剪切板,以String形式保存
|
|
76
|
+
* @param {*} event ClipboardEvent
|
|
77
|
+
* @param {*} node 节点的schema对象
|
|
78
|
+
* @return 复制的剪切板的String
|
|
79
|
+
*/
|
|
80
|
+
export const setClipboardSchema = (event, node) => {
|
|
81
|
+
let text
|
|
82
|
+
|
|
83
|
+
if (typeof node === 'object') {
|
|
84
|
+
text = JSON.stringify(node)
|
|
85
|
+
} else {
|
|
86
|
+
text = String(node)
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
event.clipboardData.setData('text/plain', text)
|
|
90
|
+
event.preventDefault()
|
|
91
|
+
|
|
92
|
+
return text
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
const translateStringToSchame = (clipText) => {
|
|
96
|
+
if (!clipText) {
|
|
97
|
+
return null
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
let data
|
|
101
|
+
|
|
102
|
+
try {
|
|
103
|
+
data = JSON.parse(clipText)
|
|
104
|
+
if (!data || !data.componentName) {
|
|
105
|
+
data = null
|
|
106
|
+
}
|
|
107
|
+
} catch (error) {
|
|
108
|
+
data = null
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
return data
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
/**
|
|
115
|
+
* 获得剪切板的内容,转换成schema
|
|
116
|
+
* @param {*} event ClipboardEvent
|
|
117
|
+
* @return 节点的schema对象
|
|
118
|
+
*/
|
|
119
|
+
export const getClipboardSchema = (event) => translateStringToSchame(event.clipboardData.getData('text/plain'))
|
|
120
|
+
|
|
121
|
+
/**
|
|
122
|
+
* 动态导入组件,缓存组件对象
|
|
123
|
+
* @param {object} param0 组件的依赖: { package: 包名,script:js文件cdn, components:组件id和导出组件名的映射关系}
|
|
124
|
+
* @returns
|
|
125
|
+
*/
|
|
126
|
+
export const dynamicImportComponents = async ({ package: pkg, script, components }) => {
|
|
127
|
+
if (!script) return
|
|
128
|
+
|
|
129
|
+
if (!window.TinyComponentLibs[pkg]) {
|
|
130
|
+
const modules = await import(/* @vite-ignore */ script)
|
|
131
|
+
|
|
132
|
+
window.TinyComponentLibs[pkg] = modules
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
Object.entries(components).forEach(([componentId, exportName]) => {
|
|
136
|
+
const modules = window.TinyComponentLibs[pkg]
|
|
137
|
+
|
|
138
|
+
if (!window.TinyLowcodeComponent[componentId]) {
|
|
139
|
+
window.TinyLowcodeComponent[componentId] = modules[exportName]
|
|
140
|
+
}
|
|
141
|
+
})
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
/**
|
|
145
|
+
* 更新区块/组件依赖
|
|
146
|
+
* @param {object} param0 依赖的CDN信息
|
|
147
|
+
*/
|
|
148
|
+
export const updateDependencies = ({ detail }) => {
|
|
149
|
+
const { scripts = [], styles = [] } = detail || {}
|
|
150
|
+
const { styles: canvasStyles } = window.thirdPartyDeps
|
|
151
|
+
const newStyles = [...styles].filter((item) => !canvasStyles.has(item))
|
|
152
|
+
|
|
153
|
+
newStyles.forEach((item) => canvasStyles.add(item))
|
|
154
|
+
|
|
155
|
+
const promises = [...newStyles].map((src) => addStyle(src)).concat(scripts.map(dynamicImportComponents))
|
|
156
|
+
|
|
157
|
+
Promise.allSettled(promises)
|
|
158
|
+
}
|