@akanjs/ui 0.0.149 → 0.0.151
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/BottomSheet.d.ts +13 -0
- package/Button.d.ts +9 -0
- package/ClientSide.d.ts +6 -0
- package/Copy.d.ts +6 -0
- package/CsrImage.d.ts +11 -0
- package/Data/CardList.d.ts +36 -0
- package/Data/Dashboard.d.ts +15 -0
- package/Data/Insight.d.ts +8 -0
- package/Data/Item.d.ts +74 -0
- package/Data/ListContainer.d.ts +38 -0
- package/Data/Pagination.d.ts +6 -0
- package/Data/QueryMaker.d.ts +9 -0
- package/Data/TableList.d.ts +26 -0
- package/Data/index.d.ts +10 -0
- package/Data/index_.d.ts +8 -0
- package/DatePicker.d.ts +38 -0
- package/Dialog/Action.d.ts +5 -0
- package/Dialog/Close.d.ts +5 -0
- package/Dialog/Content.d.ts +6 -0
- package/Dialog/Modal.d.ts +8 -0
- package/Dialog/Provider.d.ts +7 -0
- package/Dialog/Title.d.ts +5 -0
- package/Dialog/Trigger.d.ts +5 -0
- package/Dialog/context.d.ts +10 -0
- package/Dialog/index.d.ts +9 -0
- package/DragAction.d.ts +24 -0
- package/DraggableList.d.ts +25 -0
- package/Dropdown.d.ts +10 -0
- package/Empty.d.ts +9 -0
- package/Field.d.ts +404 -0
- package/FontFace.d.ts +6 -0
- package/Image.d.ts +17 -0
- package/InfiniteScroll.d.ts +10 -0
- package/Input.d.ts +85 -0
- package/KeyboardAvoiding.d.ts +7 -0
- package/Layout/BottomAction.d.ts +5 -0
- package/Layout/BottomInset.d.ts +6 -0
- package/Layout/BottomTab.d.ts +14 -0
- package/Layout/Header.d.ts +7 -0
- package/Layout/LeftSider.d.ts +8 -0
- package/Layout/Navbar.d.ts +11 -0
- package/Layout/RightSider.d.ts +9 -0
- package/Layout/Sider.d.ts +6 -0
- package/Layout/Template.d.ts +5 -0
- package/Layout/TopLeftAction.d.ts +5 -0
- package/Layout/Unit.d.ts +6 -0
- package/Layout/View.d.ts +5 -0
- package/Layout/Zone.d.ts +5 -0
- package/Layout/index.d.ts +14 -0
- package/Link/Back.d.ts +6 -0
- package/Link/Close.d.ts +6 -0
- package/Link/CsrLink.d.ts +2 -0
- package/Link/NextLink.d.ts +2 -0
- package/Link/index.d.ts +8 -0
- package/Link/types.d.ts +22 -0
- package/Load/Edit.d.ts +4 -0
- package/Load/Edit_Client.d.ts +25 -0
- package/Load/Page.d.ts +10 -0
- package/Load/PageCSR.d.ts +11 -0
- package/Load/Pagination.d.ts +8 -0
- package/Load/Units.d.ts +34 -0
- package/Load/View.d.ts +17 -0
- package/Load/index.d.ts +8 -0
- package/Load/index_.d.ts +3 -0
- package/Loading/Area.d.ts +1 -0
- package/Loading/Button.d.ts +7 -0
- package/Loading/Input.d.ts +7 -0
- package/Loading/ProgressBar.d.ts +6 -0
- package/Loading/Skeleton.d.ts +7 -0
- package/Loading/Spin.d.ts +7 -0
- package/Loading/index.d.ts +8 -0
- package/Menu.d.ts +26 -0
- package/Modal.d.ts +23 -0
- package/Model/Edit.d.ts +15 -0
- package/Model/EditModal.d.ts +33 -0
- package/Model/EditWrapper.d.ts +11 -0
- package/Model/LoadInit.d.ts +10 -0
- package/Model/New.d.ts +15 -0
- package/Model/NewWrapper.d.ts +12 -0
- package/Model/NewWrapper_Client.d.ts +12 -0
- package/Model/Remove.d.ts +10 -0
- package/Model/RemoveWrapper.d.ts +11 -0
- package/Model/SureToRemove.d.ts +10 -0
- package/Model/View.d.ts +19 -0
- package/Model/ViewEditModal.d.ts +11 -0
- package/Model/ViewModal.d.ts +13 -0
- package/Model/ViewWrapper.d.ts +11 -0
- package/Model/index.d.ts +15 -0
- package/Model/index_.d.ts +13 -0
- package/More.d.ts +12 -0
- package/ObjectId.d.ts +5 -0
- package/Pagination.d.ts +14 -0
- package/Popconfirm.d.ts +18 -0
- package/Portal.d.ts +6 -0
- package/Radio.d.ts +19 -0
- package/RecentTime.d.ts +7 -0
- package/Refresh.d.ts +7 -0
- package/ScreenNavigator.d.ts +18 -0
- package/Select.d.ts +29 -0
- package/Signal/Arg.d.ts +75 -0
- package/Signal/Doc.d.ts +19 -0
- package/Signal/GraphQL.d.ts +32 -0
- package/Signal/Listener.d.ts +9 -0
- package/Signal/Message.d.ts +27 -0
- package/Signal/Object.d.ts +19 -0
- package/Signal/PubSub.d.ts +26 -0
- package/Signal/Request.d.ts +8 -0
- package/Signal/Response.d.ts +16 -0
- package/Signal/RestApi.d.ts +40 -0
- package/Signal/WebSocket.d.ts +9 -0
- package/Signal/index.d.ts +20 -0
- package/System/CSR.d.ts +31 -0
- package/System/Client.d.ts +48 -0
- package/System/Common.d.ts +66 -0
- package/System/DevModeToggle.d.ts +1 -0
- package/System/Gtag.d.ts +3 -0
- package/System/HealthCheck.d.ts +5 -0
- package/System/Messages.d.ts +1 -0
- package/System/Reconnect.d.ts +6 -0
- package/System/Root.d.ts +5 -0
- package/System/SSR.d.ts +26 -0
- package/System/SelectLanguage.d.ts +5 -0
- package/System/ThemeToggle.d.ts +1 -0
- package/System/index.d.ts +11 -0
- package/Tab/Menu.d.ts +11 -0
- package/Tab/Menus.d.ts +5 -0
- package/Tab/Panel.d.ts +7 -0
- package/Tab/Provider.d.ts +6 -0
- package/Tab/context.d.ts +9 -0
- package/Tab/index.d.ts +7 -0
- package/Table.d.ts +26 -0
- package/ToggleSelect.d.ts +31 -0
- package/Unauthorized.d.ts +9 -0
- package/cjs/BottomSheet.js +113 -0
- package/cjs/Button.js +69 -0
- package/cjs/ClientSide.js +26 -0
- package/cjs/Copy.js +37 -0
- package/cjs/CsrImage.js +50 -0
- package/cjs/Data/CardList.js +119 -0
- package/cjs/Data/Dashboard.js +54 -0
- package/cjs/Data/Insight.js +38 -0
- package/cjs/Data/Item.js +204 -0
- package/cjs/Data/ListContainer.js +251 -0
- package/cjs/Data/Pagination.js +64 -0
- package/cjs/Data/QueryMaker.js +304 -0
- package/cjs/Data/TableList.js +139 -0
- package/cjs/Data/index.js +33 -0
- package/cjs/Data/index_.js +49 -0
- package/cjs/DatePicker.js +173 -0
- package/cjs/Dialog/Action.js +32 -0
- package/cjs/Dialog/Close.js +38 -0
- package/cjs/Dialog/Content.js +27 -0
- package/cjs/Dialog/Modal.js +155 -0
- package/cjs/Dialog/Provider.js +46 -0
- package/cjs/Dialog/Title.js +32 -0
- package/cjs/Dialog/Trigger.js +38 -0
- package/cjs/Dialog/context.js +32 -0
- package/cjs/Dialog/index.js +36 -0
- package/cjs/DragAction.js +111 -0
- package/cjs/DraggableList.js +141 -0
- package/cjs/Dropdown.js +64 -0
- package/cjs/Empty.js +50 -0
- package/cjs/Field.js +1109 -0
- package/cjs/FontFace.js +77 -0
- package/cjs/Image.js +61 -0
- package/cjs/InfiniteScroll.js +65 -0
- package/cjs/Input.js +440 -0
- package/cjs/KeyboardAvoiding.js +65 -0
- package/cjs/Layout/BottomAction.js +26 -0
- package/cjs/Layout/BottomInset.js +53 -0
- package/cjs/Layout/BottomTab.js +56 -0
- package/cjs/Layout/Header.js +52 -0
- package/cjs/Layout/LeftSider.js +49 -0
- package/cjs/Layout/Navbar.js +51 -0
- package/cjs/Layout/RightSider.js +52 -0
- package/cjs/Layout/Sider.js +39 -0
- package/cjs/Layout/Template.js +26 -0
- package/cjs/Layout/TopLeftAction.js +39 -0
- package/cjs/Layout/Unit.js +27 -0
- package/cjs/Layout/View.js +26 -0
- package/cjs/Layout/Zone.js +26 -0
- package/cjs/Layout/index.js +48 -0
- package/cjs/Link/Back.js +27 -0
- package/cjs/Link/Close.js +36 -0
- package/cjs/Link/CsrLink.js +49 -0
- package/cjs/Link/NextLink.js +71 -0
- package/cjs/Link/index.js +47 -0
- package/cjs/Link/types.js +15 -0
- package/cjs/Load/Edit.js +42 -0
- package/cjs/Load/Edit_Client.js +93 -0
- package/cjs/Load/Page.js +35 -0
- package/cjs/Load/PageCSR.js +67 -0
- package/cjs/Load/Pagination.js +89 -0
- package/cjs/Load/Units.js +232 -0
- package/cjs/Load/View.js +88 -0
- package/cjs/Load/index.js +42 -0
- package/cjs/Load/index_.js +39 -0
- package/cjs/Loading/Area.js +25 -0
- package/cjs/Loading/Button.js +33 -0
- package/cjs/Loading/Input.js +33 -0
- package/cjs/Loading/ProgressBar.js +29 -0
- package/cjs/Loading/Skeleton.js +27 -0
- package/cjs/Loading/Spin.js +27 -0
- package/cjs/Loading/index.js +29 -0
- package/cjs/Menu.js +215 -0
- package/cjs/Modal.js +75 -0
- package/cjs/Model/Edit.js +61 -0
- package/cjs/Model/EditModal.js +255 -0
- package/cjs/Model/EditWrapper.js +48 -0
- package/cjs/Model/LoadInit.js +27 -0
- package/cjs/Model/New.js +61 -0
- package/cjs/Model/NewWrapper.js +28 -0
- package/cjs/Model/NewWrapper_Client.js +66 -0
- package/cjs/Model/Remove.js +86 -0
- package/cjs/Model/RemoveWrapper.js +48 -0
- package/cjs/Model/SureToRemove.js +109 -0
- package/cjs/Model/View.js +44 -0
- package/cjs/Model/ViewEditModal.js +118 -0
- package/cjs/Model/ViewModal.js +92 -0
- package/cjs/Model/ViewWrapper.js +48 -0
- package/cjs/Model/index.js +38 -0
- package/cjs/Model/index_.js +58 -0
- package/cjs/More.js +67 -0
- package/cjs/ObjectId.js +37 -0
- package/cjs/Pagination.js +110 -0
- package/cjs/Popconfirm.js +116 -0
- package/cjs/Portal.js +27 -0
- package/cjs/Radio.js +53 -0
- package/cjs/RecentTime.js +86 -0
- package/cjs/Refresh.js +45 -0
- package/cjs/ScreenNavigator.js +121 -0
- package/cjs/Select.js +262 -0
- package/cjs/Signal/Arg.js +237 -0
- package/cjs/Signal/Doc.js +181 -0
- package/cjs/Signal/GraphQL.js +177 -0
- package/cjs/Signal/Listener.js +59 -0
- package/cjs/Signal/Message.js +190 -0
- package/cjs/Signal/Object.js +95 -0
- package/cjs/Signal/PubSub.js +191 -0
- package/cjs/Signal/Request.js +38 -0
- package/cjs/Signal/Response.js +53 -0
- package/cjs/Signal/RestApi.js +255 -0
- package/cjs/Signal/WebSocket.js +68 -0
- package/cjs/Signal/index.js +42 -0
- package/cjs/System/CSR.js +376 -0
- package/cjs/System/Client.js +200 -0
- package/cjs/System/Common.js +64 -0
- package/cjs/System/DevModeToggle.js +38 -0
- package/cjs/System/Gtag.js +67 -0
- package/cjs/System/HealthCheck.js +60 -0
- package/cjs/System/Messages.js +170 -0
- package/cjs/System/Reconnect.js +64 -0
- package/cjs/System/Root.js +30 -0
- package/cjs/System/SSR.js +144 -0
- package/cjs/System/SelectLanguage.js +58 -0
- package/cjs/System/ThemeToggle.js +40 -0
- package/cjs/System/index.js +55 -0
- package/cjs/Tab/Menu.js +70 -0
- package/cjs/{src/index.js → Tab/Menus.js} +8 -5
- package/cjs/Tab/Panel.js +42 -0
- package/cjs/Tab/Provider.js +31 -0
- package/cjs/Tab/context.js +30 -0
- package/cjs/Tab/index.js +32 -0
- package/cjs/Table.js +85 -0
- package/cjs/ToggleSelect.js +118 -0
- package/cjs/Unauthorized.js +50 -0
- package/cjs/index.js +88 -2
- package/esm/BottomSheet.js +84 -0
- package/esm/Button.js +40 -0
- package/esm/ClientSide.js +7 -0
- package/esm/Copy.js +18 -0
- package/esm/CsrImage.js +31 -0
- package/esm/Data/CardList.js +90 -0
- package/esm/Data/Dashboard.js +35 -0
- package/esm/Data/Insight.js +19 -0
- package/esm/Data/Item.js +175 -0
- package/esm/Data/ListContainer.js +228 -0
- package/esm/Data/Pagination.js +45 -0
- package/esm/Data/QueryMaker.js +293 -0
- package/esm/Data/TableList.js +110 -0
- package/esm/Data/index.js +14 -0
- package/esm/Data/index_.js +20 -0
- package/esm/DatePicker.js +144 -0
- package/esm/Dialog/Action.js +13 -0
- package/esm/Dialog/Close.js +19 -0
- package/esm/Dialog/Content.js +8 -0
- package/esm/Dialog/Modal.js +126 -0
- package/esm/Dialog/Provider.js +17 -0
- package/esm/Dialog/Title.js +13 -0
- package/esm/Dialog/Trigger.js +19 -0
- package/esm/Dialog/context.js +13 -0
- package/esm/Dialog/index.js +17 -0
- package/esm/DragAction.js +92 -0
- package/esm/DraggableList.js +112 -0
- package/esm/Dropdown.js +45 -0
- package/esm/Empty.js +21 -0
- package/esm/Field.js +1090 -0
- package/esm/FontFace.js +58 -0
- package/esm/Image.js +32 -0
- package/esm/InfiniteScroll.js +46 -0
- package/esm/Input.js +415 -0
- package/esm/KeyboardAvoiding.js +46 -0
- package/esm/Layout/BottomAction.js +7 -0
- package/esm/Layout/BottomInset.js +34 -0
- package/esm/Layout/BottomTab.js +37 -0
- package/esm/Layout/Header.js +33 -0
- package/esm/Layout/LeftSider.js +30 -0
- package/esm/Layout/Navbar.js +22 -0
- package/esm/Layout/RightSider.js +33 -0
- package/esm/Layout/Sider.js +20 -0
- package/esm/Layout/Template.js +7 -0
- package/esm/Layout/TopLeftAction.js +20 -0
- package/esm/Layout/Unit.js +8 -0
- package/esm/Layout/View.js +7 -0
- package/esm/Layout/Zone.js +7 -0
- package/esm/Layout/index.js +29 -0
- package/esm/Link/Back.js +8 -0
- package/esm/Link/Close.js +17 -0
- package/esm/Link/CsrLink.js +30 -0
- package/esm/Link/NextLink.js +42 -0
- package/esm/Link/index.js +18 -0
- package/esm/Link/types.js +0 -0
- package/esm/Load/Edit.js +13 -0
- package/esm/Load/Edit_Client.js +74 -0
- package/esm/Load/Page.js +16 -0
- package/esm/Load/PageCSR.js +48 -0
- package/esm/Load/Pagination.js +70 -0
- package/esm/Load/Units.js +213 -0
- package/esm/Load/View.js +69 -0
- package/esm/Load/index.js +13 -0
- package/esm/Load/index_.js +10 -0
- package/esm/Loading/Area.js +6 -0
- package/esm/Loading/Button.js +14 -0
- package/esm/Loading/Input.js +14 -0
- package/esm/Loading/ProgressBar.js +10 -0
- package/esm/Loading/Skeleton.js +8 -0
- package/esm/Loading/Spin.js +8 -0
- package/esm/Loading/index.js +10 -0
- package/esm/Menu.js +196 -0
- package/esm/Modal.js +46 -0
- package/esm/Model/Edit.js +32 -0
- package/esm/Model/EditModal.js +226 -0
- package/esm/Model/EditWrapper.js +29 -0
- package/esm/Model/LoadInit.js +8 -0
- package/esm/Model/New.js +32 -0
- package/esm/Model/NewWrapper.js +9 -0
- package/esm/Model/NewWrapper_Client.js +47 -0
- package/esm/Model/Remove.js +67 -0
- package/esm/Model/RemoveWrapper.js +29 -0
- package/esm/Model/SureToRemove.js +90 -0
- package/esm/Model/View.js +25 -0
- package/esm/Model/ViewEditModal.js +89 -0
- package/esm/Model/ViewModal.js +63 -0
- package/esm/Model/ViewWrapper.js +29 -0
- package/esm/Model/index.js +33 -0
- package/esm/Model/index_.js +29 -0
- package/esm/More.js +38 -0
- package/esm/ObjectId.js +18 -0
- package/esm/Pagination.js +91 -0
- package/esm/Popconfirm.js +87 -0
- package/esm/Portal.js +8 -0
- package/esm/Radio.js +34 -0
- package/esm/RecentTime.js +57 -0
- package/esm/Refresh.js +16 -0
- package/esm/ScreenNavigator.js +102 -0
- package/esm/Select.js +243 -0
- package/esm/Signal/Arg.js +208 -0
- package/esm/Signal/Doc.js +152 -0
- package/esm/Signal/GraphQL.js +156 -0
- package/esm/Signal/Listener.js +40 -0
- package/esm/Signal/Message.js +161 -0
- package/esm/Signal/Object.js +76 -0
- package/esm/Signal/PubSub.js +162 -0
- package/esm/Signal/Request.js +19 -0
- package/esm/Signal/Response.js +34 -0
- package/esm/Signal/RestApi.js +234 -0
- package/esm/Signal/WebSocket.js +39 -0
- package/esm/Signal/index.js +13 -0
- package/esm/System/CSR.js +357 -0
- package/esm/System/Client.js +191 -0
- package/esm/System/Common.js +45 -0
- package/esm/System/DevModeToggle.js +19 -0
- package/esm/System/Gtag.js +48 -0
- package/esm/System/HealthCheck.js +41 -0
- package/esm/System/Messages.js +156 -0
- package/esm/System/Reconnect.js +45 -0
- package/esm/System/Root.js +11 -0
- package/esm/System/SSR.js +125 -0
- package/esm/System/SelectLanguage.js +39 -0
- package/esm/System/ThemeToggle.js +21 -0
- package/esm/System/index.js +26 -0
- package/esm/Tab/Menu.js +51 -0
- package/esm/Tab/Menus.js +7 -0
- package/esm/Tab/Panel.js +23 -0
- package/esm/Tab/Provider.js +12 -0
- package/esm/Tab/context.js +11 -0
- package/esm/Tab/index.js +13 -0
- package/esm/Table.js +56 -0
- package/esm/ToggleSelect.js +99 -0
- package/esm/Unauthorized.js +21 -0
- package/esm/index.js +84 -1
- package/index.d.ts +41 -1
- package/package.json +23 -2
- package/esm/src/index.js +0 -4
- package/src/index.d.ts +0 -1
|
@@ -0,0 +1,226 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { clsx, router } from "@akanjs/client";
|
|
3
|
+
import { capitalize, deepObjectify, lowerlize } from "@akanjs/common";
|
|
4
|
+
import { getFullModelRef } from "@akanjs/constant";
|
|
5
|
+
import { useDebounce, usePage } from "@akanjs/next";
|
|
6
|
+
import { fetch, immerify } from "@akanjs/signal";
|
|
7
|
+
import { st } from "@akanjs/store";
|
|
8
|
+
import React, { use, useCallback, useEffect, useMemo } from "react";
|
|
9
|
+
import { AiOutlinePlus, AiOutlineSave } from "react-icons/ai";
|
|
10
|
+
import { Button } from "../Button";
|
|
11
|
+
import { Modal } from "../Modal";
|
|
12
|
+
const EditModel = ({
|
|
13
|
+
type = "modal",
|
|
14
|
+
sliceName,
|
|
15
|
+
className,
|
|
16
|
+
checkSubmit = true,
|
|
17
|
+
edit,
|
|
18
|
+
modal,
|
|
19
|
+
children,
|
|
20
|
+
loadingWrapper
|
|
21
|
+
}) => {
|
|
22
|
+
const storeUse = st.use;
|
|
23
|
+
const storeDo = st.do;
|
|
24
|
+
const refName = st.slice[sliceName].refName;
|
|
25
|
+
const [modelName, ModelName] = useMemo(() => [lowerlize(refName), capitalize(refName)], []);
|
|
26
|
+
const names = useMemo(
|
|
27
|
+
() => ({
|
|
28
|
+
model: modelName,
|
|
29
|
+
Model: ModelName,
|
|
30
|
+
modelForm: `${modelName}Form`,
|
|
31
|
+
modelFormLoading: `${modelName}FormLoading`,
|
|
32
|
+
modelModal: `${modelName}Modal`,
|
|
33
|
+
checkModelSubmitable: `check${ModelName}Submitable`
|
|
34
|
+
}),
|
|
35
|
+
[]
|
|
36
|
+
);
|
|
37
|
+
const modelModal = storeUse[names.modelModal]();
|
|
38
|
+
const modelForm = storeUse[names.modelForm]();
|
|
39
|
+
const checkSubmitable = useDebounce(() => {
|
|
40
|
+
storeDo[names.checkModelSubmitable]();
|
|
41
|
+
});
|
|
42
|
+
useEffect(() => {
|
|
43
|
+
if (checkSubmit)
|
|
44
|
+
checkSubmitable();
|
|
45
|
+
}, [modelModal, modelForm]);
|
|
46
|
+
const LoadingWrapper = useMemo(() => {
|
|
47
|
+
return loadingWrapper === false ? ({ children: children2, className: className2 }) => children2 : typeof loadingWrapper === "function" ? loadingWrapper : ({ children: children2, className: className2 }) => {
|
|
48
|
+
const modelFormLoading = storeUse[names.modelFormLoading]();
|
|
49
|
+
return /* @__PURE__ */ React.createElement("div", { className: clsx("", className2) }, children2, modelFormLoading ? /* @__PURE__ */ React.createElement("div", { className: "bg-base-100/50 absolute inset-0 animate-pulse" }) : null);
|
|
50
|
+
};
|
|
51
|
+
}, []);
|
|
52
|
+
return /* @__PURE__ */ React.createElement(LoadingWrapper, { className: clsx("w-full", className) }, children);
|
|
53
|
+
};
|
|
54
|
+
function EditModal({
|
|
55
|
+
type = "modal",
|
|
56
|
+
sliceName,
|
|
57
|
+
id,
|
|
58
|
+
className,
|
|
59
|
+
disabled,
|
|
60
|
+
checkSubmit = true,
|
|
61
|
+
modalClassName,
|
|
62
|
+
edit,
|
|
63
|
+
modal,
|
|
64
|
+
renderTitle,
|
|
65
|
+
children,
|
|
66
|
+
submitOption,
|
|
67
|
+
renderSubmit,
|
|
68
|
+
loadingWrapper,
|
|
69
|
+
onSubmit,
|
|
70
|
+
onCancel
|
|
71
|
+
}) {
|
|
72
|
+
const { l } = usePage();
|
|
73
|
+
const refName = st.slice[sliceName].refName;
|
|
74
|
+
const storeUse = st.use;
|
|
75
|
+
const storeDo = st.do;
|
|
76
|
+
const storeSel = st.sel;
|
|
77
|
+
const modelEdit = edit?.then ? use(edit) : edit;
|
|
78
|
+
const [modelName, ModelName] = useMemo(() => [lowerlize(refName), capitalize(refName)], []);
|
|
79
|
+
const names = useMemo(
|
|
80
|
+
() => ({
|
|
81
|
+
model: modelName,
|
|
82
|
+
modelForm: `${modelName}Form`,
|
|
83
|
+
modelFormLoading: `${modelName}FormLoading`,
|
|
84
|
+
modelModal: `${modelName}Modal`,
|
|
85
|
+
modelSubmit: `${modelName}Submit`,
|
|
86
|
+
submitModel: `submit${ModelName}`,
|
|
87
|
+
resetModel: `reset${ModelName}`,
|
|
88
|
+
setModelModal: `set${ModelName}Modal`,
|
|
89
|
+
modelLoading: `${modelName}Loading`,
|
|
90
|
+
modelViewAt: `${modelName}ViewAt`,
|
|
91
|
+
newModel: `new${ModelName}`,
|
|
92
|
+
crystalizeModel: `crystalize${ModelName}`,
|
|
93
|
+
modelObj: `${modelName}Obj`
|
|
94
|
+
}),
|
|
95
|
+
[]
|
|
96
|
+
);
|
|
97
|
+
const modelModal = storeUse[names.modelModal]();
|
|
98
|
+
const modelFormId = storeSel(
|
|
99
|
+
(state) => state[names.modelForm].id
|
|
100
|
+
);
|
|
101
|
+
const modelFormLoading = storeUse[names.modelFormLoading]();
|
|
102
|
+
const isModalOpen = modelModal === (modal ?? "edit") && (modelFormLoading === false || modelFormLoading === id) && (!modelFormId && !id || id === modelFormId);
|
|
103
|
+
useEffect(() => {
|
|
104
|
+
if (!modelEdit)
|
|
105
|
+
return;
|
|
106
|
+
const refName2 = modelEdit.refName;
|
|
107
|
+
const editType = refName2 && modelEdit[names.modelObj] ? "edit" : "new";
|
|
108
|
+
const crystalizeModel = fetch[names.crystalizeModel];
|
|
109
|
+
const modelRef = getFullModelRef(modelName);
|
|
110
|
+
if (editType === "edit") {
|
|
111
|
+
const crystal = crystalizeModel(modelEdit[names.modelObj]);
|
|
112
|
+
st.set({
|
|
113
|
+
[names.model]: crystal,
|
|
114
|
+
[names.modelLoading]: false,
|
|
115
|
+
[names.modelForm]: immerify(modelRef, crystal),
|
|
116
|
+
[names.modelFormLoading]: false,
|
|
117
|
+
[names.modelModal]: modal ?? "edit",
|
|
118
|
+
[names.modelViewAt]: modelEdit[names.modelViewAt]
|
|
119
|
+
});
|
|
120
|
+
} else {
|
|
121
|
+
const crystal = crystalizeModel(modelEdit);
|
|
122
|
+
void storeDo[names.newModel](crystal, { modal, setDefault: true, sliceName });
|
|
123
|
+
}
|
|
124
|
+
return () => {
|
|
125
|
+
};
|
|
126
|
+
}, [modelEdit]);
|
|
127
|
+
const handleCancel = useCallback(() => {
|
|
128
|
+
const modelForm = st.get()[names.modelForm];
|
|
129
|
+
const form = deepObjectify({ ...modelForm });
|
|
130
|
+
void storeDo[names.setModelModal](null);
|
|
131
|
+
if (typeof onCancel === "function")
|
|
132
|
+
onCancel(form);
|
|
133
|
+
else if (onCancel === "back")
|
|
134
|
+
router.back();
|
|
135
|
+
else if (onCancel === "reset")
|
|
136
|
+
void storeDo[names.resetModel]();
|
|
137
|
+
else if (typeof onCancel === "string")
|
|
138
|
+
router.replace(onCancel);
|
|
139
|
+
}, []);
|
|
140
|
+
const Title = () => {
|
|
141
|
+
const modelFormLoading2 = storeUse[names.modelFormLoading]();
|
|
142
|
+
const modelForm = storeUse[names.modelForm]();
|
|
143
|
+
return modelFormLoading2 ? /* @__PURE__ */ React.createElement(React.Fragment, null) : renderTitle ? typeof renderTitle === "string" ? `${l(`${modelName}.modelName`)}${renderTitle === "default" ? "" : ` - ${modelForm[renderTitle]}`}` : /* @__PURE__ */ React.createElement(React.Fragment, null, renderTitle(modelForm)) : /* @__PURE__ */ React.createElement(React.Fragment, null);
|
|
144
|
+
};
|
|
145
|
+
const Submit = useMemo(
|
|
146
|
+
() => renderSubmit === false ? () => /* @__PURE__ */ React.createElement(React.Fragment, null) : typeof renderSubmit === "function" ? () => renderSubmit(storeUse[names.modelForm]()) : () => {
|
|
147
|
+
const modelSubmit = storeUse[names.modelSubmit]();
|
|
148
|
+
const handleSubmit = useCallback(async ({ onError } = {}) => {
|
|
149
|
+
await storeDo[names.submitModel]({
|
|
150
|
+
...submitOption,
|
|
151
|
+
sliceName,
|
|
152
|
+
onError,
|
|
153
|
+
onSuccess: typeof onSubmit === "function" ? onSubmit : void 0
|
|
154
|
+
});
|
|
155
|
+
if (onSubmit === "back")
|
|
156
|
+
router.back();
|
|
157
|
+
else if (onSubmit === "reset")
|
|
158
|
+
void storeDo[names.resetModel]();
|
|
159
|
+
else if (typeof onSubmit === "string")
|
|
160
|
+
router.replace(onSubmit);
|
|
161
|
+
}, []);
|
|
162
|
+
return /* @__PURE__ */ React.createElement(
|
|
163
|
+
Button,
|
|
164
|
+
{
|
|
165
|
+
className: "btn btn-primary w-full gap-2 rounded-2xl",
|
|
166
|
+
disabled: modelSubmit.disabled || !!disabled,
|
|
167
|
+
onClick: async (e, { onError }) => {
|
|
168
|
+
await handleSubmit({ onError });
|
|
169
|
+
},
|
|
170
|
+
onSuccess: () => {
|
|
171
|
+
}
|
|
172
|
+
},
|
|
173
|
+
modelFormId ? /* @__PURE__ */ React.createElement(AiOutlineSave, null) : /* @__PURE__ */ React.createElement(AiOutlinePlus, null),
|
|
174
|
+
l(modelFormId ? "shared.updateModel" : "shared.createModel", {
|
|
175
|
+
model: l.field(names.model, "modelName")
|
|
176
|
+
})
|
|
177
|
+
);
|
|
178
|
+
},
|
|
179
|
+
[disabled, modelFormId]
|
|
180
|
+
);
|
|
181
|
+
if (type === "modal")
|
|
182
|
+
return /* @__PURE__ */ React.createElement(
|
|
183
|
+
Modal,
|
|
184
|
+
{
|
|
185
|
+
open: isModalOpen,
|
|
186
|
+
onCancel: () => {
|
|
187
|
+
handleCancel();
|
|
188
|
+
},
|
|
189
|
+
className: modalClassName,
|
|
190
|
+
title: /* @__PURE__ */ React.createElement(Title, null),
|
|
191
|
+
action: /* @__PURE__ */ React.createElement(Submit, null)
|
|
192
|
+
},
|
|
193
|
+
isModalOpen ? /* @__PURE__ */ React.createElement(
|
|
194
|
+
EditModel,
|
|
195
|
+
{
|
|
196
|
+
type,
|
|
197
|
+
sliceName,
|
|
198
|
+
className,
|
|
199
|
+
checkSubmit,
|
|
200
|
+
edit,
|
|
201
|
+
modal,
|
|
202
|
+
loadingWrapper
|
|
203
|
+
},
|
|
204
|
+
children
|
|
205
|
+
) : null
|
|
206
|
+
);
|
|
207
|
+
else if (isModalOpen)
|
|
208
|
+
return /* @__PURE__ */ React.createElement(
|
|
209
|
+
EditModel,
|
|
210
|
+
{
|
|
211
|
+
type,
|
|
212
|
+
sliceName,
|
|
213
|
+
className,
|
|
214
|
+
checkSubmit,
|
|
215
|
+
edit,
|
|
216
|
+
modal,
|
|
217
|
+
loadingWrapper
|
|
218
|
+
},
|
|
219
|
+
/* @__PURE__ */ React.createElement(Title, null),
|
|
220
|
+
children,
|
|
221
|
+
type === "form" ? /* @__PURE__ */ React.createElement("div", { className: "mt-4" }, /* @__PURE__ */ React.createElement(Submit, null)) : null
|
|
222
|
+
);
|
|
223
|
+
}
|
|
224
|
+
export {
|
|
225
|
+
EditModal as default
|
|
226
|
+
};
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { clsx } from "@akanjs/client";
|
|
3
|
+
import { capitalize } from "@akanjs/common";
|
|
4
|
+
import { st } from "@akanjs/store";
|
|
5
|
+
function EditWrapper({ children, sliceName, modelId, className, modal, resets }) {
|
|
6
|
+
const refName = st.slice[sliceName].refName;
|
|
7
|
+
const modelName = refName;
|
|
8
|
+
const names = {
|
|
9
|
+
editModel: `edit${capitalize(modelName)}`
|
|
10
|
+
};
|
|
11
|
+
const storeDo = st.do;
|
|
12
|
+
return /* @__PURE__ */ React.createElement(
|
|
13
|
+
"div",
|
|
14
|
+
{
|
|
15
|
+
className: clsx("cursor-pointer", className),
|
|
16
|
+
onClick: (e) => {
|
|
17
|
+
e.stopPropagation();
|
|
18
|
+
void storeDo[names.editModel](modelId, { modal });
|
|
19
|
+
resets?.forEach((reset) => {
|
|
20
|
+
void storeDo[`reset${capitalize(reset)}`]();
|
|
21
|
+
});
|
|
22
|
+
}
|
|
23
|
+
},
|
|
24
|
+
children
|
|
25
|
+
);
|
|
26
|
+
}
|
|
27
|
+
export {
|
|
28
|
+
EditWrapper as default
|
|
29
|
+
};
|
package/esm/Model/New.js
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { clsx } from "@akanjs/client";
|
|
2
|
+
import { usePage } from "@akanjs/next";
|
|
3
|
+
import { AiOutlinePlus } from "react-icons/ai";
|
|
4
|
+
import EditModal from "./EditModal";
|
|
5
|
+
import NewWrapper from "./NewWrapper";
|
|
6
|
+
function New({
|
|
7
|
+
className,
|
|
8
|
+
wrapperClassName,
|
|
9
|
+
type = "button",
|
|
10
|
+
children,
|
|
11
|
+
sliceName,
|
|
12
|
+
modal,
|
|
13
|
+
partial,
|
|
14
|
+
renderTitle
|
|
15
|
+
}) {
|
|
16
|
+
const { l } = usePage();
|
|
17
|
+
return /* @__PURE__ */ React.createElement("div", { className: clsx("inline", wrapperClassName) }, /* @__PURE__ */ React.createElement(
|
|
18
|
+
NewWrapper,
|
|
19
|
+
{
|
|
20
|
+
className: clsx("flex w-full items-center justify-center gap-2", className),
|
|
21
|
+
sliceName,
|
|
22
|
+
modal,
|
|
23
|
+
partial
|
|
24
|
+
},
|
|
25
|
+
/* @__PURE__ */ React.createElement(AiOutlinePlus, null),
|
|
26
|
+
" ",
|
|
27
|
+
type === "button" ? l("shared.new") : null
|
|
28
|
+
), /* @__PURE__ */ React.createElement(EditModal, { renderTitle, sliceName }, children));
|
|
29
|
+
}
|
|
30
|
+
export {
|
|
31
|
+
New as default
|
|
32
|
+
};
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { deepObjectify } from "@akanjs/common";
|
|
2
|
+
import { NewWrapper_Client } from "./NewWrapper_Client";
|
|
3
|
+
function NewWrapper({ partial = {}, ...props }) {
|
|
4
|
+
const serializedPartial = deepObjectify(typeof partial === "function" ? partial() : partial, { serializable: true });
|
|
5
|
+
return /* @__PURE__ */ React.createElement(NewWrapper_Client, { ...props, partial: serializedPartial });
|
|
6
|
+
}
|
|
7
|
+
export {
|
|
8
|
+
NewWrapper as default
|
|
9
|
+
};
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { clsx } from "@akanjs/client";
|
|
3
|
+
import { capitalize } from "@akanjs/common";
|
|
4
|
+
import { fetch } from "@akanjs/signal";
|
|
5
|
+
import { st } from "@akanjs/store";
|
|
6
|
+
const NewWrapper_Client = ({
|
|
7
|
+
children,
|
|
8
|
+
sliceName,
|
|
9
|
+
partial,
|
|
10
|
+
setDefault,
|
|
11
|
+
className,
|
|
12
|
+
modal,
|
|
13
|
+
resets
|
|
14
|
+
}) => {
|
|
15
|
+
const refName = st.slice[sliceName].refName;
|
|
16
|
+
const modelName = refName;
|
|
17
|
+
const names = {
|
|
18
|
+
newModel: `new${capitalize(modelName)}`,
|
|
19
|
+
crystalizeModel: `crystalize${capitalize(modelName)}`,
|
|
20
|
+
modelModal: `${modelName}Modal`
|
|
21
|
+
};
|
|
22
|
+
const storeDo = st.do;
|
|
23
|
+
const storeUse = st.use;
|
|
24
|
+
const crystalizeModel = fetch[names.crystalizeModel];
|
|
25
|
+
const modelModal = storeUse[names.modelModal]();
|
|
26
|
+
const disabled = modelModal === "edit";
|
|
27
|
+
return /* @__PURE__ */ React.createElement(
|
|
28
|
+
"div",
|
|
29
|
+
{
|
|
30
|
+
className: clsx({ "cursor-pointer": !disabled, "pointer-events-none": disabled }, className),
|
|
31
|
+
onClick: (e) => {
|
|
32
|
+
e.stopPropagation();
|
|
33
|
+
if (disabled)
|
|
34
|
+
return;
|
|
35
|
+
const crystal = crystalizeModel(partial);
|
|
36
|
+
void storeDo[names.newModel](crystal, { modal, setDefault, sliceName });
|
|
37
|
+
resets?.forEach((reset) => {
|
|
38
|
+
void storeDo[`reset${capitalize(reset)}`]();
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
},
|
|
42
|
+
children
|
|
43
|
+
);
|
|
44
|
+
};
|
|
45
|
+
export {
|
|
46
|
+
NewWrapper_Client
|
|
47
|
+
};
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { clsx, router } from "@akanjs/client";
|
|
3
|
+
import { capitalize } from "@akanjs/common";
|
|
4
|
+
import { msg } from "@akanjs/dictionary";
|
|
5
|
+
import { usePage } from "@akanjs/next";
|
|
6
|
+
import { st } from "@akanjs/store";
|
|
7
|
+
import { useMemo, useState } from "react";
|
|
8
|
+
import { AiOutlineDelete } from "react-icons/ai";
|
|
9
|
+
import { Button } from "../Button";
|
|
10
|
+
import { Modal } from "../Modal";
|
|
11
|
+
function Remove({ className, name, modelId, sliceName, modal, redirect }) {
|
|
12
|
+
const { l } = usePage();
|
|
13
|
+
const [modalOpen, setModalOpen] = useState(false);
|
|
14
|
+
const storeDo = st.do;
|
|
15
|
+
const refName = st.slice[sliceName].refName;
|
|
16
|
+
const modelName = refName;
|
|
17
|
+
const names = useMemo(
|
|
18
|
+
() => ({
|
|
19
|
+
removeModel: `remove${capitalize(modelName)}`
|
|
20
|
+
}),
|
|
21
|
+
[]
|
|
22
|
+
);
|
|
23
|
+
return /* @__PURE__ */ React.createElement("div", { className: "inline size-full" }, /* @__PURE__ */ React.createElement(
|
|
24
|
+
"button",
|
|
25
|
+
{
|
|
26
|
+
className: clsx("btn text-error btn-sm size-full flex-nowrap whitespace-nowrap", className),
|
|
27
|
+
onClick: (e) => {
|
|
28
|
+
e.stopPropagation();
|
|
29
|
+
setModalOpen(true);
|
|
30
|
+
}
|
|
31
|
+
},
|
|
32
|
+
/* @__PURE__ */ React.createElement(AiOutlineDelete, null),
|
|
33
|
+
" ",
|
|
34
|
+
l("shared.remove")
|
|
35
|
+
), /* @__PURE__ */ React.createElement(
|
|
36
|
+
Modal,
|
|
37
|
+
{
|
|
38
|
+
open: modalOpen,
|
|
39
|
+
onCancel: () => {
|
|
40
|
+
setModalOpen(false);
|
|
41
|
+
},
|
|
42
|
+
title: /* @__PURE__ */ React.createElement("div", { className: "text-error text-lg font-bold" }, l("shared.removeModel", { model: l(`${modelName}.modelName`) })),
|
|
43
|
+
action: /* @__PURE__ */ React.createElement(
|
|
44
|
+
Button,
|
|
45
|
+
{
|
|
46
|
+
className: "btn btn-warning w-full",
|
|
47
|
+
onClick: async (e, { onError }) => {
|
|
48
|
+
await storeDo[names.removeModel](modelId, { onError, modal });
|
|
49
|
+
msg.success("shared.removeSuccess", { data: { model: l(`${modelName}.modelName`) } });
|
|
50
|
+
setModalOpen(false);
|
|
51
|
+
if (!redirect)
|
|
52
|
+
return;
|
|
53
|
+
if (redirect === "back")
|
|
54
|
+
router.back();
|
|
55
|
+
else
|
|
56
|
+
router.push(redirect);
|
|
57
|
+
}
|
|
58
|
+
},
|
|
59
|
+
l("shared.yesRemove", { model: l(`${modelName}.modelName`) })
|
|
60
|
+
)
|
|
61
|
+
},
|
|
62
|
+
/* @__PURE__ */ React.createElement("div", { className: "flex w-full items-center justify-center" }, l("shared.sureToRemove", { model: l(`${modelName}.modelName`), name: name ?? "" }))
|
|
63
|
+
));
|
|
64
|
+
}
|
|
65
|
+
export {
|
|
66
|
+
Remove as default
|
|
67
|
+
};
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { clsx } from "@akanjs/client";
|
|
3
|
+
import { capitalize } from "@akanjs/common";
|
|
4
|
+
import { usePage } from "@akanjs/next";
|
|
5
|
+
import { st } from "@akanjs/store";
|
|
6
|
+
import { Popconfirm } from "../Popconfirm";
|
|
7
|
+
function RemoveWrapper({ children, sliceName, name, modelId, className, modal }) {
|
|
8
|
+
const { l } = usePage();
|
|
9
|
+
const refName = st.slice[sliceName].refName;
|
|
10
|
+
const modelName = refName;
|
|
11
|
+
const names = {
|
|
12
|
+
removeModel: `remove${capitalize(modelName)}`
|
|
13
|
+
};
|
|
14
|
+
const storeDo = st.do;
|
|
15
|
+
return /* @__PURE__ */ React.createElement(
|
|
16
|
+
Popconfirm,
|
|
17
|
+
{
|
|
18
|
+
title: l("shared.removeModel", { model: l(`${modelName}.modelName`) }),
|
|
19
|
+
description: /* @__PURE__ */ React.createElement("div", null, l("shared.sureToRemove", { model: l(`${modelName}.modelName`), name })),
|
|
20
|
+
onConfirm: () => {
|
|
21
|
+
void storeDo[names.removeModel](modelId, { modal });
|
|
22
|
+
}
|
|
23
|
+
},
|
|
24
|
+
/* @__PURE__ */ React.createElement("div", { className: clsx("cursor-pointer", className) }, children)
|
|
25
|
+
);
|
|
26
|
+
}
|
|
27
|
+
export {
|
|
28
|
+
RemoveWrapper as default
|
|
29
|
+
};
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { clsx, router } from "@akanjs/client";
|
|
3
|
+
import { capitalize } from "@akanjs/common";
|
|
4
|
+
import { msg } from "@akanjs/dictionary";
|
|
5
|
+
import { usePage } from "@akanjs/next";
|
|
6
|
+
import { st } from "@akanjs/store";
|
|
7
|
+
import { useMemo, useState } from "react";
|
|
8
|
+
import { AiOutlineDelete } from "react-icons/ai";
|
|
9
|
+
import { Modal } from "../Modal";
|
|
10
|
+
function SureToRemove({
|
|
11
|
+
className,
|
|
12
|
+
modelId,
|
|
13
|
+
name,
|
|
14
|
+
sliceName,
|
|
15
|
+
redirect,
|
|
16
|
+
typeNameToRemove
|
|
17
|
+
}) {
|
|
18
|
+
const { l } = usePage();
|
|
19
|
+
const [repeatName, setRepeatName] = useState("");
|
|
20
|
+
const [modalOpen, setModalOpen] = useState(false);
|
|
21
|
+
const storeDo = st.do;
|
|
22
|
+
const refName = st.slice[sliceName].refName;
|
|
23
|
+
const modelName = refName;
|
|
24
|
+
const names = useMemo(
|
|
25
|
+
() => ({
|
|
26
|
+
removeModel: `remove${capitalize(modelName)}`
|
|
27
|
+
}),
|
|
28
|
+
[]
|
|
29
|
+
);
|
|
30
|
+
return /* @__PURE__ */ React.createElement("div", { className: "inline size-full" }, /* @__PURE__ */ React.createElement(
|
|
31
|
+
"div",
|
|
32
|
+
{
|
|
33
|
+
className: clsx(
|
|
34
|
+
"text-error flex size-full cursor-pointer flex-nowrap items-center justify-center gap-2 whitespace-nowrap",
|
|
35
|
+
className
|
|
36
|
+
),
|
|
37
|
+
onClick: (e) => {
|
|
38
|
+
e.stopPropagation();
|
|
39
|
+
setModalOpen(true);
|
|
40
|
+
}
|
|
41
|
+
},
|
|
42
|
+
/* @__PURE__ */ React.createElement(AiOutlineDelete, null),
|
|
43
|
+
" ",
|
|
44
|
+
l("shared.remove")
|
|
45
|
+
), /* @__PURE__ */ React.createElement(
|
|
46
|
+
Modal,
|
|
47
|
+
{
|
|
48
|
+
open: modalOpen,
|
|
49
|
+
onCancel: () => {
|
|
50
|
+
setModalOpen(false);
|
|
51
|
+
},
|
|
52
|
+
title: /* @__PURE__ */ React.createElement("div", { className: "text-error text-lg font-bold" }, l("shared.removeModel", { model: l(`${modelName}.modelName`) })),
|
|
53
|
+
bodyClassName: "border-error",
|
|
54
|
+
action: /* @__PURE__ */ React.createElement(
|
|
55
|
+
"button",
|
|
56
|
+
{
|
|
57
|
+
className: "btn btn-error w-full",
|
|
58
|
+
disabled: typeNameToRemove && repeatName !== name,
|
|
59
|
+
onClick: async () => {
|
|
60
|
+
await storeDo[names.removeModel](modelId);
|
|
61
|
+
msg.success("shared.removeSuccess", { data: { model: l(`${modelName}.modelName`) } });
|
|
62
|
+
setModalOpen(false);
|
|
63
|
+
if (!redirect)
|
|
64
|
+
return;
|
|
65
|
+
if (redirect === "back")
|
|
66
|
+
router.back();
|
|
67
|
+
else
|
|
68
|
+
router.push(redirect);
|
|
69
|
+
}
|
|
70
|
+
},
|
|
71
|
+
l("shared.removeModel", { model: l(`${modelName}.modelName`) })
|
|
72
|
+
)
|
|
73
|
+
},
|
|
74
|
+
/* @__PURE__ */ React.createElement("div", { className: "py-4" }, l("shared.sureToRemove", { model: l(`${modelName}.modelName`), name }), /* @__PURE__ */ React.createElement("br", null), l("shared.irreversibleOps"), typeNameToRemove ? /* @__PURE__ */ React.createElement(React.Fragment, null, /* @__PURE__ */ React.createElement("br", null), l("shared.typeNameToRemove", { model: l(`${modelName}.modelName`), name })) : null),
|
|
75
|
+
typeNameToRemove ? /* @__PURE__ */ React.createElement(
|
|
76
|
+
"input",
|
|
77
|
+
{
|
|
78
|
+
className: "input w-full text-center",
|
|
79
|
+
placeholder: `${l(`${modelName}.modelName`)} name`,
|
|
80
|
+
value: repeatName,
|
|
81
|
+
onChange: (e) => {
|
|
82
|
+
setRepeatName(e.target.value);
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
) : null
|
|
86
|
+
));
|
|
87
|
+
}
|
|
88
|
+
export {
|
|
89
|
+
SureToRemove as default
|
|
90
|
+
};
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { useMemo } from "react";
|
|
3
|
+
import { AiOutlineMeh } from "react-icons/ai";
|
|
4
|
+
function View({
|
|
5
|
+
className,
|
|
6
|
+
model,
|
|
7
|
+
modelLoading = true,
|
|
8
|
+
render,
|
|
9
|
+
loadingWrapper,
|
|
10
|
+
loading,
|
|
11
|
+
empty
|
|
12
|
+
}) {
|
|
13
|
+
const RenderLoadingWrapper = useMemo(
|
|
14
|
+
() => loadingWrapper === null ? ({ children, className: className2 }) => children : loadingWrapper ?? (({ children, className: className2 }) => /* @__PURE__ */ React.createElement(React.Fragment, null, children, modelLoading ? /* @__PURE__ */ React.createElement("div", { className: "absolute inset-0 animate-pulse" }) : null)),
|
|
15
|
+
[modelLoading]
|
|
16
|
+
);
|
|
17
|
+
const RenderModel = useMemo(
|
|
18
|
+
() => modelLoading ? loading === null ? () => null : loading ?? (() => /* @__PURE__ */ React.createElement("div", { className: "flex size-full flex-col items-center justify-center gap-3 pt-6 pb-3" }, /* @__PURE__ */ React.createElement("span", { className: "loading loading-dots loading-lg" }), "Loading")) : model ? () => render(model) : empty === null ? () => null : empty ?? (() => /* @__PURE__ */ React.createElement("div", { className: "flex w-full flex-col items-center justify-center gap-3 pt-6 pb-3" }, /* @__PURE__ */ React.createElement(AiOutlineMeh, { className: "scale-150 text-4xl" }), " Empty")),
|
|
19
|
+
[model, modelLoading]
|
|
20
|
+
);
|
|
21
|
+
return /* @__PURE__ */ React.createElement(RenderLoadingWrapper, { className }, /* @__PURE__ */ React.createElement(RenderModel, null));
|
|
22
|
+
}
|
|
23
|
+
export {
|
|
24
|
+
View as default
|
|
25
|
+
};
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { capitalize } from "@akanjs/common";
|
|
3
|
+
import { usePage } from "@akanjs/next";
|
|
4
|
+
import { st } from "@akanjs/store";
|
|
5
|
+
import { AiOutlineEdit, AiOutlineSave } from "react-icons/ai";
|
|
6
|
+
import { BiDotsVertical } from "react-icons/bi";
|
|
7
|
+
import { Modal } from "../Modal";
|
|
8
|
+
import Remove from "./Remove";
|
|
9
|
+
import View from "./View";
|
|
10
|
+
function ViewEditModal({
|
|
11
|
+
modalClassName,
|
|
12
|
+
viewClassName,
|
|
13
|
+
sliceName,
|
|
14
|
+
renderTitle,
|
|
15
|
+
renderView,
|
|
16
|
+
renderTemplate
|
|
17
|
+
}) {
|
|
18
|
+
const { l } = usePage();
|
|
19
|
+
const storeUse = st.use;
|
|
20
|
+
const storeDo = st.do;
|
|
21
|
+
const storeSel = st.sel;
|
|
22
|
+
const refName = st.slice[sliceName].refName;
|
|
23
|
+
const [modelName, ModelName] = [refName, capitalize(refName)];
|
|
24
|
+
const names = {
|
|
25
|
+
model: modelName,
|
|
26
|
+
Model: ModelName,
|
|
27
|
+
viewModel: `view${ModelName}`,
|
|
28
|
+
modelLoading: `${modelName}Loading`,
|
|
29
|
+
modelModal: `${modelName}Modal`,
|
|
30
|
+
resetModel: `reset${ModelName}`,
|
|
31
|
+
editModel: `edit${ModelName}`,
|
|
32
|
+
submitModel: `submit${ModelName}`,
|
|
33
|
+
modelForm: `${modelName}Form`
|
|
34
|
+
};
|
|
35
|
+
const model = storeUse[names.model]();
|
|
36
|
+
const modelModal = storeUse[names.modelModal]();
|
|
37
|
+
const modelLoading = storeUse[names.modelLoading]();
|
|
38
|
+
const modelFormId = storeSel((state) => state[names.modelForm].id);
|
|
39
|
+
const isModalOpen = modelModal === "view" || modelModal === "edit" && !!modelFormId;
|
|
40
|
+
const Title = () => {
|
|
41
|
+
if (!model || modelLoading || !renderTitle)
|
|
42
|
+
return /* @__PURE__ */ React.createElement(React.Fragment, null);
|
|
43
|
+
const render = renderTitle(model);
|
|
44
|
+
if (typeof render === "string")
|
|
45
|
+
return /* @__PURE__ */ React.createElement("h2", { className: "flex items-center text-sm md:text-base lg:text-lg xl:text-2xl" }, render);
|
|
46
|
+
else
|
|
47
|
+
return render;
|
|
48
|
+
};
|
|
49
|
+
const Template = renderTemplate;
|
|
50
|
+
return /* @__PURE__ */ React.createElement(
|
|
51
|
+
Modal,
|
|
52
|
+
{
|
|
53
|
+
open: isModalOpen,
|
|
54
|
+
onCancel: () => {
|
|
55
|
+
storeDo[names.resetModel]();
|
|
56
|
+
},
|
|
57
|
+
className: modalClassName,
|
|
58
|
+
title: /* @__PURE__ */ React.createElement("div", { className: "flex w-full items-center justify-between" }, /* @__PURE__ */ React.createElement(Title, null), /* @__PURE__ */ React.createElement("div", { className: "dropdown dropdown-end" }, /* @__PURE__ */ React.createElement("label", { tabIndex: 0, className: "btn btn-square m-1" }, /* @__PURE__ */ React.createElement(BiDotsVertical, null)), /* @__PURE__ */ React.createElement("ul", { tabIndex: 0, className: "dropdown-content menu bg-base-100 rounded-box z-[1] p-2 shadow-sm" }, model ? /* @__PURE__ */ React.createElement("li", null, /* @__PURE__ */ React.createElement(Remove, { sliceName, modelId: model.id, modal: null })) : null))),
|
|
59
|
+
action: modelModal === "view" ? /* @__PURE__ */ React.createElement(
|
|
60
|
+
"button",
|
|
61
|
+
{
|
|
62
|
+
className: "btn btn-primary w-full",
|
|
63
|
+
onClick: () => {
|
|
64
|
+
if (model)
|
|
65
|
+
storeDo[names.editModel](model.id);
|
|
66
|
+
}
|
|
67
|
+
},
|
|
68
|
+
/* @__PURE__ */ React.createElement(AiOutlineEdit, null),
|
|
69
|
+
" ",
|
|
70
|
+
l("shared.edit")
|
|
71
|
+
) : /* @__PURE__ */ React.createElement(
|
|
72
|
+
"button",
|
|
73
|
+
{
|
|
74
|
+
className: "btn btn-primary w-full",
|
|
75
|
+
onClick: () => {
|
|
76
|
+
storeDo[names.submitModel]({ sliceName, modal: "view" });
|
|
77
|
+
}
|
|
78
|
+
},
|
|
79
|
+
/* @__PURE__ */ React.createElement(AiOutlineSave, null),
|
|
80
|
+
" ",
|
|
81
|
+
l("shared.save")
|
|
82
|
+
)
|
|
83
|
+
},
|
|
84
|
+
modelModal === "view" ? /* @__PURE__ */ React.createElement(View, { className: viewClassName, model, modelLoading, render: renderView }) : modelModal === "edit" ? /* @__PURE__ */ React.createElement(Template, null) : null
|
|
85
|
+
);
|
|
86
|
+
}
|
|
87
|
+
export {
|
|
88
|
+
ViewEditModal as default
|
|
89
|
+
};
|