@cccsaurora/clue-ui 0.15.0-dev.31 → 0.15.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +143 -39
- package/ActionForm-DgfJwTzt.js +0 -436
- package/AnnotationPreview-BvNpZOP0.js +0 -188
- package/ClueEnrichContext-DXwLVp0M.js +0 -518
- package/FlexOne-BSYAhhtG.js +0 -9
- package/_Map-kgDsDYxq.js +0 -64
- package/_MapCache-DabaaWfq.js +0 -161
- package/_Uint8Array-BlVVH1tp.js +0 -129
- package/_baseAssignValue-CNbcU6Nb.js +0 -25
- package/_baseClone-D3a8Pa4T.js +0 -284
- package/_baseExtremum-B1o1zHjR.js +0 -33
- package/_baseFlatten-D4huXoEI.js +0 -92
- package/_baseGet-BSK_nnoz.js +0 -109
- package/_baseIsEqual-B5xLoweL.js +0 -238
- package/_baseIteratee-p6Nj07-n.js +0 -126
- package/_baseSlice-GAv_YFTT.js +0 -20
- package/_baseSum-D0WC1dN0.js +0 -13
- package/_baseUniq-CpupKWcL.js +0 -89
- package/_commonjsHelpers-CUmg6egw.js +0 -6
- package/_createAggregator-BpVy5xMi.js +0 -63
- package/_getPrototype-D1LAdQKO.js +0 -5
- package/_getTag-D3ToyefI.js +0 -126
- package/api/lookup/enrich.d.ts +0 -10
- package/api/lookup/index.d.ts +0 -5
- package/api/lookup/types.d.ts +0 -5
- package/api/lookup/types_detection.d.ts +0 -5
- package/cloneDeep-CjP5k9zW.js +0 -8
- package/components/AnnotationBody.d.ts +0 -6
- package/components/AnnotationBody.js +0 -56
- package/components/AnnotationDetailPopover.d.ts +0 -14
- package/components/AnnotationDetailPopover.js +0 -61
- package/components/AnnotationDetails.d.ts +0 -8
- package/components/AnnotationDetails.js +0 -172
- package/components/AnnotationEntry.d.ts +0 -6
- package/components/AnnotationEntry.js +0 -59
- package/components/AnnotationPreview.d.ts +0 -14
- package/components/AnnotationPreview.js +0 -11
- package/components/ClassificationChip.d.ts +0 -11
- package/components/ClassificationChip.js +0 -52
- package/components/CountBadge.d.ts +0 -8
- package/components/CountBadge.js +0 -34
- package/components/EnrichedCard.d.ts +0 -14
- package/components/EnrichedCard.js +0 -162
- package/components/EnrichedChip.d.ts +0 -9
- package/components/EnrichedChip.js +0 -176
- package/components/EnrichedTypography.d.ts +0 -16
- package/components/EnrichedTypography.js +0 -178
- package/components/ErrorBoundary.d.ts +0 -15
- package/components/ErrorBoundary.js +0 -36
- package/components/RetryFailedEnrichments.d.ts +0 -2
- package/components/RetryFailedEnrichments.js +0 -13
- package/components/SourcePicker.d.ts +0 -2
- package/components/SourcePicker.js +0 -98
- package/components/actions/ActionForm.d.ts +0 -6
- package/components/actions/ActionForm.js +0 -16
- package/components/actions/ExecutePopover.d.ts +0 -10
- package/components/actions/ExecutePopover.js +0 -93
- package/components/actions/ResultModal.d.ts +0 -9
- package/components/actions/ResultModal.js +0 -46
- package/components/actions/form/schemaAdapter.d.ts +0 -3
- package/components/actions/form/schemaAdapter.js +0 -47
- package/components/display/graph/ExpandMoreButton.d.ts +0 -7
- package/components/display/graph/ExpandMoreButton.js +0 -18
- package/components/display/graph/elements/NodeCard.d.ts +0 -10
- package/components/display/graph/elements/NodeCard.js +0 -146
- package/components/display/graph/elements/NodeTag.d.ts +0 -9
- package/components/display/graph/elements/NodeTag.js +0 -17
- package/components/display/graph/index.d.ts +0 -9
- package/components/display/graph/index.js +0 -438
- package/components/display/graph/visualizations/Leaf.d.ts +0 -25
- package/components/display/graph/visualizations/Leaf.js +0 -125
- package/components/display/graph/visualizations/cloud/index.d.ts +0 -24
- package/components/display/graph/visualizations/cloud/index.js +0 -141
- package/components/display/graph/visualizations/icons/BaseIcon.d.ts +0 -12
- package/components/display/graph/visualizations/icons/BaseIcon.js +0 -37
- package/components/display/graph/visualizations/icons/BugIcon.d.ts +0 -5
- package/components/display/graph/visualizations/icons/BugIcon.js +0 -18
- package/components/display/graph/visualizations/icons/HostIcon.d.ts +0 -5
- package/components/display/graph/visualizations/icons/HostIcon.js +0 -24
- package/components/display/graph/visualizations/icons/NetworkIcon.d.ts +0 -5
- package/components/display/graph/visualizations/icons/NetworkIcon.js +0 -24
- package/components/display/graph/visualizations/icons/ProcessIcon.d.ts +0 -5
- package/components/display/graph/visualizations/icons/ProcessIcon.js +0 -18
- package/components/display/graph/visualizations/icons/TargetIcon.d.ts +0 -5
- package/components/display/graph/visualizations/icons/TargetIcon.js +0 -19
- package/components/display/graph/visualizations/icons/index.d.ts +0 -2
- package/components/display/graph/visualizations/icons/index.js +0 -16
- package/components/display/graph/visualizations/panels/NodePanel.d.ts +0 -8
- package/components/display/graph/visualizations/panels/NodePanel.js +0 -12
- package/components/display/graph/visualizations/tree/BundleLine.d.ts +0 -29
- package/components/display/graph/visualizations/tree/BundleLine.js +0 -121
- package/components/display/graph/visualizations/tree/Triangle.d.ts +0 -9
- package/components/display/graph/visualizations/tree/Triangle.js +0 -26
- package/components/display/graph/visualizations/tree/index.d.ts +0 -36
- package/components/display/graph/visualizations/tree/index.js +0 -485
- package/components/display/graph/visualizations/tree/types.d.ts +0 -11
- package/components/display/graph/visualizations/tree/types.js +0 -1
- package/components/display/icons/Iconified.d.ts +0 -9
- package/components/display/icons/Iconified.js +0 -29
- package/components/display/json/index.d.ts +0 -14
- package/components/display/json/index.js +0 -12
- package/components/display/markdown/DynamicTabs.d.ts +0 -8
- package/components/display/markdown/DynamicTabs.js +0 -26
- package/components/display/markdown/index.d.ts +0 -9
- package/components/display/markdown/index.js +0 -13389
- package/components/display/markdown/markdownPlugins/tabs.d.ts +0 -3
- package/components/display/markdown/markdownPlugins/tabs.js +0 -4
- package/components/enrichment/EnrichPopover.d.ts +0 -10
- package/components/enrichment/EnrichPopover.js +0 -88
- package/components/fetchers/Fetcher.d.ts +0 -17
- package/components/fetchers/Fetcher.js +0 -188
- package/components/fetchers/PreviewModal.d.ts +0 -8
- package/components/fetchers/PreviewModal.js +0 -22
- package/components/fetchers/StatusChip.d.ts +0 -8
- package/components/fetchers/StatusChip.js +0 -30
- package/components/group/Entry.d.ts +0 -8
- package/components/group/Entry.js +0 -15
- package/components/group/Group.d.ts +0 -12
- package/components/group/Group.js +0 -15
- package/components/group/GroupControl.d.ts +0 -4
- package/components/group/GroupControl.js +0 -103
- package/components/stats/QueryStatus.d.ts +0 -4
- package/components/stats/QueryStatus.js +0 -61
- package/countBy-C69WslUA.js +0 -14
- package/data/event.d.ts +0 -12
- package/data/event.js +0 -8
- package/database/index.d.ts +0 -4
- package/database/index.js +0 -4
- package/database/selector.schema.json.d.ts +0 -119
- package/database/status.schema.json.d.ts +0 -38
- package/database/types.d.ts +0 -64
- package/debounce-bV0h5FC5.js +0 -92
- package/en/translation.json +0 -135
- package/fr/translation.json +0 -135
- package/get-D3C3lEU3.js +0 -8
- package/groupBy-DC2oOuBN.js +0 -14
- package/hooks/ClueActionContext.d.ts +0 -86
- package/hooks/ClueActionContext.js +0 -18
- package/hooks/ClueComponentContext.d.ts +0 -10
- package/hooks/ClueComponentContext.js +0 -40
- package/hooks/ClueConfigProvider.d.ts +0 -12
- package/hooks/ClueConfigProvider.js +0 -23
- package/hooks/ClueDatabaseContext.d.ts +0 -10
- package/hooks/ClueDatabaseContext.js +0 -23
- package/hooks/ClueEnrichContext.d.ts +0 -6
- package/hooks/ClueEnrichContext.js +0 -15
- package/hooks/ClueEnrichContextType.d.ts +0 -113
- package/hooks/ClueEnrichProps.d.ts +0 -81
- package/hooks/ClueFetcherContext.d.ts +0 -35
- package/hooks/ClueFetcherContext.js +0 -88
- package/hooks/ClueGroupContext.d.ts +0 -14
- package/hooks/ClueGroupContext.js +0 -23
- package/hooks/CluePopupContext.d.ts +0 -24
- package/hooks/CluePopupContext.js +0 -12
- package/hooks/ClueProvider.d.ts +0 -9
- package/hooks/ClueProvider.js +0 -14
- package/hooks/selectors.d.ts +0 -10
- package/hooks/selectors.js +0 -24
- package/hooks/useAnnotations.d.ts +0 -24
- package/hooks/useAnnotations.js +0 -69
- package/hooks/useClue.d.ts +0 -4
- package/hooks/useClue.js +0 -8
- package/hooks/useClueActions.d.ts +0 -4
- package/hooks/useClueActions.js +0 -5
- package/hooks/useClueConfig.d.ts +0 -1
- package/hooks/useClueConfig.js +0 -8
- package/hooks/useClueTypeConfig.d.ts +0 -17
- package/hooks/useClueTypeConfig.js +0 -7
- package/hooks/useComparator.d.ts +0 -16
- package/hooks/useComparator.js +0 -1060
- package/hooks/useErrors.d.ts +0 -17
- package/hooks/useErrors.js +0 -35
- package/hooks/useMyHighlights.d.ts +0 -11
- package/hooks/useMyHighlights.js +0 -74
- package/hooks/useMyLocalStorage.d.ts +0 -16
- package/hooks/useMyLocalStorage.js +0 -80
- package/iconify-CXMreGTg.js +0 -1782
- package/icons/Action.d.ts +0 -9
- package/icons/Action.js +0 -90
- package/icons/Assessment.d.ts +0 -11
- package/icons/Assessment.js +0 -123
- package/icons/Context.d.ts +0 -12
- package/icons/Context.js +0 -83
- package/icons/Opinion.d.ts +0 -11
- package/icons/Opinion.js +0 -125
- package/icons/iconMap.d.ts +0 -7
- package/icons/iconMap.js +0 -10
- package/identity-CPGTqrE4.js +0 -6
- package/index-BDVjGvMI.js +0 -696
- package/index-BDrtH5ec.js +0 -465
- package/index-C9lySIVX.js +0 -1172
- package/index-DJYqRcxJ.js +0 -15750
- package/index-Dn2NHyXg.js +0 -17654
- package/index.css +0 -21
- package/isEmpty-BQkZubqU.js +0 -29
- package/isNil-CIubwp4T.js +0 -6
- package/isObject-FTY-5JQX.js +0 -7
- package/isObjectLike-OAgjjZye.js +0 -48
- package/isSymbol-Xd2FsJyp.js +0 -8
- package/isUndefined-CE8h73dH.js +0 -10
- package/last-CUCl67Im.js +0 -7
- package/main.d.ts +0 -42
- package/main.js +0 -70
- package/public/manifest.json +0 -16
- package/public/robots.txt +0 -3
- package/public/svg/dark/clue-h.svg +0 -52
- package/public/svg/dark/clue-icon1-simple.svg +0 -33
- package/public/svg/dark/clue-icon1.svg +0 -44
- package/public/svg/dark/clue-icon2-simple.svg +0 -26
- package/public/svg/dark/clue-icon2.svg +0 -37
- package/public/svg/dark/clue-name.svg +0 -14
- package/public/svg/dark/clue-v.svg +0 -52
- package/public/svg/light/clue-h.svg +0 -60
- package/public/svg/light/clue-icon1-simple.svg +0 -37
- package/public/svg/light/clue-icon1.svg +0 -48
- package/public/svg/light/clue-icon2-simple.svg +0 -30
- package/public/svg/light/clue-icon2.svg +0 -41
- package/public/svg/light/clue-name.svg +0 -14
- package/public/svg/light/clue-v.svg +0 -60
- package/sortBy-B-UKp4GT.js +0 -100
- package/sumBy-MYkDPHZL.js +0 -8
- package/tabs-xGuUGsJd.js +0 -254
- package/text/Frequency.d.ts +0 -9
- package/text/Frequency.js +0 -49
- package/toFinite-CArjry_l.js +0 -16
- package/toNumber-DPxy1FBy.js +0 -39
- package/types/EnrichmentProps.d.ts +0 -73
- package/types/RunningActionData.d.ts +0 -15
- package/types/WithActionData.d.ts +0 -9
- package/types/action.d.ts +0 -25
- package/types/config.d.ts +0 -16
- package/types/fetcher.d.ts +0 -60
- package/types/graph.d.ts +0 -101
- package/types/lookup.d.ts +0 -62
- package/types/network.d.ts +0 -9
- package/useClueTypeConfig-D9ZSxa4F.js +0 -3096
- package/utils/chain.d.ts +0 -14
- package/utils/chain.js +0 -106
- package/utils/classificationParser.d.ts +0 -195
- package/utils/classificationParser.js +0 -553
- package/utils/constants.d.ts +0 -26
- package/utils/constants.js +0 -36
- package/utils/graph.d.ts +0 -13
- package/utils/graph.js +0 -79
- package/utils/hashUtil.d.ts +0 -6
- package/utils/hashUtil.js +0 -11
- package/utils/line.d.ts +0 -28
- package/utils/line.js +0 -136
- package/utils/loggerUtil.d.ts +0 -6
- package/utils/loggerUtil.js +0 -8
- package/utils/sessionStorage.d.ts +0 -9
- package/utils/sessionStorage.js +0 -51
- package/utils/utils.d.ts +0 -13
- package/utils/utils.js +0 -11
- package/utils/window.d.ts +0 -3
- package/utils/window.js +0 -24
- package/utils-CxIhC2xH.js +0 -4182
package/hooks/useErrors.d.ts
DELETED
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Custom hook that retrieves error records from the database for a given value.
|
|
3
|
-
*
|
|
4
|
-
* This hook monitors the database for records that match the provided value and have
|
|
5
|
-
* an error field present. It returns an array of error objects containing the source
|
|
6
|
-
* and message for each error found.
|
|
7
|
-
*
|
|
8
|
-
* @param value - The value to search for in the database records
|
|
9
|
-
* @returns An array of error objects, each containing:
|
|
10
|
-
* - source: The source identifier where the error originated
|
|
11
|
-
* - message: The error message content
|
|
12
|
-
*/
|
|
13
|
-
declare const useErrors: (value: string) => {
|
|
14
|
-
source: string;
|
|
15
|
-
message: string;
|
|
16
|
-
}[];
|
|
17
|
-
export default useErrors;
|
package/hooks/useErrors.js
DELETED
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
import { useContext, useState, useEffect } from "react";
|
|
2
|
-
import { ClueDatabaseContext } from "./ClueDatabaseContext.js";
|
|
3
|
-
import { useClueEnrichSelector } from "./selectors.js";
|
|
4
|
-
const useErrors = (value) => {
|
|
5
|
-
const database = useContext(ClueDatabaseContext);
|
|
6
|
-
const ready = useClueEnrichSelector((ctx) => ctx.ready);
|
|
7
|
-
const [errors, setErrors] = useState([]);
|
|
8
|
-
useEffect(() => {
|
|
9
|
-
if (!ready || !value) {
|
|
10
|
-
return;
|
|
11
|
-
}
|
|
12
|
-
const observable = database.selectors.find({ selector: { value, error: { $exists: true } } }).$.subscribe(
|
|
13
|
-
(records) => (
|
|
14
|
-
// Transform database records into simplified error objects
|
|
15
|
-
setErrors(
|
|
16
|
-
records.map((record) => ({
|
|
17
|
-
source: record.source,
|
|
18
|
-
message: record.error
|
|
19
|
-
}))
|
|
20
|
-
)
|
|
21
|
-
)
|
|
22
|
-
);
|
|
23
|
-
return () => {
|
|
24
|
-
try {
|
|
25
|
-
observable.unsubscribe();
|
|
26
|
-
} catch (e) {
|
|
27
|
-
console.warn(e);
|
|
28
|
-
}
|
|
29
|
-
};
|
|
30
|
-
}, [database, ready, value]);
|
|
31
|
-
return errors;
|
|
32
|
-
};
|
|
33
|
-
export {
|
|
34
|
-
useErrors as default
|
|
35
|
-
};
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import { NestedDataset } from "../types/graph";
|
|
2
|
-
|
|
3
|
-
declare const useMyHighlights: (graph: NestedDataset, onNodeSelectionChanged?: (nodeIds: string[]) => void) => {
|
|
4
|
-
onNodeHoveredChanged: (nodeId: string, isHovered: boolean) => void;
|
|
5
|
-
onNodeClicked: (nodeId: string, isSelected: boolean, event: MouseEvent) => void;
|
|
6
|
-
nodeOpacities: (nodeId: string) => 1 | 0.2;
|
|
7
|
-
highlightedPath: Set<string>;
|
|
8
|
-
highlightedNodes: Set<string>;
|
|
9
|
-
hoveredNode: string;
|
|
10
|
-
};
|
|
11
|
-
export default useMyHighlights;
|
package/hooks/useMyHighlights.js
DELETED
|
@@ -1,74 +0,0 @@
|
|
|
1
|
-
import { getSubGraphNodeSet } from "../utils/graph.js";
|
|
2
|
-
import { safeAddEventListener } from "../utils/window.js";
|
|
3
|
-
import { useMemo, useState, useCallback, useEffect } from "react";
|
|
4
|
-
const useMyHighlights = (graph, onNodeSelectionChanged) => {
|
|
5
|
-
const data = useMemo(() => graph == null ? void 0 : graph.data, [graph]);
|
|
6
|
-
const [hoveredNode, setHoveredNode] = useState();
|
|
7
|
-
const [highlightedNodes, setHighlightedNodes] = useState(/* @__PURE__ */ new Set());
|
|
8
|
-
const [highlightedPath, setHighlightedPath] = useState(/* @__PURE__ */ new Set());
|
|
9
|
-
const [ctrlKeyDown, setCtrlKeyDown] = useState();
|
|
10
|
-
const onKeyPressed = useCallback((ev) => {
|
|
11
|
-
setCtrlKeyDown(ev.ctrlKey);
|
|
12
|
-
}, []);
|
|
13
|
-
const onKeyUnpressed = useCallback((ev) => {
|
|
14
|
-
setCtrlKeyDown(ev.ctrlKey);
|
|
15
|
-
}, []);
|
|
16
|
-
useEffect(() => {
|
|
17
|
-
return safeAddEventListener("keydown", onKeyPressed);
|
|
18
|
-
}, [onKeyPressed]);
|
|
19
|
-
useEffect(() => {
|
|
20
|
-
return safeAddEventListener("keyup", onKeyUnpressed);
|
|
21
|
-
}, [onKeyUnpressed]);
|
|
22
|
-
const onNodeHoveredChanged = useCallback((nodeId, isHovered) => {
|
|
23
|
-
if (isHovered) {
|
|
24
|
-
setHoveredNode(nodeId);
|
|
25
|
-
} else {
|
|
26
|
-
setHoveredNode("");
|
|
27
|
-
}
|
|
28
|
-
}, []);
|
|
29
|
-
const onNodeClicked = useCallback(
|
|
30
|
-
(nodeId, isSelected, event) => {
|
|
31
|
-
let newHighlightedNodes = /* @__PURE__ */ new Set();
|
|
32
|
-
if (isSelected) {
|
|
33
|
-
newHighlightedNodes = new Set(event.ctrlKey ? [...highlightedNodes, nodeId] : [nodeId]);
|
|
34
|
-
} else {
|
|
35
|
-
newHighlightedNodes = event.ctrlKey ? /* @__PURE__ */ new Set([...highlightedNodes]) : /* @__PURE__ */ new Set();
|
|
36
|
-
newHighlightedNodes.delete(nodeId);
|
|
37
|
-
}
|
|
38
|
-
setHighlightedNodes(newHighlightedNodes);
|
|
39
|
-
onNodeSelectionChanged == null ? void 0 : onNodeSelectionChanged([...newHighlightedNodes]);
|
|
40
|
-
},
|
|
41
|
-
[highlightedNodes, onNodeSelectionChanged]
|
|
42
|
-
);
|
|
43
|
-
const nodeOpacities = useCallback(
|
|
44
|
-
(nodeId) => {
|
|
45
|
-
return highlightedPath.size === 0 || highlightedPath.has(nodeId) ? 1 : 0.2;
|
|
46
|
-
},
|
|
47
|
-
[highlightedPath]
|
|
48
|
-
);
|
|
49
|
-
useEffect(() => {
|
|
50
|
-
let newHighlightedPath = /* @__PURE__ */ new Set();
|
|
51
|
-
if (hoveredNode) {
|
|
52
|
-
const subGraphNodes = getSubGraphNodeSet(hoveredNode, data);
|
|
53
|
-
newHighlightedPath = /* @__PURE__ */ new Set([...newHighlightedPath, ...subGraphNodes]);
|
|
54
|
-
}
|
|
55
|
-
if (highlightedNodes.size && (ctrlKeyDown || !hoveredNode)) {
|
|
56
|
-
highlightedNodes.forEach((highlightedNode) => {
|
|
57
|
-
const subGraphNodes = getSubGraphNodeSet(highlightedNode, data);
|
|
58
|
-
newHighlightedPath = /* @__PURE__ */ new Set([...newHighlightedPath, ...subGraphNodes]);
|
|
59
|
-
});
|
|
60
|
-
}
|
|
61
|
-
setHighlightedPath(newHighlightedPath);
|
|
62
|
-
}, [hoveredNode, highlightedNodes, ctrlKeyDown, data]);
|
|
63
|
-
return {
|
|
64
|
-
onNodeHoveredChanged,
|
|
65
|
-
onNodeClicked,
|
|
66
|
-
nodeOpacities,
|
|
67
|
-
highlightedPath,
|
|
68
|
-
highlightedNodes,
|
|
69
|
-
hoveredNode
|
|
70
|
-
};
|
|
71
|
-
};
|
|
72
|
-
export {
|
|
73
|
-
useMyHighlights as default
|
|
74
|
-
};
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
import { StorageKey } from "../utils/constants";
|
|
2
|
-
|
|
3
|
-
export default function useMyLocalStorage(): {
|
|
4
|
-
get: <T>(key: string) => T;
|
|
5
|
-
set: (key: string, value: any) => void;
|
|
6
|
-
remove: (key: string, withPrefix?: boolean) => void;
|
|
7
|
-
has: (key: string) => boolean;
|
|
8
|
-
keys: () => string[];
|
|
9
|
-
items: () => {
|
|
10
|
-
key: string;
|
|
11
|
-
value: any;
|
|
12
|
-
}[];
|
|
13
|
-
clear: () => void;
|
|
14
|
-
};
|
|
15
|
-
export declare function useMyLocalStorageItem<T>(key: StorageKey, initialValue?: T): [T, (value: T, save?: boolean) => void, () => void];
|
|
16
|
-
export declare function useMyLocalStorageProvider(): import('components/app/providers/LocalStorageProvider').LocalStorageContextType;
|
|
@@ -1,80 +0,0 @@
|
|
|
1
|
-
import { useCallback, useMemo, useState, useEffect, createContext, useContext } from "react";
|
|
2
|
-
import { i as isNull, a as isUndefined } from "../isUndefined-CE8h73dH.js";
|
|
3
|
-
import "react/jsx-runtime";
|
|
4
|
-
import { MY_LOCAL_STORAGE_PREFIX } from "../utils/constants.js";
|
|
5
|
-
function useLocalStorage(prefix) {
|
|
6
|
-
const _buildKey = useCallback((name) => `${prefix}.${name}`, [prefix]);
|
|
7
|
-
const get = useCallback((key) => JSON.parse(localStorage.getItem(_buildKey(key))), [_buildKey]);
|
|
8
|
-
const set = useCallback(
|
|
9
|
-
(key, value) => localStorage.setItem(_buildKey(key), JSON.stringify(value)),
|
|
10
|
-
[_buildKey]
|
|
11
|
-
);
|
|
12
|
-
const remove = useCallback(
|
|
13
|
-
(key, withPrefix = false) => localStorage.removeItem(withPrefix ? key : _buildKey(key)),
|
|
14
|
-
[_buildKey]
|
|
15
|
-
);
|
|
16
|
-
const has = useCallback((key) => get(key) !== null, [get]);
|
|
17
|
-
const keys = useCallback(() => Object.keys(localStorage), []);
|
|
18
|
-
const items = useCallback(() => keys().map((k) => ({ key: k, value: JSON.parse(localStorage.getItem(k)) })), [keys]);
|
|
19
|
-
const clear = useCallback(
|
|
20
|
-
() => keys().forEach((key) => {
|
|
21
|
-
if (key.startsWith(prefix)) {
|
|
22
|
-
remove(key, true);
|
|
23
|
-
}
|
|
24
|
-
}),
|
|
25
|
-
[prefix, remove, keys]
|
|
26
|
-
);
|
|
27
|
-
return useMemo(
|
|
28
|
-
() => ({
|
|
29
|
-
get,
|
|
30
|
-
set,
|
|
31
|
-
remove,
|
|
32
|
-
has,
|
|
33
|
-
keys,
|
|
34
|
-
items,
|
|
35
|
-
clear
|
|
36
|
-
}),
|
|
37
|
-
[get, set, remove, has, keys, items, clear]
|
|
38
|
-
);
|
|
39
|
-
}
|
|
40
|
-
function useLocalStorageItem(key, initialValue, prefix) {
|
|
41
|
-
const { get, set, has, remove } = useLocalStorage(prefix);
|
|
42
|
-
const [value, setValue] = useState(get(key) ?? initialValue);
|
|
43
|
-
useEffect(() => {
|
|
44
|
-
if (initialValue !== null && initialValue !== void 0 && !has(key)) {
|
|
45
|
-
set(key, initialValue);
|
|
46
|
-
}
|
|
47
|
-
}, [key, initialValue, has, set]);
|
|
48
|
-
return useMemo(
|
|
49
|
-
() => [
|
|
50
|
-
value,
|
|
51
|
-
(newValue, save = true) => {
|
|
52
|
-
if (save) {
|
|
53
|
-
if (!isNull(newValue) && !isUndefined(newValue)) {
|
|
54
|
-
set(key, newValue);
|
|
55
|
-
} else {
|
|
56
|
-
remove(key);
|
|
57
|
-
}
|
|
58
|
-
}
|
|
59
|
-
setValue(newValue);
|
|
60
|
-
},
|
|
61
|
-
() => remove(key)
|
|
62
|
-
],
|
|
63
|
-
[key, value, set, remove]
|
|
64
|
-
);
|
|
65
|
-
}
|
|
66
|
-
const LocalStorageContext = createContext(null);
|
|
67
|
-
function useMyLocalStorage() {
|
|
68
|
-
return useLocalStorage(MY_LOCAL_STORAGE_PREFIX);
|
|
69
|
-
}
|
|
70
|
-
function useMyLocalStorageItem(key, initialValue) {
|
|
71
|
-
return useLocalStorageItem(key, initialValue, MY_LOCAL_STORAGE_PREFIX);
|
|
72
|
-
}
|
|
73
|
-
function useMyLocalStorageProvider() {
|
|
74
|
-
return useContext(LocalStorageContext);
|
|
75
|
-
}
|
|
76
|
-
export {
|
|
77
|
-
useMyLocalStorage as default,
|
|
78
|
-
useMyLocalStorageItem,
|
|
79
|
-
useMyLocalStorageProvider
|
|
80
|
-
};
|