@atlaskit/editor-plugin-synced-block 4.1.3 → 4.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +17 -0
- package/afm-cc/tsconfig.json +3 -0
- package/dist/cjs/syncedBlockPlugin.js +3 -1
- package/dist/cjs/ui/CreateSyncedBlockButton.js +51 -0
- package/dist/cjs/ui/CreateSyncedBlockItem.js +43 -0
- package/dist/cjs/ui/toolbar-components.js +58 -0
- package/dist/es2019/syncedBlockPlugin.js +3 -1
- package/dist/es2019/ui/CreateSyncedBlockButton.js +42 -0
- package/dist/es2019/ui/CreateSyncedBlockItem.js +34 -0
- package/dist/es2019/ui/toolbar-components.js +49 -0
- package/dist/esm/syncedBlockPlugin.js +3 -1
- package/dist/esm/ui/CreateSyncedBlockButton.js +42 -0
- package/dist/esm/ui/CreateSyncedBlockItem.js +34 -0
- package/dist/esm/ui/toolbar-components.js +51 -0
- package/dist/types/syncedBlockPluginType.d.ts +3 -1
- package/dist/types/ui/CreateSyncedBlockButton.d.ts +8 -0
- package/dist/types/ui/CreateSyncedBlockItem.d.ts +8 -0
- package/dist/types/ui/toolbar-components.d.ts +4 -0
- package/dist/types-ts4.5/syncedBlockPluginType.d.ts +3 -1
- package/dist/types-ts4.5/ui/CreateSyncedBlockButton.d.ts +8 -0
- package/dist/types-ts4.5/ui/CreateSyncedBlockItem.d.ts +8 -0
- package/dist/types-ts4.5/ui/toolbar-components.d.ts +4 -0
- package/package.json +7 -6
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,22 @@
|
|
|
1
1
|
# @atlaskit/editor-plugin-synced-block
|
|
2
2
|
|
|
3
|
+
## 4.2.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- [`cd4d309562a37`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/cd4d309562a37) -
|
|
8
|
+
EDITOR-2534 add sync-block toolbar option
|
|
9
|
+
|
|
10
|
+
### Patch Changes
|
|
11
|
+
|
|
12
|
+
- Updated dependencies
|
|
13
|
+
|
|
14
|
+
## 4.1.4
|
|
15
|
+
|
|
16
|
+
### Patch Changes
|
|
17
|
+
|
|
18
|
+
- Updated dependencies
|
|
19
|
+
|
|
3
20
|
## 4.1.3
|
|
4
21
|
|
|
5
22
|
### Patch Changes
|
package/afm-cc/tsconfig.json
CHANGED
|
@@ -17,12 +17,14 @@ var _blockMenuComponents = require("./ui/block-menu-components");
|
|
|
17
17
|
var _DeleteConfirmationModal = require("./ui/DeleteConfirmationModal");
|
|
18
18
|
var _floatingToolbar = require("./ui/floating-toolbar");
|
|
19
19
|
var _SyncBlockRefresher = require("./ui/SyncBlockRefresher");
|
|
20
|
+
var _toolbarComponents = require("./ui/toolbar-components");
|
|
20
21
|
var syncedBlockPlugin = exports.syncedBlockPlugin = function syncedBlockPlugin(_ref) {
|
|
21
|
-
var _api$blockMenu;
|
|
22
|
+
var _api$blockMenu, _api$toolbar;
|
|
22
23
|
var config = _ref.config,
|
|
23
24
|
api = _ref.api;
|
|
24
25
|
var syncBlockStore = new _editorSyncedBlockProvider.SyncBlockStoreManager(config === null || config === void 0 ? void 0 : config.syncBlockDataProvider);
|
|
25
26
|
api === null || api === void 0 || (_api$blockMenu = api.blockMenu) === null || _api$blockMenu === void 0 || _api$blockMenu.actions.registerBlockMenuComponents((0, _blockMenuComponents.getBlockMenuComponents)(api));
|
|
27
|
+
api === null || api === void 0 || (_api$toolbar = api.toolbar) === null || _api$toolbar === void 0 || _api$toolbar.actions.registerComponents((0, _toolbarComponents.getToolbarComponents)(api));
|
|
26
28
|
return {
|
|
27
29
|
name: 'syncedBlock',
|
|
28
30
|
nodes: function nodes() {
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
+
var _typeof = require("@babel/runtime/helpers/typeof");
|
|
5
|
+
Object.defineProperty(exports, "__esModule", {
|
|
6
|
+
value: true
|
|
7
|
+
});
|
|
8
|
+
exports.CreateSyncedBlockButton = void 0;
|
|
9
|
+
var _react = _interopRequireWildcard(require("react"));
|
|
10
|
+
var _reactIntlNext = require("react-intl-next");
|
|
11
|
+
var _hooks = require("@atlaskit/editor-common/hooks");
|
|
12
|
+
var _messages = require("@atlaskit/editor-common/messages");
|
|
13
|
+
var _editorToolbar = require("@atlaskit/editor-toolbar");
|
|
14
|
+
var _blockSynced = _interopRequireDefault(require("@atlaskit/icon-lab/core/block-synced"));
|
|
15
|
+
var _utils = require("../pm-plugins/utils/utils");
|
|
16
|
+
function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function _interopRequireWildcard(e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, default: e }; if (null === e || "object" != _typeof(e) && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (var _t in e) "default" !== _t && {}.hasOwnProperty.call(e, _t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, _t)) && (i.get || i.set) ? o(f, _t, i) : f[_t] = e[_t]); return f; })(e, t); }
|
|
17
|
+
var CreateSyncedBlockButton = exports.CreateSyncedBlockButton = function CreateSyncedBlockButton(_ref) {
|
|
18
|
+
var api = _ref.api;
|
|
19
|
+
var intl = (0, _reactIntlNext.useIntl)();
|
|
20
|
+
var selection = (0, _hooks.useSharedPluginStateWithSelector)(api, ['selection'], function (states) {
|
|
21
|
+
var _states$selectionStat;
|
|
22
|
+
return (_states$selectionStat = states.selectionState) === null || _states$selectionStat === void 0 ? void 0 : _states$selectionStat.selection;
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
// for toolbar button, we allow both creating a new synced block
|
|
26
|
+
// and converting existing block to synced block
|
|
27
|
+
var canBeConverted = Boolean(selection && (0, _utils.canBeConvertedToSyncBlock)(selection));
|
|
28
|
+
var canInsertEmptyBlock = Boolean(selection === null || selection === void 0 ? void 0 : selection.empty);
|
|
29
|
+
var isDisabled = Boolean(!canBeConverted && !canInsertEmptyBlock);
|
|
30
|
+
var onClick = (0, _react.useCallback)(function () {
|
|
31
|
+
var _api$core, _api$core2;
|
|
32
|
+
api === null || api === void 0 || (_api$core = api.core) === null || _api$core === void 0 || _api$core.actions.execute(function (_ref2) {
|
|
33
|
+
var tr = _ref2.tr;
|
|
34
|
+
return api === null || api === void 0 ? void 0 : api.syncedBlock.commands.insertSyncedBlock()({
|
|
35
|
+
tr: tr
|
|
36
|
+
});
|
|
37
|
+
});
|
|
38
|
+
api === null || api === void 0 || (_api$core2 = api.core) === null || _api$core2 === void 0 || _api$core2.actions.focus();
|
|
39
|
+
}, [api]);
|
|
40
|
+
var message = intl.formatMessage(_messages.syncBlockMessages.createSyncBlockLabel);
|
|
41
|
+
return /*#__PURE__*/_react.default.createElement(_editorToolbar.ToolbarTooltip, {
|
|
42
|
+
content: message
|
|
43
|
+
}, /*#__PURE__*/_react.default.createElement(_editorToolbar.ToolbarButton, {
|
|
44
|
+
label: message,
|
|
45
|
+
iconBefore: /*#__PURE__*/_react.default.createElement(_blockSynced.default, {
|
|
46
|
+
label: ""
|
|
47
|
+
}),
|
|
48
|
+
isDisabled: isDisabled,
|
|
49
|
+
onClick: onClick
|
|
50
|
+
}));
|
|
51
|
+
};
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
+
var _typeof = require("@babel/runtime/helpers/typeof");
|
|
5
|
+
Object.defineProperty(exports, "__esModule", {
|
|
6
|
+
value: true
|
|
7
|
+
});
|
|
8
|
+
exports.CreateSyncedBlockItem = void 0;
|
|
9
|
+
var _react = _interopRequireWildcard(require("react"));
|
|
10
|
+
var _reactIntlNext = require("react-intl-next");
|
|
11
|
+
var _hooks = require("@atlaskit/editor-common/hooks");
|
|
12
|
+
var _messages = require("@atlaskit/editor-common/messages");
|
|
13
|
+
var _editorToolbar = require("@atlaskit/editor-toolbar");
|
|
14
|
+
var _blockSynced = _interopRequireDefault(require("@atlaskit/icon-lab/core/block-synced"));
|
|
15
|
+
var _utils = require("../pm-plugins/utils/utils");
|
|
16
|
+
function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function _interopRequireWildcard(e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, default: e }; if (null === e || "object" != _typeof(e) && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (var _t in e) "default" !== _t && {}.hasOwnProperty.call(e, _t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, _t)) && (i.get || i.set) ? o(f, _t, i) : f[_t] = e[_t]); return f; })(e, t); }
|
|
17
|
+
var CreateSyncedBlockItem = exports.CreateSyncedBlockItem = function CreateSyncedBlockItem(_ref) {
|
|
18
|
+
var api = _ref.api;
|
|
19
|
+
var intl = (0, _reactIntlNext.useIntl)();
|
|
20
|
+
var selection = (0, _hooks.useSharedPluginStateWithSelector)(api, ['selection'], function (states) {
|
|
21
|
+
var _states$selectionStat;
|
|
22
|
+
return (_states$selectionStat = states.selectionState) === null || _states$selectionStat === void 0 ? void 0 : _states$selectionStat.selection;
|
|
23
|
+
});
|
|
24
|
+
var isDisabled = Boolean(!selection || !(0, _utils.canBeConvertedToSyncBlock)(selection));
|
|
25
|
+
var onClick = (0, _react.useCallback)(function () {
|
|
26
|
+
var _api$core, _api$core2;
|
|
27
|
+
api === null || api === void 0 || (_api$core = api.core) === null || _api$core === void 0 || _api$core.actions.execute(function (_ref2) {
|
|
28
|
+
var tr = _ref2.tr;
|
|
29
|
+
return api === null || api === void 0 ? void 0 : api.syncedBlock.commands.insertSyncedBlock()({
|
|
30
|
+
tr: tr
|
|
31
|
+
});
|
|
32
|
+
});
|
|
33
|
+
api === null || api === void 0 || (_api$core2 = api.core) === null || _api$core2 === void 0 || _api$core2.actions.focus();
|
|
34
|
+
}, [api]);
|
|
35
|
+
var message = intl.formatMessage(_messages.syncBlockMessages.createSyncBlockLabel);
|
|
36
|
+
return /*#__PURE__*/_react.default.createElement(_editorToolbar.ToolbarDropdownItem, {
|
|
37
|
+
onClick: onClick,
|
|
38
|
+
isDisabled: isDisabled,
|
|
39
|
+
elemBefore: /*#__PURE__*/_react.default.createElement(_blockSynced.default, {
|
|
40
|
+
label: ""
|
|
41
|
+
})
|
|
42
|
+
}, message);
|
|
43
|
+
};
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
+
Object.defineProperty(exports, "__esModule", {
|
|
5
|
+
value: true
|
|
6
|
+
});
|
|
7
|
+
exports.getToolbarComponents = void 0;
|
|
8
|
+
var _react = _interopRequireDefault(require("react"));
|
|
9
|
+
var _toolbar = require("@atlaskit/editor-common/toolbar");
|
|
10
|
+
var _CreateSyncedBlockButton = require("./CreateSyncedBlockButton");
|
|
11
|
+
var _CreateSyncedBlockItem = require("./CreateSyncedBlockItem");
|
|
12
|
+
var SYNCED_BLOCK_OVERFLOW_MENU_SECTION = {
|
|
13
|
+
type: _toolbar.SYNCED_BLOCK_SECTION.type,
|
|
14
|
+
key: _toolbar.SYNCED_BLOCK_SECTION.key,
|
|
15
|
+
parents: [{
|
|
16
|
+
type: _toolbar.OVERFLOW_MENU.type,
|
|
17
|
+
key: _toolbar.OVERFLOW_MENU.key,
|
|
18
|
+
rank: _toolbar.OVERFLOW_MENU_RANK[_toolbar.SYNCED_BLOCK_SECTION.key]
|
|
19
|
+
}]
|
|
20
|
+
};
|
|
21
|
+
var SYNCED_BLOCK_PRIMARY_TOOLBAR_GROUP = {
|
|
22
|
+
type: _toolbar.SYNCED_BLOCK_GROUP.type,
|
|
23
|
+
key: _toolbar.SYNCED_BLOCK_GROUP.key,
|
|
24
|
+
parents: [{
|
|
25
|
+
type: _toolbar.INSERT_BLOCK_SECTION.type,
|
|
26
|
+
key: _toolbar.INSERT_BLOCK_SECTION.key,
|
|
27
|
+
rank: _toolbar.INSERT_BLOCK_SECTION_RANK[_toolbar.SYNCED_BLOCK_GROUP.key]
|
|
28
|
+
}]
|
|
29
|
+
};
|
|
30
|
+
var getToolbarComponents = exports.getToolbarComponents = function getToolbarComponents(api) {
|
|
31
|
+
return [SYNCED_BLOCK_PRIMARY_TOOLBAR_GROUP, SYNCED_BLOCK_OVERFLOW_MENU_SECTION, {
|
|
32
|
+
type: _toolbar.SYNCED_BLOCK_BUTTON.type,
|
|
33
|
+
key: _toolbar.SYNCED_BLOCK_BUTTON.key,
|
|
34
|
+
component: function component() {
|
|
35
|
+
return /*#__PURE__*/_react.default.createElement(_CreateSyncedBlockButton.CreateSyncedBlockButton, {
|
|
36
|
+
api: api
|
|
37
|
+
});
|
|
38
|
+
},
|
|
39
|
+
parents: [{
|
|
40
|
+
type: _toolbar.SYNCED_BLOCK_GROUP.type,
|
|
41
|
+
key: _toolbar.SYNCED_BLOCK_GROUP.key,
|
|
42
|
+
rank: _toolbar.SYNCED_BLOCK_SECTION_RANK[_toolbar.SYNCED_BLOCK_BUTTON.key]
|
|
43
|
+
}]
|
|
44
|
+
}, {
|
|
45
|
+
type: _toolbar.SYNCED_BLOCK_ITEM.type,
|
|
46
|
+
key: _toolbar.SYNCED_BLOCK_ITEM.key,
|
|
47
|
+
parents: [{
|
|
48
|
+
type: _toolbar.SYNCED_BLOCK_SECTION.type,
|
|
49
|
+
key: _toolbar.SYNCED_BLOCK_SECTION.key,
|
|
50
|
+
rank: _toolbar.SYNCED_BLOCK_SECTION_RANK[_toolbar.SYNCED_BLOCK_ITEM.key]
|
|
51
|
+
}],
|
|
52
|
+
component: function component() {
|
|
53
|
+
return /*#__PURE__*/_react.default.createElement(_CreateSyncedBlockItem.CreateSyncedBlockItem, {
|
|
54
|
+
api: api
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
}];
|
|
58
|
+
};
|
|
@@ -10,13 +10,15 @@ import { getBlockMenuComponents } from './ui/block-menu-components';
|
|
|
10
10
|
import { DeleteConfirmationModal } from './ui/DeleteConfirmationModal';
|
|
11
11
|
import { getToolbarConfig } from './ui/floating-toolbar';
|
|
12
12
|
import { SyncBlockRefresher } from './ui/SyncBlockRefresher';
|
|
13
|
+
import { getToolbarComponents } from './ui/toolbar-components';
|
|
13
14
|
export const syncedBlockPlugin = ({
|
|
14
15
|
config,
|
|
15
16
|
api
|
|
16
17
|
}) => {
|
|
17
|
-
var _api$blockMenu;
|
|
18
|
+
var _api$blockMenu, _api$toolbar;
|
|
18
19
|
const syncBlockStore = new SyncBlockStoreManager(config === null || config === void 0 ? void 0 : config.syncBlockDataProvider);
|
|
19
20
|
api === null || api === void 0 ? void 0 : (_api$blockMenu = api.blockMenu) === null || _api$blockMenu === void 0 ? void 0 : _api$blockMenu.actions.registerBlockMenuComponents(getBlockMenuComponents(api));
|
|
21
|
+
api === null || api === void 0 ? void 0 : (_api$toolbar = api.toolbar) === null || _api$toolbar === void 0 ? void 0 : _api$toolbar.actions.registerComponents(getToolbarComponents(api));
|
|
20
22
|
return {
|
|
21
23
|
name: 'syncedBlock',
|
|
22
24
|
nodes() {
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import React, { useCallback } from 'react';
|
|
2
|
+
import { useIntl } from 'react-intl-next';
|
|
3
|
+
import { useSharedPluginStateWithSelector } from '@atlaskit/editor-common/hooks';
|
|
4
|
+
import { syncBlockMessages } from '@atlaskit/editor-common/messages';
|
|
5
|
+
import { ToolbarButton, ToolbarTooltip } from '@atlaskit/editor-toolbar';
|
|
6
|
+
import BlockSyncedIcon from '@atlaskit/icon-lab/core/block-synced';
|
|
7
|
+
import { canBeConvertedToSyncBlock } from '../pm-plugins/utils/utils';
|
|
8
|
+
export const CreateSyncedBlockButton = ({
|
|
9
|
+
api
|
|
10
|
+
}) => {
|
|
11
|
+
const intl = useIntl();
|
|
12
|
+
const selection = useSharedPluginStateWithSelector(api, ['selection'], states => {
|
|
13
|
+
var _states$selectionStat;
|
|
14
|
+
return (_states$selectionStat = states.selectionState) === null || _states$selectionStat === void 0 ? void 0 : _states$selectionStat.selection;
|
|
15
|
+
});
|
|
16
|
+
|
|
17
|
+
// for toolbar button, we allow both creating a new synced block
|
|
18
|
+
// and converting existing block to synced block
|
|
19
|
+
const canBeConverted = Boolean(selection && canBeConvertedToSyncBlock(selection));
|
|
20
|
+
const canInsertEmptyBlock = Boolean(selection === null || selection === void 0 ? void 0 : selection.empty);
|
|
21
|
+
const isDisabled = Boolean(!canBeConverted && !canInsertEmptyBlock);
|
|
22
|
+
const onClick = useCallback(() => {
|
|
23
|
+
var _api$core, _api$core2;
|
|
24
|
+
api === null || api === void 0 ? void 0 : (_api$core = api.core) === null || _api$core === void 0 ? void 0 : _api$core.actions.execute(({
|
|
25
|
+
tr
|
|
26
|
+
}) => api === null || api === void 0 ? void 0 : api.syncedBlock.commands.insertSyncedBlock()({
|
|
27
|
+
tr
|
|
28
|
+
}));
|
|
29
|
+
api === null || api === void 0 ? void 0 : (_api$core2 = api.core) === null || _api$core2 === void 0 ? void 0 : _api$core2.actions.focus();
|
|
30
|
+
}, [api]);
|
|
31
|
+
const message = intl.formatMessage(syncBlockMessages.createSyncBlockLabel);
|
|
32
|
+
return /*#__PURE__*/React.createElement(ToolbarTooltip, {
|
|
33
|
+
content: message
|
|
34
|
+
}, /*#__PURE__*/React.createElement(ToolbarButton, {
|
|
35
|
+
label: message,
|
|
36
|
+
iconBefore: /*#__PURE__*/React.createElement(BlockSyncedIcon, {
|
|
37
|
+
label: ""
|
|
38
|
+
}),
|
|
39
|
+
isDisabled: isDisabled,
|
|
40
|
+
onClick: onClick
|
|
41
|
+
}));
|
|
42
|
+
};
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import React, { useCallback } from 'react';
|
|
2
|
+
import { useIntl } from 'react-intl-next';
|
|
3
|
+
import { useSharedPluginStateWithSelector } from '@atlaskit/editor-common/hooks';
|
|
4
|
+
import { syncBlockMessages } from '@atlaskit/editor-common/messages';
|
|
5
|
+
import { ToolbarDropdownItem } from '@atlaskit/editor-toolbar';
|
|
6
|
+
import BlockSyncedIcon from '@atlaskit/icon-lab/core/block-synced';
|
|
7
|
+
import { canBeConvertedToSyncBlock } from '../pm-plugins/utils/utils';
|
|
8
|
+
export const CreateSyncedBlockItem = ({
|
|
9
|
+
api
|
|
10
|
+
}) => {
|
|
11
|
+
const intl = useIntl();
|
|
12
|
+
const selection = useSharedPluginStateWithSelector(api, ['selection'], states => {
|
|
13
|
+
var _states$selectionStat;
|
|
14
|
+
return (_states$selectionStat = states.selectionState) === null || _states$selectionStat === void 0 ? void 0 : _states$selectionStat.selection;
|
|
15
|
+
});
|
|
16
|
+
const isDisabled = Boolean(!selection || !canBeConvertedToSyncBlock(selection));
|
|
17
|
+
const onClick = useCallback(() => {
|
|
18
|
+
var _api$core, _api$core2;
|
|
19
|
+
api === null || api === void 0 ? void 0 : (_api$core = api.core) === null || _api$core === void 0 ? void 0 : _api$core.actions.execute(({
|
|
20
|
+
tr
|
|
21
|
+
}) => api === null || api === void 0 ? void 0 : api.syncedBlock.commands.insertSyncedBlock()({
|
|
22
|
+
tr
|
|
23
|
+
}));
|
|
24
|
+
api === null || api === void 0 ? void 0 : (_api$core2 = api.core) === null || _api$core2 === void 0 ? void 0 : _api$core2.actions.focus();
|
|
25
|
+
}, [api]);
|
|
26
|
+
const message = intl.formatMessage(syncBlockMessages.createSyncBlockLabel);
|
|
27
|
+
return /*#__PURE__*/React.createElement(ToolbarDropdownItem, {
|
|
28
|
+
onClick: onClick,
|
|
29
|
+
isDisabled: isDisabled,
|
|
30
|
+
elemBefore: /*#__PURE__*/React.createElement(BlockSyncedIcon, {
|
|
31
|
+
label: ""
|
|
32
|
+
})
|
|
33
|
+
}, message);
|
|
34
|
+
};
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { INSERT_BLOCK_SECTION, INSERT_BLOCK_SECTION_RANK, OVERFLOW_MENU, OVERFLOW_MENU_RANK, SYNCED_BLOCK_BUTTON, SYNCED_BLOCK_GROUP, SYNCED_BLOCK_ITEM, SYNCED_BLOCK_SECTION, SYNCED_BLOCK_SECTION_RANK } from '@atlaskit/editor-common/toolbar';
|
|
3
|
+
import { CreateSyncedBlockButton } from './CreateSyncedBlockButton';
|
|
4
|
+
import { CreateSyncedBlockItem } from './CreateSyncedBlockItem';
|
|
5
|
+
const SYNCED_BLOCK_OVERFLOW_MENU_SECTION = {
|
|
6
|
+
type: SYNCED_BLOCK_SECTION.type,
|
|
7
|
+
key: SYNCED_BLOCK_SECTION.key,
|
|
8
|
+
parents: [{
|
|
9
|
+
type: OVERFLOW_MENU.type,
|
|
10
|
+
key: OVERFLOW_MENU.key,
|
|
11
|
+
rank: OVERFLOW_MENU_RANK[SYNCED_BLOCK_SECTION.key]
|
|
12
|
+
}]
|
|
13
|
+
};
|
|
14
|
+
const SYNCED_BLOCK_PRIMARY_TOOLBAR_GROUP = {
|
|
15
|
+
type: SYNCED_BLOCK_GROUP.type,
|
|
16
|
+
key: SYNCED_BLOCK_GROUP.key,
|
|
17
|
+
parents: [{
|
|
18
|
+
type: INSERT_BLOCK_SECTION.type,
|
|
19
|
+
key: INSERT_BLOCK_SECTION.key,
|
|
20
|
+
rank: INSERT_BLOCK_SECTION_RANK[SYNCED_BLOCK_GROUP.key]
|
|
21
|
+
}]
|
|
22
|
+
};
|
|
23
|
+
export const getToolbarComponents = api => {
|
|
24
|
+
return [SYNCED_BLOCK_PRIMARY_TOOLBAR_GROUP, SYNCED_BLOCK_OVERFLOW_MENU_SECTION, {
|
|
25
|
+
type: SYNCED_BLOCK_BUTTON.type,
|
|
26
|
+
key: SYNCED_BLOCK_BUTTON.key,
|
|
27
|
+
component: () => /*#__PURE__*/React.createElement(CreateSyncedBlockButton, {
|
|
28
|
+
api: api
|
|
29
|
+
}),
|
|
30
|
+
parents: [{
|
|
31
|
+
type: SYNCED_BLOCK_GROUP.type,
|
|
32
|
+
key: SYNCED_BLOCK_GROUP.key,
|
|
33
|
+
rank: SYNCED_BLOCK_SECTION_RANK[SYNCED_BLOCK_BUTTON.key]
|
|
34
|
+
}]
|
|
35
|
+
}, {
|
|
36
|
+
type: SYNCED_BLOCK_ITEM.type,
|
|
37
|
+
key: SYNCED_BLOCK_ITEM.key,
|
|
38
|
+
parents: [{
|
|
39
|
+
type: SYNCED_BLOCK_SECTION.type,
|
|
40
|
+
key: SYNCED_BLOCK_SECTION.key,
|
|
41
|
+
rank: SYNCED_BLOCK_SECTION_RANK[SYNCED_BLOCK_ITEM.key]
|
|
42
|
+
}],
|
|
43
|
+
component: () => {
|
|
44
|
+
return /*#__PURE__*/React.createElement(CreateSyncedBlockItem, {
|
|
45
|
+
api: api
|
|
46
|
+
});
|
|
47
|
+
}
|
|
48
|
+
}];
|
|
49
|
+
};
|
|
@@ -10,12 +10,14 @@ import { getBlockMenuComponents } from './ui/block-menu-components';
|
|
|
10
10
|
import { DeleteConfirmationModal } from './ui/DeleteConfirmationModal';
|
|
11
11
|
import { getToolbarConfig } from './ui/floating-toolbar';
|
|
12
12
|
import { SyncBlockRefresher } from './ui/SyncBlockRefresher';
|
|
13
|
+
import { getToolbarComponents } from './ui/toolbar-components';
|
|
13
14
|
export var syncedBlockPlugin = function syncedBlockPlugin(_ref) {
|
|
14
|
-
var _api$blockMenu;
|
|
15
|
+
var _api$blockMenu, _api$toolbar;
|
|
15
16
|
var config = _ref.config,
|
|
16
17
|
api = _ref.api;
|
|
17
18
|
var syncBlockStore = new SyncBlockStoreManager(config === null || config === void 0 ? void 0 : config.syncBlockDataProvider);
|
|
18
19
|
api === null || api === void 0 || (_api$blockMenu = api.blockMenu) === null || _api$blockMenu === void 0 || _api$blockMenu.actions.registerBlockMenuComponents(getBlockMenuComponents(api));
|
|
20
|
+
api === null || api === void 0 || (_api$toolbar = api.toolbar) === null || _api$toolbar === void 0 || _api$toolbar.actions.registerComponents(getToolbarComponents(api));
|
|
19
21
|
return {
|
|
20
22
|
name: 'syncedBlock',
|
|
21
23
|
nodes: function nodes() {
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import React, { useCallback } from 'react';
|
|
2
|
+
import { useIntl } from 'react-intl-next';
|
|
3
|
+
import { useSharedPluginStateWithSelector } from '@atlaskit/editor-common/hooks';
|
|
4
|
+
import { syncBlockMessages } from '@atlaskit/editor-common/messages';
|
|
5
|
+
import { ToolbarButton, ToolbarTooltip } from '@atlaskit/editor-toolbar';
|
|
6
|
+
import BlockSyncedIcon from '@atlaskit/icon-lab/core/block-synced';
|
|
7
|
+
import { canBeConvertedToSyncBlock } from '../pm-plugins/utils/utils';
|
|
8
|
+
export var CreateSyncedBlockButton = function CreateSyncedBlockButton(_ref) {
|
|
9
|
+
var api = _ref.api;
|
|
10
|
+
var intl = useIntl();
|
|
11
|
+
var selection = useSharedPluginStateWithSelector(api, ['selection'], function (states) {
|
|
12
|
+
var _states$selectionStat;
|
|
13
|
+
return (_states$selectionStat = states.selectionState) === null || _states$selectionStat === void 0 ? void 0 : _states$selectionStat.selection;
|
|
14
|
+
});
|
|
15
|
+
|
|
16
|
+
// for toolbar button, we allow both creating a new synced block
|
|
17
|
+
// and converting existing block to synced block
|
|
18
|
+
var canBeConverted = Boolean(selection && canBeConvertedToSyncBlock(selection));
|
|
19
|
+
var canInsertEmptyBlock = Boolean(selection === null || selection === void 0 ? void 0 : selection.empty);
|
|
20
|
+
var isDisabled = Boolean(!canBeConverted && !canInsertEmptyBlock);
|
|
21
|
+
var onClick = useCallback(function () {
|
|
22
|
+
var _api$core, _api$core2;
|
|
23
|
+
api === null || api === void 0 || (_api$core = api.core) === null || _api$core === void 0 || _api$core.actions.execute(function (_ref2) {
|
|
24
|
+
var tr = _ref2.tr;
|
|
25
|
+
return api === null || api === void 0 ? void 0 : api.syncedBlock.commands.insertSyncedBlock()({
|
|
26
|
+
tr: tr
|
|
27
|
+
});
|
|
28
|
+
});
|
|
29
|
+
api === null || api === void 0 || (_api$core2 = api.core) === null || _api$core2 === void 0 || _api$core2.actions.focus();
|
|
30
|
+
}, [api]);
|
|
31
|
+
var message = intl.formatMessage(syncBlockMessages.createSyncBlockLabel);
|
|
32
|
+
return /*#__PURE__*/React.createElement(ToolbarTooltip, {
|
|
33
|
+
content: message
|
|
34
|
+
}, /*#__PURE__*/React.createElement(ToolbarButton, {
|
|
35
|
+
label: message,
|
|
36
|
+
iconBefore: /*#__PURE__*/React.createElement(BlockSyncedIcon, {
|
|
37
|
+
label: ""
|
|
38
|
+
}),
|
|
39
|
+
isDisabled: isDisabled,
|
|
40
|
+
onClick: onClick
|
|
41
|
+
}));
|
|
42
|
+
};
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import React, { useCallback } from 'react';
|
|
2
|
+
import { useIntl } from 'react-intl-next';
|
|
3
|
+
import { useSharedPluginStateWithSelector } from '@atlaskit/editor-common/hooks';
|
|
4
|
+
import { syncBlockMessages } from '@atlaskit/editor-common/messages';
|
|
5
|
+
import { ToolbarDropdownItem } from '@atlaskit/editor-toolbar';
|
|
6
|
+
import BlockSyncedIcon from '@atlaskit/icon-lab/core/block-synced';
|
|
7
|
+
import { canBeConvertedToSyncBlock } from '../pm-plugins/utils/utils';
|
|
8
|
+
export var CreateSyncedBlockItem = function CreateSyncedBlockItem(_ref) {
|
|
9
|
+
var api = _ref.api;
|
|
10
|
+
var intl = useIntl();
|
|
11
|
+
var selection = useSharedPluginStateWithSelector(api, ['selection'], function (states) {
|
|
12
|
+
var _states$selectionStat;
|
|
13
|
+
return (_states$selectionStat = states.selectionState) === null || _states$selectionStat === void 0 ? void 0 : _states$selectionStat.selection;
|
|
14
|
+
});
|
|
15
|
+
var isDisabled = Boolean(!selection || !canBeConvertedToSyncBlock(selection));
|
|
16
|
+
var onClick = useCallback(function () {
|
|
17
|
+
var _api$core, _api$core2;
|
|
18
|
+
api === null || api === void 0 || (_api$core = api.core) === null || _api$core === void 0 || _api$core.actions.execute(function (_ref2) {
|
|
19
|
+
var tr = _ref2.tr;
|
|
20
|
+
return api === null || api === void 0 ? void 0 : api.syncedBlock.commands.insertSyncedBlock()({
|
|
21
|
+
tr: tr
|
|
22
|
+
});
|
|
23
|
+
});
|
|
24
|
+
api === null || api === void 0 || (_api$core2 = api.core) === null || _api$core2 === void 0 || _api$core2.actions.focus();
|
|
25
|
+
}, [api]);
|
|
26
|
+
var message = intl.formatMessage(syncBlockMessages.createSyncBlockLabel);
|
|
27
|
+
return /*#__PURE__*/React.createElement(ToolbarDropdownItem, {
|
|
28
|
+
onClick: onClick,
|
|
29
|
+
isDisabled: isDisabled,
|
|
30
|
+
elemBefore: /*#__PURE__*/React.createElement(BlockSyncedIcon, {
|
|
31
|
+
label: ""
|
|
32
|
+
})
|
|
33
|
+
}, message);
|
|
34
|
+
};
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { INSERT_BLOCK_SECTION, INSERT_BLOCK_SECTION_RANK, OVERFLOW_MENU, OVERFLOW_MENU_RANK, SYNCED_BLOCK_BUTTON, SYNCED_BLOCK_GROUP, SYNCED_BLOCK_ITEM, SYNCED_BLOCK_SECTION, SYNCED_BLOCK_SECTION_RANK } from '@atlaskit/editor-common/toolbar';
|
|
3
|
+
import { CreateSyncedBlockButton } from './CreateSyncedBlockButton';
|
|
4
|
+
import { CreateSyncedBlockItem } from './CreateSyncedBlockItem';
|
|
5
|
+
var SYNCED_BLOCK_OVERFLOW_MENU_SECTION = {
|
|
6
|
+
type: SYNCED_BLOCK_SECTION.type,
|
|
7
|
+
key: SYNCED_BLOCK_SECTION.key,
|
|
8
|
+
parents: [{
|
|
9
|
+
type: OVERFLOW_MENU.type,
|
|
10
|
+
key: OVERFLOW_MENU.key,
|
|
11
|
+
rank: OVERFLOW_MENU_RANK[SYNCED_BLOCK_SECTION.key]
|
|
12
|
+
}]
|
|
13
|
+
};
|
|
14
|
+
var SYNCED_BLOCK_PRIMARY_TOOLBAR_GROUP = {
|
|
15
|
+
type: SYNCED_BLOCK_GROUP.type,
|
|
16
|
+
key: SYNCED_BLOCK_GROUP.key,
|
|
17
|
+
parents: [{
|
|
18
|
+
type: INSERT_BLOCK_SECTION.type,
|
|
19
|
+
key: INSERT_BLOCK_SECTION.key,
|
|
20
|
+
rank: INSERT_BLOCK_SECTION_RANK[SYNCED_BLOCK_GROUP.key]
|
|
21
|
+
}]
|
|
22
|
+
};
|
|
23
|
+
export var getToolbarComponents = function getToolbarComponents(api) {
|
|
24
|
+
return [SYNCED_BLOCK_PRIMARY_TOOLBAR_GROUP, SYNCED_BLOCK_OVERFLOW_MENU_SECTION, {
|
|
25
|
+
type: SYNCED_BLOCK_BUTTON.type,
|
|
26
|
+
key: SYNCED_BLOCK_BUTTON.key,
|
|
27
|
+
component: function component() {
|
|
28
|
+
return /*#__PURE__*/React.createElement(CreateSyncedBlockButton, {
|
|
29
|
+
api: api
|
|
30
|
+
});
|
|
31
|
+
},
|
|
32
|
+
parents: [{
|
|
33
|
+
type: SYNCED_BLOCK_GROUP.type,
|
|
34
|
+
key: SYNCED_BLOCK_GROUP.key,
|
|
35
|
+
rank: SYNCED_BLOCK_SECTION_RANK[SYNCED_BLOCK_BUTTON.key]
|
|
36
|
+
}]
|
|
37
|
+
}, {
|
|
38
|
+
type: SYNCED_BLOCK_ITEM.type,
|
|
39
|
+
key: SYNCED_BLOCK_ITEM.key,
|
|
40
|
+
parents: [{
|
|
41
|
+
type: SYNCED_BLOCK_SECTION.type,
|
|
42
|
+
key: SYNCED_BLOCK_SECTION.key,
|
|
43
|
+
rank: SYNCED_BLOCK_SECTION_RANK[SYNCED_BLOCK_ITEM.key]
|
|
44
|
+
}],
|
|
45
|
+
component: function component() {
|
|
46
|
+
return /*#__PURE__*/React.createElement(CreateSyncedBlockItem, {
|
|
47
|
+
api: api
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
}];
|
|
51
|
+
};
|
|
@@ -7,7 +7,8 @@ import type { BlockMenuPlugin } from '@atlaskit/editor-plugin-block-menu';
|
|
|
7
7
|
import type { DecorationsPlugin } from '@atlaskit/editor-plugin-decorations';
|
|
8
8
|
import type { FloatingToolbarPlugin } from '@atlaskit/editor-plugin-floating-toolbar';
|
|
9
9
|
import type { SelectionPlugin } from '@atlaskit/editor-plugin-selection';
|
|
10
|
-
import type {
|
|
10
|
+
import type { ToolbarPlugin } from '@atlaskit/editor-plugin-toolbar';
|
|
11
|
+
import type { EditorView } from '@atlaskit/editor-prosemirror/view';
|
|
11
12
|
import type { SyncBlockDataProvider, UseFetchSyncBlockDataResult } from '@atlaskit/editor-synced-block-provider';
|
|
12
13
|
export type SyncedBlockEditorProps = {
|
|
13
14
|
defaultDocument: JSONDocNode;
|
|
@@ -57,6 +58,7 @@ export type SyncedBlockPlugin = NextEditorPlugin<'syncedBlock', {
|
|
|
57
58
|
FloatingToolbarPlugin,
|
|
58
59
|
DecorationsPlugin,
|
|
59
60
|
OptionalPlugin<BlockControlsPlugin>,
|
|
61
|
+
OptionalPlugin<ToolbarPlugin>,
|
|
60
62
|
OptionalPlugin<BlockMenuPlugin>,
|
|
61
63
|
OptionalPlugin<AnalyticsPlugin>
|
|
62
64
|
];
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import type { ExtractInjectionAPI } from '@atlaskit/editor-common/types';
|
|
3
|
+
import type { SyncedBlockPlugin } from '../syncedBlockPluginType';
|
|
4
|
+
type CreateSyncedBlockButtonProps = {
|
|
5
|
+
api?: ExtractInjectionAPI<SyncedBlockPlugin>;
|
|
6
|
+
};
|
|
7
|
+
export declare const CreateSyncedBlockButton: ({ api }: CreateSyncedBlockButtonProps) => React.JSX.Element;
|
|
8
|
+
export {};
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import type { ExtractInjectionAPI } from '@atlaskit/editor-common/types';
|
|
3
|
+
import type { SyncedBlockPlugin } from '../syncedBlockPluginType';
|
|
4
|
+
type CreateSyncedBlockItemProps = {
|
|
5
|
+
api?: ExtractInjectionAPI<SyncedBlockPlugin>;
|
|
6
|
+
};
|
|
7
|
+
export declare const CreateSyncedBlockItem: ({ api }: CreateSyncedBlockItemProps) => React.JSX.Element;
|
|
8
|
+
export {};
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type { ExtractInjectionAPI } from '@atlaskit/editor-common/types';
|
|
2
|
+
import type { RegisterComponent } from '@atlaskit/editor-toolbar-model';
|
|
3
|
+
import type { SyncedBlockPlugin } from '../syncedBlockPluginType';
|
|
4
|
+
export declare const getToolbarComponents: (api?: ExtractInjectionAPI<SyncedBlockPlugin>) => RegisterComponent[];
|
|
@@ -7,7 +7,8 @@ import type { BlockMenuPlugin } from '@atlaskit/editor-plugin-block-menu';
|
|
|
7
7
|
import type { DecorationsPlugin } from '@atlaskit/editor-plugin-decorations';
|
|
8
8
|
import type { FloatingToolbarPlugin } from '@atlaskit/editor-plugin-floating-toolbar';
|
|
9
9
|
import type { SelectionPlugin } from '@atlaskit/editor-plugin-selection';
|
|
10
|
-
import type {
|
|
10
|
+
import type { ToolbarPlugin } from '@atlaskit/editor-plugin-toolbar';
|
|
11
|
+
import type { EditorView } from '@atlaskit/editor-prosemirror/view';
|
|
11
12
|
import type { SyncBlockDataProvider, UseFetchSyncBlockDataResult } from '@atlaskit/editor-synced-block-provider';
|
|
12
13
|
export type SyncedBlockEditorProps = {
|
|
13
14
|
defaultDocument: JSONDocNode;
|
|
@@ -57,6 +58,7 @@ export type SyncedBlockPlugin = NextEditorPlugin<'syncedBlock', {
|
|
|
57
58
|
FloatingToolbarPlugin,
|
|
58
59
|
DecorationsPlugin,
|
|
59
60
|
OptionalPlugin<BlockControlsPlugin>,
|
|
61
|
+
OptionalPlugin<ToolbarPlugin>,
|
|
60
62
|
OptionalPlugin<BlockMenuPlugin>,
|
|
61
63
|
OptionalPlugin<AnalyticsPlugin>
|
|
62
64
|
];
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import type { ExtractInjectionAPI } from '@atlaskit/editor-common/types';
|
|
3
|
+
import type { SyncedBlockPlugin } from '../syncedBlockPluginType';
|
|
4
|
+
type CreateSyncedBlockButtonProps = {
|
|
5
|
+
api?: ExtractInjectionAPI<SyncedBlockPlugin>;
|
|
6
|
+
};
|
|
7
|
+
export declare const CreateSyncedBlockButton: ({ api }: CreateSyncedBlockButtonProps) => React.JSX.Element;
|
|
8
|
+
export {};
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import type { ExtractInjectionAPI } from '@atlaskit/editor-common/types';
|
|
3
|
+
import type { SyncedBlockPlugin } from '../syncedBlockPluginType';
|
|
4
|
+
type CreateSyncedBlockItemProps = {
|
|
5
|
+
api?: ExtractInjectionAPI<SyncedBlockPlugin>;
|
|
6
|
+
};
|
|
7
|
+
export declare const CreateSyncedBlockItem: ({ api }: CreateSyncedBlockItemProps) => React.JSX.Element;
|
|
8
|
+
export {};
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type { ExtractInjectionAPI } from '@atlaskit/editor-common/types';
|
|
2
|
+
import type { RegisterComponent } from '@atlaskit/editor-toolbar-model';
|
|
3
|
+
import type { SyncedBlockPlugin } from '../syncedBlockPluginType';
|
|
4
|
+
export declare const getToolbarComponents: (api?: ExtractInjectionAPI<SyncedBlockPlugin>) => RegisterComponent[];
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@atlaskit/editor-plugin-synced-block",
|
|
3
|
-
"version": "4.
|
|
3
|
+
"version": "4.2.0",
|
|
4
4
|
"description": "SyncedBlock plugin for @atlaskit/editor-core",
|
|
5
5
|
"author": "Atlassian Pty Ltd",
|
|
6
6
|
"license": "Apache-2.0",
|
|
@@ -29,7 +29,7 @@
|
|
|
29
29
|
"atlaskit:src": "src/index.ts",
|
|
30
30
|
"dependencies": {
|
|
31
31
|
"@atlaskit/adf-schema": "^51.3.2",
|
|
32
|
-
"@atlaskit/button": "23.
|
|
32
|
+
"@atlaskit/button": "23.6.0",
|
|
33
33
|
"@atlaskit/editor-json-transformer": "^8.31.0",
|
|
34
34
|
"@atlaskit/editor-plugin-analytics": "^6.2.0",
|
|
35
35
|
"@atlaskit/editor-plugin-block-menu": "^5.0.0",
|
|
@@ -41,18 +41,19 @@
|
|
|
41
41
|
"@atlaskit/editor-synced-block-provider": "^2.7.0",
|
|
42
42
|
"@atlaskit/editor-tables": "^2.9.0",
|
|
43
43
|
"@atlaskit/editor-toolbar": "^0.17.0",
|
|
44
|
-
"@atlaskit/icon": "28.5.
|
|
44
|
+
"@atlaskit/icon": "28.5.4",
|
|
45
|
+
"@atlaskit/icon-lab": "^5.11.0",
|
|
45
46
|
"@atlaskit/logo": "^19.9.0",
|
|
46
|
-
"@atlaskit/lozenge": "^13.
|
|
47
|
+
"@atlaskit/lozenge": "^13.1.0",
|
|
47
48
|
"@atlaskit/modal-dialog": "^14.6.0",
|
|
48
49
|
"@atlaskit/primitives": "^16.1.0",
|
|
49
|
-
"@atlaskit/tooltip": "^20.
|
|
50
|
+
"@atlaskit/tooltip": "^20.8.0",
|
|
50
51
|
"@atlaskit/visually-hidden": "^3.0.0",
|
|
51
52
|
"@babel/runtime": "^7.0.0",
|
|
52
53
|
"react-intl-next": "npm:react-intl@^5.18.1"
|
|
53
54
|
},
|
|
54
55
|
"peerDependencies": {
|
|
55
|
-
"@atlaskit/editor-common": "^110.
|
|
56
|
+
"@atlaskit/editor-common": "^110.25.0",
|
|
56
57
|
"react": "^18.2.0"
|
|
57
58
|
},
|
|
58
59
|
"devDependencies": {
|