@compill/admin 1.0.113 → 1.0.116

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.cjs CHANGED
@@ -7,15 +7,17 @@ var js = require('@mdi/js');
7
7
  var ui = require('@valerya/ui');
8
8
  var Link = require('next/link.js');
9
9
  var reactRouterDom = require('react-router-dom');
10
- var React = require('react');
11
10
  var adminApi = require('@compill/admin-api');
12
- var formik = require('formik');
11
+ var React = require('react');
13
12
  var reactToastify = require('react-toastify');
13
+ var formComponents = require('@compill/form-components');
14
+ var formik = require('formik');
14
15
  var reactHotkeysHook = require('react-hotkeys-hook');
15
16
  var form = require('@compill/form');
16
17
  var react = require('@soperio/react');
17
18
  var formEditor = require('@compill/form-editor');
18
19
  var editor = require('@compill/editor');
20
+ var componentsState = require('@compill/components-state');
19
21
  var reactDom = require('react-dom');
20
22
  var router_js = require('next/router.js');
21
23
  var table = require('@compill/table');
@@ -24,8 +26,8 @@ var hooks = require('@compill/hooks');
24
26
  var env = require('@compill/env');
25
27
  var reactTable = require('@tanstack/react-table');
26
28
  var reactQuery = require('@tanstack/react-query');
29
+ var layout = require('@brikka/layout');
27
30
  var Image = require('next/image.js');
28
- var auth = require('@compill/auth');
29
31
 
30
32
  function SectionTitle({ children, ...props }) {
31
33
  return /* @__PURE__ */ jsxRuntime.jsx("h2", { textSize: "xl", fontWeight: "600", textColor: "slate-800", ...props, children });
@@ -69,105 +71,12 @@ function BreadcrumbItem({ breadcrumb, showSeparator }) {
69
71
  ] });
70
72
  }
71
73
 
72
- function DialogButton({ buildDialog, ...props }) {
73
- const [showDialog, setShowDialog] = React.useState(false);
74
- const onShowDialog = React.useCallback((event) => {
75
- event?.preventDefault();
76
- event?.stopPropagation();
77
- setShowDialog(true);
78
- }, [setShowDialog]);
79
- const onCloseDialog = React.useCallback(() => {
80
- setShowDialog(false);
81
- }, [setShowDialog]);
82
- return /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
83
- /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { onClick: onShowDialog, ...props }),
84
- showDialog && buildDialog(onCloseDialog)
85
- ] });
86
- }
87
-
88
- function ButtonBar({ children, ...props }) {
89
- return /* @__PURE__ */ jsxRuntime.jsx("div", { dflex: true, border: "1px", borderColor: "zinc-200", divideX: "1px", divideColor: "zinc-200", rounded: "lg", overflow: "hidden", ...props, children });
90
- }
91
- const ButtonBarButton = React.forwardRef(
92
- function({ icon, children, ...props }, ref) {
93
- return /* @__PURE__ */ jsxRuntime.jsxs(
94
- ui.Button,
95
- {
96
- scheme: "dark",
97
- size: "sm",
98
- aspectRatio: icon && !children ? "square" : void 0,
99
- variant: "borderless",
100
- dflex: true,
101
- alignItems: "center",
102
- placeContent: "center",
103
- corners: "square",
104
- gap: "2",
105
- ...props,
106
- ref,
107
- children: [
108
- icon && /* @__PURE__ */ jsxRuntime.jsx(ui.Icon, { path: icon }),
109
- children
110
- ]
111
- }
112
- );
113
- }
114
- );
115
- const ButtonBarSubmitButton = React.forwardRef(
116
- function({ useDirty, disabled, icon, children, ...props }, ref) {
117
- const { dirty, handleSubmit } = formik.useFormikContext() ?? { dirty: false, handleSubmit: void 0};
118
- const onSubmit = React.useCallback(() => handleSubmit(), [handleSubmit]);
119
- return /* @__PURE__ */ jsxRuntime.jsxs(
120
- ui.Button,
121
- {
122
- scheme: "dark",
123
- size: "sm",
124
- aspectRatio: icon && !children ? "square" : void 0,
125
- variant: "borderless",
126
- dflex: true,
127
- alignItems: "center",
128
- placeContent: "center",
129
- corners: "square",
130
- gap: "2",
131
- disabled: useDirty && !dirty || disabled,
132
- onClick: onSubmit,
133
- ...props,
134
- ref,
135
- children: [
136
- icon && /* @__PURE__ */ jsxRuntime.jsx(ui.Icon, { path: icon }),
137
- children
138
- ]
139
- }
140
- );
141
- }
142
- );
143
- function ButtonBarDialogButton({ icon, children, ...props }) {
144
- return /* @__PURE__ */ jsxRuntime.jsxs(
145
- DialogButton,
146
- {
147
- scheme: "dark",
148
- size: "sm",
149
- aspectRatio: icon && !children ? "square" : void 0,
150
- variant: "borderless",
151
- dflex: true,
152
- alignItems: "center",
153
- placeContent: "center",
154
- corners: "square",
155
- gap: "2",
156
- ...props,
157
- children: [
158
- icon && /* @__PURE__ */ jsxRuntime.jsx(ui.Icon, { path: icon }),
159
- children
160
- ]
161
- }
162
- );
163
- }
164
-
165
74
  function InvalidateButton({ pathOrPermalink, ...props }) {
166
75
  const api$1 = adminApi.INVALIDATE_API.new(pathOrPermalink);
167
76
  const mutation = api.useApiMutation(api$1.invalidate, api$1.queryKey);
168
77
  const invalidate = api.useMutate(mutation, { successMsg: "Page successfully invalidated" });
169
78
  return /* @__PURE__ */ jsxRuntime.jsx(
170
- ButtonBarButton,
79
+ components.ButtonBarButton,
171
80
  {
172
81
  title: "Regenerate",
173
82
  disabled: mutation.isLoading,
@@ -199,7 +108,7 @@ function PublishButton({
199
108
  mutation.mutateAsync(queryId).then(() => reactToastify.toast.success(isDraft ? "Published!" : "Unpublished!")).catch((error) => reactToastify.toast.error(`Error: ${error}`));
200
109
  }, [mutation, queryId]);
201
110
  return /* @__PURE__ */ jsxRuntime.jsx(
202
- ButtonBarButton,
111
+ components.ButtonBarButton,
203
112
  {
204
113
  disabled: mutation.isLoading,
205
114
  onClick: publish,
@@ -215,7 +124,7 @@ function UpdateButton({ ...props }) {
215
124
  reactHotkeysHook.useHotkeys("ctrl+s", () => {
216
125
  if (dirty && !props.disabled) handleSubmit();
217
126
  }, { preventDefault: true }, [dirty, props, handleSubmit]);
218
- return /* @__PURE__ */ jsxRuntime.jsx(ButtonBarSubmitButton, { icon: js.mdiCloudUpload, ...props, children: "Update" });
127
+ return /* @__PURE__ */ jsxRuntime.jsx(formComponents.ButtonBarSubmitButton, { icon: js.mdiCloudUpload, ...props, children: "Update" });
219
128
  }
220
129
 
221
130
  function ViewButton({ label, path, icon, ...props }) {
@@ -223,7 +132,7 @@ function ViewButton({ label, path, icon, ...props }) {
223
132
  window.open(path, "_blank");
224
133
  }, [path]);
225
134
  return /* @__PURE__ */ jsxRuntime.jsx(
226
- ButtonBarButton,
135
+ components.ButtonBarButton,
227
136
  {
228
137
  onClick: openPage,
229
138
  dflex: true,
@@ -285,9 +194,9 @@ function PageQueryStateContainerInner({ queryId, api: api$1, apiFn, loadingStyle
285
194
  const { data, isLoading, isError } = apiFn == "getAll" ? api.useApiQuery(api$1.queryKey, api$1.getAll, props.apiParams) : api.useApiQuery(api$1.queryKey, api$1.get, queryId);
286
195
  const invalidate = api.useInvalidateQuery(api$1.queryKey, queryId);
287
196
  if (isLoading)
288
- return /* @__PURE__ */ jsxRuntime.jsx(components.QueryLoadingState, { w: "full", h: "100%", ...loadingStyles });
197
+ return /* @__PURE__ */ jsxRuntime.jsx(componentsState.QueryLoadingState, { w: "full", h: "100%", ...loadingStyles });
289
198
  if (isError)
290
- return /* @__PURE__ */ jsxRuntime.jsx(components.RetryOnError, { p: "0", onClick: invalidate, ...errorStyles });
199
+ return /* @__PURE__ */ jsxRuntime.jsx(componentsState.RetryOnError, { p: "0", onClick: invalidate, ...errorStyles });
291
200
  return /* @__PURE__ */ jsxRuntime.jsx(PageContainer, { ...props, children: apiFn == "get" ? children(data) : children(data) });
292
201
  }
293
202
  const PageQueryStateContainer = React.forwardRef(PageQueryStateContainerInner);
@@ -399,12 +308,12 @@ function ScreenTopBar({ tabbed, breadcrumbs, api, item, isLoading, buttonBar, tr
399
308
  }
400
309
  function Buttons$1({ api, item, isLoading, buttonBar }) {
401
310
  return /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
402
- buttonBar && buttonBar.length > 0 && /* @__PURE__ */ jsxRuntime.jsx(ButtonBar, { children: buttonBar.map((button, index) => /* @__PURE__ */ jsxRuntime.jsxs(React.Fragment, { children: [
311
+ buttonBar && buttonBar.length > 0 && /* @__PURE__ */ jsxRuntime.jsx(components.ButtonBar, { children: buttonBar.map((button, index) => /* @__PURE__ */ jsxRuntime.jsxs(React.Fragment, { children: [
403
312
  button.type === "link" && /* @__PURE__ */ jsxRuntime.jsx(ViewButton, { label: button.label, path: button.path, icon: button.icon }),
404
313
  button.type === "invalidate" && /* @__PURE__ */ jsxRuntime.jsx(InvalidateButton, { pathOrPermalink: button.pathOrPermalink }),
405
314
  button.type == "custom" && button.render(item)
406
315
  ] }, index)) }),
407
- /* @__PURE__ */ jsxRuntime.jsxs(ButtonBar, { children: [
316
+ /* @__PURE__ */ jsxRuntime.jsxs(components.ButtonBar, { children: [
408
317
  api instanceof adminApi.API && /* @__PURE__ */ jsxRuntime.jsx(PublishButton, { api, queryId: item.id, status: item.status, disabled: isLoading }),
409
318
  /* @__PURE__ */ jsxRuntime.jsx(UpdateButton, { disabled: isLoading })
410
319
  ] })
@@ -620,7 +529,7 @@ function TableContainer({ initialPageSize, initialVisibleColumns, columns, filte
620
529
  }
621
530
 
622
531
  function TableCreateButton({ icon, children, ...props }) {
623
- return /* @__PURE__ */ jsxRuntime.jsxs(ButtonBarDialogButton, { ...props, children: [
532
+ return /* @__PURE__ */ jsxRuntime.jsxs(components.ButtonBarDialogButton, { ...props, children: [
624
533
  /* @__PURE__ */ jsxRuntime.jsx(ui.Icon, { path: icon ?? js.mdiPlusThick }),
625
534
  children
626
535
  ] });
@@ -741,240 +650,21 @@ function TableMassActions({ actions }) {
741
650
  return /* @__PURE__ */ jsxRuntime.jsx(ui.Collapse, { in: showMassActions, style: { overflow: showMassActions ? "initial" : "hidden" }, children: /* @__PURE__ */ jsxRuntime.jsx("div", { dflex: true, gap: "3", flexWrap: true, alignItems: "center", px: "8", pt: "5", children: actions.map((action, index) => /* @__PURE__ */ jsxRuntime.jsx("div", { children: action.type == "button" && !action.showConfirmationDialog && /* @__PURE__ */ jsxRuntime.jsx(ActionButton$1, { label: action.label, queryFn: action.queryFn, queryKey: action.queryKey, buttonProps: action.buttonProps }) }, index)) }) });
742
651
  }
743
652
 
744
- const defaultErrorMsg$1 = "Oops, something went wrong...";
745
- function nonNullValues(data) {
746
- if (data) {
747
- const nonNullData = { ...data };
748
- for (const key in data)
749
- nonNullData[key] = nonNullData[key] ?? "";
750
- return nonNullData;
751
- }
752
- return data;
753
- }
754
- function ItemEditDialog({
755
- initialValues,
756
- itemLabel,
757
- queryId = "",
758
- api: api$1,
759
- queryFetchOptions,
760
- querySaveOptions,
761
- onSuccess,
762
- onFetchError,
763
- fetchErrorMsg = defaultErrorMsg$1,
764
- onSaveError,
765
- saveErrorMsg = defaultErrorMsg$1,
766
- fetchToFormData,
767
- formToQueryData,
768
- invalidateQueriesOnSuccess = true,
769
- invalidateQueryKey,
770
- retryText = "Retry",
771
- cancelLabel = "Cancel",
772
- saveLabel,
773
- size = "lg",
774
- title,
775
- form: form$1,
776
- show,
777
- onClose,
778
- formikProps,
779
- ...props
780
- }) {
781
- const { isInitialLoading, isFetching, data, isError, error, refetch } = api.useApiQuery(api$1.queryKey, api$1.get, queryId, {
782
- enabled: !/*queryId == 0 || */
783
- (queryId == "" || queryId == null || queryId == void 0),
784
- // means than this query is only enabled if the id is defined
785
- onError: onFetchError,
786
- ...queryFetchOptions
787
- });
788
- const mutation = invalidateQueriesOnSuccess ? api.useInvalidateParentMutation(api$1.upsert, invalidateQueryKey ?? api$1.queryKey, querySaveOptions) : api.useApiMutation(api$1.upsert, api$1.queryKey, queryId, querySaveOptions);
789
- const retry = React.useCallback(() => refetch(), [refetch]);
790
- const saveItem = React.useCallback(async (item, actions) => {
791
- mutation.reset();
792
- const formItem = formToQueryData ? formToQueryData(item) : { ...item };
793
- await mutation.mutateAsync(formItem).then((response) => {
794
- if (onSuccess)
795
- onSuccess(formItem, response);
796
- else
797
- reactToastify.toast.success(`${title ? title(formItem) : formItem.name ?? formItem.title} ${queryId ? "saved" : "created"}`);
798
- onClose?.();
799
- }).catch((error2) => {
800
- console.error("on error", error2);
801
- if (onSaveError)
802
- onSaveError(item);
803
- else
804
- reactToastify.toast.error(`Couldn't save ${title ? title(formItem) : formItem.name ?? formItem.title}`);
805
- actions.setSubmitting(false);
806
- });
807
- }, [mutation, formToQueryData, onSuccess, onSaveError, onClose]);
808
- return /* @__PURE__ */ jsxRuntime.jsxs(
809
- ui.Modal,
810
- {
811
- size,
812
- show,
813
- onClose,
814
- scheme: "light",
815
- transition: true,
816
- ...props,
817
- children: [
818
- /* @__PURE__ */ jsxRuntime.jsxs(ui.Modal.Header, { children: [
819
- !isInitialLoading && queryId && `Edit ${title ? title(data) : data?.["name"] ?? data?.["title"] ?? data?.["name"] ?? ""}`,
820
- !queryId && `Create new ${itemLabel ?? "item"}`,
821
- Array.isArray(form$1) && /* @__PURE__ */ jsxRuntime.jsx(jsxRuntime.Fragment, {})
822
- ] }),
823
- isInitialLoading && /* @__PURE__ */ jsxRuntime.jsx(ui.Modal.Body, { children: /* @__PURE__ */ jsxRuntime.jsx(components.QueryLoadingState, { minW: "72" }) }),
824
- isError && /* @__PURE__ */ jsxRuntime.jsx(ui.Modal.Body, { children: /* @__PURE__ */ jsxRuntime.jsx(components.RetryOnError, { label: `${fetchErrorMsg} ${error}`, onClick: retry }) }),
825
- !isInitialLoading && !isError && /* @__PURE__ */ jsxRuntime.jsx(jsxRuntime.Fragment, { children: /* @__PURE__ */ jsxRuntime.jsx(
826
- formik.Formik,
827
- {
828
- initialValues: fetchToFormData && queryId && data ? fetchToFormData(nonNullValues(data)) : nonNullValues(initialValues(data)) ?? {},
829
- onSubmit: saveItem,
830
- ...formikProps,
831
- children: ({ setFieldValue, dirty, handleSubmit, isValid, values }) => /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
832
- /* @__PURE__ */ jsxRuntime.jsx(ui.Modal.Body, { pb: "6", children: /* @__PURE__ */ jsxRuntime.jsxs(formik.Form, { children: [
833
- React.isValidElement(form$1) && form$1,
834
- Array.isArray(form$1) && /* @__PURE__ */ jsxRuntime.jsx(form.FormRenderer, { form: form$1 }),
835
- react.isFunction(form$1) && /* @__PURE__ */ jsxRuntime.jsx(form.FormRenderer, { form: form$1(data ?? values) })
836
- ] }) }),
837
- /* @__PURE__ */ jsxRuntime.jsxs(ui.Modal.Footer, { dflex: true, placeContent: "end", spaceX: "3", children: [
838
- /* @__PURE__ */ jsxRuntime.jsx(
839
- ui.Button,
840
- {
841
- disabled: mutation.isLoading,
842
- onClick: onClose,
843
- variant: "borderless",
844
- me: "2",
845
- children: cancelLabel
846
- }
847
- ),
848
- /* @__PURE__ */ jsxRuntime.jsx(
849
- ui.Button,
850
- {
851
- type: "submit",
852
- disabled: !dirty || mutation.isLoading,
853
- onClick: () => handleSubmit(),
854
- children: saveLabel ? saveLabel : queryId ? "Update" : "Create"
855
- }
856
- )
857
- ] })
858
- ] })
859
- }
860
- ) }),
861
- mutation.isLoading && /* @__PURE__ */ jsxRuntime.jsx(components.ModalLoadingOverlay, {})
862
- ]
863
- }
864
- );
865
- }
866
-
867
- function QueryWrapperDialog({ api: api$1, fn, transformFn, config, onClose, queryId, invalidateQueryKey }) {
868
- const { data, isFetching } = api.useApiQuery(
869
- api$1.queryKey,
870
- fn === "get" || fn === "getTransformed" ? api$1.get : api$1.getAll,
871
- void 0,
872
- { retryOnMount: false, refetchOnMount: false, refetchOnWindowFocus: false }
873
- );
874
- const transformedData = React.useMemo(() => {
875
- if (data && (fn === "getTransformed" || fn === "getAllTransformed")) {
876
- if (!transformFn)
877
- console.warn(`QueryWrapperDialog: you forgot to pass transformFn as parameter for fn ${fn}`);
878
- return transformFn?.(data);
879
- }
880
- return data;
881
- }, [data, fn, transformFn]);
882
- if (isFetching)
883
- return null;
884
- return /* @__PURE__ */ jsxRuntime.jsx(ItemEditDialog, { ...config(transformedData), queryId, invalidateQueryKey, show: true, onClose });
885
- }
886
-
887
- function MultiQueryWrapperDialog({ queries, config, onClose, queryId, invalidateQueryKey }) {
888
- const { data, isFetching, isError } = api.useApiQueries(queries.map((q) => ({
889
- queryKey: q.api.queryKey,
890
- queryFn: q.fn == "get" ? q.api.get : q.api.getAll,
891
- queryOptions: {
892
- cacheTime: q.cache === false ? 0 : void 0,
893
- staleTime: q.cache === false ? 0 : void 0
894
- }
895
- })));
896
- const transformedData = React.useMemo(() => {
897
- return data?.map((d, index) => queries[index]?.transformFn ? queries[index]?.transformFn?.(d) : d);
898
- }, [data, queries]);
899
- return /* @__PURE__ */ jsxRuntime.jsx(ItemEditDialog, { isPreloading: isFetching, ...config(...transformedData), queryId, invalidateQueryKey, show: true, onClose });
900
- }
901
-
902
653
  function DialogRenderer({ config, onClose, invalidateQueryKey, queryId }) {
903
654
  const { type, ...props } = config;
904
655
  if (config.type === "dialog")
905
- return /* @__PURE__ */ jsxRuntime.jsx(ItemEditDialog, { ...props, queryId, invalidateQueryKey, show: true, onClose });
656
+ return /* @__PURE__ */ jsxRuntime.jsx(formComponents.ItemEditDialog, { ...props, queryId, invalidateQueryKey, show: true, onClose });
906
657
  if (config.type === "query")
907
- return /* @__PURE__ */ jsxRuntime.jsx(QueryWrapperDialog, { ...props, queryId, invalidateQueryKey, onClose });
658
+ return /* @__PURE__ */ jsxRuntime.jsx(formComponents.ItemEditWrappedDialog, { ...props, queryId, invalidateQueryKey, onClose });
908
659
  if (config.type === "multiQuery")
909
- return /* @__PURE__ */ jsxRuntime.jsx(MultiQueryWrapperDialog, { ...props, queryId, invalidateQueryKey, onClose });
660
+ return /* @__PURE__ */ jsxRuntime.jsx(formComponents.ItemEditMultiWrappedDialog, { ...props, queryId, invalidateQueryKey, onClose });
910
661
  return null;
911
662
  }
912
663
 
913
664
  function RefreshButton({ queryKey }) {
914
665
  const invalidate = api.useInvalidateQuery(queryKey);
915
666
  reactHotkeysHook.useHotkeys("ctrl+r", () => invalidate(), { preventDefault: true }, [invalidate]);
916
- return /* @__PURE__ */ jsxRuntime.jsx(ButtonBarButton, { scheme: "dark", size: "sm", aspectRatio: "square", variant: "borderless", onClick: invalidate, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Icon, { path: js.mdiRefresh }) });
917
- }
918
-
919
- function ItemDeleteDialog({
920
- title,
921
- actionButtonLabel,
922
- closeActionButtonLabel = "Cancel",
923
- itemLabel,
924
- queryId = "",
925
- api: api$1,
926
- apiFn,
927
- invalidateQueriesOnSuccess = true,
928
- invalidateQueryKey,
929
- size = "lg",
930
- md_boxSizing,
931
- msg,
932
- show,
933
- onClose,
934
- onSuccess,
935
- ...props
936
- }) {
937
- const fn = apiFn ? api$1[apiFn] : api$1.delete;
938
- const mutation = invalidateQueriesOnSuccess ? api.useInvalidateParentMutation(fn, invalidateQueryKey ?? api$1.queryKey) : api.useApiMutation(fn, api$1.queryKey);
939
- const mutate = api.useMutate(mutation, { onSuccess: () => {
940
- onClose?.();
941
- onSuccess?.();
942
- } });
943
- const handleDelete = React.useCallback(() => mutate(queryId), [mutate, queryId]);
944
- return /* @__PURE__ */ jsxRuntime.jsxs(
945
- ui.Modal,
946
- {
947
- size,
948
- show,
949
- onClose,
950
- scheme: "danger",
951
- variant: "glass",
952
- transition: true,
953
- ...props,
954
- children: [
955
- /* @__PURE__ */ jsxRuntime.jsx(ui.Modal.Header, { children: title || `Delete ${itemLabel}` }),
956
- /* @__PURE__ */ jsxRuntime.jsxs(ui.Modal.Body, { pb: "6", children: [
957
- !msg && `Do you really want to delete ${itemLabel}?`,
958
- msg && react.runIfFn(msg, itemLabel)
959
- ] }),
960
- /* @__PURE__ */ jsxRuntime.jsxs(ui.Modal.Footer, { dflex: true, placeContent: "end", spaceX: "3", children: [
961
- /* @__PURE__ */ jsxRuntime.jsx(
962
- ui.Button,
963
- {
964
- disabled: mutation.isPending,
965
- onClick: onClose,
966
- variant: "borderless",
967
- scheme: "dark",
968
- me: "2",
969
- children: closeActionButtonLabel
970
- }
971
- ),
972
- /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { scheme: "danger", disabled: mutation.isPending, onClick: handleDelete, children: actionButtonLabel || "Delete" })
973
- ] }),
974
- mutation.isPending && /* @__PURE__ */ jsxRuntime.jsx(components.ModalLoadingOverlay, {})
975
- ]
976
- }
977
- );
667
+ return /* @__PURE__ */ jsxRuntime.jsx(components.ButtonBarButton, { scheme: "dark", size: "sm", aspectRatio: "square", variant: "borderless", onClick: invalidate, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Icon, { path: js.mdiRefresh }) });
978
668
  }
979
669
 
980
670
  const [provider, useContext] = react.createContext();
@@ -1018,7 +708,7 @@ function TableViewProvider({ editView, deleteItem, queryKey, children }) {
1018
708
  const deleteConfig = react.runIfFn(deleteItem, item);
1019
709
  setDialog(
1020
710
  /* @__PURE__ */ jsxRuntime.jsx(
1021
- ItemDeleteDialog,
711
+ formComponents.ItemDeleteDialog,
1022
712
  {
1023
713
  show: true,
1024
714
  onClose: onCloseDialog,
@@ -1211,7 +901,7 @@ function TableButtonBar({ buttonBar, queryKey, createView, editView, api, childr
1211
901
  return /* @__PURE__ */ jsxRuntime.jsx(DialogRenderer, { config: view, onClose, invalidateQueryKey: api.queryKey });
1212
902
  };
1213
903
  }, [createView, editView, api]);
1214
- return /* @__PURE__ */ jsxRuntime.jsxs(ButtonBar, { children: [
904
+ return /* @__PURE__ */ jsxRuntime.jsxs(components.ButtonBar, { children: [
1215
905
  /* @__PURE__ */ jsxRuntime.jsx(RefreshButton, { queryKey }),
1216
906
  buttonBar && buttonBar.map(
1217
907
  (button, index) => /* @__PURE__ */ jsxRuntime.jsxs(React.Fragment, { children: [
@@ -1301,9 +991,9 @@ function MultiQueryWrapper({
1301
991
  const { data, isFetching, isError } = useQueries(queries);
1302
992
  const invalidate = useInvalidate(queries);
1303
993
  if (isFetching)
1304
- return /* @__PURE__ */ jsxRuntime.jsx(components.QueryLoadingState, { w: "full", h: "100vh" });
994
+ return /* @__PURE__ */ jsxRuntime.jsx(componentsState.QueryLoadingState, { w: "full", h: "100vh" });
1305
995
  if (isError || !data)
1306
- return /* @__PURE__ */ jsxRuntime.jsx(components.RetryOnError, { p: "0", w: "full", h: "100vh", onClick: invalidate });
996
+ return /* @__PURE__ */ jsxRuntime.jsx(componentsState.RetryOnError, { p: "0", w: "full", h: "100vh", onClick: invalidate });
1307
997
  return /* @__PURE__ */ jsxRuntime.jsx(ScreenRenderer, { config: config(...data), tabbed, ...props });
1308
998
  }
1309
999
 
@@ -1325,283 +1015,6 @@ function Content({ ...props }) {
1325
1015
  return /* @__PURE__ */ jsxRuntime.jsx("div", { w: "100%", h: "100%", overflowY: "auto", ...props, children: /* @__PURE__ */ jsxRuntime.jsx(reactRouterDom.Outlet, {}) });
1326
1016
  }
1327
1017
 
1328
- function SelectedIndicator({ darkMode }) {
1329
- return /* @__PURE__ */ jsxRuntime.jsx(
1330
- "div",
1331
- {
1332
- position: "absolute",
1333
- bgColor: darkMode ? "white" : "black",
1334
- bgOpacity: "90",
1335
- w: "0.5",
1336
- h: "6",
1337
- top: "1.5",
1338
- start: "-4"
1339
- }
1340
- );
1341
- }
1342
-
1343
- function MenuButton({ depth, darkMode, icon, selected, children, ...props }) {
1344
- return /* @__PURE__ */ jsxRuntime.jsxs(
1345
- ui.Button,
1346
- {
1347
- as: "li",
1348
- minH: "8",
1349
- ms: `${(depth ?? 0) * 2}`,
1350
- p: "2",
1351
- font: "title",
1352
- textColor: darkMode ? "white" : "black",
1353
- fontWeight: "600",
1354
- rounded: "lg",
1355
- textSize: "sm",
1356
- variant: "borderless",
1357
- hover_bgColor: darkMode ? "white" : "black",
1358
- hover_bgOpacity: "10",
1359
- hover_textColor: darkMode ? "white" : "zinc-800",
1360
- cursor: "pointer",
1361
- dflex: true,
1362
- alignItems: "center",
1363
- gap: "3",
1364
- ...props,
1365
- children: [
1366
- icon && /* @__PURE__ */ jsxRuntime.jsx(ui.Icon, { path: icon, opacity: selected ? "100" : "60" }),
1367
- children
1368
- ]
1369
- }
1370
- );
1371
- }
1372
-
1373
- function MenuItem$1({ icon, path, depth, darkMode, subMenu, ...props }) {
1374
- const location = reactRouterDom.useLocation();
1375
- const selected = path == "/" ? location.pathname == "/" : location.pathname.startsWith(path.startsWith("/") ? path : `/${path}`);
1376
- const match = reactRouterDom.useMatch("/" + path) != null;
1377
- return /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
1378
- /* @__PURE__ */ jsxRuntime.jsxs(reactRouterDom.Link, { to: path, style: { position: "relative" }, children: [
1379
- /* @__PURE__ */ jsxRuntime.jsx(
1380
- MenuButton,
1381
- {
1382
- depth,
1383
- darkMode,
1384
- icon,
1385
- selected,
1386
- ...props
1387
- }
1388
- ),
1389
- match && /* @__PURE__ */ jsxRuntime.jsx(SelectedIndicator, { darkMode })
1390
- ] }),
1391
- subMenu?.map((item, index) => /* @__PURE__ */ jsxRuntime.jsx(
1392
- MenuItem$1,
1393
- {
1394
- icon: item.icon,
1395
- path: item.path,
1396
- depth: (depth ?? 0) + 1,
1397
- darkMode,
1398
- subMenu: item.children,
1399
- children: item.label
1400
- },
1401
- index
1402
- ))
1403
- ] });
1404
- }
1405
-
1406
- function NextMenuItem({ icon, path, depth, darkMode, subMenu, ...props }) {
1407
- const { pathname } = router_js.useRouter();
1408
- const selected = path == "/" ? pathname == "/" : pathname.startsWith(path.startsWith("/") ? path : `/${path}`);
1409
- const match = path == "/" ? pathname == "/" : pathname == (path.startsWith("/") ? path : `/${path}`);
1410
- return /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
1411
- /* @__PURE__ */ jsxRuntime.jsxs(Link, { href: path, style: { position: "relative" }, children: [
1412
- /* @__PURE__ */ jsxRuntime.jsx(
1413
- MenuButton,
1414
- {
1415
- depth,
1416
- darkMode,
1417
- icon,
1418
- selected,
1419
- ...props
1420
- }
1421
- ),
1422
- match && /* @__PURE__ */ jsxRuntime.jsx(SelectedIndicator, { darkMode })
1423
- ] }),
1424
- subMenu?.map((item, index) => /* @__PURE__ */ jsxRuntime.jsx(
1425
- NextMenuItem,
1426
- {
1427
- icon: item.icon,
1428
- path: item.path,
1429
- depth: (depth ?? 0) + 1,
1430
- darkMode,
1431
- subMenu: item.children,
1432
- children: item.label
1433
- },
1434
- index
1435
- ))
1436
- ] });
1437
- }
1438
-
1439
- function Menu({ darkMode, config, useNextRouter, ...props }) {
1440
- const Comp = useNextRouter ? NextMenuItem : MenuItem$1;
1441
- return /* @__PURE__ */ jsxRuntime.jsx("ul", { ...props, children: config.map((item, index) => {
1442
- if (item.type == "divider")
1443
- return /* @__PURE__ */ jsxRuntime.jsx(Divider, { title: item.label }, index);
1444
- if (item.type == "item") {
1445
- return /* @__PURE__ */ jsxRuntime.jsx(
1446
- Comp,
1447
- {
1448
- icon: item.icon,
1449
- path: item.path,
1450
- depth: 0,
1451
- darkMode,
1452
- subMenu: item.children,
1453
- children: item.label
1454
- },
1455
- index
1456
- );
1457
- }
1458
- }) });
1459
- }
1460
- function Divider({ title }) {
1461
- return /* @__PURE__ */ jsxRuntime.jsx(
1462
- "div",
1463
- {
1464
- px: "2",
1465
- mt: "5",
1466
- mb: "2",
1467
- opacity: "75",
1468
- textTransform: "capitalize",
1469
- letterSpacing: "widest",
1470
- fontWeight: "700",
1471
- textSize: "xs",
1472
- children: title
1473
- }
1474
- );
1475
- }
1476
-
1477
- function UserBlock({ color, darkMode, menuConfig, path }) {
1478
- const { isLoading, user } = auth.useSessionUser();
1479
- const navigate = reactRouterDom.useNavigate();
1480
- const handleClick = React.useCallback(() => navigate(path), [navigate, path]);
1481
- if (isLoading)
1482
- return null;
1483
- return /* @__PURE__ */ jsxRuntime.jsxs(
1484
- "div",
1485
- {
1486
- dflex: true,
1487
- alignItems: "center",
1488
- border: "0.5",
1489
- borderColor: `${color}-${darkMode ? "800" : "200"}`,
1490
- ps: "3",
1491
- py: "1.5",
1492
- textSize: "md",
1493
- rounded: "lg",
1494
- hover_bgColor: `${color}-${darkMode ? "800" : "200"}`,
1495
- cursor: "pointer",
1496
- textColor: darkMode ? "white" : "slate-800",
1497
- onClick: handleClick,
1498
- children: [
1499
- /* @__PURE__ */ jsxRuntime.jsx(ui.Avatar, { size: "sm", src: user?.media?.url ?? "", name: `${user?.firstname} ${user?.lastname}` }),
1500
- /* @__PURE__ */ jsxRuntime.jsx("span", { flexGrow: true, ms: "2", children: `${esToolkit.capitalize(user?.firstname || user?.lastname || "")}` }),
1501
- /* @__PURE__ */ jsxRuntime.jsx(
1502
- ui.IconButton,
1503
- {
1504
- variant: "borderless",
1505
- corners: "pill",
1506
- scheme: "dark",
1507
- textColor: darkMode ? "white" : "slate-800",
1508
- hover_textColor: darkMode ? "white" : "slate-800",
1509
- hover_bgColor: `${color}-${darkMode ? "900" : "200"}`,
1510
- icon: js.mdiCog,
1511
- onClick: handleClick
1512
- }
1513
- ),
1514
- /* @__PURE__ */ jsxRuntime.jsx(OverflowMenu, { color, darkMode, menuConfig })
1515
- ]
1516
- }
1517
- );
1518
- }
1519
- function OverflowMenu({ color, darkMode, menuConfig }) {
1520
- const [showPopup, setShowPopup] = React.useState(false);
1521
- const navigate = reactRouterDom.useNavigate();
1522
- const logout = auth.useSessionLogout(false);
1523
- return /* @__PURE__ */ jsxRuntime.jsx(jsxRuntime.Fragment, { children: /* @__PURE__ */ jsxRuntime.jsxs(
1524
- ui.Popup,
1525
- {
1526
- show: showPopup,
1527
- position: "relative",
1528
- side: "bottom-end",
1529
- onClick: (e) => {
1530
- e.preventDefault();
1531
- e.stopPropagation();
1532
- setShowPopup((show) => !show);
1533
- },
1534
- onHide: () => setShowPopup(false),
1535
- children: [
1536
- /* @__PURE__ */ jsxRuntime.jsx(
1537
- ui.IconButton,
1538
- {
1539
- icon: js.mdiDotsVertical,
1540
- variant: "borderless",
1541
- corners: "pill",
1542
- scheme: "dark",
1543
- textColor: darkMode ? "white" : "slate-800",
1544
- hover_textColor: darkMode ? "white" : "slate-800",
1545
- hover_bgColor: `${color}-${darkMode ? "900" : "200"}`
1546
- }
1547
- ),
1548
- /* @__PURE__ */ jsxRuntime.jsxs(
1549
- "div",
1550
- {
1551
- bgColor: "white",
1552
- rounded: "sm",
1553
- overflow: "hidden",
1554
- shadow: true,
1555
- mt: "1",
1556
- border: "px",
1557
- borderColor: "gray-200",
1558
- divideColor: "gray-200",
1559
- divideY: "px",
1560
- minW: "40",
1561
- children: [
1562
- menuConfig && menuConfig.length > 0 && menuConfig.map((item, index) => {
1563
- if (item.type == "item") {
1564
- return /* @__PURE__ */ jsxRuntime.jsx(MenuItem, { icon: item.icon, onClick: () => navigate(item.path), children: item.label }, index);
1565
- }
1566
- return null;
1567
- }),
1568
- /* @__PURE__ */ jsxRuntime.jsx(MenuItem, { icon: js.mdiLogout, onClick: logout, children: "Logout" })
1569
- ]
1570
- }
1571
- )
1572
- ]
1573
- }
1574
- ) });
1575
- }
1576
- function MenuItem({ icon, onClick, children, ...props }) {
1577
- const handleClick = React.useCallback((e) => {
1578
- e.preventDefault();
1579
- e.stopPropagation();
1580
- onClick?.(e);
1581
- }, []);
1582
- return /* @__PURE__ */ jsxRuntime.jsxs(
1583
- ui.Button,
1584
- {
1585
- variant: "borderless",
1586
- scheme: "dark",
1587
- size: "sm",
1588
- alignItems: "center",
1589
- dflex: true,
1590
- gap: "2",
1591
- px: "2",
1592
- py: "1.5",
1593
- w: "full",
1594
- onClick: handleClick,
1595
- textColor: "slate-700",
1596
- ...props,
1597
- children: [
1598
- icon && /* @__PURE__ */ jsxRuntime.jsx(ui.Icon, { path: icon, size: "md" }),
1599
- children
1600
- ]
1601
- }
1602
- );
1603
- }
1604
-
1605
1018
  function Sidebar({ show, logo, title, menuConfig, userMenuConfig, userSettingsPath, color, darkMode, ...props }) {
1606
1019
  return /* @__PURE__ */ jsxRuntime.jsxs(
1607
1020
  "div",
@@ -1631,8 +1044,8 @@ function Sidebar({ show, logo, title, menuConfig, userMenuConfig, userSettingsPa
1631
1044
  ]
1632
1045
  }
1633
1046
  ),
1634
- /* @__PURE__ */ jsxRuntime.jsx(Menu, { overflowY: "auto", flexGrow: "1", p: "4", darkMode, config: menuConfig }),
1635
- /* @__PURE__ */ jsxRuntime.jsx("div", { p: "2", children: /* @__PURE__ */ jsxRuntime.jsx(UserBlock, { darkMode, color, menuConfig: userMenuConfig, path: userSettingsPath }) })
1047
+ /* @__PURE__ */ jsxRuntime.jsx(layout.SidebarMenu, { overflowY: "auto", flexGrow: "1", p: "4", darkMode, config: menuConfig }),
1048
+ /* @__PURE__ */ jsxRuntime.jsx("div", { p: "2", children: /* @__PURE__ */ jsxRuntime.jsx(layout.SidebarMenuUserBlock, { darkMode, color, menuConfig: userMenuConfig, path: userSettingsPath }) })
1636
1049
  ]
1637
1050
  }
1638
1051
  );
@@ -1816,8 +1229,8 @@ function AttachDialog({
1816
1229
  ...props,
1817
1230
  children: [
1818
1231
  /* @__PURE__ */ jsxRuntime.jsx(ui.Modal.Header, { children: `Add ${itemLabel}` }),
1819
- isLoading && /* @__PURE__ */ jsxRuntime.jsx(ui.Modal.Body, { children: /* @__PURE__ */ jsxRuntime.jsx(components.QueryLoadingState, { minW: "72" }) }),
1820
- isError && /* @__PURE__ */ jsxRuntime.jsx(ui.Modal.Body, { children: /* @__PURE__ */ jsxRuntime.jsx(components.RetryOnError, { label: `${fetchErrorMsg} ${error}`, onClick: retry }) }),
1232
+ isLoading && /* @__PURE__ */ jsxRuntime.jsx(ui.Modal.Body, { children: /* @__PURE__ */ jsxRuntime.jsx(componentsState.QueryLoadingState, { minW: "72" }) }),
1233
+ isError && /* @__PURE__ */ jsxRuntime.jsx(ui.Modal.Body, { children: /* @__PURE__ */ jsxRuntime.jsx(componentsState.RetryOnError, { label: `${fetchErrorMsg} ${error}`, onClick: retry }) }),
1821
1234
  !isLoading && !isError && /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
1822
1235
  /* @__PURE__ */ jsxRuntime.jsx(ui.Modal.Body, { px: "0", pb: "6", maxH: "750px", overflow: "auto", children: /* @__PURE__ */ jsxRuntime.jsx("div", { dflex: true, flexCol: true, overflow: "auto", children: resources.map((item) => /* @__PURE__ */ jsxRuntime.jsx(
1823
1236
  ListItem,
@@ -1852,7 +1265,7 @@ function AttachDialog({
1852
1265
  )
1853
1266
  ] })
1854
1267
  ] }),
1855
- mutation.isLoading && /* @__PURE__ */ jsxRuntime.jsx(components.ModalLoadingOverlay, {})
1268
+ mutation.isLoading && /* @__PURE__ */ jsxRuntime.jsx(componentsState.ModalLoadingOverlay, {})
1856
1269
  ]
1857
1270
  }
1858
1271
  );
@@ -1949,7 +1362,7 @@ function FormActionDialog({
1949
1362
  ]
1950
1363
  }
1951
1364
  ),
1952
- mutation.isLoading && /* @__PURE__ */ jsxRuntime.jsx(components.ModalLoadingOverlay, {})
1365
+ mutation.isLoading && /* @__PURE__ */ jsxRuntime.jsx(componentsState.ModalLoadingOverlay, {})
1953
1366
  ]
1954
1367
  }
1955
1368
  );
@@ -1957,7 +1370,7 @@ function FormActionDialog({
1957
1370
 
1958
1371
  const PageStateContainer = React.forwardRef(({ loading = false, children, ...props }, ref) => {
1959
1372
  return /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
1960
- loading && /* @__PURE__ */ jsxRuntime.jsx(components.QueryLoadingState, { w: "full", h: "100%" }),
1373
+ loading && /* @__PURE__ */ jsxRuntime.jsx(componentsState.QueryLoadingState, { w: "full", h: "100%" }),
1961
1374
  !loading && /* @__PURE__ */ jsxRuntime.jsx(ui.Container, { ref, center: true, size: "x2", dflex: true, flexCol: true, gap: "8", ...props, children })
1962
1375
  ] });
1963
1376
  });
@@ -2007,7 +1420,7 @@ function TableRowNavigateButton({ path, ...props }) {
2007
1420
 
2008
1421
  function TableRowActionDialogButton({ icon, children, ...props }) {
2009
1422
  return /* @__PURE__ */ jsxRuntime.jsxs(
2010
- DialogButton,
1423
+ components.DialogButton,
2011
1424
  {
2012
1425
  dflex: true,
2013
1426
  alignContent: "center",
@@ -2069,16 +1482,8 @@ function TableRowPublishPostButton({ id, api: api$1, status, invalidateQueryKey,
2069
1482
  exports.AdminLayout = AdminLayout;
2070
1483
  exports.AttachDialog = AttachDialog;
2071
1484
  exports.Breadcrumbs = Breadcrumbs;
2072
- exports.ButtonBar = ButtonBar;
2073
- exports.ButtonBarButton = ButtonBarButton;
2074
- exports.ButtonBarDialogButton = ButtonBarDialogButton;
2075
- exports.ButtonBarSubmitButton = ButtonBarSubmitButton;
2076
- exports.DialogButton = DialogButton;
2077
1485
  exports.FormActionDialog = FormActionDialog;
2078
1486
  exports.InvalidateButton = InvalidateButton;
2079
- exports.ItemDeleteDialog = ItemDeleteDialog;
2080
- exports.ItemEditDialog = ItemEditDialog;
2081
- exports.Menu = Menu;
2082
1487
  exports.NavigateButton = NavigateButton;
2083
1488
  exports.OrderCell = OrderCell;
2084
1489
  exports.PageContainer = PageContainer;