@payloadcms/richtext-lexical 4.0.0-beta.2 → 4.0.0-beta.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/dist/exports/client/Field-334JNLRF.js +2 -0
- package/dist/exports/client/Field-334JNLRF.js.map +7 -0
- package/dist/exports/client/{RelationshipComponent-YCPAKOL7.js → RelationshipComponent-TVK6I4W4.js} +2 -2
- package/dist/exports/client/chunk-BEKGION5.js +2 -0
- package/dist/exports/client/chunk-BEKGION5.js.map +7 -0
- package/dist/exports/client/{chunk-WSAPGI3Z.js → chunk-EA5BHQ2T.js} +1 -1
- package/dist/exports/client/{chunk-WSAPGI3Z.js.map → chunk-EA5BHQ2T.js.map} +1 -1
- package/dist/exports/client/chunk-FAJJXXCW.js +2 -0
- package/dist/exports/client/{chunk-3LRZDIIG.js.map → chunk-FAJJXXCW.js.map} +2 -2
- package/dist/exports/client/{chunk-5VIL27GI.js → chunk-IYBYNEKX.js} +1 -1
- package/dist/exports/client/{chunk-5VIL27GI.js.map → chunk-IYBYNEKX.js.map} +1 -1
- package/dist/exports/client/chunk-SE5IITBK.js +2 -0
- package/dist/exports/client/chunk-SE5IITBK.js.map +7 -0
- package/dist/exports/client/{component-6DQLENIE.js → component-QENB4QTS.js} +2 -2
- package/dist/exports/client/componentInline-AU7IBNY7.js +2 -0
- package/dist/exports/client/index.js +27 -27
- package/dist/exports/client/index.js.map +3 -3
- package/dist/features/align/client/index.js.map +1 -1
- package/dist/features/blocks/client/component/BlockContent.js.map +1 -1
- package/dist/features/blocks/client/component/components/BlockCollapsible.js.map +1 -1
- package/dist/features/blocks/client/component/components/BlockEditButton.js.map +1 -1
- package/dist/features/blocks/client/component/components/BlockRemoveButton.js.map +1 -1
- package/dist/features/blocks/client/component/index.d.ts.map +1 -1
- package/dist/features/blocks/client/component/index.js +38 -16
- package/dist/features/blocks/client/component/index.js.map +1 -1
- package/dist/features/blocks/client/componentInline/components/InlineBlockContainer.js.map +1 -1
- package/dist/features/blocks/client/componentInline/components/InlineBlockEditButton.js.map +1 -1
- package/dist/features/blocks/client/componentInline/components/InlineBlockLabel.js.map +1 -1
- package/dist/features/blocks/client/componentInline/components/InlineBlockRemoveButton.js.map +1 -1
- package/dist/features/blocks/client/componentInline/index.d.ts.map +1 -1
- package/dist/features/blocks/client/componentInline/index.js +5 -11
- package/dist/features/blocks/client/componentInline/index.js.map +1 -1
- package/dist/features/blocks/client/getCachedFormStateIfDataMatches.js.map +1 -1
- package/dist/features/blocks/client/plugin/index.js.map +1 -1
- package/dist/features/blocks/premade/CodeBlock/Component/Block.js +121 -78
- package/dist/features/blocks/premade/CodeBlock/Component/Block.js.map +1 -1
- package/dist/features/blocks/premade/CodeBlock/Component/Code.js +142 -87
- package/dist/features/blocks/premade/CodeBlock/Component/Code.js.map +1 -1
- package/dist/features/converters/lexicalToHtml/sync/types.d.ts.map +1 -1
- package/dist/features/converters/lexicalToHtml/sync/types.js.map +1 -1
- package/dist/features/debug/jsxConverter/client/plugin/index.js.map +1 -1
- package/dist/features/debug/testRecorder/client/plugin/index.js.map +1 -1
- package/dist/features/debug/treeView/client/plugin/index.js.map +1 -1
- package/dist/features/heading/client/index.js.map +1 -1
- package/dist/features/horizontalRule/client/plugin/index.js.map +1 -1
- package/dist/features/indent/client/index.d.ts.map +1 -1
- package/dist/features/indent/client/index.js +0 -2
- package/dist/features/indent/client/index.js.map +1 -1
- package/dist/features/indent/server/i18n.d.ts.map +1 -1
- package/dist/features/indent/server/i18n.js.map +1 -1
- package/dist/features/link/client/plugins/autoLink/index.js.map +1 -1
- package/dist/features/link/client/plugins/floatingLinkEditor/LinkEditor/index.d.ts.map +1 -1
- package/dist/features/link/client/plugins/floatingLinkEditor/LinkEditor/index.js +10 -2
- package/dist/features/link/client/plugins/floatingLinkEditor/LinkEditor/index.js.map +1 -1
- package/dist/features/link/client/plugins/link/index.js.map +1 -1
- package/dist/features/link/markdownTransformer.js +2 -2
- package/dist/features/link/markdownTransformer.js.map +1 -1
- package/dist/features/link/server/baseFields.js.map +1 -1
- package/dist/features/lists/shared/schema.d.ts.map +1 -1
- package/dist/features/lists/shared/schema.js.map +1 -1
- package/dist/features/relationship/client/drawer/index.js.map +1 -1
- package/dist/features/relationship/client/plugins/index.js.map +1 -1
- package/dist/features/relationship/client/utils/useEnabledRelationships.js.map +1 -1
- package/dist/features/table/client/plugins/TableActionMenuPlugin/index.css +1 -1
- package/dist/features/table/client/plugins/TableActionMenuPlugin/index.js.map +1 -1
- package/dist/features/table/client/plugins/TableCellResizerPlugin/index.js +6 -6
- package/dist/features/table/client/plugins/TableCellResizerPlugin/index.js.map +1 -1
- package/dist/features/table/client/plugins/TableHoverActionsPlugin/index.js.map +1 -1
- package/dist/features/table/client/plugins/TablePlugin/index.js +54 -18
- package/dist/features/table/client/plugins/TablePlugin/index.js.map +1 -1
- package/dist/features/table/client/utils/useDebounce.js.map +1 -1
- package/dist/features/textState/defaultColors.js +1 -1
- package/dist/features/textState/defaultColors.js.map +1 -1
- package/dist/features/toolbars/fixed/client/Toolbar/horizontalWheelScroll.js.map +1 -1
- package/dist/features/toolbars/fixed/client/Toolbar/index.js +126 -70
- package/dist/features/toolbars/fixed/client/Toolbar/index.js.map +1 -1
- package/dist/features/toolbars/inline/client/Toolbar/index.js +67 -35
- package/dist/features/toolbars/inline/client/Toolbar/index.js.map +1 -1
- package/dist/features/toolbars/shared/ToolbarButton/index.d.ts.map +1 -1
- package/dist/features/toolbars/shared/ToolbarButton/index.js +26 -2
- package/dist/features/toolbars/shared/ToolbarButton/index.js.map +1 -1
- package/dist/features/toolbars/shared/ToolbarDropdown/DropDown.js +137 -72
- package/dist/features/toolbars/shared/ToolbarDropdown/DropDown.js.map +1 -1
- package/dist/features/toolbars/shared/ToolbarDropdown/index.d.ts.map +1 -1
- package/dist/features/toolbars/shared/ToolbarDropdown/index.js +22 -6
- package/dist/features/toolbars/shared/ToolbarDropdown/index.js.map +1 -1
- package/dist/features/toolbars/shared/useToolbarKeyboardNavigation.js +100 -70
- package/dist/features/toolbars/shared/useToolbarKeyboardNavigation.js.map +1 -1
- package/dist/features/upload/client/drawer/index.js.map +1 -1
- package/dist/features/upload/client/plugin/index.js.map +1 -1
- package/dist/field/RenderLexical/index.js.map +1 -1
- package/dist/field/ViewSelector.js +12 -4
- package/dist/field/ViewSelector.js.map +1 -1
- package/dist/field/bundled.css +1 -1
- package/dist/field/index.js.map +1 -1
- package/dist/i18n.d.ts.map +1 -1
- package/dist/i18n.js +44 -0
- package/dist/i18n.js.map +1 -1
- package/dist/lexical/LexicalEditor.js.map +1 -1
- package/dist/lexical/plugins/ClipboardPlugin/index.js.map +1 -1
- package/dist/lexical/plugins/DecoratorPlugin/index.js.map +1 -1
- package/dist/lexical/plugins/InsertParagraphAtEnd/index.js.map +1 -1
- package/dist/lexical/plugins/MarkdownShortcut/index.js.map +1 -1
- package/dist/lexical/plugins/NodeViewOverridePlugin/index.js.map +1 -1
- package/dist/lexical/plugins/SlashMenu/LexicalTypeaheadMenuPlugin/LexicalMenu.js +234 -87
- package/dist/lexical/plugins/SlashMenu/LexicalTypeaheadMenuPlugin/LexicalMenu.js.map +1 -1
- package/dist/lexical/plugins/SlashMenu/useMenuTriggerMatch.js.map +1 -1
- package/dist/lexical/plugins/TextPlugin/index.js.map +1 -1
- package/dist/lexical/plugins/handles/AddBlockHandlePlugin/index.js.map +1 -1
- package/dist/lexical/plugins/handles/DraggableBlockPlugin/index.css +16 -0
- package/dist/lexical/plugins/handles/DraggableBlockPlugin/index.d.ts.map +1 -1
- package/dist/lexical/plugins/handles/DraggableBlockPlugin/index.js +126 -38
- package/dist/lexical/plugins/handles/DraggableBlockPlugin/index.js.map +1 -1
- package/dist/lexical/plugins/handles/DraggableBlockPlugin/moveBlock.d.ts +7 -0
- package/dist/lexical/plugins/handles/DraggableBlockPlugin/moveBlock.d.ts.map +1 -0
- package/dist/lexical/plugins/handles/DraggableBlockPlugin/moveBlock.js +15 -0
- package/dist/lexical/plugins/handles/DraggableBlockPlugin/moveBlock.js.map +1 -0
- package/dist/lexical/plugins/handles/DraggableBlockPlugin/useKeyboardReordering.d.ts.map +1 -1
- package/dist/lexical/plugins/handles/DraggableBlockPlugin/useKeyboardReordering.js +9 -12
- package/dist/lexical/plugins/handles/DraggableBlockPlugin/useKeyboardReordering.js.map +1 -1
- package/dist/lexical/ui/ContentEditable.js.map +1 -1
- package/dist/lexical/utils/nodeFormat.d.ts.map +1 -1
- package/dist/lexical/utils/nodeFormat.js +0 -2
- package/dist/lexical/utils/nodeFormat.js.map +1 -1
- package/dist/lexical/utils/url.d.ts.map +1 -1
- package/dist/lexical/utils/url.js +1 -1
- package/dist/lexical/utils/url.js.map +1 -1
- package/dist/populateGraphQL/populate.js.map +1 -1
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/index.js.map +1 -1
- package/dist/utilities/buildEditorState.d.ts.map +1 -1
- package/dist/utilities/buildEditorState.js.map +1 -1
- package/dist/utilities/fieldsDrawer/Drawer.js +36 -36
- package/dist/utilities/fieldsDrawer/Drawer.js.map +1 -1
- package/dist/utilities/fieldsDrawer/DrawerContent.d.ts.map +1 -1
- package/dist/utilities/fieldsDrawer/DrawerContent.js +6 -9
- package/dist/utilities/fieldsDrawer/DrawerContent.js.map +1 -1
- package/dist/utilities/fieldsDrawer/useDrawerSubmit.js.map +1 -1
- package/dist/utilities/fieldsDrawer/useLexicalDocumentDrawer.js.map +1 -1
- package/dist/utilities/fieldsDrawer/useLexicalDrawer.js.map +1 -1
- package/dist/utilities/fieldsDrawer/useLexicalListDrawer.js.map +1 -1
- package/dist/utilities/initLexicalFeatures.d.ts.map +1 -1
- package/dist/utilities/initLexicalFeatures.js +38 -4
- package/dist/utilities/initLexicalFeatures.js.map +1 -1
- package/dist/utilities/useLexicalFeature.js +15 -6
- package/dist/utilities/useLexicalFeature.js.map +1 -1
- package/dist/utilities/useRunDeprioritized.js.map +1 -1
- package/package.json +32 -35
- package/dist/exports/client/Field-W2ABOM7M.js +0 -2
- package/dist/exports/client/Field-W2ABOM7M.js.map +0 -7
- package/dist/exports/client/chunk-3LRZDIIG.js +0 -2
- package/dist/exports/client/chunk-E6LSRRP2.js +0 -2
- package/dist/exports/client/chunk-E6LSRRP2.js.map +0 -7
- package/dist/exports/client/chunk-ZQX5HXUL.js +0 -2
- package/dist/exports/client/chunk-ZQX5HXUL.js.map +0 -7
- package/dist/exports/client/componentInline-HNE5G4TE.js +0 -2
- /package/dist/exports/client/{RelationshipComponent-YCPAKOL7.js.map → RelationshipComponent-TVK6I4W4.js.map} +0 -0
- /package/dist/exports/client/{component-6DQLENIE.js.map → component-QENB4QTS.js.map} +0 -0
- /package/dist/exports/client/{componentInline-HNE5G4TE.js.map → componentInline-AU7IBNY7.js.map} +0 -0
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
'use client';
|
|
2
2
|
|
|
3
|
+
import { c as _c } from "react/compiler-runtime";
|
|
3
4
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
4
5
|
import { Button } from '@payloadcms/ui';
|
|
5
6
|
import { $addUpdateTag, isDOMNode } from 'lexical';
|
|
@@ -70,81 +71,145 @@ export function DropDownItem({
|
|
|
70
71
|
children: children
|
|
71
72
|
});
|
|
72
73
|
}
|
|
73
|
-
function DropDownItems({
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
74
|
+
function DropDownItems(t0) {
|
|
75
|
+
const $ = _c(17);
|
|
76
|
+
const {
|
|
77
|
+
id,
|
|
78
|
+
children,
|
|
79
|
+
dropdownKey,
|
|
80
|
+
dropDownRef,
|
|
81
|
+
itemsContainerClassNames,
|
|
82
|
+
onClose,
|
|
83
|
+
shouldAutoFocus
|
|
84
|
+
} = t0;
|
|
82
85
|
const [items, setItems] = useState();
|
|
83
86
|
const [highlightedItem, setHighlightedItem] = useState();
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
87
|
+
let t1;
|
|
88
|
+
if ($[0] === Symbol.for("react.memo_cache_sentinel")) {
|
|
89
|
+
t1 = itemRef => {
|
|
90
|
+
setItems(prev => prev != null ? [...prev, itemRef] : [itemRef]);
|
|
91
|
+
};
|
|
92
|
+
$[0] = t1;
|
|
93
|
+
} else {
|
|
94
|
+
t1 = $[0];
|
|
95
|
+
}
|
|
96
|
+
const registerItem = t1;
|
|
97
|
+
let t2;
|
|
98
|
+
if ($[1] !== items || $[2] !== onClose) {
|
|
99
|
+
t2 = event => {
|
|
100
|
+
if (items == null) {
|
|
101
|
+
return;
|
|
102
|
+
}
|
|
103
|
+
const {
|
|
104
|
+
key
|
|
105
|
+
} = event;
|
|
106
|
+
const enabledItems = items.filter(_temp);
|
|
107
|
+
if (["ArrowDown", "ArrowUp", "Escape"].includes(key)) {
|
|
108
|
+
event.preventDefault();
|
|
109
|
+
}
|
|
110
|
+
if (key === "Escape") {
|
|
111
|
+
onClose();
|
|
112
|
+
} else {
|
|
113
|
+
if (key === "Tab") {
|
|
114
|
+
setTimeout(() => onClose({
|
|
115
|
+
restoreFocus: false
|
|
116
|
+
}));
|
|
117
|
+
} else {
|
|
118
|
+
if (key === "ArrowUp") {
|
|
119
|
+
setHighlightedItem(prev_0 => {
|
|
120
|
+
if (prev_0 == null) {
|
|
121
|
+
return enabledItems[0];
|
|
122
|
+
}
|
|
123
|
+
const index = enabledItems.indexOf(prev_0) - 1;
|
|
124
|
+
return enabledItems[index === -1 ? enabledItems.length - 1 : index];
|
|
125
|
+
});
|
|
126
|
+
} else {
|
|
127
|
+
if (key === "ArrowDown") {
|
|
128
|
+
setHighlightedItem(prev_1 => {
|
|
129
|
+
if (prev_1 == null) {
|
|
130
|
+
return enabledItems[0];
|
|
131
|
+
}
|
|
132
|
+
const index_0 = enabledItems.indexOf(prev_1);
|
|
133
|
+
return enabledItems[index_0 === enabledItems.length - 1 ? 0 : index_0 + 1];
|
|
134
|
+
});
|
|
135
|
+
}
|
|
136
|
+
}
|
|
116
137
|
}
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
}
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
}
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
}
|
|
147
|
-
|
|
138
|
+
}
|
|
139
|
+
};
|
|
140
|
+
$[1] = items;
|
|
141
|
+
$[2] = onClose;
|
|
142
|
+
$[3] = t2;
|
|
143
|
+
} else {
|
|
144
|
+
t2 = $[3];
|
|
145
|
+
}
|
|
146
|
+
const handleKeyDown = t2;
|
|
147
|
+
let t3;
|
|
148
|
+
if ($[4] === Symbol.for("react.memo_cache_sentinel")) {
|
|
149
|
+
t3 = {
|
|
150
|
+
registerItem
|
|
151
|
+
};
|
|
152
|
+
$[4] = t3;
|
|
153
|
+
} else {
|
|
154
|
+
t3 = $[4];
|
|
155
|
+
}
|
|
156
|
+
const contextValue = t3;
|
|
157
|
+
let t4;
|
|
158
|
+
let t5;
|
|
159
|
+
if ($[5] !== highlightedItem || $[6] !== items || $[7] !== shouldAutoFocus) {
|
|
160
|
+
t4 = () => {
|
|
161
|
+
if (shouldAutoFocus && items != null && highlightedItem == null) {
|
|
162
|
+
setHighlightedItem(items.find(_temp2));
|
|
163
|
+
}
|
|
164
|
+
if (highlightedItem != null && highlightedItem?.current != null) {
|
|
165
|
+
highlightedItem.current.focus();
|
|
166
|
+
}
|
|
167
|
+
};
|
|
168
|
+
t5 = [items, highlightedItem, shouldAutoFocus];
|
|
169
|
+
$[5] = highlightedItem;
|
|
170
|
+
$[6] = items;
|
|
171
|
+
$[7] = shouldAutoFocus;
|
|
172
|
+
$[8] = t4;
|
|
173
|
+
$[9] = t5;
|
|
174
|
+
} else {
|
|
175
|
+
t4 = $[8];
|
|
176
|
+
t5 = $[9];
|
|
177
|
+
}
|
|
178
|
+
useEffect(t4, t5);
|
|
179
|
+
let t6;
|
|
180
|
+
if ($[10] !== children || $[11] !== dropDownRef || $[12] !== dropdownKey || $[13] !== handleKeyDown || $[14] !== id || $[15] !== itemsContainerClassNames) {
|
|
181
|
+
t6 = _jsx(DropDownContext, {
|
|
182
|
+
value: contextValue,
|
|
183
|
+
children: _jsx("div", {
|
|
184
|
+
className: (itemsContainerClassNames ?? ["toolbar-popup__dropdown-items"]).join(" "),
|
|
185
|
+
"data-dropdown-key": dropdownKey,
|
|
186
|
+
"data-theme": "dark",
|
|
187
|
+
id,
|
|
188
|
+
onKeyDown: handleKeyDown,
|
|
189
|
+
popover: "manual",
|
|
190
|
+
ref: dropDownRef,
|
|
191
|
+
role: "menu",
|
|
192
|
+
tabIndex: -1,
|
|
193
|
+
children
|
|
194
|
+
})
|
|
195
|
+
});
|
|
196
|
+
$[10] = children;
|
|
197
|
+
$[11] = dropDownRef;
|
|
198
|
+
$[12] = dropdownKey;
|
|
199
|
+
$[13] = handleKeyDown;
|
|
200
|
+
$[14] = id;
|
|
201
|
+
$[15] = itemsContainerClassNames;
|
|
202
|
+
$[16] = t6;
|
|
203
|
+
} else {
|
|
204
|
+
t6 = $[16];
|
|
205
|
+
}
|
|
206
|
+
return t6;
|
|
207
|
+
}
|
|
208
|
+
function _temp2(item_0) {
|
|
209
|
+
return !item_0.current?.disabled;
|
|
210
|
+
}
|
|
211
|
+
function _temp(item) {
|
|
212
|
+
return !item.current?.disabled;
|
|
148
213
|
}
|
|
149
214
|
export function DropDown({
|
|
150
215
|
buttonAriaLabel,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"DropDown.js","names":["Button","$addUpdateTag","isDOMNode","React","useCallback","useEffect","useId","useMemo","useRef","useState","baseClass","DropDownContext","createContext","DropDownItem","active","children","editor","enabled","Icon","item","itemKey","tooltip","className","key","filter","Boolean","join","ref","dropDownContext","use","Error","registerItem","current","_jsx","buttonStyle","disabled","extraButtonProps","isActive","undefined","role","tabIndex","icon","iconPosition","onClick","focus","update","onSelect","onMouseDown","e","preventDefault","type","DropDownItems","id","dropdownKey","dropDownRef","itemsContainerClassNames","onClose","shouldAutoFocus","items","setItems","highlightedItem","setHighlightedItem","itemRef","prev","handleKeyDown","event","enabledItems","includes","setTimeout","restoreFocus","index","indexOf","length","contextValue","find","value","onKeyDown","popover","DropDown","buttonAriaLabel","buttonClassName","label","stopCloseOnClickSelf","buttonRef","openedViaKeyboardRef","generatedId","menuId","showDropDown","setShowDropDown","handleClose","button","dropDown","matches","showPopover","updatePosition","bottom","left","top","getBoundingClientRect","offset","gap","below","above","offsetHeight","maxTop","Math","max","window","innerHeight","preferredTop","style","position","min","innerWidth","offsetWidth","addEventListener","capture","passive","removeEventListener","handle","target","contains","document","_jsxs","Fragment"],"sources":["../../../../../src/features/toolbars/shared/ToolbarDropdown/DropDown.tsx"],"sourcesContent":["'use client'\nimport { Button } from '@payloadcms/ui'\nimport { $addUpdateTag, isDOMNode, type LexicalEditor } from 'lexical'\nimport React, {\n type ReactNode,\n useCallback,\n useEffect,\n useId,\n useMemo,\n useRef,\n useState,\n} from 'react'\n\nimport type { ToolbarGroupItem } from '../../types.js'\n\nconst baseClass = 'toolbar-popup__dropdown-item'\n\ninterface DropDownContextType {\n registerItem: (ref: React.RefObject<HTMLButtonElement | null>) => void\n}\n\nconst DropDownContext = React.createContext<DropDownContextType | null>(null)\n\nexport function DropDownItem({\n active,\n children,\n editor,\n enabled,\n Icon,\n item,\n itemKey,\n tooltip,\n}: {\n active?: boolean\n children: React.ReactNode\n editor: LexicalEditor\n enabled?: boolean\n Icon: React.ReactNode\n item: ToolbarGroupItem\n itemKey: string\n tooltip?: string\n}): React.ReactNode {\n const className = useMemo(() => {\n return [\n baseClass,\n enabled === false ? 'disabled' : '',\n active ? 'active' : '',\n item?.key ? `${baseClass}-${item.key}` : '',\n ]\n .filter(Boolean)\n .join(' ')\n }, [enabled, active, item.key])\n\n const ref = useRef<HTMLButtonElement>(null)\n\n const dropDownContext = React.use(DropDownContext)\n\n if (dropDownContext === null) {\n throw new Error('DropDownItem must be used within a DropDown')\n }\n\n const { registerItem } = dropDownContext\n\n useEffect(() => {\n if (ref?.current != null) {\n registerItem(ref)\n }\n }, [ref, registerItem])\n\n return (\n <Button\n aria-label={tooltip}\n buttonStyle=\"ghost\"\n className={className}\n disabled={enabled === false}\n extraButtonProps={{\n 'aria-checked': item.isActive ? Boolean(active) : undefined,\n 'data-item-key': itemKey,\n role: item.isActive ? 'menuitemcheckbox' : 'menuitem',\n tabIndex: -1,\n }}\n icon={Icon}\n iconPosition=\"left\"\n onClick={() => {\n if (enabled !== false) {\n editor.focus(() => {\n editor.update(() => {\n $addUpdateTag('toolbar')\n })\n // We need to wrap the onSelect in the callback, so the editor is properly focused before the onSelect is called.\n item.onSelect?.({\n editor,\n isActive: active!,\n })\n })\n }\n }}\n onMouseDown={(e: React.MouseEvent) => {\n // This is required for Firefox compatibility. Without it, the dropdown will disappear without the onClick being called.\n // This only happens in Firefox. Must be something about how Firefox handles focus events differently.\n e.preventDefault()\n }}\n ref={ref}\n tooltip={tooltip}\n type=\"button\"\n >\n {children}\n </Button>\n )\n}\n\nfunction DropDownItems({\n id,\n children,\n dropdownKey,\n dropDownRef,\n itemsContainerClassNames,\n onClose,\n shouldAutoFocus,\n}: {\n children: React.ReactNode\n dropdownKey?: string\n dropDownRef: React.Ref<HTMLDivElement>\n id: string\n itemsContainerClassNames?: string[]\n onClose: (options?: { restoreFocus?: boolean }) => void\n shouldAutoFocus: boolean\n}): React.ReactElement {\n const [items, setItems] = useState<Array<React.RefObject<HTMLButtonElement | null>>>()\n const [highlightedItem, setHighlightedItem] =\n useState<React.RefObject<HTMLButtonElement | null>>()\n\n const registerItem = useCallback(\n (itemRef: React.RefObject<HTMLButtonElement | null>) => {\n setItems((prev) => (prev != null ? [...prev, itemRef] : [itemRef]))\n },\n [setItems],\n )\n\n const handleKeyDown = (event: React.KeyboardEvent<HTMLDivElement>): void => {\n if (items == null) {\n return\n }\n\n const { key } = event\n const enabledItems = items.filter((item) => !item.current?.disabled)\n\n if (['ArrowDown', 'ArrowUp', 'Escape'].includes(key)) {\n event.preventDefault()\n }\n\n if (key === 'Escape') {\n onClose()\n } else if (key === 'Tab') {\n setTimeout(() => onClose({ restoreFocus: false }))\n } else if (key === 'ArrowUp') {\n setHighlightedItem((prev) => {\n if (prev == null) {\n return enabledItems[0]\n }\n const index = enabledItems.indexOf(prev) - 1\n return enabledItems[index === -1 ? enabledItems.length - 1 : index]\n })\n } else if (key === 'ArrowDown') {\n setHighlightedItem((prev) => {\n if (prev == null) {\n return enabledItems[0]\n }\n const index = enabledItems.indexOf(prev)\n return enabledItems[index === enabledItems.length - 1 ? 0 : index + 1]\n })\n }\n }\n\n const contextValue = useMemo(\n () => ({\n registerItem,\n }),\n [registerItem],\n )\n\n useEffect(() => {\n if (shouldAutoFocus && items != null && highlightedItem == null) {\n setHighlightedItem(items.find((item) => !item.current?.disabled))\n }\n\n if (highlightedItem != null && highlightedItem?.current != null) {\n highlightedItem.current.focus()\n }\n }, [items, highlightedItem, shouldAutoFocus])\n\n return (\n <DropDownContext value={contextValue}>\n <div\n className={(itemsContainerClassNames ?? ['toolbar-popup__dropdown-items']).join(' ')}\n data-dropdown-key={dropdownKey}\n data-theme=\"dark\"\n id={id}\n onKeyDown={handleKeyDown}\n popover=\"manual\"\n ref={dropDownRef}\n role=\"menu\"\n tabIndex={-1}\n >\n {children}\n </div>\n </DropDownContext>\n )\n}\n\nexport function DropDown({\n buttonAriaLabel,\n buttonClassName,\n children,\n disabled = false,\n dropdownKey,\n Icon,\n itemsContainerClassNames,\n label,\n stopCloseOnClickSelf,\n}: {\n buttonAriaLabel?: string\n buttonClassName: string\n children: ReactNode\n disabled?: boolean\n dropdownKey: string\n Icon?: React.FC\n itemsContainerClassNames?: string[]\n label?: string\n stopCloseOnClickSelf?: boolean\n}): React.ReactNode {\n const dropDownRef = useRef<HTMLDivElement>(null)\n const buttonRef = useRef<HTMLButtonElement>(null)\n const openedViaKeyboardRef = useRef(false)\n const generatedId = useId()\n const menuId = `toolbar-dropdown-${dropdownKey}-${generatedId}`\n const [showDropDown, setShowDropDown] = useState(false)\n\n const handleClose = ({ restoreFocus = true }: { restoreFocus?: boolean } = {}): void => {\n setShowDropDown(false)\n if (restoreFocus && buttonRef?.current != null) {\n buttonRef.current.focus()\n }\n }\n\n useEffect(() => {\n const button = buttonRef.current\n const dropDown = dropDownRef.current\n\n if (showDropDown && button !== null && dropDown !== null) {\n if (!dropDown.matches(':popover-open')) {\n dropDown.showPopover()\n }\n\n const updatePosition = (): void => {\n const { bottom, left, top } = button.getBoundingClientRect()\n const offset = 8\n const gap = 5\n const below = bottom + gap\n const above = top - dropDown.offsetHeight - gap\n const maxTop = Math.max(offset, window.innerHeight - dropDown.offsetHeight - offset)\n const preferredTop =\n below + dropDown.offsetHeight + offset <= window.innerHeight\n ? below\n : above >= offset\n ? above\n : below\n\n dropDown.style.position = 'fixed'\n dropDown.style.top = `${Math.max(offset, Math.min(preferredTop, maxTop))}px`\n dropDown.style.left = `${Math.max(8, Math.min(left - 5, window.innerWidth - dropDown.offsetWidth - 20))}px`\n }\n\n updatePosition()\n window.addEventListener('resize', updatePosition)\n window.addEventListener('scroll', updatePosition, { capture: true, passive: true })\n\n return () => {\n window.removeEventListener('resize', updatePosition)\n window.removeEventListener('scroll', updatePosition, { capture: true })\n }\n }\n }, [dropDownRef, buttonRef, showDropDown])\n\n useEffect(() => {\n const button = buttonRef.current\n\n if (button !== null && showDropDown) {\n const handle = (event: MouseEvent): void => {\n const target = event.target\n if (!isDOMNode(target)) {\n return\n }\n if (stopCloseOnClickSelf) {\n if (dropDownRef.current && dropDownRef.current.contains(target)) {\n return\n }\n }\n if (!button.contains(target)) {\n setShowDropDown(false)\n }\n }\n document.addEventListener('click', handle)\n\n return () => {\n document.removeEventListener('click', handle)\n }\n }\n }, [dropDownRef, buttonRef, showDropDown, stopCloseOnClickSelf])\n\n return (\n <React.Fragment>\n <button\n aria-controls={menuId}\n aria-expanded={showDropDown}\n aria-haspopup=\"menu\"\n aria-label={buttonAriaLabel}\n className={buttonClassName + (showDropDown ? ' active' : '')}\n data-dropdown-key={dropdownKey}\n disabled={disabled}\n onClick={(event) => {\n event.preventDefault()\n openedViaKeyboardRef.current = false\n setShowDropDown(!showDropDown)\n }}\n onKeyDown={(event) => {\n if (event.key === 'Enter' || event.key === ' ') {\n event.preventDefault()\n openedViaKeyboardRef.current = true\n setShowDropDown(!showDropDown)\n }\n }}\n onMouseDown={(e) => {\n // This fixes a bug where you are unable to click the button if you are in a NESTED editor (editor in blocks field in editor).\n // Thus only happens if you click on the SVG of the button. Clicking on the outside works. Related issue: https://github.com/payloadcms/payload/issues/4025\n // TODO: Find out why exactly it happens and why e.preventDefault() on the mouseDown fixes it. Write that down here, or potentially fix a root cause, if there is any.\n e.preventDefault()\n }}\n ref={buttonRef}\n type=\"button\"\n >\n {Icon && <Icon />}\n {label && <span className=\"toolbar-popup__dropdown-label\">{label}</span>}\n <i className=\"toolbar-popup__dropdown-caret\" />\n </button>\n\n {showDropDown && (\n <DropDownItems\n dropdownKey={dropdownKey}\n dropDownRef={dropDownRef}\n id={menuId}\n itemsContainerClassNames={itemsContainerClassNames}\n onClose={handleClose}\n shouldAutoFocus={openedViaKeyboardRef.current}\n >\n {children}\n </DropDownItems>\n )}\n </React.Fragment>\n )\n}\n"],"mappings":"AAAA;;;AACA,SAASA,MAAM,QAAQ;AACvB,SAASC,aAAa,EAAEC,SAAS,QAA4B;AAC7D,OAAOC,KAAA,IAELC,WAAW,EACXC,SAAS,EACTC,KAAK,EACLC,OAAO,EACPC,MAAM,EACNC,QAAQ,QACH;AAIP,MAAMC,SAAA,GAAY;AAMlB,MAAMC,eAAA,gBAAkBR,KAAA,CAAMS,aAAa,CAA6B;AAExE,OAAO,SAASC,aAAa;EAC3BC,MAAM;EACNC,QAAQ;EACRC,MAAM;EACNC,OAAO;EACPC,IAAI;EACJC,IAAI;EACJC,OAAO;EACPC;AAAO,CAUR;EACC,MAAMC,SAAA,GAAYf,OAAA,CAAQ;IACxB,OAAO,CACLG,SAAA,EACAO,OAAA,KAAY,QAAQ,aAAa,IACjCH,MAAA,GAAS,WAAW,IACpBK,IAAA,EAAMI,GAAA,GAAM,GAAGb,SAAA,IAAaS,IAAA,CAAKI,GAAG,EAAE,GAAG,GAC1C,CACEC,MAAM,CAACC,OAAA,EACPC,IAAI,CAAC;EACV,GAAG,CAACT,OAAA,EAASH,MAAA,EAAQK,IAAA,CAAKI,GAAG,CAAC;EAE9B,MAAMI,GAAA,GAAMnB,MAAA,CAA0B;EAEtC,MAAMoB,eAAA,GAAkBzB,KAAA,CAAM0B,GAAG,CAAClB,eAAA;EAElC,IAAIiB,eAAA,KAAoB,MAAM;IAC5B,MAAM,IAAIE,KAAA,CAAM;EAClB;EAEA,MAAM;IAAEC;EAAY,CAAE,GAAGH,eAAA;EAEzBvB,SAAA,CAAU;IACR,IAAIsB,GAAA,EAAKK,OAAA,IAAW,MAAM;MACxBD,YAAA,CAAaJ,GAAA;IACf;EACF,GAAG,CAACA,GAAA,EAAKI,YAAA,CAAa;EAEtB,oBACEE,IAAA,CAACjC,MAAA;IACC,cAAYqB,OAA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AAA;MACf,iBAAc;MACd,cAAYR,eAAA;MACZzD,SAAA,EAAW0D,eAAA,IAAmBO,YAAA,GAAe,YAAY,EAAC;MAC1D,qBAAmBlC,WAAA;MACnBlB,QAAA,EAAUA,QAAA;MACVQ,OAAA,EAAUsB,OAAA;QACRA,OAAA,CAAMhB,cAAc;QACpBmC,oBAAA,CAAqBpD,OAAO,GAAG;QAC/BwD,eAAA,CAAgB,CAACD,YAAA;MACnB;MACAX,SAAA,EAAYX,OAAA;QACV,IAAIA,OAAA,CAAM1C,GAAG,KAAK,WAAW0C,OAAA,CAAM1C,GAAG,KAAK,KAAK;UAC9C0C,OAAA,CAAMhB,cAAc;UACpBmC,oBAAA,CAAqBpD,OAAO,GAAG;UAC/BwD,eAAA,CAAgB,CAACD,YAAA;QACnB;MACF;MACAxC,WAAA,EAAcC,CAAA;QACZ;QACA;QACA;QACAA,CAAA,CAAEC,cAAc;MAClB;MACAtB,GAAA,EAAKwD,SAAA;MACLjC,IAAA,EAAK;iBAEJhC,IAAA,iBAAQe,IAAA,CAACf,IAAA,OACT+D,KAAA,iBAAShD,IAAA,CAAC;QAAKX,SAAA,EAAU;kBAAiC2D;uBAC3DhD,IAAA,CAAC;QAAEX,SAAA,EAAU;;QAGdiE,YAAA,iBACCtD,IAAA,CAACkB,aAAA;MACCE,WAAA,EAAaA,WAAA;MACbC,WAAA,EAAaA,WAAA;MACbF,EAAA,EAAIkC,MAAA;MACJ/B,wBAAA,EAA0BA,wBAAA;MAC1BC,OAAA,EAASiC,WAAA;MACThC,eAAA,EAAiB2B,oBAAA,CAAqBpD,OAAO;gBAE5CjB;;;AAKX","ignoreList":[]}
|
|
1
|
+
{"version":3,"file":"DropDown.js","names":["c","_c","Button","$addUpdateTag","isDOMNode","React","useCallback","useEffect","useId","useMemo","useRef","useState","baseClass","DropDownContext","createContext","DropDownItem","active","children","editor","enabled","Icon","item","itemKey","tooltip","className","key","filter","Boolean","join","ref","dropDownContext","use","Error","registerItem","current","_jsx","buttonStyle","disabled","extraButtonProps","isActive","undefined","role","tabIndex","icon","iconPosition","onClick","focus","update","onSelect","onMouseDown","e","preventDefault","type","DropDownItems","t0","$","id","dropdownKey","dropDownRef","itemsContainerClassNames","onClose","shouldAutoFocus","items","setItems","highlightedItem","setHighlightedItem","t1","Symbol","for","itemRef","prev","t2","event","enabledItems","_temp","includes","setTimeout","restoreFocus","prev_0","index","indexOf","length","prev_1","index_0","handleKeyDown","t3","contextValue","t4","t5","find","_temp2","t6","value","onKeyDown","popover","item_0","DropDown","buttonAriaLabel","buttonClassName","label","stopCloseOnClickSelf","buttonRef","openedViaKeyboardRef","generatedId","menuId","showDropDown","setShowDropDown","handleClose","button","dropDown","matches","showPopover","updatePosition","bottom","left","top","getBoundingClientRect","offset","gap","below","above","offsetHeight","maxTop","Math","max","window","innerHeight","preferredTop","style","position","min","innerWidth","offsetWidth","addEventListener","capture","passive","removeEventListener","handle","target","contains","document","_jsxs","Fragment"],"sources":["../../../../../src/features/toolbars/shared/ToolbarDropdown/DropDown.tsx"],"sourcesContent":["'use client'\nimport { Button } from '@payloadcms/ui'\nimport { $addUpdateTag, isDOMNode, type LexicalEditor } from 'lexical'\nimport React, {\n type ReactNode,\n useCallback,\n useEffect,\n useId,\n useMemo,\n useRef,\n useState,\n} from 'react'\n\nimport type { ToolbarGroupItem } from '../../types.js'\n\nconst baseClass = 'toolbar-popup__dropdown-item'\n\ninterface DropDownContextType {\n registerItem: (ref: React.RefObject<HTMLButtonElement | null>) => void\n}\n\nconst DropDownContext = React.createContext<DropDownContextType | null>(null)\n\nexport function DropDownItem({\n active,\n children,\n editor,\n enabled,\n Icon,\n item,\n itemKey,\n tooltip,\n}: {\n active?: boolean\n children: React.ReactNode\n editor: LexicalEditor\n enabled?: boolean\n Icon: React.ReactNode\n item: ToolbarGroupItem\n itemKey: string\n tooltip?: string\n}): React.ReactNode {\n const className = useMemo(() => {\n return [\n baseClass,\n enabled === false ? 'disabled' : '',\n active ? 'active' : '',\n item?.key ? `${baseClass}-${item.key}` : '',\n ]\n .filter(Boolean)\n .join(' ')\n }, [enabled, active, item.key])\n\n const ref = useRef<HTMLButtonElement>(null)\n\n const dropDownContext = React.use(DropDownContext)\n\n if (dropDownContext === null) {\n throw new Error('DropDownItem must be used within a DropDown')\n }\n\n const { registerItem } = dropDownContext\n\n useEffect(() => {\n if (ref?.current != null) {\n registerItem(ref)\n }\n }, [ref, registerItem])\n\n return (\n <Button\n aria-label={tooltip}\n buttonStyle=\"ghost\"\n className={className}\n disabled={enabled === false}\n extraButtonProps={{\n 'aria-checked': item.isActive ? Boolean(active) : undefined,\n 'data-item-key': itemKey,\n role: item.isActive ? 'menuitemcheckbox' : 'menuitem',\n tabIndex: -1,\n }}\n icon={Icon}\n iconPosition=\"left\"\n onClick={() => {\n if (enabled !== false) {\n editor.focus(() => {\n editor.update(() => {\n $addUpdateTag('toolbar')\n })\n // We need to wrap the onSelect in the callback, so the editor is properly focused before the onSelect is called.\n item.onSelect?.({\n editor,\n isActive: active!,\n })\n })\n }\n }}\n onMouseDown={(e: React.MouseEvent) => {\n // This is required for Firefox compatibility. Without it, the dropdown will disappear without the onClick being called.\n // This only happens in Firefox. Must be something about how Firefox handles focus events differently.\n e.preventDefault()\n }}\n ref={ref}\n tooltip={tooltip}\n type=\"button\"\n >\n {children}\n </Button>\n )\n}\n\nfunction DropDownItems({\n id,\n children,\n dropdownKey,\n dropDownRef,\n itemsContainerClassNames,\n onClose,\n shouldAutoFocus,\n}: {\n children: React.ReactNode\n dropdownKey?: string\n dropDownRef: React.Ref<HTMLDivElement>\n id: string\n itemsContainerClassNames?: string[]\n onClose: (options?: { restoreFocus?: boolean }) => void\n shouldAutoFocus: boolean\n}): React.ReactElement {\n const [items, setItems] = useState<Array<React.RefObject<HTMLButtonElement | null>>>()\n const [highlightedItem, setHighlightedItem] =\n useState<React.RefObject<HTMLButtonElement | null>>()\n\n const registerItem = useCallback(\n (itemRef: React.RefObject<HTMLButtonElement | null>) => {\n setItems((prev) => (prev != null ? [...prev, itemRef] : [itemRef]))\n },\n [setItems],\n )\n\n const handleKeyDown = (event: React.KeyboardEvent<HTMLDivElement>): void => {\n if (items == null) {\n return\n }\n\n const { key } = event\n const enabledItems = items.filter((item) => !item.current?.disabled)\n\n if (['ArrowDown', 'ArrowUp', 'Escape'].includes(key)) {\n event.preventDefault()\n }\n\n if (key === 'Escape') {\n onClose()\n } else if (key === 'Tab') {\n setTimeout(() => onClose({ restoreFocus: false }))\n } else if (key === 'ArrowUp') {\n setHighlightedItem((prev) => {\n if (prev == null) {\n return enabledItems[0]\n }\n const index = enabledItems.indexOf(prev) - 1\n return enabledItems[index === -1 ? enabledItems.length - 1 : index]\n })\n } else if (key === 'ArrowDown') {\n setHighlightedItem((prev) => {\n if (prev == null) {\n return enabledItems[0]\n }\n const index = enabledItems.indexOf(prev)\n return enabledItems[index === enabledItems.length - 1 ? 0 : index + 1]\n })\n }\n }\n\n const contextValue = useMemo(\n () => ({\n registerItem,\n }),\n [registerItem],\n )\n\n useEffect(() => {\n if (shouldAutoFocus && items != null && highlightedItem == null) {\n setHighlightedItem(items.find((item) => !item.current?.disabled))\n }\n\n if (highlightedItem != null && highlightedItem?.current != null) {\n highlightedItem.current.focus()\n }\n }, [items, highlightedItem, shouldAutoFocus])\n\n return (\n <DropDownContext value={contextValue}>\n <div\n className={(itemsContainerClassNames ?? ['toolbar-popup__dropdown-items']).join(' ')}\n data-dropdown-key={dropdownKey}\n data-theme=\"dark\"\n id={id}\n onKeyDown={handleKeyDown}\n popover=\"manual\"\n ref={dropDownRef}\n role=\"menu\"\n tabIndex={-1}\n >\n {children}\n </div>\n </DropDownContext>\n )\n}\n\nexport function DropDown({\n buttonAriaLabel,\n buttonClassName,\n children,\n disabled = false,\n dropdownKey,\n Icon,\n itemsContainerClassNames,\n label,\n stopCloseOnClickSelf,\n}: {\n buttonAriaLabel?: string\n buttonClassName: string\n children: ReactNode\n disabled?: boolean\n dropdownKey: string\n Icon?: React.FC\n itemsContainerClassNames?: string[]\n label?: string\n stopCloseOnClickSelf?: boolean\n}): React.ReactNode {\n const dropDownRef = useRef<HTMLDivElement>(null)\n const buttonRef = useRef<HTMLButtonElement>(null)\n const openedViaKeyboardRef = useRef(false)\n const generatedId = useId()\n const menuId = `toolbar-dropdown-${dropdownKey}-${generatedId}`\n const [showDropDown, setShowDropDown] = useState(false)\n\n const handleClose = ({ restoreFocus = true }: { restoreFocus?: boolean } = {}): void => {\n setShowDropDown(false)\n if (restoreFocus && buttonRef?.current != null) {\n buttonRef.current.focus()\n }\n }\n\n useEffect(() => {\n const button = buttonRef.current\n const dropDown = dropDownRef.current\n\n if (showDropDown && button !== null && dropDown !== null) {\n if (!dropDown.matches(':popover-open')) {\n dropDown.showPopover()\n }\n\n const updatePosition = (): void => {\n const { bottom, left, top } = button.getBoundingClientRect()\n const offset = 8\n const gap = 5\n const below = bottom + gap\n const above = top - dropDown.offsetHeight - gap\n const maxTop = Math.max(offset, window.innerHeight - dropDown.offsetHeight - offset)\n const preferredTop =\n below + dropDown.offsetHeight + offset <= window.innerHeight\n ? below\n : above >= offset\n ? above\n : below\n\n dropDown.style.position = 'fixed'\n dropDown.style.top = `${Math.max(offset, Math.min(preferredTop, maxTop))}px`\n dropDown.style.left = `${Math.max(8, Math.min(left - 5, window.innerWidth - dropDown.offsetWidth - 20))}px`\n }\n\n updatePosition()\n window.addEventListener('resize', updatePosition)\n window.addEventListener('scroll', updatePosition, { capture: true, passive: true })\n\n return () => {\n window.removeEventListener('resize', updatePosition)\n window.removeEventListener('scroll', updatePosition, { capture: true })\n }\n }\n }, [dropDownRef, buttonRef, showDropDown])\n\n useEffect(() => {\n const button = buttonRef.current\n\n if (button !== null && showDropDown) {\n const handle = (event: MouseEvent): void => {\n const target = event.target\n if (!isDOMNode(target)) {\n return\n }\n if (stopCloseOnClickSelf) {\n if (dropDownRef.current && dropDownRef.current.contains(target)) {\n return\n }\n }\n if (!button.contains(target)) {\n setShowDropDown(false)\n }\n }\n document.addEventListener('click', handle)\n\n return () => {\n document.removeEventListener('click', handle)\n }\n }\n }, [dropDownRef, buttonRef, showDropDown, stopCloseOnClickSelf])\n\n return (\n <React.Fragment>\n <button\n aria-controls={menuId}\n aria-expanded={showDropDown}\n aria-haspopup=\"menu\"\n aria-label={buttonAriaLabel}\n className={buttonClassName + (showDropDown ? ' active' : '')}\n data-dropdown-key={dropdownKey}\n disabled={disabled}\n onClick={(event) => {\n event.preventDefault()\n openedViaKeyboardRef.current = false\n setShowDropDown(!showDropDown)\n }}\n onKeyDown={(event) => {\n if (event.key === 'Enter' || event.key === ' ') {\n event.preventDefault()\n openedViaKeyboardRef.current = true\n setShowDropDown(!showDropDown)\n }\n }}\n onMouseDown={(e) => {\n // This fixes a bug where you are unable to click the button if you are in a NESTED editor (editor in blocks field in editor).\n // Thus only happens if you click on the SVG of the button. Clicking on the outside works. Related issue: https://github.com/payloadcms/payload/issues/4025\n // TODO: Find out why exactly it happens and why e.preventDefault() on the mouseDown fixes it. Write that down here, or potentially fix a root cause, if there is any.\n e.preventDefault()\n }}\n ref={buttonRef}\n type=\"button\"\n >\n {Icon && <Icon />}\n {label && <span className=\"toolbar-popup__dropdown-label\">{label}</span>}\n <i className=\"toolbar-popup__dropdown-caret\" />\n </button>\n\n {showDropDown && (\n <DropDownItems\n dropdownKey={dropdownKey}\n dropDownRef={dropDownRef}\n id={menuId}\n itemsContainerClassNames={itemsContainerClassNames}\n onClose={handleClose}\n shouldAutoFocus={openedViaKeyboardRef.current}\n >\n {children}\n </DropDownItems>\n )}\n </React.Fragment>\n )\n}\n"],"mappings":"AAAA;;AAAA,SAAAA,CAAA,IAAAC,EAAA;;AACA,SAASC,MAAM,QAAQ;AACvB,SAASC,aAAa,EAAEC,SAAS,QAA4B;AAC7D,OAAOC,KAAA,IAELC,WAAW,EACXC,SAAS,EACTC,KAAK,EACLC,OAAO,EACPC,MAAM,EACNC,QAAQ,QACH;AAIP,MAAMC,SAAA,GAAY;AAMlB,MAAMC,eAAA,gBAAkBR,KAA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K,WAAW+C,OAAA,CAAM/C,GAAG,KAAK,KAAK;UAC9C+C,OAAA,CAAMrB,cAAc;UACpBmD,oBAAA,CAAqBpE,OAAO,GAAG;UAC/BwE,eAAA,CAAgB,CAACD,YAAA;QACnB;MACF;MACAxD,WAAA,EAAcC,CAAA;QACZ;QACA;QACA;QACAA,CAAA,CAAEC,cAAc;MAClB;MACAtB,GAAA,EAAKwE,SAAA;MACLjD,IAAA,EAAK;iBAEJhC,IAAA,iBAAQe,IAAA,CAACf,IAAA,OACT+E,KAAA,iBAAShE,IAAA,CAAC;QAAKX,SAAA,EAAU;kBAAiC2E;uBAC3DhE,IAAA,CAAC;QAAEX,SAAA,EAAU;;QAGdiF,YAAA,iBACCtE,IAAA,CAACkB,aAAA;MACCI,WAAA,EAAaA,WAAA;MACbC,WAAA,EAAaA,WAAA;MACbF,EAAA,EAAIgD,MAAA;MACJ7C,wBAAA,EAA0BA,wBAAA;MAC1BC,OAAA,EAAS+C,WAAA;MACT9C,eAAA,EAAiByC,oBAAA,CAAqBpE,OAAO;gBAE5CjB;;;AAKX","ignoreList":[]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../src/features/toolbars/shared/ToolbarDropdown/index.tsx"],"names":[],"mappings":"AACA,OAAO,KAAkB,MAAM,OAAO,CAAA;AAItC,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,SAAS,CAAA;AAI5C,OAAO,KAAK,EAAE,oBAAoB,EAAoB,MAAM,gBAAgB,CAAA;AAC5E,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,wBAAwB,CAAA;AAG/D,OAAO,aAAa,CAAA;AAsEpB,eAAO,MAAM,eAAe,kGASzB;IACD,UAAU,EAAE,WAAW,CAAA;IACvB,UAAU,CAAC,EAAE,MAAM,EAAE,CAAA;IACrB,MAAM,EAAE,aAAa,CAAA;IACrB,KAAK,EAAE,oBAAoB,CAAA;IAC3B,UAAU,EAAE,iBAAiB,CAAA;IAC7B,IAAI,CAAC,EAAE,KAAK,CAAC,EAAE,CAAA;IACf,wBAAwB,CAAC,EAAE,MAAM,EAAE,CAAA;IACnC,KAAK,CAAC,EAAE,MAAM,CAAA;CACf,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../src/features/toolbars/shared/ToolbarDropdown/index.tsx"],"names":[],"mappings":"AACA,OAAO,KAAkB,MAAM,OAAO,CAAA;AAItC,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,SAAS,CAAA;AAI5C,OAAO,KAAK,EAAE,oBAAoB,EAAoB,MAAM,gBAAgB,CAAA;AAC5E,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,wBAAwB,CAAA;AAG/D,OAAO,aAAa,CAAA;AAsEpB,eAAO,MAAM,eAAe,kGASzB;IACD,UAAU,EAAE,WAAW,CAAA;IACvB,UAAU,CAAC,EAAE,MAAM,EAAE,CAAA;IACrB,MAAM,EAAE,aAAa,CAAA;IACrB,KAAK,EAAE,oBAAoB,CAAA;IAC3B,UAAU,EAAE,iBAAiB,CAAA;IAC7B,IAAI,CAAC,EAAE,KAAK,CAAC,EAAE,CAAA;IACf,wBAAwB,CAAC,EAAE,MAAM,EAAE,CAAA;IACnC,KAAK,CAAC,EAAE,MAAM,CAAA;CACf,sBA+CA,CAAA"}
|
|
@@ -107,18 +107,34 @@ export const ToolbarDropdown = ({
|
|
|
107
107
|
items,
|
|
108
108
|
key: groupKey
|
|
109
109
|
} = group;
|
|
110
|
+
const {
|
|
111
|
+
i18n
|
|
112
|
+
} = useTranslation();
|
|
113
|
+
const {
|
|
114
|
+
fieldProps: {
|
|
115
|
+
featureClientSchemaMap,
|
|
116
|
+
schemaPath
|
|
117
|
+
}
|
|
118
|
+
} = useEditorConfigContext();
|
|
119
|
+
const activeItemLabels = groupState.activeItems.map(item => typeof item.label === 'function' ? item.label({
|
|
120
|
+
featureClientSchemaMap,
|
|
121
|
+
i18n,
|
|
122
|
+
schemaPath
|
|
123
|
+
}) : item.label || item.key);
|
|
124
|
+
const dropdownLabel = groupKey === 'text' ? i18n.t('lexical:general:textStyle') : undefined;
|
|
125
|
+
const buttonAriaLabel = [...new Set([label, ...activeItemLabels, dropdownLabel].filter(Boolean))].join(', ') || groupKey;
|
|
110
126
|
const renderedItems = useMemo(() => {
|
|
111
|
-
return items?.length ? items.map(
|
|
112
|
-
active: groupState.activeItemKeys.includes(
|
|
127
|
+
return items?.length ? items.map(item_0 => /*#__PURE__*/_jsx(MemoToolbarItem, {
|
|
128
|
+
active: groupState.activeItemKeys.includes(item_0.key),
|
|
113
129
|
anchorElem: anchorElem,
|
|
114
130
|
editor: editor,
|
|
115
|
-
enabled: groupState.enabledItemKeys.includes(
|
|
131
|
+
enabled: groupState.enabledItemKeys.includes(item_0.key),
|
|
116
132
|
iconOnly: group.iconOnly,
|
|
117
|
-
item:
|
|
118
|
-
},
|
|
133
|
+
item: item_0
|
|
134
|
+
}, item_0.key)) : null;
|
|
119
135
|
}, [items, groupState.activeItemKeys, groupState.enabledItemKeys, anchorElem, editor]);
|
|
120
136
|
return /*#__PURE__*/_jsx(DropDown, {
|
|
121
|
-
buttonAriaLabel:
|
|
137
|
+
buttonAriaLabel: buttonAriaLabel,
|
|
122
138
|
buttonClassName: [baseClass, `${baseClass}-${groupKey}`, ...(classNames || [])].filter(Boolean).join(' '),
|
|
123
139
|
disabled: !groupState.enabledGroup,
|
|
124
140
|
dropdownKey: groupKey,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":["c","_c","React","useMemo","baseClass","useTranslation","useEditorConfigContext","DropDown","DropDownItem","ToolbarItem","t0","$","active","anchorElem","editor","enabled","iconOnly","item","i18n","fieldProps","t1","featureClientSchemaMap","schemaPath","Component","t2","_jsx","title","key","croppedTitle","label","length","substring","Icon","ChildComponent","undefined","itemKey","tooltip","children","className","MemoToolbarItem","memo","ToolbarDropdown","classNames","group","groupState","itemsContainerClassNames","items","groupKey","
|
|
1
|
+
{"version":3,"file":"index.js","names":["c","_c","React","useMemo","baseClass","useTranslation","useEditorConfigContext","DropDown","DropDownItem","ToolbarItem","t0","$","active","anchorElem","editor","enabled","iconOnly","item","i18n","fieldProps","t1","featureClientSchemaMap","schemaPath","Component","t2","_jsx","title","key","croppedTitle","label","length","substring","Icon","ChildComponent","undefined","itemKey","tooltip","children","className","MemoToolbarItem","memo","ToolbarDropdown","classNames","group","groupState","itemsContainerClassNames","items","groupKey","activeItemLabels","activeItems","map","dropdownLabel","t","buttonAriaLabel","Set","filter","Boolean","join","renderedItems","activeItemKeys","includes","enabledItemKeys","buttonClassName","disabled","enabledGroup","dropdownKey"],"sources":["../../../../../src/features/toolbars/shared/ToolbarDropdown/index.tsx"],"sourcesContent":["'use client'\nimport React, { useMemo } from 'react'\n\nconst baseClass = 'toolbar-popup__dropdown'\n\nimport type { LexicalEditor } from 'lexical'\n\nimport { useTranslation } from '@payloadcms/ui'\n\nimport type { ToolbarDropdownGroup, ToolbarGroupItem } from '../../types.js'\nimport type { ToolbarGroupState } from '../useToolbarStates.js'\n\nimport { useEditorConfigContext } from '../../../../lexical/config/client/EditorConfigProvider.js'\nimport './index.css'\nimport { DropDown, DropDownItem } from './DropDown.js'\n\nconst ToolbarItem = ({\n active,\n anchorElem,\n editor,\n enabled,\n iconOnly,\n item,\n}: {\n active?: boolean\n anchorElem: HTMLElement\n editor: LexicalEditor\n enabled?: boolean\n iconOnly?: boolean\n item: ToolbarGroupItem\n}) => {\n const { i18n } = useTranslation<{}, string>()\n const {\n fieldProps: { featureClientSchemaMap, schemaPath },\n } = useEditorConfigContext()\n\n if (item.Component) {\n return (\n item?.Component && (\n <item.Component\n active={active}\n anchorElem={anchorElem}\n editor={editor}\n enabled={enabled}\n item={item}\n key={item.key}\n />\n )\n )\n }\n\n let title = item.key\n let croppedTitle = item.key\n if (item.label) {\n title =\n typeof item.label === 'function'\n ? item.label({ featureClientSchemaMap, i18n, schemaPath })\n : item.label\n }\n if (title.length > 25) {\n croppedTitle = title.substring(0, 25) + '...'\n } else {\n croppedTitle = title\n }\n\n return (\n <DropDownItem\n active={active}\n editor={editor}\n enabled={enabled}\n Icon={item?.ChildComponent ? <item.ChildComponent /> : undefined}\n item={item}\n itemKey={item.key}\n key={item.key}\n tooltip={iconOnly ? title : undefined}\n >\n <span className=\"text\">{croppedTitle}</span>\n </DropDownItem>\n )\n}\n\nconst MemoToolbarItem = React.memo(ToolbarItem)\n\nexport const ToolbarDropdown = ({\n anchorElem,\n classNames,\n editor,\n group,\n groupState,\n Icon,\n itemsContainerClassNames,\n label,\n}: {\n anchorElem: HTMLElement\n classNames?: string[]\n editor: LexicalEditor\n group: ToolbarDropdownGroup\n groupState: ToolbarGroupState\n Icon?: React.FC\n itemsContainerClassNames?: string[]\n label?: string\n}) => {\n const { items, key: groupKey } = group\n const { i18n } = useTranslation<Record<string, never>, string>()\n const {\n fieldProps: { featureClientSchemaMap, schemaPath },\n } = useEditorConfigContext()\n const activeItemLabels = groupState.activeItems.map((item) =>\n typeof item.label === 'function'\n ? item.label({ featureClientSchemaMap, i18n, schemaPath })\n : item.label || item.key,\n )\n const dropdownLabel = groupKey === 'text' ? i18n.t('lexical:general:textStyle') : undefined\n const buttonAriaLabel =\n [...new Set([label, ...activeItemLabels, dropdownLabel].filter(Boolean))].join(', ') || groupKey\n\n const renderedItems = useMemo(() => {\n return items?.length\n ? items.map((item) => (\n <MemoToolbarItem\n active={groupState.activeItemKeys.includes(item.key)}\n anchorElem={anchorElem}\n editor={editor}\n enabled={groupState.enabledItemKeys.includes(item.key)}\n iconOnly={group.iconOnly}\n item={item}\n key={item.key}\n />\n ))\n : null\n }, [items, groupState.activeItemKeys, groupState.enabledItemKeys, anchorElem, editor])\n\n return (\n <DropDown\n buttonAriaLabel={buttonAriaLabel}\n buttonClassName={[baseClass, `${baseClass}-${groupKey}`, ...(classNames || [])]\n .filter(Boolean)\n .join(' ')}\n disabled={!groupState.enabledGroup}\n dropdownKey={groupKey}\n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AACc,eAAA;MACC3B,MAAA,EAAQgC,UAAA,CAAWe,cAAc,CAACC,QAAQ,CAAC3C,MAAA,CAAKU,GAAG;MACnDd,UAAA,EAAYA,UAAA;MACZC,MAAA,EAAQA,MAAA;MACRC,OAAA,EAAS6B,UAAA,CAAWiB,eAAe,CAACD,QAAQ,CAAC3C,MAAA,CAAKU,GAAG;MACrDX,QAAA,EAAU2B,KAAA,CAAM3B,QAAQ;MACxBC,IAAA,EAAMA;OACDA,MAAA,CAAKU,GAAG,KAGjB;EACN,GAAG,CAACmB,KAAA,EAAOF,UAAA,CAAWe,cAAc,EAAEf,UAAA,CAAWiB,eAAe,EAAEhD,UAAA,EAAYC,MAAA,CAAO;EAErF,oBACEW,IAAA,CAAClB,QAAA;IACC8C,eAAA,EAAiBA,eAAA;IACjBS,eAAA,EAAiB,CAAC1D,SAAA,EAAW,GAAGA,SAAA,IAAa2C,QAAA,EAAU,E,IAAML,UAAA,IAAc,EAAE,EAAE,CAC5Ea,MAAM,CAACC,OAAA,EACPC,IAAI,CAAC;IACRM,QAAA,EAAU,CAACnB,UAAA,CAAWoB,YAAY;IAClCC,WAAA,EAAalB,QAAA;IACbf,IAAA,EAAMA,IAAA;IACNa,wBAAA,EAA0B,CAAC,GAAGzC,SAAA,QAAiB,E,IAAMyC,wBAAA,IAA4B,EAAE,EAAE;IAErFhB,KAAA,EAAOA,KAAA;cAEN6B;KAHIX,QAAA;AAMX","ignoreList":[]}
|
|
@@ -1,79 +1,109 @@
|
|
|
1
1
|
'use client';
|
|
2
2
|
|
|
3
|
+
import { c as _c } from "react/compiler-runtime";
|
|
3
4
|
import { useEffect } from 'react';
|
|
4
|
-
export function useToolbarKeyboardNavigation({
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
const buttons = getButtons();
|
|
16
|
-
const enabledButtons = buttons.filter(button_0 => !button_0.disabled);
|
|
17
|
-
if (!activeButton || !enabledButtons.includes(activeButton)) {
|
|
18
|
-
activeButton = enabledButtons[0];
|
|
19
|
-
}
|
|
20
|
-
for (const button_1 of buttons) {
|
|
21
|
-
button_1.tabIndex = button_1 === activeButton ? 0 : -1;
|
|
22
|
-
}
|
|
23
|
-
};
|
|
24
|
-
const handleFocus = event => {
|
|
25
|
-
const button_3 = getButtons().find(button_2 => button_2 === event.target);
|
|
26
|
-
if (button_3) {
|
|
27
|
-
activeButton = button_3;
|
|
28
|
-
updateTabStops();
|
|
29
|
-
}
|
|
30
|
-
};
|
|
31
|
-
const handleKeyDown = event_0 => {
|
|
32
|
-
if (event_0.altKey || event_0.ctrlKey || event_0.metaKey || event_0.shiftKey) {
|
|
33
|
-
return;
|
|
34
|
-
}
|
|
35
|
-
const buttons_0 = getButtons().filter(button_4 => !button_4.disabled);
|
|
36
|
-
const index = buttons_0.findIndex(button_5 => button_5 === event_0.target);
|
|
37
|
-
// Dropdown menus and custom inputs retain their own keyboard behavior.
|
|
38
|
-
if (index === -1) {
|
|
5
|
+
export function useToolbarKeyboardNavigation(t0) {
|
|
6
|
+
const $ = _c(3);
|
|
7
|
+
const {
|
|
8
|
+
toolbarRef
|
|
9
|
+
} = t0;
|
|
10
|
+
let t1;
|
|
11
|
+
let t2;
|
|
12
|
+
if ($[0] !== toolbarRef) {
|
|
13
|
+
t1 = () => {
|
|
14
|
+
const toolbar = toolbarRef.current;
|
|
15
|
+
if (!toolbar) {
|
|
39
16
|
return;
|
|
40
17
|
}
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
18
|
+
let activeButton;
|
|
19
|
+
const getButtons = () => Array.from(toolbar.querySelectorAll("button")).filter(button => !button.closest("[role=\"menu\"]") && button.closest("[role=\"toolbar\"]") === toolbar);
|
|
20
|
+
const updateTabStops = () => {
|
|
21
|
+
const buttons = getButtons();
|
|
22
|
+
const enabledButtons = buttons.filter(_temp);
|
|
23
|
+
if (!activeButton || !enabledButtons.includes(activeButton)) {
|
|
24
|
+
activeButton = enabledButtons[0];
|
|
25
|
+
}
|
|
26
|
+
for (const button_1 of buttons) {
|
|
27
|
+
button_1.tabIndex = button_1 === activeButton ? 0 : -1;
|
|
28
|
+
}
|
|
29
|
+
};
|
|
30
|
+
const handleFocus = event => {
|
|
31
|
+
const button_3 = getButtons().find(button_2 => button_2 === event.target);
|
|
32
|
+
if (button_3) {
|
|
33
|
+
activeButton = button_3;
|
|
34
|
+
updateTabStops();
|
|
35
|
+
}
|
|
36
|
+
};
|
|
37
|
+
const handleKeyDown = event_0 => {
|
|
38
|
+
if (event_0.altKey || event_0.ctrlKey || event_0.metaKey || event_0.shiftKey) {
|
|
57
39
|
return;
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
40
|
+
}
|
|
41
|
+
const buttons_0 = getButtons().filter(_temp2);
|
|
42
|
+
const index = buttons_0.findIndex(button_5 => button_5 === event_0.target);
|
|
43
|
+
if (index === -1) {
|
|
44
|
+
return;
|
|
45
|
+
}
|
|
46
|
+
const isRTL = getComputedStyle(toolbar).direction === "rtl";
|
|
47
|
+
let nextIndex;
|
|
48
|
+
bb58: switch (event_0.key) {
|
|
49
|
+
case "ArrowLeft":
|
|
50
|
+
{
|
|
51
|
+
nextIndex = index + (isRTL ? 1 : -1);
|
|
52
|
+
break bb58;
|
|
53
|
+
}
|
|
54
|
+
case "ArrowRight":
|
|
55
|
+
{
|
|
56
|
+
nextIndex = index + (isRTL ? -1 : 1);
|
|
57
|
+
break bb58;
|
|
58
|
+
}
|
|
59
|
+
case "End":
|
|
60
|
+
{
|
|
61
|
+
nextIndex = buttons_0.length - 1;
|
|
62
|
+
break bb58;
|
|
63
|
+
}
|
|
64
|
+
case "Home":
|
|
65
|
+
{
|
|
66
|
+
nextIndex = 0;
|
|
67
|
+
break bb58;
|
|
68
|
+
}
|
|
69
|
+
default:
|
|
70
|
+
{
|
|
71
|
+
return;
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
event_0.preventDefault();
|
|
75
|
+
event_0.stopPropagation();
|
|
76
|
+
buttons_0[(nextIndex + buttons_0.length) % buttons_0.length]?.focus();
|
|
77
|
+
};
|
|
78
|
+
updateTabStops();
|
|
79
|
+
const observer = new MutationObserver(updateTabStops);
|
|
80
|
+
observer.observe(toolbar, {
|
|
81
|
+
attributeFilter: ["disabled"],
|
|
82
|
+
childList: true,
|
|
83
|
+
subtree: true
|
|
84
|
+
});
|
|
85
|
+
toolbar.addEventListener("focusin", handleFocus);
|
|
86
|
+
toolbar.addEventListener("keydown", handleKeyDown);
|
|
87
|
+
return () => {
|
|
88
|
+
observer.disconnect();
|
|
89
|
+
toolbar.removeEventListener("focusin", handleFocus);
|
|
90
|
+
toolbar.removeEventListener("keydown", handleKeyDown);
|
|
91
|
+
};
|
|
76
92
|
};
|
|
77
|
-
|
|
93
|
+
t2 = [toolbarRef];
|
|
94
|
+
$[0] = toolbarRef;
|
|
95
|
+
$[1] = t1;
|
|
96
|
+
$[2] = t2;
|
|
97
|
+
} else {
|
|
98
|
+
t1 = $[1];
|
|
99
|
+
t2 = $[2];
|
|
100
|
+
}
|
|
101
|
+
useEffect(t1, t2);
|
|
102
|
+
}
|
|
103
|
+
function _temp2(button_4) {
|
|
104
|
+
return !button_4.disabled;
|
|
105
|
+
}
|
|
106
|
+
function _temp(button_0) {
|
|
107
|
+
return !button_0.disabled;
|
|
78
108
|
}
|
|
79
109
|
//# sourceMappingURL=useToolbarKeyboardNavigation.js.map
|