@atlaskit/editor-plugin-synced-block 3.0.2 → 3.0.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,13 @@
1
1
  # @atlaskit/editor-plugin-synced-block
2
2
 
3
+ ## 3.0.3
4
+
5
+ ### Patch Changes
6
+
7
+ - [`dd19fd49edc58`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/dd19fd49edc58) -
8
+ Added sync block quick insert
9
+ - Updated dependencies
10
+
3
11
  ## 3.0.2
4
12
 
5
13
  ### Patch Changes
@@ -48,12 +48,8 @@ var SyncBlock = /*#__PURE__*/function (_ReactNodeView) {
48
48
  var _this;
49
49
  (0, _classCallCheck2.default)(this, SyncBlock);
50
50
  _this = _callSuper(this, SyncBlock, [props.node, props.view, props.getPos, props.portalProviderAPI, props.eventDispatcher, props]);
51
- var _props$node$attrs = props.node.attrs,
52
- resourceId = _props$node$attrs.resourceId,
53
- localId = _props$node$attrs.localId;
54
- // Temporary solution to identify the source
55
- _this.isSource = resourceId === localId;
56
51
  _this.options = props.options;
52
+ _this.syncBlockStore = props.syncBlockStore;
57
53
  return _this;
58
54
  }
59
55
  (0, _inherits2.default)(SyncBlock, _ReactNodeView);
@@ -64,6 +60,11 @@ var SyncBlock = /*#__PURE__*/function (_ReactNodeView) {
64
60
  domRef.classList.add(_syncBlock.SyncBlockSharedCssClassName.prefix);
65
61
  return domRef;
66
62
  }
63
+ }, {
64
+ key: "isSource",
65
+ value: function isSource() {
66
+ return this.syncBlockStore.isSourceBlock(this.node);
67
+ }
67
68
  }, {
68
69
  key: "handleContentChanges",
69
70
  value: function handleContentChanges(updatedDoc) {
@@ -72,7 +73,7 @@ var SyncBlock = /*#__PURE__*/function (_ReactNodeView) {
72
73
  return;
73
74
  }
74
75
  // write data
75
- var node = (0, _editorSyncedBlockProvider.createSyncBlockNode)(this.node, false);
76
+ var node = (0, _editorSyncedBlockProvider.convertSyncBlockPMNodeToSyncBlockData)(this.node, false);
76
77
  (_this$options = this.options) === null || _this$options === void 0 || (_this$options = _this$options.syncedBlockProvider) === null || _this$options === void 0 || _this$options.writeNodesData([node], [{
77
78
  content: updatedDoc.toJSON()
78
79
  }]);
@@ -82,7 +83,7 @@ var SyncBlock = /*#__PURE__*/function (_ReactNodeView) {
82
83
  value: function setInnerEditorView(editorView) {
83
84
  var _this$options2;
84
85
  // set inner editor view
85
- var nodes = [(0, _editorSyncedBlockProvider.createSyncBlockNode)(this.node, false)];
86
+ var nodes = [(0, _editorSyncedBlockProvider.convertSyncBlockPMNodeToSyncBlockData)(this.node, false)];
86
87
  (_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
88
  var _data$;
88
89
  var tr = editorView.state.tr;
@@ -141,7 +142,7 @@ var SyncBlock = /*#__PURE__*/function (_ReactNodeView) {
141
142
  }, {
142
143
  key: "render",
143
144
  value: function render() {
144
- if (this.isSource) {
145
+ if (this.isSource()) {
145
146
  return this.renderEditor();
146
147
  }
147
148
  return this.renderRenderer();
@@ -198,7 +199,8 @@ var SyncBlock = /*#__PURE__*/function (_ReactNodeView) {
198
199
  var syncBlockNodeView = exports.syncBlockNodeView = function syncBlockNodeView(_ref) {
199
200
  var options = _ref.options,
200
201
  pmPluginFactoryParams = _ref.pmPluginFactoryParams,
201
- api = _ref.api;
202
+ api = _ref.api,
203
+ syncBlockStore = _ref.syncBlockStore;
202
204
  return function (node, view, getPos) {
203
205
  var portalProviderAPI = pmPluginFactoryParams.portalProviderAPI,
204
206
  eventDispatcher = pmPluginFactoryParams.eventDispatcher;
@@ -209,7 +211,8 @@ var syncBlockNodeView = exports.syncBlockNodeView = function syncBlockNodeView(_
209
211
  view: view,
210
212
  getPos: getPos,
211
213
  portalProviderAPI: portalProviderAPI,
212
- eventDispatcher: eventDispatcher
214
+ eventDispatcher: eventDispatcher,
215
+ syncBlockStore: syncBlockStore
213
216
  }).init();
214
217
  };
215
218
  };
@@ -1,18 +1,44 @@
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
7
  exports.removeSyncedBlock = exports.editSyncedBlockSource = exports.createSyncedBlock = exports.copySyncedBlockReferenceToClipboard = void 0;
8
+ var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
7
9
  var _analytics = require("@atlaskit/editor-common/analytics");
8
- var _utils = require("@atlaskit/editor-prosemirror/utils");
10
+ var _insert = require("@atlaskit/editor-common/insert");
11
+ var _utils = require("@atlaskit/editor-common/utils");
9
12
  var _editorSyncedBlockProvider = require("@atlaskit/editor-synced-block-provider");
10
13
  var _utils2 = require("./utils/utils");
11
- var createSyncedBlock = exports.createSyncedBlock = function createSyncedBlock(state) {
12
- var tr = state.tr,
13
- syncBlock = state.schema.nodes.syncBlock;
14
- var node = (0, _editorSyncedBlockProvider.createSyncBlockPMNode)(syncBlock);
15
- (0, _utils.safeInsert)(node)(tr);
14
+ function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
15
+ function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { (0, _defineProperty2.default)(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
16
+ var createSyncedBlock = exports.createSyncedBlock = function createSyncedBlock(typeAheadInsert, state, syncBlockStore) {
17
+ var syncBlock = state.schema.nodes.syncBlock;
18
+ var tr;
19
+ var syncBlockNode = syncBlockStore.createSyncBlockNode();
20
+
21
+ // If the selection is empty, we want to insert the panel on a new line
22
+ if (state.selection.empty) {
23
+ var node = syncBlock.createAndFill(_objectSpread({}, syncBlockNode.attrs));
24
+ if (!node) {
25
+ return false;
26
+ }
27
+ if (typeAheadInsert !== undefined) {
28
+ // If the type-ahead insert is provided, we should use that to insert the node
29
+ tr = typeAheadInsert(node);
30
+ } else {
31
+ var _insertSelectedItem;
32
+ // Otherwise we can use insertSelectedItem to insert the node
33
+ tr = (_insertSelectedItem = (0, _insert.insertSelectedItem)(node)(state, state.tr, state.selection.head)) === null || _insertSelectedItem === void 0 ? void 0 : _insertSelectedItem.scrollIntoView();
34
+ }
35
+ } else {
36
+ tr = (0, _utils.createWrapSelectionTransaction)({
37
+ state: state,
38
+ type: syncBlock,
39
+ nodeAttributes: _objectSpread({}, syncBlockNode.attrs)
40
+ });
41
+ }
16
42
  return tr;
17
43
  };
18
44
  var copySyncedBlockReferenceToClipboard = exports.copySyncedBlockReferenceToClipboard = function copySyncedBlockReferenceToClipboard(api) {
@@ -32,7 +32,8 @@ var createPlugin = exports.createPlugin = function createPlugin(options, pmPlugi
32
32
  syncBlock: (0, _lazySyncedBlock.lazySyncBlockView)({
33
33
  options: options,
34
34
  pmPluginFactoryParams: pmPluginFactoryParams,
35
- api: api
35
+ api: api,
36
+ syncBlockStore: syncBlockStore
36
37
  })
37
38
  }
38
39
  },
@@ -7,8 +7,9 @@ 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 _messages = require("@atlaskit/editor-common/messages");
11
+ var _quickInsert = require("@atlaskit/editor-common/quick-insert");
10
12
  var _editorSyncedBlockProvider = require("@atlaskit/editor-synced-block-provider");
11
- var _smartLink = _interopRequireDefault(require("@atlaskit/icon/core/smart-link"));
12
13
  var _actions = require("./pm-plugins/actions");
13
14
  var _main = require("./pm-plugins/main");
14
15
  var _ContentComponent = require("./ui/ContentComponent");
@@ -34,26 +35,27 @@ var syncedBlockPlugin = exports.syncedBlockPlugin = function syncedBlockPlugin(_
34
35
  }];
35
36
  },
36
37
  pluginsOptions: {
37
- quickInsert: function quickInsert() {
38
+ quickInsert: function quickInsert(_ref2) {
39
+ var formatMessage = _ref2.formatMessage;
38
40
  return [{
39
41
  id: 'syncBlock',
40
- title: 'Synced Block',
41
- description: 'Create a synced block',
42
+ title: formatMessage(_messages.blockTypeMessages.syncedBlock),
43
+ description: formatMessage(_messages.blockTypeMessages.syncedBlockDescription),
42
44
  priority: 800,
43
- keywords: ['synced', 'block', 'synced-block', 'sync', 'sync-block'],
45
+ keywords: ['synced', 'block', 'synced-block', 'sync', 'sync-block', 'auto', 'update', 'excerpt', 'connect'],
44
46
  keyshortcut: '',
45
47
  icon: function icon() {
46
- return /*#__PURE__*/_react.default.createElement(_smartLink.default, {
47
- label: "Synced Block"
48
+ return /*#__PURE__*/_react.default.createElement(_quickInsert.IconSyncBlock, {
49
+ label: formatMessage(_messages.blockTypeMessages.syncedBlock)
48
50
  });
49
51
  },
50
- action: function action(_insert, state) {
51
- return (0, _actions.createSyncedBlock)(state);
52
+ action: function action(insert, state) {
53
+ return (0, _actions.createSyncedBlock)(insert, state, syncBlockStore);
52
54
  }
53
55
  }];
54
56
  },
55
57
  floatingToolbar: function floatingToolbar(state, intl, providerFactory) {
56
- return (0, _floatingToolbar.getToolbarConfig)(state, intl, config, providerFactory, api);
58
+ return (0, _floatingToolbar.getToolbarConfig)(state, intl, config, providerFactory, api, syncBlockStore);
57
59
  }
58
60
  },
59
61
  contentComponent: function contentComponent() {
@@ -24,6 +24,7 @@ var getToolbarConfig = exports.getToolbarConfig = function getToolbarConfig(stat
24
24
  var _options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
25
25
  var _providerFactory = arguments.length > 3 ? arguments[3] : undefined;
26
26
  var api = arguments.length > 4 ? arguments[4] : undefined;
27
+ var syncBlockStore = arguments.length > 5 ? arguments[5] : undefined;
27
28
  var syncBlockObject = (0, _utils2.findSyncBlock)(state);
28
29
  if (!syncBlockObject) {
29
30
  return;
@@ -51,7 +52,7 @@ var getToolbarConfig = exports.getToolbarConfig = function getToolbarConfig(stat
51
52
  onClick: (0, _actions.copySyncedBlockReferenceToClipboard)(api)
52
53
  }, hoverDecorationProps(nodeType, _consts.akEditorSelectedNodeClassName));
53
54
  items.push(copyButton);
54
- if (syncBlockObject.node.attrs.resourceId !== syncBlockObject.node.attrs.localId) {
55
+ if (!syncBlockStore.isSourceBlock(syncBlockObject.node)) {
55
56
  var editSourceButton = _objectSpread({
56
57
  id: 'editor.syncedBlock.editSource',
57
58
  type: 'button',
@@ -2,7 +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
+ import { convertSyncBlockPMNodeToSyncBlockData, useFetchDocNode } from '@atlaskit/editor-synced-block-provider';
6
6
  import { SyncBlockEditorWrapper, SyncBlockEditorWrapperDataId } from '../ui/SyncBlockEditorWrapper';
7
7
  import { SyncBlockRendererWrapper } from '../ui/SyncBlockRendererWrapper';
8
8
  const defaultSyncBlockEditorDocument = {
@@ -30,26 +30,24 @@ const defaultSyncBlockRendererDocument = {
30
30
  class SyncBlock extends ReactNodeView {
31
31
  constructor(props) {
32
32
  super(props.node, props.view, props.getPos, props.portalProviderAPI, props.eventDispatcher, props);
33
- const {
34
- resourceId,
35
- localId
36
- } = props.node.attrs;
37
- // Temporary solution to identify the source
38
- this.isSource = resourceId === localId;
39
33
  this.options = props.options;
34
+ this.syncBlockStore = props.syncBlockStore;
40
35
  }
41
36
  createDomRef() {
42
37
  const domRef = document.createElement('div');
43
38
  domRef.classList.add(SyncBlockSharedCssClassName.prefix);
44
39
  return domRef;
45
40
  }
41
+ isSource() {
42
+ return this.syncBlockStore.isSourceBlock(this.node);
43
+ }
46
44
  handleContentChanges(updatedDoc) {
47
45
  var _this$options, _this$options$syncedB;
48
46
  if (!this.isSource) {
49
47
  return;
50
48
  }
51
49
  // write data
52
- const node = createSyncBlockNode(this.node, false);
50
+ const node = convertSyncBlockPMNodeToSyncBlockData(this.node, false);
53
51
  (_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
52
  content: updatedDoc.toJSON()
55
53
  }]);
@@ -57,7 +55,7 @@ class SyncBlock extends ReactNodeView {
57
55
  setInnerEditorView(editorView) {
58
56
  var _this$options2, _this$options2$synced;
59
57
  // set inner editor view
60
- const nodes = [createSyncBlockNode(this.node, false)];
58
+ const nodes = [convertSyncBlockPMNodeToSyncBlockData(this.node, false)];
61
59
  (_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
60
  var _data$;
63
61
  const tr = editorView.state.tr;
@@ -102,7 +100,7 @@ class SyncBlock extends ReactNodeView {
102
100
  });
103
101
  }
104
102
  render() {
105
- if (this.isSource) {
103
+ if (this.isSource()) {
106
104
  return this.renderEditor();
107
105
  }
108
106
  return this.renderRenderer();
@@ -150,7 +148,8 @@ class SyncBlock extends ReactNodeView {
150
148
  export const syncBlockNodeView = ({
151
149
  options,
152
150
  pmPluginFactoryParams,
153
- api
151
+ api,
152
+ syncBlockStore
154
153
  }) => (node, view, getPos) => {
155
154
  const {
156
155
  portalProviderAPI,
@@ -163,6 +162,7 @@ export const syncBlockNodeView = ({
163
162
  view,
164
163
  getPos,
165
164
  portalProviderAPI,
166
- eventDispatcher
165
+ eventDispatcher,
166
+ syncBlockStore
167
167
  }).init();
168
168
  };
@@ -1,18 +1,44 @@
1
1
  import { INPUT_METHOD } from '@atlaskit/editor-common/analytics';
2
- import { safeInsert } from '@atlaskit/editor-prosemirror/utils';
3
- import { createSyncBlockPMNode, generateSyncBlockSourceUrl } from '@atlaskit/editor-synced-block-provider';
2
+ import { insertSelectedItem } from '@atlaskit/editor-common/insert';
3
+ import { createWrapSelectionTransaction } from '@atlaskit/editor-common/utils';
4
+ import { generateSyncBlockSourceUrl } from '@atlaskit/editor-synced-block-provider';
4
5
  import { findSyncBlock } from './utils/utils';
5
- export const createSyncedBlock = state => {
6
+ export const createSyncedBlock = (typeAheadInsert, state, syncBlockStore) => {
6
7
  const {
7
- tr,
8
8
  schema: {
9
9
  nodes: {
10
10
  syncBlock
11
11
  }
12
12
  }
13
13
  } = state;
14
- const node = createSyncBlockPMNode(syncBlock);
15
- safeInsert(node)(tr);
14
+ let tr;
15
+ const syncBlockNode = syncBlockStore.createSyncBlockNode();
16
+
17
+ // If the selection is empty, we want to insert the panel on a new line
18
+ if (state.selection.empty) {
19
+ const node = syncBlock.createAndFill({
20
+ ...syncBlockNode.attrs
21
+ });
22
+ if (!node) {
23
+ return false;
24
+ }
25
+ if (typeAheadInsert !== undefined) {
26
+ // If the type-ahead insert is provided, we should use that to insert the node
27
+ tr = typeAheadInsert(node);
28
+ } else {
29
+ var _insertSelectedItem;
30
+ // Otherwise we can use insertSelectedItem to insert the node
31
+ tr = (_insertSelectedItem = insertSelectedItem(node)(state, state.tr, state.selection.head)) === null || _insertSelectedItem === void 0 ? void 0 : _insertSelectedItem.scrollIntoView();
32
+ }
33
+ } else {
34
+ tr = createWrapSelectionTransaction({
35
+ state,
36
+ type: syncBlock,
37
+ nodeAttributes: {
38
+ ...syncBlockNode.attrs
39
+ }
40
+ });
41
+ }
16
42
  return tr;
17
43
  };
18
44
  export const copySyncedBlockReferenceToClipboard = api => (state, dispatch, _view) => {
@@ -26,7 +26,8 @@ export const createPlugin = (options, pmPluginFactoryParams, syncBlockStore, api
26
26
  syncBlock: lazySyncBlockView({
27
27
  options,
28
28
  pmPluginFactoryParams,
29
- api
29
+ api,
30
+ syncBlockStore
30
31
  })
31
32
  }
32
33
  },
@@ -1,7 +1,8 @@
1
1
  import React from 'react';
2
2
  import { syncBlock } from '@atlaskit/adf-schema';
3
+ import { blockTypeMessages } from '@atlaskit/editor-common/messages';
4
+ import { IconSyncBlock } from '@atlaskit/editor-common/quick-insert';
3
5
  import { SyncBlockStoreManager } from '@atlaskit/editor-synced-block-provider';
4
- import SmartLinkIcon from '@atlaskit/icon/core/smart-link';
5
6
  import { createSyncedBlock } from './pm-plugins/actions';
6
7
  import { createPlugin } from './pm-plugins/main';
7
8
  import { ContentComponent } from './ui/ContentComponent';
@@ -26,21 +27,23 @@ export const syncedBlockPlugin = ({
26
27
  }];
27
28
  },
28
29
  pluginsOptions: {
29
- quickInsert: () => [{
30
+ quickInsert: ({
31
+ formatMessage
32
+ }) => [{
30
33
  id: 'syncBlock',
31
- title: 'Synced Block',
32
- description: 'Create a synced block',
34
+ title: formatMessage(blockTypeMessages.syncedBlock),
35
+ description: formatMessage(blockTypeMessages.syncedBlockDescription),
33
36
  priority: 800,
34
- keywords: ['synced', 'block', 'synced-block', 'sync', 'sync-block'],
37
+ keywords: ['synced', 'block', 'synced-block', 'sync', 'sync-block', 'auto', 'update', 'excerpt', 'connect'],
35
38
  keyshortcut: '',
36
- icon: () => /*#__PURE__*/React.createElement(SmartLinkIcon, {
37
- label: "Synced Block"
39
+ icon: () => /*#__PURE__*/React.createElement(IconSyncBlock, {
40
+ label: formatMessage(blockTypeMessages.syncedBlock)
38
41
  }),
39
- action: (_insert, state) => {
40
- return createSyncedBlock(state);
42
+ action: (insert, state) => {
43
+ return createSyncedBlock(insert, state, syncBlockStore);
41
44
  }
42
45
  }],
43
- floatingToolbar: (state, intl, providerFactory) => getToolbarConfig(state, intl, config, providerFactory, api)
46
+ floatingToolbar: (state, intl, providerFactory) => getToolbarConfig(state, intl, config, providerFactory, api, syncBlockStore)
44
47
  },
45
48
  contentComponent: () => {
46
49
  return /*#__PURE__*/React.createElement(ContentComponent, {
@@ -7,7 +7,7 @@ import DeleteIcon from '@atlaskit/icon/core/delete';
7
7
  import LinkExternalIcon from '@atlaskit/icon/core/link-external';
8
8
  import { copySyncedBlockReferenceToClipboard, editSyncedBlockSource, removeSyncedBlock } from '../pm-plugins/actions';
9
9
  import { findSyncBlock } from '../pm-plugins/utils/utils';
10
- export const getToolbarConfig = (state, intl, _options = {}, _providerFactory, api) => {
10
+ export const getToolbarConfig = (state, intl, _options = {}, _providerFactory, api, syncBlockStore) => {
11
11
  var _api$decorations;
12
12
  const syncBlockObject = findSyncBlock(state);
13
13
  if (!syncBlockObject) {
@@ -37,7 +37,7 @@ export const getToolbarConfig = (state, intl, _options = {}, _providerFactory, a
37
37
  ...hoverDecorationProps(nodeType, akEditorSelectedNodeClassName)
38
38
  };
39
39
  items.push(copyButton);
40
- if (syncBlockObject.node.attrs.resourceId !== syncBlockObject.node.attrs.localId) {
40
+ if (!syncBlockStore.isSourceBlock(syncBlockObject.node)) {
41
41
  const editSourceButton = {
42
42
  id: 'editor.syncedBlock.editSource',
43
43
  type: 'button',
@@ -11,7 +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
+ import { convertSyncBlockPMNodeToSyncBlockData, useFetchDocNode as _useFetchDocNode } from '@atlaskit/editor-synced-block-provider';
15
15
  import { SyncBlockEditorWrapper, SyncBlockEditorWrapperDataId } from '../ui/SyncBlockEditorWrapper';
16
16
  import { SyncBlockRendererWrapper } from '../ui/SyncBlockRendererWrapper';
17
17
  var defaultSyncBlockEditorDocument = {
@@ -41,12 +41,8 @@ var SyncBlock = /*#__PURE__*/function (_ReactNodeView) {
41
41
  var _this;
42
42
  _classCallCheck(this, SyncBlock);
43
43
  _this = _callSuper(this, SyncBlock, [props.node, props.view, props.getPos, props.portalProviderAPI, props.eventDispatcher, props]);
44
- var _props$node$attrs = props.node.attrs,
45
- resourceId = _props$node$attrs.resourceId,
46
- localId = _props$node$attrs.localId;
47
- // Temporary solution to identify the source
48
- _this.isSource = resourceId === localId;
49
44
  _this.options = props.options;
45
+ _this.syncBlockStore = props.syncBlockStore;
50
46
  return _this;
51
47
  }
52
48
  _inherits(SyncBlock, _ReactNodeView);
@@ -57,6 +53,11 @@ var SyncBlock = /*#__PURE__*/function (_ReactNodeView) {
57
53
  domRef.classList.add(SyncBlockSharedCssClassName.prefix);
58
54
  return domRef;
59
55
  }
56
+ }, {
57
+ key: "isSource",
58
+ value: function isSource() {
59
+ return this.syncBlockStore.isSourceBlock(this.node);
60
+ }
60
61
  }, {
61
62
  key: "handleContentChanges",
62
63
  value: function handleContentChanges(updatedDoc) {
@@ -65,7 +66,7 @@ var SyncBlock = /*#__PURE__*/function (_ReactNodeView) {
65
66
  return;
66
67
  }
67
68
  // write data
68
- var node = createSyncBlockNode(this.node, false);
69
+ var node = convertSyncBlockPMNodeToSyncBlockData(this.node, false);
69
70
  (_this$options = this.options) === null || _this$options === void 0 || (_this$options = _this$options.syncedBlockProvider) === null || _this$options === void 0 || _this$options.writeNodesData([node], [{
70
71
  content: updatedDoc.toJSON()
71
72
  }]);
@@ -75,7 +76,7 @@ var SyncBlock = /*#__PURE__*/function (_ReactNodeView) {
75
76
  value: function setInnerEditorView(editorView) {
76
77
  var _this$options2;
77
78
  // set inner editor view
78
- var nodes = [createSyncBlockNode(this.node, false)];
79
+ var nodes = [convertSyncBlockPMNodeToSyncBlockData(this.node, false)];
79
80
  (_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
81
  var _data$;
81
82
  var tr = editorView.state.tr;
@@ -134,7 +135,7 @@ var SyncBlock = /*#__PURE__*/function (_ReactNodeView) {
134
135
  }, {
135
136
  key: "render",
136
137
  value: function render() {
137
- if (this.isSource) {
138
+ if (this.isSource()) {
138
139
  return this.renderEditor();
139
140
  }
140
141
  return this.renderRenderer();
@@ -191,7 +192,8 @@ var SyncBlock = /*#__PURE__*/function (_ReactNodeView) {
191
192
  export var syncBlockNodeView = function syncBlockNodeView(_ref) {
192
193
  var options = _ref.options,
193
194
  pmPluginFactoryParams = _ref.pmPluginFactoryParams,
194
- api = _ref.api;
195
+ api = _ref.api,
196
+ syncBlockStore = _ref.syncBlockStore;
195
197
  return function (node, view, getPos) {
196
198
  var portalProviderAPI = pmPluginFactoryParams.portalProviderAPI,
197
199
  eventDispatcher = pmPluginFactoryParams.eventDispatcher;
@@ -202,7 +204,8 @@ export var syncBlockNodeView = function syncBlockNodeView(_ref) {
202
204
  view: view,
203
205
  getPos: getPos,
204
206
  portalProviderAPI: portalProviderAPI,
205
- eventDispatcher: eventDispatcher
207
+ eventDispatcher: eventDispatcher,
208
+ syncBlockStore: syncBlockStore
206
209
  }).init();
207
210
  };
208
211
  };
@@ -1,12 +1,37 @@
1
+ import _defineProperty from "@babel/runtime/helpers/defineProperty";
2
+ function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
3
+ function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
1
4
  import { INPUT_METHOD } from '@atlaskit/editor-common/analytics';
2
- import { safeInsert } from '@atlaskit/editor-prosemirror/utils';
3
- import { createSyncBlockPMNode, generateSyncBlockSourceUrl } from '@atlaskit/editor-synced-block-provider';
5
+ import { insertSelectedItem } from '@atlaskit/editor-common/insert';
6
+ import { createWrapSelectionTransaction } from '@atlaskit/editor-common/utils';
7
+ import { generateSyncBlockSourceUrl } from '@atlaskit/editor-synced-block-provider';
4
8
  import { findSyncBlock } from './utils/utils';
5
- export var createSyncedBlock = function createSyncedBlock(state) {
6
- var tr = state.tr,
7
- syncBlock = state.schema.nodes.syncBlock;
8
- var node = createSyncBlockPMNode(syncBlock);
9
- safeInsert(node)(tr);
9
+ export var createSyncedBlock = function createSyncedBlock(typeAheadInsert, state, syncBlockStore) {
10
+ var syncBlock = state.schema.nodes.syncBlock;
11
+ var tr;
12
+ var syncBlockNode = syncBlockStore.createSyncBlockNode();
13
+
14
+ // If the selection is empty, we want to insert the panel on a new line
15
+ if (state.selection.empty) {
16
+ var node = syncBlock.createAndFill(_objectSpread({}, syncBlockNode.attrs));
17
+ if (!node) {
18
+ return false;
19
+ }
20
+ if (typeAheadInsert !== undefined) {
21
+ // If the type-ahead insert is provided, we should use that to insert the node
22
+ tr = typeAheadInsert(node);
23
+ } else {
24
+ var _insertSelectedItem;
25
+ // Otherwise we can use insertSelectedItem to insert the node
26
+ tr = (_insertSelectedItem = insertSelectedItem(node)(state, state.tr, state.selection.head)) === null || _insertSelectedItem === void 0 ? void 0 : _insertSelectedItem.scrollIntoView();
27
+ }
28
+ } else {
29
+ tr = createWrapSelectionTransaction({
30
+ state: state,
31
+ type: syncBlock,
32
+ nodeAttributes: _objectSpread({}, syncBlockNode.attrs)
33
+ });
34
+ }
10
35
  return tr;
11
36
  };
12
37
  export var copySyncedBlockReferenceToClipboard = function copySyncedBlockReferenceToClipboard(api) {
@@ -26,7 +26,8 @@ export var createPlugin = function createPlugin(options, pmPluginFactoryParams,
26
26
  syncBlock: lazySyncBlockView({
27
27
  options: options,
28
28
  pmPluginFactoryParams: pmPluginFactoryParams,
29
- api: api
29
+ api: api,
30
+ syncBlockStore: syncBlockStore
30
31
  })
31
32
  }
32
33
  },
@@ -1,7 +1,8 @@
1
1
  import React from 'react';
2
2
  import { syncBlock } from '@atlaskit/adf-schema';
3
+ import { blockTypeMessages } from '@atlaskit/editor-common/messages';
4
+ import { IconSyncBlock } from '@atlaskit/editor-common/quick-insert';
3
5
  import { SyncBlockStoreManager } from '@atlaskit/editor-synced-block-provider';
4
- import SmartLinkIcon from '@atlaskit/icon/core/smart-link';
5
6
  import { createSyncedBlock } from './pm-plugins/actions';
6
7
  import { createPlugin } from './pm-plugins/main';
7
8
  import { ContentComponent } from './ui/ContentComponent';
@@ -27,26 +28,27 @@ export var syncedBlockPlugin = function syncedBlockPlugin(_ref) {
27
28
  }];
28
29
  },
29
30
  pluginsOptions: {
30
- quickInsert: function quickInsert() {
31
+ quickInsert: function quickInsert(_ref2) {
32
+ var formatMessage = _ref2.formatMessage;
31
33
  return [{
32
34
  id: 'syncBlock',
33
- title: 'Synced Block',
34
- description: 'Create a synced block',
35
+ title: formatMessage(blockTypeMessages.syncedBlock),
36
+ description: formatMessage(blockTypeMessages.syncedBlockDescription),
35
37
  priority: 800,
36
- keywords: ['synced', 'block', 'synced-block', 'sync', 'sync-block'],
38
+ keywords: ['synced', 'block', 'synced-block', 'sync', 'sync-block', 'auto', 'update', 'excerpt', 'connect'],
37
39
  keyshortcut: '',
38
40
  icon: function icon() {
39
- return /*#__PURE__*/React.createElement(SmartLinkIcon, {
40
- label: "Synced Block"
41
+ return /*#__PURE__*/React.createElement(IconSyncBlock, {
42
+ label: formatMessage(blockTypeMessages.syncedBlock)
41
43
  });
42
44
  },
43
- action: function action(_insert, state) {
44
- return createSyncedBlock(state);
45
+ action: function action(insert, state) {
46
+ return createSyncedBlock(insert, state, syncBlockStore);
45
47
  }
46
48
  }];
47
49
  },
48
50
  floatingToolbar: function floatingToolbar(state, intl, providerFactory) {
49
- return getToolbarConfig(state, intl, config, providerFactory, api);
51
+ return getToolbarConfig(state, intl, config, providerFactory, api, syncBlockStore);
50
52
  }
51
53
  },
52
54
  contentComponent: function contentComponent() {
@@ -15,6 +15,7 @@ export var getToolbarConfig = function getToolbarConfig(state, intl) {
15
15
  var _options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
16
16
  var _providerFactory = arguments.length > 3 ? arguments[3] : undefined;
17
17
  var api = arguments.length > 4 ? arguments[4] : undefined;
18
+ var syncBlockStore = arguments.length > 5 ? arguments[5] : undefined;
18
19
  var syncBlockObject = findSyncBlock(state);
19
20
  if (!syncBlockObject) {
20
21
  return;
@@ -42,7 +43,7 @@ export var getToolbarConfig = function getToolbarConfig(state, intl) {
42
43
  onClick: copySyncedBlockReferenceToClipboard(api)
43
44
  }, hoverDecorationProps(nodeType, akEditorSelectedNodeClassName));
44
45
  items.push(copyButton);
45
- if (syncBlockObject.node.attrs.resourceId !== syncBlockObject.node.attrs.localId) {
46
+ if (!syncBlockStore.isSourceBlock(syncBlockObject.node)) {
46
47
  var editSourceButton = _objectSpread({
47
48
  id: 'editor.syncedBlock.editSource',
48
49
  type: 'button',
@@ -6,6 +6,7 @@ import type { ReactComponentProps } from '@atlaskit/editor-common/react-node-vie
6
6
  import type { ExtractInjectionAPI, PMPluginFactoryParams } from '@atlaskit/editor-common/types';
7
7
  import type { Node as PMNode } from '@atlaskit/editor-prosemirror/model';
8
8
  import type { EditorView } from '@atlaskit/editor-prosemirror/view';
9
+ import type { SyncBlockStoreManager } from '@atlaskit/editor-synced-block-provider';
9
10
  import type { SyncedBlockPlugin, SyncedBlockPluginOptions } from '../syncedBlockPluginType';
10
11
  export interface SyncBlockNodeViewProps extends ReactComponentProps {
11
12
  api?: ExtractInjectionAPI<SyncedBlockPlugin>;
@@ -15,15 +16,17 @@ export interface SyncBlockNodeViewProps extends ReactComponentProps {
15
16
  node: PMNode;
16
17
  options: SyncedBlockPluginOptions | undefined;
17
18
  portalProviderAPI: PortalProviderAPI;
19
+ syncBlockStore: SyncBlockStoreManager;
18
20
  view: EditorView;
19
21
  }
20
22
  declare class SyncBlock extends ReactNodeView<SyncBlockNodeViewProps> {
21
- private isSource;
22
23
  private options;
23
24
  private fetchIntervalId;
25
+ private syncBlockStore;
24
26
  constructor(props: SyncBlockNodeViewProps);
25
27
  unsubscribe: (() => void) | undefined;
26
28
  createDomRef(): HTMLElement;
29
+ private isSource;
27
30
  private handleContentChanges;
28
31
  private setInnerEditorView;
29
32
  private renderEditor;
@@ -38,6 +41,7 @@ export interface SyncBlockNodeViewProperties {
38
41
  api?: ExtractInjectionAPI<SyncedBlockPlugin>;
39
42
  options: SyncedBlockPluginOptions | undefined;
40
43
  pmPluginFactoryParams: PMPluginFactoryParams;
44
+ syncBlockStore: SyncBlockStoreManager;
41
45
  }
42
- export declare const syncBlockNodeView: ({ options, pmPluginFactoryParams, api }: SyncBlockNodeViewProperties) => (node: PMNode, view: EditorView, getPos: () => number | undefined) => SyncBlock;
46
+ export declare const syncBlockNodeView: ({ options, pmPluginFactoryParams, api, syncBlockStore }: SyncBlockNodeViewProperties) => (node: PMNode, view: EditorView, getPos: () => number | undefined) => SyncBlock;
43
47
  export {};
@@ -1,7 +1,8 @@
1
- import type { Command, ExtractInjectionAPI } from '@atlaskit/editor-common/types';
1
+ import type { Command, ExtractInjectionAPI, TypeAheadInsert } from '@atlaskit/editor-common/types';
2
2
  import { type EditorState, type Transaction } from '@atlaskit/editor-prosemirror/state';
3
+ import type { SyncBlockStoreManager } from '@atlaskit/editor-synced-block-provider';
3
4
  import type { SyncedBlockPlugin } from '../syncedBlockPluginType';
4
- export declare const createSyncedBlock: (state: EditorState) => Transaction;
5
+ export declare const createSyncedBlock: (typeAheadInsert: TypeAheadInsert, state: EditorState, syncBlockStore: SyncBlockStoreManager) => false | Transaction;
5
6
  export declare const copySyncedBlockReferenceToClipboard: (api?: ExtractInjectionAPI<SyncedBlockPlugin>) => Command;
6
7
  export declare const editSyncedBlockSource: (_api?: ExtractInjectionAPI<SyncedBlockPlugin>) => Command;
7
8
  export declare const removeSyncedBlock: (api?: ExtractInjectionAPI<SyncedBlockPlugin>) => Command;
@@ -2,5 +2,6 @@ import type { IntlShape } from 'react-intl-next';
2
2
  import type { ProviderFactory } from '@atlaskit/editor-common/provider-factory';
3
3
  import type { ExtractInjectionAPI, FloatingToolbarConfig } from '@atlaskit/editor-common/types';
4
4
  import type { EditorState } from '@atlaskit/editor-prosemirror/state';
5
+ import type { SyncBlockStoreManager } from '@atlaskit/editor-synced-block-provider';
5
6
  import type { SyncedBlockPlugin, SyncedBlockPluginOptions } from '../syncedBlockPluginType';
6
- export declare const getToolbarConfig: (state: EditorState, intl: IntlShape, _options: SyncedBlockPluginOptions | undefined, _providerFactory: ProviderFactory, api: ExtractInjectionAPI<SyncedBlockPlugin> | undefined) => FloatingToolbarConfig | undefined;
7
+ export declare const getToolbarConfig: (state: EditorState, intl: IntlShape, _options: SyncedBlockPluginOptions | undefined, _providerFactory: ProviderFactory, api: ExtractInjectionAPI<SyncedBlockPlugin> | undefined, syncBlockStore: SyncBlockStoreManager) => FloatingToolbarConfig | undefined;
@@ -6,6 +6,7 @@ import type { ReactComponentProps } from '@atlaskit/editor-common/react-node-vie
6
6
  import type { ExtractInjectionAPI, PMPluginFactoryParams } from '@atlaskit/editor-common/types';
7
7
  import type { Node as PMNode } from '@atlaskit/editor-prosemirror/model';
8
8
  import type { EditorView } from '@atlaskit/editor-prosemirror/view';
9
+ import type { SyncBlockStoreManager } from '@atlaskit/editor-synced-block-provider';
9
10
  import type { SyncedBlockPlugin, SyncedBlockPluginOptions } from '../syncedBlockPluginType';
10
11
  export interface SyncBlockNodeViewProps extends ReactComponentProps {
11
12
  api?: ExtractInjectionAPI<SyncedBlockPlugin>;
@@ -15,15 +16,17 @@ export interface SyncBlockNodeViewProps extends ReactComponentProps {
15
16
  node: PMNode;
16
17
  options: SyncedBlockPluginOptions | undefined;
17
18
  portalProviderAPI: PortalProviderAPI;
19
+ syncBlockStore: SyncBlockStoreManager;
18
20
  view: EditorView;
19
21
  }
20
22
  declare class SyncBlock extends ReactNodeView<SyncBlockNodeViewProps> {
21
- private isSource;
22
23
  private options;
23
24
  private fetchIntervalId;
25
+ private syncBlockStore;
24
26
  constructor(props: SyncBlockNodeViewProps);
25
27
  unsubscribe: (() => void) | undefined;
26
28
  createDomRef(): HTMLElement;
29
+ private isSource;
27
30
  private handleContentChanges;
28
31
  private setInnerEditorView;
29
32
  private renderEditor;
@@ -38,6 +41,7 @@ export interface SyncBlockNodeViewProperties {
38
41
  api?: ExtractInjectionAPI<SyncedBlockPlugin>;
39
42
  options: SyncedBlockPluginOptions | undefined;
40
43
  pmPluginFactoryParams: PMPluginFactoryParams;
44
+ syncBlockStore: SyncBlockStoreManager;
41
45
  }
42
- export declare const syncBlockNodeView: ({ options, pmPluginFactoryParams, api }: SyncBlockNodeViewProperties) => (node: PMNode, view: EditorView, getPos: () => number | undefined) => SyncBlock;
46
+ export declare const syncBlockNodeView: ({ options, pmPluginFactoryParams, api, syncBlockStore }: SyncBlockNodeViewProperties) => (node: PMNode, view: EditorView, getPos: () => number | undefined) => SyncBlock;
43
47
  export {};
@@ -1,7 +1,8 @@
1
- import type { Command, ExtractInjectionAPI } from '@atlaskit/editor-common/types';
1
+ import type { Command, ExtractInjectionAPI, TypeAheadInsert } from '@atlaskit/editor-common/types';
2
2
  import { type EditorState, type Transaction } from '@atlaskit/editor-prosemirror/state';
3
+ import type { SyncBlockStoreManager } from '@atlaskit/editor-synced-block-provider';
3
4
  import type { SyncedBlockPlugin } from '../syncedBlockPluginType';
4
- export declare const createSyncedBlock: (state: EditorState) => Transaction;
5
+ export declare const createSyncedBlock: (typeAheadInsert: TypeAheadInsert, state: EditorState, syncBlockStore: SyncBlockStoreManager) => false | Transaction;
5
6
  export declare const copySyncedBlockReferenceToClipboard: (api?: ExtractInjectionAPI<SyncedBlockPlugin>) => Command;
6
7
  export declare const editSyncedBlockSource: (_api?: ExtractInjectionAPI<SyncedBlockPlugin>) => Command;
7
8
  export declare const removeSyncedBlock: (api?: ExtractInjectionAPI<SyncedBlockPlugin>) => Command;
@@ -2,5 +2,6 @@ import type { IntlShape } from 'react-intl-next';
2
2
  import type { ProviderFactory } from '@atlaskit/editor-common/provider-factory';
3
3
  import type { ExtractInjectionAPI, FloatingToolbarConfig } from '@atlaskit/editor-common/types';
4
4
  import type { EditorState } from '@atlaskit/editor-prosemirror/state';
5
+ import type { SyncBlockStoreManager } from '@atlaskit/editor-synced-block-provider';
5
6
  import type { SyncedBlockPlugin, SyncedBlockPluginOptions } from '../syncedBlockPluginType';
6
- export declare const getToolbarConfig: (state: EditorState, intl: IntlShape, _options: SyncedBlockPluginOptions | undefined, _providerFactory: ProviderFactory, api: ExtractInjectionAPI<SyncedBlockPlugin> | undefined) => FloatingToolbarConfig | undefined;
7
+ export declare const getToolbarConfig: (state: EditorState, intl: IntlShape, _options: SyncedBlockPluginOptions | undefined, _providerFactory: ProviderFactory, api: ExtractInjectionAPI<SyncedBlockPlugin> | undefined, syncBlockStore: SyncBlockStoreManager) => FloatingToolbarConfig | undefined;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atlaskit/editor-plugin-synced-block",
3
- "version": "3.0.2",
3
+ "version": "3.0.3",
4
4
  "description": "SyncedBlock plugin for @atlaskit/editor-core",
5
5
  "author": "Atlassian Pty Ltd",
6
6
  "license": "Apache-2.0",
@@ -42,7 +42,7 @@
42
42
  "react-intl-next": "npm:react-intl@^5.18.1"
43
43
  },
44
44
  "peerDependencies": {
45
- "@atlaskit/editor-common": "^110.2.0",
45
+ "@atlaskit/editor-common": "^110.3.0",
46
46
  "react": "^18.2.0"
47
47
  },
48
48
  "devDependencies": {