@atlaskit/editor-core 189.3.3 → 189.3.6
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 +15 -0
- package/dist/cjs/plugins/index.js +0 -7
- package/dist/cjs/presets/default.js +2 -2
- package/dist/cjs/utils/deprecation-warnings.js +1 -3
- package/dist/cjs/utils/editorDeprecationWarnings.js +2 -4
- package/dist/cjs/version-wrapper.js +2 -5
- package/dist/es2019/plugins/index.js +0 -1
- package/dist/es2019/presets/default.js +1 -1
- package/dist/es2019/utils/deprecation-warnings.js +1 -3
- package/dist/es2019/utils/editorDeprecationWarnings.js +2 -4
- package/dist/es2019/version-wrapper.js +1 -4
- package/dist/esm/plugins/index.js +0 -1
- package/dist/esm/presets/default.js +1 -1
- package/dist/esm/utils/deprecation-warnings.js +1 -3
- package/dist/esm/utils/editorDeprecationWarnings.js +2 -4
- package/dist/esm/version-wrapper.js +1 -4
- package/dist/types/plugins/index.d.ts +0 -1
- package/dist/types/plugins/insert-block/types.d.ts +1 -1
- package/dist/types/presets/default.d.ts +1 -1
- package/dist/types/types/editor-props.d.ts +1 -1
- package/dist/types/ui/Appearance/FullPage/StyledComponents.d.ts +1 -1
- package/dist/types/ui/ContentStyles/index.d.ts +2 -2
- package/dist/types/version-wrapper.d.ts +0 -1
- package/dist/types-ts4.5/plugins/index.d.ts +0 -1
- package/dist/types-ts4.5/plugins/insert-block/types.d.ts +1 -1
- package/dist/types-ts4.5/presets/default.d.ts +1 -1
- package/dist/types-ts4.5/types/editor-props.d.ts +1 -1
- package/dist/types-ts4.5/ui/Appearance/FullPage/StyledComponents.d.ts +1 -1
- package/dist/types-ts4.5/ui/ContentStyles/index.d.ts +2 -2
- package/dist/types-ts4.5/version-wrapper.d.ts +0 -1
- package/package.json +4 -3
- package/report.api.md +1 -11
- package/tmp/api-report-tmp.d.ts +1 -11
- package/dist/cjs/plugins/code-block/actions.js +0 -201
- package/dist/cjs/plugins/code-block/ide-ux/bracket-handling.js +0 -35
- package/dist/cjs/plugins/code-block/ide-ux/commands.js +0 -115
- package/dist/cjs/plugins/code-block/ide-ux/line-handling.js +0 -81
- package/dist/cjs/plugins/code-block/ide-ux/paired-character-handling.js +0 -23
- package/dist/cjs/plugins/code-block/ide-ux/quote-handling.js +0 -40
- package/dist/cjs/plugins/code-block/index.js +0 -120
- package/dist/cjs/plugins/code-block/language-list.js +0 -62
- package/dist/cjs/plugins/code-block/nodeviews/code-block.js +0 -153
- package/dist/cjs/plugins/code-block/plugin-key.js +0 -8
- package/dist/cjs/plugins/code-block/pm-plugins/actions.js +0 -10
- package/dist/cjs/plugins/code-block/pm-plugins/codeBlockCopySelectionPlugin.js +0 -113
- package/dist/cjs/plugins/code-block/pm-plugins/ide-ux.js +0 -132
- package/dist/cjs/plugins/code-block/pm-plugins/input-rule.js +0 -68
- package/dist/cjs/plugins/code-block/pm-plugins/keymaps.js +0 -66
- package/dist/cjs/plugins/code-block/pm-plugins/main-state.js +0 -10
- package/dist/cjs/plugins/code-block/pm-plugins/main.js +0 -114
- package/dist/cjs/plugins/code-block/refresh-browser-selection.js +0 -29
- package/dist/cjs/plugins/code-block/toolbar.js +0 -131
- package/dist/cjs/plugins/code-block/transform-to-code-block.js +0 -84
- package/dist/cjs/plugins/code-block/types.js +0 -5
- package/dist/cjs/plugins/code-block/ui/class-names.js +0 -15
- package/dist/cjs/plugins/code-block/utils.js +0 -28
- package/dist/es2019/plugins/code-block/actions.js +0 -211
- package/dist/es2019/plugins/code-block/ide-ux/bracket-handling.js +0 -27
- package/dist/es2019/plugins/code-block/ide-ux/commands.js +0 -114
- package/dist/es2019/plugins/code-block/ide-ux/line-handling.js +0 -75
- package/dist/es2019/plugins/code-block/ide-ux/paired-character-handling.js +0 -12
- package/dist/es2019/plugins/code-block/ide-ux/quote-handling.js +0 -32
- package/dist/es2019/plugins/code-block/index.js +0 -104
- package/dist/es2019/plugins/code-block/language-list.js +0 -51
- package/dist/es2019/plugins/code-block/nodeviews/code-block.js +0 -126
- package/dist/es2019/plugins/code-block/plugin-key.js +0 -2
- package/dist/es2019/plugins/code-block/pm-plugins/actions.js +0 -4
- package/dist/es2019/plugins/code-block/pm-plugins/codeBlockCopySelectionPlugin.js +0 -101
- package/dist/es2019/plugins/code-block/pm-plugins/ide-ux.js +0 -135
- package/dist/es2019/plugins/code-block/pm-plugins/input-rule.js +0 -60
- package/dist/es2019/plugins/code-block/pm-plugins/keymaps.js +0 -58
- package/dist/es2019/plugins/code-block/pm-plugins/main-state.js +0 -2
- package/dist/es2019/plugins/code-block/pm-plugins/main.js +0 -102
- package/dist/es2019/plugins/code-block/refresh-browser-selection.js +0 -25
- package/dist/es2019/plugins/code-block/toolbar.js +0 -108
- package/dist/es2019/plugins/code-block/transform-to-code-block.js +0 -79
- package/dist/es2019/plugins/code-block/types.js +0 -1
- package/dist/es2019/plugins/code-block/ui/class-names.js +0 -9
- package/dist/es2019/plugins/code-block/utils.js +0 -4
- package/dist/esm/plugins/code-block/actions.js +0 -191
- package/dist/esm/plugins/code-block/ide-ux/bracket-handling.js +0 -29
- package/dist/esm/plugins/code-block/ide-ux/commands.js +0 -106
- package/dist/esm/plugins/code-block/ide-ux/line-handling.js +0 -73
- package/dist/esm/plugins/code-block/ide-ux/paired-character-handling.js +0 -16
- package/dist/esm/plugins/code-block/ide-ux/quote-handling.js +0 -34
- package/dist/esm/plugins/code-block/index.js +0 -113
- package/dist/esm/plugins/code-block/language-list.js +0 -52
- package/dist/esm/plugins/code-block/nodeviews/code-block.js +0 -146
- package/dist/esm/plugins/code-block/plugin-key.js +0 -2
- package/dist/esm/plugins/code-block/pm-plugins/actions.js +0 -4
- package/dist/esm/plugins/code-block/pm-plugins/codeBlockCopySelectionPlugin.js +0 -103
- package/dist/esm/plugins/code-block/pm-plugins/ide-ux.js +0 -126
- package/dist/esm/plugins/code-block/pm-plugins/input-rule.js +0 -62
- package/dist/esm/plugins/code-block/pm-plugins/keymaps.js +0 -59
- package/dist/esm/plugins/code-block/pm-plugins/main-state.js +0 -4
- package/dist/esm/plugins/code-block/pm-plugins/main.js +0 -107
- package/dist/esm/plugins/code-block/refresh-browser-selection.js +0 -25
- package/dist/esm/plugins/code-block/toolbar.js +0 -121
- package/dist/esm/plugins/code-block/transform-to-code-block.js +0 -77
- package/dist/esm/plugins/code-block/types.js +0 -1
- package/dist/esm/plugins/code-block/ui/class-names.js +0 -9
- package/dist/esm/plugins/code-block/utils.js +0 -4
- package/dist/types/plugins/code-block/actions.d.ts +0 -18
- package/dist/types/plugins/code-block/ide-ux/bracket-handling.d.ts +0 -12
- package/dist/types/plugins/code-block/ide-ux/commands.d.ts +0 -7
- package/dist/types/plugins/code-block/ide-ux/line-handling.d.ts +0 -25
- package/dist/types/plugins/code-block/ide-ux/paired-character-handling.d.ts +0 -2
- package/dist/types/plugins/code-block/ide-ux/quote-handling.d.ts +0 -12
- package/dist/types/plugins/code-block/index.d.ts +0 -19
- package/dist/types/plugins/code-block/language-list.d.ts +0 -942
- package/dist/types/plugins/code-block/nodeviews/code-block.d.ts +0 -21
- package/dist/types/plugins/code-block/plugin-key.d.ts +0 -2
- package/dist/types/plugins/code-block/pm-plugins/actions.d.ts +0 -4
- package/dist/types/plugins/code-block/pm-plugins/codeBlockCopySelectionPlugin.d.ts +0 -11
- package/dist/types/plugins/code-block/pm-plugins/ide-ux.d.ts +0 -5
- package/dist/types/plugins/code-block/pm-plugins/input-rule.d.ts +0 -3
- package/dist/types/plugins/code-block/pm-plugins/keymaps.d.ts +0 -4
- package/dist/types/plugins/code-block/pm-plugins/main-state.d.ts +0 -8
- package/dist/types/plugins/code-block/pm-plugins/main.d.ts +0 -10
- package/dist/types/plugins/code-block/refresh-browser-selection.d.ts +0 -5
- package/dist/types/plugins/code-block/toolbar.d.ts +0 -14
- package/dist/types/plugins/code-block/transform-to-code-block.d.ts +0 -3
- package/dist/types/plugins/code-block/types.d.ts +0 -6
- package/dist/types/plugins/code-block/ui/class-names.d.ts +0 -8
- package/dist/types/plugins/code-block/utils.d.ts +0 -4
- package/dist/types-ts4.5/plugins/code-block/actions.d.ts +0 -18
- package/dist/types-ts4.5/plugins/code-block/ide-ux/bracket-handling.d.ts +0 -12
- package/dist/types-ts4.5/plugins/code-block/ide-ux/commands.d.ts +0 -7
- package/dist/types-ts4.5/plugins/code-block/ide-ux/line-handling.d.ts +0 -25
- package/dist/types-ts4.5/plugins/code-block/ide-ux/paired-character-handling.d.ts +0 -2
- package/dist/types-ts4.5/plugins/code-block/ide-ux/quote-handling.d.ts +0 -12
- package/dist/types-ts4.5/plugins/code-block/index.d.ts +0 -19
- package/dist/types-ts4.5/plugins/code-block/language-list.d.ts +0 -1641
- package/dist/types-ts4.5/plugins/code-block/nodeviews/code-block.d.ts +0 -21
- package/dist/types-ts4.5/plugins/code-block/plugin-key.d.ts +0 -2
- package/dist/types-ts4.5/plugins/code-block/pm-plugins/actions.d.ts +0 -4
- package/dist/types-ts4.5/plugins/code-block/pm-plugins/codeBlockCopySelectionPlugin.d.ts +0 -14
- package/dist/types-ts4.5/plugins/code-block/pm-plugins/ide-ux.d.ts +0 -5
- package/dist/types-ts4.5/plugins/code-block/pm-plugins/input-rule.d.ts +0 -3
- package/dist/types-ts4.5/plugins/code-block/pm-plugins/keymaps.d.ts +0 -4
- package/dist/types-ts4.5/plugins/code-block/pm-plugins/main-state.d.ts +0 -8
- package/dist/types-ts4.5/plugins/code-block/pm-plugins/main.d.ts +0 -10
- package/dist/types-ts4.5/plugins/code-block/refresh-browser-selection.d.ts +0 -5
- package/dist/types-ts4.5/plugins/code-block/toolbar.d.ts +0 -14
- package/dist/types-ts4.5/plugins/code-block/transform-to-code-block.d.ts +0 -3
- package/dist/types-ts4.5/plugins/code-block/types.d.ts +0 -6
- package/dist/types-ts4.5/plugins/code-block/ui/class-names.d.ts +0 -8
- package/dist/types-ts4.5/plugins/code-block/utils.d.ts +0 -4
|
@@ -1,113 +0,0 @@
|
|
|
1
|
-
import _defineProperty from "@babel/runtime/helpers/defineProperty";
|
|
2
|
-
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
3
|
-
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
4
|
-
import React from 'react';
|
|
5
|
-
import { codeBlock } from '@atlaskit/adf-schema';
|
|
6
|
-
import { createPlugin } from './pm-plugins/main';
|
|
7
|
-
import { getToolbarConfig } from './toolbar';
|
|
8
|
-
import keymap from './pm-plugins/keymaps';
|
|
9
|
-
import ideUX from './pm-plugins/ide-ux';
|
|
10
|
-
import { codeBlockCopySelectionPlugin } from './pm-plugins/codeBlockCopySelectionPlugin';
|
|
11
|
-
import { ACTION, ACTION_SUBJECT, ACTION_SUBJECT_ID, INPUT_METHOD, EVENT_TYPE } from '@atlaskit/editor-common/analytics';
|
|
12
|
-
import { IconCode } from '@atlaskit/editor-common/quick-insert';
|
|
13
|
-
import { blockTypeMessages } from '@atlaskit/editor-common/messages';
|
|
14
|
-
import refreshBrowserSelectionOnChange from './refresh-browser-selection';
|
|
15
|
-
import { createInsertCodeBlockTransaction, insertCodeBlockWithAnalytics } from './actions';
|
|
16
|
-
import { createCodeBlockInputRule } from './pm-plugins/input-rule';
|
|
17
|
-
var codeBlockPlugin = function codeBlockPlugin(_ref) {
|
|
18
|
-
var options = _ref.config,
|
|
19
|
-
api = _ref.api;
|
|
20
|
-
return {
|
|
21
|
-
name: 'codeBlock',
|
|
22
|
-
nodes: function nodes() {
|
|
23
|
-
return [{
|
|
24
|
-
name: 'codeBlock',
|
|
25
|
-
node: codeBlock
|
|
26
|
-
}];
|
|
27
|
-
},
|
|
28
|
-
pmPlugins: function pmPlugins() {
|
|
29
|
-
return [{
|
|
30
|
-
name: 'codeBlock',
|
|
31
|
-
plugin: function plugin(_ref2) {
|
|
32
|
-
var _options$appearance;
|
|
33
|
-
var getIntl = _ref2.getIntl;
|
|
34
|
-
return createPlugin(_objectSpread(_objectSpread({}, options), {}, {
|
|
35
|
-
getIntl: getIntl,
|
|
36
|
-
appearance: (_options$appearance = options === null || options === void 0 ? void 0 : options.appearance) !== null && _options$appearance !== void 0 ? _options$appearance : 'comment'
|
|
37
|
-
}));
|
|
38
|
-
}
|
|
39
|
-
}, {
|
|
40
|
-
name: 'codeBlockInputRule',
|
|
41
|
-
plugin: function plugin(_ref3) {
|
|
42
|
-
var _api$analytics;
|
|
43
|
-
var schema = _ref3.schema;
|
|
44
|
-
return createCodeBlockInputRule(schema, api === null || api === void 0 || (_api$analytics = api.analytics) === null || _api$analytics === void 0 ? void 0 : _api$analytics.actions);
|
|
45
|
-
}
|
|
46
|
-
}, {
|
|
47
|
-
name: 'codeBlockIDEKeyBindings',
|
|
48
|
-
plugin: function plugin() {
|
|
49
|
-
return ideUX(api);
|
|
50
|
-
}
|
|
51
|
-
}, {
|
|
52
|
-
name: 'codeBlockKeyMap',
|
|
53
|
-
plugin: function plugin(_ref4) {
|
|
54
|
-
var schema = _ref4.schema;
|
|
55
|
-
return keymap(schema);
|
|
56
|
-
}
|
|
57
|
-
}, {
|
|
58
|
-
name: 'codeBlockCopySelection',
|
|
59
|
-
plugin: function plugin() {
|
|
60
|
-
return codeBlockCopySelectionPlugin();
|
|
61
|
-
}
|
|
62
|
-
}];
|
|
63
|
-
},
|
|
64
|
-
// Workaround for a firefox issue where dom selection is off sync
|
|
65
|
-
// https://product-fabric.atlassian.net/browse/ED-12442
|
|
66
|
-
onEditorViewStateUpdated: function onEditorViewStateUpdated(props) {
|
|
67
|
-
refreshBrowserSelectionOnChange(props.originalTransaction, props.newEditorState);
|
|
68
|
-
},
|
|
69
|
-
actions: {
|
|
70
|
-
/*
|
|
71
|
-
* Function will insert code block at current selection if block is empty or below current selection and set focus on it.
|
|
72
|
-
*/
|
|
73
|
-
insertCodeBlock: function insertCodeBlock(inputMethod) {
|
|
74
|
-
var _api$analytics2;
|
|
75
|
-
return insertCodeBlockWithAnalytics(inputMethod, api === null || api === void 0 || (_api$analytics2 = api.analytics) === null || _api$analytics2 === void 0 ? void 0 : _api$analytics2.actions);
|
|
76
|
-
}
|
|
77
|
-
},
|
|
78
|
-
pluginsOptions: {
|
|
79
|
-
quickInsert: function quickInsert(_ref5) {
|
|
80
|
-
var formatMessage = _ref5.formatMessage;
|
|
81
|
-
return [{
|
|
82
|
-
id: 'codeblock',
|
|
83
|
-
title: formatMessage(blockTypeMessages.codeblock),
|
|
84
|
-
description: formatMessage(blockTypeMessages.codeblockDescription),
|
|
85
|
-
keywords: ['code block'],
|
|
86
|
-
priority: 700,
|
|
87
|
-
keyshortcut: '```',
|
|
88
|
-
icon: function icon() {
|
|
89
|
-
return /*#__PURE__*/React.createElement(IconCode, null);
|
|
90
|
-
},
|
|
91
|
-
action: function action(_insert, state) {
|
|
92
|
-
var _api$analytics3;
|
|
93
|
-
var tr = createInsertCodeBlockTransaction({
|
|
94
|
-
state: state
|
|
95
|
-
});
|
|
96
|
-
api === null || api === void 0 || (_api$analytics3 = api.analytics) === null || _api$analytics3 === void 0 || _api$analytics3.actions.attachAnalyticsEvent({
|
|
97
|
-
action: ACTION.INSERTED,
|
|
98
|
-
actionSubject: ACTION_SUBJECT.DOCUMENT,
|
|
99
|
-
actionSubjectId: ACTION_SUBJECT_ID.CODE_BLOCK,
|
|
100
|
-
attributes: {
|
|
101
|
-
inputMethod: INPUT_METHOD.QUICK_INSERT
|
|
102
|
-
},
|
|
103
|
-
eventType: EVENT_TYPE.TRACK
|
|
104
|
-
})(tr);
|
|
105
|
-
return tr;
|
|
106
|
-
}
|
|
107
|
-
}];
|
|
108
|
-
},
|
|
109
|
-
floatingToolbar: getToolbarConfig(options === null || options === void 0 ? void 0 : options.allowCopyToClipboard, api)
|
|
110
|
-
}
|
|
111
|
-
};
|
|
112
|
-
};
|
|
113
|
-
export default codeBlockPlugin;
|
|
@@ -1,52 +0,0 @@
|
|
|
1
|
-
import _toConsumableArray from "@babel/runtime/helpers/toConsumableArray";
|
|
2
|
-
import { SUPPORTED_LANGUAGES } from '@atlaskit/code/constants';
|
|
3
|
-
|
|
4
|
-
// We expect alias[0] to be used for the ADF attribute, see ED-2813
|
|
5
|
-
export var DEFAULT_LANGUAGES = [{
|
|
6
|
-
name: '(None)',
|
|
7
|
-
alias: ['none'],
|
|
8
|
-
value: 'none'
|
|
9
|
-
}].concat(_toConsumableArray(SUPPORTED_LANGUAGES));
|
|
10
|
-
export function findMatchedLanguage(supportedLanguages, language) {
|
|
11
|
-
if (!language) {
|
|
12
|
-
return undefined;
|
|
13
|
-
}
|
|
14
|
-
var matches = supportedLanguages.filter(function (supportedLanguage) {
|
|
15
|
-
return supportedLanguage.alias.indexOf(language.toLowerCase()) !== -1;
|
|
16
|
-
});
|
|
17
|
-
if (matches.length > 0) {
|
|
18
|
-
return matches[0];
|
|
19
|
-
}
|
|
20
|
-
return undefined;
|
|
21
|
-
}
|
|
22
|
-
export function filterSupportedLanguages(supportedLanguages) {
|
|
23
|
-
if (!supportedLanguages || !supportedLanguages.length) {
|
|
24
|
-
return DEFAULT_LANGUAGES;
|
|
25
|
-
}
|
|
26
|
-
return DEFAULT_LANGUAGES.filter(function (language) {
|
|
27
|
-
var i = language.alias.length;
|
|
28
|
-
while (i--) {
|
|
29
|
-
if (supportedLanguages.indexOf(language.alias[i]) > -1) {
|
|
30
|
-
return true;
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
return false;
|
|
34
|
-
});
|
|
35
|
-
}
|
|
36
|
-
export function getLanguageIdentifier(language) {
|
|
37
|
-
return language.alias[0];
|
|
38
|
-
}
|
|
39
|
-
export function createLanguageList(supportedLanguages) {
|
|
40
|
-
return supportedLanguages.sort(function (left, right) {
|
|
41
|
-
if (left.alias[0] === 'none') {
|
|
42
|
-
return -1;
|
|
43
|
-
}
|
|
44
|
-
if (left.name.toLowerCase() > right.name.toLowerCase()) {
|
|
45
|
-
return 1;
|
|
46
|
-
}
|
|
47
|
-
if (left.name.toLowerCase() < right.name.toLowerCase()) {
|
|
48
|
-
return -1;
|
|
49
|
-
}
|
|
50
|
-
return 0;
|
|
51
|
-
});
|
|
52
|
-
}
|
|
@@ -1,146 +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 _defineProperty from "@babel/runtime/helpers/defineProperty";
|
|
5
|
-
import rafSchedule from 'raf-schd';
|
|
6
|
-
import { browser } from '@atlaskit/editor-common/utils';
|
|
7
|
-
import { DOMSerializer } from '@atlaskit/editor-prosemirror/model';
|
|
8
|
-
import { codeBlockClassNames } from '../ui/class-names';
|
|
9
|
-
import { resetShouldIgnoreFollowingMutations } from '../actions';
|
|
10
|
-
import { getPluginState } from '../pm-plugins/main-state';
|
|
11
|
-
var MATCH_NEWLINES = new RegExp('\n', 'g');
|
|
12
|
-
var toDOM = function toDOM(node) {
|
|
13
|
-
return ['div', {
|
|
14
|
-
class: 'code-block'
|
|
15
|
-
}, ['div', {
|
|
16
|
-
class: codeBlockClassNames.start,
|
|
17
|
-
contenteditable: 'false'
|
|
18
|
-
}], ['div', {
|
|
19
|
-
class: codeBlockClassNames.contentWrapper
|
|
20
|
-
}, ['div', {
|
|
21
|
-
class: codeBlockClassNames.gutter,
|
|
22
|
-
contenteditable: 'false'
|
|
23
|
-
}], ['div', {
|
|
24
|
-
class: codeBlockClassNames.content
|
|
25
|
-
}, ['code', {
|
|
26
|
-
'data-language': node.attrs.language || '',
|
|
27
|
-
spellcheck: 'false',
|
|
28
|
-
contenteditable: 'true',
|
|
29
|
-
'data-testid': 'code-block--code'
|
|
30
|
-
}, 0]]], ['div', {
|
|
31
|
-
class: codeBlockClassNames.end,
|
|
32
|
-
contenteditable: 'false'
|
|
33
|
-
}]];
|
|
34
|
-
};
|
|
35
|
-
export var CodeBlockView = /*#__PURE__*/function () {
|
|
36
|
-
function CodeBlockView(_node, view, getPos) {
|
|
37
|
-
var _this = this;
|
|
38
|
-
_classCallCheck(this, CodeBlockView);
|
|
39
|
-
_defineProperty(this, "ensureLineNumbers", rafSchedule(function () {
|
|
40
|
-
var lines = 1;
|
|
41
|
-
_this.node.forEach(function (node) {
|
|
42
|
-
var text = node.text;
|
|
43
|
-
if (text) {
|
|
44
|
-
lines += (node.text.match(MATCH_NEWLINES) || []).length;
|
|
45
|
-
}
|
|
46
|
-
});
|
|
47
|
-
while (_this.lineNumberGutter.childElementCount < lines) {
|
|
48
|
-
_this.lineNumberGutter.appendChild(document.createElement('span'));
|
|
49
|
-
}
|
|
50
|
-
while (_this.lineNumberGutter.childElementCount > lines) {
|
|
51
|
-
_this.lineNumberGutter.removeChild(_this.lineNumberGutter.lastChild);
|
|
52
|
-
}
|
|
53
|
-
}));
|
|
54
|
-
var _DOMSerializer$render = DOMSerializer.renderSpec(document, toDOM(_node)),
|
|
55
|
-
dom = _DOMSerializer$render.dom,
|
|
56
|
-
contentDOM = _DOMSerializer$render.contentDOM;
|
|
57
|
-
this.getPos = getPos;
|
|
58
|
-
this.view = view;
|
|
59
|
-
this.node = _node;
|
|
60
|
-
this.dom = dom;
|
|
61
|
-
this.contentDOM = contentDOM;
|
|
62
|
-
this.lineNumberGutter = this.dom.querySelector(".".concat(codeBlockClassNames.gutter));
|
|
63
|
-
this.ensureLineNumbers();
|
|
64
|
-
}
|
|
65
|
-
_createClass(CodeBlockView, [{
|
|
66
|
-
key: "updateDOMAndSelection",
|
|
67
|
-
value: function updateDOMAndSelection(savedInnerHTML, newCursorPosition) {
|
|
68
|
-
var _this$dom;
|
|
69
|
-
if ((_this$dom = this.dom) !== null && _this$dom !== void 0 && _this$dom.childNodes && this.dom.childNodes.length > 1) {
|
|
70
|
-
var _contentView$childNod;
|
|
71
|
-
var contentWrapper = this.dom.childNodes[1];
|
|
72
|
-
var contentView = contentWrapper === null || contentWrapper === void 0 ? void 0 : contentWrapper.childNodes[1];
|
|
73
|
-
if ((contentView === null || contentView === void 0 || (_contentView$childNod = contentView.childNodes) === null || _contentView$childNod === void 0 ? void 0 : _contentView$childNod.length) > 0) {
|
|
74
|
-
var codeElement = contentView.firstChild;
|
|
75
|
-
codeElement.innerHTML = savedInnerHTML;
|
|
76
|
-
|
|
77
|
-
// We need to set cursor for the DOM update
|
|
78
|
-
var textElement = _toConsumableArray(codeElement.childNodes).find(function (child) {
|
|
79
|
-
return child.nodeName === '#text';
|
|
80
|
-
});
|
|
81
|
-
var sel = window.getSelection();
|
|
82
|
-
var range = document.createRange();
|
|
83
|
-
range.setStart(textElement, newCursorPosition);
|
|
84
|
-
range.collapse(true);
|
|
85
|
-
sel === null || sel === void 0 || sel.removeAllRanges();
|
|
86
|
-
sel === null || sel === void 0 || sel.addRange(range);
|
|
87
|
-
}
|
|
88
|
-
}
|
|
89
|
-
}
|
|
90
|
-
}, {
|
|
91
|
-
key: "coalesceDOMElements",
|
|
92
|
-
value: function coalesceDOMElements() {
|
|
93
|
-
var _this$dom2;
|
|
94
|
-
if ((_this$dom2 = this.dom) !== null && _this$dom2 !== void 0 && _this$dom2.childNodes && this.dom.childNodes.length > 1) {
|
|
95
|
-
var contentWrapper = this.dom.childNodes[1];
|
|
96
|
-
var contentView = contentWrapper === null || contentWrapper === void 0 ? void 0 : contentWrapper.childNodes[1];
|
|
97
|
-
if (contentView !== null && contentView !== void 0 && contentView.childNodes && contentView.childNodes.length > 1) {
|
|
98
|
-
var savedInnerHTML = '';
|
|
99
|
-
while (contentView.childNodes.length > 1) {
|
|
100
|
-
var lastChild = contentView.lastChild;
|
|
101
|
-
savedInnerHTML = lastChild.innerHTML + savedInnerHTML;
|
|
102
|
-
contentView.removeChild(lastChild);
|
|
103
|
-
}
|
|
104
|
-
var firstChild = contentView.firstChild;
|
|
105
|
-
savedInnerHTML = firstChild.innerHTML + '\n' + savedInnerHTML;
|
|
106
|
-
var newCursorPosition = firstChild.innerHTML.length + 1;
|
|
107
|
-
setTimeout(this.updateDOMAndSelection.bind(this, savedInnerHTML, newCursorPosition), 20);
|
|
108
|
-
}
|
|
109
|
-
}
|
|
110
|
-
}
|
|
111
|
-
}, {
|
|
112
|
-
key: "update",
|
|
113
|
-
value: function update(node) {
|
|
114
|
-
if (node.type !== this.node.type) {
|
|
115
|
-
return false;
|
|
116
|
-
}
|
|
117
|
-
if (node !== this.node) {
|
|
118
|
-
if (node.attrs.language !== this.node.attrs.language) {
|
|
119
|
-
this.contentDOM.setAttribute('data-language', node.attrs.language || '');
|
|
120
|
-
}
|
|
121
|
-
this.node = node;
|
|
122
|
-
this.ensureLineNumbers();
|
|
123
|
-
if (browser.android) {
|
|
124
|
-
this.coalesceDOMElements();
|
|
125
|
-
resetShouldIgnoreFollowingMutations(this.view.state, this.view.dispatch);
|
|
126
|
-
}
|
|
127
|
-
}
|
|
128
|
-
return true;
|
|
129
|
-
}
|
|
130
|
-
}, {
|
|
131
|
-
key: "ignoreMutation",
|
|
132
|
-
value: function ignoreMutation(record) {
|
|
133
|
-
var pluginState = getPluginState(this.view.state);
|
|
134
|
-
if (pluginState !== null && pluginState !== void 0 && pluginState.shouldIgnoreFollowingMutations) {
|
|
135
|
-
return true;
|
|
136
|
-
}
|
|
137
|
-
|
|
138
|
-
// Ensure updating the line-number gutter doesn't trigger reparsing the codeblock
|
|
139
|
-
return record.target === this.lineNumberGutter || record.target.parentNode === this.lineNumberGutter;
|
|
140
|
-
}
|
|
141
|
-
}]);
|
|
142
|
-
return CodeBlockView;
|
|
143
|
-
}();
|
|
144
|
-
export var codeBlockNodeView = function codeBlockNodeView(node, view, getPos) {
|
|
145
|
-
return new CodeBlockView(node, view, getPos);
|
|
146
|
-
};
|
|
@@ -1,103 +0,0 @@
|
|
|
1
|
-
import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
|
|
2
|
-
import { SafePlugin } from '@atlaskit/editor-common/safe-plugin';
|
|
3
|
-
import { PluginKey } from '@atlaskit/editor-prosemirror/state';
|
|
4
|
-
import { Decoration, DecorationSet } from '@atlaskit/editor-prosemirror/view';
|
|
5
|
-
import { getSelectedNodeOrNodeParentByNodeType } from '@atlaskit/editor-common/copy-button';
|
|
6
|
-
export var copySelectionPluginKey = new PluginKey('codeBlockCopySelectionPlugin');
|
|
7
|
-
function getSelectionDecorationStartAndEnd(_ref) {
|
|
8
|
-
var state = _ref.state,
|
|
9
|
-
transaction = _ref.transaction;
|
|
10
|
-
var codeBlockNode = getSelectedNodeOrNodeParentByNodeType({
|
|
11
|
-
nodeType: state.schema.nodes.codeBlock,
|
|
12
|
-
selection: transaction.selection
|
|
13
|
-
});
|
|
14
|
-
if (!codeBlockNode) {
|
|
15
|
-
return {
|
|
16
|
-
decorationStartAndEnd: undefined
|
|
17
|
-
};
|
|
18
|
-
}
|
|
19
|
-
var decorationStartAndEnd = [codeBlockNode.start, codeBlockNode.start + codeBlockNode.node.nodeSize];
|
|
20
|
-
return {
|
|
21
|
-
decorationStartAndEnd: decorationStartAndEnd
|
|
22
|
-
};
|
|
23
|
-
}
|
|
24
|
-
export function codeBlockCopySelectionPlugin() {
|
|
25
|
-
return new SafePlugin({
|
|
26
|
-
key: copySelectionPluginKey,
|
|
27
|
-
state: {
|
|
28
|
-
init: function init() {
|
|
29
|
-
return {
|
|
30
|
-
decorationStartAndEnd: undefined
|
|
31
|
-
};
|
|
32
|
-
},
|
|
33
|
-
apply: function apply(transaction, currentCodeBlockCopySelectionPluginState, _oldState, newState) {
|
|
34
|
-
switch (transaction.getMeta(copySelectionPluginKey)) {
|
|
35
|
-
case 'show-selection':
|
|
36
|
-
{
|
|
37
|
-
return getSelectionDecorationStartAndEnd({
|
|
38
|
-
state: newState,
|
|
39
|
-
transaction: transaction
|
|
40
|
-
});
|
|
41
|
-
}
|
|
42
|
-
case 'remove-selection':
|
|
43
|
-
return {
|
|
44
|
-
decorationStartAndEnd: undefined
|
|
45
|
-
};
|
|
46
|
-
default:
|
|
47
|
-
// The contents of the code block can change while the selection is being shown
|
|
48
|
-
// (either from collab edits -- or from the user continuing to type while hovering
|
|
49
|
-
// the mouse over the copy button).
|
|
50
|
-
// This ensures the selection is updated in these cases.
|
|
51
|
-
if (currentCodeBlockCopySelectionPluginState.decorationStartAndEnd !== undefined) {
|
|
52
|
-
return getSelectionDecorationStartAndEnd({
|
|
53
|
-
state: newState,
|
|
54
|
-
transaction: transaction
|
|
55
|
-
});
|
|
56
|
-
}
|
|
57
|
-
return currentCodeBlockCopySelectionPluginState;
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
},
|
|
61
|
-
props: {
|
|
62
|
-
decorations: function decorations(state) {
|
|
63
|
-
if (copySelectionPluginKey.getState(state).decorationStartAndEnd) {
|
|
64
|
-
var _copySelectionPluginK = _slicedToArray(copySelectionPluginKey.getState(state).decorationStartAndEnd, 2),
|
|
65
|
-
_start = _copySelectionPluginK[0],
|
|
66
|
-
_end = _copySelectionPluginK[1];
|
|
67
|
-
return DecorationSet.create(state.doc, [Decoration.inline(_start, _end, {
|
|
68
|
-
class: 'ProseMirror-fake-text-selection'
|
|
69
|
-
})]);
|
|
70
|
-
}
|
|
71
|
-
return DecorationSet.empty;
|
|
72
|
-
}
|
|
73
|
-
}
|
|
74
|
-
});
|
|
75
|
-
}
|
|
76
|
-
export function provideVisualFeedbackForCopyButton(state, dispatch) {
|
|
77
|
-
var tr = state.tr;
|
|
78
|
-
tr.setMeta(copySelectionPluginKey, 'show-selection');
|
|
79
|
-
|
|
80
|
-
// note: dispatch should always be defined when called from the
|
|
81
|
-
// floating toolbar. Howver the Command type which the floating toolbar
|
|
82
|
-
// uses suggests it's optional.
|
|
83
|
-
// Using the type here to protect against future refactors of the
|
|
84
|
-
// floating toolbar
|
|
85
|
-
if (dispatch) {
|
|
86
|
-
dispatch(tr);
|
|
87
|
-
}
|
|
88
|
-
return true;
|
|
89
|
-
}
|
|
90
|
-
export function removeVisualFeedbackForCopyButton(state, dispatch) {
|
|
91
|
-
var tr = state.tr;
|
|
92
|
-
tr.setMeta(copySelectionPluginKey, 'remove-selection');
|
|
93
|
-
|
|
94
|
-
// note: dispatch should always be defined when called from the
|
|
95
|
-
// floating toolbar. Howver the Command type which the floating toolbar
|
|
96
|
-
// uses suggests it's optional.
|
|
97
|
-
// Using the type here to protect against future refactors of the
|
|
98
|
-
// floating toolbar
|
|
99
|
-
if (dispatch) {
|
|
100
|
-
dispatch(tr);
|
|
101
|
-
}
|
|
102
|
-
return true;
|
|
103
|
-
}
|
|
@@ -1,126 +0,0 @@
|
|
|
1
|
-
import { SafePlugin } from '@atlaskit/editor-common/safe-plugin';
|
|
2
|
-
import { TextSelection } from '@atlaskit/editor-prosemirror/state';
|
|
3
|
-
import { keydownHandler } from '@atlaskit/editor-prosemirror/keymap';
|
|
4
|
-
import { setTextSelection } from '@atlaskit/editor-prosemirror/utils';
|
|
5
|
-
import { getCursor } from '../utils';
|
|
6
|
-
import { filterCommand as filter } from '@atlaskit/editor-common/utils';
|
|
7
|
-
import { isCursorBeforeClosingCharacter, isClosingCharacter } from '../ide-ux/paired-character-handling';
|
|
8
|
-
import { getAutoClosingBracketInfo, shouldAutoCloseBracket } from '../ide-ux/bracket-handling';
|
|
9
|
-
import { getAutoClosingQuoteInfo, shouldAutoCloseQuote } from '../ide-ux/quote-handling';
|
|
10
|
-
import { getEndOfCurrentLine, getStartOfCurrentLine, isCursorInsideCodeBlock, isSelectionEntirelyInsideCodeBlock, getLineInfo } from '../ide-ux/line-handling';
|
|
11
|
-
import { insertIndent, outdent, indent, insertNewlineWithIndent } from '../ide-ux/commands';
|
|
12
|
-
var ideUX = function ideUX(pluginInjectionApi) {
|
|
13
|
-
var _pluginInjectionApi$a;
|
|
14
|
-
var editorAnalyticsAPI = pluginInjectionApi === null || pluginInjectionApi === void 0 || (_pluginInjectionApi$a = pluginInjectionApi.analytics) === null || _pluginInjectionApi$a === void 0 ? void 0 : _pluginInjectionApi$a.actions;
|
|
15
|
-
return new SafePlugin({
|
|
16
|
-
props: {
|
|
17
|
-
handleTextInput: function handleTextInput(view, from, to, text) {
|
|
18
|
-
var _pluginInjectionApi$c;
|
|
19
|
-
var state = view.state,
|
|
20
|
-
dispatch = view.dispatch;
|
|
21
|
-
var compositionPluginState = pluginInjectionApi === null || pluginInjectionApi === void 0 || (_pluginInjectionApi$c = pluginInjectionApi.composition) === null || _pluginInjectionApi$c === void 0 ? void 0 : _pluginInjectionApi$c.sharedState.currentState();
|
|
22
|
-
if (isCursorInsideCodeBlock(state) && !(compositionPluginState !== null && compositionPluginState !== void 0 && compositionPluginState.isComposing)) {
|
|
23
|
-
var beforeText = getStartOfCurrentLine(state).text;
|
|
24
|
-
var afterText = getEndOfCurrentLine(state).text;
|
|
25
|
-
|
|
26
|
-
// If text is a closing bracket/quote and we've already inserted it, move the selection after
|
|
27
|
-
if (isCursorBeforeClosingCharacter(afterText) && isClosingCharacter(text) && afterText.startsWith(text)) {
|
|
28
|
-
dispatch(setTextSelection(to + text.length)(state.tr));
|
|
29
|
-
return true;
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
// Automatically add right-hand side bracket when user types the left bracket
|
|
33
|
-
if (shouldAutoCloseBracket(beforeText, afterText)) {
|
|
34
|
-
var _getAutoClosingBracke = getAutoClosingBracketInfo(beforeText + text, afterText),
|
|
35
|
-
left = _getAutoClosingBracke.left,
|
|
36
|
-
right = _getAutoClosingBracke.right;
|
|
37
|
-
if (left && right) {
|
|
38
|
-
var bracketPair = state.schema.text(text + right);
|
|
39
|
-
var tr = state.tr.replaceWith(from, to, bracketPair);
|
|
40
|
-
dispatch(setTextSelection(from + text.length)(tr));
|
|
41
|
-
return true;
|
|
42
|
-
}
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
// Automatically add closing quote when user types a starting quote
|
|
46
|
-
if (shouldAutoCloseQuote(beforeText, afterText)) {
|
|
47
|
-
var _getAutoClosingQuoteI = getAutoClosingQuoteInfo(beforeText + text, afterText),
|
|
48
|
-
leftQuote = _getAutoClosingQuoteI.left,
|
|
49
|
-
rightQuote = _getAutoClosingQuoteI.right;
|
|
50
|
-
if (leftQuote && rightQuote) {
|
|
51
|
-
var quotePair = state.schema.text(text + rightQuote);
|
|
52
|
-
var _tr = state.tr.replaceWith(from, to, quotePair);
|
|
53
|
-
dispatch(setTextSelection(from + text.length)(_tr));
|
|
54
|
-
return true;
|
|
55
|
-
}
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
return false;
|
|
59
|
-
},
|
|
60
|
-
handleKeyDown: keydownHandler({
|
|
61
|
-
Backspace: function Backspace(state, dispatch) {
|
|
62
|
-
if (isCursorInsideCodeBlock(state)) {
|
|
63
|
-
var $cursor = getCursor(state.selection);
|
|
64
|
-
var beforeText = getStartOfCurrentLine(state).text;
|
|
65
|
-
var afterText = getEndOfCurrentLine(state).text;
|
|
66
|
-
var _getAutoClosingBracke2 = getAutoClosingBracketInfo(beforeText, afterText),
|
|
67
|
-
leftBracket = _getAutoClosingBracke2.left,
|
|
68
|
-
rightBracket = _getAutoClosingBracke2.right,
|
|
69
|
-
hasTrailingMatchingBracket = _getAutoClosingBracke2.hasTrailingMatchingBracket;
|
|
70
|
-
if (leftBracket && rightBracket && hasTrailingMatchingBracket && dispatch) {
|
|
71
|
-
dispatch(state.tr.delete($cursor.pos - leftBracket.length, $cursor.pos + rightBracket.length));
|
|
72
|
-
return true;
|
|
73
|
-
}
|
|
74
|
-
var _getAutoClosingQuoteI2 = getAutoClosingQuoteInfo(beforeText, afterText),
|
|
75
|
-
leftQuote = _getAutoClosingQuoteI2.left,
|
|
76
|
-
rightQuote = _getAutoClosingQuoteI2.right,
|
|
77
|
-
hasTrailingMatchingQuote = _getAutoClosingQuoteI2.hasTrailingMatchingQuote;
|
|
78
|
-
if (leftQuote && rightQuote && hasTrailingMatchingQuote && dispatch) {
|
|
79
|
-
dispatch(state.tr.delete($cursor.pos - leftQuote.length, $cursor.pos + rightQuote.length));
|
|
80
|
-
return true;
|
|
81
|
-
}
|
|
82
|
-
var _getLineInfo = getLineInfo(beforeText),
|
|
83
|
-
_getLineInfo$indentTo = _getLineInfo.indentToken,
|
|
84
|
-
size = _getLineInfo$indentTo.size,
|
|
85
|
-
token = _getLineInfo$indentTo.token,
|
|
86
|
-
indentText = _getLineInfo.indentText;
|
|
87
|
-
if (beforeText === indentText) {
|
|
88
|
-
if (indentText.endsWith(token.repeat(size)) && dispatch) {
|
|
89
|
-
dispatch(state.tr.delete($cursor.pos - (size - indentText.length % size || size), $cursor.pos));
|
|
90
|
-
return true;
|
|
91
|
-
}
|
|
92
|
-
}
|
|
93
|
-
}
|
|
94
|
-
return false;
|
|
95
|
-
},
|
|
96
|
-
Enter: filter(isSelectionEntirelyInsideCodeBlock, insertNewlineWithIndent),
|
|
97
|
-
'Mod-]': filter(isSelectionEntirelyInsideCodeBlock, indent(editorAnalyticsAPI)),
|
|
98
|
-
'Mod-[': filter(isSelectionEntirelyInsideCodeBlock, outdent(editorAnalyticsAPI)),
|
|
99
|
-
Tab: filter(isSelectionEntirelyInsideCodeBlock, function (state, dispatch) {
|
|
100
|
-
if (!dispatch) {
|
|
101
|
-
return false;
|
|
102
|
-
}
|
|
103
|
-
if (isCursorInsideCodeBlock(state)) {
|
|
104
|
-
return insertIndent(state, dispatch);
|
|
105
|
-
}
|
|
106
|
-
return indent(editorAnalyticsAPI)(state, dispatch);
|
|
107
|
-
}),
|
|
108
|
-
'Shift-Tab': filter(isSelectionEntirelyInsideCodeBlock, outdent(editorAnalyticsAPI)),
|
|
109
|
-
'Mod-a': function ModA(state, dispatch) {
|
|
110
|
-
if (isSelectionEntirelyInsideCodeBlock(state)) {
|
|
111
|
-
var _state$selection = state.selection,
|
|
112
|
-
$from = _state$selection.$from,
|
|
113
|
-
$to = _state$selection.$to;
|
|
114
|
-
var isFullCodeBlockSelection = $from.parentOffset === 0 && $to.parentOffset === $to.parent.nodeSize - 2;
|
|
115
|
-
if (!isFullCodeBlockSelection && dispatch) {
|
|
116
|
-
dispatch(state.tr.setSelection(TextSelection.create(state.doc, $from.start(), $to.end())));
|
|
117
|
-
return true;
|
|
118
|
-
}
|
|
119
|
-
}
|
|
120
|
-
return false;
|
|
121
|
-
}
|
|
122
|
-
})
|
|
123
|
-
}
|
|
124
|
-
});
|
|
125
|
-
};
|
|
126
|
-
export default ideUX;
|
|
@@ -1,62 +0,0 @@
|
|
|
1
|
-
import { safeInsert } from '@atlaskit/editor-prosemirror/utils';
|
|
2
|
-
import { createRule, createPlugin, leafNodeReplacementCharacter } from '@atlaskit/prosemirror-input-rules';
|
|
3
|
-
import { INPUT_METHOD, ACTION, ACTION_SUBJECT, EVENT_TYPE, ACTION_SUBJECT_ID } from '@atlaskit/editor-common/analytics';
|
|
4
|
-
import { inputRuleWithAnalytics } from '@atlaskit/editor-common/utils';
|
|
5
|
-
import { isConvertableToCodeBlock, transformToCodeBlockAction } from '../transform-to-code-block';
|
|
6
|
-
import { insertBlock } from '@atlaskit/editor-common/commands';
|
|
7
|
-
export function createCodeBlockInputRule(schema, editorAnalyticsAPI) {
|
|
8
|
-
var rules = getCodeBlockRules(editorAnalyticsAPI, schema);
|
|
9
|
-
return createPlugin('code-block-input-rule', rules, {
|
|
10
|
-
isBlockNodeRule: true
|
|
11
|
-
});
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
/**
|
|
15
|
-
* Get all code block input rules
|
|
16
|
-
*
|
|
17
|
-
* @param {Schema} schema
|
|
18
|
-
* @returns {InputRuleWithHandler[]}
|
|
19
|
-
*/
|
|
20
|
-
function getCodeBlockRules(editorAnalyticsAPI, schema) {
|
|
21
|
-
var ruleAnalytics = inputRuleWithAnalytics({
|
|
22
|
-
action: ACTION.INSERTED,
|
|
23
|
-
actionSubject: ACTION_SUBJECT.DOCUMENT,
|
|
24
|
-
actionSubjectId: ACTION_SUBJECT_ID.CODE_BLOCK,
|
|
25
|
-
attributes: {
|
|
26
|
-
inputMethod: INPUT_METHOD.FORMATTING
|
|
27
|
-
},
|
|
28
|
-
eventType: EVENT_TYPE.TRACK
|
|
29
|
-
}, editorAnalyticsAPI);
|
|
30
|
-
var validMatchLength = function validMatchLength(match) {
|
|
31
|
-
return match.length > 0 && match[0].length === 3;
|
|
32
|
-
};
|
|
33
|
-
var threeTildeRule = createRule(/(?!\s)(`{3,})$/, function (state, match, start, end) {
|
|
34
|
-
if (!validMatchLength(match)) {
|
|
35
|
-
return null;
|
|
36
|
-
}
|
|
37
|
-
var attributes = {};
|
|
38
|
-
if (match[4]) {
|
|
39
|
-
attributes.language = match[4];
|
|
40
|
-
}
|
|
41
|
-
if (isConvertableToCodeBlock(state)) {
|
|
42
|
-
return transformToCodeBlockAction(state, start, attributes);
|
|
43
|
-
}
|
|
44
|
-
var tr = state.tr;
|
|
45
|
-
tr.delete(start, end);
|
|
46
|
-
var codeBlock = tr.doc.type.schema.nodes.codeBlock.createChecked();
|
|
47
|
-
safeInsert(codeBlock)(tr);
|
|
48
|
-
return tr;
|
|
49
|
-
});
|
|
50
|
-
var leftNodeReplacementThreeTildeRule = createRule(new RegExp("((".concat(leafNodeReplacementCharacter, "`{3,})|^\\s(`{3,}))(\\S*)$")), function (state, match, start, end) {
|
|
51
|
-
if (!validMatchLength(match)) {
|
|
52
|
-
return null;
|
|
53
|
-
}
|
|
54
|
-
var attributes = {};
|
|
55
|
-
if (match[4]) {
|
|
56
|
-
attributes.language = match[4];
|
|
57
|
-
}
|
|
58
|
-
var inlineStart = Math.max(match.index + state.selection.$from.start(), 1);
|
|
59
|
-
return insertBlock(state, schema.nodes.codeBlock, inlineStart, end, attributes);
|
|
60
|
-
});
|
|
61
|
-
return [ruleAnalytics(threeTildeRule), ruleAnalytics(leftNodeReplacementThreeTildeRule)];
|
|
62
|
-
}
|
|
@@ -1,59 +0,0 @@
|
|
|
1
|
-
import { keymap } from '@atlaskit/editor-prosemirror/keymap';
|
|
2
|
-
import { Selection } from '@atlaskit/editor-prosemirror/state';
|
|
3
|
-
import { findParentNodeOfTypeClosestToPos, hasParentNodeOfType } from '@atlaskit/editor-prosemirror/utils';
|
|
4
|
-
import { getCursor } from '../utils';
|
|
5
|
-
import { isEmptyNode } from '@atlaskit/editor-common/utils';
|
|
6
|
-
var deleteCurrentItem = function deleteCurrentItem($from) {
|
|
7
|
-
return function (tr) {
|
|
8
|
-
return tr.delete($from.before($from.depth), $from.after($from.depth));
|
|
9
|
-
};
|
|
10
|
-
};
|
|
11
|
-
var setTextSelection = function setTextSelection(pos) {
|
|
12
|
-
return function (tr) {
|
|
13
|
-
var newSelection = Selection.findFrom(tr.doc.resolve(pos), -1, true);
|
|
14
|
-
if (newSelection) {
|
|
15
|
-
tr.setSelection(newSelection);
|
|
16
|
-
}
|
|
17
|
-
return tr;
|
|
18
|
-
};
|
|
19
|
-
};
|
|
20
|
-
export function keymapPlugin(schema) {
|
|
21
|
-
return keymap({
|
|
22
|
-
Backspace: function Backspace(state, dispatch) {
|
|
23
|
-
var $cursor = getCursor(state.selection);
|
|
24
|
-
var _state$schema$nodes = state.schema.nodes,
|
|
25
|
-
paragraph = _state$schema$nodes.paragraph,
|
|
26
|
-
codeBlock = _state$schema$nodes.codeBlock,
|
|
27
|
-
listItem = _state$schema$nodes.listItem,
|
|
28
|
-
table = _state$schema$nodes.table,
|
|
29
|
-
layoutColumn = _state$schema$nodes.layoutColumn;
|
|
30
|
-
if (!$cursor || $cursor.parent.type !== codeBlock || !dispatch) {
|
|
31
|
-
return false;
|
|
32
|
-
}
|
|
33
|
-
if ($cursor.pos === 1 || hasParentNodeOfType(listItem)(state.selection) && $cursor.parentOffset === 0) {
|
|
34
|
-
var node = findParentNodeOfTypeClosestToPos($cursor, codeBlock);
|
|
35
|
-
if (!node) {
|
|
36
|
-
return false;
|
|
37
|
-
}
|
|
38
|
-
dispatch(state.tr.setNodeMarkup(node.pos, node.node.type, node.node.attrs, []).setBlockType($cursor.pos, $cursor.pos, paragraph));
|
|
39
|
-
return true;
|
|
40
|
-
}
|
|
41
|
-
if ($cursor.node && isEmptyNode(schema)($cursor.node()) && (hasParentNodeOfType(layoutColumn)(state.selection) || hasParentNodeOfType(table)(state.selection))) {
|
|
42
|
-
var tr = state.tr;
|
|
43
|
-
var insertPos = $cursor.pos;
|
|
44
|
-
deleteCurrentItem($cursor)(tr);
|
|
45
|
-
setTextSelection(insertPos)(tr);
|
|
46
|
-
dispatch(tr.scrollIntoView());
|
|
47
|
-
return true;
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
// Handle not nested empty code block
|
|
51
|
-
if (isEmptyNode(schema)($cursor.node())) {
|
|
52
|
-
dispatch(deleteCurrentItem($cursor)(state === null || state === void 0 ? void 0 : state.tr));
|
|
53
|
-
return true;
|
|
54
|
-
}
|
|
55
|
-
return false;
|
|
56
|
-
}
|
|
57
|
-
});
|
|
58
|
-
}
|
|
59
|
-
export default keymapPlugin;
|