@atlaskit/editor-plugin-selection-extension 3.4.6 → 3.5.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 CHANGED
@@ -1,5 +1,16 @@
1
1
  # @atlaskit/editor-plugin-selection-extension
2
2
 
3
+ ## 3.5.0
4
+
5
+ ### Minor Changes
6
+
7
+ - [`abd3e6fd40ac6`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/abd3e6fd40ac6) -
8
+ Remove unused getSelectionText and inserSmartLinks api
9
+
10
+ ### Patch Changes
11
+
12
+ - Updated dependencies
13
+
3
14
  ## 3.4.6
4
15
 
5
16
  ### Patch Changes
@@ -6,9 +6,8 @@ Object.defineProperty(exports, "__esModule", {
6
6
  });
7
7
  exports.getFragmentInfoFromSelection = void 0;
8
8
  exports.getSelectionAdfInfo = getSelectionAdfInfo;
9
- exports.validateSelectedNode = exports.getSelectionTextInfo = void 0;
9
+ exports.getSelectionTextInfo = void 0;
10
10
  var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
11
- var _isEqual = _interopRequireDefault(require("lodash/isEqual"));
12
11
  var _monitoring = require("@atlaskit/editor-common/monitoring");
13
12
  var _editorJsonTransformer = require("@atlaskit/editor-json-transformer");
14
13
  var _model = require("@atlaskit/editor-prosemirror/model");
@@ -132,9 +131,4 @@ function getSelectionAdfInfo(state) {
132
131
  return _objectSpread(_objectSpread({}, selectionInfo), {}, {
133
132
  selectedNodeAdf: selectedNodeAdf
134
133
  });
135
- }
136
- var validateSelectedNode = exports.validateSelectedNode = function validateSelectedNode(selectedNodeAdf, selectedNode) {
137
- var serializer = new _editorJsonTransformer.JSONTransformer();
138
- var selectedNodeAdfFromState = serializer.encodeNode(selectedNode);
139
- return (0, _isEqual.default)(selectedNodeAdf, selectedNodeAdfFromState);
140
- };
134
+ }
@@ -10,7 +10,6 @@ var _react = _interopRequireDefault(require("react"));
10
10
  var _messages = require("@atlaskit/editor-common/messages");
11
11
  var _safePlugin = require("@atlaskit/editor-common/safe-plugin");
12
12
  var _platformFeatureFlags = require("@atlaskit/platform-feature-flags");
13
- var _actions = require("./pm-plugins/actions");
14
13
  var _insertAdfAtEndOfDoc2 = require("./pm-plugins/actions/insertAdfAtEndOfDoc");
15
14
  var _replaceWithAdf2 = require("./pm-plugins/actions/replaceWithAdf");
16
15
  var _main = require("./pm-plugins/main");
@@ -80,27 +79,15 @@ var selectionExtensionPlugin = exports.selectionExtensionPlugin = function selec
80
79
  }
81
80
  },
82
81
  actions: {
83
- insertSmartLinks: function insertSmartLinks(linkInsertionOptions, selectedNodeAdf) {
82
+ replaceWithAdf: function replaceWithAdf(nodeAdf) {
84
83
  if (!editorViewRef.current) {
85
84
  return {
86
- status: 'error',
87
- message: 'Editor view is not available'
85
+ status: 'failed-to-replace'
88
86
  };
89
87
  }
90
88
  var _editorViewRef$curren = editorViewRef.current,
91
89
  state = _editorViewRef$curren.state,
92
90
  dispatch = _editorViewRef$curren.dispatch;
93
- return (0, _actions.insertSmartLinks)(linkInsertionOptions, selectedNodeAdf)(state, dispatch);
94
- },
95
- replaceWithAdf: function replaceWithAdf(nodeAdf) {
96
- if (!editorViewRef.current) {
97
- return {
98
- status: 'failed-to-replace'
99
- };
100
- }
101
- var _editorViewRef$curren2 = editorViewRef.current,
102
- state = _editorViewRef$curren2.state,
103
- dispatch = _editorViewRef$curren2.dispatch;
104
91
  return (0, _replaceWithAdf2.replaceWithAdf)(nodeAdf)(state, dispatch);
105
92
  },
106
93
  insertAdfAtEndOfDoc: function insertAdfAtEndOfDoc(nodeAdf) {
@@ -109,9 +96,9 @@ var selectionExtensionPlugin = exports.selectionExtensionPlugin = function selec
109
96
  status: 'failed'
110
97
  };
111
98
  }
112
- var _editorViewRef$curren3 = editorViewRef.current,
113
- state = _editorViewRef$curren3.state,
114
- dispatch = _editorViewRef$curren3.dispatch;
99
+ var _editorViewRef$curren2 = editorViewRef.current,
100
+ state = _editorViewRef$curren2.state,
101
+ dispatch = _editorViewRef$curren2.dispatch;
115
102
  return (0, _insertAdfAtEndOfDoc2.insertAdfAtEndOfDoc)(nodeAdf)(state, dispatch);
116
103
  },
117
104
  getSelectionAdf: function getSelectionAdf() {
@@ -137,18 +124,6 @@ var selectionExtensionPlugin = exports.selectionExtensionPlugin = function selec
137
124
  return {
138
125
  selectedNodeAdf: selectedNodeAdf
139
126
  };
140
- },
141
- getSelectionText: function getSelectionText() {
142
- if (!editorViewRef.current) {
143
- return null;
144
- }
145
- var _getSelectionTextInfo = (0, _utils.getSelectionTextInfo)(editorViewRef.current, api),
146
- text = _getSelectionTextInfo.text,
147
- coords = _getSelectionTextInfo.coords;
148
- return {
149
- text: text,
150
- coords: coords
151
- };
152
127
  }
153
128
  },
154
129
  contentComponent: function contentComponent(_ref6) {
@@ -1,4 +1,3 @@
1
- import isEqual from 'lodash/isEqual';
2
1
  import { logException } from '@atlaskit/editor-common/monitoring';
3
2
  import { JSONTransformer } from '@atlaskit/editor-json-transformer';
4
3
  import { Fragment } from '@atlaskit/editor-prosemirror/model';
@@ -135,9 +134,4 @@ export function getSelectionAdfInfo(state) {
135
134
  ...selectionInfo,
136
135
  selectedNodeAdf
137
136
  };
138
- }
139
- export const validateSelectedNode = (selectedNodeAdf, selectedNode) => {
140
- const serializer = new JSONTransformer();
141
- const selectedNodeAdfFromState = serializer.encodeNode(selectedNode);
142
- return isEqual(selectedNodeAdf, selectedNodeAdfFromState);
143
- };
137
+ }
@@ -2,7 +2,6 @@ import React from 'react';
2
2
  import { selectionExtensionMessages } from '@atlaskit/editor-common/messages';
3
3
  import { SafePlugin } from '@atlaskit/editor-common/safe-plugin';
4
4
  import { fg } from '@atlaskit/platform-feature-flags';
5
- import { insertSmartLinks } from './pm-plugins/actions';
6
5
  import { insertAdfAtEndOfDoc } from './pm-plugins/actions/insertAdfAtEndOfDoc';
7
6
  import { replaceWithAdf } from './pm-plugins/actions/replaceWithAdf';
8
7
  import { createPlugin, selectionExtensionPluginKey } from './pm-plugins/main';
@@ -67,19 +66,6 @@ export const selectionExtensionPlugin = ({
67
66
  }
68
67
  },
69
68
  actions: {
70
- insertSmartLinks: (linkInsertionOptions, selectedNodeAdf) => {
71
- if (!editorViewRef.current) {
72
- return {
73
- status: 'error',
74
- message: 'Editor view is not available'
75
- };
76
- }
77
- const {
78
- state,
79
- dispatch
80
- } = editorViewRef.current;
81
- return insertSmartLinks(linkInsertionOptions, selectedNodeAdf)(state, dispatch);
82
- },
83
69
  replaceWithAdf: nodeAdf => {
84
70
  if (!editorViewRef.current) {
85
71
  return {
@@ -133,19 +119,6 @@ export const selectionExtensionPlugin = ({
133
119
  return {
134
120
  selectedNodeAdf
135
121
  };
136
- },
137
- getSelectionText: () => {
138
- if (!editorViewRef.current) {
139
- return null;
140
- }
141
- const {
142
- text,
143
- coords
144
- } = getSelectionTextInfo(editorViewRef.current, api);
145
- return {
146
- text,
147
- coords
148
- };
149
122
  }
150
123
  },
151
124
  contentComponent: ({
@@ -1,7 +1,6 @@
1
1
  import _defineProperty from "@babel/runtime/helpers/defineProperty";
2
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
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
- import isEqual from 'lodash/isEqual';
5
4
  import { logException } from '@atlaskit/editor-common/monitoring';
6
5
  import { JSONTransformer } from '@atlaskit/editor-json-transformer';
7
6
  import { Fragment } from '@atlaskit/editor-prosemirror/model';
@@ -123,9 +122,4 @@ export function getSelectionAdfInfo(state) {
123
122
  return _objectSpread(_objectSpread({}, selectionInfo), {}, {
124
123
  selectedNodeAdf: selectedNodeAdf
125
124
  });
126
- }
127
- export var validateSelectedNode = function validateSelectedNode(selectedNodeAdf, selectedNode) {
128
- var serializer = new JSONTransformer();
129
- var selectedNodeAdfFromState = serializer.encodeNode(selectedNode);
130
- return isEqual(selectedNodeAdf, selectedNodeAdfFromState);
131
- };
125
+ }
@@ -3,7 +3,6 @@ import React from 'react';
3
3
  import { selectionExtensionMessages } from '@atlaskit/editor-common/messages';
4
4
  import { SafePlugin } from '@atlaskit/editor-common/safe-plugin';
5
5
  import { fg } from '@atlaskit/platform-feature-flags';
6
- import { insertSmartLinks as _insertSmartLinks } from './pm-plugins/actions';
7
6
  import { insertAdfAtEndOfDoc as _insertAdfAtEndOfDoc } from './pm-plugins/actions/insertAdfAtEndOfDoc';
8
7
  import { replaceWithAdf as _replaceWithAdf } from './pm-plugins/actions/replaceWithAdf';
9
8
  import { createPlugin, selectionExtensionPluginKey } from './pm-plugins/main';
@@ -73,27 +72,15 @@ export var selectionExtensionPlugin = function selectionExtensionPlugin(_ref) {
73
72
  }
74
73
  },
75
74
  actions: {
76
- insertSmartLinks: function insertSmartLinks(linkInsertionOptions, selectedNodeAdf) {
75
+ replaceWithAdf: function replaceWithAdf(nodeAdf) {
77
76
  if (!editorViewRef.current) {
78
77
  return {
79
- status: 'error',
80
- message: 'Editor view is not available'
78
+ status: 'failed-to-replace'
81
79
  };
82
80
  }
83
81
  var _editorViewRef$curren = editorViewRef.current,
84
82
  state = _editorViewRef$curren.state,
85
83
  dispatch = _editorViewRef$curren.dispatch;
86
- return _insertSmartLinks(linkInsertionOptions, selectedNodeAdf)(state, dispatch);
87
- },
88
- replaceWithAdf: function replaceWithAdf(nodeAdf) {
89
- if (!editorViewRef.current) {
90
- return {
91
- status: 'failed-to-replace'
92
- };
93
- }
94
- var _editorViewRef$curren2 = editorViewRef.current,
95
- state = _editorViewRef$curren2.state,
96
- dispatch = _editorViewRef$curren2.dispatch;
97
84
  return _replaceWithAdf(nodeAdf)(state, dispatch);
98
85
  },
99
86
  insertAdfAtEndOfDoc: function insertAdfAtEndOfDoc(nodeAdf) {
@@ -102,9 +89,9 @@ export var selectionExtensionPlugin = function selectionExtensionPlugin(_ref) {
102
89
  status: 'failed'
103
90
  };
104
91
  }
105
- var _editorViewRef$curren3 = editorViewRef.current,
106
- state = _editorViewRef$curren3.state,
107
- dispatch = _editorViewRef$curren3.dispatch;
92
+ var _editorViewRef$curren2 = editorViewRef.current,
93
+ state = _editorViewRef$curren2.state,
94
+ dispatch = _editorViewRef$curren2.dispatch;
108
95
  return _insertAdfAtEndOfDoc(nodeAdf)(state, dispatch);
109
96
  },
110
97
  getSelectionAdf: function getSelectionAdf() {
@@ -130,18 +117,6 @@ export var selectionExtensionPlugin = function selectionExtensionPlugin(_ref) {
130
117
  return {
131
118
  selectedNodeAdf: selectedNodeAdf
132
119
  };
133
- },
134
- getSelectionText: function getSelectionText() {
135
- if (!editorViewRef.current) {
136
- return null;
137
- }
138
- var _getSelectionTextInfo = getSelectionTextInfo(editorViewRef.current, api),
139
- text = _getSelectionTextInfo.text,
140
- coords = _getSelectionTextInfo.coords;
141
- return {
142
- text: text,
143
- coords: coords
144
- };
145
120
  }
146
121
  },
147
122
  contentComponent: function contentComponent(_ref6) {
@@ -1,3 +1,3 @@
1
1
  export { selectionExtensionPlugin } from './selectionExtensionPlugin';
2
2
  export type { SelectionExtensionPlugin } from './selectionExtensionPluginType';
3
- export type { BlockMenuExtensionConfiguration, DynamicSelectionExtension, ExtensionConfiguration, ExtensionMenuItemConfiguration, ExtensionToolbarItemConfiguration, InsertAdfAtEndOfDocResult, LinkInsertionOption, ReplaceWithAdfResult, SelectionExtension, SelectionExtensionComponentProps, SelectionExtensionConfig, SelectionExtensionPluginOptions, SelectionExtensionPluginState, SelectionExtensionSelectionInfo, ToolbarExtensionConfiguration, SelectionAdfResult, SelectionTextResult, } from './types';
3
+ export type { BlockMenuExtensionConfiguration, DynamicSelectionExtension, ExtensionConfiguration, ExtensionMenuItemConfiguration, ExtensionToolbarItemConfiguration, InsertAdfAtEndOfDocResult, LinkInsertionOption, ReplaceWithAdfResult, SelectionExtension, SelectionExtensionComponentProps, SelectionExtensionConfig, SelectionExtensionPluginOptions, SelectionExtensionPluginState, SelectionExtensionSelectionInfo, ToolbarExtensionConfiguration, SelectionAdfResult, } from './types';
@@ -17,5 +17,4 @@ export declare const getFragmentInfoFromSelection: (state: EditorState) => {
17
17
  selectedNodeAdf: ADFEntity;
18
18
  };
19
19
  export declare function getSelectionAdfInfo(state: EditorState): SelectionInfo;
20
- export declare const validateSelectedNode: (selectedNodeAdf: ADFEntity, selectedNode: PMNode) => boolean;
21
20
  export {};
@@ -5,7 +5,7 @@ import type { EditorViewModePlugin } from '@atlaskit/editor-plugin-editor-viewmo
5
5
  import type { PrimaryToolbarPlugin } from '@atlaskit/editor-plugin-primary-toolbar';
6
6
  import type { SelectionToolbarPlugin } from '@atlaskit/editor-plugin-selection-toolbar';
7
7
  import type { UserPreferencesPlugin } from '@atlaskit/editor-plugin-user-preferences';
8
- import type { DynamicSelectionExtension, SelectionAdfResult, InsertAdfAtEndOfDocResult, LinkInsertionOption, ReplaceWithAdfResult, SelectionExtension, SelectionExtensionPluginOptions, SelectionExtensionPluginState, SelectionExtensionSelectionInfo, SelectionTextResult } from './types';
8
+ import type { DynamicSelectionExtension, SelectionAdfResult, InsertAdfAtEndOfDocResult, ReplaceWithAdfResult, SelectionExtension, SelectionExtensionPluginOptions, SelectionExtensionPluginState, SelectionExtensionSelectionInfo } from './types';
9
9
  export type SelectionExtensionPlugin = NextEditorPlugin<'selectionExtension', {
10
10
  pluginConfiguration: SelectionExtensionPluginOptions | undefined;
11
11
  dependencies: [
@@ -24,16 +24,11 @@ export type SelectionExtensionPlugin = NextEditorPlugin<'selectionExtension', {
24
24
  clearActiveExtension: () => EditorCommand;
25
25
  };
26
26
  actions: {
27
- insertSmartLinks: (linkInsertionOption: LinkInsertionOption[], selectedNodeAdf: ADFEntity) => {
28
- status: 'success' | 'error';
29
- message?: string;
30
- };
31
27
  replaceWithAdf: (nodeAdf: ADFEntity) => ReplaceWithAdfResult;
32
28
  insertAdfAtEndOfDoc: (nodeAdf: ADFEntity) => InsertAdfAtEndOfDocResult;
33
29
  getSelectionAdf: () => SelectionAdfResult;
34
30
  getDocumentFromSelection: () => {
35
31
  selectedNodeAdf?: ADFEntity;
36
32
  } | null;
37
- getSelectionText: () => SelectionTextResult;
38
33
  };
39
34
  }>;
@@ -125,10 +125,6 @@ export type SelectionAdfResult = {
125
125
  selectedNodeAdf?: ADFEntity;
126
126
  selectionRanges?: SelectionRange[];
127
127
  } | null;
128
- export type SelectionTextResult = {
129
- text: string;
130
- coords: SelectionExtensionCoords;
131
- } | null;
132
128
  export type ExtensionSource = 'first-party' | 'external';
133
129
  export type ExtensionConfiguration = {
134
130
  key: string;
@@ -1,3 +1,3 @@
1
1
  export { selectionExtensionPlugin } from './selectionExtensionPlugin';
2
2
  export type { SelectionExtensionPlugin } from './selectionExtensionPluginType';
3
- export type { BlockMenuExtensionConfiguration, DynamicSelectionExtension, ExtensionConfiguration, ExtensionMenuItemConfiguration, ExtensionToolbarItemConfiguration, InsertAdfAtEndOfDocResult, LinkInsertionOption, ReplaceWithAdfResult, SelectionExtension, SelectionExtensionComponentProps, SelectionExtensionConfig, SelectionExtensionPluginOptions, SelectionExtensionPluginState, SelectionExtensionSelectionInfo, ToolbarExtensionConfiguration, SelectionAdfResult, SelectionTextResult, } from './types';
3
+ export type { BlockMenuExtensionConfiguration, DynamicSelectionExtension, ExtensionConfiguration, ExtensionMenuItemConfiguration, ExtensionToolbarItemConfiguration, InsertAdfAtEndOfDocResult, LinkInsertionOption, ReplaceWithAdfResult, SelectionExtension, SelectionExtensionComponentProps, SelectionExtensionConfig, SelectionExtensionPluginOptions, SelectionExtensionPluginState, SelectionExtensionSelectionInfo, ToolbarExtensionConfiguration, SelectionAdfResult, } from './types';
@@ -17,5 +17,4 @@ export declare const getFragmentInfoFromSelection: (state: EditorState) => {
17
17
  selectedNodeAdf: ADFEntity;
18
18
  };
19
19
  export declare function getSelectionAdfInfo(state: EditorState): SelectionInfo;
20
- export declare const validateSelectedNode: (selectedNodeAdf: ADFEntity, selectedNode: PMNode) => boolean;
21
20
  export {};
@@ -5,7 +5,7 @@ import type { EditorViewModePlugin } from '@atlaskit/editor-plugin-editor-viewmo
5
5
  import type { PrimaryToolbarPlugin } from '@atlaskit/editor-plugin-primary-toolbar';
6
6
  import type { SelectionToolbarPlugin } from '@atlaskit/editor-plugin-selection-toolbar';
7
7
  import type { UserPreferencesPlugin } from '@atlaskit/editor-plugin-user-preferences';
8
- import type { DynamicSelectionExtension, SelectionAdfResult, InsertAdfAtEndOfDocResult, LinkInsertionOption, ReplaceWithAdfResult, SelectionExtension, SelectionExtensionPluginOptions, SelectionExtensionPluginState, SelectionExtensionSelectionInfo, SelectionTextResult } from './types';
8
+ import type { DynamicSelectionExtension, SelectionAdfResult, InsertAdfAtEndOfDocResult, ReplaceWithAdfResult, SelectionExtension, SelectionExtensionPluginOptions, SelectionExtensionPluginState, SelectionExtensionSelectionInfo } from './types';
9
9
  export type SelectionExtensionPlugin = NextEditorPlugin<'selectionExtension', {
10
10
  pluginConfiguration: SelectionExtensionPluginOptions | undefined;
11
11
  dependencies: [
@@ -24,16 +24,11 @@ export type SelectionExtensionPlugin = NextEditorPlugin<'selectionExtension', {
24
24
  clearActiveExtension: () => EditorCommand;
25
25
  };
26
26
  actions: {
27
- insertSmartLinks: (linkInsertionOption: LinkInsertionOption[], selectedNodeAdf: ADFEntity) => {
28
- status: 'success' | 'error';
29
- message?: string;
30
- };
31
27
  replaceWithAdf: (nodeAdf: ADFEntity) => ReplaceWithAdfResult;
32
28
  insertAdfAtEndOfDoc: (nodeAdf: ADFEntity) => InsertAdfAtEndOfDocResult;
33
29
  getSelectionAdf: () => SelectionAdfResult;
34
30
  getDocumentFromSelection: () => {
35
31
  selectedNodeAdf?: ADFEntity;
36
32
  } | null;
37
- getSelectionText: () => SelectionTextResult;
38
33
  };
39
34
  }>;
@@ -125,10 +125,6 @@ export type SelectionAdfResult = {
125
125
  selectedNodeAdf?: ADFEntity;
126
126
  selectionRanges?: SelectionRange[];
127
127
  } | null;
128
- export type SelectionTextResult = {
129
- text: string;
130
- coords: SelectionExtensionCoords;
131
- } | null;
132
128
  export type ExtensionSource = 'first-party' | 'external';
133
129
  export type ExtensionConfiguration = {
134
130
  key: string;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atlaskit/editor-plugin-selection-extension",
3
- "version": "3.4.6",
3
+ "version": "3.5.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",
@@ -48,7 +48,7 @@
48
48
  "@atlaskit/icon": "^27.12.0",
49
49
  "@atlaskit/platform-feature-flags": "^1.1.0",
50
50
  "@atlaskit/primitives": "^14.11.0",
51
- "@atlaskit/tmp-editor-statsig": "^11.0.0",
51
+ "@atlaskit/tmp-editor-statsig": "^11.3.0",
52
52
  "@babel/runtime": "^7.0.0",
53
53
  "lodash": "^4.17.21",
54
54
  "react-intl-next": "npm:react-intl@^5.18.1",
@@ -1,90 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.insertSmartLinks = void 0;
7
- var _types = require("../types");
8
- var _main = require("./main");
9
- var _utils = require("./utils");
10
- var _getOffsetByPath = require("./utils/getOffsetByPath");
11
- var insertLinkTr = function insertLinkTr(tr, link, offset, schema) {
12
- var newFromPos = tr.mapping.map(offset.from);
13
- var newToPos = tr.mapping.map(offset.to || offset.from);
14
- var smartLink = schema.nodes.inlineCard.createChecked({
15
- url: link
16
- });
17
- return tr.replaceWith(newFromPos, newToPos, smartLink);
18
- };
19
- var insertSmartLinks = exports.insertSmartLinks = function insertSmartLinks(linkInsertionOption, selectedNodeAdf) {
20
- return function (state, dispatch) {
21
- var _selectionExtensionPl;
22
- var tr = state.tr,
23
- schema = state.schema;
24
- if (linkInsertionOption.length === 0) {
25
- return {
26
- status: 'error',
27
- message: 'No link insertion options provided'
28
- };
29
- }
30
-
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
- }
52
- var newTr = tr;
53
- try {
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;
57
- if (!selectedNode || nodePos === undefined) {
58
- throw new Error('No selected node or node position found');
59
- }
60
-
61
- // Validate if the selectedNodeAdf matches the selected node we have in the state
62
- if (!(0, _utils.validateSelectedNode)(selectedNodeAdf, selectedNode)) {
63
- throw new Error('Selected node ADF does not match the previous stored node');
64
- }
65
- linkInsertionOption.forEach(function (option) {
66
- var link = option.link,
67
- insertPosition = option.insertPosition;
68
- var pointer = insertPosition.pointer,
69
- from = insertPosition.from,
70
- to = insertPosition.to;
71
- var offset = (0, _getOffsetByPath.getOffsetByPath)(selectedNode, nodePos, pointer, from, to);
72
- newTr = insertLinkTr(tr, link, offset, schema);
73
- });
74
- } catch (error) {
75
- return {
76
- status: 'error',
77
- message: error instanceof Error ? error.message : 'Unknown error'
78
- };
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
- });
84
- dispatch(newTr);
85
- return {
86
- status: 'success',
87
- message: 'Links inserted successfully'
88
- };
89
- };
90
- };
@@ -1,90 +0,0 @@
1
- import { SelectionExtensionActionTypes } from '../types';
2
- import { selectionExtensionPluginKey } from './main';
3
- import { validateSelectedNode } from './utils';
4
- import { getOffsetByPath } from './utils/getOffsetByPath';
5
- const insertLinkTr = (tr, link, offset, schema) => {
6
- const newFromPos = tr.mapping.map(offset.from);
7
- const newToPos = tr.mapping.map(offset.to || offset.from);
8
- const smartLink = schema.nodes.inlineCard.createChecked({
9
- url: link
10
- });
11
- return tr.replaceWith(newFromPos, newToPos, smartLink);
12
- };
13
- export const insertSmartLinks = (linkInsertionOption, selectedNodeAdf) => (state, dispatch) => {
14
- var _selectionExtensionPl;
15
- const {
16
- tr,
17
- schema
18
- } = state;
19
- if (linkInsertionOption.length === 0) {
20
- return {
21
- status: 'error',
22
- message: 'No link insertion options provided'
23
- };
24
- }
25
-
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
- }
49
- let newTr = tr;
50
- try {
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;
54
- if (!selectedNode || nodePos === undefined) {
55
- throw new Error('No selected node or node position found');
56
- }
57
-
58
- // Validate if the selectedNodeAdf matches the selected node we have in the state
59
- if (!validateSelectedNode(selectedNodeAdf, selectedNode)) {
60
- throw new Error('Selected node ADF does not match the previous stored node');
61
- }
62
- linkInsertionOption.forEach(option => {
63
- const {
64
- link,
65
- insertPosition
66
- } = option;
67
- const {
68
- pointer,
69
- from,
70
- to
71
- } = insertPosition;
72
- const offset = getOffsetByPath(selectedNode, nodePos, pointer, from, to);
73
- newTr = insertLinkTr(tr, link, offset, schema);
74
- });
75
- } catch (error) {
76
- return {
77
- status: 'error',
78
- message: error instanceof Error ? error.message : 'Unknown error'
79
- };
80
- }
81
- newTr.setMeta(selectionExtensionPluginKey, {
82
- type: SelectionExtensionActionTypes.START_TRACK_CHANGES,
83
- startTrackChanges: false // Reset the flag when starting to track changes
84
- });
85
- dispatch(newTr);
86
- return {
87
- status: 'success',
88
- message: 'Links inserted successfully'
89
- };
90
- };
@@ -1,84 +0,0 @@
1
- import { SelectionExtensionActionTypes } from '../types';
2
- import { selectionExtensionPluginKey } from './main';
3
- import { validateSelectedNode } from './utils';
4
- import { getOffsetByPath } from './utils/getOffsetByPath';
5
- var insertLinkTr = function insertLinkTr(tr, link, offset, schema) {
6
- var newFromPos = tr.mapping.map(offset.from);
7
- var newToPos = tr.mapping.map(offset.to || offset.from);
8
- var smartLink = schema.nodes.inlineCard.createChecked({
9
- url: link
10
- });
11
- return tr.replaceWith(newFromPos, newToPos, smartLink);
12
- };
13
- export var insertSmartLinks = function insertSmartLinks(linkInsertionOption, selectedNodeAdf) {
14
- return function (state, dispatch) {
15
- var _selectionExtensionPl;
16
- var tr = state.tr,
17
- schema = state.schema;
18
- if (linkInsertionOption.length === 0) {
19
- return {
20
- status: 'error',
21
- message: 'No link insertion options provided'
22
- };
23
- }
24
-
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
- }
46
- var newTr = tr;
47
- try {
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;
51
- if (!selectedNode || nodePos === undefined) {
52
- throw new Error('No selected node or node position found');
53
- }
54
-
55
- // Validate if the selectedNodeAdf matches the selected node we have in the state
56
- if (!validateSelectedNode(selectedNodeAdf, selectedNode)) {
57
- throw new Error('Selected node ADF does not match the previous stored node');
58
- }
59
- linkInsertionOption.forEach(function (option) {
60
- var link = option.link,
61
- insertPosition = option.insertPosition;
62
- var pointer = insertPosition.pointer,
63
- from = insertPosition.from,
64
- to = insertPosition.to;
65
- var offset = getOffsetByPath(selectedNode, nodePos, pointer, from, to);
66
- newTr = insertLinkTr(tr, link, offset, schema);
67
- });
68
- } catch (error) {
69
- return {
70
- status: 'error',
71
- message: error instanceof Error ? error.message : 'Unknown error'
72
- };
73
- }
74
- newTr.setMeta(selectionExtensionPluginKey, {
75
- type: SelectionExtensionActionTypes.START_TRACK_CHANGES,
76
- startTrackChanges: false // Reset the flag when starting to track changes
77
- });
78
- dispatch(newTr);
79
- return {
80
- status: 'success',
81
- message: 'Links inserted successfully'
82
- };
83
- };
84
- };
@@ -1,8 +0,0 @@
1
- import { type ADFEntity } from '@atlaskit/adf-utils/types';
2
- import type { CommandDispatch } from '@atlaskit/editor-common/types';
3
- import type { EditorState } from '@atlaskit/editor-prosemirror/state';
4
- import { type LinkInsertionOption } from '../types';
5
- export declare const insertSmartLinks: (linkInsertionOption: LinkInsertionOption[], selectedNodeAdf: ADFEntity) => (state: EditorState, dispatch: CommandDispatch) => {
6
- status: "success" | "error";
7
- message?: string;
8
- };
@@ -1,8 +0,0 @@
1
- import { type ADFEntity } from '@atlaskit/adf-utils/types';
2
- import type { CommandDispatch } from '@atlaskit/editor-common/types';
3
- import type { EditorState } from '@atlaskit/editor-prosemirror/state';
4
- import { type LinkInsertionOption } from '../types';
5
- export declare const insertSmartLinks: (linkInsertionOption: LinkInsertionOption[], selectedNodeAdf: ADFEntity) => (state: EditorState, dispatch: CommandDispatch) => {
6
- status: "success" | "error";
7
- message?: string;
8
- };