@kingteza/crud-component 1.32.0 → 1.33.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.
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const t=require("react/jsx-runtime"),l=require("antd"),s=require("react"),V=require("../select/SelectComponent.cjs.js"),M=require("../../util/ValidationUtil.cjs.js"),q=({className:b,onSelect:p,label:a,required:d,name:o,mode:u,items:r,selectingMode:j})=>{const n=l.Form.useFormInstance(),[x,k]=s.useState(!0);s.useEffect(()=>{if(r&&x){const e=r.filter(c=>c.alreadySelected).map(c=>c.id);n==null||n.setFieldsValue({[o]:u==="multiple"?e:e==null?void 0:e[0]}),k(!1)}},[x,n,r,u,o]);const[F,h]=s.useState(!1),[C,f]=s.useState(void 0),O=s.useCallback(()=>{h(!1),n.setFieldsValue({[o]:C})},[C,n,o]),g=s.useCallback(()=>{h(!1),f(void 0)},[]),S=s.useCallback(()=>{f(n.getFieldValue(o)),h(!0)},[n,o]),i=j==="checkbox",y=s.useCallback(e=>{i&&e&&S()},[i,S]),I=s.useMemo(()=>{const e=[...r];return e.sort((c,v)=>c.label.localeCompare(v.label)),e},[r]);return t.jsxs(t.Fragment,{children:[i&&t.jsx(l.Modal,{open:F,onCancel:O,onOk:g,destroyOnHidden:!0,title:a,children:t.jsx(l.Form.Item,{name:o,required:d,rules:[...d?M.required(a):[]],className:b,children:t.jsx(l.Checkbox.Group,{onChange:p,style:{width:"100%"},children:t.jsx(l.List,{size:"small",style:{width:"100%"},dataSource:I,renderItem:e=>t.jsx(l.List.Item,{style:{width:"100%"},children:t.jsx(l.List.Item.Meta,{avatar:t.jsx(l.Checkbox,{value:e.id,disabled:e.lock}),title:e.label})},e.id)})})})}),t.jsx(V,{required:d,label:a,mode:u,className:b,name:o,onSelect:p,items:r,showSearch:!1,...i?{open:!1,onOpenChange:y}:{},itemBuilder:e=>t.jsx(l.Select.Option,{value:e.id,disabled:e.lock,children:e.label},e.id)})]})};exports.SelectFieldInReport=q;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const t=require("react/jsx-runtime"),s=require("antd"),l=require("react"),V=require("../select/SelectComponent.cjs.js"),M=require("../../util/ValidationUtil.cjs.js"),q=({className:p,onSelect:x,label:a,required:d,name:o,mode:u,items:r,selectingMode:j})=>{const n=s.Form.useFormInstance(),[b,k]=l.useState(!0);l.useEffect(()=>{if(r&&b){const e=r.filter(c=>c.alreadySelected).map(c=>c.id);n==null||n.setFieldsValue({[o]:u==="multiple"?e:e==null?void 0:e[0]}),k(!1)}},[b,n,r,u,o]);const[F,h]=l.useState(!1),[C,f]=l.useState(void 0),g=l.useCallback(()=>{h(!1),n.setFieldsValue({[o]:C})},[C,n,o]),O=l.useCallback(()=>{h(!1),f(void 0)},[]),S=l.useCallback(()=>{f(n.getFieldValue(o)),h(!0)},[n,o]),i=j==="checkbox",v=l.useCallback(e=>{i&&e&&S()},[i,S]),y=l.useMemo(()=>{const e=[...r];return e.sort((c,I)=>c.label.localeCompare(I.label)),e},[r]);return t.jsxs(t.Fragment,{children:[i&&t.jsx(s.Modal,{open:F,onCancel:g,onOk:O,destroyOnHidden:!0,title:a,children:t.jsx(s.Form.Item,{name:o,required:d,rules:[...d?M.required(a):[]],className:p,children:t.jsx(s.Checkbox.Group,{onChange:x,style:{width:"100%"},children:t.jsx(s.List,{size:"small",style:{width:"100%"},dataSource:y,renderItem:e=>t.jsx(s.List.Item,{style:{width:"100%"},children:t.jsx(s.List.Item.Meta,{avatar:t.jsx(s.Checkbox,{value:e.id,disabled:e.lock}),title:e.label})},e.id)})})})}),t.jsx(V,{required:d,label:a,mode:u,className:p,name:o,onSelect:x,items:r,showSearch:!1,maxTagCount:"responsive",...i?{open:!1,onOpenChange:v}:{},itemBuilder:e=>t.jsx(s.Select.Option,{value:e.id,disabled:e.lock,children:e.label},e.id)})]})};exports.SelectFieldInReport=q;
@@ -1,9 +1,9 @@
1
1
  import { jsxs as j, Fragment as B, jsx as t } from "react/jsx-runtime";
2
- import { Form as S, Modal as z, Checkbox as O, List as p, Select as E } from "antd";
2
+ import { Form as S, Modal as z, Checkbox as x, List as p, Select as E } from "antd";
3
3
  import { useState as f, useEffect as G, useCallback as i, useMemo as H } from "react";
4
4
  import L from "../select/SelectComponent.es.js";
5
5
  import R from "../../util/ValidationUtil.es.js";
6
- const P = ({
6
+ const K = ({
7
7
  className: h,
8
8
  onSelect: C,
9
9
  label: c,
@@ -11,26 +11,26 @@ const P = ({
11
11
  name: o,
12
12
  mode: d,
13
13
  items: r,
14
- selectingMode: x
14
+ selectingMode: O
15
15
  }) => {
16
- const l = S.useFormInstance(), [b, I] = f(!0);
16
+ const l = S.useFormInstance(), [m, g] = f(!0);
17
17
  G(() => {
18
- if (r && b) {
18
+ if (r && m) {
19
19
  const e = r.filter((s) => s.alreadySelected).map((s) => s.id);
20
20
  l == null || l.setFieldsValue({
21
21
  [o]: d === "multiple" ? e : e == null ? void 0 : e[0]
22
- }), I(!1);
22
+ }), g(!1);
23
23
  }
24
- }, [b, l, r, d, o]);
25
- const [V, u] = f(!1), [m, k] = f(void 0), g = i(() => {
24
+ }, [m, l, r, d, o]);
25
+ const [v, u] = f(!1), [b, k] = f(void 0), I = i(() => {
26
26
  u(!1), l.setFieldsValue({
27
- [o]: m
27
+ [o]: b
28
28
  });
29
- }, [m, l, o]), v = i(() => {
29
+ }, [b, l, o]), V = i(() => {
30
30
  u(!1), k(void 0);
31
31
  }, []), F = i(() => {
32
32
  k(l.getFieldValue(o)), u(!0);
33
- }, [l, o]), n = x === "checkbox", y = i(
33
+ }, [l, o]), n = O === "checkbox", y = i(
34
34
  (e) => {
35
35
  n && e && F();
36
36
  },
@@ -43,9 +43,9 @@ const P = ({
43
43
  n && /* @__PURE__ */ t(
44
44
  z,
45
45
  {
46
- open: V,
47
- onCancel: g,
48
- onOk: v,
46
+ open: v,
47
+ onCancel: I,
48
+ onOk: V,
49
49
  destroyOnHidden: !0,
50
50
  title: c,
51
51
  children: /* @__PURE__ */ t(
@@ -55,7 +55,7 @@ const P = ({
55
55
  required: a,
56
56
  rules: [...a ? R.required(c) : []],
57
57
  className: h,
58
- children: /* @__PURE__ */ t(O.Group, { onChange: C, style: { width: "100%" }, children: /* @__PURE__ */ t(
58
+ children: /* @__PURE__ */ t(x.Group, { onChange: C, style: { width: "100%" }, children: /* @__PURE__ */ t(
59
59
  p,
60
60
  {
61
61
  size: "small",
@@ -64,7 +64,7 @@ const P = ({
64
64
  renderItem: (e) => /* @__PURE__ */ t(p.Item, { style: { width: "100%" }, children: /* @__PURE__ */ t(
65
65
  p.Item.Meta,
66
66
  {
67
- avatar: /* @__PURE__ */ t(O, { value: e.id, disabled: e.lock }),
67
+ avatar: /* @__PURE__ */ t(x, { value: e.id, disabled: e.lock }),
68
68
  title: e.label
69
69
  }
70
70
  ) }, e.id)
@@ -85,6 +85,7 @@ const P = ({
85
85
  onSelect: C,
86
86
  items: r,
87
87
  showSearch: !1,
88
+ maxTagCount: "responsive",
88
89
  ...n ? { open: !1, onOpenChange: y } : {},
89
90
  itemBuilder: (e) => /* @__PURE__ */ t(E.Option, { value: e.id, disabled: e.lock, children: e.label }, e.id)
90
91
  }
@@ -92,5 +93,5 @@ const P = ({
92
93
  ] });
93
94
  };
94
95
  export {
95
- P as SelectFieldInReport
96
+ K as SelectFieldInReport
96
97
  };
@@ -1 +1 @@
1
- "use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const s=require("react/jsx-runtime"),r=require("react"),u=require("../locale/index.cjs.js"),a=r.createContext({}),c=({children:o,i18nOptions:e})=>{const t=r.useRef(!1);return r.useMemo(()=>{t.current||(u.setupI18n(e||{}),t.current=!0)},[]),r.useEffect(()=>{t.current&&e&&u.setupI18n(e)},[e==null?void 0:e.language]),s.jsx(a.Provider,{value:{},children:o})};exports.CrudComponentProvider=c;exports.default=c;
1
+ "use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const o=require("react/jsx-runtime"),r=require("react"),c=require("../locale/index.cjs.js"),l=require("./CrudNavigateContext.cjs.js"),C=r.createContext({}),s=({children:a,i18nOptions:e,navigatorType:u="react-router",navigate:d})=>{const t=r.useRef(!1);r.useMemo(()=>{t.current||(c.setupI18n(e||{}),t.current=!0)},[]),r.useEffect(()=>{t.current&&e&&c.setupI18n(e)},[e==null?void 0:e.language]);const n=r.useMemo(()=>({navigatorType:u}),[u]);return o.jsx(l.CrudNavigateProvider,{navigate:d,children:o.jsx(C.Provider,{value:n,children:a})})};exports.CrudComponentProvider=s;exports.default=s;
@@ -1,5 +1,6 @@
1
1
  import { default as React, ReactNode } from 'react';
2
2
  import { SetupI18nOptions } from '../locale';
3
+ import { CrudNavigateFn } from './CrudNavigateContext';
3
4
  export interface CrudComponentProviderProps {
4
5
  children: ReactNode;
5
6
  /**
@@ -7,6 +8,19 @@ export interface CrudComponentProviderProps {
7
8
  * If not provided, defaults will be used
8
9
  */
9
10
  i18nOptions?: SetupI18nOptions;
11
+ /**
12
+ * Hints which router you use (docs / future use). Wire navigation with `navigate` and/or optional sync modules:
13
+ * - `react-router`: `@kingteza/crud-component/react-router` exports `CrudReactRouterNavigateSync`, or pass `navigate` from `useNavigate()`.
14
+ * - `nextjs`: `@kingteza/crud-component/next` exports `CrudNextNavigateSync`, or pass a `navigate` wrapper around `useRouter()`.
15
+ *
16
+ * @default "react-router"
17
+ */
18
+ navigatorType?: "react-router" | "nextjs";
19
+ /**
20
+ * Imperative navigation for `useNavigateOptional` (e.g. `Button` with `to`). If omitted, use the optional
21
+ * `react-router` or `next` package entry sync components.
22
+ */
23
+ navigate?: CrudNavigateFn;
10
24
  }
11
25
  export declare const CrudComponentProvider: React.FC<CrudComponentProviderProps>;
12
26
  export default CrudComponentProvider;
@@ -1,18 +1,26 @@
1
- import { jsx as f } from "react/jsx-runtime";
2
- import o, { useRef as a, useEffect as c, createContext as m } from "react";
3
- import { setupI18n as t } from "../locale/index.es.js";
4
- const d = m({}), C = ({
5
- children: u,
6
- i18nOptions: e
1
+ import { jsx as u } from "react/jsx-runtime";
2
+ import m, { useRef as d, useEffect as l, useMemo as s, createContext as x } from "react";
3
+ import { setupI18n as o } from "../locale/index.es.js";
4
+ import { CrudNavigateProvider as C } from "./CrudNavigateContext.es.js";
5
+ const v = x({}), M = ({
6
+ children: c,
7
+ i18nOptions: e,
8
+ navigatorType: t = "react-router",
9
+ navigate: a
7
10
  }) => {
8
- const r = a(!1);
9
- return o.useMemo(() => {
10
- r.current || (t(e || {}), r.current = !0);
11
- }, []), c(() => {
12
- r.current && e && t(e);
13
- }, [e == null ? void 0 : e.language]), /* @__PURE__ */ f(d.Provider, { value: {}, children: u });
11
+ const r = d(!1);
12
+ m.useMemo(() => {
13
+ r.current || (o(e || {}), r.current = !0);
14
+ }, []), l(() => {
15
+ r.current && e && o(e);
16
+ }, [e == null ? void 0 : e.language]);
17
+ const f = s(
18
+ () => ({ navigatorType: t }),
19
+ [t]
20
+ );
21
+ return /* @__PURE__ */ u(C, { navigate: a, children: /* @__PURE__ */ u(v.Provider, { value: f, children: c }) });
14
22
  };
15
23
  export {
16
- C as CrudComponentProvider,
17
- C as default
24
+ M as CrudComponentProvider,
25
+ M as default
18
26
  };
@@ -0,0 +1 @@
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const u=require("react/jsx-runtime"),e=require("react"),a=e.createContext(void 0),o=e.createContext(()=>{});function C({children:i,navigate:t}){const[r,n]=e.useState(),s=e.useCallback(g=>{n(g)},[]),v=e.useMemo(()=>t??r,[t,r]);return u.jsx(o.Provider,{value:s,children:u.jsx(a.Provider,{value:v,children:i})})}function c(){return e.useContext(a)}function d(){return e.useContext(o)}exports.CrudNavigateProvider=C;exports.useCrudNavigateFromContext=c;exports.useCrudNavigateRegister=d;
@@ -0,0 +1,14 @@
1
+ import { ReactNode } from 'react';
2
+ /** Matches common `useNavigate()` / App Router usage used by this library. */
3
+ export type CrudNavigateFn = (to: string | number | Record<string, unknown>, options?: {
4
+ replace?: boolean;
5
+ state?: unknown;
6
+ }) => void;
7
+ type RegisterNavigateFn = (navigate: CrudNavigateFn | undefined) => void;
8
+ export declare function CrudNavigateProvider({ children, navigate: injectedNavigate, }: {
9
+ readonly children: ReactNode;
10
+ readonly navigate?: CrudNavigateFn;
11
+ }): import("react/jsx-runtime").JSX.Element;
12
+ export declare function useCrudNavigateFromContext(): CrudNavigateFn | undefined;
13
+ export declare function useCrudNavigateRegister(): RegisterNavigateFn;
14
+ export {};
@@ -0,0 +1,29 @@
1
+ import { jsx as r } from "react/jsx-runtime";
2
+ import { useState as c, useCallback as d, useMemo as x, createContext as o, useContext as a } from "react";
3
+ const n = o(
4
+ void 0
5
+ ), u = o(() => {
6
+ });
7
+ function f({
8
+ children: i,
9
+ navigate: e
10
+ }) {
11
+ const [t, s] = c(), v = d((C) => {
12
+ s(C);
13
+ }, []), g = x(
14
+ () => e ?? t,
15
+ [e, t]
16
+ );
17
+ return /* @__PURE__ */ r(u.Provider, { value: v, children: /* @__PURE__ */ r(n.Provider, { value: g, children: i }) });
18
+ }
19
+ function l() {
20
+ return a(n);
21
+ }
22
+ function p() {
23
+ return a(u);
24
+ }
25
+ export {
26
+ f as CrudNavigateProvider,
27
+ l as useCrudNavigateFromContext,
28
+ p as useCrudNavigateRegister
29
+ };
@@ -1,2 +1,3 @@
1
1
  export { default as useWindowDimensions } from './WindowDimension';
2
2
  export { CrudComponentProvider, type CrudComponentProviderProps } from './CrudComponentProvider';
3
+ export type { CrudNavigateFn } from './CrudNavigateContext';
@@ -1 +1 @@
1
- "use strict";const t=require("react/jsx-runtime"),K=require("@ant-design/icons"),s=require("antd"),i=require("react"),x=require("./CrudField.cjs.js"),Q=require("./view/CrudViewer.cjs.js"),W=require("../common/report/SelectFieldInReport.cjs.js"),V=require("./view/CrudViewerUtil.cjs.js"),X=require("../locale/index.cjs.js"),Y=require("../common/select/SelectComponent.cjs.js"),v=require("../common/button/Button.cjs.js"),Z=require("../common/button/PrintButton.cjs.js"),A={lg:6,md:8,sm:12,xs:24},E={lg:12,md:16,sm:24,xs:24};function k({fields:d,data:u,idField:L,loadingData:f,onSubmit:g,paginateProps:G,size:M,onClickPrint:h,onClickExcelExport:y,minusHeight:O,extraSearchFields:R,searchOnMount:B,summary:U,showFieldsSelectingMode:_="checkbox"}){const{t:$}=X.useTranslationLib(),{searchable:z,selectable:c,sortable:q,defaultSort:p}=i.useMemo(()=>{var b,m,N,T,I;const e=[],r=[],o=[];let n;for(const l of d.filter(J=>!J.hidden))l.type==="image"||!l.report||((b=l.report)!=null&&b.searchable&&e.push(l),(m=l.report)!=null&&m.sortable&&(r.push(l),!n&&((N=l.report)!=null&&N.defaultSort)&&(n=l)),l.hideInTable||o.push({id:l.name,label:l.label,lock:(T=l.report)==null?void 0:T.lock,alreadySelected:(I=l.report)==null?void 0:I.alreadySelected}));return{defaultSort:n,searchable:e,sortable:r,selectable:o}},[d]),[S,F]=i.useState([]),j=i.useCallback(async({sortBy:e,sortByType:r,showFields:o=[],...n})=>{const b=[];e&&b.push({field:e,sort:r??"DESC"}),F(d.filter(m=>o.includes(m.name)).map(m=>({...m,hideInTable:!1}))),g({showFields:o,sortBy:b,...n})},[d,g]),[a]=s.Form.useForm(),[w,D]=i.useState(!1),[C,H]=i.useState(!0);return i.useEffect(()=>{if(B&&C){const e=setTimeout(()=>{a.validateFields().then(r=>{j(r)}),H(!1)},200);return()=>clearTimeout(e)}},[j,a,C,B]),i.useEffect(()=>{var r,o;!a.getFieldValue("sortBy")&&p&&a.setFieldsValue({sortBy:p.name,sortByType:typeof((r=p.report)==null?void 0:r.defaultSort)=="string"?(o=p.report)==null?void 0:o.defaultSort:"ASC"})},[p,a]),i.useEffect(()=>{if(w){const e=c.filter(r=>r.alreadySelected).map(r=>r.id);F(d.filter(r=>e.includes(r.name)).map(r=>({...r,hideInTable:!1}))),D(!1)}},[d,w,c]),t.jsxs(s.Space,{className:"w-100",direction:"vertical",children:[t.jsxs(s.Form,{form:a,layout:"vertical",onFinish:j,children:[t.jsxs(s.Row,{gutter:[8,8],children:[z.map(e=>{var r,o,n;return t.jsx(s.Col,{...e.grid??A,style:{alignSelf:"end"},children:(r=e.report)!=null&&r.customRender?e.report.customRender(a):e.type==="date"?t.jsx(x.default,{...e,type:"date",range:(o=e.report)==null?void 0:o.range,required:!!((n=e.report)!=null&&n.required),readonly:!1,fieldClassName:"mb-0"}):e.type==="select"?t.jsx(x.default,{...e,type:"select",multiple:!0,required:!1,readonly:!1,fieldClassName:"mb-0"}):t.jsx(x.default,{...e,readonly:!1,required:!1,fieldClassName:"mb-0"})},e.name)}),!!(c!=null&&c.length)&&t.jsx(s.Col,{...E,children:t.jsx(W.SelectFieldInReport,{items:c,name:"showFields",mode:"multiple",label:$("str.showFields"),className:"mb-0",selectingMode:_})}),!!q.length&&t.jsx(s.Col,{...A,children:t.jsx(Y,{label:"Sort By",name:"sortBy",items:q.map(e=>({id:e.name,label:e.label})),nameFieldInArray:"label",fieldId:"id",className:"mb-0",dropdownRender:e=>t.jsxs(t.Fragment,{children:[e,t.jsx(s.Form.Item,{name:"sortByType",noStyle:!0,className:"mt-3",children:t.jsx(s.Radio.Group,{className:"w-100",defaultValue:"DESC",optionType:"button",children:t.jsxs(s.Row,{children:[t.jsx(s.Col,{xs:12,children:t.jsx(s.Radio,{className:"w-100",style:{borderTopRightRadius:0,borderBottomRightRadius:0},value:"ASC",children:"Ascending"})}),t.jsx(s.Col,{xs:12,children:t.jsx(s.Radio,{className:"w-100",style:{borderTopLeftRadius:0,borderBottomLeftRadius:0},value:"DESC",children:"Descending"})})]})})})]})})}),R?R(a):null]}),t.jsx(v,{className:"mt-3",type:"primary",block:!0,htmlType:"submit",disabled:f,children:"Submit"})]}),t.jsxs(s.Space,{children:[!!h&&t.jsx(Z.PrintButton,{disabled:f||!u.length,onClick:()=>h==null?void 0:h({tableId:"#crud-table table",data:u,fields:S.map(e=>({...e,render:V.getRendererValueCrudViewer(e)}))})}),!!y&&t.jsx(v,{disabled:f||!u.length,onClick:()=>y==null?void 0:y({tableId:"#crud-table table",data:u,fields:S.map(e=>({...e,render:V.getRendererValueCrudViewer(e)}))}),icon:t.jsx(K.FileExcelOutlined,{}),className:`group ${f||!u.length?"":"crud-excel-export-btn"}`,children:"Excel"})]}),U,t.jsx(Q,{minusHeight:O,data:u,size:M,fields:S,idField:L,loadingData:f,paginateProps:G,viewable:!1})]})}module.exports=k;
1
+ "use strict";const s=require("react/jsx-runtime"),X=require("@ant-design/icons"),o=require("antd"),d=require("react"),C=require("./CrudField.cjs.js"),Y=require("./view/CrudViewer.cjs.js"),Z=require("../common/report/SelectFieldInReport.cjs.js"),M=require("./view/CrudViewerUtil.cjs.js"),E=require("../locale/index.cjs.js"),P=require("../common/select/SelectComponent.cjs.js"),J=require("../common/button/Button.cjs.js"),ee=require("../common/button/PrintButton.cjs.js"),k={lg:6,md:8,sm:12,xs:24},te={lg:12,md:16,sm:24,xs:24};function se({fields:n,data:l,idField:f,loadingData:i,onSubmit:b,paginateProps:j,size:U,onClickPrint:w,onClickExcelExport:x,minusHeight:_,extraSearchFields:T,searchOnMount:q,summary:$,showFieldsSelectingMode:z="checkbox",cachedSearchProps:u}){const{t:D}=E.useTranslationLib(),{searchable:H,selectable:p,sortable:N,defaultSort:g}=d.useMemo(()=>{var h,y,R,O,L;const e=[],t=[],r=[];let m;for(const a of n.filter(W=>!W.hidden))a.type==="image"||!a.report||((h=a.report)!=null&&h.searchable&&e.push(a),(y=a.report)!=null&&y.sortable&&(t.push(a),!m&&((R=a.report)!=null&&R.defaultSort)&&(m=a)),a.hideInTable||r.push({id:a.name,label:a.label,lock:(O=a.report)==null?void 0:O.lock,alreadySelected:(L=a.report)==null?void 0:L.alreadySelected}));return{defaultSort:m,searchable:e,sortable:t,selectable:r}},[n]),[F,I]=d.useState([]),S=d.useCallback(e=>{I(n.filter(t=>e.includes(t.name)).map(t=>({...t,hideInTable:!1})))},[n]),B=d.useCallback(async({sortBy:e,sortByType:t,showFields:r=[],...m})=>{var R;const h=[];e&&h.push({field:e,sort:t??"DESC"}),S(r);const y={showFields:r,sortBy:h,...m};u&&(le(u.key,u.saveMode,y),(R=u.onSave)==null||R.call(u,y)),b(y)},[S,u,b]),[c]=o.Form.useForm(),V=d.useRef(!1),[v,K]=d.useState(!1),[A,Q]=d.useState(!0);return d.useEffect(()=>{if(q&&A){const e=setTimeout(()=>{c.validateFields().then(t=>{B(t)}),Q(!1)},200);return()=>clearTimeout(e)}},[B,c,A,q]),d.useEffect(()=>{var t,r;!c.getFieldValue("sortBy")&&g&&c.setFieldsValue({sortBy:g.name,sortByType:typeof((t=g.report)==null?void 0:t.defaultSort)=="string"?(r=g.report)==null?void 0:r.defaultSort:"ASC"})},[g,c]),d.useEffect(()=>{if(!u||V.current)return;V.current=!0;const e=re(u.key,u.saveMode),t={...u.defaultValue??{},...e??{}};if(Object.keys(t).length===0)return;c.setFieldsValue(oe(t));const r=t.showFields;r!=null&&r.length&&S(r)},[S,u,c]),d.useEffect(()=>{if(v){const e=p.filter(t=>t.alreadySelected).map(t=>t.id);I(n.filter(t=>e.includes(t.name)).map(t=>({...t,hideInTable:!1}))),K(!1)}},[n,v,p]),s.jsxs(o.Space,{className:"w-100",direction:"vertical",children:[s.jsxs(o.Form,{form:c,layout:"vertical",onFinish:B,children:[s.jsxs(o.Row,{gutter:[8,8],children:[H.map(e=>{var t,r,m;return s.jsx(o.Col,{...e.grid??k,style:{alignSelf:"end"},children:(t=e.report)!=null&&t.customRender?e.report.customRender(c):e.type==="date"?s.jsx(C.default,{...e,type:"date",range:(r=e.report)==null?void 0:r.range,required:!!((m=e.report)!=null&&m.required),readonly:!1,fieldClassName:"mb-0"}):e.type==="select"?s.jsx(C.default,{...e,type:"select",multiple:!0,required:!1,readonly:!1,fieldClassName:"mb-0"}):s.jsx(C.default,{...e,readonly:!1,required:!1,fieldClassName:"mb-0"})},e.name)}),!!(p!=null&&p.length)&&s.jsx(o.Col,{...te,children:s.jsx(Z.SelectFieldInReport,{items:p,name:"showFields",mode:"multiple",label:D("str.showFields"),className:"mb-0",selectingMode:z})}),!!N.length&&s.jsx(o.Col,{...k,children:s.jsx(P,{label:"Sort By",name:"sortBy",items:N.map(e=>({id:e.name,label:e.label})),nameFieldInArray:"label",fieldId:"id",className:"mb-0",dropdownRender:e=>s.jsxs(s.Fragment,{children:[e,s.jsx(o.Form.Item,{name:"sortByType",noStyle:!0,className:"mt-3",children:s.jsx(o.Radio.Group,{className:"w-100",defaultValue:"DESC",optionType:"button",children:s.jsxs(o.Row,{children:[s.jsx(o.Col,{xs:12,children:s.jsx(o.Radio,{className:"w-100",style:{borderTopRightRadius:0,borderBottomRightRadius:0},value:"ASC",children:"Ascending"})}),s.jsx(o.Col,{xs:12,children:s.jsx(o.Radio,{className:"w-100",style:{borderTopLeftRadius:0,borderBottomLeftRadius:0},value:"DESC",children:"Descending"})})]})})})]})})}),T?T(c):null]}),s.jsx(J,{className:"mt-3",type:"primary",block:!0,htmlType:"submit",disabled:i,children:"Submit"})]}),s.jsxs(o.Space,{children:[!!w&&s.jsx(ee.PrintButton,{disabled:i||!l.length,onClick:()=>w==null?void 0:w({tableId:"#crud-table table",data:l,fields:F.map(e=>({...e,render:M.getRendererValueCrudViewer(e)}))})}),!!x&&s.jsx(J,{disabled:i||!l.length,onClick:()=>x==null?void 0:x({tableId:"#crud-table table",data:l,fields:F.map(e=>({...e,render:M.getRendererValueCrudViewer(e)}))}),icon:s.jsx(X.FileExcelOutlined,{}),className:`group ${i||!l.length?"":"crud-excel-export-btn"}`,children:"Excel"})]}),$,s.jsx(Y,{minusHeight:_,data:l,size:U,fields:F,idField:f,loadingData:i,paginateProps:j,viewable:!1})]})}function G(n){return typeof globalThis.window>"u"?null:n==="local"?globalThis.window.localStorage:globalThis.window.sessionStorage}function re(n,l){const f=G(l);if(!f)return null;try{const i=f.getItem(n);return i?JSON.parse(i):null}catch{return null}}function le(n,l,f){const i=G(l);if(i)try{i.setItem(n,JSON.stringify(f))}catch{}}function oe(n){const{sortBy:l,showFields:f,...i}=n,b={...i};if(f!==void 0&&(b.showFields=f),l!=null&&l.length){const j=l[0];b.sortBy=j.field,b.sortByType=j.sort}return b}module.exports=se;
@@ -14,6 +14,14 @@ export type SearchOnlyFields<F> = CrudFieldProps<F> & {
14
14
  hideInTable: true;
15
15
  };
16
16
  export type ReportCrudFields<T, F> = CrudFieldProps<T> | SearchOnlyFields<F>;
17
+ export interface SearchPropsCacheProps<F_Search> {
18
+ key: string;
19
+ saveMode: "local" | "session";
20
+ /** Called after each successful search, once the payload is written to storage. */
21
+ onSave?: (value: CrudReportSubmitForm<F_Search>) => void;
22
+ /** Baseline when there is no cache yet (or keys missing from cache). */
23
+ defaultValue?: Partial<CrudReportSubmitForm<F_Search>>;
24
+ }
17
25
  export interface CrudReportComponentProps<T_Data, F_Search> {
18
26
  summary?: React.ReactNode;
19
27
  fields: readonly ReportCrudFields<T_Data, F_Search>[];
@@ -41,6 +49,7 @@ export interface CrudReportComponentProps<T_Data, F_Search> {
41
49
  extraSearchFields?: (form: FormInstance<any>) => ReactElement;
42
50
  searchOnMount?: boolean;
43
51
  showFieldsSelectingMode?: SelectFieldInReportSelectingMode;
52
+ cachedSearchProps?: SearchPropsCacheProps<F_Search>;
44
53
  }
45
- declare function CrudReportComponent<T, F = T>({ fields, data, idField, loadingData, onSubmit, paginateProps, size, onClickPrint, onClickExcelExport, minusHeight, extraSearchFields, searchOnMount, summary, showFieldsSelectingMode, }: Readonly<CrudReportComponentProps<T, F>>): import("react/jsx-runtime").JSX.Element;
54
+ declare function CrudReportComponent<T, F = T>({ fields, data, idField, loadingData, onSubmit, paginateProps, size, onClickPrint, onClickExcelExport, minusHeight, extraSearchFields, searchOnMount, summary, showFieldsSelectingMode, cachedSearchProps, }: Readonly<CrudReportComponentProps<T, F>>): import("react/jsx-runtime").JSX.Element;
46
55
  export default CrudReportComponent;
@@ -1,112 +1,141 @@
1
- import { jsxs as c, jsx as t, Fragment as k } from "react/jsx-runtime";
2
- import { FileExcelOutlined as E } from "@ant-design/icons";
3
- import { Form as B, Space as G, Row as M, Col as b, Radio as R } from "antd";
4
- import { useMemo as P, useState as F, useCallback as ee, useEffect as w } from "react";
5
- import N from "./CrudField.es.js";
6
- import re from "./view/CrudViewer.es.js";
7
- import { SelectFieldInReport as te } from "../common/report/SelectFieldInReport.es.js";
8
- import { getRendererValueCrudViewer as O } from "./view/CrudViewerUtil.es.js";
9
- import { useTranslationLib as le } from "../locale/index.es.js";
10
- import oe from "../common/select/SelectComponent.es.js";
11
- import _ from "../common/button/Button.es.js";
12
- import { PrintButton as se } from "../common/button/PrintButton.es.js";
13
- const $ = { lg: 6, md: 8, sm: 12, xs: 24 }, ae = { lg: 12, md: 16, sm: 24, xs: 24 };
14
- function ge({
15
- fields: i,
16
- data: n,
17
- idField: z,
18
- loadingData: u,
19
- onSubmit: T,
20
- paginateProps: D,
21
- size: H,
22
- onClickPrint: h,
23
- onClickExcelExport: y,
24
- minusHeight: J,
25
- extraSearchFields: C,
26
- searchOnMount: I,
27
- summary: K,
28
- showFieldsSelectingMode: Q = "checkbox"
1
+ import { jsxs as b, jsx as r, Fragment as re } from "react/jsx-runtime";
2
+ import { FileExcelOutlined as le } from "@ant-design/icons";
3
+ import { Form as v, Space as $, Row as k, Col as w, Radio as I } from "antd";
4
+ import { useMemo as oe, useState as V, useCallback as z, useRef as se, useEffect as T } from "react";
5
+ import q from "./CrudField.es.js";
6
+ import ne from "./view/CrudViewer.es.js";
7
+ import { SelectFieldInReport as ie } from "../common/report/SelectFieldInReport.es.js";
8
+ import { getRendererValueCrudViewer as D } from "./view/CrudViewerUtil.es.js";
9
+ import { useTranslationLib as ae } from "../locale/index.es.js";
10
+ import de from "../common/select/SelectComponent.es.js";
11
+ import H from "../common/button/Button.es.js";
12
+ import { PrintButton as ue } from "../common/button/PrintButton.es.js";
13
+ const K = { lg: 6, md: 8, sm: 12, xs: 24 }, me = { lg: 12, md: 16, sm: 24, xs: 24 };
14
+ function ve({
15
+ fields: s,
16
+ data: o,
17
+ idField: u,
18
+ loadingData: n,
19
+ onSubmit: f,
20
+ paginateProps: R,
21
+ size: U,
22
+ onClickPrint: S,
23
+ onClickExcelExport: B,
24
+ minusHeight: W,
25
+ extraSearchFields: A,
26
+ searchOnMount: O,
27
+ summary: X,
28
+ showFieldsSelectingMode: Y = "checkbox",
29
+ cachedSearchProps: a
29
30
  }) {
30
- const { t: U } = le(), { searchable: W, selectable: d, sortable: v, defaultSort: p } = P(() => {
31
- var f, m, L, j, x;
32
- const e = [], r = [], o = [];
33
- let a;
34
- for (const l of i.filter((Z) => !Z.hidden))
35
- l.type === "image" || !l.report || ((f = l.report) != null && f.searchable && e.push(l), (m = l.report) != null && m.sortable && (r.push(l), !a && ((L = l.report) != null && L.defaultSort) && (a = l)), l.hideInTable || o.push({
36
- id: l.name,
37
- label: l.label,
38
- lock: (j = l.report) == null ? void 0 : j.lock,
39
- alreadySelected: (x = l.report) == null ? void 0 : x.alreadySelected
31
+ const { t: Z } = ae(), { searchable: E, selectable: c, sortable: j, defaultSort: y } = oe(() => {
32
+ var g, p, h, G, _;
33
+ const e = [], t = [], l = [];
34
+ let m;
35
+ for (const i of s.filter((te) => !te.hidden))
36
+ i.type === "image" || !i.report || ((g = i.report) != null && g.searchable && e.push(i), (p = i.report) != null && p.sortable && (t.push(i), !m && ((h = i.report) != null && h.defaultSort) && (m = i)), i.hideInTable || l.push({
37
+ id: i.name,
38
+ label: i.label,
39
+ lock: (G = i.report) == null ? void 0 : G.lock,
40
+ alreadySelected: (_ = i.report) == null ? void 0 : _.alreadySelected
40
41
  }));
41
42
  return {
42
- defaultSort: a,
43
+ defaultSort: m,
43
44
  searchable: e,
44
- sortable: r,
45
- selectable: o
45
+ sortable: t,
46
+ selectable: l
46
47
  };
47
- }, [i]), [S, V] = F(
48
+ }, [s]), [N, L] = V(
48
49
  []
49
- ), g = ee(
50
+ ), F = z(
51
+ (e) => {
52
+ L(
53
+ s.filter((t) => e.includes(t.name)).map((t) => ({ ...t, hideInTable: !1 }))
54
+ );
55
+ },
56
+ [s]
57
+ ), C = z(
50
58
  async ({
51
59
  sortBy: e,
52
- sortByType: r,
53
- showFields: o = [],
54
- ...a
60
+ sortByType: t,
61
+ showFields: l = [],
62
+ ...m
55
63
  }) => {
56
- const f = [];
57
- e && f.push({
64
+ var h;
65
+ const g = [];
66
+ e && g.push({
58
67
  field: e,
59
- sort: r ?? "DESC"
60
- }), V(
61
- i.filter((m) => o.includes(m.name)).map((m) => ({ ...m, hideInTable: !1 }))
62
- ), T({ showFields: o, sortBy: f, ...a });
68
+ sort: t ?? "DESC"
69
+ }), F(l);
70
+ const p = { showFields: l, sortBy: g, ...m };
71
+ a && (ce(
72
+ a.key,
73
+ a.saveMode,
74
+ p
75
+ ), (h = a.onSave) == null || h.call(a, p)), f(p);
63
76
  },
64
- [i, T]
65
- ), [s] = B.useForm(), [q, X] = F(!1), [A, Y] = F(!0);
66
- return w(() => {
67
- if (I && A) {
77
+ [F, a, f]
78
+ ), [d] = v.useForm(), M = se(!1), [J, P] = V(!1), [x, ee] = V(!0);
79
+ return T(() => {
80
+ if (O && x) {
68
81
  const e = setTimeout(() => {
69
- s.validateFields().then((r) => {
70
- g(r);
71
- }), Y(!1);
82
+ d.validateFields().then((t) => {
83
+ C(t);
84
+ }), ee(!1);
72
85
  }, 200);
73
86
  return () => clearTimeout(e);
74
87
  }
75
- }, [g, s, A, I]), w(() => {
76
- var r, o;
77
- !s.getFieldValue("sortBy") && p && s.setFieldsValue({
78
- sortBy: p.name,
79
- sortByType: typeof ((r = p.report) == null ? void 0 : r.defaultSort) == "string" ? (o = p.report) == null ? void 0 : o.defaultSort : "ASC"
88
+ }, [C, d, x, O]), T(() => {
89
+ var t, l;
90
+ !d.getFieldValue("sortBy") && y && d.setFieldsValue({
91
+ sortBy: y.name,
92
+ sortByType: typeof ((t = y.report) == null ? void 0 : t.defaultSort) == "string" ? (l = y.report) == null ? void 0 : l.defaultSort : "ASC"
80
93
  });
81
- }, [p, s]), w(() => {
82
- if (q) {
83
- const e = d.filter((r) => r.alreadySelected).map((r) => r.id);
84
- V(
85
- i.filter((r) => e.includes(r.name)).map((r) => ({ ...r, hideInTable: !1 }))
86
- ), X(!1);
94
+ }, [y, d]), T(() => {
95
+ if (!a || M.current)
96
+ return;
97
+ M.current = !0;
98
+ const e = fe(
99
+ a.key,
100
+ a.saveMode
101
+ ), t = {
102
+ ...a.defaultValue ?? {},
103
+ ...e ?? {}
104
+ };
105
+ if (Object.keys(t).length === 0)
106
+ return;
107
+ d.setFieldsValue(pe(t));
108
+ const l = t.showFields;
109
+ l != null && l.length && F(l);
110
+ }, [F, a, d]), T(() => {
111
+ if (J) {
112
+ const e = c.filter((t) => t.alreadySelected).map((t) => t.id);
113
+ L(
114
+ s.filter((t) => e.includes(t.name)).map((t) => ({ ...t, hideInTable: !1 }))
115
+ ), P(!1);
87
116
  }
88
- }, [i, q, d]), /* @__PURE__ */ c(G, { className: "w-100", direction: "vertical", children: [
89
- /* @__PURE__ */ c(B, { form: s, layout: "vertical", onFinish: g, children: [
90
- /* @__PURE__ */ c(M, { gutter: [8, 8], children: [
91
- W.map((e) => {
92
- var r, o, a;
93
- return /* @__PURE__ */ t(
94
- b,
117
+ }, [s, J, c]), /* @__PURE__ */ b($, { className: "w-100", direction: "vertical", children: [
118
+ /* @__PURE__ */ b(v, { form: d, layout: "vertical", onFinish: C, children: [
119
+ /* @__PURE__ */ b(k, { gutter: [8, 8], children: [
120
+ E.map((e) => {
121
+ var t, l, m;
122
+ return /* @__PURE__ */ r(
123
+ w,
95
124
  {
96
- ...e.grid ?? $,
125
+ ...e.grid ?? K,
97
126
  style: { alignSelf: "end" },
98
- children: (r = e.report) != null && r.customRender ? e.report.customRender(s) : e.type === "date" ? /* @__PURE__ */ t(
99
- N,
127
+ children: (t = e.report) != null && t.customRender ? e.report.customRender(d) : e.type === "date" ? /* @__PURE__ */ r(
128
+ q,
100
129
  {
101
130
  ...e,
102
131
  type: "date",
103
- range: (o = e.report) == null ? void 0 : o.range,
104
- required: !!((a = e.report) != null && a.required),
132
+ range: (l = e.report) == null ? void 0 : l.range,
133
+ required: !!((m = e.report) != null && m.required),
105
134
  readonly: !1,
106
135
  fieldClassName: "mb-0"
107
136
  }
108
- ) : e.type === "select" ? /* @__PURE__ */ t(
109
- N,
137
+ ) : e.type === "select" ? /* @__PURE__ */ r(
138
+ q,
110
139
  {
111
140
  ...e,
112
141
  type: "select",
@@ -115,8 +144,8 @@ function ge({
115
144
  readonly: !1,
116
145
  fieldClassName: "mb-0"
117
146
  }
118
- ) : /* @__PURE__ */ t(
119
- N,
147
+ ) : /* @__PURE__ */ r(
148
+ q,
120
149
  {
121
150
  ...e,
122
151
  readonly: !1,
@@ -128,37 +157,37 @@ function ge({
128
157
  e.name
129
158
  );
130
159
  }),
131
- !!(d != null && d.length) && /* @__PURE__ */ t(b, { ...ae, children: /* @__PURE__ */ t(
132
- te,
160
+ !!(c != null && c.length) && /* @__PURE__ */ r(w, { ...me, children: /* @__PURE__ */ r(
161
+ ie,
133
162
  {
134
- items: d,
163
+ items: c,
135
164
  name: "showFields",
136
165
  mode: "multiple",
137
- label: U("str.showFields"),
166
+ label: Z("str.showFields"),
138
167
  className: "mb-0",
139
- selectingMode: Q
168
+ selectingMode: Y
140
169
  }
141
170
  ) }),
142
- !!v.length && /* @__PURE__ */ t(b, { ...$, children: /* @__PURE__ */ t(
143
- oe,
171
+ !!j.length && /* @__PURE__ */ r(w, { ...K, children: /* @__PURE__ */ r(
172
+ de,
144
173
  {
145
174
  label: "Sort By",
146
175
  name: "sortBy",
147
- items: v.map((e) => ({ id: e.name, label: e.label })),
176
+ items: j.map((e) => ({ id: e.name, label: e.label })),
148
177
  nameFieldInArray: "label",
149
178
  fieldId: "id",
150
179
  className: "mb-0",
151
- dropdownRender: (e) => /* @__PURE__ */ c(k, { children: [
180
+ dropdownRender: (e) => /* @__PURE__ */ b(re, { children: [
152
181
  e,
153
- /* @__PURE__ */ t(B.Item, { name: "sortByType", noStyle: !0, className: "mt-3", children: /* @__PURE__ */ t(
154
- R.Group,
182
+ /* @__PURE__ */ r(v.Item, { name: "sortByType", noStyle: !0, className: "mt-3", children: /* @__PURE__ */ r(
183
+ I.Group,
155
184
  {
156
185
  className: "w-100",
157
186
  defaultValue: "DESC",
158
187
  optionType: "button",
159
- children: /* @__PURE__ */ c(M, { children: [
160
- /* @__PURE__ */ t(b, { xs: 12, children: /* @__PURE__ */ t(
161
- R,
188
+ children: /* @__PURE__ */ b(k, { children: [
189
+ /* @__PURE__ */ r(w, { xs: 12, children: /* @__PURE__ */ r(
190
+ I,
162
191
  {
163
192
  className: "w-100",
164
193
  style: {
@@ -169,8 +198,8 @@ function ge({
169
198
  children: "Ascending"
170
199
  }
171
200
  ) }),
172
- /* @__PURE__ */ t(b, { xs: 12, children: /* @__PURE__ */ t(
173
- R,
201
+ /* @__PURE__ */ r(w, { xs: 12, children: /* @__PURE__ */ r(
202
+ I,
174
203
  {
175
204
  className: "w-100",
176
205
  style: {
@@ -187,69 +216,99 @@ function ge({
187
216
  ] })
188
217
  }
189
218
  ) }),
190
- C ? C(s) : null
219
+ A ? A(d) : null
191
220
  ] }),
192
- /* @__PURE__ */ t(
193
- _,
221
+ /* @__PURE__ */ r(
222
+ H,
194
223
  {
195
224
  className: "mt-3",
196
225
  type: "primary",
197
226
  block: !0,
198
227
  htmlType: "submit",
199
- disabled: u,
228
+ disabled: n,
200
229
  children: "Submit"
201
230
  }
202
231
  )
203
232
  ] }),
204
- /* @__PURE__ */ c(G, { children: [
205
- !!h && /* @__PURE__ */ t(
206
- se,
233
+ /* @__PURE__ */ b($, { children: [
234
+ !!S && /* @__PURE__ */ r(
235
+ ue,
207
236
  {
208
- disabled: u || !n.length,
209
- onClick: () => h == null ? void 0 : h({
237
+ disabled: n || !o.length,
238
+ onClick: () => S == null ? void 0 : S({
210
239
  tableId: "#crud-table table",
211
- data: n,
212
- fields: S.map((e) => ({
240
+ data: o,
241
+ fields: N.map((e) => ({
213
242
  ...e,
214
- render: O(e)
243
+ render: D(e)
215
244
  }))
216
245
  })
217
246
  }
218
247
  ),
219
- !!y && /* @__PURE__ */ t(
220
- _,
248
+ !!B && /* @__PURE__ */ r(
249
+ H,
221
250
  {
222
- disabled: u || !n.length,
223
- onClick: () => y == null ? void 0 : y({
251
+ disabled: n || !o.length,
252
+ onClick: () => B == null ? void 0 : B({
224
253
  tableId: "#crud-table table",
225
- data: n,
226
- fields: S.map((e) => ({
254
+ data: o,
255
+ fields: N.map((e) => ({
227
256
  ...e,
228
- render: O(e)
257
+ render: D(e)
229
258
  }))
230
259
  }),
231
- icon: /* @__PURE__ */ t(E, {}),
232
- className: `group ${u || !n.length ? "" : "crud-excel-export-btn"}`,
260
+ icon: /* @__PURE__ */ r(le, {}),
261
+ className: `group ${n || !o.length ? "" : "crud-excel-export-btn"}`,
233
262
  children: "Excel"
234
263
  }
235
264
  )
236
265
  ] }),
237
- K,
238
- /* @__PURE__ */ t(
239
- re,
266
+ X,
267
+ /* @__PURE__ */ r(
268
+ ne,
240
269
  {
241
- minusHeight: J,
242
- data: n,
243
- size: H,
244
- fields: S,
245
- idField: z,
246
- loadingData: u,
247
- paginateProps: D,
270
+ minusHeight: W,
271
+ data: o,
272
+ size: U,
273
+ fields: N,
274
+ idField: u,
275
+ loadingData: n,
276
+ paginateProps: R,
248
277
  viewable: !1
249
278
  }
250
279
  )
251
280
  ] });
252
281
  }
282
+ function Q(s) {
283
+ return typeof globalThis.window > "u" ? null : s === "local" ? globalThis.window.localStorage : globalThis.window.sessionStorage;
284
+ }
285
+ function fe(s, o) {
286
+ const u = Q(o);
287
+ if (!u)
288
+ return null;
289
+ try {
290
+ const n = u.getItem(s);
291
+ return n ? JSON.parse(n) : null;
292
+ } catch {
293
+ return null;
294
+ }
295
+ }
296
+ function ce(s, o, u) {
297
+ const n = Q(o);
298
+ if (n)
299
+ try {
300
+ n.setItem(s, JSON.stringify(u));
301
+ } catch {
302
+ }
303
+ }
304
+ function pe(s) {
305
+ const { sortBy: o, showFields: u, ...n } = s, f = { ...n };
306
+ if (u !== void 0 && (f.showFields = u), o != null && o.length) {
307
+ const R = o[0];
308
+ f.sortBy = R.field, f.sortByType = R.sort;
309
+ }
310
+ return f;
311
+ }
253
312
  export {
254
- ge as default
313
+ ve as default
255
314
  };
@@ -5,7 +5,7 @@ export { CrudForm, CrudFormFields } from './CrudForm';
5
5
  export type { CurdFormFieldsProps } from './CrudForm';
6
6
  export { default as CrudFormWizard } from './CrudFormWizard';
7
7
  export type { CrudFormWizardProps } from './CrudFormWizard';
8
- export type { CrudReportComponentProps, CrudReportSubmitForm, ReportCrudFields, SearchOnlyFields, } from './CrudReportComponent';
8
+ export type { CrudReportComponentProps, CrudReportSubmitForm, ReportCrudFields, SearchOnlyFields, SearchPropsCacheProps, } from './CrudReportComponent';
9
9
  export { default as CrudReportComponent } from './CrudReportComponent';
10
10
  export { default as CrudSearchComponent } from './CrudSearchComponent';
11
11
  export type { CrudSearchComponentProps, CrudSearchOption, } from './CrudSearchComponent';
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("react-router-dom");function o(){return e.useInRouterContext()?e.useNavigate():(t=>{console.warn("React router not found, navigating to",t)})}exports.useNavigateOptional=o;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const o=require("react"),n=require("../context/CrudNavigateContext.cjs.js"),r=(e,t)=>{typeof process<"u"&&process.env.NODE_ENV!=="production"&&console.warn("[@kingteza/crud-component] No navigator configured. Pass `navigate` to CrudComponentProvider, or render CrudReactRouterNavigateSync / CrudNextNavigateSync from the optional entry points. Attempted navigation:",e,t)};function a(){const e=n.useCrudNavigateFromContext();return o.useMemo(()=>e??r,[e])}exports.useNavigateOptional=a;
@@ -1 +1,6 @@
1
- export declare function useNavigateOptional(): import('react-router-dom').NavigateFunction;
1
+ import { CrudNavigateFn } from '../context/CrudNavigateContext';
2
+ /**
3
+ * Returns `navigate` from `CrudComponentProvider` (prop or optional sync modules).
4
+ * Falls back to a no-op that warns in development when nothing is configured.
5
+ */
6
+ export declare function useNavigateOptional(): CrudNavigateFn;
@@ -1,9 +1,16 @@
1
- import { useInRouterContext as e, useNavigate as n } from "react-router-dom";
2
- function r() {
3
- return e() ? n() : ((t) => {
4
- console.warn("React router not found, navigating to", t);
5
- });
1
+ import { useMemo as e } from "react";
2
+ import { useCrudNavigateFromContext as n } from "../context/CrudNavigateContext.es.js";
3
+ const r = (o, t) => {
4
+ typeof process < "u" && process.env.NODE_ENV !== "production" && console.warn(
5
+ "[@kingteza/crud-component] No navigator configured. Pass `navigate` to CrudComponentProvider, or render CrudReactRouterNavigateSync / CrudNextNavigateSync from the optional entry points. Attempted navigation:",
6
+ o,
7
+ t
8
+ );
9
+ };
10
+ function u() {
11
+ const o = n();
12
+ return e(() => o ?? r, [o]);
6
13
  }
7
14
  export {
8
- r as useNavigateOptional
15
+ u as useNavigateOptional
9
16
  };
package/dist/index.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  export { TRANSLATION_NAMESPACE } from './locale/hooks/translation-constants';
2
2
  export { setupI18n, updateTranslations } from './locale';
3
- export { CrudComponentProvider, type CrudComponentProviderProps } from './context';
3
+ export { CrudComponentProvider, type CrudComponentProviderProps, type CrudNavigateFn, } from './context';
4
4
  export * from './crud';
5
5
  export type * from './crud';
@@ -0,0 +1 @@
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const u=require("react"),i=require("next/navigation"),c=require("../context/CrudNavigateContext.cjs.js");function f(e){return typeof e=="string"?e:"pathname"in e&&typeof e.pathname=="string"?e.pathname:"/"}function s(){const e=i.useRouter(),t=c.useCrudNavigateRegister();return u.useLayoutEffect(()=>(t((r,n)=>{if(typeof r=="number"){r<0?e.back():r>0&&typeof e.forward=="function"&&e.forward();return}const a=f(r);n!=null&&n.replace?e.replace(a):e.push(a)}),()=>t(void 0)),[t,e]),null}exports.CrudNextNavigateSync=s;
@@ -0,0 +1,20 @@
1
+ /**
2
+ * Registers Next.js App Router navigation with {@link CrudComponentProvider}.
3
+ * Use in a client component, inside `CrudComponentProvider`, instead of installing `react-router-dom`.
4
+ *
5
+ * @example
6
+ * ```tsx
7
+ * import { CrudComponentProvider } from "@kingteza/crud-component";
8
+ * import { CrudNextNavigateSync } from "@kingteza/crud-component/next";
9
+ *
10
+ * export default function RootLayout({ children }) {
11
+ * return (
12
+ * <CrudComponentProvider navigatorType="nextjs">
13
+ * <CrudNextNavigateSync />
14
+ * {children}
15
+ * </CrudComponentProvider>
16
+ * );
17
+ * }
18
+ * ```
19
+ */
20
+ export declare function CrudNextNavigateSync(): null;
@@ -0,0 +1,20 @@
1
+ import { useLayoutEffect as f } from "react";
2
+ import { useRouter as u } from "next/navigation";
3
+ import { useCrudNavigateRegister as i } from "../context/CrudNavigateContext.es.js";
4
+ function c(e) {
5
+ return typeof e == "string" ? e : "pathname" in e && typeof e.pathname == "string" ? e.pathname : "/";
6
+ }
7
+ function g() {
8
+ const e = u(), t = i();
9
+ return f(() => (t((r, n) => {
10
+ if (typeof r == "number") {
11
+ r < 0 ? e.back() : r > 0 && typeof e.forward == "function" && e.forward();
12
+ return;
13
+ }
14
+ const a = c(r);
15
+ n != null && n.replace ? e.replace(a) : e.push(a);
16
+ }), () => t(void 0)), [t, e]), null;
17
+ }
18
+ export {
19
+ g as CrudNextNavigateSync
20
+ };
@@ -0,0 +1 @@
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const r=require("react"),u=require("react-router-dom"),a=require("../context/CrudNavigateContext.cjs.js");function o(){const t=u.useNavigate(),e=a.useCrudNavigateRegister();return r.useLayoutEffect(()=>(e(t),()=>e(void 0)),[t,e]),null}exports.CrudReactRouterNavigateSync=o;
@@ -0,0 +1,18 @@
1
+ /**
2
+ * Registers React Router’s `useNavigate` with {@link CrudComponentProvider}.
3
+ * Render once inside your `<Router>` (e.g. inside `<BrowserRouter>`), as a descendant of `CrudComponentProvider`.
4
+ *
5
+ * @example
6
+ * ```tsx
7
+ * import { CrudComponentProvider } from "@kingteza/crud-component";
8
+ * import { CrudReactRouterNavigateSync } from "@kingteza/crud-component/react-router";
9
+ *
10
+ * <CrudComponentProvider>
11
+ * <BrowserRouter>
12
+ * <CrudReactRouterNavigateSync />
13
+ * <App />
14
+ * </BrowserRouter>
15
+ * </CrudComponentProvider>
16
+ * ```
17
+ */
18
+ export declare function CrudReactRouterNavigateSync(): null;
@@ -0,0 +1,10 @@
1
+ import { useLayoutEffect as r } from "react";
2
+ import { useNavigate as o } from "react-router-dom";
3
+ import { useCrudNavigateRegister as i } from "../context/CrudNavigateContext.es.js";
4
+ function s() {
5
+ const e = o(), t = i();
6
+ return r(() => (t(e), () => t(void 0)), [e, t]), null;
7
+ }
8
+ export {
9
+ s as CrudReactRouterNavigateSync
10
+ };
@@ -0,0 +1 @@
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("./navigator/CrudNextNavigateSync.cjs.js");exports.CrudNextNavigateSync=e.CrudNextNavigateSync;
package/dist/next.d.ts ADDED
@@ -0,0 +1 @@
1
+ export { CrudNextNavigateSync } from './navigator/CrudNextNavigateSync';
@@ -0,0 +1,4 @@
1
+ import { CrudNextNavigateSync as t } from "./navigator/CrudNextNavigateSync.es.js";
2
+ export {
3
+ t as CrudNextNavigateSync
4
+ };
@@ -0,0 +1 @@
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("./navigator/CrudReactRouterNavigateSync.cjs.js");exports.CrudReactRouterNavigateSync=e.CrudReactRouterNavigateSync;
@@ -0,0 +1 @@
1
+ export { CrudReactRouterNavigateSync } from './navigator/CrudReactRouterNavigateSync';
@@ -0,0 +1,4 @@
1
+ import { CrudReactRouterNavigateSync as t } from "./navigator/CrudReactRouterNavigateSync.es.js";
2
+ export {
3
+ t as CrudReactRouterNavigateSync
4
+ };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@kingteza/crud-component",
3
3
  "private": false,
4
- "version": "1.32.0",
4
+ "version": "1.33.0",
5
5
  "description": "React CRUD component library with Ant Design",
6
6
  "keywords": [
7
7
  "react",
@@ -46,7 +46,17 @@
46
46
  "require": "./dist/util/index.cjs.js"
47
47
  },
48
48
  "./style.css": "./dist/style.css",
49
- "./styles": "./dist/style.css"
49
+ "./styles": "./dist/style.css",
50
+ "./react-router": {
51
+ "types": "./dist/react-router.d.ts",
52
+ "import": "./dist/react-router.es.js",
53
+ "require": "./dist/react-router.cjs.js"
54
+ },
55
+ "./next": {
56
+ "types": "./dist/next.d.ts",
57
+ "import": "./dist/next.es.js",
58
+ "require": "./dist/next.cjs.js"
59
+ }
50
60
  },
51
61
  "publishConfig": {
52
62
  "access": "public"
@@ -115,7 +125,8 @@
115
125
  "react": ">=18.3.1",
116
126
  "react-dom": ">=18.3.1",
117
127
  "react-i18next": "^15.2.0",
118
- "react-router-dom": ">=6.3.0"
128
+ "react-router-dom": ">=6.3.0",
129
+ "next": ">=14.0.0"
119
130
  },
120
131
  "peerDependenciesMeta": {
121
132
  "i18next": {
@@ -123,6 +134,12 @@
123
134
  },
124
135
  "react-i18next": {
125
136
  "optional": true
137
+ },
138
+ "react-router-dom": {
139
+ "optional": true
140
+ },
141
+ "next": {
142
+ "optional": true
126
143
  }
127
144
  },
128
145
  "scripts": {