@atlaskit/editor-plugin-placeholder 6.4.0 → 6.5.1
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 +21 -0
- package/dist/cjs/placeholderPlugin.js +119 -62
- package/dist/es2019/placeholderPlugin.js +75 -16
- package/dist/esm/placeholderPlugin.js +119 -62
- package/package.json +5 -4
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,26 @@
|
|
|
1
1
|
# @atlaskit/editor-plugin-placeholder
|
|
2
2
|
|
|
3
|
+
## 6.5.1
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- [`4d676bbdb3ce6`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/4d676bbdb3ce6) -
|
|
8
|
+
ts-ignore added temporarily to unblock local consumption for help-center, will be removed once
|
|
9
|
+
project refs are setup
|
|
10
|
+
- Updated dependencies
|
|
11
|
+
|
|
12
|
+
## 6.5.0
|
|
13
|
+
|
|
14
|
+
### Minor Changes
|
|
15
|
+
|
|
16
|
+
- [`025002b2a71fc`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/025002b2a71fc) -
|
|
17
|
+
[ux] [EDITOR-3320] fix bug on panel and table placeholders/ added code mark on keyboard shorcuts
|
|
18
|
+
on panel and table placeholders
|
|
19
|
+
|
|
20
|
+
### Patch Changes
|
|
21
|
+
|
|
22
|
+
- Updated dependencies
|
|
23
|
+
|
|
3
24
|
## 6.4.0
|
|
4
25
|
|
|
5
26
|
### 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,12 +40,36 @@ 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;
|
|
45
68
|
var displayedText = '';
|
|
46
69
|
var animationTimeouts = [];
|
|
47
70
|
var clearAllTimeouts = function clearAllTimeouts() {
|
|
71
|
+
// @ts-ignore - Workaround for help-center local consumption
|
|
72
|
+
|
|
48
73
|
animationTimeouts.forEach(function (timeoutId) {
|
|
49
74
|
return clearTimeout(timeoutId);
|
|
50
75
|
});
|
|
@@ -98,6 +123,7 @@ function createPlaceholderDecoration(editorState, placeholderText, placeholderPr
|
|
|
98
123
|
var placeholderNodeWithText = placeholderDecoration;
|
|
99
124
|
placeholderDecoration.setAttribute('data-testid', placeholderTestId);
|
|
100
125
|
placeholderDecoration.className = 'placeholder-decoration';
|
|
126
|
+
placeholderDecoration.setAttribute('aria-hidden', 'true');
|
|
101
127
|
|
|
102
128
|
// PM sets contenteditable to false on Decorations so Firefox doesn't display the flashing cursor
|
|
103
129
|
// So adding an extra span which will contain the placeholder text
|
|
@@ -107,17 +133,23 @@ function createPlaceholderDecoration(editorState, placeholderText, placeholderPr
|
|
|
107
133
|
placeholderDecoration.appendChild(placeholderNode);
|
|
108
134
|
placeholderNodeWithText = placeholderNode;
|
|
109
135
|
}
|
|
110
|
-
if (
|
|
136
|
+
if (placeholderText) {
|
|
137
|
+
placeholderNodeWithText.textContent = placeholderText || ' ';
|
|
138
|
+
} else if (placeholderADF) {
|
|
111
139
|
var serializer = _model.DOMSerializer.fromSchema(editorState.schema);
|
|
112
140
|
// Get a PMNode from docnode
|
|
113
141
|
var docNode = (0, _processRawValue.processRawValue)(editorState.schema, placeholderADF);
|
|
114
142
|
if (docNode) {
|
|
115
143
|
// Extract only the inline content from paragraphs, avoiding block-level elements
|
|
116
144
|
// that can interfere with cursor rendering
|
|
145
|
+
// @ts-ignore - Workaround for help-center local consumption
|
|
146
|
+
|
|
117
147
|
docNode.children.forEach(function (node) {
|
|
118
148
|
// For paragraph nodes, serialize their content (inline elements) directly
|
|
119
149
|
// without the wrapping <p> tag
|
|
120
150
|
if (node.type.name === 'paragraph') {
|
|
151
|
+
// @ts-ignore - Workaround for help-center local consumption
|
|
152
|
+
|
|
121
153
|
node.content.forEach(function (inlineNode) {
|
|
122
154
|
var inlineDOM = serializer.serializeNode(inlineNode);
|
|
123
155
|
placeholderNodeWithText.append(inlineDOM);
|
|
@@ -129,6 +161,8 @@ function createPlaceholderDecoration(editorState, placeholderText, placeholderPr
|
|
|
129
161
|
}
|
|
130
162
|
});
|
|
131
163
|
var markElements = placeholderNodeWithText.querySelectorAll('[data-prosemirror-content-type="mark"]');
|
|
164
|
+
// @ts-ignore - Workaround for help-center local consumption
|
|
165
|
+
|
|
132
166
|
markElements.forEach(function (markEl) {
|
|
133
167
|
if (markEl instanceof HTMLElement) {
|
|
134
168
|
markEl.style.setProperty('color', "var(--ds-text-subtlest, #6B6E76)");
|
|
@@ -136,6 +170,8 @@ function createPlaceholderDecoration(editorState, placeholderText, placeholderPr
|
|
|
136
170
|
});
|
|
137
171
|
// Ensure all child elements don't block pointer events or cursor
|
|
138
172
|
var allElements = placeholderNodeWithText.querySelectorAll('*');
|
|
173
|
+
// @ts-ignore - Workaround for help-center local consumption
|
|
174
|
+
|
|
139
175
|
allElements.forEach(function (el) {
|
|
140
176
|
if (el instanceof HTMLElement) {
|
|
141
177
|
el.style.pointerEvents = 'none';
|
|
@@ -143,8 +179,6 @@ function createPlaceholderDecoration(editorState, placeholderText, placeholderPr
|
|
|
143
179
|
}
|
|
144
180
|
});
|
|
145
181
|
}
|
|
146
|
-
} else if (placeholderText) {
|
|
147
|
-
placeholderNodeWithText.textContent = placeholderText || ' ';
|
|
148
182
|
} else if (placeholderPrompts) {
|
|
149
183
|
cycleThroughPlaceholderPrompts(placeholderPrompts, activeTypewriterTimeouts, placeholderNodeWithText, initialDelayWhenUserTypedAndDeleted);
|
|
150
184
|
}
|
|
@@ -171,18 +205,20 @@ function createPlaceholderDecoration(editorState, placeholderText, placeholderPr
|
|
|
171
205
|
key: "placeholder ".concat(placeholderText)
|
|
172
206
|
})]);
|
|
173
207
|
}
|
|
174
|
-
function setPlaceHolderState(
|
|
175
|
-
var placeholderText =
|
|
176
|
-
pos =
|
|
177
|
-
placeholderPrompts =
|
|
178
|
-
typedAndDeleted =
|
|
179
|
-
userHadTyped =
|
|
180
|
-
canShowOnEmptyParagraph =
|
|
181
|
-
showOnEmptyParagraph =
|
|
208
|
+
function setPlaceHolderState(_ref3) {
|
|
209
|
+
var placeholderText = _ref3.placeholderText,
|
|
210
|
+
pos = _ref3.pos,
|
|
211
|
+
placeholderPrompts = _ref3.placeholderPrompts,
|
|
212
|
+
typedAndDeleted = _ref3.typedAndDeleted,
|
|
213
|
+
userHadTyped = _ref3.userHadTyped,
|
|
214
|
+
canShowOnEmptyParagraph = _ref3.canShowOnEmptyParagraph,
|
|
215
|
+
showOnEmptyParagraph = _ref3.showOnEmptyParagraph,
|
|
216
|
+
contextPlaceholderADF = _ref3.contextPlaceholderADF;
|
|
182
217
|
return {
|
|
183
218
|
hasPlaceholder: true,
|
|
184
219
|
placeholderText: placeholderText,
|
|
185
220
|
placeholderPrompts: placeholderPrompts,
|
|
221
|
+
contextPlaceholderADF: contextPlaceholderADF,
|
|
186
222
|
pos: pos ? pos : 1,
|
|
187
223
|
typedAndDeleted: typedAndDeleted,
|
|
188
224
|
userHadTyped: userHadTyped,
|
|
@@ -190,13 +226,13 @@ function setPlaceHolderState(_ref) {
|
|
|
190
226
|
showOnEmptyParagraph: showOnEmptyParagraph
|
|
191
227
|
};
|
|
192
228
|
}
|
|
193
|
-
var emptyPlaceholder = function emptyPlaceholder(
|
|
194
|
-
var placeholderText =
|
|
195
|
-
placeholderPrompts =
|
|
196
|
-
userHadTyped =
|
|
197
|
-
pos =
|
|
198
|
-
canShowOnEmptyParagraph =
|
|
199
|
-
showOnEmptyParagraph =
|
|
229
|
+
var emptyPlaceholder = function emptyPlaceholder(_ref4) {
|
|
230
|
+
var placeholderText = _ref4.placeholderText,
|
|
231
|
+
placeholderPrompts = _ref4.placeholderPrompts,
|
|
232
|
+
userHadTyped = _ref4.userHadTyped,
|
|
233
|
+
pos = _ref4.pos,
|
|
234
|
+
canShowOnEmptyParagraph = _ref4.canShowOnEmptyParagraph,
|
|
235
|
+
showOnEmptyParagraph = _ref4.showOnEmptyParagraph;
|
|
200
236
|
return {
|
|
201
237
|
hasPlaceholder: false,
|
|
202
238
|
placeholderText: placeholderText,
|
|
@@ -208,21 +244,22 @@ var emptyPlaceholder = function emptyPlaceholder(_ref2) {
|
|
|
208
244
|
pos: pos
|
|
209
245
|
};
|
|
210
246
|
};
|
|
211
|
-
function createPlaceHolderStateFrom(
|
|
212
|
-
var isInitial =
|
|
213
|
-
isEditorFocused =
|
|
214
|
-
editorState =
|
|
215
|
-
isTypeAheadOpen =
|
|
216
|
-
defaultPlaceholderText =
|
|
217
|
-
intl =
|
|
218
|
-
bracketPlaceholderText =
|
|
219
|
-
emptyLinePlaceholder =
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
247
|
+
function createPlaceHolderStateFrom(_ref5) {
|
|
248
|
+
var isInitial = _ref5.isInitial,
|
|
249
|
+
isEditorFocused = _ref5.isEditorFocused,
|
|
250
|
+
editorState = _ref5.editorState,
|
|
251
|
+
isTypeAheadOpen = _ref5.isTypeAheadOpen,
|
|
252
|
+
defaultPlaceholderText = _ref5.defaultPlaceholderText,
|
|
253
|
+
intl = _ref5.intl,
|
|
254
|
+
bracketPlaceholderText = _ref5.bracketPlaceholderText,
|
|
255
|
+
emptyLinePlaceholder = _ref5.emptyLinePlaceholder,
|
|
256
|
+
placeholderADF = _ref5.placeholderADF,
|
|
257
|
+
placeholderPrompts = _ref5.placeholderPrompts,
|
|
258
|
+
typedAndDeleted = _ref5.typedAndDeleted,
|
|
259
|
+
userHadTyped = _ref5.userHadTyped,
|
|
260
|
+
isPlaceholderHidden = _ref5.isPlaceholderHidden,
|
|
261
|
+
withEmptyParagraph = _ref5.withEmptyParagraph,
|
|
262
|
+
showOnEmptyParagraph = _ref5.showOnEmptyParagraph;
|
|
226
263
|
if (isPlaceholderHidden && (0, _platformFeatureFlags.fg)('platform_editor_ai_aifc_patch_beta')) {
|
|
227
264
|
return _objectSpread(_objectSpread({}, emptyPlaceholder({
|
|
228
265
|
placeholderText: defaultPlaceholderText,
|
|
@@ -239,7 +276,7 @@ function createPlaceHolderStateFrom(_ref3) {
|
|
|
239
276
|
userHadTyped: userHadTyped
|
|
240
277
|
});
|
|
241
278
|
}
|
|
242
|
-
if ((defaultPlaceholderText || placeholderPrompts) && (0, _utils.isEmptyDocument)(editorState.doc)) {
|
|
279
|
+
if ((defaultPlaceholderText || placeholderPrompts || placeholderADF) && (0, _utils.isEmptyDocument)(editorState.doc)) {
|
|
243
280
|
return setPlaceHolderState({
|
|
244
281
|
placeholderText: defaultPlaceholderText,
|
|
245
282
|
pos: 1,
|
|
@@ -248,12 +285,12 @@ function createPlaceHolderStateFrom(_ref3) {
|
|
|
248
285
|
userHadTyped: userHadTyped
|
|
249
286
|
});
|
|
250
287
|
}
|
|
251
|
-
if ((0, _platformFeatureFlags.fg)('platform_editor_ai_aifc_patch_beta_2')) {
|
|
288
|
+
if ((0, _platformFeatureFlags.fg)('platform_editor_ai_aifc_patch_beta_2') || (0, _platformFeatureFlags.fg)('platform_editor_ai_aifc_patch_ga')) {
|
|
252
289
|
var _editorState$selectio = editorState.selection,
|
|
253
290
|
from = _editorState$selectio.from,
|
|
254
291
|
to = _editorState$selectio.to,
|
|
255
292
|
$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)) {
|
|
293
|
+
if ((defaultPlaceholderText || placeholderADF) && withEmptyParagraph && isEditorFocused && !isInitial && !(0, _utils.isEmptyDocument)(editorState.doc) && from === to && (0, _utils.isEmptyParagraph)($to.parent) && (0, _utils.hasDocAsParent)($to)) {
|
|
257
294
|
return showOnEmptyParagraph ? setPlaceHolderState({
|
|
258
295
|
placeholderText: defaultPlaceholderText,
|
|
259
296
|
pos: to,
|
|
@@ -314,7 +351,8 @@ function createPlaceHolderStateFrom(_ref3) {
|
|
|
314
351
|
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
352
|
if (isFirstCell) {
|
|
316
353
|
return setPlaceHolderState({
|
|
317
|
-
placeholderText: intl.formatMessage(_messages.placeholderTextMessages.shortEmptyNodePlaceholderText),
|
|
354
|
+
placeholderText: !(0, _platformFeatureFlags.fg)('platform_editor_ai_aifc_patch_ga') ? intl.formatMessage(_messages.placeholderTextMessages.shortEmptyNodePlaceholderText) : undefined,
|
|
355
|
+
contextPlaceholderADF: (0, _platformFeatureFlags.fg)('platform_editor_ai_aifc_patch_ga') ? createShortEmptyNodePlaceholderADF(intl) : undefined,
|
|
318
356
|
pos: $from.pos,
|
|
319
357
|
placeholderPrompts: placeholderPrompts,
|
|
320
358
|
typedAndDeleted: typedAndDeleted,
|
|
@@ -324,7 +362,8 @@ function createPlaceHolderStateFrom(_ref3) {
|
|
|
324
362
|
}
|
|
325
363
|
if (nodeTypesWithLongPlaceholderText.includes(parentType) && isEmptyNode) {
|
|
326
364
|
return setPlaceHolderState({
|
|
327
|
-
placeholderText: intl.formatMessage(_messages.placeholderTextMessages.longEmptyNodePlaceholderText),
|
|
365
|
+
placeholderText: !(0, _platformFeatureFlags.fg)('platform_editor_ai_aifc_patch_ga') ? intl.formatMessage(_messages.placeholderTextMessages.longEmptyNodePlaceholderText) : undefined,
|
|
366
|
+
contextPlaceholderADF: (0, _platformFeatureFlags.fg)('platform_editor_ai_aifc_patch_ga') ? createLongEmptyNodePlaceholderADF(intl) : undefined,
|
|
328
367
|
pos: $from.pos,
|
|
329
368
|
placeholderPrompts: placeholderPrompts,
|
|
330
369
|
typedAndDeleted: typedAndDeleted,
|
|
@@ -364,10 +403,10 @@ function createPlaceHolderStateFrom(_ref3) {
|
|
|
364
403
|
userHadTyped: userHadTyped
|
|
365
404
|
});
|
|
366
405
|
}
|
|
367
|
-
function calculateUserInteractionState(
|
|
368
|
-
var placeholderState =
|
|
369
|
-
oldEditorState =
|
|
370
|
-
newEditorState =
|
|
406
|
+
function calculateUserInteractionState(_ref6) {
|
|
407
|
+
var placeholderState = _ref6.placeholderState,
|
|
408
|
+
oldEditorState = _ref6.oldEditorState,
|
|
409
|
+
newEditorState = _ref6.newEditorState;
|
|
371
410
|
var wasEmpty = oldEditorState ? (0, _utils.isEmptyDocument)(oldEditorState.doc) : true;
|
|
372
411
|
var isEmpty = (0, _utils.isEmptyDocument)(newEditorState.doc);
|
|
373
412
|
var hasEverTyped = Boolean(placeholderState === null || placeholderState === void 0 ? void 0 : placeholderState.userHadTyped) ||
|
|
@@ -391,6 +430,8 @@ function createPlugin(intl, defaultPlaceholderText, bracketPlaceholderText, empt
|
|
|
391
430
|
var isDestroyed = false;
|
|
392
431
|
var activeTypewriterTimeouts = [];
|
|
393
432
|
var clearAllTypewriterTimeouts = function clearAllTypewriterTimeouts() {
|
|
433
|
+
// @ts-ignore - Workaround for help-center local consumption
|
|
434
|
+
|
|
394
435
|
activeTypewriterTimeouts.forEach(function (clearFn) {
|
|
395
436
|
return clearFn();
|
|
396
437
|
});
|
|
@@ -399,6 +440,8 @@ function createPlugin(intl, defaultPlaceholderText, bracketPlaceholderText, empt
|
|
|
399
440
|
return new _safePlugin.SafePlugin({
|
|
400
441
|
key: pluginKey,
|
|
401
442
|
state: {
|
|
443
|
+
// @ts-ignore - Workaround for help-center local consumption
|
|
444
|
+
|
|
402
445
|
init: function init(_, state) {
|
|
403
446
|
var _api$focus, _api$typeAhead;
|
|
404
447
|
return createPlaceHolderStateFrom({
|
|
@@ -409,14 +452,17 @@ function createPlugin(intl, defaultPlaceholderText, bracketPlaceholderText, empt
|
|
|
409
452
|
defaultPlaceholderText: defaultPlaceholderText,
|
|
410
453
|
bracketPlaceholderText: bracketPlaceholderText,
|
|
411
454
|
emptyLinePlaceholder: emptyLinePlaceholder,
|
|
455
|
+
placeholderADF: placeholderADF,
|
|
412
456
|
placeholderPrompts: placeholderPrompts,
|
|
413
457
|
typedAndDeleted: false,
|
|
414
458
|
userHadTyped: false,
|
|
415
459
|
intl: intl
|
|
416
460
|
});
|
|
417
461
|
},
|
|
462
|
+
// @ts-ignore - Workaround for help-center local consumption
|
|
463
|
+
|
|
418
464
|
apply: function apply(tr, placeholderState, _oldEditorState, newEditorState) {
|
|
419
|
-
var _api$focus2, _placeholderState$isP, _api$typeAhead2,
|
|
465
|
+
var _api$focus2, _placeholderState$isP, _api$typeAhead2, _ref7, _meta$placeholderText, _ref8, _meta$placeholderProm, _meta$showOnEmptyPara;
|
|
420
466
|
var meta = tr.getMeta(pluginKey);
|
|
421
467
|
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
468
|
var _calculateUserInterac = calculateUserInteractionState({
|
|
@@ -430,17 +476,21 @@ function createPlugin(intl, defaultPlaceholderText, bracketPlaceholderText, empt
|
|
|
430
476
|
if ((meta === null || meta === void 0 ? void 0 : meta.isPlaceholderHidden) !== undefined && (0, _platformFeatureFlags.fg)('platform_editor_ai_aifc_patch_beta')) {
|
|
431
477
|
isPlaceholderHidden = meta.isPlaceholderHidden;
|
|
432
478
|
}
|
|
433
|
-
if ((meta === null || meta === void 0 ? void 0 : meta.placeholderText) !== undefined && (0, _platformFeatureFlags.fg)('platform_editor_ai_aifc_patch_beta_2')) {
|
|
434
|
-
defaultPlaceholderText
|
|
479
|
+
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'))) {
|
|
480
|
+
// Only update defaultPlaceholderText from meta if we're not using ADF placeholder
|
|
481
|
+
if (!((0, _platformFeatureFlags.fg)('platform_editor_ai_aifc_patch_ga') && placeholderADF)) {
|
|
482
|
+
defaultPlaceholderText = meta.placeholderText;
|
|
483
|
+
}
|
|
435
484
|
}
|
|
436
485
|
var newPlaceholderState = createPlaceHolderStateFrom({
|
|
437
486
|
isEditorFocused: isEditorFocused,
|
|
438
487
|
editorState: newEditorState,
|
|
439
488
|
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 : (
|
|
489
|
+
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
490
|
bracketPlaceholderText: bracketPlaceholderText,
|
|
442
491
|
emptyLinePlaceholder: emptyLinePlaceholder,
|
|
443
|
-
|
|
492
|
+
placeholderADF: placeholderADF,
|
|
493
|
+
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
494
|
typedAndDeleted: typedAndDeleted,
|
|
445
495
|
userHadTyped: userHadTyped,
|
|
446
496
|
intl: intl,
|
|
@@ -457,13 +507,15 @@ function createPlugin(intl, defaultPlaceholderText, bracketPlaceholderText, empt
|
|
|
457
507
|
}
|
|
458
508
|
},
|
|
459
509
|
props: {
|
|
510
|
+
// @ts-ignore - Workaround for help-center local consumption
|
|
460
511
|
decorations: function decorations(editorState) {
|
|
461
512
|
var _api$composition, _api$showDiff;
|
|
462
513
|
var _getPlaceholderState = getPlaceholderState(editorState),
|
|
463
514
|
hasPlaceholder = _getPlaceholderState.hasPlaceholder,
|
|
464
515
|
placeholderText = _getPlaceholderState.placeholderText,
|
|
465
516
|
pos = _getPlaceholderState.pos,
|
|
466
|
-
typedAndDeleted = _getPlaceholderState.typedAndDeleted
|
|
517
|
+
typedAndDeleted = _getPlaceholderState.typedAndDeleted,
|
|
518
|
+
contextPlaceholderADF = _getPlaceholderState.contextPlaceholderADF;
|
|
467
519
|
|
|
468
520
|
// Decorations is still called after plugin is destroyed
|
|
469
521
|
// So we need to make sure decorations is not called if plugin has been destroyed to prevent the placeholder animations' setTimeouts called infinitely
|
|
@@ -472,13 +524,16 @@ function createPlugin(intl, defaultPlaceholderText, bracketPlaceholderText, empt
|
|
|
472
524
|
}
|
|
473
525
|
var compositionPluginState = api === null || api === void 0 || (_api$composition = api.composition) === null || _api$composition === void 0 ? void 0 : _api$composition.sharedState.currentState();
|
|
474
526
|
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) {
|
|
527
|
+
if (hasPlaceholder && ((placeholderText !== null && placeholderText !== void 0 ? placeholderText : '') || placeholderPrompts || placeholderADF || contextPlaceholderADF) && pos !== undefined && !(compositionPluginState !== null && compositionPluginState !== void 0 && compositionPluginState.isComposing) && !isShowingDiff) {
|
|
476
528
|
var initialDelayWhenUserTypedAndDeleted = typedAndDeleted ? TYPEWRITER_TYPED_AND_DELETED_DELAY : 0;
|
|
477
|
-
|
|
529
|
+
// contextPlaceholderADF takes precedence over the global placeholderADF
|
|
530
|
+
var placeholderAdfToUse = contextPlaceholderADF || placeholderADF;
|
|
531
|
+
return createPlaceholderDecoration(editorState, placeholderText !== null && placeholderText !== void 0 ? placeholderText : '', placeholderPrompts, activeTypewriterTimeouts, pos, initialDelayWhenUserTypedAndDeleted, placeholderAdfToUse);
|
|
478
532
|
}
|
|
479
533
|
return;
|
|
480
534
|
}
|
|
481
535
|
},
|
|
536
|
+
// @ts-ignore - Workaround for help-center local consumption
|
|
482
537
|
view: function view() {
|
|
483
538
|
var timeoutId;
|
|
484
539
|
function startEmptyParagraphTimeout(editorView) {
|
|
@@ -499,8 +554,9 @@ function createPlugin(intl, defaultPlaceholderText, bracketPlaceholderText, empt
|
|
|
499
554
|
}
|
|
500
555
|
}
|
|
501
556
|
return {
|
|
557
|
+
// @ts-ignore - Workaround for help-center local consumption
|
|
502
558
|
update: function update(editorView, prevState) {
|
|
503
|
-
if ((0, _platformFeatureFlags.fg)('platform_editor_ai_aifc_patch_beta_2')) {
|
|
559
|
+
if ((0, _platformFeatureFlags.fg)('platform_editor_ai_aifc_patch_beta_2') || (0, _platformFeatureFlags.fg)('platform_editor_ai_aifc_patch_ga')) {
|
|
504
560
|
var prevPluginState = getPlaceholderState(prevState);
|
|
505
561
|
var newPluginState = getPlaceholderState(editorView.state);
|
|
506
562
|
|
|
@@ -522,6 +578,7 @@ function createPlugin(intl, defaultPlaceholderText, bracketPlaceholderText, empt
|
|
|
522
578
|
}
|
|
523
579
|
}
|
|
524
580
|
},
|
|
581
|
+
// @ts-ignore - Workaround for help-center local consumption
|
|
525
582
|
destroy: function destroy() {
|
|
526
583
|
clearAllTypewriterTimeouts();
|
|
527
584
|
destroyEmptyParagraphTimeout();
|
|
@@ -531,16 +588,16 @@ function createPlugin(intl, defaultPlaceholderText, bracketPlaceholderText, empt
|
|
|
531
588
|
}
|
|
532
589
|
});
|
|
533
590
|
}
|
|
534
|
-
var placeholderPlugin = exports.placeholderPlugin = function placeholderPlugin(
|
|
535
|
-
var options =
|
|
536
|
-
api =
|
|
591
|
+
var placeholderPlugin = exports.placeholderPlugin = function placeholderPlugin(_ref9) {
|
|
592
|
+
var options = _ref9.config,
|
|
593
|
+
api = _ref9.api;
|
|
537
594
|
var currentPlaceholder = options === null || options === void 0 ? void 0 : options.placeholder;
|
|
538
595
|
return {
|
|
539
596
|
name: 'placeholder',
|
|
540
597
|
commands: {
|
|
541
598
|
setPlaceholder: function setPlaceholder(placeholderText) {
|
|
542
|
-
return function (
|
|
543
|
-
var tr =
|
|
599
|
+
return function (_ref0) {
|
|
600
|
+
var tr = _ref0.tr;
|
|
544
601
|
if (currentPlaceholder !== placeholderText) {
|
|
545
602
|
currentPlaceholder = placeholderText;
|
|
546
603
|
return tr.setMeta(pluginKey, {
|
|
@@ -551,16 +608,16 @@ var placeholderPlugin = exports.placeholderPlugin = function placeholderPlugin(_
|
|
|
551
608
|
};
|
|
552
609
|
},
|
|
553
610
|
setAnimatingPlaceholderPrompts: function setAnimatingPlaceholderPrompts(placeholderPrompts) {
|
|
554
|
-
return function (
|
|
555
|
-
var tr =
|
|
611
|
+
return function (_ref1) {
|
|
612
|
+
var tr = _ref1.tr;
|
|
556
613
|
return tr.setMeta(pluginKey, {
|
|
557
614
|
placeholderPrompts: placeholderPrompts
|
|
558
615
|
});
|
|
559
616
|
};
|
|
560
617
|
},
|
|
561
618
|
setPlaceholderHidden: function setPlaceholderHidden(isPlaceholderHidden) {
|
|
562
|
-
return function (
|
|
563
|
-
var tr =
|
|
619
|
+
return function (_ref10) {
|
|
620
|
+
var tr = _ref10.tr;
|
|
564
621
|
return tr.setMeta(pluginKey, {
|
|
565
622
|
isPlaceholderHidden: isPlaceholderHidden
|
|
566
623
|
});
|
|
@@ -570,8 +627,8 @@ var placeholderPlugin = exports.placeholderPlugin = function placeholderPlugin(_
|
|
|
570
627
|
pmPlugins: function pmPlugins() {
|
|
571
628
|
return [{
|
|
572
629
|
name: 'placeholder',
|
|
573
|
-
plugin: function plugin(
|
|
574
|
-
var getIntl =
|
|
630
|
+
plugin: function plugin(_ref11) {
|
|
631
|
+
var getIntl = _ref11.getIntl;
|
|
575
632
|
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
633
|
}
|
|
577
634
|
}];
|
|
@@ -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,11 +27,33 @@ 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 = '';
|
|
32
53
|
let animationTimeouts = [];
|
|
33
54
|
const clearAllTimeouts = () => {
|
|
55
|
+
// @ts-ignore - Workaround for help-center local consumption
|
|
56
|
+
|
|
34
57
|
animationTimeouts.forEach(timeoutId => clearTimeout(timeoutId));
|
|
35
58
|
animationTimeouts = [];
|
|
36
59
|
};
|
|
@@ -79,6 +102,7 @@ export function createPlaceholderDecoration(editorState, placeholderText, placeh
|
|
|
79
102
|
let placeholderNodeWithText = placeholderDecoration;
|
|
80
103
|
placeholderDecoration.setAttribute('data-testid', placeholderTestId);
|
|
81
104
|
placeholderDecoration.className = 'placeholder-decoration';
|
|
105
|
+
placeholderDecoration.setAttribute('aria-hidden', 'true');
|
|
82
106
|
|
|
83
107
|
// PM sets contenteditable to false on Decorations so Firefox doesn't display the flashing cursor
|
|
84
108
|
// So adding an extra span which will contain the placeholder text
|
|
@@ -88,17 +112,23 @@ export function createPlaceholderDecoration(editorState, placeholderText, placeh
|
|
|
88
112
|
placeholderDecoration.appendChild(placeholderNode);
|
|
89
113
|
placeholderNodeWithText = placeholderNode;
|
|
90
114
|
}
|
|
91
|
-
if (
|
|
115
|
+
if (placeholderText) {
|
|
116
|
+
placeholderNodeWithText.textContent = placeholderText || ' ';
|
|
117
|
+
} else if (placeholderADF) {
|
|
92
118
|
const serializer = DOMSerializer.fromSchema(editorState.schema);
|
|
93
119
|
// Get a PMNode from docnode
|
|
94
120
|
const docNode = processRawValue(editorState.schema, placeholderADF);
|
|
95
121
|
if (docNode) {
|
|
96
122
|
// Extract only the inline content from paragraphs, avoiding block-level elements
|
|
97
123
|
// that can interfere with cursor rendering
|
|
124
|
+
// @ts-ignore - Workaround for help-center local consumption
|
|
125
|
+
|
|
98
126
|
docNode.children.forEach(node => {
|
|
99
127
|
// For paragraph nodes, serialize their content (inline elements) directly
|
|
100
128
|
// without the wrapping <p> tag
|
|
101
129
|
if (node.type.name === 'paragraph') {
|
|
130
|
+
// @ts-ignore - Workaround for help-center local consumption
|
|
131
|
+
|
|
102
132
|
node.content.forEach(inlineNode => {
|
|
103
133
|
const inlineDOM = serializer.serializeNode(inlineNode);
|
|
104
134
|
placeholderNodeWithText.append(inlineDOM);
|
|
@@ -110,6 +140,8 @@ export function createPlaceholderDecoration(editorState, placeholderText, placeh
|
|
|
110
140
|
}
|
|
111
141
|
});
|
|
112
142
|
const markElements = placeholderNodeWithText.querySelectorAll('[data-prosemirror-content-type="mark"]');
|
|
143
|
+
// @ts-ignore - Workaround for help-center local consumption
|
|
144
|
+
|
|
113
145
|
markElements.forEach(markEl => {
|
|
114
146
|
if (markEl instanceof HTMLElement) {
|
|
115
147
|
markEl.style.setProperty('color', "var(--ds-text-subtlest, #6B6E76)");
|
|
@@ -117,6 +149,8 @@ export function createPlaceholderDecoration(editorState, placeholderText, placeh
|
|
|
117
149
|
});
|
|
118
150
|
// Ensure all child elements don't block pointer events or cursor
|
|
119
151
|
const allElements = placeholderNodeWithText.querySelectorAll('*');
|
|
152
|
+
// @ts-ignore - Workaround for help-center local consumption
|
|
153
|
+
|
|
120
154
|
allElements.forEach(el => {
|
|
121
155
|
if (el instanceof HTMLElement) {
|
|
122
156
|
el.style.pointerEvents = 'none';
|
|
@@ -124,8 +158,6 @@ export function createPlaceholderDecoration(editorState, placeholderText, placeh
|
|
|
124
158
|
}
|
|
125
159
|
});
|
|
126
160
|
}
|
|
127
|
-
} else if (placeholderText) {
|
|
128
|
-
placeholderNodeWithText.textContent = placeholderText || ' ';
|
|
129
161
|
} else if (placeholderPrompts) {
|
|
130
162
|
cycleThroughPlaceholderPrompts(placeholderPrompts, activeTypewriterTimeouts, placeholderNodeWithText, initialDelayWhenUserTypedAndDeleted);
|
|
131
163
|
}
|
|
@@ -159,12 +191,14 @@ function setPlaceHolderState({
|
|
|
159
191
|
typedAndDeleted,
|
|
160
192
|
userHadTyped,
|
|
161
193
|
canShowOnEmptyParagraph,
|
|
162
|
-
showOnEmptyParagraph
|
|
194
|
+
showOnEmptyParagraph,
|
|
195
|
+
contextPlaceholderADF
|
|
163
196
|
}) {
|
|
164
197
|
return {
|
|
165
198
|
hasPlaceholder: true,
|
|
166
199
|
placeholderText,
|
|
167
200
|
placeholderPrompts,
|
|
201
|
+
contextPlaceholderADF,
|
|
168
202
|
pos: pos ? pos : 1,
|
|
169
203
|
typedAndDeleted,
|
|
170
204
|
userHadTyped,
|
|
@@ -198,6 +232,7 @@ function createPlaceHolderStateFrom({
|
|
|
198
232
|
intl,
|
|
199
233
|
bracketPlaceholderText,
|
|
200
234
|
emptyLinePlaceholder,
|
|
235
|
+
placeholderADF,
|
|
201
236
|
placeholderPrompts,
|
|
202
237
|
typedAndDeleted,
|
|
203
238
|
userHadTyped,
|
|
@@ -222,7 +257,7 @@ function createPlaceHolderStateFrom({
|
|
|
222
257
|
userHadTyped
|
|
223
258
|
});
|
|
224
259
|
}
|
|
225
|
-
if ((defaultPlaceholderText || placeholderPrompts) && isEmptyDocument(editorState.doc)) {
|
|
260
|
+
if ((defaultPlaceholderText || placeholderPrompts || placeholderADF) && isEmptyDocument(editorState.doc)) {
|
|
226
261
|
return setPlaceHolderState({
|
|
227
262
|
placeholderText: defaultPlaceholderText,
|
|
228
263
|
pos: 1,
|
|
@@ -231,13 +266,13 @@ function createPlaceHolderStateFrom({
|
|
|
231
266
|
userHadTyped
|
|
232
267
|
});
|
|
233
268
|
}
|
|
234
|
-
if (fg('platform_editor_ai_aifc_patch_beta_2')) {
|
|
269
|
+
if (fg('platform_editor_ai_aifc_patch_beta_2') || fg('platform_editor_ai_aifc_patch_ga')) {
|
|
235
270
|
const {
|
|
236
271
|
from,
|
|
237
272
|
to,
|
|
238
273
|
$to
|
|
239
274
|
} = editorState.selection;
|
|
240
|
-
if (defaultPlaceholderText && withEmptyParagraph && isEditorFocused && !isInitial && !isEmptyDocument(editorState.doc) && from === to && isEmptyParagraph($to.parent) && hasDocAsParent($to)) {
|
|
275
|
+
if ((defaultPlaceholderText || placeholderADF) && withEmptyParagraph && isEditorFocused && !isInitial && !isEmptyDocument(editorState.doc) && from === to && isEmptyParagraph($to.parent) && hasDocAsParent($to)) {
|
|
241
276
|
return showOnEmptyParagraph ? setPlaceHolderState({
|
|
242
277
|
placeholderText: defaultPlaceholderText,
|
|
243
278
|
pos: to,
|
|
@@ -297,7 +332,8 @@ function createPlaceHolderStateFrom({
|
|
|
297
332
|
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
333
|
if (isFirstCell) {
|
|
299
334
|
return setPlaceHolderState({
|
|
300
|
-
placeholderText: intl.formatMessage(messages.shortEmptyNodePlaceholderText),
|
|
335
|
+
placeholderText: !fg('platform_editor_ai_aifc_patch_ga') ? intl.formatMessage(messages.shortEmptyNodePlaceholderText) : undefined,
|
|
336
|
+
contextPlaceholderADF: fg('platform_editor_ai_aifc_patch_ga') ? createShortEmptyNodePlaceholderADF(intl) : undefined,
|
|
301
337
|
pos: $from.pos,
|
|
302
338
|
placeholderPrompts,
|
|
303
339
|
typedAndDeleted,
|
|
@@ -307,7 +343,8 @@ function createPlaceHolderStateFrom({
|
|
|
307
343
|
}
|
|
308
344
|
if (nodeTypesWithLongPlaceholderText.includes(parentType) && isEmptyNode) {
|
|
309
345
|
return setPlaceHolderState({
|
|
310
|
-
placeholderText: intl.formatMessage(messages.longEmptyNodePlaceholderText),
|
|
346
|
+
placeholderText: !fg('platform_editor_ai_aifc_patch_ga') ? intl.formatMessage(messages.longEmptyNodePlaceholderText) : undefined,
|
|
347
|
+
contextPlaceholderADF: fg('platform_editor_ai_aifc_patch_ga') ? createLongEmptyNodePlaceholderADF(intl) : undefined,
|
|
311
348
|
pos: $from.pos,
|
|
312
349
|
placeholderPrompts,
|
|
313
350
|
typedAndDeleted,
|
|
@@ -377,12 +414,16 @@ export function createPlugin(intl, defaultPlaceholderText, bracketPlaceholderTex
|
|
|
377
414
|
let isDestroyed = false;
|
|
378
415
|
let activeTypewriterTimeouts = [];
|
|
379
416
|
const clearAllTypewriterTimeouts = () => {
|
|
417
|
+
// @ts-ignore - Workaround for help-center local consumption
|
|
418
|
+
|
|
380
419
|
activeTypewriterTimeouts.forEach(clearFn => clearFn());
|
|
381
420
|
activeTypewriterTimeouts = [];
|
|
382
421
|
};
|
|
383
422
|
return new SafePlugin({
|
|
384
423
|
key: pluginKey,
|
|
385
424
|
state: {
|
|
425
|
+
// @ts-ignore - Workaround for help-center local consumption
|
|
426
|
+
|
|
386
427
|
init: (_, state) => {
|
|
387
428
|
var _api$focus, _api$focus$sharedStat, _api$typeAhead;
|
|
388
429
|
return createPlaceHolderStateFrom({
|
|
@@ -393,12 +434,15 @@ export function createPlugin(intl, defaultPlaceholderText, bracketPlaceholderTex
|
|
|
393
434
|
defaultPlaceholderText,
|
|
394
435
|
bracketPlaceholderText,
|
|
395
436
|
emptyLinePlaceholder,
|
|
437
|
+
placeholderADF,
|
|
396
438
|
placeholderPrompts,
|
|
397
439
|
typedAndDeleted: false,
|
|
398
440
|
userHadTyped: false,
|
|
399
441
|
intl
|
|
400
442
|
});
|
|
401
443
|
},
|
|
444
|
+
// @ts-ignore - Workaround for help-center local consumption
|
|
445
|
+
|
|
402
446
|
apply: (tr, placeholderState, _oldEditorState, newEditorState) => {
|
|
403
447
|
var _api$focus2, _api$focus2$sharedSta, _placeholderState$isP, _api$typeAhead2, _ref, _meta$placeholderText, _ref2, _meta$placeholderProm, _meta$showOnEmptyPara;
|
|
404
448
|
const meta = tr.getMeta(pluginKey);
|
|
@@ -415,16 +459,20 @@ export function createPlugin(intl, defaultPlaceholderText, bracketPlaceholderTex
|
|
|
415
459
|
if ((meta === null || meta === void 0 ? void 0 : meta.isPlaceholderHidden) !== undefined && fg('platform_editor_ai_aifc_patch_beta')) {
|
|
416
460
|
isPlaceholderHidden = meta.isPlaceholderHidden;
|
|
417
461
|
}
|
|
418
|
-
if ((meta === null || meta === void 0 ? void 0 : meta.placeholderText) !== undefined && fg('platform_editor_ai_aifc_patch_beta_2')) {
|
|
419
|
-
defaultPlaceholderText
|
|
462
|
+
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'))) {
|
|
463
|
+
// Only update defaultPlaceholderText from meta if we're not using ADF placeholder
|
|
464
|
+
if (!(fg('platform_editor_ai_aifc_patch_ga') && placeholderADF)) {
|
|
465
|
+
defaultPlaceholderText = meta.placeholderText;
|
|
466
|
+
}
|
|
420
467
|
}
|
|
421
468
|
const newPlaceholderState = createPlaceHolderStateFrom({
|
|
422
469
|
isEditorFocused,
|
|
423
470
|
editorState: newEditorState,
|
|
424
471
|
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,
|
|
472
|
+
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
473
|
bracketPlaceholderText,
|
|
427
474
|
emptyLinePlaceholder,
|
|
475
|
+
placeholderADF,
|
|
428
476
|
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
477
|
typedAndDeleted,
|
|
430
478
|
userHadTyped,
|
|
@@ -442,13 +490,16 @@ export function createPlugin(intl, defaultPlaceholderText, bracketPlaceholderTex
|
|
|
442
490
|
}
|
|
443
491
|
},
|
|
444
492
|
props: {
|
|
493
|
+
// @ts-ignore - Workaround for help-center local consumption
|
|
494
|
+
|
|
445
495
|
decorations(editorState) {
|
|
446
496
|
var _api$composition, _api$showDiff, _api$showDiff$sharedS;
|
|
447
497
|
const {
|
|
448
498
|
hasPlaceholder,
|
|
449
499
|
placeholderText,
|
|
450
500
|
pos,
|
|
451
|
-
typedAndDeleted
|
|
501
|
+
typedAndDeleted,
|
|
502
|
+
contextPlaceholderADF
|
|
452
503
|
} = getPlaceholderState(editorState);
|
|
453
504
|
|
|
454
505
|
// Decorations is still called after plugin is destroyed
|
|
@@ -458,13 +509,17 @@ export function createPlugin(intl, defaultPlaceholderText, bracketPlaceholderTex
|
|
|
458
509
|
}
|
|
459
510
|
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
511
|
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) {
|
|
512
|
+
if (hasPlaceholder && ((placeholderText !== null && placeholderText !== void 0 ? placeholderText : '') || placeholderPrompts || placeholderADF || contextPlaceholderADF) && pos !== undefined && !(compositionPluginState !== null && compositionPluginState !== void 0 && compositionPluginState.isComposing) && !isShowingDiff) {
|
|
462
513
|
const initialDelayWhenUserTypedAndDeleted = typedAndDeleted ? TYPEWRITER_TYPED_AND_DELETED_DELAY : 0;
|
|
463
|
-
|
|
514
|
+
// contextPlaceholderADF takes precedence over the global placeholderADF
|
|
515
|
+
const placeholderAdfToUse = contextPlaceholderADF || placeholderADF;
|
|
516
|
+
return createPlaceholderDecoration(editorState, placeholderText !== null && placeholderText !== void 0 ? placeholderText : '', placeholderPrompts, activeTypewriterTimeouts, pos, initialDelayWhenUserTypedAndDeleted, placeholderAdfToUse);
|
|
464
517
|
}
|
|
465
518
|
return;
|
|
466
519
|
}
|
|
467
520
|
},
|
|
521
|
+
// @ts-ignore - Workaround for help-center local consumption
|
|
522
|
+
|
|
468
523
|
view() {
|
|
469
524
|
let timeoutId;
|
|
470
525
|
function startEmptyParagraphTimeout(editorView) {
|
|
@@ -485,8 +540,10 @@ export function createPlugin(intl, defaultPlaceholderText, bracketPlaceholderTex
|
|
|
485
540
|
}
|
|
486
541
|
}
|
|
487
542
|
return {
|
|
543
|
+
// @ts-ignore - Workaround for help-center local consumption
|
|
544
|
+
|
|
488
545
|
update(editorView, prevState) {
|
|
489
|
-
if (fg('platform_editor_ai_aifc_patch_beta_2')) {
|
|
546
|
+
if (fg('platform_editor_ai_aifc_patch_beta_2') || fg('platform_editor_ai_aifc_patch_ga')) {
|
|
490
547
|
const prevPluginState = getPlaceholderState(prevState);
|
|
491
548
|
const newPluginState = getPlaceholderState(editorView.state);
|
|
492
549
|
|
|
@@ -508,6 +565,8 @@ export function createPlugin(intl, defaultPlaceholderText, bracketPlaceholderTex
|
|
|
508
565
|
}
|
|
509
566
|
}
|
|
510
567
|
},
|
|
568
|
+
// @ts-ignore - Workaround for help-center local consumption
|
|
569
|
+
|
|
511
570
|
destroy() {
|
|
512
571
|
clearAllTypewriterTimeouts();
|
|
513
572
|
destroyEmptyParagraphTimeout();
|
|
@@ -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,12 +30,36 @@ 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;
|
|
35
58
|
var displayedText = '';
|
|
36
59
|
var animationTimeouts = [];
|
|
37
60
|
var clearAllTimeouts = function clearAllTimeouts() {
|
|
61
|
+
// @ts-ignore - Workaround for help-center local consumption
|
|
62
|
+
|
|
38
63
|
animationTimeouts.forEach(function (timeoutId) {
|
|
39
64
|
return clearTimeout(timeoutId);
|
|
40
65
|
});
|
|
@@ -88,6 +113,7 @@ export function createPlaceholderDecoration(editorState, placeholderText, placeh
|
|
|
88
113
|
var placeholderNodeWithText = placeholderDecoration;
|
|
89
114
|
placeholderDecoration.setAttribute('data-testid', placeholderTestId);
|
|
90
115
|
placeholderDecoration.className = 'placeholder-decoration';
|
|
116
|
+
placeholderDecoration.setAttribute('aria-hidden', 'true');
|
|
91
117
|
|
|
92
118
|
// PM sets contenteditable to false on Decorations so Firefox doesn't display the flashing cursor
|
|
93
119
|
// So adding an extra span which will contain the placeholder text
|
|
@@ -97,17 +123,23 @@ export function createPlaceholderDecoration(editorState, placeholderText, placeh
|
|
|
97
123
|
placeholderDecoration.appendChild(placeholderNode);
|
|
98
124
|
placeholderNodeWithText = placeholderNode;
|
|
99
125
|
}
|
|
100
|
-
if (
|
|
126
|
+
if (placeholderText) {
|
|
127
|
+
placeholderNodeWithText.textContent = placeholderText || ' ';
|
|
128
|
+
} else if (placeholderADF) {
|
|
101
129
|
var serializer = DOMSerializer.fromSchema(editorState.schema);
|
|
102
130
|
// Get a PMNode from docnode
|
|
103
131
|
var docNode = processRawValue(editorState.schema, placeholderADF);
|
|
104
132
|
if (docNode) {
|
|
105
133
|
// Extract only the inline content from paragraphs, avoiding block-level elements
|
|
106
134
|
// that can interfere with cursor rendering
|
|
135
|
+
// @ts-ignore - Workaround for help-center local consumption
|
|
136
|
+
|
|
107
137
|
docNode.children.forEach(function (node) {
|
|
108
138
|
// For paragraph nodes, serialize their content (inline elements) directly
|
|
109
139
|
// without the wrapping <p> tag
|
|
110
140
|
if (node.type.name === 'paragraph') {
|
|
141
|
+
// @ts-ignore - Workaround for help-center local consumption
|
|
142
|
+
|
|
111
143
|
node.content.forEach(function (inlineNode) {
|
|
112
144
|
var inlineDOM = serializer.serializeNode(inlineNode);
|
|
113
145
|
placeholderNodeWithText.append(inlineDOM);
|
|
@@ -119,6 +151,8 @@ export function createPlaceholderDecoration(editorState, placeholderText, placeh
|
|
|
119
151
|
}
|
|
120
152
|
});
|
|
121
153
|
var markElements = placeholderNodeWithText.querySelectorAll('[data-prosemirror-content-type="mark"]');
|
|
154
|
+
// @ts-ignore - Workaround for help-center local consumption
|
|
155
|
+
|
|
122
156
|
markElements.forEach(function (markEl) {
|
|
123
157
|
if (markEl instanceof HTMLElement) {
|
|
124
158
|
markEl.style.setProperty('color', "var(--ds-text-subtlest, #6B6E76)");
|
|
@@ -126,6 +160,8 @@ export function createPlaceholderDecoration(editorState, placeholderText, placeh
|
|
|
126
160
|
});
|
|
127
161
|
// Ensure all child elements don't block pointer events or cursor
|
|
128
162
|
var allElements = placeholderNodeWithText.querySelectorAll('*');
|
|
163
|
+
// @ts-ignore - Workaround for help-center local consumption
|
|
164
|
+
|
|
129
165
|
allElements.forEach(function (el) {
|
|
130
166
|
if (el instanceof HTMLElement) {
|
|
131
167
|
el.style.pointerEvents = 'none';
|
|
@@ -133,8 +169,6 @@ export function createPlaceholderDecoration(editorState, placeholderText, placeh
|
|
|
133
169
|
}
|
|
134
170
|
});
|
|
135
171
|
}
|
|
136
|
-
} else if (placeholderText) {
|
|
137
|
-
placeholderNodeWithText.textContent = placeholderText || ' ';
|
|
138
172
|
} else if (placeholderPrompts) {
|
|
139
173
|
cycleThroughPlaceholderPrompts(placeholderPrompts, activeTypewriterTimeouts, placeholderNodeWithText, initialDelayWhenUserTypedAndDeleted);
|
|
140
174
|
}
|
|
@@ -161,18 +195,20 @@ export function createPlaceholderDecoration(editorState, placeholderText, placeh
|
|
|
161
195
|
key: "placeholder ".concat(placeholderText)
|
|
162
196
|
})]);
|
|
163
197
|
}
|
|
164
|
-
function setPlaceHolderState(
|
|
165
|
-
var placeholderText =
|
|
166
|
-
pos =
|
|
167
|
-
placeholderPrompts =
|
|
168
|
-
typedAndDeleted =
|
|
169
|
-
userHadTyped =
|
|
170
|
-
canShowOnEmptyParagraph =
|
|
171
|
-
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;
|
|
172
207
|
return {
|
|
173
208
|
hasPlaceholder: true,
|
|
174
209
|
placeholderText: placeholderText,
|
|
175
210
|
placeholderPrompts: placeholderPrompts,
|
|
211
|
+
contextPlaceholderADF: contextPlaceholderADF,
|
|
176
212
|
pos: pos ? pos : 1,
|
|
177
213
|
typedAndDeleted: typedAndDeleted,
|
|
178
214
|
userHadTyped: userHadTyped,
|
|
@@ -180,13 +216,13 @@ function setPlaceHolderState(_ref) {
|
|
|
180
216
|
showOnEmptyParagraph: showOnEmptyParagraph
|
|
181
217
|
};
|
|
182
218
|
}
|
|
183
|
-
var emptyPlaceholder = function emptyPlaceholder(
|
|
184
|
-
var placeholderText =
|
|
185
|
-
placeholderPrompts =
|
|
186
|
-
userHadTyped =
|
|
187
|
-
pos =
|
|
188
|
-
canShowOnEmptyParagraph =
|
|
189
|
-
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;
|
|
190
226
|
return {
|
|
191
227
|
hasPlaceholder: false,
|
|
192
228
|
placeholderText: placeholderText,
|
|
@@ -198,21 +234,22 @@ var emptyPlaceholder = function emptyPlaceholder(_ref2) {
|
|
|
198
234
|
pos: pos
|
|
199
235
|
};
|
|
200
236
|
};
|
|
201
|
-
function createPlaceHolderStateFrom(
|
|
202
|
-
var isInitial =
|
|
203
|
-
isEditorFocused =
|
|
204
|
-
editorState =
|
|
205
|
-
isTypeAheadOpen =
|
|
206
|
-
defaultPlaceholderText =
|
|
207
|
-
intl =
|
|
208
|
-
bracketPlaceholderText =
|
|
209
|
-
emptyLinePlaceholder =
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
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;
|
|
216
253
|
if (isPlaceholderHidden && fg('platform_editor_ai_aifc_patch_beta')) {
|
|
217
254
|
return _objectSpread(_objectSpread({}, emptyPlaceholder({
|
|
218
255
|
placeholderText: defaultPlaceholderText,
|
|
@@ -229,7 +266,7 @@ function createPlaceHolderStateFrom(_ref3) {
|
|
|
229
266
|
userHadTyped: userHadTyped
|
|
230
267
|
});
|
|
231
268
|
}
|
|
232
|
-
if ((defaultPlaceholderText || placeholderPrompts) && isEmptyDocument(editorState.doc)) {
|
|
269
|
+
if ((defaultPlaceholderText || placeholderPrompts || placeholderADF) && isEmptyDocument(editorState.doc)) {
|
|
233
270
|
return setPlaceHolderState({
|
|
234
271
|
placeholderText: defaultPlaceholderText,
|
|
235
272
|
pos: 1,
|
|
@@ -238,12 +275,12 @@ function createPlaceHolderStateFrom(_ref3) {
|
|
|
238
275
|
userHadTyped: userHadTyped
|
|
239
276
|
});
|
|
240
277
|
}
|
|
241
|
-
if (fg('platform_editor_ai_aifc_patch_beta_2')) {
|
|
278
|
+
if (fg('platform_editor_ai_aifc_patch_beta_2') || fg('platform_editor_ai_aifc_patch_ga')) {
|
|
242
279
|
var _editorState$selectio = editorState.selection,
|
|
243
280
|
from = _editorState$selectio.from,
|
|
244
281
|
to = _editorState$selectio.to,
|
|
245
282
|
$to = _editorState$selectio.$to;
|
|
246
|
-
if (defaultPlaceholderText && withEmptyParagraph && isEditorFocused && !isInitial && !isEmptyDocument(editorState.doc) && from === to && isEmptyParagraph($to.parent) && hasDocAsParent($to)) {
|
|
283
|
+
if ((defaultPlaceholderText || placeholderADF) && withEmptyParagraph && isEditorFocused && !isInitial && !isEmptyDocument(editorState.doc) && from === to && isEmptyParagraph($to.parent) && hasDocAsParent($to)) {
|
|
247
284
|
return showOnEmptyParagraph ? setPlaceHolderState({
|
|
248
285
|
placeholderText: defaultPlaceholderText,
|
|
249
286
|
pos: to,
|
|
@@ -304,7 +341,8 @@ function createPlaceHolderStateFrom(_ref3) {
|
|
|
304
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;
|
|
305
342
|
if (isFirstCell) {
|
|
306
343
|
return setPlaceHolderState({
|
|
307
|
-
placeholderText: intl.formatMessage(messages.shortEmptyNodePlaceholderText),
|
|
344
|
+
placeholderText: !fg('platform_editor_ai_aifc_patch_ga') ? intl.formatMessage(messages.shortEmptyNodePlaceholderText) : undefined,
|
|
345
|
+
contextPlaceholderADF: fg('platform_editor_ai_aifc_patch_ga') ? createShortEmptyNodePlaceholderADF(intl) : undefined,
|
|
308
346
|
pos: $from.pos,
|
|
309
347
|
placeholderPrompts: placeholderPrompts,
|
|
310
348
|
typedAndDeleted: typedAndDeleted,
|
|
@@ -314,7 +352,8 @@ function createPlaceHolderStateFrom(_ref3) {
|
|
|
314
352
|
}
|
|
315
353
|
if (nodeTypesWithLongPlaceholderText.includes(parentType) && isEmptyNode) {
|
|
316
354
|
return setPlaceHolderState({
|
|
317
|
-
placeholderText: intl.formatMessage(messages.longEmptyNodePlaceholderText),
|
|
355
|
+
placeholderText: !fg('platform_editor_ai_aifc_patch_ga') ? intl.formatMessage(messages.longEmptyNodePlaceholderText) : undefined,
|
|
356
|
+
contextPlaceholderADF: fg('platform_editor_ai_aifc_patch_ga') ? createLongEmptyNodePlaceholderADF(intl) : undefined,
|
|
318
357
|
pos: $from.pos,
|
|
319
358
|
placeholderPrompts: placeholderPrompts,
|
|
320
359
|
typedAndDeleted: typedAndDeleted,
|
|
@@ -354,10 +393,10 @@ function createPlaceHolderStateFrom(_ref3) {
|
|
|
354
393
|
userHadTyped: userHadTyped
|
|
355
394
|
});
|
|
356
395
|
}
|
|
357
|
-
function calculateUserInteractionState(
|
|
358
|
-
var placeholderState =
|
|
359
|
-
oldEditorState =
|
|
360
|
-
newEditorState =
|
|
396
|
+
function calculateUserInteractionState(_ref6) {
|
|
397
|
+
var placeholderState = _ref6.placeholderState,
|
|
398
|
+
oldEditorState = _ref6.oldEditorState,
|
|
399
|
+
newEditorState = _ref6.newEditorState;
|
|
361
400
|
var wasEmpty = oldEditorState ? isEmptyDocument(oldEditorState.doc) : true;
|
|
362
401
|
var isEmpty = isEmptyDocument(newEditorState.doc);
|
|
363
402
|
var hasEverTyped = Boolean(placeholderState === null || placeholderState === void 0 ? void 0 : placeholderState.userHadTyped) ||
|
|
@@ -381,6 +420,8 @@ export function createPlugin(intl, defaultPlaceholderText, bracketPlaceholderTex
|
|
|
381
420
|
var isDestroyed = false;
|
|
382
421
|
var activeTypewriterTimeouts = [];
|
|
383
422
|
var clearAllTypewriterTimeouts = function clearAllTypewriterTimeouts() {
|
|
423
|
+
// @ts-ignore - Workaround for help-center local consumption
|
|
424
|
+
|
|
384
425
|
activeTypewriterTimeouts.forEach(function (clearFn) {
|
|
385
426
|
return clearFn();
|
|
386
427
|
});
|
|
@@ -389,6 +430,8 @@ export function createPlugin(intl, defaultPlaceholderText, bracketPlaceholderTex
|
|
|
389
430
|
return new SafePlugin({
|
|
390
431
|
key: pluginKey,
|
|
391
432
|
state: {
|
|
433
|
+
// @ts-ignore - Workaround for help-center local consumption
|
|
434
|
+
|
|
392
435
|
init: function init(_, state) {
|
|
393
436
|
var _api$focus, _api$typeAhead;
|
|
394
437
|
return createPlaceHolderStateFrom({
|
|
@@ -399,14 +442,17 @@ export function createPlugin(intl, defaultPlaceholderText, bracketPlaceholderTex
|
|
|
399
442
|
defaultPlaceholderText: defaultPlaceholderText,
|
|
400
443
|
bracketPlaceholderText: bracketPlaceholderText,
|
|
401
444
|
emptyLinePlaceholder: emptyLinePlaceholder,
|
|
445
|
+
placeholderADF: placeholderADF,
|
|
402
446
|
placeholderPrompts: placeholderPrompts,
|
|
403
447
|
typedAndDeleted: false,
|
|
404
448
|
userHadTyped: false,
|
|
405
449
|
intl: intl
|
|
406
450
|
});
|
|
407
451
|
},
|
|
452
|
+
// @ts-ignore - Workaround for help-center local consumption
|
|
453
|
+
|
|
408
454
|
apply: function apply(tr, placeholderState, _oldEditorState, newEditorState) {
|
|
409
|
-
var _api$focus2, _placeholderState$isP, _api$typeAhead2,
|
|
455
|
+
var _api$focus2, _placeholderState$isP, _api$typeAhead2, _ref7, _meta$placeholderText, _ref8, _meta$placeholderProm, _meta$showOnEmptyPara;
|
|
410
456
|
var meta = tr.getMeta(pluginKey);
|
|
411
457
|
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
458
|
var _calculateUserInterac = calculateUserInteractionState({
|
|
@@ -420,17 +466,21 @@ export function createPlugin(intl, defaultPlaceholderText, bracketPlaceholderTex
|
|
|
420
466
|
if ((meta === null || meta === void 0 ? void 0 : meta.isPlaceholderHidden) !== undefined && fg('platform_editor_ai_aifc_patch_beta')) {
|
|
421
467
|
isPlaceholderHidden = meta.isPlaceholderHidden;
|
|
422
468
|
}
|
|
423
|
-
if ((meta === null || meta === void 0 ? void 0 : meta.placeholderText) !== undefined && fg('platform_editor_ai_aifc_patch_beta_2')) {
|
|
424
|
-
defaultPlaceholderText
|
|
469
|
+
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'))) {
|
|
470
|
+
// Only update defaultPlaceholderText from meta if we're not using ADF placeholder
|
|
471
|
+
if (!(fg('platform_editor_ai_aifc_patch_ga') && placeholderADF)) {
|
|
472
|
+
defaultPlaceholderText = meta.placeholderText;
|
|
473
|
+
}
|
|
425
474
|
}
|
|
426
475
|
var newPlaceholderState = createPlaceHolderStateFrom({
|
|
427
476
|
isEditorFocused: isEditorFocused,
|
|
428
477
|
editorState: newEditorState,
|
|
429
478
|
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 : (
|
|
479
|
+
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
480
|
bracketPlaceholderText: bracketPlaceholderText,
|
|
432
481
|
emptyLinePlaceholder: emptyLinePlaceholder,
|
|
433
|
-
|
|
482
|
+
placeholderADF: placeholderADF,
|
|
483
|
+
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
484
|
typedAndDeleted: typedAndDeleted,
|
|
435
485
|
userHadTyped: userHadTyped,
|
|
436
486
|
intl: intl,
|
|
@@ -447,13 +497,15 @@ export function createPlugin(intl, defaultPlaceholderText, bracketPlaceholderTex
|
|
|
447
497
|
}
|
|
448
498
|
},
|
|
449
499
|
props: {
|
|
500
|
+
// @ts-ignore - Workaround for help-center local consumption
|
|
450
501
|
decorations: function decorations(editorState) {
|
|
451
502
|
var _api$composition, _api$showDiff;
|
|
452
503
|
var _getPlaceholderState = getPlaceholderState(editorState),
|
|
453
504
|
hasPlaceholder = _getPlaceholderState.hasPlaceholder,
|
|
454
505
|
placeholderText = _getPlaceholderState.placeholderText,
|
|
455
506
|
pos = _getPlaceholderState.pos,
|
|
456
|
-
typedAndDeleted = _getPlaceholderState.typedAndDeleted
|
|
507
|
+
typedAndDeleted = _getPlaceholderState.typedAndDeleted,
|
|
508
|
+
contextPlaceholderADF = _getPlaceholderState.contextPlaceholderADF;
|
|
457
509
|
|
|
458
510
|
// Decorations is still called after plugin is destroyed
|
|
459
511
|
// So we need to make sure decorations is not called if plugin has been destroyed to prevent the placeholder animations' setTimeouts called infinitely
|
|
@@ -462,13 +514,16 @@ export function createPlugin(intl, defaultPlaceholderText, bracketPlaceholderTex
|
|
|
462
514
|
}
|
|
463
515
|
var compositionPluginState = api === null || api === void 0 || (_api$composition = api.composition) === null || _api$composition === void 0 ? void 0 : _api$composition.sharedState.currentState();
|
|
464
516
|
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) {
|
|
517
|
+
if (hasPlaceholder && ((placeholderText !== null && placeholderText !== void 0 ? placeholderText : '') || placeholderPrompts || placeholderADF || contextPlaceholderADF) && pos !== undefined && !(compositionPluginState !== null && compositionPluginState !== void 0 && compositionPluginState.isComposing) && !isShowingDiff) {
|
|
466
518
|
var initialDelayWhenUserTypedAndDeleted = typedAndDeleted ? TYPEWRITER_TYPED_AND_DELETED_DELAY : 0;
|
|
467
|
-
|
|
519
|
+
// contextPlaceholderADF takes precedence over the global placeholderADF
|
|
520
|
+
var placeholderAdfToUse = contextPlaceholderADF || placeholderADF;
|
|
521
|
+
return createPlaceholderDecoration(editorState, placeholderText !== null && placeholderText !== void 0 ? placeholderText : '', placeholderPrompts, activeTypewriterTimeouts, pos, initialDelayWhenUserTypedAndDeleted, placeholderAdfToUse);
|
|
468
522
|
}
|
|
469
523
|
return;
|
|
470
524
|
}
|
|
471
525
|
},
|
|
526
|
+
// @ts-ignore - Workaround for help-center local consumption
|
|
472
527
|
view: function view() {
|
|
473
528
|
var timeoutId;
|
|
474
529
|
function startEmptyParagraphTimeout(editorView) {
|
|
@@ -489,8 +544,9 @@ export function createPlugin(intl, defaultPlaceholderText, bracketPlaceholderTex
|
|
|
489
544
|
}
|
|
490
545
|
}
|
|
491
546
|
return {
|
|
547
|
+
// @ts-ignore - Workaround for help-center local consumption
|
|
492
548
|
update: function update(editorView, prevState) {
|
|
493
|
-
if (fg('platform_editor_ai_aifc_patch_beta_2')) {
|
|
549
|
+
if (fg('platform_editor_ai_aifc_patch_beta_2') || fg('platform_editor_ai_aifc_patch_ga')) {
|
|
494
550
|
var prevPluginState = getPlaceholderState(prevState);
|
|
495
551
|
var newPluginState = getPlaceholderState(editorView.state);
|
|
496
552
|
|
|
@@ -512,6 +568,7 @@ export function createPlugin(intl, defaultPlaceholderText, bracketPlaceholderTex
|
|
|
512
568
|
}
|
|
513
569
|
}
|
|
514
570
|
},
|
|
571
|
+
// @ts-ignore - Workaround for help-center local consumption
|
|
515
572
|
destroy: function destroy() {
|
|
516
573
|
clearAllTypewriterTimeouts();
|
|
517
574
|
destroyEmptyParagraphTimeout();
|
|
@@ -521,16 +578,16 @@ export function createPlugin(intl, defaultPlaceholderText, bracketPlaceholderTex
|
|
|
521
578
|
}
|
|
522
579
|
});
|
|
523
580
|
}
|
|
524
|
-
export var placeholderPlugin = function placeholderPlugin(
|
|
525
|
-
var options =
|
|
526
|
-
api =
|
|
581
|
+
export var placeholderPlugin = function placeholderPlugin(_ref9) {
|
|
582
|
+
var options = _ref9.config,
|
|
583
|
+
api = _ref9.api;
|
|
527
584
|
var currentPlaceholder = options === null || options === void 0 ? void 0 : options.placeholder;
|
|
528
585
|
return {
|
|
529
586
|
name: 'placeholder',
|
|
530
587
|
commands: {
|
|
531
588
|
setPlaceholder: function setPlaceholder(placeholderText) {
|
|
532
|
-
return function (
|
|
533
|
-
var tr =
|
|
589
|
+
return function (_ref0) {
|
|
590
|
+
var tr = _ref0.tr;
|
|
534
591
|
if (currentPlaceholder !== placeholderText) {
|
|
535
592
|
currentPlaceholder = placeholderText;
|
|
536
593
|
return tr.setMeta(pluginKey, {
|
|
@@ -541,16 +598,16 @@ export var placeholderPlugin = function placeholderPlugin(_ref7) {
|
|
|
541
598
|
};
|
|
542
599
|
},
|
|
543
600
|
setAnimatingPlaceholderPrompts: function setAnimatingPlaceholderPrompts(placeholderPrompts) {
|
|
544
|
-
return function (
|
|
545
|
-
var tr =
|
|
601
|
+
return function (_ref1) {
|
|
602
|
+
var tr = _ref1.tr;
|
|
546
603
|
return tr.setMeta(pluginKey, {
|
|
547
604
|
placeholderPrompts: placeholderPrompts
|
|
548
605
|
});
|
|
549
606
|
};
|
|
550
607
|
},
|
|
551
608
|
setPlaceholderHidden: function setPlaceholderHidden(isPlaceholderHidden) {
|
|
552
|
-
return function (
|
|
553
|
-
var tr =
|
|
609
|
+
return function (_ref10) {
|
|
610
|
+
var tr = _ref10.tr;
|
|
554
611
|
return tr.setMeta(pluginKey, {
|
|
555
612
|
isPlaceholderHidden: isPlaceholderHidden
|
|
556
613
|
});
|
|
@@ -560,8 +617,8 @@ export var placeholderPlugin = function placeholderPlugin(_ref7) {
|
|
|
560
617
|
pmPlugins: function pmPlugins() {
|
|
561
618
|
return [{
|
|
562
619
|
name: 'placeholder',
|
|
563
|
-
plugin: function plugin(
|
|
564
|
-
var getIntl =
|
|
620
|
+
plugin: function plugin(_ref11) {
|
|
621
|
+
var getIntl = _ref11.getIntl;
|
|
565
622
|
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
623
|
}
|
|
567
624
|
}];
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@atlaskit/editor-plugin-placeholder",
|
|
3
|
-
"version": "6.
|
|
3
|
+
"version": "6.5.1",
|
|
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.
|
|
37
|
-
"@atlaskit/tokens": "^8.
|
|
37
|
+
"@atlaskit/tmp-editor-statsig": "^13.42.0",
|
|
38
|
+
"@atlaskit/tokens": "^8.3.0",
|
|
38
39
|
"@babel/runtime": "^7.0.0"
|
|
39
40
|
},
|
|
40
41
|
"peerDependencies": {
|
|
41
|
-
"@atlaskit/editor-common": "^110.
|
|
42
|
+
"@atlaskit/editor-common": "^110.34.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"
|