Compare commits
12 Commits
v1.0.0-rc.
...
v1.0.0-rc.
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
d147b361d7 | ||
|
|
09e3be66e1 | ||
|
|
a8acfaad31 | ||
|
|
fd5f7779a6 | ||
|
|
311ff22ae4 | ||
|
|
86624f5728 | ||
|
|
1db52c36b4 | ||
|
|
d2c936c5f0 | ||
|
|
31cbe7818f | ||
|
|
67e2ba3825 | ||
|
|
26081ea5cc | ||
|
|
c80dab835d |
10
docs/package-lock.json
generated
10
docs/package-lock.json
generated
@@ -64,6 +64,11 @@
|
||||
"fastq": "^1.6.0"
|
||||
}
|
||||
},
|
||||
"@popperjs/core": {
|
||||
"version": "npm:@sxzz/popperjs-es@2.11.7",
|
||||
"resolved": "https://registry.npmjs.org/@sxzz/popperjs-es/-/popperjs-es-2.11.7.tgz",
|
||||
"integrity": "sha512-Ccy0NlLkzr0Ex2FKvh2X+OyERHXJ88XJ1MXtsI9y9fGexlaXaVTPzBCRBwIxFkORuOb+uBqeu+RqnpgYTEZRUQ=="
|
||||
},
|
||||
"@types/debug": {
|
||||
"version": "4.1.7",
|
||||
"resolved": "https://registry.npmjs.org/@types/debug/-/debug-4.1.7.tgz",
|
||||
@@ -826,11 +831,6 @@
|
||||
"normalize-wheel-es": "^1.1.2"
|
||||
},
|
||||
"dependencies": {
|
||||
"@popperjs/core": {
|
||||
"version": "npm:@sxzz/popperjs-es@2.11.7",
|
||||
"resolved": "https://registry.npmjs.org/@sxzz/popperjs-es/-/popperjs-es-2.11.7.tgz",
|
||||
"integrity": "sha512-Ccy0NlLkzr0Ex2FKvh2X+OyERHXJ88XJ1MXtsI9y9fGexlaXaVTPzBCRBwIxFkORuOb+uBqeu+RqnpgYTEZRUQ=="
|
||||
},
|
||||
"@vueuse/core": {
|
||||
"version": "8.5.0",
|
||||
"resolved": "https://registry.npmjs.org/@vueuse/core/-/core-8.5.0.tgz",
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
# 介绍
|
||||
|
||||
我们提供了与编辑器,表单配套的管理端供开发者直接使用。管理端(magic-admin)代码存放于[开源仓库](https://github.com/Tencent/tmagic-editor)"magic-admin"目录下,可作为一个独立项目运行。我们提供这个管理端一方面期望开发者可以更清晰的了解一个项目从编辑到生成的整个流程,另一方面,开发者也可以
|
||||
在 magic-admin 的基础上快速搭建适合自己业务的管理平台。
|
||||
我们提供了可视化搭建平台管理端(magic-admin)供开发者直接使用,与可视化编辑器(@tmagic/editor)、自定义表单(@tmagic/form)配套。管理端代码存放于[开源仓库](https://github.com/Tencent/tmagic-editor)"magic-admin"目录下,可作为一个独立项目运行。我们期望,一方面开发者可以更清晰的了解一个项目从编辑到生成的整个流程;另一方面,开发者也可以在 magic-admin 的基础上快速搭建适合自己业务的管理平台,构建一个完整的页面可视化搭建系统。
|
||||
|
||||
管理端提供了如下能力:
|
||||
|
||||
|
||||
@@ -1,6 +1,9 @@
|
||||
# 如何开发一个组件
|
||||
tmagic-editor支持业务方进行自定义组件开发。在tmagic-editor中,组件是以 npm 包形式存在的,组件和插件只要按照规范开发,就可以在tmagic-editor的 runtime 中被加入并正确渲染组件。
|
||||
|
||||
## 组件开发
|
||||
以 vue3 的组件开发为例。运行项目中的 playground 示例,会自动加载 vue3 的 runtime。runtime会加载[@tmagic/ui](https://github.com/Tencent/tmagic-editor/tree/master/packages/ui)
|
||||
|
||||
## 组件注册
|
||||
在 [playground](https://tencent.github.io/tmagic-editor/playground/index.html#/) 中,我们可以尝试点击添加一个组件,在模拟器区域里,就会出现这个组件。其中就涉及到组件注册。
|
||||
|
||||
@@ -8,9 +11,6 @@ tmagic-editor支持业务方进行自定义组件开发。在tmagic-editor中,
|
||||
|
||||
可以参考 vue3 版本的 @tmagic/ui 中,[组件渲染](../guide/advanced/page.html#组件渲染)逻辑里,type 会作为组件名进入渲染。所以在 vue3 的组件开发中,我们也需要在为 vue 组件声明 name 字段时,和 type 值对应起来,才能正确渲染组件。
|
||||
|
||||
## 组件开发
|
||||
以 vue3 的组件开发为例。目前项目中的 playground 代码,会自动加载 vue3 相关的组件库。
|
||||
|
||||
### 组件规范
|
||||
组件的基础形式,需要有四个文件
|
||||
- index 入口文件,引入下面几个文件
|
||||
|
||||
@@ -12,14 +12,14 @@ tmagic-editor的一个高级特性,就是支持开发者在不修改组件代
|
||||
- [vue runtime 执行钩子时机](https://github.com/Tencent/tmagic-editor/blob/master/packages/ui/src/useApp.ts)
|
||||
|
||||
## 函数编写
|
||||
在编辑中,即写入一个执行函数,tmagic-editor会在对应组件的指定声明周期中执行改函数。同时**传入当前组件的 Node 实例对象**,作为执行参数。
|
||||
在编辑中,即写入一个执行函数,tmagic-editor会在对应组件的指定声明周期中执行该函数。同时**传入当前组件的 Node 实例对象**,作为执行参数。
|
||||
|
||||
传入的实例对象,可以根据各语言框架实现的 ui 提供的特性能力,来支持业务组件的能力实现。这个功能提供给开发者自由实现黑科技的机会。
|
||||
|
||||
<img src="https://image.video.qpic.cn/oa_2a552e-0_934618672_1636348294258073">
|
||||
|
||||
### 函数参数
|
||||
在 Magic-Core 中,我们对执行钩子函数传入了对应的 Node 实例对象。在 react 和 vue 中会稍有差异。差异在于 Node 实例的 instance 属性。
|
||||
在 Magic-Core 中,我们对执行钩子函数传入了对应的 [Node](https://github.com/Tencent/tmagic-editor/blob/master/packages/core/src/Node.ts) 实例对象。在 react 和 vue 中会稍有差异。差异在于 [Node](https://github.com/Tencent/tmagic-editor/blob/master/packages/core/src/Node.ts) 实例的 instance 属性。
|
||||
|
||||
- [Node 实例描述](https://github.com/Tencent/tmagic-editor/blob/master/packages/core/src/Node.ts)
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
# JS Schema
|
||||
tmagic-editor的业务组件需要有表单配置能力,我们通过一份配置来描述表单,我们采用的描述方案是 JS schema。当我们在编辑器中配置一个页面时,页面的基本信息和页面包含的组件信息,也是采用 JS schema 描述的。JS schema 描述方案,,也是我们提供[高级函数](../advanced/high-level-function)功能的基础。
|
||||
tmagic-editor的业务组件需要有表单配置能力,我们通过一份配置来描述表单,我们采用的描述方案是 JS schema。当我们在编辑器中配置一个页面时,页面的基本信息和页面包含的组件信息,也是采用 JS schema 描述的。JS schema 描述方案,也是我们提供[高级函数](../advanced/high-level-function)功能的基础。
|
||||
|
||||
组件的**配置描述**,参考[示例](../advanced/magic-form.html#示例),是由开发者在开发组件时,通过 [@tmagic/form](../advanced/magic-form) 支持的表单项来提供的。
|
||||
|
||||
|
||||
@@ -40,6 +40,8 @@ app.use(MagicForm);
|
||||
app.mount("#app");
|
||||
```
|
||||
|
||||
以上代码便完成了 @tmagic/form 的引入。需要注意的是,ElementUI 的样式文件需要单独引入。
|
||||
|
||||
在 App.Vue 中写入以下内容:
|
||||
|
||||
```html
|
||||
@@ -104,8 +106,6 @@ app.mount("#app");
|
||||
</script>
|
||||
```
|
||||
|
||||
以上代码便完成了 @tmagic/form 的引入。需要注意的是,ElementUI 的样式文件需要单独引入。
|
||||
|
||||
### 开始使用
|
||||
|
||||
至此,一个基于 Vue 和 @tmagic/form 的开发环境已经搭建完毕,现在就可以编写代码了。
|
||||
|
||||
@@ -25,7 +25,7 @@ export default {
|
||||
```
|
||||
|
||||
## 组件渲染
|
||||
所有tmagic-editor组件,都通过一个tmagic-editor基础组件来渲染,这个基础组件会识别,当前渲染的组件是个普通组件,或者是容器组件,如果是普通组件(包括ui中提供的基础组件和业务开发的业务组件),则直接渲染;如果是个容器,则回到上一步的容器渲染逻辑中。
|
||||
所有tmagic-editor组件,都通过一个tmagic-editor基础组件来渲染。这个基础组件会识别当前渲染组件的类型。如果当前渲染组件是普通组件(包括ui中提供的基础组件和业务开发的业务组件),则直接渲染;如果当前渲染组件是容器,则回到[容器渲染](#容器渲染)逻辑中。
|
||||
|
||||
基础组件的具体形式为:
|
||||
```vue
|
||||
|
||||
@@ -16,6 +16,23 @@
|
||||
- 拓展描述,这部分内容目前还未有严格定义,但是我们保留这个扩展能力。
|
||||
- 组件 `type`, 是组件的类型,这是用来告诉编辑器,我们要渲染的是什么组件。每个组件在开发时就应该确定这样一个唯一、不和其他组件冲突的组件 `type`。
|
||||
|
||||
```
|
||||
[
|
||||
{
|
||||
text: '文本',
|
||||
type: 'text', ⬅️
|
||||
},
|
||||
{
|
||||
text: '按钮',
|
||||
type: 'button', ⬅️
|
||||
},
|
||||
{
|
||||
text: '测试',
|
||||
type: 'test', ⬅️
|
||||
},
|
||||
]
|
||||
```
|
||||
|
||||
### 插件
|
||||
插件和组件类似,但是插件的功能是作为页面逻辑行为的一种补充方式。一般不显式的在模拟器中被渲染出具体内容(除非插件中会生成组件并插入页面),通常我们会用插件实现类似登录,页面环境判断,请求拦截器等等功能。
|
||||
|
||||
|
||||
@@ -17,7 +17,7 @@ node.js > 14
|
||||
$ npm install @tmagic/editor@latest -S
|
||||
```
|
||||
|
||||
editor 中组件自定义属性配置由[@tmagic/form](advanced/magic-form.html)提供,需要添加@tmagic/form 依赖;editor 与 form 中使用到的 UI 组件都由 [element-plus](https://element-plus.org/)提供,需要添加 element-plus 依赖。
|
||||
editor 中组件自定义属性配置由[@tmagic/form](./advanced/magic-form.md)提供,需要添加@tmagic/form 依赖;editor 与 form 中使用到的 UI 组件都由 [element-plus](https://element-plus.org/)提供,需要添加 element-plus 依赖。
|
||||
|
||||
```bash
|
||||
$ npm install @tmagic/form@latest element-plus -S
|
||||
@@ -127,7 +127,7 @@ app.mount("#app");
|
||||
</style>
|
||||
```
|
||||
|
||||
关于 [@tmagic/editor](https://www.npmjs.com/package/@tmagic/editor) 组件,更多的属性配置详情请参考[编辑器 API](../api/editor.md)。
|
||||
关于 [@tmagic/editor](https://www.npmjs.com/package/@tmagic/editor) 组件,更多的属性配置详情请参考[编辑器 API](../api/editor/editor.md)。
|
||||
|
||||
其中,**有四个需要注意的属性配置项**:`runtimeUrl` `values` `configs` `componentGroupList`。这是能让我们的编辑器正常运行的关键。
|
||||
|
||||
@@ -141,7 +141,7 @@ app.mount("#app");
|
||||
|
||||
### componentGroupList
|
||||
|
||||
`componentGroupList` 是指定左侧组件库内容的配置。此处定义了在编辑器组件库中有什么组件。在添加的时候通过组件 `type` 来确定 runtime 中要渲染什么组件。可以参考 [componentGroupList 配置](../api/editor.html#componentgrouplist)。
|
||||
`componentGroupList` 是指定左侧组件库内容的配置。此处定义了在编辑器组件库中有什么组件。在添加的时候通过组件 `type` 来确定 runtime 中要渲染什么组件。可以参考 [componentGroupList 配置](../api/editor/editor.html#componentgrouplist)。
|
||||
|
||||
### propsConfigs/propsValues
|
||||
|
||||
|
||||
@@ -127,7 +127,7 @@ tmagic-editor的[打包脚本](../page/introduction.html#打包脚本)会根据
|
||||
|
||||
<img src="https://image.video.qpic.cn/oa_88b7d-32_1233288257_1633783105283986" width="40%" alt="版本选择">
|
||||
|
||||
版本管理具体如何实现取决于使用tmagic-editor的业务方相关,拥有版本管理能力,具有如下优点:
|
||||
版本管理具体如何实现,这取决于使用tmagic-editor的业务方。版本管理具有如下优点:
|
||||
1. 对于已经配置好发布的项目,使用固定版本,不会被新版本的特性影响,保证项目线上稳定运行
|
||||
2. 发布的新版本如果出现问题,可以及时回退选择使用旧版本
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
{
|
||||
"version": "1.0.0-rc.3",
|
||||
"version": "1.0.0-rc.5",
|
||||
"npmClient": "npm",
|
||||
"packages": [
|
||||
"packages/*",
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
# 介绍
|
||||
|
||||
我们提供了与编辑器,表单配套的管理端供开发者直接使用。管理端(magic-admin)代码存放于[开源仓库](https://github.com/Tencent/tmagic-editor)"magic-admin"目录下,可作为一个独立项目运行。我们提供这个管理端一方面期望开发者可以更清晰的了解一个项目从编辑到生成的整个流程,另一方面,开发者也可以
|
||||
我们提供了与编辑器、表单等配套的管理端供开发者直接使用。管理端(magic-admin)代码存放于[开源仓库](https://github.com/Tencent/tmagic-editor)"magic-admin"目录下,可作为一个独立项目运行。我们提供这个管理端一方面期望开发者可以更清晰的了解一个项目从编辑到生成的整个流程,另一方面,开发者也可以
|
||||
在 magic-admin 的基础上快速搭建适合自己业务的管理平台。
|
||||
|
||||
管理端提供了如下能力:
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
{
|
||||
"version": "1.0.0-rc.3",
|
||||
"version": "1.0.0-rc.5",
|
||||
"name": "@tmagic/core",
|
||||
"sideEffects": [
|
||||
"dist/*"
|
||||
@@ -33,7 +33,7 @@
|
||||
"vue"
|
||||
],
|
||||
"dependencies": {
|
||||
"@tmagic/schema": "^1.0.0-rc.3",
|
||||
"@tmagic/schema": "^1.0.0-rc.5",
|
||||
"events": "^3.3.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
|
||||
2
packages/editor/package-lock.json
generated
2
packages/editor/package-lock.json
generated
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@tmagic/editor",
|
||||
"version": "1.0.0-rc.3",
|
||||
"version": "1.0.0-rc.5",
|
||||
"lockfileVersion": 1,
|
||||
"requires": true,
|
||||
"dependencies": {
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
{
|
||||
"version": "1.0.0-rc.3",
|
||||
"version": "1.0.0-rc.5",
|
||||
"name": "@tmagic/editor",
|
||||
"sideEffects": [
|
||||
"dist/*",
|
||||
@@ -45,11 +45,11 @@
|
||||
"dependencies": {
|
||||
"@babel/core": "^7.18.0",
|
||||
"@element-plus/icons": "0.0.11",
|
||||
"@tmagic/core": "^1.0.0-rc.3",
|
||||
"@tmagic/form": "^1.0.0-rc.3",
|
||||
"@tmagic/schema": "^1.0.0-rc.3",
|
||||
"@tmagic/stage": "^1.0.0-rc.3",
|
||||
"@tmagic/utils": "^1.0.0-rc.3",
|
||||
"@tmagic/core": "^1.0.0-rc.5",
|
||||
"@tmagic/form": "^1.0.0-rc.5",
|
||||
"@tmagic/schema": "^1.0.0-rc.5",
|
||||
"@tmagic/stage": "^1.0.0-rc.5",
|
||||
"@tmagic/utils": "^1.0.0-rc.5",
|
||||
"buffer": "^6.0.3",
|
||||
"color": "^3.1.3",
|
||||
"element-plus": "^2.2.0",
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
<template>
|
||||
<div v-if="menuData.length" v-show="visible" class="magic-editor-content-menu" ref="menu" :style="menuStyle">
|
||||
<div v-if="menuData.length && visible" class="magic-editor-content-menu" ref="menu" :style="menuStyle">
|
||||
<div>
|
||||
<tool-button
|
||||
v-for="(item, index) in menuData"
|
||||
@@ -49,7 +49,7 @@ export default defineComponent({
|
||||
|
||||
onMounted(() => {
|
||||
globalThis.addEventListener(
|
||||
'mousedown',
|
||||
'mouseup',
|
||||
(e: MouseEvent) => {
|
||||
if (!visible.value || (e.target && menu.value?.contains(e.target as HTMLElement))) {
|
||||
return;
|
||||
@@ -82,7 +82,7 @@ export default defineComponent({
|
||||
|
||||
menuStyle.value = {
|
||||
top: `${top}px`,
|
||||
left: `${e.clientX}px`,
|
||||
left: `${e.clientX + 2}px`,
|
||||
};
|
||||
});
|
||||
},
|
||||
|
||||
@@ -69,8 +69,20 @@ export default defineComponent({
|
||||
text: '粘贴',
|
||||
display: () => canPaste.value,
|
||||
handler: () => {
|
||||
const top = menu.value?.$el.offsetTop || 0;
|
||||
const left = menu.value?.$el.offsetLeft || 0;
|
||||
const stage = editorService?.get<StageCore>('stage');
|
||||
|
||||
const rect = menu.value?.$el.getBoundingClientRect();
|
||||
const parentRect = stage?.container?.getBoundingClientRect();
|
||||
let left = (rect?.left || 0) - (parentRect?.left || 0);
|
||||
let top = (rect?.top || 0) - (parentRect?.top || 0);
|
||||
|
||||
if (node.value?.items && stage) {
|
||||
const parentEl = stage.renderer.contentWindow?.document.getElementById(`${node.value.id}`);
|
||||
const parentElRect = parentEl?.getBoundingClientRect();
|
||||
left = left - (parentElRect?.left || 0);
|
||||
top = top - (parentElRect?.top || 0);
|
||||
}
|
||||
|
||||
editorService?.paste({ left, top });
|
||||
},
|
||||
},
|
||||
|
||||
@@ -91,7 +91,7 @@ const doAction = async (
|
||||
* editorService.afterAdd();
|
||||
* }
|
||||
*
|
||||
* 调用时的参数会透传到before方法的参数中, 然后before的return 会作为原方法的参数和after的参数,after最后一个参数则是原方法的return值;
|
||||
* 调用时的参数会透传到before方法的参数中, 然后before的return 会作为原方法的参数和after的参数,after第一个参数则是原方法的return值;
|
||||
* 如需终止后续方法调用可以return new Error();
|
||||
*
|
||||
* 方法2:
|
||||
|
||||
@@ -33,6 +33,7 @@ import {
|
||||
change2Fixed,
|
||||
COPY_STORAGE_KEY,
|
||||
Fixed2Other,
|
||||
generatePageNameByApp,
|
||||
getNodeIndex,
|
||||
initPosition,
|
||||
isFixed,
|
||||
@@ -502,6 +503,10 @@ class Editor extends BaseService {
|
||||
};
|
||||
}
|
||||
|
||||
if (isPage(config)) {
|
||||
config.name = generatePageNameByApp(this.get('root'));
|
||||
}
|
||||
|
||||
return await this.add(config);
|
||||
}
|
||||
|
||||
|
||||
@@ -142,9 +142,13 @@ export const toRelative = (node: MNode) => {
|
||||
|
||||
const setTop2Middle = (node: MNode, parentNode: MNode, stage: StageCore) => {
|
||||
const style = node.style || {};
|
||||
const height = style.height || 0;
|
||||
let height = style.height || 0;
|
||||
|
||||
if (!stage || typeof style.top !== 'undefined' || !parentNode.style || !isNumber(height)) return style;
|
||||
if (!stage || typeof style.top !== 'undefined' || !parentNode.style) return style;
|
||||
|
||||
if (!isNumber(height)) {
|
||||
height = 0;
|
||||
}
|
||||
|
||||
const { height: parentHeight } = parentNode.style;
|
||||
|
||||
|
||||
2
packages/form/package-lock.json
generated
2
packages/form/package-lock.json
generated
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@tmagic/form",
|
||||
"version": "1.0.0-rc.3",
|
||||
"version": "1.0.0-rc.5",
|
||||
"lockfileVersion": 1,
|
||||
"requires": true,
|
||||
"dependencies": {
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
{
|
||||
"version": "1.0.0-rc.3",
|
||||
"version": "1.0.0-rc.5",
|
||||
"name": "@tmagic/form",
|
||||
"sideEffects": [
|
||||
"dist/*",
|
||||
@@ -35,7 +35,7 @@
|
||||
},
|
||||
"dependencies": {
|
||||
"@element-plus/icons": "0.0.11",
|
||||
"@tmagic/utils": "^1.0.0-rc.3",
|
||||
"@tmagic/utils": "^1.0.0-rc.5",
|
||||
"element-plus": "^2.2.0",
|
||||
"lodash-es": "^4.17.21",
|
||||
"moment": "^2.29.2",
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
{
|
||||
"version": "1.0.0-rc.3",
|
||||
"version": "1.0.0-rc.5",
|
||||
"name": "@tmagic/schema",
|
||||
"sideEffects": false,
|
||||
"main": "dist/tmagic-schema.umd.js",
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
{
|
||||
"version": "1.0.0-rc.3",
|
||||
"version": "1.0.0-rc.5",
|
||||
"name": "@tmagic/stage",
|
||||
"sideEffects": [
|
||||
"dist/*"
|
||||
@@ -27,9 +27,9 @@
|
||||
},
|
||||
"dependencies": {
|
||||
"@scena/guides": "^0.17.0",
|
||||
"@tmagic/core": "^1.0.0-rc.3",
|
||||
"@tmagic/schema": "^1.0.0-rc.3",
|
||||
"@tmagic/utils": "^1.0.0-rc.3",
|
||||
"@tmagic/core": "^1.0.0-rc.5",
|
||||
"@tmagic/schema": "^1.0.0-rc.5",
|
||||
"@tmagic/utils": "^1.0.0-rc.5",
|
||||
"events": "^3.3.0",
|
||||
"lodash-es": "^4.17.21",
|
||||
"moveable": "^0.29.4",
|
||||
|
||||
@@ -23,9 +23,9 @@ import type { MoveableOptions } from 'moveable';
|
||||
import Moveable from 'moveable';
|
||||
import MoveableHelper from 'moveable-helper';
|
||||
|
||||
import { DRAG_EL_ID_PREFIX, GHOST_EL_ID_PREFIX, GuidesType, Mode } from './const';
|
||||
import { DRAG_EL_ID_PREFIX, GHOST_EL_ID_PREFIX, GuidesType, Mode, ZIndex } from './const';
|
||||
import StageCore from './StageCore';
|
||||
import type { Offset, Runtime, SortEventData, StageDragResizeConfig } from './types';
|
||||
import type { Offset, SortEventData, StageDragResizeConfig } from './types';
|
||||
import { getAbsolutePosition, getGuideLineFromCache, getMode, getOffset } from './util';
|
||||
|
||||
/** 拖动状态 */
|
||||
@@ -171,6 +171,29 @@ export default class StageDragResize extends EventEmitter {
|
||||
});
|
||||
}
|
||||
|
||||
private setElementGuidelines(nodes: HTMLElement[]) {
|
||||
this.elementGuidelines.forEach((node) => {
|
||||
node.remove();
|
||||
});
|
||||
this.elementGuidelines = [];
|
||||
|
||||
if (this.mode === Mode.ABSOLUTE) {
|
||||
const frame = document.createDocumentFragment();
|
||||
|
||||
for (const node of nodes) {
|
||||
const { width, height } = node.getBoundingClientRect();
|
||||
if (node === this.target) continue;
|
||||
const { left, top } = getOffset(node as HTMLElement);
|
||||
const elementGuideline = document.createElement('div');
|
||||
elementGuideline.style.cssText = `position: absolute;width: ${width}px;height: ${height}px;top: ${top}px;left: ${left}px`;
|
||||
this.elementGuidelines.push(elementGuideline);
|
||||
frame.append(elementGuideline);
|
||||
}
|
||||
|
||||
this.container.append(frame);
|
||||
}
|
||||
}
|
||||
|
||||
private initMoveable() {
|
||||
this.moveable?.destroy();
|
||||
|
||||
@@ -288,19 +311,6 @@ export default class StageDragResize extends EventEmitter {
|
||||
});
|
||||
}
|
||||
|
||||
private getSnapElements(runtime: Runtime, el?: HTMLElement): HTMLElement[] {
|
||||
const { renderer, mask } = this.core;
|
||||
const getSnapElements =
|
||||
runtime?.getSnapElements ||
|
||||
(() => {
|
||||
const doc = renderer.contentWindow?.document;
|
||||
return doc ? Array.from(doc.querySelectorAll('[id]')) : [];
|
||||
});
|
||||
return getSnapElements(el).filter(
|
||||
(element) => element !== this.target && !this.target?.contains(element) && element !== mask.page,
|
||||
);
|
||||
}
|
||||
|
||||
private sort(): void {
|
||||
if (!this.target || !this.ghostEl) throw new Error('未知错误');
|
||||
const { top } = this.ghostEl.getBoundingClientRect();
|
||||
@@ -344,7 +354,7 @@ export default class StageDragResize extends EventEmitter {
|
||||
const ghostEl = el.cloneNode(true) as HTMLElement;
|
||||
const { top, left } = getAbsolutePosition(el, getOffset(el));
|
||||
ghostEl.id = `${GHOST_EL_ID_PREFIX}${el.id}`;
|
||||
ghostEl.style.zIndex = '5';
|
||||
ghostEl.style.zIndex = ZIndex.GHOST_EL;
|
||||
ghostEl.style.opacity = '.5';
|
||||
ghostEl.style.position = 'absolute';
|
||||
ghostEl.style.left = `${left}px`;
|
||||
@@ -368,7 +378,7 @@ export default class StageDragResize extends EventEmitter {
|
||||
top: ${offset.top}px;
|
||||
width: ${width}px;
|
||||
height: ${height}px;
|
||||
z-index: 9;
|
||||
z-index: ${ZIndex.DRAG_EL};
|
||||
`;
|
||||
|
||||
this.dragEl.id = `${DRAG_EL_ID_PREFIX}${el.id}`;
|
||||
@@ -390,6 +400,14 @@ export default class StageDragResize extends EventEmitter {
|
||||
moveableOptions = moveableOptions(this.core);
|
||||
}
|
||||
|
||||
const elementGuidelines: any = moveableOptions.elementGuidelines || this.target.parentElement?.children || [];
|
||||
|
||||
this.setElementGuidelines(elementGuidelines);
|
||||
|
||||
if (moveableOptions.elementGuidelines) {
|
||||
delete moveableOptions.elementGuidelines;
|
||||
}
|
||||
|
||||
return {
|
||||
origin: false,
|
||||
rootContainer: this.core.container,
|
||||
|
||||
@@ -42,6 +42,8 @@ export enum ZIndex {
|
||||
MASK = '99999',
|
||||
/** 选中的节点 */
|
||||
SELECTED_EL = '666',
|
||||
GHOST_EL = '700',
|
||||
DRAG_EL = '9',
|
||||
}
|
||||
|
||||
/** 鼠标按键 */
|
||||
|
||||
2
packages/table/package-lock.json
generated
2
packages/table/package-lock.json
generated
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@tmagic/table",
|
||||
"version": "1.0.0-rc.3",
|
||||
"version": "1.0.0-rc.5",
|
||||
"lockfileVersion": 1,
|
||||
"requires": true,
|
||||
"dependencies": {
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
{
|
||||
"version": "1.0.0-rc.3",
|
||||
"version": "1.0.0-rc.5",
|
||||
"name": "@tmagic/table",
|
||||
"sideEffects": [
|
||||
"dist/*"
|
||||
@@ -30,7 +30,7 @@
|
||||
"url": "https://github.com/Tencent/tmagic-editor.git"
|
||||
},
|
||||
"dependencies": {
|
||||
"@tmagic/form": "^1.0.0-rc.3",
|
||||
"@tmagic/form": "^1.0.0-rc.5",
|
||||
"element-plus": "^2.2.0",
|
||||
"lodash-es": "^4.17.21",
|
||||
"vue": "^3.2.0"
|
||||
|
||||
2
packages/ui-react/package-lock.json
generated
2
packages/ui-react/package-lock.json
generated
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@tmagic/ui-react",
|
||||
"version": "1.0.0-rc.3",
|
||||
"version": "1.0.0-rc.5",
|
||||
"lockfileVersion": 1,
|
||||
"requires": true,
|
||||
"dependencies": {
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@tmagic/ui-react",
|
||||
"version": "1.0.0-rc.3",
|
||||
"version": "1.0.0-rc.5",
|
||||
"main": "src/index.ts",
|
||||
"engines": {
|
||||
"node": ">=14"
|
||||
@@ -13,7 +13,7 @@
|
||||
"react:build": "tsc && vite build"
|
||||
},
|
||||
"dependencies": {
|
||||
"@tmagic/schema": "^1.0.0-rc.3",
|
||||
"@tmagic/schema": "^1.0.0-rc.5",
|
||||
"qrcode": "^1.5.0",
|
||||
"react": "^17.0.0",
|
||||
"react-dom": "^17.0.0"
|
||||
|
||||
2
packages/ui-vue2/package-lock.json
generated
2
packages/ui-vue2/package-lock.json
generated
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@tmagic/ui-vue2",
|
||||
"version": "1.0.0-rc.3",
|
||||
"version": "1.0.0-rc.5",
|
||||
"lockfileVersion": 1,
|
||||
"requires": true,
|
||||
"dependencies": {
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
{
|
||||
"version": "1.0.0-rc.3",
|
||||
"version": "1.0.0-rc.5",
|
||||
"name": "@tmagic/ui-vue2",
|
||||
"main": "src/index.ts",
|
||||
"scripts": {
|
||||
@@ -13,10 +13,10 @@
|
||||
"url": "https://github.com/Tencent/tmagic-editor.git"
|
||||
},
|
||||
"dependencies": {
|
||||
"@tmagic/schema": "^1.0.0-rc.3",
|
||||
"@tmagic/schema": "^1.0.0-rc.5",
|
||||
"@vue/composition-api": "1.0.5",
|
||||
"vue": "^2.6.14",
|
||||
"qrcode": "^1.5.0"
|
||||
"qrcode": "^1.5.0",
|
||||
"vue": "^2.6.14"
|
||||
},
|
||||
"peerDependencies": {
|
||||
"@vue/composition-api": "1.0.5",
|
||||
|
||||
2
packages/ui/package-lock.json
generated
2
packages/ui/package-lock.json
generated
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@tmagic/ui",
|
||||
"version": "1.0.0-rc.3",
|
||||
"version": "1.0.0-rc.5",
|
||||
"lockfileVersion": 1,
|
||||
"requires": true,
|
||||
"dependencies": {
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
{
|
||||
"version": "1.0.0-rc.3",
|
||||
"version": "1.0.0-rc.5",
|
||||
"name": "@tmagic/ui",
|
||||
"main": "src/index.ts",
|
||||
"engines": {
|
||||
@@ -11,7 +11,7 @@
|
||||
"url": "https://github.com/Tencent/tmagic-editor.git"
|
||||
},
|
||||
"dependencies": {
|
||||
"@tmagic/schema": "^1.0.0-rc.3",
|
||||
"@tmagic/schema": "^1.0.0-rc.5",
|
||||
"delegate": "^3.2.0",
|
||||
"qrcode": "^1.5.0",
|
||||
"tiny-emitter": "^2.1.0",
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
{
|
||||
"version": "1.0.0-rc.3",
|
||||
"version": "1.0.0-rc.5",
|
||||
"name": "@tmagic/utils",
|
||||
"main": "dist/tmagic-utils.umd.js",
|
||||
"module": "dist/tmagic-utils.es.js",
|
||||
@@ -24,7 +24,7 @@
|
||||
"url": "https://github.com/Tencent/tmagic-editor.git"
|
||||
},
|
||||
"dependencies": {
|
||||
"@tmagic/schema": "^1.0.0-rc.3",
|
||||
"@tmagic/schema": "^1.0.0-rc.5",
|
||||
"moment": "^2.29.2"
|
||||
},
|
||||
"devDependencies": {
|
||||
|
||||
2
playground/package-lock.json
generated
2
playground/package-lock.json
generated
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "tmagic-playground",
|
||||
"version": "1.0.0-rc.3",
|
||||
"version": "1.0.0-rc.5",
|
||||
"lockfileVersion": 1,
|
||||
"requires": true,
|
||||
"dependencies": {
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "tmagic-playground",
|
||||
"version": "1.0.0-rc.3",
|
||||
"version": "1.0.0-rc.5",
|
||||
"private": true,
|
||||
"scripts": {
|
||||
"dev": "vite --mode vue3",
|
||||
@@ -11,11 +11,11 @@
|
||||
},
|
||||
"dependencies": {
|
||||
"@element-plus/icons": "0.0.11",
|
||||
"@tmagic/editor": "^1.0.0-rc.3",
|
||||
"@tmagic/form": "^1.0.0-rc.3",
|
||||
"@tmagic/schema": "^1.0.0-rc.3",
|
||||
"@tmagic/stage": "^1.0.0-rc.3",
|
||||
"@tmagic/utils": "^1.0.0-rc.3",
|
||||
"@tmagic/editor": "^1.0.0-rc.5",
|
||||
"@tmagic/form": "^1.0.0-rc.5",
|
||||
"@tmagic/schema": "^1.0.0-rc.5",
|
||||
"@tmagic/stage": "^1.0.0-rc.5",
|
||||
"@tmagic/utils": "^1.0.0-rc.5",
|
||||
"element-plus": "^2.2.0",
|
||||
"monaco-editor": "^0.32.1",
|
||||
"serialize-javascript": "^6.0.0",
|
||||
|
||||
2
runtime/react/package-lock.json
generated
2
runtime/react/package-lock.json
generated
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "runtime-react",
|
||||
"version": "1.0.0-rc.3",
|
||||
"version": "1.0.0-rc.5",
|
||||
"lockfileVersion": 1,
|
||||
"requires": true,
|
||||
"dependencies": {
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "runtime-react",
|
||||
"version": "1.0.0-rc.3",
|
||||
"version": "1.0.0-rc.5",
|
||||
"private": true,
|
||||
"scripts": {
|
||||
"dev:react": "npm run build && npm run serve",
|
||||
@@ -9,8 +9,8 @@
|
||||
"serve": "vite preview --port 8076"
|
||||
},
|
||||
"dependencies": {
|
||||
"@tmagic/schema": "^1.0.0-rc.3",
|
||||
"@tmagic/stage": "^1.0.0-rc.3",
|
||||
"@tmagic/schema": "^1.0.0-rc.5",
|
||||
"@tmagic/stage": "^1.0.0-rc.5",
|
||||
"react": "^17.0.2",
|
||||
"react-dom": "^17.0.2"
|
||||
},
|
||||
|
||||
2
runtime/vue2/package-lock.json
generated
2
runtime/vue2/package-lock.json
generated
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "runtime-vue2",
|
||||
"version": "1.0.0-rc.3",
|
||||
"version": "1.0.0-rc.5",
|
||||
"lockfileVersion": 1,
|
||||
"requires": true,
|
||||
"dependencies": {
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "runtime-vue2",
|
||||
"version": "1.0.0-rc.3",
|
||||
"version": "1.0.0-rc.5",
|
||||
"private": true,
|
||||
"scripts": {
|
||||
"dev:vue2": "npm run build && npm run serve",
|
||||
@@ -9,8 +9,8 @@
|
||||
"serve": "vite preview --port 8077"
|
||||
},
|
||||
"dependencies": {
|
||||
"@tmagic/schema": "^1.0.0-rc.3",
|
||||
"@tmagic/stage": "^1.0.0-rc.3",
|
||||
"@tmagic/schema": "^1.0.0-rc.5",
|
||||
"@tmagic/stage": "^1.0.0-rc.5",
|
||||
"@vue/composition-api": "1.0.5",
|
||||
"vue": "^2.6.14"
|
||||
},
|
||||
|
||||
2
runtime/vue3/package-lock.json
generated
2
runtime/vue3/package-lock.json
generated
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "runtime-vue3",
|
||||
"version": "1.0.0-rc.3",
|
||||
"version": "1.0.0-rc.5",
|
||||
"lockfileVersion": 1,
|
||||
"requires": true,
|
||||
"dependencies": {
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "runtime-vue3",
|
||||
"version": "1.0.0-rc.3",
|
||||
"version": "1.0.0-rc.5",
|
||||
"private": true,
|
||||
"scripts": {
|
||||
"dev": "npm run build && npm run serve",
|
||||
@@ -9,8 +9,8 @@
|
||||
"serve": "vite preview --port 8078"
|
||||
},
|
||||
"dependencies": {
|
||||
"@tmagic/schema": "^1.0.0-rc.3",
|
||||
"@tmagic/stage": "^1.0.0-rc.3",
|
||||
"@tmagic/schema": "^1.0.0-rc.5",
|
||||
"@tmagic/stage": "^1.0.0-rc.5",
|
||||
"axios": "^0.25.0",
|
||||
"vue": "^3.2.0"
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user