@atlaskit/editor-core 187.18.2 → 187.19.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/CHANGELOG.md +6 -0
- package/dist/cjs/labs/next/presets/default.js +2 -1
- package/dist/cjs/plugins/base/index.js +0 -7
- package/dist/cjs/plugins/code-block/index.js +1 -1
- package/dist/cjs/plugins/code-block/pm-plugins/ide-ux.js +98 -95
- package/dist/cjs/plugins/composition/index.js +33 -0
- package/dist/cjs/plugins/{base/pm-plugins/composition.js → composition/pm-plugins/main.js} +8 -14
- package/dist/cjs/plugins/composition/pm-plugins/plugin-key.js +9 -0
- package/dist/cjs/plugins/placeholder/index.js +2 -2
- package/dist/cjs/version-wrapper.js +1 -1
- package/dist/cjs/version.json +1 -1
- package/dist/es2019/labs/next/presets/default.js +2 -1
- package/dist/es2019/plugins/base/index.js +0 -5
- package/dist/es2019/plugins/code-block/index.js +1 -1
- package/dist/es2019/plugins/code-block/pm-plugins/ide-ux.js +107 -104
- package/dist/es2019/plugins/composition/index.js +23 -0
- package/dist/es2019/plugins/{base/pm-plugins/composition.js → composition/pm-plugins/main.js} +7 -12
- package/dist/es2019/plugins/composition/pm-plugins/plugin-key.js +2 -0
- package/dist/es2019/plugins/placeholder/index.js +2 -2
- package/dist/es2019/version-wrapper.js +1 -1
- package/dist/es2019/version.json +1 -1
- package/dist/esm/labs/next/presets/default.js +2 -1
- package/dist/esm/plugins/base/index.js +0 -7
- package/dist/esm/plugins/code-block/index.js +1 -1
- package/dist/esm/plugins/code-block/pm-plugins/ide-ux.js +98 -95
- package/dist/esm/plugins/composition/index.js +25 -0
- package/dist/esm/plugins/{base/pm-plugins/composition.js → composition/pm-plugins/main.js} +7 -12
- package/dist/esm/plugins/composition/pm-plugins/plugin-key.js +2 -0
- package/dist/esm/plugins/placeholder/index.js +2 -2
- package/dist/esm/version-wrapper.js +1 -1
- package/dist/esm/version.json +1 -1
- package/dist/types/labs/next/presets/default.d.ts +16 -0
- package/dist/types/plugins/code-block/index.d.ts +6 -4
- package/dist/types/plugins/code-block/pm-plugins/ide-ux.d.ts +4 -2
- package/dist/types/plugins/composition/index.d.ts +8 -0
- package/dist/types/plugins/composition/pm-plugins/main.d.ts +4 -0
- package/dist/types/plugins/composition/pm-plugins/plugin-key.d.ts +6 -0
- package/dist/types/plugins/placeholder/index.d.ts +2 -1
- package/dist/types-ts4.5/labs/next/presets/default.d.ts +20 -0
- package/dist/types-ts4.5/plugins/code-block/index.d.ts +6 -4
- package/dist/types-ts4.5/plugins/code-block/pm-plugins/ide-ux.d.ts +4 -2
- package/dist/types-ts4.5/plugins/composition/index.d.ts +8 -0
- package/dist/types-ts4.5/plugins/composition/pm-plugins/main.d.ts +4 -0
- package/dist/types-ts4.5/plugins/composition/pm-plugins/plugin-key.d.ts +6 -0
- package/dist/types-ts4.5/plugins/placeholder/index.d.ts +3 -1
- package/package.json +1 -1
- package/dist/types/plugins/base/pm-plugins/composition.d.ts +0 -9
- package/dist/types-ts4.5/plugins/base/pm-plugins/composition.d.ts +0 -9
|
@@ -9,121 +9,124 @@ import { getAutoClosingBracketInfo, shouldAutoCloseBracket } from '../ide-ux/bra
|
|
|
9
9
|
import { getAutoClosingQuoteInfo, shouldAutoCloseQuote } from '../ide-ux/quote-handling';
|
|
10
10
|
import { getEndOfCurrentLine, getStartOfCurrentLine, isCursorInsideCodeBlock, isSelectionEntirelyInsideCodeBlock, getLineInfo } from '../ide-ux/line-handling';
|
|
11
11
|
import { insertIndent, outdent, indent, insertNewlineWithIndent } from '../ide-ux/commands';
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
const afterText = getEndOfCurrentLine(state).text;
|
|
23
|
-
|
|
24
|
-
// If text is a closing bracket/quote and we've already inserted it, move the selection after
|
|
25
|
-
if (isCursorBeforeClosingCharacter(afterText) && isClosingCharacter(text) && afterText.startsWith(text)) {
|
|
26
|
-
dispatch(setTextSelection(to + text.length)(state.tr));
|
|
27
|
-
return true;
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
// Automatically add right-hand side bracket when user types the left bracket
|
|
31
|
-
if (shouldAutoCloseBracket(beforeText, afterText)) {
|
|
32
|
-
const {
|
|
33
|
-
left,
|
|
34
|
-
right
|
|
35
|
-
} = getAutoClosingBracketInfo(beforeText + text, afterText);
|
|
36
|
-
if (left && right) {
|
|
37
|
-
const bracketPair = state.schema.text(text + right);
|
|
38
|
-
let tr = state.tr.replaceWith(from, to, bracketPair);
|
|
39
|
-
dispatch(setTextSelection(from + text.length)(tr));
|
|
40
|
-
return true;
|
|
41
|
-
}
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
// Automatically add closing quote when user types a starting quote
|
|
45
|
-
if (shouldAutoCloseQuote(beforeText, afterText)) {
|
|
46
|
-
const {
|
|
47
|
-
left: leftQuote,
|
|
48
|
-
right: rightQuote
|
|
49
|
-
} = getAutoClosingQuoteInfo(beforeText + text, afterText);
|
|
50
|
-
if (leftQuote && rightQuote) {
|
|
51
|
-
const quotePair = state.schema.text(text + rightQuote);
|
|
52
|
-
let 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: (state, dispatch) => {
|
|
62
|
-
if (isCursorInsideCodeBlock(state)) {
|
|
63
|
-
const $cursor = getCursor(state.selection);
|
|
12
|
+
const ideUX = pluginInjectionApi => {
|
|
13
|
+
return new SafePlugin({
|
|
14
|
+
props: {
|
|
15
|
+
handleTextInput(view, from, to, text) {
|
|
16
|
+
const {
|
|
17
|
+
state,
|
|
18
|
+
dispatch
|
|
19
|
+
} = view;
|
|
20
|
+
const compositionPluginState = pluginInjectionApi === null || pluginInjectionApi === void 0 ? void 0 : pluginInjectionApi.dependencies.composition.sharedState.currentState();
|
|
21
|
+
if (isCursorInsideCodeBlock(state) && !(compositionPluginState !== null && compositionPluginState !== void 0 && compositionPluginState.isComposing)) {
|
|
64
22
|
const beforeText = getStartOfCurrentLine(state).text;
|
|
65
23
|
const afterText = getEndOfCurrentLine(state).text;
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
} = getAutoClosingBracketInfo(beforeText, afterText);
|
|
71
|
-
if (leftBracket && rightBracket && hasTrailingMatchingBracket && dispatch) {
|
|
72
|
-
dispatch(state.tr.delete($cursor.pos - leftBracket.length, $cursor.pos + rightBracket.length));
|
|
24
|
+
|
|
25
|
+
// If text is a closing bracket/quote and we've already inserted it, move the selection after
|
|
26
|
+
if (isCursorBeforeClosingCharacter(afterText) && isClosingCharacter(text) && afterText.startsWith(text)) {
|
|
27
|
+
dispatch(setTextSelection(to + text.length)(state.tr));
|
|
73
28
|
return true;
|
|
74
29
|
}
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
30
|
+
|
|
31
|
+
// Automatically add right-hand side bracket when user types the left bracket
|
|
32
|
+
if (shouldAutoCloseBracket(beforeText, afterText)) {
|
|
33
|
+
const {
|
|
34
|
+
left,
|
|
35
|
+
right
|
|
36
|
+
} = getAutoClosingBracketInfo(beforeText + text, afterText);
|
|
37
|
+
if (left && right) {
|
|
38
|
+
const bracketPair = state.schema.text(text + right);
|
|
39
|
+
let tr = state.tr.replaceWith(from, to, bracketPair);
|
|
40
|
+
dispatch(setTextSelection(from + text.length)(tr));
|
|
41
|
+
return true;
|
|
42
|
+
}
|
|
83
43
|
}
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
44
|
+
|
|
45
|
+
// Automatically add closing quote when user types a starting quote
|
|
46
|
+
if (shouldAutoCloseQuote(beforeText, afterText)) {
|
|
47
|
+
const {
|
|
48
|
+
left: leftQuote,
|
|
49
|
+
right: rightQuote
|
|
50
|
+
} = getAutoClosingQuoteInfo(beforeText + text, afterText);
|
|
51
|
+
if (leftQuote && rightQuote) {
|
|
52
|
+
const quotePair = state.schema.text(text + rightQuote);
|
|
53
|
+
let tr = state.tr.replaceWith(from, to, quotePair);
|
|
54
|
+
dispatch(setTextSelection(from + text.length)(tr));
|
|
94
55
|
return true;
|
|
95
56
|
}
|
|
96
57
|
}
|
|
97
58
|
}
|
|
98
59
|
return false;
|
|
99
60
|
},
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
61
|
+
handleKeyDown: keydownHandler({
|
|
62
|
+
Backspace: (state, dispatch) => {
|
|
63
|
+
if (isCursorInsideCodeBlock(state)) {
|
|
64
|
+
const $cursor = getCursor(state.selection);
|
|
65
|
+
const beforeText = getStartOfCurrentLine(state).text;
|
|
66
|
+
const afterText = getEndOfCurrentLine(state).text;
|
|
67
|
+
const {
|
|
68
|
+
left: leftBracket,
|
|
69
|
+
right: rightBracket,
|
|
70
|
+
hasTrailingMatchingBracket
|
|
71
|
+
} = getAutoClosingBracketInfo(beforeText, afterText);
|
|
72
|
+
if (leftBracket && rightBracket && hasTrailingMatchingBracket && dispatch) {
|
|
73
|
+
dispatch(state.tr.delete($cursor.pos - leftBracket.length, $cursor.pos + rightBracket.length));
|
|
74
|
+
return true;
|
|
75
|
+
}
|
|
76
|
+
const {
|
|
77
|
+
left: leftQuote,
|
|
78
|
+
right: rightQuote,
|
|
79
|
+
hasTrailingMatchingQuote
|
|
80
|
+
} = getAutoClosingQuoteInfo(beforeText, afterText);
|
|
81
|
+
if (leftQuote && rightQuote && hasTrailingMatchingQuote && dispatch) {
|
|
82
|
+
dispatch(state.tr.delete($cursor.pos - leftQuote.length, $cursor.pos + rightQuote.length));
|
|
83
|
+
return true;
|
|
84
|
+
}
|
|
85
|
+
const {
|
|
86
|
+
indentToken: {
|
|
87
|
+
size,
|
|
88
|
+
token
|
|
89
|
+
},
|
|
90
|
+
indentText
|
|
91
|
+
} = getLineInfo(beforeText);
|
|
92
|
+
if (beforeText === indentText) {
|
|
93
|
+
if (indentText.endsWith(token.repeat(size)) && dispatch) {
|
|
94
|
+
dispatch(state.tr.delete($cursor.pos - (size - indentText.length % size || size), $cursor.pos));
|
|
95
|
+
return true;
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
}
|
|
105
99
|
return false;
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
$from,
|
|
117
|
-
$to
|
|
118
|
-
} = state.selection;
|
|
119
|
-
const isFullCodeBlockSelection = $from.parentOffset === 0 && $to.parentOffset === $to.parent.nodeSize - 2;
|
|
120
|
-
if (!isFullCodeBlockSelection && dispatch) {
|
|
121
|
-
dispatch(state.tr.setSelection(TextSelection.create(state.doc, $from.start(), $to.end())));
|
|
122
|
-
return true;
|
|
100
|
+
},
|
|
101
|
+
Enter: filter(isSelectionEntirelyInsideCodeBlock, insertNewlineWithIndent),
|
|
102
|
+
'Mod-]': filter(isSelectionEntirelyInsideCodeBlock, indent),
|
|
103
|
+
'Mod-[': filter(isSelectionEntirelyInsideCodeBlock, outdent),
|
|
104
|
+
Tab: filter(isSelectionEntirelyInsideCodeBlock, (state, dispatch) => {
|
|
105
|
+
if (!dispatch) {
|
|
106
|
+
return false;
|
|
107
|
+
}
|
|
108
|
+
if (isCursorInsideCodeBlock(state)) {
|
|
109
|
+
return insertIndent(state, dispatch);
|
|
123
110
|
}
|
|
111
|
+
return indent(state, dispatch);
|
|
112
|
+
}),
|
|
113
|
+
'Shift-Tab': filter(isSelectionEntirelyInsideCodeBlock, outdent),
|
|
114
|
+
'Mod-a': (state, dispatch) => {
|
|
115
|
+
if (isSelectionEntirelyInsideCodeBlock(state)) {
|
|
116
|
+
const {
|
|
117
|
+
$from,
|
|
118
|
+
$to
|
|
119
|
+
} = state.selection;
|
|
120
|
+
const isFullCodeBlockSelection = $from.parentOffset === 0 && $to.parentOffset === $to.parent.nodeSize - 2;
|
|
121
|
+
if (!isFullCodeBlockSelection && dispatch) {
|
|
122
|
+
dispatch(state.tr.setSelection(TextSelection.create(state.doc, $from.start(), $to.end())));
|
|
123
|
+
return true;
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
return false;
|
|
124
127
|
}
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
128
|
+
})
|
|
129
|
+
}
|
|
130
|
+
});
|
|
131
|
+
};
|
|
132
|
+
export default ideUX;
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import createPlugin from './pm-plugins/main';
|
|
2
|
+
import { pluginKey } from './pm-plugins/plugin-key';
|
|
3
|
+
const composition = () => {
|
|
4
|
+
return {
|
|
5
|
+
name: 'composition',
|
|
6
|
+
getSharedState(editorState) {
|
|
7
|
+
var _pluginKey$getState;
|
|
8
|
+
if (!editorState) {
|
|
9
|
+
return undefined;
|
|
10
|
+
}
|
|
11
|
+
return {
|
|
12
|
+
isComposing: !!((_pluginKey$getState = pluginKey.getState(editorState)) !== null && _pluginKey$getState !== void 0 && _pluginKey$getState.isComposing)
|
|
13
|
+
};
|
|
14
|
+
},
|
|
15
|
+
pmPlugins() {
|
|
16
|
+
return [{
|
|
17
|
+
name: 'composition',
|
|
18
|
+
plugin: () => createPlugin()
|
|
19
|
+
}];
|
|
20
|
+
}
|
|
21
|
+
};
|
|
22
|
+
};
|
|
23
|
+
export default composition;
|
package/dist/es2019/plugins/{base/pm-plugins/composition.js → composition/pm-plugins/main.js}
RENAMED
|
@@ -1,21 +1,16 @@
|
|
|
1
1
|
import { SafePlugin } from '@atlaskit/editor-common/safe-plugin';
|
|
2
|
-
import { PluginKey } from '@atlaskit/editor-prosemirror/state';
|
|
3
2
|
import { ZERO_WIDTH_SPACE } from '@atlaskit/editor-common/utils';
|
|
4
|
-
|
|
5
|
-
export const isComposing = state => {
|
|
6
|
-
var _compositionPluginKey;
|
|
7
|
-
return !!((_compositionPluginKey = compositionPluginKey.getState(state)) !== null && _compositionPluginKey !== void 0 && _compositionPluginKey.isComposing);
|
|
8
|
-
};
|
|
3
|
+
import { pluginKey } from './plugin-key';
|
|
9
4
|
const isLinux = () => navigator.userAgent.indexOf('Linux') >= 0;
|
|
10
5
|
export default (() => new SafePlugin({
|
|
11
|
-
key:
|
|
6
|
+
key: pluginKey,
|
|
12
7
|
state: {
|
|
13
8
|
init: () => ({
|
|
14
9
|
isComposing: false,
|
|
15
10
|
zeroWidthSpacePos: undefined
|
|
16
11
|
}),
|
|
17
12
|
apply: (tr, value) => {
|
|
18
|
-
const isComposing = tr.getMeta(
|
|
13
|
+
const isComposing = tr.getMeta(pluginKey);
|
|
19
14
|
const zeroWidthSpacePos = tr.getMeta('zeroWidthSpacePos');
|
|
20
15
|
if (typeof isComposing === 'undefined') {
|
|
21
16
|
return value;
|
|
@@ -32,7 +27,7 @@ export default (() => new SafePlugin({
|
|
|
32
27
|
const {
|
|
33
28
|
tr
|
|
34
29
|
} = view.state;
|
|
35
|
-
tr.setMeta(
|
|
30
|
+
tr.setMeta(pluginKey, true);
|
|
36
31
|
|
|
37
32
|
// only apply for linux and cursor is at start of line
|
|
38
33
|
if (isLinux() && view.state.selection.$from.parentOffset === 0) {
|
|
@@ -48,10 +43,10 @@ export default (() => new SafePlugin({
|
|
|
48
43
|
const {
|
|
49
44
|
tr
|
|
50
45
|
} = view.state;
|
|
51
|
-
tr.setMeta(
|
|
46
|
+
tr.setMeta(pluginKey, false);
|
|
52
47
|
if (isLinux()) {
|
|
53
|
-
var
|
|
54
|
-
const zeroWidthSpacePos = (
|
|
48
|
+
var _pluginKey$getState;
|
|
49
|
+
const zeroWidthSpacePos = (_pluginKey$getState = pluginKey.getState(view.state)) === null || _pluginKey$getState === void 0 ? void 0 : _pluginKey$getState.zeroWidthSpacePos;
|
|
55
50
|
if (typeof zeroWidthSpacePos !== 'undefined') {
|
|
56
51
|
tr.deleteRange(zeroWidthSpacePos, zeroWidthSpacePos + 1);
|
|
57
52
|
}
|
|
@@ -4,7 +4,6 @@ import { PluginKey } from '@atlaskit/editor-prosemirror/state';
|
|
|
4
4
|
import { DecorationSet, Decoration } from '@atlaskit/editor-prosemirror/view';
|
|
5
5
|
export const pluginKey = new PluginKey('placeholderPlugin');
|
|
6
6
|
import { isTypeAheadOpen } from '../type-ahead/utils';
|
|
7
|
-
import { isComposing } from '../base/pm-plugins/composition';
|
|
8
7
|
function getPlaceholderState(editorState) {
|
|
9
8
|
return pluginKey.getState(editorState);
|
|
10
9
|
}
|
|
@@ -100,7 +99,8 @@ export function createPlugin(defaultPlaceholderText, bracketPlaceholderText, api
|
|
|
100
99
|
placeholderText,
|
|
101
100
|
pos
|
|
102
101
|
} = getPlaceholderState(editorState);
|
|
103
|
-
|
|
102
|
+
const compositionPluginState = api === null || api === void 0 ? void 0 : api.dependencies.composition.sharedState.currentState();
|
|
103
|
+
if (hasPlaceholder && placeholderText && pos !== undefined && !(compositionPluginState !== null && compositionPluginState !== void 0 && compositionPluginState.isComposing)) {
|
|
104
104
|
return createPlaceholderDecoration(editorState, placeholderText, pos);
|
|
105
105
|
}
|
|
106
106
|
return;
|
package/dist/es2019/version.json
CHANGED
|
@@ -20,6 +20,7 @@ import { analyticsPlugin as deprecatedAnalyticsPlugin } from '../../../plugins';
|
|
|
20
20
|
import { analyticsPlugin } from '@atlaskit/editor-plugin-analytics';
|
|
21
21
|
import placeholderPlugin from '../../../plugins/placeholder';
|
|
22
22
|
import annotationPlugin from '../../../plugins/annotation';
|
|
23
|
+
import compositionPlugin from '../../../plugins/composition';
|
|
23
24
|
import quickInsertPlugin from '../../../plugins/quick-insert';
|
|
24
25
|
import selectionPlugin from '../../../plugins/selection';
|
|
25
26
|
import codeBlockPlugin from '../../../plugins/code-block';
|
|
@@ -53,7 +54,7 @@ export function createDefaultPreset(options) {
|
|
|
53
54
|
}]);
|
|
54
55
|
}
|
|
55
56
|
return builder;
|
|
56
|
-
}).add([pastePlugin, options.paste]).add(clipboardPlugin).add(focusPlugin).add([basePlugin, options.base]).add(decorationsPlugin).maybeAdd(undoRedoPlugin, function (p, builder) {
|
|
57
|
+
}).add([pastePlugin, options.paste]).add(clipboardPlugin).add(focusPlugin).add(compositionPlugin).add([basePlugin, options.base]).add(decorationsPlugin).maybeAdd(undoRedoPlugin, function (p, builder) {
|
|
57
58
|
var _options$featureFlags;
|
|
58
59
|
// The undo redo plugin needs to be add before the blockTypePlugin
|
|
59
60
|
if ((_options$featureFlags = options.featureFlags) !== null && _options$featureFlags !== void 0 && _options$featureFlags.undoRedoButtons) {
|
|
@@ -14,7 +14,6 @@ import inlineCursorTargetPlugin from './pm-plugins/inline-cursor-target';
|
|
|
14
14
|
import scrollGutter from './pm-plugins/scroll-gutter';
|
|
15
15
|
import { keymap } from '@atlaskit/editor-common/keymaps';
|
|
16
16
|
import frozenEditor from './pm-plugins/frozen-editor';
|
|
17
|
-
import compositionPlugin from './pm-plugins/composition';
|
|
18
17
|
// Chrome >= 88
|
|
19
18
|
export var isChromeWithSelectionBug = browser.chrome && browser.chrome_version >= 88;
|
|
20
19
|
var basePlugin = function basePlugin(options, api) {
|
|
@@ -104,12 +103,6 @@ var basePlugin = function basePlugin(options, api) {
|
|
|
104
103
|
return disableSpellcheckingPlugin(featureFlags);
|
|
105
104
|
}
|
|
106
105
|
});
|
|
107
|
-
plugins.push({
|
|
108
|
-
name: 'compositionPlugin',
|
|
109
|
-
plugin: function plugin() {
|
|
110
|
-
return compositionPlugin();
|
|
111
|
-
}
|
|
112
|
-
});
|
|
113
106
|
return plugins;
|
|
114
107
|
},
|
|
115
108
|
nodes: function nodes() {
|
|
@@ -9,112 +9,115 @@ import { getAutoClosingBracketInfo, shouldAutoCloseBracket } from '../ide-ux/bra
|
|
|
9
9
|
import { getAutoClosingQuoteInfo, shouldAutoCloseQuote } from '../ide-ux/quote-handling';
|
|
10
10
|
import { getEndOfCurrentLine, getStartOfCurrentLine, isCursorInsideCodeBlock, isSelectionEntirelyInsideCodeBlock, getLineInfo } from '../ide-ux/line-handling';
|
|
11
11
|
import { insertIndent, outdent, indent, insertNewlineWithIndent } from '../ide-ux/commands';
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
var afterText = getEndOfCurrentLine(state).text;
|
|
21
|
-
|
|
22
|
-
// If text is a closing bracket/quote and we've already inserted it, move the selection after
|
|
23
|
-
if (isCursorBeforeClosingCharacter(afterText) && isClosingCharacter(text) && afterText.startsWith(text)) {
|
|
24
|
-
dispatch(setTextSelection(to + text.length)(state.tr));
|
|
25
|
-
return true;
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
// Automatically add right-hand side bracket when user types the left bracket
|
|
29
|
-
if (shouldAutoCloseBracket(beforeText, afterText)) {
|
|
30
|
-
var _getAutoClosingBracke = getAutoClosingBracketInfo(beforeText + text, afterText),
|
|
31
|
-
left = _getAutoClosingBracke.left,
|
|
32
|
-
right = _getAutoClosingBracke.right;
|
|
33
|
-
if (left && right) {
|
|
34
|
-
var bracketPair = state.schema.text(text + right);
|
|
35
|
-
var tr = state.tr.replaceWith(from, to, bracketPair);
|
|
36
|
-
dispatch(setTextSelection(from + text.length)(tr));
|
|
37
|
-
return true;
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
// Automatically add closing quote when user types a starting quote
|
|
42
|
-
if (shouldAutoCloseQuote(beforeText, afterText)) {
|
|
43
|
-
var _getAutoClosingQuoteI = getAutoClosingQuoteInfo(beforeText + text, afterText),
|
|
44
|
-
leftQuote = _getAutoClosingQuoteI.left,
|
|
45
|
-
rightQuote = _getAutoClosingQuoteI.right;
|
|
46
|
-
if (leftQuote && rightQuote) {
|
|
47
|
-
var quotePair = state.schema.text(text + rightQuote);
|
|
48
|
-
var _tr = state.tr.replaceWith(from, to, quotePair);
|
|
49
|
-
dispatch(setTextSelection(from + text.length)(_tr));
|
|
50
|
-
return true;
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
|
-
}
|
|
54
|
-
return false;
|
|
55
|
-
},
|
|
56
|
-
handleKeyDown: keydownHandler({
|
|
57
|
-
Backspace: function Backspace(state, dispatch) {
|
|
58
|
-
if (isCursorInsideCodeBlock(state)) {
|
|
59
|
-
var $cursor = getCursor(state.selection);
|
|
12
|
+
var ideUX = function ideUX(pluginInjectionApi) {
|
|
13
|
+
return new SafePlugin({
|
|
14
|
+
props: {
|
|
15
|
+
handleTextInput: function handleTextInput(view, from, to, text) {
|
|
16
|
+
var state = view.state,
|
|
17
|
+
dispatch = view.dispatch;
|
|
18
|
+
var compositionPluginState = pluginInjectionApi === null || pluginInjectionApi === void 0 ? void 0 : pluginInjectionApi.dependencies.composition.sharedState.currentState();
|
|
19
|
+
if (isCursorInsideCodeBlock(state) && !(compositionPluginState !== null && compositionPluginState !== void 0 && compositionPluginState.isComposing)) {
|
|
60
20
|
var beforeText = getStartOfCurrentLine(state).text;
|
|
61
21
|
var afterText = getEndOfCurrentLine(state).text;
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
if (leftBracket && rightBracket && hasTrailingMatchingBracket && dispatch) {
|
|
67
|
-
dispatch(state.tr.delete($cursor.pos - leftBracket.length, $cursor.pos + rightBracket.length));
|
|
22
|
+
|
|
23
|
+
// If text is a closing bracket/quote and we've already inserted it, move the selection after
|
|
24
|
+
if (isCursorBeforeClosingCharacter(afterText) && isClosingCharacter(text) && afterText.startsWith(text)) {
|
|
25
|
+
dispatch(setTextSelection(to + text.length)(state.tr));
|
|
68
26
|
return true;
|
|
69
27
|
}
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
28
|
+
|
|
29
|
+
// Automatically add right-hand side bracket when user types the left bracket
|
|
30
|
+
if (shouldAutoCloseBracket(beforeText, afterText)) {
|
|
31
|
+
var _getAutoClosingBracke = getAutoClosingBracketInfo(beforeText + text, afterText),
|
|
32
|
+
left = _getAutoClosingBracke.left,
|
|
33
|
+
right = _getAutoClosingBracke.right;
|
|
34
|
+
if (left && right) {
|
|
35
|
+
var bracketPair = state.schema.text(text + right);
|
|
36
|
+
var tr = state.tr.replaceWith(from, to, bracketPair);
|
|
37
|
+
dispatch(setTextSelection(from + text.length)(tr));
|
|
38
|
+
return true;
|
|
39
|
+
}
|
|
77
40
|
}
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
if (
|
|
85
|
-
|
|
41
|
+
|
|
42
|
+
// Automatically add closing quote when user types a starting quote
|
|
43
|
+
if (shouldAutoCloseQuote(beforeText, afterText)) {
|
|
44
|
+
var _getAutoClosingQuoteI = getAutoClosingQuoteInfo(beforeText + text, afterText),
|
|
45
|
+
leftQuote = _getAutoClosingQuoteI.left,
|
|
46
|
+
rightQuote = _getAutoClosingQuoteI.right;
|
|
47
|
+
if (leftQuote && rightQuote) {
|
|
48
|
+
var quotePair = state.schema.text(text + rightQuote);
|
|
49
|
+
var _tr = state.tr.replaceWith(from, to, quotePair);
|
|
50
|
+
dispatch(setTextSelection(from + text.length)(_tr));
|
|
86
51
|
return true;
|
|
87
52
|
}
|
|
88
53
|
}
|
|
89
54
|
}
|
|
90
55
|
return false;
|
|
91
56
|
},
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
57
|
+
handleKeyDown: keydownHandler({
|
|
58
|
+
Backspace: function Backspace(state, dispatch) {
|
|
59
|
+
if (isCursorInsideCodeBlock(state)) {
|
|
60
|
+
var $cursor = getCursor(state.selection);
|
|
61
|
+
var beforeText = getStartOfCurrentLine(state).text;
|
|
62
|
+
var afterText = getEndOfCurrentLine(state).text;
|
|
63
|
+
var _getAutoClosingBracke2 = getAutoClosingBracketInfo(beforeText, afterText),
|
|
64
|
+
leftBracket = _getAutoClosingBracke2.left,
|
|
65
|
+
rightBracket = _getAutoClosingBracke2.right,
|
|
66
|
+
hasTrailingMatchingBracket = _getAutoClosingBracke2.hasTrailingMatchingBracket;
|
|
67
|
+
if (leftBracket && rightBracket && hasTrailingMatchingBracket && dispatch) {
|
|
68
|
+
dispatch(state.tr.delete($cursor.pos - leftBracket.length, $cursor.pos + rightBracket.length));
|
|
69
|
+
return true;
|
|
70
|
+
}
|
|
71
|
+
var _getAutoClosingQuoteI2 = getAutoClosingQuoteInfo(beforeText, afterText),
|
|
72
|
+
leftQuote = _getAutoClosingQuoteI2.left,
|
|
73
|
+
rightQuote = _getAutoClosingQuoteI2.right,
|
|
74
|
+
hasTrailingMatchingQuote = _getAutoClosingQuoteI2.hasTrailingMatchingQuote;
|
|
75
|
+
if (leftQuote && rightQuote && hasTrailingMatchingQuote && dispatch) {
|
|
76
|
+
dispatch(state.tr.delete($cursor.pos - leftQuote.length, $cursor.pos + rightQuote.length));
|
|
77
|
+
return true;
|
|
78
|
+
}
|
|
79
|
+
var _getLineInfo = getLineInfo(beforeText),
|
|
80
|
+
_getLineInfo$indentTo = _getLineInfo.indentToken,
|
|
81
|
+
size = _getLineInfo$indentTo.size,
|
|
82
|
+
token = _getLineInfo$indentTo.token,
|
|
83
|
+
indentText = _getLineInfo.indentText;
|
|
84
|
+
if (beforeText === indentText) {
|
|
85
|
+
if (indentText.endsWith(token.repeat(size)) && dispatch) {
|
|
86
|
+
dispatch(state.tr.delete($cursor.pos - (size - indentText.length % size || size), $cursor.pos));
|
|
87
|
+
return true;
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
}
|
|
97
91
|
return false;
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
$from = _state$selection.$from,
|
|
109
|
-
$to = _state$selection.$to;
|
|
110
|
-
var isFullCodeBlockSelection = $from.parentOffset === 0 && $to.parentOffset === $to.parent.nodeSize - 2;
|
|
111
|
-
if (!isFullCodeBlockSelection && dispatch) {
|
|
112
|
-
dispatch(state.tr.setSelection(TextSelection.create(state.doc, $from.start(), $to.end())));
|
|
113
|
-
return true;
|
|
92
|
+
},
|
|
93
|
+
Enter: filter(isSelectionEntirelyInsideCodeBlock, insertNewlineWithIndent),
|
|
94
|
+
'Mod-]': filter(isSelectionEntirelyInsideCodeBlock, indent),
|
|
95
|
+
'Mod-[': filter(isSelectionEntirelyInsideCodeBlock, outdent),
|
|
96
|
+
Tab: filter(isSelectionEntirelyInsideCodeBlock, function (state, dispatch) {
|
|
97
|
+
if (!dispatch) {
|
|
98
|
+
return false;
|
|
99
|
+
}
|
|
100
|
+
if (isCursorInsideCodeBlock(state)) {
|
|
101
|
+
return insertIndent(state, dispatch);
|
|
114
102
|
}
|
|
103
|
+
return indent(state, dispatch);
|
|
104
|
+
}),
|
|
105
|
+
'Shift-Tab': filter(isSelectionEntirelyInsideCodeBlock, outdent),
|
|
106
|
+
'Mod-a': function ModA(state, dispatch) {
|
|
107
|
+
if (isSelectionEntirelyInsideCodeBlock(state)) {
|
|
108
|
+
var _state$selection = state.selection,
|
|
109
|
+
$from = _state$selection.$from,
|
|
110
|
+
$to = _state$selection.$to;
|
|
111
|
+
var isFullCodeBlockSelection = $from.parentOffset === 0 && $to.parentOffset === $to.parent.nodeSize - 2;
|
|
112
|
+
if (!isFullCodeBlockSelection && dispatch) {
|
|
113
|
+
dispatch(state.tr.setSelection(TextSelection.create(state.doc, $from.start(), $to.end())));
|
|
114
|
+
return true;
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
return false;
|
|
115
118
|
}
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
119
|
+
})
|
|
120
|
+
}
|
|
121
|
+
});
|
|
122
|
+
};
|
|
123
|
+
export default ideUX;
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import createPlugin from './pm-plugins/main';
|
|
2
|
+
import { pluginKey } from './pm-plugins/plugin-key';
|
|
3
|
+
var composition = function composition() {
|
|
4
|
+
return {
|
|
5
|
+
name: 'composition',
|
|
6
|
+
getSharedState: function getSharedState(editorState) {
|
|
7
|
+
var _pluginKey$getState;
|
|
8
|
+
if (!editorState) {
|
|
9
|
+
return undefined;
|
|
10
|
+
}
|
|
11
|
+
return {
|
|
12
|
+
isComposing: !!((_pluginKey$getState = pluginKey.getState(editorState)) !== null && _pluginKey$getState !== void 0 && _pluginKey$getState.isComposing)
|
|
13
|
+
};
|
|
14
|
+
},
|
|
15
|
+
pmPlugins: function pmPlugins() {
|
|
16
|
+
return [{
|
|
17
|
+
name: 'composition',
|
|
18
|
+
plugin: function plugin() {
|
|
19
|
+
return createPlugin();
|
|
20
|
+
}
|
|
21
|
+
}];
|
|
22
|
+
}
|
|
23
|
+
};
|
|
24
|
+
};
|
|
25
|
+
export default composition;
|