@atlaskit/editor-plugin-text-formatting 1.16.8 → 1.16.10

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.
Files changed (36) hide show
  1. package/CHANGELOG.md +19 -0
  2. package/dist/cjs/editor-commands/utils/marks.js +120 -0
  3. package/dist/cjs/pm-plugins/commands.js +18 -12
  4. package/dist/cjs/pm-plugins/input-rule.js +15 -7
  5. package/dist/cjs/textFormattingPlugin.js +1 -1
  6. package/dist/cjs/ui/Toolbar/index.js +9 -1
  7. package/dist/cjs/ui/Toolbar/more-button.js +1 -1
  8. package/dist/cjs/ui/Toolbar/single-toolbar-buttons.js +8 -1
  9. package/dist/es2019/editor-commands/utils/marks.js +117 -0
  10. package/dist/es2019/pm-plugins/commands.js +7 -2
  11. package/dist/es2019/pm-plugins/input-rule.js +15 -7
  12. package/dist/es2019/textFormattingPlugin.js +1 -1
  13. package/dist/es2019/ui/Toolbar/index.js +10 -2
  14. package/dist/es2019/ui/Toolbar/more-button.js +1 -1
  15. package/dist/es2019/ui/Toolbar/single-toolbar-buttons.js +9 -2
  16. package/dist/esm/editor-commands/utils/marks.js +114 -0
  17. package/dist/esm/pm-plugins/commands.js +18 -12
  18. package/dist/esm/pm-plugins/input-rule.js +15 -7
  19. package/dist/esm/textFormattingPlugin.js +1 -1
  20. package/dist/esm/ui/Toolbar/index.js +10 -2
  21. package/dist/esm/ui/Toolbar/more-button.js +1 -1
  22. package/dist/esm/ui/Toolbar/single-toolbar-buttons.js +9 -2
  23. package/dist/types/editor-commands/utils/marks.d.ts +14 -0
  24. package/dist/types/pm-plugins/commands.d.ts +6 -3
  25. package/dist/types/pm-plugins/input-rule.d.ts +3 -1
  26. package/dist/types/textFormattingPluginType.d.ts +6 -1
  27. package/dist/types-ts4.5/editor-commands/utils/marks.d.ts +14 -0
  28. package/dist/types-ts4.5/pm-plugins/commands.d.ts +6 -3
  29. package/dist/types-ts4.5/pm-plugins/input-rule.d.ts +3 -1
  30. package/dist/types-ts4.5/textFormattingPluginType.d.ts +3 -1
  31. package/package.json +12 -5
  32. package/dist/cjs/editor-commands/transform-to-code.js +0 -79
  33. package/dist/es2019/editor-commands/transform-to-code.js +0 -83
  34. package/dist/esm/editor-commands/transform-to-code.js +0 -73
  35. package/dist/types/editor-commands/transform-to-code.d.ts +0 -2
  36. package/dist/types-ts4.5/editor-commands/transform-to-code.d.ts +0 -2
package/CHANGELOG.md CHANGED
@@ -1,5 +1,24 @@
1
1
  # @atlaskit/editor-plugin-text-formatting
2
2
 
3
+ ## 1.16.10
4
+
5
+ ### Patch 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
+ - Updated dependencies
13
+
14
+ ## 1.16.9
15
+
16
+ ### Patch Changes
17
+
18
+ - [#100162](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/pull-requests/100162)
19
+ [`e80e57fc37719`](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/commits/e80e57fc37719) -
20
+ [ux] ED-26089: Add 4px gap to main nav bar items
21
+
3
22
  ## 1.16.8
4
23
 
5
24
  ### Patch Changes
@@ -0,0 +1,120 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.nextToggleMark = exports.nextApplyMarkOnRange = void 0;
7
+ var _mark = require("@atlaskit/editor-common/mark");
8
+ var _state = require("@atlaskit/editor-prosemirror/state");
9
+ var _cellSelection = require("@atlaskit/editor-tables/cell-selection");
10
+ var _platformFeatureFlags = require("@atlaskit/platform-feature-flags");
11
+ /**
12
+ * A custom version of the ProseMirror toggleMark, where we only toggle marks
13
+ * on text nodes in the selection rather than all inline nodes.
14
+ * @param markType
15
+ * @param attrs
16
+ */
17
+ var nextToggleMark = exports.nextToggleMark = function nextToggleMark(markType, api, attrs) {
18
+ return function (_ref) {
19
+ var tr = _ref.tr;
20
+ var mark = markType.create(attrs);
21
+
22
+ // For cursor selections we can use the default behaviour.
23
+ if (tr.selection instanceof _state.TextSelection && tr.selection.$cursor) {
24
+ if (mark.isInSet(tr.storedMarks || tr.selection.$cursor.marks())) {
25
+ tr.removeStoredMark(mark);
26
+ } else {
27
+ tr.addStoredMark(mark);
28
+ }
29
+ return tr;
30
+ }
31
+ return nextToggleMarkInRange(mark, api)({
32
+ tr: tr
33
+ });
34
+ };
35
+ };
36
+ var nextToggleMarkInRange = function nextToggleMarkInRange(mark, api) {
37
+ return function (_ref2) {
38
+ var tr = _ref2.tr;
39
+ if (tr.selection instanceof _cellSelection.CellSelection) {
40
+ var removeMark = true;
41
+ var cells = [];
42
+ tr.selection.forEachCell(function (cell, cellPos) {
43
+ cells.push({
44
+ node: cell,
45
+ pos: cellPos
46
+ });
47
+ var from = cellPos;
48
+ var to = cellPos + cell.nodeSize;
49
+ removeMark && (removeMark = (0, _mark.entireSelectionContainsMark)(mark, tr.doc, from, to));
50
+ });
51
+ for (var i = cells.length - 1; i >= 0; i--) {
52
+ var cell = cells[i];
53
+ var from = cell.pos;
54
+ var to = from + cell.node.nodeSize;
55
+ nextApplyMarkOnRange(from, to, removeMark, mark, tr, api);
56
+ }
57
+ } else {
58
+ var _tr$selection = tr.selection,
59
+ $from = _tr$selection.$from,
60
+ $to = _tr$selection.$to;
61
+ // We decide to remove the mark only if the entire selection contains the mark
62
+ // Examples with *bold* text
63
+ // Scenario 1: Selection contains both bold and non-bold text -> bold entire selection
64
+ // Scenario 2: Selection contains only bold text -> un-bold entire selection
65
+ // Scenario 3: Selection contains no bold text -> bold entire selection
66
+ var _removeMark = (0, _mark.entireSelectionContainsMark)(mark, tr.doc, $from.pos, $to.pos);
67
+ nextApplyMarkOnRange($from.pos, $to.pos, _removeMark, mark, tr, api);
68
+ }
69
+ if (tr.docChanged) {
70
+ return tr;
71
+ }
72
+ return null;
73
+ };
74
+ };
75
+ var nextApplyMarkOnRange = exports.nextApplyMarkOnRange = function nextApplyMarkOnRange(from, to, removeMark, mark, tr, api
76
+ // eslint-disable-next-line @typescript-eslint/max-params
77
+ ) {
78
+ var schema = tr.doc.type.schema;
79
+ var code = schema.marks.code;
80
+ if (mark.type === code) {
81
+ if ((0, _platformFeatureFlags.fg)('platform_editor_resolve_marks')) {
82
+ var _api$base;
83
+ api === null || api === void 0 || (_api$base = api.base) === null || _api$base === void 0 || _api$base.actions.resolveMarks(from, to, tr);
84
+ } else {
85
+ (0, _mark.transformNonTextNodesToText)(from, to, tr);
86
+ }
87
+ }
88
+
89
+ /**
90
+ * We should refactor this so text formatting doesn't reference plugins it doesn't know about.
91
+ */
92
+ tr.doc.nodesBetween(tr.mapping.map(from), tr.mapping.map(to), function (node, pos) {
93
+ if ((0, _platformFeatureFlags.fg)('editor_inline_comments_on_inline_nodes')) {
94
+ if (!node.isText) {
95
+ var isAllowedInlineNode = ['emoji', 'status', 'date', 'mention', 'inlineCard'].includes(node.type.name);
96
+ if (!isAllowedInlineNode) {
97
+ return true;
98
+ }
99
+ }
100
+ } else {
101
+ if (!node.isText) {
102
+ return true;
103
+ }
104
+ }
105
+
106
+ // This is an issue when the user selects some text.
107
+ // We need to check if the current node position is less than the range selection from.
108
+ // If it’s true, that means we should apply the mark using the range selection,
109
+ // not the current node position.
110
+ var nodeBetweenFrom = Math.max(pos, tr.mapping.map(from));
111
+ var nodeBetweenTo = Math.min(pos + node.nodeSize, tr.mapping.map(to));
112
+ if (removeMark) {
113
+ tr.removeMark(nodeBetweenFrom, nodeBetweenTo, mark);
114
+ } else {
115
+ tr.addMark(nodeBetweenFrom, nodeBetweenTo, mark);
116
+ }
117
+ return true;
118
+ });
119
+ return tr;
120
+ };
@@ -6,6 +6,7 @@ Object.defineProperty(exports, "__esModule", {
6
6
  exports.toggleUnderlineWithAnalytics = exports.toggleUnderline = exports.toggleSuperscriptWithAnalytics = exports.toggleSuperscript = exports.toggleSubscriptWithAnalytics = exports.toggleSubscript = exports.toggleStrongWithAnalytics = exports.toggleStrong = exports.toggleStrikeWithAnalytics = exports.toggleStrike = exports.toggleEmWithAnalytics = exports.toggleEm = exports.toggleCodeWithAnalytics = exports.toggleCode = void 0;
7
7
  var _analytics = require("@atlaskit/editor-common/analytics");
8
8
  var _mark = require("@atlaskit/editor-common/mark");
9
+ var _marks = require("../editor-commands/utils/marks");
9
10
  var toggleEm = exports.toggleEm = function toggleEm(_ref) {
10
11
  var tr = _ref.tr;
11
12
  var em = tr.doc.type.schema.marks.em;
@@ -221,21 +222,26 @@ var toggleSubscriptWithAnalytics = exports.toggleSubscriptWithAnalytics = functi
221
222
  };
222
223
  };
223
224
  var toggleCode = exports.toggleCode = function toggleCode(_ref13) {
224
- var tr = _ref13.tr;
225
- var code = tr.doc.type.schema.marks.code;
226
- if (!code) {
227
- // No transaction to apply
228
- return null;
229
- }
230
- return (0, _mark.toggleMark)(code)({
231
- tr: tr
232
- });
225
+ var api = _ref13.api;
226
+ return function (_ref14) {
227
+ var tr = _ref14.tr;
228
+ var code = tr.doc.type.schema.marks.code;
229
+ if (!code) {
230
+ // No transaction to apply
231
+ return null;
232
+ }
233
+ return (0, _marks.nextToggleMark)(code, api)({
234
+ tr: tr
235
+ });
236
+ };
233
237
  };
234
- var toggleCodeWithAnalytics = exports.toggleCodeWithAnalytics = function toggleCodeWithAnalytics(editorAnalyticsApi) {
238
+ var toggleCodeWithAnalytics = exports.toggleCodeWithAnalytics = function toggleCodeWithAnalytics(editorAnalyticsApi, api) {
235
239
  return function (inputMethod) {
236
- return function (_ref14) {
237
- var tr = _ref14.tr;
240
+ return function (_ref15) {
241
+ var tr = _ref15.tr;
238
242
  var newTr = toggleCode({
243
+ api: api
244
+ })({
239
245
  tr: tr
240
246
  });
241
247
  if (!newTr) {
@@ -20,6 +20,7 @@ var _analytics = require("@atlaskit/editor-common/analytics");
20
20
  var _mark = require("@atlaskit/editor-common/mark");
21
21
  var _safePlugin = require("@atlaskit/editor-common/safe-plugin");
22
22
  var _utils = require("@atlaskit/editor-common/utils");
23
+ var _platformFeatureFlags = require("@atlaskit/platform-feature-flags");
23
24
  var _prosemirrorInputRules = require("@atlaskit/prosemirror-input-rules");
24
25
  function _callSuper(t, o, e) { return o = (0, _getPrototypeOf2.default)(o), (0, _possibleConstructorReturn2.default)(t, _isNativeReflectConstruct() ? Reflect.construct(o, e || [], (0, _getPrototypeOf2.default)(t).constructor) : o.apply(t, e)); }
25
26
  function _isNativeReflectConstruct() { try { var t = !Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); } catch (t) {} return (_isNativeReflectConstruct = function _isNativeReflectConstruct() { return !!t; })(); }
@@ -60,10 +61,12 @@ ValidAutoformatChars.STRIKE,
60
61
  ValidAutoformatChars.STRONG_MARKDOWN]), ValidAutoformatChars.CODE, [
61
62
  // e.g: loko (`some code`
62
63
  '( ']);
63
- function addMark(markType, schema, char) {
64
+
65
+ // eslint-disable-next-line @typescript-eslint/max-params
66
+ function addMark(markType, _schema, char, api) {
64
67
  // Ignored via go/ees005
65
68
  // eslint-disable-next-line @typescript-eslint/max-params
66
- return function (state, match, start, end) {
69
+ return function (state, _match, start, end) {
67
70
  var _schema$marks;
68
71
  var doc = state.doc,
69
72
  schema = state.schema,
@@ -97,7 +100,12 @@ function addMark(markType, schema, char) {
97
100
  return null;
98
101
  }
99
102
  if (markType.name === 'code') {
100
- (0, _mark.transformNonTextNodesToText)(tr.mapping.map(start), tr.mapping.map(end), tr);
103
+ if ((0, _platformFeatureFlags.fg)('platform_editor_resolve_marks')) {
104
+ var _api$base;
105
+ api === null || api === void 0 || (_api$base = api.base) === null || _api$base === void 0 || (_api$base = _api$base.actions) === null || _api$base === void 0 || _api$base.resolveMarks(tr.mapping.map(start), tr.mapping.map(end), tr);
106
+ } else {
107
+ (0, _mark.transformNonTextNodesToText)(tr.mapping.map(start), tr.mapping.map(end), tr);
108
+ }
101
109
  }
102
110
  var mappedStart = tr.mapping.map(start);
103
111
  var mappedEnd = tr.mapping.map(end);
@@ -242,7 +250,7 @@ function getStrikeInputRules(schema, editorAnalyticsAPI) {
242
250
  * @param {Schema} schema
243
251
  * @returns {InputRuleWrapper[]}
244
252
  */
245
- function getCodeInputRules(schema, editorAnalyticsAPI) {
253
+ function getCodeInputRules(schema, editorAnalyticsAPI, api) {
246
254
  var ruleWithCodeAnalytics = (0, _utils.inputRuleWithAnalytics)({
247
255
  action: _analytics.ACTION.FORMATTED,
248
256
  actionSubject: _analytics.ACTION_SUBJECT.TEXT,
@@ -252,10 +260,10 @@ function getCodeInputRules(schema, editorAnalyticsAPI) {
252
260
  inputMethod: _analytics.INPUT_METHOD.FORMATTING
253
261
  }
254
262
  }, editorAnalyticsAPI);
255
- var backTickRule = (0, _utils.createRule)(codeRegex, addMark(schema.marks.code, schema, ValidAutoformatChars.CODE));
263
+ var backTickRule = (0, _utils.createRule)(codeRegex, addMark(schema.marks.code, schema, ValidAutoformatChars.CODE, api));
256
264
  return [ruleWithCodeAnalytics(backTickRule)];
257
265
  }
258
- function inputRulePlugin(schema, editorAnalyticsAPI) {
266
+ function inputRulePlugin(schema, editorAnalyticsAPI, api) {
259
267
  var rules = [];
260
268
  if (schema.marks.strong) {
261
269
  rules.push.apply(rules, (0, _toConsumableArray2.default)(getStrongInputRules(schema, editorAnalyticsAPI)));
@@ -267,7 +275,7 @@ function inputRulePlugin(schema, editorAnalyticsAPI) {
267
275
  rules.push.apply(rules, (0, _toConsumableArray2.default)(getStrikeInputRules(schema, editorAnalyticsAPI)));
268
276
  }
269
277
  if (schema.marks.code) {
270
- rules.push.apply(rules, (0, _toConsumableArray2.default)(getCodeInputRules(schema, editorAnalyticsAPI)));
278
+ rules.push.apply(rules, (0, _toConsumableArray2.default)(getCodeInputRules(schema, editorAnalyticsAPI, api)));
271
279
  }
272
280
  if (rules.length !== 0) {
273
281
  return new _safePlugin.SafePlugin((0, _prosemirrorInputRules.createPlugin)('text-formatting', rules));
@@ -93,7 +93,7 @@ var textFormattingPlugin = exports.textFormattingPlugin = function textFormattin
93
93
  plugin: function plugin(_ref4) {
94
94
  var _api$analytics2;
95
95
  var schema = _ref4.schema;
96
- return (0, _inputRule.default)(schema, api === null || api === void 0 || (_api$analytics2 = api.analytics) === null || _api$analytics2 === void 0 ? void 0 : _api$analytics2.actions);
96
+ return (0, _inputRule.default)(schema, api === null || api === void 0 || (_api$analytics2 = api.analytics) === null || _api$analytics2 === void 0 ? void 0 : _api$analytics2.actions, api);
97
97
  }
98
98
  }, {
99
99
  name: 'textFormattingSmartRule',
@@ -14,6 +14,7 @@ var _hooks = require("@atlaskit/editor-common/hooks");
14
14
  var _messages = require("@atlaskit/editor-common/messages");
15
15
  var _styles = require("@atlaskit/editor-common/styles");
16
16
  var _ui = require("@atlaskit/editor-common/ui");
17
+ var _platformFeatureFlags = require("@atlaskit/platform-feature-flags");
17
18
  var _utils = require("../../editor-commands/utils");
18
19
  var _dropdownMenu = require("./dropdown-menu");
19
20
  var _clearFormattingIcon = require("./hooks/clear-formatting-icon");
@@ -139,7 +140,13 @@ var ToolbarFormatting = function ToolbarFormatting(_ref) {
139
140
  return (
140
141
  // eslint-disable-next-line @atlaskit/design-system/consistent-css-prop-usage, @atlaskit/ui-styling-standard/no-imported-style-values -- Ignored via go/DSP-18766
141
142
  (0, _react2.jsx)("span", {
142
- css: _styles.buttonGroupStyle
143
+ css:
144
+ // eslint-disable-next-line @atlaskit/platform/ensure-feature-flag-registration, @atlaskit/platform/ensure-feature-flag-prefix
145
+ (0, _platformFeatureFlags.fg)('platform-visual-refresh-icons') ?
146
+ // eslint-disable-next-line @atlaskit/design-system/consistent-css-prop-usage, @atlaskit/ui-styling-standard/no-imported-style-values
147
+ _styles.buttonGroupStyle :
148
+ // eslint-disable-next-line @atlaskit/design-system/consistent-css-prop-usage, @atlaskit/ui-styling-standard/no-imported-style-values
149
+ _styles.buttonGroupStyleBeforeVisualRefresh
143
150
  }, (0, _react2.jsx)("div", {
144
151
  role: "group"
145
152
  // eslint-disable-next-line @atlaskit/ui-styling-standard/no-classname-prop -- Ignored via go/DSP-18766
@@ -156,6 +163,7 @@ var ToolbarFormatting = function ToolbarFormatting(_ref) {
156
163
  editorView: editorView,
157
164
  isReducedSpacing: isReducedSpacing
158
165
  }), (0, _react2.jsx)("span", {
166
+ // eslint-disable-next-line @atlaskit/ui-styling-standard/no-imported-style-values, @atlaskit/design-system/consistent-css-prop-usage
159
167
  css: _styles.wrapperStyle
160
168
  }, isToolbarDisabled ? (0, _react2.jsx)("div", null, (0, _react2.jsx)(_moreButton.MoreButton, {
161
169
  label: moreFormattingButtonLabel,
@@ -39,7 +39,7 @@ var MoreButton = exports.MoreButton = /*#__PURE__*/_react.default.memo(function
39
39
  spacing: isReducedSpacing ? 'none' : 'default',
40
40
  title: label,
41
41
  iconBefore:
42
- // eslint-disable-next-line @atlaskit/design-system/consistent-css-prop-usage, @atlaskit/ui-styling-standard/no-imported-style-values -- Ignored via go/DSP-18766
42
+ // eslint-disable-next-line @atlaskit/design-system/consistent-css-prop-usage, @atlaskit/ui-styling-standard/no-imported-style-values, @atlaskit/platform/ensure-feature-flag-prefix -- Ignored via go/DSP-18766
43
43
  (0, _react2.jsx)("div", {
44
44
  css: (0, _platformFeatureFlags.fg)('platform-visual-refresh-icons') ? MoreIconStyle : _styles.triggerWrapperStyles
45
45
  }, (0, _react2.jsx)(_showMoreHorizontalEditorMore.default, {
@@ -9,6 +9,7 @@ var _react = _interopRequireWildcard(require("react"));
9
9
  var _react2 = require("@emotion/react");
10
10
  var _styles = require("@atlaskit/editor-common/styles");
11
11
  var _uiMenu = require("@atlaskit/editor-common/ui-menu");
12
+ var _platformFeatureFlags = require("@atlaskit/platform-feature-flags");
12
13
  function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(e) { return e ? t : r; })(e); }
13
14
  function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != _typeof(e) && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && {}.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
14
15
  /**
@@ -31,7 +32,13 @@ var SingleToolbarButtons = exports.SingleToolbarButtons = /*#__PURE__*/_react.de
31
32
  return (
32
33
  // eslint-disable-next-line @atlaskit/design-system/consistent-css-prop-usage, @atlaskit/ui-styling-standard/no-imported-style-values -- Ignored via go/DSP-18766
33
34
  (0, _react2.jsx)("span", {
34
- css: _styles.buttonGroupStyle
35
+ css:
36
+ // eslint-disable-next-line @atlaskit/platform/ensure-feature-flag-registration, @atlaskit/platform/ensure-feature-flag-prefix
37
+ (0, _platformFeatureFlags.fg)('platform-visual-refresh-icons') ?
38
+ // eslint-disable-next-line @atlaskit/design-system/consistent-css-prop-usage, @atlaskit/ui-styling-standard/no-imported-style-values
39
+ _styles.buttonGroupStyle :
40
+ // eslint-disable-next-line @atlaskit/design-system/consistent-css-prop-usage, @atlaskit/ui-styling-standard/no-imported-style-values
41
+ _styles.buttonGroupStyleBeforeVisualRefresh
35
42
  }, items.map(function (item) {
36
43
  var _item$ariaLabel;
37
44
  return (0, _react2.jsx)(_uiMenu.ToolbarButton, {
@@ -0,0 +1,117 @@
1
+ import { entireSelectionContainsMark, transformNonTextNodesToText } from '@atlaskit/editor-common/mark';
2
+ import { TextSelection } from '@atlaskit/editor-prosemirror/state';
3
+ import { CellSelection } from '@atlaskit/editor-tables/cell-selection';
4
+ import { fg } from '@atlaskit/platform-feature-flags';
5
+ /**
6
+ * A custom version of the ProseMirror toggleMark, where we only toggle marks
7
+ * on text nodes in the selection rather than all inline nodes.
8
+ * @param markType
9
+ * @param attrs
10
+ */
11
+ export const nextToggleMark = (markType, api, attrs) => ({
12
+ tr
13
+ }) => {
14
+ const mark = markType.create(attrs);
15
+
16
+ // For cursor selections we can use the default behaviour.
17
+ if (tr.selection instanceof TextSelection && tr.selection.$cursor) {
18
+ if (mark.isInSet(tr.storedMarks || tr.selection.$cursor.marks())) {
19
+ tr.removeStoredMark(mark);
20
+ } else {
21
+ tr.addStoredMark(mark);
22
+ }
23
+ return tr;
24
+ }
25
+ return nextToggleMarkInRange(mark, api)({
26
+ tr
27
+ });
28
+ };
29
+ const nextToggleMarkInRange = (mark, api) => ({
30
+ tr
31
+ }) => {
32
+ if (tr.selection instanceof CellSelection) {
33
+ let removeMark = true;
34
+ const cells = [];
35
+ tr.selection.forEachCell((cell, cellPos) => {
36
+ cells.push({
37
+ node: cell,
38
+ pos: cellPos
39
+ });
40
+ const from = cellPos;
41
+ const to = cellPos + cell.nodeSize;
42
+ removeMark && (removeMark = entireSelectionContainsMark(mark, tr.doc, from, to));
43
+ });
44
+ for (let i = cells.length - 1; i >= 0; i--) {
45
+ const cell = cells[i];
46
+ const from = cell.pos;
47
+ const to = from + cell.node.nodeSize;
48
+ nextApplyMarkOnRange(from, to, removeMark, mark, tr, api);
49
+ }
50
+ } else {
51
+ const {
52
+ $from,
53
+ $to
54
+ } = tr.selection;
55
+ // We decide to remove the mark only if the entire selection contains the mark
56
+ // Examples with *bold* text
57
+ // Scenario 1: Selection contains both bold and non-bold text -> bold entire selection
58
+ // Scenario 2: Selection contains only bold text -> un-bold entire selection
59
+ // Scenario 3: Selection contains no bold text -> bold entire selection
60
+ const removeMark = entireSelectionContainsMark(mark, tr.doc, $from.pos, $to.pos);
61
+ nextApplyMarkOnRange($from.pos, $to.pos, removeMark, mark, tr, api);
62
+ }
63
+ if (tr.docChanged) {
64
+ return tr;
65
+ }
66
+ return null;
67
+ };
68
+ export const nextApplyMarkOnRange = (from, to, removeMark, mark, tr, api
69
+ // eslint-disable-next-line @typescript-eslint/max-params
70
+ ) => {
71
+ const {
72
+ schema
73
+ } = tr.doc.type;
74
+ const {
75
+ code
76
+ } = schema.marks;
77
+ if (mark.type === code) {
78
+ if (fg('platform_editor_resolve_marks')) {
79
+ var _api$base;
80
+ api === null || api === void 0 ? void 0 : (_api$base = api.base) === null || _api$base === void 0 ? void 0 : _api$base.actions.resolveMarks(from, to, tr);
81
+ } else {
82
+ transformNonTextNodesToText(from, to, tr);
83
+ }
84
+ }
85
+
86
+ /**
87
+ * We should refactor this so text formatting doesn't reference plugins it doesn't know about.
88
+ */
89
+ tr.doc.nodesBetween(tr.mapping.map(from), tr.mapping.map(to), (node, pos) => {
90
+ if (fg('editor_inline_comments_on_inline_nodes')) {
91
+ if (!node.isText) {
92
+ const isAllowedInlineNode = ['emoji', 'status', 'date', 'mention', 'inlineCard'].includes(node.type.name);
93
+ if (!isAllowedInlineNode) {
94
+ return true;
95
+ }
96
+ }
97
+ } else {
98
+ if (!node.isText) {
99
+ return true;
100
+ }
101
+ }
102
+
103
+ // This is an issue when the user selects some text.
104
+ // We need to check if the current node position is less than the range selection from.
105
+ // If it’s true, that means we should apply the mark using the range selection,
106
+ // not the current node position.
107
+ const nodeBetweenFrom = Math.max(pos, tr.mapping.map(from));
108
+ const nodeBetweenTo = Math.min(pos + node.nodeSize, tr.mapping.map(to));
109
+ if (removeMark) {
110
+ tr.removeMark(nodeBetweenFrom, nodeBetweenTo, mark);
111
+ } else {
112
+ tr.addMark(nodeBetweenFrom, nodeBetweenTo, mark);
113
+ }
114
+ return true;
115
+ });
116
+ return tr;
117
+ };
@@ -1,5 +1,6 @@
1
1
  import { ACTION, ACTION_SUBJECT, ACTION_SUBJECT_ID, EVENT_TYPE } from '@atlaskit/editor-common/analytics';
2
2
  import { toggleMark } from '@atlaskit/editor-common/mark';
3
+ import { nextToggleMark } from '../editor-commands/utils/marks';
3
4
  export const toggleEm = ({
4
5
  tr
5
6
  }) => {
@@ -215,6 +216,8 @@ export const toggleSubscriptWithAnalytics = editorAnalyticsApi => inputMethod =>
215
216
  return newTr;
216
217
  };
217
218
  export const toggleCode = ({
219
+ api
220
+ }) => ({
218
221
  tr
219
222
  }) => {
220
223
  const {
@@ -224,14 +227,16 @@ export const toggleCode = ({
224
227
  // No transaction to apply
225
228
  return null;
226
229
  }
227
- return toggleMark(code)({
230
+ return nextToggleMark(code, api)({
228
231
  tr
229
232
  });
230
233
  };
231
- export const toggleCodeWithAnalytics = editorAnalyticsApi => inputMethod => ({
234
+ export const toggleCodeWithAnalytics = (editorAnalyticsApi, api) => inputMethod => ({
232
235
  tr
233
236
  }) => {
234
237
  const newTr = toggleCode({
238
+ api
239
+ })({
235
240
  tr
236
241
  });
237
242
  if (!newTr) {
@@ -2,6 +2,7 @@ import { ACTION, ACTION_SUBJECT, ACTION_SUBJECT_ID, EVENT_TYPE, INPUT_METHOD } f
2
2
  import { transformNonTextNodesToText } from '@atlaskit/editor-common/mark';
3
3
  import { SafePlugin } from '@atlaskit/editor-common/safe-plugin';
4
4
  import { createRule, inputRuleWithAnalytics } from '@atlaskit/editor-common/utils';
5
+ import { fg } from '@atlaskit/platform-feature-flags';
5
6
  import { createPlugin, leafNodeReplacementCharacter } from '@atlaskit/prosemirror-input-rules';
6
7
  var ValidAutoformatChars = /*#__PURE__*/function (ValidAutoformatChars) {
7
8
  ValidAutoformatChars["STRONG"] = "__";
@@ -46,10 +47,12 @@ export const ValidCombinations = {
46
47
  // e.g: loko (`some code`
47
48
  '( ']
48
49
  };
49
- function addMark(markType, schema, char) {
50
+
51
+ // eslint-disable-next-line @typescript-eslint/max-params
52
+ function addMark(markType, _schema, char, api) {
50
53
  // Ignored via go/ees005
51
54
  // eslint-disable-next-line @typescript-eslint/max-params
52
- return (state, match, start, end) => {
55
+ return (state, _match, start, end) => {
53
56
  var _schema$marks, _schema$marks$code;
54
57
  const {
55
58
  doc,
@@ -85,7 +88,12 @@ function addMark(markType, schema, char) {
85
88
  return null;
86
89
  }
87
90
  if (markType.name === 'code') {
88
- transformNonTextNodesToText(tr.mapping.map(start), tr.mapping.map(end), tr);
91
+ if (fg('platform_editor_resolve_marks')) {
92
+ var _api$base, _api$base$actions;
93
+ api === null || api === void 0 ? void 0 : (_api$base = api.base) === null || _api$base === void 0 ? void 0 : (_api$base$actions = _api$base.actions) === null || _api$base$actions === void 0 ? void 0 : _api$base$actions.resolveMarks(tr.mapping.map(start), tr.mapping.map(end), tr);
94
+ } else {
95
+ transformNonTextNodesToText(tr.mapping.map(start), tr.mapping.map(end), tr);
96
+ }
89
97
  }
90
98
  const mappedStart = tr.mapping.map(start);
91
99
  const mappedEnd = tr.mapping.map(end);
@@ -220,7 +228,7 @@ function getStrikeInputRules(schema, editorAnalyticsAPI) {
220
228
  * @param {Schema} schema
221
229
  * @returns {InputRuleWrapper[]}
222
230
  */
223
- function getCodeInputRules(schema, editorAnalyticsAPI) {
231
+ function getCodeInputRules(schema, editorAnalyticsAPI, api) {
224
232
  const ruleWithCodeAnalytics = inputRuleWithAnalytics({
225
233
  action: ACTION.FORMATTED,
226
234
  actionSubject: ACTION_SUBJECT.TEXT,
@@ -230,10 +238,10 @@ function getCodeInputRules(schema, editorAnalyticsAPI) {
230
238
  inputMethod: INPUT_METHOD.FORMATTING
231
239
  }
232
240
  }, editorAnalyticsAPI);
233
- const backTickRule = createRule(codeRegex, addMark(schema.marks.code, schema, ValidAutoformatChars.CODE));
241
+ const backTickRule = createRule(codeRegex, addMark(schema.marks.code, schema, ValidAutoformatChars.CODE, api));
234
242
  return [ruleWithCodeAnalytics(backTickRule)];
235
243
  }
236
- export function inputRulePlugin(schema, editorAnalyticsAPI) {
244
+ export function inputRulePlugin(schema, editorAnalyticsAPI, api) {
237
245
  const rules = [];
238
246
  if (schema.marks.strong) {
239
247
  rules.push(...getStrongInputRules(schema, editorAnalyticsAPI));
@@ -245,7 +253,7 @@ export function inputRulePlugin(schema, editorAnalyticsAPI) {
245
253
  rules.push(...getStrikeInputRules(schema, editorAnalyticsAPI));
246
254
  }
247
255
  if (schema.marks.code) {
248
- rules.push(...getCodeInputRules(schema, editorAnalyticsAPI));
256
+ rules.push(...getCodeInputRules(schema, editorAnalyticsAPI, api));
249
257
  }
250
258
  if (rules.length !== 0) {
251
259
  return new SafePlugin(createPlugin('text-formatting', rules));
@@ -86,7 +86,7 @@ export const textFormattingPlugin = ({
86
86
  schema
87
87
  }) => {
88
88
  var _api$analytics2;
89
- return textFormattingInputRulePlugin(schema, api === null || api === void 0 ? void 0 : (_api$analytics2 = api.analytics) === null || _api$analytics2 === void 0 ? void 0 : _api$analytics2.actions);
89
+ return textFormattingInputRulePlugin(schema, api === null || api === void 0 ? void 0 : (_api$analytics2 = api.analytics) === null || _api$analytics2 === void 0 ? void 0 : _api$analytics2.actions, api);
90
90
  }
91
91
  }, {
92
92
  name: 'textFormattingSmartRule',
@@ -9,8 +9,9 @@ import { jsx } from '@emotion/react';
9
9
  import { injectIntl } from 'react-intl-next';
10
10
  import { usePreviousState } from '@atlaskit/editor-common/hooks';
11
11
  import { toolbarMessages } from '@atlaskit/editor-common/messages';
12
- import { buttonGroupStyle, separatorStyles, wrapperStyle } from '@atlaskit/editor-common/styles';
12
+ import { buttonGroupStyle, buttonGroupStyleBeforeVisualRefresh, separatorStyles, wrapperStyle } from '@atlaskit/editor-common/styles';
13
13
  import { Announcer } from '@atlaskit/editor-common/ui';
14
+ import { fg } from '@atlaskit/platform-feature-flags';
14
15
  import { compareItemsArrays, isArrayContainsContent } from '../../editor-commands/utils';
15
16
  import { FormattingTextDropdownMenu } from './dropdown-menu';
16
17
  import { useClearIcon } from './hooks/clear-formatting-icon';
@@ -126,7 +127,13 @@ const ToolbarFormatting = ({
126
127
  return (
127
128
  // eslint-disable-next-line @atlaskit/design-system/consistent-css-prop-usage, @atlaskit/ui-styling-standard/no-imported-style-values -- Ignored via go/DSP-18766
128
129
  jsx("span", {
129
- css: buttonGroupStyle
130
+ css:
131
+ // eslint-disable-next-line @atlaskit/platform/ensure-feature-flag-registration, @atlaskit/platform/ensure-feature-flag-prefix
132
+ fg('platform-visual-refresh-icons') ?
133
+ // eslint-disable-next-line @atlaskit/design-system/consistent-css-prop-usage, @atlaskit/ui-styling-standard/no-imported-style-values
134
+ buttonGroupStyle :
135
+ // eslint-disable-next-line @atlaskit/design-system/consistent-css-prop-usage, @atlaskit/ui-styling-standard/no-imported-style-values
136
+ buttonGroupStyleBeforeVisualRefresh
130
137
  }, jsx("div", {
131
138
  role: "group"
132
139
  // eslint-disable-next-line @atlaskit/ui-styling-standard/no-classname-prop -- Ignored via go/DSP-18766
@@ -143,6 +150,7 @@ const ToolbarFormatting = ({
143
150
  editorView: editorView,
144
151
  isReducedSpacing: isReducedSpacing
145
152
  }), jsx("span", {
153
+ // eslint-disable-next-line @atlaskit/ui-styling-standard/no-imported-style-values, @atlaskit/design-system/consistent-css-prop-usage
146
154
  css: wrapperStyle
147
155
  }, isToolbarDisabled ? jsx("div", null, jsx(MoreButton, {
148
156
  label: moreFormattingButtonLabel,
@@ -32,7 +32,7 @@ export const MoreButton = /*#__PURE__*/React.memo(({
32
32
  spacing: isReducedSpacing ? 'none' : 'default',
33
33
  title: label,
34
34
  iconBefore:
35
- // eslint-disable-next-line @atlaskit/design-system/consistent-css-prop-usage, @atlaskit/ui-styling-standard/no-imported-style-values -- Ignored via go/DSP-18766
35
+ // eslint-disable-next-line @atlaskit/design-system/consistent-css-prop-usage, @atlaskit/ui-styling-standard/no-imported-style-values, @atlaskit/platform/ensure-feature-flag-prefix -- Ignored via go/DSP-18766
36
36
  jsx("div", {
37
37
  css: fg('platform-visual-refresh-icons') ? MoreIconStyle : triggerWrapperStyles
38
38
  }, jsx(ShowMoreHorizontalIcon, {
@@ -6,8 +6,9 @@ import React, { useCallback } from 'react';
6
6
 
7
7
  // eslint-disable-next-line @atlaskit/ui-styling-standard/use-compiled -- Ignored via go/DSP-18766
8
8
  import { jsx } from '@emotion/react';
9
- import { buttonGroupStyle } from '@atlaskit/editor-common/styles';
9
+ import { buttonGroupStyle, buttonGroupStyleBeforeVisualRefresh } from '@atlaskit/editor-common/styles';
10
10
  import { ToolbarButton } from '@atlaskit/editor-common/ui-menu';
11
+ import { fg } from '@atlaskit/platform-feature-flags';
11
12
  export const SingleToolbarButtons = /*#__PURE__*/React.memo(({
12
13
  items,
13
14
  isReducedSpacing,
@@ -22,7 +23,13 @@ export const SingleToolbarButtons = /*#__PURE__*/React.memo(({
22
23
  return (
23
24
  // eslint-disable-next-line @atlaskit/design-system/consistent-css-prop-usage, @atlaskit/ui-styling-standard/no-imported-style-values -- Ignored via go/DSP-18766
24
25
  jsx("span", {
25
- css: buttonGroupStyle
26
+ css:
27
+ // eslint-disable-next-line @atlaskit/platform/ensure-feature-flag-registration, @atlaskit/platform/ensure-feature-flag-prefix
28
+ fg('platform-visual-refresh-icons') ?
29
+ // eslint-disable-next-line @atlaskit/design-system/consistent-css-prop-usage, @atlaskit/ui-styling-standard/no-imported-style-values
30
+ buttonGroupStyle :
31
+ // eslint-disable-next-line @atlaskit/design-system/consistent-css-prop-usage, @atlaskit/ui-styling-standard/no-imported-style-values
32
+ buttonGroupStyleBeforeVisualRefresh
26
33
  }, items.map(item => {
27
34
  var _item$ariaLabel;
28
35
  return jsx(ToolbarButton, {