@inditextech/weave-sdk 0.40.0 → 0.40.1

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/sdk.cjs CHANGED
@@ -15548,7 +15548,6 @@ var WeaveStore = class {
15548
15548
  this.getState().weave
15549
15549
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
15550
15550
  );
15551
- console.log(`User: ${this.config.getUser().id}`);
15552
15551
  if (weaveStateValues) {
15553
15552
  this.undoManager = new yjs.UndoManager([weaveStateValues], {
15554
15553
  captureTimeout: 250,
@@ -15578,6 +15577,7 @@ var WeaveStore = class {
15578
15577
  }
15579
15578
  (0, __syncedstore_core.observeDeep)(this.getState(), () => {
15580
15579
  const newState = JSON.parse(JSON.stringify(this.getState()));
15580
+ this.logger.info({ newState }, "State changed");
15581
15581
  this.instance.emitEvent("onStateChange", newState);
15582
15582
  const nodesSelectionPlugin = this.instance.getPlugin("nodesSelection");
15583
15583
  if (this.isRoomLoaded && nodesSelectionPlugin && nodesSelectionPlugin.getSelectedNodes().length === 1) {
@@ -18419,156 +18419,159 @@ var WeaveStateManager = class {
18419
18419
  return this.findNodeById(state, nodeKey);
18420
18420
  }
18421
18421
  addNode(node, parentId = "mainLayer", index = void 0) {
18422
- const userId = this.instance.getStore().getUser().id;
18423
- this.instance.getStore().getDocument().transact(() => {
18424
- const state = this.instance.getStore().getState();
18425
- if ((0, import_lodash.isEmpty)(state.weave)) {
18426
- const msg = `State is empty, cannot add the node`;
18427
- this.logger.warn({
18428
- node,
18429
- parentId
18430
- }, msg);
18431
- return;
18432
- }
18433
- const { node: nodeState } = this.findNodeById(state.weave, node.key);
18434
- if (nodeState) {
18435
- const msg = `Node with key [${node.key}] already exists, cannot add it`;
18436
- this.logger.warn({
18437
- node,
18438
- parentId
18439
- }, msg);
18440
- return;
18441
- }
18442
- const { node: parent } = this.findNodeById(state.weave, parentId);
18443
- if (!parent) {
18444
- const msg = `Parent container with key [${node.key}] doesn't exists, cannot add it`;
18445
- this.logger.warn({
18446
- node,
18447
- parentId
18448
- }, msg);
18449
- return;
18450
- }
18451
- if (!parent.props.children || typeof parent.props.children === "undefined") parent.props.children = [];
18452
- if (index) {
18453
- let parentChildren = JSON.parse(JSON.stringify([...parent.props.children]));
18454
- parentChildren.splice(index, 0, node);
18455
- parentChildren = parentChildren.map((actNode, index$1) => {
18456
- return {
18457
- ...actNode,
18458
- props: {
18459
- ...actNode.props,
18460
- zIndex: index$1
18461
- }
18462
- };
18463
- });
18464
- parent.props.children = parentChildren;
18465
- } else {
18466
- const childrenAmount = parent.props.children.length;
18467
- const finalNode = {
18468
- ...node,
18422
+ const state = this.instance.getStore().getState();
18423
+ this.logger.info({ state: JSON.parse(JSON.stringify(state)) }, "State before addNode");
18424
+ if ((0, import_lodash.isEmpty)(state.weave)) {
18425
+ const msg = `State is empty, cannot add the node`;
18426
+ this.logger.warn({
18427
+ node,
18428
+ parentId
18429
+ }, msg);
18430
+ return;
18431
+ }
18432
+ const { node: nodeState } = this.findNodeById(state.weave, node.key);
18433
+ if (nodeState) {
18434
+ const msg = `Node with key [${node.key}] already exists, cannot add it`;
18435
+ this.logger.warn({
18436
+ node,
18437
+ parentId
18438
+ }, msg);
18439
+ return;
18440
+ }
18441
+ const { node: parent } = this.findNodeById(state.weave, parentId);
18442
+ if (!parent) {
18443
+ const msg = `Parent container with key [${node.key}] doesn't exists, cannot add it`;
18444
+ this.logger.warn({
18445
+ node,
18446
+ parentId
18447
+ }, msg);
18448
+ return;
18449
+ }
18450
+ this.logger.info({ parent: JSON.parse(JSON.stringify(parent)) }, "addNode: parent before init");
18451
+ let parentChildren = [];
18452
+ if (parent.props.children) parentChildren = JSON.parse(JSON.stringify(parent.props.children));
18453
+ this.logger.info({ parent: JSON.parse(JSON.stringify(parent)) }, "addNode: parent before add");
18454
+ if (index && parentChildren) {
18455
+ parentChildren.splice(index, 0, node);
18456
+ parentChildren = parentChildren.map((actNode, index$1) => {
18457
+ return {
18458
+ ...actNode,
18469
18459
  props: {
18470
- ...node.props,
18471
- zIndex: childrenAmount
18460
+ ...actNode.props,
18461
+ zIndex: index$1
18472
18462
  }
18473
18463
  };
18474
- parent.props.children.push(finalNode);
18475
- }
18476
- this.instance.emitEvent("onNodeAdded", node);
18477
- }, userId);
18464
+ });
18465
+ }
18466
+ if (!index && parent.props.children) {
18467
+ const childrenAmount = parent.props.children.length;
18468
+ let finalNode = JSON.parse(JSON.stringify(node));
18469
+ finalNode = {
18470
+ ...finalNode,
18471
+ props: {
18472
+ ...finalNode.props,
18473
+ zIndex: childrenAmount
18474
+ }
18475
+ };
18476
+ this.logger.info({ node: JSON.parse(JSON.stringify(finalNode)) }, "addNode: node to add");
18477
+ parentChildren.push(finalNode);
18478
+ }
18479
+ parent.props.children = parentChildren;
18480
+ this.logger.info({ parent: JSON.parse(JSON.stringify(parent)) }, "addNode: parent after add");
18481
+ this.instance.emitEvent("onNodeAdded", node);
18478
18482
  }
18479
18483
  updateNode(node) {
18480
- const userId = this.instance.getStore().getUser().id;
18481
- this.instance.getStore().getDocument().transact(() => {
18482
- const state = this.instance.getStore().getState();
18483
- if ((0, import_lodash.isEmpty)(state.weave)) {
18484
- const msg = `State is empty, cannot update the node`;
18485
- this.logger.warn({ node }, msg);
18486
- return;
18487
- }
18488
- const { node: nodeState } = this.findNodeById(state.weave, node.key);
18489
- if (!nodeState) {
18490
- const msg = `Node with key [${node.key}] doesn't exists, cannot update it`;
18491
- this.logger.warn({ node }, msg);
18492
- return;
18493
- }
18494
- const nodeNew = JSON.parse(JSON.stringify({
18495
- ...nodeState.props,
18496
- ...node.props
18497
- }));
18498
- nodeState.props = { ...nodeNew };
18499
- this.instance.emitEvent("onNodeUpdated", node);
18500
- }, userId);
18484
+ const state = this.instance.getStore().getState();
18485
+ this.logger.info({ state: JSON.parse(JSON.stringify(state)) }, "State before updateNode");
18486
+ if ((0, import_lodash.isEmpty)(state.weave)) {
18487
+ const msg = `State is empty, cannot update the node`;
18488
+ this.logger.warn({ node }, msg);
18489
+ return;
18490
+ }
18491
+ const { node: nodeState } = this.findNodeById(state.weave, node.key);
18492
+ if (!nodeState) {
18493
+ const msg = `Node with key [${node.key}] doesn't exists, cannot update it`;
18494
+ this.logger.warn({ node }, msg);
18495
+ return;
18496
+ }
18497
+ this.logger.info({ node: JSON.parse(JSON.stringify(nodeState)) }, "updateNode: before update");
18498
+ const nodeNew = JSON.parse(JSON.stringify({
18499
+ ...nodeState.props,
18500
+ ...node.props
18501
+ }));
18502
+ nodeState.props = { ...nodeNew };
18503
+ this.logger.info({ node: JSON.parse(JSON.stringify(nodeState)) }, "updateNode: after update");
18504
+ this.instance.emitEvent("onNodeUpdated", node);
18501
18505
  }
18502
18506
  removeNode(node) {
18503
- const userId = this.instance.getStore().getUser().id;
18504
- this.instance.getStore().getDocument().transact(() => {
18505
- const state = this.instance.getStore().getState();
18506
- if ((0, import_lodash.isEmpty)(state.weave)) {
18507
- const msg = `State is empty, cannot update the node`;
18508
- this.logger.warn({ node }, msg);
18509
- return;
18510
- }
18511
- const { node: nodeState, parent: parentState } = this.findNodeById(state.weave, node.key);
18512
- if (!nodeState) {
18513
- const msg = `Node with key [${node.key}] doesn't exists, cannot remove it`;
18514
- this.logger.warn({ node }, msg);
18515
- return;
18516
- }
18517
- if (parentState) {
18518
- const newChildren = JSON.parse(JSON.stringify(parentState.props.children));
18519
- const filteredChildren = newChildren.filter((actNode) => actNode.key !== node.key);
18520
- parentState.props.children = filteredChildren;
18521
- }
18522
- this.instance.emitEvent("onNodeRemoved", node);
18523
- }, userId);
18507
+ const state = this.instance.getStore().getState();
18508
+ this.logger.info({ stage: JSON.parse(JSON.stringify(state)) }, "State before removeNode");
18509
+ if ((0, import_lodash.isEmpty)(state.weave)) {
18510
+ const msg = `State is empty, cannot update the node`;
18511
+ this.logger.warn({ node }, msg);
18512
+ return;
18513
+ }
18514
+ const { node: nodeState, parent: parentState } = this.findNodeById(state.weave, node.key);
18515
+ if (!nodeState) {
18516
+ const msg = `Node with key [${node.key}] doesn't exists, cannot remove it`;
18517
+ this.logger.warn({ node }, msg);
18518
+ return;
18519
+ }
18520
+ this.logger.info({ key: node.key }, "removeNode: node to remove");
18521
+ this.logger.info({ parent: JSON.parse(JSON.stringify(parentState)) }, "removeNode: parent before remove");
18522
+ if (parentState && parentState.props.children) {
18523
+ const newChildren = JSON.parse(JSON.stringify(parentState.props.children));
18524
+ const filteredChildren = newChildren.filter((actNode) => actNode.key !== node.key);
18525
+ parentState.props.children = filteredChildren;
18526
+ this.logger.info({ parent: JSON.parse(JSON.stringify(parentState)) }, "removeNode: parent after remove");
18527
+ }
18528
+ this.instance.emitEvent("onNodeRemoved", node);
18524
18529
  }
18525
18530
  removeNodes(nodes) {
18526
18531
  for (const node of nodes) this.removeNode(node);
18527
18532
  }
18528
18533
  moveNode(node, position) {
18529
- const userId = this.instance.getStore().getUser().id;
18530
- this.instance.getStore().getDocument().transact(() => {
18531
- const state = this.instance.getStore().getState();
18532
- if ((0, import_lodash.isEmpty)(state.weave)) {
18533
- const msg = `State is empty, cannot update the node`;
18534
- this.logger.warn({ node }, msg);
18535
- return;
18536
- }
18537
- const { node: nodeState, parent: nodeParent } = this.findNodeById(state.weave, node.key);
18538
- if (!nodeState) {
18539
- const msg = `Node with key [${node.key}] doesn't exists, cannot update it`;
18540
- this.logger.warn({ node }, msg);
18541
- return;
18542
- }
18543
- if (nodeParent) {
18544
- let nodeParentNewChildren = JSON.parse(JSON.stringify([...nodeParent.props.children ?? []]));
18545
- const nodeNew = JSON.parse(JSON.stringify({ ...node }));
18546
- const childrenAmount = nodeParentNewChildren.length;
18547
- const nodeIndex = nodeParentNewChildren.findIndex((n) => n.key === nodeNew.key);
18548
- nodeParentNewChildren.splice(nodeIndex, 1);
18549
- if (position === __inditextech_weave_types.WEAVE_NODE_POSITION.UP) nodeParentNewChildren.splice(nodeIndex + 1, 0, nodeNew);
18550
- if (position === __inditextech_weave_types.WEAVE_NODE_POSITION.DOWN) nodeParentNewChildren.splice(nodeIndex - 1, 0, nodeNew);
18551
- if (position === __inditextech_weave_types.WEAVE_NODE_POSITION.FRONT) nodeParentNewChildren.splice(childrenAmount - 1, 0, nodeNew);
18552
- if (position === __inditextech_weave_types.WEAVE_NODE_POSITION.BACK) nodeParentNewChildren.splice(0, 0, nodeNew);
18553
- nodeParentNewChildren = nodeParentNewChildren.map((actNode, index) => {
18554
- return {
18555
- ...actNode,
18556
- props: {
18557
- ...actNode.props,
18558
- zIndex: index
18559
- }
18560
- };
18561
- });
18562
- if (!nodeParent.props.children) nodeParent.props.children = [];
18563
- nodeParent.props.children = nodeParentNewChildren;
18564
- }
18565
- }, userId);
18534
+ const state = this.instance.getStore().getState();
18535
+ if ((0, import_lodash.isEmpty)(state.weave)) {
18536
+ const msg = `State is empty, cannot update the node`;
18537
+ this.logger.warn({ node }, msg);
18538
+ return;
18539
+ }
18540
+ const { node: nodeState, parent: nodeParent } = this.findNodeById(state.weave, node.key);
18541
+ if (!nodeState) {
18542
+ const msg = `Node with key [${node.key}] doesn't exists, cannot update it`;
18543
+ this.logger.warn({ node }, msg);
18544
+ return;
18545
+ }
18546
+ if (nodeParent && nodeParent.props.children) {
18547
+ let nodeParentNewChildren = JSON.parse(JSON.stringify([...nodeParent.props.children ?? []]));
18548
+ const nodeNew = JSON.parse(JSON.stringify({ ...node }));
18549
+ const childrenAmount = nodeParentNewChildren.length;
18550
+ const nodeIndex = nodeParentNewChildren.findIndex((n) => n.key === nodeNew.key);
18551
+ nodeParentNewChildren.splice(nodeIndex, 1);
18552
+ if (position === __inditextech_weave_types.WEAVE_NODE_POSITION.UP) nodeParentNewChildren.splice(nodeIndex + 1, 0, nodeNew);
18553
+ if (position === __inditextech_weave_types.WEAVE_NODE_POSITION.DOWN) nodeParentNewChildren.splice(nodeIndex - 1, 0, nodeNew);
18554
+ if (position === __inditextech_weave_types.WEAVE_NODE_POSITION.FRONT) nodeParentNewChildren.splice(childrenAmount - 1, 0, nodeNew);
18555
+ if (position === __inditextech_weave_types.WEAVE_NODE_POSITION.BACK) nodeParentNewChildren.splice(0, 0, nodeNew);
18556
+ nodeParentNewChildren = nodeParentNewChildren.map((actNode, index) => {
18557
+ return {
18558
+ ...actNode,
18559
+ props: {
18560
+ ...actNode.props,
18561
+ zIndex: index
18562
+ }
18563
+ };
18564
+ });
18565
+ if (!nodeParent.props.children) nodeParent.props.children = [];
18566
+ nodeParent.props.children = nodeParentNewChildren;
18567
+ }
18566
18568
  }
18567
18569
  getElementsTree() {
18568
18570
  const state = this.instance.getStore().getState().weave;
18569
18571
  const jsonState = JSON.parse(JSON.stringify(state, null, 2));
18570
18572
  const mainLayer = jsonState.props?.children.find((node) => node.key === "mainLayer");
18571
18573
  if (!mainLayer) return [];
18574
+ if (!mainLayer.props?.children) return [];
18572
18575
  return mainLayer.props.children;
18573
18576
  }
18574
18577
  };
@@ -18646,7 +18649,7 @@ var WeaveRegisterManager = class {
18646
18649
 
18647
18650
  //#endregion
18648
18651
  //#region package.json
18649
- var version = "0.40.0";
18652
+ var version = "0.40.1";
18650
18653
 
18651
18654
  //#endregion
18652
18655
  //#region src/managers/setup.ts
package/dist/sdk.js CHANGED
@@ -15548,7 +15548,6 @@ var WeaveStore = class {
15548
15548
  this.getState().weave
15549
15549
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
15550
15550
  );
15551
- console.log(`User: ${this.config.getUser().id}`);
15552
15551
  if (weaveStateValues) {
15553
15552
  this.undoManager = new UndoManager([weaveStateValues], {
15554
15553
  captureTimeout: 250,
@@ -15578,6 +15577,7 @@ var WeaveStore = class {
15578
15577
  }
15579
15578
  observeDeep(this.getState(), () => {
15580
15579
  const newState = JSON.parse(JSON.stringify(this.getState()));
15580
+ this.logger.info({ newState }, "State changed");
15581
15581
  this.instance.emitEvent("onStateChange", newState);
15582
15582
  const nodesSelectionPlugin = this.instance.getPlugin("nodesSelection");
15583
15583
  if (this.isRoomLoaded && nodesSelectionPlugin && nodesSelectionPlugin.getSelectedNodes().length === 1) {
@@ -18419,156 +18419,159 @@ var WeaveStateManager = class {
18419
18419
  return this.findNodeById(state, nodeKey);
18420
18420
  }
18421
18421
  addNode(node, parentId = "mainLayer", index = void 0) {
18422
- const userId = this.instance.getStore().getUser().id;
18423
- this.instance.getStore().getDocument().transact(() => {
18424
- const state = this.instance.getStore().getState();
18425
- if ((0, import_lodash.isEmpty)(state.weave)) {
18426
- const msg = `State is empty, cannot add the node`;
18427
- this.logger.warn({
18428
- node,
18429
- parentId
18430
- }, msg);
18431
- return;
18432
- }
18433
- const { node: nodeState } = this.findNodeById(state.weave, node.key);
18434
- if (nodeState) {
18435
- const msg = `Node with key [${node.key}] already exists, cannot add it`;
18436
- this.logger.warn({
18437
- node,
18438
- parentId
18439
- }, msg);
18440
- return;
18441
- }
18442
- const { node: parent } = this.findNodeById(state.weave, parentId);
18443
- if (!parent) {
18444
- const msg = `Parent container with key [${node.key}] doesn't exists, cannot add it`;
18445
- this.logger.warn({
18446
- node,
18447
- parentId
18448
- }, msg);
18449
- return;
18450
- }
18451
- if (!parent.props.children || typeof parent.props.children === "undefined") parent.props.children = [];
18452
- if (index) {
18453
- let parentChildren = JSON.parse(JSON.stringify([...parent.props.children]));
18454
- parentChildren.splice(index, 0, node);
18455
- parentChildren = parentChildren.map((actNode, index$1) => {
18456
- return {
18457
- ...actNode,
18458
- props: {
18459
- ...actNode.props,
18460
- zIndex: index$1
18461
- }
18462
- };
18463
- });
18464
- parent.props.children = parentChildren;
18465
- } else {
18466
- const childrenAmount = parent.props.children.length;
18467
- const finalNode = {
18468
- ...node,
18422
+ const state = this.instance.getStore().getState();
18423
+ this.logger.info({ state: JSON.parse(JSON.stringify(state)) }, "State before addNode");
18424
+ if ((0, import_lodash.isEmpty)(state.weave)) {
18425
+ const msg = `State is empty, cannot add the node`;
18426
+ this.logger.warn({
18427
+ node,
18428
+ parentId
18429
+ }, msg);
18430
+ return;
18431
+ }
18432
+ const { node: nodeState } = this.findNodeById(state.weave, node.key);
18433
+ if (nodeState) {
18434
+ const msg = `Node with key [${node.key}] already exists, cannot add it`;
18435
+ this.logger.warn({
18436
+ node,
18437
+ parentId
18438
+ }, msg);
18439
+ return;
18440
+ }
18441
+ const { node: parent } = this.findNodeById(state.weave, parentId);
18442
+ if (!parent) {
18443
+ const msg = `Parent container with key [${node.key}] doesn't exists, cannot add it`;
18444
+ this.logger.warn({
18445
+ node,
18446
+ parentId
18447
+ }, msg);
18448
+ return;
18449
+ }
18450
+ this.logger.info({ parent: JSON.parse(JSON.stringify(parent)) }, "addNode: parent before init");
18451
+ let parentChildren = [];
18452
+ if (parent.props.children) parentChildren = JSON.parse(JSON.stringify(parent.props.children));
18453
+ this.logger.info({ parent: JSON.parse(JSON.stringify(parent)) }, "addNode: parent before add");
18454
+ if (index && parentChildren) {
18455
+ parentChildren.splice(index, 0, node);
18456
+ parentChildren = parentChildren.map((actNode, index$1) => {
18457
+ return {
18458
+ ...actNode,
18469
18459
  props: {
18470
- ...node.props,
18471
- zIndex: childrenAmount
18460
+ ...actNode.props,
18461
+ zIndex: index$1
18472
18462
  }
18473
18463
  };
18474
- parent.props.children.push(finalNode);
18475
- }
18476
- this.instance.emitEvent("onNodeAdded", node);
18477
- }, userId);
18464
+ });
18465
+ }
18466
+ if (!index && parent.props.children) {
18467
+ const childrenAmount = parent.props.children.length;
18468
+ let finalNode = JSON.parse(JSON.stringify(node));
18469
+ finalNode = {
18470
+ ...finalNode,
18471
+ props: {
18472
+ ...finalNode.props,
18473
+ zIndex: childrenAmount
18474
+ }
18475
+ };
18476
+ this.logger.info({ node: JSON.parse(JSON.stringify(finalNode)) }, "addNode: node to add");
18477
+ parentChildren.push(finalNode);
18478
+ }
18479
+ parent.props.children = parentChildren;
18480
+ this.logger.info({ parent: JSON.parse(JSON.stringify(parent)) }, "addNode: parent after add");
18481
+ this.instance.emitEvent("onNodeAdded", node);
18478
18482
  }
18479
18483
  updateNode(node) {
18480
- const userId = this.instance.getStore().getUser().id;
18481
- this.instance.getStore().getDocument().transact(() => {
18482
- const state = this.instance.getStore().getState();
18483
- if ((0, import_lodash.isEmpty)(state.weave)) {
18484
- const msg = `State is empty, cannot update the node`;
18485
- this.logger.warn({ node }, msg);
18486
- return;
18487
- }
18488
- const { node: nodeState } = this.findNodeById(state.weave, node.key);
18489
- if (!nodeState) {
18490
- const msg = `Node with key [${node.key}] doesn't exists, cannot update it`;
18491
- this.logger.warn({ node }, msg);
18492
- return;
18493
- }
18494
- const nodeNew = JSON.parse(JSON.stringify({
18495
- ...nodeState.props,
18496
- ...node.props
18497
- }));
18498
- nodeState.props = { ...nodeNew };
18499
- this.instance.emitEvent("onNodeUpdated", node);
18500
- }, userId);
18484
+ const state = this.instance.getStore().getState();
18485
+ this.logger.info({ state: JSON.parse(JSON.stringify(state)) }, "State before updateNode");
18486
+ if ((0, import_lodash.isEmpty)(state.weave)) {
18487
+ const msg = `State is empty, cannot update the node`;
18488
+ this.logger.warn({ node }, msg);
18489
+ return;
18490
+ }
18491
+ const { node: nodeState } = this.findNodeById(state.weave, node.key);
18492
+ if (!nodeState) {
18493
+ const msg = `Node with key [${node.key}] doesn't exists, cannot update it`;
18494
+ this.logger.warn({ node }, msg);
18495
+ return;
18496
+ }
18497
+ this.logger.info({ node: JSON.parse(JSON.stringify(nodeState)) }, "updateNode: before update");
18498
+ const nodeNew = JSON.parse(JSON.stringify({
18499
+ ...nodeState.props,
18500
+ ...node.props
18501
+ }));
18502
+ nodeState.props = { ...nodeNew };
18503
+ this.logger.info({ node: JSON.parse(JSON.stringify(nodeState)) }, "updateNode: after update");
18504
+ this.instance.emitEvent("onNodeUpdated", node);
18501
18505
  }
18502
18506
  removeNode(node) {
18503
- const userId = this.instance.getStore().getUser().id;
18504
- this.instance.getStore().getDocument().transact(() => {
18505
- const state = this.instance.getStore().getState();
18506
- if ((0, import_lodash.isEmpty)(state.weave)) {
18507
- const msg = `State is empty, cannot update the node`;
18508
- this.logger.warn({ node }, msg);
18509
- return;
18510
- }
18511
- const { node: nodeState, parent: parentState } = this.findNodeById(state.weave, node.key);
18512
- if (!nodeState) {
18513
- const msg = `Node with key [${node.key}] doesn't exists, cannot remove it`;
18514
- this.logger.warn({ node }, msg);
18515
- return;
18516
- }
18517
- if (parentState) {
18518
- const newChildren = JSON.parse(JSON.stringify(parentState.props.children));
18519
- const filteredChildren = newChildren.filter((actNode) => actNode.key !== node.key);
18520
- parentState.props.children = filteredChildren;
18521
- }
18522
- this.instance.emitEvent("onNodeRemoved", node);
18523
- }, userId);
18507
+ const state = this.instance.getStore().getState();
18508
+ this.logger.info({ stage: JSON.parse(JSON.stringify(state)) }, "State before removeNode");
18509
+ if ((0, import_lodash.isEmpty)(state.weave)) {
18510
+ const msg = `State is empty, cannot update the node`;
18511
+ this.logger.warn({ node }, msg);
18512
+ return;
18513
+ }
18514
+ const { node: nodeState, parent: parentState } = this.findNodeById(state.weave, node.key);
18515
+ if (!nodeState) {
18516
+ const msg = `Node with key [${node.key}] doesn't exists, cannot remove it`;
18517
+ this.logger.warn({ node }, msg);
18518
+ return;
18519
+ }
18520
+ this.logger.info({ key: node.key }, "removeNode: node to remove");
18521
+ this.logger.info({ parent: JSON.parse(JSON.stringify(parentState)) }, "removeNode: parent before remove");
18522
+ if (parentState && parentState.props.children) {
18523
+ const newChildren = JSON.parse(JSON.stringify(parentState.props.children));
18524
+ const filteredChildren = newChildren.filter((actNode) => actNode.key !== node.key);
18525
+ parentState.props.children = filteredChildren;
18526
+ this.logger.info({ parent: JSON.parse(JSON.stringify(parentState)) }, "removeNode: parent after remove");
18527
+ }
18528
+ this.instance.emitEvent("onNodeRemoved", node);
18524
18529
  }
18525
18530
  removeNodes(nodes) {
18526
18531
  for (const node of nodes) this.removeNode(node);
18527
18532
  }
18528
18533
  moveNode(node, position) {
18529
- const userId = this.instance.getStore().getUser().id;
18530
- this.instance.getStore().getDocument().transact(() => {
18531
- const state = this.instance.getStore().getState();
18532
- if ((0, import_lodash.isEmpty)(state.weave)) {
18533
- const msg = `State is empty, cannot update the node`;
18534
- this.logger.warn({ node }, msg);
18535
- return;
18536
- }
18537
- const { node: nodeState, parent: nodeParent } = this.findNodeById(state.weave, node.key);
18538
- if (!nodeState) {
18539
- const msg = `Node with key [${node.key}] doesn't exists, cannot update it`;
18540
- this.logger.warn({ node }, msg);
18541
- return;
18542
- }
18543
- if (nodeParent) {
18544
- let nodeParentNewChildren = JSON.parse(JSON.stringify([...nodeParent.props.children ?? []]));
18545
- const nodeNew = JSON.parse(JSON.stringify({ ...node }));
18546
- const childrenAmount = nodeParentNewChildren.length;
18547
- const nodeIndex = nodeParentNewChildren.findIndex((n) => n.key === nodeNew.key);
18548
- nodeParentNewChildren.splice(nodeIndex, 1);
18549
- if (position === WEAVE_NODE_POSITION.UP) nodeParentNewChildren.splice(nodeIndex + 1, 0, nodeNew);
18550
- if (position === WEAVE_NODE_POSITION.DOWN) nodeParentNewChildren.splice(nodeIndex - 1, 0, nodeNew);
18551
- if (position === WEAVE_NODE_POSITION.FRONT) nodeParentNewChildren.splice(childrenAmount - 1, 0, nodeNew);
18552
- if (position === WEAVE_NODE_POSITION.BACK) nodeParentNewChildren.splice(0, 0, nodeNew);
18553
- nodeParentNewChildren = nodeParentNewChildren.map((actNode, index) => {
18554
- return {
18555
- ...actNode,
18556
- props: {
18557
- ...actNode.props,
18558
- zIndex: index
18559
- }
18560
- };
18561
- });
18562
- if (!nodeParent.props.children) nodeParent.props.children = [];
18563
- nodeParent.props.children = nodeParentNewChildren;
18564
- }
18565
- }, userId);
18534
+ const state = this.instance.getStore().getState();
18535
+ if ((0, import_lodash.isEmpty)(state.weave)) {
18536
+ const msg = `State is empty, cannot update the node`;
18537
+ this.logger.warn({ node }, msg);
18538
+ return;
18539
+ }
18540
+ const { node: nodeState, parent: nodeParent } = this.findNodeById(state.weave, node.key);
18541
+ if (!nodeState) {
18542
+ const msg = `Node with key [${node.key}] doesn't exists, cannot update it`;
18543
+ this.logger.warn({ node }, msg);
18544
+ return;
18545
+ }
18546
+ if (nodeParent && nodeParent.props.children) {
18547
+ let nodeParentNewChildren = JSON.parse(JSON.stringify([...nodeParent.props.children ?? []]));
18548
+ const nodeNew = JSON.parse(JSON.stringify({ ...node }));
18549
+ const childrenAmount = nodeParentNewChildren.length;
18550
+ const nodeIndex = nodeParentNewChildren.findIndex((n) => n.key === nodeNew.key);
18551
+ nodeParentNewChildren.splice(nodeIndex, 1);
18552
+ if (position === WEAVE_NODE_POSITION.UP) nodeParentNewChildren.splice(nodeIndex + 1, 0, nodeNew);
18553
+ if (position === WEAVE_NODE_POSITION.DOWN) nodeParentNewChildren.splice(nodeIndex - 1, 0, nodeNew);
18554
+ if (position === WEAVE_NODE_POSITION.FRONT) nodeParentNewChildren.splice(childrenAmount - 1, 0, nodeNew);
18555
+ if (position === WEAVE_NODE_POSITION.BACK) nodeParentNewChildren.splice(0, 0, nodeNew);
18556
+ nodeParentNewChildren = nodeParentNewChildren.map((actNode, index) => {
18557
+ return {
18558
+ ...actNode,
18559
+ props: {
18560
+ ...actNode.props,
18561
+ zIndex: index
18562
+ }
18563
+ };
18564
+ });
18565
+ if (!nodeParent.props.children) nodeParent.props.children = [];
18566
+ nodeParent.props.children = nodeParentNewChildren;
18567
+ }
18566
18568
  }
18567
18569
  getElementsTree() {
18568
18570
  const state = this.instance.getStore().getState().weave;
18569
18571
  const jsonState = JSON.parse(JSON.stringify(state, null, 2));
18570
18572
  const mainLayer = jsonState.props?.children.find((node) => node.key === "mainLayer");
18571
18573
  if (!mainLayer) return [];
18574
+ if (!mainLayer.props?.children) return [];
18572
18575
  return mainLayer.props.children;
18573
18576
  }
18574
18577
  };
@@ -18646,7 +18649,7 @@ var WeaveRegisterManager = class {
18646
18649
 
18647
18650
  //#endregion
18648
18651
  //#region package.json
18649
- var version = "0.40.0";
18652
+ var version = "0.40.1";
18650
18653
 
18651
18654
  //#endregion
18652
18655
  //#region src/managers/setup.ts