@atlaskit/editor-core 189.0.1 → 189.0.4
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 +12 -0
- package/dist/cjs/plugins/index.js +2 -2
- package/dist/cjs/plugins/placeholder-text/index.js +6 -240
- package/dist/cjs/plugins/placeholder-text/plugin.js +266 -0
- package/dist/cjs/{ui → plugins/placeholder-text/ui}/FloatingToolbar/styles.js +1 -1
- package/dist/cjs/plugins/placeholder-text/ui/PlaceholderFloatingToolbar/index.js +1 -1
- package/dist/cjs/version-wrapper.js +1 -1
- package/dist/es2019/plugins/index.js +1 -1
- package/dist/es2019/plugins/placeholder-text/index.js +1 -224
- package/dist/es2019/plugins/placeholder-text/plugin.js +246 -0
- package/dist/es2019/{ui → plugins/placeholder-text/ui}/FloatingToolbar/styles.js +1 -1
- package/dist/es2019/plugins/placeholder-text/ui/PlaceholderFloatingToolbar/index.js +1 -1
- package/dist/es2019/version-wrapper.js +1 -1
- package/dist/esm/plugins/index.js +1 -1
- package/dist/esm/plugins/placeholder-text/index.js +1 -239
- package/dist/esm/plugins/placeholder-text/plugin.js +258 -0
- package/dist/esm/{ui → plugins/placeholder-text/ui}/FloatingToolbar/styles.js +1 -1
- package/dist/esm/plugins/placeholder-text/ui/PlaceholderFloatingToolbar/index.js +1 -1
- package/dist/esm/version-wrapper.js +1 -1
- package/dist/types/plugins/index.d.ts +1 -1
- package/dist/types/plugins/placeholder-text/index.d.ts +2 -16
- package/dist/types/plugins/placeholder-text/placeholder-text-nodeview.d.ts +1 -1
- package/dist/types/plugins/placeholder-text/plugin-key.d.ts +2 -2
- package/dist/types/plugins/placeholder-text/plugin.d.ts +7 -0
- package/dist/types/plugins/placeholder-text/types.d.ts +9 -1
- package/dist/types/plugins/placeholder-text/ui/PlaceholderFloatingToolbar/index.d.ts +2 -2
- package/dist/types/ui/ConfigPanel/ConfigPanel.d.ts +1 -1
- package/dist/types-ts4.5/plugins/index.d.ts +1 -1
- package/dist/types-ts4.5/plugins/placeholder-text/index.d.ts +2 -22
- package/dist/types-ts4.5/plugins/placeholder-text/placeholder-text-nodeview.d.ts +1 -1
- package/dist/types-ts4.5/plugins/placeholder-text/plugin-key.d.ts +2 -2
- package/dist/types-ts4.5/plugins/placeholder-text/plugin.d.ts +7 -0
- package/dist/types-ts4.5/plugins/placeholder-text/types.d.ts +12 -1
- package/dist/types-ts4.5/plugins/placeholder-text/ui/PlaceholderFloatingToolbar/index.d.ts +2 -2
- package/dist/types-ts4.5/ui/ConfigPanel/ConfigPanel.d.ts +1 -1
- package/package.json +7 -3
- /package/dist/cjs/{ui → plugins/placeholder-text/ui}/FloatingToolbar/index.js +0 -0
- /package/dist/cjs/{ui → plugins/placeholder-text/ui}/FloatingToolbar/utils.js +0 -0
- /package/dist/es2019/{ui → plugins/placeholder-text/ui}/FloatingToolbar/index.js +0 -0
- /package/dist/es2019/{ui → plugins/placeholder-text/ui}/FloatingToolbar/utils.js +0 -0
- /package/dist/esm/{ui → plugins/placeholder-text/ui}/FloatingToolbar/index.js +0 -0
- /package/dist/esm/{ui → plugins/placeholder-text/ui}/FloatingToolbar/utils.js +0 -0
- /package/dist/types/{ui → plugins/placeholder-text/ui}/FloatingToolbar/index.d.ts +0 -0
- /package/dist/types/{ui → plugins/placeholder-text/ui}/FloatingToolbar/styles.d.ts +0 -0
- /package/dist/types/{ui → plugins/placeholder-text/ui}/FloatingToolbar/utils.d.ts +0 -0
- /package/dist/types-ts4.5/{ui → plugins/placeholder-text/ui}/FloatingToolbar/index.d.ts +0 -0
- /package/dist/types-ts4.5/{ui → plugins/placeholder-text/ui}/FloatingToolbar/styles.d.ts +0 -0
- /package/dist/types-ts4.5/{ui → plugins/placeholder-text/ui}/FloatingToolbar/utils.d.ts +0 -0
|
@@ -1,224 +1 @@
|
|
|
1
|
-
|
|
2
|
-
import { SafePlugin } from '@atlaskit/editor-common/safe-plugin';
|
|
3
|
-
import { NodeSelection, TextSelection } from '@atlaskit/editor-prosemirror/state';
|
|
4
|
-
import { placeholder } from '@atlaskit/adf-schema';
|
|
5
|
-
import MediaServicesTextIcon from '@atlaskit/icon/glyph/media-services/text';
|
|
6
|
-
import WithPluginState from '../../ui/WithPluginState';
|
|
7
|
-
import { isNodeEmpty } from '@atlaskit/editor-common/utils';
|
|
8
|
-
import { FakeTextCursorSelection } from '../fake-text-cursor/cursor';
|
|
9
|
-
import PlaceholderFloatingToolbar from './ui/PlaceholderFloatingToolbar';
|
|
10
|
-
import { hidePlaceholderFloatingToolbar, insertPlaceholderTextAtSelection } from './actions';
|
|
11
|
-
import { PlaceholderTextNodeView } from './placeholder-text-nodeview';
|
|
12
|
-
import { pluginKey } from './plugin-key';
|
|
13
|
-
import { ACTION, ACTION_SUBJECT, ACTION_SUBJECT_ID, EVENT_TYPE, INPUT_METHOD } from '@atlaskit/editor-common/analytics';
|
|
14
|
-
import { messages } from '../insert-block/ui/ToolbarInsertBlock/messages';
|
|
15
|
-
import { isSelectionAtPlaceholder } from './selection-utils';
|
|
16
|
-
const getOpenTypeAhead = (trigger, api) => {
|
|
17
|
-
var _api$typeAhead, _api$typeAhead$action, _api$typeAhead2, _api$typeAhead2$actio;
|
|
18
|
-
const typeAheadHandler = api === null || api === void 0 ? void 0 : (_api$typeAhead = api.typeAhead) === null || _api$typeAhead === void 0 ? void 0 : (_api$typeAhead$action = _api$typeAhead.actions) === null || _api$typeAhead$action === void 0 ? void 0 : _api$typeAhead$action.findHandlerByTrigger(trigger);
|
|
19
|
-
if (!typeAheadHandler || !typeAheadHandler.id) {
|
|
20
|
-
return null;
|
|
21
|
-
}
|
|
22
|
-
return api === null || api === void 0 ? void 0 : (_api$typeAhead2 = api.typeAhead) === null || _api$typeAhead2 === void 0 ? void 0 : (_api$typeAhead2$actio = _api$typeAhead2.actions) === null || _api$typeAhead2$actio === void 0 ? void 0 : _api$typeAhead2$actio.openAtTransaction({
|
|
23
|
-
triggerHandler: typeAheadHandler,
|
|
24
|
-
inputMethod: INPUT_METHOD.KEYBOARD
|
|
25
|
-
});
|
|
26
|
-
};
|
|
27
|
-
export function createPlugin(dispatch, options, api) {
|
|
28
|
-
const allowInserting = !!options.allowInserting;
|
|
29
|
-
return new SafePlugin({
|
|
30
|
-
key: pluginKey,
|
|
31
|
-
state: {
|
|
32
|
-
init: () => ({
|
|
33
|
-
showInsertPanelAt: null,
|
|
34
|
-
allowInserting
|
|
35
|
-
}),
|
|
36
|
-
apply: (tr, state) => {
|
|
37
|
-
const meta = tr.getMeta(pluginKey);
|
|
38
|
-
if (meta && meta.showInsertPanelAt !== undefined) {
|
|
39
|
-
const newState = {
|
|
40
|
-
showInsertPanelAt: meta.showInsertPanelAt,
|
|
41
|
-
allowInserting
|
|
42
|
-
};
|
|
43
|
-
dispatch(pluginKey, newState);
|
|
44
|
-
return newState;
|
|
45
|
-
} else if (state.showInsertPanelAt) {
|
|
46
|
-
const newState = {
|
|
47
|
-
showInsertPanelAt: tr.mapping.map(state.showInsertPanelAt),
|
|
48
|
-
allowInserting
|
|
49
|
-
};
|
|
50
|
-
dispatch(pluginKey, newState);
|
|
51
|
-
return newState;
|
|
52
|
-
}
|
|
53
|
-
return state;
|
|
54
|
-
}
|
|
55
|
-
},
|
|
56
|
-
appendTransaction(transactions, oldState, newState) {
|
|
57
|
-
if (transactions.some(txn => txn.docChanged)) {
|
|
58
|
-
const didPlaceholderExistBeforeTxn = oldState.selection.$head.nodeAfter === newState.selection.$head.nodeAfter;
|
|
59
|
-
const adjacentNode = newState.selection.$head.nodeAfter;
|
|
60
|
-
const adjacentNodePos = newState.selection.$head.pos;
|
|
61
|
-
const placeholderNodeType = newState.schema.nodes.placeholder;
|
|
62
|
-
if (adjacentNode && adjacentNode.type === placeholderNodeType && didPlaceholderExistBeforeTxn) {
|
|
63
|
-
var _$newHead$nodeBefore;
|
|
64
|
-
const {
|
|
65
|
-
$head: $newHead
|
|
66
|
-
} = newState.selection;
|
|
67
|
-
const {
|
|
68
|
-
$head: $oldHead
|
|
69
|
-
} = oldState.selection;
|
|
70
|
-
// Check that cursor has moved forward in the document **and** that there is content before the cursor
|
|
71
|
-
const cursorMoved = $oldHead.pos < $newHead.pos;
|
|
72
|
-
const nodeBeforeHasContent = !isNodeEmpty($newHead.nodeBefore);
|
|
73
|
-
const nodeBeforeIsInline = (_$newHead$nodeBefore = $newHead.nodeBefore) === null || _$newHead$nodeBefore === void 0 ? void 0 : _$newHead$nodeBefore.type.isInline;
|
|
74
|
-
if (cursorMoved && (nodeBeforeHasContent || nodeBeforeIsInline)) {
|
|
75
|
-
const {
|
|
76
|
-
$from,
|
|
77
|
-
$to
|
|
78
|
-
} = NodeSelection.create(newState.doc, adjacentNodePos);
|
|
79
|
-
return newState.tr.deleteRange($from.pos, $to.pos);
|
|
80
|
-
}
|
|
81
|
-
}
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
// Handle Fake Text Cursor for Floating Toolbar
|
|
85
|
-
if (!pluginKey.getState(oldState).showInsertPanelAt && pluginKey.getState(newState).showInsertPanelAt) {
|
|
86
|
-
return newState.tr.setSelection(new FakeTextCursorSelection(newState.selection.$from));
|
|
87
|
-
}
|
|
88
|
-
if (pluginKey.getState(oldState).showInsertPanelAt && !pluginKey.getState(newState).showInsertPanelAt) {
|
|
89
|
-
if (newState.selection instanceof FakeTextCursorSelection) {
|
|
90
|
-
return newState.tr.setSelection(new TextSelection(newState.selection.$from));
|
|
91
|
-
}
|
|
92
|
-
}
|
|
93
|
-
return;
|
|
94
|
-
},
|
|
95
|
-
props: {
|
|
96
|
-
handleDOMEvents: {
|
|
97
|
-
beforeinput: (view, event) => {
|
|
98
|
-
const {
|
|
99
|
-
state
|
|
100
|
-
} = view;
|
|
101
|
-
if (event instanceof InputEvent && !event.isComposing && event.inputType === 'insertText' && isSelectionAtPlaceholder(view.state.selection)) {
|
|
102
|
-
event.stopPropagation();
|
|
103
|
-
event.preventDefault();
|
|
104
|
-
const startNodePosition = state.selection.from;
|
|
105
|
-
const content = event.data || '';
|
|
106
|
-
const tr = view.state.tr;
|
|
107
|
-
tr.delete(startNodePosition, startNodePosition + 1);
|
|
108
|
-
const openTypeAhead = getOpenTypeAhead(content, api);
|
|
109
|
-
if (openTypeAhead) {
|
|
110
|
-
openTypeAhead(tr);
|
|
111
|
-
} else {
|
|
112
|
-
tr.insertText(content);
|
|
113
|
-
}
|
|
114
|
-
view.dispatch(tr);
|
|
115
|
-
return true;
|
|
116
|
-
}
|
|
117
|
-
return false;
|
|
118
|
-
}
|
|
119
|
-
},
|
|
120
|
-
nodeViews: {
|
|
121
|
-
placeholder: (node, view, getPos) => new PlaceholderTextNodeView(node, view, getPos)
|
|
122
|
-
}
|
|
123
|
-
}
|
|
124
|
-
});
|
|
125
|
-
}
|
|
126
|
-
const basePlaceholderTextPlugin = ({
|
|
127
|
-
api,
|
|
128
|
-
config: options
|
|
129
|
-
}) => ({
|
|
130
|
-
name: 'placeholderText',
|
|
131
|
-
nodes() {
|
|
132
|
-
return [{
|
|
133
|
-
name: 'placeholder',
|
|
134
|
-
node: placeholder
|
|
135
|
-
}];
|
|
136
|
-
},
|
|
137
|
-
pmPlugins() {
|
|
138
|
-
return [{
|
|
139
|
-
name: 'placeholderText',
|
|
140
|
-
plugin: ({
|
|
141
|
-
dispatch
|
|
142
|
-
}) => createPlugin(dispatch, options, api)
|
|
143
|
-
}];
|
|
144
|
-
},
|
|
145
|
-
contentComponent({
|
|
146
|
-
editorView,
|
|
147
|
-
popupsMountPoint,
|
|
148
|
-
popupsBoundariesElement
|
|
149
|
-
}) {
|
|
150
|
-
const insertPlaceholderText = value => insertPlaceholderTextAtSelection(value)(editorView.state, editorView.dispatch);
|
|
151
|
-
const hidePlaceholderToolbar = () => hidePlaceholderFloatingToolbar(editorView.state, editorView.dispatch);
|
|
152
|
-
const getNodeFromPos = pos => editorView.domAtPos(pos).node;
|
|
153
|
-
const getFixedCoordinatesFromPos = pos => editorView.coordsAtPos(pos);
|
|
154
|
-
const setFocusInEditor = () => editorView.focus();
|
|
155
|
-
return /*#__PURE__*/React.createElement(WithPluginState, {
|
|
156
|
-
plugins: {
|
|
157
|
-
placeholderTextState: pluginKey
|
|
158
|
-
},
|
|
159
|
-
render: ({
|
|
160
|
-
placeholderTextState = {}
|
|
161
|
-
}) => {
|
|
162
|
-
if (placeholderTextState.showInsertPanelAt) {
|
|
163
|
-
return /*#__PURE__*/React.createElement(PlaceholderFloatingToolbar, {
|
|
164
|
-
editorViewDOM: editorView.dom,
|
|
165
|
-
popupsMountPoint: popupsMountPoint,
|
|
166
|
-
popupsBoundariesElement: popupsBoundariesElement,
|
|
167
|
-
getFixedCoordinatesFromPos: getFixedCoordinatesFromPos,
|
|
168
|
-
getNodeFromPos: getNodeFromPos,
|
|
169
|
-
hidePlaceholderFloatingToolbar: hidePlaceholderToolbar,
|
|
170
|
-
showInsertPanelAt: placeholderTextState.showInsertPanelAt,
|
|
171
|
-
insertPlaceholder: insertPlaceholderText,
|
|
172
|
-
setFocusInEditor: setFocusInEditor
|
|
173
|
-
});
|
|
174
|
-
}
|
|
175
|
-
return null;
|
|
176
|
-
}
|
|
177
|
-
});
|
|
178
|
-
}
|
|
179
|
-
});
|
|
180
|
-
const decorateWithPluginOptions = (plugin, options, api) => {
|
|
181
|
-
if (!options.allowInserting) {
|
|
182
|
-
return plugin;
|
|
183
|
-
}
|
|
184
|
-
plugin.pluginsOptions = {
|
|
185
|
-
quickInsert: ({
|
|
186
|
-
formatMessage
|
|
187
|
-
}) => [{
|
|
188
|
-
id: 'placeholderText',
|
|
189
|
-
title: formatMessage(messages.placeholderText),
|
|
190
|
-
description: formatMessage(messages.placeholderTextDescription),
|
|
191
|
-
priority: 1400,
|
|
192
|
-
keywords: ['placeholder'],
|
|
193
|
-
icon: () => /*#__PURE__*/React.createElement(MediaServicesTextIcon, {
|
|
194
|
-
label: ""
|
|
195
|
-
}),
|
|
196
|
-
action(insert, state) {
|
|
197
|
-
var _api$analytics;
|
|
198
|
-
const tr = state.tr;
|
|
199
|
-
tr.setMeta(pluginKey, {
|
|
200
|
-
showInsertPanelAt: tr.selection.anchor
|
|
201
|
-
});
|
|
202
|
-
api === null || api === void 0 ? void 0 : (_api$analytics = api.analytics) === null || _api$analytics === void 0 ? void 0 : _api$analytics.actions.attachAnalyticsEvent({
|
|
203
|
-
action: ACTION.INSERTED,
|
|
204
|
-
actionSubject: ACTION_SUBJECT.DOCUMENT,
|
|
205
|
-
actionSubjectId: ACTION_SUBJECT_ID.PLACEHOLDER_TEXT,
|
|
206
|
-
attributes: {
|
|
207
|
-
inputMethod: INPUT_METHOD.QUICK_INSERT
|
|
208
|
-
},
|
|
209
|
-
eventType: EVENT_TYPE.TRACK
|
|
210
|
-
})(tr);
|
|
211
|
-
return tr;
|
|
212
|
-
}
|
|
213
|
-
}]
|
|
214
|
-
};
|
|
215
|
-
return plugin;
|
|
216
|
-
};
|
|
217
|
-
const placeholderTextPlugin = ({
|
|
218
|
-
config: options = {},
|
|
219
|
-
api
|
|
220
|
-
}) => decorateWithPluginOptions(basePlaceholderTextPlugin({
|
|
221
|
-
config: options,
|
|
222
|
-
api
|
|
223
|
-
}), options, api);
|
|
224
|
-
export default placeholderTextPlugin;
|
|
1
|
+
export { default as placeholderTextPlugin } from './plugin';
|
|
@@ -0,0 +1,246 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { SafePlugin } from '@atlaskit/editor-common/safe-plugin';
|
|
3
|
+
import { NodeSelection, TextSelection } from '@atlaskit/editor-prosemirror/state';
|
|
4
|
+
import { placeholder } from '@atlaskit/adf-schema';
|
|
5
|
+
import MediaServicesTextIcon from '@atlaskit/icon/glyph/media-services/text';
|
|
6
|
+
import { useSharedPluginState } from '@atlaskit/editor-common/hooks';
|
|
7
|
+
import { isNodeEmpty } from '@atlaskit/editor-common/utils';
|
|
8
|
+
import { FakeTextCursorSelection } from '../fake-text-cursor/cursor';
|
|
9
|
+
import PlaceholderFloatingToolbar from './ui/PlaceholderFloatingToolbar';
|
|
10
|
+
import { hidePlaceholderFloatingToolbar, insertPlaceholderTextAtSelection } from './actions';
|
|
11
|
+
import { PlaceholderTextNodeView } from './placeholder-text-nodeview';
|
|
12
|
+
import { pluginKey } from './plugin-key';
|
|
13
|
+
import { ACTION, ACTION_SUBJECT, ACTION_SUBJECT_ID, EVENT_TYPE, INPUT_METHOD } from '@atlaskit/editor-common/analytics';
|
|
14
|
+
import { toolbarInsertBlockMessages as messages } from '@atlaskit/editor-common/messages';
|
|
15
|
+
import { isSelectionAtPlaceholder } from './selection-utils';
|
|
16
|
+
const getOpenTypeAhead = (trigger, api) => {
|
|
17
|
+
var _api$typeAhead, _api$typeAhead$action, _api$typeAhead2, _api$typeAhead2$actio;
|
|
18
|
+
const typeAheadHandler = api === null || api === void 0 ? void 0 : (_api$typeAhead = api.typeAhead) === null || _api$typeAhead === void 0 ? void 0 : (_api$typeAhead$action = _api$typeAhead.actions) === null || _api$typeAhead$action === void 0 ? void 0 : _api$typeAhead$action.findHandlerByTrigger(trigger);
|
|
19
|
+
if (!typeAheadHandler || !typeAheadHandler.id) {
|
|
20
|
+
return null;
|
|
21
|
+
}
|
|
22
|
+
return api === null || api === void 0 ? void 0 : (_api$typeAhead2 = api.typeAhead) === null || _api$typeAhead2 === void 0 ? void 0 : (_api$typeAhead2$actio = _api$typeAhead2.actions) === null || _api$typeAhead2$actio === void 0 ? void 0 : _api$typeAhead2$actio.openAtTransaction({
|
|
23
|
+
triggerHandler: typeAheadHandler,
|
|
24
|
+
inputMethod: INPUT_METHOD.KEYBOARD
|
|
25
|
+
});
|
|
26
|
+
};
|
|
27
|
+
export function createPlugin(dispatch, options, api) {
|
|
28
|
+
const allowInserting = !!options.allowInserting;
|
|
29
|
+
return new SafePlugin({
|
|
30
|
+
key: pluginKey,
|
|
31
|
+
state: {
|
|
32
|
+
init: () => ({
|
|
33
|
+
showInsertPanelAt: null,
|
|
34
|
+
allowInserting
|
|
35
|
+
}),
|
|
36
|
+
apply: (tr, state) => {
|
|
37
|
+
const meta = tr.getMeta(pluginKey);
|
|
38
|
+
if (meta && meta.showInsertPanelAt !== undefined) {
|
|
39
|
+
const newState = {
|
|
40
|
+
showInsertPanelAt: meta.showInsertPanelAt,
|
|
41
|
+
allowInserting
|
|
42
|
+
};
|
|
43
|
+
dispatch(pluginKey, newState);
|
|
44
|
+
return newState;
|
|
45
|
+
} else if (state.showInsertPanelAt) {
|
|
46
|
+
const newState = {
|
|
47
|
+
showInsertPanelAt: tr.mapping.map(state.showInsertPanelAt),
|
|
48
|
+
allowInserting
|
|
49
|
+
};
|
|
50
|
+
dispatch(pluginKey, newState);
|
|
51
|
+
return newState;
|
|
52
|
+
}
|
|
53
|
+
return state;
|
|
54
|
+
}
|
|
55
|
+
},
|
|
56
|
+
appendTransaction(transactions, oldState, newState) {
|
|
57
|
+
if (transactions.some(txn => txn.docChanged)) {
|
|
58
|
+
const didPlaceholderExistBeforeTxn = oldState.selection.$head.nodeAfter === newState.selection.$head.nodeAfter;
|
|
59
|
+
const adjacentNode = newState.selection.$head.nodeAfter;
|
|
60
|
+
const adjacentNodePos = newState.selection.$head.pos;
|
|
61
|
+
const placeholderNodeType = newState.schema.nodes.placeholder;
|
|
62
|
+
if (adjacentNode && adjacentNode.type === placeholderNodeType && didPlaceholderExistBeforeTxn) {
|
|
63
|
+
var _$newHead$nodeBefore;
|
|
64
|
+
const {
|
|
65
|
+
$head: $newHead
|
|
66
|
+
} = newState.selection;
|
|
67
|
+
const {
|
|
68
|
+
$head: $oldHead
|
|
69
|
+
} = oldState.selection;
|
|
70
|
+
// Check that cursor has moved forward in the document **and** that there is content before the cursor
|
|
71
|
+
const cursorMoved = $oldHead.pos < $newHead.pos;
|
|
72
|
+
const nodeBeforeHasContent = !isNodeEmpty($newHead.nodeBefore);
|
|
73
|
+
const nodeBeforeIsInline = (_$newHead$nodeBefore = $newHead.nodeBefore) === null || _$newHead$nodeBefore === void 0 ? void 0 : _$newHead$nodeBefore.type.isInline;
|
|
74
|
+
if (cursorMoved && (nodeBeforeHasContent || nodeBeforeIsInline)) {
|
|
75
|
+
const {
|
|
76
|
+
$from,
|
|
77
|
+
$to
|
|
78
|
+
} = NodeSelection.create(newState.doc, adjacentNodePos);
|
|
79
|
+
return newState.tr.deleteRange($from.pos, $to.pos);
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
// Handle Fake Text Cursor for Floating Toolbar
|
|
85
|
+
if (!pluginKey.getState(oldState).showInsertPanelAt && pluginKey.getState(newState).showInsertPanelAt) {
|
|
86
|
+
return newState.tr.setSelection(new FakeTextCursorSelection(newState.selection.$from));
|
|
87
|
+
}
|
|
88
|
+
if (pluginKey.getState(oldState).showInsertPanelAt && !pluginKey.getState(newState).showInsertPanelAt) {
|
|
89
|
+
if (newState.selection instanceof FakeTextCursorSelection) {
|
|
90
|
+
return newState.tr.setSelection(new TextSelection(newState.selection.$from));
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
return;
|
|
94
|
+
},
|
|
95
|
+
props: {
|
|
96
|
+
handleDOMEvents: {
|
|
97
|
+
beforeinput: (view, event) => {
|
|
98
|
+
const {
|
|
99
|
+
state
|
|
100
|
+
} = view;
|
|
101
|
+
if (event instanceof InputEvent && !event.isComposing && event.inputType === 'insertText' && isSelectionAtPlaceholder(view.state.selection)) {
|
|
102
|
+
event.stopPropagation();
|
|
103
|
+
event.preventDefault();
|
|
104
|
+
const startNodePosition = state.selection.from;
|
|
105
|
+
const content = event.data || '';
|
|
106
|
+
const tr = view.state.tr;
|
|
107
|
+
tr.delete(startNodePosition, startNodePosition + 1);
|
|
108
|
+
const openTypeAhead = getOpenTypeAhead(content, api);
|
|
109
|
+
if (openTypeAhead) {
|
|
110
|
+
openTypeAhead(tr);
|
|
111
|
+
} else {
|
|
112
|
+
tr.insertText(content);
|
|
113
|
+
}
|
|
114
|
+
view.dispatch(tr);
|
|
115
|
+
return true;
|
|
116
|
+
}
|
|
117
|
+
return false;
|
|
118
|
+
}
|
|
119
|
+
},
|
|
120
|
+
nodeViews: {
|
|
121
|
+
placeholder: (node, view, getPos) => new PlaceholderTextNodeView(node, view, getPos)
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
});
|
|
125
|
+
}
|
|
126
|
+
function ContentComponent({
|
|
127
|
+
editorView,
|
|
128
|
+
dependencyApi,
|
|
129
|
+
popupsMountPoint,
|
|
130
|
+
popupsBoundariesElement
|
|
131
|
+
}) {
|
|
132
|
+
const {
|
|
133
|
+
placeholderTextState
|
|
134
|
+
} = useSharedPluginState(dependencyApi, ['placeholderText']);
|
|
135
|
+
const insertPlaceholderText = value => insertPlaceholderTextAtSelection(value)(editorView.state, editorView.dispatch);
|
|
136
|
+
const hidePlaceholderToolbar = () => hidePlaceholderFloatingToolbar(editorView.state, editorView.dispatch);
|
|
137
|
+
const getNodeFromPos = pos => editorView.domAtPos(pos).node;
|
|
138
|
+
const getFixedCoordinatesFromPos = pos => editorView.coordsAtPos(pos);
|
|
139
|
+
const setFocusInEditor = () => editorView.focus();
|
|
140
|
+
if (placeholderTextState !== null && placeholderTextState !== void 0 && placeholderTextState.showInsertPanelAt) {
|
|
141
|
+
return /*#__PURE__*/React.createElement(PlaceholderFloatingToolbar, {
|
|
142
|
+
editorViewDOM: editorView.dom,
|
|
143
|
+
popupsMountPoint: popupsMountPoint,
|
|
144
|
+
popupsBoundariesElement: popupsBoundariesElement,
|
|
145
|
+
getFixedCoordinatesFromPos: getFixedCoordinatesFromPos,
|
|
146
|
+
getNodeFromPos: getNodeFromPos,
|
|
147
|
+
hidePlaceholderFloatingToolbar: hidePlaceholderToolbar,
|
|
148
|
+
showInsertPanelAt: placeholderTextState.showInsertPanelAt,
|
|
149
|
+
insertPlaceholder: insertPlaceholderText,
|
|
150
|
+
setFocusInEditor: setFocusInEditor
|
|
151
|
+
});
|
|
152
|
+
}
|
|
153
|
+
return null;
|
|
154
|
+
}
|
|
155
|
+
const basePlaceholderTextPlugin = ({
|
|
156
|
+
api,
|
|
157
|
+
config: options
|
|
158
|
+
}) => ({
|
|
159
|
+
name: 'placeholderText',
|
|
160
|
+
nodes() {
|
|
161
|
+
return [{
|
|
162
|
+
name: 'placeholder',
|
|
163
|
+
node: placeholder
|
|
164
|
+
}];
|
|
165
|
+
},
|
|
166
|
+
pmPlugins() {
|
|
167
|
+
return [{
|
|
168
|
+
name: 'placeholderText',
|
|
169
|
+
plugin: ({
|
|
170
|
+
dispatch
|
|
171
|
+
}) => createPlugin(dispatch, options, api)
|
|
172
|
+
}];
|
|
173
|
+
},
|
|
174
|
+
getSharedState(editorState) {
|
|
175
|
+
if (!editorState) {
|
|
176
|
+
return undefined;
|
|
177
|
+
}
|
|
178
|
+
const {
|
|
179
|
+
showInsertPanelAt,
|
|
180
|
+
allowInserting
|
|
181
|
+
} = pluginKey.getState(editorState) || {
|
|
182
|
+
showInsertPanelAt: null
|
|
183
|
+
};
|
|
184
|
+
return {
|
|
185
|
+
showInsertPanelAt,
|
|
186
|
+
allowInserting: !!allowInserting
|
|
187
|
+
};
|
|
188
|
+
},
|
|
189
|
+
contentComponent({
|
|
190
|
+
editorView,
|
|
191
|
+
popupsMountPoint,
|
|
192
|
+
popupsBoundariesElement
|
|
193
|
+
}) {
|
|
194
|
+
return /*#__PURE__*/React.createElement(ContentComponent, {
|
|
195
|
+
editorView: editorView,
|
|
196
|
+
popupsMountPoint: popupsMountPoint,
|
|
197
|
+
popupsBoundariesElement: popupsBoundariesElement,
|
|
198
|
+
dependencyApi: api
|
|
199
|
+
});
|
|
200
|
+
}
|
|
201
|
+
});
|
|
202
|
+
const decorateWithPluginOptions = (plugin, options, api) => {
|
|
203
|
+
if (!options.allowInserting) {
|
|
204
|
+
return plugin;
|
|
205
|
+
}
|
|
206
|
+
plugin.pluginsOptions = {
|
|
207
|
+
quickInsert: ({
|
|
208
|
+
formatMessage
|
|
209
|
+
}) => [{
|
|
210
|
+
id: 'placeholderText',
|
|
211
|
+
title: formatMessage(messages.placeholderText),
|
|
212
|
+
description: formatMessage(messages.placeholderTextDescription),
|
|
213
|
+
priority: 1400,
|
|
214
|
+
keywords: ['placeholder'],
|
|
215
|
+
icon: () => /*#__PURE__*/React.createElement(MediaServicesTextIcon, {
|
|
216
|
+
label: ""
|
|
217
|
+
}),
|
|
218
|
+
action(insert, state) {
|
|
219
|
+
var _api$analytics;
|
|
220
|
+
const tr = state.tr;
|
|
221
|
+
tr.setMeta(pluginKey, {
|
|
222
|
+
showInsertPanelAt: tr.selection.anchor
|
|
223
|
+
});
|
|
224
|
+
api === null || api === void 0 ? void 0 : (_api$analytics = api.analytics) === null || _api$analytics === void 0 ? void 0 : _api$analytics.actions.attachAnalyticsEvent({
|
|
225
|
+
action: ACTION.INSERTED,
|
|
226
|
+
actionSubject: ACTION_SUBJECT.DOCUMENT,
|
|
227
|
+
actionSubjectId: ACTION_SUBJECT_ID.PLACEHOLDER_TEXT,
|
|
228
|
+
attributes: {
|
|
229
|
+
inputMethod: INPUT_METHOD.QUICK_INSERT
|
|
230
|
+
},
|
|
231
|
+
eventType: EVENT_TYPE.TRACK
|
|
232
|
+
})(tr);
|
|
233
|
+
return tr;
|
|
234
|
+
}
|
|
235
|
+
}]
|
|
236
|
+
};
|
|
237
|
+
return plugin;
|
|
238
|
+
};
|
|
239
|
+
const placeholderTextPlugin = ({
|
|
240
|
+
config: options = {},
|
|
241
|
+
api
|
|
242
|
+
}) => decorateWithPluginOptions(basePlaceholderTextPlugin({
|
|
243
|
+
config: options,
|
|
244
|
+
api
|
|
245
|
+
}), options, api);
|
|
246
|
+
export default placeholderTextPlugin;
|
|
@@ -7,7 +7,7 @@ export const container = height => css`
|
|
|
7
7
|
display: flex;
|
|
8
8
|
align-items: center;
|
|
9
9
|
box-sizing: border-box;
|
|
10
|
-
padding: 4px 8px;
|
|
10
|
+
padding: ${"var(--ds-space-050, 4px)"} ${"var(--ds-space-100, 8px)"};
|
|
11
11
|
background-color: ${`var(--ds-background-input, ${N0})`};
|
|
12
12
|
${height ? css`
|
|
13
13
|
height: ${height}px;
|
|
@@ -2,7 +2,7 @@ import _defineProperty from "@babel/runtime/helpers/defineProperty";
|
|
|
2
2
|
import React from 'react';
|
|
3
3
|
import { defineMessages, injectIntl } from 'react-intl-next';
|
|
4
4
|
import { PanelTextInput } from '@atlaskit/editor-common/ui';
|
|
5
|
-
import FloatingToolbar, { handlePositionCalculatedWith, getOffsetParent, getNearestNonTextNode } from '
|
|
5
|
+
import FloatingToolbar, { handlePositionCalculatedWith, getOffsetParent, getNearestNonTextNode } from '../FloatingToolbar';
|
|
6
6
|
export const messages = defineMessages({
|
|
7
7
|
placeholderTextPlaceholder: {
|
|
8
8
|
id: 'fabric.editor.placeholderTextPlaceholder',
|
|
@@ -11,7 +11,7 @@ export { default as macroPlugin } from './macro';
|
|
|
11
11
|
export { default as maxContentSizePlugin } from './max-content-size';
|
|
12
12
|
export { default as panelPlugin } from './panel';
|
|
13
13
|
export { default as pastePlugin } from './paste';
|
|
14
|
-
export {
|
|
14
|
+
export { placeholderTextPlugin } from './placeholder-text';
|
|
15
15
|
export { default as tasksAndDecisionsPlugin } from './tasks-and-decisions';
|
|
16
16
|
export { default as textColorPlugin } from './text-color';
|
|
17
17
|
export { default as breakoutPlugin } from './breakout';
|