@atlaskit/editor-plugin-synced-block 4.2.5 → 4.2.7
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/dist/cjs/pm-plugins/main.js +35 -7
- package/dist/cjs/pm-plugins/utils/selection-decorations.js +22 -0
- package/dist/cjs/ui/CreateSyncedBlockDropdownItem.js +8 -8
- package/dist/es2019/pm-plugins/main.js +31 -7
- package/dist/es2019/pm-plugins/utils/selection-decorations.js +20 -0
- package/dist/es2019/ui/CreateSyncedBlockDropdownItem.js +8 -8
- package/dist/esm/pm-plugins/main.js +34 -7
- package/dist/esm/pm-plugins/utils/selection-decorations.js +16 -0
- package/dist/esm/ui/CreateSyncedBlockDropdownItem.js +8 -8
- 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 +4 -4
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,22 @@
|
|
|
1
1
|
# @atlaskit/editor-plugin-synced-block
|
|
2
2
|
|
|
3
|
+
## 4.2.7
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- [`42b421f5241a4`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/42b421f5241a4) -
|
|
8
|
+
EDITOR-2865 Add menuTriggerByNode to block plugin state and use for sync block options
|
|
9
|
+
|
|
10
|
+
## 4.2.6
|
|
11
|
+
|
|
12
|
+
### Patch Changes
|
|
13
|
+
|
|
14
|
+
- [`9e7aa73151ed0`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/9e7aa73151ed0) -
|
|
15
|
+
[ux] EDITOR-2670 add selected state for sync block when selection is inside
|
|
16
|
+
- [`18f894b7433f3`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/18f894b7433f3) -
|
|
17
|
+
EDITOR-2863 Fix Add copy sync block option to block menu
|
|
18
|
+
- Updated dependencies
|
|
19
|
+
|
|
3
20
|
## 4.2.5
|
|
4
21
|
|
|
5
22
|
### 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
|
+
};
|
|
@@ -20,15 +20,15 @@ var CreateSyncedBlockDropdownItem = function CreateSyncedBlockDropdownItem(_ref)
|
|
|
20
20
|
var _useIntl = (0, _reactIntlNext.useIntl)(),
|
|
21
21
|
formatMessage = _useIntl.formatMessage;
|
|
22
22
|
var _useSharedPluginState = (0, _hooks.useSharedPluginStateWithSelector)(api, ['selection', 'blockControls'], function (states) {
|
|
23
|
-
var _states$selectionStat, _states$blockControls;
|
|
23
|
+
var _states$selectionStat, _states$blockControls, _states$blockControls2;
|
|
24
24
|
return {
|
|
25
25
|
selection: (_states$selectionStat = states.selectionState) === null || _states$selectionStat === void 0 ? void 0 : _states$selectionStat.selection,
|
|
26
|
-
|
|
26
|
+
menuTriggerByNode: (_states$blockControls = (_states$blockControls2 = states.blockControlsState) === null || _states$blockControls2 === void 0 ? void 0 : _states$blockControls2.menuTriggerByNode) !== null && _states$blockControls !== void 0 ? _states$blockControls : undefined
|
|
27
27
|
};
|
|
28
28
|
}),
|
|
29
29
|
selection = _useSharedPluginState.selection,
|
|
30
|
-
|
|
31
|
-
var isNested =
|
|
30
|
+
menuTriggerByNode = _useSharedPluginState.menuTriggerByNode;
|
|
31
|
+
var isNested = menuTriggerByNode && menuTriggerByNode.rootPos !== menuTriggerByNode.pos;
|
|
32
32
|
var canBeConverted = (0, _react.useMemo)(function () {
|
|
33
33
|
return selection && (0, _utils.canBeConvertedToSyncBlock)(selection);
|
|
34
34
|
}, [selection]);
|
|
@@ -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$
|
|
83
|
+
var _states$blockControls3, _states$blockControls4;
|
|
84
84
|
return {
|
|
85
|
-
|
|
85
|
+
menuTriggerByNode: (_states$blockControls3 = (_states$blockControls4 = states.blockControlsState) === null || _states$blockControls4 === void 0 ? void 0 : _states$blockControls4.menuTriggerByNode) !== null && _states$blockControls3 !== void 0 ? _states$blockControls3 : undefined
|
|
86
86
|
};
|
|
87
87
|
}),
|
|
88
|
-
|
|
89
|
-
if (
|
|
88
|
+
menuTriggerByNode = _useSharedPluginState2.menuTriggerByNode;
|
|
89
|
+
if ((menuTriggerByNode === null || menuTriggerByNode === void 0 ? void 0 : menuTriggerByNode.nodeType) === 'syncBlock' || (menuTriggerByNode === null || menuTriggerByNode === void 0 ? void 0 : menuTriggerByNode.nodeType) === 'bodiedSyncBlock') {
|
|
90
90
|
return /*#__PURE__*/_react.default.createElement(CopySyncedBlockDropdownItem, {
|
|
91
91
|
api: api
|
|
92
92
|
});
|
|
@@ -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
|
+
};
|
|
@@ -14,15 +14,15 @@ const CreateSyncedBlockDropdownItem = ({
|
|
|
14
14
|
} = useIntl();
|
|
15
15
|
const {
|
|
16
16
|
selection,
|
|
17
|
-
|
|
17
|
+
menuTriggerByNode
|
|
18
18
|
} = useSharedPluginStateWithSelector(api, ['selection', 'blockControls'], states => {
|
|
19
|
-
var _states$selectionStat, _states$blockControls;
|
|
19
|
+
var _states$selectionStat, _states$blockControls, _states$blockControls2;
|
|
20
20
|
return {
|
|
21
21
|
selection: (_states$selectionStat = states.selectionState) === null || _states$selectionStat === void 0 ? void 0 : _states$selectionStat.selection,
|
|
22
|
-
|
|
22
|
+
menuTriggerByNode: (_states$blockControls = (_states$blockControls2 = states.blockControlsState) === null || _states$blockControls2 === void 0 ? void 0 : _states$blockControls2.menuTriggerByNode) !== null && _states$blockControls !== void 0 ? _states$blockControls : undefined
|
|
23
23
|
};
|
|
24
24
|
});
|
|
25
|
-
const isNested =
|
|
25
|
+
const isNested = menuTriggerByNode && menuTriggerByNode.rootPos !== menuTriggerByNode.pos;
|
|
26
26
|
const canBeConverted = useMemo(() => selection && canBeConvertedToSyncBlock(selection), [selection]);
|
|
27
27
|
if (isNested || !canBeConverted) {
|
|
28
28
|
return null;
|
|
@@ -75,14 +75,14 @@ export const CreateOrCopySyncedBlockDropdownItem = ({
|
|
|
75
75
|
api
|
|
76
76
|
}) => {
|
|
77
77
|
const {
|
|
78
|
-
|
|
78
|
+
menuTriggerByNode
|
|
79
79
|
} = useSharedPluginStateWithSelector(api, ['blockControls'], states => {
|
|
80
|
-
var _states$
|
|
80
|
+
var _states$blockControls3, _states$blockControls4;
|
|
81
81
|
return {
|
|
82
|
-
|
|
82
|
+
menuTriggerByNode: (_states$blockControls3 = (_states$blockControls4 = states.blockControlsState) === null || _states$blockControls4 === void 0 ? void 0 : _states$blockControls4.menuTriggerByNode) !== null && _states$blockControls3 !== void 0 ? _states$blockControls3 : undefined
|
|
83
83
|
};
|
|
84
84
|
});
|
|
85
|
-
if (
|
|
85
|
+
if ((menuTriggerByNode === null || menuTriggerByNode === void 0 ? void 0 : menuTriggerByNode.nodeType) === 'syncBlock' || (menuTriggerByNode === null || menuTriggerByNode === void 0 ? void 0 : menuTriggerByNode.nodeType) === 'bodiedSyncBlock') {
|
|
86
86
|
return /*#__PURE__*/React.createElement(CopySyncedBlockDropdownItem, {
|
|
87
87
|
api: api
|
|
88
88
|
});
|
|
@@ -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
|
+
};
|
|
@@ -11,15 +11,15 @@ var CreateSyncedBlockDropdownItem = function CreateSyncedBlockDropdownItem(_ref)
|
|
|
11
11
|
var _useIntl = useIntl(),
|
|
12
12
|
formatMessage = _useIntl.formatMessage;
|
|
13
13
|
var _useSharedPluginState = useSharedPluginStateWithSelector(api, ['selection', 'blockControls'], function (states) {
|
|
14
|
-
var _states$selectionStat, _states$blockControls;
|
|
14
|
+
var _states$selectionStat, _states$blockControls, _states$blockControls2;
|
|
15
15
|
return {
|
|
16
16
|
selection: (_states$selectionStat = states.selectionState) === null || _states$selectionStat === void 0 ? void 0 : _states$selectionStat.selection,
|
|
17
|
-
|
|
17
|
+
menuTriggerByNode: (_states$blockControls = (_states$blockControls2 = states.blockControlsState) === null || _states$blockControls2 === void 0 ? void 0 : _states$blockControls2.menuTriggerByNode) !== null && _states$blockControls !== void 0 ? _states$blockControls : undefined
|
|
18
18
|
};
|
|
19
19
|
}),
|
|
20
20
|
selection = _useSharedPluginState.selection,
|
|
21
|
-
|
|
22
|
-
var isNested =
|
|
21
|
+
menuTriggerByNode = _useSharedPluginState.menuTriggerByNode;
|
|
22
|
+
var isNested = menuTriggerByNode && menuTriggerByNode.rootPos !== menuTriggerByNode.pos;
|
|
23
23
|
var canBeConverted = useMemo(function () {
|
|
24
24
|
return selection && canBeConvertedToSyncBlock(selection);
|
|
25
25
|
}, [selection]);
|
|
@@ -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$
|
|
74
|
+
var _states$blockControls3, _states$blockControls4;
|
|
75
75
|
return {
|
|
76
|
-
|
|
76
|
+
menuTriggerByNode: (_states$blockControls3 = (_states$blockControls4 = states.blockControlsState) === null || _states$blockControls4 === void 0 ? void 0 : _states$blockControls4.menuTriggerByNode) !== null && _states$blockControls3 !== void 0 ? _states$blockControls3 : undefined
|
|
77
77
|
};
|
|
78
78
|
}),
|
|
79
|
-
|
|
80
|
-
if (
|
|
79
|
+
menuTriggerByNode = _useSharedPluginState2.menuTriggerByNode;
|
|
80
|
+
if ((menuTriggerByNode === null || menuTriggerByNode === void 0 ? void 0 : menuTriggerByNode.nodeType) === 'syncBlock' || (menuTriggerByNode === null || menuTriggerByNode === void 0 ? void 0 : menuTriggerByNode.nodeType) === 'bodiedSyncBlock') {
|
|
81
81
|
return /*#__PURE__*/React.createElement(CopySyncedBlockDropdownItem, {
|
|
82
82
|
api: api
|
|
83
83
|
});
|
|
@@ -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.7",
|
|
4
4
|
"description": "SyncedBlock plugin for @atlaskit/editor-core",
|
|
5
5
|
"author": "Atlassian Pty Ltd",
|
|
6
6
|
"license": "Apache-2.0",
|
|
@@ -38,14 +38,14 @@
|
|
|
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",
|
|
45
45
|
"@atlaskit/icon-lab": "^5.12.0",
|
|
46
46
|
"@atlaskit/logo": "^19.9.0",
|
|
47
47
|
"@atlaskit/lozenge": "^13.1.0",
|
|
48
|
-
"@atlaskit/modal-dialog": "^14.
|
|
48
|
+
"@atlaskit/modal-dialog": "^14.7.0",
|
|
49
49
|
"@atlaskit/primitives": "^16.1.0",
|
|
50
50
|
"@atlaskit/tooltip": "^20.8.0",
|
|
51
51
|
"@atlaskit/visually-hidden": "^3.0.0",
|
|
@@ -53,7 +53,7 @@
|
|
|
53
53
|
"react-intl-next": "npm:react-intl@^5.18.1"
|
|
54
54
|
},
|
|
55
55
|
"peerDependencies": {
|
|
56
|
-
"@atlaskit/editor-common": "^110.
|
|
56
|
+
"@atlaskit/editor-common": "^110.29.0",
|
|
57
57
|
"react": "^18.2.0"
|
|
58
58
|
},
|
|
59
59
|
"devDependencies": {
|