@atlaskit/editor-plugin-synced-block 2.2.2 → 2.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.
Files changed (33) hide show
  1. package/CHANGELOG.md +13 -0
  2. package/afm-cc/tsconfig.json +3 -0
  3. package/afm-dev-agents/tsconfig.json +3 -0
  4. package/afm-jira/tsconfig.json +3 -0
  5. package/afm-passionfruit/tsconfig.json +3 -0
  6. package/afm-post-office/tsconfig.json +3 -0
  7. package/afm-rovo-extension/tsconfig.json +3 -0
  8. package/afm-townsquare/tsconfig.json +3 -0
  9. package/dist/cjs/nodeviews/syncedBlock.js +45 -12
  10. package/dist/cjs/pm-plugins/main.js +5 -1
  11. package/dist/cjs/syncedBlockPlugin.js +2 -2
  12. package/dist/cjs/ui/SyncBlockRendererWrapper.js +2 -2
  13. package/dist/es2019/nodeviews/syncedBlock.js +37 -12
  14. package/dist/es2019/pm-plugins/main.js +5 -1
  15. package/dist/es2019/syncedBlockPlugin.js +1 -1
  16. package/dist/es2019/ui/SyncBlockRendererWrapper.js +2 -2
  17. package/dist/esm/nodeviews/syncedBlock.js +45 -12
  18. package/dist/esm/pm-plugins/main.js +5 -1
  19. package/dist/esm/syncedBlockPlugin.js +1 -1
  20. package/dist/esm/ui/SyncBlockRendererWrapper.js +2 -2
  21. package/dist/types/nodeviews/syncedBlock.d.ts +1 -0
  22. package/dist/types/pm-plugins/main.d.ts +1 -1
  23. package/dist/types/pm-plugins/utils/track-sync-blocks.d.ts +1 -1
  24. package/dist/types/syncedBlockPluginType.d.ts +3 -2
  25. package/dist/types/ui/ContentComponent.d.ts +1 -1
  26. package/dist/types/ui/SyncBlockRendererWrapper.d.ts +2 -2
  27. package/dist/types-ts4.5/nodeviews/syncedBlock.d.ts +1 -0
  28. package/dist/types-ts4.5/pm-plugins/main.d.ts +1 -1
  29. package/dist/types-ts4.5/pm-plugins/utils/track-sync-blocks.d.ts +1 -1
  30. package/dist/types-ts4.5/syncedBlockPluginType.d.ts +3 -2
  31. package/dist/types-ts4.5/ui/ContentComponent.d.ts +1 -1
  32. package/dist/types-ts4.5/ui/SyncBlockRendererWrapper.d.ts +2 -2
  33. package/package.json +5 -4
package/CHANGELOG.md CHANGED
@@ -1,5 +1,18 @@
1
1
  # @atlaskit/editor-plugin-synced-block
2
2
 
3
+ ## 2.3.0
4
+
5
+ ### Minor Changes
6
+
7
+ - [`687c1b8fa7801`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/687c1b8fa7801) -
8
+ EDITOR-1566 bump adf-schema + update validator
9
+ - [`578ac13fd9edd`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/578ac13fd9edd) -
10
+ Add Sync Block provider as new package
11
+
12
+ ### Patch Changes
13
+
14
+ - Updated dependencies
15
+
3
16
  ## 2.2.2
4
17
 
5
18
  ### Patch Changes
@@ -28,6 +28,9 @@
28
28
  {
29
29
  "path": "../../editor-plugin-selection/afm-cc/tsconfig.json"
30
30
  },
31
+ {
32
+ "path": "../../editor-synced-block-provider/afm-cc/tsconfig.json"
33
+ },
31
34
  {
32
35
  "path": "../../../design-system/icon/afm-cc/tsconfig.json"
33
36
  },
@@ -28,6 +28,9 @@
28
28
  {
29
29
  "path": "../../editor-plugin-selection/afm-dev-agents/tsconfig.json"
30
30
  },
31
+ {
32
+ "path": "../../editor-synced-block-provider/afm-dev-agents/tsconfig.json"
33
+ },
31
34
  {
32
35
  "path": "../../../design-system/icon/afm-dev-agents/tsconfig.json"
33
36
  },
@@ -28,6 +28,9 @@
28
28
  {
29
29
  "path": "../../editor-plugin-selection/afm-jira/tsconfig.json"
30
30
  },
31
+ {
32
+ "path": "../../editor-synced-block-provider/afm-jira/tsconfig.json"
33
+ },
31
34
  {
32
35
  "path": "../../../design-system/icon/afm-jira/tsconfig.json"
33
36
  },
@@ -28,6 +28,9 @@
28
28
  {
29
29
  "path": "../../editor-plugin-selection/afm-passionfruit/tsconfig.json"
30
30
  },
31
+ {
32
+ "path": "../../editor-synced-block-provider/afm-passionfruit/tsconfig.json"
33
+ },
31
34
  {
32
35
  "path": "../../../design-system/icon/afm-passionfruit/tsconfig.json"
33
36
  },
@@ -28,6 +28,9 @@
28
28
  {
29
29
  "path": "../../editor-plugin-selection/afm-post-office/tsconfig.json"
30
30
  },
31
+ {
32
+ "path": "../../editor-synced-block-provider/afm-post-office/tsconfig.json"
33
+ },
31
34
  {
32
35
  "path": "../../../design-system/icon/afm-post-office/tsconfig.json"
33
36
  },
@@ -28,6 +28,9 @@
28
28
  {
29
29
  "path": "../../editor-plugin-selection/afm-rovo-extension/tsconfig.json"
30
30
  },
31
+ {
32
+ "path": "../../editor-synced-block-provider/afm-rovo-extension/tsconfig.json"
33
+ },
31
34
  {
32
35
  "path": "../../../design-system/icon/afm-rovo-extension/tsconfig.json"
33
36
  },
@@ -28,6 +28,9 @@
28
28
  {
29
29
  "path": "../../editor-plugin-selection/afm-townsquare/tsconfig.json"
30
30
  },
31
+ {
32
+ "path": "../../editor-synced-block-provider/afm-townsquare/tsconfig.json"
33
+ },
31
34
  {
32
35
  "path": "../../../design-system/icon/afm-townsquare/tsconfig.json"
33
36
  },
@@ -15,6 +15,7 @@ var _react = _interopRequireDefault(require("react"));
15
15
  var _reactNodeView = _interopRequireDefault(require("@atlaskit/editor-common/react-node-view"));
16
16
  var _syncBlock = require("@atlaskit/editor-common/sync-block");
17
17
  var _state = require("@atlaskit/editor-prosemirror/state");
18
+ var _editorSyncedBlockProvider = require("@atlaskit/editor-synced-block-provider");
18
19
  var _SyncBlockEditorWrapper = require("../ui/SyncBlockEditorWrapper");
19
20
  var _SyncBlockRendererWrapper = require("../ui/SyncBlockRendererWrapper");
20
21
  function _callSuper(t, o, e) { return o = (0, _getPrototypeOf2.default)(o), (0, _possibleConstructorReturn2.default)(t, _isNativeReflectConstruct() ? Reflect.construct(o, e || [], (0, _getPrototypeOf2.default)(t).constructor) : o.apply(t, e)); }
@@ -65,47 +66,76 @@ var SyncBlock = /*#__PURE__*/function (_ReactNodeView) {
65
66
  }
66
67
  }, {
67
68
  key: "handleContentChanges",
68
- value: function handleContentChanges(_updatedDoc) {
69
+ value: function handleContentChanges(updatedDoc) {
70
+ var _this$options;
71
+ if (!this.isSource) {
72
+ return;
73
+ }
69
74
  // write data
75
+ var node = (0, _editorSyncedBlockProvider.createSyncBlockNode)(this.node, false);
76
+ (_this$options = this.options) === null || _this$options === void 0 || (_this$options = _this$options.syncedBlockProvider) === null || _this$options === void 0 || _this$options.writeNodesData([node], [{
77
+ content: updatedDoc.toJSON()
78
+ }]);
70
79
  }
71
80
  }, {
72
81
  key: "setInnerEditorView",
73
- value: function setInnerEditorView(_editorView) {
82
+ value: function setInnerEditorView(editorView) {
83
+ var _this$options2;
74
84
  // set inner editor view
85
+ var nodes = [(0, _editorSyncedBlockProvider.createSyncBlockNode)(this.node, false)];
86
+ (_this$options2 = this.options) === null || _this$options2 === void 0 || (_this$options2 = _this$options2.syncedBlockProvider) === null || _this$options2 === void 0 || _this$options2.fetchNodesData(nodes).then(function (data) {
87
+ var _data$;
88
+ var tr = editorView.state.tr;
89
+ if (data && (_data$ = data[0]) !== null && _data$ !== void 0 && _data$.content) {
90
+ var newNode = editorView.state.schema.nodeFromJSON(data[0].content);
91
+ editorView.dispatch(tr.replaceWith(0, editorView.state.doc.nodeSize - 2, newNode));
92
+ }
93
+ });
75
94
  }
76
95
  }, {
77
96
  key: "renderEditor",
78
97
  value: function renderEditor() {
79
- var _this$options, _this$options2;
98
+ var _this$options3,
99
+ _this2 = this,
100
+ _this$options4;
80
101
  var fabricEditorPopupScrollParent = this.view.dom.closest('.fabric-editor-popup-scroll-parent');
81
102
  if (!(fabricEditorPopupScrollParent instanceof HTMLElement)) {
82
103
  return null;
83
104
  }
84
- if (!((_this$options = this.options) !== null && _this$options !== void 0 && _this$options.getSyncedBlockEditor)) {
105
+ if (!((_this$options3 = this.options) !== null && _this$options3 !== void 0 && _this$options3.getSyncedBlockEditor)) {
85
106
  return null;
86
107
  }
87
108
  return /*#__PURE__*/_react.default.createElement(_SyncBlockEditorWrapper.SyncBlockEditorWrapper, {
88
109
  popupsBoundariesElement: fabricEditorPopupScrollParent,
89
110
  popupsMountPoint: fabricEditorPopupScrollParent,
90
111
  defaultDocument: defaultSyncBlockEditorDocument,
91
- handleContentChanges: this.handleContentChanges,
92
- setInnerEditorView: this.setInnerEditorView,
93
- getSyncedBlockEditor: (_this$options2 = this.options) === null || _this$options2 === void 0 ? void 0 : _this$options2.getSyncedBlockEditor
112
+ handleContentChanges: function handleContentChanges(updatedDoc) {
113
+ return _this2.handleContentChanges(updatedDoc);
114
+ },
115
+ setInnerEditorView: function setInnerEditorView(editorView) {
116
+ return _this2.setInnerEditorView(editorView);
117
+ },
118
+ getSyncedBlockEditor: (_this$options4 = this.options) === null || _this$options4 === void 0 ? void 0 : _this$options4.getSyncedBlockEditor
94
119
  });
95
120
  }
96
121
  }, {
97
122
  key: "renderRenderer",
98
123
  value: function renderRenderer() {
99
- var _this$options3, _this$options4;
100
- if (!((_this$options3 = this.options) !== null && _this$options3 !== void 0 && _this$options3.getSyncedBlockRenderer)) {
124
+ var _this$options5,
125
+ _this3 = this,
126
+ _this$options6;
127
+ if (!((_this$options5 = this.options) !== null && _this$options5 !== void 0 && _this$options5.getSyncedBlockRenderer)) {
101
128
  return null;
102
129
  }
103
130
 
104
131
  // get document node from data provider
105
- var docNode = defaultSyncBlockRendererDocument;
132
+
106
133
  return /*#__PURE__*/_react.default.createElement(_SyncBlockRendererWrapper.SyncBlockRendererWrapper, {
107
- docNode: docNode,
108
- getSyncedBlockRenderer: (_this$options4 = this.options) === null || _this$options4 === void 0 ? void 0 : _this$options4.getSyncedBlockRenderer
134
+ useFetchDocNode: function useFetchDocNode() {
135
+ var _this3$options;
136
+ return (0, _editorSyncedBlockProvider.useFetchDocNode)(_this3.view, _this3.node, defaultSyncBlockRendererDocument, (_this3$options = _this3.options) === null || _this3$options === void 0 ? void 0 : _this3$options.syncedBlockProvider);
137
+ },
138
+ getSyncedBlockRenderer: (_this$options6 = this.options) === null || _this$options6 === void 0 ? void 0 : _this$options6.getSyncedBlockRenderer
109
139
  });
110
140
  }
111
141
  }, {
@@ -140,6 +170,9 @@ var SyncBlock = /*#__PURE__*/function (_ReactNodeView) {
140
170
  key: "destroy",
141
171
  value: function destroy() {
142
172
  var _this$unsubscribe;
173
+ if (this.fetchIntervalId) {
174
+ window.clearInterval(this.fetchIntervalId);
175
+ }
143
176
  (_this$unsubscribe = this.unsubscribe) === null || _this$unsubscribe === void 0 || _this$unsubscribe.call(this);
144
177
  _superPropGet(SyncBlock, "destroy", this, 3)([]);
145
178
  }
@@ -19,7 +19,11 @@ var createPlugin = exports.createPlugin = function createPlugin(options, pmPlugi
19
19
  init: function init() {
20
20
  return {};
21
21
  },
22
- apply: function apply(_tr, currentPluginState) {
22
+ apply: function apply(tr, currentPluginState) {
23
+ var meta = tr.getMeta(syncedBlockPluginKey);
24
+ if (meta) {
25
+ return meta;
26
+ }
23
27
  return currentPluginState;
24
28
  }
25
29
  },
@@ -7,7 +7,7 @@ Object.defineProperty(exports, "__esModule", {
7
7
  exports.syncedBlockPlugin = void 0;
8
8
  var _react = _interopRequireDefault(require("react"));
9
9
  var _adfSchema = require("@atlaskit/adf-schema");
10
- var _syncBlock = require("@atlaskit/editor-common/sync-block");
10
+ var _editorSyncedBlockProvider = require("@atlaskit/editor-synced-block-provider");
11
11
  var _smartLink = _interopRequireDefault(require("@atlaskit/icon/core/smart-link"));
12
12
  var _actions = require("./pm-plugins/actions");
13
13
  var _main = require("./pm-plugins/main");
@@ -16,7 +16,7 @@ var _floatingToolbar = require("./ui/floating-toolbar");
16
16
  var syncedBlockPlugin = exports.syncedBlockPlugin = function syncedBlockPlugin(_ref) {
17
17
  var config = _ref.config,
18
18
  api = _ref.api;
19
- var syncBlockStore = new _syncBlock.SyncBlockStoreManager(config === null || config === void 0 ? void 0 : config.dataProvider);
19
+ var syncBlockStore = new _editorSyncedBlockProvider.SyncBlockStoreManager(config === null || config === void 0 ? void 0 : config.dataProvider);
20
20
  return {
21
21
  name: 'syncedBlock',
22
22
  nodes: function nodes() {
@@ -10,7 +10,7 @@ var _syncBlock = require("@atlaskit/editor-common/sync-block");
10
10
  var SyncBlockRendererWrapperDataId = 'sync-block-plugin-renderer-wrapper';
11
11
  var SyncBlockRendererWrapperComponent = function SyncBlockRendererWrapperComponent(_ref) {
12
12
  var getSyncedBlockRenderer = _ref.getSyncedBlockRenderer,
13
- docNode = _ref.docNode;
13
+ useFetchDocNode = _ref.useFetchDocNode;
14
14
  return (
15
15
  /*#__PURE__*/
16
16
  // eslint-disable-next-line @atlaskit/ui-styling-standard/enforce-style-prop, @atlaskit/design-system/ensure-design-token-usage
@@ -20,7 +20,7 @@ var SyncBlockRendererWrapperComponent = function SyncBlockRendererWrapperCompone
20
20
  ,
21
21
  className: _syncBlock.SyncBlockSharedCssClassName.renderer
22
22
  }, getSyncedBlockRenderer({
23
- docNode: docNode
23
+ useFetchDocNode: useFetchDocNode
24
24
  }))
25
25
  );
26
26
  };
@@ -2,6 +2,7 @@ import React from 'react';
2
2
  import ReactNodeView from '@atlaskit/editor-common/react-node-view';
3
3
  import { SyncBlockSharedCssClassName } from '@atlaskit/editor-common/sync-block';
4
4
  import { NodeSelection } from '@atlaskit/editor-prosemirror/state';
5
+ import { createSyncBlockNode, useFetchDocNode } from '@atlaskit/editor-synced-block-provider';
5
6
  import { SyncBlockEditorWrapper, SyncBlockEditorWrapperDataId } from '../ui/SyncBlockEditorWrapper';
6
7
  import { SyncBlockRendererWrapper } from '../ui/SyncBlockRendererWrapper';
7
8
  const defaultSyncBlockEditorDocument = {
@@ -42,41 +43,62 @@ class SyncBlock extends ReactNodeView {
42
43
  domRef.classList.add(SyncBlockSharedCssClassName.prefix);
43
44
  return domRef;
44
45
  }
45
- handleContentChanges(_updatedDoc) {
46
+ handleContentChanges(updatedDoc) {
47
+ var _this$options, _this$options$syncedB;
48
+ if (!this.isSource) {
49
+ return;
50
+ }
46
51
  // write data
52
+ const node = createSyncBlockNode(this.node, false);
53
+ (_this$options = this.options) === null || _this$options === void 0 ? void 0 : (_this$options$syncedB = _this$options.syncedBlockProvider) === null || _this$options$syncedB === void 0 ? void 0 : _this$options$syncedB.writeNodesData([node], [{
54
+ content: updatedDoc.toJSON()
55
+ }]);
47
56
  }
48
- setInnerEditorView(_editorView) {
57
+ setInnerEditorView(editorView) {
58
+ var _this$options2, _this$options2$synced;
49
59
  // set inner editor view
60
+ const nodes = [createSyncBlockNode(this.node, false)];
61
+ (_this$options2 = this.options) === null || _this$options2 === void 0 ? void 0 : (_this$options2$synced = _this$options2.syncedBlockProvider) === null || _this$options2$synced === void 0 ? void 0 : _this$options2$synced.fetchNodesData(nodes).then(data => {
62
+ var _data$;
63
+ const tr = editorView.state.tr;
64
+ if (data && (_data$ = data[0]) !== null && _data$ !== void 0 && _data$.content) {
65
+ const newNode = editorView.state.schema.nodeFromJSON(data[0].content);
66
+ editorView.dispatch(tr.replaceWith(0, editorView.state.doc.nodeSize - 2, newNode));
67
+ }
68
+ });
50
69
  }
51
70
  renderEditor() {
52
- var _this$options, _this$options2;
71
+ var _this$options3, _this$options4;
53
72
  const fabricEditorPopupScrollParent = this.view.dom.closest('.fabric-editor-popup-scroll-parent');
54
73
  if (!(fabricEditorPopupScrollParent instanceof HTMLElement)) {
55
74
  return null;
56
75
  }
57
- if (!((_this$options = this.options) !== null && _this$options !== void 0 && _this$options.getSyncedBlockEditor)) {
76
+ if (!((_this$options3 = this.options) !== null && _this$options3 !== void 0 && _this$options3.getSyncedBlockEditor)) {
58
77
  return null;
59
78
  }
60
79
  return /*#__PURE__*/React.createElement(SyncBlockEditorWrapper, {
61
80
  popupsBoundariesElement: fabricEditorPopupScrollParent,
62
81
  popupsMountPoint: fabricEditorPopupScrollParent,
63
82
  defaultDocument: defaultSyncBlockEditorDocument,
64
- handleContentChanges: this.handleContentChanges,
65
- setInnerEditorView: this.setInnerEditorView,
66
- getSyncedBlockEditor: (_this$options2 = this.options) === null || _this$options2 === void 0 ? void 0 : _this$options2.getSyncedBlockEditor
83
+ handleContentChanges: updatedDoc => this.handleContentChanges(updatedDoc),
84
+ setInnerEditorView: editorView => this.setInnerEditorView(editorView),
85
+ getSyncedBlockEditor: (_this$options4 = this.options) === null || _this$options4 === void 0 ? void 0 : _this$options4.getSyncedBlockEditor
67
86
  });
68
87
  }
69
88
  renderRenderer() {
70
- var _this$options3, _this$options4;
71
- if (!((_this$options3 = this.options) !== null && _this$options3 !== void 0 && _this$options3.getSyncedBlockRenderer)) {
89
+ var _this$options5, _this$options7;
90
+ if (!((_this$options5 = this.options) !== null && _this$options5 !== void 0 && _this$options5.getSyncedBlockRenderer)) {
72
91
  return null;
73
92
  }
74
93
 
75
94
  // get document node from data provider
76
- const docNode = defaultSyncBlockRendererDocument;
95
+
77
96
  return /*#__PURE__*/React.createElement(SyncBlockRendererWrapper, {
78
- docNode: docNode,
79
- getSyncedBlockRenderer: (_this$options4 = this.options) === null || _this$options4 === void 0 ? void 0 : _this$options4.getSyncedBlockRenderer
97
+ useFetchDocNode: () => {
98
+ var _this$options6;
99
+ return useFetchDocNode(this.view, this.node, defaultSyncBlockRendererDocument, (_this$options6 = this.options) === null || _this$options6 === void 0 ? void 0 : _this$options6.syncedBlockProvider);
100
+ },
101
+ getSyncedBlockRenderer: (_this$options7 = this.options) === null || _this$options7 === void 0 ? void 0 : _this$options7.getSyncedBlockRenderer
80
102
  });
81
103
  }
82
104
  render() {
@@ -103,6 +125,9 @@ class SyncBlock extends ReactNodeView {
103
125
  }
104
126
  destroy() {
105
127
  var _this$unsubscribe;
128
+ if (this.fetchIntervalId) {
129
+ window.clearInterval(this.fetchIntervalId);
130
+ }
106
131
  (_this$unsubscribe = this.unsubscribe) === null || _this$unsubscribe === void 0 ? void 0 : _this$unsubscribe.call(this);
107
132
  super.destroy();
108
133
  }
@@ -13,7 +13,11 @@ export const createPlugin = (options, pmPluginFactoryParams, syncBlockStore, api
13
13
  init() {
14
14
  return {};
15
15
  },
16
- apply: (_tr, currentPluginState) => {
16
+ apply: (tr, currentPluginState) => {
17
+ const meta = tr.getMeta(syncedBlockPluginKey);
18
+ if (meta) {
19
+ return meta;
20
+ }
17
21
  return currentPluginState;
18
22
  }
19
23
  },
@@ -1,6 +1,6 @@
1
1
  import React from 'react';
2
2
  import { syncBlock } from '@atlaskit/adf-schema';
3
- import { SyncBlockStoreManager } from '@atlaskit/editor-common/sync-block';
3
+ import { SyncBlockStoreManager } from '@atlaskit/editor-synced-block-provider';
4
4
  import SmartLinkIcon from '@atlaskit/icon/core/smart-link';
5
5
  import { createSyncedBlock } from './pm-plugins/actions';
6
6
  import { createPlugin } from './pm-plugins/main';
@@ -3,7 +3,7 @@ import { SyncBlockSharedCssClassName } from '@atlaskit/editor-common/sync-block'
3
3
  const SyncBlockRendererWrapperDataId = 'sync-block-plugin-renderer-wrapper';
4
4
  const SyncBlockRendererWrapperComponent = ({
5
5
  getSyncedBlockRenderer,
6
- docNode
6
+ useFetchDocNode
7
7
  }) => {
8
8
  return (
9
9
  /*#__PURE__*/
@@ -14,7 +14,7 @@ const SyncBlockRendererWrapperComponent = ({
14
14
  ,
15
15
  className: SyncBlockSharedCssClassName.renderer
16
16
  }, getSyncedBlockRenderer({
17
- docNode
17
+ useFetchDocNode
18
18
  }))
19
19
  );
20
20
  };
@@ -11,6 +11,7 @@ import React from 'react';
11
11
  import ReactNodeView from '@atlaskit/editor-common/react-node-view';
12
12
  import { SyncBlockSharedCssClassName } from '@atlaskit/editor-common/sync-block';
13
13
  import { NodeSelection } from '@atlaskit/editor-prosemirror/state';
14
+ import { createSyncBlockNode, useFetchDocNode as _useFetchDocNode } from '@atlaskit/editor-synced-block-provider';
14
15
  import { SyncBlockEditorWrapper, SyncBlockEditorWrapperDataId } from '../ui/SyncBlockEditorWrapper';
15
16
  import { SyncBlockRendererWrapper } from '../ui/SyncBlockRendererWrapper';
16
17
  var defaultSyncBlockEditorDocument = {
@@ -58,47 +59,76 @@ var SyncBlock = /*#__PURE__*/function (_ReactNodeView) {
58
59
  }
59
60
  }, {
60
61
  key: "handleContentChanges",
61
- value: function handleContentChanges(_updatedDoc) {
62
+ value: function handleContentChanges(updatedDoc) {
63
+ var _this$options;
64
+ if (!this.isSource) {
65
+ return;
66
+ }
62
67
  // write data
68
+ var node = createSyncBlockNode(this.node, false);
69
+ (_this$options = this.options) === null || _this$options === void 0 || (_this$options = _this$options.syncedBlockProvider) === null || _this$options === void 0 || _this$options.writeNodesData([node], [{
70
+ content: updatedDoc.toJSON()
71
+ }]);
63
72
  }
64
73
  }, {
65
74
  key: "setInnerEditorView",
66
- value: function setInnerEditorView(_editorView) {
75
+ value: function setInnerEditorView(editorView) {
76
+ var _this$options2;
67
77
  // set inner editor view
78
+ var nodes = [createSyncBlockNode(this.node, false)];
79
+ (_this$options2 = this.options) === null || _this$options2 === void 0 || (_this$options2 = _this$options2.syncedBlockProvider) === null || _this$options2 === void 0 || _this$options2.fetchNodesData(nodes).then(function (data) {
80
+ var _data$;
81
+ var tr = editorView.state.tr;
82
+ if (data && (_data$ = data[0]) !== null && _data$ !== void 0 && _data$.content) {
83
+ var newNode = editorView.state.schema.nodeFromJSON(data[0].content);
84
+ editorView.dispatch(tr.replaceWith(0, editorView.state.doc.nodeSize - 2, newNode));
85
+ }
86
+ });
68
87
  }
69
88
  }, {
70
89
  key: "renderEditor",
71
90
  value: function renderEditor() {
72
- var _this$options, _this$options2;
91
+ var _this$options3,
92
+ _this2 = this,
93
+ _this$options4;
73
94
  var fabricEditorPopupScrollParent = this.view.dom.closest('.fabric-editor-popup-scroll-parent');
74
95
  if (!(fabricEditorPopupScrollParent instanceof HTMLElement)) {
75
96
  return null;
76
97
  }
77
- if (!((_this$options = this.options) !== null && _this$options !== void 0 && _this$options.getSyncedBlockEditor)) {
98
+ if (!((_this$options3 = this.options) !== null && _this$options3 !== void 0 && _this$options3.getSyncedBlockEditor)) {
78
99
  return null;
79
100
  }
80
101
  return /*#__PURE__*/React.createElement(SyncBlockEditorWrapper, {
81
102
  popupsBoundariesElement: fabricEditorPopupScrollParent,
82
103
  popupsMountPoint: fabricEditorPopupScrollParent,
83
104
  defaultDocument: defaultSyncBlockEditorDocument,
84
- handleContentChanges: this.handleContentChanges,
85
- setInnerEditorView: this.setInnerEditorView,
86
- getSyncedBlockEditor: (_this$options2 = this.options) === null || _this$options2 === void 0 ? void 0 : _this$options2.getSyncedBlockEditor
105
+ handleContentChanges: function handleContentChanges(updatedDoc) {
106
+ return _this2.handleContentChanges(updatedDoc);
107
+ },
108
+ setInnerEditorView: function setInnerEditorView(editorView) {
109
+ return _this2.setInnerEditorView(editorView);
110
+ },
111
+ getSyncedBlockEditor: (_this$options4 = this.options) === null || _this$options4 === void 0 ? void 0 : _this$options4.getSyncedBlockEditor
87
112
  });
88
113
  }
89
114
  }, {
90
115
  key: "renderRenderer",
91
116
  value: function renderRenderer() {
92
- var _this$options3, _this$options4;
93
- if (!((_this$options3 = this.options) !== null && _this$options3 !== void 0 && _this$options3.getSyncedBlockRenderer)) {
117
+ var _this$options5,
118
+ _this3 = this,
119
+ _this$options6;
120
+ if (!((_this$options5 = this.options) !== null && _this$options5 !== void 0 && _this$options5.getSyncedBlockRenderer)) {
94
121
  return null;
95
122
  }
96
123
 
97
124
  // get document node from data provider
98
- var docNode = defaultSyncBlockRendererDocument;
125
+
99
126
  return /*#__PURE__*/React.createElement(SyncBlockRendererWrapper, {
100
- docNode: docNode,
101
- getSyncedBlockRenderer: (_this$options4 = this.options) === null || _this$options4 === void 0 ? void 0 : _this$options4.getSyncedBlockRenderer
127
+ useFetchDocNode: function useFetchDocNode() {
128
+ var _this3$options;
129
+ return _useFetchDocNode(_this3.view, _this3.node, defaultSyncBlockRendererDocument, (_this3$options = _this3.options) === null || _this3$options === void 0 ? void 0 : _this3$options.syncedBlockProvider);
130
+ },
131
+ getSyncedBlockRenderer: (_this$options6 = this.options) === null || _this$options6 === void 0 ? void 0 : _this$options6.getSyncedBlockRenderer
102
132
  });
103
133
  }
104
134
  }, {
@@ -133,6 +163,9 @@ var SyncBlock = /*#__PURE__*/function (_ReactNodeView) {
133
163
  key: "destroy",
134
164
  value: function destroy() {
135
165
  var _this$unsubscribe;
166
+ if (this.fetchIntervalId) {
167
+ window.clearInterval(this.fetchIntervalId);
168
+ }
136
169
  (_this$unsubscribe = this.unsubscribe) === null || _this$unsubscribe === void 0 || _this$unsubscribe.call(this);
137
170
  _superPropGet(SyncBlock, "destroy", this, 3)([]);
138
171
  }
@@ -13,7 +13,11 @@ export var createPlugin = function createPlugin(options, pmPluginFactoryParams,
13
13
  init: function init() {
14
14
  return {};
15
15
  },
16
- apply: function apply(_tr, currentPluginState) {
16
+ apply: function apply(tr, currentPluginState) {
17
+ var meta = tr.getMeta(syncedBlockPluginKey);
18
+ if (meta) {
19
+ return meta;
20
+ }
17
21
  return currentPluginState;
18
22
  }
19
23
  },
@@ -1,6 +1,6 @@
1
1
  import React from 'react';
2
2
  import { syncBlock } from '@atlaskit/adf-schema';
3
- import { SyncBlockStoreManager } from '@atlaskit/editor-common/sync-block';
3
+ import { SyncBlockStoreManager } from '@atlaskit/editor-synced-block-provider';
4
4
  import SmartLinkIcon from '@atlaskit/icon/core/smart-link';
5
5
  import { createSyncedBlock } from './pm-plugins/actions';
6
6
  import { createPlugin } from './pm-plugins/main';
@@ -3,7 +3,7 @@ import { SyncBlockSharedCssClassName } from '@atlaskit/editor-common/sync-block'
3
3
  var SyncBlockRendererWrapperDataId = 'sync-block-plugin-renderer-wrapper';
4
4
  var SyncBlockRendererWrapperComponent = function SyncBlockRendererWrapperComponent(_ref) {
5
5
  var getSyncedBlockRenderer = _ref.getSyncedBlockRenderer,
6
- docNode = _ref.docNode;
6
+ useFetchDocNode = _ref.useFetchDocNode;
7
7
  return (
8
8
  /*#__PURE__*/
9
9
  // eslint-disable-next-line @atlaskit/ui-styling-standard/enforce-style-prop, @atlaskit/design-system/ensure-design-token-usage
@@ -13,7 +13,7 @@ var SyncBlockRendererWrapperComponent = function SyncBlockRendererWrapperCompone
13
13
  ,
14
14
  className: SyncBlockSharedCssClassName.renderer
15
15
  }, getSyncedBlockRenderer({
16
- docNode: docNode
16
+ useFetchDocNode: useFetchDocNode
17
17
  }))
18
18
  );
19
19
  };
@@ -20,6 +20,7 @@ export interface SyncBlockNodeViewProps extends ReactComponentProps {
20
20
  declare class SyncBlock extends ReactNodeView<SyncBlockNodeViewProps> {
21
21
  private isSource;
22
22
  private options;
23
+ private fetchIntervalId;
23
24
  constructor(props: SyncBlockNodeViewProps);
24
25
  unsubscribe: (() => void) | undefined;
25
26
  createDomRef(): HTMLElement;
@@ -1,7 +1,7 @@
1
1
  import { SafePlugin } from '@atlaskit/editor-common/safe-plugin';
2
- import type { SyncBlockStoreManager } from '@atlaskit/editor-common/sync-block';
3
2
  import type { ExtractInjectionAPI, PMPluginFactoryParams } from '@atlaskit/editor-common/types';
4
3
  import { PluginKey } from '@atlaskit/editor-prosemirror/state';
4
+ import type { SyncBlockStoreManager } from '@atlaskit/editor-synced-block-provider';
5
5
  import type { SyncedBlockPlugin, SyncedBlockPluginOptions } from '../syncedBlockPluginType';
6
6
  export declare const syncedBlockPluginKey: PluginKey<any>;
7
7
  type SyncedBlockPluginState = {};
@@ -1,5 +1,5 @@
1
- import type { SyncBlockStoreManager } from '@atlaskit/editor-common/sync-block';
2
1
  import type { EditorState, Transaction } from '@atlaskit/editor-prosemirror/state';
2
+ import type { SyncBlockStoreManager } from '@atlaskit/editor-synced-block-provider';
3
3
  import type { SyncBlockAttrs } from '../../syncedBlockPluginType';
4
4
  export declare const trackSyncBlocks: (storeManager: SyncBlockStoreManager, tr: Transaction, state: EditorState) => {
5
5
  removed: SyncBlockAttrs[];
@@ -1,10 +1,10 @@
1
1
  import type { DocNode } from '@atlaskit/adf-schema';
2
2
  import type { EventDispatcher } from '@atlaskit/editor-common/event-dispatcher';
3
- import type { SyncBlockDataProvider } from '@atlaskit/editor-common/sync-block';
4
3
  import type { NextEditorPlugin } from '@atlaskit/editor-common/types';
5
4
  import type { JSONDocNode } from '@atlaskit/editor-json-transformer';
6
5
  import type { SelectionPlugin } from '@atlaskit/editor-plugin-selection';
7
6
  import type { EditorView } from '@atlaskit/editor-prosemirror/dist/types/view';
7
+ import type { SyncBlockDataProvider, SyncedBlockProvider } from '@atlaskit/editor-synced-block-provider';
8
8
  export type SyncedBlockEditorProps = {
9
9
  defaultDocument: JSONDocNode;
10
10
  onChange: (editorView: EditorView, meta: {
@@ -28,12 +28,13 @@ export type SyncedBlockEditorProps = {
28
28
  popupsMountPoint: HTMLElement;
29
29
  };
30
30
  export type SyncedBlockRendererProps = {
31
- docNode: DocNode;
31
+ useFetchDocNode: () => DocNode;
32
32
  };
33
33
  export type SyncedBlockPluginOptions = {
34
34
  dataProvider?: SyncBlockDataProvider;
35
35
  getSyncedBlockEditor?: (props: SyncedBlockEditorProps) => React.JSX.Element;
36
36
  getSyncedBlockRenderer?: (props: SyncedBlockRendererProps) => React.JSX.Element;
37
+ syncedBlockProvider?: SyncedBlockProvider;
37
38
  };
38
39
  export type SyncedBlockPlugin = NextEditorPlugin<'syncedBlock', {
39
40
  dependencies: [SelectionPlugin];
@@ -1,5 +1,5 @@
1
1
  import React from 'react';
2
- import type { SyncBlockStoreManager } from '@atlaskit/editor-common/sync-block';
2
+ import type { SyncBlockStoreManager } from '@atlaskit/editor-synced-block-provider';
3
3
  export declare const ContentComponent: ({ syncBlockStoreManager, }: {
4
4
  syncBlockStoreManager: SyncBlockStoreManager;
5
5
  }) => React.JSX.Element;
@@ -2,8 +2,8 @@ import React from 'react';
2
2
  import type { DocNode } from '@atlaskit/adf-schema';
3
3
  import type { SyncedBlockRendererProps } from '../syncedBlockPluginType';
4
4
  type Props = {
5
- docNode: DocNode;
6
5
  getSyncedBlockRenderer: (props: SyncedBlockRendererProps) => React.JSX.Element;
6
+ useFetchDocNode: () => DocNode;
7
7
  };
8
- export declare const SyncBlockRendererWrapper: React.MemoExoticComponent<({ getSyncedBlockRenderer, docNode }: Props) => React.JSX.Element>;
8
+ export declare const SyncBlockRendererWrapper: React.MemoExoticComponent<({ getSyncedBlockRenderer, useFetchDocNode }: Props) => React.JSX.Element>;
9
9
  export {};
@@ -20,6 +20,7 @@ export interface SyncBlockNodeViewProps extends ReactComponentProps {
20
20
  declare class SyncBlock extends ReactNodeView<SyncBlockNodeViewProps> {
21
21
  private isSource;
22
22
  private options;
23
+ private fetchIntervalId;
23
24
  constructor(props: SyncBlockNodeViewProps);
24
25
  unsubscribe: (() => void) | undefined;
25
26
  createDomRef(): HTMLElement;
@@ -1,7 +1,7 @@
1
1
  import { SafePlugin } from '@atlaskit/editor-common/safe-plugin';
2
- import type { SyncBlockStoreManager } from '@atlaskit/editor-common/sync-block';
3
2
  import type { ExtractInjectionAPI, PMPluginFactoryParams } from '@atlaskit/editor-common/types';
4
3
  import { PluginKey } from '@atlaskit/editor-prosemirror/state';
4
+ import type { SyncBlockStoreManager } from '@atlaskit/editor-synced-block-provider';
5
5
  import type { SyncedBlockPlugin, SyncedBlockPluginOptions } from '../syncedBlockPluginType';
6
6
  export declare const syncedBlockPluginKey: PluginKey<any>;
7
7
  type SyncedBlockPluginState = {};
@@ -1,5 +1,5 @@
1
- import type { SyncBlockStoreManager } from '@atlaskit/editor-common/sync-block';
2
1
  import type { EditorState, Transaction } from '@atlaskit/editor-prosemirror/state';
2
+ import type { SyncBlockStoreManager } from '@atlaskit/editor-synced-block-provider';
3
3
  import type { SyncBlockAttrs } from '../../syncedBlockPluginType';
4
4
  export declare const trackSyncBlocks: (storeManager: SyncBlockStoreManager, tr: Transaction, state: EditorState) => {
5
5
  removed: SyncBlockAttrs[];
@@ -1,10 +1,10 @@
1
1
  import type { DocNode } from '@atlaskit/adf-schema';
2
2
  import type { EventDispatcher } from '@atlaskit/editor-common/event-dispatcher';
3
- import type { SyncBlockDataProvider } from '@atlaskit/editor-common/sync-block';
4
3
  import type { NextEditorPlugin } from '@atlaskit/editor-common/types';
5
4
  import type { JSONDocNode } from '@atlaskit/editor-json-transformer';
6
5
  import type { SelectionPlugin } from '@atlaskit/editor-plugin-selection';
7
6
  import type { EditorView } from '@atlaskit/editor-prosemirror/dist/types/view';
7
+ import type { SyncBlockDataProvider, SyncedBlockProvider } from '@atlaskit/editor-synced-block-provider';
8
8
  export type SyncedBlockEditorProps = {
9
9
  defaultDocument: JSONDocNode;
10
10
  onChange: (editorView: EditorView, meta: {
@@ -28,12 +28,13 @@ export type SyncedBlockEditorProps = {
28
28
  popupsMountPoint: HTMLElement;
29
29
  };
30
30
  export type SyncedBlockRendererProps = {
31
- docNode: DocNode;
31
+ useFetchDocNode: () => DocNode;
32
32
  };
33
33
  export type SyncedBlockPluginOptions = {
34
34
  dataProvider?: SyncBlockDataProvider;
35
35
  getSyncedBlockEditor?: (props: SyncedBlockEditorProps) => React.JSX.Element;
36
36
  getSyncedBlockRenderer?: (props: SyncedBlockRendererProps) => React.JSX.Element;
37
+ syncedBlockProvider?: SyncedBlockProvider;
37
38
  };
38
39
  export type SyncedBlockPlugin = NextEditorPlugin<'syncedBlock', {
39
40
  dependencies: [
@@ -1,5 +1,5 @@
1
1
  import React from 'react';
2
- import type { SyncBlockStoreManager } from '@atlaskit/editor-common/sync-block';
2
+ import type { SyncBlockStoreManager } from '@atlaskit/editor-synced-block-provider';
3
3
  export declare const ContentComponent: ({ syncBlockStoreManager, }: {
4
4
  syncBlockStoreManager: SyncBlockStoreManager;
5
5
  }) => React.JSX.Element;
@@ -2,8 +2,8 @@ import React from 'react';
2
2
  import type { DocNode } from '@atlaskit/adf-schema';
3
3
  import type { SyncedBlockRendererProps } from '../syncedBlockPluginType';
4
4
  type Props = {
5
- docNode: DocNode;
6
5
  getSyncedBlockRenderer: (props: SyncedBlockRendererProps) => React.JSX.Element;
6
+ useFetchDocNode: () => DocNode;
7
7
  };
8
- export declare const SyncBlockRendererWrapper: React.MemoExoticComponent<({ getSyncedBlockRenderer, docNode }: Props) => React.JSX.Element>;
8
+ export declare const SyncBlockRendererWrapper: React.MemoExoticComponent<({ getSyncedBlockRenderer, useFetchDocNode }: Props) => React.JSX.Element>;
9
9
  export {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atlaskit/editor-plugin-synced-block",
3
- "version": "2.2.2",
3
+ "version": "2.3.0",
4
4
  "description": "SyncedBlock plugin for @atlaskit/editor-core",
5
5
  "author": "Atlassian Pty Ltd",
6
6
  "license": "Apache-2.0",
@@ -28,18 +28,19 @@
28
28
  "sideEffects": false,
29
29
  "atlaskit:src": "src/index.ts",
30
30
  "dependencies": {
31
- "@atlaskit/adf-schema": "^51.1.2",
31
+ "@atlaskit/adf-schema": "^51.2.0",
32
32
  "@atlaskit/button": "23.4.9",
33
33
  "@atlaskit/editor-plugin-selection": "^5.0.0",
34
34
  "@atlaskit/editor-prosemirror": "7.0.0",
35
+ "@atlaskit/editor-synced-block-provider": "^0.1.0",
35
36
  "@atlaskit/icon": "28.3.0",
36
- "@atlaskit/modal-dialog": "^14.3.0",
37
+ "@atlaskit/modal-dialog": "^14.4.0",
37
38
  "@babel/runtime": "^7.0.0",
38
39
  "react-intl-next": "npm:react-intl@^5.18.1",
39
40
  "uuid": "^3.1.0"
40
41
  },
41
42
  "peerDependencies": {
42
- "@atlaskit/editor-common": "^109.14.0",
43
+ "@atlaskit/editor-common": "^109.16.0",
43
44
  "react": "^18.2.0"
44
45
  },
45
46
  "devDependencies": {