@kivacore/ui-pro-shared 0.0.9 → 0.0.10

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 (145) hide show
  1. package/package.json +187 -21
  2. package/src/.kiva/config.json +27 -0
  3. package/src/components/avatar-group.tsx +222 -0
  4. package/src/components/kiva/bulk-update-dialog/bulk-update-dialog.tsx +240 -0
  5. package/src/components/kiva/bulk-update-dialog/index.tsx +6 -0
  6. package/src/components/kiva/bulk-update-dialog/types.ts +33 -0
  7. package/src/components/kiva/calendar/animations.ts +40 -0
  8. package/src/components/kiva/calendar/calendar-body.tsx +106 -0
  9. package/src/components/kiva/calendar/calendar-sidebar.tsx +103 -0
  10. package/src/components/kiva/calendar/calendar.tsx +243 -0
  11. package/src/components/kiva/calendar/constants.ts +12 -0
  12. package/src/components/kiva/calendar/contexts/calendar-context.tsx +696 -0
  13. package/src/components/kiva/calendar/contexts/dnd-context.tsx +173 -0
  14. package/src/components/kiva/calendar/dialogs/add-edit-event-dialog.tsx +287 -0
  15. package/src/components/kiva/calendar/dialogs/delete-event-dialog.tsx +73 -0
  16. package/src/components/kiva/calendar/dialogs/event-details-dialog.tsx +163 -0
  17. package/src/components/kiva/calendar/dialogs/events-list-dialog.tsx +122 -0
  18. package/src/components/kiva/calendar/dnd/draggable-event.tsx +66 -0
  19. package/src/components/kiva/calendar/dnd/droppable-area.tsx +53 -0
  20. package/src/components/kiva/calendar/dnd/resizable-event.tsx +190 -0
  21. package/src/components/kiva/calendar/header/calendar-header.tsx +84 -0
  22. package/src/components/kiva/calendar/header/date-navigator.tsx +188 -0
  23. package/src/components/kiva/calendar/header/filter.tsx +80 -0
  24. package/src/components/kiva/calendar/header/today-button.tsx +49 -0
  25. package/src/components/kiva/calendar/header/user-select.tsx +111 -0
  26. package/src/components/kiva/calendar/header/view-tabs.tsx +144 -0
  27. package/src/components/kiva/calendar/helpers.ts +617 -0
  28. package/src/components/kiva/calendar/hooks/use-disclosure.ts +19 -0
  29. package/src/components/kiva/calendar/hooks/use-local-storage.ts +40 -0
  30. package/src/components/kiva/calendar/hooks/use-media-query.ts +25 -0
  31. package/src/components/kiva/calendar/hooks.ts +5 -0
  32. package/src/components/kiva/calendar/index.tsx +27 -0
  33. package/src/components/kiva/calendar/interfaces.ts +35 -0
  34. package/src/components/kiva/calendar/schemas.ts +20 -0
  35. package/src/components/kiva/calendar/settings/settings.tsx +116 -0
  36. package/src/components/kiva/calendar/skeletons/calendar-header-skeleton.tsx +27 -0
  37. package/src/components/kiva/calendar/skeletons/calendar-skeleton.tsx +19 -0
  38. package/src/components/kiva/calendar/skeletons/day-view-skeleton.tsx +40 -0
  39. package/src/components/kiva/calendar/skeletons/month-view-skeleton.tsx +36 -0
  40. package/src/components/kiva/calendar/skeletons/week-view-skeleton.tsx +48 -0
  41. package/src/components/kiva/calendar/skeletons/year-view-skeleton.tsx +42 -0
  42. package/src/components/kiva/calendar/types.ts +25 -0
  43. package/src/components/kiva/calendar/views/agenda-view/agenda-events.tsx +150 -0
  44. package/src/components/kiva/calendar/views/month-view/calendar-month-view.tsx +82 -0
  45. package/src/components/kiva/calendar/views/month-view/day-cell.tsx +218 -0
  46. package/src/components/kiva/calendar/views/month-view/event-bullet.tsx +46 -0
  47. package/src/components/kiva/calendar/views/month-view/month-event-badge.tsx +154 -0
  48. package/src/components/kiva/calendar/views/timeline/calendar-timeline-view.tsx +100 -0
  49. package/src/components/kiva/calendar/views/timeline/lib/timeline-layout.ts +130 -0
  50. package/src/components/kiva/calendar/views/timeline/lib/timeline-model.ts +504 -0
  51. package/src/components/kiva/calendar/views/timeline/timeline-event-bar.tsx +68 -0
  52. package/src/components/kiva/calendar/views/timeline/timeline-grid-header.tsx +125 -0
  53. package/src/components/kiva/calendar/views/timeline/timeline-row.tsx +159 -0
  54. package/src/components/kiva/calendar/views/timeline/timeline-section.tsx +61 -0
  55. package/src/components/kiva/calendar/views/timeline/use-timeline-sections.ts +278 -0
  56. package/src/components/kiva/calendar/views/week-and-day-view/calendar-day-view.tsx +277 -0
  57. package/src/components/kiva/calendar/views/week-and-day-view/calendar-time-line.tsx +47 -0
  58. package/src/components/kiva/calendar/views/week-and-day-view/calendar-week-view.tsx +229 -0
  59. package/src/components/kiva/calendar/views/week-and-day-view/day-view-multi-day-events-row.tsx +79 -0
  60. package/src/components/kiva/calendar/views/week-and-day-view/event-block.tsx +116 -0
  61. package/src/components/kiva/calendar/views/week-and-day-view/render-grouped-events.tsx +54 -0
  62. package/src/components/kiva/calendar/views/week-and-day-view/week-view-multi-day-events-row.tsx +159 -0
  63. package/src/components/kiva/calendar/views/year-view/calendar-year-view.tsx +159 -0
  64. package/src/components/kiva/data-table-side-filters/components/side-filter-active-chips.tsx +137 -0
  65. package/src/components/kiva/data-table-side-filters/components/side-filter-clear.tsx +34 -0
  66. package/src/components/kiva/data-table-side-filters/components/side-filter-search.tsx +67 -0
  67. package/src/components/kiva/data-table-side-filters/components/side-filter-section.tsx +77 -0
  68. package/src/components/kiva/data-table-side-filters/controllers/side-filter-async-options.tsx +354 -0
  69. package/src/components/kiva/data-table-side-filters/controllers/side-filter-boolean.tsx +66 -0
  70. package/src/components/kiva/data-table-side-filters/controllers/side-filter-checkbox-list.tsx +137 -0
  71. package/src/components/kiva/data-table-side-filters/controllers/side-filter-date-range.tsx +204 -0
  72. package/src/components/kiva/data-table-side-filters/controllers/side-filter-numeric-range.tsx +162 -0
  73. package/src/components/kiva/data-table-side-filters/controllers/side-filter-options-dropdown.tsx +191 -0
  74. package/src/components/kiva/data-table-side-filters/controllers/side-filter-text.tsx +53 -0
  75. package/src/components/kiva/data-table-side-filters/core/query-translator.ts +367 -0
  76. package/src/components/kiva/data-table-side-filters/core/types.ts +81 -0
  77. package/src/components/kiva/data-table-side-filters/data-table-side-filters.tsx +483 -0
  78. package/src/components/kiva/data-table-side-filters/hooks/use-data-table-side-filters.tsx +160 -0
  79. package/src/components/kiva/data-table-side-filters/hooks/use-show-more.tsx +62 -0
  80. package/src/components/kiva/data-table-side-filters/index.tsx +44 -0
  81. package/src/components/kiva/data-table-side-filters/lib/render-mode.ts +62 -0
  82. package/src/components/kiva/date-time-picker.tsx +163 -0
  83. package/src/components/kiva/editable-record-detail.tsx +809 -0
  84. package/src/components/kiva/enum-option-editor/enum-option-editor.tsx +891 -0
  85. package/src/components/kiva/enum-option-editor/index.tsx +26 -0
  86. package/src/components/kiva/enum-option-editor/kiva-enum-option-editor.tsx +320 -0
  87. package/src/components/kiva/enum-option-editor/types.ts +90 -0
  88. package/src/components/kiva/kanban.tsx +1376 -0
  89. package/src/components/kiva/kiva-data-export-menu.tsx +543 -0
  90. package/src/components/kiva/map.tsx +1631 -0
  91. package/src/components/kiva/pivot-calendar/components/group-sidebar.tsx +95 -0
  92. package/src/components/kiva/pivot-calendar/components/pivot-calendar-toolbar.tsx +113 -0
  93. package/src/components/kiva/pivot-calendar/components/stats-cell.tsx +126 -0
  94. package/src/components/kiva/pivot-calendar/helpers.ts +374 -0
  95. package/src/components/kiva/pivot-calendar/hooks/use-pivot-calendar.ts +222 -0
  96. package/src/components/kiva/pivot-calendar/index.tsx +32 -0
  97. package/src/components/kiva/pivot-calendar/pivot-calendar.tsx +107 -0
  98. package/src/components/kiva/pivot-calendar/types.ts +154 -0
  99. package/src/components/kiva/pivot-calendar/views/days-of-month-view.tsx +37 -0
  100. package/src/components/kiva/pivot-calendar/views/days-of-week-view.tsx +37 -0
  101. package/src/components/kiva/pivot-calendar/views/month-calendar-view.tsx +154 -0
  102. package/src/components/kiva/pivot-calendar/views/months-of-year-view.tsx +40 -0
  103. package/src/components/kiva/pivot-calendar/views/pivot-grid-view.tsx +251 -0
  104. package/src/components/kiva/pivot-filter/index.tsx +9 -0
  105. package/src/components/kiva/pivot-filter/pivot-filter-item.tsx +159 -0
  106. package/src/components/kiva/pivot-filter/pivot-filter-settings.tsx +161 -0
  107. package/src/components/kiva/pivot-filter/pivot-filter.tsx +187 -0
  108. package/src/components/kiva/pivot-filter/types.ts +82 -0
  109. package/src/components/kiva/pivot-grid/hooks/use-pivot-grid.ts +683 -0
  110. package/src/components/kiva/pivot-grid/index.tsx +23 -0
  111. package/src/components/kiva/pivot-grid/lib/pivot-grid-color-rules.ts +98 -0
  112. package/src/components/kiva/pivot-grid/lib/pivot-grid-export.ts +265 -0
  113. package/src/components/kiva/pivot-grid/lib/pivot-grid-model.ts +1110 -0
  114. package/src/components/kiva/pivot-grid/pivot-grid-demo-data.ts +200 -0
  115. package/src/components/kiva/pivot-grid/pivot-grid-export-menu.tsx +66 -0
  116. package/src/components/kiva/pivot-grid/pivot-grid-toolbar.tsx +85 -0
  117. package/src/components/kiva/pivot-grid/pivot-grid.tsx +601 -0
  118. package/src/components/kiva/pivot-grid/types.ts +195 -0
  119. package/src/components/kiva/place-autocomplete.tsx +484 -0
  120. package/src/components/kiva/record-delete-confirm-dialog/index.tsx +10 -0
  121. package/src/components/kiva/record-delete-confirm-dialog/record-delete-confirm-dialog.tsx +266 -0
  122. package/src/components/kiva/record-delete-confirm-dialog/types.ts +25 -0
  123. package/src/hooks/kiva/_internal/autonumber-setting.ts +112 -0
  124. package/src/hooks/kiva/_internal/form-layout-to-view.ts +665 -0
  125. package/src/hooks/kiva/_internal/kiva-hook-utils.ts +143 -0
  126. package/src/hooks/kiva/_internal/use-computed-field-evaluator.tsx +310 -0
  127. package/src/hooks/kiva/_internal/use-field-actions-evaluator.tsx +398 -0
  128. package/src/hooks/kiva/_internal/use-form-actions-evaluator.tsx +363 -0
  129. package/src/hooks/kiva/_internal/use-form-view-engine.tsx +2200 -0
  130. package/src/hooks/kiva/_internal/use-kiva-form-view-fields.tsx +190 -0
  131. package/src/hooks/kiva/_internal/use-kiva-kanban-cards.tsx +311 -0
  132. package/src/hooks/kiva/use-data-export.tsx +265 -0
  133. package/src/hooks/kiva/use-kiva-calendar.tsx +992 -0
  134. package/src/hooks/kiva/use-kiva-data-export.tsx +173 -0
  135. package/src/hooks/kiva/use-kiva-data-grid.tsx +4750 -0
  136. package/src/hooks/kiva/use-kiva-data-view-select.tsx +1273 -0
  137. package/src/hooks/kiva/use-kiva-form-view.tsx +1581 -0
  138. package/src/hooks/kiva/use-kiva-inventory.tsx +184 -0
  139. package/src/hooks/kiva/use-kiva-kanban.tsx +1750 -0
  140. package/src/hooks/kiva/use-kiva-map-view.tsx +2255 -0
  141. package/src/hooks/kiva/use-kiva-pivot-calendar.tsx +759 -0
  142. package/src/hooks/kiva/use-kiva-pivot-filter.tsx +1523 -0
  143. package/src/hooks/kiva/use-kiva-pivot-grid.tsx +543 -0
  144. package/src/hooks/kiva/use-kiva-tenant.tsx +313 -0
  145. package/src/hooks/kiva/use-parameter-persistence.ts +191 -0
@@ -0,0 +1,184 @@
1
+ 'use client';
2
+
3
+ // @ts-nocheck
4
+ /* eslint-disable */
5
+ import {
6
+ useCallback,
7
+ useEffect,
8
+ useRef,
9
+ useState
10
+ } from 'react';
11
+
12
+ import { type RestApiClient } from '@kivacore/api-client';
13
+ import {
14
+ createInventoryClient,
15
+ type InventoryClient,
16
+ type InventoryLoadOptions,
17
+ type InventoryLoadProgress,
18
+ type InventoryLoadResult,
19
+ type InventoryLoadStepId
20
+ } from '@kivacore/app-utils';
21
+
22
+ /*
23
+ * One shared `InventoryClient` per `RestApiClient` instance. The inventory
24
+ * caches its data in the returned instance's closure, so a single shared
25
+ * instance is what lets the post-sign-in `load()` warm-up AND every
26
+ * inventory-backed hook (`useKivaFormView`, `useKivaDataGrid`, …) read
27
+ * tenant metadata from the SAME in-memory cache — the whole app resolves
28
+ * apps / data sources / fields / enums / views / forms from one network fetch.
29
+ *
30
+ * Keyed by a WeakMap so the cache is garbage-collected with its client and
31
+ * never leaks across tenants / sessions (a tenant switch that rebuilds the
32
+ * client gets a fresh inventory; a switch that reuses the client should call
33
+ * `inventory.refresh()`).
34
+ */
35
+ const inventoryCache = new WeakMap<RestApiClient, InventoryClient>();
36
+
37
+ /**
38
+ * Returns the process-wide shared `InventoryClient` for a given API client,
39
+ * creating it on first use. Pass the result into `createDataSourceClient`,
40
+ * `createDataViewClient`, etc. (`{ inventory }`) so every client shares one
41
+ * cache. `null` in → `null` out (so callers can call it before auth resolves).
42
+ */
43
+ export function getSharedKivaInventory(client: RestApiClient): InventoryClient;
44
+ export function getSharedKivaInventory(client: RestApiClient | null | undefined): InventoryClient | null;
45
+ export function getSharedKivaInventory(client: RestApiClient | null | undefined): InventoryClient | null {
46
+ if (!client) return null;
47
+
48
+ let inventory = inventoryCache.get(client);
49
+
50
+ if (!inventory) {
51
+ inventory = createInventoryClient(client);
52
+ inventoryCache.set(client, inventory);
53
+ }
54
+
55
+ return inventory;
56
+ }
57
+
58
+ export type KivaInventoryLoadStatus = 'idle' | 'loading' | 'ready' | 'error';
59
+
60
+ export interface UseKivaInventoryLoaderOptions {
61
+ /** The authenticated API client. The loader waits until this is set. */
62
+ client: RestApiClient | null | undefined;
63
+ /**
64
+ * Gate the warm-up (e.g. only once the session is authenticated). Defaults to
65
+ * `true`; the loader still requires a non-null `client`.
66
+ */
67
+ enabled?: boolean;
68
+ /** Which tenant-wide steps to warm. Forwarded to `inventory.load`. */
69
+ include?: InventoryLoadStepId[];
70
+ /** App ids whose config + user-config to warm. Forwarded to `inventory.load`. */
71
+ configAppIds?: string[];
72
+ /** Invalidate caches before loading (default `true`, matching `inventory.load`). */
73
+ force?: boolean;
74
+ }
75
+
76
+ export interface KivaInventoryLoaderState {
77
+ /** The shared inventory for the current client (`null` before auth). */
78
+ inventory: InventoryClient | null;
79
+ status: KivaInventoryLoadStatus;
80
+ /** Latest progress event (drive a determinate bar with `progress.ratio`). */
81
+ progress: InventoryLoadProgress | null;
82
+ error: unknown;
83
+ result: InventoryLoadResult | null;
84
+ /** `true` while a warm-up is in flight. */
85
+ isLoading: boolean;
86
+ /** `true` once the warm-up has completed successfully. */
87
+ isReady: boolean;
88
+ /** Re-run the warm-up (e.g. a Retry button, or after a tenant switch). */
89
+ reload: () => void;
90
+ }
91
+
92
+ /**
93
+ * Headless post-sign-in inventory warm-up. Runs `inventory.load()` once per
94
+ * client (StrictMode-safe) as soon as it is `enabled` and a `client` exists,
95
+ * exposing determinate progress + status so a host app can render a loading
96
+ * dialog before routing to the home page. The warm-up hydrates the SAME shared
97
+ * inventory that `getSharedKivaInventory` hands to every inventory-backed
98
+ * hook, so all later metadata reads are cache hits.
99
+ *
100
+ * Failures do not throw — `status` becomes `'error'` and `reload()` retries;
101
+ * the app can still run (inventory-backed reads fall back to the API).
102
+ */
103
+ export function useKivaInventoryLoader(
104
+ options: UseKivaInventoryLoaderOptions
105
+ ): KivaInventoryLoaderState {
106
+ const {
107
+ client,
108
+ enabled = true,
109
+ include,
110
+ configAppIds,
111
+ force
112
+ } = options;
113
+
114
+ const inventory = getSharedKivaInventory(client);
115
+
116
+ const [status, setStatus] = useState<KivaInventoryLoadStatus>('idle');
117
+ const [progress, setProgress] = useState<InventoryLoadProgress | null>(null);
118
+ const [error, setError] = useState<unknown>(null);
119
+ const [result, setResult] = useState<InventoryLoadResult | null>(null);
120
+ const [reloadCount, setReloadCount] = useState(0);
121
+
122
+ /*
123
+ * Guards against the StrictMode double-effect and re-renders re-triggering
124
+ * the load. Keyed by the client the warm-up ran for so a tenant switch (new
125
+ * client identity) re-warms automatically.
126
+ */
127
+ const loadedClientRef = useRef<RestApiClient | null>(null);
128
+
129
+ const runLoad = useCallback(async (targetInventory: InventoryClient) => {
130
+ setStatus('loading');
131
+ setError(null);
132
+ setProgress(null);
133
+
134
+ const loadOptions: InventoryLoadOptions = {
135
+ onProgress: setProgress
136
+ };
137
+
138
+ if (include) loadOptions.include = include;
139
+ if (configAppIds) loadOptions.configAppIds = configAppIds;
140
+ if (force !== undefined) loadOptions.force = force;
141
+
142
+ try {
143
+ const loaded = await targetInventory.load(loadOptions);
144
+
145
+ setResult(loaded);
146
+ setStatus('ready');
147
+ } catch (loadError) {
148
+ setError(loadError);
149
+ setStatus('error');
150
+ loadedClientRef.current = null;
151
+ }
152
+ }, [include, configAppIds, force]);
153
+
154
+ const reload = useCallback(() => {
155
+ loadedClientRef.current = null;
156
+ setStatus('idle');
157
+ setReloadCount(count => count + 1);
158
+ }, []);
159
+
160
+ useEffect(() => {
161
+ if (!enabled || !client || !inventory) return;
162
+ if (loadedClientRef.current === client) return;
163
+
164
+ loadedClientRef.current = client;
165
+ void runLoad(inventory);
166
+ }, [
167
+ enabled,
168
+ client,
169
+ inventory,
170
+ runLoad,
171
+ reloadCount
172
+ ]);
173
+
174
+ return {
175
+ inventory,
176
+ status,
177
+ progress,
178
+ error,
179
+ result,
180
+ isLoading: status === 'loading',
181
+ isReady: status === 'ready',
182
+ reload
183
+ };
184
+ }