nuxt-ui-tools 1.0.1 → 1.2.0

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 (258) hide show
  1. package/dist/module.d.mts +3 -0
  2. package/dist/module.json +1 -1
  3. package/dist/module.mjs +37 -0
  4. package/dist/runtime/dashboard/components/block/dashboard-block-state.d.vue.ts +12 -0
  5. package/dist/runtime/dashboard/components/block/dashboard-block-state.vue +59 -0
  6. package/dist/runtime/dashboard/components/block/dashboard-block-state.vue.d.ts +12 -0
  7. package/dist/runtime/dashboard/components/block/dashboard-data-table.d.vue.ts +9 -0
  8. package/dist/runtime/dashboard/components/block/dashboard-data-table.vue +47 -0
  9. package/dist/runtime/dashboard/components/block/dashboard-data-table.vue.d.ts +9 -0
  10. package/dist/runtime/dashboard/components/block/dashboard-ring.d.vue.ts +34 -0
  11. package/dist/runtime/dashboard/components/block/dashboard-ring.vue +91 -0
  12. package/dist/runtime/dashboard/components/block/dashboard-ring.vue.d.ts +34 -0
  13. package/dist/runtime/dashboard/components/block/dashboard-row-actions.d.vue.ts +13 -0
  14. package/dist/runtime/dashboard/components/block/dashboard-row-actions.vue +49 -0
  15. package/dist/runtime/dashboard/components/block/dashboard-row-actions.vue.d.ts +13 -0
  16. package/dist/runtime/dashboard/components/block/dashboard-skeleton.d.vue.ts +34 -0
  17. package/dist/runtime/dashboard/components/block/dashboard-skeleton.vue +315 -0
  18. package/dist/runtime/dashboard/components/block/dashboard-skeleton.vue.d.ts +34 -0
  19. package/dist/runtime/dashboard/components/charts/renderer.d.ts +43 -0
  20. package/dist/runtime/dashboard/components/charts/renderer.js +34 -0
  21. package/dist/runtime/dashboard/components/charts/unovis/dashboard-donut-chart.d.vue.ts +18 -0
  22. package/dist/runtime/dashboard/components/charts/unovis/dashboard-donut-chart.vue +45 -0
  23. package/dist/runtime/dashboard/components/charts/unovis/dashboard-donut-chart.vue.d.ts +18 -0
  24. package/dist/runtime/dashboard/components/charts/unovis/dashboard-xy-chart.d.vue.ts +14 -0
  25. package/dist/runtime/dashboard/components/charts/unovis/dashboard-xy-chart.vue +190 -0
  26. package/dist/runtime/dashboard/components/charts/unovis/dashboard-xy-chart.vue.d.ts +14 -0
  27. package/dist/runtime/dashboard/components/charts/unovis/dashboard-xy-marks.d.vue.ts +13 -0
  28. package/dist/runtime/dashboard/components/charts/unovis/dashboard-xy-marks.vue +72 -0
  29. package/dist/runtime/dashboard/components/charts/unovis/dashboard-xy-marks.vue.d.ts +13 -0
  30. package/dist/runtime/dashboard/components/charts/unovis/xy-layers.d.ts +43 -0
  31. package/dist/runtime/dashboard/components/charts/unovis/xy-layers.js +60 -0
  32. package/dist/runtime/dashboard/components/dashboard-alerts.d.vue.ts +49 -0
  33. package/dist/runtime/dashboard/components/dashboard-alerts.vue +226 -0
  34. package/dist/runtime/dashboard/components/dashboard-alerts.vue.d.ts +49 -0
  35. package/dist/runtime/dashboard/components/dashboard-bar-chart.d.vue.ts +53 -0
  36. package/dist/runtime/dashboard/components/dashboard-bar-chart.vue +131 -0
  37. package/dist/runtime/dashboard/components/dashboard-bar-chart.vue.d.ts +53 -0
  38. package/dist/runtime/dashboard/components/dashboard-bars.d.vue.ts +49 -0
  39. package/dist/runtime/dashboard/components/dashboard-bars.vue +187 -0
  40. package/dist/runtime/dashboard/components/dashboard-bars.vue.d.ts +49 -0
  41. package/dist/runtime/dashboard/components/dashboard-card.d.vue.ts +47 -0
  42. package/dist/runtime/dashboard/components/dashboard-card.vue +316 -0
  43. package/dist/runtime/dashboard/components/dashboard-card.vue.d.ts +47 -0
  44. package/dist/runtime/dashboard/components/dashboard-combo-chart.d.vue.ts +52 -0
  45. package/dist/runtime/dashboard/components/dashboard-combo-chart.vue +128 -0
  46. package/dist/runtime/dashboard/components/dashboard-combo-chart.vue.d.ts +52 -0
  47. package/dist/runtime/dashboard/components/dashboard-donut-chart.d.vue.ts +48 -0
  48. package/dist/runtime/dashboard/components/dashboard-donut-chart.vue +216 -0
  49. package/dist/runtime/dashboard/components/dashboard-donut-chart.vue.d.ts +48 -0
  50. package/dist/runtime/dashboard/components/dashboard-feed.d.vue.ts +49 -0
  51. package/dist/runtime/dashboard/components/dashboard-feed.vue +239 -0
  52. package/dist/runtime/dashboard/components/dashboard-feed.vue.d.ts +49 -0
  53. package/dist/runtime/dashboard/components/dashboard-funnel.d.vue.ts +34 -0
  54. package/dist/runtime/dashboard/components/dashboard-funnel.vue +157 -0
  55. package/dist/runtime/dashboard/components/dashboard-funnel.vue.d.ts +34 -0
  56. package/dist/runtime/dashboard/components/dashboard-gauge.d.vue.ts +55 -0
  57. package/dist/runtime/dashboard/components/dashboard-gauge.vue +177 -0
  58. package/dist/runtime/dashboard/components/dashboard-gauge.vue.d.ts +55 -0
  59. package/dist/runtime/dashboard/components/dashboard-grid.d.vue.ts +38 -0
  60. package/dist/runtime/dashboard/components/dashboard-grid.vue +49 -0
  61. package/dist/runtime/dashboard/components/dashboard-grid.vue.d.ts +38 -0
  62. package/dist/runtime/dashboard/components/dashboard-legend.d.vue.ts +8 -0
  63. package/dist/runtime/dashboard/components/dashboard-legend.vue +37 -0
  64. package/dist/runtime/dashboard/components/dashboard-legend.vue.d.ts +8 -0
  65. package/dist/runtime/dashboard/components/dashboard-line-chart.d.vue.ts +46 -0
  66. package/dist/runtime/dashboard/components/dashboard-line-chart.vue +129 -0
  67. package/dist/runtime/dashboard/components/dashboard-line-chart.vue.d.ts +46 -0
  68. package/dist/runtime/dashboard/components/dashboard-list.d.vue.ts +63 -0
  69. package/dist/runtime/dashboard/components/dashboard-list.vue +239 -0
  70. package/dist/runtime/dashboard/components/dashboard-list.vue.d.ts +63 -0
  71. package/dist/runtime/dashboard/components/dashboard-paired-bars.d.vue.ts +43 -0
  72. package/dist/runtime/dashboard/components/dashboard-paired-bars.vue +194 -0
  73. package/dist/runtime/dashboard/components/dashboard-paired-bars.vue.d.ts +43 -0
  74. package/dist/runtime/dashboard/components/dashboard-refresh.d.vue.ts +29 -0
  75. package/dist/runtime/dashboard/components/dashboard-refresh.vue +86 -0
  76. package/dist/runtime/dashboard/components/dashboard-refresh.vue.d.ts +29 -0
  77. package/dist/runtime/dashboard/components/dashboard-relative-time.d.vue.ts +12 -0
  78. package/dist/runtime/dashboard/components/dashboard-relative-time.vue +23 -0
  79. package/dist/runtime/dashboard/components/dashboard-relative-time.vue.d.ts +12 -0
  80. package/dist/runtime/dashboard/components/dashboard-stack-bar.d.vue.ts +36 -0
  81. package/dist/runtime/dashboard/components/dashboard-stack-bar.vue +162 -0
  82. package/dist/runtime/dashboard/components/dashboard-stack-bar.vue.d.ts +36 -0
  83. package/dist/runtime/dashboard/components/dashboard-stat.d.vue.ts +69 -0
  84. package/dist/runtime/dashboard/components/dashboard-stat.vue +279 -0
  85. package/dist/runtime/dashboard/components/dashboard-stat.vue.d.ts +69 -0
  86. package/dist/runtime/dashboard/components/dashboard-stats.d.vue.ts +38 -0
  87. package/dist/runtime/dashboard/components/dashboard-stats.vue +202 -0
  88. package/dist/runtime/dashboard/components/dashboard-stats.vue.d.ts +38 -0
  89. package/dist/runtime/dashboard/components/dashboard-table.d.vue.ts +52 -0
  90. package/dist/runtime/dashboard/components/dashboard-table.vue +305 -0
  91. package/dist/runtime/dashboard/components/dashboard-table.vue.d.ts +52 -0
  92. package/dist/runtime/dashboard/components/dashboard-tabs.d.vue.ts +35 -0
  93. package/dist/runtime/dashboard/components/dashboard-tabs.vue +55 -0
  94. package/dist/runtime/dashboard/components/dashboard-tabs.vue.d.ts +35 -0
  95. package/dist/runtime/dashboard/components/dashboard-total.d.vue.ts +10 -0
  96. package/dist/runtime/dashboard/components/dashboard-total.vue +32 -0
  97. package/dist/runtime/dashboard/components/dashboard-total.vue.d.ts +10 -0
  98. package/dist/runtime/dashboard/components/dashboard-widget.d.vue.ts +46 -0
  99. package/dist/runtime/dashboard/components/dashboard-widget.vue +84 -0
  100. package/dist/runtime/dashboard/components/dashboard-widget.vue.d.ts +46 -0
  101. package/dist/runtime/dashboard/composables/use-dashboard-api.d.ts +15 -0
  102. package/dist/runtime/dashboard/composables/use-dashboard-api.js +91 -0
  103. package/dist/runtime/dashboard/composables/use-dashboard-block.d.ts +22 -0
  104. package/dist/runtime/dashboard/composables/use-dashboard-block.js +35 -0
  105. package/dist/runtime/dashboard/composables/use-dashboard-chart.d.ts +36 -0
  106. package/dist/runtime/dashboard/composables/use-dashboard-chart.js +118 -0
  107. package/dist/runtime/dashboard/composables/use-dashboard-derived.d.ts +12 -0
  108. package/dist/runtime/dashboard/composables/use-dashboard-derived.js +47 -0
  109. package/dist/runtime/dashboard/composables/use-dashboard-format.d.ts +6 -0
  110. package/dist/runtime/dashboard/composables/use-dashboard-format.js +12 -0
  111. package/dist/runtime/dashboard/composables/use-dashboard-options.d.ts +8 -0
  112. package/dist/runtime/dashboard/composables/use-dashboard-options.js +63 -0
  113. package/dist/runtime/dashboard/composables/use-dashboard-param-scope.d.ts +30 -0
  114. package/dist/runtime/dashboard/composables/use-dashboard-param-scope.js +71 -0
  115. package/dist/runtime/dashboard/composables/use-dashboard-remote-options.d.ts +12 -0
  116. package/dist/runtime/dashboard/composables/use-dashboard-remote-options.js +117 -0
  117. package/dist/runtime/dashboard/composables/use-dashboard-resource.d.ts +35 -0
  118. package/dist/runtime/dashboard/composables/use-dashboard-resource.js +80 -0
  119. package/dist/runtime/dashboard/composables/use-dashboard-scope.d.ts +46 -0
  120. package/dist/runtime/dashboard/composables/use-dashboard-scope.js +127 -0
  121. package/dist/runtime/dashboard/composables/use-dashboard-time.d.ts +13 -0
  122. package/dist/runtime/dashboard/composables/use-dashboard-time.js +40 -0
  123. package/dist/runtime/dashboard/composables/use-dashboard-ui.d.ts +22 -0
  124. package/dist/runtime/dashboard/composables/use-dashboard-ui.js +19 -0
  125. package/dist/runtime/dashboard/composables/use-dashboard-views.d.ts +46 -0
  126. package/dist/runtime/dashboard/composables/use-dashboard-views.js +49 -0
  127. package/dist/runtime/dashboard/composables/use-dashboard.d.ts +24 -0
  128. package/dist/runtime/dashboard/composables/use-dashboard.js +42 -0
  129. package/dist/runtime/dashboard/constants/query.d.ts +16 -0
  130. package/dist/runtime/dashboard/constants/query.js +15 -0
  131. package/dist/runtime/dashboard/index.d.ts +4 -0
  132. package/dist/runtime/dashboard/index.js +3 -0
  133. package/dist/runtime/dashboard/schema/index.d.ts +57 -0
  134. package/dist/runtime/dashboard/schema/index.js +3 -0
  135. package/dist/runtime/dashboard/types/blocks.d.ts +251 -0
  136. package/dist/runtime/dashboard/types/blocks.js +0 -0
  137. package/dist/runtime/dashboard/types/charts.d.ts +60 -0
  138. package/dist/runtime/dashboard/types/charts.js +0 -0
  139. package/dist/runtime/dashboard/types/index.d.ts +7 -0
  140. package/dist/runtime/dashboard/types/index.js +0 -0
  141. package/dist/runtime/dashboard/types/options.d.ts +46 -0
  142. package/dist/runtime/dashboard/types/options.js +0 -0
  143. package/dist/runtime/dashboard/types/params.d.ts +115 -0
  144. package/dist/runtime/dashboard/types/params.js +0 -0
  145. package/dist/runtime/dashboard/types/resource.d.ts +106 -0
  146. package/dist/runtime/dashboard/types/resource.js +0 -0
  147. package/dist/runtime/dashboard/types/runtime.d.ts +44 -0
  148. package/dist/runtime/dashboard/types/runtime.js +0 -0
  149. package/dist/runtime/dashboard/types/schema.d.ts +171 -0
  150. package/dist/runtime/dashboard/types/schema.js +0 -0
  151. package/dist/runtime/dashboard/types/ui.d.ts +201 -0
  152. package/dist/runtime/dashboard/types/ui.js +0 -0
  153. package/dist/runtime/dashboard/utils/builders/dashboard-params.d.ts +85 -0
  154. package/dist/runtime/dashboard/utils/builders/dashboard-params.js +87 -0
  155. package/dist/runtime/dashboard/utils/chart-frame.d.ts +5 -0
  156. package/dist/runtime/dashboard/utils/chart-frame.js +27 -0
  157. package/dist/runtime/dashboard/utils/charts.d.ts +61 -0
  158. package/dist/runtime/dashboard/utils/charts.js +142 -0
  159. package/dist/runtime/dashboard/utils/comparison.d.ts +15 -0
  160. package/dist/runtime/dashboard/utils/comparison.js +19 -0
  161. package/dist/runtime/dashboard/utils/export.d.ts +13 -0
  162. package/dist/runtime/dashboard/utils/export.js +45 -0
  163. package/dist/runtime/dashboard/utils/options.d.ts +5 -0
  164. package/dist/runtime/dashboard/utils/options.js +18 -0
  165. package/dist/runtime/dashboard/utils/params/codecs.d.ts +14 -0
  166. package/dist/runtime/dashboard/utils/params/codecs.js +69 -0
  167. package/dist/runtime/dashboard/utils/resource.d.ts +16 -0
  168. package/dist/runtime/dashboard/utils/resource.js +39 -0
  169. package/dist/runtime/dashboard/utils/schema.d.ts +9 -0
  170. package/dist/runtime/dashboard/utils/schema.js +31 -0
  171. package/dist/runtime/dashboard/utils/sparkline.d.ts +21 -0
  172. package/dist/runtime/dashboard/utils/sparkline.js +53 -0
  173. package/dist/runtime/dashboard/utils/state.d.ts +28 -0
  174. package/dist/runtime/dashboard/utils/state.js +32 -0
  175. package/dist/runtime/dashboard/utils/time.d.ts +17 -0
  176. package/dist/runtime/dashboard/utils/time.js +60 -0
  177. package/dist/runtime/dashboard/utils/tracker.d.ts +12 -0
  178. package/dist/runtime/dashboard/utils/tracker.js +31 -0
  179. package/dist/runtime/dashboard/utils/ui.d.ts +38 -0
  180. package/dist/runtime/dashboard/utils/ui.js +24 -0
  181. package/dist/runtime/dashboard/utils/visibility.d.ts +2 -0
  182. package/dist/runtime/dashboard/utils/visibility.js +25 -0
  183. package/dist/runtime/form/types/options.d.ts +15 -36
  184. package/dist/runtime/i18n/locales/en.js +65 -1
  185. package/dist/runtime/i18n/locales/fr.js +65 -1
  186. package/dist/runtime/i18n/types.d.ts +70 -0
  187. package/dist/runtime/shared/index.d.ts +2 -0
  188. package/dist/runtime/shared/styles/scrollbars.css +1 -1
  189. package/dist/runtime/shared/styles/tokens.css +1 -1
  190. package/dist/runtime/shared/types/query.d.ts +10 -0
  191. package/dist/runtime/shared/types/query.js +0 -0
  192. package/dist/runtime/shared/types/remote-options.d.ts +37 -0
  193. package/dist/runtime/shared/types/remote-options.js +0 -0
  194. package/dist/runtime/shared/utils/remote-options.d.ts +10 -0
  195. package/dist/runtime/shared/utils/remote-options.js +6 -0
  196. package/dist/runtime/spreadsheet/components/layout/spreadsheet-import-footer.d.vue.ts +2 -2
  197. package/dist/runtime/spreadsheet/components/layout/spreadsheet-import-footer.vue.d.ts +2 -2
  198. package/dist/runtime/spreadsheet/composables/use-spreadsheet-internals.d.ts +15 -15
  199. package/dist/runtime/spreadsheet/composables/use-spreadsheet-resolutions.d.ts +2 -2
  200. package/dist/runtime/spreadsheet/schema/normalize.d.ts +1 -1
  201. package/dist/runtime/spreadsheet/utils/references/sources.d.ts +1 -1
  202. package/dist/runtime/table/components/data-list/data-list-content.d.vue.ts +1 -1
  203. package/dist/runtime/table/components/data-list/data-list-content.vue.d.ts +1 -1
  204. package/dist/runtime/table/components/data-list/data-list-infinite-loader.d.vue.ts +1 -1
  205. package/dist/runtime/table/components/data-list/data-list-infinite-loader.vue.d.ts +1 -1
  206. package/dist/runtime/table/components/data-list/data-list-layout-switch.d.vue.ts +1 -1
  207. package/dist/runtime/table/components/data-list/data-list-layout-switch.vue.d.ts +1 -1
  208. package/dist/runtime/table/components/data-list/data-list-pagination.d.vue.ts +1 -1
  209. package/dist/runtime/table/components/data-list/data-list-pagination.vue.d.ts +1 -1
  210. package/dist/runtime/table/components/data-list/data-list-sort-menu.d.vue.ts +1 -1
  211. package/dist/runtime/table/components/data-list/data-list-sort-menu.vue.d.ts +1 -1
  212. package/dist/runtime/table/components/data-list/sort-menu-panel.d.vue.ts +2 -2
  213. package/dist/runtime/table/components/data-list/sort-menu-panel.vue.d.ts +2 -2
  214. package/dist/runtime/table/components/filters/shared/filter-match-mode-button.d.vue.ts +1 -1
  215. package/dist/runtime/table/components/filters/shared/filter-match-mode-button.vue.d.ts +1 -1
  216. package/dist/runtime/table/components/filters/shared/filter-option-list-end.d.vue.ts +11 -0
  217. package/dist/runtime/table/components/filters/shared/filter-option-list-end.vue +76 -0
  218. package/dist/runtime/table/components/filters/shared/filter-option-list-end.vue.d.ts +11 -0
  219. package/dist/runtime/table/components/filters/shared/filter-option-loading-list.d.vue.ts +3 -0
  220. package/dist/runtime/table/components/filters/shared/filter-option-loading-list.vue +2 -1
  221. package/dist/runtime/table/components/filters/shared/filter-option-loading-list.vue.d.ts +3 -0
  222. package/dist/runtime/table/components/filters/shared/filter-option-multiple-list.vue +1 -1
  223. package/dist/runtime/table/components/filters/shared/filter-option-picker-content.vue +13 -0
  224. package/dist/runtime/table/components/filters/shared/filter-option-single-list.d.vue.ts +2 -0
  225. package/dist/runtime/table/components/filters/shared/filter-option-single-list.vue +1 -1
  226. package/dist/runtime/table/components/filters/shared/filter-option-single-list.vue.d.ts +2 -0
  227. package/dist/runtime/table/components/filters/shared/filter-option-tree-content.d.vue.ts +3 -0
  228. package/dist/runtime/table/components/filters/shared/filter-option-tree-content.vue +2 -2
  229. package/dist/runtime/table/components/filters/shared/filter-option-tree-content.vue.d.ts +3 -0
  230. package/dist/runtime/table/components/filters/shared/filter-searchable-panel.vue +1 -0
  231. package/dist/runtime/table/components/layout/table-footer.d.vue.ts +1 -1
  232. package/dist/runtime/table/components/layout/table-footer.vue.d.ts +1 -1
  233. package/dist/runtime/table/components/table/table-cell-ellipsis.d.ts +1 -1
  234. package/dist/runtime/table/composables/use-option-filter-editor-state.d.ts +13 -1
  235. package/dist/runtime/table/composables/use-option-filter-editor-state.js +6 -2
  236. package/dist/runtime/table/composables/use-query-state.d.ts +3 -3
  237. package/dist/runtime/table/composables/use-table-columns.d.ts +3 -3
  238. package/dist/runtime/table/composables/use-table-filter-options.d.ts +11 -1
  239. package/dist/runtime/table/composables/use-table-filter-options.js +128 -17
  240. package/dist/runtime/table/composables/use-table-filter-selected-options.d.ts +20 -0
  241. package/dist/runtime/table/composables/use-table-filter-selected-options.js +99 -0
  242. package/dist/runtime/table/composables/use-table-filters.d.ts +5 -0
  243. package/dist/runtime/table/composables/use-table-filters.js +20 -1
  244. package/dist/runtime/table/composables/use-table-internals.d.ts +42 -27
  245. package/dist/runtime/table/composables/use-table-pagination.d.ts +2 -2
  246. package/dist/runtime/table/composables/use-table-remote-filter-options.d.ts +42 -0
  247. package/dist/runtime/table/composables/use-table-remote-filter-options.js +102 -0
  248. package/dist/runtime/table/composables/use-table-selection.d.ts +1 -1
  249. package/dist/runtime/table/composables/use-table-state.d.ts +3 -3
  250. package/dist/runtime/table/types/filters.d.ts +42 -0
  251. package/dist/runtime/table/types/source.d.ts +9 -5
  252. package/dist/runtime/table/utils/columns/menu.d.ts +1 -1
  253. package/dist/runtime/table/utils/columns/state.d.ts +1 -1
  254. package/dist/runtime/table/utils/data-list-ui.d.ts +1 -1
  255. package/dist/runtime/table/utils/filters/options.d.ts +2 -0
  256. package/dist/runtime/table/utils/filters/options.js +1 -1
  257. package/dist/runtime/table/utils/prefetch.js +21 -1
  258. package/package.json +28 -1
@@ -0,0 +1,117 @@
1
+ import { useInfiniteQuery, useQuery } from "@tanstack/vue-query";
2
+ import { refDebounced } from "@vueuse/core";
3
+ import { computed, markRaw, shallowRef } from "vue";
4
+ import {
5
+ REMOTE_OPTIONS_FIRST_PAGE,
6
+ resolveRemoteOptionsNextPage
7
+ } from "../../shared/utils/remote-options.js";
8
+ import { DASHBOARD_REMOTE_OPTIONS_DEFAULTS } from "../constants/query.js";
9
+ import { mergeDashboardOptions, resolveDashboardOptionValues } from "../utils/options.js";
10
+ export function useDashboardRemoteOptions(params) {
11
+ const { config } = params;
12
+ const queryKey = config.queryKey ?? params.queryKey;
13
+ const pageSize = config.pagination?.size ?? DASHBOARD_REMOTE_OPTIONS_DEFAULTS.pageSize;
14
+ const minLength = config.search?.minLength ?? 0;
15
+ const open = shallowRef(false);
16
+ const searchInput = shallowRef("");
17
+ const search = refDebounced(
18
+ searchInput,
19
+ config.search?.debounce ?? DASHBOARD_REMOTE_OPTIONS_DEFAULTS.searchDebounce
20
+ );
21
+ const pages = useInfiniteQuery(
22
+ computed(() => ({
23
+ enabled: (open.value || searchInput.value !== "") && (search.value.length === 0 || search.value.length >= minLength),
24
+ getNextPageParam: (lastPage, allPages) => resolveRemoteOptionsNextPage(lastPage, allPages.length),
25
+ initialPageParam: REMOTE_OPTIONS_FIRST_PAGE,
26
+ queryFn: ({ pageParam }) => config.load({ page: { ...pageParam, size: pageSize }, search: search.value }),
27
+ queryKey: [...queryKey, "options", search.value],
28
+ staleTime: DASHBOARD_REMOTE_OPTIONS_DEFAULTS.staleTime
29
+ }))
30
+ );
31
+ const loaded = computed(
32
+ () => pages.data.value?.pages.flatMap((page) => page.options) ?? []
33
+ );
34
+ const loadedByValue = computed(
35
+ () => new Map(loaded.value.map((option) => [option.value, option]))
36
+ );
37
+ const selectedValues = computed(() => resolveDashboardOptionValues(params.value()));
38
+ const missing = computed(
39
+ () => selectedValues.value.filter((value) => !loadedByValue.value.has(value))
40
+ );
41
+ const hydration = useQuery(
42
+ computed(() => ({
43
+ enabled: Boolean(config.resolveSelected) && missing.value.length > 0,
44
+ queryFn: () => config.resolveSelected?.({ values: missing.value }) ?? Promise.resolve([]),
45
+ queryKey: [...queryKey, "selected", missing.value],
46
+ staleTime: DASHBOARD_REMOTE_OPTIONS_DEFAULTS.selectedStaleTime
47
+ }))
48
+ );
49
+ const selected = computed(() => {
50
+ const hydrated = new Map((hydration.data.value ?? []).map((option) => [option.value, option]));
51
+ return selectedValues.value.map(
52
+ (value) => loadedByValue.value.get(value) ?? hydrated.get(value) ?? { label: value, value }
53
+ );
54
+ });
55
+ const items = computed(
56
+ () => mergeDashboardOptions(loaded.value, selected.value)
57
+ );
58
+ const loading = computed(
59
+ () => pages.isFetching.value && !pages.isFetchingNextPage.value || hydration.isFetching.value
60
+ );
61
+ function setSearch(next) {
62
+ searchInput.value = next;
63
+ }
64
+ function setOpen(next) {
65
+ open.value = next;
66
+ }
67
+ return markRaw({
68
+ get error() {
69
+ return pages.error.value ?? hydration.error.value;
70
+ },
71
+ get hasMore() {
72
+ return pages.hasNextPage.value;
73
+ },
74
+ get items() {
75
+ return items.value;
76
+ },
77
+ get loading() {
78
+ return loading.value;
79
+ },
80
+ get loadingMore() {
81
+ return pages.isFetchingNextPage.value;
82
+ },
83
+ loadMore() {
84
+ if (pages.hasNextPage.value && !pages.isFetchingNextPage.value) void pages.fetchNextPage();
85
+ },
86
+ get menu() {
87
+ return {
88
+ ignoreFilter: true,
89
+ items: items.value,
90
+ labelKey: "label",
91
+ loading: loading.value,
92
+ "onUpdate:open": setOpen,
93
+ "onUpdate:searchTerm": setSearch,
94
+ searchTerm: searchInput.value,
95
+ valueKey: "value"
96
+ };
97
+ },
98
+ get open() {
99
+ return open.value;
100
+ },
101
+ set open(next) {
102
+ setOpen(next);
103
+ },
104
+ async refresh() {
105
+ await pages.refetch();
106
+ },
107
+ get search() {
108
+ return searchInput.value;
109
+ },
110
+ set search(next) {
111
+ setSearch(next);
112
+ },
113
+ get selected() {
114
+ return selected.value;
115
+ }
116
+ });
117
+ }
@@ -0,0 +1,35 @@
1
+ import type { QueryKey } from '@tanstack/vue-query';
2
+ import type { ComputedRef } from 'vue';
3
+ import type { DashboardResourceState, DashboardStage } from '../types/index.js';
4
+ import type { DashboardRuntimeQueryInput } from '../types/runtime.js';
5
+ /**
6
+ * Owns one declared query: exactly one `useQuery`, its widget params, and the deferred activation
7
+ * latch. Gating rewrites `enabled` on a stable definition, so hook order never changes, and a gated
8
+ * resource never evaluates its factory (it does not subscribe to params it cannot use yet).
9
+ */
10
+ export declare function useDashboardResource(params: {
11
+ id: string;
12
+ key: string;
13
+ stage: DashboardStage;
14
+ input: DashboardRuntimeQueryInput;
15
+ scope: {
16
+ active: ComputedRef<boolean>;
17
+ settled: ComputedRef<boolean>;
18
+ prefix: string;
19
+ queryKey: QueryKey;
20
+ /** Dashboard auto-refresh interval in milliseconds, `0` when off. */
21
+ refetchInterval: ComputedRef<number>;
22
+ };
23
+ }): {
24
+ activate: () => void;
25
+ active: ComputedRef<boolean>;
26
+ data: ComputedRef<unknown>;
27
+ error: import("vue").Ref<Error, Error> | import("vue").Ref<null, null>;
28
+ id: string;
29
+ refresh: () => Promise<void>;
30
+ refreshing: ComputedRef<boolean>;
31
+ stage: DashboardStage;
32
+ state: ComputedRef<DashboardResourceState>;
33
+ updatedAt: ComputedRef<number | undefined>;
34
+ widget: import("./use-dashboard-param-scope.js").DashboardParamScope;
35
+ };
@@ -0,0 +1,80 @@
1
+ import { keepPreviousData, useQuery } from "@tanstack/vue-query";
2
+ import { computed, shallowRef } from "vue";
3
+ import { hasProperty, isNullish } from "../../shared/utils/predicate.js";
4
+ import { DASHBOARD_QUERY_DEFAULTS } from "../constants/query.js";
5
+ import { dashboardParamBuilder } from "../utils/builders/dashboard-params.js";
6
+ import { joinDashboardUrlKey } from "../utils/state.js";
7
+ import { useDashboardParamScope } from "./use-dashboard-param-scope.js";
8
+ export function useDashboardResource(params) {
9
+ const { input, stage, scope } = params;
10
+ const activated = shallowRef(stage !== "deferred");
11
+ const widget = useDashboardParamScope({
12
+ definitions: input.params?.(dashboardParamBuilder) ?? {},
13
+ prefix: joinDashboardUrlKey(scope.prefix, params.key),
14
+ queryKey: [...scope.queryKey, params.id, "params"]
15
+ });
16
+ const active = computed(() => scope.active.value && activated.value);
17
+ const gate = computed(() => {
18
+ if (!active.value) return false;
19
+ if (stage === "background" && !scope.settled.value) return false;
20
+ return input.enabled?.() ?? true;
21
+ });
22
+ const required = computed(() => gate.value && input.requires ? input.requires() : true);
23
+ const enabled = computed(() => gate.value && !isNullish(required.value));
24
+ const query = useQuery(
25
+ computed(() => enabled.value ? resolveDefinition() : idleDefinition(params.id))
26
+ );
27
+ function resolveDefinition() {
28
+ const definition = input.query({ params: widget.values, required: required.value });
29
+ const interval = scope.refetchInterval.value;
30
+ return {
31
+ placeholderData: input.keepPreviousData === false ? void 0 : keepPreviousData,
32
+ // Polling pauses while the page is hidden (TanStack's `refetchIntervalInBackground: false`).
33
+ refetchInterval: interval > 0 ? interval : false,
34
+ refetchOnWindowFocus: DASHBOARD_QUERY_DEFAULTS.refetchOnWindowFocus,
35
+ staleTime: input.staleTime ?? DASHBOARD_QUERY_DEFAULTS.staleTime[stage],
36
+ ...definition,
37
+ enabled: !(hasProperty(definition, "enabled") && definition.enabled === false)
38
+ };
39
+ }
40
+ const state = computed(() => {
41
+ if (!enabled.value) return "idle";
42
+ if (query.isError.value) return "error";
43
+ return query.data.value === void 0 ? "loading" : "ready";
44
+ });
45
+ const data = computed(
46
+ () => enabled.value && query.data.value !== void 0 ? query.data.value : input.defaultValue
47
+ );
48
+ const refreshing = computed(() => state.value === "ready" && query.isFetching.value);
49
+ const updatedAt = computed(
50
+ () => state.value === "ready" && query.dataUpdatedAt.value > 0 ? query.dataUpdatedAt.value : void 0
51
+ );
52
+ function activate() {
53
+ activated.value = true;
54
+ }
55
+ async function refresh() {
56
+ if (!activated.value) return activate();
57
+ if (!enabled.value) return;
58
+ await query.refetch({ throwOnError: true });
59
+ }
60
+ return {
61
+ activate,
62
+ active,
63
+ data,
64
+ error: query.error,
65
+ id: params.id,
66
+ refresh,
67
+ refreshing,
68
+ stage,
69
+ state,
70
+ updatedAt,
71
+ widget
72
+ };
73
+ }
74
+ function idleDefinition(id) {
75
+ return {
76
+ enabled: false,
77
+ queryFn: () => Promise.resolve(null),
78
+ queryKey: ["nuxt-ui-tools", "dashboard", "idle", id]
79
+ };
80
+ }
@@ -0,0 +1,46 @@
1
+ import type { ComputedRef } from 'vue';
2
+ import type { DashboardResourceState, DashboardSourceLike, DashboardStage } from '../types/index.js';
3
+ import type { DashboardRuntimeScopeInput } from '../types/runtime.js';
4
+ import type { DashboardReadTracker } from '../utils/tracker.js';
5
+ import { useDashboardParamScope } from './use-dashboard-param-scope.js';
6
+ /**
7
+ * One scope of a dashboard: the root, or one view. It owns the scope params, declares its queries
8
+ * in a single synchronous pass, instantiates them once their keys are known, and derives the scope
9
+ * state from its essential queries.
10
+ */
11
+ export declare function useDashboardScope(params: {
12
+ schemaKey: string;
13
+ /** `''` for the root, the view key otherwise. */
14
+ scopeKey: string;
15
+ input: DashboardRuntimeScopeInput;
16
+ prefix: string;
17
+ active: ComputedRef<boolean>;
18
+ /** Dashboard auto-refresh interval in milliseconds, `0` when off. */
19
+ refetchInterval: ComputedRef<number>;
20
+ /** Root params, visible inside a view's builders. */
21
+ shared?: ReturnType<typeof useDashboardParamScope>;
22
+ /** Root queries and derived values, readable from a view's `derive`. */
23
+ rootSources?: ReadonlyMap<string, DashboardSourceLike>;
24
+ tracker: DashboardReadTracker;
25
+ }): {
26
+ label: import("../../shared/index.js").LazyTextValue | undefined;
27
+ members: Map<string, DashboardSourceLike<unknown>>;
28
+ paramScope: import("./use-dashboard-param-scope.js").DashboardParamScope;
29
+ refresh: () => Promise<void>;
30
+ refreshing: import("vue").ShallowRef<boolean, boolean>;
31
+ resources: {
32
+ activate: () => void;
33
+ active: ComputedRef<boolean>;
34
+ data: ComputedRef<unknown>;
35
+ error: import("vue").Ref<Error, Error> | import("vue").Ref<null, null>;
36
+ id: string;
37
+ refresh: () => Promise<void>;
38
+ refreshing: ComputedRef<boolean>;
39
+ stage: DashboardStage;
40
+ state: ComputedRef<DashboardResourceState>;
41
+ updatedAt: ComputedRef<number | undefined>;
42
+ widget: import("./use-dashboard-param-scope.js").DashboardParamScope;
43
+ }[];
44
+ state: ComputedRef<DashboardResourceState>;
45
+ updatedAt: ComputedRef<number | undefined>;
46
+ };
@@ -0,0 +1,127 @@
1
+ import { computed, shallowRef } from "vue";
2
+ import { dashboardParamBuilder } from "../utils/builders/dashboard-params.js";
3
+ import { createDashboardResourceFacade } from "../utils/resource.js";
4
+ import { assertDashboardMemberKey } from "../utils/schema.js";
5
+ import {
6
+ combineDashboardStates,
7
+ refreshDashboardSources,
8
+ resolveDashboardUpdatedAt
9
+ } from "../utils/state.js";
10
+ import { createDashboardTrackedData } from "../utils/tracker.js";
11
+ import { useDashboardDerived } from "./use-dashboard-derived.js";
12
+ import { mergeDashboardParamValues, useDashboardParamScope } from "./use-dashboard-param-scope.js";
13
+ import { useDashboardResource } from "./use-dashboard-resource.js";
14
+ export function useDashboardScope(params) {
15
+ const { input, scopeKey } = params;
16
+ const queryKey = [params.schemaKey, scopeKey || "$root"];
17
+ const paramScope = useDashboardParamScope({
18
+ definitions: input.params?.(dashboardParamBuilder) ?? {},
19
+ prefix: params.prefix,
20
+ queryKey
21
+ });
22
+ const visibleParams = mergeDashboardParamValues(
23
+ params.shared ? [params.shared, paramScope] : [paramScope]
24
+ );
25
+ const declared = shallowRef(false);
26
+ const declarations = /* @__PURE__ */ new Map();
27
+ const resources = [];
28
+ const settled = computed(
29
+ () => declared.value && resources.every(
30
+ (resource) => resource.stage !== "essential" || resource.state.value !== "loading"
31
+ )
32
+ );
33
+ function createStage(stage) {
34
+ return {
35
+ query(definition) {
36
+ const query = typeof definition === "function" ? { query: definition } : definition;
37
+ const slot = shallowRef(null);
38
+ const facade = createDashboardResourceFacade(stage, slot, query.defaultValue);
39
+ declarations.set(facade, { input: query, slot, stage });
40
+ return facade;
41
+ }
42
+ };
43
+ }
44
+ const exposed = input.queries?.({
45
+ background: createStage("background"),
46
+ deferred: createStage("deferred"),
47
+ essential: createStage("essential"),
48
+ params: visibleParams
49
+ });
50
+ const scopeLabel = scopeKey ? `view "${scopeKey}"` : "the dashboard root";
51
+ const taken = new Set(params.rootSources?.keys());
52
+ const members = /* @__PURE__ */ new Map();
53
+ function instantiate(key, declaration) {
54
+ const resource = useDashboardResource({
55
+ id: scopeKey ? `${scopeKey}.${key}` : key,
56
+ input: declaration.input,
57
+ key,
58
+ scope: {
59
+ active: params.active,
60
+ prefix: params.prefix,
61
+ queryKey,
62
+ refetchInterval: params.refetchInterval,
63
+ settled
64
+ },
65
+ stage: declaration.stage
66
+ });
67
+ declaration.slot.value = resource;
68
+ resources.push(resource);
69
+ }
70
+ for (const [key, facade] of Object.entries(exposed ?? {})) {
71
+ const declaration = declarations.get(facade);
72
+ if (!declaration)
73
+ throw new Error(`[dashboard] "${key}" in ${scopeLabel} is not a declared query.`);
74
+ assertDashboardMemberKey(key, taken, scopeLabel);
75
+ taken.add(key);
76
+ declarations.delete(facade);
77
+ instantiate(key, declaration);
78
+ members.set(key, facade);
79
+ }
80
+ let anonymous = 0;
81
+ for (const declaration of declarations.values()) instantiate(`$${anonymous++}`, declaration);
82
+ declared.value = true;
83
+ const data = createDashboardTrackedData(
84
+ new Map([...params.rootSources ?? [], ...members]),
85
+ params.tracker
86
+ );
87
+ const derived = input.derive?.({ data, params: visibleParams }) ?? {};
88
+ for (const [key, evaluate] of Object.entries(derived)) {
89
+ assertDashboardMemberKey(key, taken, scopeLabel);
90
+ taken.add(key);
91
+ const id = scopeKey ? `${scopeKey}.${key}` : key;
92
+ members.set(key, useDashboardDerived({ evaluate, id, tracker: params.tracker }));
93
+ }
94
+ const essentials = resources.filter((resource) => resource.stage === "essential");
95
+ const state = computed(() => {
96
+ if (!params.active.value) return "idle";
97
+ const combined = combineDashboardStates(essentials.map((resource) => resource.state.value));
98
+ return combined === "idle" ? "ready" : combined;
99
+ });
100
+ const updatedAt = computed(
101
+ () => resolveDashboardUpdatedAt(
102
+ resources.flatMap((resource) => resource.active.value ? [resource.updatedAt.value] : [])
103
+ )
104
+ );
105
+ const refreshing = shallowRef(false);
106
+ let pending = null;
107
+ function refresh() {
108
+ pending ??= refreshDashboardSources(
109
+ resources.filter((resource) => resource.active.value)
110
+ ).finally(() => {
111
+ pending = null;
112
+ refreshing.value = false;
113
+ });
114
+ refreshing.value = true;
115
+ return pending;
116
+ }
117
+ return {
118
+ label: input.label,
119
+ members,
120
+ paramScope,
121
+ refresh,
122
+ refreshing,
123
+ resources,
124
+ state,
125
+ updatedAt
126
+ };
127
+ }
@@ -0,0 +1,13 @@
1
+ import type { DashboardTimeValue } from '../types/index.js';
2
+ /**
3
+ * Locale-aware time formatting that stays current: relative times re-render every 30 seconds
4
+ * through one shared clock.
5
+ */
6
+ export declare function useDashboardTime(): {
7
+ /** Full date and time, for `title` attributes. */
8
+ absolute: (value: DashboardTimeValue) => string;
9
+ /** Day heading: `Today`, `Yesterday`, then the date. */
10
+ day: (value: DashboardTimeValue) => string;
11
+ /** `3 min ago`, `yesterday`, then the date. */
12
+ relative: (value: DashboardTimeValue) => string;
13
+ };
@@ -0,0 +1,40 @@
1
+ import { onBeforeUnmount, onMounted, readonly, shallowRef } from "vue";
2
+ import { useUiToolsLocale } from "../../i18n/use-locale.js";
3
+ import {
4
+ formatDashboardDateTime,
5
+ formatDashboardDay,
6
+ formatDashboardRelativeTime,
7
+ toDashboardTime
8
+ } from "../utils/time.js";
9
+ const TICK = 3e4;
10
+ const now = shallowRef(Date.now());
11
+ let subscribers = 0;
12
+ let timer;
13
+ function useDashboardNow() {
14
+ now.value = Date.now();
15
+ onMounted(() => {
16
+ subscribers += 1;
17
+ if (subscribers > 1) return;
18
+ now.value = Date.now();
19
+ timer = setInterval(() => {
20
+ now.value = Date.now();
21
+ }, TICK);
22
+ });
23
+ onBeforeUnmount(() => {
24
+ subscribers -= 1;
25
+ if (subscribers === 0) clearInterval(timer);
26
+ });
27
+ return readonly(now);
28
+ }
29
+ export function useDashboardTime() {
30
+ const { code } = useUiToolsLocale();
31
+ const clock = useDashboardNow();
32
+ return {
33
+ /** Full date and time, for `title` attributes. */
34
+ absolute: (value) => formatDashboardDateTime(toDashboardTime(value), code.value),
35
+ /** Day heading: `Today`, `Yesterday`, then the date. */
36
+ day: (value) => formatDashboardDay(toDashboardTime(value), clock.value, code.value),
37
+ /** `3 min ago`, `yesterday`, then the date. */
38
+ relative: (value) => formatDashboardRelativeTime(toDashboardTime(value), clock.value, code.value)
39
+ };
40
+ }
@@ -0,0 +1,22 @@
1
+ import type { ComputedRef } from 'vue';
2
+ import type { DashboardMenu, DashboardUiConfig } from '../types/index.js';
3
+ /** App-wide dashboard class overrides from `appConfig.nuxtUiTools.dashboard`. */
4
+ export declare function useDashboardUi(): ComputedRef<DashboardUiConfig>;
5
+ interface DashboardGridContext {
6
+ panels: ComputedRef<boolean>;
7
+ /** Card menu of the blocks that do not set their own. */
8
+ menu: ComputedRef<DashboardMenu | undefined>;
9
+ /** `freshness` of the blocks that do not set their own. */
10
+ freshness: ComputedRef<boolean | undefined>;
11
+ }
12
+ /**
13
+ * Lets blocks know whether they sit in a `panels` grid (joined cells, no card borders), and hands
14
+ * them the grid's block defaults. A nested grid inherits the defaults it does not set.
15
+ */
16
+ export declare function provideDashboardGrid(params: {
17
+ panels: () => boolean;
18
+ menu: () => DashboardMenu | undefined;
19
+ freshness: () => boolean | undefined;
20
+ }): void;
21
+ export declare function useDashboardGridContext(): DashboardGridContext | null;
22
+ export {};
@@ -0,0 +1,19 @@
1
+ import { useAppConfig } from "nuxt/app";
2
+ import { computed, inject, provide } from "vue";
3
+ import { resolveAppDashboardUi } from "../utils/ui.js";
4
+ export function useDashboardUi() {
5
+ const appConfig = useAppConfig();
6
+ return computed(() => resolveAppDashboardUi(appConfig));
7
+ }
8
+ const dashboardGridKey = Symbol("nuxt-ui-tools.dashboard-grid");
9
+ export function provideDashboardGrid(params) {
10
+ const parent = useDashboardGridContext();
11
+ provide(dashboardGridKey, {
12
+ freshness: computed(() => params.freshness() ?? parent?.freshness.value),
13
+ menu: computed(() => params.menu() ?? parent?.menu.value),
14
+ panels: computed(params.panels)
15
+ });
16
+ }
17
+ export function useDashboardGridContext() {
18
+ return inject(dashboardGridKey, null);
19
+ }
@@ -0,0 +1,46 @@
1
+ import type { ComputedRef } from 'vue';
2
+ import type { DashboardSourceLike } from '../types/index.js';
3
+ import type { DashboardRuntimeSchema } from '../types/runtime.js';
4
+ import type { DashboardReadTracker } from '../utils/tracker.js';
5
+ import { useDashboardScope } from './use-dashboard-scope.js';
6
+ /**
7
+ * Owns the view controller: the URL-synced current view (`view`, pushed to history so Back returns
8
+ * to the previous tab) and one scope per view. A view's queries stay idle until the view is opened
9
+ * once, then stay warm across switches.
10
+ */
11
+ export declare function useDashboardViews(params: {
12
+ schema: DashboardRuntimeSchema;
13
+ root: ReturnType<typeof useDashboardScope>;
14
+ refetchInterval: ComputedRef<number>;
15
+ tracker: DashboardReadTracker;
16
+ }): {
17
+ current: import("vue").WritableComputedRef<string, string>;
18
+ keys: string[];
19
+ views: {
20
+ key: string;
21
+ label: () => string;
22
+ opened: import("vue").ShallowRef<boolean, boolean>;
23
+ scope: {
24
+ label: import("../../shared/index.js").LazyTextValue | undefined;
25
+ members: Map<string, DashboardSourceLike<unknown>>;
26
+ paramScope: import("./use-dashboard-param-scope.js").DashboardParamScope;
27
+ refresh: () => Promise<void>;
28
+ refreshing: import("vue").ShallowRef<boolean, boolean>;
29
+ resources: {
30
+ activate: () => void;
31
+ active: ComputedRef<boolean>;
32
+ data: ComputedRef<unknown>;
33
+ error: import("vue").Ref<Error, Error> | import("vue").Ref<null, null>;
34
+ id: string;
35
+ refresh: () => Promise<void>;
36
+ refreshing: ComputedRef<boolean>;
37
+ stage: import("..").DashboardStage;
38
+ state: ComputedRef<import("..").DashboardResourceState>;
39
+ updatedAt: ComputedRef<number | undefined>;
40
+ widget: import("./use-dashboard-param-scope.js").DashboardParamScope;
41
+ }[];
42
+ state: ComputedRef<import("..").DashboardResourceState>;
43
+ updatedAt: ComputedRef<number | undefined>;
44
+ };
45
+ }[];
46
+ };
@@ -0,0 +1,49 @@
1
+ import { computed, shallowRef, watch } from "vue";
2
+ import { createEnumCodec, useQueryState } from "../../query-state/index.js";
3
+ import { resolveTextValue } from "../../shared/utils/render.js";
4
+ import {
5
+ DASHBOARD_VIEW_URL_KEY,
6
+ resolveDashboardScopePrefix,
7
+ resolveDashboardViewKey
8
+ } from "../utils/state.js";
9
+ import { useDashboardScope } from "./use-dashboard-scope.js";
10
+ export function useDashboardViews(params) {
11
+ const { schema } = params;
12
+ if (params.root.paramScope.urlKeys.includes(DASHBOARD_VIEW_URL_KEY)) {
13
+ throw new Error(
14
+ `[dashboard] Root param URL key "${DASHBOARD_VIEW_URL_KEY}" is reserved for the current view of "${schema.key}". Rename the param or set its \`urlKey\`.`
15
+ );
16
+ }
17
+ const keys = schema.views.map(([key]) => key);
18
+ const current = useQueryState({
19
+ codec: createEnumCodec(keys),
20
+ defaultValue: schema.defaultView ?? keys[0] ?? "",
21
+ historyMode: "push",
22
+ key: resolveDashboardViewKey(schema.urlPrefix)
23
+ });
24
+ const rootSources = new Map(params.root.members);
25
+ const views = schema.views.map(([key, input]) => {
26
+ const opened = shallowRef(false);
27
+ watch(
28
+ () => current.value === key,
29
+ (visible) => {
30
+ if (visible) opened.value = true;
31
+ },
32
+ { flush: "sync", immediate: true }
33
+ );
34
+ const scope = useDashboardScope({
35
+ active: computed(() => opened.value),
36
+ input,
37
+ prefix: resolveDashboardScopePrefix(schema.urlPrefix, key),
38
+ refetchInterval: params.refetchInterval,
39
+ rootSources,
40
+ schemaKey: schema.key,
41
+ scopeKey: key,
42
+ shared: params.root.paramScope,
43
+ tracker: params.tracker
44
+ });
45
+ const label = () => resolveTextValue(input.label, key);
46
+ return { key, label, opened, scope };
47
+ });
48
+ return { current, keys, views };
49
+ }
@@ -0,0 +1,24 @@
1
+ import type { DashboardApi, DashboardSchemaLike } from '../types/index.js';
2
+ /**
3
+ * Instantiates a dashboard schema. Call it once in `<script setup>`; every query and URL binding is
4
+ * created synchronously here, so hook order is stable.
5
+ *
6
+ * The returned object has no refs: `dashboard.params.year`, `dashboard.revenue.data`,
7
+ * `dashboard.state` are plain reads, params are `v-model` targets, and every query / derived value
8
+ * can be bound to a block with `:source="dashboard.revenue"`.
9
+ *
10
+ * @example
11
+ * ```vue
12
+ * <script setup lang="ts">
13
+ * const dashboard = useDashboard(salesDashboard)
14
+ * </script>
15
+ *
16
+ * <template>
17
+ * <USelect v-model="dashboard.params.period" v-bind="dashboard.options.period.menu" />
18
+ * <UiDashboardGrid>
19
+ * <UiDashboardStat :source="dashboard.summary" label="Revenue" :value="(d) => d.revenue" />
20
+ * </UiDashboardGrid>
21
+ * </template>
22
+ * ```
23
+ */
24
+ export declare function useDashboard<const TSchema extends DashboardSchemaLike>(schema: TSchema): DashboardApi<TSchema>;
@@ -0,0 +1,42 @@
1
+ import { computed } from "vue";
2
+ import { numberCodec, useQueryState } from "../../query-state/index.js";
3
+ import { resolveDashboardRuntimeSchema } from "../utils/schema.js";
4
+ import {
5
+ DASHBOARD_REFRESH_URL_KEY,
6
+ resolveDashboardRefreshKey,
7
+ resolveDashboardScopePrefix
8
+ } from "../utils/state.js";
9
+ import { createDashboardReadTracker } from "../utils/tracker.js";
10
+ import { useDashboardApi } from "./use-dashboard-api.js";
11
+ import { useDashboardScope } from "./use-dashboard-scope.js";
12
+ import { useDashboardViews } from "./use-dashboard-views.js";
13
+ export function useDashboard(schema) {
14
+ const runtime = resolveDashboardRuntimeSchema(schema);
15
+ const tracker = createDashboardReadTracker();
16
+ const autoRefresh = useQueryState({
17
+ codec: numberCodec,
18
+ defaultValue: Math.max(0, runtime.autoRefresh ?? 0),
19
+ historyMode: "replace",
20
+ key: resolveDashboardRefreshKey(runtime.urlPrefix)
21
+ });
22
+ const refetchInterval = computed(
23
+ () => Number.isFinite(autoRefresh.value) && autoRefresh.value > 0 ? autoRefresh.value * 1e3 : 0
24
+ );
25
+ const root = useDashboardScope({
26
+ active: computed(() => true),
27
+ input: runtime,
28
+ prefix: resolveDashboardScopePrefix(runtime.urlPrefix),
29
+ refetchInterval,
30
+ schemaKey: runtime.key,
31
+ scopeKey: "",
32
+ tracker
33
+ });
34
+ if (root.paramScope.urlKeys.includes(DASHBOARD_REFRESH_URL_KEY)) {
35
+ throw new Error(
36
+ `[dashboard] Root param URL key "${DASHBOARD_REFRESH_URL_KEY}" is reserved for the auto-refresh interval of "${runtime.key}". Rename the param or set its \`urlKey\`.`
37
+ );
38
+ }
39
+ const views = runtime.views.length > 0 ? useDashboardViews({ refetchInterval, root, schema: runtime, tracker }) : null;
40
+ const api = useDashboardApi({ autoRefresh, root, schema, views });
41
+ return api;
42
+ }