@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
@@ -0,0 +1,30 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.createShortEmptyNodePlaceholderADF = exports.createLongEmptyNodePlaceholderADF = void 0;
7
+ var _builders = require("@atlaskit/adf-utils/builders");
8
+ var _messages = require("@atlaskit/editor-common/messages");
9
+ var createShortEmptyNodePlaceholderADF = exports.createShortEmptyNodePlaceholderADF = function createShortEmptyNodePlaceholderADF(_ref) {
10
+ var formatMessage = _ref.formatMessage;
11
+ return {
12
+ version: 1,
13
+ type: 'doc',
14
+ content: [{
15
+ type: 'paragraph',
16
+ content: [(0, _builders.code)(formatMessage(_messages.placeholderTextMessages.shortEmptyNodePlaceholderADFSlashShortcut)), (0, _builders.text)(' '), (0, _builders.text)(formatMessage(_messages.placeholderTextMessages.shortEmptyNodePlaceholderADFSuffix))]
17
+ }]
18
+ };
19
+ };
20
+ var createLongEmptyNodePlaceholderADF = exports.createLongEmptyNodePlaceholderADF = function createLongEmptyNodePlaceholderADF(_ref2) {
21
+ var formatMessage = _ref2.formatMessage;
22
+ return {
23
+ version: 1,
24
+ type: 'doc',
25
+ content: [{
26
+ type: 'paragraph',
27
+ 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))]
28
+ }]
29
+ };
30
+ };
@@ -0,0 +1,58 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.cycleThroughPlaceholderPrompts = void 0;
7
+ var _constants = require("./constants");
8
+ var cycleThroughPlaceholderPrompts = exports.cycleThroughPlaceholderPrompts = function cycleThroughPlaceholderPrompts(placeholderPrompts, activeTypewriterTimeouts, placeholderNodeWithText) {
9
+ var initialDelayWhenUserTypedAndDeleted = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : 0;
10
+ var currentPromptIndex = 0;
11
+ var displayedText = '';
12
+ var animationTimeouts = [];
13
+ var clearAllTimeouts = function clearAllTimeouts() {
14
+ animationTimeouts.forEach(function (timeoutId) {
15
+ return clearTimeout(timeoutId);
16
+ });
17
+ animationTimeouts = [];
18
+ };
19
+ var scheduleTimeout = function scheduleTimeout(callback, delay) {
20
+ var timeoutId = setTimeout(callback, delay);
21
+ animationTimeouts.push(timeoutId);
22
+ return timeoutId;
23
+ };
24
+ var _startAnimationCycle = function startAnimationCycle() {
25
+ var currentPrompt = placeholderPrompts[currentPromptIndex];
26
+ var characterIndex = 0;
27
+ var _typeNextCharacter = function typeNextCharacter() {
28
+ if (characterIndex < currentPrompt.length) {
29
+ displayedText = currentPrompt.substring(0, characterIndex + 1);
30
+ placeholderNodeWithText.textContent = displayedText;
31
+ characterIndex++;
32
+ scheduleTimeout(_typeNextCharacter, _constants.TYPEWRITER_TYPE_DELAY);
33
+ } else {
34
+ scheduleTimeout(_eraseLastCharacter, _constants.TYPEWRITER_PAUSE_BEFORE_ERASE);
35
+ }
36
+ };
37
+ var _eraseLastCharacter = function eraseLastCharacter() {
38
+ if (displayedText.length > 1) {
39
+ displayedText = displayedText.substring(0, displayedText.length - 1);
40
+ placeholderNodeWithText.textContent = displayedText;
41
+ scheduleTimeout(_eraseLastCharacter, _constants.TYPEWRITER_ERASE_DELAY);
42
+ } else {
43
+ displayedText = ' ';
44
+ placeholderNodeWithText.textContent = displayedText;
45
+ currentPromptIndex = (currentPromptIndex + 1) % placeholderPrompts.length;
46
+ scheduleTimeout(_startAnimationCycle, _constants.TYPEWRITER_CYCLE_DELAY);
47
+ }
48
+ };
49
+ _typeNextCharacter();
50
+ };
51
+ activeTypewriterTimeouts === null || activeTypewriterTimeouts === void 0 || activeTypewriterTimeouts.push(clearAllTimeouts);
52
+ if (initialDelayWhenUserTypedAndDeleted > 0) {
53
+ placeholderNodeWithText.textContent = ' ';
54
+ scheduleTimeout(_startAnimationCycle, initialDelayWhenUserTypedAndDeleted);
55
+ } else {
56
+ _startAnimationCycle();
57
+ }
58
+ };
@@ -0,0 +1,18 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.placeholderTestId = exports.nodeTypesWithSyncBlockPlaceholderText = exports.nodeTypesWithShortPlaceholderText = exports.nodeTypesWithLongPlaceholderText = exports.TYPEWRITER_TYPE_DELAY = exports.TYPEWRITER_TYPED_AND_DELETED_DELAY = exports.TYPEWRITER_PAUSE_BEFORE_ERASE = exports.TYPEWRITER_ERASE_DELAY = exports.TYPEWRITER_CYCLE_DELAY = void 0;
7
+ var placeholderTestId = exports.placeholderTestId = 'placeholder-test-id';
8
+
9
+ // Typewriter animation timing constants
10
+ var TYPEWRITER_TYPE_DELAY = exports.TYPEWRITER_TYPE_DELAY = 50; // Delay between typing each character
11
+ var TYPEWRITER_PAUSE_BEFORE_ERASE = exports.TYPEWRITER_PAUSE_BEFORE_ERASE = 2000; // Pause before starting to erase text
12
+ var TYPEWRITER_ERASE_DELAY = exports.TYPEWRITER_ERASE_DELAY = 40; // Delay between erasing each character
13
+ var TYPEWRITER_CYCLE_DELAY = exports.TYPEWRITER_CYCLE_DELAY = 500; // Delay before starting next cycle
14
+ var TYPEWRITER_TYPED_AND_DELETED_DELAY = exports.TYPEWRITER_TYPED_AND_DELETED_DELAY = 1500; // Delay before starting animation after user typed and deleted
15
+
16
+ var nodeTypesWithLongPlaceholderText = exports.nodeTypesWithLongPlaceholderText = ['expand', 'panel'];
17
+ var nodeTypesWithShortPlaceholderText = exports.nodeTypesWithShortPlaceholderText = ['tableCell', 'tableHeader'];
18
+ var nodeTypesWithSyncBlockPlaceholderText = exports.nodeTypesWithSyncBlockPlaceholderText = ['bodiedSyncBlock'];
@@ -0,0 +1,96 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.createPlaceholderDecoration = createPlaceholderDecoration;
7
+ var _processRawValue = require("@atlaskit/editor-common/process-raw-value");
8
+ var _utils = require("@atlaskit/editor-common/utils");
9
+ var _model = require("@atlaskit/editor-prosemirror/model");
10
+ var _view = require("@atlaskit/editor-prosemirror/view");
11
+ var _experiments = require("@atlaskit/tmp-editor-statsig/experiments");
12
+ var _animation = require("./animation");
13
+ var _constants = require("./constants");
14
+ function createPlaceholderDecoration(editorState, placeholderText, placeholderPrompts, activeTypewriterTimeouts) {
15
+ var pos = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : 1;
16
+ var initialDelayWhenUserTypedAndDeleted = arguments.length > 5 && arguments[5] !== undefined ? arguments[5] : 0;
17
+ var placeholderADF = arguments.length > 6 ? arguments[6] : undefined;
18
+ var placeholderDecoration = document.createElement('span');
19
+ var placeholderNodeWithText = placeholderDecoration;
20
+ placeholderDecoration.setAttribute('data-testid', _constants.placeholderTestId);
21
+ placeholderDecoration.className = 'placeholder-decoration';
22
+ placeholderDecoration.setAttribute('aria-hidden', 'true');
23
+
24
+ // PM sets contenteditable to false on Decorations so Firefox doesn't display the flashing cursor
25
+ // So adding an extra span which will contain the placeholder text
26
+ if (_utils.browser.gecko) {
27
+ var placeholderNode = document.createElement('span');
28
+ placeholderNode.setAttribute('contenteditable', 'true'); // explicitly overriding the default Decoration behaviour
29
+ placeholderDecoration.appendChild(placeholderNode);
30
+ placeholderNodeWithText = placeholderNode;
31
+ }
32
+ if (placeholderText) {
33
+ placeholderNodeWithText.textContent = placeholderText || ' ';
34
+ } else if (placeholderADF) {
35
+ var serializer = _model.DOMSerializer.fromSchema(editorState.schema);
36
+ // Get a PMNode from docnode
37
+ var docNode = (0, _processRawValue.processRawValue)(editorState.schema, placeholderADF);
38
+ if (docNode) {
39
+ // Extract only the inline content from paragraphs, avoiding block-level elements
40
+ // that can interfere with cursor rendering
41
+
42
+ docNode.children.forEach(function (node) {
43
+ // For paragraph nodes, serialize their content (inline elements) directly
44
+ // without the wrapping <p> tag
45
+ if (node.type.name === 'paragraph') {
46
+ node.content.forEach(function (inlineNode) {
47
+ var inlineDOM = serializer.serializeNode(inlineNode);
48
+ placeholderNodeWithText.append(inlineDOM);
49
+ });
50
+ } else {
51
+ // For non-paragraph nodes, serialize normally
52
+ var nodeDOM = serializer.serializeNode(node);
53
+ placeholderNodeWithText.append(nodeDOM);
54
+ }
55
+ });
56
+ var markElements = placeholderNodeWithText.querySelectorAll('[data-prosemirror-content-type="mark"]');
57
+ markElements.forEach(function (markEl) {
58
+ if (markEl instanceof HTMLElement) {
59
+ markEl.style.setProperty('color', "var(--ds-text-subtlest, #6B6E76)");
60
+ }
61
+ });
62
+ // Ensure all child elements don't block pointer events or cursor
63
+ var allElements = placeholderNodeWithText.querySelectorAll('*');
64
+ allElements.forEach(function (el) {
65
+ if (el instanceof HTMLElement) {
66
+ el.style.pointerEvents = 'none';
67
+ el.style.userSelect = 'none';
68
+ }
69
+ });
70
+ }
71
+ } else if (placeholderPrompts) {
72
+ (0, _animation.cycleThroughPlaceholderPrompts)(placeholderPrompts, activeTypewriterTimeouts, placeholderNodeWithText, initialDelayWhenUserTypedAndDeleted);
73
+ }
74
+
75
+ // ME-2289 Tapping on backspace in empty editor hides and displays the keyboard
76
+ // Add a editable buff node as the cursor moving forward is inevitable
77
+ // when backspace in GBoard composition
78
+ if (_utils.browser.android && _utils.browser.chrome) {
79
+ var buffNode = document.createElement('span');
80
+ buffNode.setAttribute('class', 'placeholder-android');
81
+ buffNode.setAttribute('contenteditable', 'true');
82
+ buffNode.textContent = ' ';
83
+ placeholderDecoration.appendChild(buffNode);
84
+ }
85
+ var isTargetNested = editorState.doc.resolve(pos).depth > 1;
86
+
87
+ // only truncate text for nested nodes, otherwise applying 'overflow: hidden;' to top level nodes
88
+ // creates issues with quick insert button
89
+ if (isTargetNested && (0, _experiments.editorExperiment)('platform_editor_controls', 'variant1')) {
90
+ placeholderDecoration.classList.add('placeholder-decoration-hide-overflow');
91
+ }
92
+ return _view.DecorationSet.create(editorState.doc, [_view.Decoration.widget(pos, placeholderDecoration, {
93
+ side: 0,
94
+ key: "placeholder ".concat(placeholderText)
95
+ })]);
96
+ }
@@ -0,0 +1,167 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = createPlugin;
7
+ var _safePlugin = require("@atlaskit/editor-common/safe-plugin");
8
+ var _platformFeatureFlags = require("@atlaskit/platform-feature-flags");
9
+ var _placeholderPlugin = require("../placeholderPlugin");
10
+ var _constants = require("./constants");
11
+ var _decorations = require("./decorations");
12
+ var _utils = require("./utils");
13
+ function createPlugin(intl, defaultPlaceholderText, bracketPlaceholderText, emptyLinePlaceholder, placeholderPrompts, withEmptyParagraph, placeholderADF, api) {
14
+ if (!defaultPlaceholderText && !placeholderPrompts && !bracketPlaceholderText && !placeholderADF) {
15
+ return;
16
+ }
17
+ var isDestroyed = false;
18
+ var activeTypewriterTimeouts = [];
19
+ var clearAllTypewriterTimeouts = function clearAllTypewriterTimeouts() {
20
+ activeTypewriterTimeouts.forEach(function (clearFn) {
21
+ return clearFn();
22
+ });
23
+ activeTypewriterTimeouts = [];
24
+ };
25
+ return new _safePlugin.SafePlugin({
26
+ key: _placeholderPlugin.pluginKey,
27
+ state: {
28
+ init: function init(_, state) {
29
+ var _api$focus, _api$typeAhead;
30
+ return (0, _utils.createPlaceHolderStateFrom)({
31
+ isInitial: true,
32
+ 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),
33
+ editorState: state,
34
+ isTypeAheadOpen: api === null || api === void 0 || (_api$typeAhead = api.typeAhead) === null || _api$typeAhead === void 0 ? void 0 : _api$typeAhead.actions.isOpen,
35
+ defaultPlaceholderText: defaultPlaceholderText,
36
+ bracketPlaceholderText: bracketPlaceholderText,
37
+ emptyLinePlaceholder: emptyLinePlaceholder,
38
+ placeholderADF: placeholderADF,
39
+ placeholderPrompts: placeholderPrompts,
40
+ typedAndDeleted: false,
41
+ userHadTyped: false,
42
+ intl: intl
43
+ });
44
+ },
45
+ apply: function apply(tr, placeholderState, _oldEditorState, newEditorState) {
46
+ var _api$focus2, _placeholderState$isP, _api$typeAhead2, _ref, _meta$placeholderText, _ref2, _meta$placeholderProm, _meta$showOnEmptyPara;
47
+ var meta = tr.getMeta(_placeholderPlugin.pluginKey);
48
+ 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);
49
+ var _calculateUserInterac = (0, _utils.calculateUserInteractionState)({
50
+ placeholderState: placeholderState,
51
+ oldEditorState: _oldEditorState,
52
+ newEditorState: newEditorState
53
+ }),
54
+ userHadTyped = _calculateUserInterac.userHadTyped,
55
+ typedAndDeleted = _calculateUserInterac.typedAndDeleted;
56
+ var isPlaceholderHidden = (_placeholderState$isP = placeholderState === null || placeholderState === void 0 ? void 0 : placeholderState.isPlaceholderHidden) !== null && _placeholderState$isP !== void 0 ? _placeholderState$isP : false;
57
+ if ((meta === null || meta === void 0 ? void 0 : meta.isPlaceholderHidden) !== undefined && (0, _platformFeatureFlags.fg)('platform_editor_ai_aifc_patch_beta')) {
58
+ isPlaceholderHidden = meta.isPlaceholderHidden;
59
+ }
60
+ 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'))) {
61
+ // Only update defaultPlaceholderText from meta if we're not using ADF placeholder
62
+ if (!((0, _platformFeatureFlags.fg)('platform_editor_ai_aifc_patch_ga') && placeholderADF)) {
63
+ defaultPlaceholderText = meta.placeholderText;
64
+ }
65
+ }
66
+ var newPlaceholderState = (0, _utils.createPlaceHolderStateFrom)({
67
+ isEditorFocused: isEditorFocused,
68
+ editorState: newEditorState,
69
+ isTypeAheadOpen: api === null || api === void 0 || (_api$typeAhead2 = api.typeAhead) === null || _api$typeAhead2 === void 0 ? void 0 : _api$typeAhead2.actions.isOpen,
70
+ defaultPlaceholderText: (0, _platformFeatureFlags.fg)('platform_editor_ai_aifc_patch_beta_2') || (0, _platformFeatureFlags.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,
71
+ bracketPlaceholderText: bracketPlaceholderText,
72
+ emptyLinePlaceholder: emptyLinePlaceholder,
73
+ placeholderADF: placeholderADF,
74
+ 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,
75
+ typedAndDeleted: typedAndDeleted,
76
+ userHadTyped: userHadTyped,
77
+ intl: intl,
78
+ isPlaceholderHidden: isPlaceholderHidden,
79
+ withEmptyParagraph: withEmptyParagraph,
80
+ 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
81
+ });
82
+
83
+ // Clear timeouts when hasPlaceholder becomes false
84
+ if (!newPlaceholderState.hasPlaceholder) {
85
+ clearAllTypewriterTimeouts();
86
+ }
87
+ return newPlaceholderState;
88
+ }
89
+ },
90
+ props: {
91
+ decorations: function decorations(editorState) {
92
+ var _api$composition, _api$showDiff;
93
+ var _getPlaceholderState = (0, _utils.getPlaceholderState)(editorState),
94
+ hasPlaceholder = _getPlaceholderState.hasPlaceholder,
95
+ placeholderText = _getPlaceholderState.placeholderText,
96
+ pos = _getPlaceholderState.pos,
97
+ typedAndDeleted = _getPlaceholderState.typedAndDeleted,
98
+ contextPlaceholderADF = _getPlaceholderState.contextPlaceholderADF;
99
+
100
+ // Decorations is still called after plugin is destroyed
101
+ // So we need to make sure decorations is not called if plugin has been destroyed to prevent the placeholder animations' setTimeouts called infinitely
102
+ if (isDestroyed) {
103
+ return;
104
+ }
105
+ var compositionPluginState = api === null || api === void 0 || (_api$composition = api.composition) === null || _api$composition === void 0 ? void 0 : _api$composition.sharedState.currentState();
106
+ 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);
107
+ if (hasPlaceholder && ((placeholderText !== null && placeholderText !== void 0 ? placeholderText : '') || placeholderPrompts || placeholderADF || contextPlaceholderADF) && pos !== undefined && !(compositionPluginState !== null && compositionPluginState !== void 0 && compositionPluginState.isComposing) && !isShowingDiff) {
108
+ var initialDelayWhenUserTypedAndDeleted = typedAndDeleted ? _constants.TYPEWRITER_TYPED_AND_DELETED_DELAY : 0;
109
+ // contextPlaceholderADF takes precedence over the global placeholderADF
110
+ var placeholderAdfToUse = contextPlaceholderADF || placeholderADF;
111
+ return (0, _decorations.createPlaceholderDecoration)(editorState, placeholderText !== null && placeholderText !== void 0 ? placeholderText : '', placeholderPrompts, activeTypewriterTimeouts, pos, initialDelayWhenUserTypedAndDeleted, placeholderAdfToUse);
112
+ }
113
+ return;
114
+ }
115
+ },
116
+ view: function view() {
117
+ var timeoutId;
118
+ function startEmptyParagraphTimeout(editorView) {
119
+ if (timeoutId) {
120
+ return;
121
+ }
122
+ timeoutId = setTimeout(function () {
123
+ timeoutId = undefined;
124
+ editorView.dispatch(editorView.state.tr.setMeta(_placeholderPlugin.pluginKey, {
125
+ showOnEmptyParagraph: true
126
+ }));
127
+ }, _placeholderPlugin.EMPTY_PARAGRAPH_TIMEOUT_DELAY);
128
+ }
129
+ function destroyEmptyParagraphTimeout() {
130
+ if (timeoutId) {
131
+ clearTimeout(timeoutId);
132
+ timeoutId = undefined;
133
+ }
134
+ }
135
+ return {
136
+ update: function update(editorView, prevState) {
137
+ if ((0, _platformFeatureFlags.fg)('platform_editor_ai_aifc_patch_beta_2') || (0, _platformFeatureFlags.fg)('platform_editor_ai_aifc_patch_ga')) {
138
+ var prevPluginState = (0, _utils.getPlaceholderState)(prevState);
139
+ var newPluginState = (0, _utils.getPlaceholderState)(editorView.state);
140
+
141
+ // user start typing after move to an empty paragraph, clear timeout
142
+ if (!newPluginState.canShowOnEmptyParagraph && timeoutId) {
143
+ destroyEmptyParagraphTimeout();
144
+ }
145
+ // user move to an empty paragraph again, reset state to hide placeholder, and restart timeout
146
+ else if (prevPluginState.canShowOnEmptyParagraph && newPluginState.canShowOnEmptyParagraph && newPluginState.pos !== prevPluginState.pos) {
147
+ editorView.dispatch(editorView.state.tr.setMeta(_placeholderPlugin.pluginKey, {
148
+ showOnEmptyParagraph: false
149
+ }));
150
+ destroyEmptyParagraphTimeout();
151
+ startEmptyParagraphTimeout(editorView);
152
+ }
153
+ // user move to an empty paragraph (by click enter or move to an empty paragraph), start timeout
154
+ else if (!prevPluginState.canShowOnEmptyParagraph && newPluginState.canShowOnEmptyParagraph && !newPluginState.showOnEmptyParagraph && !timeoutId) {
155
+ startEmptyParagraphTimeout(editorView);
156
+ }
157
+ }
158
+ },
159
+ destroy: function destroy() {
160
+ clearAllTypewriterTimeouts();
161
+ destroyEmptyParagraphTimeout();
162
+ isDestroyed = true;
163
+ }
164
+ };
165
+ }
166
+ });
167
+ }