@atlaskit/editor-plugin-selection 7.0.24 → 7.0.25

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,13 @@
1
1
  # @atlaskit/editor-plugin-selection
2
2
 
3
+ ## 7.0.25
4
+
5
+ ### Patch Changes
6
+
7
+ - [`10f36a235eedd`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/10f36a235eedd) -
8
+ Extract selection helpers to editor-common
9
+ - Updated dependencies
10
+
3
11
  ## 7.0.24
4
12
 
5
13
  ### Patch Changes
@@ -6,9 +6,11 @@ Object.defineProperty(exports, "__esModule", {
6
6
  });
7
7
  exports.getSliceFromSelection = exports.getSelectionLocalIds = exports.getSelectionFragment = void 0;
8
8
  var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray"));
9
+ var _selection2 = require("@atlaskit/editor-common/selection");
9
10
  var _editorJsonTransformer = require("@atlaskit/editor-json-transformer");
10
11
  var _model = require("@atlaskit/editor-prosemirror/model");
11
12
  var _state = require("@atlaskit/editor-prosemirror/state");
13
+ var _platformFeatureFlags = require("@atlaskit/platform-feature-flags");
12
14
  function _createForOfIteratorHelper(r, e) { var t = "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (!t) { if (Array.isArray(r) || (t = _unsupportedIterableToArray(r)) || e && r && "number" == typeof r.length) { t && (r = t); var _n = 0, F = function F() {}; return { s: F, n: function n() { return _n >= r.length ? { done: !0 } : { done: !1, value: r[_n++] }; }, e: function e(r) { throw r; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var o, a = !0, u = !1; return { s: function s() { t = t.call(r); }, n: function n() { var r = t.next(); return a = r.done, r; }, e: function e(r) { u = !0, o = r; }, f: function f() { try { a || null == t.return || t.return(); } finally { if (u) throw o; } } }; }
13
15
  function _unsupportedIterableToArray(r, a) { if (r) { if ("string" == typeof r) return _arrayLikeToArray(r, a); var t = {}.toString.call(r).slice(8, -1); return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0; } }
14
16
  function _arrayLikeToArray(r, a) { (null == a || a > r.length) && (a = r.length); for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e]; return n; }
@@ -81,24 +83,27 @@ var getSliceFromSelection = exports.getSliceFromSelection = function getSliceFro
81
83
  };
82
84
  var getSelectionFragment = exports.getSelectionFragment = function getSelectionFragment(api) {
83
85
  return function () {
84
- var _api$selection$shared, _api$core$sharedState;
86
+ var _api$selection$shared;
85
87
  var selection = api === null || api === void 0 || (_api$selection$shared = api.selection.sharedState) === null || _api$selection$shared === void 0 || (_api$selection$shared = _api$selection$shared.currentState()) === null || _api$selection$shared === void 0 ? void 0 : _api$selection$shared.selection;
86
- var schema = api === null || api === void 0 || (_api$core$sharedState = api.core.sharedState.currentState()) === null || _api$core$sharedState === void 0 ? void 0 : _api$core$sharedState.schema;
87
- if (!selection || !schema || selection.empty) {
88
- return null;
88
+ if ((0, _platformFeatureFlags.fg)('platform_editor_renderer_selection_context')) {
89
+ return (0, _selection2.getFragmentsFromSelection)(selection);
90
+ } else {
91
+ var _api$core$sharedState;
92
+ var schema = api === null || api === void 0 || (_api$core$sharedState = api.core.sharedState.currentState()) === null || _api$core$sharedState === void 0 ? void 0 : _api$core$sharedState.schema;
93
+ if (!selection || !schema || selection.empty) {
94
+ return null;
95
+ }
96
+ var slice = getSliceFromSelection(selection);
97
+ var content = slice.content;
98
+ var fragment = [];
99
+ content.forEach(function (node) {
100
+ fragment.push((0, _editorJsonTransformer.nodeToJSON)(node));
101
+ });
102
+ return fragment;
89
103
  }
90
- var slice = getSliceFromSelection(selection);
91
- var content = slice.content;
92
- var fragment = [];
93
- content.forEach(function (node) {
94
- fragment.push((0, _editorJsonTransformer.nodeToJSON)(node));
95
- });
96
- return fragment;
97
104
  };
98
105
  };
99
- var getSelectionLocalIds = exports.getSelectionLocalIds =
100
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
101
- function getSelectionLocalIds(api) {
106
+ var getSelectionLocalIds = exports.getSelectionLocalIds = function getSelectionLocalIds(api) {
102
107
  return function () {
103
108
  var _api$selection$shared2, _selection;
104
109
  var selection = api === null || api === void 0 || (_api$selection$shared2 = api.selection.sharedState) === null || _api$selection$shared2 === void 0 || (_api$selection$shared2 = _api$selection$shared2.currentState()) === null || _api$selection$shared2 === void 0 ? void 0 : _api$selection$shared2.selection;
@@ -111,23 +116,27 @@ function getSelectionLocalIds(api) {
111
116
  return null;
112
117
  });
113
118
  }
114
- if (!selection) {
115
- return null;
116
- }
117
- if (selection instanceof _state.NodeSelection) {
118
- return [selection.node.attrs.localId];
119
- } else if (selection.empty) {
120
- return [selection.$from.parent.attrs.localId];
121
- }
122
- var content = getSliceFromSelection(selection).content;
123
- var ids = [];
124
- content.forEach(function (node) {
125
- var _node$attrs;
126
- var localId = (_node$attrs = node.attrs) === null || _node$attrs === void 0 ? void 0 : _node$attrs.localId;
127
- if (localId) {
128
- ids.push(localId);
119
+ if ((0, _platformFeatureFlags.fg)('platform_editor_renderer_selection_context')) {
120
+ return (0, _selection2.getLocalIdsFromSelection)(selection);
121
+ } else {
122
+ if (!selection) {
123
+ return null;
124
+ }
125
+ if (selection instanceof _state.NodeSelection) {
126
+ return [selection.node.attrs.localId];
127
+ } else if (selection.empty) {
128
+ return [selection.$from.parent.attrs.localId];
129
129
  }
130
- });
131
- return ids;
130
+ var content = getSliceFromSelection(selection).content;
131
+ var ids = [];
132
+ content.forEach(function (node) {
133
+ var _node$attrs;
134
+ var localId = (_node$attrs = node.attrs) === null || _node$attrs === void 0 ? void 0 : _node$attrs.localId;
135
+ if (localId) {
136
+ ids.push(localId);
137
+ }
138
+ });
139
+ return ids;
140
+ }
132
141
  };
133
142
  };
@@ -1,6 +1,8 @@
1
+ import { getFragmentsFromSelection, getLocalIdsFromSelection } from '@atlaskit/editor-common/selection';
1
2
  import { nodeToJSON } from '@atlaskit/editor-json-transformer';
2
3
  import { Fragment } from '@atlaskit/editor-prosemirror/model';
3
4
  import { NodeSelection, TextSelection } from '@atlaskit/editor-prosemirror/state';
5
+ import { fg } from '@atlaskit/platform-feature-flags';
4
6
  const listDepth = 3;
5
7
  const selectionCoversAllListItems = ($from, $to) => {
6
8
  // Block level lists
@@ -62,23 +64,26 @@ export const getSliceFromSelection = selection => {
62
64
  return frag;
63
65
  };
64
66
  export const getSelectionFragment = api => () => {
65
- var _api$selection$shared, _api$selection$shared2, _api$core$sharedState;
67
+ var _api$selection$shared, _api$selection$shared2;
66
68
  const selection = api === null || api === void 0 ? void 0 : (_api$selection$shared = api.selection.sharedState) === null || _api$selection$shared === void 0 ? void 0 : (_api$selection$shared2 = _api$selection$shared.currentState()) === null || _api$selection$shared2 === void 0 ? void 0 : _api$selection$shared2.selection;
67
- const schema = api === null || api === void 0 ? void 0 : (_api$core$sharedState = api.core.sharedState.currentState()) === null || _api$core$sharedState === void 0 ? void 0 : _api$core$sharedState.schema;
68
- if (!selection || !schema || selection.empty) {
69
- return null;
69
+ if (fg('platform_editor_renderer_selection_context')) {
70
+ return getFragmentsFromSelection(selection);
71
+ } else {
72
+ var _api$core$sharedState;
73
+ const schema = api === null || api === void 0 ? void 0 : (_api$core$sharedState = api.core.sharedState.currentState()) === null || _api$core$sharedState === void 0 ? void 0 : _api$core$sharedState.schema;
74
+ if (!selection || !schema || selection.empty) {
75
+ return null;
76
+ }
77
+ const slice = getSliceFromSelection(selection);
78
+ const content = slice.content;
79
+ const fragment = [];
80
+ content.forEach(node => {
81
+ fragment.push(nodeToJSON(node));
82
+ });
83
+ return fragment;
70
84
  }
71
- const slice = getSliceFromSelection(selection);
72
- const content = slice.content;
73
- const fragment = [];
74
- content.forEach(node => {
75
- fragment.push(nodeToJSON(node));
76
- });
77
- return fragment;
78
85
  };
79
- export const getSelectionLocalIds =
80
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
81
- api => () => {
86
+ export const getSelectionLocalIds = api => () => {
82
87
  var _api$selection$shared3, _api$selection$shared4, _selection;
83
88
  let selection = api === null || api === void 0 ? void 0 : (_api$selection$shared3 = api.selection.sharedState) === null || _api$selection$shared3 === void 0 ? void 0 : (_api$selection$shared4 = _api$selection$shared3.currentState()) === null || _api$selection$shared4 === void 0 ? void 0 : _api$selection$shared4.selection;
84
89
  if ((_selection = selection) !== null && _selection !== void 0 && _selection.empty) {
@@ -91,22 +96,26 @@ api => () => {
91
96
  return null;
92
97
  });
93
98
  }
94
- if (!selection) {
95
- return null;
96
- }
97
- if (selection instanceof NodeSelection) {
98
- return [selection.node.attrs.localId];
99
- } else if (selection.empty) {
100
- return [selection.$from.parent.attrs.localId];
101
- }
102
- const content = getSliceFromSelection(selection).content;
103
- const ids = [];
104
- content.forEach(node => {
105
- var _node$attrs;
106
- const localId = (_node$attrs = node.attrs) === null || _node$attrs === void 0 ? void 0 : _node$attrs.localId;
107
- if (localId) {
108
- ids.push(localId);
99
+ if (fg('platform_editor_renderer_selection_context')) {
100
+ return getLocalIdsFromSelection(selection);
101
+ } else {
102
+ if (!selection) {
103
+ return null;
104
+ }
105
+ if (selection instanceof NodeSelection) {
106
+ return [selection.node.attrs.localId];
107
+ } else if (selection.empty) {
108
+ return [selection.$from.parent.attrs.localId];
109
109
  }
110
- });
111
- return ids;
110
+ const content = getSliceFromSelection(selection).content;
111
+ const ids = [];
112
+ content.forEach(node => {
113
+ var _node$attrs;
114
+ const localId = (_node$attrs = node.attrs) === null || _node$attrs === void 0 ? void 0 : _node$attrs.localId;
115
+ if (localId) {
116
+ ids.push(localId);
117
+ }
118
+ });
119
+ return ids;
120
+ }
112
121
  };
@@ -2,9 +2,11 @@ import _toConsumableArray from "@babel/runtime/helpers/toConsumableArray";
2
2
  function _createForOfIteratorHelper(r, e) { var t = "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (!t) { if (Array.isArray(r) || (t = _unsupportedIterableToArray(r)) || e && r && "number" == typeof r.length) { t && (r = t); var _n = 0, F = function F() {}; return { s: F, n: function n() { return _n >= r.length ? { done: !0 } : { done: !1, value: r[_n++] }; }, e: function e(r) { throw r; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var o, a = !0, u = !1; return { s: function s() { t = t.call(r); }, n: function n() { var r = t.next(); return a = r.done, r; }, e: function e(r) { u = !0, o = r; }, f: function f() { try { a || null == t.return || t.return(); } finally { if (u) throw o; } } }; }
3
3
  function _unsupportedIterableToArray(r, a) { if (r) { if ("string" == typeof r) return _arrayLikeToArray(r, a); var t = {}.toString.call(r).slice(8, -1); return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0; } }
4
4
  function _arrayLikeToArray(r, a) { (null == a || a > r.length) && (a = r.length); for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e]; return n; }
5
+ import { getFragmentsFromSelection, getLocalIdsFromSelection } from '@atlaskit/editor-common/selection';
5
6
  import { nodeToJSON } from '@atlaskit/editor-json-transformer';
6
7
  import { Fragment } from '@atlaskit/editor-prosemirror/model';
7
8
  import { NodeSelection, TextSelection } from '@atlaskit/editor-prosemirror/state';
9
+ import { fg } from '@atlaskit/platform-feature-flags';
8
10
  var listDepth = 3;
9
11
  var selectionCoversAllListItems = function selectionCoversAllListItems($from, $to) {
10
12
  // Block level lists
@@ -74,24 +76,27 @@ export var getSliceFromSelection = function getSliceFromSelection(selection) {
74
76
  };
75
77
  export var getSelectionFragment = function getSelectionFragment(api) {
76
78
  return function () {
77
- var _api$selection$shared, _api$core$sharedState;
79
+ var _api$selection$shared;
78
80
  var selection = api === null || api === void 0 || (_api$selection$shared = api.selection.sharedState) === null || _api$selection$shared === void 0 || (_api$selection$shared = _api$selection$shared.currentState()) === null || _api$selection$shared === void 0 ? void 0 : _api$selection$shared.selection;
79
- var schema = api === null || api === void 0 || (_api$core$sharedState = api.core.sharedState.currentState()) === null || _api$core$sharedState === void 0 ? void 0 : _api$core$sharedState.schema;
80
- if (!selection || !schema || selection.empty) {
81
- return null;
81
+ if (fg('platform_editor_renderer_selection_context')) {
82
+ return getFragmentsFromSelection(selection);
83
+ } else {
84
+ var _api$core$sharedState;
85
+ var schema = api === null || api === void 0 || (_api$core$sharedState = api.core.sharedState.currentState()) === null || _api$core$sharedState === void 0 ? void 0 : _api$core$sharedState.schema;
86
+ if (!selection || !schema || selection.empty) {
87
+ return null;
88
+ }
89
+ var slice = getSliceFromSelection(selection);
90
+ var content = slice.content;
91
+ var fragment = [];
92
+ content.forEach(function (node) {
93
+ fragment.push(nodeToJSON(node));
94
+ });
95
+ return fragment;
82
96
  }
83
- var slice = getSliceFromSelection(selection);
84
- var content = slice.content;
85
- var fragment = [];
86
- content.forEach(function (node) {
87
- fragment.push(nodeToJSON(node));
88
- });
89
- return fragment;
90
97
  };
91
98
  };
92
- export var getSelectionLocalIds =
93
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
94
- function getSelectionLocalIds(api) {
99
+ export var getSelectionLocalIds = function getSelectionLocalIds(api) {
95
100
  return function () {
96
101
  var _api$selection$shared2, _selection;
97
102
  var selection = api === null || api === void 0 || (_api$selection$shared2 = api.selection.sharedState) === null || _api$selection$shared2 === void 0 || (_api$selection$shared2 = _api$selection$shared2.currentState()) === null || _api$selection$shared2 === void 0 ? void 0 : _api$selection$shared2.selection;
@@ -104,23 +109,27 @@ function getSelectionLocalIds(api) {
104
109
  return null;
105
110
  });
106
111
  }
107
- if (!selection) {
108
- return null;
109
- }
110
- if (selection instanceof NodeSelection) {
111
- return [selection.node.attrs.localId];
112
- } else if (selection.empty) {
113
- return [selection.$from.parent.attrs.localId];
114
- }
115
- var content = getSliceFromSelection(selection).content;
116
- var ids = [];
117
- content.forEach(function (node) {
118
- var _node$attrs;
119
- var localId = (_node$attrs = node.attrs) === null || _node$attrs === void 0 ? void 0 : _node$attrs.localId;
120
- if (localId) {
121
- ids.push(localId);
112
+ if (fg('platform_editor_renderer_selection_context')) {
113
+ return getLocalIdsFromSelection(selection);
114
+ } else {
115
+ if (!selection) {
116
+ return null;
117
+ }
118
+ if (selection instanceof NodeSelection) {
119
+ return [selection.node.attrs.localId];
120
+ } else if (selection.empty) {
121
+ return [selection.$from.parent.attrs.localId];
122
122
  }
123
- });
124
- return ids;
123
+ var content = getSliceFromSelection(selection).content;
124
+ var ids = [];
125
+ content.forEach(function (node) {
126
+ var _node$attrs;
127
+ var localId = (_node$attrs = node.attrs) === null || _node$attrs === void 0 ? void 0 : _node$attrs.localId;
128
+ if (localId) {
129
+ ids.push(localId);
130
+ }
131
+ });
132
+ return ids;
133
+ }
125
134
  };
126
135
  };
@@ -13,4 +13,4 @@ import type { SelectionPlugin } from '../selectionPluginType';
13
13
  */
14
14
  export declare const getSliceFromSelection: (selection: Selection) => Fragment;
15
15
  export declare const getSelectionFragment: (api: ExtractInjectionAPI<SelectionPlugin> | undefined) => () => JSONNode[] | null;
16
- export declare const getSelectionLocalIds: (api: ExtractInjectionAPI<SelectionPlugin> | undefined) => () => any[] | null;
16
+ export declare const getSelectionLocalIds: (api?: ExtractInjectionAPI<SelectionPlugin>) => () => string[] | null;
@@ -13,4 +13,4 @@ import type { SelectionPlugin } from '../selectionPluginType';
13
13
  */
14
14
  export declare const getSliceFromSelection: (selection: Selection) => Fragment;
15
15
  export declare const getSelectionFragment: (api: ExtractInjectionAPI<SelectionPlugin> | undefined) => () => JSONNode[] | null;
16
- export declare const getSelectionLocalIds: (api: ExtractInjectionAPI<SelectionPlugin> | undefined) => () => any[] | null;
16
+ export declare const getSelectionLocalIds: (api?: ExtractInjectionAPI<SelectionPlugin>) => () => string[] | null;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atlaskit/editor-plugin-selection",
3
- "version": "7.0.24",
3
+ "version": "7.0.25",
4
4
  "description": "Selection plugin for @atlaskit/editor-core",
5
5
  "publishConfig": {
6
6
  "registry": "https://registry.npmjs.org/"
@@ -25,12 +25,12 @@
25
25
  "@atlaskit/editor-shared-styles": "^3.10.0",
26
26
  "@atlaskit/editor-tables": "^2.9.0",
27
27
  "@atlaskit/platform-feature-flags": "^1.1.0",
28
- "@atlaskit/tmp-editor-statsig": "^33.0.0",
28
+ "@atlaskit/tmp-editor-statsig": "^33.2.0",
29
29
  "@atlaskit/tokens": "^11.0.0",
30
30
  "@babel/runtime": "^7.0.0"
31
31
  },
32
32
  "peerDependencies": {
33
- "@atlaskit/editor-common": "^111.26.0",
33
+ "@atlaskit/editor-common": "^111.28.0",
34
34
  "react": "^18.2.0"
35
35
  },
36
36
  "techstack": {
@@ -81,6 +81,9 @@
81
81
  "platform_editor_nested_tables_gap_cursor": {
82
82
  "type": "boolean"
83
83
  },
84
+ "platform_editor_renderer_selection_context": {
85
+ "type": "boolean"
86
+ },
84
87
  "platform_synced_block_patch_4": {
85
88
  "type": "boolean"
86
89
  }