@atlaskit/editor-synced-block-provider 0.3.0 → 0.4.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.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,12 @@
1
1
  # @atlaskit/editor-synced-block-provider
2
2
 
3
+ ## 0.4.0
4
+
5
+ ### Minor Changes
6
+
7
+ - [`acb8231bc9e0c`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/acb8231bc9e0c) -
8
+ EDITOR-1779 - "rebase" the transaction to reflect the latest document state
9
+
3
10
  ## 0.3.0
4
11
 
5
12
  ### Minor Changes
@@ -0,0 +1,31 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.rebaseTransaction = void 0;
7
+ var _transform = require("@atlaskit/editor-prosemirror/transform");
8
+ /**
9
+ * Rebase `currentTr` over `incomingTr` based on the provided `state`.
10
+ * This function adjusts the steps in `currentTr` to account for the changes made by `incomingTr`.
11
+ *
12
+ * @param currentTr - The transaction to be rebased.
13
+ * @param incomingTr - The transaction that has already been applied to the state.
14
+ * @param state - The editor state after applying `incomingTr`.
15
+ * @returns A new transaction that represents `currentTr` rebased over `incomingTr`.
16
+ */
17
+ var rebaseTransaction = exports.rebaseTransaction = function rebaseTransaction(currentTr, incomingTr, state) {
18
+ if (!incomingTr.docChanged) {
19
+ return currentTr;
20
+ }
21
+ var currentMapping = new _transform.Mapping(incomingTr.mapping.maps);
22
+ var rebasedTransaction = state.tr;
23
+ currentTr.steps.forEach(function (step) {
24
+ var mappedStep = step.map(currentMapping);
25
+ if (mappedStep) {
26
+ rebasedTransaction.step(mappedStep);
27
+ currentMapping.appendMap(mappedStep.getMap());
28
+ }
29
+ });
30
+ return rebasedTransaction;
31
+ };
@@ -10,6 +10,7 @@ var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/
10
10
  var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));
11
11
  var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
12
12
  var _uuid = _interopRequireDefault(require("uuid"));
13
+ var _rebaseTransaction2 = require("./rebase-transaction");
13
14
  // Do this typedef to make it clear that
14
15
  // this is a local identifier for a resource for local use
15
16
  // A store manager responsible for the lifecycle and state management of sync blocks in an editor instance.
@@ -88,23 +89,24 @@ var SyncBlockStoreManager = exports.SyncBlockStoreManager = /*#__PURE__*/functio
88
89
  while (1) switch (_context.prev = _context.next) {
89
90
  case 0:
90
91
  if (!this.confirmationCallback) {
91
- _context.next = 5;
92
+ _context.next = 7;
92
93
  break;
93
94
  }
94
- _context.next = 3;
95
+ this.confirmationTransaction = tr;
96
+ _context.next = 4;
95
97
  return this.confirmationCallback();
96
- case 3:
98
+ case 4:
97
99
  confirmed = _context.sent;
98
100
  if (confirmed) {
99
- // TODO: EDITOR-1779 - "rebase" the transaction to reflect the latest document state
100
- (_this$editorView = this.editorView) === null || _this$editorView === void 0 || _this$editorView.dispatch(tr.setMeta('isConfirmedSyncBlockDeletion', true));
101
+ (_this$editorView = this.editorView) === null || _this$editorView === void 0 || _this$editorView.dispatch(this.confirmationTransaction.setMeta('isConfirmedSyncBlockDeletion', true));
101
102
  // Need to update the BE on deletion
102
103
  syncBlockIds.forEach(function (_ref) {
103
104
  var resourceId = _ref.resourceId;
104
105
  return _this2.syncBlocks.delete(resourceId);
105
106
  });
106
107
  }
107
- case 5:
108
+ this.confirmationTransaction = undefined;
109
+ case 7:
108
110
  case "end":
109
111
  return _context.stop();
110
112
  }
@@ -115,5 +117,13 @@ var SyncBlockStoreManager = exports.SyncBlockStoreManager = /*#__PURE__*/functio
115
117
  }
116
118
  return deleteSyncBlocksWithConfirmation;
117
119
  }()
120
+ }, {
121
+ key: "rebaseTransaction",
122
+ value: function rebaseTransaction(incomingTr, state) {
123
+ if (!this.confirmationTransaction) {
124
+ return;
125
+ }
126
+ this.confirmationTransaction = (0, _rebaseTransaction2.rebaseTransaction)(this.confirmationTransaction, incomingTr, state);
127
+ }
118
128
  }]);
119
129
  }();
package/dist/cjs/index.js CHANGED
@@ -57,6 +57,12 @@ Object.defineProperty(exports, "inMemoryWriteProvider", {
57
57
  return _inMemory.inMemoryWriteProvider;
58
58
  }
59
59
  });
60
+ Object.defineProperty(exports, "rebaseTransaction", {
61
+ enumerable: true,
62
+ get: function get() {
63
+ return _rebaseTransaction.rebaseTransaction;
64
+ }
65
+ });
60
66
  Object.defineProperty(exports, "useFetchDocNode", {
61
67
  enumerable: true,
62
68
  get: function get() {
@@ -81,4 +87,5 @@ var _inMemory = require("./providers/inMemory");
81
87
  var _schema = require("./common/schema");
82
88
  var _confluenceContentAPI = require("./providers/confluenceContentAPI");
83
89
  var _ari = require("./utils/ari");
84
- var _utils = require("./utils/utils");
90
+ var _utils = require("./utils/utils");
91
+ var _rebaseTransaction = require("./common/rebase-transaction");
@@ -0,0 +1,26 @@
1
+ import { Mapping } from '@atlaskit/editor-prosemirror/transform';
2
+
3
+ /**
4
+ * Rebase `currentTr` over `incomingTr` based on the provided `state`.
5
+ * This function adjusts the steps in `currentTr` to account for the changes made by `incomingTr`.
6
+ *
7
+ * @param currentTr - The transaction to be rebased.
8
+ * @param incomingTr - The transaction that has already been applied to the state.
9
+ * @param state - The editor state after applying `incomingTr`.
10
+ * @returns A new transaction that represents `currentTr` rebased over `incomingTr`.
11
+ */
12
+ export const rebaseTransaction = (currentTr, incomingTr, state) => {
13
+ if (!incomingTr.docChanged) {
14
+ return currentTr;
15
+ }
16
+ const currentMapping = new Mapping(incomingTr.mapping.maps);
17
+ const rebasedTransaction = state.tr;
18
+ currentTr.steps.forEach(step => {
19
+ const mappedStep = step.map(currentMapping);
20
+ if (mappedStep) {
21
+ rebasedTransaction.step(mappedStep);
22
+ currentMapping.appendMap(mappedStep.getMap());
23
+ }
24
+ });
25
+ return rebasedTransaction;
26
+ };
@@ -1,4 +1,5 @@
1
1
  import uuid from 'uuid';
2
+ import { rebaseTransaction } from './rebase-transaction';
2
3
 
3
4
  // Do this typedef to make it clear that
4
5
  // this is a local identifier for a resource for local use
@@ -60,16 +61,23 @@ export class SyncBlockStoreManager {
60
61
  }
61
62
  async deleteSyncBlocksWithConfirmation(tr, syncBlockIds) {
62
63
  if (this.confirmationCallback) {
64
+ this.confirmationTransaction = tr;
63
65
  const confirmed = await this.confirmationCallback();
64
66
  if (confirmed) {
65
67
  var _this$editorView;
66
- // TODO: EDITOR-1779 - "rebase" the transaction to reflect the latest document state
67
- (_this$editorView = this.editorView) === null || _this$editorView === void 0 ? void 0 : _this$editorView.dispatch(tr.setMeta('isConfirmedSyncBlockDeletion', true));
68
+ (_this$editorView = this.editorView) === null || _this$editorView === void 0 ? void 0 : _this$editorView.dispatch(this.confirmationTransaction.setMeta('isConfirmedSyncBlockDeletion', true));
68
69
  // Need to update the BE on deletion
69
70
  syncBlockIds.forEach(({
70
71
  resourceId
71
72
  }) => this.syncBlocks.delete(resourceId));
72
73
  }
74
+ this.confirmationTransaction = undefined;
73
75
  }
74
76
  }
77
+ rebaseTransaction(incomingTr, state) {
78
+ if (!this.confirmationTransaction) {
79
+ return;
80
+ }
81
+ this.confirmationTransaction = rebaseTransaction(this.confirmationTransaction, incomingTr, state);
82
+ }
75
83
  }
@@ -6,4 +6,5 @@ export { inMemoryFetchProvider, inMemoryWriteProvider } from './providers/inMemo
6
6
  export { getDefaultSyncBlockSchema } from './common/schema';
7
7
  export { createContentAPIProvidersWithDefaultKey, useMemoizedContentAPIProviders } from './providers/confluenceContentAPI';
8
8
  export { getConfluencePageAri } from './utils/ari';
9
- export { convertSyncBlockPMNodeToSyncBlockData, generateSyncBlockSourceUrl } from './utils/utils';
9
+ export { convertSyncBlockPMNodeToSyncBlockData, generateSyncBlockSourceUrl } from './utils/utils';
10
+ export { rebaseTransaction } from './common/rebase-transaction';
@@ -0,0 +1,26 @@
1
+ import { Mapping } from '@atlaskit/editor-prosemirror/transform';
2
+
3
+ /**
4
+ * Rebase `currentTr` over `incomingTr` based on the provided `state`.
5
+ * This function adjusts the steps in `currentTr` to account for the changes made by `incomingTr`.
6
+ *
7
+ * @param currentTr - The transaction to be rebased.
8
+ * @param incomingTr - The transaction that has already been applied to the state.
9
+ * @param state - The editor state after applying `incomingTr`.
10
+ * @returns A new transaction that represents `currentTr` rebased over `incomingTr`.
11
+ */
12
+ export var rebaseTransaction = function rebaseTransaction(currentTr, incomingTr, state) {
13
+ if (!incomingTr.docChanged) {
14
+ return currentTr;
15
+ }
16
+ var currentMapping = new Mapping(incomingTr.mapping.maps);
17
+ var rebasedTransaction = state.tr;
18
+ currentTr.steps.forEach(function (step) {
19
+ var mappedStep = step.map(currentMapping);
20
+ if (mappedStep) {
21
+ rebasedTransaction.step(mappedStep);
22
+ currentMapping.appendMap(mappedStep.getMap());
23
+ }
24
+ });
25
+ return rebasedTransaction;
26
+ };
@@ -3,6 +3,7 @@ import _classCallCheck from "@babel/runtime/helpers/classCallCheck";
3
3
  import _createClass from "@babel/runtime/helpers/createClass";
4
4
  import _regeneratorRuntime from "@babel/runtime/regenerator";
5
5
  import uuid from 'uuid';
6
+ import { rebaseTransaction as _rebaseTransaction } from './rebase-transaction';
6
7
 
7
8
  // Do this typedef to make it clear that
8
9
  // this is a local identifier for a resource for local use
@@ -83,23 +84,24 @@ export var SyncBlockStoreManager = /*#__PURE__*/function () {
83
84
  while (1) switch (_context.prev = _context.next) {
84
85
  case 0:
85
86
  if (!this.confirmationCallback) {
86
- _context.next = 5;
87
+ _context.next = 7;
87
88
  break;
88
89
  }
89
- _context.next = 3;
90
+ this.confirmationTransaction = tr;
91
+ _context.next = 4;
90
92
  return this.confirmationCallback();
91
- case 3:
93
+ case 4:
92
94
  confirmed = _context.sent;
93
95
  if (confirmed) {
94
- // TODO: EDITOR-1779 - "rebase" the transaction to reflect the latest document state
95
- (_this$editorView = this.editorView) === null || _this$editorView === void 0 || _this$editorView.dispatch(tr.setMeta('isConfirmedSyncBlockDeletion', true));
96
+ (_this$editorView = this.editorView) === null || _this$editorView === void 0 || _this$editorView.dispatch(this.confirmationTransaction.setMeta('isConfirmedSyncBlockDeletion', true));
96
97
  // Need to update the BE on deletion
97
98
  syncBlockIds.forEach(function (_ref) {
98
99
  var resourceId = _ref.resourceId;
99
100
  return _this2.syncBlocks.delete(resourceId);
100
101
  });
101
102
  }
102
- case 5:
103
+ this.confirmationTransaction = undefined;
104
+ case 7:
103
105
  case "end":
104
106
  return _context.stop();
105
107
  }
@@ -110,5 +112,13 @@ export var SyncBlockStoreManager = /*#__PURE__*/function () {
110
112
  }
111
113
  return deleteSyncBlocksWithConfirmation;
112
114
  }()
115
+ }, {
116
+ key: "rebaseTransaction",
117
+ value: function rebaseTransaction(incomingTr, state) {
118
+ if (!this.confirmationTransaction) {
119
+ return;
120
+ }
121
+ this.confirmationTransaction = _rebaseTransaction(this.confirmationTransaction, incomingTr, state);
122
+ }
113
123
  }]);
114
124
  }();
package/dist/esm/index.js CHANGED
@@ -6,4 +6,5 @@ export { inMemoryFetchProvider, inMemoryWriteProvider } from './providers/inMemo
6
6
  export { getDefaultSyncBlockSchema } from './common/schema';
7
7
  export { createContentAPIProvidersWithDefaultKey, useMemoizedContentAPIProviders } from './providers/confluenceContentAPI';
8
8
  export { getConfluencePageAri } from './utils/ari';
9
- export { convertSyncBlockPMNodeToSyncBlockData, generateSyncBlockSourceUrl } from './utils/utils';
9
+ export { convertSyncBlockPMNodeToSyncBlockData, generateSyncBlockSourceUrl } from './utils/utils';
10
+ export { rebaseTransaction } from './common/rebase-transaction';
@@ -0,0 +1,11 @@
1
+ import type { EditorState, Transaction } from '@atlaskit/editor-prosemirror/state';
2
+ /**
3
+ * Rebase `currentTr` over `incomingTr` based on the provided `state`.
4
+ * This function adjusts the steps in `currentTr` to account for the changes made by `incomingTr`.
5
+ *
6
+ * @param currentTr - The transaction to be rebased.
7
+ * @param incomingTr - The transaction that has already been applied to the state.
8
+ * @param state - The editor state after applying `incomingTr`.
9
+ * @returns A new transaction that represents `currentTr` rebased over `incomingTr`.
10
+ */
11
+ export declare const rebaseTransaction: (currentTr: Transaction, incomingTr: Transaction, state: EditorState) => Transaction;
@@ -1,6 +1,6 @@
1
1
  import type { ADFEntity } from '@atlaskit/adf-utils/types';
2
2
  import type { Node as PMNode } from '@atlaskit/editor-prosemirror/model';
3
- import type { Transaction } from '@atlaskit/editor-prosemirror/state';
3
+ import type { EditorState, Transaction } from '@atlaskit/editor-prosemirror/state';
4
4
  import type { EditorView } from '@atlaskit/editor-prosemirror/view';
5
5
  import type { SyncBlockAttrs, SyncBlockDataProvider, SyncBlockNode } from './types';
6
6
  export interface SyncBlock {
@@ -18,6 +18,7 @@ export declare class SyncBlockStoreManager {
18
18
  private confirmationCallback?;
19
19
  private editorView?;
20
20
  private dataProvider?;
21
+ private confirmationTransaction?;
21
22
  constructor(dataProvider?: SyncBlockDataProvider);
22
23
  setEditorView(editorView: EditorView | undefined): void;
23
24
  isSourceBlock(node: PMNode): boolean;
@@ -25,5 +26,6 @@ export declare class SyncBlockStoreManager {
25
26
  requireConfirmationBeforeDelete(): boolean;
26
27
  createSyncBlockNode(): SyncBlockNode;
27
28
  deleteSyncBlocksWithConfirmation(tr: Transaction, syncBlockIds: SyncBlockAttrs[]): Promise<void>;
29
+ rebaseTransaction(incomingTr: Transaction, state: EditorState): void;
28
30
  }
29
31
  export {};
@@ -6,3 +6,4 @@ export { getDefaultSyncBlockSchema } from './common/schema';
6
6
  export { createContentAPIProvidersWithDefaultKey, useMemoizedContentAPIProviders, } from './providers/confluenceContentAPI';
7
7
  export { getConfluencePageAri } from './utils/ari';
8
8
  export { convertSyncBlockPMNodeToSyncBlockData, generateSyncBlockSourceUrl } from './utils/utils';
9
+ export { rebaseTransaction } from './common/rebase-transaction';
@@ -0,0 +1,11 @@
1
+ import type { EditorState, Transaction } from '@atlaskit/editor-prosemirror/state';
2
+ /**
3
+ * Rebase `currentTr` over `incomingTr` based on the provided `state`.
4
+ * This function adjusts the steps in `currentTr` to account for the changes made by `incomingTr`.
5
+ *
6
+ * @param currentTr - The transaction to be rebased.
7
+ * @param incomingTr - The transaction that has already been applied to the state.
8
+ * @param state - The editor state after applying `incomingTr`.
9
+ * @returns A new transaction that represents `currentTr` rebased over `incomingTr`.
10
+ */
11
+ export declare const rebaseTransaction: (currentTr: Transaction, incomingTr: Transaction, state: EditorState) => Transaction;
@@ -1,6 +1,6 @@
1
1
  import type { ADFEntity } from '@atlaskit/adf-utils/types';
2
2
  import type { Node as PMNode } from '@atlaskit/editor-prosemirror/model';
3
- import type { Transaction } from '@atlaskit/editor-prosemirror/state';
3
+ import type { EditorState, Transaction } from '@atlaskit/editor-prosemirror/state';
4
4
  import type { EditorView } from '@atlaskit/editor-prosemirror/view';
5
5
  import type { SyncBlockAttrs, SyncBlockDataProvider, SyncBlockNode } from './types';
6
6
  export interface SyncBlock {
@@ -18,6 +18,7 @@ export declare class SyncBlockStoreManager {
18
18
  private confirmationCallback?;
19
19
  private editorView?;
20
20
  private dataProvider?;
21
+ private confirmationTransaction?;
21
22
  constructor(dataProvider?: SyncBlockDataProvider);
22
23
  setEditorView(editorView: EditorView | undefined): void;
23
24
  isSourceBlock(node: PMNode): boolean;
@@ -25,5 +26,6 @@ export declare class SyncBlockStoreManager {
25
26
  requireConfirmationBeforeDelete(): boolean;
26
27
  createSyncBlockNode(): SyncBlockNode;
27
28
  deleteSyncBlocksWithConfirmation(tr: Transaction, syncBlockIds: SyncBlockAttrs[]): Promise<void>;
29
+ rebaseTransaction(incomingTr: Transaction, state: EditorState): void;
28
30
  }
29
31
  export {};
@@ -6,3 +6,4 @@ export { getDefaultSyncBlockSchema } from './common/schema';
6
6
  export { createContentAPIProvidersWithDefaultKey, useMemoizedContentAPIProviders, } from './providers/confluenceContentAPI';
7
7
  export { getConfluencePageAri } from './utils/ari';
8
8
  export { convertSyncBlockPMNodeToSyncBlockData, generateSyncBlockSourceUrl } from './utils/utils';
9
+ export { rebaseTransaction } from './common/rebase-transaction';
package/package.json CHANGED
@@ -82,7 +82,7 @@
82
82
  }
83
83
  },
84
84
  "name": "@atlaskit/editor-synced-block-provider",
85
- "version": "0.3.0",
85
+ "version": "0.4.0",
86
86
  "description": "Synced Block Provider for @atlaskit/editor-plugin-synced-block",
87
87
  "author": "Atlassian Pty Ltd",
88
88
  "license": "Apache-2.0",