@atlaskit/editor-plugin-placeholder 6.2.0 → 6.4.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,23 @@
1
1
  # @atlaskit/editor-plugin-placeholder
2
2
 
3
+ ## 6.4.0
4
+
5
+ ### Minor Changes
6
+
7
+ - [`f34c6075cc3a4`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/f34c6075cc3a4) -
8
+ [ux] [EDITOR-2327] added support to add marks on placeholder plugin texts
9
+
10
+ ## 6.3.0
11
+
12
+ ### Minor Changes
13
+
14
+ - [`673772ec67daf`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/673772ec67daf) -
15
+ [ux] EDITOR-2265 - show placeholder for empty paragraph
16
+
17
+ ### Patch Changes
18
+
19
+ - Updated dependencies
20
+
3
21
  ## 6.2.0
4
22
 
5
23
  ### Minor Changes
@@ -4,13 +4,16 @@ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefau
4
4
  Object.defineProperty(exports, "__esModule", {
5
5
  value: true
6
6
  });
7
+ exports.EMPTY_PARAGRAPH_TIMEOUT_DELAY = void 0;
7
8
  exports.createPlaceholderDecoration = createPlaceholderDecoration;
8
9
  exports.createPlugin = createPlugin;
9
10
  exports.pluginKey = exports.placeholderPlugin = void 0;
10
11
  var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
11
12
  var _messages = require("@atlaskit/editor-common/messages");
13
+ var _processRawValue = require("@atlaskit/editor-common/process-raw-value");
12
14
  var _safePlugin = require("@atlaskit/editor-common/safe-plugin");
13
15
  var _utils = require("@atlaskit/editor-common/utils");
16
+ var _model = require("@atlaskit/editor-prosemirror/model");
14
17
  var _state = require("@atlaskit/editor-prosemirror/state");
15
18
  var _utils2 = require("@atlaskit/editor-prosemirror/utils");
16
19
  var _view = require("@atlaskit/editor-prosemirror/view");
@@ -26,6 +29,8 @@ var TYPEWRITER_ERASE_DELAY = 40; // Delay between erasing each character
26
29
  var TYPEWRITER_CYCLE_DELAY = 500; // Delay before starting next cycle
27
30
  var TYPEWRITER_TYPED_AND_DELETED_DELAY = 1500; // Delay before starting animation after user typed and deleted
28
31
 
32
+ var EMPTY_PARAGRAPH_TIMEOUT_DELAY = exports.EMPTY_PARAGRAPH_TIMEOUT_DELAY = 2000; // Delay before showing placeholder on empty paragraph
33
+
29
34
  var pluginKey = exports.pluginKey = new _state.PluginKey('placeholderPlugin');
30
35
  var placeholderTestId = 'placeholder-test-id';
31
36
  function getPlaceholderState(editorState) {
@@ -88,6 +93,7 @@ var cycleThroughPlaceholderPrompts = function cycleThroughPlaceholderPrompts(pla
88
93
  function createPlaceholderDecoration(editorState, placeholderText, placeholderPrompts, activeTypewriterTimeouts) {
89
94
  var pos = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : 1;
90
95
  var initialDelayWhenUserTypedAndDeleted = arguments.length > 5 && arguments[5] !== undefined ? arguments[5] : 0;
96
+ var placeholderADF = arguments.length > 6 ? arguments[6] : undefined;
91
97
  var placeholderDecoration = document.createElement('span');
92
98
  var placeholderNodeWithText = placeholderDecoration;
93
99
  placeholderDecoration.setAttribute('data-testid', placeholderTestId);
@@ -101,7 +107,43 @@ function createPlaceholderDecoration(editorState, placeholderText, placeholderPr
101
107
  placeholderDecoration.appendChild(placeholderNode);
102
108
  placeholderNodeWithText = placeholderNode;
103
109
  }
104
- if (placeholderText) {
110
+ if (placeholderADF) {
111
+ var serializer = _model.DOMSerializer.fromSchema(editorState.schema);
112
+ // Get a PMNode from docnode
113
+ var docNode = (0, _processRawValue.processRawValue)(editorState.schema, placeholderADF);
114
+ if (docNode) {
115
+ // Extract only the inline content from paragraphs, avoiding block-level elements
116
+ // that can interfere with cursor rendering
117
+ docNode.children.forEach(function (node) {
118
+ // For paragraph nodes, serialize their content (inline elements) directly
119
+ // without the wrapping <p> tag
120
+ if (node.type.name === 'paragraph') {
121
+ node.content.forEach(function (inlineNode) {
122
+ var inlineDOM = serializer.serializeNode(inlineNode);
123
+ placeholderNodeWithText.append(inlineDOM);
124
+ });
125
+ } else {
126
+ // For non-paragraph nodes, serialize normally
127
+ var nodeDOM = serializer.serializeNode(node);
128
+ placeholderNodeWithText.append(nodeDOM);
129
+ }
130
+ });
131
+ var markElements = placeholderNodeWithText.querySelectorAll('[data-prosemirror-content-type="mark"]');
132
+ markElements.forEach(function (markEl) {
133
+ if (markEl instanceof HTMLElement) {
134
+ markEl.style.setProperty('color', "var(--ds-text-subtlest, #6B6E76)");
135
+ }
136
+ });
137
+ // Ensure all child elements don't block pointer events or cursor
138
+ var allElements = placeholderNodeWithText.querySelectorAll('*');
139
+ allElements.forEach(function (el) {
140
+ if (el instanceof HTMLElement) {
141
+ el.style.pointerEvents = 'none';
142
+ el.style.userSelect = 'none';
143
+ }
144
+ });
145
+ }
146
+ } else if (placeholderText) {
105
147
  placeholderNodeWithText.textContent = placeholderText || ' ';
106
148
  } else if (placeholderPrompts) {
107
149
  cycleThroughPlaceholderPrompts(placeholderPrompts, activeTypewriterTimeouts, placeholderNodeWithText, initialDelayWhenUserTypedAndDeleted);
@@ -129,62 +171,131 @@ function createPlaceholderDecoration(editorState, placeholderText, placeholderPr
129
171
  key: "placeholder ".concat(placeholderText)
130
172
  })]);
131
173
  }
132
- function setPlaceHolderState(placeholderText, pos, placeholderPrompts, typedAndDeleted, userHadTyped) {
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;
133
182
  return {
134
183
  hasPlaceholder: true,
135
184
  placeholderText: placeholderText,
136
185
  placeholderPrompts: placeholderPrompts,
137
186
  pos: pos ? pos : 1,
138
187
  typedAndDeleted: typedAndDeleted,
139
- userHadTyped: userHadTyped
188
+ userHadTyped: userHadTyped,
189
+ canShowOnEmptyParagraph: canShowOnEmptyParagraph,
190
+ showOnEmptyParagraph: showOnEmptyParagraph
140
191
  };
141
192
  }
142
- var emptyPlaceholder = function emptyPlaceholder(placeholderText, placeholderPrompts, userHadTyped) {
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;
143
200
  return {
144
201
  hasPlaceholder: false,
145
202
  placeholderText: placeholderText,
146
203
  placeholderPrompts: placeholderPrompts,
147
204
  userHadTyped: userHadTyped,
148
- typedAndDeleted: false
205
+ typedAndDeleted: false,
206
+ canShowOnEmptyParagraph: canShowOnEmptyParagraph,
207
+ showOnEmptyParagraph: showOnEmptyParagraph,
208
+ pos: pos
149
209
  };
150
210
  };
151
- function createPlaceHolderStateFrom(_ref) {
152
- var isEditorFocused = _ref.isEditorFocused,
153
- editorState = _ref.editorState,
154
- isTypeAheadOpen = _ref.isTypeAheadOpen,
155
- defaultPlaceholderText = _ref.defaultPlaceholderText,
156
- intl = _ref.intl,
157
- bracketPlaceholderText = _ref.bracketPlaceholderText,
158
- emptyLinePlaceholder = _ref.emptyLinePlaceholder,
159
- placeholderPrompts = _ref.placeholderPrompts,
160
- typedAndDeleted = _ref.typedAndDeleted,
161
- userHadTyped = _ref.userHadTyped,
162
- isPlaceholderHidden = _ref.isPlaceholderHidden;
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;
163
226
  if (isPlaceholderHidden && (0, _platformFeatureFlags.fg)('platform_editor_ai_aifc_patch_beta')) {
164
- return _objectSpread(_objectSpread({}, emptyPlaceholder(defaultPlaceholderText, placeholderPrompts, userHadTyped)), {}, {
227
+ return _objectSpread(_objectSpread({}, emptyPlaceholder({
228
+ placeholderText: defaultPlaceholderText,
229
+ placeholderPrompts: placeholderPrompts,
230
+ userHadTyped: userHadTyped
231
+ })), {}, {
165
232
  isPlaceholderHidden: isPlaceholderHidden
166
233
  });
167
234
  }
168
235
  if (isTypeAheadOpen !== null && isTypeAheadOpen !== void 0 && isTypeAheadOpen(editorState)) {
169
- return emptyPlaceholder(defaultPlaceholderText, placeholderPrompts, userHadTyped);
236
+ return emptyPlaceholder({
237
+ placeholderText: defaultPlaceholderText,
238
+ placeholderPrompts: placeholderPrompts,
239
+ userHadTyped: userHadTyped
240
+ });
170
241
  }
171
242
  if ((defaultPlaceholderText || placeholderPrompts) && (0, _utils.isEmptyDocument)(editorState.doc)) {
172
- return setPlaceHolderState(defaultPlaceholderText, 1, placeholderPrompts, typedAndDeleted, userHadTyped);
243
+ return setPlaceHolderState({
244
+ placeholderText: defaultPlaceholderText,
245
+ pos: 1,
246
+ placeholderPrompts: placeholderPrompts,
247
+ typedAndDeleted: typedAndDeleted,
248
+ userHadTyped: userHadTyped
249
+ });
173
250
  }
174
- if (isEditorFocused && (0, _experiments.editorExperiment)('platform_editor_controls', 'variant1')) {
175
- var _parentNode$firstChil, _parentNode$firstChil2;
251
+ if ((0, _platformFeatureFlags.fg)('platform_editor_ai_aifc_patch_beta_2')) {
176
252
  var _editorState$selectio = editorState.selection,
177
- $from = _editorState$selectio.$from,
253
+ from = _editorState$selectio.from,
254
+ to = _editorState$selectio.to,
178
255
  $to = _editorState$selectio.$to;
179
- if ($from.pos !== $to.pos) {
180
- return emptyPlaceholder(defaultPlaceholderText, placeholderPrompts, userHadTyped);
256
+ if (defaultPlaceholderText && withEmptyParagraph && isEditorFocused && !isInitial && !(0, _utils.isEmptyDocument)(editorState.doc) && from === to && (0, _utils.isEmptyParagraph)($to.parent) && (0, _utils.hasDocAsParent)($to)) {
257
+ return showOnEmptyParagraph ? setPlaceHolderState({
258
+ placeholderText: defaultPlaceholderText,
259
+ pos: to,
260
+ placeholderPrompts: placeholderPrompts,
261
+ typedAndDeleted: typedAndDeleted,
262
+ userHadTyped: userHadTyped,
263
+ canShowOnEmptyParagraph: true,
264
+ showOnEmptyParagraph: true
265
+ }) : emptyPlaceholder({
266
+ placeholderText: defaultPlaceholderText,
267
+ placeholderPrompts: placeholderPrompts,
268
+ userHadTyped: userHadTyped,
269
+ canShowOnEmptyParagraph: true,
270
+ showOnEmptyParagraph: false,
271
+ pos: to
272
+ });
273
+ }
274
+ }
275
+ if (isEditorFocused && (0, _experiments.editorExperiment)('platform_editor_controls', 'variant1')) {
276
+ var _parentNode$firstChil, _parentNode$firstChil2;
277
+ var _editorState$selectio2 = editorState.selection,
278
+ $from = _editorState$selectio2.$from,
279
+ _$to = _editorState$selectio2.$to;
280
+ if ($from.pos !== _$to.pos) {
281
+ return emptyPlaceholder({
282
+ placeholderText: defaultPlaceholderText,
283
+ placeholderPrompts: placeholderPrompts,
284
+ userHadTyped: userHadTyped
285
+ });
181
286
  }
182
287
  var parentNode = $from.node($from.depth - 1);
183
288
  var parentType = parentNode === null || parentNode === void 0 ? void 0 : parentNode.type.name;
184
289
  if (emptyLinePlaceholder && parentType === 'doc') {
185
290
  var isEmptyLine = (0, _utils.isEmptyParagraph)($from.parent);
186
291
  if (isEmptyLine) {
187
- return setPlaceHolderState(emptyLinePlaceholder, $from.pos, placeholderPrompts, typedAndDeleted, userHadTyped);
292
+ return setPlaceHolderState({
293
+ placeholderText: emptyLinePlaceholder,
294
+ pos: $from.pos,
295
+ placeholderPrompts: placeholderPrompts,
296
+ typedAndDeleted: typedAndDeleted,
297
+ userHadTyped: userHadTyped
298
+ });
188
299
  }
189
300
  }
190
301
  var isEmptyNode = (parentNode === null || parentNode === void 0 ? void 0 : parentNode.childCount) === 1 && ((_parentNode$firstChil = parentNode.firstChild) === null || _parentNode$firstChil === void 0 ? void 0 : _parentNode$firstChil.content.size) === 0 && ((_parentNode$firstChil2 = parentNode.firstChild) === null || _parentNode$firstChil2 === void 0 ? void 0 : _parentNode$firstChil2.type.name) === 'paragraph';
@@ -194,33 +305,69 @@ function createPlaceHolderStateFrom(_ref) {
194
305
  return node.type === editorState.schema.nodes.table;
195
306
  })(editorState.selection);
196
307
  if (!table) {
197
- return emptyPlaceholder(defaultPlaceholderText, placeholderPrompts, userHadTyped);
308
+ return emptyPlaceholder({
309
+ placeholderText: defaultPlaceholderText,
310
+ placeholderPrompts: placeholderPrompts,
311
+ userHadTyped: userHadTyped
312
+ });
198
313
  }
199
314
  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;
200
315
  if (isFirstCell) {
201
- return setPlaceHolderState(intl.formatMessage(_messages.placeholderTextMessages.shortEmptyNodePlaceholderText), $from.pos, placeholderPrompts, typedAndDeleted, userHadTyped);
316
+ return setPlaceHolderState({
317
+ placeholderText: intl.formatMessage(_messages.placeholderTextMessages.shortEmptyNodePlaceholderText),
318
+ pos: $from.pos,
319
+ placeholderPrompts: placeholderPrompts,
320
+ typedAndDeleted: typedAndDeleted,
321
+ userHadTyped: userHadTyped
322
+ });
202
323
  }
203
324
  }
204
325
  if (nodeTypesWithLongPlaceholderText.includes(parentType) && isEmptyNode) {
205
- return setPlaceHolderState(intl.formatMessage(_messages.placeholderTextMessages.longEmptyNodePlaceholderText), $from.pos, placeholderPrompts, typedAndDeleted, userHadTyped);
326
+ return setPlaceHolderState({
327
+ placeholderText: intl.formatMessage(_messages.placeholderTextMessages.longEmptyNodePlaceholderText),
328
+ pos: $from.pos,
329
+ placeholderPrompts: placeholderPrompts,
330
+ typedAndDeleted: typedAndDeleted,
331
+ userHadTyped: userHadTyped
332
+ });
206
333
  }
207
334
  if (nodeTypesWithSyncBlockPlaceholderText.includes(parentType) && isEmptyNode && (0, _expValEquals.expValEquals)('platform_synced_block', 'isEnabled', true)) {
208
- return setPlaceHolderState(intl.formatMessage(_messages.placeholderTextMessages.syncBlockPlaceholderText), $from.pos, placeholderPrompts, typedAndDeleted, userHadTyped);
335
+ return setPlaceHolderState({
336
+ placeholderText: intl.formatMessage(_messages.placeholderTextMessages.syncBlockPlaceholderText),
337
+ pos: $from.pos,
338
+ placeholderPrompts: placeholderPrompts,
339
+ typedAndDeleted: typedAndDeleted,
340
+ userHadTyped: userHadTyped
341
+ });
209
342
  }
210
- return emptyPlaceholder(defaultPlaceholderText, placeholderPrompts, userHadTyped);
343
+ return emptyPlaceholder({
344
+ placeholderText: defaultPlaceholderText,
345
+ placeholderPrompts: placeholderPrompts,
346
+ userHadTyped: userHadTyped
347
+ });
211
348
  }
212
349
  if (bracketPlaceholderText && (0, _utils.bracketTyped)(editorState) && isEditorFocused) {
213
350
  var _$from = editorState.selection.$from;
214
351
  // Space is to account for positioning of the bracket
215
352
  var bracketHint = ' ' + bracketPlaceholderText;
216
- return setPlaceHolderState(bracketHint, _$from.pos - 1, placeholderPrompts, typedAndDeleted, userHadTyped);
353
+ return setPlaceHolderState({
354
+ placeholderText: bracketHint,
355
+ pos: _$from.pos - 1,
356
+ placeholderPrompts: placeholderPrompts,
357
+ typedAndDeleted: typedAndDeleted,
358
+ userHadTyped: userHadTyped
359
+ });
217
360
  }
218
- return emptyPlaceholder(defaultPlaceholderText, placeholderPrompts, userHadTyped);
361
+ return emptyPlaceholder({
362
+ placeholderText: defaultPlaceholderText,
363
+ placeholderPrompts: placeholderPrompts,
364
+ userHadTyped: userHadTyped
365
+ });
219
366
  }
220
- function calculateUserInteractionState(_ref2) {
221
- var placeholderState = _ref2.placeholderState,
222
- oldEditorState = _ref2.oldEditorState,
223
- newEditorState = _ref2.newEditorState;
367
+ function calculateUserInteractionState(_ref4) {
368
+ var placeholderState = _ref4.placeholderState,
369
+ oldEditorState = _ref4.oldEditorState,
370
+ newEditorState = _ref4.newEditorState;
224
371
  var wasEmpty = oldEditorState ? (0, _utils.isEmptyDocument)(oldEditorState.doc) : true;
225
372
  var isEmpty = (0, _utils.isEmptyDocument)(newEditorState.doc);
226
373
  var hasEverTyped = Boolean(placeholderState === null || placeholderState === void 0 ? void 0 : placeholderState.userHadTyped) ||
@@ -237,8 +384,8 @@ function calculateUserInteractionState(_ref2) {
237
384
  typedAndDeleted: isInTypedAndDeletedState
238
385
  };
239
386
  }
240
- function createPlugin(intl, defaultPlaceholderText, bracketPlaceholderText, emptyLinePlaceholder, placeholderPrompts, api) {
241
- if (!defaultPlaceholderText && !placeholderPrompts && !bracketPlaceholderText) {
387
+ function createPlugin(intl, defaultPlaceholderText, bracketPlaceholderText, emptyLinePlaceholder, placeholderPrompts, withEmptyParagraph, placeholderADF, api) {
388
+ if (!defaultPlaceholderText && !placeholderPrompts && !bracketPlaceholderText && !placeholderADF) {
242
389
  return;
243
390
  }
244
391
  var isDestroyed = false;
@@ -255,6 +402,7 @@ function createPlugin(intl, defaultPlaceholderText, bracketPlaceholderText, empt
255
402
  init: function init(_, state) {
256
403
  var _api$focus, _api$typeAhead;
257
404
  return createPlaceHolderStateFrom({
405
+ isInitial: true,
258
406
  isEditorFocused: Boolean(api === null || api === void 0 || (_api$focus = api.focus) === null || _api$focus === void 0 || (_api$focus = _api$focus.sharedState.currentState()) === null || _api$focus === void 0 ? void 0 : _api$focus.hasFocus),
259
407
  editorState: state,
260
408
  isTypeAheadOpen: api === null || api === void 0 || (_api$typeAhead = api.typeAhead) === null || _api$typeAhead === void 0 ? void 0 : _api$typeAhead.actions.isOpen,
@@ -268,7 +416,7 @@ function createPlugin(intl, defaultPlaceholderText, bracketPlaceholderText, empt
268
416
  });
269
417
  },
270
418
  apply: function apply(tr, placeholderState, _oldEditorState, newEditorState) {
271
- var _api$focus2, _placeholderState$isP, _api$typeAhead2, _ref3, _meta$placeholderText, _ref4, _meta$placeholderProm;
419
+ var _api$focus2, _placeholderState$isP, _api$typeAhead2, _ref5, _meta$placeholderText, _ref6, _meta$placeholderProm, _meta$showOnEmptyPara;
272
420
  var meta = tr.getMeta(pluginKey);
273
421
  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);
274
422
  var _calculateUserInterac = calculateUserInteractionState({
@@ -282,18 +430,23 @@ function createPlugin(intl, defaultPlaceholderText, bracketPlaceholderText, empt
282
430
  if ((meta === null || meta === void 0 ? void 0 : meta.isPlaceholderHidden) !== undefined && (0, _platformFeatureFlags.fg)('platform_editor_ai_aifc_patch_beta')) {
283
431
  isPlaceholderHidden = meta.isPlaceholderHidden;
284
432
  }
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;
435
+ }
285
436
  var newPlaceholderState = createPlaceHolderStateFrom({
286
437
  isEditorFocused: isEditorFocused,
287
438
  editorState: newEditorState,
288
439
  isTypeAheadOpen: api === null || api === void 0 || (_api$typeAhead2 = api.typeAhead) === null || _api$typeAhead2 === void 0 ? void 0 : _api$typeAhead2.actions.isOpen,
289
- defaultPlaceholderText: (_ref3 = (_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 && _ref3 !== void 0 ? _ref3 : defaultPlaceholderText,
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,
290
441
  bracketPlaceholderText: bracketPlaceholderText,
291
442
  emptyLinePlaceholder: emptyLinePlaceholder,
292
- placeholderPrompts: (_ref4 = (_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 && _ref4 !== void 0 ? _ref4 : placeholderPrompts,
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,
293
444
  typedAndDeleted: typedAndDeleted,
294
445
  userHadTyped: userHadTyped,
295
446
  intl: intl,
296
- isPlaceholderHidden: isPlaceholderHidden
447
+ isPlaceholderHidden: isPlaceholderHidden,
448
+ withEmptyParagraph: withEmptyParagraph,
449
+ showOnEmptyParagraph: (_meta$showOnEmptyPara = meta === null || meta === void 0 ? void 0 : meta.showOnEmptyParagraph) !== null && _meta$showOnEmptyPara !== void 0 ? _meta$showOnEmptyPara : placeholderState === null || placeholderState === void 0 ? void 0 : placeholderState.showOnEmptyParagraph
297
450
  });
298
451
 
299
452
  // Clear timeouts when hasPlaceholder becomes false
@@ -319,33 +472,75 @@ function createPlugin(intl, defaultPlaceholderText, bracketPlaceholderText, empt
319
472
  }
320
473
  var compositionPluginState = api === null || api === void 0 || (_api$composition = api.composition) === null || _api$composition === void 0 ? void 0 : _api$composition.sharedState.currentState();
321
474
  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);
322
- if (hasPlaceholder && ((placeholderText !== null && placeholderText !== void 0 ? placeholderText : '') || placeholderPrompts) && pos !== undefined && !(compositionPluginState !== null && compositionPluginState !== void 0 && compositionPluginState.isComposing) && !isShowingDiff) {
475
+ if (hasPlaceholder && ((placeholderText !== null && placeholderText !== void 0 ? placeholderText : '') || placeholderPrompts || placeholderADF) && pos !== undefined && !(compositionPluginState !== null && compositionPluginState !== void 0 && compositionPluginState.isComposing) && !isShowingDiff) {
323
476
  var initialDelayWhenUserTypedAndDeleted = typedAndDeleted ? TYPEWRITER_TYPED_AND_DELETED_DELAY : 0;
324
- return createPlaceholderDecoration(editorState, placeholderText !== null && placeholderText !== void 0 ? placeholderText : '', placeholderPrompts, activeTypewriterTimeouts, pos, initialDelayWhenUserTypedAndDeleted);
477
+ return createPlaceholderDecoration(editorState, placeholderText !== null && placeholderText !== void 0 ? placeholderText : '', placeholderPrompts, activeTypewriterTimeouts, pos, initialDelayWhenUserTypedAndDeleted, placeholderADF);
325
478
  }
326
479
  return;
327
480
  }
328
481
  },
329
482
  view: function view() {
483
+ var timeoutId;
484
+ function startEmptyParagraphTimeout(editorView) {
485
+ if (timeoutId) {
486
+ return;
487
+ }
488
+ timeoutId = setTimeout(function () {
489
+ timeoutId = undefined;
490
+ editorView.dispatch(editorView.state.tr.setMeta(pluginKey, {
491
+ showOnEmptyParagraph: true
492
+ }));
493
+ }, EMPTY_PARAGRAPH_TIMEOUT_DELAY);
494
+ }
495
+ function destroyEmptyParagraphTimeout() {
496
+ if (timeoutId) {
497
+ clearTimeout(timeoutId);
498
+ timeoutId = undefined;
499
+ }
500
+ }
330
501
  return {
502
+ update: function update(editorView, prevState) {
503
+ if ((0, _platformFeatureFlags.fg)('platform_editor_ai_aifc_patch_beta_2')) {
504
+ var prevPluginState = getPlaceholderState(prevState);
505
+ var newPluginState = getPlaceholderState(editorView.state);
506
+
507
+ // user start typing after move to an empty paragraph, clear timeout
508
+ if (!newPluginState.canShowOnEmptyParagraph && timeoutId) {
509
+ destroyEmptyParagraphTimeout();
510
+ }
511
+ // user move to an empty paragraph again, reset state to hide placeholder, and restart timeout
512
+ else if (prevPluginState.canShowOnEmptyParagraph && newPluginState.canShowOnEmptyParagraph && newPluginState.pos !== prevPluginState.pos) {
513
+ editorView.dispatch(editorView.state.tr.setMeta(pluginKey, {
514
+ showOnEmptyParagraph: false
515
+ }));
516
+ destroyEmptyParagraphTimeout();
517
+ startEmptyParagraphTimeout(editorView);
518
+ }
519
+ // user move to an empty paragraph (by click enter or move to an empty paragraph), start timeout
520
+ else if (!prevPluginState.canShowOnEmptyParagraph && newPluginState.canShowOnEmptyParagraph && !newPluginState.showOnEmptyParagraph && !timeoutId) {
521
+ startEmptyParagraphTimeout(editorView);
522
+ }
523
+ }
524
+ },
331
525
  destroy: function destroy() {
332
526
  clearAllTypewriterTimeouts();
527
+ destroyEmptyParagraphTimeout();
333
528
  isDestroyed = true;
334
529
  }
335
530
  };
336
531
  }
337
532
  });
338
533
  }
339
- var placeholderPlugin = exports.placeholderPlugin = function placeholderPlugin(_ref5) {
340
- var options = _ref5.config,
341
- api = _ref5.api;
534
+ var placeholderPlugin = exports.placeholderPlugin = function placeholderPlugin(_ref7) {
535
+ var options = _ref7.config,
536
+ api = _ref7.api;
342
537
  var currentPlaceholder = options === null || options === void 0 ? void 0 : options.placeholder;
343
538
  return {
344
539
  name: 'placeholder',
345
540
  commands: {
346
541
  setPlaceholder: function setPlaceholder(placeholderText) {
347
- return function (_ref6) {
348
- var tr = _ref6.tr;
542
+ return function (_ref8) {
543
+ var tr = _ref8.tr;
349
544
  if (currentPlaceholder !== placeholderText) {
350
545
  currentPlaceholder = placeholderText;
351
546
  return tr.setMeta(pluginKey, {
@@ -356,16 +551,16 @@ var placeholderPlugin = exports.placeholderPlugin = function placeholderPlugin(_
356
551
  };
357
552
  },
358
553
  setAnimatingPlaceholderPrompts: function setAnimatingPlaceholderPrompts(placeholderPrompts) {
359
- return function (_ref7) {
360
- var tr = _ref7.tr;
554
+ return function (_ref9) {
555
+ var tr = _ref9.tr;
361
556
  return tr.setMeta(pluginKey, {
362
557
  placeholderPrompts: placeholderPrompts
363
558
  });
364
559
  };
365
560
  },
366
561
  setPlaceholderHidden: function setPlaceholderHidden(isPlaceholderHidden) {
367
- return function (_ref8) {
368
- var tr = _ref8.tr;
562
+ return function (_ref0) {
563
+ var tr = _ref0.tr;
369
564
  return tr.setMeta(pluginKey, {
370
565
  isPlaceholderHidden: isPlaceholderHidden
371
566
  });
@@ -375,9 +570,9 @@ var placeholderPlugin = exports.placeholderPlugin = function placeholderPlugin(_
375
570
  pmPlugins: function pmPlugins() {
376
571
  return [{
377
572
  name: 'placeholder',
378
- plugin: function plugin(_ref9) {
379
- var getIntl = _ref9.getIntl;
380
- return createPlugin(getIntl(), options && options.placeholder, options && options.placeholderBracketHint, options && options.emptyLinePlaceholder, options && options.placeholderPrompts, api);
573
+ plugin: function plugin(_ref1) {
574
+ var getIntl = _ref1.getIntl;
575
+ 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);
381
576
  }
382
577
  }];
383
578
  }