@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.
Files changed (31) hide show
  1. package/CHANGELOG.md +6 -0
  2. package/dist/cjs/plugins/block-type/commands/block-type.js +79 -44
  3. package/dist/cjs/plugins/code-block/index.js +7 -3
  4. package/dist/cjs/plugins/expand/commands.js +6 -2
  5. package/dist/cjs/plugins/expand/index.js +5 -1
  6. package/dist/cjs/plugins/panel/index.js +81 -43
  7. package/dist/cjs/plugins/quick-insert/commands.js +2 -0
  8. package/dist/cjs/ui/ElementBrowser/InsertMenu.js +10 -0
  9. package/dist/cjs/version-wrapper.js +1 -1
  10. package/dist/cjs/version.json +1 -1
  11. package/dist/es2019/plugins/block-type/commands/block-type.js +86 -51
  12. package/dist/es2019/plugins/code-block/index.js +7 -2
  13. package/dist/es2019/plugins/expand/commands.js +6 -2
  14. package/dist/es2019/plugins/expand/index.js +5 -1
  15. package/dist/es2019/plugins/panel/index.js +82 -41
  16. package/dist/es2019/plugins/quick-insert/commands.js +2 -0
  17. package/dist/es2019/ui/ElementBrowser/InsertMenu.js +10 -0
  18. package/dist/es2019/version-wrapper.js +1 -1
  19. package/dist/es2019/version.json +1 -1
  20. package/dist/esm/plugins/block-type/commands/block-type.js +76 -43
  21. package/dist/esm/plugins/code-block/index.js +7 -2
  22. package/dist/esm/plugins/expand/commands.js +6 -2
  23. package/dist/esm/plugins/expand/index.js +5 -1
  24. package/dist/esm/plugins/panel/index.js +81 -43
  25. package/dist/esm/plugins/quick-insert/commands.js +2 -0
  26. package/dist/esm/ui/ElementBrowser/InsertMenu.js +10 -0
  27. package/dist/esm/version-wrapper.js +1 -1
  28. package/dist/esm/version.json +1 -1
  29. package/dist/types/plugins/block-type/commands/block-type.d.ts +25 -0
  30. package/dist/types-ts4.5/plugins/block-type/commands/block-type.d.ts +25 -0
  31. package/package.json +2 -2
package/CHANGELOG.md CHANGED
@@ -1,5 +1,11 @@
1
1
  # @atlaskit/editor-core
2
2
 
3
+ ## 185.12.2
4
+
5
+ ### Patch Changes
6
+
7
+ - [`a20c7920f82`](https://bitbucket.org/atlassian/atlassian-frontend/commits/a20c7920f82) - [ux] ED-15477 Update insertion behaviour for expands, code blocks and panels to make them consistent
8
+
3
9
  ## 185.12.1
4
10
 
5
11
  ### Patch Changes
@@ -4,6 +4,8 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.cleanUpAtTheStartOfDocument = void 0;
7
+ exports.createInsertCodeBlockTransaction = createInsertCodeBlockTransaction;
8
+ exports.createWrapSelectionTransaction = createWrapSelectionTransaction;
7
9
  exports.insertBlockType = insertBlockType;
8
10
  exports.insertBlockTypesWithAnalytics = void 0;
9
11
  exports.setBlockType = setBlockType;
@@ -225,34 +227,53 @@ var insertBlockTypesWithAnalytics = function insertBlockTypesWithAnalytics(name,
225
227
  }
226
228
  };
227
229
 
230
+ /**
231
+ * This function creates a new transaction that wraps the current selection
232
+ * in the specified node type if it results in a valid transaction.
233
+ * If not valid, it performs a safe insert operation.
234
+ *
235
+ * Example of when wrapping might not be valid is when attempting to wrap
236
+ * content that is already inside a panel with another panel
237
+ */
238
+ exports.insertBlockTypesWithAnalytics = insertBlockTypesWithAnalytics;
239
+ function createWrapSelectionTransaction(_ref3) {
240
+ var state = _ref3.state,
241
+ type = _ref3.type,
242
+ nodeAttributes = _ref3.nodeAttributes;
243
+ var tr = state.tr;
244
+ var _state$selection = state.selection,
245
+ $from = _state$selection.$from,
246
+ $to = _state$selection.$to;
247
+ var _state$schema$marks = state.schema.marks,
248
+ alignment = _state$schema$marks.alignment,
249
+ indentation = _state$schema$marks.indentation;
250
+
251
+ /** Alignment or Indentation is not valid inside block types */
252
+ var removeAlignTr = (0, _mark.removeBlockMarks)(state, [alignment, indentation]);
253
+ tr = removeAlignTr || tr;
254
+ var range = $from.blockRange($to);
255
+ var wrapping = range && (0, _prosemirrorTransform.findWrapping)(range, type, nodeAttributes);
256
+ if (range && wrapping) {
257
+ tr.wrap(range, wrapping).scrollIntoView();
258
+ } else {
259
+ /** We always want to append a block type */
260
+ (0, _prosemirrorUtils.safeInsert)(type.createAndFill())(tr).scrollIntoView();
261
+ }
262
+ return tr;
263
+ }
264
+
228
265
  /**
229
266
  * Function will add wrapping node.
230
267
  * 1. If currently selected blocks can be wrapped in the wrapper type it will wrap them.
231
268
  * 2. If current block can not be wrapped inside wrapping block it will create a new block below selection,
232
269
  * and set selection on it.
233
270
  */
234
- exports.insertBlockTypesWithAnalytics = insertBlockTypesWithAnalytics;
235
271
  function wrapSelectionIn(type) {
236
272
  return function (state, dispatch) {
237
- var tr = state.tr;
238
- var _state$selection = state.selection,
239
- $from = _state$selection.$from,
240
- $to = _state$selection.$to;
241
- var _state$schema$marks = state.schema.marks,
242
- alignment = _state$schema$marks.alignment,
243
- indentation = _state$schema$marks.indentation;
244
-
245
- /** Alignment or Indentation is not valid inside block types */
246
- var removeAlignTr = (0, _mark.removeBlockMarks)(state, [alignment, indentation]);
247
- tr = removeAlignTr || tr;
248
- var range = $from.blockRange($to);
249
- var wrapping = range && (0, _prosemirrorTransform.findWrapping)(range, type);
250
- if (range && wrapping) {
251
- tr.wrap(range, wrapping).scrollIntoView();
252
- } else {
253
- /** We always want to append a block type */
254
- (0, _prosemirrorUtils.safeInsert)(type.createAndFill())(tr).scrollIntoView();
255
- }
273
+ var tr = createWrapSelectionTransaction({
274
+ state: state,
275
+ type: type
276
+ });
256
277
  if (dispatch) {
257
278
  dispatch(tr);
258
279
  }
@@ -260,39 +281,53 @@ function wrapSelectionIn(type) {
260
281
  };
261
282
  }
262
283
 
284
+ /**
285
+ * This function creates a new transaction that inserts a code block,
286
+ * if there is text selected it will wrap the current selection if not it will
287
+ * append the codeblock to the end of the document.
288
+ */
289
+ function createInsertCodeBlockTransaction(_ref4) {
290
+ var _state$selection$$fro;
291
+ var state = _ref4.state;
292
+ var tr = state.tr;
293
+ var from = state.selection.from;
294
+ var codeBlock = state.schema.nodes.codeBlock;
295
+ var grandParentNodeType = (_state$selection$$fro = state.selection.$from.node(-1)) === null || _state$selection$$fro === void 0 ? void 0 : _state$selection$$fro.type;
296
+ var parentNodeType = state.selection.$from.parent.type;
297
+
298
+ /** We always want to append a codeBlock unless we're inserting into a paragraph
299
+ * AND it's a valid child of the grandparent node.
300
+ * Insert the current selection as codeBlock content unless it contains nodes other
301
+ * than paragraphs and inline.
302
+ */
303
+ var canInsertCodeBlock = (0, _insert.shouldSplitSelectedNodeOnNodeInsertion)({
304
+ parentNodeType: parentNodeType,
305
+ grandParentNodeType: grandParentNodeType,
306
+ content: codeBlock.createAndFill()
307
+ }) && contentAllowedInCodeBlock(state);
308
+ if (canInsertCodeBlock) {
309
+ tr = (0, _transformToCodeBlock.transformToCodeBlockAction)(state, from);
310
+ } else {
311
+ (0, _prosemirrorUtils.safeInsert)(codeBlock.createAndFill())(tr).scrollIntoView();
312
+ }
313
+ return tr;
314
+ }
315
+
263
316
  /**
264
317
  * Function will insert code block at current selection if block is empty or below current selection and set focus on it.
265
318
  */
266
319
  function insertCodeBlock() {
267
320
  return function (state, dispatch) {
268
- var _state$selection$$fro;
269
- var tr = state.tr;
270
- var from = state.selection.from;
271
- var codeBlock = state.schema.nodes.codeBlock;
272
- var grandParentNodeType = (_state$selection$$fro = state.selection.$from.node(-1)) === null || _state$selection$$fro === void 0 ? void 0 : _state$selection$$fro.type;
273
- var parentNodeType = state.selection.$from.parent.type;
274
-
275
- /** We always want to append a codeBlock unless we're inserting into a paragraph
276
- * AND it's a valid child of the grandparent node.
277
- * Insert the current selection as codeBlock content unless it contains nodes other
278
- * than paragraphs and inline.
279
- */
280
- var canInsertCodeBlock = (0, _insert.shouldSplitSelectedNodeOnNodeInsertion)({
281
- parentNodeType: parentNodeType,
282
- grandParentNodeType: grandParentNodeType,
283
- content: codeBlock.createAndFill()
284
- }) && contentAllowedInCodeBlock(state);
285
- if (canInsertCodeBlock) {
286
- tr = (0, _transformToCodeBlock.transformToCodeBlockAction)(state, from);
287
- } else {
288
- (0, _prosemirrorUtils.safeInsert)(codeBlock.createAndFill())(tr).scrollIntoView();
289
- }
321
+ var tr = createInsertCodeBlockTransaction({
322
+ state: state
323
+ });
290
324
  if (dispatch) {
291
325
  dispatch(tr);
292
326
  }
293
327
  return true;
294
328
  };
295
329
  }
330
+
296
331
  /**
297
332
  * Check if the current selection contains any nodes that are not permitted
298
333
  * as codeBlock child nodes. Note that this allows paragraphs and inline nodes
@@ -312,8 +347,8 @@ function contentAllowedInCodeBlock(state) {
312
347
  return isAllowedChild;
313
348
  }
314
349
  var cleanUpAtTheStartOfDocument = function cleanUpAtTheStartOfDocument(state, dispatch) {
315
- var _ref3 = state.selection,
316
- $cursor = _ref3.$cursor;
350
+ var _ref5 = state.selection,
351
+ $cursor = _ref5.$cursor;
317
352
  if ($cursor && !$cursor.nodeBefore && !$cursor.nodeAfter && $cursor.pos === 1) {
318
353
  var tr = state.tr,
319
354
  schema = state.schema;
@@ -17,8 +17,11 @@ var _analytics = require("@atlaskit/editor-common/analytics");
17
17
  var _assets = require("../quick-insert/assets");
18
18
  var _messages = require("../block-type/messages");
19
19
  var _refreshBrowserSelection = _interopRequireDefault(require("./refresh-browser-selection"));
20
+ var _blockType = require("../block-type/commands/block-type");
20
21
  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; }
21
- 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) { (0, _defineProperty2.default)(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; }
22
+ 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) { (0, _defineProperty2.default)(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; } // Theres an existing interelationship between these files, where the imported function is being called for code-block
23
+ // Insertions via the drop down menu
24
+ // tslint-ignore-next-line
22
25
  var codeBlockPlugin = function codeBlockPlugin(options, api) {
23
26
  return {
24
27
  name: 'codeBlock',
@@ -76,8 +79,9 @@ var codeBlockPlugin = function codeBlockPlugin(options, api) {
76
79
  },
77
80
  action: function action(insert, state) {
78
81
  var _api$dependencies$ana;
79
- var schema = state.schema;
80
- var tr = insert(schema.nodes.codeBlock.createChecked());
82
+ var tr = (0, _blockType.createInsertCodeBlockTransaction)({
83
+ state: state
84
+ });
81
85
  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({
82
86
  action: _analytics.ACTION.INSERTED,
83
87
  actionSubject: _analytics.ACTION_SUBJECT.DOCUMENT,
@@ -7,12 +7,12 @@ Object.defineProperty(exports, "__esModule", {
7
7
  exports.updateExpandTitle = exports.toggleExpandExpanded = exports.setSelectionInsideExpand = exports.setExpandRef = exports.insertExpand = exports.focusTitle = exports.deleteExpandAtPos = exports.deleteExpand = exports.createExpandNode = void 0;
8
8
  var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
9
9
  var _prosemirrorState = require("prosemirror-state");
10
- var _prosemirrorUtils = require("prosemirror-utils");
11
10
  var _utils = require("@atlaskit/editor-tables/utils");
12
11
  var _analytics = require("../analytics");
13
12
  var _gapCursorSelection = require("../selection/gap-cursor-selection");
14
13
  var _utils2 = require("./utils");
15
14
  var _pluginFactory = require("./pm-plugins/plugin-factory");
15
+ var _blockType = require("../block-type/commands/block-type");
16
16
  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; }
17
17
  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) { (0, _defineProperty2.default)(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; }
18
18
  var setExpandRef = function setExpandRef(ref) {
@@ -118,6 +118,10 @@ var createExpandNode = function createExpandNode(state) {
118
118
  exports.createExpandNode = createExpandNode;
119
119
  var insertExpand = function insertExpand(state, dispatch) {
120
120
  var expandNode = createExpandNode(state);
121
+ var tr = (0, _blockType.createWrapSelectionTransaction)({
122
+ state: state,
123
+ type: state.schema.nodes.expand
124
+ });
121
125
  var payload = {
122
126
  action: _analytics.ACTION.INSERTED,
123
127
  actionSubject: _analytics.ACTION_SUBJECT.DOCUMENT,
@@ -128,7 +132,7 @@ var insertExpand = function insertExpand(state, dispatch) {
128
132
  eventType: _analytics.EVENT_TYPE.TRACK
129
133
  };
130
134
  if (dispatch && expandNode) {
131
- dispatch((0, _analytics.addAnalytics)(state, (0, _prosemirrorUtils.safeInsert)(expandNode)(state.tr).scrollIntoView(), payload));
135
+ dispatch((0, _analytics.addAnalytics)(state, tr, payload));
132
136
  }
133
137
  return true;
134
138
  };
@@ -22,6 +22,7 @@ var _analytics = require("../analytics");
22
22
  var _toolbar = require("./toolbar");
23
23
  var _commands = require("./commands");
24
24
  var _messages = require("../insert-block/ui/ToolbarInsertBlock/messages");
25
+ var _blockType = require("../block-type/commands/block-type");
25
26
  var _pluginFactory = require("./pm-plugins/plugin-factory");
26
27
  var expandPlugin = function expandPlugin() {
27
28
  var _api$dependencies, _api$dependencies$fea;
@@ -73,7 +74,10 @@ var expandPlugin = function expandPlugin() {
73
74
  if (!node) {
74
75
  return false;
75
76
  }
76
- var tr = insert(node);
77
+ var tr = (0, _blockType.createWrapSelectionTransaction)({
78
+ state: state,
79
+ type: state.schema.nodes.expand
80
+ });
77
81
  return (0, _analytics.addAnalytics)(state, tr, {
78
82
  action: _analytics.ACTION.INSERTED,
79
83
  actionSubject: _analytics.ACTION_SUBJECT.DOCUMENT,
@@ -15,25 +15,10 @@ var _assets = require("../quick-insert/assets");
15
15
  var _messages = require("../block-type/messages");
16
16
  var _customPanel = _interopRequireDefault(require("../quick-insert/assets/custom-panel"));
17
17
  var _colors = require("@atlaskit/theme/colors");
18
- var insertPanelTypeWithAnalytics = function insertPanelTypeWithAnalytics(panelAttributes, state, insert) {
19
- var tr = insert(insertPanelType(panelAttributes, state));
20
- if (tr) {
21
- (0, _analytics.addAnalytics)(state, tr, {
22
- action: _analytics.ACTION.INSERTED,
23
- actionSubject: _analytics.ACTION_SUBJECT.DOCUMENT,
24
- actionSubjectId: _analytics.ACTION_SUBJECT_ID.PANEL,
25
- attributes: {
26
- inputMethod: _analytics.INPUT_METHOD.QUICK_INSERT,
27
- panelType: panelAttributes.panelType
28
- },
29
- eventType: _analytics.EVENT_TYPE.TRACK
30
- });
31
- }
32
- return tr;
33
- };
34
- var insertPanelType = function insertPanelType(panelAttributes, state) {
35
- return state.schema.nodes.panel.createChecked(panelAttributes, state.schema.nodes.paragraph.createChecked());
36
- };
18
+ var _blockType = require("../block-type/commands/block-type");
19
+ // Theres an existing interelationship between these files, where the imported function is being called for panel
20
+ // Insertions via the drop down menu
21
+ // tslint-ignore-next-line
37
22
  var panelPlugin = function panelPlugin() {
38
23
  var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
39
24
  var api = arguments.length > 1 ? arguments[1] : undefined;
@@ -74,9 +59,12 @@ var panelPlugin = function panelPlugin() {
74
59
  return /*#__PURE__*/_react.default.createElement(_assets.IconPanel, null);
75
60
  },
76
61
  action: function action(insert, state) {
77
- return insertPanelTypeWithAnalytics({
78
- panelType: _adfSchema.PanelType.INFO
79
- }, state, insert);
62
+ return createPanelAction({
63
+ state: state,
64
+ attributes: {
65
+ panelType: _adfSchema.PanelType.INFO
66
+ }
67
+ });
80
68
  }
81
69
  }, {
82
70
  id: 'notepanel',
@@ -87,9 +75,12 @@ var panelPlugin = function panelPlugin() {
87
75
  return /*#__PURE__*/_react.default.createElement(_assets.IconPanelNote, null);
88
76
  },
89
77
  action: function action(insert, state) {
90
- return insertPanelTypeWithAnalytics({
91
- panelType: _adfSchema.PanelType.NOTE
92
- }, state, insert);
78
+ return createPanelAction({
79
+ state: state,
80
+ attributes: {
81
+ panelType: _adfSchema.PanelType.NOTE
82
+ }
83
+ });
93
84
  }
94
85
  }, {
95
86
  id: 'successpanel',
@@ -101,9 +92,12 @@ var panelPlugin = function panelPlugin() {
101
92
  return /*#__PURE__*/_react.default.createElement(_assets.IconPanelSuccess, null);
102
93
  },
103
94
  action: function action(insert, state) {
104
- return insertPanelTypeWithAnalytics({
105
- panelType: _adfSchema.PanelType.SUCCESS
106
- }, state, insert);
95
+ return createPanelAction({
96
+ state: state,
97
+ attributes: {
98
+ panelType: _adfSchema.PanelType.SUCCESS
99
+ }
100
+ });
107
101
  }
108
102
  }, {
109
103
  id: 'warningpanel',
@@ -114,9 +108,12 @@ var panelPlugin = function panelPlugin() {
114
108
  return /*#__PURE__*/_react.default.createElement(_assets.IconPanelWarning, null);
115
109
  },
116
110
  action: function action(insert, state) {
117
- return insertPanelTypeWithAnalytics({
118
- panelType: _adfSchema.PanelType.WARNING
119
- }, state, insert);
111
+ return createPanelAction({
112
+ state: state,
113
+ attributes: {
114
+ panelType: _adfSchema.PanelType.WARNING
115
+ }
116
+ });
120
117
  }
121
118
  }, {
122
119
  id: 'errorpanel',
@@ -127,9 +124,12 @@ var panelPlugin = function panelPlugin() {
127
124
  return /*#__PURE__*/_react.default.createElement(_assets.IconPanelError, null);
128
125
  },
129
126
  action: function action(insert, state) {
130
- return insertPanelTypeWithAnalytics({
131
- panelType: _adfSchema.PanelType.ERROR
132
- }, state, insert);
127
+ return createPanelAction({
128
+ state: state,
129
+ attributes: {
130
+ panelType: _adfSchema.PanelType.ERROR
131
+ }
132
+ });
133
133
  }
134
134
  }];
135
135
  if (options.allowCustomPanel && options.allowCustomPanelEdit) {
@@ -142,15 +142,18 @@ var panelPlugin = function panelPlugin() {
142
142
  return /*#__PURE__*/_react.default.createElement(_customPanel.default, null);
143
143
  },
144
144
  action: function action(insert, state) {
145
- return insertPanelTypeWithAnalytics({
146
- panelType: _adfSchema.PanelType.CUSTOM,
147
- panelIcon: ':rainbow:',
148
- panelIconId: '1f308',
149
- panelIconText: '🌈',
150
- // TODO: https://product-fabric.atlassian.net/browse/DSP-7268
151
- // eslint-disable-next-line @atlaskit/design-system/ensure-design-token-usage
152
- panelColor: _colors.T50
153
- }, state, insert);
145
+ return createPanelAction({
146
+ state: state,
147
+ attributes: {
148
+ panelType: _adfSchema.PanelType.CUSTOM,
149
+ panelIcon: ':rainbow:',
150
+ panelIconId: '1f308',
151
+ panelIconText: '🌈',
152
+ // TODO: https://product-fabric.atlassian.net/browse/DSP-7268
153
+ // eslint-disable-next-line @atlaskit/design-system/ensure-design-token-usage
154
+ panelColor: _colors.T50
155
+ }
156
+ });
154
157
  }
155
158
  });
156
159
  }
@@ -162,5 +165,40 @@ var panelPlugin = function panelPlugin() {
162
165
  }
163
166
  };
164
167
  };
168
+
169
+ /**
170
+ * Creates panel action and wrap selection transaction with analytics for the panel insertion.
171
+ *
172
+ * @example
173
+ * const tr = createPanelAction({
174
+ * state: editorState,
175
+ * attributes: { panelType: 'info' },
176
+ * });
177
+ * if (tr) {
178
+ * applyTransaction(tr);
179
+ * }
180
+ */
181
+ function createPanelAction(_ref3) {
182
+ var state = _ref3.state,
183
+ attributes = _ref3.attributes;
184
+ var tr = (0, _blockType.createWrapSelectionTransaction)({
185
+ state: state,
186
+ type: state.schema.nodes.panel,
187
+ nodeAttributes: attributes
188
+ });
189
+ if (tr) {
190
+ (0, _analytics.addAnalytics)(state, tr, {
191
+ action: _analytics.ACTION.INSERTED,
192
+ actionSubject: _analytics.ACTION_SUBJECT.DOCUMENT,
193
+ actionSubjectId: _analytics.ACTION_SUBJECT_ID.PANEL,
194
+ attributes: {
195
+ inputMethod: _analytics.INPUT_METHOD.QUICK_INSERT,
196
+ panelType: attributes.panelType
197
+ },
198
+ eventType: _analytics.EVENT_TYPE.TRACK
199
+ });
200
+ }
201
+ return tr;
202
+ }
165
203
  var _default = panelPlugin;
166
204
  exports.default = _default;
@@ -40,6 +40,8 @@ var insertItem = function insertItem(item) {
40
40
  return (0, _insert.insertSelectedItem)(maybeNode, opts)(state, state.tr, state.selection.head);
41
41
  };
42
42
  var tr = item.action(insert, state);
43
+
44
+ /** @note There is no transaction when called without a search currently (different insert) */
43
45
  if (tr && dispatch) {
44
46
  dispatch(tr);
45
47
  }
@@ -47,6 +47,10 @@ var InsertMenu = function InsertMenu(_ref) {
47
47
  name: item.value.name
48
48
  }) || item.elemBefore;
49
49
  },
50
+ /**
51
+ * @note This transformed items action is only used when a quick insert item has been
52
+ * called from the quick insert menu and a search has not been performed.
53
+ */
50
54
  action: function action() {
51
55
  return onInsert({
52
56
  item: item
@@ -69,6 +73,12 @@ var InsertMenu = function InsertMenu(_ref) {
69
73
  var getItems = (0, _react.useCallback)(function (quickInsertState) {
70
74
  return function (query, category) {
71
75
  var result;
76
+ /**
77
+ * @warning The results if there is a query are not the same as the results if there is no query.
78
+ * For example: If you have a typed panel and then select the panel item then it will call a different action
79
+ * than is specified on the editor plugins quick insert
80
+ * @see above transform function for more details.
81
+ */
72
82
  if (query) {
73
83
  result = (0, _search.searchQuickInsertItems)(quickInsertState, {})(query, category);
74
84
  } else {
@@ -6,7 +6,7 @@ Object.defineProperty(exports, "__esModule", {
6
6
  exports.version = exports.nextMajorVersion = exports.name = void 0;
7
7
  var name = "@atlaskit/editor-core";
8
8
  exports.name = name;
9
- var version = "185.12.1";
9
+ var version = "185.12.2";
10
10
  exports.version = version;
11
11
  var nextMajorVersion = function nextMajorVersion() {
12
12
  return [Number(version.split('.')[0]) + 1, 0, 0].join('.');
@@ -1,5 +1,5 @@
1
1
  {
2
2
  "name": "@atlaskit/editor-core",
3
- "version": "185.12.1",
3
+ "version": "185.12.2",
4
4
  "sideEffects": false
5
5
  }
@@ -207,6 +207,45 @@ export const insertBlockTypesWithAnalytics = (name, inputMethod, editorAnalytics
207
207
  }
208
208
  };
209
209
 
210
+ /**
211
+ * This function creates a new transaction that wraps the current selection
212
+ * in the specified node type if it results in a valid transaction.
213
+ * If not valid, it performs a safe insert operation.
214
+ *
215
+ * Example of when wrapping might not be valid is when attempting to wrap
216
+ * content that is already inside a panel with another panel
217
+ */
218
+ export function createWrapSelectionTransaction({
219
+ state,
220
+ type,
221
+ nodeAttributes
222
+ }) {
223
+ let {
224
+ tr
225
+ } = state;
226
+ const {
227
+ $from,
228
+ $to
229
+ } = state.selection;
230
+ const {
231
+ alignment,
232
+ indentation
233
+ } = state.schema.marks;
234
+
235
+ /** Alignment or Indentation is not valid inside block types */
236
+ const removeAlignTr = removeBlockMarks(state, [alignment, indentation]);
237
+ tr = removeAlignTr || tr;
238
+ const range = $from.blockRange($to);
239
+ const wrapping = range && findWrapping(range, type, nodeAttributes);
240
+ if (range && wrapping) {
241
+ tr.wrap(range, wrapping).scrollIntoView();
242
+ } else {
243
+ /** We always want to append a block type */
244
+ safeInsert(type.createAndFill())(tr).scrollIntoView();
245
+ }
246
+ return tr;
247
+ }
248
+
210
249
  /**
211
250
  * Function will add wrapping node.
212
251
  * 1. If currently selected blocks can be wrapped in the wrapper type it will wrap them.
@@ -215,29 +254,10 @@ export const insertBlockTypesWithAnalytics = (name, inputMethod, editorAnalytics
215
254
  */
216
255
  function wrapSelectionIn(type) {
217
256
  return function (state, dispatch) {
218
- let {
219
- tr
220
- } = state;
221
- const {
222
- $from,
223
- $to
224
- } = state.selection;
225
- const {
226
- alignment,
227
- indentation
228
- } = state.schema.marks;
229
-
230
- /** Alignment or Indentation is not valid inside block types */
231
- const removeAlignTr = removeBlockMarks(state, [alignment, indentation]);
232
- tr = removeAlignTr || tr;
233
- const range = $from.blockRange($to);
234
- const wrapping = range && findWrapping(range, type);
235
- if (range && wrapping) {
236
- tr.wrap(range, wrapping).scrollIntoView();
237
- } else {
238
- /** We always want to append a block type */
239
- safeInsert(type.createAndFill())(tr).scrollIntoView();
240
- }
257
+ let tr = createWrapSelectionTransaction({
258
+ state,
259
+ type
260
+ });
241
261
  if (dispatch) {
242
262
  dispatch(tr);
243
263
  }
@@ -245,45 +265,60 @@ function wrapSelectionIn(type) {
245
265
  };
246
266
  }
247
267
 
268
+ /**
269
+ * This function creates a new transaction that inserts a code block,
270
+ * if there is text selected it will wrap the current selection if not it will
271
+ * append the codeblock to the end of the document.
272
+ */
273
+ export function createInsertCodeBlockTransaction({
274
+ state
275
+ }) {
276
+ var _state$selection$$fro;
277
+ let {
278
+ tr
279
+ } = state;
280
+ const {
281
+ from
282
+ } = state.selection;
283
+ const {
284
+ codeBlock
285
+ } = state.schema.nodes;
286
+ const grandParentNodeType = (_state$selection$$fro = state.selection.$from.node(-1)) === null || _state$selection$$fro === void 0 ? void 0 : _state$selection$$fro.type;
287
+ const parentNodeType = state.selection.$from.parent.type;
288
+
289
+ /** We always want to append a codeBlock unless we're inserting into a paragraph
290
+ * AND it's a valid child of the grandparent node.
291
+ * Insert the current selection as codeBlock content unless it contains nodes other
292
+ * than paragraphs and inline.
293
+ */
294
+ const canInsertCodeBlock = shouldSplitSelectedNodeOnNodeInsertion({
295
+ parentNodeType,
296
+ grandParentNodeType,
297
+ content: codeBlock.createAndFill()
298
+ }) && contentAllowedInCodeBlock(state);
299
+ if (canInsertCodeBlock) {
300
+ tr = transformToCodeBlockAction(state, from);
301
+ } else {
302
+ safeInsert(codeBlock.createAndFill())(tr).scrollIntoView();
303
+ }
304
+ return tr;
305
+ }
306
+
248
307
  /**
249
308
  * Function will insert code block at current selection if block is empty or below current selection and set focus on it.
250
309
  */
251
310
  function insertCodeBlock() {
252
311
  return function (state, dispatch) {
253
- var _state$selection$$fro;
254
- let {
255
- tr
256
- } = state;
257
- const {
258
- from
259
- } = state.selection;
260
- const {
261
- codeBlock
262
- } = state.schema.nodes;
263
- const grandParentNodeType = (_state$selection$$fro = state.selection.$from.node(-1)) === null || _state$selection$$fro === void 0 ? void 0 : _state$selection$$fro.type;
264
- const parentNodeType = state.selection.$from.parent.type;
265
-
266
- /** We always want to append a codeBlock unless we're inserting into a paragraph
267
- * AND it's a valid child of the grandparent node.
268
- * Insert the current selection as codeBlock content unless it contains nodes other
269
- * than paragraphs and inline.
270
- */
271
- const canInsertCodeBlock = shouldSplitSelectedNodeOnNodeInsertion({
272
- parentNodeType,
273
- grandParentNodeType,
274
- content: codeBlock.createAndFill()
275
- }) && contentAllowedInCodeBlock(state);
276
- if (canInsertCodeBlock) {
277
- tr = transformToCodeBlockAction(state, from);
278
- } else {
279
- safeInsert(codeBlock.createAndFill())(tr).scrollIntoView();
280
- }
312
+ let tr = createInsertCodeBlockTransaction({
313
+ state
314
+ });
281
315
  if (dispatch) {
282
316
  dispatch(tr);
283
317
  }
284
318
  return true;
285
319
  };
286
320
  }
321
+
287
322
  /**
288
323
  * Check if the current selection contains any nodes that are not permitted
289
324
  * as codeBlock child nodes. Note that this allows paragraphs and inline nodes