@atlaskit/editor-plugin-placeholder 6.4.0 → 6.5.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,17 @@
1
1
  # @atlaskit/editor-plugin-placeholder
2
2
 
3
+ ## 6.5.0
4
+
5
+ ### Minor Changes
6
+
7
+ - [`025002b2a71fc`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/025002b2a71fc) -
8
+ [ux] [EDITOR-3320] fix bug on panel and table placeholders/ added code mark on keyboard shorcuts
9
+ on panel and table placeholders
10
+
11
+ ### Patch Changes
12
+
13
+ - Updated dependencies
14
+
3
15
  ## 6.4.0
4
16
 
5
17
  ### Minor Changes
@@ -9,6 +9,7 @@ exports.createPlaceholderDecoration = createPlaceholderDecoration;
9
9
  exports.createPlugin = createPlugin;
10
10
  exports.pluginKey = exports.placeholderPlugin = void 0;
11
11
  var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
12
+ var _builders = require("@atlaskit/adf-utils/builders");
12
13
  var _messages = require("@atlaskit/editor-common/messages");
13
14
  var _processRawValue = require("@atlaskit/editor-common/process-raw-value");
14
15
  var _safePlugin = require("@atlaskit/editor-common/safe-plugin");
@@ -39,6 +40,28 @@ function getPlaceholderState(editorState) {
39
40
  var nodeTypesWithLongPlaceholderText = ['expand', 'panel'];
40
41
  var nodeTypesWithShortPlaceholderText = ['tableCell', 'tableHeader'];
41
42
  var nodeTypesWithSyncBlockPlaceholderText = ['bodiedSyncBlock'];
43
+ var createShortEmptyNodePlaceholderADF = function createShortEmptyNodePlaceholderADF(_ref) {
44
+ var formatMessage = _ref.formatMessage;
45
+ return {
46
+ version: 1,
47
+ type: 'doc',
48
+ content: [{
49
+ type: 'paragraph',
50
+ content: [(0, _builders.code)(formatMessage(_messages.placeholderTextMessages.shortEmptyNodePlaceholderADFSlashShortcut)), (0, _builders.text)(' '), (0, _builders.text)(formatMessage(_messages.placeholderTextMessages.shortEmptyNodePlaceholderADFSuffix))]
51
+ }]
52
+ };
53
+ };
54
+ var createLongEmptyNodePlaceholderADF = function createLongEmptyNodePlaceholderADF(_ref2) {
55
+ var formatMessage = _ref2.formatMessage;
56
+ return {
57
+ version: 1,
58
+ type: 'doc',
59
+ content: [{
60
+ type: 'paragraph',
61
+ content: [(0, _builders.text)(formatMessage(_messages.placeholderTextMessages.longEmptyNodePlaceholderADFPrefix)), (0, _builders.text)(' '), (0, _builders.code)(formatMessage(_messages.placeholderTextMessages.longEmptyNodePlaceholderADFSlashShortcut)), (0, _builders.text)(' '), (0, _builders.text)(formatMessage(_messages.placeholderTextMessages.longEmptyNodePlaceholderADFSuffix))]
62
+ }]
63
+ };
64
+ };
42
65
  var cycleThroughPlaceholderPrompts = function cycleThroughPlaceholderPrompts(placeholderPrompts, activeTypewriterTimeouts, placeholderNodeWithText) {
43
66
  var initialDelayWhenUserTypedAndDeleted = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : 0;
44
67
  var currentPromptIndex = 0;
@@ -98,6 +121,7 @@ function createPlaceholderDecoration(editorState, placeholderText, placeholderPr
98
121
  var placeholderNodeWithText = placeholderDecoration;
99
122
  placeholderDecoration.setAttribute('data-testid', placeholderTestId);
100
123
  placeholderDecoration.className = 'placeholder-decoration';
124
+ placeholderDecoration.setAttribute('aria-hidden', 'true');
101
125
 
102
126
  // PM sets contenteditable to false on Decorations so Firefox doesn't display the flashing cursor
103
127
  // So adding an extra span which will contain the placeholder text
@@ -107,7 +131,9 @@ function createPlaceholderDecoration(editorState, placeholderText, placeholderPr
107
131
  placeholderDecoration.appendChild(placeholderNode);
108
132
  placeholderNodeWithText = placeholderNode;
109
133
  }
110
- if (placeholderADF) {
134
+ if (placeholderText) {
135
+ placeholderNodeWithText.textContent = placeholderText || ' ';
136
+ } else if (placeholderADF) {
111
137
  var serializer = _model.DOMSerializer.fromSchema(editorState.schema);
112
138
  // Get a PMNode from docnode
113
139
  var docNode = (0, _processRawValue.processRawValue)(editorState.schema, placeholderADF);
@@ -143,8 +169,6 @@ function createPlaceholderDecoration(editorState, placeholderText, placeholderPr
143
169
  }
144
170
  });
145
171
  }
146
- } else if (placeholderText) {
147
- placeholderNodeWithText.textContent = placeholderText || ' ';
148
172
  } else if (placeholderPrompts) {
149
173
  cycleThroughPlaceholderPrompts(placeholderPrompts, activeTypewriterTimeouts, placeholderNodeWithText, initialDelayWhenUserTypedAndDeleted);
150
174
  }
@@ -171,18 +195,20 @@ function createPlaceholderDecoration(editorState, placeholderText, placeholderPr
171
195
  key: "placeholder ".concat(placeholderText)
172
196
  })]);
173
197
  }
174
- function setPlaceHolderState(_ref) {
175
- var placeholderText = _ref.placeholderText,
176
- pos = _ref.pos,
177
- placeholderPrompts = _ref.placeholderPrompts,
178
- typedAndDeleted = _ref.typedAndDeleted,
179
- userHadTyped = _ref.userHadTyped,
180
- canShowOnEmptyParagraph = _ref.canShowOnEmptyParagraph,
181
- showOnEmptyParagraph = _ref.showOnEmptyParagraph;
198
+ function setPlaceHolderState(_ref3) {
199
+ var placeholderText = _ref3.placeholderText,
200
+ pos = _ref3.pos,
201
+ placeholderPrompts = _ref3.placeholderPrompts,
202
+ typedAndDeleted = _ref3.typedAndDeleted,
203
+ userHadTyped = _ref3.userHadTyped,
204
+ canShowOnEmptyParagraph = _ref3.canShowOnEmptyParagraph,
205
+ showOnEmptyParagraph = _ref3.showOnEmptyParagraph,
206
+ contextPlaceholderADF = _ref3.contextPlaceholderADF;
182
207
  return {
183
208
  hasPlaceholder: true,
184
209
  placeholderText: placeholderText,
185
210
  placeholderPrompts: placeholderPrompts,
211
+ contextPlaceholderADF: contextPlaceholderADF,
186
212
  pos: pos ? pos : 1,
187
213
  typedAndDeleted: typedAndDeleted,
188
214
  userHadTyped: userHadTyped,
@@ -190,13 +216,13 @@ function setPlaceHolderState(_ref) {
190
216
  showOnEmptyParagraph: showOnEmptyParagraph
191
217
  };
192
218
  }
193
- var emptyPlaceholder = function emptyPlaceholder(_ref2) {
194
- var placeholderText = _ref2.placeholderText,
195
- placeholderPrompts = _ref2.placeholderPrompts,
196
- userHadTyped = _ref2.userHadTyped,
197
- pos = _ref2.pos,
198
- canShowOnEmptyParagraph = _ref2.canShowOnEmptyParagraph,
199
- showOnEmptyParagraph = _ref2.showOnEmptyParagraph;
219
+ var emptyPlaceholder = function emptyPlaceholder(_ref4) {
220
+ var placeholderText = _ref4.placeholderText,
221
+ placeholderPrompts = _ref4.placeholderPrompts,
222
+ userHadTyped = _ref4.userHadTyped,
223
+ pos = _ref4.pos,
224
+ canShowOnEmptyParagraph = _ref4.canShowOnEmptyParagraph,
225
+ showOnEmptyParagraph = _ref4.showOnEmptyParagraph;
200
226
  return {
201
227
  hasPlaceholder: false,
202
228
  placeholderText: placeholderText,
@@ -208,21 +234,22 @@ var emptyPlaceholder = function emptyPlaceholder(_ref2) {
208
234
  pos: pos
209
235
  };
210
236
  };
211
- function createPlaceHolderStateFrom(_ref3) {
212
- var isInitial = _ref3.isInitial,
213
- isEditorFocused = _ref3.isEditorFocused,
214
- editorState = _ref3.editorState,
215
- isTypeAheadOpen = _ref3.isTypeAheadOpen,
216
- defaultPlaceholderText = _ref3.defaultPlaceholderText,
217
- intl = _ref3.intl,
218
- bracketPlaceholderText = _ref3.bracketPlaceholderText,
219
- emptyLinePlaceholder = _ref3.emptyLinePlaceholder,
220
- placeholderPrompts = _ref3.placeholderPrompts,
221
- typedAndDeleted = _ref3.typedAndDeleted,
222
- userHadTyped = _ref3.userHadTyped,
223
- isPlaceholderHidden = _ref3.isPlaceholderHidden,
224
- withEmptyParagraph = _ref3.withEmptyParagraph,
225
- showOnEmptyParagraph = _ref3.showOnEmptyParagraph;
237
+ function createPlaceHolderStateFrom(_ref5) {
238
+ var isInitial = _ref5.isInitial,
239
+ isEditorFocused = _ref5.isEditorFocused,
240
+ editorState = _ref5.editorState,
241
+ isTypeAheadOpen = _ref5.isTypeAheadOpen,
242
+ defaultPlaceholderText = _ref5.defaultPlaceholderText,
243
+ intl = _ref5.intl,
244
+ bracketPlaceholderText = _ref5.bracketPlaceholderText,
245
+ emptyLinePlaceholder = _ref5.emptyLinePlaceholder,
246
+ placeholderADF = _ref5.placeholderADF,
247
+ placeholderPrompts = _ref5.placeholderPrompts,
248
+ typedAndDeleted = _ref5.typedAndDeleted,
249
+ userHadTyped = _ref5.userHadTyped,
250
+ isPlaceholderHidden = _ref5.isPlaceholderHidden,
251
+ withEmptyParagraph = _ref5.withEmptyParagraph,
252
+ showOnEmptyParagraph = _ref5.showOnEmptyParagraph;
226
253
  if (isPlaceholderHidden && (0, _platformFeatureFlags.fg)('platform_editor_ai_aifc_patch_beta')) {
227
254
  return _objectSpread(_objectSpread({}, emptyPlaceholder({
228
255
  placeholderText: defaultPlaceholderText,
@@ -239,7 +266,7 @@ function createPlaceHolderStateFrom(_ref3) {
239
266
  userHadTyped: userHadTyped
240
267
  });
241
268
  }
242
- if ((defaultPlaceholderText || placeholderPrompts) && (0, _utils.isEmptyDocument)(editorState.doc)) {
269
+ if ((defaultPlaceholderText || placeholderPrompts || placeholderADF) && (0, _utils.isEmptyDocument)(editorState.doc)) {
243
270
  return setPlaceHolderState({
244
271
  placeholderText: defaultPlaceholderText,
245
272
  pos: 1,
@@ -248,12 +275,12 @@ function createPlaceHolderStateFrom(_ref3) {
248
275
  userHadTyped: userHadTyped
249
276
  });
250
277
  }
251
- if ((0, _platformFeatureFlags.fg)('platform_editor_ai_aifc_patch_beta_2')) {
278
+ if ((0, _platformFeatureFlags.fg)('platform_editor_ai_aifc_patch_beta_2') || (0, _platformFeatureFlags.fg)('platform_editor_ai_aifc_patch_ga')) {
252
279
  var _editorState$selectio = editorState.selection,
253
280
  from = _editorState$selectio.from,
254
281
  to = _editorState$selectio.to,
255
282
  $to = _editorState$selectio.$to;
256
- if (defaultPlaceholderText && withEmptyParagraph && isEditorFocused && !isInitial && !(0, _utils.isEmptyDocument)(editorState.doc) && from === to && (0, _utils.isEmptyParagraph)($to.parent) && (0, _utils.hasDocAsParent)($to)) {
283
+ if ((defaultPlaceholderText || placeholderADF) && withEmptyParagraph && isEditorFocused && !isInitial && !(0, _utils.isEmptyDocument)(editorState.doc) && from === to && (0, _utils.isEmptyParagraph)($to.parent) && (0, _utils.hasDocAsParent)($to)) {
257
284
  return showOnEmptyParagraph ? setPlaceHolderState({
258
285
  placeholderText: defaultPlaceholderText,
259
286
  pos: to,
@@ -314,7 +341,8 @@ function createPlaceHolderStateFrom(_ref3) {
314
341
  var isFirstCell = (table === null || table === void 0 || (_table$node$firstChil = table.node.firstChild) === null || _table$node$firstChil === void 0 ? void 0 : _table$node$firstChil.content.firstChild) === parentNode;
315
342
  if (isFirstCell) {
316
343
  return setPlaceHolderState({
317
- placeholderText: intl.formatMessage(_messages.placeholderTextMessages.shortEmptyNodePlaceholderText),
344
+ placeholderText: !(0, _platformFeatureFlags.fg)('platform_editor_ai_aifc_patch_ga') ? intl.formatMessage(_messages.placeholderTextMessages.shortEmptyNodePlaceholderText) : undefined,
345
+ contextPlaceholderADF: (0, _platformFeatureFlags.fg)('platform_editor_ai_aifc_patch_ga') ? createShortEmptyNodePlaceholderADF(intl) : undefined,
318
346
  pos: $from.pos,
319
347
  placeholderPrompts: placeholderPrompts,
320
348
  typedAndDeleted: typedAndDeleted,
@@ -324,7 +352,8 @@ function createPlaceHolderStateFrom(_ref3) {
324
352
  }
325
353
  if (nodeTypesWithLongPlaceholderText.includes(parentType) && isEmptyNode) {
326
354
  return setPlaceHolderState({
327
- placeholderText: intl.formatMessage(_messages.placeholderTextMessages.longEmptyNodePlaceholderText),
355
+ placeholderText: !(0, _platformFeatureFlags.fg)('platform_editor_ai_aifc_patch_ga') ? intl.formatMessage(_messages.placeholderTextMessages.longEmptyNodePlaceholderText) : undefined,
356
+ contextPlaceholderADF: (0, _platformFeatureFlags.fg)('platform_editor_ai_aifc_patch_ga') ? createLongEmptyNodePlaceholderADF(intl) : undefined,
328
357
  pos: $from.pos,
329
358
  placeholderPrompts: placeholderPrompts,
330
359
  typedAndDeleted: typedAndDeleted,
@@ -364,10 +393,10 @@ function createPlaceHolderStateFrom(_ref3) {
364
393
  userHadTyped: userHadTyped
365
394
  });
366
395
  }
367
- function calculateUserInteractionState(_ref4) {
368
- var placeholderState = _ref4.placeholderState,
369
- oldEditorState = _ref4.oldEditorState,
370
- newEditorState = _ref4.newEditorState;
396
+ function calculateUserInteractionState(_ref6) {
397
+ var placeholderState = _ref6.placeholderState,
398
+ oldEditorState = _ref6.oldEditorState,
399
+ newEditorState = _ref6.newEditorState;
371
400
  var wasEmpty = oldEditorState ? (0, _utils.isEmptyDocument)(oldEditorState.doc) : true;
372
401
  var isEmpty = (0, _utils.isEmptyDocument)(newEditorState.doc);
373
402
  var hasEverTyped = Boolean(placeholderState === null || placeholderState === void 0 ? void 0 : placeholderState.userHadTyped) ||
@@ -409,6 +438,7 @@ function createPlugin(intl, defaultPlaceholderText, bracketPlaceholderText, empt
409
438
  defaultPlaceholderText: defaultPlaceholderText,
410
439
  bracketPlaceholderText: bracketPlaceholderText,
411
440
  emptyLinePlaceholder: emptyLinePlaceholder,
441
+ placeholderADF: placeholderADF,
412
442
  placeholderPrompts: placeholderPrompts,
413
443
  typedAndDeleted: false,
414
444
  userHadTyped: false,
@@ -416,7 +446,7 @@ function createPlugin(intl, defaultPlaceholderText, bracketPlaceholderText, empt
416
446
  });
417
447
  },
418
448
  apply: function apply(tr, placeholderState, _oldEditorState, newEditorState) {
419
- var _api$focus2, _placeholderState$isP, _api$typeAhead2, _ref5, _meta$placeholderText, _ref6, _meta$placeholderProm, _meta$showOnEmptyPara;
449
+ var _api$focus2, _placeholderState$isP, _api$typeAhead2, _ref7, _meta$placeholderText, _ref8, _meta$placeholderProm, _meta$showOnEmptyPara;
420
450
  var meta = tr.getMeta(pluginKey);
421
451
  var isEditorFocused = Boolean(api === null || api === void 0 || (_api$focus2 = api.focus) === null || _api$focus2 === void 0 || (_api$focus2 = _api$focus2.sharedState.currentState()) === null || _api$focus2 === void 0 ? void 0 : _api$focus2.hasFocus);
422
452
  var _calculateUserInterac = calculateUserInteractionState({
@@ -430,17 +460,21 @@ function createPlugin(intl, defaultPlaceholderText, bracketPlaceholderText, empt
430
460
  if ((meta === null || meta === void 0 ? void 0 : meta.isPlaceholderHidden) !== undefined && (0, _platformFeatureFlags.fg)('platform_editor_ai_aifc_patch_beta')) {
431
461
  isPlaceholderHidden = meta.isPlaceholderHidden;
432
462
  }
433
- if ((meta === null || meta === void 0 ? void 0 : meta.placeholderText) !== undefined && (0, _platformFeatureFlags.fg)('platform_editor_ai_aifc_patch_beta_2')) {
434
- defaultPlaceholderText = meta.placeholderText;
463
+ if ((meta === null || meta === void 0 ? void 0 : meta.placeholderText) !== undefined && ((0, _platformFeatureFlags.fg)('platform_editor_ai_aifc_patch_beta_2') || (0, _platformFeatureFlags.fg)('platform_editor_ai_aifc_patch_ga'))) {
464
+ // Only update defaultPlaceholderText from meta if we're not using ADF placeholder
465
+ if (!((0, _platformFeatureFlags.fg)('platform_editor_ai_aifc_patch_ga') && placeholderADF)) {
466
+ defaultPlaceholderText = meta.placeholderText;
467
+ }
435
468
  }
436
469
  var newPlaceholderState = createPlaceHolderStateFrom({
437
470
  isEditorFocused: isEditorFocused,
438
471
  editorState: newEditorState,
439
472
  isTypeAheadOpen: api === null || api === void 0 || (_api$typeAhead2 = api.typeAhead) === null || _api$typeAhead2 === void 0 ? void 0 : _api$typeAhead2.actions.isOpen,
440
- defaultPlaceholderText: (0, _platformFeatureFlags.fg)('platform_editor_ai_aifc_patch_beta_2') ? defaultPlaceholderText : (_ref5 = (_meta$placeholderText = meta === null || meta === void 0 ? void 0 : meta.placeholderText) !== null && _meta$placeholderText !== void 0 ? _meta$placeholderText : placeholderState === null || placeholderState === void 0 ? void 0 : placeholderState.placeholderText) !== null && _ref5 !== void 0 ? _ref5 : defaultPlaceholderText,
473
+ defaultPlaceholderText: (0, _platformFeatureFlags.fg)('platform_editor_ai_aifc_patch_beta_2') || (0, _platformFeatureFlags.fg)('platform_editor_ai_aifc_patch_ga') ? defaultPlaceholderText : (_ref7 = (_meta$placeholderText = meta === null || meta === void 0 ? void 0 : meta.placeholderText) !== null && _meta$placeholderText !== void 0 ? _meta$placeholderText : placeholderState === null || placeholderState === void 0 ? void 0 : placeholderState.placeholderText) !== null && _ref7 !== void 0 ? _ref7 : defaultPlaceholderText,
441
474
  bracketPlaceholderText: bracketPlaceholderText,
442
475
  emptyLinePlaceholder: emptyLinePlaceholder,
443
- placeholderPrompts: (_ref6 = (_meta$placeholderProm = meta === null || meta === void 0 ? void 0 : meta.placeholderPrompts) !== null && _meta$placeholderProm !== void 0 ? _meta$placeholderProm : placeholderState === null || placeholderState === void 0 ? void 0 : placeholderState.placeholderPrompts) !== null && _ref6 !== void 0 ? _ref6 : placeholderPrompts,
476
+ placeholderADF: placeholderADF,
477
+ placeholderPrompts: (_ref8 = (_meta$placeholderProm = meta === null || meta === void 0 ? void 0 : meta.placeholderPrompts) !== null && _meta$placeholderProm !== void 0 ? _meta$placeholderProm : placeholderState === null || placeholderState === void 0 ? void 0 : placeholderState.placeholderPrompts) !== null && _ref8 !== void 0 ? _ref8 : placeholderPrompts,
444
478
  typedAndDeleted: typedAndDeleted,
445
479
  userHadTyped: userHadTyped,
446
480
  intl: intl,
@@ -463,7 +497,8 @@ function createPlugin(intl, defaultPlaceholderText, bracketPlaceholderText, empt
463
497
  hasPlaceholder = _getPlaceholderState.hasPlaceholder,
464
498
  placeholderText = _getPlaceholderState.placeholderText,
465
499
  pos = _getPlaceholderState.pos,
466
- typedAndDeleted = _getPlaceholderState.typedAndDeleted;
500
+ typedAndDeleted = _getPlaceholderState.typedAndDeleted,
501
+ contextPlaceholderADF = _getPlaceholderState.contextPlaceholderADF;
467
502
 
468
503
  // Decorations is still called after plugin is destroyed
469
504
  // So we need to make sure decorations is not called if plugin has been destroyed to prevent the placeholder animations' setTimeouts called infinitely
@@ -472,9 +507,11 @@ function createPlugin(intl, defaultPlaceholderText, bracketPlaceholderText, empt
472
507
  }
473
508
  var compositionPluginState = api === null || api === void 0 || (_api$composition = api.composition) === null || _api$composition === void 0 ? void 0 : _api$composition.sharedState.currentState();
474
509
  var isShowingDiff = Boolean(api === null || api === void 0 || (_api$showDiff = api.showDiff) === null || _api$showDiff === void 0 || (_api$showDiff = _api$showDiff.sharedState.currentState()) === null || _api$showDiff === void 0 ? void 0 : _api$showDiff.isDisplayingChanges);
475
- if (hasPlaceholder && ((placeholderText !== null && placeholderText !== void 0 ? placeholderText : '') || placeholderPrompts || placeholderADF) && pos !== undefined && !(compositionPluginState !== null && compositionPluginState !== void 0 && compositionPluginState.isComposing) && !isShowingDiff) {
510
+ if (hasPlaceholder && ((placeholderText !== null && placeholderText !== void 0 ? placeholderText : '') || placeholderPrompts || placeholderADF || contextPlaceholderADF) && pos !== undefined && !(compositionPluginState !== null && compositionPluginState !== void 0 && compositionPluginState.isComposing) && !isShowingDiff) {
476
511
  var initialDelayWhenUserTypedAndDeleted = typedAndDeleted ? TYPEWRITER_TYPED_AND_DELETED_DELAY : 0;
477
- return createPlaceholderDecoration(editorState, placeholderText !== null && placeholderText !== void 0 ? placeholderText : '', placeholderPrompts, activeTypewriterTimeouts, pos, initialDelayWhenUserTypedAndDeleted, placeholderADF);
512
+ // contextPlaceholderADF takes precedence over the global placeholderADF
513
+ var placeholderAdfToUse = contextPlaceholderADF || placeholderADF;
514
+ return createPlaceholderDecoration(editorState, placeholderText !== null && placeholderText !== void 0 ? placeholderText : '', placeholderPrompts, activeTypewriterTimeouts, pos, initialDelayWhenUserTypedAndDeleted, placeholderAdfToUse);
478
515
  }
479
516
  return;
480
517
  }
@@ -500,7 +537,7 @@ function createPlugin(intl, defaultPlaceholderText, bracketPlaceholderText, empt
500
537
  }
501
538
  return {
502
539
  update: function update(editorView, prevState) {
503
- if ((0, _platformFeatureFlags.fg)('platform_editor_ai_aifc_patch_beta_2')) {
540
+ if ((0, _platformFeatureFlags.fg)('platform_editor_ai_aifc_patch_beta_2') || (0, _platformFeatureFlags.fg)('platform_editor_ai_aifc_patch_ga')) {
504
541
  var prevPluginState = getPlaceholderState(prevState);
505
542
  var newPluginState = getPlaceholderState(editorView.state);
506
543
 
@@ -531,16 +568,16 @@ function createPlugin(intl, defaultPlaceholderText, bracketPlaceholderText, empt
531
568
  }
532
569
  });
533
570
  }
534
- var placeholderPlugin = exports.placeholderPlugin = function placeholderPlugin(_ref7) {
535
- var options = _ref7.config,
536
- api = _ref7.api;
571
+ var placeholderPlugin = exports.placeholderPlugin = function placeholderPlugin(_ref9) {
572
+ var options = _ref9.config,
573
+ api = _ref9.api;
537
574
  var currentPlaceholder = options === null || options === void 0 ? void 0 : options.placeholder;
538
575
  return {
539
576
  name: 'placeholder',
540
577
  commands: {
541
578
  setPlaceholder: function setPlaceholder(placeholderText) {
542
- return function (_ref8) {
543
- var tr = _ref8.tr;
579
+ return function (_ref0) {
580
+ var tr = _ref0.tr;
544
581
  if (currentPlaceholder !== placeholderText) {
545
582
  currentPlaceholder = placeholderText;
546
583
  return tr.setMeta(pluginKey, {
@@ -551,16 +588,16 @@ var placeholderPlugin = exports.placeholderPlugin = function placeholderPlugin(_
551
588
  };
552
589
  },
553
590
  setAnimatingPlaceholderPrompts: function setAnimatingPlaceholderPrompts(placeholderPrompts) {
554
- return function (_ref9) {
555
- var tr = _ref9.tr;
591
+ return function (_ref1) {
592
+ var tr = _ref1.tr;
556
593
  return tr.setMeta(pluginKey, {
557
594
  placeholderPrompts: placeholderPrompts
558
595
  });
559
596
  };
560
597
  },
561
598
  setPlaceholderHidden: function setPlaceholderHidden(isPlaceholderHidden) {
562
- return function (_ref0) {
563
- var tr = _ref0.tr;
599
+ return function (_ref10) {
600
+ var tr = _ref10.tr;
564
601
  return tr.setMeta(pluginKey, {
565
602
  isPlaceholderHidden: isPlaceholderHidden
566
603
  });
@@ -570,8 +607,8 @@ var placeholderPlugin = exports.placeholderPlugin = function placeholderPlugin(_
570
607
  pmPlugins: function pmPlugins() {
571
608
  return [{
572
609
  name: 'placeholder',
573
- plugin: function plugin(_ref1) {
574
- var getIntl = _ref1.getIntl;
610
+ plugin: function plugin(_ref11) {
611
+ var getIntl = _ref11.getIntl;
575
612
  return createPlugin(getIntl(), options && options.placeholder, options && options.placeholderBracketHint, options && options.emptyLinePlaceholder, options && options.placeholderPrompts, options === null || options === void 0 ? void 0 : options.withEmptyParagraph, options && options.placeholderADF, api);
576
613
  }
577
614
  }];
@@ -1,3 +1,4 @@
1
+ import { code, text } from '@atlaskit/adf-utils/builders';
1
2
  import { placeholderTextMessages as messages } from '@atlaskit/editor-common/messages';
2
3
  import { processRawValue } from '@atlaskit/editor-common/process-raw-value';
3
4
  import { SafePlugin } from '@atlaskit/editor-common/safe-plugin';
@@ -26,6 +27,26 @@ function getPlaceholderState(editorState) {
26
27
  const nodeTypesWithLongPlaceholderText = ['expand', 'panel'];
27
28
  const nodeTypesWithShortPlaceholderText = ['tableCell', 'tableHeader'];
28
29
  const nodeTypesWithSyncBlockPlaceholderText = ['bodiedSyncBlock'];
30
+ const createShortEmptyNodePlaceholderADF = ({
31
+ formatMessage
32
+ }) => ({
33
+ version: 1,
34
+ type: 'doc',
35
+ content: [{
36
+ type: 'paragraph',
37
+ content: [code(formatMessage(messages.shortEmptyNodePlaceholderADFSlashShortcut)), text(' '), text(formatMessage(messages.shortEmptyNodePlaceholderADFSuffix))]
38
+ }]
39
+ });
40
+ const createLongEmptyNodePlaceholderADF = ({
41
+ formatMessage
42
+ }) => ({
43
+ version: 1,
44
+ type: 'doc',
45
+ content: [{
46
+ type: 'paragraph',
47
+ content: [text(formatMessage(messages.longEmptyNodePlaceholderADFPrefix)), text(' '), code(formatMessage(messages.longEmptyNodePlaceholderADFSlashShortcut)), text(' '), text(formatMessage(messages.longEmptyNodePlaceholderADFSuffix))]
48
+ }]
49
+ });
29
50
  const cycleThroughPlaceholderPrompts = (placeholderPrompts, activeTypewriterTimeouts, placeholderNodeWithText, initialDelayWhenUserTypedAndDeleted = 0) => {
30
51
  let currentPromptIndex = 0;
31
52
  let displayedText = '';
@@ -79,6 +100,7 @@ export function createPlaceholderDecoration(editorState, placeholderText, placeh
79
100
  let placeholderNodeWithText = placeholderDecoration;
80
101
  placeholderDecoration.setAttribute('data-testid', placeholderTestId);
81
102
  placeholderDecoration.className = 'placeholder-decoration';
103
+ placeholderDecoration.setAttribute('aria-hidden', 'true');
82
104
 
83
105
  // PM sets contenteditable to false on Decorations so Firefox doesn't display the flashing cursor
84
106
  // So adding an extra span which will contain the placeholder text
@@ -88,7 +110,9 @@ export function createPlaceholderDecoration(editorState, placeholderText, placeh
88
110
  placeholderDecoration.appendChild(placeholderNode);
89
111
  placeholderNodeWithText = placeholderNode;
90
112
  }
91
- if (placeholderADF) {
113
+ if (placeholderText) {
114
+ placeholderNodeWithText.textContent = placeholderText || ' ';
115
+ } else if (placeholderADF) {
92
116
  const serializer = DOMSerializer.fromSchema(editorState.schema);
93
117
  // Get a PMNode from docnode
94
118
  const docNode = processRawValue(editorState.schema, placeholderADF);
@@ -124,8 +148,6 @@ export function createPlaceholderDecoration(editorState, placeholderText, placeh
124
148
  }
125
149
  });
126
150
  }
127
- } else if (placeholderText) {
128
- placeholderNodeWithText.textContent = placeholderText || ' ';
129
151
  } else if (placeholderPrompts) {
130
152
  cycleThroughPlaceholderPrompts(placeholderPrompts, activeTypewriterTimeouts, placeholderNodeWithText, initialDelayWhenUserTypedAndDeleted);
131
153
  }
@@ -159,12 +181,14 @@ function setPlaceHolderState({
159
181
  typedAndDeleted,
160
182
  userHadTyped,
161
183
  canShowOnEmptyParagraph,
162
- showOnEmptyParagraph
184
+ showOnEmptyParagraph,
185
+ contextPlaceholderADF
163
186
  }) {
164
187
  return {
165
188
  hasPlaceholder: true,
166
189
  placeholderText,
167
190
  placeholderPrompts,
191
+ contextPlaceholderADF,
168
192
  pos: pos ? pos : 1,
169
193
  typedAndDeleted,
170
194
  userHadTyped,
@@ -198,6 +222,7 @@ function createPlaceHolderStateFrom({
198
222
  intl,
199
223
  bracketPlaceholderText,
200
224
  emptyLinePlaceholder,
225
+ placeholderADF,
201
226
  placeholderPrompts,
202
227
  typedAndDeleted,
203
228
  userHadTyped,
@@ -222,7 +247,7 @@ function createPlaceHolderStateFrom({
222
247
  userHadTyped
223
248
  });
224
249
  }
225
- if ((defaultPlaceholderText || placeholderPrompts) && isEmptyDocument(editorState.doc)) {
250
+ if ((defaultPlaceholderText || placeholderPrompts || placeholderADF) && isEmptyDocument(editorState.doc)) {
226
251
  return setPlaceHolderState({
227
252
  placeholderText: defaultPlaceholderText,
228
253
  pos: 1,
@@ -231,13 +256,13 @@ function createPlaceHolderStateFrom({
231
256
  userHadTyped
232
257
  });
233
258
  }
234
- if (fg('platform_editor_ai_aifc_patch_beta_2')) {
259
+ if (fg('platform_editor_ai_aifc_patch_beta_2') || fg('platform_editor_ai_aifc_patch_ga')) {
235
260
  const {
236
261
  from,
237
262
  to,
238
263
  $to
239
264
  } = editorState.selection;
240
- if (defaultPlaceholderText && withEmptyParagraph && isEditorFocused && !isInitial && !isEmptyDocument(editorState.doc) && from === to && isEmptyParagraph($to.parent) && hasDocAsParent($to)) {
265
+ if ((defaultPlaceholderText || placeholderADF) && withEmptyParagraph && isEditorFocused && !isInitial && !isEmptyDocument(editorState.doc) && from === to && isEmptyParagraph($to.parent) && hasDocAsParent($to)) {
241
266
  return showOnEmptyParagraph ? setPlaceHolderState({
242
267
  placeholderText: defaultPlaceholderText,
243
268
  pos: to,
@@ -297,7 +322,8 @@ function createPlaceHolderStateFrom({
297
322
  const isFirstCell = (table === null || table === void 0 ? void 0 : (_table$node$firstChil = table.node.firstChild) === null || _table$node$firstChil === void 0 ? void 0 : _table$node$firstChil.content.firstChild) === parentNode;
298
323
  if (isFirstCell) {
299
324
  return setPlaceHolderState({
300
- placeholderText: intl.formatMessage(messages.shortEmptyNodePlaceholderText),
325
+ placeholderText: !fg('platform_editor_ai_aifc_patch_ga') ? intl.formatMessage(messages.shortEmptyNodePlaceholderText) : undefined,
326
+ contextPlaceholderADF: fg('platform_editor_ai_aifc_patch_ga') ? createShortEmptyNodePlaceholderADF(intl) : undefined,
301
327
  pos: $from.pos,
302
328
  placeholderPrompts,
303
329
  typedAndDeleted,
@@ -307,7 +333,8 @@ function createPlaceHolderStateFrom({
307
333
  }
308
334
  if (nodeTypesWithLongPlaceholderText.includes(parentType) && isEmptyNode) {
309
335
  return setPlaceHolderState({
310
- placeholderText: intl.formatMessage(messages.longEmptyNodePlaceholderText),
336
+ placeholderText: !fg('platform_editor_ai_aifc_patch_ga') ? intl.formatMessage(messages.longEmptyNodePlaceholderText) : undefined,
337
+ contextPlaceholderADF: fg('platform_editor_ai_aifc_patch_ga') ? createLongEmptyNodePlaceholderADF(intl) : undefined,
311
338
  pos: $from.pos,
312
339
  placeholderPrompts,
313
340
  typedAndDeleted,
@@ -393,6 +420,7 @@ export function createPlugin(intl, defaultPlaceholderText, bracketPlaceholderTex
393
420
  defaultPlaceholderText,
394
421
  bracketPlaceholderText,
395
422
  emptyLinePlaceholder,
423
+ placeholderADF,
396
424
  placeholderPrompts,
397
425
  typedAndDeleted: false,
398
426
  userHadTyped: false,
@@ -415,16 +443,20 @@ export function createPlugin(intl, defaultPlaceholderText, bracketPlaceholderTex
415
443
  if ((meta === null || meta === void 0 ? void 0 : meta.isPlaceholderHidden) !== undefined && fg('platform_editor_ai_aifc_patch_beta')) {
416
444
  isPlaceholderHidden = meta.isPlaceholderHidden;
417
445
  }
418
- if ((meta === null || meta === void 0 ? void 0 : meta.placeholderText) !== undefined && fg('platform_editor_ai_aifc_patch_beta_2')) {
419
- defaultPlaceholderText = meta.placeholderText;
446
+ if ((meta === null || meta === void 0 ? void 0 : meta.placeholderText) !== undefined && (fg('platform_editor_ai_aifc_patch_beta_2') || fg('platform_editor_ai_aifc_patch_ga'))) {
447
+ // Only update defaultPlaceholderText from meta if we're not using ADF placeholder
448
+ if (!(fg('platform_editor_ai_aifc_patch_ga') && placeholderADF)) {
449
+ defaultPlaceholderText = meta.placeholderText;
450
+ }
420
451
  }
421
452
  const newPlaceholderState = createPlaceHolderStateFrom({
422
453
  isEditorFocused,
423
454
  editorState: newEditorState,
424
455
  isTypeAheadOpen: api === null || api === void 0 ? void 0 : (_api$typeAhead2 = api.typeAhead) === null || _api$typeAhead2 === void 0 ? void 0 : _api$typeAhead2.actions.isOpen,
425
- defaultPlaceholderText: fg('platform_editor_ai_aifc_patch_beta_2') ? defaultPlaceholderText : (_ref = (_meta$placeholderText = meta === null || meta === void 0 ? void 0 : meta.placeholderText) !== null && _meta$placeholderText !== void 0 ? _meta$placeholderText : placeholderState === null || placeholderState === void 0 ? void 0 : placeholderState.placeholderText) !== null && _ref !== void 0 ? _ref : defaultPlaceholderText,
456
+ defaultPlaceholderText: fg('platform_editor_ai_aifc_patch_beta_2') || fg('platform_editor_ai_aifc_patch_ga') ? defaultPlaceholderText : (_ref = (_meta$placeholderText = meta === null || meta === void 0 ? void 0 : meta.placeholderText) !== null && _meta$placeholderText !== void 0 ? _meta$placeholderText : placeholderState === null || placeholderState === void 0 ? void 0 : placeholderState.placeholderText) !== null && _ref !== void 0 ? _ref : defaultPlaceholderText,
426
457
  bracketPlaceholderText,
427
458
  emptyLinePlaceholder,
459
+ placeholderADF,
428
460
  placeholderPrompts: (_ref2 = (_meta$placeholderProm = meta === null || meta === void 0 ? void 0 : meta.placeholderPrompts) !== null && _meta$placeholderProm !== void 0 ? _meta$placeholderProm : placeholderState === null || placeholderState === void 0 ? void 0 : placeholderState.placeholderPrompts) !== null && _ref2 !== void 0 ? _ref2 : placeholderPrompts,
429
461
  typedAndDeleted,
430
462
  userHadTyped,
@@ -448,7 +480,8 @@ export function createPlugin(intl, defaultPlaceholderText, bracketPlaceholderTex
448
480
  hasPlaceholder,
449
481
  placeholderText,
450
482
  pos,
451
- typedAndDeleted
483
+ typedAndDeleted,
484
+ contextPlaceholderADF
452
485
  } = getPlaceholderState(editorState);
453
486
 
454
487
  // Decorations is still called after plugin is destroyed
@@ -458,9 +491,11 @@ export function createPlugin(intl, defaultPlaceholderText, bracketPlaceholderTex
458
491
  }
459
492
  const compositionPluginState = api === null || api === void 0 ? void 0 : (_api$composition = api.composition) === null || _api$composition === void 0 ? void 0 : _api$composition.sharedState.currentState();
460
493
  const isShowingDiff = Boolean(api === null || api === void 0 ? void 0 : (_api$showDiff = api.showDiff) === null || _api$showDiff === void 0 ? void 0 : (_api$showDiff$sharedS = _api$showDiff.sharedState.currentState()) === null || _api$showDiff$sharedS === void 0 ? void 0 : _api$showDiff$sharedS.isDisplayingChanges);
461
- if (hasPlaceholder && ((placeholderText !== null && placeholderText !== void 0 ? placeholderText : '') || placeholderPrompts || placeholderADF) && pos !== undefined && !(compositionPluginState !== null && compositionPluginState !== void 0 && compositionPluginState.isComposing) && !isShowingDiff) {
494
+ if (hasPlaceholder && ((placeholderText !== null && placeholderText !== void 0 ? placeholderText : '') || placeholderPrompts || placeholderADF || contextPlaceholderADF) && pos !== undefined && !(compositionPluginState !== null && compositionPluginState !== void 0 && compositionPluginState.isComposing) && !isShowingDiff) {
462
495
  const initialDelayWhenUserTypedAndDeleted = typedAndDeleted ? TYPEWRITER_TYPED_AND_DELETED_DELAY : 0;
463
- return createPlaceholderDecoration(editorState, placeholderText !== null && placeholderText !== void 0 ? placeholderText : '', placeholderPrompts, activeTypewriterTimeouts, pos, initialDelayWhenUserTypedAndDeleted, placeholderADF);
496
+ // contextPlaceholderADF takes precedence over the global placeholderADF
497
+ const placeholderAdfToUse = contextPlaceholderADF || placeholderADF;
498
+ return createPlaceholderDecoration(editorState, placeholderText !== null && placeholderText !== void 0 ? placeholderText : '', placeholderPrompts, activeTypewriterTimeouts, pos, initialDelayWhenUserTypedAndDeleted, placeholderAdfToUse);
464
499
  }
465
500
  return;
466
501
  }
@@ -486,7 +521,7 @@ export function createPlugin(intl, defaultPlaceholderText, bracketPlaceholderTex
486
521
  }
487
522
  return {
488
523
  update(editorView, prevState) {
489
- if (fg('platform_editor_ai_aifc_patch_beta_2')) {
524
+ if (fg('platform_editor_ai_aifc_patch_beta_2') || fg('platform_editor_ai_aifc_patch_ga')) {
490
525
  const prevPluginState = getPlaceholderState(prevState);
491
526
  const newPluginState = getPlaceholderState(editorView.state);
492
527
 
@@ -1,6 +1,7 @@
1
1
  import _defineProperty from "@babel/runtime/helpers/defineProperty";
2
2
  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; }
3
3
  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; }
4
+ import { code, text } from '@atlaskit/adf-utils/builders';
4
5
  import { placeholderTextMessages as messages } from '@atlaskit/editor-common/messages';
5
6
  import { processRawValue } from '@atlaskit/editor-common/process-raw-value';
6
7
  import { SafePlugin } from '@atlaskit/editor-common/safe-plugin';
@@ -29,6 +30,28 @@ function getPlaceholderState(editorState) {
29
30
  var nodeTypesWithLongPlaceholderText = ['expand', 'panel'];
30
31
  var nodeTypesWithShortPlaceholderText = ['tableCell', 'tableHeader'];
31
32
  var nodeTypesWithSyncBlockPlaceholderText = ['bodiedSyncBlock'];
33
+ var createShortEmptyNodePlaceholderADF = function createShortEmptyNodePlaceholderADF(_ref) {
34
+ var formatMessage = _ref.formatMessage;
35
+ return {
36
+ version: 1,
37
+ type: 'doc',
38
+ content: [{
39
+ type: 'paragraph',
40
+ content: [code(formatMessage(messages.shortEmptyNodePlaceholderADFSlashShortcut)), text(' '), text(formatMessage(messages.shortEmptyNodePlaceholderADFSuffix))]
41
+ }]
42
+ };
43
+ };
44
+ var createLongEmptyNodePlaceholderADF = function createLongEmptyNodePlaceholderADF(_ref2) {
45
+ var formatMessage = _ref2.formatMessage;
46
+ return {
47
+ version: 1,
48
+ type: 'doc',
49
+ content: [{
50
+ type: 'paragraph',
51
+ content: [text(formatMessage(messages.longEmptyNodePlaceholderADFPrefix)), text(' '), code(formatMessage(messages.longEmptyNodePlaceholderADFSlashShortcut)), text(' '), text(formatMessage(messages.longEmptyNodePlaceholderADFSuffix))]
52
+ }]
53
+ };
54
+ };
32
55
  var cycleThroughPlaceholderPrompts = function cycleThroughPlaceholderPrompts(placeholderPrompts, activeTypewriterTimeouts, placeholderNodeWithText) {
33
56
  var initialDelayWhenUserTypedAndDeleted = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : 0;
34
57
  var currentPromptIndex = 0;
@@ -88,6 +111,7 @@ export function createPlaceholderDecoration(editorState, placeholderText, placeh
88
111
  var placeholderNodeWithText = placeholderDecoration;
89
112
  placeholderDecoration.setAttribute('data-testid', placeholderTestId);
90
113
  placeholderDecoration.className = 'placeholder-decoration';
114
+ placeholderDecoration.setAttribute('aria-hidden', 'true');
91
115
 
92
116
  // PM sets contenteditable to false on Decorations so Firefox doesn't display the flashing cursor
93
117
  // So adding an extra span which will contain the placeholder text
@@ -97,7 +121,9 @@ export function createPlaceholderDecoration(editorState, placeholderText, placeh
97
121
  placeholderDecoration.appendChild(placeholderNode);
98
122
  placeholderNodeWithText = placeholderNode;
99
123
  }
100
- if (placeholderADF) {
124
+ if (placeholderText) {
125
+ placeholderNodeWithText.textContent = placeholderText || ' ';
126
+ } else if (placeholderADF) {
101
127
  var serializer = DOMSerializer.fromSchema(editorState.schema);
102
128
  // Get a PMNode from docnode
103
129
  var docNode = processRawValue(editorState.schema, placeholderADF);
@@ -133,8 +159,6 @@ export function createPlaceholderDecoration(editorState, placeholderText, placeh
133
159
  }
134
160
  });
135
161
  }
136
- } else if (placeholderText) {
137
- placeholderNodeWithText.textContent = placeholderText || ' ';
138
162
  } else if (placeholderPrompts) {
139
163
  cycleThroughPlaceholderPrompts(placeholderPrompts, activeTypewriterTimeouts, placeholderNodeWithText, initialDelayWhenUserTypedAndDeleted);
140
164
  }
@@ -161,18 +185,20 @@ export function createPlaceholderDecoration(editorState, placeholderText, placeh
161
185
  key: "placeholder ".concat(placeholderText)
162
186
  })]);
163
187
  }
164
- function setPlaceHolderState(_ref) {
165
- var placeholderText = _ref.placeholderText,
166
- pos = _ref.pos,
167
- placeholderPrompts = _ref.placeholderPrompts,
168
- typedAndDeleted = _ref.typedAndDeleted,
169
- userHadTyped = _ref.userHadTyped,
170
- canShowOnEmptyParagraph = _ref.canShowOnEmptyParagraph,
171
- showOnEmptyParagraph = _ref.showOnEmptyParagraph;
188
+ function setPlaceHolderState(_ref3) {
189
+ var placeholderText = _ref3.placeholderText,
190
+ pos = _ref3.pos,
191
+ placeholderPrompts = _ref3.placeholderPrompts,
192
+ typedAndDeleted = _ref3.typedAndDeleted,
193
+ userHadTyped = _ref3.userHadTyped,
194
+ canShowOnEmptyParagraph = _ref3.canShowOnEmptyParagraph,
195
+ showOnEmptyParagraph = _ref3.showOnEmptyParagraph,
196
+ contextPlaceholderADF = _ref3.contextPlaceholderADF;
172
197
  return {
173
198
  hasPlaceholder: true,
174
199
  placeholderText: placeholderText,
175
200
  placeholderPrompts: placeholderPrompts,
201
+ contextPlaceholderADF: contextPlaceholderADF,
176
202
  pos: pos ? pos : 1,
177
203
  typedAndDeleted: typedAndDeleted,
178
204
  userHadTyped: userHadTyped,
@@ -180,13 +206,13 @@ function setPlaceHolderState(_ref) {
180
206
  showOnEmptyParagraph: showOnEmptyParagraph
181
207
  };
182
208
  }
183
- var emptyPlaceholder = function emptyPlaceholder(_ref2) {
184
- var placeholderText = _ref2.placeholderText,
185
- placeholderPrompts = _ref2.placeholderPrompts,
186
- userHadTyped = _ref2.userHadTyped,
187
- pos = _ref2.pos,
188
- canShowOnEmptyParagraph = _ref2.canShowOnEmptyParagraph,
189
- showOnEmptyParagraph = _ref2.showOnEmptyParagraph;
209
+ var emptyPlaceholder = function emptyPlaceholder(_ref4) {
210
+ var placeholderText = _ref4.placeholderText,
211
+ placeholderPrompts = _ref4.placeholderPrompts,
212
+ userHadTyped = _ref4.userHadTyped,
213
+ pos = _ref4.pos,
214
+ canShowOnEmptyParagraph = _ref4.canShowOnEmptyParagraph,
215
+ showOnEmptyParagraph = _ref4.showOnEmptyParagraph;
190
216
  return {
191
217
  hasPlaceholder: false,
192
218
  placeholderText: placeholderText,
@@ -198,21 +224,22 @@ var emptyPlaceholder = function emptyPlaceholder(_ref2) {
198
224
  pos: pos
199
225
  };
200
226
  };
201
- function createPlaceHolderStateFrom(_ref3) {
202
- var isInitial = _ref3.isInitial,
203
- isEditorFocused = _ref3.isEditorFocused,
204
- editorState = _ref3.editorState,
205
- isTypeAheadOpen = _ref3.isTypeAheadOpen,
206
- defaultPlaceholderText = _ref3.defaultPlaceholderText,
207
- intl = _ref3.intl,
208
- bracketPlaceholderText = _ref3.bracketPlaceholderText,
209
- emptyLinePlaceholder = _ref3.emptyLinePlaceholder,
210
- placeholderPrompts = _ref3.placeholderPrompts,
211
- typedAndDeleted = _ref3.typedAndDeleted,
212
- userHadTyped = _ref3.userHadTyped,
213
- isPlaceholderHidden = _ref3.isPlaceholderHidden,
214
- withEmptyParagraph = _ref3.withEmptyParagraph,
215
- showOnEmptyParagraph = _ref3.showOnEmptyParagraph;
227
+ function createPlaceHolderStateFrom(_ref5) {
228
+ var isInitial = _ref5.isInitial,
229
+ isEditorFocused = _ref5.isEditorFocused,
230
+ editorState = _ref5.editorState,
231
+ isTypeAheadOpen = _ref5.isTypeAheadOpen,
232
+ defaultPlaceholderText = _ref5.defaultPlaceholderText,
233
+ intl = _ref5.intl,
234
+ bracketPlaceholderText = _ref5.bracketPlaceholderText,
235
+ emptyLinePlaceholder = _ref5.emptyLinePlaceholder,
236
+ placeholderADF = _ref5.placeholderADF,
237
+ placeholderPrompts = _ref5.placeholderPrompts,
238
+ typedAndDeleted = _ref5.typedAndDeleted,
239
+ userHadTyped = _ref5.userHadTyped,
240
+ isPlaceholderHidden = _ref5.isPlaceholderHidden,
241
+ withEmptyParagraph = _ref5.withEmptyParagraph,
242
+ showOnEmptyParagraph = _ref5.showOnEmptyParagraph;
216
243
  if (isPlaceholderHidden && fg('platform_editor_ai_aifc_patch_beta')) {
217
244
  return _objectSpread(_objectSpread({}, emptyPlaceholder({
218
245
  placeholderText: defaultPlaceholderText,
@@ -229,7 +256,7 @@ function createPlaceHolderStateFrom(_ref3) {
229
256
  userHadTyped: userHadTyped
230
257
  });
231
258
  }
232
- if ((defaultPlaceholderText || placeholderPrompts) && isEmptyDocument(editorState.doc)) {
259
+ if ((defaultPlaceholderText || placeholderPrompts || placeholderADF) && isEmptyDocument(editorState.doc)) {
233
260
  return setPlaceHolderState({
234
261
  placeholderText: defaultPlaceholderText,
235
262
  pos: 1,
@@ -238,12 +265,12 @@ function createPlaceHolderStateFrom(_ref3) {
238
265
  userHadTyped: userHadTyped
239
266
  });
240
267
  }
241
- if (fg('platform_editor_ai_aifc_patch_beta_2')) {
268
+ if (fg('platform_editor_ai_aifc_patch_beta_2') || fg('platform_editor_ai_aifc_patch_ga')) {
242
269
  var _editorState$selectio = editorState.selection,
243
270
  from = _editorState$selectio.from,
244
271
  to = _editorState$selectio.to,
245
272
  $to = _editorState$selectio.$to;
246
- if (defaultPlaceholderText && withEmptyParagraph && isEditorFocused && !isInitial && !isEmptyDocument(editorState.doc) && from === to && isEmptyParagraph($to.parent) && hasDocAsParent($to)) {
273
+ if ((defaultPlaceholderText || placeholderADF) && withEmptyParagraph && isEditorFocused && !isInitial && !isEmptyDocument(editorState.doc) && from === to && isEmptyParagraph($to.parent) && hasDocAsParent($to)) {
247
274
  return showOnEmptyParagraph ? setPlaceHolderState({
248
275
  placeholderText: defaultPlaceholderText,
249
276
  pos: to,
@@ -304,7 +331,8 @@ function createPlaceHolderStateFrom(_ref3) {
304
331
  var isFirstCell = (table === null || table === void 0 || (_table$node$firstChil = table.node.firstChild) === null || _table$node$firstChil === void 0 ? void 0 : _table$node$firstChil.content.firstChild) === parentNode;
305
332
  if (isFirstCell) {
306
333
  return setPlaceHolderState({
307
- placeholderText: intl.formatMessage(messages.shortEmptyNodePlaceholderText),
334
+ placeholderText: !fg('platform_editor_ai_aifc_patch_ga') ? intl.formatMessage(messages.shortEmptyNodePlaceholderText) : undefined,
335
+ contextPlaceholderADF: fg('platform_editor_ai_aifc_patch_ga') ? createShortEmptyNodePlaceholderADF(intl) : undefined,
308
336
  pos: $from.pos,
309
337
  placeholderPrompts: placeholderPrompts,
310
338
  typedAndDeleted: typedAndDeleted,
@@ -314,7 +342,8 @@ function createPlaceHolderStateFrom(_ref3) {
314
342
  }
315
343
  if (nodeTypesWithLongPlaceholderText.includes(parentType) && isEmptyNode) {
316
344
  return setPlaceHolderState({
317
- placeholderText: intl.formatMessage(messages.longEmptyNodePlaceholderText),
345
+ placeholderText: !fg('platform_editor_ai_aifc_patch_ga') ? intl.formatMessage(messages.longEmptyNodePlaceholderText) : undefined,
346
+ contextPlaceholderADF: fg('platform_editor_ai_aifc_patch_ga') ? createLongEmptyNodePlaceholderADF(intl) : undefined,
318
347
  pos: $from.pos,
319
348
  placeholderPrompts: placeholderPrompts,
320
349
  typedAndDeleted: typedAndDeleted,
@@ -354,10 +383,10 @@ function createPlaceHolderStateFrom(_ref3) {
354
383
  userHadTyped: userHadTyped
355
384
  });
356
385
  }
357
- function calculateUserInteractionState(_ref4) {
358
- var placeholderState = _ref4.placeholderState,
359
- oldEditorState = _ref4.oldEditorState,
360
- newEditorState = _ref4.newEditorState;
386
+ function calculateUserInteractionState(_ref6) {
387
+ var placeholderState = _ref6.placeholderState,
388
+ oldEditorState = _ref6.oldEditorState,
389
+ newEditorState = _ref6.newEditorState;
361
390
  var wasEmpty = oldEditorState ? isEmptyDocument(oldEditorState.doc) : true;
362
391
  var isEmpty = isEmptyDocument(newEditorState.doc);
363
392
  var hasEverTyped = Boolean(placeholderState === null || placeholderState === void 0 ? void 0 : placeholderState.userHadTyped) ||
@@ -399,6 +428,7 @@ export function createPlugin(intl, defaultPlaceholderText, bracketPlaceholderTex
399
428
  defaultPlaceholderText: defaultPlaceholderText,
400
429
  bracketPlaceholderText: bracketPlaceholderText,
401
430
  emptyLinePlaceholder: emptyLinePlaceholder,
431
+ placeholderADF: placeholderADF,
402
432
  placeholderPrompts: placeholderPrompts,
403
433
  typedAndDeleted: false,
404
434
  userHadTyped: false,
@@ -406,7 +436,7 @@ export function createPlugin(intl, defaultPlaceholderText, bracketPlaceholderTex
406
436
  });
407
437
  },
408
438
  apply: function apply(tr, placeholderState, _oldEditorState, newEditorState) {
409
- var _api$focus2, _placeholderState$isP, _api$typeAhead2, _ref5, _meta$placeholderText, _ref6, _meta$placeholderProm, _meta$showOnEmptyPara;
439
+ var _api$focus2, _placeholderState$isP, _api$typeAhead2, _ref7, _meta$placeholderText, _ref8, _meta$placeholderProm, _meta$showOnEmptyPara;
410
440
  var meta = tr.getMeta(pluginKey);
411
441
  var isEditorFocused = Boolean(api === null || api === void 0 || (_api$focus2 = api.focus) === null || _api$focus2 === void 0 || (_api$focus2 = _api$focus2.sharedState.currentState()) === null || _api$focus2 === void 0 ? void 0 : _api$focus2.hasFocus);
412
442
  var _calculateUserInterac = calculateUserInteractionState({
@@ -420,17 +450,21 @@ export function createPlugin(intl, defaultPlaceholderText, bracketPlaceholderTex
420
450
  if ((meta === null || meta === void 0 ? void 0 : meta.isPlaceholderHidden) !== undefined && fg('platform_editor_ai_aifc_patch_beta')) {
421
451
  isPlaceholderHidden = meta.isPlaceholderHidden;
422
452
  }
423
- if ((meta === null || meta === void 0 ? void 0 : meta.placeholderText) !== undefined && fg('platform_editor_ai_aifc_patch_beta_2')) {
424
- defaultPlaceholderText = meta.placeholderText;
453
+ if ((meta === null || meta === void 0 ? void 0 : meta.placeholderText) !== undefined && (fg('platform_editor_ai_aifc_patch_beta_2') || fg('platform_editor_ai_aifc_patch_ga'))) {
454
+ // Only update defaultPlaceholderText from meta if we're not using ADF placeholder
455
+ if (!(fg('platform_editor_ai_aifc_patch_ga') && placeholderADF)) {
456
+ defaultPlaceholderText = meta.placeholderText;
457
+ }
425
458
  }
426
459
  var newPlaceholderState = createPlaceHolderStateFrom({
427
460
  isEditorFocused: isEditorFocused,
428
461
  editorState: newEditorState,
429
462
  isTypeAheadOpen: api === null || api === void 0 || (_api$typeAhead2 = api.typeAhead) === null || _api$typeAhead2 === void 0 ? void 0 : _api$typeAhead2.actions.isOpen,
430
- defaultPlaceholderText: fg('platform_editor_ai_aifc_patch_beta_2') ? defaultPlaceholderText : (_ref5 = (_meta$placeholderText = meta === null || meta === void 0 ? void 0 : meta.placeholderText) !== null && _meta$placeholderText !== void 0 ? _meta$placeholderText : placeholderState === null || placeholderState === void 0 ? void 0 : placeholderState.placeholderText) !== null && _ref5 !== void 0 ? _ref5 : defaultPlaceholderText,
463
+ defaultPlaceholderText: fg('platform_editor_ai_aifc_patch_beta_2') || fg('platform_editor_ai_aifc_patch_ga') ? defaultPlaceholderText : (_ref7 = (_meta$placeholderText = meta === null || meta === void 0 ? void 0 : meta.placeholderText) !== null && _meta$placeholderText !== void 0 ? _meta$placeholderText : placeholderState === null || placeholderState === void 0 ? void 0 : placeholderState.placeholderText) !== null && _ref7 !== void 0 ? _ref7 : defaultPlaceholderText,
431
464
  bracketPlaceholderText: bracketPlaceholderText,
432
465
  emptyLinePlaceholder: emptyLinePlaceholder,
433
- placeholderPrompts: (_ref6 = (_meta$placeholderProm = meta === null || meta === void 0 ? void 0 : meta.placeholderPrompts) !== null && _meta$placeholderProm !== void 0 ? _meta$placeholderProm : placeholderState === null || placeholderState === void 0 ? void 0 : placeholderState.placeholderPrompts) !== null && _ref6 !== void 0 ? _ref6 : placeholderPrompts,
466
+ placeholderADF: placeholderADF,
467
+ placeholderPrompts: (_ref8 = (_meta$placeholderProm = meta === null || meta === void 0 ? void 0 : meta.placeholderPrompts) !== null && _meta$placeholderProm !== void 0 ? _meta$placeholderProm : placeholderState === null || placeholderState === void 0 ? void 0 : placeholderState.placeholderPrompts) !== null && _ref8 !== void 0 ? _ref8 : placeholderPrompts,
434
468
  typedAndDeleted: typedAndDeleted,
435
469
  userHadTyped: userHadTyped,
436
470
  intl: intl,
@@ -453,7 +487,8 @@ export function createPlugin(intl, defaultPlaceholderText, bracketPlaceholderTex
453
487
  hasPlaceholder = _getPlaceholderState.hasPlaceholder,
454
488
  placeholderText = _getPlaceholderState.placeholderText,
455
489
  pos = _getPlaceholderState.pos,
456
- typedAndDeleted = _getPlaceholderState.typedAndDeleted;
490
+ typedAndDeleted = _getPlaceholderState.typedAndDeleted,
491
+ contextPlaceholderADF = _getPlaceholderState.contextPlaceholderADF;
457
492
 
458
493
  // Decorations is still called after plugin is destroyed
459
494
  // So we need to make sure decorations is not called if plugin has been destroyed to prevent the placeholder animations' setTimeouts called infinitely
@@ -462,9 +497,11 @@ export function createPlugin(intl, defaultPlaceholderText, bracketPlaceholderTex
462
497
  }
463
498
  var compositionPluginState = api === null || api === void 0 || (_api$composition = api.composition) === null || _api$composition === void 0 ? void 0 : _api$composition.sharedState.currentState();
464
499
  var isShowingDiff = Boolean(api === null || api === void 0 || (_api$showDiff = api.showDiff) === null || _api$showDiff === void 0 || (_api$showDiff = _api$showDiff.sharedState.currentState()) === null || _api$showDiff === void 0 ? void 0 : _api$showDiff.isDisplayingChanges);
465
- if (hasPlaceholder && ((placeholderText !== null && placeholderText !== void 0 ? placeholderText : '') || placeholderPrompts || placeholderADF) && pos !== undefined && !(compositionPluginState !== null && compositionPluginState !== void 0 && compositionPluginState.isComposing) && !isShowingDiff) {
500
+ if (hasPlaceholder && ((placeholderText !== null && placeholderText !== void 0 ? placeholderText : '') || placeholderPrompts || placeholderADF || contextPlaceholderADF) && pos !== undefined && !(compositionPluginState !== null && compositionPluginState !== void 0 && compositionPluginState.isComposing) && !isShowingDiff) {
466
501
  var initialDelayWhenUserTypedAndDeleted = typedAndDeleted ? TYPEWRITER_TYPED_AND_DELETED_DELAY : 0;
467
- return createPlaceholderDecoration(editorState, placeholderText !== null && placeholderText !== void 0 ? placeholderText : '', placeholderPrompts, activeTypewriterTimeouts, pos, initialDelayWhenUserTypedAndDeleted, placeholderADF);
502
+ // contextPlaceholderADF takes precedence over the global placeholderADF
503
+ var placeholderAdfToUse = contextPlaceholderADF || placeholderADF;
504
+ return createPlaceholderDecoration(editorState, placeholderText !== null && placeholderText !== void 0 ? placeholderText : '', placeholderPrompts, activeTypewriterTimeouts, pos, initialDelayWhenUserTypedAndDeleted, placeholderAdfToUse);
468
505
  }
469
506
  return;
470
507
  }
@@ -490,7 +527,7 @@ export function createPlugin(intl, defaultPlaceholderText, bracketPlaceholderTex
490
527
  }
491
528
  return {
492
529
  update: function update(editorView, prevState) {
493
- if (fg('platform_editor_ai_aifc_patch_beta_2')) {
530
+ if (fg('platform_editor_ai_aifc_patch_beta_2') || fg('platform_editor_ai_aifc_patch_ga')) {
494
531
  var prevPluginState = getPlaceholderState(prevState);
495
532
  var newPluginState = getPlaceholderState(editorView.state);
496
533
 
@@ -521,16 +558,16 @@ export function createPlugin(intl, defaultPlaceholderText, bracketPlaceholderTex
521
558
  }
522
559
  });
523
560
  }
524
- export var placeholderPlugin = function placeholderPlugin(_ref7) {
525
- var options = _ref7.config,
526
- api = _ref7.api;
561
+ export var placeholderPlugin = function placeholderPlugin(_ref9) {
562
+ var options = _ref9.config,
563
+ api = _ref9.api;
527
564
  var currentPlaceholder = options === null || options === void 0 ? void 0 : options.placeholder;
528
565
  return {
529
566
  name: 'placeholder',
530
567
  commands: {
531
568
  setPlaceholder: function setPlaceholder(placeholderText) {
532
- return function (_ref8) {
533
- var tr = _ref8.tr;
569
+ return function (_ref0) {
570
+ var tr = _ref0.tr;
534
571
  if (currentPlaceholder !== placeholderText) {
535
572
  currentPlaceholder = placeholderText;
536
573
  return tr.setMeta(pluginKey, {
@@ -541,16 +578,16 @@ export var placeholderPlugin = function placeholderPlugin(_ref7) {
541
578
  };
542
579
  },
543
580
  setAnimatingPlaceholderPrompts: function setAnimatingPlaceholderPrompts(placeholderPrompts) {
544
- return function (_ref9) {
545
- var tr = _ref9.tr;
581
+ return function (_ref1) {
582
+ var tr = _ref1.tr;
546
583
  return tr.setMeta(pluginKey, {
547
584
  placeholderPrompts: placeholderPrompts
548
585
  });
549
586
  };
550
587
  },
551
588
  setPlaceholderHidden: function setPlaceholderHidden(isPlaceholderHidden) {
552
- return function (_ref0) {
553
- var tr = _ref0.tr;
589
+ return function (_ref10) {
590
+ var tr = _ref10.tr;
554
591
  return tr.setMeta(pluginKey, {
555
592
  isPlaceholderHidden: isPlaceholderHidden
556
593
  });
@@ -560,8 +597,8 @@ export var placeholderPlugin = function placeholderPlugin(_ref7) {
560
597
  pmPlugins: function pmPlugins() {
561
598
  return [{
562
599
  name: 'placeholder',
563
- plugin: function plugin(_ref1) {
564
- var getIntl = _ref1.getIntl;
600
+ plugin: function plugin(_ref11) {
601
+ var getIntl = _ref11.getIntl;
565
602
  return createPlugin(getIntl(), options && options.placeholder, options && options.placeholderBracketHint, options && options.emptyLinePlaceholder, options && options.placeholderPrompts, options === null || options === void 0 ? void 0 : options.withEmptyParagraph, options && options.placeholderADF, api);
566
603
  }
567
604
  }];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atlaskit/editor-plugin-placeholder",
3
- "version": "6.4.0",
3
+ "version": "6.5.0",
4
4
  "description": "Placeholder plugin for @atlaskit/editor-core.",
5
5
  "author": "Atlassian Pty Ltd",
6
6
  "license": "Apache-2.0",
@@ -27,18 +27,19 @@
27
27
  "sideEffects": false,
28
28
  "atlaskit:src": "src/index.ts",
29
29
  "dependencies": {
30
+ "@atlaskit/adf-utils": "^19.26.0",
30
31
  "@atlaskit/editor-plugin-composition": "^5.0.0",
31
32
  "@atlaskit/editor-plugin-focus": "^5.0.0",
32
33
  "@atlaskit/editor-plugin-show-diff": "^3.2.0",
33
34
  "@atlaskit/editor-plugin-type-ahead": "^6.5.0",
34
35
  "@atlaskit/editor-prosemirror": "7.0.0",
35
36
  "@atlaskit/platform-feature-flags": "^1.1.0",
36
- "@atlaskit/tmp-editor-statsig": "^13.38.0",
37
- "@atlaskit/tokens": "^8.0.0",
37
+ "@atlaskit/tmp-editor-statsig": "^13.39.0",
38
+ "@atlaskit/tokens": "^8.1.0",
38
39
  "@babel/runtime": "^7.0.0"
39
40
  },
40
41
  "peerDependencies": {
41
- "@atlaskit/editor-common": "^110.31.0",
42
+ "@atlaskit/editor-common": "^110.33.0",
42
43
  "react": "^18.2.0",
43
44
  "react-dom": "^18.2.0",
44
45
  "react-intl-next": "npm:react-intl@^5.18.1"