@flowgram.ai/free-layout-core 0.2.8 → 0.2.9

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/esm/index.js CHANGED
@@ -1535,7 +1535,11 @@ import { customAlphabet } from "nanoid";
1535
1535
  import { inject as inject5, injectable as injectable5, optional, postConstruct } from "inversify";
1536
1536
  import { Emitter as Emitter4 } from "@flowgram.ai/utils";
1537
1537
  import { NodeEngineContext } from "@flowgram.ai/form-core";
1538
- import { FlowDocument, FlowNodeBaseType, FlowNodeTransformData as FlowNodeTransformData5 } from "@flowgram.ai/document";
1538
+ import {
1539
+ FlowDocument,
1540
+ FlowNodeBaseType,
1541
+ FlowNodeTransformData as FlowNodeTransformData5
1542
+ } from "@flowgram.ai/document";
1539
1543
  import {
1540
1544
  injectPlaygroundContext,
1541
1545
  PlaygroundConfigEntity as PlaygroundConfigEntity4,
@@ -1778,7 +1782,6 @@ var WorkflowDocument = class extends FlowDocument {
1778
1782
  parent
1779
1783
  },
1780
1784
  void 0,
1781
- true,
1782
1785
  true
1783
1786
  );
1784
1787
  const registry = node.getNodeRegistry();
@@ -1883,6 +1886,64 @@ var WorkflowDocument = class extends FlowDocument {
1883
1886
  }
1884
1887
  return node;
1885
1888
  }
1889
+ /**
1890
+ * 添加节点,如果节点已经存在则不会重复创建
1891
+ * @param data
1892
+ * @param addedNodes
1893
+ */
1894
+ addNode(data, addedNodes, ignoreCreateAndUpdateEvent) {
1895
+ const { id, type = "block", originParent, parent, meta, hidden, index } = data;
1896
+ let node = this.getNode(id);
1897
+ let isNew = false;
1898
+ const register = this.getNodeRegistry(type, data.originParent);
1899
+ if (node && node.flowNodeType !== data.type) {
1900
+ node.dispose();
1901
+ node = void 0;
1902
+ }
1903
+ if (!node) {
1904
+ const { dataRegistries } = register;
1905
+ node = this.entityManager.createEntity(WorkflowNodeEntity, {
1906
+ id,
1907
+ document: this,
1908
+ flowNodeType: type,
1909
+ originParent,
1910
+ meta
1911
+ });
1912
+ const datas = dataRegistries ? this.nodeDataRegistries.concat(...dataRegistries) : this.nodeDataRegistries;
1913
+ node.addInitializeData(datas);
1914
+ node.onDispose(() => this.onNodeDisposeEmitter.fire({ node }));
1915
+ this.options.fromNodeJSON?.(node, data, true);
1916
+ isNew = true;
1917
+ } else {
1918
+ this.options.fromNodeJSON?.(node, data, false);
1919
+ }
1920
+ node.initData({
1921
+ originParent,
1922
+ parent,
1923
+ meta,
1924
+ hidden,
1925
+ index
1926
+ });
1927
+ addedNodes?.push(node);
1928
+ if (register.onCreate) {
1929
+ const extendNodes = register.onCreate(node, data);
1930
+ if (extendNodes && addedNodes) {
1931
+ addedNodes.push(...extendNodes);
1932
+ }
1933
+ }
1934
+ if (!ignoreCreateAndUpdateEvent) {
1935
+ if (isNew) {
1936
+ this.onNodeCreateEmitter.fire({
1937
+ node,
1938
+ data,
1939
+ json: data
1940
+ });
1941
+ } else {
1942
+ this.onNodeUpdateEmitter.fire({ node, data, json: data });
1943
+ }
1944
+ }
1945
+ return node;
1946
+ }
1886
1947
  get layout() {
1887
1948
  const layout = this.layouts.find((layout2) => layout2.name == this.currentLayoutKey);
1888
1949
  if (!layout) {