@omnitend/dashboard-for-laravel 0.28.0 → 0.30.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 (40) hide show
  1. package/dist/charts.d.ts +19 -0
  2. package/dist/charts.js +225 -0
  3. package/dist/charts.js.map +1 -0
  4. package/dist/charts.umd.cjs +2 -0
  5. package/dist/charts.umd.cjs.map +1 -0
  6. package/dist/components/base/DAlert.vue.d.ts +6 -1
  7. package/dist/components/base/DAutocomplete.vue.d.ts +21 -1
  8. package/dist/components/base/DFormCheckboxGroup.vue.d.ts +12 -0
  9. package/dist/components/extended/DXDashboardSidebar.vue.d.ts +2 -2
  10. package/dist/components/extended/DXField.vue.d.ts +4 -4
  11. package/dist/components/extended/DXForm.vue.d.ts +15 -4
  12. package/dist/components/extended/DXTable.vue.d.ts +39 -1
  13. package/dist/components/extended/DXTablePagination.vue.d.ts +2 -0
  14. package/dist/dashboard-for-laravel.js +8826 -8937
  15. package/dist/dashboard-for-laravel.js.map +1 -1
  16. package/dist/dashboard-for-laravel.umd.cjs +7 -7
  17. package/dist/dashboard-for-laravel.umd.cjs.map +1 -1
  18. package/dist/index.d.ts +1 -3
  19. package/dist/style.css +1 -1
  20. package/dist/types/index.d.ts +1 -1
  21. package/docs/public/api-reference.json +84 -9
  22. package/docs/public/docs-map.md +1 -1
  23. package/docs/public/llms.txt +3 -2
  24. package/package.json +11 -5
  25. package/resources/css/theme.scss +21 -7
  26. package/resources/js/charts.ts +19 -0
  27. package/resources/js/components/base/DAlert.vue +19 -1
  28. package/resources/js/components/base/DAutocomplete.vue +96 -4
  29. package/resources/js/components/base/DFormCheckboxGroup.vue +22 -0
  30. package/resources/js/components/charts/DXBarChart.vue +0 -9
  31. package/resources/js/components/charts/DXDoughnutChart.vue +0 -9
  32. package/resources/js/components/charts/DXLineChart.vue +0 -9
  33. package/resources/js/components/extended/DXField.vue +12 -0
  34. package/resources/js/components/extended/DXForm.vue +25 -5
  35. package/resources/js/components/extended/DXTable.vue +139 -19
  36. package/resources/js/components/extended/DXTableEditorModal.vue +4 -0
  37. package/resources/js/components/extended/DXTablePagination.vue +5 -2
  38. package/resources/js/composables/useForm.ts +30 -3
  39. package/resources/js/index.ts +4 -3
  40. package/resources/js/types/index.ts +1 -0
@@ -57,6 +57,7 @@
57
57
  :striped="striped"
58
58
  :hover="hover"
59
59
  :responsive="responsive"
60
+ :fixed="fixedLayout"
60
61
  :tbody-tr-class="composeRowClass"
61
62
  v-bind="{ ...tableModeBindings, ...tablePassthroughProps }"
62
63
  @update:sort-by="handleSortChange"
@@ -65,6 +66,25 @@
65
66
  @update:busy="handleBusyChange"
66
67
  @row-clicked="handleRowClick"
67
68
  >
69
+ <!-- Per-column widths (#156) via a `<colgroup>`. bvn nests this
70
+ slot's `<col>`s inside a `<colgroup>` it renders. Only
71
+ emitted when a field declares a width AND the consumer hasn't
72
+ supplied their own `table-colgroup` (forwarded generically) —
73
+ so a table with no widths gets no colgroup and renders exactly
74
+ as before. `<col>` widths are authoritative under
75
+ `table-layout: fixed`, where the filter row (not the header)
76
+ is the width-determining first row. -->
77
+ <template
78
+ v-if="fieldsHaveWidths && !$slots['table-colgroup']"
79
+ #table-colgroup
80
+ >
81
+ <col
82
+ v-for="field in fields"
83
+ :key="`col-${field.key}`"
84
+ :style="columnStyleFor(field)"
85
+ />
86
+ </template>
87
+
68
88
  <!-- DXTable owns `thead-top` (its filter row lives there), so a
69
89
  consumer's own thead-top content is COMPOSED above it rather
70
90
  than being dropped: a grouped column-header banner or a pinned
@@ -177,6 +197,7 @@
177
197
  :per-page-options="perPageOptions"
178
198
  :show-pagination="showPagination"
179
199
  :show-per-page-selector="shouldShowPerPageSelector"
200
+ :show-count="showCount"
180
201
  :singular-item-name="singularItemName"
181
202
  :plural-item-name="pluralItemName"
182
203
  :has-active-filters="hasActiveFilters"
@@ -288,6 +309,21 @@ export interface TableField {
288
309
  filter?: FilterType;
289
310
  filterOptions?: FilterOption[];
290
311
  filterPlaceholder?: string;
312
+
313
+ /**
314
+ * Fixed width for this column, applied via a `<colgroup>` `<col>`. A number
315
+ * is treated as pixels (`200` → `200px`); a string is used verbatim
316
+ * (`"20%"`, `"12rem"`). Pair with the table-level `fixedLayout` prop so the
317
+ * width is authoritative and the column stops resizing to fit its content —
318
+ * without `fixedLayout` a wider cell can still stretch the column (#156).
319
+ */
320
+ width?: string | number;
321
+
322
+ /**
323
+ * Minimum width for this column, applied via the same `<col>` as `width`.
324
+ * A number is pixels; a string is used verbatim.
325
+ */
326
+ minWidth?: string | number;
291
327
  [key: string]: any;
292
328
  }
293
329
 
@@ -390,13 +426,30 @@ export interface Props<TItem = any> {
390
426
  /** Show per-page selector */
391
427
  showPerPageSelector?: boolean;
392
428
 
429
+ /**
430
+ * Show the footer's item-count caption ("N items." / "X to Y out of Z
431
+ * items."). Defaults to `true`. Set `false` to suppress just the caption,
432
+ * independent of the pager — a page ported from a plain `<b-table>` that
433
+ * hides the pager with `:show-pagination="false"` would otherwise gain a
434
+ * caption it never had (#127).
435
+ */
436
+ showCount?: boolean;
437
+
393
438
  /** Per-page options for selector */
394
439
  perPageOptions?: number[];
395
440
 
396
441
  /** Current page (for provider mode) */
397
442
  currentPage?: number;
398
443
 
399
- /** Items per page (for provider mode, v-model support) */
444
+ /**
445
+ * Items per page. With a `v-model:per-page` it is controlled state; a bare
446
+ * `:per-page="20"` is the INITIAL page size (see the initial-value vs
447
+ * controlled note above). When passed explicitly it takes PRECEDENCE over any
448
+ * per-page preference persisted in localStorage — `:per-page="20"` always
449
+ * starts at 20, never a size the user once picked on another table (#124).
450
+ * Omit it to let a stored preference (URL-keyed tables only) or the default
451
+ * apply.
452
+ */
400
453
  perPage?: number;
401
454
 
402
455
  /** Striped (banded) rows. Off by default — banding adds little on short
@@ -525,6 +578,16 @@ export interface Props<TItem = any> {
525
578
 
526
579
  /** Enable client-side filtering, sorting, and pagination on items array */
527
580
  clientSide?: boolean;
581
+
582
+ /**
583
+ * Apply `table-layout: fixed` to the underlying table. Off by default, so
584
+ * existing tables keep their content-sized columns. When on, column widths
585
+ * stop depending on cell content, so they no longer reshuffle when a filter
586
+ * narrows the rows — the table stays put as you filter (#156). Combine with
587
+ * per-field `width`/`minWidth` to control the proportions; columns with no
588
+ * declared width share the remaining space equally.
589
+ */
590
+ fixedLayout?: boolean;
528
591
  }
529
592
 
530
593
  const props = withDefaults(defineProps<Props<T>>(), {
@@ -542,6 +605,7 @@ const props = withDefaults(defineProps<Props<T>>(), {
542
605
  }),
543
606
  showPagination: true,
544
607
  showPerPageSelector: true,
608
+ showCount: true,
545
609
  perPageOptions: () => [10, 20, 50, 100],
546
610
  currentPage: 1,
547
611
  // perPage: 10, // Don't set default - let internalPerPage handle it
@@ -556,6 +620,7 @@ const props = withDefaults(defineProps<Props<T>>(), {
556
620
  showCreateButton: true,
557
621
  footClone: false,
558
622
  showEmpty: true,
623
+ fixedLayout: false,
559
624
  });
560
625
 
561
626
  const emit = defineEmits<{
@@ -906,6 +971,35 @@ const hasFieldValue = (item: unknown, key: string): boolean => {
906
971
  const dottedCellFields = (slots: Record<string, unknown>): TableField[] =>
907
972
  props.fields.filter((field) => field.key.includes('.') && !slots[`cell(${field.key})`]);
908
973
 
974
+ /*
975
+ * Per-column widths (#156). A field's `width`/`minWidth` is applied through a
976
+ * `<colgroup>` `<col>`, NOT the header `<th>`: with `table-layout: fixed` the
977
+ * column widths are taken from the FIRST row of cells, and DXTable's inline
978
+ * filter row (`thead-top`) is that first row — so a width on the header `<th>`
979
+ * would be ignored whenever filters are present. A `<col>` width is
980
+ * authoritative regardless of row order, in both fixed and auto layout.
981
+ */
982
+ const sizeToCss = (value: string | number): string =>
983
+ typeof value === 'number' ? `${value}px` : value;
984
+
985
+ const hasDeclaredWidth = (field: TableField): boolean =>
986
+ (field.width !== undefined && field.width !== null) ||
987
+ (field.minWidth !== undefined && field.minWidth !== null);
988
+
989
+ const columnStyleFor = (field: TableField): Record<string, string> | undefined => {
990
+ const style: Record<string, string> = {};
991
+ if (field.width !== undefined && field.width !== null) style.width = sizeToCss(field.width);
992
+ if (field.minWidth !== undefined && field.minWidth !== null) {
993
+ style.minWidth = sizeToCss(field.minWidth);
994
+ }
995
+ return Object.keys(style).length > 0 ? style : undefined;
996
+ };
997
+
998
+ // Only inject a `<colgroup>` when a column actually declares a width — otherwise
999
+ // the table renders exactly as before (no colgroup at all), preserving the
1000
+ // content-sized default byte-for-byte.
1001
+ const fieldsHaveWidths = computed(() => props.fields.some(hasDeclaredWidth));
1002
+
909
1003
  // Computed: Get effective filter options for a field
910
1004
  // The key a column's filter is SENT under, which is not always the column's own
911
1005
  // key: a display column can filter on a different server param via `filterKey`.
@@ -973,27 +1067,51 @@ const getFieldFilterOptions = (field: TableField): FilterOption[] => {
973
1067
  return [];
974
1068
  };
975
1069
 
976
- // LocalStorage key for perPage preference
977
- const perPageStorageKey = computed(() => {
978
- const url = props.inertiaUrl || props.apiUrl || 'table';
1070
+ // LocalStorage key for the per-page preference. Only tables identified by a URL
1071
+ // (inertiaUrl / apiUrl) persist their preference: a keyless client-side table
1072
+ // has no stable identity across reloads, and every such table would otherwise
1073
+ // share the literal `table` key and clobber each other's stored value (#124).
1074
+ // Returns null when there is nothing stable to key on — every read and write
1075
+ // guards on that, so a keyless table simply doesn't persist.
1076
+ const perPageStorageKey = computed<string | null>(() => {
1077
+ const url = props.inertiaUrl || props.apiUrl;
1078
+ if (!url) return null;
979
1079
  return `dxtable-perpage-${url.replace(/\//g, '-')}`;
980
1080
  });
981
1081
 
1082
+ // Whether the consumer EXPLICITLY passed `perPage`. A defaulted/omitted prop is
1083
+ // indistinguishable via `props`, so this reads the raw vnode props — the same
1084
+ // technique as `hasListener` above (Vue keeps passed props on the vnode).
1085
+ const wasPerPagePassed = ((): boolean => {
1086
+ const vnodeProps = instance?.vnode.props ?? {};
1087
+ return 'perPage' in vnodeProps || 'per-page' in vnodeProps;
1088
+ })();
1089
+
982
1090
  // Load perPage from localStorage or use default
983
1091
  const getInitialPerPage = (): number => {
1092
+ // An explicitly-passed `perPage` wins over any stored preference (#124):
1093
+ // `:per-page="20"` means "start at 20" (since #110) and must not be silently
1094
+ // overridden by a size the user once picked on a different table.
1095
+ if (wasPerPagePassed && props.perPage !== undefined) {
1096
+ return props.perPage;
1097
+ }
1098
+
984
1099
  if (typeof window === 'undefined') return props.perPage || 10;
985
1100
 
986
- try {
987
- const saved = localStorage.getItem(perPageStorageKey.value);
988
- if (saved !== null) {
989
- const parsed = parseInt(saved, 10);
990
- // Validate it's in the allowed options
991
- if (props.perPageOptions.includes(parsed)) {
992
- return parsed;
1101
+ const storageKey = perPageStorageKey.value;
1102
+ if (storageKey !== null) {
1103
+ try {
1104
+ const saved = localStorage.getItem(storageKey);
1105
+ if (saved !== null) {
1106
+ const parsed = parseInt(saved, 10);
1107
+ // Validate it's in the allowed options
1108
+ if (props.perPageOptions.includes(parsed)) {
1109
+ return parsed;
1110
+ }
993
1111
  }
1112
+ } catch (error) {
1113
+ console.error('Error loading perPage from localStorage:', error);
994
1114
  }
995
- } catch (error) {
996
- console.error('Error loading perPage from localStorage:', error);
997
1115
  }
998
1116
 
999
1117
  return props.perPage || 10;
@@ -1006,10 +1124,11 @@ const internalPerPage = ref<number>(getInitialPerPage());
1006
1124
  watch(() => props.pagination?.per_page, (newPerPage) => {
1007
1125
  if (newPerPage && newPerPage !== internalPerPage.value) {
1008
1126
  internalPerPage.value = newPerPage;
1009
- // Also update localStorage to stay in sync
1010
- if (typeof window !== 'undefined') {
1127
+ // Also update localStorage to stay in sync (only for URL-keyed tables).
1128
+ const storageKey = perPageStorageKey.value;
1129
+ if (typeof window !== 'undefined' && storageKey !== null) {
1011
1130
  try {
1012
- localStorage.setItem(perPageStorageKey.value, newPerPage.toString());
1131
+ localStorage.setItem(storageKey, newPerPage.toString());
1013
1132
  } catch (error) {
1014
1133
  console.error('Error saving perPage from watcher:', error);
1015
1134
  }
@@ -1445,10 +1564,11 @@ const handlePerPageChange = (newPerPage: number | string | null | (number | stri
1445
1564
  internalPerPage.value = perPageNum;
1446
1565
  }
1447
1566
 
1448
- // Save to localStorage
1449
- if (typeof window !== 'undefined') {
1567
+ // Save to localStorage (only for URL-keyed tables — see perPageStorageKey).
1568
+ const storageKey = perPageStorageKey.value;
1569
+ if (typeof window !== 'undefined' && storageKey !== null) {
1450
1570
  try {
1451
- localStorage.setItem(perPageStorageKey.value, perPageNum.toString());
1571
+ localStorage.setItem(storageKey, perPageNum.toString());
1452
1572
  } catch (error) {
1453
1573
  console.error('Error saving perPage to localStorage:', error);
1454
1574
  }
@@ -37,6 +37,9 @@
37
37
  from one row into the next. The key gives each record a fresh
38
38
  field subtree; the data still lives in `form`, so nothing
39
39
  is lost by remounting. -->
40
+ <!-- Tabs stay bare here: the modal body already provides the panel
41
+ boundary, so DXForm's default card-panel-around-tabs (#159) would be
42
+ redundant nested chrome inside the modal. -->
40
43
  <DXForm
41
44
  v-if="form"
42
45
  :key="formInstanceKey"
@@ -44,6 +47,7 @@
44
47
  :form="form"
45
48
  :fields="fields"
46
49
  :tabs="tabs"
50
+ :card-tabs="false"
47
51
  :context="item ?? undefined"
48
52
  :show-submit="false"
49
53
  @update:active-tab="emit('update:activeTab', $event)"
@@ -45,8 +45,9 @@
45
45
  </div>
46
46
  </div>
47
47
 
48
- <!-- Bottom row: Info text -->
49
- <div class="small text-muted">
48
+ <!-- Bottom row: Info text (the item-count caption). Suppressed by
49
+ `showCount` independent of the pager (#127). -->
50
+ <div v-if="showCount" class="small text-muted">
50
51
  <div>
51
52
  <template v-if="pagination.total > pagination.per_page">
52
53
  {{ pagination.from }} to {{ pagination.to }} out of {{ pagination.total }} {{ pagination.total === 1 ? singularItemName : pluralItemName }}.
@@ -81,6 +82,8 @@ interface Props {
81
82
  showPagination: boolean;
82
83
  /** Whether to render the per-page selector. */
83
84
  showPerPageSelector: boolean;
85
+ /** Whether to render the item-count caption (the "X out of Z items" line). */
86
+ showCount: boolean;
84
87
  /** Singular item noun for the info line (e.g. "product"). */
85
88
  singularItemName: string;
86
89
  /** Plural item noun for the info line (e.g. "products"). */
@@ -154,6 +154,17 @@ export function useForm<TData extends Record<string, any>>(
154
154
  ): UseFormReturn<TData> {
155
155
  const snapshot = deepClone(initialData);
156
156
 
157
+ // Concurrency guards (#133). `useForm` allows overlapping submissions (a
158
+ // consumer can fire two before the first resolves), so:
159
+ // - `inFlightCount` tracks how many requests are active; `processing` only
160
+ // flips false when the LAST one finishes (a per-request `finally` flipping
161
+ // it unconditionally re-enabled the button while another was still running).
162
+ // - `successTimer` is a single handle for the `recentlySuccessful` reset; a
163
+ // new success clears any pending timer before scheduling its own, so an
164
+ // earlier success's timer can't clear the flag a later success just set.
165
+ let inFlightCount = 0;
166
+ let successTimer: ReturnType<typeof setTimeout> | null = null;
167
+
157
168
  const state = reactive<FormState<TData>>({
158
169
  data: deepClone(snapshot) as TData,
159
170
  errors: {},
@@ -250,12 +261,22 @@ export function useForm<TData extends Record<string, any>>(
250
261
  url: string,
251
262
  options: FormSubmitOptions<TData, TResponse> = {},
252
263
  ): Promise<TResponse> => {
264
+ inFlightCount += 1;
253
265
  state.processing = true;
254
266
  if (!options.preserveErrors) clearErrors();
255
267
 
256
268
  const payloadRaw = (
257
269
  options.transform
258
- ? options.transform(state.data as TData)
270
+ ? // Give `transform` a COPY of the form data (#150), so a transform
271
+ // that MUTATES what it receives — `data.allergens = assemble();
272
+ // return data` — shapes the outbound payload WITHOUT corrupting
273
+ // form state. (This is why consumers reach for a transform instead
274
+ // of mutating `form.data` in a validation guard.) A shallow copy:
275
+ // returning a new object is still the tidiest style, and a
276
+ // deeply-nested field should be replaced, not mutated in place.
277
+ options.transform({
278
+ ...(toRaw(state.data) as Record<string, any>),
279
+ } as TData)
259
280
  : (state.data as TData)
260
281
  ) as any;
261
282
 
@@ -305,7 +326,11 @@ export function useForm<TData extends Record<string, any>>(
305
326
  });
306
327
 
307
328
  state.recentlySuccessful = true;
308
- setTimeout(() => (state.recentlySuccessful = false), 1500);
329
+ if (successTimer !== null) clearTimeout(successTimer);
330
+ successTimer = setTimeout(() => {
331
+ state.recentlySuccessful = false;
332
+ successTimer = null;
333
+ }, 1500);
309
334
 
310
335
  options.onSuccess?.(data);
311
336
  if (options.resetOnSuccess) {
@@ -319,7 +344,9 @@ export function useForm<TData extends Record<string, any>>(
319
344
  options.onError?.(err as FormError);
320
345
  throw err;
321
346
  } finally {
322
- state.processing = false;
347
+ inFlightCount -= 1;
348
+ // Only clear `processing` once no submission is still in flight.
349
+ if (inFlightCount === 0) state.processing = false;
323
350
  options.onFinish?.();
324
351
  }
325
352
  };
@@ -11,9 +11,9 @@ export { default as DXField } from "./components/extended/DXField.vue";
11
11
  export { default as DXFieldLabel } from "./components/extended/DXFieldLabel.vue";
12
12
  export { default as DXSwitch } from "./components/extended/DXSwitch.vue";
13
13
  export { default as DXStatCard } from "./components/extended/DXStatCard.vue";
14
- export { default as DXBarChart } from "./components/charts/DXBarChart.vue";
15
- export { default as DXLineChart } from "./components/charts/DXLineChart.vue";
16
- export { default as DXDoughnutChart } from "./components/charts/DXDoughnutChart.vue";
14
+ // Chart components moved to the `@omnitend/dashboard-for-laravel/charts` entry
15
+ // (#142) so chart.js / vue-chartjs stay genuinely optional peers — the main
16
+ // entry no longer references them. See resources/js/charts.ts.
17
17
  export { default as DXRepeater } from "./components/extended/DXRepeater.vue";
18
18
  /**
19
19
  * @deprecated Use `DXForm`. `DXBasicForm` is a thin wrapper around `DXForm`
@@ -53,6 +53,7 @@ export { default as DDropdownDivider } from "./components/base/DDropdownDivider.
53
53
  export { default as DDropdownItem } from "./components/base/DDropdownItem.vue";
54
54
  export { default as DForm } from "./components/base/DForm.vue";
55
55
  export { default as DFormCheckbox } from "./components/base/DFormCheckbox.vue";
56
+ export { default as DFormCheckboxGroup } from "./components/base/DFormCheckboxGroup.vue";
56
57
  export { default as DFormGroup } from "./components/base/DFormGroup.vue";
57
58
  export { default as DFormInput } from "./components/base/DFormInput.vue";
58
59
  export { default as DFormInvalidFeedback } from "./components/base/DFormInvalidFeedback.vue";
@@ -31,6 +31,7 @@ export type FieldType =
31
31
  | "select"
32
32
  | "autocomplete"
33
33
  | "checkbox"
34
+ | "checkbox-group"
34
35
  | "switch"
35
36
  | "radio"
36
37
  | "image"