@compill/admin 1.0.73 → 1.0.75

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/index.cjs.js CHANGED
@@ -8,15 +8,15 @@ var Link = require('next/link');
8
8
  var React = require('react');
9
9
  var adminApi = require('@compill/admin-api');
10
10
  var api = require('@compill/api');
11
+ var formik = require('formik');
11
12
  var reactRouterDom = require('react-router-dom');
13
+ var admin = require('@compill/admin');
12
14
  var reactToastify = require('react-toastify');
13
- var form = require('@compill/form');
14
- var formik = require('formik');
15
15
  require('react/jsx-runtime');
16
16
  var components = require('@compill/components');
17
+ var form = require('@compill/form');
17
18
  var react = require('@soperio/react');
18
19
  var editor = require('@compill/editor');
19
- var admin = require('@compill/admin');
20
20
  var reactDom = require('react-dom');
21
21
  var router = require('next/router');
22
22
  var table = require('@compill/table');
@@ -205,6 +205,43 @@ const ButtonBarButton = /*#__PURE__*/React__default["default"].forwardRef(functi
205
205
  }), children]
206
206
  }));
207
207
  });
208
+ const ButtonBarSubmitButton = /*#__PURE__*/React__default["default"].forwardRef(function (_a, ref) {
209
+ var _b;
210
+ var {
211
+ useDirty,
212
+ disabled,
213
+ icon,
214
+ children
215
+ } = _a,
216
+ props = __rest$1(_a, ["useDirty", "disabled", "icon", "children"]);
217
+ const {
218
+ dirty,
219
+ handleSubmit
220
+ } = (_b = formik.useFormikContext()) !== null && _b !== void 0 ? _b : {
221
+ dirty: false,
222
+ handleSubmit: undefined,
223
+ values: {}
224
+ };
225
+ const onSubmit = React__default["default"].useCallback(() => handleSubmit(), [handleSubmit]);
226
+ return jsxRuntime.jsxs(ui.Button, Object.assign({
227
+ scheme: "dark",
228
+ size: "sm",
229
+ aspectRatio: icon && !children ? "square" : undefined,
230
+ variant: "borderless",
231
+ dflex: true,
232
+ alignItems: "center",
233
+ placeContent: "center",
234
+ corners: "square",
235
+ gap: "2",
236
+ disabled: useDirty && !dirty || disabled,
237
+ onClick: onSubmit
238
+ }, props, {
239
+ ref: ref,
240
+ children: [icon && jsxRuntime.jsx(ui.Icon, {
241
+ path: icon
242
+ }), children]
243
+ }));
244
+ });
208
245
  function ButtonBarDialogButton(_a) {
209
246
  var {
210
247
  icon,
@@ -285,20 +322,12 @@ function PublishButton(_a) {
285
322
  mutation.reset();
286
323
  mutation.mutateAsync(queryId).then(() => reactToastify.toast.success(isDraft ? "Published!" : "Unpublished!")).catch(error => reactToastify.toast.error(`Error: ${error}`));
287
324
  }, [mutation, queryId]);
288
- return jsxRuntime.jsxs(ui.Button, Object.assign({
289
- scheme: "secondary",
290
- variant: "glass",
291
- size: "sm",
292
- px: "3",
325
+ return jsxRuntime.jsx(admin.ButtonBarButton, Object.assign({
293
326
  disabled: mutation.isLoading,
294
327
  onClick: publish,
295
- dflex: true,
296
- alignItems: "center",
297
- gap: "3"
328
+ icon: isDraft ? mdiEye : mdiEyeOff
298
329
  }, props, {
299
- children: [jsxRuntime.jsx(ui.Icon, {
300
- path: isDraft ? mdiEye : mdiEyeOff
301
- }), isDraft ? "Publish" : "Switch to draft"]
330
+ children: isDraft ? "Publish" : "Switch to draft"
302
331
  }));
303
332
  }
304
333
 
@@ -705,17 +734,10 @@ function UpdateButton(_a) {
705
734
  }, {
706
735
  preventDefault: true
707
736
  }, [dirty, props, handleSubmit]);
708
- return jsxRuntime.jsxs(form.SubmitButton, Object.assign({
709
- type: "submit",
710
- size: "sm",
711
- px: "3",
712
- dflex: true,
713
- alignItems: "center",
714
- gap: "3"
737
+ return jsxRuntime.jsx(admin.ButtonBarSubmitButton, Object.assign({
738
+ icon: mdiCloudUpload
715
739
  }, props, {
716
- children: [jsxRuntime.jsx(ui.Icon, {
717
- path: mdiCloudUpload
718
- }), "Update"]
740
+ children: "Update"
719
741
  }));
720
742
  }
721
743
 
@@ -1119,13 +1141,15 @@ function Buttons$1({
1119
1141
  }), button.type === "invalidate" && jsxRuntime.jsx(InvalidateButton, {
1120
1142
  pathOrPermalink: button.pathOrPermalink
1121
1143
  }), button.type == "custom" && button.render(item)]
1122
- }, index)), jsxRuntime.jsx(PublishButton, {
1123
- api: api,
1124
- queryId: item.id,
1125
- status: item.status,
1126
- disabled: isLoading
1127
- }), jsxRuntime.jsx(UpdateButton, {
1128
- disabled: isLoading
1144
+ }, index)), jsxRuntime.jsxs(admin.ButtonBar, {
1145
+ children: [api instanceof adminApi.API && jsxRuntime.jsx(PublishButton, {
1146
+ api: api,
1147
+ queryId: item.id,
1148
+ status: item.status,
1149
+ disabled: isLoading
1150
+ }), jsxRuntime.jsx(UpdateButton, {
1151
+ disabled: isLoading
1152
+ })]
1129
1153
  })]
1130
1154
  });
1131
1155
  }
@@ -2237,6 +2261,7 @@ function ItemDeleteDialog(_a) {
2237
2261
  itemLabel,
2238
2262
  queryId = "",
2239
2263
  api: api$1,
2264
+ apiFn,
2240
2265
  invalidateQueriesOnSuccess = true,
2241
2266
  invalidateQueryKey,
2242
2267
  size = "lg",
@@ -2245,8 +2270,9 @@ function ItemDeleteDialog(_a) {
2245
2270
  show,
2246
2271
  onClose
2247
2272
  } = _a,
2248
- props = __rest$1(_a, ["itemLabel", "queryId", "api", "invalidateQueriesOnSuccess", "invalidateQueryKey", "size", "md_boxSizing", "msg", "show", "onClose"]);
2249
- const mutation = invalidateQueriesOnSuccess ? api.useInvalidateParentMutation(api$1.delete, invalidateQueryKey !== null && invalidateQueryKey !== void 0 ? invalidateQueryKey : api$1.queryKey) : api.useApiMutation(api$1.delete, api$1.queryKey);
2273
+ props = __rest$1(_a, ["itemLabel", "queryId", "api", "apiFn", "invalidateQueriesOnSuccess", "invalidateQueryKey", "size", "md_boxSizing", "msg", "show", "onClose"]);
2274
+ const fn = apiFn ? api$1[apiFn] : api$1.delete;
2275
+ const mutation = invalidateQueriesOnSuccess ? api.useInvalidateParentMutation(fn, invalidateQueryKey !== null && invalidateQueryKey !== void 0 ? invalidateQueryKey : api$1.queryKey) : api.useApiMutation(fn, api$1.queryKey);
2250
2276
  const mutate = api.useMutate(mutation, {
2251
2277
  onSuccess: () => onClose === null || onClose === void 0 ? void 0 : onClose()
2252
2278
  });
@@ -3652,6 +3678,7 @@ exports.Breadcrumbs = Breadcrumbs;
3652
3678
  exports.ButtonBar = ButtonBar;
3653
3679
  exports.ButtonBarButton = ButtonBarButton;
3654
3680
  exports.ButtonBarDialogButton = ButtonBarDialogButton;
3681
+ exports.ButtonBarSubmitButton = ButtonBarSubmitButton;
3655
3682
  exports.DialogButton = DialogButton;
3656
3683
  exports.FormActionDialog = FormActionDialog;
3657
3684
  exports.InvalidateButton = InvalidateButton;
package/index.esm.js CHANGED
@@ -2,17 +2,17 @@ import { jsx, jsxs, Fragment } from '@soperio/jsx-runtime';
2
2
  import { Icon, Button, IconButton, Container, Tile, Popover, Collapse, Modal, Checkbox, Badge } from '@valerya/ui';
3
3
  import Link from 'next/link';
4
4
  import React, { useRef, useCallback, useContext as useContext$2, useLayoutEffect, useEffect, createContext } from 'react';
5
- import { INVALIDATE_API } from '@compill/admin-api';
5
+ import { INVALIDATE_API, API } from '@compill/admin-api';
6
6
  import { useApiMutation, useMutate, useInvalidateMutation, useApiQuery, useInvalidateQuery, useInvalidateParentMutation, useApiQueries } from '@compill/api';
7
+ import { useFormikContext, Field, Formik, Form } from 'formik';
7
8
  import { useNavigate, useParams, Outlet, useLocation, useMatch, Link as Link$1 } from 'react-router-dom';
9
+ import { ButtonBarButton as ButtonBarButton$1, ButtonBarSubmitButton as ButtonBarSubmitButton$1, PageSectionTitle as PageSectionTitle$1, ButtonBar as ButtonBar$1, ButtonBarDialogButton as ButtonBarDialogButton$1, TableRowActionButton as TableRowActionButton$1, DialogButton as DialogButton$1 } from '@compill/admin';
8
10
  import { toast } from 'react-toastify';
9
- import { SubmitButton, FormProvider, TextArea, FormRenderer, mergeInitialFormValues, FieldLabel } from '@compill/form';
10
- import { useFormikContext, Field, Formik, Form } from 'formik';
11
11
  import 'react/jsx-runtime';
12
12
  import { FlexCenter, QueryLoadingState, RetryOnError, TabContainer, ModalLoadingOverlay } from '@compill/components';
13
+ import { FormProvider, TextArea, FormRenderer, mergeInitialFormValues, FieldLabel, SubmitButton } from '@compill/form';
13
14
  import { createContext as createContext$1, runIfFn, isFunction } from '@soperio/react';
14
15
  import { Editor } from '@compill/editor';
15
- import { PageSectionTitle as PageSectionTitle$1, ButtonBarDialogButton as ButtonBarDialogButton$1, TableRowActionButton as TableRowActionButton$1, DialogButton as DialogButton$1 } from '@compill/admin';
16
16
  import { createPortal } from 'react-dom';
17
17
  import { useRouter } from 'next/router';
18
18
  import { TableContextProvider, useTableContext, Table } from '@compill/table';
@@ -195,6 +195,43 @@ const ButtonBarButton = /*#__PURE__*/React.forwardRef(function (_a, ref) {
195
195
  }), children]
196
196
  }));
197
197
  });
198
+ const ButtonBarSubmitButton = /*#__PURE__*/React.forwardRef(function (_a, ref) {
199
+ var _b;
200
+ var {
201
+ useDirty,
202
+ disabled,
203
+ icon,
204
+ children
205
+ } = _a,
206
+ props = __rest$1(_a, ["useDirty", "disabled", "icon", "children"]);
207
+ const {
208
+ dirty,
209
+ handleSubmit
210
+ } = (_b = useFormikContext()) !== null && _b !== void 0 ? _b : {
211
+ dirty: false,
212
+ handleSubmit: undefined,
213
+ values: {}
214
+ };
215
+ const onSubmit = React.useCallback(() => handleSubmit(), [handleSubmit]);
216
+ return jsxs(Button, Object.assign({
217
+ scheme: "dark",
218
+ size: "sm",
219
+ aspectRatio: icon && !children ? "square" : undefined,
220
+ variant: "borderless",
221
+ dflex: true,
222
+ alignItems: "center",
223
+ placeContent: "center",
224
+ corners: "square",
225
+ gap: "2",
226
+ disabled: useDirty && !dirty || disabled,
227
+ onClick: onSubmit
228
+ }, props, {
229
+ ref: ref,
230
+ children: [icon && jsx(Icon, {
231
+ path: icon
232
+ }), children]
233
+ }));
234
+ });
198
235
  function ButtonBarDialogButton(_a) {
199
236
  var {
200
237
  icon,
@@ -275,20 +312,12 @@ function PublishButton(_a) {
275
312
  mutation.reset();
276
313
  mutation.mutateAsync(queryId).then(() => toast.success(isDraft ? "Published!" : "Unpublished!")).catch(error => toast.error(`Error: ${error}`));
277
314
  }, [mutation, queryId]);
278
- return jsxs(Button, Object.assign({
279
- scheme: "secondary",
280
- variant: "glass",
281
- size: "sm",
282
- px: "3",
315
+ return jsx(ButtonBarButton$1, Object.assign({
283
316
  disabled: mutation.isLoading,
284
317
  onClick: publish,
285
- dflex: true,
286
- alignItems: "center",
287
- gap: "3"
318
+ icon: isDraft ? mdiEye : mdiEyeOff
288
319
  }, props, {
289
- children: [jsx(Icon, {
290
- path: isDraft ? mdiEye : mdiEyeOff
291
- }), isDraft ? "Publish" : "Switch to draft"]
320
+ children: isDraft ? "Publish" : "Switch to draft"
292
321
  }));
293
322
  }
294
323
 
@@ -695,17 +724,10 @@ function UpdateButton(_a) {
695
724
  }, {
696
725
  preventDefault: true
697
726
  }, [dirty, props, handleSubmit]);
698
- return jsxs(SubmitButton, Object.assign({
699
- type: "submit",
700
- size: "sm",
701
- px: "3",
702
- dflex: true,
703
- alignItems: "center",
704
- gap: "3"
727
+ return jsx(ButtonBarSubmitButton$1, Object.assign({
728
+ icon: mdiCloudUpload
705
729
  }, props, {
706
- children: [jsx(Icon, {
707
- path: mdiCloudUpload
708
- }), "Update"]
730
+ children: "Update"
709
731
  }));
710
732
  }
711
733
 
@@ -1109,13 +1131,15 @@ function Buttons$1({
1109
1131
  }), button.type === "invalidate" && jsx(InvalidateButton, {
1110
1132
  pathOrPermalink: button.pathOrPermalink
1111
1133
  }), button.type == "custom" && button.render(item)]
1112
- }, index)), jsx(PublishButton, {
1113
- api: api,
1114
- queryId: item.id,
1115
- status: item.status,
1116
- disabled: isLoading
1117
- }), jsx(UpdateButton, {
1118
- disabled: isLoading
1134
+ }, index)), jsxs(ButtonBar$1, {
1135
+ children: [api instanceof API && jsx(PublishButton, {
1136
+ api: api,
1137
+ queryId: item.id,
1138
+ status: item.status,
1139
+ disabled: isLoading
1140
+ }), jsx(UpdateButton, {
1141
+ disabled: isLoading
1142
+ })]
1119
1143
  })]
1120
1144
  });
1121
1145
  }
@@ -2227,6 +2251,7 @@ function ItemDeleteDialog(_a) {
2227
2251
  itemLabel,
2228
2252
  queryId = "",
2229
2253
  api,
2254
+ apiFn,
2230
2255
  invalidateQueriesOnSuccess = true,
2231
2256
  invalidateQueryKey,
2232
2257
  size = "lg",
@@ -2235,8 +2260,9 @@ function ItemDeleteDialog(_a) {
2235
2260
  show,
2236
2261
  onClose
2237
2262
  } = _a,
2238
- props = __rest$1(_a, ["itemLabel", "queryId", "api", "invalidateQueriesOnSuccess", "invalidateQueryKey", "size", "md_boxSizing", "msg", "show", "onClose"]);
2239
- const mutation = invalidateQueriesOnSuccess ? useInvalidateParentMutation(api.delete, invalidateQueryKey !== null && invalidateQueryKey !== void 0 ? invalidateQueryKey : api.queryKey) : useApiMutation(api.delete, api.queryKey);
2263
+ props = __rest$1(_a, ["itemLabel", "queryId", "api", "apiFn", "invalidateQueriesOnSuccess", "invalidateQueryKey", "size", "md_boxSizing", "msg", "show", "onClose"]);
2264
+ const fn = apiFn ? api[apiFn] : api.delete;
2265
+ const mutation = invalidateQueriesOnSuccess ? useInvalidateParentMutation(fn, invalidateQueryKey !== null && invalidateQueryKey !== void 0 ? invalidateQueryKey : api.queryKey) : useApiMutation(fn, api.queryKey);
2240
2266
  const mutate = useMutate(mutation, {
2241
2267
  onSuccess: () => onClose === null || onClose === void 0 ? void 0 : onClose()
2242
2268
  });
@@ -3636,4 +3662,4 @@ function TableRowPublishPostButton(_a) {
3636
3662
  }, props));
3637
3663
  }
3638
3664
 
3639
- export { AdminLayout, AttachDialog, Breadcrumbs, ButtonBar, ButtonBarButton, ButtonBarDialogButton, DialogButton, FormActionDialog, InvalidateButton, ItemDeleteDialog, ItemEditDialog, Menu, NavigateButton, OrderCell, PageContainer, PageContentEditor, PageMain, PageQueryStateContainer, PageSectionTitle, PageSidebar, PageSidebarSection, PageStateContainer, PageSubSectionTitle, PageTabbedTopBar, PageTabbedTopBarProvider, PageTitle, PageTopBar, PageTopBarToolbar, PublishButton, ScreenRenderer, SectionTitle, StatusBadge, TableContainer, TableCreateButton, TableFilterButton, TableRowActionBar, TableRowActionButton, TableRowActionDialogButton, TableRowDeleteButton, TableRowEditButton, TableRowNavigateButton, TableRowPublishPostButton, TableRowViewButton, TableTopBar, UpdateButton, ViewButton };
3665
+ export { AdminLayout, AttachDialog, Breadcrumbs, ButtonBar, ButtonBarButton, ButtonBarDialogButton, ButtonBarSubmitButton, DialogButton, FormActionDialog, InvalidateButton, ItemDeleteDialog, ItemEditDialog, Menu, NavigateButton, OrderCell, PageContainer, PageContentEditor, PageMain, PageQueryStateContainer, PageSectionTitle, PageSidebar, PageSidebarSection, PageStateContainer, PageSubSectionTitle, PageTabbedTopBar, PageTabbedTopBarProvider, PageTitle, PageTopBar, PageTopBarToolbar, PublishButton, ScreenRenderer, SectionTitle, StatusBadge, TableContainer, TableCreateButton, TableFilterButton, TableRowActionBar, TableRowActionButton, TableRowActionDialogButton, TableRowDeleteButton, TableRowEditButton, TableRowNavigateButton, TableRowPublishPostButton, TableRowViewButton, TableTopBar, UpdateButton, ViewButton };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@compill/admin",
3
- "version": "1.0.73",
3
+ "version": "1.0.75",
4
4
  "module": "./index.esm.js",
5
5
  "main": "./index.cjs.js"
6
6
  }
@@ -2,11 +2,12 @@
2
2
  import { API } from "@compill/admin-api";
3
3
  import { Breadcrumb } from "../breadcrumbs/BreadCrumbs";
4
4
  import { DetailViewButton } from "./types/DetailsView";
5
+ import { CRUDAPI } from "@compill/api";
5
6
  interface ScreenTopBarProps {
6
7
  tabbed?: boolean;
7
8
  breadcrumbs?: Breadcrumb[];
8
9
  buttonBar?: DetailViewButton[];
9
- api: API<any>;
10
+ api: CRUDAPI<any> | API<any>;
10
11
  item: any;
11
12
  isLoading: boolean;
12
13
  trackingRef?: Element | null;
@@ -5,8 +5,9 @@ export interface ItemDeleteDialogProps extends ModalProps {
5
5
  itemLabel: string;
6
6
  queryId: string;
7
7
  api: CRUDAPI<any>;
8
+ apiFn?: string;
8
9
  invalidateQueriesOnSuccess?: boolean;
9
10
  invalidateQueryKey?: string[];
10
11
  msg?: (itemLabel: string) => string | React.ReactNode;
11
12
  }
12
- export declare function ItemDeleteDialog({ itemLabel, queryId, api, invalidateQueriesOnSuccess, invalidateQueryKey, size, md_boxSizing, msg, show, onClose, ...props }: ItemDeleteDialogProps): JSX.Element;
13
+ export declare function ItemDeleteDialog({ itemLabel, queryId, api, apiFn, invalidateQueriesOnSuccess, invalidateQueryKey, size, md_boxSizing, msg, show, onClose, ...props }: ItemDeleteDialogProps): JSX.Element;
@@ -3,9 +3,10 @@ import { API } from "@compill/admin-api";
3
3
  import * as Yup from "yup";
4
4
  import { Breadcrumb } from "../../breadcrumbs/BreadCrumbs";
5
5
  import { FormRendererConfig } from "@compill/form";
6
+ import { CRUDAPI } from "@compill/api";
6
7
  export type DetailsViewConfig<T = any> = {
7
8
  type: "details";
8
- api: API<T>;
9
+ api: CRUDAPI<T> | API<T>;
9
10
  queryField: string;
10
11
  useNextRouter?: boolean;
11
12
  processInput?: (input: T) => any;
@@ -9,6 +9,10 @@ export type ButtonBarButtonProps = {
9
9
  export declare const ButtonBarButton: React.ForwardRefExoticComponent<{
10
10
  icon?: string | undefined;
11
11
  } & ButtonProps & React.RefAttributes<HTMLDivElement>>;
12
+ export interface ButtonBarSubmitButtonProps extends ButtonBarButtonProps {
13
+ useDirty?: boolean;
14
+ }
15
+ export declare const ButtonBarSubmitButton: React.ForwardRefExoticComponent<ButtonBarSubmitButtonProps & React.RefAttributes<HTMLDivElement>>;
12
16
  export type ButtonBarDialogButtonProps = {
13
17
  icon?: string;
14
18
  } & DialogButtonProps;