@atlaskit/editor-plugin-placeholder 6.5.4 → 6.6.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +18 -0
- package/dist/cjs/placeholderPlugin.js +19 -568
- package/dist/cjs/pm-plugins/adf-builders.js +30 -0
- package/dist/cjs/pm-plugins/animation.js +58 -0
- package/dist/cjs/pm-plugins/constants.js +18 -0
- package/dist/cjs/pm-plugins/decorations.js +96 -0
- package/dist/cjs/pm-plugins/main.js +168 -0
- package/dist/cjs/pm-plugins/placeholderPluginLegacy.js +617 -0
- package/dist/cjs/pm-plugins/types.js +5 -0
- package/dist/cjs/pm-plugins/utils.js +243 -0
- package/dist/es2019/placeholderPlugin.js +8 -548
- package/dist/es2019/pm-plugins/adf-builders.js +22 -0
- package/dist/es2019/pm-plugins/animation.js +49 -0
- package/dist/es2019/pm-plugins/constants.js +12 -0
- package/dist/es2019/pm-plugins/decorations.js +87 -0
- package/dist/es2019/pm-plugins/main.js +162 -0
- package/dist/es2019/pm-plugins/placeholderPluginLegacy.js +598 -0
- package/dist/es2019/pm-plugins/types.js +1 -0
- package/dist/es2019/pm-plugins/utils.js +234 -0
- package/dist/esm/placeholderPlugin.js +17 -563
- package/dist/esm/pm-plugins/adf-builders.js +24 -0
- package/dist/esm/pm-plugins/animation.js +52 -0
- package/dist/esm/pm-plugins/constants.js +12 -0
- package/dist/esm/pm-plugins/decorations.js +90 -0
- package/dist/esm/pm-plugins/main.js +162 -0
- package/dist/esm/pm-plugins/placeholderPluginLegacy.js +607 -0
- package/dist/esm/pm-plugins/types.js +1 -0
- package/dist/esm/pm-plugins/utils.js +232 -0
- package/dist/types/placeholderPlugin.d.ts +0 -8
- package/dist/types/pm-plugins/adf-builders.d.ts +4 -0
- package/dist/types/pm-plugins/animation.d.ts +1 -0
- package/dist/types/pm-plugins/constants.d.ts +9 -0
- package/dist/types/pm-plugins/decorations.d.ts +4 -0
- package/dist/types/pm-plugins/main.d.ts +6 -0
- package/dist/types/pm-plugins/placeholderPluginLegacy.d.ts +13 -0
- package/dist/types/pm-plugins/types.d.ts +37 -0
- package/dist/types/pm-plugins/utils.d.ts +27 -0
- package/dist/types-ts4.5/placeholderPlugin.d.ts +0 -8
- package/dist/types-ts4.5/pm-plugins/adf-builders.d.ts +4 -0
- package/dist/types-ts4.5/pm-plugins/animation.d.ts +1 -0
- package/dist/types-ts4.5/pm-plugins/constants.d.ts +9 -0
- package/dist/types-ts4.5/pm-plugins/decorations.d.ts +4 -0
- package/dist/types-ts4.5/pm-plugins/main.d.ts +6 -0
- package/dist/types-ts4.5/pm-plugins/placeholderPluginLegacy.d.ts +13 -0
- package/dist/types-ts4.5/pm-plugins/types.d.ts +37 -0
- package/dist/types-ts4.5/pm-plugins/utils.d.ts +27 -0
- package/package.json +6 -9
|
@@ -0,0 +1,243 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
+
Object.defineProperty(exports, "__esModule", {
|
|
5
|
+
value: true
|
|
6
|
+
});
|
|
7
|
+
exports.calculateUserInteractionState = calculateUserInteractionState;
|
|
8
|
+
exports.createPlaceHolderStateFrom = createPlaceHolderStateFrom;
|
|
9
|
+
exports.emptyPlaceholder = void 0;
|
|
10
|
+
exports.getPlaceholderState = getPlaceholderState;
|
|
11
|
+
exports.setPlaceHolderState = setPlaceHolderState;
|
|
12
|
+
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
13
|
+
var _messages = require("@atlaskit/editor-common/messages");
|
|
14
|
+
var _utils = require("@atlaskit/editor-common/utils");
|
|
15
|
+
var _utils2 = require("@atlaskit/editor-prosemirror/utils");
|
|
16
|
+
var _platformFeatureFlags = require("@atlaskit/platform-feature-flags");
|
|
17
|
+
var _experiments = require("@atlaskit/tmp-editor-statsig/experiments");
|
|
18
|
+
var _placeholderPlugin = require("../placeholderPlugin");
|
|
19
|
+
var _adfBuilders = require("./adf-builders");
|
|
20
|
+
var _constants = require("./constants");
|
|
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; }
|
|
23
|
+
function getPlaceholderState(editorState) {
|
|
24
|
+
return _placeholderPlugin.pluginKey.getState(editorState);
|
|
25
|
+
}
|
|
26
|
+
function setPlaceHolderState(_ref) {
|
|
27
|
+
var placeholderText = _ref.placeholderText,
|
|
28
|
+
pos = _ref.pos,
|
|
29
|
+
placeholderPrompts = _ref.placeholderPrompts,
|
|
30
|
+
typedAndDeleted = _ref.typedAndDeleted,
|
|
31
|
+
userHadTyped = _ref.userHadTyped,
|
|
32
|
+
canShowOnEmptyParagraph = _ref.canShowOnEmptyParagraph,
|
|
33
|
+
showOnEmptyParagraph = _ref.showOnEmptyParagraph,
|
|
34
|
+
contextPlaceholderADF = _ref.contextPlaceholderADF;
|
|
35
|
+
return {
|
|
36
|
+
hasPlaceholder: true,
|
|
37
|
+
placeholderText: placeholderText,
|
|
38
|
+
placeholderPrompts: placeholderPrompts,
|
|
39
|
+
contextPlaceholderADF: contextPlaceholderADF,
|
|
40
|
+
pos: pos ? pos : 1,
|
|
41
|
+
typedAndDeleted: typedAndDeleted,
|
|
42
|
+
userHadTyped: userHadTyped,
|
|
43
|
+
canShowOnEmptyParagraph: canShowOnEmptyParagraph,
|
|
44
|
+
showOnEmptyParagraph: showOnEmptyParagraph
|
|
45
|
+
};
|
|
46
|
+
}
|
|
47
|
+
var emptyPlaceholder = exports.emptyPlaceholder = function emptyPlaceholder(_ref2) {
|
|
48
|
+
var placeholderText = _ref2.placeholderText,
|
|
49
|
+
placeholderPrompts = _ref2.placeholderPrompts,
|
|
50
|
+
userHadTyped = _ref2.userHadTyped,
|
|
51
|
+
pos = _ref2.pos,
|
|
52
|
+
canShowOnEmptyParagraph = _ref2.canShowOnEmptyParagraph,
|
|
53
|
+
showOnEmptyParagraph = _ref2.showOnEmptyParagraph;
|
|
54
|
+
return {
|
|
55
|
+
hasPlaceholder: false,
|
|
56
|
+
placeholderText: placeholderText,
|
|
57
|
+
placeholderPrompts: placeholderPrompts,
|
|
58
|
+
userHadTyped: userHadTyped,
|
|
59
|
+
typedAndDeleted: false,
|
|
60
|
+
canShowOnEmptyParagraph: canShowOnEmptyParagraph,
|
|
61
|
+
showOnEmptyParagraph: showOnEmptyParagraph,
|
|
62
|
+
pos: pos
|
|
63
|
+
};
|
|
64
|
+
};
|
|
65
|
+
function createPlaceHolderStateFrom(_ref3) {
|
|
66
|
+
var isInitial = _ref3.isInitial,
|
|
67
|
+
isEditorFocused = _ref3.isEditorFocused,
|
|
68
|
+
editorState = _ref3.editorState,
|
|
69
|
+
isTypeAheadOpen = _ref3.isTypeAheadOpen,
|
|
70
|
+
defaultPlaceholderText = _ref3.defaultPlaceholderText,
|
|
71
|
+
intl = _ref3.intl,
|
|
72
|
+
bracketPlaceholderText = _ref3.bracketPlaceholderText,
|
|
73
|
+
emptyLinePlaceholder = _ref3.emptyLinePlaceholder,
|
|
74
|
+
placeholderADF = _ref3.placeholderADF,
|
|
75
|
+
placeholderPrompts = _ref3.placeholderPrompts,
|
|
76
|
+
typedAndDeleted = _ref3.typedAndDeleted,
|
|
77
|
+
userHadTyped = _ref3.userHadTyped,
|
|
78
|
+
isPlaceholderHidden = _ref3.isPlaceholderHidden,
|
|
79
|
+
withEmptyParagraph = _ref3.withEmptyParagraph,
|
|
80
|
+
showOnEmptyParagraph = _ref3.showOnEmptyParagraph;
|
|
81
|
+
if (isPlaceholderHidden && withEmptyParagraph) {
|
|
82
|
+
return _objectSpread(_objectSpread({}, emptyPlaceholder({
|
|
83
|
+
placeholderText: defaultPlaceholderText,
|
|
84
|
+
placeholderPrompts: placeholderPrompts,
|
|
85
|
+
userHadTyped: userHadTyped
|
|
86
|
+
})), {}, {
|
|
87
|
+
isPlaceholderHidden: isPlaceholderHidden
|
|
88
|
+
});
|
|
89
|
+
}
|
|
90
|
+
if (isTypeAheadOpen !== null && isTypeAheadOpen !== void 0 && isTypeAheadOpen(editorState)) {
|
|
91
|
+
return emptyPlaceholder({
|
|
92
|
+
placeholderText: defaultPlaceholderText,
|
|
93
|
+
placeholderPrompts: placeholderPrompts,
|
|
94
|
+
userHadTyped: userHadTyped
|
|
95
|
+
});
|
|
96
|
+
}
|
|
97
|
+
if ((defaultPlaceholderText || placeholderPrompts || placeholderADF) && (0, _utils.isEmptyDocument)(editorState.doc)) {
|
|
98
|
+
return setPlaceHolderState({
|
|
99
|
+
placeholderText: defaultPlaceholderText,
|
|
100
|
+
pos: 1,
|
|
101
|
+
placeholderPrompts: placeholderPrompts,
|
|
102
|
+
typedAndDeleted: typedAndDeleted,
|
|
103
|
+
userHadTyped: userHadTyped
|
|
104
|
+
});
|
|
105
|
+
}
|
|
106
|
+
if (withEmptyParagraph) {
|
|
107
|
+
var _editorState$selectio = editorState.selection,
|
|
108
|
+
from = _editorState$selectio.from,
|
|
109
|
+
to = _editorState$selectio.to,
|
|
110
|
+
$to = _editorState$selectio.$to;
|
|
111
|
+
if ((defaultPlaceholderText || placeholderADF) && withEmptyParagraph && isEditorFocused && !isInitial && !(0, _utils.isEmptyDocument)(editorState.doc) && from === to && (0, _utils.isEmptyParagraph)($to.parent) && (0, _utils.hasDocAsParent)($to)) {
|
|
112
|
+
return showOnEmptyParagraph ? setPlaceHolderState({
|
|
113
|
+
placeholderText: defaultPlaceholderText,
|
|
114
|
+
pos: to,
|
|
115
|
+
placeholderPrompts: placeholderPrompts,
|
|
116
|
+
typedAndDeleted: typedAndDeleted,
|
|
117
|
+
userHadTyped: userHadTyped,
|
|
118
|
+
canShowOnEmptyParagraph: true,
|
|
119
|
+
showOnEmptyParagraph: true
|
|
120
|
+
}) : emptyPlaceholder({
|
|
121
|
+
placeholderText: defaultPlaceholderText,
|
|
122
|
+
placeholderPrompts: placeholderPrompts,
|
|
123
|
+
userHadTyped: userHadTyped,
|
|
124
|
+
canShowOnEmptyParagraph: true,
|
|
125
|
+
showOnEmptyParagraph: false,
|
|
126
|
+
pos: to
|
|
127
|
+
});
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
if (isEditorFocused && (0, _experiments.editorExperiment)('platform_editor_controls', 'variant1')) {
|
|
131
|
+
var _parentNode$firstChil, _parentNode$firstChil2;
|
|
132
|
+
var _editorState$selectio2 = editorState.selection,
|
|
133
|
+
$from = _editorState$selectio2.$from,
|
|
134
|
+
_$to = _editorState$selectio2.$to;
|
|
135
|
+
if ($from.pos !== _$to.pos) {
|
|
136
|
+
return emptyPlaceholder({
|
|
137
|
+
placeholderText: defaultPlaceholderText,
|
|
138
|
+
placeholderPrompts: placeholderPrompts,
|
|
139
|
+
userHadTyped: userHadTyped
|
|
140
|
+
});
|
|
141
|
+
}
|
|
142
|
+
var parentNode = $from.node($from.depth - 1);
|
|
143
|
+
var parentType = parentNode === null || parentNode === void 0 ? void 0 : parentNode.type.name;
|
|
144
|
+
if (emptyLinePlaceholder && parentType === 'doc') {
|
|
145
|
+
var isEmptyLine = (0, _utils.isEmptyParagraph)($from.parent);
|
|
146
|
+
if (isEmptyLine) {
|
|
147
|
+
return setPlaceHolderState({
|
|
148
|
+
placeholderText: emptyLinePlaceholder,
|
|
149
|
+
pos: $from.pos,
|
|
150
|
+
placeholderPrompts: placeholderPrompts,
|
|
151
|
+
typedAndDeleted: typedAndDeleted,
|
|
152
|
+
userHadTyped: userHadTyped
|
|
153
|
+
});
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
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';
|
|
157
|
+
if (_constants.nodeTypesWithShortPlaceholderText.includes(parentType) && isEmptyNode) {
|
|
158
|
+
var _table$node$firstChil;
|
|
159
|
+
var table = (0, _utils2.findParentNode)(function (node) {
|
|
160
|
+
return node.type === editorState.schema.nodes.table;
|
|
161
|
+
})(editorState.selection);
|
|
162
|
+
if (!table) {
|
|
163
|
+
return emptyPlaceholder({
|
|
164
|
+
placeholderText: defaultPlaceholderText,
|
|
165
|
+
placeholderPrompts: placeholderPrompts,
|
|
166
|
+
userHadTyped: userHadTyped
|
|
167
|
+
});
|
|
168
|
+
}
|
|
169
|
+
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;
|
|
170
|
+
if (isFirstCell) {
|
|
171
|
+
return setPlaceHolderState({
|
|
172
|
+
placeholderText: !(0, _platformFeatureFlags.fg)('platform_editor_ai_aifc_patch_ga') ? intl.formatMessage(_messages.placeholderTextMessages.shortEmptyNodePlaceholderText) : undefined,
|
|
173
|
+
contextPlaceholderADF: (0, _platformFeatureFlags.fg)('platform_editor_ai_aifc_patch_ga') ? (0, _adfBuilders.createShortEmptyNodePlaceholderADF)(intl) : undefined,
|
|
174
|
+
pos: $from.pos,
|
|
175
|
+
placeholderPrompts: placeholderPrompts,
|
|
176
|
+
typedAndDeleted: typedAndDeleted,
|
|
177
|
+
userHadTyped: userHadTyped
|
|
178
|
+
});
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
if (_constants.nodeTypesWithLongPlaceholderText.includes(parentType) && isEmptyNode) {
|
|
182
|
+
return setPlaceHolderState({
|
|
183
|
+
placeholderText: !(0, _platformFeatureFlags.fg)('platform_editor_ai_aifc_patch_ga') ? intl.formatMessage(_messages.placeholderTextMessages.longEmptyNodePlaceholderText) : undefined,
|
|
184
|
+
contextPlaceholderADF: (0, _platformFeatureFlags.fg)('platform_editor_ai_aifc_patch_ga') ? (0, _adfBuilders.createLongEmptyNodePlaceholderADF)(intl) : undefined,
|
|
185
|
+
pos: $from.pos,
|
|
186
|
+
placeholderPrompts: placeholderPrompts,
|
|
187
|
+
typedAndDeleted: typedAndDeleted,
|
|
188
|
+
userHadTyped: userHadTyped
|
|
189
|
+
});
|
|
190
|
+
}
|
|
191
|
+
if (_constants.nodeTypesWithSyncBlockPlaceholderText.includes(parentType) && isEmptyNode && (0, _experiments.editorExperiment)('platform_synced_block', true)) {
|
|
192
|
+
return setPlaceHolderState({
|
|
193
|
+
placeholderText: intl.formatMessage(_messages.placeholderTextMessages.syncBlockPlaceholderText),
|
|
194
|
+
pos: $from.pos,
|
|
195
|
+
placeholderPrompts: placeholderPrompts,
|
|
196
|
+
typedAndDeleted: typedAndDeleted,
|
|
197
|
+
userHadTyped: userHadTyped
|
|
198
|
+
});
|
|
199
|
+
}
|
|
200
|
+
return emptyPlaceholder({
|
|
201
|
+
placeholderText: defaultPlaceholderText,
|
|
202
|
+
placeholderPrompts: placeholderPrompts,
|
|
203
|
+
userHadTyped: userHadTyped
|
|
204
|
+
});
|
|
205
|
+
}
|
|
206
|
+
if (bracketPlaceholderText && (0, _utils.bracketTyped)(editorState) && isEditorFocused) {
|
|
207
|
+
var _$from = editorState.selection.$from;
|
|
208
|
+
// Space is to account for positioning of the bracket
|
|
209
|
+
var bracketHint = ' ' + bracketPlaceholderText;
|
|
210
|
+
return setPlaceHolderState({
|
|
211
|
+
placeholderText: bracketHint,
|
|
212
|
+
pos: _$from.pos - 1,
|
|
213
|
+
placeholderPrompts: placeholderPrompts,
|
|
214
|
+
typedAndDeleted: typedAndDeleted,
|
|
215
|
+
userHadTyped: userHadTyped
|
|
216
|
+
});
|
|
217
|
+
}
|
|
218
|
+
return emptyPlaceholder({
|
|
219
|
+
placeholderText: defaultPlaceholderText,
|
|
220
|
+
placeholderPrompts: placeholderPrompts,
|
|
221
|
+
userHadTyped: userHadTyped
|
|
222
|
+
});
|
|
223
|
+
}
|
|
224
|
+
function calculateUserInteractionState(_ref4) {
|
|
225
|
+
var placeholderState = _ref4.placeholderState,
|
|
226
|
+
oldEditorState = _ref4.oldEditorState,
|
|
227
|
+
newEditorState = _ref4.newEditorState;
|
|
228
|
+
var wasEmpty = oldEditorState ? (0, _utils.isEmptyDocument)(oldEditorState.doc) : true;
|
|
229
|
+
var isEmpty = (0, _utils.isEmptyDocument)(newEditorState.doc);
|
|
230
|
+
var hasEverTyped = Boolean(placeholderState === null || placeholderState === void 0 ? void 0 : placeholderState.userHadTyped) ||
|
|
231
|
+
// Previously typed
|
|
232
|
+
!wasEmpty ||
|
|
233
|
+
// Had content before
|
|
234
|
+
wasEmpty && !isEmpty; // Just added content
|
|
235
|
+
var justDeletedAll = hasEverTyped && isEmpty && !wasEmpty;
|
|
236
|
+
var isInTypedAndDeletedState = justDeletedAll || Boolean(placeholderState === null || placeholderState === void 0 ? void 0 : placeholderState.typedAndDeleted) && isEmpty;
|
|
237
|
+
// Only reset user interaction tracking when editor is cleanly empty
|
|
238
|
+
var shouldResetInteraction = isEmpty && !isInTypedAndDeletedState;
|
|
239
|
+
return {
|
|
240
|
+
userHadTyped: shouldResetInteraction ? false : hasEverTyped,
|
|
241
|
+
typedAndDeleted: isInTypedAndDeletedState
|
|
242
|
+
};
|
|
243
|
+
}
|