@tirth_jasoliya/ui 1.0.0 → 1.0.2
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 +49 -14
- 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 +51 -16
- package/dist/index.js.map +1 -1
- package/package.json +5 -5
package/dist/index.cjs
CHANGED
|
@@ -2312,6 +2312,7 @@ var AppContainer = ({
|
|
|
2312
2312
|
|
|
2313
2313
|
// src/components/layouts/app-header.tsx
|
|
2314
2314
|
var import_lucide_react16 = require("lucide-react");
|
|
2315
|
+
var import_react_router = require("react-router");
|
|
2315
2316
|
var import_jsx_runtime27 = require("react/jsx-runtime");
|
|
2316
2317
|
var AppHeader = ({
|
|
2317
2318
|
className,
|
|
@@ -2327,10 +2328,10 @@ var AppHeader = ({
|
|
|
2327
2328
|
className: "hover:bg-primary/20 inline-flex"
|
|
2328
2329
|
};
|
|
2329
2330
|
if (meta.backAction.href) {
|
|
2330
|
-
return /* @__PURE__ */ (0, import_jsx_runtime27.jsxs)(Button, { ...buttonProps, children: [
|
|
2331
|
+
return /* @__PURE__ */ (0, import_jsx_runtime27.jsx)(import_react_router.NavLink, { to: meta.backAction.href, children: /* @__PURE__ */ (0, import_jsx_runtime27.jsxs)(Button, { ...buttonProps, children: [
|
|
2331
2332
|
/* @__PURE__ */ (0, import_jsx_runtime27.jsx)(import_lucide_react16.ArrowLeftIcon, { className: "size-6" }),
|
|
2332
2333
|
meta.backAction.content
|
|
2333
|
-
] });
|
|
2334
|
+
] }) });
|
|
2334
2335
|
}
|
|
2335
2336
|
return /* @__PURE__ */ (0, import_jsx_runtime27.jsxs)(Button, { ...buttonProps, onClick: meta.backAction.onClick, children: [
|
|
2336
2337
|
/* @__PURE__ */ (0, import_jsx_runtime27.jsx)(import_lucide_react16.ArrowLeftIcon, { className: "size-6" }),
|
|
@@ -2741,16 +2742,26 @@ var AppMetaProvider = ({ children }) => {
|
|
|
2741
2742
|
breadcrumbs: []
|
|
2742
2743
|
});
|
|
2743
2744
|
const setMeta = (0, import_react4.useCallback)((partialMeta) => {
|
|
2744
|
-
setMetaState((prev) =>
|
|
2745
|
+
setMetaState((prev) => {
|
|
2746
|
+
const hasChanges = Object.keys(partialMeta).some(
|
|
2747
|
+
(key) => JSON.stringify(prev[key]) !== JSON.stringify(partialMeta[key])
|
|
2748
|
+
);
|
|
2749
|
+
return hasChanges ? { ...prev, ...partialMeta } : prev;
|
|
2750
|
+
});
|
|
2745
2751
|
}, []);
|
|
2746
2752
|
const resetMeta = (0, import_react4.useCallback)(() => {
|
|
2747
|
-
setMetaState({
|
|
2753
|
+
setMetaState((prev) => prev.title === "" && prev.description === "" && (prev.breadcrumbs?.length ?? 0) === 0 ? prev : {
|
|
2748
2754
|
title: "",
|
|
2749
2755
|
description: "",
|
|
2750
2756
|
breadcrumbs: []
|
|
2751
2757
|
});
|
|
2752
2758
|
}, []);
|
|
2753
|
-
|
|
2759
|
+
const contextValue = (0, import_react4.useMemo)(() => ({
|
|
2760
|
+
meta,
|
|
2761
|
+
setMeta,
|
|
2762
|
+
resetMeta
|
|
2763
|
+
}), [meta, setMeta, resetMeta]);
|
|
2764
|
+
return /* @__PURE__ */ (0, import_jsx_runtime32.jsx)(AppMetaContext.Provider, { value: contextValue, children });
|
|
2754
2765
|
};
|
|
2755
2766
|
function createTypedAppMetaContext() {
|
|
2756
2767
|
const TypedAppMetaContext = (0, import_react4.createContext)(void 0);
|
|
@@ -2761,16 +2772,28 @@ function createTypedAppMetaContext() {
|
|
|
2761
2772
|
breadcrumbs: []
|
|
2762
2773
|
});
|
|
2763
2774
|
const setMeta = (0, import_react4.useCallback)((partialMeta) => {
|
|
2764
|
-
setMetaState((prev) =>
|
|
2775
|
+
setMetaState((prev) => {
|
|
2776
|
+
const hasChanges = Object.keys(partialMeta).some((key) => {
|
|
2777
|
+
const prevValue = prev[key];
|
|
2778
|
+
const newValue = partialMeta[key];
|
|
2779
|
+
return JSON.stringify(prevValue) !== JSON.stringify(newValue);
|
|
2780
|
+
});
|
|
2781
|
+
return hasChanges ? { ...prev, ...partialMeta } : prev;
|
|
2782
|
+
});
|
|
2765
2783
|
}, []);
|
|
2766
2784
|
const resetMeta = (0, import_react4.useCallback)(() => {
|
|
2767
|
-
setMetaState({
|
|
2785
|
+
setMetaState((prev) => prev.title === "" && prev.description === "" && (prev.breadcrumbs?.length ?? 0) === 0 ? prev : {
|
|
2768
2786
|
title: "",
|
|
2769
2787
|
description: "",
|
|
2770
2788
|
breadcrumbs: []
|
|
2771
2789
|
});
|
|
2772
2790
|
}, []);
|
|
2773
|
-
|
|
2791
|
+
const contextValue = (0, import_react4.useMemo)(() => ({
|
|
2792
|
+
meta,
|
|
2793
|
+
setMeta,
|
|
2794
|
+
resetMeta
|
|
2795
|
+
}), [meta, setMeta, resetMeta]);
|
|
2796
|
+
return /* @__PURE__ */ (0, import_jsx_runtime32.jsx)(TypedAppMetaContext.Provider, { value: contextValue, children });
|
|
2774
2797
|
};
|
|
2775
2798
|
const useTypedAppMeta = () => {
|
|
2776
2799
|
const context = (0, import_react4.useContext)(TypedAppMetaContext);
|
|
@@ -2789,21 +2812,33 @@ function createPageTemplateHook({
|
|
|
2789
2812
|
}) {
|
|
2790
2813
|
function usePageTemplate(options) {
|
|
2791
2814
|
const { setMeta, resetMeta } = useTypedAppMeta();
|
|
2792
|
-
const
|
|
2815
|
+
const backAction = (0, import_react5.useMemo)(() => {
|
|
2816
|
+
if (!options.backAction) return void 0;
|
|
2817
|
+
return {
|
|
2818
|
+
...options.backAction,
|
|
2819
|
+
onClick: options.backAction.onClick
|
|
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
|
}
|