@tmagic/editor 1.8.0-beta.5 → 1.8.0-beta.7
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/dist/es/fields/CodeSelectCol.vue_vue_type_script_setup_true_lang.js +4 -1
- package/dist/es/fields/DataSourceFieldSelect/FieldSelect.vue_vue_type_script_setup_true_lang.js +8 -2
- package/dist/es/fields/DataSourceFields.vue_vue_type_script_setup_true_lang.js +25 -8
- package/dist/es/fields/DataSourceMethodSelect.vue_vue_type_script_setup_true_name_true_lang.js +6 -4
- package/dist/es/fields/DataSourceMethods.vue_vue_type_script_setup_true_lang.js +25 -12
- package/dist/es/fields/StyleSetter/components/Border.vue_vue_type_script_setup_true_lang.js +27 -5
- package/dist/es/index.js +2 -2
- package/dist/es/layouts/history-list/HistoryListPanel.vue_vue_type_script_setup_true_lang.js +10 -14
- package/dist/es/layouts/history-list/InitialRow.vue_vue_type_script_setup_true_lang.js +12 -4
- package/dist/es/layouts/history-list/composables.js +28 -77
- package/dist/es/layouts/sidebar/Sidebar.vue_vue_type_script_setup_true_lang.js +2 -2
- package/dist/es/layouts/sidebar/data-source/DataSourceConfigPanel.vue_vue_type_script_setup_true_lang.js +16 -3
- package/dist/es/layouts/sidebar/data-source/DataSourceListPanel.vue_vue_type_script_setup_true_lang.js +23 -1
- package/dist/es/services/codeBlock.js +30 -19
- package/dist/es/services/dataSource.js +29 -21
- package/dist/es/services/editor.js +52 -33
- package/dist/es/services/history.js +10 -15
- package/dist/es/style.css +4 -1
- package/dist/es/utils/data-source/index.js +2 -0
- package/dist/es/utils/editor.js +68 -48
- package/dist/es/utils/history.js +42 -33
- package/dist/style.css +4 -1
- package/dist/tmagic-editor.umd.cjs +412 -295
- package/package.json +7 -7
- package/src/fields/CodeSelectCol.vue +7 -1
- package/src/fields/DataSourceFieldSelect/FieldSelect.vue +16 -2
- package/src/fields/DataSourceFields.vue +37 -8
- package/src/fields/DataSourceMethodSelect.vue +9 -4
- package/src/fields/DataSourceMethods.vue +42 -21
- package/src/fields/StyleSetter/components/Border.vue +15 -6
- package/src/layouts/history-list/HistoryListPanel.vue +12 -25
- package/src/layouts/history-list/InitialRow.vue +3 -0
- package/src/layouts/history-list/composables.ts +34 -94
- package/src/layouts/sidebar/Sidebar.vue +2 -2
- package/src/layouts/sidebar/data-source/DataSourceConfigPanel.vue +31 -2
- package/src/layouts/sidebar/data-source/DataSourceListPanel.vue +26 -1
- package/src/services/codeBlock.ts +28 -22
- package/src/services/dataSource.ts +29 -24
- package/src/services/editor.ts +41 -37
- package/src/services/history.ts +19 -25
- package/src/theme/style-setter/border.scss +4 -1
- package/src/type.ts +38 -26
- package/src/utils/data-source/index.ts +2 -0
- package/src/utils/editor.ts +125 -59
- package/src/utils/history.ts +48 -45
- package/types/index.d.ts +109 -112
package/dist/es/utils/editor.js
CHANGED
|
@@ -74,12 +74,26 @@ var getMiddleTop = (node, parentNode, stage) => {
|
|
|
74
74
|
}
|
|
75
75
|
return (Math.min(parentHeight, wrapperHeightDeal) - height) / 2;
|
|
76
76
|
};
|
|
77
|
+
var removeConflictPosition = (style, primary, secondary) => {
|
|
78
|
+
const isInvalid = (value) => value === "" || value === 0 || value === void 0 || value === null;
|
|
79
|
+
if (!(primary in style) || !(secondary in style)) return;
|
|
80
|
+
const primaryValue = style[primary];
|
|
81
|
+
const secondaryValue = style[secondary];
|
|
82
|
+
const primaryInvalid = isInvalid(primaryValue);
|
|
83
|
+
const secondaryInvalid = isInvalid(secondaryValue);
|
|
84
|
+
if (primaryInvalid && !secondaryInvalid) delete style[primary];
|
|
85
|
+
else if (secondaryInvalid && !primaryInvalid) delete style[secondary];
|
|
86
|
+
else if (primaryInvalid && secondaryInvalid) if (secondaryValue === 0 && primaryValue !== 0) delete style[primary];
|
|
87
|
+
else delete style[secondary];
|
|
88
|
+
};
|
|
77
89
|
var getInitPositionStyle = (style = {}, layout) => {
|
|
78
90
|
if (layout === Layout.ABSOLUTE) {
|
|
79
91
|
const newStyle = {
|
|
80
92
|
...style,
|
|
81
93
|
position: "absolute"
|
|
82
94
|
};
|
|
95
|
+
removeConflictPosition(newStyle, "left", "right");
|
|
96
|
+
removeConflictPosition(newStyle, "top", "bottom");
|
|
83
97
|
if (typeof newStyle.left === "undefined" && typeof newStyle.right === "undefined") newStyle.left = 0;
|
|
84
98
|
return newStyle;
|
|
85
99
|
}
|
|
@@ -104,58 +118,63 @@ var setLayout = (node, layout) => {
|
|
|
104
118
|
}
|
|
105
119
|
return node;
|
|
106
120
|
};
|
|
107
|
-
var
|
|
121
|
+
var hasPositionValue = (style, key) => typeof style?.[key] !== "undefined" && style?.[key] !== "";
|
|
122
|
+
/**
|
|
123
|
+
* 沿节点路径累加(或抵消)某一方向上的定位偏移量
|
|
124
|
+
* 当路径上的祖先使用了反方向定位(例如计算 left 时祖先用了 right)或非数值定位时,
|
|
125
|
+
* 无法简单地通过求和换算坐标,此时返回 0 表示放弃补偿、保持原值
|
|
126
|
+
* @param path 从根到目标节点的路径(含节点自身)
|
|
127
|
+
* @param dir 需要累加的定位方向
|
|
128
|
+
* @param opposite 反方向定位属性
|
|
129
|
+
* @param sign change2Fixed 取 1(累加祖先偏移),Fixed2Other 取 -1(抵消祖先偏移)
|
|
130
|
+
* @param init 偏移量初始值
|
|
131
|
+
*/
|
|
132
|
+
var accumulatePositionOffset = (path, dir, opposite, sign, init = 0) => {
|
|
133
|
+
let offset = init;
|
|
134
|
+
for (const value of path) {
|
|
135
|
+
if (hasPositionValue(value.style, opposite) || !isNumber(value.style?.[dir] || 0)) return 0;
|
|
136
|
+
offset = offset + sign * Number(value.style?.[dir] || 0);
|
|
137
|
+
}
|
|
138
|
+
return offset;
|
|
139
|
+
};
|
|
140
|
+
var change2Fixed = (node, path) => {
|
|
108
141
|
const style = { ...node.style || {} };
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
left
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
if (value.style?.right || !isNumber(value.style?.left || 0)) {
|
|
116
|
-
offset.left = 0;
|
|
117
|
-
break;
|
|
118
|
-
}
|
|
119
|
-
offset.left = offset.left + Number(value.style?.left || 0);
|
|
142
|
+
if (!hasPositionValue(node.style, "right") && isNumber(node.style?.left || 0)) {
|
|
143
|
+
const left = accumulatePositionOffset(path, "left", "right", 1);
|
|
144
|
+
if (left) style.left = left;
|
|
145
|
+
} else if (hasPositionValue(node.style, "right") && isNumber(node.style?.right || 0)) {
|
|
146
|
+
const right = accumulatePositionOffset(path, "right", "left", 1);
|
|
147
|
+
if (right) style.right = right;
|
|
120
148
|
}
|
|
121
|
-
if (!node.style
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
149
|
+
if (!hasPositionValue(node.style, "bottom") && isNumber(node.style?.top || 0)) {
|
|
150
|
+
const top = accumulatePositionOffset(path, "top", "bottom", 1);
|
|
151
|
+
if (top) style.top = top;
|
|
152
|
+
} else if (hasPositionValue(node.style, "bottom") && isNumber(node.style?.bottom || 0)) {
|
|
153
|
+
const bottom = accumulatePositionOffset(path, "bottom", "top", 1);
|
|
154
|
+
if (bottom) style.bottom = bottom;
|
|
127
155
|
}
|
|
128
|
-
if (offset.left) style.left = offset.left;
|
|
129
|
-
if (offset.top) style.top = offset.top;
|
|
130
156
|
return style;
|
|
131
157
|
};
|
|
132
|
-
var Fixed2Other = async (node,
|
|
133
|
-
const path = getNodePath(node.id, root.items);
|
|
158
|
+
var Fixed2Other = async (node, path, getLayout) => {
|
|
134
159
|
const cur = path.pop();
|
|
135
160
|
const offset = {
|
|
136
|
-
left:
|
|
137
|
-
top:
|
|
161
|
+
left: 0,
|
|
162
|
+
top: 0,
|
|
163
|
+
right: 0,
|
|
164
|
+
bottom: 0
|
|
138
165
|
};
|
|
139
|
-
if (!node.style
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
}
|
|
144
|
-
offset.left = offset.left - Number(value.style?.left || 0);
|
|
145
|
-
}
|
|
146
|
-
if (!node.style?.bottom && isNumber(node.style?.top || 0)) for (const value of path) {
|
|
147
|
-
if (value.style?.bottom || !isNumber(value.style?.top || 0)) {
|
|
148
|
-
offset.top = 0;
|
|
149
|
-
break;
|
|
150
|
-
}
|
|
151
|
-
offset.top = offset.top - Number(value.style?.top || 0);
|
|
152
|
-
}
|
|
166
|
+
if (!hasPositionValue(node.style, "right") && isNumber(node.style?.left || 0)) offset.left = accumulatePositionOffset(path, "left", "right", -1, Number(cur?.style?.left || 0));
|
|
167
|
+
else if (hasPositionValue(node.style, "right") && isNumber(node.style?.right || 0)) offset.right = accumulatePositionOffset(path, "right", "left", -1, Number(cur?.style?.right || 0));
|
|
168
|
+
if (!hasPositionValue(node.style, "bottom") && isNumber(node.style?.top || 0)) offset.top = accumulatePositionOffset(path, "top", "bottom", -1, Number(cur?.style?.top || 0));
|
|
169
|
+
else if (hasPositionValue(node.style, "bottom") && isNumber(node.style?.bottom || 0)) offset.bottom = accumulatePositionOffset(path, "bottom", "top", -1, Number(cur?.style?.bottom || 0));
|
|
153
170
|
const style = node.style || {};
|
|
154
171
|
const parent = path.pop();
|
|
155
172
|
if (!parent) return getRelativeStyle(style);
|
|
156
173
|
if (await getLayout(parent) !== Layout.RELATIVE) {
|
|
157
174
|
if (offset.left) style.left = offset.left;
|
|
158
175
|
if (offset.top) style.top = offset.top;
|
|
176
|
+
if (offset.right) style.right = offset.right;
|
|
177
|
+
if (offset.bottom) style.bottom = offset.bottom;
|
|
159
178
|
return {
|
|
160
179
|
...style,
|
|
161
180
|
position: "absolute"
|
|
@@ -187,11 +206,11 @@ var fixNodeLeft = (config, parent, doc) => {
|
|
|
187
206
|
};
|
|
188
207
|
var fixNodePosition = (config, parent, stage) => {
|
|
189
208
|
if (config.style?.position !== "absolute") return config.style;
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
209
|
+
const style = { ...config.style || {} };
|
|
210
|
+
const baseStyle = config.style || {};
|
|
211
|
+
if (!("right" in baseStyle)) style.left = fixNodeLeft(config, parent, stage?.renderer?.contentWindow?.document);
|
|
212
|
+
if (!("top" in baseStyle) && !("bottom" in baseStyle)) style.top = getMiddleTop(config, parent, stage);
|
|
213
|
+
return style;
|
|
195
214
|
};
|
|
196
215
|
var serializeConfig = (config) => serialize(config, {
|
|
197
216
|
space: 2,
|
|
@@ -268,13 +287,14 @@ var buildChangeRecords = (value, basePath) => {
|
|
|
268
287
|
var resolveSelectedNode = (config, getNodeInfoFn, rootId) => {
|
|
269
288
|
const id = typeof config === "string" || typeof config === "number" ? config : config.id;
|
|
270
289
|
if (!id) throw new Error("没有ID,无法选中");
|
|
271
|
-
const { node, parent, page } = getNodeInfoFn(id);
|
|
290
|
+
const { node, parent, page, path } = getNodeInfoFn(id);
|
|
272
291
|
if (!node) throw new Error("获取不到组件信息");
|
|
273
292
|
if (node.id === rootId) throw new Error("不能选根节点");
|
|
274
293
|
return {
|
|
275
294
|
node,
|
|
276
295
|
parent,
|
|
277
|
-
page
|
|
296
|
+
page,
|
|
297
|
+
path
|
|
278
298
|
};
|
|
279
299
|
};
|
|
280
300
|
/**
|
|
@@ -286,11 +306,11 @@ var resolveSelectedNode = (config, getNodeInfoFn, rootId) => {
|
|
|
286
306
|
* @param getLayoutFn 获取父节点布局方式的回调函数
|
|
287
307
|
* @returns 处理后的节点配置(深拷贝)
|
|
288
308
|
*/
|
|
289
|
-
var toggleFixedPosition = async (dist, src,
|
|
309
|
+
var toggleFixedPosition = async (dist, src, path, getLayoutFn) => {
|
|
290
310
|
const newConfig = cloneDeep$1(dist);
|
|
291
311
|
if (!isPop(src) && newConfig.style?.position) {
|
|
292
|
-
if (isFixed(newConfig.style) && !isFixed(src.style || {})) newConfig.style = change2Fixed(newConfig,
|
|
293
|
-
else if (!isFixed(newConfig.style) && isFixed(src.style || {})) newConfig.style = await Fixed2Other(newConfig,
|
|
312
|
+
if (isFixed(newConfig.style) && !isFixed(src.style || {})) newConfig.style = change2Fixed(newConfig, path);
|
|
313
|
+
else if (!isFixed(newConfig.style) && isFixed(src.style || {})) newConfig.style = await Fixed2Other(newConfig, path, getLayoutFn);
|
|
294
314
|
}
|
|
295
315
|
return newConfig;
|
|
296
316
|
};
|
package/dist/es/utils/history.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { UndoRedo } from "./undo-redo.js";
|
|
2
2
|
import { guid } from "@tmagic/utils";
|
|
3
3
|
import { cloneDeep } from "lodash-es";
|
|
4
|
+
import serialize from "serialize-javascript";
|
|
4
5
|
//#region packages/editor/src/utils/history.ts
|
|
5
6
|
/**
|
|
6
7
|
* 「回滚」生成的新 step 简短描述。代码块 / 数据源共用。
|
|
@@ -66,46 +67,29 @@ var markStackSaved = (undoRedo) => {
|
|
|
66
67
|
};
|
|
67
68
|
/**
|
|
68
69
|
* 把单个「按 id 分栈」的历史栈(代码块 / 数据源)拆成若干 group:
|
|
69
|
-
*
|
|
70
|
-
* - 连续 'update' 合并到同一组,组内 steps 顺序就是发生顺序。
|
|
70
|
+
* 每条操作记录独立成组,不做相邻 update 合并(与页面历史的合并策略不同)。
|
|
71
71
|
*
|
|
72
72
|
* 代码块与数据源除 `kind` 外结构完全一致,统一由本方法处理;`kind` 决定返回的具体分组类型。
|
|
73
73
|
*/
|
|
74
74
|
var mergeStackSteps = (kind, id, list, cursor) => {
|
|
75
|
-
const groups = [];
|
|
76
|
-
let current = null;
|
|
77
75
|
const currentIndex = cursor - 1;
|
|
78
|
-
list.
|
|
79
|
-
const { opType } = step;
|
|
76
|
+
return list.map((step, index) => {
|
|
80
77
|
const applied = index < cursor;
|
|
81
78
|
const isCurrent = index === currentIndex;
|
|
82
|
-
|
|
83
|
-
|
|
79
|
+
return {
|
|
80
|
+
kind,
|
|
81
|
+
id,
|
|
82
|
+
opType: step.opType,
|
|
83
|
+
steps: [{
|
|
84
84
|
step,
|
|
85
85
|
index,
|
|
86
86
|
applied,
|
|
87
87
|
isCurrent
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
}
|
|
92
|
-
current = {
|
|
93
|
-
kind,
|
|
94
|
-
id,
|
|
95
|
-
opType,
|
|
96
|
-
steps: [{
|
|
97
|
-
step,
|
|
98
|
-
index,
|
|
99
|
-
applied,
|
|
100
|
-
isCurrent
|
|
101
|
-
}],
|
|
102
|
-
applied,
|
|
103
|
-
isCurrent
|
|
104
|
-
};
|
|
105
|
-
groups.push(current);
|
|
106
|
-
}
|
|
88
|
+
}],
|
|
89
|
+
applied,
|
|
90
|
+
isCurrent
|
|
91
|
+
};
|
|
107
92
|
});
|
|
108
|
-
return groups;
|
|
109
93
|
};
|
|
110
94
|
/**
|
|
111
95
|
* 把页面栈拆成若干 group:
|
|
@@ -186,22 +170,45 @@ var detectPageTargetName = (step) => {
|
|
|
186
170
|
return items?.length ? `${items.length} 个节点` : void 0;
|
|
187
171
|
}
|
|
188
172
|
};
|
|
189
|
-
/**
|
|
173
|
+
/**
|
|
174
|
+
* 把 `Record<Id, UndoRedo>` 整体序列化为 `Record<Id, SerializedUndoRedo>`。
|
|
175
|
+
*
|
|
176
|
+
* 序列化(深克隆)的同一趟里,只把每条 step 中可能含函数的 `diff` 用 serialize-javascript 序列化成字符串,
|
|
177
|
+
* 其余字段(uuid / opType / timestamp / `modifiedNodeIds` Map 等)原样保留,交给 IndexedDB 结构化克隆。
|
|
178
|
+
* 这样既能写入函数,又避免序列化整份快照的开销;读取时再由 {@link parseStacksStepDiff} 还原 diff。
|
|
179
|
+
* 不含 `diff` 的元素(如通用栈)原样透传。
|
|
180
|
+
*/
|
|
190
181
|
var serializeStacks = (stacks) => {
|
|
191
182
|
const result = {};
|
|
192
183
|
Object.entries(stacks).forEach(([id, undoRedo]) => {
|
|
193
|
-
if (undoRedo)
|
|
184
|
+
if (!undoRedo) return;
|
|
185
|
+
const serialized = undoRedo.serialize();
|
|
186
|
+
result[id] = {
|
|
187
|
+
...serialized,
|
|
188
|
+
elementList: serialized.elementList.map((step) => step.diff === void 0 ? step : Object.assign({}, step, { diff: serialize(step.diff) }))
|
|
189
|
+
};
|
|
194
190
|
});
|
|
195
191
|
return result;
|
|
196
192
|
};
|
|
197
193
|
/**
|
|
198
194
|
* 把 `Record<Id, SerializedUndoRedo>` 整体还原为 `Record<Id, UndoRedo>`。
|
|
199
195
|
* 还原时把每个栈的游标定位到最近一条已保存(`saved === true`)记录之后。
|
|
196
|
+
*
|
|
197
|
+
* 与 {@link serializeStacks} 相反:当传入 `parse`(parseDSL)时,把每条 step 中以字符串形式存储的 `diff`
|
|
198
|
+
* 解析回真实对象(含函数);不含 `diff` 的元素(如通用栈)原样透传。
|
|
200
199
|
*/
|
|
201
|
-
var deserializeStacks = (stacks = {}) => {
|
|
200
|
+
var deserializeStacks = (stacks = {}, parse) => {
|
|
202
201
|
const result = {};
|
|
203
202
|
Object.entries(stacks).forEach(([id, serialized]) => {
|
|
204
|
-
if (serialized)
|
|
203
|
+
if (!serialized) return;
|
|
204
|
+
const elementList = parse ? serialized.elementList.map((step) => {
|
|
205
|
+
const { diff } = step;
|
|
206
|
+
return typeof diff === "string" ? Object.assign({}, step, { diff: parse(`(${diff})`) }) : step;
|
|
207
|
+
}) : serialized.elementList;
|
|
208
|
+
result[id] = UndoRedo.fromSerialized({
|
|
209
|
+
...serialized,
|
|
210
|
+
elementList
|
|
211
|
+
}, { isSavedStep: (element) => element.saved === true });
|
|
205
212
|
});
|
|
206
213
|
return result;
|
|
207
214
|
};
|
|
@@ -219,5 +226,7 @@ var getOrCreateStack = (stacks, id) => {
|
|
|
219
226
|
var undoFloor = (undoRedo) => {
|
|
220
227
|
return undoRedo.getElementList()[0]?.opType === "initial" ? 1 : 0;
|
|
221
228
|
};
|
|
229
|
+
/** 将单次 push 产生的 history uuid(或 null)转为 *AndGetHistoryId 返回用的 uuid 列表。 */
|
|
230
|
+
var getLastPushedHistoryIds = (historyId) => historyId ? [historyId] : [];
|
|
222
231
|
//#endregion
|
|
223
|
-
export { createStackStep, describeRevertStep, deserializeStacks, detectPageTargetId, detectPageTargetName, detectStackOpType, getOrCreateStack, markStackSaved, mergePageSteps, mergeStackSteps, serializeStacks, undoFloor };
|
|
232
|
+
export { createStackStep, describeRevertStep, deserializeStacks, detectPageTargetId, detectPageTargetName, detectStackOpType, getLastPushedHistoryIds, getOrCreateStack, markStackSaved, mergePageSteps, mergeStackSteps, serializeStacks, undoFloor };
|
package/dist/style.css
CHANGED
|
@@ -2093,9 +2093,12 @@ fieldset.m-fieldset .m-form-tip {
|
|
|
2093
2093
|
.border-box-container .border-icon-container .border-icon + .border-icon {
|
|
2094
2094
|
margin-left: 8px;
|
|
2095
2095
|
}
|
|
2096
|
+
.border-box-container .border-icon-container .border-icon.configured {
|
|
2097
|
+
border-color: var(--el-color-success, var(--td-success-color, #2ba471));
|
|
2098
|
+
}
|
|
2096
2099
|
.border-box-container .border-icon-container .border-icon.active {
|
|
2097
2100
|
border-width: 1px;
|
|
2098
|
-
border-color: var(--el-color-primary);
|
|
2101
|
+
border-color: var(--el-color-primary, var(--td-brand-color, #0052d9));
|
|
2099
2102
|
}
|
|
2100
2103
|
.border-box-container .border-icon-container .border-icon.border-icon-top {
|
|
2101
2104
|
border-top-width: 2px;
|