@atlaskit/editor-plugin-synced-block 3.1.0 → 3.1.2

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,19 @@
1
1
  # @atlaskit/editor-plugin-synced-block
2
2
 
3
+ ## 3.1.2
4
+
5
+ ### Patch Changes
6
+
7
+ - Updated dependencies
8
+
9
+ ## 3.1.1
10
+
11
+ ### Patch Changes
12
+
13
+ - [`7011f9be6a430`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/7011f9be6a430) -
14
+ [ux] EDITOR-1653 add create synced block item to the block menu
15
+ - Updated dependencies
16
+
3
17
  ## 3.1.0
4
18
 
5
19
  ### Minor 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
  },
@@ -25,6 +25,9 @@
25
25
  {
26
26
  "path": "../../../design-system/button/afm-dev-agents/tsconfig.json"
27
27
  },
28
+ {
29
+ "path": "../../editor-plugin-block-menu/afm-dev-agents/tsconfig.json"
30
+ },
28
31
  {
29
32
  "path": "../../editor-plugin-decorations/afm-dev-agents/tsconfig.json"
30
33
  },
@@ -40,6 +43,9 @@
40
43
  {
41
44
  "path": "../../editor-synced-block-provider/afm-dev-agents/tsconfig.json"
42
45
  },
46
+ {
47
+ "path": "../../editor-toolbar/afm-dev-agents/tsconfig.json"
48
+ },
43
49
  {
44
50
  "path": "../../../design-system/icon/afm-dev-agents/tsconfig.json"
45
51
  },
@@ -25,6 +25,9 @@
25
25
  {
26
26
  "path": "../../../design-system/button/afm-jira/tsconfig.json"
27
27
  },
28
+ {
29
+ "path": "../../editor-plugin-block-menu/afm-jira/tsconfig.json"
30
+ },
28
31
  {
29
32
  "path": "../../editor-plugin-decorations/afm-jira/tsconfig.json"
30
33
  },
@@ -40,6 +43,9 @@
40
43
  {
41
44
  "path": "../../editor-synced-block-provider/afm-jira/tsconfig.json"
42
45
  },
46
+ {
47
+ "path": "../../editor-toolbar/afm-jira/tsconfig.json"
48
+ },
43
49
  {
44
50
  "path": "../../../design-system/icon/afm-jira/tsconfig.json"
45
51
  },
@@ -25,6 +25,9 @@
25
25
  {
26
26
  "path": "../../../design-system/button/afm-passionfruit/tsconfig.json"
27
27
  },
28
+ {
29
+ "path": "../../editor-plugin-block-menu/afm-passionfruit/tsconfig.json"
30
+ },
28
31
  {
29
32
  "path": "../../editor-plugin-decorations/afm-passionfruit/tsconfig.json"
30
33
  },
@@ -40,6 +43,9 @@
40
43
  {
41
44
  "path": "../../editor-synced-block-provider/afm-passionfruit/tsconfig.json"
42
45
  },
46
+ {
47
+ "path": "../../editor-toolbar/afm-passionfruit/tsconfig.json"
48
+ },
43
49
  {
44
50
  "path": "../../../design-system/icon/afm-passionfruit/tsconfig.json"
45
51
  },
@@ -25,6 +25,9 @@
25
25
  {
26
26
  "path": "../../../design-system/button/afm-post-office/tsconfig.json"
27
27
  },
28
+ {
29
+ "path": "../../editor-plugin-block-menu/afm-post-office/tsconfig.json"
30
+ },
28
31
  {
29
32
  "path": "../../editor-plugin-decorations/afm-post-office/tsconfig.json"
30
33
  },
@@ -40,6 +43,9 @@
40
43
  {
41
44
  "path": "../../editor-synced-block-provider/afm-post-office/tsconfig.json"
42
45
  },
46
+ {
47
+ "path": "../../editor-toolbar/afm-post-office/tsconfig.json"
48
+ },
43
49
  {
44
50
  "path": "../../../design-system/icon/afm-post-office/tsconfig.json"
45
51
  },
@@ -25,6 +25,9 @@
25
25
  {
26
26
  "path": "../../../design-system/button/afm-rovo-extension/tsconfig.json"
27
27
  },
28
+ {
29
+ "path": "../../editor-plugin-block-menu/afm-rovo-extension/tsconfig.json"
30
+ },
28
31
  {
29
32
  "path": "../../editor-plugin-decorations/afm-rovo-extension/tsconfig.json"
30
33
  },
@@ -40,6 +43,9 @@
40
43
  {
41
44
  "path": "../../editor-synced-block-provider/afm-rovo-extension/tsconfig.json"
42
45
  },
46
+ {
47
+ "path": "../../editor-toolbar/afm-rovo-extension/tsconfig.json"
48
+ },
43
49
  {
44
50
  "path": "../../../design-system/icon/afm-rovo-extension/tsconfig.json"
45
51
  },
@@ -25,6 +25,9 @@
25
25
  {
26
26
  "path": "../../../design-system/button/afm-townsquare/tsconfig.json"
27
27
  },
28
+ {
29
+ "path": "../../editor-plugin-block-menu/afm-townsquare/tsconfig.json"
30
+ },
28
31
  {
29
32
  "path": "../../editor-plugin-decorations/afm-townsquare/tsconfig.json"
30
33
  },
@@ -40,6 +43,9 @@
40
43
  {
41
44
  "path": "../../editor-synced-block-provider/afm-townsquare/tsconfig.json"
42
45
  },
46
+ {
47
+ "path": "../../editor-toolbar/afm-townsquare/tsconfig.json"
48
+ },
43
49
  {
44
50
  "path": "../../../design-system/icon/afm-townsquare/tsconfig.json"
45
51
  },
@@ -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
+ };
@@ -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
+ };
@@ -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,7 +1,8 @@
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';
@@ -38,7 +39,15 @@ export type SyncedBlockPluginOptions = {
38
39
  getSyncedBlockRenderer?: (props: SyncedBlockRendererProps) => React.JSX.Element;
39
40
  };
40
41
  export type SyncedBlockPlugin = NextEditorPlugin<'syncedBlock', {
41
- dependencies: [SelectionPlugin, FloatingToolbarPlugin, DecorationsPlugin];
42
+ commands: {
43
+ insertSyncedBlock: () => EditorCommand;
44
+ };
45
+ dependencies: [
46
+ SelectionPlugin,
47
+ FloatingToolbarPlugin,
48
+ DecorationsPlugin,
49
+ OptionalPlugin<BlockMenuPlugin>
50
+ ];
42
51
  pluginConfiguration: SyncedBlockPluginOptions | undefined;
43
52
  }>;
44
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,7 +1,8 @@
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';
@@ -38,10 +39,14 @@ export type SyncedBlockPluginOptions = {
38
39
  getSyncedBlockRenderer?: (props: SyncedBlockRendererProps) => React.JSX.Element;
39
40
  };
40
41
  export type SyncedBlockPlugin = NextEditorPlugin<'syncedBlock', {
42
+ commands: {
43
+ insertSyncedBlock: () => EditorCommand;
44
+ };
41
45
  dependencies: [
42
46
  SelectionPlugin,
43
47
  FloatingToolbarPlugin,
44
- DecorationsPlugin
48
+ DecorationsPlugin,
49
+ OptionalPlugin<BlockMenuPlugin>
45
50
  ];
46
51
  pluginConfiguration: SyncedBlockPluginOptions | undefined;
47
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.1.0",
3
+ "version": "3.1.2",
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
39
  "@atlaskit/editor-synced-block-provider": "^0.3.0",
39
- "@atlaskit/icon": "28.3.0",
40
+ "@atlaskit/editor-toolbar": "^0.14.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"