@inditextech/weave-sdk 0.40.0 → 0.40.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.
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) {
@@ -17482,9 +17482,13 @@ var WeaveStateSerializer = class {
17482
17482
  });
17483
17483
  const { key, type, props } = element;
17484
17484
  if (typeof type !== "string") throw new Error(`Deserialization error: element type must be string received [${type}]`);
17485
- const { children,...restProps } = props;
17485
+ let restProps = {};
17486
17486
  let childrenNodes = [];
17487
- if (children) childrenNodes = this.deserializeElement(children);
17487
+ if (props.children) {
17488
+ const { children,...actRestProps } = props;
17489
+ restProps = actRestProps;
17490
+ if (children) childrenNodes = this.deserializeElement(children);
17491
+ } else restProps = props;
17488
17492
  return React.createElement(type.toLowerCase(), {
17489
17493
  ...restProps,
17490
17494
  key
@@ -18305,13 +18309,17 @@ var WeaveZIndexManager = class {
18305
18309
  this.logger = this.instance.getChildLogger("zindex-manager");
18306
18310
  this.logger.debug("zIndex manager created");
18307
18311
  }
18312
+ getSelectionPlugin() {
18313
+ const selectionPlugin = this.instance.getPlugin("nodesSelection");
18314
+ return selectionPlugin;
18315
+ }
18308
18316
  moveUp(instance) {
18309
18317
  this.logger.debug(`Moving instance with id [${instance.getAttrs().id}], up one step of z-index`);
18310
18318
  instance.moveUp();
18311
18319
  const handler = this.instance.getNodeHandler(instance.getAttrs().nodeType);
18312
18320
  if (handler) {
18313
- const node = handler.serialize(instance);
18314
- this.instance.moveNode(node, WEAVE_NODE_POSITION.UP);
18321
+ const nodeState = handler.serialize(instance);
18322
+ this.instance.moveNode(nodeState, WEAVE_NODE_POSITION.UP);
18315
18323
  }
18316
18324
  }
18317
18325
  moveDown(instance) {
@@ -18319,8 +18327,8 @@ var WeaveZIndexManager = class {
18319
18327
  instance.moveDown();
18320
18328
  const handler = this.instance.getNodeHandler(instance.getAttrs().nodeType);
18321
18329
  if (handler) {
18322
- const node = handler.serialize(instance);
18323
- this.instance.moveNode(node, WEAVE_NODE_POSITION.DOWN);
18330
+ const nodeState = handler.serialize(instance);
18331
+ this.instance.moveNode(nodeState, WEAVE_NODE_POSITION.DOWN);
18324
18332
  }
18325
18333
  }
18326
18334
  sendToBack(instances) {
@@ -18331,7 +18339,6 @@ var WeaveZIndexManager = class {
18331
18339
  const handler = this.instance.getNodeHandler(node.getAttrs().nodeType);
18332
18340
  if (handler) {
18333
18341
  const nodeState = handler.serialize(node);
18334
- this.instance.updateNode(nodeState);
18335
18342
  this.instance.moveNode(nodeState, WEAVE_NODE_POSITION.BACK);
18336
18343
  }
18337
18344
  }
@@ -18344,7 +18351,6 @@ var WeaveZIndexManager = class {
18344
18351
  const handler = this.instance.getNodeHandler(node.getAttrs().nodeType);
18345
18352
  if (handler) {
18346
18353
  const nodeState = handler.serialize(node);
18347
- this.instance.updateNode(nodeState);
18348
18354
  this.instance.moveNode(nodeState, WEAVE_NODE_POSITION.FRONT);
18349
18355
  }
18350
18356
  }
@@ -18419,156 +18425,151 @@ var WeaveStateManager = class {
18419
18425
  return this.findNodeById(state, nodeKey);
18420
18426
  }
18421
18427
  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,
18469
- props: {
18470
- ...node.props,
18471
- zIndex: childrenAmount
18472
- }
18473
- };
18474
- parent.props.children.push(finalNode);
18475
- }
18476
- this.instance.emitEvent("onNodeAdded", node);
18477
- }, userId);
18428
+ const state = this.instance.getStore().getState();
18429
+ this.logger.info({ state: JSON.parse(JSON.stringify(state)) }, "State before addNode");
18430
+ if ((0, import_lodash.isEmpty)(state.weave)) {
18431
+ const msg = `State is empty, cannot add the node`;
18432
+ this.logger.warn({
18433
+ node,
18434
+ parentId
18435
+ }, msg);
18436
+ return;
18437
+ }
18438
+ const { node: nodeState } = this.findNodeById(state.weave, node.key);
18439
+ if (nodeState) {
18440
+ const msg = `Node with key [${node.key}] already exists, cannot add it`;
18441
+ this.logger.warn({
18442
+ node,
18443
+ parentId
18444
+ }, msg);
18445
+ return;
18446
+ }
18447
+ const { node: parent } = this.findNodeById(state.weave, parentId);
18448
+ if (!parent) {
18449
+ const msg = `Parent container with key [${node.key}] doesn't exists, cannot add it`;
18450
+ this.logger.warn({
18451
+ node,
18452
+ parentId
18453
+ }, msg);
18454
+ return;
18455
+ }
18456
+ this.logger.info({ parent: JSON.parse(JSON.stringify(parent)) }, "addNode: parent before init");
18457
+ const newChildren = JSON.parse(JSON.stringify(parent.props.children ?? []));
18458
+ this.logger.info({ parent: JSON.parse(JSON.stringify(parent)) }, "addNode: parent before add");
18459
+ if (index) {
18460
+ newChildren?.splice(index, 0, node);
18461
+ for (let i = 0; i < newChildren.length; i++) newChildren[i].props.zIndex = i;
18462
+ }
18463
+ if (!index) {
18464
+ const childrenAmount = newChildren.length;
18465
+ node.props.zIndex = childrenAmount;
18466
+ const nodeToAdd = {
18467
+ ...node,
18468
+ props: {
18469
+ ...node.props,
18470
+ zIndex: childrenAmount
18471
+ }
18472
+ };
18473
+ this.logger.info({ node: JSON.parse(JSON.stringify(nodeToAdd)) }, "addNode: node to add");
18474
+ newChildren.push(nodeToAdd);
18475
+ }
18476
+ if (typeof newChildren !== "undefined") parent.props.children = newChildren;
18477
+ this.logger.info({ parent: JSON.parse(JSON.stringify(parent)) }, "addNode: parent after add");
18478
+ this.instance.emitEvent("onNodeAdded", node);
18478
18479
  }
18479
18480
  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);
18481
+ const state = this.instance.getStore().getState();
18482
+ this.logger.info({ state: JSON.parse(JSON.stringify(state)) }, "State before updateNode");
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
+ this.logger.info({ node: JSON.parse(JSON.stringify(nodeState)) }, "updateNode: before update");
18495
+ const newNode = JSON.parse(JSON.stringify(nodeState));
18496
+ newNode.props = {
18497
+ ...newNode.props,
18498
+ ...node.props
18499
+ };
18500
+ if (typeof newNode.props !== "undefined") nodeState.props = newNode.props;
18501
+ this.logger.info({ node: JSON.parse(JSON.stringify(nodeState)) }, "updateNode: after update");
18502
+ this.instance.emitEvent("onNodeUpdated", node);
18501
18503
  }
18502
18504
  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);
18505
+ const state = this.instance.getStore().getState();
18506
+ this.logger.info({ stage: JSON.parse(JSON.stringify(state)) }, "State before removeNode");
18507
+ if ((0, import_lodash.isEmpty)(state.weave)) {
18508
+ const msg = `State is empty, cannot update the node`;
18509
+ this.logger.warn({ node }, msg);
18510
+ return;
18511
+ }
18512
+ const { node: nodeState, parent } = this.findNodeById(state.weave, node.key);
18513
+ if (!nodeState) {
18514
+ const msg = `Node with key [${node.key}] doesn't exists, cannot remove it`;
18515
+ this.logger.warn({ node }, msg);
18516
+ return;
18517
+ }
18518
+ if (!parent) {
18519
+ const msg = `Parent doesn't exists, cannot remove it`;
18520
+ this.logger.warn({ node }, msg);
18521
+ return;
18522
+ }
18523
+ this.logger.info({ key: node.key }, "removeNode: node to remove");
18524
+ this.logger.info({ parent: JSON.parse(JSON.stringify(parent)) }, "removeNode: parent before remove");
18525
+ const newChildren = JSON.parse(JSON.stringify(parent.props.children ?? []));
18526
+ for (let i = newChildren.length - 1; i >= 0; i--) if (newChildren[i].key === node.key) {
18527
+ newChildren.splice(i, 1);
18528
+ break;
18529
+ }
18530
+ for (let i = 0; i < newChildren.length; i++) newChildren[i].props.zIndex = i;
18531
+ if (typeof newChildren !== "undefined") parent.props.children = newChildren;
18532
+ this.logger.info({ parent: JSON.parse(JSON.stringify(parent)) }, "removeNode: parent after remove");
18533
+ this.instance.emitEvent("onNodeRemoved", node);
18524
18534
  }
18525
18535
  removeNodes(nodes) {
18526
18536
  for (const node of nodes) this.removeNode(node);
18527
18537
  }
18528
18538
  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);
18539
+ const state = this.instance.getStore().getState();
18540
+ this.logger.info({ stage: JSON.parse(JSON.stringify(state)) }, "State before moveNode");
18541
+ if ((0, import_lodash.isEmpty)(state.weave)) {
18542
+ const msg = `State is empty, cannot update the node`;
18543
+ this.logger.warn({ node }, msg);
18544
+ return;
18545
+ }
18546
+ const { node: nodeState, parent } = this.findNodeById(state.weave, node.key);
18547
+ if (!nodeState) {
18548
+ const msg = `Node with key [${node.key}] doesn't exists, cannot update it`;
18549
+ this.logger.warn({ node }, msg);
18550
+ return;
18551
+ }
18552
+ this.logger.info({ parent: JSON.parse(JSON.stringify(parent)) }, "moveNode: parent before move");
18553
+ if (parent && parent.props.children) {
18554
+ const childrenAmount = parent.props.children.length;
18555
+ const nodeIndex = parent.props.children.findIndex((child) => child.key === node.key);
18556
+ const newChildren = JSON.parse(JSON.stringify(parent.props.children ?? []));
18557
+ newChildren.splice(nodeIndex, 1);
18558
+ if (position === WEAVE_NODE_POSITION.UP) newChildren.splice(nodeIndex + 1, 0, { ...node });
18559
+ if (position === WEAVE_NODE_POSITION.DOWN) newChildren.splice(nodeIndex - 1, 0, { ...node });
18560
+ if (position === WEAVE_NODE_POSITION.FRONT) newChildren.splice(childrenAmount - 1, 0, { ...node });
18561
+ if (position === WEAVE_NODE_POSITION.BACK) newChildren.splice(0, 0, { ...node });
18562
+ for (let i = 0; i < newChildren.length; i++) newChildren[i].props.zIndex = i;
18563
+ if (typeof newChildren !== "undefined") parent.props.children = newChildren;
18564
+ }
18565
+ this.logger.info({ parent: JSON.parse(JSON.stringify(parent)) }, "moveNode: parent after move");
18566
18566
  }
18567
18567
  getElementsTree() {
18568
18568
  const state = this.instance.getStore().getState().weave;
18569
18569
  const jsonState = JSON.parse(JSON.stringify(state, null, 2));
18570
18570
  const mainLayer = jsonState.props?.children.find((node) => node.key === "mainLayer");
18571
18571
  if (!mainLayer) return [];
18572
+ if (!mainLayer.props?.children) return [];
18572
18573
  return mainLayer.props.children;
18573
18574
  }
18574
18575
  };
@@ -18646,7 +18647,7 @@ var WeaveRegisterManager = class {
18646
18647
 
18647
18648
  //#endregion
18648
18649
  //#region package.json
18649
- var version = "0.40.0";
18650
+ var version = "0.40.2";
18650
18651
 
18651
18652
  //#endregion
18652
18653
  //#region src/managers/setup.ts