@atlaskit/editor-core 187.17.6 → 187.18.1
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 +18 -0
- package/dist/cjs/labs/next/presets/default.js +2 -2
- package/dist/cjs/plugins/annotation/toolbar.js +31 -8
- package/dist/cjs/plugins/help-dialog/ui/index.js +26 -27
- package/dist/cjs/plugins/index.js +0 -7
- package/dist/cjs/plugins/list/index.js +5 -5
- package/dist/cjs/plugins/list/transforms.js +1 -223
- package/dist/cjs/plugins/paste/commands.js +224 -2
- package/dist/cjs/plugins/paste/pm-plugins/main.js +3 -3
- package/dist/cjs/plugins/toolbar-lists-indentation/ui/Toolbar.js +3 -3
- package/dist/cjs/plugins/toolbar-lists-indentation/ui/ToolbarDropdown.js +4 -4
- package/dist/cjs/version-wrapper.js +1 -1
- package/dist/cjs/version.json +1 -1
- package/dist/es2019/labs/next/presets/default.js +1 -1
- package/dist/es2019/plugins/annotation/toolbar.js +34 -9
- package/dist/es2019/plugins/help-dialog/ui/index.js +1 -2
- package/dist/es2019/plugins/index.js +0 -1
- package/dist/es2019/plugins/list/index.js +1 -1
- package/dist/es2019/plugins/list/transforms.js +2 -210
- package/dist/es2019/plugins/paste/commands.js +210 -2
- package/dist/es2019/plugins/paste/pm-plugins/main.js +1 -1
- package/dist/es2019/plugins/toolbar-lists-indentation/ui/Toolbar.js +1 -1
- package/dist/es2019/plugins/toolbar-lists-indentation/ui/ToolbarDropdown.js +1 -1
- package/dist/es2019/version-wrapper.js +1 -1
- package/dist/es2019/version.json +1 -1
- package/dist/esm/labs/next/presets/default.js +1 -1
- package/dist/esm/plugins/annotation/toolbar.js +30 -7
- package/dist/esm/plugins/help-dialog/ui/index.js +1 -2
- package/dist/esm/plugins/index.js +0 -1
- package/dist/esm/plugins/list/index.js +1 -1
- package/dist/esm/plugins/list/transforms.js +2 -219
- package/dist/esm/plugins/paste/commands.js +218 -1
- package/dist/esm/plugins/paste/pm-plugins/main.js +1 -1
- package/dist/esm/plugins/toolbar-lists-indentation/ui/Toolbar.js +1 -1
- package/dist/esm/plugins/toolbar-lists-indentation/ui/ToolbarDropdown.js +1 -1
- package/dist/esm/version-wrapper.js +1 -1
- package/dist/esm/version.json +1 -1
- package/dist/types/index.d.ts +0 -5
- package/dist/types/labs/next/presets/default.d.ts +28 -28
- package/dist/types/plugins/annotation/types.d.ts +9 -3
- package/dist/types/plugins/index.d.ts +0 -1
- package/dist/types/plugins/list/pm-plugins/input-rules/wrapping-join-rule.d.ts +1 -2
- package/dist/types/plugins/list/transforms.d.ts +0 -13
- package/dist/types/plugins/paste/commands.d.ts +14 -0
- package/dist/types/plugins/paste/index.d.ts +2 -0
- package/dist/types-ts4.5/index.d.ts +0 -5
- package/dist/types-ts4.5/labs/next/presets/default.d.ts +28 -28
- package/dist/types-ts4.5/plugins/annotation/types.d.ts +9 -3
- package/dist/types-ts4.5/plugins/index.d.ts +0 -1
- package/dist/types-ts4.5/plugins/list/pm-plugins/input-rules/wrapping-join-rule.d.ts +1 -2
- package/dist/types-ts4.5/plugins/list/transforms.d.ts +0 -13
- package/dist/types-ts4.5/plugins/paste/commands.d.ts +14 -0
- package/dist/types-ts4.5/plugins/paste/index.d.ts +2 -0
- package/package.json +3 -2
- package/report.api.md +1 -24
- package/tmp/api-report-tmp.d.ts +1 -21
- package/dist/cjs/plugins/text-formatting/actions.js +0 -188
- package/dist/cjs/plugins/text-formatting/commands/clear-formatting.js +0 -111
- package/dist/cjs/plugins/text-formatting/commands/text-formatting.js +0 -143
- package/dist/cjs/plugins/text-formatting/commands/transform-to-code.js +0 -68
- package/dist/cjs/plugins/text-formatting/index.js +0 -136
- package/dist/cjs/plugins/text-formatting/pm-plugins/clear-formatting-keymap.js +0 -21
- package/dist/cjs/plugins/text-formatting/pm-plugins/clear-formatting.js +0 -36
- package/dist/cjs/plugins/text-formatting/pm-plugins/cursor.js +0 -55
- package/dist/cjs/plugins/text-formatting/pm-plugins/input-rule.js +0 -276
- package/dist/cjs/plugins/text-formatting/pm-plugins/keymap.js +0 -52
- package/dist/cjs/plugins/text-formatting/pm-plugins/main.js +0 -113
- package/dist/cjs/plugins/text-formatting/pm-plugins/plugin-key.js +0 -9
- package/dist/cjs/plugins/text-formatting/pm-plugins/smart-input-rule.js +0 -176
- package/dist/cjs/plugins/text-formatting/ui/Toolbar/constants.js +0 -19
- package/dist/cjs/plugins/text-formatting/ui/Toolbar/dropdown-menu.js +0 -86
- package/dist/cjs/plugins/text-formatting/ui/Toolbar/hooks/clear-formatting-icon.js +0 -53
- package/dist/cjs/plugins/text-formatting/ui/Toolbar/hooks/formatting-icons.js +0 -225
- package/dist/cjs/plugins/text-formatting/ui/Toolbar/hooks/menu-state.js +0 -23
- package/dist/cjs/plugins/text-formatting/ui/Toolbar/hooks/responsive-toolbar-buttons.js +0 -60
- package/dist/cjs/plugins/text-formatting/ui/Toolbar/index.js +0 -201
- package/dist/cjs/plugins/text-formatting/ui/Toolbar/more-button.js +0 -40
- package/dist/cjs/plugins/text-formatting/ui/Toolbar/single-toolbar-buttons.js +0 -46
- package/dist/cjs/plugins/text-formatting/ui/Toolbar/types.js +0 -17
- package/dist/cjs/plugins/text-formatting/utils/cell-selection.js +0 -12
- package/dist/cjs/plugins/text-formatting/utils.js +0 -86
- package/dist/es2019/plugins/text-formatting/actions.js +0 -161
- package/dist/es2019/plugins/text-formatting/commands/clear-formatting.js +0 -105
- package/dist/es2019/plugins/text-formatting/commands/text-formatting.js +0 -144
- package/dist/es2019/plugins/text-formatting/commands/transform-to-code.js +0 -71
- package/dist/es2019/plugins/text-formatting/index.js +0 -127
- package/dist/es2019/plugins/text-formatting/pm-plugins/clear-formatting-keymap.js +0 -10
- package/dist/es2019/plugins/text-formatting/pm-plugins/clear-formatting.js +0 -26
- package/dist/es2019/plugins/text-formatting/pm-plugins/cursor.js +0 -52
- package/dist/es2019/plugins/text-formatting/pm-plugins/input-rule.js +0 -244
- package/dist/es2019/plugins/text-formatting/pm-plugins/keymap.js +0 -43
- package/dist/es2019/plugins/text-formatting/pm-plugins/main.js +0 -109
- package/dist/es2019/plugins/text-formatting/pm-plugins/plugin-key.js +0 -2
- package/dist/es2019/plugins/text-formatting/pm-plugins/smart-input-rule.js +0 -155
- package/dist/es2019/plugins/text-formatting/ui/Toolbar/constants.js +0 -20
- package/dist/es2019/plugins/text-formatting/ui/Toolbar/dropdown-menu.js +0 -66
- package/dist/es2019/plugins/text-formatting/ui/Toolbar/hooks/clear-formatting-icon.js +0 -42
- package/dist/es2019/plugins/text-formatting/ui/Toolbar/hooks/formatting-icons.js +0 -210
- package/dist/es2019/plugins/text-formatting/ui/Toolbar/hooks/menu-state.js +0 -11
- package/dist/es2019/plugins/text-formatting/ui/Toolbar/hooks/responsive-toolbar-buttons.js +0 -48
- package/dist/es2019/plugins/text-formatting/ui/Toolbar/index.js +0 -168
- package/dist/es2019/plugins/text-formatting/ui/Toolbar/more-button.js +0 -32
- package/dist/es2019/plugins/text-formatting/ui/Toolbar/single-toolbar-buttons.js +0 -36
- package/dist/es2019/plugins/text-formatting/ui/Toolbar/types.js +0 -10
- package/dist/es2019/plugins/text-formatting/utils/cell-selection.js +0 -5
- package/dist/es2019/plugins/text-formatting/utils.js +0 -74
- package/dist/esm/plugins/text-formatting/actions.js +0 -168
- package/dist/esm/plugins/text-formatting/commands/clear-formatting.js +0 -101
- package/dist/esm/plugins/text-formatting/commands/text-formatting.js +0 -134
- package/dist/esm/plugins/text-formatting/commands/transform-to-code.js +0 -61
- package/dist/esm/plugins/text-formatting/index.js +0 -128
- package/dist/esm/plugins/text-formatting/pm-plugins/clear-formatting-keymap.js +0 -10
- package/dist/esm/plugins/text-formatting/pm-plugins/clear-formatting.js +0 -28
- package/dist/esm/plugins/text-formatting/pm-plugins/cursor.js +0 -48
- package/dist/esm/plugins/text-formatting/pm-plugins/input-rule.js +0 -259
- package/dist/esm/plugins/text-formatting/pm-plugins/keymap.js +0 -43
- package/dist/esm/plugins/text-formatting/pm-plugins/main.js +0 -98
- package/dist/esm/plugins/text-formatting/pm-plugins/plugin-key.js +0 -2
- package/dist/esm/plugins/text-formatting/pm-plugins/smart-input-rule.js +0 -169
- package/dist/esm/plugins/text-formatting/ui/Toolbar/constants.js +0 -8
- package/dist/esm/plugins/text-formatting/ui/Toolbar/dropdown-menu.js +0 -75
- package/dist/esm/plugins/text-formatting/ui/Toolbar/hooks/clear-formatting-icon.js +0 -45
- package/dist/esm/plugins/text-formatting/ui/Toolbar/hooks/formatting-icons.js +0 -213
- package/dist/esm/plugins/text-formatting/ui/Toolbar/hooks/menu-state.js +0 -15
- package/dist/esm/plugins/text-formatting/ui/Toolbar/hooks/responsive-toolbar-buttons.js +0 -50
- package/dist/esm/plugins/text-formatting/ui/Toolbar/index.js +0 -191
- package/dist/esm/plugins/text-formatting/ui/Toolbar/more-button.js +0 -31
- package/dist/esm/plugins/text-formatting/ui/Toolbar/single-toolbar-buttons.js +0 -35
- package/dist/esm/plugins/text-formatting/ui/Toolbar/types.js +0 -10
- package/dist/esm/plugins/text-formatting/utils/cell-selection.js +0 -5
- package/dist/esm/plugins/text-formatting/utils.js +0 -75
- package/dist/types/plugins/text-formatting/actions.d.ts +0 -22
- package/dist/types/plugins/text-formatting/commands/clear-formatting.d.ts +0 -6
- package/dist/types/plugins/text-formatting/commands/text-formatting.d.ts +0 -5
- package/dist/types/plugins/text-formatting/commands/transform-to-code.d.ts +0 -2
- package/dist/types/plugins/text-formatting/index.d.ts +0 -17
- package/dist/types/plugins/text-formatting/pm-plugins/clear-formatting-keymap.d.ts +0 -4
- package/dist/types/plugins/text-formatting/pm-plugins/clear-formatting.d.ts +0 -8
- package/dist/types/plugins/text-formatting/pm-plugins/cursor.d.ts +0 -3
- package/dist/types/plugins/text-formatting/pm-plugins/input-rule.d.ts +0 -24
- package/dist/types/plugins/text-formatting/pm-plugins/keymap.d.ts +0 -4
- package/dist/types/plugins/text-formatting/pm-plugins/main.d.ts +0 -7
- package/dist/types/plugins/text-formatting/pm-plugins/plugin-key.d.ts +0 -3
- package/dist/types/plugins/text-formatting/pm-plugins/smart-input-rule.d.ts +0 -3
- package/dist/types/plugins/text-formatting/ui/Toolbar/constants.d.ts +0 -6
- package/dist/types/plugins/text-formatting/ui/Toolbar/dropdown-menu.d.ts +0 -15
- package/dist/types/plugins/text-formatting/ui/Toolbar/hooks/clear-formatting-icon.d.ts +0 -7
- package/dist/types/plugins/text-formatting/ui/Toolbar/hooks/formatting-icons.d.ts +0 -14
- package/dist/types/plugins/text-formatting/ui/Toolbar/hooks/menu-state.d.ts +0 -1
- package/dist/types/plugins/text-formatting/ui/Toolbar/hooks/responsive-toolbar-buttons.d.ts +0 -20
- package/dist/types/plugins/text-formatting/ui/Toolbar/index.d.ts +0 -26
- package/dist/types/plugins/text-formatting/ui/Toolbar/more-button.d.ts +0 -13
- package/dist/types/plugins/text-formatting/ui/Toolbar/single-toolbar-buttons.d.ts +0 -9
- package/dist/types/plugins/text-formatting/ui/Toolbar/types.d.ts +0 -32
- package/dist/types/plugins/text-formatting/utils/cell-selection.d.ts +0 -3
- package/dist/types/plugins/text-formatting/utils.d.ts +0 -11
- package/dist/types-ts4.5/plugins/text-formatting/actions.d.ts +0 -22
- package/dist/types-ts4.5/plugins/text-formatting/commands/clear-formatting.d.ts +0 -6
- package/dist/types-ts4.5/plugins/text-formatting/commands/text-formatting.d.ts +0 -5
- package/dist/types-ts4.5/plugins/text-formatting/commands/transform-to-code.d.ts +0 -2
- package/dist/types-ts4.5/plugins/text-formatting/index.d.ts +0 -19
- package/dist/types-ts4.5/plugins/text-formatting/pm-plugins/clear-formatting-keymap.d.ts +0 -4
- package/dist/types-ts4.5/plugins/text-formatting/pm-plugins/clear-formatting.d.ts +0 -8
- package/dist/types-ts4.5/plugins/text-formatting/pm-plugins/cursor.d.ts +0 -3
- package/dist/types-ts4.5/plugins/text-formatting/pm-plugins/input-rule.d.ts +0 -24
- package/dist/types-ts4.5/plugins/text-formatting/pm-plugins/keymap.d.ts +0 -4
- package/dist/types-ts4.5/plugins/text-formatting/pm-plugins/main.d.ts +0 -7
- package/dist/types-ts4.5/plugins/text-formatting/pm-plugins/plugin-key.d.ts +0 -3
- package/dist/types-ts4.5/plugins/text-formatting/pm-plugins/smart-input-rule.d.ts +0 -3
- package/dist/types-ts4.5/plugins/text-formatting/ui/Toolbar/constants.d.ts +0 -6
- package/dist/types-ts4.5/plugins/text-formatting/ui/Toolbar/dropdown-menu.d.ts +0 -15
- package/dist/types-ts4.5/plugins/text-formatting/ui/Toolbar/hooks/clear-formatting-icon.d.ts +0 -7
- package/dist/types-ts4.5/plugins/text-formatting/ui/Toolbar/hooks/formatting-icons.d.ts +0 -14
- package/dist/types-ts4.5/plugins/text-formatting/ui/Toolbar/hooks/menu-state.d.ts +0 -5
- package/dist/types-ts4.5/plugins/text-formatting/ui/Toolbar/hooks/responsive-toolbar-buttons.d.ts +0 -20
- package/dist/types-ts4.5/plugins/text-formatting/ui/Toolbar/index.d.ts +0 -26
- package/dist/types-ts4.5/plugins/text-formatting/ui/Toolbar/more-button.d.ts +0 -13
- package/dist/types-ts4.5/plugins/text-formatting/ui/Toolbar/single-toolbar-buttons.d.ts +0 -9
- package/dist/types-ts4.5/plugins/text-formatting/ui/Toolbar/types.d.ts +0 -32
- package/dist/types-ts4.5/plugins/text-formatting/utils/cell-selection.d.ts +0 -3
- package/dist/types-ts4.5/plugins/text-formatting/utils.d.ts +0 -11
|
@@ -1,28 +0,0 @@
|
|
|
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
|
-
};
|
|
@@ -1,48 +0,0 @@
|
|
|
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
|
-
});
|
|
@@ -1,259 +0,0 @@
|
|
|
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 { createRule, createPlugin, leafNodeReplacementCharacter } from '@atlaskit/prosemirror-input-rules';
|
|
14
|
-
import { ACTION, ACTION_SUBJECT, ACTION_SUBJECT_ID, EVENT_TYPE, INPUT_METHOD } from '@atlaskit/editor-common/analytics';
|
|
15
|
-
import { transformSmartCharsMentionsAndEmojis } from '@atlaskit/editor-common/mark';
|
|
16
|
-
import { inputRuleWithAnalytics } from '@atlaskit/editor-common/utils';
|
|
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,
|
|
239
|
-
// Don't remove the unused featureFlags, this gets used to test if we're properly passing them to the PM plugin
|
|
240
|
-
_featureFlags, editorAnalyticsAPI) {
|
|
241
|
-
var rules = [];
|
|
242
|
-
if (schema.marks.strong) {
|
|
243
|
-
rules.push.apply(rules, _toConsumableArray(getStrongInputRules(schema, editorAnalyticsAPI)));
|
|
244
|
-
}
|
|
245
|
-
if (schema.marks.em) {
|
|
246
|
-
rules.push.apply(rules, _toConsumableArray(getItalicInputRules(schema, editorAnalyticsAPI)));
|
|
247
|
-
}
|
|
248
|
-
if (schema.marks.strike) {
|
|
249
|
-
rules.push.apply(rules, _toConsumableArray(getStrikeInputRules(schema, editorAnalyticsAPI)));
|
|
250
|
-
}
|
|
251
|
-
if (schema.marks.code) {
|
|
252
|
-
rules.push.apply(rules, _toConsumableArray(getCodeInputRules(schema, editorAnalyticsAPI)));
|
|
253
|
-
}
|
|
254
|
-
if (rules.length !== 0) {
|
|
255
|
-
return createPlugin('text-formatting', rules);
|
|
256
|
-
}
|
|
257
|
-
return;
|
|
258
|
-
}
|
|
259
|
-
export default inputRulePlugin;
|
|
@@ -1,43 +0,0 @@
|
|
|
1
|
-
import * as keymaps from '@atlaskit/editor-common/keymaps';
|
|
2
|
-
import { keymap } from '@atlaskit/editor-prosemirror/keymap';
|
|
3
|
-
import { INPUT_METHOD } from '@atlaskit/editor-common/analytics';
|
|
4
|
-
import { toggleStrongWithAnalytics, toggleEmWithAnalytics, toggleCodeWithAnalytics, toggleStrikeWithAnalytics, toggleSubscriptWithAnalytics, toggleSuperscriptWithAnalytics, toggleUnderlineWithAnalytics } from '../actions';
|
|
5
|
-
export default function keymapPlugin(schema, editorAnalyticsAPI) {
|
|
6
|
-
var list = {};
|
|
7
|
-
if (schema.marks.strong) {
|
|
8
|
-
keymaps.bindKeymapWithCommand(keymaps.toggleBold.common, toggleStrongWithAnalytics(editorAnalyticsAPI)({
|
|
9
|
-
inputMethod: INPUT_METHOD.SHORTCUT
|
|
10
|
-
}), list);
|
|
11
|
-
}
|
|
12
|
-
if (schema.marks.em) {
|
|
13
|
-
keymaps.bindKeymapWithCommand(keymaps.toggleItalic.common, toggleEmWithAnalytics(editorAnalyticsAPI)({
|
|
14
|
-
inputMethod: INPUT_METHOD.SHORTCUT
|
|
15
|
-
}), list);
|
|
16
|
-
}
|
|
17
|
-
if (schema.marks.code) {
|
|
18
|
-
keymaps.bindKeymapWithCommand(keymaps.toggleCode.common, toggleCodeWithAnalytics(editorAnalyticsAPI)({
|
|
19
|
-
inputMethod: INPUT_METHOD.SHORTCUT
|
|
20
|
-
}), list);
|
|
21
|
-
}
|
|
22
|
-
if (schema.marks.strike) {
|
|
23
|
-
keymaps.bindKeymapWithCommand(keymaps.toggleStrikethrough.common, toggleStrikeWithAnalytics(editorAnalyticsAPI)({
|
|
24
|
-
inputMethod: INPUT_METHOD.SHORTCUT
|
|
25
|
-
}), list);
|
|
26
|
-
}
|
|
27
|
-
if (schema.marks.subsup) {
|
|
28
|
-
keymaps.bindKeymapWithCommand(keymaps.toggleSubscript.common, toggleSubscriptWithAnalytics(editorAnalyticsAPI)({
|
|
29
|
-
inputMethod: INPUT_METHOD.SHORTCUT
|
|
30
|
-
}), list);
|
|
31
|
-
}
|
|
32
|
-
if (schema.marks.subsup) {
|
|
33
|
-
keymaps.bindKeymapWithCommand(keymaps.toggleSuperscript.common, toggleSuperscriptWithAnalytics(editorAnalyticsAPI)({
|
|
34
|
-
inputMethod: INPUT_METHOD.SHORTCUT
|
|
35
|
-
}), list);
|
|
36
|
-
}
|
|
37
|
-
if (schema.marks.underline) {
|
|
38
|
-
keymaps.bindKeymapWithCommand(keymaps.toggleUnderline.common, toggleUnderlineWithAnalytics(editorAnalyticsAPI)({
|
|
39
|
-
inputMethod: INPUT_METHOD.SHORTCUT
|
|
40
|
-
}), list);
|
|
41
|
-
}
|
|
42
|
-
return keymap(list);
|
|
43
|
-
}
|
|
@@ -1,98 +0,0 @@
|
|
|
1
|
-
// TODO: Ideally this should use the custom toggleMark function from @atlaskit/editor-common so we also disable the options when selecting inline nodes but it disables the marks when the selection is empty at this point in time which is undesirable
|
|
2
|
-
// import { toggleMark } from '@atlaskit/editor-common/mark';
|
|
3
|
-
import { toggleMark } from '@atlaskit/editor-prosemirror/commands';
|
|
4
|
-
import { SafePlugin } from '@atlaskit/editor-common/safe-plugin';
|
|
5
|
-
import * as keymaps from '@atlaskit/editor-common/keymaps';
|
|
6
|
-
import { shallowEqual } from '@atlaskit/editor-common/utils';
|
|
7
|
-
import { createInlineCodeFromTextInputWithAnalytics } from '../commands/text-formatting';
|
|
8
|
-
import * as commands from '../commands/text-formatting';
|
|
9
|
-
import { anyMarkActive } from '@atlaskit/editor-common/mark';
|
|
10
|
-
import { pluginKey } from './plugin-key';
|
|
11
|
-
export { pluginKey };
|
|
12
|
-
var getTextFormattingState = function getTextFormattingState(editorState, editorAnalyticsAPI) {
|
|
13
|
-
var _editorState$schema$m = editorState.schema.marks,
|
|
14
|
-
em = _editorState$schema$m.em,
|
|
15
|
-
code = _editorState$schema$m.code,
|
|
16
|
-
strike = _editorState$schema$m.strike,
|
|
17
|
-
strong = _editorState$schema$m.strong,
|
|
18
|
-
subsup = _editorState$schema$m.subsup,
|
|
19
|
-
underline = _editorState$schema$m.underline;
|
|
20
|
-
var state = {};
|
|
21
|
-
if (code) {
|
|
22
|
-
state.codeActive = anyMarkActive(editorState, code.create());
|
|
23
|
-
state.codeDisabled = !toggleMark(code)(editorState);
|
|
24
|
-
}
|
|
25
|
-
if (em) {
|
|
26
|
-
state.emActive = anyMarkActive(editorState, em);
|
|
27
|
-
state.emDisabled = state.codeActive ? true : !toggleMark(em)(editorState);
|
|
28
|
-
}
|
|
29
|
-
if (strike) {
|
|
30
|
-
state.strikeActive = anyMarkActive(editorState, strike);
|
|
31
|
-
state.strikeDisabled = state.codeActive ? true : !toggleMark(strike)(editorState);
|
|
32
|
-
}
|
|
33
|
-
if (strong) {
|
|
34
|
-
state.strongActive = anyMarkActive(editorState, strong);
|
|
35
|
-
state.strongDisabled = state.codeActive ? true : !toggleMark(strong)(editorState);
|
|
36
|
-
}
|
|
37
|
-
if (subsup) {
|
|
38
|
-
var subMark = subsup.create({
|
|
39
|
-
type: 'sub'
|
|
40
|
-
});
|
|
41
|
-
var supMark = subsup.create({
|
|
42
|
-
type: 'sup'
|
|
43
|
-
});
|
|
44
|
-
state.subscriptActive = anyMarkActive(editorState, subMark);
|
|
45
|
-
state.subscriptDisabled = state.codeActive ? true : !toggleMark(subsup, {
|
|
46
|
-
type: 'sub'
|
|
47
|
-
})(editorState);
|
|
48
|
-
state.superscriptActive = anyMarkActive(editorState, supMark);
|
|
49
|
-
state.superscriptDisabled = state.codeActive ? true : !toggleMark(subsup, {
|
|
50
|
-
type: 'sup'
|
|
51
|
-
})(editorState);
|
|
52
|
-
}
|
|
53
|
-
if (underline) {
|
|
54
|
-
state.underlineActive = anyMarkActive(editorState, underline);
|
|
55
|
-
state.underlineDisabled = state.codeActive ? true : !toggleMark(underline)(editorState);
|
|
56
|
-
}
|
|
57
|
-
return state;
|
|
58
|
-
};
|
|
59
|
-
export var plugin = function plugin(dispatch, editorAnalyticsAPI) {
|
|
60
|
-
return new SafePlugin({
|
|
61
|
-
state: {
|
|
62
|
-
init: function init(_config, state) {
|
|
63
|
-
return getTextFormattingState(state, editorAnalyticsAPI);
|
|
64
|
-
},
|
|
65
|
-
apply: function apply(_tr, pluginState, _oldState, newState) {
|
|
66
|
-
var state = getTextFormattingState(newState, editorAnalyticsAPI);
|
|
67
|
-
if (!shallowEqual(pluginState, state)) {
|
|
68
|
-
dispatch(pluginKey, state);
|
|
69
|
-
return state;
|
|
70
|
-
}
|
|
71
|
-
return pluginState;
|
|
72
|
-
}
|
|
73
|
-
},
|
|
74
|
-
key: pluginKey,
|
|
75
|
-
props: {
|
|
76
|
-
handleKeyDown: function handleKeyDown(view, event) {
|
|
77
|
-
var state = view.state,
|
|
78
|
-
dispatch = view.dispatch;
|
|
79
|
-
if (event.key === keymaps.moveRight.common && !event.metaKey) {
|
|
80
|
-
return commands.moveRight()(state, dispatch);
|
|
81
|
-
} else if (event.key === keymaps.moveLeft.common && !event.metaKey) {
|
|
82
|
-
return commands.moveLeft()(state, dispatch);
|
|
83
|
-
}
|
|
84
|
-
return false;
|
|
85
|
-
},
|
|
86
|
-
handleTextInput: function handleTextInput(view, from, to, text) {
|
|
87
|
-
var state = view.state,
|
|
88
|
-
dispatch = view.dispatch;
|
|
89
|
-
var schema = state.schema,
|
|
90
|
-
parentNodeType = state.selection.$from.parent.type;
|
|
91
|
-
if (parentNodeType.allowsMarkType(schema.marks.code)) {
|
|
92
|
-
return createInlineCodeFromTextInputWithAnalytics(editorAnalyticsAPI)(from, to, text)(state, dispatch);
|
|
93
|
-
}
|
|
94
|
-
return false;
|
|
95
|
-
}
|
|
96
|
-
}
|
|
97
|
-
});
|
|
98
|
-
};
|
|
@@ -1,169 +0,0 @@
|
|
|
1
|
-
import _toConsumableArray from "@babel/runtime/helpers/toConsumableArray";
|
|
2
|
-
import _defineProperty from "@babel/runtime/helpers/defineProperty";
|
|
3
|
-
import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
|
|
4
|
-
import { Selection } from '@atlaskit/editor-prosemirror/state';
|
|
5
|
-
import { createRule, createPlugin } from '@atlaskit/prosemirror-input-rules';
|
|
6
|
-
import { ACTION, ACTION_SUBJECT, ACTION_SUBJECT_ID, EVENT_TYPE, PUNC, SYMBOL } from '@atlaskit/editor-common/analytics';
|
|
7
|
-
import { inputRuleWithAnalytics } from '@atlaskit/editor-common/utils';
|
|
8
|
-
|
|
9
|
-
/**
|
|
10
|
-
* Creates an InputRuleHandler that will match on a regular expression of the
|
|
11
|
-
* form `(prefix, content, suffix?)`, and replace it with some given text,
|
|
12
|
-
* maintaining prefix and suffix around the replacement.
|
|
13
|
-
*
|
|
14
|
-
* @param text text to replace with
|
|
15
|
-
*/
|
|
16
|
-
function replaceTextUsingCaptureGroup(text) {
|
|
17
|
-
return function (state, match, start, end) {
|
|
18
|
-
var _match = _slicedToArray(match, 4),
|
|
19
|
-
prefix = _match[1],
|
|
20
|
-
suffix = _match[3];
|
|
21
|
-
var replacement = text + (suffix || '');
|
|
22
|
-
var tr = state.tr,
|
|
23
|
-
$to = state.selection.$to;
|
|
24
|
-
var startPos = start + (prefix || '').length;
|
|
25
|
-
var safePos = Math.min(
|
|
26
|
-
// I know it is almost impossible to have a negative value at this point.
|
|
27
|
-
// But, this is JS #trustnoone
|
|
28
|
-
Math.max(startPos, 0), end);
|
|
29
|
-
tr.replaceWith(safePos, end, state.schema.text(replacement, $to.marks()));
|
|
30
|
-
tr.setSelection(Selection.near(tr.doc.resolve(tr.selection.to)));
|
|
31
|
-
return tr;
|
|
32
|
-
};
|
|
33
|
-
}
|
|
34
|
-
function createReplacementRule(to, from) {
|
|
35
|
-
return createRule(from, replaceTextUsingCaptureGroup(to));
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
/**
|
|
39
|
-
* Create replacement rules fiven a replacement map
|
|
40
|
-
* @param replMap - Replacement map
|
|
41
|
-
* @param trackingEventName - Analytics V2 tracking event name
|
|
42
|
-
* @param replacementRuleWithAnalytics - Analytics GAS V3 middleware for replacement and rules.
|
|
43
|
-
*/
|
|
44
|
-
function createReplacementRules(replMap, replacementRuleWithAnalytics) {
|
|
45
|
-
return Object.keys(replMap).map(function (replacement) {
|
|
46
|
-
var regex = replMap[replacement];
|
|
47
|
-
var rule = createReplacementRule(replacement, regex);
|
|
48
|
-
if (replacementRuleWithAnalytics) {
|
|
49
|
-
return replacementRuleWithAnalytics(replacement)(rule);
|
|
50
|
-
}
|
|
51
|
-
return rule;
|
|
52
|
-
});
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
// We don't agressively upgrade single quotes to smart quotes because
|
|
56
|
-
// they may clash with an emoji. Only do that when we have a matching
|
|
57
|
-
// single quote, or a contraction.
|
|
58
|
-
function createSingleQuotesRules() {
|
|
59
|
-
return [
|
|
60
|
-
// wrapped text
|
|
61
|
-
createRule(/(\s|^)'(\S+.*\S+)'$/, function (state, match, start, end) {
|
|
62
|
-
var OPEN_SMART_QUOTE_CHAR = '‘';
|
|
63
|
-
var CLOSED_SMART_QUOTE_CHAR = '’';
|
|
64
|
-
var _match2 = _slicedToArray(match, 3),
|
|
65
|
-
spacing = _match2[1],
|
|
66
|
-
innerContent = _match2[2];
|
|
67
|
-
// Edge case where match begins with some spacing. We need to add
|
|
68
|
-
// it back to the document
|
|
69
|
-
var openQuoteReplacement = spacing + OPEN_SMART_QUOTE_CHAR;
|
|
70
|
-
// End is not always where the closed quote is, edge case exists
|
|
71
|
-
// when there is spacing after the closed quote. We need to
|
|
72
|
-
// determine position of closed quote from the start position.
|
|
73
|
-
var positionOfClosedQuote = start + openQuoteReplacement.length + innerContent.length;
|
|
74
|
-
return state.tr.insertText(CLOSED_SMART_QUOTE_CHAR, positionOfClosedQuote, end).insertText(openQuoteReplacement, start, start + openQuoteReplacement.length);
|
|
75
|
-
}),
|
|
76
|
-
// apostrophe
|
|
77
|
-
createReplacementRule('’', /(\w+)(')(\w+)$/)];
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
/**
|
|
81
|
-
* Get replacement rules related to product
|
|
82
|
-
*/
|
|
83
|
-
function getProductRules(editorAnalyticsAPI) {
|
|
84
|
-
var productRuleWithAnalytics = function productRuleWithAnalytics(product) {
|
|
85
|
-
return inputRuleWithAnalytics(function (_, match) {
|
|
86
|
-
return {
|
|
87
|
-
action: ACTION.SUBSTITUTED,
|
|
88
|
-
actionSubject: ACTION_SUBJECT.TEXT,
|
|
89
|
-
actionSubjectId: ACTION_SUBJECT_ID.PRODUCT_NAME,
|
|
90
|
-
eventType: EVENT_TYPE.TRACK,
|
|
91
|
-
attributes: {
|
|
92
|
-
product: product,
|
|
93
|
-
originalSpelling: match[2]
|
|
94
|
-
}
|
|
95
|
-
};
|
|
96
|
-
}, editorAnalyticsAPI);
|
|
97
|
-
};
|
|
98
|
-
return createReplacementRules({
|
|
99
|
-
Atlassian: /(\s+|^)(atlassian)(\s)$/,
|
|
100
|
-
Jira: /(\s+|^)(jira|JIRA)(\s)$/,
|
|
101
|
-
Bitbucket: /(\s+|^)(bitbucket|BitBucket)(\s)$/,
|
|
102
|
-
Hipchat: /(\s+|^)(hipchat|HipChat)(\s)$/,
|
|
103
|
-
Trello: /(\s+|^)(trello)(\s)$/
|
|
104
|
-
}, productRuleWithAnalytics);
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
/**
|
|
108
|
-
* Get replacement rules related to symbol
|
|
109
|
-
*/
|
|
110
|
-
function getSymbolRules(editorAnalyticsAPI) {
|
|
111
|
-
var symbolToString = {
|
|
112
|
-
'→': SYMBOL.ARROW_RIGHT,
|
|
113
|
-
'←': SYMBOL.ARROW_LEFT,
|
|
114
|
-
'↔︎': SYMBOL.ARROW_DOUBLE
|
|
115
|
-
};
|
|
116
|
-
var symbolRuleWithAnalytics = function symbolRuleWithAnalytics(symbol) {
|
|
117
|
-
return inputRuleWithAnalytics({
|
|
118
|
-
action: ACTION.SUBSTITUTED,
|
|
119
|
-
actionSubject: ACTION_SUBJECT.TEXT,
|
|
120
|
-
actionSubjectId: ACTION_SUBJECT_ID.SYMBOL,
|
|
121
|
-
eventType: EVENT_TYPE.TRACK,
|
|
122
|
-
attributes: {
|
|
123
|
-
symbol: symbolToString[symbol]
|
|
124
|
-
}
|
|
125
|
-
}, editorAnalyticsAPI);
|
|
126
|
-
};
|
|
127
|
-
return createReplacementRules({
|
|
128
|
-
'→': /(\s+|^)(--?>)(\s)$/,
|
|
129
|
-
'←': /(\s+|^)(<--?)(\s)$/,
|
|
130
|
-
'↔︎': /(\s+|^)(<->?)(\s)$/
|
|
131
|
-
}, symbolRuleWithAnalytics);
|
|
132
|
-
}
|
|
133
|
-
|
|
134
|
-
/**
|
|
135
|
-
* Get replacement rules related to punctuation
|
|
136
|
-
*/
|
|
137
|
-
function getPunctuationRules(editorAnalyticsAPI) {
|
|
138
|
-
var punctuationToString = _defineProperty({
|
|
139
|
-
'–': PUNC.DASH,
|
|
140
|
-
'…': PUNC.ELLIPSIS,
|
|
141
|
-
'”': PUNC.QUOTE_DOUBLE
|
|
142
|
-
}, PUNC.QUOTE_SINGLE, PUNC.QUOTE_SINGLE);
|
|
143
|
-
var punctuationRuleWithAnalytics = function punctuationRuleWithAnalytics(punctuation) {
|
|
144
|
-
return inputRuleWithAnalytics({
|
|
145
|
-
action: ACTION.SUBSTITUTED,
|
|
146
|
-
actionSubject: ACTION_SUBJECT.TEXT,
|
|
147
|
-
actionSubjectId: ACTION_SUBJECT_ID.PUNC,
|
|
148
|
-
eventType: EVENT_TYPE.TRACK,
|
|
149
|
-
attributes: {
|
|
150
|
-
punctuation: punctuationToString[punctuation]
|
|
151
|
-
}
|
|
152
|
-
}, editorAnalyticsAPI);
|
|
153
|
-
};
|
|
154
|
-
var dashEllipsisRules = createReplacementRules({
|
|
155
|
-
'–': /(\s+|^)(--)(\s)$/,
|
|
156
|
-
'…': /()(\.\.\.)$/
|
|
157
|
-
}, punctuationRuleWithAnalytics);
|
|
158
|
-
var doubleQuoteRules = createReplacementRules({
|
|
159
|
-
'“': /((?:^|[\s\{\[\(\<'"\u2018\u201C]))(")$/,
|
|
160
|
-
'”': /"$/
|
|
161
|
-
}, punctuationRuleWithAnalytics);
|
|
162
|
-
var singleQuoteRules = createSingleQuotesRules();
|
|
163
|
-
return [].concat(_toConsumableArray(dashEllipsisRules), _toConsumableArray(doubleQuoteRules), _toConsumableArray(singleQuoteRules.map(function (rule) {
|
|
164
|
-
return punctuationRuleWithAnalytics(PUNC.QUOTE_SINGLE)(rule);
|
|
165
|
-
})));
|
|
166
|
-
}
|
|
167
|
-
export default (function (editorAnalyticsAPI) {
|
|
168
|
-
return createPlugin('text-formatting:smart-input', [].concat(_toConsumableArray(getProductRules(editorAnalyticsAPI)), _toConsumableArray(getSymbolRules(editorAnalyticsAPI)), _toConsumableArray(getPunctuationRules(editorAnalyticsAPI))));
|
|
169
|
-
});
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
import _defineProperty from "@babel/runtime/helpers/defineProperty";
|
|
2
|
-
var _ResponsiveCustomButt, _ResponsiveCustomMenu;
|
|
3
|
-
import { ToolbarSize } from '@atlaskit/editor-common/types';
|
|
4
|
-
import { IconTypes } from './types';
|
|
5
|
-
export var DefaultButtonsToolbar = [IconTypes.strong, IconTypes.em];
|
|
6
|
-
export var DefaultButtonsMenu = [IconTypes.underline, IconTypes.strike, IconTypes.code, IconTypes.subscript, IconTypes.superscript];
|
|
7
|
-
export var ResponsiveCustomButtonToolbar = (_ResponsiveCustomButt = {}, _defineProperty(_ResponsiveCustomButt, ToolbarSize.XXL, DefaultButtonsToolbar), _defineProperty(_ResponsiveCustomButt, ToolbarSize.XL, DefaultButtonsToolbar), _defineProperty(_ResponsiveCustomButt, ToolbarSize.L, DefaultButtonsToolbar), _defineProperty(_ResponsiveCustomButt, ToolbarSize.M, []), _defineProperty(_ResponsiveCustomButt, ToolbarSize.S, []), _defineProperty(_ResponsiveCustomButt, ToolbarSize.XXXS, []), _ResponsiveCustomButt);
|
|
8
|
-
export var ResponsiveCustomMenu = (_ResponsiveCustomMenu = {}, _defineProperty(_ResponsiveCustomMenu, ToolbarSize.XXL, DefaultButtonsMenu), _defineProperty(_ResponsiveCustomMenu, ToolbarSize.XL, DefaultButtonsMenu), _defineProperty(_ResponsiveCustomMenu, ToolbarSize.L, DefaultButtonsMenu), _defineProperty(_ResponsiveCustomMenu, ToolbarSize.M, [IconTypes.strong, IconTypes.em].concat(DefaultButtonsMenu)), _defineProperty(_ResponsiveCustomMenu, ToolbarSize.S, [IconTypes.strong, IconTypes.em].concat(DefaultButtonsMenu)), _defineProperty(_ResponsiveCustomMenu, ToolbarSize.XXXS, [IconTypes.strong, IconTypes.em].concat(DefaultButtonsMenu)), _ResponsiveCustomMenu);
|