@contember/react-utils 1.2.7 → 1.3.0-alpha.11
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/development/context/createNonNullableContextFactory.cjs +17 -0
- package/dist/development/context/createNonNullableContextFactory.cjs.map +1 -0
- package/dist/development/context/createNonNullableContextFactory.js.map +1 -1
- package/dist/development/context/createOptionalContextFactory.cjs +13 -0
- package/dist/development/context/createOptionalContextFactory.cjs.map +1 -0
- package/dist/development/debug-context/Constants.cjs +25 -0
- package/dist/development/debug-context/Constants.cjs.map +1 -0
- package/dist/development/debug-context/Context.cjs +72 -0
- package/dist/development/debug-context/Context.cjs.map +1 -0
- package/dist/development/debug-context/Context.js +4 -3
- package/dist/development/debug-context/Context.js.map +1 -1
- package/dist/development/hooks/unwrapRefValue.cjs +11 -0
- package/dist/development/hooks/unwrapRefValue.cjs.map +1 -0
- package/dist/development/hooks/useAbortController.cjs +17 -0
- package/dist/development/hooks/useAbortController.cjs.map +1 -0
- package/dist/development/hooks/useAddClassNameDuringResize.cjs +32 -0
- package/dist/development/hooks/useAddClassNameDuringResize.cjs.map +1 -0
- package/dist/development/hooks/useArrayMapMemo.cjs +11 -0
- package/dist/development/hooks/useArrayMapMemo.cjs.map +1 -0
- package/dist/development/hooks/useAutoHeightTextArea.cjs +41 -0
- package/dist/development/hooks/useAutoHeightTextArea.cjs.map +1 -0
- package/dist/development/hooks/useChildrenAsLabel.cjs +53 -0
- package/dist/development/hooks/useChildrenAsLabel.cjs.map +1 -0
- package/dist/development/hooks/useCloseOnClickOutside.cjs +25 -0
- package/dist/development/hooks/useCloseOnClickOutside.cjs.map +1 -0
- package/dist/development/hooks/useCloseOnClickOutside.js +25 -0
- package/dist/development/hooks/useCloseOnClickOutside.js.map +1 -0
- package/dist/development/hooks/useCloseOnEscape.cjs +20 -0
- package/dist/development/hooks/useCloseOnEscape.cjs.map +1 -0
- package/dist/development/hooks/useCloseOnEscape.js +20 -0
- package/dist/development/hooks/useCloseOnEscape.js.map +1 -0
- package/dist/development/hooks/useComposeRef.cjs +31 -0
- package/dist/development/hooks/useComposeRef.cjs.map +1 -0
- package/dist/development/hooks/useConstantLengthInvariant.cjs +15 -0
- package/dist/development/hooks/useConstantLengthInvariant.cjs.map +1 -0
- package/dist/development/hooks/useConstantLengthInvariant.js.map +1 -1
- package/dist/development/hooks/useConstantValueInvariant.cjs +15 -0
- package/dist/development/hooks/useConstantValueInvariant.cjs.map +1 -0
- package/dist/development/hooks/useConstantValueInvariant.js.map +1 -1
- package/dist/development/hooks/useContainerWidth.cjs +14 -0
- package/dist/development/hooks/useContainerWidth.cjs.map +1 -0
- package/dist/development/hooks/useDebounce.cjs +15 -0
- package/dist/development/hooks/useDebounce.cjs.map +1 -0
- package/dist/development/hooks/useDebounceCallback.cjs +19 -0
- package/dist/development/hooks/useDebounceCallback.cjs.map +1 -0
- package/dist/development/hooks/useDocumentTitle.cjs +22 -0
- package/dist/development/hooks/useDocumentTitle.cjs.map +1 -0
- package/dist/development/hooks/useElementSize.cjs +37 -0
- package/dist/development/hooks/useElementSize.cjs.map +1 -0
- package/dist/development/hooks/useElementTopOffset.cjs +29 -0
- package/dist/development/hooks/useElementTopOffset.cjs.map +1 -0
- package/dist/development/hooks/useEventHandler.cjs +19 -0
- package/dist/development/hooks/useEventHandler.cjs.map +1 -0
- package/dist/development/hooks/useExpectSameValueReference.cjs +24 -0
- package/dist/development/hooks/useExpectSameValueReference.cjs.map +1 -0
- package/dist/development/hooks/useForceRender.cjs +9 -0
- package/dist/development/hooks/useForceRender.cjs.map +1 -0
- package/dist/development/hooks/useId.cjs +13 -0
- package/dist/development/hooks/useId.cjs.map +1 -0
- package/dist/development/hooks/useId.js.map +1 -1
- package/dist/development/hooks/useIsMounted.cjs +18 -0
- package/dist/development/hooks/useIsMounted.cjs.map +1 -0
- package/dist/development/hooks/useObjectMemo.cjs +27 -0
- package/dist/development/hooks/useObjectMemo.cjs.map +1 -0
- package/dist/development/hooks/useOnElementClickOutsideCallback.cjs +20 -0
- package/dist/development/hooks/useOnElementClickOutsideCallback.cjs.map +1 -0
- package/dist/development/hooks/useOnElementMouseEnterDelayedCallback.cjs +33 -0
- package/dist/development/hooks/useOnElementMouseEnterDelayedCallback.cjs.map +1 -0
- package/dist/development/hooks/useOnElementMutation.cjs +35 -0
- package/dist/development/hooks/useOnElementMutation.cjs.map +1 -0
- package/dist/development/hooks/useOnElementResize.cjs +42 -0
- package/dist/development/hooks/useOnElementResize.cjs.map +1 -0
- package/dist/development/hooks/useOnScrollWithin.cjs +52 -0
- package/dist/development/hooks/useOnScrollWithin.cjs.map +1 -0
- package/dist/development/hooks/useOnWindowResize.cjs +36 -0
- package/dist/development/hooks/useOnWindowResize.cjs.map +1 -0
- package/dist/development/hooks/usePreviousValue.cjs +12 -0
- package/dist/development/hooks/usePreviousValue.cjs.map +1 -0
- package/dist/development/hooks/useScrollOffsets.cjs +67 -0
- package/dist/development/hooks/useScrollOffsets.cjs.map +1 -0
- package/dist/development/hooks/useStoredState.cjs +23 -0
- package/dist/development/hooks/useStoredState.cjs.map +1 -0
- package/dist/development/hooks/useUpdatedRef.cjs +10 -0
- package/dist/development/hooks/useUpdatedRef.cjs.map +1 -0
- package/dist/development/hooks/useWindowSize.cjs +20 -0
- package/dist/development/hooks/useWindowSize.cjs.map +1 -0
- package/dist/development/index.cjs +116 -0
- package/dist/development/index.cjs.map +1 -0
- package/dist/development/index.js +4 -0
- package/dist/development/index.js.map +1 -1
- package/dist/development/referentiallyStable/emptyArray.cjs +5 -0
- package/dist/development/referentiallyStable/emptyArray.cjs.map +1 -0
- package/dist/development/referentiallyStable/emptyObject.cjs +5 -0
- package/dist/development/referentiallyStable/emptyObject.cjs.map +1 -0
- package/dist/development/referentiallyStable/identityFunction.cjs +5 -0
- package/dist/development/referentiallyStable/identityFunction.cjs.map +1 -0
- package/dist/development/referentiallyStable/noop.cjs +5 -0
- package/dist/development/referentiallyStable/noop.cjs.map +1 -0
- package/dist/development/referentiallyStable/returnFalse.cjs +5 -0
- package/dist/development/referentiallyStable/returnFalse.cjs.map +1 -0
- package/dist/development/referentiallyStable/returnTrue.cjs +5 -0
- package/dist/development/referentiallyStable/returnTrue.cjs.map +1 -0
- package/dist/development/referentiallyStable/useReferentiallyStableCallback.cjs +12 -0
- package/dist/development/referentiallyStable/useReferentiallyStableCallback.cjs.map +1 -0
- package/dist/development/theming/ColorSchemeProvider.cjs +16 -0
- package/dist/development/theming/ColorSchemeProvider.cjs.map +1 -0
- package/dist/development/theming/ColorSchemeProvider.js +8 -10
- package/dist/development/theming/ColorSchemeProvider.js.map +1 -1
- package/dist/development/theming/GlobalClassNamePrefixContext.cjs +6 -0
- package/dist/development/theming/GlobalClassNamePrefixContext.cjs.map +1 -0
- package/dist/development/theming/contexts.cjs +12 -0
- package/dist/development/theming/contexts.cjs.map +1 -0
- package/dist/development/theming/useClassName.cjs +17 -0
- package/dist/development/theming/useClassName.cjs.map +1 -0
- package/dist/development/theming/useClassName.js.map +1 -1
- package/dist/development/theming/useClassNameFactory.cjs +22 -0
- package/dist/development/theming/useClassNameFactory.cjs.map +1 -0
- package/dist/development/theming/useClassNameFactory.js.map +1 -1
- package/dist/development/theming/useThemedClassName.cjs +17 -0
- package/dist/development/theming/useThemedClassName.cjs.map +1 -0
- package/dist/development/theming/useThemedClassNameFactory.cjs +29 -0
- package/dist/development/theming/useThemedClassNameFactory.cjs.map +1 -0
- package/dist/development/theming/useThemedClassNameFactory.js.map +1 -1
- package/dist/production/context/createNonNullableContextFactory.cjs +17 -0
- package/dist/production/context/createNonNullableContextFactory.cjs.map +1 -0
- package/dist/production/context/createNonNullableContextFactory.js.map +1 -1
- package/dist/production/context/createOptionalContextFactory.cjs +13 -0
- package/dist/production/context/createOptionalContextFactory.cjs.map +1 -0
- package/dist/production/debug-context/Constants.cjs +25 -0
- package/dist/production/debug-context/Constants.cjs.map +1 -0
- package/dist/production/debug-context/Context.cjs +68 -0
- package/dist/production/debug-context/Context.cjs.map +1 -0
- package/dist/production/debug-context/Context.js +3 -2
- package/dist/production/debug-context/Context.js.map +1 -1
- package/dist/production/hooks/unwrapRefValue.cjs +11 -0
- package/dist/production/hooks/unwrapRefValue.cjs.map +1 -0
- package/dist/production/hooks/useAbortController.cjs +17 -0
- package/dist/production/hooks/useAbortController.cjs.map +1 -0
- package/dist/production/hooks/useAddClassNameDuringResize.cjs +32 -0
- package/dist/production/hooks/useAddClassNameDuringResize.cjs.map +1 -0
- package/dist/production/hooks/useArrayMapMemo.cjs +9 -0
- package/dist/production/hooks/useArrayMapMemo.cjs.map +1 -0
- package/dist/production/hooks/useAutoHeightTextArea.cjs +41 -0
- package/dist/production/hooks/useAutoHeightTextArea.cjs.map +1 -0
- package/dist/production/hooks/useChildrenAsLabel.cjs +52 -0
- package/dist/production/hooks/useChildrenAsLabel.cjs.map +1 -0
- package/dist/production/hooks/useChildrenAsLabel.js.map +1 -1
- package/dist/production/hooks/useCloseOnClickOutside.cjs +25 -0
- package/dist/production/hooks/useCloseOnClickOutside.cjs.map +1 -0
- package/dist/production/hooks/useCloseOnClickOutside.js +25 -0
- package/dist/production/hooks/useCloseOnClickOutside.js.map +1 -0
- package/dist/production/hooks/useCloseOnEscape.cjs +20 -0
- package/dist/production/hooks/useCloseOnEscape.cjs.map +1 -0
- package/dist/production/hooks/useCloseOnEscape.js +20 -0
- package/dist/production/hooks/useCloseOnEscape.js.map +1 -0
- package/dist/production/hooks/useComposeRef.cjs +31 -0
- package/dist/production/hooks/useComposeRef.cjs.map +1 -0
- package/dist/production/hooks/useConstantLengthInvariant.cjs +6 -0
- package/dist/production/hooks/useConstantLengthInvariant.cjs.map +1 -0
- package/dist/production/hooks/useConstantValueInvariant.cjs +6 -0
- package/dist/production/hooks/useConstantValueInvariant.cjs.map +1 -0
- package/dist/production/hooks/useContainerWidth.cjs +14 -0
- package/dist/production/hooks/useContainerWidth.cjs.map +1 -0
- package/dist/production/hooks/useDebounce.cjs +15 -0
- package/dist/production/hooks/useDebounce.cjs.map +1 -0
- package/dist/production/hooks/useDebounceCallback.cjs +19 -0
- package/dist/production/hooks/useDebounceCallback.cjs.map +1 -0
- package/dist/production/hooks/useDocumentTitle.cjs +22 -0
- package/dist/production/hooks/useDocumentTitle.cjs.map +1 -0
- package/dist/production/hooks/useElementSize.cjs +37 -0
- package/dist/production/hooks/useElementSize.cjs.map +1 -0
- package/dist/production/hooks/useElementTopOffset.cjs +29 -0
- package/dist/production/hooks/useElementTopOffset.cjs.map +1 -0
- package/dist/production/hooks/useEventHandler.cjs +19 -0
- package/dist/production/hooks/useEventHandler.cjs.map +1 -0
- package/dist/production/hooks/useExpectSameValueReference.cjs +15 -0
- package/dist/production/hooks/useExpectSameValueReference.cjs.map +1 -0
- package/dist/production/hooks/useForceRender.cjs +9 -0
- package/dist/production/hooks/useForceRender.cjs.map +1 -0
- package/dist/production/hooks/useId.cjs +13 -0
- package/dist/production/hooks/useId.cjs.map +1 -0
- package/dist/production/hooks/useId.js.map +1 -1
- package/dist/production/hooks/useIsMounted.cjs +18 -0
- package/dist/production/hooks/useIsMounted.cjs.map +1 -0
- package/dist/production/hooks/useObjectMemo.cjs +27 -0
- package/dist/production/hooks/useObjectMemo.cjs.map +1 -0
- package/dist/production/hooks/useOnElementClickOutsideCallback.cjs +20 -0
- package/dist/production/hooks/useOnElementClickOutsideCallback.cjs.map +1 -0
- package/dist/production/hooks/useOnElementMouseEnterDelayedCallback.cjs +33 -0
- package/dist/production/hooks/useOnElementMouseEnterDelayedCallback.cjs.map +1 -0
- package/dist/production/hooks/useOnElementMutation.cjs +35 -0
- package/dist/production/hooks/useOnElementMutation.cjs.map +1 -0
- package/dist/production/hooks/useOnElementResize.cjs +42 -0
- package/dist/production/hooks/useOnElementResize.cjs.map +1 -0
- package/dist/production/hooks/useOnScrollWithin.cjs +52 -0
- package/dist/production/hooks/useOnScrollWithin.cjs.map +1 -0
- package/dist/production/hooks/useOnWindowResize.cjs +36 -0
- package/dist/production/hooks/useOnWindowResize.cjs.map +1 -0
- package/dist/production/hooks/usePreviousValue.cjs +12 -0
- package/dist/production/hooks/usePreviousValue.cjs.map +1 -0
- package/dist/production/hooks/useScrollOffsets.cjs +67 -0
- package/dist/production/hooks/useScrollOffsets.cjs.map +1 -0
- package/dist/production/hooks/useStoredState.cjs +23 -0
- package/dist/production/hooks/useStoredState.cjs.map +1 -0
- package/dist/production/hooks/useUpdatedRef.cjs +10 -0
- package/dist/production/hooks/useUpdatedRef.cjs.map +1 -0
- package/dist/production/hooks/useWindowSize.cjs +20 -0
- package/dist/production/hooks/useWindowSize.cjs.map +1 -0
- package/dist/production/index.cjs +116 -0
- package/dist/production/index.cjs.map +1 -0
- package/dist/production/index.js +4 -0
- package/dist/production/index.js.map +1 -1
- package/dist/production/referentiallyStable/emptyArray.cjs +5 -0
- package/dist/production/referentiallyStable/emptyArray.cjs.map +1 -0
- package/dist/production/referentiallyStable/emptyObject.cjs +5 -0
- package/dist/production/referentiallyStable/emptyObject.cjs.map +1 -0
- package/dist/production/referentiallyStable/identityFunction.cjs +5 -0
- package/dist/production/referentiallyStable/identityFunction.cjs.map +1 -0
- package/dist/production/referentiallyStable/noop.cjs +5 -0
- package/dist/production/referentiallyStable/noop.cjs.map +1 -0
- package/dist/production/referentiallyStable/returnFalse.cjs +5 -0
- package/dist/production/referentiallyStable/returnFalse.cjs.map +1 -0
- package/dist/production/referentiallyStable/returnTrue.cjs +5 -0
- package/dist/production/referentiallyStable/returnTrue.cjs.map +1 -0
- package/dist/production/referentiallyStable/useReferentiallyStableCallback.cjs +12 -0
- package/dist/production/referentiallyStable/useReferentiallyStableCallback.cjs.map +1 -0
- package/dist/production/theming/ColorSchemeProvider.cjs +12 -0
- package/dist/production/theming/ColorSchemeProvider.cjs.map +1 -0
- package/dist/production/theming/ColorSchemeProvider.js +4 -6
- package/dist/production/theming/ColorSchemeProvider.js.map +1 -1
- package/dist/production/theming/GlobalClassNamePrefixContext.cjs +6 -0
- package/dist/production/theming/GlobalClassNamePrefixContext.cjs.map +1 -0
- package/dist/production/theming/contexts.cjs +12 -0
- package/dist/production/theming/contexts.cjs.map +1 -0
- package/dist/production/theming/useClassName.cjs +17 -0
- package/dist/production/theming/useClassName.cjs.map +1 -0
- package/dist/production/theming/useClassName.js.map +1 -1
- package/dist/production/theming/useClassNameFactory.cjs +22 -0
- package/dist/production/theming/useClassNameFactory.cjs.map +1 -0
- package/dist/production/theming/useClassNameFactory.js.map +1 -1
- package/dist/production/theming/useThemedClassName.cjs +17 -0
- package/dist/production/theming/useThemedClassName.cjs.map +1 -0
- package/dist/production/theming/useThemedClassNameFactory.cjs +29 -0
- package/dist/production/theming/useThemedClassNameFactory.cjs.map +1 -0
- package/dist/production/theming/useThemedClassNameFactory.js.map +1 -1
- package/dist/types/debug-context/Context.d.ts.map +1 -1
- package/dist/types/hooks/index.d.ts +2 -0
- package/dist/types/hooks/index.d.ts.map +1 -1
- package/dist/types/hooks/useCloseOnClickOutside.d.ts +7 -0
- package/dist/types/hooks/useCloseOnClickOutside.d.ts.map +1 -0
- package/dist/types/hooks/useCloseOnEscape.d.ts +5 -0
- package/dist/types/hooks/useCloseOnEscape.d.ts.map +1 -0
- package/dist/types/theming/ColorSchemeProvider.d.ts +3 -4
- package/dist/types/theming/ColorSchemeProvider.d.ts.map +1 -1
- package/dist/types/tsconfig.tsbuildinfo +1 -1
- package/package.json +10 -3
- package/src/debug-context/Context.tsx +3 -3
- package/src/hooks/index.ts +2 -0
- package/src/hooks/useCloseOnClickOutside.ts +27 -0
- package/src/hooks/useCloseOnEscape.ts +18 -0
- package/src/theming/ColorSchemeProvider.tsx +8 -11
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useClassNameFactory.js","sources":["../../../src/theming/useClassNameFactory.ts"],"sourcesContent":["import { NestedClassName, deduplicateClassName, flatClassNameList } from '@contember/utilities'\nimport { useContext } from 'react'\nimport { useReferentiallyStableCallback } from '../referentiallyStable'\nimport { GlobalClassNamePrefixContext } from './GlobalClassNamePrefixContext'\n\n/**\n * Hook for component class name accepting outer class name\n *\n * Returns a reusable function almost that is handy for components\n * with many sub-component parts that should inherit the root component\n * name.\n *\n * Also, product of the factory is a function that can be used outside of rules of hooks.\n *\n * @param componentClassName - Component class name\n * @param glue - String to use to glue component and sub-component suffix\n * @param prefixOverride - Context component prefix override\n * @returns\n */\nexport function useClassNameFactory(\n\tcomponentClassName: NestedClassName,\n\tglue: string | null = '-',\n\tprefixOverride?: string | null | undefined,\n) {\n\tconst contextPrefix = useContext(GlobalClassNamePrefixContext)\n\tconst classNamePrefix: string = prefixOverride === null || prefixOverride === '' ? '' : prefixOverride || contextPrefix\n\n\tconst componentClassNameList: string[] = flatClassNameList(componentClassName).map(\n\t\tcomponentClassName => `${classNamePrefix}${componentClassName}`,\n\t)\n\n\tfunction componentClassNameFor(\n\t\tsuffix: string | null | undefined = null,\n\t\tadditionalClassName: NestedClassName = null,\n\t): string {\n\t\tconst classNameSuffix: string = suffix ?? ''\n\n\t\treturn deduplicateClassName((classNameSuffix\n\t\t\t? (classNameSuffix.match(/^[a-zA-Z0-9]/)\n\t\t\t\t? componentClassNameList.map(componentClassName => `${componentClassName}${glue}${classNameSuffix}`)\n\t\t\t\t: componentClassNameList.map(componentClassName => `${componentClassName}${classNameSuffix}`)\n\t\t\t)\n\t\t\t: componentClassNameList\n\t\t).concat(\n\t\t\tflatClassNameList(additionalClassName),\n\t\t)).join(' ')\n\t}\n\n\treturn useReferentiallyStableCallback(componentClassNameFor)\n}\n"],"names":["componentClassName"],"mappings":";;;;AAmBO,SAAS,oBACf,oBACA,OAAsB,KACtB,gBACC;AACK,QAAA,gBAAgB,WAAW,4BAA4B;AAC7D,QAAM,kBAA0B,mBAAmB,QAAQ,mBAAmB,KAAK,KAAK,kBAAkB;AAEpG,QAAA,yBAAmC,kBAAkB,kBAAkB,EAAE;AAAA,IAC9E,CAAAA,wBAAsB,GAAG,
|
|
1
|
+
{"version":3,"file":"useClassNameFactory.js","sources":["../../../src/theming/useClassNameFactory.ts"],"sourcesContent":["import { NestedClassName, deduplicateClassName, flatClassNameList } from '@contember/utilities'\nimport { useContext } from 'react'\nimport { useReferentiallyStableCallback } from '../referentiallyStable'\nimport { GlobalClassNamePrefixContext } from './GlobalClassNamePrefixContext'\n\n/**\n * Hook for component class name accepting outer class name\n *\n * Returns a reusable function almost that is handy for components\n * with many sub-component parts that should inherit the root component\n * name.\n *\n * Also, product of the factory is a function that can be used outside of rules of hooks.\n *\n * @param componentClassName - Component class name\n * @param glue - String to use to glue component and sub-component suffix\n * @param prefixOverride - Context component prefix override\n * @returns\n */\nexport function useClassNameFactory(\n\tcomponentClassName: NestedClassName,\n\tglue: string | null = '-',\n\tprefixOverride?: string | null | undefined,\n) {\n\tconst contextPrefix = useContext(GlobalClassNamePrefixContext)\n\tconst classNamePrefix: string = prefixOverride === null || prefixOverride === '' ? '' : prefixOverride || contextPrefix\n\n\tconst componentClassNameList: string[] = flatClassNameList(componentClassName).map(\n\t\tcomponentClassName => `${classNamePrefix}${componentClassName}`,\n\t)\n\n\tfunction componentClassNameFor(\n\t\tsuffix: string | null | undefined = null,\n\t\tadditionalClassName: NestedClassName = null,\n\t): string {\n\t\tconst classNameSuffix: string = suffix ?? ''\n\n\t\treturn deduplicateClassName((classNameSuffix\n\t\t\t? (classNameSuffix.match(/^[a-zA-Z0-9]/)\n\t\t\t\t? componentClassNameList.map(componentClassName => `${componentClassName}${glue}${classNameSuffix}`)\n\t\t\t\t: componentClassNameList.map(componentClassName => `${componentClassName}${classNameSuffix}`)\n\t\t\t)\n\t\t\t: componentClassNameList\n\t\t).concat(\n\t\t\tflatClassNameList(additionalClassName),\n\t\t)).join(' ')\n\t}\n\n\treturn useReferentiallyStableCallback(componentClassNameFor)\n}\n"],"names":["componentClassName"],"mappings":";;;;AAmBO,SAAS,oBACf,oBACA,OAAsB,KACtB,gBACC;AACK,QAAA,gBAAgB,WAAW,4BAA4B;AAC7D,QAAM,kBAA0B,mBAAmB,QAAQ,mBAAmB,KAAK,KAAK,kBAAkB;AAEpG,QAAA,yBAAmC,kBAAkB,kBAAkB,EAAE;AAAA,IAC9E,CAAAA,wBAAsB,GAAG,eAAe,GAAGA,mBAAkB;AAAA,EAAA;AAG9D,WAAS,sBACR,SAAoC,MACpC,sBAAuC,MAC9B;AACT,UAAM,kBAA0B,UAAU;AAE1C,WAAO,sBAAsB,kBACzB,gBAAgB,MAAM,cAAc,IACpC,uBAAuB,IAAI,CAAAA,wBAAsB,GAAGA,mBAAkB,GAAG,IAAI,GAAG,eAAe,EAAE,IACjG,uBAAuB,IAAI,CAAAA,wBAAsB,GAAGA,mBAAkB,GAAG,eAAe,EAAE,IAE3F,wBACD;AAAA,MACD,kBAAkB,mBAAmB;AAAA,IAAA,CACrC,EAAE,KAAK,GAAG;AAAA,EACZ;AAEA,SAAO,+BAA+B,qBAAqB;AAC5D;"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
|
+
const utilities = require("@contember/utilities");
|
|
4
|
+
const contexts = require("./contexts.cjs");
|
|
5
|
+
const useClassName = require("./useClassName.cjs");
|
|
6
|
+
function useThemedClassName(componentClassName, additionalClassName, prefixOverride) {
|
|
7
|
+
return useClassName.useClassName(
|
|
8
|
+
componentClassName,
|
|
9
|
+
utilities.filterThemedClassName(
|
|
10
|
+
additionalClassName,
|
|
11
|
+
utilities.colorSchemeClassName(contexts.useColorScheme())
|
|
12
|
+
),
|
|
13
|
+
prefixOverride
|
|
14
|
+
);
|
|
15
|
+
}
|
|
16
|
+
exports.useThemedClassName = useThemedClassName;
|
|
17
|
+
//# sourceMappingURL=useThemedClassName.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useThemedClassName.cjs","sources":["../../../src/theming/useThemedClassName.ts"],"sourcesContent":["import { NestedClassName, colorSchemeClassName, filterThemedClassName } from '@contember/utilities'\nimport { useColorScheme } from './contexts'\nimport { useClassName } from './useClassName'\n\n/**\n * Hook for component class name accepting outer class name with theme-* and scheme-* class manes\n *\n * It looks for theme CSS classes in the given class name, deduplicates them and returns final theme class name with scheme CSS class set\n * @internal\n *\n * @param componentClassName - Component class name\n * @param additionalClassName - Additional class name\n * @param prefixOverride - Context component prefix override\n * @returns string\n * @see useColorScheme\n *\n * @example\n * ```tsx\n * function Button({ className }: { className?: string | string[] }) {\n * \t const [contentThemeClassName, controlsThemeClassName] = useThemedClassName(className)\n *\n * \t return (\n * \t\t <div className={contentThemeClassName}>\n * \t\t\t <button className={controlsThemeClassName}>Click me</button>\n * \t\t </div>\n * \t )\n * }\n *\n * function App() {\n * \t return (\n * \t\t <Button className=\"theme-default theme-danger:hover\" />\n * \t )\n * }\n *\n * // renders:\n * // <div class=\"scheme-system theme-default-content theme-danger-content:hover\">\n * // \t<button class=\"scheme-system theme-default-controls theme-danger-controls:hover\">Click me</button>\n * // </div>\n * ```\n */\nexport function useThemedClassName(\n\tcomponentClassName: NestedClassName,\n\tadditionalClassName: NestedClassName,\n\tprefixOverride?: string | null | undefined,\n): string {\n\treturn useClassName(\n\t\tcomponentClassName,\n\t\tfilterThemedClassName(\n\t\t\tadditionalClassName,\n\t\t\tcolorSchemeClassName(useColorScheme()),\n\t\t),\n\t\tprefixOverride,\n\t)\n}\n"],"names":["useClassName","filterThemedClassName","colorSchemeClassName","useColorScheme"],"mappings":";;;;;AAwCgB,SAAA,mBACf,oBACA,qBACA,gBACS;AACF,SAAAA,aAAA;AAAA,IACN;AAAA,IACAC,UAAA;AAAA,MACC;AAAA,MACAC,UAAA,qBAAqBC,yBAAgB;AAAA,IACtC;AAAA,IACA;AAAA,EAAA;AAEF;;"}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
|
+
const utilities = require("@contember/utilities");
|
|
4
|
+
const react = require("react");
|
|
5
|
+
const GlobalClassNamePrefixContext = require("./GlobalClassNamePrefixContext.cjs");
|
|
6
|
+
const contexts = require("./contexts.cjs");
|
|
7
|
+
const useReferentiallyStableCallback = require("../referentiallyStable/useReferentiallyStableCallback.cjs");
|
|
8
|
+
function useThemedClassNameFactory(componentClassName, glue = "-", prefixOverride) {
|
|
9
|
+
const contextPrefix = react.useContext(GlobalClassNamePrefixContext.GlobalClassNamePrefixContext);
|
|
10
|
+
const classNamePrefix = prefixOverride === null || prefixOverride === "" ? "" : prefixOverride || contextPrefix;
|
|
11
|
+
const componentClassNameList = utilities.flatClassNameList(componentClassName).map(
|
|
12
|
+
(componentClassName2) => `${classNamePrefix}${componentClassName2}`
|
|
13
|
+
);
|
|
14
|
+
const colorScheme = utilities.colorSchemeClassName(contexts.useColorScheme());
|
|
15
|
+
function componentClassNameFor(suffix = null, additionalClassName = null) {
|
|
16
|
+
const classNameSuffix = suffix ?? "";
|
|
17
|
+
return utilities.deduplicateClassName((classNameSuffix ? classNameSuffix.match(/^[a-zA-Z0-9]/) ? componentClassNameList.map((componentClassName2) => `${componentClassName2}${glue}${classNameSuffix}`) : componentClassNameList.map((componentClassName2) => `${componentClassName2}${classNameSuffix}`) : componentClassNameList).concat(
|
|
18
|
+
utilities.flatClassNameList(
|
|
19
|
+
utilities.filterThemedClassName(
|
|
20
|
+
additionalClassName,
|
|
21
|
+
colorScheme
|
|
22
|
+
)
|
|
23
|
+
)
|
|
24
|
+
)).join(" ");
|
|
25
|
+
}
|
|
26
|
+
return useReferentiallyStableCallback.useReferentiallyStableCallback(componentClassNameFor);
|
|
27
|
+
}
|
|
28
|
+
exports.useThemedClassNameFactory = useThemedClassNameFactory;
|
|
29
|
+
//# sourceMappingURL=useThemedClassNameFactory.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useThemedClassNameFactory.cjs","sources":["../../../src/theming/useThemedClassNameFactory.ts"],"sourcesContent":["import { NestedClassName, colorSchemeClassName, deduplicateClassName, filterThemedClassName, flatClassNameList } from '@contember/utilities'\nimport { useContext } from 'react'\nimport { useReferentiallyStableCallback } from '../referentiallyStable'\nimport { GlobalClassNamePrefixContext } from './GlobalClassNamePrefixContext'\nimport { useColorScheme } from './contexts'\n\nexport function useThemedClassNameFactory(\n\tcomponentClassName: NestedClassName,\n\tglue: string | null = '-',\n\tprefixOverride?: string | null | undefined,\n) {\n\tconst contextPrefix = useContext(GlobalClassNamePrefixContext)\n\tconst classNamePrefix: string = prefixOverride === null || prefixOverride === '' ? '' : prefixOverride || contextPrefix\n\n\tconst componentClassNameList: string[] = flatClassNameList(componentClassName).map(\n\t\tcomponentClassName => `${classNamePrefix}${componentClassName}`,\n\t)\n\n\tconst colorScheme = colorSchemeClassName(useColorScheme())\n\n\tfunction componentClassNameFor(\n\t\tsuffix: string | null | undefined = null,\n\t\tadditionalClassName: NestedClassName = null,\n\t): string {\n\t\tconst classNameSuffix: string = suffix ?? ''\n\n\t\treturn deduplicateClassName((classNameSuffix\n\t\t\t? (classNameSuffix.match(/^[a-zA-Z0-9]/)\n\t\t\t\t? componentClassNameList.map(componentClassName => `${componentClassName}${glue}${classNameSuffix}`)\n\t\t\t\t: componentClassNameList.map(componentClassName => `${componentClassName}${classNameSuffix}`)\n\t\t\t)\n\t\t\t: componentClassNameList\n\t\t).concat(\n\t\t\tflatClassNameList(\n\t\t\t\tfilterThemedClassName(\n\t\t\t\t\tadditionalClassName,\n\t\t\t\t\tcolorScheme,\n\t\t\t\t),\n\t\t\t),\n\t\t)).join(' ')\n\t}\n\n\treturn useReferentiallyStableCallback(componentClassNameFor)\n}\n"],"names":["useContext","GlobalClassNamePrefixContext","flatClassNameList","componentClassName","colorSchemeClassName","useColorScheme","deduplicateClassName","filterThemedClassName","useReferentiallyStableCallback"],"mappings":";;;;;;;AAMO,SAAS,0BACf,oBACA,OAAsB,KACtB,gBACC;AACK,QAAA,gBAAgBA,iBAAWC,6BAAAA,4BAA4B;AAC7D,QAAM,kBAA0B,mBAAmB,QAAQ,mBAAmB,KAAK,KAAK,kBAAkB;AAEpG,QAAA,yBAAmCC,UAAAA,kBAAkB,kBAAkB,EAAE;AAAA,IAC9E,CAAAC,wBAAsB,GAAG,eAAe,GAAGA,mBAAkB;AAAA,EAAA;AAGxD,QAAA,cAAcC,UAAAA,qBAAqBC,SAAA,eAAA,CAAgB;AAEzD,WAAS,sBACR,SAAoC,MACpC,sBAAuC,MAC9B;AACT,UAAM,kBAA0B,UAAU;AAE1C,WAAOC,UAAsB,sBAAA,kBACzB,gBAAgB,MAAM,cAAc,IACpC,uBAAuB,IAAI,CAAAH,wBAAsB,GAAGA,mBAAkB,GAAG,IAAI,GAAG,eAAe,EAAE,IACjG,uBAAuB,IAAI,CAAAA,wBAAsB,GAAGA,mBAAkB,GAAG,eAAe,EAAE,IAE3F,wBACD;AAAA,MACDD,UAAA;AAAA,QACCK,UAAA;AAAA,UACC;AAAA,UACA;AAAA,QACD;AAAA,MACD;AAAA,IAAA,CACA,EAAE,KAAK,GAAG;AAAA,EACZ;AAEA,SAAOC,+BAAAA,+BAA+B,qBAAqB;AAC5D;;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useThemedClassNameFactory.js","sources":["../../../src/theming/useThemedClassNameFactory.ts"],"sourcesContent":["import { NestedClassName, colorSchemeClassName, deduplicateClassName, filterThemedClassName, flatClassNameList } from '@contember/utilities'\nimport { useContext } from 'react'\nimport { useReferentiallyStableCallback } from '../referentiallyStable'\nimport { GlobalClassNamePrefixContext } from './GlobalClassNamePrefixContext'\nimport { useColorScheme } from './contexts'\n\nexport function useThemedClassNameFactory(\n\tcomponentClassName: NestedClassName,\n\tglue: string | null = '-',\n\tprefixOverride?: string | null | undefined,\n) {\n\tconst contextPrefix = useContext(GlobalClassNamePrefixContext)\n\tconst classNamePrefix: string = prefixOverride === null || prefixOverride === '' ? '' : prefixOverride || contextPrefix\n\n\tconst componentClassNameList: string[] = flatClassNameList(componentClassName).map(\n\t\tcomponentClassName => `${classNamePrefix}${componentClassName}`,\n\t)\n\n\tconst colorScheme = colorSchemeClassName(useColorScheme())\n\n\tfunction componentClassNameFor(\n\t\tsuffix: string | null | undefined = null,\n\t\tadditionalClassName: NestedClassName = null,\n\t): string {\n\t\tconst classNameSuffix: string = suffix ?? ''\n\n\t\treturn deduplicateClassName((classNameSuffix\n\t\t\t? (classNameSuffix.match(/^[a-zA-Z0-9]/)\n\t\t\t\t? componentClassNameList.map(componentClassName => `${componentClassName}${glue}${classNameSuffix}`)\n\t\t\t\t: componentClassNameList.map(componentClassName => `${componentClassName}${classNameSuffix}`)\n\t\t\t)\n\t\t\t: componentClassNameList\n\t\t).concat(\n\t\t\tflatClassNameList(\n\t\t\t\tfilterThemedClassName(\n\t\t\t\t\tadditionalClassName,\n\t\t\t\t\tcolorScheme,\n\t\t\t\t),\n\t\t\t),\n\t\t)).join(' ')\n\t}\n\n\treturn useReferentiallyStableCallback(componentClassNameFor)\n}\n"],"names":["componentClassName"],"mappings":";;;;;AAMO,SAAS,0BACf,oBACA,OAAsB,KACtB,gBACC;AACK,QAAA,gBAAgB,WAAW,4BAA4B;AAC7D,QAAM,kBAA0B,mBAAmB,QAAQ,mBAAmB,KAAK,KAAK,kBAAkB;AAEpG,QAAA,yBAAmC,kBAAkB,kBAAkB,EAAE;AAAA,IAC9E,CAAAA,wBAAsB,GAAG,
|
|
1
|
+
{"version":3,"file":"useThemedClassNameFactory.js","sources":["../../../src/theming/useThemedClassNameFactory.ts"],"sourcesContent":["import { NestedClassName, colorSchemeClassName, deduplicateClassName, filterThemedClassName, flatClassNameList } from '@contember/utilities'\nimport { useContext } from 'react'\nimport { useReferentiallyStableCallback } from '../referentiallyStable'\nimport { GlobalClassNamePrefixContext } from './GlobalClassNamePrefixContext'\nimport { useColorScheme } from './contexts'\n\nexport function useThemedClassNameFactory(\n\tcomponentClassName: NestedClassName,\n\tglue: string | null = '-',\n\tprefixOverride?: string | null | undefined,\n) {\n\tconst contextPrefix = useContext(GlobalClassNamePrefixContext)\n\tconst classNamePrefix: string = prefixOverride === null || prefixOverride === '' ? '' : prefixOverride || contextPrefix\n\n\tconst componentClassNameList: string[] = flatClassNameList(componentClassName).map(\n\t\tcomponentClassName => `${classNamePrefix}${componentClassName}`,\n\t)\n\n\tconst colorScheme = colorSchemeClassName(useColorScheme())\n\n\tfunction componentClassNameFor(\n\t\tsuffix: string | null | undefined = null,\n\t\tadditionalClassName: NestedClassName = null,\n\t): string {\n\t\tconst classNameSuffix: string = suffix ?? ''\n\n\t\treturn deduplicateClassName((classNameSuffix\n\t\t\t? (classNameSuffix.match(/^[a-zA-Z0-9]/)\n\t\t\t\t? componentClassNameList.map(componentClassName => `${componentClassName}${glue}${classNameSuffix}`)\n\t\t\t\t: componentClassNameList.map(componentClassName => `${componentClassName}${classNameSuffix}`)\n\t\t\t)\n\t\t\t: componentClassNameList\n\t\t).concat(\n\t\t\tflatClassNameList(\n\t\t\t\tfilterThemedClassName(\n\t\t\t\t\tadditionalClassName,\n\t\t\t\t\tcolorScheme,\n\t\t\t\t),\n\t\t\t),\n\t\t)).join(' ')\n\t}\n\n\treturn useReferentiallyStableCallback(componentClassNameFor)\n}\n"],"names":["componentClassName"],"mappings":";;;;;AAMO,SAAS,0BACf,oBACA,OAAsB,KACtB,gBACC;AACK,QAAA,gBAAgB,WAAW,4BAA4B;AAC7D,QAAM,kBAA0B,mBAAmB,QAAQ,mBAAmB,KAAK,KAAK,kBAAkB;AAEpG,QAAA,yBAAmC,kBAAkB,kBAAkB,EAAE;AAAA,IAC9E,CAAAA,wBAAsB,GAAG,eAAe,GAAGA,mBAAkB;AAAA,EAAA;AAGxD,QAAA,cAAc,qBAAqB,eAAA,CAAgB;AAEzD,WAAS,sBACR,SAAoC,MACpC,sBAAuC,MAC9B;AACT,UAAM,kBAA0B,UAAU;AAE1C,WAAO,sBAAsB,kBACzB,gBAAgB,MAAM,cAAc,IACpC,uBAAuB,IAAI,CAAAA,wBAAsB,GAAGA,mBAAkB,GAAG,IAAI,GAAG,eAAe,EAAE,IACjG,uBAAuB,IAAI,CAAAA,wBAAsB,GAAGA,mBAAkB,GAAG,eAAe,EAAE,IAE3F,wBACD;AAAA,MACD;AAAA,QACC;AAAA,UACC;AAAA,UACA;AAAA,QACD;AAAA,MACD;AAAA,IAAA,CACA,EAAE,KAAK,GAAG;AAAA,EACZ;AAEA,SAAO,+BAA+B,qBAAqB;AAC5D;"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
|
+
const react = require("react");
|
|
4
|
+
function createNonNullableContextFactory(displayName, initialValue) {
|
|
5
|
+
const RequiredContext = react.createContext(initialValue ?? null);
|
|
6
|
+
RequiredContext.displayName = displayName;
|
|
7
|
+
const useRequiredContext = () => {
|
|
8
|
+
const context = react.useContext(RequiredContext);
|
|
9
|
+
if (context == null) {
|
|
10
|
+
throw new Error(`use${displayName} must be used within a ${displayName} provider`);
|
|
11
|
+
}
|
|
12
|
+
return context;
|
|
13
|
+
};
|
|
14
|
+
return [RequiredContext, useRequiredContext];
|
|
15
|
+
}
|
|
16
|
+
exports.createNonNullableContextFactory = createNonNullableContextFactory;
|
|
17
|
+
//# sourceMappingURL=createNonNullableContextFactory.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"createNonNullableContextFactory.cjs","sources":["../../../src/context/createNonNullableContextFactory.ts"],"sourcesContent":["import type { Context } from 'react'\nimport { createContext, useContext } from 'react'\n\nexport function createNonNullableContextFactory<T>(displayName: string, initialValue?: T): [Context<T>, () => NonNullable<T>] {\n const RequiredContext = createContext<T>((initialValue ?? null)!)\n RequiredContext.displayName = displayName\n\n const useRequiredContext = () => {\n const context = useContext(RequiredContext)\n\n if (context == null) {\n throw new Error(`use${displayName} must be used within a ${displayName} provider`)\n }\n\n return context\n }\n\n return [RequiredContext, useRequiredContext]\n}\n"],"names":["createContext","useContext"],"mappings":";;;AAGgB,SAAA,gCAAmC,aAAqB,cAAsD;AACtH,QAAA,kBAAkBA,MAAAA,cAAkB,gBAAgB,IAAM;AAChE,kBAAgB,cAAc;AAE9B,QAAM,qBAAqB,MAAM;AACzB,UAAA,UAAUC,iBAAW,eAAe;AAE1C,QAAI,WAAW,MAAM;AACnB,YAAM,IAAI,MAAM,MAAM,WAAW,0BAA0B,WAAW,WAAW;AAAA,IACnF;AAEO,WAAA;AAAA,EAAA;AAGF,SAAA,CAAC,iBAAiB,kBAAkB;AAC7C;;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"createNonNullableContextFactory.js","sources":["../../../src/context/createNonNullableContextFactory.ts"],"sourcesContent":["import type { Context } from 'react'\nimport { createContext, useContext } from 'react'\n\nexport function createNonNullableContextFactory<T>(displayName: string, initialValue?: T): [Context<T>, () => NonNullable<T>] {\n const RequiredContext = createContext<T>((initialValue ?? null)!)\n RequiredContext.displayName = displayName\n\n const useRequiredContext = () => {\n const context = useContext(RequiredContext)\n\n if (context == null) {\n throw new Error(`use${displayName} must be used within a ${displayName} provider`)\n }\n\n return context\n }\n\n return [RequiredContext, useRequiredContext]\n}\n"],"names":[],"mappings":";AAGgB,SAAA,gCAAmC,aAAqB,cAAsD;AACtH,QAAA,kBAAkB,cAAkB,gBAAgB,IAAM;AAChE,kBAAgB,cAAc;AAE9B,QAAM,qBAAqB,MAAM;AACzB,UAAA,UAAU,WAAW,eAAe;AAE1C,QAAI,WAAW,MAAM;AACnB,YAAM,IAAI,MAAM,MAAM,
|
|
1
|
+
{"version":3,"file":"createNonNullableContextFactory.js","sources":["../../../src/context/createNonNullableContextFactory.ts"],"sourcesContent":["import type { Context } from 'react'\nimport { createContext, useContext } from 'react'\n\nexport function createNonNullableContextFactory<T>(displayName: string, initialValue?: T): [Context<T>, () => NonNullable<T>] {\n const RequiredContext = createContext<T>((initialValue ?? null)!)\n RequiredContext.displayName = displayName\n\n const useRequiredContext = () => {\n const context = useContext(RequiredContext)\n\n if (context == null) {\n throw new Error(`use${displayName} must be used within a ${displayName} provider`)\n }\n\n return context\n }\n\n return [RequiredContext, useRequiredContext]\n}\n"],"names":[],"mappings":";AAGgB,SAAA,gCAAmC,aAAqB,cAAsD;AACtH,QAAA,kBAAkB,cAAkB,gBAAgB,IAAM;AAChE,kBAAgB,cAAc;AAE9B,QAAM,qBAAqB,MAAM;AACzB,UAAA,UAAU,WAAW,eAAe;AAE1C,QAAI,WAAW,MAAM;AACnB,YAAM,IAAI,MAAM,MAAM,WAAW,0BAA0B,WAAW,WAAW;AAAA,IACnF;AAEO,WAAA;AAAA,EAAA;AAGF,SAAA,CAAC,iBAAiB,kBAAkB;AAC7C;"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
|
+
const react = require("react");
|
|
4
|
+
function createOptionalContextFactory(name, initialValue) {
|
|
5
|
+
const OptionalContext = react.createContext(initialValue);
|
|
6
|
+
OptionalContext.displayName = name;
|
|
7
|
+
const useOptionalContext = () => {
|
|
8
|
+
return react.useContext(OptionalContext) ?? initialValue;
|
|
9
|
+
};
|
|
10
|
+
return [OptionalContext, useOptionalContext];
|
|
11
|
+
}
|
|
12
|
+
exports.createOptionalContextFactory = createOptionalContextFactory;
|
|
13
|
+
//# sourceMappingURL=createOptionalContextFactory.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"createOptionalContextFactory.cjs","sources":["../../../src/context/createOptionalContextFactory.ts"],"sourcesContent":["import type { Context } from 'react'\nimport { createContext, useContext } from 'react'\n\nexport function createOptionalContextFactory<T>(name: string, initialValue: T): [Context<T>, () => T] {\n const OptionalContext = createContext<T>(initialValue)\n OptionalContext.displayName = name\n\n const useOptionalContext = () => {\n return useContext(OptionalContext) ?? initialValue\n }\n\n return [OptionalContext, useOptionalContext]\n}\n"],"names":["createContext","useContext"],"mappings":";;;AAGgB,SAAA,6BAAgC,MAAc,cAAwC;AAC9F,QAAA,kBAAkBA,oBAAiB,YAAY;AACrD,kBAAgB,cAAc;AAE9B,QAAM,qBAAqB,MAAM;AACxB,WAAAC,MAAA,WAAW,eAAe,KAAK;AAAA,EAAA;AAGjC,SAAA,CAAC,iBAAiB,kBAAkB;AAC7C;;"}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
|
+
function noopLog(...parameters) {
|
|
4
|
+
}
|
|
5
|
+
function noopLogged(message, value) {
|
|
6
|
+
return value;
|
|
7
|
+
}
|
|
8
|
+
const noopScopedConsole = Object.freeze({
|
|
9
|
+
log: noopLog,
|
|
10
|
+
logged: noopLogged,
|
|
11
|
+
warn: noopLog,
|
|
12
|
+
warned: noopLogged,
|
|
13
|
+
error: noopLog,
|
|
14
|
+
errored: noopLogged,
|
|
15
|
+
trace: noopLog,
|
|
16
|
+
traced: noopLogged
|
|
17
|
+
});
|
|
18
|
+
function isNoopScopedConsole(value) {
|
|
19
|
+
return value === noopScopedConsole;
|
|
20
|
+
}
|
|
21
|
+
exports.isNoopScopedConsole = isNoopScopedConsole;
|
|
22
|
+
exports.noopLog = noopLog;
|
|
23
|
+
exports.noopLogged = noopLogged;
|
|
24
|
+
exports.noopScopedConsole = noopScopedConsole;
|
|
25
|
+
//# sourceMappingURL=Constants.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Constants.cjs","sources":["../../../src/debug-context/Constants.ts"],"sourcesContent":["import type { ScopedConsoleContextType } from './Types'\n\nexport function noopLog(...parameters: any[]) { }\n\nexport function noopLogged<T>(message: string, value: T): T {\n\treturn value\n}\n\nexport const noopScopedConsole: ScopedConsoleContextType = Object.freeze({\n\tlog: noopLog,\n\tlogged: noopLogged,\n\twarn: noopLog,\n\twarned: noopLogged,\n\terror: noopLog,\n\terrored: noopLogged,\n\ttrace: noopLog,\n\ttraced: noopLogged,\n})\n\nexport function isNoopScopedConsole(value: unknown): boolean {\n\treturn value === noopScopedConsole\n}\n"],"names":[],"mappings":";;AAEO,SAAS,WAAW,YAAmB;AAAE;AAEhC,SAAA,WAAc,SAAiB,OAAa;AACpD,SAAA;AACR;AAEa,MAAA,oBAA8C,OAAO,OAAO;AAAA,EACxE,KAAK;AAAA,EACL,QAAQ;AAAA,EACR,MAAM;AAAA,EACN,QAAQ;AAAA,EACR,OAAO;AAAA,EACP,SAAS;AAAA,EACT,OAAO;AAAA,EACP,QAAQ;AACT,CAAC;AAEM,SAAS,oBAAoB,OAAyB;AAC5D,SAAO,UAAU;AAClB;;;;;"}
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
|
+
const jsxRuntime = require("react/jsx-runtime");
|
|
4
|
+
const react = require("react");
|
|
5
|
+
const Constants = require("./Constants.cjs");
|
|
6
|
+
function createPrefixedConsole(message, prefixedConsole) {
|
|
7
|
+
return {
|
|
8
|
+
error: function error(...parameters) {
|
|
9
|
+
(prefixedConsole ?? console).error(message, ...parameters);
|
|
10
|
+
},
|
|
11
|
+
errored: function errored(message2, value) {
|
|
12
|
+
(prefixedConsole ?? console).error(message2, value);
|
|
13
|
+
return value;
|
|
14
|
+
},
|
|
15
|
+
log: function log(...parameters) {
|
|
16
|
+
(prefixedConsole ?? console).log(message, ...parameters);
|
|
17
|
+
},
|
|
18
|
+
logged: function logged(message2, value) {
|
|
19
|
+
(prefixedConsole ?? console).log(message2, value);
|
|
20
|
+
return value;
|
|
21
|
+
},
|
|
22
|
+
trace: function trace(...parameters) {
|
|
23
|
+
(prefixedConsole ?? console).trace(message, ...parameters);
|
|
24
|
+
},
|
|
25
|
+
traced: function traced(message2, value) {
|
|
26
|
+
(prefixedConsole ?? console).trace(message2, value);
|
|
27
|
+
return value;
|
|
28
|
+
},
|
|
29
|
+
warn: function warn(...parameters) {
|
|
30
|
+
(prefixedConsole ?? console).warn(message, ...parameters);
|
|
31
|
+
},
|
|
32
|
+
warned: function warned(message2, value) {
|
|
33
|
+
(prefixedConsole ?? console).warn(message2, value);
|
|
34
|
+
return value;
|
|
35
|
+
}
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
const ScopedConsoleContext = react.createContext(null);
|
|
39
|
+
ScopedConsoleContext.displayName = "ScopedConsoleContext";
|
|
40
|
+
function parentScopedConsoleOrNone(parentConsole) {
|
|
41
|
+
return Constants.isNoopScopedConsole(parentConsole) ? void 0 : parentConsole;
|
|
42
|
+
}
|
|
43
|
+
const useScopedConsoleRef = (prefix, override) => {
|
|
44
|
+
if (prefix.length === 0) {
|
|
45
|
+
throw new Error("Prefix must be non-empty string");
|
|
46
|
+
}
|
|
47
|
+
const parentConsole = parentScopedConsoleOrNone(react.useContext(ScopedConsoleContext));
|
|
48
|
+
const scopedConsole = react.useMemo(() => {
|
|
49
|
+
if (override !== false && (parentConsole || override)) {
|
|
50
|
+
return createPrefixedConsole(prefix, parentConsole);
|
|
51
|
+
} else {
|
|
52
|
+
return Constants.noopScopedConsole;
|
|
53
|
+
}
|
|
54
|
+
}, [override, parentConsole, prefix]);
|
|
55
|
+
const ref = react.useRef(scopedConsole);
|
|
56
|
+
ref.current = scopedConsole;
|
|
57
|
+
return ref;
|
|
58
|
+
};
|
|
59
|
+
const DebugChildren = react.memo(({ active = true, children, id }) => {
|
|
60
|
+
const parentScopedConsole = parentScopedConsoleOrNone(react.useContext(ScopedConsoleContext));
|
|
61
|
+
const console2 = active && id ? createPrefixedConsole(id, parentScopedConsole) : Constants.noopScopedConsole;
|
|
62
|
+
return /* @__PURE__ */ jsxRuntime.jsx(ScopedConsoleContext.Provider, { value: active ? console2 : Constants.noopScopedConsole, children });
|
|
63
|
+
});
|
|
64
|
+
DebugChildren.displayName = "DebugChildren";
|
|
65
|
+
exports.DebugChildren = DebugChildren;
|
|
66
|
+
exports.ScopedConsoleContext = ScopedConsoleContext;
|
|
67
|
+
exports.useScopedConsoleRef = useScopedConsoleRef;
|
|
68
|
+
//# sourceMappingURL=Context.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Context.cjs","sources":["../../../src/debug-context/Context.tsx"],"sourcesContent":["import { ReactNode, createContext, memo, useContext, useMemo, useRef } from 'react'\nimport { isNoopScopedConsole, noopScopedConsole } from './Constants'\nimport { ScopedConsoleContextType } from './Types'\n\nfunction createPrefixedConsole(message: string, prefixedConsole?: ScopedConsoleContextType): ScopedConsoleContextType {\n\treturn {\n\t\terror: function error(...parameters: any[]) {\n\t\t\t(prefixedConsole ?? console).error(message, ...parameters)\n\t\t},\n\t\terrored: function errored<T>(message: string, value: T): T {\n\t\t\t(prefixedConsole ?? console).error(message, value)\n\t\t\treturn value\n\t\t},\n\t\tlog: function log(...parameters: any[]) {\n\t\t\t(prefixedConsole ?? console).log(message, ...parameters)\n\t\t},\n\t\tlogged: function logged<T>(message: string, value: T): T {\n\t\t\t(prefixedConsole ?? console).log(message, value)\n\t\t\treturn value\n\t\t},\n\t\ttrace: function trace(...parameters: any[]) {\n\t\t\t(prefixedConsole ?? console).trace(message, ...parameters)\n\t\t},\n\t\ttraced: function traced<T>(message: string, value: T): T {\n\t\t\t(prefixedConsole ?? console).trace(message, value)\n\t\t\treturn value\n\t\t},\n\t\twarn: function warn(...parameters: any[]) {\n\t\t\t(prefixedConsole ?? console).warn(message, ...parameters)\n\t\t},\n\t\twarned: function warned<T>(message: string, value: T): T {\n\t\t\t(prefixedConsole ?? console).warn(message, value)\n\t\t\treturn value\n\t\t},\n\t}\n}\n\nexport const ScopedConsoleContext = createContext<ScopedConsoleContextType>(null!)\nScopedConsoleContext.displayName = 'ScopedConsoleContext'\n\nfunction parentScopedConsoleOrNone(parentConsole: ScopedConsoleContextType): ScopedConsoleContextType | undefined {\n\treturn isNoopScopedConsole(parentConsole) ? undefined : parentConsole\n}\n\nexport const useScopedConsoleRef = (prefix: string, override?: boolean) => {\n\tif (prefix.length === 0) {\n\t\tthrow new Error('Prefix must be non-empty string')\n\t}\n\tconst parentConsole = parentScopedConsoleOrNone(useContext(ScopedConsoleContext))\n\n\tconst scopedConsole = useMemo(() => {\n\t\tif (override !== false && (parentConsole || override)) {\n\t\t\treturn createPrefixedConsole(prefix, parentConsole)\n\t\t} else {\n\t\t\treturn noopScopedConsole\n\t\t}\n\t}, [override, parentConsole, prefix])\n\n\tconst ref = useRef(scopedConsole)\n\tref.current = scopedConsole\n\n\treturn ref\n}\n\nexport type DebugChildrenProps =\n\t| { active?: true; children: ReactNode; id: string }\n\t| { active?: false; children: ReactNode; id?: string }\n\nexport const DebugChildren = memo<DebugChildrenProps>(({ active = true, children, id }) => {\n\tconst parentScopedConsole = parentScopedConsoleOrNone(useContext(ScopedConsoleContext))\n\n\tconst console = active && id\n\t\t? createPrefixedConsole(id, parentScopedConsole)\n\t\t: noopScopedConsole\n\n\treturn (\n\t\t<ScopedConsoleContext.Provider value={active ? console : noopScopedConsole}>\n\t\t\t{children}\n\t\t</ScopedConsoleContext.Provider>\n\t)\n})\nDebugChildren.displayName = 'DebugChildren'\n"],"names":["message","createContext","isNoopScopedConsole","useContext","useMemo","noopScopedConsole","useRef","memo","console","jsx"],"mappings":";;;;;AAIA,SAAS,sBAAsB,SAAiB,iBAAsE;AAC9G,SAAA;AAAA,IACN,OAAO,SAAS,SAAS,YAAmB;AAC3C,OAAC,mBAAmB,SAAS,MAAM,SAAS,GAAG,UAAU;AAAA,IAC1D;AAAA,IACA,SAAS,SAAS,QAAWA,UAAiB,OAAa;AAC1D,OAAC,mBAAmB,SAAS,MAAMA,UAAS,KAAK;AAC1C,aAAA;AAAA,IACR;AAAA,IACA,KAAK,SAAS,OAAO,YAAmB;AACvC,OAAC,mBAAmB,SAAS,IAAI,SAAS,GAAG,UAAU;AAAA,IACxD;AAAA,IACA,QAAQ,SAAS,OAAUA,UAAiB,OAAa;AACxD,OAAC,mBAAmB,SAAS,IAAIA,UAAS,KAAK;AACxC,aAAA;AAAA,IACR;AAAA,IACA,OAAO,SAAS,SAAS,YAAmB;AAC3C,OAAC,mBAAmB,SAAS,MAAM,SAAS,GAAG,UAAU;AAAA,IAC1D;AAAA,IACA,QAAQ,SAAS,OAAUA,UAAiB,OAAa;AACxD,OAAC,mBAAmB,SAAS,MAAMA,UAAS,KAAK;AAC1C,aAAA;AAAA,IACR;AAAA,IACA,MAAM,SAAS,QAAQ,YAAmB;AACzC,OAAC,mBAAmB,SAAS,KAAK,SAAS,GAAG,UAAU;AAAA,IACzD;AAAA,IACA,QAAQ,SAAS,OAAUA,UAAiB,OAAa;AACxD,OAAC,mBAAmB,SAAS,KAAKA,UAAS,KAAK;AACzC,aAAA;AAAA,IACR;AAAA,EAAA;AAEF;AAEa,MAAA,uBAAuBC,oBAAwC,IAAK;AACjF,qBAAqB,cAAc;AAEnC,SAAS,0BAA0B,eAA+E;AAC1G,SAAAC,UAAA,oBAAoB,aAAa,IAAI,SAAY;AACzD;AAEa,MAAA,sBAAsB,CAAC,QAAgB,aAAuB;AACtE,MAAA,OAAO,WAAW,GAAG;AAClB,UAAA,IAAI,MAAM,iCAAiC;AAAA,EAClD;AACA,QAAM,gBAAgB,0BAA0BC,iBAAW,oBAAoB,CAAC;AAE1E,QAAA,gBAAgBC,MAAAA,QAAQ,MAAM;AAC/B,QAAA,aAAa,UAAU,iBAAiB,WAAW;AAC/C,aAAA,sBAAsB,QAAQ,aAAa;AAAA,IAAA,OAC5C;AACC,aAAAC;IACR;AAAA,EACE,GAAA,CAAC,UAAU,eAAe,MAAM,CAAC;AAE9B,QAAA,MAAMC,aAAO,aAAa;AAChC,MAAI,UAAU;AAEP,SAAA;AACR;AAMa,MAAA,gBAAgBC,WAAyB,CAAC,EAAE,SAAS,MAAM,UAAU,SAAS;AAC1F,QAAM,sBAAsB,0BAA0BJ,iBAAW,oBAAoB,CAAC;AAEtF,QAAMK,WAAU,UAAU,KACvB,sBAAsB,IAAI,mBAAmB,IAC7CH;AAGF,SAAAI,2BAAA,IAAC,qBAAqB,UAArB,EAA8B,OAAO,SAASD,WAAUH,UAAAA,mBACvD,SACF,CAAA;AAEF,CAAC;AACD,cAAc,cAAc;;;;"}
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { jsx } from "react/jsx-runtime";
|
|
2
|
-
import { assert, isNonEmptyString } from "@contember/utilities";
|
|
3
2
|
import { createContext, useContext, useMemo, useRef, memo } from "react";
|
|
4
3
|
import { noopScopedConsole, isNoopScopedConsole } from "./Constants.js";
|
|
5
4
|
function createPrefixedConsole(message, prefixedConsole) {
|
|
@@ -40,7 +39,9 @@ function parentScopedConsoleOrNone(parentConsole) {
|
|
|
40
39
|
return isNoopScopedConsole(parentConsole) ? void 0 : parentConsole;
|
|
41
40
|
}
|
|
42
41
|
const useScopedConsoleRef = (prefix, override) => {
|
|
43
|
-
|
|
42
|
+
if (prefix.length === 0) {
|
|
43
|
+
throw new Error("Prefix must be non-empty string");
|
|
44
|
+
}
|
|
44
45
|
const parentConsole = parentScopedConsoleOrNone(useContext(ScopedConsoleContext));
|
|
45
46
|
const scopedConsole = useMemo(() => {
|
|
46
47
|
if (override !== false && (parentConsole || override)) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Context.js","sources":["../../../src/debug-context/Context.tsx"],"sourcesContent":["import {
|
|
1
|
+
{"version":3,"file":"Context.js","sources":["../../../src/debug-context/Context.tsx"],"sourcesContent":["import { ReactNode, createContext, memo, useContext, useMemo, useRef } from 'react'\nimport { isNoopScopedConsole, noopScopedConsole } from './Constants'\nimport { ScopedConsoleContextType } from './Types'\n\nfunction createPrefixedConsole(message: string, prefixedConsole?: ScopedConsoleContextType): ScopedConsoleContextType {\n\treturn {\n\t\terror: function error(...parameters: any[]) {\n\t\t\t(prefixedConsole ?? console).error(message, ...parameters)\n\t\t},\n\t\terrored: function errored<T>(message: string, value: T): T {\n\t\t\t(prefixedConsole ?? console).error(message, value)\n\t\t\treturn value\n\t\t},\n\t\tlog: function log(...parameters: any[]) {\n\t\t\t(prefixedConsole ?? console).log(message, ...parameters)\n\t\t},\n\t\tlogged: function logged<T>(message: string, value: T): T {\n\t\t\t(prefixedConsole ?? console).log(message, value)\n\t\t\treturn value\n\t\t},\n\t\ttrace: function trace(...parameters: any[]) {\n\t\t\t(prefixedConsole ?? console).trace(message, ...parameters)\n\t\t},\n\t\ttraced: function traced<T>(message: string, value: T): T {\n\t\t\t(prefixedConsole ?? console).trace(message, value)\n\t\t\treturn value\n\t\t},\n\t\twarn: function warn(...parameters: any[]) {\n\t\t\t(prefixedConsole ?? console).warn(message, ...parameters)\n\t\t},\n\t\twarned: function warned<T>(message: string, value: T): T {\n\t\t\t(prefixedConsole ?? console).warn(message, value)\n\t\t\treturn value\n\t\t},\n\t}\n}\n\nexport const ScopedConsoleContext = createContext<ScopedConsoleContextType>(null!)\nScopedConsoleContext.displayName = 'ScopedConsoleContext'\n\nfunction parentScopedConsoleOrNone(parentConsole: ScopedConsoleContextType): ScopedConsoleContextType | undefined {\n\treturn isNoopScopedConsole(parentConsole) ? undefined : parentConsole\n}\n\nexport const useScopedConsoleRef = (prefix: string, override?: boolean) => {\n\tif (prefix.length === 0) {\n\t\tthrow new Error('Prefix must be non-empty string')\n\t}\n\tconst parentConsole = parentScopedConsoleOrNone(useContext(ScopedConsoleContext))\n\n\tconst scopedConsole = useMemo(() => {\n\t\tif (override !== false && (parentConsole || override)) {\n\t\t\treturn createPrefixedConsole(prefix, parentConsole)\n\t\t} else {\n\t\t\treturn noopScopedConsole\n\t\t}\n\t}, [override, parentConsole, prefix])\n\n\tconst ref = useRef(scopedConsole)\n\tref.current = scopedConsole\n\n\treturn ref\n}\n\nexport type DebugChildrenProps =\n\t| { active?: true; children: ReactNode; id: string }\n\t| { active?: false; children: ReactNode; id?: string }\n\nexport const DebugChildren = memo<DebugChildrenProps>(({ active = true, children, id }) => {\n\tconst parentScopedConsole = parentScopedConsoleOrNone(useContext(ScopedConsoleContext))\n\n\tconst console = active && id\n\t\t? createPrefixedConsole(id, parentScopedConsole)\n\t\t: noopScopedConsole\n\n\treturn (\n\t\t<ScopedConsoleContext.Provider value={active ? console : noopScopedConsole}>\n\t\t\t{children}\n\t\t</ScopedConsoleContext.Provider>\n\t)\n})\nDebugChildren.displayName = 'DebugChildren'\n"],"names":["message","console"],"mappings":";;;AAIA,SAAS,sBAAsB,SAAiB,iBAAsE;AAC9G,SAAA;AAAA,IACN,OAAO,SAAS,SAAS,YAAmB;AAC3C,OAAC,mBAAmB,SAAS,MAAM,SAAS,GAAG,UAAU;AAAA,IAC1D;AAAA,IACA,SAAS,SAAS,QAAWA,UAAiB,OAAa;AAC1D,OAAC,mBAAmB,SAAS,MAAMA,UAAS,KAAK;AAC1C,aAAA;AAAA,IACR;AAAA,IACA,KAAK,SAAS,OAAO,YAAmB;AACvC,OAAC,mBAAmB,SAAS,IAAI,SAAS,GAAG,UAAU;AAAA,IACxD;AAAA,IACA,QAAQ,SAAS,OAAUA,UAAiB,OAAa;AACxD,OAAC,mBAAmB,SAAS,IAAIA,UAAS,KAAK;AACxC,aAAA;AAAA,IACR;AAAA,IACA,OAAO,SAAS,SAAS,YAAmB;AAC3C,OAAC,mBAAmB,SAAS,MAAM,SAAS,GAAG,UAAU;AAAA,IAC1D;AAAA,IACA,QAAQ,SAAS,OAAUA,UAAiB,OAAa;AACxD,OAAC,mBAAmB,SAAS,MAAMA,UAAS,KAAK;AAC1C,aAAA;AAAA,IACR;AAAA,IACA,MAAM,SAAS,QAAQ,YAAmB;AACzC,OAAC,mBAAmB,SAAS,KAAK,SAAS,GAAG,UAAU;AAAA,IACzD;AAAA,IACA,QAAQ,SAAS,OAAUA,UAAiB,OAAa;AACxD,OAAC,mBAAmB,SAAS,KAAKA,UAAS,KAAK;AACzC,aAAA;AAAA,IACR;AAAA,EAAA;AAEF;AAEa,MAAA,uBAAuB,cAAwC,IAAK;AACjF,qBAAqB,cAAc;AAEnC,SAAS,0BAA0B,eAA+E;AAC1G,SAAA,oBAAoB,aAAa,IAAI,SAAY;AACzD;AAEa,MAAA,sBAAsB,CAAC,QAAgB,aAAuB;AACtE,MAAA,OAAO,WAAW,GAAG;AAClB,UAAA,IAAI,MAAM,iCAAiC;AAAA,EAClD;AACA,QAAM,gBAAgB,0BAA0B,WAAW,oBAAoB,CAAC;AAE1E,QAAA,gBAAgB,QAAQ,MAAM;AAC/B,QAAA,aAAa,UAAU,iBAAiB,WAAW;AAC/C,aAAA,sBAAsB,QAAQ,aAAa;AAAA,IAAA,OAC5C;AACC,aAAA;AAAA,IACR;AAAA,EACE,GAAA,CAAC,UAAU,eAAe,MAAM,CAAC;AAE9B,QAAA,MAAM,OAAO,aAAa;AAChC,MAAI,UAAU;AAEP,SAAA;AACR;AAMa,MAAA,gBAAgB,KAAyB,CAAC,EAAE,SAAS,MAAM,UAAU,SAAS;AAC1F,QAAM,sBAAsB,0BAA0B,WAAW,oBAAoB,CAAC;AAEtF,QAAMC,WAAU,UAAU,KACvB,sBAAsB,IAAI,mBAAmB,IAC7C;AAGF,SAAA,oBAAC,qBAAqB,UAArB,EAA8B,OAAO,SAASA,WAAU,mBACvD,SACF,CAAA;AAEF,CAAC;AACD,cAAc,cAAc;"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
|
+
function unwrapRefValue(value) {
|
|
4
|
+
if (value && typeof value === "object" && "current" in value) {
|
|
5
|
+
return value.current;
|
|
6
|
+
} else {
|
|
7
|
+
return value;
|
|
8
|
+
}
|
|
9
|
+
}
|
|
10
|
+
exports.unwrapRefValue = unwrapRefValue;
|
|
11
|
+
//# sourceMappingURL=unwrapRefValue.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"unwrapRefValue.cjs","sources":["../../../src/hooks/unwrapRefValue.ts"],"sourcesContent":["import { RefObject } from 'react'\n\nexport type RefObjectOrElement<T> = T | RefObject<T>\n\n/**\n * Unwraps a ref object or returns the value if it is not a ref object.\n * @param value - Value to unwrap\n * @returns Unwrapped value\n */\nexport function unwrapRefValue<T>(value: RefObjectOrElement<T>): T | null {\n\tif (value && typeof value === 'object' && 'current' in value) {\n\t\treturn value.current\n\t} else {\n\t\treturn value\n\t}\n}\n"],"names":[],"mappings":";;AASO,SAAS,eAAkB,OAAwC;AACzE,MAAI,SAAS,OAAO,UAAU,YAAY,aAAa,OAAO;AAC7D,WAAO,MAAM;AAAA,EAAA,OACP;AACC,WAAA;AAAA,EACR;AACD;;"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
|
+
const react = require("react");
|
|
4
|
+
const useAbortController = () => {
|
|
5
|
+
const lastAbortControllerRef = react.useRef(void 0);
|
|
6
|
+
react.useEffect(() => () => {
|
|
7
|
+
lastAbortControllerRef.current?.abort();
|
|
8
|
+
}, []);
|
|
9
|
+
return react.useCallback(() => {
|
|
10
|
+
lastAbortControllerRef.current?.abort();
|
|
11
|
+
const newController = new AbortController();
|
|
12
|
+
lastAbortControllerRef.current = newController;
|
|
13
|
+
return newController.signal;
|
|
14
|
+
}, []);
|
|
15
|
+
};
|
|
16
|
+
exports.useAbortController = useAbortController;
|
|
17
|
+
//# sourceMappingURL=useAbortController.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useAbortController.cjs","sources":["../../../src/hooks/useAbortController.ts"],"sourcesContent":["import { useCallback, useEffect, useRef } from 'react'\n\nexport const useAbortController = () => {\n\tconst lastAbortControllerRef = useRef<AbortController | undefined>(undefined)\n\tuseEffect(() => () => {\n\t\tlastAbortControllerRef.current?.abort()\n\t}, [])\n\treturn useCallback((): AbortSignal => {\n\t\tlastAbortControllerRef.current?.abort()\n\n\t\tconst newController = new AbortController()\n\t\tlastAbortControllerRef.current = newController\n\t\treturn newController.signal\n\t}, [])\n}\n"],"names":["useRef","useEffect","useCallback"],"mappings":";;;AAEO,MAAM,qBAAqB,MAAM;AACjC,QAAA,yBAAyBA,MAAAA,OAAoC,MAAS;AAC5EC,QAAAA,UAAU,MAAM,MAAM;AACrB,2BAAuB,SAAS;EACjC,GAAG,CAAE,CAAA;AACL,SAAOC,kBAAY,MAAmB;AACrC,2BAAuB,SAAS;AAE1B,UAAA,gBAAgB,IAAI;AAC1B,2BAAuB,UAAU;AACjC,WAAO,cAAc;AAAA,EACtB,GAAG,CAAE,CAAA;AACN;;"}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
|
+
const react = require("react");
|
|
4
|
+
const useOnWindowResize = require("./useOnWindowResize.cjs");
|
|
5
|
+
const useReferentiallyStableCallback = require("../referentiallyStable/useReferentiallyStableCallback.cjs");
|
|
6
|
+
function addClassName(className, element) {
|
|
7
|
+
if (element.classList.contains(className)) {
|
|
8
|
+
element.classList.remove(className);
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
function removeClassName(className, element) {
|
|
12
|
+
if (!element.classList.contains(className)) {
|
|
13
|
+
element.classList.add(className);
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
function useAddClassNameDuringResize(className, timeoutToRestore = 300, element) {
|
|
17
|
+
const timeoutID = react.useRef();
|
|
18
|
+
const addTemporaryClassName = useReferentiallyStableCallback.useReferentiallyStableCallback(() => {
|
|
19
|
+
clearTimeout(timeoutID.current);
|
|
20
|
+
removeClassName(className, element ?? document.body);
|
|
21
|
+
timeoutID.current = setTimeout(() => {
|
|
22
|
+
addClassName(className, element ?? document.body);
|
|
23
|
+
}, timeoutToRestore);
|
|
24
|
+
return () => {
|
|
25
|
+
clearTimeout(timeoutID.current);
|
|
26
|
+
};
|
|
27
|
+
});
|
|
28
|
+
react.useLayoutEffect(addTemporaryClassName, [addTemporaryClassName]);
|
|
29
|
+
useOnWindowResize.useOnWindowResize(addTemporaryClassName);
|
|
30
|
+
}
|
|
31
|
+
exports.useAddClassNameDuringResize = useAddClassNameDuringResize;
|
|
32
|
+
//# sourceMappingURL=useAddClassNameDuringResize.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useAddClassNameDuringResize.cjs","sources":["../../../src/hooks/useAddClassNameDuringResize.ts"],"sourcesContent":["import { useLayoutEffect, useRef } from 'react'\nimport { useReferentiallyStableCallback } from '../referentiallyStable'\nimport { useOnWindowResize } from './useOnWindowResize'\n\nfunction addClassName(\n\tclassName: string,\n\telement: HTMLElement,\n) {\n\tif (element.classList.contains(className)) {\n\t\telement.classList.remove(className)\n\t}\n}\n\nfunction removeClassName(\n\tclassName: string,\n\telement: HTMLElement,\n) {\n\tif (!element.classList.contains(className)) {\n\t\telement.classList.add(className)\n\t}\n}\n\n/**\n * Adds CSS class during resize event to element\n *\n * - Falls back to document.body when no element is specified\n * - Adds CSS class to element also on the initial load\n * - Uses element.classList directly\n *\n * @param className - CSS class to apply during the resize event\n * @param timeoutToRestore - Timeout in milliseconds to wait before finally removing the CSS class\n * @param element - Optional HTML element to apply CSS class to\n */\nexport function useAddClassNameDuringResize(\n\tclassName: string,\n\ttimeoutToRestore: number = 300,\n\telement?: HTMLElement,\n) {\n\tconst timeoutID = useRef<number>()\n\n\tconst addTemporaryClassName = useReferentiallyStableCallback(() => {\n\t\tclearTimeout(timeoutID.current)\n\t\tremoveClassName(className, element ?? document.body)\n\n\t\ttimeoutID.current = setTimeout(() => {\n\t\t\taddClassName(className, element ?? document.body)\n\t\t}, timeoutToRestore)\n\n\t\treturn () => {\n\t\t\tclearTimeout(timeoutID.current)\n\t\t}\n\t})\n\n\tuseLayoutEffect(addTemporaryClassName, [addTemporaryClassName])\n\tuseOnWindowResize(addTemporaryClassName)\n}\n"],"names":["useRef","useReferentiallyStableCallback","useLayoutEffect","useOnWindowResize"],"mappings":";;;;;AAIA,SAAS,aACR,WACA,SACC;AACD,MAAI,QAAQ,UAAU,SAAS,SAAS,GAAG;AAClC,YAAA,UAAU,OAAO,SAAS;AAAA,EACnC;AACD;AAEA,SAAS,gBACR,WACA,SACC;AACD,MAAI,CAAC,QAAQ,UAAU,SAAS,SAAS,GAAG;AACnC,YAAA,UAAU,IAAI,SAAS;AAAA,EAChC;AACD;AAaO,SAAS,4BACf,WACA,mBAA2B,KAC3B,SACC;AACD,QAAM,YAAYA,MAAAA;AAEZ,QAAA,wBAAwBC,+BAAAA,+BAA+B,MAAM;AAClE,iBAAa,UAAU,OAAO;AACd,oBAAA,WAAW,WAAW,SAAS,IAAI;AAEzC,cAAA,UAAU,WAAW,MAAM;AACvB,mBAAA,WAAW,WAAW,SAAS,IAAI;AAAA,OAC9C,gBAAgB;AAEnB,WAAO,MAAM;AACZ,mBAAa,UAAU,OAAO;AAAA,IAAA;AAAA,EAC/B,CACA;AAEeC,QAAAA,gBAAA,uBAAuB,CAAC,qBAAqB,CAAC;AAC9DC,oBAAA,kBAAkB,qBAAqB;AACxC;;"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
|
+
const react = require("react");
|
|
4
|
+
const useArrayMapMemo = (items, map) => {
|
|
5
|
+
const mapped = react.useMemo(() => items.map(map), [map, ...items]);
|
|
6
|
+
return react.useMemo(() => mapped, mapped);
|
|
7
|
+
};
|
|
8
|
+
exports.useArrayMapMemo = useArrayMapMemo;
|
|
9
|
+
//# sourceMappingURL=useArrayMapMemo.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useArrayMapMemo.cjs","sources":["../../../src/hooks/useArrayMapMemo.ts"],"sourcesContent":["import { useMemo } from 'react'\nimport { useConstantLengthInvariant } from './useConstantLengthInvariant'\n\n/**\n * ⚠️ ONLY USE THIS IF YOU *REALLY* KNOW WHAT YOU'RE DOING! ⚠️\n * ⚠ HERE BE DRAGONS THAT KNOW WHERE YOU LIVE! ⚠\n *\n * This is a bit of React naughtiness that allows us to memoize outputs of Array.prototype.map() based on the contents\n * of the original array, and not its referential equality. That way, if we create a new array with identical items,\n * we get an array that is referentially equal to the previous one.\n */\nexport const useArrayMapMemo = <Item, OutputItem>(\n\titems: Item[],\n\tmap: (value: Item, index: number, array: Item[]) => OutputItem,\n): OutputItem[] => {\n\tuseConstantLengthInvariant(items)\n\n\t// This is tricky. We don't want to exclude the map function from the dependency list because if it changes but the\n\t// items array remains the same, we still want to re-compute the new array. However, if that yields the same array,\n\t// in the sense that the items are identical, albeit computed via a different map function, we still want to\n\t// preserve the referential equality of the original. Hence the second memo.\n\n\t// eslint-disable-next-line react-hooks/exhaustive-deps\n\tconst mapped = useMemo(() => items.map(map), [map, ...items])\n\n\t// eslint-disable-next-line react-hooks/exhaustive-deps\n\treturn useMemo(() => mapped, mapped) // This is deliberately not `[mapped]`\n}\n"],"names":["useMemo"],"mappings":";;;AAWa,MAAA,kBAAkB,CAC9B,OACA,QACkB;AASZ,QAAA,SAASA,MAAAA,QAAQ,MAAM,MAAM,IAAI,GAAG,GAAG,CAAC,KAAK,GAAG,KAAK,CAAC;AAGrD,SAAAA,cAAQ,MAAM,QAAQ,MAAM;AACpC;;"}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
|
+
const utilities = require("@contember/utilities");
|
|
4
|
+
const react = require("react");
|
|
5
|
+
const unwrapRefValue = require("./unwrapRefValue.cjs");
|
|
6
|
+
const useOnElementResize = require("./useOnElementResize.cjs");
|
|
7
|
+
const useAutoHeightTextArea = (textAreaRef, value, minRows, maxRows) => {
|
|
8
|
+
const measure = react.useCallback(async (ref, minRows2, maxRows2) => {
|
|
9
|
+
if (ref) {
|
|
10
|
+
const rowsAttribute = ref.rows;
|
|
11
|
+
ref.style.height = "";
|
|
12
|
+
ref.style.minHeight = "";
|
|
13
|
+
ref.style.maxHeight = "";
|
|
14
|
+
if (minRows2 !== maxRows2) {
|
|
15
|
+
const height = ref.scrollHeight;
|
|
16
|
+
let minHeight;
|
|
17
|
+
let maxHeight;
|
|
18
|
+
ref.rows = minRows2;
|
|
19
|
+
minHeight = await ref.getBoundingClientRect().height;
|
|
20
|
+
if (maxRows2 === Infinity) {
|
|
21
|
+
maxHeight = Infinity;
|
|
22
|
+
} else {
|
|
23
|
+
ref.rows = maxRows2;
|
|
24
|
+
maxHeight = await ref.getBoundingClientRect().height;
|
|
25
|
+
}
|
|
26
|
+
ref.style.height = utilities.px(height);
|
|
27
|
+
ref.style.minHeight = utilities.px(minHeight);
|
|
28
|
+
ref.style.maxHeight = utilities.px(maxHeight);
|
|
29
|
+
}
|
|
30
|
+
ref.rows = rowsAttribute;
|
|
31
|
+
}
|
|
32
|
+
}, []);
|
|
33
|
+
useOnElementResize.useOnElementResize(textAreaRef, () => {
|
|
34
|
+
measure(unwrapRefValue.unwrapRefValue(textAreaRef), minRows, maxRows);
|
|
35
|
+
});
|
|
36
|
+
react.useLayoutEffect(() => {
|
|
37
|
+
measure(unwrapRefValue.unwrapRefValue(textAreaRef), minRows, maxRows);
|
|
38
|
+
}, [maxRows, measure, minRows, textAreaRef, value]);
|
|
39
|
+
};
|
|
40
|
+
exports.useAutoHeightTextArea = useAutoHeightTextArea;
|
|
41
|
+
//# sourceMappingURL=useAutoHeightTextArea.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useAutoHeightTextArea.cjs","sources":["../../../src/hooks/useAutoHeightTextArea.ts"],"sourcesContent":["import { px } from '@contember/utilities'\nimport { useCallback, useLayoutEffect } from 'react'\nimport { RefObjectOrElement, unwrapRefValue } from './unwrapRefValue'\nimport { useOnElementResize } from './useOnElementResize'\n\nexport const useAutoHeightTextArea = (\n\ttextAreaRef: RefObjectOrElement<HTMLTextAreaElement>,\n\tvalue: string,\n\tminRows: number,\n\tmaxRows: number,\n) => {\n\tconst measure = useCallback(async (ref: HTMLTextAreaElement | null, minRows: number, maxRows: number) => {\n\t\tif (ref) {\n\t\t\tconst rowsAttribute = ref.rows\n\n\t\t\tref.style.height = ''\n\t\t\tref.style.minHeight = ''\n\t\t\tref.style.maxHeight = ''\n\n\t\t\tif (minRows !== maxRows) {\n\t\t\t\tconst height = ref.scrollHeight\n\t\t\t\tlet minHeight: number\n\t\t\t\tlet maxHeight: number\n\n\t\t\t\tref.rows = minRows\n\t\t\t\tminHeight = await ref.getBoundingClientRect().height\n\n\t\t\t\tif (maxRows === Infinity) {\n\t\t\t\t\tmaxHeight = Infinity\n\t\t\t\t} else {\n\t\t\t\t\tref.rows = maxRows\n\t\t\t\t\tmaxHeight = await ref.getBoundingClientRect().height\n\t\t\t\t}\n\n\t\t\t\tref.style.height = px(height)\n\t\t\t\tref.style.minHeight = px(minHeight)\n\t\t\t\tref.style.maxHeight = px(maxHeight)\n\t\t\t}\n\n\t\t\tref.rows = rowsAttribute\n\t\t}\n\t}, [])\n\n\tuseOnElementResize(textAreaRef, () => {\n\t\tmeasure(unwrapRefValue(textAreaRef), minRows, maxRows)\n\t})\n\n\tuseLayoutEffect(() => {\n\t\tmeasure(unwrapRefValue(textAreaRef), minRows, maxRows)\n\t}, [maxRows, measure, minRows, textAreaRef, value])\n}\n"],"names":["useCallback","minRows","maxRows","px","useOnElementResize","unwrapRefValue","useLayoutEffect"],"mappings":";;;;;;AAKO,MAAM,wBAAwB,CACpC,aACA,OACA,SACA,YACI;AACJ,QAAM,UAAUA,MAAA,YAAY,OAAO,KAAiCC,UAAiBC,aAAoB;AACxG,QAAI,KAAK;AACR,YAAM,gBAAgB,IAAI;AAE1B,UAAI,MAAM,SAAS;AACnB,UAAI,MAAM,YAAY;AACtB,UAAI,MAAM,YAAY;AAEtB,UAAID,aAAYC,UAAS;AACxB,cAAM,SAAS,IAAI;AACf,YAAA;AACA,YAAA;AAEJ,YAAI,OAAOD;AACC,oBAAA,MAAM,IAAI,sBAAA,EAAwB;AAE9C,YAAIC,aAAY,UAAU;AACb,sBAAA;AAAA,QAAA,OACN;AACN,cAAI,OAAOA;AACC,sBAAA,MAAM,IAAI,sBAAA,EAAwB;AAAA,QAC/C;AAEI,YAAA,MAAM,SAASC,UAAA,GAAG,MAAM;AACxB,YAAA,MAAM,YAAYA,UAAA,GAAG,SAAS;AAC9B,YAAA,MAAM,YAAYA,UAAA,GAAG,SAAS;AAAA,MACnC;AAEA,UAAI,OAAO;AAAA,IACZ;AAAA,EACD,GAAG,CAAE,CAAA;AAELC,qBAAA,mBAAmB,aAAa,MAAM;AACrC,YAAQC,eAAAA,eAAe,WAAW,GAAG,SAAS,OAAO;AAAA,EAAA,CACrD;AAEDC,QAAAA,gBAAgB,MAAM;AACrB,YAAQD,eAAAA,eAAe,WAAW,GAAG,SAAS,OAAO;AAAA,EAAA,GACnD,CAAC,SAAS,SAAS,SAAS,aAAa,KAAK,CAAC;AACnD;;"}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
|
+
const react = require("react");
|
|
4
|
+
const MULTIPLE_SPACES_REG_EXP = / +/g;
|
|
5
|
+
function normalize(text) {
|
|
6
|
+
return text.replace(MULTIPLE_SPACES_REG_EXP, " ").trim();
|
|
7
|
+
}
|
|
8
|
+
function getChildrenAsLabel(node) {
|
|
9
|
+
if (typeof node === "string" || typeof node === "number") {
|
|
10
|
+
return String(node);
|
|
11
|
+
} else if (node === null || node === void 0 || typeof node === "boolean") {
|
|
12
|
+
return void 0;
|
|
13
|
+
} else if (Array.isArray(node)) {
|
|
14
|
+
return normalize(node.map(getChildrenAsLabel).join(""));
|
|
15
|
+
} else {
|
|
16
|
+
let label = [];
|
|
17
|
+
react.Children.map(node, (child) => {
|
|
18
|
+
if (child === null || child === void 0 || typeof child === "boolean")
|
|
19
|
+
;
|
|
20
|
+
else if (typeof child === "string") {
|
|
21
|
+
label.push(child);
|
|
22
|
+
} else if (typeof child === "number") {
|
|
23
|
+
label.push(child);
|
|
24
|
+
} else if (Array.isArray(child)) {
|
|
25
|
+
const childLabel = getChildrenAsLabel(child);
|
|
26
|
+
if (childLabel) {
|
|
27
|
+
label.push(childLabel);
|
|
28
|
+
}
|
|
29
|
+
} else {
|
|
30
|
+
if ("props" in child && "children" in child.props) {
|
|
31
|
+
const childLabel = getChildrenAsLabel(child.props.children);
|
|
32
|
+
if (childLabel) {
|
|
33
|
+
label.push(childLabel);
|
|
34
|
+
}
|
|
35
|
+
} else if ("children" in child) {
|
|
36
|
+
const childLabel = getChildrenAsLabel(child.children);
|
|
37
|
+
if (childLabel) {
|
|
38
|
+
label.push(childLabel);
|
|
39
|
+
}
|
|
40
|
+
} else
|
|
41
|
+
;
|
|
42
|
+
}
|
|
43
|
+
});
|
|
44
|
+
return label.length > 0 ? label.join("") : void 0;
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
function useChildrenAsLabel(node) {
|
|
48
|
+
return react.useMemo(() => getChildrenAsLabel(node), [node]);
|
|
49
|
+
}
|
|
50
|
+
exports.getChildrenAsLabel = getChildrenAsLabel;
|
|
51
|
+
exports.useChildrenAsLabel = useChildrenAsLabel;
|
|
52
|
+
//# sourceMappingURL=useChildrenAsLabel.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useChildrenAsLabel.cjs","sources":["../../../src/hooks/useChildrenAsLabel.ts"],"sourcesContent":["import { Children, ReactNode, useMemo } from 'react'\n\nconst MULTIPLE_SPACES_REG_EXP = / +/g\n\nfunction normalize(text: string): string {\n\treturn text.replace(MULTIPLE_SPACES_REG_EXP, ' ').trim()\n}\n\n/**\n * Walks through the children and returns a string representation of the text content.\n *\n * @param node - The children to walk through.\n * @returns String representation of the text content or undefined if there is no text content.\n *\n */\nexport function getChildrenAsLabel(node: ReactNode): string | undefined {\n\tif (typeof node === 'string' || typeof node === 'number') {\n\t\treturn String(node)\n\t} else if (node === null || node === undefined || typeof node === 'boolean') {\n\t\treturn undefined\n\t} else if (Array.isArray(node)) {\n\t\treturn normalize(node.map(getChildrenAsLabel).join(''))\n\t} else {\n\t\tlet label: (string | number)[] = []\n\n\t\tChildren.map(node, child => {\n\t\t\tif (child === null || child === undefined || typeof child === 'boolean') {\n\t\t\t} else if (typeof child === 'string') {\n\t\t\t\tlabel.push(child)\n\t\t\t} else if (typeof child === 'number') {\n\t\t\t\tlabel.push(child)\n\t\t\t} else if (Array.isArray(child)) {\n\t\t\t\tconst childLabel = getChildrenAsLabel(child)\n\n\t\t\t\tif (childLabel) {\n\t\t\t\t\tlabel.push(childLabel)\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\t// ReactElement | JSXElementConstructor | ReactPortal\n\t\t\t\tif ('props' in child && 'children' in child.props) {\n\t\t\t\t\tconst childLabel = getChildrenAsLabel(child.props.children)\n\n\t\t\t\t\tif (childLabel) {\n\t\t\t\t\t\tlabel.push(childLabel)\n\t\t\t\t\t}\n\t\t\t\t} else if ('children' in child) {\n\t\t\t\t\t// ReactPortal\n\t\t\t\t\tconst childLabel = getChildrenAsLabel(child.children)\n\n\t\t\t\t\tif (childLabel) {\n\t\t\t\t\t\tlabel.push(childLabel)\n\t\t\t\t\t}\n\t\t\t\t} else if (import.meta.env.DEV) {\n\t\t\t\t\tconsole.warn('Unsupported child:', child)\n\t\t\t\t}\n\t\t\t}\n\t\t})\n\n\t\treturn label.length > 0 ? label.join('') : undefined\n\t}\n}\n\n/**\n * Walks through the children and returns a string representation of the text content.\n *\n * @param node - The children to walk through.\n * @returns String representation of the text content or undefined if there is no text content.\n *\n */\nexport function useChildrenAsLabel(node: ReactNode): string | undefined {\n\treturn useMemo(() => getChildrenAsLabel(node), [node])\n}\n"],"names":["Children","useMemo"],"mappings":";;;AAEA,MAAM,0BAA0B;AAEhC,SAAS,UAAU,MAAsB;AACxC,SAAO,KAAK,QAAQ,yBAAyB,GAAG,EAAE,KAAK;AACxD;AASO,SAAS,mBAAmB,MAAqC;AACvE,MAAI,OAAO,SAAS,YAAY,OAAO,SAAS,UAAU;AACzD,WAAO,OAAO,IAAI;AAAA,EAAA,WACR,SAAS,QAAQ,SAAS,UAAa,OAAO,SAAS,WAAW;AACrE,WAAA;AAAA,EACG,WAAA,MAAM,QAAQ,IAAI,GAAG;AAC/B,WAAO,UAAU,KAAK,IAAI,kBAAkB,EAAE,KAAK,EAAE,CAAC;AAAA,EAAA,OAChD;AACN,QAAI,QAA6B,CAAA;AAExBA,UAAAA,SAAA,IAAI,MAAM,CAAS,UAAA;AAC3B,UAAI,UAAU,QAAQ,UAAU,UAAa,OAAO,UAAU;AAAW;AAAA,eAC9D,OAAO,UAAU,UAAU;AACrC,cAAM,KAAK,KAAK;AAAA,MAAA,WACN,OAAO,UAAU,UAAU;AACrC,cAAM,KAAK,KAAK;AAAA,MACN,WAAA,MAAM,QAAQ,KAAK,GAAG;AAC1B,cAAA,aAAa,mBAAmB,KAAK;AAE3C,YAAI,YAAY;AACf,gBAAM,KAAK,UAAU;AAAA,QACtB;AAAA,MAAA,OACM;AAEN,YAAI,WAAW,SAAS,cAAc,MAAM,OAAO;AAClD,gBAAM,aAAa,mBAAmB,MAAM,MAAM,QAAQ;AAE1D,cAAI,YAAY;AACf,kBAAM,KAAK,UAAU;AAAA,UACtB;AAAA,QAAA,WACU,cAAc,OAAO;AAEzB,gBAAA,aAAa,mBAAmB,MAAM,QAAQ;AAEpD,cAAI,YAAY;AACf,kBAAM,KAAK,UAAU;AAAA,UACtB;AAAA,QAAA;;MAIF;AAAA,IAAA,CACA;AAED,WAAO,MAAM,SAAS,IAAI,MAAM,KAAK,EAAE,IAAI;AAAA,EAC5C;AACD;AASO,SAAS,mBAAmB,MAAqC;AACvE,SAAOC,MAAAA,QAAQ,MAAM,mBAAmB,IAAI,GAAG,CAAC,IAAI,CAAC;AACtD;;;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useChildrenAsLabel.js","sources":["../../../src/hooks/useChildrenAsLabel.ts"],"sourcesContent":["import { Children, ReactNode, useMemo } from 'react'\n\nconst MULTIPLE_SPACES_REG_EXP = / +/g\n\nfunction normalize(text: string): string {\n\treturn text.replace(MULTIPLE_SPACES_REG_EXP, ' ').trim()\n}\n\n/**\n * Walks through the children and returns a string representation of the text content.\n *\n * @param node - The children to walk through.\n * @returns String representation of the text content or undefined if there is no text content.\n *\n */\nexport function getChildrenAsLabel(node: ReactNode): string | undefined {\n\tif (typeof node === 'string' || typeof node === 'number') {\n\t\treturn String(node)\n\t} else if (node === null || node === undefined || typeof node === 'boolean') {\n\t\treturn undefined\n\t} else if (Array.isArray(node)) {\n\t\treturn normalize(node.map(getChildrenAsLabel).join(''))\n\t} else {\n\t\tlet label: (string | number)[] = []\n\n\t\tChildren.map(node, child => {\n\t\t\tif (child === null || child === undefined || typeof child === 'boolean') {\n\t\t\t} else if (typeof child === 'string') {\n\t\t\t\tlabel.push(child)\n\t\t\t} else if (typeof child === 'number') {\n\t\t\t\tlabel.push(child)\n\t\t\t} else if (Array.isArray(child)) {\n\t\t\t\tconst childLabel = getChildrenAsLabel(child)\n\n\t\t\t\tif (childLabel) {\n\t\t\t\t\tlabel.push(childLabel)\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\t// ReactElement | JSXElementConstructor | ReactPortal\n\t\t\t\tif ('props' in child && 'children' in child.props) {\n\t\t\t\t\tconst childLabel = getChildrenAsLabel(child.props.children)\n\n\t\t\t\t\tif (childLabel) {\n\t\t\t\t\t\tlabel.push(childLabel)\n\t\t\t\t\t}\n\t\t\t\t} else if ('children' in child) {\n\t\t\t\t\t// ReactPortal\n\t\t\t\t\tconst childLabel = getChildrenAsLabel(child.children)\n\n\t\t\t\t\tif (childLabel) {\n\t\t\t\t\t\tlabel.push(childLabel)\n\t\t\t\t\t}\n\t\t\t\t} else if (import.meta.env.DEV) {\n\t\t\t\t\tconsole.warn('Unsupported child:', child)\n\t\t\t\t}\n\t\t\t}\n\t\t})\n\n\t\treturn label.length > 0 ? label.join('') : undefined\n\t}\n}\n\n/**\n * Walks through the children and returns a string representation of the text content.\n *\n * @param node - The children to walk through.\n * @returns String representation of the text content or undefined if there is no text content.\n *\n */\nexport function useChildrenAsLabel(node: ReactNode): string | undefined {\n\treturn useMemo(() => getChildrenAsLabel(node), [node])\n}\n"],"names":[],"mappings":";AAEA,MAAM,0BAA0B;AAEhC,SAAS,UAAU,MAAsB;AACxC,SAAO,KAAK,QAAQ,yBAAyB,GAAG,EAAE,KAAK;AACxD;AASO,SAAS,mBAAmB,MAAqC;AACvE,MAAI,OAAO,SAAS,YAAY,OAAO,SAAS,UAAU;AACzD,WAAO,OAAO,IAAI;AAAA,EAAA,WACR,SAAS,QAAQ,SAAS,UAAa,OAAO,SAAS,WAAW;AACrE,WAAA;AAAA,EACG,WAAA,MAAM,QAAQ,IAAI,GAAG;AAC/B,WAAO,UAAU,KAAK,IAAI,kBAAkB,EAAE,KAAK,EAAE,CAAC;AAAA,EAAA,OAChD;AACN,QAAI,QAA6B,CAAA;AAExB,aAAA,IAAI,MAAM,CAAS,UAAA;AAC3B,UAAI,UAAU,QAAQ,UAAU,UAAa,OAAO,UAAU;AAAW;AAAA,eAC9D,OAAO,UAAU,UAAU;AACrC,cAAM,KAAK,KAAK;AAAA,MAAA,WACN,OAAO,UAAU,UAAU;AACrC,cAAM,KAAK,KAAK;AAAA,MACN,WAAA,MAAM,QAAQ,KAAK,GAAG;AAC1B,cAAA,aAAa,mBAAmB,KAAK;AAE3C,YAAI,YAAY;AACf,gBAAM,KAAK,UAAU;AAAA,QACtB;AAAA,MAAA,OACM;AAEN,YAAI,WAAW,SAAS,cAAc,MAAM,OAAO;AAClD,gBAAM,aAAa,mBAAmB,MAAM,MAAM,QAAQ;AAE1D,cAAI,YAAY;AACf,kBAAM,KAAK,UAAU;AAAA,UACtB;AAAA,QAAA,WACU,cAAc,OAAO;AAEzB,gBAAA,aAAa,mBAAmB,MAAM,QAAQ;AAEpD,cAAI,YAAY;AACf,kBAAM,KAAK,UAAU;AAAA,UACtB;AAAA,QAAA;
|
|
1
|
+
{"version":3,"file":"useChildrenAsLabel.js","sources":["../../../src/hooks/useChildrenAsLabel.ts"],"sourcesContent":["import { Children, ReactNode, useMemo } from 'react'\n\nconst MULTIPLE_SPACES_REG_EXP = / +/g\n\nfunction normalize(text: string): string {\n\treturn text.replace(MULTIPLE_SPACES_REG_EXP, ' ').trim()\n}\n\n/**\n * Walks through the children and returns a string representation of the text content.\n *\n * @param node - The children to walk through.\n * @returns String representation of the text content or undefined if there is no text content.\n *\n */\nexport function getChildrenAsLabel(node: ReactNode): string | undefined {\n\tif (typeof node === 'string' || typeof node === 'number') {\n\t\treturn String(node)\n\t} else if (node === null || node === undefined || typeof node === 'boolean') {\n\t\treturn undefined\n\t} else if (Array.isArray(node)) {\n\t\treturn normalize(node.map(getChildrenAsLabel).join(''))\n\t} else {\n\t\tlet label: (string | number)[] = []\n\n\t\tChildren.map(node, child => {\n\t\t\tif (child === null || child === undefined || typeof child === 'boolean') {\n\t\t\t} else if (typeof child === 'string') {\n\t\t\t\tlabel.push(child)\n\t\t\t} else if (typeof child === 'number') {\n\t\t\t\tlabel.push(child)\n\t\t\t} else if (Array.isArray(child)) {\n\t\t\t\tconst childLabel = getChildrenAsLabel(child)\n\n\t\t\t\tif (childLabel) {\n\t\t\t\t\tlabel.push(childLabel)\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\t// ReactElement | JSXElementConstructor | ReactPortal\n\t\t\t\tif ('props' in child && 'children' in child.props) {\n\t\t\t\t\tconst childLabel = getChildrenAsLabel(child.props.children)\n\n\t\t\t\t\tif (childLabel) {\n\t\t\t\t\t\tlabel.push(childLabel)\n\t\t\t\t\t}\n\t\t\t\t} else if ('children' in child) {\n\t\t\t\t\t// ReactPortal\n\t\t\t\t\tconst childLabel = getChildrenAsLabel(child.children)\n\n\t\t\t\t\tif (childLabel) {\n\t\t\t\t\t\tlabel.push(childLabel)\n\t\t\t\t\t}\n\t\t\t\t} else if (import.meta.env.DEV) {\n\t\t\t\t\tconsole.warn('Unsupported child:', child)\n\t\t\t\t}\n\t\t\t}\n\t\t})\n\n\t\treturn label.length > 0 ? label.join('') : undefined\n\t}\n}\n\n/**\n * Walks through the children and returns a string representation of the text content.\n *\n * @param node - The children to walk through.\n * @returns String representation of the text content or undefined if there is no text content.\n *\n */\nexport function useChildrenAsLabel(node: ReactNode): string | undefined {\n\treturn useMemo(() => getChildrenAsLabel(node), [node])\n}\n"],"names":[],"mappings":";AAEA,MAAM,0BAA0B;AAEhC,SAAS,UAAU,MAAsB;AACxC,SAAO,KAAK,QAAQ,yBAAyB,GAAG,EAAE,KAAK;AACxD;AASO,SAAS,mBAAmB,MAAqC;AACvE,MAAI,OAAO,SAAS,YAAY,OAAO,SAAS,UAAU;AACzD,WAAO,OAAO,IAAI;AAAA,EAAA,WACR,SAAS,QAAQ,SAAS,UAAa,OAAO,SAAS,WAAW;AACrE,WAAA;AAAA,EACG,WAAA,MAAM,QAAQ,IAAI,GAAG;AAC/B,WAAO,UAAU,KAAK,IAAI,kBAAkB,EAAE,KAAK,EAAE,CAAC;AAAA,EAAA,OAChD;AACN,QAAI,QAA6B,CAAA;AAExB,aAAA,IAAI,MAAM,CAAS,UAAA;AAC3B,UAAI,UAAU,QAAQ,UAAU,UAAa,OAAO,UAAU;AAAW;AAAA,eAC9D,OAAO,UAAU,UAAU;AACrC,cAAM,KAAK,KAAK;AAAA,MAAA,WACN,OAAO,UAAU,UAAU;AACrC,cAAM,KAAK,KAAK;AAAA,MACN,WAAA,MAAM,QAAQ,KAAK,GAAG;AAC1B,cAAA,aAAa,mBAAmB,KAAK;AAE3C,YAAI,YAAY;AACf,gBAAM,KAAK,UAAU;AAAA,QACtB;AAAA,MAAA,OACM;AAEN,YAAI,WAAW,SAAS,cAAc,MAAM,OAAO;AAClD,gBAAM,aAAa,mBAAmB,MAAM,MAAM,QAAQ;AAE1D,cAAI,YAAY;AACf,kBAAM,KAAK,UAAU;AAAA,UACtB;AAAA,QAAA,WACU,cAAc,OAAO;AAEzB,gBAAA,aAAa,mBAAmB,MAAM,QAAQ;AAEpD,cAAI,YAAY;AACf,kBAAM,KAAK,UAAU;AAAA,UACtB;AAAA,QAAA;;MAIF;AAAA,IAAA,CACA;AAED,WAAO,MAAM,SAAS,IAAI,MAAM,KAAK,EAAE,IAAI;AAAA,EAC5C;AACD;AASO,SAAS,mBAAmB,MAAqC;AACvE,SAAO,QAAQ,MAAM,mBAAmB,IAAI,GAAG,CAAC,IAAI,CAAC;AACtD;"}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
|
+
const react = require("react");
|
|
4
|
+
const useCloseOnClickOutside = ({ isOpen, close, contents, outside }) => {
|
|
5
|
+
react.useEffect(() => {
|
|
6
|
+
if (isOpen) {
|
|
7
|
+
const closeOnClickOutside = (event) => {
|
|
8
|
+
const target = event.target;
|
|
9
|
+
if (target instanceof Node && (!document.body.contains(target) || target === document.body || contents.some((it) => it && it.contains(target)))) {
|
|
10
|
+
return;
|
|
11
|
+
}
|
|
12
|
+
if (contents.every((it) => it === null)) {
|
|
13
|
+
return;
|
|
14
|
+
}
|
|
15
|
+
close();
|
|
16
|
+
};
|
|
17
|
+
(outside ?? window).addEventListener("click", closeOnClickOutside);
|
|
18
|
+
return () => {
|
|
19
|
+
(outside ?? window).removeEventListener("click", closeOnClickOutside);
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
}, [close, isOpen, contents, outside]);
|
|
23
|
+
};
|
|
24
|
+
exports.useCloseOnClickOutside = useCloseOnClickOutside;
|
|
25
|
+
//# sourceMappingURL=useCloseOnClickOutside.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useCloseOnClickOutside.cjs","sources":["../../../src/hooks/useCloseOnClickOutside.ts"],"sourcesContent":["import { useEffect } from 'react'\n\nexport const useCloseOnClickOutside = ({ isOpen, close, contents, outside }: { isOpen: boolean, close: () => void, contents: (Node | null)[], outside?: HTMLElement | null }) => {\n\tuseEffect(() => {\n\t\tif (isOpen) {\n\t\t\tconst closeOnClickOutside = (event: Event) => {\n\t\t\t\tconst target = event.target\n\t\t\t\tif (\n\t\t\t\t\ttarget instanceof Node &&\n\t\t\t\t\t(!document.body.contains(target) ||\n\t\t\t\t\t\ttarget === document.body ||\n\t\t\t\t\t\tcontents.some(it => it && it.contains(target)))\n\t\t\t\t) {\n\t\t\t\t\treturn\n\t\t\t\t}\n\t\t\t\tif (contents.every(it => it === null)) {\n\t\t\t\t\treturn\n\t\t\t\t}\n\t\t\t\tclose()\n\t\t\t}\n\t\t\t(outside ?? window).addEventListener('click', closeOnClickOutside)\n\t\t\treturn () => {\n\t\t\t\t(outside ?? window).removeEventListener('click', closeOnClickOutside)\n\t\t\t}\n\t\t}\n\t}, [close, isOpen, contents, outside])\n}\n"],"names":["useEffect"],"mappings":";;;AAEO,MAAM,yBAAyB,CAAC,EAAE,QAAQ,OAAO,UAAU,cAA+G;AAChLA,QAAAA,UAAU,MAAM;AACf,QAAI,QAAQ;AACL,YAAA,sBAAsB,CAAC,UAAiB;AAC7C,cAAM,SAAS,MAAM;AACrB,YACC,kBAAkB,SACjB,CAAC,SAAS,KAAK,SAAS,MAAM,KAC9B,WAAW,SAAS,QACpB,SAAS,KAAK,CAAM,OAAA,MAAM,GAAG,SAAS,MAAM,CAAC,IAC7C;AACD;AAAA,QACD;AACA,YAAI,SAAS,MAAM,CAAM,OAAA,OAAO,IAAI,GAAG;AACtC;AAAA,QACD;AACM;MAAA;AAEP,OAAC,WAAW,QAAQ,iBAAiB,SAAS,mBAAmB;AACjE,aAAO,MAAM;AACZ,SAAC,WAAW,QAAQ,oBAAoB,SAAS,mBAAmB;AAAA,MAAA;AAAA,IAEtE;AAAA,KACE,CAAC,OAAO,QAAQ,UAAU,OAAO,CAAC;AACtC;;"}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { useEffect } from "react";
|
|
2
|
+
const useCloseOnClickOutside = ({ isOpen, close, contents, outside }) => {
|
|
3
|
+
useEffect(() => {
|
|
4
|
+
if (isOpen) {
|
|
5
|
+
const closeOnClickOutside = (event) => {
|
|
6
|
+
const target = event.target;
|
|
7
|
+
if (target instanceof Node && (!document.body.contains(target) || target === document.body || contents.some((it) => it && it.contains(target)))) {
|
|
8
|
+
return;
|
|
9
|
+
}
|
|
10
|
+
if (contents.every((it) => it === null)) {
|
|
11
|
+
return;
|
|
12
|
+
}
|
|
13
|
+
close();
|
|
14
|
+
};
|
|
15
|
+
(outside ?? window).addEventListener("click", closeOnClickOutside);
|
|
16
|
+
return () => {
|
|
17
|
+
(outside ?? window).removeEventListener("click", closeOnClickOutside);
|
|
18
|
+
};
|
|
19
|
+
}
|
|
20
|
+
}, [close, isOpen, contents, outside]);
|
|
21
|
+
};
|
|
22
|
+
export {
|
|
23
|
+
useCloseOnClickOutside
|
|
24
|
+
};
|
|
25
|
+
//# sourceMappingURL=useCloseOnClickOutside.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useCloseOnClickOutside.js","sources":["../../../src/hooks/useCloseOnClickOutside.ts"],"sourcesContent":["import { useEffect } from 'react'\n\nexport const useCloseOnClickOutside = ({ isOpen, close, contents, outside }: { isOpen: boolean, close: () => void, contents: (Node | null)[], outside?: HTMLElement | null }) => {\n\tuseEffect(() => {\n\t\tif (isOpen) {\n\t\t\tconst closeOnClickOutside = (event: Event) => {\n\t\t\t\tconst target = event.target\n\t\t\t\tif (\n\t\t\t\t\ttarget instanceof Node &&\n\t\t\t\t\t(!document.body.contains(target) ||\n\t\t\t\t\t\ttarget === document.body ||\n\t\t\t\t\t\tcontents.some(it => it && it.contains(target)))\n\t\t\t\t) {\n\t\t\t\t\treturn\n\t\t\t\t}\n\t\t\t\tif (contents.every(it => it === null)) {\n\t\t\t\t\treturn\n\t\t\t\t}\n\t\t\t\tclose()\n\t\t\t}\n\t\t\t(outside ?? window).addEventListener('click', closeOnClickOutside)\n\t\t\treturn () => {\n\t\t\t\t(outside ?? window).removeEventListener('click', closeOnClickOutside)\n\t\t\t}\n\t\t}\n\t}, [close, isOpen, contents, outside])\n}\n"],"names":[],"mappings":";AAEO,MAAM,yBAAyB,CAAC,EAAE,QAAQ,OAAO,UAAU,cAA+G;AAChL,YAAU,MAAM;AACf,QAAI,QAAQ;AACL,YAAA,sBAAsB,CAAC,UAAiB;AAC7C,cAAM,SAAS,MAAM;AACrB,YACC,kBAAkB,SACjB,CAAC,SAAS,KAAK,SAAS,MAAM,KAC9B,WAAW,SAAS,QACpB,SAAS,KAAK,CAAM,OAAA,MAAM,GAAG,SAAS,MAAM,CAAC,IAC7C;AACD;AAAA,QACD;AACA,YAAI,SAAS,MAAM,CAAM,OAAA,OAAO,IAAI,GAAG;AACtC;AAAA,QACD;AACM;MAAA;AAEP,OAAC,WAAW,QAAQ,iBAAiB,SAAS,mBAAmB;AACjE,aAAO,MAAM;AACZ,SAAC,WAAW,QAAQ,oBAAoB,SAAS,mBAAmB;AAAA,MAAA;AAAA,IAEtE;AAAA,KACE,CAAC,OAAO,QAAQ,UAAU,OAAO,CAAC;AACtC;"}
|