@atlaskit/editor-plugin-placeholder 6.3.0 → 6.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +19 -0
- package/dist/cjs/placeholderPlugin.js +138 -62
- package/dist/es2019/placeholderPlugin.js +90 -17
- package/dist/esm/placeholderPlugin.js +138 -62
- package/dist/types/placeholderPlugin.d.ts +3 -2
- package/dist/types/placeholderPluginType.d.ts +2 -0
- package/dist/types-ts4.5/placeholderPlugin.d.ts +3 -2
- package/dist/types-ts4.5/placeholderPluginType.d.ts +2 -0
- package/package.json +9 -4
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,24 @@
|
|
|
1
1
|
# @atlaskit/editor-plugin-placeholder
|
|
2
2
|
|
|
3
|
+
## 6.5.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- [`025002b2a71fc`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/025002b2a71fc) -
|
|
8
|
+
[ux] [EDITOR-3320] fix bug on panel and table placeholders/ added code mark on keyboard shorcuts
|
|
9
|
+
on panel and table placeholders
|
|
10
|
+
|
|
11
|
+
### Patch Changes
|
|
12
|
+
|
|
13
|
+
- Updated dependencies
|
|
14
|
+
|
|
15
|
+
## 6.4.0
|
|
16
|
+
|
|
17
|
+
### Minor Changes
|
|
18
|
+
|
|
19
|
+
- [`f34c6075cc3a4`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/f34c6075cc3a4) -
|
|
20
|
+
[ux] [EDITOR-2327] added support to add marks on placeholder plugin texts
|
|
21
|
+
|
|
3
22
|
## 6.3.0
|
|
4
23
|
|
|
5
24
|
### Minor Changes
|
|
@@ -9,9 +9,12 @@ 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");
|
|
14
|
+
var _processRawValue = require("@atlaskit/editor-common/process-raw-value");
|
|
13
15
|
var _safePlugin = require("@atlaskit/editor-common/safe-plugin");
|
|
14
16
|
var _utils = require("@atlaskit/editor-common/utils");
|
|
17
|
+
var _model = require("@atlaskit/editor-prosemirror/model");
|
|
15
18
|
var _state = require("@atlaskit/editor-prosemirror/state");
|
|
16
19
|
var _utils2 = require("@atlaskit/editor-prosemirror/utils");
|
|
17
20
|
var _view = require("@atlaskit/editor-prosemirror/view");
|
|
@@ -37,6 +40,28 @@ function getPlaceholderState(editorState) {
|
|
|
37
40
|
var nodeTypesWithLongPlaceholderText = ['expand', 'panel'];
|
|
38
41
|
var nodeTypesWithShortPlaceholderText = ['tableCell', 'tableHeader'];
|
|
39
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
|
+
};
|
|
40
65
|
var cycleThroughPlaceholderPrompts = function cycleThroughPlaceholderPrompts(placeholderPrompts, activeTypewriterTimeouts, placeholderNodeWithText) {
|
|
41
66
|
var initialDelayWhenUserTypedAndDeleted = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : 0;
|
|
42
67
|
var currentPromptIndex = 0;
|
|
@@ -91,10 +116,12 @@ var cycleThroughPlaceholderPrompts = function cycleThroughPlaceholderPrompts(pla
|
|
|
91
116
|
function createPlaceholderDecoration(editorState, placeholderText, placeholderPrompts, activeTypewriterTimeouts) {
|
|
92
117
|
var pos = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : 1;
|
|
93
118
|
var initialDelayWhenUserTypedAndDeleted = arguments.length > 5 && arguments[5] !== undefined ? arguments[5] : 0;
|
|
119
|
+
var placeholderADF = arguments.length > 6 ? arguments[6] : undefined;
|
|
94
120
|
var placeholderDecoration = document.createElement('span');
|
|
95
121
|
var placeholderNodeWithText = placeholderDecoration;
|
|
96
122
|
placeholderDecoration.setAttribute('data-testid', placeholderTestId);
|
|
97
123
|
placeholderDecoration.className = 'placeholder-decoration';
|
|
124
|
+
placeholderDecoration.setAttribute('aria-hidden', 'true');
|
|
98
125
|
|
|
99
126
|
// PM sets contenteditable to false on Decorations so Firefox doesn't display the flashing cursor
|
|
100
127
|
// So adding an extra span which will contain the placeholder text
|
|
@@ -106,6 +133,42 @@ function createPlaceholderDecoration(editorState, placeholderText, placeholderPr
|
|
|
106
133
|
}
|
|
107
134
|
if (placeholderText) {
|
|
108
135
|
placeholderNodeWithText.textContent = placeholderText || ' ';
|
|
136
|
+
} else if (placeholderADF) {
|
|
137
|
+
var serializer = _model.DOMSerializer.fromSchema(editorState.schema);
|
|
138
|
+
// Get a PMNode from docnode
|
|
139
|
+
var docNode = (0, _processRawValue.processRawValue)(editorState.schema, placeholderADF);
|
|
140
|
+
if (docNode) {
|
|
141
|
+
// Extract only the inline content from paragraphs, avoiding block-level elements
|
|
142
|
+
// that can interfere with cursor rendering
|
|
143
|
+
docNode.children.forEach(function (node) {
|
|
144
|
+
// For paragraph nodes, serialize their content (inline elements) directly
|
|
145
|
+
// without the wrapping <p> tag
|
|
146
|
+
if (node.type.name === 'paragraph') {
|
|
147
|
+
node.content.forEach(function (inlineNode) {
|
|
148
|
+
var inlineDOM = serializer.serializeNode(inlineNode);
|
|
149
|
+
placeholderNodeWithText.append(inlineDOM);
|
|
150
|
+
});
|
|
151
|
+
} else {
|
|
152
|
+
// For non-paragraph nodes, serialize normally
|
|
153
|
+
var nodeDOM = serializer.serializeNode(node);
|
|
154
|
+
placeholderNodeWithText.append(nodeDOM);
|
|
155
|
+
}
|
|
156
|
+
});
|
|
157
|
+
var markElements = placeholderNodeWithText.querySelectorAll('[data-prosemirror-content-type="mark"]');
|
|
158
|
+
markElements.forEach(function (markEl) {
|
|
159
|
+
if (markEl instanceof HTMLElement) {
|
|
160
|
+
markEl.style.setProperty('color', "var(--ds-text-subtlest, #6B6E76)");
|
|
161
|
+
}
|
|
162
|
+
});
|
|
163
|
+
// Ensure all child elements don't block pointer events or cursor
|
|
164
|
+
var allElements = placeholderNodeWithText.querySelectorAll('*');
|
|
165
|
+
allElements.forEach(function (el) {
|
|
166
|
+
if (el instanceof HTMLElement) {
|
|
167
|
+
el.style.pointerEvents = 'none';
|
|
168
|
+
el.style.userSelect = 'none';
|
|
169
|
+
}
|
|
170
|
+
});
|
|
171
|
+
}
|
|
109
172
|
} else if (placeholderPrompts) {
|
|
110
173
|
cycleThroughPlaceholderPrompts(placeholderPrompts, activeTypewriterTimeouts, placeholderNodeWithText, initialDelayWhenUserTypedAndDeleted);
|
|
111
174
|
}
|
|
@@ -132,18 +195,20 @@ function createPlaceholderDecoration(editorState, placeholderText, placeholderPr
|
|
|
132
195
|
key: "placeholder ".concat(placeholderText)
|
|
133
196
|
})]);
|
|
134
197
|
}
|
|
135
|
-
function setPlaceHolderState(
|
|
136
|
-
var placeholderText =
|
|
137
|
-
pos =
|
|
138
|
-
placeholderPrompts =
|
|
139
|
-
typedAndDeleted =
|
|
140
|
-
userHadTyped =
|
|
141
|
-
canShowOnEmptyParagraph =
|
|
142
|
-
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;
|
|
143
207
|
return {
|
|
144
208
|
hasPlaceholder: true,
|
|
145
209
|
placeholderText: placeholderText,
|
|
146
210
|
placeholderPrompts: placeholderPrompts,
|
|
211
|
+
contextPlaceholderADF: contextPlaceholderADF,
|
|
147
212
|
pos: pos ? pos : 1,
|
|
148
213
|
typedAndDeleted: typedAndDeleted,
|
|
149
214
|
userHadTyped: userHadTyped,
|
|
@@ -151,13 +216,13 @@ function setPlaceHolderState(_ref) {
|
|
|
151
216
|
showOnEmptyParagraph: showOnEmptyParagraph
|
|
152
217
|
};
|
|
153
218
|
}
|
|
154
|
-
var emptyPlaceholder = function emptyPlaceholder(
|
|
155
|
-
var placeholderText =
|
|
156
|
-
placeholderPrompts =
|
|
157
|
-
userHadTyped =
|
|
158
|
-
pos =
|
|
159
|
-
canShowOnEmptyParagraph =
|
|
160
|
-
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;
|
|
161
226
|
return {
|
|
162
227
|
hasPlaceholder: false,
|
|
163
228
|
placeholderText: placeholderText,
|
|
@@ -169,21 +234,22 @@ var emptyPlaceholder = function emptyPlaceholder(_ref2) {
|
|
|
169
234
|
pos: pos
|
|
170
235
|
};
|
|
171
236
|
};
|
|
172
|
-
function createPlaceHolderStateFrom(
|
|
173
|
-
var isInitial =
|
|
174
|
-
isEditorFocused =
|
|
175
|
-
editorState =
|
|
176
|
-
isTypeAheadOpen =
|
|
177
|
-
defaultPlaceholderText =
|
|
178
|
-
intl =
|
|
179
|
-
bracketPlaceholderText =
|
|
180
|
-
emptyLinePlaceholder =
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
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;
|
|
187
253
|
if (isPlaceholderHidden && (0, _platformFeatureFlags.fg)('platform_editor_ai_aifc_patch_beta')) {
|
|
188
254
|
return _objectSpread(_objectSpread({}, emptyPlaceholder({
|
|
189
255
|
placeholderText: defaultPlaceholderText,
|
|
@@ -200,7 +266,7 @@ function createPlaceHolderStateFrom(_ref3) {
|
|
|
200
266
|
userHadTyped: userHadTyped
|
|
201
267
|
});
|
|
202
268
|
}
|
|
203
|
-
if ((defaultPlaceholderText || placeholderPrompts) && (0, _utils.isEmptyDocument)(editorState.doc)) {
|
|
269
|
+
if ((defaultPlaceholderText || placeholderPrompts || placeholderADF) && (0, _utils.isEmptyDocument)(editorState.doc)) {
|
|
204
270
|
return setPlaceHolderState({
|
|
205
271
|
placeholderText: defaultPlaceholderText,
|
|
206
272
|
pos: 1,
|
|
@@ -209,12 +275,12 @@ function createPlaceHolderStateFrom(_ref3) {
|
|
|
209
275
|
userHadTyped: userHadTyped
|
|
210
276
|
});
|
|
211
277
|
}
|
|
212
|
-
if ((0, _platformFeatureFlags.fg)('platform_editor_ai_aifc_patch_beta_2')) {
|
|
278
|
+
if ((0, _platformFeatureFlags.fg)('platform_editor_ai_aifc_patch_beta_2') || (0, _platformFeatureFlags.fg)('platform_editor_ai_aifc_patch_ga')) {
|
|
213
279
|
var _editorState$selectio = editorState.selection,
|
|
214
280
|
from = _editorState$selectio.from,
|
|
215
281
|
to = _editorState$selectio.to,
|
|
216
282
|
$to = _editorState$selectio.$to;
|
|
217
|
-
if (defaultPlaceholderText && withEmptyParagraph && isEditorFocused && !isInitial && !(0, _utils.isEmptyDocument)(editorState.doc) && from === to && (0, _utils.isEmptyParagraph)($to.parent) && (0, _utils.hasDocAsParent)($to)) {
|
|
283
|
+
if ((defaultPlaceholderText || placeholderADF) && withEmptyParagraph && isEditorFocused && !isInitial && !(0, _utils.isEmptyDocument)(editorState.doc) && from === to && (0, _utils.isEmptyParagraph)($to.parent) && (0, _utils.hasDocAsParent)($to)) {
|
|
218
284
|
return showOnEmptyParagraph ? setPlaceHolderState({
|
|
219
285
|
placeholderText: defaultPlaceholderText,
|
|
220
286
|
pos: to,
|
|
@@ -275,7 +341,8 @@ function createPlaceHolderStateFrom(_ref3) {
|
|
|
275
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;
|
|
276
342
|
if (isFirstCell) {
|
|
277
343
|
return setPlaceHolderState({
|
|
278
|
-
placeholderText: intl.formatMessage(_messages.placeholderTextMessages.shortEmptyNodePlaceholderText),
|
|
344
|
+
placeholderText: !(0, _platformFeatureFlags.fg)('platform_editor_ai_aifc_patch_ga') ? intl.formatMessage(_messages.placeholderTextMessages.shortEmptyNodePlaceholderText) : undefined,
|
|
345
|
+
contextPlaceholderADF: (0, _platformFeatureFlags.fg)('platform_editor_ai_aifc_patch_ga') ? createShortEmptyNodePlaceholderADF(intl) : undefined,
|
|
279
346
|
pos: $from.pos,
|
|
280
347
|
placeholderPrompts: placeholderPrompts,
|
|
281
348
|
typedAndDeleted: typedAndDeleted,
|
|
@@ -285,7 +352,8 @@ function createPlaceHolderStateFrom(_ref3) {
|
|
|
285
352
|
}
|
|
286
353
|
if (nodeTypesWithLongPlaceholderText.includes(parentType) && isEmptyNode) {
|
|
287
354
|
return setPlaceHolderState({
|
|
288
|
-
placeholderText: intl.formatMessage(_messages.placeholderTextMessages.longEmptyNodePlaceholderText),
|
|
355
|
+
placeholderText: !(0, _platformFeatureFlags.fg)('platform_editor_ai_aifc_patch_ga') ? intl.formatMessage(_messages.placeholderTextMessages.longEmptyNodePlaceholderText) : undefined,
|
|
356
|
+
contextPlaceholderADF: (0, _platformFeatureFlags.fg)('platform_editor_ai_aifc_patch_ga') ? createLongEmptyNodePlaceholderADF(intl) : undefined,
|
|
289
357
|
pos: $from.pos,
|
|
290
358
|
placeholderPrompts: placeholderPrompts,
|
|
291
359
|
typedAndDeleted: typedAndDeleted,
|
|
@@ -325,10 +393,10 @@ function createPlaceHolderStateFrom(_ref3) {
|
|
|
325
393
|
userHadTyped: userHadTyped
|
|
326
394
|
});
|
|
327
395
|
}
|
|
328
|
-
function calculateUserInteractionState(
|
|
329
|
-
var placeholderState =
|
|
330
|
-
oldEditorState =
|
|
331
|
-
newEditorState =
|
|
396
|
+
function calculateUserInteractionState(_ref6) {
|
|
397
|
+
var placeholderState = _ref6.placeholderState,
|
|
398
|
+
oldEditorState = _ref6.oldEditorState,
|
|
399
|
+
newEditorState = _ref6.newEditorState;
|
|
332
400
|
var wasEmpty = oldEditorState ? (0, _utils.isEmptyDocument)(oldEditorState.doc) : true;
|
|
333
401
|
var isEmpty = (0, _utils.isEmptyDocument)(newEditorState.doc);
|
|
334
402
|
var hasEverTyped = Boolean(placeholderState === null || placeholderState === void 0 ? void 0 : placeholderState.userHadTyped) ||
|
|
@@ -345,8 +413,8 @@ function calculateUserInteractionState(_ref4) {
|
|
|
345
413
|
typedAndDeleted: isInTypedAndDeletedState
|
|
346
414
|
};
|
|
347
415
|
}
|
|
348
|
-
function createPlugin(intl, defaultPlaceholderText, bracketPlaceholderText, emptyLinePlaceholder, placeholderPrompts, withEmptyParagraph, api) {
|
|
349
|
-
if (!defaultPlaceholderText && !placeholderPrompts && !bracketPlaceholderText) {
|
|
416
|
+
function createPlugin(intl, defaultPlaceholderText, bracketPlaceholderText, emptyLinePlaceholder, placeholderPrompts, withEmptyParagraph, placeholderADF, api) {
|
|
417
|
+
if (!defaultPlaceholderText && !placeholderPrompts && !bracketPlaceholderText && !placeholderADF) {
|
|
350
418
|
return;
|
|
351
419
|
}
|
|
352
420
|
var isDestroyed = false;
|
|
@@ -370,6 +438,7 @@ function createPlugin(intl, defaultPlaceholderText, bracketPlaceholderText, empt
|
|
|
370
438
|
defaultPlaceholderText: defaultPlaceholderText,
|
|
371
439
|
bracketPlaceholderText: bracketPlaceholderText,
|
|
372
440
|
emptyLinePlaceholder: emptyLinePlaceholder,
|
|
441
|
+
placeholderADF: placeholderADF,
|
|
373
442
|
placeholderPrompts: placeholderPrompts,
|
|
374
443
|
typedAndDeleted: false,
|
|
375
444
|
userHadTyped: false,
|
|
@@ -377,7 +446,7 @@ function createPlugin(intl, defaultPlaceholderText, bracketPlaceholderText, empt
|
|
|
377
446
|
});
|
|
378
447
|
},
|
|
379
448
|
apply: function apply(tr, placeholderState, _oldEditorState, newEditorState) {
|
|
380
|
-
var _api$focus2, _placeholderState$isP, _api$typeAhead2,
|
|
449
|
+
var _api$focus2, _placeholderState$isP, _api$typeAhead2, _ref7, _meta$placeholderText, _ref8, _meta$placeholderProm, _meta$showOnEmptyPara;
|
|
381
450
|
var meta = tr.getMeta(pluginKey);
|
|
382
451
|
var isEditorFocused = Boolean(api === null || api === void 0 || (_api$focus2 = api.focus) === null || _api$focus2 === void 0 || (_api$focus2 = _api$focus2.sharedState.currentState()) === null || _api$focus2 === void 0 ? void 0 : _api$focus2.hasFocus);
|
|
383
452
|
var _calculateUserInterac = calculateUserInteractionState({
|
|
@@ -391,17 +460,21 @@ function createPlugin(intl, defaultPlaceholderText, bracketPlaceholderText, empt
|
|
|
391
460
|
if ((meta === null || meta === void 0 ? void 0 : meta.isPlaceholderHidden) !== undefined && (0, _platformFeatureFlags.fg)('platform_editor_ai_aifc_patch_beta')) {
|
|
392
461
|
isPlaceholderHidden = meta.isPlaceholderHidden;
|
|
393
462
|
}
|
|
394
|
-
if ((meta === null || meta === void 0 ? void 0 : meta.placeholderText) !== undefined && (0, _platformFeatureFlags.fg)('platform_editor_ai_aifc_patch_beta_2')) {
|
|
395
|
-
defaultPlaceholderText
|
|
463
|
+
if ((meta === null || meta === void 0 ? void 0 : meta.placeholderText) !== undefined && ((0, _platformFeatureFlags.fg)('platform_editor_ai_aifc_patch_beta_2') || (0, _platformFeatureFlags.fg)('platform_editor_ai_aifc_patch_ga'))) {
|
|
464
|
+
// Only update defaultPlaceholderText from meta if we're not using ADF placeholder
|
|
465
|
+
if (!((0, _platformFeatureFlags.fg)('platform_editor_ai_aifc_patch_ga') && placeholderADF)) {
|
|
466
|
+
defaultPlaceholderText = meta.placeholderText;
|
|
467
|
+
}
|
|
396
468
|
}
|
|
397
469
|
var newPlaceholderState = createPlaceHolderStateFrom({
|
|
398
470
|
isEditorFocused: isEditorFocused,
|
|
399
471
|
editorState: newEditorState,
|
|
400
472
|
isTypeAheadOpen: api === null || api === void 0 || (_api$typeAhead2 = api.typeAhead) === null || _api$typeAhead2 === void 0 ? void 0 : _api$typeAhead2.actions.isOpen,
|
|
401
|
-
defaultPlaceholderText: (0, _platformFeatureFlags.fg)('platform_editor_ai_aifc_patch_beta_2') ? defaultPlaceholderText : (
|
|
473
|
+
defaultPlaceholderText: (0, _platformFeatureFlags.fg)('platform_editor_ai_aifc_patch_beta_2') || (0, _platformFeatureFlags.fg)('platform_editor_ai_aifc_patch_ga') ? defaultPlaceholderText : (_ref7 = (_meta$placeholderText = meta === null || meta === void 0 ? void 0 : meta.placeholderText) !== null && _meta$placeholderText !== void 0 ? _meta$placeholderText : placeholderState === null || placeholderState === void 0 ? void 0 : placeholderState.placeholderText) !== null && _ref7 !== void 0 ? _ref7 : defaultPlaceholderText,
|
|
402
474
|
bracketPlaceholderText: bracketPlaceholderText,
|
|
403
475
|
emptyLinePlaceholder: emptyLinePlaceholder,
|
|
404
|
-
|
|
476
|
+
placeholderADF: placeholderADF,
|
|
477
|
+
placeholderPrompts: (_ref8 = (_meta$placeholderProm = meta === null || meta === void 0 ? void 0 : meta.placeholderPrompts) !== null && _meta$placeholderProm !== void 0 ? _meta$placeholderProm : placeholderState === null || placeholderState === void 0 ? void 0 : placeholderState.placeholderPrompts) !== null && _ref8 !== void 0 ? _ref8 : placeholderPrompts,
|
|
405
478
|
typedAndDeleted: typedAndDeleted,
|
|
406
479
|
userHadTyped: userHadTyped,
|
|
407
480
|
intl: intl,
|
|
@@ -424,7 +497,8 @@ function createPlugin(intl, defaultPlaceholderText, bracketPlaceholderText, empt
|
|
|
424
497
|
hasPlaceholder = _getPlaceholderState.hasPlaceholder,
|
|
425
498
|
placeholderText = _getPlaceholderState.placeholderText,
|
|
426
499
|
pos = _getPlaceholderState.pos,
|
|
427
|
-
typedAndDeleted = _getPlaceholderState.typedAndDeleted
|
|
500
|
+
typedAndDeleted = _getPlaceholderState.typedAndDeleted,
|
|
501
|
+
contextPlaceholderADF = _getPlaceholderState.contextPlaceholderADF;
|
|
428
502
|
|
|
429
503
|
// Decorations is still called after plugin is destroyed
|
|
430
504
|
// So we need to make sure decorations is not called if plugin has been destroyed to prevent the placeholder animations' setTimeouts called infinitely
|
|
@@ -433,9 +507,11 @@ function createPlugin(intl, defaultPlaceholderText, bracketPlaceholderText, empt
|
|
|
433
507
|
}
|
|
434
508
|
var compositionPluginState = api === null || api === void 0 || (_api$composition = api.composition) === null || _api$composition === void 0 ? void 0 : _api$composition.sharedState.currentState();
|
|
435
509
|
var isShowingDiff = Boolean(api === null || api === void 0 || (_api$showDiff = api.showDiff) === null || _api$showDiff === void 0 || (_api$showDiff = _api$showDiff.sharedState.currentState()) === null || _api$showDiff === void 0 ? void 0 : _api$showDiff.isDisplayingChanges);
|
|
436
|
-
if (hasPlaceholder && ((placeholderText !== null && placeholderText !== void 0 ? placeholderText : '') || placeholderPrompts) && pos !== undefined && !(compositionPluginState !== null && compositionPluginState !== void 0 && compositionPluginState.isComposing) && !isShowingDiff) {
|
|
510
|
+
if (hasPlaceholder && ((placeholderText !== null && placeholderText !== void 0 ? placeholderText : '') || placeholderPrompts || placeholderADF || contextPlaceholderADF) && pos !== undefined && !(compositionPluginState !== null && compositionPluginState !== void 0 && compositionPluginState.isComposing) && !isShowingDiff) {
|
|
437
511
|
var initialDelayWhenUserTypedAndDeleted = typedAndDeleted ? TYPEWRITER_TYPED_AND_DELETED_DELAY : 0;
|
|
438
|
-
|
|
512
|
+
// contextPlaceholderADF takes precedence over the global placeholderADF
|
|
513
|
+
var placeholderAdfToUse = contextPlaceholderADF || placeholderADF;
|
|
514
|
+
return createPlaceholderDecoration(editorState, placeholderText !== null && placeholderText !== void 0 ? placeholderText : '', placeholderPrompts, activeTypewriterTimeouts, pos, initialDelayWhenUserTypedAndDeleted, placeholderAdfToUse);
|
|
439
515
|
}
|
|
440
516
|
return;
|
|
441
517
|
}
|
|
@@ -461,7 +537,7 @@ function createPlugin(intl, defaultPlaceholderText, bracketPlaceholderText, empt
|
|
|
461
537
|
}
|
|
462
538
|
return {
|
|
463
539
|
update: function update(editorView, prevState) {
|
|
464
|
-
if ((0, _platformFeatureFlags.fg)('platform_editor_ai_aifc_patch_beta_2')) {
|
|
540
|
+
if ((0, _platformFeatureFlags.fg)('platform_editor_ai_aifc_patch_beta_2') || (0, _platformFeatureFlags.fg)('platform_editor_ai_aifc_patch_ga')) {
|
|
465
541
|
var prevPluginState = getPlaceholderState(prevState);
|
|
466
542
|
var newPluginState = getPlaceholderState(editorView.state);
|
|
467
543
|
|
|
@@ -492,16 +568,16 @@ function createPlugin(intl, defaultPlaceholderText, bracketPlaceholderText, empt
|
|
|
492
568
|
}
|
|
493
569
|
});
|
|
494
570
|
}
|
|
495
|
-
var placeholderPlugin = exports.placeholderPlugin = function placeholderPlugin(
|
|
496
|
-
var options =
|
|
497
|
-
api =
|
|
571
|
+
var placeholderPlugin = exports.placeholderPlugin = function placeholderPlugin(_ref9) {
|
|
572
|
+
var options = _ref9.config,
|
|
573
|
+
api = _ref9.api;
|
|
498
574
|
var currentPlaceholder = options === null || options === void 0 ? void 0 : options.placeholder;
|
|
499
575
|
return {
|
|
500
576
|
name: 'placeholder',
|
|
501
577
|
commands: {
|
|
502
578
|
setPlaceholder: function setPlaceholder(placeholderText) {
|
|
503
|
-
return function (
|
|
504
|
-
var tr =
|
|
579
|
+
return function (_ref0) {
|
|
580
|
+
var tr = _ref0.tr;
|
|
505
581
|
if (currentPlaceholder !== placeholderText) {
|
|
506
582
|
currentPlaceholder = placeholderText;
|
|
507
583
|
return tr.setMeta(pluginKey, {
|
|
@@ -512,16 +588,16 @@ var placeholderPlugin = exports.placeholderPlugin = function placeholderPlugin(_
|
|
|
512
588
|
};
|
|
513
589
|
},
|
|
514
590
|
setAnimatingPlaceholderPrompts: function setAnimatingPlaceholderPrompts(placeholderPrompts) {
|
|
515
|
-
return function (
|
|
516
|
-
var tr =
|
|
591
|
+
return function (_ref1) {
|
|
592
|
+
var tr = _ref1.tr;
|
|
517
593
|
return tr.setMeta(pluginKey, {
|
|
518
594
|
placeholderPrompts: placeholderPrompts
|
|
519
595
|
});
|
|
520
596
|
};
|
|
521
597
|
},
|
|
522
598
|
setPlaceholderHidden: function setPlaceholderHidden(isPlaceholderHidden) {
|
|
523
|
-
return function (
|
|
524
|
-
var tr =
|
|
599
|
+
return function (_ref10) {
|
|
600
|
+
var tr = _ref10.tr;
|
|
525
601
|
return tr.setMeta(pluginKey, {
|
|
526
602
|
isPlaceholderHidden: isPlaceholderHidden
|
|
527
603
|
});
|
|
@@ -531,9 +607,9 @@ var placeholderPlugin = exports.placeholderPlugin = function placeholderPlugin(_
|
|
|
531
607
|
pmPlugins: function pmPlugins() {
|
|
532
608
|
return [{
|
|
533
609
|
name: 'placeholder',
|
|
534
|
-
plugin: function plugin(
|
|
535
|
-
var getIntl =
|
|
536
|
-
return createPlugin(getIntl(), options && options.placeholder, options && options.placeholderBracketHint, options && options.emptyLinePlaceholder, options && options.placeholderPrompts, options === null || options === void 0 ? void 0 : options.withEmptyParagraph, api);
|
|
610
|
+
plugin: function plugin(_ref11) {
|
|
611
|
+
var getIntl = _ref11.getIntl;
|
|
612
|
+
return createPlugin(getIntl(), options && options.placeholder, options && options.placeholderBracketHint, options && options.emptyLinePlaceholder, options && options.placeholderPrompts, options === null || options === void 0 ? void 0 : options.withEmptyParagraph, options && options.placeholderADF, api);
|
|
537
613
|
}
|
|
538
614
|
}];
|
|
539
615
|
}
|
|
@@ -1,6 +1,9 @@
|
|
|
1
|
+
import { code, text } from '@atlaskit/adf-utils/builders';
|
|
1
2
|
import { placeholderTextMessages as messages } from '@atlaskit/editor-common/messages';
|
|
3
|
+
import { processRawValue } from '@atlaskit/editor-common/process-raw-value';
|
|
2
4
|
import { SafePlugin } from '@atlaskit/editor-common/safe-plugin';
|
|
3
5
|
import { bracketTyped, browser, hasDocAsParent, isEmptyDocument, isEmptyParagraph } from '@atlaskit/editor-common/utils';
|
|
6
|
+
import { DOMSerializer } from '@atlaskit/editor-prosemirror/model';
|
|
4
7
|
import { PluginKey } from '@atlaskit/editor-prosemirror/state';
|
|
5
8
|
import { findParentNode } from '@atlaskit/editor-prosemirror/utils';
|
|
6
9
|
import { Decoration, DecorationSet } from '@atlaskit/editor-prosemirror/view';
|
|
@@ -24,6 +27,26 @@ function getPlaceholderState(editorState) {
|
|
|
24
27
|
const nodeTypesWithLongPlaceholderText = ['expand', 'panel'];
|
|
25
28
|
const nodeTypesWithShortPlaceholderText = ['tableCell', 'tableHeader'];
|
|
26
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
|
+
});
|
|
27
50
|
const cycleThroughPlaceholderPrompts = (placeholderPrompts, activeTypewriterTimeouts, placeholderNodeWithText, initialDelayWhenUserTypedAndDeleted = 0) => {
|
|
28
51
|
let currentPromptIndex = 0;
|
|
29
52
|
let displayedText = '';
|
|
@@ -72,11 +95,12 @@ const cycleThroughPlaceholderPrompts = (placeholderPrompts, activeTypewriterTime
|
|
|
72
95
|
startAnimationCycle();
|
|
73
96
|
}
|
|
74
97
|
};
|
|
75
|
-
export function createPlaceholderDecoration(editorState, placeholderText, placeholderPrompts, activeTypewriterTimeouts, pos = 1, initialDelayWhenUserTypedAndDeleted = 0) {
|
|
98
|
+
export function createPlaceholderDecoration(editorState, placeholderText, placeholderPrompts, activeTypewriterTimeouts, pos = 1, initialDelayWhenUserTypedAndDeleted = 0, placeholderADF) {
|
|
76
99
|
const placeholderDecoration = document.createElement('span');
|
|
77
100
|
let placeholderNodeWithText = placeholderDecoration;
|
|
78
101
|
placeholderDecoration.setAttribute('data-testid', placeholderTestId);
|
|
79
102
|
placeholderDecoration.className = 'placeholder-decoration';
|
|
103
|
+
placeholderDecoration.setAttribute('aria-hidden', 'true');
|
|
80
104
|
|
|
81
105
|
// PM sets contenteditable to false on Decorations so Firefox doesn't display the flashing cursor
|
|
82
106
|
// So adding an extra span which will contain the placeholder text
|
|
@@ -88,6 +112,42 @@ export function createPlaceholderDecoration(editorState, placeholderText, placeh
|
|
|
88
112
|
}
|
|
89
113
|
if (placeholderText) {
|
|
90
114
|
placeholderNodeWithText.textContent = placeholderText || ' ';
|
|
115
|
+
} else if (placeholderADF) {
|
|
116
|
+
const serializer = DOMSerializer.fromSchema(editorState.schema);
|
|
117
|
+
// Get a PMNode from docnode
|
|
118
|
+
const docNode = processRawValue(editorState.schema, placeholderADF);
|
|
119
|
+
if (docNode) {
|
|
120
|
+
// Extract only the inline content from paragraphs, avoiding block-level elements
|
|
121
|
+
// that can interfere with cursor rendering
|
|
122
|
+
docNode.children.forEach(node => {
|
|
123
|
+
// For paragraph nodes, serialize their content (inline elements) directly
|
|
124
|
+
// without the wrapping <p> tag
|
|
125
|
+
if (node.type.name === 'paragraph') {
|
|
126
|
+
node.content.forEach(inlineNode => {
|
|
127
|
+
const inlineDOM = serializer.serializeNode(inlineNode);
|
|
128
|
+
placeholderNodeWithText.append(inlineDOM);
|
|
129
|
+
});
|
|
130
|
+
} else {
|
|
131
|
+
// For non-paragraph nodes, serialize normally
|
|
132
|
+
const nodeDOM = serializer.serializeNode(node);
|
|
133
|
+
placeholderNodeWithText.append(nodeDOM);
|
|
134
|
+
}
|
|
135
|
+
});
|
|
136
|
+
const markElements = placeholderNodeWithText.querySelectorAll('[data-prosemirror-content-type="mark"]');
|
|
137
|
+
markElements.forEach(markEl => {
|
|
138
|
+
if (markEl instanceof HTMLElement) {
|
|
139
|
+
markEl.style.setProperty('color', "var(--ds-text-subtlest, #6B6E76)");
|
|
140
|
+
}
|
|
141
|
+
});
|
|
142
|
+
// Ensure all child elements don't block pointer events or cursor
|
|
143
|
+
const allElements = placeholderNodeWithText.querySelectorAll('*');
|
|
144
|
+
allElements.forEach(el => {
|
|
145
|
+
if (el instanceof HTMLElement) {
|
|
146
|
+
el.style.pointerEvents = 'none';
|
|
147
|
+
el.style.userSelect = 'none';
|
|
148
|
+
}
|
|
149
|
+
});
|
|
150
|
+
}
|
|
91
151
|
} else if (placeholderPrompts) {
|
|
92
152
|
cycleThroughPlaceholderPrompts(placeholderPrompts, activeTypewriterTimeouts, placeholderNodeWithText, initialDelayWhenUserTypedAndDeleted);
|
|
93
153
|
}
|
|
@@ -121,12 +181,14 @@ function setPlaceHolderState({
|
|
|
121
181
|
typedAndDeleted,
|
|
122
182
|
userHadTyped,
|
|
123
183
|
canShowOnEmptyParagraph,
|
|
124
|
-
showOnEmptyParagraph
|
|
184
|
+
showOnEmptyParagraph,
|
|
185
|
+
contextPlaceholderADF
|
|
125
186
|
}) {
|
|
126
187
|
return {
|
|
127
188
|
hasPlaceholder: true,
|
|
128
189
|
placeholderText,
|
|
129
190
|
placeholderPrompts,
|
|
191
|
+
contextPlaceholderADF,
|
|
130
192
|
pos: pos ? pos : 1,
|
|
131
193
|
typedAndDeleted,
|
|
132
194
|
userHadTyped,
|
|
@@ -160,6 +222,7 @@ function createPlaceHolderStateFrom({
|
|
|
160
222
|
intl,
|
|
161
223
|
bracketPlaceholderText,
|
|
162
224
|
emptyLinePlaceholder,
|
|
225
|
+
placeholderADF,
|
|
163
226
|
placeholderPrompts,
|
|
164
227
|
typedAndDeleted,
|
|
165
228
|
userHadTyped,
|
|
@@ -184,7 +247,7 @@ function createPlaceHolderStateFrom({
|
|
|
184
247
|
userHadTyped
|
|
185
248
|
});
|
|
186
249
|
}
|
|
187
|
-
if ((defaultPlaceholderText || placeholderPrompts) && isEmptyDocument(editorState.doc)) {
|
|
250
|
+
if ((defaultPlaceholderText || placeholderPrompts || placeholderADF) && isEmptyDocument(editorState.doc)) {
|
|
188
251
|
return setPlaceHolderState({
|
|
189
252
|
placeholderText: defaultPlaceholderText,
|
|
190
253
|
pos: 1,
|
|
@@ -193,13 +256,13 @@ function createPlaceHolderStateFrom({
|
|
|
193
256
|
userHadTyped
|
|
194
257
|
});
|
|
195
258
|
}
|
|
196
|
-
if (fg('platform_editor_ai_aifc_patch_beta_2')) {
|
|
259
|
+
if (fg('platform_editor_ai_aifc_patch_beta_2') || fg('platform_editor_ai_aifc_patch_ga')) {
|
|
197
260
|
const {
|
|
198
261
|
from,
|
|
199
262
|
to,
|
|
200
263
|
$to
|
|
201
264
|
} = editorState.selection;
|
|
202
|
-
if (defaultPlaceholderText && withEmptyParagraph && isEditorFocused && !isInitial && !isEmptyDocument(editorState.doc) && from === to && isEmptyParagraph($to.parent) && hasDocAsParent($to)) {
|
|
265
|
+
if ((defaultPlaceholderText || placeholderADF) && withEmptyParagraph && isEditorFocused && !isInitial && !isEmptyDocument(editorState.doc) && from === to && isEmptyParagraph($to.parent) && hasDocAsParent($to)) {
|
|
203
266
|
return showOnEmptyParagraph ? setPlaceHolderState({
|
|
204
267
|
placeholderText: defaultPlaceholderText,
|
|
205
268
|
pos: to,
|
|
@@ -259,7 +322,8 @@ function createPlaceHolderStateFrom({
|
|
|
259
322
|
const isFirstCell = (table === null || table === void 0 ? void 0 : (_table$node$firstChil = table.node.firstChild) === null || _table$node$firstChil === void 0 ? void 0 : _table$node$firstChil.content.firstChild) === parentNode;
|
|
260
323
|
if (isFirstCell) {
|
|
261
324
|
return setPlaceHolderState({
|
|
262
|
-
placeholderText: intl.formatMessage(messages.shortEmptyNodePlaceholderText),
|
|
325
|
+
placeholderText: !fg('platform_editor_ai_aifc_patch_ga') ? intl.formatMessage(messages.shortEmptyNodePlaceholderText) : undefined,
|
|
326
|
+
contextPlaceholderADF: fg('platform_editor_ai_aifc_patch_ga') ? createShortEmptyNodePlaceholderADF(intl) : undefined,
|
|
263
327
|
pos: $from.pos,
|
|
264
328
|
placeholderPrompts,
|
|
265
329
|
typedAndDeleted,
|
|
@@ -269,7 +333,8 @@ function createPlaceHolderStateFrom({
|
|
|
269
333
|
}
|
|
270
334
|
if (nodeTypesWithLongPlaceholderText.includes(parentType) && isEmptyNode) {
|
|
271
335
|
return setPlaceHolderState({
|
|
272
|
-
placeholderText: intl.formatMessage(messages.longEmptyNodePlaceholderText),
|
|
336
|
+
placeholderText: !fg('platform_editor_ai_aifc_patch_ga') ? intl.formatMessage(messages.longEmptyNodePlaceholderText) : undefined,
|
|
337
|
+
contextPlaceholderADF: fg('platform_editor_ai_aifc_patch_ga') ? createLongEmptyNodePlaceholderADF(intl) : undefined,
|
|
273
338
|
pos: $from.pos,
|
|
274
339
|
placeholderPrompts,
|
|
275
340
|
typedAndDeleted,
|
|
@@ -332,8 +397,8 @@ function calculateUserInteractionState({
|
|
|
332
397
|
typedAndDeleted: isInTypedAndDeletedState
|
|
333
398
|
};
|
|
334
399
|
}
|
|
335
|
-
export function createPlugin(intl, defaultPlaceholderText, bracketPlaceholderText, emptyLinePlaceholder, placeholderPrompts, withEmptyParagraph, api) {
|
|
336
|
-
if (!defaultPlaceholderText && !placeholderPrompts && !bracketPlaceholderText) {
|
|
400
|
+
export function createPlugin(intl, defaultPlaceholderText, bracketPlaceholderText, emptyLinePlaceholder, placeholderPrompts, withEmptyParagraph, placeholderADF, api) {
|
|
401
|
+
if (!defaultPlaceholderText && !placeholderPrompts && !bracketPlaceholderText && !placeholderADF) {
|
|
337
402
|
return;
|
|
338
403
|
}
|
|
339
404
|
let isDestroyed = false;
|
|
@@ -355,6 +420,7 @@ export function createPlugin(intl, defaultPlaceholderText, bracketPlaceholderTex
|
|
|
355
420
|
defaultPlaceholderText,
|
|
356
421
|
bracketPlaceholderText,
|
|
357
422
|
emptyLinePlaceholder,
|
|
423
|
+
placeholderADF,
|
|
358
424
|
placeholderPrompts,
|
|
359
425
|
typedAndDeleted: false,
|
|
360
426
|
userHadTyped: false,
|
|
@@ -377,16 +443,20 @@ export function createPlugin(intl, defaultPlaceholderText, bracketPlaceholderTex
|
|
|
377
443
|
if ((meta === null || meta === void 0 ? void 0 : meta.isPlaceholderHidden) !== undefined && fg('platform_editor_ai_aifc_patch_beta')) {
|
|
378
444
|
isPlaceholderHidden = meta.isPlaceholderHidden;
|
|
379
445
|
}
|
|
380
|
-
if ((meta === null || meta === void 0 ? void 0 : meta.placeholderText) !== undefined && fg('platform_editor_ai_aifc_patch_beta_2')) {
|
|
381
|
-
defaultPlaceholderText
|
|
446
|
+
if ((meta === null || meta === void 0 ? void 0 : meta.placeholderText) !== undefined && (fg('platform_editor_ai_aifc_patch_beta_2') || fg('platform_editor_ai_aifc_patch_ga'))) {
|
|
447
|
+
// Only update defaultPlaceholderText from meta if we're not using ADF placeholder
|
|
448
|
+
if (!(fg('platform_editor_ai_aifc_patch_ga') && placeholderADF)) {
|
|
449
|
+
defaultPlaceholderText = meta.placeholderText;
|
|
450
|
+
}
|
|
382
451
|
}
|
|
383
452
|
const newPlaceholderState = createPlaceHolderStateFrom({
|
|
384
453
|
isEditorFocused,
|
|
385
454
|
editorState: newEditorState,
|
|
386
455
|
isTypeAheadOpen: api === null || api === void 0 ? void 0 : (_api$typeAhead2 = api.typeAhead) === null || _api$typeAhead2 === void 0 ? void 0 : _api$typeAhead2.actions.isOpen,
|
|
387
|
-
defaultPlaceholderText: fg('platform_editor_ai_aifc_patch_beta_2') ? defaultPlaceholderText : (_ref = (_meta$placeholderText = meta === null || meta === void 0 ? void 0 : meta.placeholderText) !== null && _meta$placeholderText !== void 0 ? _meta$placeholderText : placeholderState === null || placeholderState === void 0 ? void 0 : placeholderState.placeholderText) !== null && _ref !== void 0 ? _ref : defaultPlaceholderText,
|
|
456
|
+
defaultPlaceholderText: fg('platform_editor_ai_aifc_patch_beta_2') || fg('platform_editor_ai_aifc_patch_ga') ? defaultPlaceholderText : (_ref = (_meta$placeholderText = meta === null || meta === void 0 ? void 0 : meta.placeholderText) !== null && _meta$placeholderText !== void 0 ? _meta$placeholderText : placeholderState === null || placeholderState === void 0 ? void 0 : placeholderState.placeholderText) !== null && _ref !== void 0 ? _ref : defaultPlaceholderText,
|
|
388
457
|
bracketPlaceholderText,
|
|
389
458
|
emptyLinePlaceholder,
|
|
459
|
+
placeholderADF,
|
|
390
460
|
placeholderPrompts: (_ref2 = (_meta$placeholderProm = meta === null || meta === void 0 ? void 0 : meta.placeholderPrompts) !== null && _meta$placeholderProm !== void 0 ? _meta$placeholderProm : placeholderState === null || placeholderState === void 0 ? void 0 : placeholderState.placeholderPrompts) !== null && _ref2 !== void 0 ? _ref2 : placeholderPrompts,
|
|
391
461
|
typedAndDeleted,
|
|
392
462
|
userHadTyped,
|
|
@@ -410,7 +480,8 @@ export function createPlugin(intl, defaultPlaceholderText, bracketPlaceholderTex
|
|
|
410
480
|
hasPlaceholder,
|
|
411
481
|
placeholderText,
|
|
412
482
|
pos,
|
|
413
|
-
typedAndDeleted
|
|
483
|
+
typedAndDeleted,
|
|
484
|
+
contextPlaceholderADF
|
|
414
485
|
} = getPlaceholderState(editorState);
|
|
415
486
|
|
|
416
487
|
// Decorations is still called after plugin is destroyed
|
|
@@ -420,9 +491,11 @@ export function createPlugin(intl, defaultPlaceholderText, bracketPlaceholderTex
|
|
|
420
491
|
}
|
|
421
492
|
const compositionPluginState = api === null || api === void 0 ? void 0 : (_api$composition = api.composition) === null || _api$composition === void 0 ? void 0 : _api$composition.sharedState.currentState();
|
|
422
493
|
const isShowingDiff = Boolean(api === null || api === void 0 ? void 0 : (_api$showDiff = api.showDiff) === null || _api$showDiff === void 0 ? void 0 : (_api$showDiff$sharedS = _api$showDiff.sharedState.currentState()) === null || _api$showDiff$sharedS === void 0 ? void 0 : _api$showDiff$sharedS.isDisplayingChanges);
|
|
423
|
-
if (hasPlaceholder && ((placeholderText !== null && placeholderText !== void 0 ? placeholderText : '') || placeholderPrompts) && pos !== undefined && !(compositionPluginState !== null && compositionPluginState !== void 0 && compositionPluginState.isComposing) && !isShowingDiff) {
|
|
494
|
+
if (hasPlaceholder && ((placeholderText !== null && placeholderText !== void 0 ? placeholderText : '') || placeholderPrompts || placeholderADF || contextPlaceholderADF) && pos !== undefined && !(compositionPluginState !== null && compositionPluginState !== void 0 && compositionPluginState.isComposing) && !isShowingDiff) {
|
|
424
495
|
const initialDelayWhenUserTypedAndDeleted = typedAndDeleted ? TYPEWRITER_TYPED_AND_DELETED_DELAY : 0;
|
|
425
|
-
|
|
496
|
+
// contextPlaceholderADF takes precedence over the global placeholderADF
|
|
497
|
+
const placeholderAdfToUse = contextPlaceholderADF || placeholderADF;
|
|
498
|
+
return createPlaceholderDecoration(editorState, placeholderText !== null && placeholderText !== void 0 ? placeholderText : '', placeholderPrompts, activeTypewriterTimeouts, pos, initialDelayWhenUserTypedAndDeleted, placeholderAdfToUse);
|
|
426
499
|
}
|
|
427
500
|
return;
|
|
428
501
|
}
|
|
@@ -448,7 +521,7 @@ export function createPlugin(intl, defaultPlaceholderText, bracketPlaceholderTex
|
|
|
448
521
|
}
|
|
449
522
|
return {
|
|
450
523
|
update(editorView, prevState) {
|
|
451
|
-
if (fg('platform_editor_ai_aifc_patch_beta_2')) {
|
|
524
|
+
if (fg('platform_editor_ai_aifc_patch_beta_2') || fg('platform_editor_ai_aifc_patch_ga')) {
|
|
452
525
|
const prevPluginState = getPlaceholderState(prevState);
|
|
453
526
|
const newPluginState = getPlaceholderState(editorView.state);
|
|
454
527
|
|
|
@@ -518,7 +591,7 @@ export const placeholderPlugin = ({
|
|
|
518
591
|
name: 'placeholder',
|
|
519
592
|
plugin: ({
|
|
520
593
|
getIntl
|
|
521
|
-
}) => createPlugin(getIntl(), options && options.placeholder, options && options.placeholderBracketHint, options && options.emptyLinePlaceholder, options && options.placeholderPrompts, options === null || options === void 0 ? void 0 : options.withEmptyParagraph, api)
|
|
594
|
+
}) => 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)
|
|
522
595
|
}];
|
|
523
596
|
}
|
|
524
597
|
};
|
|
@@ -1,9 +1,12 @@
|
|
|
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';
|
|
6
|
+
import { processRawValue } from '@atlaskit/editor-common/process-raw-value';
|
|
5
7
|
import { SafePlugin } from '@atlaskit/editor-common/safe-plugin';
|
|
6
8
|
import { bracketTyped, browser, hasDocAsParent, isEmptyDocument, isEmptyParagraph } from '@atlaskit/editor-common/utils';
|
|
9
|
+
import { DOMSerializer } from '@atlaskit/editor-prosemirror/model';
|
|
7
10
|
import { PluginKey } from '@atlaskit/editor-prosemirror/state';
|
|
8
11
|
import { findParentNode } from '@atlaskit/editor-prosemirror/utils';
|
|
9
12
|
import { Decoration, DecorationSet } from '@atlaskit/editor-prosemirror/view';
|
|
@@ -27,6 +30,28 @@ function getPlaceholderState(editorState) {
|
|
|
27
30
|
var nodeTypesWithLongPlaceholderText = ['expand', 'panel'];
|
|
28
31
|
var nodeTypesWithShortPlaceholderText = ['tableCell', 'tableHeader'];
|
|
29
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
|
+
};
|
|
30
55
|
var cycleThroughPlaceholderPrompts = function cycleThroughPlaceholderPrompts(placeholderPrompts, activeTypewriterTimeouts, placeholderNodeWithText) {
|
|
31
56
|
var initialDelayWhenUserTypedAndDeleted = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : 0;
|
|
32
57
|
var currentPromptIndex = 0;
|
|
@@ -81,10 +106,12 @@ var cycleThroughPlaceholderPrompts = function cycleThroughPlaceholderPrompts(pla
|
|
|
81
106
|
export function createPlaceholderDecoration(editorState, placeholderText, placeholderPrompts, activeTypewriterTimeouts) {
|
|
82
107
|
var pos = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : 1;
|
|
83
108
|
var initialDelayWhenUserTypedAndDeleted = arguments.length > 5 && arguments[5] !== undefined ? arguments[5] : 0;
|
|
109
|
+
var placeholderADF = arguments.length > 6 ? arguments[6] : undefined;
|
|
84
110
|
var placeholderDecoration = document.createElement('span');
|
|
85
111
|
var placeholderNodeWithText = placeholderDecoration;
|
|
86
112
|
placeholderDecoration.setAttribute('data-testid', placeholderTestId);
|
|
87
113
|
placeholderDecoration.className = 'placeholder-decoration';
|
|
114
|
+
placeholderDecoration.setAttribute('aria-hidden', 'true');
|
|
88
115
|
|
|
89
116
|
// PM sets contenteditable to false on Decorations so Firefox doesn't display the flashing cursor
|
|
90
117
|
// So adding an extra span which will contain the placeholder text
|
|
@@ -96,6 +123,42 @@ export function createPlaceholderDecoration(editorState, placeholderText, placeh
|
|
|
96
123
|
}
|
|
97
124
|
if (placeholderText) {
|
|
98
125
|
placeholderNodeWithText.textContent = placeholderText || ' ';
|
|
126
|
+
} else if (placeholderADF) {
|
|
127
|
+
var serializer = DOMSerializer.fromSchema(editorState.schema);
|
|
128
|
+
// Get a PMNode from docnode
|
|
129
|
+
var docNode = processRawValue(editorState.schema, placeholderADF);
|
|
130
|
+
if (docNode) {
|
|
131
|
+
// Extract only the inline content from paragraphs, avoiding block-level elements
|
|
132
|
+
// that can interfere with cursor rendering
|
|
133
|
+
docNode.children.forEach(function (node) {
|
|
134
|
+
// For paragraph nodes, serialize their content (inline elements) directly
|
|
135
|
+
// without the wrapping <p> tag
|
|
136
|
+
if (node.type.name === 'paragraph') {
|
|
137
|
+
node.content.forEach(function (inlineNode) {
|
|
138
|
+
var inlineDOM = serializer.serializeNode(inlineNode);
|
|
139
|
+
placeholderNodeWithText.append(inlineDOM);
|
|
140
|
+
});
|
|
141
|
+
} else {
|
|
142
|
+
// For non-paragraph nodes, serialize normally
|
|
143
|
+
var nodeDOM = serializer.serializeNode(node);
|
|
144
|
+
placeholderNodeWithText.append(nodeDOM);
|
|
145
|
+
}
|
|
146
|
+
});
|
|
147
|
+
var markElements = placeholderNodeWithText.querySelectorAll('[data-prosemirror-content-type="mark"]');
|
|
148
|
+
markElements.forEach(function (markEl) {
|
|
149
|
+
if (markEl instanceof HTMLElement) {
|
|
150
|
+
markEl.style.setProperty('color', "var(--ds-text-subtlest, #6B6E76)");
|
|
151
|
+
}
|
|
152
|
+
});
|
|
153
|
+
// Ensure all child elements don't block pointer events or cursor
|
|
154
|
+
var allElements = placeholderNodeWithText.querySelectorAll('*');
|
|
155
|
+
allElements.forEach(function (el) {
|
|
156
|
+
if (el instanceof HTMLElement) {
|
|
157
|
+
el.style.pointerEvents = 'none';
|
|
158
|
+
el.style.userSelect = 'none';
|
|
159
|
+
}
|
|
160
|
+
});
|
|
161
|
+
}
|
|
99
162
|
} else if (placeholderPrompts) {
|
|
100
163
|
cycleThroughPlaceholderPrompts(placeholderPrompts, activeTypewriterTimeouts, placeholderNodeWithText, initialDelayWhenUserTypedAndDeleted);
|
|
101
164
|
}
|
|
@@ -122,18 +185,20 @@ export function createPlaceholderDecoration(editorState, placeholderText, placeh
|
|
|
122
185
|
key: "placeholder ".concat(placeholderText)
|
|
123
186
|
})]);
|
|
124
187
|
}
|
|
125
|
-
function setPlaceHolderState(
|
|
126
|
-
var placeholderText =
|
|
127
|
-
pos =
|
|
128
|
-
placeholderPrompts =
|
|
129
|
-
typedAndDeleted =
|
|
130
|
-
userHadTyped =
|
|
131
|
-
canShowOnEmptyParagraph =
|
|
132
|
-
showOnEmptyParagraph =
|
|
188
|
+
function setPlaceHolderState(_ref3) {
|
|
189
|
+
var placeholderText = _ref3.placeholderText,
|
|
190
|
+
pos = _ref3.pos,
|
|
191
|
+
placeholderPrompts = _ref3.placeholderPrompts,
|
|
192
|
+
typedAndDeleted = _ref3.typedAndDeleted,
|
|
193
|
+
userHadTyped = _ref3.userHadTyped,
|
|
194
|
+
canShowOnEmptyParagraph = _ref3.canShowOnEmptyParagraph,
|
|
195
|
+
showOnEmptyParagraph = _ref3.showOnEmptyParagraph,
|
|
196
|
+
contextPlaceholderADF = _ref3.contextPlaceholderADF;
|
|
133
197
|
return {
|
|
134
198
|
hasPlaceholder: true,
|
|
135
199
|
placeholderText: placeholderText,
|
|
136
200
|
placeholderPrompts: placeholderPrompts,
|
|
201
|
+
contextPlaceholderADF: contextPlaceholderADF,
|
|
137
202
|
pos: pos ? pos : 1,
|
|
138
203
|
typedAndDeleted: typedAndDeleted,
|
|
139
204
|
userHadTyped: userHadTyped,
|
|
@@ -141,13 +206,13 @@ function setPlaceHolderState(_ref) {
|
|
|
141
206
|
showOnEmptyParagraph: showOnEmptyParagraph
|
|
142
207
|
};
|
|
143
208
|
}
|
|
144
|
-
var emptyPlaceholder = function emptyPlaceholder(
|
|
145
|
-
var placeholderText =
|
|
146
|
-
placeholderPrompts =
|
|
147
|
-
userHadTyped =
|
|
148
|
-
pos =
|
|
149
|
-
canShowOnEmptyParagraph =
|
|
150
|
-
showOnEmptyParagraph =
|
|
209
|
+
var emptyPlaceholder = function emptyPlaceholder(_ref4) {
|
|
210
|
+
var placeholderText = _ref4.placeholderText,
|
|
211
|
+
placeholderPrompts = _ref4.placeholderPrompts,
|
|
212
|
+
userHadTyped = _ref4.userHadTyped,
|
|
213
|
+
pos = _ref4.pos,
|
|
214
|
+
canShowOnEmptyParagraph = _ref4.canShowOnEmptyParagraph,
|
|
215
|
+
showOnEmptyParagraph = _ref4.showOnEmptyParagraph;
|
|
151
216
|
return {
|
|
152
217
|
hasPlaceholder: false,
|
|
153
218
|
placeholderText: placeholderText,
|
|
@@ -159,21 +224,22 @@ var emptyPlaceholder = function emptyPlaceholder(_ref2) {
|
|
|
159
224
|
pos: pos
|
|
160
225
|
};
|
|
161
226
|
};
|
|
162
|
-
function createPlaceHolderStateFrom(
|
|
163
|
-
var isInitial =
|
|
164
|
-
isEditorFocused =
|
|
165
|
-
editorState =
|
|
166
|
-
isTypeAheadOpen =
|
|
167
|
-
defaultPlaceholderText =
|
|
168
|
-
intl =
|
|
169
|
-
bracketPlaceholderText =
|
|
170
|
-
emptyLinePlaceholder =
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
227
|
+
function createPlaceHolderStateFrom(_ref5) {
|
|
228
|
+
var isInitial = _ref5.isInitial,
|
|
229
|
+
isEditorFocused = _ref5.isEditorFocused,
|
|
230
|
+
editorState = _ref5.editorState,
|
|
231
|
+
isTypeAheadOpen = _ref5.isTypeAheadOpen,
|
|
232
|
+
defaultPlaceholderText = _ref5.defaultPlaceholderText,
|
|
233
|
+
intl = _ref5.intl,
|
|
234
|
+
bracketPlaceholderText = _ref5.bracketPlaceholderText,
|
|
235
|
+
emptyLinePlaceholder = _ref5.emptyLinePlaceholder,
|
|
236
|
+
placeholderADF = _ref5.placeholderADF,
|
|
237
|
+
placeholderPrompts = _ref5.placeholderPrompts,
|
|
238
|
+
typedAndDeleted = _ref5.typedAndDeleted,
|
|
239
|
+
userHadTyped = _ref5.userHadTyped,
|
|
240
|
+
isPlaceholderHidden = _ref5.isPlaceholderHidden,
|
|
241
|
+
withEmptyParagraph = _ref5.withEmptyParagraph,
|
|
242
|
+
showOnEmptyParagraph = _ref5.showOnEmptyParagraph;
|
|
177
243
|
if (isPlaceholderHidden && fg('platform_editor_ai_aifc_patch_beta')) {
|
|
178
244
|
return _objectSpread(_objectSpread({}, emptyPlaceholder({
|
|
179
245
|
placeholderText: defaultPlaceholderText,
|
|
@@ -190,7 +256,7 @@ function createPlaceHolderStateFrom(_ref3) {
|
|
|
190
256
|
userHadTyped: userHadTyped
|
|
191
257
|
});
|
|
192
258
|
}
|
|
193
|
-
if ((defaultPlaceholderText || placeholderPrompts) && isEmptyDocument(editorState.doc)) {
|
|
259
|
+
if ((defaultPlaceholderText || placeholderPrompts || placeholderADF) && isEmptyDocument(editorState.doc)) {
|
|
194
260
|
return setPlaceHolderState({
|
|
195
261
|
placeholderText: defaultPlaceholderText,
|
|
196
262
|
pos: 1,
|
|
@@ -199,12 +265,12 @@ function createPlaceHolderStateFrom(_ref3) {
|
|
|
199
265
|
userHadTyped: userHadTyped
|
|
200
266
|
});
|
|
201
267
|
}
|
|
202
|
-
if (fg('platform_editor_ai_aifc_patch_beta_2')) {
|
|
268
|
+
if (fg('platform_editor_ai_aifc_patch_beta_2') || fg('platform_editor_ai_aifc_patch_ga')) {
|
|
203
269
|
var _editorState$selectio = editorState.selection,
|
|
204
270
|
from = _editorState$selectio.from,
|
|
205
271
|
to = _editorState$selectio.to,
|
|
206
272
|
$to = _editorState$selectio.$to;
|
|
207
|
-
if (defaultPlaceholderText && withEmptyParagraph && isEditorFocused && !isInitial && !isEmptyDocument(editorState.doc) && from === to && isEmptyParagraph($to.parent) && hasDocAsParent($to)) {
|
|
273
|
+
if ((defaultPlaceholderText || placeholderADF) && withEmptyParagraph && isEditorFocused && !isInitial && !isEmptyDocument(editorState.doc) && from === to && isEmptyParagraph($to.parent) && hasDocAsParent($to)) {
|
|
208
274
|
return showOnEmptyParagraph ? setPlaceHolderState({
|
|
209
275
|
placeholderText: defaultPlaceholderText,
|
|
210
276
|
pos: to,
|
|
@@ -265,7 +331,8 @@ function createPlaceHolderStateFrom(_ref3) {
|
|
|
265
331
|
var isFirstCell = (table === null || table === void 0 || (_table$node$firstChil = table.node.firstChild) === null || _table$node$firstChil === void 0 ? void 0 : _table$node$firstChil.content.firstChild) === parentNode;
|
|
266
332
|
if (isFirstCell) {
|
|
267
333
|
return setPlaceHolderState({
|
|
268
|
-
placeholderText: intl.formatMessage(messages.shortEmptyNodePlaceholderText),
|
|
334
|
+
placeholderText: !fg('platform_editor_ai_aifc_patch_ga') ? intl.formatMessage(messages.shortEmptyNodePlaceholderText) : undefined,
|
|
335
|
+
contextPlaceholderADF: fg('platform_editor_ai_aifc_patch_ga') ? createShortEmptyNodePlaceholderADF(intl) : undefined,
|
|
269
336
|
pos: $from.pos,
|
|
270
337
|
placeholderPrompts: placeholderPrompts,
|
|
271
338
|
typedAndDeleted: typedAndDeleted,
|
|
@@ -275,7 +342,8 @@ function createPlaceHolderStateFrom(_ref3) {
|
|
|
275
342
|
}
|
|
276
343
|
if (nodeTypesWithLongPlaceholderText.includes(parentType) && isEmptyNode) {
|
|
277
344
|
return setPlaceHolderState({
|
|
278
|
-
placeholderText: intl.formatMessage(messages.longEmptyNodePlaceholderText),
|
|
345
|
+
placeholderText: !fg('platform_editor_ai_aifc_patch_ga') ? intl.formatMessage(messages.longEmptyNodePlaceholderText) : undefined,
|
|
346
|
+
contextPlaceholderADF: fg('platform_editor_ai_aifc_patch_ga') ? createLongEmptyNodePlaceholderADF(intl) : undefined,
|
|
279
347
|
pos: $from.pos,
|
|
280
348
|
placeholderPrompts: placeholderPrompts,
|
|
281
349
|
typedAndDeleted: typedAndDeleted,
|
|
@@ -315,10 +383,10 @@ function createPlaceHolderStateFrom(_ref3) {
|
|
|
315
383
|
userHadTyped: userHadTyped
|
|
316
384
|
});
|
|
317
385
|
}
|
|
318
|
-
function calculateUserInteractionState(
|
|
319
|
-
var placeholderState =
|
|
320
|
-
oldEditorState =
|
|
321
|
-
newEditorState =
|
|
386
|
+
function calculateUserInteractionState(_ref6) {
|
|
387
|
+
var placeholderState = _ref6.placeholderState,
|
|
388
|
+
oldEditorState = _ref6.oldEditorState,
|
|
389
|
+
newEditorState = _ref6.newEditorState;
|
|
322
390
|
var wasEmpty = oldEditorState ? isEmptyDocument(oldEditorState.doc) : true;
|
|
323
391
|
var isEmpty = isEmptyDocument(newEditorState.doc);
|
|
324
392
|
var hasEverTyped = Boolean(placeholderState === null || placeholderState === void 0 ? void 0 : placeholderState.userHadTyped) ||
|
|
@@ -335,8 +403,8 @@ function calculateUserInteractionState(_ref4) {
|
|
|
335
403
|
typedAndDeleted: isInTypedAndDeletedState
|
|
336
404
|
};
|
|
337
405
|
}
|
|
338
|
-
export function createPlugin(intl, defaultPlaceholderText, bracketPlaceholderText, emptyLinePlaceholder, placeholderPrompts, withEmptyParagraph, api) {
|
|
339
|
-
if (!defaultPlaceholderText && !placeholderPrompts && !bracketPlaceholderText) {
|
|
406
|
+
export function createPlugin(intl, defaultPlaceholderText, bracketPlaceholderText, emptyLinePlaceholder, placeholderPrompts, withEmptyParagraph, placeholderADF, api) {
|
|
407
|
+
if (!defaultPlaceholderText && !placeholderPrompts && !bracketPlaceholderText && !placeholderADF) {
|
|
340
408
|
return;
|
|
341
409
|
}
|
|
342
410
|
var isDestroyed = false;
|
|
@@ -360,6 +428,7 @@ export function createPlugin(intl, defaultPlaceholderText, bracketPlaceholderTex
|
|
|
360
428
|
defaultPlaceholderText: defaultPlaceholderText,
|
|
361
429
|
bracketPlaceholderText: bracketPlaceholderText,
|
|
362
430
|
emptyLinePlaceholder: emptyLinePlaceholder,
|
|
431
|
+
placeholderADF: placeholderADF,
|
|
363
432
|
placeholderPrompts: placeholderPrompts,
|
|
364
433
|
typedAndDeleted: false,
|
|
365
434
|
userHadTyped: false,
|
|
@@ -367,7 +436,7 @@ export function createPlugin(intl, defaultPlaceholderText, bracketPlaceholderTex
|
|
|
367
436
|
});
|
|
368
437
|
},
|
|
369
438
|
apply: function apply(tr, placeholderState, _oldEditorState, newEditorState) {
|
|
370
|
-
var _api$focus2, _placeholderState$isP, _api$typeAhead2,
|
|
439
|
+
var _api$focus2, _placeholderState$isP, _api$typeAhead2, _ref7, _meta$placeholderText, _ref8, _meta$placeholderProm, _meta$showOnEmptyPara;
|
|
371
440
|
var meta = tr.getMeta(pluginKey);
|
|
372
441
|
var isEditorFocused = Boolean(api === null || api === void 0 || (_api$focus2 = api.focus) === null || _api$focus2 === void 0 || (_api$focus2 = _api$focus2.sharedState.currentState()) === null || _api$focus2 === void 0 ? void 0 : _api$focus2.hasFocus);
|
|
373
442
|
var _calculateUserInterac = calculateUserInteractionState({
|
|
@@ -381,17 +450,21 @@ export function createPlugin(intl, defaultPlaceholderText, bracketPlaceholderTex
|
|
|
381
450
|
if ((meta === null || meta === void 0 ? void 0 : meta.isPlaceholderHidden) !== undefined && fg('platform_editor_ai_aifc_patch_beta')) {
|
|
382
451
|
isPlaceholderHidden = meta.isPlaceholderHidden;
|
|
383
452
|
}
|
|
384
|
-
if ((meta === null || meta === void 0 ? void 0 : meta.placeholderText) !== undefined && fg('platform_editor_ai_aifc_patch_beta_2')) {
|
|
385
|
-
defaultPlaceholderText
|
|
453
|
+
if ((meta === null || meta === void 0 ? void 0 : meta.placeholderText) !== undefined && (fg('platform_editor_ai_aifc_patch_beta_2') || fg('platform_editor_ai_aifc_patch_ga'))) {
|
|
454
|
+
// Only update defaultPlaceholderText from meta if we're not using ADF placeholder
|
|
455
|
+
if (!(fg('platform_editor_ai_aifc_patch_ga') && placeholderADF)) {
|
|
456
|
+
defaultPlaceholderText = meta.placeholderText;
|
|
457
|
+
}
|
|
386
458
|
}
|
|
387
459
|
var newPlaceholderState = createPlaceHolderStateFrom({
|
|
388
460
|
isEditorFocused: isEditorFocused,
|
|
389
461
|
editorState: newEditorState,
|
|
390
462
|
isTypeAheadOpen: api === null || api === void 0 || (_api$typeAhead2 = api.typeAhead) === null || _api$typeAhead2 === void 0 ? void 0 : _api$typeAhead2.actions.isOpen,
|
|
391
|
-
defaultPlaceholderText: fg('platform_editor_ai_aifc_patch_beta_2') ? defaultPlaceholderText : (
|
|
463
|
+
defaultPlaceholderText: fg('platform_editor_ai_aifc_patch_beta_2') || fg('platform_editor_ai_aifc_patch_ga') ? defaultPlaceholderText : (_ref7 = (_meta$placeholderText = meta === null || meta === void 0 ? void 0 : meta.placeholderText) !== null && _meta$placeholderText !== void 0 ? _meta$placeholderText : placeholderState === null || placeholderState === void 0 ? void 0 : placeholderState.placeholderText) !== null && _ref7 !== void 0 ? _ref7 : defaultPlaceholderText,
|
|
392
464
|
bracketPlaceholderText: bracketPlaceholderText,
|
|
393
465
|
emptyLinePlaceholder: emptyLinePlaceholder,
|
|
394
|
-
|
|
466
|
+
placeholderADF: placeholderADF,
|
|
467
|
+
placeholderPrompts: (_ref8 = (_meta$placeholderProm = meta === null || meta === void 0 ? void 0 : meta.placeholderPrompts) !== null && _meta$placeholderProm !== void 0 ? _meta$placeholderProm : placeholderState === null || placeholderState === void 0 ? void 0 : placeholderState.placeholderPrompts) !== null && _ref8 !== void 0 ? _ref8 : placeholderPrompts,
|
|
395
468
|
typedAndDeleted: typedAndDeleted,
|
|
396
469
|
userHadTyped: userHadTyped,
|
|
397
470
|
intl: intl,
|
|
@@ -414,7 +487,8 @@ export function createPlugin(intl, defaultPlaceholderText, bracketPlaceholderTex
|
|
|
414
487
|
hasPlaceholder = _getPlaceholderState.hasPlaceholder,
|
|
415
488
|
placeholderText = _getPlaceholderState.placeholderText,
|
|
416
489
|
pos = _getPlaceholderState.pos,
|
|
417
|
-
typedAndDeleted = _getPlaceholderState.typedAndDeleted
|
|
490
|
+
typedAndDeleted = _getPlaceholderState.typedAndDeleted,
|
|
491
|
+
contextPlaceholderADF = _getPlaceholderState.contextPlaceholderADF;
|
|
418
492
|
|
|
419
493
|
// Decorations is still called after plugin is destroyed
|
|
420
494
|
// So we need to make sure decorations is not called if plugin has been destroyed to prevent the placeholder animations' setTimeouts called infinitely
|
|
@@ -423,9 +497,11 @@ export function createPlugin(intl, defaultPlaceholderText, bracketPlaceholderTex
|
|
|
423
497
|
}
|
|
424
498
|
var compositionPluginState = api === null || api === void 0 || (_api$composition = api.composition) === null || _api$composition === void 0 ? void 0 : _api$composition.sharedState.currentState();
|
|
425
499
|
var isShowingDiff = Boolean(api === null || api === void 0 || (_api$showDiff = api.showDiff) === null || _api$showDiff === void 0 || (_api$showDiff = _api$showDiff.sharedState.currentState()) === null || _api$showDiff === void 0 ? void 0 : _api$showDiff.isDisplayingChanges);
|
|
426
|
-
if (hasPlaceholder && ((placeholderText !== null && placeholderText !== void 0 ? placeholderText : '') || placeholderPrompts) && pos !== undefined && !(compositionPluginState !== null && compositionPluginState !== void 0 && compositionPluginState.isComposing) && !isShowingDiff) {
|
|
500
|
+
if (hasPlaceholder && ((placeholderText !== null && placeholderText !== void 0 ? placeholderText : '') || placeholderPrompts || placeholderADF || contextPlaceholderADF) && pos !== undefined && !(compositionPluginState !== null && compositionPluginState !== void 0 && compositionPluginState.isComposing) && !isShowingDiff) {
|
|
427
501
|
var initialDelayWhenUserTypedAndDeleted = typedAndDeleted ? TYPEWRITER_TYPED_AND_DELETED_DELAY : 0;
|
|
428
|
-
|
|
502
|
+
// contextPlaceholderADF takes precedence over the global placeholderADF
|
|
503
|
+
var placeholderAdfToUse = contextPlaceholderADF || placeholderADF;
|
|
504
|
+
return createPlaceholderDecoration(editorState, placeholderText !== null && placeholderText !== void 0 ? placeholderText : '', placeholderPrompts, activeTypewriterTimeouts, pos, initialDelayWhenUserTypedAndDeleted, placeholderAdfToUse);
|
|
429
505
|
}
|
|
430
506
|
return;
|
|
431
507
|
}
|
|
@@ -451,7 +527,7 @@ export function createPlugin(intl, defaultPlaceholderText, bracketPlaceholderTex
|
|
|
451
527
|
}
|
|
452
528
|
return {
|
|
453
529
|
update: function update(editorView, prevState) {
|
|
454
|
-
if (fg('platform_editor_ai_aifc_patch_beta_2')) {
|
|
530
|
+
if (fg('platform_editor_ai_aifc_patch_beta_2') || fg('platform_editor_ai_aifc_patch_ga')) {
|
|
455
531
|
var prevPluginState = getPlaceholderState(prevState);
|
|
456
532
|
var newPluginState = getPlaceholderState(editorView.state);
|
|
457
533
|
|
|
@@ -482,16 +558,16 @@ export function createPlugin(intl, defaultPlaceholderText, bracketPlaceholderTex
|
|
|
482
558
|
}
|
|
483
559
|
});
|
|
484
560
|
}
|
|
485
|
-
export var placeholderPlugin = function placeholderPlugin(
|
|
486
|
-
var options =
|
|
487
|
-
api =
|
|
561
|
+
export var placeholderPlugin = function placeholderPlugin(_ref9) {
|
|
562
|
+
var options = _ref9.config,
|
|
563
|
+
api = _ref9.api;
|
|
488
564
|
var currentPlaceholder = options === null || options === void 0 ? void 0 : options.placeholder;
|
|
489
565
|
return {
|
|
490
566
|
name: 'placeholder',
|
|
491
567
|
commands: {
|
|
492
568
|
setPlaceholder: function setPlaceholder(placeholderText) {
|
|
493
|
-
return function (
|
|
494
|
-
var tr =
|
|
569
|
+
return function (_ref0) {
|
|
570
|
+
var tr = _ref0.tr;
|
|
495
571
|
if (currentPlaceholder !== placeholderText) {
|
|
496
572
|
currentPlaceholder = placeholderText;
|
|
497
573
|
return tr.setMeta(pluginKey, {
|
|
@@ -502,16 +578,16 @@ export var placeholderPlugin = function placeholderPlugin(_ref7) {
|
|
|
502
578
|
};
|
|
503
579
|
},
|
|
504
580
|
setAnimatingPlaceholderPrompts: function setAnimatingPlaceholderPrompts(placeholderPrompts) {
|
|
505
|
-
return function (
|
|
506
|
-
var tr =
|
|
581
|
+
return function (_ref1) {
|
|
582
|
+
var tr = _ref1.tr;
|
|
507
583
|
return tr.setMeta(pluginKey, {
|
|
508
584
|
placeholderPrompts: placeholderPrompts
|
|
509
585
|
});
|
|
510
586
|
};
|
|
511
587
|
},
|
|
512
588
|
setPlaceholderHidden: function setPlaceholderHidden(isPlaceholderHidden) {
|
|
513
|
-
return function (
|
|
514
|
-
var tr =
|
|
589
|
+
return function (_ref10) {
|
|
590
|
+
var tr = _ref10.tr;
|
|
515
591
|
return tr.setMeta(pluginKey, {
|
|
516
592
|
isPlaceholderHidden: isPlaceholderHidden
|
|
517
593
|
});
|
|
@@ -521,9 +597,9 @@ export var placeholderPlugin = function placeholderPlugin(_ref7) {
|
|
|
521
597
|
pmPlugins: function pmPlugins() {
|
|
522
598
|
return [{
|
|
523
599
|
name: 'placeholder',
|
|
524
|
-
plugin: function plugin(
|
|
525
|
-
var getIntl =
|
|
526
|
-
return createPlugin(getIntl(), options && options.placeholder, options && options.placeholderBracketHint, options && options.emptyLinePlaceholder, options && options.placeholderPrompts, options === null || options === void 0 ? void 0 : options.withEmptyParagraph, api);
|
|
600
|
+
plugin: function plugin(_ref11) {
|
|
601
|
+
var getIntl = _ref11.getIntl;
|
|
602
|
+
return createPlugin(getIntl(), options && options.placeholder, options && options.placeholderBracketHint, options && options.emptyLinePlaceholder, options && options.placeholderPrompts, options === null || options === void 0 ? void 0 : options.withEmptyParagraph, options && options.placeholderADF, api);
|
|
527
603
|
}
|
|
528
604
|
}];
|
|
529
605
|
}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { IntlShape } from 'react-intl-next';
|
|
2
|
+
import type { DocNode } from '@atlaskit/adf-schema';
|
|
2
3
|
import { SafePlugin } from '@atlaskit/editor-common/safe-plugin';
|
|
3
4
|
import type { ExtractInjectionAPI } from '@atlaskit/editor-common/types';
|
|
4
5
|
import type { EditorState } from '@atlaskit/editor-prosemirror/state';
|
|
@@ -7,6 +8,6 @@ import { DecorationSet } from '@atlaskit/editor-prosemirror/view';
|
|
|
7
8
|
import type { PlaceholderPlugin } from './placeholderPluginType';
|
|
8
9
|
export declare const EMPTY_PARAGRAPH_TIMEOUT_DELAY = 2000;
|
|
9
10
|
export declare const pluginKey: PluginKey<any>;
|
|
10
|
-
export declare function createPlaceholderDecoration(editorState: EditorState, placeholderText: string, placeholderPrompts?: string[], activeTypewriterTimeouts?: (() => void)[], pos?: number, initialDelayWhenUserTypedAndDeleted?: number): DecorationSet;
|
|
11
|
-
export declare function createPlugin(intl: IntlShape, defaultPlaceholderText?: string, bracketPlaceholderText?: string, emptyLinePlaceholder?: string, placeholderPrompts?: string[], withEmptyParagraph?: boolean, api?: ExtractInjectionAPI<PlaceholderPlugin>): SafePlugin | undefined;
|
|
11
|
+
export declare function createPlaceholderDecoration(editorState: EditorState, placeholderText: string, placeholderPrompts?: string[], activeTypewriterTimeouts?: (() => void)[], pos?: number, initialDelayWhenUserTypedAndDeleted?: number, placeholderADF?: DocNode): DecorationSet;
|
|
12
|
+
export declare function createPlugin(intl: IntlShape, defaultPlaceholderText?: string, bracketPlaceholderText?: string, emptyLinePlaceholder?: string, placeholderPrompts?: string[], withEmptyParagraph?: boolean, placeholderADF?: DocNode, api?: ExtractInjectionAPI<PlaceholderPlugin>): SafePlugin | undefined;
|
|
12
13
|
export declare const placeholderPlugin: PlaceholderPlugin;
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { DocNode } from '@atlaskit/adf-schema';
|
|
1
2
|
import type { EditorCommand, NextEditorPlugin, OptionalPlugin } from '@atlaskit/editor-common/types';
|
|
2
3
|
import type { CompositionPlugin } from '@atlaskit/editor-plugin-composition';
|
|
3
4
|
import type { FocusPlugin } from '@atlaskit/editor-plugin-focus';
|
|
@@ -6,6 +7,7 @@ import type { TypeAheadPlugin } from '@atlaskit/editor-plugin-type-ahead';
|
|
|
6
7
|
export interface PlaceholderPluginOptions {
|
|
7
8
|
emptyLinePlaceholder?: string;
|
|
8
9
|
placeholder?: string;
|
|
10
|
+
placeholderADF?: DocNode;
|
|
9
11
|
placeholderBracketHint?: string;
|
|
10
12
|
placeholderPrompts?: string[];
|
|
11
13
|
withEmptyParagraph?: boolean;
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { IntlShape } from 'react-intl-next';
|
|
2
|
+
import type { DocNode } from '@atlaskit/adf-schema';
|
|
2
3
|
import { SafePlugin } from '@atlaskit/editor-common/safe-plugin';
|
|
3
4
|
import type { ExtractInjectionAPI } from '@atlaskit/editor-common/types';
|
|
4
5
|
import type { EditorState } from '@atlaskit/editor-prosemirror/state';
|
|
@@ -7,6 +8,6 @@ import { DecorationSet } from '@atlaskit/editor-prosemirror/view';
|
|
|
7
8
|
import type { PlaceholderPlugin } from './placeholderPluginType';
|
|
8
9
|
export declare const EMPTY_PARAGRAPH_TIMEOUT_DELAY = 2000;
|
|
9
10
|
export declare const pluginKey: PluginKey<any>;
|
|
10
|
-
export declare function createPlaceholderDecoration(editorState: EditorState, placeholderText: string, placeholderPrompts?: string[], activeTypewriterTimeouts?: (() => void)[], pos?: number, initialDelayWhenUserTypedAndDeleted?: number): DecorationSet;
|
|
11
|
-
export declare function createPlugin(intl: IntlShape, defaultPlaceholderText?: string, bracketPlaceholderText?: string, emptyLinePlaceholder?: string, placeholderPrompts?: string[], withEmptyParagraph?: boolean, api?: ExtractInjectionAPI<PlaceholderPlugin>): SafePlugin | undefined;
|
|
11
|
+
export declare function createPlaceholderDecoration(editorState: EditorState, placeholderText: string, placeholderPrompts?: string[], activeTypewriterTimeouts?: (() => void)[], pos?: number, initialDelayWhenUserTypedAndDeleted?: number, placeholderADF?: DocNode): DecorationSet;
|
|
12
|
+
export declare function createPlugin(intl: IntlShape, defaultPlaceholderText?: string, bracketPlaceholderText?: string, emptyLinePlaceholder?: string, placeholderPrompts?: string[], withEmptyParagraph?: boolean, placeholderADF?: DocNode, api?: ExtractInjectionAPI<PlaceholderPlugin>): SafePlugin | undefined;
|
|
12
13
|
export declare const placeholderPlugin: PlaceholderPlugin;
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { DocNode } from '@atlaskit/adf-schema';
|
|
1
2
|
import type { EditorCommand, NextEditorPlugin, OptionalPlugin } from '@atlaskit/editor-common/types';
|
|
2
3
|
import type { CompositionPlugin } from '@atlaskit/editor-plugin-composition';
|
|
3
4
|
import type { FocusPlugin } from '@atlaskit/editor-plugin-focus';
|
|
@@ -6,6 +7,7 @@ import type { TypeAheadPlugin } from '@atlaskit/editor-plugin-type-ahead';
|
|
|
6
7
|
export interface PlaceholderPluginOptions {
|
|
7
8
|
emptyLinePlaceholder?: string;
|
|
8
9
|
placeholder?: string;
|
|
10
|
+
placeholderADF?: DocNode;
|
|
9
11
|
placeholderBracketHint?: string;
|
|
10
12
|
placeholderPrompts?: string[];
|
|
11
13
|
withEmptyParagraph?: boolean;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@atlaskit/editor-plugin-placeholder",
|
|
3
|
-
"version": "6.
|
|
3
|
+
"version": "6.5.0",
|
|
4
4
|
"description": "Placeholder plugin for @atlaskit/editor-core.",
|
|
5
5
|
"author": "Atlassian Pty Ltd",
|
|
6
6
|
"license": "Apache-2.0",
|
|
@@ -27,17 +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
|
-
"@atlaskit/editor-plugin-show-diff": "^3.
|
|
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/tmp-editor-statsig": "^13.39.0",
|
|
38
|
+
"@atlaskit/tokens": "^8.1.0",
|
|
37
39
|
"@babel/runtime": "^7.0.0"
|
|
38
40
|
},
|
|
39
41
|
"peerDependencies": {
|
|
40
|
-
"@atlaskit/editor-common": "^110.
|
|
42
|
+
"@atlaskit/editor-common": "^110.33.0",
|
|
41
43
|
"react": "^18.2.0",
|
|
42
44
|
"react-dom": "^18.2.0",
|
|
43
45
|
"react-intl-next": "npm:react-intl@^5.18.1"
|
|
@@ -51,6 +53,9 @@
|
|
|
51
53
|
},
|
|
52
54
|
"platform_editor_ai_aifc_patch_beta_2": {
|
|
53
55
|
"type": "boolean"
|
|
56
|
+
},
|
|
57
|
+
"platform_editor_ai_aifc_patch_ga": {
|
|
58
|
+
"type": "boolean"
|
|
54
59
|
}
|
|
55
60
|
},
|
|
56
61
|
"techstack": {
|