@atlaskit/editor-plugin-selection-extension 3.1.0 → 3.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 +24 -0
- package/dist/cjs/pm-plugins/actions.js +30 -9
- package/dist/cjs/pm-plugins/main.js +17 -1
- package/dist/cjs/types/index.js +1 -0
- package/dist/cjs/ui/extension/SelectionExtensionComponentWrapper.js +12 -6
- package/dist/es2019/pm-plugins/actions.js +32 -9
- package/dist/es2019/pm-plugins/main.js +17 -1
- package/dist/es2019/types/index.js +1 -0
- package/dist/es2019/ui/extension/SelectionExtensionComponentWrapper.js +11 -4
- package/dist/esm/pm-plugins/actions.js +30 -9
- package/dist/esm/pm-plugins/main.js +17 -1
- package/dist/esm/types/index.js +1 -0
- package/dist/esm/ui/extension/SelectionExtensionComponentWrapper.js +13 -7
- package/dist/types/index.d.ts +1 -1
- package/dist/types/pm-plugins/actions.d.ts +1 -1
- package/dist/types/pm-plugins/main.d.ts +14 -0
- package/dist/types/selectionExtensionPluginType.d.ts +1 -1
- package/dist/types/types/index.d.ts +4 -1
- package/dist/types-ts4.5/index.d.ts +1 -1
- package/dist/types-ts4.5/pm-plugins/actions.d.ts +1 -1
- package/dist/types-ts4.5/pm-plugins/main.d.ts +14 -0
- package/dist/types-ts4.5/selectionExtensionPluginType.d.ts +1 -1
- package/dist/types-ts4.5/types/index.d.ts +4 -1
- package/package.json +5 -5
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,29 @@
|
|
|
1
1
|
# @atlaskit/editor-plugin-selection-extension
|
|
2
2
|
|
|
3
|
+
## 3.2.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- [#189314](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/pull-requests/189314)
|
|
8
|
+
[`22c6251496010`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/22c6251496010) -
|
|
9
|
+
Exported missing types that were already being inferred from existing exports
|
|
10
|
+
|
|
11
|
+
### Patch Changes
|
|
12
|
+
|
|
13
|
+
- Updated dependencies
|
|
14
|
+
|
|
15
|
+
## 3.1.1
|
|
16
|
+
|
|
17
|
+
### Patch Changes
|
|
18
|
+
|
|
19
|
+
- [#183521](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/pull-requests/183521)
|
|
20
|
+
[`86379b9b3d99e`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/86379b9b3d99e) -
|
|
21
|
+
Insert links to page bottom as fallback when changes detect
|
|
22
|
+
- [#183158](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/pull-requests/183158)
|
|
23
|
+
[`d6096ec5c8ad9`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/d6096ec5c8ad9) -
|
|
24
|
+
Migrate to useSharedPluginStateWithSelector
|
|
25
|
+
- Updated dependencies
|
|
26
|
+
|
|
3
27
|
## 3.1.0
|
|
4
28
|
|
|
5
29
|
### Minor Changes
|
|
@@ -4,6 +4,7 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.insertSmartLinks = void 0;
|
|
7
|
+
var _types = require("../types");
|
|
7
8
|
var _main = require("./main");
|
|
8
9
|
var _utils = require("./utils");
|
|
9
10
|
var _getOffsetByPath = require("./utils/getOffsetByPath");
|
|
@@ -17,11 +18,9 @@ var insertLinkTr = function insertLinkTr(tr, link, offset, schema) {
|
|
|
17
18
|
};
|
|
18
19
|
var insertSmartLinks = exports.insertSmartLinks = function insertSmartLinks(linkInsertionOption, selectedNodeAdf) {
|
|
19
20
|
return function (state, dispatch) {
|
|
21
|
+
var _selectionExtensionPl;
|
|
20
22
|
var tr = state.tr,
|
|
21
23
|
schema = state.schema;
|
|
22
|
-
if (!Array.isArray(linkInsertionOption)) {
|
|
23
|
-
linkInsertionOption = [linkInsertionOption];
|
|
24
|
-
}
|
|
25
24
|
if (linkInsertionOption.length === 0) {
|
|
26
25
|
return {
|
|
27
26
|
status: 'error',
|
|
@@ -29,14 +28,32 @@ var insertSmartLinks = exports.insertSmartLinks = function insertSmartLinks(link
|
|
|
29
28
|
};
|
|
30
29
|
}
|
|
31
30
|
|
|
32
|
-
//
|
|
33
|
-
// if there is change, we
|
|
34
|
-
|
|
31
|
+
// we need to track if any changes were made since user click the toolbar button
|
|
32
|
+
// if there is change, we insert the links at the bottom of the page instead
|
|
33
|
+
var docChangedAfterClick = ((_selectionExtensionPl = _main.selectionExtensionPluginKey.getState(state)) === null || _selectionExtensionPl === void 0 ? void 0 : _selectionExtensionPl.docChangedAfterClick) || false;
|
|
34
|
+
if (docChangedAfterClick) {
|
|
35
|
+
var docEnd = state.doc.content.size;
|
|
36
|
+
linkInsertionOption.forEach(function (option) {
|
|
37
|
+
var link = option.link;
|
|
38
|
+
tr.insert(tr.mapping.map(docEnd), schema.nodes.inlineCard.createChecked({
|
|
39
|
+
url: link
|
|
40
|
+
}));
|
|
41
|
+
});
|
|
42
|
+
tr.setMeta(_main.selectionExtensionPluginKey, {
|
|
43
|
+
type: _types.SelectionExtensionActionTypes.START_TRACK_CHANGES,
|
|
44
|
+
startTrackChanges: false // Reset the flag when starting to track changes
|
|
45
|
+
});
|
|
46
|
+
dispatch(tr);
|
|
47
|
+
return {
|
|
48
|
+
status: 'success',
|
|
49
|
+
message: 'Links inserted to page bottom successfully'
|
|
50
|
+
};
|
|
51
|
+
}
|
|
35
52
|
var newTr = tr;
|
|
36
53
|
try {
|
|
37
|
-
var
|
|
38
|
-
var selectedNode = (
|
|
39
|
-
var nodePos = (
|
|
54
|
+
var _selectionExtensionPl2, _selectionExtensionPl3;
|
|
55
|
+
var selectedNode = (_selectionExtensionPl2 = _main.selectionExtensionPluginKey.getState(state)) === null || _selectionExtensionPl2 === void 0 ? void 0 : _selectionExtensionPl2.selectedNode;
|
|
56
|
+
var nodePos = (_selectionExtensionPl3 = _main.selectionExtensionPluginKey.getState(state)) === null || _selectionExtensionPl3 === void 0 ? void 0 : _selectionExtensionPl3.nodePos;
|
|
40
57
|
if (!selectedNode || nodePos === undefined) {
|
|
41
58
|
throw new Error('No selected node or node position found');
|
|
42
59
|
}
|
|
@@ -60,6 +77,10 @@ var insertSmartLinks = exports.insertSmartLinks = function insertSmartLinks(link
|
|
|
60
77
|
message: error instanceof Error ? error.message : 'Unknown error'
|
|
61
78
|
};
|
|
62
79
|
}
|
|
80
|
+
newTr.setMeta(_main.selectionExtensionPluginKey, {
|
|
81
|
+
type: _types.SelectionExtensionActionTypes.START_TRACK_CHANGES,
|
|
82
|
+
startTrackChanges: false // Reset the flag when starting to track changes
|
|
83
|
+
});
|
|
63
84
|
dispatch(newTr);
|
|
64
85
|
return {
|
|
65
86
|
status: 'success',
|
|
@@ -8,6 +8,7 @@ exports.selectionExtensionPluginKey = exports.createPlugin = void 0;
|
|
|
8
8
|
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
9
9
|
var _safePlugin = require("@atlaskit/editor-common/safe-plugin");
|
|
10
10
|
var _state = require("@atlaskit/editor-prosemirror/state");
|
|
11
|
+
var _transform = require("@atlaskit/editor-prosemirror/transform");
|
|
11
12
|
var _types = require("../types");
|
|
12
13
|
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
13
14
|
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { (0, _defineProperty2.default)(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
@@ -35,8 +36,23 @@ var createPlugin = exports.createPlugin = function createPlugin() {
|
|
|
35
36
|
case _types.SelectionExtensionActionTypes.SET_SELECTED_NODE:
|
|
36
37
|
return _objectSpread(_objectSpread({}, pluginState), {}, {
|
|
37
38
|
selectedNode: meta.selectedNode,
|
|
38
|
-
nodePos: meta.nodePos
|
|
39
|
+
nodePos: meta.nodePos,
|
|
40
|
+
startTrackChanges: true,
|
|
41
|
+
docChangedAfterClick: false // Reset the flag when starting to track changes
|
|
39
42
|
});
|
|
43
|
+
case _types.SelectionExtensionActionTypes.START_TRACK_CHANGES:
|
|
44
|
+
return _objectSpread(_objectSpread({}, pluginState), {}, {
|
|
45
|
+
startTrackChanges: meta.startTrackChanges
|
|
46
|
+
});
|
|
47
|
+
}
|
|
48
|
+
var docChangedAfterClick = pluginState.startTrackChanges && tr.steps.some(function (step) {
|
|
49
|
+
return step instanceof _transform.ReplaceStep || step instanceof _transform.ReplaceAroundStep;
|
|
50
|
+
});
|
|
51
|
+
if (docChangedAfterClick) {
|
|
52
|
+
return _objectSpread(_objectSpread({}, pluginState), {}, {
|
|
53
|
+
docChangedAfterClick: true,
|
|
54
|
+
startTrackChanges: false // Reset the flag to stop tracking after the document has changed
|
|
55
|
+
});
|
|
40
56
|
}
|
|
41
57
|
return pluginState;
|
|
42
58
|
}
|
package/dist/cjs/types/index.js
CHANGED
|
@@ -15,5 +15,6 @@ var SelectionExtensionActionTypes = exports.SelectionExtensionActionTypes = /*#_
|
|
|
15
15
|
SelectionExtensionActionTypes["UPDATE_ACTIVE_EXTENSION_COORDS"] = "update-active-extension-coords";
|
|
16
16
|
SelectionExtensionActionTypes["CLEAR_ACTIVE_EXTENSION"] = "clear-active-extension";
|
|
17
17
|
SelectionExtensionActionTypes["SET_SELECTED_NODE"] = "set-selected-node";
|
|
18
|
+
SelectionExtensionActionTypes["START_TRACK_CHANGES"] = "start-track-changes";
|
|
18
19
|
return SelectionExtensionActionTypes;
|
|
19
20
|
}({});
|
|
@@ -8,20 +8,26 @@ exports.SelectionExtensionComponentWrapper = void 0;
|
|
|
8
8
|
var _react = _interopRequireWildcard(require("react"));
|
|
9
9
|
var _analytics = require("@atlaskit/editor-common/analytics");
|
|
10
10
|
var _hooks = require("@atlaskit/editor-common/hooks");
|
|
11
|
-
var _useSharedPluginStateSelector = require("@atlaskit/editor-common/use-shared-plugin-state-selector");
|
|
12
11
|
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); }
|
|
13
12
|
var useSharedState = (0, _hooks.sharedPluginStateHookMigratorFactory)(function (api) {
|
|
14
|
-
var
|
|
15
|
-
|
|
13
|
+
var _useSharedPluginState = (0, _hooks.useSharedPluginStateWithSelector)(api, ['selectionExtension', 'editorViewMode'], function (states) {
|
|
14
|
+
var _states$selectionExte, _states$editorViewMod;
|
|
15
|
+
return {
|
|
16
|
+
activeExtension: (_states$selectionExte = states.selectionExtensionState) === null || _states$selectionExte === void 0 ? void 0 : _states$selectionExte.activeExtension,
|
|
17
|
+
mode: (_states$editorViewMod = states.editorViewModeState) === null || _states$editorViewMod === void 0 ? void 0 : _states$editorViewMod.mode
|
|
18
|
+
};
|
|
19
|
+
}),
|
|
20
|
+
activeExtension = _useSharedPluginState.activeExtension,
|
|
21
|
+
mode = _useSharedPluginState.mode;
|
|
16
22
|
return {
|
|
17
23
|
editorViewModeState: undefined,
|
|
18
24
|
mode: mode,
|
|
19
25
|
activeExtension: activeExtension
|
|
20
26
|
};
|
|
21
27
|
}, function (api) {
|
|
22
|
-
var
|
|
23
|
-
selectionExtensionState =
|
|
24
|
-
editorViewModeState =
|
|
28
|
+
var _useSharedPluginState2 = (0, _hooks.useSharedPluginState)(api, ['selectionExtension', 'editorViewMode']),
|
|
29
|
+
selectionExtensionState = _useSharedPluginState2.selectionExtensionState,
|
|
30
|
+
editorViewModeState = _useSharedPluginState2.editorViewModeState;
|
|
25
31
|
return {
|
|
26
32
|
editorViewModeState: editorViewModeState,
|
|
27
33
|
mode: editorViewModeState === null || editorViewModeState === void 0 ? void 0 : editorViewModeState.mode,
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { SelectionExtensionActionTypes } from '../types';
|
|
1
2
|
import { selectionExtensionPluginKey } from './main';
|
|
2
3
|
import { validateSelectedNode } from './utils';
|
|
3
4
|
import { getOffsetByPath } from './utils/getOffsetByPath';
|
|
@@ -10,13 +11,11 @@ const insertLinkTr = (tr, link, offset, schema) => {
|
|
|
10
11
|
return tr.replaceWith(newFromPos, newToPos, smartLink);
|
|
11
12
|
};
|
|
12
13
|
export const insertSmartLinks = (linkInsertionOption, selectedNodeAdf) => (state, dispatch) => {
|
|
14
|
+
var _selectionExtensionPl;
|
|
13
15
|
const {
|
|
14
16
|
tr,
|
|
15
17
|
schema
|
|
16
18
|
} = state;
|
|
17
|
-
if (!Array.isArray(linkInsertionOption)) {
|
|
18
|
-
linkInsertionOption = [linkInsertionOption];
|
|
19
|
-
}
|
|
20
19
|
if (linkInsertionOption.length === 0) {
|
|
21
20
|
return {
|
|
22
21
|
status: 'error',
|
|
@@ -24,14 +23,34 @@ export const insertSmartLinks = (linkInsertionOption, selectedNodeAdf) => (state
|
|
|
24
23
|
};
|
|
25
24
|
}
|
|
26
25
|
|
|
27
|
-
//
|
|
28
|
-
// if there is change, we
|
|
29
|
-
|
|
26
|
+
// we need to track if any changes were made since user click the toolbar button
|
|
27
|
+
// if there is change, we insert the links at the bottom of the page instead
|
|
28
|
+
const docChangedAfterClick = ((_selectionExtensionPl = selectionExtensionPluginKey.getState(state)) === null || _selectionExtensionPl === void 0 ? void 0 : _selectionExtensionPl.docChangedAfterClick) || false;
|
|
29
|
+
if (docChangedAfterClick) {
|
|
30
|
+
const docEnd = state.doc.content.size;
|
|
31
|
+
linkInsertionOption.forEach(option => {
|
|
32
|
+
const {
|
|
33
|
+
link
|
|
34
|
+
} = option;
|
|
35
|
+
tr.insert(tr.mapping.map(docEnd), schema.nodes.inlineCard.createChecked({
|
|
36
|
+
url: link
|
|
37
|
+
}));
|
|
38
|
+
});
|
|
39
|
+
tr.setMeta(selectionExtensionPluginKey, {
|
|
40
|
+
type: SelectionExtensionActionTypes.START_TRACK_CHANGES,
|
|
41
|
+
startTrackChanges: false // Reset the flag when starting to track changes
|
|
42
|
+
});
|
|
43
|
+
dispatch(tr);
|
|
44
|
+
return {
|
|
45
|
+
status: 'success',
|
|
46
|
+
message: 'Links inserted to page bottom successfully'
|
|
47
|
+
};
|
|
48
|
+
}
|
|
30
49
|
let newTr = tr;
|
|
31
50
|
try {
|
|
32
|
-
var
|
|
33
|
-
const selectedNode = (
|
|
34
|
-
const nodePos = (
|
|
51
|
+
var _selectionExtensionPl2, _selectionExtensionPl3;
|
|
52
|
+
const selectedNode = (_selectionExtensionPl2 = selectionExtensionPluginKey.getState(state)) === null || _selectionExtensionPl2 === void 0 ? void 0 : _selectionExtensionPl2.selectedNode;
|
|
53
|
+
const nodePos = (_selectionExtensionPl3 = selectionExtensionPluginKey.getState(state)) === null || _selectionExtensionPl3 === void 0 ? void 0 : _selectionExtensionPl3.nodePos;
|
|
35
54
|
if (!selectedNode || nodePos === undefined) {
|
|
36
55
|
throw new Error('No selected node or node position found');
|
|
37
56
|
}
|
|
@@ -59,6 +78,10 @@ export const insertSmartLinks = (linkInsertionOption, selectedNodeAdf) => (state
|
|
|
59
78
|
message: error instanceof Error ? error.message : 'Unknown error'
|
|
60
79
|
};
|
|
61
80
|
}
|
|
81
|
+
newTr.setMeta(selectionExtensionPluginKey, {
|
|
82
|
+
type: SelectionExtensionActionTypes.START_TRACK_CHANGES,
|
|
83
|
+
startTrackChanges: false // Reset the flag when starting to track changes
|
|
84
|
+
});
|
|
62
85
|
dispatch(newTr);
|
|
63
86
|
return {
|
|
64
87
|
status: 'success',
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { SafePlugin } from '@atlaskit/editor-common/safe-plugin';
|
|
2
2
|
import { PluginKey } from '@atlaskit/editor-prosemirror/state';
|
|
3
|
+
import { ReplaceAroundStep, ReplaceStep } from '@atlaskit/editor-prosemirror/transform';
|
|
3
4
|
import { SelectionExtensionActionTypes } from '../types';
|
|
4
5
|
export const selectionExtensionPluginKey = new PluginKey('selectionExtensionPlugin');
|
|
5
6
|
export const createPlugin = () => {
|
|
@@ -28,8 +29,23 @@ export const createPlugin = () => {
|
|
|
28
29
|
return {
|
|
29
30
|
...pluginState,
|
|
30
31
|
selectedNode: meta.selectedNode,
|
|
31
|
-
nodePos: meta.nodePos
|
|
32
|
+
nodePos: meta.nodePos,
|
|
33
|
+
startTrackChanges: true,
|
|
34
|
+
docChangedAfterClick: false // Reset the flag when starting to track changes
|
|
32
35
|
};
|
|
36
|
+
case SelectionExtensionActionTypes.START_TRACK_CHANGES:
|
|
37
|
+
return {
|
|
38
|
+
...pluginState,
|
|
39
|
+
startTrackChanges: meta.startTrackChanges
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
const docChangedAfterClick = pluginState.startTrackChanges && tr.steps.some(step => step instanceof ReplaceStep || step instanceof ReplaceAroundStep);
|
|
43
|
+
if (docChangedAfterClick) {
|
|
44
|
+
return {
|
|
45
|
+
...pluginState,
|
|
46
|
+
docChangedAfterClick: true,
|
|
47
|
+
startTrackChanges: false // Reset the flag to stop tracking after the document has changed
|
|
48
|
+
};
|
|
33
49
|
}
|
|
34
50
|
return pluginState;
|
|
35
51
|
}
|
|
@@ -11,5 +11,6 @@ export let SelectionExtensionActionTypes = /*#__PURE__*/function (SelectionExten
|
|
|
11
11
|
SelectionExtensionActionTypes["UPDATE_ACTIVE_EXTENSION_COORDS"] = "update-active-extension-coords";
|
|
12
12
|
SelectionExtensionActionTypes["CLEAR_ACTIVE_EXTENSION"] = "clear-active-extension";
|
|
13
13
|
SelectionExtensionActionTypes["SET_SELECTED_NODE"] = "set-selected-node";
|
|
14
|
+
SelectionExtensionActionTypes["START_TRACK_CHANGES"] = "start-track-changes";
|
|
14
15
|
return SelectionExtensionActionTypes;
|
|
15
16
|
}({});
|
|
@@ -1,10 +1,17 @@
|
|
|
1
1
|
import React, { useCallback, useEffect, useRef } from 'react';
|
|
2
2
|
import { ACTION, ACTION_SUBJECT, ACTION_SUBJECT_ID, EVENT_TYPE } from '@atlaskit/editor-common/analytics';
|
|
3
|
-
import { useSharedPluginState, sharedPluginStateHookMigratorFactory } from '@atlaskit/editor-common/hooks';
|
|
4
|
-
import { useSharedPluginStateSelector } from '@atlaskit/editor-common/use-shared-plugin-state-selector';
|
|
3
|
+
import { useSharedPluginState, sharedPluginStateHookMigratorFactory, useSharedPluginStateWithSelector } from '@atlaskit/editor-common/hooks';
|
|
5
4
|
const useSharedState = sharedPluginStateHookMigratorFactory(api => {
|
|
6
|
-
const
|
|
7
|
-
|
|
5
|
+
const {
|
|
6
|
+
activeExtension,
|
|
7
|
+
mode
|
|
8
|
+
} = useSharedPluginStateWithSelector(api, ['selectionExtension', 'editorViewMode'], states => {
|
|
9
|
+
var _states$selectionExte, _states$editorViewMod;
|
|
10
|
+
return {
|
|
11
|
+
activeExtension: (_states$selectionExte = states.selectionExtensionState) === null || _states$selectionExte === void 0 ? void 0 : _states$selectionExte.activeExtension,
|
|
12
|
+
mode: (_states$editorViewMod = states.editorViewModeState) === null || _states$editorViewMod === void 0 ? void 0 : _states$editorViewMod.mode
|
|
13
|
+
};
|
|
14
|
+
});
|
|
8
15
|
return {
|
|
9
16
|
editorViewModeState: undefined,
|
|
10
17
|
mode,
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { SelectionExtensionActionTypes } from '../types';
|
|
1
2
|
import { selectionExtensionPluginKey } from './main';
|
|
2
3
|
import { validateSelectedNode } from './utils';
|
|
3
4
|
import { getOffsetByPath } from './utils/getOffsetByPath';
|
|
@@ -11,11 +12,9 @@ var insertLinkTr = function insertLinkTr(tr, link, offset, schema) {
|
|
|
11
12
|
};
|
|
12
13
|
export var insertSmartLinks = function insertSmartLinks(linkInsertionOption, selectedNodeAdf) {
|
|
13
14
|
return function (state, dispatch) {
|
|
15
|
+
var _selectionExtensionPl;
|
|
14
16
|
var tr = state.tr,
|
|
15
17
|
schema = state.schema;
|
|
16
|
-
if (!Array.isArray(linkInsertionOption)) {
|
|
17
|
-
linkInsertionOption = [linkInsertionOption];
|
|
18
|
-
}
|
|
19
18
|
if (linkInsertionOption.length === 0) {
|
|
20
19
|
return {
|
|
21
20
|
status: 'error',
|
|
@@ -23,14 +22,32 @@ export var insertSmartLinks = function insertSmartLinks(linkInsertionOption, sel
|
|
|
23
22
|
};
|
|
24
23
|
}
|
|
25
24
|
|
|
26
|
-
//
|
|
27
|
-
// if there is change, we
|
|
28
|
-
|
|
25
|
+
// we need to track if any changes were made since user click the toolbar button
|
|
26
|
+
// if there is change, we insert the links at the bottom of the page instead
|
|
27
|
+
var docChangedAfterClick = ((_selectionExtensionPl = selectionExtensionPluginKey.getState(state)) === null || _selectionExtensionPl === void 0 ? void 0 : _selectionExtensionPl.docChangedAfterClick) || false;
|
|
28
|
+
if (docChangedAfterClick) {
|
|
29
|
+
var docEnd = state.doc.content.size;
|
|
30
|
+
linkInsertionOption.forEach(function (option) {
|
|
31
|
+
var link = option.link;
|
|
32
|
+
tr.insert(tr.mapping.map(docEnd), schema.nodes.inlineCard.createChecked({
|
|
33
|
+
url: link
|
|
34
|
+
}));
|
|
35
|
+
});
|
|
36
|
+
tr.setMeta(selectionExtensionPluginKey, {
|
|
37
|
+
type: SelectionExtensionActionTypes.START_TRACK_CHANGES,
|
|
38
|
+
startTrackChanges: false // Reset the flag when starting to track changes
|
|
39
|
+
});
|
|
40
|
+
dispatch(tr);
|
|
41
|
+
return {
|
|
42
|
+
status: 'success',
|
|
43
|
+
message: 'Links inserted to page bottom successfully'
|
|
44
|
+
};
|
|
45
|
+
}
|
|
29
46
|
var newTr = tr;
|
|
30
47
|
try {
|
|
31
|
-
var
|
|
32
|
-
var selectedNode = (
|
|
33
|
-
var nodePos = (
|
|
48
|
+
var _selectionExtensionPl2, _selectionExtensionPl3;
|
|
49
|
+
var selectedNode = (_selectionExtensionPl2 = selectionExtensionPluginKey.getState(state)) === null || _selectionExtensionPl2 === void 0 ? void 0 : _selectionExtensionPl2.selectedNode;
|
|
50
|
+
var nodePos = (_selectionExtensionPl3 = selectionExtensionPluginKey.getState(state)) === null || _selectionExtensionPl3 === void 0 ? void 0 : _selectionExtensionPl3.nodePos;
|
|
34
51
|
if (!selectedNode || nodePos === undefined) {
|
|
35
52
|
throw new Error('No selected node or node position found');
|
|
36
53
|
}
|
|
@@ -54,6 +71,10 @@ export var insertSmartLinks = function insertSmartLinks(linkInsertionOption, sel
|
|
|
54
71
|
message: error instanceof Error ? error.message : 'Unknown error'
|
|
55
72
|
};
|
|
56
73
|
}
|
|
74
|
+
newTr.setMeta(selectionExtensionPluginKey, {
|
|
75
|
+
type: SelectionExtensionActionTypes.START_TRACK_CHANGES,
|
|
76
|
+
startTrackChanges: false // Reset the flag when starting to track changes
|
|
77
|
+
});
|
|
57
78
|
dispatch(newTr);
|
|
58
79
|
return {
|
|
59
80
|
status: 'success',
|
|
@@ -3,6 +3,7 @@ function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbol
|
|
|
3
3
|
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
4
4
|
import { SafePlugin } from '@atlaskit/editor-common/safe-plugin';
|
|
5
5
|
import { PluginKey } from '@atlaskit/editor-prosemirror/state';
|
|
6
|
+
import { ReplaceAroundStep, ReplaceStep } from '@atlaskit/editor-prosemirror/transform';
|
|
6
7
|
import { SelectionExtensionActionTypes } from '../types';
|
|
7
8
|
export var selectionExtensionPluginKey = new PluginKey('selectionExtensionPlugin');
|
|
8
9
|
export var createPlugin = function createPlugin() {
|
|
@@ -28,8 +29,23 @@ export var createPlugin = function createPlugin() {
|
|
|
28
29
|
case SelectionExtensionActionTypes.SET_SELECTED_NODE:
|
|
29
30
|
return _objectSpread(_objectSpread({}, pluginState), {}, {
|
|
30
31
|
selectedNode: meta.selectedNode,
|
|
31
|
-
nodePos: meta.nodePos
|
|
32
|
+
nodePos: meta.nodePos,
|
|
33
|
+
startTrackChanges: true,
|
|
34
|
+
docChangedAfterClick: false // Reset the flag when starting to track changes
|
|
32
35
|
});
|
|
36
|
+
case SelectionExtensionActionTypes.START_TRACK_CHANGES:
|
|
37
|
+
return _objectSpread(_objectSpread({}, pluginState), {}, {
|
|
38
|
+
startTrackChanges: meta.startTrackChanges
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
var docChangedAfterClick = pluginState.startTrackChanges && tr.steps.some(function (step) {
|
|
42
|
+
return step instanceof ReplaceStep || step instanceof ReplaceAroundStep;
|
|
43
|
+
});
|
|
44
|
+
if (docChangedAfterClick) {
|
|
45
|
+
return _objectSpread(_objectSpread({}, pluginState), {}, {
|
|
46
|
+
docChangedAfterClick: true,
|
|
47
|
+
startTrackChanges: false // Reset the flag to stop tracking after the document has changed
|
|
48
|
+
});
|
|
33
49
|
}
|
|
34
50
|
return pluginState;
|
|
35
51
|
}
|
package/dist/esm/types/index.js
CHANGED
|
@@ -11,5 +11,6 @@ export var SelectionExtensionActionTypes = /*#__PURE__*/function (SelectionExten
|
|
|
11
11
|
SelectionExtensionActionTypes["UPDATE_ACTIVE_EXTENSION_COORDS"] = "update-active-extension-coords";
|
|
12
12
|
SelectionExtensionActionTypes["CLEAR_ACTIVE_EXTENSION"] = "clear-active-extension";
|
|
13
13
|
SelectionExtensionActionTypes["SET_SELECTED_NODE"] = "set-selected-node";
|
|
14
|
+
SelectionExtensionActionTypes["START_TRACK_CHANGES"] = "start-track-changes";
|
|
14
15
|
return SelectionExtensionActionTypes;
|
|
15
16
|
}({});
|
|
@@ -1,19 +1,25 @@
|
|
|
1
1
|
import React, { useCallback, useEffect, useRef } from 'react';
|
|
2
2
|
import { ACTION, ACTION_SUBJECT, ACTION_SUBJECT_ID, EVENT_TYPE } from '@atlaskit/editor-common/analytics';
|
|
3
|
-
import { useSharedPluginState, sharedPluginStateHookMigratorFactory } from '@atlaskit/editor-common/hooks';
|
|
4
|
-
import { useSharedPluginStateSelector } from '@atlaskit/editor-common/use-shared-plugin-state-selector';
|
|
3
|
+
import { useSharedPluginState, sharedPluginStateHookMigratorFactory, useSharedPluginStateWithSelector } from '@atlaskit/editor-common/hooks';
|
|
5
4
|
var useSharedState = sharedPluginStateHookMigratorFactory(function (api) {
|
|
6
|
-
var
|
|
7
|
-
|
|
5
|
+
var _useSharedPluginState = useSharedPluginStateWithSelector(api, ['selectionExtension', 'editorViewMode'], function (states) {
|
|
6
|
+
var _states$selectionExte, _states$editorViewMod;
|
|
7
|
+
return {
|
|
8
|
+
activeExtension: (_states$selectionExte = states.selectionExtensionState) === null || _states$selectionExte === void 0 ? void 0 : _states$selectionExte.activeExtension,
|
|
9
|
+
mode: (_states$editorViewMod = states.editorViewModeState) === null || _states$editorViewMod === void 0 ? void 0 : _states$editorViewMod.mode
|
|
10
|
+
};
|
|
11
|
+
}),
|
|
12
|
+
activeExtension = _useSharedPluginState.activeExtension,
|
|
13
|
+
mode = _useSharedPluginState.mode;
|
|
8
14
|
return {
|
|
9
15
|
editorViewModeState: undefined,
|
|
10
16
|
mode: mode,
|
|
11
17
|
activeExtension: activeExtension
|
|
12
18
|
};
|
|
13
19
|
}, function (api) {
|
|
14
|
-
var
|
|
15
|
-
selectionExtensionState =
|
|
16
|
-
editorViewModeState =
|
|
20
|
+
var _useSharedPluginState2 = useSharedPluginState(api, ['selectionExtension', 'editorViewMode']),
|
|
21
|
+
selectionExtensionState = _useSharedPluginState2.selectionExtensionState,
|
|
22
|
+
editorViewModeState = _useSharedPluginState2.editorViewModeState;
|
|
17
23
|
return {
|
|
18
24
|
editorViewModeState: editorViewModeState,
|
|
19
25
|
mode: editorViewModeState === null || editorViewModeState === void 0 ? void 0 : editorViewModeState.mode,
|
package/dist/types/index.d.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
export { selectionExtensionPlugin } from './selectionExtensionPlugin';
|
|
2
2
|
export type { SelectionExtensionPlugin } from './selectionExtensionPluginType';
|
|
3
|
-
export type { SelectionExtensionComponentProps, SelectionExtensionPluginOptions, SelectionExtension, } from './types';
|
|
3
|
+
export type { SelectionExtensionComponentProps, SelectionExtensionPluginOptions, SelectionExtension, LinkInsertionOption, SelectionExtensionPluginState, SelectionExtensionSelectionInfo, } from './types';
|
|
@@ -2,7 +2,7 @@ import { type ADFEntity } from '@atlaskit/adf-utils/types';
|
|
|
2
2
|
import type { CommandDispatch } from '@atlaskit/editor-common/types';
|
|
3
3
|
import type { EditorState } from '@atlaskit/editor-prosemirror/state';
|
|
4
4
|
import { type LinkInsertionOption } from '../types';
|
|
5
|
-
export declare const insertSmartLinks: (linkInsertionOption: LinkInsertionOption
|
|
5
|
+
export declare const insertSmartLinks: (linkInsertionOption: LinkInsertionOption[], selectedNodeAdf: ADFEntity) => (state: EditorState, dispatch: CommandDispatch) => {
|
|
6
6
|
status: 'success' | 'error';
|
|
7
7
|
message?: string;
|
|
8
8
|
};
|
|
@@ -6,12 +6,26 @@ export declare const createPlugin: () => SafePlugin<SelectionExtensionPluginStat
|
|
|
6
6
|
activeExtension: any;
|
|
7
7
|
selectedNode?: import("prosemirror-model").Node | undefined;
|
|
8
8
|
nodePos?: number | undefined;
|
|
9
|
+
startTrackChanges?: boolean | undefined;
|
|
10
|
+
docChangedAfterClick?: boolean | undefined;
|
|
9
11
|
} | {
|
|
10
12
|
selectedNode: any;
|
|
11
13
|
nodePos: any;
|
|
14
|
+
startTrackChanges: boolean;
|
|
15
|
+
docChangedAfterClick: boolean;
|
|
12
16
|
activeExtension?: {
|
|
13
17
|
extension: import("../types").SelectionExtension;
|
|
14
18
|
selection: import("../types").SelectionExtensionSelectionInfo;
|
|
15
19
|
coords: import("../types").SelectionExtensionCoords;
|
|
16
20
|
} | undefined;
|
|
21
|
+
} | {
|
|
22
|
+
startTrackChanges: any;
|
|
23
|
+
activeExtension?: {
|
|
24
|
+
extension: import("../types").SelectionExtension;
|
|
25
|
+
selection: import("../types").SelectionExtensionSelectionInfo;
|
|
26
|
+
coords: import("../types").SelectionExtensionCoords;
|
|
27
|
+
} | undefined;
|
|
28
|
+
selectedNode?: import("prosemirror-model").Node | undefined;
|
|
29
|
+
nodePos?: number | undefined;
|
|
30
|
+
docChangedAfterClick?: boolean | undefined;
|
|
17
31
|
}>;
|
|
@@ -20,7 +20,7 @@ export type SelectionExtensionPlugin = NextEditorPlugin<'selectionExtension', {
|
|
|
20
20
|
clearActiveExtension: () => EditorCommand;
|
|
21
21
|
};
|
|
22
22
|
actions: {
|
|
23
|
-
insertSmartLinks: (linkInsertionOption: LinkInsertionOption
|
|
23
|
+
insertSmartLinks: (linkInsertionOption: LinkInsertionOption[], selectedNodeAdf: ADFEntity) => {
|
|
24
24
|
status: 'success' | 'error';
|
|
25
25
|
message?: string;
|
|
26
26
|
};
|
|
@@ -84,7 +84,8 @@ export declare enum SelectionExtensionActionTypes {
|
|
|
84
84
|
SET_ACTIVE_EXTENSION = "set-active-extension",
|
|
85
85
|
UPDATE_ACTIVE_EXTENSION_COORDS = "update-active-extension-coords",
|
|
86
86
|
CLEAR_ACTIVE_EXTENSION = "clear-active-extension",
|
|
87
|
-
SET_SELECTED_NODE = "set-selected-node"
|
|
87
|
+
SET_SELECTED_NODE = "set-selected-node",
|
|
88
|
+
START_TRACK_CHANGES = "start-track-changes"
|
|
88
89
|
}
|
|
89
90
|
export type UpdateActiveExtensionAction = {
|
|
90
91
|
type: SelectionExtensionActionTypes.SET_ACTIVE_EXTENSION;
|
|
@@ -103,5 +104,7 @@ export type SelectionExtensionPluginState = {
|
|
|
103
104
|
};
|
|
104
105
|
selectedNode?: PMNode;
|
|
105
106
|
nodePos?: number;
|
|
107
|
+
startTrackChanges?: boolean;
|
|
108
|
+
docChangedAfterClick?: boolean;
|
|
106
109
|
};
|
|
107
110
|
export {};
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
export { selectionExtensionPlugin } from './selectionExtensionPlugin';
|
|
2
2
|
export type { SelectionExtensionPlugin } from './selectionExtensionPluginType';
|
|
3
|
-
export type { SelectionExtensionComponentProps, SelectionExtensionPluginOptions, SelectionExtension, } from './types';
|
|
3
|
+
export type { SelectionExtensionComponentProps, SelectionExtensionPluginOptions, SelectionExtension, LinkInsertionOption, SelectionExtensionPluginState, SelectionExtensionSelectionInfo, } from './types';
|
|
@@ -2,7 +2,7 @@ import { type ADFEntity } from '@atlaskit/adf-utils/types';
|
|
|
2
2
|
import type { CommandDispatch } from '@atlaskit/editor-common/types';
|
|
3
3
|
import type { EditorState } from '@atlaskit/editor-prosemirror/state';
|
|
4
4
|
import { type LinkInsertionOption } from '../types';
|
|
5
|
-
export declare const insertSmartLinks: (linkInsertionOption: LinkInsertionOption
|
|
5
|
+
export declare const insertSmartLinks: (linkInsertionOption: LinkInsertionOption[], selectedNodeAdf: ADFEntity) => (state: EditorState, dispatch: CommandDispatch) => {
|
|
6
6
|
status: 'success' | 'error';
|
|
7
7
|
message?: string;
|
|
8
8
|
};
|
|
@@ -6,12 +6,26 @@ export declare const createPlugin: () => SafePlugin<SelectionExtensionPluginStat
|
|
|
6
6
|
activeExtension: any;
|
|
7
7
|
selectedNode?: import("prosemirror-model").Node | undefined;
|
|
8
8
|
nodePos?: number | undefined;
|
|
9
|
+
startTrackChanges?: boolean | undefined;
|
|
10
|
+
docChangedAfterClick?: boolean | undefined;
|
|
9
11
|
} | {
|
|
10
12
|
selectedNode: any;
|
|
11
13
|
nodePos: any;
|
|
14
|
+
startTrackChanges: boolean;
|
|
15
|
+
docChangedAfterClick: boolean;
|
|
12
16
|
activeExtension?: {
|
|
13
17
|
extension: import("../types").SelectionExtension;
|
|
14
18
|
selection: import("../types").SelectionExtensionSelectionInfo;
|
|
15
19
|
coords: import("../types").SelectionExtensionCoords;
|
|
16
20
|
} | undefined;
|
|
21
|
+
} | {
|
|
22
|
+
startTrackChanges: any;
|
|
23
|
+
activeExtension?: {
|
|
24
|
+
extension: import("../types").SelectionExtension;
|
|
25
|
+
selection: import("../types").SelectionExtensionSelectionInfo;
|
|
26
|
+
coords: import("../types").SelectionExtensionCoords;
|
|
27
|
+
} | undefined;
|
|
28
|
+
selectedNode?: import("prosemirror-model").Node | undefined;
|
|
29
|
+
nodePos?: number | undefined;
|
|
30
|
+
docChangedAfterClick?: boolean | undefined;
|
|
17
31
|
}>;
|
|
@@ -20,7 +20,7 @@ export type SelectionExtensionPlugin = NextEditorPlugin<'selectionExtension', {
|
|
|
20
20
|
clearActiveExtension: () => EditorCommand;
|
|
21
21
|
};
|
|
22
22
|
actions: {
|
|
23
|
-
insertSmartLinks: (linkInsertionOption: LinkInsertionOption
|
|
23
|
+
insertSmartLinks: (linkInsertionOption: LinkInsertionOption[], selectedNodeAdf: ADFEntity) => {
|
|
24
24
|
status: 'success' | 'error';
|
|
25
25
|
message?: string;
|
|
26
26
|
};
|
|
@@ -84,7 +84,8 @@ export declare enum SelectionExtensionActionTypes {
|
|
|
84
84
|
SET_ACTIVE_EXTENSION = "set-active-extension",
|
|
85
85
|
UPDATE_ACTIVE_EXTENSION_COORDS = "update-active-extension-coords",
|
|
86
86
|
CLEAR_ACTIVE_EXTENSION = "clear-active-extension",
|
|
87
|
-
SET_SELECTED_NODE = "set-selected-node"
|
|
87
|
+
SET_SELECTED_NODE = "set-selected-node",
|
|
88
|
+
START_TRACK_CHANGES = "start-track-changes"
|
|
88
89
|
}
|
|
89
90
|
export type UpdateActiveExtensionAction = {
|
|
90
91
|
type: SelectionExtensionActionTypes.SET_ACTIVE_EXTENSION;
|
|
@@ -103,5 +104,7 @@ export type SelectionExtensionPluginState = {
|
|
|
103
104
|
};
|
|
104
105
|
selectedNode?: PMNode;
|
|
105
106
|
nodePos?: number;
|
|
107
|
+
startTrackChanges?: boolean;
|
|
108
|
+
docChangedAfterClick?: boolean;
|
|
106
109
|
};
|
|
107
110
|
export {};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@atlaskit/editor-plugin-selection-extension",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.2.0",
|
|
4
4
|
"description": "editor-plugin-selection-extension plugin for @atlaskit/editor-core",
|
|
5
5
|
"author": "Atlassian Pty Ltd",
|
|
6
6
|
"license": "Apache-2.0",
|
|
@@ -39,20 +39,20 @@
|
|
|
39
39
|
"@atlaskit/editor-json-transformer": "^8.24.0",
|
|
40
40
|
"@atlaskit/editor-plugin-analytics": "^3.0.0",
|
|
41
41
|
"@atlaskit/editor-plugin-editor-viewmode": "^5.0.0",
|
|
42
|
-
"@atlaskit/editor-plugin-selection-toolbar": "^4.
|
|
42
|
+
"@atlaskit/editor-plugin-selection-toolbar": "^4.2.0",
|
|
43
43
|
"@atlaskit/editor-prosemirror": "7.0.0",
|
|
44
44
|
"@atlaskit/editor-tables": "^2.9.0",
|
|
45
|
-
"@atlaskit/icon": "^27.
|
|
45
|
+
"@atlaskit/icon": "^27.5.0",
|
|
46
46
|
"@atlaskit/platform-feature-flags": "^1.1.0",
|
|
47
47
|
"@atlaskit/primitives": "^14.10.0",
|
|
48
|
-
"@atlaskit/tmp-editor-statsig": "^9.
|
|
48
|
+
"@atlaskit/tmp-editor-statsig": "^9.9.0",
|
|
49
49
|
"@babel/runtime": "^7.0.0",
|
|
50
50
|
"lodash": "^4.17.21",
|
|
51
51
|
"react-intl-next": "npm:react-intl@^5.18.1",
|
|
52
52
|
"uuid": "^3.1.0"
|
|
53
53
|
},
|
|
54
54
|
"peerDependencies": {
|
|
55
|
-
"@atlaskit/editor-common": "^107.
|
|
55
|
+
"@atlaskit/editor-common": "^107.9.0",
|
|
56
56
|
"react": "^18.2.0"
|
|
57
57
|
},
|
|
58
58
|
"devDependencies": {
|