@atlaskit/editor-plugin-text-formatting 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.eslintrc.js +7 -0
- package/CHANGELOG.md +1 -0
- package/LICENSE.md +13 -0
- package/README.md +9 -0
- package/dist/cjs/actions.js +188 -0
- package/dist/cjs/commands/clear-formatting.js +111 -0
- package/dist/cjs/commands/text-formatting.js +143 -0
- package/dist/cjs/commands/transform-to-code.js +68 -0
- package/dist/cjs/index.js +12 -0
- package/dist/cjs/plugin.js +133 -0
- package/dist/cjs/pm-plugins/clear-formatting-keymap.js +21 -0
- package/dist/cjs/pm-plugins/clear-formatting.js +36 -0
- package/dist/cjs/pm-plugins/cursor.js +55 -0
- package/dist/cjs/pm-plugins/input-rule.js +274 -0
- package/dist/cjs/pm-plugins/keymap.js +52 -0
- package/dist/cjs/pm-plugins/main.js +113 -0
- package/dist/cjs/pm-plugins/plugin-key.js +9 -0
- package/dist/cjs/pm-plugins/smart-input-rule.js +176 -0
- package/dist/cjs/ui/Toolbar/constants.js +19 -0
- package/dist/cjs/ui/Toolbar/dropdown-menu.js +86 -0
- package/dist/cjs/ui/Toolbar/hooks/clear-formatting-icon.js +55 -0
- package/dist/cjs/ui/Toolbar/hooks/formatting-icons.js +227 -0
- package/dist/cjs/ui/Toolbar/hooks/menu-state.js +23 -0
- package/dist/cjs/ui/Toolbar/hooks/responsive-toolbar-buttons.js +60 -0
- package/dist/cjs/ui/Toolbar/index.js +183 -0
- package/dist/cjs/ui/Toolbar/more-button.js +42 -0
- package/dist/cjs/ui/Toolbar/single-toolbar-buttons.js +49 -0
- package/dist/cjs/ui/Toolbar/types.js +17 -0
- package/dist/cjs/utils/cell-selection.js +12 -0
- package/dist/cjs/utils.js +86 -0
- package/dist/cjs/version.json +5 -0
- package/dist/es2019/actions.js +161 -0
- package/dist/es2019/commands/clear-formatting.js +105 -0
- package/dist/es2019/commands/text-formatting.js +144 -0
- package/dist/es2019/commands/transform-to-code.js +71 -0
- package/dist/es2019/index.js +1 -0
- package/dist/es2019/plugin.js +124 -0
- package/dist/es2019/pm-plugins/clear-formatting-keymap.js +10 -0
- package/dist/es2019/pm-plugins/clear-formatting.js +26 -0
- package/dist/es2019/pm-plugins/cursor.js +52 -0
- package/dist/es2019/pm-plugins/input-rule.js +242 -0
- package/dist/es2019/pm-plugins/keymap.js +43 -0
- package/dist/es2019/pm-plugins/main.js +110 -0
- package/dist/es2019/pm-plugins/plugin-key.js +2 -0
- package/dist/es2019/pm-plugins/smart-input-rule.js +155 -0
- package/dist/es2019/ui/Toolbar/constants.js +20 -0
- package/dist/es2019/ui/Toolbar/dropdown-menu.js +66 -0
- package/dist/es2019/ui/Toolbar/hooks/clear-formatting-icon.js +44 -0
- package/dist/es2019/ui/Toolbar/hooks/formatting-icons.js +212 -0
- package/dist/es2019/ui/Toolbar/hooks/menu-state.js +11 -0
- package/dist/es2019/ui/Toolbar/hooks/responsive-toolbar-buttons.js +48 -0
- package/dist/es2019/ui/Toolbar/index.js +168 -0
- package/dist/es2019/ui/Toolbar/more-button.js +34 -0
- package/dist/es2019/ui/Toolbar/single-toolbar-buttons.js +39 -0
- package/dist/es2019/ui/Toolbar/types.js +10 -0
- package/dist/es2019/utils/cell-selection.js +5 -0
- package/dist/es2019/utils.js +74 -0
- package/dist/es2019/version.json +5 -0
- package/dist/esm/actions.js +168 -0
- package/dist/esm/commands/clear-formatting.js +101 -0
- package/dist/esm/commands/text-formatting.js +134 -0
- package/dist/esm/commands/transform-to-code.js +61 -0
- package/dist/esm/index.js +1 -0
- package/dist/esm/plugin.js +125 -0
- package/dist/esm/pm-plugins/clear-formatting-keymap.js +10 -0
- package/dist/esm/pm-plugins/clear-formatting.js +28 -0
- package/dist/esm/pm-plugins/cursor.js +48 -0
- package/dist/esm/pm-plugins/input-rule.js +257 -0
- package/dist/esm/pm-plugins/keymap.js +43 -0
- package/dist/esm/pm-plugins/main.js +99 -0
- package/dist/esm/pm-plugins/plugin-key.js +2 -0
- package/dist/esm/pm-plugins/smart-input-rule.js +169 -0
- package/dist/esm/ui/Toolbar/constants.js +8 -0
- package/dist/esm/ui/Toolbar/dropdown-menu.js +75 -0
- package/dist/esm/ui/Toolbar/hooks/clear-formatting-icon.js +47 -0
- package/dist/esm/ui/Toolbar/hooks/formatting-icons.js +215 -0
- package/dist/esm/ui/Toolbar/hooks/menu-state.js +15 -0
- package/dist/esm/ui/Toolbar/hooks/responsive-toolbar-buttons.js +50 -0
- package/dist/esm/ui/Toolbar/index.js +174 -0
- package/dist/esm/ui/Toolbar/more-button.js +33 -0
- package/dist/esm/ui/Toolbar/single-toolbar-buttons.js +38 -0
- package/dist/esm/ui/Toolbar/types.js +10 -0
- package/dist/esm/utils/cell-selection.js +5 -0
- package/dist/esm/utils.js +75 -0
- package/dist/esm/version.json +5 -0
- package/dist/types/actions.d.ts +22 -0
- package/dist/types/commands/clear-formatting.d.ts +6 -0
- package/dist/types/commands/text-formatting.d.ts +5 -0
- package/dist/types/commands/transform-to-code.d.ts +2 -0
- package/dist/types/index.d.ts +3 -0
- package/dist/types/plugin.d.ts +17 -0
- package/dist/types/pm-plugins/clear-formatting-keymap.d.ts +4 -0
- package/dist/types/pm-plugins/clear-formatting.d.ts +8 -0
- package/dist/types/pm-plugins/cursor.d.ts +3 -0
- package/dist/types/pm-plugins/input-rule.d.ts +23 -0
- package/dist/types/pm-plugins/keymap.d.ts +4 -0
- package/dist/types/pm-plugins/main.d.ts +7 -0
- package/dist/types/pm-plugins/plugin-key.d.ts +3 -0
- package/dist/types/pm-plugins/smart-input-rule.d.ts +3 -0
- package/dist/types/ui/Toolbar/constants.d.ts +6 -0
- package/dist/types/ui/Toolbar/dropdown-menu.d.ts +15 -0
- package/dist/types/ui/Toolbar/hooks/clear-formatting-icon.d.ts +7 -0
- package/dist/types/ui/Toolbar/hooks/formatting-icons.d.ts +14 -0
- package/dist/types/ui/Toolbar/hooks/menu-state.d.ts +1 -0
- package/dist/types/ui/Toolbar/hooks/responsive-toolbar-buttons.d.ts +20 -0
- package/dist/types/ui/Toolbar/index.d.ts +25 -0
- package/dist/types/ui/Toolbar/more-button.d.ts +14 -0
- package/dist/types/ui/Toolbar/single-toolbar-buttons.d.ts +10 -0
- package/dist/types/ui/Toolbar/types.d.ts +32 -0
- package/dist/types/utils/cell-selection.d.ts +3 -0
- package/dist/types/utils.d.ts +11 -0
- package/dist/types-ts4.5/actions.d.ts +22 -0
- package/dist/types-ts4.5/commands/clear-formatting.d.ts +6 -0
- package/dist/types-ts4.5/commands/text-formatting.d.ts +5 -0
- package/dist/types-ts4.5/commands/transform-to-code.d.ts +2 -0
- package/dist/types-ts4.5/index.d.ts +3 -0
- package/dist/types-ts4.5/plugin.d.ts +19 -0
- package/dist/types-ts4.5/pm-plugins/clear-formatting-keymap.d.ts +4 -0
- package/dist/types-ts4.5/pm-plugins/clear-formatting.d.ts +8 -0
- package/dist/types-ts4.5/pm-plugins/cursor.d.ts +3 -0
- package/dist/types-ts4.5/pm-plugins/input-rule.d.ts +23 -0
- package/dist/types-ts4.5/pm-plugins/keymap.d.ts +4 -0
- package/dist/types-ts4.5/pm-plugins/main.d.ts +7 -0
- package/dist/types-ts4.5/pm-plugins/plugin-key.d.ts +3 -0
- package/dist/types-ts4.5/pm-plugins/smart-input-rule.d.ts +3 -0
- package/dist/types-ts4.5/ui/Toolbar/constants.d.ts +6 -0
- package/dist/types-ts4.5/ui/Toolbar/dropdown-menu.d.ts +15 -0
- package/dist/types-ts4.5/ui/Toolbar/hooks/clear-formatting-icon.d.ts +7 -0
- package/dist/types-ts4.5/ui/Toolbar/hooks/formatting-icons.d.ts +14 -0
- package/dist/types-ts4.5/ui/Toolbar/hooks/menu-state.d.ts +5 -0
- package/dist/types-ts4.5/ui/Toolbar/hooks/responsive-toolbar-buttons.d.ts +20 -0
- package/dist/types-ts4.5/ui/Toolbar/index.d.ts +25 -0
- package/dist/types-ts4.5/ui/Toolbar/more-button.d.ts +14 -0
- package/dist/types-ts4.5/ui/Toolbar/single-toolbar-buttons.d.ts +10 -0
- package/dist/types-ts4.5/ui/Toolbar/types.d.ts +32 -0
- package/dist/types-ts4.5/utils/cell-selection.d.ts +3 -0
- package/dist/types-ts4.5/utils.d.ts +11 -0
- package/package.json +93 -0
- package/report.api.md +66 -0
- package/tmp/api-report-tmp.d.ts +39 -0
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
import { ACTION, ACTION_SUBJECT, ACTION_SUBJECT_ID, EVENT_TYPE, INPUT_METHOD } from '@atlaskit/editor-common/analytics';
|
|
2
|
+
import { withAnalytics } from '@atlaskit/editor-common/editor-analytics';
|
|
3
|
+
import { applyMarkOnRange } from '@atlaskit/editor-common/mark';
|
|
4
|
+
import { Selection } from '@atlaskit/editor-prosemirror/state';
|
|
5
|
+
import { hasCode, markActive } from '../utils';
|
|
6
|
+
export var moveRight = function moveRight() {
|
|
7
|
+
return function (state, dispatch) {
|
|
8
|
+
var code = state.schema.marks.code;
|
|
9
|
+
var _ref = state.selection,
|
|
10
|
+
empty = _ref.empty,
|
|
11
|
+
$cursor = _ref.$cursor;
|
|
12
|
+
if (!empty || !$cursor) {
|
|
13
|
+
return false;
|
|
14
|
+
}
|
|
15
|
+
var storedMarks = state.tr.storedMarks;
|
|
16
|
+
if (code) {
|
|
17
|
+
var insideCode = markActive(state, code.create());
|
|
18
|
+
var currentPosHasCode = state.doc.rangeHasMark($cursor.pos, $cursor.pos, code);
|
|
19
|
+
var nextPosHasCode = state.doc.rangeHasMark($cursor.pos, $cursor.pos + 1, code);
|
|
20
|
+
var exitingCode = !currentPosHasCode && !nextPosHasCode && (!storedMarks || !!storedMarks.length);
|
|
21
|
+
var enteringCode = !currentPosHasCode && nextPosHasCode && (!storedMarks || !storedMarks.length);
|
|
22
|
+
|
|
23
|
+
// entering code mark (from the left edge): don't move the cursor, just add the mark
|
|
24
|
+
if (!insideCode && enteringCode) {
|
|
25
|
+
if (dispatch) {
|
|
26
|
+
dispatch(state.tr.addStoredMark(code.create()));
|
|
27
|
+
}
|
|
28
|
+
return true;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
// exiting code mark: don't move the cursor, just remove the mark
|
|
32
|
+
if (insideCode && exitingCode) {
|
|
33
|
+
if (dispatch) {
|
|
34
|
+
dispatch(state.tr.removeStoredMark(code));
|
|
35
|
+
}
|
|
36
|
+
return true;
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
return false;
|
|
40
|
+
};
|
|
41
|
+
};
|
|
42
|
+
export var moveLeft = function moveLeft() {
|
|
43
|
+
return function (state, dispatch) {
|
|
44
|
+
var code = state.schema.marks.code;
|
|
45
|
+
var _ref2 = state.selection,
|
|
46
|
+
empty = _ref2.empty,
|
|
47
|
+
$cursor = _ref2.$cursor;
|
|
48
|
+
if (!empty || !$cursor) {
|
|
49
|
+
return false;
|
|
50
|
+
}
|
|
51
|
+
var storedMarks = state.tr.storedMarks;
|
|
52
|
+
if (code) {
|
|
53
|
+
var insideCode = code && markActive(state, code.create());
|
|
54
|
+
var currentPosHasCode = hasCode(state, $cursor.pos);
|
|
55
|
+
var nextPosHasCode = hasCode(state, $cursor.pos - 1);
|
|
56
|
+
var nextNextPosHasCode = hasCode(state, $cursor.pos - 2);
|
|
57
|
+
var exitingCode = currentPosHasCode && !nextPosHasCode && Array.isArray(storedMarks);
|
|
58
|
+
var atLeftEdge = nextPosHasCode && !nextNextPosHasCode && (storedMarks === null || Array.isArray(storedMarks) && !!storedMarks.length);
|
|
59
|
+
var atRightEdge = (exitingCode && Array.isArray(storedMarks) && !storedMarks.length || !exitingCode && storedMarks === null) && !nextPosHasCode && nextNextPosHasCode;
|
|
60
|
+
var enteringCode = !currentPosHasCode && nextPosHasCode && Array.isArray(storedMarks) && !storedMarks.length;
|
|
61
|
+
|
|
62
|
+
// at the right edge: remove code mark and move the cursor to the left
|
|
63
|
+
if (!insideCode && atRightEdge) {
|
|
64
|
+
var tr = state.tr.setSelection(Selection.near(state.doc.resolve($cursor.pos - 1)));
|
|
65
|
+
if (dispatch) {
|
|
66
|
+
dispatch(tr.removeStoredMark(code));
|
|
67
|
+
}
|
|
68
|
+
return true;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
// entering code mark (from right edge): don't move the cursor, just add the mark
|
|
72
|
+
if (!insideCode && enteringCode) {
|
|
73
|
+
if (dispatch) {
|
|
74
|
+
dispatch(state.tr.addStoredMark(code.create()));
|
|
75
|
+
}
|
|
76
|
+
return true;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
// at the left edge: add code mark and move the cursor to the left
|
|
80
|
+
if (insideCode && atLeftEdge) {
|
|
81
|
+
var _tr = state.tr.setSelection(Selection.near(state.doc.resolve($cursor.pos - 1)));
|
|
82
|
+
if (dispatch) {
|
|
83
|
+
dispatch(_tr.addStoredMark(code.create()));
|
|
84
|
+
}
|
|
85
|
+
return true;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
// exiting code mark (or at the beginning of the line): don't move the cursor, just remove the mark
|
|
89
|
+
var isFirstChild = $cursor.index($cursor.depth - 1) === 0;
|
|
90
|
+
if (insideCode && (exitingCode || !$cursor.nodeBefore && isFirstChild)) {
|
|
91
|
+
if (dispatch) {
|
|
92
|
+
dispatch(state.tr.removeStoredMark(code));
|
|
93
|
+
}
|
|
94
|
+
return true;
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
return false;
|
|
98
|
+
};
|
|
99
|
+
};
|
|
100
|
+
var createInlineCodeFromTextInput = function createInlineCodeFromTextInput(from, to, text) {
|
|
101
|
+
return function (state, dispatch) {
|
|
102
|
+
if (state.selection.empty) {
|
|
103
|
+
var _state$doc$resolve = state.doc.resolve(from),
|
|
104
|
+
before = _state$doc$resolve.nodeBefore;
|
|
105
|
+
var _state$doc$resolve2 = state.doc.resolve(to),
|
|
106
|
+
after = _state$doc$resolve2.nodeAfter;
|
|
107
|
+
var hasTickBefore = before && before.text && before.text.endsWith('`');
|
|
108
|
+
var hasTickAfter = after && after.text && after.text.startsWith('`');
|
|
109
|
+
if (hasTickBefore && hasTickAfter) {
|
|
110
|
+
var tr = state.tr.replaceRangeWith(from - 1, to + 1, state.schema.text(text));
|
|
111
|
+
if (dispatch) {
|
|
112
|
+
var codeMark = state.schema.marks.code.create();
|
|
113
|
+
tr = applyMarkOnRange(tr.mapping.map(from - 1), tr.mapping.map(to + 1), false, codeMark, tr).setStoredMarks([codeMark]);
|
|
114
|
+
dispatch(tr);
|
|
115
|
+
}
|
|
116
|
+
return true;
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
return false;
|
|
120
|
+
};
|
|
121
|
+
};
|
|
122
|
+
export var createInlineCodeFromTextInputWithAnalytics = function createInlineCodeFromTextInputWithAnalytics(editorAnalyticsAPI) {
|
|
123
|
+
return function (from, to, text) {
|
|
124
|
+
return withAnalytics(editorAnalyticsAPI, {
|
|
125
|
+
action: ACTION.FORMATTED,
|
|
126
|
+
actionSubject: ACTION_SUBJECT.TEXT,
|
|
127
|
+
eventType: EVENT_TYPE.TRACK,
|
|
128
|
+
actionSubjectId: ACTION_SUBJECT_ID.FORMAT_CODE,
|
|
129
|
+
attributes: {
|
|
130
|
+
inputMethod: INPUT_METHOD.FORMATTING
|
|
131
|
+
}
|
|
132
|
+
})(createInlineCodeFromTextInput(from, to, text));
|
|
133
|
+
};
|
|
134
|
+
};
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import { filterChildrenBetween } from '@atlaskit/editor-common/mark';
|
|
2
|
+
var SMART_TO_ASCII = {
|
|
3
|
+
'…': '...',
|
|
4
|
+
'→': '->',
|
|
5
|
+
'←': '<-',
|
|
6
|
+
'–': '--',
|
|
7
|
+
'“': '"',
|
|
8
|
+
'”': '"',
|
|
9
|
+
'‘': "'",
|
|
10
|
+
'’': "'"
|
|
11
|
+
};
|
|
12
|
+
var FIND_SMART_CHAR = new RegExp("[".concat(Object.keys(SMART_TO_ASCII).join(''), "]"), 'g');
|
|
13
|
+
var replaceMentionOrEmojiForTextContent = function replaceMentionOrEmojiForTextContent(position, nodeSize, textContent, tr) {
|
|
14
|
+
var currentPos = tr.mapping.map(position);
|
|
15
|
+
var schema = tr.doc.type.schema;
|
|
16
|
+
tr.replaceWith(currentPos, currentPos + nodeSize, schema.text(textContent));
|
|
17
|
+
};
|
|
18
|
+
var replaceSmartCharsToAscii = function replaceSmartCharsToAscii(position, textContent, tr) {
|
|
19
|
+
var schema = tr.doc.type.schema;
|
|
20
|
+
var match;
|
|
21
|
+
while (match = FIND_SMART_CHAR.exec(textContent)) {
|
|
22
|
+
var _match = match,
|
|
23
|
+
smartChar = _match[0],
|
|
24
|
+
offset = _match.index;
|
|
25
|
+
var replacePos = tr.mapping.map(position + offset);
|
|
26
|
+
var replacementText = schema.text(SMART_TO_ASCII[smartChar]);
|
|
27
|
+
tr.replaceWith(replacePos, replacePos + smartChar.length, replacementText);
|
|
28
|
+
}
|
|
29
|
+
};
|
|
30
|
+
var isNodeTextBlock = function isNodeTextBlock(schema) {
|
|
31
|
+
var _schema$nodes = schema.nodes,
|
|
32
|
+
mention = _schema$nodes.mention,
|
|
33
|
+
text = _schema$nodes.text,
|
|
34
|
+
emoji = _schema$nodes.emoji;
|
|
35
|
+
return function (node, _, parent) {
|
|
36
|
+
if (node.type === mention || node.type === emoji || node.type === text) {
|
|
37
|
+
return parent === null || parent === void 0 ? void 0 : parent.isTextblock;
|
|
38
|
+
}
|
|
39
|
+
return;
|
|
40
|
+
};
|
|
41
|
+
};
|
|
42
|
+
export var transformSmartCharsMentionsAndEmojis = function transformSmartCharsMentionsAndEmojis(from, to, tr) {
|
|
43
|
+
var schema = tr.doc.type.schema;
|
|
44
|
+
var _schema$nodes2 = schema.nodes,
|
|
45
|
+
mention = _schema$nodes2.mention,
|
|
46
|
+
text = _schema$nodes2.text,
|
|
47
|
+
emoji = _schema$nodes2.emoji;
|
|
48
|
+
// Traverse through all the nodes within the range and replace them with their plaintext counterpart
|
|
49
|
+
var children = filterChildrenBetween(tr.doc, from, to, isNodeTextBlock(schema));
|
|
50
|
+
children.forEach(function (_ref) {
|
|
51
|
+
var node = _ref.node,
|
|
52
|
+
pos = _ref.pos;
|
|
53
|
+
if (node.type === mention || node.type === emoji) {
|
|
54
|
+
replaceMentionOrEmojiForTextContent(pos, node.nodeSize, node.attrs.text, tr);
|
|
55
|
+
} else if (node.type === text && node.text) {
|
|
56
|
+
var replacePosition = pos > from ? pos : from;
|
|
57
|
+
var textToReplace = pos > from ? node.text : node.text.substr(from - pos);
|
|
58
|
+
replaceSmartCharsToAscii(replacePosition, textToReplace, tr);
|
|
59
|
+
}
|
|
60
|
+
});
|
|
61
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { textFormattingPlugin } from './plugin';
|
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { code, em, strike, strong, subsup, underline } from '@atlaskit/adf-schema';
|
|
3
|
+
import { WithPluginState } from '@atlaskit/editor-common/with-plugin-state';
|
|
4
|
+
import { toggleCodeWithAnalytics, toggleEmWithAnalytics, toggleStrikeWithAnalytics, toggleStrongWithAnalytics, toggleSubscriptWithAnalytics, toggleSuperscriptWithAnalytics, toggleUnderlineWithAnalytics } from './actions';
|
|
5
|
+
import { plugin as clearFormattingPlugin, pluginKey as clearFormattingPluginKey } from './pm-plugins/clear-formatting';
|
|
6
|
+
import clearFormattingKeymapPlugin from './pm-plugins/clear-formatting-keymap';
|
|
7
|
+
import textFormattingCursorPlugin from './pm-plugins/cursor';
|
|
8
|
+
import textFormattingInputRulePlugin from './pm-plugins/input-rule';
|
|
9
|
+
import keymapPlugin from './pm-plugins/keymap';
|
|
10
|
+
import { plugin as pmPlugin, pluginKey as textFormattingPluginKey } from './pm-plugins/main';
|
|
11
|
+
import textFormattingSmartInputRulePlugin from './pm-plugins/smart-input-rule';
|
|
12
|
+
import Toolbar from './ui/Toolbar';
|
|
13
|
+
export var textFormattingPlugin = function textFormattingPlugin() {
|
|
14
|
+
var _api$dependencies$ana7, _api$dependencies$ana8, _api$dependencies$ana9, _api$dependencies$ana10, _api$dependencies$ana11, _api$dependencies$ana12, _api$dependencies$ana13;
|
|
15
|
+
var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
16
|
+
var api = arguments.length > 1 ? arguments[1] : undefined;
|
|
17
|
+
return {
|
|
18
|
+
name: 'textFormatting',
|
|
19
|
+
marks: function marks() {
|
|
20
|
+
return [{
|
|
21
|
+
name: 'em',
|
|
22
|
+
mark: em
|
|
23
|
+
}, {
|
|
24
|
+
name: 'strong',
|
|
25
|
+
mark: strong
|
|
26
|
+
}, {
|
|
27
|
+
name: 'strike',
|
|
28
|
+
mark: strike
|
|
29
|
+
}].concat(options.disableCode ? [] : {
|
|
30
|
+
name: 'code',
|
|
31
|
+
mark: code
|
|
32
|
+
}).concat(options.disableSuperscriptAndSubscript ? [] : {
|
|
33
|
+
name: 'subsup',
|
|
34
|
+
mark: subsup
|
|
35
|
+
}).concat(options.disableUnderline ? [] : {
|
|
36
|
+
name: 'underline',
|
|
37
|
+
mark: underline
|
|
38
|
+
});
|
|
39
|
+
},
|
|
40
|
+
pmPlugins: function pmPlugins() {
|
|
41
|
+
return [{
|
|
42
|
+
name: 'textFormatting',
|
|
43
|
+
plugin: function plugin(_ref) {
|
|
44
|
+
var _api$dependencies$ana;
|
|
45
|
+
var dispatch = _ref.dispatch;
|
|
46
|
+
return pmPlugin(dispatch, api === null || api === void 0 ? void 0 : (_api$dependencies$ana = api.dependencies.analytics) === null || _api$dependencies$ana === void 0 ? void 0 : _api$dependencies$ana.actions);
|
|
47
|
+
}
|
|
48
|
+
}, {
|
|
49
|
+
name: 'textFormattingCursor',
|
|
50
|
+
plugin: function plugin() {
|
|
51
|
+
return textFormattingCursorPlugin;
|
|
52
|
+
}
|
|
53
|
+
}, {
|
|
54
|
+
name: 'textFormattingInputRule',
|
|
55
|
+
plugin: function plugin(_ref2) {
|
|
56
|
+
var _api$dependencies$ana2;
|
|
57
|
+
var schema = _ref2.schema;
|
|
58
|
+
return textFormattingInputRulePlugin(schema, api === null || api === void 0 ? void 0 : (_api$dependencies$ana2 = api.dependencies.analytics) === null || _api$dependencies$ana2 === void 0 ? void 0 : _api$dependencies$ana2.actions);
|
|
59
|
+
}
|
|
60
|
+
}, {
|
|
61
|
+
name: 'textFormattingSmartRule',
|
|
62
|
+
plugin: function plugin() {
|
|
63
|
+
var _api$dependencies$ana3;
|
|
64
|
+
return !options.disableSmartTextCompletion ? textFormattingSmartInputRulePlugin(api === null || api === void 0 ? void 0 : (_api$dependencies$ana3 = api.dependencies.analytics) === null || _api$dependencies$ana3 === void 0 ? void 0 : _api$dependencies$ana3.actions) : undefined;
|
|
65
|
+
}
|
|
66
|
+
}, {
|
|
67
|
+
name: 'textFormattingClear',
|
|
68
|
+
plugin: function plugin(_ref3) {
|
|
69
|
+
var dispatch = _ref3.dispatch;
|
|
70
|
+
return clearFormattingPlugin(dispatch);
|
|
71
|
+
}
|
|
72
|
+
}, {
|
|
73
|
+
name: 'textFormattingClearKeymap',
|
|
74
|
+
plugin: function plugin() {
|
|
75
|
+
var _api$dependencies$ana4;
|
|
76
|
+
return clearFormattingKeymapPlugin(api === null || api === void 0 ? void 0 : (_api$dependencies$ana4 = api.dependencies.analytics) === null || _api$dependencies$ana4 === void 0 ? void 0 : _api$dependencies$ana4.actions);
|
|
77
|
+
}
|
|
78
|
+
}, {
|
|
79
|
+
name: 'textFormattingKeymap',
|
|
80
|
+
plugin: function plugin(_ref4) {
|
|
81
|
+
var _api$dependencies$ana5;
|
|
82
|
+
var schema = _ref4.schema;
|
|
83
|
+
return keymapPlugin(schema, api === null || api === void 0 ? void 0 : (_api$dependencies$ana5 = api.dependencies.analytics) === null || _api$dependencies$ana5 === void 0 ? void 0 : _api$dependencies$ana5.actions);
|
|
84
|
+
}
|
|
85
|
+
}];
|
|
86
|
+
},
|
|
87
|
+
primaryToolbarComponent: function primaryToolbarComponent(_ref5) {
|
|
88
|
+
var editorView = _ref5.editorView,
|
|
89
|
+
popupsMountPoint = _ref5.popupsMountPoint,
|
|
90
|
+
popupsScrollableElement = _ref5.popupsScrollableElement,
|
|
91
|
+
isToolbarReducedSpacing = _ref5.isToolbarReducedSpacing,
|
|
92
|
+
toolbarSize = _ref5.toolbarSize,
|
|
93
|
+
disabled = _ref5.disabled;
|
|
94
|
+
return /*#__PURE__*/React.createElement(WithPluginState, {
|
|
95
|
+
plugins: {
|
|
96
|
+
textFormattingState: textFormattingPluginKey,
|
|
97
|
+
clearFormattingPluginState: clearFormattingPluginKey
|
|
98
|
+
},
|
|
99
|
+
render: function render() {
|
|
100
|
+
var _api$dependencies$ana6;
|
|
101
|
+
return /*#__PURE__*/React.createElement(Toolbar, {
|
|
102
|
+
editorState: editorView.state,
|
|
103
|
+
popupsMountPoint: popupsMountPoint,
|
|
104
|
+
popupsScrollableElement: popupsScrollableElement,
|
|
105
|
+
toolbarSize: toolbarSize,
|
|
106
|
+
isReducedSpacing: isToolbarReducedSpacing,
|
|
107
|
+
editorView: editorView,
|
|
108
|
+
isToolbarDisabled: disabled,
|
|
109
|
+
shouldUseResponsiveToolbar: Boolean(options.responsiveToolbarMenu),
|
|
110
|
+
editorAnalyticsAPI: api === null || api === void 0 ? void 0 : (_api$dependencies$ana6 = api.dependencies.analytics) === null || _api$dependencies$ana6 === void 0 ? void 0 : _api$dependencies$ana6.actions
|
|
111
|
+
});
|
|
112
|
+
}
|
|
113
|
+
});
|
|
114
|
+
},
|
|
115
|
+
actions: {
|
|
116
|
+
toggleSuperscript: toggleSuperscriptWithAnalytics(api === null || api === void 0 ? void 0 : (_api$dependencies$ana7 = api.dependencies.analytics) === null || _api$dependencies$ana7 === void 0 ? void 0 : _api$dependencies$ana7.actions),
|
|
117
|
+
toggleSubscript: toggleSubscriptWithAnalytics(api === null || api === void 0 ? void 0 : (_api$dependencies$ana8 = api.dependencies.analytics) === null || _api$dependencies$ana8 === void 0 ? void 0 : _api$dependencies$ana8.actions),
|
|
118
|
+
toggleStrike: toggleStrikeWithAnalytics(api === null || api === void 0 ? void 0 : (_api$dependencies$ana9 = api.dependencies.analytics) === null || _api$dependencies$ana9 === void 0 ? void 0 : _api$dependencies$ana9.actions),
|
|
119
|
+
toggleCode: toggleCodeWithAnalytics(api === null || api === void 0 ? void 0 : (_api$dependencies$ana10 = api.dependencies.analytics) === null || _api$dependencies$ana10 === void 0 ? void 0 : _api$dependencies$ana10.actions),
|
|
120
|
+
toggleUnderline: toggleUnderlineWithAnalytics(api === null || api === void 0 ? void 0 : (_api$dependencies$ana11 = api.dependencies.analytics) === null || _api$dependencies$ana11 === void 0 ? void 0 : _api$dependencies$ana11.actions),
|
|
121
|
+
toggleEm: toggleEmWithAnalytics(api === null || api === void 0 ? void 0 : (_api$dependencies$ana12 = api.dependencies.analytics) === null || _api$dependencies$ana12 === void 0 ? void 0 : _api$dependencies$ana12.actions),
|
|
122
|
+
toggleStrong: toggleStrongWithAnalytics(api === null || api === void 0 ? void 0 : (_api$dependencies$ana13 = api.dependencies.analytics) === null || _api$dependencies$ana13 === void 0 ? void 0 : _api$dependencies$ana13.actions)
|
|
123
|
+
}
|
|
124
|
+
};
|
|
125
|
+
};
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { INPUT_METHOD } from '@atlaskit/editor-common/analytics';
|
|
2
|
+
import * as keymaps from '@atlaskit/editor-common/keymaps';
|
|
3
|
+
import { keymap } from '@atlaskit/editor-prosemirror/keymap';
|
|
4
|
+
import { clearFormattingWithAnalytics } from '../commands/clear-formatting';
|
|
5
|
+
export function keymapPlugin(editorAnalyticsAPI) {
|
|
6
|
+
var list = {};
|
|
7
|
+
keymaps.bindKeymapWithCommand(keymaps.clearFormatting.common, clearFormattingWithAnalytics(INPUT_METHOD.SHORTCUT, editorAnalyticsAPI), list);
|
|
8
|
+
return keymap(list);
|
|
9
|
+
}
|
|
10
|
+
export default keymapPlugin;
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { SafePlugin } from '@atlaskit/editor-common/safe-plugin';
|
|
2
|
+
import { PluginKey } from '@atlaskit/editor-prosemirror/state';
|
|
3
|
+
import { checkFormattingIsPresent } from '../utils';
|
|
4
|
+
export var pluginKey = new PluginKey('clearFormattingPlugin');
|
|
5
|
+
export var plugin = function plugin(dispatch) {
|
|
6
|
+
return new SafePlugin({
|
|
7
|
+
state: {
|
|
8
|
+
init: function init(_config, state) {
|
|
9
|
+
return {
|
|
10
|
+
formattingIsPresent: checkFormattingIsPresent(state)
|
|
11
|
+
};
|
|
12
|
+
},
|
|
13
|
+
apply: function apply(_tr, pluginState, _oldState, newState) {
|
|
14
|
+
var formattingIsPresent = checkFormattingIsPresent(newState);
|
|
15
|
+
if (formattingIsPresent !== pluginState.formattingIsPresent) {
|
|
16
|
+
dispatch(pluginKey, {
|
|
17
|
+
formattingIsPresent: formattingIsPresent
|
|
18
|
+
});
|
|
19
|
+
return {
|
|
20
|
+
formattingIsPresent: formattingIsPresent
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
return pluginState;
|
|
24
|
+
}
|
|
25
|
+
},
|
|
26
|
+
key: pluginKey
|
|
27
|
+
});
|
|
28
|
+
};
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { SafePlugin } from '@atlaskit/editor-common/safe-plugin';
|
|
2
|
+
import { TextSelection } from '@atlaskit/editor-prosemirror/state';
|
|
3
|
+
export default new SafePlugin({
|
|
4
|
+
props: {
|
|
5
|
+
handleClick: function handleClick(view, clickPos, event) {
|
|
6
|
+
// Don't apply in Edge as per ED-4546
|
|
7
|
+
if (navigator && /Edge\/\d/.test(navigator.userAgent)) {
|
|
8
|
+
return false;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
// @see ED-6231
|
|
12
|
+
if (clickPos > view.state.doc.content.size) {
|
|
13
|
+
return false;
|
|
14
|
+
}
|
|
15
|
+
var code = view.state.schema.marks.code;
|
|
16
|
+
var paragraph = view.state.schema.nodes.paragraph;
|
|
17
|
+
var $click = view.state.doc.resolve(clickPos);
|
|
18
|
+
var clickWasAtEdgeOfATextNode = ($click.nodeBefore ? $click.nodeBefore.isInline : $click.nodeAfter) && ($click.nodeAfter ? $click.nodeAfter.isInline : $click.nodeBefore) && $click.textOffset === 0;
|
|
19
|
+
var clickWasNearACodeMark = code && ($click.nodeBefore && code.isInSet($click.nodeBefore.marks) || $click.nodeAfter && code.isInSet($click.nodeAfter.marks));
|
|
20
|
+
|
|
21
|
+
// Find the starting position of the clicked dom-element
|
|
22
|
+
// TODO: Remove calls to private API
|
|
23
|
+
var clickedDOMElementPosition = event.target && event.target instanceof Node && view.posAtDOM(event.target);
|
|
24
|
+
var clickNode = view.state.doc.nodeAt(clickPos);
|
|
25
|
+
var clickWasAtTextNode = !!(clickNode && clickNode.isText);
|
|
26
|
+
var clickWasAtEndOfAParagraphNode = $click.parent.type === paragraph && $click.textOffset === 0 && $click.nodeAfter === null;
|
|
27
|
+
if (clickWasAtEdgeOfATextNode && clickWasNearACodeMark && clickedDOMElementPosition && (
|
|
28
|
+
// if click did not occur at a text node or end of paragraph, then
|
|
29
|
+
// it was at a directly adjacent non-text node, so we skip this manual
|
|
30
|
+
// text selection logic to preserve that non-text node's selection
|
|
31
|
+
clickWasAtTextNode || clickWasAtEndOfAParagraphNode)) {
|
|
32
|
+
var clickWasInsideNodeDOM = event.target.parentNode === view.domAtPos(clickedDOMElementPosition).node && code.isInSet(view.state.doc.resolve(clickedDOMElementPosition).nodeAfter.marks);
|
|
33
|
+
var nodeNextToClick = $click.nodeBefore && code.isInSet($click.nodeBefore.marks) ? $click.nodeAfter : $click.nodeBefore;
|
|
34
|
+
|
|
35
|
+
// Need to set the selection here to allow clicking between [code('text'),{<>},emoji()]
|
|
36
|
+
var tr = view.state.tr.setSelection(TextSelection.near($click));
|
|
37
|
+
if (clickWasInsideNodeDOM) {
|
|
38
|
+
tr.setStoredMarks([code.create()]);
|
|
39
|
+
} else {
|
|
40
|
+
tr.setStoredMarks(nodeNextToClick ? nodeNextToClick.marks : []);
|
|
41
|
+
}
|
|
42
|
+
view.dispatch(tr);
|
|
43
|
+
return true;
|
|
44
|
+
}
|
|
45
|
+
return false;
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
});
|
|
@@ -0,0 +1,257 @@
|
|
|
1
|
+
import _toConsumableArray from "@babel/runtime/helpers/toConsumableArray";
|
|
2
|
+
import _classCallCheck from "@babel/runtime/helpers/classCallCheck";
|
|
3
|
+
import _createClass from "@babel/runtime/helpers/createClass";
|
|
4
|
+
import _get from "@babel/runtime/helpers/get";
|
|
5
|
+
import _inherits from "@babel/runtime/helpers/inherits";
|
|
6
|
+
import _possibleConstructorReturn from "@babel/runtime/helpers/possibleConstructorReturn";
|
|
7
|
+
import _getPrototypeOf from "@babel/runtime/helpers/getPrototypeOf";
|
|
8
|
+
import _wrapNativeSuper from "@babel/runtime/helpers/wrapNativeSuper";
|
|
9
|
+
import _defineProperty from "@babel/runtime/helpers/defineProperty";
|
|
10
|
+
var _ValidCombinations;
|
|
11
|
+
function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
|
|
12
|
+
function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
|
|
13
|
+
import { ACTION, ACTION_SUBJECT, ACTION_SUBJECT_ID, EVENT_TYPE, INPUT_METHOD } from '@atlaskit/editor-common/analytics';
|
|
14
|
+
import { transformSmartCharsMentionsAndEmojis } from '@atlaskit/editor-common/mark';
|
|
15
|
+
import { inputRuleWithAnalytics } from '@atlaskit/editor-common/utils';
|
|
16
|
+
import { createPlugin, createRule, leafNodeReplacementCharacter } from '@atlaskit/prosemirror-input-rules';
|
|
17
|
+
var ValidAutoformatChars = /*#__PURE__*/function (ValidAutoformatChars) {
|
|
18
|
+
ValidAutoformatChars["STRONG"] = "__";
|
|
19
|
+
ValidAutoformatChars["STRIKE"] = "~~";
|
|
20
|
+
ValidAutoformatChars["STRONG_MARKDOWN"] = "**";
|
|
21
|
+
ValidAutoformatChars["ITALIC_MARKDOWN"] = "*";
|
|
22
|
+
ValidAutoformatChars["ITALIC"] = "_";
|
|
23
|
+
ValidAutoformatChars["CODE"] = "`";
|
|
24
|
+
return ValidAutoformatChars;
|
|
25
|
+
}(ValidAutoformatChars || {});
|
|
26
|
+
export var ValidCombinations = (_ValidCombinations = {}, _defineProperty(_ValidCombinations, ValidAutoformatChars.STRIKE, [
|
|
27
|
+
// e.g: _~~lol~~_
|
|
28
|
+
ValidAutoformatChars.ITALIC,
|
|
29
|
+
// e.g: __~~lol~~__
|
|
30
|
+
ValidAutoformatChars.STRONG,
|
|
31
|
+
// e.g: **~~lol~~**
|
|
32
|
+
ValidAutoformatChars.STRONG_MARKDOWN,
|
|
33
|
+
// e.g: *~~lol~~*
|
|
34
|
+
ValidAutoformatChars.ITALIC_MARKDOWN]), _defineProperty(_ValidCombinations, ValidAutoformatChars.STRONG, [
|
|
35
|
+
// e.g: ~~__lol__~~
|
|
36
|
+
ValidAutoformatChars.STRIKE,
|
|
37
|
+
// e.g: *__lol__*
|
|
38
|
+
ValidAutoformatChars.ITALIC_MARKDOWN]), _defineProperty(_ValidCombinations, ValidAutoformatChars.STRONG_MARKDOWN, [
|
|
39
|
+
// e.g: _**lol**_
|
|
40
|
+
ValidAutoformatChars.ITALIC,
|
|
41
|
+
// e.g: ~~**lol**~~
|
|
42
|
+
ValidAutoformatChars.STRIKE]), _defineProperty(_ValidCombinations, ValidAutoformatChars.ITALIC_MARKDOWN, [
|
|
43
|
+
// e.g: ~~*lol*~~
|
|
44
|
+
ValidAutoformatChars.STRIKE,
|
|
45
|
+
// e.g: __*lol*__
|
|
46
|
+
ValidAutoformatChars.STRONG]), _defineProperty(_ValidCombinations, ValidAutoformatChars.ITALIC, [
|
|
47
|
+
// e.g: ~~_lol_~~
|
|
48
|
+
ValidAutoformatChars.STRIKE,
|
|
49
|
+
// e.g: **_lol_**
|
|
50
|
+
ValidAutoformatChars.STRONG_MARKDOWN]), _defineProperty(_ValidCombinations, ValidAutoformatChars.CODE, [
|
|
51
|
+
// e.g: loko (`some code`
|
|
52
|
+
'( ']), _ValidCombinations);
|
|
53
|
+
function addMark(markType, schema, char) {
|
|
54
|
+
return function (state, match, start, end) {
|
|
55
|
+
var _schema$marks, _schema$marks$code;
|
|
56
|
+
var doc = state.doc,
|
|
57
|
+
schema = state.schema,
|
|
58
|
+
tr = state.tr;
|
|
59
|
+
var textPrefix = state.doc.textBetween(start, start + char.length);
|
|
60
|
+
|
|
61
|
+
// fixes the following case: my `*name` is *
|
|
62
|
+
// expected result: should ignore special characters inside "code"
|
|
63
|
+
if (textPrefix !== char || schema !== null && schema !== void 0 && (_schema$marks = schema.marks) !== null && _schema$marks !== void 0 && (_schema$marks$code = _schema$marks.code) !== null && _schema$marks$code !== void 0 && _schema$marks$code.isInSet(doc.resolve(start + 1).marks())) {
|
|
64
|
+
return null;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
// Prevent autoformatting across hardbreaks
|
|
68
|
+
var containsHardBreak;
|
|
69
|
+
doc.nodesBetween(start, end, function (node) {
|
|
70
|
+
if (node.type === schema.nodes.hardBreak) {
|
|
71
|
+
containsHardBreak = true;
|
|
72
|
+
return false;
|
|
73
|
+
}
|
|
74
|
+
return !containsHardBreak;
|
|
75
|
+
});
|
|
76
|
+
if (containsHardBreak) {
|
|
77
|
+
return null;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
// fixes autoformatting in heading nodes: # Heading *bold*
|
|
81
|
+
// expected result: should not autoformat *bold*; <h1>Heading *bold*</h1>
|
|
82
|
+
var startPosResolved = doc.resolve(start);
|
|
83
|
+
var endPosResolved = doc.resolve(end);
|
|
84
|
+
if (startPosResolved.sameParent(endPosResolved) && !startPosResolved.parent.type.allowsMarkType(markType)) {
|
|
85
|
+
return null;
|
|
86
|
+
}
|
|
87
|
+
if (markType.name === 'code') {
|
|
88
|
+
transformSmartCharsMentionsAndEmojis(tr.mapping.map(start), tr.mapping.map(end), tr);
|
|
89
|
+
}
|
|
90
|
+
var mappedStart = tr.mapping.map(start);
|
|
91
|
+
var mappedEnd = tr.mapping.map(end);
|
|
92
|
+
tr.addMark(mappedStart, mappedEnd, markType.create());
|
|
93
|
+
var textSuffix = tr.doc.textBetween(mappedEnd - char.length, mappedEnd);
|
|
94
|
+
if (textSuffix === char) {
|
|
95
|
+
tr.delete(mappedEnd - char.length, mappedEnd);
|
|
96
|
+
}
|
|
97
|
+
if (textPrefix === char) {
|
|
98
|
+
tr.delete(mappedStart, mappedStart + char.length);
|
|
99
|
+
}
|
|
100
|
+
return tr.removeStoredMark(markType);
|
|
101
|
+
};
|
|
102
|
+
}
|
|
103
|
+
var ReverseRegexExp = /*#__PURE__*/function (_RegExp) {
|
|
104
|
+
_inherits(ReverseRegexExp, _RegExp);
|
|
105
|
+
var _super = _createSuper(ReverseRegexExp);
|
|
106
|
+
function ReverseRegexExp() {
|
|
107
|
+
_classCallCheck(this, ReverseRegexExp);
|
|
108
|
+
return _super.apply(this, arguments);
|
|
109
|
+
}
|
|
110
|
+
_createClass(ReverseRegexExp, [{
|
|
111
|
+
key: "exec",
|
|
112
|
+
value: function exec(str) {
|
|
113
|
+
if (!str) {
|
|
114
|
+
return null;
|
|
115
|
+
}
|
|
116
|
+
var reverseStr = _toConsumableArray(str).reverse().join('');
|
|
117
|
+
var result = _get(_getPrototypeOf(ReverseRegexExp.prototype), "exec", this).call(this, reverseStr);
|
|
118
|
+
if (!result) {
|
|
119
|
+
return null;
|
|
120
|
+
}
|
|
121
|
+
for (var i = 0; i < result.length; i++) {
|
|
122
|
+
if (result[i] && typeof result[i] === 'string') {
|
|
123
|
+
result[i] = _toConsumableArray(result[i]).reverse().join('');
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
if (result.input && typeof result.input === 'string') {
|
|
127
|
+
result.input = _toConsumableArray(result.input).reverse().join('');
|
|
128
|
+
}
|
|
129
|
+
if (result.input && result[0]) {
|
|
130
|
+
result.index = result.input.length - result[0].length;
|
|
131
|
+
}
|
|
132
|
+
return result;
|
|
133
|
+
}
|
|
134
|
+
}]);
|
|
135
|
+
return ReverseRegexExp;
|
|
136
|
+
}( /*#__PURE__*/_wrapNativeSuper(RegExp));
|
|
137
|
+
var buildRegex = function buildRegex(char) {
|
|
138
|
+
var escapedChar = char.replace(/(\W)/g, '\\$1');
|
|
139
|
+
var combinations = ValidCombinations[char].map(function (c) {
|
|
140
|
+
return c.replace(/(\W)/g, '\\$1');
|
|
141
|
+
}).join('|');
|
|
142
|
+
|
|
143
|
+
// Single X - https://regex101.com/r/McT3yq/14/
|
|
144
|
+
// Double X - https://regex101.com/r/pQUgjx/1/
|
|
145
|
+
var baseRegex = '^X(?=[^X\\s]).*?[^\\sX]X(?=[\\sOBJECT_REPLACEMENT_CHARACTER]COMBINATIONS|$)'.replace('OBJECT_REPLACEMENT_CHARACTER', leafNodeReplacementCharacter).replace('COMBINATIONS', combinations ? "|".concat(combinations) : '');
|
|
146
|
+
var replacedRegex = String.prototype.hasOwnProperty('replaceAll') ? baseRegex.replaceAll('X', escapedChar) : baseRegex.replace(/X/g, escapedChar);
|
|
147
|
+
return new ReverseRegexExp(replacedRegex);
|
|
148
|
+
};
|
|
149
|
+
export var strongRegex1 = buildRegex(ValidAutoformatChars.STRONG);
|
|
150
|
+
export var strongRegex2 = buildRegex(ValidAutoformatChars.STRONG_MARKDOWN);
|
|
151
|
+
export var italicRegex1 = buildRegex(ValidAutoformatChars.ITALIC);
|
|
152
|
+
export var italicRegex2 = buildRegex(ValidAutoformatChars.ITALIC_MARKDOWN);
|
|
153
|
+
export var strikeRegex = buildRegex(ValidAutoformatChars.STRIKE);
|
|
154
|
+
export var codeRegex = buildRegex(ValidAutoformatChars.CODE);
|
|
155
|
+
|
|
156
|
+
/**
|
|
157
|
+
* Create input rules for strong mark
|
|
158
|
+
*
|
|
159
|
+
* @param {Schema} schema
|
|
160
|
+
* @returns {InputRuleWrapper[]}
|
|
161
|
+
*/
|
|
162
|
+
function getStrongInputRules(schema, editorAnalyticsAPI) {
|
|
163
|
+
var ruleWithStrongAnalytics = inputRuleWithAnalytics({
|
|
164
|
+
action: ACTION.FORMATTED,
|
|
165
|
+
actionSubject: ACTION_SUBJECT.TEXT,
|
|
166
|
+
actionSubjectId: ACTION_SUBJECT_ID.FORMAT_STRONG,
|
|
167
|
+
eventType: EVENT_TYPE.TRACK,
|
|
168
|
+
attributes: {
|
|
169
|
+
inputMethod: INPUT_METHOD.FORMATTING
|
|
170
|
+
}
|
|
171
|
+
}, editorAnalyticsAPI);
|
|
172
|
+
// **string** or __strong__ should bold the text
|
|
173
|
+
var doubleUnderscoreRule = createRule(strongRegex1, addMark(schema.marks.strong, schema, ValidAutoformatChars.STRONG));
|
|
174
|
+
var doubleAsterixRule = createRule(strongRegex2, addMark(schema.marks.strong, schema, ValidAutoformatChars.STRONG_MARKDOWN));
|
|
175
|
+
return [ruleWithStrongAnalytics(doubleUnderscoreRule), ruleWithStrongAnalytics(doubleAsterixRule)];
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
/**
|
|
179
|
+
* Create input rules for em mark
|
|
180
|
+
*
|
|
181
|
+
* @param {Schema} schema
|
|
182
|
+
* @returns {InputRuleWrapper[]}
|
|
183
|
+
*/
|
|
184
|
+
function getItalicInputRules(schema, editorAnalyticsAPI) {
|
|
185
|
+
var ruleWithItalicAnalytics = inputRuleWithAnalytics({
|
|
186
|
+
action: ACTION.FORMATTED,
|
|
187
|
+
actionSubject: ACTION_SUBJECT.TEXT,
|
|
188
|
+
actionSubjectId: ACTION_SUBJECT_ID.FORMAT_ITALIC,
|
|
189
|
+
eventType: EVENT_TYPE.TRACK,
|
|
190
|
+
attributes: {
|
|
191
|
+
inputMethod: INPUT_METHOD.FORMATTING
|
|
192
|
+
}
|
|
193
|
+
}, editorAnalyticsAPI);
|
|
194
|
+
var underscoreRule = createRule(italicRegex1, addMark(schema.marks.em, schema, ValidAutoformatChars.ITALIC));
|
|
195
|
+
var asterixRule = createRule(italicRegex2, addMark(schema.marks.em, schema, ValidAutoformatChars.ITALIC_MARKDOWN));
|
|
196
|
+
return [ruleWithItalicAnalytics(underscoreRule), ruleWithItalicAnalytics(asterixRule)];
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
/**
|
|
200
|
+
* Create input rules for strike mark
|
|
201
|
+
*
|
|
202
|
+
* @param {Schema} schema
|
|
203
|
+
* @returns {InputRuleWrapper[]}
|
|
204
|
+
*/
|
|
205
|
+
function getStrikeInputRules(schema, editorAnalyticsAPI) {
|
|
206
|
+
var ruleWithStrikeAnalytics = inputRuleWithAnalytics({
|
|
207
|
+
action: ACTION.FORMATTED,
|
|
208
|
+
actionSubject: ACTION_SUBJECT.TEXT,
|
|
209
|
+
actionSubjectId: ACTION_SUBJECT_ID.FORMAT_STRIKE,
|
|
210
|
+
eventType: EVENT_TYPE.TRACK,
|
|
211
|
+
attributes: {
|
|
212
|
+
inputMethod: INPUT_METHOD.FORMATTING
|
|
213
|
+
}
|
|
214
|
+
}, editorAnalyticsAPI);
|
|
215
|
+
var doubleTildeRule = createRule(strikeRegex, addMark(schema.marks.strike, schema, ValidAutoformatChars.STRIKE));
|
|
216
|
+
return [ruleWithStrikeAnalytics(doubleTildeRule)];
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
/**
|
|
220
|
+
* Create input rules for code mark
|
|
221
|
+
*
|
|
222
|
+
* @param {Schema} schema
|
|
223
|
+
* @returns {InputRuleWrapper[]}
|
|
224
|
+
*/
|
|
225
|
+
function getCodeInputRules(schema, editorAnalyticsAPI) {
|
|
226
|
+
var ruleWithCodeAnalytics = inputRuleWithAnalytics({
|
|
227
|
+
action: ACTION.FORMATTED,
|
|
228
|
+
actionSubject: ACTION_SUBJECT.TEXT,
|
|
229
|
+
actionSubjectId: ACTION_SUBJECT_ID.FORMAT_CODE,
|
|
230
|
+
eventType: EVENT_TYPE.TRACK,
|
|
231
|
+
attributes: {
|
|
232
|
+
inputMethod: INPUT_METHOD.FORMATTING
|
|
233
|
+
}
|
|
234
|
+
}, editorAnalyticsAPI);
|
|
235
|
+
var backTickRule = createRule(codeRegex, addMark(schema.marks.code, schema, ValidAutoformatChars.CODE));
|
|
236
|
+
return [ruleWithCodeAnalytics(backTickRule)];
|
|
237
|
+
}
|
|
238
|
+
export function inputRulePlugin(schema, editorAnalyticsAPI) {
|
|
239
|
+
var rules = [];
|
|
240
|
+
if (schema.marks.strong) {
|
|
241
|
+
rules.push.apply(rules, _toConsumableArray(getStrongInputRules(schema, editorAnalyticsAPI)));
|
|
242
|
+
}
|
|
243
|
+
if (schema.marks.em) {
|
|
244
|
+
rules.push.apply(rules, _toConsumableArray(getItalicInputRules(schema, editorAnalyticsAPI)));
|
|
245
|
+
}
|
|
246
|
+
if (schema.marks.strike) {
|
|
247
|
+
rules.push.apply(rules, _toConsumableArray(getStrikeInputRules(schema, editorAnalyticsAPI)));
|
|
248
|
+
}
|
|
249
|
+
if (schema.marks.code) {
|
|
250
|
+
rules.push.apply(rules, _toConsumableArray(getCodeInputRules(schema, editorAnalyticsAPI)));
|
|
251
|
+
}
|
|
252
|
+
if (rules.length !== 0) {
|
|
253
|
+
return createPlugin('text-formatting', rules);
|
|
254
|
+
}
|
|
255
|
+
return;
|
|
256
|
+
}
|
|
257
|
+
export default inputRulePlugin;
|