@mittwald/flow-react-components 1.6.0-next.56 → 1.6.0-next.57
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/assets/component-index.json +1 -1
- package/dist/assets/doc-properties.json +1 -1
- package/dist/js/packages/components/src/components/Action/lib/ariaLive.mjs.map +1 -1
- package/dist/js/packages/components/src/components/LightBox/components/LightBoxGallery/LightBoxGallery.mjs.map +1 -1
- package/dist/js/packages/components/src/components/List/components/Items/components/Item/hooks/useGridItemProps.mjs.map +1 -1
- package/dist/js/packages/components/src/components/List/hooks/useAriaAnnounceSearchState.mjs.map +1 -1
- package/dist/js/packages/components/src/components/List/model/List.mjs +3 -2
- package/dist/js/packages/components/src/components/List/model/List.mjs.map +1 -1
- package/dist/js/packages/components/src/components/List/model/loading/IncrementalLoader.mjs +9 -6
- package/dist/js/packages/components/src/components/List/model/loading/IncrementalLoader.mjs.map +1 -1
- package/dist/js/packages/components/src/components/PasswordCreationField/lib/ariaAnnounce.mjs.map +1 -1
- package/dist/js/packages/components/src/components/PasswordCreationField/lib/usePolicyValidationResult.mjs.map +1 -1
- package/dist/js/packages/components/src/components/SettingsProvider/SettingsProvider.mjs.map +1 -1
- package/dist/js/packages/components/src/components/TextArea/TextArea.mjs.map +1 -1
- package/dist/js/packages/components/src/integrations/react-hook-form/components/Form/Form.mjs.map +1 -1
- package/dist/js/packages/components/src/integrations/react-hook-form/components/FormContextProvider/useFormSubmitAction.mjs.map +1 -1
- package/dist/js/packages/components/src/lib/controller/overlay/OverlayController.mjs +7 -5
- package/dist/js/packages/components/src/lib/controller/overlay/OverlayController.mjs.map +1 -1
- package/dist/js/packages/components/src/lib/hooks/dom/useMakeFocusable.mjs.map +1 -1
- package/dist/js/packages/components/src/lib/hooks/useFieldError.mjs.map +1 -1
- package/dist/js/packages/components/src/lib/hooks/useOnChange.mjs.map +1 -1
- package/dist/js/packages/components/src/lib/mobx/useSelector.mjs.map +1 -1
- package/dist/js/packages/components/src/lib/remote/useControlledHostValueProps.mjs +1 -1
- package/dist/js/packages/components/src/lib/remote/useControlledHostValueProps.mjs.map +1 -1
- package/package.json +10 -10
- package/dist/types/lib/mobx/useAutorunEffect.d.ts +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ariaLive.mjs","names":["locales"],"sources":["../../../../../../../../src/components/Action/lib/ariaLive.ts"],"sourcesContent":["import { useLocalizedStringFormatter } from \"@/components/TranslationProvider/useLocalizedStringFormatter\";\nimport locales from \"../locales/*.locale.json\";\nimport { useEffect } from \"react\";\nimport type { ActionStateValue } from \"@/components/Action/models/ActionState\";\nimport { announce } from \"@react-aria/live-announcer\";\n\ninterface Options {\n isPendingText?: string;\n isSucceededText?: string;\n isFailedText?: string;\n}\n\nexport const useAriaAnnounceActionState = (\n actionState: ActionStateValue,\n options: Options = {},\n): void => {\n const formatter = useLocalizedStringFormatter(locales, \"AriaAnnounce\");\n\n const {\n isPendingText = formatter.format(\"action.isPending\"),\n isSucceededText = formatter.format(\"action.isSucceeded\"),\n isFailedText = formatter.format(\"action.isFailed\"),\n } = options;\n\n useEffect(() => {\n if (actionState === \"isPending\") {\n announce(isPendingText, \"polite\");\n } else if (actionState === \"isSucceeded\") {\n announce(isSucceededText, \"polite\");\n } else if (actionState === \"isFailed\") {\n announce(isFailedText, \"polite\");\n }\n }, [actionState]);\n};\n\nexport const useAriaAnnounceSuspense = () => {\n const formatter = useLocalizedStringFormatter(locales, \"AriaAnnounce\");\n\n useEffect(() => {\n const timeout = setTimeout(() => {\n const isPendingText = formatter.format(\"suspense.isPending\");\n announce(isPendingText, \"polite\");\n }, 750);\n\n return () => {\n clearTimeout(timeout);\n };\n }, []);\n};\n"],"mappings":";;;;;;;AAYA,IAAa,8BACX,aACA,UAAmB,CAAC,MACX;CACT,MAAM,YAAY,4BAA4BA,kBAAS,cAAc;CAErE,MAAM,EACJ,gBAAgB,UAAU,OAAO,kBAAkB,GACnD,kBAAkB,UAAU,OAAO,oBAAoB,GACvD,eAAe,UAAU,OAAO,iBAAiB,MAC/C;CAEJ,gBAAgB;EACd,IAAI,gBAAgB,aAClB,SAAS,eAAe,QAAQ;OAC3B,IAAI,gBAAgB,eACzB,SAAS,iBAAiB,QAAQ;OAC7B,IAAI,gBAAgB,YACzB,SAAS,cAAc,QAAQ;
|
|
1
|
+
{"version":3,"file":"ariaLive.mjs","names":["locales"],"sources":["../../../../../../../../src/components/Action/lib/ariaLive.ts"],"sourcesContent":["import { useLocalizedStringFormatter } from \"@/components/TranslationProvider/useLocalizedStringFormatter\";\nimport locales from \"../locales/*.locale.json\";\nimport { useEffect } from \"react\";\nimport type { ActionStateValue } from \"@/components/Action/models/ActionState\";\nimport { announce } from \"@react-aria/live-announcer\";\n\ninterface Options {\n isPendingText?: string;\n isSucceededText?: string;\n isFailedText?: string;\n}\n\nexport const useAriaAnnounceActionState = (\n actionState: ActionStateValue,\n options: Options = {},\n): void => {\n const formatter = useLocalizedStringFormatter(locales, \"AriaAnnounce\");\n\n const {\n isPendingText = formatter.format(\"action.isPending\"),\n isSucceededText = formatter.format(\"action.isSucceeded\"),\n isFailedText = formatter.format(\"action.isFailed\"),\n } = options;\n\n useEffect(() => {\n if (actionState === \"isPending\") {\n announce(isPendingText, \"polite\");\n } else if (actionState === \"isSucceeded\") {\n announce(isSucceededText, \"polite\");\n } else if (actionState === \"isFailed\") {\n announce(isFailedText, \"polite\");\n }\n // eslint-disable-next-line react-hooks/exhaustive-deps -- announce on state changes only, not when the texts change\n }, [actionState]);\n};\n\nexport const useAriaAnnounceSuspense = () => {\n const formatter = useLocalizedStringFormatter(locales, \"AriaAnnounce\");\n\n useEffect(() => {\n const timeout = setTimeout(() => {\n const isPendingText = formatter.format(\"suspense.isPending\");\n announce(isPendingText, \"polite\");\n }, 750);\n\n return () => {\n clearTimeout(timeout);\n };\n // eslint-disable-next-line react-hooks/exhaustive-deps -- announce once per mount\n }, []);\n};\n"],"mappings":";;;;;;;AAYA,IAAa,8BACX,aACA,UAAmB,CAAC,MACX;CACT,MAAM,YAAY,4BAA4BA,kBAAS,cAAc;CAErE,MAAM,EACJ,gBAAgB,UAAU,OAAO,kBAAkB,GACnD,kBAAkB,UAAU,OAAO,oBAAoB,GACvD,eAAe,UAAU,OAAO,iBAAiB,MAC/C;CAEJ,gBAAgB;EACd,IAAI,gBAAgB,aAClB,SAAS,eAAe,QAAQ;OAC3B,IAAI,gBAAgB,eACzB,SAAS,iBAAiB,QAAQ;OAC7B,IAAI,gBAAgB,YACzB,SAAS,cAAc,QAAQ;CAGnC,GAAG,CAAC,WAAW,CAAC;AAClB;AAEA,IAAa,gCAAgC;CAC3C,MAAM,YAAY,4BAA4BA,kBAAS,cAAc;CAErE,gBAAgB;EACd,MAAM,UAAU,iBAAiB;GAC/B,MAAM,gBAAgB,UAAU,OAAO,oBAAoB;GAC3D,SAAS,eAAe,QAAQ;EAClC,GAAG,GAAG;EAEN,aAAa;GACX,aAAa,OAAO;EACtB;CAEF,GAAG,CAAC,CAAC;AACP"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"LightBoxGallery.mjs","names":["locales","styles"],"sources":["../../../../../../../../../src/components/LightBox/components/LightBoxGallery/LightBoxGallery.tsx"],"sourcesContent":["import { flowComponent } from \"@/lib/componentFactory/flowComponent\";\nimport React, { type ReactNode, useEffect, useRef, useState } from \"react\";\nimport {\n IconChevronLeft,\n IconChevronRight,\n} from \"@/components/Icon/components/icons\";\nimport styles from \"./LightBoxGallery.module.scss\";\nimport type { PropsWithClassName } from \"@/lib/types/props\";\nimport clsx from \"clsx\";\nimport { useLocalizedStringFormatter } from \"react-aria\";\nimport locales from \"../../locales/*.locale.json\";\nimport Button from \"@/components/Button\";\nimport { Controls } from \"@/components/LightBox/components/LightBoxGallery/Controls\";\n\nexport interface LightBoxGalleryProps extends PropsWithClassName {\n children: ReactNode[];\n defaultIndex?: number;\n}\n\n/** @flr-generate all */\nexport const LightBoxGallery = flowComponent(\"LightBoxGallery\", (props) => {\n const { children, className, defaultIndex = 0 } = props;\n\n const [currentIndex, setIndex] = useState(defaultIndex);\n\n const count = React.Children.count(children);\n\n const isFirst = currentIndex === 0;\n const isLast = currentIndex === count - 1;\n\n const pointerStartX = useRef<number | null>(null);\n const swipeThreshold = 50;\n\n const containerRef = useRef<HTMLDivElement>(null);\n\n useEffect(() => {\n containerRef.current?.focus();\n }, [containerRef.current]);\n\n const paginate = (direction: number) => {\n setIndex((prev) => {\n const next = prev + direction;\n\n if (next < 0) return 0;\n if (next >= count) return count - 1;\n\n return next;\n });\n };\n\n const handlePointerDown = (e: React.PointerEvent) => {\n if (!e.isPrimary) return;\n pointerStartX.current = e.clientX;\n };\n\n const handlePointerUp = (e: React.PointerEvent) => {\n if (pointerStartX.current === null) return;\n\n const distance = pointerStartX.current - e.clientX;\n\n if (Math.abs(distance) > swipeThreshold) {\n paginate(distance > 0 ? 1 : -1);\n }\n\n pointerStartX.current = null;\n };\n\n const handlePointerCancel = () => {\n pointerStartX.current = null;\n };\n\n const handleKeyDown = (e: React.KeyboardEvent) => {\n switch (e.key) {\n case \"ArrowLeft\":\n if (!isFirst) paginate(-1);\n break;\n case \"ArrowRight\":\n if (!isLast) paginate(1);\n break;\n }\n };\n\n const stringFormatter = useLocalizedStringFormatter(locales, \"LightBox\");\n\n return (\n <div className={clsx(styles.lightBoxGallery, className)}>\n <div\n ref={containerRef}\n className={styles.content}\n onPointerDown={handlePointerDown}\n onPointerUp={handlePointerUp}\n onPointerCancel={handlePointerCancel}\n tabIndex={0}\n onKeyDown={handleKeyDown}\n role=\"region\"\n aria-roledescription=\"carousel\"\n aria-label={stringFormatter.format(\"gallery\")}\n >\n <div className={styles.galleryItem} key={currentIndex}>\n {children[currentIndex]}\n </div>\n\n <div className={styles.controls}>\n <Button\n aria-label={stringFormatter.format(\"previous\")}\n onPress={() => paginate(-1)}\n color=\"light-static\"\n className={styles.previousButton}\n isDisabled={isFirst}\n >\n <IconChevronLeft />\n </Button>\n\n <Controls count={count} currentIndex={currentIndex} />\n\n <Button\n aria-label={stringFormatter.format(\"next\")}\n onPress={() => paginate(1)}\n color=\"light-static\"\n className={styles.nextButton}\n isDisabled={isLast}\n >\n <IconChevronRight />\n </Button>\n </div>\n </div>\n </div>\n );\n});\n\nexport default LightBoxGallery;\n"],"mappings":";;;;;;;;;;;;;;;AAoBA,IAAa,kBAAkB,cAAc,oBAAoB,UAAU;CACzE,MAAM,EAAE,UAAU,WAAW,eAAe,MAAM;CAElD,MAAM,CAAC,cAAc,YAAY,SAAS,YAAY;CAEtD,MAAM,QAAQ,MAAM,SAAS,MAAM,QAAQ;CAE3C,MAAM,UAAU,iBAAiB;CACjC,MAAM,SAAS,iBAAiB,QAAQ;CAExC,MAAM,gBAAgB,OAAsB,IAAI;CAChD,MAAM,iBAAiB;CAEvB,MAAM,eAAe,OAAuB,IAAI;CAEhD,gBAAgB;EACd,aAAa,SAAS,MAAM;
|
|
1
|
+
{"version":3,"file":"LightBoxGallery.mjs","names":["locales","styles"],"sources":["../../../../../../../../../src/components/LightBox/components/LightBoxGallery/LightBoxGallery.tsx"],"sourcesContent":["import { flowComponent } from \"@/lib/componentFactory/flowComponent\";\nimport React, { type ReactNode, useEffect, useRef, useState } from \"react\";\nimport {\n IconChevronLeft,\n IconChevronRight,\n} from \"@/components/Icon/components/icons\";\nimport styles from \"./LightBoxGallery.module.scss\";\nimport type { PropsWithClassName } from \"@/lib/types/props\";\nimport clsx from \"clsx\";\nimport { useLocalizedStringFormatter } from \"react-aria\";\nimport locales from \"../../locales/*.locale.json\";\nimport Button from \"@/components/Button\";\nimport { Controls } from \"@/components/LightBox/components/LightBoxGallery/Controls\";\n\nexport interface LightBoxGalleryProps extends PropsWithClassName {\n children: ReactNode[];\n defaultIndex?: number;\n}\n\n/** @flr-generate all */\nexport const LightBoxGallery = flowComponent(\"LightBoxGallery\", (props) => {\n const { children, className, defaultIndex = 0 } = props;\n\n const [currentIndex, setIndex] = useState(defaultIndex);\n\n const count = React.Children.count(children);\n\n const isFirst = currentIndex === 0;\n const isLast = currentIndex === count - 1;\n\n const pointerStartX = useRef<number | null>(null);\n const swipeThreshold = 50;\n\n const containerRef = useRef<HTMLDivElement>(null);\n\n useEffect(() => {\n containerRef.current?.focus();\n // eslint-disable-next-line react-hooks/exhaustive-deps -- rerunning once the ref is set takes the focus back from the dialog's autofocus\n }, [containerRef.current]);\n\n const paginate = (direction: number) => {\n setIndex((prev) => {\n const next = prev + direction;\n\n if (next < 0) return 0;\n if (next >= count) return count - 1;\n\n return next;\n });\n };\n\n const handlePointerDown = (e: React.PointerEvent) => {\n if (!e.isPrimary) return;\n pointerStartX.current = e.clientX;\n };\n\n const handlePointerUp = (e: React.PointerEvent) => {\n if (pointerStartX.current === null) return;\n\n const distance = pointerStartX.current - e.clientX;\n\n if (Math.abs(distance) > swipeThreshold) {\n paginate(distance > 0 ? 1 : -1);\n }\n\n pointerStartX.current = null;\n };\n\n const handlePointerCancel = () => {\n pointerStartX.current = null;\n };\n\n const handleKeyDown = (e: React.KeyboardEvent) => {\n switch (e.key) {\n case \"ArrowLeft\":\n if (!isFirst) paginate(-1);\n break;\n case \"ArrowRight\":\n if (!isLast) paginate(1);\n break;\n }\n };\n\n const stringFormatter = useLocalizedStringFormatter(locales, \"LightBox\");\n\n return (\n <div className={clsx(styles.lightBoxGallery, className)}>\n <div\n ref={containerRef}\n className={styles.content}\n onPointerDown={handlePointerDown}\n onPointerUp={handlePointerUp}\n onPointerCancel={handlePointerCancel}\n tabIndex={0}\n onKeyDown={handleKeyDown}\n role=\"region\"\n aria-roledescription=\"carousel\"\n aria-label={stringFormatter.format(\"gallery\")}\n >\n <div className={styles.galleryItem} key={currentIndex}>\n {children[currentIndex]}\n </div>\n\n <div className={styles.controls}>\n <Button\n aria-label={stringFormatter.format(\"previous\")}\n onPress={() => paginate(-1)}\n color=\"light-static\"\n className={styles.previousButton}\n isDisabled={isFirst}\n >\n <IconChevronLeft />\n </Button>\n\n <Controls count={count} currentIndex={currentIndex} />\n\n <Button\n aria-label={stringFormatter.format(\"next\")}\n onPress={() => paginate(1)}\n color=\"light-static\"\n className={styles.nextButton}\n isDisabled={isLast}\n >\n <IconChevronRight />\n </Button>\n </div>\n </div>\n </div>\n );\n});\n\nexport default LightBoxGallery;\n"],"mappings":";;;;;;;;;;;;;;;AAoBA,IAAa,kBAAkB,cAAc,oBAAoB,UAAU;CACzE,MAAM,EAAE,UAAU,WAAW,eAAe,MAAM;CAElD,MAAM,CAAC,cAAc,YAAY,SAAS,YAAY;CAEtD,MAAM,QAAQ,MAAM,SAAS,MAAM,QAAQ;CAE3C,MAAM,UAAU,iBAAiB;CACjC,MAAM,SAAS,iBAAiB,QAAQ;CAExC,MAAM,gBAAgB,OAAsB,IAAI;CAChD,MAAM,iBAAiB;CAEvB,MAAM,eAAe,OAAuB,IAAI;CAEhD,gBAAgB;EACd,aAAa,SAAS,MAAM;CAE9B,GAAG,CAAC,aAAa,OAAO,CAAC;CAEzB,MAAM,YAAY,cAAsB;EACtC,UAAU,SAAS;GACjB,MAAM,OAAO,OAAO;GAEpB,IAAI,OAAO,GAAG,OAAO;GACrB,IAAI,QAAQ,OAAO,OAAO,QAAQ;GAElC,OAAO;EACT,CAAC;CACH;CAEA,MAAM,qBAAqB,MAA0B;EACnD,IAAI,CAAC,EAAE,WAAW;EAClB,cAAc,UAAU,EAAE;CAC5B;CAEA,MAAM,mBAAmB,MAA0B;EACjD,IAAI,cAAc,YAAY,MAAM;EAEpC,MAAM,WAAW,cAAc,UAAU,EAAE;EAE3C,IAAI,KAAK,IAAI,QAAQ,IAAI,gBACvB,SAAS,WAAW,IAAI,IAAI,EAAE;EAGhC,cAAc,UAAU;CAC1B;CAEA,MAAM,4BAA4B;EAChC,cAAc,UAAU;CAC1B;CAEA,MAAM,iBAAiB,MAA2B;EAChD,QAAQ,EAAE,KAAV;GACE,KAAK;IACH,IAAI,CAAC,SAAS,SAAS,EAAE;IACzB;GACF,KAAK,cACH,IAAI,CAAC,QAAQ,SAAS,CAAC;EAE3B;CACF;CAEA,MAAM,kBAAkB,4BAA4BA,kBAAS,UAAU;CAEvE,OACE,oBAAC,OAAD;EAAK,WAAW,KAAKC,+BAAO,iBAAiB,SAAS;EACpD,UAAA,qBAAC,OAAD;GACE,KAAK;GACL,WAAWA,+BAAO;GAClB,eAAe;GACf,aAAa;GACb,iBAAiB;GACjB,UAAU;GACV,WAAW;GACX,MAAK;GACL,wBAAqB;GACrB,cAAY,gBAAgB,OAAO,SAAS;GAV9C,UAAA,CAYE,oBAAC,OAAD;IAAK,WAAWA,+BAAO;IACpB,UAAA,SAAS;GACP,GAFoC,YAEpC,GAEL,qBAAC,OAAD;IAAK,WAAWA,+BAAO;IAAvB,UAAA;KACE,oBAAC,QAAD;MACE,cAAY,gBAAgB,OAAO,UAAU;MAC7C,eAAe,SAAS,EAAE;MAC1B,OAAM;MACN,WAAWA,+BAAO;MAClB,YAAY;MAEZ,UAAA,oBAAC,iBAAD,CAAkB,CAAA;KACZ,CAAA;KAER,oBAAC,UAAD;MAAiB;MAAqB;KAAe,CAAA;KAErD,oBAAC,QAAD;MACE,cAAY,gBAAgB,OAAO,MAAM;MACzC,eAAe,SAAS,CAAC;MACzB,OAAM;MACN,WAAWA,+BAAO;MAClB,YAAY;MAEZ,UAAA,oBAAC,kBAAD,CAAmB,CAAA;KACb,CAAA;IACL;GACF,CAAA,CAAA;;CACF,CAAA;AAET,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useGridItemProps.mjs","names":[],"sources":["../../../../../../../../../../../../src/components/List/components/Items/components/Item/hooks/useGridItemProps.tsx"],"sourcesContent":["import type { PropsWithChildren } from \"react\";\nimport { useEffect, useId, useRef, useState } from \"react\";\nimport type List from \"@/components/List/model/List\";\nimport type { PropsContext } from \"@/lib/propsContext\";\nimport { dynamic, PropsContextProvider } from \"@/lib/propsContext\";\nimport { AccordionButton } from \"@/components/List/components/Items/components/Item/components/AccordionButton\";\n\ninterface P extends PropsWithChildren {\n data: never;\n onAction?: (data: never) => void;\n}\n\nexport const useGridItemProps = (props: P, list: List<never>) => {\n const { data, onAction, children: childrenFromProps } = props;\n const itemView = list.itemView;\n\n const [isExpanded, setIsExpanded] = useState(\n itemView?.defaultExpanded?.(data) ?? false,\n );\n const contentElementId = useId();\n const itemRef = useRef<HTMLDivElement>(null);\n\n const accordion = list.accordion;\n const children = childrenFromProps ?? itemView?.render(data);\n\n useEffect(() => {\n if (accordion) {\n itemRef.current?.setAttribute(\"aria-expanded\", String(isExpanded));\n itemRef.current?.setAttribute(\"aria-controls\", contentElementId);\n }\n }, [isExpanded, contentElementId, itemRef.current, accordion]);\n\n if (!accordion) {\n return {\n gridItemProps: {\n onAction: onAction\n ? () => {\n onAction?.(data);\n }\n : undefined,\n },\n children,\n };\n }\n\n const toggleAccordion = () => {\n setIsExpanded((current) => !current);\n onAction?.(data);\n };\n\n const propsContext: PropsContext = {\n Content: {\n id: dynamic((p) => (p.slot === \"bottom\" ? contentElementId : undefined)),\n wrapWith: dynamic((p) =>\n p.slot === \"bottom\" ? (\n <AccordionButton\n contentElementId={contentElementId}\n toggle={toggleAccordion}\n isExpanded={isExpanded}\n />\n ) : undefined,\n ),\n },\n };\n\n return {\n gridItemProps: {\n ref: itemRef,\n onAction: toggleAccordion,\n },\n children: (\n <PropsContextProvider\n props={propsContext}\n dependencies={[contentElementId, isExpanded]}\n >\n {children}\n </PropsContextProvider>\n ),\n };\n};\n"],"mappings":";;;;;;;;AAYA,IAAa,oBAAoB,OAAU,SAAsB;CAC/D,MAAM,EAAE,MAAM,UAAU,UAAU,sBAAsB;CACxD,MAAM,WAAW,KAAK;CAEtB,MAAM,CAAC,YAAY,iBAAiB,SAClC,UAAU,kBAAkB,IAAI,KAAK,KACvC;CACA,MAAM,mBAAmB,MAAM;CAC/B,MAAM,UAAU,OAAuB,IAAI;CAE3C,MAAM,YAAY,KAAK;CACvB,MAAM,WAAW,qBAAqB,UAAU,OAAO,IAAI;CAE3D,gBAAgB;EACd,IAAI,WAAW;GACb,QAAQ,SAAS,aAAa,iBAAiB,OAAO,UAAU,CAAC;GACjE,QAAQ,SAAS,aAAa,iBAAiB,gBAAgB;EACjE;
|
|
1
|
+
{"version":3,"file":"useGridItemProps.mjs","names":[],"sources":["../../../../../../../../../../../../src/components/List/components/Items/components/Item/hooks/useGridItemProps.tsx"],"sourcesContent":["import type { PropsWithChildren } from \"react\";\nimport { useEffect, useId, useRef, useState } from \"react\";\nimport type List from \"@/components/List/model/List\";\nimport type { PropsContext } from \"@/lib/propsContext\";\nimport { dynamic, PropsContextProvider } from \"@/lib/propsContext\";\nimport { AccordionButton } from \"@/components/List/components/Items/components/Item/components/AccordionButton\";\n\ninterface P extends PropsWithChildren {\n data: never;\n onAction?: (data: never) => void;\n}\n\nexport const useGridItemProps = (props: P, list: List<never>) => {\n const { data, onAction, children: childrenFromProps } = props;\n const itemView = list.itemView;\n\n const [isExpanded, setIsExpanded] = useState(\n itemView?.defaultExpanded?.(data) ?? false,\n );\n const contentElementId = useId();\n const itemRef = useRef<HTMLDivElement>(null);\n\n const accordion = list.accordion;\n const children = childrenFromProps ?? itemView?.render(data);\n\n useEffect(() => {\n if (accordion) {\n itemRef.current?.setAttribute(\"aria-expanded\", String(isExpanded));\n itemRef.current?.setAttribute(\"aria-controls\", contentElementId);\n }\n // eslint-disable-next-line react-hooks/exhaustive-deps -- re-run once the grid item element is attached\n }, [isExpanded, contentElementId, itemRef.current, accordion]);\n\n if (!accordion) {\n return {\n gridItemProps: {\n onAction: onAction\n ? () => {\n onAction?.(data);\n }\n : undefined,\n },\n children,\n };\n }\n\n const toggleAccordion = () => {\n setIsExpanded((current) => !current);\n onAction?.(data);\n };\n\n const propsContext: PropsContext = {\n Content: {\n id: dynamic((p) => (p.slot === \"bottom\" ? contentElementId : undefined)),\n wrapWith: dynamic((p) =>\n p.slot === \"bottom\" ? (\n <AccordionButton\n contentElementId={contentElementId}\n toggle={toggleAccordion}\n isExpanded={isExpanded}\n />\n ) : undefined,\n ),\n },\n };\n\n return {\n gridItemProps: {\n ref: itemRef,\n onAction: toggleAccordion,\n },\n children: (\n <PropsContextProvider\n props={propsContext}\n dependencies={[contentElementId, isExpanded]}\n >\n {children}\n </PropsContextProvider>\n ),\n };\n};\n"],"mappings":";;;;;;;;AAYA,IAAa,oBAAoB,OAAU,SAAsB;CAC/D,MAAM,EAAE,MAAM,UAAU,UAAU,sBAAsB;CACxD,MAAM,WAAW,KAAK;CAEtB,MAAM,CAAC,YAAY,iBAAiB,SAClC,UAAU,kBAAkB,IAAI,KAAK,KACvC;CACA,MAAM,mBAAmB,MAAM;CAC/B,MAAM,UAAU,OAAuB,IAAI;CAE3C,MAAM,YAAY,KAAK;CACvB,MAAM,WAAW,qBAAqB,UAAU,OAAO,IAAI;CAE3D,gBAAgB;EACd,IAAI,WAAW;GACb,QAAQ,SAAS,aAAa,iBAAiB,OAAO,UAAU,CAAC;GACjE,QAAQ,SAAS,aAAa,iBAAiB,gBAAgB;EACjE;CAEF,GAAG;EAAC;EAAY;EAAkB,QAAQ;EAAS;CAAS,CAAC;CAE7D,IAAI,CAAC,WACH,OAAO;EACL,eAAe,EACb,UAAU,iBACA;GACJ,WAAW,IAAI;EACjB,IACA,KAAA,EACN;EACA;CACF;CAGF,MAAM,wBAAwB;EAC5B,eAAe,YAAY,CAAC,OAAO;EACnC,WAAW,IAAI;CACjB;CAEA,MAAM,eAA6B,EACjC,SAAS;EACP,IAAI,SAAS,MAAO,EAAE,SAAS,WAAW,mBAAmB,KAAA,CAAU;EACvE,UAAU,SAAS,MACjB,EAAE,SAAS,WACT,oBAAC,iBAAD;GACoB;GAClB,QAAQ;GACI;EACb,CAAA,IACC,KAAA,CACN;CACF,EACF;CAEA,OAAO;EACL,eAAe;GACb,KAAK;GACL,UAAU;EACZ;EACA,UACE,oBAAC,sBAAD;GACE,OAAO;GACP,cAAc,CAAC,kBAAkB,UAAU;GAE1C;EACmB,CAAA;CAE1B;AACF"}
|
package/dist/js/packages/components/src/components/List/hooks/useAriaAnnounceSearchState.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useAriaAnnounceSearchState.mjs","names":["locales"],"sources":["../../../../../../../../src/components/List/hooks/useAriaAnnounceSearchState.ts"],"sourcesContent":["import { useLocalizedStringFormatter } from \"@/components/TranslationProvider/useLocalizedStringFormatter\";\nimport locales from \"../locales/*.locale.json\";\nimport { announce } from \"@react-aria/live-announcer\";\nimport { useDebounceCallback } from \"usehooks-ts\";\nimport { useEffect } from \"react\";\nimport { useList } from \"@/components/List/hooks/useList\";\n\nconst announceDebounceMs = 600;\n\nexport const useAriaAnnounceSearchState = (): void => {\n const formatter = useLocalizedStringFormatter(locales, \"List\");\n const list = useList();\n const debouncedAnnounce = useDebounceCallback(announce, announceDebounceMs);\n\n const searchTerm = list.search?.value;\n const resultCount = list.batches.getTotalItemsCount();\n const isLoading = list.loader.loaderState.useIsLoading();\n\n useEffect(() => {\n if (isLoading || !searchTerm) {\n debouncedAnnounce.cancel();\n return;\n }\n\n const text = formatter.format(\n resultCount > 0 ? \"search.announce.result\" : \"search.announce.noResult\",\n {\n resultCount,\n searchTerm,\n },\n );\n\n debouncedAnnounce(text, \"polite\");\n }, [searchTerm, resultCount, isLoading]);\n};\n"],"mappings":";;;;;;;;;AAOA,IAAM,qBAAqB;AAE3B,IAAa,mCAAyC;CACpD,MAAM,YAAY,4BAA4BA,kBAAS,MAAM;CAC7D,MAAM,OAAO,QAAQ;CACrB,MAAM,oBAAoB,oBAAoB,UAAU,kBAAkB;CAE1E,MAAM,aAAa,KAAK,QAAQ;CAChC,MAAM,cAAc,KAAK,QAAQ,mBAAmB;CACpD,MAAM,YAAY,KAAK,OAAO,YAAY,aAAa;CAEvD,gBAAgB;EACd,IAAI,aAAa,CAAC,YAAY;GAC5B,kBAAkB,OAAO;GACzB;EACF;EAEA,MAAM,OAAO,UAAU,OACrB,cAAc,IAAI,2BAA2B,4BAC7C;GACE;GACA;EACF,CACF;EAEA,kBAAkB,MAAM,QAAQ;
|
|
1
|
+
{"version":3,"file":"useAriaAnnounceSearchState.mjs","names":["locales"],"sources":["../../../../../../../../src/components/List/hooks/useAriaAnnounceSearchState.ts"],"sourcesContent":["import { useLocalizedStringFormatter } from \"@/components/TranslationProvider/useLocalizedStringFormatter\";\nimport locales from \"../locales/*.locale.json\";\nimport { announce } from \"@react-aria/live-announcer\";\nimport { useDebounceCallback } from \"usehooks-ts\";\nimport { useEffect } from \"react\";\nimport { useList } from \"@/components/List/hooks/useList\";\n\nconst announceDebounceMs = 600;\n\nexport const useAriaAnnounceSearchState = (): void => {\n const formatter = useLocalizedStringFormatter(locales, \"List\");\n const list = useList();\n const debouncedAnnounce = useDebounceCallback(announce, announceDebounceMs);\n\n const searchTerm = list.search?.value;\n const resultCount = list.batches.getTotalItemsCount();\n const isLoading = list.loader.loaderState.useIsLoading();\n\n useEffect(() => {\n if (isLoading || !searchTerm) {\n debouncedAnnounce.cancel();\n return;\n }\n\n const text = formatter.format(\n resultCount > 0 ? \"search.announce.result\" : \"search.announce.noResult\",\n {\n resultCount,\n searchTerm,\n },\n );\n\n debouncedAnnounce(text, \"polite\");\n // eslint-disable-next-line react-hooks/exhaustive-deps -- announce on search changes only, not when the formatter changes\n }, [searchTerm, resultCount, isLoading]);\n};\n"],"mappings":";;;;;;;;;AAOA,IAAM,qBAAqB;AAE3B,IAAa,mCAAyC;CACpD,MAAM,YAAY,4BAA4BA,kBAAS,MAAM;CAC7D,MAAM,OAAO,QAAQ;CACrB,MAAM,oBAAoB,oBAAoB,UAAU,kBAAkB;CAE1E,MAAM,aAAa,KAAK,QAAQ;CAChC,MAAM,cAAc,KAAK,QAAQ,mBAAmB;CACpD,MAAM,YAAY,KAAK,OAAO,YAAY,aAAa;CAEvD,gBAAgB;EACd,IAAI,aAAa,CAAC,YAAY;GAC5B,kBAAkB,OAAO;GACzB;EACF;EAEA,MAAM,OAAO,UAAU,OACrB,cAAc,IAAI,2BAA2B,4BAC7C;GACE;GACA;EACF,CACF;EAEA,kBAAkB,MAAM,QAAQ;CAElC,GAAG;EAAC;EAAY;EAAa;CAAS,CAAC;AACzC"}
|
|
@@ -71,9 +71,10 @@ var List = class List {
|
|
|
71
71
|
this.viewMode = ListViewMode.useNew(this, { defaultViewMode });
|
|
72
72
|
this.emptyView = emptyView;
|
|
73
73
|
this.emptySearchResultView = emptySearchResultView;
|
|
74
|
+
const listFilters = this.filters;
|
|
74
75
|
useEffect(() => {
|
|
75
|
-
|
|
76
|
-
}, [
|
|
76
|
+
listFilters.forEach((f) => f.deleteUnknownFilterValues());
|
|
77
|
+
}, [listFilters]);
|
|
77
78
|
}
|
|
78
79
|
get dataTable() {
|
|
79
80
|
return this.reactTable.table;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"List.mjs","names":["BatchesController"],"sources":["../../../../../../../../src/components/List/model/List.ts"],"sourcesContent":["import { ItemCollection } from \"@/components/List/model/item/ItemCollection\";\nimport { BatchesController } from \"@/components/List/model/pagination/BatchesController\";\nimport { Filter } from \"./filter/Filter\";\nimport { Sorting } from \"@/components/List/model/sorting/Sorting\";\nimport ReactTable from \"@/components/List/model/ReactTable\";\nimport type {\n EmptyViewType,\n GetItemId,\n ItemActionFn,\n ListSettingsStorageDefaults,\n ListShape,\n ListSupportedComponentProps,\n} from \"@/components/List/model/types\";\nimport { IncrementalLoader } from \"@/components/List/model/loading/IncrementalLoader\";\nimport invariant from \"invariant\";\nimport { Search } from \"@/components/List/model/search/Search\";\nimport { ItemView } from \"@/components/List/model/item/ItemView\";\nimport { Table } from \"@/components/List/model/table/Table\";\nimport { useEffect, type ReactNode } from \"react\";\nimport { ListSettingsStore } from \"./ListSettingsStore\";\nimport { ListViewMode } from \"./ListViewMode\";\nimport { useSettings } from \"@/components/SettingsProvider/SettingsProvider\";\nimport { DateRangeFilter } from \"@/components/List/model/filter/DateRangeFilter\";\nimport { useWarnDeprecation } from \"@/components/DeprecationWarningProvider\";\nimport type {\n ListModelContext,\n ListSettingsPort,\n} from \"@mittwald/flow-components-base\";\nimport type { Table as ReactTableInstance } from \"@tanstack/table-core\";\n\nexport class List<T = unknown, TMeta = unknown> implements ListModelContext<T> {\n public readonly filters: (\n Filter<T, never, never> | DateRangeFilter<T, never>\n )[];\n public readonly itemView?: ItemView<T>;\n public readonly table?: Table<T>;\n public readonly search?: Search<T>;\n public readonly sorting: Sorting<T>[];\n public readonly items: ItemCollection<T>;\n public readonly reactTable: ReactTable<T>;\n public readonly batches: BatchesController<T>;\n public readonly loader: IncrementalLoader<T>;\n public readonly onAction?: ItemActionFn<T>;\n public readonly accordion: boolean;\n public readonly infiniteScroll: boolean;\n public readonly getItemId?: GetItemId<T>;\n public readonly componentProps: ListSupportedComponentProps;\n public metadata?: TMeta;\n public readonly settingsStorage?: ListSettingsStore<T>;\n public readonly loadingItemsCount;\n public readonly viewMode: ListViewMode<T>;\n public readonly emptyView?: ReactNode;\n public readonly emptySearchResultView?: ReactNode;\n public readonly settingsStorageDefaults?: ListSettingsStorageDefaults;\n\n public constructor(shape: ListShape<T, TMeta>) {\n const {\n settingStorageKey,\n itemView,\n table,\n filters = [],\n sorting = [],\n batchesController,\n onChange,\n loader,\n search,\n onAction,\n getItemId,\n defaultViewMode,\n accordion = false,\n infiniteScroll = false,\n loadingItemsCount = 5,\n settingsStorageDefaults,\n emptyView,\n emptySearchResultView,\n ...componentProps\n } = shape;\n\n const warnDeprecation = useWarnDeprecation();\n if (itemView?.fallback !== undefined) {\n warnDeprecation(\n \"The 'fallback' prop is deprecated and will be removed in a future release. Use 'loadingView' instead.\",\n );\n }\n if (itemView?.dependencies !== undefined) {\n warnDeprecation(\n \"The 'dependencies' prop of 'List.Item' is deprecated and will be removed in a future release. Use 'renderDependencies' instead.\",\n );\n }\n\n this.settingsStorageDefaults = settingsStorageDefaults;\n const generalSettingsStore = useSettings();\n\n this.settingsStorage =\n settingStorageKey && generalSettingsStore\n ? new ListSettingsStore(this, generalSettingsStore, {\n storageKey: settingStorageKey,\n })\n : undefined;\n\n this.items = new ItemCollection(this);\n this.filters = filters.map((shape) =>\n shape.mode === \"dateRange\"\n ? new DateRangeFilter(this, shape)\n : new Filter(this, shape),\n );\n this.sorting = sorting.map((shape) => new Sorting<T>(this, shape));\n this.search = search ? new Search(this, search) : undefined;\n this.itemView = itemView ? new ItemView(this, itemView) : undefined;\n this.accordion = accordion;\n this.infiniteScroll = infiniteScroll;\n this.table = table ? new Table(this, table) : undefined;\n this.batches = new BatchesController(this, batchesController);\n\n /*\n * The controller no longer subscribes itself: the filters and the search\n * are this list's, and handing a list of concrete filters to a shared\n * model is the `Table<never>` variance trap. `IncrementalLoader` still\n * subscribes in its own constructor, which runs right after this, so the\n * order of the two resets is unchanged.\n */\n this.filters.forEach((f) => f.onFilterUpdated(() => this.batches.reset()));\n this.search?.onUpdated(() => this.batches.reset());\n this.componentProps = componentProps;\n /*\n * Before the loader: its state takes `getItemId` over in its constructor,\n * and a loader built first would never deduplicate.\n */\n this.getItemId = getItemId;\n this.loader = IncrementalLoader.useNew<T>(this, loader);\n this.onAction = onAction;\n this.loadingItemsCount = loadingItemsCount;\n this.reactTable = ReactTable.useNew(this, onChange, {\n manualFiltering: this.loader.manualFiltering,\n manualPagination: this.loader.manualPagination,\n manualSorting: this.loader.manualSorting,\n });\n this.viewMode = ListViewMode.useNew(this, { defaultViewMode });\n this.emptyView = emptyView;\n this.emptySearchResultView = emptySearchResultView;\n\n useEffect(() => {\n this.filters.forEach((f) => f.deleteUnknownFilterValues());\n }, [this.filters]);\n }\n\n /*\n * `ListModelContext` — what the shared model in\n * `@mittwald/flow-components-base` reaches for, so `Sorting` and `Search` can\n * keep being handed the list itself. Getters, because the model is built\n * before the table is.\n */\n public get dataTable(): ReactTableInstance<T> {\n return this.reactTable.table;\n }\n\n public get settings(): ListSettingsPort | undefined {\n return this.settingsStorage;\n }\n\n public get settingsDefaults(): ListSettingsStorageDefaults | undefined {\n return this.settingsStorageDefaults;\n }\n\n public getEmptyViewType(): EmptyViewType {\n return this.hasActiveFilters || this.search?.isSet ? \"search\" : \"list\";\n }\n\n public get hasActiveFilters(): boolean {\n return this.filters.some((f) => f.isActive());\n }\n\n public get visibleSorting() {\n return this.sorting.filter((s) => s.initialEnabled !== \"hidden\");\n }\n\n public static useNew<T, TMeta = unknown>(\n shape: ListShape<T, TMeta>,\n ): List<T, TMeta> {\n return new List<T, TMeta>(shape);\n }\n\n public getSorting(id: string): Sorting<T> {\n const sorting = this.sorting.find((s) => s.id === id);\n invariant(!!sorting, `Could not get Sorting (ID: ${id})`);\n return sorting;\n }\n\n public clearSorting(): void {\n return this.sorting.forEach((s) => s.clear());\n }\n\n public resetFilters(): void {\n return this.filters.forEach((f) => f.resetValues());\n }\n\n public clearFilters(): void {\n return this.filters.forEach((f) => f.clear());\n }\n\n public useIsEmpty(): boolean {\n return !this.loader.useIsLoading() && this.items.entries.length === 0;\n }\n}\n\nexport default List;\n"],"mappings":";;;;;;;;;;;;;;;;;;;AA8BA,IAAa,OAAb,MAAa,KAAkE;CAC7E;CAGA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CAEA,YAAmB,OAA4B;EAC7C,MAAM,EACJ,mBACA,UACA,OACA,UAAU,CAAC,GACX,UAAU,CAAC,GACX,mBACA,UACA,QACA,QACA,UACA,WACA,iBACA,YAAY,OACZ,iBAAiB,OACjB,oBAAoB,GACpB,yBACA,WACA,uBACA,GAAG,mBACD;EAEJ,MAAM,kBAAkB,mBAAmB;EAC3C,IAAI,UAAU,aAAa,KAAA,GACzB,gBACE,uGACF;EAEF,IAAI,UAAU,iBAAiB,KAAA,GAC7B,gBACE,iIACF;EAGF,KAAK,0BAA0B;EAC/B,MAAM,uBAAuB,YAAY;EAEzC,KAAK,kBACH,qBAAqB,uBACjB,IAAI,kBAAkB,MAAM,sBAAsB,EAChD,YAAY,kBACd,CAAC,IACD,KAAA;EAEN,KAAK,QAAQ,IAAI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K,oBAAoB,KAAK,QAAQ,QAAQ,WAAW;CAClE;CAEA,IAAW,mBAA4B;EACrC,OAAO,KAAK,QAAQ,MAAM,MAAM,EAAE,SAAS,CAAC;CAC9C;CAEA,IAAW,iBAAiB;EAC1B,OAAO,KAAK,QAAQ,QAAQ,MAAM,EAAE,mBAAmB,QAAQ;CACjE;CAEA,OAAc,OACZ,OACgB;EAChB,OAAO,IAAI,KAAe,KAAK;CACjC;CAEA,WAAkB,IAAwB;EACxC,MAAM,UAAU,KAAK,QAAQ,MAAM,MAAM,EAAE,OAAO,EAAE;EACpD,UAAU,CAAC,CAAC,SAAS,8BAA8B,GAAG,EAAE;EACxD,OAAO;CACT;CAEA,eAA4B;EAC1B,OAAO,KAAK,QAAQ,SAAS,MAAM,EAAE,MAAM,CAAC;CAC9C;CAEA,eAA4B;EAC1B,OAAO,KAAK,QAAQ,SAAS,MAAM,EAAE,YAAY,CAAC;CACpD;CAEA,eAA4B;EAC1B,OAAO,KAAK,QAAQ,SAAS,MAAM,EAAE,MAAM,CAAC;CAC9C;CAEA,aAA6B;EAC3B,OAAO,CAAC,KAAK,OAAO,aAAa,KAAK,KAAK,MAAM,QAAQ,WAAW;CACtE;AACF"}
|
|
1
|
+
{"version":3,"file":"List.mjs","names":["BatchesController"],"sources":["../../../../../../../../src/components/List/model/List.ts"],"sourcesContent":["import { ItemCollection } from \"@/components/List/model/item/ItemCollection\";\nimport { BatchesController } from \"@/components/List/model/pagination/BatchesController\";\nimport { Filter } from \"./filter/Filter\";\nimport { Sorting } from \"@/components/List/model/sorting/Sorting\";\nimport ReactTable from \"@/components/List/model/ReactTable\";\nimport type {\n EmptyViewType,\n GetItemId,\n ItemActionFn,\n ListSettingsStorageDefaults,\n ListShape,\n ListSupportedComponentProps,\n} from \"@/components/List/model/types\";\nimport { IncrementalLoader } from \"@/components/List/model/loading/IncrementalLoader\";\nimport invariant from \"invariant\";\nimport { Search } from \"@/components/List/model/search/Search\";\nimport { ItemView } from \"@/components/List/model/item/ItemView\";\nimport { Table } from \"@/components/List/model/table/Table\";\nimport { useEffect, type ReactNode } from \"react\";\nimport { ListSettingsStore } from \"./ListSettingsStore\";\nimport { ListViewMode } from \"./ListViewMode\";\nimport { useSettings } from \"@/components/SettingsProvider/SettingsProvider\";\nimport { DateRangeFilter } from \"@/components/List/model/filter/DateRangeFilter\";\nimport { useWarnDeprecation } from \"@/components/DeprecationWarningProvider\";\nimport type {\n ListModelContext,\n ListSettingsPort,\n} from \"@mittwald/flow-components-base\";\nimport type { Table as ReactTableInstance } from \"@tanstack/table-core\";\n\nexport class List<T = unknown, TMeta = unknown> implements ListModelContext<T> {\n public readonly filters: (\n Filter<T, never, never> | DateRangeFilter<T, never>\n )[];\n public readonly itemView?: ItemView<T>;\n public readonly table?: Table<T>;\n public readonly search?: Search<T>;\n public readonly sorting: Sorting<T>[];\n public readonly items: ItemCollection<T>;\n public readonly reactTable: ReactTable<T>;\n public readonly batches: BatchesController<T>;\n public readonly loader: IncrementalLoader<T>;\n public readonly onAction?: ItemActionFn<T>;\n public readonly accordion: boolean;\n public readonly infiniteScroll: boolean;\n public readonly getItemId?: GetItemId<T>;\n public readonly componentProps: ListSupportedComponentProps;\n public metadata?: TMeta;\n public readonly settingsStorage?: ListSettingsStore<T>;\n public readonly loadingItemsCount;\n public readonly viewMode: ListViewMode<T>;\n public readonly emptyView?: ReactNode;\n public readonly emptySearchResultView?: ReactNode;\n public readonly settingsStorageDefaults?: ListSettingsStorageDefaults;\n\n public constructor(shape: ListShape<T, TMeta>) {\n const {\n settingStorageKey,\n itemView,\n table,\n filters = [],\n sorting = [],\n batchesController,\n onChange,\n loader,\n search,\n onAction,\n getItemId,\n defaultViewMode,\n accordion = false,\n infiniteScroll = false,\n loadingItemsCount = 5,\n settingsStorageDefaults,\n emptyView,\n emptySearchResultView,\n ...componentProps\n } = shape;\n\n const warnDeprecation = useWarnDeprecation();\n if (itemView?.fallback !== undefined) {\n warnDeprecation(\n \"The 'fallback' prop is deprecated and will be removed in a future release. Use 'loadingView' instead.\",\n );\n }\n if (itemView?.dependencies !== undefined) {\n warnDeprecation(\n \"The 'dependencies' prop of 'List.Item' is deprecated and will be removed in a future release. Use 'renderDependencies' instead.\",\n );\n }\n\n this.settingsStorageDefaults = settingsStorageDefaults;\n const generalSettingsStore = useSettings();\n\n this.settingsStorage =\n settingStorageKey && generalSettingsStore\n ? new ListSettingsStore(this, generalSettingsStore, {\n storageKey: settingStorageKey,\n })\n : undefined;\n\n this.items = new ItemCollection(this);\n this.filters = filters.map((shape) =>\n shape.mode === \"dateRange\"\n ? new DateRangeFilter(this, shape)\n : new Filter(this, shape),\n );\n this.sorting = sorting.map((shape) => new Sorting<T>(this, shape));\n this.search = search ? new Search(this, search) : undefined;\n this.itemView = itemView ? new ItemView(this, itemView) : undefined;\n this.accordion = accordion;\n this.infiniteScroll = infiniteScroll;\n this.table = table ? new Table(this, table) : undefined;\n this.batches = new BatchesController(this, batchesController);\n\n /*\n * The controller no longer subscribes itself: the filters and the search\n * are this list's, and handing a list of concrete filters to a shared\n * model is the `Table<never>` variance trap. `IncrementalLoader` still\n * subscribes in its own constructor, which runs right after this, so the\n * order of the two resets is unchanged.\n */\n this.filters.forEach((f) => f.onFilterUpdated(() => this.batches.reset()));\n this.search?.onUpdated(() => this.batches.reset());\n this.componentProps = componentProps;\n /*\n * Before the loader: its state takes `getItemId` over in its constructor,\n * and a loader built first would never deduplicate.\n */\n this.getItemId = getItemId;\n this.loader = IncrementalLoader.useNew<T>(this, loader);\n this.onAction = onAction;\n this.loadingItemsCount = loadingItemsCount;\n this.reactTable = ReactTable.useNew(this, onChange, {\n manualFiltering: this.loader.manualFiltering,\n manualPagination: this.loader.manualPagination,\n manualSorting: this.loader.manualSorting,\n });\n this.viewMode = ListViewMode.useNew(this, { defaultViewMode });\n this.emptyView = emptyView;\n this.emptySearchResultView = emptySearchResultView;\n\n const listFilters = this.filters;\n useEffect(() => {\n listFilters.forEach((f) => f.deleteUnknownFilterValues());\n }, [listFilters]);\n }\n\n /*\n * `ListModelContext` — what the shared model in\n * `@mittwald/flow-components-base` reaches for, so `Sorting` and `Search` can\n * keep being handed the list itself. Getters, because the model is built\n * before the table is.\n */\n public get dataTable(): ReactTableInstance<T> {\n return this.reactTable.table;\n }\n\n public get settings(): ListSettingsPort | undefined {\n return this.settingsStorage;\n }\n\n public get settingsDefaults(): ListSettingsStorageDefaults | undefined {\n return this.settingsStorageDefaults;\n }\n\n public getEmptyViewType(): EmptyViewType {\n return this.hasActiveFilters || this.search?.isSet ? \"search\" : \"list\";\n }\n\n public get hasActiveFilters(): boolean {\n return this.filters.some((f) => f.isActive());\n }\n\n public get visibleSorting() {\n return this.sorting.filter((s) => s.initialEnabled !== \"hidden\");\n }\n\n public static useNew<T, TMeta = unknown>(\n shape: ListShape<T, TMeta>,\n ): List<T, TMeta> {\n return new List<T, TMeta>(shape);\n }\n\n public getSorting(id: string): Sorting<T> {\n const sorting = this.sorting.find((s) => s.id === id);\n invariant(!!sorting, `Could not get Sorting (ID: ${id})`);\n return sorting;\n }\n\n public clearSorting(): void {\n return this.sorting.forEach((s) => s.clear());\n }\n\n public resetFilters(): void {\n return this.filters.forEach((f) => f.resetValues());\n }\n\n public clearFilters(): void {\n return this.filters.forEach((f) => f.clear());\n }\n\n public useIsEmpty(): boolean {\n return !this.loader.useIsLoading() && this.items.entries.length === 0;\n }\n}\n\nexport default List;\n"],"mappings":";;;;;;;;;;;;;;;;;;;AA8BA,IAAa,OAAb,MAAa,KAAkE;CAC7E;CAGA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CAEA,YAAmB,OAA4B;EAC7C,MAAM,EACJ,mBACA,UACA,OACA,UAAU,CAAC,GACX,UAAU,CAAC,GACX,mBACA,UACA,QACA,QACA,UACA,WACA,iBACA,YAAY,OACZ,iBAAiB,OACjB,oBAAoB,GACpB,yBACA,WACA,uBACA,GAAG,mBACD;EAEJ,M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jB,KAAK,wBAAwB;EAE7B,MAAM,cAAc,KAAK;EACzB,gBAAgB;GACd,YAAY,SAAS,MAAM,EAAE,0BAA0B,CAAC;EAC1D,GAAG,CAAC,WAAW,CAAC;CAClB;CAQA,IAAW,YAAmC;EAC5C,OAAO,KAAK,WAAW;CACzB;CAEA,IAAW,WAAyC;EAClD,OAAO,KAAK;CACd;CAEA,IAAW,mBAA4D;EACrE,OAAO,KAAK;CACd;CAEA,mBAAyC;EACvC,OAAO,KAAK,oBAAoB,KAAK,QAAQ,QAAQ,WAAW;CAClE;CAEA,IAAW,mBAA4B;EACrC,OAAO,KAAK,QAAQ,MAAM,MAAM,EAAE,SAAS,CAAC;CAC9C;CAEA,IAAW,iBAAiB;EAC1B,OAAO,KAAK,QAAQ,QAAQ,MAAM,EAAE,mBAAmB,QAAQ;CACjE;CAEA,OAAc,OACZ,OACgB;EAChB,OAAO,IAAI,KAAe,KAAK;CACjC;CAEA,WAAkB,IAAwB;EACxC,MAAM,UAAU,KAAK,QAAQ,MAAM,MAAM,EAAE,OAAO,EAAE;EACpD,UAAU,CAAC,CAAC,SAAS,8BAA8B,GAAG,EAAE;EACxD,OAAO;CACT;CAEA,eAA4B;EAC1B,OAAO,KAAK,QAAQ,SAAS,MAAM,EAAE,MAAM,CAAC;CAC9C;CAEA,eAA4B;EAC1B,OAAO,KAAK,QAAQ,SAAS,MAAM,EAAE,YAAY,CAAC;CACpD;CAEA,eAA4B;EAC1B,OAAO,KAAK,QAAQ,SAAS,MAAM,EAAE,MAAM,CAAC;CAC9C;CAEA,aAA6B;EAC3B,OAAO,CAAC,KAAK,OAAO,aAAa,KAAK,KAAK,MAAM,QAAQ,WAAW;CACtE;AACF"}
|
|
@@ -66,10 +66,13 @@ var IncrementalLoader = class IncrementalLoader {
|
|
|
66
66
|
getUseData() {
|
|
67
67
|
const dataSource = this.dataSource;
|
|
68
68
|
return (options) => {
|
|
69
|
-
if ("staticData" in dataSource)
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
69
|
+
if ("staticData" in dataSource) {
|
|
70
|
+
const staticData = dataSource.staticData;
|
|
71
|
+
return useMemo(() => ({
|
|
72
|
+
data: staticData,
|
|
73
|
+
itemTotalCount: staticData.length
|
|
74
|
+
}), [staticData]);
|
|
75
|
+
}
|
|
73
76
|
if ("useData" in dataSource) return dataSource.useData(options);
|
|
74
77
|
if ("asyncLoader" in dataSource) {
|
|
75
78
|
const asyncLoader = dataSource.asyncLoader;
|
|
@@ -91,8 +94,8 @@ var IncrementalLoader = class IncrementalLoader {
|
|
|
91
94
|
useLoadBatch: () => {
|
|
92
95
|
const loaderOptions = this.getDataLoaderOptions(batchIndex);
|
|
93
96
|
const loaderResult = useData(loaderOptions);
|
|
94
|
-
const { data, itemTotalCount, metadata } = loaderResult;
|
|
95
97
|
useEffect(() => {
|
|
98
|
+
const { data, itemTotalCount, metadata } = loaderResult;
|
|
96
99
|
this.loaderState.setDataBatch(batchIndex, data);
|
|
97
100
|
if (itemTotalCount !== void 0) this.list.batches.updateItemTotalCount(itemTotalCount);
|
|
98
101
|
this.loaderState.setMetadata(metadata);
|
|
@@ -102,7 +105,7 @@ var IncrementalLoader = class IncrementalLoader {
|
|
|
102
105
|
useRenderSuspense: () => {
|
|
103
106
|
useEffect(() => {
|
|
104
107
|
this.loaderState.setBatchLoadingState(batchIndex, "loading");
|
|
105
|
-
}, [
|
|
108
|
+
}, []);
|
|
106
109
|
}
|
|
107
110
|
}));
|
|
108
111
|
}
|
package/dist/js/packages/components/src/components/List/model/loading/IncrementalLoader.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"IncrementalLoader.mjs","names":[],"sources":["../../../../../../../../../src/components/List/model/loading/IncrementalLoader.ts"],"sourcesContent":["import type List from \"@/components/List/model/List\";\nimport type {\n DataLoaderOptions,\n DataLoaderResult,\n DataSource,\n IncrementalLoaderShape,\n LoaderInvocationHook,\n} from \"@/components/List/model/loading/types\";\nimport type { AsyncResource } from \"@mittwald/react-use-promise\";\nimport { getAsyncResource, usePromise } from \"@mittwald/react-use-promise\";\nimport { useEffect } from \"react\";\nimport { times } from \"remeda\";\nimport { IncrementalLoaderState } from \"@/components/List/model/loading/IncrementalLoaderState\";\nimport { getListDataLoaderOptions } from \"@mittwald/flow-components-base\";\nimport { hash } from \"object-code\";\nimport type { PropertyName } from \"@/components/List/model/types\";\nimport { useMemo } from \"react\";\nimport { useComponentDefaults } from \"@/components/ComponentDefaultsProvider\";\n\nconst emptyData: never[] = [];\n\nexport class IncrementalLoader<T> {\n private readonly list: List<T>;\n private readonly dataSource: DataSource<T>;\n public readonly manualSorting: boolean;\n public readonly manualFiltering: boolean;\n public readonly manualPagination: boolean;\n public readonly disableInitialSuspenseBoundary: boolean;\n public readonly loaderState: IncrementalLoaderState<T>;\n public readonly staticDataProperties: PropertyName<T>[] = [];\n\n private constructor(list: List<T>, shape: IncrementalLoaderShape<T> = {}) {\n const { source } = shape;\n\n this.dataSource = source ?? { staticData: emptyData };\n\n const {\n disableInitialSuspenseBoundary: disableInitialSuspenseBoundaryDefault,\n } = useComponentDefaults(\"List\");\n\n this.disableInitialSuspenseBoundary =\n \"disableInitialSuspenseBoundary\" in this.dataSource\n ? (this.dataSource.disableInitialSuspenseBoundary ??\n disableInitialSuspenseBoundaryDefault)\n : disableInitialSuspenseBoundaryDefault;\n\n const manualPagination =\n \"manualPagination\" in this.dataSource\n ? this.dataSource.manualPagination\n : undefined;\n\n const manualFiltering =\n \"manualFiltering\" in this.dataSource\n ? this.dataSource.manualFiltering\n : undefined;\n\n const manualSorting =\n \"manualSorting\" in this.dataSource\n ? this.dataSource.manualSorting\n : undefined;\n\n this.list = list;\n this.loaderState = IncrementalLoaderState.useNew<T>(list);\n\n this.manualPagination = manualPagination ?? false;\n this.manualFiltering = manualFiltering ?? this.manualPagination;\n this.manualSorting = manualSorting ?? this.manualPagination;\n this.list.filters.forEach((f) => f.onFilterUpdated(() => this.reset()));\n this.list.search?.onUpdated(() => this.reset());\n\n this.initStaticDataProperties();\n }\n\n public static useNew<T>(\n list: List<T>,\n shape: IncrementalLoaderShape<T> = {},\n ): IncrementalLoader<T> {\n return new IncrementalLoader(list, shape);\n }\n\n private initStaticDataProperties() {\n const addPropertiesOfDataEntry = (data: unknown) => {\n if (typeof data !== \"object\" || data === null) {\n return;\n }\n\n (Object.keys(data) as PropertyName<T>[])\n .filter((p) => !this.staticDataProperties.includes(p))\n .forEach((p) => {\n this.staticDataProperties.push(p);\n });\n };\n\n if (\"staticData\" in this.dataSource) {\n this.dataSource.staticData\n // collect properties from just the first 100 items\n .slice(0, 100)\n .forEach(addPropertiesOfDataEntry);\n }\n }\n\n private reset(): void {\n this.loaderState.reset();\n }\n\n public useIsLoading(): boolean {\n return this.loaderState.useIsLoading();\n }\n\n public useIsInitiallyLoading(): boolean {\n return this.loaderState.useIsInitiallyLoading();\n }\n\n public useIsLoadingMore(): boolean {\n return this.loaderState.useIsLoadingMore();\n }\n\n public useData(): T[] {\n return this.loaderState.useMergedData();\n }\n\n private getUseData(): (options: DataLoaderOptions<T>) => DataLoaderResult<T> {\n const dataSource = this.dataSource;\n\n return (options: DataLoaderOptions<T>) => {\n if (\"staticData\" in dataSource) {\n return useMemo(\n () => ({\n data: dataSource.staticData,\n itemTotalCount: dataSource.staticData.length,\n }),\n [dataSource.staticData],\n );\n }\n\n if (\"useData\" in dataSource) {\n return dataSource.useData(options);\n }\n\n if (\"asyncLoader\" in dataSource) {\n const asyncLoader = dataSource.asyncLoader;\n const dependencies = dataSource.dependencies;\n const loaderId = dependencies\n ? hash(dependencies).toString()\n : undefined;\n\n return usePromise(asyncLoader, [options], {\n loaderId,\n });\n }\n\n if (\"asyncResourceFactory\" in dataSource) {\n return dataSource.asyncResourceFactory(options).use();\n }\n\n return useMemo(\n () => ({\n data: [],\n itemTotalCount: 0,\n }),\n [],\n );\n };\n }\n\n public getLoaderInvocationHooks(): LoaderInvocationHook[] {\n const batchesCount = times(this.list.batches.getBatchIndex() + 1, (i) => i);\n const useData = this.getUseData();\n\n return batchesCount.map((batchIndex) => ({\n useLoadBatch: () => {\n const loaderOptions = this.getDataLoaderOptions(batchIndex);\n const loaderResult = useData(loaderOptions);\n const { data, itemTotalCount, metadata } = loaderResult;\n\n useEffect(() => {\n this.loaderState.setDataBatch(batchIndex, data);\n\n if (itemTotalCount !== undefined) {\n this.list.batches.updateItemTotalCount(itemTotalCount);\n }\n\n this.loaderState.setMetadata(metadata);\n\n this.loaderState.setBatchLoadingState(batchIndex, \"loaded\");\n }, [loaderResult]);\n },\n\n useRenderSuspense: () => {\n useEffect(() => {\n this.loaderState.setBatchLoadingState(batchIndex, \"loading\");\n }, [batchIndex]);\n },\n }));\n }\n\n private getDataLoaderOptions(batchIndex: number): DataLoaderOptions<T> {\n return getListDataLoaderOptions<T>(\n {\n batchSize: this.list.batches.batchSize,\n modes: this,\n sorting: this.list.sorting,\n filters: this.list.filters,\n searchString: this.list.reactTable.searchString,\n },\n batchIndex,\n );\n }\n\n private getBatchDataAsyncResource(\n batchIndex: number,\n ): AsyncResource<DataLoaderResult<T>> {\n const dataSource = this.dataSource;\n const loaderOptions = this.getDataLoaderOptions(batchIndex);\n\n if (\"staticData\" in dataSource) {\n return getAsyncResource(\n async (staticData) => ({\n data: staticData as T[],\n itemTotalCount: staticData.length,\n }),\n [dataSource.staticData],\n );\n }\n\n if (\"asyncLoader\" in dataSource) {\n const asyncLoader = dataSource.asyncLoader;\n const dependencies = dataSource.dependencies;\n const loaderId = dependencies ? hash(dependencies).toString() : undefined;\n return getAsyncResource(asyncLoader, [loaderOptions], {\n loaderId,\n });\n }\n\n if (\"asyncResourceFactory\" in dataSource) {\n const asyncResourceFactory = dataSource.asyncResourceFactory;\n return asyncResourceFactory(loaderOptions);\n }\n\n throw new Error(\"Unknown data source\");\n }\n}\n"],"mappings":";;;;;;;;;;;AAmBA,IAAM,YAAqB,CAAC;AAE5B,IAAa,oBAAb,MAAa,kBAAqB;CAChC;CACA;CACA;CACA;CACA;CACA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K,YAAY,qBAAqB,YAAY,QAAQ;IAC5D,GAAG,CAAC,YAAY,CAAC;GACnB;GAEA,yBAAyB;IACvB,gBAAgB;KACd,KAAK,YAAY,qBAAqB,YAAY,SAAS;IAC7D,GAAG,CAAC,UAAU,CAAC;GACjB;EACF,EAAE;CACJ;CAEA,qBAA6B,YAA0C;EACrE,OAAO,yBACL;GACE,WAAW,KAAK,KAAK,QAAQ;GAC7B,OAAO;GACP,SAAS,KAAK,KAAK;GACnB,SAAS,KAAK,KAAK;GACnB,cAAc,KAAK,KAAK,WAAW;EACrC,GACA,UACF;CACF;CAEA,0BACE,YACoC;EACpC,MAAM,aAAa,KAAK;EACxB,MAAM,gBAAgB,KAAK,qBAAqB,UAAU;EAE1D,IAAI,gBAAgB,YAClB,OAAO,iBACL,OAAO,gBAAgB;GACrB,MAAM;GACN,gBAAgB,WAAW;EAC7B,IACA,CAAC,WAAW,UAAU,CACxB;EAGF,IAAI,iBAAiB,YAAY;GAC/B,MAAM,cAAc,WAAW;GAC/B,MAAM,eAAe,WAAW;GAChC,MAAM,WAAW,eAAe,KAAK,YAAY,CAAC,CAAC,SAAS,IAAI,KAAA;GAChE,OAAO,iBAAiB,aAAa,CAAC,aAAa,GAAG,EACpD,SACF,CAAC;EACH;EAEA,IAAI,0BAA0B,YAAY;GACxC,MAAM,uBAAuB,WAAW;GACxC,OAAO,qBAAqB,aAAa;EAC3C;EAEA,MAAM,IAAI,MAAM,qBAAqB;CACvC;AACF"}
|
|
1
|
+
{"version":3,"file":"IncrementalLoader.mjs","names":[],"sources":["../../../../../../../../../src/components/List/model/loading/IncrementalLoader.ts"],"sourcesContent":["import type List from \"@/components/List/model/List\";\nimport type {\n DataLoaderOptions,\n DataLoaderResult,\n DataSource,\n IncrementalLoaderShape,\n LoaderInvocationHook,\n} from \"@/components/List/model/loading/types\";\nimport type { AsyncResource } from \"@mittwald/react-use-promise\";\nimport { getAsyncResource, usePromise } from \"@mittwald/react-use-promise\";\nimport { useEffect } from \"react\";\nimport { times } from \"remeda\";\nimport { IncrementalLoaderState } from \"@/components/List/model/loading/IncrementalLoaderState\";\nimport { getListDataLoaderOptions } from \"@mittwald/flow-components-base\";\nimport { hash } from \"object-code\";\nimport type { PropertyName } from \"@/components/List/model/types\";\nimport { useMemo } from \"react\";\nimport { useComponentDefaults } from \"@/components/ComponentDefaultsProvider\";\n\nconst emptyData: never[] = [];\n\nexport class IncrementalLoader<T> {\n private readonly list: List<T>;\n private readonly dataSource: DataSource<T>;\n public readonly manualSorting: boolean;\n public readonly manualFiltering: boolean;\n public readonly manualPagination: boolean;\n public readonly disableInitialSuspenseBoundary: boolean;\n public readonly loaderState: IncrementalLoaderState<T>;\n public readonly staticDataProperties: PropertyName<T>[] = [];\n\n private constructor(list: List<T>, shape: IncrementalLoaderShape<T> = {}) {\n const { source } = shape;\n\n this.dataSource = source ?? { staticData: emptyData };\n\n const {\n disableInitialSuspenseBoundary: disableInitialSuspenseBoundaryDefault,\n } = useComponentDefaults(\"List\");\n\n this.disableInitialSuspenseBoundary =\n \"disableInitialSuspenseBoundary\" in this.dataSource\n ? (this.dataSource.disableInitialSuspenseBoundary ??\n disableInitialSuspenseBoundaryDefault)\n : disableInitialSuspenseBoundaryDefault;\n\n const manualPagination =\n \"manualPagination\" in this.dataSource\n ? this.dataSource.manualPagination\n : undefined;\n\n const manualFiltering =\n \"manualFiltering\" in this.dataSource\n ? this.dataSource.manualFiltering\n : undefined;\n\n const manualSorting =\n \"manualSorting\" in this.dataSource\n ? this.dataSource.manualSorting\n : undefined;\n\n this.list = list;\n this.loaderState = IncrementalLoaderState.useNew<T>(list);\n\n this.manualPagination = manualPagination ?? false;\n this.manualFiltering = manualFiltering ?? this.manualPagination;\n this.manualSorting = manualSorting ?? this.manualPagination;\n this.list.filters.forEach((f) => f.onFilterUpdated(() => this.reset()));\n this.list.search?.onUpdated(() => this.reset());\n\n this.initStaticDataProperties();\n }\n\n public static useNew<T>(\n list: List<T>,\n shape: IncrementalLoaderShape<T> = {},\n ): IncrementalLoader<T> {\n return new IncrementalLoader(list, shape);\n }\n\n private initStaticDataProperties() {\n const addPropertiesOfDataEntry = (data: unknown) => {\n if (typeof data !== \"object\" || data === null) {\n return;\n }\n\n (Object.keys(data) as PropertyName<T>[])\n .filter((p) => !this.staticDataProperties.includes(p))\n .forEach((p) => {\n this.staticDataProperties.push(p);\n });\n };\n\n if (\"staticData\" in this.dataSource) {\n this.dataSource.staticData\n // collect properties from just the first 100 items\n .slice(0, 100)\n .forEach(addPropertiesOfDataEntry);\n }\n }\n\n private reset(): void {\n this.loaderState.reset();\n }\n\n public useIsLoading(): boolean {\n return this.loaderState.useIsLoading();\n }\n\n public useIsInitiallyLoading(): boolean {\n return this.loaderState.useIsInitiallyLoading();\n }\n\n public useIsLoadingMore(): boolean {\n return this.loaderState.useIsLoadingMore();\n }\n\n public useData(): T[] {\n return this.loaderState.useMergedData();\n }\n\n private getUseData(): (options: DataLoaderOptions<T>) => DataLoaderResult<T> {\n const dataSource = this.dataSource;\n\n return (options: DataLoaderOptions<T>) => {\n if (\"staticData\" in dataSource) {\n const staticData = dataSource.staticData;\n return useMemo(\n () => ({\n data: staticData,\n itemTotalCount: staticData.length,\n }),\n [staticData],\n );\n }\n\n if (\"useData\" in dataSource) {\n return dataSource.useData(options);\n }\n\n if (\"asyncLoader\" in dataSource) {\n const asyncLoader = dataSource.asyncLoader;\n const dependencies = dataSource.dependencies;\n const loaderId = dependencies\n ? hash(dependencies).toString()\n : undefined;\n\n return usePromise(asyncLoader, [options], {\n loaderId,\n });\n }\n\n if (\"asyncResourceFactory\" in dataSource) {\n return dataSource.asyncResourceFactory(options).use();\n }\n\n return useMemo(\n () => ({\n data: [],\n itemTotalCount: 0,\n }),\n [],\n );\n };\n }\n\n public getLoaderInvocationHooks(): LoaderInvocationHook[] {\n const batchesCount = times(this.list.batches.getBatchIndex() + 1, (i) => i);\n const useData = this.getUseData();\n\n return batchesCount.map((batchIndex) => ({\n useLoadBatch: () => {\n const loaderOptions = this.getDataLoaderOptions(batchIndex);\n const loaderResult = useData(loaderOptions);\n\n useEffect(() => {\n const { data, itemTotalCount, metadata } = loaderResult;\n this.loaderState.setDataBatch(batchIndex, data);\n\n if (itemTotalCount !== undefined) {\n this.list.batches.updateItemTotalCount(itemTotalCount);\n }\n\n this.loaderState.setMetadata(metadata);\n\n this.loaderState.setBatchLoadingState(batchIndex, \"loaded\");\n }, [loaderResult]);\n },\n\n useRenderSuspense: () => {\n useEffect(() => {\n this.loaderState.setBatchLoadingState(batchIndex, \"loading\");\n }, []);\n },\n }));\n }\n\n private getDataLoaderOptions(batchIndex: number): DataLoaderOptions<T> {\n return getListDataLoaderOptions<T>(\n {\n batchSize: this.list.batches.batchSize,\n modes: this,\n sorting: this.list.sorting,\n filters: this.list.filters,\n searchString: this.list.reactTable.searchString,\n },\n batchIndex,\n );\n }\n\n private getBatchDataAsyncResource(\n batchIndex: number,\n ): AsyncResource<DataLoaderResult<T>> {\n const dataSource = this.dataSource;\n const loaderOptions = this.getDataLoaderOptions(batchIndex);\n\n if (\"staticData\" in dataSource) {\n return getAsyncResource(\n async (staticData) => ({\n data: staticData as T[],\n itemTotalCount: staticData.length,\n }),\n [dataSource.staticData],\n );\n }\n\n if (\"asyncLoader\" in dataSource) {\n const asyncLoader = dataSource.asyncLoader;\n const dependencies = dataSource.dependencies;\n const loaderId = dependencies ? hash(dependencies).toString() : undefined;\n return getAsyncResource(asyncLoader, [loaderOptions], {\n loaderId,\n });\n }\n\n if (\"asyncResourceFactory\" in dataSource) {\n const asyncResourceFactory = dataSource.asyncResourceFactory;\n return asyncResourceFactory(loaderOptions);\n }\n\n throw new Error(\"Unknown data source\");\n }\n}\n"],"mappings":";;;;;;;;;;;AAmBA,IAAM,YAAqB,CAAC;AAE5B,IAAa,oBAAb,MAAa,kBAAqB;CAChC;CACA;CACA;CACA;CACA;CACA;CACA;CACA,uBAA0D,CAAC;CAE3D,YAAoB,MAAe,QAAmC,CAAC,GAAG;EACxE,MAAM,EAAE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nB;GAEA,yBAAyB;IACvB,gBAAgB;KACd,KAAK,YAAY,qBAAqB,YAAY,SAAS;IAC7D,GAAG,CAAC,CAAC;GACP;EACF,EAAE;CACJ;CAEA,qBAA6B,YAA0C;EACrE,OAAO,yBACL;GACE,WAAW,KAAK,KAAK,QAAQ;GAC7B,OAAO;GACP,SAAS,KAAK,KAAK;GACnB,SAAS,KAAK,KAAK;GACnB,cAAc,KAAK,KAAK,WAAW;EACrC,GACA,UACF;CACF;CAEA,0BACE,YACoC;EACpC,MAAM,aAAa,KAAK;EACxB,MAAM,gBAAgB,KAAK,qBAAqB,UAAU;EAE1D,IAAI,gBAAgB,YAClB,OAAO,iBACL,OAAO,gBAAgB;GACrB,MAAM;GACN,gBAAgB,WAAW;EAC7B,IACA,CAAC,WAAW,UAAU,CACxB;EAGF,IAAI,iBAAiB,YAAY;GAC/B,MAAM,cAAc,WAAW;GAC/B,MAAM,eAAe,WAAW;GAChC,MAAM,WAAW,eAAe,KAAK,YAAY,CAAC,CAAC,SAAS,IAAI,KAAA;GAChE,OAAO,iBAAiB,aAAa,CAAC,aAAa,GAAG,EACpD,SACF,CAAC;EACH;EAEA,IAAI,0BAA0B,YAAY;GACxC,MAAM,uBAAuB,WAAW;GACxC,OAAO,qBAAqB,aAAa;EAC3C;EAEA,MAAM,IAAI,MAAM,qBAAqB;CACvC;AACF"}
|
package/dist/js/packages/components/src/components/PasswordCreationField/lib/ariaAnnounce.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ariaAnnounce.mjs","names":["locales"],"sources":["../../../../../../../../src/components/PasswordCreationField/lib/ariaAnnounce.ts"],"sourcesContent":["import { useEffect, useRef } from \"react\";\nimport { announce } from \"@react-aria/live-announcer\";\nimport { useLocalizedStringFormatter } from \"@/components/TranslationProvider/useLocalizedStringFormatter\";\nimport locales from \"./../locales/*.locale.json\";\n\n/**\n * Announces the current validation message — which rule the password misses, or\n * that it is secure.\n *\n * The same text is wired to the field via `aria-describedby`, but a description\n * is only read when the field receives focus. The field keeps focus while the\n * password is typed, so without a live region a screen reader reports the field\n * as invalid and never says why.\n *\n * @internal\n */\nexport const useAriaAnnounceValidationState = (\n text: string | undefined,\n isAnnounceable: boolean,\n): void => {\n const lastAnnouncedText = useRef<string>(undefined);\n\n useEffect(() => {\n if (!isAnnounceable || !text) {\n // Announce the text again when it comes back after an empty field or a\n // pending validation.\n lastAnnouncedText.current = undefined;\n return;\n }\n\n if (text === lastAnnouncedText.current) {\n return;\n }\n\n lastAnnouncedText.current = text;\n announce(text, \"polite\");\n }, [text, isAnnounceable]);\n};\n\n/**\n * Announces that the password became visible or hidden. The toggle button keeps\n * focus, and a screen reader does not report that the input switched between\n * masked characters and plain text on its own.\n *\n * @internal\n */\nexport const useAriaAnnouncePasswordVisibility = (\n isRevealed: boolean,\n): void => {\n const formatter = useLocalizedStringFormatter(\n locales,\n \"PasswordCreationField\",\n );\n const isInitialRender = useRef(true);\n\n useEffect(() => {\n if (isInitialRender.current) {\n isInitialRender.current = false;\n return;\n }\n\n announce(\n formatter.format(\n isRevealed ? \"password.announce.revealed\" : \"password.announce.hidden\",\n ),\n \"polite\",\n );\n }, [isRevealed]);\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;AAgBA,IAAa,kCACX,MACA,mBACS;CACT,MAAM,oBAAoB,OAAe,KAAA,CAAS;CAElD,gBAAgB;EACd,IAAI,CAAC,kBAAkB,CAAC,MAAM;GAG5B,kBAAkB,UAAU,KAAA;GAC5B;EACF;EAEA,IAAI,SAAS,kBAAkB,SAC7B;EAGF,kBAAkB,UAAU;EAC5B,SAAS,MAAM,QAAQ;CACzB,GAAG,CAAC,MAAM,cAAc,CAAC;AAC3B;;;;;;;;AASA,IAAa,qCACX,eACS;CACT,MAAM,YAAY,4BAChBA,kBACA,uBACF;CACA,MAAM,kBAAkB,OAAO,IAAI;CAEnC,gBAAgB;EACd,IAAI,gBAAgB,SAAS;GAC3B,gBAAgB,UAAU;GAC1B;EACF;EAEA,SACE,UAAU,OACR,aAAa,+BAA+B,0BAC9C,GACA,QACF;
|
|
1
|
+
{"version":3,"file":"ariaAnnounce.mjs","names":["locales"],"sources":["../../../../../../../../src/components/PasswordCreationField/lib/ariaAnnounce.ts"],"sourcesContent":["import { useEffect, useRef } from \"react\";\nimport { announce } from \"@react-aria/live-announcer\";\nimport { useLocalizedStringFormatter } from \"@/components/TranslationProvider/useLocalizedStringFormatter\";\nimport locales from \"./../locales/*.locale.json\";\n\n/**\n * Announces the current validation message — which rule the password misses, or\n * that it is secure.\n *\n * The same text is wired to the field via `aria-describedby`, but a description\n * is only read when the field receives focus. The field keeps focus while the\n * password is typed, so without a live region a screen reader reports the field\n * as invalid and never says why.\n *\n * @internal\n */\nexport const useAriaAnnounceValidationState = (\n text: string | undefined,\n isAnnounceable: boolean,\n): void => {\n const lastAnnouncedText = useRef<string>(undefined);\n\n useEffect(() => {\n if (!isAnnounceable || !text) {\n // Announce the text again when it comes back after an empty field or a\n // pending validation.\n lastAnnouncedText.current = undefined;\n return;\n }\n\n if (text === lastAnnouncedText.current) {\n return;\n }\n\n lastAnnouncedText.current = text;\n announce(text, \"polite\");\n }, [text, isAnnounceable]);\n};\n\n/**\n * Announces that the password became visible or hidden. The toggle button keeps\n * focus, and a screen reader does not report that the input switched between\n * masked characters and plain text on its own.\n *\n * @internal\n */\nexport const useAriaAnnouncePasswordVisibility = (\n isRevealed: boolean,\n): void => {\n const formatter = useLocalizedStringFormatter(\n locales,\n \"PasswordCreationField\",\n );\n const isInitialRender = useRef(true);\n\n useEffect(() => {\n if (isInitialRender.current) {\n isInitialRender.current = false;\n return;\n }\n\n announce(\n formatter.format(\n isRevealed ? \"password.announce.revealed\" : \"password.announce.hidden\",\n ),\n \"polite\",\n );\n // eslint-disable-next-line react-hooks/exhaustive-deps -- announce on toggles only, not when the formatter changes\n }, [isRevealed]);\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;AAgBA,IAAa,kCACX,MACA,mBACS;CACT,MAAM,oBAAoB,OAAe,KAAA,CAAS;CAElD,gBAAgB;EACd,IAAI,CAAC,kBAAkB,CAAC,MAAM;GAG5B,kBAAkB,UAAU,KAAA;GAC5B;EACF;EAEA,IAAI,SAAS,kBAAkB,SAC7B;EAGF,kBAAkB,UAAU;EAC5B,SAAS,MAAM,QAAQ;CACzB,GAAG,CAAC,MAAM,cAAc,CAAC;AAC3B;;;;;;;;AASA,IAAa,qCACX,eACS;CACT,MAAM,YAAY,4BAChBA,kBACA,uBACF;CACA,MAAM,kBAAkB,OAAO,IAAI;CAEnC,gBAAgB;EACd,IAAI,gBAAgB,SAAS;GAC3B,gBAAgB,UAAU;GAC1B;EACF;EAEA,SACE,UAAU,OACR,aAAa,+BAA+B,0BAC9C,GACA,QACF;CAEF,GAAG,CAAC,UAAU,CAAC;AACjB"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"usePolicyValidationResult.mjs","names":[],"sources":["../../../../../../../../src/components/PasswordCreationField/lib/usePolicyValidationResult.ts"],"sourcesContent":["import { startTransition, useEffect, useRef } from \"react\";\nimport type { Policy } from \"@/integrations/@mittwald/password-tools-js\";\nimport type { ResolvedPolicyValidationResult } from \"@/components/PasswordCreationField/PasswordCreationField\";\nimport { useDebouncedCallback } from \"use-debounce\";\n\n/** @internal */\nexport const usePolicyValidationResult = (\n validationPolicy: Policy,\n password: string,\n onValidationStart?: () => void,\n onValidationResult?: (data: {\n password: string;\n isValid: boolean;\n results: ResolvedPolicyValidationResult;\n }) => void,\n) => {\n const cache = useRef<{\n password: string;\n results: ResolvedPolicyValidationResult;\n } | null>(null);\n /**\n * Validations resolve in any order. A result for a password that is no longer\n * the field's value would overwrite the current one.\n */\n const latestPassword = useRef(password);\n\n const validatePassword = (pwd: string) => {\n onValidationStart?.();\n\n startTransition(async () => {\n if (cache.current?.password === pwd) {\n onValidationResult?.({\n password: cache.current.password,\n isValid: Boolean(cache.current.results.isValid),\n results: cache.current.results,\n });\n return;\n }\n\n const validationResult = await validationPolicy.validate(pwd);\n if (pwd !== latestPassword.current) {\n return;\n }\n cache.current = { password: pwd, results: validationResult };\n onValidationResult?.({\n password: pwd,\n isValid: validationResult.isValid,\n results: validationResult,\n });\n });\n };\n\n const validatePasswordDebounce = useDebouncedCallback(validatePassword, 350, {\n trailing: true,\n });\n\n useEffect(() => {\n latestPassword.current = password;\n if (password) {\n validatePasswordDebounce(password);\n } else {\n validatePassword(password);\n }\n }, [password, validationPolicy]);\n\n /**\n * Stores a result the caller already has (a generated password), so the\n * validation of that password answers from the cache instead of rating it\n * again.\n */\n const rememberValidationResult = (\n pwd: string,\n results: ResolvedPolicyValidationResult,\n ) => {\n cache.current = { password: pwd, results };\n };\n\n return { rememberValidationResult } as const;\n};\n"],"mappings":";;;;;;AAMA,IAAa,6BACX,kBACA,UACA,mBACA,uBAKG;CACH,MAAM,QAAQ,OAGJ,IAAI;;;;;CAKd,MAAM,iBAAiB,OAAO,QAAQ;CAEtC,MAAM,oBAAoB,QAAgB;EACxC,oBAAoB;EAEpB,gBAAgB,YAAY;GAC1B,IAAI,MAAM,SAAS,aAAa,KAAK;IACnC,qBAAqB;KACnB,UAAU,MAAM,QAAQ;KACxB,SAAS,QAAQ,MAAM,QAAQ,QAAQ,OAAO;KAC9C,SAAS,MAAM,QAAQ;IACzB,CAAC;IACD;GACF;GAEA,MAAM,mBAAmB,MAAM,iBAAiB,SAAS,GAAG;GAC5D,IAAI,QAAQ,eAAe,SACzB;GAEF,MAAM,UAAU;IAAE,UAAU;IAAK,SAAS;GAAiB;GAC3D,qBAAqB;IACnB,UAAU;IACV,SAAS,iBAAiB;IAC1B,SAAS;GACX,CAAC;EACH,CAAC;CACH;CAEA,MAAM,2BAA2B,qBAAqB,kBAAkB,KAAK,EAC3E,UAAU,KACZ,CAAC;CAED,gBAAgB;EACd,eAAe,UAAU;EACzB,IAAI,UACF,yBAAyB,QAAQ;OAEjC,iBAAiB,QAAQ;
|
|
1
|
+
{"version":3,"file":"usePolicyValidationResult.mjs","names":[],"sources":["../../../../../../../../src/components/PasswordCreationField/lib/usePolicyValidationResult.ts"],"sourcesContent":["import { startTransition, useEffect, useRef } from \"react\";\nimport type { Policy } from \"@/integrations/@mittwald/password-tools-js\";\nimport type { ResolvedPolicyValidationResult } from \"@/components/PasswordCreationField/PasswordCreationField\";\nimport { useDebouncedCallback } from \"use-debounce\";\n\n/** @internal */\nexport const usePolicyValidationResult = (\n validationPolicy: Policy,\n password: string,\n onValidationStart?: () => void,\n onValidationResult?: (data: {\n password: string;\n isValid: boolean;\n results: ResolvedPolicyValidationResult;\n }) => void,\n) => {\n const cache = useRef<{\n password: string;\n results: ResolvedPolicyValidationResult;\n } | null>(null);\n /**\n * Validations resolve in any order. A result for a password that is no longer\n * the field's value would overwrite the current one.\n */\n const latestPassword = useRef(password);\n\n const validatePassword = (pwd: string) => {\n onValidationStart?.();\n\n startTransition(async () => {\n if (cache.current?.password === pwd) {\n onValidationResult?.({\n password: cache.current.password,\n isValid: Boolean(cache.current.results.isValid),\n results: cache.current.results,\n });\n return;\n }\n\n const validationResult = await validationPolicy.validate(pwd);\n if (pwd !== latestPassword.current) {\n return;\n }\n cache.current = { password: pwd, results: validationResult };\n onValidationResult?.({\n password: pwd,\n isValid: validationResult.isValid,\n results: validationResult,\n });\n });\n };\n\n const validatePasswordDebounce = useDebouncedCallback(validatePassword, 350, {\n trailing: true,\n });\n\n useEffect(() => {\n latestPassword.current = password;\n if (password) {\n validatePasswordDebounce(password);\n } else {\n validatePassword(password);\n }\n // eslint-disable-next-line react-hooks/exhaustive-deps -- validate on input changes only; the validators are new each render\n }, [password, validationPolicy]);\n\n /**\n * Stores a result the caller already has (a generated password), so the\n * validation of that password answers from the cache instead of rating it\n * again.\n */\n const rememberValidationResult = (\n pwd: string,\n results: ResolvedPolicyValidationResult,\n ) => {\n cache.current = { password: pwd, results };\n };\n\n return { rememberValidationResult } as const;\n};\n"],"mappings":";;;;;;AAMA,IAAa,6BACX,kBACA,UACA,mBACA,uBAKG;CACH,MAAM,QAAQ,OAGJ,IAAI;;;;;CAKd,MAAM,iBAAiB,OAAO,QAAQ;CAEtC,MAAM,oBAAoB,QAAgB;EACxC,oBAAoB;EAEpB,gBAAgB,YAAY;GAC1B,IAAI,MAAM,SAAS,aAAa,KAAK;IACnC,qBAAqB;KACnB,UAAU,MAAM,QAAQ;KACxB,SAAS,QAAQ,MAAM,QAAQ,QAAQ,OAAO;KAC9C,SAAS,MAAM,QAAQ;IACzB,CAAC;IACD;GACF;GAEA,MAAM,mBAAmB,MAAM,iBAAiB,SAAS,GAAG;GAC5D,IAAI,QAAQ,eAAe,SACzB;GAEF,MAAM,UAAU;IAAE,UAAU;IAAK,SAAS;GAAiB;GAC3D,qBAAqB;IACnB,UAAU;IACV,SAAS,iBAAiB;IAC1B,SAAS;GACX,CAAC;EACH,CAAC;CACH;CAEA,MAAM,2BAA2B,qBAAqB,kBAAkB,KAAK,EAC3E,UAAU,KACZ,CAAC;CAED,gBAAgB;EACd,eAAe,UAAU;EACzB,IAAI,UACF,yBAAyB,QAAQ;OAEjC,iBAAiB,QAAQ;CAG7B,GAAG,CAAC,UAAU,gBAAgB,CAAC;;;;;;CAO/B,MAAM,4BACJ,KACA,YACG;EACH,MAAM,UAAU;GAAE,UAAU;GAAK;EAAQ;CAC3C;CAEA,OAAO,EAAE,yBAAyB;AACpC"}
|
package/dist/js/packages/components/src/components/SettingsProvider/SettingsProvider.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SettingsProvider.mjs","names":[],"sources":["../../../../../../../src/components/SettingsProvider/SettingsProvider.tsx"],"sourcesContent":["import type { FC, PropsWithChildren } from \"react\";\nimport { createContext, useContext, useEffect, useMemo, useRef } from \"react\";\nimport type { SupportedSettingsBackend } from \"@/components/SettingsProvider/backends/types\";\nimport { autorun } from \"mobx\";\nimport { getAsyncResource } from \"@mittwald/react-use-promise\";\nimport {\n SettingsStore,\n type SettingsStoreOptions,\n} from \"@/components/SettingsProvider/models/SettingsStore\";\nimport { settingsBackendFactory } from \"@/components/SettingsProvider/backends/settingsBackendFactory\";\n\ntype Props = PropsWithChildren &\n SupportedSettingsBackend & {\n id?: string;\n } & Pick<SettingsStoreOptions, \"middleware\">;\n\nconst context = createContext<SettingsStore | undefined>(undefined);\n\nexport const useSettings = () => useContext(context);\n\nexport const SettingsProvider: FC<Props> = (props) => {\n const { children, middleware, id = \"static\", ...storeShape } = props;\n const backend = settingsBackendFactory(storeShape);\n\n const settingsResource = getAsyncResource(() => backend.load(), [], {\n loaderId: id,\n });\n const settings = settingsResource.use();\n\n const storingPromise = useRef(Promise.resolve());\n const parentStore = useSettings();\n\n const settingsStore = useMemo(\n () => SettingsStore.fromJson(settings, { middleware, parentStore }),\n [id],\n );\n\n const watchAndStoreSettings = () => {\n const json = settingsStore.asJson;\n storingPromise.current = storingPromise.current.then(async () => {\n await backend.store(json);\n settingsResource.refresh();\n });\n };\n\n useEffect(() => autorun(watchAndStoreSettings), [id]);\n\n return <context.Provider value={settingsStore}>{children}</context.Provider>;\n};\n\nexport default SettingsProvider;\n"],"mappings":";;;;;;;;;AAgBA,IAAM,UAAU,cAAyC,KAAA,CAAS;AAElE,IAAa,oBAAoB,WAAW,OAAO;AAEnD,IAAa,oBAA+B,UAAU;CACpD,MAAM,EAAE,UAAU,YAAY,KAAK,UAAU,GAAG,eAAe;CAC/D,MAAM,UAAU,uBAAuB,UAAU;CAEjD,MAAM,mBAAmB,uBAAuB,QAAQ,KAAK,GAAG,CAAC,GAAG,EAClE,UAAU,GACZ,CAAC;CACD,MAAM,WAAW,iBAAiB,IAAI;CAEtC,MAAM,iBAAiB,OAAO,QAAQ,QAAQ,CAAC;CAC/C,MAAM,cAAc,YAAY;CAEhC,MAAM,gBAAgB,cACd,cAAc,SAAS,UAAU;EAAE;EAAY;CAAY,CAAC,
|
|
1
|
+
{"version":3,"file":"SettingsProvider.mjs","names":[],"sources":["../../../../../../../src/components/SettingsProvider/SettingsProvider.tsx"],"sourcesContent":["import type { FC, PropsWithChildren } from \"react\";\nimport { createContext, useContext, useEffect, useMemo, useRef } from \"react\";\nimport type { SupportedSettingsBackend } from \"@/components/SettingsProvider/backends/types\";\nimport { autorun } from \"mobx\";\nimport { getAsyncResource } from \"@mittwald/react-use-promise\";\nimport {\n SettingsStore,\n type SettingsStoreOptions,\n} from \"@/components/SettingsProvider/models/SettingsStore\";\nimport { settingsBackendFactory } from \"@/components/SettingsProvider/backends/settingsBackendFactory\";\n\ntype Props = PropsWithChildren &\n SupportedSettingsBackend & {\n id?: string;\n } & Pick<SettingsStoreOptions, \"middleware\">;\n\nconst context = createContext<SettingsStore | undefined>(undefined);\n\nexport const useSettings = () => useContext(context);\n\nexport const SettingsProvider: FC<Props> = (props) => {\n const { children, middleware, id = \"static\", ...storeShape } = props;\n const backend = settingsBackendFactory(storeShape);\n\n const settingsResource = getAsyncResource(() => backend.load(), [], {\n loaderId: id,\n });\n const settings = settingsResource.use();\n\n const storingPromise = useRef(Promise.resolve());\n const parentStore = useSettings();\n\n const settingsStore = useMemo(\n () => SettingsStore.fromJson(settings, { middleware, parentStore }),\n // eslint-disable-next-line react-hooks/exhaustive-deps -- one store per settings id\n [id],\n );\n\n const watchAndStoreSettings = () => {\n const json = settingsStore.asJson;\n storingPromise.current = storingPromise.current.then(async () => {\n await backend.store(json);\n settingsResource.refresh();\n });\n };\n\n // eslint-disable-next-line react-hooks/exhaustive-deps -- one autorun per settings id\n useEffect(() => autorun(watchAndStoreSettings), [id]);\n\n return <context.Provider value={settingsStore}>{children}</context.Provider>;\n};\n\nexport default SettingsProvider;\n"],"mappings":";;;;;;;;;AAgBA,IAAM,UAAU,cAAyC,KAAA,CAAS;AAElE,IAAa,oBAAoB,WAAW,OAAO;AAEnD,IAAa,oBAA+B,UAAU;CACpD,MAAM,EAAE,UAAU,YAAY,KAAK,UAAU,GAAG,eAAe;CAC/D,MAAM,UAAU,uBAAuB,UAAU;CAEjD,MAAM,mBAAmB,uBAAuB,QAAQ,KAAK,GAAG,CAAC,GAAG,EAClE,UAAU,GACZ,CAAC;CACD,MAAM,WAAW,iBAAiB,IAAI;CAEtC,MAAM,iBAAiB,OAAO,QAAQ,QAAQ,CAAC;CAC/C,MAAM,cAAc,YAAY;CAEhC,MAAM,gBAAgB,cACd,cAAc,SAAS,UAAU;EAAE;EAAY;CAAY,CAAC,GAElE,CAAC,EAAE,CACL;CAEA,MAAM,8BAA8B;EAClC,MAAM,OAAO,cAAc;EAC3B,eAAe,UAAU,eAAe,QAAQ,KAAK,YAAY;GAC/D,MAAM,QAAQ,MAAM,IAAI;GACxB,iBAAiB,QAAQ;EAC3B,CAAC;CACH;CAGA,gBAAgB,QAAQ,qBAAqB,GAAG,CAAC,EAAE,CAAC;CAEpD,OAAO,oBAAC,QAAQ,UAAT;EAAkB,OAAO;EAAgB;CAA2B,CAAA;AAC7E"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"TextArea.mjs","names":["styles","locales"],"sources":["../../../../../../../src/components/TextArea/TextArea.tsx"],"sourcesContent":["import * as Aria from \"react-aria-components\";\nimport styles from \"./TextArea.module.scss\";\nimport type { FlowComponentProps } from \"@/lib/componentFactory/flowComponent\";\nimport { flowComponent } from \"@/lib/componentFactory/flowComponent\";\nimport { useObjectRef } from \"@react-aria/utils\";\nimport { useFieldComponent } from \"@/lib/hooks/useFieldComponent\";\nimport { PropsContextProvider } from \"@/lib/propsContext\";\nimport clsx from \"clsx\";\nimport {\n type PropsWithChildren,\n useEffect,\n useLayoutEffect,\n useState,\n} from \"react\";\nimport { useControlledHostValueProps } from \"@/lib/remote/useControlledHostValueProps\";\nimport { useLocalizedStringFormatter } from \"@/components/TranslationProvider/useLocalizedStringFormatter\";\nimport locales from \"./locales/*.locale.json\";\nimport { FieldDescription } from \"@/components/FieldDescription\";\nimport { useWarnDeprecation } from \"@/components/DeprecationWarningProvider\";\n\nexport interface TextAreaProps\n extends\n PropsWithChildren<Omit<Aria.TextFieldProps, \"children\">>,\n Pick<Aria.TextAreaProps, \"placeholder\" | \"rows\" | \"aria-hidden\">,\n FlowComponentProps<HTMLTextAreaElement> {\n /** Whether a character count should be displayed inside the field description. */\n showCharacterCount?: boolean;\n /**\n * Whether the text area should grow if its content gets longer than its\n * initial height.\n */\n autoResizeMaxRows?: number;\n /** Allows the user to manually resize the textArea horizontally. */\n allowResize?: boolean | \"horizontal\" | \"vertical\";\n /** @deprecated Use `allowResize` instead. */\n allowHorizontalResize?: boolean;\n /** @deprecated Use `allowResize` instead. */\n allowVerticalResize?: boolean;\n}\n\n/** @flr-generate all */\nexport const TextArea = flowComponent(\"TextArea\", (props) => {\n const warnDeprecation = useWarnDeprecation();\n const {\n children,\n placeholder,\n rows = 5,\n autoResizeMaxRows = rows,\n ref,\n allowVerticalResize,\n allowHorizontalResize,\n showCharacterCount,\n className,\n onChange,\n isReadOnly,\n value,\n ...rest\n } = useControlledHostValueProps(props, \"\");\n\n if (allowHorizontalResize !== undefined) {\n warnDeprecation(\n \"The 'allowHorizontalResize' prop is deprecated and will be removed in a future release. Use 'allowResize' instead.\",\n );\n }\n if (allowVerticalResize !== undefined) {\n warnDeprecation(\n \"The 'allowVerticalResize' prop is deprecated and will be removed in a future release. Use 'allowResize' instead.\",\n );\n }\n\n const {\n FieldErrorView,\n FieldErrorCaptureContext,\n fieldPropsContext,\n wrapperProps,\n controlProps,\n skeletonProps,\n } = useFieldComponent(props, \"TextArea\");\n\n let { allowResize } = props;\n if (allowVerticalResize) {\n allowResize = \"vertical\";\n } else if (allowHorizontalResize) {\n allowResize = \"horizontal\";\n }\n\n const rootClassName = clsx(wrapperProps.className, className);\n\n const inputClassName = clsx(\n styles.input,\n typeof allowResize === \"boolean\" && allowResize ? styles.resize : null,\n allowResize === \"horizontal\"\n ? styles.horizontalResize\n : allowResize === \"vertical\"\n ? styles.verticalResize\n : null,\n );\n\n const handleChange = (v: string) => {\n if (isReadOnly) {\n return;\n }\n\n if (onChange) {\n onChange(v);\n }\n };\n\n const translation = useLocalizedStringFormatter(locales, \"TextArea\");\n\n // Derived, so that a value the field never saw typed is counted as well.\n const charactersCountDescription = translation.format(\"characters\", {\n count: value.length,\n maxCount: props.maxLength ?? 0,\n });\n\n const localRef = useObjectRef(ref);\n\n const [resized, setResized] = useState(false);\n\n const autoResizable = rows !== autoResizeMaxRows;\n\n const verticallyResizable =\n allowResize && (!autoResizable || (autoResizable && resized));\n\n useEffect(() => {\n const textarea = localRef.current;\n if (!textarea) return;\n\n const startHeight = textarea.offsetHeight;\n let tracking = false;\n\n const handleMouseDown = () => {\n tracking = true;\n };\n\n const handleMouseMove = () => {\n if (!tracking || resized) return;\n\n const currentHeight = textarea.offsetHeight;\n\n if (currentHeight !== startHeight) {\n setResized(true);\n tracking = false;\n }\n };\n\n const handleMouseUp = () => {\n tracking = false;\n };\n\n window.addEventListener(\"mousedown\", handleMouseDown);\n window.addEventListener(\"mousemove\", handleMouseMove);\n window.addEventListener(\"mouseup\", handleMouseUp);\n\n return () => {\n window.removeEventListener(\"mousedown\", handleMouseDown);\n window.removeEventListener(\"mousemove\", handleMouseMove);\n window.removeEventListener(\"mouseup\", handleMouseUp);\n };\n }, [resized]);\n\n /*\n * The height depends on the rendered content, so it cannot be a style. It is\n * synced to the value instead of to the `change` event, because a value the\n * field never saw typed — an initial value, or a draft loaded into a\n * controlled field — has to resize it just the same.\n */\n useLayoutEffect(() => {\n const textArea = localRef.current;\n if (!textArea || !autoResizable || verticallyResizable) {\n return;\n }\n // https://stackoverflow.com/a/60795884\n textArea.style.height = \"0px\";\n // + 2 to add border height\n textArea.style.height = `${textArea.scrollHeight + 2}px`;\n }, [value, autoResizable, verticallyResizable]);\n\n return (\n <Aria.TextField\n {...rest}\n {...controlProps}\n {...skeletonProps}\n value={value}\n className={rootClassName}\n onChange={handleChange}\n >\n <PropsContextProvider props={fieldPropsContext}>\n <FieldErrorCaptureContext>{children}</FieldErrorCaptureContext>\n <Aria.TextArea\n rows={rows}\n {...(isReadOnly ? { \"data-readonly\": true } : {})}\n aria-readonly={isReadOnly}\n aria-hidden={props[\"aria-hidden\"]}\n placeholder={placeholder}\n className={inputClassName}\n ref={localRef}\n style={{\n \"--text-area--rows\": rows,\n \"--text-area--max-rows\": verticallyResizable\n ? undefined\n : autoResizeMaxRows,\n }}\n />\n {showCharacterCount && (\n <FieldDescription>{charactersCountDescription}</FieldDescription>\n )}\n <FieldErrorView />\n </PropsContextProvider>\n </Aria.TextField>\n );\n});\n\nexport default TextArea;\n"],"mappings":";;;;;;;;;;;;;;;;;;AAyCA,IAAa,WAAW,cAAc,aAAa,UAAU;CAC3D,MAAM,kBAAkB,mBAAmB;CAC3C,MAAM,EACJ,UACA,aACA,OAAO,GACP,oBAAoB,MACpB,KACA,qBACA,uBACA,oBACA,WACA,UACA,YACA,OACA,GAAG,SACD,4BAA4B,OAAO,EAAE;CAEzC,IAAI,0BAA0B,KAAA,GAC5B,gBACE,oHACF;CAEF,IAAI,wBAAwB,KAAA,GAC1B,gBACE,kHACF;CAGF,MAAM,EACJ,gBACA,0BACA,mBACA,cACA,cACA,kBACE,kBAAkB,OAAO,UAAU;CAEvC,IAAI,EAAE,gBAAgB;CACtB,IAAI,qBACF,cAAc;MACT,IAAI,uBACT,cAAc;CAGhB,MAAM,gBAAgB,KAAK,aAAa,WAAW,SAAS;CAE5D,MAAM,iBAAiB,KACrBA,wBAAO,OACP,OAAO,gBAAgB,aAAa,cAAcA,wBAAO,SAAS,MAClE,gBAAgB,eACZA,wBAAO,mBACP,gBAAgB,aACdA,wBAAO,iBACP,IACR;CAEA,MAAM,gBAAgB,MAAc;EAClC,IAAI,YACF;EAGF,IAAI,UACF,SAAS,CAAC;CAEd;CAKA,MAAM,6BAHc,4BAA4BC,kBAAS,UAGtB,CAAA,CAAY,OAAO,cAAc;EAClE,OAAO,MAAM;EACb,UAAU,MAAM,aAAa;CAC/B,CAAC;CAED,MAAM,WAAW,aAAa,GAAG;CAEjC,MAAM,CAAC,SAAS,cAAc,SAAS,KAAK;CAE5C,MAAM,gBAAgB,SAAS;CAE/B,MAAM,sBACJ,gBAAgB,CAAC,iBAAkB,iBAAiB;CAEtD,gBAAgB;EACd,MAAM,WAAW,SAAS;EAC1B,IAAI,CAAC,UAAU;EAEf,MAAM,cAAc,SAAS;EAC7B,IAAI,WAAW;EAEf,MAAM,wBAAwB;GAC5B,WAAW;EACb;EAEA,MAAM,wBAAwB;GAC5B,IAAI,CAAC,YAAY,SAAS;GAI1B,IAFsB,SAAS,iBAET,aAAa;IACjC,WAAW,IAAI;IACf,WAAW;GACb;EACF;EAEA,MAAM,sBAAsB;GAC1B,WAAW;EACb;EAEA,OAAO,iBAAiB,aAAa,eAAe;EACpD,OAAO,iBAAiB,aAAa,eAAe;EACpD,OAAO,iBAAiB,WAAW,aAAa;EAEhD,aAAa;GACX,OAAO,oBAAoB,aAAa,eAAe;GACvD,OAAO,oBAAoB,aAAa,eAAe;GACvD,OAAO,oBAAoB,WAAW,aAAa;EACrD;
|
|
1
|
+
{"version":3,"file":"TextArea.mjs","names":["styles","locales"],"sources":["../../../../../../../src/components/TextArea/TextArea.tsx"],"sourcesContent":["import * as Aria from \"react-aria-components\";\nimport styles from \"./TextArea.module.scss\";\nimport type { FlowComponentProps } from \"@/lib/componentFactory/flowComponent\";\nimport { flowComponent } from \"@/lib/componentFactory/flowComponent\";\nimport { useObjectRef } from \"@react-aria/utils\";\nimport { useFieldComponent } from \"@/lib/hooks/useFieldComponent\";\nimport { PropsContextProvider } from \"@/lib/propsContext\";\nimport clsx from \"clsx\";\nimport {\n type PropsWithChildren,\n useEffect,\n useLayoutEffect,\n useState,\n} from \"react\";\nimport { useControlledHostValueProps } from \"@/lib/remote/useControlledHostValueProps\";\nimport { useLocalizedStringFormatter } from \"@/components/TranslationProvider/useLocalizedStringFormatter\";\nimport locales from \"./locales/*.locale.json\";\nimport { FieldDescription } from \"@/components/FieldDescription\";\nimport { useWarnDeprecation } from \"@/components/DeprecationWarningProvider\";\n\nexport interface TextAreaProps\n extends\n PropsWithChildren<Omit<Aria.TextFieldProps, \"children\">>,\n Pick<Aria.TextAreaProps, \"placeholder\" | \"rows\" | \"aria-hidden\">,\n FlowComponentProps<HTMLTextAreaElement> {\n /** Whether a character count should be displayed inside the field description. */\n showCharacterCount?: boolean;\n /**\n * Whether the text area should grow if its content gets longer than its\n * initial height.\n */\n autoResizeMaxRows?: number;\n /** Allows the user to manually resize the textArea horizontally. */\n allowResize?: boolean | \"horizontal\" | \"vertical\";\n /** @deprecated Use `allowResize` instead. */\n allowHorizontalResize?: boolean;\n /** @deprecated Use `allowResize` instead. */\n allowVerticalResize?: boolean;\n}\n\n/** @flr-generate all */\nexport const TextArea = flowComponent(\"TextArea\", (props) => {\n const warnDeprecation = useWarnDeprecation();\n const {\n children,\n placeholder,\n rows = 5,\n autoResizeMaxRows = rows,\n ref,\n allowVerticalResize,\n allowHorizontalResize,\n showCharacterCount,\n className,\n onChange,\n isReadOnly,\n value,\n ...rest\n } = useControlledHostValueProps(props, \"\");\n\n if (allowHorizontalResize !== undefined) {\n warnDeprecation(\n \"The 'allowHorizontalResize' prop is deprecated and will be removed in a future release. Use 'allowResize' instead.\",\n );\n }\n if (allowVerticalResize !== undefined) {\n warnDeprecation(\n \"The 'allowVerticalResize' prop is deprecated and will be removed in a future release. Use 'allowResize' instead.\",\n );\n }\n\n const {\n FieldErrorView,\n FieldErrorCaptureContext,\n fieldPropsContext,\n wrapperProps,\n controlProps,\n skeletonProps,\n } = useFieldComponent(props, \"TextArea\");\n\n let { allowResize } = props;\n if (allowVerticalResize) {\n allowResize = \"vertical\";\n } else if (allowHorizontalResize) {\n allowResize = \"horizontal\";\n }\n\n const rootClassName = clsx(wrapperProps.className, className);\n\n const inputClassName = clsx(\n styles.input,\n typeof allowResize === \"boolean\" && allowResize ? styles.resize : null,\n allowResize === \"horizontal\"\n ? styles.horizontalResize\n : allowResize === \"vertical\"\n ? styles.verticalResize\n : null,\n );\n\n const handleChange = (v: string) => {\n if (isReadOnly) {\n return;\n }\n\n if (onChange) {\n onChange(v);\n }\n };\n\n const translation = useLocalizedStringFormatter(locales, \"TextArea\");\n\n // Derived, so that a value the field never saw typed is counted as well.\n const charactersCountDescription = translation.format(\"characters\", {\n count: value.length,\n maxCount: props.maxLength ?? 0,\n });\n\n const localRef = useObjectRef(ref);\n\n const [resized, setResized] = useState(false);\n\n const autoResizable = rows !== autoResizeMaxRows;\n\n const verticallyResizable =\n allowResize && (!autoResizable || (autoResizable && resized));\n\n useEffect(() => {\n const textarea = localRef.current;\n if (!textarea) return;\n\n const startHeight = textarea.offsetHeight;\n let tracking = false;\n\n const handleMouseDown = () => {\n tracking = true;\n };\n\n const handleMouseMove = () => {\n if (!tracking || resized) return;\n\n const currentHeight = textarea.offsetHeight;\n\n if (currentHeight !== startHeight) {\n setResized(true);\n tracking = false;\n }\n };\n\n const handleMouseUp = () => {\n tracking = false;\n };\n\n window.addEventListener(\"mousedown\", handleMouseDown);\n window.addEventListener(\"mousemove\", handleMouseMove);\n window.addEventListener(\"mouseup\", handleMouseUp);\n\n return () => {\n window.removeEventListener(\"mousedown\", handleMouseDown);\n window.removeEventListener(\"mousemove\", handleMouseMove);\n window.removeEventListener(\"mouseup\", handleMouseUp);\n };\n // eslint-disable-next-line react-hooks/exhaustive-deps -- the ref object follows the forwarded ref, which callers may pass inline\n }, [resized]);\n\n /*\n * The height depends on the rendered content, so it cannot be a style. It is\n * synced to the value instead of to the `change` event, because a value the\n * field never saw typed — an initial value, or a draft loaded into a\n * controlled field — has to resize it just the same.\n */\n useLayoutEffect(() => {\n const textArea = localRef.current;\n if (!textArea || !autoResizable || verticallyResizable) {\n return;\n }\n // https://stackoverflow.com/a/60795884\n textArea.style.height = \"0px\";\n // + 2 to add border height\n textArea.style.height = `${textArea.scrollHeight + 2}px`;\n // eslint-disable-next-line react-hooks/exhaustive-deps -- the ref object follows the forwarded ref, which callers may pass inline\n }, [value, autoResizable, verticallyResizable]);\n\n return (\n <Aria.TextField\n {...rest}\n {...controlProps}\n {...skeletonProps}\n value={value}\n className={rootClassName}\n onChange={handleChange}\n >\n <PropsContextProvider props={fieldPropsContext}>\n <FieldErrorCaptureContext>{children}</FieldErrorCaptureContext>\n <Aria.TextArea\n rows={rows}\n {...(isReadOnly ? { \"data-readonly\": true } : {})}\n aria-readonly={isReadOnly}\n aria-hidden={props[\"aria-hidden\"]}\n placeholder={placeholder}\n className={inputClassName}\n ref={localRef}\n style={{\n \"--text-area--rows\": rows,\n \"--text-area--max-rows\": verticallyResizable\n ? undefined\n : autoResizeMaxRows,\n }}\n />\n {showCharacterCount && (\n <FieldDescription>{charactersCountDescription}</FieldDescription>\n )}\n <FieldErrorView />\n </PropsContextProvider>\n </Aria.TextField>\n );\n});\n\nexport default TextArea;\n"],"mappings":";;;;;;;;;;;;;;;;;;AAyCA,IAAa,WAAW,cAAc,aAAa,UAAU;CAC3D,MAAM,kBAAkB,mBAAmB;CAC3C,MAAM,EACJ,UACA,aACA,OAAO,GACP,oBAAoB,MACpB,KACA,qBACA,uBACA,oBACA,WACA,UACA,YACA,OACA,GAAG,SACD,4BAA4B,OAAO,EAAE;CAEzC,IAAI,0BAA0B,KAAA,GAC5B,gBACE,oHACF;CAEF,IAAI,wBAAwB,KAAA,GAC1B,gBACE,kHACF;CAGF,MAAM,EACJ,gBACA,0BACA,mBACA,cACA,cACA,kBACE,kBAAkB,OAAO,UAAU;CAEvC,IAAI,EAAE,gBAAgB;CACtB,IAAI,qBACF,cAAc;MACT,IAAI,uBACT,cAAc;CAGhB,MAAM,gBAAgB,KAAK,aAAa,WAAW,SAAS;CAE5D,MAAM,iBAAiB,KACrBA,wBAAO,OACP,OAAO,gBAAgB,aAAa,cAAcA,wBAAO,SAAS,MAClE,gBAAgB,eACZA,wBAAO,mBACP,gBAAgB,aACdA,wBAAO,iBACP,IACR;CAEA,MAAM,gBAAgB,MAAc;EAClC,IAAI,YACF;EAGF,IAAI,UACF,SAAS,CAAC;CAEd;CAKA,MAAM,6BAHc,4BAA4BC,kBAAS,UAGtB,CAAA,CAAY,O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AAC;KAC/C,iBAAe;KACf,eAAa,MAAM;KACN;KACb,WAAW;KACX,KAAK;KACL,OAAO;MACL,qBAAqB;MACrB,yBAAyB,sBACrB,KAAA,IACA;KACN;IACD,CAAA;IACA,sBACC,oBAAC,kBAAD,EAAA,UAAmB,2BAA6C,CAAA;IAElE,oBAAC,gBAAD,CAAiB,CAAA;GACG;;CACR,CAAA;AAEpB,CAAC"}
|
package/dist/js/packages/components/src/integrations/react-hook-form/components/Form/Form.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Form.mjs","names":["RhfFormContextProvider"],"sources":["../../../../../../../../../src/integrations/react-hook-form/components/Form/Form.tsx"],"sourcesContent":["import { FormContextProvider } from \"@/integrations/react-hook-form/components/FormContextProvider/FormContextProvider\";\nimport { useComponentDefaults } from \"@/components/ComponentDefaultsProvider\";\nimport { type OverlayController, useModalController } from \"@/lib/controller\";\nimport {\n type BaseSyntheticEvent,\n type ComponentProps,\n type FC,\n type PropsWithChildren,\n type Ref,\n type SubmitEventHandler,\n useId,\n useMemo,\n useRef,\n} from \"react\";\nimport type {\n FieldValues,\n Path,\n SubmitHandler,\n UseFormReturn,\n} from \"react-hook-form\";\nimport { FormProvider as RhfFormContextProvider } from \"react-hook-form\";\nimport { useFormRootErrorController } from \"../FormRootError/useFormRootErrorController\";\nimport { FormRootError } from \"../../lib/FormRootError\";\nimport { useFormSettings } from \"../FormSettingsProvider/FormSettingsProvider\";\nimport {\n useFormSubmitController,\n type WithFormSubmitControllerProps,\n} from \"@/integrations/react-hook-form/components/Form/hooks/useFormSubmitController\";\nimport { useHotkeySubmit } from \"@/integrations/react-hook-form/components/Form/hooks/useHotkeySubmit\";\n\nexport type FormOnSubmitHandler<F extends FieldValues> = SubmitHandler<F>;\n\nexport type AfterFormSubmitCallback = (...unknownArgs: unknown[]) => unknown;\n\nexport interface FormAutoResetOptions {\n /**\n * Whether the form is reset to its default values after the surrounding modal\n * has closed.\n *\n * @default true\n */\n onAfterModalClose?: boolean;\n}\n\ntype FormComponentType = FC<\n PropsWithChildren<{\n id: string;\n onSubmit?: SubmitEventHandler | FormOnSubmitHandler<never>;\n ref?: Ref<HTMLFormElement>;\n }>\n>;\n\nexport interface FormProps<F extends FieldValues>\n extends\n Omit<ComponentProps<\"form\">, \"onSubmit\">,\n PropsWithChildren,\n WithFormSubmitControllerProps {\n /** The react-hook-form instance returned by `useForm()`. */\n form: UseFormReturn<F>;\n /**\n * Called with the validated form values when the form is submitted. Returning\n * a promise keeps the submit button pending until it settles.\n */\n onSubmit: FormOnSubmitHandler<F>;\n /**\n * The component rendered as the form element. Use it to render the form with\n * a routers form component. Defaults to a plain `<form />`.\n */\n formComponent?: FC<Omit<FormComponentType, \"ref\">>;\n /**\n * Whether all fields of the form can be read but not edited.\n *\n * @default false\n */\n isReadOnly?: boolean;\n /**\n * When the form is reset to its default values. `true` resets it after the\n * surrounding modal has closed, `false` never resets it.\n *\n * @default true\n */\n autoReset?: FormAutoResetOptions | boolean;\n /**\n * Whether closing the surrounding modal must be confirmed while the form has\n * unsaved changes. Overrides `Form.confirmModalCloseOnUnsavedChanges` of the\n * `ComponentDefaultsProvider`.\n *\n * @default true\n */\n confirmModalCloseOnUnsavedChanges?: boolean;\n}\n\nconst DefaultFormComponent: FormComponentType = (p) => <form {...p} />;\n\n/**\n * Runs `operation` while closing the surrounding Modal is allowed without a\n * confirmation, and drops that permission again as soon as the operation has\n * settled. Scoping it to the operation is what keeps a submit that only\n * advances a wizard step from disarming the confirmation for good (#2775).\n */\nconst runWithGrantedModalClose = (\n modalController: OverlayController,\n operation: () => unknown,\n): unknown => {\n const releaseGrant = modalController.grantCloseWithoutConfirmation();\n\n let result: unknown;\n try {\n result = operation();\n } catch (error) {\n releaseGrant();\n throw error;\n }\n\n if (result instanceof Promise) {\n return result.finally(releaseGrant);\n }\n releaseGrant();\n return result;\n};\n\nexport function Form<F extends FieldValues>(props: FormProps<F>) {\n const {\n form,\n children,\n onSubmit: onSubmitProp,\n formComponent = DefaultFormComponent,\n isReadOnly,\n ref,\n id: idProp,\n autoReset = true,\n confirmModalCloseOnUnsavedChanges: confirmModalCloseOnUnsavedChangesProp,\n submitController: submitControllerFromProps,\n ...formProps\n } = props;\n\n const newFormId = useId();\n const formId = idProp ?? newFormId;\n const FormComponent = useMemo(() => formComponent, [formId]);\n const afterSubmitCallback = useRef<AfterFormSubmitCallback>(undefined);\n const { isDirty } = form.formState;\n const rootErrorController = useFormRootErrorController();\n\n const defaultSubmitController = useFormSubmitController();\n const submitController = submitControllerFromProps\n ? submitControllerFromProps.submit.extend(defaultSubmitController)\n : defaultSubmitController;\n\n const autoResetOptions =\n typeof autoReset === \"boolean\"\n ? { onAfterModalClose: autoReset }\n : autoReset;\n\n const defaults = useComponentDefaults(\"Form\");\n const confirmModalCloseOnUnsavedChanges =\n confirmModalCloseOnUnsavedChangesProp ??\n defaults.confirmModalCloseOnUnsavedChanges;\n\n const modalController = useModalController();\n modalController.useUpdateOptions({\n // A dirty Form contributes one close confirmation source to the surrounding\n // Modal; sources are combined, so a clean Form does not overrule a\n // `<Modal confirmOnClose>`. The Modal renders the confirmation dialog.\n // A Form that switched it off contributes nothing at all.\n confirmOnClose: confirmModalCloseOnUnsavedChanges ? isDirty : undefined,\n });\n modalController.useOnClosed(() => {\n if (autoResetOptions?.onAfterModalClose) {\n form.reset();\n }\n });\n\n const { submitInterceptor } = useFormSettings();\n const onSubmit = submitInterceptor\n ? (values: F, event?: BaseSyntheticEvent) =>\n submitInterceptor<F>(onSubmitProp, values, { form, event })\n : onSubmitProp;\n\n const handleSubmitResult = (result: unknown) => {\n if (typeof result === \"function\") {\n afterSubmitCallback.current = result as AfterFormSubmitCallback;\n }\n const rootError = form.getFieldState(\"root\" as Path<F>)?.error;\n if (rootError && !rootErrorController.errorComponentMounted) {\n throw new FormRootError(rootError);\n }\n };\n\n const handleSubmit = async (e?: BaseSyntheticEvent | F): Promise<void> => {\n const formEvent =\n e && \"nativeEvent\" in e ? (e as BaseSyntheticEvent) : undefined;\n formEvent?.stopPropagation();\n\n // react-hook-form's submit handler resolves with an unknown value; the\n // submit controller only awaits it, so drop the result.\n await form.handleSubmit((values, event) =>\n runWithGrantedModalClose(modalController, () => {\n const submitResult = onSubmit(values, event);\n if (submitResult instanceof Promise) {\n return submitResult.then(handleSubmitResult);\n }\n handleSubmitResult(submitResult);\n }),\n )(formEvent);\n };\n submitController.submit.set(handleSubmit);\n\n const onAfterSuccessFeedback = () => {\n const callback = afterSubmitCallback.current;\n if (!callback) {\n return;\n }\n // The callback runs after the submit itself has finished (and after\n // SubmitButton's success feedback), so it needs its own permission to close\n // the Modal.\n runWithGrantedModalClose(modalController, callback);\n };\n\n const refWithHotkeySubmit = useHotkeySubmit({\n ref,\n submitController,\n });\n\n return (\n <RhfFormContextProvider {...form}>\n <FormContextProvider\n form={form as UseFormReturn}\n isReadOnly={isReadOnly}\n id={formId}\n onAfterSuccessFeedback={onAfterSuccessFeedback}\n rootErrorController={rootErrorController}\n >\n <FormComponent\n {...formProps}\n ref={refWithHotkeySubmit}\n id={formId}\n onSubmit={handleSubmit}\n >\n {children}\n </FormComponent>\n </FormContextProvider>\n </RhfFormContextProvider>\n );\n}\n\nexport default Form;\n"],"mappings":";;;;;;;;;;;;;;AA4FA,IAAM,wBAA2C,MAAM,oBAAC,QAAD,EAAM,GAAI,EAAI,CAAA;;;;;;;AAQrE,IAAM,4BACJ,iBACA,cACY;CACZ,MAAM,eAAe,gBAAgB,8BAA8B;CAEnE,IAAI;CACJ,IAAI;EACF,SAAS,UAAU;CACrB,SAAS,OAAO;EACd,aAAa;EACb,MAAM;CACR;CAEA,IAAI,kBAAkB,SACpB,OAAO,OAAO,QAAQ,YAAY;CAEpC,aAAa;CACb,OAAO;AACT;AAEA,SAAgB,KAA4B,OAAqB;CAC/D,MAAM,EACJ,MACA,UACA,UAAU,cACV,gBAAgB,sBAChB,YACA,KACA,IAAI,QACJ,YAAY,MACZ,mCAAmC,uCACnC,kBAAkB,2B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CAAC,SAAS;CACb;CACA,iBAAiB,OAAO,IAAI,YAAY;CAExC,MAAM,+BAA+B;EACnC,MAAM,WAAW,oBAAoB;EACrC,IAAI,CAAC,UACH;EAKF,yBAAyB,iBAAiB,QAAQ;CACpD;CAEA,MAAM,sBAAsB,gBAAgB;EAC1C;EACA;CACF,CAAC;CAED,OACE,oBAACA,cAAD;EAAwB,GAAI;EAC1B,UAAA,oBAAC,qBAAD;GACQ;GACM;GACZ,IAAI;GACoB;GACH;GAErB,UAAA,oBAAC,eAAD;IACE,GAAI;IACJ,KAAK;IACL,IAAI;IACJ,UAAU;IAET;GACY,CAAA;EACI,CAAA;CACC,CAAA;AAE5B"}
|
|
1
|
+
{"version":3,"file":"Form.mjs","names":["RhfFormContextProvider"],"sources":["../../../../../../../../../src/integrations/react-hook-form/components/Form/Form.tsx"],"sourcesContent":["import { FormContextProvider } from \"@/integrations/react-hook-form/components/FormContextProvider/FormContextProvider\";\nimport { useComponentDefaults } from \"@/components/ComponentDefaultsProvider\";\nimport { type OverlayController, useModalController } from \"@/lib/controller\";\nimport {\n type BaseSyntheticEvent,\n type ComponentProps,\n type FC,\n type PropsWithChildren,\n type Ref,\n type SubmitEventHandler,\n useId,\n useMemo,\n useRef,\n} from \"react\";\nimport type {\n FieldValues,\n Path,\n SubmitHandler,\n UseFormReturn,\n} from \"react-hook-form\";\nimport { FormProvider as RhfFormContextProvider } from \"react-hook-form\";\nimport { useFormRootErrorController } from \"../FormRootError/useFormRootErrorController\";\nimport { FormRootError } from \"../../lib/FormRootError\";\nimport { useFormSettings } from \"../FormSettingsProvider/FormSettingsProvider\";\nimport {\n useFormSubmitController,\n type WithFormSubmitControllerProps,\n} from \"@/integrations/react-hook-form/components/Form/hooks/useFormSubmitController\";\nimport { useHotkeySubmit } from \"@/integrations/react-hook-form/components/Form/hooks/useHotkeySubmit\";\n\nexport type FormOnSubmitHandler<F extends FieldValues> = SubmitHandler<F>;\n\nexport type AfterFormSubmitCallback = (...unknownArgs: unknown[]) => unknown;\n\nexport interface FormAutoResetOptions {\n /**\n * Whether the form is reset to its default values after the surrounding modal\n * has closed.\n *\n * @default true\n */\n onAfterModalClose?: boolean;\n}\n\ntype FormComponentType = FC<\n PropsWithChildren<{\n id: string;\n onSubmit?: SubmitEventHandler | FormOnSubmitHandler<never>;\n ref?: Ref<HTMLFormElement>;\n }>\n>;\n\nexport interface FormProps<F extends FieldValues>\n extends\n Omit<ComponentProps<\"form\">, \"onSubmit\">,\n PropsWithChildren,\n WithFormSubmitControllerProps {\n /** The react-hook-form instance returned by `useForm()`. */\n form: UseFormReturn<F>;\n /**\n * Called with the validated form values when the form is submitted. Returning\n * a promise keeps the submit button pending until it settles.\n */\n onSubmit: FormOnSubmitHandler<F>;\n /**\n * The component rendered as the form element. Use it to render the form with\n * a routers form component. Defaults to a plain `<form />`.\n */\n formComponent?: FC<Omit<FormComponentType, \"ref\">>;\n /**\n * Whether all fields of the form can be read but not edited.\n *\n * @default false\n */\n isReadOnly?: boolean;\n /**\n * When the form is reset to its default values. `true` resets it after the\n * surrounding modal has closed, `false` never resets it.\n *\n * @default true\n */\n autoReset?: FormAutoResetOptions | boolean;\n /**\n * Whether closing the surrounding modal must be confirmed while the form has\n * unsaved changes. Overrides `Form.confirmModalCloseOnUnsavedChanges` of the\n * `ComponentDefaultsProvider`.\n *\n * @default true\n */\n confirmModalCloseOnUnsavedChanges?: boolean;\n}\n\nconst DefaultFormComponent: FormComponentType = (p) => <form {...p} />;\n\n/**\n * Runs `operation` while closing the surrounding Modal is allowed without a\n * confirmation, and drops that permission again as soon as the operation has\n * settled. Scoping it to the operation is what keeps a submit that only\n * advances a wizard step from disarming the confirmation for good (#2775).\n */\nconst runWithGrantedModalClose = (\n modalController: OverlayController,\n operation: () => unknown,\n): unknown => {\n const releaseGrant = modalController.grantCloseWithoutConfirmation();\n\n let result: unknown;\n try {\n result = operation();\n } catch (error) {\n releaseGrant();\n throw error;\n }\n\n if (result instanceof Promise) {\n return result.finally(releaseGrant);\n }\n releaseGrant();\n return result;\n};\n\nexport function Form<F extends FieldValues>(props: FormProps<F>) {\n const {\n form,\n children,\n onSubmit: onSubmitProp,\n formComponent = DefaultFormComponent,\n isReadOnly,\n ref,\n id: idProp,\n autoReset = true,\n confirmModalCloseOnUnsavedChanges: confirmModalCloseOnUnsavedChangesProp,\n submitController: submitControllerFromProps,\n ...formProps\n } = props;\n\n const newFormId = useId();\n const formId = idProp ?? newFormId;\n // eslint-disable-next-line react-hooks/exhaustive-deps -- keep the component identity per form, or the form remounts\n const FormComponent = useMemo(() => formComponent, [formId]);\n const afterSubmitCallback = useRef<AfterFormSubmitCallback>(undefined);\n const { isDirty } = form.formState;\n const rootErrorController = useFormRootErrorController();\n\n const defaultSubmitController = useFormSubmitController();\n const submitController = submitControllerFromProps\n ? submitControllerFromProps.submit.extend(defaultSubmitController)\n : defaultSubmitController;\n\n const autoResetOptions =\n typeof autoReset === \"boolean\"\n ? { onAfterModalClose: autoReset }\n : autoReset;\n\n const defaults = useComponentDefaults(\"Form\");\n const confirmModalCloseOnUnsavedChanges =\n confirmModalCloseOnUnsavedChangesProp ??\n defaults.confirmModalCloseOnUnsavedChanges;\n\n const modalController = useModalController();\n modalController.useUpdateOptions({\n // A dirty Form contributes one close confirmation source to the surrounding\n // Modal; sources are combined, so a clean Form does not overrule a\n // `<Modal confirmOnClose>`. The Modal renders the confirmation dialog.\n // A Form that switched it off contributes nothing at all.\n confirmOnClose: confirmModalCloseOnUnsavedChanges ? isDirty : undefined,\n });\n modalController.useOnClosed(() => {\n if (autoResetOptions?.onAfterModalClose) {\n form.reset();\n }\n });\n\n const { submitInterceptor } = useFormSettings();\n const onSubmit = submitInterceptor\n ? (values: F, event?: BaseSyntheticEvent) =>\n submitInterceptor<F>(onSubmitProp, values, { form, event })\n : onSubmitProp;\n\n const handleSubmitResult = (result: unknown) => {\n if (typeof result === \"function\") {\n afterSubmitCallback.current = result as AfterFormSubmitCallback;\n }\n const rootError = form.getFieldState(\"root\" as Path<F>)?.error;\n if (rootError && !rootErrorController.errorComponentMounted) {\n throw new FormRootError(rootError);\n }\n };\n\n const handleSubmit = async (e?: BaseSyntheticEvent | F): Promise<void> => {\n const formEvent =\n e && \"nativeEvent\" in e ? (e as BaseSyntheticEvent) : undefined;\n formEvent?.stopPropagation();\n\n // react-hook-form's submit handler resolves with an unknown value; the\n // submit controller only awaits it, so drop the result.\n await form.handleSubmit((values, event) =>\n runWithGrantedModalClose(modalController, () => {\n const submitResult = onSubmit(values, event);\n if (submitResult instanceof Promise) {\n return submitResult.then(handleSubmitResult);\n }\n handleSubmitResult(submitResult);\n }),\n )(formEvent);\n };\n submitController.submit.set(handleSubmit);\n\n const onAfterSuccessFeedback = () => {\n const callback = afterSubmitCallback.current;\n if (!callback) {\n return;\n }\n // The callback runs after the submit itself has finished (and after\n // SubmitButton's success feedback), so it needs its own permission to close\n // the Modal.\n runWithGrantedModalClose(modalController, callback);\n };\n\n const refWithHotkeySubmit = useHotkeySubmit({\n ref,\n submitController,\n });\n\n return (\n <RhfFormContextProvider {...form}>\n <FormContextProvider\n form={form as UseFormReturn}\n isReadOnly={isReadOnly}\n id={formId}\n onAfterSuccessFeedback={onAfterSuccessFeedback}\n rootErrorController={rootErrorController}\n >\n <FormComponent\n {...formProps}\n ref={refWithHotkeySubmit}\n id={formId}\n onSubmit={handleSubmit}\n >\n {children}\n </FormComponent>\n </FormContextProvider>\n </RhfFormContextProvider>\n );\n}\n\nexport default Form;\n"],"mappings":";;;;;;;;;;;;;;AA4FA,IAAM,wBAA2C,MAAM,oBAAC,QAAD,EAAM,GAAI,EAAI,CAAA;;;;;;;AAQrE,IAAM,4BACJ,iBACA,cACY;CACZ,MAAM,eAAe,gBAAgB,8BAA8B;CAEnE,IAAI;CACJ,IAAI;EACF,SAAS,UAAU;CACrB,SAAS,OAAO;EACd,aAAa;EACb,MAAM;CACR;CAEA,IAAI,kBAAkB,SACpB,OAAO,OAAO,QAAQ,YAAY;CAEpC,aAAa;CACb,OAAO;AACT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BAAuB;GAC9C,MAAM,eAAe,SAAS,QAAQ,KAAK;GAC3C,IAAI,wBAAwB,SAC1B,OAAO,aAAa,KAAK,kBAAkB;GAE7C,mBAAmB,YAAY;EACjC,CAAC,CACH,CAAC,CAAC,SAAS;CACb;CACA,iBAAiB,OAAO,IAAI,YAAY;CAExC,MAAM,+BAA+B;EACnC,MAAM,WAAW,oBAAoB;EACrC,IAAI,CAAC,UACH;EAKF,yBAAyB,iBAAiB,QAAQ;CACpD;CAEA,MAAM,sBAAsB,gBAAgB;EAC1C;EACA;CACF,CAAC;CAED,OACE,oBAACA,cAAD;EAAwB,GAAI;EAC1B,UAAA,oBAAC,qBAAD;GACQ;GACM;GACZ,IAAI;GACoB;GACH;GAErB,UAAA,oBAAC,eAAD;IACE,GAAI;IACJ,KAAK;IACL,IAAI;IACJ,UAAU;IAET;GACY,CAAA;EACI,CAAA;CACC,CAAA;AAE5B"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useFormSubmitAction.mjs","names":[],"sources":["../../../../../../../../../src/integrations/react-hook-form/components/FormContextProvider/useFormSubmitAction.ts"],"sourcesContent":["import { AbortActionError, type ActionProps } from \"@/components/Action\";\nimport { ActionModel } from \"@/components/Action/models/ActionModel\";\nimport { useEffect, useRef } from \"react\";\nimport type { FieldValues, FormState } from \"react-hook-form\";\n\nexport const useFormSubmitAction = (\n formState: FormState<FieldValues>,\n actionProps?: ActionProps,\n) => {\n const { isSubmitting, isSubmitSuccessful } = formState;\n\n const submitPromise = useRef<PromiseWithResolvers<void>>(undefined);\n\n const formSubmitAction = ActionModel.useNew({\n ...actionProps,\n onAction: () => {\n submitPromise.current = Promise.withResolvers<void>();\n actionProps?.onAction?.();\n return submitPromise.current.promise;\n },\n });\n\n useEffect(() => {\n if (isSubmitting) {\n if (!formSubmitAction.state.isBusy) {\n /**\n * Manually start execution. This happens if the form submission was\n * triggered by other means than the submit button, e.g. by pressing\n * Enter in a text field.\n */\n formSubmitAction.execute();\n }\n return;\n }\n\n if (isSubmitSuccessful) {\n submitPromise.current?.resolve();\n return;\n }\n\n submitPromise.current?.reject(\n new AbortActionError(\"Form submission failed\"),\n );\n }, [isSubmitting, isSubmitSuccessful, submitPromise]);\n\n return formSubmitAction;\n};\n"],"mappings":";;;;;;AAKA,IAAa,uBACX,WACA,gBACG;CACH,MAAM,EAAE,cAAc,uBAAuB;CAE7C,MAAM,gBAAgB,OAAmC,KAAA,CAAS;CAElE,MAAM,mBAAmB,YAAY,OAAO;EAC1C,GAAG;EACH,gBAAgB;GACd,cAAc,UAAU,QAAQ,cAAoB;GACpD,aAAa,WAAW;GACxB,OAAO,cAAc,QAAQ;EAC/B;CACF,CAAC;CAED,gBAAgB;EACd,IAAI,cAAc;GAChB,IAAI,CAAC,iBAAiB,MAAM;;;;;;GAM1B,iBAAiB,QAAQ;GAE3B;EACF;EAEA,IAAI,oBAAoB;GACtB,cAAc,SAAS,QAAQ;GAC/B;EACF;EAEA,cAAc,SAAS,OACrB,IAAI,iBAAiB,wBAAwB,CAC/C;
|
|
1
|
+
{"version":3,"file":"useFormSubmitAction.mjs","names":[],"sources":["../../../../../../../../../src/integrations/react-hook-form/components/FormContextProvider/useFormSubmitAction.ts"],"sourcesContent":["import { AbortActionError, type ActionProps } from \"@/components/Action\";\nimport { ActionModel } from \"@/components/Action/models/ActionModel\";\nimport { useEffect, useRef } from \"react\";\nimport type { FieldValues, FormState } from \"react-hook-form\";\n\nexport const useFormSubmitAction = (\n formState: FormState<FieldValues>,\n actionProps?: ActionProps,\n) => {\n const { isSubmitting, isSubmitSuccessful } = formState;\n\n const submitPromise = useRef<PromiseWithResolvers<void>>(undefined);\n\n const formSubmitAction = ActionModel.useNew({\n ...actionProps,\n onAction: () => {\n submitPromise.current = Promise.withResolvers<void>();\n actionProps?.onAction?.();\n return submitPromise.current.promise;\n },\n });\n\n useEffect(() => {\n if (isSubmitting) {\n if (!formSubmitAction.state.isBusy) {\n /**\n * Manually start execution. This happens if the form submission was\n * triggered by other means than the submit button, e.g. by pressing\n * Enter in a text field.\n */\n formSubmitAction.execute();\n }\n return;\n }\n\n if (isSubmitSuccessful) {\n submitPromise.current?.resolve();\n return;\n }\n\n submitPromise.current?.reject(\n new AbortActionError(\"Form submission failed\"),\n );\n // eslint-disable-next-line react-hooks/exhaustive-deps -- the action model is new each render; react to form state changes only\n }, [isSubmitting, isSubmitSuccessful, submitPromise]);\n\n return formSubmitAction;\n};\n"],"mappings":";;;;;;AAKA,IAAa,uBACX,WACA,gBACG;CACH,MAAM,EAAE,cAAc,uBAAuB;CAE7C,MAAM,gBAAgB,OAAmC,KAAA,CAAS;CAElE,MAAM,mBAAmB,YAAY,OAAO;EAC1C,GAAG;EACH,gBAAgB;GACd,cAAc,UAAU,QAAQ,cAAoB;GACpD,aAAa,WAAW;GACxB,OAAO,cAAc,QAAQ;EAC/B;CACF,CAAC;CAED,gBAAgB;EACd,IAAI,cAAc;GAChB,IAAI,CAAC,iBAAiB,MAAM;;;;;;GAM1B,iBAAiB,QAAQ;GAE3B;EACF;EAEA,IAAI,oBAAoB;GACtB,cAAc,SAAS,QAAQ;GAC/B;EACF;EAEA,cAAc,SAAS,OACrB,IAAI,iBAAiB,wBAAwB,CAC/C;CAEF,GAAG;EAAC;EAAc;EAAoB;CAAa,CAAC;CAEpD,OAAO;AACT"}
|
|
@@ -25,15 +25,16 @@ var OverlayController = class OverlayController extends OverlayState {
|
|
|
25
25
|
*/
|
|
26
26
|
useConfirmOnCloseSource(confirmOnClose) {
|
|
27
27
|
const source = useStatic(() => ({}));
|
|
28
|
+
const controller = this;
|
|
28
29
|
useEffect(() => {
|
|
29
30
|
if (confirmOnClose === void 0) {
|
|
30
|
-
|
|
31
|
+
controller.removeConfirmOnCloseSource(source);
|
|
31
32
|
return;
|
|
32
33
|
}
|
|
33
|
-
|
|
34
|
-
return () =>
|
|
34
|
+
controller.setConfirmOnCloseSource(source, confirmOnClose);
|
|
35
|
+
return () => controller.removeConfirmOnCloseSource(source);
|
|
35
36
|
}, [
|
|
36
|
-
|
|
37
|
+
controller,
|
|
37
38
|
source,
|
|
38
39
|
confirmOnClose
|
|
39
40
|
]);
|
|
@@ -66,7 +67,8 @@ var OverlayController = class OverlayController extends OverlayState {
|
|
|
66
67
|
return controller;
|
|
67
68
|
}
|
|
68
69
|
useOnHandler(handler, addHandlerFn) {
|
|
69
|
-
|
|
70
|
+
const controller = this;
|
|
71
|
+
useEffect(() => handler ? addHandlerFn(handler) : void 0, [handler, controller]);
|
|
70
72
|
}
|
|
71
73
|
useIsOpen() {
|
|
72
74
|
return useSelector(() => this.isOpen);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"OverlayController.mjs","names":[],"sources":["../../../../../../../../src/lib/controller/overlay/OverlayController.ts"],"sourcesContent":["import {\n OverlayState,\n type AnyOverlayOpenStateHandler,\n type DisposerFn,\n type OverlayCloseHandler,\n type OverlayCloseOptions,\n type OverlayOpenHandler,\n type OverlayOpenStateHandler,\n} from \"@mittwald/flow-components-base\";\nimport useSelector from \"@/lib/mobx/useSelector\";\nimport { useStatic } from \"@/lib/hooks/useStatic\";\nimport { useEffect, useRef, type DependencyList } from \"react\";\nimport { useCloseOverlayConfirmationController } from \"@/lib/controller/overlay/useCloseOverlayConfirmationController\";\nimport type { FlowComponentName } from \"@/components/propTypes\";\n\nexport type {\n OverlayCloseHandler,\n OverlayOpenHandler,\n OverlayOpenStateHandler,\n} from \"@mittwald/flow-components-base\";\n\nexport interface CloseOverlayOptions extends OverlayCloseOptions {\n /**\n * The overlay to close. Omitted, the nearest enclosing overlay is closed –\n * the same thing `closeOverlay={true}` means.\n */\n overlay?: FlowComponentName | OverlayController;\n}\n\nexport interface OnOverlayClosedOptions {\n dependencies?: DependencyList;\n}\n\nexport type CloseModalOptions = Omit<CloseOverlayOptions, \"overlay\">;\n\n/**\n * Every way an action can point at an overlay: by the Flow component name it\n * registers under, by controller, by options, or with `true` – the nearest\n * enclosing overlay, whatever its name.\n */\nexport type OverlayReference =\n FlowComponentName | OverlayController | CloseOverlayOptions | true;\n\ntype CloseOptions = CloseOverlayOptions | CloseModalOptions;\n\nexport interface OverlayControllerOptions {\n isDefaultOpen?: boolean;\n onOpen?: OverlayOpenHandler;\n onClose?: OverlayCloseHandler;\n onOpenChange?: OverlayOpenStateHandler;\n /**\n * Whether closing the overlay must be confirmed. `undefined` means \"no\n * opinion\": the value is not contributed at all, so other sources (e.g. a\n * `Modal`'s `confirmOnClose` prop or a dirty `Form`) still decide.\n */\n confirmOnClose?: boolean;\n}\n\n/**\n * The state is `OverlayState` from `@mittwald/flow-components-base`, shared\n * with every remote binding; this adds the hooks.\n */\nexport class OverlayController extends OverlayState<CloseOptions> {\n public useUpdateOptions(options: OverlayControllerOptions = {}): void {\n const { onOpen, onClose, onOpenChange, confirmOnClose } = options;\n\n this.useOnHandler(onOpen, (h) => this.addOnOpen(h));\n this.useOnHandler(onClose, (h) => this.addOnClose(h));\n this.useOnHandler(onOpenChange, (h) => this.addOnOpenChange(h));\n\n this.useConfirmOnCloseSource(confirmOnClose);\n }\n\n /**\n * Registers the calling component as a close confirmation source for as long\n * as it is mounted. `undefined` contributes nothing at all.\n */\n private useConfirmOnCloseSource(confirmOnClose: boolean | undefined): void {\n const source = useStatic((): object => ({}));\n\n useEffect(() => {\n if (confirmOnClose === undefined) {\n
|
|
1
|
+
{"version":3,"file":"OverlayController.mjs","names":[],"sources":["../../../../../../../../src/lib/controller/overlay/OverlayController.ts"],"sourcesContent":["import {\n OverlayState,\n type AnyOverlayOpenStateHandler,\n type DisposerFn,\n type OverlayCloseHandler,\n type OverlayCloseOptions,\n type OverlayOpenHandler,\n type OverlayOpenStateHandler,\n} from \"@mittwald/flow-components-base\";\nimport useSelector from \"@/lib/mobx/useSelector\";\nimport { useStatic } from \"@/lib/hooks/useStatic\";\nimport { useEffect, useRef, type DependencyList } from \"react\";\nimport { useCloseOverlayConfirmationController } from \"@/lib/controller/overlay/useCloseOverlayConfirmationController\";\nimport type { FlowComponentName } from \"@/components/propTypes\";\n\nexport type {\n OverlayCloseHandler,\n OverlayOpenHandler,\n OverlayOpenStateHandler,\n} from \"@mittwald/flow-components-base\";\n\nexport interface CloseOverlayOptions extends OverlayCloseOptions {\n /**\n * The overlay to close. Omitted, the nearest enclosing overlay is closed –\n * the same thing `closeOverlay={true}` means.\n */\n overlay?: FlowComponentName | OverlayController;\n}\n\nexport interface OnOverlayClosedOptions {\n dependencies?: DependencyList;\n}\n\nexport type CloseModalOptions = Omit<CloseOverlayOptions, \"overlay\">;\n\n/**\n * Every way an action can point at an overlay: by the Flow component name it\n * registers under, by controller, by options, or with `true` – the nearest\n * enclosing overlay, whatever its name.\n */\nexport type OverlayReference =\n FlowComponentName | OverlayController | CloseOverlayOptions | true;\n\ntype CloseOptions = CloseOverlayOptions | CloseModalOptions;\n\nexport interface OverlayControllerOptions {\n isDefaultOpen?: boolean;\n onOpen?: OverlayOpenHandler;\n onClose?: OverlayCloseHandler;\n onOpenChange?: OverlayOpenStateHandler;\n /**\n * Whether closing the overlay must be confirmed. `undefined` means \"no\n * opinion\": the value is not contributed at all, so other sources (e.g. a\n * `Modal`'s `confirmOnClose` prop or a dirty `Form`) still decide.\n */\n confirmOnClose?: boolean;\n}\n\n/**\n * The state is `OverlayState` from `@mittwald/flow-components-base`, shared\n * with every remote binding; this adds the hooks.\n */\nexport class OverlayController extends OverlayState<CloseOptions> {\n public useUpdateOptions(options: OverlayControllerOptions = {}): void {\n const { onOpen, onClose, onOpenChange, confirmOnClose } = options;\n\n this.useOnHandler(onOpen, (h) => this.addOnOpen(h));\n this.useOnHandler(onClose, (h) => this.addOnClose(h));\n this.useOnHandler(onOpenChange, (h) => this.addOnOpenChange(h));\n\n this.useConfirmOnCloseSource(confirmOnClose);\n }\n\n /**\n * Registers the calling component as a close confirmation source for as long\n * as it is mounted. `undefined` contributes nothing at all.\n */\n private useConfirmOnCloseSource(confirmOnClose: boolean | undefined): void {\n const source = useStatic((): object => ({}));\n // eslint-disable-next-line @typescript-eslint/no-this-alias -- a dependency must be a plain variable\n const controller = this;\n\n useEffect(() => {\n if (confirmOnClose === undefined) {\n controller.removeConfirmOnCloseSource(source);\n return;\n }\n controller.setConfirmOnCloseSource(source, confirmOnClose);\n return () => controller.removeConfirmOnCloseSource(source);\n }, [controller, source, confirmOnClose]);\n }\n\n /**\n * Can be used to execute a callback when the Overlay has unmounted – means\n * after any closing animation.\n *\n * NOTICE: This hook only works inside the corresponding Overlay!\n */\n public useOnClosed(\n callback: () => unknown,\n options: OnOverlayClosedOptions = {},\n ) {\n const { dependencies = [] } = options;\n const isOpen = this.useIsOpen();\n const wasOpen = useRef(this.isOpen);\n\n this.useUpdateOptions({\n onOpen: () => {\n wasOpen.current = true;\n },\n });\n\n useEffect(() => {\n return () => {\n if (!isOpen && wasOpen.current) {\n wasOpen.current = false;\n callback();\n }\n };\n // eslint-disable-next-line react-hooks/exhaustive-deps -- the caller passes the callback's dependencies\n }, [isOpen, ...dependencies]);\n }\n\n public static useNew(\n options: OverlayControllerOptions = {},\n ): OverlayController {\n const controller = useStatic(() => new OverlayController(options));\n controller.useUpdateOptions(options);\n return controller;\n }\n\n private useOnHandler<T extends AnyOverlayOpenStateHandler>(\n handler: T | undefined,\n addHandlerFn: (handler: T) => DisposerFn,\n ) {\n // eslint-disable-next-line @typescript-eslint/no-this-alias -- a dependency must be a plain variable\n const controller = this;\n\n useEffect(\n () => (handler ? addHandlerFn(handler) : undefined),\n // eslint-disable-next-line react-hooks/exhaustive-deps -- addHandlerFn is an inline arrow, new each render\n [handler, controller],\n );\n }\n\n public useIsOpen() {\n return useSelector(() => this.isOpen);\n }\n\n public useIsContentSuspended() {\n return useSelector(() => this.isContentSuspended);\n }\n\n public useShowConfirmationModal() {\n return useSelector(() => this.showConfirmationModal);\n }\n\n public useConfirmOnCloseEnabled() {\n return useSelector(() => this.confirmOnCloseEnabled);\n }\n\n public useConfirmationController() {\n return useCloseOverlayConfirmationController(this);\n }\n}\n"],"mappings":";;;;;;;;;;;;;A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YAAmB;EACjB,OAAO,kBAAkB,KAAK,MAAM;CACtC;CAEA,wBAA+B;EAC7B,OAAO,kBAAkB,KAAK,kBAAkB;CAClD;CAEA,2BAAkC;EAChC,OAAO,kBAAkB,KAAK,qBAAqB;CACrD;CAEA,2BAAkC;EAChC,OAAO,kBAAkB,KAAK,qBAAqB;CACrD;CAEA,4BAAmC;EACjC,OAAO,sCAAsC,IAAI;CACnD;AACF"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useMakeFocusable.mjs","names":[],"sources":["../../../../../../../../src/lib/hooks/dom/useMakeFocusable.ts"],"sourcesContent":["import { type RefObject, useEffect } from \"react\";\n\n/**\n * A hook that makes an element focusable and calls a callback when it receives\n * focus.\n */\nexport const useMakeFocusable = (\n ref: RefObject<unknown>,\n onFocus?: CallableFunction,\n) => {\n useEffect(() => {\n const element = ref.current;\n const shouldProcessElement = element && element instanceof HTMLElement;\n\n if (!shouldProcessElement) {\n return;\n }\n\n const onFocusHandler = () => onFocus?.();\n element.addEventListener(\"focus\", onFocusHandler);\n\n const hasTabIndex = element.hasAttribute(\"tabIndex\");\n if (!hasTabIndex) {\n // when we have no tabIndex, we set it to -1 to make it focusable\n element.setAttribute(\"tabIndex\", \"-1\");\n }\n\n return () => {\n element.removeEventListener(\"focus\", onFocusHandler);\n if (!hasTabIndex) {\n element.removeAttribute(\"tabIndex\");\n }\n };\n }, [ref.current, onFocus]);\n};\n"],"mappings":";;;;;;;;AAMA,IAAa,oBACX,KACA,YACG;CACH,gBAAgB;EACd,MAAM,UAAU,IAAI;EAGpB,IAAI,EAFyB,WAAW,mBAAmB,cAGzD;EAGF,MAAM,uBAAuB,UAAU;EACvC,QAAQ,iBAAiB,SAAS,cAAc;EAEhD,MAAM,cAAc,QAAQ,aAAa,UAAU;EACnD,IAAI,CAAC,aAEH,QAAQ,aAAa,YAAY,IAAI;EAGvC,aAAa;GACX,QAAQ,oBAAoB,SAAS,cAAc;GACnD,IAAI,CAAC,aACH,QAAQ,gBAAgB,UAAU;EAEtC;
|
|
1
|
+
{"version":3,"file":"useMakeFocusable.mjs","names":[],"sources":["../../../../../../../../src/lib/hooks/dom/useMakeFocusable.ts"],"sourcesContent":["import { type RefObject, useEffect } from \"react\";\n\n/**\n * A hook that makes an element focusable and calls a callback when it receives\n * focus.\n */\nexport const useMakeFocusable = (\n ref: RefObject<unknown>,\n onFocus?: CallableFunction,\n) => {\n useEffect(() => {\n const element = ref.current;\n const shouldProcessElement = element && element instanceof HTMLElement;\n\n if (!shouldProcessElement) {\n return;\n }\n\n const onFocusHandler = () => onFocus?.();\n element.addEventListener(\"focus\", onFocusHandler);\n\n const hasTabIndex = element.hasAttribute(\"tabIndex\");\n if (!hasTabIndex) {\n // when we have no tabIndex, we set it to -1 to make it focusable\n element.setAttribute(\"tabIndex\", \"-1\");\n }\n\n return () => {\n element.removeEventListener(\"focus\", onFocusHandler);\n if (!hasTabIndex) {\n element.removeAttribute(\"tabIndex\");\n }\n };\n // eslint-disable-next-line react-hooks/exhaustive-deps -- re-attach when the ref points to a new element\n }, [ref.current, onFocus]);\n};\n"],"mappings":";;;;;;;;AAMA,IAAa,oBACX,KACA,YACG;CACH,gBAAgB;EACd,MAAM,UAAU,IAAI;EAGpB,IAAI,EAFyB,WAAW,mBAAmB,cAGzD;EAGF,MAAM,uBAAuB,UAAU;EACvC,QAAQ,iBAAiB,SAAS,cAAc;EAEhD,MAAM,cAAc,QAAQ,aAAa,UAAU;EACnD,IAAI,CAAC,aAEH,QAAQ,aAAa,YAAY,IAAI;EAGvC,aAAa;GACX,QAAQ,oBAAoB,SAAS,cAAc;GACnD,IAAI,CAAC,aACH,QAAQ,gBAAgB,UAAU;EAEtC;CAEF,GAAG,CAAC,IAAI,SAAS,OAAO,CAAC;AAC3B"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useFieldError.mjs","names":["formFieldStyles"],"sources":["../../../../../../../src/lib/hooks/useFieldError.tsx"],"sourcesContent":["import React, {\n type FC,\n type PropsWithChildren,\n useMemo,\n useState,\n} from \"react\";\nimport { type PropsContext, PropsContextProvider } from \"@/lib/propsContext\";\nimport formFieldStyles from \"@/components/FormField/FormField.module.scss\";\nimport ClearPropsContext from \"@/lib/propsContext/components/ClearPropsContext\";\nimport { useProps } from \"@/lib/hooks/useProps\";\nimport { UiComponentTunnelExit } from \"@/components/UiComponentTunnel/UiComponentTunnelExit\";\nimport type { FlowComponentName } from \"@/components/propTypes\";\nimport { FieldErrorRenderedContext } from \"@/lib/hooks/fieldErrorRenderedContext\";\n\nexport interface UseFieldErrorOptions {\n fieldErrorId: string;\n tunnelId?: string;\n component: FlowComponentName;\n}\n\nexport const useFieldError = (options: UseFieldErrorOptions) => {\n const fieldErrorProps = useProps(\"FieldError\", {});\n const currentTunnelId = fieldErrorProps.tunnel?.id;\n const tunnelId =\n options.tunnelId ?? currentTunnelId ?? `${options.fieldErrorId}.fieldError`;\n\n const fieldErrorCapturePropsContext: PropsContext = {\n FieldError: {\n id: options.fieldErrorId,\n tunnel: { id: tunnelId, component: options.component },\n className: formFieldStyles.fieldError,\n },\n };\n\n const [renderedFieldErrorId, setRenderedFieldErrorId] = useState<string>();\n\n const FieldErrorCaptureContext: FC<PropsWithChildren> = useMemo(\n () => (props) => {\n return (\n <PropsContextProvider\n props={fieldErrorCapturePropsContext}\n dependencies={[tunnelId]}\n >\n {props.children}\n </PropsContextProvider>\n );\n },\n [tunnelId],\n );\n\n // Keep the component identity stable: a new one per render makes React\n // remount the error on every render of the field (each keystroke).\n const FieldErrorView: FC = useMemo(\n () => () => {\n if (currentTunnelId) {\n return null;\n }\n\n return (\n <FieldErrorRenderedContext value={setRenderedFieldErrorId}>\n <UiComponentTunnelExit id={tunnelId} component={options.component}>\n {(children) => {\n const childrenArray = React.Children.toArray(children);\n return <ClearPropsContext>{childrenArray[0]}</ClearPropsContext>;\n }}\n </UiComponentTunnelExit>\n </FieldErrorRenderedContext>\n );\n },\n [currentTunnelId, tunnelId, options.component],\n );\n\n return {\n FieldErrorCaptureContext,\n FieldErrorView,\n /**\n * The id of the error while one is rendered for this field. A nested field\n * (a `Checkbox` inside a `CheckboxButton`) renders its error at the outer\n * one, so only the outer field ever gets an id here.\n */\n renderedFieldErrorId,\n } as const;\n};\n"],"mappings":";;;;;;;;;;;AAoBA,IAAa,iBAAiB,YAAkC;CAE9D,MAAM,kBADkB,SAAS,cAAc,CAAC,CACxB,CAAA,CAAgB,QAAQ;CAChD,MAAM,WACJ,QAAQ,YAAY,mBAAmB,GAAG,QAAQ,aAAa;CAEjE,MAAM,gCAA8C,EAClD,YAAY;EACV,IAAI,QAAQ;EACZ,QAAQ;GAAE,IAAI;GAAU,WAAW,QAAQ;EAAU;EACrD,WAAWA,yBAAgB;CAC7B,EACF;CAEA,MAAM,CAAC,sBAAsB,2BAA2B,SAAiB;
|
|
1
|
+
{"version":3,"file":"useFieldError.mjs","names":["formFieldStyles"],"sources":["../../../../../../../src/lib/hooks/useFieldError.tsx"],"sourcesContent":["import React, {\n type FC,\n type PropsWithChildren,\n useMemo,\n useState,\n} from \"react\";\nimport { type PropsContext, PropsContextProvider } from \"@/lib/propsContext\";\nimport formFieldStyles from \"@/components/FormField/FormField.module.scss\";\nimport ClearPropsContext from \"@/lib/propsContext/components/ClearPropsContext\";\nimport { useProps } from \"@/lib/hooks/useProps\";\nimport { UiComponentTunnelExit } from \"@/components/UiComponentTunnel/UiComponentTunnelExit\";\nimport type { FlowComponentName } from \"@/components/propTypes\";\nimport { FieldErrorRenderedContext } from \"@/lib/hooks/fieldErrorRenderedContext\";\n\nexport interface UseFieldErrorOptions {\n fieldErrorId: string;\n tunnelId?: string;\n component: FlowComponentName;\n}\n\nexport const useFieldError = (options: UseFieldErrorOptions) => {\n const fieldErrorProps = useProps(\"FieldError\", {});\n const currentTunnelId = fieldErrorProps.tunnel?.id;\n const tunnelId =\n options.tunnelId ?? currentTunnelId ?? `${options.fieldErrorId}.fieldError`;\n\n const fieldErrorCapturePropsContext: PropsContext = {\n FieldError: {\n id: options.fieldErrorId,\n tunnel: { id: tunnelId, component: options.component },\n className: formFieldStyles.fieldError,\n },\n };\n\n const [renderedFieldErrorId, setRenderedFieldErrorId] = useState<string>();\n\n const FieldErrorCaptureContext: FC<PropsWithChildren> = useMemo(\n () => (props) => {\n return (\n <PropsContextProvider\n props={fieldErrorCapturePropsContext}\n dependencies={[tunnelId]}\n >\n {props.children}\n </PropsContextProvider>\n );\n },\n // eslint-disable-next-line react-hooks/exhaustive-deps -- the props context is new each render and only changes with tunnelId\n [tunnelId],\n );\n\n // Keep the component identity stable: a new one per render makes React\n // remount the error on every render of the field (each keystroke).\n const FieldErrorView: FC = useMemo(\n () => () => {\n if (currentTunnelId) {\n return null;\n }\n\n return (\n <FieldErrorRenderedContext value={setRenderedFieldErrorId}>\n <UiComponentTunnelExit id={tunnelId} component={options.component}>\n {(children) => {\n const childrenArray = React.Children.toArray(children);\n return <ClearPropsContext>{childrenArray[0]}</ClearPropsContext>;\n }}\n </UiComponentTunnelExit>\n </FieldErrorRenderedContext>\n );\n },\n [currentTunnelId, tunnelId, options.component],\n );\n\n return {\n FieldErrorCaptureContext,\n FieldErrorView,\n /**\n * The id of the error while one is rendered for this field. A nested field\n * (a `Checkbox` inside a `CheckboxButton`) renders its error at the outer\n * one, so only the outer field ever gets an id here.\n */\n renderedFieldErrorId,\n } as const;\n};\n"],"mappings":";;;;;;;;;;;AAoBA,IAAa,iBAAiB,YAAkC;CAE9D,MAAM,kBADkB,SAAS,cAAc,CAAC,CACxB,CAAA,CAAgB,QAAQ;CAChD,MAAM,WACJ,QAAQ,YAAY,mBAAmB,GAAG,QAAQ,aAAa;CAEjE,MAAM,gCAA8C,EAClD,YAAY;EACV,IAAI,QAAQ;EACZ,QAAQ;GAAE,IAAI;GAAU,WAAW,QAAQ;EAAU;EACrD,WAAWA,yBAAgB;CAC7B,EACF;CAEA,MAAM,CAAC,sBAAsB,2BAA2B,SAAiB;CAuCzE,OAAO;EACL,0BAtCsD,eAC/C,UAAU;GACf,OACE,oBAAC,sBAAD;IACE,OAAO;IACP,cAAc,CAAC,QAAQ;IAEtB,UAAA,MAAM;GACa,CAAA;EAE1B,GAEA,CAAC,QAAQ,CA0BT;EACA,gBAtByB,oBACb;GACV,IAAI,iBACF,OAAO;GAGT,OACE,oBAAC,2BAAD;IAA2B,OAAO;IAChC,UAAA,oBAAC,uBAAD;KAAuB,IAAI;KAAU,WAAW,QAAQ;KACpD,WAAA,aAAa;MACb,MAAM,gBAAgB,MAAM,SAAS,QAAQ,QAAQ;MACrD,OAAO,oBAAC,mBAAD,EAAA,UAAoB,cAAc,GAAsB,CAAA;KACjE;IACqB,CAAA;GACE,CAAA;EAE/B,GACA;GAAC;GAAiB;GAAU,QAAQ;EAAS,CAK7C;;;;;;EAMA;CACF;AACF"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useOnChange.mjs","names":[],"sources":["../../../../../../../src/lib/hooks/useOnChange.ts"],"sourcesContent":["import type { DependencyList } from \"react\";\nimport { useEffect, useRef } from \"react\";\n\nexport const useOnChange = (\n value: unknown,\n callback: () => void,\n dependencies: DependencyList = [],\n) => {\n const oldValue = useRef(value);\n\n useEffect(() => {\n if (oldValue.current !== value) {\n callback();\n }\n oldValue.current = value;\n }, [value, callback, ...dependencies]);\n};\n"],"mappings":";;;;AAGA,IAAa,eACX,OACA,UACA,eAA+B,CAAC,MAC7B;CACH,MAAM,WAAW,OAAO,KAAK;CAE7B,gBAAgB;EACd,IAAI,SAAS,YAAY,OACvB,SAAS;EAEX,SAAS,UAAU;
|
|
1
|
+
{"version":3,"file":"useOnChange.mjs","names":[],"sources":["../../../../../../../src/lib/hooks/useOnChange.ts"],"sourcesContent":["import type { DependencyList } from \"react\";\nimport { useEffect, useRef } from \"react\";\n\nexport const useOnChange = (\n value: unknown,\n callback: () => void,\n dependencies: DependencyList = [],\n) => {\n const oldValue = useRef(value);\n\n useEffect(() => {\n if (oldValue.current !== value) {\n callback();\n }\n oldValue.current = value;\n // eslint-disable-next-line react-hooks/exhaustive-deps -- the caller passes the callback's dependencies\n }, [value, callback, ...dependencies]);\n};\n"],"mappings":";;;;AAGA,IAAa,eACX,OACA,UACA,eAA+B,CAAC,MAC7B;CACH,MAAM,WAAW,OAAO,KAAK;CAE7B,gBAAgB;EACd,IAAI,SAAS,YAAY,OACvB,SAAS;EAEX,SAAS,UAAU;CAErB,GAAG;EAAC;EAAO;EAAU,GAAG;CAAY,CAAC;AACvC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useSelector.mjs","names":[],"sources":["../../../../../../../src/lib/mobx/useSelector.ts"],"sourcesContent":["import { autorun } from \"mobx\";\nimport { useEffect, useState } from \"react\";\n\nexport type MobXSelector<T> = () => T;\n\n/** Use this hook to select reactive state from the store */\nexport const useSelector = <T>(\n select: MobXSelector<T>,\n deps: unknown[] = [],\n): T => {\n const [selected, setSelected] = useState<T>(select());\n\n useEffect(() => {\n return autorun(() => {\n setSelected(select());\n });\n }, deps);\n\n return selected;\n};\n\nexport default useSelector;\n"],"mappings":";;;;;;AAMA,IAAa,eACX,QACA,OAAkB,CAAC,MACb;CACN,MAAM,CAAC,UAAU,eAAe,SAAY,OAAO,CAAC;CAEpD,gBAAgB;EACd,OAAO,cAAc;GACnB,YAAY,OAAO,CAAC;EACtB,CAAC;
|
|
1
|
+
{"version":3,"file":"useSelector.mjs","names":[],"sources":["../../../../../../../src/lib/mobx/useSelector.ts"],"sourcesContent":["import { autorun } from \"mobx\";\nimport { useEffect, useState } from \"react\";\n\nexport type MobXSelector<T> = () => T;\n\n/** Use this hook to select reactive state from the store */\nexport const useSelector = <T>(\n select: MobXSelector<T>,\n deps: unknown[] = [],\n): T => {\n const [selected, setSelected] = useState<T>(select());\n\n useEffect(() => {\n return autorun(() => {\n setSelected(select());\n });\n // eslint-disable-next-line react-hooks/exhaustive-deps -- the caller passes the selector's dependencies\n }, deps);\n\n return selected;\n};\n\nexport default useSelector;\n"],"mappings":";;;;;;AAMA,IAAa,eACX,QACA,OAAkB,CAAC,MACb;CACN,MAAM,CAAC,UAAU,eAAe,SAAY,OAAO,CAAC;CAEpD,gBAAgB;EACd,OAAO,cAAc;GACnB,YAAY,OAAO,CAAC;EACtB,CAAC;CAEH,GAAG,IAAI;CAEP,OAAO;AACT"}
|
|
@@ -22,7 +22,7 @@ var useControlledHostValueProps = (props, emptyValue) => {
|
|
|
22
22
|
const [value, setValue] = useState(regularValue !== void 0 ? regularValue : defaultValue !== void 0 ? defaultValue : emptyValue);
|
|
23
23
|
useLayoutEffect(() => {
|
|
24
24
|
if (regularValue !== void 0) setValue(regularValue);
|
|
25
|
-
}, [
|
|
25
|
+
}, [regularValue]);
|
|
26
26
|
const onChange = (v) => {
|
|
27
27
|
setValue(v);
|
|
28
28
|
onChangeFromProps?.(v);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useControlledHostValueProps.mjs","names":[],"sources":["../../../../../../../src/lib/remote/useControlledHostValueProps.ts"],"sourcesContent":["import { useLayoutEffect, useState } from \"react\";\nimport { controlledRemoteValueMarker } from \"./useControlledRemoteValueProps\";\nimport type { FieldProps } from \"@/lib/remote/types\";\n\n/**\n * Returns props with controlled value handling for remote components. It works\n * by omitting values resulting from a remotely executed event handler. These\n * values are marked by the `controlledRemoteValueMarker`.\n *\n * This hook is only necessary for text inputs. If not used the controlled input\n * value may be corrupted by interleaved host inputs and remote events.\n *\n * @param emptyValue What the field reports while nothing has been entered —\n * `\"\"` for a text input, `NaN` for a number, `null` for a date range. It is\n * the sentinel that keeps the field controlled from the first render; see\n * that convention in the package's AGENTS.md.\n */\nexport const useControlledHostValueProps = <T, P>(\n props: FieldProps<T, P>,\n emptyValue: T,\n) => {\n const {\n value: valueFromProps,\n onChange: onChangeFromProps,\n defaultValue,\n } = props;\n\n const regularValue =\n valueFromProps === controlledRemoteValueMarker ? undefined : valueFromProps;\n\n /*\n * Only `undefined` falls back, because only `undefined` reads as\n * uncontrolled: a caller-supplied `null` controls a `DateRangePicker` with no\n * range selected, so `??` would swallow it. The marker cannot appear on the\n * first render, so `regularValue` is the caller's own value here.\n */\n const [value, setValue] = useState(\n regularValue !== undefined\n ? regularValue\n : defaultValue !== undefined\n ? defaultValue\n : emptyValue,\n );\n\n useLayoutEffect(() => {\n if (regularValue !== undefined) {\n setValue(regularValue);\n }\n }, [
|
|
1
|
+
{"version":3,"file":"useControlledHostValueProps.mjs","names":[],"sources":["../../../../../../../src/lib/remote/useControlledHostValueProps.ts"],"sourcesContent":["import { useLayoutEffect, useState } from \"react\";\nimport { controlledRemoteValueMarker } from \"./useControlledRemoteValueProps\";\nimport type { FieldProps } from \"@/lib/remote/types\";\n\n/**\n * Returns props with controlled value handling for remote components. It works\n * by omitting values resulting from a remotely executed event handler. These\n * values are marked by the `controlledRemoteValueMarker`.\n *\n * This hook is only necessary for text inputs. If not used the controlled input\n * value may be corrupted by interleaved host inputs and remote events.\n *\n * @param emptyValue What the field reports while nothing has been entered —\n * `\"\"` for a text input, `NaN` for a number, `null` for a date range. It is\n * the sentinel that keeps the field controlled from the first render; see\n * that convention in the package's AGENTS.md.\n */\nexport const useControlledHostValueProps = <T, P>(\n props: FieldProps<T, P>,\n emptyValue: T,\n) => {\n const {\n value: valueFromProps,\n onChange: onChangeFromProps,\n defaultValue,\n } = props;\n\n const regularValue =\n valueFromProps === controlledRemoteValueMarker ? undefined : valueFromProps;\n\n /*\n * Only `undefined` falls back, because only `undefined` reads as\n * uncontrolled: a caller-supplied `null` controls a `DateRangePicker` with no\n * range selected, so `??` would swallow it. The marker cannot appear on the\n * first render, so `regularValue` is the caller's own value here.\n */\n const [value, setValue] = useState(\n regularValue !== undefined\n ? regularValue\n : defaultValue !== undefined\n ? defaultValue\n : emptyValue,\n );\n\n useLayoutEffect(() => {\n if (regularValue !== undefined) {\n setValue(regularValue);\n }\n }, [regularValue]);\n\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n const onChange = (v: any) => {\n setValue(v);\n onChangeFromProps?.(v);\n };\n\n return {\n ...props,\n value,\n onChange,\n };\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;AAiBA,IAAa,+BACX,OACA,eACG;CACH,MAAM,EACJ,OAAO,gBACP,UAAU,mBACV,iBACE;CAEJ,MAAM,eACJ,mBAAA,oCAAiD,KAAA,IAAY;CAQ/D,MAAM,CAAC,OAAO,YAAY,SACxB,iBAAiB,KAAA,IACb,eACA,iBAAiB,KAAA,IACf,eACA,UACR;CAEA,sBAAsB;EACpB,IAAI,iBAAiB,KAAA,GACnB,SAAS,YAAY;CAEzB,GAAG,CAAC,YAAY,CAAC;CAGjB,MAAM,YAAY,MAAW;EAC3B,SAAS,CAAC;EACV,oBAAoB,CAAC;CACvB;CAEA,OAAO;EACL,GAAG;EACH;EACA;CACF;AACF"}
|