@atlaskit/editor-plugin-quick-insert 16.0.1 → 16.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +13 -0
- package/dist/cjs/quickInsertPlugin.js +23 -4
- package/dist/cjs/ui/BlockControlQuickInsertButton.compiled.css +20 -0
- package/dist/cjs/ui/BlockControlQuickInsertButton.js +163 -0
- package/dist/cjs/ui/block-control-quick-insert.js +45 -0
- package/dist/es2019/quickInsertPlugin.js +22 -5
- package/dist/es2019/ui/BlockControlQuickInsertButton.compiled.css +20 -0
- package/dist/es2019/ui/BlockControlQuickInsertButton.js +159 -0
- package/dist/es2019/ui/block-control-quick-insert.js +34 -0
- package/dist/esm/quickInsertPlugin.js +23 -4
- package/dist/esm/ui/BlockControlQuickInsertButton.compiled.css +20 -0
- package/dist/esm/ui/BlockControlQuickInsertButton.js +154 -0
- package/dist/esm/ui/block-control-quick-insert.js +38 -0
- package/dist/types/ui/BlockControlQuickInsertButton.d.ts +16 -0
- package/dist/types/ui/block-control-quick-insert.d.ts +9 -0
- package/dist/types/ui/getLegacyCompatibleComponents.d.ts +9 -2
- package/dist/types/ui/getQuickInsertComponents.d.ts +2 -2
- package/package.json +4 -2
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,18 @@
|
|
|
1
1
|
# @atlaskit/editor-plugin-quick-insert
|
|
2
2
|
|
|
3
|
+
## 16.1.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- [`5f66a8c3706e3`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/5f66a8c3706e3) -
|
|
8
|
+
Add the registry-backed Block Controls Quick Insert surface behind
|
|
9
|
+
`platform_editor_block_control_migration`, including typed surface context, cached registry
|
|
10
|
+
lookup, stable left/right surface identities, and experiment-gated Quick Insert registration.
|
|
11
|
+
|
|
12
|
+
### Patch Changes
|
|
13
|
+
|
|
14
|
+
- Updated dependencies
|
|
15
|
+
|
|
3
16
|
## 16.0.1
|
|
4
17
|
|
|
5
18
|
### Patch Changes
|
|
@@ -25,6 +25,7 @@ var _commands = require("./pm-plugins/commands");
|
|
|
25
25
|
var _quickInsertOpenExperience = require("./pm-plugins/experiences/quick-insert-open-experience");
|
|
26
26
|
var _pluginKey = require("./pm-plugins/plugin-key");
|
|
27
27
|
var _getLegacyCompatibleComponents = require("./ui/getLegacyCompatibleComponents");
|
|
28
|
+
var _blockControlQuickInsert = require("./ui/block-control-quick-insert");
|
|
28
29
|
var _getQuickInsertComponents = require("./ui/getQuickInsertComponents");
|
|
29
30
|
var _ModalElementBrowser = _interopRequireDefault(require("./ui/ModalElementBrowser"));
|
|
30
31
|
var _RegistryElementBrowser = require("./ui/RegistryElementBrowser");
|
|
@@ -106,6 +107,23 @@ var quickInsertPlugin = exports.quickInsertPlugin = function quickInsertPlugin(_
|
|
|
106
107
|
isRecommendedItem: options === null || options === void 0 ? void 0 : options.isRecommendedItem
|
|
107
108
|
}));
|
|
108
109
|
}
|
|
110
|
+
if ((0, _isExperimentEnabled.isExperimentEnabled)('platform_editor_block_control_migration')) {
|
|
111
|
+
var _api$uiControlRegistr2;
|
|
112
|
+
api === null || api === void 0 || (_api$uiControlRegistr2 = api.uiControlRegistry) === null || _api$uiControlRegistr2 === void 0 || _api$uiControlRegistr2.actions.register((0, _blockControlQuickInsert.getBlockControlQuickInsertComponents)({
|
|
113
|
+
api: api,
|
|
114
|
+
getEditorView: function getEditorView() {
|
|
115
|
+
return refs.editorView;
|
|
116
|
+
},
|
|
117
|
+
openTypeAhead: function openTypeAhead() {
|
|
118
|
+
var _api$typeAhead;
|
|
119
|
+
return api === null || api === void 0 || (_api$typeAhead = api.typeAhead) === null || _api$typeAhead === void 0 ? void 0 : _api$typeAhead.actions.open({
|
|
120
|
+
triggerHandler: typeAhead,
|
|
121
|
+
inputMethod: 'blockControl',
|
|
122
|
+
removePrefixTriggerOnCancel: true
|
|
123
|
+
});
|
|
124
|
+
}
|
|
125
|
+
}));
|
|
126
|
+
}
|
|
109
127
|
var openElementBrowser = function openElementBrowser(options) {
|
|
110
128
|
return function (_ref5) {
|
|
111
129
|
var tr = _ref5.tr;
|
|
@@ -157,6 +175,7 @@ var quickInsertPlugin = exports.quickInsertPlugin = function quickInsertPlugin(_
|
|
|
157
175
|
var editorView = _ref7.editorView,
|
|
158
176
|
popupsMountPoint = _ref7.popupsMountPoint,
|
|
159
177
|
wrapperElement = _ref7.wrapperElement;
|
|
178
|
+
refs.editorView = editorView || undefined;
|
|
160
179
|
refs.popupsMountPoint = popupsMountPoint || undefined;
|
|
161
180
|
refs.wrapperElement = wrapperElement || undefined;
|
|
162
181
|
if (!editorView || (0, _coreUtils.isSSR)()) {
|
|
@@ -195,8 +214,8 @@ var quickInsertPlugin = exports.quickInsertPlugin = function quickInsertPlugin(_
|
|
|
195
214
|
actions: {
|
|
196
215
|
insertItem: (0, _commands.createInsertItem)(onInsert),
|
|
197
216
|
openTypeAhead: function openTypeAhead(inputMethod, removePrefixTriggerOnCancel) {
|
|
198
|
-
var _api$
|
|
199
|
-
return Boolean(api === null || api === void 0 || (_api$
|
|
217
|
+
var _api$typeAhead2;
|
|
218
|
+
return Boolean(api === null || api === void 0 || (_api$typeAhead2 = api.typeAhead) === null || _api$typeAhead2 === void 0 ? void 0 : _api$typeAhead2.actions.open({
|
|
200
219
|
triggerHandler: typeAhead,
|
|
201
220
|
inputMethod: inputMethod,
|
|
202
221
|
removePrefixTriggerOnCancel: removePrefixTriggerOnCancel
|
|
@@ -369,7 +388,7 @@ function quickInsertPluginFactory(defaultItems, providerFactory, getIntl, dispat
|
|
|
369
388
|
var isDestroyed = false;
|
|
370
389
|
var providerHandler = /*#__PURE__*/function () {
|
|
371
390
|
var _ref14 = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee(_name, providerPromise) {
|
|
372
|
-
var provider, providedItems, _api$
|
|
391
|
+
var provider, providedItems, _api$uiControlRegistr3, directComponents, components, _t, _t2;
|
|
373
392
|
return _regenerator.default.wrap(function (_context) {
|
|
374
393
|
while (1) switch (_context.prev = _context.next) {
|
|
375
394
|
case 0:
|
|
@@ -410,7 +429,7 @@ function quickInsertPluginFactory(defaultItems, providerFactory, getIntl, dispat
|
|
|
410
429
|
onInsert: onInsert,
|
|
411
430
|
providedItems: providedItems
|
|
412
431
|
});
|
|
413
|
-
api === null || api === void 0 || (_api$
|
|
432
|
+
api === null || api === void 0 || (_api$uiControlRegistr3 = api.uiControlRegistry) === null || _api$uiControlRegistr3 === void 0 || _api$uiControlRegistr3.actions.register(components);
|
|
414
433
|
case 7:
|
|
415
434
|
setProviderState({
|
|
416
435
|
provider: provider,
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
._19itglyw{border:none}
|
|
2
|
+
._2rko1rr0{border-radius:var(--ds-radius-full,9999px)}
|
|
3
|
+
._18zrze3t{padding-inline:var(--ds-space-0,0)}
|
|
4
|
+
._1rjcze3t{padding-block:var(--ds-space-0,0)}
|
|
5
|
+
._1bah1h6o{justify-content:center}
|
|
6
|
+
._1bsb1osq{width:100%}
|
|
7
|
+
._1bsb9xsi{width:calc(var(--ak-editor-base-font-size, 1pc)*24/16)}
|
|
8
|
+
._1e0c1txw{display:flex}
|
|
9
|
+
._4cvr1h6o{align-items:center}
|
|
10
|
+
._4t3i1osq{height:100%}
|
|
11
|
+
._4t3i9xsi{height:calc(var(--ak-editor-base-font-size, 1pc)*24/16)}
|
|
12
|
+
._80omtlke{cursor:pointer}
|
|
13
|
+
._bfhksm61{background-color:var(--ds-background-neutral-subtle,#00000000)}
|
|
14
|
+
._syazazsu{color:var(--ds-text-subtle,#505258)}
|
|
15
|
+
._vchhusvi{box-sizing:border-box}._128mdkaa:focus-visible{outline-width:var(--ds-border-width-focused,2px)}
|
|
16
|
+
._1ah3v77o:focus-visible{outline-offset:var(--ds-space-025,2px)}
|
|
17
|
+
._mizu1v1w:focus-visible{outline-color:var(--ds-border-focused,#4688ec)}
|
|
18
|
+
._ra3xnqa1:focus-visible{outline-style:solid}
|
|
19
|
+
._irr31dpa:hover{background-color:var(--ds-background-neutral-subtle-hovered,#0515240f)}
|
|
20
|
+
._1di6fcek:active{background-color:var(--ds-background-neutral-subtle-pressed,#0b120e24)}
|
|
@@ -0,0 +1,163 @@
|
|
|
1
|
+
/* BlockControlQuickInsertButton.tsx generated by @compiled/babel-plugin v2.0.0 */
|
|
2
|
+
"use strict";
|
|
3
|
+
|
|
4
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
5
|
+
var _typeof = require("@babel/runtime/helpers/typeof");
|
|
6
|
+
Object.defineProperty(exports, "__esModule", {
|
|
7
|
+
value: true
|
|
8
|
+
});
|
|
9
|
+
exports.BlockControlQuickInsertButton = void 0;
|
|
10
|
+
require("./BlockControlQuickInsertButton.compiled.css");
|
|
11
|
+
var _runtime = require("@compiled/react/runtime");
|
|
12
|
+
var _react = _interopRequireWildcard(require("react"));
|
|
13
|
+
var _reactIntl = require("react-intl");
|
|
14
|
+
var _keymaps = require("@atlaskit/editor-common/keymaps");
|
|
15
|
+
var _messages = require("@atlaskit/editor-common/messages");
|
|
16
|
+
var _state = require("@atlaskit/editor-prosemirror/state");
|
|
17
|
+
var _utils = require("@atlaskit/editor-prosemirror/utils");
|
|
18
|
+
var _cellSelection = require("@atlaskit/editor-tables/cell-selection");
|
|
19
|
+
var _add = _interopRequireDefault(require("@atlaskit/icon/core/add"));
|
|
20
|
+
var _compiled = require("@atlaskit/primitives/compiled");
|
|
21
|
+
var _Tooltip = _interopRequireDefault(require("@atlaskit/tooltip/Tooltip"));
|
|
22
|
+
function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function _interopRequireWildcard(e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, default: e }; if (null === e || "object" != _typeof(e) && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (var _t in e) "default" !== _t && {}.hasOwnProperty.call(e, _t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, _t)) && (i.get || i.set) ? o(f, _t, i) : f[_t] = e[_t]); return f; })(e, t); }
|
|
23
|
+
var TEXT_PARENT_TYPES = ['paragraph', 'heading', 'blockquote', 'taskItem', 'decisionItem'];
|
|
24
|
+
|
|
25
|
+
// @atlaskit/css intentionally restricts height and width values, so Compiled owns only the
|
|
26
|
+
// dimensions that scale at runtime with the editor's dense-mode font-size custom property.
|
|
27
|
+
var quickInsertButtonContainerStyles = {
|
|
28
|
+
root: "_1e0c1txw _4t3i9xsi _1bsb9xsi"
|
|
29
|
+
};
|
|
30
|
+
var quickInsertButtonStyles = {
|
|
31
|
+
root: "_19itglyw _2rko1rr0 _1rjcze3t _18zrze3t _4cvr1h6o _bfhksm61 _vchhusvi _syazazsu _80omtlke _1e0c1txw _4t3i1osq _1bah1h6o _1bsb1osq _mizu1v1w _1ah3v77o _ra3xnqa1 _128mdkaa _irr31dpa _1di6fcek"
|
|
32
|
+
};
|
|
33
|
+
var createNewLine = function createNewLine(start) {
|
|
34
|
+
return function (_ref) {
|
|
35
|
+
var _tr$doc$nodeAt;
|
|
36
|
+
var tr = _ref.tr;
|
|
37
|
+
var nodeSize = (_tr$doc$nodeAt = tr.doc.nodeAt(start)) === null || _tr$doc$nodeAt === void 0 ? void 0 : _tr$doc$nodeAt.nodeSize;
|
|
38
|
+
if (nodeSize === undefined) {
|
|
39
|
+
return tr;
|
|
40
|
+
}
|
|
41
|
+
var position = start + nodeSize;
|
|
42
|
+
tr.insert(position, tr.doc.type.schema.nodes.paragraph.create());
|
|
43
|
+
return tr.setSelection(_state.TextSelection.near(tr.doc.resolve(position)));
|
|
44
|
+
};
|
|
45
|
+
};
|
|
46
|
+
var isSelectionInNode = function isSelectionInNode(start, view) {
|
|
47
|
+
var node = view.state.doc.nodeAt(start);
|
|
48
|
+
if (!node) {
|
|
49
|
+
return false;
|
|
50
|
+
}
|
|
51
|
+
var _view$state$selection = view.state.selection,
|
|
52
|
+
$from = _view$state$selection.$from,
|
|
53
|
+
$to = _view$state$selection.$to;
|
|
54
|
+
return $from.pos >= start && $to.pos <= start + node.nodeSize;
|
|
55
|
+
};
|
|
56
|
+
var isNonEditableBlock = function isNonEditableBlock(start, view) {
|
|
57
|
+
var node = view.state.doc.nodeAt(start);
|
|
58
|
+
if (!node) {
|
|
59
|
+
return false;
|
|
60
|
+
}
|
|
61
|
+
if (node.type.name === 'mediaGroup' || node.type.name === 'mediaSingle') {
|
|
62
|
+
return true;
|
|
63
|
+
}
|
|
64
|
+
return node.isBlock && (node.isAtom || node.isLeaf);
|
|
65
|
+
};
|
|
66
|
+
var openQuickInsert = function openQuickInsert(api, view, start, openTypeAhead) {
|
|
67
|
+
var isSelectionInsideNode = isSelectionInNode(start, view);
|
|
68
|
+
if (!isSelectionInsideNode || isNonEditableBlock(start, view)) {
|
|
69
|
+
api.core.actions.execute(createNewLine(start));
|
|
70
|
+
}
|
|
71
|
+
var codeBlock = view.state.schema.nodes.codeBlock;
|
|
72
|
+
var selection = view.state.selection;
|
|
73
|
+
var codeBlockParentNode = (0, _utils.findParentNodeOfType)(codeBlock)(selection);
|
|
74
|
+
if (codeBlockParentNode) {
|
|
75
|
+
api.core.actions.execute(createNewLine(codeBlockParentNode.pos));
|
|
76
|
+
} else if (isSelectionInsideNode) {
|
|
77
|
+
var currentSelection = view.state.selection;
|
|
78
|
+
if ((currentSelection instanceof _state.TextSelection || currentSelection instanceof _state.NodeSelection && currentSelection.node.isInline) && currentSelection.from !== currentSelection.to) {
|
|
79
|
+
var currentParagraphNode = (0, _utils.findParentNode)(function (node) {
|
|
80
|
+
return TEXT_PARENT_TYPES.includes(node.type.name);
|
|
81
|
+
})(currentSelection);
|
|
82
|
+
if (currentParagraphNode) {
|
|
83
|
+
var newPos = currentSelection.anchor === currentSelection.to ? currentParagraphNode.pos : currentParagraphNode.pos + currentParagraphNode.node.nodeSize - 1;
|
|
84
|
+
api.core.actions.execute(function (_ref2) {
|
|
85
|
+
var tr = _ref2.tr;
|
|
86
|
+
tr.setSelection(_state.TextSelection.create(view.state.selection.$from.doc, newPos));
|
|
87
|
+
return tr;
|
|
88
|
+
});
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
if (currentSelection instanceof _state.NodeSelection && currentSelection.$from.depth > 0) {
|
|
92
|
+
if (isNonEditableBlock(view.state.selection.from, view)) {
|
|
93
|
+
api.core.actions.execute(createNewLine(view.state.selection.from));
|
|
94
|
+
} else {
|
|
95
|
+
api.core.actions.execute(function (_ref3) {
|
|
96
|
+
var tr = _ref3.tr;
|
|
97
|
+
createNewLine(view.state.selection.from)({
|
|
98
|
+
tr: tr
|
|
99
|
+
});
|
|
100
|
+
tr.setSelection(_state.TextSelection.create(tr.doc, view.state.selection.from));
|
|
101
|
+
return tr;
|
|
102
|
+
});
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
if (currentSelection instanceof _cellSelection.CellSelection) {
|
|
106
|
+
var lastInlinePosition = _state.TextSelection.near(view.state.selection.$to, -1);
|
|
107
|
+
if (lastInlinePosition) {
|
|
108
|
+
api.core.actions.execute(function (_ref4) {
|
|
109
|
+
var tr = _ref4.tr;
|
|
110
|
+
if (!(lastInlinePosition instanceof _state.TextSelection)) {
|
|
111
|
+
createNewLine(lastInlinePosition.from)({
|
|
112
|
+
tr: tr
|
|
113
|
+
});
|
|
114
|
+
tr.setSelection(_state.TextSelection.create(tr.doc, lastInlinePosition.to));
|
|
115
|
+
} else {
|
|
116
|
+
tr.setSelection(lastInlinePosition);
|
|
117
|
+
}
|
|
118
|
+
return tr;
|
|
119
|
+
});
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
openTypeAhead();
|
|
124
|
+
};
|
|
125
|
+
var BlockControlQuickInsertButton = exports.BlockControlQuickInsertButton = function BlockControlQuickInsertButton(_ref5) {
|
|
126
|
+
var api = _ref5.api,
|
|
127
|
+
openTypeAhead = _ref5.openTypeAhead,
|
|
128
|
+
start = _ref5.start,
|
|
129
|
+
view = _ref5.view;
|
|
130
|
+
var _useIntl = (0, _reactIntl.useIntl)(),
|
|
131
|
+
formatMessage = _useIntl.formatMessage;
|
|
132
|
+
var label = formatMessage(_messages.blockControlsMessages.insert);
|
|
133
|
+
var handleMouseDown = (0, _react.useCallback)(function () {
|
|
134
|
+
var _api$typeAhead;
|
|
135
|
+
if ((_api$typeAhead = api.typeAhead) !== null && _api$typeAhead !== void 0 && _api$typeAhead.actions.isOpen(view.state)) {
|
|
136
|
+
api.typeAhead.actions.close({
|
|
137
|
+
insertCurrentQueryAsRawText: false
|
|
138
|
+
});
|
|
139
|
+
}
|
|
140
|
+
}, [api, view]);
|
|
141
|
+
var handleClick = (0, _react.useCallback)(function () {
|
|
142
|
+
return openQuickInsert(api, view, start, openTypeAhead);
|
|
143
|
+
}, [api, openTypeAhead, start, view]);
|
|
144
|
+
return /*#__PURE__*/_react.default.createElement(_Tooltip.default, {
|
|
145
|
+
position: "top",
|
|
146
|
+
content: /*#__PURE__*/_react.default.createElement(_keymaps.ToolTipContent, {
|
|
147
|
+
description: label
|
|
148
|
+
})
|
|
149
|
+
}, /*#__PURE__*/_react.default.createElement("span", {
|
|
150
|
+
className: (0, _runtime.ax)([quickInsertButtonContainerStyles.root])
|
|
151
|
+
}, /*#__PURE__*/_react.default.createElement(_compiled.Pressable, {
|
|
152
|
+
"aria-label": label,
|
|
153
|
+
onClick: handleClick,
|
|
154
|
+
onMouseDown: handleMouseDown,
|
|
155
|
+
testId: "editor-quick-insert-button",
|
|
156
|
+
type: "button",
|
|
157
|
+
xcss: quickInsertButtonStyles.root
|
|
158
|
+
}, /*#__PURE__*/_react.default.createElement(_add.default, {
|
|
159
|
+
label: "",
|
|
160
|
+
color: "var(--ds-icon-subtle, #505258)",
|
|
161
|
+
size: "small"
|
|
162
|
+
}))));
|
|
163
|
+
};
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
+
Object.defineProperty(exports, "__esModule", {
|
|
5
|
+
value: true
|
|
6
|
+
});
|
|
7
|
+
exports.getBlockControlQuickInsertComponents = void 0;
|
|
8
|
+
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
9
|
+
var _react = _interopRequireDefault(require("react"));
|
|
10
|
+
var _blockControlUiContext = require("@atlaskit/editor-common/block-controls/block-control-ui-context");
|
|
11
|
+
var _surfaceKeys = require("@atlaskit/editor-common/block-controls/surface-keys");
|
|
12
|
+
var _BlockControlQuickInsertButton = require("./BlockControlQuickInsertButton");
|
|
13
|
+
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; }
|
|
14
|
+
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; }
|
|
15
|
+
var getBlockControlQuickInsertComponents = exports.getBlockControlQuickInsertComponents = function getBlockControlQuickInsertComponents(_ref) {
|
|
16
|
+
var api = _ref.api,
|
|
17
|
+
getEditorView = _ref.getEditorView,
|
|
18
|
+
openTypeAhead = _ref.openTypeAhead;
|
|
19
|
+
return [{
|
|
20
|
+
key: 'block-controls-quick-insert',
|
|
21
|
+
type: 'button',
|
|
22
|
+
parents: [_objectSpread(_objectSpread({}, _surfaceKeys.BLOCK_CONTROLS_LEFT_GROUP), {}, {
|
|
23
|
+
rank: 100
|
|
24
|
+
})],
|
|
25
|
+
isHidden: function isHidden() {
|
|
26
|
+
var _ref2 = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {},
|
|
27
|
+
surfaceContext = _ref2.surfaceContext;
|
|
28
|
+
return (surfaceContext === null || surfaceContext === void 0 ? void 0 : surfaceContext.get(_blockControlUiContext.BLOCK_CONTROL_UI_CONTEXT)) === undefined;
|
|
29
|
+
},
|
|
30
|
+
component: function component(_ref3) {
|
|
31
|
+
var surfaceContext = _ref3.surfaceContext;
|
|
32
|
+
var context = surfaceContext === null || surfaceContext === void 0 ? void 0 : surfaceContext.get(_blockControlUiContext.BLOCK_CONTROL_UI_CONTEXT);
|
|
33
|
+
var view = getEditorView();
|
|
34
|
+
if (!context || !view) {
|
|
35
|
+
return null;
|
|
36
|
+
}
|
|
37
|
+
return /*#__PURE__*/_react.default.createElement(_BlockControlQuickInsertButton.BlockControlQuickInsertButton, {
|
|
38
|
+
api: api,
|
|
39
|
+
openTypeAhead: openTypeAhead,
|
|
40
|
+
start: context.targetNode.pos,
|
|
41
|
+
view: view
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
}];
|
|
45
|
+
};
|
|
@@ -14,6 +14,7 @@ import { createInsertItem, openElementBrowser as openElementBrowserCommand, open
|
|
|
14
14
|
import { getQuickInsertOpenExperiencePlugin } from './pm-plugins/experiences/quick-insert-open-experience';
|
|
15
15
|
import { pluginKey } from './pm-plugins/plugin-key';
|
|
16
16
|
import { getLegacyCompatibleComponents } from './ui/getLegacyCompatibleComponents';
|
|
17
|
+
import { getBlockControlQuickInsertComponents } from './ui/block-control-quick-insert';
|
|
17
18
|
import { getQuickInsertComponents } from './ui/getQuickInsertComponents';
|
|
18
19
|
import ModalElementBrowser from './ui/ModalElementBrowser';
|
|
19
20
|
import { RegistryElementBrowserContainer } from './ui/RegistryElementBrowser';
|
|
@@ -95,6 +96,21 @@ export const quickInsertPlugin = ({
|
|
|
95
96
|
isRecommendedItem: options === null || options === void 0 ? void 0 : options.isRecommendedItem
|
|
96
97
|
}));
|
|
97
98
|
}
|
|
99
|
+
if (isExperimentEnabled('platform_editor_block_control_migration')) {
|
|
100
|
+
var _api$uiControlRegistr2;
|
|
101
|
+
api === null || api === void 0 ? void 0 : (_api$uiControlRegistr2 = api.uiControlRegistry) === null || _api$uiControlRegistr2 === void 0 ? void 0 : _api$uiControlRegistr2.actions.register(getBlockControlQuickInsertComponents({
|
|
102
|
+
api,
|
|
103
|
+
getEditorView: () => refs.editorView,
|
|
104
|
+
openTypeAhead: () => {
|
|
105
|
+
var _api$typeAhead;
|
|
106
|
+
return api === null || api === void 0 ? void 0 : (_api$typeAhead = api.typeAhead) === null || _api$typeAhead === void 0 ? void 0 : _api$typeAhead.actions.open({
|
|
107
|
+
triggerHandler: typeAhead,
|
|
108
|
+
inputMethod: 'blockControl',
|
|
109
|
+
removePrefixTriggerOnCancel: true
|
|
110
|
+
});
|
|
111
|
+
}
|
|
112
|
+
}));
|
|
113
|
+
}
|
|
98
114
|
const openElementBrowser = options => ({
|
|
99
115
|
tr
|
|
100
116
|
}) => {
|
|
@@ -143,6 +159,7 @@ export const quickInsertPlugin = ({
|
|
|
143
159
|
popupsMountPoint,
|
|
144
160
|
wrapperElement
|
|
145
161
|
}) {
|
|
162
|
+
refs.editorView = editorView || undefined;
|
|
146
163
|
refs.popupsMountPoint = popupsMountPoint || undefined;
|
|
147
164
|
refs.wrapperElement = wrapperElement || undefined;
|
|
148
165
|
if (!editorView || isSSR()) {
|
|
@@ -181,11 +198,11 @@ export const quickInsertPlugin = ({
|
|
|
181
198
|
actions: {
|
|
182
199
|
insertItem: createInsertItem(onInsert),
|
|
183
200
|
openTypeAhead(inputMethod, removePrefixTriggerOnCancel) {
|
|
184
|
-
var _api$
|
|
185
|
-
return Boolean(api === null || api === void 0 ? void 0 : (_api$
|
|
201
|
+
var _api$typeAhead2;
|
|
202
|
+
return Boolean(api === null || api === void 0 ? void 0 : (_api$typeAhead2 = api.typeAhead) === null || _api$typeAhead2 === void 0 ? void 0 : _api$typeAhead2.actions.open({
|
|
186
203
|
triggerHandler: typeAhead,
|
|
187
204
|
inputMethod,
|
|
188
|
-
removePrefixTriggerOnCancel
|
|
205
|
+
removePrefixTriggerOnCancel
|
|
189
206
|
}));
|
|
190
207
|
},
|
|
191
208
|
getSuggestions: searchOptions => {
|
|
@@ -340,7 +357,7 @@ function quickInsertPluginFactory(defaultItems, providerFactory, getIntl, dispat
|
|
|
340
357
|
const provider = await providerPromise;
|
|
341
358
|
const providedItems = await provider.getItems();
|
|
342
359
|
if (isExperimentEnabled('platform_editor_slash_command')) {
|
|
343
|
-
var _api$
|
|
360
|
+
var _api$uiControlRegistr3;
|
|
344
361
|
const directComponents = provider.getComponents ? await provider.getComponents() : [];
|
|
345
362
|
const components = getLegacyCompatibleComponents({
|
|
346
363
|
directComponents,
|
|
@@ -348,7 +365,7 @@ function quickInsertPluginFactory(defaultItems, providerFactory, getIntl, dispat
|
|
|
348
365
|
onInsert,
|
|
349
366
|
providedItems
|
|
350
367
|
});
|
|
351
|
-
api === null || api === void 0 ? void 0 : (_api$
|
|
368
|
+
api === null || api === void 0 ? void 0 : (_api$uiControlRegistr3 = api.uiControlRegistry) === null || _api$uiControlRegistr3 === void 0 ? void 0 : _api$uiControlRegistr3.actions.register(components);
|
|
352
369
|
}
|
|
353
370
|
setProviderState({
|
|
354
371
|
provider,
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
._19itglyw{border:none}
|
|
2
|
+
._2rko1rr0{border-radius:var(--ds-radius-full,9999px)}
|
|
3
|
+
._18zrze3t{padding-inline:var(--ds-space-0,0)}
|
|
4
|
+
._1rjcze3t{padding-block:var(--ds-space-0,0)}
|
|
5
|
+
._1bah1h6o{justify-content:center}
|
|
6
|
+
._1bsb1osq{width:100%}
|
|
7
|
+
._1bsb9xsi{width:calc(var(--ak-editor-base-font-size, 1pc)*24/16)}
|
|
8
|
+
._1e0c1txw{display:flex}
|
|
9
|
+
._4cvr1h6o{align-items:center}
|
|
10
|
+
._4t3i1osq{height:100%}
|
|
11
|
+
._4t3i9xsi{height:calc(var(--ak-editor-base-font-size, 1pc)*24/16)}
|
|
12
|
+
._80omtlke{cursor:pointer}
|
|
13
|
+
._bfhksm61{background-color:var(--ds-background-neutral-subtle,#00000000)}
|
|
14
|
+
._syazazsu{color:var(--ds-text-subtle,#505258)}
|
|
15
|
+
._vchhusvi{box-sizing:border-box}._128mdkaa:focus-visible{outline-width:var(--ds-border-width-focused,2px)}
|
|
16
|
+
._1ah3v77o:focus-visible{outline-offset:var(--ds-space-025,2px)}
|
|
17
|
+
._mizu1v1w:focus-visible{outline-color:var(--ds-border-focused,#4688ec)}
|
|
18
|
+
._ra3xnqa1:focus-visible{outline-style:solid}
|
|
19
|
+
._irr31dpa:hover{background-color:var(--ds-background-neutral-subtle-hovered,#0515240f)}
|
|
20
|
+
._1di6fcek:active{background-color:var(--ds-background-neutral-subtle-pressed,#0b120e24)}
|
|
@@ -0,0 +1,159 @@
|
|
|
1
|
+
/* BlockControlQuickInsertButton.tsx generated by @compiled/babel-plugin v2.0.0 */
|
|
2
|
+
import "./BlockControlQuickInsertButton.compiled.css";
|
|
3
|
+
import { ax, ix } from "@compiled/react/runtime";
|
|
4
|
+
import React, { useCallback } from 'react';
|
|
5
|
+
import { useIntl } from 'react-intl';
|
|
6
|
+
import { ToolTipContent } from '@atlaskit/editor-common/keymaps';
|
|
7
|
+
import { blockControlsMessages as messages } from '@atlaskit/editor-common/messages';
|
|
8
|
+
import { NodeSelection, 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 AddIcon from '@atlaskit/icon/core/add';
|
|
12
|
+
import { Pressable } from '@atlaskit/primitives/compiled';
|
|
13
|
+
import Tooltip from '@atlaskit/tooltip/Tooltip';
|
|
14
|
+
const TEXT_PARENT_TYPES = ['paragraph', 'heading', 'blockquote', 'taskItem', 'decisionItem'];
|
|
15
|
+
|
|
16
|
+
// @atlaskit/css intentionally restricts height and width values, so Compiled owns only the
|
|
17
|
+
// dimensions that scale at runtime with the editor's dense-mode font-size custom property.
|
|
18
|
+
const quickInsertButtonContainerStyles = {
|
|
19
|
+
root: "_1e0c1txw _4t3i9xsi _1bsb9xsi"
|
|
20
|
+
};
|
|
21
|
+
const quickInsertButtonStyles = {
|
|
22
|
+
root: "_19itglyw _2rko1rr0 _1rjcze3t _18zrze3t _4cvr1h6o _bfhksm61 _vchhusvi _syazazsu _80omtlke _1e0c1txw _4t3i1osq _1bah1h6o _1bsb1osq _mizu1v1w _1ah3v77o _ra3xnqa1 _128mdkaa _irr31dpa _1di6fcek"
|
|
23
|
+
};
|
|
24
|
+
const createNewLine = start => ({
|
|
25
|
+
tr
|
|
26
|
+
}) => {
|
|
27
|
+
var _tr$doc$nodeAt;
|
|
28
|
+
const nodeSize = (_tr$doc$nodeAt = tr.doc.nodeAt(start)) === null || _tr$doc$nodeAt === void 0 ? void 0 : _tr$doc$nodeAt.nodeSize;
|
|
29
|
+
if (nodeSize === undefined) {
|
|
30
|
+
return tr;
|
|
31
|
+
}
|
|
32
|
+
const position = start + nodeSize;
|
|
33
|
+
tr.insert(position, tr.doc.type.schema.nodes.paragraph.create());
|
|
34
|
+
return tr.setSelection(TextSelection.near(tr.doc.resolve(position)));
|
|
35
|
+
};
|
|
36
|
+
const isSelectionInNode = (start, view) => {
|
|
37
|
+
const node = view.state.doc.nodeAt(start);
|
|
38
|
+
if (!node) {
|
|
39
|
+
return false;
|
|
40
|
+
}
|
|
41
|
+
const {
|
|
42
|
+
$from,
|
|
43
|
+
$to
|
|
44
|
+
} = view.state.selection;
|
|
45
|
+
return $from.pos >= start && $to.pos <= start + node.nodeSize;
|
|
46
|
+
};
|
|
47
|
+
const isNonEditableBlock = (start, view) => {
|
|
48
|
+
const node = view.state.doc.nodeAt(start);
|
|
49
|
+
if (!node) {
|
|
50
|
+
return false;
|
|
51
|
+
}
|
|
52
|
+
if (node.type.name === 'mediaGroup' || node.type.name === 'mediaSingle') {
|
|
53
|
+
return true;
|
|
54
|
+
}
|
|
55
|
+
return node.isBlock && (node.isAtom || node.isLeaf);
|
|
56
|
+
};
|
|
57
|
+
const openQuickInsert = (api, view, start, openTypeAhead) => {
|
|
58
|
+
const isSelectionInsideNode = isSelectionInNode(start, view);
|
|
59
|
+
if (!isSelectionInsideNode || isNonEditableBlock(start, view)) {
|
|
60
|
+
api.core.actions.execute(createNewLine(start));
|
|
61
|
+
}
|
|
62
|
+
const {
|
|
63
|
+
codeBlock
|
|
64
|
+
} = view.state.schema.nodes;
|
|
65
|
+
const {
|
|
66
|
+
selection
|
|
67
|
+
} = view.state;
|
|
68
|
+
const codeBlockParentNode = findParentNodeOfType(codeBlock)(selection);
|
|
69
|
+
if (codeBlockParentNode) {
|
|
70
|
+
api.core.actions.execute(createNewLine(codeBlockParentNode.pos));
|
|
71
|
+
} else if (isSelectionInsideNode) {
|
|
72
|
+
const currentSelection = view.state.selection;
|
|
73
|
+
if ((currentSelection instanceof TextSelection || currentSelection instanceof NodeSelection && currentSelection.node.isInline) && currentSelection.from !== currentSelection.to) {
|
|
74
|
+
const currentParagraphNode = findParentNode(node => TEXT_PARENT_TYPES.includes(node.type.name))(currentSelection);
|
|
75
|
+
if (currentParagraphNode) {
|
|
76
|
+
const newPos = currentSelection.anchor === currentSelection.to ? currentParagraphNode.pos : currentParagraphNode.pos + currentParagraphNode.node.nodeSize - 1;
|
|
77
|
+
api.core.actions.execute(({
|
|
78
|
+
tr
|
|
79
|
+
}) => {
|
|
80
|
+
tr.setSelection(TextSelection.create(view.state.selection.$from.doc, newPos));
|
|
81
|
+
return tr;
|
|
82
|
+
});
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
if (currentSelection instanceof NodeSelection && currentSelection.$from.depth > 0) {
|
|
86
|
+
if (isNonEditableBlock(view.state.selection.from, view)) {
|
|
87
|
+
api.core.actions.execute(createNewLine(view.state.selection.from));
|
|
88
|
+
} else {
|
|
89
|
+
api.core.actions.execute(({
|
|
90
|
+
tr
|
|
91
|
+
}) => {
|
|
92
|
+
createNewLine(view.state.selection.from)({
|
|
93
|
+
tr
|
|
94
|
+
});
|
|
95
|
+
tr.setSelection(TextSelection.create(tr.doc, view.state.selection.from));
|
|
96
|
+
return tr;
|
|
97
|
+
});
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
if (currentSelection instanceof CellSelection) {
|
|
101
|
+
const lastInlinePosition = TextSelection.near(view.state.selection.$to, -1);
|
|
102
|
+
if (lastInlinePosition) {
|
|
103
|
+
api.core.actions.execute(({
|
|
104
|
+
tr
|
|
105
|
+
}) => {
|
|
106
|
+
if (!(lastInlinePosition instanceof TextSelection)) {
|
|
107
|
+
createNewLine(lastInlinePosition.from)({
|
|
108
|
+
tr
|
|
109
|
+
});
|
|
110
|
+
tr.setSelection(TextSelection.create(tr.doc, lastInlinePosition.to));
|
|
111
|
+
} else {
|
|
112
|
+
tr.setSelection(lastInlinePosition);
|
|
113
|
+
}
|
|
114
|
+
return tr;
|
|
115
|
+
});
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
openTypeAhead();
|
|
120
|
+
};
|
|
121
|
+
export const BlockControlQuickInsertButton = ({
|
|
122
|
+
api,
|
|
123
|
+
openTypeAhead,
|
|
124
|
+
start,
|
|
125
|
+
view
|
|
126
|
+
}) => {
|
|
127
|
+
const {
|
|
128
|
+
formatMessage
|
|
129
|
+
} = useIntl();
|
|
130
|
+
const label = formatMessage(messages.insert);
|
|
131
|
+
const handleMouseDown = useCallback(() => {
|
|
132
|
+
var _api$typeAhead;
|
|
133
|
+
if ((_api$typeAhead = api.typeAhead) !== null && _api$typeAhead !== void 0 && _api$typeAhead.actions.isOpen(view.state)) {
|
|
134
|
+
api.typeAhead.actions.close({
|
|
135
|
+
insertCurrentQueryAsRawText: false
|
|
136
|
+
});
|
|
137
|
+
}
|
|
138
|
+
}, [api, view]);
|
|
139
|
+
const handleClick = useCallback(() => openQuickInsert(api, view, start, openTypeAhead), [api, openTypeAhead, start, view]);
|
|
140
|
+
return /*#__PURE__*/React.createElement(Tooltip, {
|
|
141
|
+
position: "top",
|
|
142
|
+
content: /*#__PURE__*/React.createElement(ToolTipContent, {
|
|
143
|
+
description: label
|
|
144
|
+
})
|
|
145
|
+
}, /*#__PURE__*/React.createElement("span", {
|
|
146
|
+
className: ax([quickInsertButtonContainerStyles.root])
|
|
147
|
+
}, /*#__PURE__*/React.createElement(Pressable, {
|
|
148
|
+
"aria-label": label,
|
|
149
|
+
onClick: handleClick,
|
|
150
|
+
onMouseDown: handleMouseDown,
|
|
151
|
+
testId: "editor-quick-insert-button",
|
|
152
|
+
type: "button",
|
|
153
|
+
xcss: quickInsertButtonStyles.root
|
|
154
|
+
}, /*#__PURE__*/React.createElement(AddIcon, {
|
|
155
|
+
label: "",
|
|
156
|
+
color: "var(--ds-icon-subtle, #505258)",
|
|
157
|
+
size: "small"
|
|
158
|
+
}))));
|
|
159
|
+
};
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { BLOCK_CONTROL_UI_CONTEXT } from '@atlaskit/editor-common/block-controls/block-control-ui-context';
|
|
3
|
+
import { BLOCK_CONTROLS_LEFT_GROUP } from '@atlaskit/editor-common/block-controls/surface-keys';
|
|
4
|
+
import { BlockControlQuickInsertButton } from './BlockControlQuickInsertButton';
|
|
5
|
+
export const getBlockControlQuickInsertComponents = ({
|
|
6
|
+
api,
|
|
7
|
+
getEditorView,
|
|
8
|
+
openTypeAhead
|
|
9
|
+
}) => [{
|
|
10
|
+
key: 'block-controls-quick-insert',
|
|
11
|
+
type: 'button',
|
|
12
|
+
parents: [{
|
|
13
|
+
...BLOCK_CONTROLS_LEFT_GROUP,
|
|
14
|
+
rank: 100
|
|
15
|
+
}],
|
|
16
|
+
isHidden: ({
|
|
17
|
+
surfaceContext
|
|
18
|
+
} = {}) => (surfaceContext === null || surfaceContext === void 0 ? void 0 : surfaceContext.get(BLOCK_CONTROL_UI_CONTEXT)) === undefined,
|
|
19
|
+
component: ({
|
|
20
|
+
surfaceContext
|
|
21
|
+
}) => {
|
|
22
|
+
const context = surfaceContext === null || surfaceContext === void 0 ? void 0 : surfaceContext.get(BLOCK_CONTROL_UI_CONTEXT);
|
|
23
|
+
const view = getEditorView();
|
|
24
|
+
if (!context || !view) {
|
|
25
|
+
return null;
|
|
26
|
+
}
|
|
27
|
+
return /*#__PURE__*/React.createElement(BlockControlQuickInsertButton, {
|
|
28
|
+
api: api,
|
|
29
|
+
openTypeAhead: openTypeAhead,
|
|
30
|
+
start: context.targetNode.pos,
|
|
31
|
+
view: view
|
|
32
|
+
});
|
|
33
|
+
}
|
|
34
|
+
}];
|
|
@@ -20,6 +20,7 @@ import { createInsertItem, openElementBrowser as openElementBrowserCommand, open
|
|
|
20
20
|
import { getQuickInsertOpenExperiencePlugin } from './pm-plugins/experiences/quick-insert-open-experience';
|
|
21
21
|
import { pluginKey } from './pm-plugins/plugin-key';
|
|
22
22
|
import { getLegacyCompatibleComponents } from './ui/getLegacyCompatibleComponents';
|
|
23
|
+
import { getBlockControlQuickInsertComponents } from './ui/block-control-quick-insert';
|
|
23
24
|
import { getQuickInsertComponents } from './ui/getQuickInsertComponents';
|
|
24
25
|
import ModalElementBrowser from './ui/ModalElementBrowser';
|
|
25
26
|
import { RegistryElementBrowserContainer } from './ui/RegistryElementBrowser';
|
|
@@ -99,6 +100,23 @@ export var quickInsertPlugin = function quickInsertPlugin(_ref) {
|
|
|
99
100
|
isRecommendedItem: options === null || options === void 0 ? void 0 : options.isRecommendedItem
|
|
100
101
|
}));
|
|
101
102
|
}
|
|
103
|
+
if (isExperimentEnabled('platform_editor_block_control_migration')) {
|
|
104
|
+
var _api$uiControlRegistr2;
|
|
105
|
+
api === null || api === void 0 || (_api$uiControlRegistr2 = api.uiControlRegistry) === null || _api$uiControlRegistr2 === void 0 || _api$uiControlRegistr2.actions.register(getBlockControlQuickInsertComponents({
|
|
106
|
+
api: api,
|
|
107
|
+
getEditorView: function getEditorView() {
|
|
108
|
+
return refs.editorView;
|
|
109
|
+
},
|
|
110
|
+
openTypeAhead: function openTypeAhead() {
|
|
111
|
+
var _api$typeAhead;
|
|
112
|
+
return api === null || api === void 0 || (_api$typeAhead = api.typeAhead) === null || _api$typeAhead === void 0 ? void 0 : _api$typeAhead.actions.open({
|
|
113
|
+
triggerHandler: typeAhead,
|
|
114
|
+
inputMethod: 'blockControl',
|
|
115
|
+
removePrefixTriggerOnCancel: true
|
|
116
|
+
});
|
|
117
|
+
}
|
|
118
|
+
}));
|
|
119
|
+
}
|
|
102
120
|
var openElementBrowser = function openElementBrowser(options) {
|
|
103
121
|
return function (_ref5) {
|
|
104
122
|
var tr = _ref5.tr;
|
|
@@ -150,6 +168,7 @@ export var quickInsertPlugin = function quickInsertPlugin(_ref) {
|
|
|
150
168
|
var editorView = _ref7.editorView,
|
|
151
169
|
popupsMountPoint = _ref7.popupsMountPoint,
|
|
152
170
|
wrapperElement = _ref7.wrapperElement;
|
|
171
|
+
refs.editorView = editorView || undefined;
|
|
153
172
|
refs.popupsMountPoint = popupsMountPoint || undefined;
|
|
154
173
|
refs.wrapperElement = wrapperElement || undefined;
|
|
155
174
|
if (!editorView || isSSR()) {
|
|
@@ -188,8 +207,8 @@ export var quickInsertPlugin = function quickInsertPlugin(_ref) {
|
|
|
188
207
|
actions: {
|
|
189
208
|
insertItem: createInsertItem(onInsert),
|
|
190
209
|
openTypeAhead: function openTypeAhead(inputMethod, removePrefixTriggerOnCancel) {
|
|
191
|
-
var _api$
|
|
192
|
-
return Boolean(api === null || api === void 0 || (_api$
|
|
210
|
+
var _api$typeAhead2;
|
|
211
|
+
return Boolean(api === null || api === void 0 || (_api$typeAhead2 = api.typeAhead) === null || _api$typeAhead2 === void 0 ? void 0 : _api$typeAhead2.actions.open({
|
|
193
212
|
triggerHandler: typeAhead,
|
|
194
213
|
inputMethod: inputMethod,
|
|
195
214
|
removePrefixTriggerOnCancel: removePrefixTriggerOnCancel
|
|
@@ -362,7 +381,7 @@ function quickInsertPluginFactory(defaultItems, providerFactory, getIntl, dispat
|
|
|
362
381
|
var isDestroyed = false;
|
|
363
382
|
var providerHandler = /*#__PURE__*/function () {
|
|
364
383
|
var _ref14 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee(_name, providerPromise) {
|
|
365
|
-
var provider, providedItems, _api$
|
|
384
|
+
var provider, providedItems, _api$uiControlRegistr3, directComponents, components, _t, _t2;
|
|
366
385
|
return _regeneratorRuntime.wrap(function (_context) {
|
|
367
386
|
while (1) switch (_context.prev = _context.next) {
|
|
368
387
|
case 0:
|
|
@@ -403,7 +422,7 @@ function quickInsertPluginFactory(defaultItems, providerFactory, getIntl, dispat
|
|
|
403
422
|
onInsert: onInsert,
|
|
404
423
|
providedItems: providedItems
|
|
405
424
|
});
|
|
406
|
-
api === null || api === void 0 || (_api$
|
|
425
|
+
api === null || api === void 0 || (_api$uiControlRegistr3 = api.uiControlRegistry) === null || _api$uiControlRegistr3 === void 0 || _api$uiControlRegistr3.actions.register(components);
|
|
407
426
|
case 7:
|
|
408
427
|
setProviderState({
|
|
409
428
|
provider: provider,
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
._19itglyw{border:none}
|
|
2
|
+
._2rko1rr0{border-radius:var(--ds-radius-full,9999px)}
|
|
3
|
+
._18zrze3t{padding-inline:var(--ds-space-0,0)}
|
|
4
|
+
._1rjcze3t{padding-block:var(--ds-space-0,0)}
|
|
5
|
+
._1bah1h6o{justify-content:center}
|
|
6
|
+
._1bsb1osq{width:100%}
|
|
7
|
+
._1bsb9xsi{width:calc(var(--ak-editor-base-font-size, 1pc)*24/16)}
|
|
8
|
+
._1e0c1txw{display:flex}
|
|
9
|
+
._4cvr1h6o{align-items:center}
|
|
10
|
+
._4t3i1osq{height:100%}
|
|
11
|
+
._4t3i9xsi{height:calc(var(--ak-editor-base-font-size, 1pc)*24/16)}
|
|
12
|
+
._80omtlke{cursor:pointer}
|
|
13
|
+
._bfhksm61{background-color:var(--ds-background-neutral-subtle,#00000000)}
|
|
14
|
+
._syazazsu{color:var(--ds-text-subtle,#505258)}
|
|
15
|
+
._vchhusvi{box-sizing:border-box}._128mdkaa:focus-visible{outline-width:var(--ds-border-width-focused,2px)}
|
|
16
|
+
._1ah3v77o:focus-visible{outline-offset:var(--ds-space-025,2px)}
|
|
17
|
+
._mizu1v1w:focus-visible{outline-color:var(--ds-border-focused,#4688ec)}
|
|
18
|
+
._ra3xnqa1:focus-visible{outline-style:solid}
|
|
19
|
+
._irr31dpa:hover{background-color:var(--ds-background-neutral-subtle-hovered,#0515240f)}
|
|
20
|
+
._1di6fcek:active{background-color:var(--ds-background-neutral-subtle-pressed,#0b120e24)}
|
|
@@ -0,0 +1,154 @@
|
|
|
1
|
+
/* BlockControlQuickInsertButton.tsx generated by @compiled/babel-plugin v2.0.0 */
|
|
2
|
+
import "./BlockControlQuickInsertButton.compiled.css";
|
|
3
|
+
import { ax, ix } from "@compiled/react/runtime";
|
|
4
|
+
import React, { useCallback } from 'react';
|
|
5
|
+
import { useIntl } from 'react-intl';
|
|
6
|
+
import { ToolTipContent } from '@atlaskit/editor-common/keymaps';
|
|
7
|
+
import { blockControlsMessages as messages } from '@atlaskit/editor-common/messages';
|
|
8
|
+
import { NodeSelection, 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 AddIcon from '@atlaskit/icon/core/add';
|
|
12
|
+
import { Pressable } from '@atlaskit/primitives/compiled';
|
|
13
|
+
import Tooltip from '@atlaskit/tooltip/Tooltip';
|
|
14
|
+
var TEXT_PARENT_TYPES = ['paragraph', 'heading', 'blockquote', 'taskItem', 'decisionItem'];
|
|
15
|
+
|
|
16
|
+
// @atlaskit/css intentionally restricts height and width values, so Compiled owns only the
|
|
17
|
+
// dimensions that scale at runtime with the editor's dense-mode font-size custom property.
|
|
18
|
+
var quickInsertButtonContainerStyles = {
|
|
19
|
+
root: "_1e0c1txw _4t3i9xsi _1bsb9xsi"
|
|
20
|
+
};
|
|
21
|
+
var quickInsertButtonStyles = {
|
|
22
|
+
root: "_19itglyw _2rko1rr0 _1rjcze3t _18zrze3t _4cvr1h6o _bfhksm61 _vchhusvi _syazazsu _80omtlke _1e0c1txw _4t3i1osq _1bah1h6o _1bsb1osq _mizu1v1w _1ah3v77o _ra3xnqa1 _128mdkaa _irr31dpa _1di6fcek"
|
|
23
|
+
};
|
|
24
|
+
var createNewLine = function createNewLine(start) {
|
|
25
|
+
return function (_ref) {
|
|
26
|
+
var _tr$doc$nodeAt;
|
|
27
|
+
var tr = _ref.tr;
|
|
28
|
+
var nodeSize = (_tr$doc$nodeAt = tr.doc.nodeAt(start)) === null || _tr$doc$nodeAt === void 0 ? void 0 : _tr$doc$nodeAt.nodeSize;
|
|
29
|
+
if (nodeSize === undefined) {
|
|
30
|
+
return tr;
|
|
31
|
+
}
|
|
32
|
+
var position = start + nodeSize;
|
|
33
|
+
tr.insert(position, tr.doc.type.schema.nodes.paragraph.create());
|
|
34
|
+
return tr.setSelection(TextSelection.near(tr.doc.resolve(position)));
|
|
35
|
+
};
|
|
36
|
+
};
|
|
37
|
+
var isSelectionInNode = function isSelectionInNode(start, view) {
|
|
38
|
+
var node = view.state.doc.nodeAt(start);
|
|
39
|
+
if (!node) {
|
|
40
|
+
return false;
|
|
41
|
+
}
|
|
42
|
+
var _view$state$selection = view.state.selection,
|
|
43
|
+
$from = _view$state$selection.$from,
|
|
44
|
+
$to = _view$state$selection.$to;
|
|
45
|
+
return $from.pos >= start && $to.pos <= start + node.nodeSize;
|
|
46
|
+
};
|
|
47
|
+
var isNonEditableBlock = function isNonEditableBlock(start, view) {
|
|
48
|
+
var node = view.state.doc.nodeAt(start);
|
|
49
|
+
if (!node) {
|
|
50
|
+
return false;
|
|
51
|
+
}
|
|
52
|
+
if (node.type.name === 'mediaGroup' || node.type.name === 'mediaSingle') {
|
|
53
|
+
return true;
|
|
54
|
+
}
|
|
55
|
+
return node.isBlock && (node.isAtom || node.isLeaf);
|
|
56
|
+
};
|
|
57
|
+
var openQuickInsert = function openQuickInsert(api, view, start, openTypeAhead) {
|
|
58
|
+
var isSelectionInsideNode = isSelectionInNode(start, view);
|
|
59
|
+
if (!isSelectionInsideNode || isNonEditableBlock(start, view)) {
|
|
60
|
+
api.core.actions.execute(createNewLine(start));
|
|
61
|
+
}
|
|
62
|
+
var codeBlock = view.state.schema.nodes.codeBlock;
|
|
63
|
+
var selection = view.state.selection;
|
|
64
|
+
var codeBlockParentNode = findParentNodeOfType(codeBlock)(selection);
|
|
65
|
+
if (codeBlockParentNode) {
|
|
66
|
+
api.core.actions.execute(createNewLine(codeBlockParentNode.pos));
|
|
67
|
+
} else if (isSelectionInsideNode) {
|
|
68
|
+
var currentSelection = view.state.selection;
|
|
69
|
+
if ((currentSelection instanceof TextSelection || currentSelection instanceof NodeSelection && currentSelection.node.isInline) && currentSelection.from !== currentSelection.to) {
|
|
70
|
+
var currentParagraphNode = findParentNode(function (node) {
|
|
71
|
+
return TEXT_PARENT_TYPES.includes(node.type.name);
|
|
72
|
+
})(currentSelection);
|
|
73
|
+
if (currentParagraphNode) {
|
|
74
|
+
var newPos = currentSelection.anchor === currentSelection.to ? currentParagraphNode.pos : currentParagraphNode.pos + currentParagraphNode.node.nodeSize - 1;
|
|
75
|
+
api.core.actions.execute(function (_ref2) {
|
|
76
|
+
var tr = _ref2.tr;
|
|
77
|
+
tr.setSelection(TextSelection.create(view.state.selection.$from.doc, newPos));
|
|
78
|
+
return tr;
|
|
79
|
+
});
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
if (currentSelection instanceof NodeSelection && currentSelection.$from.depth > 0) {
|
|
83
|
+
if (isNonEditableBlock(view.state.selection.from, view)) {
|
|
84
|
+
api.core.actions.execute(createNewLine(view.state.selection.from));
|
|
85
|
+
} else {
|
|
86
|
+
api.core.actions.execute(function (_ref3) {
|
|
87
|
+
var tr = _ref3.tr;
|
|
88
|
+
createNewLine(view.state.selection.from)({
|
|
89
|
+
tr: tr
|
|
90
|
+
});
|
|
91
|
+
tr.setSelection(TextSelection.create(tr.doc, view.state.selection.from));
|
|
92
|
+
return tr;
|
|
93
|
+
});
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
if (currentSelection instanceof CellSelection) {
|
|
97
|
+
var lastInlinePosition = TextSelection.near(view.state.selection.$to, -1);
|
|
98
|
+
if (lastInlinePosition) {
|
|
99
|
+
api.core.actions.execute(function (_ref4) {
|
|
100
|
+
var tr = _ref4.tr;
|
|
101
|
+
if (!(lastInlinePosition instanceof TextSelection)) {
|
|
102
|
+
createNewLine(lastInlinePosition.from)({
|
|
103
|
+
tr: tr
|
|
104
|
+
});
|
|
105
|
+
tr.setSelection(TextSelection.create(tr.doc, lastInlinePosition.to));
|
|
106
|
+
} else {
|
|
107
|
+
tr.setSelection(lastInlinePosition);
|
|
108
|
+
}
|
|
109
|
+
return tr;
|
|
110
|
+
});
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
openTypeAhead();
|
|
115
|
+
};
|
|
116
|
+
export var BlockControlQuickInsertButton = function BlockControlQuickInsertButton(_ref5) {
|
|
117
|
+
var api = _ref5.api,
|
|
118
|
+
openTypeAhead = _ref5.openTypeAhead,
|
|
119
|
+
start = _ref5.start,
|
|
120
|
+
view = _ref5.view;
|
|
121
|
+
var _useIntl = useIntl(),
|
|
122
|
+
formatMessage = _useIntl.formatMessage;
|
|
123
|
+
var label = formatMessage(messages.insert);
|
|
124
|
+
var handleMouseDown = useCallback(function () {
|
|
125
|
+
var _api$typeAhead;
|
|
126
|
+
if ((_api$typeAhead = api.typeAhead) !== null && _api$typeAhead !== void 0 && _api$typeAhead.actions.isOpen(view.state)) {
|
|
127
|
+
api.typeAhead.actions.close({
|
|
128
|
+
insertCurrentQueryAsRawText: false
|
|
129
|
+
});
|
|
130
|
+
}
|
|
131
|
+
}, [api, view]);
|
|
132
|
+
var handleClick = useCallback(function () {
|
|
133
|
+
return openQuickInsert(api, view, start, openTypeAhead);
|
|
134
|
+
}, [api, openTypeAhead, start, view]);
|
|
135
|
+
return /*#__PURE__*/React.createElement(Tooltip, {
|
|
136
|
+
position: "top",
|
|
137
|
+
content: /*#__PURE__*/React.createElement(ToolTipContent, {
|
|
138
|
+
description: label
|
|
139
|
+
})
|
|
140
|
+
}, /*#__PURE__*/React.createElement("span", {
|
|
141
|
+
className: ax([quickInsertButtonContainerStyles.root])
|
|
142
|
+
}, /*#__PURE__*/React.createElement(Pressable, {
|
|
143
|
+
"aria-label": label,
|
|
144
|
+
onClick: handleClick,
|
|
145
|
+
onMouseDown: handleMouseDown,
|
|
146
|
+
testId: "editor-quick-insert-button",
|
|
147
|
+
type: "button",
|
|
148
|
+
xcss: quickInsertButtonStyles.root
|
|
149
|
+
}, /*#__PURE__*/React.createElement(AddIcon, {
|
|
150
|
+
label: "",
|
|
151
|
+
color: "var(--ds-icon-subtle, #505258)",
|
|
152
|
+
size: "small"
|
|
153
|
+
}))));
|
|
154
|
+
};
|
|
@@ -0,0 +1,38 @@
|
|
|
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 React from 'react';
|
|
5
|
+
import { BLOCK_CONTROL_UI_CONTEXT } from '@atlaskit/editor-common/block-controls/block-control-ui-context';
|
|
6
|
+
import { BLOCK_CONTROLS_LEFT_GROUP } from '@atlaskit/editor-common/block-controls/surface-keys';
|
|
7
|
+
import { BlockControlQuickInsertButton } from './BlockControlQuickInsertButton';
|
|
8
|
+
export var getBlockControlQuickInsertComponents = function getBlockControlQuickInsertComponents(_ref) {
|
|
9
|
+
var api = _ref.api,
|
|
10
|
+
getEditorView = _ref.getEditorView,
|
|
11
|
+
openTypeAhead = _ref.openTypeAhead;
|
|
12
|
+
return [{
|
|
13
|
+
key: 'block-controls-quick-insert',
|
|
14
|
+
type: 'button',
|
|
15
|
+
parents: [_objectSpread(_objectSpread({}, BLOCK_CONTROLS_LEFT_GROUP), {}, {
|
|
16
|
+
rank: 100
|
|
17
|
+
})],
|
|
18
|
+
isHidden: function isHidden() {
|
|
19
|
+
var _ref2 = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {},
|
|
20
|
+
surfaceContext = _ref2.surfaceContext;
|
|
21
|
+
return (surfaceContext === null || surfaceContext === void 0 ? void 0 : surfaceContext.get(BLOCK_CONTROL_UI_CONTEXT)) === undefined;
|
|
22
|
+
},
|
|
23
|
+
component: function component(_ref3) {
|
|
24
|
+
var surfaceContext = _ref3.surfaceContext;
|
|
25
|
+
var context = surfaceContext === null || surfaceContext === void 0 ? void 0 : surfaceContext.get(BLOCK_CONTROL_UI_CONTEXT);
|
|
26
|
+
var view = getEditorView();
|
|
27
|
+
if (!context || !view) {
|
|
28
|
+
return null;
|
|
29
|
+
}
|
|
30
|
+
return /*#__PURE__*/React.createElement(BlockControlQuickInsertButton, {
|
|
31
|
+
api: api,
|
|
32
|
+
openTypeAhead: openTypeAhead,
|
|
33
|
+
start: context.targetNode.pos,
|
|
34
|
+
view: view
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
}];
|
|
38
|
+
};
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @jsxRuntime classic
|
|
3
|
+
* @jsx jsx
|
|
4
|
+
*/
|
|
5
|
+
import React from 'react';
|
|
6
|
+
import type { ExtractInjectionAPI } from '@atlaskit/editor-common/types';
|
|
7
|
+
import type { EditorView } from '@atlaskit/editor-prosemirror/view';
|
|
8
|
+
import type { QuickInsertPlugin } from '../quickInsertPluginType';
|
|
9
|
+
type Props = {
|
|
10
|
+
api: ExtractInjectionAPI<QuickInsertPlugin>;
|
|
11
|
+
openTypeAhead: () => void;
|
|
12
|
+
start: number;
|
|
13
|
+
view: EditorView;
|
|
14
|
+
};
|
|
15
|
+
export declare const BlockControlQuickInsertButton: ({ api, openTypeAhead, start, view, }: Props) => React.JSX.Element;
|
|
16
|
+
export {};
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { ExtractInjectionAPI } from '@atlaskit/editor-common/types';
|
|
2
|
+
import type { EditorView } from '@atlaskit/editor-prosemirror/view';
|
|
3
|
+
import type { RegisterButton } from '@atlaskit/editor-ui-control-model/types';
|
|
4
|
+
import type { QuickInsertPlugin } from '../quickInsertPluginType';
|
|
5
|
+
export declare const getBlockControlQuickInsertComponents: ({ api, getEditorView, openTypeAhead, }: {
|
|
6
|
+
api: ExtractInjectionAPI<QuickInsertPlugin>;
|
|
7
|
+
getEditorView: () => EditorView | undefined;
|
|
8
|
+
openTypeAhead: () => void;
|
|
9
|
+
}) => RegisterButton[];
|
|
@@ -1,7 +1,14 @@
|
|
|
1
|
+
import React from 'react';
|
|
1
2
|
import type { QuickInsertItem } from '@atlaskit/editor-common/provider-factory';
|
|
2
|
-
import type { RegisterMenuItem } from '@atlaskit/editor-ui-control-model/types';
|
|
3
|
+
import type { CommonComponentProps, RegisterMenuItem } from '@atlaskit/editor-ui-control-model/types';
|
|
4
|
+
type LegacyCompatibleComponentProps = CommonComponentProps & {
|
|
5
|
+
onInsert?: () => void;
|
|
6
|
+
};
|
|
7
|
+
type LegacyCompatibleRegisterMenuItem = Omit<RegisterMenuItem, 'component'> & {
|
|
8
|
+
component?: (props: LegacyCompatibleComponentProps) => React.ReactNode;
|
|
9
|
+
};
|
|
3
10
|
type Options = {
|
|
4
|
-
directComponents:
|
|
11
|
+
directComponents: LegacyCompatibleRegisterMenuItem[];
|
|
5
12
|
itemFilter?: (item: QuickInsertItem) => boolean;
|
|
6
13
|
onInsert: (item: QuickInsertItem) => void;
|
|
7
14
|
providedItems: QuickInsertItem[];
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { ExtractInjectionAPI } from '@atlaskit/editor-common/types';
|
|
2
|
-
import type { RegisterComponent } from '@atlaskit/editor-ui-control-model/types';
|
|
2
|
+
import type { CommonComponentProps, RegisterComponent } from '@atlaskit/editor-ui-control-model/types';
|
|
3
3
|
import type { IsRecommendedItem } from '@atlaskit/editor-common/quick-insert/is-recommended-item';
|
|
4
4
|
import type { QuickInsertPlugin } from '../quickInsertPluginType';
|
|
5
5
|
type Params = {
|
|
@@ -7,5 +7,5 @@ type Params = {
|
|
|
7
7
|
includeElementBrowserItems: boolean;
|
|
8
8
|
isRecommendedItem?: IsRecommendedItem;
|
|
9
9
|
};
|
|
10
|
-
export declare const getQuickInsertComponents: ({ api, includeElementBrowserItems, isRecommendedItem, }: Params) => RegisterComponent[];
|
|
10
|
+
export declare const getQuickInsertComponents: <TProps extends CommonComponentProps = CommonComponentProps>({ api, includeElementBrowserItems, isRecommendedItem, }: Params) => RegisterComponent<TProps>[];
|
|
11
11
|
export {};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@atlaskit/editor-plugin-quick-insert",
|
|
3
|
-
"version": "16.0
|
|
3
|
+
"version": "16.1.0",
|
|
4
4
|
"description": "Quick insert plugin for @atlaskit/editor-core",
|
|
5
5
|
"author": "Atlassian Pty Ltd",
|
|
6
6
|
"license": "Apache-2.0",
|
|
@@ -29,6 +29,7 @@
|
|
|
29
29
|
"@atlaskit/editor-plugin-type-ahead": "^17.0.0",
|
|
30
30
|
"@atlaskit/editor-plugin-ui-control-registry": "^10.0.0",
|
|
31
31
|
"@atlaskit/editor-prosemirror": "^8.0.0",
|
|
32
|
+
"@atlaskit/editor-tables": "^3.0.0",
|
|
32
33
|
"@atlaskit/editor-ui-control-model": "^2.8.0",
|
|
33
34
|
"@atlaskit/heading": "^7.1.0",
|
|
34
35
|
"@atlaskit/icon": "^37.5.0",
|
|
@@ -39,12 +40,13 @@
|
|
|
39
40
|
"@atlaskit/textfield": "^10.1.0",
|
|
40
41
|
"@atlaskit/tmp-editor-statsig": "^161.0.0",
|
|
41
42
|
"@atlaskit/tokens": "^16.8.0",
|
|
43
|
+
"@atlaskit/tooltip": "^24.2.0",
|
|
42
44
|
"@babel/runtime": "^7.0.0",
|
|
43
45
|
"@compiled/react": "^1.0.2",
|
|
44
46
|
"@emotion/react": "^11.7.1"
|
|
45
47
|
},
|
|
46
48
|
"peerDependencies": {
|
|
47
|
-
"@atlaskit/editor-common": "^120.
|
|
49
|
+
"@atlaskit/editor-common": "^120.1.0",
|
|
48
50
|
"react": "^18.2.0 || ^19.2.0",
|
|
49
51
|
"react-dom": "^18.2.0 || ^19.2.0",
|
|
50
52
|
"react-intl": "^5.25.1 || ^6.0.0 || ^7.0.0"
|