microboard-temp 0.4.28 → 0.4.30

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
@@ -19306,9 +19306,19 @@ class BaseCommand {
19306
19306
  const items = this.items;
19307
19307
  return mapItemsByOperation(items, (item) => {
19308
19308
  const op = this.operation;
19309
+ let newData = {};
19310
+ if (op.prevData) {
19311
+ newData = op.prevData;
19312
+ } else {
19313
+ Object.keys(op.newData).forEach((key) => {
19314
+ if (item[key]) {
19315
+ op.newData[key] = item[key];
19316
+ }
19317
+ });
19318
+ }
19309
19319
  return {
19310
19320
  ...op,
19311
- newData: op.prevData
19321
+ newData
19312
19322
  };
19313
19323
  });
19314
19324
  }
@@ -46208,6 +46218,18 @@ class Dice extends BaseItem {
46208
46218
  }
46209
46219
  return { min: this.values[0], max: this.values[this.values.length - 1] };
46210
46220
  }
46221
+ getBackgroundColor() {
46222
+ return this.backgroundColor;
46223
+ }
46224
+ getBorderStyle() {
46225
+ return this.borderStyle;
46226
+ }
46227
+ getStrokeColor() {
46228
+ return this.borderColor;
46229
+ }
46230
+ getStrokeWidth() {
46231
+ return this.borderWidth;
46232
+ }
46211
46233
  applyBackgroundColor(backgroundColor) {
46212
46234
  this.backgroundColor = backgroundColor;
46213
46235
  this.path.setBackgroundColor(backgroundColor);
@@ -50148,28 +50170,20 @@ class BoardSelection {
50148
50170
  return color2;
50149
50171
  }
50150
50172
  getFillColor() {
50151
- const tmp = this.items.getItemsByItemTypes([
50152
- "Shape",
50153
- "Sticker",
50154
- "Frame"
50155
- ])[0];
50156
- return tmp?.getBackgroundColor() || defaultShapeData2.backgroundColor;
50173
+ const tmp = this.items.list()[0];
50174
+ return "getBackgroundColor" in tmp ? tmp.getBackgroundColor() : defaultShapeData2.backgroundColor;
50157
50175
  }
50158
50176
  getBorderStyle() {
50159
- const shape = this.items.getItemsByItemTypes([
50160
- "Shape",
50161
- "Drawing",
50162
- "Connector"
50163
- ])[0];
50164
- return shape?.getBorderStyle() || defaultShapeData2.borderStyle;
50177
+ const shape = this.items.list()[0];
50178
+ return "getBorderStyle" in shape ? shape.getBorderStyle() : defaultShapeData2.borderStyle;
50165
50179
  }
50166
50180
  getStrokeColor() {
50167
- const shape = this.items.getItemsByItemTypes(["Shape", "Drawing"])[0];
50168
- return shape?.getStrokeColor() || defaultShapeData2.borderColor;
50181
+ const shape = this.items.list()[0];
50182
+ return "getStrokeColor" in shape ? shape.getStrokeColor() : defaultShapeData2.borderColor;
50169
50183
  }
50170
50184
  getStrokeWidth() {
50171
- const shape = this.items.getItemsByItemTypes(["Shape", "Drawing"])[0];
50172
- return shape?.getStrokeWidth() || defaultShapeData2.borderWidth;
50185
+ const shape = this.items.list()[0];
50186
+ return "getStrokeWidth" in shape ? shape.getStrokeWidth() : defaultShapeData2.borderWidth;
50173
50187
  }
50174
50188
  getConnectorLineWidth() {
50175
50189
  const connector = this.items.getItemsByItemTypes(["Connector"])[0];
@@ -50369,93 +50383,85 @@ class BoardSelection {
50369
50383
  }
50370
50384
  }
50371
50385
  setStrokeColor(borderColor) {
50372
- const shapes = this.items.getIdsByItemTypes(["Shape"]);
50373
- if (shapes.length > 0) {
50374
- this.emit({
50375
- class: "Shape",
50376
- method: "setBorderColor",
50377
- item: shapes,
50378
- borderColor
50379
- });
50380
- }
50381
- const connectors = this.items.getIdsByItemTypes(["Connector"]);
50382
- if (connectors.length > 0) {
50383
- this.emit({
50384
- class: "Connector",
50385
- method: "setLineColor",
50386
- item: connectors,
50387
- lineColor: borderColor
50388
- });
50389
- }
50390
- const drawings = this.items.getIdsByItemTypes(["Drawing"]);
50391
- if (drawings.length > 0) {
50392
- this.emit({
50393
- class: "Drawing",
50394
- method: "setStrokeColor",
50395
- item: drawings,
50396
- color: borderColor
50397
- });
50398
- }
50386
+ const operation = {
50387
+ class: "Shape",
50388
+ method: "setBorderColor",
50389
+ item: [],
50390
+ newData: { borderColor }
50391
+ };
50392
+ const operations2 = {};
50393
+ this.items.list().forEach((item) => {
50394
+ if (!operations2[item.itemType]) {
50395
+ const operationCopy = { ...operation };
50396
+ if (item.itemType === "Connector") {
50397
+ operationCopy.method = "setLineColor";
50398
+ operationCopy.lineColor = borderColor;
50399
+ } else if (item.itemType === "Drawing") {
50400
+ operationCopy.method = "setStrokeColor";
50401
+ operationCopy.color = borderColor;
50402
+ } else {
50403
+ operationCopy.borderColor = borderColor;
50404
+ }
50405
+ operations2[item.itemType] = { ...operationCopy, class: item.itemType, item: [item.getId()] };
50406
+ } else {
50407
+ operations2[item.itemType].item.push(item.getId());
50408
+ }
50409
+ });
50410
+ Object.values(operations2).forEach((op) => {
50411
+ this.emit(op);
50412
+ });
50399
50413
  }
50400
50414
  setStrokeWidth(width2) {
50401
- const shapes = this.items.getIdsByItemTypes(["Shape"]);
50402
- if (shapes.length > 0) {
50403
- this.emit({
50404
- class: "Shape",
50405
- method: "setBorderWidth",
50406
- item: shapes,
50407
- borderWidth: width2,
50408
- prevBorderWidth: this.getStrokeWidth()
50409
- });
50410
- }
50411
- const connectors = this.items.getIdsByItemTypes(["Connector"]);
50412
- if (connectors.length > 0) {
50413
- this.emit({
50414
- class: "Connector",
50415
- method: "setLineWidth",
50416
- item: connectors,
50417
- lineWidth: width2
50418
- });
50419
- }
50420
- const drawings = this.items.getIdsByItemTypes(["Drawing"]);
50421
- if (drawings.length > 0) {
50422
- this.emit({
50423
- class: "Drawing",
50424
- method: "setStrokeWidth",
50425
- item: drawings,
50426
- width: width2,
50427
- prevWidth: this.getStrokeWidth()
50428
- });
50429
- }
50415
+ const operation = {
50416
+ class: "Shape",
50417
+ method: "setStrokeWidth",
50418
+ item: [],
50419
+ width: width2,
50420
+ newData: { width: width2 }
50421
+ };
50422
+ const operations2 = {};
50423
+ this.items.list().forEach((item) => {
50424
+ if (!operations2[item.itemType]) {
50425
+ const operationCopy = { ...operation };
50426
+ if (item.itemType === "Connector") {
50427
+ operationCopy.method = "setLineWidth";
50428
+ operationCopy.lineWidth = width2;
50429
+ } else if (item.itemType === "Drawing") {
50430
+ operationCopy.method = "setStrokeWidth";
50431
+ operationCopy.width = width2;
50432
+ operationCopy.prevWidth = this.getStrokeWidth();
50433
+ } else {
50434
+ operationCopy.borderWidth = width2;
50435
+ operationCopy.prevBorderWidth = this.getStrokeWidth();
50436
+ }
50437
+ operations2[item.itemType] = { ...operationCopy, class: item.itemType, item: [item.getId()] };
50438
+ } else {
50439
+ operations2[item.itemType].item.push(item.getId());
50440
+ }
50441
+ });
50442
+ Object.values(operations2).forEach((op) => {
50443
+ this.emit(op);
50444
+ });
50430
50445
  }
50431
50446
  setFillColor(backgroundColor) {
50432
- const shapes = this.items.getIdsByItemTypes(["Shape"]);
50433
- if (shapes.length) {
50434
- this.emit({
50435
- class: "Shape",
50436
- method: "setBackgroundColor",
50437
- item: shapes,
50438
- backgroundColor
50439
- });
50440
- }
50441
- const stickers = this.items.getIdsByItemTypes(["Sticker"]);
50442
- if (stickers.length) {
50443
- this.emit({
50444
- class: "Sticker",
50445
- method: "setBackgroundColor",
50446
- item: stickers,
50447
- backgroundColor
50448
- });
50449
- }
50450
- const frames = this.items.getIdsByItemTypes(["Frame"]);
50451
- if (frames.length) {
50452
- this.emit({
50453
- class: "Frame",
50454
- method: "setBackgroundColor",
50455
- item: frames,
50456
- backgroundColor
50457
- });
50458
- }
50447
+ const operation = {
50448
+ class: "Shape",
50449
+ method: "setBackgroundColor",
50450
+ item: [],
50451
+ backgroundColor,
50452
+ newData: { backgroundColor }
50453
+ };
50454
+ const operations2 = {};
50455
+ this.items.list().forEach((item) => {
50456
+ if (!operations2[item.itemType]) {
50457
+ operations2[item.itemType] = { ...operation, class: item.itemType, item: [item.getId()] };
50458
+ } else {
50459
+ operations2[item.itemType].item.push(item.getId());
50460
+ }
50461
+ });
50462
+ Object.values(operations2).forEach((op) => {
50463
+ this.emit(op);
50464
+ });
50459
50465
  }
50460
50466
  setCanChangeRatio(canChangeRatio) {
50461
50467
  const frames = this.items.getIdsByItemTypes(["Frame"]);
package/dist/esm/node.js CHANGED
@@ -21840,9 +21840,19 @@ class BaseCommand {
21840
21840
  const items = this.items;
21841
21841
  return mapItemsByOperation(items, (item) => {
21842
21842
  const op = this.operation;
21843
+ let newData = {};
21844
+ if (op.prevData) {
21845
+ newData = op.prevData;
21846
+ } else {
21847
+ Object.keys(op.newData).forEach((key) => {
21848
+ if (item[key]) {
21849
+ op.newData[key] = item[key];
21850
+ }
21851
+ });
21852
+ }
21843
21853
  return {
21844
21854
  ...op,
21845
- newData: op.prevData
21855
+ newData
21846
21856
  };
21847
21857
  });
21848
21858
  }
@@ -48743,6 +48753,18 @@ class Dice extends BaseItem {
48743
48753
  }
48744
48754
  return { min: this.values[0], max: this.values[this.values.length - 1] };
48745
48755
  }
48756
+ getBackgroundColor() {
48757
+ return this.backgroundColor;
48758
+ }
48759
+ getBorderStyle() {
48760
+ return this.borderStyle;
48761
+ }
48762
+ getStrokeColor() {
48763
+ return this.borderColor;
48764
+ }
48765
+ getStrokeWidth() {
48766
+ return this.borderWidth;
48767
+ }
48746
48768
  applyBackgroundColor(backgroundColor) {
48747
48769
  this.backgroundColor = backgroundColor;
48748
48770
  this.path.setBackgroundColor(backgroundColor);
@@ -52683,28 +52705,20 @@ class BoardSelection {
52683
52705
  return color2;
52684
52706
  }
52685
52707
  getFillColor() {
52686
- const tmp = this.items.getItemsByItemTypes([
52687
- "Shape",
52688
- "Sticker",
52689
- "Frame"
52690
- ])[0];
52691
- return tmp?.getBackgroundColor() || defaultShapeData2.backgroundColor;
52708
+ const tmp = this.items.list()[0];
52709
+ return "getBackgroundColor" in tmp ? tmp.getBackgroundColor() : defaultShapeData2.backgroundColor;
52692
52710
  }
52693
52711
  getBorderStyle() {
52694
- const shape = this.items.getItemsByItemTypes([
52695
- "Shape",
52696
- "Drawing",
52697
- "Connector"
52698
- ])[0];
52699
- return shape?.getBorderStyle() || defaultShapeData2.borderStyle;
52712
+ const shape = this.items.list()[0];
52713
+ return "getBorderStyle" in shape ? shape.getBorderStyle() : defaultShapeData2.borderStyle;
52700
52714
  }
52701
52715
  getStrokeColor() {
52702
- const shape = this.items.getItemsByItemTypes(["Shape", "Drawing"])[0];
52703
- return shape?.getStrokeColor() || defaultShapeData2.borderColor;
52716
+ const shape = this.items.list()[0];
52717
+ return "getStrokeColor" in shape ? shape.getStrokeColor() : defaultShapeData2.borderColor;
52704
52718
  }
52705
52719
  getStrokeWidth() {
52706
- const shape = this.items.getItemsByItemTypes(["Shape", "Drawing"])[0];
52707
- return shape?.getStrokeWidth() || defaultShapeData2.borderWidth;
52720
+ const shape = this.items.list()[0];
52721
+ return "getStrokeWidth" in shape ? shape.getStrokeWidth() : defaultShapeData2.borderWidth;
52708
52722
  }
52709
52723
  getConnectorLineWidth() {
52710
52724
  const connector = this.items.getItemsByItemTypes(["Connector"])[0];
@@ -52904,93 +52918,85 @@ class BoardSelection {
52904
52918
  }
52905
52919
  }
52906
52920
  setStrokeColor(borderColor) {
52907
- const shapes = this.items.getIdsByItemTypes(["Shape"]);
52908
- if (shapes.length > 0) {
52909
- this.emit({
52910
- class: "Shape",
52911
- method: "setBorderColor",
52912
- item: shapes,
52913
- borderColor
52914
- });
52915
- }
52916
- const connectors = this.items.getIdsByItemTypes(["Connector"]);
52917
- if (connectors.length > 0) {
52918
- this.emit({
52919
- class: "Connector",
52920
- method: "setLineColor",
52921
- item: connectors,
52922
- lineColor: borderColor
52923
- });
52924
- }
52925
- const drawings = this.items.getIdsByItemTypes(["Drawing"]);
52926
- if (drawings.length > 0) {
52927
- this.emit({
52928
- class: "Drawing",
52929
- method: "setStrokeColor",
52930
- item: drawings,
52931
- color: borderColor
52932
- });
52933
- }
52921
+ const operation = {
52922
+ class: "Shape",
52923
+ method: "setBorderColor",
52924
+ item: [],
52925
+ newData: { borderColor }
52926
+ };
52927
+ const operations2 = {};
52928
+ this.items.list().forEach((item) => {
52929
+ if (!operations2[item.itemType]) {
52930
+ const operationCopy = { ...operation };
52931
+ if (item.itemType === "Connector") {
52932
+ operationCopy.method = "setLineColor";
52933
+ operationCopy.lineColor = borderColor;
52934
+ } else if (item.itemType === "Drawing") {
52935
+ operationCopy.method = "setStrokeColor";
52936
+ operationCopy.color = borderColor;
52937
+ } else {
52938
+ operationCopy.borderColor = borderColor;
52939
+ }
52940
+ operations2[item.itemType] = { ...operationCopy, class: item.itemType, item: [item.getId()] };
52941
+ } else {
52942
+ operations2[item.itemType].item.push(item.getId());
52943
+ }
52944
+ });
52945
+ Object.values(operations2).forEach((op) => {
52946
+ this.emit(op);
52947
+ });
52934
52948
  }
52935
52949
  setStrokeWidth(width2) {
52936
- const shapes = this.items.getIdsByItemTypes(["Shape"]);
52937
- if (shapes.length > 0) {
52938
- this.emit({
52939
- class: "Shape",
52940
- method: "setBorderWidth",
52941
- item: shapes,
52942
- borderWidth: width2,
52943
- prevBorderWidth: this.getStrokeWidth()
52944
- });
52945
- }
52946
- const connectors = this.items.getIdsByItemTypes(["Connector"]);
52947
- if (connectors.length > 0) {
52948
- this.emit({
52949
- class: "Connector",
52950
- method: "setLineWidth",
52951
- item: connectors,
52952
- lineWidth: width2
52953
- });
52954
- }
52955
- const drawings = this.items.getIdsByItemTypes(["Drawing"]);
52956
- if (drawings.length > 0) {
52957
- this.emit({
52958
- class: "Drawing",
52959
- method: "setStrokeWidth",
52960
- item: drawings,
52961
- width: width2,
52962
- prevWidth: this.getStrokeWidth()
52963
- });
52964
- }
52950
+ const operation = {
52951
+ class: "Shape",
52952
+ method: "setStrokeWidth",
52953
+ item: [],
52954
+ width: width2,
52955
+ newData: { width: width2 }
52956
+ };
52957
+ const operations2 = {};
52958
+ this.items.list().forEach((item) => {
52959
+ if (!operations2[item.itemType]) {
52960
+ const operationCopy = { ...operation };
52961
+ if (item.itemType === "Connector") {
52962
+ operationCopy.method = "setLineWidth";
52963
+ operationCopy.lineWidth = width2;
52964
+ } else if (item.itemType === "Drawing") {
52965
+ operationCopy.method = "setStrokeWidth";
52966
+ operationCopy.width = width2;
52967
+ operationCopy.prevWidth = this.getStrokeWidth();
52968
+ } else {
52969
+ operationCopy.borderWidth = width2;
52970
+ operationCopy.prevBorderWidth = this.getStrokeWidth();
52971
+ }
52972
+ operations2[item.itemType] = { ...operationCopy, class: item.itemType, item: [item.getId()] };
52973
+ } else {
52974
+ operations2[item.itemType].item.push(item.getId());
52975
+ }
52976
+ });
52977
+ Object.values(operations2).forEach((op) => {
52978
+ this.emit(op);
52979
+ });
52965
52980
  }
52966
52981
  setFillColor(backgroundColor) {
52967
- const shapes = this.items.getIdsByItemTypes(["Shape"]);
52968
- if (shapes.length) {
52969
- this.emit({
52970
- class: "Shape",
52971
- method: "setBackgroundColor",
52972
- item: shapes,
52973
- backgroundColor
52974
- });
52975
- }
52976
- const stickers = this.items.getIdsByItemTypes(["Sticker"]);
52977
- if (stickers.length) {
52978
- this.emit({
52979
- class: "Sticker",
52980
- method: "setBackgroundColor",
52981
- item: stickers,
52982
- backgroundColor
52983
- });
52984
- }
52985
- const frames = this.items.getIdsByItemTypes(["Frame"]);
52986
- if (frames.length) {
52987
- this.emit({
52988
- class: "Frame",
52989
- method: "setBackgroundColor",
52990
- item: frames,
52991
- backgroundColor
52992
- });
52993
- }
52982
+ const operation = {
52983
+ class: "Shape",
52984
+ method: "setBackgroundColor",
52985
+ item: [],
52986
+ backgroundColor,
52987
+ newData: { backgroundColor }
52988
+ };
52989
+ const operations2 = {};
52990
+ this.items.list().forEach((item) => {
52991
+ if (!operations2[item.itemType]) {
52992
+ operations2[item.itemType] = { ...operation, class: item.itemType, item: [item.getId()] };
52993
+ } else {
52994
+ operations2[item.itemType].item.push(item.getId());
52995
+ }
52996
+ });
52997
+ Object.values(operations2).forEach((op) => {
52998
+ this.emit(op);
52999
+ });
52994
53000
  }
52995
53001
  setCanChangeRatio(canChangeRatio) {
52996
53002
  const frames = this.items.getIdsByItemTypes(["Frame"]);
@@ -29,7 +29,7 @@ export interface BaseOperation<T extends Record<string, unknown> = {}> {
29
29
  item: string[];
30
30
  method: string;
31
31
  newData: T;
32
- prevData: T;
32
+ prevData?: T;
33
33
  }
34
34
  export type ItemOperation = LinkToOperation | TransformationOperation | ShapeOperation | StickerOperation | RichTextOperation | ConnectorOperation | DrawingOperation | FrameOperation | PlaceholderOperation | GroupOperation | CommentOperation | ImageOperation | VideoOperation | AudioOperation;
35
35
  export type UndoableOperation = BoardOps | ItemOperation;
@@ -32,6 +32,10 @@ export declare class Dice extends BaseItem {
32
32
  min: number;
33
33
  max: number;
34
34
  };
35
+ getBackgroundColor(): string;
36
+ getBorderStyle(): string;
37
+ getStrokeColor(): string;
38
+ getStrokeWidth(): number;
35
39
  private applyBackgroundColor;
36
40
  setBackgroundColor(backgroundColor: string): void;
37
41
  private applyBorderWidth;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "microboard-temp",
3
- "version": "0.4.28",
3
+ "version": "0.4.30",
4
4
  "description": "A flexible interactive whiteboard library",
5
5
  "main": "dist/cjs/index.js",
6
6
  "module": "dist/esm/index.js",