@omnitend/dashboard-for-laravel 0.48.1 → 0.49.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 (32) hide show
  1. package/dist/components/base/DApp.vue.d.ts +12 -0
  2. package/dist/components/base/DFormCheckbox.vue.d.ts +1 -1
  3. package/dist/components/extended/DXFieldAffixGroup.vue.d.ts +26 -0
  4. package/dist/components/extended/DXNumericField.vue.d.ts +5 -0
  5. package/dist/components/extended/DXTable.vue.d.ts +5 -1
  6. package/dist/composables/useToast.d.ts +36 -1
  7. package/dist/dashboard-for-laravel.js +15383 -14546
  8. package/dist/dashboard-for-laravel.js.map +1 -1
  9. package/dist/dashboard-for-laravel.umd.cjs +9 -9
  10. package/dist/dashboard-for-laravel.umd.cjs.map +1 -1
  11. package/dist/index.d.ts +2 -0
  12. package/dist/style.css +4 -4
  13. package/dist/types/index.d.ts +32 -3
  14. package/dist/utils/itemNameCase.d.ts +17 -0
  15. package/docs/public/api-reference.json +93 -8
  16. package/docs/public/docs-map.md +1 -1
  17. package/docs/public/llms.txt +3 -2
  18. package/package.json +10 -11
  19. package/resources/css/theme.scss +22 -3
  20. package/resources/js/components/base/DApp.vue +29 -0
  21. package/resources/js/components/base/DFormCheckbox.vue +21 -3
  22. package/resources/js/components/extended/DXCurrencyInput.vue +3 -2
  23. package/resources/js/components/extended/DXField.vue +51 -0
  24. package/resources/js/components/extended/DXFieldAffixGroup.vue +84 -0
  25. package/resources/js/components/extended/DXNumericField.vue +54 -1
  26. package/resources/js/components/extended/DXTable.vue +10 -2
  27. package/resources/js/components/extended/DXTableEditorModal.vue +2 -4
  28. package/resources/js/composables/useResourceEditor.ts +7 -9
  29. package/resources/js/composables/useToast.ts +105 -15
  30. package/resources/js/index.ts +2 -0
  31. package/resources/js/types/index.ts +39 -3
  32. package/resources/js/utils/itemNameCase.ts +27 -0
@@ -5,7 +5,10 @@
5
5
  value/guards/`setValue` coercion — this component only renders the control and
6
6
  emits the raw edited value back up. The `percentage` `asFraction` display
7
7
  scaling (model holds a 0–1 fraction, input shows 0–100) lives here because it
8
- is purely presentational to this control.
8
+ is purely presentational to this control. A field's `prepend`/`append`
9
+ (resolved by DXField) go to the currency's `append`, or wrap a number or
10
+ percentage in DXFieldAffixGroup; without them each control renders as it
11
+ did before they existed.
9
12
  -->
10
13
  <template>
11
14
  <!-- Currency: the DXCurrencyInput leaf (#152) owns the symbol prepend, the
@@ -26,10 +29,41 @@
26
29
  :disabled="isDisabled"
27
30
  :readonly="isReadonly || isPlaintext"
28
31
  :plaintext="isPlaintext"
32
+ :append="append"
29
33
  v-bind="inputProps"
30
34
  @update:model-value="emit('update:modelValue', $event)"
31
35
  />
32
36
 
37
+ <!-- Number or percentage with the field's own `prepend`/`append`: the
38
+ input inside a DXFieldAffixGroup. A percentage's trailing cell is
39
+ its `append`, "%" by default. Only a field WITH an affix takes this
40
+ branch, so the two below keep their markup. -->
41
+ <DXFieldAffixGroup
42
+ v-else-if="hasAffixes"
43
+ v-slot="{ describedBy }"
44
+ :prepend="prepend"
45
+ :append="trailingAffix"
46
+ :plaintext="isPlaintext"
47
+ :value="numericInputValue"
48
+ :consumer-described-by="inputProps?.['aria-describedby']"
49
+ >
50
+ <DFormInput
51
+ v-model="numericInputValue"
52
+ type="number"
53
+ :required="field.required"
54
+ :placeholder="field.placeholder"
55
+ :step="field.step"
56
+ :min="field.min"
57
+ :max="field.max"
58
+ :state="state"
59
+ :disabled="isDisabled"
60
+ :readonly="isReadonly || isPlaintext"
61
+ :plaintext="isPlaintext"
62
+ v-bind="inputProps"
63
+ :aria-describedby="describedBy"
64
+ />
65
+ </DXFieldAffixGroup>
66
+
33
67
  <!-- Percentage: numeric input with an affix -->
34
68
  <DInputGroup v-else-if="field.type === 'percentage'">
35
69
  <DFormInput
@@ -76,6 +110,7 @@ import { computed } from "vue";
76
110
  import DFormInput from "../base/DFormInput.vue";
77
111
  import DInputGroup from "../base/DInputGroup.vue";
78
112
  import DXCurrencyInput from "./DXCurrencyInput.vue";
113
+ import DXFieldAffixGroup from "./DXFieldAffixGroup.vue";
79
114
  import type { FieldDefinition } from "../../types";
80
115
 
81
116
  interface Props {
@@ -99,10 +134,28 @@ interface Props {
99
134
 
100
135
  /** Escape-hatch input props, already guard-merged by DXField. */
101
136
  inputProps?: Record<string, any>;
137
+
138
+ /** The field's resolved `prepend` (number and percentage only). */
139
+ prepend?: string;
140
+
141
+ /** The field's resolved `append`: the currency's trailing unit, the
142
+ * percentage's trailing cell in place of "%", or the number's unit. */
143
+ append?: string;
102
144
  }
103
145
 
104
146
  const props = defineProps<Props>();
105
147
 
148
+ // Currency renders its own affixes (DXCurrencyInput: the symbol, `append`).
149
+ const hasAffixes = computed(
150
+ () =>
151
+ props.field.type !== "currency" &&
152
+ (Boolean(props.prepend) || Boolean(props.append)),
153
+ );
154
+
155
+ const trailingAffix = computed(() =>
156
+ props.field.type === "percentage" ? props.append || "%" : props.append,
157
+ );
158
+
106
159
  const emit = defineEmits<{
107
160
  (event: "update:modelValue", value: any): void;
108
161
  }>();
@@ -21,7 +21,7 @@
21
21
  size="sm"
22
22
  @click="handleCreateNew"
23
23
  >
24
- New {{ singularItemName }}
24
+ New {{ titleCasedItemName }}
25
25
  </DButton>
26
26
  </div>
27
27
  </slot>
@@ -322,6 +322,7 @@ import { api } from "../../utils/api";
322
322
  import pluralize from "pluralize";
323
323
  import { useResourceEditor } from "../../composables/useResourceEditor";
324
324
  import { getByPath } from "../../utils/objectPath";
325
+ import { titleCaseItemName } from "../../utils/itemNameCase";
325
326
  import type { FieldDefinition, LabelCols } from "../../types";
326
327
  import DContainer from "../base/DContainer.vue";
327
328
  import DRow from "../base/DRow.vue";
@@ -538,7 +539,11 @@ export interface Props<TItem = any> {
538
539
  /** Table title */
539
540
  title?: string;
540
541
 
541
- /** Name for item (singular) - automatically pluralized (e.g., "product" → "products") */
542
+ /**
543
+ * Name for item (singular), as written mid-sentence - automatically
544
+ * pluralized (e.g., "product" → "products"). Titles and buttons Title-Case
545
+ * it ("New Booking Period"); toasts start it with a capital.
546
+ */
542
547
  itemName?: string;
543
548
 
544
549
  /** Table data items (Inertia mode) */
@@ -2475,6 +2480,9 @@ const tablePassthroughProps = computed(() => ({
2475
2480
  // Computed: Singular and plural item names
2476
2481
  const singularItemName = computed(() => props.itemName);
2477
2482
  const pluralItemName = computed(() => pluralize(props.itemName));
2483
+ // For titles and buttons ("New Booking Period"); mid-sentence text keeps the
2484
+ // name as written.
2485
+ const titleCasedItemName = computed(() => titleCaseItemName(props.itemName));
2478
2486
 
2479
2487
  // The built-in "New {item}" button needs both a create endpoint and consent.
2480
2488
  // Gating the header's own v-if on this (not on `createUrl`) means a table that
@@ -245,6 +245,7 @@ import DXForm from "./DXForm.vue";
245
245
  import DXFormErrorSummary from "./DXFormErrorSummary.vue";
246
246
  import type { EditTab } from "./DXTable.vue";
247
247
  import type { LabelCols } from "../../types";
248
+ import { titleCaseItemName } from "../../utils/itemNameCase";
248
249
 
249
250
  interface Props {
250
251
  /** Whether the modal is open (v-model:show). */
@@ -305,10 +306,7 @@ const innerForm = ref<InstanceType<typeof DXForm> | null>(null);
305
306
 
306
307
  // Title-case the singular item noun for button labels ("customer" → "Customer",
307
308
  // "sales order" → "Sales Order") — capitalize the first letter of each word.
308
- const capitalizedItem = computed(() => {
309
- const noun = props.itemName?.trim() || 'item';
310
- return noun.replace(/\b\w/g, (char) => char.toUpperCase());
311
- });
309
+ const capitalizedItem = computed(() => titleCaseItemName(props.itemName));
312
310
 
313
311
  // Buttons default to item-named copy ("Save Customer" / "Create Customer" /
314
312
  // "Delete Customer") — clearer than a generic "Save Changes" — overridable per
@@ -2,6 +2,7 @@ import { computed, ref, watch, type Ref } from "vue";
2
2
  import { api } from "../utils/api";
3
3
  import { isAbortError, useForm, type FormError } from "./useForm";
4
4
  import { useToast } from "./useToast";
5
+ import { capitaliseFirst, titleCaseItemName } from "../utils/itemNameCase";
5
6
  import type { FieldDefinition } from "../types";
6
7
  import {
7
8
  resolveFieldDefault,
@@ -279,13 +280,10 @@ export function useResourceEditor<T = any>(
279
280
  // Modal title (supports function)
280
281
  const computedModalTitle = computed(() => {
281
282
  if (isCreateMode.value) {
282
- return `New ${singularItemName.value}`;
283
+ return `New ${titleCaseItemName(singularItemName.value)}`;
283
284
  }
284
- if (!selectedItem.value) {
285
- return `Edit ${singularItemName.value}`;
286
- }
287
- if (!props.editModalTitle) {
288
- return `Edit ${singularItemName.value}`;
285
+ if (!selectedItem.value || !props.editModalTitle) {
286
+ return `Edit ${titleCaseItemName(singularItemName.value)}`;
289
287
  }
290
288
  return typeof props.editModalTitle === 'function'
291
289
  ? props.editModalTitle(selectedItem.value)
@@ -538,7 +536,7 @@ export function useResourceEditor<T = any>(
538
536
  onSuccess: (data: any) => {
539
537
  createToast?.({
540
538
  title: 'Success',
541
- body: `${singularItemName.value} created successfully`,
539
+ body: capitaliseFirst(`${singularItemName.value} created successfully`),
542
540
  variant: 'success',
543
541
  modelValue: 3000,
544
542
  });
@@ -581,7 +579,7 @@ export function useResourceEditor<T = any>(
581
579
  // Show success toast
582
580
  createToast?.({
583
581
  title: 'Success',
584
- body: `${singularItemName.value} updated successfully`,
582
+ body: capitaliseFirst(`${singularItemName.value} updated successfully`),
585
583
  variant: 'success',
586
584
  modelValue: 3000, // Auto-dismiss after 3 seconds
587
585
  });
@@ -670,7 +668,7 @@ export function useResourceEditor<T = any>(
670
668
  // Show success toast
671
669
  createToast?.({
672
670
  title: 'Success',
673
- body: `${singularItemName.value} deleted successfully`,
671
+ body: capitaliseFirst(`${singularItemName.value} deleted successfully`),
674
672
  variant: 'success',
675
673
  modelValue: 3000, // Auto-dismiss after 3 seconds
676
674
  });
@@ -1,6 +1,7 @@
1
1
  import { isRef } from "vue";
2
2
  import { useToast as useBvnToast } from "bootstrap-vue-next";
3
3
  import type {
4
+ BvTriggerableEvent,
4
5
  OrchestratorCreateOptions,
5
6
  ToastOrchestratorCreateParam,
6
7
  } from "bootstrap-vue-next";
@@ -15,6 +16,22 @@ import type {
15
16
  // BVN's default `.text-bg-*` styling unchanged.
16
17
  const THEMED_TOAST_VARIANTS = new Set(["success", "danger", "warning", "info", "pending"]);
17
18
 
19
+ /**
20
+ * How long a created toast shows when the caller sets no `modelValue`: bvn
21
+ * 0.45's default. bvn 0.46+ creates the toast hidden until `.show()`, which
22
+ * would make every `create({ body, variant })` silently show nothing
23
+ * (DIVERGENCES.md #10).
24
+ */
25
+ const DEFAULT_TOAST_DURATION_MS = 5000;
26
+
27
+ /**
28
+ * Where a toast shows when the caller sets no `position`. bvn's default,
29
+ * `top-end`, sits over the navbar's right-hand controls (user menu, page
30
+ * actions); reaching for them hovered the toast, which pauses its countdown,
31
+ * so it stayed until its × was clicked (DIVERGENCES.md #11).
32
+ */
33
+ const DEFAULT_TOAST_POSITION = "bottom-end";
34
+
18
35
  function themeToastParam(param: Record<string, unknown>): Record<string, unknown> {
19
36
  const variant = param.variant as string | null | undefined;
20
37
  if (!variant || !THEMED_TOAST_VARIANTS.has(variant)) return param;
@@ -26,28 +43,101 @@ function themeToastParam(param: Record<string, unknown>): Record<string, unknown
26
43
  };
27
44
  }
28
45
 
29
- /**
30
- * Thin wrapper around Bootstrap Vue Next's `useToast()`. Public API is
31
- * identical (`create({ title, body, variant })`, `show(...)`) — a themed
32
- * `variant` is translated internally into a `toast-{variant}` class instead
33
- * of being passed through to BVN, so it's styled via `--bs-toast-*` variables
34
- * (see theme.scss) rather than an `!important`-overridden utility class.
35
- */
46
+ /** `create`'s second argument: bvn's orchestrator options plus 0.45's `keep`. */
47
+ export type ToastCreateOptions = OrchestratorCreateOptions & {
48
+ /**
49
+ * Keep the toast in the orchestrator's store after it hides, so its
50
+ * controller can `.show()` it again. By default a hidden toast is
51
+ * removed, as in bvn 0.45 (bvn 1.x keeps every toast until the calling
52
+ * component unmounts).
53
+ */
54
+ keep?: boolean;
55
+ };
56
+
36
57
  // A ref-wrapped param (rare — most callers pass a plain object) is forwarded
37
58
  // untouched: reading through it once here would snapshot every field, losing
38
- // reactivity for the rest of the toast, not just its variant.
39
- function maybeThemeParam(obj?: ToastOrchestratorCreateParam): ToastOrchestratorCreateParam | undefined {
40
- if (!obj || isRef(obj)) return obj;
41
- return themeToastParam(obj as Record<string, unknown>) as unknown as ToastOrchestratorCreateParam;
59
+ // reactivity for the rest of the toast, not just its variant. It gets none
60
+ // of the shields either (no default duration, no folded options, no removal
61
+ // once hidden), so it must set `modelValue` itself (or be shown with
62
+ // `.show()`) and is removed only when the calling component unmounts.
63
+ function prepareParam(
64
+ obj: ToastOrchestratorCreateParam | undefined,
65
+ options: ToastCreateOptions | undefined,
66
+ removeOnceHidden: () => void,
67
+ ): ToastOrchestratorCreateParam | undefined {
68
+ if (isRef(obj)) return obj;
69
+ const param: Record<string, unknown> = { ...(obj ?? {}) };
70
+ if (param.modelValue === undefined) param.modelValue = DEFAULT_TOAST_DURATION_MS;
71
+ if (param.position === undefined) param.position = DEFAULT_TOAST_POSITION;
72
+
73
+ // bvn 0.45 took options as a second argument; 0.46+ reads `obj.options`.
74
+ // `keep` is ours (0.45's), so it never reaches bvn.
75
+ const { keep = false, ...bvnOptions }: ToastCreateOptions = {
76
+ ...options,
77
+ ...(param.options as ToastCreateOptions | undefined),
78
+ };
79
+ if (options !== undefined || param.options !== undefined) param.options = bvnOptions;
80
+
81
+ // bvn 0.45's orchestrator destroyed a toast once hidden unless `keep`;
82
+ // 1.x leaves it in the store and the DOM. The caller's own onHidden runs
83
+ // first. `hidden` is not cancelable (in 0.45 either), so `keep` is the
84
+ // only way to opt out. bvn 1.2.4 calls onHidden twice per hide; the
85
+ // second destroy finds nothing to remove.
86
+ if (!keep) {
87
+ const callersOnHidden = param.onHidden as ((event: BvTriggerableEvent) => void) | undefined;
88
+ param.onHidden = (event: BvTriggerableEvent) => {
89
+ callersOnHidden?.(event);
90
+ removeOnceHidden();
91
+ };
92
+ }
93
+ return themeToastParam(param) as unknown as ToastOrchestratorCreateParam;
42
94
  }
43
95
 
44
- export function useToast(): ReturnType<typeof useBvnToast> {
96
+ type BvnToast = ReturnType<typeof useBvnToast>;
97
+ type ToastController = ReturnType<BvnToast["create"]>;
98
+
99
+ export type UseToastReturn = Omit<BvnToast, "create"> & {
100
+ /**
101
+ * Create a toast and show it. With no `modelValue` it shows for 5 s
102
+ * (bvn 0.45's default; bvn 1.x would create it hidden). Pass
103
+ * `modelValue: false` to create it hidden and call `.show()` later.
104
+ * Once hidden it is removed, unless `keep` is set. The optional second
105
+ * argument is bvn 0.45's `options`, folded into `obj.options`.
106
+ */
107
+ create: <ComponentProps extends Record<string, unknown> = Record<string, unknown>>(
108
+ obj?: ToastOrchestratorCreateParam<ComponentProps>,
109
+ options?: ToastCreateOptions,
110
+ ) => ToastController;
111
+ /** @deprecated Alias of `create`, kept from bvn 0.45 (removed upstream in 0.46). */
112
+ show: <ComponentProps extends Record<string, unknown> = Record<string, unknown>>(
113
+ obj?: ToastOrchestratorCreateParam<ComponentProps>,
114
+ ) => ToastController;
115
+ };
116
+
117
+ /**
118
+ * Thin wrapper around Bootstrap Vue Next's `useToast()`. Public API is
119
+ * bvn 0.45's (`create({ title, body, variant })` shows the toast and removes
120
+ * it once hidden, `show(...)`, a second `options` argument with `keep`) on
121
+ * top of bvn 1.x's controller, `hide` and `hideAll`. A themed `variant` is
122
+ * translated internally into a `toast-{variant}` class instead of being
123
+ * passed through to BVN, so it's styled via `--bs-toast-*` variables (see
124
+ * theme.scss) rather than an `!important`-overridden utility class.
125
+ */
126
+ export function useToast(): UseToastReturn {
45
127
  const toast = useBvnToast();
128
+ const create = (obj?: ToastOrchestratorCreateParam, options?: ToastCreateOptions) => {
129
+ let controller: ToastController | undefined;
130
+ // After the orchestrator has finished its own `hidden` handling.
131
+ const removeOnceHidden = () => {
132
+ void Promise.resolve().then(() => controller?.destroy());
133
+ };
134
+ controller = toast.create(prepareParam(obj, options, removeOnceHidden));
135
+ return controller;
136
+ };
46
137
 
47
138
  return {
48
139
  ...toast,
49
- create: (obj?: ToastOrchestratorCreateParam, options?: OrchestratorCreateOptions) =>
50
- toast.create(maybeThemeParam(obj), options),
51
- show: (obj?: ToastOrchestratorCreateParam) => toast.show(maybeThemeParam(obj)),
140
+ create: create as UseToastReturn["create"],
141
+ show: ((obj?: ToastOrchestratorCreateParam) => create(obj)) as UseToastReturn["show"],
52
142
  };
53
143
  }
@@ -38,6 +38,7 @@ export { default as DXUserAvatar } from "./components/extended/DXUserAvatar.vue"
38
38
  export { default as DAccordion } from "./components/base/DAccordion.vue";
39
39
  export { default as DAccordionItem } from "./components/base/DAccordionItem.vue";
40
40
  export { default as DAlert } from "./components/base/DAlert.vue";
41
+ export { default as DApp } from "./components/base/DApp.vue";
41
42
  export { default as DAspect } from "./components/base/DAspect.vue";
42
43
  export { default as DAutocomplete } from "./components/base/DAutocomplete.vue";
43
44
  export type { AutocompleteProvider } from "./components/base/DAutocomplete.vue";
@@ -120,6 +121,7 @@ export { default as DTooltip } from "./components/base/DTooltip.vue";
120
121
  export { useForm } from "./composables/useForm";
121
122
  export { defineForm } from "./composables/defineForm";
122
123
  export { useToast } from "./composables/useToast";
124
+ export type { UseToastReturn, ToastCreateOptions } from "./composables/useToast";
123
125
  export { useContainerWidth } from "./composables/useContainerWidth";
124
126
 
125
127
  // Utils
@@ -144,6 +144,30 @@ export interface FieldDefinition {
144
144
  min?: number | string;
145
145
  max?: number | string;
146
146
 
147
+ /**
148
+ * Short unit text shown in an input-group cell AFTER the input: "minutes"
149
+ * for "Online notice", rather than "Online notice (minutes)" in the label.
150
+ * May be a function of the model, like `hint`.
151
+ *
152
+ * For `number`, `text`, `email`, `url` and `tel` fields; on `currency` it
153
+ * is the trailing unit the price is per ("per case", DXCurrencyInput's
154
+ * `append`), and on `percentage` it replaces the "%" cell. Other types
155
+ * ignore it. The input names the cell in its `aria-describedby`, so a
156
+ * screen reader reads "Online notice, 120, minutes". A `plaintext` field
157
+ * shows the value followed by the unit as text ("120 minutes"), and an
158
+ * empty value shows neither. A field without `append` or `prepend`
159
+ * renders exactly as it did before they existed: no input group.
160
+ */
161
+ append?: MaybeFn<string>;
162
+
163
+ /**
164
+ * Short text shown in an input-group cell BEFORE the input ("every",
165
+ * "#"). The counterpart of `append`, on the same field types except
166
+ * `currency`, whose leading cell is `currencySymbol`. May be a function
167
+ * of the model.
168
+ */
169
+ prepend?: MaybeFn<string>;
170
+
147
171
  /** Symbol shown for `currency` fields (default: the locale's, "£"). */
148
172
  currencySymbol?: string;
149
173
 
@@ -475,6 +499,11 @@ interface WithNumericBounds {
475
499
  min?: number | string;
476
500
  max?: number | string;
477
501
  }
502
+ /** `append`/`prepend` unit text in an input-group cell beside the input. */
503
+ interface WithAffixes {
504
+ append?: MaybeFn<string>;
505
+ prepend?: MaybeFn<string>;
506
+ }
478
507
  interface WithSelectableOptions {
479
508
  options?: FieldOption[];
480
509
  optionsLoader?: OptionsLoader;
@@ -482,7 +511,10 @@ interface WithSelectableOptions {
482
511
  }
483
512
 
484
513
  /** `text` / `email` / `url` / `tel` — a plain text-like `<input>`. */
485
- export interface TextFieldDef extends BaseFieldDef, WithPlaceholder {
514
+ export interface TextFieldDef
515
+ extends BaseFieldDef,
516
+ WithPlaceholder,
517
+ WithAffixes {
486
518
  type: "text" | "email" | "url" | "tel";
487
519
  }
488
520
 
@@ -496,7 +528,8 @@ export interface PasswordFieldDef extends BaseFieldDef, WithPlaceholder {
496
528
  export interface NumberFieldDef
497
529
  extends BaseFieldDef,
498
530
  WithPlaceholder,
499
- WithNumericBounds {
531
+ WithNumericBounds,
532
+ WithAffixes {
500
533
  type: "number";
501
534
  }
502
535
 
@@ -514,6 +547,8 @@ export interface CurrencyFieldDef
514
547
  WithNumericBounds {
515
548
  type: "currency";
516
549
  currencySymbol?: string;
550
+ /** The unit the price is per; the leading cell is `currencySymbol`. */
551
+ append?: MaybeFn<string>;
517
552
  decimals?: number;
518
553
  minorUnits?: boolean;
519
554
  }
@@ -522,7 +557,8 @@ export interface CurrencyFieldDef
522
557
  export interface PercentageFieldDef
523
558
  extends BaseFieldDef,
524
559
  WithPlaceholder,
525
- WithNumericBounds {
560
+ WithNumericBounds,
561
+ WithAffixes {
526
562
  type: "percentage";
527
563
  asFraction?: boolean;
528
564
  }
@@ -0,0 +1,27 @@
1
+ /**
2
+ * Casing for a DXTable `itemName` ("booking period") where it is shown.
3
+ *
4
+ * Titles and buttons ("New Booking Period", "Create Booking Period") take
5
+ * Title Case; a sentence that starts with the name ("Booking period
6
+ * created successfully") takes a capital first letter; mid-sentence uses
7
+ * ("No booking periods found") keep the name as written.
8
+ */
9
+
10
+ /**
11
+ * Upper-cases the first letter of each space-separated word and leaves the
12
+ * rest as written, so "SKU" stays "SKU" and "product's" does not become
13
+ * "Product'S" (a `\b\w` replace capitalised the letter after an apostrophe).
14
+ * An empty name reads as "Item".
15
+ */
16
+ export function titleCaseItemName(itemName: string | undefined): string {
17
+ const noun = itemName?.trim() || "item";
18
+ return noun
19
+ .split(/(\s+)/)
20
+ .map((word) => (word.trim() === "" ? word : capitaliseFirst(word)))
21
+ .join("");
22
+ }
23
+
24
+ /** Upper-cases the first character, for text that starts a sentence. */
25
+ export function capitaliseFirst(text: string): string {
26
+ return text.charAt(0).toUpperCase() + text.slice(1);
27
+ }