@atlaskit/editor-plugin-placeholder 2.0.9 → 2.0.10
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
CHANGED
|
@@ -1,5 +1,14 @@
|
|
|
1
1
|
# @atlaskit/editor-plugin-placeholder
|
|
2
2
|
|
|
3
|
+
## 2.0.10
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- [#135586](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/pull-requests/135586)
|
|
8
|
+
[`3aeba66081612`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/3aeba66081612) -
|
|
9
|
+
ED-26593 Add missing i18n for editor control
|
|
10
|
+
- Updated dependencies
|
|
11
|
+
|
|
3
12
|
## 2.0.9
|
|
4
13
|
|
|
5
14
|
### Patch Changes
|
|
@@ -6,6 +6,7 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
6
6
|
exports.createPlaceholderDecoration = createPlaceholderDecoration;
|
|
7
7
|
exports.createPlugin = createPlugin;
|
|
8
8
|
exports.pluginKey = exports.placeholderTestId = exports.placeholderPlugin = void 0;
|
|
9
|
+
var _messages = require("@atlaskit/editor-common/messages");
|
|
9
10
|
var _safePlugin = require("@atlaskit/editor-common/safe-plugin");
|
|
10
11
|
var _utils = require("@atlaskit/editor-common/utils");
|
|
11
12
|
var _state = require("@atlaskit/editor-prosemirror/state");
|
|
@@ -16,10 +17,6 @@ function getPlaceholderState(editorState) {
|
|
|
16
17
|
return pluginKey.getState(editorState);
|
|
17
18
|
}
|
|
18
19
|
var placeholderTestId = exports.placeholderTestId = 'placeholder-test-id';
|
|
19
|
-
|
|
20
|
-
// TODO: ED-26962 - Use i18n for new placeholders
|
|
21
|
-
var SHORT_NODE_PLACEHOLDER_TEXT = '/ to insert';
|
|
22
|
-
var NODE_PLACEHOLDER_TEXT = 'Type / to insert elements';
|
|
23
20
|
var nodeTypesWithLongPlaceholderText = ['expand', 'panel'];
|
|
24
21
|
var nodeTypesWithShortPlaceholderText = ['tableCell', 'tableHeader'];
|
|
25
22
|
function createPlaceholderDecoration(editorState, placeholderText) {
|
|
@@ -74,7 +71,14 @@ var emptyPlaceholder = function emptyPlaceholder(placeholderText) {
|
|
|
74
71
|
placeholderText: placeholderText
|
|
75
72
|
};
|
|
76
73
|
};
|
|
77
|
-
function createPlaceHolderStateFrom(
|
|
74
|
+
function createPlaceHolderStateFrom(_ref) {
|
|
75
|
+
var isEditorFocused = _ref.isEditorFocused,
|
|
76
|
+
editorState = _ref.editorState,
|
|
77
|
+
isTypeAheadOpen = _ref.isTypeAheadOpen,
|
|
78
|
+
defaultPlaceholderText = _ref.defaultPlaceholderText,
|
|
79
|
+
intl = _ref.intl,
|
|
80
|
+
bracketPlaceholderText = _ref.bracketPlaceholderText,
|
|
81
|
+
emptyLinePlaceholder = _ref.emptyLinePlaceholder;
|
|
78
82
|
if (isTypeAheadOpen !== null && isTypeAheadOpen !== void 0 && isTypeAheadOpen(editorState)) {
|
|
79
83
|
return emptyPlaceholder(defaultPlaceholderText);
|
|
80
84
|
}
|
|
@@ -99,10 +103,10 @@ function createPlaceHolderStateFrom(isEditorFocused, editorState, isTypeAheadOpe
|
|
|
99
103
|
}
|
|
100
104
|
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';
|
|
101
105
|
if (nodeTypesWithShortPlaceholderText.includes(parentType) && isEmptyNode) {
|
|
102
|
-
return setPlaceHolderState(
|
|
106
|
+
return setPlaceHolderState(intl.formatMessage(_messages.placeholderTextMessages.shortEmptyNodePlaceholderText), $from.pos);
|
|
103
107
|
}
|
|
104
108
|
if (nodeTypesWithLongPlaceholderText.includes(parentType) && isEmptyNode) {
|
|
105
|
-
return setPlaceHolderState(
|
|
109
|
+
return setPlaceHolderState(intl.formatMessage(_messages.placeholderTextMessages.longEmptyNodePlaceholderText), $from.pos);
|
|
106
110
|
}
|
|
107
111
|
return emptyPlaceholder(defaultPlaceholderText);
|
|
108
112
|
}
|
|
@@ -114,7 +118,7 @@ function createPlaceHolderStateFrom(isEditorFocused, editorState, isTypeAheadOpe
|
|
|
114
118
|
}
|
|
115
119
|
return emptyPlaceholder(defaultPlaceholderText);
|
|
116
120
|
}
|
|
117
|
-
function createPlugin(defaultPlaceholderText, bracketPlaceholderText, emptyLinePlaceholder, api) {
|
|
121
|
+
function createPlugin(intl, defaultPlaceholderText, bracketPlaceholderText, emptyLinePlaceholder, api) {
|
|
118
122
|
if (!defaultPlaceholderText && !bracketPlaceholderText) {
|
|
119
123
|
return;
|
|
120
124
|
}
|
|
@@ -123,7 +127,15 @@ function createPlugin(defaultPlaceholderText, bracketPlaceholderText, emptyLineP
|
|
|
123
127
|
state: {
|
|
124
128
|
init: function init(_, state) {
|
|
125
129
|
var _api$focus, _api$typeAhead;
|
|
126
|
-
return createPlaceHolderStateFrom(
|
|
130
|
+
return createPlaceHolderStateFrom({
|
|
131
|
+
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),
|
|
132
|
+
editorState: state,
|
|
133
|
+
isTypeAheadOpen: api === null || api === void 0 || (_api$typeAhead = api.typeAhead) === null || _api$typeAhead === void 0 ? void 0 : _api$typeAhead.actions.isOpen,
|
|
134
|
+
defaultPlaceholderText: defaultPlaceholderText,
|
|
135
|
+
bracketPlaceholderText: bracketPlaceholderText,
|
|
136
|
+
emptyLinePlaceholder: emptyLinePlaceholder,
|
|
137
|
+
intl: intl
|
|
138
|
+
});
|
|
127
139
|
},
|
|
128
140
|
apply: function apply(tr, placeholderState, _oldEditorState, newEditorState) {
|
|
129
141
|
var _api$focus2, _api$typeAhead3, _placeholderState$pla;
|
|
@@ -131,9 +143,25 @@ function createPlugin(defaultPlaceholderText, bracketPlaceholderText, emptyLineP
|
|
|
131
143
|
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);
|
|
132
144
|
if ((meta === null || meta === void 0 ? void 0 : meta.placeholderText) !== undefined) {
|
|
133
145
|
var _api$typeAhead2;
|
|
134
|
-
return createPlaceHolderStateFrom(
|
|
146
|
+
return createPlaceHolderStateFrom({
|
|
147
|
+
isEditorFocused: isEditorFocused,
|
|
148
|
+
editorState: newEditorState,
|
|
149
|
+
isTypeAheadOpen: api === null || api === void 0 || (_api$typeAhead2 = api.typeAhead) === null || _api$typeAhead2 === void 0 ? void 0 : _api$typeAhead2.actions.isOpen,
|
|
150
|
+
defaultPlaceholderText: meta.placeholderText,
|
|
151
|
+
bracketPlaceholderText: bracketPlaceholderText,
|
|
152
|
+
emptyLinePlaceholder: emptyLinePlaceholder,
|
|
153
|
+
intl: intl
|
|
154
|
+
});
|
|
135
155
|
}
|
|
136
|
-
return createPlaceHolderStateFrom(
|
|
156
|
+
return createPlaceHolderStateFrom({
|
|
157
|
+
isEditorFocused: isEditorFocused,
|
|
158
|
+
editorState: newEditorState,
|
|
159
|
+
isTypeAheadOpen: api === null || api === void 0 || (_api$typeAhead3 = api.typeAhead) === null || _api$typeAhead3 === void 0 ? void 0 : _api$typeAhead3.actions.isOpen,
|
|
160
|
+
defaultPlaceholderText: (_placeholderState$pla = placeholderState === null || placeholderState === void 0 ? void 0 : placeholderState.placeholderText) !== null && _placeholderState$pla !== void 0 ? _placeholderState$pla : defaultPlaceholderText,
|
|
161
|
+
bracketPlaceholderText: bracketPlaceholderText,
|
|
162
|
+
emptyLinePlaceholder: emptyLinePlaceholder,
|
|
163
|
+
intl: intl
|
|
164
|
+
});
|
|
137
165
|
}
|
|
138
166
|
},
|
|
139
167
|
props: {
|
|
@@ -152,16 +180,16 @@ function createPlugin(defaultPlaceholderText, bracketPlaceholderText, emptyLineP
|
|
|
152
180
|
}
|
|
153
181
|
});
|
|
154
182
|
}
|
|
155
|
-
var placeholderPlugin = exports.placeholderPlugin = function placeholderPlugin(
|
|
156
|
-
var options =
|
|
157
|
-
api =
|
|
183
|
+
var placeholderPlugin = exports.placeholderPlugin = function placeholderPlugin(_ref2) {
|
|
184
|
+
var options = _ref2.config,
|
|
185
|
+
api = _ref2.api;
|
|
158
186
|
var currentPlaceholder = options === null || options === void 0 ? void 0 : options.placeholder;
|
|
159
187
|
return {
|
|
160
188
|
name: 'placeholder',
|
|
161
189
|
commands: {
|
|
162
190
|
setPlaceholder: function setPlaceholder(placeholderText) {
|
|
163
|
-
return function (
|
|
164
|
-
var tr =
|
|
191
|
+
return function (_ref3) {
|
|
192
|
+
var tr = _ref3.tr;
|
|
165
193
|
if (currentPlaceholder !== placeholderText) {
|
|
166
194
|
currentPlaceholder = placeholderText;
|
|
167
195
|
return tr.setMeta(pluginKey, {
|
|
@@ -175,8 +203,9 @@ var placeholderPlugin = exports.placeholderPlugin = function placeholderPlugin(_
|
|
|
175
203
|
pmPlugins: function pmPlugins() {
|
|
176
204
|
return [{
|
|
177
205
|
name: 'placeholder',
|
|
178
|
-
plugin: function plugin() {
|
|
179
|
-
|
|
206
|
+
plugin: function plugin(_ref4) {
|
|
207
|
+
var getIntl = _ref4.getIntl;
|
|
208
|
+
return createPlugin(getIntl(), options && options.placeholder, options && options.placeholderBracketHint, options && options.emptyLinePlaceholder, api);
|
|
180
209
|
}
|
|
181
210
|
}];
|
|
182
211
|
}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { placeholderTextMessages as messages } from '@atlaskit/editor-common/messages';
|
|
1
2
|
import { SafePlugin } from '@atlaskit/editor-common/safe-plugin';
|
|
2
3
|
import { bracketTyped, browser, isEmptyDocument, isEmptyParagraph } from '@atlaskit/editor-common/utils';
|
|
3
4
|
import { PluginKey } from '@atlaskit/editor-prosemirror/state';
|
|
@@ -8,10 +9,6 @@ function getPlaceholderState(editorState) {
|
|
|
8
9
|
return pluginKey.getState(editorState);
|
|
9
10
|
}
|
|
10
11
|
export const placeholderTestId = 'placeholder-test-id';
|
|
11
|
-
|
|
12
|
-
// TODO: ED-26962 - Use i18n for new placeholders
|
|
13
|
-
const SHORT_NODE_PLACEHOLDER_TEXT = '/ to insert';
|
|
14
|
-
const NODE_PLACEHOLDER_TEXT = 'Type / to insert elements';
|
|
15
12
|
const nodeTypesWithLongPlaceholderText = ['expand', 'panel'];
|
|
16
13
|
const nodeTypesWithShortPlaceholderText = ['tableCell', 'tableHeader'];
|
|
17
14
|
export function createPlaceholderDecoration(editorState, placeholderText, pos = 1) {
|
|
@@ -63,7 +60,15 @@ const emptyPlaceholder = placeholderText => ({
|
|
|
63
60
|
hasPlaceholder: false,
|
|
64
61
|
placeholderText
|
|
65
62
|
});
|
|
66
|
-
function createPlaceHolderStateFrom(
|
|
63
|
+
function createPlaceHolderStateFrom({
|
|
64
|
+
isEditorFocused,
|
|
65
|
+
editorState,
|
|
66
|
+
isTypeAheadOpen,
|
|
67
|
+
defaultPlaceholderText,
|
|
68
|
+
intl,
|
|
69
|
+
bracketPlaceholderText,
|
|
70
|
+
emptyLinePlaceholder
|
|
71
|
+
}) {
|
|
67
72
|
if (isTypeAheadOpen !== null && isTypeAheadOpen !== void 0 && isTypeAheadOpen(editorState)) {
|
|
68
73
|
return emptyPlaceholder(defaultPlaceholderText);
|
|
69
74
|
}
|
|
@@ -89,10 +94,10 @@ function createPlaceHolderStateFrom(isEditorFocused, editorState, isTypeAheadOpe
|
|
|
89
94
|
}
|
|
90
95
|
const 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';
|
|
91
96
|
if (nodeTypesWithShortPlaceholderText.includes(parentType) && isEmptyNode) {
|
|
92
|
-
return setPlaceHolderState(
|
|
97
|
+
return setPlaceHolderState(intl.formatMessage(messages.shortEmptyNodePlaceholderText), $from.pos);
|
|
93
98
|
}
|
|
94
99
|
if (nodeTypesWithLongPlaceholderText.includes(parentType) && isEmptyNode) {
|
|
95
|
-
return setPlaceHolderState(
|
|
100
|
+
return setPlaceHolderState(intl.formatMessage(messages.longEmptyNodePlaceholderText), $from.pos);
|
|
96
101
|
}
|
|
97
102
|
return emptyPlaceholder(defaultPlaceholderText);
|
|
98
103
|
}
|
|
@@ -106,7 +111,7 @@ function createPlaceHolderStateFrom(isEditorFocused, editorState, isTypeAheadOpe
|
|
|
106
111
|
}
|
|
107
112
|
return emptyPlaceholder(defaultPlaceholderText);
|
|
108
113
|
}
|
|
109
|
-
export function createPlugin(defaultPlaceholderText, bracketPlaceholderText, emptyLinePlaceholder, api) {
|
|
114
|
+
export function createPlugin(intl, defaultPlaceholderText, bracketPlaceholderText, emptyLinePlaceholder, api) {
|
|
110
115
|
if (!defaultPlaceholderText && !bracketPlaceholderText) {
|
|
111
116
|
return;
|
|
112
117
|
}
|
|
@@ -115,7 +120,15 @@ export function createPlugin(defaultPlaceholderText, bracketPlaceholderText, emp
|
|
|
115
120
|
state: {
|
|
116
121
|
init: (_, state) => {
|
|
117
122
|
var _api$focus, _api$focus$sharedStat, _api$typeAhead;
|
|
118
|
-
return createPlaceHolderStateFrom(
|
|
123
|
+
return createPlaceHolderStateFrom({
|
|
124
|
+
isEditorFocused: Boolean(api === null || api === void 0 ? void 0 : (_api$focus = api.focus) === null || _api$focus === void 0 ? void 0 : (_api$focus$sharedStat = _api$focus.sharedState.currentState()) === null || _api$focus$sharedStat === void 0 ? void 0 : _api$focus$sharedStat.hasFocus),
|
|
125
|
+
editorState: state,
|
|
126
|
+
isTypeAheadOpen: api === null || api === void 0 ? void 0 : (_api$typeAhead = api.typeAhead) === null || _api$typeAhead === void 0 ? void 0 : _api$typeAhead.actions.isOpen,
|
|
127
|
+
defaultPlaceholderText,
|
|
128
|
+
bracketPlaceholderText,
|
|
129
|
+
emptyLinePlaceholder,
|
|
130
|
+
intl
|
|
131
|
+
});
|
|
119
132
|
},
|
|
120
133
|
apply: (tr, placeholderState, _oldEditorState, newEditorState) => {
|
|
121
134
|
var _api$focus2, _api$focus2$sharedSta, _api$typeAhead3, _placeholderState$pla;
|
|
@@ -123,9 +136,25 @@ export function createPlugin(defaultPlaceholderText, bracketPlaceholderText, emp
|
|
|
123
136
|
const isEditorFocused = Boolean(api === null || api === void 0 ? void 0 : (_api$focus2 = api.focus) === null || _api$focus2 === void 0 ? void 0 : (_api$focus2$sharedSta = _api$focus2.sharedState.currentState()) === null || _api$focus2$sharedSta === void 0 ? void 0 : _api$focus2$sharedSta.hasFocus);
|
|
124
137
|
if ((meta === null || meta === void 0 ? void 0 : meta.placeholderText) !== undefined) {
|
|
125
138
|
var _api$typeAhead2;
|
|
126
|
-
return createPlaceHolderStateFrom(
|
|
139
|
+
return createPlaceHolderStateFrom({
|
|
140
|
+
isEditorFocused,
|
|
141
|
+
editorState: newEditorState,
|
|
142
|
+
isTypeAheadOpen: api === null || api === void 0 ? void 0 : (_api$typeAhead2 = api.typeAhead) === null || _api$typeAhead2 === void 0 ? void 0 : _api$typeAhead2.actions.isOpen,
|
|
143
|
+
defaultPlaceholderText: meta.placeholderText,
|
|
144
|
+
bracketPlaceholderText,
|
|
145
|
+
emptyLinePlaceholder,
|
|
146
|
+
intl
|
|
147
|
+
});
|
|
127
148
|
}
|
|
128
|
-
return createPlaceHolderStateFrom(
|
|
149
|
+
return createPlaceHolderStateFrom({
|
|
150
|
+
isEditorFocused,
|
|
151
|
+
editorState: newEditorState,
|
|
152
|
+
isTypeAheadOpen: api === null || api === void 0 ? void 0 : (_api$typeAhead3 = api.typeAhead) === null || _api$typeAhead3 === void 0 ? void 0 : _api$typeAhead3.actions.isOpen,
|
|
153
|
+
defaultPlaceholderText: (_placeholderState$pla = placeholderState === null || placeholderState === void 0 ? void 0 : placeholderState.placeholderText) !== null && _placeholderState$pla !== void 0 ? _placeholderState$pla : defaultPlaceholderText,
|
|
154
|
+
bracketPlaceholderText,
|
|
155
|
+
emptyLinePlaceholder,
|
|
156
|
+
intl
|
|
157
|
+
});
|
|
129
158
|
}
|
|
130
159
|
},
|
|
131
160
|
props: {
|
|
@@ -168,7 +197,9 @@ export const placeholderPlugin = ({
|
|
|
168
197
|
pmPlugins() {
|
|
169
198
|
return [{
|
|
170
199
|
name: 'placeholder',
|
|
171
|
-
plugin: (
|
|
200
|
+
plugin: ({
|
|
201
|
+
getIntl
|
|
202
|
+
}) => createPlugin(getIntl(), options && options.placeholder, options && options.placeholderBracketHint, options && options.emptyLinePlaceholder, api)
|
|
172
203
|
}];
|
|
173
204
|
}
|
|
174
205
|
};
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { placeholderTextMessages as messages } from '@atlaskit/editor-common/messages';
|
|
1
2
|
import { SafePlugin } from '@atlaskit/editor-common/safe-plugin';
|
|
2
3
|
import { bracketTyped, browser, isEmptyDocument, isEmptyParagraph } from '@atlaskit/editor-common/utils';
|
|
3
4
|
import { PluginKey } from '@atlaskit/editor-prosemirror/state';
|
|
@@ -8,10 +9,6 @@ function getPlaceholderState(editorState) {
|
|
|
8
9
|
return pluginKey.getState(editorState);
|
|
9
10
|
}
|
|
10
11
|
export var placeholderTestId = 'placeholder-test-id';
|
|
11
|
-
|
|
12
|
-
// TODO: ED-26962 - Use i18n for new placeholders
|
|
13
|
-
var SHORT_NODE_PLACEHOLDER_TEXT = '/ to insert';
|
|
14
|
-
var NODE_PLACEHOLDER_TEXT = 'Type / to insert elements';
|
|
15
12
|
var nodeTypesWithLongPlaceholderText = ['expand', 'panel'];
|
|
16
13
|
var nodeTypesWithShortPlaceholderText = ['tableCell', 'tableHeader'];
|
|
17
14
|
export function createPlaceholderDecoration(editorState, placeholderText) {
|
|
@@ -66,7 +63,14 @@ var emptyPlaceholder = function emptyPlaceholder(placeholderText) {
|
|
|
66
63
|
placeholderText: placeholderText
|
|
67
64
|
};
|
|
68
65
|
};
|
|
69
|
-
function createPlaceHolderStateFrom(
|
|
66
|
+
function createPlaceHolderStateFrom(_ref) {
|
|
67
|
+
var isEditorFocused = _ref.isEditorFocused,
|
|
68
|
+
editorState = _ref.editorState,
|
|
69
|
+
isTypeAheadOpen = _ref.isTypeAheadOpen,
|
|
70
|
+
defaultPlaceholderText = _ref.defaultPlaceholderText,
|
|
71
|
+
intl = _ref.intl,
|
|
72
|
+
bracketPlaceholderText = _ref.bracketPlaceholderText,
|
|
73
|
+
emptyLinePlaceholder = _ref.emptyLinePlaceholder;
|
|
70
74
|
if (isTypeAheadOpen !== null && isTypeAheadOpen !== void 0 && isTypeAheadOpen(editorState)) {
|
|
71
75
|
return emptyPlaceholder(defaultPlaceholderText);
|
|
72
76
|
}
|
|
@@ -91,10 +95,10 @@ function createPlaceHolderStateFrom(isEditorFocused, editorState, isTypeAheadOpe
|
|
|
91
95
|
}
|
|
92
96
|
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';
|
|
93
97
|
if (nodeTypesWithShortPlaceholderText.includes(parentType) && isEmptyNode) {
|
|
94
|
-
return setPlaceHolderState(
|
|
98
|
+
return setPlaceHolderState(intl.formatMessage(messages.shortEmptyNodePlaceholderText), $from.pos);
|
|
95
99
|
}
|
|
96
100
|
if (nodeTypesWithLongPlaceholderText.includes(parentType) && isEmptyNode) {
|
|
97
|
-
return setPlaceHolderState(
|
|
101
|
+
return setPlaceHolderState(intl.formatMessage(messages.longEmptyNodePlaceholderText), $from.pos);
|
|
98
102
|
}
|
|
99
103
|
return emptyPlaceholder(defaultPlaceholderText);
|
|
100
104
|
}
|
|
@@ -106,7 +110,7 @@ function createPlaceHolderStateFrom(isEditorFocused, editorState, isTypeAheadOpe
|
|
|
106
110
|
}
|
|
107
111
|
return emptyPlaceholder(defaultPlaceholderText);
|
|
108
112
|
}
|
|
109
|
-
export function createPlugin(defaultPlaceholderText, bracketPlaceholderText, emptyLinePlaceholder, api) {
|
|
113
|
+
export function createPlugin(intl, defaultPlaceholderText, bracketPlaceholderText, emptyLinePlaceholder, api) {
|
|
110
114
|
if (!defaultPlaceholderText && !bracketPlaceholderText) {
|
|
111
115
|
return;
|
|
112
116
|
}
|
|
@@ -115,7 +119,15 @@ export function createPlugin(defaultPlaceholderText, bracketPlaceholderText, emp
|
|
|
115
119
|
state: {
|
|
116
120
|
init: function init(_, state) {
|
|
117
121
|
var _api$focus, _api$typeAhead;
|
|
118
|
-
return createPlaceHolderStateFrom(
|
|
122
|
+
return createPlaceHolderStateFrom({
|
|
123
|
+
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),
|
|
124
|
+
editorState: state,
|
|
125
|
+
isTypeAheadOpen: api === null || api === void 0 || (_api$typeAhead = api.typeAhead) === null || _api$typeAhead === void 0 ? void 0 : _api$typeAhead.actions.isOpen,
|
|
126
|
+
defaultPlaceholderText: defaultPlaceholderText,
|
|
127
|
+
bracketPlaceholderText: bracketPlaceholderText,
|
|
128
|
+
emptyLinePlaceholder: emptyLinePlaceholder,
|
|
129
|
+
intl: intl
|
|
130
|
+
});
|
|
119
131
|
},
|
|
120
132
|
apply: function apply(tr, placeholderState, _oldEditorState, newEditorState) {
|
|
121
133
|
var _api$focus2, _api$typeAhead3, _placeholderState$pla;
|
|
@@ -123,9 +135,25 @@ export function createPlugin(defaultPlaceholderText, bracketPlaceholderText, emp
|
|
|
123
135
|
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);
|
|
124
136
|
if ((meta === null || meta === void 0 ? void 0 : meta.placeholderText) !== undefined) {
|
|
125
137
|
var _api$typeAhead2;
|
|
126
|
-
return createPlaceHolderStateFrom(
|
|
138
|
+
return createPlaceHolderStateFrom({
|
|
139
|
+
isEditorFocused: isEditorFocused,
|
|
140
|
+
editorState: newEditorState,
|
|
141
|
+
isTypeAheadOpen: api === null || api === void 0 || (_api$typeAhead2 = api.typeAhead) === null || _api$typeAhead2 === void 0 ? void 0 : _api$typeAhead2.actions.isOpen,
|
|
142
|
+
defaultPlaceholderText: meta.placeholderText,
|
|
143
|
+
bracketPlaceholderText: bracketPlaceholderText,
|
|
144
|
+
emptyLinePlaceholder: emptyLinePlaceholder,
|
|
145
|
+
intl: intl
|
|
146
|
+
});
|
|
127
147
|
}
|
|
128
|
-
return createPlaceHolderStateFrom(
|
|
148
|
+
return createPlaceHolderStateFrom({
|
|
149
|
+
isEditorFocused: isEditorFocused,
|
|
150
|
+
editorState: newEditorState,
|
|
151
|
+
isTypeAheadOpen: api === null || api === void 0 || (_api$typeAhead3 = api.typeAhead) === null || _api$typeAhead3 === void 0 ? void 0 : _api$typeAhead3.actions.isOpen,
|
|
152
|
+
defaultPlaceholderText: (_placeholderState$pla = placeholderState === null || placeholderState === void 0 ? void 0 : placeholderState.placeholderText) !== null && _placeholderState$pla !== void 0 ? _placeholderState$pla : defaultPlaceholderText,
|
|
153
|
+
bracketPlaceholderText: bracketPlaceholderText,
|
|
154
|
+
emptyLinePlaceholder: emptyLinePlaceholder,
|
|
155
|
+
intl: intl
|
|
156
|
+
});
|
|
129
157
|
}
|
|
130
158
|
},
|
|
131
159
|
props: {
|
|
@@ -144,16 +172,16 @@ export function createPlugin(defaultPlaceholderText, bracketPlaceholderText, emp
|
|
|
144
172
|
}
|
|
145
173
|
});
|
|
146
174
|
}
|
|
147
|
-
export var placeholderPlugin = function placeholderPlugin(
|
|
148
|
-
var options =
|
|
149
|
-
api =
|
|
175
|
+
export var placeholderPlugin = function placeholderPlugin(_ref2) {
|
|
176
|
+
var options = _ref2.config,
|
|
177
|
+
api = _ref2.api;
|
|
150
178
|
var currentPlaceholder = options === null || options === void 0 ? void 0 : options.placeholder;
|
|
151
179
|
return {
|
|
152
180
|
name: 'placeholder',
|
|
153
181
|
commands: {
|
|
154
182
|
setPlaceholder: function setPlaceholder(placeholderText) {
|
|
155
|
-
return function (
|
|
156
|
-
var tr =
|
|
183
|
+
return function (_ref3) {
|
|
184
|
+
var tr = _ref3.tr;
|
|
157
185
|
if (currentPlaceholder !== placeholderText) {
|
|
158
186
|
currentPlaceholder = placeholderText;
|
|
159
187
|
return tr.setMeta(pluginKey, {
|
|
@@ -167,8 +195,9 @@ export var placeholderPlugin = function placeholderPlugin(_ref) {
|
|
|
167
195
|
pmPlugins: function pmPlugins() {
|
|
168
196
|
return [{
|
|
169
197
|
name: 'placeholder',
|
|
170
|
-
plugin: function plugin() {
|
|
171
|
-
|
|
198
|
+
plugin: function plugin(_ref4) {
|
|
199
|
+
var getIntl = _ref4.getIntl;
|
|
200
|
+
return createPlugin(getIntl(), options && options.placeholder, options && options.placeholderBracketHint, options && options.emptyLinePlaceholder, api);
|
|
172
201
|
}
|
|
173
202
|
}];
|
|
174
203
|
}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { IntlShape } from 'react-intl-next';
|
|
1
2
|
import { SafePlugin } from '@atlaskit/editor-common/safe-plugin';
|
|
2
3
|
import type { ExtractInjectionAPI } from '@atlaskit/editor-common/types';
|
|
3
4
|
import type { EditorState } from '@atlaskit/editor-prosemirror/state';
|
|
@@ -7,5 +8,5 @@ import type { PlaceholderPlugin } from './placeholderPluginType';
|
|
|
7
8
|
export declare const pluginKey: PluginKey<any>;
|
|
8
9
|
export declare const placeholderTestId = "placeholder-test-id";
|
|
9
10
|
export declare function createPlaceholderDecoration(editorState: EditorState, placeholderText: string, pos?: number): DecorationSet;
|
|
10
|
-
export declare function createPlugin(defaultPlaceholderText?: string, bracketPlaceholderText?: string, emptyLinePlaceholder?: string, api?: ExtractInjectionAPI<PlaceholderPlugin>): SafePlugin | undefined;
|
|
11
|
+
export declare function createPlugin(intl: IntlShape, defaultPlaceholderText?: string, bracketPlaceholderText?: string, emptyLinePlaceholder?: string, api?: ExtractInjectionAPI<PlaceholderPlugin>): SafePlugin | undefined;
|
|
11
12
|
export declare const placeholderPlugin: PlaceholderPlugin;
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { IntlShape } from 'react-intl-next';
|
|
1
2
|
import { SafePlugin } from '@atlaskit/editor-common/safe-plugin';
|
|
2
3
|
import type { ExtractInjectionAPI } from '@atlaskit/editor-common/types';
|
|
3
4
|
import type { EditorState } from '@atlaskit/editor-prosemirror/state';
|
|
@@ -7,5 +8,5 @@ import type { PlaceholderPlugin } from './placeholderPluginType';
|
|
|
7
8
|
export declare const pluginKey: PluginKey<any>;
|
|
8
9
|
export declare const placeholderTestId = "placeholder-test-id";
|
|
9
10
|
export declare function createPlaceholderDecoration(editorState: EditorState, placeholderText: string, pos?: number): DecorationSet;
|
|
10
|
-
export declare function createPlugin(defaultPlaceholderText?: string, bracketPlaceholderText?: string, emptyLinePlaceholder?: string, api?: ExtractInjectionAPI<PlaceholderPlugin>): SafePlugin | undefined;
|
|
11
|
+
export declare function createPlugin(intl: IntlShape, defaultPlaceholderText?: string, bracketPlaceholderText?: string, emptyLinePlaceholder?: string, api?: ExtractInjectionAPI<PlaceholderPlugin>): SafePlugin | undefined;
|
|
11
12
|
export declare const placeholderPlugin: PlaceholderPlugin;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@atlaskit/editor-plugin-placeholder",
|
|
3
|
-
"version": "2.0.
|
|
3
|
+
"version": "2.0.10",
|
|
4
4
|
"description": "Placeholder plugin for @atlaskit/editor-core.",
|
|
5
5
|
"author": "Atlassian Pty Ltd",
|
|
6
6
|
"license": "Apache-2.0",
|
|
@@ -31,17 +31,18 @@
|
|
|
31
31
|
".": "./src/index.ts"
|
|
32
32
|
},
|
|
33
33
|
"dependencies": {
|
|
34
|
-
"@atlaskit/editor-common": "^102.
|
|
34
|
+
"@atlaskit/editor-common": "^102.18.0",
|
|
35
35
|
"@atlaskit/editor-plugin-composition": "^1.3.0",
|
|
36
36
|
"@atlaskit/editor-plugin-focus": "^1.5.0",
|
|
37
|
-
"@atlaskit/editor-plugin-type-ahead": "^2.
|
|
37
|
+
"@atlaskit/editor-plugin-type-ahead": "^2.3.0",
|
|
38
38
|
"@atlaskit/editor-prosemirror": "7.0.0",
|
|
39
|
-
"@atlaskit/tmp-editor-statsig": "^4.
|
|
39
|
+
"@atlaskit/tmp-editor-statsig": "^4.6.0",
|
|
40
40
|
"@babel/runtime": "^7.0.0"
|
|
41
41
|
},
|
|
42
42
|
"peerDependencies": {
|
|
43
43
|
"react": "^18.2.0",
|
|
44
|
-
"react-dom": "^18.2.0"
|
|
44
|
+
"react-dom": "^18.2.0",
|
|
45
|
+
"react-intl-next": "npm:react-intl@^5.18.1"
|
|
45
46
|
},
|
|
46
47
|
"devDependencies": {
|
|
47
48
|
"@testing-library/react": "^13.4.0",
|