@atlaskit/editor-core 188.13.1 → 188.13.3
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 +12 -0
- package/dist/cjs/plugins/code-block/actions.js +27 -25
- package/dist/cjs/plugins/code-block/ide-ux/commands.js +64 -60
- package/dist/cjs/plugins/code-block/index.js +1 -1
- package/dist/cjs/plugins/code-block/pm-plugins/ide-ux.js +6 -4
- package/dist/cjs/plugins/code-block/toolbar.js +8 -5
- package/dist/cjs/plugins/layout/actions.js +53 -50
- package/dist/cjs/plugins/layout/index.js +1 -2
- package/dist/cjs/plugins/layout/toolbar.js +10 -6
- package/dist/cjs/plugins/panel/actions.js +59 -56
- package/dist/cjs/plugins/panel/index.js +18 -10
- package/dist/cjs/plugins/panel/toolbar.js +11 -11
- package/dist/cjs/plugins/undo-redo/pm-plugins/keymaps.js +10 -1
- package/dist/cjs/version-wrapper.js +1 -1
- package/dist/es2019/plugins/code-block/actions.js +4 -4
- package/dist/es2019/plugins/code-block/ide-ux/commands.js +9 -9
- package/dist/es2019/plugins/code-block/index.js +1 -1
- package/dist/es2019/plugins/code-block/pm-plugins/ide-ux.js +6 -4
- package/dist/es2019/plugins/code-block/toolbar.js +7 -3
- package/dist/es2019/plugins/layout/actions.js +6 -7
- package/dist/es2019/plugins/layout/index.js +1 -2
- package/dist/es2019/plugins/layout/toolbar.js +10 -5
- package/dist/es2019/plugins/panel/actions.js +8 -7
- package/dist/es2019/plugins/panel/index.js +18 -10
- package/dist/es2019/plugins/panel/toolbar.js +11 -11
- package/dist/es2019/plugins/undo-redo/pm-plugins/keymaps.js +11 -2
- package/dist/es2019/version-wrapper.js +1 -1
- package/dist/esm/plugins/code-block/actions.js +27 -25
- package/dist/esm/plugins/code-block/ide-ux/commands.js +62 -58
- package/dist/esm/plugins/code-block/index.js +1 -1
- package/dist/esm/plugins/code-block/pm-plugins/ide-ux.js +6 -4
- package/dist/esm/plugins/code-block/toolbar.js +8 -5
- package/dist/esm/plugins/layout/actions.js +53 -50
- package/dist/esm/plugins/layout/index.js +1 -2
- package/dist/esm/plugins/layout/toolbar.js +10 -6
- package/dist/esm/plugins/panel/actions.js +59 -56
- package/dist/esm/plugins/panel/index.js +18 -10
- package/dist/esm/plugins/panel/toolbar.js +11 -11
- package/dist/esm/plugins/undo-redo/pm-plugins/keymaps.js +11 -2
- package/dist/esm/version-wrapper.js +1 -1
- package/dist/types/plugins/code-block/actions.d.ts +1 -1
- package/dist/types/plugins/code-block/ide-ux/commands.d.ts +4 -3
- package/dist/types/plugins/code-block/toolbar.d.ts +3 -3
- package/dist/types/plugins/layout/actions.d.ts +2 -2
- package/dist/types/plugins/layout/toolbar.d.ts +3 -3
- package/dist/types/plugins/panel/actions.d.ts +4 -4
- package/dist/types/plugins/panel/index.d.ts +1 -1
- package/dist/types/plugins/undo-redo/pm-plugins/keymaps.d.ts +1 -1
- package/dist/types-ts4.5/plugins/code-block/actions.d.ts +1 -1
- package/dist/types-ts4.5/plugins/code-block/ide-ux/commands.d.ts +4 -3
- package/dist/types-ts4.5/plugins/code-block/toolbar.d.ts +3 -3
- package/dist/types-ts4.5/plugins/layout/actions.d.ts +2 -2
- package/dist/types-ts4.5/plugins/layout/toolbar.d.ts +3 -3
- package/dist/types-ts4.5/plugins/panel/actions.d.ts +4 -4
- package/dist/types-ts4.5/plugins/panel/index.d.ts +1 -1
- package/dist/types-ts4.5/plugins/undo-redo/pm-plugins/keymaps.d.ts +1 -1
- package/package.json +2 -2
|
@@ -48,7 +48,7 @@ export const getToolbarItems = (formatMessage, panelNodeType, isCustomPanelEnabl
|
|
|
48
48
|
id: 'editor.panel.info',
|
|
49
49
|
type: 'button',
|
|
50
50
|
icon: InfoIcon,
|
|
51
|
-
onClick: changePanelType(PanelType.INFO),
|
|
51
|
+
onClick: changePanelType(editorAnalyticsAPI)(PanelType.INFO),
|
|
52
52
|
selected: activePanelType === PanelType.INFO,
|
|
53
53
|
title: formatMessage(messages.info),
|
|
54
54
|
tabIndex: null
|
|
@@ -56,7 +56,7 @@ export const getToolbarItems = (formatMessage, panelNodeType, isCustomPanelEnabl
|
|
|
56
56
|
id: 'editor.panel.note',
|
|
57
57
|
type: 'button',
|
|
58
58
|
icon: NoteIcon,
|
|
59
|
-
onClick: changePanelType(PanelType.NOTE),
|
|
59
|
+
onClick: changePanelType(editorAnalyticsAPI)(PanelType.NOTE),
|
|
60
60
|
selected: activePanelType === PanelType.NOTE,
|
|
61
61
|
title: formatMessage(messages.note),
|
|
62
62
|
tabIndex: null
|
|
@@ -64,7 +64,7 @@ export const getToolbarItems = (formatMessage, panelNodeType, isCustomPanelEnabl
|
|
|
64
64
|
id: 'editor.panel.success',
|
|
65
65
|
type: 'button',
|
|
66
66
|
icon: SuccessIcon,
|
|
67
|
-
onClick: changePanelType(PanelType.SUCCESS),
|
|
67
|
+
onClick: changePanelType(editorAnalyticsAPI)(PanelType.SUCCESS),
|
|
68
68
|
selected: activePanelType === PanelType.SUCCESS,
|
|
69
69
|
title: formatMessage(messages.success),
|
|
70
70
|
tabIndex: null
|
|
@@ -72,7 +72,7 @@ export const getToolbarItems = (formatMessage, panelNodeType, isCustomPanelEnabl
|
|
|
72
72
|
id: 'editor.panel.warning',
|
|
73
73
|
type: 'button',
|
|
74
74
|
icon: WarningIcon,
|
|
75
|
-
onClick: changePanelType(PanelType.WARNING),
|
|
75
|
+
onClick: changePanelType(editorAnalyticsAPI)(PanelType.WARNING),
|
|
76
76
|
selected: activePanelType === PanelType.WARNING,
|
|
77
77
|
title: formatMessage(messages.warning),
|
|
78
78
|
tabIndex: null
|
|
@@ -80,7 +80,7 @@ export const getToolbarItems = (formatMessage, panelNodeType, isCustomPanelEnabl
|
|
|
80
80
|
id: 'editor.panel.error',
|
|
81
81
|
type: 'button',
|
|
82
82
|
icon: ErrorIcon,
|
|
83
|
-
onClick: changePanelType(PanelType.ERROR),
|
|
83
|
+
onClick: changePanelType(editorAnalyticsAPI)(PanelType.ERROR),
|
|
84
84
|
selected: activePanelType === PanelType.ERROR,
|
|
85
85
|
title: formatMessage(messages.error),
|
|
86
86
|
tabIndex: null
|
|
@@ -99,7 +99,7 @@ export const getToolbarItems = (formatMessage, panelNodeType, isCustomPanelEnabl
|
|
|
99
99
|
emojiId: panelEmoji.id
|
|
100
100
|
} : {};
|
|
101
101
|
if (previousColor === color) {
|
|
102
|
-
changePanelType(PanelType.CUSTOM, {
|
|
102
|
+
changePanelType(editorAnalyticsAPI)(PanelType.CUSTOM, {
|
|
103
103
|
color,
|
|
104
104
|
...previousEmoji
|
|
105
105
|
}, isCustomPanelEnabled)(state, dispatch);
|
|
@@ -115,7 +115,7 @@ export const getToolbarItems = (formatMessage, panelNodeType, isCustomPanelEnabl
|
|
|
115
115
|
},
|
|
116
116
|
eventType: EVENT_TYPE.TRACK
|
|
117
117
|
};
|
|
118
|
-
withAnalytics(editorAnalyticsAPI, payload)(changePanelType(PanelType.CUSTOM, {
|
|
118
|
+
withAnalytics(editorAnalyticsAPI, payload)(changePanelType(editorAnalyticsAPI)(PanelType.CUSTOM, {
|
|
119
119
|
color,
|
|
120
120
|
...previousEmoji
|
|
121
121
|
}, isCustomPanelEnabled))(state, dispatch);
|
|
@@ -128,7 +128,7 @@ export const getToolbarItems = (formatMessage, panelNodeType, isCustomPanelEnabl
|
|
|
128
128
|
}
|
|
129
129
|
let previousIcon = panelNode.node.attrs.panelIcon || '';
|
|
130
130
|
if (previousIcon === emoji.shortName) {
|
|
131
|
-
changePanelType(PanelType.CUSTOM, {
|
|
131
|
+
changePanelType(editorAnalyticsAPI)(PanelType.CUSTOM, {
|
|
132
132
|
emoji: emoji.shortName,
|
|
133
133
|
emojiId: emoji.id,
|
|
134
134
|
emojiText: emoji.fallback
|
|
@@ -145,7 +145,7 @@ export const getToolbarItems = (formatMessage, panelNodeType, isCustomPanelEnabl
|
|
|
145
145
|
},
|
|
146
146
|
eventType: EVENT_TYPE.TRACK
|
|
147
147
|
};
|
|
148
|
-
withAnalytics(editorAnalyticsAPI, payload)(changePanelType(PanelType.CUSTOM, {
|
|
148
|
+
withAnalytics(editorAnalyticsAPI, payload)(changePanelType(editorAnalyticsAPI)(PanelType.CUSTOM, {
|
|
149
149
|
emoji: emoji.shortName,
|
|
150
150
|
emojiId: emoji.id,
|
|
151
151
|
emojiText: emoji.fallback
|
|
@@ -169,7 +169,7 @@ export const getToolbarItems = (formatMessage, panelNodeType, isCustomPanelEnabl
|
|
|
169
169
|
},
|
|
170
170
|
eventType: EVENT_TYPE.TRACK
|
|
171
171
|
};
|
|
172
|
-
withAnalytics(editorAnalyticsAPI, payload)(changePanelType(PanelType.CUSTOM, {
|
|
172
|
+
withAnalytics(editorAnalyticsAPI, payload)(changePanelType(editorAnalyticsAPI)(PanelType.CUSTOM, {
|
|
173
173
|
emoji: undefined,
|
|
174
174
|
emojiId: undefined,
|
|
175
175
|
emojiText: undefined
|
|
@@ -234,7 +234,7 @@ export const getToolbarItems = (formatMessage, panelNodeType, isCustomPanelEnabl
|
|
|
234
234
|
appearance: 'danger',
|
|
235
235
|
focusEditoronEnter: true,
|
|
236
236
|
icon: RemoveIcon,
|
|
237
|
-
onClick: removePanel(),
|
|
237
|
+
onClick: removePanel(editorAnalyticsAPI),
|
|
238
238
|
onMouseEnter: hoverDecoration === null || hoverDecoration === void 0 ? void 0 : hoverDecoration(panelNodeType, true),
|
|
239
239
|
onMouseLeave: hoverDecoration === null || hoverDecoration === void 0 ? void 0 : hoverDecoration(panelNodeType, false),
|
|
240
240
|
onFocus: hoverDecoration === null || hoverDecoration === void 0 ? void 0 : hoverDecoration(panelNodeType, true),
|
|
@@ -1,8 +1,17 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { SafePlugin } from '@atlaskit/editor-common/safe-plugin';
|
|
2
|
+
import { undo, redo, bindKeymapWithCommand, findKeyMapForBrowser, isCapsLockOnAndModifyKeyboardEvent } from '@atlaskit/editor-common/keymaps';
|
|
2
3
|
import { redoFromKeyboard, undoFromKeyboard } from '../commands';
|
|
4
|
+
import { keydownHandler } from '@atlaskit/editor-prosemirror/keymap';
|
|
3
5
|
export function keymapPlugin() {
|
|
4
6
|
const list = {};
|
|
5
7
|
bindKeymapWithCommand(findKeyMapForBrowser(redo), redoFromKeyboard, list);
|
|
6
8
|
bindKeymapWithCommand(undo.common, undoFromKeyboard, list);
|
|
7
|
-
return
|
|
9
|
+
return new SafePlugin({
|
|
10
|
+
props: {
|
|
11
|
+
handleKeyDown(view, event) {
|
|
12
|
+
let keyboardEvent = isCapsLockOnAndModifyKeyboardEvent(event);
|
|
13
|
+
return keydownHandler(list)(view, keyboardEvent);
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
});
|
|
8
17
|
}
|
|
@@ -4,7 +4,6 @@ import { pluginKey } from './plugin-key';
|
|
|
4
4
|
import { copySelectionPluginKey } from './pm-plugins/codeBlockCopySelectionPlugin';
|
|
5
5
|
import { ACTIONS } from './pm-plugins/actions';
|
|
6
6
|
import { copyToClipboard } from '../../utils/clipboard';
|
|
7
|
-
import { addAnalytics } from '../analytics/utils';
|
|
8
7
|
import { shouldSplitSelectedNodeOnNodeInsertion } from '@atlaskit/editor-common/insert';
|
|
9
8
|
import { transformToCodeBlockAction } from './transform-to-code-block';
|
|
10
9
|
import { withAnalytics } from '@atlaskit/editor-common/editor-analytics';
|
|
@@ -23,30 +22,33 @@ export var removeCodeBlock = function removeCodeBlock(state, dispatch) {
|
|
|
23
22
|
}
|
|
24
23
|
return true;
|
|
25
24
|
};
|
|
26
|
-
export var changeLanguage = function changeLanguage(
|
|
27
|
-
return function (
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
dispatch
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
25
|
+
export var changeLanguage = function changeLanguage(editorAnalyticsAPI) {
|
|
26
|
+
return function (language) {
|
|
27
|
+
return function (state, dispatch) {
|
|
28
|
+
var _pluginKey$getState;
|
|
29
|
+
var codeBlock = state.schema.nodes.codeBlock;
|
|
30
|
+
var pos = (_pluginKey$getState = pluginKey.getState(state)) === null || _pluginKey$getState === void 0 ? void 0 : _pluginKey$getState.pos;
|
|
31
|
+
if (typeof pos !== 'number') {
|
|
32
|
+
return false;
|
|
33
|
+
}
|
|
34
|
+
var tr = state.tr.setNodeMarkup(pos, codeBlock, {
|
|
35
|
+
language: language
|
|
36
|
+
}).setMeta('scrollIntoView', false);
|
|
37
|
+
var selection = isNodeSelection(state.selection) ? NodeSelection.create(tr.doc, pos) : tr.selection;
|
|
38
|
+
var result = tr.setSelection(selection);
|
|
39
|
+
if (dispatch) {
|
|
40
|
+
editorAnalyticsAPI === null || editorAnalyticsAPI === void 0 || editorAnalyticsAPI.attachAnalyticsEvent({
|
|
41
|
+
action: ACTION.LANGUAGE_SELECTED,
|
|
42
|
+
actionSubject: ACTION_SUBJECT.CODE_BLOCK,
|
|
43
|
+
attributes: {
|
|
44
|
+
language: language
|
|
45
|
+
},
|
|
46
|
+
eventType: EVENT_TYPE.TRACK
|
|
47
|
+
})(result);
|
|
48
|
+
dispatch(result);
|
|
49
|
+
}
|
|
50
|
+
return true;
|
|
51
|
+
};
|
|
50
52
|
};
|
|
51
53
|
};
|
|
52
54
|
export var copyContentToClipboard = function copyContentToClipboard(state, dispatch) {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { TextSelection } from '@atlaskit/editor-prosemirror/state';
|
|
2
2
|
import { getLinesFromSelection, getLineInfo, forEachLine, getStartOfCurrentLine } from './line-handling';
|
|
3
|
-
import {
|
|
3
|
+
import { ACTION, ACTION_SUBJECT_ID, EVENT_TYPE, INPUT_METHOD, INDENT_DIRECTION, INDENT_TYPE, ACTION_SUBJECT } from '@atlaskit/editor-common/analytics';
|
|
4
4
|
/**
|
|
5
5
|
* Return the current indentation level
|
|
6
6
|
* @param indentText - Text in the code block that represent an indentation
|
|
@@ -12,55 +12,21 @@ function getIndentLevel(indentText, indentSize) {
|
|
|
12
12
|
}
|
|
13
13
|
return indentText.length / indentSize;
|
|
14
14
|
}
|
|
15
|
-
export function indent(
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
var indentToAdd = indentToken.token.repeat(indentToken.size - indentText.length % indentToken.size || indentToken.size);
|
|
27
|
-
tr.insertText(indentToAdd, tr.mapping.map(start + offset, -1));
|
|
28
|
-
addAnalytics(state, tr, {
|
|
29
|
-
action: ACTION.FORMATTED,
|
|
30
|
-
actionSubject: ACTION_SUBJECT.TEXT,
|
|
31
|
-
actionSubjectId: ACTION_SUBJECT_ID.FORMAT_INDENT,
|
|
32
|
-
eventType: EVENT_TYPE.TRACK,
|
|
33
|
-
attributes: {
|
|
34
|
-
inputMethod: INPUT_METHOD.KEYBOARD,
|
|
35
|
-
previousIndentationLevel: indentLevel,
|
|
36
|
-
newIndentLevel: indentLevel + 1,
|
|
37
|
-
direction: INDENT_DIRECTION.INDENT,
|
|
38
|
-
indentType: INDENT_TYPE.CODE_BLOCK
|
|
39
|
-
}
|
|
40
|
-
});
|
|
41
|
-
if (!selection.empty) {
|
|
42
|
-
tr.setSelection(TextSelection.create(tr.doc, tr.mapping.map(selection.from, -1), tr.selection.to));
|
|
43
|
-
}
|
|
44
|
-
});
|
|
45
|
-
if (dispatch) {
|
|
46
|
-
dispatch(tr);
|
|
47
|
-
}
|
|
48
|
-
return true;
|
|
49
|
-
}
|
|
50
|
-
export function outdent(state, dispatch) {
|
|
51
|
-
var _getLinesFromSelectio2 = getLinesFromSelection(state),
|
|
52
|
-
text = _getLinesFromSelectio2.text,
|
|
53
|
-
start = _getLinesFromSelectio2.start;
|
|
54
|
-
var tr = state.tr;
|
|
55
|
-
forEachLine(text, function (line, offset) {
|
|
56
|
-
var _getLineInfo2 = getLineInfo(line),
|
|
57
|
-
indentText = _getLineInfo2.indentText,
|
|
58
|
-
indentToken = _getLineInfo2.indentToken;
|
|
59
|
-
if (indentText) {
|
|
15
|
+
export var indent = function indent(editorAnalyticsAPI) {
|
|
16
|
+
return function (state, dispatch) {
|
|
17
|
+
var _getLinesFromSelectio = getLinesFromSelection(state),
|
|
18
|
+
text = _getLinesFromSelectio.text,
|
|
19
|
+
start = _getLinesFromSelectio.start;
|
|
20
|
+
var tr = state.tr,
|
|
21
|
+
selection = state.selection;
|
|
22
|
+
forEachLine(text, function (line, offset) {
|
|
23
|
+
var _getLineInfo = getLineInfo(line),
|
|
24
|
+
indentText = _getLineInfo.indentText,
|
|
25
|
+
indentToken = _getLineInfo.indentToken;
|
|
60
26
|
var indentLevel = getIndentLevel(indentText, indentToken.size);
|
|
61
|
-
var
|
|
62
|
-
tr.
|
|
63
|
-
|
|
27
|
+
var indentToAdd = indentToken.token.repeat(indentToken.size - indentText.length % indentToken.size || indentToken.size);
|
|
28
|
+
tr.insertText(indentToAdd, tr.mapping.map(start + offset, -1));
|
|
29
|
+
editorAnalyticsAPI === null || editorAnalyticsAPI === void 0 || editorAnalyticsAPI.attachAnalyticsEvent({
|
|
64
30
|
action: ACTION.FORMATTED,
|
|
65
31
|
actionSubject: ACTION_SUBJECT.TEXT,
|
|
66
32
|
actionSubjectId: ACTION_SUBJECT_ID.FORMAT_INDENT,
|
|
@@ -68,18 +34,56 @@ export function outdent(state, dispatch) {
|
|
|
68
34
|
attributes: {
|
|
69
35
|
inputMethod: INPUT_METHOD.KEYBOARD,
|
|
70
36
|
previousIndentationLevel: indentLevel,
|
|
71
|
-
newIndentLevel: indentLevel
|
|
72
|
-
direction: INDENT_DIRECTION.
|
|
37
|
+
newIndentLevel: indentLevel + 1,
|
|
38
|
+
direction: INDENT_DIRECTION.INDENT,
|
|
73
39
|
indentType: INDENT_TYPE.CODE_BLOCK
|
|
74
40
|
}
|
|
75
|
-
});
|
|
41
|
+
})(tr);
|
|
42
|
+
if (!selection.empty) {
|
|
43
|
+
tr.setSelection(TextSelection.create(tr.doc, tr.mapping.map(selection.from, -1), tr.selection.to));
|
|
44
|
+
}
|
|
45
|
+
});
|
|
46
|
+
if (dispatch) {
|
|
47
|
+
dispatch(tr);
|
|
76
48
|
}
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
return
|
|
82
|
-
|
|
49
|
+
return true;
|
|
50
|
+
};
|
|
51
|
+
};
|
|
52
|
+
export var outdent = function outdent(editorAnalyticsAPI) {
|
|
53
|
+
return function (state, dispatch) {
|
|
54
|
+
var _getLinesFromSelectio2 = getLinesFromSelection(state),
|
|
55
|
+
text = _getLinesFromSelectio2.text,
|
|
56
|
+
start = _getLinesFromSelectio2.start;
|
|
57
|
+
var tr = state.tr;
|
|
58
|
+
forEachLine(text, function (line, offset) {
|
|
59
|
+
var _getLineInfo2 = getLineInfo(line),
|
|
60
|
+
indentText = _getLineInfo2.indentText,
|
|
61
|
+
indentToken = _getLineInfo2.indentToken;
|
|
62
|
+
if (indentText) {
|
|
63
|
+
var indentLevel = getIndentLevel(indentText, indentToken.size);
|
|
64
|
+
var unindentLength = indentText.length % indentToken.size || indentToken.size;
|
|
65
|
+
tr.delete(tr.mapping.map(start + offset), tr.mapping.map(start + offset + unindentLength));
|
|
66
|
+
editorAnalyticsAPI === null || editorAnalyticsAPI === void 0 || editorAnalyticsAPI.attachAnalyticsEvent({
|
|
67
|
+
action: ACTION.FORMATTED,
|
|
68
|
+
actionSubject: ACTION_SUBJECT.TEXT,
|
|
69
|
+
actionSubjectId: ACTION_SUBJECT_ID.FORMAT_INDENT,
|
|
70
|
+
eventType: EVENT_TYPE.TRACK,
|
|
71
|
+
attributes: {
|
|
72
|
+
inputMethod: INPUT_METHOD.KEYBOARD,
|
|
73
|
+
previousIndentationLevel: indentLevel,
|
|
74
|
+
newIndentLevel: indentLevel - 1,
|
|
75
|
+
direction: INDENT_DIRECTION.OUTDENT,
|
|
76
|
+
indentType: INDENT_TYPE.CODE_BLOCK
|
|
77
|
+
}
|
|
78
|
+
})(tr);
|
|
79
|
+
}
|
|
80
|
+
});
|
|
81
|
+
if (dispatch) {
|
|
82
|
+
dispatch(tr);
|
|
83
|
+
}
|
|
84
|
+
return true;
|
|
85
|
+
};
|
|
86
|
+
};
|
|
83
87
|
export function insertIndent(state, dispatch) {
|
|
84
88
|
var _getStartOfCurrentLin = getStartOfCurrentLine(state),
|
|
85
89
|
textAtStartOfLine = _getStartOfCurrentLin.text;
|
|
@@ -106,7 +106,7 @@ var codeBlockPlugin = function codeBlockPlugin(_ref) {
|
|
|
106
106
|
}
|
|
107
107
|
}];
|
|
108
108
|
},
|
|
109
|
-
floatingToolbar: getToolbarConfig(options === null || options === void 0 ? void 0 : options.allowCopyToClipboard, api
|
|
109
|
+
floatingToolbar: getToolbarConfig(options === null || options === void 0 ? void 0 : options.allowCopyToClipboard, api)
|
|
110
110
|
}
|
|
111
111
|
};
|
|
112
112
|
};
|
|
@@ -10,6 +10,8 @@ import { getAutoClosingQuoteInfo, shouldAutoCloseQuote } from '../ide-ux/quote-h
|
|
|
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
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;
|
|
13
15
|
return new SafePlugin({
|
|
14
16
|
props: {
|
|
15
17
|
handleTextInput: function handleTextInput(view, from, to, text) {
|
|
@@ -92,8 +94,8 @@ var ideUX = function ideUX(pluginInjectionApi) {
|
|
|
92
94
|
return false;
|
|
93
95
|
},
|
|
94
96
|
Enter: filter(isSelectionEntirelyInsideCodeBlock, insertNewlineWithIndent),
|
|
95
|
-
'Mod-]': filter(isSelectionEntirelyInsideCodeBlock, indent),
|
|
96
|
-
'Mod-[': filter(isSelectionEntirelyInsideCodeBlock, outdent),
|
|
97
|
+
'Mod-]': filter(isSelectionEntirelyInsideCodeBlock, indent(editorAnalyticsAPI)),
|
|
98
|
+
'Mod-[': filter(isSelectionEntirelyInsideCodeBlock, outdent(editorAnalyticsAPI)),
|
|
97
99
|
Tab: filter(isSelectionEntirelyInsideCodeBlock, function (state, dispatch) {
|
|
98
100
|
if (!dispatch) {
|
|
99
101
|
return false;
|
|
@@ -101,9 +103,9 @@ var ideUX = function ideUX(pluginInjectionApi) {
|
|
|
101
103
|
if (isCursorInsideCodeBlock(state)) {
|
|
102
104
|
return insertIndent(state, dispatch);
|
|
103
105
|
}
|
|
104
|
-
return indent(state, dispatch);
|
|
106
|
+
return indent(editorAnalyticsAPI)(state, dispatch);
|
|
105
107
|
}),
|
|
106
|
-
'Shift-Tab': filter(isSelectionEntirelyInsideCodeBlock, outdent),
|
|
108
|
+
'Shift-Tab': filter(isSelectionEntirelyInsideCodeBlock, outdent(editorAnalyticsAPI)),
|
|
107
109
|
'Mod-a': function ModA(state, dispatch) {
|
|
108
110
|
if (isSelectionEntirelyInsideCodeBlock(state)) {
|
|
109
111
|
var _state$selection = state.selection,
|
|
@@ -18,10 +18,13 @@ export var messages = defineMessages({
|
|
|
18
18
|
var languageList = createLanguageList(DEFAULT_LANGUAGES);
|
|
19
19
|
export var getToolbarConfig = function getToolbarConfig() {
|
|
20
20
|
var allowCopyToClipboard = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : false;
|
|
21
|
-
var
|
|
21
|
+
var api = arguments.length > 1 ? arguments[1] : undefined;
|
|
22
22
|
return function (state, _ref) {
|
|
23
|
-
var _codeBlockState$pos, _node$attrs;
|
|
23
|
+
var _api$decorations$acti, _api$analytics, _codeBlockState$pos, _node$attrs;
|
|
24
24
|
var formatMessage = _ref.formatMessage;
|
|
25
|
+
var _ref2 = (_api$decorations$acti = api === null || api === void 0 ? void 0 : api.decorations.actions) !== null && _api$decorations$acti !== void 0 ? _api$decorations$acti : {},
|
|
26
|
+
hoverDecoration = _ref2.hoverDecoration;
|
|
27
|
+
var editorAnalyticsAPI = api === null || api === void 0 || (_api$analytics = api.analytics) === null || _api$analytics === void 0 ? void 0 : _api$analytics.actions;
|
|
25
28
|
var codeBlockState = pluginKey.getState(state);
|
|
26
29
|
var pos = (_codeBlockState$pos = codeBlockState === null || codeBlockState === void 0 ? void 0 : codeBlockState.pos) !== null && _codeBlockState$pos !== void 0 ? _codeBlockState$pos : null;
|
|
27
30
|
if (!codeBlockState || pos === null) {
|
|
@@ -52,7 +55,7 @@ export var getToolbarConfig = function getToolbarConfig() {
|
|
|
52
55
|
type: 'select',
|
|
53
56
|
selectType: 'list',
|
|
54
57
|
onChange: function onChange(option) {
|
|
55
|
-
return changeLanguage(option.value);
|
|
58
|
+
return changeLanguage(editorAnalyticsAPI)(option.value);
|
|
56
59
|
},
|
|
57
60
|
defaultValue: defaultValue,
|
|
58
61
|
placeholder: formatMessage(messages.selectLanguage),
|
|
@@ -110,8 +113,8 @@ export var getToolbarConfig = function getToolbarConfig() {
|
|
|
110
113
|
* Filters language list based on both name and alias properties.
|
|
111
114
|
*/
|
|
112
115
|
export var languageListFilter = function languageListFilter(option, rawInput) {
|
|
113
|
-
var
|
|
114
|
-
data =
|
|
116
|
+
var _ref3 = option,
|
|
117
|
+
data = _ref3.data;
|
|
115
118
|
var searchString = rawInput.toLowerCase();
|
|
116
119
|
return data.label.toLowerCase().includes(searchString) || data.alias.some(function (alias) {
|
|
117
120
|
return alias.toLowerCase() === searchString;
|
|
@@ -7,7 +7,6 @@ import { TextSelection, NodeSelection } from '@atlaskit/editor-prosemirror/state
|
|
|
7
7
|
import { flatmap, mapChildren } from '../../utils/slice';
|
|
8
8
|
import { getStepRange, isEmptyDocument } from '@atlaskit/editor-common/utils';
|
|
9
9
|
import { ACTION, ACTION_SUBJECT, ACTION_SUBJECT_ID, EVENT_TYPE } from '@atlaskit/editor-common/analytics';
|
|
10
|
-
import { addAnalytics } from '../analytics/utils';
|
|
11
10
|
import { withAnalytics } from '@atlaskit/editor-common/editor-analytics';
|
|
12
11
|
import { LAYOUT_TYPE } from '../analytics/types/node-events';
|
|
13
12
|
import { pluginKey } from './pm-plugins/plugin-key';
|
|
@@ -201,36 +200,38 @@ export function forceSectionToPresetLayout(state, node, pos, presetLayout) {
|
|
|
201
200
|
var selectionPos$ = tr.doc.resolve(selection.$from.pos);
|
|
202
201
|
return tr.setSelection(state.selection instanceof NodeSelection ? new NodeSelection(selectionPos$) : new TextSelection(selectionPos$));
|
|
203
202
|
}
|
|
204
|
-
export var setPresetLayout = function setPresetLayout(
|
|
205
|
-
return function (
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
var node = state.doc.nodeAt(pos);
|
|
213
|
-
if (!node) {
|
|
214
|
-
return false;
|
|
215
|
-
}
|
|
216
|
-
var tr = forceSectionToPresetLayout(state, node, pos, layout);
|
|
217
|
-
if (tr) {
|
|
218
|
-
tr = addAnalytics(state, tr, {
|
|
219
|
-
action: ACTION.CHANGED_LAYOUT,
|
|
220
|
-
actionSubject: ACTION_SUBJECT.LAYOUT,
|
|
221
|
-
attributes: {
|
|
222
|
-
previousLayout: formatLayoutName(selectedLayout),
|
|
223
|
-
newLayout: formatLayoutName(layout)
|
|
224
|
-
},
|
|
225
|
-
eventType: EVENT_TYPE.TRACK
|
|
226
|
-
});
|
|
227
|
-
tr.setMeta('scrollIntoView', false);
|
|
228
|
-
if (dispatch) {
|
|
229
|
-
dispatch(tr);
|
|
203
|
+
export var setPresetLayout = function setPresetLayout(editorAnalyticsAPI) {
|
|
204
|
+
return function (layout) {
|
|
205
|
+
return function (state, dispatch) {
|
|
206
|
+
var _ref = pluginKey.getState(state),
|
|
207
|
+
pos = _ref.pos,
|
|
208
|
+
selectedLayout = _ref.selectedLayout;
|
|
209
|
+
if (selectedLayout === layout || pos === null) {
|
|
210
|
+
return false;
|
|
230
211
|
}
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
212
|
+
var node = state.doc.nodeAt(pos);
|
|
213
|
+
if (!node) {
|
|
214
|
+
return false;
|
|
215
|
+
}
|
|
216
|
+
var tr = forceSectionToPresetLayout(state, node, pos, layout);
|
|
217
|
+
if (tr) {
|
|
218
|
+
editorAnalyticsAPI === null || editorAnalyticsAPI === void 0 || editorAnalyticsAPI.attachAnalyticsEvent({
|
|
219
|
+
action: ACTION.CHANGED_LAYOUT,
|
|
220
|
+
actionSubject: ACTION_SUBJECT.LAYOUT,
|
|
221
|
+
attributes: {
|
|
222
|
+
previousLayout: formatLayoutName(selectedLayout),
|
|
223
|
+
newLayout: formatLayoutName(layout)
|
|
224
|
+
},
|
|
225
|
+
eventType: EVENT_TYPE.TRACK
|
|
226
|
+
})(tr);
|
|
227
|
+
tr.setMeta('scrollIntoView', false);
|
|
228
|
+
if (dispatch) {
|
|
229
|
+
dispatch(tr);
|
|
230
|
+
}
|
|
231
|
+
return true;
|
|
232
|
+
}
|
|
233
|
+
return false;
|
|
234
|
+
};
|
|
234
235
|
};
|
|
235
236
|
};
|
|
236
237
|
function layoutNeedChanges(node) {
|
|
@@ -295,27 +296,29 @@ export var fixColumnStructure = function fixColumnStructure(state) {
|
|
|
295
296
|
}
|
|
296
297
|
return;
|
|
297
298
|
};
|
|
298
|
-
export var deleteActiveLayoutNode = function deleteActiveLayoutNode(
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
299
|
+
export var deleteActiveLayoutNode = function deleteActiveLayoutNode(editorAnalyticsAPI) {
|
|
300
|
+
return function (state, dispatch) {
|
|
301
|
+
var _ref3 = pluginKey.getState(state),
|
|
302
|
+
pos = _ref3.pos,
|
|
303
|
+
selectedLayout = _ref3.selectedLayout;
|
|
304
|
+
if (pos !== null) {
|
|
305
|
+
var node = state.doc.nodeAt(pos);
|
|
306
|
+
if (dispatch) {
|
|
307
|
+
var tr = state.tr.delete(pos, pos + node.nodeSize);
|
|
308
|
+
editorAnalyticsAPI === null || editorAnalyticsAPI === void 0 || editorAnalyticsAPI.attachAnalyticsEvent({
|
|
309
|
+
action: ACTION.DELETED,
|
|
310
|
+
actionSubject: ACTION_SUBJECT.LAYOUT,
|
|
311
|
+
attributes: {
|
|
312
|
+
layout: formatLayoutName(selectedLayout)
|
|
313
|
+
},
|
|
314
|
+
eventType: EVENT_TYPE.TRACK
|
|
315
|
+
})(tr);
|
|
316
|
+
dispatch(tr);
|
|
317
|
+
}
|
|
318
|
+
return true;
|
|
315
319
|
}
|
|
316
|
-
return
|
|
317
|
-
}
|
|
318
|
-
return false;
|
|
320
|
+
return false;
|
|
321
|
+
};
|
|
319
322
|
};
|
|
320
323
|
var formatLayoutName = function formatLayoutName(layout) {
|
|
321
324
|
switch (layout) {
|
|
@@ -43,8 +43,7 @@ var layoutPlugin = function layoutPlugin(_ref) {
|
|
|
43
43
|
addSidebarLayouts = _ref2.addSidebarLayouts,
|
|
44
44
|
allowSingleColumnLayout = _ref2.allowSingleColumnLayout;
|
|
45
45
|
if (pos !== null) {
|
|
46
|
-
|
|
47
|
-
return buildToolbar(state, intl, pos, allowBreakout, addSidebarLayouts, allowSingleColumnLayout, api === null || api === void 0 || (_api$decorations$acti = api.decorations.actions) === null || _api$decorations$acti === void 0 ? void 0 : _api$decorations$acti.hoverDecoration);
|
|
46
|
+
return buildToolbar(state, intl, pos, allowBreakout, addSidebarLayouts, allowSingleColumnLayout, api);
|
|
48
47
|
}
|
|
49
48
|
return undefined;
|
|
50
49
|
},
|
|
@@ -43,20 +43,24 @@ var SIDEBAR_LAYOUT_TYPES = [{
|
|
|
43
43
|
title: toolbarMessages.threeColumnsWithSidebars,
|
|
44
44
|
icon: LayoutThreeWithSidebarsIcon
|
|
45
45
|
}];
|
|
46
|
-
var buildLayoutButton = function buildLayoutButton(intl, item, currentLayout) {
|
|
46
|
+
var buildLayoutButton = function buildLayoutButton(intl, item, currentLayout, editorAnalyticsAPI) {
|
|
47
47
|
return {
|
|
48
48
|
id: item.id,
|
|
49
49
|
type: 'button',
|
|
50
50
|
icon: item.icon,
|
|
51
51
|
testId: item.title.id,
|
|
52
52
|
title: intl.formatMessage(item.title),
|
|
53
|
-
onClick: setPresetLayout(item.type),
|
|
53
|
+
onClick: setPresetLayout(editorAnalyticsAPI)(item.type),
|
|
54
54
|
selected: !!currentLayout && currentLayout === item.type,
|
|
55
55
|
tabIndex: null
|
|
56
56
|
};
|
|
57
57
|
};
|
|
58
58
|
export var layoutToolbarTitle = 'Layout floating controls';
|
|
59
|
-
export var buildToolbar = function buildToolbar(state, intl, pos, _allowBreakout, addSidebarLayouts, allowSingleColumnLayout,
|
|
59
|
+
export var buildToolbar = function buildToolbar(state, intl, pos, _allowBreakout, addSidebarLayouts, allowSingleColumnLayout, api) {
|
|
60
|
+
var _api$decorations$acti, _api$decorations, _api$analytics;
|
|
61
|
+
var _ref = (_api$decorations$acti = api === null || api === void 0 || (_api$decorations = api.decorations) === null || _api$decorations === void 0 ? void 0 : _api$decorations.actions) !== null && _api$decorations$acti !== void 0 ? _api$decorations$acti : {},
|
|
62
|
+
hoverDecoration = _ref.hoverDecoration;
|
|
63
|
+
var editorAnalyticsAPI = api === null || api === void 0 || (_api$analytics = api.analytics) === null || _api$analytics === void 0 ? void 0 : _api$analytics.actions;
|
|
60
64
|
var node = state.doc.nodeAt(pos);
|
|
61
65
|
if (node) {
|
|
62
66
|
var currentLayout = getPresetLayout(node);
|
|
@@ -72,7 +76,7 @@ export var buildToolbar = function buildToolbar(state, intl, pos, _allowBreakout
|
|
|
72
76
|
icon: RemoveIcon,
|
|
73
77
|
testId: commonMessages.remove.id,
|
|
74
78
|
title: intl.formatMessage(commonMessages.remove),
|
|
75
|
-
onClick: deleteActiveLayoutNode,
|
|
79
|
+
onClick: deleteActiveLayoutNode(editorAnalyticsAPI),
|
|
76
80
|
onMouseEnter: hoverDecoration === null || hoverDecoration === void 0 ? void 0 : hoverDecoration(nodeType, true),
|
|
77
81
|
onMouseLeave: hoverDecoration === null || hoverDecoration === void 0 ? void 0 : hoverDecoration(nodeType, false),
|
|
78
82
|
onFocus: hoverDecoration === null || hoverDecoration === void 0 ? void 0 : hoverDecoration(nodeType, true),
|
|
@@ -87,9 +91,9 @@ export var buildToolbar = function buildToolbar(state, intl, pos, _allowBreakout
|
|
|
87
91
|
},
|
|
88
92
|
nodeType: nodeType,
|
|
89
93
|
items: [].concat(_toConsumableArray(layoutTypes.map(function (i) {
|
|
90
|
-
return buildLayoutButton(intl, i, currentLayout);
|
|
94
|
+
return buildLayoutButton(intl, i, currentLayout, editorAnalyticsAPI);
|
|
91
95
|
})), _toConsumableArray(addSidebarLayouts ? SIDEBAR_LAYOUT_TYPES.map(function (i) {
|
|
92
|
-
return buildLayoutButton(intl, i, currentLayout);
|
|
96
|
+
return buildLayoutButton(intl, i, currentLayout, editorAnalyticsAPI);
|
|
93
97
|
}) : []), [{
|
|
94
98
|
type: 'copy-button',
|
|
95
99
|
items: [separator, {
|