@compill/admin 1.0.100 → 1.0.102

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.
Files changed (169) hide show
  1. package/dist/index.js +50 -0
  2. package/{src → dist}/lib/SectionTitle.d.ts +0 -1
  3. package/dist/lib/SectionTitle.jsx +3 -0
  4. package/{src → dist}/lib/breadcrumbs/BreadCrumbs.d.ts +0 -1
  5. package/dist/lib/breadcrumbs/BreadCrumbs.jsx +43 -0
  6. package/dist/lib/buttons/DialogButton.jsx +17 -0
  7. package/{src → dist}/lib/buttons/InvalidateButton.d.ts +0 -1
  8. package/dist/lib/buttons/InvalidateButton.jsx +10 -0
  9. package/{src → dist}/lib/buttons/NavigateButton.d.ts +0 -1
  10. package/dist/lib/buttons/NavigateButton.jsx +13 -0
  11. package/{src → dist}/lib/buttons/PublishButton.d.ts +0 -1
  12. package/dist/lib/buttons/PublishButton.jsx +18 -0
  13. package/{src → dist}/lib/buttons/UpdateButton.d.ts +0 -1
  14. package/dist/lib/buttons/UpdateButton.jsx +12 -0
  15. package/{src → dist}/lib/buttons/ViewButton.d.ts +1 -2
  16. package/dist/lib/buttons/ViewButton.jsx +14 -0
  17. package/{src → dist}/lib/cells/OrderCell.d.ts +0 -1
  18. package/dist/lib/cells/OrderCell.jsx +35 -0
  19. package/{src → dist}/lib/json/DetailsView.d.ts +0 -1
  20. package/dist/lib/json/DetailsView.jsx +96 -0
  21. package/{src → dist}/lib/json/EditItemView.d.ts +0 -1
  22. package/dist/lib/json/EditItemView.jsx +5 -0
  23. package/{src → dist}/lib/json/MultiQueryWrapper.d.ts +0 -1
  24. package/dist/lib/json/MultiQueryWrapper.jsx +60 -0
  25. package/{src → dist}/lib/json/QueryWrapper.d.ts +0 -1
  26. package/dist/lib/json/QueryWrapper.jsx +28 -0
  27. package/{src → dist}/lib/json/ScreenRenderer.d.ts +0 -1
  28. package/dist/lib/json/ScreenRenderer.jsx +18 -0
  29. package/{src → dist}/lib/json/ScreenTopBar.d.ts +0 -1
  30. package/dist/lib/json/ScreenTopBar.jsx +39 -0
  31. package/{src → dist}/lib/json/TabbedView.d.ts +0 -1
  32. package/dist/lib/json/TabbedView.jsx +28 -0
  33. package/{src → dist}/lib/json/buttons/ActionButton.d.ts +0 -1
  34. package/dist/lib/json/buttons/ActionButton.jsx +13 -0
  35. package/{src → dist}/lib/json/buttons/ConfirmationActionButton.d.ts +0 -1
  36. package/dist/lib/json/buttons/ConfirmationActionButton.jsx +37 -0
  37. package/{src → dist}/lib/json/dialog/DialogRenderer.d.ts +0 -1
  38. package/dist/lib/json/dialog/DialogRenderer.jsx +13 -0
  39. package/dist/lib/json/dialog/ItemDeleteDialog.jsx +36 -0
  40. package/dist/lib/json/dialog/ItemEditDialog.jsx +124 -0
  41. package/{src → dist}/lib/json/dialog/MultiQueryWrapperDialog.d.ts +0 -1
  42. package/dist/lib/json/dialog/MultiQueryWrapperDialog.jsx +22 -0
  43. package/{src → dist}/lib/json/dialog/QueryWrapperDialog.d.ts +0 -1
  44. package/dist/lib/json/dialog/QueryWrapperDialog.jsx +19 -0
  45. package/{src → dist}/lib/json/table/RefreshButton.d.ts +0 -1
  46. package/dist/lib/json/table/RefreshButton.jsx +12 -0
  47. package/{src → dist}/lib/json/table/TableRowActionsView.d.ts +0 -1
  48. package/dist/lib/json/table/TableRowActionsView.jsx +45 -0
  49. package/{src → dist}/lib/json/table/TableRowPublishPostButton.d.ts +0 -1
  50. package/dist/lib/json/table/TableRowPublishPostButton.jsx +21 -0
  51. package/{src → dist}/lib/json/table/TableView.d.ts +0 -1
  52. package/dist/lib/json/table/TableView.jsx +100 -0
  53. package/dist/lib/json/table/TableViewContext.jsx +57 -0
  54. package/dist/lib/json/table/useTableProps.jsx +56 -0
  55. package/{src → dist}/lib/json/types/DetailsView.d.ts +0 -1
  56. package/dist/lib/json/types/DetailsView.js +1 -0
  57. package/dist/lib/json/types/EditItemDialog.js +1 -0
  58. package/dist/lib/json/types/MultiQueryWrapper.js +1 -0
  59. package/dist/lib/json/types/MultiQueryWrapperDialog.js +1 -0
  60. package/dist/lib/json/types/QueryWrapper.js +1 -0
  61. package/dist/lib/json/types/QueryWrapperDialog.js +1 -0
  62. package/dist/lib/json/types/ScreenConfig.js +1 -0
  63. package/{src → dist}/lib/json/types/TabbedView.d.ts +0 -1
  64. package/dist/lib/json/types/TabbedView.js +1 -0
  65. package/{src → dist}/lib/json/types/TableView.d.ts +0 -1
  66. package/dist/lib/json/types/TableView.js +1 -0
  67. package/{src → dist}/lib/layout/AdminLayout.d.ts +0 -1
  68. package/dist/lib/layout/AdminLayout.jsx +24 -0
  69. package/{src → dist}/lib/layout/ButtonBar.d.ts +1 -1
  70. package/dist/lib/layout/ButtonBar.jsx +29 -0
  71. package/{src → dist}/lib/layout/Content.d.ts +0 -1
  72. package/dist/lib/layout/Content.jsx +10 -0
  73. package/{src → dist}/lib/layout/PageTitleBar.d.ts +0 -1
  74. package/dist/lib/layout/PageTitleBar.jsx +12 -0
  75. package/{src → dist}/lib/layout/Sidebar.d.ts +0 -1
  76. package/dist/lib/layout/Sidebar.jsx +24 -0
  77. package/{src → dist}/lib/layout/menu/Menu.d.ts +0 -1
  78. package/dist/lib/layout/menu/Menu.jsx +30 -0
  79. package/{src → dist}/lib/layout/menu/MenuButton.d.ts +0 -1
  80. package/dist/lib/layout/menu/MenuButton.jsx +7 -0
  81. package/dist/lib/layout/menu/MenuConfig.js +1 -0
  82. package/{src → dist}/lib/layout/menu/MenuItem.d.ts +0 -1
  83. package/dist/lib/layout/menu/MenuItem.jsx +20 -0
  84. package/{src → dist}/lib/layout/menu/NextMenuItem.d.ts +0 -1
  85. package/dist/lib/layout/menu/NextMenuItem.jsx +20 -0
  86. package/{src → dist}/lib/layout/menu/SelectedIndicator.d.ts +0 -1
  87. package/dist/lib/layout/menu/SelectedIndicator.jsx +3 -0
  88. package/{src → dist}/lib/layout/menu/UserBlock.d.ts +1 -2
  89. package/dist/lib/layout/menu/UserBlock.jsx +55 -0
  90. package/{src → dist}/lib/modal/AttachDialog.d.ts +0 -1
  91. package/dist/lib/modal/AttachDialog.jsx +109 -0
  92. package/dist/lib/modal/FormActionDialog.jsx +46 -0
  93. package/{src → dist}/lib/page/PageContainer.d.ts +0 -1
  94. package/dist/lib/page/PageContainer.jsx +4 -0
  95. package/{src → dist}/lib/page/PageContentEditor.d.ts +0 -1
  96. package/dist/lib/page/PageContentEditor.jsx +11 -0
  97. package/{src → dist}/lib/page/PageMain.d.ts +0 -1
  98. package/dist/lib/page/PageMain.jsx +4 -0
  99. package/dist/lib/page/PageQueryStateContainer.jsx +15 -0
  100. package/{src → dist}/lib/page/PageSectionTitle.d.ts +0 -1
  101. package/dist/lib/page/PageSectionTitle.jsx +3 -0
  102. package/{src → dist}/lib/page/PageSidebar.d.ts +0 -1
  103. package/dist/lib/page/PageSidebar.jsx +3 -0
  104. package/{src → dist}/lib/page/PageSidebarSection.d.ts +0 -1
  105. package/dist/lib/page/PageSidebarSection.jsx +7 -0
  106. package/dist/lib/page/PageStateContainer.jsx +9 -0
  107. package/{src → dist}/lib/page/PageSubSectionTitle.d.ts +0 -1
  108. package/dist/lib/page/PageSubSectionTitle.jsx +3 -0
  109. package/{src → dist}/lib/page/PageTitle.d.ts +0 -1
  110. package/dist/lib/page/PageTitle.jsx +3 -0
  111. package/dist/lib/page/PageTopBar.jsx +92 -0
  112. package/{src → dist}/lib/status/StatusBadge.d.ts +0 -1
  113. package/dist/lib/status/StatusBadge.jsx +20 -0
  114. package/dist/lib/table/TableColumnButton.d.ts +1 -0
  115. package/dist/lib/table/TableColumnButton.jsx +53 -0
  116. package/{src → dist}/lib/table/TableContainer.d.ts +0 -1
  117. package/dist/lib/table/TableContainer.jsx +11 -0
  118. package/dist/lib/table/TableContainerContext.jsx +39 -0
  119. package/{src → dist}/lib/table/TableCreateButton.d.ts +0 -1
  120. package/dist/lib/table/TableCreateButton.jsx +9 -0
  121. package/{src → dist}/lib/table/TableFilterButton.d.ts +0 -1
  122. package/dist/lib/table/TableFilterButton.jsx +16 -0
  123. package/{src → dist}/lib/table/TableFilters.d.ts +0 -1
  124. package/dist/lib/table/TableFilters.jsx +46 -0
  125. package/{src → dist}/lib/table/TableMassActions.d.ts +0 -1
  126. package/dist/lib/table/TableMassActions.jsx +15 -0
  127. package/{src → dist}/lib/table/TableRowActionBar.d.ts +0 -1
  128. package/dist/lib/table/TableRowActionBar.jsx +14 -0
  129. package/{src → dist}/lib/table/TableRowActionButton.d.ts +0 -1
  130. package/dist/lib/table/TableRowActionButton.jsx +7 -0
  131. package/{src → dist}/lib/table/TableRowActionDialogButton.d.ts +1 -2
  132. package/dist/lib/table/TableRowActionDialogButton.jsx +8 -0
  133. package/{src → dist}/lib/table/TableRowDeleteButton.d.ts +0 -1
  134. package/dist/lib/table/TableRowDeleteButton.jsx +5 -0
  135. package/{src → dist}/lib/table/TableRowEditButton.d.ts +0 -1
  136. package/dist/lib/table/TableRowEditButton.jsx +7 -0
  137. package/{src → dist}/lib/table/TableRowNavigateButton.d.ts +0 -1
  138. package/dist/lib/table/TableRowNavigateButton.jsx +13 -0
  139. package/{src → dist}/lib/table/TableRowPublishPostButton.d.ts +0 -1
  140. package/dist/lib/table/TableRowPublishPostButton.jsx +18 -0
  141. package/{src → dist}/lib/table/TableRowViewButton.d.ts +0 -1
  142. package/dist/lib/table/TableRowViewButton.jsx +12 -0
  143. package/{src → dist}/lib/table/TableTopBar.d.ts +1 -2
  144. package/dist/lib/table/TableTopBar.jsx +17 -0
  145. package/package.json +60 -4
  146. package/README.md +0 -7
  147. package/index.cjs.d.ts +0 -1
  148. package/index.cjs.js +0 -3710
  149. package/index.esm.d.ts +0 -1
  150. package/index.esm.js +0 -3662
  151. package/src/lib/table/TableColumnButton.d.ts +0 -0
  152. /package/{src → dist}/index.d.ts +0 -0
  153. /package/{src → dist}/lib/buttons/DialogButton.d.ts +0 -0
  154. /package/{src → dist}/lib/json/dialog/ItemDeleteDialog.d.ts +0 -0
  155. /package/{src → dist}/lib/json/dialog/ItemEditDialog.d.ts +0 -0
  156. /package/{src → dist}/lib/json/table/TableViewContext.d.ts +0 -0
  157. /package/{src → dist}/lib/json/table/useTableProps.d.ts +0 -0
  158. /package/{src → dist}/lib/json/types/EditItemDialog.d.ts +0 -0
  159. /package/{src → dist}/lib/json/types/MultiQueryWrapper.d.ts +0 -0
  160. /package/{src → dist}/lib/json/types/MultiQueryWrapperDialog.d.ts +0 -0
  161. /package/{src → dist}/lib/json/types/QueryWrapper.d.ts +0 -0
  162. /package/{src → dist}/lib/json/types/QueryWrapperDialog.d.ts +0 -0
  163. /package/{src → dist}/lib/json/types/ScreenConfig.d.ts +0 -0
  164. /package/{src → dist}/lib/layout/menu/MenuConfig.d.ts +0 -0
  165. /package/{src → dist}/lib/modal/FormActionDialog.d.ts +0 -0
  166. /package/{src → dist}/lib/page/PageQueryStateContainer.d.ts +0 -0
  167. /package/{src → dist}/lib/page/PageStateContainer.d.ts +0 -0
  168. /package/{src → dist}/lib/page/PageTopBar.d.ts +0 -0
  169. /package/{src → dist}/lib/table/TableContainerContext.d.ts +0 -0
package/index.cjs.js DELETED
@@ -1,3710 +0,0 @@
1
- 'use strict';
2
-
3
- var tslib = require('tslib');
4
- var jsxRuntime = require('@soperio/jsx-runtime');
5
- var api = require('@compill/api');
6
- var components = require('@compill/components');
7
- var ui = require('@valerya/ui');
8
- var Link = require('next/link');
9
- var reactRouterDom = require('react-router-dom');
10
- var React = require('react');
11
- var adminApi = require('@compill/admin-api');
12
- var formik = require('formik');
13
- var admin = require('@compill/admin');
14
- var reactToastify = require('react-toastify');
15
- require('react/jsx-runtime');
16
- var form = require('@compill/form');
17
- var react = require('@soperio/react');
18
- var formEditor = require('@compill/form-editor');
19
- var editor = require('@compill/editor');
20
- var reactDom = require('react-dom');
21
- var router = require('next/router');
22
- var table = require('@compill/table');
23
- var hooks = require('@compill/hooks');
24
- var env = require('@compill/env');
25
- var reactQuery = require('@tanstack/react-query');
26
- var Image = require('next/image');
27
- var auth = require('@compill/auth');
28
-
29
- function SectionTitle(_a) {
30
- var {
31
- children
32
- } = _a,
33
- props = tslib.__rest(_a, ["children"]);
34
- return jsxRuntime.jsx("h2", Object.assign({
35
- textSize: "xl",
36
- fontWeight: "600",
37
- textColor: "slate-800"
38
- }, props, {
39
- children: children
40
- }));
41
- }
42
-
43
- // Material Design Icons v7.4.47
44
- var mdiArrowDownBoldBox = "M5,3H19A2,2 0 0,1 21,5V19A2,2 0 0,1 19,21H5A2,2 0 0,1 3,19V5A2,2 0 0,1 5,3M12,17L17,12H14V8H10V12H7L12,17Z";
45
- var mdiArrowLeft = "M20,11V13H8L13.5,18.5L12.08,19.92L4.16,12L12.08,4.08L13.5,5.5L8,11H20Z";
46
- var mdiArrowUpBoldBox = "M19,21H5A2,2 0 0,1 3,19V5A2,2 0 0,1 5,3H19A2,2 0 0,1 21,5V19A2,2 0 0,1 19,21M12,7L7,12H10V16H14V12H17L12,7Z";
47
- var mdiCircleSmall = "M12,10A2,2 0 0,0 10,12C10,13.11 10.9,14 12,14C13.11,14 14,13.11 14,12A2,2 0 0,0 12,10Z";
48
- var mdiCloudUpload = "M11 20H6.5Q4.22 20 2.61 18.43 1 16.85 1 14.58 1 12.63 2.17 11.1 3.35 9.57 5.25 9.15 5.88 6.85 7.75 5.43 9.63 4 12 4 14.93 4 16.96 6.04 19 8.07 19 11 20.73 11.2 21.86 12.5 23 13.78 23 15.5 23 17.38 21.69 18.69 20.38 20 18.5 20H13V12.85L14.6 14.4L16 13L12 9L8 13L9.4 14.4L11 12.85Z";
49
- var mdiCog = "M12,15.5A3.5,3.5 0 0,1 8.5,12A3.5,3.5 0 0,1 12,8.5A3.5,3.5 0 0,1 15.5,12A3.5,3.5 0 0,1 12,15.5M19.43,12.97C19.47,12.65 19.5,12.33 19.5,12C19.5,11.67 19.47,11.34 19.43,11L21.54,9.37C21.73,9.22 21.78,8.95 21.66,8.73L19.66,5.27C19.54,5.05 19.27,4.96 19.05,5.05L16.56,6.05C16.04,5.66 15.5,5.32 14.87,5.07L14.5,2.42C14.46,2.18 14.25,2 14,2H10C9.75,2 9.54,2.18 9.5,2.42L9.13,5.07C8.5,5.32 7.96,5.66 7.44,6.05L4.95,5.05C4.73,4.96 4.46,5.05 4.34,5.27L2.34,8.73C2.21,8.95 2.27,9.22 2.46,9.37L4.57,11C4.53,11.34 4.5,11.67 4.5,12C4.5,12.33 4.53,12.65 4.57,12.97L2.46,14.63C2.27,14.78 2.21,15.05 2.34,15.27L4.34,18.73C4.46,18.95 4.73,19.03 4.95,18.95L7.44,17.94C7.96,18.34 8.5,18.68 9.13,18.93L9.5,21.58C9.54,21.82 9.75,22 10,22H14C14.25,22 14.46,21.82 14.5,21.58L14.87,18.93C15.5,18.67 16.04,18.34 16.56,17.94L19.05,18.95C19.27,19.03 19.54,18.95 19.66,18.73L21.66,15.27C21.78,15.05 21.73,14.78 21.54,14.63L19.43,12.97Z";
50
- var mdiDatabaseRefreshOutline = "M6 12.45V9.64C7.47 10.47 9.61 11 12 11S16.53 10.47 18 9.64V12.03C18.17 12 18.33 12 18.5 12C19 12 19.5 12.07 20 12.18V7C20 4.79 16.42 3 12 3S4 4.79 4 7V17C4 19.21 7.59 21 12 21C12.17 21 12.33 21 12.5 21C12.24 20.37 12.09 19.7 12.03 19L12 19C8.13 19 6 17.5 6 17V14.77C7.61 15.55 9.72 16 12 16C12.17 16 12.34 16 12.5 16C12.85 15.18 13.34 14.46 13.95 13.86C13.32 13.95 12.67 14 12 14C9.58 14 7.3 13.4 6 12.45M12 5C15.87 5 18 6.5 18 7S15.87 9 12 9 6 7.5 6 7 8.13 5 12 5M18 18.5L19.77 16.73C19.32 16.28 18.69 16 18 16C16.62 16 15.5 17.12 15.5 18.5S16.62 21 18 21C18.82 21 19.54 20.61 20 20H21.71C21.12 21.47 19.68 22.5 18 22.5C15.79 22.5 14 20.71 14 18.5S15.79 14.5 18 14.5C19.11 14.5 20.11 14.95 20.83 15.67L22 14.5V18.5H18Z";
51
- var mdiDelete = "M19,4H15.5L14.5,3H9.5L8.5,4H5V6H19M6,19A2,2 0 0,0 8,21H16A2,2 0 0,0 18,19V7H6V19Z";
52
- var mdiDotsVertical = "M12,16A2,2 0 0,1 14,18A2,2 0 0,1 12,20A2,2 0 0,1 10,18A2,2 0 0,1 12,16M12,10A2,2 0 0,1 14,12A2,2 0 0,1 12,14A2,2 0 0,1 10,12A2,2 0 0,1 12,10M12,4A2,2 0 0,1 14,6A2,2 0 0,1 12,8A2,2 0 0,1 10,6A2,2 0 0,1 12,4Z";
53
- var mdiEye = "M12,9A3,3 0 0,0 9,12A3,3 0 0,0 12,15A3,3 0 0,0 15,12A3,3 0 0,0 12,9M12,17A5,5 0 0,1 7,12A5,5 0 0,1 12,7A5,5 0 0,1 17,12A5,5 0 0,1 12,17M12,4.5C7,4.5 2.73,7.61 1,12C2.73,16.39 7,19.5 12,19.5C17,19.5 21.27,16.39 23,12C21.27,7.61 17,4.5 12,4.5Z";
54
- var mdiEyeOff = "M11.83,9L15,12.16C15,12.11 15,12.05 15,12A3,3 0 0,0 12,9C11.94,9 11.89,9 11.83,9M7.53,9.8L9.08,11.35C9.03,11.56 9,11.77 9,12A3,3 0 0,0 12,15C12.22,15 12.44,14.97 12.65,14.92L14.2,16.47C13.53,16.8 12.79,17 12,17A5,5 0 0,1 7,12C7,11.21 7.2,10.47 7.53,9.8M2,4.27L4.28,6.55L4.73,7C3.08,8.3 1.78,10 1,12C2.73,16.39 7,19.5 12,19.5C13.55,19.5 15.03,19.2 16.38,18.66L16.81,19.08L19.73,22L21,20.73L3.27,3M12,7A5,5 0 0,1 17,12C17,12.64 16.87,13.26 16.64,13.82L19.57,16.75C21.07,15.5 22.27,13.86 23,12C21.27,7.61 17,4.5 12,4.5C10.6,4.5 9.26,4.75 8,5.2L10.17,7.35C10.74,7.13 11.35,7 12,7Z";
55
- var mdiFilter = "M14,12V19.88C14.04,20.18 13.94,20.5 13.71,20.71C13.32,21.1 12.69,21.1 12.3,20.71L10.29,18.7C10.06,18.47 9.96,18.16 10,17.87V12H9.97L4.21,4.62C3.87,4.19 3.95,3.56 4.38,3.22C4.57,3.08 4.78,3 5,3V3H19V3C19.22,3 19.43,3.08 19.62,3.22C20.05,3.56 20.13,4.19 19.79,4.62L14.03,12H14Z";
56
- var mdiLogout = "M17 7L15.59 8.41L18.17 11H8V13H18.17L15.59 15.58L17 17L22 12M4 5H12V3H4C2.9 3 2 3.9 2 5V19C2 20.1 2.9 21 4 21H12V19H4V5Z";
57
- var mdiOpenInNew = "M14,3V5H17.59L7.76,14.83L9.17,16.24L19,6.41V10H21V3M19,19H5V5H12V3H5C3.89,3 3,3.9 3,5V19A2,2 0 0,0 5,21H19A2,2 0 0,0 21,19V12H19V19Z";
58
- var mdiPencil = "M20.71,7.04C21.1,6.65 21.1,6 20.71,5.63L18.37,3.29C18,2.9 17.35,2.9 16.96,3.29L15.12,5.12L18.87,8.87M3,17.25V21H6.75L17.81,9.93L14.06,6.18L3,17.25Z";
59
- var mdiPlusThick = "M20 14H14V20H10V14H4V10H10V4H14V10H20V14Z";
60
- var mdiPost = "M3 3V21H21V3H3M18 18H6V17H18V18M18 16H6V15H18V16M18 12H6V6H18V12Z";
61
- var mdiPublish = "M5,4V6H19V4H5M5,14H9V20H15V14H19L12,7L5,14Z";
62
- var mdiPublishOff = "M20.8 22.7L15 16.9V20H9V14H5L8.6 10.4L1.1 3L2.4 1.7L22.1 21.4L20.8 22.7M19 6V4H7.2L9.2 6H19M17.2 14H19L12 7L11.1 7.9L17.2 14Z";
63
- var mdiRefresh = "M17.65,6.35C16.2,4.9 14.21,4 12,4A8,8 0 0,0 4,12A8,8 0 0,0 12,20C15.73,20 18.84,17.45 19.73,14H17.65C16.83,16.33 14.61,18 12,18A6,6 0 0,1 6,12A6,6 0 0,1 12,6C13.66,6 15.14,6.69 16.22,7.78L13,11H20V4L17.65,6.35Z";
64
-
65
- function eq(value, other) {
66
- return value === other || (Number.isNaN(value) && Number.isNaN(other));
67
- }
68
-
69
- function getSymbols(object) {
70
- return Object.getOwnPropertySymbols(object).filter(symbol => Object.prototype.propertyIsEnumerable.call(object, symbol));
71
- }
72
-
73
- function getTag(value) {
74
- if (value == null) {
75
- return value === undefined ? '[object Undefined]' : '[object Null]';
76
- }
77
- return Object.prototype.toString.call(value);
78
- }
79
-
80
- const regexpTag = '[object RegExp]';
81
- const stringTag = '[object String]';
82
- const numberTag = '[object Number]';
83
- const booleanTag = '[object Boolean]';
84
- const argumentsTag = '[object Arguments]';
85
- const symbolTag = '[object Symbol]';
86
- const dateTag = '[object Date]';
87
- const mapTag = '[object Map]';
88
- const setTag = '[object Set]';
89
- const arrayTag = '[object Array]';
90
- const functionTag = '[object Function]';
91
- const arrayBufferTag = '[object ArrayBuffer]';
92
- const objectTag = '[object Object]';
93
- const errorTag = '[object Error]';
94
- const dataViewTag = '[object DataView]';
95
- const uint8ArrayTag = '[object Uint8Array]';
96
- const uint8ClampedArrayTag = '[object Uint8ClampedArray]';
97
- const uint16ArrayTag = '[object Uint16Array]';
98
- const uint32ArrayTag = '[object Uint32Array]';
99
- const bigUint64ArrayTag = '[object BigUint64Array]';
100
- const int8ArrayTag = '[object Int8Array]';
101
- const int16ArrayTag = '[object Int16Array]';
102
- const int32ArrayTag = '[object Int32Array]';
103
- const bigInt64ArrayTag = '[object BigInt64Array]';
104
- const float32ArrayTag = '[object Float32Array]';
105
- const float64ArrayTag = '[object Float64Array]';
106
-
107
- function isArray(value) {
108
- return Array.isArray(value);
109
- }
110
-
111
- function isPlainObject(value) {
112
- if (!value || typeof value !== 'object') {
113
- return false;
114
- }
115
- const proto = Object.getPrototypeOf(value);
116
- const hasObjectPrototype = proto === null ||
117
- proto === Object.prototype ||
118
- Object.getPrototypeOf(proto) === null;
119
- if (!hasObjectPrototype) {
120
- return false;
121
- }
122
- return Object.prototype.toString.call(value) === '[object Object]';
123
- }
124
-
125
- function isEqualWith(a, b, areValuesEqual) {
126
- return isEqualWithImpl(a, b, undefined, undefined, undefined, undefined, areValuesEqual);
127
- }
128
- function isEqualWithImpl(a, b, property, aParent, bParent, stack, areValuesEqual) {
129
- const result = areValuesEqual(a, b, property, aParent, bParent, stack);
130
- if (result !== undefined) {
131
- return result;
132
- }
133
- if (typeof a === typeof b) {
134
- switch (typeof a) {
135
- case 'bigint':
136
- case 'string':
137
- case 'boolean':
138
- case 'symbol':
139
- case 'undefined': {
140
- return a === b;
141
- }
142
- case 'number': {
143
- return a === b || Object.is(a, b);
144
- }
145
- case 'function': {
146
- return a === b;
147
- }
148
- case 'object': {
149
- return areObjectsEqual(a, b, stack, areValuesEqual);
150
- }
151
- }
152
- }
153
- return areObjectsEqual(a, b, stack, areValuesEqual);
154
- }
155
- function areObjectsEqual(a, b, stack, areValuesEqual) {
156
- if (Object.is(a, b)) {
157
- return true;
158
- }
159
- let aTag = getTag(a);
160
- let bTag = getTag(b);
161
- if (aTag === argumentsTag) {
162
- aTag = objectTag;
163
- }
164
- if (bTag === argumentsTag) {
165
- bTag = objectTag;
166
- }
167
- if (aTag !== bTag) {
168
- return false;
169
- }
170
- switch (aTag) {
171
- case stringTag:
172
- return a.toString() === b.toString();
173
- case numberTag: {
174
- const x = a.valueOf();
175
- const y = b.valueOf();
176
- return eq(x, y);
177
- }
178
- case booleanTag:
179
- case dateTag:
180
- case symbolTag:
181
- return Object.is(a.valueOf(), b.valueOf());
182
- case regexpTag: {
183
- return a.source === b.source && a.flags === b.flags;
184
- }
185
- case functionTag: {
186
- return a === b;
187
- }
188
- }
189
- stack = stack ?? new Map();
190
- const aStack = stack.get(a);
191
- const bStack = stack.get(b);
192
- if (aStack != null && bStack != null) {
193
- return aStack === b;
194
- }
195
- stack.set(a, b);
196
- stack.set(b, a);
197
- try {
198
- switch (aTag) {
199
- case mapTag: {
200
- if (a.size !== b.size) {
201
- return false;
202
- }
203
- for (const [key, value] of a.entries()) {
204
- if (!b.has(key) || !isEqualWithImpl(value, b.get(key), key, a, b, stack, areValuesEqual)) {
205
- return false;
206
- }
207
- }
208
- return true;
209
- }
210
- case setTag: {
211
- if (a.size !== b.size) {
212
- return false;
213
- }
214
- const aValues = Array.from(a.values());
215
- const bValues = Array.from(b.values());
216
- for (let i = 0; i < aValues.length; i++) {
217
- const aValue = aValues[i];
218
- const index = bValues.findIndex(bValue => {
219
- return isEqualWithImpl(aValue, bValue, undefined, a, b, stack, areValuesEqual);
220
- });
221
- if (index === -1) {
222
- return false;
223
- }
224
- bValues.splice(index, 1);
225
- }
226
- return true;
227
- }
228
- case arrayTag:
229
- case uint8ArrayTag:
230
- case uint8ClampedArrayTag:
231
- case uint16ArrayTag:
232
- case uint32ArrayTag:
233
- case bigUint64ArrayTag:
234
- case int8ArrayTag:
235
- case int16ArrayTag:
236
- case int32ArrayTag:
237
- case bigInt64ArrayTag:
238
- case float32ArrayTag:
239
- case float64ArrayTag: {
240
- if (typeof Buffer !== 'undefined' && Buffer.isBuffer(a) !== Buffer.isBuffer(b)) {
241
- return false;
242
- }
243
- if (a.length !== b.length) {
244
- return false;
245
- }
246
- for (let i = 0; i < a.length; i++) {
247
- if (!isEqualWithImpl(a[i], b[i], i, a, b, stack, areValuesEqual)) {
248
- return false;
249
- }
250
- }
251
- return true;
252
- }
253
- case arrayBufferTag: {
254
- if (a.byteLength !== b.byteLength) {
255
- return false;
256
- }
257
- return areObjectsEqual(new Uint8Array(a), new Uint8Array(b), stack, areValuesEqual);
258
- }
259
- case dataViewTag: {
260
- if (a.byteLength !== b.byteLength || a.byteOffset !== b.byteOffset) {
261
- return false;
262
- }
263
- return areObjectsEqual(new Uint8Array(a), new Uint8Array(b), stack, areValuesEqual);
264
- }
265
- case errorTag: {
266
- return a.name === b.name && a.message === b.message;
267
- }
268
- case objectTag: {
269
- const areEqualInstances = areObjectsEqual(a.constructor, b.constructor, stack, areValuesEqual) ||
270
- (isPlainObject(a) && isPlainObject(b));
271
- if (!areEqualInstances) {
272
- return false;
273
- }
274
- const aKeys = [...Object.keys(a), ...getSymbols(a)];
275
- const bKeys = [...Object.keys(b), ...getSymbols(b)];
276
- if (aKeys.length !== bKeys.length) {
277
- return false;
278
- }
279
- for (let i = 0; i < aKeys.length; i++) {
280
- const propKey = aKeys[i];
281
- const aProp = a[propKey];
282
- if (!Object.hasOwn(b, propKey)) {
283
- return false;
284
- }
285
- const bProp = b[propKey];
286
- if (!isEqualWithImpl(aProp, bProp, propKey, a, b, stack, areValuesEqual)) {
287
- return false;
288
- }
289
- }
290
- return true;
291
- }
292
- default: {
293
- return false;
294
- }
295
- }
296
- }
297
- finally {
298
- stack.delete(a);
299
- stack.delete(b);
300
- }
301
- }
302
-
303
- function noop() { }
304
-
305
- function isEqual(a, b) {
306
- return isEqualWith(a, b, noop);
307
- }
308
-
309
- function capitalize(str) {
310
- return (str.charAt(0).toUpperCase() + str.slice(1).toLowerCase());
311
- }
312
-
313
- function Breadcrumbs(_a) {
314
- var {
315
- breadcrumbs
316
- } = _a,
317
- props = tslib.__rest(_a, ["breadcrumbs"]);
318
- if (isArray(breadcrumbs)) {
319
- return jsxRuntime.jsx("div", Object.assign({
320
- dflex: true,
321
- alignItems: "center",
322
- trait: "typo.h5"
323
- }, props, {
324
- children: breadcrumbs.map((b, index) => jsxRuntime.jsx(BreadcrumbItem, {
325
- breadcrumb: b,
326
- showSeparator: index > 0
327
- }, index))
328
- }));
329
- }
330
- return jsxRuntime.jsx(QueryBreadcrumbs, {
331
- queryFn: breadcrumbs.queryFn,
332
- queryField: breadcrumbs.queryField,
333
- generate: breadcrumbs.generate
334
- });
335
- }
336
- function QueryBreadcrumbs(_a) {
337
- var {
338
- queryFn,
339
- queryField,
340
- generate
341
- } = _a,
342
- props = tslib.__rest(_a, ["queryFn", "queryField", "generate"]);
343
- const params = reactRouterDom.useParams();
344
- const id = queryField ? params[queryField] : undefined;
345
- const {
346
- data,
347
- isLoading,
348
- isError
349
- } = api.useApiQuery([""], queryFn, id);
350
- if (isLoading || isError) {
351
- return jsxRuntime.jsxs("div", {
352
- dflex: true,
353
- alignItems: "center",
354
- children: [jsxRuntime.jsx(components.Shimmer, {
355
- h: "8",
356
- w: "24"
357
- }), jsxRuntime.jsx(ui.Icon, {
358
- path: mdiCircleSmall,
359
- mx: "1"
360
- }), jsxRuntime.jsx(components.Shimmer, {
361
- h: "8",
362
- w: "20"
363
- })]
364
- });
365
- }
366
- const breadcrumbs = generate(data);
367
- return jsxRuntime.jsx("div", Object.assign({
368
- dflex: true,
369
- alignItems: "center",
370
- trait: "typo.h5"
371
- }, props, {
372
- children: breadcrumbs.map((b, index) => jsxRuntime.jsx(BreadcrumbItem, {
373
- breadcrumb: b,
374
- showSeparator: index > 0
375
- }, index))
376
- }));
377
- }
378
- function BreadcrumbItem({
379
- breadcrumb,
380
- showSeparator
381
- }) {
382
- return jsxRuntime.jsxs(jsxRuntime.Fragment, {
383
- children: [showSeparator && jsxRuntime.jsx(ui.Icon, {
384
- path: mdiCircleSmall,
385
- mx: "1"
386
- }), jsxRuntime.jsx(Link, {
387
- href: `/${breadcrumb.path || "#"}`,
388
- children: jsxRuntime.jsx("span", {
389
- // onClick={breadcrumb.path ? handleClick : undefined}
390
- hover_textDecoration: breadcrumb.path ? "underline" : undefined,
391
- cursor: breadcrumb.path ? "pointer" : undefined,
392
- children: breadcrumb.label
393
- })
394
- })]
395
- });
396
- }
397
-
398
- function DialogButton(_a) {
399
- var {
400
- buildDialog
401
- } = _a,
402
- props = tslib.__rest(_a, ["buildDialog"]);
403
- const [showDialog, setShowDialog] = React.useState(false);
404
- const onShowDialog = React.useCallback(event => {
405
- event === null || event === void 0 ? void 0 : event.preventDefault();
406
- event === null || event === void 0 ? void 0 : event.stopPropagation();
407
- setShowDialog(true);
408
- }, [setShowDialog]);
409
- const onCloseDialog = React.useCallback(() => {
410
- setShowDialog(false);
411
- }, [setShowDialog]);
412
- return jsxRuntime.jsxs(jsxRuntime.Fragment, {
413
- children: [jsxRuntime.jsx(ui.Button, Object.assign({
414
- onClick: onShowDialog
415
- }, props)), showDialog && buildDialog(onCloseDialog)]
416
- });
417
- }
418
-
419
- function ButtonBar(_a) {
420
- var {
421
- children
422
- } = _a,
423
- props = tslib.__rest(_a, ["children"]);
424
- return jsxRuntime.jsx("div", Object.assign({
425
- dflex: true,
426
- border: "1px",
427
- borderColor: "zinc-200",
428
- divideX: "1px",
429
- divideColor: "zinc-200",
430
- rounded: "lg",
431
- overflow: "hidden"
432
- }, props, {
433
- children: children
434
- }));
435
- }
436
- const ButtonBarButton = /*#__PURE__*/React.forwardRef(function (_a, ref) {
437
- var {
438
- icon,
439
- children
440
- } = _a,
441
- props = tslib.__rest(_a, ["icon", "children"]);
442
- return jsxRuntime.jsxs(ui.Button, Object.assign({
443
- scheme: "dark",
444
- size: "sm",
445
- aspectRatio: icon && !children ? "square" : undefined,
446
- variant: "borderless",
447
- dflex: true,
448
- alignItems: "center",
449
- placeContent: "center",
450
- corners: "square",
451
- gap: "2"
452
- }, props, {
453
- ref: ref,
454
- children: [icon && jsxRuntime.jsx(ui.Icon, {
455
- path: icon
456
- }), children]
457
- }));
458
- });
459
- const ButtonBarSubmitButton = /*#__PURE__*/React.forwardRef(function (_a, ref) {
460
- var _b;
461
- var {
462
- useDirty,
463
- disabled,
464
- icon,
465
- children
466
- } = _a,
467
- props = tslib.__rest(_a, ["useDirty", "disabled", "icon", "children"]);
468
- const {
469
- dirty,
470
- handleSubmit
471
- } = (_b = formik.useFormikContext()) !== null && _b !== void 0 ? _b : {
472
- dirty: false,
473
- handleSubmit: undefined};
474
- const onSubmit = React.useCallback(() => handleSubmit(), [handleSubmit]);
475
- return jsxRuntime.jsxs(ui.Button, Object.assign({
476
- scheme: "dark",
477
- size: "sm",
478
- aspectRatio: icon && !children ? "square" : undefined,
479
- variant: "borderless",
480
- dflex: true,
481
- alignItems: "center",
482
- placeContent: "center",
483
- corners: "square",
484
- gap: "2",
485
- disabled: useDirty && !dirty || disabled,
486
- onClick: onSubmit
487
- }, props, {
488
- ref: ref,
489
- children: [icon && jsxRuntime.jsx(ui.Icon, {
490
- path: icon
491
- }), children]
492
- }));
493
- });
494
- function ButtonBarDialogButton(_a) {
495
- var {
496
- icon,
497
- children
498
- } = _a,
499
- props = tslib.__rest(_a, ["icon", "children"]);
500
- return jsxRuntime.jsxs(DialogButton, Object.assign({
501
- scheme: "dark",
502
- size: "sm",
503
- aspectRatio: icon && !children ? "square" : undefined,
504
- variant: "borderless",
505
- dflex: true,
506
- alignItems: "center",
507
- placeContent: "center",
508
- corners: "square",
509
- gap: "2"
510
- }, props, {
511
- children: [icon && jsxRuntime.jsx(ui.Icon, {
512
- path: icon
513
- }), children]
514
- }));
515
- }
516
-
517
- function InvalidateButton(_a) {
518
- var {
519
- pathOrPermalink
520
- } = _a,
521
- props = tslib.__rest(_a, ["pathOrPermalink"]);
522
- const api$1 = adminApi.INVALIDATE_API.new(pathOrPermalink);
523
- const mutation = api.useApiMutation(api$1.invalidate, api$1.queryKey);
524
- const invalidate = api.useMutate(mutation, {
525
- successMsg: "Page successfully invalidated"
526
- });
527
- return jsxRuntime.jsx(ButtonBarButton, Object.assign({
528
- title: "Regenerate",
529
- disabled: mutation.isLoading,
530
- onClick: invalidate,
531
- icon: mdiDatabaseRefreshOutline
532
- }, props));
533
- }
534
-
535
- function NavigateButton(_a) {
536
- var {
537
- path
538
- } = _a,
539
- props = tslib.__rest(_a, ["path"]);
540
- const navigate = reactRouterDom.useNavigate();
541
- const handleClick = React.useCallback(() => {
542
- navigate(path);
543
- }, [navigate, path]);
544
- return jsxRuntime.jsx(ui.Button, Object.assign({
545
- type: "submit",
546
- scheme: "dark",
547
- variant: "glass",
548
- corners: "pill",
549
- w: "10",
550
- h: "10",
551
- onClick: handleClick
552
- }, props, {
553
- children: jsxRuntime.jsx(ui.Icon, {
554
- path: mdiPost
555
- })
556
- }));
557
- }
558
-
559
- function PublishButton(_a) {
560
- var {
561
- status,
562
- queryId,
563
- api: api$1
564
- } = _a,
565
- props = tslib.__rest(_a, ["status", "queryId", "api"]);
566
- const isDraft = status == "draft";
567
- const mutation = api.useInvalidateMutation(isDraft ? api$1.publish : api$1.unpublish, api$1.queryKey, queryId, {
568
- networkMode: "always"
569
- });
570
- const publish = React.useCallback(() => {
571
- mutation.reset();
572
- mutation.mutateAsync(queryId).then(() => reactToastify.toast.success(isDraft ? "Published!" : "Unpublished!")).catch(error => reactToastify.toast.error(`Error: ${error}`));
573
- }, [mutation, queryId]);
574
- return jsxRuntime.jsx(admin.ButtonBarButton, Object.assign({
575
- disabled: mutation.isLoading,
576
- onClick: publish,
577
- icon: isDraft ? mdiEye : mdiEyeOff
578
- }, props, {
579
- children: isDraft ? "Publish" : "Switch to draft"
580
- }));
581
- }
582
-
583
- const j = ["shift", "alt", "meta", "mod", "ctrl", "control"], Q = {
584
- esc: "escape",
585
- return: "enter",
586
- left: "arrowleft",
587
- right: "arrowright",
588
- up: "arrowup",
589
- down: "arrowdown",
590
- ShiftLeft: "shift",
591
- ShiftRight: "shift",
592
- AltLeft: "alt",
593
- AltRight: "alt",
594
- MetaLeft: "meta",
595
- MetaRight: "meta",
596
- OSLeft: "meta",
597
- OSRight: "meta",
598
- ControlLeft: "ctrl",
599
- ControlRight: "ctrl"
600
- };
601
- function K(e) {
602
- return (Q[e.trim()] || e.trim()).toLowerCase().replace(/key|digit|numpad/, "");
603
- }
604
- function D(e) {
605
- return j.includes(e);
606
- }
607
- function H(e, r = ",") {
608
- return e.toLowerCase().split(r);
609
- }
610
- function P(e, r = "+", o = ">", i = false, u) {
611
- let n = [], c = false;
612
- e = e.trim(), e.includes(o) ? (c = true, n = e.toLocaleLowerCase().split(o).map((f) => K(f))) : n = e.toLocaleLowerCase().split(r).map((f) => K(f));
613
- const y = {
614
- alt: n.includes("alt"),
615
- ctrl: n.includes("ctrl") || n.includes("control"),
616
- shift: n.includes("shift"),
617
- meta: n.includes("meta"),
618
- mod: n.includes("mod"),
619
- useKey: i
620
- }, d = n.filter((f) => !j.includes(f));
621
- return {
622
- ...y,
623
- keys: d,
624
- description: u,
625
- isSequence: c,
626
- hotkey: e
627
- };
628
- }
629
- typeof document < "u" && (document.addEventListener("keydown", (e) => {
630
- e.code !== void 0 && I([K(e.code)]);
631
- }), document.addEventListener("keyup", (e) => {
632
- e.code !== void 0 && _([K(e.code)]);
633
- })), typeof window < "u" && (window.addEventListener("blur", () => {
634
- L.clear();
635
- }), window.addEventListener("contextmenu", () => {
636
- setTimeout(() => {
637
- L.clear();
638
- }, 0);
639
- }));
640
- const L = /* @__PURE__ */ new Set();
641
- function R(e) {
642
- return Array.isArray(e);
643
- }
644
- function U(e, r = ",") {
645
- return (R(e) ? e : e.split(r)).every((i) => L.has(i.trim().toLowerCase()));
646
- }
647
- function I(e) {
648
- const r = Array.isArray(e) ? e : [e];
649
- L.has("meta") && L.forEach((o) => !D(o) && L.delete(o.toLowerCase())), r.forEach((o) => L.add(o.toLowerCase()));
650
- }
651
- function _(e) {
652
- const r = Array.isArray(e) ? e : [e];
653
- e === "meta" ? L.clear() : r.forEach((o) => L.delete(o.toLowerCase()));
654
- }
655
- function V(e, r, o) {
656
- (typeof o == "function" && o(e, r) || o === true) && e.preventDefault();
657
- }
658
- function X(e, r, o) {
659
- return typeof o == "function" ? o(e, r) : o === true || o === void 0;
660
- }
661
- const Y = [
662
- "input",
663
- "textarea",
664
- "select",
665
- "searchbox",
666
- "slider",
667
- "spinbutton",
668
- "menuitem",
669
- "menuitemcheckbox",
670
- "menuitemradio",
671
- "option",
672
- "radio",
673
- "textbox"
674
- ];
675
- function Z(e) {
676
- return F(e, Y);
677
- }
678
- function F(e, r = false) {
679
- const { target: o, composed: i } = e;
680
- let u, n;
681
- return ee(o) && i ? (u = e.composedPath()[0] && e.composedPath()[0].tagName, n = e.composedPath()[0] && e.composedPath()[0].role) : (u = o && o.tagName, n = o && o.role), R(r) ? !!(u && r && r.some((c) => c.toLowerCase() === u.toLowerCase() || c === n)) : !!(u && r && r);
682
- }
683
- function ee(e) {
684
- return !!e.tagName && !e.tagName.startsWith("-") && e.tagName.includes("-");
685
- }
686
- function te(e, r) {
687
- return e.length === 0 && r ? (console.warn(
688
- 'A hotkey has the "scopes" option set, however no active scopes were found. If you want to use the global scopes feature, you need to wrap your app in a <HotkeysProvider>'
689
- ), true) : r ? e.some((o) => r.includes(o)) || e.includes("*") : true;
690
- }
691
- const re = (e, r, o = false) => {
692
- const { alt: i, meta: u, mod: n, shift: c, ctrl: y, keys: d, useKey: f } = r, { code: p, key: t, ctrlKey: a, metaKey: l, shiftKey: g, altKey: k } = e, m = K(p);
693
- if (f && d?.length === 1 && d.includes(t))
694
- return true;
695
- if (!d?.includes(m) && !["ctrl", "control", "unknown", "meta", "alt", "shift", "os"].includes(m))
696
- return false;
697
- if (!o) {
698
- if (i !== k && m !== "alt" || c !== g && m !== "shift")
699
- return false;
700
- if (n) {
701
- if (!l && !a)
702
- return false;
703
- } else if (u !== l && m !== "meta" && m !== "os" || y !== a && m !== "ctrl" && m !== "control")
704
- return false;
705
- }
706
- return d && d.length === 1 && d.includes(m) ? true : d ? U(d) : !d;
707
- }, $ = React.createContext(void 0), oe = () => React.useContext($);
708
- function x(e, r) {
709
- return e && r && typeof e == "object" && typeof r == "object" ? Object.keys(e).length === Object.keys(r).length && // @ts-expect-error TS7053
710
- Object.keys(e).reduce((o, i) => o && x(e[i], r[i]), true) : e === r;
711
- }
712
- const W = React.createContext({
713
- hotkeys: [],
714
- activeScopes: [],
715
- // This array has to be empty instead of containing '*' as default, to check if the provider is set or not
716
- toggleScope: () => {
717
- },
718
- enableScope: () => {
719
- },
720
- disableScope: () => {
721
- }
722
- }), se = () => React.useContext(W);
723
- function ie(e) {
724
- const r = React.useRef(void 0);
725
- return x(r.current, e) || (r.current = e), r.current;
726
- }
727
- const N = (e) => {
728
- e.stopPropagation(), e.preventDefault(), e.stopImmediatePropagation();
729
- }, ue = typeof window < "u" ? React.useLayoutEffect : React.useEffect;
730
- function fe(e, r, o, i) {
731
- const u = React.useRef(null), n = React.useRef(false), c = Array.isArray(o) ? Array.isArray(i) ? void 0 : i : o, y = R(e) ? e.join(c?.delimiter) : e, d = Array.isArray(o) ? o : Array.isArray(i) ? i : void 0, f = React.useCallback(r, d ?? []), p = React.useRef(f);
732
- d ? p.current = f : p.current = r;
733
- const t = ie(c), { activeScopes: a } = se(), l = oe();
734
- return ue(() => {
735
- if (t?.enabled === false || !te(a, t?.scopes))
736
- return;
737
- let g = [], k;
738
- const m = (s, B = false) => {
739
- if (!(Z(s) && !F(s, t?.enableOnFormTags))) {
740
- if (u.current !== null) {
741
- const v = u.current.getRootNode();
742
- if ((v instanceof Document || v instanceof ShadowRoot) && v.activeElement !== u.current && !u.current.contains(v.activeElement)) {
743
- N(s);
744
- return;
745
- }
746
- }
747
- s.target?.isContentEditable && !t?.enableOnContentEditable || H(y, t?.delimiter).forEach((v) => {
748
- if (v.includes(t?.splitKey ?? "+") && v.includes(t?.sequenceSplitKey ?? ">")) {
749
- console.warn(
750
- `Hotkey ${v} contains both ${t?.splitKey ?? "+"} and ${t?.sequenceSplitKey ?? ">"} which is not supported.`
751
- );
752
- return;
753
- }
754
- const h = P(
755
- v,
756
- t?.splitKey,
757
- t?.sequenceSplitKey,
758
- t?.useKey,
759
- t?.description
760
- );
761
- if (h.isSequence) {
762
- k = setTimeout(() => {
763
- g = [];
764
- }, t?.sequenceTimeoutMs ?? 1e3);
765
- const C = h.useKey ? s.key : K(s.code);
766
- if (D(C.toLowerCase()))
767
- return;
768
- g.push(C);
769
- const G = h.keys?.[g.length - 1];
770
- if (C !== G) {
771
- g = [], k && clearTimeout(k);
772
- return;
773
- }
774
- g.length === h.keys?.length && (p.current(s, h), k && clearTimeout(k), g = []);
775
- } else if (re(s, h, t?.ignoreModifiers) || h.keys?.includes("*")) {
776
- if (t?.ignoreEventWhen?.(s) || B && n.current)
777
- return;
778
- if (V(s, h, t?.preventDefault), !X(s, h, t?.enabled)) {
779
- N(s);
780
- return;
781
- }
782
- p.current(s, h), B || (n.current = true);
783
- }
784
- });
785
- }
786
- }, O = (s) => {
787
- s.code !== void 0 && (I(K(s.code)), (t?.keydown === void 0 && t?.keyup !== true || t?.keydown) && m(s));
788
- }, q = (s) => {
789
- s.code !== void 0 && (_(K(s.code)), n.current = false, t?.keyup && m(s, true));
790
- }, E = u.current || c?.document || document;
791
- return E.addEventListener("keyup", q, c?.eventListenerOptions), E.addEventListener("keydown", O, c?.eventListenerOptions), l && H(y, t?.delimiter).forEach(
792
- (s) => l.addHotkey(
793
- P(
794
- s,
795
- t?.splitKey,
796
- t?.sequenceSplitKey,
797
- t?.useKey,
798
- t?.description
799
- )
800
- )
801
- ), () => {
802
- E.removeEventListener("keyup", q, c?.eventListenerOptions), E.removeEventListener("keydown", O, c?.eventListenerOptions), l && H(y, t?.delimiter).forEach(
803
- (s) => l.removeHotkey(
804
- P(
805
- s,
806
- t?.splitKey,
807
- t?.sequenceSplitKey,
808
- t?.useKey,
809
- t?.description
810
- )
811
- )
812
- ), g = [], k && clearTimeout(k);
813
- };
814
- }, [y, t, a]), u;
815
- }
816
-
817
- function UpdateButton(_a) {
818
- var _b;
819
- var props = tslib.__rest(_a, []);
820
- const {
821
- dirty,
822
- handleSubmit
823
- } = (_b = formik.useFormikContext()) !== null && _b !== void 0 ? _b : {
824
- dirty: false,
825
- handleSubmit: undefined};
826
- fe('ctrl+s', () => {
827
- if (dirty && !props.disabled) handleSubmit();
828
- }, {
829
- preventDefault: true
830
- }, [dirty, props, handleSubmit]);
831
- return jsxRuntime.jsx(admin.ButtonBarSubmitButton, Object.assign({
832
- icon: mdiCloudUpload
833
- }, props, {
834
- children: "Update"
835
- }));
836
- }
837
-
838
- function ViewButton(_a) {
839
- var {
840
- label,
841
- path,
842
- icon
843
- } = _a,
844
- props = tslib.__rest(_a, ["label", "path", "icon"]);
845
- const openPage = React.useCallback(() => {
846
- window.open(path, '_blank');
847
- }, [path]);
848
- return jsxRuntime.jsx(admin.ButtonBarButton, Object.assign({
849
- onClick: openPage,
850
- dflex: true,
851
- alignItems: "center",
852
- gap: "2",
853
- icon: icon || mdiOpenInNew
854
- }, props, {
855
- children: label
856
- }));
857
- // return (
858
- // <IconButton icon={icon ? icon : mdiOpenInNew} type="submit" scheme="dark" variant="glass" size="md" onClick={openPage} {...props}/>
859
- // )
860
- }
861
-
862
- function OrderCell({
863
- api: api$1,
864
- postId,
865
- order
866
- }) {
867
- const mutationDown = api.useInvalidateMutation(api$1.moveDown, api$1.queryKey);
868
- const mutationUp = api.useInvalidateMutation(api$1.moveUp, api$1.queryKey);
869
- const moveDown = React.useCallback(e => {
870
- e.stopPropagation();
871
- mutationDown.mutateAsync(postId).catch(error => {
872
- reactToastify.toast.error(`Error: ${error}`);
873
- });
874
- }, [mutationDown, postId]);
875
- const moveUp = React.useCallback(e => {
876
- e.stopPropagation();
877
- mutationUp.mutateAsync(postId).catch(error => {
878
- reactToastify.toast.error(`Error: ${error}`);
879
- });
880
- }, [mutationUp, postId]);
881
- return jsxRuntime.jsxs(components.FlexCenter, {
882
- placeContent: "start",
883
- numericFontVariant: "tabular-nums",
884
- children: [order, jsxRuntime.jsx(ui.Button, {
885
- ms: "3",
886
- variant: "borderless",
887
- scheme: "dark",
888
- onClick: moveUp,
889
- children: jsxRuntime.jsx(ui.Icon, {
890
- path: mdiArrowUpBoldBox
891
- })
892
- }), jsxRuntime.jsx(ui.Button, {
893
- variant: "borderless",
894
- scheme: "dark",
895
- onClick: moveDown,
896
- children: jsxRuntime.jsx(ui.Icon, {
897
- path: mdiArrowDownBoldBox
898
- })
899
- })]
900
- });
901
- }
902
-
903
- function PageContainer(_a) {
904
- var {
905
- children
906
- } = _a,
907
- props = tslib.__rest(_a, ["children"]);
908
- return jsxRuntime.jsx(ui.Container, Object.assign({
909
- center: true,
910
- dflex: true,
911
- flexCol: true,
912
- gap: "8"
913
- }, props, {
914
- children: children
915
- }));
916
- }
917
-
918
- function PageMain(_a) {
919
- var {
920
- children
921
- } = _a,
922
- props = tslib.__rest(_a, ["children"]);
923
- return jsxRuntime.jsx(ui.Tile, Object.assign({
924
- scheme: "light",
925
- p: "5"
926
- }, props, {
927
- children: children
928
- }));
929
- }
930
-
931
- function PageContentEditor(_a) {
932
- var {
933
- name
934
- } = _a,
935
- props = tslib.__rest(_a, ["name"]);
936
- const extensions = [editor.ImageExtension];
937
- return jsxRuntime.jsx(PageMain, Object.assign({
938
- h: "min"
939
- }, props, {
940
- children: jsxRuntime.jsx(formEditor.FormEditor, {
941
- minH: "128",
942
- minW: "144",
943
- maxW: props.maxW,
944
- // w={props.w}
945
- name: name,
946
- placeHolder: "Write here...",
947
- extensions: extensions
948
- })
949
- }));
950
- }
951
-
952
- function PageQueryStateContainerInner(_a) {
953
- var {
954
- queryId,
955
- api: api$1,
956
- apiFn,
957
- loadingStyles,
958
- errorStyles,
959
- children
960
- } = _a,
961
- props = tslib.__rest(_a, ["queryId", "api", "apiFn", "loadingStyles", "errorStyles", "children"]);
962
- // @ts-ignore
963
- const {
964
- data,
965
- isLoading,
966
- isError
967
- } = apiFn == "getAll" ? api.useApiQuery(api$1.queryKey, api$1.getAll, props.apiParams) : api.useApiQuery(api$1.queryKey, api$1.get, queryId);
968
- const invalidate = api.useInvalidateQuery(api$1.queryKey, queryId);
969
- if (isLoading) return jsxRuntime.jsx(components.QueryLoadingState, Object.assign({
970
- w: "full",
971
- h: "100%"
972
- }, loadingStyles));
973
- if (isError) return jsxRuntime.jsx(components.RetryOnError, Object.assign({
974
- p: "0",
975
- onClick: invalidate
976
- }, errorStyles));
977
- return jsxRuntime.jsx(PageContainer, Object.assign({}, props, {
978
- children: apiFn == "get" ? children(data) : children(data)
979
- }));
980
- }
981
- const PageQueryStateContainer = /*#__PURE__*/React.forwardRef(PageQueryStateContainerInner);
982
-
983
- function PageSidebar(_a) {
984
- var {
985
- children
986
- } = _a,
987
- props = tslib.__rest(_a, ["children"]);
988
- return jsxRuntime.jsx("div", Object.assign({
989
- w: "112",
990
- minW: "112",
991
- minH: "100%",
992
- gap: "8",
993
- dflex: true,
994
- flexCol: true
995
- }, props, {
996
- children: children
997
- }));
998
- }
999
-
1000
- function PageSidebarSection(_a) {
1001
- var {
1002
- title,
1003
- children
1004
- } = _a,
1005
- props = tslib.__rest(_a, ["title", "children"]);
1006
- return jsxRuntime.jsxs("div", Object.assign({
1007
- w: "full"
1008
- }, props, {
1009
- children: [title && jsxRuntime.jsx(admin.PageSectionTitle, {
1010
- children: title
1011
- }), children]
1012
- }));
1013
- }
1014
-
1015
- function PageTitle(_a) {
1016
- var {
1017
- children
1018
- } = _a,
1019
- props = tslib.__rest(_a, ["children"]);
1020
- return jsxRuntime.jsx("div", Object.assign({
1021
- trait: "typo.h5"
1022
- }, props, {
1023
- children: children
1024
- }));
1025
- }
1026
-
1027
- function PageTopBar(_a) {
1028
- var {
1029
- title,
1030
- breadcrumbs,
1031
- children
1032
- } = _a,
1033
- props = tslib.__rest(_a, ["title", "breadcrumbs", "children"]);
1034
- return jsxRuntime.jsxs(components.FlexCenter, Object.assign({
1035
- gap: "3",
1036
- minH: "9"
1037
- }, props, {
1038
- children: [title && jsxRuntime.jsx(PageTitle, {
1039
- children: title
1040
- }), breadcrumbs && jsxRuntime.jsx(Breadcrumbs, {
1041
- breadcrumbs: breadcrumbs
1042
- }), jsxRuntime.jsx("div", {
1043
- flexGrow: true
1044
- }), children]
1045
- }));
1046
- }
1047
- const [CP, usePageTabbedTopBarContext] = react.createContext();
1048
- function PageTabbedTopBarProvider({
1049
- children
1050
- }) {
1051
- const [containerEl, setContainerEl] = React.useState(null);
1052
- return jsxRuntime.jsx(CP, {
1053
- value: {
1054
- containerEl,
1055
- setContainerEl
1056
- },
1057
- children: children
1058
- });
1059
- }
1060
- function PageTabbedTopBar(_a) {
1061
- var {
1062
- title,
1063
- breadcrumbs,
1064
- children
1065
- } = _a,
1066
- props = tslib.__rest(_a, ["title", "breadcrumbs", "children"]);
1067
- const ref = /*#__PURE__*/React.createRef();
1068
- const {
1069
- setContainerEl
1070
- } = usePageTabbedTopBarContext();
1071
- const [isSet, setIsSet] = React.useState(false);
1072
- React.useEffect(() => {
1073
- if (!isSet && ref.current) {
1074
- setContainerEl(ref.current);
1075
- setIsSet(true);
1076
- }
1077
- return () => setContainerEl(null);
1078
- }, []);
1079
- return jsxRuntime.jsx(components.FlexCenter, Object.assign({
1080
- gap: "3",
1081
- minH: "9"
1082
- }, props, {
1083
- children: jsxRuntime.jsxs(jsxRuntime.Fragment, {
1084
- children: [title && jsxRuntime.jsx(PageTitle, {
1085
- children: title
1086
- }), breadcrumbs && jsxRuntime.jsx(Breadcrumbs, {
1087
- breadcrumbs: breadcrumbs
1088
- }), jsxRuntime.jsx("div", {
1089
- flexGrow: true
1090
- }), jsxRuntime.jsx("div", {
1091
- ref: ref,
1092
- dflex: true,
1093
- flexRow: true,
1094
- gap: "3"
1095
- }), children]
1096
- })
1097
- }));
1098
- }
1099
- function PageTopBarToolbar({
1100
- trackingRef,
1101
- children
1102
- }) {
1103
- const {
1104
- containerEl
1105
- } = usePageTabbedTopBarContext();
1106
- const [visible, setVisible] = React.useState(false);
1107
- const portal = React.useMemo(() => {
1108
- const node = containerEl; //?.ownerDocument.createElement("div")
1109
- // if (node) node.className = PORTAL_CLASSNAME
1110
- return node;
1111
- }, [containerEl]);
1112
- const host = containerEl !== null && containerEl !== void 0 ? containerEl : typeof window !== "undefined" ? document.body : undefined;
1113
- React.useLayoutEffect(() => {
1114
- if (!portal || !host) return;
1115
- try {
1116
- if (visible) host.appendChild(portal);else host.removeChild(portal);
1117
- } catch (e) {}
1118
- return () => {
1119
- try {
1120
- host.removeChild(portal);
1121
- } catch (e) {}
1122
- };
1123
- }, [visible, portal, host]);
1124
- const callback = React.useCallback(entries => {
1125
- // @ts-ignore
1126
- setVisible(entries[0].isVisible);
1127
- }, [children]);
1128
- React.useEffect(() => {
1129
- const opts = {
1130
- root: null,
1131
- rootMargin: '0px',
1132
- threshold: 0,
1133
- /* required options*/
1134
- trackVisibility: true,
1135
- delay: 100
1136
- };
1137
- const observerScroll = new IntersectionObserver(callback, opts);
1138
- if (trackingRef) observerScroll.observe(trackingRef);
1139
- return () => observerScroll.disconnect();
1140
- }, [trackingRef, callback, children]);
1141
- if (host && portal) return /*#__PURE__*/reactDom.createPortal(children, portal);
1142
- return null;
1143
- }
1144
-
1145
- function ScreenTopBar({
1146
- tabbed,
1147
- breadcrumbs,
1148
- api,
1149
- item,
1150
- isLoading,
1151
- buttonBar,
1152
- trackingRef
1153
- }) {
1154
- return jsxRuntime.jsxs(jsxRuntime.Fragment, {
1155
- children: [tabbed && jsxRuntime.jsx(PageTopBarToolbar, {
1156
- trackingRef: trackingRef,
1157
- children: jsxRuntime.jsx(Buttons$1, {
1158
- api: api,
1159
- item: item,
1160
- isLoading: isLoading,
1161
- buttonBar: buttonBar
1162
- })
1163
- }), !tabbed && jsxRuntime.jsx(PageTopBar, {
1164
- breadcrumbs: breadcrumbs,
1165
- children: jsxRuntime.jsx(Buttons$1, {
1166
- api: api,
1167
- item: item,
1168
- isLoading: isLoading,
1169
- buttonBar: buttonBar
1170
- })
1171
- })]
1172
- });
1173
- }
1174
- function Buttons$1({
1175
- api,
1176
- item,
1177
- isLoading,
1178
- buttonBar
1179
- }) {
1180
- return jsxRuntime.jsxs(jsxRuntime.Fragment, {
1181
- children: [buttonBar && buttonBar.length > 0 && jsxRuntime.jsx(admin.ButtonBar, {
1182
- children: buttonBar.map((button, index) => jsxRuntime.jsxs(React.Fragment, {
1183
- children: [button.type === "link" && jsxRuntime.jsx(ViewButton, {
1184
- label: button.label,
1185
- path: button.path,
1186
- icon: button.icon
1187
- }), button.type === "invalidate" && jsxRuntime.jsx(InvalidateButton, {
1188
- pathOrPermalink: button.pathOrPermalink
1189
- }), button.type == "custom" && button.render(item)]
1190
- }, index))
1191
- }), jsxRuntime.jsxs(admin.ButtonBar, {
1192
- children: [api instanceof adminApi.API && jsxRuntime.jsx(PublishButton, {
1193
- api: api,
1194
- queryId: item.id,
1195
- status: item.status,
1196
- disabled: isLoading
1197
- }), jsxRuntime.jsx(UpdateButton, {
1198
- disabled: isLoading
1199
- })]
1200
- })]
1201
- });
1202
- }
1203
-
1204
- function useQueryField(queryField, useNextRouter) {
1205
- if (useNextRouter) {
1206
- const router$1 = router.useRouter();
1207
- return router$1.query[queryField];
1208
- }
1209
- const {
1210
- [queryField]: id
1211
- } = reactRouterDom.useParams();
1212
- return id;
1213
- }
1214
- function DetailsView(_a) {
1215
- var {
1216
- queryField,
1217
- api,
1218
- useNextRouter,
1219
- processInput,
1220
- screen,
1221
- tabbed
1222
- } = _a,
1223
- props = tslib.__rest(_a, ["queryField", "api", "useNextRouter", "processInput", "screen", "tabbed"]);
1224
- const id = useQueryField(queryField, useNextRouter);
1225
- const ref = React.useRef(null);
1226
- return jsxRuntime.jsx(PageQueryStateContainer, Object.assign({
1227
- api: api,
1228
- apiFn: "get",
1229
- queryId: id,
1230
- ref: ref,
1231
- p: "5"
1232
- }, props, {
1233
- children: item => jsxRuntime.jsx(Internal, {
1234
- item: item,
1235
- screen: screen,
1236
- api: api,
1237
- tabbed: tabbed,
1238
- processInput: processInput,
1239
- containerRef: ref
1240
- })
1241
- }));
1242
- }
1243
- function Internal({
1244
- item,
1245
- screen,
1246
- api: api$1,
1247
- processInput,
1248
- tabbed,
1249
- containerRef
1250
- }) {
1251
- var _a, _b, _c;
1252
- const pScreen = react.runIfFn(screen, item);
1253
- const {
1254
- breadcrumbs,
1255
- schema,
1256
- initialValues,
1257
- header,
1258
- sections,
1259
- buttonBar,
1260
- type,
1261
- invalidateParentQueryKey,
1262
- invalidatePage
1263
- } = pScreen;
1264
- const mutation = api.useInvalidateParentMutation(api$1.update, invalidateParentQueryKey !== null && invalidateParentQueryKey !== void 0 ? invalidateParentQueryKey : api$1.queryKey, {
1265
- networkMode: "always"
1266
- });
1267
- const invalidatePageFn = adminApi.useInvalidatePage(invalidatePage || "");
1268
- const save = api.useMutate(mutation, {
1269
- processInput,
1270
- successMsg: (item, values) => `${item.title || item.name} updated.`,
1271
- errorMsg: (error, item) => `Error updating ${item.title || item.name}: ${error}`,
1272
- onSuccess: () => {
1273
- if (invalidatePage) invalidatePageFn();
1274
- }
1275
- });
1276
- let editorMaxW = undefined;
1277
- if (!type || type == "post") editorMaxW = "calc(1280px - 28rem)";else if (type == "section") editorMaxW = "calc(1280px - 22rem)";
1278
- return jsxRuntime.jsxs(form.FormProvider, {
1279
- initialValues: react.runIfFn(initialValues, item),
1280
- validationSchema: schema,
1281
- onSubmit: save,
1282
- enableReinitialize: true,
1283
- children: [jsxRuntime.jsx(ScreenTopBar, {
1284
- tabbed: tabbed,
1285
- api: api$1,
1286
- breadcrumbs: breadcrumbs,
1287
- buttonBar: buttonBar,
1288
- item: item,
1289
- isLoading: mutation.isLoading,
1290
- trackingRef: containerRef === null || containerRef === void 0 ? void 0 : containerRef.current
1291
- }), type == "form" && (sections === null || sections === void 0 ? void 0 : sections.map((section, index) => jsxRuntime.jsx(Section, {
1292
- section: section,
1293
- item: item
1294
- }, index))), (pScreen.type == "post" || pScreen.type == "section") && jsxRuntime.jsx("div", {
1295
- p: "5",
1296
- bgColor: "slate-100",
1297
- rounded: "lg",
1298
- children: jsxRuntime.jsxs(PageContainer, {
1299
- w: editorMaxW ? "auto" : "full",
1300
- size: "x2",
1301
- id: "pagecontainer",
1302
- children: [header, jsxRuntime.jsxs("div", {
1303
- dflex: true,
1304
- gap: "5",
1305
- children: [jsxRuntime.jsxs("div", {
1306
- dflex: true,
1307
- flexCol: true,
1308
- gap: "8",
1309
- flexGrow: true,
1310
- children: [((_a = pScreen.editor) === null || _a === void 0 ? void 0 : _a.type) != "textarea" &&
1311
- // TODO Find a way to make this editor shrink in width when resizing the window...
1312
- jsxRuntime.jsx(PageContentEditor, {
1313
- name: "content",
1314
- maxW: editorMaxW,
1315
- minW: "144",
1316
- shadow: true,
1317
- rounded: "lg"
1318
- }), ((_b = pScreen.editor) === null || _b === void 0 ? void 0 : _b.type) == "textarea" && jsxRuntime.jsx(form.TextArea, {
1319
- name: (_c = pScreen.editor) === null || _c === void 0 ? void 0 : _c.name,
1320
- maxW: editorMaxW,
1321
- minW: editorMaxW,
1322
- w: editorMaxW,
1323
- minH: "128",
1324
- rows: 25,
1325
- bgColor: "white",
1326
- border: "0",
1327
- shadow: true,
1328
- p: "5",
1329
- textColor: "slate-800"
1330
- }), pScreen.editorFooter]
1331
- }), jsxRuntime.jsx(PageSidebar, {
1332
- children: sections === null || sections === void 0 ? void 0 : sections.map((section, index) => jsxRuntime.jsx(Section, {
1333
- section: section,
1334
- item: item,
1335
- cardStyle: true
1336
- }, index))
1337
- })]
1338
- })]
1339
- })
1340
- })]
1341
- });
1342
- }
1343
- function Section({
1344
- section,
1345
- item,
1346
- cardStyle
1347
- }) {
1348
- if (section.type === "section") {
1349
- const style = cardStyle ? {
1350
- bgColor: "white",
1351
- rounded: "lg",
1352
- p: "5",
1353
- textSize: "sm",
1354
- shadow: true
1355
- } : {};
1356
- return jsxRuntime.jsx(PageSidebarSection, Object.assign({
1357
- title: section.title
1358
- }, style, {
1359
- children: jsxRuntime.jsx(form.FormRenderer, {
1360
- form: react.runIfFn(section.form, item)
1361
- })
1362
- }));
1363
- }
1364
- if (section.type === "custom") return react.runIfFn(section.component, item);
1365
- return null;
1366
- }
1367
-
1368
- function useApi(api, queryField) {
1369
- const params = reactRouterDom.useParams();
1370
- if (queryField === undefined) return {
1371
- id: undefined,
1372
- api: api
1373
- };
1374
- const {
1375
- [queryField]: id
1376
- } = params;
1377
- return {
1378
- id,
1379
- api: react.runIfFn(api, id)
1380
- };
1381
- }
1382
- function QueryWrapper(_a) {
1383
- var {
1384
- api: api$1,
1385
- queryField,
1386
- fn,
1387
- transformFn,
1388
- config,
1389
- tabbed
1390
- } = _a,
1391
- props = tslib.__rest(_a, ["api", "queryField", "fn", "transformFn", "config", "tabbed"]);
1392
- const {
1393
- id,
1394
- api: mApi
1395
- } = useApi(api$1, queryField);
1396
- const {
1397
- data
1398
- } = api.useApiQuery(mApi.queryKey, fn === "get" || fn === "getTransformed" ? mApi.get : mApi.getAll, react.isFunction(api$1) ? undefined : id);
1399
- const transformedData = React.useMemo(() => {
1400
- if (data && (fn === "getTransformed" || fn === "getAllTransformed")) {
1401
- if (!transformFn) console.warn(`QueryWrapperDialog: you forgot to pass transformFn as parameter for fn ${fn}`);
1402
- return transformFn === null || transformFn === void 0 ? void 0 : transformFn(data);
1403
- }
1404
- return data;
1405
- }, [data]);
1406
- // TODO states
1407
- if (!data) return null;
1408
- return jsxRuntime.jsx(ScreenRenderer, Object.assign({
1409
- config: config(transformedData),
1410
- tabbed: tabbed
1411
- }, props));
1412
- }
1413
-
1414
- function TabbedView(_a) {
1415
- var {
1416
- queryField,
1417
- api,
1418
- screen
1419
- } = _a;
1420
- tslib.__rest(_a, ["queryField", "api", "screen"]);
1421
- const {
1422
- [queryField]: id
1423
- } = reactRouterDom.useParams();
1424
- return jsxRuntime.jsx(PageQueryStateContainer, {
1425
- queryId: id,
1426
- api: api,
1427
- apiFn: "get",
1428
- p: "5",
1429
- children: city => {
1430
- const {
1431
- breadcrumbs,
1432
- tabs
1433
- } = react.runIfFn(screen, city);
1434
- return jsxRuntime.jsxs(PageTabbedTopBarProvider, {
1435
- children: [jsxRuntime.jsx(PageTabbedTopBar, {
1436
- breadcrumbs: breadcrumbs,
1437
- mb: "-3"
1438
- }), jsxRuntime.jsx(components.TabContainer, {
1439
- tabs: tabs.map(tab => tab.label),
1440
- saveKey: `tab-${id}`,
1441
- mt: "-3",
1442
- mb: "3",
1443
- id: "fff",
1444
- children: tabs.map((tab, index) => jsxRuntime.jsx(TabView, {
1445
- tab: tab
1446
- }, index))
1447
- })]
1448
- });
1449
- }
1450
- });
1451
- }
1452
- function TabView({
1453
- tab
1454
- }) {
1455
- if (!tab.component && !tab.config) throw new Error(`Screen config for tabbed view: one of your tabs does not have a component or config declared: ${tab.label}`);
1456
- if (tab.component) return tab.component();
1457
- return jsxRuntime.jsx(ScreenRenderer, {
1458
- config: tab.config,
1459
- tabbed: true,
1460
- p: "0"
1461
- });
1462
- }
1463
-
1464
- const [provider$1, useContext$1] = react.createContext();
1465
- function getColId(column) {
1466
- var _a;
1467
- return (_a = column.accessorKey) !== null && _a !== void 0 ? _a : column.id;
1468
- }
1469
- function TableContainerContextProvider({
1470
- initialVisibleColumns,
1471
- columns,
1472
- children
1473
- }) {
1474
- var _a, _b;
1475
- const [showFilters, setShowFilters] = React.useState(false);
1476
- const [showMassActions, setShowMassActions] = React.useState(false);
1477
- const [visibleColumnIds, setVisibleColumnIds] = React.useState((_a = initialVisibleColumns !== null && initialVisibleColumns !== void 0 ? initialVisibleColumns : columns === null || columns === void 0 ? void 0 : columns.map(col => getColId(col))) !== null && _a !== void 0 ? _a : []);
1478
- const filteredColumns = (_b = columns === null || columns === void 0 ? void 0 : columns.filter(col => visibleColumnIds.includes(getColId(col)))) !== null && _b !== void 0 ? _b : [];
1479
- const toggleColumnVisibility = React.useCallback(id => {
1480
- const index = visibleColumnIds.indexOf(id);
1481
- if (index > -1) {
1482
- const newIds = visibleColumnIds.concat();
1483
- newIds.splice(index, 1);
1484
- setVisibleColumnIds(newIds);
1485
- } else {
1486
- setVisibleColumnIds(visibleColumnIds.concat(id));
1487
- }
1488
- }, [visibleColumnIds, setVisibleColumnIds]);
1489
- const isColumnVisible = React.useCallback(id => {
1490
- return visibleColumnIds.includes(id);
1491
- }, [visibleColumnIds]);
1492
- const Provider = provider$1;
1493
- const value = {
1494
- showFilters,
1495
- setShowFilters,
1496
- showMassActions,
1497
- setShowMassActions,
1498
- columns: columns !== null && columns !== void 0 ? columns : [],
1499
- filteredColumns,
1500
- toggleColumnVisibility,
1501
- isColumnVisible
1502
- };
1503
- return jsxRuntime.jsx(Provider, {
1504
- value: value,
1505
- children: children
1506
- });
1507
- }
1508
-
1509
- function TableContainer(_a) {
1510
- var {
1511
- initialPageSize,
1512
- initialVisibleColumns,
1513
- columns,
1514
- filtersMethod = "reactRouter",
1515
- children
1516
- } = _a,
1517
- props = tslib.__rest(_a, ["initialPageSize", "initialVisibleColumns", "columns", "filtersMethod", "children"]);
1518
- return jsxRuntime.jsx("div", Object.assign({
1519
- w: "full",
1520
- dflex: true,
1521
- flexCol: true
1522
- }, props, {
1523
- children: jsxRuntime.jsx(table.TableContextProvider, {
1524
- initialPageSize: initialPageSize,
1525
- filtersMethod: filtersMethod,
1526
- children: jsxRuntime.jsx(TableContainerContextProvider, {
1527
- columns: columns,
1528
- initialVisibleColumns: initialVisibleColumns,
1529
- children: children
1530
- })
1531
- })
1532
- }));
1533
- }
1534
-
1535
- function TableCreateButton(_a) {
1536
- var {
1537
- icon,
1538
- children
1539
- } = _a,
1540
- props = tslib.__rest(_a, ["icon", "children"]);
1541
- return jsxRuntime.jsxs(admin.ButtonBarDialogButton, Object.assign({}, props, {
1542
- children: [jsxRuntime.jsx(ui.Icon, {
1543
- path: icon !== null && icon !== void 0 ? icon : mdiPlusThick
1544
- }), children]
1545
- }));
1546
- }
1547
-
1548
- function TableFilterButton(_a) {
1549
- var props = tslib.__rest(_a, []);
1550
- // return <Button scheme="secondary" {...props}><Icon path={mdiFilter} /></Button>
1551
- return jsxRuntime.jsxs(ui.Popover, {
1552
- side: "bottom-end",
1553
- modal: true,
1554
- children: [jsxRuntime.jsx(ui.Button, Object.assign({
1555
- scheme: "dark",
1556
- size: "sm",
1557
- aspectRatio: "square",
1558
- variant: "borderless",
1559
- corners: "square"
1560
- }, props, {
1561
- children: jsxRuntime.jsx(ui.Icon, {
1562
- path: mdiFilter
1563
- })
1564
- })), jsxRuntime.jsxs("div", {
1565
- bgColor: "white",
1566
- rounded: true,
1567
- shadow: true,
1568
- children: [jsxRuntime.jsx("div", {
1569
- py: "3",
1570
- hover_bgColor: "#ff0000",
1571
- px: "5",
1572
- hover_textColor: "white",
1573
- children: "First Item"
1574
- }), jsxRuntime.jsx("div", {
1575
- py: "3",
1576
- hover_bgColor: "#ff0000",
1577
- px: "5",
1578
- hover_textColor: "white",
1579
- children: "Second Item"
1580
- }), jsxRuntime.jsx("div", {
1581
- py: "3",
1582
- hover_bgColor: "#ff0000",
1583
- px: "5",
1584
- hover_textColor: "white",
1585
- children: "Third Item"
1586
- })]
1587
- })]
1588
- });
1589
- }
1590
-
1591
- function TableTopBar(_a) {
1592
- var {
1593
- title,
1594
- breadcrumbs,
1595
- children
1596
- } = _a,
1597
- props = tslib.__rest(_a, ["title", "breadcrumbs", "children"]);
1598
- return jsxRuntime.jsxs("div", Object.assign({
1599
- dflex: true,
1600
- flexRow: true,
1601
- alignItems: "center",
1602
- gap: "3",
1603
- p: "8"
1604
- }, props, {
1605
- children: [jsxRuntime.jsxs("div", {
1606
- children: [title && jsxRuntime.jsx("h2", {
1607
- textSize: "x2",
1608
- fontWeight: "600",
1609
- textColor: "#3f4254",
1610
- textTransform: "capitalize",
1611
- children: title
1612
- }), breadcrumbs && jsxRuntime.jsx(admin.Breadcrumbs, {
1613
- breadcrumbs: breadcrumbs
1614
- })]
1615
- }), jsxRuntime.jsx("div", {
1616
- flexGrow: true,
1617
- children: "\u00A0"
1618
- }), children]
1619
- }));
1620
- }
1621
-
1622
- function compareValues(a, b, order) {
1623
- if (a < b) {
1624
- return order === 'asc' ? -1 : 1;
1625
- }
1626
- if (a > b) {
1627
- return order === 'asc' ? 1 : -1;
1628
- }
1629
- return 0;
1630
- }
1631
-
1632
- function orderBy(arr, criteria, orders) {
1633
- return arr.slice().sort((a, b) => {
1634
- const ordersLength = orders.length;
1635
- for (let i = 0; i < criteria.length; i++) {
1636
- const order = ordersLength > i ? orders[i] : orders[ordersLength - 1];
1637
- const criterion = criteria[i];
1638
- const criterionIsFunction = typeof criterion === 'function';
1639
- const valueA = criterionIsFunction ? criterion(a) : a[criterion];
1640
- const valueB = criterionIsFunction ? criterion(b) : b[criterion];
1641
- const result = compareValues(valueA, valueB, order);
1642
- if (result !== 0) {
1643
- return result;
1644
- }
1645
- }
1646
- return 0;
1647
- });
1648
- }
1649
-
1650
- function sortBy(arr, criteria) {
1651
- return orderBy(arr, criteria, ['asc']);
1652
- }
1653
-
1654
- function TableFilters({
1655
- form: form$1,
1656
- initialValues,
1657
- schema,
1658
- processInput
1659
- }) {
1660
- const {
1661
- showFilters
1662
- } = useContext$1();
1663
- const {
1664
- getFilters,
1665
- setFilters
1666
- } = table.useTableContext();
1667
- const handleSubmit = React.useCallback((values, actions) => {
1668
- var _a;
1669
- const params = (_a = processInput === null || processInput === void 0 ? void 0 : processInput(values)) !== null && _a !== void 0 ? _a : values;
1670
- if (!isEqual(params, getFilters())) setFilters(params);
1671
- // setFilters(processInput?.(values) ?? values)
1672
- actions.setSubmitting(false);
1673
- }, [setFilters, processInput]);
1674
- const handleReset = React.useCallback(resetForm => {
1675
- setFilters(initialValues);
1676
- resetForm();
1677
- }, [setFilters, initialValues]);
1678
- React.useEffect(() => setFilters(initialValues), []);
1679
- return jsxRuntime.jsx(ui.Collapse, {
1680
- in: showFilters,
1681
- style: {
1682
- overflow: showFilters ? "initial" : "hidden"
1683
- },
1684
- children: jsxRuntime.jsx("div", {
1685
- p: "8",
1686
- borderT: "px",
1687
- borderB: "px",
1688
- borderColor: "slate-100",
1689
- children: jsxRuntime.jsx(form.FormProvider, {
1690
- initialValues: form.mergeInitialFormValues(getFilters(), initialValues),
1691
- onSubmit: handleSubmit,
1692
- validationSchema: schema,
1693
- enableReinitialize: true,
1694
- children: props => jsxRuntime.jsxs("div", {
1695
- dflex: true,
1696
- gap: "3",
1697
- placeContent: "start",
1698
- children: [jsxRuntime.jsx(form.FormRenderer, {
1699
- flexRow: true,
1700
- w: "auto",
1701
- form: form$1
1702
- }), jsxRuntime.jsx(Buttons, {
1703
- handleReset: () => handleReset(props.resetForm)
1704
- })]
1705
- })
1706
- })
1707
- })
1708
- });
1709
- }
1710
- function Buttons({
1711
- handleReset
1712
- }) {
1713
- return jsxRuntime.jsxs("div", {
1714
- dflex: true,
1715
- gap: "3",
1716
- children: [jsxRuntime.jsxs("div", {
1717
- dflex: true,
1718
- flexCol: true,
1719
- children: [jsxRuntime.jsx(form.FieldLabel, {
1720
- name: "",
1721
- label: "\u00A0"
1722
- }), jsxRuntime.jsx(form.SubmitButton, {
1723
- children: "Filter"
1724
- })]
1725
- }), jsxRuntime.jsxs("div", {
1726
- dflex: true,
1727
- flexCol: true,
1728
- children: [jsxRuntime.jsx(form.FieldLabel, {
1729
- name: "",
1730
- label: "\u00A0"
1731
- }), jsxRuntime.jsx(ui.Button, {
1732
- scheme: "neutral",
1733
- onClick: handleReset,
1734
- children: "Reset"
1735
- })]
1736
- })]
1737
- });
1738
- }
1739
-
1740
- function ActionButton$1({
1741
- label,
1742
- buttonProps,
1743
- icon,
1744
- queryKey,
1745
- queryFn,
1746
- successMsg,
1747
- errorMsg,
1748
- invalidateParent
1749
- }) {
1750
- const mutation = invalidateParent ? api.useInvalidateParentMutation(queryFn, queryKey) : api.useApiMutation(queryFn, queryKey);
1751
- const mutate = api.useMutate(mutation, {
1752
- successMsg,
1753
- errorMsg
1754
- });
1755
- return jsxRuntime.jsxs(ui.Button, Object.assign({
1756
- display: "flex",
1757
- alignItems: "center",
1758
- gap: "3"
1759
- }, buttonProps, {
1760
- onClick: mutate,
1761
- disabled: mutation.isLoading,
1762
- children: [icon && jsxRuntime.jsx(ui.Icon, {
1763
- path: icon
1764
- }), label]
1765
- }));
1766
- }
1767
-
1768
- function TableMassActions({
1769
- actions
1770
- }) {
1771
- const {
1772
- ids
1773
- } = table.useTableContext();
1774
- const showMassActions = ids && ids.length > 0;
1775
- return jsxRuntime.jsx(ui.Collapse, {
1776
- in: showMassActions,
1777
- style: {
1778
- overflow: showMassActions ? "initial" : "hidden"
1779
- },
1780
- children: jsxRuntime.jsx("div", {
1781
- dflex: true,
1782
- gap: "3",
1783
- flexWrap: true,
1784
- alignItems: "center",
1785
- px: "8",
1786
- pt: "5",
1787
- children: actions.map((action, index) => jsxRuntime.jsx("div", {
1788
- children: action.type == "button" && !action.showConfirmationDialog && jsxRuntime.jsx(ActionButton$1, {
1789
- label: action.label,
1790
- queryFn: action.queryFn,
1791
- queryKey: action.queryKey,
1792
- buttonProps: action.buttonProps
1793
- })
1794
- }, index))
1795
- })
1796
- });
1797
- }
1798
-
1799
- const defaultErrorMsg$1 = "Oops, something went wrong...";
1800
- function nonNullValues(data) {
1801
- var _a;
1802
- if (data) {
1803
- const nonNullData = Object.assign({}, data);
1804
- for (const key in data) nonNullData[key] = (_a = nonNullData[key]) !== null && _a !== void 0 ? _a : "";
1805
- return nonNullData;
1806
- }
1807
- return data;
1808
- }
1809
- function ItemEditDialog(_a) {
1810
- var _b, _c, _d, _e;
1811
- var {
1812
- initialValues,
1813
- itemLabel,
1814
- queryId = "",
1815
- api: api$1,
1816
- queryFetchOptions,
1817
- querySaveOptions,
1818
- onSuccess,
1819
- onFetchError,
1820
- fetchErrorMsg = defaultErrorMsg$1,
1821
- onSaveError,
1822
- saveErrorMsg = defaultErrorMsg$1,
1823
- fetchToFormData,
1824
- formToQueryData,
1825
- invalidateQueriesOnSuccess = true,
1826
- invalidateQueryKey,
1827
- retryText = "Retry",
1828
- cancelLabel = "Cancel",
1829
- saveLabel,
1830
- size = "lg",
1831
- title,
1832
- form: form$1,
1833
- show,
1834
- onClose,
1835
- formikProps
1836
- } = _a,
1837
- props = tslib.__rest(_a, ["initialValues", "itemLabel", "queryId", "api", "queryFetchOptions", "querySaveOptions", "onSuccess", "onFetchError", "fetchErrorMsg", "onSaveError", "saveErrorMsg", "fetchToFormData", "formToQueryData", "invalidateQueriesOnSuccess", "invalidateQueryKey", "retryText", "cancelLabel", "saveLabel", "size", "title", "form", "show", "onClose", "formikProps"]);
1838
- const {
1839
- isInitialLoading,
1840
- isFetching,
1841
- data,
1842
- isError,
1843
- error /*, error*/,
1844
- refetch
1845
- } = api.useApiQuery(api$1.queryKey, api$1.get, queryId, Object.assign({
1846
- enabled: !(/*queryId == 0 || */queryId == "" || queryId == null || queryId == undefined),
1847
- onError: onFetchError
1848
- }, queryFetchOptions));
1849
- // const [activeTab, setActiveTab] = React.useState(form && Array.isArray(form) ? form[0].key : "");
1850
- // const [showTab, setShowTab] = React.useState(true);
1851
- const mutation = invalidateQueriesOnSuccess ? api.useInvalidateParentMutation(api$1.upsert, invalidateQueryKey !== null && invalidateQueryKey !== void 0 ? invalidateQueryKey : api$1.queryKey, querySaveOptions) : api.useApiMutation(api$1.upsert, api$1.queryKey, queryId, querySaveOptions);
1852
- const retry = React.useCallback(() => refetch(), [refetch]);
1853
- const saveItem = React.useCallback((item, actions) => tslib.__awaiter(this, void 0, void 0, function* () {
1854
- // Clear mutation error if any
1855
- mutation.reset();
1856
- const formItem = formToQueryData ? formToQueryData(item) : Object.assign({}, item);
1857
- yield mutation.mutateAsync(formItem).then(response => {
1858
- var _a;
1859
- if (onSuccess) onSuccess(formItem, response);else reactToastify.toast.success(`${title ? title(formItem) : (_a = formItem.name) !== null && _a !== void 0 ? _a : formItem.title} ${queryId ? "saved" : "created"}`);
1860
- // closing delete modal
1861
- onClose === null || onClose === void 0 ? void 0 : onClose();
1862
- }).catch(error => {
1863
- var _a;
1864
- console.error("on error", error);
1865
- if (onSaveError) onSaveError(item);else reactToastify.toast.error(`Couldn't save ${title ? title(formItem) : (_a = formItem.name) !== null && _a !== void 0 ? _a : formItem.title}`);
1866
- actions.setSubmitting(false);
1867
- });
1868
- }), [mutation, formToQueryData, onSuccess, onSaveError, onClose]);
1869
- // const switchTab = React.useCallback((tab: string) =>
1870
- // {
1871
- // setActiveTab(tab);
1872
- // setShowTab(false);
1873
- // setTimeout(function ()
1874
- // {
1875
- // setActiveTab(tab);
1876
- // setShowTab(true);
1877
- // }, 150);
1878
- // }, [setActiveTab])
1879
- return jsxRuntime.jsxs(ui.Modal, Object.assign({
1880
- size: size,
1881
- show: show,
1882
- onClose: onClose,
1883
- scheme: "light",
1884
- transition: true
1885
- }, props, {
1886
- children: [jsxRuntime.jsxs(ui.Modal.Header, {
1887
- children: [!isInitialLoading && queryId && `Edit ${title ? title(data) : (_d = (_c = (_b = data === null || data === void 0 ? void 0 : data["name"]) !== null && _b !== void 0 ? _b : data === null || data === void 0 ? void 0 : data["title"]) !== null && _c !== void 0 ? _c : data === null || data === void 0 ? void 0 : data["name"]) !== null && _d !== void 0 ? _d : ""}`, !queryId && `Create new ${itemLabel !== null && itemLabel !== void 0 ? itemLabel : "item"}`, Array.isArray(form$1) && jsxRuntime.jsx(jsxRuntime.Fragment, {})
1888
- // <ul className="nav nav-bold nav-pills">
1889
- // {form.map(item =>
1890
- // <li key={item.key} className="nav-item cursor-pointer bg-hover-light rounded" onClick={() => switchTab(item.key)}>
1891
- // <span className={clsx("nav-link", activeTab === item.key && "active")} data-toggle="tab">{item.label}</span>
1892
- // </li>
1893
- // )}
1894
- // </ul>
1895
- ]
1896
- }), isInitialLoading && jsxRuntime.jsx(ui.Modal.Body, {
1897
- children: jsxRuntime.jsx(components.QueryLoadingState, {
1898
- minW: "72"
1899
- })
1900
- }), isError && jsxRuntime.jsx(ui.Modal.Body, {
1901
- children: jsxRuntime.jsx(components.RetryOnError, {
1902
- label: `${fetchErrorMsg} ${error}`,
1903
- onClick: retry
1904
- })
1905
- }), !isInitialLoading && !isError && jsxRuntime.jsx(jsxRuntime.Fragment, {
1906
- children: jsxRuntime.jsx(formik.Formik
1907
- // initialValues={fetchToFormData && queryId && data ? fetchToFormData(nonNullValues(data)) : nonNullValues(data) ?? initialValues(data) ?? {}}
1908
- , Object.assign({
1909
- // initialValues={fetchToFormData && queryId && data ? fetchToFormData(nonNullValues(data)) : nonNullValues(data) ?? initialValues(data) ?? {}}
1910
- initialValues: fetchToFormData && queryId && data ? fetchToFormData(nonNullValues(data)) : (_e = nonNullValues(initialValues(data))) !== null && _e !== void 0 ? _e : {},
1911
- onSubmit: saveItem
1912
- }, formikProps, {
1913
- children: ({
1914
- setFieldValue,
1915
- dirty,
1916
- handleSubmit,
1917
- isValid,
1918
- values
1919
- }) => jsxRuntime.jsxs(jsxRuntime.Fragment, {
1920
- children: [jsxRuntime.jsx(ui.Modal.Body, {
1921
- pb: "6",
1922
- children: jsxRuntime.jsxs(formik.Form, {
1923
- children: [/*#__PURE__*/React.isValidElement(form$1) && form$1, Array.isArray(form$1) && jsxRuntime.jsx(form.FormRenderer, {
1924
- form: form$1
1925
- }), react.isFunction(form$1) && jsxRuntime.jsx(form.FormRenderer, {
1926
- form: form$1(data !== null && data !== void 0 ? data : values)
1927
- })]
1928
- })
1929
- }), jsxRuntime.jsxs(ui.Modal.Footer, {
1930
- dflex: true,
1931
- placeContent: "end",
1932
- spaceX: "3",
1933
- children: [jsxRuntime.jsx(ui.Button, {
1934
- disabled: mutation.isLoading,
1935
- onClick: onClose,
1936
- variant: "borderless",
1937
- me: "2",
1938
- children: cancelLabel
1939
- }), jsxRuntime.jsx(ui.Button, {
1940
- type: "submit",
1941
- disabled: !dirty || mutation.isLoading /* || !isValid*/,
1942
- onClick: () => handleSubmit(),
1943
- children: saveLabel ? saveLabel : queryId ? "Update" : "Create"
1944
- })]
1945
- })]
1946
- })
1947
- }))
1948
- }), mutation.isLoading && jsxRuntime.jsx(components.ModalLoadingOverlay, {})]
1949
- }));
1950
- }
1951
-
1952
- function QueryWrapperDialog({
1953
- api: api$1,
1954
- fn,
1955
- transformFn,
1956
- config,
1957
- onClose,
1958
- queryId,
1959
- invalidateQueryKey
1960
- }) {
1961
- const {
1962
- data,
1963
- isFetching
1964
- } = api.useApiQuery(api$1.queryKey, fn === "get" || fn === "getTransformed" ? api$1.get : api$1.getAll, undefined, {
1965
- retryOnMount: false,
1966
- refetchOnMount: false,
1967
- refetchOnWindowFocus: false
1968
- });
1969
- const transformedData = React.useMemo(() => {
1970
- if (data && (fn === "getTransformed" || fn === "getAllTransformed")) {
1971
- if (!transformFn) console.warn(`QueryWrapperDialog: you forgot to pass transformFn as parameter for fn ${fn}`);
1972
- // @ts-ignore
1973
- return transformFn === null || transformFn === void 0 ? void 0 : transformFn(data);
1974
- }
1975
- return data;
1976
- }, [data, fn, transformFn]);
1977
- if (isFetching) return null;
1978
- // @ts-ignore
1979
- return jsxRuntime.jsx(ItemEditDialog, Object.assign({}, config(transformedData), {
1980
- queryId: queryId,
1981
- invalidateQueryKey: invalidateQueryKey,
1982
- show: true,
1983
- onClose: onClose
1984
- }));
1985
- }
1986
-
1987
- function MultiQueryWrapperDialog({
1988
- queries,
1989
- config,
1990
- onClose,
1991
- queryId,
1992
- invalidateQueryKey
1993
- }) {
1994
- const {
1995
- data,
1996
- isFetching,
1997
- isError
1998
- } = api.useApiQueries(queries.map(q => ({
1999
- queryKey: q.api.queryKey,
2000
- queryFn: q.fn == "get" ? q.api.get : q.api.getAll,
2001
- queryOptions: {
2002
- cacheTime: q.cache === false ? 0 : undefined,
2003
- staleTime: q.cache === false ? 0 : undefined
2004
- }
2005
- })));
2006
- const transformedData = React.useMemo(() => {
2007
- return data === null || data === void 0 ? void 0 : data.map((d, index) => {
2008
- var _a, _b;
2009
- return queries[index].transformFn ? (_b = (_a = queries[index]) === null || _a === void 0 ? void 0 : _a.transformFn) === null || _b === void 0 ? void 0 : _b.call(_a, d) : d;
2010
- });
2011
- }, [data, queries]);
2012
- // TODO This is not really good
2013
- // So instead, add a isPreloading and isPreloadingError to ItemEditDialog to handle the cases
2014
- // if (isFetching)
2015
- // return null
2016
- // @ts-ignore
2017
- return jsxRuntime.jsx(ItemEditDialog, Object.assign({
2018
- isPreloading: isFetching
2019
- }, config(...transformedData), {
2020
- queryId: queryId,
2021
- invalidateQueryKey: invalidateQueryKey,
2022
- show: true,
2023
- onClose: onClose
2024
- }));
2025
- }
2026
-
2027
- function DialogRenderer({
2028
- config,
2029
- onClose,
2030
- invalidateQueryKey,
2031
- queryId
2032
- }) {
2033
- const {
2034
- type
2035
- } = config,
2036
- props = tslib.__rest(config, ["type"]);
2037
- if (config.type === "dialog") return jsxRuntime.jsx(ItemEditDialog, Object.assign({}, props, {
2038
- queryId: queryId,
2039
- invalidateQueryKey: invalidateQueryKey,
2040
- show: true,
2041
- onClose: onClose
2042
- }));
2043
- if (config.type === "query") return jsxRuntime.jsx(QueryWrapperDialog, Object.assign({}, props, {
2044
- queryId: queryId,
2045
- invalidateQueryKey: invalidateQueryKey,
2046
- onClose: onClose
2047
- }));
2048
- if (config.type === "multiQuery") return jsxRuntime.jsx(MultiQueryWrapperDialog, Object.assign({}, props, {
2049
- queryId: queryId,
2050
- invalidateQueryKey: invalidateQueryKey,
2051
- onClose: onClose
2052
- }));
2053
- return null;
2054
- }
2055
-
2056
- function RefreshButton({
2057
- queryKey
2058
- }) {
2059
- const invalidate = api.useInvalidateQuery(queryKey);
2060
- fe('ctrl+r', () => invalidate(), {
2061
- preventDefault: true
2062
- }, [invalidate]);
2063
- return jsxRuntime.jsx(ButtonBarButton, {
2064
- scheme: "dark",
2065
- size: "sm",
2066
- aspectRatio: "square",
2067
- variant: "borderless",
2068
- onClick: invalidate,
2069
- children: jsxRuntime.jsx(ui.Icon, {
2070
- path: mdiRefresh
2071
- })
2072
- });
2073
- }
2074
-
2075
- function ItemDeleteDialog(_a) {
2076
- var {
2077
- title,
2078
- actionButtonLabel,
2079
- closeActionButtonLabel = "Cancel",
2080
- itemLabel,
2081
- queryId = "",
2082
- api: api$1,
2083
- apiFn,
2084
- invalidateQueriesOnSuccess = true,
2085
- invalidateQueryKey,
2086
- size = "lg",
2087
- md_boxSizing,
2088
- msg,
2089
- show,
2090
- onClose,
2091
- onSuccess
2092
- } = _a,
2093
- props = tslib.__rest(_a, ["title", "actionButtonLabel", "closeActionButtonLabel", "itemLabel", "queryId", "api", "apiFn", "invalidateQueriesOnSuccess", "invalidateQueryKey", "size", "md_boxSizing", "msg", "show", "onClose", "onSuccess"]);
2094
- const fn = apiFn ? api$1[apiFn] : api$1.delete;
2095
- const mutation = invalidateQueriesOnSuccess ? api.useInvalidateParentMutation(fn, invalidateQueryKey !== null && invalidateQueryKey !== void 0 ? invalidateQueryKey : api$1.queryKey) : api.useApiMutation(fn, api$1.queryKey);
2096
- const mutate = api.useMutate(mutation, {
2097
- onSuccess: () => {
2098
- onClose === null || onClose === void 0 ? void 0 : onClose();
2099
- onSuccess === null || onSuccess === void 0 ? void 0 : onSuccess();
2100
- }
2101
- });
2102
- const handleDelete = React.useCallback(() => mutate(queryId), [mutate, queryId]);
2103
- return jsxRuntime.jsxs(ui.Modal, Object.assign({
2104
- size: size,
2105
- show: show,
2106
- onClose: onClose,
2107
- scheme: "danger",
2108
- variant: "glass",
2109
- transition: true
2110
- }, props, {
2111
- children: [jsxRuntime.jsx(ui.Modal.Header, {
2112
- children: title || `Delete ${itemLabel}`
2113
- }), jsxRuntime.jsxs(ui.Modal.Body, {
2114
- pb: "6",
2115
- children: [!msg && `Do you really want to delete ${itemLabel}?`, msg && react.runIfFn(msg, itemLabel)]
2116
- }), jsxRuntime.jsxs(ui.Modal.Footer, {
2117
- dflex: true,
2118
- placeContent: "end",
2119
- spaceX: "3",
2120
- children: [jsxRuntime.jsx(ui.Button, {
2121
- disabled: mutation.isPending,
2122
- onClick: onClose,
2123
- variant: "borderless",
2124
- scheme: "dark",
2125
- me: "2",
2126
- children: closeActionButtonLabel
2127
- }), jsxRuntime.jsx(ui.Button, {
2128
- scheme: "danger",
2129
- disabled: mutation.isPending,
2130
- onClick: handleDelete,
2131
- children: actionButtonLabel || "Delete"
2132
- })]
2133
- }), mutation.isPending && jsxRuntime.jsx(components.ModalLoadingOverlay, {})]
2134
- }));
2135
- }
2136
-
2137
- const [provider, useContext] = react.createContext();
2138
- function TableViewProvider({
2139
- editView,
2140
- deleteItem,
2141
- queryKey,
2142
- children
2143
- }) {
2144
- const openLink = hooks.useOpenLink();
2145
- const navigate = reactRouterDom.useNavigate();
2146
- const [dialog, setDialog] = React.useState(null);
2147
- const onCloseDialog = React.useCallback(() => setDialog(null), [setDialog]);
2148
- const onAction = React.useCallback((action, item) => {
2149
- switch (action.type) {
2150
- case "view":
2151
- {
2152
- navigate(react.runIfFn(action.path, item));
2153
- break;
2154
- }
2155
- case "link":
2156
- {
2157
- openLink(`${env.AppEnv.websiteUrl()}/${react.runIfFn(action.path, item)}`);
2158
- break;
2159
- }
2160
- case "edit":
2161
- {
2162
- const editConfig = react.runIfFn(editView, item);
2163
- if (editConfig) {
2164
- if (editConfig.type == "customDialog") {
2165
- setDialog(editConfig.render({
2166
- show: true,
2167
- onClose: onCloseDialog
2168
- }));
2169
- } else {
2170
- setDialog(jsxRuntime.jsx(DialogRenderer, {
2171
- onClose: onCloseDialog,
2172
- config: editConfig,
2173
- queryId: item.id,
2174
- invalidateQueryKey: queryKey
2175
- }));
2176
- }
2177
- }
2178
- break;
2179
- }
2180
- case "delete":
2181
- {
2182
- const deleteConfig = react.runIfFn(deleteItem, item);
2183
- setDialog(jsxRuntime.jsx(ItemDeleteDialog, Object.assign({
2184
- show: true,
2185
- onClose: onCloseDialog,
2186
- queryId: item.id,
2187
- invalidateQueryKey: queryKey,
2188
- msg: item.msg
2189
- }, deleteConfig, {
2190
- itemLabel: react.runIfFn(deleteConfig.itemLabel, item)
2191
- })));
2192
- // TODO
2193
- // const { initialValues, ...props } = editItem!!
2194
- // setDialog(<ItemEditDialog {...props} initialValues={runIfFn(initialValues, item)} show queryId={item?.id} onClose={onCloseDialog} />)
2195
- break;
2196
- }
2197
- }
2198
- }, [navigate, editView, deleteItem]);
2199
- const Provider = provider;
2200
- const value = {
2201
- dialog,
2202
- onAction
2203
- };
2204
- return jsxRuntime.jsx(Provider, {
2205
- value: value,
2206
- children: children
2207
- });
2208
- }
2209
-
2210
- /**
2211
- * table-core
2212
- *
2213
- * Copyright (c) TanStack
2214
- *
2215
- * This source code is licensed under the MIT license found in the
2216
- * LICENSE.md file in the root directory of this source tree.
2217
- *
2218
- * @license MIT
2219
- */
2220
- // type Person = {
2221
- // firstName: string
2222
- // lastName: string
2223
- // age: number
2224
- // visits: number
2225
- // status: string
2226
- // progress: number
2227
- // createdAt: Date
2228
- // nested: {
2229
- // foo: [
2230
- // {
2231
- // bar: 'bar'
2232
- // }
2233
- // ]
2234
- // bar: { subBar: boolean }[]
2235
- // baz: {
2236
- // foo: 'foo'
2237
- // bar: {
2238
- // baz: 'baz'
2239
- // }
2240
- // }
2241
- // }
2242
- // }
2243
-
2244
- // const test: DeepKeys<Person> = 'nested.foo.0.bar'
2245
- // const test2: DeepKeys<Person> = 'nested.bar'
2246
-
2247
- // const helper = createColumnHelper<Person>()
2248
-
2249
- // helper.accessor('nested.foo', {
2250
- // cell: info => info.getValue(),
2251
- // })
2252
-
2253
- // helper.accessor('nested.foo.0.bar', {
2254
- // cell: info => info.getValue(),
2255
- // })
2256
-
2257
- // helper.accessor('nested.bar', {
2258
- // cell: info => info.getValue(),
2259
- // })
2260
-
2261
- function createColumnHelper() {
2262
- return {
2263
- accessor: (accessor, column) => {
2264
- return typeof accessor === 'function' ? {
2265
- ...column,
2266
- accessorFn: accessor
2267
- } : {
2268
- ...column,
2269
- accessorKey: accessor
2270
- };
2271
- },
2272
- display: column => column,
2273
- group: column => column
2274
- };
2275
- }
2276
-
2277
- function TableRowPublishPostButton$1(_a) {
2278
- var {
2279
- id,
2280
- api: api$1,
2281
- status,
2282
- invalidateQueryKey
2283
- } = _a,
2284
- props = tslib.__rest(_a, ["id", "api", "status", "invalidateQueryKey"]);
2285
- const isDraft = status == "draft";
2286
- const mutation = api.useInvalidateParentMutation(isDraft ? api$1.publish : api$1.unpublish, invalidateQueryKey !== null && invalidateQueryKey !== void 0 ? invalidateQueryKey : api$1.queryKey, {
2287
- networkMode: "always"
2288
- });
2289
- const publish = React.useCallback(event => {
2290
- event === null || event === void 0 ? void 0 : event.preventDefault();
2291
- event === null || event === void 0 ? void 0 : event.stopPropagation();
2292
- mutation.reset();
2293
- mutation.mutateAsync(id).then(() => reactToastify.toast.success(isDraft ? "Published!" : "Unpublished!")).catch(error => reactToastify.toast.error(`Error: ${error}`));
2294
- }, [mutation, id]);
2295
- return jsxRuntime.jsx(ui.Button, Object.assign({
2296
- variant: "borderless",
2297
- corners: "square",
2298
- scheme: "dark",
2299
- onClick: publish
2300
- }, props, {
2301
- children: jsxRuntime.jsx(ui.Icon, {
2302
- path: isDraft ? mdiPublish : mdiPublishOff,
2303
- size: "sm"
2304
- })
2305
- }));
2306
- }
2307
-
2308
- function TableRowActionsView({
2309
- row,
2310
- onAction,
2311
- rowActions,
2312
- api,
2313
- queryKey
2314
- }) {
2315
- var _a;
2316
- const item = row.original;
2317
- return jsxRuntime.jsx("div", {
2318
- dflex: true,
2319
- w: "full",
2320
- alignItems: "stretch",
2321
- placeContent: "end",
2322
- h: "full",
2323
- children: (_a = react.runIfFn(rowActions, item)) === null || _a === void 0 ? void 0 : _a.map((action, index) => {
2324
- var _a;
2325
- return jsxRuntime.jsxs(React.Fragment, {
2326
- children: [action.type === "publish" && jsxRuntime.jsx(TableRowPublishPostButton$1, {
2327
- id: item.id,
2328
- api: (_a = action.api) !== null && _a !== void 0 ? _a : api,
2329
- status: item.status,
2330
- invalidateQueryKey: queryKey
2331
- }), action.type == "custom" && jsxRuntime.jsx(jsxRuntime.Fragment, {
2332
- children: action.component(item, queryKey, action.icon, action.label)
2333
- }), !["publish", "custom"].includes(action.type) && jsxRuntime.jsx(ActionButton, {
2334
- onClick: () => onAction(action, item),
2335
- scheme: schemes$1[action.type],
2336
- children: jsxRuntime.jsx(ui.Icon, {
2337
- path: icons[action.type],
2338
- size: "sm"
2339
- })
2340
- })]
2341
- }, index);
2342
- })
2343
- });
2344
- }
2345
- function ActionButton(_a) {
2346
- var {
2347
- onClick
2348
- } = _a,
2349
- props = tslib.__rest(_a, ["onClick"]);
2350
- const handleClick = React.useCallback(event => {
2351
- event === null || event === void 0 ? void 0 : event.preventDefault();
2352
- event === null || event === void 0 ? void 0 : event.stopPropagation();
2353
- onClick === null || onClick === void 0 ? void 0 : onClick(event);
2354
- }, [onClick]);
2355
- return jsxRuntime.jsx(admin.TableRowActionButton, Object.assign({
2356
- onClick: handleClick
2357
- }, props));
2358
- }
2359
- const icons = {
2360
- "link": mdiOpenInNew,
2361
- "view": mdiEye,
2362
- "edit": mdiPencil,
2363
- "delete": mdiDelete,
2364
- "publish": mdiDelete,
2365
- "custom": ""
2366
- };
2367
- const schemes$1 = {
2368
- "link": "dark",
2369
- "view": "dark",
2370
- "edit": "dark",
2371
- "delete": "dark",
2372
- "publish": "dark",
2373
- "custom": "dark"
2374
- };
2375
-
2376
- function useTableProps(api, table, rowActions, queryParams) {
2377
- const navigate = reactRouterDom.useNavigate();
2378
- const nextRouter = router.useRouter();
2379
- const openLink = hooks.useOpenLink();
2380
- const {
2381
- onAction
2382
- } = useContext();
2383
- const {
2384
- onRowClick,
2385
- columns: c
2386
- } = table,
2387
- props = tslib.__rest(table, ["onRowClick", "columns"]);
2388
- const onRowClickHandler = React.useCallback(item => {
2389
- var _a;
2390
- const config = react.runIfFn(onRowClick, item);
2391
- if (config) {
2392
- switch (config.type) {
2393
- case "navigate":
2394
- {
2395
- navigate((_a = react.runIfFn(config.path, item)) !== null && _a !== void 0 ? _a : "");
2396
- break;
2397
- }
2398
- case "nextpush":
2399
- {
2400
- nextRouter.push(react.runIfFn(config.path, item));
2401
- break;
2402
- }
2403
- case "link":
2404
- {
2405
- openLink(`${env.AppEnv.websiteUrl()}/${react.runIfFn(config.path, item)}`);
2406
- break;
2407
- }
2408
- }
2409
- }
2410
- }, [navigate, onRowClick]);
2411
- const columns = React.useMemo(() => {
2412
- const columns = table.columns.concat([]);
2413
- if (rowActions) {
2414
- columns.push(createColumnHelper().display({
2415
- id: "actions",
2416
- header: "Actions",
2417
- cell: props => jsxRuntime.jsx(TableRowActionsView, {
2418
- row: props.row,
2419
- onAction: onAction,
2420
- rowActions: rowActions,
2421
- api: api,
2422
- queryKey: api.queryKey
2423
- })
2424
- }));
2425
- }
2426
- return columns;
2427
- }, [table, onAction, rowActions, api]);
2428
- const tableProps = Object.assign({}, props);
2429
- tableProps.columns = columns;
2430
- tableProps.onRowClick = onRowClickHandler;
2431
- tableProps.queryKey = api.queryKey;
2432
- tableProps.queryFilters = queryParams;
2433
- tableProps.queryFn = api.search;
2434
- return tableProps;
2435
- }
2436
-
2437
- function useId(queryField) {
2438
- const params = reactRouterDom.useParams();
2439
- if (queryField === undefined) return undefined;
2440
- const {
2441
- [queryField]: id
2442
- } = params;
2443
- return id;
2444
- }
2445
- function TableView(_a) {
2446
- var {
2447
- queryField,
2448
- title,
2449
- subtitle,
2450
- screen
2451
- } = _a,
2452
- props = tslib.__rest(_a, ["queryField", "title", "subtitle", "screen"]);
2453
- const id = useId(queryField);
2454
- const _screen = react.runIfFn(screen, id);
2455
- return jsxRuntime.jsx(PageContainer, Object.assign({
2456
- bgColor: "white"
2457
- }, props, {
2458
- children: jsxRuntime.jsx(TableContainer, {
2459
- columns: _screen.table.columns,
2460
- initialVisibleColumns: _screen.table.initialVisibleColumns,
2461
- filtersMethod: _screen.table.filtersMethod,
2462
- children: jsxRuntime.jsx(TT, {
2463
- id: id,
2464
- title: title,
2465
- subtitle: subtitle,
2466
- screen: _screen
2467
- })
2468
- })
2469
- }));
2470
- }
2471
- function TT({
2472
- id,
2473
- title,
2474
- subtitle,
2475
- screen
2476
- }) {
2477
- const {
2478
- setRowSelection
2479
- } = table.useTableContext();
2480
- const {
2481
- api,
2482
- table: table$1,
2483
- filters,
2484
- massActions,
2485
- buttonBar,
2486
- rowActions,
2487
- createView,
2488
- editView,
2489
- deleteItem,
2490
- breadcrumbs
2491
- } = screen;
2492
- const tableApi = react.runIfFn(api, id !== null && id !== void 0 ? id : "");
2493
- return jsxRuntime.jsxs(jsxRuntime.Fragment, {
2494
- children: [jsxRuntime.jsx(TableTopBar, {
2495
- title: title,
2496
- breadcrumbs: breadcrumbs,
2497
- children: jsxRuntime.jsx(TableButtonBar, {
2498
- buttonBar: buttonBar,
2499
- createView: createView,
2500
- editView: editView,
2501
- api: tableApi,
2502
- queryKey: tableApi.queryKey,
2503
- children: filters && jsxRuntime.jsx(TableFilterButton, {})
2504
- })
2505
- }), filters && jsxRuntime.jsx(TableFilters, {
2506
- form: filters.form,
2507
- initialValues: filters.initialValues,
2508
- schema: filters.schema,
2509
- processInput: filters.processInput
2510
- }), massActions && jsxRuntime.jsx(TableMassActions, {
2511
- actions: massActions.items
2512
- }), jsxRuntime.jsxs(TableViewProvider, {
2513
- queryKey: tableApi.queryKey,
2514
- editView: editView,
2515
- deleteItem: deleteItem,
2516
- children: [jsxRuntime.jsx(TableWrapper, {
2517
- table: Object.assign(Object.assign({}, table$1), {
2518
- onSelectionChange: setRowSelection
2519
- }),
2520
- rowActions: rowActions,
2521
- api: tableApi,
2522
- subtitle: subtitle,
2523
- queryParams: screen.queryParams
2524
- }), jsxRuntime.jsx(TableDialogManager, {})]
2525
- })]
2526
- });
2527
- }
2528
- function TableButtonBar({
2529
- buttonBar,
2530
- queryKey,
2531
- createView,
2532
- editView,
2533
- api,
2534
- children
2535
- }) {
2536
- const createDialogFn = React.useCallback(data => {
2537
- return onClose => {
2538
- var _a;
2539
- const view = (_a = react.runIfFn(createView, data)) !== null && _a !== void 0 ? _a : react.runIfFn(editView, null);
2540
- if (view.type == "customDialog") return view.render({
2541
- show: true,
2542
- onClose
2543
- });else return jsxRuntime.jsx(DialogRenderer, {
2544
- config: view,
2545
- onClose: onClose,
2546
- invalidateQueryKey: api.queryKey
2547
- });
2548
- };
2549
- }, [createView, editView, api]);
2550
- return jsxRuntime.jsxs(ButtonBar, {
2551
- children: [jsxRuntime.jsx(RefreshButton, {
2552
- queryKey: queryKey
2553
- }), buttonBar && buttonBar.map((button, index) => jsxRuntime.jsxs(React.Fragment, {
2554
- children: [button.type === "create" && editView && jsxRuntime.jsx(TableCreateButton, {
2555
- buildDialog: createDialogFn(button.data),
2556
- icon: button.icon,
2557
- children: button.label
2558
- }), button.type === "invalidate" && jsxRuntime.jsx(InvalidateButton, {
2559
- pathOrPermalink: button.pathOrPermalink
2560
- }), button.type === "custom" && button.render()]
2561
- }, index)), children]
2562
- });
2563
- }
2564
- function TableWrapper({
2565
- table: table$1,
2566
- subtitle,
2567
- rowActions,
2568
- api,
2569
- queryParams
2570
- }) {
2571
- const tableProps = useTableProps(api, table$1, rowActions, queryParams);
2572
- const _subtitle = React.useMemo(() => {
2573
- if (!subtitle) return undefined;
2574
- return data => {
2575
- return jsxRuntime.jsx("div", {
2576
- textSize: "lg",
2577
- textColor: "#475569",
2578
- fontWeight: "600",
2579
- children: react.isFunction(subtitle) ? subtitle(data) : subtitle
2580
- });
2581
- };
2582
- }, [subtitle]);
2583
- return jsxRuntime.jsx(table.Table, Object.assign({}, tableProps, {
2584
- p: "8",
2585
- title: _subtitle
2586
- }));
2587
- }
2588
- function TableDialogManager() {
2589
- const {
2590
- dialog
2591
- } = useContext();
2592
- return dialog;
2593
- }
2594
-
2595
- function useQueries(queries) {
2596
- const params = reactRouterDom.useParams();
2597
- const {
2598
- data,
2599
- isFetching,
2600
- isError
2601
- } = api.useApiQueries(queries.map(q => {
2602
- if (!q.queryField) {
2603
- const _api = react.runIfFn(q.api);
2604
- return {
2605
- queryKey: _api.queryKey,
2606
- queryFn: q.fn == "get" ? _api.get : _api.getAll,
2607
- queryParam: q.params
2608
- };
2609
- }
2610
- const id = params[q.queryField];
2611
- const api = react.runIfFn(q.api, id);
2612
- return {
2613
- queryKey: api.queryKey,
2614
- queryFn: q.fn == "get" ? api.get : api.getAll,
2615
- queryParam: q.fn == "getAll" ? q.params : react.isFunction(q.api) ? undefined : id
2616
- };
2617
- }));
2618
- let transformedData = undefined;
2619
- if (!isFetching && !isError) {
2620
- transformedData = data === null || data === void 0 ? void 0 : data.map((d, index) => {
2621
- var _a, _b;
2622
- return queries[index].transformFn ? (_b = (_a = queries[index]).transformFn) === null || _b === void 0 ? void 0 : _b.call(_a, d) : d;
2623
- });
2624
- }
2625
- return {
2626
- data: transformedData,
2627
- isFetching,
2628
- isError
2629
- };
2630
- }
2631
- function useInvalidate(queries) {
2632
- const queryClient = reactQuery.useQueryClient();
2633
- const params = reactRouterDom.useParams();
2634
- const invalidate = React.useCallback(() => {
2635
- const queryKeys = [];
2636
- queries.forEach(q => {
2637
- if (!q.queryField || !react.isFunction(q.api)) {
2638
- queryKeys.push(q.api.queryKey);
2639
- } else {
2640
- const id = params[q.queryField];
2641
- const api = react.runIfFn(q.api, id);
2642
- queryKeys.push(api.queryKey);
2643
- }
2644
- });
2645
- queryClient.invalidateQueries({
2646
- predicate: query => queryKeys.includes(query.queryKey)
2647
- });
2648
- }, [queries, queryClient, params]);
2649
- return invalidate;
2650
- }
2651
- function MultiQueryWrapper(_a) {
2652
- var {
2653
- queries,
2654
- config,
2655
- tabbed
2656
- } = _a,
2657
- props = tslib.__rest(_a, ["queries", "config", "tabbed"]);
2658
- const {
2659
- data,
2660
- isFetching,
2661
- isError
2662
- } = useQueries(queries);
2663
- const invalidate = useInvalidate(queries);
2664
- if (isFetching) return jsxRuntime.jsx(components.QueryLoadingState, {
2665
- w: "full",
2666
- h: "100vh"
2667
- });
2668
- if (isError || !data) return jsxRuntime.jsx(components.RetryOnError, {
2669
- p: "0",
2670
- w: "full",
2671
- h: "100vh",
2672
- onClick: invalidate
2673
- });
2674
- return jsxRuntime.jsx(ScreenRenderer, Object.assign({
2675
- config: config(...data),
2676
- tabbed: tabbed
2677
- }, props));
2678
- }
2679
-
2680
- function ScreenRenderer(_a) {
2681
- var {
2682
- config,
2683
- tabbed
2684
- } = _a,
2685
- props = tslib.__rest(_a, ["config", "tabbed"]);
2686
- if (config.type === "table") return jsxRuntime.jsx(TableView, Object.assign({}, config, props));
2687
- if (config.type === "tabbed") return jsxRuntime.jsx(TabbedView, Object.assign({}, config, props));
2688
- if (config.type === "details") return jsxRuntime.jsx(DetailsView, Object.assign({}, config, {
2689
- tabbed: tabbed
2690
- }, props));
2691
- if (config.type === "query") return jsxRuntime.jsx(QueryWrapper, Object.assign({}, config, {
2692
- tabbed: tabbed
2693
- }, props));
2694
- if (config.type === "multiQuery") return jsxRuntime.jsx(MultiQueryWrapper, Object.assign({}, config, {
2695
- tabbed: tabbed
2696
- }, props));
2697
- return jsxRuntime.jsx(jsxRuntime.Fragment, {});
2698
- }
2699
-
2700
- /**
2701
- *
2702
- *
2703
- */
2704
- function Content(_a) {
2705
- var props = tslib.__rest(_a, []);
2706
- return jsxRuntime.jsx("div", Object.assign({
2707
- w: "100%",
2708
- h: "100%",
2709
- overflowY: "auto"
2710
- }, props, {
2711
- children: jsxRuntime.jsx(reactRouterDom.Outlet, {})
2712
- }));
2713
- }
2714
-
2715
- function SelectedIndicator({
2716
- darkMode
2717
- }) {
2718
- return jsxRuntime.jsx("div", {
2719
- position: "absolute",
2720
- bgColor: darkMode ? "white" : "black",
2721
- bgOpacity: "90",
2722
- w: "0.5",
2723
- h: "6",
2724
- top: "1.5",
2725
- start: "-4"
2726
- });
2727
- }
2728
-
2729
- function MenuButton(_a) {
2730
- var {
2731
- depth,
2732
- darkMode,
2733
- icon,
2734
- selected,
2735
- children
2736
- } = _a,
2737
- props = tslib.__rest(_a, ["depth", "darkMode", "icon", "selected", "children"]);
2738
- return jsxRuntime.jsxs(ui.Button, Object.assign({
2739
- as: "li",
2740
- minH: "8",
2741
- ms: `${(depth !== null && depth !== void 0 ? depth : 0) * 2}`,
2742
- p: "2",
2743
- font: "title",
2744
- textColor: darkMode ? "white" : "black",
2745
- fontWeight: "600",
2746
- rounded: "lg",
2747
- textSize: "sm",
2748
- variant: "borderless",
2749
- hover_bgColor: darkMode ? "white" : "black",
2750
- hover_bgOpacity: "10",
2751
- hover_textColor: darkMode ? "white" : "zinc-800",
2752
- cursor: "pointer",
2753
- dflex: true,
2754
- alignItems: "center",
2755
- gap: "3"
2756
- }, props, {
2757
- children: [icon && jsxRuntime.jsx(ui.Icon, {
2758
- path: icon,
2759
- opacity: selected ? "100" : "60"
2760
- }), children]
2761
- }));
2762
- }
2763
-
2764
- function MenuItem$1(_a) {
2765
- var {
2766
- icon,
2767
- path,
2768
- depth,
2769
- darkMode,
2770
- subMenu
2771
- } = _a,
2772
- props = tslib.__rest(_a, ["icon", "path", "depth", "darkMode", "subMenu"]);
2773
- const location = reactRouterDom.useLocation();
2774
- const selected = path == "/" ? location.pathname == "/" : location.pathname.startsWith(path.startsWith("/") ? path : `/${path}`);
2775
- const match = reactRouterDom.useMatch("/" + path) != null;
2776
- // const selected = match != null
2777
- return jsxRuntime.jsxs(jsxRuntime.Fragment, {
2778
- children: [jsxRuntime.jsxs(reactRouterDom.Link, {
2779
- to: path,
2780
- style: {
2781
- position: "relative"
2782
- },
2783
- children: [jsxRuntime.jsx(MenuButton, Object.assign({
2784
- depth: depth,
2785
- darkMode: darkMode,
2786
- icon: icon,
2787
- selected: selected
2788
- }, props)), match && jsxRuntime.jsx(SelectedIndicator, {
2789
- darkMode: darkMode
2790
- })]
2791
- }), subMenu === null || subMenu === void 0 ? void 0 : subMenu.map((item, index) => jsxRuntime.jsx(MenuItem$1, {
2792
- icon: item.icon,
2793
- path: item.path,
2794
- depth: (depth !== null && depth !== void 0 ? depth : 0) + 1,
2795
- darkMode: darkMode,
2796
- subMenu: item.children,
2797
- children: item.label
2798
- }, index))]
2799
- });
2800
- }
2801
-
2802
- function NextMenuItem(_a) {
2803
- var {
2804
- icon,
2805
- path,
2806
- depth,
2807
- darkMode,
2808
- subMenu
2809
- } = _a,
2810
- props = tslib.__rest(_a, ["icon", "path", "depth", "darkMode", "subMenu"]);
2811
- const {
2812
- pathname
2813
- } = router.useRouter();
2814
- const selected = path == "/" ? pathname == "/" : pathname.startsWith(path.startsWith("/") ? path : `/${path}`);
2815
- const match = path == "/" ? pathname == "/" : pathname == (path.startsWith("/") ? path : `/${path}`);
2816
- return jsxRuntime.jsxs(jsxRuntime.Fragment, {
2817
- children: [jsxRuntime.jsxs(Link, {
2818
- href: path,
2819
- style: {
2820
- position: "relative"
2821
- },
2822
- children: [jsxRuntime.jsx(MenuButton, Object.assign({
2823
- depth: depth,
2824
- darkMode: darkMode,
2825
- icon: icon,
2826
- selected: selected
2827
- }, props)), match && jsxRuntime.jsx(SelectedIndicator, {
2828
- darkMode: darkMode
2829
- })]
2830
- }), subMenu === null || subMenu === void 0 ? void 0 : subMenu.map((item, index) => jsxRuntime.jsx(NextMenuItem, {
2831
- icon: item.icon,
2832
- path: item.path,
2833
- depth: (depth !== null && depth !== void 0 ? depth : 0) + 1,
2834
- darkMode: darkMode,
2835
- subMenu: item.children,
2836
- children: item.label
2837
- }, index))]
2838
- });
2839
- }
2840
-
2841
- /**
2842
- *
2843
- *
2844
- */
2845
- function Menu(_a) {
2846
- var {
2847
- darkMode,
2848
- config,
2849
- useNextRouter
2850
- } = _a,
2851
- props = tslib.__rest(_a, ["darkMode", "config", "useNextRouter"]);
2852
- const Comp = useNextRouter ? NextMenuItem : MenuItem$1;
2853
- return jsxRuntime.jsx("ul", Object.assign({}, props, {
2854
- children: config.map((item, index) => {
2855
- if (item.type == "divider") return jsxRuntime.jsx(Divider, {
2856
- title: item.label
2857
- }, index);
2858
- if (item.type == "item") {
2859
- return jsxRuntime.jsx(Comp, {
2860
- icon: item.icon,
2861
- path: item.path,
2862
- depth: 0,
2863
- darkMode: darkMode,
2864
- subMenu: item.children,
2865
- children: item.label
2866
- }, index);
2867
- }
2868
- })
2869
- }));
2870
- }
2871
- function Divider({
2872
- title
2873
- }) {
2874
- return jsxRuntime.jsx("div", {
2875
- px: "2",
2876
- mt: "5",
2877
- mb: "2",
2878
- opacity: "75",
2879
- textTransform: "capitalize",
2880
- letterSpacing: "widest",
2881
- fontWeight: "700",
2882
- textSize: "xs",
2883
- children: title
2884
- });
2885
- }
2886
-
2887
- function UserBlock({
2888
- color,
2889
- darkMode,
2890
- menuConfig,
2891
- path
2892
- }) {
2893
- var _a, _b;
2894
- const {
2895
- isLoading,
2896
- user
2897
- } = auth.useSessionUser();
2898
- const navigate = reactRouterDom.useNavigate();
2899
- const handleClick = React.useCallback(() => navigate(path), [navigate, path]);
2900
- if (isLoading) return null;
2901
- return jsxRuntime.jsxs("div", {
2902
- dflex: true,
2903
- alignItems: "center",
2904
- border: "0.5",
2905
- borderColor: `${color}-${darkMode ? "800" : "200"}`,
2906
- ps: "3",
2907
- py: "1.5",
2908
- textSize: "md",
2909
- rounded: "lg",
2910
- hover_bgColor: `${color}-${darkMode ? "800" : "200"}`,
2911
- cursor: "pointer",
2912
- textColor: darkMode ? "white" : "slate-800",
2913
- onClick: handleClick,
2914
- children: [jsxRuntime.jsx(ui.Avatar, {
2915
- size: "sm",
2916
- src: (_b = (_a = user === null || user === void 0 ? void 0 : user.media) === null || _a === void 0 ? void 0 : _a.url) !== null && _b !== void 0 ? _b : "",
2917
- name: `${user === null || user === void 0 ? void 0 : user.firstname} ${user === null || user === void 0 ? void 0 : user.lastname}`
2918
- }), jsxRuntime.jsx("span", {
2919
- flexGrow: true,
2920
- ms: "2",
2921
- children: `${capitalize((user === null || user === void 0 ? void 0 : user.firstname) || (user === null || user === void 0 ? void 0 : user.lastname) || "")}`
2922
- }), jsxRuntime.jsx(ui.IconButton, {
2923
- variant: "borderless",
2924
- corners: "pill",
2925
- scheme: "dark",
2926
- textColor: darkMode ? "white" : "slate-800",
2927
- hover_textColor: darkMode ? "white" : "slate-800",
2928
- hover_bgColor: `${color}-${darkMode ? "900" : "200"}`,
2929
- icon: mdiCog,
2930
- onClick: handleClick
2931
- }), jsxRuntime.jsx(OverflowMenu, {
2932
- color: color,
2933
- darkMode: darkMode,
2934
- menuConfig: menuConfig
2935
- })]
2936
- });
2937
- }
2938
- function OverflowMenu({
2939
- color,
2940
- darkMode,
2941
- menuConfig
2942
- }) {
2943
- const [showPopup, setShowPopup] = React.useState(false);
2944
- const navigate = reactRouterDom.useNavigate();
2945
- const logout = auth.useSessionLogout(false);
2946
- return jsxRuntime.jsx(jsxRuntime.Fragment, {
2947
- children: jsxRuntime.jsxs(ui.Popup, {
2948
- show: showPopup,
2949
- position: "relative",
2950
- side: "bottom-end",
2951
- onClick: e => {
2952
- e.preventDefault();
2953
- e.stopPropagation();
2954
- setShowPopup(show => !show);
2955
- },
2956
- onHide: () => setShowPopup(false),
2957
- children: [jsxRuntime.jsx(ui.IconButton, {
2958
- icon: mdiDotsVertical,
2959
- variant: "borderless",
2960
- corners: "pill",
2961
- scheme: "dark",
2962
- textColor: darkMode ? "white" : "slate-800",
2963
- hover_textColor: darkMode ? "white" : "slate-800",
2964
- hover_bgColor: `${color}-${darkMode ? "900" : "200"}`
2965
- }), jsxRuntime.jsxs("div", {
2966
- bgColor: "white",
2967
- rounded: "sm",
2968
- overflow: "hidden",
2969
- shadow: true,
2970
- mt: "1",
2971
- border: "px",
2972
- borderColor: "gray-200",
2973
- divideColor: "gray-200",
2974
- divideY: "px",
2975
- minW: "40",
2976
- children: [menuConfig && menuConfig.length > 0 && menuConfig.map((item, index) => {
2977
- if (item.type == "item") {
2978
- return jsxRuntime.jsx(MenuItem, {
2979
- icon: item.icon,
2980
- onClick: () => navigate(item.path),
2981
- children: item.label
2982
- }, index);
2983
- }
2984
- return null;
2985
- }), jsxRuntime.jsx(MenuItem, {
2986
- icon: mdiLogout,
2987
- onClick: logout,
2988
- children: "Logout"
2989
- })]
2990
- })]
2991
- })
2992
- });
2993
- }
2994
- function MenuItem(_a) {
2995
- var {
2996
- icon,
2997
- onClick,
2998
- children
2999
- } = _a,
3000
- props = tslib.__rest(_a, ["icon", "onClick", "children"]);
3001
- const handleClick = React.useCallback(e => {
3002
- e.preventDefault();
3003
- e.stopPropagation();
3004
- onClick === null || onClick === void 0 ? void 0 : onClick(e);
3005
- }, []);
3006
- return jsxRuntime.jsxs(ui.Button, Object.assign({
3007
- variant: "borderless",
3008
- scheme: "dark",
3009
- size: "sm",
3010
- alignItems: "center",
3011
- dflex: true,
3012
- gap: "2",
3013
- px: "2",
3014
- py: "1.5",
3015
- w: "full",
3016
- onClick: handleClick,
3017
- textColor: "slate-700"
3018
- }, props, {
3019
- children: [icon && jsxRuntime.jsx(ui.Icon, {
3020
- path: icon,
3021
- size: "md"
3022
- }), children]
3023
- }));
3024
- }
3025
-
3026
- function Sidebar(_a) {
3027
- var {
3028
- show,
3029
- logo,
3030
- title,
3031
- menuConfig,
3032
- userMenuConfig,
3033
- userSettingsPath,
3034
- color,
3035
- darkMode
3036
- } = _a,
3037
- props = tslib.__rest(_a, ["show", "logo", "title", "menuConfig", "userMenuConfig", "userSettingsPath", "color", "darkMode"]);
3038
- return jsxRuntime.jsxs("div", Object.assign({
3039
- dflex: true,
3040
- flexCol: true,
3041
- w: "full",
3042
- md_w: "64",
3043
- minH: "screen",
3044
- p: "0",
3045
- textColor: darkMode ? "white" : "slate-800"
3046
- }, props, {
3047
- children: [jsxRuntime.jsxs(components.FlexCenter, {
3048
- placeContent: "start",
3049
- p: "4",
3050
- font: "title",
3051
- gap: "3",
3052
- borderB: "px",
3053
- borderBColor: "slate-900",
3054
- borderOpacity: "5",
3055
- children: [logo !== null && logo !== void 0 ? logo : jsxRuntime.jsx(Logo, {
3056
- width: 40,
3057
- height: 40,
3058
- darkMode: darkMode
3059
- }), jsxRuntime.jsx("h1", {
3060
- textSize: "md",
3061
- children: title || env.AppEnv.appName()
3062
- })]
3063
- }), jsxRuntime.jsx(Menu, {
3064
- overflowY: "auto",
3065
- flexGrow: "1",
3066
- p: "4",
3067
- darkMode: darkMode,
3068
- config: menuConfig
3069
- }), jsxRuntime.jsx("div", {
3070
- p: "2",
3071
- children: jsxRuntime.jsx(UserBlock, {
3072
- darkMode: darkMode,
3073
- color: color,
3074
- menuConfig: userMenuConfig,
3075
- path: userSettingsPath
3076
- })
3077
- })]
3078
- }));
3079
- }
3080
- function Logo(_a) {
3081
- var {
3082
- width,
3083
- height,
3084
- darkMode
3085
- } = _a,
3086
- props = tslib.__rest(_a, ["width", "height", "darkMode"]);
3087
- return jsxRuntime.jsx("div", Object.assign({}, props, {
3088
- children: jsxRuntime.jsx(Image, {
3089
- src: `/logo_${darkMode ? "light" : "dark"}.png`,
3090
- alt: env.AppEnv.appName(),
3091
- width: width,
3092
- height: height,
3093
- priority: true,
3094
- unoptimized: true
3095
- })
3096
- }));
3097
- }
3098
-
3099
- function AdminLayout(_a) {
3100
- var {
3101
- color,
3102
- darkMode,
3103
- logo,
3104
- title,
3105
- menuConfig,
3106
- userMenuConfig,
3107
- userSettingsPath
3108
- } = _a,
3109
- props = tslib.__rest(_a, ["color", "darkMode", "logo", "title", "menuConfig", "userMenuConfig", "userSettingsPath"]);
3110
- return jsxRuntime.jsxs("div", Object.assign({
3111
- w: "full",
3112
- h: "screen",
3113
- dflex: true,
3114
- flexRow: true,
3115
- bgColor: `${color}-${darkMode ? "900" : "100"}`
3116
- }, props, {
3117
- children: [jsxRuntime.jsx(LeftPanel, {
3118
- color: color,
3119
- darkMode: darkMode,
3120
- logo: logo,
3121
- title: title,
3122
- menuConfig: menuConfig,
3123
- userMenuConfig: userMenuConfig,
3124
- userSettingsPath: userSettingsPath
3125
- }), jsxRuntime.jsx("div", {
3126
- w: "screen",
3127
- py: "2",
3128
- pe: "2",
3129
- children: jsxRuntime.jsx(Content, {
3130
- bgColor: "white",
3131
- rounded: "lg",
3132
- shadow: true
3133
- })
3134
- })]
3135
- }));
3136
- }
3137
- function LeftPanel({
3138
- color,
3139
- darkMode,
3140
- logo,
3141
- title,
3142
- menuConfig,
3143
- userMenuConfig,
3144
- userSettingsPath
3145
- }) {
3146
- const [isOpen, __, toggle] = hooks.useBoolean(true);
3147
- fe('ctrl+t', () => toggle(), [toggle]);
3148
- return jsxRuntime.jsxs("div", {
3149
- ms: isOpen ? "0" : "-14.5rem",
3150
- transition: "all",
3151
- duration: "500",
3152
- transform: true,
3153
- children: [jsxRuntime.jsx(Sidebar, {
3154
- flexShrink: "0",
3155
- color: color,
3156
- darkMode: darkMode,
3157
- logo: logo,
3158
- title: title,
3159
- menuConfig: menuConfig,
3160
- userMenuConfig: userMenuConfig,
3161
- userSettingsPath: userSettingsPath
3162
- }), jsxRuntime.jsx(ui.IconButton, {
3163
- icon: mdiArrowLeft,
3164
- transition: "all",
3165
- duration: "500",
3166
- transform: true,
3167
- rotate: isOpen ? "0" : "180",
3168
- position: "absolute",
3169
- bottom: "14",
3170
- end: "-5",
3171
- size: "lg",
3172
- corners: "pill",
3173
- onClick: toggle,
3174
- z: "100"
3175
- })]
3176
- });
3177
- }
3178
-
3179
- const defaultErrorMsg = "Oops, something went wrong...";
3180
- function AttachDialog(_a) {
3181
- var {
3182
- queryId,
3183
- queryKey,
3184
- queryFetchFn,
3185
- queryFetchAllKey,
3186
- queryFetchAllFn,
3187
- querySaveFn,
3188
- matchKey,
3189
- size = "lg",
3190
- show,
3191
- onClose,
3192
- itemLabel,
3193
- onSuccess,
3194
- onFetchError,
3195
- fetchErrorMsg = defaultErrorMsg,
3196
- onSaveError,
3197
- saveErrorMsg = defaultErrorMsg,
3198
- invalidateQueriesOnSuccess = true,
3199
- retryText = "Retry",
3200
- cancelLabel = "Cancel",
3201
- saveLabel,
3202
- formikProps,
3203
- getItemName
3204
- } = _a,
3205
- props = tslib.__rest(_a, ["queryId", "queryKey", "queryFetchFn", "queryFetchAllKey", "queryFetchAllFn", "querySaveFn", "matchKey", "size", "show", "onClose", "itemLabel", "onSuccess", "onFetchError", "fetchErrorMsg", "onSaveError", "saveErrorMsg", "invalidateQueriesOnSuccess", "retryText", "cancelLabel", "saveLabel", "formikProps", "getItemName"]);
3206
- const queryClient = reactQuery.useQueryClient();
3207
- const {
3208
- data: attached,
3209
- isInitialLoading: fetchLoading,
3210
- isError: fetchError,
3211
- refetch,
3212
- error
3213
- } = api.useApiQuery(queryKey, queryFetchFn);
3214
- const {
3215
- data,
3216
- isInitialLoading: fetchAllLoading,
3217
- isError: fetchAllError,
3218
- refetch: refetchAll,
3219
- error: errorAll
3220
- } = api.useApiQuery(queryFetchAllKey, queryFetchAllFn);
3221
- const [selectedResources, setSelectedResources] = React.useState([]);
3222
- const isLoading = fetchLoading || fetchAllLoading;
3223
- const isError = fetchError || fetchAllError;
3224
- const mutation = api.useApiMutation(querySaveFn, queryKey, queryId);
3225
- const handleClick = React.useCallback(event => {
3226
- var _a;
3227
- const id = (_a = event === null || event === void 0 ? void 0 : event.currentTarget.dataset.id) !== null && _a !== void 0 ? _a : "";
3228
- const arr = selectedResources.concat([]);
3229
- const i = selectedResources.indexOf(id);
3230
- if (i != -1) arr.splice(i, 1);else arr.push(id);
3231
- setSelectedResources(arr);
3232
- }, [selectedResources, setSelectedResources]);
3233
- const retry = React.useCallback(() => {
3234
- if (fetchError) refetch();
3235
- if (fetchAllError) refetchAll();
3236
- }, [refetch, refetchAll, fetchError, fetchAllError]);
3237
- const saveItem = React.useCallback(() => {
3238
- // Clear mutation error if any
3239
- mutation.reset();
3240
- mutation.mutateAsync({
3241
- resources: selectedResources
3242
- }).then(response => {
3243
- if (onSuccess) onSuccess(response);else reactToastify.toast.success(`${itemLabel} saved`);
3244
- if (invalidateQueriesOnSuccess) queryClient.invalidateQueries({
3245
- queryKey: queryKey
3246
- });
3247
- // closing delete modal
3248
- onClose === null || onClose === void 0 ? void 0 : onClose();
3249
- }).catch(error => {
3250
- console.error("on error", error);
3251
- if (onSaveError) onSaveError();else reactToastify.toast.error(`Error adding ${itemLabel}`);
3252
- });
3253
- }, [mutation, queryId, onSuccess, queryClient, onSaveError, onClose]);
3254
- const resources = React.useMemo(() => {
3255
- let r = [];
3256
- if (attached && data) {
3257
- r = [].concat(data);
3258
- attached.forEach(attachedItem => r.splice(r.findIndex(item => item.id == attachedItem[matchKey]), 1));
3259
- // TODO set keyField for name (could be title for example)
3260
- if (getItemName) r = r.map(item => {
3261
- return Object.assign(Object.assign({}, item), {
3262
- name: getItemName(item)
3263
- });
3264
- });
3265
- r = sortBy(r, ["name"]);
3266
- }
3267
- return r;
3268
- }, [attached, data]);
3269
- return jsxRuntime.jsxs(ui.Modal, Object.assign({
3270
- size: size,
3271
- show: show,
3272
- onClose: onClose,
3273
- scheme: "light",
3274
- transition: true
3275
- }, props, {
3276
- children: [jsxRuntime.jsx(ui.Modal.Header, {
3277
- children: `Add ${itemLabel}`
3278
- }), isLoading && jsxRuntime.jsx(ui.Modal.Body, {
3279
- children: jsxRuntime.jsx(components.QueryLoadingState, {
3280
- minW: "72"
3281
- })
3282
- }), isError && jsxRuntime.jsx(ui.Modal.Body, {
3283
- children: jsxRuntime.jsx(components.RetryOnError, {
3284
- label: `${fetchErrorMsg} ${error}`,
3285
- onClick: retry
3286
- })
3287
- }), !isLoading && !isError && jsxRuntime.jsxs(jsxRuntime.Fragment, {
3288
- children: [jsxRuntime.jsx(ui.Modal.Body, {
3289
- px: "0",
3290
- pb: "6",
3291
- maxH: "750px",
3292
- overflow: "auto",
3293
- children: jsxRuntime.jsx("div", {
3294
- dflex: true,
3295
- flexCol: true,
3296
- overflow: "auto",
3297
- children: resources.map(item => jsxRuntime.jsx(ListItem, {
3298
- label: item.name,
3299
- value: item.id,
3300
- "data-id": item.id,
3301
- checked: selectedResources.includes(`${item.id}`),
3302
- onClick: handleClick
3303
- }, item.id))
3304
- })
3305
- }), jsxRuntime.jsxs(ui.Modal.Footer, {
3306
- dflex: true,
3307
- placeContent: "end",
3308
- spaceX: "3",
3309
- children: [jsxRuntime.jsx(ui.Button, {
3310
- disabled: mutation.isLoading,
3311
- onClick: onClose,
3312
- variant: "borderless",
3313
- me: "2",
3314
- children: cancelLabel
3315
- }), jsxRuntime.jsx(ui.Button, {
3316
- type: "submit",
3317
- disabled: selectedResources.length == 0 || mutation.isLoading /* || !isValid*/,
3318
- onClick: saveItem,
3319
- children: saveLabel ? saveLabel : queryId ? "Update" : "Create"
3320
- })]
3321
- })]
3322
- }), mutation.isLoading && jsxRuntime.jsx(components.ModalLoadingOverlay, {})]
3323
- }));
3324
- }
3325
- function ListItem(_a) {
3326
- var {
3327
- label,
3328
- value,
3329
- checked
3330
- } = _a,
3331
- props = tslib.__rest(_a, ["label", "value", "checked"]);
3332
- return jsxRuntime.jsxs("div", Object.assign({
3333
- dflex: true,
3334
- alignItems: "center",
3335
- hover_bgColor: "slate-100",
3336
- px: "5",
3337
- py: "2",
3338
- cursor: "pointer"
3339
- }, props, {
3340
- children: [jsxRuntime.jsx("span", {
3341
- flexGrow: true,
3342
- children: label
3343
- }), jsxRuntime.jsx(ui.Checkbox, {
3344
- name: `resources.${value}`,
3345
- value: value,
3346
- checked: checked
3347
- })]
3348
- }));
3349
- }
3350
-
3351
- function FormActionDialog(_a) {
3352
- var {
3353
- initialValues,
3354
- itemLabel,
3355
- queryId = "",
3356
- queryKey,
3357
- queryFn,
3358
- queryOptions,
3359
- onSuccess,
3360
- successMsg,
3361
- showSuccessMsg,
3362
- onError,
3363
- errorMsg,
3364
- showErrorMsg,
3365
- processInput,
3366
- invalidateQueriesOnSuccess = true,
3367
- cancelLabel = "Cancel",
3368
- saveLabel = "Send",
3369
- size = "lg",
3370
- title,
3371
- form: form$1,
3372
- show,
3373
- onClose,
3374
- formikProps
3375
- } = _a,
3376
- props = tslib.__rest(_a, ["initialValues", "itemLabel", "queryId", "queryKey", "queryFn", "queryOptions", "onSuccess", "successMsg", "showSuccessMsg", "onError", "errorMsg", "showErrorMsg", "processInput", "invalidateQueriesOnSuccess", "cancelLabel", "saveLabel", "size", "title", "form", "show", "onClose", "formikProps"]);
3377
- const mutation = invalidateQueriesOnSuccess ? api.useInvalidateParentMutation(queryFn, queryKey, queryOptions) : api.useApiMutation(queryFn, queryKey, queryId, queryOptions);
3378
- const mutate = api.useMutate(mutation, {
3379
- onSuccess,
3380
- successMsg,
3381
- showSuccessMsg,
3382
- onError,
3383
- errorMsg,
3384
- showErrorMsg,
3385
- processInput
3386
- });
3387
- return jsxRuntime.jsxs(ui.Modal, Object.assign({
3388
- size: size,
3389
- show: show,
3390
- onClose: onClose,
3391
- scheme: "light",
3392
- transition: true
3393
- }, props, {
3394
- children: [jsxRuntime.jsx(ui.Modal.Header, {
3395
- children: title
3396
- }), jsxRuntime.jsxs(form.FormProvider, Object.assign({
3397
- initialValues: initialValues !== null && initialValues !== void 0 ? initialValues : {},
3398
- onSubmit: mutate
3399
- }, formikProps, {
3400
- children: [jsxRuntime.jsxs(ui.Modal.Body, {
3401
- pb: "6",
3402
- children: [/*#__PURE__*/React.isValidElement(form$1) && form$1, Array.isArray(form$1) && jsxRuntime.jsx(form.FormRenderer, {
3403
- form: form$1
3404
- })]
3405
- }), jsxRuntime.jsxs(ui.Modal.Footer, {
3406
- dflex: true,
3407
- placeContent: "end",
3408
- spaceX: "3",
3409
- children: [jsxRuntime.jsx(ui.Button, {
3410
- disabled: mutation.isLoading,
3411
- onClick: onClose,
3412
- variant: "borderless",
3413
- me: "2",
3414
- children: cancelLabel
3415
- }), jsxRuntime.jsx(form.SubmitButton, {
3416
- disabled: mutation.isLoading,
3417
- children: saveLabel
3418
- })]
3419
- })]
3420
- })), mutation.isLoading && jsxRuntime.jsx(components.ModalLoadingOverlay, {})]
3421
- }));
3422
- }
3423
-
3424
- function PageSectionTitle(_a) {
3425
- var {
3426
- children
3427
- } = _a,
3428
- props = tslib.__rest(_a, ["children"]);
3429
- return jsxRuntime.jsx("div", Object.assign({
3430
- trait: "typo.h6",
3431
- mb: "5"
3432
- }, props, {
3433
- children: children
3434
- }));
3435
- }
3436
-
3437
- const PageStateContainer = /*#__PURE__*/React.forwardRef((_a, ref) => {
3438
- var {
3439
- loading = false,
3440
- children
3441
- } = _a,
3442
- props = tslib.__rest(_a, ["loading", "children"]);
3443
- return jsxRuntime.jsxs(jsxRuntime.Fragment, {
3444
- children: [loading && jsxRuntime.jsx(components.QueryLoadingState, {
3445
- w: "full",
3446
- h: "100%"
3447
- }), !loading && jsxRuntime.jsx(ui.Container, Object.assign({
3448
- ref: ref,
3449
- center: true,
3450
- size: "x2",
3451
- dflex: true,
3452
- flexCol: true,
3453
- gap: "8"
3454
- }, props, {
3455
- children: children
3456
- }))]
3457
- });
3458
- });
3459
-
3460
- function PageSubSectionTitle(_a) {
3461
- var {
3462
- children
3463
- } = _a,
3464
- props = tslib.__rest(_a, ["children"]);
3465
- return jsxRuntime.jsx("div", Object.assign({
3466
- trait: "typo.h6",
3467
- mb: "3"
3468
- }, props, {
3469
- children: children
3470
- }));
3471
- }
3472
-
3473
- const labels = {
3474
- draft: "Draft",
3475
- published: "Published",
3476
- pending: "Pending",
3477
- approved: "Approved",
3478
- partially_approved: "Partially Approved",
3479
- rejected: "Rejected"
3480
- };
3481
- const schemes = {
3482
- draft: "warning",
3483
- published: "success",
3484
- pending: "secondary",
3485
- approved: "success",
3486
- partially_approved: "warning",
3487
- rejected: "danger"
3488
- };
3489
- function StatusBadge(_a) {
3490
- var {
3491
- status
3492
- } = _a,
3493
- props = tslib.__rest(_a, ["status"]);
3494
- return jsxRuntime.jsx(ui.Badge, Object.assign({
3495
- size: "sm",
3496
- variant: "glass",
3497
- whiteSpace: "nowrap",
3498
- rounded: "full",
3499
- px: "3",
3500
- scheme: schemes[status]
3501
- }, props, {
3502
- children: labels[status]
3503
- }));
3504
- }
3505
-
3506
- function TableRowActionButton(_a) {
3507
- var {
3508
- icon,
3509
- children
3510
- } = _a,
3511
- props = tslib.__rest(_a, ["icon", "children"]);
3512
- return jsxRuntime.jsxs(ui.Button, Object.assign({
3513
- dflex: true,
3514
- alignContent: "center",
3515
- placeContent: "center",
3516
- py: "2.5",
3517
- px: "3",
3518
- h: "full",
3519
- size: "lg",
3520
- variant: "borderless",
3521
- corners: "square",
3522
- gap: "2"
3523
- }, props, {
3524
- children: [icon && jsxRuntime.jsx(ui.Icon, {
3525
- path: icon,
3526
- size: "sm"
3527
- }), children]
3528
- }));
3529
- }
3530
-
3531
- function TableRowViewButton(_a) {
3532
- var {
3533
- path
3534
- } = _a,
3535
- props = tslib.__rest(_a, ["path"]);
3536
- const openPage = React.useCallback(event => {
3537
- event === null || event === void 0 ? void 0 : event.preventDefault();
3538
- event === null || event === void 0 ? void 0 : event.stopPropagation();
3539
- window.open(`${env.AppEnv.websiteUrl()}/${path}`, '_blank');
3540
- }, [path]);
3541
- return jsxRuntime.jsx(TableRowActionButton, Object.assign({
3542
- icon: mdiOpenInNew,
3543
- onClick: openPage
3544
- }, props));
3545
- }
3546
-
3547
- function TableRowNavigateButton(_a) {
3548
- var {
3549
- path
3550
- } = _a,
3551
- props = tslib.__rest(_a, ["path"]);
3552
- const navigate = reactRouterDom.useNavigate();
3553
- const handleClick = React.useCallback(event => {
3554
- event === null || event === void 0 ? void 0 : event.preventDefault();
3555
- event === null || event === void 0 ? void 0 : event.stopPropagation();
3556
- navigate(`${path}`);
3557
- }, [navigate, path]);
3558
- return jsxRuntime.jsx(TableRowActionButton, Object.assign({
3559
- icon: mdiEye,
3560
- onClick: handleClick
3561
- }, props));
3562
- }
3563
-
3564
- function TableRowActionDialogButton(_a) {
3565
- var {
3566
- icon,
3567
- children
3568
- } = _a,
3569
- props = tslib.__rest(_a, ["icon", "children"]);
3570
- return jsxRuntime.jsxs(admin.DialogButton, Object.assign({
3571
- dflex: true,
3572
- alignContent: "center",
3573
- placeContent: "center",
3574
- py: "2.5",
3575
- px: "3",
3576
- h: "full",
3577
- size: "lg",
3578
- variant: "borderless",
3579
- corners: "square",
3580
- gap: "2"
3581
- }, props, {
3582
- children: [icon && jsxRuntime.jsx(ui.Icon, {
3583
- path: icon,
3584
- size: "sm"
3585
- }), children]
3586
- }));
3587
- }
3588
-
3589
- function TableRowEditButton(_a) {
3590
- var {
3591
- children
3592
- } = _a,
3593
- props = tslib.__rest(_a, ["children"]);
3594
- return jsxRuntime.jsx(TableRowActionDialogButton, Object.assign({
3595
- icon: mdiPencil
3596
- }, props, {
3597
- children: children
3598
- }));
3599
- }
3600
-
3601
- function TableRowDeleteButton(_a) {
3602
- var {
3603
- children
3604
- } = _a,
3605
- props = tslib.__rest(_a, ["children"]);
3606
- return jsxRuntime.jsx(TableRowActionDialogButton, Object.assign({
3607
- icon: mdiDelete
3608
- }, props, {
3609
- children: children
3610
- }));
3611
- }
3612
-
3613
- function TableRowActionBar(_a) {
3614
- var {
3615
- publishId,
3616
- viewPath,
3617
- navigatePath,
3618
- editDialog,
3619
- deleteDialog,
3620
- children
3621
- } = _a,
3622
- props = tslib.__rest(_a, ["publishId", "viewPath", "navigatePath", "editDialog", "deleteDialog", "children"]);
3623
- return jsxRuntime.jsxs("div", Object.assign({
3624
- dflex: true,
3625
- spaceX: "1",
3626
- placeContent: "end"
3627
- }, props, {
3628
- children: [viewPath && jsxRuntime.jsx(TableRowViewButton, {
3629
- path: viewPath
3630
- }), navigatePath && jsxRuntime.jsx(TableRowNavigateButton, {
3631
- path: navigatePath
3632
- }), editDialog && jsxRuntime.jsx(TableRowEditButton, {
3633
- buildDialog: editDialog
3634
- }), deleteDialog && jsxRuntime.jsx(TableRowDeleteButton, {
3635
- buildDialog: deleteDialog
3636
- }), children]
3637
- }));
3638
- }
3639
-
3640
- function TableRowPublishPostButton(_a) {
3641
- var {
3642
- id,
3643
- api: api$1,
3644
- status,
3645
- invalidateQueryKey
3646
- } = _a,
3647
- props = tslib.__rest(_a, ["id", "api", "status", "invalidateQueryKey"]);
3648
- const isDraft = status == "draft";
3649
- const mutation = api.useInvalidateParentMutation(isDraft ? api$1.publish : api$1.unpublish, invalidateQueryKey !== null && invalidateQueryKey !== void 0 ? invalidateQueryKey : api$1.queryKey, {
3650
- networkMode: "always"
3651
- });
3652
- const publish = React.useCallback(event => {
3653
- event === null || event === void 0 ? void 0 : event.preventDefault();
3654
- event === null || event === void 0 ? void 0 : event.stopPropagation();
3655
- mutation.reset();
3656
- mutation.mutateAsync(id).then(() => reactToastify.toast.success(isDraft ? "Published!" : "Unpublished!")).catch(error => reactToastify.toast.error(`Error: ${error}`));
3657
- }, [mutation, id]);
3658
- return jsxRuntime.jsx(TableRowActionButton, Object.assign({
3659
- icon: isDraft ? mdiPublish : mdiPublishOff,
3660
- onClick: publish
3661
- }, props));
3662
- }
3663
-
3664
- exports.AdminLayout = AdminLayout;
3665
- exports.AttachDialog = AttachDialog;
3666
- exports.Breadcrumbs = Breadcrumbs;
3667
- exports.ButtonBar = ButtonBar;
3668
- exports.ButtonBarButton = ButtonBarButton;
3669
- exports.ButtonBarDialogButton = ButtonBarDialogButton;
3670
- exports.ButtonBarSubmitButton = ButtonBarSubmitButton;
3671
- exports.DialogButton = DialogButton;
3672
- exports.FormActionDialog = FormActionDialog;
3673
- exports.InvalidateButton = InvalidateButton;
3674
- exports.ItemDeleteDialog = ItemDeleteDialog;
3675
- exports.ItemEditDialog = ItemEditDialog;
3676
- exports.Menu = Menu;
3677
- exports.NavigateButton = NavigateButton;
3678
- exports.OrderCell = OrderCell;
3679
- exports.PageContainer = PageContainer;
3680
- exports.PageContentEditor = PageContentEditor;
3681
- exports.PageMain = PageMain;
3682
- exports.PageQueryStateContainer = PageQueryStateContainer;
3683
- exports.PageSectionTitle = PageSectionTitle;
3684
- exports.PageSidebar = PageSidebar;
3685
- exports.PageSidebarSection = PageSidebarSection;
3686
- exports.PageStateContainer = PageStateContainer;
3687
- exports.PageSubSectionTitle = PageSubSectionTitle;
3688
- exports.PageTabbedTopBar = PageTabbedTopBar;
3689
- exports.PageTabbedTopBarProvider = PageTabbedTopBarProvider;
3690
- exports.PageTitle = PageTitle;
3691
- exports.PageTopBar = PageTopBar;
3692
- exports.PageTopBarToolbar = PageTopBarToolbar;
3693
- exports.PublishButton = PublishButton;
3694
- exports.ScreenRenderer = ScreenRenderer;
3695
- exports.SectionTitle = SectionTitle;
3696
- exports.StatusBadge = StatusBadge;
3697
- exports.TableContainer = TableContainer;
3698
- exports.TableCreateButton = TableCreateButton;
3699
- exports.TableFilterButton = TableFilterButton;
3700
- exports.TableRowActionBar = TableRowActionBar;
3701
- exports.TableRowActionButton = TableRowActionButton;
3702
- exports.TableRowActionDialogButton = TableRowActionDialogButton;
3703
- exports.TableRowDeleteButton = TableRowDeleteButton;
3704
- exports.TableRowEditButton = TableRowEditButton;
3705
- exports.TableRowNavigateButton = TableRowNavigateButton;
3706
- exports.TableRowPublishPostButton = TableRowPublishPostButton;
3707
- exports.TableRowViewButton = TableRowViewButton;
3708
- exports.TableTopBar = TableTopBar;
3709
- exports.UpdateButton = UpdateButton;
3710
- exports.ViewButton = ViewButton;