@akanjs/ui 0.0.150 → 0.0.152
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 +37 -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 +31 -0
- package/Signal/Listener.d.ts +9 -0
- package/Signal/Message.d.ts +26 -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 +39 -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 +109 -0
- package/cjs/Button.js +71 -0
- package/cjs/ClientSide.js +27 -0
- package/cjs/Copy.js +38 -0
- package/cjs/CsrImage.js +51 -0
- package/cjs/Data/CardList.js +127 -0
- package/cjs/Data/Dashboard.js +64 -0
- package/cjs/Data/Insight.js +42 -0
- package/cjs/Data/Item.js +219 -0
- package/cjs/Data/ListContainer.js +285 -0
- package/cjs/Data/Pagination.js +65 -0
- package/cjs/Data/QueryMaker.js +326 -0
- package/cjs/Data/TableList.js +150 -0
- package/cjs/Data/index.js +33 -0
- package/cjs/Data/index_.js +49 -0
- package/cjs/DatePicker.js +178 -0
- package/cjs/Dialog/Action.js +32 -0
- package/cjs/Dialog/Close.js +39 -0
- package/cjs/Dialog/Content.js +28 -0
- package/cjs/Dialog/Modal.js +166 -0
- package/cjs/Dialog/Provider.js +47 -0
- package/cjs/Dialog/Title.js +32 -0
- package/cjs/Dialog/Trigger.js +39 -0
- package/cjs/Dialog/context.js +32 -0
- package/cjs/Dialog/index.js +37 -0
- package/cjs/DragAction.js +112 -0
- package/cjs/DraggableList.js +142 -0
- package/cjs/Dropdown.js +67 -0
- package/cjs/Empty.js +45 -0
- package/cjs/Field.js +1231 -0
- package/cjs/FontFace.js +77 -0
- package/cjs/Image.js +62 -0
- package/cjs/InfiniteScroll.js +70 -0
- package/cjs/Input.js +457 -0
- package/cjs/KeyboardAvoiding.js +66 -0
- package/cjs/Layout/BottomAction.js +27 -0
- package/cjs/Layout/BottomInset.js +54 -0
- package/cjs/Layout/BottomTab.js +62 -0
- package/cjs/Layout/Header.js +56 -0
- package/cjs/Layout/LeftSider.js +52 -0
- package/cjs/Layout/Navbar.js +45 -0
- package/cjs/Layout/RightSider.js +58 -0
- package/cjs/Layout/Sider.js +52 -0
- package/cjs/Layout/Template.js +27 -0
- package/cjs/Layout/TopLeftAction.js +40 -0
- package/cjs/Layout/Unit.js +28 -0
- package/cjs/Layout/View.js +27 -0
- package/cjs/Layout/Zone.js +27 -0
- package/cjs/Layout/index.js +48 -0
- package/cjs/Link/Back.js +28 -0
- package/cjs/Link/Close.js +37 -0
- package/cjs/Link/CsrLink.js +50 -0
- package/cjs/Link/NextLink.js +72 -0
- package/cjs/Link/index.js +48 -0
- package/cjs/{src/index.js → Link/types.js} +2 -10
- package/cjs/Load/Edit.js +43 -0
- package/cjs/Load/Edit_Client.js +94 -0
- package/cjs/Load/Page.js +35 -0
- package/cjs/Load/PageCSR.js +68 -0
- package/cjs/Load/Pagination.js +90 -0
- package/cjs/Load/Units.js +239 -0
- package/cjs/Load/View.js +89 -0
- package/cjs/Load/index.js +42 -0
- package/cjs/Load/index_.js +39 -0
- package/cjs/Loading/Area.js +29 -0
- package/cjs/Loading/Button.js +34 -0
- package/cjs/Loading/Input.js +34 -0
- package/cjs/Loading/ProgressBar.js +30 -0
- package/cjs/Loading/Skeleton.js +33 -0
- package/cjs/Loading/Spin.js +28 -0
- package/cjs/Loading/index.js +29 -0
- package/cjs/Menu.js +231 -0
- package/cjs/Modal.js +88 -0
- package/cjs/Model/Edit.js +67 -0
- package/cjs/Model/EditModal.js +253 -0
- package/cjs/Model/EditWrapper.js +49 -0
- package/cjs/Model/LoadInit.js +28 -0
- package/cjs/Model/New.js +67 -0
- package/cjs/Model/NewWrapper.js +29 -0
- package/cjs/Model/NewWrapper_Client.js +67 -0
- package/cjs/Model/Remove.js +92 -0
- package/cjs/Model/RemoveWrapper.js +49 -0
- package/cjs/Model/SureToRemove.js +125 -0
- package/cjs/Model/View.js +54 -0
- package/cjs/Model/ViewEditModal.js +129 -0
- package/cjs/Model/ViewModal.js +93 -0
- package/cjs/Model/ViewWrapper.js +49 -0
- package/cjs/Model/index.js +38 -0
- package/cjs/Model/index_.js +58 -0
- package/cjs/More.js +71 -0
- package/cjs/ObjectId.js +41 -0
- package/cjs/Pagination.js +115 -0
- package/cjs/Popconfirm.js +124 -0
- package/cjs/Portal.js +27 -0
- package/cjs/Radio.js +57 -0
- package/cjs/RecentTime.js +87 -0
- package/cjs/Refresh.js +46 -0
- package/cjs/ScreenNavigator.js +122 -0
- package/cjs/Select.js +283 -0
- package/cjs/Signal/Arg.js +277 -0
- package/cjs/Signal/Doc.js +258 -0
- package/cjs/Signal/GraphQL.js +261 -0
- package/cjs/Signal/Listener.js +66 -0
- package/cjs/Signal/Message.js +276 -0
- package/cjs/Signal/Object.js +131 -0
- package/cjs/Signal/PubSub.js +273 -0
- package/cjs/Signal/Request.js +45 -0
- package/cjs/Signal/Response.js +66 -0
- package/cjs/Signal/RestApi.js +357 -0
- package/cjs/Signal/WebSocket.js +69 -0
- package/cjs/Signal/index.js +42 -0
- package/cjs/System/CSR.js +395 -0
- package/cjs/System/Client.js +204 -0
- package/cjs/System/Common.js +68 -0
- package/cjs/System/DevModeToggle.js +42 -0
- package/cjs/System/Gtag.js +71 -0
- package/cjs/System/HealthCheck.js +61 -0
- package/cjs/System/Messages.js +173 -0
- package/cjs/System/Reconnect.js +86 -0
- package/cjs/System/Root.js +31 -0
- package/cjs/System/SSR.js +162 -0
- package/cjs/System/SelectLanguage.js +62 -0
- package/cjs/System/ThemeToggle.js +44 -0
- package/cjs/System/index.js +56 -0
- package/cjs/Tab/Menu.js +71 -0
- package/cjs/Tab/Menus.js +27 -0
- package/cjs/Tab/Panel.js +43 -0
- package/cjs/Tab/Provider.js +32 -0
- package/cjs/Tab/context.js +30 -0
- package/cjs/Tab/index.js +33 -0
- package/cjs/Table.js +84 -0
- package/cjs/ToggleSelect.js +123 -0
- package/cjs/Unauthorized.js +45 -0
- package/cjs/index.js +88 -2
- package/esm/BottomSheet.js +90 -0
- package/esm/Button.js +52 -0
- package/esm/ClientSide.js +8 -0
- package/esm/Copy.js +19 -0
- package/esm/CsrImage.js +32 -0
- package/esm/Data/CardList.js +98 -0
- package/esm/Data/Dashboard.js +45 -0
- package/esm/Data/Insight.js +23 -0
- package/esm/Data/Item.js +200 -0
- package/esm/Data/ListContainer.js +262 -0
- package/esm/Data/Pagination.js +46 -0
- package/esm/Data/QueryMaker.js +315 -0
- package/esm/Data/TableList.js +121 -0
- package/esm/Data/index.js +14 -0
- package/esm/Data/index_.js +20 -0
- package/esm/DatePicker.js +149 -0
- package/esm/Dialog/Action.js +13 -0
- package/esm/Dialog/Close.js +20 -0
- package/esm/Dialog/Content.js +9 -0
- package/esm/Dialog/Modal.js +137 -0
- package/esm/Dialog/Provider.js +18 -0
- package/esm/Dialog/Title.js +13 -0
- package/esm/Dialog/Trigger.js +20 -0
- package/esm/Dialog/context.js +13 -0
- package/esm/Dialog/index.js +18 -0
- package/esm/DragAction.js +93 -0
- package/esm/DraggableList.js +113 -0
- package/esm/Dropdown.js +48 -0
- package/esm/Empty.js +26 -0
- package/esm/Field.js +1212 -0
- package/esm/FontFace.js +58 -0
- package/esm/Image.js +33 -0
- package/esm/InfiniteScroll.js +51 -0
- package/esm/Input.js +442 -0
- package/esm/KeyboardAvoiding.js +47 -0
- package/esm/Layout/BottomAction.js +8 -0
- package/esm/Layout/BottomInset.js +35 -0
- package/esm/Layout/BottomTab.js +43 -0
- package/esm/Layout/Header.js +37 -0
- package/esm/Layout/LeftSider.js +33 -0
- package/esm/Layout/Navbar.js +26 -0
- package/esm/Layout/RightSider.js +39 -0
- package/esm/Layout/Sider.js +33 -0
- package/esm/Layout/Template.js +8 -0
- package/esm/Layout/TopLeftAction.js +21 -0
- package/esm/Layout/Unit.js +9 -0
- package/esm/Layout/View.js +8 -0
- package/esm/Layout/Zone.js +8 -0
- package/esm/Layout/index.js +29 -0
- package/esm/Link/Back.js +9 -0
- package/esm/Link/Close.js +18 -0
- package/esm/Link/CsrLink.js +31 -0
- package/esm/Link/NextLink.js +43 -0
- package/esm/Link/index.js +19 -0
- package/esm/Link/types.js +0 -0
- package/esm/Load/Edit.js +14 -0
- package/esm/Load/Edit_Client.js +75 -0
- package/esm/Load/Page.js +16 -0
- package/esm/Load/PageCSR.js +49 -0
- package/esm/Load/Pagination.js +71 -0
- package/esm/Load/Units.js +220 -0
- package/esm/Load/View.js +70 -0
- package/esm/Load/index.js +13 -0
- package/esm/Load/index_.js +10 -0
- package/esm/Loading/Area.js +10 -0
- package/esm/Loading/Button.js +15 -0
- package/esm/Loading/Input.js +15 -0
- package/esm/Loading/ProgressBar.js +11 -0
- package/esm/Loading/Skeleton.js +14 -0
- package/esm/Loading/Spin.js +9 -0
- package/esm/Loading/index.js +10 -0
- package/esm/Menu.js +212 -0
- package/esm/Modal.js +59 -0
- package/esm/Model/Edit.js +38 -0
- package/esm/Model/EditModal.js +234 -0
- package/esm/Model/EditWrapper.js +30 -0
- package/esm/Model/LoadInit.js +9 -0
- package/esm/Model/New.js +38 -0
- package/esm/Model/NewWrapper.js +10 -0
- package/esm/Model/NewWrapper_Client.js +48 -0
- package/esm/Model/Remove.js +73 -0
- package/esm/Model/RemoveWrapper.js +30 -0
- package/esm/Model/SureToRemove.js +106 -0
- package/esm/Model/View.js +35 -0
- package/esm/Model/ViewEditModal.js +100 -0
- package/esm/Model/ViewModal.js +64 -0
- package/esm/Model/ViewWrapper.js +30 -0
- package/esm/Model/index.js +33 -0
- package/esm/Model/index_.js +29 -0
- package/esm/More.js +42 -0
- package/esm/ObjectId.js +22 -0
- package/esm/Pagination.js +96 -0
- package/esm/Popconfirm.js +105 -0
- package/esm/Portal.js +8 -0
- package/esm/Radio.js +38 -0
- package/esm/RecentTime.js +58 -0
- package/esm/Refresh.js +17 -0
- package/esm/ScreenNavigator.js +103 -0
- package/esm/Select.js +264 -0
- package/esm/Signal/Arg.js +248 -0
- package/esm/Signal/Doc.js +229 -0
- package/esm/Signal/GraphQL.js +240 -0
- package/esm/Signal/Listener.js +47 -0
- package/esm/Signal/Message.js +247 -0
- package/esm/Signal/Object.js +112 -0
- package/esm/Signal/PubSub.js +244 -0
- package/esm/Signal/Request.js +26 -0
- package/esm/Signal/Response.js +47 -0
- package/esm/Signal/RestApi.js +336 -0
- package/esm/Signal/WebSocket.js +40 -0
- package/esm/Signal/index.js +13 -0
- package/esm/System/CSR.js +376 -0
- package/esm/System/Client.js +195 -0
- package/esm/System/Common.js +49 -0
- package/esm/System/DevModeToggle.js +23 -0
- package/esm/System/Gtag.js +52 -0
- package/esm/System/HealthCheck.js +42 -0
- package/esm/System/Messages.js +159 -0
- package/esm/System/Reconnect.js +67 -0
- package/esm/System/Root.js +12 -0
- package/esm/System/SSR.js +143 -0
- package/esm/System/SelectLanguage.js +43 -0
- package/esm/System/ThemeToggle.js +25 -0
- package/esm/System/index.js +27 -0
- package/esm/Tab/Menu.js +52 -0
- package/esm/Tab/Menus.js +8 -0
- package/esm/Tab/Panel.js +24 -0
- package/esm/Tab/Provider.js +13 -0
- package/esm/Tab/context.js +11 -0
- package/esm/Tab/index.js +14 -0
- package/esm/Table.js +65 -0
- package/esm/ToggleSelect.js +104 -0
- package/esm/Unauthorized.js +26 -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
package/cjs/Menu.js
ADDED
|
@@ -0,0 +1,231 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
var Menu_exports = {};
|
|
20
|
+
__export(Menu_exports, {
|
|
21
|
+
Menu: () => Menu
|
|
22
|
+
});
|
|
23
|
+
module.exports = __toCommonJS(Menu_exports);
|
|
24
|
+
var import_jsx_runtime = require("react/jsx-runtime");
|
|
25
|
+
var import_client = require("@akanjs/client");
|
|
26
|
+
var import_store = require("@akanjs/store");
|
|
27
|
+
var import_react = require("react");
|
|
28
|
+
var import_ai = require("react-icons/ai");
|
|
29
|
+
const Menu = ({
|
|
30
|
+
items,
|
|
31
|
+
onClick,
|
|
32
|
+
selectedKeys,
|
|
33
|
+
labelClassName,
|
|
34
|
+
defaultSelectedKeys,
|
|
35
|
+
className = "",
|
|
36
|
+
ulClassName = "",
|
|
37
|
+
liClassName,
|
|
38
|
+
style,
|
|
39
|
+
mode = "inline",
|
|
40
|
+
activeStyle = "bordered",
|
|
41
|
+
inlineCollapsed,
|
|
42
|
+
onMouseOver,
|
|
43
|
+
onMouseLeave
|
|
44
|
+
}) => {
|
|
45
|
+
const [expandedKey, setExpandedKey] = (0, import_react.useState)();
|
|
46
|
+
const [currentKey, setCurrentKey] = (0, import_react.useState)(defaultSelectedKeys?.[0] ?? null);
|
|
47
|
+
const modeClassName = mode === "horizontal" ? "menu-horizontal flex-row " : "bg-base-200";
|
|
48
|
+
const menuRef = (0, import_react.useRef)(null);
|
|
49
|
+
const LiRefs = (0, import_react.useRef)([]);
|
|
50
|
+
const overflowLiRef = (0, import_react.useRef)(null);
|
|
51
|
+
const itemWidthsRef = (0, import_react.useRef)([]);
|
|
52
|
+
const innerWidth = import_store.st.use.innerWidth();
|
|
53
|
+
const subMenuClassName = mode === "horizontal" ? `fixed menu-title bottom-0 translate-y-[98%] border-0 rounded-xs shadow-lg bg-base-100 hover:bg-base-100 flex flex-col` : "flex flex-col gap-0 p-0 bg-primary/10 hover:bg-primary/10 overflow-hidden";
|
|
54
|
+
const subMenuItemClassName = mode === "inline" ? "w-full h-full bg-red-500 btn btn-ghost px-2 m-0 hover:bg-primary/20 btn btn-ghost text-primary-focus font-normal" : "w-full text-center duration-300 whitespace-nowrap btn btn-ghost text-primary-focus font-normal";
|
|
55
|
+
const activeClassName = activeStyle === "active" ? "bg-primary text-primary-focus" : activeStyle === "bordered" ? " border-b-2 border-white" : activeStyle;
|
|
56
|
+
const [overflowMenuItems, setOverflowMenuItems] = (0, import_react.useState)([]);
|
|
57
|
+
(0, import_react.useLayoutEffect)(() => {
|
|
58
|
+
if (mode !== "horizontal")
|
|
59
|
+
return;
|
|
60
|
+
const menu = menuRef.current;
|
|
61
|
+
if (!menu)
|
|
62
|
+
return;
|
|
63
|
+
const liList = LiRefs.current;
|
|
64
|
+
const widths = [];
|
|
65
|
+
liList.forEach((li) => {
|
|
66
|
+
widths.push(li.getBoundingClientRect().width);
|
|
67
|
+
});
|
|
68
|
+
itemWidthsRef.current = widths;
|
|
69
|
+
checkOverflow();
|
|
70
|
+
}, []);
|
|
71
|
+
(0, import_react.useEffect)(() => {
|
|
72
|
+
checkOverflow();
|
|
73
|
+
}, [innerWidth]);
|
|
74
|
+
const checkOverflow = (0, import_react.useCallback)(() => {
|
|
75
|
+
if (mode !== "horizontal" || !itemWidthsRef.current.length)
|
|
76
|
+
return;
|
|
77
|
+
const menu = menuRef.current;
|
|
78
|
+
if (!menu)
|
|
79
|
+
return;
|
|
80
|
+
const totalWidth = menu.getBoundingClientRect().width;
|
|
81
|
+
const widths = itemWidthsRef.current;
|
|
82
|
+
const overflowItems = [];
|
|
83
|
+
let accumulatedWidth = 0;
|
|
84
|
+
for (let i = 0; i < widths.length; i++) {
|
|
85
|
+
accumulatedWidth += widths[i];
|
|
86
|
+
if (accumulatedWidth > totalWidth) {
|
|
87
|
+
if (overflowItems.length === 0 && i - 1 >= 0)
|
|
88
|
+
overflowItems.push(items[i - 1]);
|
|
89
|
+
overflowItems.push(items[i]);
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
setOverflowMenuItems(overflowItems);
|
|
93
|
+
}, [items, mode]);
|
|
94
|
+
const handleOnClick = (item) => {
|
|
95
|
+
setCurrentKey(item.key);
|
|
96
|
+
if (mode === "inline" && item.children)
|
|
97
|
+
setExpandedKey(item.key === expandedKey ? void 0 : item.key);
|
|
98
|
+
else
|
|
99
|
+
onClick?.(item);
|
|
100
|
+
};
|
|
101
|
+
const checkIsActive = (key) => {
|
|
102
|
+
if (selectedKeys)
|
|
103
|
+
return selectedKeys.includes(key);
|
|
104
|
+
return key === currentKey;
|
|
105
|
+
};
|
|
106
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
107
|
+
"div",
|
|
108
|
+
{
|
|
109
|
+
ref: menuRef,
|
|
110
|
+
id: "menu",
|
|
111
|
+
className: (0, import_client.clsx)(mode === "horizontal" ? "w-full shrink overflow-hidden" : "w-fit", className),
|
|
112
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(
|
|
113
|
+
"ul",
|
|
114
|
+
{
|
|
115
|
+
className: (0, import_client.clsx)("menu size-full flex-nowrap overflow-y-auto p-0", modeClassName, ulClassName),
|
|
116
|
+
style: { ...style },
|
|
117
|
+
onMouseOver,
|
|
118
|
+
onMouseLeave,
|
|
119
|
+
children: [
|
|
120
|
+
items.filter((item) => !overflowMenuItems.some((overflowItem) => overflowItem.key === item.key)).map((item, idx) => {
|
|
121
|
+
const isOverflowItem = overflowMenuItems.some((overflowItem) => overflowItem.key === item.key);
|
|
122
|
+
const overflowClassName = isOverflowItem ? "opacity-50" : "";
|
|
123
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(
|
|
124
|
+
"li",
|
|
125
|
+
{
|
|
126
|
+
ref: (el) => {
|
|
127
|
+
if (el)
|
|
128
|
+
LiRefs.current[idx] = el;
|
|
129
|
+
},
|
|
130
|
+
id: item.key,
|
|
131
|
+
className: (0, import_client.clsx)("relative m-0 duration-200 hover:opacity-70", overflowClassName, liClassName, {
|
|
132
|
+
"bg-base-300": activeStyle === "active" && checkIsActive(item.key),
|
|
133
|
+
"border-base-100 border-b-2": activeStyle === "bordered" && checkIsActive(item.key)
|
|
134
|
+
}),
|
|
135
|
+
onClick: () => {
|
|
136
|
+
if (!isOverflowItem)
|
|
137
|
+
handleOnClick(item);
|
|
138
|
+
},
|
|
139
|
+
onMouseEnter: () => {
|
|
140
|
+
if (mode === "horizontal" && !isOverflowItem && item.children && expandedKey !== item.key)
|
|
141
|
+
setExpandedKey(item.key);
|
|
142
|
+
},
|
|
143
|
+
onMouseLeave: () => {
|
|
144
|
+
if (mode === "horizontal" && !isOverflowItem)
|
|
145
|
+
setExpandedKey(void 0);
|
|
146
|
+
},
|
|
147
|
+
children: [
|
|
148
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { className: "flex h-full justify-between rounded-none", children: [
|
|
149
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { className: (0, import_client.clsx)("flex items-center gap-1", labelClassName?.(checkIsActive(item.key))), children: [
|
|
150
|
+
item.icon,
|
|
151
|
+
!inlineCollapsed && /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { className: "text-base-content whitespace-nowrap", children: item.label })
|
|
152
|
+
] }),
|
|
153
|
+
item.children && mode === "inline" && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
154
|
+
import_ai.AiFillCaretDown,
|
|
155
|
+
{
|
|
156
|
+
className: (0, import_client.clsx)(
|
|
157
|
+
"text-xs transition-transform duration-400",
|
|
158
|
+
expandedKey === item.key ? "rotate-180" : ""
|
|
159
|
+
)
|
|
160
|
+
}
|
|
161
|
+
)
|
|
162
|
+
] }),
|
|
163
|
+
item.children && expandedKey === item.key && /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { className: subMenuClassName, children: item.children.map((child) => /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
164
|
+
"div",
|
|
165
|
+
{
|
|
166
|
+
onClick: (e) => {
|
|
167
|
+
e.stopPropagation();
|
|
168
|
+
onClick?.(child);
|
|
169
|
+
setExpandedKey(void 0);
|
|
170
|
+
},
|
|
171
|
+
className: subMenuItemClassName,
|
|
172
|
+
children: child.label
|
|
173
|
+
},
|
|
174
|
+
child.key
|
|
175
|
+
)) })
|
|
176
|
+
]
|
|
177
|
+
},
|
|
178
|
+
item.key
|
|
179
|
+
);
|
|
180
|
+
}),
|
|
181
|
+
overflowMenuItems.length > 0 && mode === "horizontal" && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(OverflowMenu, { overflowItems: overflowMenuItems, onClick })
|
|
182
|
+
]
|
|
183
|
+
}
|
|
184
|
+
)
|
|
185
|
+
}
|
|
186
|
+
);
|
|
187
|
+
};
|
|
188
|
+
const OverflowMenu = ({ overflowItems, onClick }) => {
|
|
189
|
+
const [isOpen, setIsOpen] = (0, import_react.useState)(false);
|
|
190
|
+
const [expandedKey, setExpandedKey] = (0, import_react.useState)();
|
|
191
|
+
const handleMouseEnter = () => {
|
|
192
|
+
setIsOpen(true);
|
|
193
|
+
};
|
|
194
|
+
const handleMouseLeave = () => {
|
|
195
|
+
setIsOpen(false);
|
|
196
|
+
};
|
|
197
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("li", { className: "relative h-full", onMouseEnter: handleMouseEnter, onMouseLeave: handleMouseLeave, children: [
|
|
198
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { className: "flex h-full items-center justify-center rounded-none", children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_ai.AiOutlineEllipsis, {}) }),
|
|
199
|
+
isOpen && /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { className: "bg-base-100 hover:bg-base-100 fixed -bottom-0 flex translate-y-[98%] flex-col rounded-xs border-0 p-2 shadow-lg", children: overflowItems.map((item) => /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(
|
|
200
|
+
"div",
|
|
201
|
+
{
|
|
202
|
+
onClick: () => onClick?.(item),
|
|
203
|
+
className: "btn btn-ghost text-primary-focus relative font-normal whitespace-nowrap",
|
|
204
|
+
onMouseEnter: () => {
|
|
205
|
+
if (item.children && expandedKey !== item.key)
|
|
206
|
+
setExpandedKey(item.key);
|
|
207
|
+
},
|
|
208
|
+
onMouseLeave: () => {
|
|
209
|
+
setExpandedKey(void 0);
|
|
210
|
+
},
|
|
211
|
+
children: [
|
|
212
|
+
item.label,
|
|
213
|
+
item.children && expandedKey === item.key && /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { className: "bg-base-100 absolute top-0 left-0 -translate-x-full p-4 drop-shadow-sm", children: item.children.map((child) => /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
214
|
+
"div",
|
|
215
|
+
{
|
|
216
|
+
onClick: (e) => {
|
|
217
|
+
e.stopPropagation();
|
|
218
|
+
onClick?.(child);
|
|
219
|
+
setExpandedKey(void 0);
|
|
220
|
+
},
|
|
221
|
+
className: "btn btn-ghost text-primary-focus flex items-center justify-center text-center font-normal",
|
|
222
|
+
children: child.label
|
|
223
|
+
},
|
|
224
|
+
child.key
|
|
225
|
+
)) })
|
|
226
|
+
]
|
|
227
|
+
},
|
|
228
|
+
item.key
|
|
229
|
+
)) })
|
|
230
|
+
] });
|
|
231
|
+
};
|
package/cjs/Modal.js
ADDED
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __export = (target, all) => {
|
|
9
|
+
for (var name in all)
|
|
10
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
+
};
|
|
12
|
+
var __copyProps = (to, from, except, desc) => {
|
|
13
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
+
for (let key of __getOwnPropNames(from))
|
|
15
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
+
}
|
|
18
|
+
return to;
|
|
19
|
+
};
|
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
+
mod
|
|
27
|
+
));
|
|
28
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
+
var Modal_exports = {};
|
|
30
|
+
__export(Modal_exports, {
|
|
31
|
+
Modal: () => Modal,
|
|
32
|
+
Window: () => Window
|
|
33
|
+
});
|
|
34
|
+
module.exports = __toCommonJS(Modal_exports);
|
|
35
|
+
var import_jsx_runtime = require("react/jsx-runtime");
|
|
36
|
+
var RadixDialog = __toESM(require("@radix-ui/react-dialog"));
|
|
37
|
+
var import_bi = require("react-icons/bi");
|
|
38
|
+
var import_Dialog = require("./Dialog");
|
|
39
|
+
const Modal = ({
|
|
40
|
+
className,
|
|
41
|
+
title,
|
|
42
|
+
action,
|
|
43
|
+
open,
|
|
44
|
+
onCancel,
|
|
45
|
+
bodyClassName,
|
|
46
|
+
children,
|
|
47
|
+
confirmClose = false
|
|
48
|
+
}) => {
|
|
49
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_Dialog.Dialog, { open, children: /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_Dialog.Dialog.Modal, { className, onCancel, bodyClassName, confirmClose, children: [
|
|
50
|
+
title ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_Dialog.Dialog.Title, { children: title }) : null,
|
|
51
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_Dialog.Dialog.Content, { children }),
|
|
52
|
+
action ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_Dialog.Dialog.Action, { children: action }) : null
|
|
53
|
+
] }) });
|
|
54
|
+
};
|
|
55
|
+
const Window = ({ open, onCancel, title, children }) => {
|
|
56
|
+
if (!open)
|
|
57
|
+
return null;
|
|
58
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(RadixDialog.Root, { open, children: /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(RadixDialog.Portal, { children: [
|
|
59
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(RadixDialog.Overlay, { className: "fixed inset-0 bg-black/40" }),
|
|
60
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsxs)(
|
|
61
|
+
RadixDialog.Content,
|
|
62
|
+
{
|
|
63
|
+
className: "animate-fadeIn fixed top-1/2 left-1/2 z-[2] w-[90%] min-w-auto -translate-x-1/2 -translate-y-1/2 rounded-[10px] border-[3px] border-black text-black backdrop-blur-lg md:w-fit",
|
|
64
|
+
style: {
|
|
65
|
+
background: `rgba(255, 255, 255, 0.3)`,
|
|
66
|
+
width: "406px"
|
|
67
|
+
},
|
|
68
|
+
children: [
|
|
69
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsxs)(RadixDialog.Title, { className: "height-[36px] relative overflow-hidden rounded-t-[6px] border-b-2 border-black bg-white/60 text-center", children: [
|
|
70
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { className: "m-0 text-[22px]", children: title }),
|
|
71
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
72
|
+
RadixDialog.Close,
|
|
73
|
+
{
|
|
74
|
+
onClick: () => {
|
|
75
|
+
onCancel();
|
|
76
|
+
},
|
|
77
|
+
className: "absolute top-0 right-0 flex h-[34px] w-[40px] cursor-pointer items-center justify-center border-l-2 border-black",
|
|
78
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_bi.BiX, { className: "text-[32px]" })
|
|
79
|
+
}
|
|
80
|
+
)
|
|
81
|
+
] }),
|
|
82
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(RadixDialog.Description, { className: "overflow-y-hidden rounded-b-[10px] p-2", children })
|
|
83
|
+
]
|
|
84
|
+
}
|
|
85
|
+
)
|
|
86
|
+
] }) });
|
|
87
|
+
};
|
|
88
|
+
Modal.Window = Window;
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
var __create = Object.create;
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
6
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
+
var __export = (target, all) => {
|
|
8
|
+
for (var name in all)
|
|
9
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
10
|
+
};
|
|
11
|
+
var __copyProps = (to, from, except, desc) => {
|
|
12
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
13
|
+
for (let key of __getOwnPropNames(from))
|
|
14
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
15
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
16
|
+
}
|
|
17
|
+
return to;
|
|
18
|
+
};
|
|
19
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
20
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
21
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
22
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
23
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
24
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
25
|
+
mod
|
|
26
|
+
));
|
|
27
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
28
|
+
var Edit_exports = {};
|
|
29
|
+
__export(Edit_exports, {
|
|
30
|
+
default: () => Edit
|
|
31
|
+
});
|
|
32
|
+
module.exports = __toCommonJS(Edit_exports);
|
|
33
|
+
var import_jsx_runtime = require("react/jsx-runtime");
|
|
34
|
+
var import_client = require("@akanjs/client");
|
|
35
|
+
var import_next = require("@akanjs/next");
|
|
36
|
+
var import_ai = require("react-icons/ai");
|
|
37
|
+
var import_EditModal = __toESM(require("./EditModal"));
|
|
38
|
+
var import_EditWrapper = __toESM(require("./EditWrapper"));
|
|
39
|
+
function Edit({
|
|
40
|
+
className,
|
|
41
|
+
wrapperClassName,
|
|
42
|
+
type = "button",
|
|
43
|
+
children,
|
|
44
|
+
sliceName,
|
|
45
|
+
modelId,
|
|
46
|
+
modal,
|
|
47
|
+
renderTitle
|
|
48
|
+
}) {
|
|
49
|
+
const { l } = (0, import_next.usePage)();
|
|
50
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { className: (0, import_client.clsx)("inline", wrapperClassName), children: [
|
|
51
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsxs)(
|
|
52
|
+
import_EditWrapper.default,
|
|
53
|
+
{
|
|
54
|
+
className: (0, import_client.clsx)("flex w-full items-center justify-center gap-2", className),
|
|
55
|
+
sliceName,
|
|
56
|
+
modelId,
|
|
57
|
+
modal,
|
|
58
|
+
children: [
|
|
59
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_ai.AiOutlineEdit, {}),
|
|
60
|
+
" ",
|
|
61
|
+
type === "button" ? l("shared.edit") : null
|
|
62
|
+
]
|
|
63
|
+
}
|
|
64
|
+
),
|
|
65
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_EditModal.default, { renderTitle, sliceName, id: modelId, children })
|
|
66
|
+
] });
|
|
67
|
+
}
|
|
@@ -0,0 +1,253 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
var EditModal_exports = {};
|
|
20
|
+
__export(EditModal_exports, {
|
|
21
|
+
default: () => EditModal
|
|
22
|
+
});
|
|
23
|
+
module.exports = __toCommonJS(EditModal_exports);
|
|
24
|
+
var import_jsx_runtime = require("react/jsx-runtime");
|
|
25
|
+
var import_client = require("@akanjs/client");
|
|
26
|
+
var import_common = require("@akanjs/common");
|
|
27
|
+
var import_constant = require("@akanjs/constant");
|
|
28
|
+
var import_next = require("@akanjs/next");
|
|
29
|
+
var import_signal = require("@akanjs/signal");
|
|
30
|
+
var import_store2 = require("@akanjs/store");
|
|
31
|
+
var import_react = require("react");
|
|
32
|
+
var import_ai = require("react-icons/ai");
|
|
33
|
+
var import_Button = require("../Button");
|
|
34
|
+
var import_Modal = require("../Modal");
|
|
35
|
+
const EditModel = ({
|
|
36
|
+
type = "modal",
|
|
37
|
+
sliceName,
|
|
38
|
+
className,
|
|
39
|
+
checkSubmit = true,
|
|
40
|
+
edit,
|
|
41
|
+
modal,
|
|
42
|
+
children,
|
|
43
|
+
loadingWrapper
|
|
44
|
+
}) => {
|
|
45
|
+
const storeUse = import_store2.st.use;
|
|
46
|
+
const storeDo = import_store2.st.do;
|
|
47
|
+
const refName = import_store2.st.slice[sliceName].refName;
|
|
48
|
+
const [modelName, ModelName] = (0, import_react.useMemo)(() => [(0, import_common.lowerlize)(refName), (0, import_common.capitalize)(refName)], []);
|
|
49
|
+
const names = (0, import_react.useMemo)(
|
|
50
|
+
() => ({
|
|
51
|
+
model: modelName,
|
|
52
|
+
Model: ModelName,
|
|
53
|
+
modelForm: `${modelName}Form`,
|
|
54
|
+
modelFormLoading: `${modelName}FormLoading`,
|
|
55
|
+
modelModal: `${modelName}Modal`,
|
|
56
|
+
checkModelSubmitable: `check${ModelName}Submitable`
|
|
57
|
+
}),
|
|
58
|
+
[]
|
|
59
|
+
);
|
|
60
|
+
const modelModal = storeUse[names.modelModal]();
|
|
61
|
+
const modelForm = storeUse[names.modelForm]();
|
|
62
|
+
const checkSubmitable = (0, import_next.useDebounce)(() => {
|
|
63
|
+
storeDo[names.checkModelSubmitable]();
|
|
64
|
+
});
|
|
65
|
+
(0, import_react.useEffect)(() => {
|
|
66
|
+
if (checkSubmit)
|
|
67
|
+
checkSubmitable();
|
|
68
|
+
}, [modelModal, modelForm]);
|
|
69
|
+
const LoadingWrapper = (0, import_react.useMemo)(() => {
|
|
70
|
+
return loadingWrapper === false ? ({ children: children2, className: className2 }) => children2 : typeof loadingWrapper === "function" ? loadingWrapper : ({ children: children2, className: className2 }) => {
|
|
71
|
+
const modelFormLoading = storeUse[names.modelFormLoading]();
|
|
72
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { className: (0, import_client.clsx)("", className2), children: [
|
|
73
|
+
children2,
|
|
74
|
+
modelFormLoading ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { className: "bg-base-100/50 absolute inset-0 animate-pulse" }) : null
|
|
75
|
+
] });
|
|
76
|
+
};
|
|
77
|
+
}, []);
|
|
78
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(LoadingWrapper, { className: (0, import_client.clsx)("w-full", className), children });
|
|
79
|
+
};
|
|
80
|
+
function EditModal({
|
|
81
|
+
type = "modal",
|
|
82
|
+
sliceName,
|
|
83
|
+
id,
|
|
84
|
+
className,
|
|
85
|
+
disabled,
|
|
86
|
+
checkSubmit = true,
|
|
87
|
+
modalClassName,
|
|
88
|
+
edit,
|
|
89
|
+
modal,
|
|
90
|
+
renderTitle,
|
|
91
|
+
children,
|
|
92
|
+
submitOption,
|
|
93
|
+
renderSubmit,
|
|
94
|
+
loadingWrapper,
|
|
95
|
+
onSubmit,
|
|
96
|
+
onCancel
|
|
97
|
+
}) {
|
|
98
|
+
const { l } = (0, import_next.usePage)();
|
|
99
|
+
const refName = import_store2.st.slice[sliceName].refName;
|
|
100
|
+
const storeUse = import_store2.st.use;
|
|
101
|
+
const storeDo = import_store2.st.do;
|
|
102
|
+
const storeSel = import_store2.st.sel;
|
|
103
|
+
const modelEdit = edit?.then ? (0, import_react.use)(edit) : edit;
|
|
104
|
+
const [modelName, ModelName] = (0, import_react.useMemo)(() => [(0, import_common.lowerlize)(refName), (0, import_common.capitalize)(refName)], []);
|
|
105
|
+
const names = (0, import_react.useMemo)(
|
|
106
|
+
() => ({
|
|
107
|
+
model: modelName,
|
|
108
|
+
modelForm: `${modelName}Form`,
|
|
109
|
+
modelFormLoading: `${modelName}FormLoading`,
|
|
110
|
+
modelModal: `${modelName}Modal`,
|
|
111
|
+
modelSubmit: `${modelName}Submit`,
|
|
112
|
+
submitModel: `submit${ModelName}`,
|
|
113
|
+
resetModel: `reset${ModelName}`,
|
|
114
|
+
setModelModal: `set${ModelName}Modal`,
|
|
115
|
+
modelLoading: `${modelName}Loading`,
|
|
116
|
+
modelViewAt: `${modelName}ViewAt`,
|
|
117
|
+
newModel: `new${ModelName}`,
|
|
118
|
+
crystalizeModel: `crystalize${ModelName}`,
|
|
119
|
+
modelObj: `${modelName}Obj`
|
|
120
|
+
}),
|
|
121
|
+
[]
|
|
122
|
+
);
|
|
123
|
+
const modelModal = storeUse[names.modelModal]();
|
|
124
|
+
const modelFormId = storeSel(
|
|
125
|
+
(state) => state[names.modelForm].id
|
|
126
|
+
);
|
|
127
|
+
const modelFormLoading = storeUse[names.modelFormLoading]();
|
|
128
|
+
const isModalOpen = modelModal === (modal ?? "edit") && (modelFormLoading === false || modelFormLoading === id) && (!modelFormId && !id || id === modelFormId);
|
|
129
|
+
(0, import_react.useEffect)(() => {
|
|
130
|
+
if (!modelEdit)
|
|
131
|
+
return;
|
|
132
|
+
const refName2 = modelEdit.refName;
|
|
133
|
+
const editType = refName2 && modelEdit[names.modelObj] ? "edit" : "new";
|
|
134
|
+
const crystalizeModel = import_signal.fetch[names.crystalizeModel];
|
|
135
|
+
const modelRef = (0, import_constant.getFullModelRef)(modelName);
|
|
136
|
+
if (editType === "edit") {
|
|
137
|
+
const crystal = crystalizeModel(modelEdit[names.modelObj]);
|
|
138
|
+
import_store2.st.set({
|
|
139
|
+
[names.model]: crystal,
|
|
140
|
+
[names.modelLoading]: false,
|
|
141
|
+
[names.modelForm]: (0, import_signal.immerify)(modelRef, crystal),
|
|
142
|
+
[names.modelFormLoading]: false,
|
|
143
|
+
[names.modelModal]: modal ?? "edit",
|
|
144
|
+
[names.modelViewAt]: modelEdit[names.modelViewAt]
|
|
145
|
+
});
|
|
146
|
+
} else {
|
|
147
|
+
const crystal = crystalizeModel(modelEdit);
|
|
148
|
+
void storeDo[names.newModel](crystal, { modal, setDefault: true, sliceName });
|
|
149
|
+
}
|
|
150
|
+
return () => {
|
|
151
|
+
};
|
|
152
|
+
}, [modelEdit]);
|
|
153
|
+
const handleCancel = (0, import_react.useCallback)(() => {
|
|
154
|
+
const modelForm = import_store2.st.get()[names.modelForm];
|
|
155
|
+
const form = (0, import_common.deepObjectify)({ ...modelForm });
|
|
156
|
+
void storeDo[names.setModelModal](null);
|
|
157
|
+
if (typeof onCancel === "function")
|
|
158
|
+
onCancel(form);
|
|
159
|
+
else if (onCancel === "back")
|
|
160
|
+
import_client.router.back();
|
|
161
|
+
else if (onCancel === "reset")
|
|
162
|
+
void storeDo[names.resetModel]();
|
|
163
|
+
else if (typeof onCancel === "string")
|
|
164
|
+
import_client.router.replace(onCancel);
|
|
165
|
+
}, []);
|
|
166
|
+
const Title = () => {
|
|
167
|
+
const modelFormLoading2 = storeUse[names.modelFormLoading]();
|
|
168
|
+
const modelForm = storeUse[names.modelForm]();
|
|
169
|
+
return modelFormLoading2 ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_jsx_runtime.Fragment, {}) : renderTitle ? typeof renderTitle === "string" ? `${l(`${modelName}.modelName`)}${renderTitle === "default" ? "" : ` - ${modelForm[renderTitle]}`}` : /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_jsx_runtime.Fragment, { children: renderTitle(modelForm) }) : /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_jsx_runtime.Fragment, {});
|
|
170
|
+
};
|
|
171
|
+
const Submit = (0, import_react.useMemo)(
|
|
172
|
+
() => renderSubmit === false ? () => /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_jsx_runtime.Fragment, {}) : typeof renderSubmit === "function" ? () => renderSubmit(storeUse[names.modelForm]()) : () => {
|
|
173
|
+
const modelSubmit = storeUse[names.modelSubmit]();
|
|
174
|
+
const handleSubmit = (0, import_react.useCallback)(async ({ onError } = {}) => {
|
|
175
|
+
await storeDo[names.submitModel]({
|
|
176
|
+
...submitOption,
|
|
177
|
+
sliceName,
|
|
178
|
+
onError,
|
|
179
|
+
onSuccess: typeof onSubmit === "function" ? onSubmit : void 0
|
|
180
|
+
});
|
|
181
|
+
if (onSubmit === "back")
|
|
182
|
+
import_client.router.back();
|
|
183
|
+
else if (onSubmit === "reset")
|
|
184
|
+
void storeDo[names.resetModel]();
|
|
185
|
+
else if (typeof onSubmit === "string")
|
|
186
|
+
import_client.router.replace(onSubmit);
|
|
187
|
+
}, []);
|
|
188
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(
|
|
189
|
+
import_Button.Button,
|
|
190
|
+
{
|
|
191
|
+
className: "btn btn-primary w-full gap-2 rounded-2xl",
|
|
192
|
+
disabled: modelSubmit.disabled || !!disabled,
|
|
193
|
+
onClick: async (e, { onError }) => {
|
|
194
|
+
await handleSubmit({ onError });
|
|
195
|
+
},
|
|
196
|
+
onSuccess: () => {
|
|
197
|
+
},
|
|
198
|
+
children: [
|
|
199
|
+
modelFormId ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_ai.AiOutlineSave, {}) : /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_ai.AiOutlinePlus, {}),
|
|
200
|
+
l(modelFormId ? "shared.updateModel" : "shared.createModel", {
|
|
201
|
+
model: l.field(names.model, "modelName")
|
|
202
|
+
})
|
|
203
|
+
]
|
|
204
|
+
}
|
|
205
|
+
);
|
|
206
|
+
},
|
|
207
|
+
[disabled, modelFormId]
|
|
208
|
+
);
|
|
209
|
+
if (type === "modal")
|
|
210
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
211
|
+
import_Modal.Modal,
|
|
212
|
+
{
|
|
213
|
+
open: isModalOpen,
|
|
214
|
+
onCancel: () => {
|
|
215
|
+
handleCancel();
|
|
216
|
+
},
|
|
217
|
+
className: modalClassName,
|
|
218
|
+
title: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Title, {}),
|
|
219
|
+
action: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Submit, {}),
|
|
220
|
+
children: isModalOpen ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
221
|
+
EditModel,
|
|
222
|
+
{
|
|
223
|
+
type,
|
|
224
|
+
sliceName,
|
|
225
|
+
className,
|
|
226
|
+
checkSubmit,
|
|
227
|
+
edit,
|
|
228
|
+
modal,
|
|
229
|
+
loadingWrapper,
|
|
230
|
+
children
|
|
231
|
+
}
|
|
232
|
+
) : null
|
|
233
|
+
}
|
|
234
|
+
);
|
|
235
|
+
else if (isModalOpen)
|
|
236
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(
|
|
237
|
+
EditModel,
|
|
238
|
+
{
|
|
239
|
+
type,
|
|
240
|
+
sliceName,
|
|
241
|
+
className,
|
|
242
|
+
checkSubmit,
|
|
243
|
+
edit,
|
|
244
|
+
modal,
|
|
245
|
+
loadingWrapper,
|
|
246
|
+
children: [
|
|
247
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(Title, {}),
|
|
248
|
+
children,
|
|
249
|
+
type === "form" ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { className: "mt-4", children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Submit, {}) }) : null
|
|
250
|
+
]
|
|
251
|
+
}
|
|
252
|
+
);
|
|
253
|
+
}
|