@atlaskit/editor-core 187.9.2 → 187.10.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.eslintrc.js +1 -0
- package/CHANGELOG.md +17 -0
- package/dist/cjs/commands/index.js +8 -134
- package/dist/cjs/labs/next/presets/default.js +2 -2
- 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/floating-toolbar/index.js +154 -132
- package/dist/cjs/plugins/floating-toolbar/pm-plugins/force-focus/index.js +11 -10
- package/dist/cjs/plugins/floating-toolbar/ui/ExtensionsPlaceholder.js +14 -7
- package/dist/cjs/plugins/floating-toolbar/ui/Toolbar.js +6 -1
- package/dist/cjs/plugins/index.js +0 -7
- package/dist/cjs/plugins/media/pm-plugins/alt-text/ui/AltTextEdit.js +4 -1
- package/dist/cjs/plugins/media/toolbar/alt-text.js +6 -6
- package/dist/cjs/plugins/media/toolbar/linking.js +4 -1
- package/dist/cjs/plugins/media/ui/MediaLinkingToolbar.js +2 -2
- package/dist/cjs/plugins/media/utils/media-common.js +5 -5
- package/dist/cjs/plugins/undo-redo/pm-plugins/keymaps.js +2 -2
- package/dist/cjs/ui/ColorPickerButton/index.js +3 -3
- 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/labs/next/presets/default.js +1 -1
- 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/floating-toolbar/index.js +152 -128
- package/dist/es2019/plugins/floating-toolbar/pm-plugins/force-focus/index.js +12 -8
- package/dist/es2019/plugins/floating-toolbar/ui/ExtensionsPlaceholder.js +5 -4
- package/dist/es2019/plugins/floating-toolbar/ui/Toolbar.js +12 -1
- package/dist/es2019/plugins/index.js +0 -1
- package/dist/es2019/plugins/media/pm-plugins/alt-text/ui/AltTextEdit.js +3 -1
- package/dist/es2019/plugins/media/toolbar/alt-text.js +10 -6
- package/dist/es2019/plugins/media/toolbar/linking.js +8 -1
- package/dist/es2019/plugins/media/ui/MediaLinkingToolbar.js +5 -3
- package/dist/es2019/plugins/media/utils/media-common.js +1 -1
- 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/ColorPickerButton/index.js +2 -2
- 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/labs/next/presets/default.js +1 -1
- 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/floating-toolbar/index.js +153 -131
- package/dist/esm/plugins/floating-toolbar/pm-plugins/force-focus/index.js +9 -7
- package/dist/esm/plugins/floating-toolbar/ui/ExtensionsPlaceholder.js +14 -7
- package/dist/esm/plugins/floating-toolbar/ui/Toolbar.js +6 -1
- package/dist/esm/plugins/index.js +0 -1
- package/dist/esm/plugins/media/pm-plugins/alt-text/ui/AltTextEdit.js +4 -1
- package/dist/esm/plugins/media/toolbar/alt-text.js +6 -6
- package/dist/esm/plugins/media/toolbar/linking.js +4 -1
- package/dist/esm/plugins/media/ui/MediaLinkingToolbar.js +2 -2
- package/dist/esm/plugins/media/utils/media-common.js +1 -1
- 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/ColorPickerButton/index.js +3 -3
- 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/labs/next/presets/default.d.ts +40 -8
- 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/date/index.d.ts +2 -2
- package/dist/types/plugins/floating-toolbar/index.d.ts +1 -7
- package/dist/types/plugins/floating-toolbar/pm-plugins/force-focus/index.d.ts +2 -1
- package/dist/types/plugins/floating-toolbar/pm-plugins/toolbar-data/plugin-factory.d.ts +1 -1
- package/dist/types/plugins/floating-toolbar/pm-plugins/toolbar-data/plugin-key.d.ts +1 -1
- package/dist/types/plugins/floating-toolbar/pm-plugins/toolbar-data/plugin.d.ts +1 -1
- package/dist/types/plugins/floating-toolbar/pm-plugins/toolbar-data/reducer.d.ts +2 -1
- package/dist/types/plugins/floating-toolbar/pm-plugins/toolbar-data/types.d.ts +0 -3
- package/dist/types/plugins/floating-toolbar/ui/ExtensionsPlaceholder.d.ts +1 -1
- package/dist/types/plugins/floating-toolbar/ui/Toolbar.d.ts +1 -1
- package/dist/types/plugins/index.d.ts +0 -1
- package/dist/types/plugins/media/index.d.ts +2 -2
- package/dist/types/plugins/media/pm-plugins/alt-text/ui/AltTextEdit.d.ts +1 -0
- package/dist/types/plugins/media/ui/MediaLinkingToolbar.d.ts +3 -3
- package/dist/types/plugins/undo-redo/pm-plugins/keymaps.d.ts +1 -1
- package/dist/types/plugins/view-update-subscription/subscribe/toolbarAndPickerUpdates.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/ColorPickerButton/index.d.ts +2 -2
- 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/labs/next/presets/default.d.ts +44 -8
- 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/date/index.d.ts +2 -2
- package/dist/types-ts4.5/plugins/floating-toolbar/index.d.ts +1 -7
- package/dist/types-ts4.5/plugins/floating-toolbar/pm-plugins/force-focus/index.d.ts +2 -1
- package/dist/types-ts4.5/plugins/floating-toolbar/pm-plugins/toolbar-data/plugin-factory.d.ts +1 -1
- package/dist/types-ts4.5/plugins/floating-toolbar/pm-plugins/toolbar-data/plugin-key.d.ts +1 -1
- package/dist/types-ts4.5/plugins/floating-toolbar/pm-plugins/toolbar-data/plugin.d.ts +1 -1
- package/dist/types-ts4.5/plugins/floating-toolbar/pm-plugins/toolbar-data/reducer.d.ts +2 -1
- package/dist/types-ts4.5/plugins/floating-toolbar/pm-plugins/toolbar-data/types.d.ts +0 -3
- package/dist/types-ts4.5/plugins/floating-toolbar/ui/ExtensionsPlaceholder.d.ts +1 -1
- package/dist/types-ts4.5/plugins/floating-toolbar/ui/Toolbar.d.ts +1 -1
- package/dist/types-ts4.5/plugins/index.d.ts +0 -1
- package/dist/types-ts4.5/plugins/media/index.d.ts +2 -2
- package/dist/types-ts4.5/plugins/media/pm-plugins/alt-text/ui/AltTextEdit.d.ts +1 -0
- package/dist/types-ts4.5/plugins/media/ui/MediaLinkingToolbar.d.ts +3 -3
- package/dist/types-ts4.5/plugins/undo-redo/pm-plugins/keymaps.d.ts +1 -1
- package/dist/types-ts4.5/plugins/view-update-subscription/subscribe/toolbarAndPickerUpdates.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/ColorPickerButton/index.d.ts +2 -2
- 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 +6 -5
- package/report.api.md +9 -37
- package/tmp/api-report-tmp.d.ts +8 -34
- package/dist/cjs/plugins/editor-disabled/index.js +0 -75
- package/dist/cjs/types/allowed-block-types.js +0 -5
- package/dist/cjs/utils/keymap.js +0 -38
- package/dist/es2019/plugins/editor-disabled/index.js +0 -62
- package/dist/es2019/types/allowed-block-types.js +0 -1
- package/dist/es2019/utils/keymap.js +0 -33
- package/dist/esm/plugins/editor-disabled/index.js +0 -66
- package/dist/esm/types/allowed-block-types.js +0 -1
- package/dist/esm/utils/keymap.js +0 -33
- package/dist/types/plugins/editor-disabled/index.d.ts +0 -13
- 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/plugins/editor-disabled/index.d.ts +0 -13
- 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,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 = {};
|
|
@@ -6,11 +6,9 @@ import camelCase from 'lodash/camelCase';
|
|
|
6
6
|
import { Popup } from '@atlaskit/editor-common/ui';
|
|
7
7
|
// AFP-2532 TODO: Fix automatic suppressions below
|
|
8
8
|
// eslint-disable-next-line @atlassian/tangerine/import/entry-points
|
|
9
|
-
import
|
|
9
|
+
import { WithProviders } from '@atlaskit/editor-common/provider-factory';
|
|
10
10
|
import { CONTENT_COMPONENT } from '../analytics/types';
|
|
11
11
|
import { ACTION, ACTION_SUBJECT, EVENT_TYPE } from '@atlaskit/editor-common/analytics';
|
|
12
|
-
import { pluginKey as extensionsPluginKey } from '../extension/plugin-key';
|
|
13
|
-
import { pluginKey as editorDisabledPluginKey } from '../editor-disabled';
|
|
14
12
|
import { pluginKey as dataPluginKey } from './pm-plugins/toolbar-data/plugin-key';
|
|
15
13
|
import { createPlugin as floatingToolbarDataPluginFactory } from './pm-plugins/toolbar-data/plugin';
|
|
16
14
|
import { hideConfirmDialog } from './pm-plugins/toolbar-data/commands';
|
|
@@ -112,8 +110,6 @@ function filterUndefined(x) {
|
|
|
112
110
|
return !!x;
|
|
113
111
|
}
|
|
114
112
|
const floatingToolbarPlugin = (_, api) => {
|
|
115
|
-
var _api$dependencies, _api$dependencies$fea;
|
|
116
|
-
const featureFlags = (api === null || api === void 0 ? void 0 : (_api$dependencies = api.dependencies) === null || _api$dependencies === void 0 ? void 0 : (_api$dependencies$fea = _api$dependencies.featureFlags) === null || _api$dependencies$fea === void 0 ? void 0 : _api$dependencies$fea.sharedState.currentState()) || {};
|
|
117
113
|
return {
|
|
118
114
|
name: 'floatingToolbar',
|
|
119
115
|
pmPlugins(floatingToolbarHandlers = []) {
|
|
@@ -143,6 +139,17 @@ const floatingToolbarPlugin = (_, api) => {
|
|
|
143
139
|
actions: {
|
|
144
140
|
forceFocusSelector
|
|
145
141
|
},
|
|
142
|
+
getSharedState(editorState) {
|
|
143
|
+
var _pluginKey$getState$g, _pluginKey$getState, _pluginKey$getState$g2;
|
|
144
|
+
if (!editorState) {
|
|
145
|
+
return undefined;
|
|
146
|
+
}
|
|
147
|
+
const configWithNodeInfo = (_pluginKey$getState$g = (_pluginKey$getState = pluginKey.getState(editorState)) === null || _pluginKey$getState === void 0 ? void 0 : (_pluginKey$getState$g2 = _pluginKey$getState.getConfigWithNodeInfo) === null || _pluginKey$getState$g2 === void 0 ? void 0 : _pluginKey$getState$g2.call(_pluginKey$getState, editorState)) !== null && _pluginKey$getState$g !== void 0 ? _pluginKey$getState$g : undefined;
|
|
148
|
+
return {
|
|
149
|
+
configWithNodeInfo,
|
|
150
|
+
floatingToolbarData: dataPluginKey.getState(editorState)
|
|
151
|
+
};
|
|
152
|
+
},
|
|
146
153
|
contentComponent({
|
|
147
154
|
popupsMountPoint,
|
|
148
155
|
popupsBoundariesElement,
|
|
@@ -151,131 +158,150 @@ const floatingToolbarPlugin = (_, api) => {
|
|
|
151
158
|
providerFactory,
|
|
152
159
|
dispatchAnalyticsEvent
|
|
153
160
|
}) {
|
|
154
|
-
return /*#__PURE__*/React.createElement(
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
editorDisabledPlugin,
|
|
163
|
-
floatingToolbarState,
|
|
164
|
-
floatingToolbarData,
|
|
165
|
-
extensionsState
|
|
166
|
-
}) => {
|
|
167
|
-
var _configWithNodeInfo$c, _configWithNodeInfo$c2;
|
|
168
|
-
const configWithNodeInfo = floatingToolbarState === null || floatingToolbarState === void 0 ? void 0 : floatingToolbarState.getConfigWithNodeInfo(editorView.state);
|
|
169
|
-
if (!configWithNodeInfo || !configWithNodeInfo.config || typeof ((_configWithNodeInfo$c = configWithNodeInfo.config) === null || _configWithNodeInfo$c === void 0 ? void 0 : _configWithNodeInfo$c.visible) !== 'undefined' && !((_configWithNodeInfo$c2 = configWithNodeInfo.config) !== null && _configWithNodeInfo$c2 !== void 0 && _configWithNodeInfo$c2.visible)) {
|
|
170
|
-
return null;
|
|
171
|
-
}
|
|
172
|
-
const {
|
|
173
|
-
config,
|
|
174
|
-
node
|
|
175
|
-
} = configWithNodeInfo;
|
|
176
|
-
const {
|
|
177
|
-
title,
|
|
178
|
-
getDomRef = getDomRefFromSelection,
|
|
179
|
-
items,
|
|
180
|
-
align = 'center',
|
|
181
|
-
className = '',
|
|
182
|
-
height,
|
|
183
|
-
width,
|
|
184
|
-
zIndex,
|
|
185
|
-
offset = [0, 12],
|
|
186
|
-
forcePlacement,
|
|
187
|
-
preventPopupOverflow,
|
|
188
|
-
onPositionCalculated,
|
|
189
|
-
focusTrap
|
|
190
|
-
} = config;
|
|
191
|
-
const targetRef = getDomRef(editorView, dispatchAnalyticsEvent);
|
|
192
|
-
if (!targetRef || editorDisabledPlugin && editorDisabledPlugin.editorDisabled) {
|
|
193
|
-
return null;
|
|
194
|
-
}
|
|
195
|
-
let customPositionCalculation;
|
|
196
|
-
const toolbarItems = processCopyButtonItems(editorView.state)(Array.isArray(items) ? items : items(node), api === null || api === void 0 ? void 0 : api.dependencies.decorations.actions.hoverDecoration);
|
|
197
|
-
if (onPositionCalculated) {
|
|
198
|
-
customPositionCalculation = nextPos => {
|
|
199
|
-
return onPositionCalculated(editorView, nextPos);
|
|
200
|
-
};
|
|
201
|
-
}
|
|
202
|
-
const dispatchCommand = fn => fn && fn(editorView.state, editorView.dispatch, editorView);
|
|
203
|
-
|
|
204
|
-
// Confirm dialog
|
|
205
|
-
const {
|
|
206
|
-
confirmDialogForItem
|
|
207
|
-
} = floatingToolbarData || {};
|
|
208
|
-
const confirmButtonItem = confirmDialogForItem ? toolbarItems[confirmDialogForItem] : undefined;
|
|
209
|
-
const scrollable = featureFlags.floatingToolbarCopyButton && config.scrollable;
|
|
210
|
-
const confirmDialogOptions = typeof (confirmButtonItem === null || confirmButtonItem === void 0 ? void 0 : confirmButtonItem.confirmDialog) === 'function' ? confirmButtonItem === null || confirmButtonItem === void 0 ? void 0 : confirmButtonItem.confirmDialog() : confirmButtonItem === null || confirmButtonItem === void 0 ? void 0 : confirmButtonItem.confirmDialog;
|
|
211
|
-
return /*#__PURE__*/React.createElement(ErrorBoundary, {
|
|
212
|
-
component: ACTION_SUBJECT.FLOATING_TOOLBAR_PLUGIN,
|
|
213
|
-
componentId: camelCase(title),
|
|
214
|
-
dispatchAnalyticsEvent: dispatchAnalyticsEvent,
|
|
215
|
-
fallbackComponent: null
|
|
216
|
-
}, /*#__PURE__*/React.createElement(Popup, {
|
|
217
|
-
ariaLabel: title,
|
|
218
|
-
offset: offset,
|
|
219
|
-
target: targetRef,
|
|
220
|
-
alignY: "bottom",
|
|
221
|
-
forcePlacement: forcePlacement,
|
|
222
|
-
fitHeight: height,
|
|
223
|
-
fitWidth: width,
|
|
224
|
-
alignX: align,
|
|
225
|
-
stick: true,
|
|
226
|
-
zIndex: zIndex,
|
|
227
|
-
mountTo: popupsMountPoint,
|
|
228
|
-
boundariesElement: popupsBoundariesElement,
|
|
229
|
-
scrollableElement: popupsScrollableElement,
|
|
230
|
-
onPositionCalculated: customPositionCalculation,
|
|
231
|
-
style: scrollable ? {
|
|
232
|
-
maxWidth: '100%'
|
|
233
|
-
} : {},
|
|
234
|
-
focusTrap: focusTrap,
|
|
235
|
-
preventOverflow: preventPopupOverflow
|
|
236
|
-
}, /*#__PURE__*/React.createElement(ToolbarLoader, {
|
|
237
|
-
target: targetRef,
|
|
238
|
-
items: toolbarItems,
|
|
239
|
-
node: node,
|
|
240
|
-
dispatchCommand: dispatchCommand,
|
|
241
|
-
editorView: editorView,
|
|
242
|
-
className: className,
|
|
243
|
-
focusEditor: () => editorView.focus(),
|
|
244
|
-
providerFactory: providerFactory,
|
|
245
|
-
popupsMountPoint: popupsMountPoint,
|
|
246
|
-
popupsBoundariesElement: popupsBoundariesElement,
|
|
247
|
-
popupsScrollableElement: popupsScrollableElement,
|
|
248
|
-
dispatchAnalyticsEvent: dispatchAnalyticsEvent,
|
|
249
|
-
extensionsProvider: extensionsState === null || extensionsState === void 0 ? void 0 : extensionsState.extensionProvider,
|
|
250
|
-
scrollable: scrollable,
|
|
251
|
-
featureFlags: featureFlags,
|
|
252
|
-
api: api
|
|
253
|
-
})), /*#__PURE__*/React.createElement(ConfirmationModal, {
|
|
254
|
-
testId: "ak-floating-toolbar-confirmation-modal",
|
|
255
|
-
options: confirmDialogOptions,
|
|
256
|
-
onConfirm: (isChecked = false) => {
|
|
257
|
-
if (!!confirmDialogOptions.onConfirm) {
|
|
258
|
-
dispatchCommand(confirmDialogOptions.onConfirm(isChecked));
|
|
259
|
-
} else {
|
|
260
|
-
dispatchCommand(confirmButtonItem.onClick);
|
|
261
|
-
}
|
|
262
|
-
},
|
|
263
|
-
onClose: () => {
|
|
264
|
-
dispatchCommand(hideConfirmDialog());
|
|
265
|
-
// Need to set focus to Editor here,
|
|
266
|
-
// As when the Confirmation dialog pop up, and user interacts with the dialog, Editor loses focus.
|
|
267
|
-
// So when Confirmation dialog is closed, Editor does not have the focus, then cursor goes to the position 1 of the doc,
|
|
268
|
-
// instead of the cursor position before the dialog pop up.
|
|
269
|
-
if (!editorView.hasFocus()) {
|
|
270
|
-
editorView.focus();
|
|
271
|
-
}
|
|
272
|
-
}
|
|
273
|
-
}));
|
|
274
|
-
}
|
|
161
|
+
return /*#__PURE__*/React.createElement(ContentComponent, {
|
|
162
|
+
editorView: editorView,
|
|
163
|
+
pluginInjectionApi: api,
|
|
164
|
+
popupsMountPoint: popupsMountPoint,
|
|
165
|
+
popupsBoundariesElement: popupsBoundariesElement,
|
|
166
|
+
popupsScrollableElement: popupsScrollableElement,
|
|
167
|
+
providerFactory: providerFactory,
|
|
168
|
+
dispatchAnalyticsEvent: dispatchAnalyticsEvent
|
|
275
169
|
});
|
|
276
170
|
}
|
|
277
171
|
};
|
|
278
172
|
};
|
|
173
|
+
import { useSharedPluginState } from '@atlaskit/editor-common/hooks';
|
|
174
|
+
function ContentComponent({
|
|
175
|
+
pluginInjectionApi,
|
|
176
|
+
editorView,
|
|
177
|
+
popupsMountPoint,
|
|
178
|
+
popupsBoundariesElement,
|
|
179
|
+
popupsScrollableElement,
|
|
180
|
+
providerFactory,
|
|
181
|
+
dispatchAnalyticsEvent
|
|
182
|
+
}) {
|
|
183
|
+
var _pluginInjectionApi$d, _pluginInjectionApi$d2, _configWithNodeInfo$c, _configWithNodeInfo$c2;
|
|
184
|
+
const featureFlags = (pluginInjectionApi === null || pluginInjectionApi === void 0 ? void 0 : (_pluginInjectionApi$d = pluginInjectionApi.dependencies) === null || _pluginInjectionApi$d === void 0 ? void 0 : (_pluginInjectionApi$d2 = _pluginInjectionApi$d.featureFlags) === null || _pluginInjectionApi$d2 === void 0 ? void 0 : _pluginInjectionApi$d2.sharedState.currentState()) || {};
|
|
185
|
+
const {
|
|
186
|
+
floatingToolbarState,
|
|
187
|
+
editorDisabledState
|
|
188
|
+
} = useSharedPluginState(pluginInjectionApi, ['floatingToolbar', 'editorDisabled']);
|
|
189
|
+
const {
|
|
190
|
+
configWithNodeInfo,
|
|
191
|
+
floatingToolbarData
|
|
192
|
+
} = floatingToolbarState !== null && floatingToolbarState !== void 0 ? floatingToolbarState : {};
|
|
193
|
+
if (!configWithNodeInfo || !configWithNodeInfo.config || typeof ((_configWithNodeInfo$c = configWithNodeInfo.config) === null || _configWithNodeInfo$c === void 0 ? void 0 : _configWithNodeInfo$c.visible) !== 'undefined' && !((_configWithNodeInfo$c2 = configWithNodeInfo.config) !== null && _configWithNodeInfo$c2 !== void 0 && _configWithNodeInfo$c2.visible)) {
|
|
194
|
+
return null;
|
|
195
|
+
}
|
|
196
|
+
const {
|
|
197
|
+
config,
|
|
198
|
+
node
|
|
199
|
+
} = configWithNodeInfo;
|
|
200
|
+
const {
|
|
201
|
+
title,
|
|
202
|
+
getDomRef = getDomRefFromSelection,
|
|
203
|
+
items,
|
|
204
|
+
align = 'center',
|
|
205
|
+
className = '',
|
|
206
|
+
height,
|
|
207
|
+
width,
|
|
208
|
+
zIndex,
|
|
209
|
+
offset = [0, 12],
|
|
210
|
+
forcePlacement,
|
|
211
|
+
preventPopupOverflow,
|
|
212
|
+
onPositionCalculated,
|
|
213
|
+
focusTrap
|
|
214
|
+
} = config;
|
|
215
|
+
const targetRef = getDomRef(editorView, dispatchAnalyticsEvent);
|
|
216
|
+
if (!targetRef || editorDisabledState && editorDisabledState.editorDisabled) {
|
|
217
|
+
return null;
|
|
218
|
+
}
|
|
219
|
+
let customPositionCalculation;
|
|
220
|
+
const toolbarItems = processCopyButtonItems(editorView.state)(Array.isArray(items) ? items : items(node), pluginInjectionApi === null || pluginInjectionApi === void 0 ? void 0 : pluginInjectionApi.dependencies.decorations.actions.hoverDecoration);
|
|
221
|
+
if (onPositionCalculated) {
|
|
222
|
+
customPositionCalculation = nextPos => {
|
|
223
|
+
return onPositionCalculated(editorView, nextPos);
|
|
224
|
+
};
|
|
225
|
+
}
|
|
226
|
+
const dispatchCommand = fn => fn && fn(editorView.state, editorView.dispatch, editorView);
|
|
227
|
+
|
|
228
|
+
// Confirm dialog
|
|
229
|
+
const {
|
|
230
|
+
confirmDialogForItem
|
|
231
|
+
} = floatingToolbarData || {};
|
|
232
|
+
const confirmButtonItem = confirmDialogForItem ? toolbarItems[confirmDialogForItem] : undefined;
|
|
233
|
+
const scrollable = featureFlags.floatingToolbarCopyButton && config.scrollable;
|
|
234
|
+
const confirmDialogOptions = typeof (confirmButtonItem === null || confirmButtonItem === void 0 ? void 0 : confirmButtonItem.confirmDialog) === 'function' ? confirmButtonItem === null || confirmButtonItem === void 0 ? void 0 : confirmButtonItem.confirmDialog() : confirmButtonItem === null || confirmButtonItem === void 0 ? void 0 : confirmButtonItem.confirmDialog;
|
|
235
|
+
return /*#__PURE__*/React.createElement(ErrorBoundary, {
|
|
236
|
+
component: ACTION_SUBJECT.FLOATING_TOOLBAR_PLUGIN,
|
|
237
|
+
componentId: camelCase(title),
|
|
238
|
+
dispatchAnalyticsEvent: dispatchAnalyticsEvent,
|
|
239
|
+
fallbackComponent: null
|
|
240
|
+
}, /*#__PURE__*/React.createElement(Popup, {
|
|
241
|
+
ariaLabel: title,
|
|
242
|
+
offset: offset,
|
|
243
|
+
target: targetRef,
|
|
244
|
+
alignY: "bottom",
|
|
245
|
+
forcePlacement: forcePlacement,
|
|
246
|
+
fitHeight: height,
|
|
247
|
+
fitWidth: width,
|
|
248
|
+
alignX: align,
|
|
249
|
+
stick: true,
|
|
250
|
+
zIndex: zIndex,
|
|
251
|
+
mountTo: popupsMountPoint,
|
|
252
|
+
boundariesElement: popupsBoundariesElement,
|
|
253
|
+
scrollableElement: popupsScrollableElement,
|
|
254
|
+
onPositionCalculated: customPositionCalculation,
|
|
255
|
+
style: scrollable ? {
|
|
256
|
+
maxWidth: '100%'
|
|
257
|
+
} : {},
|
|
258
|
+
focusTrap: focusTrap,
|
|
259
|
+
preventOverflow: preventPopupOverflow
|
|
260
|
+
}, /*#__PURE__*/React.createElement(WithProviders, {
|
|
261
|
+
providerFactory: providerFactory,
|
|
262
|
+
providers: ['extensionProvider'],
|
|
263
|
+
renderNode: providers => {
|
|
264
|
+
return /*#__PURE__*/React.createElement(ToolbarLoader, {
|
|
265
|
+
target: targetRef,
|
|
266
|
+
items: toolbarItems,
|
|
267
|
+
node: node,
|
|
268
|
+
dispatchCommand: dispatchCommand,
|
|
269
|
+
editorView: editorView,
|
|
270
|
+
className: className,
|
|
271
|
+
focusEditor: () => editorView.focus(),
|
|
272
|
+
providerFactory: providerFactory,
|
|
273
|
+
popupsMountPoint: popupsMountPoint,
|
|
274
|
+
popupsBoundariesElement: popupsBoundariesElement,
|
|
275
|
+
popupsScrollableElement: popupsScrollableElement,
|
|
276
|
+
dispatchAnalyticsEvent: dispatchAnalyticsEvent,
|
|
277
|
+
extensionsProvider: providers.extensionProvider,
|
|
278
|
+
scrollable: scrollable,
|
|
279
|
+
featureFlags: featureFlags,
|
|
280
|
+
api: pluginInjectionApi
|
|
281
|
+
});
|
|
282
|
+
}
|
|
283
|
+
})), /*#__PURE__*/React.createElement(ConfirmationModal, {
|
|
284
|
+
testId: "ak-floating-toolbar-confirmation-modal",
|
|
285
|
+
options: confirmDialogOptions,
|
|
286
|
+
onConfirm: (isChecked = false) => {
|
|
287
|
+
if (!!confirmDialogOptions.onConfirm) {
|
|
288
|
+
dispatchCommand(confirmDialogOptions.onConfirm(isChecked));
|
|
289
|
+
} else {
|
|
290
|
+
dispatchCommand(confirmButtonItem.onClick);
|
|
291
|
+
}
|
|
292
|
+
},
|
|
293
|
+
onClose: () => {
|
|
294
|
+
dispatchCommand(hideConfirmDialog());
|
|
295
|
+
// Need to set focus to Editor here,
|
|
296
|
+
// As when the Confirmation dialog pop up, and user interacts with the dialog, Editor loses focus.
|
|
297
|
+
// So when Confirmation dialog is closed, Editor does not have the focus, then cursor goes to the position 1 of the doc,
|
|
298
|
+
// instead of the cursor position before the dialog pop up.
|
|
299
|
+
if (!editorView.hasFocus()) {
|
|
300
|
+
editorView.focus();
|
|
301
|
+
}
|
|
302
|
+
}
|
|
303
|
+
}));
|
|
304
|
+
}
|
|
279
305
|
export default floatingToolbarPlugin;
|
|
280
306
|
|
|
281
307
|
/**
|
|
@@ -303,7 +329,6 @@ function sanitizeFloatingToolbarConfig(config) {
|
|
|
303
329
|
function floatingToolbarPluginFactory(options) {
|
|
304
330
|
const {
|
|
305
331
|
floatingToolbarHandlers,
|
|
306
|
-
dispatch,
|
|
307
332
|
providerFactory,
|
|
308
333
|
getIntl
|
|
309
334
|
} = options;
|
|
@@ -317,7 +342,6 @@ function floatingToolbarPluginFactory(options) {
|
|
|
317
342
|
const newPluginState = {
|
|
318
343
|
...pluginState
|
|
319
344
|
};
|
|
320
|
-
dispatch(pluginKey, newPluginState);
|
|
321
345
|
return newPluginState;
|
|
322
346
|
};
|
|
323
347
|
return new SafePlugin({
|