@aglyn/shared-ui-jsx 1.0.0-beta.143
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/LICENSE +201 -0
- package/README.md +7 -0
- package/package.json +63 -0
- package/src/index.d.ts +48 -0
- package/src/index.js +179 -0
- package/src/index.js.map +1 -0
- package/src/lib/components/aglyn-text.d.ts +86 -0
- package/src/lib/components/aglyn-text.js +44 -0
- package/src/lib/components/aglyn-text.js.map +1 -0
- package/src/lib/components/app-link.d.ts +74 -0
- package/src/lib/components/app-link.js +139 -0
- package/src/lib/components/app-link.js.map +1 -0
- package/src/lib/components/aspect-ratio.d.ts +59 -0
- package/src/lib/components/aspect-ratio.js +153 -0
- package/src/lib/components/aspect-ratio.js.map +1 -0
- package/src/lib/components/background-image.component.d.ts +30 -0
- package/src/lib/components/background-image.component.js +42 -0
- package/src/lib/components/background-image.component.js.map +1 -0
- package/src/lib/components/card-columns.d.ts +86 -0
- package/src/lib/components/card-columns.js +148 -0
- package/src/lib/components/card-columns.js.map +1 -0
- package/src/lib/components/card-display.d.ts +36 -0
- package/src/lib/components/card-display.js +158 -0
- package/src/lib/components/card-display.js.map +1 -0
- package/src/lib/components/card-list-item.d.ts +35 -0
- package/src/lib/components/card-list-item.js +137 -0
- package/src/lib/components/card-list-item.js.map +1 -0
- package/src/lib/components/children-function-prop.d.ts +25 -0
- package/src/lib/components/children-function-prop.js +29 -0
- package/src/lib/components/children-function-prop.js.map +1 -0
- package/src/lib/components/confirmation-provider.component.d.ts +19 -0
- package/src/lib/components/confirmation-provider.component.js +83 -0
- package/src/lib/components/confirmation-provider.component.js.map +1 -0
- package/src/lib/components/container.d.ts +25 -0
- package/src/lib/components/container.js +62 -0
- package/src/lib/components/container.js.map +1 -0
- package/src/lib/components/data-table.component.d.ts +54 -0
- package/src/lib/components/data-table.component.js +211 -0
- package/src/lib/components/data-table.component.js.map +1 -0
- package/src/lib/components/dialog-confirm.d.ts +36 -0
- package/src/lib/components/dialog-confirm.js +74 -0
- package/src/lib/components/dialog-confirm.js.map +1 -0
- package/src/lib/components/ellipsis-pulse.component.d.ts +22 -0
- package/src/lib/components/ellipsis-pulse.component.js +51 -0
- package/src/lib/components/ellipsis-pulse.component.js.map +1 -0
- package/src/lib/components/emotion-cache-provider.d.ts +31 -0
- package/src/lib/components/emotion-cache-provider.js +40 -0
- package/src/lib/components/emotion-cache-provider.js.map +1 -0
- package/src/lib/components/empty-state.component.d.ts +63 -0
- package/src/lib/components/empty-state.component.js +214 -0
- package/src/lib/components/empty-state.component.js.map +1 -0
- package/src/lib/components/error-boundary.component.d.ts +28 -0
- package/src/lib/components/error-boundary.component.js +86 -0
- package/src/lib/components/error-boundary.component.js.map +1 -0
- package/src/lib/components/grid-buttons.d.ts +26 -0
- package/src/lib/components/grid-buttons.js +45 -0
- package/src/lib/components/grid-buttons.js.map +1 -0
- package/src/lib/components/grid-items.d.ts +103 -0
- package/src/lib/components/grid-items.js +336 -0
- package/src/lib/components/grid-items.js.map +1 -0
- package/src/lib/components/grid-list.d.ts +37 -0
- package/src/lib/components/grid-list.js +156 -0
- package/src/lib/components/grid-list.js.map +1 -0
- package/src/lib/components/help-tip.component.d.ts +30 -0
- package/src/lib/components/help-tip.component.js +139 -0
- package/src/lib/components/help-tip.component.js.map +1 -0
- package/src/lib/components/link-navigation-reporter.d.ts +24 -0
- package/src/lib/components/link-navigation-reporter.js +64 -0
- package/src/lib/components/link-navigation-reporter.js.map +1 -0
- package/src/lib/components/list-pagination.component.d.ts +57 -0
- package/src/lib/components/list-pagination.component.js +90 -0
- package/src/lib/components/list-pagination.component.js.map +1 -0
- package/src/lib/components/list-table.component.d.ts +155 -0
- package/src/lib/components/list-table.component.js +369 -0
- package/src/lib/components/list-table.component.js.map +1 -0
- package/src/lib/components/loading-layout-app.component.d.ts +35 -0
- package/src/lib/components/loading-layout-app.component.js +42 -0
- package/src/lib/components/loading-layout-app.component.js.map +1 -0
- package/src/lib/components/loading-modal-overlay.d.ts +30 -0
- package/src/lib/components/loading-modal-overlay.js +156 -0
- package/src/lib/components/loading-modal-overlay.js.map +1 -0
- package/src/lib/components/loading-modal.d.ts +19 -0
- package/src/lib/components/loading-modal.js +113 -0
- package/src/lib/components/loading-modal.js.map +1 -0
- package/src/lib/components/loading-text.component.d.ts +21 -0
- package/src/lib/components/loading-text.component.js +40 -0
- package/src/lib/components/loading-text.component.js.map +1 -0
- package/src/lib/components/mdi-icon/index.d.ts +2 -0
- package/src/lib/components/mdi-icon/index.js +4 -0
- package/src/lib/components/mdi-icon/index.js.map +1 -0
- package/src/lib/components/mdi-icon/md-icon-stack.d.ts +31 -0
- package/src/lib/components/mdi-icon/md-icon-stack.js +101 -0
- package/src/lib/components/mdi-icon/md-icon-stack.js.map +1 -0
- package/src/lib/components/mdi-icon/md-icon.d.ts +32 -0
- package/src/lib/components/mdi-icon/md-icon.js +147 -0
- package/src/lib/components/mdi-icon/md-icon.js.map +1 -0
- package/src/lib/components/mdi-icon/mdi-icon-from-id.d.ts +23 -0
- package/src/lib/components/mdi-icon/mdi-icon-from-id.js +35 -0
- package/src/lib/components/mdi-icon/mdi-icon-from-id.js.map +1 -0
- package/src/lib/components/mdi-icon/mdi-icon.d.ts +24 -0
- package/src/lib/components/mdi-icon/mdi-icon.js +46 -0
- package/src/lib/components/mdi-icon/mdi-icon.js.map +1 -0
- package/src/lib/components/measured-figures.component.d.ts +64 -0
- package/src/lib/components/measured-figures.component.js +161 -0
- package/src/lib/components/measured-figures.component.js.map +1 -0
- package/src/lib/components/menu.d.ts +45 -0
- package/src/lib/components/menu.js +229 -0
- package/src/lib/components/menu.js.map +1 -0
- package/src/lib/components/mui-shadow-dom.d.ts +38 -0
- package/src/lib/components/mui-shadow-dom.js +161 -0
- package/src/lib/components/mui-shadow-dom.js.map +1 -0
- package/src/lib/components/navigation-drawer.component.d.ts +31 -0
- package/src/lib/components/navigation-drawer.component.js +76 -0
- package/src/lib/components/navigation-drawer.component.js.map +1 -0
- package/src/lib/components/navigation-intent.d.ts +18 -0
- package/src/lib/components/navigation-intent.js +56 -0
- package/src/lib/components/navigation-intent.js.map +1 -0
- package/src/lib/components/navigation-view/index.d.ts +18 -0
- package/src/lib/components/navigation-view/index.js +19 -0
- package/src/lib/components/navigation-view/index.js.map +1 -0
- package/src/lib/components/navigation-view/navigation-view.d.ts +35 -0
- package/src/lib/components/navigation-view/navigation-view.js +175 -0
- package/src/lib/components/navigation-view/navigation-view.js.map +1 -0
- package/src/lib/components/next-link.d.ts +27 -0
- package/src/lib/components/next-link.js +88 -0
- package/src/lib/components/next-link.js.map +1 -0
- package/src/lib/components/popper-styled.component.d.ts +25 -0
- package/src/lib/components/popper-styled.component.js +129 -0
- package/src/lib/components/popper-styled.component.js.map +1 -0
- package/src/lib/components/quota-readout.component.d.ts +69 -0
- package/src/lib/components/quota-readout.component.js +52 -0
- package/src/lib/components/quota-readout.component.js.map +1 -0
- package/src/lib/components/resizeable-stack.d.ts +4 -0
- package/src/lib/components/resizeable-stack.js +23 -0
- package/src/lib/components/resizeable-stack.js.map +1 -0
- package/src/lib/components/row-actions-menu.component.d.ts +53 -0
- package/src/lib/components/row-actions-menu.component.js +132 -0
- package/src/lib/components/row-actions-menu.component.js.map +1 -0
- package/src/lib/components/ruler-guides.component.d.ts +35 -0
- package/src/lib/components/ruler-guides.component.js +166 -0
- package/src/lib/components/ruler-guides.component.js.map +1 -0
- package/src/lib/components/sandbox-frame.d.ts +42 -0
- package/src/lib/components/sandbox-frame.js +122 -0
- package/src/lib/components/sandbox-frame.js.map +1 -0
- package/src/lib/components/scroll-reaction.d.ts +59 -0
- package/src/lib/components/scroll-reaction.js +43 -0
- package/src/lib/components/scroll-reaction.js.map +1 -0
- package/src/lib/components/scroll-table.component.d.ts +124 -0
- package/src/lib/components/scroll-table.component.js +103 -0
- package/src/lib/components/scroll-table.component.js.map +1 -0
- package/src/lib/components/shadow-dom/index.d.ts +18 -0
- package/src/lib/components/shadow-dom/index.js +19 -0
- package/src/lib/components/shadow-dom/index.js.map +1 -0
- package/src/lib/components/shadow-dom/shadow-dom.d.ts +42 -0
- package/src/lib/components/shadow-dom/shadow-dom.js +123 -0
- package/src/lib/components/shadow-dom/shadow-dom.js.map +1 -0
- package/src/lib/components/splash-screen.d.ts +33 -0
- package/src/lib/components/splash-screen.js +105 -0
- package/src/lib/components/splash-screen.js.map +1 -0
- package/src/lib/components/sr-only.d.ts +20 -0
- package/src/lib/components/sr-only.js +25 -0
- package/src/lib/components/sr-only.js.map +1 -0
- package/src/lib/components/status-screen-plain.component.d.ts +27 -0
- package/src/lib/components/status-screen-plain.component.js +178 -0
- package/src/lib/components/status-screen-plain.component.js.map +1 -0
- package/src/lib/components/usage-meter.component.d.ts +30 -0
- package/src/lib/components/usage-meter.component.js +92 -0
- package/src/lib/components/usage-meter.component.js.map +1 -0
- package/src/lib/components/variable-text-field.component.d.ts +50 -0
- package/src/lib/components/variable-text-field.component.js +188 -0
- package/src/lib/components/variable-text-field.component.js.map +1 -0
- package/src/lib/components/zoomable-panning-component/index.d.ts +1 -0
- package/src/lib/components/zoomable-panning-component/index.js +3 -0
- package/src/lib/components/zoomable-panning-component/index.js.map +1 -0
- package/src/lib/components/zoomable-panning-component/util.d.ts +58 -0
- package/src/lib/components/zoomable-panning-component/util.js +114 -0
- package/src/lib/components/zoomable-panning-component/util.js.map +1 -0
- package/src/lib/components/zoomable-panning-component/zoomable-panning-component.d.ts +132 -0
- package/src/lib/components/zoomable-panning-component/zoomable-panning-component.js +728 -0
- package/src/lib/components/zoomable-panning-component/zoomable-panning-component.js.map +1 -0
- package/src/lib/const/aglyn-besigner-logo-full.d.ts +39 -0
- package/src/lib/const/aglyn-besigner-logo-full.js +146 -0
- package/src/lib/const/aglyn-besigner-logo-full.js.map +1 -0
- package/src/lib/const/aglyn-console-logo-full.d.ts +34 -0
- package/src/lib/const/aglyn-console-logo-full.js +142 -0
- package/src/lib/const/aglyn-console-logo-full.js.map +1 -0
- package/src/lib/const/aglyn-logo-class-keys.d.ts +30 -0
- package/src/lib/const/aglyn-logo-class-keys.js +32 -0
- package/src/lib/const/aglyn-logo-class-keys.js.map +1 -0
- package/src/lib/const/aglyn-logo-full.d.ts +29 -0
- package/src/lib/const/aglyn-logo-full.js +111 -0
- package/src/lib/const/aglyn-logo-full.js.map +1 -0
- package/src/lib/const/list-filter.d.ts +260 -0
- package/src/lib/const/list-filter.js +409 -0
- package/src/lib/const/list-filter.js.map +1 -0
- package/src/lib/const/prebuilt-components.d.ts +17 -0
- package/src/lib/const/prebuilt-components.js +22 -0
- package/src/lib/const/prebuilt-components.js.map +1 -0
- package/src/lib/const/svg-icons.d.ts +75 -0
- package/src/lib/const/svg-icons.js +313 -0
- package/src/lib/const/svg-icons.js.map +1 -0
- package/src/lib/const/table-pagination.d.ts +106 -0
- package/src/lib/const/table-pagination.js +106 -0
- package/src/lib/const/table-pagination.js.map +1 -0
- package/src/lib/contexts/confirmation.context.d.ts +996 -0
- package/src/lib/contexts/confirmation.context.js +49 -0
- package/src/lib/contexts/confirmation.context.js.map +1 -0
- package/src/lib/contexts/loading.context.d.ts +93 -0
- package/src/lib/contexts/loading.context.js +126 -0
- package/src/lib/contexts/loading.context.js.map +1 -0
- package/src/lib/hocs/create-hoc-with-context-consumer.d.ts +36 -0
- package/src/lib/hocs/create-hoc-with-context-consumer.js +44 -0
- package/src/lib/hocs/create-hoc-with-context-consumer.js.map +1 -0
- package/src/lib/hocs/with-hoc.d.ts +32 -0
- package/src/lib/hocs/with-hoc.js +37 -0
- package/src/lib/hocs/with-hoc.js.map +1 -0
- package/src/lib/hooks/mdi-icon/use-mdi-icon.d.ts +20 -0
- package/src/lib/hooks/mdi-icon/use-mdi-icon.js +48 -0
- package/src/lib/hooks/mdi-icon/use-mdi-icon.js.map +1 -0
- package/src/lib/hooks/mdi-icon/use-mdi-icons-fuzzy.d.ts +26 -0
- package/src/lib/hooks/mdi-icon/use-mdi-icons-fuzzy.js +73 -0
- package/src/lib/hooks/mdi-icon/use-mdi-icons-fuzzy.js.map +1 -0
- package/src/lib/hooks/mdi-icon/use-mdi-icons.d.ts +19 -0
- package/src/lib/hooks/mdi-icon/use-mdi-icons.js +49 -0
- package/src/lib/hooks/mdi-icon/use-mdi-icons.js.map +1 -0
- package/src/lib/hooks/router-events.d.ts +56 -0
- package/src/lib/hooks/router-events.js +88 -0
- package/src/lib/hooks/router-events.js.map +1 -0
- package/src/lib/hooks/use-async-effect.d.ts +24 -0
- package/src/lib/hooks/use-async-effect.js +44 -0
- package/src/lib/hooks/use-async-effect.js.map +1 -0
- package/src/lib/hooks/use-callback-param-ref.d.ts +19 -0
- package/src/lib/hooks/use-callback-param-ref.js +29 -0
- package/src/lib/hooks/use-callback-param-ref.js.map +1 -0
- package/src/lib/hooks/use-id.d.ts +21 -0
- package/src/lib/hooks/use-id.js +28 -0
- package/src/lib/hooks/use-id.js.map +1 -0
- package/src/lib/hooks/use-isomorphic-layout-effect.d.ts +19 -0
- package/src/lib/hooks/use-isomorphic-layout-effect.js +20 -0
- package/src/lib/hooks/use-isomorphic-layout-effect.js.map +1 -0
- package/src/lib/hooks/use-merge-refs.d.ts +38 -0
- package/src/lib/hooks/use-merge-refs.js +52 -0
- package/src/lib/hooks/use-merge-refs.js.map +1 -0
- package/src/lib/hooks/use-subscribable.d.ts +29 -0
- package/src/lib/hooks/use-subscribable.js +50 -0
- package/src/lib/hooks/use-subscribable.js.map +1 -0
- package/src/lib/types.d.ts +18 -0
- package/src/lib/types.js +18 -0
- package/src/lib/types.js.map +1 -0
- package/src/lib/utils/make-link-elements.d.ts +24 -0
- package/src/lib/utils/make-link-elements.js +32 -0
- package/src/lib/utils/make-link-elements.js.map +1 -0
- package/src/lib/utils/make-meta-elements.d.ts +24 -0
- package/src/lib/utils/make-meta-elements.js +32 -0
- package/src/lib/utils/make-meta-elements.js.map +1 -0
- package/src/lib/utils/scroll-overflow.d.ts +120 -0
- package/src/lib/utils/scroll-overflow.js +115 -0
- package/src/lib/utils/scroll-overflow.js.map +1 -0
- package/src/lib/utils/vendor.d.ts +17 -0
- package/src/lib/utils/vendor.js +18 -0
- package/src/lib/utils/vendor.js.map +1 -0
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { _ as _extends } from "@swc/helpers/_/_extends";
|
|
2
|
+
/**
|
|
3
|
+
* @license
|
|
4
|
+
* Copyright 2023 Aglyn LLC
|
|
5
|
+
*
|
|
6
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
7
|
+
* you may not use this file except in compliance with the License.
|
|
8
|
+
* You may obtain a copy of the License at
|
|
9
|
+
*
|
|
10
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
11
|
+
*
|
|
12
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
13
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
14
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
15
|
+
* See the License for the specific language governing permissions and
|
|
16
|
+
* limitations under the License.
|
|
17
|
+
*/ import { noop } from "@aglyn/shared-util-tools";
|
|
18
|
+
import { createContext, useContext } from "react";
|
|
19
|
+
export const DEFAULT_CONTEXT_VALUE = {
|
|
20
|
+
confirm: noop
|
|
21
|
+
};
|
|
22
|
+
export const DEFAULT_CONTEXT_CONFIG = {
|
|
23
|
+
title: 'Are you sure?',
|
|
24
|
+
description: '',
|
|
25
|
+
confirmationText: 'OK',
|
|
26
|
+
cancellationText: 'Cancel',
|
|
27
|
+
dialogProps: {},
|
|
28
|
+
confirmationButtonProps: {},
|
|
29
|
+
cancellationButtonProps: {}
|
|
30
|
+
};
|
|
31
|
+
export const buildConfirmationContextConfig = (defaultConfig, config)=>{
|
|
32
|
+
const dialogProps = _extends({}, defaultConfig.dialogProps || DEFAULT_CONTEXT_CONFIG.dialogProps, config.dialogProps || {});
|
|
33
|
+
const confirmationButtonProps = _extends({}, defaultConfig.confirmationButtonProps || DEFAULT_CONTEXT_CONFIG.confirmationButtonProps, config.confirmationButtonProps || {});
|
|
34
|
+
const cancellationButtonProps = _extends({}, defaultConfig.cancellationButtonProps || DEFAULT_CONTEXT_CONFIG.cancellationButtonProps, config.cancellationButtonProps || {});
|
|
35
|
+
return _extends({}, DEFAULT_CONTEXT_CONFIG, defaultConfig, config, {
|
|
36
|
+
dialogProps,
|
|
37
|
+
confirmationButtonProps,
|
|
38
|
+
cancellationButtonProps
|
|
39
|
+
});
|
|
40
|
+
};
|
|
41
|
+
export const ConfirmationContext = createContext(DEFAULT_CONTEXT_VALUE);
|
|
42
|
+
ConfirmationContext.displayName = 'ConfirmationContext';
|
|
43
|
+
ConfirmationContext.aglyn = true;
|
|
44
|
+
export function useConfirmationContext() {
|
|
45
|
+
return useContext(ConfirmationContext);
|
|
46
|
+
}
|
|
47
|
+
export default ConfirmationContext;
|
|
48
|
+
|
|
49
|
+
//# sourceMappingURL=confirmation.context.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../../../../../libs/shared/ui/jsx/src/lib/contexts/confirmation.context.ts"],"sourcesContent":["/**\n * @license\n * Copyright 2023 Aglyn LLC\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { noop } from '@aglyn/shared-util-tools'\nimport type { ButtonProps, DialogProps } from '@mui/material'\nimport { type Context, createContext, useContext } from 'react'\n\nexport type ConfirmationContextConfig = {\n cancellationText?: JSX.Children\n confirmationText?: JSX.Children\n cancellationButtonProps?: Partial<ButtonProps>\n confirmationButtonProps?: Partial<ButtonProps>\n dialogProps?: Partial<DialogProps>\n title?: JSX.Children\n description?: JSX.Children\n}\nexport type ConfirmFunctionOptions = ConfirmationContextConfig\nexport type ConfirmFunction = <T>(\n options?: ConfirmFunctionOptions,\n) => Promise<T>\nexport type ConfirmationContextType = {\n confirm: ConfirmFunction\n}\nexport type ConfirmationContext = Context<ConfirmationContextType>\n\nexport const DEFAULT_CONTEXT_VALUE: ConfirmationContextType = {\n confirm: noop,\n}\nexport const DEFAULT_CONTEXT_CONFIG: ConfirmationContextConfig = {\n title: 'Are you sure?',\n description: '',\n confirmationText: 'OK',\n cancellationText: 'Cancel',\n dialogProps: {},\n confirmationButtonProps: {},\n cancellationButtonProps: {},\n}\n\nexport const buildConfirmationContextConfig = (defaultConfig: ConfirmationContextConfig, config: ConfirmationContextConfig) => {\n const dialogProps = {\n ...(defaultConfig.dialogProps || DEFAULT_CONTEXT_CONFIG.dialogProps),\n ...(config.dialogProps || {}),\n }\n const confirmationButtonProps = {\n ...(defaultConfig.confirmationButtonProps ||\n DEFAULT_CONTEXT_CONFIG.confirmationButtonProps),\n ...(config.confirmationButtonProps || {}),\n }\n const cancellationButtonProps = {\n ...(defaultConfig.cancellationButtonProps ||\n DEFAULT_CONTEXT_CONFIG.cancellationButtonProps),\n ...(config.cancellationButtonProps || {}),\n }\n\n return {\n ...DEFAULT_CONTEXT_CONFIG,\n ...defaultConfig,\n ...config,\n dialogProps,\n confirmationButtonProps,\n cancellationButtonProps,\n }\n}\n\nexport const ConfirmationContext: ConfirmationContext =\n createContext<ConfirmationContextType>(DEFAULT_CONTEXT_VALUE)\nConfirmationContext.displayName = 'ConfirmationContext'\nConfirmationContext.aglyn = true\n\nexport function useConfirmationContext(): ConfirmationContextType {\n return useContext(ConfirmationContext)\n}\n\nexport default ConfirmationContext\n"],"names":["noop","createContext","useContext","DEFAULT_CONTEXT_VALUE","confirm","DEFAULT_CONTEXT_CONFIG","title","description","confirmationText","cancellationText","dialogProps","confirmationButtonProps","cancellationButtonProps","buildConfirmationContextConfig","defaultConfig","config","ConfirmationContext","displayName","aglyn","useConfirmationContext"],"mappings":";AAAA;;;;;;;;;;;;;;;CAeC,GAED,SAASA,IAAI,QAAQ,2BAA0B;AAE/C,SAAuBC,aAAa,EAAEC,UAAU,QAAQ,QAAO;AAoB/D,OAAO,MAAMC,wBAAiD;IAC5DC,SAASJ;AACX,EAAC;AACD,OAAO,MAAMK,yBAAoD;IAC/DC,OAAO;IACPC,aAAa;IACbC,kBAAkB;IAClBC,kBAAkB;IAClBC,aAAa,CAAC;IACdC,yBAAyB,CAAC;IAC1BC,yBAAyB,CAAC;AAC5B,EAAC;AAED,OAAO,MAAMC,iCAAiC,CAACC,eAA0CC;IACvF,MAAML,cAAc,aACdI,cAAcJ,WAAW,IAAIL,uBAAuBK,WAAW,EAC/DK,OAAOL,WAAW,IAAI,CAAC;IAE7B,MAAMC,0BAA0B,aAC1BG,cAAcH,uBAAuB,IACvCN,uBAAuBM,uBAAuB,EAC5CI,OAAOJ,uBAAuB,IAAI,CAAC;IAEzC,MAAMC,0BAA0B,aAC1BE,cAAcF,uBAAuB,IACvCP,uBAAuBO,uBAAuB,EAC5CG,OAAOH,uBAAuB,IAAI,CAAC;IAGzC,OAAO,aACFP,wBACAS,eACAC;QACHL;QACAC;QACAC;;AAEJ,EAAC;AAED,OAAO,MAAMI,sBACXf,cAAuCE,uBAAsB;AAC/Da,oBAAoBC,WAAW,GAAG;AAClCD,oBAAoBE,KAAK,GAAG;AAE5B,OAAO,SAASC;IACd,OAAOjB,WAAWc;AACpB;AAEA,eAAeA,oBAAmB"}
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Copyright 2023 Aglyn LLC
|
|
4
|
+
*
|
|
5
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
6
|
+
* you may not use this file except in compliance with the License.
|
|
7
|
+
* You may obtain a copy of the License at
|
|
8
|
+
*
|
|
9
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
10
|
+
*
|
|
11
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
12
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
13
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
14
|
+
* See the License for the specific language governing permissions and
|
|
15
|
+
* limitations under the License.
|
|
16
|
+
*/
|
|
17
|
+
import { ContextType } from 'react';
|
|
18
|
+
import { type InjectedContextConsumerProps } from '../hocs/create-hoc-with-context-consumer';
|
|
19
|
+
export type QueueId = string;
|
|
20
|
+
export type Queues = QueueId[];
|
|
21
|
+
export type TupledDequeue = [QueueId, DequeueLoading];
|
|
22
|
+
export type QueueResponse<T extends boolean> = ConditionalNonDist<T, true, TupledDequeue, DequeueLoading>;
|
|
23
|
+
export interface LoadingHelper {
|
|
24
|
+
enqueue<T extends boolean = false>(asTuple?: T): QueueResponse<T>;
|
|
25
|
+
dequeue(queueId?: QueueId): void;
|
|
26
|
+
dequeueAll(): void;
|
|
27
|
+
check(queueId?: QueueId): boolean;
|
|
28
|
+
}
|
|
29
|
+
export type EnqueueLoading = LoadingHelper['enqueue'];
|
|
30
|
+
export type DequeueLoading = LoadingHelper['dequeue'];
|
|
31
|
+
export type DequeueAllLoading = LoadingHelper['dequeueAll'];
|
|
32
|
+
export type CheckLoading = LoadingHelper['check'];
|
|
33
|
+
export type EnqueueResponse = {
|
|
34
|
+
(): LoadingManager;
|
|
35
|
+
readonly queueId: QueueId;
|
|
36
|
+
};
|
|
37
|
+
export declare class LoaderItem {
|
|
38
|
+
readonly id: QueueId;
|
|
39
|
+
private readonly manager;
|
|
40
|
+
loading(): boolean;
|
|
41
|
+
constructor(id: QueueId, manager: LoadingManager);
|
|
42
|
+
dequeue(): this;
|
|
43
|
+
}
|
|
44
|
+
export declare class LoadingManager {
|
|
45
|
+
queues: Map<QueueId, LoaderItem>;
|
|
46
|
+
get loading(): boolean;
|
|
47
|
+
constructor();
|
|
48
|
+
check: (id: QueueId) => boolean;
|
|
49
|
+
static createQueueId(): string;
|
|
50
|
+
enqueue(): LoaderItem;
|
|
51
|
+
dequeue(id: QueueId): this;
|
|
52
|
+
}
|
|
53
|
+
export declare const LoadingContext: import("react").Context<{
|
|
54
|
+
loading: boolean;
|
|
55
|
+
queueLoading: EnqueueLoading;
|
|
56
|
+
dequeueLoading: DequeueLoading;
|
|
57
|
+
dequeueAllLoading: DequeueAllLoading;
|
|
58
|
+
checkLoading: CheckLoading;
|
|
59
|
+
}>;
|
|
60
|
+
export type LoadingContextType = ContextType<typeof LoadingContext>;
|
|
61
|
+
export declare const LoadingConsumer: import("react").Consumer<{
|
|
62
|
+
loading: boolean;
|
|
63
|
+
queueLoading: EnqueueLoading;
|
|
64
|
+
dequeueLoading: DequeueLoading;
|
|
65
|
+
dequeueAllLoading: DequeueAllLoading;
|
|
66
|
+
checkLoading: CheckLoading;
|
|
67
|
+
}>;
|
|
68
|
+
export declare const useLoading: () => {
|
|
69
|
+
loading: boolean;
|
|
70
|
+
queueLoading: EnqueueLoading;
|
|
71
|
+
dequeueLoading: DequeueLoading;
|
|
72
|
+
dequeueAllLoading: DequeueAllLoading;
|
|
73
|
+
checkLoading: CheckLoading;
|
|
74
|
+
};
|
|
75
|
+
export interface LoadingProviderProps {
|
|
76
|
+
children?: JSX.Children;
|
|
77
|
+
}
|
|
78
|
+
export declare function LoadingProviderComponent(props: LoadingProviderProps): import("react").JSX.Element;
|
|
79
|
+
declare const WithN = "_contextLoading";
|
|
80
|
+
type WithN = typeof WithN;
|
|
81
|
+
export type LoadingConsumer = typeof LoadingConsumer;
|
|
82
|
+
export type WithInjectedLoadingContextProps = InjectedContextConsumerProps<typeof LoadingContext.Consumer, WithN>;
|
|
83
|
+
/**
|
|
84
|
+
* App loading context HOC prop injector
|
|
85
|
+
*/
|
|
86
|
+
export declare const withInjectedLoadingContext: import("../..").WithContextConsumer<{
|
|
87
|
+
loading: boolean;
|
|
88
|
+
queueLoading: EnqueueLoading;
|
|
89
|
+
dequeueLoading: DequeueLoading;
|
|
90
|
+
dequeueAllLoading: DequeueAllLoading;
|
|
91
|
+
checkLoading: CheckLoading;
|
|
92
|
+
}, "_contextLoading">;
|
|
93
|
+
export {};
|
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
import { _ as _extends } from "@swc/helpers/_/_extends";
|
|
2
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
3
|
+
/**
|
|
4
|
+
* @license
|
|
5
|
+
* Copyright 2023 Aglyn LLC
|
|
6
|
+
*
|
|
7
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
8
|
+
* you may not use this file except in compliance with the License.
|
|
9
|
+
* You may obtain a copy of the License at
|
|
10
|
+
*
|
|
11
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
12
|
+
*
|
|
13
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
14
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
15
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
16
|
+
* See the License for the specific language governing permissions and
|
|
17
|
+
* limitations under the License.
|
|
18
|
+
*/ import { noop } from "@aglyn/shared-util-tools";
|
|
19
|
+
import { createUid } from "@aglyn/shared-util-vendor";
|
|
20
|
+
import { makeAutoObservable } from "mobx";
|
|
21
|
+
// The leaf module, not the 68 KB package bundle — see the note there.
|
|
22
|
+
import { computedFn } from "@aglyn/shared-util-vendor/mobx-computed-fn";
|
|
23
|
+
import { createContext, useContext, useRef, useState } from "react";
|
|
24
|
+
import { createHocWithContextConsumer } from "../hocs/create-hoc-with-context-consumer.js";
|
|
25
|
+
export class LoaderItem {
|
|
26
|
+
loading() {
|
|
27
|
+
return this.manager.queues.has(this.id);
|
|
28
|
+
}
|
|
29
|
+
dequeue() {
|
|
30
|
+
this.manager.dequeue(this.id);
|
|
31
|
+
return this;
|
|
32
|
+
}
|
|
33
|
+
constructor(id, manager){
|
|
34
|
+
this.id = id;
|
|
35
|
+
this.manager = manager;
|
|
36
|
+
makeAutoObservable(this);
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
export class LoadingManager {
|
|
40
|
+
get loading() {
|
|
41
|
+
return this.queues.size > 0;
|
|
42
|
+
}
|
|
43
|
+
static createQueueId() {
|
|
44
|
+
return createUid();
|
|
45
|
+
}
|
|
46
|
+
enqueue() {
|
|
47
|
+
const id = LoadingManager.createQueueId();
|
|
48
|
+
const loader = new LoaderItem(id, this);
|
|
49
|
+
this.queues.set(id, new LoaderItem(id, this));
|
|
50
|
+
return loader;
|
|
51
|
+
}
|
|
52
|
+
dequeue(id) {
|
|
53
|
+
if (this.queues.has(id)) {
|
|
54
|
+
this.queues.delete(id);
|
|
55
|
+
} else {
|
|
56
|
+
console.error('Invalid loading queue ID', id);
|
|
57
|
+
}
|
|
58
|
+
return this;
|
|
59
|
+
}
|
|
60
|
+
constructor(){
|
|
61
|
+
this.queues = new Map();
|
|
62
|
+
this.check = computedFn((id)=>{
|
|
63
|
+
return this.queues.has(id);
|
|
64
|
+
});
|
|
65
|
+
makeAutoObservable(this);
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
export const LoadingContext = /*#__PURE__*/ createContext({
|
|
69
|
+
loading: false,
|
|
70
|
+
queueLoading: noop,
|
|
71
|
+
dequeueLoading: noop,
|
|
72
|
+
dequeueAllLoading: noop,
|
|
73
|
+
checkLoading: noop
|
|
74
|
+
});
|
|
75
|
+
LoadingContext.displayName = 'LoadingContext';
|
|
76
|
+
export const { Consumer: LoadingConsumer } = LoadingContext;
|
|
77
|
+
const createQueueId = ()=>{
|
|
78
|
+
return createUid();
|
|
79
|
+
};
|
|
80
|
+
export const useLoading = ()=>{
|
|
81
|
+
return useContext(LoadingContext);
|
|
82
|
+
};
|
|
83
|
+
export function LoadingProviderComponent(props) {
|
|
84
|
+
const { children } = props;
|
|
85
|
+
const localRef = useRef([]);
|
|
86
|
+
const [state, setState] = useState(()=>({
|
|
87
|
+
loading: false,
|
|
88
|
+
queueLoading: (asTuple)=>{
|
|
89
|
+
const queueId = createQueueId();
|
|
90
|
+
const dequeue = ()=>state.dequeueLoading(queueId);
|
|
91
|
+
localRef.current.push(queueId);
|
|
92
|
+
setState((prev)=>_extends({}, prev, {
|
|
93
|
+
loading: true
|
|
94
|
+
}));
|
|
95
|
+
return asTuple === true ? [
|
|
96
|
+
queueId,
|
|
97
|
+
dequeue
|
|
98
|
+
] : dequeue;
|
|
99
|
+
},
|
|
100
|
+
dequeueLoading: (queueId)=>{
|
|
101
|
+
localRef.current = localRef.current.filter((i)=>i !== queueId);
|
|
102
|
+
setState((prev)=>_extends({}, prev, {
|
|
103
|
+
loading: state.checkLoading()
|
|
104
|
+
}));
|
|
105
|
+
},
|
|
106
|
+
dequeueAllLoading: ()=>{
|
|
107
|
+
localRef.current = [];
|
|
108
|
+
},
|
|
109
|
+
checkLoading: (queueId)=>{
|
|
110
|
+
if (queueId) {
|
|
111
|
+
return localRef.current.indexOf(queueId) >= 0;
|
|
112
|
+
}
|
|
113
|
+
return localRef.current.length > 0;
|
|
114
|
+
}
|
|
115
|
+
}));
|
|
116
|
+
return /*#__PURE__*/ _jsx(LoadingContext.Provider, {
|
|
117
|
+
value: state,
|
|
118
|
+
children: children
|
|
119
|
+
});
|
|
120
|
+
}
|
|
121
|
+
const WithN = '_contextLoading';
|
|
122
|
+
/**
|
|
123
|
+
* App loading context HOC prop injector
|
|
124
|
+
*/ export const withInjectedLoadingContext = createHocWithContextConsumer(LoadingContext.Consumer, WithN);
|
|
125
|
+
|
|
126
|
+
//# sourceMappingURL=loading.context.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../../../../../libs/shared/ui/jsx/src/lib/contexts/loading.context.tsx"],"sourcesContent":["/**\n * @license\n * Copyright 2023 Aglyn LLC\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { noop } from '@aglyn/shared-util-tools'\nimport { createUid } from '@aglyn/shared-util-vendor'\nimport { makeAutoObservable } from 'mobx'\n// The leaf module, not the 68 KB package bundle — see the note there.\nimport { computedFn } from '@aglyn/shared-util-vendor/mobx-computed-fn'\nimport { ContextType, createContext, useContext, useRef, useState } from 'react'\nimport {\n createHocWithContextConsumer,\n type InjectedContextConsumerProps,\n} from '../hocs/create-hoc-with-context-consumer'\n\nexport type QueueId = string\nexport type Queues = QueueId[]\nexport type TupledDequeue = [QueueId, DequeueLoading]\nexport type QueueResponse<T extends boolean> = ConditionalNonDist<\n T,\n true,\n TupledDequeue,\n DequeueLoading\n>\n\nexport interface LoadingHelper {\n enqueue<T extends boolean = false>(asTuple?: T): QueueResponse<T>\n dequeue(queueId?: QueueId): void\n dequeueAll(): void\n check(queueId?: QueueId): boolean\n}\n\nexport type EnqueueLoading = LoadingHelper['enqueue']\nexport type DequeueLoading = LoadingHelper['dequeue']\nexport type DequeueAllLoading = LoadingHelper['dequeueAll']\nexport type CheckLoading = LoadingHelper['check']\n\nexport type EnqueueResponse = {\n (): LoadingManager\n readonly queueId: QueueId\n}\n\nexport class LoaderItem {\n public loading(): boolean {\n return this.manager.queues.has(this.id)\n }\n\n constructor(\n public readonly id: QueueId,\n private readonly manager: LoadingManager,\n ) {\n makeAutoObservable(this)\n }\n\n public dequeue() {\n this.manager.dequeue(this.id)\n return this\n }\n}\n\nexport class LoadingManager {\n public queues: Map<QueueId, LoaderItem> = new Map()\n\n public get loading(): boolean {\n return this.queues.size > 0\n }\n\n constructor() {\n makeAutoObservable(this)\n }\n\n public check = computedFn((id: QueueId) => {\n return this.queues.has(id)\n })\n\n public static createQueueId() {\n return createUid()\n }\n\n public enqueue(): LoaderItem {\n const id = LoadingManager.createQueueId()\n const loader = new LoaderItem(id, this)\n this.queues.set(id, new LoaderItem(id, this))\n return loader\n }\n\n public dequeue(id: QueueId): this {\n if (this.queues.has(id)) {\n this.queues.delete(id)\n } else {\n console.error('Invalid loading queue ID', id)\n }\n return this\n }\n}\n\nexport const LoadingContext = createContext({\n loading: false,\n queueLoading: noop as EnqueueLoading,\n dequeueLoading: noop as DequeueLoading,\n dequeueAllLoading: noop as DequeueAllLoading,\n checkLoading: noop as CheckLoading,\n})\nLoadingContext.displayName = 'LoadingContext'\n\nexport type LoadingContextType = ContextType<typeof LoadingContext>\n\nexport const { Consumer: LoadingConsumer } = LoadingContext\n\nconst createQueueId = () => {\n return createUid()\n}\n\nexport const useLoading = () => {\n return useContext(LoadingContext)\n}\n\nexport interface LoadingProviderProps {\n children?: JSX.Children\n}\n\nexport function LoadingProviderComponent(props: LoadingProviderProps) {\n const { children } = props\n const localRef = useRef<Queues>([])\n const [state, setState] = useState<LoadingContextType>(() => ({\n loading: false,\n queueLoading: <T extends boolean>(asTuple?: T): QueueResponse<T> => {\n const queueId = createQueueId()\n const dequeue: DequeueLoading = () => state.dequeueLoading(queueId)\n localRef.current.push(queueId)\n setState((prev) => ({ ...prev, loading: true }))\n return (\n asTuple === true ? [queueId, dequeue] : dequeue\n ) as QueueResponse<T>\n },\n dequeueLoading: (queueId?: QueueId) => {\n localRef.current = localRef.current.filter((i) => i !== queueId)\n setState((prev) => ({ ...prev, loading: state.checkLoading() }))\n },\n dequeueAllLoading: () => {\n localRef.current = []\n },\n checkLoading: (queueId?: QueueId) => {\n if (queueId) {\n return localRef.current.indexOf(queueId) >= 0\n }\n return localRef.current.length > 0\n },\n }))\n\n return (\n <LoadingContext.Provider value={state}>{children}</LoadingContext.Provider>\n )\n}\n\nconst WithN = '_contextLoading'\ntype WithN = typeof WithN\nexport type LoadingConsumer = typeof LoadingConsumer\nexport type WithInjectedLoadingContextProps = InjectedContextConsumerProps<\n typeof LoadingContext.Consumer,\n WithN\n>\n\n/**\n * App loading context HOC prop injector\n */\nexport const withInjectedLoadingContext = createHocWithContextConsumer(\n LoadingContext.Consumer,\n WithN,\n)\n"],"names":["noop","createUid","makeAutoObservable","computedFn","createContext","useContext","useRef","useState","createHocWithContextConsumer","LoaderItem","loading","manager","queues","has","id","dequeue","LoadingManager","size","createQueueId","enqueue","loader","set","delete","console","error","Map","check","LoadingContext","queueLoading","dequeueLoading","dequeueAllLoading","checkLoading","displayName","Consumer","LoadingConsumer","useLoading","LoadingProviderComponent","props","children","localRef","state","setState","asTuple","queueId","current","push","prev","filter","i","indexOf","length","Provider","value","WithN","withInjectedLoadingContext"],"mappings":";;AAAA;;;;;;;;;;;;;;;CAeC,GAED,SAASA,IAAI,QAAQ,2BAA0B;AAC/C,SAASC,SAAS,QAAQ,4BAA2B;AACrD,SAASC,kBAAkB,QAAQ,OAAM;AACzC,sEAAsE;AACtE,SAASC,UAAU,QAAQ,6CAA4C;AACvE,SAAsBC,aAAa,EAAEC,UAAU,EAAEC,MAAM,EAAEC,QAAQ,QAAQ,QAAO;AAChF,SACEC,4BAA4B,QAEvB,8CAA0C;AA6BjD,OAAO,MAAMC;IACJC,UAAmB;QACxB,OAAO,IAAI,CAACC,OAAO,CAACC,MAAM,CAACC,GAAG,CAAC,IAAI,CAACC,EAAE;IACxC;IASOC,UAAU;QACf,IAAI,CAACJ,OAAO,CAACI,OAAO,CAAC,IAAI,CAACD,EAAE;QAC5B,OAAO,IAAI;IACb;IAVA,YACE,AAAgBA,EAAW,EAC3B,AAAiBH,OAAuB,CACxC;aAFgBG,KAAAA;aACCH,UAAAA;QAEjBT,mBAAmB,IAAI;IACzB;AAMF;AAEA,OAAO,MAAMc;IAGX,IAAWN,UAAmB;QAC5B,OAAO,IAAI,CAACE,MAAM,CAACK,IAAI,GAAG;IAC5B;IAUA,OAAcC,gBAAgB;QAC5B,OAAOjB;IACT;IAEOkB,UAAsB;QAC3B,MAAML,KAAKE,eAAeE,aAAa;QACvC,MAAME,SAAS,IAAIX,WAAWK,IAAI,IAAI;QACtC,IAAI,CAACF,MAAM,CAACS,GAAG,CAACP,IAAI,IAAIL,WAAWK,IAAI,IAAI;QAC3C,OAAOM;IACT;IAEOL,QAAQD,EAAW,EAAQ;QAChC,IAAI,IAAI,CAACF,MAAM,CAACC,GAAG,CAACC,KAAK;YACvB,IAAI,CAACF,MAAM,CAACU,MAAM,CAACR;QACrB,OAAO;YACLS,QAAQC,KAAK,CAAC,4BAA4BV;QAC5C;QACA,OAAO,IAAI;IACb;IA1BA,aAAc;aANPF,SAAmC,IAAIa;aAUvCC,QAAQvB,WAAW,CAACW;YACzB,OAAO,IAAI,CAACF,MAAM,CAACC,GAAG,CAACC;QACzB;QALEZ,mBAAmB,IAAI;IACzB;AAyBF;AAEA,OAAO,MAAMyB,+BAAiBvB,cAAc;IAC1CM,SAAS;IACTkB,cAAc5B;IACd6B,gBAAgB7B;IAChB8B,mBAAmB9B;IACnB+B,cAAc/B;AAChB,GAAE;AACF2B,eAAeK,WAAW,GAAG;AAI7B,OAAO,MAAM,EAAEC,UAAUC,eAAe,EAAE,GAAGP,eAAc;AAE3D,MAAMT,gBAAgB;IACpB,OAAOjB;AACT;AAEA,OAAO,MAAMkC,aAAa;IACxB,OAAO9B,WAAWsB;AACpB,EAAC;AAMD,OAAO,SAASS,yBAAyBC,KAA2B;IAClE,MAAM,EAAEC,QAAQ,EAAE,GAAGD;IACrB,MAAME,WAAWjC,OAAe,EAAE;IAClC,MAAM,CAACkC,OAAOC,SAAS,GAAGlC,SAA6B,IAAO,CAAA;YAC5DG,SAAS;YACTkB,cAAc,CAAoBc;gBAChC,MAAMC,UAAUzB;gBAChB,MAAMH,UAA0B,IAAMyB,MAAMX,cAAc,CAACc;gBAC3DJ,SAASK,OAAO,CAACC,IAAI,CAACF;gBACtBF,SAAS,CAACK,OAAU,aAAKA;wBAAMpC,SAAS;;gBACxC,OACEgC,YAAY,OAAO;oBAACC;oBAAS5B;iBAAQ,GAAGA;YAE5C;YACAc,gBAAgB,CAACc;gBACfJ,SAASK,OAAO,GAAGL,SAASK,OAAO,CAACG,MAAM,CAAC,CAACC,IAAMA,MAAML;gBACxDF,SAAS,CAACK,OAAU,aAAKA;wBAAMpC,SAAS8B,MAAMT,YAAY;;YAC5D;YACAD,mBAAmB;gBACjBS,SAASK,OAAO,GAAG,EAAE;YACvB;YACAb,cAAc,CAACY;gBACb,IAAIA,SAAS;oBACX,OAAOJ,SAASK,OAAO,CAACK,OAAO,CAACN,YAAY;gBAC9C;gBACA,OAAOJ,SAASK,OAAO,CAACM,MAAM,GAAG;YACnC;QACF,CAAA;IAEA,qBACE,KAACvB,eAAewB,QAAQ;QAACC,OAAOZ;kBAAQF;;AAE5C;AAEA,MAAMe,QAAQ;AAQd;;CAEC,GACD,OAAO,MAAMC,6BAA6B9C,6BACxCmB,eAAeM,QAAQ,EACvBoB,OACD"}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Copyright 2022 Aglyn LLC
|
|
4
|
+
*
|
|
5
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
6
|
+
* you may not use this file except in compliance with the License.
|
|
7
|
+
* You may obtain a copy of the License at
|
|
8
|
+
*
|
|
9
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
10
|
+
*
|
|
11
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
12
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
13
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
14
|
+
* See the License for the specific language governing permissions and
|
|
15
|
+
* limitations under the License.
|
|
16
|
+
*/
|
|
17
|
+
import { ComponentType, Consumer, ForwardRefExoticComponent } from 'react';
|
|
18
|
+
export declare const DEFAULT_INJECTED_PROP_NAME = "ctx";
|
|
19
|
+
export type DEFAULT_INJECTED_PROP_NAME = typeof DEFAULT_INJECTED_PROP_NAME;
|
|
20
|
+
/**
|
|
21
|
+
* Infer the context type from the consumer
|
|
22
|
+
*/
|
|
23
|
+
export type ConsumerContextType<C extends Consumer<any>> = C extends Consumer<infer T> ? T : never;
|
|
24
|
+
/** The context props to inject into the component */
|
|
25
|
+
export type InjectedContextConsumerProps<C extends Consumer<any>, NM extends string = DEFAULT_INJECTED_PROP_NAME> = {
|
|
26
|
+
[K in NM]: ConsumerContextType<C>;
|
|
27
|
+
};
|
|
28
|
+
/** A react component awaiting decoration of injected prop */
|
|
29
|
+
export type ComponentWithInjectedProp<P, CTX_C extends Consumer<any>, InjectedProp extends string = DEFAULT_INJECTED_PROP_NAME> = ComponentType<P & InjectedContextConsumerProps<CTX_C, InjectedProp>>;
|
|
30
|
+
export interface WithContextConsumer<T, Key extends string = 'ctx'> {
|
|
31
|
+
<P>(component: ComponentType<P & Record<Key, T>>): ForwardRefExoticComponent<Omit<P, Key>>;
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Helper util to HOC a context consumer
|
|
35
|
+
*/
|
|
36
|
+
export declare function createHocWithContextConsumer<T, K extends string = 'ctx'>(Consumer: Consumer<T>, prop?: K): WithContextConsumer<T, K>;
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { _ as _extends } from "@swc/helpers/_/_extends";
|
|
2
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
3
|
+
/**
|
|
4
|
+
* @license
|
|
5
|
+
* Copyright 2022 Aglyn LLC
|
|
6
|
+
*
|
|
7
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
8
|
+
* you may not use this file except in compliance with the License.
|
|
9
|
+
* You may obtain a copy of the License at
|
|
10
|
+
*
|
|
11
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
12
|
+
*
|
|
13
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
14
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
15
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
16
|
+
* See the License for the specific language governing permissions and
|
|
17
|
+
* limitations under the License.
|
|
18
|
+
*/ import { getDisplayName } from "@aglyn/shared-util-tools";
|
|
19
|
+
import { hoistNonReactStatics } from "@aglyn/shared-util-vendor";
|
|
20
|
+
import { forwardRef } from "react";
|
|
21
|
+
export const DEFAULT_INJECTED_PROP_NAME = 'ctx';
|
|
22
|
+
/**
|
|
23
|
+
* Helper util to HOC a context consumer
|
|
24
|
+
*/ export function createHocWithContextConsumer(Consumer, prop) {
|
|
25
|
+
const injectedPropName = prop || DEFAULT_INJECTED_PROP_NAME;
|
|
26
|
+
function withContextConsumer(Component) {
|
|
27
|
+
const displayName = getDisplayName(Component);
|
|
28
|
+
const DecoratedComponent = /*#__PURE__*/ forwardRef((props, ref)=>{
|
|
29
|
+
return /*#__PURE__*/ _jsx(Consumer, {
|
|
30
|
+
children: (ctx)=>/*#__PURE__*/ _jsx(Component, _extends({
|
|
31
|
+
ref: ref
|
|
32
|
+
}, {
|
|
33
|
+
[injectedPropName]: ctx
|
|
34
|
+
}, props))
|
|
35
|
+
});
|
|
36
|
+
});
|
|
37
|
+
DecoratedComponent.displayName = `WithContext(${displayName})`;
|
|
38
|
+
hoistNonReactStatics(DecoratedComponent, Component);
|
|
39
|
+
return DecoratedComponent;
|
|
40
|
+
}
|
|
41
|
+
return withContextConsumer;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
//# sourceMappingURL=create-hoc-with-context-consumer.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../../../../../libs/shared/ui/jsx/src/lib/hocs/create-hoc-with-context-consumer.tsx"],"sourcesContent":["/**\n * @license\n * Copyright 2022 Aglyn LLC\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { getDisplayName } from '@aglyn/shared-util-tools'\nimport { hoistNonReactStatics } from '@aglyn/shared-util-vendor'\nimport {\n ComponentType,\n Consumer,\n forwardRef,\n ForwardRefExoticComponent,\n} from 'react'\n\nexport const DEFAULT_INJECTED_PROP_NAME = 'ctx'\nexport type DEFAULT_INJECTED_PROP_NAME = typeof DEFAULT_INJECTED_PROP_NAME\n\n/**\n * Infer the context type from the consumer\n */\nexport type ConsumerContextType<C extends Consumer<any>> = C extends Consumer<\n infer T\n>\n ? T\n : never\n\n/** The context props to inject into the component */\nexport type InjectedContextConsumerProps<\n C extends Consumer<any>,\n NM extends string = DEFAULT_INJECTED_PROP_NAME,\n> = {\n [K in NM]: ConsumerContextType<C>\n}\n\n/** A react component awaiting decoration of injected prop */\nexport type ComponentWithInjectedProp<\n P,\n CTX_C extends Consumer<any>,\n InjectedProp extends string = DEFAULT_INJECTED_PROP_NAME,\n> = ComponentType<P & InjectedContextConsumerProps<CTX_C, InjectedProp>>\n\nexport interface WithContextConsumer<T, Key extends string = 'ctx'> {\n <P>(\n component: ComponentType<P & Record<Key, T>>,\n ): ForwardRefExoticComponent<Omit<P, Key>>\n}\n\n/**\n * Helper util to HOC a context consumer\n */\nexport function createHocWithContextConsumer<T, K extends string = 'ctx'>(\n Consumer: Consumer<T>,\n prop?: K,\n): WithContextConsumer<T, K> {\n const injectedPropName = prop || DEFAULT_INJECTED_PROP_NAME\n\n function withContextConsumer<P>(\n Component: ComponentType<P & Record<K, T>>,\n ): ForwardRefExoticComponent<Omit<P, K>> {\n const displayName = getDisplayName(Component)\n\n const DecoratedComponent = forwardRef<any, P>((props, ref) => {\n return (\n <Consumer>\n {(ctx) => (\n <Component\n ref={ref}\n {...({ [injectedPropName]: ctx } as Record<K, T>)}\n {...(props as P)}\n />\n )}\n </Consumer>\n )\n })\n\n DecoratedComponent.displayName = `WithContext(${displayName})`\n hoistNonReactStatics(DecoratedComponent, Component)\n return DecoratedComponent as ForwardRefExoticComponent<Omit<P, K>>\n }\n\n return withContextConsumer\n}\n"],"names":["getDisplayName","hoistNonReactStatics","forwardRef","DEFAULT_INJECTED_PROP_NAME","createHocWithContextConsumer","Consumer","prop","injectedPropName","withContextConsumer","Component","displayName","DecoratedComponent","props","ref","ctx"],"mappings":";;AAAA;;;;;;;;;;;;;;;CAeC,GAED,SAASA,cAAc,QAAQ,2BAA0B;AACzD,SAASC,oBAAoB,QAAQ,4BAA2B;AAChE,SAGEC,UAAU,QAEL,QAAO;AAEd,OAAO,MAAMC,6BAA6B,MAAK;AAiC/C;;CAEC,GACD,OAAO,SAASC,6BACdC,QAAqB,EACrBC,IAAQ;IAER,MAAMC,mBAAmBD,QAAQH;IAEjC,SAASK,oBACPC,SAA0C;QAE1C,MAAMC,cAAcV,eAAeS;QAEnC,MAAME,mCAAqBT,WAAmB,CAACU,OAAOC;YACpD,qBACE,KAACR;0BACE,CAACS,oBACA,KAACL;wBACCI,KAAKA;uBACA;wBAAE,CAACN,iBAAiB,EAAEO;oBAAI,GAC1BF;;QAKf;QAEAD,mBAAmBD,WAAW,GAAG,CAAC,YAAY,EAAEA,YAAY,CAAC,CAAC;QAC9DT,qBAAqBU,oBAAoBF;QACzC,OAAOE;IACT;IAEA,OAAOH;AACT"}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Copyright 2026 Aglyn LLC
|
|
4
|
+
*
|
|
5
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
6
|
+
* you may not use this file except in compliance with the License.
|
|
7
|
+
* You may obtain a copy of the License at
|
|
8
|
+
*
|
|
9
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
10
|
+
*
|
|
11
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
12
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
13
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
14
|
+
* See the License for the specific language governing permissions and
|
|
15
|
+
* limitations under the License.
|
|
16
|
+
*/
|
|
17
|
+
import { ComponentType } from 'react';
|
|
18
|
+
/** Merge props for WithHoc utility functions */
|
|
19
|
+
export type WithHocProps<P, N extends MapKey, T> = P & {
|
|
20
|
+
[K in N]: T;
|
|
21
|
+
};
|
|
22
|
+
/** Component with merge props from WithHocProps for WithHoc utility functions */
|
|
23
|
+
export type WithHocComponent<P, N extends MapKey, T> = ComponentType<WithHocProps<P, N, T>>;
|
|
24
|
+
/** "with*" HOC function type */
|
|
25
|
+
export type WithHocFn<P, T, K extends MapKey> = {
|
|
26
|
+
(Component: WithHocComponent<P, K, T>, prop?: K): ComponentType<P>;
|
|
27
|
+
};
|
|
28
|
+
/** Utility "with*" HOC utility function builder */
|
|
29
|
+
export type WithHocFnBuilder = {
|
|
30
|
+
<P, T, U extends string>(value: T | ((props: P) => T), injectedPropName: U): WithHocFn<P, T, U>;
|
|
31
|
+
};
|
|
32
|
+
export declare const withHocFactoryBuilder: WithHocFnBuilder;
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { _ as _extends } from "@swc/helpers/_/_extends";
|
|
2
|
+
/**
|
|
3
|
+
* @license
|
|
4
|
+
* Copyright 2026 Aglyn LLC
|
|
5
|
+
*
|
|
6
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
7
|
+
* you may not use this file except in compliance with the License.
|
|
8
|
+
* You may obtain a copy of the License at
|
|
9
|
+
*
|
|
10
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
11
|
+
*
|
|
12
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
13
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
14
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
15
|
+
* See the License for the specific language governing permissions and
|
|
16
|
+
* limitations under the License.
|
|
17
|
+
*/ import { _isFnT, getDisplayName } from "@aglyn/shared-util-tools";
|
|
18
|
+
import { hoistNonReactStatics } from "@aglyn/shared-util-vendor";
|
|
19
|
+
import { createElement } from "react";
|
|
20
|
+
function withHocFactoryBuilderImpl(value, injectedPropName) {
|
|
21
|
+
return function withHocFactory(Component, overrideInjectedPropName) {
|
|
22
|
+
const propName = overrideInjectedPropName || injectedPropName;
|
|
23
|
+
function WithHocFactory(props) {
|
|
24
|
+
const _value = _isFnT(value) ? value(props) : value;
|
|
25
|
+
const mergedProps = _extends({}, props, {
|
|
26
|
+
[propName]: _value
|
|
27
|
+
});
|
|
28
|
+
return createElement(Component, mergedProps);
|
|
29
|
+
}
|
|
30
|
+
WithHocFactory.name = `WithHocFactory(${getDisplayName(Component)})`;
|
|
31
|
+
hoistNonReactStatics(WithHocFactory, Component);
|
|
32
|
+
return WithHocFactory;
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
export const withHocFactoryBuilder = withHocFactoryBuilderImpl;
|
|
36
|
+
|
|
37
|
+
//# sourceMappingURL=with-hoc.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../../../../../libs/shared/ui/jsx/src/lib/hocs/with-hoc.ts"],"sourcesContent":["/**\n * @license\n * Copyright 2026 Aglyn LLC\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { _isFnT, getDisplayName } from '@aglyn/shared-util-tools'\nimport { hoistNonReactStatics } from '@aglyn/shared-util-vendor'\nimport { ComponentType, createElement } from 'react'\n\n\n/** Merge props for WithHoc utility functions */\nexport type WithHocProps<P, N extends MapKey, T> = P & { [K in N]: T }\n\n/** Component with merge props from WithHocProps for WithHoc utility functions */\nexport type WithHocComponent<P, N extends MapKey, T> = ComponentType<\n WithHocProps<P, N, T>\n>\n\n/** \"with*\" HOC function type */\nexport type WithHocFn<P, T, K extends MapKey> = {\n (Component: WithHocComponent<P, K, T>, prop?: K): ComponentType<P>\n}\n\n/** Utility \"with*\" HOC utility function builder */\nexport type WithHocFnBuilder = {\n <P, T, U extends string>(\n value: T | ((props: P) => T),\n injectedPropName: U,\n ): WithHocFn<P, T, U>\n}\n\nfunction withHocFactoryBuilderImpl<P, T, U extends MapKey>(\n value: T | { (props: P): T },\n injectedPropName: U,\n) {\n return function withHocFactory(\n Component: WithHocComponent<P, U, T>,\n overrideInjectedPropName?: U,\n ): ComponentType<P> {\n const propName = overrideInjectedPropName || injectedPropName\n function WithHocFactory(props: P) {\n const _value = _isFnT(value) ? value(props) : value\n const mergedProps = { ...props, [propName]: _value } as P & {\n [K in U]: T\n }\n return createElement(Component, mergedProps)\n }\n WithHocFactory.name = `WithHocFactory(${getDisplayName(Component)})`\n hoistNonReactStatics(WithHocFactory, Component)\n return WithHocFactory\n }\n}\n\nexport const withHocFactoryBuilder: WithHocFnBuilder = withHocFactoryBuilderImpl\n"],"names":["_isFnT","getDisplayName","hoistNonReactStatics","createElement","withHocFactoryBuilderImpl","value","injectedPropName","withHocFactory","Component","overrideInjectedPropName","propName","WithHocFactory","props","_value","mergedProps","name","withHocFactoryBuilder"],"mappings":";AAAA;;;;;;;;;;;;;;;CAeC,GAED,SAASA,MAAM,EAAEC,cAAc,QAAQ,2BAA0B;AACjE,SAASC,oBAAoB,QAAQ,4BAA2B;AAChE,SAAwBC,aAAa,QAAQ,QAAO;AAwBpD,SAASC,0BACPC,KAA4B,EAC5BC,gBAAmB;IAEnB,OAAO,SAASC,eACdC,SAAoC,EACpCC,wBAA4B;QAE5B,MAAMC,WAAWD,4BAA4BH;QAC7C,SAASK,eAAeC,KAAQ;YAC9B,MAAMC,SAASb,OAAOK,SAASA,MAAMO,SAASP;YAC9C,MAAMS,cAAc,aAAKF;gBAAO,CAACF,SAAS,EAAEG;;YAG5C,OAAOV,cAAcK,WAAWM;QAClC;QACAH,eAAeI,IAAI,GAAG,CAAC,eAAe,EAAEd,eAAeO,WAAW,CAAC,CAAC;QACpEN,qBAAqBS,gBAAgBH;QACrC,OAAOG;IACT;AACF;AAEA,OAAO,MAAMK,wBAA0CZ,0BAAyB"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Copyright 2023 Aglyn LLC
|
|
4
|
+
*
|
|
5
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
6
|
+
* you may not use this file except in compliance with the License.
|
|
7
|
+
* You may obtain a copy of the License at
|
|
8
|
+
*
|
|
9
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
10
|
+
*
|
|
11
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
12
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
13
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
14
|
+
* See the License for the specific language governing permissions and
|
|
15
|
+
* limitations under the License.
|
|
16
|
+
*/
|
|
17
|
+
import type * as MdiJs from '@mdi/js';
|
|
18
|
+
type IconPath<T> = [T] extends [keyof typeof MdiJs] ? typeof MdiJs[T] : string;
|
|
19
|
+
export declare function useMdiIcon<T>(id: T): IconPath<T>;
|
|
20
|
+
export default useMdiIcon;
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Copyright 2023 Aglyn LLC
|
|
4
|
+
*
|
|
5
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
6
|
+
* you may not use this file except in compliance with the License.
|
|
7
|
+
* You may obtain a copy of the License at
|
|
8
|
+
*
|
|
9
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
10
|
+
*
|
|
11
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
12
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
13
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
14
|
+
* See the License for the specific language governing permissions and
|
|
15
|
+
* limitations under the License.
|
|
16
|
+
*/ import { DEFAULT_ICON } from "@aglyn/shared-data-mdi";
|
|
17
|
+
import useAsyncEffect from "../use-async-effect.js";
|
|
18
|
+
import { useState } from "react";
|
|
19
|
+
export function useMdiIcon(id) {
|
|
20
|
+
const [path, setPath] = useState(()=>DEFAULT_ICON.path);
|
|
21
|
+
useAsyncEffect(async (isMounted)=>{
|
|
22
|
+
if (!id || typeof id !== 'string') return;
|
|
23
|
+
const data = await import("@mdi/js").then(({ [id]: path })=>path).catch(console.error);
|
|
24
|
+
if (isMounted() && data) setPath(data);
|
|
25
|
+
}, [
|
|
26
|
+
id
|
|
27
|
+
]);
|
|
28
|
+
// useEffect(() => {
|
|
29
|
+
// let unmounted = false
|
|
30
|
+
//
|
|
31
|
+
// ;(async () => {
|
|
32
|
+
// if (!id || typeof id !== 'string') return
|
|
33
|
+
// const data = await import('@mdi/js')
|
|
34
|
+
// .then(({ [id]: path }) => path as IconPath<T>)
|
|
35
|
+
// .catch(console.error)
|
|
36
|
+
// if (unmounted) return
|
|
37
|
+
// if (data) setPath(data)
|
|
38
|
+
// })()
|
|
39
|
+
//
|
|
40
|
+
// return () => {
|
|
41
|
+
// unmounted = true
|
|
42
|
+
// }
|
|
43
|
+
// }, [id])
|
|
44
|
+
return path;
|
|
45
|
+
}
|
|
46
|
+
export default useMdiIcon;
|
|
47
|
+
|
|
48
|
+
//# sourceMappingURL=use-mdi-icon.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../../../../../../libs/shared/ui/jsx/src/lib/hooks/mdi-icon/use-mdi-icon.ts"],"sourcesContent":["/**\n * @license\n * Copyright 2023 Aglyn LLC\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { DEFAULT_ICON } from '@aglyn/shared-data-mdi'\nimport useAsyncEffect from '../use-async-effect'\nimport type * as MdiJs from '@mdi/js'\nimport { useState } from 'react'\n\ntype IconPath<T> = [T] extends [keyof typeof MdiJs] ? typeof MdiJs[T] : string\n\nexport function useMdiIcon<T>(id: T): IconPath<T> {\n const [path, setPath] = useState<IconPath<T>>(() => DEFAULT_ICON.path)\n\n useAsyncEffect(\n async (isMounted) => {\n if (!id || typeof id !== 'string') return\n const data = await import('@mdi/js')\n .then(({ [id]: path }) => path as IconPath<T>)\n .catch(console.error)\n if (isMounted() && data) setPath(data)\n },\n [id],\n )\n\n // useEffect(() => {\n // let unmounted = false\n //\n // ;(async () => {\n // if (!id || typeof id !== 'string') return\n // const data = await import('@mdi/js')\n // .then(({ [id]: path }) => path as IconPath<T>)\n // .catch(console.error)\n // if (unmounted) return\n // if (data) setPath(data)\n // })()\n //\n // return () => {\n // unmounted = true\n // }\n // }, [id])\n\n return path\n}\n\nexport default useMdiIcon\n"],"names":["DEFAULT_ICON","useAsyncEffect","useState","useMdiIcon","id","path","setPath","isMounted","data","then","catch","console","error"],"mappings":"AAAA;;;;;;;;;;;;;;;CAeC,GAED,SAASA,YAAY,QAAQ,yBAAwB;AACrD,OAAOC,oBAAoB,yBAAqB;AAEhD,SAASC,QAAQ,QAAQ,QAAO;AAIhC,OAAO,SAASC,WAAcC,EAAK;IACjC,MAAM,CAACC,MAAMC,QAAQ,GAAGJ,SAAsB,IAAMF,aAAaK,IAAI;IAErEJ,eACE,OAAOM;QACL,IAAI,CAACH,MAAM,OAAOA,OAAO,UAAU;QACnC,MAAMI,OAAO,MAAM,MAAM,CAAC,WACvBC,IAAI,CAAC,CAAC,EAAE,CAACL,GAAG,EAAEC,IAAI,EAAE,GAAKA,MACzBK,KAAK,CAACC,QAAQC,KAAK;QACtB,IAAIL,eAAeC,MAAMF,QAAQE;IACnC,GACA;QAACJ;KAAG;IAGN,oBAAoB;IACpB,0BAA0B;IAC1B,EAAE;IACF,oBAAoB;IACpB,gDAAgD;IAChD,2CAA2C;IAC3C,uDAAuD;IACvD,8BAA8B;IAC9B,4BAA4B;IAC5B,8BAA8B;IAC9B,SAAS;IACT,EAAE;IACF,mBAAmB;IACnB,uBAAuB;IACvB,MAAM;IACN,WAAW;IAEX,OAAOC;AACT;AAEA,eAAeF,WAAU"}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Copyright 2026 Aglyn LLC
|
|
4
|
+
*
|
|
5
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
6
|
+
* you may not use this file except in compliance with the License.
|
|
7
|
+
* You may obtain a copy of the License at
|
|
8
|
+
*
|
|
9
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
10
|
+
*
|
|
11
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
12
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
13
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
14
|
+
* See the License for the specific language governing permissions and
|
|
15
|
+
* limitations under the License.
|
|
16
|
+
*/
|
|
17
|
+
import type { Icon, IconId } from '@aglyn/shared-data-mdi';
|
|
18
|
+
import type { ApplyFilterFn, ClearFilterFn } from '../../types';
|
|
19
|
+
type UseMdiIconsReturn = [
|
|
20
|
+
filteredIcons: Icon[],
|
|
21
|
+
allIcons: Icon[],
|
|
22
|
+
applyFilter: ApplyFilterFn,
|
|
23
|
+
clearFilter: ClearFilterFn
|
|
24
|
+
];
|
|
25
|
+
export declare function useMdiIconsFuzzy(iconId?: IconId[]): UseMdiIconsReturn;
|
|
26
|
+
export default useMdiIconsFuzzy;
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Copyright 2026 Aglyn LLC
|
|
4
|
+
*
|
|
5
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
6
|
+
* you may not use this file except in compliance with the License.
|
|
7
|
+
* You may obtain a copy of the License at
|
|
8
|
+
*
|
|
9
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
10
|
+
*
|
|
11
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
12
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
13
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
14
|
+
* See the License for the specific language governing permissions and
|
|
15
|
+
* limitations under the License.
|
|
16
|
+
*/ import { Fuse } from "@aglyn/shared-util-vendor/fuse";
|
|
17
|
+
import { useCallback, useEffect, useMemo, useState } from "react";
|
|
18
|
+
import { useMdiIcons } from "./use-mdi-icons.js";
|
|
19
|
+
export function useMdiIconsFuzzy(iconId) {
|
|
20
|
+
const allIcons = useMdiIcons(iconId);
|
|
21
|
+
const [filteredIcons, setFilteredIcons] = useState(allIcons);
|
|
22
|
+
// The catalog arrives async (AGL-189): when the icon set materializes
|
|
23
|
+
// after mount, refresh the unfiltered view or the grid stays empty.
|
|
24
|
+
useEffect(()=>{
|
|
25
|
+
setFilteredIcons(allIcons);
|
|
26
|
+
}, [
|
|
27
|
+
allIcons
|
|
28
|
+
]);
|
|
29
|
+
const fuzzy = useMemo(()=>{
|
|
30
|
+
return new Fuse(allIcons, {
|
|
31
|
+
keys: [
|
|
32
|
+
{
|
|
33
|
+
name: 'name',
|
|
34
|
+
weight: 0.5
|
|
35
|
+
},
|
|
36
|
+
{
|
|
37
|
+
name: 'as',
|
|
38
|
+
weight: 0.25
|
|
39
|
+
},
|
|
40
|
+
{
|
|
41
|
+
name: 'tags',
|
|
42
|
+
weight: 0.25
|
|
43
|
+
}
|
|
44
|
+
],
|
|
45
|
+
includeScore: true,
|
|
46
|
+
shouldSort: true
|
|
47
|
+
});
|
|
48
|
+
}, [
|
|
49
|
+
allIcons
|
|
50
|
+
]);
|
|
51
|
+
const clearFilter = useCallback(()=>{
|
|
52
|
+
setFilteredIcons(allIcons);
|
|
53
|
+
}, [
|
|
54
|
+
allIcons,
|
|
55
|
+
setFilteredIcons
|
|
56
|
+
]);
|
|
57
|
+
const applyFilter = useCallback(async (query)=>{
|
|
58
|
+
const results = fuzzy.search(query);
|
|
59
|
+
setFilteredIcons(results.map((i)=>i.item));
|
|
60
|
+
}, [
|
|
61
|
+
fuzzy,
|
|
62
|
+
setFilteredIcons
|
|
63
|
+
]);
|
|
64
|
+
return [
|
|
65
|
+
filteredIcons,
|
|
66
|
+
allIcons,
|
|
67
|
+
applyFilter,
|
|
68
|
+
clearFilter
|
|
69
|
+
];
|
|
70
|
+
}
|
|
71
|
+
export default useMdiIconsFuzzy;
|
|
72
|
+
|
|
73
|
+
//# sourceMappingURL=use-mdi-icons-fuzzy.js.map
|