@atlaskit/editor-plugin-floating-toolbar 0.5.1 → 0.6.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 +16 -10
- package/README.md +1 -1
- package/dist/cjs/index.js +8 -1
- package/dist/cjs/plugin.js +385 -0
- package/dist/cjs/pm-plugins/force-focus/index.js +73 -0
- package/dist/cjs/pm-plugins/toolbar-data/commands.js +26 -0
- package/dist/cjs/pm-plugins/toolbar-data/plugin-factory.js +16 -0
- package/dist/cjs/pm-plugins/toolbar-data/plugin-key.js +9 -0
- package/dist/cjs/pm-plugins/toolbar-data/plugin.js +16 -0
- package/dist/cjs/pm-plugins/toolbar-data/reducer.js +25 -0
- package/dist/cjs/pm-plugins/toolbar-data/types.js +5 -0
- package/dist/cjs/ui/CheckboxModal.js +83 -0
- package/dist/cjs/ui/ConfirmationModal.js +22 -0
- package/dist/cjs/ui/Dropdown.js +212 -0
- package/dist/cjs/ui/DropdownMenu.js +218 -0
- package/dist/cjs/ui/EditorEmojiAddIcon.js +32 -0
- package/dist/cjs/ui/EmojiPickerButton.js +121 -0
- package/dist/cjs/ui/ExtensionsPlaceholder.js +179 -0
- package/dist/cjs/ui/Input.js +80 -0
- package/dist/cjs/ui/ScrollButtons.js +155 -0
- package/dist/cjs/ui/Select.js +74 -0
- package/dist/cjs/ui/Separator.js +9 -0
- package/dist/cjs/ui/SimpleModal.js +42 -0
- package/dist/cjs/ui/Toolbar.js +436 -0
- package/dist/cjs/ui/ToolbarLoader.js +25 -0
- package/dist/cjs/ui/messages.js +55 -0
- package/dist/cjs/ui/styles.js +79 -0
- package/dist/cjs/utils.js +22 -0
- package/dist/es2019/index.js +1 -1
- package/dist/es2019/plugin.js +366 -0
- package/dist/es2019/pm-plugins/force-focus/index.js +63 -0
- package/dist/es2019/pm-plugins/toolbar-data/commands.js +10 -0
- package/dist/es2019/pm-plugins/toolbar-data/plugin-factory.js +8 -0
- package/dist/es2019/pm-plugins/toolbar-data/plugin-key.js +2 -0
- package/dist/es2019/pm-plugins/toolbar-data/plugin.js +9 -0
- package/dist/es2019/pm-plugins/toolbar-data/reducer.js +16 -0
- package/dist/es2019/pm-plugins/toolbar-data/types.js +1 -0
- package/dist/es2019/ui/CheckboxModal.js +71 -0
- package/dist/es2019/ui/ConfirmationModal.js +13 -0
- package/dist/es2019/ui/Dropdown.js +185 -0
- package/dist/es2019/ui/DropdownMenu.js +205 -0
- package/dist/es2019/ui/EditorEmojiAddIcon.js +25 -0
- package/dist/es2019/ui/EmojiPickerButton.js +108 -0
- package/dist/es2019/ui/ExtensionsPlaceholder.js +100 -0
- package/dist/es2019/ui/Input.js +54 -0
- package/dist/es2019/ui/ScrollButtons.js +141 -0
- package/dist/es2019/ui/Select.js +62 -0
- package/dist/es2019/ui/Separator.js +2 -0
- package/dist/es2019/ui/SimpleModal.js +35 -0
- package/dist/es2019/ui/Toolbar.js +428 -0
- package/dist/es2019/ui/ToolbarLoader.js +6 -0
- package/dist/es2019/ui/messages.js +48 -0
- package/dist/es2019/ui/styles.js +64 -0
- package/dist/es2019/utils.js +16 -0
- package/dist/esm/index.js +1 -1
- package/dist/esm/plugin.js +373 -0
- package/dist/esm/pm-plugins/force-focus/index.js +64 -0
- package/dist/esm/pm-plugins/toolbar-data/commands.js +18 -0
- package/dist/esm/pm-plugins/toolbar-data/plugin-factory.js +8 -0
- package/dist/esm/pm-plugins/toolbar-data/plugin-key.js +2 -0
- package/dist/esm/pm-plugins/toolbar-data/plugin.js +9 -0
- package/dist/esm/pm-plugins/toolbar-data/reducer.js +17 -0
- package/dist/esm/pm-plugins/toolbar-data/types.js +1 -0
- package/dist/esm/ui/CheckboxModal.js +72 -0
- package/dist/esm/ui/ConfirmationModal.js +14 -0
- package/dist/esm/ui/Dropdown.js +204 -0
- package/dist/esm/ui/DropdownMenu.js +211 -0
- package/dist/esm/ui/EditorEmojiAddIcon.js +25 -0
- package/dist/esm/ui/EmojiPickerButton.js +114 -0
- package/dist/esm/ui/ExtensionsPlaceholder.js +168 -0
- package/dist/esm/ui/Input.js +72 -0
- package/dist/esm/ui/ScrollButtons.js +145 -0
- package/dist/esm/ui/Select.js +64 -0
- package/dist/esm/ui/Separator.js +2 -0
- package/dist/esm/ui/SimpleModal.js +31 -0
- package/dist/esm/ui/Toolbar.js +426 -0
- package/dist/esm/ui/ToolbarLoader.js +12 -0
- package/dist/esm/ui/messages.js +48 -0
- package/dist/esm/ui/styles.js +68 -0
- package/dist/esm/utils.js +16 -0
- package/dist/types/index.d.ts +1 -0
- package/dist/types/plugin.d.ts +12 -0
- package/dist/types/pm-plugins/force-focus/index.d.ts +21 -0
- package/dist/types/pm-plugins/toolbar-data/commands.d.ts +3 -0
- package/dist/types/pm-plugins/toolbar-data/plugin-factory.d.ts +1 -0
- package/dist/types/pm-plugins/toolbar-data/plugin-key.d.ts +3 -0
- package/dist/types/pm-plugins/toolbar-data/plugin.d.ts +3 -0
- package/dist/types/pm-plugins/toolbar-data/reducer.d.ts +3 -0
- package/dist/types/pm-plugins/toolbar-data/types.d.ts +8 -0
- package/dist/types/ui/CheckboxModal.d.ts +4 -0
- package/dist/types/ui/ConfirmationModal.d.ts +6 -0
- package/dist/types/ui/Dropdown.d.ts +41 -0
- package/dist/types/ui/DropdownMenu.d.ts +29 -0
- package/dist/types/ui/EditorEmojiAddIcon.d.ts +2 -0
- package/dist/types/ui/EmojiPickerButton.d.ts +16 -0
- package/dist/types/ui/ExtensionsPlaceholder.d.ts +16 -0
- package/dist/types/ui/Input.d.ts +23 -0
- package/dist/types/ui/ScrollButtons.d.ts +13 -0
- package/dist/types/ui/Select.d.ts +21 -0
- package/dist/types/ui/Separator.d.ts +2 -0
- package/dist/types/ui/SimpleModal.d.ts +4 -0
- package/dist/types/ui/Toolbar.d.ts +44 -0
- package/dist/types/ui/ToolbarLoader.d.ts +4 -0
- package/dist/types/ui/messages.d.ts +48 -0
- package/dist/types/ui/styles.d.ts +20 -0
- package/dist/types/utils.d.ts +2 -0
- package/dist/types-ts4.5/index.d.ts +1 -0
- package/dist/types-ts4.5/plugin.d.ts +12 -0
- package/dist/types-ts4.5/pm-plugins/force-focus/index.d.ts +21 -0
- package/dist/types-ts4.5/pm-plugins/toolbar-data/commands.d.ts +3 -0
- package/dist/types-ts4.5/pm-plugins/toolbar-data/plugin-factory.d.ts +1 -0
- package/dist/types-ts4.5/pm-plugins/toolbar-data/plugin-key.d.ts +3 -0
- package/dist/types-ts4.5/pm-plugins/toolbar-data/plugin.d.ts +3 -0
- package/dist/types-ts4.5/pm-plugins/toolbar-data/reducer.d.ts +3 -0
- package/dist/types-ts4.5/pm-plugins/toolbar-data/types.d.ts +8 -0
- package/dist/types-ts4.5/ui/CheckboxModal.d.ts +4 -0
- package/dist/types-ts4.5/ui/ConfirmationModal.d.ts +6 -0
- package/dist/types-ts4.5/ui/Dropdown.d.ts +41 -0
- package/dist/types-ts4.5/ui/DropdownMenu.d.ts +29 -0
- package/dist/types-ts4.5/ui/EditorEmojiAddIcon.d.ts +2 -0
- package/dist/types-ts4.5/ui/EmojiPickerButton.d.ts +16 -0
- package/dist/types-ts4.5/ui/ExtensionsPlaceholder.d.ts +16 -0
- package/dist/types-ts4.5/ui/Input.d.ts +23 -0
- package/dist/types-ts4.5/ui/ScrollButtons.d.ts +13 -0
- package/dist/types-ts4.5/ui/Select.d.ts +21 -0
- package/dist/types-ts4.5/ui/Separator.d.ts +2 -0
- package/dist/types-ts4.5/ui/SimpleModal.d.ts +4 -0
- package/dist/types-ts4.5/ui/Toolbar.d.ts +44 -0
- package/dist/types-ts4.5/ui/ToolbarLoader.d.ts +4 -0
- package/dist/types-ts4.5/ui/messages.d.ts +48 -0
- package/dist/types-ts4.5/ui/styles.d.ts +20 -0
- package/dist/types-ts4.5/utils.d.ts +2 -0
- package/package.json +32 -3
- package/report.api.md +3 -0
- package/tmp/api-report-tmp.d.ts +3 -0
|
@@ -0,0 +1,168 @@
|
|
|
1
|
+
import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
|
|
2
|
+
import _asyncToGenerator from "@babel/runtime/helpers/asyncToGenerator";
|
|
3
|
+
import _regeneratorRuntime from "@babel/runtime/regenerator";
|
|
4
|
+
import React, { useEffect, useState } from 'react';
|
|
5
|
+
import Loadable from 'react-loadable';
|
|
6
|
+
import ButtonGroup from '@atlaskit/button/button-group';
|
|
7
|
+
import { getContextualToolbarItemsFromModule } from '@atlaskit/editor-common/extensions';
|
|
8
|
+
import { FloatingToolbarButton as Button } from '@atlaskit/editor-common/ui';
|
|
9
|
+
import { nodeToJSON } from '@atlaskit/editor-common/utils';
|
|
10
|
+
import Separator from './Separator';
|
|
11
|
+
var noop = function noop() {
|
|
12
|
+
return null;
|
|
13
|
+
};
|
|
14
|
+
var isDefaultExport = function isDefaultExport(mod) {
|
|
15
|
+
return mod.hasOwnProperty('default');
|
|
16
|
+
};
|
|
17
|
+
var resolveExtensionIcon = /*#__PURE__*/function () {
|
|
18
|
+
var _ref = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee(getIcon) {
|
|
19
|
+
var maybeIcon;
|
|
20
|
+
return _regeneratorRuntime.wrap(function _callee$(_context) {
|
|
21
|
+
while (1) switch (_context.prev = _context.next) {
|
|
22
|
+
case 0:
|
|
23
|
+
if (getIcon) {
|
|
24
|
+
_context.next = 2;
|
|
25
|
+
break;
|
|
26
|
+
}
|
|
27
|
+
return _context.abrupt("return", noop);
|
|
28
|
+
case 2:
|
|
29
|
+
_context.next = 4;
|
|
30
|
+
return getIcon();
|
|
31
|
+
case 4:
|
|
32
|
+
maybeIcon = _context.sent;
|
|
33
|
+
return _context.abrupt("return", isDefaultExport(maybeIcon) ? maybeIcon.default : maybeIcon);
|
|
34
|
+
case 6:
|
|
35
|
+
case "end":
|
|
36
|
+
return _context.stop();
|
|
37
|
+
}
|
|
38
|
+
}, _callee);
|
|
39
|
+
}));
|
|
40
|
+
return function resolveExtensionIcon(_x) {
|
|
41
|
+
return _ref.apply(this, arguments);
|
|
42
|
+
};
|
|
43
|
+
}();
|
|
44
|
+
var ExtensionButton = function ExtensionButton(props) {
|
|
45
|
+
var item = props.item,
|
|
46
|
+
node = props.node,
|
|
47
|
+
extensionApi = props.extensionApi;
|
|
48
|
+
var ButtonIcon = React.useMemo(function () {
|
|
49
|
+
return item.icon ? Loadable({
|
|
50
|
+
loader: function () {
|
|
51
|
+
var _loader = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee2() {
|
|
52
|
+
return _regeneratorRuntime.wrap(function _callee2$(_context2) {
|
|
53
|
+
while (1) switch (_context2.prev = _context2.next) {
|
|
54
|
+
case 0:
|
|
55
|
+
return _context2.abrupt("return", resolveExtensionIcon(item.icon));
|
|
56
|
+
case 1:
|
|
57
|
+
case "end":
|
|
58
|
+
return _context2.stop();
|
|
59
|
+
}
|
|
60
|
+
}, _callee2);
|
|
61
|
+
}));
|
|
62
|
+
function loader() {
|
|
63
|
+
return _loader.apply(this, arguments);
|
|
64
|
+
}
|
|
65
|
+
return loader;
|
|
66
|
+
}(),
|
|
67
|
+
loading: noop
|
|
68
|
+
}) : undefined;
|
|
69
|
+
}, [item.icon]);
|
|
70
|
+
var onClick = function onClick() {
|
|
71
|
+
if (typeof item.action !== 'function') {
|
|
72
|
+
throw new Error("'action' of context toolbar item '".concat(item.key, "' is not a function"));
|
|
73
|
+
}
|
|
74
|
+
var targetNodeAdf = nodeToJSON(node);
|
|
75
|
+
item.action(targetNodeAdf, extensionApi);
|
|
76
|
+
};
|
|
77
|
+
return /*#__PURE__*/React.createElement(Button, {
|
|
78
|
+
title: item.label,
|
|
79
|
+
ariaLabel: item.tooltip,
|
|
80
|
+
icon: ButtonIcon ? /*#__PURE__*/React.createElement(ButtonIcon, {
|
|
81
|
+
label: item.label || ''
|
|
82
|
+
}) : undefined,
|
|
83
|
+
onClick: onClick,
|
|
84
|
+
tooltipContent: item.tooltip,
|
|
85
|
+
disabled: item.disabled
|
|
86
|
+
}, item.label);
|
|
87
|
+
};
|
|
88
|
+
export var ExtensionsPlaceholder = function ExtensionsPlaceholder(props) {
|
|
89
|
+
var node = props.node,
|
|
90
|
+
editorView = props.editorView,
|
|
91
|
+
extensionProvider = props.extensionProvider,
|
|
92
|
+
separator = props.separator,
|
|
93
|
+
applyChangeToContextPanel = props.applyChangeToContextPanel,
|
|
94
|
+
extensionApi = props.extensionApi;
|
|
95
|
+
var _useState = useState([]),
|
|
96
|
+
_useState2 = _slicedToArray(_useState, 2),
|
|
97
|
+
extensions = _useState2[0],
|
|
98
|
+
setExtensions = _useState2[1];
|
|
99
|
+
useEffect(function () {
|
|
100
|
+
getExtensions();
|
|
101
|
+
function getExtensions() {
|
|
102
|
+
return _getExtensions.apply(this, arguments);
|
|
103
|
+
} // leaving dependencies array empty so that this effect runs just once on component mount
|
|
104
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
105
|
+
function _getExtensions() {
|
|
106
|
+
_getExtensions = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee3() {
|
|
107
|
+
var provider;
|
|
108
|
+
return _regeneratorRuntime.wrap(function _callee3$(_context3) {
|
|
109
|
+
while (1) switch (_context3.prev = _context3.next) {
|
|
110
|
+
case 0:
|
|
111
|
+
_context3.next = 2;
|
|
112
|
+
return extensionProvider;
|
|
113
|
+
case 2:
|
|
114
|
+
provider = _context3.sent;
|
|
115
|
+
if (!provider) {
|
|
116
|
+
_context3.next = 9;
|
|
117
|
+
break;
|
|
118
|
+
}
|
|
119
|
+
_context3.t0 = setExtensions;
|
|
120
|
+
_context3.next = 7;
|
|
121
|
+
return provider.getExtensions();
|
|
122
|
+
case 7:
|
|
123
|
+
_context3.t1 = _context3.sent;
|
|
124
|
+
(0, _context3.t0)(_context3.t1);
|
|
125
|
+
case 9:
|
|
126
|
+
case "end":
|
|
127
|
+
return _context3.stop();
|
|
128
|
+
}
|
|
129
|
+
}, _callee3);
|
|
130
|
+
}));
|
|
131
|
+
return _getExtensions.apply(this, arguments);
|
|
132
|
+
}
|
|
133
|
+
}, []);
|
|
134
|
+
var nodeAdf = React.useMemo(function () {
|
|
135
|
+
return nodeToJSON(node);
|
|
136
|
+
}, [node]);
|
|
137
|
+
var extensionItems = React.useMemo(function () {
|
|
138
|
+
return getContextualToolbarItemsFromModule(extensions, nodeAdf, extensionApi);
|
|
139
|
+
}, [extensions, nodeAdf, extensionApi]);
|
|
140
|
+
if (!extensionItems.length) {
|
|
141
|
+
return null;
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
// ButtonGroup wraps each child with another layer
|
|
145
|
+
// but count fragment as 1 child, so here we create the children manually.
|
|
146
|
+
var children = [];
|
|
147
|
+
if (separator && ['start', 'both'].includes(separator)) {
|
|
148
|
+
children.push( /*#__PURE__*/React.createElement(Separator, null));
|
|
149
|
+
}
|
|
150
|
+
extensionItems.forEach(function (item, index) {
|
|
151
|
+
children.push( /*#__PURE__*/React.createElement(ExtensionButton, {
|
|
152
|
+
node: node,
|
|
153
|
+
item: item,
|
|
154
|
+
editorView: editorView,
|
|
155
|
+
applyChangeToContextPanel: applyChangeToContextPanel,
|
|
156
|
+
extensionApi: extensionApi
|
|
157
|
+
}));
|
|
158
|
+
if (index < extensionItems.length - 1) {
|
|
159
|
+
children.push( /*#__PURE__*/React.createElement(Separator, null));
|
|
160
|
+
}
|
|
161
|
+
});
|
|
162
|
+
if (separator && ['end', 'both'].includes(separator)) {
|
|
163
|
+
children.push( /*#__PURE__*/React.createElement(Separator, null));
|
|
164
|
+
}
|
|
165
|
+
return /*#__PURE__*/React.createElement(ButtonGroup, {
|
|
166
|
+
children: children
|
|
167
|
+
});
|
|
168
|
+
};
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import _classCallCheck from "@babel/runtime/helpers/classCallCheck";
|
|
2
|
+
import _createClass from "@babel/runtime/helpers/createClass";
|
|
3
|
+
import _assertThisInitialized from "@babel/runtime/helpers/assertThisInitialized";
|
|
4
|
+
import _inherits from "@babel/runtime/helpers/inherits";
|
|
5
|
+
import _possibleConstructorReturn from "@babel/runtime/helpers/possibleConstructorReturn";
|
|
6
|
+
import _getPrototypeOf from "@babel/runtime/helpers/getPrototypeOf";
|
|
7
|
+
import _defineProperty from "@babel/runtime/helpers/defineProperty";
|
|
8
|
+
function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
|
|
9
|
+
function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
|
|
10
|
+
/** @jsx jsx */
|
|
11
|
+
import React from 'react';
|
|
12
|
+
import { Component } from 'react';
|
|
13
|
+
import { jsx } from '@emotion/react';
|
|
14
|
+
import { panelTextInput } from '@atlaskit/editor-common/ui';
|
|
15
|
+
// eslint-disable-next-line @repo/internal/react/no-class-components
|
|
16
|
+
var TextField = /*#__PURE__*/function (_Component) {
|
|
17
|
+
_inherits(TextField, _Component);
|
|
18
|
+
var _super = _createSuper(TextField);
|
|
19
|
+
function TextField(props) {
|
|
20
|
+
var _this;
|
|
21
|
+
_classCallCheck(this, TextField);
|
|
22
|
+
_this = _super.call(this, props);
|
|
23
|
+
_defineProperty(_assertThisInitialized(_this), "handleChange", function (e) {
|
|
24
|
+
_this.setState({
|
|
25
|
+
text: e.target.value
|
|
26
|
+
});
|
|
27
|
+
});
|
|
28
|
+
_defineProperty(_assertThisInitialized(_this), "handleSubmit", function (e) {
|
|
29
|
+
e.preventDefault();
|
|
30
|
+
if (_this.props.onSubmit) {
|
|
31
|
+
_this.props.onSubmit(_this.state.text);
|
|
32
|
+
}
|
|
33
|
+
});
|
|
34
|
+
_defineProperty(_assertThisInitialized(_this), "handleBlur", function (e) {
|
|
35
|
+
e.preventDefault();
|
|
36
|
+
if (_this.props.onBlur) {
|
|
37
|
+
_this.props.onBlur(_this.state.text);
|
|
38
|
+
}
|
|
39
|
+
});
|
|
40
|
+
_this.state = {
|
|
41
|
+
text: props.defaultValue || ''
|
|
42
|
+
};
|
|
43
|
+
return _this;
|
|
44
|
+
}
|
|
45
|
+
_createClass(TextField, [{
|
|
46
|
+
key: "UNSAFE_componentWillReceiveProps",
|
|
47
|
+
value: function UNSAFE_componentWillReceiveProps(nextProps) {
|
|
48
|
+
if (this.state.text !== nextProps.defaultValue) {
|
|
49
|
+
this.setState({
|
|
50
|
+
text: nextProps.defaultValue || ''
|
|
51
|
+
});
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
}, {
|
|
55
|
+
key: "render",
|
|
56
|
+
value: function render() {
|
|
57
|
+
var placeholder = this.props.placeholder;
|
|
58
|
+
return jsx("form", {
|
|
59
|
+
onSubmit: this.handleSubmit
|
|
60
|
+
}, jsx("input", {
|
|
61
|
+
// eslint-disable-next-line @atlaskit/design-system/consistent-css-prop-usage
|
|
62
|
+
css: panelTextInput,
|
|
63
|
+
value: this.state.text,
|
|
64
|
+
onChange: this.handleChange,
|
|
65
|
+
placeholder: placeholder,
|
|
66
|
+
onBlur: this.handleBlur
|
|
67
|
+
}));
|
|
68
|
+
}
|
|
69
|
+
}]);
|
|
70
|
+
return TextField;
|
|
71
|
+
}(Component);
|
|
72
|
+
export { TextField as default };
|
|
@@ -0,0 +1,145 @@
|
|
|
1
|
+
import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
|
|
2
|
+
import _taggedTemplateLiteral from "@babel/runtime/helpers/taggedTemplateLiteral";
|
|
3
|
+
var _templateObject;
|
|
4
|
+
/** @jsx jsx */
|
|
5
|
+
import React, { useEffect, useRef, useState } from 'react';
|
|
6
|
+
import { css, jsx } from '@emotion/react';
|
|
7
|
+
import rafSchedule from 'raf-schd';
|
|
8
|
+
import { FloatingToolbarButton as Button } from '@atlaskit/editor-common/ui';
|
|
9
|
+
import ChevronLeftLargeIcon from '@atlaskit/icon/glyph/chevron-left-large';
|
|
10
|
+
import ChevronRightLargeIcon from '@atlaskit/icon/glyph/chevron-right-large';
|
|
11
|
+
import { N30 } from '@atlaskit/theme/colors';
|
|
12
|
+
import messages from './messages';
|
|
13
|
+
|
|
14
|
+
// eslint-disable-next-line @atlaskit/design-system/consistent-css-prop-usage
|
|
15
|
+
var toolbarScrollButtons = css(_templateObject || (_templateObject = _taggedTemplateLiteral(["\n display: grid;\n grid-template-columns: 1fr 1fr;\n grid-gap: ", ";\n padding: ", " ", ";\n border-left: solid ", " 1px;\n flex-shrink: 0;\n align-items: center;\n"])), "var(--ds-space-050, 4px)", "var(--ds-space-050, 4px)", "var(--ds-space-100, 8px)", "var(--ds-border, ".concat(N30, ")"));
|
|
16
|
+
var LeftIcon = ChevronLeftLargeIcon;
|
|
17
|
+
var RightIcon = ChevronRightLargeIcon;
|
|
18
|
+
export var ScrollButtons = function ScrollButtons(_ref) {
|
|
19
|
+
var intl = _ref.intl,
|
|
20
|
+
scrollContainerRef = _ref.scrollContainerRef,
|
|
21
|
+
node = _ref.node,
|
|
22
|
+
disabled = _ref.disabled;
|
|
23
|
+
var buttonsContainerRef = useRef(null);
|
|
24
|
+
var _useState = useState(false),
|
|
25
|
+
_useState2 = _slicedToArray(_useState, 2),
|
|
26
|
+
needScroll = _useState2[0],
|
|
27
|
+
setNeedScroll = _useState2[1];
|
|
28
|
+
var _useState3 = useState(true),
|
|
29
|
+
_useState4 = _slicedToArray(_useState3, 2),
|
|
30
|
+
canScrollLeft = _useState4[0],
|
|
31
|
+
setCanScrollLeft = _useState4[1];
|
|
32
|
+
var _useState5 = useState(true),
|
|
33
|
+
_useState6 = _slicedToArray(_useState5, 2),
|
|
34
|
+
canScrollRight = _useState6[0],
|
|
35
|
+
setCanScrollRight = _useState6[1];
|
|
36
|
+
var setCanScrollDebounced = rafSchedule(function () {
|
|
37
|
+
// Refs are null before mounting and after unmount
|
|
38
|
+
if (!scrollContainerRef.current) {
|
|
39
|
+
return;
|
|
40
|
+
}
|
|
41
|
+
var _scrollContainerRef$c = scrollContainerRef.current,
|
|
42
|
+
scrollLeft = _scrollContainerRef$c.scrollLeft,
|
|
43
|
+
scrollWidth = _scrollContainerRef$c.scrollWidth,
|
|
44
|
+
offsetWidth = _scrollContainerRef$c.offsetWidth;
|
|
45
|
+
setCanScrollLeft(scrollLeft > 0);
|
|
46
|
+
setCanScrollRight(scrollLeft + offsetWidth < scrollWidth - 1); // -1 to account for half pixel
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
var onScroll = function onScroll() {
|
|
50
|
+
return setCanScrollDebounced();
|
|
51
|
+
};
|
|
52
|
+
var scrollLeft = function scrollLeft() {
|
|
53
|
+
var _scrollContainerRef$c2, _scrollContainerRef$c3, _scrollContainerRef$c4;
|
|
54
|
+
var _ref2 = ((_scrollContainerRef$c2 = scrollContainerRef.current) === null || _scrollContainerRef$c2 === void 0 ? void 0 : _scrollContainerRef$c2.getBoundingClientRect()) || {},
|
|
55
|
+
_ref2$width = _ref2.width,
|
|
56
|
+
scrollContainerWidth = _ref2$width === void 0 ? 0 : _ref2$width;
|
|
57
|
+
var scrollLeft = ((_scrollContainerRef$c3 = scrollContainerRef.current) === null || _scrollContainerRef$c3 === void 0 ? void 0 : _scrollContainerRef$c3.scrollLeft) || 0;
|
|
58
|
+
|
|
59
|
+
// scroll to current position - scroll container width
|
|
60
|
+
var scrollTo = scrollLeft - scrollContainerWidth;
|
|
61
|
+
(_scrollContainerRef$c4 = scrollContainerRef.current) === null || _scrollContainerRef$c4 === void 0 ? void 0 : _scrollContainerRef$c4.scrollTo({
|
|
62
|
+
top: 0,
|
|
63
|
+
left: scrollTo,
|
|
64
|
+
behavior: 'smooth'
|
|
65
|
+
});
|
|
66
|
+
};
|
|
67
|
+
var scrollRight = function scrollRight() {
|
|
68
|
+
var _scrollContainerRef$c5, _scrollContainerRef$c6, _scrollContainerRef$c7;
|
|
69
|
+
var _ref3 = ((_scrollContainerRef$c5 = scrollContainerRef.current) === null || _scrollContainerRef$c5 === void 0 ? void 0 : _scrollContainerRef$c5.getBoundingClientRect()) || {},
|
|
70
|
+
_ref3$width = _ref3.width,
|
|
71
|
+
scrollContainerWidth = _ref3$width === void 0 ? 0 : _ref3$width;
|
|
72
|
+
var scrollLeft = ((_scrollContainerRef$c6 = scrollContainerRef.current) === null || _scrollContainerRef$c6 === void 0 ? void 0 : _scrollContainerRef$c6.scrollLeft) || 0;
|
|
73
|
+
|
|
74
|
+
// scroll to current position + scroll container width
|
|
75
|
+
var scrollTo = scrollLeft + scrollContainerWidth;
|
|
76
|
+
(_scrollContainerRef$c7 = scrollContainerRef.current) === null || _scrollContainerRef$c7 === void 0 ? void 0 : _scrollContainerRef$c7.scrollTo({
|
|
77
|
+
top: 0,
|
|
78
|
+
left: scrollTo,
|
|
79
|
+
behavior: 'smooth'
|
|
80
|
+
});
|
|
81
|
+
};
|
|
82
|
+
var resizeObserver = new ResizeObserver(function (t) {
|
|
83
|
+
var _scrollContainerRef$c8, _scrollContainerRef$c9, _scrollContainerRef$c10;
|
|
84
|
+
var widthNeededToShowAllItems = ((_scrollContainerRef$c8 = scrollContainerRef.current) === null || _scrollContainerRef$c8 === void 0 ? void 0 : _scrollContainerRef$c8.scrollWidth) || 0;
|
|
85
|
+
var availableSpace = (_scrollContainerRef$c9 = scrollContainerRef.current) === null || _scrollContainerRef$c9 === void 0 ? void 0 : (_scrollContainerRef$c10 = _scrollContainerRef$c9.parentNode) === null || _scrollContainerRef$c10 === void 0 ? void 0 : _scrollContainerRef$c10.offsetWidth;
|
|
86
|
+
if (availableSpace >= widthNeededToShowAllItems) {
|
|
87
|
+
setNeedScroll(false);
|
|
88
|
+
} else {
|
|
89
|
+
setNeedScroll(true);
|
|
90
|
+
onScroll();
|
|
91
|
+
}
|
|
92
|
+
});
|
|
93
|
+
useEffect(function () {
|
|
94
|
+
onScroll();
|
|
95
|
+
var scrollContainerRefCurrent = scrollContainerRef.current;
|
|
96
|
+
if (scrollContainerRefCurrent) {
|
|
97
|
+
// enable/disable scroll buttons depending on scroll position
|
|
98
|
+
// eslint-disable-next-line @repo/internal/dom-events/no-unsafe-event-listeners
|
|
99
|
+
scrollContainerRefCurrent.addEventListener('scroll', onScroll);
|
|
100
|
+
|
|
101
|
+
// watch for toolbar resize and show/hide scroll buttons if needed
|
|
102
|
+
resizeObserver.observe(scrollContainerRefCurrent);
|
|
103
|
+
}
|
|
104
|
+
return function () {
|
|
105
|
+
if (scrollContainerRefCurrent) {
|
|
106
|
+
// eslint-disable-next-line @repo/internal/dom-events/no-unsafe-event-listeners
|
|
107
|
+
scrollContainerRefCurrent.removeEventListener('scroll', onScroll);
|
|
108
|
+
resizeObserver.unobserve(scrollContainerRefCurrent);
|
|
109
|
+
}
|
|
110
|
+
setCanScrollDebounced.cancel();
|
|
111
|
+
};
|
|
112
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
113
|
+
}, []);
|
|
114
|
+
useEffect(function () {
|
|
115
|
+
var scrollContainerRefCurrent = scrollContainerRef.current;
|
|
116
|
+
if (scrollContainerRefCurrent) {
|
|
117
|
+
var _scrollContainerRefCu;
|
|
118
|
+
// reset scroll position when switching from one node with toolbar to another
|
|
119
|
+
// scroll to made optional as it may not be rendered in testing env
|
|
120
|
+
(_scrollContainerRefCu = scrollContainerRefCurrent.scrollTo) === null || _scrollContainerRefCu === void 0 ? void 0 : _scrollContainerRefCu.call(scrollContainerRefCurrent, {
|
|
121
|
+
left: 0
|
|
122
|
+
});
|
|
123
|
+
}
|
|
124
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
125
|
+
}, [node.type]);
|
|
126
|
+
return needScroll ? jsx("div", {
|
|
127
|
+
ref: buttonsContainerRef,
|
|
128
|
+
css: toolbarScrollButtons,
|
|
129
|
+
className: "scroll-buttons"
|
|
130
|
+
}, jsx(Button, {
|
|
131
|
+
title: intl.formatMessage(messages.floatingToolbarScrollLeft),
|
|
132
|
+
icon: jsx(LeftIcon, {
|
|
133
|
+
label: intl.formatMessage(messages.floatingToolbarScrollLeft)
|
|
134
|
+
}),
|
|
135
|
+
onClick: scrollLeft,
|
|
136
|
+
disabled: !canScrollLeft || disabled
|
|
137
|
+
}), jsx(Button, {
|
|
138
|
+
title: intl.formatMessage(messages.floatingToolbarScrollRight),
|
|
139
|
+
icon: jsx(RightIcon, {
|
|
140
|
+
label: intl.formatMessage(messages.floatingToolbarScrollRight)
|
|
141
|
+
}),
|
|
142
|
+
onClick: scrollRight,
|
|
143
|
+
disabled: !canScrollRight || disabled
|
|
144
|
+
})) : null;
|
|
145
|
+
};
|
|
@@ -0,0 +1,64 @@
|
|
|
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, { useRef } from 'react';
|
|
5
|
+
import Select from '@atlaskit/select';
|
|
6
|
+
export default function Search(props) {
|
|
7
|
+
var selectRef = useRef(null);
|
|
8
|
+
var _props$width = props.width,
|
|
9
|
+
width = _props$width === void 0 ? 200 : _props$width;
|
|
10
|
+
var style = React.useMemo(function () {
|
|
11
|
+
return {
|
|
12
|
+
container: function container(base) {
|
|
13
|
+
return _objectSpread(_objectSpread({}, base), {}, {
|
|
14
|
+
width: width
|
|
15
|
+
});
|
|
16
|
+
},
|
|
17
|
+
menuPortal: function menuPortal(base) {
|
|
18
|
+
var _selectRef$current, _selectRef$current$se, _selectRef$current$se2, _selectRef$current2, _selectRef$current2$s, _selectRef$current2$s2, _selectRef$current2$s3;
|
|
19
|
+
// ED:16095: We add two possible getter paths for safely reaching into the underlying
|
|
20
|
+
// react-select element. We first try a getter that conforms with react-select v5 APIs,
|
|
21
|
+
// Failing that, we try a getter consistent with react-select v4 APIs. (We
|
|
22
|
+
// handle both as consumers may control the time of the actual dependency version
|
|
23
|
+
// cutover).
|
|
24
|
+
var controlWrapper = (selectRef === null || selectRef === void 0 ? void 0 : (_selectRef$current = selectRef.current) === null || _selectRef$current === void 0 ? void 0 : (_selectRef$current$se = _selectRef$current.select) === null || _selectRef$current$se === void 0 ? void 0 : (_selectRef$current$se2 = _selectRef$current$se.controlRef) === null || _selectRef$current$se2 === void 0 ? void 0 : _selectRef$current$se2.parentNode) || (selectRef === null || selectRef === void 0 ? void 0 : (_selectRef$current2 = selectRef.current) === null || _selectRef$current2 === void 0 ? void 0 : (_selectRef$current2$s = _selectRef$current2.select) === null || _selectRef$current2$s === void 0 ? void 0 : (_selectRef$current2$s2 = _selectRef$current2$s.select) === null || _selectRef$current2$s2 === void 0 ? void 0 : (_selectRef$current2$s3 = _selectRef$current2$s2.controlRef) === null || _selectRef$current2$s3 === void 0 ? void 0 : _selectRef$current2$s3.parentNode);
|
|
25
|
+
var menuPortalStyles = controlWrapper && props.setDisableParentScroll ? {
|
|
26
|
+
// since the portal is now outside, we need to position it as before
|
|
27
|
+
top: controlWrapper.offsetTop,
|
|
28
|
+
left: controlWrapper.offsetLeft,
|
|
29
|
+
height: controlWrapper.offsetHeight,
|
|
30
|
+
width: width
|
|
31
|
+
} : {};
|
|
32
|
+
return _objectSpread(_objectSpread({}, base), menuPortalStyles);
|
|
33
|
+
}
|
|
34
|
+
};
|
|
35
|
+
},
|
|
36
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
37
|
+
[width]);
|
|
38
|
+
var onMenuOpen = function onMenuOpen() {
|
|
39
|
+
if (props.setDisableParentScroll) {
|
|
40
|
+
props.setDisableParentScroll(true);
|
|
41
|
+
}
|
|
42
|
+
};
|
|
43
|
+
var onMenuClose = function onMenuClose() {
|
|
44
|
+
if (props.setDisableParentScroll) {
|
|
45
|
+
props.setDisableParentScroll(false);
|
|
46
|
+
}
|
|
47
|
+
};
|
|
48
|
+
return /*#__PURE__*/React.createElement(Select, {
|
|
49
|
+
ref: selectRef,
|
|
50
|
+
options: props.options,
|
|
51
|
+
value: props.defaultValue,
|
|
52
|
+
onChange: props.onChange,
|
|
53
|
+
placeholder: props.placeholder,
|
|
54
|
+
spacing: "compact",
|
|
55
|
+
menuPlacement: "auto",
|
|
56
|
+
filterOption: props.filterOption,
|
|
57
|
+
styles: style,
|
|
58
|
+
menuPortalTarget: props.mountPoint,
|
|
59
|
+
onMenuOpen: onMenuOpen,
|
|
60
|
+
onMenuClose: onMenuClose,
|
|
61
|
+
"aria-label": props.ariaLabel,
|
|
62
|
+
classNamePrefix: props.classNamePrefix
|
|
63
|
+
});
|
|
64
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import Button from '@atlaskit/button/standard-button';
|
|
3
|
+
import Modal, { ModalBody, ModalFooter, ModalHeader, ModalTitle } from '@atlaskit/modal-dialog';
|
|
4
|
+
import messages from './messages';
|
|
5
|
+
export var SimpleModal = function SimpleModal(props) {
|
|
6
|
+
var onConfirm = props.onConfirm,
|
|
7
|
+
onClose = props.onClose,
|
|
8
|
+
options = props.options,
|
|
9
|
+
formatMessage = props.intl.formatMessage,
|
|
10
|
+
testId = props.testId;
|
|
11
|
+
var heading = (options === null || options === void 0 ? void 0 : options.title) || formatMessage(messages.confirmModalDefaultHeading);
|
|
12
|
+
var okButtonLabel = (options === null || options === void 0 ? void 0 : options.okButtonLabel) || formatMessage(messages.confirmModalOK);
|
|
13
|
+
var cancelButtonLabel = (options === null || options === void 0 ? void 0 : options.cancelButtonLabel) || formatMessage(messages.confirmModalCancel);
|
|
14
|
+
return /*#__PURE__*/React.createElement(Modal, {
|
|
15
|
+
onClose: onClose,
|
|
16
|
+
testId: testId
|
|
17
|
+
}, /*#__PURE__*/React.createElement(ModalHeader, null, /*#__PURE__*/React.createElement(ModalTitle, {
|
|
18
|
+
appearance: "warning"
|
|
19
|
+
}, heading)), /*#__PURE__*/React.createElement(ModalBody, null, /*#__PURE__*/React.createElement("p", null, options === null || options === void 0 ? void 0 : options.message)), /*#__PURE__*/React.createElement(ModalFooter, null, /*#__PURE__*/React.createElement(Button, {
|
|
20
|
+
appearance: "default",
|
|
21
|
+
onClick: onClose,
|
|
22
|
+
testId: testId ? "".concat(testId, "-cancel-button") : undefined
|
|
23
|
+
}, cancelButtonLabel), /*#__PURE__*/React.createElement(Button, {
|
|
24
|
+
appearance: "warning",
|
|
25
|
+
onClick: function onClick() {
|
|
26
|
+
onConfirm();
|
|
27
|
+
onClose();
|
|
28
|
+
},
|
|
29
|
+
testId: testId ? "".concat(testId, "-confirm-button") : undefined
|
|
30
|
+
}, okButtonLabel)));
|
|
31
|
+
};
|