@atlaskit/editor-plugin-panel 5.2.5 → 5.3.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 CHANGED
@@ -1,5 +1,16 @@
1
1
  # @atlaskit/editor-plugin-panel
2
2
 
3
+ ## 5.3.0
4
+
5
+ ### Minor Changes
6
+
7
+ - [`a0e6cdeb5a90c`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/a0e6cdeb5a90c) -
8
+ [ux] New experiment to unify the handling of panel insertion to more consistent behaviour.
9
+
10
+ ### Patch Changes
11
+
12
+ - Updated dependencies
13
+
3
14
  ## 5.2.5
4
15
 
5
16
  ### Patch Changes
@@ -109,6 +109,8 @@ var changePanelType = exports.changePanelType = function changePanelType(editorA
109
109
  };
110
110
  };
111
111
  };
112
+
113
+ // Delete with 'platform_editor_fix_quick_insert_consistency_exp'
112
114
  function insertPanelWithAnalytics(inputMethod, analyticsAPI) {
113
115
  return (0, _editorAnalytics.withAnalytics)(analyticsAPI, {
114
116
  action: _analytics.ACTION.INSERTED,
@@ -9,11 +9,13 @@ var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/de
9
9
  var _react = _interopRequireDefault(require("react"));
10
10
  var _adfSchema = require("@atlaskit/adf-schema");
11
11
  var _analytics = require("@atlaskit/editor-common/analytics");
12
+ var _insert = require("@atlaskit/editor-common/insert");
12
13
  var _messages = require("@atlaskit/editor-common/messages");
13
14
  var _quickInsert = require("@atlaskit/editor-common/quick-insert");
14
15
  var _utils = require("@atlaskit/editor-common/utils");
15
16
  var _platformFeatureFlags = require("@atlaskit/platform-feature-flags");
16
17
  var _colors = require("@atlaskit/theme/colors");
18
+ var _expValEquals = require("@atlaskit/tmp-editor-statsig/exp-val-equals");
17
19
  var _experiments = require("@atlaskit/tmp-editor-statsig/experiments");
18
20
  var _actions = require("./editor-actions/actions");
19
21
  var _keymaps = _interopRequireDefault(require("./pm-plugins/keymaps"));
@@ -57,8 +59,28 @@ var panelPlugin = function panelPlugin(_ref) {
57
59
  },
58
60
  actions: {
59
61
  insertPanel: function insertPanel(inputMethod) {
60
- var _api$analytics;
61
- return (0, _actions.insertPanelWithAnalytics)(inputMethod, api === null || api === void 0 || (_api$analytics = api.analytics) === null || _api$analytics === void 0 ? void 0 : _api$analytics.actions);
62
+ if ((0, _expValEquals.expValEquals)('platform_editor_fix_quick_insert_consistency_exp', 'isEnabled', true)) {
63
+ return function (state, dispatch) {
64
+ var tr = createPanelAction({
65
+ state: state,
66
+ attributes: {
67
+ panelType: _adfSchema.PanelType.INFO
68
+ },
69
+ api: api,
70
+ inputMethod: inputMethod
71
+ });
72
+ if (!tr) {
73
+ return false;
74
+ }
75
+ if (dispatch) {
76
+ dispatch(tr);
77
+ }
78
+ return true;
79
+ };
80
+ } else {
81
+ var _api$analytics;
82
+ return (0, _actions.insertPanelWithAnalytics)(inputMethod, api === null || api === void 0 || (_api$analytics = api.analytics) === null || _api$analytics === void 0 ? void 0 : _api$analytics.actions);
83
+ }
62
84
  }
63
85
  },
64
86
  pluginsOptions: {
@@ -74,14 +96,14 @@ var panelPlugin = function panelPlugin(_ref) {
74
96
  icon: function icon() {
75
97
  return /*#__PURE__*/_react.default.createElement(_quickInsert.IconPanel, null);
76
98
  },
77
- action: function action(insert, state) {
99
+ action: function action(typeAheadInsert, state) {
78
100
  return createPanelAction({
79
101
  state: state,
80
102
  attributes: {
81
103
  panelType: _adfSchema.PanelType.INFO
82
104
  },
83
105
  api: api,
84
- insert: insert
106
+ typeAheadInsert: typeAheadInsert
85
107
  });
86
108
  }
87
109
  }];
@@ -95,14 +117,14 @@ var panelPlugin = function panelPlugin(_ref) {
95
117
  icon: function icon() {
96
118
  return /*#__PURE__*/_react.default.createElement(_quickInsert.IconPanel, null);
97
119
  },
98
- action: function action(insert, state) {
120
+ action: function action(typeAheadInsert, state) {
99
121
  return createPanelAction({
100
122
  state: state,
101
123
  attributes: {
102
124
  panelType: _adfSchema.PanelType.INFO
103
125
  },
104
126
  api: api,
105
- insert: insert
127
+ typeAheadInsert: typeAheadInsert
106
128
  });
107
129
  }
108
130
  }, {
@@ -113,14 +135,14 @@ var panelPlugin = function panelPlugin(_ref) {
113
135
  icon: function icon() {
114
136
  return /*#__PURE__*/_react.default.createElement(_quickInsert.IconPanelNote, null);
115
137
  },
116
- action: function action(insert, state) {
138
+ action: function action(typeAheadInsert, state) {
117
139
  return createPanelAction({
118
140
  state: state,
119
141
  attributes: {
120
142
  panelType: _adfSchema.PanelType.NOTE
121
143
  },
122
144
  api: api,
123
- insert: insert
145
+ typeAheadInsert: typeAheadInsert
124
146
  });
125
147
  }
126
148
  }, {
@@ -132,14 +154,14 @@ var panelPlugin = function panelPlugin(_ref) {
132
154
  icon: function icon() {
133
155
  return /*#__PURE__*/_react.default.createElement(_quickInsert.IconPanelSuccess, null);
134
156
  },
135
- action: function action(insert, state) {
157
+ action: function action(typeAheadInsert, state) {
136
158
  return createPanelAction({
137
159
  state: state,
138
160
  attributes: {
139
161
  panelType: _adfSchema.PanelType.SUCCESS
140
162
  },
141
163
  api: api,
142
- insert: insert
164
+ typeAheadInsert: typeAheadInsert
143
165
  });
144
166
  }
145
167
  }, {
@@ -150,14 +172,14 @@ var panelPlugin = function panelPlugin(_ref) {
150
172
  icon: function icon() {
151
173
  return /*#__PURE__*/_react.default.createElement(_quickInsert.IconPanelWarning, null);
152
174
  },
153
- action: function action(insert, state) {
175
+ action: function action(typeAheadInsert, state) {
154
176
  return createPanelAction({
155
177
  state: state,
156
178
  attributes: {
157
179
  panelType: _adfSchema.PanelType.WARNING
158
180
  },
159
181
  api: api,
160
- insert: insert
182
+ typeAheadInsert: typeAheadInsert
161
183
  });
162
184
  }
163
185
  }, {
@@ -168,14 +190,14 @@ var panelPlugin = function panelPlugin(_ref) {
168
190
  icon: function icon() {
169
191
  return /*#__PURE__*/_react.default.createElement(_quickInsert.IconPanelError, null);
170
192
  },
171
- action: function action(insert, state) {
193
+ action: function action(typeAheadInsert, state) {
172
194
  return createPanelAction({
173
195
  state: state,
174
196
  attributes: {
175
197
  panelType: _adfSchema.PanelType.ERROR
176
198
  },
177
199
  api: api,
178
- insert: insert
200
+ typeAheadInsert: typeAheadInsert
179
201
  });
180
202
  }
181
203
  }];
@@ -188,7 +210,7 @@ var panelPlugin = function panelPlugin(_ref) {
188
210
  icon: function icon() {
189
211
  return /*#__PURE__*/_react.default.createElement(_quickInsert.IconCustomPanel, null);
190
212
  },
191
- action: function action(insert, state) {
213
+ action: function action(typeAheadInsert, state) {
192
214
  return createPanelAction({
193
215
  state: state,
194
216
  attributes: {
@@ -203,7 +225,7 @@ var panelPlugin = function panelPlugin(_ref) {
203
225
  panelColor: _colors.T50
204
226
  },
205
227
  api: api,
206
- insert: insert
228
+ typeAheadInsert: typeAheadInsert
207
229
  });
208
230
  }
209
231
  });
@@ -234,27 +256,60 @@ function createPanelAction(_ref4) {
234
256
  var state = _ref4.state,
235
257
  attributes = _ref4.attributes,
236
258
  api = _ref4.api,
237
- insert = _ref4.insert;
259
+ typeAheadInsert = _ref4.typeAheadInsert,
260
+ _ref4$inputMethod = _ref4.inputMethod,
261
+ inputMethod = _ref4$inputMethod === void 0 ? _analytics.INPUT_METHOD.QUICK_INSERT : _ref4$inputMethod;
238
262
  var panel = state.schema.nodes.panel;
239
263
  var tr;
240
264
  var panelAttrs = (0, _platformFeatureFlags.fg)('platform_editor_adf_with_localid') ? _objectSpread(_objectSpread({}, attributes), {}, {
241
265
  localId: attributes.localId || _adfSchema.uuid.generate()
242
266
  }) : _objectSpread({}, attributes);
243
267
 
244
- // Panels should wrap content by default when inserted, the quickInsert `insert` method
245
- // will insert the node on a newline
246
- if ((0, _experiments.editorExperiment)('platform_editor_controls', 'variant1')) {
247
- tr = state.selection.empty && (0, _utils.createWrapSelectionTransaction)({
248
- state: state,
249
- type: panel,
250
- nodeAttributes: panelAttrs
251
- });
268
+ /*
269
+ During investigation of go/j/ED-26928 I found that the behaviour of this experience was very
270
+ inconsistent. I reached out to Nicole* for a design review, and she confirmed that the desired
271
+ behaviour is to insert the panel on a new line if the selection is empty.
272
+ *Confluence Editor Lead Product Designer
273
+ */
274
+ if ((0, _expValEquals.expValEquals)('platform_editor_fix_quick_insert_consistency_exp', 'isEnabled', true)) {
275
+ // If the selection is empty, we want to insert the panel on a new line
276
+ if (state.selection.empty) {
277
+ var node = panel.createAndFill(panelAttrs);
278
+ if (!node) {
279
+ return false;
280
+ }
281
+ if (typeAheadInsert !== undefined) {
282
+ // If the type-ahead insert is provided, we should use that to insert the node
283
+ tr = typeAheadInsert(node);
284
+ } else {
285
+ var _insertSelectedItem;
286
+ // Otherwise we can use insertSelectedItem to insert the node
287
+ tr = (_insertSelectedItem = (0, _insert.insertSelectedItem)(node)(state, state.tr, state.selection.head)) === null || _insertSelectedItem === void 0 ? void 0 : _insertSelectedItem.scrollIntoView();
288
+ }
289
+ } else {
290
+ tr = (0, _utils.createWrapSelectionTransaction)({
291
+ state: state,
292
+ type: panel,
293
+ nodeAttributes: panelAttrs
294
+ });
295
+ }
252
296
  } else {
253
- var node = panel.createAndFill(panelAttrs);
254
- if (!node) {
255
- return false;
297
+ // Panels should wrap content by default when inserted, the quickInsert `insert` method
298
+ // will insert the node on a newline
299
+ if ((0, _experiments.editorExperiment)('platform_editor_controls', 'variant1')) {
300
+ tr = state.selection.empty && (0, _utils.createWrapSelectionTransaction)({
301
+ state: state,
302
+ type: panel,
303
+ nodeAttributes: panelAttrs
304
+ });
305
+ } else {
306
+ var _node = panel.createAndFill(panelAttrs);
307
+ if (!_node) {
308
+ return false;
309
+ }
310
+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion -- This is only optional within the experiment, so safe to assume non-null here
311
+ tr = state.selection.empty && typeAheadInsert(_node);
256
312
  }
257
- tr = state.selection.empty && insert(node);
258
313
  }
259
314
  if (tr) {
260
315
  var _api$analytics2;
@@ -263,12 +318,12 @@ function createPanelAction(_ref4) {
263
318
  actionSubject: _analytics.ACTION_SUBJECT.DOCUMENT,
264
319
  actionSubjectId: _analytics.ACTION_SUBJECT_ID.PANEL,
265
320
  attributes: {
266
- inputMethod: _analytics.INPUT_METHOD.QUICK_INSERT,
321
+ inputMethod: inputMethod,
267
322
  panelType: attributes.panelType
268
323
  },
269
324
  eventType: _analytics.EVENT_TYPE.TRACK
270
325
  })(tr);
271
326
  }
272
- return tr;
327
+ return tr !== null && tr !== void 0 ? tr : false;
273
328
  }
274
329
  var _default = exports.default = panelPlugin;
@@ -98,6 +98,8 @@ export const changePanelType = editorAnalyticsAPI => (panelType, panelOptions =
98
98
  }
99
99
  return true;
100
100
  };
101
+
102
+ // Delete with 'platform_editor_fix_quick_insert_consistency_exp'
101
103
  export function insertPanelWithAnalytics(inputMethod, analyticsAPI) {
102
104
  return withAnalytics(analyticsAPI, {
103
105
  action: ACTION.INSERTED,
@@ -1,11 +1,13 @@
1
1
  import React from 'react';
2
2
  import { extendedPanel, extendedPanelWithLocalId, PanelType, uuid } from '@atlaskit/adf-schema';
3
3
  import { ACTION, ACTION_SUBJECT, ACTION_SUBJECT_ID, EVENT_TYPE, INPUT_METHOD } from '@atlaskit/editor-common/analytics';
4
+ import { insertSelectedItem } from '@atlaskit/editor-common/insert';
4
5
  import { blockTypeMessages } from '@atlaskit/editor-common/messages';
5
6
  import { IconCustomPanel, IconPanel, IconPanelError, IconPanelNote, IconPanelSuccess, IconPanelWarning } from '@atlaskit/editor-common/quick-insert';
6
7
  import { createWrapSelectionTransaction } from '@atlaskit/editor-common/utils';
7
8
  import { fg } from '@atlaskit/platform-feature-flags';
8
9
  import { T50 } from '@atlaskit/theme/colors';
10
+ import { expValEquals } from '@atlaskit/tmp-editor-statsig/exp-val-equals';
9
11
  import { editorExperiment } from '@atlaskit/tmp-editor-statsig/experiments';
10
12
  import { insertPanelWithAnalytics } from './editor-actions/actions';
11
13
  import keymap from './pm-plugins/keymaps';
@@ -43,8 +45,28 @@ const panelPlugin = ({
43
45
  },
44
46
  actions: {
45
47
  insertPanel(inputMethod) {
46
- var _api$analytics;
47
- return insertPanelWithAnalytics(inputMethod, api === null || api === void 0 ? void 0 : (_api$analytics = api.analytics) === null || _api$analytics === void 0 ? void 0 : _api$analytics.actions);
48
+ if (expValEquals('platform_editor_fix_quick_insert_consistency_exp', 'isEnabled', true)) {
49
+ return function (state, dispatch) {
50
+ const tr = createPanelAction({
51
+ state,
52
+ attributes: {
53
+ panelType: PanelType.INFO
54
+ },
55
+ api,
56
+ inputMethod
57
+ });
58
+ if (!tr) {
59
+ return false;
60
+ }
61
+ if (dispatch) {
62
+ dispatch(tr);
63
+ }
64
+ return true;
65
+ };
66
+ } else {
67
+ var _api$analytics;
68
+ return insertPanelWithAnalytics(inputMethod, api === null || api === void 0 ? void 0 : (_api$analytics = api.analytics) === null || _api$analytics === void 0 ? void 0 : _api$analytics.actions);
69
+ }
48
70
  }
49
71
  },
50
72
  pluginsOptions: {
@@ -59,14 +81,14 @@ const panelPlugin = ({
59
81
  description: formatMessage(blockTypeMessages.infoPanelDescription),
60
82
  priority: 800,
61
83
  icon: () => /*#__PURE__*/React.createElement(IconPanel, null),
62
- action(insert, state) {
84
+ action(typeAheadInsert, state) {
63
85
  return createPanelAction({
64
86
  state,
65
87
  attributes: {
66
88
  panelType: PanelType.INFO
67
89
  },
68
90
  api,
69
- insert
91
+ typeAheadInsert
70
92
  });
71
93
  }
72
94
  }];
@@ -78,14 +100,14 @@ const panelPlugin = ({
78
100
  description: formatMessage(blockTypeMessages.infoPanelDescription),
79
101
  priority: 800,
80
102
  icon: () => /*#__PURE__*/React.createElement(IconPanel, null),
81
- action(insert, state) {
103
+ action(typeAheadInsert, state) {
82
104
  return createPanelAction({
83
105
  state,
84
106
  attributes: {
85
107
  panelType: PanelType.INFO
86
108
  },
87
109
  api,
88
- insert
110
+ typeAheadInsert
89
111
  });
90
112
  }
91
113
  }, {
@@ -94,14 +116,14 @@ const panelPlugin = ({
94
116
  description: formatMessage(blockTypeMessages.notePanelDescription),
95
117
  priority: 1000,
96
118
  icon: () => /*#__PURE__*/React.createElement(IconPanelNote, null),
97
- action(insert, state) {
119
+ action(typeAheadInsert, state) {
98
120
  return createPanelAction({
99
121
  state,
100
122
  attributes: {
101
123
  panelType: PanelType.NOTE
102
124
  },
103
125
  api,
104
- insert
126
+ typeAheadInsert
105
127
  });
106
128
  }
107
129
  }, {
@@ -111,14 +133,14 @@ const panelPlugin = ({
111
133
  keywords: ['tip'],
112
134
  priority: 1000,
113
135
  icon: () => /*#__PURE__*/React.createElement(IconPanelSuccess, null),
114
- action(insert, state) {
136
+ action(typeAheadInsert, state) {
115
137
  return createPanelAction({
116
138
  state,
117
139
  attributes: {
118
140
  panelType: PanelType.SUCCESS
119
141
  },
120
142
  api,
121
- insert
143
+ typeAheadInsert
122
144
  });
123
145
  }
124
146
  }, {
@@ -127,14 +149,14 @@ const panelPlugin = ({
127
149
  description: formatMessage(blockTypeMessages.warningPanelDescription),
128
150
  priority: 1000,
129
151
  icon: () => /*#__PURE__*/React.createElement(IconPanelWarning, null),
130
- action(insert, state) {
152
+ action(typeAheadInsert, state) {
131
153
  return createPanelAction({
132
154
  state,
133
155
  attributes: {
134
156
  panelType: PanelType.WARNING
135
157
  },
136
158
  api,
137
- insert
159
+ typeAheadInsert
138
160
  });
139
161
  }
140
162
  }, {
@@ -143,14 +165,14 @@ const panelPlugin = ({
143
165
  description: formatMessage(blockTypeMessages.errorPanelDescription),
144
166
  priority: 1000,
145
167
  icon: () => /*#__PURE__*/React.createElement(IconPanelError, null),
146
- action(insert, state) {
168
+ action(typeAheadInsert, state) {
147
169
  return createPanelAction({
148
170
  state,
149
171
  attributes: {
150
172
  panelType: PanelType.ERROR
151
173
  },
152
174
  api,
153
- insert
175
+ typeAheadInsert
154
176
  });
155
177
  }
156
178
  }];
@@ -161,7 +183,7 @@ const panelPlugin = ({
161
183
  description: formatMessage(blockTypeMessages.customPanelDescription),
162
184
  priority: 1000,
163
185
  icon: () => /*#__PURE__*/React.createElement(IconCustomPanel, null),
164
- action(insert, state) {
186
+ action(typeAheadInsert, state) {
165
187
  return createPanelAction({
166
188
  state,
167
189
  attributes: {
@@ -176,7 +198,7 @@ const panelPlugin = ({
176
198
  panelColor: T50
177
199
  },
178
200
  api,
179
- insert
201
+ typeAheadInsert
180
202
  });
181
203
  }
182
204
  });
@@ -204,8 +226,10 @@ function createPanelAction({
204
226
  state,
205
227
  attributes,
206
228
  api,
207
- insert
229
+ typeAheadInsert,
230
+ inputMethod = INPUT_METHOD.QUICK_INSERT
208
231
  }) {
232
+ var _tr;
209
233
  const {
210
234
  panel
211
235
  } = state.schema.nodes;
@@ -217,20 +241,51 @@ function createPanelAction({
217
241
  ...attributes
218
242
  };
219
243
 
220
- // Panels should wrap content by default when inserted, the quickInsert `insert` method
221
- // will insert the node on a newline
222
- if (editorExperiment('platform_editor_controls', 'variant1')) {
223
- tr = state.selection.empty && createWrapSelectionTransaction({
224
- state,
225
- type: panel,
226
- nodeAttributes: panelAttrs
227
- });
244
+ /*
245
+ During investigation of go/j/ED-26928 I found that the behaviour of this experience was very
246
+ inconsistent. I reached out to Nicole* for a design review, and she confirmed that the desired
247
+ behaviour is to insert the panel on a new line if the selection is empty.
248
+ *Confluence Editor Lead Product Designer
249
+ */
250
+ if (expValEquals('platform_editor_fix_quick_insert_consistency_exp', 'isEnabled', true)) {
251
+ // If the selection is empty, we want to insert the panel on a new line
252
+ if (state.selection.empty) {
253
+ const node = panel.createAndFill(panelAttrs);
254
+ if (!node) {
255
+ return false;
256
+ }
257
+ if (typeAheadInsert !== undefined) {
258
+ // If the type-ahead insert is provided, we should use that to insert the node
259
+ tr = typeAheadInsert(node);
260
+ } else {
261
+ var _insertSelectedItem;
262
+ // Otherwise we can use insertSelectedItem to insert the node
263
+ tr = (_insertSelectedItem = insertSelectedItem(node)(state, state.tr, state.selection.head)) === null || _insertSelectedItem === void 0 ? void 0 : _insertSelectedItem.scrollIntoView();
264
+ }
265
+ } else {
266
+ tr = createWrapSelectionTransaction({
267
+ state,
268
+ type: panel,
269
+ nodeAttributes: panelAttrs
270
+ });
271
+ }
228
272
  } else {
229
- const node = panel.createAndFill(panelAttrs);
230
- if (!node) {
231
- return false;
273
+ // Panels should wrap content by default when inserted, the quickInsert `insert` method
274
+ // will insert the node on a newline
275
+ if (editorExperiment('platform_editor_controls', 'variant1')) {
276
+ tr = state.selection.empty && createWrapSelectionTransaction({
277
+ state,
278
+ type: panel,
279
+ nodeAttributes: panelAttrs
280
+ });
281
+ } else {
282
+ const node = panel.createAndFill(panelAttrs);
283
+ if (!node) {
284
+ return false;
285
+ }
286
+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion -- This is only optional within the experiment, so safe to assume non-null here
287
+ tr = state.selection.empty && typeAheadInsert(node);
232
288
  }
233
- tr = state.selection.empty && insert(node);
234
289
  }
235
290
  if (tr) {
236
291
  var _api$analytics2;
@@ -239,12 +294,12 @@ function createPanelAction({
239
294
  actionSubject: ACTION_SUBJECT.DOCUMENT,
240
295
  actionSubjectId: ACTION_SUBJECT_ID.PANEL,
241
296
  attributes: {
242
- inputMethod: INPUT_METHOD.QUICK_INSERT,
297
+ inputMethod,
243
298
  panelType: attributes.panelType
244
299
  },
245
300
  eventType: EVENT_TYPE.TRACK
246
301
  })(tr);
247
302
  }
248
- return tr;
303
+ return (_tr = tr) !== null && _tr !== void 0 ? _tr : false;
249
304
  }
250
305
  export default panelPlugin;
@@ -100,6 +100,8 @@ export var changePanelType = function changePanelType(editorAnalyticsAPI) {
100
100
  };
101
101
  };
102
102
  };
103
+
104
+ // Delete with 'platform_editor_fix_quick_insert_consistency_exp'
103
105
  export function insertPanelWithAnalytics(inputMethod, analyticsAPI) {
104
106
  return withAnalytics(analyticsAPI, {
105
107
  action: ACTION.INSERTED,
@@ -4,11 +4,13 @@ function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t =
4
4
  import React from 'react';
5
5
  import { extendedPanel, extendedPanelWithLocalId, PanelType, uuid } from '@atlaskit/adf-schema';
6
6
  import { ACTION, ACTION_SUBJECT, ACTION_SUBJECT_ID, EVENT_TYPE, INPUT_METHOD } from '@atlaskit/editor-common/analytics';
7
+ import { insertSelectedItem } from '@atlaskit/editor-common/insert';
7
8
  import { blockTypeMessages } from '@atlaskit/editor-common/messages';
8
9
  import { IconCustomPanel, IconPanel, IconPanelError, IconPanelNote, IconPanelSuccess, IconPanelWarning } from '@atlaskit/editor-common/quick-insert';
9
10
  import { createWrapSelectionTransaction } from '@atlaskit/editor-common/utils';
10
11
  import { fg } from '@atlaskit/platform-feature-flags';
11
12
  import { T50 } from '@atlaskit/theme/colors';
13
+ import { expValEquals } from '@atlaskit/tmp-editor-statsig/exp-val-equals';
12
14
  import { editorExperiment } from '@atlaskit/tmp-editor-statsig/experiments';
13
15
  import { insertPanelWithAnalytics } from './editor-actions/actions';
14
16
  import keymap from './pm-plugins/keymaps';
@@ -50,8 +52,28 @@ var panelPlugin = function panelPlugin(_ref) {
50
52
  },
51
53
  actions: {
52
54
  insertPanel: function insertPanel(inputMethod) {
53
- var _api$analytics;
54
- return insertPanelWithAnalytics(inputMethod, api === null || api === void 0 || (_api$analytics = api.analytics) === null || _api$analytics === void 0 ? void 0 : _api$analytics.actions);
55
+ if (expValEquals('platform_editor_fix_quick_insert_consistency_exp', 'isEnabled', true)) {
56
+ return function (state, dispatch) {
57
+ var tr = createPanelAction({
58
+ state: state,
59
+ attributes: {
60
+ panelType: PanelType.INFO
61
+ },
62
+ api: api,
63
+ inputMethod: inputMethod
64
+ });
65
+ if (!tr) {
66
+ return false;
67
+ }
68
+ if (dispatch) {
69
+ dispatch(tr);
70
+ }
71
+ return true;
72
+ };
73
+ } else {
74
+ var _api$analytics;
75
+ return insertPanelWithAnalytics(inputMethod, api === null || api === void 0 || (_api$analytics = api.analytics) === null || _api$analytics === void 0 ? void 0 : _api$analytics.actions);
76
+ }
55
77
  }
56
78
  },
57
79
  pluginsOptions: {
@@ -67,14 +89,14 @@ var panelPlugin = function panelPlugin(_ref) {
67
89
  icon: function icon() {
68
90
  return /*#__PURE__*/React.createElement(IconPanel, null);
69
91
  },
70
- action: function action(insert, state) {
92
+ action: function action(typeAheadInsert, state) {
71
93
  return createPanelAction({
72
94
  state: state,
73
95
  attributes: {
74
96
  panelType: PanelType.INFO
75
97
  },
76
98
  api: api,
77
- insert: insert
99
+ typeAheadInsert: typeAheadInsert
78
100
  });
79
101
  }
80
102
  }];
@@ -88,14 +110,14 @@ var panelPlugin = function panelPlugin(_ref) {
88
110
  icon: function icon() {
89
111
  return /*#__PURE__*/React.createElement(IconPanel, null);
90
112
  },
91
- action: function action(insert, state) {
113
+ action: function action(typeAheadInsert, state) {
92
114
  return createPanelAction({
93
115
  state: state,
94
116
  attributes: {
95
117
  panelType: PanelType.INFO
96
118
  },
97
119
  api: api,
98
- insert: insert
120
+ typeAheadInsert: typeAheadInsert
99
121
  });
100
122
  }
101
123
  }, {
@@ -106,14 +128,14 @@ var panelPlugin = function panelPlugin(_ref) {
106
128
  icon: function icon() {
107
129
  return /*#__PURE__*/React.createElement(IconPanelNote, null);
108
130
  },
109
- action: function action(insert, state) {
131
+ action: function action(typeAheadInsert, state) {
110
132
  return createPanelAction({
111
133
  state: state,
112
134
  attributes: {
113
135
  panelType: PanelType.NOTE
114
136
  },
115
137
  api: api,
116
- insert: insert
138
+ typeAheadInsert: typeAheadInsert
117
139
  });
118
140
  }
119
141
  }, {
@@ -125,14 +147,14 @@ var panelPlugin = function panelPlugin(_ref) {
125
147
  icon: function icon() {
126
148
  return /*#__PURE__*/React.createElement(IconPanelSuccess, null);
127
149
  },
128
- action: function action(insert, state) {
150
+ action: function action(typeAheadInsert, state) {
129
151
  return createPanelAction({
130
152
  state: state,
131
153
  attributes: {
132
154
  panelType: PanelType.SUCCESS
133
155
  },
134
156
  api: api,
135
- insert: insert
157
+ typeAheadInsert: typeAheadInsert
136
158
  });
137
159
  }
138
160
  }, {
@@ -143,14 +165,14 @@ var panelPlugin = function panelPlugin(_ref) {
143
165
  icon: function icon() {
144
166
  return /*#__PURE__*/React.createElement(IconPanelWarning, null);
145
167
  },
146
- action: function action(insert, state) {
168
+ action: function action(typeAheadInsert, state) {
147
169
  return createPanelAction({
148
170
  state: state,
149
171
  attributes: {
150
172
  panelType: PanelType.WARNING
151
173
  },
152
174
  api: api,
153
- insert: insert
175
+ typeAheadInsert: typeAheadInsert
154
176
  });
155
177
  }
156
178
  }, {
@@ -161,14 +183,14 @@ var panelPlugin = function panelPlugin(_ref) {
161
183
  icon: function icon() {
162
184
  return /*#__PURE__*/React.createElement(IconPanelError, null);
163
185
  },
164
- action: function action(insert, state) {
186
+ action: function action(typeAheadInsert, state) {
165
187
  return createPanelAction({
166
188
  state: state,
167
189
  attributes: {
168
190
  panelType: PanelType.ERROR
169
191
  },
170
192
  api: api,
171
- insert: insert
193
+ typeAheadInsert: typeAheadInsert
172
194
  });
173
195
  }
174
196
  }];
@@ -181,7 +203,7 @@ var panelPlugin = function panelPlugin(_ref) {
181
203
  icon: function icon() {
182
204
  return /*#__PURE__*/React.createElement(IconCustomPanel, null);
183
205
  },
184
- action: function action(insert, state) {
206
+ action: function action(typeAheadInsert, state) {
185
207
  return createPanelAction({
186
208
  state: state,
187
209
  attributes: {
@@ -196,7 +218,7 @@ var panelPlugin = function panelPlugin(_ref) {
196
218
  panelColor: T50
197
219
  },
198
220
  api: api,
199
- insert: insert
221
+ typeAheadInsert: typeAheadInsert
200
222
  });
201
223
  }
202
224
  });
@@ -227,27 +249,60 @@ function createPanelAction(_ref4) {
227
249
  var state = _ref4.state,
228
250
  attributes = _ref4.attributes,
229
251
  api = _ref4.api,
230
- insert = _ref4.insert;
252
+ typeAheadInsert = _ref4.typeAheadInsert,
253
+ _ref4$inputMethod = _ref4.inputMethod,
254
+ inputMethod = _ref4$inputMethod === void 0 ? INPUT_METHOD.QUICK_INSERT : _ref4$inputMethod;
231
255
  var panel = state.schema.nodes.panel;
232
256
  var tr;
233
257
  var panelAttrs = fg('platform_editor_adf_with_localid') ? _objectSpread(_objectSpread({}, attributes), {}, {
234
258
  localId: attributes.localId || uuid.generate()
235
259
  }) : _objectSpread({}, attributes);
236
260
 
237
- // Panels should wrap content by default when inserted, the quickInsert `insert` method
238
- // will insert the node on a newline
239
- if (editorExperiment('platform_editor_controls', 'variant1')) {
240
- tr = state.selection.empty && createWrapSelectionTransaction({
241
- state: state,
242
- type: panel,
243
- nodeAttributes: panelAttrs
244
- });
261
+ /*
262
+ During investigation of go/j/ED-26928 I found that the behaviour of this experience was very
263
+ inconsistent. I reached out to Nicole* for a design review, and she confirmed that the desired
264
+ behaviour is to insert the panel on a new line if the selection is empty.
265
+ *Confluence Editor Lead Product Designer
266
+ */
267
+ if (expValEquals('platform_editor_fix_quick_insert_consistency_exp', 'isEnabled', true)) {
268
+ // If the selection is empty, we want to insert the panel on a new line
269
+ if (state.selection.empty) {
270
+ var node = panel.createAndFill(panelAttrs);
271
+ if (!node) {
272
+ return false;
273
+ }
274
+ if (typeAheadInsert !== undefined) {
275
+ // If the type-ahead insert is provided, we should use that to insert the node
276
+ tr = typeAheadInsert(node);
277
+ } else {
278
+ var _insertSelectedItem;
279
+ // Otherwise we can use insertSelectedItem to insert the node
280
+ tr = (_insertSelectedItem = insertSelectedItem(node)(state, state.tr, state.selection.head)) === null || _insertSelectedItem === void 0 ? void 0 : _insertSelectedItem.scrollIntoView();
281
+ }
282
+ } else {
283
+ tr = createWrapSelectionTransaction({
284
+ state: state,
285
+ type: panel,
286
+ nodeAttributes: panelAttrs
287
+ });
288
+ }
245
289
  } else {
246
- var node = panel.createAndFill(panelAttrs);
247
- if (!node) {
248
- return false;
290
+ // Panels should wrap content by default when inserted, the quickInsert `insert` method
291
+ // will insert the node on a newline
292
+ if (editorExperiment('platform_editor_controls', 'variant1')) {
293
+ tr = state.selection.empty && createWrapSelectionTransaction({
294
+ state: state,
295
+ type: panel,
296
+ nodeAttributes: panelAttrs
297
+ });
298
+ } else {
299
+ var _node = panel.createAndFill(panelAttrs);
300
+ if (!_node) {
301
+ return false;
302
+ }
303
+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion -- This is only optional within the experiment, so safe to assume non-null here
304
+ tr = state.selection.empty && typeAheadInsert(_node);
249
305
  }
250
- tr = state.selection.empty && insert(node);
251
306
  }
252
307
  if (tr) {
253
308
  var _api$analytics2;
@@ -256,12 +311,12 @@ function createPanelAction(_ref4) {
256
311
  actionSubject: ACTION_SUBJECT.DOCUMENT,
257
312
  actionSubjectId: ACTION_SUBJECT_ID.PANEL,
258
313
  attributes: {
259
- inputMethod: INPUT_METHOD.QUICK_INSERT,
314
+ inputMethod: inputMethod,
260
315
  panelType: attributes.panelType
261
316
  },
262
317
  eventType: EVENT_TYPE.TRACK
263
318
  })(tr);
264
319
  }
265
- return tr;
320
+ return tr !== null && tr !== void 0 ? tr : false;
266
321
  }
267
322
  export default panelPlugin;
@@ -33,6 +33,6 @@ export type PanelPlugin = NextEditorPlugin<'panel', {
33
33
  pluginConfiguration: PanelPluginOptions | undefined;
34
34
  dependencies: PanelPluginDependencies;
35
35
  actions: {
36
- insertPanel: (inputMethod: INPUT_METHOD) => Command;
36
+ insertPanel: (inputMethod: INPUT_METHOD.INSERT_MENU | INPUT_METHOD.QUICK_INSERT | INPUT_METHOD.TOOLBAR) => Command;
37
37
  };
38
38
  }>;
@@ -33,6 +33,6 @@ export type PanelPlugin = NextEditorPlugin<'panel', {
33
33
  pluginConfiguration: PanelPluginOptions | undefined;
34
34
  dependencies: PanelPluginDependencies;
35
35
  actions: {
36
- insertPanel: (inputMethod: INPUT_METHOD) => Command;
36
+ insertPanel: (inputMethod: INPUT_METHOD.INSERT_MENU | INPUT_METHOD.QUICK_INSERT | INPUT_METHOD.TOOLBAR) => Command;
37
37
  };
38
38
  }>;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atlaskit/editor-plugin-panel",
3
- "version": "5.2.5",
3
+ "version": "5.3.0",
4
4
  "description": "Panel plugin for @atlaskit/editor-core.",
5
5
  "author": "Atlassian Pty Ltd",
6
6
  "license": "Apache-2.0",
@@ -41,20 +41,17 @@
41
41
  "@atlaskit/icon": "^27.9.0",
42
42
  "@atlaskit/platform-feature-flags": "^1.1.0",
43
43
  "@atlaskit/theme": "^19.0.0",
44
- "@atlaskit/tmp-editor-statsig": "^9.22.0",
44
+ "@atlaskit/tmp-editor-statsig": "^9.25.0",
45
45
  "@atlaskit/tokens": "^6.0.0",
46
46
  "@babel/runtime": "^7.0.0",
47
47
  "uuid": "^3.1.0"
48
48
  },
49
49
  "peerDependencies": {
50
- "@atlaskit/editor-common": "^107.16.0",
50
+ "@atlaskit/editor-common": "^107.18.0",
51
51
  "react": "^18.2.0",
52
52
  "react-dom": "^18.2.0",
53
53
  "react-intl-next": "npm:react-intl@^5.18.1"
54
54
  },
55
- "devDependencies": {
56
- "typescript": "~5.4.2"
57
- },
58
55
  "techstack": {
59
56
  "@atlassian/frontend": {
60
57
  "import-structure": [