microboard-temp 0.13.12 → 0.13.14

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.
@@ -4993,6 +4993,13 @@ class BoardCommand {
4993
4993
  item: [operation.item]
4994
4994
  };
4995
4995
  }
4996
+ case "addGroup": {
4997
+ return {
4998
+ class: "Board",
4999
+ method: "removeGroup",
5000
+ item: [operation.item]
5001
+ };
5002
+ }
4996
5003
  case "removeLockedGroup": {
4997
5004
  const items = this.board.items;
4998
5005
  const reverse = [];
@@ -5010,6 +5017,23 @@ class BoardCommand {
5010
5017
  }
5011
5018
  return reverse;
5012
5019
  }
5020
+ case "removeGroup": {
5021
+ const items = this.board.items;
5022
+ const reverse = [];
5023
+ for (const itemId of operation.item) {
5024
+ const item = items.getById(itemId);
5025
+ if (!item || item.itemType !== "Group") {
5026
+ throw new Error("Get reverse board operation. Item not found");
5027
+ }
5028
+ reverse.push({
5029
+ class: "Board",
5030
+ method: "addGroup",
5031
+ item: itemId,
5032
+ data: item.serialize()
5033
+ });
5034
+ }
5035
+ return reverse;
5036
+ }
5013
5037
  case "duplicate":
5014
5038
  case "paste": {
5015
5039
  const item = [];
@@ -19533,7 +19557,7 @@ class GroupCommand {
19533
19557
  const operation = {
19534
19558
  ...this.operation,
19535
19559
  method: "removeChild",
19536
- childId: group2.getId()
19560
+ childId: this.operation.childId
19537
19561
  };
19538
19562
  return {
19539
19563
  item: group2,
@@ -19547,7 +19571,33 @@ class GroupCommand {
19547
19571
  const operation = {
19548
19572
  ...this.operation,
19549
19573
  method: "addChild",
19550
- childId: group2.getId()
19574
+ childId: this.operation.childId
19575
+ };
19576
+ return {
19577
+ item: group2,
19578
+ operation
19579
+ };
19580
+ });
19581
+ }
19582
+ case "addChildren": {
19583
+ const groups = Array.isArray(group) ? group : [group];
19584
+ return groups.map((group2) => {
19585
+ const operation = {
19586
+ ...this.operation,
19587
+ method: "removeChildren"
19588
+ };
19589
+ return {
19590
+ item: group2,
19591
+ operation
19592
+ };
19593
+ });
19594
+ }
19595
+ case "removeChildren": {
19596
+ const groups = Array.isArray(group) ? group : [group];
19597
+ return groups.map((group2) => {
19598
+ const operation = {
19599
+ ...this.operation,
19600
+ method: "addChildren"
19551
19601
  };
19552
19602
  return {
19553
19603
  item: group2,
@@ -43587,6 +43637,7 @@ class Group extends BaseItem {
43587
43637
  transformation;
43588
43638
  subject = new Subject;
43589
43639
  transformationRenderBlock = undefined;
43640
+ isLockedGroup = false;
43590
43641
  constructor(board, events, children = [], id = "") {
43591
43642
  super(board, id, undefined, true);
43592
43643
  this.events = events;
@@ -43607,21 +43658,15 @@ class Group extends BaseItem {
43607
43658
  return null;
43608
43659
  }
43609
43660
  apply(op) {
43661
+ super.apply(op);
43610
43662
  switch (op.class) {
43611
43663
  case "Group":
43612
43664
  if (op.method === "addChild") {
43613
43665
  this.applyAddChildren([op.childId]);
43614
43666
  } else if (op.method === "removeChild") {
43615
43667
  this.applyRemoveChildren([op.childId]);
43616
- } else if (op.method === "addChildren") {
43617
- this.applyAddChildren(op.newData.childIds);
43618
- } else if (op.method === "removeChildren") {
43619
- this.applyRemoveChildren(op.newData.childIds);
43620
43668
  }
43621
43669
  break;
43622
- case "Transformation":
43623
- super.apply(op);
43624
- break;
43625
43670
  default:
43626
43671
  return;
43627
43672
  }
@@ -43654,10 +43699,10 @@ class Group extends BaseItem {
43654
43699
  for (const child of children) {
43655
43700
  const childLocalMbr = child.getMbr();
43656
43701
  const corners = [
43657
- { x: childLocalMbr.left, y: childLocalMbr.top },
43658
- { x: childLocalMbr.right, y: childLocalMbr.top },
43659
- { x: childLocalMbr.right, y: childLocalMbr.bottom },
43660
- { x: childLocalMbr.left, y: childLocalMbr.bottom }
43702
+ new Point(childLocalMbr.left, childLocalMbr.top),
43703
+ new Point(childLocalMbr.right, childLocalMbr.top),
43704
+ new Point(childLocalMbr.right, childLocalMbr.bottom),
43705
+ new Point(childLocalMbr.left, childLocalMbr.bottom)
43661
43706
  ];
43662
43707
  for (const corner of corners) {
43663
43708
  groupWorldMatrix.apply(corner);
@@ -43694,7 +43739,8 @@ class Group extends BaseItem {
43694
43739
  return {
43695
43740
  itemType: "Group",
43696
43741
  children: this.getChildrenIds(),
43697
- transformation: this.transformation.serialize()
43742
+ transformation: this.transformation.serialize(),
43743
+ isLockedGroup: this.isLockedGroup
43698
43744
  };
43699
43745
  }
43700
43746
  deserialize(data) {
@@ -43704,6 +43750,9 @@ class Group extends BaseItem {
43704
43750
  if (data.children && data.children.length > 0) {
43705
43751
  this.applyAddChildren(data.children);
43706
43752
  }
43753
+ if (data.isLockedGroup !== undefined) {
43754
+ this.isLockedGroup = data.isLockedGroup;
43755
+ }
43707
43756
  this.subject.publish(this);
43708
43757
  return this;
43709
43758
  }
@@ -43842,7 +43891,7 @@ function createGroup(id, data, board) {
43842
43891
  if (!isGroupData(data)) {
43843
43892
  throw new Error("Invalid data for Group");
43844
43893
  }
43845
- const group = new Group(board, board.events, data.children, "").setId(id).deserialize(data);
43894
+ const group = new Group(board, board.events, data.children, id).setId(id).deserialize(data);
43846
43895
  return group;
43847
43896
  }
43848
43897
  function isStickerData(data) {
@@ -54655,12 +54704,17 @@ class Board {
54655
54704
  return this.applyAddItems(op);
54656
54705
  case "addLockedGroup":
54657
54706
  return this.applyAddLockedGroupOperation(op);
54707
+ case "addGroup":
54708
+ return this.applyAddGroupOperation(op);
54658
54709
  case "remove": {
54659
54710
  return this.applyRemoveOperation(op);
54660
54711
  }
54661
54712
  case "removeLockedGroup": {
54662
54713
  return this.applyRemoveLockedGroupOperation(op);
54663
54714
  }
54715
+ case "removeGroup": {
54716
+ return this.applyRemoveGroupOperation(op);
54717
+ }
54664
54718
  case "paste": {
54665
54719
  return this.applyPasteOperation(op.itemsMap);
54666
54720
  }
@@ -54698,11 +54752,23 @@ class Board {
54698
54752
  const zIndex = this.index.getZIndex(lastChildrenId) + 1;
54699
54753
  this.index.moveToZIndex(item, zIndex);
54700
54754
  }
54755
+ item.isLockedGroup = true;
54701
54756
  item.getChildren().forEach((item2) => {
54702
54757
  item2.transformation.isLocked = true;
54703
54758
  });
54704
54759
  item.transformation.isLocked = true;
54705
54760
  }
54761
+ applyAddGroupOperation(op) {
54762
+ const item = this.createItem(op.item, op.data);
54763
+ const groupChildrenIds = item.getChildrenIds();
54764
+ this.index.insert(item);
54765
+ const lastChildrenId = this.index.getById(groupChildrenIds[groupChildrenIds.length - 1]);
54766
+ if (lastChildrenId) {
54767
+ const zIndex = this.index.getZIndex(lastChildrenId) + 1;
54768
+ this.index.moveToZIndex(item, zIndex);
54769
+ }
54770
+ item.isLockedGroup = false;
54771
+ }
54706
54772
  applyRemoveOperation(op) {
54707
54773
  const removedItems = [];
54708
54774
  this.findItemAndApply(op.item, (item) => {
@@ -54731,6 +54797,21 @@ class Board {
54731
54797
  removedItems.push(item2);
54732
54798
  });
54733
54799
  }
54800
+ applyRemoveGroupOperation(op) {
54801
+ const item = this.index.getById(op.item[0]);
54802
+ if (!item || !(item instanceof Group)) {
54803
+ return;
54804
+ }
54805
+ item.getChildren().forEach((item2) => {
54806
+ item2.parent = "Board";
54807
+ });
54808
+ const removedItems = [];
54809
+ this.findItemAndApply(op.item, (item2) => {
54810
+ this.index.remove(item2);
54811
+ this.selection.remove(item2);
54812
+ removedItems.push(item2);
54813
+ });
54814
+ }
54734
54815
  applyItemOperation(op) {
54735
54816
  if ("item" in op) {
54736
54817
  this.findItemAndApply(op.item, (item) => {
@@ -54805,20 +54886,21 @@ class Board {
54805
54886
  this.handleNesting(newItem);
54806
54887
  return newItem;
54807
54888
  }
54808
- addLockedGroup(item) {
54889
+ addLockedGroup(items) {
54809
54890
  const id = this.getNewItemId();
54891
+ const groupData = {
54892
+ itemType: "Group",
54893
+ children: items.map((i) => i.getId()),
54894
+ transformation: { translateX: 0, translateY: 0, scaleX: 1, scaleY: 1, rotate: 0, isLocked: false },
54895
+ isLockedGroup: true
54896
+ };
54810
54897
  this.emit({
54811
54898
  class: "Board",
54812
54899
  method: "addLockedGroup",
54813
54900
  item: id,
54814
- data: item.serialize()
54901
+ data: groupData
54815
54902
  });
54816
- const newItem = this.items.getById(id);
54817
- if (!newItem) {
54818
- throw new Error(`Add item. Item ${id} was not created.`);
54819
- }
54820
- this.handleNesting(newItem);
54821
- return newItem;
54903
+ return this.items.getById(id);
54822
54904
  }
54823
54905
  remove(item, withConnectors = true) {
54824
54906
  let connectors = [];
@@ -54846,11 +54928,12 @@ class Board {
54846
54928
  const groupData = {
54847
54929
  itemType: "Group",
54848
54930
  children: items.map((i) => i.getId()),
54849
- transformation: { translateX: 0, translateY: 0, scaleX: 1, scaleY: 1, shearX: 0, shearY: 0 }
54931
+ transformation: { translateX: 0, translateY: 0, scaleX: 1, scaleY: 1, rotate: 0, isLocked: false },
54932
+ isLockedGroup: false
54850
54933
  };
54851
54934
  this.emit({
54852
54935
  class: "Board",
54853
- method: "addLockedGroup",
54936
+ method: "addGroup",
54854
54937
  item: id,
54855
54938
  data: groupData
54856
54939
  });
@@ -54859,7 +54942,7 @@ class Board {
54859
54942
  ungroup(group) {
54860
54943
  this.emit({
54861
54944
  class: "Board",
54862
- method: "removeLockedGroup",
54945
+ method: "removeGroup",
54863
54946
  item: [group.getId()]
54864
54947
  });
54865
54948
  }
package/dist/cjs/index.js CHANGED
@@ -4993,6 +4993,13 @@ class BoardCommand {
4993
4993
  item: [operation.item]
4994
4994
  };
4995
4995
  }
4996
+ case "addGroup": {
4997
+ return {
4998
+ class: "Board",
4999
+ method: "removeGroup",
5000
+ item: [operation.item]
5001
+ };
5002
+ }
4996
5003
  case "removeLockedGroup": {
4997
5004
  const items = this.board.items;
4998
5005
  const reverse = [];
@@ -5010,6 +5017,23 @@ class BoardCommand {
5010
5017
  }
5011
5018
  return reverse;
5012
5019
  }
5020
+ case "removeGroup": {
5021
+ const items = this.board.items;
5022
+ const reverse = [];
5023
+ for (const itemId of operation.item) {
5024
+ const item = items.getById(itemId);
5025
+ if (!item || item.itemType !== "Group") {
5026
+ throw new Error("Get reverse board operation. Item not found");
5027
+ }
5028
+ reverse.push({
5029
+ class: "Board",
5030
+ method: "addGroup",
5031
+ item: itemId,
5032
+ data: item.serialize()
5033
+ });
5034
+ }
5035
+ return reverse;
5036
+ }
5013
5037
  case "duplicate":
5014
5038
  case "paste": {
5015
5039
  const item = [];
@@ -19533,7 +19557,7 @@ class GroupCommand {
19533
19557
  const operation = {
19534
19558
  ...this.operation,
19535
19559
  method: "removeChild",
19536
- childId: group2.getId()
19560
+ childId: this.operation.childId
19537
19561
  };
19538
19562
  return {
19539
19563
  item: group2,
@@ -19547,7 +19571,33 @@ class GroupCommand {
19547
19571
  const operation = {
19548
19572
  ...this.operation,
19549
19573
  method: "addChild",
19550
- childId: group2.getId()
19574
+ childId: this.operation.childId
19575
+ };
19576
+ return {
19577
+ item: group2,
19578
+ operation
19579
+ };
19580
+ });
19581
+ }
19582
+ case "addChildren": {
19583
+ const groups = Array.isArray(group) ? group : [group];
19584
+ return groups.map((group2) => {
19585
+ const operation = {
19586
+ ...this.operation,
19587
+ method: "removeChildren"
19588
+ };
19589
+ return {
19590
+ item: group2,
19591
+ operation
19592
+ };
19593
+ });
19594
+ }
19595
+ case "removeChildren": {
19596
+ const groups = Array.isArray(group) ? group : [group];
19597
+ return groups.map((group2) => {
19598
+ const operation = {
19599
+ ...this.operation,
19600
+ method: "addChildren"
19551
19601
  };
19552
19602
  return {
19553
19603
  item: group2,
@@ -43587,6 +43637,7 @@ class Group extends BaseItem {
43587
43637
  transformation;
43588
43638
  subject = new Subject;
43589
43639
  transformationRenderBlock = undefined;
43640
+ isLockedGroup = false;
43590
43641
  constructor(board, events, children = [], id = "") {
43591
43642
  super(board, id, undefined, true);
43592
43643
  this.events = events;
@@ -43607,21 +43658,15 @@ class Group extends BaseItem {
43607
43658
  return null;
43608
43659
  }
43609
43660
  apply(op) {
43661
+ super.apply(op);
43610
43662
  switch (op.class) {
43611
43663
  case "Group":
43612
43664
  if (op.method === "addChild") {
43613
43665
  this.applyAddChildren([op.childId]);
43614
43666
  } else if (op.method === "removeChild") {
43615
43667
  this.applyRemoveChildren([op.childId]);
43616
- } else if (op.method === "addChildren") {
43617
- this.applyAddChildren(op.newData.childIds);
43618
- } else if (op.method === "removeChildren") {
43619
- this.applyRemoveChildren(op.newData.childIds);
43620
43668
  }
43621
43669
  break;
43622
- case "Transformation":
43623
- super.apply(op);
43624
- break;
43625
43670
  default:
43626
43671
  return;
43627
43672
  }
@@ -43654,10 +43699,10 @@ class Group extends BaseItem {
43654
43699
  for (const child of children) {
43655
43700
  const childLocalMbr = child.getMbr();
43656
43701
  const corners = [
43657
- { x: childLocalMbr.left, y: childLocalMbr.top },
43658
- { x: childLocalMbr.right, y: childLocalMbr.top },
43659
- { x: childLocalMbr.right, y: childLocalMbr.bottom },
43660
- { x: childLocalMbr.left, y: childLocalMbr.bottom }
43702
+ new Point(childLocalMbr.left, childLocalMbr.top),
43703
+ new Point(childLocalMbr.right, childLocalMbr.top),
43704
+ new Point(childLocalMbr.right, childLocalMbr.bottom),
43705
+ new Point(childLocalMbr.left, childLocalMbr.bottom)
43661
43706
  ];
43662
43707
  for (const corner of corners) {
43663
43708
  groupWorldMatrix.apply(corner);
@@ -43694,7 +43739,8 @@ class Group extends BaseItem {
43694
43739
  return {
43695
43740
  itemType: "Group",
43696
43741
  children: this.getChildrenIds(),
43697
- transformation: this.transformation.serialize()
43742
+ transformation: this.transformation.serialize(),
43743
+ isLockedGroup: this.isLockedGroup
43698
43744
  };
43699
43745
  }
43700
43746
  deserialize(data) {
@@ -43704,6 +43750,9 @@ class Group extends BaseItem {
43704
43750
  if (data.children && data.children.length > 0) {
43705
43751
  this.applyAddChildren(data.children);
43706
43752
  }
43753
+ if (data.isLockedGroup !== undefined) {
43754
+ this.isLockedGroup = data.isLockedGroup;
43755
+ }
43707
43756
  this.subject.publish(this);
43708
43757
  return this;
43709
43758
  }
@@ -43842,7 +43891,7 @@ function createGroup(id, data, board) {
43842
43891
  if (!isGroupData(data)) {
43843
43892
  throw new Error("Invalid data for Group");
43844
43893
  }
43845
- const group = new Group(board, board.events, data.children, "").setId(id).deserialize(data);
43894
+ const group = new Group(board, board.events, data.children, id).setId(id).deserialize(data);
43846
43895
  return group;
43847
43896
  }
43848
43897
  function isStickerData(data) {
@@ -54655,12 +54704,17 @@ class Board {
54655
54704
  return this.applyAddItems(op);
54656
54705
  case "addLockedGroup":
54657
54706
  return this.applyAddLockedGroupOperation(op);
54707
+ case "addGroup":
54708
+ return this.applyAddGroupOperation(op);
54658
54709
  case "remove": {
54659
54710
  return this.applyRemoveOperation(op);
54660
54711
  }
54661
54712
  case "removeLockedGroup": {
54662
54713
  return this.applyRemoveLockedGroupOperation(op);
54663
54714
  }
54715
+ case "removeGroup": {
54716
+ return this.applyRemoveGroupOperation(op);
54717
+ }
54664
54718
  case "paste": {
54665
54719
  return this.applyPasteOperation(op.itemsMap);
54666
54720
  }
@@ -54698,11 +54752,23 @@ class Board {
54698
54752
  const zIndex = this.index.getZIndex(lastChildrenId) + 1;
54699
54753
  this.index.moveToZIndex(item, zIndex);
54700
54754
  }
54755
+ item.isLockedGroup = true;
54701
54756
  item.getChildren().forEach((item2) => {
54702
54757
  item2.transformation.isLocked = true;
54703
54758
  });
54704
54759
  item.transformation.isLocked = true;
54705
54760
  }
54761
+ applyAddGroupOperation(op) {
54762
+ const item = this.createItem(op.item, op.data);
54763
+ const groupChildrenIds = item.getChildrenIds();
54764
+ this.index.insert(item);
54765
+ const lastChildrenId = this.index.getById(groupChildrenIds[groupChildrenIds.length - 1]);
54766
+ if (lastChildrenId) {
54767
+ const zIndex = this.index.getZIndex(lastChildrenId) + 1;
54768
+ this.index.moveToZIndex(item, zIndex);
54769
+ }
54770
+ item.isLockedGroup = false;
54771
+ }
54706
54772
  applyRemoveOperation(op) {
54707
54773
  const removedItems = [];
54708
54774
  this.findItemAndApply(op.item, (item) => {
@@ -54731,6 +54797,21 @@ class Board {
54731
54797
  removedItems.push(item2);
54732
54798
  });
54733
54799
  }
54800
+ applyRemoveGroupOperation(op) {
54801
+ const item = this.index.getById(op.item[0]);
54802
+ if (!item || !(item instanceof Group)) {
54803
+ return;
54804
+ }
54805
+ item.getChildren().forEach((item2) => {
54806
+ item2.parent = "Board";
54807
+ });
54808
+ const removedItems = [];
54809
+ this.findItemAndApply(op.item, (item2) => {
54810
+ this.index.remove(item2);
54811
+ this.selection.remove(item2);
54812
+ removedItems.push(item2);
54813
+ });
54814
+ }
54734
54815
  applyItemOperation(op) {
54735
54816
  if ("item" in op) {
54736
54817
  this.findItemAndApply(op.item, (item) => {
@@ -54805,20 +54886,21 @@ class Board {
54805
54886
  this.handleNesting(newItem);
54806
54887
  return newItem;
54807
54888
  }
54808
- addLockedGroup(item) {
54889
+ addLockedGroup(items) {
54809
54890
  const id = this.getNewItemId();
54891
+ const groupData = {
54892
+ itemType: "Group",
54893
+ children: items.map((i) => i.getId()),
54894
+ transformation: { translateX: 0, translateY: 0, scaleX: 1, scaleY: 1, rotate: 0, isLocked: false },
54895
+ isLockedGroup: true
54896
+ };
54810
54897
  this.emit({
54811
54898
  class: "Board",
54812
54899
  method: "addLockedGroup",
54813
54900
  item: id,
54814
- data: item.serialize()
54901
+ data: groupData
54815
54902
  });
54816
- const newItem = this.items.getById(id);
54817
- if (!newItem) {
54818
- throw new Error(`Add item. Item ${id} was not created.`);
54819
- }
54820
- this.handleNesting(newItem);
54821
- return newItem;
54903
+ return this.items.getById(id);
54822
54904
  }
54823
54905
  remove(item, withConnectors = true) {
54824
54906
  let connectors = [];
@@ -54846,11 +54928,12 @@ class Board {
54846
54928
  const groupData = {
54847
54929
  itemType: "Group",
54848
54930
  children: items.map((i) => i.getId()),
54849
- transformation: { translateX: 0, translateY: 0, scaleX: 1, scaleY: 1, shearX: 0, shearY: 0 }
54931
+ transformation: { translateX: 0, translateY: 0, scaleX: 1, scaleY: 1, rotate: 0, isLocked: false },
54932
+ isLockedGroup: false
54850
54933
  };
54851
54934
  this.emit({
54852
54935
  class: "Board",
54853
- method: "addLockedGroup",
54936
+ method: "addGroup",
54854
54937
  item: id,
54855
54938
  data: groupData
54856
54939
  });
@@ -54859,7 +54942,7 @@ class Board {
54859
54942
  ungroup(group) {
54860
54943
  this.emit({
54861
54944
  class: "Board",
54862
- method: "removeLockedGroup",
54945
+ method: "removeGroup",
54863
54946
  item: [group.getId()]
54864
54947
  });
54865
54948
  }