@atlaskit/editor-plugin-synced-block 2.1.0 → 2.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (59) hide show
  1. package/CHANGELOG.md +19 -0
  2. package/afm-cc/tsconfig.json +9 -0
  3. package/afm-dev-agents/tsconfig.json +9 -0
  4. package/afm-jira/tsconfig.json +9 -0
  5. package/afm-passionfruit/tsconfig.json +9 -0
  6. package/afm-post-office/tsconfig.json +9 -0
  7. package/afm-rovo-extension/tsconfig.json +9 -0
  8. package/afm-townsquare/tsconfig.json +9 -0
  9. package/dist/cjs/nodeviews/syncedBlock.js +118 -75
  10. package/dist/cjs/pm-plugins/actions.js +23 -9
  11. package/dist/cjs/pm-plugins/main.js +34 -8
  12. package/dist/cjs/pm-plugins/utils/track-sync-blocks.js +54 -0
  13. package/dist/cjs/pm-plugins/utils/utils.js +11 -0
  14. package/dist/cjs/syncedBlockPlugin.js +12 -3
  15. package/dist/cjs/ui/ContentComponent.js +55 -0
  16. package/dist/cjs/ui/SyncBlockEditorWrapper.js +38 -0
  17. package/dist/cjs/ui/SyncBlockRendererWrapper.js +26 -0
  18. package/dist/cjs/ui/floating-toolbar.js +58 -3
  19. package/dist/es2019/nodeviews/syncedBlock.js +103 -67
  20. package/dist/es2019/pm-plugins/actions.js +23 -8
  21. package/dist/es2019/pm-plugins/main.js +35 -8
  22. package/dist/es2019/pm-plugins/utils/track-sync-blocks.js +50 -0
  23. package/dist/es2019/pm-plugins/utils/utils.js +7 -0
  24. package/dist/es2019/syncedBlockPlugin.js +10 -3
  25. package/dist/es2019/ui/ContentComponent.js +41 -0
  26. package/dist/es2019/ui/SyncBlockEditorWrapper.js +28 -0
  27. package/dist/es2019/ui/SyncBlockRendererWrapper.js +20 -0
  28. package/dist/es2019/ui/floating-toolbar.js +56 -2
  29. package/dist/esm/nodeviews/syncedBlock.js +116 -72
  30. package/dist/esm/pm-plugins/actions.js +21 -8
  31. package/dist/esm/pm-plugins/main.js +34 -8
  32. package/dist/esm/pm-plugins/utils/track-sync-blocks.js +48 -0
  33. package/dist/esm/pm-plugins/utils/utils.js +5 -0
  34. package/dist/esm/syncedBlockPlugin.js +12 -3
  35. package/dist/esm/ui/ContentComponent.js +46 -0
  36. package/dist/esm/ui/SyncBlockEditorWrapper.js +31 -0
  37. package/dist/esm/ui/SyncBlockRendererWrapper.js +19 -0
  38. package/dist/esm/ui/floating-toolbar.js +57 -3
  39. package/dist/types/nodeviews/syncedBlock.d.ts +29 -15
  40. package/dist/types/pm-plugins/actions.d.ts +3 -1
  41. package/dist/types/pm-plugins/main.d.ts +3 -3
  42. package/dist/types/pm-plugins/utils/track-sync-blocks.d.ts +7 -0
  43. package/dist/types/pm-plugins/utils/utils.d.ts +3 -0
  44. package/dist/types/syncedBlockPluginType.d.ts +8 -2
  45. package/dist/types/ui/ContentComponent.d.ts +5 -0
  46. package/dist/types/ui/SyncBlockEditorWrapper.d.ts +16 -0
  47. package/dist/types/ui/SyncBlockRendererWrapper.d.ts +9 -0
  48. package/dist/types/ui/floating-toolbar.d.ts +6 -2
  49. package/dist/types-ts4.5/nodeviews/syncedBlock.d.ts +29 -15
  50. package/dist/types-ts4.5/pm-plugins/actions.d.ts +3 -1
  51. package/dist/types-ts4.5/pm-plugins/main.d.ts +3 -3
  52. package/dist/types-ts4.5/pm-plugins/utils/track-sync-blocks.d.ts +7 -0
  53. package/dist/types-ts4.5/pm-plugins/utils/utils.d.ts +3 -0
  54. package/dist/types-ts4.5/syncedBlockPluginType.d.ts +10 -2
  55. package/dist/types-ts4.5/ui/ContentComponent.d.ts +5 -0
  56. package/dist/types-ts4.5/ui/SyncBlockEditorWrapper.d.ts +16 -0
  57. package/dist/types-ts4.5/ui/SyncBlockRendererWrapper.d.ts +9 -0
  58. package/dist/types-ts4.5/ui/floating-toolbar.d.ts +6 -2
  59. package/package.json +8 -4
package/CHANGELOG.md CHANGED
@@ -1,5 +1,24 @@
1
1
  # @atlaskit/editor-plugin-synced-block
2
2
 
3
+ ## 2.2.0
4
+
5
+ ### Minor Changes
6
+
7
+ - [`889f0cb60f68d`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/889f0cb60f68d) -
8
+ EDITOR-1561 implement confirmation before deleting a source sync block
9
+
10
+ ### Patch Changes
11
+
12
+ - Updated dependencies
13
+
14
+ ## 2.1.1
15
+
16
+ ### Patch Changes
17
+
18
+ - [`7846d87959f7a`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/7846d87959f7a) -
19
+ Initial implementation of the floating toolbar
20
+ - Updated dependencies
21
+
3
22
  ## 2.1.0
4
23
 
5
24
  ### Minor Changes
@@ -22,9 +22,18 @@
22
22
  "../src/**/stories/**/*"
23
23
  ],
24
24
  "references": [
25
+ {
26
+ "path": "../../../design-system/button/afm-cc/tsconfig.json"
27
+ },
28
+ {
29
+ "path": "../../editor-plugin-selection/afm-cc/tsconfig.json"
30
+ },
25
31
  {
26
32
  "path": "../../../design-system/icon/afm-cc/tsconfig.json"
27
33
  },
34
+ {
35
+ "path": "../../../design-system/modal-dialog/afm-cc/tsconfig.json"
36
+ },
28
37
  {
29
38
  "path": "../../editor-common/afm-cc/tsconfig.json"
30
39
  }
@@ -22,9 +22,18 @@
22
22
  "../src/**/stories/**/*"
23
23
  ],
24
24
  "references": [
25
+ {
26
+ "path": "../../../design-system/button/afm-dev-agents/tsconfig.json"
27
+ },
28
+ {
29
+ "path": "../../editor-plugin-selection/afm-dev-agents/tsconfig.json"
30
+ },
25
31
  {
26
32
  "path": "../../../design-system/icon/afm-dev-agents/tsconfig.json"
27
33
  },
34
+ {
35
+ "path": "../../../design-system/modal-dialog/afm-dev-agents/tsconfig.json"
36
+ },
28
37
  {
29
38
  "path": "../../editor-common/afm-dev-agents/tsconfig.json"
30
39
  }
@@ -22,9 +22,18 @@
22
22
  "../src/**/stories/**/*"
23
23
  ],
24
24
  "references": [
25
+ {
26
+ "path": "../../../design-system/button/afm-jira/tsconfig.json"
27
+ },
28
+ {
29
+ "path": "../../editor-plugin-selection/afm-jira/tsconfig.json"
30
+ },
25
31
  {
26
32
  "path": "../../../design-system/icon/afm-jira/tsconfig.json"
27
33
  },
34
+ {
35
+ "path": "../../../design-system/modal-dialog/afm-jira/tsconfig.json"
36
+ },
28
37
  {
29
38
  "path": "../../editor-common/afm-jira/tsconfig.json"
30
39
  }
@@ -22,9 +22,18 @@
22
22
  "../src/**/stories/**/*"
23
23
  ],
24
24
  "references": [
25
+ {
26
+ "path": "../../../design-system/button/afm-passionfruit/tsconfig.json"
27
+ },
28
+ {
29
+ "path": "../../editor-plugin-selection/afm-passionfruit/tsconfig.json"
30
+ },
25
31
  {
26
32
  "path": "../../../design-system/icon/afm-passionfruit/tsconfig.json"
27
33
  },
34
+ {
35
+ "path": "../../../design-system/modal-dialog/afm-passionfruit/tsconfig.json"
36
+ },
28
37
  {
29
38
  "path": "../../editor-common/afm-passionfruit/tsconfig.json"
30
39
  }
@@ -22,9 +22,18 @@
22
22
  "../src/**/stories/**/*"
23
23
  ],
24
24
  "references": [
25
+ {
26
+ "path": "../../../design-system/button/afm-post-office/tsconfig.json"
27
+ },
28
+ {
29
+ "path": "../../editor-plugin-selection/afm-post-office/tsconfig.json"
30
+ },
25
31
  {
26
32
  "path": "../../../design-system/icon/afm-post-office/tsconfig.json"
27
33
  },
34
+ {
35
+ "path": "../../../design-system/modal-dialog/afm-post-office/tsconfig.json"
36
+ },
28
37
  {
29
38
  "path": "../../editor-common/afm-post-office/tsconfig.json"
30
39
  }
@@ -22,9 +22,18 @@
22
22
  "../src/**/stories/**/*"
23
23
  ],
24
24
  "references": [
25
+ {
26
+ "path": "../../../design-system/button/afm-rovo-extension/tsconfig.json"
27
+ },
28
+ {
29
+ "path": "../../editor-plugin-selection/afm-rovo-extension/tsconfig.json"
30
+ },
25
31
  {
26
32
  "path": "../../../design-system/icon/afm-rovo-extension/tsconfig.json"
27
33
  },
34
+ {
35
+ "path": "../../../design-system/modal-dialog/afm-rovo-extension/tsconfig.json"
36
+ },
28
37
  {
29
38
  "path": "../../editor-common/afm-rovo-extension/tsconfig.json"
30
39
  }
@@ -22,9 +22,18 @@
22
22
  "../src/**/stories/**/*"
23
23
  ],
24
24
  "references": [
25
+ {
26
+ "path": "../../../design-system/button/afm-townsquare/tsconfig.json"
27
+ },
28
+ {
29
+ "path": "../../editor-plugin-selection/afm-townsquare/tsconfig.json"
30
+ },
25
31
  {
26
32
  "path": "../../../design-system/icon/afm-townsquare/tsconfig.json"
27
33
  },
34
+ {
35
+ "path": "../../../design-system/modal-dialog/afm-townsquare/tsconfig.json"
36
+ },
28
37
  {
29
38
  "path": "../../editor-common/afm-townsquare/tsconfig.json"
30
39
  }
@@ -1,108 +1,118 @@
1
1
  "use strict";
2
2
 
3
3
  var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
- var _typeof = require("@babel/runtime/helpers/typeof");
5
4
  Object.defineProperty(exports, "__esModule", {
6
5
  value: true
7
6
  });
8
- exports.syncBlockNodeView = exports.defaultSyncBlockDocument = exports.SyncBlockPluginComponent = void 0;
7
+ exports.syncBlockNodeView = void 0;
9
8
  var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));
10
9
  var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
11
10
  var _possibleConstructorReturn2 = _interopRequireDefault(require("@babel/runtime/helpers/possibleConstructorReturn"));
12
11
  var _getPrototypeOf2 = _interopRequireDefault(require("@babel/runtime/helpers/getPrototypeOf"));
13
12
  var _get2 = _interopRequireDefault(require("@babel/runtime/helpers/get"));
14
13
  var _inherits2 = _interopRequireDefault(require("@babel/runtime/helpers/inherits"));
15
- var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
16
- var _react = _interopRequireWildcard(require("react"));
14
+ var _react = _interopRequireDefault(require("react"));
17
15
  var _reactNodeView = _interopRequireDefault(require("@atlaskit/editor-common/react-node-view"));
18
- function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function _interopRequireWildcard(e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, default: e }; if (null === e || "object" != _typeof(e) && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (var _t in e) "default" !== _t && {}.hasOwnProperty.call(e, _t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, _t)) && (i.get || i.set) ? o(f, _t, i) : f[_t] = e[_t]); return f; })(e, t); }
16
+ var _state = require("@atlaskit/editor-prosemirror/state");
17
+ var _SyncBlockEditorWrapper = require("../ui/SyncBlockEditorWrapper");
18
+ var _SyncBlockRendererWrapper = require("../ui/SyncBlockRendererWrapper");
19
19
  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)); }
20
20
  function _isNativeReflectConstruct() { try { var t = !Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); } catch (t) {} return (_isNativeReflectConstruct = function _isNativeReflectConstruct() { return !!t; })(); }
21
- function _superPropGet(t, o, e, r) { var p = (0, _get2.default)((0, _getPrototypeOf2.default)(1 & r ? t.prototype : t), o, e); return 2 & r && "function" == typeof p ? function (t) { return p.apply(e, t); } : p; } /* eslint-disable @atlaskit/ui-styling-standard/enforce-style-prop */
22
- var defaultSyncBlockDocument = exports.defaultSyncBlockDocument = {
21
+ function _superPropGet(t, o, e, r) { var p = (0, _get2.default)((0, _getPrototypeOf2.default)(1 & r ? t.prototype : t), o, e); return 2 & r && "function" == typeof p ? function (t) { return p.apply(e, t); } : p; }
22
+ var defaultSyncBlockEditorDocument = {
23
23
  version: 1,
24
24
  type: 'doc',
25
25
  content: [{
26
26
  type: 'paragraph',
27
27
  content: [{
28
28
  type: 'text',
29
- text: 'This is a synced block. Edit the source to update the content.'
29
+ text: 'This is a source sync block. Edit me to update the content.'
30
30
  }]
31
31
  }]
32
32
  };
33
- var SyncBlockEditorWrapperDataId = 'sync-block-plugin-editor-wrapper';
34
- var SyncBlockPluginComponent = exports.SyncBlockPluginComponent = function SyncBlockPluginComponent(_ref) {
35
- var config = _ref.config,
36
- dom = _ref.dom;
37
- var innerEditorView = (0, _react.useRef)(null);
38
-
39
- /* Tmp solution to demonstrate the synced block renderer */
40
- var _useState = (0, _react.useState)(defaultSyncBlockDocument),
41
- _useState2 = (0, _slicedToArray2.default)(_useState, 2),
42
- rendererDocument = _useState2[0],
43
- setRendererDocument = _useState2[1];
44
- var onChange = function onChange(editorView, _meta) {
45
- var content = editorView.state.doc.toJSON().content;
46
- var rendererDocument = {
47
- version: 1,
48
- type: 'doc',
49
- content: content
50
- };
51
- setRendererDocument(rendererDocument);
52
- };
53
- var onEditorReady = function onEditorReady(_ref2) {
54
- var editorView = _ref2.editorView;
55
- innerEditorView.current = editorView || null;
56
- };
57
- var boundariesElement = (0, _react.useMemo)(function () {
58
- // eslint-disable-next-line @atlaskit/editor/no-as-casting
59
- return dom.closest('.fabric-editor-popup-scroll-parent');
60
- }, [dom]);
61
- if (!boundariesElement || !(boundariesElement instanceof HTMLElement)) {
62
- return null;
63
- }
64
- if (!(config !== null && config !== void 0 && config.getSyncedBlockEditor) || !(config !== null && config !== void 0 && config.getSyncedBlockRenderer)) {
65
- return null;
66
- }
67
- return /*#__PURE__*/_react.default.createElement("div", {
68
- "data-testid": SyncBlockEditorWrapperDataId
69
- }, config.getSyncedBlockEditor({
70
- boundariesElement: boundariesElement,
71
- defaultDocument: defaultSyncBlockDocument,
72
- mountPoint: dom,
73
- onChange: onChange,
74
- onEditorReady: onEditorReady
75
- }), /*#__PURE__*/_react.default.createElement("div", {
76
- style: {
77
- width: '100%',
78
- height: '1px',
79
- // eslint-disable-next-line @atlaskit/design-system/ensure-design-token-usage
80
- backgroundColor: 'purple'
81
- }
82
- }), config.getSyncedBlockRenderer({
83
- docNode: rendererDocument
84
- }));
33
+ var defaultSyncBlockRendererDocument = {
34
+ version: 1,
35
+ type: 'doc',
36
+ content: [{
37
+ type: 'paragraph',
38
+ content: [{
39
+ type: 'text',
40
+ text: 'This is a reference sync block. Stay tuned for updates...'
41
+ }]
42
+ }]
85
43
  };
86
44
  var SyncBlock = /*#__PURE__*/function (_ReactNodeView) {
87
- function SyncBlock() {
45
+ function SyncBlock(props) {
46
+ var _this;
88
47
  (0, _classCallCheck2.default)(this, SyncBlock);
89
- return _callSuper(this, SyncBlock, arguments);
48
+ _this = _callSuper(this, SyncBlock, [props.node, props.view, props.getPos, props.portalProviderAPI, props.eventDispatcher, props]);
49
+ var _props$node$attrs = props.node.attrs,
50
+ resourceId = _props$node$attrs.resourceId,
51
+ localId = _props$node$attrs.localId;
52
+ // Temporary solution to identify the source
53
+ _this.isSource = resourceId === localId;
54
+ _this.options = props.options;
55
+ return _this;
90
56
  }
91
57
  (0, _inherits2.default)(SyncBlock, _ReactNodeView);
92
58
  return (0, _createClass2.default)(SyncBlock, [{
93
59
  key: "createDomRef",
94
60
  value: function createDomRef() {
95
61
  var domRef = document.createElement('div');
96
- domRef.setAttribute('style', 'border: purple solid 1px;');
97
62
  return domRef;
98
63
  }
64
+ }, {
65
+ key: "handleContentChanges",
66
+ value: function handleContentChanges(_updatedDoc) {
67
+ // write data
68
+ }
69
+ }, {
70
+ key: "setInnerEditorView",
71
+ value: function setInnerEditorView(_editorView) {
72
+ // set inner editor view
73
+ }
74
+ }, {
75
+ key: "renderEditor",
76
+ value: function renderEditor() {
77
+ var _this$options, _this$options2;
78
+ var popupsBoundariesElement = this.dom.closest('.fabric-editor-popup-scroll-parent');
79
+ if (!(popupsBoundariesElement instanceof HTMLElement)) {
80
+ return null;
81
+ }
82
+ if (!((_this$options = this.options) !== null && _this$options !== void 0 && _this$options.getSyncedBlockEditor)) {
83
+ return null;
84
+ }
85
+ return /*#__PURE__*/_react.default.createElement(_SyncBlockEditorWrapper.SyncBlockEditorWrapper, {
86
+ popupsBoundariesElement: popupsBoundariesElement,
87
+ popupsMountPoint: this.dom,
88
+ defaultDocument: defaultSyncBlockEditorDocument,
89
+ handleContentChanges: this.handleContentChanges,
90
+ setInnerEditorView: this.setInnerEditorView,
91
+ getSyncedBlockEditor: (_this$options2 = this.options) === null || _this$options2 === void 0 ? void 0 : _this$options2.getSyncedBlockEditor
92
+ });
93
+ }
94
+ }, {
95
+ key: "renderRenderer",
96
+ value: function renderRenderer() {
97
+ var _this$options3, _this$options4;
98
+ if (!((_this$options3 = this.options) !== null && _this$options3 !== void 0 && _this$options3.getSyncedBlockRenderer)) {
99
+ return null;
100
+ }
101
+
102
+ // get document node from data provider
103
+ var docNode = defaultSyncBlockRendererDocument;
104
+ return /*#__PURE__*/_react.default.createElement(_SyncBlockRendererWrapper.SyncBlockRendererWrapper, {
105
+ docNode: docNode,
106
+ getSyncedBlockRenderer: (_this$options4 = this.options) === null || _this$options4 === void 0 ? void 0 : _this$options4.getSyncedBlockRenderer
107
+ });
108
+ }
99
109
  }, {
100
110
  key: "render",
101
111
  value: function render() {
102
- return /*#__PURE__*/_react.default.createElement(SyncBlockPluginComponent, {
103
- config: this.reactComponentProps.config,
104
- dom: this.dom
105
- });
112
+ if (this.isSource) {
113
+ return this.renderEditor();
114
+ }
115
+ return this.renderRenderer();
106
116
  }
107
117
  }, {
108
118
  key: "stopEvent",
@@ -112,7 +122,17 @@ var SyncBlock = /*#__PURE__*/function (_ReactNodeView) {
112
122
  if (!target) {
113
123
  return false;
114
124
  }
115
- return ((_target$closest = target.closest) === null || _target$closest === void 0 ? void 0 : _target$closest.call(target, "[data-testid=\"".concat(SyncBlockEditorWrapperDataId, "\"]"))) != null;
125
+ var isInNestedEditor = ((_target$closest = target.closest) === null || _target$closest === void 0 ? void 0 : _target$closest.call(target, "[data-testid=\"".concat(_SyncBlockEditorWrapper.SyncBlockEditorWrapperDataId, "\"]"))) != null;
126
+ if (isInNestedEditor) {
127
+ this.selectNode();
128
+ return true;
129
+ }
130
+ return false;
131
+ }
132
+ }, {
133
+ key: "selectNode",
134
+ value: function selectNode() {
135
+ this.selectSyncBlockNode(undefined);
116
136
  }
117
137
  }, {
118
138
  key: "destroy",
@@ -121,17 +141,40 @@ var SyncBlock = /*#__PURE__*/function (_ReactNodeView) {
121
141
  (_this$unsubscribe = this.unsubscribe) === null || _this$unsubscribe === void 0 || _this$unsubscribe.call(this);
122
142
  _superPropGet(SyncBlock, "destroy", this, 3)([]);
123
143
  }
144
+ }, {
145
+ key: "selectSyncBlockNode",
146
+ value: function selectSyncBlockNode(relativeSelectionPos) {
147
+ var _this$reactComponentP;
148
+ var getPos = typeof this.getPos === 'function' ? this.getPos() : 0;
149
+ var selectionAPI = (_this$reactComponentP = this.reactComponentProps.api) === null || _this$reactComponentP === void 0 || (_this$reactComponentP = _this$reactComponentP.selection) === null || _this$reactComponentP === void 0 ? void 0 : _this$reactComponentP.actions;
150
+ if (!selectionAPI) {
151
+ return;
152
+ }
153
+ var tr = selectionAPI.selectNearNode({
154
+ selectionRelativeToNode: relativeSelectionPos,
155
+ selection: _state.NodeSelection.create(this.view.state.doc, getPos !== null && getPos !== void 0 ? getPos : 0)
156
+ })(this.view.state);
157
+ if (tr) {
158
+ this.view.dispatch(tr);
159
+ }
160
+ }
124
161
  }]);
125
162
  }(_reactNodeView.default);
126
- var syncBlockNodeView = exports.syncBlockNodeView = function syncBlockNodeView(_ref3) {
127
- var config = _ref3.config,
128
- pmPluginFactoryParams = _ref3.pmPluginFactoryParams;
163
+ var syncBlockNodeView = exports.syncBlockNodeView = function syncBlockNodeView(_ref) {
164
+ var options = _ref.options,
165
+ pmPluginFactoryParams = _ref.pmPluginFactoryParams,
166
+ api = _ref.api;
129
167
  return function (node, view, getPos) {
130
168
  var portalProviderAPI = pmPluginFactoryParams.portalProviderAPI,
131
169
  eventDispatcher = pmPluginFactoryParams.eventDispatcher;
132
- var reactComponentProps = {
133
- config: config
134
- };
135
- return new SyncBlock(node, view, getPos, portalProviderAPI, eventDispatcher, reactComponentProps, undefined).init();
170
+ return new SyncBlock({
171
+ api: api,
172
+ options: options,
173
+ node: node,
174
+ view: view,
175
+ getPos: getPos,
176
+ portalProviderAPI: portalProviderAPI,
177
+ eventDispatcher: eventDispatcher
178
+ }).init();
136
179
  };
137
180
  };
@@ -1,25 +1,39 @@
1
1
  "use strict";
2
2
 
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
3
4
  Object.defineProperty(exports, "__esModule", {
4
5
  value: true
5
6
  });
6
- exports.createSyncedBlock = void 0;
7
+ exports.createSyncedBlock = exports.copySyncedBlockReferenceToClipboard = void 0;
8
+ var _uuid = _interopRequireDefault(require("uuid"));
9
+ var _copyButton = require("@atlaskit/editor-common/copy-button");
10
+ var _state = require("@atlaskit/editor-prosemirror/state");
7
11
  var _utils = require("@atlaskit/editor-prosemirror/utils");
8
- var getRandomId = function getRandomId() {
9
- if (!globalThis.crypto || typeof globalThis.crypto.randomUUID !== 'function') {
10
- return new Date().toISOString();
11
- }
12
- return globalThis.crypto.randomUUID();
13
- };
14
12
  var createSyncedBlock = exports.createSyncedBlock = function createSyncedBlock(state) {
13
+ var id = (0, _uuid.default)();
15
14
  var tr = state.tr;
16
15
  // const { breakout } = state.schema.marks;
17
16
  var node = state.schema.nodes.syncBlock.createChecked({
18
- resourceId: getRandomId(),
19
- localId: getRandomId()
17
+ resourceId: id,
18
+ localId: id
20
19
  }, null
21
20
  // [breakout.create({ mode: 'wide' })],
22
21
  );
23
22
  (0, _utils.safeInsert)(node)(tr);
24
23
  return tr;
24
+ };
25
+ var copySyncedBlockReferenceToClipboard = exports.copySyncedBlockReferenceToClipboard = function copySyncedBlockReferenceToClipboard(state, _dispatch, _view) {
26
+ var schema = state.schema,
27
+ selection = state.selection;
28
+ if (selection instanceof _state.NodeSelection) {
29
+ var nodeType = selection.node.type;
30
+ var domNode = (0, _copyButton.toDOM)(selection.node, schema);
31
+ // clear local-id
32
+ if (domNode instanceof HTMLElement) {
33
+ domNode.setAttribute('data-local-id', '');
34
+ }
35
+ (0, _copyButton.copyDomNode)(domNode, nodeType, selection);
36
+ return true;
37
+ }
38
+ return false;
25
39
  };
@@ -7,32 +7,58 @@ exports.syncedBlockPluginKey = exports.createPlugin = void 0;
7
7
  var _safePlugin = require("@atlaskit/editor-common/safe-plugin");
8
8
  var _state = require("@atlaskit/editor-prosemirror/state");
9
9
  var _lazySyncedBlock = require("../nodeviews/lazySyncedBlock");
10
+ var _trackSyncBlocks2 = require("./utils/track-sync-blocks");
10
11
  var syncedBlockPluginKey = exports.syncedBlockPluginKey = new _state.PluginKey('syncedBlockPlugin');
11
12
 
12
13
  // eslint-disable-next-line @typescript-eslint/no-empty-object-type
13
14
 
14
- var createPlugin = exports.createPlugin = function createPlugin(config, pmPluginFactoryParams, _syncBlockStore) {
15
+ var createPlugin = exports.createPlugin = function createPlugin(options, pmPluginFactoryParams, syncBlockStore, api) {
15
16
  return new _safePlugin.SafePlugin({
16
17
  key: syncedBlockPluginKey,
17
18
  state: {
18
19
  init: function init() {
19
20
  return {};
20
21
  },
21
- apply: function apply(tr, currentPluginState) {
22
- var meta = tr.getMeta(syncedBlockPluginKey);
23
- if (meta) {
24
- return meta;
25
- }
22
+ apply: function apply(_tr, currentPluginState) {
26
23
  return currentPluginState;
27
24
  }
28
25
  },
29
26
  props: {
30
27
  nodeViews: {
31
28
  syncBlock: (0, _lazySyncedBlock.lazySyncBlockView)({
32
- config: config,
33
- pmPluginFactoryParams: pmPluginFactoryParams
29
+ options: options,
30
+ pmPluginFactoryParams: pmPluginFactoryParams,
31
+ api: api
34
32
  })
35
33
  }
34
+ },
35
+ view: function view(editorView) {
36
+ syncBlockStore.setEditorView(editorView);
37
+ return {
38
+ destroy: function destroy() {
39
+ syncBlockStore.setEditorView(undefined);
40
+ }
41
+ };
42
+ },
43
+ filterTransaction: function filterTransaction(tr, state) {
44
+ // Ignore transactions that don't change the document
45
+ // or are from remote (collab) or already confirmed sync block deletion
46
+ // We only care about local changes that change the document
47
+ // and are not yet confirmed for sync block deletion
48
+ if (!tr.docChanged || !(syncBlockStore !== null && syncBlockStore !== void 0 && syncBlockStore.requireConfirmationBeforeDelete()) || Boolean(tr.getMeta('isRemote')) || Boolean(tr.getMeta('isConfirmedSyncBlockDeletion'))) {
49
+ return true;
50
+ }
51
+ var _trackSyncBlocks = (0, _trackSyncBlocks2.trackSyncBlocks)(syncBlockStore, tr, state),
52
+ removed = _trackSyncBlocks.removed;
53
+ if (removed.length > 0) {
54
+ // If there are source sync blocks being removed, and we need to confirm with user before deleting,
55
+ // we block the transaction here, and wait for user confirmation to proceed with deletion.
56
+ // See editor-common/src/sync-block/sync-block-store-manager.ts for how we handle user confirmation and
57
+ // proceed with deletion.
58
+ syncBlockStore.deleteSyncBlocksWithConfirmation(tr, removed);
59
+ return false;
60
+ }
61
+ return true;
36
62
  }
37
63
  });
38
64
  };
@@ -0,0 +1,54 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.trackSyncBlocks = void 0;
7
+ var _transform = require("@atlaskit/editor-prosemirror/transform");
8
+ var trackSyncBlocks = exports.trackSyncBlocks = function trackSyncBlocks(storeManager, tr, state) {
9
+ var sourceSyncBlockRemoved = {};
10
+ var sourceSyncBlockAdded = {};
11
+ tr.steps.map(function (step) {
12
+ if (step instanceof _transform.ReplaceStep || step instanceof _transform.ReplaceAroundStep) {
13
+ var from = step.from,
14
+ to = step.to;
15
+ // replaced a range, check for deleted syncBlock
16
+ if (from !== to) {
17
+ state.doc.nodesBetween(step.from, step.to, function (node) {
18
+ if (storeManager.isSourceBlock(node)) {
19
+ if (sourceSyncBlockAdded[node.attrs.localId]) {
20
+ // If a source block added and then removed in the same transaction,
21
+ // we treat it as no-op.
22
+ delete sourceSyncBlockAdded[node.attrs.localId];
23
+ } else {
24
+ sourceSyncBlockRemoved[node.attrs.localId] = node.attrs;
25
+ }
26
+ }
27
+ // we don't need to go deeper
28
+ return false;
29
+ });
30
+ }
31
+
32
+ // replaced content, check for inserted syncBlock
33
+ if (step.slice.content.size > 0) {
34
+ step.slice.content.nodesBetween(0, step.slice.content.size, function (node) {
35
+ if (storeManager.isSourceBlock(node)) {
36
+ if (sourceSyncBlockRemoved[node.attrs.localId]) {
37
+ // If a source block is removed and added back in the same transaction,
38
+ // we treat it as no-op.
39
+ delete sourceSyncBlockRemoved[node.attrs.localId];
40
+ } else {
41
+ sourceSyncBlockAdded[node.attrs.localId] = node.attrs;
42
+ }
43
+ }
44
+ // we don't need to go deeper
45
+ return false;
46
+ });
47
+ }
48
+ }
49
+ });
50
+ return {
51
+ removed: Object.values(sourceSyncBlockRemoved),
52
+ added: Object.values(sourceSyncBlockAdded)
53
+ };
54
+ };
@@ -0,0 +1,11 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.findSyncBlock = void 0;
7
+ var _utils = require("@atlaskit/editor-prosemirror/utils");
8
+ var findSyncBlock = exports.findSyncBlock = function findSyncBlock(state, selection) {
9
+ var syncBlock = state.schema.nodes.syncBlock;
10
+ return (0, _utils.findSelectedNodeOfType)(syncBlock)(selection || state.selection) || (0, _utils.findParentNodeOfType)(syncBlock)(selection || state.selection);
11
+ };
@@ -11,9 +11,11 @@ var _syncBlock = require("@atlaskit/editor-common/sync-block");
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");
14
+ var _ContentComponent = require("./ui/ContentComponent");
14
15
  var _floatingToolbar = require("./ui/floating-toolbar");
15
16
  var syncedBlockPlugin = exports.syncedBlockPlugin = function syncedBlockPlugin(_ref) {
16
- var config = _ref.config;
17
+ var config = _ref.config,
18
+ api = _ref.api;
17
19
  var syncBlockStore = new _syncBlock.SyncBlockStoreManager(config === null || config === void 0 ? void 0 : config.dataProvider);
18
20
  return {
19
21
  name: 'syncedBlock',
@@ -27,7 +29,7 @@ var syncedBlockPlugin = exports.syncedBlockPlugin = function syncedBlockPlugin(_
27
29
  return [{
28
30
  name: 'syncedBlockPlugin',
29
31
  plugin: function plugin(params) {
30
- return (0, _main.createPlugin)(config, params, syncBlockStore);
32
+ return (0, _main.createPlugin)(config, params, syncBlockStore, api);
31
33
  }
32
34
  }];
33
35
  },
@@ -50,7 +52,14 @@ var syncedBlockPlugin = exports.syncedBlockPlugin = function syncedBlockPlugin(_
50
52
  }
51
53
  }];
52
54
  },
53
- floatingToolbar: (0, _floatingToolbar.getToolbarConfig)()
55
+ floatingToolbar: function floatingToolbar(state, intl, providerFactory) {
56
+ return (0, _floatingToolbar.getToolbarConfig)(state, intl, config, providerFactory);
57
+ }
58
+ },
59
+ contentComponent: function contentComponent() {
60
+ return /*#__PURE__*/_react.default.createElement(_ContentComponent.ContentComponent, {
61
+ syncBlockStoreManager: syncBlockStore
62
+ });
54
63
  }
55
64
  };
56
65
  };