@tmagic/editor 1.1.0-beta.2 → 1.1.0-beta.3

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.
@@ -3,9 +3,9 @@ import serialize from 'serialize-javascript';
3
3
  import { Delete, Pointer, Close, Plus, Edit, ArrowDown, Grid, ScaleToOriginal, ZoomOut, ZoomIn, Right, Back, Files, DocumentCopy, Coin, ArrowLeftBold, ArrowRightBold, CaretBottom, Top, Bottom } from '@element-plus/icons-vue';
4
4
  import { throttle, cloneDeep, mergeWith, random } from 'lodash-es';
5
5
  import * as monaco from 'monaco-editor';
6
- import StageCore, { GHOST_EL_ID_PREFIX, GuidesType, getOffset, calcValueByFontsize, CONTAINER_HIGHLIGHT_CLASS } from '@tmagic/stage';
6
+ import StageCore, { GuidesType, getOffset, calcValueByFontsize, CONTAINER_HIGHLIGHT_CLASS } from '@tmagic/stage';
7
7
  import { NodeType } from '@tmagic/schema';
8
- import { toLine, isPop, getNodePath, isNumber, isPage, removeClassNameByClassName, addClassName } from '@tmagic/utils';
8
+ import { toLine, isPop, getNodePath, isNumber, isPage, removeClassNameByClassName } from '@tmagic/utils';
9
9
  import { EventEmitter } from 'events';
10
10
  import { DEFAULT_EVENTS, DEFAULT_METHODS } from '@tmagic/core';
11
11
  import Gesto from 'gesto';
@@ -461,17 +461,12 @@ const doAction = async (args, scope, sourceMethod, beforeMethodName, afterMethod
461
461
  try {
462
462
  let beforeArgs = args;
463
463
  for (const beforeMethod of scope.pluginOptionsList[beforeMethodName]) {
464
- let beforeReturnValue = await beforeMethod(...beforeArgs) || [];
465
- if (isError(beforeReturnValue))
466
- throw beforeReturnValue;
467
- if (!Array.isArray(beforeReturnValue)) {
468
- beforeReturnValue = [beforeReturnValue];
464
+ beforeArgs = await beforeMethod(...beforeArgs) || [];
465
+ if (isError(beforeArgs))
466
+ throw beforeArgs;
467
+ if (!Array.isArray(beforeArgs)) {
468
+ beforeArgs = [beforeArgs];
469
469
  }
470
- beforeArgs = beforeArgs.map((v, index) => {
471
- if (typeof beforeReturnValue[index] === "undefined")
472
- return v;
473
- return beforeReturnValue[index];
474
- });
475
470
  }
476
471
  let returnValue = await fn(beforeArgs, sourceMethod.bind(scope));
477
472
  for (const afterMethod of scope.pluginOptionsList[afterMethodName]) {
@@ -861,23 +856,13 @@ const fixNodeLeft = (config, parent, doc) => {
861
856
  return config.style?.left;
862
857
  const el = doc.getElementById(`${config.id}`);
863
858
  const parentEl = doc.getElementById(`${parent.id}`);
864
- if (el && parentEl && el.offsetWidth + config.style?.left > parentEl.offsetWidth) {
859
+ const left = Number(config.style?.left) || 0;
860
+ if (el && parentEl && el.offsetWidth + left > parentEl.offsetWidth) {
865
861
  return parentEl.offsetWidth - el.offsetWidth;
866
862
  }
867
863
  return config.style.left;
868
864
  };
869
865
 
870
- const log = (...args) => {
871
- };
872
- const info = (...args) => {
873
- };
874
- const warn = (...args) => {
875
- };
876
- const debug = (...args) => {
877
- };
878
- const error = (...args) => {
879
- };
880
-
881
866
  class Editor$1 extends BaseService {
882
867
  constructor() {
883
868
  super([
@@ -1039,7 +1024,7 @@ class Editor$1 extends BaseService {
1039
1024
  parentNode?.items?.push(newNode);
1040
1025
  const stage = this.get("stage");
1041
1026
  const root = this.get("root");
1042
- await stage?.add({ config: cloneDeep(newNode), root: cloneDeep(root) });
1027
+ await stage?.add({ config: cloneDeep(newNode), parent: cloneDeep(parentNode), root: cloneDeep(root) });
1043
1028
  if (layout === Layout.ABSOLUTE) {
1044
1029
  const fixedLeft = fixNodeLeft(newNode, parentNode, stage?.renderer.contentWindow?.document);
1045
1030
  if (typeof fixedLeft !== "undefined") {
@@ -1624,6 +1609,17 @@ const getDefaultPropsValue = (type, id) => ["page", "container"].includes(type)
1624
1609
  name: type
1625
1610
  };
1626
1611
 
1612
+ const log = (...args) => {
1613
+ };
1614
+ const info = (...args) => {
1615
+ };
1616
+ const warn = (...args) => {
1617
+ };
1618
+ const debug = (...args) => {
1619
+ };
1620
+ const error = (...args) => {
1621
+ };
1622
+
1627
1623
  const _sfc_main$i = defineComponent({
1628
1624
  components: { Plus },
1629
1625
  setup() {
@@ -2289,20 +2285,9 @@ const _sfc_main$b = defineComponent({
2289
2285
  }
2290
2286
  return;
2291
2287
  }
2292
- if (timeout)
2288
+ if (timeout || !stage.value)
2293
2289
  return;
2294
- timeout = globalThis.setTimeout(async () => {
2295
- if (!stageOptions || !stage.value)
2296
- return;
2297
- const doc = stage.value.renderer.contentWindow?.document;
2298
- const els = stage.value.getElementsFromPoint(e);
2299
- for (const el of els) {
2300
- if (doc && !el.id.startsWith(GHOST_EL_ID_PREFIX) && await stageOptions.isContainer(el)) {
2301
- addClassName(el, doc, stageOptions?.containerHighlightClassName);
2302
- break;
2303
- }
2304
- }
2305
- }, stageOptions?.containerHighlightDuration);
2290
+ timeout = stage.value.getAddContainerHighlightClassNameTimeout(e);
2306
2291
  }
2307
2292
  };
2308
2293
  }