@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 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) => ({ ...prev, ...partialMeta }));
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
- return /* @__PURE__ */ (0, import_jsx_runtime32.jsx)(AppMetaContext.Provider, { value: { meta, setMeta, resetMeta }, children });
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) => ({ ...prev, ...partialMeta }));
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
- return /* @__PURE__ */ (0, import_jsx_runtime32.jsx)(TypedAppMetaContext.Provider, { value: { meta, setMeta, resetMeta }, children });
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 memoizedOptions = (0, import_react5.useMemo)(() => options, [
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.metadata,
2801
- options.status
2834
+ options.status,
2835
+ backAction,
2836
+ metadata
2802
2837
  ]);
2803
2838
  (0, import_react5.useEffect)(() => {
2804
- setMeta(memoizedOptions);
2839
+ setMeta(stableOptions);
2805
2840
  return () => resetMeta();
2806
- }, [memoizedOptions, setMeta, resetMeta]);
2841
+ }, [stableOptions, setMeta, resetMeta]);
2807
2842
  }
2808
2843
  return { usePageTemplate };
2809
2844
  }