@atlaskit/editor-plugin-synced-block 4.2.4 → 4.2.6
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 +18 -0
- package/dist/cjs/pm-plugins/main.js +35 -7
- package/dist/cjs/pm-plugins/utils/selection-decorations.js +22 -0
- package/dist/cjs/syncedBlockPlugin.js +4 -0
- package/dist/cjs/syncedBlockPluginType.js +2 -1
- package/dist/cjs/ui/CreateSyncedBlockButton.js +1 -0
- package/dist/cjs/ui/CreateSyncedBlockDropdownItem.js +4 -4
- package/dist/cjs/ui/CreateSyncedBlockItem.js +9 -1
- package/dist/es2019/pm-plugins/main.js +31 -7
- package/dist/es2019/pm-plugins/utils/selection-decorations.js +20 -0
- package/dist/es2019/syncedBlockPlugin.js +4 -0
- package/dist/es2019/syncedBlockPluginType.js +1 -0
- package/dist/es2019/ui/CreateSyncedBlockButton.js +1 -0
- package/dist/es2019/ui/CreateSyncedBlockDropdownItem.js +4 -4
- package/dist/es2019/ui/CreateSyncedBlockItem.js +9 -1
- package/dist/esm/pm-plugins/main.js +34 -7
- package/dist/esm/pm-plugins/utils/selection-decorations.js +16 -0
- package/dist/esm/syncedBlockPlugin.js +4 -0
- package/dist/esm/syncedBlockPluginType.js +1 -0
- package/dist/esm/ui/CreateSyncedBlockButton.js +1 -0
- package/dist/esm/ui/CreateSyncedBlockDropdownItem.js +4 -4
- package/dist/esm/ui/CreateSyncedBlockItem.js +9 -1
- package/dist/types/pm-plugins/main.d.ts +4 -1
- package/dist/types/pm-plugins/utils/selection-decorations.d.ts +4 -0
- package/dist/types/syncedBlockPluginType.d.ts +3 -3
- package/dist/types-ts4.5/pm-plugins/main.d.ts +4 -1
- package/dist/types-ts4.5/pm-plugins/utils/selection-decorations.d.ts +4 -0
- package/dist/types-ts4.5/syncedBlockPluginType.d.ts +3 -3
- package/package.json +2 -2
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,23 @@
|
|
|
1
1
|
# @atlaskit/editor-plugin-synced-block
|
|
2
2
|
|
|
3
|
+
## 4.2.6
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- [`9e7aa73151ed0`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/9e7aa73151ed0) -
|
|
8
|
+
[ux] EDITOR-2670 add selected state for sync block when selection is inside
|
|
9
|
+
- [`18f894b7433f3`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/18f894b7433f3) -
|
|
10
|
+
EDITOR-2863 Fix Add copy sync block option to block menu
|
|
11
|
+
- Updated dependencies
|
|
12
|
+
|
|
13
|
+
## 4.2.5
|
|
14
|
+
|
|
15
|
+
### Patch Changes
|
|
16
|
+
|
|
17
|
+
- [`7e8c949e9c8c0`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/7e8c949e9c8c0) -
|
|
18
|
+
[ux] Add new lozenge next to create synced block in toolbar and typeahead, and text updates
|
|
19
|
+
- Updated dependencies
|
|
20
|
+
|
|
3
21
|
## 4.2.4
|
|
4
22
|
|
|
5
23
|
### Patch Changes
|
|
@@ -1,19 +1,26 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
3
4
|
Object.defineProperty(exports, "__esModule", {
|
|
4
5
|
value: true
|
|
5
6
|
});
|
|
6
7
|
exports.syncedBlockPluginKey = exports.createPlugin = void 0;
|
|
8
|
+
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
7
9
|
var _safePlugin = require("@atlaskit/editor-common/safe-plugin");
|
|
10
|
+
var _selection = require("@atlaskit/editor-common/selection");
|
|
11
|
+
var _syncBlock = require("@atlaskit/editor-common/sync-block");
|
|
8
12
|
var _state = require("@atlaskit/editor-prosemirror/state");
|
|
9
13
|
var _bodiedLazySyncedBlock = require("../nodeviews/bodiedLazySyncedBlock");
|
|
10
14
|
var _lazySyncedBlock = require("../nodeviews/lazySyncedBlock");
|
|
15
|
+
var _selectionDecorations = require("./utils/selection-decorations");
|
|
11
16
|
var _trackSyncBlocks2 = require("./utils/track-sync-blocks");
|
|
17
|
+
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; }
|
|
18
|
+
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; }
|
|
12
19
|
var syncedBlockPluginKey = exports.syncedBlockPluginKey = new _state.PluginKey('syncedBlockPlugin');
|
|
13
|
-
|
|
14
|
-
// eslint-disable-next-line @typescript-eslint/no-empty-object-type
|
|
15
|
-
|
|
16
20
|
var createPlugin = exports.createPlugin = function createPlugin(options, pmPluginFactoryParams, syncBlockStore, api) {
|
|
21
|
+
var _ref = options || {},
|
|
22
|
+
_ref$useLongPressSele = _ref.useLongPressSelection,
|
|
23
|
+
useLongPressSelection = _ref$useLongPressSele === void 0 ? false : _ref$useLongPressSele;
|
|
17
24
|
return new _safePlugin.SafePlugin({
|
|
18
25
|
key: syncedBlockPluginKey,
|
|
19
26
|
state: {
|
|
@@ -22,14 +29,26 @@ var createPlugin = exports.createPlugin = function createPlugin(options, pmPlugi
|
|
|
22
29
|
return node.type.name === 'syncBlock';
|
|
23
30
|
});
|
|
24
31
|
syncBlockStore.fetchSyncBlocksData(syncBlockNodes);
|
|
25
|
-
return {
|
|
32
|
+
return {
|
|
33
|
+
decorationSet: (0, _selectionDecorations.calculateDecorations)(instance.doc, instance.selection, instance.schema)
|
|
34
|
+
};
|
|
26
35
|
},
|
|
27
|
-
apply: function apply(tr, currentPluginState) {
|
|
36
|
+
apply: function apply(tr, currentPluginState, oldEditorState) {
|
|
28
37
|
var meta = tr.getMeta(syncedBlockPluginKey);
|
|
29
38
|
if (meta) {
|
|
30
39
|
return meta;
|
|
31
40
|
}
|
|
32
|
-
|
|
41
|
+
var newState = currentPluginState;
|
|
42
|
+
if (!tr.selection.eq(oldEditorState.selection)) {
|
|
43
|
+
newState = _objectSpread(_objectSpread({}, newState), {}, {
|
|
44
|
+
decorationSet: (0, _selectionDecorations.calculateDecorations)(tr.doc, tr.selection, tr.doc.type.schema)
|
|
45
|
+
});
|
|
46
|
+
} else if (newState.decorationSet) {
|
|
47
|
+
newState = _objectSpread(_objectSpread({}, newState), {}, {
|
|
48
|
+
decorationSet: newState.decorationSet.map(tr.mapping, tr.doc)
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
return newState;
|
|
33
52
|
}
|
|
34
53
|
},
|
|
35
54
|
props: {
|
|
@@ -46,7 +65,16 @@ var createPlugin = exports.createPlugin = function createPlugin(options, pmPlugi
|
|
|
46
65
|
api: api,
|
|
47
66
|
syncBlockStore: syncBlockStore
|
|
48
67
|
})
|
|
49
|
-
}
|
|
68
|
+
},
|
|
69
|
+
decorations: function decorations(state) {
|
|
70
|
+
var pluginState = syncedBlockPluginKey.getState(state);
|
|
71
|
+
return pluginState === null || pluginState === void 0 ? void 0 : pluginState.decorationSet;
|
|
72
|
+
},
|
|
73
|
+
handleClickOn: (0, _selection.createSelectionClickHandler)(['bodiedSyncBlock'], function (target) {
|
|
74
|
+
return !!target.closest(".".concat(_syncBlock.BodiedSyncBlockSharedCssClassName.prefix));
|
|
75
|
+
}, {
|
|
76
|
+
useLongPressSelection: useLongPressSelection
|
|
77
|
+
})
|
|
50
78
|
},
|
|
51
79
|
view: function view(editorView) {
|
|
52
80
|
syncBlockStore.setEditorView(editorView);
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.calculateDecorations = void 0;
|
|
7
|
+
var _syncBlock = require("@atlaskit/editor-common/sync-block");
|
|
8
|
+
var _utils = require("@atlaskit/editor-prosemirror/utils");
|
|
9
|
+
var _view = require("@atlaskit/editor-prosemirror/view");
|
|
10
|
+
var calculateDecorations = exports.calculateDecorations = function calculateDecorations(doc, selection, schema) {
|
|
11
|
+
var bodiedSyncBlock = schema.nodes.bodiedSyncBlock;
|
|
12
|
+
var syncBlockParent = (0, _utils.findParentNodeOfType)(bodiedSyncBlock)(selection);
|
|
13
|
+
if (syncBlockParent) {
|
|
14
|
+
var node = syncBlockParent.node,
|
|
15
|
+
pos = syncBlockParent.pos;
|
|
16
|
+
var decoration = _view.Decoration.node(pos, pos + node.nodeSize, {
|
|
17
|
+
class: "".concat(_syncBlock.BodiedSyncBlockSharedCssClassName.selectionInside)
|
|
18
|
+
});
|
|
19
|
+
return _view.DecorationSet.create(doc, [decoration]);
|
|
20
|
+
}
|
|
21
|
+
return _view.DecorationSet.empty;
|
|
22
|
+
};
|
|
@@ -10,6 +10,7 @@ var _adfSchema = require("@atlaskit/adf-schema");
|
|
|
10
10
|
var _messages = require("@atlaskit/editor-common/messages");
|
|
11
11
|
var _quickInsert = require("@atlaskit/editor-common/quick-insert");
|
|
12
12
|
var _editorSyncedBlockProvider = require("@atlaskit/editor-synced-block-provider");
|
|
13
|
+
var _lozenge = _interopRequireDefault(require("@atlaskit/lozenge"));
|
|
13
14
|
var _editorActions = require("./editor-actions");
|
|
14
15
|
var _editorCommands = require("./editor-commands");
|
|
15
16
|
var _main = require("./pm-plugins/main");
|
|
@@ -73,6 +74,9 @@ var syncedBlockPlugin = exports.syncedBlockPlugin = function syncedBlockPlugin(_
|
|
|
73
74
|
priority: 800,
|
|
74
75
|
keywords: ['synced', 'block', 'synced-block', 'sync', 'sync-block', 'auto', 'update', 'excerpt', 'connect'],
|
|
75
76
|
keyshortcut: '',
|
|
77
|
+
lozenge: /*#__PURE__*/_react.default.createElement(_lozenge.default, {
|
|
78
|
+
appearance: "new"
|
|
79
|
+
}, formatMessage(_messages.blockTypeMessages.newLozenge)),
|
|
76
80
|
icon: function icon() {
|
|
77
81
|
return /*#__PURE__*/_react.default.createElement(_quickInsert.IconSyncBlock, {
|
|
78
82
|
label: formatMessage(_messages.blockTypeMessages.syncedBlock)
|
|
@@ -43,6 +43,7 @@ var CreateSyncedBlockButton = exports.CreateSyncedBlockButton = function CreateS
|
|
|
43
43
|
}, /*#__PURE__*/_react.default.createElement(_editorToolbar.ToolbarButton, {
|
|
44
44
|
label: message,
|
|
45
45
|
iconBefore: /*#__PURE__*/_react.default.createElement(_blockSynced.default, {
|
|
46
|
+
size: "small",
|
|
46
47
|
label: ""
|
|
47
48
|
}),
|
|
48
49
|
isDisabled: isDisabled,
|
|
@@ -80,13 +80,13 @@ var CopySyncedBlockDropdownItem = function CopySyncedBlockDropdownItem(_ref2) {
|
|
|
80
80
|
var CreateOrCopySyncedBlockDropdownItem = exports.CreateOrCopySyncedBlockDropdownItem = function CreateOrCopySyncedBlockDropdownItem(_ref3) {
|
|
81
81
|
var api = _ref3.api;
|
|
82
82
|
var _useSharedPluginState2 = (0, _hooks.useSharedPluginStateWithSelector)(api, ['blockControls'], function (states) {
|
|
83
|
-
var _states$blockControls2;
|
|
83
|
+
var _states$blockControls2, _states$blockControls3;
|
|
84
84
|
return {
|
|
85
|
-
|
|
85
|
+
activeNodeType: (_states$blockControls2 = (_states$blockControls3 = states.blockControlsState) === null || _states$blockControls3 === void 0 || (_states$blockControls3 = _states$blockControls3.activeNode) === null || _states$blockControls3 === void 0 ? void 0 : _states$blockControls3.nodeType) !== null && _states$blockControls2 !== void 0 ? _states$blockControls2 : undefined
|
|
86
86
|
};
|
|
87
87
|
}),
|
|
88
|
-
|
|
89
|
-
if (
|
|
88
|
+
activeNodeType = _useSharedPluginState2.activeNodeType;
|
|
89
|
+
if (activeNodeType === 'syncBlock' || activeNodeType === 'bodiedSyncBlock') {
|
|
90
90
|
return /*#__PURE__*/_react.default.createElement(CopySyncedBlockDropdownItem, {
|
|
91
91
|
api: api
|
|
92
92
|
});
|
|
@@ -12,6 +12,8 @@ var _hooks = require("@atlaskit/editor-common/hooks");
|
|
|
12
12
|
var _messages = require("@atlaskit/editor-common/messages");
|
|
13
13
|
var _editorToolbar = require("@atlaskit/editor-toolbar");
|
|
14
14
|
var _blockSynced = _interopRequireDefault(require("@atlaskit/icon-lab/core/block-synced"));
|
|
15
|
+
var _lozenge = _interopRequireDefault(require("@atlaskit/lozenge"));
|
|
16
|
+
var _compiled = require("@atlaskit/primitives/compiled");
|
|
15
17
|
var _utils = require("../pm-plugins/utils/utils");
|
|
16
18
|
function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function _interopRequireWildcard(e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, default: e }; if (null === e || "object" != _typeof(e) && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (var _t in e) "default" !== _t && {}.hasOwnProperty.call(e, _t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, _t)) && (i.get || i.set) ? o(f, _t, i) : f[_t] = e[_t]); return f; })(e, t); }
|
|
17
19
|
var CreateSyncedBlockItem = exports.CreateSyncedBlockItem = function CreateSyncedBlockItem(_ref) {
|
|
@@ -37,7 +39,13 @@ var CreateSyncedBlockItem = exports.CreateSyncedBlockItem = function CreateSynce
|
|
|
37
39
|
onClick: onClick,
|
|
38
40
|
isDisabled: isDisabled,
|
|
39
41
|
elemBefore: /*#__PURE__*/_react.default.createElement(_blockSynced.default, {
|
|
42
|
+
size: "small",
|
|
40
43
|
label: ""
|
|
41
44
|
})
|
|
42
|
-
},
|
|
45
|
+
}, /*#__PURE__*/_react.default.createElement(_compiled.Flex, {
|
|
46
|
+
alignItems: "center",
|
|
47
|
+
gap: "space.050"
|
|
48
|
+
}, message, /*#__PURE__*/_react.default.createElement(_lozenge.default, {
|
|
49
|
+
appearance: "new"
|
|
50
|
+
}, intl.formatMessage(_messages.syncBlockMessages.newLozenge))));
|
|
43
51
|
};
|
|
@@ -1,27 +1,44 @@
|
|
|
1
1
|
import { SafePlugin } from '@atlaskit/editor-common/safe-plugin';
|
|
2
|
+
import { createSelectionClickHandler } from '@atlaskit/editor-common/selection';
|
|
3
|
+
import { BodiedSyncBlockSharedCssClassName } from '@atlaskit/editor-common/sync-block';
|
|
2
4
|
import { PluginKey } from '@atlaskit/editor-prosemirror/state';
|
|
3
5
|
import { lazyBodiedSyncBlockView } from '../nodeviews/bodiedLazySyncedBlock';
|
|
4
6
|
import { lazySyncBlockView } from '../nodeviews/lazySyncedBlock';
|
|
7
|
+
import { calculateDecorations } from './utils/selection-decorations';
|
|
5
8
|
import { trackSyncBlocks } from './utils/track-sync-blocks';
|
|
6
9
|
export const syncedBlockPluginKey = new PluginKey('syncedBlockPlugin');
|
|
7
|
-
|
|
8
|
-
// eslint-disable-next-line @typescript-eslint/no-empty-object-type
|
|
9
|
-
|
|
10
10
|
export const createPlugin = (options, pmPluginFactoryParams, syncBlockStore, api) => {
|
|
11
|
+
const {
|
|
12
|
+
useLongPressSelection = false
|
|
13
|
+
} = options || {};
|
|
11
14
|
return new SafePlugin({
|
|
12
15
|
key: syncedBlockPluginKey,
|
|
13
16
|
state: {
|
|
14
17
|
init(_, instance) {
|
|
15
18
|
const syncBlockNodes = instance.doc.children.filter(node => node.type.name === 'syncBlock');
|
|
16
19
|
syncBlockStore.fetchSyncBlocksData(syncBlockNodes);
|
|
17
|
-
return {
|
|
20
|
+
return {
|
|
21
|
+
decorationSet: calculateDecorations(instance.doc, instance.selection, instance.schema)
|
|
22
|
+
};
|
|
18
23
|
},
|
|
19
|
-
apply: (tr, currentPluginState) => {
|
|
24
|
+
apply: (tr, currentPluginState, oldEditorState) => {
|
|
20
25
|
const meta = tr.getMeta(syncedBlockPluginKey);
|
|
21
26
|
if (meta) {
|
|
22
27
|
return meta;
|
|
23
28
|
}
|
|
24
|
-
|
|
29
|
+
let newState = currentPluginState;
|
|
30
|
+
if (!tr.selection.eq(oldEditorState.selection)) {
|
|
31
|
+
newState = {
|
|
32
|
+
...newState,
|
|
33
|
+
decorationSet: calculateDecorations(tr.doc, tr.selection, tr.doc.type.schema)
|
|
34
|
+
};
|
|
35
|
+
} else if (newState.decorationSet) {
|
|
36
|
+
newState = {
|
|
37
|
+
...newState,
|
|
38
|
+
decorationSet: newState.decorationSet.map(tr.mapping, tr.doc)
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
return newState;
|
|
25
42
|
}
|
|
26
43
|
},
|
|
27
44
|
props: {
|
|
@@ -38,7 +55,14 @@ export const createPlugin = (options, pmPluginFactoryParams, syncBlockStore, api
|
|
|
38
55
|
api,
|
|
39
56
|
syncBlockStore
|
|
40
57
|
})
|
|
41
|
-
}
|
|
58
|
+
},
|
|
59
|
+
decorations: state => {
|
|
60
|
+
const pluginState = syncedBlockPluginKey.getState(state);
|
|
61
|
+
return pluginState === null || pluginState === void 0 ? void 0 : pluginState.decorationSet;
|
|
62
|
+
},
|
|
63
|
+
handleClickOn: createSelectionClickHandler(['bodiedSyncBlock'], target => !!target.closest(`.${BodiedSyncBlockSharedCssClassName.prefix}`), {
|
|
64
|
+
useLongPressSelection
|
|
65
|
+
})
|
|
42
66
|
},
|
|
43
67
|
view: editorView => {
|
|
44
68
|
syncBlockStore.setEditorView(editorView);
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { BodiedSyncBlockSharedCssClassName } from '@atlaskit/editor-common/sync-block';
|
|
2
|
+
import { findParentNodeOfType } from '@atlaskit/editor-prosemirror/utils';
|
|
3
|
+
import { Decoration, DecorationSet } from "@atlaskit/editor-prosemirror/view";
|
|
4
|
+
export const calculateDecorations = (doc, selection, schema) => {
|
|
5
|
+
const {
|
|
6
|
+
bodiedSyncBlock
|
|
7
|
+
} = schema.nodes;
|
|
8
|
+
const syncBlockParent = findParentNodeOfType(bodiedSyncBlock)(selection);
|
|
9
|
+
if (syncBlockParent) {
|
|
10
|
+
const {
|
|
11
|
+
node,
|
|
12
|
+
pos
|
|
13
|
+
} = syncBlockParent;
|
|
14
|
+
const decoration = Decoration.node(pos, pos + node.nodeSize, {
|
|
15
|
+
class: `${BodiedSyncBlockSharedCssClassName.selectionInside}`
|
|
16
|
+
});
|
|
17
|
+
return DecorationSet.create(doc, [decoration]);
|
|
18
|
+
}
|
|
19
|
+
return DecorationSet.empty;
|
|
20
|
+
};
|
|
@@ -3,6 +3,7 @@ import { bodiedSyncBlock, syncBlock } from '@atlaskit/adf-schema';
|
|
|
3
3
|
import { blockTypeMessages } from '@atlaskit/editor-common/messages';
|
|
4
4
|
import { IconSyncBlock } from '@atlaskit/editor-common/quick-insert';
|
|
5
5
|
import { SyncBlockStoreManager } from '@atlaskit/editor-synced-block-provider';
|
|
6
|
+
import Lozenge from '@atlaskit/lozenge';
|
|
6
7
|
import { flushBodiedSyncBlocks } from './editor-actions';
|
|
7
8
|
import { copySyncedBlockReferenceToClipboardEditorCommand, createSyncedBlock } from './editor-commands';
|
|
8
9
|
import { createPlugin } from './pm-plugins/main';
|
|
@@ -60,6 +61,9 @@ export const syncedBlockPlugin = ({
|
|
|
60
61
|
priority: 800,
|
|
61
62
|
keywords: ['synced', 'block', 'synced-block', 'sync', 'sync-block', 'auto', 'update', 'excerpt', 'connect'],
|
|
62
63
|
keyshortcut: '',
|
|
64
|
+
lozenge: /*#__PURE__*/React.createElement(Lozenge, {
|
|
65
|
+
appearance: "new"
|
|
66
|
+
}, formatMessage(blockTypeMessages.newLozenge)),
|
|
63
67
|
icon: () => /*#__PURE__*/React.createElement(IconSyncBlock, {
|
|
64
68
|
label: formatMessage(blockTypeMessages.syncedBlock)
|
|
65
69
|
}),
|
|
@@ -75,14 +75,14 @@ export const CreateOrCopySyncedBlockDropdownItem = ({
|
|
|
75
75
|
api
|
|
76
76
|
}) => {
|
|
77
77
|
const {
|
|
78
|
-
|
|
78
|
+
activeNodeType
|
|
79
79
|
} = useSharedPluginStateWithSelector(api, ['blockControls'], states => {
|
|
80
|
-
var _states$blockControls2;
|
|
80
|
+
var _states$blockControls2, _states$blockControls3, _states$blockControls4;
|
|
81
81
|
return {
|
|
82
|
-
|
|
82
|
+
activeNodeType: (_states$blockControls2 = (_states$blockControls3 = states.blockControlsState) === null || _states$blockControls3 === void 0 ? void 0 : (_states$blockControls4 = _states$blockControls3.activeNode) === null || _states$blockControls4 === void 0 ? void 0 : _states$blockControls4.nodeType) !== null && _states$blockControls2 !== void 0 ? _states$blockControls2 : undefined
|
|
83
83
|
};
|
|
84
84
|
});
|
|
85
|
-
if (
|
|
85
|
+
if (activeNodeType === 'syncBlock' || activeNodeType === 'bodiedSyncBlock') {
|
|
86
86
|
return /*#__PURE__*/React.createElement(CopySyncedBlockDropdownItem, {
|
|
87
87
|
api: api
|
|
88
88
|
});
|
|
@@ -4,6 +4,8 @@ import { useSharedPluginStateWithSelector } from '@atlaskit/editor-common/hooks'
|
|
|
4
4
|
import { syncBlockMessages } from '@atlaskit/editor-common/messages';
|
|
5
5
|
import { ToolbarDropdownItem } from '@atlaskit/editor-toolbar';
|
|
6
6
|
import BlockSyncedIcon from '@atlaskit/icon-lab/core/block-synced';
|
|
7
|
+
import Lozenge from '@atlaskit/lozenge';
|
|
8
|
+
import { Flex } from '@atlaskit/primitives/compiled';
|
|
7
9
|
import { canBeConvertedToSyncBlock } from '../pm-plugins/utils/utils';
|
|
8
10
|
export const CreateSyncedBlockItem = ({
|
|
9
11
|
api
|
|
@@ -28,7 +30,13 @@ export const CreateSyncedBlockItem = ({
|
|
|
28
30
|
onClick: onClick,
|
|
29
31
|
isDisabled: isDisabled,
|
|
30
32
|
elemBefore: /*#__PURE__*/React.createElement(BlockSyncedIcon, {
|
|
33
|
+
size: "small",
|
|
31
34
|
label: ""
|
|
32
35
|
})
|
|
33
|
-
},
|
|
36
|
+
}, /*#__PURE__*/React.createElement(Flex, {
|
|
37
|
+
alignItems: "center",
|
|
38
|
+
gap: "space.050"
|
|
39
|
+
}, message, /*#__PURE__*/React.createElement(Lozenge, {
|
|
40
|
+
appearance: "new"
|
|
41
|
+
}, intl.formatMessage(syncBlockMessages.newLozenge))));
|
|
34
42
|
};
|
|
@@ -1,13 +1,19 @@
|
|
|
1
|
+
import _defineProperty from "@babel/runtime/helpers/defineProperty";
|
|
2
|
+
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
3
|
+
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
1
4
|
import { SafePlugin } from '@atlaskit/editor-common/safe-plugin';
|
|
5
|
+
import { createSelectionClickHandler } from '@atlaskit/editor-common/selection';
|
|
6
|
+
import { BodiedSyncBlockSharedCssClassName } from '@atlaskit/editor-common/sync-block';
|
|
2
7
|
import { PluginKey } from '@atlaskit/editor-prosemirror/state';
|
|
3
8
|
import { lazyBodiedSyncBlockView } from '../nodeviews/bodiedLazySyncedBlock';
|
|
4
9
|
import { lazySyncBlockView } from '../nodeviews/lazySyncedBlock';
|
|
10
|
+
import { calculateDecorations } from './utils/selection-decorations';
|
|
5
11
|
import { trackSyncBlocks } from './utils/track-sync-blocks';
|
|
6
12
|
export var syncedBlockPluginKey = new PluginKey('syncedBlockPlugin');
|
|
7
|
-
|
|
8
|
-
// eslint-disable-next-line @typescript-eslint/no-empty-object-type
|
|
9
|
-
|
|
10
13
|
export var createPlugin = function createPlugin(options, pmPluginFactoryParams, syncBlockStore, api) {
|
|
14
|
+
var _ref = options || {},
|
|
15
|
+
_ref$useLongPressSele = _ref.useLongPressSelection,
|
|
16
|
+
useLongPressSelection = _ref$useLongPressSele === void 0 ? false : _ref$useLongPressSele;
|
|
11
17
|
return new SafePlugin({
|
|
12
18
|
key: syncedBlockPluginKey,
|
|
13
19
|
state: {
|
|
@@ -16,14 +22,26 @@ export var createPlugin = function createPlugin(options, pmPluginFactoryParams,
|
|
|
16
22
|
return node.type.name === 'syncBlock';
|
|
17
23
|
});
|
|
18
24
|
syncBlockStore.fetchSyncBlocksData(syncBlockNodes);
|
|
19
|
-
return {
|
|
25
|
+
return {
|
|
26
|
+
decorationSet: calculateDecorations(instance.doc, instance.selection, instance.schema)
|
|
27
|
+
};
|
|
20
28
|
},
|
|
21
|
-
apply: function apply(tr, currentPluginState) {
|
|
29
|
+
apply: function apply(tr, currentPluginState, oldEditorState) {
|
|
22
30
|
var meta = tr.getMeta(syncedBlockPluginKey);
|
|
23
31
|
if (meta) {
|
|
24
32
|
return meta;
|
|
25
33
|
}
|
|
26
|
-
|
|
34
|
+
var newState = currentPluginState;
|
|
35
|
+
if (!tr.selection.eq(oldEditorState.selection)) {
|
|
36
|
+
newState = _objectSpread(_objectSpread({}, newState), {}, {
|
|
37
|
+
decorationSet: calculateDecorations(tr.doc, tr.selection, tr.doc.type.schema)
|
|
38
|
+
});
|
|
39
|
+
} else if (newState.decorationSet) {
|
|
40
|
+
newState = _objectSpread(_objectSpread({}, newState), {}, {
|
|
41
|
+
decorationSet: newState.decorationSet.map(tr.mapping, tr.doc)
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
return newState;
|
|
27
45
|
}
|
|
28
46
|
},
|
|
29
47
|
props: {
|
|
@@ -40,7 +58,16 @@ export var createPlugin = function createPlugin(options, pmPluginFactoryParams,
|
|
|
40
58
|
api: api,
|
|
41
59
|
syncBlockStore: syncBlockStore
|
|
42
60
|
})
|
|
43
|
-
}
|
|
61
|
+
},
|
|
62
|
+
decorations: function decorations(state) {
|
|
63
|
+
var pluginState = syncedBlockPluginKey.getState(state);
|
|
64
|
+
return pluginState === null || pluginState === void 0 ? void 0 : pluginState.decorationSet;
|
|
65
|
+
},
|
|
66
|
+
handleClickOn: createSelectionClickHandler(['bodiedSyncBlock'], function (target) {
|
|
67
|
+
return !!target.closest(".".concat(BodiedSyncBlockSharedCssClassName.prefix));
|
|
68
|
+
}, {
|
|
69
|
+
useLongPressSelection: useLongPressSelection
|
|
70
|
+
})
|
|
44
71
|
},
|
|
45
72
|
view: function view(editorView) {
|
|
46
73
|
syncBlockStore.setEditorView(editorView);
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { BodiedSyncBlockSharedCssClassName } from '@atlaskit/editor-common/sync-block';
|
|
2
|
+
import { findParentNodeOfType } from '@atlaskit/editor-prosemirror/utils';
|
|
3
|
+
import { Decoration, DecorationSet } from "@atlaskit/editor-prosemirror/view";
|
|
4
|
+
export var calculateDecorations = function calculateDecorations(doc, selection, schema) {
|
|
5
|
+
var bodiedSyncBlock = schema.nodes.bodiedSyncBlock;
|
|
6
|
+
var syncBlockParent = findParentNodeOfType(bodiedSyncBlock)(selection);
|
|
7
|
+
if (syncBlockParent) {
|
|
8
|
+
var node = syncBlockParent.node,
|
|
9
|
+
pos = syncBlockParent.pos;
|
|
10
|
+
var decoration = Decoration.node(pos, pos + node.nodeSize, {
|
|
11
|
+
class: "".concat(BodiedSyncBlockSharedCssClassName.selectionInside)
|
|
12
|
+
});
|
|
13
|
+
return DecorationSet.create(doc, [decoration]);
|
|
14
|
+
}
|
|
15
|
+
return DecorationSet.empty;
|
|
16
|
+
};
|
|
@@ -3,6 +3,7 @@ import { bodiedSyncBlock, syncBlock } from '@atlaskit/adf-schema';
|
|
|
3
3
|
import { blockTypeMessages } from '@atlaskit/editor-common/messages';
|
|
4
4
|
import { IconSyncBlock } from '@atlaskit/editor-common/quick-insert';
|
|
5
5
|
import { SyncBlockStoreManager } from '@atlaskit/editor-synced-block-provider';
|
|
6
|
+
import Lozenge from '@atlaskit/lozenge';
|
|
6
7
|
import { flushBodiedSyncBlocks as _flushBodiedSyncBlocks } from './editor-actions';
|
|
7
8
|
import { copySyncedBlockReferenceToClipboardEditorCommand, createSyncedBlock } from './editor-commands';
|
|
8
9
|
import { createPlugin } from './pm-plugins/main';
|
|
@@ -66,6 +67,9 @@ export var syncedBlockPlugin = function syncedBlockPlugin(_ref) {
|
|
|
66
67
|
priority: 800,
|
|
67
68
|
keywords: ['synced', 'block', 'synced-block', 'sync', 'sync-block', 'auto', 'update', 'excerpt', 'connect'],
|
|
68
69
|
keyshortcut: '',
|
|
70
|
+
lozenge: /*#__PURE__*/React.createElement(Lozenge, {
|
|
71
|
+
appearance: "new"
|
|
72
|
+
}, formatMessage(blockTypeMessages.newLozenge)),
|
|
69
73
|
icon: function icon() {
|
|
70
74
|
return /*#__PURE__*/React.createElement(IconSyncBlock, {
|
|
71
75
|
label: formatMessage(blockTypeMessages.syncedBlock)
|
|
@@ -34,6 +34,7 @@ export var CreateSyncedBlockButton = function CreateSyncedBlockButton(_ref) {
|
|
|
34
34
|
}, /*#__PURE__*/React.createElement(ToolbarButton, {
|
|
35
35
|
label: message,
|
|
36
36
|
iconBefore: /*#__PURE__*/React.createElement(BlockSyncedIcon, {
|
|
37
|
+
size: "small",
|
|
37
38
|
label: ""
|
|
38
39
|
}),
|
|
39
40
|
isDisabled: isDisabled,
|
|
@@ -71,13 +71,13 @@ var CopySyncedBlockDropdownItem = function CopySyncedBlockDropdownItem(_ref2) {
|
|
|
71
71
|
export var CreateOrCopySyncedBlockDropdownItem = function CreateOrCopySyncedBlockDropdownItem(_ref3) {
|
|
72
72
|
var api = _ref3.api;
|
|
73
73
|
var _useSharedPluginState2 = useSharedPluginStateWithSelector(api, ['blockControls'], function (states) {
|
|
74
|
-
var _states$blockControls2;
|
|
74
|
+
var _states$blockControls2, _states$blockControls3;
|
|
75
75
|
return {
|
|
76
|
-
|
|
76
|
+
activeNodeType: (_states$blockControls2 = (_states$blockControls3 = states.blockControlsState) === null || _states$blockControls3 === void 0 || (_states$blockControls3 = _states$blockControls3.activeNode) === null || _states$blockControls3 === void 0 ? void 0 : _states$blockControls3.nodeType) !== null && _states$blockControls2 !== void 0 ? _states$blockControls2 : undefined
|
|
77
77
|
};
|
|
78
78
|
}),
|
|
79
|
-
|
|
80
|
-
if (
|
|
79
|
+
activeNodeType = _useSharedPluginState2.activeNodeType;
|
|
80
|
+
if (activeNodeType === 'syncBlock' || activeNodeType === 'bodiedSyncBlock') {
|
|
81
81
|
return /*#__PURE__*/React.createElement(CopySyncedBlockDropdownItem, {
|
|
82
82
|
api: api
|
|
83
83
|
});
|
|
@@ -4,6 +4,8 @@ import { useSharedPluginStateWithSelector } from '@atlaskit/editor-common/hooks'
|
|
|
4
4
|
import { syncBlockMessages } from '@atlaskit/editor-common/messages';
|
|
5
5
|
import { ToolbarDropdownItem } from '@atlaskit/editor-toolbar';
|
|
6
6
|
import BlockSyncedIcon from '@atlaskit/icon-lab/core/block-synced';
|
|
7
|
+
import Lozenge from '@atlaskit/lozenge';
|
|
8
|
+
import { Flex } from '@atlaskit/primitives/compiled';
|
|
7
9
|
import { canBeConvertedToSyncBlock } from '../pm-plugins/utils/utils';
|
|
8
10
|
export var CreateSyncedBlockItem = function CreateSyncedBlockItem(_ref) {
|
|
9
11
|
var api = _ref.api;
|
|
@@ -28,7 +30,13 @@ export var CreateSyncedBlockItem = function CreateSyncedBlockItem(_ref) {
|
|
|
28
30
|
onClick: onClick,
|
|
29
31
|
isDisabled: isDisabled,
|
|
30
32
|
elemBefore: /*#__PURE__*/React.createElement(BlockSyncedIcon, {
|
|
33
|
+
size: "small",
|
|
31
34
|
label: ""
|
|
32
35
|
})
|
|
33
|
-
},
|
|
36
|
+
}, /*#__PURE__*/React.createElement(Flex, {
|
|
37
|
+
alignItems: "center",
|
|
38
|
+
gap: "space.050"
|
|
39
|
+
}, message, /*#__PURE__*/React.createElement(Lozenge, {
|
|
40
|
+
appearance: "new"
|
|
41
|
+
}, intl.formatMessage(syncBlockMessages.newLozenge))));
|
|
34
42
|
};
|
|
@@ -1,9 +1,12 @@
|
|
|
1
1
|
import { SafePlugin } from '@atlaskit/editor-common/safe-plugin';
|
|
2
2
|
import type { ExtractInjectionAPI, PMPluginFactoryParams } from '@atlaskit/editor-common/types';
|
|
3
3
|
import { PluginKey } from '@atlaskit/editor-prosemirror/state';
|
|
4
|
+
import type { DecorationSet } from '@atlaskit/editor-prosemirror/view';
|
|
4
5
|
import type { SyncBlockStoreManager } from '@atlaskit/editor-synced-block-provider';
|
|
5
6
|
import type { SyncedBlockPlugin, SyncedBlockPluginOptions } from '../syncedBlockPluginType';
|
|
6
7
|
export declare const syncedBlockPluginKey: PluginKey<any>;
|
|
7
|
-
type SyncedBlockPluginState = {
|
|
8
|
+
type SyncedBlockPluginState = {
|
|
9
|
+
decorationSet: DecorationSet;
|
|
10
|
+
};
|
|
8
11
|
export declare const createPlugin: (options: SyncedBlockPluginOptions | undefined, pmPluginFactoryParams: PMPluginFactoryParams, syncBlockStore: SyncBlockStoreManager, api?: ExtractInjectionAPI<SyncedBlockPlugin>) => SafePlugin<SyncedBlockPluginState>;
|
|
9
12
|
export {};
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type { Node as PMNode, Schema } from '@atlaskit/editor-prosemirror/model';
|
|
2
|
+
import type { Selection } from '@atlaskit/editor-prosemirror/state';
|
|
3
|
+
import { DecorationSet } from "@atlaskit/editor-prosemirror/view";
|
|
4
|
+
export declare const calculateDecorations: (doc: PMNode, selection: Selection, schema: Schema) => DecorationSet;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { EventDispatcher } from '@atlaskit/editor-common/event-dispatcher';
|
|
2
|
-
import type { EditorCommand, NextEditorPlugin, OptionalPlugin } from '@atlaskit/editor-common/types';
|
|
2
|
+
import type { EditorCommand, LongPressSelectionPluginOptions, NextEditorPlugin, OptionalPlugin } from '@atlaskit/editor-common/types';
|
|
3
3
|
import type { JSONDocNode } from '@atlaskit/editor-json-transformer';
|
|
4
4
|
import type { AnalyticsPlugin } from '@atlaskit/editor-plugin-analytics';
|
|
5
5
|
import type { BlockControlsPlugin } from '@atlaskit/editor-plugin-block-controls';
|
|
@@ -35,10 +35,10 @@ export type SyncedBlockEditorProps = {
|
|
|
35
35
|
export type SyncedBlockRendererProps = {
|
|
36
36
|
useFetchSyncBlockData: () => UseFetchSyncBlockDataResult;
|
|
37
37
|
};
|
|
38
|
-
export
|
|
38
|
+
export interface SyncedBlockPluginOptions extends LongPressSelectionPluginOptions {
|
|
39
39
|
syncBlockDataProvider: SyncBlockDataProvider;
|
|
40
40
|
syncedBlockRenderer: (props: SyncedBlockRendererProps) => React.JSX.Element;
|
|
41
|
-
}
|
|
41
|
+
}
|
|
42
42
|
export type SyncedBlockPlugin = NextEditorPlugin<'syncedBlock', {
|
|
43
43
|
actions: {
|
|
44
44
|
/**
|
|
@@ -1,9 +1,12 @@
|
|
|
1
1
|
import { SafePlugin } from '@atlaskit/editor-common/safe-plugin';
|
|
2
2
|
import type { ExtractInjectionAPI, PMPluginFactoryParams } from '@atlaskit/editor-common/types';
|
|
3
3
|
import { PluginKey } from '@atlaskit/editor-prosemirror/state';
|
|
4
|
+
import type { DecorationSet } from '@atlaskit/editor-prosemirror/view';
|
|
4
5
|
import type { SyncBlockStoreManager } from '@atlaskit/editor-synced-block-provider';
|
|
5
6
|
import type { SyncedBlockPlugin, SyncedBlockPluginOptions } from '../syncedBlockPluginType';
|
|
6
7
|
export declare const syncedBlockPluginKey: PluginKey<any>;
|
|
7
|
-
type SyncedBlockPluginState = {
|
|
8
|
+
type SyncedBlockPluginState = {
|
|
9
|
+
decorationSet: DecorationSet;
|
|
10
|
+
};
|
|
8
11
|
export declare const createPlugin: (options: SyncedBlockPluginOptions | undefined, pmPluginFactoryParams: PMPluginFactoryParams, syncBlockStore: SyncBlockStoreManager, api?: ExtractInjectionAPI<SyncedBlockPlugin>) => SafePlugin<SyncedBlockPluginState>;
|
|
9
12
|
export {};
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type { Node as PMNode, Schema } from '@atlaskit/editor-prosemirror/model';
|
|
2
|
+
import type { Selection } from '@atlaskit/editor-prosemirror/state';
|
|
3
|
+
import { DecorationSet } from "@atlaskit/editor-prosemirror/view";
|
|
4
|
+
export declare const calculateDecorations: (doc: PMNode, selection: Selection, schema: Schema) => DecorationSet;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { EventDispatcher } from '@atlaskit/editor-common/event-dispatcher';
|
|
2
|
-
import type { EditorCommand, NextEditorPlugin, OptionalPlugin } from '@atlaskit/editor-common/types';
|
|
2
|
+
import type { EditorCommand, LongPressSelectionPluginOptions, NextEditorPlugin, OptionalPlugin } from '@atlaskit/editor-common/types';
|
|
3
3
|
import type { JSONDocNode } from '@atlaskit/editor-json-transformer';
|
|
4
4
|
import type { AnalyticsPlugin } from '@atlaskit/editor-plugin-analytics';
|
|
5
5
|
import type { BlockControlsPlugin } from '@atlaskit/editor-plugin-block-controls';
|
|
@@ -35,10 +35,10 @@ export type SyncedBlockEditorProps = {
|
|
|
35
35
|
export type SyncedBlockRendererProps = {
|
|
36
36
|
useFetchSyncBlockData: () => UseFetchSyncBlockDataResult;
|
|
37
37
|
};
|
|
38
|
-
export
|
|
38
|
+
export interface SyncedBlockPluginOptions extends LongPressSelectionPluginOptions {
|
|
39
39
|
syncBlockDataProvider: SyncBlockDataProvider;
|
|
40
40
|
syncedBlockRenderer: (props: SyncedBlockRendererProps) => React.JSX.Element;
|
|
41
|
-
}
|
|
41
|
+
}
|
|
42
42
|
export type SyncedBlockPlugin = NextEditorPlugin<'syncedBlock', {
|
|
43
43
|
actions: {
|
|
44
44
|
/**
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@atlaskit/editor-plugin-synced-block",
|
|
3
|
-
"version": "4.2.
|
|
3
|
+
"version": "4.2.6",
|
|
4
4
|
"description": "SyncedBlock plugin for @atlaskit/editor-core",
|
|
5
5
|
"author": "Atlassian Pty Ltd",
|
|
6
6
|
"license": "Apache-2.0",
|
|
@@ -38,7 +38,7 @@
|
|
|
38
38
|
"@atlaskit/editor-plugin-selection": "^6.1.0",
|
|
39
39
|
"@atlaskit/editor-prosemirror": "7.0.0",
|
|
40
40
|
"@atlaskit/editor-shared-styles": "^3.9.0",
|
|
41
|
-
"@atlaskit/editor-synced-block-provider": "^2.
|
|
41
|
+
"@atlaskit/editor-synced-block-provider": "^2.8.0",
|
|
42
42
|
"@atlaskit/editor-tables": "^2.9.0",
|
|
43
43
|
"@atlaskit/editor-toolbar": "^0.17.0",
|
|
44
44
|
"@atlaskit/icon": "29.0.0",
|