@tmagic/editor 1.0.0-beta.11 → 1.0.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.
@@ -1,8 +1,8 @@
1
1
  (function (global, factory) {
2
- typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('vue'), require('serialize-javascript'), require('monaco-editor'), require('@element-plus/icons'), require('@tmagic/schema'), require('lodash-es'), require('@tmagic/utils'), require('events'), require('@tmagic/core'), require('element-plus'), require('@tmagic/stage')) :
3
- typeof define === 'function' && define.amd ? define(['exports', 'vue', 'serialize-javascript', 'monaco-editor', '@element-plus/icons', '@tmagic/schema', 'lodash-es', '@tmagic/utils', 'events', '@tmagic/core', 'element-plus', '@tmagic/stage'], factory) :
4
- (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.TMagicEditor = {}, global.vue, global.serialize, global.monaco, global.icons, global.schema, global.lodashEs, global.utils, global.events, global.core, global.elementPlus, global.StageCore));
5
- })(this, (function (exports, vue, serialize, monaco, icons, schema, lodashEs, utils, events, core, elementPlus, StageCore) { 'use strict';
2
+ typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('vue'), require('serialize-javascript'), require('monaco-editor'), require('@element-plus/icons'), require('@tmagic/schema'), require('lodash-es'), require('@tmagic/utils'), require('events'), require('@tmagic/core'), require('element-plus'), require('keycon'), require('@tmagic/stage')) :
3
+ typeof define === 'function' && define.amd ? define(['exports', 'vue', 'serialize-javascript', 'monaco-editor', '@element-plus/icons', '@tmagic/schema', 'lodash-es', '@tmagic/utils', 'events', '@tmagic/core', 'element-plus', 'keycon', '@tmagic/stage'], factory) :
4
+ (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.TMagicEditor = {}, global.vue, global.serialize, global.monaco, global.icons, global.schema, global.lodashEs, global.utils, global.events, global.core, global.elementPlus, global.KeyController, global.StageCore));
5
+ })(this, (function (exports, vue, serialize, monaco, icons, schema, lodashEs, utils, events, core, elementPlus, KeyController, StageCore) { 'use strict';
6
6
 
7
7
  function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
8
8
 
@@ -26,6 +26,7 @@
26
26
 
27
27
  var serialize__default = /*#__PURE__*/_interopDefaultLegacy(serialize);
28
28
  var monaco__namespace = /*#__PURE__*/_interopNamespace(monaco);
29
+ var KeyController__default = /*#__PURE__*/_interopDefaultLegacy(KeyController);
29
30
  var StageCore__default = /*#__PURE__*/_interopDefaultLegacy(StageCore);
30
31
 
31
32
  var _export_sfc = (sfc, props) => {
@@ -627,7 +628,7 @@
627
628
  setPropsValue(type, value) {
628
629
  this.state.propsValueMap[type] = value;
629
630
  }
630
- async getPropsValue(type) {
631
+ async getPropsValue(type, defaultValue = {}) {
631
632
  if (type === "area") {
632
633
  const value = await this.getPropsValue("button");
633
634
  value.className = "action-area";
@@ -639,6 +640,7 @@
639
640
  }
640
641
  return lodashEs.cloneDeep({
641
642
  ...getDefaultPropsValue(type),
643
+ ...defaultValue,
642
644
  ...this.state.propsValueMap[type] || {}
643
645
  });
644
646
  }
@@ -700,7 +702,7 @@
700
702
  };
701
703
  const setNewItemId = (config, parent) => {
702
704
  const oldId = config.id;
703
- config.id = generateId(config.type);
705
+ config.id = generateId(config.type || "component");
704
706
  config.name = `${config.name?.replace(/_(\d+)$/, "")}_${config.id}`;
705
707
  if (utils.isPop(config) && parent?.type === schema.NodeType.PAGE) {
706
708
  updatePopId(oldId, config.id, parent);
@@ -723,11 +725,25 @@
723
725
  };
724
726
  return node;
725
727
  };
726
- const initPosition = (node, layout) => {
728
+ const setTop2Middle = (node, parentNode, stage) => {
729
+ const style = node.style || {};
730
+ const height = style.height || 0;
731
+ if (!stage || style.top || !parentNode.style || !utils.isNumber(height))
732
+ return style;
733
+ const { height: parentHeight } = parentNode.style;
734
+ if (utils.isPage(parentNode)) {
735
+ const { scrollTop = 0, wrapperHeight } = stage.mask;
736
+ style.top = (wrapperHeight - height) / 2 + scrollTop;
737
+ } else {
738
+ style.top = (parentHeight - height) / 2;
739
+ }
740
+ return style;
741
+ };
742
+ const initPosition = (node, layout, parentNode, stage) => {
727
743
  if (layout === Layout.ABSOLUTE) {
728
744
  node.style = {
729
745
  position: "absolute",
730
- ...node.style || {}
746
+ ...setTop2Middle(node, parentNode, stage)
731
747
  };
732
748
  return node;
733
749
  }
@@ -774,7 +790,9 @@
774
790
  const cur = path.pop();
775
791
  const offset = {
776
792
  left: cur?.style?.left || 0,
777
- top: cur?.style?.top || 0
793
+ top: cur?.style?.top || 0,
794
+ right: "",
795
+ bottom: ""
778
796
  };
779
797
  path.forEach((value) => {
780
798
  offset.left = offset.left - globalThis.parseFloat(value.style?.left || 0);
@@ -919,7 +937,7 @@
919
937
  if (!parentNode)
920
938
  throw new Error("\u672A\u627E\u5230\u7236\u5143\u7D20");
921
939
  const layout = await this.getLayout(parentNode);
922
- const newNode = initPosition({ ...vue.toRaw(await propsService.getPropsValue(type)), ...config2 }, layout);
940
+ const newNode = initPosition({ ...vue.toRaw(await propsService.getPropsValue(type, config2)) }, layout, parentNode, this.get("stage"));
923
941
  if ((parentNode?.type === schema.NodeType.ROOT || curNode.type === schema.NodeType.ROOT) && newNode.type !== schema.NodeType.PAGE) {
924
942
  throw new Error("app\u4E0B\u4E0D\u80FD\u6DFB\u52A0\u7EC4\u4EF6");
925
943
  }
@@ -1344,7 +1362,7 @@
1344
1362
  type: "select",
1345
1363
  options: (mForm, { model }) => {
1346
1364
  const node = editorService.getNodeById(model.to);
1347
- if (!node)
1365
+ if (!node?.type)
1348
1366
  return [];
1349
1367
  return eventsService.getMethod(node.type).map((option) => ({
1350
1368
  text: option.label,
@@ -3067,9 +3085,9 @@
3067
3085
  curFormConfig.value = [];
3068
3086
  return;
3069
3087
  }
3070
- values.value = node.value;
3071
3088
  const type = node.value.type || (node.value.items ? "container" : "text");
3072
3089
  curFormConfig.value = await services?.propsService.getPropsConfig(type) || [];
3090
+ values.value = node.value;
3073
3091
  };
3074
3092
  vue.watchEffect(init);
3075
3093
  services?.propsService.on("props-configs-change", init);
@@ -3127,11 +3145,11 @@
3127
3145
  searchText,
3128
3146
  collapseValue,
3129
3147
  list,
3130
- appendComponent({ text, type, ...config }) {
3148
+ appendComponent({ text, type, data = {} }) {
3131
3149
  services?.editorService.add({
3132
3150
  name: text,
3133
3151
  type,
3134
- ...config
3152
+ ...data
3135
3153
  });
3136
3154
  }
3137
3155
  };
@@ -3221,7 +3239,8 @@
3221
3239
  append(config) {
3222
3240
  services?.editorService.add({
3223
3241
  name: config.text,
3224
- type: config.type
3242
+ type: config.type,
3243
+ ...config.data || {}
3225
3244
  });
3226
3245
  },
3227
3246
  remove() {
@@ -4366,12 +4385,48 @@
4366
4385
  },
4367
4386
  setup() {
4368
4387
  const services = vue.inject("services");
4388
+ const workspace = vue.ref();
4389
+ const node = vue.computed(() => services?.editorService.get("node"));
4390
+ let keycon;
4391
+ const mouseenterHandler = () => {
4392
+ workspace.value?.focus();
4393
+ };
4394
+ const mouseleaveHandler = () => {
4395
+ workspace.value?.blur();
4396
+ };
4397
+ vue.onMounted(() => {
4398
+ workspace.value?.addEventListener("mouseenter", mouseenterHandler);
4399
+ workspace.value?.addEventListener("mouseleave", mouseleaveHandler);
4400
+ keycon = new KeyController__default["default"](workspace.value);
4401
+ keycon.keyup("delete", () => {
4402
+ node.value && services?.editorService.remove(node.value);
4403
+ }).keyup(["ctrl", "c"], () => {
4404
+ node.value && services?.editorService.copy(node.value);
4405
+ }).keyup(["ctrl", "v"], () => {
4406
+ node.value && services?.editorService.paste();
4407
+ }).keyup(["ctrl", "x"], () => {
4408
+ if (node.value && services) {
4409
+ services.editorService.copy(node.value);
4410
+ services.editorService.remove(node.value);
4411
+ }
4412
+ });
4413
+ });
4414
+ vue.onUnmounted(() => {
4415
+ workspace.value?.removeEventListener("mouseenter", mouseenterHandler);
4416
+ workspace.value?.removeEventListener("mouseleave", mouseleaveHandler);
4417
+ keycon.destroy();
4418
+ });
4369
4419
  return {
4420
+ workspace,
4370
4421
  page: vue.computed(() => services?.editorService.get("page"))
4371
4422
  };
4372
4423
  }
4373
4424
  });
4374
- const _hoisted_1 = { class: "m-editor-workspace" };
4425
+ const _hoisted_1 = {
4426
+ class: "m-editor-workspace",
4427
+ tabindex: "1",
4428
+ ref: "workspace"
4429
+ };
4375
4430
  function _sfc_render$1(_ctx, _cache, $props, $setup, $data, $options) {
4376
4431
  const _component_magic_stage = vue.resolveComponent("magic-stage");
4377
4432
  const _component_page_bar = vue.resolveComponent("page-bar");
@@ -4393,7 +4448,7 @@
4393
4448
  ]),
4394
4449
  _: 3
4395
4450
  })
4396
- ]);
4451
+ ], 512);
4397
4452
  }
4398
4453
  var Workspace = /* @__PURE__ */ _export_sfc(_sfc_main$1, [["render", _sfc_render$1]]);
4399
4454