@atlaskit/editor-plugin-selection-extension 3.1.0 → 3.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,17 @@
1
1
  # @atlaskit/editor-plugin-selection-extension
2
2
 
3
+ ## 3.1.1
4
+
5
+ ### Patch Changes
6
+
7
+ - [#183521](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/pull-requests/183521)
8
+ [`86379b9b3d99e`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/86379b9b3d99e) -
9
+ Insert links to page bottom as fallback when changes detect
10
+ - [#183158](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/pull-requests/183158)
11
+ [`d6096ec5c8ad9`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/d6096ec5c8ad9) -
12
+ Migrate to useSharedPluginStateWithSelector
13
+ - Updated dependencies
14
+
3
15
  ## 3.1.0
4
16
 
5
17
  ### 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,6 +18,7 @@ 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
24
  if (!Array.isArray(linkInsertionOption)) {
@@ -29,14 +31,32 @@ var insertSmartLinks = exports.insertSmartLinks = function insertSmartLinks(link
29
31
  };
30
32
  }
31
33
 
32
- // TODO: ED-28365 - we need to track if any changes were made since user click the toolbar button
33
- // if there is change, we should insert the link at the bottom of the page
34
-
34
+ // we need to track if any changes were made since user click the toolbar button
35
+ // if there is change, we insert the links at the bottom of the page instead
36
+ var docChangedAfterClick = ((_selectionExtensionPl = _main.selectionExtensionPluginKey.getState(state)) === null || _selectionExtensionPl === void 0 ? void 0 : _selectionExtensionPl.docChangedAfterClick) || false;
37
+ if (docChangedAfterClick) {
38
+ var docEnd = state.doc.content.size;
39
+ linkInsertionOption.forEach(function (option) {
40
+ var link = option.link;
41
+ tr.insert(tr.mapping.map(docEnd), schema.nodes.inlineCard.createChecked({
42
+ url: link
43
+ }));
44
+ });
45
+ tr.setMeta(_main.selectionExtensionPluginKey, {
46
+ type: _types.SelectionExtensionActionTypes.START_TRACK_CHANGES,
47
+ startTrackChanges: false // Reset the flag when starting to track changes
48
+ });
49
+ dispatch(tr);
50
+ return {
51
+ status: 'success',
52
+ message: 'Links inserted to page bottom successfully'
53
+ };
54
+ }
35
55
  var newTr = tr;
36
56
  try {
37
- var _selectionExtensionPl, _selectionExtensionPl2;
38
- var selectedNode = (_selectionExtensionPl = _main.selectionExtensionPluginKey.getState(state)) === null || _selectionExtensionPl === void 0 ? void 0 : _selectionExtensionPl.selectedNode;
39
- var nodePos = (_selectionExtensionPl2 = _main.selectionExtensionPluginKey.getState(state)) === null || _selectionExtensionPl2 === void 0 ? void 0 : _selectionExtensionPl2.nodePos;
57
+ var _selectionExtensionPl2, _selectionExtensionPl3;
58
+ var selectedNode = (_selectionExtensionPl2 = _main.selectionExtensionPluginKey.getState(state)) === null || _selectionExtensionPl2 === void 0 ? void 0 : _selectionExtensionPl2.selectedNode;
59
+ var nodePos = (_selectionExtensionPl3 = _main.selectionExtensionPluginKey.getState(state)) === null || _selectionExtensionPl3 === void 0 ? void 0 : _selectionExtensionPl3.nodePos;
40
60
  if (!selectedNode || nodePos === undefined) {
41
61
  throw new Error('No selected node or node position found');
42
62
  }
@@ -60,6 +80,10 @@ var insertSmartLinks = exports.insertSmartLinks = function insertSmartLinks(link
60
80
  message: error instanceof Error ? error.message : 'Unknown error'
61
81
  };
62
82
  }
83
+ newTr.setMeta(_main.selectionExtensionPluginKey, {
84
+ type: _types.SelectionExtensionActionTypes.START_TRACK_CHANGES,
85
+ startTrackChanges: false // Reset the flag when starting to track changes
86
+ });
63
87
  dispatch(newTr);
64
88
  return {
65
89
  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
  }
@@ -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 activeExtension = (0, _useSharedPluginStateSelector.useSharedPluginStateSelector)(api, 'selectionExtension.activeExtension');
15
- var mode = (0, _useSharedPluginStateSelector.useSharedPluginStateSelector)(api, 'editorViewMode.mode');
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 _useSharedPluginState = (0, _hooks.useSharedPluginState)(api, ['selectionExtension', 'editorViewMode']),
23
- selectionExtensionState = _useSharedPluginState.selectionExtensionState,
24
- editorViewModeState = _useSharedPluginState.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,6 +11,7 @@ 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
@@ -24,14 +26,34 @@ export const insertSmartLinks = (linkInsertionOption, selectedNodeAdf) => (state
24
26
  };
25
27
  }
26
28
 
27
- // TODO: ED-28365 - we need to track if any changes were made since user click the toolbar button
28
- // if there is change, we should insert the link at the bottom of the page
29
-
29
+ // we need to track if any changes were made since user click the toolbar button
30
+ // if there is change, we insert the links at the bottom of the page instead
31
+ const docChangedAfterClick = ((_selectionExtensionPl = selectionExtensionPluginKey.getState(state)) === null || _selectionExtensionPl === void 0 ? void 0 : _selectionExtensionPl.docChangedAfterClick) || false;
32
+ if (docChangedAfterClick) {
33
+ const docEnd = state.doc.content.size;
34
+ linkInsertionOption.forEach(option => {
35
+ const {
36
+ link
37
+ } = option;
38
+ tr.insert(tr.mapping.map(docEnd), schema.nodes.inlineCard.createChecked({
39
+ url: link
40
+ }));
41
+ });
42
+ tr.setMeta(selectionExtensionPluginKey, {
43
+ type: 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
+ }
30
52
  let newTr = tr;
31
53
  try {
32
- var _selectionExtensionPl, _selectionExtensionPl2;
33
- const selectedNode = (_selectionExtensionPl = selectionExtensionPluginKey.getState(state)) === null || _selectionExtensionPl === void 0 ? void 0 : _selectionExtensionPl.selectedNode;
34
- const nodePos = (_selectionExtensionPl2 = selectionExtensionPluginKey.getState(state)) === null || _selectionExtensionPl2 === void 0 ? void 0 : _selectionExtensionPl2.nodePos;
54
+ var _selectionExtensionPl2, _selectionExtensionPl3;
55
+ const selectedNode = (_selectionExtensionPl2 = selectionExtensionPluginKey.getState(state)) === null || _selectionExtensionPl2 === void 0 ? void 0 : _selectionExtensionPl2.selectedNode;
56
+ const nodePos = (_selectionExtensionPl3 = selectionExtensionPluginKey.getState(state)) === null || _selectionExtensionPl3 === void 0 ? void 0 : _selectionExtensionPl3.nodePos;
35
57
  if (!selectedNode || nodePos === undefined) {
36
58
  throw new Error('No selected node or node position found');
37
59
  }
@@ -59,6 +81,10 @@ export const insertSmartLinks = (linkInsertionOption, selectedNodeAdf) => (state
59
81
  message: error instanceof Error ? error.message : 'Unknown error'
60
82
  };
61
83
  }
84
+ newTr.setMeta(selectionExtensionPluginKey, {
85
+ type: SelectionExtensionActionTypes.START_TRACK_CHANGES,
86
+ startTrackChanges: false // Reset the flag when starting to track changes
87
+ });
62
88
  dispatch(newTr);
63
89
  return {
64
90
  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 activeExtension = useSharedPluginStateSelector(api, 'selectionExtension.activeExtension');
7
- const mode = useSharedPluginStateSelector(api, 'editorViewMode.mode');
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,6 +12,7 @@ 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
18
  if (!Array.isArray(linkInsertionOption)) {
@@ -23,14 +25,32 @@ export var insertSmartLinks = function insertSmartLinks(linkInsertionOption, sel
23
25
  };
24
26
  }
25
27
 
26
- // TODO: ED-28365 - we need to track if any changes were made since user click the toolbar button
27
- // if there is change, we should insert the link at the bottom of the page
28
-
28
+ // we need to track if any changes were made since user click the toolbar button
29
+ // if there is change, we insert the links at the bottom of the page instead
30
+ var docChangedAfterClick = ((_selectionExtensionPl = selectionExtensionPluginKey.getState(state)) === null || _selectionExtensionPl === void 0 ? void 0 : _selectionExtensionPl.docChangedAfterClick) || false;
31
+ if (docChangedAfterClick) {
32
+ var docEnd = state.doc.content.size;
33
+ linkInsertionOption.forEach(function (option) {
34
+ var link = option.link;
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
+ }
29
49
  var newTr = tr;
30
50
  try {
31
- var _selectionExtensionPl, _selectionExtensionPl2;
32
- var selectedNode = (_selectionExtensionPl = selectionExtensionPluginKey.getState(state)) === null || _selectionExtensionPl === void 0 ? void 0 : _selectionExtensionPl.selectedNode;
33
- var nodePos = (_selectionExtensionPl2 = selectionExtensionPluginKey.getState(state)) === null || _selectionExtensionPl2 === void 0 ? void 0 : _selectionExtensionPl2.nodePos;
51
+ var _selectionExtensionPl2, _selectionExtensionPl3;
52
+ var selectedNode = (_selectionExtensionPl2 = selectionExtensionPluginKey.getState(state)) === null || _selectionExtensionPl2 === void 0 ? void 0 : _selectionExtensionPl2.selectedNode;
53
+ var nodePos = (_selectionExtensionPl3 = selectionExtensionPluginKey.getState(state)) === null || _selectionExtensionPl3 === void 0 ? void 0 : _selectionExtensionPl3.nodePos;
34
54
  if (!selectedNode || nodePos === undefined) {
35
55
  throw new Error('No selected node or node position found');
36
56
  }
@@ -54,6 +74,10 @@ export var insertSmartLinks = function insertSmartLinks(linkInsertionOption, sel
54
74
  message: error instanceof Error ? error.message : 'Unknown error'
55
75
  };
56
76
  }
77
+ newTr.setMeta(selectionExtensionPluginKey, {
78
+ type: SelectionExtensionActionTypes.START_TRACK_CHANGES,
79
+ startTrackChanges: false // Reset the flag when starting to track changes
80
+ });
57
81
  dispatch(newTr);
58
82
  return {
59
83
  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
  }
@@ -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 activeExtension = useSharedPluginStateSelector(api, 'selectionExtension.activeExtension');
7
- var mode = useSharedPluginStateSelector(api, 'editorViewMode.mode');
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 _useSharedPluginState = useSharedPluginState(api, ['selectionExtension', 'editorViewMode']),
15
- selectionExtensionState = _useSharedPluginState.selectionExtensionState,
16
- editorViewModeState = _useSharedPluginState.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,
@@ -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
  }>;
@@ -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 {};
@@ -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
  }>;
@@ -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.1.0",
3
+ "version": "3.1.1",
4
4
  "description": "editor-plugin-selection-extension plugin for @atlaskit/editor-core",
5
5
  "author": "Atlassian Pty Ltd",
6
6
  "license": "Apache-2.0",
@@ -45,7 +45,7 @@
45
45
  "@atlaskit/icon": "^27.3.0",
46
46
  "@atlaskit/platform-feature-flags": "^1.1.0",
47
47
  "@atlaskit/primitives": "^14.10.0",
48
- "@atlaskit/tmp-editor-statsig": "^9.0.0",
48
+ "@atlaskit/tmp-editor-statsig": "^9.1.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",