@fluidframework/matrix 2.0.0-internal.4.1.2 → 2.0.0-internal.4.2.0

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.
@@ -5,5 +5,5 @@
5
5
  * THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY
6
6
  */
7
7
  export declare const pkgName = "@fluidframework/matrix";
8
- export declare const pkgVersion = "2.0.0-internal.4.1.2";
8
+ export declare const pkgVersion = "2.0.0-internal.4.2.0";
9
9
  //# sourceMappingURL=packageVersion.d.ts.map
@@ -8,5 +8,5 @@
8
8
  Object.defineProperty(exports, "__esModule", { value: true });
9
9
  exports.pkgVersion = exports.pkgName = void 0;
10
10
  exports.pkgName = "@fluidframework/matrix";
11
- exports.pkgVersion = "2.0.0-internal.4.1.2";
11
+ exports.pkgVersion = "2.0.0-internal.4.2.0";
12
12
  //# sourceMappingURL=packageVersion.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"packageVersion.js","sourceRoot":"","sources":["../src/packageVersion.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;;AAEU,QAAA,OAAO,GAAG,wBAAwB,CAAC;AACnC,QAAA,UAAU,GAAG,sBAAsB,CAAC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n *\n * THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY\n */\n\nexport const pkgName = \"@fluidframework/matrix\";\nexport const pkgVersion = \"2.0.0-internal.4.1.2\";\n"]}
1
+ {"version":3,"file":"packageVersion.js","sourceRoot":"","sources":["../src/packageVersion.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;;AAEU,QAAA,OAAO,GAAG,wBAAwB,CAAC;AACnC,QAAA,UAAU,GAAG,sBAAsB,CAAC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n *\n * THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY\n */\n\nexport const pkgName = \"@fluidframework/matrix\";\nexport const pkgVersion = \"2.0.0-internal.4.2.0\";\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"undoprovider.d.ts","sourceRoot":"","sources":["../src/undoprovider.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAGH,OAAO,EAEN,2BAA2B,EAE3B,MAAM,4BAA4B,CAAC;AACpC,OAAO,EAAE,UAAU,EAAE,YAAY,EAAE,MAAM,UAAU,CAAC;AACpD,OAAO,EAAE,MAAM,EAAiB,MAAM,eAAe,CAAC;AACtD,OAAO,EAAE,kBAAkB,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AAC5E,OAAO,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AAExC,qBAAa,kBAAkB;IAQ7B,OAAO,CAAC,QAAQ,CAAC,OAAO;IACxB,OAAO,CAAC,QAAQ,CAAC,UAAU;IAC3B,OAAO,CAAC,QAAQ,CAAC,UAAU;IAN5B,OAAO,CAAC,YAAY,CAAC,CAAgB;IACrC,OAAO,CAAC,SAAS,CAAC,CAAqB;gBAGrB,OAAO,EAAE,aAAa,EACtB,UAAU,EAAE,CAAC,OAAO,EAAE,kBAAkB,KAAK,IAAI,EACjD,UAAU,EAAE,CAAC,OAAO,EAAE,kBAAkB,KAAK,IAAI;IAG5D,MAAM,CACZ,SAAS,EAAE,2BAA2B,EACtC,MAAM,EAAE;QAAE,OAAO,EAAE,kBAAkB,CAAA;KAAE,EAAE;IAuD1C,OAAO,CAAC,cAAc;CAwCtB;AAED,qBAAa,kBAAkB,CAAC,CAAC;IAE/B,OAAO,CAAC,QAAQ,CAAC,QAAQ;IACzB,OAAO,CAAC,QAAQ,CAAC,MAAM;IACvB,OAAO,CAAC,QAAQ,CAAC,IAAI;IACrB,OAAO,CAAC,QAAQ,CAAC,IAAI;gBAHJ,QAAQ,EAAE,aAAa,EACvB,MAAM,EAAE,YAAY,CAAC,CAAC,C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,EAAE,aAAa,EACvB,MAAM,EAAE,YAAY,CAAC,CAAC,CAAC,EACvB,IAAI,EAAE,iBAAiB,EACvB,IAAI,EAAE,iBAAiB;IA4BzC,OAAO,CAAC,SAAS,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,EAAE,QAAQ,EAAE,UAAU,CAAC,CAAC,CAAC;CAoBrE"}
@@ -98,16 +98,20 @@ class MatrixUndoProvider {
98
98
  this.cols = cols;
99
99
  rows.undo = new VectorUndoProvider(consumer,
100
100
  /* undoInsert: */ (segment) => {
101
- const start = this.rows.getPosition(segment);
102
- this.matrix.removeRows(start, segment.cachedLength);
101
+ if ((0, merge_tree_1.toRemovalInfo)(segment) === undefined) {
102
+ const start = this.rows.getPosition(segment);
103
+ this.matrix.removeRows(start, segment.cachedLength);
104
+ }
103
105
  },
104
106
  /* undoRemove: */ (segment) => {
105
107
  this.matrix._undoRemoveRows(segment);
106
108
  });
107
109
  cols.undo = new VectorUndoProvider(consumer,
108
110
  /* undoInsert: */ (segment) => {
109
- const start = this.cols.getPosition(segment);
110
- this.matrix.removeCols(start, segment.cachedLength);
111
+ if ((0, merge_tree_1.toRemovalInfo)(segment) === undefined) {
112
+ const start = this.cols.getPosition(segment);
113
+ this.matrix.removeCols(start, segment.cachedLength);
114
+ }
111
115
  },
112
116
  /* undoRemove: */ (segment) => {
113
117
  this.matrix._undoRemoveCols(segment);
@@ -118,7 +122,12 @@ class MatrixUndoProvider {
118
122
  if (this.consumer !== undefined) {
119
123
  this.consumer.pushToCurrentOperation({
120
124
  revert: () => {
121
- this.matrix.setCell(this.rows.handleToPosition(rowHandle), this.cols.handleToPosition(colHandle), oldValue);
125
+ const row = this.rows.handleToPosition(rowHandle);
126
+ const col = this.cols.handleToPosition(colHandle);
127
+ // if the row/column no longer exists, we cannot set the cell
128
+ if (row < this.matrix.rowCount && col < this.matrix.colCount) {
129
+ this.matrix.setCell(row, col, oldValue);
130
+ }
122
131
  },
123
132
  discard: () => { },
124
133
  });
@@ -1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,SAAS,CAAC,IAAI,IAAA,2BAAa,EAAC,SAAS,CAAC,EACpD,KAAK,CAAC,wDAAwD,CAC9D,CAAC;QAEF,IAAI,IAAI,CAAC,QAAQ,KAAK,SAAS,EAAE;YAChC,IAAI,CAAC,QAAQ,CAAC,sBAAsB,CAAC;gBACpC,MAAM,EAAE,GAAG,EAAE;oBACZ,IAAI,CAAC,MAAM,CAAC,OAAO,CAClB,IAAI,CAAC,IAAI,CAAC,gBAAgB,CAAC,SAAS,CAAC,EACrC,IAAI,CAAC,IAAI,CAAC,gBAAgB,CAAC,SAAS,CAAC,EACrC,QAAQ,CACR,CAAC;gBACH,CAAC;gBACD,OAAO,EAAE,GAAG,EAAE,GAAE,CAAC;aACjB,CAAC,CAAC;SACH;IACF,CAAC;CACD;AAhDD,gDAgDC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { assert } from \"@fluidframework/common-utils\";\nimport {\n\tTrackingGroup,\n\tMergeTreeDeltaOperationType,\n\tMergeTreeDeltaType,\n} from \"@fluidframework/merge-tree\";\nimport { MatrixItem, SharedMatrix } from \"./matrix\";\nimport { Handle, isHandleValid } from \"./handletable\";\nimport { PermutationSegment, PermutationVector } from \"./permutationvector\";\nimport { IUndoConsumer } from \"./types\";\n\nexport class VectorUndoProvider {\n\t// 'currentGroup' and 'currentOp' are used while applying an IRevertable.revert() to coalesce\n\t// the recorded into a single IRevertable / tracking group as they move between the undo <->\n\t// redo stacks.\n\tprivate currentGroup?: TrackingGroup;\n\tprivate currentOp?: MergeTreeDeltaType;\n\n\tconstructor(\n\t\tprivate readonly manager: IUndoConsumer,\n\t\tprivate readonly undoInsert: (segment: PermutationSegment) => void,\n\t\tprivate readonly undoRemove: (segment: PermutationSegment) => void,\n\t) {}\n\n\tpublic record(\n\t\toperation: MergeTreeDeltaOperationType,\n\t\tranges: { segment: PermutationSegment }[],\n\t) {\n\t\tif (ranges.length > 0) {\n\t\t\t// Link each segment to a new TrackingGroup. A TrackingGroup keeps track of the original\n\t\t\t// set of linked segments, including any fragmentatiton that occurs due to future splitting.\n\t\t\t//\n\t\t\t// A TrackingGroup also prevents removed segments from being unlinked from the tree during\n\t\t\t// Zamboni and guarantees segments will not be merged/coalesced with segments outside of the\n\t\t\t// current tracking group.\n\t\t\t//\n\t\t\t// These properties allow us to rely on MergeTree.getPosition() to find the locations/lengths\n\t\t\t// of all content contained within the tracking group in the future.\n\n\t\t\t// If we are in the process of reverting, the `IRevertible.revert()` will provide the tracking\n\t\t\t// group so that we can preserve the original segment ranges as a single op/group as we move\n\t\t\t// ops between the undo <-> redo stacks.\n\t\t\tconst trackingGroup = this.currentGroup ?? new TrackingGroup();\n\t\t\tfor (const range of ranges) {\n\t\t\t\ttrackingGroup.link(range.segment);\n\t\t\t}\n\n\t\t\t// For SharedMatrix, each IRevertibles always holds a single row/col operation.\n\t\t\t// Therefore, 'currentOp' must either be undefined or equal to the current op.\n\t\t\tassert(\n\t\t\t\tthis.currentOp === undefined || this.currentOp === operation,\n\t\t\t\t0x02a /* \"On vector undo, unexpected 'currentOp' type/state!\" */,\n\t\t\t);\n\n\t\t\tswitch (operation) {\n\t\t\t\tcase MergeTreeDeltaType.INSERT:\n\t\t\t\t\tif (this.currentOp !== MergeTreeDeltaType.INSERT) {\n\t\t\t\t\t\tthis.pushRevertible(trackingGroup, this.undoInsert);\n\t\t\t\t\t}\n\t\t\t\t\tbreak;\n\n\t\t\t\tcase MergeTreeDeltaType.REMOVE: {\n\t\t\t\t\tif (this.currentOp !== MergeTreeDeltaType.REMOVE) {\n\t\t\t\t\t\tthis.pushRevertible(trackingGroup, this.undoRemove);\n\t\t\t\t\t}\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\n\t\t\t\tdefault:\n\t\t\t\t\tthrow new Error(\"operation type not revertible\");\n\t\t\t}\n\n\t\t\t// If we are in the process of reverting, set 'currentOp' to remind ourselves not to push\n\t\t\t// another revertible until `IRevertable.revert()` finishes the current op and clears this\n\t\t\t// field.\n\t\t\tif (this.currentGroup !== undefined) {\n\t\t\t\tthis.currentOp = operation;\n\t\t\t}\n\t\t}\n\t}\n\n\tprivate pushRevertible(\n\t\ttrackingGroup: TrackingGroup,\n\t\tcallback: (segment: PermutationSegment) => void,\n\t) {\n\t\tconst revertible = {\n\t\t\trevert: () => {\n\t\t\t\tassert(\n\t\t\t\t\tthis.currentGroup === undefined && this.currentOp === undefined,\n\t\t\t\t\t0x02b /* \"Must not nest calls to IRevertible.revert()\" */,\n\t\t\t\t);\n\n\t\t\t\tthis.currentGroup = new TrackingGroup();\n\n\t\t\t\ttry {\n\t\t\t\t\twhile (trackingGroup.size > 0) {\n\t\t\t\t\t\tconst segment = trackingGroup.segments[0] as PermutationSegment;\n\n\t\t\t\t\t\t// Unlink 'segment' from the current tracking group before invoking the callback\n\t\t\t\t\t\t// to exclude the current undo/redo segment from those copied to the replacement\n\t\t\t\t\t\t// segment (if any). (See 'PermutationSegment.transferToReplacement()')\n\t\t\t\t\t\tsegment.trackingCollection.unlink(trackingGroup);\n\n\t\t\t\t\t\tcallback(segment);\n\t\t\t\t\t}\n\t\t\t\t} finally {\n\t\t\t\t\tthis.currentOp = undefined;\n\t\t\t\t\tthis.currentGroup = undefined;\n\t\t\t\t}\n\t\t\t},\n\t\t\tdiscard: () => {\n\t\t\t\twhile (trackingGroup.size > 0) {\n\t\t\t\t\ttrackingGroup.unlink(trackingGroup.segments[0]);\n\t\t\t\t}\n\t\t\t},\n\t\t};\n\n\t\tthis.manager.pushToCurrentOperation(revertible);\n\n\t\treturn revertible;\n\t}\n}\n\nexport class MatrixUndoProvider<T> {\n\tconstructor(\n\t\tprivate readonly consumer: IUndoConsumer,\n\t\tprivate readonly matrix: SharedMatrix<T>,\n\t\tprivate readonly rows: PermutationVector,\n\t\tprivate readonly cols: PermutationVector,\n\t) {\n\t\trows.undo = new VectorUndoProvider(\n\t\t\tconsumer,\n\t\t\t/* undoInsert: */ (segment: PermutationSegment) => {\n\t\t\t\tconst start = this.rows.getPosition(segment);\n\t\t\t\tthis.matrix.removeRows(start, segment.cachedLength);\n\t\t\t},\n\t\t\t/* undoRemove: */ (segment: PermutationSegment) => {\n\t\t\t\tthis.matrix._undoRemoveRows(segment);\n\t\t\t},\n\t\t);\n\t\tcols.undo = new VectorUndoProvider(\n\t\t\tconsumer,\n\t\t\t/* undoInsert: */ (segment: PermutationSegment) => {\n\t\t\t\tconst start = this.cols.getPosition(segment);\n\t\t\t\tthis.matrix.removeCols(start, segment.cachedLength);\n\t\t\t},\n\t\t\t/* undoRemove: */ (segment: PermutationSegment) => {\n\t\t\t\tthis.matrix._undoRemoveCols(segment);\n\t\t\t},\n\t\t);\n\t}\n\n\tcellSet(rowHandle: Handle, colHandle: Handle, oldValue: MatrixItem<T>) {\n\t\tassert(\n\t\t\tisHandleValid(rowHandle) && isHandleValid(colHandle),\n\t\t\t0x02c /* \"On cellSet(), invalid row and/or column handles!\" */,\n\t\t);\n\n\t\tif (this.consumer !== undefined) {\n\t\t\tthis.consumer.pushToCurrentOperation({\n\t\t\t\trevert: () => {\n\t\t\t\t\tthis.matrix.setCell(\n\t\t\t\t\t\tthis.rows.handleToPosition(rowHandle),\n\t\t\t\t\t\tthis.cols.handleToPosition(colHandle),\n\t\t\t\t\t\toldValue,\n\t\t\t\t\t);\n\t\t\t\t},\n\t\t\t\tdiscard: () => {},\n\t\t\t});\n\t\t}\n\t}\n}\n"]}
1
+ {"version":3,"file":"undoprovider.js","sourceRoot":"","sources":["../src/undoprovider.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAEH,+DAAsD;AACtD,2DAKoC;AAEpC,+CAAsD;AAItD,MAAa,kBAAkB;IAO9B,YACkB,OAAsB,EACtB,UAAiD,EACjD,UAAiD;QAFjD,YAAO,GAAP,OAAO,CAAe;QACtB,eAAU,GAAV,UAAU,CAAuC;QACjD,eAAU,GAAV,UAAU,CAAuC;IAChE,CAAC;IAEG,MAAM,CACZ,SAAsC,EACtC,MAA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EAAE;oBACZ,MAAM,GAAG,GAAG,IAAI,CAAC,IAAI,CAAC,gBAAgB,CAAC,SAAS,CAAC,CAAC;oBAClD,MAAM,GAAG,GAAG,IAAI,CAAC,IAAI,CAAC,gBAAgB,CAAC,SAAS,CAAC,CAAC;oBAClD,6DAA6D;oBAC7D,IAAI,GAAG,GAAG,IAAI,CAAC,MAAM,CAAC,QAAQ,IAAI,GAAG,GAAG,IAAI,CAAC,MAAM,CAAC,QAAQ,EAAE;wBAC7D,IAAI,CAAC,MAAM,CAAC,OAAO,CAAC,GAAG,EAAE,GAAG,EAAE,QAAQ,CAAC,CAAC;qBACxC;gBACF,CAAC;gBACD,OAAO,EAAE,GAAG,EAAE,GAAE,CAAC;aACjB,CAAC,CAAC;SACH;IACF,CAAC;CACD;AArDD,gDAqDC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { assert } from \"@fluidframework/common-utils\";\nimport {\n\tTrackingGroup,\n\tMergeTreeDeltaOperationType,\n\tMergeTreeDeltaType,\n\ttoRemovalInfo,\n} from \"@fluidframework/merge-tree\";\nimport { MatrixItem, SharedMatrix } from \"./matrix\";\nimport { Handle, isHandleValid } from \"./handletable\";\nimport { PermutationSegment, PermutationVector } from \"./permutationvector\";\nimport { IUndoConsumer } from \"./types\";\n\nexport class VectorUndoProvider {\n\t// 'currentGroup' and 'currentOp' are used while applying an IRevertable.revert() to coalesce\n\t// the recorded into a single IRevertable / tracking group as they move between the undo <->\n\t// redo stacks.\n\tprivate currentGroup?: TrackingGroup;\n\tprivate currentOp?: MergeTreeDeltaType;\n\n\tconstructor(\n\t\tprivate readonly manager: IUndoConsumer,\n\t\tprivate readonly undoInsert: (segment: PermutationSegment) => void,\n\t\tprivate readonly undoRemove: (segment: PermutationSegment) => void,\n\t) {}\n\n\tpublic record(\n\t\toperation: MergeTreeDeltaOperationType,\n\t\tranges: { segment: PermutationSegment }[],\n\t) {\n\t\tif (ranges.length > 0) {\n\t\t\t// Link each segment to a new TrackingGroup. A TrackingGroup keeps track of the original\n\t\t\t// set of linked segments, including any fragmentatiton that occurs due to future splitting.\n\t\t\t//\n\t\t\t// A TrackingGroup also prevents removed segments from being unlinked from the tree during\n\t\t\t// Zamboni and guarantees segments will not be merged/coalesced with segments outside of the\n\t\t\t// current tracking group.\n\t\t\t//\n\t\t\t// These properties allow us to rely on MergeTree.getPosition() to find the locations/lengths\n\t\t\t// of all content contained within the tracking group in the future.\n\n\t\t\t// If we are in the process of reverting, the `IRevertible.revert()` will provide the tracking\n\t\t\t// group so that we can preserve the original segment ranges as a single op/group as we move\n\t\t\t// ops between the undo <-> redo stacks.\n\t\t\tconst trackingGroup = this.currentGroup ?? new TrackingGroup();\n\t\t\tfor (const range of ranges) {\n\t\t\t\ttrackingGroup.link(range.segment);\n\t\t\t}\n\n\t\t\t// For SharedMatrix, each IRevertibles always holds a single row/col operation.\n\t\t\t// Therefore, 'currentOp' must either be undefined or equal to the current op.\n\t\t\tassert(\n\t\t\t\tthis.currentOp === undefined || this.currentOp === operation,\n\t\t\t\t0x02a /* \"On vector undo, unexpected 'currentOp' type/state!\" */,\n\t\t\t);\n\n\t\t\tswitch (operation) {\n\t\t\t\tcase MergeTreeDeltaType.INSERT:\n\t\t\t\t\tif (this.currentOp !== MergeTreeDeltaType.INSERT) {\n\t\t\t\t\t\tthis.pushRevertible(trackingGroup, this.undoInsert);\n\t\t\t\t\t}\n\t\t\t\t\tbreak;\n\n\t\t\t\tcase MergeTreeDeltaType.REMOVE: {\n\t\t\t\t\tif (this.currentOp !== MergeTreeDeltaType.REMOVE) {\n\t\t\t\t\t\tthis.pushRevertible(trackingGroup, this.undoRemove);\n\t\t\t\t\t}\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\n\t\t\t\tdefault:\n\t\t\t\t\tthrow new Error(\"operation type not revertible\");\n\t\t\t}\n\n\t\t\t// If we are in the process of reverting, set 'currentOp' to remind ourselves not to push\n\t\t\t// another revertible until `IRevertable.revert()` finishes the current op and clears this\n\t\t\t// field.\n\t\t\tif (this.currentGroup !== undefined) {\n\t\t\t\tthis.currentOp = operation;\n\t\t\t}\n\t\t}\n\t}\n\n\tprivate pushRevertible(\n\t\ttrackingGroup: TrackingGroup,\n\t\tcallback: (segment: PermutationSegment) => void,\n\t) {\n\t\tconst revertible = {\n\t\t\trevert: () => {\n\t\t\t\tassert(\n\t\t\t\t\tthis.currentGroup === undefined && this.currentOp === undefined,\n\t\t\t\t\t0x02b /* \"Must not nest calls to IRevertible.revert()\" */,\n\t\t\t\t);\n\n\t\t\t\tthis.currentGroup = new TrackingGroup();\n\n\t\t\t\ttry {\n\t\t\t\t\twhile (trackingGroup.size > 0) {\n\t\t\t\t\t\tconst segment = trackingGroup.segments[0] as PermutationSegment;\n\n\t\t\t\t\t\t// Unlink 'segment' from the current tracking group before invoking the callback\n\t\t\t\t\t\t// to exclude the current undo/redo segment from those copied to the replacement\n\t\t\t\t\t\t// segment (if any). (See 'PermutationSegment.transferToReplacement()')\n\t\t\t\t\t\tsegment.trackingCollection.unlink(trackingGroup);\n\n\t\t\t\t\t\tcallback(segment);\n\t\t\t\t\t}\n\t\t\t\t} finally {\n\t\t\t\t\tthis.currentOp = undefined;\n\t\t\t\t\tthis.currentGroup = undefined;\n\t\t\t\t}\n\t\t\t},\n\t\t\tdiscard: () => {\n\t\t\t\twhile (trackingGroup.size > 0) {\n\t\t\t\t\ttrackingGroup.unlink(trackingGroup.segments[0]);\n\t\t\t\t}\n\t\t\t},\n\t\t};\n\n\t\tthis.manager.pushToCurrentOperation(revertible);\n\n\t\treturn revertible;\n\t}\n}\n\nexport class MatrixUndoProvider<T> {\n\tconstructor(\n\t\tprivate readonly consumer: IUndoConsumer,\n\t\tprivate readonly matrix: SharedMatrix<T>,\n\t\tprivate readonly rows: PermutationVector,\n\t\tprivate readonly cols: PermutationVector,\n\t) {\n\t\trows.undo = new VectorUndoProvider(\n\t\t\tconsumer,\n\t\t\t/* undoInsert: */ (segment: PermutationSegment) => {\n\t\t\t\tif (toRemovalInfo(segment) === undefined) {\n\t\t\t\t\tconst start = this.rows.getPosition(segment);\n\t\t\t\t\tthis.matrix.removeRows(start, segment.cachedLength);\n\t\t\t\t}\n\t\t\t},\n\t\t\t/* undoRemove: */ (segment: PermutationSegment) => {\n\t\t\t\tthis.matrix._undoRemoveRows(segment);\n\t\t\t},\n\t\t);\n\t\tcols.undo = new VectorUndoProvider(\n\t\t\tconsumer,\n\t\t\t/* undoInsert: */ (segment: PermutationSegment) => {\n\t\t\t\tif (toRemovalInfo(segment) === undefined) {\n\t\t\t\t\tconst start = this.cols.getPosition(segment);\n\t\t\t\t\tthis.matrix.removeCols(start, segment.cachedLength);\n\t\t\t\t}\n\t\t\t},\n\t\t\t/* undoRemove: */ (segment: PermutationSegment) => {\n\t\t\t\tthis.matrix._undoRemoveCols(segment);\n\t\t\t},\n\t\t);\n\t}\n\n\tcellSet(rowHandle: Handle, colHandle: Handle, oldValue: MatrixItem<T>) {\n\t\tassert(\n\t\t\tisHandleValid(rowHandle) && isHandleValid(colHandle),\n\t\t\t0x02c /* \"On cellSet(), invalid row and/or column handles!\" */,\n\t\t);\n\n\t\tif (this.consumer !== undefined) {\n\t\t\tthis.consumer.pushToCurrentOperation({\n\t\t\t\trevert: () => {\n\t\t\t\t\tconst row = this.rows.handleToPosition(rowHandle);\n\t\t\t\t\tconst col = this.cols.handleToPosition(colHandle);\n\t\t\t\t\t// if the row/column no longer exists, we cannot set the cell\n\t\t\t\t\tif (row < this.matrix.rowCount && col < this.matrix.colCount) {\n\t\t\t\t\t\tthis.matrix.setCell(row, col, oldValue);\n\t\t\t\t\t}\n\t\t\t\t},\n\t\t\t\tdiscard: () => {},\n\t\t\t});\n\t\t}\n\t}\n}\n"]}
@@ -5,5 +5,5 @@
5
5
  * THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY
6
6
  */
7
7
  export declare const pkgName = "@fluidframework/matrix";
8
- export declare const pkgVersion = "2.0.0-internal.4.1.2";
8
+ export declare const pkgVersion = "2.0.0-internal.4.2.0";
9
9
  //# sourceMappingURL=packageVersion.d.ts.map
@@ -5,5 +5,5 @@
5
5
  * THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY
6
6
  */
7
7
  export const pkgName = "@fluidframework/matrix";
8
- export const pkgVersion = "2.0.0-internal.4.1.2";
8
+ export const pkgVersion = "2.0.0-internal.4.2.0";
9
9
  //# sourceMappingURL=packageVersion.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"packageVersion.js","sourceRoot":"","sources":["../src/packageVersion.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,MAAM,CAAC,MAAM,OAAO,GAAG,wBAAwB,CAAC;AAChD,MAAM,CAAC,MAAM,UAAU,GAAG,sBAAsB,CAAC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n *\n * THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY\n */\n\nexport const pkgName = \"@fluidframework/matrix\";\nexport const pkgVersion = \"2.0.0-internal.4.1.2\";\n"]}
1
+ {"version":3,"file":"packageVersion.js","sourceRoot":"","sources":["../src/packageVersion.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,MAAM,CAAC,MAAM,OAAO,GAAG,wBAAwB,CAAC;AAChD,MAAM,CAAC,MAAM,UAAU,GAAG,sBAAsB,CAAC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n *\n * THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY\n */\n\nexport const pkgName = \"@fluidframework/matrix\";\nexport const pkgVersion = \"2.0.0-internal.4.2.0\";\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"undoprovider.d.ts","sourceRoot":"","sources":["../src/undoprovider.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAGH,OAAO,EAEN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3,7 +3,7 @@
3
3
  * Licensed under the MIT License.
4
4
  */
5
5
  import { assert } from "@fluidframework/common-utils";
6
- import { TrackingGroup, MergeTreeDeltaType, } from "@fluidframework/merge-tree";
6
+ import { TrackingGroup, MergeTreeDeltaType, toRemovalInfo, } from "@fluidframework/merge-tree";
7
7
  import { isHandleValid } from "./handletable";
8
8
  export class VectorUndoProvider {
9
9
  constructor(manager, undoInsert, undoRemove) {
@@ -94,16 +94,20 @@ export class MatrixUndoProvider {
94
94
  this.cols = cols;
95
95
  rows.undo = new VectorUndoProvider(consumer,
96
96
  /* undoInsert: */ (segment) => {
97
- const start = this.rows.getPosition(segment);
98
- this.matrix.removeRows(start, segment.cachedLength);
97
+ if (toRemovalInfo(segment) === undefined) {
98
+ const start = this.rows.getPosition(segment);
99
+ this.matrix.removeRows(start, segment.cachedLength);
100
+ }
99
101
  },
100
102
  /* undoRemove: */ (segment) => {
101
103
  this.matrix._undoRemoveRows(segment);
102
104
  });
103
105
  cols.undo = new VectorUndoProvider(consumer,
104
106
  /* undoInsert: */ (segment) => {
105
- const start = this.cols.getPosition(segment);
106
- this.matrix.removeCols(start, segment.cachedLength);
107
+ if (toRemovalInfo(segment) === undefined) {
108
+ const start = this.cols.getPosition(segment);
109
+ this.matrix.removeCols(start, segment.cachedLength);
110
+ }
107
111
  },
108
112
  /* undoRemove: */ (segment) => {
109
113
  this.matrix._undoRemoveCols(segment);
@@ -114,7 +118,12 @@ export class MatrixUndoProvider {
114
118
  if (this.consumer !== undefined) {
115
119
  this.consumer.pushToCurrentOperation({
116
120
  revert: () => {
117
- this.matrix.setCell(this.rows.handleToPosition(rowHandle), this.cols.handleToPosition(colHandle), oldValue);
121
+ const row = this.rows.handleToPosition(rowHandle);
122
+ const col = this.cols.handleToPosition(colHandle);
123
+ // if the row/column no longer exists, we cannot set the cell
124
+ if (row < this.matrix.rowCount && col < this.matrix.colCount) {
125
+ this.matrix.setCell(row, col, oldValue);
126
+ }
118
127
  },
119
128
  discard: () => { },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D,CAAC;IACH,CAAC;IAED,OAAO,CAAC,SAAiB,EAAE,SAAiB,EAAE,QAAuB;QACpE,MAAM,CACL,aAAa,CAAC,SAAS,CAAC,IAAI,aAAa,CAAC,SAAS,CAAC,EACpD,KAAK,CAAC,wDAAwD,CAC9D,CAAC;QAEF,IAAI,IAAI,CAAC,QAAQ,KAAK,SAAS,EAAE;YAChC,IAAI,CAAC,QAAQ,CAAC,sBAAsB,CAAC;gBACpC,MAAM,EAAE,GAAG,EAAE;oBACZ,IAAI,CAAC,MAAM,CAAC,OAAO,CAClB,IAAI,CAAC,IAAI,CAAC,gBAAgB,CAAC,SAAS,CAAC,EACrC,IAAI,CAAC,IAAI,CAAC,gBAAgB,CAAC,SAAS,CAAC,EACrC,QAAQ,CACR,CAAC;gBACH,CAAC;gBACD,OAAO,EAAE,GAAG,EAAE,GAAE,CAAC;aACjB,CAAC,CAAC;SACH;IACF,CAAC;CACD","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { assert } from \"@fluidframework/common-utils\";\nimport {\n\tTrackingGroup,\n\tMergeTreeDeltaOperationType,\n\tMergeTreeDeltaType,\n} from \"@fluidframework/merge-tree\";\nimport { MatrixItem, SharedMatrix } from \"./matrix\";\nimport { Handle, isHandleValid } from \"./handletable\";\nimport { PermutationSegment, PermutationVector } from \"./permutationvector\";\nimport { IUndoConsumer } from \"./types\";\n\nexport class VectorUndoProvider {\n\t// 'currentGroup' and 'currentOp' are used while applying an IRevertable.revert() to coalesce\n\t// the recorded into a single IRevertable / tracking group as they move between the undo <->\n\t// redo stacks.\n\tprivate currentGroup?: TrackingGroup;\n\tprivate currentOp?: MergeTreeDeltaType;\n\n\tconstructor(\n\t\tprivate readonly manager: IUndoConsumer,\n\t\tprivate readonly undoInsert: (segment: PermutationSegment) => void,\n\t\tprivate readonly undoRemove: (segment: PermutationSegment) => void,\n\t) {}\n\n\tpublic record(\n\t\toperation: MergeTreeDeltaOperationType,\n\t\tranges: { segment: PermutationSegment }[],\n\t) {\n\t\tif (ranges.length > 0) {\n\t\t\t// Link each segment to a new TrackingGroup. A TrackingGroup keeps track of the original\n\t\t\t// set of linked segments, including any fragmentatiton that occurs due to future splitting.\n\t\t\t//\n\t\t\t// A TrackingGroup also prevents removed segments from being unlinked from the tree during\n\t\t\t// Zamboni and guarantees segments will not be merged/coalesced with segments outside of the\n\t\t\t// current tracking group.\n\t\t\t//\n\t\t\t// These properties allow us to rely on MergeTree.getPosition() to find the locations/lengths\n\t\t\t// of all content contained within the tracking group in the future.\n\n\t\t\t// If we are in the process of reverting, the `IRevertible.revert()` will provide the tracking\n\t\t\t// group so that we can preserve the original segment ranges as a single op/group as we move\n\t\t\t// ops between the undo <-> redo stacks.\n\t\t\tconst trackingGroup = this.currentGroup ?? new TrackingGroup();\n\t\t\tfor (const range of ranges) {\n\t\t\t\ttrackingGroup.link(range.segment);\n\t\t\t}\n\n\t\t\t// For SharedMatrix, each IRevertibles always holds a single row/col operation.\n\t\t\t// Therefore, 'currentOp' must either be undefined or equal to the current op.\n\t\t\tassert(\n\t\t\t\tthis.currentOp === undefined || this.currentOp === operation,\n\t\t\t\t0x02a /* \"On vector undo, unexpected 'currentOp' type/state!\" */,\n\t\t\t);\n\n\t\t\tswitch (operation) {\n\t\t\t\tcase MergeTreeDeltaType.INSERT:\n\t\t\t\t\tif (this.currentOp !== MergeTreeDeltaType.INSERT) {\n\t\t\t\t\t\tthis.pushRevertible(trackingGroup, this.undoInsert);\n\t\t\t\t\t}\n\t\t\t\t\tbreak;\n\n\t\t\t\tcase MergeTreeDeltaType.REMOVE: {\n\t\t\t\t\tif (this.currentOp !== MergeTreeDeltaType.REMOVE) {\n\t\t\t\t\t\tthis.pushRevertible(trackingGroup, this.undoRemove);\n\t\t\t\t\t}\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\n\t\t\t\tdefault:\n\t\t\t\t\tthrow new Error(\"operation type not revertible\");\n\t\t\t}\n\n\t\t\t// If we are in the process of reverting, set 'currentOp' to remind ourselves not to push\n\t\t\t// another revertible until `IRevertable.revert()` finishes the current op and clears this\n\t\t\t// field.\n\t\t\tif (this.currentGroup !== undefined) {\n\t\t\t\tthis.currentOp = operation;\n\t\t\t}\n\t\t}\n\t}\n\n\tprivate pushRevertible(\n\t\ttrackingGroup: TrackingGroup,\n\t\tcallback: (segment: PermutationSegment) => void,\n\t) {\n\t\tconst revertible = {\n\t\t\trevert: () => {\n\t\t\t\tassert(\n\t\t\t\t\tthis.currentGroup === undefined && this.currentOp === undefined,\n\t\t\t\t\t0x02b /* \"Must not nest calls to IRevertible.revert()\" */,\n\t\t\t\t);\n\n\t\t\t\tthis.currentGroup = new TrackingGroup();\n\n\t\t\t\ttry {\n\t\t\t\t\twhile (trackingGroup.size > 0) {\n\t\t\t\t\t\tconst segment = trackingGroup.segments[0] as PermutationSegment;\n\n\t\t\t\t\t\t// Unlink 'segment' from the current tracking group before invoking the callback\n\t\t\t\t\t\t// to exclude the current undo/redo segment from those copied to the replacement\n\t\t\t\t\t\t// segment (if any). (See 'PermutationSegment.transferToReplacement()')\n\t\t\t\t\t\tsegment.trackingCollection.unlink(trackingGroup);\n\n\t\t\t\t\t\tcallback(segment);\n\t\t\t\t\t}\n\t\t\t\t} finally {\n\t\t\t\t\tthis.currentOp = undefined;\n\t\t\t\t\tthis.currentGroup = undefined;\n\t\t\t\t}\n\t\t\t},\n\t\t\tdiscard: () => {\n\t\t\t\twhile (trackingGroup.size > 0) {\n\t\t\t\t\ttrackingGroup.unlink(trackingGroup.segments[0]);\n\t\t\t\t}\n\t\t\t},\n\t\t};\n\n\t\tthis.manager.pushToCurrentOperation(revertible);\n\n\t\treturn revertible;\n\t}\n}\n\nexport class MatrixUndoProvider<T> {\n\tconstructor(\n\t\tprivate readonly consumer: IUndoConsumer,\n\t\tprivate readonly matrix: SharedMatrix<T>,\n\t\tprivate readonly rows: PermutationVector,\n\t\tprivate readonly cols: PermutationVector,\n\t) {\n\t\trows.undo = new VectorUndoProvider(\n\t\t\tconsumer,\n\t\t\t/* undoInsert: */ (segment: PermutationSegment) => {\n\t\t\t\tconst start = this.rows.getPosition(segment);\n\t\t\t\tthis.matrix.removeRows(start, segment.cachedLength);\n\t\t\t},\n\t\t\t/* undoRemove: */ (segment: PermutationSegment) => {\n\t\t\t\tthis.matrix._undoRemoveRows(segment);\n\t\t\t},\n\t\t);\n\t\tcols.undo = new VectorUndoProvider(\n\t\t\tconsumer,\n\t\t\t/* undoInsert: */ (segment: PermutationSegment) => {\n\t\t\t\tconst start = this.cols.getPosition(segment);\n\t\t\t\tthis.matrix.removeCols(start, segment.cachedLength);\n\t\t\t},\n\t\t\t/* undoRemove: */ (segment: PermutationSegment) => {\n\t\t\t\tthis.matrix._undoRemoveCols(segment);\n\t\t\t},\n\t\t);\n\t}\n\n\tcellSet(rowHandle: Handle, colHandle: Handle, oldValue: MatrixItem<T>) {\n\t\tassert(\n\t\t\tisHandleValid(rowHandle) && isHandleValid(colHandle),\n\t\t\t0x02c /* \"On cellSet(), invalid row and/or column handles!\" */,\n\t\t);\n\n\t\tif (this.consumer !== undefined) {\n\t\t\tthis.consumer.pushToCurrentOperation({\n\t\t\t\trevert: () => {\n\t\t\t\t\tthis.matrix.setCell(\n\t\t\t\t\t\tthis.rows.handleToPosition(rowHandle),\n\t\t\t\t\t\tthis.cols.handleToPosition(colHandle),\n\t\t\t\t\t\toldValue,\n\t\t\t\t\t);\n\t\t\t\t},\n\t\t\t\tdiscard: () => {},\n\t\t\t});\n\t\t}\n\t}\n}\n"]}
1
+ {"version":3,"file":"undoprovider.js","sourceRoot":"","sources":["../src/undoprovider.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,MAAM,EAAE,MAAM,8BAA8B,CAAC;AACtD,OAAO,EACN,aAAa,EAEb,kBAAkB,EAClB,aAAa,GACb,MAAM,4BAA4B,CAAC;AAEpC,OAAO,EAAU,aAAa,EAAE,MAAM,eAAe,CAAC;AAItD,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AC,wDAAwD,CAC9D,CAAC;QAEF,IAAI,IAAI,CAAC,QAAQ,KAAK,SAAS,EAAE;YAChC,IAAI,CAAC,QAAQ,CAAC,sBAAsB,CAAC;gBACpC,MAAM,EAAE,GAAG,EAAE;oBACZ,MAAM,GAAG,GAAG,IAAI,CAAC,IAAI,CAAC,gBAAgB,CAAC,SAAS,CAAC,CAAC;oBAClD,MAAM,GAAG,GAAG,IAAI,CAAC,IAAI,CAAC,gBAAgB,CAAC,SAAS,CAAC,CAAC;oBAClD,6DAA6D;oBAC7D,IAAI,GAAG,GAAG,IAAI,CAAC,MAAM,CAAC,QAAQ,IAAI,GAAG,GAAG,IAAI,CAAC,MAAM,CAAC,QAAQ,EAAE;wBAC7D,IAAI,CAAC,MAAM,CAAC,OAAO,CAAC,GAAG,EAAE,GAAG,EAAE,QAAQ,CAAC,CAAC;qBACxC;gBACF,CAAC;gBACD,OAAO,EAAE,GAAG,EAAE,GAAE,CAAC;aACjB,CAAC,CAAC;SACH;IACF,CAAC;CACD","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { assert } from \"@fluidframework/common-utils\";\nimport {\n\tTrackingGroup,\n\tMergeTreeDeltaOperationType,\n\tMergeTreeDeltaType,\n\ttoRemovalInfo,\n} from \"@fluidframework/merge-tree\";\nimport { MatrixItem, SharedMatrix } from \"./matrix\";\nimport { Handle, isHandleValid } from \"./handletable\";\nimport { PermutationSegment, PermutationVector } from \"./permutationvector\";\nimport { IUndoConsumer } from \"./types\";\n\nexport class VectorUndoProvider {\n\t// 'currentGroup' and 'currentOp' are used while applying an IRevertable.revert() to coalesce\n\t// the recorded into a single IRevertable / tracking group as they move between the undo <->\n\t// redo stacks.\n\tprivate currentGroup?: TrackingGroup;\n\tprivate currentOp?: MergeTreeDeltaType;\n\n\tconstructor(\n\t\tprivate readonly manager: IUndoConsumer,\n\t\tprivate readonly undoInsert: (segment: PermutationSegment) => void,\n\t\tprivate readonly undoRemove: (segment: PermutationSegment) => void,\n\t) {}\n\n\tpublic record(\n\t\toperation: MergeTreeDeltaOperationType,\n\t\tranges: { segment: PermutationSegment }[],\n\t) {\n\t\tif (ranges.length > 0) {\n\t\t\t// Link each segment to a new TrackingGroup. A TrackingGroup keeps track of the original\n\t\t\t// set of linked segments, including any fragmentatiton that occurs due to future splitting.\n\t\t\t//\n\t\t\t// A TrackingGroup also prevents removed segments from being unlinked from the tree during\n\t\t\t// Zamboni and guarantees segments will not be merged/coalesced with segments outside of the\n\t\t\t// current tracking group.\n\t\t\t//\n\t\t\t// These properties allow us to rely on MergeTree.getPosition() to find the locations/lengths\n\t\t\t// of all content contained within the tracking group in the future.\n\n\t\t\t// If we are in the process of reverting, the `IRevertible.revert()` will provide the tracking\n\t\t\t// group so that we can preserve the original segment ranges as a single op/group as we move\n\t\t\t// ops between the undo <-> redo stacks.\n\t\t\tconst trackingGroup = this.currentGroup ?? new TrackingGroup();\n\t\t\tfor (const range of ranges) {\n\t\t\t\ttrackingGroup.link(range.segment);\n\t\t\t}\n\n\t\t\t// For SharedMatrix, each IRevertibles always holds a single row/col operation.\n\t\t\t// Therefore, 'currentOp' must either be undefined or equal to the current op.\n\t\t\tassert(\n\t\t\t\tthis.currentOp === undefined || this.currentOp === operation,\n\t\t\t\t0x02a /* \"On vector undo, unexpected 'currentOp' type/state!\" */,\n\t\t\t);\n\n\t\t\tswitch (operation) {\n\t\t\t\tcase MergeTreeDeltaType.INSERT:\n\t\t\t\t\tif (this.currentOp !== MergeTreeDeltaType.INSERT) {\n\t\t\t\t\t\tthis.pushRevertible(trackingGroup, this.undoInsert);\n\t\t\t\t\t}\n\t\t\t\t\tbreak;\n\n\t\t\t\tcase MergeTreeDeltaType.REMOVE: {\n\t\t\t\t\tif (this.currentOp !== MergeTreeDeltaType.REMOVE) {\n\t\t\t\t\t\tthis.pushRevertible(trackingGroup, this.undoRemove);\n\t\t\t\t\t}\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\n\t\t\t\tdefault:\n\t\t\t\t\tthrow new Error(\"operation type not revertible\");\n\t\t\t}\n\n\t\t\t// If we are in the process of reverting, set 'currentOp' to remind ourselves not to push\n\t\t\t// another revertible until `IRevertable.revert()` finishes the current op and clears this\n\t\t\t// field.\n\t\t\tif (this.currentGroup !== undefined) {\n\t\t\t\tthis.currentOp = operation;\n\t\t\t}\n\t\t}\n\t}\n\n\tprivate pushRevertible(\n\t\ttrackingGroup: TrackingGroup,\n\t\tcallback: (segment: PermutationSegment) => void,\n\t) {\n\t\tconst revertible = {\n\t\t\trevert: () => {\n\t\t\t\tassert(\n\t\t\t\t\tthis.currentGroup === undefined && this.currentOp === undefined,\n\t\t\t\t\t0x02b /* \"Must not nest calls to IRevertible.revert()\" */,\n\t\t\t\t);\n\n\t\t\t\tthis.currentGroup = new TrackingGroup();\n\n\t\t\t\ttry {\n\t\t\t\t\twhile (trackingGroup.size > 0) {\n\t\t\t\t\t\tconst segment = trackingGroup.segments[0] as PermutationSegment;\n\n\t\t\t\t\t\t// Unlink 'segment' from the current tracking group before invoking the callback\n\t\t\t\t\t\t// to exclude the current undo/redo segment from those copied to the replacement\n\t\t\t\t\t\t// segment (if any). (See 'PermutationSegment.transferToReplacement()')\n\t\t\t\t\t\tsegment.trackingCollection.unlink(trackingGroup);\n\n\t\t\t\t\t\tcallback(segment);\n\t\t\t\t\t}\n\t\t\t\t} finally {\n\t\t\t\t\tthis.currentOp = undefined;\n\t\t\t\t\tthis.currentGroup = undefined;\n\t\t\t\t}\n\t\t\t},\n\t\t\tdiscard: () => {\n\t\t\t\twhile (trackingGroup.size > 0) {\n\t\t\t\t\ttrackingGroup.unlink(trackingGroup.segments[0]);\n\t\t\t\t}\n\t\t\t},\n\t\t};\n\n\t\tthis.manager.pushToCurrentOperation(revertible);\n\n\t\treturn revertible;\n\t}\n}\n\nexport class MatrixUndoProvider<T> {\n\tconstructor(\n\t\tprivate readonly consumer: IUndoConsumer,\n\t\tprivate readonly matrix: SharedMatrix<T>,\n\t\tprivate readonly rows: PermutationVector,\n\t\tprivate readonly cols: PermutationVector,\n\t) {\n\t\trows.undo = new VectorUndoProvider(\n\t\t\tconsumer,\n\t\t\t/* undoInsert: */ (segment: PermutationSegment) => {\n\t\t\t\tif (toRemovalInfo(segment) === undefined) {\n\t\t\t\t\tconst start = this.rows.getPosition(segment);\n\t\t\t\t\tthis.matrix.removeRows(start, segment.cachedLength);\n\t\t\t\t}\n\t\t\t},\n\t\t\t/* undoRemove: */ (segment: PermutationSegment) => {\n\t\t\t\tthis.matrix._undoRemoveRows(segment);\n\t\t\t},\n\t\t);\n\t\tcols.undo = new VectorUndoProvider(\n\t\t\tconsumer,\n\t\t\t/* undoInsert: */ (segment: PermutationSegment) => {\n\t\t\t\tif (toRemovalInfo(segment) === undefined) {\n\t\t\t\t\tconst start = this.cols.getPosition(segment);\n\t\t\t\t\tthis.matrix.removeCols(start, segment.cachedLength);\n\t\t\t\t}\n\t\t\t},\n\t\t\t/* undoRemove: */ (segment: PermutationSegment) => {\n\t\t\t\tthis.matrix._undoRemoveCols(segment);\n\t\t\t},\n\t\t);\n\t}\n\n\tcellSet(rowHandle: Handle, colHandle: Handle, oldValue: MatrixItem<T>) {\n\t\tassert(\n\t\t\tisHandleValid(rowHandle) && isHandleValid(colHandle),\n\t\t\t0x02c /* \"On cellSet(), invalid row and/or column handles!\" */,\n\t\t);\n\n\t\tif (this.consumer !== undefined) {\n\t\t\tthis.consumer.pushToCurrentOperation({\n\t\t\t\trevert: () => {\n\t\t\t\t\tconst row = this.rows.handleToPosition(rowHandle);\n\t\t\t\t\tconst col = this.cols.handleToPosition(colHandle);\n\t\t\t\t\t// if the row/column no longer exists, we cannot set the cell\n\t\t\t\t\tif (row < this.matrix.rowCount && col < this.matrix.colCount) {\n\t\t\t\t\t\tthis.matrix.setCell(row, col, oldValue);\n\t\t\t\t\t}\n\t\t\t\t},\n\t\t\t\tdiscard: () => {},\n\t\t\t});\n\t\t}\n\t}\n}\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fluidframework/matrix",
3
- "version": "2.0.0-internal.4.1.2",
3
+ "version": "2.0.0-internal.4.2.0",
4
4
  "description": "Distributed matrix",
5
5
  "homepage": "https://fluidframework.com",
6
6
  "repository": {
@@ -33,29 +33,29 @@
33
33
  "dependencies": {
34
34
  "@fluidframework/common-definitions": "^0.20.1",
35
35
  "@fluidframework/common-utils": "^1.1.1",
36
- "@fluidframework/core-interfaces": ">=2.0.0-internal.4.1.2 <2.0.0-internal.4.2.0",
37
- "@fluidframework/datastore-definitions": ">=2.0.0-internal.4.1.2 <2.0.0-internal.4.2.0",
38
- "@fluidframework/merge-tree": ">=2.0.0-internal.4.1.2 <2.0.0-internal.4.2.0",
36
+ "@fluidframework/core-interfaces": ">=2.0.0-internal.4.2.0 <2.0.0-internal.4.3.0",
37
+ "@fluidframework/datastore-definitions": ">=2.0.0-internal.4.2.0 <2.0.0-internal.4.3.0",
38
+ "@fluidframework/merge-tree": ">=2.0.0-internal.4.2.0 <2.0.0-internal.4.3.0",
39
39
  "@fluidframework/protocol-base": "^0.1039.1000",
40
40
  "@fluidframework/protocol-definitions": "^1.1.0",
41
- "@fluidframework/runtime-definitions": ">=2.0.0-internal.4.1.2 <2.0.0-internal.4.2.0",
42
- "@fluidframework/runtime-utils": ">=2.0.0-internal.4.1.2 <2.0.0-internal.4.2.0",
43
- "@fluidframework/shared-object-base": ">=2.0.0-internal.4.1.2 <2.0.0-internal.4.2.0",
44
- "@fluidframework/telemetry-utils": ">=2.0.0-internal.4.1.2 <2.0.0-internal.4.2.0",
41
+ "@fluidframework/runtime-definitions": ">=2.0.0-internal.4.2.0 <2.0.0-internal.4.3.0",
42
+ "@fluidframework/runtime-utils": ">=2.0.0-internal.4.2.0 <2.0.0-internal.4.3.0",
43
+ "@fluidframework/shared-object-base": ">=2.0.0-internal.4.2.0 <2.0.0-internal.4.3.0",
44
+ "@fluidframework/telemetry-utils": ">=2.0.0-internal.4.2.0 <2.0.0-internal.4.3.0",
45
45
  "@tiny-calc/nano": "0.0.0-alpha.5",
46
46
  "events": "^3.1.0",
47
47
  "tslib": "^1.10.0"
48
48
  },
49
49
  "devDependencies": {
50
- "@fluid-internal/test-dds-utils": ">=2.0.0-internal.4.1.2 <2.0.0-internal.4.2.0",
50
+ "@fluid-internal/test-dds-utils": ">=2.0.0-internal.4.2.0 <2.0.0-internal.4.3.0",
51
51
  "@fluid-tools/benchmark": "^0.47.0",
52
- "@fluid-tools/build-cli": "^0.15.0",
52
+ "@fluid-tools/build-cli": "^0.17.0",
53
53
  "@fluidframework/build-common": "^1.1.0",
54
- "@fluidframework/build-tools": "^0.15.0",
54
+ "@fluidframework/build-tools": "^0.17.0",
55
55
  "@fluidframework/eslint-config-fluid": "^2.0.0",
56
56
  "@fluidframework/matrix-previous": "npm:@fluidframework/matrix@2.0.0-internal.4.1.0",
57
- "@fluidframework/mocha-test-setup": ">=2.0.0-internal.4.1.2 <2.0.0-internal.4.2.0",
58
- "@fluidframework/test-runtime-utils": ">=2.0.0-internal.4.1.2 <2.0.0-internal.4.2.0",
57
+ "@fluidframework/mocha-test-setup": ">=2.0.0-internal.4.2.0 <2.0.0-internal.4.3.0",
58
+ "@fluidframework/test-runtime-utils": ">=2.0.0-internal.4.2.0 <2.0.0-internal.4.3.0",
59
59
  "@microsoft/api-extractor": "^7.34.4",
60
60
  "@tiny-calc/micro": "0.0.0-alpha.5",
61
61
  "@types/mocha": "^9.1.1",
@@ -6,4 +6,4 @@
6
6
  */
7
7
 
8
8
  export const pkgName = "@fluidframework/matrix";
9
- export const pkgVersion = "2.0.0-internal.4.1.2";
9
+ export const pkgVersion = "2.0.0-internal.4.2.0";
@@ -8,6 +8,7 @@ import {
8
8
  TrackingGroup,
9
9
  MergeTreeDeltaOperationType,
10
10
  MergeTreeDeltaType,
11
+ toRemovalInfo,
11
12
  } from "@fluidframework/merge-tree";
12
13
  import { MatrixItem, SharedMatrix } from "./matrix";
13
14
  import { Handle, isHandleValid } from "./handletable";
@@ -136,8 +137,10 @@ export class MatrixUndoProvider<T> {
136
137
  rows.undo = new VectorUndoProvider(
137
138
  consumer,
138
139
  /* undoInsert: */ (segment: PermutationSegment) => {
139
- const start = this.rows.getPosition(segment);
140
- this.matrix.removeRows(start, segment.cachedLength);
140
+ if (toRemovalInfo(segment) === undefined) {
141
+ const start = this.rows.getPosition(segment);
142
+ this.matrix.removeRows(start, segment.cachedLength);
143
+ }
141
144
  },
142
145
  /* undoRemove: */ (segment: PermutationSegment) => {
143
146
  this.matrix._undoRemoveRows(segment);
@@ -146,8 +149,10 @@ export class MatrixUndoProvider<T> {
146
149
  cols.undo = new VectorUndoProvider(
147
150
  consumer,
148
151
  /* undoInsert: */ (segment: PermutationSegment) => {
149
- const start = this.cols.getPosition(segment);
150
- this.matrix.removeCols(start, segment.cachedLength);
152
+ if (toRemovalInfo(segment) === undefined) {
153
+ const start = this.cols.getPosition(segment);
154
+ this.matrix.removeCols(start, segment.cachedLength);
155
+ }
151
156
  },
152
157
  /* undoRemove: */ (segment: PermutationSegment) => {
153
158
  this.matrix._undoRemoveCols(segment);
@@ -164,11 +169,12 @@ export class MatrixUndoProvider<T> {
164
169
  if (this.consumer !== undefined) {
165
170
  this.consumer.pushToCurrentOperation({
166
171
  revert: () => {
167
- this.matrix.setCell(
168
- this.rows.handleToPosition(rowHandle),
169
- this.cols.handleToPosition(colHandle),
170
- oldValue,
171
- );
172
+ const row = this.rows.handleToPosition(rowHandle);
173
+ const col = this.cols.handleToPosition(colHandle);
174
+ // if the row/column no longer exists, we cannot set the cell
175
+ if (row < this.matrix.rowCount && col < this.matrix.colCount) {
176
+ this.matrix.setCell(row, col, oldValue);
177
+ }
172
178
  },
173
179
  discard: () => {},
174
180
  });