@tmagic/editor 1.1.0-beta.11 → 1.1.0-beta.12

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.
@@ -879,6 +879,7 @@ class Props extends BaseService {
879
879
  "getPropsValue",
880
880
  "createId",
881
881
  "setNewItemId",
882
+ "fillConfig",
882
883
  "getDefaultPropsValue"
883
884
  ]);
884
885
  }
@@ -888,14 +889,17 @@ class Props extends BaseService {
888
889
  });
889
890
  this.emit("props-configs-change");
890
891
  }
891
- setPropsConfig(type, config) {
892
- this.state.propsConfigMap[type] = fillConfig(Array.isArray(config) ? config : [config]);
892
+ async fillConfig(config) {
893
+ return fillConfig(config);
894
+ }
895
+ async setPropsConfig(type, config) {
896
+ this.state.propsConfigMap[type] = await this.fillConfig(Array.isArray(config) ? config : [config]);
893
897
  }
894
898
  async getPropsConfig(type) {
895
899
  if (type === "area") {
896
900
  return await this.getPropsConfig("button");
897
901
  }
898
- return cloneDeep(this.state.propsConfigMap[type] || DEFAULT_CONFIG);
902
+ return cloneDeep(this.state.propsConfigMap[type] || await this.fillConfig([]));
899
903
  }
900
904
  setPropsValues(values) {
901
905
  Object.keys(values).forEach((type) => {
@@ -929,25 +933,14 @@ class Props extends BaseService {
929
933
  ...mergeWith({}, cloneDeep(this.state.propsValueMap[type] || {}), data)
930
934
  };
931
935
  }
932
- guid(digit = 8) {
933
- return "x".repeat(digit).replace(/[xy]/g, (c) => {
934
- const r = Math.random() * 16 | 0;
935
- const v = c == "x" ? r : r & 3 | 8;
936
- return v.toString(16);
937
- });
938
- }
939
936
  async createId(type) {
940
937
  return `${type}_${this.guid()}`;
941
938
  }
942
- async setNewItemId(config, parent) {
943
- const oldId = config.id;
939
+ async setNewItemId(config) {
944
940
  config.id = await this.createId(config.type || "component");
945
- if (isPop(config) && parent?.type === NodeType.PAGE) {
946
- updatePopId(oldId, config.id, parent);
947
- }
948
941
  if (config.items && Array.isArray(config.items)) {
949
942
  for (const item of config.items) {
950
- await this.setNewItemId(item, config);
943
+ await this.setNewItemId(item);
951
944
  }
952
945
  }
953
946
  return config;
@@ -965,22 +958,14 @@ class Props extends BaseService {
965
958
  name: type
966
959
  };
967
960
  }
961
+ guid(digit = 8) {
962
+ return "x".repeat(digit).replace(/[xy]/g, (c) => {
963
+ const r = Math.random() * 16 | 0;
964
+ const v = c === "x" ? r : r & 3 | 8;
965
+ return v.toString(16);
966
+ });
967
+ }
968
968
  }
969
- const updatePopId = (oldId, popId, pageConfig) => {
970
- pageConfig.items?.forEach((config) => {
971
- if (config.pop === oldId) {
972
- config.pop = popId;
973
- return;
974
- }
975
- if (config.popId === oldId) {
976
- config.popId = popId;
977
- return;
978
- }
979
- if (Array.isArray(config.items)) {
980
- updatePopId(oldId, popId, config);
981
- }
982
- });
983
- };
984
969
  const propsService = new Props();
985
970
 
986
971
  const beforePaste = async (position, config) => {
@@ -1000,7 +985,7 @@ const beforePaste = async (position, config) => {
1000
985
  if (pastePosition.top && configItem.style?.top) {
1001
986
  pastePosition.top = configItem.style?.top - referenceTop + pastePosition.top;
1002
987
  }
1003
- const pasteConfig = await propsService.setNewItemId(configItem, editorService.get("root"));
988
+ const pasteConfig = await propsService.setNewItemId(configItem);
1004
989
  if (pasteConfig.style) {
1005
990
  const { left, top } = pasteConfig.style;
1006
991
  if (typeof left === "number" || !!left && !isNaN(Number(left))) {
@@ -1071,6 +1056,7 @@ class Editor$1 extends BaseService {
1071
1056
  "sort",
1072
1057
  "copy",
1073
1058
  "paste",
1059
+ "doPaste",
1074
1060
  "duAlignCenter",
1075
1061
  "alignCenter",
1076
1062
  "moveLayer",
@@ -1252,7 +1238,7 @@ class Editor$1 extends BaseService {
1252
1238
  }
1253
1239
  this.pushHistoryState();
1254
1240
  this.emit("add", newNodes);
1255
- return newNodes.length > 1 ? newNodes[0] : newNodes;
1241
+ return Array.isArray(addNode) ? newNodes : newNodes[0];
1256
1242
  }
1257
1243
  async doRemove(node) {
1258
1244
  const root = this.get("root");
@@ -1346,7 +1332,7 @@ class Editor$1 extends BaseService {
1346
1332
  const newNodes = await Promise.all(nodes.map((node) => this.doUpdate(node)));
1347
1333
  this.pushHistoryState();
1348
1334
  this.emit("update", newNodes);
1349
- return newNodes.length > 1 ? newNodes[0] : newNodes;
1335
+ return Array.isArray(config) ? newNodes : newNodes[0];
1350
1336
  }
1351
1337
  async sort(id1, id2) {
1352
1338
  const node = this.get("node");
@@ -1375,9 +1361,13 @@ class Editor$1 extends BaseService {
1375
1361
  const config = await storageService.getItem(COPY_STORAGE_KEY);
1376
1362
  if (!Array.isArray(config))
1377
1363
  return;
1378
- const pasteConfigs = await beforePaste(position, config);
1364
+ const pasteConfigs = await this.doPaste(config, position);
1379
1365
  return this.add(pasteConfigs);
1380
1366
  }
1367
+ async doPaste(config, position = {}) {
1368
+ const pasteConfigs = await beforePaste(position, cloneDeep(config));
1369
+ return pasteConfigs;
1370
+ }
1381
1371
  async doAlignCenter(config) {
1382
1372
  const parent = this.getParentById(config.id);
1383
1373
  if (!parent)
@@ -1422,11 +1412,14 @@ class Editor$1 extends BaseService {
1422
1412
  } else {
1423
1413
  brothers.splice(index + parseInt(`${offset}`, 10), 0, brothers.splice(index, 1)[0]);
1424
1414
  }
1415
+ const grandparent = this.getParentById(parent.id);
1425
1416
  this.get("stage")?.update({
1426
1417
  config: cloneDeep(toRaw(parent)),
1427
- parentId: parent.id,
1418
+ parentId: grandparent?.id,
1428
1419
  root: cloneDeep(this.get("root"))
1429
1420
  });
1421
+ this.addModifiedNodeId(parent.id);
1422
+ this.pushHistoryState();
1430
1423
  }
1431
1424
  async moveToContainer(config, targetId) {
1432
1425
  const { node, parent } = this.getNodeInfo(config.id, false);
@@ -1446,7 +1439,8 @@ class Editor$1 extends BaseService {
1446
1439
  newConfig.style = getInitPositionStyle(newConfig.style, layout);
1447
1440
  target.items.push(newConfig);
1448
1441
  await stage.select(targetId);
1449
- await stage.update({ config: cloneDeep(target), parentId: parent.id, root });
1442
+ const targetParent = this.getParentById(target.id);
1443
+ await stage.update({ config: cloneDeep(target), parentId: targetParent?.id, root });
1450
1444
  await this.select(newConfig);
1451
1445
  stage.select(newConfig.id);
1452
1446
  this.addModifiedNodeId(target.id);
@@ -1809,7 +1803,6 @@ const fillConfig = (config = []) => [
1809
1803
  ]
1810
1804
  }
1811
1805
  ];
1812
- const DEFAULT_CONFIG = fillConfig([]);
1813
1806
 
1814
1807
  const log = (...args) => {
1815
1808
  if (process.env.NODE_ENV === "development") {
@@ -3346,7 +3339,7 @@ const _sfc_main$5 = /* @__PURE__ */ defineComponent({
3346
3339
  content: item.name
3347
3340
  }, {
3348
3341
  default: withCtx(() => [
3349
- createElementVNode("span", null, toDisplayString(item.name), 1)
3342
+ createElementVNode("span", null, toDisplayString(item.name || item.id), 1)
3350
3343
  ]),
3351
3344
  _: 2
3352
3345
  }, 1032, ["content"])
@@ -4080,9 +4073,11 @@ function _sfc_render$1(_ctx, _cache, $props, $setup, $data, $options) {
4080
4073
  const _component_magic_stage = resolveComponent("magic-stage");
4081
4074
  const _component_page_bar = resolveComponent("page-bar");
4082
4075
  return openBlock(), createElementBlock("div", _hoisted_1, [
4083
- (openBlock(), createBlock(_component_magic_stage, {
4084
- key: _ctx.page?.id
4085
- })),
4076
+ renderSlot(_ctx.$slots, "stage", {}, () => [
4077
+ (openBlock(), createBlock(_component_magic_stage, {
4078
+ key: _ctx.page?.id
4079
+ }))
4080
+ ]),
4086
4081
  renderSlot(_ctx.$slots, "workspace-content"),
4087
4082
  createVNode(_component_page_bar, null, {
4088
4083
  "page-bar-title": withCtx(({ page }) => [
@@ -4415,6 +4410,9 @@ function _sfc_render(_ctx, _cache, $props, $setup, $data, $options) {
4415
4410
  workspace: withCtx(() => [
4416
4411
  renderSlot(_ctx.$slots, "workspace", { editorService: _ctx.editorService }, () => [
4417
4412
  createVNode(_component_workspace, null, {
4413
+ stage: withCtx(() => [
4414
+ renderSlot(_ctx.$slots, "stage")
4415
+ ]),
4418
4416
  "workspace-content": withCtx(() => [
4419
4417
  renderSlot(_ctx.$slots, "workspace-content", { editorService: _ctx.editorService })
4420
4418
  ]),
@@ -4465,5 +4463,5 @@ const index = {
4465
4463
  }
4466
4464
  };
4467
4465
 
4468
- export { COPY_STORAGE_KEY, ComponentListPanel, DEFAULT_CONFIG, Fixed2Other, H_GUIDE_LINE_STORAGE_KEY, Keys, LayerOffset, LayerPanel, Layout, PropsPanel, CodeEditor as TMagicCodeEditor, Editor as TMagicEditor, _sfc_main$f as ToolButton, V_GUIDE_LINE_STORAGE_KEY, change2Fixed, debug, index as default, editorService, error, eventsService, fillConfig, fixNodeLeft, fixNodePosition, generatePageName, generatePageNameByApp, getConfig, getGuideLineFromCache, getInitPositionStyle, getNodeIndex, getPageList, getPageNameList, getRelativeStyle, historyService, info, isFixed, log, propsService, setConfig, setLayout, storageService, uiService, warn };
4466
+ export { COPY_STORAGE_KEY, ComponentListPanel, Fixed2Other, H_GUIDE_LINE_STORAGE_KEY, Keys, LayerOffset, LayerPanel, Layout, PropsPanel, CodeEditor as TMagicCodeEditor, Editor as TMagicEditor, _sfc_main$f as ToolButton, V_GUIDE_LINE_STORAGE_KEY, change2Fixed, debug, index as default, editorService, error, eventsService, fillConfig, fixNodeLeft, fixNodePosition, generatePageName, generatePageNameByApp, getConfig, getGuideLineFromCache, getInitPositionStyle, getNodeIndex, getPageList, getPageNameList, getRelativeStyle, historyService, info, isFixed, log, propsService, setConfig, setLayout, storageService, uiService, warn };
4469
4467
  //# sourceMappingURL=tmagic-editor.mjs.map