@inditextech/weave-sdk 0.39.3 → 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
@@ -15551,10 +15551,10 @@ var WeaveStore = class {
15551
15551
  if (weaveStateValues) {
15552
15552
  this.undoManager = new yjs.UndoManager([weaveStateValues], {
15553
15553
  captureTimeout: 250,
15554
- trackedOrigins: new Set([this.config.getUser().name]),
15554
+ trackedOrigins: new Set([this.config.getUser().id]),
15555
15555
  ...this.config?.undoManagerOptions
15556
15556
  });
15557
- this.undoManager.addTrackedOrigin(this.config.getUser().name);
15557
+ this.undoManager.addTrackedOrigin(this.config.getUser().id);
15558
15558
  this.undoManager.on("stack-item-added", () => {
15559
15559
  const change = {
15560
15560
  canUndo: this.undoManager.canUndo(),
@@ -15577,6 +15577,7 @@ var WeaveStore = class {
15577
15577
  }
15578
15578
  (0, __syncedstore_core.observeDeep)(this.getState(), () => {
15579
15579
  const newState = JSON.parse(JSON.stringify(this.getState()));
15580
+ this.logger.info({ newState }, "State changed");
15580
15581
  this.instance.emitEvent("onStateChange", newState);
15581
15582
  const nodesSelectionPlugin = this.instance.getPlugin("nodesSelection");
15582
15583
  if (this.isRoomLoaded && nodesSelectionPlugin && nodesSelectionPlugin.getSelectedNodes().length === 1) {
@@ -18418,156 +18419,159 @@ var WeaveStateManager = class {
18418
18419
  return this.findNodeById(state, nodeKey);
18419
18420
  }
18420
18421
  addNode(node, parentId = "mainLayer", index = void 0) {
18421
- const userName = this.instance.getStore().getUser().name;
18422
- this.instance.getStore().getDocument().transact(() => {
18423
- const state = this.instance.getStore().getState();
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
- if (!parent.props.children || typeof parent.props.children === "undefined") parent.props.children = [];
18451
- if (index) {
18452
- let parentChildren = JSON.parse(JSON.stringify([...parent.props.children]));
18453
- parentChildren.splice(index, 0, node);
18454
- parentChildren = parentChildren.map((actNode, index$1) => {
18455
- return {
18456
- ...actNode,
18457
- props: {
18458
- ...actNode.props,
18459
- zIndex: index$1
18460
- }
18461
- };
18462
- });
18463
- parent.props.children = parentChildren;
18464
- } else {
18465
- const childrenAmount = parent.props.children.length;
18466
- const finalNode = {
18467
- ...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,
18468
18459
  props: {
18469
- ...node.props,
18470
- zIndex: childrenAmount
18460
+ ...actNode.props,
18461
+ zIndex: index$1
18471
18462
  }
18472
18463
  };
18473
- parent.props.children.push(finalNode);
18474
- }
18475
- this.instance.emitEvent("onNodeAdded", node);
18476
- }, userName);
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);
18477
18482
  }
18478
18483
  updateNode(node) {
18479
- const userName = this.instance.getStore().getUser().name;
18480
- this.instance.getStore().getDocument().transact(() => {
18481
- const state = this.instance.getStore().getState();
18482
- if ((0, import_lodash.isEmpty)(state.weave)) {
18483
- const msg = `State is empty, cannot update the node`;
18484
- this.logger.warn({ node }, msg);
18485
- return;
18486
- }
18487
- const { node: nodeState } = this.findNodeById(state.weave, node.key);
18488
- if (!nodeState) {
18489
- const msg = `Node with key [${node.key}] doesn't exists, cannot update it`;
18490
- this.logger.warn({ node }, msg);
18491
- return;
18492
- }
18493
- const nodeNew = JSON.parse(JSON.stringify({
18494
- ...nodeState.props,
18495
- ...node.props
18496
- }));
18497
- nodeState.props = { ...nodeNew };
18498
- this.instance.emitEvent("onNodeUpdated", node);
18499
- }, userName);
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);
18500
18505
  }
18501
18506
  removeNode(node) {
18502
- const userName = this.instance.getStore().getUser().name;
18503
- this.instance.getStore().getDocument().transact(() => {
18504
- const state = this.instance.getStore().getState();
18505
- if ((0, import_lodash.isEmpty)(state.weave)) {
18506
- const msg = `State is empty, cannot update the node`;
18507
- this.logger.warn({ node }, msg);
18508
- return;
18509
- }
18510
- const { node: nodeState, parent: parentState } = this.findNodeById(state.weave, node.key);
18511
- if (!nodeState) {
18512
- const msg = `Node with key [${node.key}] doesn't exists, cannot remove it`;
18513
- this.logger.warn({ node }, msg);
18514
- return;
18515
- }
18516
- if (parentState) {
18517
- const newChildren = JSON.parse(JSON.stringify(parentState.props.children));
18518
- const filteredChildren = newChildren.filter((actNode) => actNode.key !== node.key);
18519
- parentState.props.children = filteredChildren;
18520
- }
18521
- this.instance.emitEvent("onNodeRemoved", node);
18522
- }, userName);
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);
18523
18529
  }
18524
18530
  removeNodes(nodes) {
18525
18531
  for (const node of nodes) this.removeNode(node);
18526
18532
  }
18527
18533
  moveNode(node, position) {
18528
- const userName = this.instance.getStore().getUser().name;
18529
- this.instance.getStore().getDocument().transact(() => {
18530
- const state = this.instance.getStore().getState();
18531
- if ((0, import_lodash.isEmpty)(state.weave)) {
18532
- const msg = `State is empty, cannot update the node`;
18533
- this.logger.warn({ node }, msg);
18534
- return;
18535
- }
18536
- const { node: nodeState, parent: nodeParent } = this.findNodeById(state.weave, node.key);
18537
- if (!nodeState) {
18538
- const msg = `Node with key [${node.key}] doesn't exists, cannot update it`;
18539
- this.logger.warn({ node }, msg);
18540
- return;
18541
- }
18542
- if (nodeParent) {
18543
- let nodeParentNewChildren = JSON.parse(JSON.stringify([...nodeParent.props.children ?? []]));
18544
- const nodeNew = JSON.parse(JSON.stringify({ ...node }));
18545
- const childrenAmount = nodeParentNewChildren.length;
18546
- const nodeIndex = nodeParentNewChildren.findIndex((n) => n.key === nodeNew.key);
18547
- nodeParentNewChildren.splice(nodeIndex, 1);
18548
- if (position === __inditextech_weave_types.WEAVE_NODE_POSITION.UP) nodeParentNewChildren.splice(nodeIndex + 1, 0, nodeNew);
18549
- if (position === __inditextech_weave_types.WEAVE_NODE_POSITION.DOWN) nodeParentNewChildren.splice(nodeIndex - 1, 0, nodeNew);
18550
- if (position === __inditextech_weave_types.WEAVE_NODE_POSITION.FRONT) nodeParentNewChildren.splice(childrenAmount - 1, 0, nodeNew);
18551
- if (position === __inditextech_weave_types.WEAVE_NODE_POSITION.BACK) nodeParentNewChildren.splice(0, 0, nodeNew);
18552
- nodeParentNewChildren = nodeParentNewChildren.map((actNode, index) => {
18553
- return {
18554
- ...actNode,
18555
- props: {
18556
- ...actNode.props,
18557
- zIndex: index
18558
- }
18559
- };
18560
- });
18561
- if (!nodeParent.props.children) nodeParent.props.children = [];
18562
- nodeParent.props.children = nodeParentNewChildren;
18563
- }
18564
- }, userName);
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
+ }
18565
18568
  }
18566
18569
  getElementsTree() {
18567
18570
  const state = this.instance.getStore().getState().weave;
18568
18571
  const jsonState = JSON.parse(JSON.stringify(state, null, 2));
18569
18572
  const mainLayer = jsonState.props?.children.find((node) => node.key === "mainLayer");
18570
18573
  if (!mainLayer) return [];
18574
+ if (!mainLayer.props?.children) return [];
18571
18575
  return mainLayer.props.children;
18572
18576
  }
18573
18577
  };
@@ -18645,7 +18649,7 @@ var WeaveRegisterManager = class {
18645
18649
 
18646
18650
  //#endregion
18647
18651
  //#region package.json
18648
- var version = "0.39.3";
18652
+ var version = "0.40.1";
18649
18653
 
18650
18654
  //#endregion
18651
18655
  //#region src/managers/setup.ts
@@ -26546,7 +26550,7 @@ var WeaveConnectedUsersPlugin = class extends WeavePlugin {
26546
26550
  const store = this.instance.getStore();
26547
26551
  const userInfo = this.config.getUser();
26548
26552
  store.setAwarenessInfo(WEAVE_CONNECTED_USER_INFO_KEY, userInfo);
26549
- this.instance.emitEvent("onConnectedUsersChange", { [userInfo.name]: userInfo });
26553
+ this.instance.emitEvent("onConnectedUsersChange", { [userInfo.id]: userInfo });
26550
26554
  this.instance.addEventListener("onConnectionStatusChange", (status) => {
26551
26555
  if (status === "connected") {
26552
26556
  const userInfo$1 = this.config.getUser();
@@ -26564,7 +26568,7 @@ var WeaveConnectedUsersPlugin = class extends WeavePlugin {
26564
26568
  if (!change[WEAVE_CONNECTED_USER_INFO_KEY]) continue;
26565
26569
  if (change[WEAVE_CONNECTED_USER_INFO_KEY]) {
26566
26570
  const userInformation = change[WEAVE_CONNECTED_USER_INFO_KEY];
26567
- newConnectedUsers[userInformation.name] = userInformation;
26571
+ newConnectedUsers[userInformation.id] = userInformation;
26568
26572
  }
26569
26573
  }
26570
26574
  if (!(0, import_lodash.isEqual)(this.connectedUsers, newConnectedUsers)) this.instance.emitEvent("onConnectedUsersChange", newConnectedUsers);
@@ -26617,7 +26621,7 @@ var WeaveUsersSelectionPlugin = class extends WeavePlugin {
26617
26621
  const allActiveUsers = [];
26618
26622
  for (const change of changes) {
26619
26623
  if (!change[WEAVE_USER_SELECTION_KEY]) continue;
26620
- if (change[WEAVE_USER_SELECTION_KEY] && selfUser.name !== change[WEAVE_USER_SELECTION_KEY].user) {
26624
+ if (change[WEAVE_USER_SELECTION_KEY] && selfUser.id !== change[WEAVE_USER_SELECTION_KEY].user) {
26621
26625
  const userSelection = change[WEAVE_USER_SELECTION_KEY];
26622
26626
  allActiveUsers.push(userSelection.user);
26623
26627
  this.usersSelection[userSelection.user] = userSelection;
@@ -26640,7 +26644,7 @@ var WeaveUsersSelectionPlugin = class extends WeavePlugin {
26640
26644
  const userInfo = this.config.getUser();
26641
26645
  const store = this.instance.getStore();
26642
26646
  store.setAwarenessInfo(WEAVE_USER_SELECTION_KEY, {
26643
- user: userInfo.name,
26647
+ user: userInfo.id,
26644
26648
  nodes: tr.nodes().map((node) => node.getAttrs().id)
26645
26649
  });
26646
26650
  }
@@ -26791,7 +26795,7 @@ var WeaveUsersPointersPlugin = class extends WeavePlugin {
26791
26795
  const allActiveUsers = [];
26792
26796
  for (const change of changes) {
26793
26797
  if (!change[WEAVE_USER_POINTER_KEY]) continue;
26794
- if (change[WEAVE_USER_POINTER_KEY] && selfUser.name !== change[WEAVE_USER_POINTER_KEY].user) {
26798
+ if (change[WEAVE_USER_POINTER_KEY] && selfUser.id !== change[WEAVE_USER_POINTER_KEY].user) {
26795
26799
  const userPointer = change[WEAVE_USER_POINTER_KEY];
26796
26800
  allActiveUsers.push(userPointer.user);
26797
26801
  this.usersPointers[userPointer.user] = userPointer;
@@ -26806,7 +26810,8 @@ var WeaveUsersPointersPlugin = class extends WeavePlugin {
26806
26810
  const userInfo = this.config.getUser();
26807
26811
  const mousePos = stage.getRelativePointerPosition();
26808
26812
  if (mousePos) store.setAwarenessInfo(WEAVE_USER_POINTER_KEY, {
26809
- user: userInfo.name,
26813
+ user: userInfo.id,
26814
+ name: userInfo.name,
26810
26815
  x: mousePos.x,
26811
26816
  y: mousePos.y
26812
26817
  });
@@ -26815,7 +26820,8 @@ var WeaveUsersPointersPlugin = class extends WeavePlugin {
26815
26820
  const userInfo = this.config.getUser();
26816
26821
  const mousePos = stage.getRelativePointerPosition();
26817
26822
  if (mousePos) store.setAwarenessInfo(WEAVE_USER_POINTER_KEY, {
26818
- user: userInfo.name,
26823
+ user: userInfo.id,
26824
+ name: userInfo.name,
26819
26825
  x: mousePos.x,
26820
26826
  y: mousePos.y
26821
26827
  });
@@ -26859,7 +26865,7 @@ var WeaveUsersPointersPlugin = class extends WeavePlugin {
26859
26865
  id: `pointer_${userPointer.user}_userPointName`,
26860
26866
  x: separation,
26861
26867
  y: -circleRadius * 2 + backgroundPaddingY,
26862
- text: userPointer.user.trim(),
26868
+ text: userPointer.name.trim(),
26863
26869
  fontSize,
26864
26870
  fontFamily,
26865
26871
  lineHeight: .9,
package/dist/sdk.d.cts CHANGED
@@ -53,6 +53,7 @@ type WeaveStoreOptions = {
53
53
  interface WeaveStoreBase {
54
54
  connect(): void;
55
55
  disconnect(): void;
56
+ handleAwarenessChange(emit: boolean): void;
56
57
  setAwarenessInfo(field: string, value: unknown): void;
57
58
  }
58
59
 
@@ -131,9 +132,10 @@ type WeaveExportNodesOptions = {
131
132
  quality?: number;
132
133
  };
133
134
  type WeaveUser = {
134
- [key: string]: any;
135
+ id: string;
135
136
  name: string;
136
137
  email: string;
138
+ [key: string]: any;
137
139
  };
138
140
  type WeaveFont = {
139
141
  id: string;
@@ -223,6 +225,7 @@ declare abstract class WeaveStore implements WeaveStoreBase {
223
225
  handleConnectionStatusChange(status: WeaveStoreConnectionStatus): void;
224
226
  abstract connect(): void;
225
227
  abstract disconnect(): void;
228
+ abstract handleAwarenessChange(emit: boolean): void;
226
229
  abstract setAwarenessInfo(field: string, value: unknown): void;
227
230
  }
228
231
 
@@ -2349,6 +2352,7 @@ type WeaveUsersPointersPluginParams = {
2349
2352
  };
2350
2353
  type WeaveUserPointer = {
2351
2354
  user: string;
2355
+ name: string;
2352
2356
  x: number;
2353
2357
  y: number;
2354
2358
  };