@atlaskit/editor-plugin-synced-block 4.2.14 → 4.3.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 +19 -0
- package/dist/cjs/nodeviews/bodiedSyncedBlock.js +8 -6
- package/dist/cjs/nodeviews/syncedBlock.js +10 -7
- package/dist/cjs/pm-plugins/main.js +6 -6
- package/dist/cjs/pm-plugins/utils/track-sync-blocks.js +56 -30
- package/dist/cjs/syncedBlockPlugin.js +4 -2
- package/dist/es2019/nodeviews/bodiedSyncedBlock.js +8 -6
- package/dist/es2019/nodeviews/syncedBlock.js +10 -8
- package/dist/es2019/pm-plugins/main.js +6 -6
- package/dist/es2019/pm-plugins/utils/track-sync-blocks.js +56 -30
- package/dist/es2019/syncedBlockPlugin.js +4 -2
- package/dist/esm/nodeviews/bodiedSyncedBlock.js +8 -6
- package/dist/esm/nodeviews/syncedBlock.js +10 -7
- package/dist/esm/pm-plugins/main.js +6 -6
- package/dist/esm/pm-plugins/utils/track-sync-blocks.js +56 -30
- package/dist/esm/syncedBlockPlugin.js +4 -2
- package/dist/types/nodeviews/bodiedSyncedBlock.d.ts +0 -3
- package/dist/types/nodeviews/syncedBlock.d.ts +0 -3
- package/dist/types/pm-plugins/main.d.ts +1 -0
- package/dist/types/types/index.d.ts +5 -0
- package/dist/types-ts4.5/nodeviews/bodiedSyncedBlock.d.ts +0 -3
- package/dist/types-ts4.5/nodeviews/syncedBlock.d.ts +0 -3
- package/dist/types-ts4.5/pm-plugins/main.d.ts +1 -0
- package/dist/types-ts4.5/types/index.d.ts +5 -0
- package/package.json +2 -2
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,24 @@
|
|
|
1
1
|
# @atlaskit/editor-plugin-synced-block
|
|
2
2
|
|
|
3
|
+
## 4.3.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- [`1f699b87203c4`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/1f699b87203c4) -
|
|
8
|
+
EDITOR-2881 improve track sync blocks function
|
|
9
|
+
|
|
10
|
+
### Patch Changes
|
|
11
|
+
|
|
12
|
+
- Updated dependencies
|
|
13
|
+
|
|
14
|
+
## 4.2.15
|
|
15
|
+
|
|
16
|
+
### Patch Changes
|
|
17
|
+
|
|
18
|
+
- [`a9159bf9608a8`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/a9159bf9608a8) -
|
|
19
|
+
[ux] Fix edit link disabled on reference sync block by setting syncBlockStore in nodeview from
|
|
20
|
+
plugin state
|
|
21
|
+
|
|
3
22
|
## 4.2.14
|
|
4
23
|
|
|
5
24
|
### Patch Changes
|
|
@@ -28,7 +28,6 @@ var BodiedSyncBlock = /*#__PURE__*/function (_ReactNodeView) {
|
|
|
28
28
|
var _this;
|
|
29
29
|
(0, _classCallCheck2.default)(this, BodiedSyncBlock);
|
|
30
30
|
_this = _callSuper(this, BodiedSyncBlock, [props.node, props.view, props.getPos, props.portalProviderAPI, props.eventDispatcher, props]);
|
|
31
|
-
_this.syncBlockStore = props.syncBlockStore;
|
|
32
31
|
_this.api = props.api;
|
|
33
32
|
_this.handleConnectivityModeChange();
|
|
34
33
|
_this.handleViewModeChange();
|
|
@@ -89,9 +88,14 @@ var BodiedSyncBlock = /*#__PURE__*/function (_ReactNodeView) {
|
|
|
89
88
|
}, {
|
|
90
89
|
key: "render",
|
|
91
90
|
value: function render(_props, forwardRef) {
|
|
91
|
+
var _this$api5;
|
|
92
|
+
var syncBlockStore = (_this$api5 = this.api) === null || _this$api5 === void 0 || (_this$api5 = _this$api5.syncedBlock.sharedState) === null || _this$api5 === void 0 || (_this$api5 = _this$api5.currentState()) === null || _this$api5 === void 0 ? void 0 : _this$api5.syncBlockStore;
|
|
93
|
+
if (!syncBlockStore) {
|
|
94
|
+
return null;
|
|
95
|
+
}
|
|
92
96
|
return /*#__PURE__*/_react.default.createElement(_BodiedSyncBlockWrapper.BodiedSyncBlockWrapper, {
|
|
93
97
|
ref: forwardRef,
|
|
94
|
-
syncBlockStore:
|
|
98
|
+
syncBlockStore: syncBlockStore,
|
|
95
99
|
node: this.node
|
|
96
100
|
});
|
|
97
101
|
}
|
|
@@ -127,8 +131,7 @@ var BodiedSyncBlock = /*#__PURE__*/function (_ReactNodeView) {
|
|
|
127
131
|
var bodiedSyncBlockNodeView = exports.bodiedSyncBlockNodeView = function bodiedSyncBlockNodeView(_ref4) {
|
|
128
132
|
var pluginOptions = _ref4.pluginOptions,
|
|
129
133
|
pmPluginFactoryParams = _ref4.pmPluginFactoryParams,
|
|
130
|
-
api = _ref4.api
|
|
131
|
-
syncBlockStore = _ref4.syncBlockStore;
|
|
134
|
+
api = _ref4.api;
|
|
132
135
|
return function (node, view, getPos) {
|
|
133
136
|
var portalProviderAPI = pmPluginFactoryParams.portalProviderAPI,
|
|
134
137
|
eventDispatcher = pmPluginFactoryParams.eventDispatcher;
|
|
@@ -139,8 +142,7 @@ var bodiedSyncBlockNodeView = exports.bodiedSyncBlockNodeView = function bodiedS
|
|
|
139
142
|
view: view,
|
|
140
143
|
getPos: getPos,
|
|
141
144
|
portalProviderAPI: portalProviderAPI,
|
|
142
|
-
eventDispatcher: eventDispatcher
|
|
143
|
-
syncBlockStore: syncBlockStore
|
|
145
|
+
eventDispatcher: eventDispatcher
|
|
144
146
|
}).init();
|
|
145
147
|
};
|
|
146
148
|
};
|
|
@@ -25,7 +25,7 @@ var SyncBlock = /*#__PURE__*/function (_ReactNodeView) {
|
|
|
25
25
|
(0, _classCallCheck2.default)(this, SyncBlock);
|
|
26
26
|
_this = _callSuper(this, SyncBlock, [props.node, props.view, props.getPos, props.portalProviderAPI, props.eventDispatcher, props]);
|
|
27
27
|
_this.options = props.options;
|
|
28
|
-
_this.
|
|
28
|
+
_this.api = props.api;
|
|
29
29
|
return _this;
|
|
30
30
|
}
|
|
31
31
|
(0, _inherits2.default)(SyncBlock, _ReactNodeView);
|
|
@@ -40,6 +40,7 @@ var SyncBlock = /*#__PURE__*/function (_ReactNodeView) {
|
|
|
40
40
|
key: "render",
|
|
41
41
|
value: function render() {
|
|
42
42
|
var _this$options,
|
|
43
|
+
_this$api,
|
|
43
44
|
_this$options2,
|
|
44
45
|
_this2 = this;
|
|
45
46
|
if (!((_this$options = this.options) !== null && _this$options !== void 0 && _this$options.syncedBlockRenderer)) {
|
|
@@ -51,16 +52,20 @@ var SyncBlock = /*#__PURE__*/function (_ReactNodeView) {
|
|
|
51
52
|
if (!resourceId || !localId) {
|
|
52
53
|
return null;
|
|
53
54
|
}
|
|
55
|
+
var syncBlockStore = (_this$api = this.api) === null || _this$api === void 0 || (_this$api = _this$api.syncedBlock) === null || _this$api === void 0 || (_this$api = _this$api.sharedState.currentState()) === null || _this$api === void 0 ? void 0 : _this$api.syncBlockStore;
|
|
56
|
+
if (!syncBlockStore) {
|
|
57
|
+
return null;
|
|
58
|
+
}
|
|
54
59
|
|
|
55
60
|
// get document node from data provider
|
|
56
61
|
return /*#__PURE__*/_react.default.createElement(_SyncBlockRendererWrapper.SyncBlockRendererWrapper, {
|
|
57
62
|
localId: this.node.attrs.localId,
|
|
58
63
|
syncedBlockRenderer: (_this$options2 = this.options) === null || _this$options2 === void 0 ? void 0 : _this$options2.syncedBlockRenderer,
|
|
59
64
|
useFetchSyncBlockTitle: function useFetchSyncBlockTitle() {
|
|
60
|
-
return (0, _editorSyncedBlockProvider.useFetchSyncBlockTitle)(
|
|
65
|
+
return (0, _editorSyncedBlockProvider.useFetchSyncBlockTitle)(syncBlockStore, _this2.node);
|
|
61
66
|
},
|
|
62
67
|
useFetchSyncBlockData: function useFetchSyncBlockData() {
|
|
63
|
-
return (0, _editorSyncedBlockProvider.useFetchSyncBlockData)(
|
|
68
|
+
return (0, _editorSyncedBlockProvider.useFetchSyncBlockData)(syncBlockStore, resourceId, localId);
|
|
64
69
|
}
|
|
65
70
|
});
|
|
66
71
|
}
|
|
@@ -76,8 +81,7 @@ var SyncBlock = /*#__PURE__*/function (_ReactNodeView) {
|
|
|
76
81
|
var syncBlockNodeView = exports.syncBlockNodeView = function syncBlockNodeView(_ref) {
|
|
77
82
|
var options = _ref.options,
|
|
78
83
|
pmPluginFactoryParams = _ref.pmPluginFactoryParams,
|
|
79
|
-
api = _ref.api
|
|
80
|
-
syncBlockStore = _ref.syncBlockStore;
|
|
84
|
+
api = _ref.api;
|
|
81
85
|
return function (node, view, getPos) {
|
|
82
86
|
var portalProviderAPI = pmPluginFactoryParams.portalProviderAPI,
|
|
83
87
|
eventDispatcher = pmPluginFactoryParams.eventDispatcher;
|
|
@@ -88,8 +92,7 @@ var syncBlockNodeView = exports.syncBlockNodeView = function syncBlockNodeView(_
|
|
|
88
92
|
view: view,
|
|
89
93
|
getPos: getPos,
|
|
90
94
|
portalProviderAPI: portalProviderAPI,
|
|
91
|
-
eventDispatcher: eventDispatcher
|
|
92
|
-
syncBlockStore: syncBlockStore
|
|
95
|
+
eventDispatcher: eventDispatcher
|
|
93
96
|
}).init();
|
|
94
97
|
};
|
|
95
98
|
};
|
|
@@ -31,7 +31,8 @@ var createPlugin = exports.createPlugin = function createPlugin(options, pmPlugi
|
|
|
31
31
|
syncBlockStore.referenceManager.fetchSyncBlocksData((0, _editorSyncedBlockProvider.convertPMNodesToSyncBlockNodes)(syncBlockNodes));
|
|
32
32
|
return {
|
|
33
33
|
selectionDecorationSet: (0, _selectionDecorations.calculateDecorations)(instance.doc, instance.selection, instance.schema),
|
|
34
|
-
showFlag: false
|
|
34
|
+
showFlag: false,
|
|
35
|
+
syncBlockStore: syncBlockStore
|
|
35
36
|
};
|
|
36
37
|
},
|
|
37
38
|
apply: function apply(tr, currentPluginState, oldEditorState) {
|
|
@@ -45,7 +46,8 @@ var createPlugin = exports.createPlugin = function createPlugin(options, pmPlugi
|
|
|
45
46
|
}
|
|
46
47
|
return {
|
|
47
48
|
showFlag: (_meta$showFlag = meta === null || meta === void 0 ? void 0 : meta.showFlag) !== null && _meta$showFlag !== void 0 ? _meta$showFlag : showFlag,
|
|
48
|
-
selectionDecorationSet: newDecorationSet
|
|
49
|
+
selectionDecorationSet: newDecorationSet,
|
|
50
|
+
syncBlockStore: syncBlockStore
|
|
49
51
|
};
|
|
50
52
|
}
|
|
51
53
|
},
|
|
@@ -54,14 +56,12 @@ var createPlugin = exports.createPlugin = function createPlugin(options, pmPlugi
|
|
|
54
56
|
syncBlock: (0, _lazySyncedBlock.lazySyncBlockView)({
|
|
55
57
|
options: options,
|
|
56
58
|
pmPluginFactoryParams: pmPluginFactoryParams,
|
|
57
|
-
api: api
|
|
58
|
-
syncBlockStore: syncBlockStore
|
|
59
|
+
api: api
|
|
59
60
|
}),
|
|
60
61
|
bodiedSyncBlock: (0, _bodiedLazySyncedBlock.lazyBodiedSyncBlockView)({
|
|
61
62
|
pluginOptions: options,
|
|
62
63
|
pmPluginFactoryParams: pmPluginFactoryParams,
|
|
63
|
-
api: api
|
|
64
|
-
syncBlockStore: syncBlockStore
|
|
64
|
+
api: api
|
|
65
65
|
})
|
|
66
66
|
},
|
|
67
67
|
decorations: function decorations(state) {
|
|
@@ -12,56 +12,82 @@ function _arrayLikeToArray(r, a) { (null == a || a > r.length) && (a = r.length)
|
|
|
12
12
|
var trackSyncBlocks = exports.trackSyncBlocks = function trackSyncBlocks(predicate, tr, state) {
|
|
13
13
|
var removed = {};
|
|
14
14
|
var added = {};
|
|
15
|
+
if (!tr.docChanged) {
|
|
16
|
+
return {
|
|
17
|
+
removed: [],
|
|
18
|
+
added: []
|
|
19
|
+
};
|
|
20
|
+
}
|
|
15
21
|
|
|
16
22
|
// and cast to specific step types
|
|
17
23
|
var replaceSteps = tr.steps.filter(function (step) {
|
|
18
24
|
return step instanceof _transform.ReplaceStep || step instanceof _transform.ReplaceAroundStep;
|
|
19
25
|
});
|
|
20
|
-
|
|
26
|
+
|
|
27
|
+
// this is a quick check to see if any insertion/deletion of bodiedSyncBlock happened
|
|
28
|
+
var hasBodiedSyncBlockChanges = replaceSteps.some(function (step) {
|
|
21
29
|
var from = step.from,
|
|
22
30
|
to = step.to;
|
|
23
|
-
|
|
24
|
-
|
|
31
|
+
var hasChange = false;
|
|
25
32
|
if (from !== to) {
|
|
26
33
|
step.getMap().forEach(function (oldStart, oldEnd) {
|
|
27
|
-
if (oldStart !== oldEnd) {
|
|
28
|
-
var deletedSlice = state.doc.slice(oldStart, oldEnd);
|
|
29
|
-
deletedSlice.content.
|
|
34
|
+
if (oldStart !== oldEnd && !hasChange) {
|
|
35
|
+
var deletedSlice = state.doc.slice(Math.max(0, oldStart), Math.min(state.doc.content.size, oldEnd));
|
|
36
|
+
deletedSlice.content.forEach(function (node, _, index) {
|
|
37
|
+
if (hasChange) {
|
|
38
|
+
return;
|
|
39
|
+
}
|
|
40
|
+
// for top level nodes
|
|
30
41
|
if (predicate(node)) {
|
|
31
|
-
|
|
32
|
-
// If a source block added and then removed in the same transaction,
|
|
33
|
-
// we treat it as no-op.
|
|
34
|
-
delete added[node.attrs.localId];
|
|
35
|
-
} else {
|
|
36
|
-
removed[node.attrs.localId] = node.attrs;
|
|
37
|
-
}
|
|
42
|
+
hasChange = true;
|
|
38
43
|
}
|
|
39
|
-
|
|
40
|
-
// we don't need to go deeper
|
|
41
|
-
return false;
|
|
42
44
|
});
|
|
43
45
|
}
|
|
44
46
|
});
|
|
45
47
|
}
|
|
46
48
|
|
|
47
|
-
//
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
if (removed[node.attrs.localId]) {
|
|
53
|
-
// If a source block is removed and added back in the same transaction,
|
|
54
|
-
// we treat it as no-op.
|
|
55
|
-
delete removed[node.attrs.localId];
|
|
56
|
-
} else {
|
|
57
|
-
added[node.attrs.localId] = node.attrs;
|
|
58
|
-
}
|
|
49
|
+
// no need to check insertions if we already found deletions
|
|
50
|
+
if (step.slice.content.size > 0 && !hasChange) {
|
|
51
|
+
step.slice.content.forEach(function (node) {
|
|
52
|
+
if (predicate(node) && !hasChange) {
|
|
53
|
+
hasChange = true;
|
|
59
54
|
}
|
|
60
|
-
// we don't need to go deeper
|
|
61
|
-
return false;
|
|
62
55
|
});
|
|
63
56
|
}
|
|
57
|
+
return hasChange;
|
|
64
58
|
});
|
|
59
|
+
if (hasBodiedSyncBlockChanges) {
|
|
60
|
+
var oldDoc = state.doc;
|
|
61
|
+
var newDoc = tr.doc;
|
|
62
|
+
var syncBlockMapOld = {};
|
|
63
|
+
var syncBlockMapNew = {};
|
|
64
|
+
oldDoc.content.forEach(function (node) {
|
|
65
|
+
if (predicate(node)) {
|
|
66
|
+
var syncBlockAttr = node.attrs;
|
|
67
|
+
syncBlockMapOld[syncBlockAttr.localId] = syncBlockAttr;
|
|
68
|
+
}
|
|
69
|
+
});
|
|
70
|
+
newDoc.content.forEach(function (node) {
|
|
71
|
+
if (predicate(node)) {
|
|
72
|
+
var syncBlockAttr = node.attrs;
|
|
73
|
+
syncBlockMapNew[syncBlockAttr.localId] = syncBlockAttr;
|
|
74
|
+
}
|
|
75
|
+
});
|
|
76
|
+
|
|
77
|
+
// Find removed sync blocks
|
|
78
|
+
for (var localId in syncBlockMapOld) {
|
|
79
|
+
if (!syncBlockMapNew[localId]) {
|
|
80
|
+
removed[localId] = syncBlockMapOld[localId];
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
// Find added sync blocks
|
|
85
|
+
for (var _localId in syncBlockMapNew) {
|
|
86
|
+
if (!syncBlockMapOld[_localId]) {
|
|
87
|
+
added[_localId] = syncBlockMapNew[_localId];
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
}
|
|
65
91
|
return {
|
|
66
92
|
removed: Object.values(removed),
|
|
67
93
|
added: Object.values(added)
|
|
@@ -113,9 +113,11 @@ var syncedBlockPlugin = exports.syncedBlockPlugin = function syncedBlockPlugin(_
|
|
|
113
113
|
return;
|
|
114
114
|
}
|
|
115
115
|
var _syncedBlockPluginKey = _main.syncedBlockPluginKey.getState(editorState),
|
|
116
|
-
showFlag = _syncedBlockPluginKey.showFlag
|
|
116
|
+
showFlag = _syncedBlockPluginKey.showFlag,
|
|
117
|
+
currentSyncBlockStore = _syncedBlockPluginKey.syncBlockStore;
|
|
117
118
|
return {
|
|
118
|
-
showFlag: showFlag
|
|
119
|
+
showFlag: showFlag,
|
|
120
|
+
syncBlockStore: currentSyncBlockStore
|
|
119
121
|
};
|
|
120
122
|
}
|
|
121
123
|
};
|
|
@@ -10,7 +10,6 @@ const toDOM = () => ['div', {
|
|
|
10
10
|
class BodiedSyncBlock extends ReactNodeView {
|
|
11
11
|
constructor(props) {
|
|
12
12
|
super(props.node, props.view, props.getPos, props.portalProviderAPI, props.eventDispatcher, props);
|
|
13
|
-
this.syncBlockStore = props.syncBlockStore;
|
|
14
13
|
this.api = props.api;
|
|
15
14
|
this.handleConnectivityModeChange();
|
|
16
15
|
this.handleViewModeChange();
|
|
@@ -60,9 +59,14 @@ class BodiedSyncBlock extends ReactNodeView {
|
|
|
60
59
|
return domRef;
|
|
61
60
|
}
|
|
62
61
|
render(_props, forwardRef) {
|
|
62
|
+
var _this$api5, _this$api5$syncedBloc, _this$api5$syncedBloc2;
|
|
63
|
+
const syncBlockStore = (_this$api5 = this.api) === null || _this$api5 === void 0 ? void 0 : (_this$api5$syncedBloc = _this$api5.syncedBlock.sharedState) === null || _this$api5$syncedBloc === void 0 ? void 0 : (_this$api5$syncedBloc2 = _this$api5$syncedBloc.currentState()) === null || _this$api5$syncedBloc2 === void 0 ? void 0 : _this$api5$syncedBloc2.syncBlockStore;
|
|
64
|
+
if (!syncBlockStore) {
|
|
65
|
+
return null;
|
|
66
|
+
}
|
|
63
67
|
return /*#__PURE__*/React.createElement(BodiedSyncBlockWrapper, {
|
|
64
68
|
ref: forwardRef,
|
|
65
|
-
syncBlockStore:
|
|
69
|
+
syncBlockStore: syncBlockStore,
|
|
66
70
|
node: this.node
|
|
67
71
|
});
|
|
68
72
|
}
|
|
@@ -94,8 +98,7 @@ class BodiedSyncBlock extends ReactNodeView {
|
|
|
94
98
|
export const bodiedSyncBlockNodeView = ({
|
|
95
99
|
pluginOptions,
|
|
96
100
|
pmPluginFactoryParams,
|
|
97
|
-
api
|
|
98
|
-
syncBlockStore
|
|
101
|
+
api
|
|
99
102
|
}) => (node, view, getPos) => {
|
|
100
103
|
const {
|
|
101
104
|
portalProviderAPI,
|
|
@@ -108,7 +111,6 @@ export const bodiedSyncBlockNodeView = ({
|
|
|
108
111
|
view,
|
|
109
112
|
getPos,
|
|
110
113
|
portalProviderAPI,
|
|
111
|
-
eventDispatcher
|
|
112
|
-
syncBlockStore
|
|
114
|
+
eventDispatcher
|
|
113
115
|
}).init();
|
|
114
116
|
};
|
|
@@ -7,7 +7,7 @@ class SyncBlock extends ReactNodeView {
|
|
|
7
7
|
constructor(props) {
|
|
8
8
|
super(props.node, props.view, props.getPos, props.portalProviderAPI, props.eventDispatcher, props);
|
|
9
9
|
this.options = props.options;
|
|
10
|
-
this.
|
|
10
|
+
this.api = props.api;
|
|
11
11
|
}
|
|
12
12
|
createDomRef() {
|
|
13
13
|
const domRef = document.createElement('div');
|
|
@@ -15,7 +15,7 @@ class SyncBlock extends ReactNodeView {
|
|
|
15
15
|
return domRef;
|
|
16
16
|
}
|
|
17
17
|
render() {
|
|
18
|
-
var _this$options, _this$options2;
|
|
18
|
+
var _this$options, _this$api, _this$api$syncedBlock, _this$api$syncedBlock2, _this$options2;
|
|
19
19
|
if (!((_this$options = this.options) !== null && _this$options !== void 0 && _this$options.syncedBlockRenderer)) {
|
|
20
20
|
return null;
|
|
21
21
|
}
|
|
@@ -26,13 +26,17 @@ class SyncBlock extends ReactNodeView {
|
|
|
26
26
|
if (!resourceId || !localId) {
|
|
27
27
|
return null;
|
|
28
28
|
}
|
|
29
|
+
const syncBlockStore = (_this$api = this.api) === null || _this$api === void 0 ? void 0 : (_this$api$syncedBlock = _this$api.syncedBlock) === null || _this$api$syncedBlock === void 0 ? void 0 : (_this$api$syncedBlock2 = _this$api$syncedBlock.sharedState.currentState()) === null || _this$api$syncedBlock2 === void 0 ? void 0 : _this$api$syncedBlock2.syncBlockStore;
|
|
30
|
+
if (!syncBlockStore) {
|
|
31
|
+
return null;
|
|
32
|
+
}
|
|
29
33
|
|
|
30
34
|
// get document node from data provider
|
|
31
35
|
return /*#__PURE__*/React.createElement(SyncBlockRendererWrapper, {
|
|
32
36
|
localId: this.node.attrs.localId,
|
|
33
37
|
syncedBlockRenderer: (_this$options2 = this.options) === null || _this$options2 === void 0 ? void 0 : _this$options2.syncedBlockRenderer,
|
|
34
|
-
useFetchSyncBlockTitle: () => useFetchSyncBlockTitle(
|
|
35
|
-
useFetchSyncBlockData: () => useFetchSyncBlockData(
|
|
38
|
+
useFetchSyncBlockTitle: () => useFetchSyncBlockTitle(syncBlockStore, this.node),
|
|
39
|
+
useFetchSyncBlockData: () => useFetchSyncBlockData(syncBlockStore, resourceId, localId)
|
|
36
40
|
});
|
|
37
41
|
}
|
|
38
42
|
destroy() {
|
|
@@ -44,8 +48,7 @@ class SyncBlock extends ReactNodeView {
|
|
|
44
48
|
export const syncBlockNodeView = ({
|
|
45
49
|
options,
|
|
46
50
|
pmPluginFactoryParams,
|
|
47
|
-
api
|
|
48
|
-
syncBlockStore
|
|
51
|
+
api
|
|
49
52
|
}) => (node, view, getPos) => {
|
|
50
53
|
const {
|
|
51
54
|
portalProviderAPI,
|
|
@@ -58,7 +61,6 @@ export const syncBlockNodeView = ({
|
|
|
58
61
|
view,
|
|
59
62
|
getPos,
|
|
60
63
|
portalProviderAPI,
|
|
61
|
-
eventDispatcher
|
|
62
|
-
syncBlockStore
|
|
64
|
+
eventDispatcher
|
|
63
65
|
}).init();
|
|
64
66
|
};
|
|
@@ -23,7 +23,8 @@ export const createPlugin = (options, pmPluginFactoryParams, syncBlockStore, api
|
|
|
23
23
|
syncBlockStore.referenceManager.fetchSyncBlocksData(convertPMNodesToSyncBlockNodes(syncBlockNodes));
|
|
24
24
|
return {
|
|
25
25
|
selectionDecorationSet: calculateDecorations(instance.doc, instance.selection, instance.schema),
|
|
26
|
-
showFlag: false
|
|
26
|
+
showFlag: false,
|
|
27
|
+
syncBlockStore: syncBlockStore
|
|
27
28
|
};
|
|
28
29
|
},
|
|
29
30
|
apply: (tr, currentPluginState, oldEditorState) => {
|
|
@@ -39,7 +40,8 @@ export const createPlugin = (options, pmPluginFactoryParams, syncBlockStore, api
|
|
|
39
40
|
}
|
|
40
41
|
return {
|
|
41
42
|
showFlag: (_meta$showFlag = meta === null || meta === void 0 ? void 0 : meta.showFlag) !== null && _meta$showFlag !== void 0 ? _meta$showFlag : showFlag,
|
|
42
|
-
selectionDecorationSet: newDecorationSet
|
|
43
|
+
selectionDecorationSet: newDecorationSet,
|
|
44
|
+
syncBlockStore: syncBlockStore
|
|
43
45
|
};
|
|
44
46
|
}
|
|
45
47
|
},
|
|
@@ -48,14 +50,12 @@ export const createPlugin = (options, pmPluginFactoryParams, syncBlockStore, api
|
|
|
48
50
|
syncBlock: lazySyncBlockView({
|
|
49
51
|
options,
|
|
50
52
|
pmPluginFactoryParams,
|
|
51
|
-
api
|
|
52
|
-
syncBlockStore
|
|
53
|
+
api
|
|
53
54
|
}),
|
|
54
55
|
bodiedSyncBlock: lazyBodiedSyncBlockView({
|
|
55
56
|
pluginOptions: options,
|
|
56
57
|
pmPluginFactoryParams,
|
|
57
|
-
api
|
|
58
|
-
syncBlockStore
|
|
58
|
+
api
|
|
59
59
|
})
|
|
60
60
|
},
|
|
61
61
|
decorations: state => {
|
|
@@ -3,56 +3,82 @@ import { findParentNodeOfTypeClosestToPos } from '@atlaskit/editor-prosemirror/u
|
|
|
3
3
|
export const trackSyncBlocks = (predicate, tr, state) => {
|
|
4
4
|
const removed = {};
|
|
5
5
|
const added = {};
|
|
6
|
+
if (!tr.docChanged) {
|
|
7
|
+
return {
|
|
8
|
+
removed: [],
|
|
9
|
+
added: []
|
|
10
|
+
};
|
|
11
|
+
}
|
|
6
12
|
|
|
7
13
|
// and cast to specific step types
|
|
8
14
|
const replaceSteps = tr.steps.filter(step => step instanceof ReplaceStep || step instanceof ReplaceAroundStep);
|
|
9
|
-
|
|
15
|
+
|
|
16
|
+
// this is a quick check to see if any insertion/deletion of bodiedSyncBlock happened
|
|
17
|
+
const hasBodiedSyncBlockChanges = replaceSteps.some(step => {
|
|
10
18
|
const {
|
|
11
19
|
from,
|
|
12
20
|
to
|
|
13
21
|
} = step;
|
|
14
|
-
|
|
15
|
-
|
|
22
|
+
let hasChange = false;
|
|
16
23
|
if (from !== to) {
|
|
17
24
|
step.getMap().forEach((oldStart, oldEnd) => {
|
|
18
|
-
if (oldStart !== oldEnd) {
|
|
19
|
-
const deletedSlice = state.doc.slice(oldStart, oldEnd);
|
|
20
|
-
deletedSlice.content.
|
|
25
|
+
if (oldStart !== oldEnd && !hasChange) {
|
|
26
|
+
const deletedSlice = state.doc.slice(Math.max(0, oldStart), Math.min(state.doc.content.size, oldEnd));
|
|
27
|
+
deletedSlice.content.forEach((node, _, index) => {
|
|
28
|
+
if (hasChange) {
|
|
29
|
+
return;
|
|
30
|
+
}
|
|
31
|
+
// for top level nodes
|
|
21
32
|
if (predicate(node)) {
|
|
22
|
-
|
|
23
|
-
// If a source block added and then removed in the same transaction,
|
|
24
|
-
// we treat it as no-op.
|
|
25
|
-
delete added[node.attrs.localId];
|
|
26
|
-
} else {
|
|
27
|
-
removed[node.attrs.localId] = node.attrs;
|
|
28
|
-
}
|
|
33
|
+
hasChange = true;
|
|
29
34
|
}
|
|
30
|
-
|
|
31
|
-
// we don't need to go deeper
|
|
32
|
-
return false;
|
|
33
35
|
});
|
|
34
36
|
}
|
|
35
37
|
});
|
|
36
38
|
}
|
|
37
39
|
|
|
38
|
-
//
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
if (removed[node.attrs.localId]) {
|
|
44
|
-
// If a source block is removed and added back in the same transaction,
|
|
45
|
-
// we treat it as no-op.
|
|
46
|
-
delete removed[node.attrs.localId];
|
|
47
|
-
} else {
|
|
48
|
-
added[node.attrs.localId] = node.attrs;
|
|
49
|
-
}
|
|
40
|
+
// no need to check insertions if we already found deletions
|
|
41
|
+
if (step.slice.content.size > 0 && !hasChange) {
|
|
42
|
+
step.slice.content.forEach(node => {
|
|
43
|
+
if (predicate(node) && !hasChange) {
|
|
44
|
+
hasChange = true;
|
|
50
45
|
}
|
|
51
|
-
// we don't need to go deeper
|
|
52
|
-
return false;
|
|
53
46
|
});
|
|
54
47
|
}
|
|
48
|
+
return hasChange;
|
|
55
49
|
});
|
|
50
|
+
if (hasBodiedSyncBlockChanges) {
|
|
51
|
+
const oldDoc = state.doc;
|
|
52
|
+
const newDoc = tr.doc;
|
|
53
|
+
const syncBlockMapOld = {};
|
|
54
|
+
const syncBlockMapNew = {};
|
|
55
|
+
oldDoc.content.forEach(node => {
|
|
56
|
+
if (predicate(node)) {
|
|
57
|
+
const syncBlockAttr = node.attrs;
|
|
58
|
+
syncBlockMapOld[syncBlockAttr.localId] = syncBlockAttr;
|
|
59
|
+
}
|
|
60
|
+
});
|
|
61
|
+
newDoc.content.forEach(node => {
|
|
62
|
+
if (predicate(node)) {
|
|
63
|
+
const syncBlockAttr = node.attrs;
|
|
64
|
+
syncBlockMapNew[syncBlockAttr.localId] = syncBlockAttr;
|
|
65
|
+
}
|
|
66
|
+
});
|
|
67
|
+
|
|
68
|
+
// Find removed sync blocks
|
|
69
|
+
for (const localId in syncBlockMapOld) {
|
|
70
|
+
if (!syncBlockMapNew[localId]) {
|
|
71
|
+
removed[localId] = syncBlockMapOld[localId];
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
// Find added sync blocks
|
|
76
|
+
for (const localId in syncBlockMapNew) {
|
|
77
|
+
if (!syncBlockMapOld[localId]) {
|
|
78
|
+
added[localId] = syncBlockMapNew[localId];
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
}
|
|
56
82
|
return {
|
|
57
83
|
removed: Object.values(removed),
|
|
58
84
|
added: Object.values(added)
|
|
@@ -95,10 +95,12 @@ export const syncedBlockPlugin = ({
|
|
|
95
95
|
return;
|
|
96
96
|
}
|
|
97
97
|
const {
|
|
98
|
-
showFlag
|
|
98
|
+
showFlag,
|
|
99
|
+
syncBlockStore: currentSyncBlockStore
|
|
99
100
|
} = syncedBlockPluginKey.getState(editorState);
|
|
100
101
|
return {
|
|
101
|
-
showFlag
|
|
102
|
+
showFlag,
|
|
103
|
+
syncBlockStore: currentSyncBlockStore
|
|
102
104
|
};
|
|
103
105
|
}
|
|
104
106
|
};
|
|
@@ -21,7 +21,6 @@ var BodiedSyncBlock = /*#__PURE__*/function (_ReactNodeView) {
|
|
|
21
21
|
var _this;
|
|
22
22
|
_classCallCheck(this, BodiedSyncBlock);
|
|
23
23
|
_this = _callSuper(this, BodiedSyncBlock, [props.node, props.view, props.getPos, props.portalProviderAPI, props.eventDispatcher, props]);
|
|
24
|
-
_this.syncBlockStore = props.syncBlockStore;
|
|
25
24
|
_this.api = props.api;
|
|
26
25
|
_this.handleConnectivityModeChange();
|
|
27
26
|
_this.handleViewModeChange();
|
|
@@ -82,9 +81,14 @@ var BodiedSyncBlock = /*#__PURE__*/function (_ReactNodeView) {
|
|
|
82
81
|
}, {
|
|
83
82
|
key: "render",
|
|
84
83
|
value: function render(_props, forwardRef) {
|
|
84
|
+
var _this$api5;
|
|
85
|
+
var syncBlockStore = (_this$api5 = this.api) === null || _this$api5 === void 0 || (_this$api5 = _this$api5.syncedBlock.sharedState) === null || _this$api5 === void 0 || (_this$api5 = _this$api5.currentState()) === null || _this$api5 === void 0 ? void 0 : _this$api5.syncBlockStore;
|
|
86
|
+
if (!syncBlockStore) {
|
|
87
|
+
return null;
|
|
88
|
+
}
|
|
85
89
|
return /*#__PURE__*/React.createElement(BodiedSyncBlockWrapper, {
|
|
86
90
|
ref: forwardRef,
|
|
87
|
-
syncBlockStore:
|
|
91
|
+
syncBlockStore: syncBlockStore,
|
|
88
92
|
node: this.node
|
|
89
93
|
});
|
|
90
94
|
}
|
|
@@ -120,8 +124,7 @@ var BodiedSyncBlock = /*#__PURE__*/function (_ReactNodeView) {
|
|
|
120
124
|
export var bodiedSyncBlockNodeView = function bodiedSyncBlockNodeView(_ref4) {
|
|
121
125
|
var pluginOptions = _ref4.pluginOptions,
|
|
122
126
|
pmPluginFactoryParams = _ref4.pmPluginFactoryParams,
|
|
123
|
-
api = _ref4.api
|
|
124
|
-
syncBlockStore = _ref4.syncBlockStore;
|
|
127
|
+
api = _ref4.api;
|
|
125
128
|
return function (node, view, getPos) {
|
|
126
129
|
var portalProviderAPI = pmPluginFactoryParams.portalProviderAPI,
|
|
127
130
|
eventDispatcher = pmPluginFactoryParams.eventDispatcher;
|
|
@@ -132,8 +135,7 @@ export var bodiedSyncBlockNodeView = function bodiedSyncBlockNodeView(_ref4) {
|
|
|
132
135
|
view: view,
|
|
133
136
|
getPos: getPos,
|
|
134
137
|
portalProviderAPI: portalProviderAPI,
|
|
135
|
-
eventDispatcher: eventDispatcher
|
|
136
|
-
syncBlockStore: syncBlockStore
|
|
138
|
+
eventDispatcher: eventDispatcher
|
|
137
139
|
}).init();
|
|
138
140
|
};
|
|
139
141
|
};
|
|
@@ -18,7 +18,7 @@ var SyncBlock = /*#__PURE__*/function (_ReactNodeView) {
|
|
|
18
18
|
_classCallCheck(this, SyncBlock);
|
|
19
19
|
_this = _callSuper(this, SyncBlock, [props.node, props.view, props.getPos, props.portalProviderAPI, props.eventDispatcher, props]);
|
|
20
20
|
_this.options = props.options;
|
|
21
|
-
_this.
|
|
21
|
+
_this.api = props.api;
|
|
22
22
|
return _this;
|
|
23
23
|
}
|
|
24
24
|
_inherits(SyncBlock, _ReactNodeView);
|
|
@@ -33,6 +33,7 @@ var SyncBlock = /*#__PURE__*/function (_ReactNodeView) {
|
|
|
33
33
|
key: "render",
|
|
34
34
|
value: function render() {
|
|
35
35
|
var _this$options,
|
|
36
|
+
_this$api,
|
|
36
37
|
_this$options2,
|
|
37
38
|
_this2 = this;
|
|
38
39
|
if (!((_this$options = this.options) !== null && _this$options !== void 0 && _this$options.syncedBlockRenderer)) {
|
|
@@ -44,16 +45,20 @@ var SyncBlock = /*#__PURE__*/function (_ReactNodeView) {
|
|
|
44
45
|
if (!resourceId || !localId) {
|
|
45
46
|
return null;
|
|
46
47
|
}
|
|
48
|
+
var syncBlockStore = (_this$api = this.api) === null || _this$api === void 0 || (_this$api = _this$api.syncedBlock) === null || _this$api === void 0 || (_this$api = _this$api.sharedState.currentState()) === null || _this$api === void 0 ? void 0 : _this$api.syncBlockStore;
|
|
49
|
+
if (!syncBlockStore) {
|
|
50
|
+
return null;
|
|
51
|
+
}
|
|
47
52
|
|
|
48
53
|
// get document node from data provider
|
|
49
54
|
return /*#__PURE__*/React.createElement(SyncBlockRendererWrapper, {
|
|
50
55
|
localId: this.node.attrs.localId,
|
|
51
56
|
syncedBlockRenderer: (_this$options2 = this.options) === null || _this$options2 === void 0 ? void 0 : _this$options2.syncedBlockRenderer,
|
|
52
57
|
useFetchSyncBlockTitle: function useFetchSyncBlockTitle() {
|
|
53
|
-
return _useFetchSyncBlockTitle(
|
|
58
|
+
return _useFetchSyncBlockTitle(syncBlockStore, _this2.node);
|
|
54
59
|
},
|
|
55
60
|
useFetchSyncBlockData: function useFetchSyncBlockData() {
|
|
56
|
-
return _useFetchSyncBlockData(
|
|
61
|
+
return _useFetchSyncBlockData(syncBlockStore, resourceId, localId);
|
|
57
62
|
}
|
|
58
63
|
});
|
|
59
64
|
}
|
|
@@ -69,8 +74,7 @@ var SyncBlock = /*#__PURE__*/function (_ReactNodeView) {
|
|
|
69
74
|
export var syncBlockNodeView = function syncBlockNodeView(_ref) {
|
|
70
75
|
var options = _ref.options,
|
|
71
76
|
pmPluginFactoryParams = _ref.pmPluginFactoryParams,
|
|
72
|
-
api = _ref.api
|
|
73
|
-
syncBlockStore = _ref.syncBlockStore;
|
|
77
|
+
api = _ref.api;
|
|
74
78
|
return function (node, view, getPos) {
|
|
75
79
|
var portalProviderAPI = pmPluginFactoryParams.portalProviderAPI,
|
|
76
80
|
eventDispatcher = pmPluginFactoryParams.eventDispatcher;
|
|
@@ -81,8 +85,7 @@ export var syncBlockNodeView = function syncBlockNodeView(_ref) {
|
|
|
81
85
|
view: view,
|
|
82
86
|
getPos: getPos,
|
|
83
87
|
portalProviderAPI: portalProviderAPI,
|
|
84
|
-
eventDispatcher: eventDispatcher
|
|
85
|
-
syncBlockStore: syncBlockStore
|
|
88
|
+
eventDispatcher: eventDispatcher
|
|
86
89
|
}).init();
|
|
87
90
|
};
|
|
88
91
|
};
|
|
@@ -25,7 +25,8 @@ export var createPlugin = function createPlugin(options, pmPluginFactoryParams,
|
|
|
25
25
|
syncBlockStore.referenceManager.fetchSyncBlocksData(convertPMNodesToSyncBlockNodes(syncBlockNodes));
|
|
26
26
|
return {
|
|
27
27
|
selectionDecorationSet: calculateDecorations(instance.doc, instance.selection, instance.schema),
|
|
28
|
-
showFlag: false
|
|
28
|
+
showFlag: false,
|
|
29
|
+
syncBlockStore: syncBlockStore
|
|
29
30
|
};
|
|
30
31
|
},
|
|
31
32
|
apply: function apply(tr, currentPluginState, oldEditorState) {
|
|
@@ -39,7 +40,8 @@ export var createPlugin = function createPlugin(options, pmPluginFactoryParams,
|
|
|
39
40
|
}
|
|
40
41
|
return {
|
|
41
42
|
showFlag: (_meta$showFlag = meta === null || meta === void 0 ? void 0 : meta.showFlag) !== null && _meta$showFlag !== void 0 ? _meta$showFlag : showFlag,
|
|
42
|
-
selectionDecorationSet: newDecorationSet
|
|
43
|
+
selectionDecorationSet: newDecorationSet,
|
|
44
|
+
syncBlockStore: syncBlockStore
|
|
43
45
|
};
|
|
44
46
|
}
|
|
45
47
|
},
|
|
@@ -48,14 +50,12 @@ export var createPlugin = function createPlugin(options, pmPluginFactoryParams,
|
|
|
48
50
|
syncBlock: lazySyncBlockView({
|
|
49
51
|
options: options,
|
|
50
52
|
pmPluginFactoryParams: pmPluginFactoryParams,
|
|
51
|
-
api: api
|
|
52
|
-
syncBlockStore: syncBlockStore
|
|
53
|
+
api: api
|
|
53
54
|
}),
|
|
54
55
|
bodiedSyncBlock: lazyBodiedSyncBlockView({
|
|
55
56
|
pluginOptions: options,
|
|
56
57
|
pmPluginFactoryParams: pmPluginFactoryParams,
|
|
57
|
-
api: api
|
|
58
|
-
syncBlockStore: syncBlockStore
|
|
58
|
+
api: api
|
|
59
59
|
})
|
|
60
60
|
},
|
|
61
61
|
decorations: function decorations(state) {
|
|
@@ -6,56 +6,82 @@ import { findParentNodeOfTypeClosestToPos } from '@atlaskit/editor-prosemirror/u
|
|
|
6
6
|
export var trackSyncBlocks = function trackSyncBlocks(predicate, tr, state) {
|
|
7
7
|
var removed = {};
|
|
8
8
|
var added = {};
|
|
9
|
+
if (!tr.docChanged) {
|
|
10
|
+
return {
|
|
11
|
+
removed: [],
|
|
12
|
+
added: []
|
|
13
|
+
};
|
|
14
|
+
}
|
|
9
15
|
|
|
10
16
|
// and cast to specific step types
|
|
11
17
|
var replaceSteps = tr.steps.filter(function (step) {
|
|
12
18
|
return step instanceof ReplaceStep || step instanceof ReplaceAroundStep;
|
|
13
19
|
});
|
|
14
|
-
|
|
20
|
+
|
|
21
|
+
// this is a quick check to see if any insertion/deletion of bodiedSyncBlock happened
|
|
22
|
+
var hasBodiedSyncBlockChanges = replaceSteps.some(function (step) {
|
|
15
23
|
var from = step.from,
|
|
16
24
|
to = step.to;
|
|
17
|
-
|
|
18
|
-
|
|
25
|
+
var hasChange = false;
|
|
19
26
|
if (from !== to) {
|
|
20
27
|
step.getMap().forEach(function (oldStart, oldEnd) {
|
|
21
|
-
if (oldStart !== oldEnd) {
|
|
22
|
-
var deletedSlice = state.doc.slice(oldStart, oldEnd);
|
|
23
|
-
deletedSlice.content.
|
|
28
|
+
if (oldStart !== oldEnd && !hasChange) {
|
|
29
|
+
var deletedSlice = state.doc.slice(Math.max(0, oldStart), Math.min(state.doc.content.size, oldEnd));
|
|
30
|
+
deletedSlice.content.forEach(function (node, _, index) {
|
|
31
|
+
if (hasChange) {
|
|
32
|
+
return;
|
|
33
|
+
}
|
|
34
|
+
// for top level nodes
|
|
24
35
|
if (predicate(node)) {
|
|
25
|
-
|
|
26
|
-
// If a source block added and then removed in the same transaction,
|
|
27
|
-
// we treat it as no-op.
|
|
28
|
-
delete added[node.attrs.localId];
|
|
29
|
-
} else {
|
|
30
|
-
removed[node.attrs.localId] = node.attrs;
|
|
31
|
-
}
|
|
36
|
+
hasChange = true;
|
|
32
37
|
}
|
|
33
|
-
|
|
34
|
-
// we don't need to go deeper
|
|
35
|
-
return false;
|
|
36
38
|
});
|
|
37
39
|
}
|
|
38
40
|
});
|
|
39
41
|
}
|
|
40
42
|
|
|
41
|
-
//
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
if (removed[node.attrs.localId]) {
|
|
47
|
-
// If a source block is removed and added back in the same transaction,
|
|
48
|
-
// we treat it as no-op.
|
|
49
|
-
delete removed[node.attrs.localId];
|
|
50
|
-
} else {
|
|
51
|
-
added[node.attrs.localId] = node.attrs;
|
|
52
|
-
}
|
|
43
|
+
// no need to check insertions if we already found deletions
|
|
44
|
+
if (step.slice.content.size > 0 && !hasChange) {
|
|
45
|
+
step.slice.content.forEach(function (node) {
|
|
46
|
+
if (predicate(node) && !hasChange) {
|
|
47
|
+
hasChange = true;
|
|
53
48
|
}
|
|
54
|
-
// we don't need to go deeper
|
|
55
|
-
return false;
|
|
56
49
|
});
|
|
57
50
|
}
|
|
51
|
+
return hasChange;
|
|
58
52
|
});
|
|
53
|
+
if (hasBodiedSyncBlockChanges) {
|
|
54
|
+
var oldDoc = state.doc;
|
|
55
|
+
var newDoc = tr.doc;
|
|
56
|
+
var syncBlockMapOld = {};
|
|
57
|
+
var syncBlockMapNew = {};
|
|
58
|
+
oldDoc.content.forEach(function (node) {
|
|
59
|
+
if (predicate(node)) {
|
|
60
|
+
var syncBlockAttr = node.attrs;
|
|
61
|
+
syncBlockMapOld[syncBlockAttr.localId] = syncBlockAttr;
|
|
62
|
+
}
|
|
63
|
+
});
|
|
64
|
+
newDoc.content.forEach(function (node) {
|
|
65
|
+
if (predicate(node)) {
|
|
66
|
+
var syncBlockAttr = node.attrs;
|
|
67
|
+
syncBlockMapNew[syncBlockAttr.localId] = syncBlockAttr;
|
|
68
|
+
}
|
|
69
|
+
});
|
|
70
|
+
|
|
71
|
+
// Find removed sync blocks
|
|
72
|
+
for (var localId in syncBlockMapOld) {
|
|
73
|
+
if (!syncBlockMapNew[localId]) {
|
|
74
|
+
removed[localId] = syncBlockMapOld[localId];
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
// Find added sync blocks
|
|
79
|
+
for (var _localId in syncBlockMapNew) {
|
|
80
|
+
if (!syncBlockMapOld[_localId]) {
|
|
81
|
+
added[_localId] = syncBlockMapNew[_localId];
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
}
|
|
59
85
|
return {
|
|
60
86
|
removed: Object.values(removed),
|
|
61
87
|
added: Object.values(added)
|
|
@@ -106,9 +106,11 @@ export var syncedBlockPlugin = function syncedBlockPlugin(_ref) {
|
|
|
106
106
|
return;
|
|
107
107
|
}
|
|
108
108
|
var _syncedBlockPluginKey = syncedBlockPluginKey.getState(editorState),
|
|
109
|
-
showFlag = _syncedBlockPluginKey.showFlag
|
|
109
|
+
showFlag = _syncedBlockPluginKey.showFlag,
|
|
110
|
+
currentSyncBlockStore = _syncedBlockPluginKey.syncBlockStore;
|
|
110
111
|
return {
|
|
111
|
-
showFlag: showFlag
|
|
112
|
+
showFlag: showFlag,
|
|
113
|
+
syncBlockStore: currentSyncBlockStore
|
|
112
114
|
};
|
|
113
115
|
}
|
|
114
116
|
};
|
|
@@ -5,7 +5,6 @@ import ReactNodeView, { type getPosHandler } from '@atlaskit/editor-common/react
|
|
|
5
5
|
import type { ExtractInjectionAPI, PMPluginFactoryParams } from '@atlaskit/editor-common/types';
|
|
6
6
|
import { type Node as PMNode } from '@atlaskit/editor-prosemirror/model';
|
|
7
7
|
import type { EditorView } from '@atlaskit/editor-prosemirror/view';
|
|
8
|
-
import type { SyncBlockStoreManager } from '@atlaskit/editor-synced-block-provider';
|
|
9
8
|
import type { SyncedBlockPlugin, SyncedBlockPluginOptions } from '../syncedBlockPluginType';
|
|
10
9
|
export interface BodiedSyncBlockNodeViewProps extends ReactComponentProps {
|
|
11
10
|
api?: ExtractInjectionAPI<SyncedBlockPlugin>;
|
|
@@ -14,13 +13,11 @@ export interface BodiedSyncBlockNodeViewProps extends ReactComponentProps {
|
|
|
14
13
|
node: PMNode;
|
|
15
14
|
pluginOptions: SyncedBlockPluginOptions | undefined;
|
|
16
15
|
portalProviderAPI: PortalProviderAPI;
|
|
17
|
-
syncBlockStore: SyncBlockStoreManager;
|
|
18
16
|
view: EditorView;
|
|
19
17
|
}
|
|
20
18
|
export interface BodiedSyncBlockNodeViewProperties {
|
|
21
19
|
api?: ExtractInjectionAPI<SyncedBlockPlugin>;
|
|
22
20
|
pluginOptions: SyncedBlockPluginOptions | undefined;
|
|
23
21
|
pmPluginFactoryParams: PMPluginFactoryParams;
|
|
24
|
-
syncBlockStore: SyncBlockStoreManager;
|
|
25
22
|
}
|
|
26
23
|
export declare const bodiedSyncBlockNodeView: (props: BodiedSyncBlockNodeViewProperties) => (node: PMNode, view: EditorView, getPos: getPosHandler) => ReactNodeView<BodiedSyncBlockNodeViewProps>;
|
|
@@ -5,7 +5,6 @@ import type { ReactComponentProps } from '@atlaskit/editor-common/react-node-vie
|
|
|
5
5
|
import type { ExtractInjectionAPI, PMPluginFactoryParams } from '@atlaskit/editor-common/types';
|
|
6
6
|
import type { Node as PMNode } from '@atlaskit/editor-prosemirror/model';
|
|
7
7
|
import type { EditorView } from '@atlaskit/editor-prosemirror/view';
|
|
8
|
-
import type { SyncBlockStoreManager } from '@atlaskit/editor-synced-block-provider';
|
|
9
8
|
import type { SyncedBlockPlugin, SyncedBlockPluginOptions } from '../syncedBlockPluginType';
|
|
10
9
|
export interface SyncBlockNodeViewProps extends ReactComponentProps {
|
|
11
10
|
api?: ExtractInjectionAPI<SyncedBlockPlugin>;
|
|
@@ -15,13 +14,11 @@ export interface SyncBlockNodeViewProps extends ReactComponentProps {
|
|
|
15
14
|
node: PMNode;
|
|
16
15
|
options: SyncedBlockPluginOptions | undefined;
|
|
17
16
|
portalProviderAPI: PortalProviderAPI;
|
|
18
|
-
syncBlockStore: SyncBlockStoreManager;
|
|
19
17
|
view: EditorView;
|
|
20
18
|
}
|
|
21
19
|
export interface SyncBlockNodeViewProperties {
|
|
22
20
|
api?: ExtractInjectionAPI<SyncedBlockPlugin>;
|
|
23
21
|
options: SyncedBlockPluginOptions | undefined;
|
|
24
22
|
pmPluginFactoryParams: PMPluginFactoryParams;
|
|
25
|
-
syncBlockStore: SyncBlockStoreManager;
|
|
26
23
|
}
|
|
27
24
|
export declare const syncBlockNodeView: (props: SyncBlockNodeViewProperties) => (node: PMNode, view: EditorView, getPos: getPosHandler) => ReactNodeView<SyncBlockNodeViewProps>;
|
|
@@ -9,6 +9,7 @@ export declare const syncedBlockPluginKey: PluginKey<any>;
|
|
|
9
9
|
type SyncedBlockPluginState = {
|
|
10
10
|
selectionDecorationSet: DecorationSet;
|
|
11
11
|
showFlag: FLAG_ID | false;
|
|
12
|
+
syncBlockStore: SyncBlockStoreManager;
|
|
12
13
|
};
|
|
13
14
|
export declare const createPlugin: (options: SyncedBlockPluginOptions | undefined, pmPluginFactoryParams: PMPluginFactoryParams, syncBlockStore: SyncBlockStoreManager, api?: ExtractInjectionAPI<SyncedBlockPlugin>) => SafePlugin<SyncedBlockPluginState>;
|
|
14
15
|
export {};
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { SyncBlockStoreManager } from '@atlaskit/editor-synced-block-provider';
|
|
1
2
|
export declare enum FLAG_ID {
|
|
2
3
|
CANNOT_DELETE_WHEN_OFFLINE = "cannot-delete-when-offline",
|
|
3
4
|
CANNOT_EDIT_WHEN_OFFLINE = "cannot-edit-when-offline",
|
|
@@ -8,4 +9,8 @@ export type SyncedBlockSharedState = {
|
|
|
8
9
|
* Whether to show a flag (usually for errors, e.g. fail to delete)
|
|
9
10
|
*/
|
|
10
11
|
showFlag: FLAG_ID | false;
|
|
12
|
+
/**
|
|
13
|
+
* The current sync block store manager, used to manage fetching and updating sync block data
|
|
14
|
+
*/
|
|
15
|
+
syncBlockStore: SyncBlockStoreManager;
|
|
11
16
|
};
|
|
@@ -5,7 +5,6 @@ import ReactNodeView, { type getPosHandler } from '@atlaskit/editor-common/react
|
|
|
5
5
|
import type { ExtractInjectionAPI, PMPluginFactoryParams } from '@atlaskit/editor-common/types';
|
|
6
6
|
import { type Node as PMNode } from '@atlaskit/editor-prosemirror/model';
|
|
7
7
|
import type { EditorView } from '@atlaskit/editor-prosemirror/view';
|
|
8
|
-
import type { SyncBlockStoreManager } from '@atlaskit/editor-synced-block-provider';
|
|
9
8
|
import type { SyncedBlockPlugin, SyncedBlockPluginOptions } from '../syncedBlockPluginType';
|
|
10
9
|
export interface BodiedSyncBlockNodeViewProps extends ReactComponentProps {
|
|
11
10
|
api?: ExtractInjectionAPI<SyncedBlockPlugin>;
|
|
@@ -14,13 +13,11 @@ export interface BodiedSyncBlockNodeViewProps extends ReactComponentProps {
|
|
|
14
13
|
node: PMNode;
|
|
15
14
|
pluginOptions: SyncedBlockPluginOptions | undefined;
|
|
16
15
|
portalProviderAPI: PortalProviderAPI;
|
|
17
|
-
syncBlockStore: SyncBlockStoreManager;
|
|
18
16
|
view: EditorView;
|
|
19
17
|
}
|
|
20
18
|
export interface BodiedSyncBlockNodeViewProperties {
|
|
21
19
|
api?: ExtractInjectionAPI<SyncedBlockPlugin>;
|
|
22
20
|
pluginOptions: SyncedBlockPluginOptions | undefined;
|
|
23
21
|
pmPluginFactoryParams: PMPluginFactoryParams;
|
|
24
|
-
syncBlockStore: SyncBlockStoreManager;
|
|
25
22
|
}
|
|
26
23
|
export declare const bodiedSyncBlockNodeView: (props: BodiedSyncBlockNodeViewProperties) => (node: PMNode, view: EditorView, getPos: getPosHandler) => ReactNodeView<BodiedSyncBlockNodeViewProps>;
|
|
@@ -5,7 +5,6 @@ import type { ReactComponentProps } from '@atlaskit/editor-common/react-node-vie
|
|
|
5
5
|
import type { ExtractInjectionAPI, PMPluginFactoryParams } from '@atlaskit/editor-common/types';
|
|
6
6
|
import type { Node as PMNode } from '@atlaskit/editor-prosemirror/model';
|
|
7
7
|
import type { EditorView } from '@atlaskit/editor-prosemirror/view';
|
|
8
|
-
import type { SyncBlockStoreManager } from '@atlaskit/editor-synced-block-provider';
|
|
9
8
|
import type { SyncedBlockPlugin, SyncedBlockPluginOptions } from '../syncedBlockPluginType';
|
|
10
9
|
export interface SyncBlockNodeViewProps extends ReactComponentProps {
|
|
11
10
|
api?: ExtractInjectionAPI<SyncedBlockPlugin>;
|
|
@@ -15,13 +14,11 @@ export interface SyncBlockNodeViewProps extends ReactComponentProps {
|
|
|
15
14
|
node: PMNode;
|
|
16
15
|
options: SyncedBlockPluginOptions | undefined;
|
|
17
16
|
portalProviderAPI: PortalProviderAPI;
|
|
18
|
-
syncBlockStore: SyncBlockStoreManager;
|
|
19
17
|
view: EditorView;
|
|
20
18
|
}
|
|
21
19
|
export interface SyncBlockNodeViewProperties {
|
|
22
20
|
api?: ExtractInjectionAPI<SyncedBlockPlugin>;
|
|
23
21
|
options: SyncedBlockPluginOptions | undefined;
|
|
24
22
|
pmPluginFactoryParams: PMPluginFactoryParams;
|
|
25
|
-
syncBlockStore: SyncBlockStoreManager;
|
|
26
23
|
}
|
|
27
24
|
export declare const syncBlockNodeView: (props: SyncBlockNodeViewProperties) => (node: PMNode, view: EditorView, getPos: getPosHandler) => ReactNodeView<SyncBlockNodeViewProps>;
|
|
@@ -9,6 +9,7 @@ export declare const syncedBlockPluginKey: PluginKey<any>;
|
|
|
9
9
|
type SyncedBlockPluginState = {
|
|
10
10
|
selectionDecorationSet: DecorationSet;
|
|
11
11
|
showFlag: FLAG_ID | false;
|
|
12
|
+
syncBlockStore: SyncBlockStoreManager;
|
|
12
13
|
};
|
|
13
14
|
export declare const createPlugin: (options: SyncedBlockPluginOptions | undefined, pmPluginFactoryParams: PMPluginFactoryParams, syncBlockStore: SyncBlockStoreManager, api?: ExtractInjectionAPI<SyncedBlockPlugin>) => SafePlugin<SyncedBlockPluginState>;
|
|
14
15
|
export {};
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { SyncBlockStoreManager } from '@atlaskit/editor-synced-block-provider';
|
|
1
2
|
export declare enum FLAG_ID {
|
|
2
3
|
CANNOT_DELETE_WHEN_OFFLINE = "cannot-delete-when-offline",
|
|
3
4
|
CANNOT_EDIT_WHEN_OFFLINE = "cannot-edit-when-offline",
|
|
@@ -8,4 +9,8 @@ export type SyncedBlockSharedState = {
|
|
|
8
9
|
* Whether to show a flag (usually for errors, e.g. fail to delete)
|
|
9
10
|
*/
|
|
10
11
|
showFlag: FLAG_ID | false;
|
|
12
|
+
/**
|
|
13
|
+
* The current sync block store manager, used to manage fetching and updating sync block data
|
|
14
|
+
*/
|
|
15
|
+
syncBlockStore: SyncBlockStoreManager;
|
|
11
16
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@atlaskit/editor-plugin-synced-block",
|
|
3
|
-
"version": "4.
|
|
3
|
+
"version": "4.3.0",
|
|
4
4
|
"description": "SyncedBlock plugin for @atlaskit/editor-core",
|
|
5
5
|
"author": "Atlassian Pty Ltd",
|
|
6
6
|
"license": "Apache-2.0",
|
|
@@ -49,7 +49,7 @@
|
|
|
49
49
|
"@atlaskit/lozenge": "^13.1.0",
|
|
50
50
|
"@atlaskit/modal-dialog": "^14.7.0",
|
|
51
51
|
"@atlaskit/primitives": "^16.2.0",
|
|
52
|
-
"@atlaskit/tokens": "8.
|
|
52
|
+
"@atlaskit/tokens": "8.2.0",
|
|
53
53
|
"@atlaskit/tooltip": "^20.10.0",
|
|
54
54
|
"@atlaskit/visually-hidden": "^3.0.0",
|
|
55
55
|
"@babel/runtime": "^7.0.0",
|