@uva-glass/component-library 2.7.1 → 3.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/{SelectListbox.module-DX1IVM9E.js → SelectListbox.module-BD2qbcmZ.js} +21 -21
- package/dist/SelectListbox.module-BD2qbcmZ.js.map +1 -0
- package/dist/{TablePlugin-C_QKVXSo.js → TablePlugin-CPEwD-wi.js} +2 -2
- package/dist/TablePlugin-CPEwD-wi.js.map +1 -0
- package/dist/assets/SelectListbox.css +1 -1
- package/dist/components/ActionList/ActionList.js +15 -5
- package/dist/components/ActionList/ActionList.js.map +1 -1
- package/dist/components/Buttons/Button.stories.js +1 -1
- package/dist/components/Buttons/LinkButton.stories.js +1 -1
- package/dist/components/Buttons/MenuButton.stories.js +1 -1
- package/dist/components/Checkbox/Checkbox.stories.js +1 -1
- package/dist/components/CheckboxButton/CheckboxButton.stories.js +1 -1
- package/dist/components/CheckboxButtonBar/CheckboxButtonBar.stories.js +1 -1
- package/dist/components/CheckboxTree/CheckboxTree.js +1 -1
- package/dist/components/CheckboxTree/CheckboxTree.js.map +1 -1
- package/dist/components/CheckboxTree/CheckboxTree.stories.js +10 -10
- package/dist/components/Chip/Chip.stories.js +1 -1
- package/dist/components/Drawer/Drawer.stories.js +1 -1
- package/dist/components/FormInput/FormInput.js +1 -1
- package/dist/components/FormInput/FormInput.stories.js +1 -1
- package/dist/components/IconButton/IconButton.stories.js +1 -1
- package/dist/components/InputField/InputField.stories.js +2 -2
- package/dist/components/ModalDialog/ModalDialog.stories.js +1 -1
- package/dist/components/MultiSelect/MultiSelect.js +1 -1
- package/dist/components/MultiSelect/MultiSelect.stories.js +2 -2
- package/dist/components/MultiSelect/components/MultiSelectHeader.js +1 -1
- package/dist/components/MultiSelect/index.js +1 -1
- package/dist/components/OverlayCloseButton/OverlayCloseButton.stories.js +1 -1
- package/dist/components/OverlayStepBar/OverlayStepBar.js +1 -1
- package/dist/components/PeriodSelector/PeriodSelector.js +1 -1
- package/dist/components/PeriodSelector/PeriodSelector.stories.js +1 -1
- package/dist/components/ProgrammeCard/ProgrammeCard.stories.js +2 -2
- package/dist/components/RteEditor/EditorHeader/EditorHeader.js +1 -1
- package/dist/components/RteEditor/Plugins/BlockFormatPlugin/BlockFormatPlugin.d.ts +1 -0
- package/dist/components/RteEditor/Plugins/BlockFormatPlugin/BlockFormatPlugin.js.map +1 -1
- package/dist/components/RteEditor/Plugins/HistoryPlugin/HistoryPlugin.js +1 -1
- package/dist/components/RteEditor/Plugins/LinkPlugin/AddLinkForm/AddLinkFrom.js +1 -1
- package/dist/components/RteEditor/Plugins/LinkPlugin/LinkPlugin.js +2 -2
- package/dist/components/RteEditor/Plugins/LinkPlugin/LinkPlugin.js.map +1 -1
- package/dist/components/RteEditor/Plugins/TablePlugin/AddTableFrom.js +1 -1
- package/dist/components/RteEditor/Plugins/TablePlugin/TablePlugin.js +1 -1
- package/dist/components/RteEditor/Plugins/TablePlugin/index.js +1 -1
- package/dist/components/RteEditor/Plugins/ToolbarPlugin/ToolbarPlugin.d.ts +1 -0
- package/dist/components/RteEditor/Plugins/ToolbarPlugin/ToolbarPlugin.js +1 -1
- package/dist/components/RteEditor/Plugins/ToolbarPlugin/ToolbarPlugin.js.map +1 -1
- package/dist/components/RteEditor/Plugins/index.js +1 -1
- package/dist/components/RteEditor/RteEditor.js +1 -1
- package/dist/components/RteEditor/hooks/components/Flyout.js.map +1 -1
- package/dist/components/RteEditor/hooks/useFlyout.js.map +1 -1
- package/dist/components/SelectListbox/SelectListBox.stories.js +1 -1
- package/dist/components/SelectListbox/SelectListbox.d.ts +2 -1
- package/dist/components/SelectListbox/SelectListbox.js +36 -39
- package/dist/components/SelectListbox/SelectListbox.js.map +1 -1
- package/dist/components/SelectListbox/components/SelectButton.js +1 -1
- package/dist/components/SelectListbox/components/SelectContainer.js +1 -1
- package/dist/components/SelectListbox/components/SelectOption.d.ts +1 -1
- package/dist/components/SelectListbox/components/SelectOption.js +1 -1
- package/dist/components/SelectListbox/components/SelectOption.js.map +1 -1
- package/dist/components/SelectListbox/components/SelectOptionBox.js +1 -1
- package/dist/components/Sortable/Sortable.stories.js +1 -1
- package/dist/components/ToggleSwitch/ToggleSwitch.stories.js +1 -1
- package/dist/components/hooks/useDebounce.js +5 -5
- package/dist/components/hooks/useDebounce.js.map +1 -1
- package/dist/components/index.js +1 -1
- package/dist/index-Sh2oo6_C.js +23304 -0
- package/dist/index-Sh2oo6_C.js.map +1 -0
- package/dist/index.js +1 -1
- package/dist/storybook__react.d.js +603 -561
- package/dist/storybook__react.d.js.map +1 -1
- package/package.json +29 -33
- package/dist/SelectListbox.module-DX1IVM9E.js.map +0 -1
- package/dist/TablePlugin-C_QKVXSo.js.map +0 -1
- package/dist/index-CHX1d9_A.js +0 -21922
- package/dist/index-CHX1d9_A.js.map +0 -1
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { jsxs as e, jsx as r } from "react/jsx-runtime";
|
|
2
|
-
import { f as a } from "../../index-
|
|
2
|
+
import { f as a } from "../../index-Sh2oo6_C.js";
|
|
3
3
|
import { ProgrammeCard as o } from "./ProgrammeCard.js";
|
|
4
4
|
import { Container as n } from "../../storyComponents/Container/Container.js";
|
|
5
5
|
import "react";
|
|
@@ -17,7 +17,7 @@ import "../IconButton/IconButton.js";
|
|
|
17
17
|
import "../Input/Input.js";
|
|
18
18
|
import "../InputField/InputField.js";
|
|
19
19
|
import "react-router";
|
|
20
|
-
import "../../TablePlugin-
|
|
20
|
+
import "../../TablePlugin-CPEwD-wi.js";
|
|
21
21
|
import { Repeater as i } from "../Repeater/Repeater.js";
|
|
22
22
|
import "../RteEditor/Providers/LanguageProvider.js";
|
|
23
23
|
import "../RteEditor/Plugins/LinkPlugin/LinkContextMenu/LinkContextMenu.js";
|
|
@@ -14,7 +14,7 @@ import "../../IconButton/IconButton.js";
|
|
|
14
14
|
import "../../Input/Input.js";
|
|
15
15
|
import "../../InputField/InputField.js";
|
|
16
16
|
import "react-router";
|
|
17
|
-
import "../../../TablePlugin-
|
|
17
|
+
import "../../../TablePlugin-CPEwD-wi.js";
|
|
18
18
|
import "../Providers/LanguageProvider.js";
|
|
19
19
|
import "../Plugins/LinkPlugin/LinkContextMenu/LinkContextMenu.js";
|
|
20
20
|
import "../hooks/components/Flyout.js";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"BlockFormatPlugin.js","sources":["../../../../../src/components/RteEditor/Plugins/BlockFormatPlugin/BlockFormatPlugin.tsx"],"sourcesContent":["import { useLexicalComposerContext } from '@lexical/react/LexicalComposerContext';\nimport clsx from 'clsx';\nimport { $getSelection, $isRangeSelection, FORMAT_TEXT_COMMAND } from 'lexical';\nimport { useEffect, useState } from 'react';\n\nimport { Icon } from 'components/Icon';\nimport styles from 'components/RteEditor/RteEditor.module.css';\nimport { useTranslation } from 'components/RteEditor/hooks/useTranslation';\n\ntype BlockTypesType = 'bold' | 'italic';\nconst BLOCK_TYPE_ICONS = {\n bold: 'Bold',\n italic: 'Italic',\n};\n\nconst BlockTypes = ['bold', 'italic'];\n\nexport const BlockFormatPlugin = (): JSX.Element => {\n const t = useTranslation();\n const [editor] = useLexicalComposerContext();\n const [isBold, setIsBold] = useState(false);\n const [isItalic, setIsItalic] = useState(false);\n\n const onClick = (type: BlockTypesType): void => {\n editor.dispatchCommand(FORMAT_TEXT_COMMAND, type);\n };\n\n useEffect(() => {\n const removeStatusListener = editor.registerUpdateListener(({ editorState }) => {\n editorState.read(() => {\n const selection = $getSelection();\n if ($isRangeSelection(selection)) {\n setIsBold(selection.hasFormat('bold'));\n setIsItalic(selection.hasFormat('italic'));\n }\n });\n });\n\n return () => {\n removeStatusListener();\n };\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [editor]);\n\n return (\n <div className={styles['editor__toolbar-button-group']}>\n {BlockTypes.map((type) => (\n <button\n onClick={() => onClick(type as BlockTypesType)}\n key={type}\n title={type === 'bold' ? t.format.boldTooltip : t.format.italicTooltip}\n className={clsx(\n styles['editor__toolbar-button'],\n styles[`editor__toolbar-button--${type}`],\n type === 'bold' && isBold && styles['editor__toolbar-button--active'],\n type === 'italic' && isItalic && styles['editor__toolbar-button--active']\n )}\n aria-label={`${type === 'bold' ? t.aria.labels.bold : t.aria.labels.italic}`}\n aria-keyshortcuts={`${type === 'bold' ? t.aria.keyshortcuts.bold : t.aria.keyshortcuts.italic}`}\n type=\"button\"\n >\n <Icon name={BLOCK_TYPE_ICONS[type as keyof typeof Icon]} size={24} />\n </button>\n ))}\n </div>\n );\n};\n"],"names":["BLOCK_TYPE_ICONS","BlockTypes","BlockFormatPlugin","useTranslation","editor","useLexicalComposerContext","isBold","setIsBold","useState","isItalic","setIsItalic","onClick","type","FORMAT_TEXT_COMMAND","useEffect","removeStatusListener","editorState","selection","$getSelection","$isRangeSelection","jsx","styles","clsx","Icon"],"mappings":";;;;;;;;
|
|
1
|
+
{"version":3,"file":"BlockFormatPlugin.js","sources":["../../../../../src/components/RteEditor/Plugins/BlockFormatPlugin/BlockFormatPlugin.tsx"],"sourcesContent":["import { useLexicalComposerContext } from '@lexical/react/LexicalComposerContext';\nimport clsx from 'clsx';\nimport { $getSelection, $isRangeSelection, FORMAT_TEXT_COMMAND } from 'lexical';\nimport { useEffect, useState } from 'react';\n\nimport type { JSX } from 'react';\n\nimport { Icon } from 'components/Icon';\nimport styles from 'components/RteEditor/RteEditor.module.css';\nimport { useTranslation } from 'components/RteEditor/hooks/useTranslation';\n\ntype BlockTypesType = 'bold' | 'italic';\nconst BLOCK_TYPE_ICONS = {\n bold: 'Bold',\n italic: 'Italic',\n};\n\nconst BlockTypes = ['bold', 'italic'];\n\nexport const BlockFormatPlugin = (): JSX.Element => {\n const t = useTranslation();\n const [editor] = useLexicalComposerContext();\n const [isBold, setIsBold] = useState(false);\n const [isItalic, setIsItalic] = useState(false);\n\n const onClick = (type: BlockTypesType): void => {\n editor.dispatchCommand(FORMAT_TEXT_COMMAND, type);\n };\n\n useEffect(() => {\n const removeStatusListener = editor.registerUpdateListener(({ editorState }) => {\n editorState.read(() => {\n const selection = $getSelection();\n if ($isRangeSelection(selection)) {\n setIsBold(selection.hasFormat('bold'));\n setIsItalic(selection.hasFormat('italic'));\n }\n });\n });\n\n return () => {\n removeStatusListener();\n };\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [editor]);\n\n return (\n <div className={styles['editor__toolbar-button-group']}>\n {BlockTypes.map((type) => (\n <button\n onClick={() => onClick(type as BlockTypesType)}\n key={type}\n title={type === 'bold' ? t.format.boldTooltip : t.format.italicTooltip}\n className={clsx(\n styles['editor__toolbar-button'],\n styles[`editor__toolbar-button--${type}`],\n type === 'bold' && isBold && styles['editor__toolbar-button--active'],\n type === 'italic' && isItalic && styles['editor__toolbar-button--active']\n )}\n aria-label={`${type === 'bold' ? t.aria.labels.bold : t.aria.labels.italic}`}\n aria-keyshortcuts={`${type === 'bold' ? t.aria.keyshortcuts.bold : t.aria.keyshortcuts.italic}`}\n type=\"button\"\n >\n <Icon name={BLOCK_TYPE_ICONS[type as keyof typeof Icon]} size={24} />\n </button>\n ))}\n </div>\n );\n};\n"],"names":["BLOCK_TYPE_ICONS","BlockTypes","BlockFormatPlugin","useTranslation","editor","useLexicalComposerContext","isBold","setIsBold","useState","isItalic","setIsItalic","onClick","type","FORMAT_TEXT_COMMAND","useEffect","removeStatusListener","editorState","selection","$getSelection","$isRangeSelection","jsx","styles","clsx","Icon"],"mappings":";;;;;;;;AAYA,MAAMA,IAAmB;AAAA,EACvB,MAAM;AAAA,EACN,QAAQ;AACV,GAEMC,IAAa,CAAC,QAAQ,QAAQ,GAEvBC,IAAoB,MAAmB;AAClD,QAAM,IAAIC,EAAe,GACnB,CAACC,CAAM,IAAIC,EAA0B,GACrC,CAACC,GAAQC,CAAS,IAAIC,EAAS,EAAK,GACpC,CAACC,GAAUC,CAAW,IAAIF,EAAS,EAAK,GAExCG,IAAU,CAACC,MAA+B;AACvC,IAAAR,EAAA,gBAAgBS,GAAqBD,CAA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Field/InputField.js";
|
|
19
19
|
import "react-router";
|
|
20
|
-
import "../../../../TablePlugin-
|
|
20
|
+
import "../../../../TablePlugin-CPEwD-wi.js";
|
|
21
21
|
import { s as r } from "../../../../RteEditor.module-oFMKEW6f.js";
|
|
22
22
|
import { useTranslation as g } from "../../hooks/useTranslation.js";
|
|
23
23
|
import "../LinkPlugin/LinkContextMenu/LinkContextMenu.js";
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import "react/jsx-runtime";
|
|
2
2
|
import "react";
|
|
3
|
-
import { A as D } from "../../../../../TablePlugin-
|
|
3
|
+
import { A as D } from "../../../../../TablePlugin-CPEwD-wi.js";
|
|
4
4
|
import "../../../../../helpers-C_Mib4v3.js";
|
|
5
5
|
import "../../../../Icon/Icon.js";
|
|
6
6
|
import "../../../../Buttons/Button.js";
|
|
@@ -4,7 +4,7 @@ import { c as q } from "../../../../clsx-OuTLNxxd.js";
|
|
|
4
4
|
import { m as z, x as G, N as J } from "../../../../LexicalLink.prod-D8-zZW0o.js";
|
|
5
5
|
import { useRef as a, useState as Q, useEffect as m } from "react";
|
|
6
6
|
import { t as X, H as f, a8 as Z, a7 as tt, a as w, f as et, M as ot, b as rt } from "../../../../Lexical.prod-CQl7J8uU.js";
|
|
7
|
-
import { A as nt } from "../../../../TablePlugin-
|
|
7
|
+
import { A as nt } from "../../../../TablePlugin-CPEwD-wi.js";
|
|
8
8
|
import { e as it } from "../../../../helpers-C_Mib4v3.js";
|
|
9
9
|
import { LinkContextMenu as st } from "./LinkContextMenu/LinkContextMenu.js";
|
|
10
10
|
import { useFlyout as ct } from "../../hooks/useFlyout.js";
|
|
@@ -52,7 +52,7 @@ const mt = 200, M = (p) => {
|
|
|
52
52
|
}
|
|
53
53
|
return !1;
|
|
54
54
|
}, Wt = ({ parentScrollPosition: p }) => {
|
|
55
|
-
const n = ut(), [c] = $(), { flyout: I, showFlyout: E, hideFlyout: C, isVisible: u } = ct(), d = a(), N = a(!1), y = a(""), g = a(""), [L, U] = Q({ active: !1, url: "", linktext: "" }), P = a(u), x = a(null), S = a(null), T = a(), b = () => {
|
|
55
|
+
const n = ut(), [c] = $(), { flyout: I, showFlyout: E, hideFlyout: C, isVisible: u } = ct(), d = a(void 0), N = a(!1), y = a(""), g = a(""), [L, U] = Q({ active: !1, url: "", linktext: "" }), P = a(u), x = a(null), S = a(null), T = a(void 0), b = () => {
|
|
56
56
|
c.update(() => {
|
|
57
57
|
const e = f();
|
|
58
58
|
x.current = e;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"LinkPlugin.js","sources":["../../../../../src/components/RteEditor/Plugins/LinkPlugin/LinkPlugin.tsx"],"sourcesContent":["import { useLexicalComposerContext } from '@lexical/react/LexicalComposerContext';\nimport clsx from 'clsx';\nimport { $isLinkNode, $toggleLink, TOGGLE_LINK_COMMAND } from '@lexical/link';\nimport { useEffect, useRef, useState } from 'react';\nimport {\n $createTextNode,\n $getSelection,\n $isRangeSelection,\n $setSelection,\n CLICK_COMMAND,\n COMMAND_PRIORITY_EDITOR,\n KEY_DOWN_COMMAND,\n SELECTION_CHANGE_COMMAND,\n} from 'lexical';\n\nimport type { LinkNode } from '@lexical/link';\nimport type { ElementNode, TextNode, BaseSelection } from 'lexical';\nimport type { addLinkFormMethods } from './AddLinkForm/AddLinkFrom';\nimport type { linkFormMethods } from './LinkContextMenu/LinkContextMenu';\n\nimport { AddLinkForm } from './AddLinkForm/AddLinkFrom';\nimport { ensureHttps } from './helpers';\nimport { LinkContextMenu } from './LinkContextMenu/LinkContextMenu';\n\nimport { useFlyout } from 'components/RteEditor/hooks/useFlyout';\nimport { Icon } from 'components';\nimport styles from 'components/RteEditor/RteEditor.module.css';\nimport { useTranslation } from 'components/RteEditor/hooks/useTranslation';\nimport { removeScrollableContainers, setScrollableContainers } from 'components/RteEditor/helpers';\n\nconst PREVENT_OPEN_DELAY = 200;\n\nexport interface LinkType {\n active: boolean;\n url: string;\n linktext: string;\n}\n\ntype Position = {\n top: number;\n left: number;\n};\n\ninterface LinkPluginProps {\n parentScrollPosition: number;\n}\n\nconst getLinkNode = (node: ElementNode | null): ElementNode | null => {\n let currentNode: TextNode | ElementNode | null = node;\n\n while (currentNode) {\n if ($isLinkNode(currentNode)) {\n return currentNode;\n }\n currentNode = currentNode.getParent();\n }\n\n return null;\n};\n\nexport const getLinkNodeTag = (anchorNode: ElementNode | TextNode): boolean | LinkType => {\n let currentNode: TextNode | ElementNode | null = anchorNode;\n\n while (currentNode) {\n if ($isLinkNode(currentNode)) {\n return {\n active: true,\n url: currentNode.getURL(),\n linktext: currentNode.getTextContent(),\n };\n }\n currentNode = currentNode.getParent();\n }\n\n return false;\n};\n\nexport const LinkPlugin = ({ parentScrollPosition }: LinkPluginProps) => {\n const t = useTranslation();\n const [editor] = useLexicalComposerContext();\n const { flyout, showFlyout, hideFlyout, isVisible } = useFlyout();\n const addLinkForm = useRef<addLinkFormMethods>();\n const preventOpen = useRef(false);\n const previousLinkText = useRef('');\n const selectedText = useRef('');\n const [isLink, setIsLink] = useState<LinkType>({ active: false, url: '', linktext: '' });\n const isVisibleRef = useRef(isVisible);\n const storedSelection = useRef<BaseSelection | null>(null);\n const linkButtonRef = useRef<HTMLButtonElement>(null);\n const editLinkForm = useRef<linkFormMethods>();\n\n const storeCursorPosition = () => {\n editor.update(() => {\n const selection = $getSelection();\n storedSelection.current = selection;\n });\n };\n\n const rePositionCursor = () => {\n editor.update(() => {\n if (storedSelection.current) {\n $setSelection(storedSelection.current);\n }\n });\n };\n\n const openContextMenu = (url: string, position: Position) => {\n showFlyout({\n position,\n children: (\n <LinkContextMenu\n url={url}\n onSave={(url) => insertLink(url, '')}\n onDelete={() => removeLink()}\n onClose={closeContextMenu}\n ref={editLinkForm}\n />\n ),\n });\n };\n\n const closeContextMenu = () => {\n editLinkForm.current?.clearForm();\n hideFlyout();\n rePositionCursor();\n };\n\n const openFlyout = () => {\n const rect = linkButtonRef.current?.getBoundingClientRect();\n if (!preventOpen.current && rect) {\n storeCursorPosition();\n showFlyout({ position: { top: rect.bottom, left: rect.left }, ...flyoutOptions });\n setTimeout(() => addLinkForm.current?.setDefaults('', selectedText.current), 0);\n }\n };\n\n const closeFlyout = () => {\n hideFlyout();\n rePositionCursor();\n };\n\n const insertLink = (url: string, linktext: string) => {\n editor.update(() => {\n const selection = $getSelection();\n\n if ($isRangeSelection(selection)) {\n const anchor = selection.anchor;\n const node = anchor.getNode() as ElementNode;\n const linkNode = getLinkNode(node);\n if (linktext && linktext !== '') {\n if (linkNode) {\n const newTextNode = $createTextNode(linktext);\n linkNode.replace(newTextNode);\n newTextNode.select();\n }\n if (linktext !== previousLinkText.current && previousLinkText.current === '') {\n const { anchor, focus } = selection;\n selection.insertText(linktext);\n anchor.offset -= linktext.length;\n focus.offset = anchor.offset + linktext.length;\n }\n }\n $toggleLink(ensureHttps(url), { target: '_blank' });\n }\n\n closeFlyout();\n });\n };\n\n const removeLink = (): void => {\n editor.dispatchCommand(TOGGLE_LINK_COMMAND, null);\n closeContextMenu();\n };\n\n const flyoutOptions = {\n children: (\n <AddLinkForm\n isLink={isLink}\n onCloseHandler={closeFlyout}\n onSaveHandler={(url, linktext) => insertLink(url, linktext)}\n ref={addLinkForm}\n />\n ),\n };\n\n useEffect(() => {\n if (!isVisible) {\n addLinkForm.current?.clearForm();\n previousLinkText.current = selectedText.current = '';\n setTimeout(() => (preventOpen.current = false), PREVENT_OPEN_DELAY);\n } else {\n preventOpen.current = true;\n addLinkForm.current?.focusFirstField();\n }\n }, [addLinkForm, isVisible]);\n\n useEffect(() => {\n const handleSelectionClickOrChange = (selection: BaseSelection | null) => {\n if ($isRangeSelection(selection) && selection.isCollapsed()) {\n const node = getLinkNodeTag(selection.anchor.getNode()) as LinkType;\n\n if (node) {\n const domNode = editor.getElementByKey(selection.anchor.getNode().getKey());\n const position = domNode\n ? { top: domNode.getBoundingClientRect().bottom, left: domNode.getBoundingClientRect().left }\n : { top: 0, left: 0 };\n openContextMenu(node.url, position);\n return true;\n }\n }\n return false;\n };\n\n const unregisterSelect = editor.registerCommand(\n SELECTION_CHANGE_COMMAND,\n () => {\n const selection = $getSelection();\n selectedText.current = selection?.getTextContent() ?? '';\n handleSelectionClickOrChange(selection);\n return false;\n },\n 0\n );\n\n const unregisterClick = editor.registerCommand(\n CLICK_COMMAND,\n (event) => {\n const selection = $getSelection();\n storeCursorPosition();\n event.preventDefault();\n event.stopPropagation();\n event.stopImmediatePropagation();\n handleSelectionClickOrChange(selection);\n return false;\n },\n 0\n );\n\n return () => {\n unregisterClick();\n unregisterSelect();\n };\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [editor]);\n\n useEffect(() => {\n const removeKeyboardShortcut = editor.registerCommand(\n KEY_DOWN_COMMAND,\n (event: KeyboardEvent) => {\n if (event.ctrlKey && event.shiftKey && event.key === 'U') {\n const selection = $getSelection();\n storeCursorPosition();\n\n if (!$isRangeSelection(selection)) {\n return false;\n }\n\n const node = getLinkNodeTag(selection.anchor.getNode()) as LinkType;\n\n const openFlyoutWithDefaults = (url = '', linkText = '') => {\n openFlyout();\n setTimeout(() => addLinkForm.current?.setDefaults(url, linkText), 0);\n };\n\n if (node) {\n event.preventDefault();\n event.stopPropagation();\n event.stopImmediatePropagation();\n\n previousLinkText.current = node.linktext;\n openFlyoutWithDefaults(node.url, node.linktext);\n\n return true;\n }\n\n const selectedTextContent = selection.getTextContent();\n if (selectedTextContent !== '') {\n selectedText.current = selectedTextContent;\n openFlyoutWithDefaults('', selectedText.current);\n\n return true;\n }\n\n openFlyout();\n return true;\n }\n\n return false;\n },\n COMMAND_PRIORITY_EDITOR\n );\n\n const removeStatusListener = editor.registerUpdateListener(({ editorState }) => {\n setIsLink(\n editorState.read(() => {\n const selection = $getSelection();\n storeCursorPosition();\n\n if ($isRangeSelection(selection)) {\n const anchorNode = selection.anchor.getNode() as ElementNode;\n const linkNode = getLinkNode(anchorNode) as LinkNode;\n\n if (linkNode) {\n return {\n active: true,\n url: linkNode.getURL(),\n linktext: linkNode.getTextContent(),\n };\n }\n }\n\n return {\n active: false,\n url: '',\n linktext: '',\n };\n })\n );\n });\n\n return () => {\n removeKeyboardShortcut();\n removeStatusListener();\n };\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [editor]);\n\n useEffect(() => {\n isVisibleRef.current = isVisible;\n if (!isVisible) editLinkForm.current?.clearForm();\n }, [isVisible]);\n\n useEffect(() => {\n if (isVisible) {\n closeFlyout();\n }\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [parentScrollPosition]);\n\n useEffect(() => {\n if (!isLink.active) {\n hideFlyout();\n }\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [isLink]);\n\n useEffect(() => {\n const removeKeydown = (event: KeyboardEvent): boolean => {\n setScrollableContainers(handleResizeScroll);\n\n if (event.key === 'Escape' && isVisibleRef.current) {\n event.preventDefault();\n event.stopPropagation();\n closeFlyout();\n }\n return true;\n };\n\n window.addEventListener('keydown', removeKeydown, { capture: true });\n\n const handleResizeScroll = () => {\n hideFlyout();\n };\n\n setScrollableContainers(handleResizeScroll);\n\n window.addEventListener('scroll', handleResizeScroll);\n window.addEventListener('resize', handleResizeScroll);\n\n return () => {\n window.removeEventListener('keydown', removeKeydown);\n window.removeEventListener('scroll', handleResizeScroll);\n window.removeEventListener('resize', handleResizeScroll);\n removeScrollableContainers(handleResizeScroll);\n };\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, []);\n\n return (\n <div className={styles['editor__toolbar-button-group']}>\n <div className={styles['editor__toolbar-button-flyoutwrapper']}>\n <button\n onClick={openFlyout}\n title={t.links.linkTooltip}\n className={clsx(\n styles['editor__toolbar-button'],\n styles[`editor__toolbar-button--link`],\n isLink.active && styles['editor__toolbar-button--active']\n )}\n aria-label={t.aria.labels.link}\n aria-keyshortcuts={t.aria.keyshortcuts.link}\n type=\"button\"\n ref={linkButtonRef}\n >\n <Icon name=\"Link\" size={20} />\n </button>\n {flyout}\n </div>\n </div>\n );\n};\n"],"names":["PREVENT_OPEN_DELAY","getLinkNode","node","currentNode","$isLinkNode","getLinkNodeTag","anchorNode","LinkPlugin","parentScrollPosition","t","useTranslation","editor","useLexicalComposerContext","flyout","showFlyout","hideFlyout","isVisible","useFlyout","addLinkForm","useRef","preventOpen","previousLinkText","selectedText","isLink","setIsLink","useState","isVisibleRef","storedSelection","linkButtonRef","editLinkForm","storeCursorPosition","selection","$getSelection","rePositionCursor","$setSelection","openContextMenu","url","position","jsx","LinkContextMenu","insertLink","removeLink","closeContextMenu","_a","openFlyout","rect","flyoutOptions","closeFlyout","linktext","$isRangeSelection","linkNode","newTextNode","$createTextNode","anchor","focus","$toggleLink","ensureHttps","TOGGLE_LINK_COMMAND","AddLinkForm","useEffect","_b","handleSelectionClickOrChange","domNode","unregisterSelect","SELECTION_CHANGE_COMMAND","unregisterClick","CLICK_COMMAND","event","removeKeyboardShortcut","KEY_DOWN_COMMAND","openFlyoutWithDefaults","linkText","selectedTextContent","COMMAND_PRIORITY_EDITOR","removeStatusListener","editorState","removeKeydown","setScrollableContainers","handleResizeScroll","removeScrollableContainers","styles","jsxs","clsx","Icon"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA8BA,MAAMA,KAAqB,KAiBrBC,IAAc,CAACC,MAAiD;AACpE,MAAIC,IAA6CD;AAEjD,SAAOC,KAAa;AACd,QAAAC,EAAYD,CAAW;AAClB,aAAAA;AAET,IAAAA,IAAcA,EAAY,UAAU;AAAA,EAAA;AAG/B,SAAA;AACT,GAEaE,IAAiB,CAACC,MAA2D;AACxF,MAAIH,IAA6CG;AAEjD,SAAOH,KAAa;AACd,QAAAC,EAAYD,CAAW;AAClB,aAAA;AAAA,QACL,QAAQ;AAAA,QACR,KAAKA,EAAY,OAAO;AAAA,QACxB,UAAUA,EAAY,eAAe;AAAA,MACvC;AAEF,IAAAA,IAAcA,EAAY,UAAU;AAAA,EAAA;AAG/B,SAAA;AACT,GAEaI,KAAa,CAAC,EAAE,sBAAAC,QAA4C;AACvE,QAAMC,IA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GAAG,EAAE,GAGH,gBAAAxC,EAAC,OAAI,EAAA,WAAW0C,EAAO,8BAA8B,GACnD,UAAA,gBAAAC,EAAC,OAAI,EAAA,WAAWD,EAAO,sCAAsC,GAC3D,UAAA;AAAA,IAAA,gBAAA1C;AAAA,MAAC;AAAA,MAAA;AAAA,QACC,SAASM;AAAA,QACT,OAAOnC,EAAE,MAAM;AAAA,QACf,WAAWyE;AAAA,UACTF,EAAO,wBAAwB;AAAA,UAC/BA,EAAO,8BAA8B;AAAA,UACrCzD,EAAO,UAAUyD,EAAO,gCAAgC;AAAA,QAC1D;AAAA,QACA,cAAYvE,EAAE,KAAK,OAAO;AAAA,QAC1B,qBAAmBA,EAAE,KAAK,aAAa;AAAA,QACvC,MAAK;AAAA,QACL,KAAKmB;AAAA,QAEL,UAAC,gBAAAU,EAAA6C,IAAA,EAAK,MAAK,QAAO,MAAM,GAAI,CAAA;AAAA,MAAA;AAAA,IAC9B;AAAA,IACCtE;AAAA,EAAA,EAAA,CACH,EACF,CAAA;AAEJ;"}
|
|
1
|
+
{"version":3,"file":"LinkPlugin.js","sources":["../../../../../src/components/RteEditor/Plugins/LinkPlugin/LinkPlugin.tsx"],"sourcesContent":["import { useLexicalComposerContext } from '@lexical/react/LexicalComposerContext';\nimport clsx from 'clsx';\nimport { $isLinkNode, $toggleLink, TOGGLE_LINK_COMMAND } from '@lexical/link';\nimport { useEffect, useRef, useState } from 'react';\nimport {\n $createTextNode,\n $getSelection,\n $isRangeSelection,\n $setSelection,\n CLICK_COMMAND,\n COMMAND_PRIORITY_EDITOR,\n KEY_DOWN_COMMAND,\n SELECTION_CHANGE_COMMAND,\n} from 'lexical';\n\nimport type { LinkNode } from '@lexical/link';\nimport type { ElementNode, TextNode, BaseSelection } from 'lexical';\nimport type { addLinkFormMethods } from './AddLinkForm/AddLinkFrom';\nimport type { linkFormMethods } from './LinkContextMenu/LinkContextMenu';\n\nimport { AddLinkForm } from './AddLinkForm/AddLinkFrom';\nimport { ensureHttps } from './helpers';\nimport { LinkContextMenu } from './LinkContextMenu/LinkContextMenu';\n\nimport { useFlyout } from 'components/RteEditor/hooks/useFlyout';\nimport { Icon } from 'components';\nimport styles from 'components/RteEditor/RteEditor.module.css';\nimport { useTranslation } from 'components/RteEditor/hooks/useTranslation';\nimport { removeScrollableContainers, setScrollableContainers } from 'components/RteEditor/helpers';\n\nconst PREVENT_OPEN_DELAY = 200;\n\nexport interface LinkType {\n active: boolean;\n url: string;\n linktext: string;\n}\n\ntype Position = {\n top: number;\n left: number;\n};\n\ninterface LinkPluginProps {\n parentScrollPosition: number;\n}\n\nconst getLinkNode = (node: ElementNode | null): ElementNode | null => {\n let currentNode: TextNode | ElementNode | null = node;\n\n while (currentNode) {\n if ($isLinkNode(currentNode)) {\n return currentNode;\n }\n currentNode = currentNode.getParent();\n }\n\n return null;\n};\n\nexport const getLinkNodeTag = (anchorNode: ElementNode | TextNode): boolean | LinkType => {\n let currentNode: TextNode | ElementNode | null = anchorNode;\n\n while (currentNode) {\n if ($isLinkNode(currentNode)) {\n return {\n active: true,\n url: currentNode.getURL(),\n linktext: currentNode.getTextContent(),\n };\n }\n currentNode = currentNode.getParent();\n }\n\n return false;\n};\n\nexport const LinkPlugin = ({ parentScrollPosition }: LinkPluginProps) => {\n const t = useTranslation();\n const [editor] = useLexicalComposerContext();\n const { flyout, showFlyout, hideFlyout, isVisible } = useFlyout();\n const addLinkForm = useRef<addLinkFormMethods>(undefined);\n const preventOpen = useRef(false);\n const previousLinkText = useRef('');\n const selectedText = useRef('');\n const [isLink, setIsLink] = useState<LinkType>({ active: false, url: '', linktext: '' });\n const isVisibleRef = useRef(isVisible);\n const storedSelection = useRef<BaseSelection | null>(null);\n const linkButtonRef = useRef<HTMLButtonElement>(null);\n const editLinkForm = useRef<linkFormMethods>(undefined);\n\n const storeCursorPosition = () => {\n editor.update(() => {\n const selection = $getSelection();\n storedSelection.current = selection;\n });\n };\n\n const rePositionCursor = () => {\n editor.update(() => {\n if (storedSelection.current) {\n $setSelection(storedSelection.current);\n }\n });\n };\n\n const openContextMenu = (url: string, position: Position) => {\n showFlyout({\n position,\n children: (\n <LinkContextMenu\n url={url}\n onSave={(url) => insertLink(url, '')}\n onDelete={() => removeLink()}\n onClose={closeContextMenu}\n ref={editLinkForm}\n />\n ),\n });\n };\n\n const closeContextMenu = () => {\n editLinkForm.current?.clearForm();\n hideFlyout();\n rePositionCursor();\n };\n\n const openFlyout = () => {\n const rect = linkButtonRef.current?.getBoundingClientRect();\n if (!preventOpen.current && rect) {\n storeCursorPosition();\n showFlyout({ position: { top: rect.bottom, left: rect.left }, ...flyoutOptions });\n setTimeout(() => addLinkForm.current?.setDefaults('', selectedText.current), 0);\n }\n };\n\n const closeFlyout = () => {\n hideFlyout();\n rePositionCursor();\n };\n\n const insertLink = (url: string, linktext: string) => {\n editor.update(() => {\n const selection = $getSelection();\n\n if ($isRangeSelection(selection)) {\n const anchor = selection.anchor;\n const node = anchor.getNode() as ElementNode;\n const linkNode = getLinkNode(node);\n if (linktext && linktext !== '') {\n if (linkNode) {\n const newTextNode = $createTextNode(linktext);\n linkNode.replace(newTextNode);\n newTextNode.select();\n }\n if (linktext !== previousLinkText.current && previousLinkText.current === '') {\n const { anchor, focus } = selection;\n selection.insertText(linktext);\n anchor.offset -= linktext.length;\n focus.offset = anchor.offset + linktext.length;\n }\n }\n $toggleLink(ensureHttps(url), { target: '_blank' });\n }\n\n closeFlyout();\n });\n };\n\n const removeLink = (): void => {\n editor.dispatchCommand(TOGGLE_LINK_COMMAND, null);\n closeContextMenu();\n };\n\n const flyoutOptions = {\n children: (\n <AddLinkForm\n isLink={isLink}\n onCloseHandler={closeFlyout}\n onSaveHandler={(url, linktext) => insertLink(url, linktext)}\n ref={addLinkForm}\n />\n ),\n };\n\n useEffect(() => {\n if (!isVisible) {\n addLinkForm.current?.clearForm();\n previousLinkText.current = selectedText.current = '';\n setTimeout(() => (preventOpen.current = false), PREVENT_OPEN_DELAY);\n } else {\n preventOpen.current = true;\n addLinkForm.current?.focusFirstField();\n }\n }, [addLinkForm, isVisible]);\n\n useEffect(() => {\n const handleSelectionClickOrChange = (selection: BaseSelection | null) => {\n if ($isRangeSelection(selection) && selection.isCollapsed()) {\n const node = getLinkNodeTag(selection.anchor.getNode()) as LinkType;\n\n if (node) {\n const domNode = editor.getElementByKey(selection.anchor.getNode().getKey());\n const position = domNode\n ? { top: domNode.getBoundingClientRect().bottom, left: domNode.getBoundingClientRect().left }\n : { top: 0, left: 0 };\n openContextMenu(node.url, position);\n return true;\n }\n }\n return false;\n };\n\n const unregisterSelect = editor.registerCommand(\n SELECTION_CHANGE_COMMAND,\n () => {\n const selection = $getSelection();\n selectedText.current = selection?.getTextContent() ?? '';\n handleSelectionClickOrChange(selection);\n return false;\n },\n 0\n );\n\n const unregisterClick = editor.registerCommand(\n CLICK_COMMAND,\n (event) => {\n const selection = $getSelection();\n storeCursorPosition();\n event.preventDefault();\n event.stopPropagation();\n event.stopImmediatePropagation();\n handleSelectionClickOrChange(selection);\n return false;\n },\n 0\n );\n\n return () => {\n unregisterClick();\n unregisterSelect();\n };\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [editor]);\n\n useEffect(() => {\n const removeKeyboardShortcut = editor.registerCommand(\n KEY_DOWN_COMMAND,\n (event: KeyboardEvent) => {\n if (event.ctrlKey && event.shiftKey && event.key === 'U') {\n const selection = $getSelection();\n storeCursorPosition();\n\n if (!$isRangeSelection(selection)) {\n return false;\n }\n\n const node = getLinkNodeTag(selection.anchor.getNode()) as LinkType;\n\n const openFlyoutWithDefaults = (url = '', linkText = '') => {\n openFlyout();\n setTimeout(() => addLinkForm.current?.setDefaults(url, linkText), 0);\n };\n\n if (node) {\n event.preventDefault();\n event.stopPropagation();\n event.stopImmediatePropagation();\n\n previousLinkText.current = node.linktext;\n openFlyoutWithDefaults(node.url, node.linktext);\n\n return true;\n }\n\n const selectedTextContent = selection.getTextContent();\n if (selectedTextContent !== '') {\n selectedText.current = selectedTextContent;\n openFlyoutWithDefaults('', selectedText.current);\n\n return true;\n }\n\n openFlyout();\n return true;\n }\n\n return false;\n },\n COMMAND_PRIORITY_EDITOR\n );\n\n const removeStatusListener = editor.registerUpdateListener(({ editorState }) => {\n setIsLink(\n editorState.read(() => {\n const selection = $getSelection();\n storeCursorPosition();\n\n if ($isRangeSelection(selection)) {\n const anchorNode = selection.anchor.getNode() as ElementNode;\n const linkNode = getLinkNode(anchorNode) as LinkNode;\n\n if (linkNode) {\n return {\n active: true,\n url: linkNode.getURL(),\n linktext: linkNode.getTextContent(),\n };\n }\n }\n\n return {\n active: false,\n url: '',\n linktext: '',\n };\n })\n );\n });\n\n return () => {\n removeKeyboardShortcut();\n removeStatusListener();\n };\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [editor]);\n\n useEffect(() => {\n isVisibleRef.current = isVisible;\n if (!isVisible) editLinkForm.current?.clearForm();\n }, [isVisible]);\n\n useEffect(() => {\n if (isVisible) {\n closeFlyout();\n }\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [parentScrollPosition]);\n\n useEffect(() => {\n if (!isLink.active) {\n hideFlyout();\n }\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [isLink]);\n\n useEffect(() => {\n const removeKeydown = (event: KeyboardEvent): boolean => {\n setScrollableContainers(handleResizeScroll);\n\n if (event.key === 'Escape' && isVisibleRef.current) {\n event.preventDefault();\n event.stopPropagation();\n closeFlyout();\n }\n return true;\n };\n\n window.addEventListener('keydown', removeKeydown, { capture: true });\n\n const handleResizeScroll = () => {\n hideFlyout();\n };\n\n setScrollableContainers(handleResizeScroll);\n\n window.addEventListener('scroll', handleResizeScroll);\n window.addEventListener('resize', handleResizeScroll);\n\n return () => {\n window.removeEventListener('keydown', removeKeydown);\n window.removeEventListener('scroll', handleResizeScroll);\n window.removeEventListener('resize', handleResizeScroll);\n removeScrollableContainers(handleResizeScroll);\n };\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, []);\n\n return (\n <div className={styles['editor__toolbar-button-group']}>\n <div className={styles['editor__toolbar-button-flyoutwrapper']}>\n <button\n onClick={openFlyout}\n title={t.links.linkTooltip}\n className={clsx(\n styles['editor__toolbar-button'],\n styles[`editor__toolbar-button--link`],\n isLink.active && styles['editor__toolbar-button--active']\n )}\n aria-label={t.aria.labels.link}\n aria-keyshortcuts={t.aria.keyshortcuts.link}\n type=\"button\"\n ref={linkButtonRef}\n >\n <Icon name=\"Link\" size={20} />\n </button>\n {flyout}\n </div>\n </div>\n );\n};\n"],"names":["PREVENT_OPEN_DELAY","getLinkNode","node","currentNode","$isLinkNode","getLinkNodeTag","anchorNode","LinkPlugin","parentScrollPosition","t","useTranslation","editor","useLexicalComposerContext","flyout","showFlyout","hideFlyout","isVisible","useFlyout","addLinkForm","useRef","preventOpen","previousLinkText","selectedText","isLink","setIsLink","useState","isVisibleRef","storedSelection","linkButtonRef","editLinkForm","storeCursorPosition","selection","$getSelection","rePositionCursor","$setSelection","openContextMenu","url","position","jsx","LinkContextMenu","insertLink","removeLink","closeContextMenu","_a","openFlyout","rect","flyoutOptions","closeFlyout","linktext","$isRangeSelection","linkNode","newTextNode","$createTextNode","anchor","focus","$toggleLink","ensureHttps","TOGGLE_LINK_COMMAND","AddLinkForm","useEffect","_b","handleSelectionClickOrChange","domNode","unregisterSelect","SELECTION_CHANGE_COMMAND","unregisterClick","CLICK_COMMAND","event","removeKeyboardShortcut","KEY_DOWN_COMMAND","openFlyoutWithDefaults","linkText","selectedTextContent","COMMAND_PRIORITY_EDITOR","removeStatusListener","editorState","removeKeydown","setScrollableContainers","handleResizeScroll","removeScrollableContainers","styles","jsxs","clsx","Icon"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA8BA,MAAMA,KAAqB,KAiBrBC,IAAc,CAACC,MAAiD;AACpE,MAAIC,IAA6CD;AAEjD,SAAOC,KAAa;AACd,QAAAC,EAAYD,CAAW;AAClB,aAAAA;AAET,IAAAA,IAAcA,EAAY,UAAU;AAAA,EAAA;AAG/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AAE,SAAS,IAAM;AAEnE,UAAME,IAAqB,MAAM;AACpB,MAAA/D,EAAA;AAAA,IACb;AAEA,WAAA8D,EAAwBC,CAAkB,GAEnC,OAAA,iBAAiB,UAAUA,CAAkB,GAC7C,OAAA,iBAAiB,UAAUA,CAAkB,GAE7C,MAAM;AACJ,aAAA,oBAAoB,WAAWF,CAAa,GAC5C,OAAA,oBAAoB,UAAUE,CAAkB,GAChD,OAAA,oBAAoB,UAAUA,CAAkB,GACvDC,GAA2BD,CAAkB;AAAA,IAC/C;AAAA,EAEF,GAAG,EAAE,GAGH,gBAAAxC,EAAC,OAAI,EAAA,WAAW0C,EAAO,8BAA8B,GACnD,UAAA,gBAAAC,EAAC,OAAI,EAAA,WAAWD,EAAO,sCAAsC,GAC3D,UAAA;AAAA,IAAA,gBAAA1C;AAAA,MAAC;AAAA,MAAA;AAAA,QACC,SAASM;AAAA,QACT,OAAOnC,EAAE,MAAM;AAAA,QACf,WAAWyE;AAAA,UACTF,EAAO,wBAAwB;AAAA,UAC/BA,EAAO,8BAA8B;AAAA,UACrCzD,EAAO,UAAUyD,EAAO,gCAAgC;AAAA,QAC1D;AAAA,QACA,cAAYvE,EAAE,KAAK,OAAO;AAAA,QAC1B,qBAAmBA,EAAE,KAAK,aAAa;AAAA,QACvC,MAAK;AAAA,QACL,KAAKmB;AAAA,QAEL,UAAC,gBAAAU,EAAA6C,IAAA,EAAK,MAAK,QAAO,MAAM,GAAI,CAAA;AAAA,MAAA;AAAA,IAC9B;AAAA,IACCtE;AAAA,EAAA,EAAA,CACH,EACF,CAAA;AAEJ;"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import "react/jsx-runtime";
|
|
2
2
|
import "react";
|
|
3
|
-
import { b as B } from "../../../../TablePlugin-
|
|
3
|
+
import { b as B } from "../../../../TablePlugin-CPEwD-wi.js";
|
|
4
4
|
import "../../../Buttons/Button.js";
|
|
5
5
|
import "../../../Buttons/LinkButton.js";
|
|
6
6
|
import "@react-aria/button";
|
|
@@ -4,7 +4,7 @@ import "../../../../clsx-OuTLNxxd.js";
|
|
|
4
4
|
import "../../../../LexicalTable.prod-BvJxbarH.js";
|
|
5
5
|
import "../../../../Lexical.prod-CQl7J8uU.js";
|
|
6
6
|
import "react";
|
|
7
|
-
import { T as F } from "../../../../TablePlugin-
|
|
7
|
+
import { T as F } from "../../../../TablePlugin-CPEwD-wi.js";
|
|
8
8
|
import "./helpers.js";
|
|
9
9
|
import "../../hooks/useFlyout.js";
|
|
10
10
|
import "../../../Icon/Icon.js";
|
|
@@ -7,7 +7,7 @@ import { BlockFormatPlugin as N } from "../BlockFormatPlugin/BlockFormatPlugin.j
|
|
|
7
7
|
import { ListPlugin as k } from "../ListPlugin/ListPlugin.js";
|
|
8
8
|
import { LinkPlugin as x } from "../LinkPlugin/LinkPlugin.js";
|
|
9
9
|
import { HistoryPlugin as B } from "../HistoryPlugin/HistoryPlugin.js";
|
|
10
|
-
import { T as S } from "../../../../TablePlugin-
|
|
10
|
+
import { T as S } from "../../../../TablePlugin-CPEwD-wi.js";
|
|
11
11
|
import { TableCellContextMenu as z } from "../TablePlugin/TableCellContextMenu/TableCellContextMenu.js";
|
|
12
12
|
import { s as A } from "../../../../RteEditor.module-oFMKEW6f.js";
|
|
13
13
|
import { setScrollableContainers as v, removeScrollableContainers as H } from "../../helpers.js";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ToolbarPlugin.js","sources":["../../../../../src/components/RteEditor/Plugins/ToolbarPlugin/ToolbarPlugin.tsx"],"sourcesContent":["import { useLexicalComposerContext } from '@lexical/react/LexicalComposerContext';\nimport { $getSelection, $isRangeSelection, $setSelection } from 'lexical';\nimport { useCallback, useEffect, useRef, useState } from 'react';\nimport { $getTableCellNodeFromLexicalNode } from '@lexical/table';\n\nimport type { Actions } from 'components/RteEditor/Plugins/TablePlugin/TableCellContextMenu/TableCellContextMenu';\nimport type { TableMutation } from 'components/RteEditor/Plugins/TablePlugin/TablePlugin';\n\nimport {\n LinkPlugin,\n BlockFormatPlugin,\n ListPlugin,\n HistoryPlugin,\n TablePlugin,\n TableCellContextMenu,\n} from 'components/RteEditor/Plugins';\nimport styles from 'components/RteEditor/RteEditor.module.css';\nimport { removeScrollableContainers, setScrollableContainers } from 'components/RteEditor/helpers';\n\nexport type Position = {\n xPos: number;\n yPos: number;\n height: number;\n};\n\ninterface ToolBarProps {\n editorScrollPosition: number;\n}\n\nexport const ToolBarPlugin = ({ editorScrollPosition }: ToolBarProps): JSX.Element => {\n const [editor] = useLexicalComposerContext();\n const [position, setPosition] = useState<Position | null>(null);\n const tableref = useRef<TableMutation>(null);\n\n const updateToolbar = useCallback(() => {\n const selection = $getSelection();\n if ($isRangeSelection(selection)) {\n const anchor = selection.anchor;\n const anchorNode = anchor.getNode();\n\n const tableCell = $getTableCellNodeFromLexicalNode(anchorNode);\n if (tableCell) {\n const domNode = editor.getElementByKey(tableCell.getKey());\n const position = domNode ? domNode.getBoundingClientRect() : { right: 0, bottom: 0, height: 0 };\n setPosition({ xPos: position.right, yPos: position.bottom, height: position.height });\n } else {\n setPosition(null);\n }\n }\n }, [editor]);\n\n const handleTableAction = (action: Actions) => {\n tableref.current?.mutateTable(action);\n };\n\n const handleResizeScroll = () => {\n editor.update(() => {\n const selection = $getSelection();\n\n if ($isRangeSelection(selection)) {\n const anchor = selection.anchor;\n const anchorNode = anchor.getNode();\n\n const tableCell = $getTableCellNodeFromLexicalNode(anchorNode);\n if (tableCell) {\n $setSelection(null);\n setPosition(null);\n }\n }\n });\n };\n\n useEffect(() => {\n editor.registerUpdateListener(({ editorState }) => {\n editorState.read(() => {\n updateToolbar();\n });\n });\n }, [editor, updateToolbar]);\n\n useEffect(() => {\n setScrollableContainers(handleResizeScroll);\n\n window.addEventListener('scroll', handleResizeScroll);\n window.addEventListener('resize', handleResizeScroll);\n\n return () => {\n window.removeEventListener('scroll', handleResizeScroll);\n window.removeEventListener('resize', handleResizeScroll);\n removeScrollableContainers(handleResizeScroll);\n };\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [editor]);\n\n useEffect(() => {\n const removeKeydown = () => {\n setScrollableContainers(handleResizeScroll);\n };\n\n window.addEventListener('keydown', removeKeydown, { capture: true });\n\n return () => {\n window.removeEventListener('keydown', removeKeydown);\n };\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, []);\n\n return (\n <div className={styles['editor__toolbar']}>\n <BlockFormatPlugin />\n <ListPlugin />\n <TablePlugin isActive={Boolean(position)} ref={tableref} />\n {position && (\n <TableCellContextMenu\n position={position}\n parentScrollPosition={editorScrollPosition}\n onAction={handleTableAction}\n />\n )}\n <LinkPlugin parentScrollPosition={editorScrollPosition} />\n <HistoryPlugin />\n </div>\n );\n};\n"],"names":["ToolBarPlugin","editorScrollPosition","editor","useLexicalComposerContext","position","setPosition","useState","tableref","useRef","updateToolbar","useCallback","selection","$getSelection","$isRangeSelection","anchorNode","tableCell","$getTableCellNodeFromLexicalNode","domNode","handleTableAction","action","_a","handleResizeScroll","$setSelection","useEffect","editorState","setScrollableContainers","removeScrollableContainers","removeKeydown","jsxs","styles","jsx","BlockFormatPlugin","ListPlugin","TablePlugin","TableCellContextMenu","LinkPlugin","HistoryPlugin"],"mappings":";;;;;;;;;;;;;
|
|
1
|
+
{"version":3,"file":"ToolbarPlugin.js","sources":["../../../../../src/components/RteEditor/Plugins/ToolbarPlugin/ToolbarPlugin.tsx"],"sourcesContent":["import { useLexicalComposerContext } from '@lexical/react/LexicalComposerContext';\nimport { $getSelection, $isRangeSelection, $setSelection } from 'lexical';\nimport { useCallback, useEffect, useRef, useState } from 'react';\nimport { $getTableCellNodeFromLexicalNode } from '@lexical/table';\n\nimport type { JSX } from 'react';\nimport type { Actions } from 'components/RteEditor/Plugins/TablePlugin/TableCellContextMenu/TableCellContextMenu';\nimport type { TableMutation } from 'components/RteEditor/Plugins/TablePlugin/TablePlugin';\n\nimport {\n LinkPlugin,\n BlockFormatPlugin,\n ListPlugin,\n HistoryPlugin,\n TablePlugin,\n TableCellContextMenu,\n} from 'components/RteEditor/Plugins';\nimport styles from 'components/RteEditor/RteEditor.module.css';\nimport { removeScrollableContainers, setScrollableContainers } from 'components/RteEditor/helpers';\n\nexport type Position = {\n xPos: number;\n yPos: number;\n height: number;\n};\n\ninterface ToolBarProps {\n editorScrollPosition: number;\n}\n\nexport const ToolBarPlugin = ({ editorScrollPosition }: ToolBarProps): JSX.Element => {\n const [editor] = useLexicalComposerContext();\n const [position, setPosition] = useState<Position | null>(null);\n const tableref = useRef<TableMutation>(null);\n\n const updateToolbar = useCallback(() => {\n const selection = $getSelection();\n if ($isRangeSelection(selection)) {\n const anchor = selection.anchor;\n const anchorNode = anchor.getNode();\n\n const tableCell = $getTableCellNodeFromLexicalNode(anchorNode);\n if (tableCell) {\n const domNode = editor.getElementByKey(tableCell.getKey());\n const position = domNode ? domNode.getBoundingClientRect() : { right: 0, bottom: 0, height: 0 };\n setPosition({ xPos: position.right, yPos: position.bottom, height: position.height });\n } else {\n setPosition(null);\n }\n }\n }, [editor]);\n\n const handleTableAction = (action: Actions) => {\n tableref.current?.mutateTable(action);\n };\n\n const handleResizeScroll = () => {\n editor.update(() => {\n const selection = $getSelection();\n\n if ($isRangeSelection(selection)) {\n const anchor = selection.anchor;\n const anchorNode = anchor.getNode();\n\n const tableCell = $getTableCellNodeFromLexicalNode(anchorNode);\n if (tableCell) {\n $setSelection(null);\n setPosition(null);\n }\n }\n });\n };\n\n useEffect(() => {\n editor.registerUpdateListener(({ editorState }) => {\n editorState.read(() => {\n updateToolbar();\n });\n });\n }, [editor, updateToolbar]);\n\n useEffect(() => {\n setScrollableContainers(handleResizeScroll);\n\n window.addEventListener('scroll', handleResizeScroll);\n window.addEventListener('resize', handleResizeScroll);\n\n return () => {\n window.removeEventListener('scroll', handleResizeScroll);\n window.removeEventListener('resize', handleResizeScroll);\n removeScrollableContainers(handleResizeScroll);\n };\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [editor]);\n\n useEffect(() => {\n const removeKeydown = () => {\n setScrollableContainers(handleResizeScroll);\n };\n\n window.addEventListener('keydown', removeKeydown, { capture: true });\n\n return () => {\n window.removeEventListener('keydown', removeKeydown);\n };\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, []);\n\n return (\n <div className={styles['editor__toolbar']}>\n <BlockFormatPlugin />\n <ListPlugin />\n <TablePlugin isActive={Boolean(position)} ref={tableref} />\n {position && (\n <TableCellContextMenu\n position={position}\n parentScrollPosition={editorScrollPosition}\n onAction={handleTableAction}\n />\n )}\n <LinkPlugin parentScrollPosition={editorScrollPosition} />\n <HistoryPlugin />\n </div>\n );\n};\n"],"names":["ToolBarPlugin","editorScrollPosition","editor","useLexicalComposerContext","position","setPosition","useState","tableref","useRef","updateToolbar","useCallback","selection","$getSelection","$isRangeSelection","anchorNode","tableCell","$getTableCellNodeFromLexicalNode","domNode","handleTableAction","action","_a","handleResizeScroll","$setSelection","useEffect","editorState","setScrollableContainers","removeScrollableContainers","removeKeydown","jsxs","styles","jsx","BlockFormatPlugin","ListPlugin","TablePlugin","TableCellContextMenu","LinkPlugin","HistoryPlugin"],"mappings":";;;;;;;;;;;;;AA8BO,MAAMA,IAAgB,CAAC,EAAE,sBAAAC,QAAsD;AAC9E,QAAA,CAACC,CAAM,IAAIC,EAA0B,GACrC,CAACC,GAAUC,CAAW,IAAIC,EAA0B,IAAI,GACxDC,IAAWC,EAAsB,IAAI,GAErCC,IAAgBC,EAAY,MAAM;AACtC,UAAMC,IAAYC,EAAc;AAC5B,QAAAC,EAAkBF,CAAS,GAAG;AAE1B,YAAAG,IADSH,EAAU,OACC,QAAQ,GAE5BI,IAAYC,EAAiCF,CAAU;AAC7D,UAAIC,GAAW;AACb,cAAME,IAAUf,EAAO,gBAAgBa,EAAU,QAAQ,GACnDX,IAAWa,IAAUA,EAAQ,sBAAsB,IAAI,EAAE,OAAO,GAAG,QAAQ,GAAG,QAAQ,EAAE;AAClF,QAAAZ,EAAA,EAAE,MAAMD,EAAS,OAAO,MAAMA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,IAAA,gBAAAC,EAACC,GAAkB,EAAA;AAAA,sBAClBC,GAAW,EAAA;AAAA,sBACXC,GAAY,EAAA,UAAU,EAAQ7B,GAAW,KAAKG,GAAU;AAAA,IACxDH,KACC,gBAAA0B;AAAA,MAACI;AAAA,MAAA;AAAA,QACC,UAAA9B;AAAA,QACA,sBAAsBH;AAAA,QACtB,UAAUiB;AAAA,MAAA;AAAA,IACZ;AAAA,IAEF,gBAAAY,EAACK,GAAW,EAAA,sBAAsBlC,EAAsB,CAAA;AAAA,sBACvDmC,GAAc,CAAA,CAAA;AAAA,EAAA,GACjB;AAEJ;"}
|
|
@@ -3,7 +3,7 @@ import { BlockFormatPlugin as l } from "./BlockFormatPlugin/BlockFormatPlugin.js
|
|
|
3
3
|
import { ListPlugin as n } from "./ListPlugin/ListPlugin.js";
|
|
4
4
|
import { LinkPlugin as m, getLinkNodeTag as x } from "./LinkPlugin/LinkPlugin.js";
|
|
5
5
|
import { HistoryPlugin as p } from "./HistoryPlugin/HistoryPlugin.js";
|
|
6
|
-
import { T as a } from "../../../TablePlugin-
|
|
6
|
+
import { T as a } from "../../../TablePlugin-CPEwD-wi.js";
|
|
7
7
|
import { TableCellContextMenu as T } from "./TablePlugin/TableCellContextMenu/TableCellContextMenu.js";
|
|
8
8
|
export {
|
|
9
9
|
l as BlockFormatPlugin,
|
|
@@ -16,7 +16,7 @@ import { exportMap as tn, isStartingWithHtmlTag as nn, mergeBoldStrongTags as rn
|
|
|
16
16
|
import { s as R } from "../../RteEditor.module-oFMKEW6f.js";
|
|
17
17
|
import { ToolBarPlugin as on } from "./Plugins/ToolbarPlugin/ToolbarPlugin.js";
|
|
18
18
|
import { useTranslation as an } from "./hooks/useTranslation.js";
|
|
19
|
-
import "../../TablePlugin-
|
|
19
|
+
import "../../TablePlugin-CPEwD-wi.js";
|
|
20
20
|
import "./Plugins/LinkPlugin/LinkContextMenu/LinkContextMenu.js";
|
|
21
21
|
import "./hooks/components/Flyout.js";
|
|
22
22
|
import "../Buttons/Button.js";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Flyout.js","sources":["../../../../../src/components/RteEditor/hooks/components/Flyout.tsx"],"sourcesContent":["import clsx from 'clsx';\nimport { forwardRef } from 'react';\n\nimport type { ReactNode } from 'react';\n\nimport styles from './Flyout.module.css';\n\ninterface FlyoutProps {\n position: { top: number; left: number };\n visible: boolean;\n children: ReactNode;\n}\n\nexport const Flyout = forwardRef<HTMLDivElement, FlyoutProps>(\n ({ position, visible, children }: FlyoutProps, ref): JSX.Element => (\n <div\n className={clsx(styles['flyout__wrapper'], visible && styles['flyout__open'])}\n style={{ top: position.top, left: position.left }}\n ref={ref}\n >\n {children}\n </div>\n )\n);\n"],"names":["Flyout","forwardRef","position","visible","children","ref","jsx","clsx","styles"],"mappings":";;;;;;;GAaaA,IAASC;AAAA,EACpB,CAAC,EAAE,UAAAC,GAAU,SAAAC,GAAS,UAAAC,KAAyBC,MAC7C,gBAAAC;AAAA,IAAC;AAAA,IAAA;AAAA,MACC,WAAWC,EAAKC,EAAO,iBAAoBL,KAAWK,EAAO,YAAe;AAAA,MAC5E,OAAO,EAAE,KAAKN,EAAS,KAAK,MAAMA,EAAS,KAAK;AAAA,MAChD,KAAAG;AAAA,MAEC,UAAAD;AAAA,IAAA;AAAA,EAAA;AAGP;"}
|
|
1
|
+
{"version":3,"file":"Flyout.js","sources":["../../../../../src/components/RteEditor/hooks/components/Flyout.tsx"],"sourcesContent":["import clsx from 'clsx';\nimport { forwardRef } from 'react';\n\nimport type { JSX, ReactNode } from 'react';\n\nimport styles from './Flyout.module.css';\n\ninterface FlyoutProps {\n position: { top: number; left: number };\n visible: boolean;\n children: ReactNode;\n}\n\nexport const Flyout = forwardRef<HTMLDivElement, FlyoutProps>(\n ({ position, visible, children }: FlyoutProps, ref): JSX.Element => (\n <div\n className={clsx(styles['flyout__wrapper'], visible && styles['flyout__open'])}\n style={{ top: position.top, left: position.left }}\n ref={ref}\n >\n {children}\n </div>\n )\n);\n"],"names":["Flyout","forwardRef","position","visible","children","ref","jsx","clsx","styles"],"mappings":";;;;;;;GAaaA,IAASC;AAAA,EACpB,CAAC,EAAE,UAAAC,GAAU,SAAAC,GAAS,UAAAC,KAAyBC,MAC7C,gBAAAC;AAAA,IAAC;AAAA,IAAA;AAAA,MACC,WAAWC,EAAKC,EAAO,iBAAoBL,KAAWK,EAAO,YAAe;AAAA,MAC5E,OAAO,EAAE,KAAKN,EAAS,KAAK,MAAMA,EAAS,KAAK;AAAA,MAChD,KAAAG;AAAA,MAEC,UAAAD;AAAA,IAAA;AAAA,EAAA;AAGP;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useFlyout.js","sources":["../../../../src/components/RteEditor/hooks/useFlyout.tsx"],"sourcesContent":["import { useRef, useState } from 'react';\n\nimport type { ReactNode } from 'react';\n\nimport { Flyout } from './components/Flyout';\n\nimport { useOnClickOutside } from 'components/hooks/useOnClickOutside';\n\ninterface FlyoutOptions {\n position: { top: number; left: number };\n children?: ReactNode;\n}\n\nexport interface FlyoutHookResult {\n flyout: ReactNode;\n showFlyout: (options: FlyoutOptions) => void;\n hideFlyout: () => void;\n isVisible: boolean;\n}\n\nexport const useFlyout = (): FlyoutHookResult => {\n const flyoutRef = useRef<HTMLDivElement>(null);\n const [visible, setVisible] = useState(false);\n const [options, setOptions] = useState<FlyoutOptions>({\n position: { top: 0, left: 0 },\n children: null,\n });\n\n const showFlyout = (customOptions: FlyoutOptions): void => {\n setVisible(true);\n setOptions({ ...options, ...customOptions });\n };\n\n const hideFlyout = (): void => {\n setVisible(false);\n setOptions({ ...options });\n };\n\n useOnClickOutside(flyoutRef
|
|
1
|
+
{"version":3,"file":"useFlyout.js","sources":["../../../../src/components/RteEditor/hooks/useFlyout.tsx"],"sourcesContent":["import { useRef, useState } from 'react';\n\nimport type { ReactNode, RefObject } from 'react';\n\nimport { Flyout } from './components/Flyout';\n\nimport { useOnClickOutside } from 'components/hooks/useOnClickOutside';\n\ninterface FlyoutOptions {\n position: { top: number; left: number };\n children?: ReactNode;\n}\n\nexport interface FlyoutHookResult {\n flyout: ReactNode;\n showFlyout: (options: FlyoutOptions) => void;\n hideFlyout: () => void;\n isVisible: boolean;\n}\n\nexport const useFlyout = (): FlyoutHookResult => {\n const flyoutRef = useRef<HTMLDivElement>(null);\n const [visible, setVisible] = useState(false);\n const [options, setOptions] = useState<FlyoutOptions>({\n position: { top: 0, left: 0 },\n children: null,\n });\n\n const showFlyout = (customOptions: FlyoutOptions): void => {\n setVisible(true);\n setOptions({ ...options, ...customOptions });\n };\n\n const hideFlyout = (): void => {\n setVisible(false);\n setOptions({ ...options });\n };\n\n useOnClickOutside(flyoutRef as RefObject<HTMLElement>, hideFlyout);\n\n const flyout = (\n <Flyout visible={visible} position={options.position} ref={flyoutRef}>\n {options.children}\n </Flyout>\n );\n\n return {\n flyout,\n showFlyout,\n hideFlyout,\n isVisible: visible,\n };\n};\n"],"names":["useFlyout","flyoutRef","useRef","visible","setVisible","useState","options","setOptions","showFlyout","customOptions","hideFlyout","useOnClickOutside","jsx","Flyout"],"mappings":";;;;AAoBO,MAAMA,IAAY,MAAwB;AACzC,QAAAC,IAAYC,EAAuB,IAAI,GACvC,CAACC,GAASC,CAAU,IAAIC,EAAS,EAAK,GACtC,CAACC,GAASC,CAAU,IAAIF,EAAwB;AAAA,IACpD,UAAU,EAAE,KAAK,GAAG,MAAM,EAAE;AAAA,IAC5B,UAAU;AAAA,EAAA,CACX,GAEKG,IAAa,CAACC,MAAuC;AACzD,IAAAL,EAAW,EAAI,GACfG,EAAW,EAAE,GAAGD,GAAS,GAAGG,GAAe;AAAA,EAC7C,GAEMC,IAAa,MAAY;AAC7B,IAAAN,EAAW,EAAK,GACLG,EAAA,EAAE,GAAGD,GAAS;AAAA,EAC3B;AAEA,SAAAK,EAAkBV,GAAqCS,CAAU,GAQ1D;AAAA,IACL,QANC,gBAAAE,EAAAC,GAAA,EAAO,SAAAV,GAAkB,UAAUG,EAAQ,UAAU,KAAKL,GACxD,UAAAK,EAAQ,SACX,CAAA;AAAA,IAKA,YAAAE;AAAA,IACA,YAAAE;AAAA,IACA,WAAWP;AAAA,EACb;AACF;"}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { PropsWithChildren } from 'react';
|
|
2
2
|
import { OptionValue, SelectValue } from './SelectProvider';
|
|
3
|
+
import { SelectOptionProps } from './components/SelectOption';
|
|
3
4
|
export interface SelectListboxProps {
|
|
4
5
|
/** The possible options to select. */
|
|
5
6
|
options: OptionValue[];
|
|
@@ -31,5 +32,5 @@ export interface SelectListboxProps {
|
|
|
31
32
|
/** Represents a component to render a select list box. */
|
|
32
33
|
export declare const SelectListbox: {
|
|
33
34
|
({ options, variant, fullWidth, size, optionPositionRight, defaultValue, maxOptionHeight, disabled, buttonLabelProp, buttonLabelBold, onChange, dividerAfter, children, }: PropsWithChildren<SelectListboxProps>): import("react/jsx-runtime").JSX.Element;
|
|
34
|
-
SelectOption: ({ option, index, dividerAfter, children }:
|
|
35
|
+
SelectOption: ({ option, index, dividerAfter, children }: SelectOptionProps) => import("react/jsx-runtime").JSX.Element;
|
|
35
36
|
};
|
|
@@ -1,59 +1,56 @@
|
|
|
1
|
-
import { jsx as
|
|
2
|
-
import { useState as
|
|
3
|
-
import { SelectProvider as
|
|
4
|
-
import { SelectButton as
|
|
5
|
-
import { SelectContainer as
|
|
6
|
-
import { SelectOptionBox as
|
|
7
|
-
import { SelectOption as
|
|
8
|
-
import { usePositionedFloaters as
|
|
9
|
-
const
|
|
10
|
-
options:
|
|
1
|
+
import { jsx as t, jsxs as y } from "react/jsx-runtime";
|
|
2
|
+
import { useState as o, Children as B, isValidElement as O, cloneElement as g } from "react";
|
|
3
|
+
import { SelectProvider as j } from "./SelectProvider.js";
|
|
4
|
+
import { SelectButton as v } from "./components/SelectButton.js";
|
|
5
|
+
import { SelectContainer as C } from "./components/SelectContainer.js";
|
|
6
|
+
import { SelectOptionBox as F } from "./components/SelectOptionBox.js";
|
|
7
|
+
import { SelectOption as L } from "./components/SelectOption.js";
|
|
8
|
+
import { usePositionedFloaters as z } from "../hooks/usePositionedFloaters.js";
|
|
9
|
+
const H = ({
|
|
10
|
+
options: r,
|
|
11
11
|
variant: i,
|
|
12
|
-
fullWidth:
|
|
13
|
-
size:
|
|
14
|
-
optionPositionRight:
|
|
15
|
-
defaultValue:
|
|
16
|
-
maxOptionHeight:
|
|
12
|
+
fullWidth: n = !1,
|
|
13
|
+
size: l = "default",
|
|
14
|
+
optionPositionRight: m,
|
|
15
|
+
defaultValue: s = -1,
|
|
16
|
+
maxOptionHeight: f,
|
|
17
17
|
disabled: c,
|
|
18
|
-
buttonLabelProp:
|
|
19
|
-
buttonLabelBold:
|
|
20
|
-
onChange:
|
|
18
|
+
buttonLabelProp: p = "label",
|
|
19
|
+
buttonLabelBold: a,
|
|
20
|
+
onChange: u,
|
|
21
21
|
dividerAfter: S,
|
|
22
22
|
children: d
|
|
23
23
|
}) => {
|
|
24
|
-
const [
|
|
24
|
+
const [x, E] = o(null), [h, b] = o(null), { style: P } = z(x, h, {
|
|
25
25
|
mouseEvent: "click",
|
|
26
26
|
position: "bottomLeft",
|
|
27
27
|
offset: 4,
|
|
28
|
-
maxFixedHeight:
|
|
29
|
-
horizontalPosition:
|
|
28
|
+
maxFixedHeight: f,
|
|
29
|
+
horizontalPosition: m ? "right" : "left",
|
|
30
30
|
mobileBreakpoint: "28rem",
|
|
31
|
-
fullWidth:
|
|
31
|
+
fullWidth: n
|
|
32
32
|
});
|
|
33
|
-
return /* @__PURE__ */
|
|
34
|
-
/* @__PURE__ */
|
|
35
|
-
|
|
33
|
+
return /* @__PURE__ */ t(j, { options: r, defaultValue: s, children: /* @__PURE__ */ y(C, { children: [
|
|
34
|
+
/* @__PURE__ */ t(
|
|
35
|
+
v,
|
|
36
36
|
{
|
|
37
37
|
disabled: c,
|
|
38
|
-
buttonLabelProp:
|
|
39
|
-
buttonLabelBold:
|
|
38
|
+
buttonLabelProp: p,
|
|
39
|
+
buttonLabelBold: a,
|
|
40
40
|
variant: i,
|
|
41
|
-
size:
|
|
42
|
-
onChange:
|
|
43
|
-
ref:
|
|
41
|
+
size: l,
|
|
42
|
+
onChange: u,
|
|
43
|
+
ref: b
|
|
44
44
|
}
|
|
45
45
|
),
|
|
46
|
-
/* @__PURE__ */
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
key: k
|
|
51
|
-
})
|
|
52
|
-
) })
|
|
46
|
+
/* @__PURE__ */ t(F, { ref: E, ...P, children: B.map(d, (e, k) => O(e) ? g(e, {
|
|
47
|
+
dividerAfter: S,
|
|
48
|
+
key: k
|
|
49
|
+
}) : e) })
|
|
53
50
|
] }) });
|
|
54
51
|
};
|
|
55
|
-
|
|
52
|
+
H.SelectOption = L;
|
|
56
53
|
export {
|
|
57
|
-
|
|
54
|
+
H as SelectListbox
|
|
58
55
|
};
|
|
59
56
|
//# sourceMappingURL=SelectListbox.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SelectListbox.js","sources":["../../../src/components/SelectListbox/SelectListbox.tsx"],"sourcesContent":["import { Children, cloneElement, useState } from 'react';\n\nimport type { PropsWithChildren } from 'react';\nimport type { OptionValue, SelectValue } from './SelectProvider';\n\nimport { SelectProvider } from './SelectProvider';\nimport { SelectButton } from './components/SelectButton';\nimport { SelectContainer } from './components/SelectContainer';\nimport { SelectOptionBox } from './components/SelectOptionBox';\nimport { SelectOption } from './components/SelectOption';\n\nimport { usePositionedFloaters } from 'components/hooks/usePositionedFloaters';\n\nexport interface SelectListboxProps {\n /** The possible options to select. */\n options: OptionValue[];\n /** The selected value by default. */\n defaultValue?: SelectValue;\n /** The max height of the options. */\n maxOptionHeight?: `${number}${'px' | 'rem'}`;\n /** `true` to disable the select box; otherwise, `false`. The default is `false`. */\n disabled?: boolean;\n /** The name of the property in the options structure that contains the label of the options. */\n buttonLabelProp?: string;\n /** `true` to render the labels in bold; otherwise, `false`. The default is `false`. */\n buttonLabelBold?: boolean;\n /** The variant of the select box. */\n variant?: 'noborder' | 'pill' | 'pillLeft' | 'pillRight' | 'darkBorder';\n /** If true sets the option dropdown min-width to the width of the select button. */\n fullWidth?: boolean;\n /** The size of the select box. */\n size?: 'small' | 'medium' | 'default';\n /** `true` to align the right side of the options with the select box; otherwise, `false` to align on the left side. */\n optionPositionRight?: boolean;\n /** The breakpoint at which to switch to the mobile view. */\n mobileBreakpoint?: `${number}${'px' | 'rem'}`;\n /** The callback function that is invoked when an option is selected. */\n onChange?: (option: OptionValue) => void;\n /** Option to add a devider after a given amout of ouptions in the select option box. */\n dividerAfter?: number;\n}\n\n/** Represents a component to render a select list box. */\nexport const SelectListbox = ({\n options,\n variant,\n fullWidth = false,\n size = 'default',\n optionPositionRight,\n defaultValue = -1,\n maxOptionHeight,\n disabled,\n buttonLabelProp = 'label',\n buttonLabelBold,\n onChange,\n dividerAfter,\n children,\n}: PropsWithChildren<SelectListboxProps>) => {\n const [positionElement, setPositionElement] = useState<HTMLElement | null>(null);\n const [referenceElement, setReferenceElement] = useState<HTMLElement | null>(null);\n const { style: positionStyle } = usePositionedFloaters(positionElement, referenceElement, {\n mouseEvent: 'click',\n position: 'bottomLeft',\n offset: 4,\n maxFixedHeight: maxOptionHeight,\n horizontalPosition: optionPositionRight ? 'right' : 'left',\n mobileBreakpoint: '28rem',\n fullWidth,\n });\n\n return (\n <SelectProvider options={options} defaultValue={defaultValue}>\n <SelectContainer>\n <SelectButton\n disabled={disabled}\n buttonLabelProp={buttonLabelProp}\n buttonLabelBold={buttonLabelBold}\n variant={variant}\n size={size}\n onChange={onChange}\n ref={setReferenceElement}\n />\n\n <SelectOptionBox ref={setPositionElement} {...positionStyle}>\n {Children.map(children, (child, index)
|
|
1
|
+
{"version":3,"file":"SelectListbox.js","sources":["../../../src/components/SelectListbox/SelectListbox.tsx"],"sourcesContent":["import { Children, cloneElement, isValidElement, useState } from 'react';\n\nimport type { PropsWithChildren } from 'react';\nimport type { OptionValue, SelectValue } from './SelectProvider';\nimport type { SelectOptionProps } from './components/SelectOption';\n\nimport { SelectProvider } from './SelectProvider';\nimport { SelectButton } from './components/SelectButton';\nimport { SelectContainer } from './components/SelectContainer';\nimport { SelectOptionBox } from './components/SelectOptionBox';\nimport { SelectOption } from './components/SelectOption';\n\nimport { usePositionedFloaters } from 'components/hooks/usePositionedFloaters';\n\nexport interface SelectListboxProps {\n /** The possible options to select. */\n options: OptionValue[];\n /** The selected value by default. */\n defaultValue?: SelectValue;\n /** The max height of the options. */\n maxOptionHeight?: `${number}${'px' | 'rem'}`;\n /** `true` to disable the select box; otherwise, `false`. The default is `false`. */\n disabled?: boolean;\n /** The name of the property in the options structure that contains the label of the options. */\n buttonLabelProp?: string;\n /** `true` to render the labels in bold; otherwise, `false`. The default is `false`. */\n buttonLabelBold?: boolean;\n /** The variant of the select box. */\n variant?: 'noborder' | 'pill' | 'pillLeft' | 'pillRight' | 'darkBorder';\n /** If true sets the option dropdown min-width to the width of the select button. */\n fullWidth?: boolean;\n /** The size of the select box. */\n size?: 'small' | 'medium' | 'default';\n /** `true` to align the right side of the options with the select box; otherwise, `false` to align on the left side. */\n optionPositionRight?: boolean;\n /** The breakpoint at which to switch to the mobile view. */\n mobileBreakpoint?: `${number}${'px' | 'rem'}`;\n /** The callback function that is invoked when an option is selected. */\n onChange?: (option: OptionValue) => void;\n /** Option to add a devider after a given amout of ouptions in the select option box. */\n dividerAfter?: number;\n}\n\n/** Represents a component to render a select list box. */\nexport const SelectListbox = ({\n options,\n variant,\n fullWidth = false,\n size = 'default',\n optionPositionRight,\n defaultValue = -1,\n maxOptionHeight,\n disabled,\n buttonLabelProp = 'label',\n buttonLabelBold,\n onChange,\n dividerAfter,\n children,\n}: PropsWithChildren<SelectListboxProps>) => {\n const [positionElement, setPositionElement] = useState<HTMLElement | null>(null);\n const [referenceElement, setReferenceElement] = useState<HTMLElement | null>(null);\n const { style: positionStyle } = usePositionedFloaters(positionElement, referenceElement, {\n mouseEvent: 'click',\n position: 'bottomLeft',\n offset: 4,\n maxFixedHeight: maxOptionHeight,\n horizontalPosition: optionPositionRight ? 'right' : 'left',\n mobileBreakpoint: '28rem',\n fullWidth,\n });\n\n return (\n <SelectProvider options={options} defaultValue={defaultValue}>\n <SelectContainer>\n <SelectButton\n disabled={disabled}\n buttonLabelProp={buttonLabelProp}\n buttonLabelBold={buttonLabelBold}\n variant={variant}\n size={size}\n onChange={onChange}\n ref={setReferenceElement}\n />\n\n <SelectOptionBox ref={setPositionElement} {...positionStyle}>\n {Children.map(children, (child, index) => {\n if (isValidElement<SelectOptionProps>(child)) {\n return cloneElement(child, {\n dividerAfter,\n key: index,\n });\n }\n return child;\n })}\n </SelectOptionBox>\n </SelectContainer>\n </SelectProvider>\n );\n};\n\nSelectListbox.SelectOption = SelectOption;\n"],"names":["SelectListbox","options","variant","fullWidth","size","optionPositionRight","defaultValue","maxOptionHeight","disabled","buttonLabelProp","buttonLabelBold","onChange","dividerAfter","children","positionElement","setPositionElement","useState","referenceElement","setReferenceElement","positionStyle","usePositionedFloaters","jsx","SelectProvider","SelectContainer","SelectButton","SelectOptionBox","Children","child","index","isValidElement","cloneElement","SelectOption"],"mappings":";;;;;;;;AA4CO,MAAMA,IAAgB,CAAC;AAAA,EAC5B,SAAAC;AAAA,EACA,SAAAC;AAAA,EACA,WAAAC,IAAY;AAAA,EACZ,MAAAC,IAAO;AAAA,EACP,qBAAAC;AAAA,EACA,cAAAC,IAAe;AAAA,EACf,iBAAAC;AAAA,EACA,UAAAC;AAAA,EACA,iBAAAC,IAAkB;AAAA,EAClB,iBAAAC;AAAA,EACA,UAAAC;AAAA,EACA,cAAAC;AAAA,EACA,UAAAC;AACF,MAA6C;AAC3C,QAAM,CAACC,GAAiBC,CAAkB,IAAIC,EAA6B,IAAI,GACzE,CAACC,GAAkBC,CAAmB,IAAIF,EAA6B,IAAI,GAC3E,EAAE,OAAOG,EAAA,IAAkBC,EAAsBN,GAAiBG,GAAkB;AAAA,IACxF,YAAY;AAAA,IACZ,UAAU;AAAA,IACV,QAAQ;AAAA,IACR,gBAAgBV;AAAA,IAChB,oBAAoBF,IAAsB,UAAU;AAAA,IACpD,kBAAkB;AAAA,IAClB,WAAAF;AAAA,EAAA,CACD;AAED,SACG,gBAAAkB,EAAAC,GAAA,EAAe,SAAArB,GAAkB,cAAAK,GAChC,4BAACiB,GACC,EAAA,UAAA;AAAA,IAAA,gBAAAF;AAAA,MAACG;AAAA,MAAA;AAAA,QACC,UAAAhB;AAAA,QACA,iBAAAC;AAAA,QACA,iBAAAC;AAAA,QACA,SAAAR;AAAA,QACA,MAAAE;AAAA,QACA,UAAAO;AAAA,QACA,KAAKO;AAAA,MAAA;AAAA,IACP;AAAA,IAEA,gBAAAG,EAACI,GAAgB,EAAA,KAAKV,GAAqB,GAAGI,GAC3C,UAAAO,EAAS,IAAIb,GAAU,CAACc,GAAOC,MAC1BC,EAAkCF,CAAK,IAClCG,EAAaH,GAAO;AAAA,MACzB,cAAAf;AAAA,MACA,KAAKgB;AAAA,IAAA,CACN,IAEID,CACR,EACH,CAAA;AAAA,EAAA,EAAA,CACF,EACF,CAAA;AAEJ;AAEA3B,EAAc,eAAe+B;"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { jsx as a, jsxs as C } from "react/jsx-runtime";
|
|
2
2
|
import { c as f } from "../../../clsx-OuTLNxxd.js";
|
|
3
3
|
import { forwardRef as E, useRef as g, useEffect as c } from "react";
|
|
4
|
-
import { s as t } from "../../../SelectListbox.module-
|
|
4
|
+
import { s as t } from "../../../SelectListbox.module-BD2qbcmZ.js";
|
|
5
5
|
import { Icon as L } from "../../Icon/Icon.js";
|
|
6
6
|
import { useSelect as N } from "../SelectProvider.js";
|
|
7
7
|
const O = E((d, u) => {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { jsx as c } from "react/jsx-runtime";
|
|
2
2
|
import { useRef as i, useCallback as u, useEffect as l } from "react";
|
|
3
3
|
import { useSelect as m } from "../SelectProvider.js";
|
|
4
|
-
import { s as f } from "../../../SelectListbox.module-
|
|
4
|
+
import { s as f } from "../../../SelectListbox.module-BD2qbcmZ.js";
|
|
5
5
|
const E = ({ children: o }) => {
|
|
6
6
|
const { isOpen: r, setIsOpen: n } = m(), t = i(null), e = u(
|
|
7
7
|
({ target: s }) => {
|
|
@@ -2,7 +2,7 @@ import { jsxs as D, Fragment as h, jsx as m } from "react/jsx-runtime";
|
|
|
2
2
|
import { c as y } from "../../../clsx-OuTLNxxd.js";
|
|
3
3
|
import { useRef as O, useEffect as d } from "react";
|
|
4
4
|
import { useSelect as x } from "../SelectProvider.js";
|
|
5
|
-
import { s as o } from "../../../SelectListbox.module-
|
|
5
|
+
import { s as o } from "../../../SelectListbox.module-BD2qbcmZ.js";
|
|
6
6
|
const j = ({ option: l, index: t, dividerAfter: u, children: v }) => {
|
|
7
7
|
const i = O(null), { isOpen: r, activeIndex: s, setActiveIndex: c, selectedValue: f, setSelectedValue: p, setIsOpen: n, options: a } = x(), w = (e) => {
|
|
8
8
|
p(a[e]), n(!1);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SelectOption.js","sources":["../../../../src/components/SelectListbox/components/SelectOption.tsx"],"sourcesContent":["import { clsx } from 'clsx';\nimport { useEffect, useRef } from 'react';\n\nimport type { KeyboardEvent, ReactNode } from 'react';\nimport type { OptionValue } from 'components/SelectListbox/SelectProvider';\n\nimport { useSelect } from 'components/SelectListbox/SelectProvider';\nimport styles from 'components/SelectListbox/SelectListbox.module.css';\n\nexport interface SelectOptionProps {\n option: OptionValue;\n index: number;\n key: string;\n dividerAfter?: number;\n children: ReactNode;\n}\n\nexport const SelectOption = ({ option, index, dividerAfter, children }: SelectOptionProps) => {\n const selectOptionRef = useRef<HTMLLIElement>(null);\n const { isOpen, activeIndex, setActiveIndex, selectedValue, setSelectedValue, setIsOpen, options } = useSelect();\n\n const handleSelectOption = (aIndex: number) => {\n setSelectedValue(options[aIndex]);\n setIsOpen(false);\n };\n\n const onOptionKeyDown = (event: KeyboardEvent<HTMLLIElement>) => {\n switch (event.key) {\n case 'Tab':\n event.preventDefault();\n if (isOpen) {\n setIsOpen(false);\n }\n break;\n case 'ArrowDown':\n case 'ArrowUp':\n event.preventDefault();\n if (!isOpen) {\n return;\n }\n if (event.key === 'ArrowDown' && activeIndex < options.length - 1) {\n setActiveIndex(activeIndex + 1);\n }\n if (event.key === 'ArrowUp' && activeIndex > 0) {\n setActiveIndex(activeIndex - 1);\n }\n break;\n case 'Enter':\n event.preventDefault();\n if (options?.length && activeIndex > -1 && !options[activeIndex].disabled) {\n handleSelectOption(activeIndex);\n }\n break;\n case 'Escape':\n if (isOpen) {\n event.stopPropagation();\n setIsOpen(false);\n }\n break;\n }\n };\n\n useEffect(() => {\n if (index === activeIndex) {\n isOpen ? selectOptionRef.current?.focus() : selectOptionRef.current?.blur();\n }\n }, [activeIndex, index, isOpen]);\n\n useEffect(() => {\n if (selectedValue.value === option.value) {\n setActiveIndex(index);\n }\n }, [index, option.value, selectedValue.value, setActiveIndex]);\n\n return (\n <>\n <li\n className={clsx(styles['select-listbox-option'], {\n [styles['select-listbox-option--active']]: index === activeIndex,\n [styles['select-listbox-option--divider']]: index + 1 === dividerAfter,\n })}\n key={`${option.value}`}\n {...(!option.disabled && {\n onClick: () => setSelectedValue(option),\n onKeyDown: onOptionKeyDown,\n tabIndex: 0,\n role: 'option',\n 'aria-selected': selectedValue.value === option.value,\n })}\n ref={selectOptionRef}\n >\n {children}\n </li>\n {index + 1 === dividerAfter && <div className={styles['select-listbox-divider']} aria-hidden=\"true\" />}\n </>\n );\n};\n"],"names":["SelectOption","option","index","dividerAfter","children","selectOptionRef","useRef","isOpen","activeIndex","setActiveIndex","selectedValue","setSelectedValue","setIsOpen","options","useSelect","handleSelectOption","aIndex","onOptionKeyDown","event","useEffect","_a","_b","jsxs","Fragment","jsx","clsx","styles"],"mappings":";;;;;AAiBO,MAAMA,IAAe,CAAC,EAAE,QAAAC,GAAQ,OAAAC,G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D,gBAAAa,EAAAC,GAAA,EAAA,UAAA;AAAA,IAAA,gBAAAC;AAAA,MAAC;AAAA,MAAA;AAAA,QACC,WAAWC,EAAKC,EAAO,uBAAuB,GAAG;AAAA,UAC/C,CAACA,EAAO,+BAA+B,CAAC,GAAGxB,MAAUM;AAAA,UACrD,CAACkB,EAAO,gCAAgC,CAAC,GAAGxB,IAAQ,MAAMC;AAAA,QAAA,CAC3D;AAAA,QAEA,GAAI,CAACF,EAAO,YAAY;AAAA,UACvB,SAAS,MAAMU,EAAiBV,CAAM;AAAA,UACtC,WAAWgB;AAAA,UACX,UAAU;AAAA,UACV,MAAM;AAAA,UACN,iBAAiBP,EAAc,UAAUT,EAAO;AAAA,QAClD;AAAA,QACA,KAAKI;AAAA,QAEJ,UAAAD;AAAA,MAAA;AAAA,MAVI,GAAGH,EAAO,KAAK;AAAA,IAWtB;AAAA,IACCC,IAAQ,MAAMC,KAAiB,gBAAAqB,EAAA,OAAA,EAAI,WAAWE,EAAO,wBAAwB,GAAG,eAAY,OAAO,CAAA;AAAA,EAAA,GACtG;AAEJ;"}
|
|
1
|
+
{"version":3,"file":"SelectOption.js","sources":["../../../../src/components/SelectListbox/components/SelectOption.tsx"],"sourcesContent":["import { clsx } from 'clsx';\nimport { useEffect, useRef } from 'react';\n\nimport type { KeyboardEvent, ReactNode } from 'react';\nimport type { OptionValue } from 'components/SelectListbox/SelectProvider';\n\nimport { useSelect } from 'components/SelectListbox/SelectProvider';\nimport styles from 'components/SelectListbox/SelectListbox.module.css';\n\nexport interface SelectOptionProps {\n option: OptionValue;\n index: number;\n key: string | number;\n dividerAfter?: number;\n children: ReactNode;\n}\n\nexport const SelectOption = ({ option, index, dividerAfter, children }: SelectOptionProps) => {\n const selectOptionRef = useRef<HTMLLIElement>(null);\n const { isOpen, activeIndex, setActiveIndex, selectedValue, setSelectedValue, setIsOpen, options } = useSelect();\n\n const handleSelectOption = (aIndex: number) => {\n setSelectedValue(options[aIndex]);\n setIsOpen(false);\n };\n\n const onOptionKeyDown = (event: KeyboardEvent<HTMLLIElement>) => {\n switch (event.key) {\n case 'Tab':\n event.preventDefault();\n if (isOpen) {\n setIsOpen(false);\n }\n break;\n case 'ArrowDown':\n case 'ArrowUp':\n event.preventDefault();\n if (!isOpen) {\n return;\n }\n if (event.key === 'ArrowDown' && activeIndex < options.length - 1) {\n setActiveIndex(activeIndex + 1);\n }\n if (event.key === 'ArrowUp' && activeIndex > 0) {\n setActiveIndex(activeIndex - 1);\n }\n break;\n case 'Enter':\n event.preventDefault();\n if (options?.length && activeIndex > -1 && !options[activeIndex].disabled) {\n handleSelectOption(activeIndex);\n }\n break;\n case 'Escape':\n if (isOpen) {\n event.stopPropagation();\n setIsOpen(false);\n }\n break;\n }\n };\n\n useEffect(() => {\n if (index === activeIndex) {\n isOpen ? selectOptionRef.current?.focus() : selectOptionRef.current?.blur();\n }\n }, [activeIndex, index, isOpen]);\n\n useEffect(() => {\n if (selectedValue.value === option.value) {\n setActiveIndex(index);\n }\n }, [index, option.value, selectedValue.value, setActiveIndex]);\n\n return (\n <>\n <li\n className={clsx(styles['select-listbox-option'], {\n [styles['select-listbox-option--active']]: index === activeIndex,\n [styles['select-listbox-option--divider']]: index + 1 === dividerAfter,\n })}\n key={`${option.value}`}\n {...(!option.disabled && {\n onClick: () => setSelectedValue(option),\n onKeyDown: onOptionKeyDown,\n tabIndex: 0,\n role: 'option',\n 'aria-selected': selectedValue.value === option.value,\n })}\n ref={selectOptionRef}\n >\n {children}\n </li>\n {index + 1 === dividerAfter && <div className={styles['select-listbox-divider']} aria-hidden=\"true\" />}\n </>\n );\n};\n"],"names":["SelectOption","option","index","dividerAfter","children","selectOptionRef","useRef","isOpen","activeIndex","setActiveIndex","selectedValue","setSelectedValue","setIsOpen","options","useSelect","handleSelectOption","aIndex","onOptionKeyDown","event","useEffect","_a","_b","jsxs","Fragment","jsx","clsx","styles"],"mappings":";;;;;AAiBO,MAAMA,IAAe,CAAC,EAAE,QAAAC,GAAQ,OAAA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AIzD,gBAAAa,EAAAC,GAAA,EAAA,UAAA;AAAA,IAAA,gBAAAC;AAAA,MAAC;AAAA,MAAA;AAAA,QACC,WAAWC,EAAKC,EAAO,uBAAuB,GAAG;AAAA,UAC/C,CAACA,EAAO,+BAA+B,CAAC,GAAGxB,MAAUM;AAAA,UACrD,CAACkB,EAAO,gCAAgC,CAAC,GAAGxB,IAAQ,MAAMC;AAAA,QAAA,CAC3D;AAAA,QAEA,GAAI,CAACF,EAAO,YAAY;AAAA,UACvB,SAAS,MAAMU,EAAiBV,CAAM;AAAA,UACtC,WAAWgB;AAAA,UACX,UAAU;AAAA,UACV,MAAM;AAAA,UACN,iBAAiBP,EAAc,UAAUT,EAAO;AAAA,QAClD;AAAA,QACA,KAAKI;AAAA,QAEJ,UAAAD;AAAA,MAAA;AAAA,MAVI,GAAGH,EAAO,KAAK;AAAA,IAWtB;AAAA,IACCC,IAAQ,MAAMC,KAAiB,gBAAAqB,EAAA,OAAA,EAAI,WAAWE,EAAO,wBAAwB,GAAG,eAAY,OAAO,CAAA;AAAA,EAAA,GACtG;AAEJ;"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { jsx as s } from "react/jsx-runtime";
|
|
2
2
|
import { forwardRef as m, useRef as x } from "react";
|
|
3
|
-
import { s as i } from "../../../SelectListbox.module-
|
|
3
|
+
import { s as i } from "../../../SelectListbox.module-BD2qbcmZ.js";
|
|
4
4
|
import { useSelect as a } from "../SelectProvider.js";
|
|
5
5
|
const h = m((l, e) => {
|
|
6
6
|
const { style: t, children: o } = l, { listboxId: r, isOpen: c } = a(), n = x(null);
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { jsx as e, jsxs as m, Fragment as i } from "react/jsx-runtime";
|
|
2
|
-
import { f as s } from "../../index-
|
|
2
|
+
import { f as s } from "../../index-Sh2oo6_C.js";
|
|
3
3
|
import { Sortable as o } from "./Sortable.js";
|
|
4
4
|
import { InputField as c } from "../InputField/InputField.js";
|
|
5
5
|
import { Icon as d } from "../Icon/Icon.js";
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { jsx as o } from "react/jsx-runtime";
|
|
2
|
-
import { f as l } from "../../index-
|
|
2
|
+
import { f as l } from "../../index-Sh2oo6_C.js";
|
|
3
3
|
import { ToggleSwitch as e } from "./ToggleSwitch.js";
|
|
4
4
|
const a = `
|
|
5
5
|
// Has all InputHTMLAttributes props available except "className" and "style"
|
|
@@ -1,17 +1,17 @@
|
|
|
1
1
|
import { useRef as c, useEffect as o } from "react";
|
|
2
2
|
const i = 200;
|
|
3
|
-
function
|
|
4
|
-
const e = c();
|
|
3
|
+
function m(n, t = i) {
|
|
4
|
+
const e = c(void 0);
|
|
5
5
|
return o(() => () => {
|
|
6
6
|
e.current && clearTimeout(e.current);
|
|
7
7
|
}, []), (...r) => {
|
|
8
8
|
const u = setTimeout(() => {
|
|
9
|
-
|
|
10
|
-
},
|
|
9
|
+
n(...r);
|
|
10
|
+
}, t);
|
|
11
11
|
clearTimeout(e.current), e.current = u;
|
|
12
12
|
};
|
|
13
13
|
}
|
|
14
14
|
export {
|
|
15
|
-
|
|
15
|
+
m as useDebounce
|
|
16
16
|
};
|
|
17
17
|
//# sourceMappingURL=useDebounce.js.map
|