@atlaskit/editor-plugin-block-controls 31.0.2 → 31.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 +18 -0
- package/dist/cjs/blockControlsPlugin.js +0 -1
- package/dist/cjs/pm-plugins/decorations-drag-handle.js +1 -4
- package/dist/cjs/pm-plugins/decorations-quick-insert-button.js +1 -4
- package/dist/cjs/pm-plugins/handle-mouse-over.js +2 -2
- package/dist/cjs/pm-plugins/interaction-tracking/handle-mouse-move.js +2 -2
- package/dist/cjs/pm-plugins/interaction-tracking/pm-plugin.js +0 -2
- package/dist/cjs/pm-plugins/main.js +4 -5
- package/dist/cjs/pm-plugins/utils/getSelection.js +1 -11
- package/dist/cjs/ui/block-controls-surface-drag-handle.js +1 -2
- package/dist/cjs/ui/consts.js +1 -22
- package/dist/cjs/ui/drag-handle.js +1 -1
- package/dist/cjs/ui/visibility-container.js +0 -1
- package/dist/es2019/blockControlsPlugin.js +0 -1
- package/dist/es2019/pm-plugins/decorations-drag-handle.js +1 -4
- package/dist/es2019/pm-plugins/decorations-quick-insert-button.js +1 -4
- package/dist/es2019/pm-plugins/handle-mouse-over.js +2 -2
- package/dist/es2019/pm-plugins/interaction-tracking/handle-mouse-move.js +2 -2
- package/dist/es2019/pm-plugins/interaction-tracking/pm-plugin.js +0 -2
- package/dist/es2019/pm-plugins/main.js +4 -5
- package/dist/es2019/pm-plugins/utils/getSelection.js +0 -10
- package/dist/es2019/ui/block-controls-surface-drag-handle.js +1 -2
- package/dist/es2019/ui/consts.js +0 -37
- package/dist/es2019/ui/drag-handle.js +1 -1
- package/dist/es2019/ui/visibility-container.js +0 -1
- package/dist/esm/blockControlsPlugin.js +0 -1
- package/dist/esm/pm-plugins/decorations-drag-handle.js +1 -4
- package/dist/esm/pm-plugins/decorations-quick-insert-button.js +1 -4
- package/dist/esm/pm-plugins/handle-mouse-over.js +2 -2
- package/dist/esm/pm-plugins/interaction-tracking/handle-mouse-move.js +2 -2
- package/dist/esm/pm-plugins/interaction-tracking/pm-plugin.js +0 -2
- package/dist/esm/pm-plugins/main.js +4 -5
- package/dist/esm/pm-plugins/utils/getSelection.js +0 -10
- package/dist/esm/ui/block-controls-surface-drag-handle.js +1 -2
- package/dist/esm/ui/consts.js +0 -21
- package/dist/esm/ui/drag-handle.js +1 -1
- package/dist/esm/ui/visibility-container.js +0 -1
- package/dist/types/pm-plugins/decorations-surface-anchor.d.ts +0 -5
- package/dist/types/pm-plugins/main.d.ts +3 -49
- package/dist/types/pm-plugins/utils/getSelection.d.ts +0 -1
- package/dist/types/ui/consts.d.ts +0 -11
- package/package.json +3 -6
- package/dist/cjs/pm-plugins/vanilla-quick-insert.js +0 -215
- package/dist/es2019/pm-plugins/vanilla-quick-insert.js +0 -215
- package/dist/esm/pm-plugins/vanilla-quick-insert.js +0 -208
- package/dist/types/pm-plugins/vanilla-quick-insert.d.ts +0 -21
|
@@ -1,215 +0,0 @@
|
|
|
1
|
-
import { convertToInlineCss } from '@atlaskit/editor-common/css-helper';
|
|
2
|
-
import { messages } from '@atlaskit/editor-common/messages/block-controls';
|
|
3
|
-
import { VanillaTooltip } from '@atlaskit/editor-common/vanilla-tooltip';
|
|
4
|
-
import { DOMSerializer } from '@atlaskit/editor-prosemirror/model';
|
|
5
|
-
import { TextSelection } from '@atlaskit/editor-prosemirror/state';
|
|
6
|
-
import { findParentNode, findParentNodeOfType } from '@atlaskit/editor-prosemirror/utils';
|
|
7
|
-
import { CellSelection } from '@atlaskit/editor-tables/cell-selection';
|
|
8
|
-
import { isInTextSelection, isNestedNodeSelected, isNonEditableBlock, isSelectionInNode } from '../ui/utils/document-checks';
|
|
9
|
-
import { createNewLine } from '../ui/utils/editor-commands';
|
|
10
|
-
import { calculatePosition } from './quick-insert-calculate-position';
|
|
11
|
-
// Based on platform/packages/design-system/icon/svgs/utility/add.svg
|
|
12
|
-
const plusButtonDOM = ['http://www.w3.org/2000/svg svg', {
|
|
13
|
-
width: '12',
|
|
14
|
-
height: '12',
|
|
15
|
-
fill: 'none',
|
|
16
|
-
viewBox: '0 0 12 12',
|
|
17
|
-
style: 'pointer-events: none;'
|
|
18
|
-
}, ['http://www.w3.org/2000/svg path', {
|
|
19
|
-
fill: 'currentcolor',
|
|
20
|
-
'fill-rule': 'evenodd',
|
|
21
|
-
d: 'M5.25 6.75V11h1.5V6.75H11v-1.5H6.75V1h-1.5v4.25H1v1.5z',
|
|
22
|
-
'clip-rule': 'evenodd',
|
|
23
|
-
style: 'pointer-events: none;'
|
|
24
|
-
}]];
|
|
25
|
-
const vanillaQuickInsert = ({
|
|
26
|
-
view,
|
|
27
|
-
getPos,
|
|
28
|
-
rootNodeType,
|
|
29
|
-
anchorRectCache,
|
|
30
|
-
anchorName,
|
|
31
|
-
rootAnchorName,
|
|
32
|
-
api
|
|
33
|
-
}) => {
|
|
34
|
-
var _api$featureFlags$sha, _api$featureFlags, _api$featureFlags$sha2;
|
|
35
|
-
return ['div', {
|
|
36
|
-
style: convertToInlineCss({
|
|
37
|
-
position: 'absolute',
|
|
38
|
-
...calculatePosition({
|
|
39
|
-
rootAnchorName,
|
|
40
|
-
anchorName,
|
|
41
|
-
view,
|
|
42
|
-
getPos,
|
|
43
|
-
rootNodeType: rootNodeType,
|
|
44
|
-
macroInteractionUpdates: (_api$featureFlags$sha = api === null || api === void 0 ? void 0 : (_api$featureFlags = api.featureFlags) === null || _api$featureFlags === void 0 ? void 0 : (_api$featureFlags$sha2 = _api$featureFlags.sharedState.currentState()) === null || _api$featureFlags$sha2 === void 0 ? void 0 : _api$featureFlags$sha2.macroInteractionUpdates) !== null && _api$featureFlags$sha !== void 0 ? _api$featureFlags$sha : false,
|
|
45
|
-
anchorRectCache
|
|
46
|
-
})
|
|
47
|
-
})
|
|
48
|
-
}, ['button', {
|
|
49
|
-
class: 'blocks-quick-insert-button',
|
|
50
|
-
'data-testid': 'editor-quick-insert-button'
|
|
51
|
-
}, plusButtonDOM]];
|
|
52
|
-
};
|
|
53
|
-
|
|
54
|
-
/**
|
|
55
|
-
* Create a Node which contains the quick insert button
|
|
56
|
-
*/
|
|
57
|
-
export const createVanillaButton = props => {
|
|
58
|
-
var _props$api$typeAhead, _props$api$typeAhead$, _props$api$blockContr, _props$api$blockContr2, _props$api$blockContr3, _props$api$blockContr4, _props$api$blockContr5, _props$api$blockContr6, _props$api$blockContr7, _props$api$editorView, _props$api$editorView2, _props$api$typeAhead2, _props$api$blockContr8;
|
|
59
|
-
const {
|
|
60
|
-
dom
|
|
61
|
-
} = DOMSerializer.renderSpec(document, vanillaQuickInsert(props));
|
|
62
|
-
if (dom instanceof HTMLElement) {
|
|
63
|
-
const button = dom.querySelector('button[data-testid="editor-quick-insert-button"]');
|
|
64
|
-
if (button instanceof HTMLButtonElement) {
|
|
65
|
-
button.onclick = () => handleQuickInsert(props);
|
|
66
|
-
|
|
67
|
-
// Flag-on (platform-dst-top-layer), positioning is async via a React root;
|
|
68
|
-
// safe here as VanillaTooltip stays hidden until positioned.
|
|
69
|
-
const tooltip = new VanillaTooltip(button, props.formatMessage(messages.insert), 'quick-insert-button-tooltip', 'blocks-quick-insert-tooltip');
|
|
70
|
-
props.cleanupCallbacks.push(() => {
|
|
71
|
-
tooltip.destroy();
|
|
72
|
-
});
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
// Dynamically control the visibility of the node
|
|
77
|
-
let isTypeAheadOpen = (_props$api$typeAhead = props.api.typeAhead) === null || _props$api$typeAhead === void 0 ? void 0 : (_props$api$typeAhead$ = _props$api$typeAhead.sharedState.currentState()) === null || _props$api$typeAhead$ === void 0 ? void 0 : _props$api$typeAhead$.isOpen;
|
|
78
|
-
let isEditing = (_props$api$blockContr = props.api.blockControls) === null || _props$api$blockContr === void 0 ? void 0 : (_props$api$blockContr2 = _props$api$blockContr.sharedState.currentState()) === null || _props$api$blockContr2 === void 0 ? void 0 : _props$api$blockContr2.isEditing;
|
|
79
|
-
let hoverSide = (_props$api$blockContr3 = props.api.blockControls) === null || _props$api$blockContr3 === void 0 ? void 0 : (_props$api$blockContr4 = _props$api$blockContr3.sharedState.currentState()) === null || _props$api$blockContr4 === void 0 ? void 0 : _props$api$blockContr4.hoverSide;
|
|
80
|
-
let rightSideControlsEnabled = (_props$api$blockContr5 = (_props$api$blockContr6 = props.api.blockControls) === null || _props$api$blockContr6 === void 0 ? void 0 : (_props$api$blockContr7 = _props$api$blockContr6.sharedState.currentState()) === null || _props$api$blockContr7 === void 0 ? void 0 : _props$api$blockContr7.rightSideControlsEnabled) !== null && _props$api$blockContr5 !== void 0 ? _props$api$blockContr5 : false;
|
|
81
|
-
let editorViewMode = (_props$api$editorView = props.api.editorViewMode) === null || _props$api$editorView === void 0 ? void 0 : (_props$api$editorView2 = _props$api$editorView.sharedState.currentState()) === null || _props$api$editorView2 === void 0 ? void 0 : _props$api$editorView2.mode;
|
|
82
|
-
const changeDOMVisibility = () => {
|
|
83
|
-
if (!(dom instanceof HTMLElement)) {
|
|
84
|
-
return;
|
|
85
|
-
}
|
|
86
|
-
const isViewMode = editorViewMode === 'view';
|
|
87
|
-
const shouldRestrictBySide = rightSideControlsEnabled && !isViewMode;
|
|
88
|
-
// Only restrict by side when hoverSide is known. When undefined, show quick insert.
|
|
89
|
-
const sideHidden = shouldRestrictBySide && hoverSide !== undefined ? hoverSide !== 'left' : false;
|
|
90
|
-
if (isTypeAheadOpen || isEditing || sideHidden) {
|
|
91
|
-
dom.classList.add('blocks-quick-insert-invisible-container');
|
|
92
|
-
dom.classList.remove('blocks-quick-insert-visible-container');
|
|
93
|
-
} else {
|
|
94
|
-
dom.classList.add('blocks-quick-insert-visible-container');
|
|
95
|
-
dom.classList.remove('blocks-quick-insert-invisible-container');
|
|
96
|
-
}
|
|
97
|
-
};
|
|
98
|
-
changeDOMVisibility();
|
|
99
|
-
props.cleanupCallbacks.push((_props$api$typeAhead2 = props.api.typeAhead) === null || _props$api$typeAhead2 === void 0 ? void 0 : _props$api$typeAhead2.sharedState.onChange(({
|
|
100
|
-
nextSharedState
|
|
101
|
-
}) => {
|
|
102
|
-
isTypeAheadOpen = nextSharedState === null || nextSharedState === void 0 ? void 0 : nextSharedState.isOpen;
|
|
103
|
-
changeDOMVisibility();
|
|
104
|
-
}));
|
|
105
|
-
props.cleanupCallbacks.push((_props$api$blockContr8 = props.api.blockControls) === null || _props$api$blockContr8 === void 0 ? void 0 : _props$api$blockContr8.sharedState.onChange(({
|
|
106
|
-
nextSharedState
|
|
107
|
-
}) => {
|
|
108
|
-
var _nextSharedState$righ;
|
|
109
|
-
isEditing = nextSharedState === null || nextSharedState === void 0 ? void 0 : nextSharedState.isEditing;
|
|
110
|
-
hoverSide = nextSharedState === null || nextSharedState === void 0 ? void 0 : nextSharedState.hoverSide;
|
|
111
|
-
rightSideControlsEnabled = (_nextSharedState$righ = nextSharedState === null || nextSharedState === void 0 ? void 0 : nextSharedState.rightSideControlsEnabled) !== null && _nextSharedState$righ !== void 0 ? _nextSharedState$righ : false;
|
|
112
|
-
changeDOMVisibility();
|
|
113
|
-
}));
|
|
114
|
-
// Only subscribe to view mode when right-side controls are enabled (editorViewMode affects side restriction)
|
|
115
|
-
if (rightSideControlsEnabled) {
|
|
116
|
-
var _props$api$editorView3, _props$api$editorView4, _props$api$editorView5;
|
|
117
|
-
const unsubscribeViewMode = (_props$api$editorView3 = props.api.editorViewMode) === null || _props$api$editorView3 === void 0 ? void 0 : (_props$api$editorView4 = (_props$api$editorView5 = _props$api$editorView3.sharedState).onChange) === null || _props$api$editorView4 === void 0 ? void 0 : _props$api$editorView4.call(_props$api$editorView5, ({
|
|
118
|
-
nextSharedState
|
|
119
|
-
}) => {
|
|
120
|
-
editorViewMode = nextSharedState === null || nextSharedState === void 0 ? void 0 : nextSharedState.mode;
|
|
121
|
-
changeDOMVisibility();
|
|
122
|
-
});
|
|
123
|
-
if (unsubscribeViewMode) {
|
|
124
|
-
props.cleanupCallbacks.push(unsubscribeViewMode);
|
|
125
|
-
}
|
|
126
|
-
}
|
|
127
|
-
return dom;
|
|
128
|
-
};
|
|
129
|
-
const TEXT_PARENT_TYPES = ['paragraph', 'heading', 'blockquote', 'taskItem', 'decisionItem'];
|
|
130
|
-
const handleQuickInsert = ({
|
|
131
|
-
api,
|
|
132
|
-
view,
|
|
133
|
-
getPos
|
|
134
|
-
}) => {
|
|
135
|
-
var _api$quickInsert;
|
|
136
|
-
// if the selection is not within the node this decoration is rendered at
|
|
137
|
-
// then insert a newline and trigger quick insert
|
|
138
|
-
const start = getPos();
|
|
139
|
-
if (start !== undefined) {
|
|
140
|
-
// if the selection is not within the node this decoration is rendered at
|
|
141
|
-
// or the node is non-editable, then insert a newline and trigger quick insert
|
|
142
|
-
const isSelectionInsideNode = isSelectionInNode(start, view);
|
|
143
|
-
if (!isSelectionInsideNode || isNonEditableBlock(start, view)) {
|
|
144
|
-
api.core.actions.execute(createNewLine(start));
|
|
145
|
-
}
|
|
146
|
-
const {
|
|
147
|
-
codeBlock
|
|
148
|
-
} = view.state.schema.nodes;
|
|
149
|
-
const {
|
|
150
|
-
selection
|
|
151
|
-
} = view.state;
|
|
152
|
-
const codeBlockParentNode = findParentNodeOfType(codeBlock)(selection);
|
|
153
|
-
if (codeBlockParentNode) {
|
|
154
|
-
// Slash command is not meant to be triggered inside code block, hence always insert slash in a new line following
|
|
155
|
-
api.core.actions.execute(createNewLine(codeBlockParentNode.pos));
|
|
156
|
-
} else if (isSelectionInsideNode) {
|
|
157
|
-
// text or element with be deselected and the / added immediately after the paragraph
|
|
158
|
-
// unless the selection is empty
|
|
159
|
-
const currentSelection = view.state.selection;
|
|
160
|
-
if (isInTextSelection(view) && currentSelection.from !== currentSelection.to) {
|
|
161
|
-
const currentParagraphNode = findParentNode(node => TEXT_PARENT_TYPES.includes(node.type.name))(currentSelection);
|
|
162
|
-
if (currentParagraphNode) {
|
|
163
|
-
const newPos =
|
|
164
|
-
//if the current selection is selected from right to left, then set the selection to the start of the paragraph
|
|
165
|
-
currentSelection.anchor === currentSelection.to ? currentParagraphNode.pos : currentParagraphNode.pos + currentParagraphNode.node.nodeSize - 1;
|
|
166
|
-
api.core.actions.execute(({
|
|
167
|
-
tr
|
|
168
|
-
}) => {
|
|
169
|
-
tr.setSelection(TextSelection.create(view.state.selection.$from.doc, newPos));
|
|
170
|
-
return tr;
|
|
171
|
-
});
|
|
172
|
-
}
|
|
173
|
-
}
|
|
174
|
-
if (isNestedNodeSelected(view)) {
|
|
175
|
-
// if the nested selected node is non-editable, then insert a newline below the selected node
|
|
176
|
-
if (isNonEditableBlock(view.state.selection.from, view)) {
|
|
177
|
-
api.core.actions.execute(createNewLine(view.state.selection.from));
|
|
178
|
-
} else {
|
|
179
|
-
// otherwise need to force the selection to be at the start of the node, because
|
|
180
|
-
// prosemirror is keeping it as NodeSelection for nested nodes. Do this to keep it
|
|
181
|
-
// consistent NodeSelection for root level nodes.
|
|
182
|
-
api.core.actions.execute(({
|
|
183
|
-
tr
|
|
184
|
-
}) => {
|
|
185
|
-
createNewLine(view.state.selection.from)({
|
|
186
|
-
tr
|
|
187
|
-
});
|
|
188
|
-
tr.setSelection(TextSelection.create(tr.doc, view.state.selection.from));
|
|
189
|
-
return tr;
|
|
190
|
-
});
|
|
191
|
-
}
|
|
192
|
-
}
|
|
193
|
-
if (currentSelection instanceof CellSelection) {
|
|
194
|
-
// find the last inline position in the selection
|
|
195
|
-
const lastInlinePosition = TextSelection.near(view.state.selection.$to, -1);
|
|
196
|
-
lastInlinePosition && api.core.actions.execute(({
|
|
197
|
-
tr
|
|
198
|
-
}) => {
|
|
199
|
-
if (!(lastInlinePosition instanceof TextSelection)) {
|
|
200
|
-
// this will create a new line after the node
|
|
201
|
-
createNewLine(lastInlinePosition.from)({
|
|
202
|
-
tr
|
|
203
|
-
});
|
|
204
|
-
// this will find the next valid text position after the node
|
|
205
|
-
tr.setSelection(TextSelection.create(tr.doc, lastInlinePosition.to));
|
|
206
|
-
} else {
|
|
207
|
-
tr.setSelection(lastInlinePosition);
|
|
208
|
-
}
|
|
209
|
-
return tr;
|
|
210
|
-
});
|
|
211
|
-
}
|
|
212
|
-
}
|
|
213
|
-
}
|
|
214
|
-
(_api$quickInsert = api.quickInsert) === null || _api$quickInsert === void 0 ? void 0 : _api$quickInsert.actions.openTypeAhead('blockControl', true);
|
|
215
|
-
};
|
|
@@ -1,208 +0,0 @@
|
|
|
1
|
-
import _defineProperty from "@babel/runtime/helpers/defineProperty";
|
|
2
|
-
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
3
|
-
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
4
|
-
import { convertToInlineCss } from '@atlaskit/editor-common/css-helper';
|
|
5
|
-
import { messages } from '@atlaskit/editor-common/messages/block-controls';
|
|
6
|
-
import { VanillaTooltip } from '@atlaskit/editor-common/vanilla-tooltip';
|
|
7
|
-
import { DOMSerializer } from '@atlaskit/editor-prosemirror/model';
|
|
8
|
-
import { TextSelection } from '@atlaskit/editor-prosemirror/state';
|
|
9
|
-
import { findParentNode, findParentNodeOfType } from '@atlaskit/editor-prosemirror/utils';
|
|
10
|
-
import { CellSelection } from '@atlaskit/editor-tables/cell-selection';
|
|
11
|
-
import { isInTextSelection, isNestedNodeSelected, isNonEditableBlock, isSelectionInNode } from '../ui/utils/document-checks';
|
|
12
|
-
import { createNewLine } from '../ui/utils/editor-commands';
|
|
13
|
-
import { calculatePosition } from './quick-insert-calculate-position';
|
|
14
|
-
// Based on platform/packages/design-system/icon/svgs/utility/add.svg
|
|
15
|
-
var plusButtonDOM = ['http://www.w3.org/2000/svg svg', {
|
|
16
|
-
width: '12',
|
|
17
|
-
height: '12',
|
|
18
|
-
fill: 'none',
|
|
19
|
-
viewBox: '0 0 12 12',
|
|
20
|
-
style: 'pointer-events: none;'
|
|
21
|
-
}, ['http://www.w3.org/2000/svg path', {
|
|
22
|
-
fill: 'currentcolor',
|
|
23
|
-
'fill-rule': 'evenodd',
|
|
24
|
-
d: 'M5.25 6.75V11h1.5V6.75H11v-1.5H6.75V1h-1.5v4.25H1v1.5z',
|
|
25
|
-
'clip-rule': 'evenodd',
|
|
26
|
-
style: 'pointer-events: none;'
|
|
27
|
-
}]];
|
|
28
|
-
var vanillaQuickInsert = function vanillaQuickInsert(_ref) {
|
|
29
|
-
var _api$featureFlags$sha, _api$featureFlags;
|
|
30
|
-
var view = _ref.view,
|
|
31
|
-
getPos = _ref.getPos,
|
|
32
|
-
rootNodeType = _ref.rootNodeType,
|
|
33
|
-
anchorRectCache = _ref.anchorRectCache,
|
|
34
|
-
anchorName = _ref.anchorName,
|
|
35
|
-
rootAnchorName = _ref.rootAnchorName,
|
|
36
|
-
api = _ref.api;
|
|
37
|
-
return ['div', {
|
|
38
|
-
style: convertToInlineCss(_objectSpread({
|
|
39
|
-
position: 'absolute'
|
|
40
|
-
}, calculatePosition({
|
|
41
|
-
rootAnchorName: rootAnchorName,
|
|
42
|
-
anchorName: anchorName,
|
|
43
|
-
view: view,
|
|
44
|
-
getPos: getPos,
|
|
45
|
-
rootNodeType: rootNodeType,
|
|
46
|
-
macroInteractionUpdates: (_api$featureFlags$sha = api === null || api === void 0 || (_api$featureFlags = api.featureFlags) === null || _api$featureFlags === void 0 || (_api$featureFlags = _api$featureFlags.sharedState.currentState()) === null || _api$featureFlags === void 0 ? void 0 : _api$featureFlags.macroInteractionUpdates) !== null && _api$featureFlags$sha !== void 0 ? _api$featureFlags$sha : false,
|
|
47
|
-
anchorRectCache: anchorRectCache
|
|
48
|
-
})))
|
|
49
|
-
}, ['button', {
|
|
50
|
-
class: 'blocks-quick-insert-button',
|
|
51
|
-
'data-testid': 'editor-quick-insert-button'
|
|
52
|
-
}, plusButtonDOM]];
|
|
53
|
-
};
|
|
54
|
-
|
|
55
|
-
/**
|
|
56
|
-
* Create a Node which contains the quick insert button
|
|
57
|
-
*/
|
|
58
|
-
export var createVanillaButton = function createVanillaButton(props) {
|
|
59
|
-
var _props$api$typeAhead, _props$api$blockContr, _props$api$blockContr2, _props$api$blockContr3, _props$api$blockContr4, _props$api$editorView, _props$api$typeAhead2, _props$api$blockContr5;
|
|
60
|
-
var _DOMSerializer$render = DOMSerializer.renderSpec(document, vanillaQuickInsert(props)),
|
|
61
|
-
dom = _DOMSerializer$render.dom;
|
|
62
|
-
if (dom instanceof HTMLElement) {
|
|
63
|
-
var button = dom.querySelector('button[data-testid="editor-quick-insert-button"]');
|
|
64
|
-
if (button instanceof HTMLButtonElement) {
|
|
65
|
-
button.onclick = function () {
|
|
66
|
-
return handleQuickInsert(props);
|
|
67
|
-
};
|
|
68
|
-
|
|
69
|
-
// Flag-on (platform-dst-top-layer), positioning is async via a React root;
|
|
70
|
-
// safe here as VanillaTooltip stays hidden until positioned.
|
|
71
|
-
var tooltip = new VanillaTooltip(button, props.formatMessage(messages.insert), 'quick-insert-button-tooltip', 'blocks-quick-insert-tooltip');
|
|
72
|
-
props.cleanupCallbacks.push(function () {
|
|
73
|
-
tooltip.destroy();
|
|
74
|
-
});
|
|
75
|
-
}
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
// Dynamically control the visibility of the node
|
|
79
|
-
var isTypeAheadOpen = (_props$api$typeAhead = props.api.typeAhead) === null || _props$api$typeAhead === void 0 || (_props$api$typeAhead = _props$api$typeAhead.sharedState.currentState()) === null || _props$api$typeAhead === void 0 ? void 0 : _props$api$typeAhead.isOpen;
|
|
80
|
-
var isEditing = (_props$api$blockContr = props.api.blockControls) === null || _props$api$blockContr === void 0 || (_props$api$blockContr = _props$api$blockContr.sharedState.currentState()) === null || _props$api$blockContr === void 0 ? void 0 : _props$api$blockContr.isEditing;
|
|
81
|
-
var hoverSide = (_props$api$blockContr2 = props.api.blockControls) === null || _props$api$blockContr2 === void 0 || (_props$api$blockContr2 = _props$api$blockContr2.sharedState.currentState()) === null || _props$api$blockContr2 === void 0 ? void 0 : _props$api$blockContr2.hoverSide;
|
|
82
|
-
var rightSideControlsEnabled = (_props$api$blockContr3 = (_props$api$blockContr4 = props.api.blockControls) === null || _props$api$blockContr4 === void 0 || (_props$api$blockContr4 = _props$api$blockContr4.sharedState.currentState()) === null || _props$api$blockContr4 === void 0 ? void 0 : _props$api$blockContr4.rightSideControlsEnabled) !== null && _props$api$blockContr3 !== void 0 ? _props$api$blockContr3 : false;
|
|
83
|
-
var editorViewMode = (_props$api$editorView = props.api.editorViewMode) === null || _props$api$editorView === void 0 || (_props$api$editorView = _props$api$editorView.sharedState.currentState()) === null || _props$api$editorView === void 0 ? void 0 : _props$api$editorView.mode;
|
|
84
|
-
var changeDOMVisibility = function changeDOMVisibility() {
|
|
85
|
-
if (!(dom instanceof HTMLElement)) {
|
|
86
|
-
return;
|
|
87
|
-
}
|
|
88
|
-
var isViewMode = editorViewMode === 'view';
|
|
89
|
-
var shouldRestrictBySide = rightSideControlsEnabled && !isViewMode;
|
|
90
|
-
// Only restrict by side when hoverSide is known. When undefined, show quick insert.
|
|
91
|
-
var sideHidden = shouldRestrictBySide && hoverSide !== undefined ? hoverSide !== 'left' : false;
|
|
92
|
-
if (isTypeAheadOpen || isEditing || sideHidden) {
|
|
93
|
-
dom.classList.add('blocks-quick-insert-invisible-container');
|
|
94
|
-
dom.classList.remove('blocks-quick-insert-visible-container');
|
|
95
|
-
} else {
|
|
96
|
-
dom.classList.add('blocks-quick-insert-visible-container');
|
|
97
|
-
dom.classList.remove('blocks-quick-insert-invisible-container');
|
|
98
|
-
}
|
|
99
|
-
};
|
|
100
|
-
changeDOMVisibility();
|
|
101
|
-
props.cleanupCallbacks.push((_props$api$typeAhead2 = props.api.typeAhead) === null || _props$api$typeAhead2 === void 0 ? void 0 : _props$api$typeAhead2.sharedState.onChange(function (_ref2) {
|
|
102
|
-
var nextSharedState = _ref2.nextSharedState;
|
|
103
|
-
isTypeAheadOpen = nextSharedState === null || nextSharedState === void 0 ? void 0 : nextSharedState.isOpen;
|
|
104
|
-
changeDOMVisibility();
|
|
105
|
-
}));
|
|
106
|
-
props.cleanupCallbacks.push((_props$api$blockContr5 = props.api.blockControls) === null || _props$api$blockContr5 === void 0 ? void 0 : _props$api$blockContr5.sharedState.onChange(function (_ref3) {
|
|
107
|
-
var _nextSharedState$righ;
|
|
108
|
-
var nextSharedState = _ref3.nextSharedState;
|
|
109
|
-
isEditing = nextSharedState === null || nextSharedState === void 0 ? void 0 : nextSharedState.isEditing;
|
|
110
|
-
hoverSide = nextSharedState === null || nextSharedState === void 0 ? void 0 : nextSharedState.hoverSide;
|
|
111
|
-
rightSideControlsEnabled = (_nextSharedState$righ = nextSharedState === null || nextSharedState === void 0 ? void 0 : nextSharedState.rightSideControlsEnabled) !== null && _nextSharedState$righ !== void 0 ? _nextSharedState$righ : false;
|
|
112
|
-
changeDOMVisibility();
|
|
113
|
-
}));
|
|
114
|
-
// Only subscribe to view mode when right-side controls are enabled (editorViewMode affects side restriction)
|
|
115
|
-
if (rightSideControlsEnabled) {
|
|
116
|
-
var _props$api$editorView2, _props$api$editorView3, _props$api$editorView4;
|
|
117
|
-
var unsubscribeViewMode = (_props$api$editorView2 = props.api.editorViewMode) === null || _props$api$editorView2 === void 0 || (_props$api$editorView3 = (_props$api$editorView4 = _props$api$editorView2.sharedState).onChange) === null || _props$api$editorView3 === void 0 ? void 0 : _props$api$editorView3.call(_props$api$editorView4, function (_ref4) {
|
|
118
|
-
var nextSharedState = _ref4.nextSharedState;
|
|
119
|
-
editorViewMode = nextSharedState === null || nextSharedState === void 0 ? void 0 : nextSharedState.mode;
|
|
120
|
-
changeDOMVisibility();
|
|
121
|
-
});
|
|
122
|
-
if (unsubscribeViewMode) {
|
|
123
|
-
props.cleanupCallbacks.push(unsubscribeViewMode);
|
|
124
|
-
}
|
|
125
|
-
}
|
|
126
|
-
return dom;
|
|
127
|
-
};
|
|
128
|
-
var TEXT_PARENT_TYPES = ['paragraph', 'heading', 'blockquote', 'taskItem', 'decisionItem'];
|
|
129
|
-
var handleQuickInsert = function handleQuickInsert(_ref5) {
|
|
130
|
-
var _api$quickInsert;
|
|
131
|
-
var api = _ref5.api,
|
|
132
|
-
view = _ref5.view,
|
|
133
|
-
getPos = _ref5.getPos;
|
|
134
|
-
// if the selection is not within the node this decoration is rendered at
|
|
135
|
-
// then insert a newline and trigger quick insert
|
|
136
|
-
var start = getPos();
|
|
137
|
-
if (start !== undefined) {
|
|
138
|
-
// if the selection is not within the node this decoration is rendered at
|
|
139
|
-
// or the node is non-editable, then insert a newline and trigger quick insert
|
|
140
|
-
var isSelectionInsideNode = isSelectionInNode(start, view);
|
|
141
|
-
if (!isSelectionInsideNode || isNonEditableBlock(start, view)) {
|
|
142
|
-
api.core.actions.execute(createNewLine(start));
|
|
143
|
-
}
|
|
144
|
-
var codeBlock = view.state.schema.nodes.codeBlock;
|
|
145
|
-
var selection = view.state.selection;
|
|
146
|
-
var codeBlockParentNode = findParentNodeOfType(codeBlock)(selection);
|
|
147
|
-
if (codeBlockParentNode) {
|
|
148
|
-
// Slash command is not meant to be triggered inside code block, hence always insert slash in a new line following
|
|
149
|
-
api.core.actions.execute(createNewLine(codeBlockParentNode.pos));
|
|
150
|
-
} else if (isSelectionInsideNode) {
|
|
151
|
-
// text or element with be deselected and the / added immediately after the paragraph
|
|
152
|
-
// unless the selection is empty
|
|
153
|
-
var currentSelection = view.state.selection;
|
|
154
|
-
if (isInTextSelection(view) && currentSelection.from !== currentSelection.to) {
|
|
155
|
-
var currentParagraphNode = findParentNode(function (node) {
|
|
156
|
-
return TEXT_PARENT_TYPES.includes(node.type.name);
|
|
157
|
-
})(currentSelection);
|
|
158
|
-
if (currentParagraphNode) {
|
|
159
|
-
var newPos =
|
|
160
|
-
//if the current selection is selected from right to left, then set the selection to the start of the paragraph
|
|
161
|
-
currentSelection.anchor === currentSelection.to ? currentParagraphNode.pos : currentParagraphNode.pos + currentParagraphNode.node.nodeSize - 1;
|
|
162
|
-
api.core.actions.execute(function (_ref6) {
|
|
163
|
-
var tr = _ref6.tr;
|
|
164
|
-
tr.setSelection(TextSelection.create(view.state.selection.$from.doc, newPos));
|
|
165
|
-
return tr;
|
|
166
|
-
});
|
|
167
|
-
}
|
|
168
|
-
}
|
|
169
|
-
if (isNestedNodeSelected(view)) {
|
|
170
|
-
// if the nested selected node is non-editable, then insert a newline below the selected node
|
|
171
|
-
if (isNonEditableBlock(view.state.selection.from, view)) {
|
|
172
|
-
api.core.actions.execute(createNewLine(view.state.selection.from));
|
|
173
|
-
} else {
|
|
174
|
-
// otherwise need to force the selection to be at the start of the node, because
|
|
175
|
-
// prosemirror is keeping it as NodeSelection for nested nodes. Do this to keep it
|
|
176
|
-
// consistent NodeSelection for root level nodes.
|
|
177
|
-
api.core.actions.execute(function (_ref7) {
|
|
178
|
-
var tr = _ref7.tr;
|
|
179
|
-
createNewLine(view.state.selection.from)({
|
|
180
|
-
tr: tr
|
|
181
|
-
});
|
|
182
|
-
tr.setSelection(TextSelection.create(tr.doc, view.state.selection.from));
|
|
183
|
-
return tr;
|
|
184
|
-
});
|
|
185
|
-
}
|
|
186
|
-
}
|
|
187
|
-
if (currentSelection instanceof CellSelection) {
|
|
188
|
-
// find the last inline position in the selection
|
|
189
|
-
var lastInlinePosition = TextSelection.near(view.state.selection.$to, -1);
|
|
190
|
-
lastInlinePosition && api.core.actions.execute(function (_ref8) {
|
|
191
|
-
var tr = _ref8.tr;
|
|
192
|
-
if (!(lastInlinePosition instanceof TextSelection)) {
|
|
193
|
-
// this will create a new line after the node
|
|
194
|
-
createNewLine(lastInlinePosition.from)({
|
|
195
|
-
tr: tr
|
|
196
|
-
});
|
|
197
|
-
// this will find the next valid text position after the node
|
|
198
|
-
tr.setSelection(TextSelection.create(tr.doc, lastInlinePosition.to));
|
|
199
|
-
} else {
|
|
200
|
-
tr.setSelection(lastInlinePosition);
|
|
201
|
-
}
|
|
202
|
-
return tr;
|
|
203
|
-
});
|
|
204
|
-
}
|
|
205
|
-
}
|
|
206
|
-
}
|
|
207
|
-
(_api$quickInsert = api.quickInsert) === null || _api$quickInsert === void 0 || _api$quickInsert.actions.openTypeAhead('blockControl', true);
|
|
208
|
-
};
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
import type { IntlShape } from 'react-intl';
|
|
2
|
-
import type { ExtractInjectionAPI } from '@atlaskit/editor-common/types/next-editor-plugin';
|
|
3
|
-
import type { EditorView } from '@atlaskit/editor-prosemirror/view';
|
|
4
|
-
import type { BlockControlsPlugin } from '../blockControlsPluginType';
|
|
5
|
-
import type { AnchorRectCache } from './utils/anchor-utils';
|
|
6
|
-
type VanillaQuickInsertProps = {
|
|
7
|
-
anchorName: string;
|
|
8
|
-
anchorRectCache?: AnchorRectCache;
|
|
9
|
-
api: ExtractInjectionAPI<BlockControlsPlugin>;
|
|
10
|
-
cleanupCallbacks: ((() => void) | undefined)[];
|
|
11
|
-
formatMessage: IntlShape['formatMessage'];
|
|
12
|
-
getPos: () => number | undefined;
|
|
13
|
-
rootAnchorName: string;
|
|
14
|
-
rootNodeType: string;
|
|
15
|
-
view: EditorView;
|
|
16
|
-
};
|
|
17
|
-
/**
|
|
18
|
-
* Create a Node which contains the quick insert button
|
|
19
|
-
*/
|
|
20
|
-
export declare const createVanillaButton: (props: VanillaQuickInsertProps) => Node;
|
|
21
|
-
export {};
|