@atlaskit/editor-plugin-placeholder 6.5.3 → 6.6.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.
Files changed (47) hide show
  1. package/CHANGELOG.md +15 -0
  2. package/dist/cjs/placeholderPlugin.js +19 -588
  3. package/dist/cjs/pm-plugins/adf-builders.js +30 -0
  4. package/dist/cjs/pm-plugins/animation.js +58 -0
  5. package/dist/cjs/pm-plugins/constants.js +18 -0
  6. package/dist/cjs/pm-plugins/decorations.js +96 -0
  7. package/dist/cjs/pm-plugins/main.js +167 -0
  8. package/dist/cjs/pm-plugins/placeholderPluginLegacy.js +616 -0
  9. package/dist/cjs/pm-plugins/types.js +5 -0
  10. package/dist/cjs/pm-plugins/utils.js +243 -0
  11. package/dist/es2019/placeholderPlugin.js +8 -572
  12. package/dist/es2019/pm-plugins/adf-builders.js +22 -0
  13. package/dist/es2019/pm-plugins/animation.js +49 -0
  14. package/dist/es2019/pm-plugins/constants.js +12 -0
  15. package/dist/es2019/pm-plugins/decorations.js +87 -0
  16. package/dist/es2019/pm-plugins/main.js +161 -0
  17. package/dist/es2019/pm-plugins/placeholderPluginLegacy.js +597 -0
  18. package/dist/es2019/pm-plugins/types.js +1 -0
  19. package/dist/es2019/pm-plugins/utils.js +234 -0
  20. package/dist/esm/placeholderPlugin.js +17 -583
  21. package/dist/esm/pm-plugins/adf-builders.js +24 -0
  22. package/dist/esm/pm-plugins/animation.js +52 -0
  23. package/dist/esm/pm-plugins/constants.js +12 -0
  24. package/dist/esm/pm-plugins/decorations.js +90 -0
  25. package/dist/esm/pm-plugins/main.js +161 -0
  26. package/dist/esm/pm-plugins/placeholderPluginLegacy.js +606 -0
  27. package/dist/esm/pm-plugins/types.js +1 -0
  28. package/dist/esm/pm-plugins/utils.js +232 -0
  29. package/dist/types/placeholderPlugin.d.ts +0 -8
  30. package/dist/types/pm-plugins/adf-builders.d.ts +4 -0
  31. package/dist/types/pm-plugins/animation.d.ts +1 -0
  32. package/dist/types/pm-plugins/constants.d.ts +9 -0
  33. package/dist/types/pm-plugins/decorations.d.ts +4 -0
  34. package/dist/types/pm-plugins/main.d.ts +6 -0
  35. package/dist/types/pm-plugins/placeholderPluginLegacy.d.ts +13 -0
  36. package/dist/types/pm-plugins/types.d.ts +37 -0
  37. package/dist/types/pm-plugins/utils.d.ts +27 -0
  38. package/dist/types-ts4.5/placeholderPlugin.d.ts +0 -8
  39. package/dist/types-ts4.5/pm-plugins/adf-builders.d.ts +4 -0
  40. package/dist/types-ts4.5/pm-plugins/animation.d.ts +1 -0
  41. package/dist/types-ts4.5/pm-plugins/constants.d.ts +9 -0
  42. package/dist/types-ts4.5/pm-plugins/decorations.d.ts +4 -0
  43. package/dist/types-ts4.5/pm-plugins/main.d.ts +6 -0
  44. package/dist/types-ts4.5/pm-plugins/placeholderPluginLegacy.d.ts +13 -0
  45. package/dist/types-ts4.5/pm-plugins/types.d.ts +37 -0
  46. package/dist/types-ts4.5/pm-plugins/utils.d.ts +27 -0
  47. package/package.json +7 -4
package/CHANGELOG.md CHANGED
@@ -1,5 +1,20 @@
1
1
  # @atlaskit/editor-plugin-placeholder
2
2
 
3
+ ## 6.6.0
4
+
5
+ ### Minor Changes
6
+
7
+ - [`a3a576969a12c`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/a3a576969a12c) -
8
+ [No-issue] placeholder plugin tidying
9
+
10
+ ## 6.5.4
11
+
12
+ ### Patch Changes
13
+
14
+ - [`55920a92e882a`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/55920a92e882a) -
15
+ tsignores added for help-center local consumpton removed
16
+ - Updated dependencies
17
+
3
18
  ## 6.5.3
4
19
 
5
20
  ### Patch Changes
@@ -4,599 +4,30 @@ 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;
8
- exports.createPlaceholderDecoration = createPlaceholderDecoration;
9
- exports.createPlugin = createPlugin;
10
- exports.pluginKey = exports.placeholderPlugin = void 0;
11
- var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
12
- var _builders = require("@atlaskit/adf-utils/builders");
13
- var _messages = require("@atlaskit/editor-common/messages");
14
- var _processRawValue = require("@atlaskit/editor-common/process-raw-value");
15
- var _safePlugin = require("@atlaskit/editor-common/safe-plugin");
16
- var _utils = require("@atlaskit/editor-common/utils");
17
- var _model = require("@atlaskit/editor-prosemirror/model");
7
+ exports.pluginKey = exports.placeholderPlugin = exports.EMPTY_PARAGRAPH_TIMEOUT_DELAY = void 0;
18
8
  var _state = require("@atlaskit/editor-prosemirror/state");
19
- var _utils2 = require("@atlaskit/editor-prosemirror/utils");
20
- var _view = require("@atlaskit/editor-prosemirror/view");
21
9
  var _platformFeatureFlags = require("@atlaskit/platform-feature-flags");
22
- var _experiments = require("@atlaskit/tmp-editor-statsig/experiments");
23
- 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; }
24
- 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) { (0, _defineProperty2.default)(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; }
25
- // Typewriter animation timing constants
26
- var TYPEWRITER_TYPE_DELAY = 50; // Delay between typing each character
27
- var TYPEWRITER_PAUSE_BEFORE_ERASE = 2000; // Pause before starting to erase text
28
- var TYPEWRITER_ERASE_DELAY = 40; // Delay between erasing each character
29
- var TYPEWRITER_CYCLE_DELAY = 500; // Delay before starting next cycle
30
- var TYPEWRITER_TYPED_AND_DELETED_DELAY = 1500; // Delay before starting animation after user typed and deleted
31
-
10
+ var _main = _interopRequireDefault(require("./pm-plugins/main"));
11
+ var _placeholderPluginLegacy = require("./pm-plugins/placeholderPluginLegacy");
32
12
  var EMPTY_PARAGRAPH_TIMEOUT_DELAY = exports.EMPTY_PARAGRAPH_TIMEOUT_DELAY = 2000; // Delay before showing placeholder on empty paragraph
33
13
 
34
14
  var pluginKey = exports.pluginKey = new _state.PluginKey('placeholderPlugin');
35
- var placeholderTestId = 'placeholder-test-id';
36
- function getPlaceholderState(editorState) {
37
- return pluginKey.getState(editorState);
38
- }
39
- var nodeTypesWithLongPlaceholderText = ['expand', 'panel'];
40
- var nodeTypesWithShortPlaceholderText = ['tableCell', 'tableHeader'];
41
- var nodeTypesWithSyncBlockPlaceholderText = ['bodiedSyncBlock'];
42
- var createShortEmptyNodePlaceholderADF = function createShortEmptyNodePlaceholderADF(_ref) {
43
- var formatMessage = _ref.formatMessage;
44
- return {
45
- version: 1,
46
- type: 'doc',
47
- content: [{
48
- type: 'paragraph',
49
- content: [(0, _builders.code)(formatMessage(_messages.placeholderTextMessages.shortEmptyNodePlaceholderADFSlashShortcut)), (0, _builders.text)(' '), (0, _builders.text)(formatMessage(_messages.placeholderTextMessages.shortEmptyNodePlaceholderADFSuffix))]
50
- }]
51
- };
52
- };
53
- var createLongEmptyNodePlaceholderADF = function createLongEmptyNodePlaceholderADF(_ref2) {
54
- var formatMessage = _ref2.formatMessage;
55
- return {
56
- version: 1,
57
- type: 'doc',
58
- content: [{
59
- type: 'paragraph',
60
- 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))]
61
- }]
62
- };
63
- };
64
- var cycleThroughPlaceholderPrompts = function cycleThroughPlaceholderPrompts(placeholderPrompts, activeTypewriterTimeouts, placeholderNodeWithText) {
65
- var initialDelayWhenUserTypedAndDeleted = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : 0;
66
- var currentPromptIndex = 0;
67
- var displayedText = '';
68
- var animationTimeouts = [];
69
- var clearAllTimeouts = function clearAllTimeouts() {
70
- // @ts-ignore - Workaround for help-center local consumption
71
-
72
- animationTimeouts.forEach(function (timeoutId) {
73
- return clearTimeout(timeoutId);
74
- });
75
- animationTimeouts = [];
76
- };
77
- var scheduleTimeout = function scheduleTimeout(callback, delay) {
78
- var timeoutId = setTimeout(callback, delay);
79
- animationTimeouts.push(timeoutId);
80
- return timeoutId;
81
- };
82
- var _startAnimationCycle = function startAnimationCycle() {
83
- var currentPrompt = placeholderPrompts[currentPromptIndex];
84
- var characterIndex = 0;
85
- var _typeNextCharacter = function typeNextCharacter() {
86
- if (characterIndex < currentPrompt.length) {
87
- displayedText = currentPrompt.substring(0, characterIndex + 1);
88
- placeholderNodeWithText.textContent = displayedText;
89
- characterIndex++;
90
- scheduleTimeout(_typeNextCharacter, TYPEWRITER_TYPE_DELAY);
91
- } else {
92
- scheduleTimeout(_eraseLastCharacter, TYPEWRITER_PAUSE_BEFORE_ERASE);
93
- }
94
- };
95
- var _eraseLastCharacter = function eraseLastCharacter() {
96
- if (displayedText.length > 1) {
97
- displayedText = displayedText.substring(0, displayedText.length - 1);
98
- placeholderNodeWithText.textContent = displayedText;
99
- scheduleTimeout(_eraseLastCharacter, TYPEWRITER_ERASE_DELAY);
100
- } else {
101
- displayedText = ' ';
102
- placeholderNodeWithText.textContent = displayedText;
103
- currentPromptIndex = (currentPromptIndex + 1) % placeholderPrompts.length;
104
- scheduleTimeout(_startAnimationCycle, TYPEWRITER_CYCLE_DELAY);
105
- }
106
- };
107
- _typeNextCharacter();
108
- };
109
- activeTypewriterTimeouts === null || activeTypewriterTimeouts === void 0 || activeTypewriterTimeouts.push(clearAllTimeouts);
110
- if (initialDelayWhenUserTypedAndDeleted > 0) {
111
- placeholderNodeWithText.textContent = ' ';
112
- scheduleTimeout(_startAnimationCycle, initialDelayWhenUserTypedAndDeleted);
113
- } else {
114
- _startAnimationCycle();
115
- }
116
- };
117
- function createPlaceholderDecoration(editorState, placeholderText, placeholderPrompts, activeTypewriterTimeouts) {
118
- var pos = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : 1;
119
- var initialDelayWhenUserTypedAndDeleted = arguments.length > 5 && arguments[5] !== undefined ? arguments[5] : 0;
120
- var placeholderADF = arguments.length > 6 ? arguments[6] : undefined;
121
- var placeholderDecoration = document.createElement('span');
122
- var placeholderNodeWithText = placeholderDecoration;
123
- placeholderDecoration.setAttribute('data-testid', placeholderTestId);
124
- placeholderDecoration.className = 'placeholder-decoration';
125
- placeholderDecoration.setAttribute('aria-hidden', 'true');
126
-
127
- // PM sets contenteditable to false on Decorations so Firefox doesn't display the flashing cursor
128
- // So adding an extra span which will contain the placeholder text
129
- if (_utils.browser.gecko) {
130
- var placeholderNode = document.createElement('span');
131
- placeholderNode.setAttribute('contenteditable', 'true'); // explicitly overriding the default Decoration behaviour
132
- placeholderDecoration.appendChild(placeholderNode);
133
- placeholderNodeWithText = placeholderNode;
134
- }
135
- if (placeholderText) {
136
- placeholderNodeWithText.textContent = placeholderText || ' ';
137
- } else if (placeholderADF) {
138
- var serializer = _model.DOMSerializer.fromSchema(editorState.schema);
139
- // Get a PMNode from docnode
140
- var docNode = (0, _processRawValue.processRawValue)(editorState.schema, placeholderADF);
141
- if (docNode) {
142
- // Extract only the inline content from paragraphs, avoiding block-level elements
143
- // that can interfere with cursor rendering
144
- // @ts-ignore - Workaround for help-center local consumption
145
-
146
- docNode.children.forEach(function (node) {
147
- // For paragraph nodes, serialize their content (inline elements) directly
148
- // without the wrapping <p> tag
149
- if (node.type.name === 'paragraph') {
150
- // @ts-ignore - Workaround for help-center local consumption
151
-
152
- node.content.forEach(function (inlineNode) {
153
- var inlineDOM = serializer.serializeNode(inlineNode);
154
- placeholderNodeWithText.append(inlineDOM);
155
- });
156
- } else {
157
- // For non-paragraph nodes, serialize normally
158
- var nodeDOM = serializer.serializeNode(node);
159
- placeholderNodeWithText.append(nodeDOM);
160
- }
161
- });
162
- var markElements = placeholderNodeWithText.querySelectorAll('[data-prosemirror-content-type="mark"]');
163
- // @ts-ignore - Workaround for help-center local consumption
164
-
165
- markElements.forEach(function (markEl) {
166
- if (markEl instanceof HTMLElement) {
167
- markEl.style.setProperty('color', "var(--ds-text-subtlest, #6B6E76)");
168
- }
169
- });
170
- // Ensure all child elements don't block pointer events or cursor
171
- var allElements = placeholderNodeWithText.querySelectorAll('*');
172
- // @ts-ignore - Workaround for help-center local consumption
173
-
174
- allElements.forEach(function (el) {
175
- if (el instanceof HTMLElement) {
176
- el.style.pointerEvents = 'none';
177
- el.style.userSelect = 'none';
178
- }
179
- });
180
- }
181
- } else if (placeholderPrompts) {
182
- cycleThroughPlaceholderPrompts(placeholderPrompts, activeTypewriterTimeouts, placeholderNodeWithText, initialDelayWhenUserTypedAndDeleted);
183
- }
184
-
185
- // ME-2289 Tapping on backspace in empty editor hides and displays the keyboard
186
- // Add a editable buff node as the cursor moving forward is inevitable
187
- // when backspace in GBoard composition
188
- if (_utils.browser.android && _utils.browser.chrome) {
189
- var buffNode = document.createElement('span');
190
- buffNode.setAttribute('class', 'placeholder-android');
191
- buffNode.setAttribute('contenteditable', 'true');
192
- buffNode.textContent = ' ';
193
- placeholderDecoration.appendChild(buffNode);
194
- }
195
- var isTargetNested = editorState.doc.resolve(pos).depth > 1;
196
-
197
- // only truncate text for nested nodes, otherwise applying 'overflow: hidden;' to top level nodes
198
- // creates issues with quick insert button
199
- if (isTargetNested && (0, _experiments.editorExperiment)('platform_editor_controls', 'variant1')) {
200
- placeholderDecoration.classList.add('placeholder-decoration-hide-overflow');
201
- }
202
- return _view.DecorationSet.create(editorState.doc, [_view.Decoration.widget(pos, placeholderDecoration, {
203
- side: 0,
204
- key: "placeholder ".concat(placeholderText)
205
- })]);
206
- }
207
- function setPlaceHolderState(_ref3) {
208
- var placeholderText = _ref3.placeholderText,
209
- pos = _ref3.pos,
210
- placeholderPrompts = _ref3.placeholderPrompts,
211
- typedAndDeleted = _ref3.typedAndDeleted,
212
- userHadTyped = _ref3.userHadTyped,
213
- canShowOnEmptyParagraph = _ref3.canShowOnEmptyParagraph,
214
- showOnEmptyParagraph = _ref3.showOnEmptyParagraph,
215
- contextPlaceholderADF = _ref3.contextPlaceholderADF;
216
- return {
217
- hasPlaceholder: true,
218
- placeholderText: placeholderText,
219
- placeholderPrompts: placeholderPrompts,
220
- contextPlaceholderADF: contextPlaceholderADF,
221
- pos: pos ? pos : 1,
222
- typedAndDeleted: typedAndDeleted,
223
- userHadTyped: userHadTyped,
224
- canShowOnEmptyParagraph: canShowOnEmptyParagraph,
225
- showOnEmptyParagraph: showOnEmptyParagraph
226
- };
227
- }
228
- var emptyPlaceholder = function emptyPlaceholder(_ref4) {
229
- var placeholderText = _ref4.placeholderText,
230
- placeholderPrompts = _ref4.placeholderPrompts,
231
- userHadTyped = _ref4.userHadTyped,
232
- pos = _ref4.pos,
233
- canShowOnEmptyParagraph = _ref4.canShowOnEmptyParagraph,
234
- showOnEmptyParagraph = _ref4.showOnEmptyParagraph;
235
- return {
236
- hasPlaceholder: false,
237
- placeholderText: placeholderText,
238
- placeholderPrompts: placeholderPrompts,
239
- userHadTyped: userHadTyped,
240
- typedAndDeleted: false,
241
- canShowOnEmptyParagraph: canShowOnEmptyParagraph,
242
- showOnEmptyParagraph: showOnEmptyParagraph,
243
- pos: pos
244
- };
245
- };
246
- function createPlaceHolderStateFrom(_ref5) {
247
- var isInitial = _ref5.isInitial,
248
- isEditorFocused = _ref5.isEditorFocused,
249
- editorState = _ref5.editorState,
250
- isTypeAheadOpen = _ref5.isTypeAheadOpen,
251
- defaultPlaceholderText = _ref5.defaultPlaceholderText,
252
- intl = _ref5.intl,
253
- bracketPlaceholderText = _ref5.bracketPlaceholderText,
254
- emptyLinePlaceholder = _ref5.emptyLinePlaceholder,
255
- placeholderADF = _ref5.placeholderADF,
256
- placeholderPrompts = _ref5.placeholderPrompts,
257
- typedAndDeleted = _ref5.typedAndDeleted,
258
- userHadTyped = _ref5.userHadTyped,
259
- isPlaceholderHidden = _ref5.isPlaceholderHidden,
260
- withEmptyParagraph = _ref5.withEmptyParagraph,
261
- showOnEmptyParagraph = _ref5.showOnEmptyParagraph;
262
- if (isPlaceholderHidden && (0, _platformFeatureFlags.fg)('platform_editor_ai_aifc_patch_beta')) {
263
- return _objectSpread(_objectSpread({}, emptyPlaceholder({
264
- placeholderText: defaultPlaceholderText,
265
- placeholderPrompts: placeholderPrompts,
266
- userHadTyped: userHadTyped
267
- })), {}, {
268
- isPlaceholderHidden: isPlaceholderHidden
269
- });
270
- }
271
- if (isTypeAheadOpen !== null && isTypeAheadOpen !== void 0 && isTypeAheadOpen(editorState)) {
272
- return emptyPlaceholder({
273
- placeholderText: defaultPlaceholderText,
274
- placeholderPrompts: placeholderPrompts,
275
- userHadTyped: userHadTyped
276
- });
277
- }
278
- if ((defaultPlaceholderText || placeholderPrompts || placeholderADF) && (0, _utils.isEmptyDocument)(editorState.doc)) {
279
- return setPlaceHolderState({
280
- placeholderText: defaultPlaceholderText,
281
- pos: 1,
282
- placeholderPrompts: placeholderPrompts,
283
- typedAndDeleted: typedAndDeleted,
284
- userHadTyped: userHadTyped
285
- });
286
- }
287
- if ((0, _platformFeatureFlags.fg)('platform_editor_ai_aifc_patch_beta_2') || (0, _platformFeatureFlags.fg)('platform_editor_ai_aifc_patch_ga')) {
288
- var _editorState$selectio = editorState.selection,
289
- from = _editorState$selectio.from,
290
- to = _editorState$selectio.to,
291
- $to = _editorState$selectio.$to;
292
- if ((defaultPlaceholderText || placeholderADF) && withEmptyParagraph && isEditorFocused && !isInitial && !(0, _utils.isEmptyDocument)(editorState.doc) && from === to && (0, _utils.isEmptyParagraph)($to.parent) && (0, _utils.hasDocAsParent)($to)) {
293
- return showOnEmptyParagraph ? setPlaceHolderState({
294
- placeholderText: defaultPlaceholderText,
295
- pos: to,
296
- placeholderPrompts: placeholderPrompts,
297
- typedAndDeleted: typedAndDeleted,
298
- userHadTyped: userHadTyped,
299
- canShowOnEmptyParagraph: true,
300
- showOnEmptyParagraph: true
301
- }) : emptyPlaceholder({
302
- placeholderText: defaultPlaceholderText,
303
- placeholderPrompts: placeholderPrompts,
304
- userHadTyped: userHadTyped,
305
- canShowOnEmptyParagraph: true,
306
- showOnEmptyParagraph: false,
307
- pos: to
308
- });
309
- }
310
- }
311
- if (isEditorFocused && (0, _experiments.editorExperiment)('platform_editor_controls', 'variant1')) {
312
- var _parentNode$firstChil, _parentNode$firstChil2;
313
- var _editorState$selectio2 = editorState.selection,
314
- $from = _editorState$selectio2.$from,
315
- _$to = _editorState$selectio2.$to;
316
- if ($from.pos !== _$to.pos) {
317
- return emptyPlaceholder({
318
- placeholderText: defaultPlaceholderText,
319
- placeholderPrompts: placeholderPrompts,
320
- userHadTyped: userHadTyped
321
- });
322
- }
323
- var parentNode = $from.node($from.depth - 1);
324
- var parentType = parentNode === null || parentNode === void 0 ? void 0 : parentNode.type.name;
325
- if (emptyLinePlaceholder && parentType === 'doc') {
326
- var isEmptyLine = (0, _utils.isEmptyParagraph)($from.parent);
327
- if (isEmptyLine) {
328
- return setPlaceHolderState({
329
- placeholderText: emptyLinePlaceholder,
330
- pos: $from.pos,
331
- placeholderPrompts: placeholderPrompts,
332
- typedAndDeleted: typedAndDeleted,
333
- userHadTyped: userHadTyped
334
- });
335
- }
336
- }
337
- 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';
338
- if (nodeTypesWithShortPlaceholderText.includes(parentType) && isEmptyNode) {
339
- var _table$node$firstChil;
340
- var table = (0, _utils2.findParentNode)(function (node) {
341
- return node.type === editorState.schema.nodes.table;
342
- })(editorState.selection);
343
- if (!table) {
344
- return emptyPlaceholder({
345
- placeholderText: defaultPlaceholderText,
346
- placeholderPrompts: placeholderPrompts,
347
- userHadTyped: userHadTyped
348
- });
349
- }
350
- 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;
351
- if (isFirstCell) {
352
- return setPlaceHolderState({
353
- placeholderText: !(0, _platformFeatureFlags.fg)('platform_editor_ai_aifc_patch_ga') ? intl.formatMessage(_messages.placeholderTextMessages.shortEmptyNodePlaceholderText) : undefined,
354
- contextPlaceholderADF: (0, _platformFeatureFlags.fg)('platform_editor_ai_aifc_patch_ga') ? createShortEmptyNodePlaceholderADF(intl) : undefined,
355
- pos: $from.pos,
356
- placeholderPrompts: placeholderPrompts,
357
- typedAndDeleted: typedAndDeleted,
358
- userHadTyped: userHadTyped
359
- });
360
- }
361
- }
362
- if (nodeTypesWithLongPlaceholderText.includes(parentType) && isEmptyNode) {
363
- return setPlaceHolderState({
364
- placeholderText: !(0, _platformFeatureFlags.fg)('platform_editor_ai_aifc_patch_ga') ? intl.formatMessage(_messages.placeholderTextMessages.longEmptyNodePlaceholderText) : undefined,
365
- contextPlaceholderADF: (0, _platformFeatureFlags.fg)('platform_editor_ai_aifc_patch_ga') ? createLongEmptyNodePlaceholderADF(intl) : undefined,
366
- pos: $from.pos,
367
- placeholderPrompts: placeholderPrompts,
368
- typedAndDeleted: typedAndDeleted,
369
- userHadTyped: userHadTyped
370
- });
371
- }
372
- if (nodeTypesWithSyncBlockPlaceholderText.includes(parentType) && isEmptyNode && (0, _experiments.editorExperiment)('platform_synced_block', true)) {
373
- return setPlaceHolderState({
374
- placeholderText: intl.formatMessage(_messages.placeholderTextMessages.syncBlockPlaceholderText),
375
- pos: $from.pos,
376
- placeholderPrompts: placeholderPrompts,
377
- typedAndDeleted: typedAndDeleted,
378
- userHadTyped: userHadTyped
379
- });
380
- }
381
- return emptyPlaceholder({
382
- placeholderText: defaultPlaceholderText,
383
- placeholderPrompts: placeholderPrompts,
384
- userHadTyped: userHadTyped
385
- });
386
- }
387
- if (bracketPlaceholderText && (0, _utils.bracketTyped)(editorState) && isEditorFocused) {
388
- var _$from = editorState.selection.$from;
389
- // Space is to account for positioning of the bracket
390
- var bracketHint = ' ' + bracketPlaceholderText;
391
- return setPlaceHolderState({
392
- placeholderText: bracketHint,
393
- pos: _$from.pos - 1,
394
- placeholderPrompts: placeholderPrompts,
395
- typedAndDeleted: typedAndDeleted,
396
- userHadTyped: userHadTyped
15
+ var placeholderPlugin = exports.placeholderPlugin = function placeholderPlugin(_ref) {
16
+ var options = _ref.config,
17
+ api = _ref.api;
18
+ if (!(0, _platformFeatureFlags.fg)('platform_editor_placeholder_plugin_tidying')) {
19
+ return (0, _placeholderPluginLegacy.placeholderPluginLegacy)({
20
+ config: options,
21
+ api: api
397
22
  });
398
23
  }
399
- return emptyPlaceholder({
400
- placeholderText: defaultPlaceholderText,
401
- placeholderPrompts: placeholderPrompts,
402
- userHadTyped: userHadTyped
403
- });
404
- }
405
- function calculateUserInteractionState(_ref6) {
406
- var placeholderState = _ref6.placeholderState,
407
- oldEditorState = _ref6.oldEditorState,
408
- newEditorState = _ref6.newEditorState;
409
- var wasEmpty = oldEditorState ? (0, _utils.isEmptyDocument)(oldEditorState.doc) : true;
410
- var isEmpty = (0, _utils.isEmptyDocument)(newEditorState.doc);
411
- var hasEverTyped = Boolean(placeholderState === null || placeholderState === void 0 ? void 0 : placeholderState.userHadTyped) ||
412
- // Previously typed
413
- !wasEmpty ||
414
- // Had content before
415
- wasEmpty && !isEmpty; // Just added content
416
- var justDeletedAll = hasEverTyped && isEmpty && !wasEmpty;
417
- var isInTypedAndDeletedState = justDeletedAll || Boolean(placeholderState === null || placeholderState === void 0 ? void 0 : placeholderState.typedAndDeleted) && isEmpty;
418
- // Only reset user interaction tracking when editor is cleanly empty
419
- var shouldResetInteraction = isEmpty && !isInTypedAndDeletedState;
420
- return {
421
- userHadTyped: shouldResetInteraction ? false : hasEverTyped,
422
- typedAndDeleted: isInTypedAndDeletedState
423
- };
424
- }
425
- function createPlugin(intl, defaultPlaceholderText, bracketPlaceholderText, emptyLinePlaceholder, placeholderPrompts, withEmptyParagraph, placeholderADF, api) {
426
- if (!defaultPlaceholderText && !placeholderPrompts && !bracketPlaceholderText && !placeholderADF) {
427
- return;
428
- }
429
- var isDestroyed = false;
430
- var activeTypewriterTimeouts = [];
431
- var clearAllTypewriterTimeouts = function clearAllTypewriterTimeouts() {
432
- // @ts-ignore - Workaround for help-center local consumption
433
-
434
- activeTypewriterTimeouts.forEach(function (clearFn) {
435
- return clearFn();
436
- });
437
- activeTypewriterTimeouts = [];
438
- };
439
- return new _safePlugin.SafePlugin({
440
- key: pluginKey,
441
- state: {
442
- // @ts-ignore - Workaround for help-center local consumption
443
-
444
- init: function init(_, state) {
445
- var _api$focus, _api$typeAhead;
446
- return createPlaceHolderStateFrom({
447
- isInitial: true,
448
- 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),
449
- editorState: state,
450
- isTypeAheadOpen: api === null || api === void 0 || (_api$typeAhead = api.typeAhead) === null || _api$typeAhead === void 0 ? void 0 : _api$typeAhead.actions.isOpen,
451
- defaultPlaceholderText: defaultPlaceholderText,
452
- bracketPlaceholderText: bracketPlaceholderText,
453
- emptyLinePlaceholder: emptyLinePlaceholder,
454
- placeholderADF: placeholderADF,
455
- placeholderPrompts: placeholderPrompts,
456
- typedAndDeleted: false,
457
- userHadTyped: false,
458
- intl: intl
459
- });
460
- },
461
- // @ts-ignore - Workaround for help-center local consumption
462
-
463
- apply: function apply(tr, placeholderState, _oldEditorState, newEditorState) {
464
- var _api$focus2, _placeholderState$isP, _api$typeAhead2, _ref7, _meta$placeholderText, _ref8, _meta$placeholderProm, _meta$showOnEmptyPara;
465
- var meta = tr.getMeta(pluginKey);
466
- 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);
467
- var _calculateUserInterac = calculateUserInteractionState({
468
- placeholderState: placeholderState,
469
- oldEditorState: _oldEditorState,
470
- newEditorState: newEditorState
471
- }),
472
- userHadTyped = _calculateUserInterac.userHadTyped,
473
- typedAndDeleted = _calculateUserInterac.typedAndDeleted;
474
- var isPlaceholderHidden = (_placeholderState$isP = placeholderState === null || placeholderState === void 0 ? void 0 : placeholderState.isPlaceholderHidden) !== null && _placeholderState$isP !== void 0 ? _placeholderState$isP : false;
475
- if ((meta === null || meta === void 0 ? void 0 : meta.isPlaceholderHidden) !== undefined && (0, _platformFeatureFlags.fg)('platform_editor_ai_aifc_patch_beta')) {
476
- isPlaceholderHidden = meta.isPlaceholderHidden;
477
- }
478
- 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'))) {
479
- // Only update defaultPlaceholderText from meta if we're not using ADF placeholder
480
- if (!((0, _platformFeatureFlags.fg)('platform_editor_ai_aifc_patch_ga') && placeholderADF)) {
481
- defaultPlaceholderText = meta.placeholderText;
482
- }
483
- }
484
- var newPlaceholderState = createPlaceHolderStateFrom({
485
- isEditorFocused: isEditorFocused,
486
- editorState: newEditorState,
487
- isTypeAheadOpen: api === null || api === void 0 || (_api$typeAhead2 = api.typeAhead) === null || _api$typeAhead2 === void 0 ? void 0 : _api$typeAhead2.actions.isOpen,
488
- 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,
489
- bracketPlaceholderText: bracketPlaceholderText,
490
- emptyLinePlaceholder: emptyLinePlaceholder,
491
- placeholderADF: placeholderADF,
492
- 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,
493
- typedAndDeleted: typedAndDeleted,
494
- userHadTyped: userHadTyped,
495
- intl: intl,
496
- isPlaceholderHidden: isPlaceholderHidden,
497
- withEmptyParagraph: withEmptyParagraph,
498
- 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
499
- });
500
-
501
- // Clear timeouts when hasPlaceholder becomes false
502
- if (!newPlaceholderState.hasPlaceholder) {
503
- clearAllTypewriterTimeouts();
504
- }
505
- return newPlaceholderState;
506
- }
507
- },
508
- props: {
509
- // @ts-ignore - Workaround for help-center local consumption
510
- decorations: function decorations(editorState) {
511
- var _api$composition, _api$showDiff;
512
- var _getPlaceholderState = getPlaceholderState(editorState),
513
- hasPlaceholder = _getPlaceholderState.hasPlaceholder,
514
- placeholderText = _getPlaceholderState.placeholderText,
515
- pos = _getPlaceholderState.pos,
516
- typedAndDeleted = _getPlaceholderState.typedAndDeleted,
517
- contextPlaceholderADF = _getPlaceholderState.contextPlaceholderADF;
518
-
519
- // Decorations is still called after plugin is destroyed
520
- // So we need to make sure decorations is not called if plugin has been destroyed to prevent the placeholder animations' setTimeouts called infinitely
521
- if (isDestroyed) {
522
- return;
523
- }
524
- var compositionPluginState = api === null || api === void 0 || (_api$composition = api.composition) === null || _api$composition === void 0 ? void 0 : _api$composition.sharedState.currentState();
525
- 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);
526
- if (hasPlaceholder && ((placeholderText !== null && placeholderText !== void 0 ? placeholderText : '') || placeholderPrompts || placeholderADF || contextPlaceholderADF) && pos !== undefined && !(compositionPluginState !== null && compositionPluginState !== void 0 && compositionPluginState.isComposing) && !isShowingDiff) {
527
- var initialDelayWhenUserTypedAndDeleted = typedAndDeleted ? TYPEWRITER_TYPED_AND_DELETED_DELAY : 0;
528
- // contextPlaceholderADF takes precedence over the global placeholderADF
529
- var placeholderAdfToUse = contextPlaceholderADF || placeholderADF;
530
- return createPlaceholderDecoration(editorState, placeholderText !== null && placeholderText !== void 0 ? placeholderText : '', placeholderPrompts, activeTypewriterTimeouts, pos, initialDelayWhenUserTypedAndDeleted, placeholderAdfToUse);
531
- }
532
- return;
533
- }
534
- },
535
- // @ts-ignore - Workaround for help-center local consumption
536
- view: function view() {
537
- var timeoutId;
538
- function startEmptyParagraphTimeout(editorView) {
539
- if (timeoutId) {
540
- return;
541
- }
542
- timeoutId = setTimeout(function () {
543
- timeoutId = undefined;
544
- editorView.dispatch(editorView.state.tr.setMeta(pluginKey, {
545
- showOnEmptyParagraph: true
546
- }));
547
- }, EMPTY_PARAGRAPH_TIMEOUT_DELAY);
548
- }
549
- function destroyEmptyParagraphTimeout() {
550
- if (timeoutId) {
551
- clearTimeout(timeoutId);
552
- timeoutId = undefined;
553
- }
554
- }
555
- return {
556
- // @ts-ignore - Workaround for help-center local consumption
557
- update: function update(editorView, prevState) {
558
- if ((0, _platformFeatureFlags.fg)('platform_editor_ai_aifc_patch_beta_2') || (0, _platformFeatureFlags.fg)('platform_editor_ai_aifc_patch_ga')) {
559
- var prevPluginState = getPlaceholderState(prevState);
560
- var newPluginState = getPlaceholderState(editorView.state);
561
-
562
- // user start typing after move to an empty paragraph, clear timeout
563
- if (!newPluginState.canShowOnEmptyParagraph && timeoutId) {
564
- destroyEmptyParagraphTimeout();
565
- }
566
- // user move to an empty paragraph again, reset state to hide placeholder, and restart timeout
567
- else if (prevPluginState.canShowOnEmptyParagraph && newPluginState.canShowOnEmptyParagraph && newPluginState.pos !== prevPluginState.pos) {
568
- editorView.dispatch(editorView.state.tr.setMeta(pluginKey, {
569
- showOnEmptyParagraph: false
570
- }));
571
- destroyEmptyParagraphTimeout();
572
- startEmptyParagraphTimeout(editorView);
573
- }
574
- // user move to an empty paragraph (by click enter or move to an empty paragraph), start timeout
575
- else if (!prevPluginState.canShowOnEmptyParagraph && newPluginState.canShowOnEmptyParagraph && !newPluginState.showOnEmptyParagraph && !timeoutId) {
576
- startEmptyParagraphTimeout(editorView);
577
- }
578
- }
579
- },
580
- // @ts-ignore - Workaround for help-center local consumption
581
- destroy: function destroy() {
582
- clearAllTypewriterTimeouts();
583
- destroyEmptyParagraphTimeout();
584
- isDestroyed = true;
585
- }
586
- };
587
- }
588
- });
589
- }
590
- var placeholderPlugin = exports.placeholderPlugin = function placeholderPlugin(_ref9) {
591
- var options = _ref9.config,
592
- api = _ref9.api;
593
24
  var currentPlaceholder = options === null || options === void 0 ? void 0 : options.placeholder;
594
25
  return {
595
26
  name: 'placeholder',
596
27
  commands: {
597
28
  setPlaceholder: function setPlaceholder(placeholderText) {
598
- return function (_ref0) {
599
- var tr = _ref0.tr;
29
+ return function (_ref2) {
30
+ var tr = _ref2.tr;
600
31
  if (currentPlaceholder !== placeholderText) {
601
32
  currentPlaceholder = placeholderText;
602
33
  return tr.setMeta(pluginKey, {
@@ -607,16 +38,16 @@ var placeholderPlugin = exports.placeholderPlugin = function placeholderPlugin(_
607
38
  };
608
39
  },
609
40
  setAnimatingPlaceholderPrompts: function setAnimatingPlaceholderPrompts(placeholderPrompts) {
610
- return function (_ref1) {
611
- var tr = _ref1.tr;
41
+ return function (_ref3) {
42
+ var tr = _ref3.tr;
612
43
  return tr.setMeta(pluginKey, {
613
44
  placeholderPrompts: placeholderPrompts
614
45
  });
615
46
  };
616
47
  },
617
48
  setPlaceholderHidden: function setPlaceholderHidden(isPlaceholderHidden) {
618
- return function (_ref10) {
619
- var tr = _ref10.tr;
49
+ return function (_ref4) {
50
+ var tr = _ref4.tr;
620
51
  return tr.setMeta(pluginKey, {
621
52
  isPlaceholderHidden: isPlaceholderHidden
622
53
  });
@@ -626,9 +57,9 @@ var placeholderPlugin = exports.placeholderPlugin = function placeholderPlugin(_
626
57
  pmPlugins: function pmPlugins() {
627
58
  return [{
628
59
  name: 'placeholder',
629
- plugin: function plugin(_ref11) {
630
- var getIntl = _ref11.getIntl;
631
- 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);
60
+ plugin: function plugin(_ref5) {
61
+ var getIntl = _ref5.getIntl;
62
+ return (0, _main.default)(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);
632
63
  }
633
64
  }];
634
65
  }