@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.
- package/dist/common/report/SelectFieldInReport.cjs.js +1 -1
- package/dist/common/report/SelectFieldInReport.es.js +18 -17
- package/dist/context/CrudComponentProvider.cjs.js +1 -1
- package/dist/context/CrudComponentProvider.d.ts +14 -0
- package/dist/context/CrudComponentProvider.es.js +22 -14
- package/dist/context/CrudNavigateContext.cjs.js +1 -0
- package/dist/context/CrudNavigateContext.d.ts +14 -0
- package/dist/context/CrudNavigateContext.es.js +29 -0
- package/dist/context/index.d.ts +1 -0
- package/dist/crud/CrudReportComponent.cjs.js +1 -1
- package/dist/crud/CrudReportComponent.d.ts +10 -1
- package/dist/crud/CrudReportComponent.es.js +193 -134
- package/dist/crud/index.d.ts +1 -1
- package/dist/hooks/NavigatorHooks.cjs.js +1 -1
- package/dist/hooks/NavigatorHooks.d.ts +6 -1
- package/dist/hooks/NavigatorHooks.es.js +13 -6
- package/dist/index.d.ts +1 -1
- package/dist/navigator/CrudNextNavigateSync.cjs.js +1 -0
- package/dist/navigator/CrudNextNavigateSync.d.ts +20 -0
- package/dist/navigator/CrudNextNavigateSync.es.js +20 -0
- package/dist/navigator/CrudReactRouterNavigateSync.cjs.js +1 -0
- package/dist/navigator/CrudReactRouterNavigateSync.d.ts +18 -0
- package/dist/navigator/CrudReactRouterNavigateSync.es.js +10 -0
- package/dist/next.cjs.js +1 -0
- package/dist/next.d.ts +1 -0
- package/dist/next.es.js +4 -0
- package/dist/react-router.cjs.js +1 -0
- package/dist/react-router.d.ts +1 -0
- package/dist/react-router.es.js +4 -0
- package/package.json +20 -3
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const t=require("react/jsx-runtime"),
|
|
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
|
|
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
|
|
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:
|
|
14
|
+
selectingMode: O
|
|
15
15
|
}) => {
|
|
16
|
-
const l = S.useFormInstance(), [
|
|
16
|
+
const l = S.useFormInstance(), [m, g] = f(!0);
|
|
17
17
|
G(() => {
|
|
18
|
-
if (r &&
|
|
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
|
-
}),
|
|
22
|
+
}), g(!1);
|
|
23
23
|
}
|
|
24
|
-
}, [
|
|
25
|
-
const [
|
|
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]:
|
|
27
|
+
[o]: b
|
|
28
28
|
});
|
|
29
|
-
}, [
|
|
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 =
|
|
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:
|
|
47
|
-
onCancel:
|
|
48
|
-
onOk:
|
|
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(
|
|
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(
|
|
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
|
-
|
|
96
|
+
K as SelectFieldInReport
|
|
96
97
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const
|
|
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
|
|
2
|
-
import
|
|
3
|
-
import { setupI18n as
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
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 =
|
|
9
|
-
|
|
10
|
-
r.current || (
|
|
11
|
-
}, []),
|
|
12
|
-
r.current && e &&
|
|
13
|
-
}, [e == null ? void 0 : e.language])
|
|
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
|
-
|
|
17
|
-
|
|
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
|
+
};
|
package/dist/context/index.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";const
|
|
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
|
|
2
|
-
import { FileExcelOutlined as
|
|
3
|
-
import { Form as
|
|
4
|
-
import { useMemo as
|
|
5
|
-
import
|
|
6
|
-
import
|
|
7
|
-
import { SelectFieldInReport as
|
|
8
|
-
import { getRendererValueCrudViewer as
|
|
9
|
-
import { useTranslationLib as
|
|
10
|
-
import
|
|
11
|
-
import
|
|
12
|
-
import { PrintButton as
|
|
13
|
-
const
|
|
14
|
-
function
|
|
15
|
-
fields:
|
|
16
|
-
data:
|
|
17
|
-
idField:
|
|
18
|
-
loadingData:
|
|
19
|
-
onSubmit:
|
|
20
|
-
paginateProps:
|
|
21
|
-
size:
|
|
22
|
-
onClickPrint:
|
|
23
|
-
onClickExcelExport:
|
|
24
|
-
minusHeight:
|
|
25
|
-
extraSearchFields:
|
|
26
|
-
searchOnMount:
|
|
27
|
-
summary:
|
|
28
|
-
showFieldsSelectingMode:
|
|
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:
|
|
31
|
-
var
|
|
32
|
-
const e = [],
|
|
33
|
-
let
|
|
34
|
-
for (const
|
|
35
|
-
|
|
36
|
-
id:
|
|
37
|
-
label:
|
|
38
|
-
lock: (
|
|
39
|
-
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:
|
|
43
|
+
defaultSort: m,
|
|
43
44
|
searchable: e,
|
|
44
|
-
sortable:
|
|
45
|
-
selectable:
|
|
45
|
+
sortable: t,
|
|
46
|
+
selectable: l
|
|
46
47
|
};
|
|
47
|
-
}, [
|
|
48
|
+
}, [s]), [N, L] = V(
|
|
48
49
|
[]
|
|
49
|
-
),
|
|
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:
|
|
53
|
-
showFields:
|
|
54
|
-
...
|
|
60
|
+
sortByType: t,
|
|
61
|
+
showFields: l = [],
|
|
62
|
+
...m
|
|
55
63
|
}) => {
|
|
56
|
-
|
|
57
|
-
|
|
64
|
+
var h;
|
|
65
|
+
const g = [];
|
|
66
|
+
e && g.push({
|
|
58
67
|
field: e,
|
|
59
|
-
sort:
|
|
60
|
-
}),
|
|
61
|
-
|
|
62
|
-
|
|
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
|
-
[
|
|
65
|
-
), [
|
|
66
|
-
return
|
|
67
|
-
if (
|
|
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
|
-
|
|
70
|
-
|
|
71
|
-
}),
|
|
82
|
+
d.validateFields().then((t) => {
|
|
83
|
+
C(t);
|
|
84
|
+
}), ee(!1);
|
|
72
85
|
}, 200);
|
|
73
86
|
return () => clearTimeout(e);
|
|
74
87
|
}
|
|
75
|
-
}, [
|
|
76
|
-
var
|
|
77
|
-
!
|
|
78
|
-
sortBy:
|
|
79
|
-
sortByType: typeof ((
|
|
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
|
-
}, [
|
|
82
|
-
if (
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
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
|
-
}, [
|
|
89
|
-
/* @__PURE__ */
|
|
90
|
-
/* @__PURE__ */
|
|
91
|
-
|
|
92
|
-
var
|
|
93
|
-
return /* @__PURE__ */
|
|
94
|
-
|
|
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: (
|
|
99
|
-
|
|
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: (
|
|
104
|
-
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__ */
|
|
109
|
-
|
|
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__ */
|
|
119
|
-
|
|
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
|
-
!!(
|
|
132
|
-
|
|
160
|
+
!!(c != null && c.length) && /* @__PURE__ */ r(w, { ...me, children: /* @__PURE__ */ r(
|
|
161
|
+
ie,
|
|
133
162
|
{
|
|
134
|
-
items:
|
|
163
|
+
items: c,
|
|
135
164
|
name: "showFields",
|
|
136
165
|
mode: "multiple",
|
|
137
|
-
label:
|
|
166
|
+
label: Z("str.showFields"),
|
|
138
167
|
className: "mb-0",
|
|
139
|
-
selectingMode:
|
|
168
|
+
selectingMode: Y
|
|
140
169
|
}
|
|
141
170
|
) }),
|
|
142
|
-
!!
|
|
143
|
-
|
|
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:
|
|
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__ */
|
|
180
|
+
dropdownRender: (e) => /* @__PURE__ */ b(re, { children: [
|
|
152
181
|
e,
|
|
153
|
-
/* @__PURE__ */
|
|
154
|
-
|
|
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__ */
|
|
160
|
-
/* @__PURE__ */
|
|
161
|
-
|
|
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__ */
|
|
173
|
-
|
|
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
|
-
|
|
219
|
+
A ? A(d) : null
|
|
191
220
|
] }),
|
|
192
|
-
/* @__PURE__ */
|
|
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:
|
|
228
|
+
disabled: n,
|
|
200
229
|
children: "Submit"
|
|
201
230
|
}
|
|
202
231
|
)
|
|
203
232
|
] }),
|
|
204
|
-
/* @__PURE__ */
|
|
205
|
-
!!
|
|
206
|
-
|
|
233
|
+
/* @__PURE__ */ b($, { children: [
|
|
234
|
+
!!S && /* @__PURE__ */ r(
|
|
235
|
+
ue,
|
|
207
236
|
{
|
|
208
|
-
disabled:
|
|
209
|
-
onClick: () =>
|
|
237
|
+
disabled: n || !o.length,
|
|
238
|
+
onClick: () => S == null ? void 0 : S({
|
|
210
239
|
tableId: "#crud-table table",
|
|
211
|
-
data:
|
|
212
|
-
fields:
|
|
240
|
+
data: o,
|
|
241
|
+
fields: N.map((e) => ({
|
|
213
242
|
...e,
|
|
214
|
-
render:
|
|
243
|
+
render: D(e)
|
|
215
244
|
}))
|
|
216
245
|
})
|
|
217
246
|
}
|
|
218
247
|
),
|
|
219
|
-
!!
|
|
220
|
-
|
|
248
|
+
!!B && /* @__PURE__ */ r(
|
|
249
|
+
H,
|
|
221
250
|
{
|
|
222
|
-
disabled:
|
|
223
|
-
onClick: () =>
|
|
251
|
+
disabled: n || !o.length,
|
|
252
|
+
onClick: () => B == null ? void 0 : B({
|
|
224
253
|
tableId: "#crud-table table",
|
|
225
|
-
data:
|
|
226
|
-
fields:
|
|
254
|
+
data: o,
|
|
255
|
+
fields: N.map((e) => ({
|
|
227
256
|
...e,
|
|
228
|
-
render:
|
|
257
|
+
render: D(e)
|
|
229
258
|
}))
|
|
230
259
|
}),
|
|
231
|
-
icon: /* @__PURE__ */
|
|
232
|
-
className: `group ${
|
|
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
|
-
|
|
238
|
-
/* @__PURE__ */
|
|
239
|
-
|
|
266
|
+
X,
|
|
267
|
+
/* @__PURE__ */ r(
|
|
268
|
+
ne,
|
|
240
269
|
{
|
|
241
|
-
minusHeight:
|
|
242
|
-
data:
|
|
243
|
-
size:
|
|
244
|
-
fields:
|
|
245
|
-
idField:
|
|
246
|
-
loadingData:
|
|
247
|
-
paginateProps:
|
|
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
|
-
|
|
313
|
+
ve as default
|
|
255
314
|
};
|
package/dist/crud/index.d.ts
CHANGED
|
@@ -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
|
|
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
|
-
|
|
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 {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
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
|
-
|
|
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
|
+
};
|
package/dist/next.cjs.js
ADDED
|
@@ -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';
|
package/dist/next.es.js
ADDED
|
@@ -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';
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kingteza/crud-component",
|
|
3
3
|
"private": false,
|
|
4
|
-
"version": "1.
|
|
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": {
|