@atlaskit/editor-core 187.9.0 → 187.10.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 +17 -0
- package/dist/cjs/commands/index.js +8 -134
- package/dist/cjs/plugins/base/index.js +2 -2
- package/dist/cjs/plugins/block-type/commands/block-type.js +34 -36
- package/dist/cjs/plugins/block-type/commands/transform-to-code-block.js +1 -2
- package/dist/cjs/plugins/block-type/index.js +16 -13
- package/dist/cjs/plugins/block-type/pm-plugins/input-rule.js +19 -18
- package/dist/cjs/plugins/block-type/pm-plugins/keymap.js +12 -14
- package/dist/cjs/plugins/block-type/pm-plugins/main.js +9 -9
- package/dist/cjs/plugins/block-type/ui/ToolbarBlockType/blocktype-button.js +7 -7
- package/dist/cjs/plugins/block-type/ui/ToolbarBlockType/index.js +3 -4
- package/dist/cjs/plugins/block-type/ui/ToolbarBlockType/styled.js +13 -5
- package/dist/cjs/plugins/block-type/utils.js +73 -2
- package/dist/cjs/plugins/caption/pm-plugins/keymap.js +2 -2
- package/dist/cjs/plugins/emoji/commands/insert-emoji.js +31 -28
- package/dist/cjs/plugins/emoji/index.js +4 -3
- package/dist/cjs/plugins/emoji/pm-plugins/ascii-input-rules.js +23 -18
- package/dist/cjs/plugins/extension/pm-plugins/main.js +54 -9
- package/dist/cjs/plugins/insert-block/ui/ToolbarInsertBlock/index.js +1 -1
- package/dist/cjs/plugins/media/utils/media-common.js +5 -5
- package/dist/cjs/plugins/selection/pm-plugins/events/keydown.js +61 -25
- package/dist/cjs/plugins/undo-redo/pm-plugins/keymaps.js +2 -2
- package/dist/cjs/ui/styles.js +4 -11
- package/dist/cjs/utils/index.js +4 -80
- package/dist/cjs/utils/input-rules.js +6 -66
- package/dist/cjs/utils/mark.js +2 -38
- package/dist/cjs/version-wrapper.js +1 -1
- package/dist/cjs/version.json +1 -1
- package/dist/es2019/commands/index.js +1 -128
- package/dist/es2019/plugins/base/index.js +1 -1
- package/dist/es2019/plugins/block-type/commands/block-type.js +11 -13
- package/dist/es2019/plugins/block-type/commands/transform-to-code-block.js +1 -2
- package/dist/es2019/plugins/block-type/index.js +21 -12
- package/dist/es2019/plugins/block-type/pm-plugins/input-rule.js +18 -18
- package/dist/es2019/plugins/block-type/pm-plugins/keymap.js +8 -9
- package/dist/es2019/plugins/block-type/pm-plugins/main.js +9 -9
- package/dist/es2019/plugins/block-type/ui/ToolbarBlockType/blocktype-button.js +2 -2
- package/dist/es2019/plugins/block-type/ui/ToolbarBlockType/index.js +2 -3
- package/dist/es2019/plugins/block-type/ui/ToolbarBlockType/styled.js +21 -2
- package/dist/es2019/plugins/block-type/utils.js +70 -1
- package/dist/es2019/plugins/caption/pm-plugins/keymap.js +1 -1
- package/dist/es2019/plugins/emoji/commands/insert-emoji.js +5 -5
- package/dist/es2019/plugins/emoji/index.js +6 -3
- package/dist/es2019/plugins/emoji/pm-plugins/ascii-input-rules.js +14 -11
- package/dist/es2019/plugins/extension/pm-plugins/main.js +50 -0
- package/dist/es2019/plugins/insert-block/ui/ToolbarInsertBlock/index.js +1 -1
- package/dist/es2019/plugins/media/utils/media-common.js +1 -1
- package/dist/es2019/plugins/selection/pm-plugins/events/keydown.js +60 -24
- package/dist/es2019/plugins/tasks-and-decisions/pm-plugins/keymaps.js +1 -1
- package/dist/es2019/plugins/undo-redo/pm-plugins/keymaps.js +1 -1
- package/dist/es2019/ui/styles.js +0 -16
- package/dist/es2019/utils/index.js +0 -80
- package/dist/es2019/utils/input-rules.js +4 -61
- package/dist/es2019/utils/mark.js +0 -33
- package/dist/es2019/version-wrapper.js +1 -1
- package/dist/es2019/version.json +1 -1
- package/dist/esm/commands/index.js +7 -125
- package/dist/esm/plugins/base/index.js +1 -1
- package/dist/esm/plugins/block-type/commands/block-type.js +11 -13
- package/dist/esm/plugins/block-type/commands/transform-to-code-block.js +1 -2
- package/dist/esm/plugins/block-type/index.js +15 -12
- package/dist/esm/plugins/block-type/pm-plugins/input-rule.js +18 -18
- package/dist/esm/plugins/block-type/pm-plugins/keymap.js +8 -9
- package/dist/esm/plugins/block-type/pm-plugins/main.js +9 -9
- package/dist/esm/plugins/block-type/ui/ToolbarBlockType/blocktype-button.js +2 -2
- package/dist/esm/plugins/block-type/ui/ToolbarBlockType/index.js +2 -3
- package/dist/esm/plugins/block-type/ui/ToolbarBlockType/styled.js +8 -4
- package/dist/esm/plugins/block-type/utils.js +69 -1
- package/dist/esm/plugins/caption/pm-plugins/keymap.js +1 -1
- package/dist/esm/plugins/emoji/commands/insert-emoji.js +29 -27
- package/dist/esm/plugins/emoji/index.js +4 -3
- package/dist/esm/plugins/emoji/pm-plugins/ascii-input-rules.js +23 -18
- package/dist/esm/plugins/extension/pm-plugins/main.js +45 -0
- package/dist/esm/plugins/insert-block/ui/ToolbarInsertBlock/index.js +1 -1
- package/dist/esm/plugins/media/utils/media-common.js +1 -1
- package/dist/esm/plugins/selection/pm-plugins/events/keydown.js +62 -25
- package/dist/esm/plugins/tasks-and-decisions/pm-plugins/keymaps.js +1 -1
- package/dist/esm/plugins/undo-redo/pm-plugins/keymaps.js +1 -1
- package/dist/esm/ui/styles.js +3 -6
- package/dist/esm/utils/index.js +3 -77
- package/dist/esm/utils/input-rules.js +4 -61
- package/dist/esm/utils/mark.js +0 -35
- package/dist/esm/version-wrapper.js +1 -1
- package/dist/esm/version.json +1 -1
- package/dist/types/commands/index.d.ts +0 -6
- package/dist/types/plugins/block-type/commands/block-type.d.ts +5 -6
- package/dist/types/plugins/block-type/commands/delete-and-move-cursor.d.ts +1 -1
- package/dist/types/plugins/block-type/commands/delete-block-content.d.ts +1 -1
- package/dist/types/plugins/block-type/index.d.ts +1 -1
- package/dist/types/plugins/block-type/pm-plugins/input-rule.d.ts +3 -2
- package/dist/types/plugins/block-type/pm-plugins/keymap.d.ts +2 -2
- package/dist/types/plugins/block-type/pm-plugins/main.d.ts +2 -1
- package/dist/types/plugins/block-type/styles.d.ts +1 -1
- package/dist/types/plugins/block-type/types.d.ts +2 -3
- package/dist/types/plugins/block-type/ui/ToolbarBlockType/blocktype-button.d.ts +1 -2
- package/dist/types/plugins/block-type/ui/ToolbarBlockType/index.d.ts +2 -2
- package/dist/types/plugins/block-type/ui/ToolbarBlockType/styled.d.ts +5 -1
- package/dist/types/plugins/block-type/utils.d.ts +15 -1
- package/dist/types/plugins/emoji/commands/insert-emoji.d.ts +2 -2
- package/dist/types/plugins/emoji/pm-plugins/ascii-input-rules.d.ts +3 -2
- package/dist/types/plugins/extension/pm-plugins/main.d.ts +1 -1
- package/dist/types/plugins/insert-block/ui/ToolbarInsertBlock/index.d.ts +1 -0
- package/dist/types/plugins/undo-redo/pm-plugins/keymaps.d.ts +1 -1
- package/dist/types/types/index.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/ui/styles.d.ts +0 -3
- package/dist/types/utils/index.d.ts +0 -6
- package/dist/types/utils/input-rules.d.ts +4 -16
- package/dist/types/utils/mark.d.ts +0 -1
- package/dist/types-ts4.5/commands/index.d.ts +0 -6
- package/dist/types-ts4.5/plugins/block-type/commands/block-type.d.ts +5 -6
- package/dist/types-ts4.5/plugins/block-type/commands/delete-and-move-cursor.d.ts +1 -1
- package/dist/types-ts4.5/plugins/block-type/commands/delete-block-content.d.ts +1 -1
- package/dist/types-ts4.5/plugins/block-type/index.d.ts +1 -1
- package/dist/types-ts4.5/plugins/block-type/pm-plugins/input-rule.d.ts +3 -2
- package/dist/types-ts4.5/plugins/block-type/pm-plugins/keymap.d.ts +2 -2
- package/dist/types-ts4.5/plugins/block-type/pm-plugins/main.d.ts +2 -1
- package/dist/types-ts4.5/plugins/block-type/styles.d.ts +1 -1
- package/dist/types-ts4.5/plugins/block-type/types.d.ts +2 -3
- package/dist/types-ts4.5/plugins/block-type/ui/ToolbarBlockType/blocktype-button.d.ts +1 -2
- package/dist/types-ts4.5/plugins/block-type/ui/ToolbarBlockType/index.d.ts +2 -2
- package/dist/types-ts4.5/plugins/block-type/ui/ToolbarBlockType/styled.d.ts +5 -1
- package/dist/types-ts4.5/plugins/block-type/utils.d.ts +15 -1
- package/dist/types-ts4.5/plugins/emoji/commands/insert-emoji.d.ts +2 -2
- package/dist/types-ts4.5/plugins/emoji/pm-plugins/ascii-input-rules.d.ts +3 -2
- package/dist/types-ts4.5/plugins/extension/pm-plugins/main.d.ts +1 -1
- package/dist/types-ts4.5/plugins/insert-block/ui/ToolbarInsertBlock/index.d.ts +1 -0
- package/dist/types-ts4.5/plugins/undo-redo/pm-plugins/keymaps.d.ts +1 -1
- package/dist/types-ts4.5/types/index.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/ui/styles.d.ts +0 -3
- package/dist/types-ts4.5/utils/index.d.ts +0 -6
- package/dist/types-ts4.5/utils/input-rules.d.ts +4 -16
- package/dist/types-ts4.5/utils/mark.d.ts +0 -1
- package/package.json +4 -4
- package/report.api.md +6 -16
- package/tmp/api-report-tmp.d.ts +5 -16
- package/dist/cjs/types/allowed-block-types.js +0 -5
- package/dist/cjs/utils/keymap.js +0 -38
- package/dist/es2019/types/allowed-block-types.js +0 -1
- package/dist/es2019/utils/keymap.js +0 -33
- package/dist/esm/types/allowed-block-types.js +0 -1
- package/dist/esm/utils/keymap.js +0 -33
- package/dist/types/types/allowed-block-types.d.ts +0 -1
- package/dist/types/utils/keymap.d.ts +0 -11
- package/dist/types-ts4.5/types/allowed-block-types.d.ts +0 -1
- package/dist/types-ts4.5/utils/keymap.d.ts +0 -11
- /package/dist/cjs/{keymaps → plugins/block-type}/consts.js +0 -0
- /package/dist/es2019/{keymaps → plugins/block-type}/consts.js +0 -0
- /package/dist/esm/{keymaps → plugins/block-type}/consts.js +0 -0
- /package/dist/types/{keymaps → plugins/block-type}/consts.d.ts +0 -0
- /package/dist/types-ts4.5/{keymaps → plugins/block-type}/consts.d.ts +0 -0
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { TextSelection } from '@atlaskit/editor-prosemirror/state';
|
|
2
|
-
import { mapSlice } from '../../../utils/slice';
|
|
3
2
|
import { Fragment } from '@atlaskit/editor-prosemirror/model';
|
|
4
|
-
import { timestampToString } from '@atlaskit/editor-common/utils';
|
|
3
|
+
import { timestampToString, mapSlice } from '@atlaskit/editor-common/utils';
|
|
5
4
|
export function transformToCodeBlockAction(state, start, attrs) {
|
|
6
5
|
const startOfCodeBlockText = state.selection.$from;
|
|
7
6
|
const endPosition = state.selection.empty ? startOfCodeBlockText.end() : state.selection.$to.pos;
|
|
@@ -1,16 +1,16 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
import { blockquote, hardBreak, heading } from '@atlaskit/adf-schema';
|
|
3
|
+
import { ToolbarSize } from '@atlaskit/editor-common/types';
|
|
4
|
+
import { WithPluginState } from '@atlaskit/editor-common/with-plugin-state';
|
|
5
|
+
import { ACTION, ACTION_SUBJECT, ACTION_SUBJECT_ID, EVENT_TYPE, INPUT_METHOD } from '@atlaskit/editor-common/analytics';
|
|
6
|
+
import { IconHeading, IconQuote } from '@atlaskit/editor-common/quick-insert';
|
|
7
|
+
import * as keymaps from '@atlaskit/editor-common/keymaps';
|
|
3
8
|
import { createPlugin, pluginKey } from './pm-plugins/main';
|
|
4
9
|
import keymapPlugin from './pm-plugins/keymap';
|
|
5
10
|
import inputRulePlugin from './pm-plugins/input-rule';
|
|
6
11
|
import ToolbarBlockType from './ui/ToolbarBlockType';
|
|
7
|
-
import WithPluginState from '../../ui/WithPluginState';
|
|
8
12
|
import { setBlockTypeWithAnalytics } from './commands';
|
|
9
|
-
import { ACTION, ACTION_SUBJECT, ACTION_SUBJECT_ID, EVENT_TYPE, INPUT_METHOD } from '@atlaskit/editor-common/analytics';
|
|
10
|
-
import * as keymaps from '../../keymaps';
|
|
11
|
-
import { IconHeading, IconQuote } from '@atlaskit/editor-common/quick-insert';
|
|
12
13
|
import { messages } from './messages';
|
|
13
|
-
import { ToolbarSize } from '../../ui/Toolbar/types';
|
|
14
14
|
const headingPluginOptions = ({
|
|
15
15
|
formatMessage
|
|
16
16
|
}, isAllowed, editorAnalyticsApi) => {
|
|
@@ -105,13 +105,19 @@ const blockTypePlugin = (options, api) => ({
|
|
|
105
105
|
name: 'blockType',
|
|
106
106
|
plugin: ({
|
|
107
107
|
dispatch
|
|
108
|
-
}) =>
|
|
108
|
+
}) => {
|
|
109
|
+
var _api$dependencies$ana;
|
|
110
|
+
return createPlugin(api === null || api === void 0 ? void 0 : (_api$dependencies$ana = api.dependencies.analytics) === null || _api$dependencies$ana === void 0 ? void 0 : _api$dependencies$ana.actions, dispatch, options && options.lastNodeMustBeParagraph);
|
|
111
|
+
}
|
|
109
112
|
}, {
|
|
110
113
|
name: 'blockTypeInputRule',
|
|
111
114
|
plugin: ({
|
|
112
115
|
schema,
|
|
113
116
|
featureFlags
|
|
114
|
-
}) =>
|
|
117
|
+
}) => {
|
|
118
|
+
var _api$dependencies$ana2;
|
|
119
|
+
return inputRulePlugin(api === null || api === void 0 ? void 0 : (_api$dependencies$ana2 = api.dependencies.analytics) === null || _api$dependencies$ana2 === void 0 ? void 0 : _api$dependencies$ana2.actions, schema, featureFlags);
|
|
120
|
+
}
|
|
115
121
|
},
|
|
116
122
|
// Needs to be lower priority than editor-tables.tableEditing
|
|
117
123
|
// plugin as it is currently swallowing right/down arrow events inside tables
|
|
@@ -121,8 +127,8 @@ const blockTypePlugin = (options, api) => ({
|
|
|
121
127
|
schema,
|
|
122
128
|
featureFlags
|
|
123
129
|
}) => {
|
|
124
|
-
var _api$dependencies$
|
|
125
|
-
return keymapPlugin(
|
|
130
|
+
var _api$dependencies$ana3;
|
|
131
|
+
return keymapPlugin(api === null || api === void 0 ? void 0 : (_api$dependencies$ana3 = api.dependencies.analytics) === null || _api$dependencies$ana3 === void 0 ? void 0 : _api$dependencies$ana3.actions, schema, featureFlags);
|
|
126
132
|
}
|
|
127
133
|
}];
|
|
128
134
|
},
|
|
@@ -137,7 +143,10 @@ const blockTypePlugin = (options, api) => ({
|
|
|
137
143
|
eventDispatcher
|
|
138
144
|
}) {
|
|
139
145
|
const isSmall = options && options.isUndoRedoButtonsEnabled ? toolbarSize < ToolbarSize.XXL : toolbarSize < ToolbarSize.XL;
|
|
140
|
-
const boundSetBlockType = name =>
|
|
146
|
+
const boundSetBlockType = name => {
|
|
147
|
+
var _api$dependencies$ana4;
|
|
148
|
+
return setBlockTypeWithAnalytics(name, INPUT_METHOD.TOOLBAR, api === null || api === void 0 ? void 0 : (_api$dependencies$ana4 = api.dependencies.analytics) === null || _api$dependencies$ana4 === void 0 ? void 0 : _api$dependencies$ana4.actions)(editorView.state, editorView.dispatch);
|
|
149
|
+
};
|
|
141
150
|
return /*#__PURE__*/React.createElement(WithPluginState, {
|
|
142
151
|
editorView: editorView,
|
|
143
152
|
eventDispatcher: eventDispatcher,
|
|
@@ -162,9 +171,9 @@ const blockTypePlugin = (options, api) => ({
|
|
|
162
171
|
},
|
|
163
172
|
pluginsOptions: {
|
|
164
173
|
quickInsert: intl => {
|
|
165
|
-
var _api$dependencies$
|
|
174
|
+
var _api$dependencies$ana5, _api$dependencies$ana6;
|
|
166
175
|
const exclude = options && options.allowBlockType && options.allowBlockType.exclude ? options.allowBlockType.exclude : [];
|
|
167
|
-
return [...blockquotePluginOptions(intl, exclude.indexOf('blockquote') === -1, api === null || api === void 0 ? void 0 : (_api$dependencies$
|
|
176
|
+
return [...blockquotePluginOptions(intl, exclude.indexOf('blockquote') === -1, api === null || api === void 0 ? void 0 : (_api$dependencies$ana5 = api.dependencies.analytics) === null || _api$dependencies$ana5 === void 0 ? void 0 : _api$dependencies$ana5.actions), ...headingPluginOptions(intl, exclude.indexOf('heading') === -1, api === null || api === void 0 ? void 0 : (_api$dependencies$ana6 = api.dependencies.analytics) === null || _api$dependencies$ana6 === void 0 ? void 0 : _api$dependencies$ana6.actions)];
|
|
168
177
|
}
|
|
169
178
|
}
|
|
170
179
|
});
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import { createJoinNodesRule, createWrappingTextBlockRule, ruleWithAnalytics } from '../../../utils/input-rules';
|
|
2
|
-
import { createRule, createPlugin } from '@atlaskit/prosemirror-input-rules';
|
|
3
|
-
import { leafNodeReplacementCharacter } from '@atlaskit/prosemirror-input-rules';
|
|
4
|
-
import { isConvertableToCodeBlock, transformToCodeBlockAction } from '../commands/transform-to-code-block';
|
|
5
|
-
import { insertBlock } from '../commands/insert-block';
|
|
6
1
|
import { safeInsert } from '@atlaskit/editor-prosemirror/utils';
|
|
2
|
+
import { createRule, createPlugin, leafNodeReplacementCharacter } from '@atlaskit/prosemirror-input-rules';
|
|
7
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 '../commands/transform-to-code-block';
|
|
6
|
+
import { insertBlock } from '../commands/insert-block';
|
|
7
|
+
import { createJoinNodesRule, createWrappingTextBlockRule } from '../utils';
|
|
8
8
|
const MAX_HEADING_LEVEL = 6;
|
|
9
9
|
function getHeadingLevel(match) {
|
|
10
10
|
return {
|
|
@@ -28,7 +28,7 @@ function blockQuoteRule(nodeType) {
|
|
|
28
28
|
* @param {Schema} schema
|
|
29
29
|
* @returns {InputRuleWithHandler[]}
|
|
30
30
|
*/
|
|
31
|
-
function getHeadingRules(schema) {
|
|
31
|
+
function getHeadingRules(editorAnalyticsAPI, schema) {
|
|
32
32
|
// '# ' for h1, '## ' for h2 and etc
|
|
33
33
|
const hashRule = headingRule(schema.nodes.heading, MAX_HEADING_LEVEL);
|
|
34
34
|
const leftNodeReplacementHashRule = createRule(new RegExp(`${leafNodeReplacementCharacter}(#{1,6})\\s$`), (state, match, start, end) => {
|
|
@@ -39,7 +39,7 @@ function getHeadingRules(schema) {
|
|
|
39
39
|
});
|
|
40
40
|
|
|
41
41
|
// New analytics handler
|
|
42
|
-
const ruleWithHeadingAnalytics =
|
|
42
|
+
const ruleWithHeadingAnalytics = inputRuleWithAnalytics((_state, matchResult) => ({
|
|
43
43
|
action: ACTION.FORMATTED,
|
|
44
44
|
actionSubject: ACTION_SUBJECT.TEXT,
|
|
45
45
|
eventType: EVENT_TYPE.TRACK,
|
|
@@ -48,7 +48,7 @@ function getHeadingRules(schema) {
|
|
|
48
48
|
inputMethod: INPUT_METHOD.FORMATTING,
|
|
49
49
|
newHeadingLevel: getHeadingLevel(matchResult).level
|
|
50
50
|
}
|
|
51
|
-
}));
|
|
51
|
+
}), editorAnalyticsAPI);
|
|
52
52
|
return [ruleWithHeadingAnalytics(hashRule), ruleWithHeadingAnalytics(leftNodeReplacementHashRule)];
|
|
53
53
|
}
|
|
54
54
|
|
|
@@ -58,7 +58,7 @@ function getHeadingRules(schema) {
|
|
|
58
58
|
* @param {Schema} schema
|
|
59
59
|
* @returns {InputRuleWithHandler[]}
|
|
60
60
|
*/
|
|
61
|
-
function getBlockQuoteRules(schema) {
|
|
61
|
+
function getBlockQuoteRules(editorAnalyticsAPI, schema) {
|
|
62
62
|
// '> ' for blockquote
|
|
63
63
|
const greatherThanRule = blockQuoteRule(schema.nodes.blockquote);
|
|
64
64
|
const leftNodeReplacementGreatherRule = createRule(new RegExp(`${leafNodeReplacementCharacter}\\s*>\\s$`), (state, _match, start, end) => {
|
|
@@ -66,7 +66,7 @@ function getBlockQuoteRules(schema) {
|
|
|
66
66
|
});
|
|
67
67
|
|
|
68
68
|
// Analytics V3 handler
|
|
69
|
-
const ruleWithBlockQuoteAnalytics =
|
|
69
|
+
const ruleWithBlockQuoteAnalytics = inputRuleWithAnalytics({
|
|
70
70
|
action: ACTION.FORMATTED,
|
|
71
71
|
actionSubject: ACTION_SUBJECT.TEXT,
|
|
72
72
|
eventType: EVENT_TYPE.TRACK,
|
|
@@ -74,7 +74,7 @@ function getBlockQuoteRules(schema) {
|
|
|
74
74
|
attributes: {
|
|
75
75
|
inputMethod: INPUT_METHOD.FORMATTING
|
|
76
76
|
}
|
|
77
|
-
});
|
|
77
|
+
}, editorAnalyticsAPI);
|
|
78
78
|
return [ruleWithBlockQuoteAnalytics(greatherThanRule), ruleWithBlockQuoteAnalytics(leftNodeReplacementGreatherRule)];
|
|
79
79
|
}
|
|
80
80
|
|
|
@@ -84,8 +84,8 @@ function getBlockQuoteRules(schema) {
|
|
|
84
84
|
* @param {Schema} schema
|
|
85
85
|
* @returns {InputRuleWithHandler[]}
|
|
86
86
|
*/
|
|
87
|
-
function getCodeBlockRules(schema) {
|
|
88
|
-
const ruleAnalytics =
|
|
87
|
+
function getCodeBlockRules(editorAnalyticsAPI, schema) {
|
|
88
|
+
const ruleAnalytics = inputRuleWithAnalytics({
|
|
89
89
|
action: ACTION.INSERTED,
|
|
90
90
|
actionSubject: ACTION_SUBJECT.DOCUMENT,
|
|
91
91
|
actionSubjectId: ACTION_SUBJECT_ID.CODE_BLOCK,
|
|
@@ -93,7 +93,7 @@ function getCodeBlockRules(schema) {
|
|
|
93
93
|
inputMethod: INPUT_METHOD.FORMATTING
|
|
94
94
|
},
|
|
95
95
|
eventType: EVENT_TYPE.TRACK
|
|
96
|
-
});
|
|
96
|
+
}, editorAnalyticsAPI);
|
|
97
97
|
const validMatchLength = match => match.length > 0 && match[0].length === 3;
|
|
98
98
|
const threeTildeRule = createRule(/(?!\s)(`{3,})$/, (state, match, start, end) => {
|
|
99
99
|
if (!validMatchLength(match)) {
|
|
@@ -125,16 +125,16 @@ function getCodeBlockRules(schema) {
|
|
|
125
125
|
});
|
|
126
126
|
return [ruleAnalytics(threeTildeRule), ruleAnalytics(leftNodeReplacementThreeTildeRule)];
|
|
127
127
|
}
|
|
128
|
-
function inputRulePlugin(schema, featureFlags) {
|
|
128
|
+
function inputRulePlugin(editorAnalyticsAPI, schema, featureFlags) {
|
|
129
129
|
const rules = [];
|
|
130
130
|
if (schema.nodes.heading) {
|
|
131
|
-
rules.push(...getHeadingRules(schema));
|
|
131
|
+
rules.push(...getHeadingRules(editorAnalyticsAPI, schema));
|
|
132
132
|
}
|
|
133
133
|
if (schema.nodes.blockquote) {
|
|
134
|
-
rules.push(...getBlockQuoteRules(schema));
|
|
134
|
+
rules.push(...getBlockQuoteRules(editorAnalyticsAPI, schema));
|
|
135
135
|
}
|
|
136
136
|
if (schema.nodes.codeBlock) {
|
|
137
|
-
rules.push(...getCodeBlockRules(schema));
|
|
137
|
+
rules.push(...getCodeBlockRules(editorAnalyticsAPI, schema));
|
|
138
138
|
}
|
|
139
139
|
if (rules.length !== 0) {
|
|
140
140
|
return createPlugin('block-type', rules, {
|
|
@@ -1,20 +1,19 @@
|
|
|
1
1
|
import { redo, undo } from '@atlaskit/editor-prosemirror/history';
|
|
2
2
|
import { chainCommands } from '@atlaskit/editor-prosemirror/commands';
|
|
3
|
-
import
|
|
4
|
-
import * as
|
|
3
|
+
import { INPUT_METHOD } from '@atlaskit/editor-common/analytics';
|
|
4
|
+
import * as keymaps from '@atlaskit/editor-common/keymaps';
|
|
5
|
+
import { keymap } from '@atlaskit/editor-common/keymaps';
|
|
6
|
+
import { insertNewLineWithAnalytics, createNewParagraphAbove, createNewParagraphBelow, deleteEmptyParagraphAndMoveBlockUp } from '@atlaskit/editor-common/utils';
|
|
5
7
|
import * as blockTypes from '../types';
|
|
6
|
-
import { keymap } from '../../../utils/keymap';
|
|
7
8
|
import { cleanUpAtTheStartOfDocument, deleteAndMoveCursor, deleteBlockContent, insertBlockTypesWithAnalytics } from '../commands';
|
|
8
|
-
import { deleteEmptyParagraphAndMoveBlockUp } from '@atlaskit/editor-common/utils';
|
|
9
|
-
import { INPUT_METHOD } from '../../analytics';
|
|
10
9
|
import { isNodeAWrappingBlockNode } from '../utils';
|
|
11
10
|
const backspace = chainCommands(cleanUpAtTheStartOfDocument, deleteBlockContent(isNodeAWrappingBlockNode), deleteAndMoveCursor);
|
|
12
11
|
const del = chainCommands(deleteEmptyParagraphAndMoveBlockUp(isNodeAWrappingBlockNode), deleteBlockContent(isNodeAWrappingBlockNode), deleteAndMoveCursor);
|
|
13
|
-
export default function keymapPlugin(
|
|
12
|
+
export default function keymapPlugin(editorAnalyticsApi, schema, _featureFlags) {
|
|
14
13
|
const list = {};
|
|
15
|
-
keymaps.bindKeymapWithCommand(keymaps.insertNewLine.common,
|
|
16
|
-
keymaps.bindKeymapWithCommand(keymaps.moveUp.common,
|
|
17
|
-
keymaps.bindKeymapWithCommand(keymaps.moveDown.common,
|
|
14
|
+
keymaps.bindKeymapWithCommand(keymaps.insertNewLine.common, insertNewLineWithAnalytics(editorAnalyticsApi), list);
|
|
15
|
+
keymaps.bindKeymapWithCommand(keymaps.moveUp.common, createNewParagraphAbove, list);
|
|
16
|
+
keymaps.bindKeymapWithCommand(keymaps.moveDown.common, createNewParagraphBelow, list);
|
|
18
17
|
keymaps.bindKeymapWithCommand(keymaps.findKeyMapForBrowser(keymaps.redo), redo, list);
|
|
19
18
|
keymaps.bindKeymapWithCommand(keymaps.undo.common, undo, list);
|
|
20
19
|
keymaps.bindKeymapWithCommand(keymaps.backspace.common, backspace, list);
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import { SafePlugin } from '@atlaskit/editor-common/safe-plugin';
|
|
2
2
|
import { PluginKey } from '@atlaskit/editor-prosemirror/state';
|
|
3
3
|
import { browser } from '@atlaskit/editor-common/utils';
|
|
4
|
+
import { INPUT_METHOD } from '@atlaskit/editor-common/analytics';
|
|
4
5
|
import { NORMAL_TEXT, HEADING_1, HEADING_2, HEADING_3, HEADING_4, HEADING_5, HEADING_6, BLOCK_QUOTE, CODE_BLOCK, PANEL, OTHER, TEXT_BLOCK_TYPES, WRAPPER_BLOCK_TYPES, HEADINGS_BY_LEVEL } from '../types';
|
|
5
|
-
import {
|
|
6
|
+
import { HEADING_KEYS } from '../consts';
|
|
6
7
|
import { setHeadingWithAnalytics, setNormalTextWithAnalytics } from '../commands';
|
|
7
|
-
import {
|
|
8
|
-
import { HEADING_KEYS } from '../../../keymaps/consts';
|
|
8
|
+
import { areBlockTypesDisabled } from '../utils';
|
|
9
9
|
const blockTypeForNode = (node, schema) => {
|
|
10
10
|
if (node.type === schema.nodes.heading) {
|
|
11
11
|
const maybeNode = HEADINGS_BY_LEVEL[node.attrs['level']];
|
|
@@ -59,16 +59,16 @@ const detectBlockType = (availableBlockTypes, state) => {
|
|
|
59
59
|
});
|
|
60
60
|
return blockType || OTHER;
|
|
61
61
|
};
|
|
62
|
-
const autoformatHeading = (headingLevel, view) => {
|
|
62
|
+
const autoformatHeading = (headingLevel, view, editorAnalyticsApi) => {
|
|
63
63
|
if (headingLevel === 0) {
|
|
64
|
-
setNormalTextWithAnalytics(INPUT_METHOD.FORMATTING)(view.state, view.dispatch);
|
|
64
|
+
setNormalTextWithAnalytics(INPUT_METHOD.FORMATTING, editorAnalyticsApi)(view.state, view.dispatch);
|
|
65
65
|
} else {
|
|
66
|
-
setHeadingWithAnalytics(headingLevel, INPUT_METHOD.FORMATTING)(view.state, view.dispatch);
|
|
66
|
+
setHeadingWithAnalytics(headingLevel, INPUT_METHOD.FORMATTING, editorAnalyticsApi)(view.state, view.dispatch);
|
|
67
67
|
}
|
|
68
68
|
return true;
|
|
69
69
|
};
|
|
70
70
|
export const pluginKey = new PluginKey('blockTypePlugin');
|
|
71
|
-
export const createPlugin = (dispatch, lastNodeMustBeParagraph) => {
|
|
71
|
+
export const createPlugin = (editorAnalyticsApi, dispatch, lastNodeMustBeParagraph) => {
|
|
72
72
|
let altKeyLocation = 0;
|
|
73
73
|
return new SafePlugin({
|
|
74
74
|
appendTransaction(_transactions, _oldState, newState) {
|
|
@@ -118,9 +118,9 @@ export const createPlugin = (dispatch, lastNodeMustBeParagraph) => {
|
|
|
118
118
|
const headingLevel = HEADING_KEYS.indexOf(event.keyCode);
|
|
119
119
|
if (headingLevel > -1 && event.altKey) {
|
|
120
120
|
if (browser.mac && event.metaKey) {
|
|
121
|
-
return autoformatHeading(headingLevel, view);
|
|
121
|
+
return autoformatHeading(headingLevel, view, editorAnalyticsApi);
|
|
122
122
|
} else if (!browser.mac && event.ctrlKey && altKeyLocation !== event.DOM_KEY_LOCATION_RIGHT) {
|
|
123
|
-
return autoformatHeading(headingLevel, view);
|
|
123
|
+
return autoformatHeading(headingLevel, view, editorAnalyticsApi);
|
|
124
124
|
}
|
|
125
125
|
} else if (event.key === 'Alt') {
|
|
126
126
|
// event.location is for the current key only; when a user hits Ctrl-Alt-1 the
|
|
@@ -4,10 +4,10 @@ import { jsx } from '@emotion/react';
|
|
|
4
4
|
import { FormattedMessage, defineMessages } from 'react-intl-next';
|
|
5
5
|
import ExpandIcon from '@atlaskit/icon/glyph/chevron-down';
|
|
6
6
|
import TextStyleIcon from '@atlaskit/icon/glyph/editor/text-style';
|
|
7
|
-
import ToolbarButton from '../../../../ui/ToolbarButton';
|
|
8
|
-
import { buttonContentStyle, buttonContentReducedSpacingStyle, wrapperSmallStyle, expandIconWrapperStyle } from '../../../../ui/styles';
|
|
9
7
|
import { wrapperStyle } from '@atlaskit/editor-common/styles';
|
|
8
|
+
import { ToolbarButton } from '@atlaskit/editor-common/ui-menu';
|
|
10
9
|
import { NORMAL_TEXT } from '../../types';
|
|
10
|
+
import { buttonContentStyle, buttonContentReducedSpacingStyle, wrapperSmallStyle, expandIconWrapperStyle } from './styled';
|
|
11
11
|
export const messages = defineMessages({
|
|
12
12
|
textStyles: {
|
|
13
13
|
id: 'fabric.editor.textStyles',
|
|
@@ -4,12 +4,11 @@ import React from 'react';
|
|
|
4
4
|
import { jsx } from '@emotion/react';
|
|
5
5
|
import { injectIntl } from 'react-intl-next';
|
|
6
6
|
import { akEditorMenuZIndex } from '@atlaskit/editor-shared-styles';
|
|
7
|
-
import {
|
|
7
|
+
import { getAriaKeyshortcuts, tooltip, findKeymapByDescription } from '@atlaskit/editor-common/keymaps';
|
|
8
8
|
import { separatorStyles, wrapperStyle } from '@atlaskit/editor-common/styles';
|
|
9
|
+
import { DropdownMenuWithKeyboardNavigation as DropdownMenu } from '@atlaskit/editor-common/ui-menu';
|
|
9
10
|
import { blockTypeMenuItemStyle, keyboardShortcut, keyboardShortcutSelect } from './styled';
|
|
10
|
-
import { tooltip, findKeymapByDescription } from '../../../../keymaps';
|
|
11
11
|
import { BlockTypeButton } from './blocktype-button';
|
|
12
|
-
import { getAriaKeyshortcuts } from '@atlaskit/editor-common/keymaps';
|
|
13
12
|
class ToolbarBlockType extends React.PureComponent {
|
|
14
13
|
constructor(...args) {
|
|
15
14
|
super(...args);
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
import { css } from '@emotion/react';
|
|
3
3
|
import { N400 } from '@atlaskit/theme/colors';
|
|
4
4
|
import { headingsSharedStyles } from '@atlaskit/editor-common/styles';
|
|
5
|
-
import { shortcutStyle } from '
|
|
5
|
+
import { shortcutStyle } from '@atlaskit/editor-shared-styles/shortcut';
|
|
6
6
|
export const blockTypeMenuItemStyle = (tagName, selected) => {
|
|
7
7
|
// TEMP FIX: See https://product-fabric.atlassian.net/browse/ED-13878
|
|
8
8
|
const selectedStyle = selected ? `${tagName} { color: ${"var(--ds-text, white)"} !important; }` : '';
|
|
@@ -23,8 +23,27 @@ export const blockTypeMenuItemStyle = (tagName, selected) => {
|
|
|
23
23
|
};
|
|
24
24
|
export const keyboardShortcut = css`
|
|
25
25
|
${shortcutStyle}
|
|
26
|
-
margin-left: 16px;
|
|
26
|
+
margin-left: ${"var(--ds-space-200, 16px)"};
|
|
27
27
|
`;
|
|
28
28
|
export const keyboardShortcutSelect = css`
|
|
29
29
|
color: ${`var(--ds-icon, ${N400})`};
|
|
30
|
+
`;
|
|
31
|
+
export const buttonContentStyle = css`
|
|
32
|
+
display: flex;
|
|
33
|
+
min-width: 80px;
|
|
34
|
+
align-items: center;
|
|
35
|
+
overflow: hidden;
|
|
36
|
+
justify-content: center;
|
|
37
|
+
flex-direction: column;
|
|
38
|
+
padding: ${"var(--ds-space-075, 6px)"};
|
|
39
|
+
`;
|
|
40
|
+
export const buttonContentReducedSpacingStyle = css`
|
|
41
|
+
padding: ${"var(--ds-space-100, 8px)"};
|
|
42
|
+
`;
|
|
43
|
+
export const wrapperSmallStyle = css`
|
|
44
|
+
margin-left: ${"var(--ds-space-050, 4px)"};
|
|
45
|
+
min-width: 40px;
|
|
46
|
+
`;
|
|
47
|
+
export const expandIconWrapperStyle = css`
|
|
48
|
+
margin-left: -8px;
|
|
30
49
|
`;
|
|
@@ -1,7 +1,76 @@
|
|
|
1
|
+
import { createRule } from '@atlaskit/prosemirror-input-rules';
|
|
2
|
+
import { createWrappingJoinRule } from '@atlaskit/editor-common/utils';
|
|
1
3
|
import { WRAPPER_BLOCK_TYPES } from './types';
|
|
2
4
|
export const isNodeAWrappingBlockNode = node => {
|
|
3
5
|
if (!node) {
|
|
4
6
|
return false;
|
|
5
7
|
}
|
|
6
8
|
return WRAPPER_BLOCK_TYPES.some(blockNode => blockNode.name === node.type.name);
|
|
7
|
-
};
|
|
9
|
+
};
|
|
10
|
+
export const createJoinNodesRule = (match, nodeType) => {
|
|
11
|
+
return createWrappingJoinRule({
|
|
12
|
+
nodeType,
|
|
13
|
+
match,
|
|
14
|
+
getAttrs: {},
|
|
15
|
+
joinPredicate: (_, node) => node.type === nodeType
|
|
16
|
+
});
|
|
17
|
+
};
|
|
18
|
+
export const createWrappingTextBlockRule = ({
|
|
19
|
+
match,
|
|
20
|
+
nodeType,
|
|
21
|
+
getAttrs
|
|
22
|
+
}) => {
|
|
23
|
+
const handler = (state, match, start, end) => {
|
|
24
|
+
const fixedStart = Math.max(start, 1);
|
|
25
|
+
const $start = state.doc.resolve(fixedStart);
|
|
26
|
+
const attrs = getAttrs instanceof Function ? getAttrs(match) : getAttrs;
|
|
27
|
+
const nodeBefore = $start.node(-1);
|
|
28
|
+
if (nodeBefore && !nodeBefore.canReplaceWith($start.index(-1), $start.indexAfter(-1), nodeType)) {
|
|
29
|
+
return null;
|
|
30
|
+
}
|
|
31
|
+
return state.tr.delete(fixedStart, end).setBlockType(fixedStart, fixedStart, nodeType, attrs);
|
|
32
|
+
};
|
|
33
|
+
return createRule(match, handler);
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* Function will create a list of wrapper blocks present in a selection.
|
|
38
|
+
*/
|
|
39
|
+
function getSelectedWrapperNodes(state) {
|
|
40
|
+
const nodes = [];
|
|
41
|
+
if (state.selection) {
|
|
42
|
+
const {
|
|
43
|
+
$from,
|
|
44
|
+
$to
|
|
45
|
+
} = state.selection;
|
|
46
|
+
const {
|
|
47
|
+
blockquote,
|
|
48
|
+
panel,
|
|
49
|
+
orderedList,
|
|
50
|
+
bulletList,
|
|
51
|
+
listItem,
|
|
52
|
+
codeBlock,
|
|
53
|
+
decisionItem,
|
|
54
|
+
decisionList,
|
|
55
|
+
taskItem,
|
|
56
|
+
taskList
|
|
57
|
+
} = state.schema.nodes;
|
|
58
|
+
state.doc.nodesBetween($from.pos, $to.pos, node => {
|
|
59
|
+
if (node.isBlock && [blockquote, panel, orderedList, bulletList, listItem, codeBlock, decisionItem, decisionList, taskItem, taskList].indexOf(node.type) >= 0) {
|
|
60
|
+
nodes.push(node.type);
|
|
61
|
+
}
|
|
62
|
+
});
|
|
63
|
+
}
|
|
64
|
+
return nodes;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
/**
|
|
68
|
+
* Function will check if changing block types: Paragraph, Heading is enabled.
|
|
69
|
+
*/
|
|
70
|
+
export function areBlockTypesDisabled(state) {
|
|
71
|
+
const nodesTypes = getSelectedWrapperNodes(state);
|
|
72
|
+
const {
|
|
73
|
+
panel
|
|
74
|
+
} = state.schema.nodes;
|
|
75
|
+
return nodesTypes.filter(type => type !== panel).length > 0;
|
|
76
|
+
}
|
|
@@ -2,7 +2,7 @@ import { keymap } from '@atlaskit/editor-prosemirror/keymap';
|
|
|
2
2
|
import { Selection } from '@atlaskit/editor-prosemirror/state';
|
|
3
3
|
import * as keymaps from '../../../keymaps';
|
|
4
4
|
import { findParentNodeOfType } from '@atlaskit/editor-prosemirror/utils';
|
|
5
|
-
import { createNewParagraphBelow } from '
|
|
5
|
+
import { createNewParagraphBelow } from '@atlaskit/editor-common/utils';
|
|
6
6
|
import { GapCursorSelection } from '../../selection/gap-cursor/selection';
|
|
7
7
|
export function captionKeymap() {
|
|
8
8
|
const list = {};
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { safeInsert } from '@atlaskit/editor-prosemirror/utils';
|
|
2
2
|
import { Fragment } from '@atlaskit/editor-prosemirror/model';
|
|
3
3
|
import { Selection } from '@atlaskit/editor-prosemirror/state';
|
|
4
|
-
import {
|
|
5
|
-
export
|
|
4
|
+
import { EVENT_TYPE, ACTION_SUBJECT_ID, ACTION_SUBJECT, ACTION } from '@atlaskit/editor-common/analytics';
|
|
5
|
+
export const insertEmoji = editorAnalyticsAPI => (emojiId, inputMethod) => {
|
|
6
6
|
return (state, dispatch) => {
|
|
7
7
|
const {
|
|
8
8
|
emoji
|
|
@@ -17,7 +17,7 @@ export function insertEmoji(emojiId, inputMethod) {
|
|
|
17
17
|
const fragment = Fragment.fromArray([node, textNode]);
|
|
18
18
|
const tr = safeInsert(fragment)(state.tr);
|
|
19
19
|
if (inputMethod) {
|
|
20
|
-
|
|
20
|
+
editorAnalyticsAPI === null || editorAnalyticsAPI === void 0 ? void 0 : editorAnalyticsAPI.attachAnalyticsEvent({
|
|
21
21
|
action: ACTION.INSERTED,
|
|
22
22
|
actionSubject: ACTION_SUBJECT.DOCUMENT,
|
|
23
23
|
actionSubjectId: ACTION_SUBJECT_ID.EMOJI,
|
|
@@ -25,7 +25,7 @@ export function insertEmoji(emojiId, inputMethod) {
|
|
|
25
25
|
inputMethod
|
|
26
26
|
},
|
|
27
27
|
eventType: EVENT_TYPE.TRACK
|
|
28
|
-
});
|
|
28
|
+
})(tr);
|
|
29
29
|
}
|
|
30
30
|
dispatch(tr.setSelection(Selection.near(tr.doc.resolve(state.selection.$from.pos + fragment.size))));
|
|
31
31
|
}
|
|
@@ -33,4 +33,4 @@ export function insertEmoji(emojiId, inputMethod) {
|
|
|
33
33
|
}
|
|
34
34
|
return false;
|
|
35
35
|
};
|
|
36
|
-
}
|
|
36
|
+
};
|
|
@@ -169,7 +169,10 @@ const emojiPlugin = (options, api) => {
|
|
|
169
169
|
schema,
|
|
170
170
|
providerFactory,
|
|
171
171
|
featureFlags
|
|
172
|
-
}) =>
|
|
172
|
+
}) => {
|
|
173
|
+
var _api$dependencies$ana8;
|
|
174
|
+
return asciiInputRulePlugin(schema, providerFactory, featureFlags, api === null || api === void 0 ? void 0 : (_api$dependencies$ana8 = api.dependencies.analytics) === null || _api$dependencies$ana8 === void 0 ? void 0 : _api$dependencies$ana8.actions);
|
|
175
|
+
}
|
|
173
176
|
}];
|
|
174
177
|
},
|
|
175
178
|
pluginsOptions: {
|
|
@@ -183,13 +186,13 @@ const emojiPlugin = (options, api) => {
|
|
|
183
186
|
keyshortcut: ':',
|
|
184
187
|
icon: () => /*#__PURE__*/React.createElement(IconEmoji, null),
|
|
185
188
|
action(insert, state) {
|
|
186
|
-
var _api$dependencies$
|
|
189
|
+
var _api$dependencies$ana9;
|
|
187
190
|
const tr = insert(undefined);
|
|
188
191
|
openTypeAheadAtCursor({
|
|
189
192
|
triggerHandler: typeAhead,
|
|
190
193
|
inputMethod: INPUT_METHOD.QUICK_INSERT
|
|
191
194
|
})(tr);
|
|
192
|
-
api === null || api === void 0 ? void 0 : (_api$dependencies$
|
|
195
|
+
api === null || api === void 0 ? void 0 : (_api$dependencies$ana9 = api.dependencies.analytics) === null || _api$dependencies$ana9 === void 0 ? void 0 : _api$dependencies$ana9.actions.attachAnalyticsEvent({
|
|
193
196
|
action: ACTION.INVOKED,
|
|
194
197
|
actionSubject: ACTION_SUBJECT.TYPEAHEAD,
|
|
195
198
|
actionSubjectId: ACTION_SUBJECT_ID.TYPEAHEAD_EMOJI,
|
|
@@ -2,12 +2,12 @@ import _defineProperty from "@babel/runtime/helpers/defineProperty";
|
|
|
2
2
|
import { PluginKey } from '@atlaskit/editor-prosemirror/state';
|
|
3
3
|
import { createRule, createPlugin } from '@atlaskit/prosemirror-input-rules';
|
|
4
4
|
import { leafNodeReplacementCharacter } from '@atlaskit/prosemirror-input-rules';
|
|
5
|
-
import {
|
|
5
|
+
import { ACTION, ACTION_SUBJECT, ACTION_SUBJECT_ID, INPUT_METHOD, EVENT_TYPE } from '@atlaskit/editor-common/analytics';
|
|
6
6
|
let matcher;
|
|
7
|
-
export function inputRulePlugin(schema, providerFactory, featureFlags) {
|
|
7
|
+
export function inputRulePlugin(schema, providerFactory, featureFlags, editorAnalyticsAPI) {
|
|
8
8
|
if (schema.nodes.emoji && providerFactory) {
|
|
9
9
|
initMatcher(providerFactory);
|
|
10
|
-
const asciiEmojiRule = createRule(AsciiEmojiMatcher.REGEX, inputRuleHandler);
|
|
10
|
+
const asciiEmojiRule = createRule(AsciiEmojiMatcher.REGEX, inputRuleHandler(editorAnalyticsAPI));
|
|
11
11
|
return createPlugin('emoji', [asciiEmojiRule]);
|
|
12
12
|
}
|
|
13
13
|
return;
|
|
@@ -25,17 +25,17 @@ function initMatcher(providerFactory) {
|
|
|
25
25
|
};
|
|
26
26
|
providerFactory.subscribe('emojiProvider', handleProvider);
|
|
27
27
|
}
|
|
28
|
-
|
|
28
|
+
const inputRuleHandler = editorAnalyticsAPI => (state, matchParts, start, end) => {
|
|
29
29
|
if (!matcher) {
|
|
30
30
|
return null;
|
|
31
31
|
}
|
|
32
32
|
const match = matcher.match(matchParts);
|
|
33
33
|
if (match) {
|
|
34
|
-
const transactionCreator = new AsciiEmojiTransactionCreator(state, match, start, end);
|
|
34
|
+
const transactionCreator = new AsciiEmojiTransactionCreator(state, match, start, end, editorAnalyticsAPI);
|
|
35
35
|
return transactionCreator.create();
|
|
36
36
|
}
|
|
37
37
|
return null;
|
|
38
|
-
}
|
|
38
|
+
};
|
|
39
39
|
const REGEX_LEADING_CAPTURE_INDEX = 1;
|
|
40
40
|
const REGEX_EMOJI_LEADING_PARENTHESES = 2;
|
|
41
41
|
const REGEX_EMOJI_ASCII_CAPTURE_INDEX = 3;
|
|
@@ -107,15 +107,17 @@ class RecordingAsciiEmojiMatcher extends AsciiEmojiMatcher {
|
|
|
107
107
|
}
|
|
108
108
|
}
|
|
109
109
|
class AsciiEmojiTransactionCreator {
|
|
110
|
-
constructor(state, match, start, end) {
|
|
110
|
+
constructor(state, match, start, end, editorAnalyticsAPI) {
|
|
111
111
|
this.state = state;
|
|
112
112
|
this.match = match;
|
|
113
113
|
this.start = start;
|
|
114
114
|
this.end = end;
|
|
115
|
+
this.editorAnalyticsAPI = editorAnalyticsAPI;
|
|
115
116
|
}
|
|
116
117
|
create() {
|
|
118
|
+
var _this$editorAnalytics;
|
|
117
119
|
const tr = this.state.tr.replaceWith(this.from, this.to, this.createNodes());
|
|
118
|
-
|
|
120
|
+
(_this$editorAnalytics = this.editorAnalyticsAPI) === null || _this$editorAnalytics === void 0 ? void 0 : _this$editorAnalytics.attachAnalyticsEvent({
|
|
119
121
|
action: ACTION.INSERTED,
|
|
120
122
|
actionSubject: ACTION_SUBJECT.DOCUMENT,
|
|
121
123
|
actionSubjectId: ACTION_SUBJECT_ID.EMOJI,
|
|
@@ -123,7 +125,8 @@ class AsciiEmojiTransactionCreator {
|
|
|
123
125
|
inputMethod: INPUT_METHOD.ASCII
|
|
124
126
|
},
|
|
125
127
|
eventType: EVENT_TYPE.TRACK
|
|
126
|
-
});
|
|
128
|
+
})(tr);
|
|
129
|
+
return tr;
|
|
127
130
|
}
|
|
128
131
|
get from() {
|
|
129
132
|
return this.start + this.match.leadingString.length;
|
|
@@ -160,7 +163,7 @@ class AsciiEmojiTransactionCreator {
|
|
|
160
163
|
}
|
|
161
164
|
}
|
|
162
165
|
export const stateKey = new PluginKey('asciiEmojiPlugin');
|
|
163
|
-
const plugins = (schema, providerFactory, featureFlags) => {
|
|
164
|
-
return [inputRulePlugin(schema, providerFactory, featureFlags)].filter(plugin => !!plugin);
|
|
166
|
+
const plugins = (schema, providerFactory, featureFlags, editorAnalyticsAPI) => {
|
|
167
|
+
return [inputRulePlugin(schema, providerFactory, featureFlags, editorAnalyticsAPI)].filter(plugin => !!plugin);
|
|
165
168
|
};
|
|
166
169
|
export default plugins;
|
|
@@ -1,4 +1,7 @@
|
|
|
1
|
+
import { TextSelection, NodeSelection } from '@atlaskit/editor-prosemirror/state';
|
|
2
|
+
import { findParentNodeOfTypeClosestToPos, findSelectedNodeOfType } from '@atlaskit/editor-prosemirror/utils';
|
|
1
3
|
import { SafePlugin } from '@atlaskit/editor-common/safe-plugin';
|
|
4
|
+
import { isSelectionAtStartOfNode, isSelectionAtEndOfNode } from '@atlaskit/editor-common/selection';
|
|
2
5
|
import { createSelectionClickHandler } from '../../selection/utils';
|
|
3
6
|
import ExtensionNodeView from '../nodeviews/extension';
|
|
4
7
|
import { updateState, clearEditingContext } from '../commands';
|
|
@@ -163,6 +166,53 @@ const createPlugin = (dispatch, providerFactory, extensionHandlers, portalProvid
|
|
|
163
166
|
},
|
|
164
167
|
key: pluginKey,
|
|
165
168
|
props: {
|
|
169
|
+
handleDOMEvents: {
|
|
170
|
+
/**
|
|
171
|
+
* ED-18072 - Cannot shift + arrow past bodied extension if it is not empty.
|
|
172
|
+
* This code is to handle the case where the selection starts inside or on the node and the user is trying to shift + arrow.
|
|
173
|
+
* For other part of the solution see code in: packages/editor/editor-core/src/plugins/selection/pm-plugins/events/keydown.ts
|
|
174
|
+
*/
|
|
175
|
+
keydown: (view, event) => {
|
|
176
|
+
if (event instanceof KeyboardEvent && event.shiftKey && ['ArrowUp', 'ArrowDown', 'ArrowLeft', 'ArrowRight'].includes(event.key)) {
|
|
177
|
+
const {
|
|
178
|
+
schema,
|
|
179
|
+
selection,
|
|
180
|
+
selection: {
|
|
181
|
+
$head
|
|
182
|
+
},
|
|
183
|
+
doc,
|
|
184
|
+
tr
|
|
185
|
+
} = view.state;
|
|
186
|
+
const {
|
|
187
|
+
bodiedExtension
|
|
188
|
+
} = schema.nodes;
|
|
189
|
+
if (selection instanceof TextSelection || selection instanceof NodeSelection) {
|
|
190
|
+
const maybeBodiedExtension = selection instanceof TextSelection ? findParentNodeOfTypeClosestToPos($head, bodiedExtension) : findSelectedNodeOfType(bodiedExtension)(selection);
|
|
191
|
+
if (maybeBodiedExtension) {
|
|
192
|
+
const end = maybeBodiedExtension.pos + maybeBodiedExtension.node.nodeSize;
|
|
193
|
+
if (event.key === 'ArrowUp' || event.key === 'ArrowLeft' && isSelectionAtStartOfNode($head, maybeBodiedExtension)) {
|
|
194
|
+
const anchor = end + 1;
|
|
195
|
+
|
|
196
|
+
// an offset is used here so that left arrow selects the first character before the node (consistent with arrow right)
|
|
197
|
+
const headOffset = event.key === 'ArrowLeft' ? -1 : 0;
|
|
198
|
+
const head = maybeBodiedExtension.pos + headOffset;
|
|
199
|
+
const newSelection = TextSelection.create(doc, Math.max(anchor, selection.anchor), head);
|
|
200
|
+
view.dispatch(tr.setSelection(newSelection));
|
|
201
|
+
return true;
|
|
202
|
+
}
|
|
203
|
+
if (event.key === 'ArrowDown' || event.key === 'ArrowRight' && isSelectionAtEndOfNode($head, maybeBodiedExtension)) {
|
|
204
|
+
const anchor = maybeBodiedExtension.pos - 1;
|
|
205
|
+
const head = end + 1;
|
|
206
|
+
const newSelection = TextSelection.create(doc, Math.min(anchor, selection.anchor), head);
|
|
207
|
+
view.dispatch(tr.setSelection(newSelection));
|
|
208
|
+
return true;
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
return false;
|
|
214
|
+
}
|
|
215
|
+
},
|
|
166
216
|
nodeViews: {
|
|
167
217
|
// WARNING: referentiality-plugin also creates these nodeviews
|
|
168
218
|
extension: ExtensionNodeView(portalProviderAPI, eventDispatcher, providerFactory, extensionHandlers, extensionNodeViewOptions, pluginInjectionApi),
|
|
@@ -290,7 +290,7 @@ export class ToolbarInsertBlock extends React.PureComponent {
|
|
|
290
290
|
});
|
|
291
291
|
_defineProperty(this, "handleSelectedEmoji", emojiId => {
|
|
292
292
|
this.props.editorView.focus();
|
|
293
|
-
insertEmoji(emojiId, INPUT_METHOD.PICKER)(this.props.editorView.state, this.props.editorView.dispatch);
|
|
293
|
+
insertEmoji(this.editorAnalyticsAPI)(emojiId, INPUT_METHOD.PICKER)(this.props.editorView.state, this.props.editorView.dispatch);
|
|
294
294
|
this.toggleEmojiPicker();
|
|
295
295
|
return true;
|
|
296
296
|
});
|