@atlaskit/editor-plugin-base 2.0.12 → 2.1.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,19 @@
1
1
  # @atlaskit/editor-plugin-base
2
2
 
3
+ ## 2.1.0
4
+
5
+ ### Minor Changes
6
+
7
+ - [#97984](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/pull-requests/97984)
8
+ [`8ffeab9aaf1ab`](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/commits/8ffeab9aaf1ab) -
9
+ [ux] [ED-23573] Added new actions (resolveMarks and registerMarks) to basePlugin. Callbacks added
10
+ to mentions, card, emoji and base plugins to handle conversion to inline code. Deprecated code
11
+ removed from editor-common.
12
+
13
+ ### Patch Changes
14
+
15
+ - Updated dependencies
16
+
3
17
  ## 2.0.12
4
18
 
5
19
  ### Patch Changes
@@ -5,6 +5,7 @@ Object.defineProperty(exports, "__esModule", {
5
5
  value: true
6
6
  });
7
7
  exports.default = void 0;
8
+ exports.resolveCallbacks = resolveCallbacks;
8
9
  var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
9
10
  var _adfSchema = require("@atlaskit/adf-schema");
10
11
  var _keymaps = require("@atlaskit/editor-common/keymaps");
@@ -25,11 +26,63 @@ var _getKeyboardHeight = require("./pm-plugins/scroll-gutter/util/get-keyboard-h
25
26
  var _inputTrackingConfig = require("./pm-plugins/utils/inputTrackingConfig");
26
27
  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; }
27
28
  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; }
29
+ // eslint-disable-next-line @typescript-eslint/max-params
30
+ function resolveCallbacks(from, to, tr, callbacks) {
31
+ var doc = tr.doc;
32
+ doc.nodesBetween(from, to, function (node, pos) {
33
+ callbacks.forEach(function (cb) {
34
+ return cb({
35
+ tr: tr,
36
+ node: node,
37
+ pos: pos,
38
+ from: from,
39
+ to: to
40
+ });
41
+ });
42
+ });
43
+ }
44
+ var SMART_TO_ASCII = {
45
+ '…': '...',
46
+ '→': '->',
47
+ '←': '<-',
48
+ '–': '--',
49
+ '“': '"',
50
+ '”': '"',
51
+ '‘': "'",
52
+ '’': "'"
53
+ };
54
+
55
+ // eslint-disable-next-line require-unicode-regexp
56
+ var FIND_SMART_CHAR = new RegExp("[".concat(Object.keys(SMART_TO_ASCII).join(''), "]"), 'g');
28
57
  var basePlugin = function basePlugin(_ref) {
29
- var _api$featureFlags;
58
+ var _api$featureFlags, _api$base;
30
59
  var options = _ref.config,
31
60
  api = _ref.api;
32
61
  var featureFlags = (api === null || api === void 0 || (_api$featureFlags = api.featureFlags) === null || _api$featureFlags === void 0 ? void 0 : _api$featureFlags.sharedState.currentState()) || {};
62
+ var callbacks = [];
63
+ api === null || api === void 0 || (_api$base = api.base) === null || _api$base === void 0 || _api$base.actions.registerMarks(function (_ref2) {
64
+ var tr = _ref2.tr,
65
+ node = _ref2.node,
66
+ pos = _ref2.pos,
67
+ from = _ref2.from,
68
+ to = _ref2.to;
69
+ var doc = tr.doc;
70
+ var schema = doc.type.schema;
71
+ var textNodeType = schema.nodes.text;
72
+ if (node.type === textNodeType && node.text) {
73
+ // Find a valid start and end position because the text may be partially selected.
74
+ var startPositionInSelection = Math.max(pos, from);
75
+ var endPositionInSelection = Math.min(pos + node.nodeSize, to);
76
+ var textForReplacing = doc.textBetween(startPositionInSelection, endPositionInSelection);
77
+ var newText = textForReplacing.replace(FIND_SMART_CHAR, function (match) {
78
+ var _SMART_TO_ASCII$match;
79
+ return (_SMART_TO_ASCII$match = SMART_TO_ASCII[match]) !== null && _SMART_TO_ASCII$match !== void 0 ? _SMART_TO_ASCII$match : match;
80
+ });
81
+ var currentStartPos = tr.mapping.map(startPositionInSelection);
82
+ var currentEndPos = tr.mapping.map(endPositionInSelection);
83
+ tr.replaceWith(currentStartPos, currentEndPos, schema.text(newText, node.marks));
84
+ }
85
+ });
33
86
  return {
34
87
  name: 'base',
35
88
  getSharedState: function getSharedState(editorState) {
@@ -38,13 +91,19 @@ var basePlugin = function basePlugin(_ref) {
38
91
  };
39
92
  },
40
93
  actions: {
41
- setKeyboardHeight: _setKeyboardHeight.setKeyboardHeight
94
+ setKeyboardHeight: _setKeyboardHeight.setKeyboardHeight,
95
+ resolveMarks: function resolveMarks(from, to, tr) {
96
+ return resolveCallbacks(from, to, tr, callbacks);
97
+ },
98
+ registerMarks: function registerMarks(callback) {
99
+ callbacks.push(callback);
100
+ }
42
101
  },
43
102
  pmPlugins: function pmPlugins() {
44
103
  var plugins = [{
45
104
  name: 'filterStepsPlugin',
46
- plugin: function plugin(_ref2) {
47
- var dispatchAnalyticsEvent = _ref2.dispatchAnalyticsEvent;
105
+ plugin: function plugin(_ref3) {
106
+ var dispatchAnalyticsEvent = _ref3.dispatchAnalyticsEvent;
48
107
  return (0, _filterSteps.default)(dispatchAnalyticsEvent);
49
108
  }
50
109
  }];
@@ -81,8 +140,8 @@ var basePlugin = function basePlugin(_ref) {
81
140
  plugin: _newlinePreserveMarks.default
82
141
  }, {
83
142
  name: 'frozenEditor',
84
- plugin: function plugin(_ref3) {
85
- var dispatchAnalyticsEvent = _ref3.dispatchAnalyticsEvent;
143
+ plugin: function plugin(_ref4) {
144
+ var dispatchAnalyticsEvent = _ref4.dispatchAnalyticsEvent;
86
145
  return (0, _frozenEditor.default)(api === null || api === void 0 ? void 0 : api.contextIdentifier)(dispatchAnalyticsEvent, _inputTrackingConfig.inputTracking, undefined);
87
146
  }
88
147
  }, {
@@ -15,12 +15,72 @@ import scrollGutter from './pm-plugins/scroll-gutter/plugin';
15
15
  import scrollGutterNext from './pm-plugins/scroll-gutter/plugin-next';
16
16
  import { getKeyboardHeight } from './pm-plugins/scroll-gutter/util/get-keyboard-height';
17
17
  import { inputTracking } from './pm-plugins/utils/inputTrackingConfig';
18
+
19
+ // eslint-disable-next-line @typescript-eslint/max-params
20
+ export function resolveCallbacks(from, to, tr, callbacks) {
21
+ const {
22
+ doc
23
+ } = tr;
24
+ doc.nodesBetween(from, to, (node, pos) => {
25
+ callbacks.forEach(cb => cb({
26
+ tr,
27
+ node,
28
+ pos,
29
+ from,
30
+ to
31
+ }));
32
+ });
33
+ }
34
+ const SMART_TO_ASCII = {
35
+ '…': '...',
36
+ '→': '->',
37
+ '←': '<-',
38
+ '–': '--',
39
+ '“': '"',
40
+ '”': '"',
41
+ '‘': "'",
42
+ '’': "'"
43
+ };
44
+
45
+ // eslint-disable-next-line require-unicode-regexp
46
+ const FIND_SMART_CHAR = new RegExp(`[${Object.keys(SMART_TO_ASCII).join('')}]`, 'g');
18
47
  const basePlugin = ({
19
48
  config: options,
20
49
  api
21
50
  }) => {
22
- var _api$featureFlags;
51
+ var _api$featureFlags, _api$base;
23
52
  const featureFlags = (api === null || api === void 0 ? void 0 : (_api$featureFlags = api.featureFlags) === null || _api$featureFlags === void 0 ? void 0 : _api$featureFlags.sharedState.currentState()) || {};
53
+ const callbacks = [];
54
+ api === null || api === void 0 ? void 0 : (_api$base = api.base) === null || _api$base === void 0 ? void 0 : _api$base.actions.registerMarks(({
55
+ tr,
56
+ node,
57
+ pos,
58
+ from,
59
+ to
60
+ }) => {
61
+ const {
62
+ doc
63
+ } = tr;
64
+ const {
65
+ schema
66
+ } = doc.type;
67
+ const {
68
+ text: textNodeType
69
+ } = schema.nodes;
70
+ if (node.type === textNodeType && node.text) {
71
+ // Find a valid start and end position because the text may be partially selected.
72
+ const startPositionInSelection = Math.max(pos, from);
73
+ const endPositionInSelection = Math.min(pos + node.nodeSize, to);
74
+ const textForReplacing = doc.textBetween(startPositionInSelection, endPositionInSelection);
75
+ const newText = textForReplacing.replace(FIND_SMART_CHAR, match => {
76
+ var _SMART_TO_ASCII$match;
77
+ return (_SMART_TO_ASCII$match = SMART_TO_ASCII[match]) !== null && _SMART_TO_ASCII$match !== void 0 ? _SMART_TO_ASCII$match : match;
78
+ });
79
+ const currentStartPos = tr.mapping.map(startPositionInSelection);
80
+ const currentEndPos = tr.mapping.map(endPositionInSelection);
81
+ tr.replaceWith(currentStartPos, currentEndPos, schema.text(newText, node.marks));
82
+ }
83
+ });
24
84
  return {
25
85
  name: 'base',
26
86
  getSharedState(editorState) {
@@ -29,7 +89,11 @@ const basePlugin = ({
29
89
  };
30
90
  },
31
91
  actions: {
32
- setKeyboardHeight
92
+ setKeyboardHeight,
93
+ resolveMarks: (from, to, tr) => resolveCallbacks(from, to, tr, callbacks),
94
+ registerMarks: callback => {
95
+ callbacks.push(callback);
96
+ }
33
97
  },
34
98
  pmPlugins() {
35
99
  const plugins = [{
@@ -18,11 +18,64 @@ import scrollGutter from './pm-plugins/scroll-gutter/plugin';
18
18
  import scrollGutterNext from './pm-plugins/scroll-gutter/plugin-next';
19
19
  import { getKeyboardHeight } from './pm-plugins/scroll-gutter/util/get-keyboard-height';
20
20
  import { inputTracking } from './pm-plugins/utils/inputTrackingConfig';
21
+
22
+ // eslint-disable-next-line @typescript-eslint/max-params
23
+ export function resolveCallbacks(from, to, tr, callbacks) {
24
+ var doc = tr.doc;
25
+ doc.nodesBetween(from, to, function (node, pos) {
26
+ callbacks.forEach(function (cb) {
27
+ return cb({
28
+ tr: tr,
29
+ node: node,
30
+ pos: pos,
31
+ from: from,
32
+ to: to
33
+ });
34
+ });
35
+ });
36
+ }
37
+ var SMART_TO_ASCII = {
38
+ '…': '...',
39
+ '→': '->',
40
+ '←': '<-',
41
+ '–': '--',
42
+ '“': '"',
43
+ '”': '"',
44
+ '‘': "'",
45
+ '’': "'"
46
+ };
47
+
48
+ // eslint-disable-next-line require-unicode-regexp
49
+ var FIND_SMART_CHAR = new RegExp("[".concat(Object.keys(SMART_TO_ASCII).join(''), "]"), 'g');
21
50
  var basePlugin = function basePlugin(_ref) {
22
- var _api$featureFlags;
51
+ var _api$featureFlags, _api$base;
23
52
  var options = _ref.config,
24
53
  api = _ref.api;
25
54
  var featureFlags = (api === null || api === void 0 || (_api$featureFlags = api.featureFlags) === null || _api$featureFlags === void 0 ? void 0 : _api$featureFlags.sharedState.currentState()) || {};
55
+ var callbacks = [];
56
+ api === null || api === void 0 || (_api$base = api.base) === null || _api$base === void 0 || _api$base.actions.registerMarks(function (_ref2) {
57
+ var tr = _ref2.tr,
58
+ node = _ref2.node,
59
+ pos = _ref2.pos,
60
+ from = _ref2.from,
61
+ to = _ref2.to;
62
+ var doc = tr.doc;
63
+ var schema = doc.type.schema;
64
+ var textNodeType = schema.nodes.text;
65
+ if (node.type === textNodeType && node.text) {
66
+ // Find a valid start and end position because the text may be partially selected.
67
+ var startPositionInSelection = Math.max(pos, from);
68
+ var endPositionInSelection = Math.min(pos + node.nodeSize, to);
69
+ var textForReplacing = doc.textBetween(startPositionInSelection, endPositionInSelection);
70
+ var newText = textForReplacing.replace(FIND_SMART_CHAR, function (match) {
71
+ var _SMART_TO_ASCII$match;
72
+ return (_SMART_TO_ASCII$match = SMART_TO_ASCII[match]) !== null && _SMART_TO_ASCII$match !== void 0 ? _SMART_TO_ASCII$match : match;
73
+ });
74
+ var currentStartPos = tr.mapping.map(startPositionInSelection);
75
+ var currentEndPos = tr.mapping.map(endPositionInSelection);
76
+ tr.replaceWith(currentStartPos, currentEndPos, schema.text(newText, node.marks));
77
+ }
78
+ });
26
79
  return {
27
80
  name: 'base',
28
81
  getSharedState: function getSharedState(editorState) {
@@ -31,13 +84,19 @@ var basePlugin = function basePlugin(_ref) {
31
84
  };
32
85
  },
33
86
  actions: {
34
- setKeyboardHeight: setKeyboardHeight
87
+ setKeyboardHeight: setKeyboardHeight,
88
+ resolveMarks: function resolveMarks(from, to, tr) {
89
+ return resolveCallbacks(from, to, tr, callbacks);
90
+ },
91
+ registerMarks: function registerMarks(callback) {
92
+ callbacks.push(callback);
93
+ }
35
94
  },
36
95
  pmPlugins: function pmPlugins() {
37
96
  var plugins = [{
38
97
  name: 'filterStepsPlugin',
39
- plugin: function plugin(_ref2) {
40
- var dispatchAnalyticsEvent = _ref2.dispatchAnalyticsEvent;
98
+ plugin: function plugin(_ref3) {
99
+ var dispatchAnalyticsEvent = _ref3.dispatchAnalyticsEvent;
41
100
  return filterStepsPlugin(dispatchAnalyticsEvent);
42
101
  }
43
102
  }];
@@ -74,8 +133,8 @@ var basePlugin = function basePlugin(_ref) {
74
133
  plugin: newlinePreserveMarksPlugin
75
134
  }, {
76
135
  name: 'frozenEditor',
77
- plugin: function plugin(_ref3) {
78
- var dispatchAnalyticsEvent = _ref3.dispatchAnalyticsEvent;
136
+ plugin: function plugin(_ref4) {
137
+ var dispatchAnalyticsEvent = _ref4.dispatchAnalyticsEvent;
79
138
  return frozenEditor(api === null || api === void 0 ? void 0 : api.contextIdentifier)(dispatchAnalyticsEvent, inputTracking, undefined);
80
139
  }
81
140
  }, {
@@ -1,3 +1,5 @@
1
- import { type BasePlugin } from './basePluginType';
1
+ import type { Transaction } from '@atlaskit/editor-prosemirror/state';
2
+ import type { BasePlugin, Callback } from './basePluginType';
3
+ export declare function resolveCallbacks(from: number, to: number, tr: Transaction, callbacks: Callback[]): void;
2
4
  declare const basePlugin: BasePlugin;
3
5
  export default basePlugin;
@@ -1,6 +1,8 @@
1
1
  import type { BrowserFreezetracking, InputTracking, NextEditorPlugin, OptionalPlugin } from '@atlaskit/editor-common/types';
2
2
  import type { ContextIdentifierPlugin } from '@atlaskit/editor-plugin-context-identifier';
3
3
  import type { FeatureFlagsPlugin } from '@atlaskit/editor-plugin-feature-flags';
4
+ import type { Node as PMNode } from '@atlaskit/editor-prosemirror/model';
5
+ import type { Transaction } from '@atlaskit/editor-prosemirror/state';
4
6
  import { type setKeyboardHeight } from './editor-commands/set-keyboard-height';
5
7
  import type { ScrollGutterPluginOptions } from './pm-plugins/scroll-gutter/plugin';
6
8
  export interface BasePluginOptions {
@@ -25,5 +27,14 @@ export type BasePlugin = NextEditorPlugin<'base', {
25
27
  sharedState: BasePluginState;
26
28
  actions: {
27
29
  setKeyboardHeight: typeof setKeyboardHeight;
30
+ registerMarks: (callback: Callback) => void;
31
+ resolveMarks: (from: number, to: number, tr: Transaction) => void;
28
32
  };
29
33
  }>;
34
+ export type Callback = ({ node, tr, pos, from, to, }: {
35
+ node: PMNode;
36
+ tr: Transaction;
37
+ pos: number;
38
+ from: number;
39
+ to: number;
40
+ }) => void;
@@ -1,3 +1,5 @@
1
- import { type BasePlugin } from './basePluginType';
1
+ import type { Transaction } from '@atlaskit/editor-prosemirror/state';
2
+ import type { BasePlugin, Callback } from './basePluginType';
3
+ export declare function resolveCallbacks(from: number, to: number, tr: Transaction, callbacks: Callback[]): void;
2
4
  declare const basePlugin: BasePlugin;
3
5
  export default basePlugin;
@@ -1,6 +1,8 @@
1
1
  import type { BrowserFreezetracking, InputTracking, NextEditorPlugin, OptionalPlugin } from '@atlaskit/editor-common/types';
2
2
  import type { ContextIdentifierPlugin } from '@atlaskit/editor-plugin-context-identifier';
3
3
  import type { FeatureFlagsPlugin } from '@atlaskit/editor-plugin-feature-flags';
4
+ import type { Node as PMNode } from '@atlaskit/editor-prosemirror/model';
5
+ import type { Transaction } from '@atlaskit/editor-prosemirror/state';
4
6
  import { type setKeyboardHeight } from './editor-commands/set-keyboard-height';
5
7
  import type { ScrollGutterPluginOptions } from './pm-plugins/scroll-gutter/plugin';
6
8
  export interface BasePluginOptions {
@@ -28,5 +30,14 @@ export type BasePlugin = NextEditorPlugin<'base', {
28
30
  sharedState: BasePluginState;
29
31
  actions: {
30
32
  setKeyboardHeight: typeof setKeyboardHeight;
33
+ registerMarks: (callback: Callback) => void;
34
+ resolveMarks: (from: number, to: number, tr: Transaction) => void;
31
35
  };
32
36
  }>;
37
+ export type Callback = ({ node, tr, pos, from, to, }: {
38
+ node: PMNode;
39
+ tr: Transaction;
40
+ pos: number;
41
+ from: number;
42
+ to: number;
43
+ }) => void;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atlaskit/editor-plugin-base",
3
- "version": "2.0.12",
3
+ "version": "2.1.0",
4
4
  "description": "Base plugin for @atlaskit/editor-core",
5
5
  "author": "Atlassian Pty Ltd",
6
6
  "license": "Apache-2.0",
@@ -32,12 +32,12 @@
32
32
  },
33
33
  "dependencies": {
34
34
  "@atlaskit/adf-schema": "^46.1.0",
35
- "@atlaskit/editor-common": "^98.0.0",
35
+ "@atlaskit/editor-common": "^99.0.0",
36
36
  "@atlaskit/editor-plugin-context-identifier": "^1.3.0",
37
37
  "@atlaskit/editor-plugin-feature-flags": "^1.2.0",
38
38
  "@atlaskit/editor-prosemirror": "6.2.1",
39
39
  "@atlaskit/platform-feature-flags": "^0.3.0",
40
- "@atlaskit/tmp-editor-statsig": "^2.31.0",
40
+ "@atlaskit/tmp-editor-statsig": "^2.33.0",
41
41
  "@babel/runtime": "^7.0.0"
42
42
  },
43
43
  "techstack": {