@atlaskit/editor-plugin-extension 20.0.4 → 20.0.6

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,21 @@
1
1
  # @atlaskit/editor-plugin-extension
2
2
 
3
+ ## 20.0.6
4
+
5
+ ### Patch Changes
6
+
7
+ - [`78155dcee29bf`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/78155dcee29bf) -
8
+ Add generic extension API insertion and node-type replacement support. Use these APIs to preserve
9
+ the position of newly inserted inline-bodied Forge macros and to restore inline placement when an
10
+ inline Connect macro is harmonized to Forge while platform_forge_inline_bodied_macro is enabled.
11
+ - Updated dependencies
12
+
13
+ ## 20.0.5
14
+
15
+ ### Patch Changes
16
+
17
+ - Updated dependencies
18
+
3
19
  ## 20.0.4
4
20
 
5
21
  ### Patch Changes
@@ -5,8 +5,8 @@ Object.defineProperty(exports, "__esModule", {
5
5
  value: true
6
6
  });
7
7
  exports.getEditInLegacyMacroBrowser = exports.createExtensionAPI = void 0;
8
- var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
9
8
  var _typeof2 = _interopRequireDefault(require("@babel/runtime/helpers/typeof"));
9
+ var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
10
10
  var _validator = require("@atlaskit/adf-utils/validator");
11
11
  var _analytics = require("@atlaskit/editor-common/analytics");
12
12
  var _utils = require("@atlaskit/editor-common/utils");
@@ -167,15 +167,38 @@ var createExtensionAPI = exports.createExtensionAPI = function createExtensionAP
167
167
  }
168
168
  dispatch(tr);
169
169
  },
170
+ insertAtSelection: function insertAtSelection(adf) {
171
+ if (!(0, _fg.fg)('platform_forge_inline_bodied_macro')) {
172
+ return;
173
+ }
174
+ try {
175
+ validate(adf);
176
+ } catch (_unused) {
177
+ throw new Error("insertAtSelection(): Invalid ADF given.");
178
+ }
179
+ var _options$editorView = options.editorView,
180
+ dispatch = _options$editorView.dispatch,
181
+ state = _options$editorView.state;
182
+ var newNode = state.schema.nodeFromJSON(adf);
183
+ var tr = state.tr.replaceSelectionWith(newNode).scrollIntoView();
184
+ try {
185
+ tr.doc.check();
186
+ } catch (err) {
187
+ throw new Error("insertAtSelection(): The given ADFEntity cannot replace the current selection.\n".concat(err));
188
+ }
189
+ var apiCallPayload = extensionAPICallPayload('insertAtSelection');
190
+ editorAnalyticsAPI === null || editorAnalyticsAPI === void 0 || editorAnalyticsAPI.attachAnalyticsEvent(apiCallPayload)(tr);
191
+ dispatch(tr);
192
+ },
170
193
  scrollTo: function scrollTo(localId) {
171
194
  var nodePos = ensureNodePosByLocalId(localId, {
172
195
  opName: 'scrollTo'
173
196
  });
174
197
  // Analytics - tracking the api call
175
198
  var apiCallPayload = extensionAPICallPayload('scrollTo');
176
- var _options$editorView = options.editorView,
177
- dispatch = _options$editorView.dispatch,
178
- state = _options$editorView.state;
199
+ var _options$editorView2 = options.editorView,
200
+ dispatch = _options$editorView2.dispatch,
201
+ state = _options$editorView2.state;
179
202
  var tr = state.tr;
180
203
  editorAnalyticsAPI === null || editorAnalyticsAPI === void 0 || editorAnalyticsAPI.attachAnalyticsEvent(apiCallPayload)(tr);
181
204
  tr = (0, _utils2.setTextSelection)(nodePos.pos)(tr);
@@ -202,12 +225,14 @@ var createExtensionAPI = exports.createExtensionAPI = function createExtensionAP
202
225
  }),
203
226
  node = _ensureNodePosByLocal.node,
204
227
  pos = _ensureNodePosByLocal.pos;
205
- var _options$editorView2 = options.editorView,
206
- dispatch = _options$editorView2.dispatch,
207
- state = _options$editorView2.state;
228
+ var _options$editorView3 = options.editorView,
229
+ dispatch = _options$editorView3.dispatch,
230
+ state = _options$editorView3.state;
208
231
  var tr = state.tr,
209
232
  schema = state.schema;
210
- var changedValues = mutationCallback({
233
+ var changedValues = mutationCallback(_objectSpread(_objectSpread({}, (0, _fg.fg)('platform_forge_inline_bodied_macro') ? {
234
+ type: node.type.name
235
+ } : {}), {}, {
211
236
  content: (0, _utils.nodeToJSON)(node).content,
212
237
  attrs: node.attrs,
213
238
  marks: node.marks.map(function (pmMark) {
@@ -216,7 +241,7 @@ var createExtensionAPI = exports.createExtensionAPI = function createExtensionAP
216
241
  attrs: pmMark.attrs
217
242
  };
218
243
  })
219
- });
244
+ }));
220
245
  var ensureValidMark = function ensureValidMark(mark) {
221
246
  if ((0, _typeof2.default)(mark) !== 'object' || Array.isArray(mark)) {
222
247
  throw new Error("update(): Invalid mark given.");
@@ -242,6 +267,13 @@ var createExtensionAPI = exports.createExtensionAPI = function createExtensionAP
242
267
  return mark.create(attrs);
243
268
  }) : node.marks;
244
269
  var newContent = changedValues.hasOwnProperty('content') ? _model.Fragment.fromJSON(schema, changedValues.content) : node.content;
270
+ var newType = node.type;
271
+ if (changedValues.hasOwnProperty('type') && changedValues.type !== node.type.name && (0, _fg.fg)('platform_forge_inline_bodied_macro')) {
272
+ newType = changedValues.type ? schema.nodes[changedValues.type] : undefined;
273
+ }
274
+ if (!newType) {
275
+ throw new Error("update(): Invalid ADF node type '".concat(changedValues.type, "'."));
276
+ }
245
277
  var newAttrs = changedValues.hasOwnProperty('attrs') ? changedValues.attrs : node.attrs;
246
278
  if (node.type.name === 'multiBodiedExtension') {
247
279
  var _changedValues$attrs, _node$attrs$parameter, _changedValues$attrs2;
@@ -255,13 +287,21 @@ var createExtensionAPI = exports.createExtensionAPI = function createExtensionAP
255
287
 
256
288
  // Validate if the new attributes, content and marks result in a valid node and adf.
257
289
  try {
258
- var newNode = node.type.createChecked(newAttrs, newContent, newMarks);
290
+ var newNode = newType.createChecked(newAttrs, newContent, newMarks);
259
291
  var newNodeAdf = new _JSONTransformer.JSONTransformer().encodeNode(newNode);
260
292
  validate(newNodeAdf);
261
- tr.replaceWith(pos, pos + node.nodeSize, newNode);
293
+ if (newType === node.type) {
294
+ tr.replaceWith(pos, pos + node.nodeSize, newNode);
295
+ } else {
296
+ tr.replaceRangeWith(pos, pos + node.nodeSize, newNode);
297
+ if (node.isBlock && newNode.isInline) {
298
+ (0, _utils.autoJoinTr)(tr, ['paragraph']);
299
+ }
300
+ tr.doc.check();
301
+ }
262
302
 
263
303
  // Keep selection if content does not change
264
- if (newContent === node.content) {
304
+ if (newType === node.type && newContent === node.content) {
265
305
  tr.setSelection(_state.Selection.fromJSON(tr.doc, state.selection.toJSON()));
266
306
  }
267
307
  } catch (err) {
@@ -1,6 +1,6 @@
1
1
  import { validator } from '@atlaskit/adf-utils/validator';
2
2
  import { ACTION, ACTION_SUBJECT, ACTION_SUBJECT_ID, EVENT_TYPE, INPUT_METHOD } from '@atlaskit/editor-common/analytics';
3
- import { nodeToJSON } from '@atlaskit/editor-common/utils';
3
+ import { autoJoinTr, nodeToJSON } from '@atlaskit/editor-common/utils';
4
4
  import { JSONTransformer } from '@atlaskit/editor-json-transformer/JSONTransformer-2';
5
5
  import { Fragment, Mark } from '@atlaskit/editor-prosemirror/model';
6
6
  import { NodeSelection, Selection, TextSelection } from '@atlaskit/editor-prosemirror/state';
@@ -169,6 +169,30 @@ export const createExtensionAPI = options => {
169
169
  }
170
170
  dispatch(tr);
171
171
  },
172
+ insertAtSelection: adf => {
173
+ if (!fg('platform_forge_inline_bodied_macro')) {
174
+ return;
175
+ }
176
+ try {
177
+ validate(adf);
178
+ } catch {
179
+ throw new Error(`insertAtSelection(): Invalid ADF given.`);
180
+ }
181
+ const {
182
+ dispatch,
183
+ state
184
+ } = options.editorView;
185
+ const newNode = state.schema.nodeFromJSON(adf);
186
+ const tr = state.tr.replaceSelectionWith(newNode).scrollIntoView();
187
+ try {
188
+ tr.doc.check();
189
+ } catch (err) {
190
+ throw new Error(`insertAtSelection(): The given ADFEntity cannot replace the current selection.\n${err}`);
191
+ }
192
+ const apiCallPayload = extensionAPICallPayload('insertAtSelection');
193
+ editorAnalyticsAPI === null || editorAnalyticsAPI === void 0 ? void 0 : editorAnalyticsAPI.attachAnalyticsEvent(apiCallPayload)(tr);
194
+ dispatch(tr);
195
+ },
172
196
  scrollTo: localId => {
173
197
  const nodePos = ensureNodePosByLocalId(localId, {
174
198
  opName: 'scrollTo'
@@ -221,6 +245,9 @@ export const createExtensionAPI = options => {
221
245
  schema
222
246
  } = state;
223
247
  const changedValues = mutationCallback({
248
+ ...(fg('platform_forge_inline_bodied_macro') ? {
249
+ type: node.type.name
250
+ } : {}),
224
251
  content: nodeToJSON(node).content,
225
252
  attrs: node.attrs,
226
253
  marks: node.marks.map(pmMark => ({
@@ -253,6 +280,13 @@ export const createExtensionAPI = options => {
253
280
  attrs
254
281
  }) => mark.create(attrs)) : node.marks;
255
282
  const newContent = changedValues.hasOwnProperty('content') ? Fragment.fromJSON(schema, changedValues.content) : node.content;
283
+ let newType = node.type;
284
+ if (changedValues.hasOwnProperty('type') && changedValues.type !== node.type.name && fg('platform_forge_inline_bodied_macro')) {
285
+ newType = changedValues.type ? schema.nodes[changedValues.type] : undefined;
286
+ }
287
+ if (!newType) {
288
+ throw new Error(`update(): Invalid ADF node type '${changedValues.type}'.`);
289
+ }
256
290
  let newAttrs = changedValues.hasOwnProperty('attrs') ? changedValues.attrs : node.attrs;
257
291
  if (node.type.name === 'multiBodiedExtension') {
258
292
  var _changedValues$attrs, _node$attrs$parameter, _changedValues$attrs2, _changedValues$attrs3;
@@ -273,13 +307,21 @@ export const createExtensionAPI = options => {
273
307
 
274
308
  // Validate if the new attributes, content and marks result in a valid node and adf.
275
309
  try {
276
- const newNode = node.type.createChecked(newAttrs, newContent, newMarks);
310
+ const newNode = newType.createChecked(newAttrs, newContent, newMarks);
277
311
  const newNodeAdf = new JSONTransformer().encodeNode(newNode);
278
312
  validate(newNodeAdf);
279
- tr.replaceWith(pos, pos + node.nodeSize, newNode);
313
+ if (newType === node.type) {
314
+ tr.replaceWith(pos, pos + node.nodeSize, newNode);
315
+ } else {
316
+ tr.replaceRangeWith(pos, pos + node.nodeSize, newNode);
317
+ if (node.isBlock && newNode.isInline) {
318
+ autoJoinTr(tr, ['paragraph']);
319
+ }
320
+ tr.doc.check();
321
+ }
280
322
 
281
323
  // Keep selection if content does not change
282
- if (newContent === node.content) {
324
+ if (newType === node.type && newContent === node.content) {
283
325
  tr.setSelection(Selection.fromJSON(tr.doc, state.selection.toJSON()));
284
326
  }
285
327
  } catch (err) {
@@ -1,10 +1,10 @@
1
- import _defineProperty from "@babel/runtime/helpers/defineProperty";
2
1
  import _typeof from "@babel/runtime/helpers/typeof";
2
+ import _defineProperty from "@babel/runtime/helpers/defineProperty";
3
3
  function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
4
4
  function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
5
5
  import { validator } from '@atlaskit/adf-utils/validator';
6
6
  import { ACTION, ACTION_SUBJECT, ACTION_SUBJECT_ID, EVENT_TYPE, INPUT_METHOD } from '@atlaskit/editor-common/analytics';
7
- import { nodeToJSON } from '@atlaskit/editor-common/utils';
7
+ import { autoJoinTr, nodeToJSON } from '@atlaskit/editor-common/utils';
8
8
  import { JSONTransformer } from '@atlaskit/editor-json-transformer/JSONTransformer-2';
9
9
  import { Fragment, Mark } from '@atlaskit/editor-prosemirror/model';
10
10
  import { NodeSelection, Selection, TextSelection } from '@atlaskit/editor-prosemirror/state';
@@ -160,15 +160,38 @@ export var createExtensionAPI = function createExtensionAPI(options) {
160
160
  }
161
161
  dispatch(tr);
162
162
  },
163
+ insertAtSelection: function insertAtSelection(adf) {
164
+ if (!fg('platform_forge_inline_bodied_macro')) {
165
+ return;
166
+ }
167
+ try {
168
+ validate(adf);
169
+ } catch (_unused) {
170
+ throw new Error("insertAtSelection(): Invalid ADF given.");
171
+ }
172
+ var _options$editorView = options.editorView,
173
+ dispatch = _options$editorView.dispatch,
174
+ state = _options$editorView.state;
175
+ var newNode = state.schema.nodeFromJSON(adf);
176
+ var tr = state.tr.replaceSelectionWith(newNode).scrollIntoView();
177
+ try {
178
+ tr.doc.check();
179
+ } catch (err) {
180
+ throw new Error("insertAtSelection(): The given ADFEntity cannot replace the current selection.\n".concat(err));
181
+ }
182
+ var apiCallPayload = extensionAPICallPayload('insertAtSelection');
183
+ editorAnalyticsAPI === null || editorAnalyticsAPI === void 0 || editorAnalyticsAPI.attachAnalyticsEvent(apiCallPayload)(tr);
184
+ dispatch(tr);
185
+ },
163
186
  scrollTo: function scrollTo(localId) {
164
187
  var nodePos = ensureNodePosByLocalId(localId, {
165
188
  opName: 'scrollTo'
166
189
  });
167
190
  // Analytics - tracking the api call
168
191
  var apiCallPayload = extensionAPICallPayload('scrollTo');
169
- var _options$editorView = options.editorView,
170
- dispatch = _options$editorView.dispatch,
171
- state = _options$editorView.state;
192
+ var _options$editorView2 = options.editorView,
193
+ dispatch = _options$editorView2.dispatch,
194
+ state = _options$editorView2.state;
172
195
  var tr = state.tr;
173
196
  editorAnalyticsAPI === null || editorAnalyticsAPI === void 0 || editorAnalyticsAPI.attachAnalyticsEvent(apiCallPayload)(tr);
174
197
  tr = setTextSelection(nodePos.pos)(tr);
@@ -195,12 +218,14 @@ export var createExtensionAPI = function createExtensionAPI(options) {
195
218
  }),
196
219
  node = _ensureNodePosByLocal.node,
197
220
  pos = _ensureNodePosByLocal.pos;
198
- var _options$editorView2 = options.editorView,
199
- dispatch = _options$editorView2.dispatch,
200
- state = _options$editorView2.state;
221
+ var _options$editorView3 = options.editorView,
222
+ dispatch = _options$editorView3.dispatch,
223
+ state = _options$editorView3.state;
201
224
  var tr = state.tr,
202
225
  schema = state.schema;
203
- var changedValues = mutationCallback({
226
+ var changedValues = mutationCallback(_objectSpread(_objectSpread({}, fg('platform_forge_inline_bodied_macro') ? {
227
+ type: node.type.name
228
+ } : {}), {}, {
204
229
  content: nodeToJSON(node).content,
205
230
  attrs: node.attrs,
206
231
  marks: node.marks.map(function (pmMark) {
@@ -209,7 +234,7 @@ export var createExtensionAPI = function createExtensionAPI(options) {
209
234
  attrs: pmMark.attrs
210
235
  };
211
236
  })
212
- });
237
+ }));
213
238
  var ensureValidMark = function ensureValidMark(mark) {
214
239
  if (_typeof(mark) !== 'object' || Array.isArray(mark)) {
215
240
  throw new Error("update(): Invalid mark given.");
@@ -235,6 +260,13 @@ export var createExtensionAPI = function createExtensionAPI(options) {
235
260
  return mark.create(attrs);
236
261
  }) : node.marks;
237
262
  var newContent = changedValues.hasOwnProperty('content') ? Fragment.fromJSON(schema, changedValues.content) : node.content;
263
+ var newType = node.type;
264
+ if (changedValues.hasOwnProperty('type') && changedValues.type !== node.type.name && fg('platform_forge_inline_bodied_macro')) {
265
+ newType = changedValues.type ? schema.nodes[changedValues.type] : undefined;
266
+ }
267
+ if (!newType) {
268
+ throw new Error("update(): Invalid ADF node type '".concat(changedValues.type, "'."));
269
+ }
238
270
  var newAttrs = changedValues.hasOwnProperty('attrs') ? changedValues.attrs : node.attrs;
239
271
  if (node.type.name === 'multiBodiedExtension') {
240
272
  var _changedValues$attrs, _node$attrs$parameter, _changedValues$attrs2;
@@ -248,13 +280,21 @@ export var createExtensionAPI = function createExtensionAPI(options) {
248
280
 
249
281
  // Validate if the new attributes, content and marks result in a valid node and adf.
250
282
  try {
251
- var newNode = node.type.createChecked(newAttrs, newContent, newMarks);
283
+ var newNode = newType.createChecked(newAttrs, newContent, newMarks);
252
284
  var newNodeAdf = new JSONTransformer().encodeNode(newNode);
253
285
  validate(newNodeAdf);
254
- tr.replaceWith(pos, pos + node.nodeSize, newNode);
286
+ if (newType === node.type) {
287
+ tr.replaceWith(pos, pos + node.nodeSize, newNode);
288
+ } else {
289
+ tr.replaceRangeWith(pos, pos + node.nodeSize, newNode);
290
+ if (node.isBlock && newNode.isInline) {
291
+ autoJoinTr(tr, ['paragraph']);
292
+ }
293
+ tr.doc.check();
294
+ }
255
295
 
256
296
  // Keep selection if content does not change
257
- if (newContent === node.content) {
297
+ if (newType === node.type && newContent === node.content) {
258
298
  tr.setSelection(Selection.fromJSON(tr.doc, state.selection.toJSON()));
259
299
  }
260
300
  } catch (err) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atlaskit/editor-plugin-extension",
3
- "version": "20.0.4",
3
+ "version": "20.0.6",
4
4
  "description": "editor-plugin-extension plugin for @atlaskit/editor-core",
5
5
  "author": "Atlassian Pty Ltd",
6
6
  "license": "Apache-2.0",
@@ -44,7 +44,7 @@
44
44
  "@atlaskit/editor-plugin-width": "^18.0.0",
45
45
  "@atlaskit/editor-prosemirror": "^8.0.0",
46
46
  "@atlaskit/editor-shared-styles": "^4.1.0",
47
- "@atlaskit/editor-tables": "^3.1.0",
47
+ "@atlaskit/editor-tables": "^3.2.0",
48
48
  "@atlaskit/empty-state": "^12.2.0",
49
49
  "@atlaskit/form": "^17.2.0",
50
50
  "@atlaskit/heading": "^7.2.0",
@@ -64,7 +64,7 @@
64
64
  "@atlaskit/tabs": "^21.2.0",
65
65
  "@atlaskit/textarea": "^10.2.0",
66
66
  "@atlaskit/textfield": "^10.2.0",
67
- "@atlaskit/tmp-editor-statsig": "^183.0.0",
67
+ "@atlaskit/tmp-editor-statsig": "^184.0.0",
68
68
  "@atlaskit/toggle": "^17.3.0",
69
69
  "@atlaskit/tokens": "^16.11.0",
70
70
  "@atlaskit/tooltip": "^24.3.0",
@@ -79,12 +79,13 @@
79
79
  "uuid": "^11.1.1"
80
80
  },
81
81
  "peerDependencies": {
82
- "@atlaskit/editor-common": "^121.2.0",
82
+ "@atlaskit/editor-common": "^121.3.0",
83
83
  "react": "^18.2.0 || ^19.2.0",
84
84
  "react-intl": "^5.25.1 || ^6.0.0 || ^7.0.0"
85
85
  },
86
86
  "devDependencies": {
87
87
  "@atlassian/structured-docs-types": "workspace:^",
88
+ "@atlassian/workbench": "workspace:*",
88
89
  "react": "^19.2.0",
89
90
  "react-intl": "^7.0.0",
90
91
  "react-select": "^5.4.0"
@@ -93,6 +94,9 @@
93
94
  "platform_editor_adf_validator_stage0": {
94
95
  "type": "boolean"
95
96
  },
97
+ "platform_forge_inline_bodied_macro": {
98
+ "type": "boolean"
99
+ },
96
100
  "platform_editor_ai_object_sidebar_injection": {
97
101
  "type": "boolean"
98
102
  },