@atlaskit/editor-plugin-placeholder 6.1.1 → 6.3.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 +22 -1
- package/dist/cjs/placeholderPlugin.js +233 -48
- package/dist/es2019/placeholderPlugin.js +204 -21
- package/dist/esm/placeholderPlugin.js +232 -49
- package/dist/types/placeholderPlugin.d.ts +2 -1
- package/dist/types/placeholderPluginType.d.ts +2 -0
- package/dist/types-ts4.5/placeholderPlugin.d.ts +2 -1
- package/dist/types-ts4.5/placeholderPluginType.d.ts +2 -0
- package/package.json +13 -5
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,27 @@
|
|
|
1
1
|
# @atlaskit/editor-plugin-placeholder
|
|
2
2
|
|
|
3
|
+
## 6.3.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- [`673772ec67daf`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/673772ec67daf) -
|
|
8
|
+
[ux] EDITOR-2265 - show placeholder for empty paragraph
|
|
9
|
+
|
|
10
|
+
### Patch Changes
|
|
11
|
+
|
|
12
|
+
- Updated dependencies
|
|
13
|
+
|
|
14
|
+
## 6.2.0
|
|
15
|
+
|
|
16
|
+
### Minor Changes
|
|
17
|
+
|
|
18
|
+
- [`10882b2fab738`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/10882b2fab738) -
|
|
19
|
+
[ux] Introduced bodiedSyncBlock nodeview
|
|
20
|
+
|
|
21
|
+
### Patch Changes
|
|
22
|
+
|
|
23
|
+
- Updated dependencies
|
|
24
|
+
|
|
3
25
|
## 6.1.1
|
|
4
26
|
|
|
5
27
|
### Patch Changes
|
|
@@ -114,7 +136,6 @@
|
|
|
114
136
|
shared context or singletons.
|
|
115
137
|
|
|
116
138
|
**HOW TO ADJUST:**
|
|
117
|
-
|
|
118
139
|
- Consumers must now explicitly install `@atlaskit/editor-common` in their own project if they use
|
|
119
140
|
any of these editor plugins.
|
|
120
141
|
- Ensure the version you install matches the version required by the plugins.
|
|
@@ -1,18 +1,25 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
3
4
|
Object.defineProperty(exports, "__esModule", {
|
|
4
5
|
value: true
|
|
5
6
|
});
|
|
7
|
+
exports.EMPTY_PARAGRAPH_TIMEOUT_DELAY = void 0;
|
|
6
8
|
exports.createPlaceholderDecoration = createPlaceholderDecoration;
|
|
7
9
|
exports.createPlugin = createPlugin;
|
|
8
10
|
exports.pluginKey = exports.placeholderPlugin = void 0;
|
|
11
|
+
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
9
12
|
var _messages = require("@atlaskit/editor-common/messages");
|
|
10
13
|
var _safePlugin = require("@atlaskit/editor-common/safe-plugin");
|
|
11
14
|
var _utils = require("@atlaskit/editor-common/utils");
|
|
12
15
|
var _state = require("@atlaskit/editor-prosemirror/state");
|
|
13
16
|
var _utils2 = require("@atlaskit/editor-prosemirror/utils");
|
|
14
17
|
var _view = require("@atlaskit/editor-prosemirror/view");
|
|
18
|
+
var _platformFeatureFlags = require("@atlaskit/platform-feature-flags");
|
|
19
|
+
var _expValEquals = require("@atlaskit/tmp-editor-statsig/exp-val-equals");
|
|
15
20
|
var _experiments = require("@atlaskit/tmp-editor-statsig/experiments");
|
|
21
|
+
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; }
|
|
22
|
+
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { (0, _defineProperty2.default)(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
16
23
|
// Typewriter animation timing constants
|
|
17
24
|
var TYPEWRITER_TYPE_DELAY = 50; // Delay between typing each character
|
|
18
25
|
var TYPEWRITER_PAUSE_BEFORE_ERASE = 2000; // Pause before starting to erase text
|
|
@@ -20,6 +27,8 @@ var TYPEWRITER_ERASE_DELAY = 40; // Delay between erasing each character
|
|
|
20
27
|
var TYPEWRITER_CYCLE_DELAY = 500; // Delay before starting next cycle
|
|
21
28
|
var TYPEWRITER_TYPED_AND_DELETED_DELAY = 1500; // Delay before starting animation after user typed and deleted
|
|
22
29
|
|
|
30
|
+
var EMPTY_PARAGRAPH_TIMEOUT_DELAY = exports.EMPTY_PARAGRAPH_TIMEOUT_DELAY = 2000; // Delay before showing placeholder on empty paragraph
|
|
31
|
+
|
|
23
32
|
var pluginKey = exports.pluginKey = new _state.PluginKey('placeholderPlugin');
|
|
24
33
|
var placeholderTestId = 'placeholder-test-id';
|
|
25
34
|
function getPlaceholderState(editorState) {
|
|
@@ -27,6 +36,7 @@ function getPlaceholderState(editorState) {
|
|
|
27
36
|
}
|
|
28
37
|
var nodeTypesWithLongPlaceholderText = ['expand', 'panel'];
|
|
29
38
|
var nodeTypesWithShortPlaceholderText = ['tableCell', 'tableHeader'];
|
|
39
|
+
var nodeTypesWithSyncBlockPlaceholderText = ['bodiedSyncBlock'];
|
|
30
40
|
var cycleThroughPlaceholderPrompts = function cycleThroughPlaceholderPrompts(placeholderPrompts, activeTypewriterTimeouts, placeholderNodeWithText) {
|
|
31
41
|
var initialDelayWhenUserTypedAndDeleted = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : 0;
|
|
32
42
|
var currentPromptIndex = 0;
|
|
@@ -122,56 +132,131 @@ function createPlaceholderDecoration(editorState, placeholderText, placeholderPr
|
|
|
122
132
|
key: "placeholder ".concat(placeholderText)
|
|
123
133
|
})]);
|
|
124
134
|
}
|
|
125
|
-
function setPlaceHolderState(
|
|
135
|
+
function setPlaceHolderState(_ref) {
|
|
136
|
+
var placeholderText = _ref.placeholderText,
|
|
137
|
+
pos = _ref.pos,
|
|
138
|
+
placeholderPrompts = _ref.placeholderPrompts,
|
|
139
|
+
typedAndDeleted = _ref.typedAndDeleted,
|
|
140
|
+
userHadTyped = _ref.userHadTyped,
|
|
141
|
+
canShowOnEmptyParagraph = _ref.canShowOnEmptyParagraph,
|
|
142
|
+
showOnEmptyParagraph = _ref.showOnEmptyParagraph;
|
|
126
143
|
return {
|
|
127
144
|
hasPlaceholder: true,
|
|
128
145
|
placeholderText: placeholderText,
|
|
129
146
|
placeholderPrompts: placeholderPrompts,
|
|
130
147
|
pos: pos ? pos : 1,
|
|
131
148
|
typedAndDeleted: typedAndDeleted,
|
|
132
|
-
userHadTyped: userHadTyped
|
|
149
|
+
userHadTyped: userHadTyped,
|
|
150
|
+
canShowOnEmptyParagraph: canShowOnEmptyParagraph,
|
|
151
|
+
showOnEmptyParagraph: showOnEmptyParagraph
|
|
133
152
|
};
|
|
134
153
|
}
|
|
135
|
-
var emptyPlaceholder = function emptyPlaceholder(
|
|
154
|
+
var emptyPlaceholder = function emptyPlaceholder(_ref2) {
|
|
155
|
+
var placeholderText = _ref2.placeholderText,
|
|
156
|
+
placeholderPrompts = _ref2.placeholderPrompts,
|
|
157
|
+
userHadTyped = _ref2.userHadTyped,
|
|
158
|
+
pos = _ref2.pos,
|
|
159
|
+
canShowOnEmptyParagraph = _ref2.canShowOnEmptyParagraph,
|
|
160
|
+
showOnEmptyParagraph = _ref2.showOnEmptyParagraph;
|
|
136
161
|
return {
|
|
137
162
|
hasPlaceholder: false,
|
|
138
163
|
placeholderText: placeholderText,
|
|
139
164
|
placeholderPrompts: placeholderPrompts,
|
|
140
165
|
userHadTyped: userHadTyped,
|
|
141
|
-
typedAndDeleted: false
|
|
166
|
+
typedAndDeleted: false,
|
|
167
|
+
canShowOnEmptyParagraph: canShowOnEmptyParagraph,
|
|
168
|
+
showOnEmptyParagraph: showOnEmptyParagraph,
|
|
169
|
+
pos: pos
|
|
142
170
|
};
|
|
143
171
|
};
|
|
144
|
-
function createPlaceHolderStateFrom(
|
|
145
|
-
var
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
172
|
+
function createPlaceHolderStateFrom(_ref3) {
|
|
173
|
+
var isInitial = _ref3.isInitial,
|
|
174
|
+
isEditorFocused = _ref3.isEditorFocused,
|
|
175
|
+
editorState = _ref3.editorState,
|
|
176
|
+
isTypeAheadOpen = _ref3.isTypeAheadOpen,
|
|
177
|
+
defaultPlaceholderText = _ref3.defaultPlaceholderText,
|
|
178
|
+
intl = _ref3.intl,
|
|
179
|
+
bracketPlaceholderText = _ref3.bracketPlaceholderText,
|
|
180
|
+
emptyLinePlaceholder = _ref3.emptyLinePlaceholder,
|
|
181
|
+
placeholderPrompts = _ref3.placeholderPrompts,
|
|
182
|
+
typedAndDeleted = _ref3.typedAndDeleted,
|
|
183
|
+
userHadTyped = _ref3.userHadTyped,
|
|
184
|
+
isPlaceholderHidden = _ref3.isPlaceholderHidden,
|
|
185
|
+
withEmptyParagraph = _ref3.withEmptyParagraph,
|
|
186
|
+
showOnEmptyParagraph = _ref3.showOnEmptyParagraph;
|
|
187
|
+
if (isPlaceholderHidden && (0, _platformFeatureFlags.fg)('platform_editor_ai_aifc_patch_beta')) {
|
|
188
|
+
return _objectSpread(_objectSpread({}, emptyPlaceholder({
|
|
189
|
+
placeholderText: defaultPlaceholderText,
|
|
190
|
+
placeholderPrompts: placeholderPrompts,
|
|
191
|
+
userHadTyped: userHadTyped
|
|
192
|
+
})), {}, {
|
|
193
|
+
isPlaceholderHidden: isPlaceholderHidden
|
|
194
|
+
});
|
|
195
|
+
}
|
|
155
196
|
if (isTypeAheadOpen !== null && isTypeAheadOpen !== void 0 && isTypeAheadOpen(editorState)) {
|
|
156
|
-
return emptyPlaceholder(
|
|
197
|
+
return emptyPlaceholder({
|
|
198
|
+
placeholderText: defaultPlaceholderText,
|
|
199
|
+
placeholderPrompts: placeholderPrompts,
|
|
200
|
+
userHadTyped: userHadTyped
|
|
201
|
+
});
|
|
157
202
|
}
|
|
158
203
|
if ((defaultPlaceholderText || placeholderPrompts) && (0, _utils.isEmptyDocument)(editorState.doc)) {
|
|
159
|
-
return setPlaceHolderState(
|
|
204
|
+
return setPlaceHolderState({
|
|
205
|
+
placeholderText: defaultPlaceholderText,
|
|
206
|
+
pos: 1,
|
|
207
|
+
placeholderPrompts: placeholderPrompts,
|
|
208
|
+
typedAndDeleted: typedAndDeleted,
|
|
209
|
+
userHadTyped: userHadTyped
|
|
210
|
+
});
|
|
160
211
|
}
|
|
161
|
-
if (
|
|
162
|
-
var _parentNode$firstChil, _parentNode$firstChil2;
|
|
212
|
+
if ((0, _platformFeatureFlags.fg)('platform_editor_ai_aifc_patch_beta_2')) {
|
|
163
213
|
var _editorState$selectio = editorState.selection,
|
|
164
|
-
|
|
214
|
+
from = _editorState$selectio.from,
|
|
215
|
+
to = _editorState$selectio.to,
|
|
165
216
|
$to = _editorState$selectio.$to;
|
|
166
|
-
if (
|
|
167
|
-
return
|
|
217
|
+
if (defaultPlaceholderText && withEmptyParagraph && isEditorFocused && !isInitial && !(0, _utils.isEmptyDocument)(editorState.doc) && from === to && (0, _utils.isEmptyParagraph)($to.parent) && (0, _utils.hasDocAsParent)($to)) {
|
|
218
|
+
return showOnEmptyParagraph ? setPlaceHolderState({
|
|
219
|
+
placeholderText: defaultPlaceholderText,
|
|
220
|
+
pos: to,
|
|
221
|
+
placeholderPrompts: placeholderPrompts,
|
|
222
|
+
typedAndDeleted: typedAndDeleted,
|
|
223
|
+
userHadTyped: userHadTyped,
|
|
224
|
+
canShowOnEmptyParagraph: true,
|
|
225
|
+
showOnEmptyParagraph: true
|
|
226
|
+
}) : emptyPlaceholder({
|
|
227
|
+
placeholderText: defaultPlaceholderText,
|
|
228
|
+
placeholderPrompts: placeholderPrompts,
|
|
229
|
+
userHadTyped: userHadTyped,
|
|
230
|
+
canShowOnEmptyParagraph: true,
|
|
231
|
+
showOnEmptyParagraph: false,
|
|
232
|
+
pos: to
|
|
233
|
+
});
|
|
234
|
+
}
|
|
235
|
+
}
|
|
236
|
+
if (isEditorFocused && (0, _experiments.editorExperiment)('platform_editor_controls', 'variant1')) {
|
|
237
|
+
var _parentNode$firstChil, _parentNode$firstChil2;
|
|
238
|
+
var _editorState$selectio2 = editorState.selection,
|
|
239
|
+
$from = _editorState$selectio2.$from,
|
|
240
|
+
_$to = _editorState$selectio2.$to;
|
|
241
|
+
if ($from.pos !== _$to.pos) {
|
|
242
|
+
return emptyPlaceholder({
|
|
243
|
+
placeholderText: defaultPlaceholderText,
|
|
244
|
+
placeholderPrompts: placeholderPrompts,
|
|
245
|
+
userHadTyped: userHadTyped
|
|
246
|
+
});
|
|
168
247
|
}
|
|
169
248
|
var parentNode = $from.node($from.depth - 1);
|
|
170
249
|
var parentType = parentNode === null || parentNode === void 0 ? void 0 : parentNode.type.name;
|
|
171
250
|
if (emptyLinePlaceholder && parentType === 'doc') {
|
|
172
251
|
var isEmptyLine = (0, _utils.isEmptyParagraph)($from.parent);
|
|
173
252
|
if (isEmptyLine) {
|
|
174
|
-
return setPlaceHolderState(
|
|
253
|
+
return setPlaceHolderState({
|
|
254
|
+
placeholderText: emptyLinePlaceholder,
|
|
255
|
+
pos: $from.pos,
|
|
256
|
+
placeholderPrompts: placeholderPrompts,
|
|
257
|
+
typedAndDeleted: typedAndDeleted,
|
|
258
|
+
userHadTyped: userHadTyped
|
|
259
|
+
});
|
|
175
260
|
}
|
|
176
261
|
}
|
|
177
262
|
var isEmptyNode = (parentNode === null || parentNode === void 0 ? void 0 : parentNode.childCount) === 1 && ((_parentNode$firstChil = parentNode.firstChild) === null || _parentNode$firstChil === void 0 ? void 0 : _parentNode$firstChil.content.size) === 0 && ((_parentNode$firstChil2 = parentNode.firstChild) === null || _parentNode$firstChil2 === void 0 ? void 0 : _parentNode$firstChil2.type.name) === 'paragraph';
|
|
@@ -181,30 +266,69 @@ function createPlaceHolderStateFrom(_ref) {
|
|
|
181
266
|
return node.type === editorState.schema.nodes.table;
|
|
182
267
|
})(editorState.selection);
|
|
183
268
|
if (!table) {
|
|
184
|
-
return emptyPlaceholder(
|
|
269
|
+
return emptyPlaceholder({
|
|
270
|
+
placeholderText: defaultPlaceholderText,
|
|
271
|
+
placeholderPrompts: placeholderPrompts,
|
|
272
|
+
userHadTyped: userHadTyped
|
|
273
|
+
});
|
|
185
274
|
}
|
|
186
275
|
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;
|
|
187
276
|
if (isFirstCell) {
|
|
188
|
-
return setPlaceHolderState(
|
|
277
|
+
return setPlaceHolderState({
|
|
278
|
+
placeholderText: intl.formatMessage(_messages.placeholderTextMessages.shortEmptyNodePlaceholderText),
|
|
279
|
+
pos: $from.pos,
|
|
280
|
+
placeholderPrompts: placeholderPrompts,
|
|
281
|
+
typedAndDeleted: typedAndDeleted,
|
|
282
|
+
userHadTyped: userHadTyped
|
|
283
|
+
});
|
|
189
284
|
}
|
|
190
285
|
}
|
|
191
286
|
if (nodeTypesWithLongPlaceholderText.includes(parentType) && isEmptyNode) {
|
|
192
|
-
return setPlaceHolderState(
|
|
287
|
+
return setPlaceHolderState({
|
|
288
|
+
placeholderText: intl.formatMessage(_messages.placeholderTextMessages.longEmptyNodePlaceholderText),
|
|
289
|
+
pos: $from.pos,
|
|
290
|
+
placeholderPrompts: placeholderPrompts,
|
|
291
|
+
typedAndDeleted: typedAndDeleted,
|
|
292
|
+
userHadTyped: userHadTyped
|
|
293
|
+
});
|
|
294
|
+
}
|
|
295
|
+
if (nodeTypesWithSyncBlockPlaceholderText.includes(parentType) && isEmptyNode && (0, _expValEquals.expValEquals)('platform_synced_block', 'isEnabled', true)) {
|
|
296
|
+
return setPlaceHolderState({
|
|
297
|
+
placeholderText: intl.formatMessage(_messages.placeholderTextMessages.syncBlockPlaceholderText),
|
|
298
|
+
pos: $from.pos,
|
|
299
|
+
placeholderPrompts: placeholderPrompts,
|
|
300
|
+
typedAndDeleted: typedAndDeleted,
|
|
301
|
+
userHadTyped: userHadTyped
|
|
302
|
+
});
|
|
193
303
|
}
|
|
194
|
-
return emptyPlaceholder(
|
|
304
|
+
return emptyPlaceholder({
|
|
305
|
+
placeholderText: defaultPlaceholderText,
|
|
306
|
+
placeholderPrompts: placeholderPrompts,
|
|
307
|
+
userHadTyped: userHadTyped
|
|
308
|
+
});
|
|
195
309
|
}
|
|
196
310
|
if (bracketPlaceholderText && (0, _utils.bracketTyped)(editorState) && isEditorFocused) {
|
|
197
311
|
var _$from = editorState.selection.$from;
|
|
198
312
|
// Space is to account for positioning of the bracket
|
|
199
313
|
var bracketHint = ' ' + bracketPlaceholderText;
|
|
200
|
-
return setPlaceHolderState(
|
|
314
|
+
return setPlaceHolderState({
|
|
315
|
+
placeholderText: bracketHint,
|
|
316
|
+
pos: _$from.pos - 1,
|
|
317
|
+
placeholderPrompts: placeholderPrompts,
|
|
318
|
+
typedAndDeleted: typedAndDeleted,
|
|
319
|
+
userHadTyped: userHadTyped
|
|
320
|
+
});
|
|
201
321
|
}
|
|
202
|
-
return emptyPlaceholder(
|
|
322
|
+
return emptyPlaceholder({
|
|
323
|
+
placeholderText: defaultPlaceholderText,
|
|
324
|
+
placeholderPrompts: placeholderPrompts,
|
|
325
|
+
userHadTyped: userHadTyped
|
|
326
|
+
});
|
|
203
327
|
}
|
|
204
|
-
function calculateUserInteractionState(
|
|
205
|
-
var placeholderState =
|
|
206
|
-
oldEditorState =
|
|
207
|
-
newEditorState =
|
|
328
|
+
function calculateUserInteractionState(_ref4) {
|
|
329
|
+
var placeholderState = _ref4.placeholderState,
|
|
330
|
+
oldEditorState = _ref4.oldEditorState,
|
|
331
|
+
newEditorState = _ref4.newEditorState;
|
|
208
332
|
var wasEmpty = oldEditorState ? (0, _utils.isEmptyDocument)(oldEditorState.doc) : true;
|
|
209
333
|
var isEmpty = (0, _utils.isEmptyDocument)(newEditorState.doc);
|
|
210
334
|
var hasEverTyped = Boolean(placeholderState === null || placeholderState === void 0 ? void 0 : placeholderState.userHadTyped) ||
|
|
@@ -221,7 +345,7 @@ function calculateUserInteractionState(_ref2) {
|
|
|
221
345
|
typedAndDeleted: isInTypedAndDeletedState
|
|
222
346
|
};
|
|
223
347
|
}
|
|
224
|
-
function createPlugin(intl, defaultPlaceholderText, bracketPlaceholderText, emptyLinePlaceholder, placeholderPrompts, api) {
|
|
348
|
+
function createPlugin(intl, defaultPlaceholderText, bracketPlaceholderText, emptyLinePlaceholder, placeholderPrompts, withEmptyParagraph, api) {
|
|
225
349
|
if (!defaultPlaceholderText && !placeholderPrompts && !bracketPlaceholderText) {
|
|
226
350
|
return;
|
|
227
351
|
}
|
|
@@ -239,6 +363,7 @@ function createPlugin(intl, defaultPlaceholderText, bracketPlaceholderText, empt
|
|
|
239
363
|
init: function init(_, state) {
|
|
240
364
|
var _api$focus, _api$typeAhead;
|
|
241
365
|
return createPlaceHolderStateFrom({
|
|
366
|
+
isInitial: true,
|
|
242
367
|
isEditorFocused: Boolean(api === null || api === void 0 || (_api$focus = api.focus) === null || _api$focus === void 0 || (_api$focus = _api$focus.sharedState.currentState()) === null || _api$focus === void 0 ? void 0 : _api$focus.hasFocus),
|
|
243
368
|
editorState: state,
|
|
244
369
|
isTypeAheadOpen: api === null || api === void 0 || (_api$typeAhead = api.typeAhead) === null || _api$typeAhead === void 0 ? void 0 : _api$typeAhead.actions.isOpen,
|
|
@@ -252,7 +377,7 @@ function createPlugin(intl, defaultPlaceholderText, bracketPlaceholderText, empt
|
|
|
252
377
|
});
|
|
253
378
|
},
|
|
254
379
|
apply: function apply(tr, placeholderState, _oldEditorState, newEditorState) {
|
|
255
|
-
var _api$focus2, _api$typeAhead2,
|
|
380
|
+
var _api$focus2, _placeholderState$isP, _api$typeAhead2, _ref5, _meta$placeholderText, _ref6, _meta$placeholderProm, _meta$showOnEmptyPara;
|
|
256
381
|
var meta = tr.getMeta(pluginKey);
|
|
257
382
|
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);
|
|
258
383
|
var _calculateUserInterac = calculateUserInteractionState({
|
|
@@ -262,17 +387,27 @@ function createPlugin(intl, defaultPlaceholderText, bracketPlaceholderText, empt
|
|
|
262
387
|
}),
|
|
263
388
|
userHadTyped = _calculateUserInterac.userHadTyped,
|
|
264
389
|
typedAndDeleted = _calculateUserInterac.typedAndDeleted;
|
|
390
|
+
var isPlaceholderHidden = (_placeholderState$isP = placeholderState === null || placeholderState === void 0 ? void 0 : placeholderState.isPlaceholderHidden) !== null && _placeholderState$isP !== void 0 ? _placeholderState$isP : false;
|
|
391
|
+
if ((meta === null || meta === void 0 ? void 0 : meta.isPlaceholderHidden) !== undefined && (0, _platformFeatureFlags.fg)('platform_editor_ai_aifc_patch_beta')) {
|
|
392
|
+
isPlaceholderHidden = meta.isPlaceholderHidden;
|
|
393
|
+
}
|
|
394
|
+
if ((meta === null || meta === void 0 ? void 0 : meta.placeholderText) !== undefined && (0, _platformFeatureFlags.fg)('platform_editor_ai_aifc_patch_beta_2')) {
|
|
395
|
+
defaultPlaceholderText = meta.placeholderText;
|
|
396
|
+
}
|
|
265
397
|
var newPlaceholderState = createPlaceHolderStateFrom({
|
|
266
398
|
isEditorFocused: isEditorFocused,
|
|
267
399
|
editorState: newEditorState,
|
|
268
400
|
isTypeAheadOpen: api === null || api === void 0 || (_api$typeAhead2 = api.typeAhead) === null || _api$typeAhead2 === void 0 ? void 0 : _api$typeAhead2.actions.isOpen,
|
|
269
|
-
defaultPlaceholderText: (
|
|
401
|
+
defaultPlaceholderText: (0, _platformFeatureFlags.fg)('platform_editor_ai_aifc_patch_beta_2') ? defaultPlaceholderText : (_ref5 = (_meta$placeholderText = meta === null || meta === void 0 ? void 0 : meta.placeholderText) !== null && _meta$placeholderText !== void 0 ? _meta$placeholderText : placeholderState === null || placeholderState === void 0 ? void 0 : placeholderState.placeholderText) !== null && _ref5 !== void 0 ? _ref5 : defaultPlaceholderText,
|
|
270
402
|
bracketPlaceholderText: bracketPlaceholderText,
|
|
271
403
|
emptyLinePlaceholder: emptyLinePlaceholder,
|
|
272
|
-
placeholderPrompts: (
|
|
404
|
+
placeholderPrompts: (_ref6 = (_meta$placeholderProm = meta === null || meta === void 0 ? void 0 : meta.placeholderPrompts) !== null && _meta$placeholderProm !== void 0 ? _meta$placeholderProm : placeholderState === null || placeholderState === void 0 ? void 0 : placeholderState.placeholderPrompts) !== null && _ref6 !== void 0 ? _ref6 : placeholderPrompts,
|
|
273
405
|
typedAndDeleted: typedAndDeleted,
|
|
274
406
|
userHadTyped: userHadTyped,
|
|
275
|
-
intl: intl
|
|
407
|
+
intl: intl,
|
|
408
|
+
isPlaceholderHidden: isPlaceholderHidden,
|
|
409
|
+
withEmptyParagraph: withEmptyParagraph,
|
|
410
|
+
showOnEmptyParagraph: (_meta$showOnEmptyPara = meta === null || meta === void 0 ? void 0 : meta.showOnEmptyParagraph) !== null && _meta$showOnEmptyPara !== void 0 ? _meta$showOnEmptyPara : placeholderState === null || placeholderState === void 0 ? void 0 : placeholderState.showOnEmptyParagraph
|
|
276
411
|
});
|
|
277
412
|
|
|
278
413
|
// Clear timeouts when hasPlaceholder becomes false
|
|
@@ -306,25 +441,67 @@ function createPlugin(intl, defaultPlaceholderText, bracketPlaceholderText, empt
|
|
|
306
441
|
}
|
|
307
442
|
},
|
|
308
443
|
view: function view() {
|
|
444
|
+
var timeoutId;
|
|
445
|
+
function startEmptyParagraphTimeout(editorView) {
|
|
446
|
+
if (timeoutId) {
|
|
447
|
+
return;
|
|
448
|
+
}
|
|
449
|
+
timeoutId = setTimeout(function () {
|
|
450
|
+
timeoutId = undefined;
|
|
451
|
+
editorView.dispatch(editorView.state.tr.setMeta(pluginKey, {
|
|
452
|
+
showOnEmptyParagraph: true
|
|
453
|
+
}));
|
|
454
|
+
}, EMPTY_PARAGRAPH_TIMEOUT_DELAY);
|
|
455
|
+
}
|
|
456
|
+
function destroyEmptyParagraphTimeout() {
|
|
457
|
+
if (timeoutId) {
|
|
458
|
+
clearTimeout(timeoutId);
|
|
459
|
+
timeoutId = undefined;
|
|
460
|
+
}
|
|
461
|
+
}
|
|
309
462
|
return {
|
|
463
|
+
update: function update(editorView, prevState) {
|
|
464
|
+
if ((0, _platformFeatureFlags.fg)('platform_editor_ai_aifc_patch_beta_2')) {
|
|
465
|
+
var prevPluginState = getPlaceholderState(prevState);
|
|
466
|
+
var newPluginState = getPlaceholderState(editorView.state);
|
|
467
|
+
|
|
468
|
+
// user start typing after move to an empty paragraph, clear timeout
|
|
469
|
+
if (!newPluginState.canShowOnEmptyParagraph && timeoutId) {
|
|
470
|
+
destroyEmptyParagraphTimeout();
|
|
471
|
+
}
|
|
472
|
+
// user move to an empty paragraph again, reset state to hide placeholder, and restart timeout
|
|
473
|
+
else if (prevPluginState.canShowOnEmptyParagraph && newPluginState.canShowOnEmptyParagraph && newPluginState.pos !== prevPluginState.pos) {
|
|
474
|
+
editorView.dispatch(editorView.state.tr.setMeta(pluginKey, {
|
|
475
|
+
showOnEmptyParagraph: false
|
|
476
|
+
}));
|
|
477
|
+
destroyEmptyParagraphTimeout();
|
|
478
|
+
startEmptyParagraphTimeout(editorView);
|
|
479
|
+
}
|
|
480
|
+
// user move to an empty paragraph (by click enter or move to an empty paragraph), start timeout
|
|
481
|
+
else if (!prevPluginState.canShowOnEmptyParagraph && newPluginState.canShowOnEmptyParagraph && !newPluginState.showOnEmptyParagraph && !timeoutId) {
|
|
482
|
+
startEmptyParagraphTimeout(editorView);
|
|
483
|
+
}
|
|
484
|
+
}
|
|
485
|
+
},
|
|
310
486
|
destroy: function destroy() {
|
|
311
487
|
clearAllTypewriterTimeouts();
|
|
488
|
+
destroyEmptyParagraphTimeout();
|
|
312
489
|
isDestroyed = true;
|
|
313
490
|
}
|
|
314
491
|
};
|
|
315
492
|
}
|
|
316
493
|
});
|
|
317
494
|
}
|
|
318
|
-
var placeholderPlugin = exports.placeholderPlugin = function placeholderPlugin(
|
|
319
|
-
var options =
|
|
320
|
-
api =
|
|
495
|
+
var placeholderPlugin = exports.placeholderPlugin = function placeholderPlugin(_ref7) {
|
|
496
|
+
var options = _ref7.config,
|
|
497
|
+
api = _ref7.api;
|
|
321
498
|
var currentPlaceholder = options === null || options === void 0 ? void 0 : options.placeholder;
|
|
322
499
|
return {
|
|
323
500
|
name: 'placeholder',
|
|
324
501
|
commands: {
|
|
325
502
|
setPlaceholder: function setPlaceholder(placeholderText) {
|
|
326
|
-
return function (
|
|
327
|
-
var tr =
|
|
503
|
+
return function (_ref8) {
|
|
504
|
+
var tr = _ref8.tr;
|
|
328
505
|
if (currentPlaceholder !== placeholderText) {
|
|
329
506
|
currentPlaceholder = placeholderText;
|
|
330
507
|
return tr.setMeta(pluginKey, {
|
|
@@ -335,20 +512,28 @@ var placeholderPlugin = exports.placeholderPlugin = function placeholderPlugin(_
|
|
|
335
512
|
};
|
|
336
513
|
},
|
|
337
514
|
setAnimatingPlaceholderPrompts: function setAnimatingPlaceholderPrompts(placeholderPrompts) {
|
|
338
|
-
return function (
|
|
339
|
-
var tr =
|
|
515
|
+
return function (_ref9) {
|
|
516
|
+
var tr = _ref9.tr;
|
|
340
517
|
return tr.setMeta(pluginKey, {
|
|
341
518
|
placeholderPrompts: placeholderPrompts
|
|
342
519
|
});
|
|
343
520
|
};
|
|
521
|
+
},
|
|
522
|
+
setPlaceholderHidden: function setPlaceholderHidden(isPlaceholderHidden) {
|
|
523
|
+
return function (_ref0) {
|
|
524
|
+
var tr = _ref0.tr;
|
|
525
|
+
return tr.setMeta(pluginKey, {
|
|
526
|
+
isPlaceholderHidden: isPlaceholderHidden
|
|
527
|
+
});
|
|
528
|
+
};
|
|
344
529
|
}
|
|
345
530
|
},
|
|
346
531
|
pmPlugins: function pmPlugins() {
|
|
347
532
|
return [{
|
|
348
533
|
name: 'placeholder',
|
|
349
|
-
plugin: function plugin(
|
|
350
|
-
var getIntl =
|
|
351
|
-
return createPlugin(getIntl(), options && options.placeholder, options && options.placeholderBracketHint, options && options.emptyLinePlaceholder, options && options.placeholderPrompts, api);
|
|
534
|
+
plugin: function plugin(_ref1) {
|
|
535
|
+
var getIntl = _ref1.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);
|
|
352
537
|
}
|
|
353
538
|
}];
|
|
354
539
|
}
|