@atlaskit/editor-core 185.12.1 → 185.12.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +6 -0
- package/dist/cjs/plugins/block-type/commands/block-type.js +79 -44
- package/dist/cjs/plugins/code-block/index.js +7 -3
- package/dist/cjs/plugins/expand/commands.js +6 -2
- package/dist/cjs/plugins/expand/index.js +5 -1
- package/dist/cjs/plugins/panel/index.js +81 -43
- package/dist/cjs/plugins/quick-insert/commands.js +2 -0
- package/dist/cjs/ui/ElementBrowser/InsertMenu.js +10 -0
- package/dist/cjs/version-wrapper.js +1 -1
- package/dist/cjs/version.json +1 -1
- package/dist/es2019/plugins/block-type/commands/block-type.js +86 -51
- package/dist/es2019/plugins/code-block/index.js +7 -2
- package/dist/es2019/plugins/expand/commands.js +6 -2
- package/dist/es2019/plugins/expand/index.js +5 -1
- package/dist/es2019/plugins/panel/index.js +82 -41
- package/dist/es2019/plugins/quick-insert/commands.js +2 -0
- package/dist/es2019/ui/ElementBrowser/InsertMenu.js +10 -0
- package/dist/es2019/version-wrapper.js +1 -1
- package/dist/es2019/version.json +1 -1
- package/dist/esm/plugins/block-type/commands/block-type.js +76 -43
- package/dist/esm/plugins/code-block/index.js +7 -2
- package/dist/esm/plugins/expand/commands.js +6 -2
- package/dist/esm/plugins/expand/index.js +5 -1
- package/dist/esm/plugins/panel/index.js +81 -43
- package/dist/esm/plugins/quick-insert/commands.js +2 -0
- package/dist/esm/ui/ElementBrowser/InsertMenu.js +10 -0
- package/dist/esm/version-wrapper.js +1 -1
- package/dist/esm/version.json +1 -1
- package/dist/types/plugins/block-type/commands/block-type.d.ts +25 -0
- package/dist/types-ts4.5/plugins/block-type/commands/block-type.d.ts +25 -0
- package/package.json +2 -2
|
@@ -9,6 +9,10 @@ import { ACTION, ACTION_SUBJECT, ACTION_SUBJECT_ID, INPUT_METHOD, EVENT_TYPE } f
|
|
|
9
9
|
import { IconCode } from '../quick-insert/assets';
|
|
10
10
|
import { messages } from '../block-type/messages';
|
|
11
11
|
import refreshBrowserSelectionOnChange from './refresh-browser-selection';
|
|
12
|
+
// Theres an existing interelationship between these files, where the imported function is being called for code-block
|
|
13
|
+
// Insertions via the drop down menu
|
|
14
|
+
// tslint-ignore-next-line
|
|
15
|
+
import { createInsertCodeBlockTransaction } from '../block-type/commands/block-type';
|
|
12
16
|
const codeBlockPlugin = (options, api) => ({
|
|
13
17
|
name: 'codeBlock',
|
|
14
18
|
nodes() {
|
|
@@ -58,8 +62,9 @@ const codeBlockPlugin = (options, api) => ({
|
|
|
58
62
|
icon: () => /*#__PURE__*/React.createElement(IconCode, null),
|
|
59
63
|
action(insert, state) {
|
|
60
64
|
var _api$dependencies$ana;
|
|
61
|
-
const
|
|
62
|
-
|
|
65
|
+
const tr = createInsertCodeBlockTransaction({
|
|
66
|
+
state
|
|
67
|
+
});
|
|
63
68
|
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.attachAnalyticsEvent({
|
|
64
69
|
action: ACTION.INSERTED,
|
|
65
70
|
actionSubject: ACTION_SUBJECT.DOCUMENT,
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { TextSelection } from 'prosemirror-state';
|
|
2
|
-
import { safeInsert } from 'prosemirror-utils';
|
|
3
2
|
import { findTable } from '@atlaskit/editor-tables/utils';
|
|
4
3
|
import { addAnalytics, ACTION, ACTION_SUBJECT, ACTION_SUBJECT_ID, INPUT_METHOD, EVENT_TYPE, PLATFORMS, MODE } from '../analytics';
|
|
5
4
|
import { GapCursorSelection, Side } from '../selection/gap-cursor-selection';
|
|
6
5
|
import { findExpand } from './utils';
|
|
7
6
|
import { createCommand } from './pm-plugins/plugin-factory';
|
|
7
|
+
import { createWrapSelectionTransaction } from '../block-type/commands/block-type';
|
|
8
8
|
export const setExpandRef = ref => createCommand({
|
|
9
9
|
type: 'SET_EXPAND_REF',
|
|
10
10
|
data: {
|
|
@@ -97,6 +97,10 @@ export const createExpandNode = state => {
|
|
|
97
97
|
};
|
|
98
98
|
export const insertExpand = (state, dispatch) => {
|
|
99
99
|
const expandNode = createExpandNode(state);
|
|
100
|
+
const tr = createWrapSelectionTransaction({
|
|
101
|
+
state,
|
|
102
|
+
type: state.schema.nodes.expand
|
|
103
|
+
});
|
|
100
104
|
const payload = {
|
|
101
105
|
action: ACTION.INSERTED,
|
|
102
106
|
actionSubject: ACTION_SUBJECT.DOCUMENT,
|
|
@@ -107,7 +111,7 @@ export const insertExpand = (state, dispatch) => {
|
|
|
107
111
|
eventType: EVENT_TYPE.TRACK
|
|
108
112
|
};
|
|
109
113
|
if (dispatch && expandNode) {
|
|
110
|
-
dispatch(addAnalytics(state,
|
|
114
|
+
dispatch(addAnalytics(state, tr, payload));
|
|
111
115
|
}
|
|
112
116
|
return true;
|
|
113
117
|
};
|
|
@@ -7,6 +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 '../block-type/commands/block-type';
|
|
10
11
|
const expandPlugin = (options = {}, api) => {
|
|
11
12
|
var _api$dependencies, _api$dependencies$fea;
|
|
12
13
|
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()) || {};
|
|
@@ -55,7 +56,10 @@ const expandPlugin = (options = {}, api) => {
|
|
|
55
56
|
if (!node) {
|
|
56
57
|
return false;
|
|
57
58
|
}
|
|
58
|
-
const tr =
|
|
59
|
+
const tr = createWrapSelectionTransaction({
|
|
60
|
+
state,
|
|
61
|
+
type: state.schema.nodes.expand
|
|
62
|
+
});
|
|
59
63
|
return addAnalytics(state, tr, {
|
|
60
64
|
action: ACTION.INSERTED,
|
|
61
65
|
actionSubject: ACTION_SUBJECT.DOCUMENT,
|
|
@@ -8,23 +8,10 @@ import { IconPanel, IconPanelNote, IconPanelSuccess, IconPanelWarning, IconPanel
|
|
|
8
8
|
import { messages } from '../block-type/messages';
|
|
9
9
|
import IconCustomPanel from '../quick-insert/assets/custom-panel';
|
|
10
10
|
import { T50 } from '@atlaskit/theme/colors';
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
action: ACTION.INSERTED,
|
|
16
|
-
actionSubject: ACTION_SUBJECT.DOCUMENT,
|
|
17
|
-
actionSubjectId: ACTION_SUBJECT_ID.PANEL,
|
|
18
|
-
attributes: {
|
|
19
|
-
inputMethod: INPUT_METHOD.QUICK_INSERT,
|
|
20
|
-
panelType: panelAttributes.panelType
|
|
21
|
-
},
|
|
22
|
-
eventType: EVENT_TYPE.TRACK
|
|
23
|
-
});
|
|
24
|
-
}
|
|
25
|
-
return tr;
|
|
26
|
-
};
|
|
27
|
-
const insertPanelType = (panelAttributes, state) => state.schema.nodes.panel.createChecked(panelAttributes, state.schema.nodes.paragraph.createChecked());
|
|
11
|
+
// Theres an existing interelationship between these files, where the imported function is being called for panel
|
|
12
|
+
// Insertions via the drop down menu
|
|
13
|
+
// tslint-ignore-next-line
|
|
14
|
+
import { createWrapSelectionTransaction } from '../block-type/commands/block-type';
|
|
28
15
|
const panelPlugin = (options = {}, api) => ({
|
|
29
16
|
name: 'panel',
|
|
30
17
|
nodes() {
|
|
@@ -58,9 +45,12 @@ const panelPlugin = (options = {}, api) => ({
|
|
|
58
45
|
priority: 800,
|
|
59
46
|
icon: () => /*#__PURE__*/React.createElement(IconPanel, null),
|
|
60
47
|
action(insert, state) {
|
|
61
|
-
return
|
|
62
|
-
|
|
63
|
-
|
|
48
|
+
return createPanelAction({
|
|
49
|
+
state,
|
|
50
|
+
attributes: {
|
|
51
|
+
panelType: PanelType.INFO
|
|
52
|
+
}
|
|
53
|
+
});
|
|
64
54
|
}
|
|
65
55
|
}, {
|
|
66
56
|
id: 'notepanel',
|
|
@@ -69,9 +59,12 @@ const panelPlugin = (options = {}, api) => ({
|
|
|
69
59
|
priority: 1000,
|
|
70
60
|
icon: () => /*#__PURE__*/React.createElement(IconPanelNote, null),
|
|
71
61
|
action(insert, state) {
|
|
72
|
-
return
|
|
73
|
-
|
|
74
|
-
|
|
62
|
+
return createPanelAction({
|
|
63
|
+
state,
|
|
64
|
+
attributes: {
|
|
65
|
+
panelType: PanelType.NOTE
|
|
66
|
+
}
|
|
67
|
+
});
|
|
75
68
|
}
|
|
76
69
|
}, {
|
|
77
70
|
id: 'successpanel',
|
|
@@ -81,9 +74,12 @@ const panelPlugin = (options = {}, api) => ({
|
|
|
81
74
|
priority: 1000,
|
|
82
75
|
icon: () => /*#__PURE__*/React.createElement(IconPanelSuccess, null),
|
|
83
76
|
action(insert, state) {
|
|
84
|
-
return
|
|
85
|
-
|
|
86
|
-
|
|
77
|
+
return createPanelAction({
|
|
78
|
+
state,
|
|
79
|
+
attributes: {
|
|
80
|
+
panelType: PanelType.SUCCESS
|
|
81
|
+
}
|
|
82
|
+
});
|
|
87
83
|
}
|
|
88
84
|
}, {
|
|
89
85
|
id: 'warningpanel',
|
|
@@ -92,9 +88,12 @@ const panelPlugin = (options = {}, api) => ({
|
|
|
92
88
|
priority: 1000,
|
|
93
89
|
icon: () => /*#__PURE__*/React.createElement(IconPanelWarning, null),
|
|
94
90
|
action(insert, state) {
|
|
95
|
-
return
|
|
96
|
-
|
|
97
|
-
|
|
91
|
+
return createPanelAction({
|
|
92
|
+
state,
|
|
93
|
+
attributes: {
|
|
94
|
+
panelType: PanelType.WARNING
|
|
95
|
+
}
|
|
96
|
+
});
|
|
98
97
|
}
|
|
99
98
|
}, {
|
|
100
99
|
id: 'errorpanel',
|
|
@@ -103,9 +102,12 @@ const panelPlugin = (options = {}, api) => ({
|
|
|
103
102
|
priority: 1000,
|
|
104
103
|
icon: () => /*#__PURE__*/React.createElement(IconPanelError, null),
|
|
105
104
|
action(insert, state) {
|
|
106
|
-
return
|
|
107
|
-
|
|
108
|
-
|
|
105
|
+
return createPanelAction({
|
|
106
|
+
state,
|
|
107
|
+
attributes: {
|
|
108
|
+
panelType: PanelType.ERROR
|
|
109
|
+
}
|
|
110
|
+
});
|
|
109
111
|
}
|
|
110
112
|
}];
|
|
111
113
|
if (options.allowCustomPanel && options.allowCustomPanelEdit) {
|
|
@@ -116,15 +118,18 @@ const panelPlugin = (options = {}, api) => ({
|
|
|
116
118
|
priority: 1000,
|
|
117
119
|
icon: () => /*#__PURE__*/React.createElement(IconCustomPanel, null),
|
|
118
120
|
action(insert, state) {
|
|
119
|
-
return
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
121
|
+
return createPanelAction({
|
|
122
|
+
state,
|
|
123
|
+
attributes: {
|
|
124
|
+
panelType: PanelType.CUSTOM,
|
|
125
|
+
panelIcon: ':rainbow:',
|
|
126
|
+
panelIconId: '1f308',
|
|
127
|
+
panelIconText: '🌈',
|
|
128
|
+
// TODO: https://product-fabric.atlassian.net/browse/DSP-7268
|
|
129
|
+
// eslint-disable-next-line @atlaskit/design-system/ensure-design-token-usage
|
|
130
|
+
panelColor: T50
|
|
131
|
+
}
|
|
132
|
+
});
|
|
128
133
|
}
|
|
129
134
|
});
|
|
130
135
|
}
|
|
@@ -133,4 +138,40 @@ const panelPlugin = (options = {}, api) => ({
|
|
|
133
138
|
floatingToolbar: (state, intl, providerFactory) => getToolbarConfig(state, intl, options, providerFactory, api === null || api === void 0 ? void 0 : api.dependencies.decorations.actions.hoverDecoration)
|
|
134
139
|
}
|
|
135
140
|
});
|
|
141
|
+
|
|
142
|
+
/**
|
|
143
|
+
* Creates panel action and wrap selection transaction with analytics for the panel insertion.
|
|
144
|
+
*
|
|
145
|
+
* @example
|
|
146
|
+
* const tr = createPanelAction({
|
|
147
|
+
* state: editorState,
|
|
148
|
+
* attributes: { panelType: 'info' },
|
|
149
|
+
* });
|
|
150
|
+
* if (tr) {
|
|
151
|
+
* applyTransaction(tr);
|
|
152
|
+
* }
|
|
153
|
+
*/
|
|
154
|
+
function createPanelAction({
|
|
155
|
+
state,
|
|
156
|
+
attributes
|
|
157
|
+
}) {
|
|
158
|
+
const tr = createWrapSelectionTransaction({
|
|
159
|
+
state,
|
|
160
|
+
type: state.schema.nodes.panel,
|
|
161
|
+
nodeAttributes: attributes
|
|
162
|
+
});
|
|
163
|
+
if (tr) {
|
|
164
|
+
addAnalytics(state, tr, {
|
|
165
|
+
action: ACTION.INSERTED,
|
|
166
|
+
actionSubject: ACTION_SUBJECT.DOCUMENT,
|
|
167
|
+
actionSubjectId: ACTION_SUBJECT_ID.PANEL,
|
|
168
|
+
attributes: {
|
|
169
|
+
inputMethod: INPUT_METHOD.QUICK_INSERT,
|
|
170
|
+
panelType: attributes.panelType
|
|
171
|
+
},
|
|
172
|
+
eventType: EVENT_TYPE.TRACK
|
|
173
|
+
});
|
|
174
|
+
}
|
|
175
|
+
return tr;
|
|
176
|
+
}
|
|
136
177
|
export default panelPlugin;
|
|
@@ -25,6 +25,8 @@ export const insertItem = item => (state, dispatch) => {
|
|
|
25
25
|
return insertSelectedItem(maybeNode, opts)(state, state.tr, state.selection.head);
|
|
26
26
|
};
|
|
27
27
|
const tr = item.action(insert, state);
|
|
28
|
+
|
|
29
|
+
/** @note There is no transaction when called without a search currently (different insert) */
|
|
28
30
|
if (tr && dispatch) {
|
|
29
31
|
dispatch(tr);
|
|
30
32
|
}
|
|
@@ -30,6 +30,10 @@ const InsertMenu = ({
|
|
|
30
30
|
icon: () => getSvgIconForItem({
|
|
31
31
|
name: item.value.name
|
|
32
32
|
}) || item.elemBefore,
|
|
33
|
+
/**
|
|
34
|
+
* @note This transformed items action is only used when a quick insert item has been
|
|
35
|
+
* called from the quick insert menu and a search has not been performed.
|
|
36
|
+
*/
|
|
33
37
|
action: () => onInsert({
|
|
34
38
|
item
|
|
35
39
|
}),
|
|
@@ -48,6 +52,12 @@ const InsertMenu = ({
|
|
|
48
52
|
}, [editorView, toggleVisiblity]);
|
|
49
53
|
const getItems = useCallback(quickInsertState => (query, category) => {
|
|
50
54
|
let result;
|
|
55
|
+
/**
|
|
56
|
+
* @warning The results if there is a query are not the same as the results if there is no query.
|
|
57
|
+
* For example: If you have a typed panel and then select the panel item then it will call a different action
|
|
58
|
+
* than is specified on the editor plugins quick insert
|
|
59
|
+
* @see above transform function for more details.
|
|
60
|
+
*/
|
|
51
61
|
if (query) {
|
|
52
62
|
result = searchQuickInsertItems(quickInsertState, {})(query, category);
|
|
53
63
|
} else {
|
package/dist/es2019/version.json
CHANGED
|
@@ -210,6 +210,40 @@ export var insertBlockTypesWithAnalytics = function insertBlockTypesWithAnalytic
|
|
|
210
210
|
}
|
|
211
211
|
};
|
|
212
212
|
|
|
213
|
+
/**
|
|
214
|
+
* This function creates a new transaction that wraps the current selection
|
|
215
|
+
* in the specified node type if it results in a valid transaction.
|
|
216
|
+
* If not valid, it performs a safe insert operation.
|
|
217
|
+
*
|
|
218
|
+
* Example of when wrapping might not be valid is when attempting to wrap
|
|
219
|
+
* content that is already inside a panel with another panel
|
|
220
|
+
*/
|
|
221
|
+
export function createWrapSelectionTransaction(_ref3) {
|
|
222
|
+
var state = _ref3.state,
|
|
223
|
+
type = _ref3.type,
|
|
224
|
+
nodeAttributes = _ref3.nodeAttributes;
|
|
225
|
+
var tr = state.tr;
|
|
226
|
+
var _state$selection = state.selection,
|
|
227
|
+
$from = _state$selection.$from,
|
|
228
|
+
$to = _state$selection.$to;
|
|
229
|
+
var _state$schema$marks = state.schema.marks,
|
|
230
|
+
alignment = _state$schema$marks.alignment,
|
|
231
|
+
indentation = _state$schema$marks.indentation;
|
|
232
|
+
|
|
233
|
+
/** Alignment or Indentation is not valid inside block types */
|
|
234
|
+
var removeAlignTr = removeBlockMarks(state, [alignment, indentation]);
|
|
235
|
+
tr = removeAlignTr || tr;
|
|
236
|
+
var range = $from.blockRange($to);
|
|
237
|
+
var wrapping = range && findWrapping(range, type, nodeAttributes);
|
|
238
|
+
if (range && wrapping) {
|
|
239
|
+
tr.wrap(range, wrapping).scrollIntoView();
|
|
240
|
+
} else {
|
|
241
|
+
/** We always want to append a block type */
|
|
242
|
+
safeInsert(type.createAndFill())(tr).scrollIntoView();
|
|
243
|
+
}
|
|
244
|
+
return tr;
|
|
245
|
+
}
|
|
246
|
+
|
|
213
247
|
/**
|
|
214
248
|
* Function will add wrapping node.
|
|
215
249
|
* 1. If currently selected blocks can be wrapped in the wrapper type it will wrap them.
|
|
@@ -218,25 +252,10 @@ export var insertBlockTypesWithAnalytics = function insertBlockTypesWithAnalytic
|
|
|
218
252
|
*/
|
|
219
253
|
function wrapSelectionIn(type) {
|
|
220
254
|
return function (state, dispatch) {
|
|
221
|
-
var tr =
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
var _state$schema$marks = state.schema.marks,
|
|
226
|
-
alignment = _state$schema$marks.alignment,
|
|
227
|
-
indentation = _state$schema$marks.indentation;
|
|
228
|
-
|
|
229
|
-
/** Alignment or Indentation is not valid inside block types */
|
|
230
|
-
var removeAlignTr = removeBlockMarks(state, [alignment, indentation]);
|
|
231
|
-
tr = removeAlignTr || tr;
|
|
232
|
-
var range = $from.blockRange($to);
|
|
233
|
-
var wrapping = range && findWrapping(range, type);
|
|
234
|
-
if (range && wrapping) {
|
|
235
|
-
tr.wrap(range, wrapping).scrollIntoView();
|
|
236
|
-
} else {
|
|
237
|
-
/** We always want to append a block type */
|
|
238
|
-
safeInsert(type.createAndFill())(tr).scrollIntoView();
|
|
239
|
-
}
|
|
255
|
+
var tr = createWrapSelectionTransaction({
|
|
256
|
+
state: state,
|
|
257
|
+
type: type
|
|
258
|
+
});
|
|
240
259
|
if (dispatch) {
|
|
241
260
|
dispatch(tr);
|
|
242
261
|
}
|
|
@@ -244,39 +263,53 @@ function wrapSelectionIn(type) {
|
|
|
244
263
|
};
|
|
245
264
|
}
|
|
246
265
|
|
|
266
|
+
/**
|
|
267
|
+
* This function creates a new transaction that inserts a code block,
|
|
268
|
+
* if there is text selected it will wrap the current selection if not it will
|
|
269
|
+
* append the codeblock to the end of the document.
|
|
270
|
+
*/
|
|
271
|
+
export function createInsertCodeBlockTransaction(_ref4) {
|
|
272
|
+
var _state$selection$$fro;
|
|
273
|
+
var state = _ref4.state;
|
|
274
|
+
var tr = state.tr;
|
|
275
|
+
var from = state.selection.from;
|
|
276
|
+
var codeBlock = state.schema.nodes.codeBlock;
|
|
277
|
+
var grandParentNodeType = (_state$selection$$fro = state.selection.$from.node(-1)) === null || _state$selection$$fro === void 0 ? void 0 : _state$selection$$fro.type;
|
|
278
|
+
var parentNodeType = state.selection.$from.parent.type;
|
|
279
|
+
|
|
280
|
+
/** We always want to append a codeBlock unless we're inserting into a paragraph
|
|
281
|
+
* AND it's a valid child of the grandparent node.
|
|
282
|
+
* Insert the current selection as codeBlock content unless it contains nodes other
|
|
283
|
+
* than paragraphs and inline.
|
|
284
|
+
*/
|
|
285
|
+
var canInsertCodeBlock = shouldSplitSelectedNodeOnNodeInsertion({
|
|
286
|
+
parentNodeType: parentNodeType,
|
|
287
|
+
grandParentNodeType: grandParentNodeType,
|
|
288
|
+
content: codeBlock.createAndFill()
|
|
289
|
+
}) && contentAllowedInCodeBlock(state);
|
|
290
|
+
if (canInsertCodeBlock) {
|
|
291
|
+
tr = transformToCodeBlockAction(state, from);
|
|
292
|
+
} else {
|
|
293
|
+
safeInsert(codeBlock.createAndFill())(tr).scrollIntoView();
|
|
294
|
+
}
|
|
295
|
+
return tr;
|
|
296
|
+
}
|
|
297
|
+
|
|
247
298
|
/**
|
|
248
299
|
* Function will insert code block at current selection if block is empty or below current selection and set focus on it.
|
|
249
300
|
*/
|
|
250
301
|
function insertCodeBlock() {
|
|
251
302
|
return function (state, dispatch) {
|
|
252
|
-
var
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
var codeBlock = state.schema.nodes.codeBlock;
|
|
256
|
-
var grandParentNodeType = (_state$selection$$fro = state.selection.$from.node(-1)) === null || _state$selection$$fro === void 0 ? void 0 : _state$selection$$fro.type;
|
|
257
|
-
var parentNodeType = state.selection.$from.parent.type;
|
|
258
|
-
|
|
259
|
-
/** We always want to append a codeBlock unless we're inserting into a paragraph
|
|
260
|
-
* AND it's a valid child of the grandparent node.
|
|
261
|
-
* Insert the current selection as codeBlock content unless it contains nodes other
|
|
262
|
-
* than paragraphs and inline.
|
|
263
|
-
*/
|
|
264
|
-
var canInsertCodeBlock = shouldSplitSelectedNodeOnNodeInsertion({
|
|
265
|
-
parentNodeType: parentNodeType,
|
|
266
|
-
grandParentNodeType: grandParentNodeType,
|
|
267
|
-
content: codeBlock.createAndFill()
|
|
268
|
-
}) && contentAllowedInCodeBlock(state);
|
|
269
|
-
if (canInsertCodeBlock) {
|
|
270
|
-
tr = transformToCodeBlockAction(state, from);
|
|
271
|
-
} else {
|
|
272
|
-
safeInsert(codeBlock.createAndFill())(tr).scrollIntoView();
|
|
273
|
-
}
|
|
303
|
+
var tr = createInsertCodeBlockTransaction({
|
|
304
|
+
state: state
|
|
305
|
+
});
|
|
274
306
|
if (dispatch) {
|
|
275
307
|
dispatch(tr);
|
|
276
308
|
}
|
|
277
309
|
return true;
|
|
278
310
|
};
|
|
279
311
|
}
|
|
312
|
+
|
|
280
313
|
/**
|
|
281
314
|
* Check if the current selection contains any nodes that are not permitted
|
|
282
315
|
* as codeBlock child nodes. Note that this allows paragraphs and inline nodes
|
|
@@ -296,8 +329,8 @@ function contentAllowedInCodeBlock(state) {
|
|
|
296
329
|
return isAllowedChild;
|
|
297
330
|
}
|
|
298
331
|
export var cleanUpAtTheStartOfDocument = function cleanUpAtTheStartOfDocument(state, dispatch) {
|
|
299
|
-
var
|
|
300
|
-
$cursor =
|
|
332
|
+
var _ref5 = state.selection,
|
|
333
|
+
$cursor = _ref5.$cursor;
|
|
301
334
|
if ($cursor && !$cursor.nodeBefore && !$cursor.nodeAfter && $cursor.pos === 1) {
|
|
302
335
|
var tr = state.tr,
|
|
303
336
|
schema = state.schema;
|
|
@@ -12,6 +12,10 @@ import { ACTION, ACTION_SUBJECT, ACTION_SUBJECT_ID, INPUT_METHOD, EVENT_TYPE } f
|
|
|
12
12
|
import { IconCode } from '../quick-insert/assets';
|
|
13
13
|
import { messages } from '../block-type/messages';
|
|
14
14
|
import refreshBrowserSelectionOnChange from './refresh-browser-selection';
|
|
15
|
+
// Theres an existing interelationship between these files, where the imported function is being called for code-block
|
|
16
|
+
// Insertions via the drop down menu
|
|
17
|
+
// tslint-ignore-next-line
|
|
18
|
+
import { createInsertCodeBlockTransaction } from '../block-type/commands/block-type';
|
|
15
19
|
var codeBlockPlugin = function codeBlockPlugin(options, api) {
|
|
16
20
|
return {
|
|
17
21
|
name: 'codeBlock',
|
|
@@ -69,8 +73,9 @@ var codeBlockPlugin = function codeBlockPlugin(options, api) {
|
|
|
69
73
|
},
|
|
70
74
|
action: function action(insert, state) {
|
|
71
75
|
var _api$dependencies$ana;
|
|
72
|
-
var
|
|
73
|
-
|
|
76
|
+
var tr = createInsertCodeBlockTransaction({
|
|
77
|
+
state: state
|
|
78
|
+
});
|
|
74
79
|
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.attachAnalyticsEvent({
|
|
75
80
|
action: ACTION.INSERTED,
|
|
76
81
|
actionSubject: ACTION_SUBJECT.DOCUMENT,
|
|
@@ -2,12 +2,12 @@ import _defineProperty from "@babel/runtime/helpers/defineProperty";
|
|
|
2
2
|
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
|
3
3
|
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
|
|
4
4
|
import { TextSelection } from 'prosemirror-state';
|
|
5
|
-
import { safeInsert } from 'prosemirror-utils';
|
|
6
5
|
import { findTable } from '@atlaskit/editor-tables/utils';
|
|
7
6
|
import { addAnalytics, ACTION, ACTION_SUBJECT, ACTION_SUBJECT_ID, INPUT_METHOD, EVENT_TYPE, PLATFORMS, MODE } from '../analytics';
|
|
8
7
|
import { GapCursorSelection, Side } from '../selection/gap-cursor-selection';
|
|
9
8
|
import { findExpand } from './utils';
|
|
10
9
|
import { createCommand } from './pm-plugins/plugin-factory';
|
|
10
|
+
import { createWrapSelectionTransaction } from '../block-type/commands/block-type';
|
|
11
11
|
export var setExpandRef = function setExpandRef(ref) {
|
|
12
12
|
return createCommand({
|
|
13
13
|
type: 'SET_EXPAND_REF',
|
|
@@ -105,6 +105,10 @@ export var createExpandNode = function createExpandNode(state) {
|
|
|
105
105
|
};
|
|
106
106
|
export var insertExpand = function insertExpand(state, dispatch) {
|
|
107
107
|
var expandNode = createExpandNode(state);
|
|
108
|
+
var tr = createWrapSelectionTransaction({
|
|
109
|
+
state: state,
|
|
110
|
+
type: state.schema.nodes.expand
|
|
111
|
+
});
|
|
108
112
|
var payload = {
|
|
109
113
|
action: ACTION.INSERTED,
|
|
110
114
|
actionSubject: ACTION_SUBJECT.DOCUMENT,
|
|
@@ -115,7 +119,7 @@ export var insertExpand = function insertExpand(state, dispatch) {
|
|
|
115
119
|
eventType: EVENT_TYPE.TRACK
|
|
116
120
|
};
|
|
117
121
|
if (dispatch && expandNode) {
|
|
118
|
-
dispatch(addAnalytics(state,
|
|
122
|
+
dispatch(addAnalytics(state, tr, payload));
|
|
119
123
|
}
|
|
120
124
|
return true;
|
|
121
125
|
};
|
|
@@ -8,6 +8,7 @@ import { ACTION, ACTION_SUBJECT, ACTION_SUBJECT_ID, addAnalytics, EVENT_TYPE, IN
|
|
|
8
8
|
import { getToolbarConfig } from './toolbar';
|
|
9
9
|
import { createExpandNode } from './commands';
|
|
10
10
|
import { messages } from '../insert-block/ui/ToolbarInsertBlock/messages';
|
|
11
|
+
import { createWrapSelectionTransaction } from '../block-type/commands/block-type';
|
|
11
12
|
var expandPlugin = function expandPlugin() {
|
|
12
13
|
var _api$dependencies, _api$dependencies$fea;
|
|
13
14
|
var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
@@ -58,7 +59,10 @@ var expandPlugin = function expandPlugin() {
|
|
|
58
59
|
if (!node) {
|
|
59
60
|
return false;
|
|
60
61
|
}
|
|
61
|
-
var tr =
|
|
62
|
+
var tr = createWrapSelectionTransaction({
|
|
63
|
+
state: state,
|
|
64
|
+
type: state.schema.nodes.expand
|
|
65
|
+
});
|
|
62
66
|
return addAnalytics(state, tr, {
|
|
63
67
|
action: ACTION.INSERTED,
|
|
64
68
|
actionSubject: ACTION_SUBJECT.DOCUMENT,
|