@doist/reactist 11.5.1 → 12.0.2
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/reactist.cjs.development.js +1336 -1496
- package/dist/reactist.cjs.development.js.map +1 -1
- package/dist/reactist.cjs.production.min.js +1 -1
- package/dist/reactist.cjs.production.min.js.map +1 -1
- package/es/_virtual/_rollupPluginBabelHelpers.js +18 -21
- package/es/_virtual/_rollupPluginBabelHelpers.js.map +1 -1
- package/es/components/checkbox/checkbox.js +7 -9
- package/es/components/checkbox/checkbox.js.map +1 -1
- package/es/components/color-picker/color-picker.js +24 -28
- package/es/components/color-picker/color-picker.js.map +1 -1
- package/es/components/deprecated-button/deprecated-button.js +16 -18
- package/es/components/deprecated-button/deprecated-button.js.map +1 -1
- package/es/components/deprecated-loading/deprecated-loading.js +7 -10
- package/es/components/deprecated-loading/deprecated-loading.js.map +1 -1
- package/es/components/deprecated-modal/deprecated-modal.js +69 -101
- package/es/components/deprecated-modal/deprecated-modal.js.map +1 -1
- package/es/components/deprecated-modal/index.js +4 -4
- package/es/components/deprecated-modal/index.js.map +1 -1
- package/es/components/dropdown/dropdown.js +86 -85
- package/es/components/dropdown/dropdown.js.map +1 -1
- package/es/components/icons/CloseIcon.svg.js +9 -11
- package/es/components/icons/CloseIcon.svg.js.map +1 -1
- package/es/components/input/input.js +4 -3
- package/es/components/input/input.js.map +1 -1
- package/es/components/key-capturer/key-capturer.js +22 -19
- package/es/components/key-capturer/key-capturer.js.map +1 -1
- package/es/components/keyboard-shortcut/keyboard-shortcut.js +20 -26
- package/es/components/keyboard-shortcut/keyboard-shortcut.js.map +1 -1
- package/es/components/menu/menu.js +112 -142
- package/es/components/menu/menu.js.map +1 -1
- package/es/components/notification/notification.js +32 -32
- package/es/components/notification/notification.js.map +1 -1
- package/es/components/popover/popover.js +85 -91
- package/es/components/popover/popover.js.map +1 -1
- package/es/components/popover/positioning-utils.js +49 -65
- package/es/components/popover/positioning-utils.js.map +1 -1
- package/es/components/progress-bar/progress-bar.js +8 -8
- package/es/components/progress-bar/progress-bar.js.map +1 -1
- package/es/components/select/select.js +20 -25
- package/es/components/select/select.js.map +1 -1
- package/es/components/time/time-utils.js +30 -47
- package/es/components/time/time-utils.js.map +1 -1
- package/es/components/time/time.js +43 -56
- package/es/components/time/time.js.map +1 -1
- package/es/components/tooltip/tooltip.js +40 -46
- package/es/components/tooltip/tooltip.js.map +1 -1
- package/es/hooks/use-previous/use-previous.js +2 -2
- package/es/hooks/use-previous/use-previous.js.map +1 -1
- package/es/new-components/alert/alert.js +7 -6
- package/es/new-components/alert/alert.js.map +1 -1
- package/es/new-components/avatar/avatar.js +19 -18
- package/es/new-components/avatar/avatar.js.map +1 -1
- package/es/new-components/avatar/utils.js +12 -9
- package/es/new-components/avatar/utils.js.map +1 -1
- package/es/new-components/base-button/base-button.js +25 -29
- package/es/new-components/base-button/base-button.js.map +1 -1
- package/es/new-components/base-field/base-field.js +20 -18
- package/es/new-components/base-field/base-field.js.map +1 -1
- package/es/new-components/box/box.js +51 -52
- package/es/new-components/box/box.js.map +1 -1
- package/es/new-components/button/button.js +13 -15
- package/es/new-components/button/button.js.map +1 -1
- package/es/new-components/button-link/button-link.js +13 -15
- package/es/new-components/button-link/button-link.js.map +1 -1
- package/es/new-components/checkbox-field/checkbox-field.js +25 -33
- package/es/new-components/checkbox-field/checkbox-field.js.map +1 -1
- package/es/new-components/checkbox-field/checkbox-icon.js +21 -19
- package/es/new-components/checkbox-field/checkbox-icon.js.map +1 -1
- package/es/new-components/columns/columns.js +24 -27
- package/es/new-components/columns/columns.js.map +1 -1
- package/es/new-components/common-helpers.js +3 -3
- package/es/new-components/common-helpers.js.map +1 -1
- package/es/new-components/divider/divider.js +7 -6
- package/es/new-components/divider/divider.js.map +1 -1
- package/es/new-components/heading/heading.js +17 -17
- package/es/new-components/heading/heading.js.map +1 -1
- package/es/new-components/hidden/hidden.js +14 -13
- package/es/new-components/hidden/hidden.js.map +1 -1
- package/es/new-components/hidden-visually/hidden-visually.js +3 -2
- package/es/new-components/hidden-visually/hidden-visually.js.map +1 -1
- package/es/new-components/icons/alert-icon.js +13 -11
- package/es/new-components/icons/alert-icon.js.map +1 -1
- package/es/new-components/icons/close-icon.js +2 -1
- package/es/new-components/icons/close-icon.js.map +1 -1
- package/es/new-components/icons/password-hidden-icon.js +2 -1
- package/es/new-components/icons/password-hidden-icon.js.map +1 -1
- package/es/new-components/icons/password-visible-icon.js +2 -1
- package/es/new-components/icons/password-visible-icon.js.map +1 -1
- package/es/new-components/inline/inline.js +15 -19
- package/es/new-components/inline/inline.js.map +1 -1
- package/es/new-components/loading/loading.js +12 -10
- package/es/new-components/loading/loading.js.map +1 -1
- package/es/new-components/modal/modal.js +60 -64
- package/es/new-components/modal/modal.js.map +1 -1
- package/es/new-components/notice/notice.js +5 -4
- package/es/new-components/notice/notice.js.map +1 -1
- package/es/new-components/password-field/password-field.js +40 -46
- package/es/new-components/password-field/password-field.js.map +1 -1
- package/es/new-components/responsive-props.js +5 -5
- package/es/new-components/responsive-props.js.map +1 -1
- package/es/new-components/select-field/select-field.js +23 -23
- package/es/new-components/select-field/select-field.js.map +1 -1
- package/es/new-components/spinner/spinner.js +3 -3
- package/es/new-components/spinner/spinner.js.map +1 -1
- package/es/new-components/stack/stack.js +18 -22
- package/es/new-components/stack/stack.js.map +1 -1
- package/es/new-components/switch-field/switch-field.js +31 -41
- package/es/new-components/switch-field/switch-field.js.map +1 -1
- package/es/new-components/tabs/tabs.js +92 -78
- package/es/new-components/tabs/tabs.js.map +1 -1
- package/es/new-components/tabs/tabs.module.css.js +1 -1
- package/es/new-components/text/text.js +16 -17
- package/es/new-components/text/text.js.map +1 -1
- package/es/new-components/text/text.module.css.js +1 -1
- package/es/new-components/text-area/text-area.js +14 -14
- package/es/new-components/text-area/text-area.js.map +1 -1
- package/es/new-components/text-field/text-field.js +21 -22
- package/es/new-components/text-field/text-field.js.map +1 -1
- package/es/new-components/text-link/text-link.js +10 -10
- package/es/new-components/text-link/text-link.js.map +1 -1
- package/es/new-components/text-link/text-link.module.css.js +1 -1
- package/es/utils/polymorphism.js.map +1 -1
- package/lib/_virtual/_rollupPluginBabelHelpers.js +1 -1
- package/lib/components/checkbox/checkbox.js +1 -1
- package/lib/components/checkbox/checkbox.js.map +1 -1
- package/lib/components/color-picker/color-picker.js +1 -1
- package/lib/components/color-picker/color-picker.js.map +1 -1
- package/lib/components/deprecated-button/deprecated-button.d.ts +3 -3
- package/lib/components/deprecated-button/deprecated-button.js +1 -1
- package/lib/components/deprecated-button/deprecated-button.js.map +1 -1
- package/lib/components/deprecated-loading/deprecated-loading.js +1 -1
- package/lib/components/deprecated-loading/deprecated-loading.js.map +1 -1
- package/lib/components/deprecated-modal/deprecated-modal.d.ts +2 -2
- package/lib/components/deprecated-modal/deprecated-modal.js +1 -1
- package/lib/components/deprecated-modal/deprecated-modal.js.map +1 -1
- package/lib/components/deprecated-modal/index.js.map +1 -1
- package/lib/components/dropdown/dropdown.d.ts +5 -2
- package/lib/components/dropdown/dropdown.js +1 -1
- package/lib/components/dropdown/dropdown.js.map +1 -1
- package/lib/components/icons/CloseIcon.svg.js +1 -1
- package/lib/components/icons/CloseIcon.svg.js.map +1 -1
- package/lib/components/input/input.js +1 -1
- package/lib/components/input/input.js.map +1 -1
- package/lib/components/key-capturer/key-capturer.d.ts +1 -1
- package/lib/components/key-capturer/key-capturer.js +1 -1
- package/lib/components/key-capturer/key-capturer.js.map +1 -1
- package/lib/components/keyboard-shortcut/keyboard-shortcut.js +1 -1
- package/lib/components/keyboard-shortcut/keyboard-shortcut.js.map +1 -1
- package/lib/components/menu/menu.d.ts +7 -7
- package/lib/components/menu/menu.js +1 -1
- package/lib/components/menu/menu.js.map +1 -1
- package/lib/components/notification/notification.js +1 -1
- package/lib/components/notification/notification.js.map +1 -1
- package/lib/components/popover/popover.d.ts +1 -1
- package/lib/components/popover/popover.js +1 -1
- package/lib/components/popover/popover.js.map +1 -1
- package/lib/components/popover/positioning-utils.js +1 -1
- package/lib/components/popover/positioning-utils.js.map +1 -1
- package/lib/components/progress-bar/progress-bar.js +1 -1
- package/lib/components/progress-bar/progress-bar.js.map +1 -1
- package/lib/components/select/select.js +1 -1
- package/lib/components/select/select.js.map +1 -1
- package/lib/components/time/time-utils.js +1 -1
- package/lib/components/time/time-utils.js.map +1 -1
- package/lib/components/time/time.js +1 -1
- package/lib/components/time/time.js.map +1 -1
- package/lib/components/tooltip/index.d.ts +1 -2
- package/lib/components/tooltip/tooltip.d.ts +3 -3
- package/lib/components/tooltip/tooltip.js +1 -1
- package/lib/components/tooltip/tooltip.js.map +1 -1
- package/lib/hooks/use-previous/use-previous.js +1 -1
- package/lib/hooks/use-previous/use-previous.js.map +1 -1
- package/lib/index.d.ts +2 -1
- package/lib/new-components/alert/alert.d.ts +1 -1
- package/lib/new-components/alert/alert.js +1 -1
- package/lib/new-components/alert/alert.js.map +1 -1
- package/lib/new-components/avatar/avatar.js +1 -1
- package/lib/new-components/avatar/avatar.js.map +1 -1
- package/lib/new-components/avatar/utils.d.ts +1 -1
- package/lib/new-components/avatar/utils.js +1 -1
- package/lib/new-components/avatar/utils.js.map +1 -1
- package/lib/new-components/base-button/base-button.js +1 -1
- package/lib/new-components/base-button/base-button.js.map +1 -1
- package/lib/new-components/base-field/base-field.d.ts +1 -1
- package/lib/new-components/base-field/base-field.js +1 -1
- package/lib/new-components/base-field/base-field.js.map +1 -1
- package/lib/new-components/box/box.js +1 -1
- package/lib/new-components/box/box.js.map +1 -1
- package/lib/new-components/button/button.d.ts +1 -58
- package/lib/new-components/button/button.js +1 -1
- package/lib/new-components/button/button.js.map +1 -1
- package/lib/new-components/button-link/button-link.js +1 -1
- package/lib/new-components/button-link/button-link.js.map +1 -1
- package/lib/new-components/checkbox-field/checkbox-field.d.ts +1 -1
- package/lib/new-components/checkbox-field/checkbox-field.js +1 -1
- package/lib/new-components/checkbox-field/checkbox-field.js.map +1 -1
- package/lib/new-components/checkbox-field/checkbox-icon.js +1 -1
- package/lib/new-components/checkbox-field/checkbox-icon.js.map +1 -1
- package/lib/new-components/columns/columns.js +1 -1
- package/lib/new-components/columns/columns.js.map +1 -1
- package/lib/new-components/common-helpers.js +1 -1
- package/lib/new-components/common-helpers.js.map +1 -1
- package/lib/new-components/common-types.d.ts +2 -2
- package/lib/new-components/divider/divider.js +1 -1
- package/lib/new-components/divider/divider.js.map +1 -1
- package/lib/new-components/heading/heading.d.ts +2 -2
- package/lib/new-components/heading/heading.js +1 -1
- package/lib/new-components/heading/heading.js.map +1 -1
- package/lib/new-components/hidden/hidden.js +1 -1
- package/lib/new-components/hidden/hidden.js.map +1 -1
- package/lib/new-components/hidden-visually/hidden-visually.js +1 -1
- package/lib/new-components/hidden-visually/hidden-visually.js.map +1 -1
- package/lib/new-components/icons/alert-icon.d.ts +1 -1
- package/lib/new-components/icons/alert-icon.js +1 -1
- package/lib/new-components/icons/alert-icon.js.map +1 -1
- package/lib/new-components/icons/close-icon.js +1 -1
- package/lib/new-components/icons/close-icon.js.map +1 -1
- package/lib/new-components/icons/password-hidden-icon.js +1 -1
- package/lib/new-components/icons/password-hidden-icon.js.map +1 -1
- package/lib/new-components/icons/password-visible-icon.js +1 -1
- package/lib/new-components/icons/password-visible-icon.js.map +1 -1
- package/lib/new-components/inline/inline.js +1 -1
- package/lib/new-components/inline/inline.js.map +1 -1
- package/lib/new-components/loading/loading.d.ts +1 -1
- package/lib/new-components/loading/loading.js +1 -1
- package/lib/new-components/loading/loading.js.map +1 -1
- package/lib/new-components/modal/modal.js +1 -1
- package/lib/new-components/modal/modal.js.map +1 -1
- package/lib/new-components/notice/notice.d.ts +1 -1
- package/lib/new-components/notice/notice.js +1 -1
- package/lib/new-components/notice/notice.js.map +1 -1
- package/lib/new-components/password-field/password-field.d.ts +1 -1
- package/lib/new-components/password-field/password-field.js +1 -1
- package/lib/new-components/password-field/password-field.js.map +1 -1
- package/lib/new-components/responsive-props.d.ts +1 -1
- package/lib/new-components/responsive-props.js +1 -1
- package/lib/new-components/responsive-props.js.map +1 -1
- package/lib/new-components/select-field/select-field.d.ts +1 -1
- package/lib/new-components/select-field/select-field.js +1 -1
- package/lib/new-components/select-field/select-field.js.map +1 -1
- package/lib/new-components/spinner/spinner.js +1 -1
- package/lib/new-components/spinner/spinner.js.map +1 -1
- package/lib/new-components/stack/stack.js +1 -1
- package/lib/new-components/stack/stack.js.map +1 -1
- package/lib/new-components/switch-field/switch-field.d.ts +1 -1
- package/lib/new-components/switch-field/switch-field.js +1 -1
- package/lib/new-components/switch-field/switch-field.js.map +1 -1
- package/lib/new-components/tabs/tabs.d.ts +13 -3
- package/lib/new-components/tabs/tabs.js +1 -1
- package/lib/new-components/tabs/tabs.js.map +1 -1
- package/lib/new-components/tabs/tabs.module.css.js +1 -1
- package/lib/new-components/test-helpers.d.ts +4 -3
- package/lib/new-components/text/text.js +1 -1
- package/lib/new-components/text/text.js.map +1 -1
- package/lib/new-components/text/text.module.css.js +1 -1
- package/lib/new-components/text-area/text-area.js +1 -1
- package/lib/new-components/text-area/text-area.js.map +1 -1
- package/lib/new-components/text-field/text-field.d.ts +1 -1
- package/lib/new-components/text-field/text-field.js +1 -1
- package/lib/new-components/text-field/text-field.js.map +1 -1
- package/lib/new-components/text-link/text-link.js +1 -1
- package/lib/new-components/text-link/text-link.js.map +1 -1
- package/lib/new-components/text-link/text-link.module.css.js +1 -1
- package/lib/utils/polymorphism.js.map +1 -1
- package/package.json +45 -38
- package/styles/base-field.css +1 -1
- package/styles/checkbox-field.css +1 -1
- package/styles/menu.css +1 -1
- package/styles/password-field.css +1 -1
- package/styles/reactist.css +5 -5
- package/styles/select-field.css +1 -1
- package/styles/switch-field.css +1 -1
- package/styles/tabs.css +1 -1
- package/styles/tabs.module.css.css +1 -1
- package/styles/text-area.css +1 -1
- package/styles/text-field.css +1 -1
- package/styles/text-link.css +1 -1
- package/styles/text-link.module.css.css +1 -1
- package/styles/text.css +1 -1
- package/styles/text.module.css.css +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"key-capturer.js","sources":["../../../src/components/key-capturer/key-capturer.tsx"],"sourcesContent":["import React, { useRef } from 'react'\n\ntype Key = 'ArrowUp' | 'ArrowRight' | 'ArrowDown' | 'ArrowLeft' | 'Enter' | 'Backspace' | 'Escape'\n\nconst SUPPORTED_KEYS: Record<string, Key> = {\n ARROW_UP: 'ArrowUp',\n ARROW_RIGHT: 'ArrowRight',\n ARROW_DOWN: 'ArrowDown',\n ARROW_LEFT: 'ArrowLeft',\n ENTER: 'Enter',\n BACKSPACE: 'Backspace',\n ESCAPE: 'Escape',\n}\n\nconst KeyCapturerResolver = {\n resolveByKey(eventKey: string): Key | null {\n switch (eventKey) {\n case 'Left': // IE specific\n case 'ArrowLeft': {\n return 'ArrowLeft'\n }\n case 'Up': // IE specific\n case 'ArrowUp': {\n return 'ArrowUp'\n }\n case 'Right': // IE specific\n case 'ArrowRight': {\n return 'ArrowRight'\n }\n case 'Down': // IE specific\n case 'ArrowDown': {\n return 'ArrowDown'\n }\n case 'Enter': {\n return 'Enter'\n }\n case 'Backspace': {\n return 'Backspace'\n }\n case 'Esc': // IE specific\n case 'Escape': {\n return 'Escape'\n }\n default: {\n return null\n }\n }\n },\n\n resolveByKeyCode(keyCode: number): Key | null {\n switch (keyCode) {\n case 37: {\n return 'ArrowLeft'\n }\n case 38: {\n return 'ArrowUp'\n }\n case 39: {\n return 'ArrowRight'\n }\n case 40: {\n return 'ArrowDown'\n }\n case 13: {\n return 'Enter'\n }\n case 8: {\n return 'Backspace'\n }\n case 27: {\n return 'Escape'\n }\n default: {\n return null\n }\n }\n },\n}\n\ntype EventHandler = (event: React.SyntheticEvent) => void\n\ntype EventHandlerProps = {\n onArrowUp?: EventHandler\n onArrowDown?: EventHandler\n onArrowLeft?: EventHandler\n onArrowRight?: EventHandler\n onEnter?: EventHandler\n onBackspace?: EventHandler\n onEscape?: EventHandler\n}\n\ntype PropagateProps = {\n propagateArrowUp?: boolean\n propagateArrowDown?: boolean\n propagateArrowLeft?: boolean\n propagateArrowRight?: boolean\n propagateEnter?: boolean\n propagateBackspace?: boolean\n propagateEscape?: boolean\n}\n\nconst keyEventHandlerMapping: Record<Key, keyof EventHandlerProps> = {\n ArrowUp: 'onArrowUp',\n ArrowDown: 'onArrowDown',\n ArrowLeft: 'onArrowLeft',\n ArrowRight: 'onArrowRight',\n Enter: 'onEnter',\n Backspace: 'onBackspace',\n Escape: 'onEscape',\n}\n\nconst keyPropagatePropMapping: Record<Key, keyof PropagateProps> = {\n ArrowUp: 'propagateArrowUp',\n ArrowDown: 'propagateArrowDown',\n ArrowLeft: 'propagateArrowLeft',\n ArrowRight: 'propagateArrowRight',\n Enter: 'propagateEnter',\n Backspace: 'propagateBackspace',\n Escape: 'propagateEscape',\n}\n\ntype KeyCapturerProps = EventHandlerProps &\n PropagateProps & {\n eventName?: 'onKeyDown' | 'onKeyDownCapture' | 'onKeyUp' | 'onKeyUpCapture'\n children: React.ReactElement<unknown>\n }\n\n/**\n * Use this component to wrap anything you want to handle key events for (e.g. an input).\n * You can specify the `eventName` to capture (defaults to `onKeyDown`).\n * Check the SUPPORTED_KEYS map to see which keys are supported and supply the respective\n * `on${Key}` prop (i.e. `onEnter` or `onArrowDown`).\n * If you want the default behaviour to be preserved (i.e. only want to hook into the event\n * instead of replacing it) set the `propagate${Key}` prop (e.g. propagateBackspace).\n */\nfunction KeyCapturer(props: KeyCapturerProps) {\n const { children, eventName = 'onKeyDown' } = props\n const composingRef = useRef(false)\n const composingEventHandlers = props.onEnter\n ? {\n onCompositionStart: () => {\n composingRef.current = true\n },\n onCompositionEnd: () => {\n composingRef.current = false\n },\n }\n : undefined\n\n function handleKeyEvent(event: React.KeyboardEvent<HTMLInputElement>) {\n // https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent/keyCode\n const key =\n event.key !== undefined\n ? KeyCapturerResolver.resolveByKey(event.key)\n : KeyCapturerResolver.resolveByKeyCode(event.keyCode)\n\n if (!key) return\n const propagateEvent = props[keyPropagatePropMapping[key]] || false\n const eventHandler = props[keyEventHandlerMapping[key]]\n\n if (key === 'Enter' && eventHandler) {\n if (\n composingRef.current ||\n // Safari fires the onCompositionEnd event before the keydown event, so we\n // have to rely on the 229 keycode, which is Enter when fired from an IME\n // https://www.w3.org/TR/uievents/#determine-keydown-keyup-keyCode\n (event.keyCode || event.which) === 229\n ) {\n return\n }\n }\n\n if (eventHandler) {\n eventHandler(event)\n if (!propagateEvent) {\n event.preventDefault()\n event.stopPropagation()\n }\n }\n }\n\n return React.cloneElement(children, {\n [eventName]: handleKeyEvent,\n ...composingEventHandlers,\n })\n}\n\nexport { KeyCapturer, KeyCapturerResolver, SUPPORTED_KEYS }\n"],"names":["SUPPORTED_KEYS","ARROW_UP","ARROW_RIGHT","ARROW_DOWN","ARROW_LEFT","ENTER","BACKSPACE","ESCAPE","KeyCapturerResolver","resolveByKey","eventKey","resolveByKeyCode","keyCode","keyEventHandlerMapping","ArrowUp","ArrowDown","ArrowLeft","ArrowRight","Enter","Backspace","Escape","keyPropagatePropMapping","KeyCapturer","props","children","eventName","composingRef","useRef","composingEventHandlers","onEnter","onCompositionStart","current","onCompositionEnd","undefined","handleKeyEvent","event","key","propagateEvent","eventHandler","which","preventDefault","stopPropagation","React","cloneElement"],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"key-capturer.js","sources":["../../../src/components/key-capturer/key-capturer.tsx"],"sourcesContent":["import React, { useRef } from 'react'\n\ntype Key = 'ArrowUp' | 'ArrowRight' | 'ArrowDown' | 'ArrowLeft' | 'Enter' | 'Backspace' | 'Escape'\n\nconst SUPPORTED_KEYS: Record<string, Key> = {\n ARROW_UP: 'ArrowUp',\n ARROW_RIGHT: 'ArrowRight',\n ARROW_DOWN: 'ArrowDown',\n ARROW_LEFT: 'ArrowLeft',\n ENTER: 'Enter',\n BACKSPACE: 'Backspace',\n ESCAPE: 'Escape',\n}\n\nconst KeyCapturerResolver = {\n resolveByKey(eventKey: string): Key | null {\n switch (eventKey) {\n case 'Left': // IE specific\n case 'ArrowLeft': {\n return 'ArrowLeft'\n }\n case 'Up': // IE specific\n case 'ArrowUp': {\n return 'ArrowUp'\n }\n case 'Right': // IE specific\n case 'ArrowRight': {\n return 'ArrowRight'\n }\n case 'Down': // IE specific\n case 'ArrowDown': {\n return 'ArrowDown'\n }\n case 'Enter': {\n return 'Enter'\n }\n case 'Backspace': {\n return 'Backspace'\n }\n case 'Esc': // IE specific\n case 'Escape': {\n return 'Escape'\n }\n default: {\n return null\n }\n }\n },\n\n resolveByKeyCode(keyCode: number): Key | null {\n switch (keyCode) {\n case 37: {\n return 'ArrowLeft'\n }\n case 38: {\n return 'ArrowUp'\n }\n case 39: {\n return 'ArrowRight'\n }\n case 40: {\n return 'ArrowDown'\n }\n case 13: {\n return 'Enter'\n }\n case 8: {\n return 'Backspace'\n }\n case 27: {\n return 'Escape'\n }\n default: {\n return null\n }\n }\n },\n}\n\ntype EventHandler = (event: React.SyntheticEvent) => void\n\ntype EventHandlerProps = {\n onArrowUp?: EventHandler\n onArrowDown?: EventHandler\n onArrowLeft?: EventHandler\n onArrowRight?: EventHandler\n onEnter?: EventHandler\n onBackspace?: EventHandler\n onEscape?: EventHandler\n}\n\ntype PropagateProps = {\n propagateArrowUp?: boolean\n propagateArrowDown?: boolean\n propagateArrowLeft?: boolean\n propagateArrowRight?: boolean\n propagateEnter?: boolean\n propagateBackspace?: boolean\n propagateEscape?: boolean\n}\n\nconst keyEventHandlerMapping: Record<Key, keyof EventHandlerProps> = {\n ArrowUp: 'onArrowUp',\n ArrowDown: 'onArrowDown',\n ArrowLeft: 'onArrowLeft',\n ArrowRight: 'onArrowRight',\n Enter: 'onEnter',\n Backspace: 'onBackspace',\n Escape: 'onEscape',\n}\n\nconst keyPropagatePropMapping: Record<Key, keyof PropagateProps> = {\n ArrowUp: 'propagateArrowUp',\n ArrowDown: 'propagateArrowDown',\n ArrowLeft: 'propagateArrowLeft',\n ArrowRight: 'propagateArrowRight',\n Enter: 'propagateEnter',\n Backspace: 'propagateBackspace',\n Escape: 'propagateEscape',\n}\n\ntype KeyCapturerProps = EventHandlerProps &\n PropagateProps & {\n eventName?: 'onKeyDown' | 'onKeyDownCapture' | 'onKeyUp' | 'onKeyUpCapture'\n children: React.ReactElement<unknown>\n }\n\n/**\n * Use this component to wrap anything you want to handle key events for (e.g. an input).\n * You can specify the `eventName` to capture (defaults to `onKeyDown`).\n * Check the SUPPORTED_KEYS map to see which keys are supported and supply the respective\n * `on${Key}` prop (i.e. `onEnter` or `onArrowDown`).\n * If you want the default behaviour to be preserved (i.e. only want to hook into the event\n * instead of replacing it) set the `propagate${Key}` prop (e.g. propagateBackspace).\n */\nfunction KeyCapturer(props: KeyCapturerProps) {\n const { children, eventName = 'onKeyDown' } = props\n const composingRef = useRef(false)\n const composingEventHandlers = props.onEnter\n ? {\n onCompositionStart: () => {\n composingRef.current = true\n },\n onCompositionEnd: () => {\n composingRef.current = false\n },\n }\n : undefined\n\n function handleKeyEvent(event: React.KeyboardEvent<HTMLInputElement>) {\n // https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent/keyCode\n const key =\n event.key !== undefined\n ? KeyCapturerResolver.resolveByKey(event.key)\n : KeyCapturerResolver.resolveByKeyCode(event.keyCode)\n\n if (!key) return\n const propagateEvent = props[keyPropagatePropMapping[key]] || false\n const eventHandler = props[keyEventHandlerMapping[key]]\n\n if (key === 'Enter' && eventHandler) {\n if (\n composingRef.current ||\n // Safari fires the onCompositionEnd event before the keydown event, so we\n // have to rely on the 229 keycode, which is Enter when fired from an IME\n // https://www.w3.org/TR/uievents/#determine-keydown-keyup-keyCode\n (event.keyCode || event.which) === 229\n ) {\n return\n }\n }\n\n if (eventHandler) {\n eventHandler(event)\n if (!propagateEvent) {\n event.preventDefault()\n event.stopPropagation()\n }\n }\n }\n\n return React.cloneElement(children, {\n [eventName]: handleKeyEvent,\n ...composingEventHandlers,\n })\n}\n\nexport { KeyCapturer, KeyCapturerResolver, SUPPORTED_KEYS }\n"],"names":["SUPPORTED_KEYS","ARROW_UP","ARROW_RIGHT","ARROW_DOWN","ARROW_LEFT","ENTER","BACKSPACE","ESCAPE","KeyCapturerResolver","resolveByKey","eventKey","resolveByKeyCode","keyCode","keyEventHandlerMapping","ArrowUp","ArrowDown","ArrowLeft","ArrowRight","Enter","Backspace","Escape","keyPropagatePropMapping","KeyCapturer","props","children","eventName","composingRef","useRef","composingEventHandlers","onEnter","onCompositionStart","current","onCompositionEnd","undefined","handleKeyEvent","event","key","propagateEvent","eventHandler","which","preventDefault","stopPropagation","React","cloneElement"],"mappings":";;;MAIMA,cAAc,GAAwB;EACxCC,QAAQ,EAAE,SAD8B;EAExCC,WAAW,EAAE,YAF2B;EAGxCC,UAAU,EAAE,WAH4B;EAIxCC,UAAU,EAAE,WAJ4B;EAKxCC,KAAK,EAAE,OALiC;EAMxCC,SAAS,EAAE,WAN6B;EAOxCC,MAAM,EAAE;AAPgC;MAUtCC,mBAAmB,GAAG;EACxBC,YAAY,CAACC,QAAD;IACR,QAAQA,QAAR;MACI,KAAK,MAAL,CADJ;;MAEI,KAAK,WAAL;QAAkB;UACd,OAAO,WAAP;;;MAEJ,KAAK,IAAL,CALJ;;MAMI,KAAK,SAAL;QAAgB;UACZ,OAAO,SAAP;;;MAEJ,KAAK,OAAL,CATJ;;MAUI,KAAK,YAAL;QAAmB;UACf,OAAO,YAAP;;;MAEJ,KAAK,MAAL,CAbJ;;MAcI,KAAK,WAAL;QAAkB;UACd,OAAO,WAAP;;;MAEJ,KAAK,OAAL;QAAc;UACV,OAAO,OAAP;;;MAEJ,KAAK,WAAL;QAAkB;UACd,OAAO,WAAP;;;MAEJ,KAAK,KAAL,CAvBJ;;MAwBI,KAAK,QAAL;QAAe;UACX,OAAO,QAAP;;;MAEJ;QAAS;UACL,OAAO,IAAP;;;GA9BY;;EAmCxBC,gBAAgB,CAACC,OAAD;IACZ,QAAQA,OAAR;MACI,KAAK,EAAL;QAAS;UACL,OAAO,WAAP;;;MAEJ,K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ACC,YAApB,CAAiC0B,KAAK,CAACC,GAAvC,CADN,GAEM5B,mBAAmB,CAACG,gBAApB,CAAqCwB,KAAK,CAACvB,OAA3C,CAHV;IAKA,IAAI,CAACwB,GAAL,EAAU;IACV,MAAMC,cAAc,GAAGd,KAAK,CAACF,uBAAuB,CAACe,GAAD,CAAxB,CAAL,IAAuC,KAA9D;IACA,MAAME,YAAY,GAAGf,KAAK,CAACV,sBAAsB,CAACuB,GAAD,CAAvB,CAA1B;;IAEA,IAAIA,GAAG,KAAK,OAAR,IAAmBE,YAAvB,EAAqC;MACjC,IACIZ,YAAY,CAACK,OAAb;;;MAIA,CAACI,KAAK,CAACvB,OAAN,IAAiBuB,KAAK,CAACI,KAAxB,MAAmC,GALvC,EAME;QACE;;;;IAIR,IAAID,YAAJ,EAAkB;MACdA,YAAY,CAACH,KAAD,CAAZ;;MACA,IAAI,CAACE,cAAL,EAAqB;QACjBF,KAAK,CAACK,cAAN;QACAL,KAAK,CAACM,eAAN;;;;;EAKZ,oBAAOC,cAAK,CAACC,YAAN,CAAmBnB,QAAnB;IACH,CAACC,SAAD,GAAaS;KACVN,sBAFA,EAAP;AAIH;;;;"}
|
|
@@ -1,16 +1,14 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { objectWithoutProperties as _objectWithoutProperties, objectSpread2 as _objectSpread2 } from '../../_virtual/_rollupPluginBabelHelpers.js';
|
|
2
2
|
import { createElement, Fragment } from 'react';
|
|
3
3
|
import classNames from 'classnames';
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
const _excluded = ["children", "className", "translateKey", "isMac"];
|
|
6
6
|
// Support for setting up how to translate modifiers globally.
|
|
7
7
|
//
|
|
8
8
|
|
|
9
|
-
|
|
10
|
-
return key;
|
|
11
|
-
};
|
|
9
|
+
let globalTranslateKey = key => key;
|
|
12
10
|
|
|
13
|
-
KeyboardShortcut.setTranslateKey =
|
|
11
|
+
KeyboardShortcut.setTranslateKey = tr => {
|
|
14
12
|
globalTranslateKey = tr;
|
|
15
13
|
};
|
|
16
14
|
|
|
@@ -54,9 +52,9 @@ function isSpecialKey(str) {
|
|
|
54
52
|
}
|
|
55
53
|
|
|
56
54
|
function parseKeys(shortcut, isMac, translateKey) {
|
|
57
|
-
|
|
55
|
+
const t = isMac ? translateKeyMac : translateKey;
|
|
58
56
|
|
|
59
|
-
|
|
57
|
+
const _hasModifiers = hasModifiers(shortcut);
|
|
60
58
|
|
|
61
59
|
function mapIndividualKey(str) {
|
|
62
60
|
if (isSpecialKey(str)) {
|
|
@@ -80,28 +78,24 @@ function parseKeys(shortcut, isMac, translateKey) {
|
|
|
80
78
|
function KeyboardShortcut(_ref) {
|
|
81
79
|
var _navigator$platform$t, _navigator$platform;
|
|
82
80
|
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
props =
|
|
81
|
+
let {
|
|
82
|
+
children,
|
|
83
|
+
className,
|
|
84
|
+
translateKey = globalTranslateKey,
|
|
85
|
+
isMac = (_navigator$platform$t = (_navigator$platform = navigator.platform) == null ? void 0 : _navigator$platform.toUpperCase().includes('MAC')) != null ? _navigator$platform$t : false
|
|
86
|
+
} = _ref,
|
|
87
|
+
props = _objectWithoutProperties(_ref, _excluded);
|
|
90
88
|
|
|
91
|
-
|
|
92
|
-
return /*#__PURE__*/createElement("span",
|
|
89
|
+
const shortcuts = typeof children === 'string' ? [children] : children;
|
|
90
|
+
return /*#__PURE__*/createElement("span", _objectSpread2({
|
|
93
91
|
className: classNames('reactist_keyboard_shortcut', className, {
|
|
94
92
|
'reactist_keyboard_shortcut--macos': isMac
|
|
95
93
|
})
|
|
96
|
-
}, props), shortcuts.map(
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
key: j
|
|
102
|
-
}, key);
|
|
103
|
-
})));
|
|
104
|
-
}));
|
|
94
|
+
}, props), shortcuts.map((shortcut, i) => /*#__PURE__*/createElement(Fragment, {
|
|
95
|
+
key: i
|
|
96
|
+
}, i === 0 ? null : ', ', /*#__PURE__*/createElement("kbd", null, parseKeys(shortcut, isMac, translateKey).map((key, j) => /*#__PURE__*/createElement("kbd", {
|
|
97
|
+
key: j
|
|
98
|
+
}, key))))));
|
|
105
99
|
}
|
|
106
100
|
|
|
107
101
|
export { KeyboardShortcut };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"keyboard-shortcut.js","sources":["../../../src/components/keyboard-shortcut/keyboard-shortcut.tsx"],"sourcesContent":["import * as React from 'react'\nimport classNames from 'classnames'\n\n//\n// Support for setting up how to translate modifiers globally.\n//\n\nlet globalTranslateKey = (key: string) => key\n\ntype TranslateKey = typeof globalTranslateKey\n\nKeyboardShortcut.setTranslateKey = (tr: TranslateKey) => {\n globalTranslateKey = tr\n}\n\nfunction translateKeyMac(key: string) {\n switch (key.toLowerCase()) {\n case 'cmd':\n case 'mod':\n return '⌘'\n case 'control':\n case 'ctrl':\n return '⌃'\n case 'alt':\n return '⌥'\n case 'shift':\n return '⇧'\n case 'space':\n return '␣'\n default:\n return key\n }\n}\n\n//\n// Some helpers\n//\n\nfunction capitalize(str: string) {\n return str.charAt(0).toUpperCase() + str.slice(1).toLowerCase()\n}\n\nfunction hasModifiers(str: string) {\n return /\\b(mod|cmd|ctrl|control|alt|shift)\\b/i.test(str)\n}\n\nfunction isSpecialKey(str: string) {\n return /^(mod|cmd|ctrl|control|alt|shift|space|super)$/i.test(str)\n}\n\nfunction parseKeys(shortcut: string, isMac: boolean, translateKey: TranslateKey) {\n const t = isMac ? translateKeyMac : translateKey\n const _hasModifiers = hasModifiers(shortcut)\n\n function mapIndividualKey(str: string) {\n if (isSpecialKey(str)) {\n return capitalize(t(str))\n }\n if (_hasModifiers && str.length === 1) {\n return str.toUpperCase()\n }\n return str\n }\n\n if (!isMac) {\n shortcut = shortcut.replace(/\\b(mod|cmd)\\b/i, 'ctrl')\n }\n\n return shortcut.split(/\\s*\\+\\s*/).map(mapIndividualKey)\n}\n\n//\n// The KeyboardShortcut component\n//\n\ntype NativeSpanProps = React.DetailedHTMLProps<\n React.HTMLAttributes<HTMLSpanElement>,\n HTMLSpanElement\n>\n\ntype Props = Omit<NativeSpanProps, 'children'> & {\n /**\n * The shortcut to be represented as markup. It supports an intuitive syntax where you can\n * combine modifiers (cmd, ctrl, shift, alt) with single keys all concatenated with plus signs.\n * You can also pass various shortcuts as an array, which will be depicted separated by commas.\n */\n children: string | string[]\n /**\n * A function that allows you to change how some key names are represented. This may be useful,\n * for instance, to translate modifier names that are expressed differently in other languages\n * (e.g. `Ctrl` is named `Strg` in German).\n *\n * It defaults to a global version that leaves the key as is. You can pass your version as a\n * prop, or you can also set your own version of this global default one, so you don't need to\n * pass your own on each invocation of this component.\n *\n * ```js\n * import { KeyboardShortcut } from '@doist/reactist'\n * KeyboardShortcut.setTranslateKey = key => { ... }\n * ```\n *\n * Note: When the component detects the macOS operating system it bypasses key translation for\n * most modifiers and uses macOS-specific symbols. See the `isMac` prop for details.\n */\n translateKey?: TranslateKey\n /**\n * This prop is not meant to be passed. The component will automatically initialize it to `true`\n * if it detects that the current browser / operating system is on macOS, in which case modifier\n * keys are represented using macOS' notation (e.g. ⌘ ⌃ ⌥ ⇧).\n *\n * Though it is discouraged, if you don't want this special treatment in macOS, you can pass\n * `isMac={false}` in all invocations of this component.\n */\n isMac?: boolean\n}\n\nfunction KeyboardShortcut({\n children,\n className,\n translateKey = globalTranslateKey,\n isMac = navigator.platform?.toUpperCase().includes('MAC') ?? false,\n ...props\n}: Props) {\n const shortcuts = typeof children === 'string' ? [children] : children\n return (\n <span\n className={classNames('reactist_keyboard_shortcut', className, {\n 'reactist_keyboard_shortcut--macos': isMac,\n })}\n {...props}\n >\n {shortcuts.map((shortcut, i) => (\n <React.Fragment key={i}>\n {i === 0 ? null : ', '}\n <kbd>\n {parseKeys(shortcut, isMac, translateKey).map((key, j) => (\n <kbd key={j}>{key}</kbd>\n ))}\n </kbd>\n </React.Fragment>\n ))}\n </span>\n )\n}\n\nexport { KeyboardShortcut }\n"],"names":["globalTranslateKey","key","KeyboardShortcut","setTranslateKey","tr","translateKeyMac","toLowerCase","capitalize","str","charAt","toUpperCase","slice","hasModifiers","test","isSpecialKey","parseKeys","shortcut","isMac","translateKey","t","_hasModifiers","mapIndividualKey","length","replace","split","map","children","className","navigator","platform","includes","props","shortcuts","React","classNames","i","j"],"mappings":";;;;;AAIA;AACA;;AAEA,IAAIA,kBAAkB,
|
|
1
|
+
{"version":3,"file":"keyboard-shortcut.js","sources":["../../../src/components/keyboard-shortcut/keyboard-shortcut.tsx"],"sourcesContent":["import * as React from 'react'\nimport classNames from 'classnames'\n\n//\n// Support for setting up how to translate modifiers globally.\n//\n\nlet globalTranslateKey = (key: string) => key\n\ntype TranslateKey = typeof globalTranslateKey\n\nKeyboardShortcut.setTranslateKey = (tr: TranslateKey) => {\n globalTranslateKey = tr\n}\n\nfunction translateKeyMac(key: string) {\n switch (key.toLowerCase()) {\n case 'cmd':\n case 'mod':\n return '⌘'\n case 'control':\n case 'ctrl':\n return '⌃'\n case 'alt':\n return '⌥'\n case 'shift':\n return '⇧'\n case 'space':\n return '␣'\n default:\n return key\n }\n}\n\n//\n// Some helpers\n//\n\nfunction capitalize(str: string) {\n return str.charAt(0).toUpperCase() + str.slice(1).toLowerCase()\n}\n\nfunction hasModifiers(str: string) {\n return /\\b(mod|cmd|ctrl|control|alt|shift)\\b/i.test(str)\n}\n\nfunction isSpecialKey(str: string) {\n return /^(mod|cmd|ctrl|control|alt|shift|space|super)$/i.test(str)\n}\n\nfunction parseKeys(shortcut: string, isMac: boolean, translateKey: TranslateKey) {\n const t = isMac ? translateKeyMac : translateKey\n const _hasModifiers = hasModifiers(shortcut)\n\n function mapIndividualKey(str: string) {\n if (isSpecialKey(str)) {\n return capitalize(t(str))\n }\n if (_hasModifiers && str.length === 1) {\n return str.toUpperCase()\n }\n return str\n }\n\n if (!isMac) {\n shortcut = shortcut.replace(/\\b(mod|cmd)\\b/i, 'ctrl')\n }\n\n return shortcut.split(/\\s*\\+\\s*/).map(mapIndividualKey)\n}\n\n//\n// The KeyboardShortcut component\n//\n\ntype NativeSpanProps = React.DetailedHTMLProps<\n React.HTMLAttributes<HTMLSpanElement>,\n HTMLSpanElement\n>\n\ntype Props = Omit<NativeSpanProps, 'children'> & {\n /**\n * The shortcut to be represented as markup. It supports an intuitive syntax where you can\n * combine modifiers (cmd, ctrl, shift, alt) with single keys all concatenated with plus signs.\n * You can also pass various shortcuts as an array, which will be depicted separated by commas.\n */\n children: string | string[]\n /**\n * A function that allows you to change how some key names are represented. This may be useful,\n * for instance, to translate modifier names that are expressed differently in other languages\n * (e.g. `Ctrl` is named `Strg` in German).\n *\n * It defaults to a global version that leaves the key as is. You can pass your version as a\n * prop, or you can also set your own version of this global default one, so you don't need to\n * pass your own on each invocation of this component.\n *\n * ```js\n * import { KeyboardShortcut } from '@doist/reactist'\n * KeyboardShortcut.setTranslateKey = key => { ... }\n * ```\n *\n * Note: When the component detects the macOS operating system it bypasses key translation for\n * most modifiers and uses macOS-specific symbols. See the `isMac` prop for details.\n */\n translateKey?: TranslateKey\n /**\n * This prop is not meant to be passed. The component will automatically initialize it to `true`\n * if it detects that the current browser / operating system is on macOS, in which case modifier\n * keys are represented using macOS' notation (e.g. ⌘ ⌃ ⌥ ⇧).\n *\n * Though it is discouraged, if you don't want this special treatment in macOS, you can pass\n * `isMac={false}` in all invocations of this component.\n */\n isMac?: boolean\n}\n\nfunction KeyboardShortcut({\n children,\n className,\n translateKey = globalTranslateKey,\n isMac = navigator.platform?.toUpperCase().includes('MAC') ?? false,\n ...props\n}: Props) {\n const shortcuts = typeof children === 'string' ? [children] : children\n return (\n <span\n className={classNames('reactist_keyboard_shortcut', className, {\n 'reactist_keyboard_shortcut--macos': isMac,\n })}\n {...props}\n >\n {shortcuts.map((shortcut, i) => (\n <React.Fragment key={i}>\n {i === 0 ? null : ', '}\n <kbd>\n {parseKeys(shortcut, isMac, translateKey).map((key, j) => (\n <kbd key={j}>{key}</kbd>\n ))}\n </kbd>\n </React.Fragment>\n ))}\n </span>\n )\n}\n\nexport { KeyboardShortcut }\n"],"names":["globalTranslateKey","key","KeyboardShortcut","setTranslateKey","tr","translateKeyMac","toLowerCase","capitalize","str","charAt","toUpperCase","slice","hasModifiers","test","isSpecialKey","parseKeys","shortcut","isMac","translateKey","t","_hasModifiers","mapIndividualKey","length","replace","split","map","children","className","navigator","platform","includes","props","shortcuts","React","classNames","i","j"],"mappings":";;;;;AAIA;AACA;;AAEA,IAAIA,kBAAkB,GAAIC,GAAD,IAAiBA,GAA1C;;AAIAC,gBAAgB,CAACC,eAAjB,GAAoCC,EAAD;EAC/BJ,kBAAkB,GAAGI,EAArB;AACH,CAFD;;AAIA,SAASC,eAAT,CAAyBJ,GAAzB;EACI,QAAQA,GAAG,CAACK,WAAJ,EAAR;IACI,KAAK,KAAL;IACA,KAAK,KAAL;MACI,OAAO,GAAP;;IACJ,KAAK,SAAL;IACA,KAAK,MAAL;MACI,OAAO,GAAP;;IACJ,KAAK,KAAL;MACI,OAAO,GAAP;;IACJ,KAAK,OAAL;MACI,OAAO,GAAP;;IACJ,KAAK,OAAL;MACI,OAAO,GAAP;;IACJ;MACI,OAAOL,GAAP;;AAEX;AAGD;AACA;;;AAEA,SAASM,UAAT,CAAoBC,GAApB;EACI,OAAOA,GAAG,CAACC,MAAJ,CAAW,CAAX,EAAcC,WAAd,KAA8BF,GAAG,CAACG,KAAJ,CAAU,CAAV,EAAaL,WAAb,EAArC;AACH;;AAED,SAASM,YAAT,CAAsBJ,GAAtB;EACI,OAAO,wCAAwCK,IAAxC,CAA6CL,GAA7C,CAAP;AACH;;AAED,SAASM,YAAT,CAAsBN,GAAtB;EACI,OAAO,kDAAkDK,IAAlD,CAAuDL,GAAvD,CAAP;AACH;;AAED,SAASO,SAAT,CAAmBC,QAAnB,EAAqCC,KAArC,EAAqDC,YAArD;EACI,MAAMC,CAAC,GAAGF,KAAK,GAAGZ,eAAH,G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A6C,CAACxB,GAAD,EAAMmC,CAAN,kBAC1CH,aAAA,MAAA;IAAKhC,GAAG,EAAEmC;GAAV,EAAcnC,GAAd,CADH,CADL,CAFJ,CADH,CANL,CADJ;AAmBH;;;;"}
|
|
@@ -1,23 +1,16 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { useCallback, useMemo, createElement, useContext,
|
|
1
|
+
import { objectWithoutProperties as _objectWithoutProperties, objectSpread2 as _objectSpread2 } from '../../_virtual/_rollupPluginBabelHelpers.js';
|
|
2
|
+
import { useCallback, useMemo, createElement, useContext, forwardRef, Children, cloneElement, createContext } from 'react';
|
|
3
3
|
import classNames from 'classnames';
|
|
4
4
|
import { polymorphicComponent } from '../../utils/polymorphism.js';
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
_excluded6 = ["value", "children", "onSelect", "hideOnSelect", "onClick", "exceptionallySetClassName"],
|
|
15
|
-
_excluded7 = ["handleItemSelect"],
|
|
16
|
-
_excluded8 = ["children", "onItemSelect"],
|
|
17
|
-
_excluded9 = ["handleItemSelect"],
|
|
18
|
-
_excluded10 = ["label", "children", "exceptionallySetClassName"],
|
|
19
|
-
_excluded11 = ["handleItemSelect"];
|
|
20
|
-
var MenuContext = /*#__PURE__*/createContext( // Reakit gives us no means to obtain a valid initial/default value of type MenuStateReturn
|
|
5
|
+
import { useMenuState, MenuButton as MenuButton$1, Menu as Menu$1, MenuItem as MenuItem$1, useMenuItem, MenuGroup as MenuGroup$1 } from 'ariakit/menu';
|
|
6
|
+
import { Portal } from 'ariakit/portal';
|
|
7
|
+
|
|
8
|
+
const _excluded = ["children", "onItemSelect"],
|
|
9
|
+
_excluded2 = ["exceptionallySetClassName"],
|
|
10
|
+
_excluded3 = ["exceptionallySetClassName"],
|
|
11
|
+
_excluded4 = ["value", "children", "onSelect", "hideOnSelect", "onClick", "exceptionallySetClassName", "as"],
|
|
12
|
+
_excluded5 = ["label", "children", "exceptionallySetClassName"];
|
|
13
|
+
const MenuContext = /*#__PURE__*/createContext( // Ariakit gives us no means to obtain a valid initial/default value of type MenuStateReturn
|
|
21
14
|
// (it is normally obtained by calling useMenuState but we can't call hooks outside components).
|
|
22
15
|
// This is however of little consequence since this value is only used if some of the components
|
|
23
16
|
// are used outside Menu, something that should not happen and we do not support.
|
|
@@ -29,22 +22,24 @@ var MenuContext = /*#__PURE__*/createContext( // Reakit gives us no means to obt
|
|
|
29
22
|
*/
|
|
30
23
|
|
|
31
24
|
function Menu(_ref) {
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
25
|
+
let {
|
|
26
|
+
children,
|
|
27
|
+
onItemSelect
|
|
28
|
+
} = _ref,
|
|
29
|
+
props = _objectWithoutProperties(_ref, _excluded);
|
|
30
|
+
|
|
31
|
+
const state = useMenuState(_objectSpread2({
|
|
32
|
+
focusLoop: true,
|
|
33
|
+
gutter: 8,
|
|
34
|
+
shift: 8
|
|
39
35
|
}, props));
|
|
40
|
-
|
|
36
|
+
const handleItemSelect = useCallback(function handleItemSelect(value) {
|
|
41
37
|
if (onItemSelect) onItemSelect(value);
|
|
42
38
|
}, [onItemSelect]);
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
}, [state, handleItemSelect]);
|
|
39
|
+
const value = useMemo(() => ({
|
|
40
|
+
state,
|
|
41
|
+
handleItemSelect
|
|
42
|
+
}), [state, handleItemSelect]);
|
|
48
43
|
return /*#__PURE__*/createElement(MenuContext.Provider, {
|
|
49
44
|
value: value
|
|
50
45
|
}, children);
|
|
@@ -54,69 +49,38 @@ function Menu(_ref) {
|
|
|
54
49
|
*/
|
|
55
50
|
|
|
56
51
|
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
state = _objectWithoutPropertiesLoose(_React$useContext, _excluded3);
|
|
52
|
+
const MenuButton = /*#__PURE__*/polymorphicComponent(function MenuButton(_ref2, ref) {
|
|
53
|
+
let {
|
|
54
|
+
exceptionallySetClassName
|
|
55
|
+
} = _ref2,
|
|
56
|
+
props = _objectWithoutProperties(_ref2, _excluded2);
|
|
63
57
|
|
|
64
|
-
|
|
58
|
+
const {
|
|
59
|
+
state
|
|
60
|
+
} = useContext(MenuContext);
|
|
61
|
+
return /*#__PURE__*/createElement(MenuButton$1, _objectSpread2(_objectSpread2({}, props), {}, {
|
|
62
|
+
state: state,
|
|
65
63
|
ref: ref,
|
|
66
64
|
className: classNames('reactist_menubutton', exceptionallySetClassName)
|
|
67
65
|
}));
|
|
68
66
|
});
|
|
69
|
-
var BACKDROP_STYLE = {
|
|
70
|
-
width: '100%',
|
|
71
|
-
height: '100%',
|
|
72
|
-
position: 'fixed',
|
|
73
|
-
top: 0,
|
|
74
|
-
left: 0
|
|
75
|
-
};
|
|
76
|
-
/**
|
|
77
|
-
* Internal component to provide a backdrop/overlay to all menus. This is needed because reakit's
|
|
78
|
-
* menus do not show an overlay by default.
|
|
79
|
-
*/
|
|
80
|
-
|
|
81
|
-
function MenuBackdrop(_ref3) {
|
|
82
|
-
var baseId = _ref3.baseId,
|
|
83
|
-
visible = _ref3.visible,
|
|
84
|
-
animated = _ref3.animated,
|
|
85
|
-
animating = _ref3.animating,
|
|
86
|
-
stopAnimation = _ref3.stopAnimation,
|
|
87
|
-
modal = _ref3.modal,
|
|
88
|
-
children = _ref3.children;
|
|
89
|
-
return /*#__PURE__*/createElement(PopoverBackdrop, {
|
|
90
|
-
baseId: baseId,
|
|
91
|
-
visible: visible,
|
|
92
|
-
animated: animated,
|
|
93
|
-
animating: animating,
|
|
94
|
-
stopAnimation: stopAnimation,
|
|
95
|
-
modal: modal,
|
|
96
|
-
style: BACKDROP_STYLE
|
|
97
|
-
}, children);
|
|
98
|
-
}
|
|
99
67
|
/**
|
|
100
68
|
* The dropdown menu itself, containing a list of menu items.
|
|
101
69
|
*/
|
|
102
70
|
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
(_state$unstable_refer = state.unstable_referenceRef) === null || _state$unstable_refer === void 0 ? void 0 : (_state$unstable_refer2 = _state$unstable_refer.current) === null || _state$unstable_refer2 === void 0 ? void 0 : _state$unstable_refer2.focus();
|
|
117
|
-
}
|
|
118
|
-
}, [state.visible, previousVisible, state.unstable_referenceRef]);
|
|
119
|
-
return state.visible ? /*#__PURE__*/createElement(MenuBackdrop, Object.assign({}, state), /*#__PURE__*/createElement(Menu$1, Object.assign({}, props, state, {
|
|
71
|
+
const MenuList = /*#__PURE__*/polymorphicComponent(function MenuList(_ref3, ref) {
|
|
72
|
+
let {
|
|
73
|
+
exceptionallySetClassName
|
|
74
|
+
} = _ref3,
|
|
75
|
+
props = _objectWithoutProperties(_ref3, _excluded3);
|
|
76
|
+
|
|
77
|
+
const {
|
|
78
|
+
state
|
|
79
|
+
} = useContext(MenuContext);
|
|
80
|
+
return state.visible ? /*#__PURE__*/createElement(Portal, {
|
|
81
|
+
preserveTabOrder: true
|
|
82
|
+
}, /*#__PURE__*/createElement(Menu$1, _objectSpread2(_objectSpread2({}, props), {}, {
|
|
83
|
+
state: state,
|
|
120
84
|
ref: ref,
|
|
121
85
|
className: classNames('reactist_menulist', exceptionallySetClassName)
|
|
122
86
|
}))) : null;
|
|
@@ -126,32 +90,39 @@ var MenuList = /*#__PURE__*/polymorphicComponent(function MenuList(_ref4, ref) {
|
|
|
126
90
|
* callback.
|
|
127
91
|
*/
|
|
128
92
|
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
93
|
+
const MenuItem = /*#__PURE__*/polymorphicComponent(function MenuItem(_ref4, ref) {
|
|
94
|
+
let {
|
|
95
|
+
value,
|
|
96
|
+
children,
|
|
97
|
+
onSelect,
|
|
98
|
+
hideOnSelect = true,
|
|
99
|
+
onClick,
|
|
100
|
+
exceptionallySetClassName,
|
|
101
|
+
as = 'button'
|
|
102
|
+
} = _ref4,
|
|
103
|
+
props = _objectWithoutProperties(_ref4, _excluded4);
|
|
104
|
+
|
|
105
|
+
const {
|
|
106
|
+
handleItemSelect,
|
|
107
|
+
state
|
|
108
|
+
} = useContext(MenuContext);
|
|
109
|
+
const {
|
|
110
|
+
hide
|
|
111
|
+
} = state;
|
|
112
|
+
const handleClick = useCallback(function handleClick(event) {
|
|
113
|
+
onClick == null ? void 0 : onClick(event);
|
|
114
|
+
const onSelectResult = onSelect && !event.defaultPrevented ? onSelect() : undefined;
|
|
115
|
+
const shouldClose = onSelectResult !== false && hideOnSelect;
|
|
148
116
|
handleItemSelect(value);
|
|
149
117
|
if (shouldClose) hide();
|
|
150
118
|
}, [onSelect, onClick, handleItemSelect, hideOnSelect, hide, value]);
|
|
151
|
-
return /*#__PURE__*/createElement(MenuItem$1,
|
|
119
|
+
return /*#__PURE__*/createElement(MenuItem$1, _objectSpread2(_objectSpread2({}, props), {}, {
|
|
120
|
+
as: as,
|
|
121
|
+
state: state,
|
|
152
122
|
ref: ref,
|
|
153
123
|
onClick: handleClick,
|
|
154
|
-
className: exceptionallySetClassName
|
|
124
|
+
className: exceptionallySetClassName,
|
|
125
|
+
hideOnClick: false
|
|
155
126
|
}), children);
|
|
156
127
|
});
|
|
157
128
|
/**
|
|
@@ -176,35 +147,32 @@ var MenuItem = /*#__PURE__*/polymorphicComponent(function MenuItem(_ref5, ref) {
|
|
|
176
147
|
* opening a sub-menu with the menu items list below it.
|
|
177
148
|
*/
|
|
178
149
|
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
150
|
+
const SubMenu = /*#__PURE__*/forwardRef(function SubMenu({
|
|
151
|
+
children,
|
|
152
|
+
onItemSelect
|
|
153
|
+
}, ref) {
|
|
154
|
+
const {
|
|
155
|
+
handleItemSelect: parentMenuItemSelect,
|
|
156
|
+
state
|
|
157
|
+
} = useContext(MenuContext);
|
|
158
|
+
const {
|
|
159
|
+
hide: parentMenuHide
|
|
160
|
+
} = state;
|
|
161
|
+
const handleSubItemSelect = useCallback(function handleSubItemSelect(value) {
|
|
190
162
|
if (onItemSelect) onItemSelect(value);
|
|
191
163
|
parentMenuItemSelect(value);
|
|
192
164
|
parentMenuHide();
|
|
193
165
|
}, [parentMenuHide, parentMenuItemSelect, onItemSelect]);
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
list = _React$Children$toArr[1];
|
|
198
|
-
|
|
199
|
-
return /*#__PURE__*/createElement(MenuItem$1, Object.assign({}, state, props, {
|
|
200
|
-
ref: ref
|
|
201
|
-
}), function (buttonProps) {
|
|
202
|
-
return /*#__PURE__*/createElement(Menu, {
|
|
203
|
-
onItemSelect: handleSubItemSelect
|
|
204
|
-
}, /*#__PURE__*/cloneElement(button, _objectSpread2(_objectSpread2({}, buttonProps), {}, {
|
|
205
|
-
className: classNames(buttonProps.className, 'reactist_submenu_button')
|
|
206
|
-
})), list);
|
|
166
|
+
const [button, list] = Children.toArray(children);
|
|
167
|
+
const menuProps = useMenuItem({
|
|
168
|
+
state
|
|
207
169
|
});
|
|
170
|
+
return /*#__PURE__*/createElement(Menu, {
|
|
171
|
+
onItemSelect: handleSubItemSelect
|
|
172
|
+
}, /*#__PURE__*/cloneElement(button, _objectSpread2(_objectSpread2({}, menuProps), {}, {
|
|
173
|
+
className: classNames(menuProps.className, 'reactist_submenu_button'),
|
|
174
|
+
ref
|
|
175
|
+
})), list);
|
|
208
176
|
});
|
|
209
177
|
/**
|
|
210
178
|
* A way to semantically group some menu items.
|
|
@@ -213,18 +181,20 @@ var SubMenu = /*#__PURE__*/forwardRef(function SubMenu(_ref6, ref) {
|
|
|
213
181
|
* before and/or after the group if you so wish.
|
|
214
182
|
*/
|
|
215
183
|
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
}, props,
|
|
184
|
+
const MenuGroup = /*#__PURE__*/polymorphicComponent(function MenuGroup(_ref5, ref) {
|
|
185
|
+
let {
|
|
186
|
+
label,
|
|
187
|
+
children,
|
|
188
|
+
exceptionallySetClassName
|
|
189
|
+
} = _ref5,
|
|
190
|
+
props = _objectWithoutProperties(_ref5, _excluded5);
|
|
191
|
+
|
|
192
|
+
const {
|
|
193
|
+
state
|
|
194
|
+
} = useContext(MenuContext);
|
|
195
|
+
return /*#__PURE__*/createElement(MenuGroup$1, _objectSpread2(_objectSpread2({}, props), {}, {
|
|
196
|
+
ref: ref,
|
|
197
|
+
state: state,
|
|
228
198
|
className: exceptionallySetClassName
|
|
229
199
|
}), label ? /*#__PURE__*/createElement("div", {
|
|
230
200
|
role: "presentation",
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"menu.js","sources":["../../../src/components/menu/menu.tsx"],"sourcesContent":["import * as React from 'react'\nimport classNames from 'classnames'\nimport { polymorphicComponent } from '../../utils/polymorphism'\nimport { usePrevious } from '../../hooks/use-previous'\n\n//\n// Reactist menu is a thin wrapper around Reakit's menu components. This may or may not be\n// temporary. Our goal is to make it transparent for the users of Reactist of this implementation\n// detail. We may change in the future the external lib we use, or even implement it all internally,\n// as long as we keep the same outer interface as intact as possible.\n//\n// Around the heavy lifting of the external lib we just add some features to better integrate the\n// menu to Reactist's more opinionated approach (e.g. using our button with its custom variants and\n// other features, easily show keyboard shortcuts in menu items, etc.)\n//\nimport * as Reakit from 'reakit/Menu'\nimport { PopoverBackdrop } from 'reakit/Popover'\n\nimport './menu.less'\n\ntype NativeProps<E extends HTMLElement> = React.DetailedHTMLProps<React.HTMLAttributes<E>, E>\n\ntype MenuContextState = Reakit.MenuStateReturn & {\n handleItemSelect: (value: string | null | undefined) => void\n}\n\nconst MenuContext = React.createContext<MenuContextState>(\n // Reakit gives us no means to obtain a valid initial/default value of type MenuStateReturn\n // (it is normally obtained by calling useMenuState but we can't call hooks outside components).\n // This is however of little consequence since this value is only used if some of the components\n // are used outside Menu, something that should not happen and we do not support.\n // @ts-expect-error\n {},\n)\n\n//\n// Menu\n//\n\ntype MenuProps = Omit<Reakit.MenuInitialState, 'visible'> & {\n /**\n * The `Menu` must contain a `MenuList` that defines the menu options. It must also contain a\n * `MenuButton` that triggers the menu to be opened or closed.\n */\n children: React.ReactNode\n\n /**\n * An optional callback that will be called back whenever a menu item is selected. It receives\n * the `value` of the selected `MenuItem`.\n *\n * If you pass down this callback, it is recommended that you properly memoize it so it does not\n * change on every render.\n */\n onItemSelect?: (value: string | null | undefined) => void\n}\n\n/**\n * Wrapper component to control a menu. It does not render anything, only providing the state\n * management for the menu components inside it.\n */\nfunction Menu({ children, onItemSelect, ...props }: MenuProps) {\n const state = Reakit.useMenuState({ loop: true, unstable_offset: [8, 8], ...props })\n\n const handleItemSelect = React.useCallback(\n function handleItemSelect(value: string | null | undefined) {\n if (onItemSelect) onItemSelect(value)\n },\n [onItemSelect],\n )\n\n const value: MenuContextState = React.useMemo(\n () => ({\n ...state,\n handleItemSelect,\n }),\n [state, handleItemSelect],\n )\n\n return <MenuContext.Provider value={value}>{children}</MenuContext.Provider>\n}\n\n//\n// MenuButton\n//\n\ntype MenuButtonProps = Omit<Reakit.MenuButtonProps, keyof Reakit.MenuStateReturn | 'className'>\n\n/**\n * A button to toggle a dropdown menu open or closed.\n */\nconst MenuButton = polymorphicComponent<'button', MenuButtonProps>(function MenuButton(\n { exceptionallySetClassName, ...props },\n ref,\n) {\n const { handleItemSelect, ...state } = React.useContext(MenuContext)\n return (\n <Reakit.MenuButton\n {...props}\n {...state}\n ref={ref}\n className={classNames('reactist_menubutton', exceptionallySetClassName)}\n />\n )\n})\n\n//\n// MenuList\n//\n\ntype MenuBackdropProps = Reakit.MenuStateReturn & {\n children: React.ReactNode\n}\n\nconst BACKDROP_STYLE: React.CSSProperties = {\n width: '100%',\n height: '100%',\n position: 'fixed',\n top: 0,\n left: 0,\n}\n\n/**\n * Internal component to provide a backdrop/overlay to all menus. This is needed because reakit's\n * menus do not show an overlay by default.\n */\nfunction MenuBackdrop({\n baseId,\n visible,\n animated,\n animating,\n stopAnimation,\n modal,\n children,\n}: MenuBackdropProps) {\n return (\n <PopoverBackdrop\n baseId={baseId}\n visible={visible}\n animated={animated}\n animating={animating}\n stopAnimation={stopAnimation}\n modal={modal}\n style={BACKDROP_STYLE}\n >\n {children}\n </PopoverBackdrop>\n )\n}\n\ntype MenuListProps = Omit<Reakit.MenuProps, keyof Reakit.MenuStateReturn | 'className'>\n\n/**\n * The dropdown menu itself, containing a list of menu items.\n */\nconst MenuList = polymorphicComponent<'div', MenuListProps>(function MenuList(\n { exceptionallySetClassName, ...props },\n ref,\n) {\n const { handleItemSelect, ...state } = React.useContext(MenuContext)\n const previousVisible = usePrevious(state.visible)\n\n React.useEffect(\n function focusTriggerOnClose() {\n if (state.visible === false && previousVisible === true) {\n state.unstable_referenceRef?.current?.focus()\n }\n },\n [state.visible, previousVisible, state.unstable_referenceRef],\n )\n\n return state.visible ? (\n <MenuBackdrop {...state}>\n <Reakit.Menu\n {...props}\n {...state}\n ref={ref}\n className={classNames('reactist_menulist', exceptionallySetClassName)}\n />\n </MenuBackdrop>\n ) : null\n})\n\n//\n// MenuItem\n//\n\ntype MenuItemProps = {\n /**\n * An optional value given to this menu item. It is passed on to the parent `Menu`'s\n * `onItemSelect` when you provide that instead of (or alongside) providing individual\n * `onSelect` callbacks to each menu item.\n */\n value?: string\n /**\n * The content inside the menu item.\n */\n children: React.ReactNode\n /**\n * When `true` the menu item is disabled and won't be selectable or be part of the keyboard\n * navigation across the menu options.\n *\n * @default true\n */\n disabled?: boolean\n /**\n * When `true` the menu will close when the menu item is selected, in addition to performing the\n * action that the menu item is set out to do.\n *\n * Set this to `false` to make sure that a given menu item does not auto-closes the menu when\n * selected. This should be the exception and not the norm, as the default is to auto-close.\n *\n * @default true\n */\n hideOnSelect?: boolean\n /**\n * The action to perform when the menu item is selected.\n *\n * If you return `false` from this function, the menu will not auto-close when this menu item\n * is selected. Though you should use `hideOnSelect` for this purpose, this allows you to\n * achieve the same effect conditionally and dynamically deciding at run time.\n */\n onSelect?: () => unknown\n /**\n * The event handler called when the menu item is clicked.\n *\n * This is similar to `onSelect`, but a bit different. You can certainly use it to trigger the\n * action that the menu item represents. But in general you should prefer `onSelect` for that.\n *\n * The main use for this handler is to get access to the click event. This can be used, for\n * example, to call `event.preventDefault()`, which will effectively prevent the rest of the\n * consequences of the click, including preventing `onSelect` from being called. In particular,\n * this is useful in menu items that are links, and you want the click to not trigger navigation\n * under some circumstances.\n */\n onClick?: (event: React.MouseEvent) => void\n}\n\n/**\n * A menu item inside a menu list. It can be selected by the user, triggering the `onSelect`\n * callback.\n */\nconst MenuItem = polymorphicComponent<'button', MenuItemProps>(function MenuItem(\n {\n value,\n children,\n onSelect,\n hideOnSelect = true,\n onClick,\n exceptionallySetClassName,\n ...props\n },\n ref,\n) {\n const { handleItemSelect, ...state } = React.useContext(MenuContext)\n const { hide } = state\n\n const handleClick = React.useCallback(\n function handleClick(event: React.MouseEvent<HTMLButtonElement>) {\n onClick?.(event)\n const onSelectResult: unknown =\n onSelect && !event.defaultPrevented ? onSelect() : undefined\n const shouldClose = onSelectResult !== false && hideOnSelect\n handleItemSelect(value)\n if (shouldClose) hide()\n },\n [onSelect, onClick, handleItemSelect, hideOnSelect, hide, value],\n )\n\n return (\n <Reakit.MenuItem\n {...props}\n {...state}\n ref={ref}\n onClick={handleClick}\n className={exceptionallySetClassName}\n >\n {children}\n </Reakit.MenuItem>\n )\n})\n\n//\n// SubMenu\n//\n\ntype SubMenuProps = Pick<MenuProps, 'children' | 'onItemSelect'>\n\n/**\n * This component can be rendered alongside other `MenuItem` inside a `MenuList` in order to have\n * a sub-menu.\n *\n * Its children are expected to have the structure of a first level menu (a `MenuButton` and a\n * `MenuList`).\n *\n * ```jsx\n * <MenuItem label=\"Edit profile\" />\n * <SubMenu>\n * <MenuButton>More options</MenuButton>\n * <MenuList>\n * <MenuItem label=\"Preferences\" />\n * <MenuItem label=\"Sign out\" />\n * </MenuList>\n * </SubMenu>\n * ```\n *\n * The `MenuButton` will become a menu item in the current menu items list, and it will lead to\n * opening a sub-menu with the menu items list below it.\n */\nconst SubMenu = React.forwardRef<HTMLButtonElement, SubMenuProps>(function SubMenu(\n { children, onItemSelect, ...props },\n ref,\n) {\n const { handleItemSelect: parentMenuItemSelect, ...state } = React.useContext(MenuContext)\n const { hide: parentMenuHide } = state\n\n const handleSubItemSelect = React.useCallback(\n function handleSubItemSelect(value) {\n if (onItemSelect) onItemSelect(value)\n parentMenuItemSelect(value)\n parentMenuHide()\n },\n [parentMenuHide, parentMenuItemSelect, onItemSelect],\n )\n\n const [button, list] = React.Children.toArray(children)\n\n return (\n <Reakit.MenuItem {...state} {...props} ref={ref}>\n {(buttonProps) => (\n <Menu onItemSelect={handleSubItemSelect}>\n {React.cloneElement(button as React.ReactElement, {\n ...buttonProps,\n className: classNames(buttonProps.className, 'reactist_submenu_button'),\n })}\n {list}\n </Menu>\n )}\n </Reakit.MenuItem>\n )\n})\n\n//\n// MenuGroup\n//\n\ntype MenuGroupProps = Omit<NativeProps<HTMLDivElement>, 'className'> & {\n /**\n * A label to be shown visually and also used to semantically label the group.\n */\n label: string\n}\n\n/**\n * A way to semantically group some menu items.\n *\n * This group does not add any visual separator. You can do that yourself adding `<hr />` elements\n * before and/or after the group if you so wish.\n */\nconst MenuGroup = polymorphicComponent<'div', MenuGroupProps>(function MenuGroud(\n { label, children, exceptionallySetClassName, ...props },\n ref,\n) {\n const { handleItemSelect, ...state } = React.useContext(MenuContext)\n return (\n <Reakit.MenuGroup ref={ref} {...props} {...state} className={exceptionallySetClassName}>\n {label ? (\n <div role=\"presentation\" className=\"reactist_menugroup__label\">\n {label}\n </div>\n ) : null}\n {children}\n </Reakit.MenuGroup>\n )\n})\n\nexport { Menu, MenuButton, MenuList, MenuItem, SubMenu, MenuGroup }\nexport type { MenuButtonProps, MenuListProps, MenuItemProps, SubMenuProps, MenuGroupProps }\n"],"names":["MenuContext","React","Menu","children","onItemSelect","props","state","Reakit","loop","unstable_offset","handleItemSelect","value","Provider","MenuButton","polymorphicComponent","ref","exceptionallySetClassName","className","classNames","BACKDROP_STYLE","width","height","position","top","left","MenuBackdrop","baseId","visible","animated","animating","stopAnimation","modal","PopoverBackdrop","style","MenuList","previousVisible","usePrevious","focusTriggerOnClose","unstable_referenceRef","current","focus","MenuItem","onSelect","hideOnSelect","onClick","hide","handleClick","event","onSelectResult","defaultPrevented","undefined","shouldClose","SubMenu","parentMenuItemSelect","parentMenuHide","handleSubItemSelect","toArray","button","list","buttonProps","MenuGroup","MenuGroud","label","role"],"mappings":";;;;;;;;;;;;;;;;;;;AA0BA,IAAMA,WAAW,gBAAGC,aAAA;AAEhB;AACA;AACA;AACA;AACA,EANgB,CAApB;AA8BA;;;;;AAIA,SAASC,IAAT;MAAgBC,gBAAAA;MAAUC,oBAAAA;MAAiBC;;AACvC,MAAMC,KAAK,GAAGC,YAAA;AAAsBC,IAAAA,IAAI,EAAE,IAA5B;AAAkCC,IAAAA,eAAe,EAAE,CAAC,CAAD,EAAI,CAAJ;AAAnD,KAA8DJ,KAA9D,EAAd;AAEA,MAAMK,gBAAgB,GAAGT,WAAA,CACrB,SAASS,gBAAT,CAA0BC,KAA1B;AACI,QAAIP,YAA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rD,QAAvB,CAAvB;AAAA,MAAOsD,MAAP;AAAA,MAAeC,IAAf;;AAEA,sBACIzD,aAAA,CAACM,UAAD,oBAAqBD,OAAWD;AAAOU,IAAAA,GAAG,EAAEA;IAA5C,EACK,UAAC4C,WAAD;AAAA,wBACG1D,aAAA,CAACC,IAAD;AAAME,MAAAA,YAAY,EAAEmD;KAApB,eACKtD,YAAA,CAAmBwD,MAAnB,oCACME,WADN;AAEG1C,MAAAA,SAAS,EAAEC,UAAU,CAACyC,WAAW,CAAC1C,SAAb,EAAwB,yBAAxB;AAFxB,OADL,EAKKyC,IALL,CADH;AAAA,GADL,CADJ;AAaH,CA/Be;AA4ChB;;;;;;;IAMME,SAAS,gBAAG9C,oBAAoB,CAAwB,SAAS+C,SAAT,QAE1D9C,GAF0D;MACxD+C,cAAAA;MAAO3D,iBAAAA;MAAUa,kCAAAA;MAA8BX;;AAGjD,2BAAuCJ,UAAA,CAAiBD,WAAjB,CAAvC;AAAA,MAA6BM,KAA7B;;AACA,sBACIL,aAAA,CAACM,WAAD;AAAkBQ,IAAAA,GAAG,EAAEA;KAASV,OAAWC;AAAOW,IAAAA,SAAS,EAAED;IAA7D,EACK8C,KAAK,gBACF7D,aAAA,MAAA;AAAK8D,IAAAA,IAAI,EAAC;AAAe9C,IAAAA,SAAS,EAAC;GAAnC,EACK6C,KADL,CADE,GAIF,IALR,EAMK3D,QANL,CADJ;AAUH,CAfqC;;;;"}
|
|
1
|
+
{"version":3,"file":"menu.js","sources":["../../../src/components/menu/menu.tsx"],"sourcesContent":["import * as React from 'react'\nimport classNames from 'classnames'\nimport { polymorphicComponent } from '../../utils/polymorphism'\n\n//\n// Reactist menu is a thin wrapper around Ariakit's menu components. This may or may not be\n// temporary. Our goal is to make it transparent for the users of Reactist of this implementation\n// detail. We may change in the future the external lib we use, or even implement it all internally,\n// as long as we keep the same outer interface as intact as possible.\n//\n// Around the heavy lifting of the external lib we just add some features to better integrate the\n// menu to Reactist's more opinionated approach (e.g. using our button with its custom variants and\n// other features, easily show keyboard shortcuts in menu items, etc.)\n//\nimport * as Ariakit from 'ariakit/menu'\nimport { Portal } from 'ariakit/portal'\n\nimport './menu.less'\nimport { useMenuItem } from 'ariakit/menu'\n\ntype NativeProps<E extends HTMLElement> = React.DetailedHTMLProps<React.HTMLAttributes<E>, E>\n\ntype MenuContextState = {\n state: Ariakit.MenuState\n handleItemSelect: (value: string | null | undefined) => void\n}\n\nconst MenuContext = React.createContext<MenuContextState>(\n // Ariakit gives us no means to obtain a valid initial/default value of type MenuStateReturn\n // (it is normally obtained by calling useMenuState but we can't call hooks outside components).\n // This is however of little consequence since this value is only used if some of the components\n // are used outside Menu, something that should not happen and we do not support.\n // @ts-expect-error\n {},\n)\n\n//\n// Menu\n//\n\ntype MenuProps = Omit<Ariakit.MenuStateProps, 'visible'> & {\n /**\n * The `Menu` must contain a `MenuList` that defines the menu options. It must also contain a\n * `MenuButton` that triggers the menu to be opened or closed.\n */\n children: React.ReactNode\n\n /**\n * An optional callback that will be called back whenever a menu item is selected. It receives\n * the `value` of the selected `MenuItem`.\n *\n * If you pass down this callback, it is recommended that you properly memoize it so it does not\n * change on every render.\n */\n onItemSelect?: (value: string | null | undefined) => void\n}\n\n/**\n * Wrapper component to control a menu. It does not render anything, only providing the state\n * management for the menu components inside it.\n */\nfunction Menu({ children, onItemSelect, ...props }: MenuProps) {\n const state = Ariakit.useMenuState({ focusLoop: true, gutter: 8, shift: 8, ...props })\n\n const handleItemSelect = React.useCallback(\n function handleItemSelect(value: string | null | undefined) {\n if (onItemSelect) onItemSelect(value)\n },\n [onItemSelect],\n )\n\n const value: MenuContextState = React.useMemo(\n () => ({\n state,\n handleItemSelect,\n }),\n [state, handleItemSelect],\n )\n\n return <MenuContext.Provider value={value}>{children}</MenuContext.Provider>\n}\n\n//\n// MenuButton\n//\n\ntype MenuButtonProps = Omit<Ariakit.MenuButtonProps, 'state' | 'className' | 'as'>\n\n/**\n * A button to toggle a dropdown menu open or closed.\n */\nconst MenuButton = polymorphicComponent<'button', MenuButtonProps>(function MenuButton(\n { exceptionallySetClassName, ...props },\n ref,\n) {\n const { state } = React.useContext(MenuContext)\n return (\n <Ariakit.MenuButton\n {...props}\n state={state}\n ref={ref}\n className={classNames('reactist_menubutton', exceptionallySetClassName)}\n />\n )\n})\n\n//\n// MenuList\n//\n\ntype MenuListProps = Omit<Ariakit.MenuProps, 'state' | 'className'>\n\n/**\n * The dropdown menu itself, containing a list of menu items.\n */\nconst MenuList = polymorphicComponent<'div', MenuListProps>(function MenuList(\n { exceptionallySetClassName, ...props },\n ref,\n) {\n const { state } = React.useContext(MenuContext)\n\n return state.visible ? (\n <Portal preserveTabOrder>\n <Ariakit.Menu\n {...props}\n state={state}\n ref={ref}\n className={classNames('reactist_menulist', exceptionallySetClassName)}\n />\n </Portal>\n ) : null\n})\n\n//\n// MenuItem\n//\n\ntype MenuItemProps = {\n /**\n * An optional value given to this menu item. It is passed on to the parent `Menu`'s\n * `onItemSelect` when you provide that instead of (or alongside) providing individual\n * `onSelect` callbacks to each menu item.\n */\n value?: string\n /**\n * The content inside the menu item.\n */\n children: React.ReactNode\n /**\n * When `true` the menu item is disabled and won't be selectable or be part of the keyboard\n * navigation across the menu options.\n *\n * @default true\n */\n disabled?: boolean\n /**\n * When `true` the menu will close when the menu item is selected, in addition to performing the\n * action that the menu item is set out to do.\n *\n * Set this to `false` to make sure that a given menu item does not auto-closes the menu when\n * selected. This should be the exception and not the norm, as the default is to auto-close.\n *\n * @default true\n */\n hideOnSelect?: boolean\n /**\n * The action to perform when the menu item is selected.\n *\n * If you return `false` from this function, the menu will not auto-close when this menu item\n * is selected. Though you should use `hideOnSelect` for this purpose, this allows you to\n * achieve the same effect conditionally and dynamically deciding at run time.\n */\n onSelect?: () => unknown\n /**\n * The event handler called when the menu item is clicked.\n *\n * This is similar to `onSelect`, but a bit different. You can certainly use it to trigger the\n * action that the menu item represents. But in general you should prefer `onSelect` for that.\n *\n * The main use for this handler is to get access to the click event. This can be used, for\n * example, to call `event.preventDefault()`, which will effectively prevent the rest of the\n * consequences of the click, including preventing `onSelect` from being called. In particular,\n * this is useful in menu items that are links, and you want the click to not trigger navigation\n * under some circumstances.\n */\n onClick?: (event: React.MouseEvent) => void\n}\n\n/**\n * A menu item inside a menu list. It can be selected by the user, triggering the `onSelect`\n * callback.\n */\nconst MenuItem = polymorphicComponent<'button', MenuItemProps>(function MenuItem(\n {\n value,\n children,\n onSelect,\n hideOnSelect = true,\n onClick,\n exceptionallySetClassName,\n as = 'button',\n ...props\n },\n ref,\n) {\n const { handleItemSelect, state } = React.useContext(MenuContext)\n const { hide } = state\n\n const handleClick = React.useCallback(\n function handleClick(event: React.MouseEvent<HTMLButtonElement>) {\n onClick?.(event)\n const onSelectResult: unknown =\n onSelect && !event.defaultPrevented ? onSelect() : undefined\n const shouldClose = onSelectResult !== false && hideOnSelect\n handleItemSelect(value)\n if (shouldClose) hide()\n },\n [onSelect, onClick, handleItemSelect, hideOnSelect, hide, value],\n )\n\n return (\n <Ariakit.MenuItem\n {...props}\n as={as}\n state={state}\n ref={ref}\n onClick={handleClick}\n className={exceptionallySetClassName}\n hideOnClick={false}\n >\n {children}\n </Ariakit.MenuItem>\n )\n})\n\n//\n// SubMenu\n//\n\ntype SubMenuProps = Pick<MenuProps, 'children' | 'onItemSelect'>\n\n/**\n * This component can be rendered alongside other `MenuItem` inside a `MenuList` in order to have\n * a sub-menu.\n *\n * Its children are expected to have the structure of a first level menu (a `MenuButton` and a\n * `MenuList`).\n *\n * ```jsx\n * <MenuItem label=\"Edit profile\" />\n * <SubMenu>\n * <MenuButton>More options</MenuButton>\n * <MenuList>\n * <MenuItem label=\"Preferences\" />\n * <MenuItem label=\"Sign out\" />\n * </MenuList>\n * </SubMenu>\n * ```\n *\n * The `MenuButton` will become a menu item in the current menu items list, and it will lead to\n * opening a sub-menu with the menu items list below it.\n */\nconst SubMenu = React.forwardRef<HTMLButtonElement, SubMenuProps>(function SubMenu(\n { children, onItemSelect },\n ref,\n) {\n const { handleItemSelect: parentMenuItemSelect, state } = React.useContext(MenuContext)\n const { hide: parentMenuHide } = state\n\n const handleSubItemSelect = React.useCallback(\n function handleSubItemSelect(value: string | null | undefined) {\n if (onItemSelect) onItemSelect(value)\n parentMenuItemSelect(value)\n parentMenuHide()\n },\n [parentMenuHide, parentMenuItemSelect, onItemSelect],\n )\n\n const [button, list] = React.Children.toArray(children)\n\n const menuProps = useMenuItem({ state })\n\n return (\n <Menu onItemSelect={handleSubItemSelect}>\n {React.cloneElement(button as React.ReactElement, {\n ...menuProps,\n className: classNames(menuProps.className, 'reactist_submenu_button'),\n ref,\n })}\n {list}\n </Menu>\n )\n})\n\n//\n// MenuGroup\n//\n\ntype MenuGroupProps = Omit<NativeProps<HTMLDivElement>, 'className'> & {\n /**\n * A label to be shown visually and also used to semantically label the group.\n */\n label: string\n}\n\n/**\n * A way to semantically group some menu items.\n *\n * This group does not add any visual separator. You can do that yourself adding `<hr />` elements\n * before and/or after the group if you so wish.\n */\nconst MenuGroup = polymorphicComponent<'div', MenuGroupProps>(function MenuGroup(\n { label, children, exceptionallySetClassName, ...props },\n ref,\n) {\n const { state } = React.useContext(MenuContext)\n return (\n <Ariakit.MenuGroup {...props} ref={ref} state={state} className={exceptionallySetClassName}>\n {label ? (\n <div role=\"presentation\" className=\"reactist_menugroup__label\">\n {label}\n </div>\n ) : null}\n {children}\n </Ariakit.MenuGroup>\n )\n})\n\nexport { Menu, MenuButton, MenuList, MenuItem, SubMenu, MenuGroup }\nexport type { MenuButtonProps, MenuListProps, MenuItemProps, SubMenuProps, MenuGroupProps }\n"],"names":["MenuContext","React","Menu","children","onItemSelect","props","state","Ariakit","focusLoop","gutter","shift","handleItemSelect","value","Provider","MenuButton","polymorphicComponent","ref","exceptionallySetClassName","className","classNames","MenuList","visible","Portal","preserveTabOrder","MenuItem","onSelect","hideOnSelect","onClick","as","hide","handleClick","event","onSelectResult","defaultPrevented","undefined","shouldClose","hideOnClick","SubMenu","parentMenuItemSelect","parent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