@tmagic/editor 1.3.0-alpha.0 → 1.3.0-alpha.2

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.
@@ -8,7 +8,7 @@ import { createValues, MFormDialog, MForm } from '@tmagic/form';
8
8
  import { MagicTable } from '@tmagic/table';
9
9
  import * as monaco from 'monaco-editor';
10
10
  import Gesto from 'gesto';
11
- import { isPop, getNodePath, isNumber, isPage, toLine, guid, datetimeFormatter, removeClassNameByClassName } from '@tmagic/utils';
11
+ import { isPop, getNodePath, isNumber, isPage, toLine, guid, datetimeFormatter, removeClassNameByClassName, getNodes } from '@tmagic/utils';
12
12
  import KeyController from 'keycon';
13
13
  import StageCore, { GuidesType, getOffset, calcValueByFontsize, CONTAINER_HIGHLIGHT_CLASS_NAME, ContainerHighlightType } from '@tmagic/stage';
14
14
  import { EventEmitter } from 'events';
@@ -450,7 +450,7 @@ const _sfc_main$y = /* @__PURE__ */ defineComponent({
450
450
  {
451
451
  validator: ({ value, callback }, { model, parent }) => {
452
452
  const index = parent.findIndex((item) => item.name === value);
453
- if (model.index === -1 && index > -1 || model.index > -1 && index !== model.index) {
453
+ if (model.index === -1 && index > -1 || model.index > -1 && index > -1 && index !== model.index) {
454
454
  return callback(`属性key(${value})已存在`);
455
455
  }
456
456
  callback();
@@ -7089,6 +7089,7 @@ class Watcher extends EventEmitter {
7089
7089
  });
7090
7090
  });
7091
7091
  });
7092
+ this.emit("collected", nodes, deep);
7092
7093
  }
7093
7094
  /**
7094
7095
  * 清除依赖
@@ -7117,6 +7118,7 @@ class Watcher extends EventEmitter {
7117
7118
  const fullKey = prop ? `${prop}.${key}` : key;
7118
7119
  if (target.isTarget(key, value)) {
7119
7120
  target.updateDep(node, fullKey);
7121
+ this.emit("update-dep", node, fullKey);
7120
7122
  } else if (!keyIsItems && Array.isArray(value)) {
7121
7123
  value.forEach((item, index) => {
7122
7124
  collectTarget(item, `${fullKey}.${index}`);
@@ -7391,6 +7393,42 @@ const initServiceState = (props, {
7391
7393
  });
7392
7394
  };
7393
7395
  const initServiceEvents = (props, emit, { editorService, codeBlockService, dataSourceService, depService }) => {
7396
+ const getApp = () => {
7397
+ const stage = editorService.get("stage");
7398
+ return stage?.renderer.runtime?.getApp?.();
7399
+ };
7400
+ const updateDataSoucreSchema = () => {
7401
+ const root = editorService.get("root");
7402
+ if (root?.dataSources) {
7403
+ getApp()?.dataSourceManager?.updateSchema(root.dataSources);
7404
+ }
7405
+ };
7406
+ const upateNodeWhenDataSourceChange = (nodes) => {
7407
+ const root = editorService.get("root");
7408
+ const stage = editorService.get("stage");
7409
+ if (!root || !stage)
7410
+ return;
7411
+ const app = getApp();
7412
+ if (!app)
7413
+ return;
7414
+ if (app.dsl) {
7415
+ app.dsl.dataSourceDeps = root.dataSourceDeps;
7416
+ app.dsl.dataSources = root.dataSources;
7417
+ }
7418
+ updateDataSoucreSchema();
7419
+ nodes.forEach((node) => {
7420
+ const deps = Object.values(root.dataSourceDeps || {});
7421
+ deps.forEach((dep) => {
7422
+ if (dep[node.id]) {
7423
+ stage.update({
7424
+ config: cloneDeep(node),
7425
+ parentId: editorService.getParentById(node.id)?.id,
7426
+ root: cloneDeep(root)
7427
+ });
7428
+ }
7429
+ });
7430
+ });
7431
+ };
7394
7432
  const targetAddHandler = (target) => {
7395
7433
  if (target.type !== "data-source")
7396
7434
  return;
@@ -7408,8 +7446,16 @@ const initServiceEvents = (props, emit, { editorService, codeBlockService, dataS
7408
7446
  return;
7409
7447
  delete root.dataSourceDeps[id];
7410
7448
  };
7449
+ const depUpdateHandler = (node) => {
7450
+ upateNodeWhenDataSourceChange([node]);
7451
+ };
7452
+ const collectedHandler = (nodes) => {
7453
+ upateNodeWhenDataSourceChange(nodes);
7454
+ };
7411
7455
  depService.on("add-target", targetAddHandler);
7412
7456
  depService.on("remove-target", targetRemoveHandler);
7457
+ depService.on("dep-update", depUpdateHandler);
7458
+ depService.on("collected", collectedHandler);
7413
7459
  const rootChangeHandler = async (value, preValue) => {
7414
7460
  const nodeId = editorService.get("node")?.id || props.defaultSelected;
7415
7461
  let node;
@@ -7477,14 +7523,20 @@ const initServiceEvents = (props, emit, { editorService, codeBlockService, dataS
7477
7523
  codeBlockService.on("remove", codeBlockRemoveHandler);
7478
7524
  const dataSourceAddHandler = (config) => {
7479
7525
  depService.addTarget(createDataSourceTarget(config.id, config));
7526
+ getApp()?.dataSourceManager?.addDataSource(config);
7480
7527
  };
7481
7528
  const dataSourceUpdateHandler = (config) => {
7482
7529
  if (config.title) {
7483
7530
  depService.getTarget(config.id).name = config.title;
7484
7531
  }
7532
+ const root = editorService.get("root");
7533
+ const targets = depService.getTargets("data-source");
7534
+ const nodes = getNodes(Object.keys(targets[config.id].deps), root?.items);
7535
+ upateNodeWhenDataSourceChange(nodes);
7485
7536
  };
7486
7537
  const dataSourceRemoveHandler = (id) => {
7487
7538
  depService.removeTarget(id);
7539
+ getApp()?.dataSourceManager?.removeDataSource(id);
7488
7540
  };
7489
7541
  dataSourceService.on("add", dataSourceAddHandler);
7490
7542
  dataSourceService.on("update", dataSourceUpdateHandler);
@@ -7492,6 +7544,8 @@ const initServiceEvents = (props, emit, { editorService, codeBlockService, dataS
7492
7544
  onUnmounted(() => {
7493
7545
  depService.off("add-target", targetAddHandler);
7494
7546
  depService.off("remove-target", targetRemoveHandler);
7547
+ depService.off("dep-update", depUpdateHandler);
7548
+ depService.off("collected", collectedHandler);
7495
7549
  editorService.off("history-change", historyChangeHandler);
7496
7550
  editorService.off("root-change", rootChangeHandler);
7497
7551
  editorService.off("add", nodeAddHandler);
@@ -7664,5 +7718,5 @@ const index = {
7664
7718
  }
7665
7719
  };
7666
7720
 
7667
- export { CODE_DRAFT_STORAGE_KEY, COPY_STORAGE_KEY, _sfc_main$g as CodeBlockList, CodeDeleteErrorType, _sfc_main$B as CodeSelect, _sfc_main$z as CodeSelectCol, ColumnLayout, _sfc_main$d as ComponentListPanel, _sfc_main$c as ContentMenu, _sfc_main$y as DataSourceFields, _sfc_main$x as EventSelect, Fixed2Other, H_GUIDE_LINE_STORAGE_KEY, _sfc_main$A as Icon, _sfc_main$w as KeyValue, Keys, LayerOffset, _sfc_main$a as LayerPanel, Layout, _sfc_main$s as LayoutContainer, _sfc_main$n as PropsPanel, _sfc_main$u as TMagicCodeEditor, Editor as TMagicEditor, _sfc_main$p as ToolButton, V_GUIDE_LINE_STORAGE_KEY, beforePaste, change2Fixed, codeBlockService, debug, index as default, depService, editorService, error, eventsService, fillConfig$1 as fillConfig, fixNodeLeft, fixNodePosition, generatePageName, generatePageNameByApp, getAddParent, getConfig, getDefaultConfig, getGuideLineFromCache, getInitPositionStyle, getNodeIndex, getPageList, getPageNameList, getPositionInContainer, getRelativeStyle, historyService, info, isFixed, log, propsService, serializeConfig, setConfig, setLayout, storageService, uiService, useStage, warn };
7721
+ export { CODE_DRAFT_STORAGE_KEY, COPY_STORAGE_KEY, _sfc_main$g as CodeBlockList, CodeDeleteErrorType, _sfc_main$B as CodeSelect, _sfc_main$z as CodeSelectCol, ColumnLayout, _sfc_main$d as ComponentListPanel, _sfc_main$c as ContentMenu, _sfc_main$y as DataSourceFields, _sfc_main$x as EventSelect, Fixed2Other, H_GUIDE_LINE_STORAGE_KEY, _sfc_main$A as Icon, _sfc_main$w as KeyValue, Keys, LayerOffset, _sfc_main$a as LayerPanel, Layout, _sfc_main$s as LayoutContainer, _sfc_main$n as PropsPanel, _sfc_main$u as TMagicCodeEditor, Editor as TMagicEditor, _sfc_main$p as ToolButton, V_GUIDE_LINE_STORAGE_KEY, beforePaste, change2Fixed, codeBlockService, dataSourceService, debug, index as default, depService, editorService, error, eventsService, fillConfig$1 as fillConfig, fixNodeLeft, fixNodePosition, generatePageName, generatePageNameByApp, getAddParent, getConfig, getDefaultConfig, getGuideLineFromCache, getInitPositionStyle, getNodeIndex, getPageList, getPageNameList, getPositionInContainer, getRelativeStyle, historyService, info, isFixed, log, propsService, serializeConfig, setConfig, setLayout, storageService, uiService, useStage, warn };
7668
7722
  //# sourceMappingURL=tmagic-editor.js.map