@tirth_jasoliya/ui 1.0.0 → 1.0.1
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/index.cjs +47 -12
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +49 -14
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
package/dist/index.cjs
CHANGED
|
@@ -2741,16 +2741,26 @@ var AppMetaProvider = ({ children }) => {
|
|
|
2741
2741
|
breadcrumbs: []
|
|
2742
2742
|
});
|
|
2743
2743
|
const setMeta = (0, import_react4.useCallback)((partialMeta) => {
|
|
2744
|
-
setMetaState((prev) =>
|
|
2744
|
+
setMetaState((prev) => {
|
|
2745
|
+
const hasChanges = Object.keys(partialMeta).some(
|
|
2746
|
+
(key) => JSON.stringify(prev[key]) !== JSON.stringify(partialMeta[key])
|
|
2747
|
+
);
|
|
2748
|
+
return hasChanges ? { ...prev, ...partialMeta } : prev;
|
|
2749
|
+
});
|
|
2745
2750
|
}, []);
|
|
2746
2751
|
const resetMeta = (0, import_react4.useCallback)(() => {
|
|
2747
|
-
setMetaState({
|
|
2752
|
+
setMetaState((prev) => prev.title === "" && prev.description === "" && (prev.breadcrumbs?.length ?? 0) === 0 ? prev : {
|
|
2748
2753
|
title: "",
|
|
2749
2754
|
description: "",
|
|
2750
2755
|
breadcrumbs: []
|
|
2751
2756
|
});
|
|
2752
2757
|
}, []);
|
|
2753
|
-
|
|
2758
|
+
const contextValue = (0, import_react4.useMemo)(() => ({
|
|
2759
|
+
meta,
|
|
2760
|
+
setMeta,
|
|
2761
|
+
resetMeta
|
|
2762
|
+
}), [meta, setMeta, resetMeta]);
|
|
2763
|
+
return /* @__PURE__ */ (0, import_jsx_runtime32.jsx)(AppMetaContext.Provider, { value: contextValue, children });
|
|
2754
2764
|
};
|
|
2755
2765
|
function createTypedAppMetaContext() {
|
|
2756
2766
|
const TypedAppMetaContext = (0, import_react4.createContext)(void 0);
|
|
@@ -2761,16 +2771,28 @@ function createTypedAppMetaContext() {
|
|
|
2761
2771
|
breadcrumbs: []
|
|
2762
2772
|
});
|
|
2763
2773
|
const setMeta = (0, import_react4.useCallback)((partialMeta) => {
|
|
2764
|
-
setMetaState((prev) =>
|
|
2774
|
+
setMetaState((prev) => {
|
|
2775
|
+
const hasChanges = Object.keys(partialMeta).some((key) => {
|
|
2776
|
+
const prevValue = prev[key];
|
|
2777
|
+
const newValue = partialMeta[key];
|
|
2778
|
+
return JSON.stringify(prevValue) !== JSON.stringify(newValue);
|
|
2779
|
+
});
|
|
2780
|
+
return hasChanges ? { ...prev, ...partialMeta } : prev;
|
|
2781
|
+
});
|
|
2765
2782
|
}, []);
|
|
2766
2783
|
const resetMeta = (0, import_react4.useCallback)(() => {
|
|
2767
|
-
setMetaState({
|
|
2784
|
+
setMetaState((prev) => prev.title === "" && prev.description === "" && (prev.breadcrumbs?.length ?? 0) === 0 ? prev : {
|
|
2768
2785
|
title: "",
|
|
2769
2786
|
description: "",
|
|
2770
2787
|
breadcrumbs: []
|
|
2771
2788
|
});
|
|
2772
2789
|
}, []);
|
|
2773
|
-
|
|
2790
|
+
const contextValue = (0, import_react4.useMemo)(() => ({
|
|
2791
|
+
meta,
|
|
2792
|
+
setMeta,
|
|
2793
|
+
resetMeta
|
|
2794
|
+
}), [meta, setMeta, resetMeta]);
|
|
2795
|
+
return /* @__PURE__ */ (0, import_jsx_runtime32.jsx)(TypedAppMetaContext.Provider, { value: contextValue, children });
|
|
2774
2796
|
};
|
|
2775
2797
|
const useTypedAppMeta = () => {
|
|
2776
2798
|
const context = (0, import_react4.useContext)(TypedAppMetaContext);
|
|
@@ -2789,21 +2811,34 @@ function createPageTemplateHook({
|
|
|
2789
2811
|
}) {
|
|
2790
2812
|
function usePageTemplate(options) {
|
|
2791
2813
|
const { setMeta, resetMeta } = useTypedAppMeta();
|
|
2792
|
-
const
|
|
2814
|
+
const backAction = (0, import_react5.useMemo)(() => {
|
|
2815
|
+
if (!options.backAction) return void 0;
|
|
2816
|
+
return {
|
|
2817
|
+
...options.backAction,
|
|
2818
|
+
onClick: options.backAction.onClick
|
|
2819
|
+
// Keep as is - we'll handle stabilization differently
|
|
2820
|
+
};
|
|
2821
|
+
}, [options.backAction?.content, options.backAction?.href, options.backAction?.onClick?.toString()]);
|
|
2822
|
+
const metadata = (0, import_react5.useMemo)(() => options.metadata, [JSON.stringify(options.metadata)]);
|
|
2823
|
+
const stableOptions = (0, import_react5.useMemo)(() => ({
|
|
2824
|
+
...options,
|
|
2825
|
+
backAction,
|
|
2826
|
+
metadata
|
|
2827
|
+
}), [
|
|
2793
2828
|
options.title,
|
|
2794
2829
|
options.description,
|
|
2795
2830
|
options.breadcrumbs,
|
|
2796
2831
|
options.primaryActions,
|
|
2797
2832
|
options.secondaryActions,
|
|
2798
|
-
options.backAction,
|
|
2799
2833
|
options.pagination,
|
|
2800
|
-
options.
|
|
2801
|
-
|
|
2834
|
+
options.status,
|
|
2835
|
+
backAction,
|
|
2836
|
+
metadata
|
|
2802
2837
|
]);
|
|
2803
2838
|
(0, import_react5.useEffect)(() => {
|
|
2804
|
-
setMeta(
|
|
2839
|
+
setMeta(stableOptions);
|
|
2805
2840
|
return () => resetMeta();
|
|
2806
|
-
}, [
|
|
2841
|
+
}, [stableOptions, setMeta, resetMeta]);
|
|
2807
2842
|
}
|
|
2808
2843
|
return { usePageTemplate };
|
|
2809
2844
|
}
|