@antelopejs/dms 0.21.4-next.987.gb437fd0 → 0.21.4-next.990.g2afafca

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.
@@ -2,6 +2,7 @@
2
2
  import { computed, watch } from "vue";
3
3
  import { isObject, isString } from "#dms-core/app/utils/type-check";
4
4
  import { useFileReadUrls } from "../../../composables/useFileReadUrls";
5
+ import { labelInitials } from "../../utils/initials";
5
6
 
6
7
  /**
7
8
  * The leading tile of a built-in card: the row's avatar when its title column
@@ -18,8 +19,6 @@ interface CardAvatarProps {
18
19
 
19
20
  const props = defineProps<CardAvatarProps>();
20
21
 
21
- const INITIALS_LENGTH = 2;
22
-
23
22
  const { getUrl, resolve } = useFileReadUrls(props.storage);
24
23
 
25
24
  const avatarKey = computed(() =>
@@ -32,14 +31,7 @@ const src = computed(() => {
32
31
  return avatarKey.value ? getUrl(avatarKey.value) : undefined;
33
32
  });
34
33
 
35
- const initials = computed(() =>
36
- props.label
37
- .split(/\s+/)
38
- .filter(Boolean)
39
- .slice(0, INITIALS_LENGTH)
40
- .map((word) => word.charAt(0).toUpperCase())
41
- .join(""),
42
- );
34
+ const initials = computed(() => labelInitials(props.label));
43
35
  </script>
44
36
 
45
37
  <template>
@@ -2,6 +2,7 @@
2
2
  import { computed, watch } from "vue";
3
3
  import { isObject, isString } from "#dms-core/app/utils/type-check";
4
4
  import { useFileReadUrls } from "../../../composables/useFileReadUrls";
5
+ import { labelInitials } from "../../utils/initials";
5
6
 
6
7
  /**
7
8
  * The `identity` cell of a table: an avatar (or an icon tile), a name with an
@@ -58,9 +59,6 @@ const props = withDefaults(defineProps<IdentityCellProps>(), {
58
59
  const { user } = useCurrentUser();
59
60
  const { getUrl, resolve } = useFileReadUrls(props.storage);
60
61
 
61
- const MAX_INITIALS = 2;
62
- const INITIALS_SPLIT = /[\s.@_-]+/;
63
-
64
62
  const isEmpty = computed(
65
63
  () => !props.title && !!(props.emptyLabel || props.emptyIcon),
66
64
  );
@@ -91,14 +89,7 @@ const avatarSrc = computed(() => {
91
89
  return avatarKey.value ? getUrl(avatarKey.value) : undefined;
92
90
  });
93
91
 
94
- const initials = computed(() =>
95
- label.value
96
- .split(INITIALS_SPLIT)
97
- .filter(Boolean)
98
- .slice(0, MAX_INITIALS)
99
- .map((word) => word[0]!.toLocaleUpperCase())
100
- .join(""),
101
- );
92
+ const initials = computed(() => labelInitials(label.value));
102
93
  </script>
103
94
 
104
95
  <template>
@@ -35,6 +35,8 @@ interface SelectItemOption {
35
35
  value: unknown;
36
36
  label?: string;
37
37
  icon?: string;
38
+ textColor?: string;
39
+ iconColor?: string;
38
40
  }
39
41
 
40
42
  interface StatusPillOptions {
@@ -49,13 +51,24 @@ interface StatusPillOptions {
49
51
  typeOptions?: { items?: SelectItemOption[] };
50
52
  }
51
53
 
52
- function statusPillTone(opts: StatusPillOptions, key: string, row: Row) {
53
- return readRowTone(row, opts.toneField) ?? opts.tones?.[key] ?? "neutral";
54
+ function statusPillTone(
55
+ opts: StatusPillOptions,
56
+ key: string,
57
+ row: Row,
58
+ item?: SelectItemOption,
59
+ ) {
60
+ return (
61
+ readRowTone(row, opts.toneField) ??
62
+ opts.tones?.[key] ??
63
+ item?.textColor ??
64
+ item?.iconColor ??
65
+ "neutral"
66
+ );
54
67
  }
55
68
 
56
69
  /**
57
70
  * `status_pill`: a tinted pill led by a dot, in the tone the row gives
58
- * (`toneField`) or the value maps to, with an optional line under it (a
71
+ * (`toneField`), the value maps to or its select item carries, with an optional line under it (a
59
72
  * failure's cause, a composed "retry Oct 10") in the row's tone, else
60
73
  * `subTone`, else the pill's.
61
74
  */
@@ -71,7 +84,7 @@ function renderStatusPill(
71
84
  const item = opts.typeOptions?.items?.find(
72
85
  (candidate) => String(candidate.value) === key,
73
86
  );
74
- const tone = statusPillTone(opts, key, row);
87
+ const tone = statusPillTone(opts, key, row, item);
75
88
  const pill = h(StatusPill, {
76
89
  tone,
77
90
  label: processI18n(item?.label ?? key),
@@ -30,7 +30,7 @@ export function calendarToDate(
30
30
  calendar: CalendarDate,
31
31
  asEndOfDay: boolean,
32
32
  ): Date {
33
- const native = new Date(calendar.year, calendar.month - 1, calendar.day);
33
+ const native = calendar.toDate(getLocalTimeZone());
34
34
  if (asEndOfDay) {
35
35
  native.setHours(
36
36
  END_OF_DAY_HOURS,
@@ -0,0 +1,36 @@
1
+ const INITIALS_LENGTH = 2;
2
+ const WORD_SPLIT = /[\s.@_-]+/;
3
+ const LETTER_OR_DIGIT = /^[\p{L}\p{N}]/u;
4
+
5
+ const segmenter = new Intl.Segmenter(undefined, { granularity: "grapheme" });
6
+
7
+ function graphemes(text: string): string[] {
8
+ return Array.from(segmenter.segment(text), ({ segment }) => segment);
9
+ }
10
+
11
+ function wordInitials(word: string, count: number): string[] {
12
+ const characters = graphemes(word);
13
+ const letters = characters.filter((character) =>
14
+ LETTER_OR_DIGIT.test(character),
15
+ );
16
+ return letters.length > 0 ? letters.slice(0, count) : characters.slice(0, 1);
17
+ }
18
+
19
+ /**
20
+ * The two characters an avatar draws for a name without a picture: the first
21
+ * letter or digit of its first two words ("Camille Martin" → "CM", "3M Group" →
22
+ * "3G"), or the first two letters or digits of a one-word name ("EduLoop" →
23
+ * "ED"), uppercased. Words split on spaces, dots, `@`, `_` and `-`, so an
24
+ * address reads as a name ("ada.lovelace@example.com" → "AL"). Characters are
25
+ * whole graphemes: an accent or an emoji is never cut in half.
26
+ */
27
+ export function labelInitials(label: string): string {
28
+ const words = label.split(WORD_SPLIT).filter(Boolean);
29
+ const characters =
30
+ words.length === 1
31
+ ? wordInitials(words[0]!, INITIALS_LENGTH)
32
+ : words
33
+ .slice(0, INITIALS_LENGTH)
34
+ .flatMap((word) => wordInitials(word, 1));
35
+ return characters.join("").toLocaleUpperCase();
36
+ }
@@ -133,8 +133,9 @@ const {
133
133
  draftCalendar,
134
134
  draftCompareCalendar,
135
135
  selectCalendarRange,
136
- updateStart,
137
- updateEnd,
136
+ fieldCalendar,
137
+ typeDay,
138
+ leaveField,
138
139
  segmentedPreset,
139
140
  onSegmentedClick,
140
141
  } = usePeriodSelectorInteraction(props, period, draft, isCustomEnabled);
@@ -309,33 +310,33 @@ const segmentedItems = usePeriodSelectorSegments(
309
310
  <div
310
311
  class="grid grid-cols-1 gap-2 min-[22rem]:grid-cols-2 md:grid-cols-[1fr_1fr_1.25fr]"
311
312
  >
312
- <label class="grid gap-1">
313
+ <label class="grid gap-1" @focusout="leaveField">
313
314
  <span :class="FIELD_LABEL_CLASS">
314
315
  {{ $t("dms.period.popover.start", "Start") }}
315
316
  </span>
316
317
  <UInputDate
317
- :model-value="draftCalendar.start"
318
+ :model-value="fieldCalendar.start"
318
319
  :locale="locale"
319
320
  :disabled="!isCustomEnabled"
320
321
  size="sm"
321
322
  class="w-full"
322
323
  :ui="{ base: 'font-mono text-xs' }"
323
- @update:model-value="updateStart"
324
+ @update:model-value="typeDay('start', $event)"
324
325
  />
325
326
  </label>
326
- <label class="grid gap-1">
327
+ <label class="grid gap-1" @focusout="leaveField">
327
328
  <span :class="FIELD_LABEL_CLASS">
328
329
  {{ $t("dms.period.popover.end", "End") }}
329
330
  </span>
330
331
  <UInputDate
331
- :model-value="draftCalendar.end"
332
+ :model-value="fieldCalendar.end"
332
333
  :locale="locale"
333
334
  :disabled="!isCustomEnabled"
334
335
  :highlight="!!pendingStart"
335
336
  size="sm"
336
337
  class="w-full"
337
338
  :ui="{ base: 'font-mono text-xs' }"
338
- @update:model-value="updateEnd"
339
+ @update:model-value="typeDay('end', $event)"
339
340
  />
340
341
  </label>
341
342
  <label
@@ -1,4 +1,4 @@
1
- import { computed, ref, type Ref } from "vue";
1
+ import { computed, ref, shallowRef, type Ref } from "vue";
2
2
  import type { CalendarDate, DateValue } from "@internationalized/date";
3
3
  import type { UsePeriodReturn } from "#dms-core/app/composables/period/usePeriod";
4
4
  import type { PeriodPreset } from "#dms-core/app/composables/period/types";
@@ -9,6 +9,7 @@ import {
9
9
  import {
10
10
  type CalendarRange,
11
11
  type CalendarRangeAnchor,
12
+ calendarRangeDays,
12
13
  calendarToRange,
13
14
  limitCalendarRange,
14
15
  rangeToCalendar,
@@ -16,6 +17,28 @@ import {
16
17
  import { toCalendarDay } from "../../build/utils/calendarDay";
17
18
  import { CUSTOM_PRESET } from "./periodSelectorPresentation";
18
19
 
20
+ interface HeldDay {
21
+ anchor: CalendarRangeAnchor;
22
+ day: CalendarDate;
23
+ }
24
+
25
+ function withHeldDay(
26
+ range: CalendarRange,
27
+ held: HeldDay | null,
28
+ ): CalendarRange {
29
+ return held ? { ...range, [held.anchor]: held.day } : range;
30
+ }
31
+
32
+ function isLeavingField(event: FocusEvent): boolean {
33
+ const field = event.currentTarget;
34
+ const next = event.relatedTarget;
35
+ return !(
36
+ field instanceof Node &&
37
+ next instanceof Node &&
38
+ field.contains(next)
39
+ );
40
+ }
41
+
19
42
  export function usePeriodSelectorInteraction(
20
43
  props: { maxDays?: number },
21
44
  period: UsePeriodReturn,
@@ -24,12 +47,15 @@ export function usePeriodSelectorInteraction(
24
47
  ) {
25
48
  const isOpen = ref(false);
26
49
  const pendingStart = ref<CalendarDate | null>(null);
50
+ const heldDay = shallowRef<HeldDay | null>(null);
27
51
  function setOpen(open: boolean) {
28
52
  if (open) draft.reset();
29
53
  pendingStart.value = null;
54
+ heldDay.value = null;
30
55
  isOpen.value = open;
31
56
  }
32
57
  function selectDraftPreset(preset: PeriodPreset) {
58
+ heldDay.value = null;
33
59
  draft.selectPreset(preset);
34
60
  const custom = draft.customRange.value;
35
61
  if (preset !== CUSTOM_PRESET || !custom) return;
@@ -42,12 +68,16 @@ export function usePeriodSelectorInteraction(
42
68
  isOpen.value = true;
43
69
  }
44
70
  function applyDraft() {
71
+ commitHeldDay();
45
72
  draft.apply();
46
73
  isOpen.value = false;
47
74
  }
48
75
  const draftCalendar = computed<CalendarRange>(() =>
49
76
  rangeToCalendar(draft.range.value ?? startingRange(new Date())),
50
77
  );
78
+ const fieldCalendar = computed(() =>
79
+ withHeldDay(draftCalendar.value, heldDay.value),
80
+ );
51
81
  const draftCompareCalendar = computed<CalendarRange | null>(() => {
52
82
  const compare = draft.compareRange.value;
53
83
  return compare ? rangeToCalendar(compare) : null;
@@ -57,27 +87,42 @@ export function usePeriodSelectorInteraction(
57
87
  anchor: CalendarRangeAnchor = "start",
58
88
  ) {
59
89
  if (!isCustomEnabled.value) return;
90
+ heldDay.value = null;
60
91
  draft.selectRange(
61
92
  calendarToRange(limitCalendarRange(range, props.maxDays, anchor)),
62
93
  );
63
94
  }
64
- function updateStart(value: DateValue | null | undefined) {
65
- const start = toCalendarDay(value);
66
- if (!start) return;
67
- const end = draftCalendar.value.end;
68
- selectCalendarRange(
69
- start.compare(end) > 0 ? { start, end: start } : { start, end },
70
- );
95
+ function typeDay(
96
+ anchor: CalendarRangeAnchor,
97
+ value: DateValue | null | undefined,
98
+ ) {
99
+ const day = toCalendarDay(value);
100
+ if (!day || !isCustomEnabled.value) return;
101
+ const range = { ...draftCalendar.value, [anchor]: day };
102
+ const fits =
103
+ range.start.compare(range.end) <= 0 &&
104
+ (!props.maxDays || calendarRangeDays(range) <= props.maxDays);
105
+ if (fits) {
106
+ selectCalendarRange(range, anchor);
107
+ return;
108
+ }
109
+ heldDay.value = { anchor, day };
110
+ draft.selectPreset(CUSTOM_PRESET);
71
111
  }
72
- function updateEnd(value: DateValue | null | undefined) {
73
- const end = toCalendarDay(value);
74
- if (!end) return;
75
- const start = draftCalendar.value.start;
112
+ function commitHeldDay() {
113
+ const held = heldDay.value;
114
+ if (!held) return;
115
+ const range = fieldCalendar.value;
76
116
  selectCalendarRange(
77
- end.compare(start) < 0 ? { start: end, end } : { start, end },
78
- "end",
117
+ range.start.compare(range.end) <= 0
118
+ ? range
119
+ : { start: held.day, end: held.day },
120
+ held.anchor,
79
121
  );
80
122
  }
123
+ function leaveField(event: FocusEvent) {
124
+ if (isLeavingField(event)) commitHeldDay();
125
+ }
81
126
  const segmentedPreset = computed<string | number | undefined>({
82
127
  get: () => period.preset.value,
83
128
  set: (value) => {
@@ -104,8 +149,9 @@ export function usePeriodSelectorInteraction(
104
149
  draftCalendar,
105
150
  draftCompareCalendar,
106
151
  selectCalendarRange,
107
- updateStart,
108
- updateEnd,
152
+ fieldCalendar,
153
+ typeDay,
154
+ leaveField,
109
155
  segmentedPreset,
110
156
  onSegmentedClick,
111
157
  };
@@ -0,0 +1 @@
1
+ export * from "../../build/utils/initials";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@antelopejs/dms",
3
- "version": "0.21.4-next.987.gb437fd0",
3
+ "version": "0.21.4-next.990.g2afafca",
4
4
  "description": "AntelopeJS DMS. Plug in your PostgreSQL, MySQL, MariaDB, MongoDB or RethinkDB database and your coding agent builds a back office and analytics dashboard as typed TypeScript. Real-time updates on the data the DMS manages.",
5
5
  "keywords": [
6
6
  "antelopejs",
@@ -89,7 +89,7 @@
89
89
  "@antelopejs/interface-data-api": ">=0.8.0 <0.9.0",
90
90
  "@antelopejs/interface-database": ">=0.4.0 <0.5.0",
91
91
  "@antelopejs/interface-database-decorators": ">=0.5.2 <0.6.0",
92
- "@antelopejs/interface-dms": "0.14.7-next.985.g3110f87",
92
+ "@antelopejs/interface-dms": "0.14.7-next.990.g2afafca",
93
93
  "@antelopejs/interface-dms-builder": "0.6.2-next.987.gb437fd0",
94
94
  "@antelopejs/interface-email": ">=0.2.1 <0.3.0",
95
95
  "@antelopejs/interface-file-storage": ">=0.1.4 <0.2.0",
@@ -212,7 +212,7 @@
212
212
  "optional": true
213
213
  }
214
214
  },
215
- "gitHead": "b437fd06a397f00a33e397c7c9100a29703956b7",
215
+ "gitHead": "2afafcaab1a3a505d5aa025b77850f99e73d56ce",
216
216
  "scripts": {
217
217
  "build": "pnpm --filter @antelopejs/interface-dms --filter @antelopejs/interface-dms-builder build && rimraf dist && antelopejs-tsc && tsc-alias && tsc -p e2e/tsconfig.types.json",
218
218
  "dev": "ajs project run --inspect -w -p playground",