@atlaskit/editor-core 187.34.2 → 187.35.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 +11 -0
- package/dist/cjs/index.js +10 -42
- package/dist/cjs/plugins/block-type/commands/block-type.js +19 -211
- package/dist/cjs/plugins/block-type/commands/index.js +2 -28
- package/dist/cjs/plugins/block-type/index.js +21 -4
- package/dist/cjs/plugins/block-type/pm-plugins/input-rule.js +9 -64
- package/dist/cjs/plugins/block-type/pm-plugins/keymap.js +1 -1
- package/dist/cjs/plugins/code-block/actions.js +83 -6
- package/dist/cjs/plugins/code-block/index.js +27 -12
- package/dist/cjs/plugins/code-block/pm-plugins/input-rule.js +68 -0
- package/dist/cjs/plugins/date/ui/DatePicker/index.js +3 -2
- package/dist/cjs/plugins/expand/commands.js +3 -3
- package/dist/cjs/plugins/expand/index.js +2 -2
- package/dist/cjs/plugins/index.js +1 -7
- package/dist/cjs/plugins/insert-block/index.js +34 -29
- package/dist/cjs/plugins/panel/actions.js +26 -2
- package/dist/cjs/plugins/panel/index.js +9 -5
- package/dist/cjs/version-wrapper.js +1 -1
- package/dist/es2019/index.js +16 -2
- package/dist/es2019/plugins/block-type/commands/block-type.js +15 -217
- package/dist/es2019/plugins/block-type/commands/index.js +1 -3
- package/dist/es2019/plugins/block-type/index.js +21 -4
- package/dist/es2019/plugins/block-type/pm-plugins/input-rule.js +3 -56
- package/dist/es2019/plugins/block-type/pm-plugins/keymap.js +2 -2
- package/dist/es2019/plugins/code-block/actions.js +84 -3
- package/dist/es2019/plugins/code-block/index.js +22 -7
- package/dist/es2019/plugins/code-block/pm-plugins/input-rule.js +60 -0
- package/dist/es2019/plugins/date/ui/DatePicker/index.js +3 -2
- package/dist/es2019/plugins/expand/commands.js +1 -1
- package/dist/es2019/plugins/expand/index.js +1 -1
- package/dist/es2019/plugins/index.js +0 -1
- package/dist/es2019/plugins/insert-block/index.js +47 -42
- package/dist/es2019/plugins/panel/actions.js +26 -2
- package/dist/es2019/plugins/panel/index.js +8 -4
- package/dist/es2019/version-wrapper.js +1 -1
- package/dist/esm/index.js +16 -2
- package/dist/esm/plugins/block-type/commands/block-type.js +17 -205
- package/dist/esm/plugins/block-type/commands/index.js +1 -3
- package/dist/esm/plugins/block-type/index.js +21 -4
- package/dist/esm/plugins/block-type/pm-plugins/input-rule.js +3 -58
- package/dist/esm/plugins/block-type/pm-plugins/keymap.js +2 -2
- package/dist/esm/plugins/code-block/actions.js +76 -3
- package/dist/esm/plugins/code-block/index.js +25 -11
- package/dist/esm/plugins/code-block/pm-plugins/input-rule.js +62 -0
- package/dist/esm/plugins/date/ui/DatePicker/index.js +3 -2
- package/dist/esm/plugins/expand/commands.js +1 -1
- package/dist/esm/plugins/expand/index.js +1 -1
- package/dist/esm/plugins/index.js +0 -1
- package/dist/esm/plugins/insert-block/index.js +27 -22
- package/dist/esm/plugins/panel/actions.js +24 -2
- package/dist/esm/plugins/panel/index.js +8 -4
- package/dist/esm/version-wrapper.js +1 -1
- package/dist/types/index.d.ts +16 -3
- package/dist/types/labs/next/presets/default.d.ts +6 -0
- package/dist/types/plugins/block-type/commands/block-type.d.ts +1 -25
- package/dist/types/plugins/block-type/commands/index.d.ts +1 -3
- package/dist/types/plugins/block-type/index.d.ts +10 -2
- package/dist/types/plugins/code-block/actions.d.ts +11 -0
- package/dist/types/plugins/code-block/index.d.ts +6 -1
- package/dist/types/plugins/code-block/pm-plugins/input-rule.d.ts +3 -0
- package/dist/types/plugins/date/ui/DatePicker/index.d.ts +2 -2
- package/dist/types/plugins/index.d.ts +0 -2
- package/dist/types/plugins/insert-block/types.d.ts +7 -1
- package/dist/types/plugins/panel/actions.d.ts +4 -1
- package/dist/types/plugins/panel/index.d.ts +11 -2
- package/dist/types-ts4.5/index.d.ts +16 -3
- package/dist/types-ts4.5/labs/next/presets/default.d.ts +6 -0
- package/dist/types-ts4.5/plugins/block-type/commands/block-type.d.ts +1 -25
- package/dist/types-ts4.5/plugins/block-type/commands/index.d.ts +1 -3
- package/dist/types-ts4.5/plugins/block-type/index.d.ts +10 -2
- package/dist/types-ts4.5/plugins/code-block/actions.d.ts +11 -0
- package/dist/types-ts4.5/plugins/code-block/index.d.ts +6 -1
- package/dist/types-ts4.5/plugins/code-block/pm-plugins/input-rule.d.ts +3 -0
- package/dist/types-ts4.5/plugins/date/ui/DatePicker/index.d.ts +2 -2
- package/dist/types-ts4.5/plugins/index.d.ts +0 -2
- package/dist/types-ts4.5/plugins/insert-block/types.d.ts +7 -1
- package/dist/types-ts4.5/plugins/panel/actions.d.ts +4 -1
- package/dist/types-ts4.5/plugins/panel/index.d.ts +9 -2
- package/package.json +3 -3
- package/report.api.md +62 -23
- package/tmp/api-report-tmp.d.ts +49 -15
- package/dist/cjs/plugins/block-type/commands/insert-block.js +0 -60
- package/dist/es2019/plugins/block-type/commands/insert-block.js +0 -55
- package/dist/esm/plugins/block-type/commands/insert-block.js +0 -53
- package/dist/types/plugins/block-type/commands/insert-block.d.ts +0 -5
- package/dist/types-ts4.5/plugins/block-type/commands/insert-block.d.ts +0 -5
- /package/dist/cjs/plugins/{block-type/commands → code-block}/transform-to-code-block.js +0 -0
- /package/dist/es2019/plugins/{block-type/commands → code-block}/transform-to-code-block.js +0 -0
- /package/dist/esm/plugins/{block-type/commands → code-block}/transform-to-code-block.js +0 -0
- /package/dist/types/plugins/{block-type/commands → code-block}/transform-to-code-block.d.ts +0 -0
- /package/dist/types-ts4.5/plugins/{block-type/commands → code-block}/transform-to-code-block.d.ts +0 -0
|
@@ -4,7 +4,7 @@ import { addAnalytics, ACTION, ACTION_SUBJECT, ACTION_SUBJECT_ID, INPUT_METHOD,
|
|
|
4
4
|
import { GapCursorSelection, Side } from '../selection/gap-cursor-selection';
|
|
5
5
|
import { findExpand } from './utils';
|
|
6
6
|
import { createCommand } from './pm-plugins/plugin-factory';
|
|
7
|
-
import { createWrapSelectionTransaction } from '
|
|
7
|
+
import { createWrapSelectionTransaction } from '@atlaskit/editor-common/utils';
|
|
8
8
|
import { safeInsert } from '@atlaskit/editor-prosemirror/utils';
|
|
9
9
|
export const setExpandRef = ref => createCommand({
|
|
10
10
|
type: 'SET_EXPAND_REF',
|
|
@@ -7,7 +7,7 @@ import { ACTION, ACTION_SUBJECT, ACTION_SUBJECT_ID, addAnalytics, EVENT_TYPE, IN
|
|
|
7
7
|
import { getToolbarConfig } from './toolbar';
|
|
8
8
|
import { createExpandNode } from './commands';
|
|
9
9
|
import { messages } from '../insert-block/ui/ToolbarInsertBlock/messages';
|
|
10
|
-
import { createWrapSelectionTransaction } from '
|
|
10
|
+
import { createWrapSelectionTransaction } from '@atlaskit/editor-common/utils';
|
|
11
11
|
const expandPlugin = ({
|
|
12
12
|
config: options = {},
|
|
13
13
|
api
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
export { basePlugin } from './base';
|
|
2
2
|
export { default as blockTypePlugin } from './block-type';
|
|
3
|
-
export { pluginKey as blockPluginStateKey } from './block-type';
|
|
4
3
|
export { default as betterTypeHistoryPlugin } from './better-type-history';
|
|
5
4
|
export { default as clearMarksOnChangeToEmptyDocumentPlugin } from './clear-marks-on-change-to-empty-document';
|
|
6
5
|
export { default as codeBlockPlugin } from './code-block';
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
import { WithProviders } from '@atlaskit/editor-common/provider-factory';
|
|
3
|
-
import { pluginKey as blockTypeStateKey } from '../block-type/pm-plugins/main';
|
|
4
3
|
import { stateKey as mediaStateKey } from '../media/pm-plugins/plugin-key';
|
|
5
4
|
import { isTypeAheadAllowed } from '../type-ahead/utils';
|
|
6
5
|
import { pluginKey as layoutStateKey } from '../layout';
|
|
@@ -8,7 +7,7 @@ import { insertMacroFromMacroBrowser } from '../macro';
|
|
|
8
7
|
import WithPluginState from '../../ui/WithPluginState';
|
|
9
8
|
import ToolbarInsertBlock from './ui/ToolbarInsertBlock';
|
|
10
9
|
import { pluginKey as typeAheadPluginKey } from '../type-ahead/pm-plugins/key';
|
|
11
|
-
import {
|
|
10
|
+
import { BLOCK_QUOTE, CODE_BLOCK, PANEL } from '../block-type/types';
|
|
12
11
|
import { INPUT_METHOD } from '../analytics';
|
|
13
12
|
import { pluginKey as placeholderTextStateKey } from '../placeholder-text/plugin-key';
|
|
14
13
|
import { pluginKey as macroStateKey } from '../macro/plugin-key';
|
|
@@ -27,6 +26,24 @@ const toolbarSizeToButtons = toolbarSize => {
|
|
|
27
26
|
return 0;
|
|
28
27
|
}
|
|
29
28
|
};
|
|
29
|
+
/**
|
|
30
|
+
* Wrapper over insertBlockTypeWithAnalytics to autobind toolbar input method
|
|
31
|
+
* @param name Block name
|
|
32
|
+
*/
|
|
33
|
+
function handleInsertBlockType(insertCodeBlock, insertPanel, insertBlockQuote) {
|
|
34
|
+
return name => {
|
|
35
|
+
if (name === CODE_BLOCK.name && insertCodeBlock) {
|
|
36
|
+
return insertCodeBlock(INPUT_METHOD.TOOLBAR);
|
|
37
|
+
}
|
|
38
|
+
if (name === PANEL.name && insertPanel) {
|
|
39
|
+
return insertPanel(INPUT_METHOD.TOOLBAR);
|
|
40
|
+
}
|
|
41
|
+
if (name === BLOCK_QUOTE.name && insertBlockQuote) {
|
|
42
|
+
return insertBlockQuote(INPUT_METHOD.TOOLBAR);
|
|
43
|
+
}
|
|
44
|
+
return () => false;
|
|
45
|
+
};
|
|
46
|
+
}
|
|
30
47
|
const insertBlockPlugin = ({
|
|
31
48
|
config: options = {},
|
|
32
49
|
api
|
|
@@ -54,41 +71,39 @@ const insertBlockPlugin = ({
|
|
|
54
71
|
return /*#__PURE__*/React.createElement(WithPluginState, {
|
|
55
72
|
plugins: {
|
|
56
73
|
typeAheadState: typeAheadPluginKey,
|
|
57
|
-
// needed to check isTypeAheadAllowed in ToolbarInsertBlock
|
|
58
|
-
blockTypeState: blockTypeStateKey,
|
|
59
74
|
mediaState: mediaStateKey,
|
|
60
75
|
macroState: macroStateKey,
|
|
61
76
|
placeholderTextState: placeholderTextStateKey,
|
|
62
77
|
layoutState: layoutStateKey
|
|
63
78
|
},
|
|
64
79
|
render: ({
|
|
65
|
-
blockTypeState,
|
|
66
80
|
mediaState,
|
|
67
81
|
macroState = {},
|
|
68
82
|
placeholderTextState,
|
|
69
83
|
layoutState
|
|
70
|
-
}) =>
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
84
|
+
}) => {
|
|
85
|
+
return /*#__PURE__*/React.createElement(ToolbarInsertBlockWithInjectionApi, {
|
|
86
|
+
pluginInjectionApi: api,
|
|
87
|
+
editorView: editorView,
|
|
88
|
+
editorActions: editorActions,
|
|
89
|
+
dispatchAnalyticsEvent: dispatchAnalyticsEvent,
|
|
90
|
+
providerFactory: providerFactory,
|
|
91
|
+
popupsMountPoint: popupsMountPoint,
|
|
92
|
+
popupsBoundariesElement: popupsBoundariesElement,
|
|
93
|
+
popupsScrollableElement: popupsScrollableElement,
|
|
94
|
+
toolbarSize: toolbarSize,
|
|
95
|
+
disabled: disabled,
|
|
96
|
+
isToolbarReducedSpacing: isToolbarReducedSpacing,
|
|
97
|
+
isLastItem: isLastItem,
|
|
98
|
+
featureFlags: featureFlags,
|
|
99
|
+
mediaState: mediaState,
|
|
100
|
+
macroState: macroState,
|
|
101
|
+
placeholderTextState: placeholderTextState,
|
|
102
|
+
layoutState: layoutState,
|
|
103
|
+
providers: providers,
|
|
104
|
+
options: options
|
|
105
|
+
});
|
|
106
|
+
}
|
|
92
107
|
});
|
|
93
108
|
};
|
|
94
109
|
return /*#__PURE__*/React.createElement(WithProviders, {
|
|
@@ -103,7 +118,6 @@ function ToolbarInsertBlockWithInjectionApi({
|
|
|
103
118
|
editorView,
|
|
104
119
|
editorActions,
|
|
105
120
|
dispatchAnalyticsEvent,
|
|
106
|
-
providerFactory,
|
|
107
121
|
popupsMountPoint,
|
|
108
122
|
popupsBoundariesElement,
|
|
109
123
|
popupsScrollableElement,
|
|
@@ -114,31 +128,22 @@ function ToolbarInsertBlockWithInjectionApi({
|
|
|
114
128
|
providers,
|
|
115
129
|
pluginInjectionApi,
|
|
116
130
|
options,
|
|
117
|
-
blockTypeState,
|
|
118
131
|
mediaState,
|
|
119
132
|
macroState,
|
|
120
133
|
placeholderTextState,
|
|
121
134
|
layoutState,
|
|
122
135
|
featureFlags
|
|
123
136
|
}) {
|
|
124
|
-
var _pluginInjectionApi$
|
|
137
|
+
var _pluginInjectionApi$i, _pluginInjectionApi$c, _pluginInjectionApi$p, _pluginInjectionApi$b;
|
|
125
138
|
const buttons = toolbarSizeToButtons(toolbarSize);
|
|
126
139
|
const {
|
|
127
140
|
dateState,
|
|
128
141
|
hyperlinkState,
|
|
129
142
|
imageUploadState,
|
|
130
143
|
mentionState,
|
|
131
|
-
emojiState
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
/**
|
|
135
|
-
* Wrapper over insertBlockTypeWithAnalytics to autobind toolbar input method
|
|
136
|
-
* @param name Block name
|
|
137
|
-
*/
|
|
138
|
-
const handleInsertBlockType = React.useCallback(name => {
|
|
139
|
-
var _pluginInjectionApi$a;
|
|
140
|
-
return insertBlockTypesWithAnalytics(name, INPUT_METHOD.TOOLBAR, pluginInjectionApi === null || pluginInjectionApi === void 0 ? void 0 : (_pluginInjectionApi$a = pluginInjectionApi.analytics) === null || _pluginInjectionApi$a === void 0 ? void 0 : _pluginInjectionApi$a.actions);
|
|
141
|
-
}, [pluginInjectionApi === null || pluginInjectionApi === void 0 ? void 0 : (_pluginInjectionApi$a2 = pluginInjectionApi.analytics) === null || _pluginInjectionApi$a2 === void 0 ? void 0 : _pluginInjectionApi$a2.actions]);
|
|
144
|
+
emojiState,
|
|
145
|
+
blockTypeState
|
|
146
|
+
} = useSharedPluginState(pluginInjectionApi, ['hyperlink', 'date', 'imageUpload', 'mention', 'emoji', 'blockType']);
|
|
142
147
|
return /*#__PURE__*/React.createElement(ToolbarInsertBlock, {
|
|
143
148
|
pluginInjectionApi: pluginInjectionApi,
|
|
144
149
|
buttons: buttons,
|
|
@@ -168,7 +173,7 @@ function ToolbarInsertBlockWithInjectionApi({
|
|
|
168
173
|
emojiProvider: providers.emojiProvider,
|
|
169
174
|
nativeStatusSupported: options.nativeStatusSupported,
|
|
170
175
|
horizontalRuleEnabled: options.horizontalRuleEnabled,
|
|
171
|
-
onInsertBlockType: handleInsertBlockType,
|
|
176
|
+
onInsertBlockType: handleInsertBlockType(pluginInjectionApi === null || pluginInjectionApi === void 0 ? void 0 : (_pluginInjectionApi$c = pluginInjectionApi.codeBlock) === null || _pluginInjectionApi$c === void 0 ? void 0 : _pluginInjectionApi$c.actions.insertCodeBlock, pluginInjectionApi === null || pluginInjectionApi === void 0 ? void 0 : (_pluginInjectionApi$p = pluginInjectionApi.panel) === null || _pluginInjectionApi$p === void 0 ? void 0 : _pluginInjectionApi$p.actions.insertPanel, pluginInjectionApi === null || pluginInjectionApi === void 0 ? void 0 : (_pluginInjectionApi$b = pluginInjectionApi.blockType) === null || _pluginInjectionApi$b === void 0 ? void 0 : _pluginInjectionApi$b.actions.insertBlockQuote),
|
|
172
177
|
onInsertMacroFromMacroBrowser: insertMacroFromMacroBrowser,
|
|
173
178
|
macroProvider: macroState.macroProvider,
|
|
174
179
|
popupsMountPoint: popupsMountPoint,
|
|
@@ -1,8 +1,11 @@
|
|
|
1
1
|
import { removeParentNodeOfType, findSelectedNodeOfType, removeSelectedNode, findParentNodeOfType } from '@atlaskit/editor-prosemirror/utils';
|
|
2
2
|
import { NodeSelection } from '@atlaskit/editor-prosemirror/state';
|
|
3
|
-
import {
|
|
3
|
+
import { PanelType } from '@atlaskit/adf-schema';
|
|
4
|
+
import { ACTION, ACTION_SUBJECT, ACTION_SUBJECT_ID, INPUT_METHOD, EVENT_TYPE, addAnalytics } from '../analytics';
|
|
4
5
|
import { findPanel } from './utils';
|
|
5
6
|
import { getPanelTypeBackgroundNoTokens } from '@atlaskit/editor-common/panel';
|
|
7
|
+
import { withAnalytics } from '@atlaskit/editor-common/editor-analytics';
|
|
8
|
+
import { wrapSelectionIn } from '@atlaskit/editor-common/utils';
|
|
6
9
|
export const removePanel = () => (state, dispatch) => {
|
|
7
10
|
const {
|
|
8
11
|
schema: {
|
|
@@ -88,4 +91,25 @@ export const changePanelType = (panelType, panelOptions = {}, allowCustomPanel =
|
|
|
88
91
|
dispatch(changePanelTypeTr);
|
|
89
92
|
}
|
|
90
93
|
return true;
|
|
91
|
-
};
|
|
94
|
+
};
|
|
95
|
+
export function insertPanelWithAnalytics(inputMethod, analyticsAPI) {
|
|
96
|
+
return withAnalytics(analyticsAPI, {
|
|
97
|
+
action: ACTION.INSERTED,
|
|
98
|
+
actionSubject: ACTION_SUBJECT.DOCUMENT,
|
|
99
|
+
actionSubjectId: ACTION_SUBJECT_ID.PANEL,
|
|
100
|
+
attributes: {
|
|
101
|
+
inputMethod: inputMethod,
|
|
102
|
+
panelType: PanelType.INFO // only info panels can be inserted via this action
|
|
103
|
+
},
|
|
104
|
+
|
|
105
|
+
eventType: EVENT_TYPE.TRACK
|
|
106
|
+
})(function (state, dispatch) {
|
|
107
|
+
const {
|
|
108
|
+
nodes
|
|
109
|
+
} = state.schema;
|
|
110
|
+
if (nodes.panel && nodes.paragraph) {
|
|
111
|
+
return wrapSelectionIn(nodes.panel)(state, dispatch);
|
|
112
|
+
}
|
|
113
|
+
return false;
|
|
114
|
+
});
|
|
115
|
+
}
|
|
@@ -5,13 +5,11 @@ import { getToolbarConfig } from './toolbar';
|
|
|
5
5
|
import keymap from './pm-plugins/keymaps';
|
|
6
6
|
import { addAnalytics, ACTION, ACTION_SUBJECT, ACTION_SUBJECT_ID, INPUT_METHOD, EVENT_TYPE } from '../analytics';
|
|
7
7
|
import { IconPanel, IconPanelNote, IconPanelSuccess, IconPanelWarning, IconPanelError } from '@atlaskit/editor-common/quick-insert';
|
|
8
|
+
import { createWrapSelectionTransaction } from '@atlaskit/editor-common/utils';
|
|
8
9
|
import { messages } from '../block-type/messages';
|
|
9
10
|
import { IconCustomPanel } from '@atlaskit/editor-common/quick-insert';
|
|
10
11
|
import { T50 } from '@atlaskit/theme/colors';
|
|
11
|
-
|
|
12
|
-
// Insertions via the drop down menu
|
|
13
|
-
// tslint-ignore-next-line
|
|
14
|
-
import { createWrapSelectionTransaction } from '../block-type/commands/block-type';
|
|
12
|
+
import { insertPanelWithAnalytics } from './actions';
|
|
15
13
|
const panelPlugin = ({
|
|
16
14
|
config: options = {},
|
|
17
15
|
api
|
|
@@ -36,6 +34,12 @@ const panelPlugin = ({
|
|
|
36
34
|
plugin: () => keymap()
|
|
37
35
|
}];
|
|
38
36
|
},
|
|
37
|
+
actions: {
|
|
38
|
+
insertPanel(inputMethod) {
|
|
39
|
+
var _api$analytics;
|
|
40
|
+
return insertPanelWithAnalytics(inputMethod, api === null || api === void 0 ? void 0 : (_api$analytics = api.analytics) === null || _api$analytics === void 0 ? void 0 : _api$analytics.actions);
|
|
41
|
+
}
|
|
42
|
+
},
|
|
39
43
|
pluginsOptions: {
|
|
40
44
|
quickInsert: ({
|
|
41
45
|
formatMessage
|
package/dist/esm/index.js
CHANGED
|
@@ -20,10 +20,24 @@ export { mentionPluginKey } from './plugins/mentions';
|
|
|
20
20
|
export { textColorPluginKey } from './plugins/text-color';
|
|
21
21
|
export { changeColor } from './plugins/text-color/commands/change-color';
|
|
22
22
|
export { insertHorizontalRule } from './plugins/rule/commands';
|
|
23
|
-
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* @private
|
|
26
|
+
* @deprecated DO NOT USE, temporary solution while decoupling plugins from editor-core
|
|
27
|
+
*/
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* @private
|
|
31
|
+
* @deprecated DO NOT USE, temporary solution while decoupling plugins from editor-core
|
|
32
|
+
*/
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* @private
|
|
36
|
+
* @deprecated DO NOT USE, temporary solution while decoupling plugins from editor-core
|
|
37
|
+
*/
|
|
38
|
+
|
|
24
39
|
export { subscribeToToolbarAndPickerUpdates } from './plugins/view-update-subscription/subscribe/toolbarAndPickerUpdates';
|
|
25
40
|
export { subscribeTypeAheadUpdates } from './plugins/view-update-subscription/subscribe/type-ahead-updates';
|
|
26
|
-
export { insertBlockType, insertBlockTypesWithAnalytics, setBlockType, setBlockTypeWithAnalytics } from './plugins/block-type/commands';
|
|
27
41
|
export { createTable } from '@atlaskit/editor-plugin-table/commands';
|
|
28
42
|
export { insertTaskDecisionCommand } from './plugins/tasks-and-decisions/commands';
|
|
29
43
|
export { EventDispatcher } from './event-dispatcher';
|
|
@@ -1,16 +1,11 @@
|
|
|
1
1
|
function _createForOfIteratorHelper(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (!it) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e) { throw _e; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var normalCompletion = true, didErr = false, err; return { s: function s() { it = it.call(o); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it.return != null) it.return(); } finally { if (didErr) throw err; } } }; }
|
|
2
2
|
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
|
|
3
3
|
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
|
|
4
|
-
import { findWrapping } from '@atlaskit/editor-prosemirror/transform';
|
|
5
|
-
import { safeInsert } from '@atlaskit/editor-prosemirror/utils';
|
|
6
|
-
import { PanelType } from '@atlaskit/adf-schema';
|
|
7
4
|
import { CellSelection } from '@atlaskit/editor-tables';
|
|
8
|
-
import { shouldSplitSelectedNodeOnNodeInsertion } from '@atlaskit/editor-common/insert';
|
|
9
5
|
import { ACTION, ACTION_SUBJECT, ACTION_SUBJECT_ID, EVENT_TYPE } from '@atlaskit/editor-common/analytics';
|
|
10
6
|
import { withAnalytics } from '@atlaskit/editor-common/editor-analytics';
|
|
11
|
-
import { filterChildrenBetween,
|
|
12
|
-
import {
|
|
13
|
-
import { transformToCodeBlockAction } from './transform-to-code-block';
|
|
7
|
+
import { filterChildrenBetween, wrapSelectionIn } from '@atlaskit/editor-common/utils';
|
|
8
|
+
import { HEADINGS_BY_NAME, NORMAL_TEXT } from '../types';
|
|
14
9
|
export function setBlockType(name) {
|
|
15
10
|
return function (state, dispatch) {
|
|
16
11
|
var nodes = state.schema.nodes;
|
|
@@ -137,25 +132,11 @@ export var setHeadingWithAnalytics = function setHeadingWithAnalytics(newHeading
|
|
|
137
132
|
})(setHeading(newHeadingLevel));
|
|
138
133
|
});
|
|
139
134
|
};
|
|
140
|
-
|
|
135
|
+
function insertBlockQuote() {
|
|
141
136
|
return function (state, dispatch) {
|
|
142
137
|
var nodes = state.schema.nodes;
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
if (nodes.paragraph && nodes.blockquote) {
|
|
146
|
-
return wrapSelectionIn(nodes.blockquote)(state, dispatch);
|
|
147
|
-
}
|
|
148
|
-
break;
|
|
149
|
-
case CODE_BLOCK.name:
|
|
150
|
-
if (nodes.codeBlock) {
|
|
151
|
-
return insertCodeBlock()(state, dispatch);
|
|
152
|
-
}
|
|
153
|
-
break;
|
|
154
|
-
case PANEL.name:
|
|
155
|
-
if (nodes.panel && nodes.paragraph) {
|
|
156
|
-
return wrapSelectionIn(nodes.panel)(state, dispatch);
|
|
157
|
-
}
|
|
158
|
-
break;
|
|
138
|
+
if (nodes.paragraph && nodes.blockquote) {
|
|
139
|
+
return wrapSelectionIn(nodes.blockquote)(state, dispatch);
|
|
159
140
|
}
|
|
160
141
|
return false;
|
|
161
142
|
};
|
|
@@ -169,189 +150,20 @@ export function insertBlockType(name) {
|
|
|
169
150
|
* otherwise Editor becomes very sad and crashes
|
|
170
151
|
* @returns - command that inserts block type
|
|
171
152
|
*/
|
|
172
|
-
export var
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
attributes: {
|
|
181
|
-
inputMethod: inputMethod
|
|
182
|
-
}
|
|
183
|
-
})(insertBlockType(name));
|
|
184
|
-
case CODE_BLOCK.name:
|
|
185
|
-
return withAnalytics(editorAnalyticsApi, {
|
|
186
|
-
action: ACTION.INSERTED,
|
|
187
|
-
actionSubject: ACTION_SUBJECT.DOCUMENT,
|
|
188
|
-
actionSubjectId: ACTION_SUBJECT_ID.CODE_BLOCK,
|
|
189
|
-
attributes: {
|
|
190
|
-
inputMethod: inputMethod
|
|
191
|
-
},
|
|
192
|
-
eventType: EVENT_TYPE.TRACK
|
|
193
|
-
})(insertBlockType(name));
|
|
194
|
-
case PANEL.name:
|
|
195
|
-
return withAnalytics(editorAnalyticsApi, {
|
|
196
|
-
action: ACTION.INSERTED,
|
|
197
|
-
actionSubject: ACTION_SUBJECT.DOCUMENT,
|
|
198
|
-
actionSubjectId: ACTION_SUBJECT_ID.PANEL,
|
|
199
|
-
attributes: {
|
|
200
|
-
inputMethod: inputMethod,
|
|
201
|
-
panelType: PanelType.INFO // only info panels can be inserted from toolbar
|
|
202
|
-
},
|
|
203
|
-
|
|
204
|
-
eventType: EVENT_TYPE.TRACK
|
|
205
|
-
})(insertBlockType(name));
|
|
206
|
-
default:
|
|
207
|
-
return insertBlockType(name);
|
|
208
|
-
}
|
|
209
|
-
};
|
|
210
|
-
|
|
211
|
-
/**
|
|
212
|
-
* This function creates a new transaction that wraps the current selection
|
|
213
|
-
* in the specified node type if it results in a valid transaction.
|
|
214
|
-
* If not valid, it performs a safe insert operation.
|
|
215
|
-
*
|
|
216
|
-
* Example of when wrapping might not be valid is when attempting to wrap
|
|
217
|
-
* content that is already inside a panel with another panel
|
|
218
|
-
*/
|
|
219
|
-
export function createWrapSelectionTransaction(_ref3) {
|
|
220
|
-
var state = _ref3.state,
|
|
221
|
-
type = _ref3.type,
|
|
222
|
-
nodeAttributes = _ref3.nodeAttributes;
|
|
223
|
-
var tr = state.tr;
|
|
224
|
-
var _state$schema$marks = state.schema.marks,
|
|
225
|
-
alignment = _state$schema$marks.alignment,
|
|
226
|
-
indentation = _state$schema$marks.indentation;
|
|
227
|
-
|
|
228
|
-
/** Alignment or Indentation is not valid inside block types */
|
|
229
|
-
var removeAlignTr = removeBlockMarks(state, [alignment, indentation]);
|
|
230
|
-
tr = removeAlignTr || tr;
|
|
231
|
-
|
|
232
|
-
/**Get range and wrapping needed for the selection*/
|
|
233
|
-
var _getWrappingOptions = getWrappingOptions(state, type, nodeAttributes),
|
|
234
|
-
range = _getWrappingOptions.range,
|
|
235
|
-
wrapping = _getWrappingOptions.wrapping;
|
|
236
|
-
if (wrapping) {
|
|
237
|
-
tr.wrap(range, wrapping).scrollIntoView();
|
|
238
|
-
} else {
|
|
239
|
-
/** We always want to append a block type */
|
|
240
|
-
safeInsert(type.createAndFill(nodeAttributes))(tr).scrollIntoView();
|
|
241
|
-
}
|
|
242
|
-
return tr;
|
|
243
|
-
}
|
|
244
|
-
function getWrappingOptions(state, type, nodeAttributes) {
|
|
245
|
-
var _state$selection = state.selection,
|
|
246
|
-
$from = _state$selection.$from,
|
|
247
|
-
$to = _state$selection.$to;
|
|
248
|
-
var range = $from.blockRange($to);
|
|
249
|
-
var isAllowedChild = true;
|
|
250
|
-
/**
|
|
251
|
-
* Added a check to avoid wrapping codeblock
|
|
252
|
-
*/
|
|
253
|
-
if (state.selection.empty) {
|
|
254
|
-
state.doc.nodesBetween($from.pos, $to.pos, function (node) {
|
|
255
|
-
if (!isAllowedChild) {
|
|
256
|
-
return false;
|
|
257
|
-
}
|
|
258
|
-
return isAllowedChild = node.type !== state.schema.nodes.codeBlock;
|
|
259
|
-
});
|
|
260
|
-
}
|
|
261
|
-
var wrapping = isAllowedChild && range && findWrapping(range, type, nodeAttributes);
|
|
262
|
-
return {
|
|
263
|
-
range: range,
|
|
264
|
-
wrapping: wrapping
|
|
265
|
-
};
|
|
266
|
-
}
|
|
267
|
-
|
|
268
|
-
/**
|
|
269
|
-
* Function will add wrapping node.
|
|
270
|
-
* 1. If currently selected blocks can be wrapped in the wrapper type it will wrap them.
|
|
271
|
-
* 2. If current block can not be wrapped inside wrapping block it will create a new block below selection,
|
|
272
|
-
* and set selection on it.
|
|
273
|
-
*/
|
|
274
|
-
function wrapSelectionIn(type) {
|
|
275
|
-
return function (state, dispatch) {
|
|
276
|
-
var tr = createWrapSelectionTransaction({
|
|
277
|
-
state: state,
|
|
278
|
-
type: type
|
|
279
|
-
});
|
|
280
|
-
if (dispatch) {
|
|
281
|
-
dispatch(tr);
|
|
282
|
-
}
|
|
283
|
-
return true;
|
|
284
|
-
};
|
|
285
|
-
}
|
|
286
|
-
|
|
287
|
-
/**
|
|
288
|
-
* This function creates a new transaction that inserts a code block,
|
|
289
|
-
* if there is text selected it will wrap the current selection if not it will
|
|
290
|
-
* append the codeblock to the end of the document.
|
|
291
|
-
*/
|
|
292
|
-
export function createInsertCodeBlockTransaction(_ref4) {
|
|
293
|
-
var _state$selection$$fro;
|
|
294
|
-
var state = _ref4.state;
|
|
295
|
-
var tr = state.tr;
|
|
296
|
-
var from = state.selection.from;
|
|
297
|
-
var codeBlock = state.schema.nodes.codeBlock;
|
|
298
|
-
var grandParentNodeType = (_state$selection$$fro = state.selection.$from.node(-1)) === null || _state$selection$$fro === void 0 ? void 0 : _state$selection$$fro.type;
|
|
299
|
-
var parentNodeType = state.selection.$from.parent.type;
|
|
300
|
-
|
|
301
|
-
/** We always want to append a codeBlock unless we're inserting into a paragraph
|
|
302
|
-
* AND it's a valid child of the grandparent node.
|
|
303
|
-
* Insert the current selection as codeBlock content unless it contains nodes other
|
|
304
|
-
* than paragraphs and inline.
|
|
305
|
-
*/
|
|
306
|
-
var canInsertCodeBlock = shouldSplitSelectedNodeOnNodeInsertion({
|
|
307
|
-
parentNodeType: parentNodeType,
|
|
308
|
-
grandParentNodeType: grandParentNodeType,
|
|
309
|
-
content: codeBlock.createAndFill()
|
|
310
|
-
}) && contentAllowedInCodeBlock(state);
|
|
311
|
-
if (canInsertCodeBlock) {
|
|
312
|
-
tr = transformToCodeBlockAction(state, from);
|
|
313
|
-
} else {
|
|
314
|
-
safeInsert(codeBlock.createAndFill())(tr).scrollIntoView();
|
|
315
|
-
}
|
|
316
|
-
return tr;
|
|
317
|
-
}
|
|
318
|
-
|
|
319
|
-
/**
|
|
320
|
-
* Function will insert code block at current selection if block is empty or below current selection and set focus on it.
|
|
321
|
-
*/
|
|
322
|
-
function insertCodeBlock() {
|
|
323
|
-
return function (state, dispatch) {
|
|
324
|
-
var tr = createInsertCodeBlockTransaction({
|
|
325
|
-
state: state
|
|
326
|
-
});
|
|
327
|
-
if (dispatch) {
|
|
328
|
-
dispatch(tr);
|
|
153
|
+
export var insertBlockQuoteWithAnalytics = function insertBlockQuoteWithAnalytics(inputMethod, editorAnalyticsApi) {
|
|
154
|
+
return withAnalytics(editorAnalyticsApi, {
|
|
155
|
+
action: ACTION.FORMATTED,
|
|
156
|
+
actionSubject: ACTION_SUBJECT.TEXT,
|
|
157
|
+
eventType: EVENT_TYPE.TRACK,
|
|
158
|
+
actionSubjectId: ACTION_SUBJECT_ID.FORMAT_BLOCK_QUOTE,
|
|
159
|
+
attributes: {
|
|
160
|
+
inputMethod: inputMethod
|
|
329
161
|
}
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
}
|
|
333
|
-
|
|
334
|
-
/**
|
|
335
|
-
* Check if the current selection contains any nodes that are not permitted
|
|
336
|
-
* as codeBlock child nodes. Note that this allows paragraphs and inline nodes
|
|
337
|
-
* as we extract their text content.
|
|
338
|
-
*/
|
|
339
|
-
function contentAllowedInCodeBlock(state) {
|
|
340
|
-
var _state$selection2 = state.selection,
|
|
341
|
-
$from = _state$selection2.$from,
|
|
342
|
-
$to = _state$selection2.$to;
|
|
343
|
-
var isAllowedChild = true;
|
|
344
|
-
state.doc.nodesBetween($from.pos, $to.pos, function (node) {
|
|
345
|
-
if (!isAllowedChild) {
|
|
346
|
-
return false;
|
|
347
|
-
}
|
|
348
|
-
return isAllowedChild = node.type === state.schema.nodes.listItem || node.type === state.schema.nodes.bulletList || node.type === state.schema.nodes.orderedList || node.type === state.schema.nodes.paragraph || node.isInline || node.isText;
|
|
349
|
-
});
|
|
350
|
-
return isAllowedChild;
|
|
351
|
-
}
|
|
162
|
+
})(insertBlockQuote());
|
|
163
|
+
};
|
|
352
164
|
export var cleanUpAtTheStartOfDocument = function cleanUpAtTheStartOfDocument(state, dispatch) {
|
|
353
|
-
var
|
|
354
|
-
$cursor =
|
|
165
|
+
var _ref3 = state.selection,
|
|
166
|
+
$cursor = _ref3.$cursor;
|
|
355
167
|
if ($cursor && !$cursor.nodeBefore && !$cursor.nodeAfter && $cursor.pos === 1) {
|
|
356
168
|
var tr = state.tr,
|
|
357
169
|
schema = state.schema;
|
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
export { cleanUpAtTheStartOfDocument,
|
|
2
|
-
export { insertBlock } from './insert-block';
|
|
3
|
-
export { isConvertableToCodeBlock, transformToCodeBlockAction } from './transform-to-code-block';
|
|
1
|
+
export { cleanUpAtTheStartOfDocument, insertBlockQuoteWithAnalytics, setBlockType, setBlockTypeWithAnalytics, setHeading, setHeadingWithAnalytics, setNormalText, setNormalTextWithAnalytics } from './block-type';
|
|
4
2
|
export { deleteAndMoveCursor } from './delete-and-move-cursor';
|
|
5
3
|
export { deleteBlockContent } from './delete-block-content';
|
|
@@ -12,6 +12,7 @@ import inputRulePlugin from './pm-plugins/input-rule';
|
|
|
12
12
|
import ToolbarBlockType from './ui/ToolbarBlockType';
|
|
13
13
|
import { setBlockTypeWithAnalytics } from './commands';
|
|
14
14
|
import { messages } from './messages';
|
|
15
|
+
import { insertBlockQuoteWithAnalytics } from './commands/block-type';
|
|
15
16
|
var headingPluginOptions = function headingPluginOptions(_ref, isAllowed, editorAnalyticsApi) {
|
|
16
17
|
var formatMessage = _ref.formatMessage;
|
|
17
18
|
if (!isAllowed) {
|
|
@@ -137,6 +138,22 @@ var blockTypePlugin = function blockTypePlugin(_ref3) {
|
|
|
137
138
|
}
|
|
138
139
|
}];
|
|
139
140
|
},
|
|
141
|
+
actions: {
|
|
142
|
+
insertBlockQuote: function insertBlockQuote(inputMethod) {
|
|
143
|
+
var _api$analytics4;
|
|
144
|
+
return insertBlockQuoteWithAnalytics(inputMethod, api === null || api === void 0 ? void 0 : (_api$analytics4 = api.analytics) === null || _api$analytics4 === void 0 ? void 0 : _api$analytics4.actions);
|
|
145
|
+
},
|
|
146
|
+
setBlockType: function setBlockType(name, inputMethod) {
|
|
147
|
+
var _api$analytics5;
|
|
148
|
+
return setBlockTypeWithAnalytics(name, inputMethod, api === null || api === void 0 ? void 0 : (_api$analytics5 = api.analytics) === null || _api$analytics5 === void 0 ? void 0 : _api$analytics5.actions);
|
|
149
|
+
}
|
|
150
|
+
},
|
|
151
|
+
getSharedState: function getSharedState(editorState) {
|
|
152
|
+
if (!editorState) {
|
|
153
|
+
return;
|
|
154
|
+
}
|
|
155
|
+
return pluginKey.getState(editorState);
|
|
156
|
+
},
|
|
140
157
|
primaryToolbarComponent: function primaryToolbarComponent(_ref7) {
|
|
141
158
|
var editorView = _ref7.editorView,
|
|
142
159
|
popupsMountPoint = _ref7.popupsMountPoint,
|
|
@@ -148,8 +165,8 @@ var blockTypePlugin = function blockTypePlugin(_ref3) {
|
|
|
148
165
|
eventDispatcher = _ref7.eventDispatcher;
|
|
149
166
|
var isSmall = options && options.isUndoRedoButtonsEnabled ? toolbarSize < ToolbarSize.XXL : toolbarSize < ToolbarSize.XL;
|
|
150
167
|
var boundSetBlockType = function boundSetBlockType(name) {
|
|
151
|
-
var _api$
|
|
152
|
-
return setBlockTypeWithAnalytics(name, INPUT_METHOD.TOOLBAR, api === null || api === void 0 ? void 0 : (_api$
|
|
168
|
+
var _api$analytics6;
|
|
169
|
+
return setBlockTypeWithAnalytics(name, INPUT_METHOD.TOOLBAR, api === null || api === void 0 ? void 0 : (_api$analytics6 = api.analytics) === null || _api$analytics6 === void 0 ? void 0 : _api$analytics6.actions)(editorView.state, editorView.dispatch);
|
|
153
170
|
};
|
|
154
171
|
return /*#__PURE__*/React.createElement(WithPluginState, {
|
|
155
172
|
editorView: editorView,
|
|
@@ -174,9 +191,9 @@ var blockTypePlugin = function blockTypePlugin(_ref3) {
|
|
|
174
191
|
},
|
|
175
192
|
pluginsOptions: {
|
|
176
193
|
quickInsert: function quickInsert(intl) {
|
|
177
|
-
var _api$
|
|
194
|
+
var _api$analytics7, _api$analytics8;
|
|
178
195
|
var exclude = options && options.allowBlockType && options.allowBlockType.exclude ? options.allowBlockType.exclude : [];
|
|
179
|
-
return [].concat(_toConsumableArray(blockquotePluginOptions(intl, exclude.indexOf('blockquote') === -1, api === null || api === void 0 ? void 0 : (_api$
|
|
196
|
+
return [].concat(_toConsumableArray(blockquotePluginOptions(intl, exclude.indexOf('blockquote') === -1, api === null || api === void 0 ? void 0 : (_api$analytics7 = api.analytics) === null || _api$analytics7 === void 0 ? void 0 : _api$analytics7.actions)), _toConsumableArray(headingPluginOptions(intl, exclude.indexOf('heading') === -1, api === null || api === void 0 ? void 0 : (_api$analytics8 = api.analytics) === null || _api$analytics8 === void 0 ? void 0 : _api$analytics8.actions)));
|
|
180
197
|
}
|
|
181
198
|
}
|
|
182
199
|
};
|