@atlaskit/editor-plugin-synced-block 3.0.6 → 3.1.1

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,24 @@
1
1
  # @atlaskit/editor-plugin-synced-block
2
2
 
3
+ ## 3.1.1
4
+
5
+ ### Patch Changes
6
+
7
+ - [`7011f9be6a430`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/7011f9be6a430) -
8
+ [ux] EDITOR-1653 add create synced block item to the block menu
9
+ - Updated dependencies
10
+
11
+ ## 3.1.0
12
+
13
+ ### Minor Changes
14
+
15
+ - [`9e7a5a0bb1869`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/9e7a5a0bb1869) -
16
+ Add content api sync block provider
17
+
18
+ ### Patch Changes
19
+
20
+ - Updated dependencies
21
+
3
22
  ## 3.0.6
4
23
 
5
24
  ### Patch Changes
@@ -25,6 +25,9 @@
25
25
  {
26
26
  "path": "../../../design-system/button/afm-cc/tsconfig.json"
27
27
  },
28
+ {
29
+ "path": "../../editor-plugin-block-menu/afm-cc/tsconfig.json"
30
+ },
28
31
  {
29
32
  "path": "../../editor-plugin-decorations/afm-cc/tsconfig.json"
30
33
  },
@@ -40,6 +43,9 @@
40
43
  {
41
44
  "path": "../../editor-synced-block-provider/afm-cc/tsconfig.json"
42
45
  },
46
+ {
47
+ "path": "../../editor-toolbar/afm-cc/tsconfig.json"
48
+ },
43
49
  {
44
50
  "path": "../../../design-system/icon/afm-cc/tsconfig.json"
45
51
  },
@@ -74,7 +74,7 @@ var SyncBlock = /*#__PURE__*/function (_ReactNodeView) {
74
74
  }
75
75
  // write data
76
76
  var node = (0, _editorSyncedBlockProvider.convertSyncBlockPMNodeToSyncBlockData)(this.node, false);
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
+ (_this$options = this.options) === null || _this$options === void 0 || (_this$options = _this$options.dataProvider) === null || _this$options === void 0 || _this$options.writeNodesData([node], [{
78
78
  content: updatedDoc.toJSON()
79
79
  }]);
80
80
  }
@@ -84,7 +84,7 @@ var SyncBlock = /*#__PURE__*/function (_ReactNodeView) {
84
84
  var _this$options2;
85
85
  // set inner editor view
86
86
  var nodes = [(0, _editorSyncedBlockProvider.convertSyncBlockPMNodeToSyncBlockData)(this.node, false)];
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
+ (_this$options2 = this.options) === null || _this$options2 === void 0 || (_this$options2 = _this$options2.dataProvider) === null || _this$options2 === void 0 || _this$options2.fetchNodesData(nodes).then(function (data) {
88
88
  var _data$;
89
89
  var tr = editorView.state.tr;
90
90
  if (data && (_data$ = data[0]) !== null && _data$ !== void 0 && _data$.content) {
@@ -134,7 +134,7 @@ var SyncBlock = /*#__PURE__*/function (_ReactNodeView) {
134
134
  return /*#__PURE__*/_react.default.createElement(_SyncBlockRendererWrapper.SyncBlockRendererWrapper, {
135
135
  useFetchDocNode: function useFetchDocNode() {
136
136
  var _this3$options;
137
- return (0, _editorSyncedBlockProvider.useFetchDocNode)(_this3.view, _this3.node, defaultSyncBlockRendererDocument, (_this3$options = _this3.options) === null || _this3$options === void 0 ? void 0 : _this3$options.syncedBlockProvider);
137
+ return (0, _editorSyncedBlockProvider.useFetchDocNode)(_this3.view, _this3.node, defaultSyncBlockRendererDocument, (_this3$options = _this3.options) === null || _this3$options === void 0 ? void 0 : _this3$options.dataProvider);
138
138
  },
139
139
  getSyncedBlockRenderer: (_this$options6 = this.options) === null || _this$options6 === void 0 ? void 0 : _this$options6.getSyncedBlockRenderer
140
140
  });
@@ -7,37 +7,30 @@ Object.defineProperty(exports, "__esModule", {
7
7
  exports.removeSyncedBlock = exports.editSyncedBlockSource = exports.createSyncedBlock = exports.copySyncedBlockReferenceToClipboard = void 0;
8
8
  var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
9
9
  var _analytics = require("@atlaskit/editor-common/analytics");
10
- var _insert = require("@atlaskit/editor-common/insert");
11
- var _utils = require("@atlaskit/editor-common/utils");
10
+ var _utils = require("@atlaskit/editor-prosemirror/utils");
12
11
  var _editorSyncedBlockProvider = require("@atlaskit/editor-synced-block-provider");
13
12
  var _utils2 = require("./utils/utils");
14
13
  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
14
  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;
15
+ var createSyncedBlock = exports.createSyncedBlock = function createSyncedBlock(tr, syncBlockStore, typeAheadInsert) {
16
+ var syncBlock = tr.doc.type.schema.nodes.syncBlock;
19
17
  var syncBlockNode = syncBlockStore.createSyncBlockNode();
20
18
 
21
19
  // If the selection is empty, we want to insert the panel on a new line
22
- if (state.selection.empty) {
20
+ if (tr.selection.empty) {
23
21
  var node = syncBlock.createAndFill(_objectSpread({}, syncBlockNode.attrs));
24
22
  if (!node) {
25
23
  return false;
26
24
  }
27
- if (typeAheadInsert !== undefined) {
28
- // If the type-ahead insert is provided, we should use that to insert the node
25
+ if (typeAheadInsert) {
29
26
  tr = typeAheadInsert(node);
30
27
  } 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();
28
+ tr = tr.replaceSelectionWith(node).scrollIntoView();
34
29
  }
35
30
  } else {
36
- tr = (0, _utils.createWrapSelectionTransaction)({
37
- state: state,
38
- type: syncBlock,
39
- nodeAttributes: _objectSpread({}, syncBlockNode.attrs)
40
- });
31
+ var _safeInsert;
32
+ // TODO: EDITOR-1653 - put selection inside the sync block if possible
33
+ (_safeInsert = (0, _utils.safeInsert)(syncBlock.createAndFill(syncBlockNode.attrs))(tr)) === null || _safeInsert === void 0 || _safeInsert.scrollIntoView();
41
34
  }
42
35
  return tr;
43
36
  };
@@ -12,12 +12,15 @@ var _quickInsert = require("@atlaskit/editor-common/quick-insert");
12
12
  var _editorSyncedBlockProvider = require("@atlaskit/editor-synced-block-provider");
13
13
  var _actions = require("./pm-plugins/actions");
14
14
  var _main = require("./pm-plugins/main");
15
+ var _blockMenuComponents = require("./ui/block-menu-components");
15
16
  var _ContentComponent = require("./ui/ContentComponent");
16
17
  var _floatingToolbar = require("./ui/floating-toolbar");
17
18
  var syncedBlockPlugin = exports.syncedBlockPlugin = function syncedBlockPlugin(_ref) {
19
+ var _api$blockMenu;
18
20
  var config = _ref.config,
19
21
  api = _ref.api;
20
22
  var syncBlockStore = new _editorSyncedBlockProvider.SyncBlockStoreManager(config === null || config === void 0 ? void 0 : config.dataProvider);
23
+ api === null || api === void 0 || (_api$blockMenu = api.blockMenu) === null || _api$blockMenu === void 0 || _api$blockMenu.actions.registerBlockMenuComponents((0, _blockMenuComponents.getBlockMenuComponents)(api));
21
24
  return {
22
25
  name: 'syncedBlock',
23
26
  nodes: function nodes() {
@@ -34,9 +37,17 @@ var syncedBlockPlugin = exports.syncedBlockPlugin = function syncedBlockPlugin(_
34
37
  }
35
38
  }];
36
39
  },
40
+ commands: {
41
+ insertSyncedBlock: function insertSyncedBlock() {
42
+ return function (_ref2) {
43
+ var tr = _ref2.tr;
44
+ return (0, _actions.createSyncedBlock)(tr, syncBlockStore) || null;
45
+ };
46
+ }
47
+ },
37
48
  pluginsOptions: {
38
- quickInsert: function quickInsert(_ref2) {
39
- var formatMessage = _ref2.formatMessage;
49
+ quickInsert: function quickInsert(_ref3) {
50
+ var formatMessage = _ref3.formatMessage;
40
51
  return [{
41
52
  id: 'syncBlock',
42
53
  title: formatMessage(_messages.blockTypeMessages.syncedBlock),
@@ -50,7 +61,7 @@ var syncedBlockPlugin = exports.syncedBlockPlugin = function syncedBlockPlugin(_
50
61
  });
51
62
  },
52
63
  action: function action(insert, state) {
53
- return (0, _actions.createSyncedBlock)(insert, state, syncBlockStore);
64
+ return (0, _actions.createSyncedBlock)(state.tr, syncBlockStore, insert);
54
65
  }
55
66
  }];
56
67
  },
@@ -0,0 +1,31 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
+ Object.defineProperty(exports, "__esModule", {
5
+ value: true
6
+ });
7
+ exports.CreateSyncedBlockDropdownItem = void 0;
8
+ var _react = _interopRequireDefault(require("react"));
9
+ var _reactIntlNext = require("react-intl-next");
10
+ var _messages = require("@atlaskit/editor-common/messages");
11
+ var _editorToolbar = require("@atlaskit/editor-toolbar");
12
+ var CreateSyncedBlockDropdownItem = exports.CreateSyncedBlockDropdownItem = function CreateSyncedBlockDropdownItem(_ref) {
13
+ var _api$selection;
14
+ var api = _ref.api;
15
+ var _useIntl = (0, _reactIntlNext.useIntl)(),
16
+ formatMessage = _useIntl.formatMessage;
17
+ var selection = api === null || api === void 0 || (_api$selection = api.selection) === null || _api$selection === void 0 || (_api$selection = _api$selection.sharedState) === null || _api$selection === void 0 || (_api$selection = _api$selection.currentState()) === null || _api$selection === void 0 ? void 0 : _api$selection.selection;
18
+ if (!(selection !== null && selection !== void 0 && selection.empty)) {
19
+ return null;
20
+ }
21
+ var onClick = function onClick() {
22
+ var _api$core;
23
+ api === null || api === void 0 || (_api$core = api.core) === null || _api$core === void 0 || _api$core.actions.execute(api === null || api === void 0 ? void 0 : api.syncedBlock.commands.insertSyncedBlock());
24
+ };
25
+ return /*#__PURE__*/_react.default.createElement(_editorToolbar.ToolbarDropdownItem, {
26
+ elemBefore: /*#__PURE__*/_react.default.createElement(_editorToolbar.SyncBlocksIcon, {
27
+ label: ""
28
+ }),
29
+ onClick: onClick
30
+ }, formatMessage(_messages.blockMenuMessages.createSyncedBlock));
31
+ };
@@ -0,0 +1,26 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
+ Object.defineProperty(exports, "__esModule", {
5
+ value: true
6
+ });
7
+ exports.getBlockMenuComponents = void 0;
8
+ var _react = _interopRequireDefault(require("react"));
9
+ var _blockMenu = require("@atlaskit/editor-common/block-menu");
10
+ var _CreateSyncedBlockDropdownItem = require("./CreateSyncedBlockDropdownItem");
11
+ var getBlockMenuComponents = exports.getBlockMenuComponents = function getBlockMenuComponents(api) {
12
+ return [{
13
+ type: 'block-menu-item',
14
+ key: _blockMenu.CREATE_SYNCED_BLOCK_MENU_ITEM.key,
15
+ parent: {
16
+ type: 'block-menu-section',
17
+ key: _blockMenu.ADD_BLOCKS_MENU_SECTION.key,
18
+ rank: _blockMenu.ADD_BLOCKS_MENU_SECTION_RANK[_blockMenu.CREATE_SYNCED_BLOCK_MENU_ITEM.key]
19
+ },
20
+ component: function component() {
21
+ return /*#__PURE__*/_react.default.createElement(_CreateSyncedBlockDropdownItem.CreateSyncedBlockDropdownItem, {
22
+ api: api
23
+ });
24
+ }
25
+ }];
26
+ };
@@ -42,21 +42,21 @@ class SyncBlock extends ReactNodeView {
42
42
  return this.syncBlockStore.isSourceBlock(this.node);
43
43
  }
44
44
  handleContentChanges(updatedDoc) {
45
- var _this$options, _this$options$syncedB;
45
+ var _this$options, _this$options$dataPro;
46
46
  if (!this.isSource) {
47
47
  return;
48
48
  }
49
49
  // write data
50
50
  const node = convertSyncBlockPMNodeToSyncBlockData(this.node, false);
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], [{
51
+ (_this$options = this.options) === null || _this$options === void 0 ? void 0 : (_this$options$dataPro = _this$options.dataProvider) === null || _this$options$dataPro === void 0 ? void 0 : _this$options$dataPro.writeNodesData([node], [{
52
52
  content: updatedDoc.toJSON()
53
53
  }]);
54
54
  }
55
55
  setInnerEditorView(editorView) {
56
- var _this$options2, _this$options2$synced;
56
+ var _this$options2, _this$options2$dataPr;
57
57
  // set inner editor view
58
58
  const nodes = [convertSyncBlockPMNodeToSyncBlockData(this.node, false)];
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 => {
59
+ (_this$options2 = this.options) === null || _this$options2 === void 0 ? void 0 : (_this$options2$dataPr = _this$options2.dataProvider) === null || _this$options2$dataPr === void 0 ? void 0 : _this$options2$dataPr.fetchNodesData(nodes).then(data => {
60
60
  var _data$;
61
61
  const tr = editorView.state.tr;
62
62
  if (data && (_data$ = data[0]) !== null && _data$ !== void 0 && _data$.content) {
@@ -94,7 +94,7 @@ class SyncBlock extends ReactNodeView {
94
94
  return /*#__PURE__*/React.createElement(SyncBlockRendererWrapper, {
95
95
  useFetchDocNode: () => {
96
96
  var _this$options6;
97
- return useFetchDocNode(this.view, this.node, defaultSyncBlockRendererDocument, (_this$options6 = this.options) === null || _this$options6 === void 0 ? void 0 : _this$options6.syncedBlockProvider);
97
+ return useFetchDocNode(this.view, this.node, defaultSyncBlockRendererDocument, (_this$options6 = this.options) === null || _this$options6 === void 0 ? void 0 : _this$options6.dataProvider);
98
98
  },
99
99
  getSyncedBlockRenderer: (_this$options7 = this.options) === null || _this$options7 === void 0 ? void 0 : _this$options7.getSyncedBlockRenderer
100
100
  });
@@ -1,43 +1,34 @@
1
1
  import { INPUT_METHOD } from '@atlaskit/editor-common/analytics';
2
- import { insertSelectedItem } from '@atlaskit/editor-common/insert';
3
- import { createWrapSelectionTransaction } from '@atlaskit/editor-common/utils';
2
+ import { safeInsert } from '@atlaskit/editor-prosemirror/utils';
4
3
  import { generateSyncBlockSourceUrl } from '@atlaskit/editor-synced-block-provider';
5
4
  import { findSyncBlock } from './utils/utils';
6
- export const createSyncedBlock = (typeAheadInsert, state, syncBlockStore) => {
5
+ export const createSyncedBlock = (tr, syncBlockStore, typeAheadInsert) => {
7
6
  const {
8
7
  schema: {
9
8
  nodes: {
10
9
  syncBlock
11
10
  }
12
11
  }
13
- } = state;
14
- let tr;
12
+ } = tr.doc.type;
15
13
  const syncBlockNode = syncBlockStore.createSyncBlockNode();
16
14
 
17
15
  // If the selection is empty, we want to insert the panel on a new line
18
- if (state.selection.empty) {
16
+ if (tr.selection.empty) {
19
17
  const node = syncBlock.createAndFill({
20
18
  ...syncBlockNode.attrs
21
19
  });
22
20
  if (!node) {
23
21
  return false;
24
22
  }
25
- if (typeAheadInsert !== undefined) {
26
- // If the type-ahead insert is provided, we should use that to insert the node
23
+ if (typeAheadInsert) {
27
24
  tr = typeAheadInsert(node);
28
25
  } 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();
26
+ tr = tr.replaceSelectionWith(node).scrollIntoView();
32
27
  }
33
28
  } else {
34
- tr = createWrapSelectionTransaction({
35
- state,
36
- type: syncBlock,
37
- nodeAttributes: {
38
- ...syncBlockNode.attrs
39
- }
40
- });
29
+ var _safeInsert;
30
+ // TODO: EDITOR-1653 - put selection inside the sync block if possible
31
+ (_safeInsert = safeInsert(syncBlock.createAndFill(syncBlockNode.attrs))(tr)) === null || _safeInsert === void 0 ? void 0 : _safeInsert.scrollIntoView();
41
32
  }
42
33
  return tr;
43
34
  };
@@ -5,13 +5,16 @@ import { IconSyncBlock } from '@atlaskit/editor-common/quick-insert';
5
5
  import { SyncBlockStoreManager } from '@atlaskit/editor-synced-block-provider';
6
6
  import { createSyncedBlock } from './pm-plugins/actions';
7
7
  import { createPlugin } from './pm-plugins/main';
8
+ import { getBlockMenuComponents } from './ui/block-menu-components';
8
9
  import { ContentComponent } from './ui/ContentComponent';
9
10
  import { getToolbarConfig } from './ui/floating-toolbar';
10
11
  export const syncedBlockPlugin = ({
11
12
  config,
12
13
  api
13
14
  }) => {
15
+ var _api$blockMenu;
14
16
  const syncBlockStore = new SyncBlockStoreManager(config === null || config === void 0 ? void 0 : config.dataProvider);
17
+ api === null || api === void 0 ? void 0 : (_api$blockMenu = api.blockMenu) === null || _api$blockMenu === void 0 ? void 0 : _api$blockMenu.actions.registerBlockMenuComponents(getBlockMenuComponents(api));
15
18
  return {
16
19
  name: 'syncedBlock',
17
20
  nodes() {
@@ -26,6 +29,11 @@ export const syncedBlockPlugin = ({
26
29
  plugin: params => createPlugin(config, params, syncBlockStore, api)
27
30
  }];
28
31
  },
32
+ commands: {
33
+ insertSyncedBlock: () => ({
34
+ tr
35
+ }) => createSyncedBlock(tr, syncBlockStore) || null
36
+ },
29
37
  pluginsOptions: {
30
38
  quickInsert: ({
31
39
  formatMessage
@@ -40,7 +48,7 @@ export const syncedBlockPlugin = ({
40
48
  label: formatMessage(blockTypeMessages.syncedBlock)
41
49
  }),
42
50
  action: (insert, state) => {
43
- return createSyncedBlock(insert, state, syncBlockStore);
51
+ return createSyncedBlock(state.tr, syncBlockStore, insert);
44
52
  }
45
53
  }],
46
54
  floatingToolbar: (state, intl, providerFactory) => getToolbarConfig(state, intl, config, providerFactory, api, syncBlockStore)
@@ -0,0 +1,26 @@
1
+ import React from 'react';
2
+ import { useIntl } from 'react-intl-next';
3
+ import { blockMenuMessages } from '@atlaskit/editor-common/messages';
4
+ import { SyncBlocksIcon, ToolbarDropdownItem } from '@atlaskit/editor-toolbar';
5
+ export const CreateSyncedBlockDropdownItem = ({
6
+ api
7
+ }) => {
8
+ var _api$selection, _api$selection$shared, _api$selection$shared2;
9
+ const {
10
+ formatMessage
11
+ } = useIntl();
12
+ const selection = api === null || api === void 0 ? void 0 : (_api$selection = api.selection) === null || _api$selection === void 0 ? void 0 : (_api$selection$shared = _api$selection.sharedState) === null || _api$selection$shared === void 0 ? void 0 : (_api$selection$shared2 = _api$selection$shared.currentState()) === null || _api$selection$shared2 === void 0 ? void 0 : _api$selection$shared2.selection;
13
+ if (!(selection !== null && selection !== void 0 && selection.empty)) {
14
+ return null;
15
+ }
16
+ const onClick = () => {
17
+ var _api$core;
18
+ api === null || api === void 0 ? void 0 : (_api$core = api.core) === null || _api$core === void 0 ? void 0 : _api$core.actions.execute(api === null || api === void 0 ? void 0 : api.syncedBlock.commands.insertSyncedBlock());
19
+ };
20
+ return /*#__PURE__*/React.createElement(ToolbarDropdownItem, {
21
+ elemBefore: /*#__PURE__*/React.createElement(SyncBlocksIcon, {
22
+ label: ""
23
+ }),
24
+ onClick: onClick
25
+ }, formatMessage(blockMenuMessages.createSyncedBlock));
26
+ };
@@ -0,0 +1,17 @@
1
+ import React from 'react';
2
+ import { ADD_BLOCKS_MENU_SECTION, ADD_BLOCKS_MENU_SECTION_RANK, CREATE_SYNCED_BLOCK_MENU_ITEM } from '@atlaskit/editor-common/block-menu';
3
+ import { CreateSyncedBlockDropdownItem } from './CreateSyncedBlockDropdownItem';
4
+ export const getBlockMenuComponents = api => {
5
+ return [{
6
+ type: 'block-menu-item',
7
+ key: CREATE_SYNCED_BLOCK_MENU_ITEM.key,
8
+ parent: {
9
+ type: 'block-menu-section',
10
+ key: ADD_BLOCKS_MENU_SECTION.key,
11
+ rank: ADD_BLOCKS_MENU_SECTION_RANK[CREATE_SYNCED_BLOCK_MENU_ITEM.key]
12
+ },
13
+ component: () => /*#__PURE__*/React.createElement(CreateSyncedBlockDropdownItem, {
14
+ api: api
15
+ })
16
+ }];
17
+ };
@@ -67,7 +67,7 @@ var SyncBlock = /*#__PURE__*/function (_ReactNodeView) {
67
67
  }
68
68
  // write data
69
69
  var node = convertSyncBlockPMNodeToSyncBlockData(this.node, false);
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
+ (_this$options = this.options) === null || _this$options === void 0 || (_this$options = _this$options.dataProvider) === null || _this$options === void 0 || _this$options.writeNodesData([node], [{
71
71
  content: updatedDoc.toJSON()
72
72
  }]);
73
73
  }
@@ -77,7 +77,7 @@ var SyncBlock = /*#__PURE__*/function (_ReactNodeView) {
77
77
  var _this$options2;
78
78
  // set inner editor view
79
79
  var nodes = [convertSyncBlockPMNodeToSyncBlockData(this.node, false)];
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
+ (_this$options2 = this.options) === null || _this$options2 === void 0 || (_this$options2 = _this$options2.dataProvider) === null || _this$options2 === void 0 || _this$options2.fetchNodesData(nodes).then(function (data) {
81
81
  var _data$;
82
82
  var tr = editorView.state.tr;
83
83
  if (data && (_data$ = data[0]) !== null && _data$ !== void 0 && _data$.content) {
@@ -127,7 +127,7 @@ var SyncBlock = /*#__PURE__*/function (_ReactNodeView) {
127
127
  return /*#__PURE__*/React.createElement(SyncBlockRendererWrapper, {
128
128
  useFetchDocNode: function useFetchDocNode() {
129
129
  var _this3$options;
130
- return _useFetchDocNode(_this3.view, _this3.node, defaultSyncBlockRendererDocument, (_this3$options = _this3.options) === null || _this3$options === void 0 ? void 0 : _this3$options.syncedBlockProvider);
130
+ return _useFetchDocNode(_this3.view, _this3.node, defaultSyncBlockRendererDocument, (_this3$options = _this3.options) === null || _this3$options === void 0 ? void 0 : _this3$options.dataProvider);
131
131
  },
132
132
  getSyncedBlockRenderer: (_this$options6 = this.options) === null || _this$options6 === void 0 ? void 0 : _this$options6.getSyncedBlockRenderer
133
133
  });
@@ -2,35 +2,28 @@ import _defineProperty from "@babel/runtime/helpers/defineProperty";
2
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
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; }
4
4
  import { INPUT_METHOD } from '@atlaskit/editor-common/analytics';
5
- import { insertSelectedItem } from '@atlaskit/editor-common/insert';
6
- import { createWrapSelectionTransaction } from '@atlaskit/editor-common/utils';
5
+ import { safeInsert } from '@atlaskit/editor-prosemirror/utils';
7
6
  import { generateSyncBlockSourceUrl } from '@atlaskit/editor-synced-block-provider';
8
7
  import { findSyncBlock } from './utils/utils';
9
- export var createSyncedBlock = function createSyncedBlock(typeAheadInsert, state, syncBlockStore) {
10
- var syncBlock = state.schema.nodes.syncBlock;
11
- var tr;
8
+ export var createSyncedBlock = function createSyncedBlock(tr, syncBlockStore, typeAheadInsert) {
9
+ var syncBlock = tr.doc.type.schema.nodes.syncBlock;
12
10
  var syncBlockNode = syncBlockStore.createSyncBlockNode();
13
11
 
14
12
  // If the selection is empty, we want to insert the panel on a new line
15
- if (state.selection.empty) {
13
+ if (tr.selection.empty) {
16
14
  var node = syncBlock.createAndFill(_objectSpread({}, syncBlockNode.attrs));
17
15
  if (!node) {
18
16
  return false;
19
17
  }
20
- if (typeAheadInsert !== undefined) {
21
- // If the type-ahead insert is provided, we should use that to insert the node
18
+ if (typeAheadInsert) {
22
19
  tr = typeAheadInsert(node);
23
20
  } 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();
21
+ tr = tr.replaceSelectionWith(node).scrollIntoView();
27
22
  }
28
23
  } else {
29
- tr = createWrapSelectionTransaction({
30
- state: state,
31
- type: syncBlock,
32
- nodeAttributes: _objectSpread({}, syncBlockNode.attrs)
33
- });
24
+ var _safeInsert;
25
+ // TODO: EDITOR-1653 - put selection inside the sync block if possible
26
+ (_safeInsert = safeInsert(syncBlock.createAndFill(syncBlockNode.attrs))(tr)) === null || _safeInsert === void 0 || _safeInsert.scrollIntoView();
34
27
  }
35
28
  return tr;
36
29
  };
@@ -5,12 +5,15 @@ import { IconSyncBlock } from '@atlaskit/editor-common/quick-insert';
5
5
  import { SyncBlockStoreManager } from '@atlaskit/editor-synced-block-provider';
6
6
  import { createSyncedBlock } from './pm-plugins/actions';
7
7
  import { createPlugin } from './pm-plugins/main';
8
+ import { getBlockMenuComponents } from './ui/block-menu-components';
8
9
  import { ContentComponent } from './ui/ContentComponent';
9
10
  import { getToolbarConfig } from './ui/floating-toolbar';
10
11
  export var syncedBlockPlugin = function syncedBlockPlugin(_ref) {
12
+ var _api$blockMenu;
11
13
  var config = _ref.config,
12
14
  api = _ref.api;
13
15
  var syncBlockStore = new SyncBlockStoreManager(config === null || config === void 0 ? void 0 : config.dataProvider);
16
+ api === null || api === void 0 || (_api$blockMenu = api.blockMenu) === null || _api$blockMenu === void 0 || _api$blockMenu.actions.registerBlockMenuComponents(getBlockMenuComponents(api));
14
17
  return {
15
18
  name: 'syncedBlock',
16
19
  nodes: function nodes() {
@@ -27,9 +30,17 @@ export var syncedBlockPlugin = function syncedBlockPlugin(_ref) {
27
30
  }
28
31
  }];
29
32
  },
33
+ commands: {
34
+ insertSyncedBlock: function insertSyncedBlock() {
35
+ return function (_ref2) {
36
+ var tr = _ref2.tr;
37
+ return createSyncedBlock(tr, syncBlockStore) || null;
38
+ };
39
+ }
40
+ },
30
41
  pluginsOptions: {
31
- quickInsert: function quickInsert(_ref2) {
32
- var formatMessage = _ref2.formatMessage;
42
+ quickInsert: function quickInsert(_ref3) {
43
+ var formatMessage = _ref3.formatMessage;
33
44
  return [{
34
45
  id: 'syncBlock',
35
46
  title: formatMessage(blockTypeMessages.syncedBlock),
@@ -43,7 +54,7 @@ export var syncedBlockPlugin = function syncedBlockPlugin(_ref) {
43
54
  });
44
55
  },
45
56
  action: function action(insert, state) {
46
- return createSyncedBlock(insert, state, syncBlockStore);
57
+ return createSyncedBlock(state.tr, syncBlockStore, insert);
47
58
  }
48
59
  }];
49
60
  },
@@ -0,0 +1,24 @@
1
+ import React from 'react';
2
+ import { useIntl } from 'react-intl-next';
3
+ import { blockMenuMessages } from '@atlaskit/editor-common/messages';
4
+ import { SyncBlocksIcon, ToolbarDropdownItem } from '@atlaskit/editor-toolbar';
5
+ export var CreateSyncedBlockDropdownItem = function CreateSyncedBlockDropdownItem(_ref) {
6
+ var _api$selection;
7
+ var api = _ref.api;
8
+ var _useIntl = useIntl(),
9
+ formatMessage = _useIntl.formatMessage;
10
+ var selection = api === null || api === void 0 || (_api$selection = api.selection) === null || _api$selection === void 0 || (_api$selection = _api$selection.sharedState) === null || _api$selection === void 0 || (_api$selection = _api$selection.currentState()) === null || _api$selection === void 0 ? void 0 : _api$selection.selection;
11
+ if (!(selection !== null && selection !== void 0 && selection.empty)) {
12
+ return null;
13
+ }
14
+ var onClick = function onClick() {
15
+ var _api$core;
16
+ api === null || api === void 0 || (_api$core = api.core) === null || _api$core === void 0 || _api$core.actions.execute(api === null || api === void 0 ? void 0 : api.syncedBlock.commands.insertSyncedBlock());
17
+ };
18
+ return /*#__PURE__*/React.createElement(ToolbarDropdownItem, {
19
+ elemBefore: /*#__PURE__*/React.createElement(SyncBlocksIcon, {
20
+ label: ""
21
+ }),
22
+ onClick: onClick
23
+ }, formatMessage(blockMenuMessages.createSyncedBlock));
24
+ };
@@ -0,0 +1,19 @@
1
+ import React from 'react';
2
+ import { ADD_BLOCKS_MENU_SECTION, ADD_BLOCKS_MENU_SECTION_RANK, CREATE_SYNCED_BLOCK_MENU_ITEM } from '@atlaskit/editor-common/block-menu';
3
+ import { CreateSyncedBlockDropdownItem } from './CreateSyncedBlockDropdownItem';
4
+ export var getBlockMenuComponents = function getBlockMenuComponents(api) {
5
+ return [{
6
+ type: 'block-menu-item',
7
+ key: CREATE_SYNCED_BLOCK_MENU_ITEM.key,
8
+ parent: {
9
+ type: 'block-menu-section',
10
+ key: ADD_BLOCKS_MENU_SECTION.key,
11
+ rank: ADD_BLOCKS_MENU_SECTION_RANK[CREATE_SYNCED_BLOCK_MENU_ITEM.key]
12
+ },
13
+ component: function component() {
14
+ return /*#__PURE__*/React.createElement(CreateSyncedBlockDropdownItem, {
15
+ api: api
16
+ });
17
+ }
18
+ }];
19
+ };
@@ -1,8 +1,8 @@
1
1
  import type { Command, ExtractInjectionAPI, TypeAheadInsert } from '@atlaskit/editor-common/types';
2
- import { type EditorState, type Transaction } from '@atlaskit/editor-prosemirror/state';
2
+ import { type Transaction } from '@atlaskit/editor-prosemirror/state';
3
3
  import type { SyncBlockStoreManager } from '@atlaskit/editor-synced-block-provider';
4
4
  import type { SyncedBlockPlugin } from '../syncedBlockPluginType';
5
- export declare const createSyncedBlock: (typeAheadInsert: TypeAheadInsert, state: EditorState, syncBlockStore: SyncBlockStoreManager) => false | Transaction;
5
+ export declare const createSyncedBlock: (tr: Transaction, syncBlockStore: SyncBlockStoreManager, typeAheadInsert?: TypeAheadInsert) => false | Transaction;
6
6
  export declare const copySyncedBlockReferenceToClipboard: (api?: ExtractInjectionAPI<SyncedBlockPlugin>) => Command;
7
7
  export declare const editSyncedBlockSource: (_api?: ExtractInjectionAPI<SyncedBlockPlugin>) => Command;
8
8
  export declare const removeSyncedBlock: (api?: ExtractInjectionAPI<SyncedBlockPlugin>) => Command;
@@ -1,12 +1,13 @@
1
1
  import type { DocNode } from '@atlaskit/adf-schema';
2
2
  import type { EventDispatcher } from '@atlaskit/editor-common/event-dispatcher';
3
- import type { NextEditorPlugin } from '@atlaskit/editor-common/types';
3
+ import type { EditorCommand, NextEditorPlugin, OptionalPlugin } from '@atlaskit/editor-common/types';
4
4
  import type { JSONDocNode } from '@atlaskit/editor-json-transformer';
5
+ import type { BlockMenuPlugin } from '@atlaskit/editor-plugin-block-menu';
5
6
  import type { DecorationsPlugin } from '@atlaskit/editor-plugin-decorations';
6
7
  import type { FloatingToolbarPlugin } from '@atlaskit/editor-plugin-floating-toolbar';
7
8
  import type { SelectionPlugin } from '@atlaskit/editor-plugin-selection';
8
9
  import type { EditorView } from '@atlaskit/editor-prosemirror/dist/types/view';
9
- import type { SyncBlockDataProvider, SyncedBlockProvider } from '@atlaskit/editor-synced-block-provider';
10
+ import type { SyncBlockDataProvider } from '@atlaskit/editor-synced-block-provider';
10
11
  export type SyncedBlockEditorProps = {
11
12
  defaultDocument: JSONDocNode;
12
13
  onChange: (editorView: EditorView, meta: {
@@ -36,10 +37,17 @@ export type SyncedBlockPluginOptions = {
36
37
  dataProvider?: SyncBlockDataProvider;
37
38
  getSyncedBlockEditor?: (props: SyncedBlockEditorProps) => React.JSX.Element;
38
39
  getSyncedBlockRenderer?: (props: SyncedBlockRendererProps) => React.JSX.Element;
39
- syncedBlockProvider?: SyncedBlockProvider;
40
40
  };
41
41
  export type SyncedBlockPlugin = NextEditorPlugin<'syncedBlock', {
42
- dependencies: [SelectionPlugin, FloatingToolbarPlugin, DecorationsPlugin];
42
+ commands: {
43
+ insertSyncedBlock: () => EditorCommand;
44
+ };
45
+ dependencies: [
46
+ SelectionPlugin,
47
+ FloatingToolbarPlugin,
48
+ DecorationsPlugin,
49
+ OptionalPlugin<BlockMenuPlugin>
50
+ ];
43
51
  pluginConfiguration: SyncedBlockPluginOptions | undefined;
44
52
  }>;
45
53
  export type SyncBlockAttrs = {
@@ -0,0 +1,6 @@
1
+ import React from 'react';
2
+ import type { ExtractInjectionAPI } from '@atlaskit/editor-common/types';
3
+ import type { SyncedBlockPlugin } from '../syncedBlockPluginType';
4
+ export declare const CreateSyncedBlockDropdownItem: ({ api }: {
5
+ api: ExtractInjectionAPI<SyncedBlockPlugin> | undefined;
6
+ }) => React.JSX.Element | null;
@@ -0,0 +1,4 @@
1
+ import type { ExtractInjectionAPI } from '@atlaskit/editor-common/types';
2
+ import type { RegisterBlockMenuComponent } from '@atlaskit/editor-plugin-block-menu';
3
+ import type { SyncedBlockPlugin } from '../syncedBlockPluginType';
4
+ export declare const getBlockMenuComponents: (api: ExtractInjectionAPI<SyncedBlockPlugin> | undefined) => RegisterBlockMenuComponent[];
@@ -1,8 +1,8 @@
1
1
  import type { Command, ExtractInjectionAPI, TypeAheadInsert } from '@atlaskit/editor-common/types';
2
- import { type EditorState, type Transaction } from '@atlaskit/editor-prosemirror/state';
2
+ import { type Transaction } from '@atlaskit/editor-prosemirror/state';
3
3
  import type { SyncBlockStoreManager } from '@atlaskit/editor-synced-block-provider';
4
4
  import type { SyncedBlockPlugin } from '../syncedBlockPluginType';
5
- export declare const createSyncedBlock: (typeAheadInsert: TypeAheadInsert, state: EditorState, syncBlockStore: SyncBlockStoreManager) => false | Transaction;
5
+ export declare const createSyncedBlock: (tr: Transaction, syncBlockStore: SyncBlockStoreManager, typeAheadInsert?: TypeAheadInsert) => false | Transaction;
6
6
  export declare const copySyncedBlockReferenceToClipboard: (api?: ExtractInjectionAPI<SyncedBlockPlugin>) => Command;
7
7
  export declare const editSyncedBlockSource: (_api?: ExtractInjectionAPI<SyncedBlockPlugin>) => Command;
8
8
  export declare const removeSyncedBlock: (api?: ExtractInjectionAPI<SyncedBlockPlugin>) => Command;
@@ -1,12 +1,13 @@
1
1
  import type { DocNode } from '@atlaskit/adf-schema';
2
2
  import type { EventDispatcher } from '@atlaskit/editor-common/event-dispatcher';
3
- import type { NextEditorPlugin } from '@atlaskit/editor-common/types';
3
+ import type { EditorCommand, NextEditorPlugin, OptionalPlugin } from '@atlaskit/editor-common/types';
4
4
  import type { JSONDocNode } from '@atlaskit/editor-json-transformer';
5
+ import type { BlockMenuPlugin } from '@atlaskit/editor-plugin-block-menu';
5
6
  import type { DecorationsPlugin } from '@atlaskit/editor-plugin-decorations';
6
7
  import type { FloatingToolbarPlugin } from '@atlaskit/editor-plugin-floating-toolbar';
7
8
  import type { SelectionPlugin } from '@atlaskit/editor-plugin-selection';
8
9
  import type { EditorView } from '@atlaskit/editor-prosemirror/dist/types/view';
9
- import type { SyncBlockDataProvider, SyncedBlockProvider } from '@atlaskit/editor-synced-block-provider';
10
+ import type { SyncBlockDataProvider } from '@atlaskit/editor-synced-block-provider';
10
11
  export type SyncedBlockEditorProps = {
11
12
  defaultDocument: JSONDocNode;
12
13
  onChange: (editorView: EditorView, meta: {
@@ -36,13 +37,16 @@ export type SyncedBlockPluginOptions = {
36
37
  dataProvider?: SyncBlockDataProvider;
37
38
  getSyncedBlockEditor?: (props: SyncedBlockEditorProps) => React.JSX.Element;
38
39
  getSyncedBlockRenderer?: (props: SyncedBlockRendererProps) => React.JSX.Element;
39
- syncedBlockProvider?: SyncedBlockProvider;
40
40
  };
41
41
  export type SyncedBlockPlugin = NextEditorPlugin<'syncedBlock', {
42
+ commands: {
43
+ insertSyncedBlock: () => EditorCommand;
44
+ };
42
45
  dependencies: [
43
46
  SelectionPlugin,
44
47
  FloatingToolbarPlugin,
45
- DecorationsPlugin
48
+ DecorationsPlugin,
49
+ OptionalPlugin<BlockMenuPlugin>
46
50
  ];
47
51
  pluginConfiguration: SyncedBlockPluginOptions | undefined;
48
52
  }>;
@@ -0,0 +1,6 @@
1
+ import React from 'react';
2
+ import type { ExtractInjectionAPI } from '@atlaskit/editor-common/types';
3
+ import type { SyncedBlockPlugin } from '../syncedBlockPluginType';
4
+ export declare const CreateSyncedBlockDropdownItem: ({ api }: {
5
+ api: ExtractInjectionAPI<SyncedBlockPlugin> | undefined;
6
+ }) => React.JSX.Element | null;
@@ -0,0 +1,4 @@
1
+ import type { ExtractInjectionAPI } from '@atlaskit/editor-common/types';
2
+ import type { RegisterBlockMenuComponent } from '@atlaskit/editor-plugin-block-menu';
3
+ import type { SyncedBlockPlugin } from '../syncedBlockPluginType';
4
+ export declare const getBlockMenuComponents: (api: ExtractInjectionAPI<SyncedBlockPlugin> | undefined) => RegisterBlockMenuComponent[];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atlaskit/editor-plugin-synced-block",
3
- "version": "3.0.6",
3
+ "version": "3.1.1",
4
4
  "description": "SyncedBlock plugin for @atlaskit/editor-core",
5
5
  "author": "Atlassian Pty Ltd",
6
6
  "license": "Apache-2.0",
@@ -30,13 +30,15 @@
30
30
  "dependencies": {
31
31
  "@atlaskit/adf-schema": "^51.2.0",
32
32
  "@atlaskit/button": "23.5.0",
33
+ "@atlaskit/editor-plugin-block-menu": "^4.0.0",
33
34
  "@atlaskit/editor-plugin-decorations": "^6.1.0",
34
- "@atlaskit/editor-plugin-floating-toolbar": "^8.1.0",
35
+ "@atlaskit/editor-plugin-floating-toolbar": "^8.2.0",
35
36
  "@atlaskit/editor-plugin-selection": "^6.0.0",
36
37
  "@atlaskit/editor-prosemirror": "7.0.0",
37
38
  "@atlaskit/editor-shared-styles": "^3.6.0",
38
- "@atlaskit/editor-synced-block-provider": "^0.2.0",
39
- "@atlaskit/icon": "28.3.0",
39
+ "@atlaskit/editor-synced-block-provider": "^0.3.0",
40
+ "@atlaskit/editor-toolbar": "^0.13.0",
41
+ "@atlaskit/icon": "28.4.0",
40
42
  "@atlaskit/modal-dialog": "^14.4.0",
41
43
  "@babel/runtime": "^7.0.0",
42
44
  "react-intl-next": "npm:react-intl@^5.18.1"