@atlaskit/editor-plugin-text-formatting 1.16.9 → 1.16.11
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 +21 -0
- package/dist/cjs/editor-commands/utils/marks.js +120 -0
- package/dist/cjs/pm-plugins/commands.js +18 -12
- package/dist/cjs/pm-plugins/input-rule.js +15 -7
- package/dist/cjs/textFormattingPlugin.js +3 -1
- package/dist/es2019/editor-commands/utils/marks.js +117 -0
- package/dist/es2019/pm-plugins/commands.js +7 -2
- package/dist/es2019/pm-plugins/input-rule.js +15 -7
- package/dist/es2019/textFormattingPlugin.js +3 -1
- package/dist/esm/editor-commands/utils/marks.js +114 -0
- package/dist/esm/pm-plugins/commands.js +18 -12
- package/dist/esm/pm-plugins/input-rule.js +15 -7
- package/dist/esm/textFormattingPlugin.js +3 -1
- package/dist/types/editor-commands/utils/marks.d.ts +14 -0
- package/dist/types/pm-plugins/commands.d.ts +6 -3
- package/dist/types/pm-plugins/input-rule.d.ts +3 -1
- package/dist/types/textFormattingPluginType.d.ts +6 -1
- package/dist/types-ts4.5/editor-commands/utils/marks.d.ts +14 -0
- package/dist/types-ts4.5/pm-plugins/commands.d.ts +6 -3
- package/dist/types-ts4.5/pm-plugins/input-rule.d.ts +3 -1
- package/dist/types-ts4.5/textFormattingPluginType.d.ts +3 -1
- package/package.json +13 -6
- package/dist/cjs/editor-commands/transform-to-code.js +0 -79
- package/dist/es2019/editor-commands/transform-to-code.js +0 -83
- package/dist/esm/editor-commands/transform-to-code.js +0 -73
- package/dist/types/editor-commands/transform-to-code.d.ts +0 -2
- package/dist/types-ts4.5/editor-commands/transform-to-code.d.ts +0 -2
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,26 @@
|
|
|
1
1
|
# @atlaskit/editor-plugin-text-formatting
|
|
2
2
|
|
|
3
|
+
## 1.16.11
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- [#105009](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/pull-requests/105009)
|
|
8
|
+
[`a4039ebf7ed11`](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/commits/a4039ebf7ed11) -
|
|
9
|
+
[ux] Implement variant 2 cohorts experience for platform_editor_contextual_formatting_toolbar_v2
|
|
10
|
+
experiment
|
|
11
|
+
- Updated dependencies
|
|
12
|
+
|
|
13
|
+
## 1.16.10
|
|
14
|
+
|
|
15
|
+
### Patch Changes
|
|
16
|
+
|
|
17
|
+
- [#97984](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/pull-requests/97984)
|
|
18
|
+
[`8ffeab9aaf1ab`](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/commits/8ffeab9aaf1ab) -
|
|
19
|
+
[ux] [ED-23573] Added new actions (resolveMarks and registerMarks) to basePlugin. Callbacks added
|
|
20
|
+
to mentions, card, emoji and base plugins to handle conversion to inline code. Deprecated code
|
|
21
|
+
removed from editor-common.
|
|
22
|
+
- Updated dependencies
|
|
23
|
+
|
|
3
24
|
## 1.16.9
|
|
4
25
|
|
|
5
26
|
### 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
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
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 (
|
|
237
|
-
var 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
|
-
|
|
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,
|
|
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,
|
|
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',
|
|
@@ -135,6 +135,8 @@ var textFormattingPlugin = exports.textFormattingPlugin = function textFormattin
|
|
|
135
135
|
selectionToolbar: function selectionToolbar() {
|
|
136
136
|
if ((0, _experiments.editorExperiment)('contextual_formatting_toolbar', true, {
|
|
137
137
|
exposure: true
|
|
138
|
+
}) || (0, _experiments.editorExperiment)('platform_editor_contextual_formatting_toolbar_v2', 'variant2', {
|
|
139
|
+
exposure: true
|
|
138
140
|
})) {
|
|
139
141
|
var toolbarCustom = {
|
|
140
142
|
type: 'custom',
|
|
@@ -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
|
|
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
|
-
|
|
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,
|
|
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
|
-
|
|
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',
|
|
@@ -129,6 +129,8 @@ export const textFormattingPlugin = ({
|
|
|
129
129
|
selectionToolbar: () => {
|
|
130
130
|
if (editorExperiment('contextual_formatting_toolbar', true, {
|
|
131
131
|
exposure: true
|
|
132
|
+
}) || editorExperiment('platform_editor_contextual_formatting_toolbar_v2', 'variant2', {
|
|
133
|
+
exposure: true
|
|
132
134
|
})) {
|
|
133
135
|
const toolbarCustom = {
|
|
134
136
|
type: 'custom',
|
|
@@ -0,0 +1,114 @@
|
|
|
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 var nextToggleMark = function nextToggleMark(markType, api, attrs) {
|
|
12
|
+
return function (_ref) {
|
|
13
|
+
var tr = _ref.tr;
|
|
14
|
+
var 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: tr
|
|
27
|
+
});
|
|
28
|
+
};
|
|
29
|
+
};
|
|
30
|
+
var nextToggleMarkInRange = function nextToggleMarkInRange(mark, api) {
|
|
31
|
+
return function (_ref2) {
|
|
32
|
+
var tr = _ref2.tr;
|
|
33
|
+
if (tr.selection instanceof CellSelection) {
|
|
34
|
+
var removeMark = true;
|
|
35
|
+
var cells = [];
|
|
36
|
+
tr.selection.forEachCell(function (cell, cellPos) {
|
|
37
|
+
cells.push({
|
|
38
|
+
node: cell,
|
|
39
|
+
pos: cellPos
|
|
40
|
+
});
|
|
41
|
+
var from = cellPos;
|
|
42
|
+
var to = cellPos + cell.nodeSize;
|
|
43
|
+
removeMark && (removeMark = entireSelectionContainsMark(mark, tr.doc, from, to));
|
|
44
|
+
});
|
|
45
|
+
for (var i = cells.length - 1; i >= 0; i--) {
|
|
46
|
+
var cell = cells[i];
|
|
47
|
+
var from = cell.pos;
|
|
48
|
+
var to = from + cell.node.nodeSize;
|
|
49
|
+
nextApplyMarkOnRange(from, to, removeMark, mark, tr, api);
|
|
50
|
+
}
|
|
51
|
+
} else {
|
|
52
|
+
var _tr$selection = tr.selection,
|
|
53
|
+
$from = _tr$selection.$from,
|
|
54
|
+
$to = _tr$selection.$to;
|
|
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
|
+
var _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
|
+
};
|
|
69
|
+
export var nextApplyMarkOnRange = function nextApplyMarkOnRange(from, to, removeMark, mark, tr, api
|
|
70
|
+
// eslint-disable-next-line @typescript-eslint/max-params
|
|
71
|
+
) {
|
|
72
|
+
var schema = tr.doc.type.schema;
|
|
73
|
+
var code = schema.marks.code;
|
|
74
|
+
if (mark.type === code) {
|
|
75
|
+
if (fg('platform_editor_resolve_marks')) {
|
|
76
|
+
var _api$base;
|
|
77
|
+
api === null || api === void 0 || (_api$base = api.base) === null || _api$base === void 0 || _api$base.actions.resolveMarks(from, to, tr);
|
|
78
|
+
} else {
|
|
79
|
+
transformNonTextNodesToText(from, to, tr);
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
/**
|
|
84
|
+
* We should refactor this so text formatting doesn't reference plugins it doesn't know about.
|
|
85
|
+
*/
|
|
86
|
+
tr.doc.nodesBetween(tr.mapping.map(from), tr.mapping.map(to), function (node, pos) {
|
|
87
|
+
if (fg('editor_inline_comments_on_inline_nodes')) {
|
|
88
|
+
if (!node.isText) {
|
|
89
|
+
var isAllowedInlineNode = ['emoji', 'status', 'date', 'mention', 'inlineCard'].includes(node.type.name);
|
|
90
|
+
if (!isAllowedInlineNode) {
|
|
91
|
+
return true;
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
} else {
|
|
95
|
+
if (!node.isText) {
|
|
96
|
+
return true;
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
// This is an issue when the user selects some text.
|
|
101
|
+
// We need to check if the current node position is less than the range selection from.
|
|
102
|
+
// If it’s true, that means we should apply the mark using the range selection,
|
|
103
|
+
// not the current node position.
|
|
104
|
+
var nodeBetweenFrom = Math.max(pos, tr.mapping.map(from));
|
|
105
|
+
var nodeBetweenTo = Math.min(pos + node.nodeSize, tr.mapping.map(to));
|
|
106
|
+
if (removeMark) {
|
|
107
|
+
tr.removeMark(nodeBetweenFrom, nodeBetweenTo, mark);
|
|
108
|
+
} else {
|
|
109
|
+
tr.addMark(nodeBetweenFrom, nodeBetweenTo, mark);
|
|
110
|
+
}
|
|
111
|
+
return true;
|
|
112
|
+
});
|
|
113
|
+
return tr;
|
|
114
|
+
};
|
|
@@ -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 var toggleEm = function toggleEm(_ref) {
|
|
4
5
|
var tr = _ref.tr;
|
|
5
6
|
var em = tr.doc.type.schema.marks.em;
|
|
@@ -215,21 +216,26 @@ export var toggleSubscriptWithAnalytics = function toggleSubscriptWithAnalytics(
|
|
|
215
216
|
};
|
|
216
217
|
};
|
|
217
218
|
export var toggleCode = function toggleCode(_ref13) {
|
|
218
|
-
var
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
219
|
+
var api = _ref13.api;
|
|
220
|
+
return function (_ref14) {
|
|
221
|
+
var tr = _ref14.tr;
|
|
222
|
+
var code = tr.doc.type.schema.marks.code;
|
|
223
|
+
if (!code) {
|
|
224
|
+
// No transaction to apply
|
|
225
|
+
return null;
|
|
226
|
+
}
|
|
227
|
+
return nextToggleMark(code, api)({
|
|
228
|
+
tr: tr
|
|
229
|
+
});
|
|
230
|
+
};
|
|
227
231
|
};
|
|
228
|
-
export var toggleCodeWithAnalytics = function toggleCodeWithAnalytics(editorAnalyticsApi) {
|
|
232
|
+
export var toggleCodeWithAnalytics = function toggleCodeWithAnalytics(editorAnalyticsApi, api) {
|
|
229
233
|
return function (inputMethod) {
|
|
230
|
-
return function (
|
|
231
|
-
var tr =
|
|
234
|
+
return function (_ref15) {
|
|
235
|
+
var tr = _ref15.tr;
|
|
232
236
|
var newTr = toggleCode({
|
|
237
|
+
api: api
|
|
238
|
+
})({
|
|
233
239
|
tr: tr
|
|
234
240
|
});
|
|
235
241
|
if (!newTr) {
|
|
@@ -14,6 +14,7 @@ import { ACTION, ACTION_SUBJECT, ACTION_SUBJECT_ID, EVENT_TYPE, INPUT_METHOD } f
|
|
|
14
14
|
import { transformNonTextNodesToText } from '@atlaskit/editor-common/mark';
|
|
15
15
|
import { SafePlugin } from '@atlaskit/editor-common/safe-plugin';
|
|
16
16
|
import { createRule, inputRuleWithAnalytics } from '@atlaskit/editor-common/utils';
|
|
17
|
+
import { fg } from '@atlaskit/platform-feature-flags';
|
|
17
18
|
import { createPlugin, leafNodeReplacementCharacter } from '@atlaskit/prosemirror-input-rules';
|
|
18
19
|
var ValidAutoformatChars = /*#__PURE__*/function (ValidAutoformatChars) {
|
|
19
20
|
ValidAutoformatChars["STRONG"] = "__";
|
|
@@ -51,10 +52,12 @@ ValidAutoformatChars.STRIKE,
|
|
|
51
52
|
ValidAutoformatChars.STRONG_MARKDOWN]), ValidAutoformatChars.CODE, [
|
|
52
53
|
// e.g: loko (`some code`
|
|
53
54
|
'( ']);
|
|
54
|
-
|
|
55
|
+
|
|
56
|
+
// eslint-disable-next-line @typescript-eslint/max-params
|
|
57
|
+
function addMark(markType, _schema, char, api) {
|
|
55
58
|
// Ignored via go/ees005
|
|
56
59
|
// eslint-disable-next-line @typescript-eslint/max-params
|
|
57
|
-
return function (state,
|
|
60
|
+
return function (state, _match, start, end) {
|
|
58
61
|
var _schema$marks;
|
|
59
62
|
var doc = state.doc,
|
|
60
63
|
schema = state.schema,
|
|
@@ -88,7 +91,12 @@ function addMark(markType, schema, char) {
|
|
|
88
91
|
return null;
|
|
89
92
|
}
|
|
90
93
|
if (markType.name === 'code') {
|
|
91
|
-
|
|
94
|
+
if (fg('platform_editor_resolve_marks')) {
|
|
95
|
+
var _api$base;
|
|
96
|
+
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);
|
|
97
|
+
} else {
|
|
98
|
+
transformNonTextNodesToText(tr.mapping.map(start), tr.mapping.map(end), tr);
|
|
99
|
+
}
|
|
92
100
|
}
|
|
93
101
|
var mappedStart = tr.mapping.map(start);
|
|
94
102
|
var mappedEnd = tr.mapping.map(end);
|
|
@@ -233,7 +241,7 @@ function getStrikeInputRules(schema, editorAnalyticsAPI) {
|
|
|
233
241
|
* @param {Schema} schema
|
|
234
242
|
* @returns {InputRuleWrapper[]}
|
|
235
243
|
*/
|
|
236
|
-
function getCodeInputRules(schema, editorAnalyticsAPI) {
|
|
244
|
+
function getCodeInputRules(schema, editorAnalyticsAPI, api) {
|
|
237
245
|
var ruleWithCodeAnalytics = inputRuleWithAnalytics({
|
|
238
246
|
action: ACTION.FORMATTED,
|
|
239
247
|
actionSubject: ACTION_SUBJECT.TEXT,
|
|
@@ -243,10 +251,10 @@ function getCodeInputRules(schema, editorAnalyticsAPI) {
|
|
|
243
251
|
inputMethod: INPUT_METHOD.FORMATTING
|
|
244
252
|
}
|
|
245
253
|
}, editorAnalyticsAPI);
|
|
246
|
-
var backTickRule = createRule(codeRegex, addMark(schema.marks.code, schema, ValidAutoformatChars.CODE));
|
|
254
|
+
var backTickRule = createRule(codeRegex, addMark(schema.marks.code, schema, ValidAutoformatChars.CODE, api));
|
|
247
255
|
return [ruleWithCodeAnalytics(backTickRule)];
|
|
248
256
|
}
|
|
249
|
-
export function inputRulePlugin(schema, editorAnalyticsAPI) {
|
|
257
|
+
export function inputRulePlugin(schema, editorAnalyticsAPI, api) {
|
|
250
258
|
var rules = [];
|
|
251
259
|
if (schema.marks.strong) {
|
|
252
260
|
rules.push.apply(rules, _toConsumableArray(getStrongInputRules(schema, editorAnalyticsAPI)));
|
|
@@ -258,7 +266,7 @@ export function inputRulePlugin(schema, editorAnalyticsAPI) {
|
|
|
258
266
|
rules.push.apply(rules, _toConsumableArray(getStrikeInputRules(schema, editorAnalyticsAPI)));
|
|
259
267
|
}
|
|
260
268
|
if (schema.marks.code) {
|
|
261
|
-
rules.push.apply(rules, _toConsumableArray(getCodeInputRules(schema, editorAnalyticsAPI)));
|
|
269
|
+
rules.push.apply(rules, _toConsumableArray(getCodeInputRules(schema, editorAnalyticsAPI, api)));
|
|
262
270
|
}
|
|
263
271
|
if (rules.length !== 0) {
|
|
264
272
|
return new SafePlugin(createPlugin('text-formatting', rules));
|
|
@@ -87,7 +87,7 @@ export var textFormattingPlugin = function textFormattingPlugin(_ref) {
|
|
|
87
87
|
plugin: function plugin(_ref4) {
|
|
88
88
|
var _api$analytics2;
|
|
89
89
|
var schema = _ref4.schema;
|
|
90
|
-
return textFormattingInputRulePlugin(schema, api === null || api === void 0 || (_api$analytics2 = api.analytics) === null || _api$analytics2 === void 0 ? void 0 : _api$analytics2.actions);
|
|
90
|
+
return textFormattingInputRulePlugin(schema, api === null || api === void 0 || (_api$analytics2 = api.analytics) === null || _api$analytics2 === void 0 ? void 0 : _api$analytics2.actions, api);
|
|
91
91
|
}
|
|
92
92
|
}, {
|
|
93
93
|
name: 'textFormattingSmartRule',
|
|
@@ -129,6 +129,8 @@ export var textFormattingPlugin = function textFormattingPlugin(_ref) {
|
|
|
129
129
|
selectionToolbar: function selectionToolbar() {
|
|
130
130
|
if (editorExperiment('contextual_formatting_toolbar', true, {
|
|
131
131
|
exposure: true
|
|
132
|
+
}) || editorExperiment('platform_editor_contextual_formatting_toolbar_v2', 'variant2', {
|
|
133
|
+
exposure: true
|
|
132
134
|
})) {
|
|
133
135
|
var toolbarCustom = {
|
|
134
136
|
type: 'custom',
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { EditorCommand, ExtractInjectionAPI } from '@atlaskit/editor-common/types';
|
|
2
|
+
import type { Mark, MarkType } from '@atlaskit/editor-prosemirror/model';
|
|
3
|
+
import type { Transaction } from '@atlaskit/editor-prosemirror/state';
|
|
4
|
+
import type { TextFormattingPlugin } from '../../textFormattingPluginType';
|
|
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 declare const nextToggleMark: (markType: MarkType, api: ExtractInjectionAPI<TextFormattingPlugin> | undefined, attrs?: {
|
|
12
|
+
[key: string]: any;
|
|
13
|
+
} | undefined) => EditorCommand;
|
|
14
|
+
export declare const nextApplyMarkOnRange: (from: number, to: number, removeMark: boolean, mark: Mark, tr: Transaction, api: ExtractInjectionAPI<TextFormattingPlugin> | undefined) => Transaction;
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import type { EditorAnalyticsAPI } from '@atlaskit/editor-common/analytics';
|
|
2
|
-
import type { EditorCommand, InputMethodBasic } from '@atlaskit/editor-common/types';
|
|
3
|
-
type
|
|
2
|
+
import type { EditorCommand, ExtractInjectionAPI, InputMethodBasic } from '@atlaskit/editor-common/types';
|
|
3
|
+
import type { TextFormattingPlugin } from '../textFormattingPluginType';
|
|
4
|
+
type ToggleMarkWithAnalyticsEditorCommand = (editorAnalyticsApi: EditorAnalyticsAPI | undefined, api?: ExtractInjectionAPI<TextFormattingPlugin>) => ToggleMarkEditorCommand;
|
|
4
5
|
export type ToggleMarkEditorCommand = (inputMethod: InputMethodBasic) => EditorCommand;
|
|
5
6
|
export declare const toggleEm: EditorCommand;
|
|
6
7
|
export declare const toggleEmWithAnalytics: ToggleMarkWithAnalyticsEditorCommand;
|
|
@@ -14,6 +15,8 @@ export declare const toggleSuperscript: EditorCommand;
|
|
|
14
15
|
export declare const toggleSuperscriptWithAnalytics: ToggleMarkWithAnalyticsEditorCommand;
|
|
15
16
|
export declare const toggleSubscript: EditorCommand;
|
|
16
17
|
export declare const toggleSubscriptWithAnalytics: ToggleMarkWithAnalyticsEditorCommand;
|
|
17
|
-
export declare const toggleCode:
|
|
18
|
+
export declare const toggleCode: ({ api }: {
|
|
19
|
+
api: ExtractInjectionAPI<TextFormattingPlugin> | undefined;
|
|
20
|
+
}) => EditorCommand;
|
|
18
21
|
export declare const toggleCodeWithAnalytics: ToggleMarkWithAnalyticsEditorCommand;
|
|
19
22
|
export {};
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import type { EditorAnalyticsAPI } from '@atlaskit/editor-common/analytics';
|
|
2
2
|
import { SafePlugin } from '@atlaskit/editor-common/safe-plugin';
|
|
3
|
+
import type { ExtractInjectionAPI } from '@atlaskit/editor-common/types';
|
|
3
4
|
import type { Schema } from '@atlaskit/editor-prosemirror/model';
|
|
5
|
+
import type { TextFormattingPlugin } from '../textFormattingPluginType';
|
|
4
6
|
declare enum ValidAutoformatChars {
|
|
5
7
|
STRONG = "__",
|
|
6
8
|
STRIKE = "~~",
|
|
@@ -19,5 +21,5 @@ export declare const italicRegex1: ReverseRegexExp;
|
|
|
19
21
|
export declare const italicRegex2: ReverseRegexExp;
|
|
20
22
|
export declare const strikeRegex: ReverseRegexExp;
|
|
21
23
|
export declare const codeRegex: ReverseRegexExp;
|
|
22
|
-
export declare function inputRulePlugin(schema: Schema, editorAnalyticsAPI: EditorAnalyticsAPI | undefined): SafePlugin | undefined;
|
|
24
|
+
export declare function inputRulePlugin(schema: Schema, editorAnalyticsAPI: EditorAnalyticsAPI | undefined, api: ExtractInjectionAPI<TextFormattingPlugin> | undefined): SafePlugin | undefined;
|
|
23
25
|
export default inputRulePlugin;
|
|
@@ -1,10 +1,15 @@
|
|
|
1
1
|
import type { NextEditorPlugin, OptionalPlugin, TextFormattingOptions, TextFormattingState } from '@atlaskit/editor-common/types';
|
|
2
2
|
import type { AnalyticsPlugin } from '@atlaskit/editor-plugin-analytics';
|
|
3
|
+
import type { BasePlugin } from '@atlaskit/editor-plugin-base';
|
|
3
4
|
import type { PrimaryToolbarPlugin } from '@atlaskit/editor-plugin-primary-toolbar';
|
|
4
5
|
import type { ToggleMarkEditorCommand } from './pm-plugins/commands';
|
|
5
6
|
export type TextFormattingPlugin = NextEditorPlugin<'textFormatting', {
|
|
6
7
|
pluginConfiguration: TextFormattingOptions | undefined;
|
|
7
|
-
dependencies: [
|
|
8
|
+
dependencies: [
|
|
9
|
+
OptionalPlugin<AnalyticsPlugin>,
|
|
10
|
+
OptionalPlugin<PrimaryToolbarPlugin>,
|
|
11
|
+
OptionalPlugin<BasePlugin>
|
|
12
|
+
];
|
|
8
13
|
commands: {
|
|
9
14
|
toggleSuperscript: ToggleMarkEditorCommand;
|
|
10
15
|
toggleSubscript: ToggleMarkEditorCommand;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { EditorCommand, ExtractInjectionAPI } from '@atlaskit/editor-common/types';
|
|
2
|
+
import type { Mark, MarkType } from '@atlaskit/editor-prosemirror/model';
|
|
3
|
+
import type { Transaction } from '@atlaskit/editor-prosemirror/state';
|
|
4
|
+
import type { TextFormattingPlugin } from '../../textFormattingPluginType';
|
|
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 declare const nextToggleMark: (markType: MarkType, api: ExtractInjectionAPI<TextFormattingPlugin> | undefined, attrs?: {
|
|
12
|
+
[key: string]: any;
|
|
13
|
+
} | undefined) => EditorCommand;
|
|
14
|
+
export declare const nextApplyMarkOnRange: (from: number, to: number, removeMark: boolean, mark: Mark, tr: Transaction, api: ExtractInjectionAPI<TextFormattingPlugin> | undefined) => Transaction;
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import type { EditorAnalyticsAPI } from '@atlaskit/editor-common/analytics';
|
|
2
|
-
import type { EditorCommand, InputMethodBasic } from '@atlaskit/editor-common/types';
|
|
3
|
-
type
|
|
2
|
+
import type { EditorCommand, ExtractInjectionAPI, InputMethodBasic } from '@atlaskit/editor-common/types';
|
|
3
|
+
import type { TextFormattingPlugin } from '../textFormattingPluginType';
|
|
4
|
+
type ToggleMarkWithAnalyticsEditorCommand = (editorAnalyticsApi: EditorAnalyticsAPI | undefined, api?: ExtractInjectionAPI<TextFormattingPlugin>) => ToggleMarkEditorCommand;
|
|
4
5
|
export type ToggleMarkEditorCommand = (inputMethod: InputMethodBasic) => EditorCommand;
|
|
5
6
|
export declare const toggleEm: EditorCommand;
|
|
6
7
|
export declare const toggleEmWithAnalytics: ToggleMarkWithAnalyticsEditorCommand;
|
|
@@ -14,6 +15,8 @@ export declare const toggleSuperscript: EditorCommand;
|
|
|
14
15
|
export declare const toggleSuperscriptWithAnalytics: ToggleMarkWithAnalyticsEditorCommand;
|
|
15
16
|
export declare const toggleSubscript: EditorCommand;
|
|
16
17
|
export declare const toggleSubscriptWithAnalytics: ToggleMarkWithAnalyticsEditorCommand;
|
|
17
|
-
export declare const toggleCode:
|
|
18
|
+
export declare const toggleCode: ({ api }: {
|
|
19
|
+
api: ExtractInjectionAPI<TextFormattingPlugin> | undefined;
|
|
20
|
+
}) => EditorCommand;
|
|
18
21
|
export declare const toggleCodeWithAnalytics: ToggleMarkWithAnalyticsEditorCommand;
|
|
19
22
|
export {};
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import type { EditorAnalyticsAPI } from '@atlaskit/editor-common/analytics';
|
|
2
2
|
import { SafePlugin } from '@atlaskit/editor-common/safe-plugin';
|
|
3
|
+
import type { ExtractInjectionAPI } from '@atlaskit/editor-common/types';
|
|
3
4
|
import type { Schema } from '@atlaskit/editor-prosemirror/model';
|
|
5
|
+
import type { TextFormattingPlugin } from '../textFormattingPluginType';
|
|
4
6
|
declare enum ValidAutoformatChars {
|
|
5
7
|
STRONG = "__",
|
|
6
8
|
STRIKE = "~~",
|
|
@@ -19,5 +21,5 @@ export declare const italicRegex1: ReverseRegexExp;
|
|
|
19
21
|
export declare const italicRegex2: ReverseRegexExp;
|
|
20
22
|
export declare const strikeRegex: ReverseRegexExp;
|
|
21
23
|
export declare const codeRegex: ReverseRegexExp;
|
|
22
|
-
export declare function inputRulePlugin(schema: Schema, editorAnalyticsAPI: EditorAnalyticsAPI | undefined): SafePlugin | undefined;
|
|
24
|
+
export declare function inputRulePlugin(schema: Schema, editorAnalyticsAPI: EditorAnalyticsAPI | undefined, api: ExtractInjectionAPI<TextFormattingPlugin> | undefined): SafePlugin | undefined;
|
|
23
25
|
export default inputRulePlugin;
|
|
@@ -1,12 +1,14 @@
|
|
|
1
1
|
import type { NextEditorPlugin, OptionalPlugin, TextFormattingOptions, TextFormattingState } from '@atlaskit/editor-common/types';
|
|
2
2
|
import type { AnalyticsPlugin } from '@atlaskit/editor-plugin-analytics';
|
|
3
|
+
import type { BasePlugin } from '@atlaskit/editor-plugin-base';
|
|
3
4
|
import type { PrimaryToolbarPlugin } from '@atlaskit/editor-plugin-primary-toolbar';
|
|
4
5
|
import type { ToggleMarkEditorCommand } from './pm-plugins/commands';
|
|
5
6
|
export type TextFormattingPlugin = NextEditorPlugin<'textFormatting', {
|
|
6
7
|
pluginConfiguration: TextFormattingOptions | undefined;
|
|
7
8
|
dependencies: [
|
|
8
9
|
OptionalPlugin<AnalyticsPlugin>,
|
|
9
|
-
OptionalPlugin<PrimaryToolbarPlugin
|
|
10
|
+
OptionalPlugin<PrimaryToolbarPlugin>,
|
|
11
|
+
OptionalPlugin<BasePlugin>
|
|
10
12
|
];
|
|
11
13
|
commands: {
|
|
12
14
|
toggleSuperscript: ToggleMarkEditorCommand;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@atlaskit/editor-plugin-text-formatting",
|
|
3
|
-
"version": "1.16.
|
|
3
|
+
"version": "1.16.11",
|
|
4
4
|
"description": "Text-formatting plugin for @atlaskit/editor-core",
|
|
5
5
|
"author": "Atlassian Pty Ltd",
|
|
6
6
|
"license": "Apache-2.0",
|
|
@@ -32,17 +32,18 @@
|
|
|
32
32
|
},
|
|
33
33
|
"dependencies": {
|
|
34
34
|
"@atlaskit/adf-schema": "^46.1.0",
|
|
35
|
-
"@atlaskit/editor-common": "^
|
|
36
|
-
"@atlaskit/editor-plugin-analytics": "^1.
|
|
35
|
+
"@atlaskit/editor-common": "^99.5.0",
|
|
36
|
+
"@atlaskit/editor-plugin-analytics": "^1.11.0",
|
|
37
|
+
"@atlaskit/editor-plugin-base": "^2.1.0",
|
|
37
38
|
"@atlaskit/editor-plugin-primary-toolbar": "^2.1.0",
|
|
38
39
|
"@atlaskit/editor-prosemirror": "6.2.1",
|
|
39
40
|
"@atlaskit/editor-shared-styles": "^3.2.0",
|
|
40
41
|
"@atlaskit/editor-tables": "^2.8.0",
|
|
41
|
-
"@atlaskit/icon": "^23.
|
|
42
|
+
"@atlaskit/icon": "^23.4.0",
|
|
42
43
|
"@atlaskit/platform-feature-flags": "^0.3.0",
|
|
43
44
|
"@atlaskit/prosemirror-input-rules": "^3.2.0",
|
|
44
|
-
"@atlaskit/tmp-editor-statsig": "^2.
|
|
45
|
-
"@atlaskit/tokens": "^2.
|
|
45
|
+
"@atlaskit/tmp-editor-statsig": "^2.39.0",
|
|
46
|
+
"@atlaskit/tokens": "^3.2.0",
|
|
46
47
|
"@babel/runtime": "^7.0.0",
|
|
47
48
|
"@emotion/react": "^11.7.1",
|
|
48
49
|
"react-intl-next": "npm:react-intl@^5.18.1"
|
|
@@ -99,6 +100,12 @@
|
|
|
99
100
|
},
|
|
100
101
|
"platform-visual-refresh-icons": {
|
|
101
102
|
"type": "boolean"
|
|
103
|
+
},
|
|
104
|
+
"platform_editor_resolve_marks": {
|
|
105
|
+
"type": "boolean"
|
|
106
|
+
},
|
|
107
|
+
"editor_inline_comments_on_inline_nodes": {
|
|
108
|
+
"type": "boolean"
|
|
102
109
|
}
|
|
103
110
|
}
|
|
104
111
|
}
|
|
@@ -1,79 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.transformSmartCharsMentionsAndEmojis = void 0;
|
|
7
|
-
var _mark = require("@atlaskit/editor-common/mark");
|
|
8
|
-
var SMART_TO_ASCII = {
|
|
9
|
-
'…': '...',
|
|
10
|
-
'→': '->',
|
|
11
|
-
'←': '<-',
|
|
12
|
-
'–': '--',
|
|
13
|
-
'“': '"',
|
|
14
|
-
'”': '"',
|
|
15
|
-
'‘': "'",
|
|
16
|
-
'’': "'"
|
|
17
|
-
};
|
|
18
|
-
|
|
19
|
-
// Ignored via go/ees005
|
|
20
|
-
// eslint-disable-next-line require-unicode-regexp
|
|
21
|
-
var FIND_SMART_CHAR = new RegExp("[".concat(Object.keys(SMART_TO_ASCII).join(''), "]"), 'g');
|
|
22
|
-
var replaceMentionOrEmojiForTextContent = function replaceMentionOrEmojiForTextContent(position, nodeSize, textContent, tr
|
|
23
|
-
// Ignored via go/ees005
|
|
24
|
-
// eslint-disable-next-line @typescript-eslint/max-params
|
|
25
|
-
) {
|
|
26
|
-
var currentPos = tr.mapping.map(position);
|
|
27
|
-
var schema = tr.doc.type.schema;
|
|
28
|
-
tr.replaceWith(currentPos, currentPos + nodeSize, schema.text(textContent));
|
|
29
|
-
};
|
|
30
|
-
var replaceSmartCharsToAscii = function replaceSmartCharsToAscii(position, textContent, tr) {
|
|
31
|
-
var schema = tr.doc.type.schema;
|
|
32
|
-
var match;
|
|
33
|
-
|
|
34
|
-
// Ignored via go/ees005
|
|
35
|
-
// eslint-disable-next-line no-cond-assign
|
|
36
|
-
while (match = FIND_SMART_CHAR.exec(textContent)) {
|
|
37
|
-
var _match = match,
|
|
38
|
-
smartChar = _match[0],
|
|
39
|
-
offset = _match.index;
|
|
40
|
-
var replacePos = tr.mapping.map(position + offset);
|
|
41
|
-
var replacementText = schema.text(SMART_TO_ASCII[smartChar]);
|
|
42
|
-
tr.replaceWith(replacePos, replacePos + smartChar.length, replacementText);
|
|
43
|
-
}
|
|
44
|
-
};
|
|
45
|
-
var isNodeTextBlock = function isNodeTextBlock(schema) {
|
|
46
|
-
var _schema$nodes = schema.nodes,
|
|
47
|
-
mention = _schema$nodes.mention,
|
|
48
|
-
text = _schema$nodes.text,
|
|
49
|
-
emoji = _schema$nodes.emoji;
|
|
50
|
-
|
|
51
|
-
// Ignored via go/ees005
|
|
52
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
53
|
-
return function (node, _, parent) {
|
|
54
|
-
if (node.type === mention || node.type === emoji || node.type === text) {
|
|
55
|
-
return parent === null || parent === void 0 ? void 0 : parent.isTextblock;
|
|
56
|
-
}
|
|
57
|
-
return;
|
|
58
|
-
};
|
|
59
|
-
};
|
|
60
|
-
var transformSmartCharsMentionsAndEmojis = exports.transformSmartCharsMentionsAndEmojis = function transformSmartCharsMentionsAndEmojis(from, to, tr) {
|
|
61
|
-
var schema = tr.doc.type.schema;
|
|
62
|
-
var _schema$nodes2 = schema.nodes,
|
|
63
|
-
mention = _schema$nodes2.mention,
|
|
64
|
-
text = _schema$nodes2.text,
|
|
65
|
-
emoji = _schema$nodes2.emoji;
|
|
66
|
-
// Traverse through all the nodes within the range and replace them with their plaintext counterpart
|
|
67
|
-
var children = (0, _mark.filterChildrenBetween)(tr.doc, from, to, isNodeTextBlock(schema));
|
|
68
|
-
children.forEach(function (_ref) {
|
|
69
|
-
var node = _ref.node,
|
|
70
|
-
pos = _ref.pos;
|
|
71
|
-
if (node.type === mention || node.type === emoji) {
|
|
72
|
-
replaceMentionOrEmojiForTextContent(pos, node.nodeSize, node.attrs.text, tr);
|
|
73
|
-
} else if (node.type === text && node.text) {
|
|
74
|
-
var replacePosition = pos > from ? pos : from;
|
|
75
|
-
var textToReplace = pos > from ? node.text : node.text.substr(from - pos);
|
|
76
|
-
replaceSmartCharsToAscii(replacePosition, textToReplace, tr);
|
|
77
|
-
}
|
|
78
|
-
});
|
|
79
|
-
};
|
|
@@ -1,83 +0,0 @@
|
|
|
1
|
-
import { filterChildrenBetween } from '@atlaskit/editor-common/mark';
|
|
2
|
-
const SMART_TO_ASCII = {
|
|
3
|
-
'…': '...',
|
|
4
|
-
'→': '->',
|
|
5
|
-
'←': '<-',
|
|
6
|
-
'–': '--',
|
|
7
|
-
'“': '"',
|
|
8
|
-
'”': '"',
|
|
9
|
-
'‘': "'",
|
|
10
|
-
'’': "'"
|
|
11
|
-
};
|
|
12
|
-
|
|
13
|
-
// Ignored via go/ees005
|
|
14
|
-
// eslint-disable-next-line require-unicode-regexp
|
|
15
|
-
const FIND_SMART_CHAR = new RegExp(`[${Object.keys(SMART_TO_ASCII).join('')}]`, 'g');
|
|
16
|
-
const replaceMentionOrEmojiForTextContent = (position, nodeSize, textContent, tr
|
|
17
|
-
// Ignored via go/ees005
|
|
18
|
-
// eslint-disable-next-line @typescript-eslint/max-params
|
|
19
|
-
) => {
|
|
20
|
-
const currentPos = tr.mapping.map(position);
|
|
21
|
-
const {
|
|
22
|
-
schema
|
|
23
|
-
} = tr.doc.type;
|
|
24
|
-
tr.replaceWith(currentPos, currentPos + nodeSize, schema.text(textContent));
|
|
25
|
-
};
|
|
26
|
-
const replaceSmartCharsToAscii = (position, textContent, tr) => {
|
|
27
|
-
const {
|
|
28
|
-
schema
|
|
29
|
-
} = tr.doc.type;
|
|
30
|
-
let match;
|
|
31
|
-
|
|
32
|
-
// Ignored via go/ees005
|
|
33
|
-
// eslint-disable-next-line no-cond-assign
|
|
34
|
-
while (match = FIND_SMART_CHAR.exec(textContent)) {
|
|
35
|
-
const {
|
|
36
|
-
0: smartChar,
|
|
37
|
-
index: offset
|
|
38
|
-
} = match;
|
|
39
|
-
const replacePos = tr.mapping.map(position + offset);
|
|
40
|
-
const replacementText = schema.text(SMART_TO_ASCII[smartChar]);
|
|
41
|
-
tr.replaceWith(replacePos, replacePos + smartChar.length, replacementText);
|
|
42
|
-
}
|
|
43
|
-
};
|
|
44
|
-
const isNodeTextBlock = schema => {
|
|
45
|
-
const {
|
|
46
|
-
mention,
|
|
47
|
-
text,
|
|
48
|
-
emoji
|
|
49
|
-
} = schema.nodes;
|
|
50
|
-
|
|
51
|
-
// Ignored via go/ees005
|
|
52
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
53
|
-
return (node, _, parent) => {
|
|
54
|
-
if (node.type === mention || node.type === emoji || node.type === text) {
|
|
55
|
-
return parent === null || parent === void 0 ? void 0 : parent.isTextblock;
|
|
56
|
-
}
|
|
57
|
-
return;
|
|
58
|
-
};
|
|
59
|
-
};
|
|
60
|
-
export const transformSmartCharsMentionsAndEmojis = (from, to, tr) => {
|
|
61
|
-
const {
|
|
62
|
-
schema
|
|
63
|
-
} = tr.doc.type;
|
|
64
|
-
const {
|
|
65
|
-
mention,
|
|
66
|
-
text,
|
|
67
|
-
emoji
|
|
68
|
-
} = schema.nodes;
|
|
69
|
-
// Traverse through all the nodes within the range and replace them with their plaintext counterpart
|
|
70
|
-
const children = filterChildrenBetween(tr.doc, from, to, isNodeTextBlock(schema));
|
|
71
|
-
children.forEach(({
|
|
72
|
-
node,
|
|
73
|
-
pos
|
|
74
|
-
}) => {
|
|
75
|
-
if (node.type === mention || node.type === emoji) {
|
|
76
|
-
replaceMentionOrEmojiForTextContent(pos, node.nodeSize, node.attrs.text, tr);
|
|
77
|
-
} else if (node.type === text && node.text) {
|
|
78
|
-
const replacePosition = pos > from ? pos : from;
|
|
79
|
-
const textToReplace = pos > from ? node.text : node.text.substr(from - pos);
|
|
80
|
-
replaceSmartCharsToAscii(replacePosition, textToReplace, tr);
|
|
81
|
-
}
|
|
82
|
-
});
|
|
83
|
-
};
|
|
@@ -1,73 +0,0 @@
|
|
|
1
|
-
import { filterChildrenBetween } from '@atlaskit/editor-common/mark';
|
|
2
|
-
var SMART_TO_ASCII = {
|
|
3
|
-
'…': '...',
|
|
4
|
-
'→': '->',
|
|
5
|
-
'←': '<-',
|
|
6
|
-
'–': '--',
|
|
7
|
-
'“': '"',
|
|
8
|
-
'”': '"',
|
|
9
|
-
'‘': "'",
|
|
10
|
-
'’': "'"
|
|
11
|
-
};
|
|
12
|
-
|
|
13
|
-
// Ignored via go/ees005
|
|
14
|
-
// eslint-disable-next-line require-unicode-regexp
|
|
15
|
-
var FIND_SMART_CHAR = new RegExp("[".concat(Object.keys(SMART_TO_ASCII).join(''), "]"), 'g');
|
|
16
|
-
var replaceMentionOrEmojiForTextContent = function replaceMentionOrEmojiForTextContent(position, nodeSize, textContent, tr
|
|
17
|
-
// Ignored via go/ees005
|
|
18
|
-
// eslint-disable-next-line @typescript-eslint/max-params
|
|
19
|
-
) {
|
|
20
|
-
var currentPos = tr.mapping.map(position);
|
|
21
|
-
var schema = tr.doc.type.schema;
|
|
22
|
-
tr.replaceWith(currentPos, currentPos + nodeSize, schema.text(textContent));
|
|
23
|
-
};
|
|
24
|
-
var replaceSmartCharsToAscii = function replaceSmartCharsToAscii(position, textContent, tr) {
|
|
25
|
-
var schema = tr.doc.type.schema;
|
|
26
|
-
var match;
|
|
27
|
-
|
|
28
|
-
// Ignored via go/ees005
|
|
29
|
-
// eslint-disable-next-line no-cond-assign
|
|
30
|
-
while (match = FIND_SMART_CHAR.exec(textContent)) {
|
|
31
|
-
var _match = match,
|
|
32
|
-
smartChar = _match[0],
|
|
33
|
-
offset = _match.index;
|
|
34
|
-
var replacePos = tr.mapping.map(position + offset);
|
|
35
|
-
var replacementText = schema.text(SMART_TO_ASCII[smartChar]);
|
|
36
|
-
tr.replaceWith(replacePos, replacePos + smartChar.length, replacementText);
|
|
37
|
-
}
|
|
38
|
-
};
|
|
39
|
-
var isNodeTextBlock = function isNodeTextBlock(schema) {
|
|
40
|
-
var _schema$nodes = schema.nodes,
|
|
41
|
-
mention = _schema$nodes.mention,
|
|
42
|
-
text = _schema$nodes.text,
|
|
43
|
-
emoji = _schema$nodes.emoji;
|
|
44
|
-
|
|
45
|
-
// Ignored via go/ees005
|
|
46
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
47
|
-
return function (node, _, parent) {
|
|
48
|
-
if (node.type === mention || node.type === emoji || node.type === text) {
|
|
49
|
-
return parent === null || parent === void 0 ? void 0 : parent.isTextblock;
|
|
50
|
-
}
|
|
51
|
-
return;
|
|
52
|
-
};
|
|
53
|
-
};
|
|
54
|
-
export var transformSmartCharsMentionsAndEmojis = function transformSmartCharsMentionsAndEmojis(from, to, tr) {
|
|
55
|
-
var schema = tr.doc.type.schema;
|
|
56
|
-
var _schema$nodes2 = schema.nodes,
|
|
57
|
-
mention = _schema$nodes2.mention,
|
|
58
|
-
text = _schema$nodes2.text,
|
|
59
|
-
emoji = _schema$nodes2.emoji;
|
|
60
|
-
// Traverse through all the nodes within the range and replace them with their plaintext counterpart
|
|
61
|
-
var children = filterChildrenBetween(tr.doc, from, to, isNodeTextBlock(schema));
|
|
62
|
-
children.forEach(function (_ref) {
|
|
63
|
-
var node = _ref.node,
|
|
64
|
-
pos = _ref.pos;
|
|
65
|
-
if (node.type === mention || node.type === emoji) {
|
|
66
|
-
replaceMentionOrEmojiForTextContent(pos, node.nodeSize, node.attrs.text, tr);
|
|
67
|
-
} else if (node.type === text && node.text) {
|
|
68
|
-
var replacePosition = pos > from ? pos : from;
|
|
69
|
-
var textToReplace = pos > from ? node.text : node.text.substr(from - pos);
|
|
70
|
-
replaceSmartCharsToAscii(replacePosition, textToReplace, tr);
|
|
71
|
-
}
|
|
72
|
-
});
|
|
73
|
-
};
|