@vadem/ui 0.0.0-stage → 0.0.2
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.
- package/LICENSE-lucide.txt +43 -0
- package/README.md +93 -2
- package/fesm2022/vadem-ui-accordion.mjs +139 -0
- package/fesm2022/vadem-ui-accordion.mjs.map +1 -0
- package/fesm2022/vadem-ui-active-filters.mjs +355 -0
- package/fesm2022/vadem-ui-active-filters.mjs.map +1 -0
- package/fesm2022/vadem-ui-alert-dialog.mjs +433 -0
- package/fesm2022/vadem-ui-alert-dialog.mjs.map +1 -0
- package/fesm2022/vadem-ui-alert.mjs +266 -0
- package/fesm2022/vadem-ui-alert.mjs.map +1 -0
- package/fesm2022/vadem-ui-autocomplete.mjs +715 -0
- package/fesm2022/vadem-ui-autocomplete.mjs.map +1 -0
- package/fesm2022/vadem-ui-avatar.mjs +219 -0
- package/fesm2022/vadem-ui-avatar.mjs.map +1 -0
- package/fesm2022/vadem-ui-badge.mjs +86 -0
- package/fesm2022/vadem-ui-badge.mjs.map +1 -0
- package/fesm2022/vadem-ui-breadcrumbs.mjs +61 -0
- package/fesm2022/vadem-ui-breadcrumbs.mjs.map +1 -0
- package/fesm2022/vadem-ui-button.mjs +220 -0
- package/fesm2022/vadem-ui-button.mjs.map +1 -0
- package/fesm2022/vadem-ui-calendar.mjs +1314 -0
- package/fesm2022/vadem-ui-calendar.mjs.map +1 -0
- package/fesm2022/vadem-ui-card.mjs +271 -0
- package/fesm2022/vadem-ui-card.mjs.map +1 -0
- package/fesm2022/vadem-ui-character-count.mjs +269 -0
- package/fesm2022/vadem-ui-character-count.mjs.map +1 -0
- package/fesm2022/vadem-ui-chart.mjs +1984 -0
- package/fesm2022/vadem-ui-chart.mjs.map +1 -0
- package/fesm2022/vadem-ui-checkbox.mjs +67 -0
- package/fesm2022/vadem-ui-checkbox.mjs.map +1 -0
- package/fesm2022/vadem-ui-color-picker.mjs +815 -0
- package/fesm2022/vadem-ui-color-picker.mjs.map +1 -0
- package/fesm2022/vadem-ui-command.mjs +735 -0
- package/fesm2022/vadem-ui-command.mjs.map +1 -0
- package/fesm2022/vadem-ui-copy-button.mjs +375 -0
- package/fesm2022/vadem-ui-copy-button.mjs.map +1 -0
- package/fesm2022/vadem-ui-date-range-picker.mjs +1011 -0
- package/fesm2022/vadem-ui-date-range-picker.mjs.map +1 -0
- package/fesm2022/vadem-ui-description-list.mjs +59 -0
- package/fesm2022/vadem-ui-description-list.mjs.map +1 -0
- package/fesm2022/vadem-ui-dialog.mjs +587 -0
- package/fesm2022/vadem-ui-dialog.mjs.map +1 -0
- package/fesm2022/vadem-ui-dropzone.mjs +176 -0
- package/fesm2022/vadem-ui-dropzone.mjs.map +1 -0
- package/fesm2022/vadem-ui-editable-text.mjs +641 -0
- package/fesm2022/vadem-ui-editable-text.mjs.map +1 -0
- package/fesm2022/vadem-ui-empty-state.mjs +175 -0
- package/fesm2022/vadem-ui-empty-state.mjs.map +1 -0
- package/fesm2022/vadem-ui-expandable-text.mjs +244 -0
- package/fesm2022/vadem-ui-expandable-text.mjs.map +1 -0
- package/fesm2022/vadem-ui-field.mjs +583 -0
- package/fesm2022/vadem-ui-field.mjs.map +1 -0
- package/fesm2022/vadem-ui-file-preview.mjs +532 -0
- package/fesm2022/vadem-ui-file-preview.mjs.map +1 -0
- package/fesm2022/vadem-ui-file-size.mjs +83 -0
- package/fesm2022/vadem-ui-file-size.mjs.map +1 -0
- package/fesm2022/vadem-ui-form-error-summary.mjs +201 -0
- package/fesm2022/vadem-ui-form-error-summary.mjs.map +1 -0
- package/fesm2022/vadem-ui-icon.mjs +303 -0
- package/fesm2022/vadem-ui-icon.mjs.map +1 -0
- package/fesm2022/vadem-ui-input.mjs +120 -0
- package/fesm2022/vadem-ui-input.mjs.map +1 -0
- package/fesm2022/vadem-ui-kbd.mjs +286 -0
- package/fesm2022/vadem-ui-kbd.mjs.map +1 -0
- package/fesm2022/vadem-ui-keyboard.mjs +105 -0
- package/fesm2022/vadem-ui-keyboard.mjs.map +1 -0
- package/fesm2022/vadem-ui-locale.mjs +443 -0
- package/fesm2022/vadem-ui-locale.mjs.map +1 -0
- package/fesm2022/vadem-ui-menu.mjs +657 -0
- package/fesm2022/vadem-ui-menu.mjs.map +1 -0
- package/fesm2022/vadem-ui-navigation-list.mjs +130 -0
- package/fesm2022/vadem-ui-navigation-list.mjs.map +1 -0
- package/fesm2022/vadem-ui-number-input.mjs +264 -0
- package/fesm2022/vadem-ui-number-input.mjs.map +1 -0
- package/fesm2022/vadem-ui-otp-input.mjs +86 -0
- package/fesm2022/vadem-ui-otp-input.mjs.map +1 -0
- package/fesm2022/vadem-ui-pagination.mjs +353 -0
- package/fesm2022/vadem-ui-pagination.mjs.map +1 -0
- package/fesm2022/vadem-ui-password-input.mjs +213 -0
- package/fesm2022/vadem-ui-password-input.mjs.map +1 -0
- package/fesm2022/vadem-ui-popover.mjs +178 -0
- package/fesm2022/vadem-ui-popover.mjs.map +1 -0
- package/fesm2022/vadem-ui-progress.mjs +331 -0
- package/fesm2022/vadem-ui-progress.mjs.map +1 -0
- package/fesm2022/vadem-ui-radio.mjs +39 -0
- package/fesm2022/vadem-ui-radio.mjs.map +1 -0
- package/fesm2022/vadem-ui-range-slider.mjs +561 -0
- package/fesm2022/vadem-ui-range-slider.mjs.map +1 -0
- package/fesm2022/vadem-ui-rating.mjs +404 -0
- package/fesm2022/vadem-ui-rating.mjs.map +1 -0
- package/fesm2022/vadem-ui-relative-time.mjs +217 -0
- package/fesm2022/vadem-ui-relative-time.mjs.map +1 -0
- package/fesm2022/vadem-ui-reorder-list.mjs +601 -0
- package/fesm2022/vadem-ui-reorder-list.mjs.map +1 -0
- package/fesm2022/vadem-ui-scroll-area.mjs +65 -0
- package/fesm2022/vadem-ui-scroll-area.mjs.map +1 -0
- package/fesm2022/vadem-ui-search-input.mjs +307 -0
- package/fesm2022/vadem-ui-search-input.mjs.map +1 -0
- package/fesm2022/vadem-ui-segmented.mjs +297 -0
- package/fesm2022/vadem-ui-segmented.mjs.map +1 -0
- package/fesm2022/vadem-ui-select.mjs +1462 -0
- package/fesm2022/vadem-ui-select.mjs.map +1 -0
- package/fesm2022/vadem-ui-sidebar.mjs +493 -0
- package/fesm2022/vadem-ui-sidebar.mjs.map +1 -0
- package/fesm2022/vadem-ui-skeleton.mjs +106 -0
- package/fesm2022/vadem-ui-skeleton.mjs.map +1 -0
- package/fesm2022/vadem-ui-slider.mjs +60 -0
- package/fesm2022/vadem-ui-slider.mjs.map +1 -0
- package/fesm2022/vadem-ui-splitter.mjs +438 -0
- package/fesm2022/vadem-ui-splitter.mjs.map +1 -0
- package/fesm2022/vadem-ui-stat.mjs +369 -0
- package/fesm2022/vadem-ui-stat.mjs.map +1 -0
- package/fesm2022/vadem-ui-stepper.mjs +483 -0
- package/fesm2022/vadem-ui-stepper.mjs.map +1 -0
- package/fesm2022/vadem-ui-switch.mjs +45 -0
- package/fesm2022/vadem-ui-switch.mjs.map +1 -0
- package/fesm2022/vadem-ui-table.mjs +593 -0
- package/fesm2022/vadem-ui-table.mjs.map +1 -0
- package/fesm2022/vadem-ui-tabs.mjs +405 -0
- package/fesm2022/vadem-ui-tabs.mjs.map +1 -0
- package/fesm2022/vadem-ui-tag-input.mjs +685 -0
- package/fesm2022/vadem-ui-tag-input.mjs.map +1 -0
- package/fesm2022/vadem-ui-text-highlight.mjs +126 -0
- package/fesm2022/vadem-ui-text-highlight.mjs.map +1 -0
- package/fesm2022/vadem-ui-time-input.mjs +430 -0
- package/fesm2022/vadem-ui-time-input.mjs.map +1 -0
- package/fesm2022/vadem-ui-timeline.mjs +313 -0
- package/fesm2022/vadem-ui-timeline.mjs.map +1 -0
- package/fesm2022/vadem-ui-toast.mjs +397 -0
- package/fesm2022/vadem-ui-toast.mjs.map +1 -0
- package/fesm2022/vadem-ui-toolbar.mjs +396 -0
- package/fesm2022/vadem-ui-toolbar.mjs.map +1 -0
- package/fesm2022/vadem-ui-tooltip.mjs +218 -0
- package/fesm2022/vadem-ui-tooltip.mjs.map +1 -0
- package/fesm2022/vadem-ui-tree.mjs +551 -0
- package/fesm2022/vadem-ui-tree.mjs.map +1 -0
- package/fesm2022/vadem-ui-upload-list.mjs +408 -0
- package/fesm2022/vadem-ui-upload-list.mjs.map +1 -0
- package/fesm2022/vadem-ui.mjs +4 -0
- package/fesm2022/vadem-ui.mjs.map +1 -0
- package/fonts/jetbrains-mono/OFL.txt +93 -0
- package/fonts/jetbrains-mono/jetbrains-mono-cyrillic.woff2 +0 -0
- package/fonts/jetbrains-mono/jetbrains-mono-latin.woff2 +0 -0
- package/fonts/manrope/OFL.txt +93 -0
- package/fonts/manrope/manrope-cyrillic.woff2 +0 -0
- package/fonts/manrope/manrope-latin.woff2 +0 -0
- package/package.json +329 -3
- package/styles/base.css +160 -0
- package/styles/components/accordion.css +130 -0
- package/styles/components/active-filters.css +42 -0
- package/styles/components/alert-dialog.css +34 -0
- package/styles/components/alert.css +159 -0
- package/styles/components/autocomplete.css +97 -0
- package/styles/components/avatar.css +90 -0
- package/styles/components/badge.css +91 -0
- package/styles/components/breadcrumbs.css +94 -0
- package/styles/components/button.css +174 -0
- package/styles/components/calendar.css +186 -0
- package/styles/components/card.css +206 -0
- package/styles/components/character-count.css +41 -0
- package/styles/components/chart.css +308 -0
- package/styles/components/checkbox.css +115 -0
- package/styles/components/color-picker.css +158 -0
- package/styles/components/command.css +175 -0
- package/styles/components/copy-button.css +58 -0
- package/styles/components/date-range-picker.css +153 -0
- package/styles/components/description-list.css +69 -0
- package/styles/components/dialog.css +334 -0
- package/styles/components/dropzone.css +89 -0
- package/styles/components/editable-text.css +58 -0
- package/styles/components/empty-state.css +72 -0
- package/styles/components/expandable-text.css +24 -0
- package/styles/components/field.css +148 -0
- package/styles/components/file-preview.css +65 -0
- package/styles/components/form-error-summary.css +71 -0
- package/styles/components/icon.css +38 -0
- package/styles/components/index.css +80 -0
- package/styles/components/input.css +171 -0
- package/styles/components/kbd.css +42 -0
- package/styles/components/menu.css +168 -0
- package/styles/components/multi-select.css +156 -0
- package/styles/components/navigation-list.css +147 -0
- package/styles/components/number-input.css +33 -0
- package/styles/components/otp-input.css +26 -0
- package/styles/components/pagination.css +127 -0
- package/styles/components/password-input.css +20 -0
- package/styles/components/popover.css +93 -0
- package/styles/components/progress-ring.css +112 -0
- package/styles/components/progress.css +162 -0
- package/styles/components/radio.css +117 -0
- package/styles/components/range-slider.css +158 -0
- package/styles/components/rating.css +100 -0
- package/styles/components/reorder-list.css +143 -0
- package/styles/components/scroll-area.css +39 -0
- package/styles/components/search-input.css +25 -0
- package/styles/components/segmented.css +136 -0
- package/styles/components/select.css +257 -0
- package/styles/components/sidebar.css +105 -0
- package/styles/components/skeleton.css +83 -0
- package/styles/components/slider.css +132 -0
- package/styles/components/splitter.css +83 -0
- package/styles/components/stat.css +62 -0
- package/styles/components/stepper.css +236 -0
- package/styles/components/switch.css +107 -0
- package/styles/components/table.css +195 -0
- package/styles/components/tabs.css +198 -0
- package/styles/components/tag-input.css +138 -0
- package/styles/components/text-highlight.css +22 -0
- package/styles/components/time-input.css +96 -0
- package/styles/components/timeline.css +182 -0
- package/styles/components/toast.css +146 -0
- package/styles/components/toolbar.css +72 -0
- package/styles/components/tooltip.css +93 -0
- package/styles/components/tree.css +88 -0
- package/styles/components/upload-list.css +113 -0
- package/styles/fonts.css +67 -0
- package/styles/index.css +14 -0
- package/styles/reset.css +57 -0
- package/styles/tokens/primitives.css +364 -0
- package/styles/tokens/semantic.css +233 -0
- package/types/vadem-ui-accordion.d.ts +43 -0
- package/types/vadem-ui-active-filters.d.ts +73 -0
- package/types/vadem-ui-alert-dialog.d.ts +87 -0
- package/types/vadem-ui-alert.d.ts +64 -0
- package/types/vadem-ui-autocomplete.d.ts +156 -0
- package/types/vadem-ui-avatar.d.ts +59 -0
- package/types/vadem-ui-badge.d.ts +25 -0
- package/types/vadem-ui-breadcrumbs.d.ts +22 -0
- package/types/vadem-ui-button.d.ts +52 -0
- package/types/vadem-ui-calendar.d.ts +327 -0
- package/types/vadem-ui-card.d.ts +58 -0
- package/types/vadem-ui-character-count.d.ts +71 -0
- package/types/vadem-ui-chart.d.ts +452 -0
- package/types/vadem-ui-checkbox.d.ts +20 -0
- package/types/vadem-ui-color-picker.d.ts +171 -0
- package/types/vadem-ui-command.d.ts +145 -0
- package/types/vadem-ui-copy-button.d.ts +90 -0
- package/types/vadem-ui-date-range-picker.d.ts +216 -0
- package/types/vadem-ui-description-list.d.ts +15 -0
- package/types/vadem-ui-dialog.d.ts +174 -0
- package/types/vadem-ui-dropzone.d.ts +73 -0
- package/types/vadem-ui-editable-text.d.ts +141 -0
- package/types/vadem-ui-empty-state.d.ts +34 -0
- package/types/vadem-ui-expandable-text.d.ts +52 -0
- package/types/vadem-ui-field.d.ts +180 -0
- package/types/vadem-ui-file-preview.d.ts +108 -0
- package/types/vadem-ui-file-size.d.ts +18 -0
- package/types/vadem-ui-form-error-summary.d.ts +46 -0
- package/types/vadem-ui-icon.d.ts +152 -0
- package/types/vadem-ui-input.d.ts +31 -0
- package/types/vadem-ui-kbd.d.ts +66 -0
- package/types/vadem-ui-keyboard.d.ts +61 -0
- package/types/vadem-ui-locale.d.ts +241 -0
- package/types/vadem-ui-menu.d.ts +134 -0
- package/types/vadem-ui-navigation-list.d.ts +28 -0
- package/types/vadem-ui-number-input.d.ts +39 -0
- package/types/vadem-ui-otp-input.d.ts +15 -0
- package/types/vadem-ui-pagination.d.ts +96 -0
- package/types/vadem-ui-password-input.d.ts +36 -0
- package/types/vadem-ui-popover.d.ts +48 -0
- package/types/vadem-ui-progress.d.ts +95 -0
- package/types/vadem-ui-radio.d.ts +11 -0
- package/types/vadem-ui-range-slider.d.ts +136 -0
- package/types/vadem-ui-rating.d.ts +95 -0
- package/types/vadem-ui-relative-time.d.ts +58 -0
- package/types/vadem-ui-reorder-list.d.ts +120 -0
- package/types/vadem-ui-scroll-area.d.ts +13 -0
- package/types/vadem-ui-search-input.d.ts +58 -0
- package/types/vadem-ui-segmented.d.ts +76 -0
- package/types/vadem-ui-select.d.ts +303 -0
- package/types/vadem-ui-sidebar.d.ts +70 -0
- package/types/vadem-ui-skeleton.d.ts +28 -0
- package/types/vadem-ui-slider.d.ts +17 -0
- package/types/vadem-ui-splitter.d.ts +99 -0
- package/types/vadem-ui-stat.d.ts +101 -0
- package/types/vadem-ui-stepper.d.ts +108 -0
- package/types/vadem-ui-switch.d.ts +10 -0
- package/types/vadem-ui-table.d.ts +172 -0
- package/types/vadem-ui-tabs.d.ts +101 -0
- package/types/vadem-ui-tag-input.d.ts +170 -0
- package/types/vadem-ui-text-highlight.d.ts +27 -0
- package/types/vadem-ui-time-input.d.ts +47 -0
- package/types/vadem-ui-timeline.d.ts +54 -0
- package/types/vadem-ui-toast.d.ts +104 -0
- package/types/vadem-ui-toolbar.d.ts +80 -0
- package/types/vadem-ui-tooltip.d.ts +71 -0
- package/types/vadem-ui-tree.d.ts +123 -0
- package/types/vadem-ui-upload-list.d.ts +70 -0
- package/types/vadem-ui.d.ts +1 -0
|
@@ -0,0 +1,404 @@
|
|
|
1
|
+
import * as i0 from "@angular/core";
|
|
2
|
+
import { ChangeDetectionStrategy, Component, DestroyRef, ElementRef, Injector, ViewEncapsulation, booleanAttribute, computed, inject, input, model, output, signal } from "@angular/core";
|
|
3
|
+
import { NgControl } from "@angular/forms";
|
|
4
|
+
import { FormField } from "@angular/forms/signals";
|
|
5
|
+
import { VD_FIELD, vdNgControlState, vdUniqueId } from "@vadem/ui/field";
|
|
6
|
+
import { VdIcon } from "@vadem/ui/icon";
|
|
7
|
+
import { vdTexts } from "@vadem/ui/locale";
|
|
8
|
+
function vdRatingValue(value) {
|
|
9
|
+
return typeof value === "number" && Number.isInteger(value) && value >= 1 && value <= 5 ? value : 0;
|
|
10
|
+
}
|
|
11
|
+
function vdRatingKey(value, key, rtl) {
|
|
12
|
+
if (key === "Home") return 1;
|
|
13
|
+
if (key === "End") return 5;
|
|
14
|
+
const delta = key === "ArrowDown" ? 1 : key === "ArrowUp" ? -1 : key === "ArrowRight" ? rtl ? -1 : 1 : key === "ArrowLeft" ? rtl ? 1 : -1 : 0;
|
|
15
|
+
if (!delta) return null;
|
|
16
|
+
return (Math.max(1, vdRatingValue(value)) - 1 + delta + 5) % 5 + 1;
|
|
17
|
+
}
|
|
18
|
+
var VdRating = class VdRating {
|
|
19
|
+
value = model(0, ...ngDevMode ? [{ debugName: "value" }] : /* istanbul ignore next */ []);
|
|
20
|
+
label = input.required(...ngDevMode ? [{ debugName: "label" }] : /* istanbul ignore next */ []);
|
|
21
|
+
starLabel = input(...ngDevMode ? [void 0, { debugName: "starLabel" }] : /* istanbul ignore next */ []);
|
|
22
|
+
t = vdTexts("rating", { starLabel: this.starLabel });
|
|
23
|
+
size = input("md", ...ngDevMode ? [{ debugName: "size" }] : /* istanbul ignore next */ []);
|
|
24
|
+
disabled = input(false, {
|
|
25
|
+
...ngDevMode ? { debugName: "disabled" } : /* istanbul ignore next */ {},
|
|
26
|
+
transform: booleanAttribute
|
|
27
|
+
});
|
|
28
|
+
readonly = input(false, {
|
|
29
|
+
...ngDevMode ? { debugName: "readonly" } : /* istanbul ignore next */ {},
|
|
30
|
+
transform: booleanAttribute
|
|
31
|
+
});
|
|
32
|
+
invalid = input(false, {
|
|
33
|
+
...ngDevMode ? { debugName: "invalid" } : /* istanbul ignore next */ {},
|
|
34
|
+
transform: booleanAttribute
|
|
35
|
+
});
|
|
36
|
+
touched = input(false, {
|
|
37
|
+
...ngDevMode ? { debugName: "touched" } : /* istanbul ignore next */ {},
|
|
38
|
+
transform: booleanAttribute
|
|
39
|
+
});
|
|
40
|
+
required = input(false, {
|
|
41
|
+
...ngDevMode ? { debugName: "required" } : /* istanbul ignore next */ {},
|
|
42
|
+
transform: booleanAttribute
|
|
43
|
+
});
|
|
44
|
+
touch = output();
|
|
45
|
+
controlId = vdUniqueId("vd-rating");
|
|
46
|
+
labelId = `${this.controlId}-label`;
|
|
47
|
+
stars = [
|
|
48
|
+
1,
|
|
49
|
+
2,
|
|
50
|
+
3,
|
|
51
|
+
4,
|
|
52
|
+
5
|
|
53
|
+
];
|
|
54
|
+
preview = signal(0, ...ngDevMode ? [{ debugName: "preview" }] : /* istanbul ignore next */ []);
|
|
55
|
+
selected = computed(() => vdRatingValue(this.value()), ...ngDevMode ? [{ debugName: "selected" }] : /* istanbul ignore next */ []);
|
|
56
|
+
filled = computed(() => !this.locked() && this.preview() ? this.preview() : this.selected(), ...ngDevMode ? [{ debugName: "filled" }] : /* istanbul ignore next */ []);
|
|
57
|
+
field = inject(VD_FIELD, { optional: true });
|
|
58
|
+
host = inject(ElementRef).nativeElement;
|
|
59
|
+
injector = inject(Injector);
|
|
60
|
+
destroyRef = inject(DestroyRef);
|
|
61
|
+
formBound = signal(false, ...ngDevMode ? [{ debugName: "formBound" }] : /* istanbul ignore next */ []);
|
|
62
|
+
ngSource = signal(null, ...ngDevMode ? [{ debugName: "ngSource" }] : /* istanbul ignore next */ []);
|
|
63
|
+
ngState = computed(() => this.ngSource()?.() ?? {
|
|
64
|
+
invalid: false,
|
|
65
|
+
touched: false,
|
|
66
|
+
disabled: false,
|
|
67
|
+
required: false
|
|
68
|
+
}, ...ngDevMode ? [{ debugName: "ngState" }] : /* istanbul ignore next */ []);
|
|
69
|
+
isDisabled = computed(() => this.disabled() || this.ngState().disabled, ...ngDevMode ? [{ debugName: "isDisabled" }] : /* istanbul ignore next */ []);
|
|
70
|
+
locked = computed(() => this.isDisabled() || this.readonly(), ...ngDevMode ? [{ debugName: "locked" }] : /* istanbul ignore next */ []);
|
|
71
|
+
isRequired = computed(() => this.required() || this.ngState().required, ...ngDevMode ? [{ debugName: "isRequired" }] : /* istanbul ignore next */ []);
|
|
72
|
+
showInvalid = computed(() => this.invalid() && (!this.formBound() || this.touched()) || this.ngState().invalid && this.ngState().touched, ...ngDevMode ? [{ debugName: "showInvalid" }] : /* istanbul ignore next */ []);
|
|
73
|
+
constructor() {
|
|
74
|
+
const control = {
|
|
75
|
+
id: signal(this.controlId),
|
|
76
|
+
invalid: this.showInvalid,
|
|
77
|
+
required: this.isRequired,
|
|
78
|
+
disabled: this.isDisabled
|
|
79
|
+
};
|
|
80
|
+
this.field?.register(control);
|
|
81
|
+
this.destroyRef.onDestroy(() => this.field?.unregister(control));
|
|
82
|
+
}
|
|
83
|
+
ngOnInit() {
|
|
84
|
+
const ng = this.injector.get(NgControl, null, {
|
|
85
|
+
self: true,
|
|
86
|
+
optional: true
|
|
87
|
+
});
|
|
88
|
+
this.formBound.set(!!ng || !!this.injector.get(FormField, null, {
|
|
89
|
+
self: true,
|
|
90
|
+
optional: true
|
|
91
|
+
}));
|
|
92
|
+
this.ngSource.set(vdNgControlState(ng, this.destroyRef));
|
|
93
|
+
}
|
|
94
|
+
choose(value) {
|
|
95
|
+
if (!this.locked()) {
|
|
96
|
+
this.preview.set(0);
|
|
97
|
+
this.value.set(value);
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
onKeydown(event, star) {
|
|
101
|
+
if (event.altKey || event.ctrlKey || event.metaKey || event.shiftKey) return;
|
|
102
|
+
const next = vdRatingKey(star, event.key, this.host.matches(":dir(rtl)"));
|
|
103
|
+
if (next === null) return;
|
|
104
|
+
event.preventDefault();
|
|
105
|
+
if (this.locked()) return;
|
|
106
|
+
this.choose(next);
|
|
107
|
+
this.host.querySelectorAll("button")[next - 1]?.focus();
|
|
108
|
+
}
|
|
109
|
+
onFocusOut(event) {
|
|
110
|
+
if (!event.relatedTarget || !this.host.contains(event.relatedTarget)) this.touch.emit();
|
|
111
|
+
}
|
|
112
|
+
static ɵfac = i0.ɵɵngDeclareFactory({
|
|
113
|
+
minVersion: "12.0.0",
|
|
114
|
+
version: "22.2.1",
|
|
115
|
+
ngImport: i0,
|
|
116
|
+
type: VdRating,
|
|
117
|
+
deps: [],
|
|
118
|
+
target: i0.ɵɵFactoryTarget.Component
|
|
119
|
+
});
|
|
120
|
+
static ɵcmp = i0.ɵɵngDeclareComponent({
|
|
121
|
+
minVersion: "17.0.0",
|
|
122
|
+
version: "22.2.1",
|
|
123
|
+
type: VdRating,
|
|
124
|
+
isStandalone: true,
|
|
125
|
+
selector: "vd-rating",
|
|
126
|
+
inputs: {
|
|
127
|
+
value: {
|
|
128
|
+
classPropertyName: "value",
|
|
129
|
+
publicName: "value",
|
|
130
|
+
isSignal: true,
|
|
131
|
+
isRequired: false,
|
|
132
|
+
transformFunction: null
|
|
133
|
+
},
|
|
134
|
+
label: {
|
|
135
|
+
classPropertyName: "label",
|
|
136
|
+
publicName: "label",
|
|
137
|
+
isSignal: true,
|
|
138
|
+
isRequired: true,
|
|
139
|
+
transformFunction: null
|
|
140
|
+
},
|
|
141
|
+
starLabel: {
|
|
142
|
+
classPropertyName: "starLabel",
|
|
143
|
+
publicName: "starLabel",
|
|
144
|
+
isSignal: true,
|
|
145
|
+
isRequired: false,
|
|
146
|
+
transformFunction: null
|
|
147
|
+
},
|
|
148
|
+
size: {
|
|
149
|
+
classPropertyName: "size",
|
|
150
|
+
publicName: "size",
|
|
151
|
+
isSignal: true,
|
|
152
|
+
isRequired: false,
|
|
153
|
+
transformFunction: null
|
|
154
|
+
},
|
|
155
|
+
disabled: {
|
|
156
|
+
classPropertyName: "disabled",
|
|
157
|
+
publicName: "disabled",
|
|
158
|
+
isSignal: true,
|
|
159
|
+
isRequired: false,
|
|
160
|
+
transformFunction: null
|
|
161
|
+
},
|
|
162
|
+
readonly: {
|
|
163
|
+
classPropertyName: "readonly",
|
|
164
|
+
publicName: "readonly",
|
|
165
|
+
isSignal: true,
|
|
166
|
+
isRequired: false,
|
|
167
|
+
transformFunction: null
|
|
168
|
+
},
|
|
169
|
+
invalid: {
|
|
170
|
+
classPropertyName: "invalid",
|
|
171
|
+
publicName: "invalid",
|
|
172
|
+
isSignal: true,
|
|
173
|
+
isRequired: false,
|
|
174
|
+
transformFunction: null
|
|
175
|
+
},
|
|
176
|
+
touched: {
|
|
177
|
+
classPropertyName: "touched",
|
|
178
|
+
publicName: "touched",
|
|
179
|
+
isSignal: true,
|
|
180
|
+
isRequired: false,
|
|
181
|
+
transformFunction: null
|
|
182
|
+
},
|
|
183
|
+
required: {
|
|
184
|
+
classPropertyName: "required",
|
|
185
|
+
publicName: "required",
|
|
186
|
+
isSignal: true,
|
|
187
|
+
isRequired: false,
|
|
188
|
+
transformFunction: null
|
|
189
|
+
}
|
|
190
|
+
},
|
|
191
|
+
outputs: {
|
|
192
|
+
value: "valueChange",
|
|
193
|
+
touch: "touch"
|
|
194
|
+
},
|
|
195
|
+
host: {
|
|
196
|
+
listeners: { "focusout": "onFocusOut($event)" },
|
|
197
|
+
properties: {
|
|
198
|
+
"attr.data-size": "size()",
|
|
199
|
+
"attr.data-invalid": "showInvalid() ? \"\" : null",
|
|
200
|
+
"attr.data-disabled": "isDisabled() ? \"\" : null",
|
|
201
|
+
"attr.data-readonly": "readonly() ? \"\" : null"
|
|
202
|
+
},
|
|
203
|
+
classAttribute: "vd-rating"
|
|
204
|
+
},
|
|
205
|
+
ngImport: i0,
|
|
206
|
+
template: `
|
|
207
|
+
<fieldset
|
|
208
|
+
class="vd-rating__group"
|
|
209
|
+
role="radiogroup"
|
|
210
|
+
[id]="controlId"
|
|
211
|
+
[attr.aria-required]="isRequired() || null"
|
|
212
|
+
[attr.aria-invalid]="showInvalid() || null"
|
|
213
|
+
[attr.aria-readonly]="readonly() || null"
|
|
214
|
+
[attr.aria-disabled]="isDisabled() || null"
|
|
215
|
+
[attr.aria-describedby]="field?.describedBy() ?? null"
|
|
216
|
+
[attr.aria-labelledby]="labelId"
|
|
217
|
+
>
|
|
218
|
+
<legend class="vd-rating__label vd-field__label" [id]="labelId">
|
|
219
|
+
{{ label() }}
|
|
220
|
+
@if (isRequired()) {
|
|
221
|
+
<span class="vd-field__required" aria-hidden="true">*</span>
|
|
222
|
+
}
|
|
223
|
+
</legend>
|
|
224
|
+
<div class="vd-rating__stars" (pointerleave)="preview.set(0)">
|
|
225
|
+
@for (star of stars; track star) {
|
|
226
|
+
<button
|
|
227
|
+
type="button"
|
|
228
|
+
class="vd-rating__star"
|
|
229
|
+
role="radio"
|
|
230
|
+
[attr.aria-label]="t().starLabel(star)"
|
|
231
|
+
[attr.aria-checked]="selected() === star"
|
|
232
|
+
[attr.tabindex]="(selected() || 1) === star ? 0 : -1"
|
|
233
|
+
[disabled]="isDisabled()"
|
|
234
|
+
[attr.data-filled]="star <= filled() ? '' : null"
|
|
235
|
+
[attr.data-preview]="!locked() && preview() > 0 ? '' : null"
|
|
236
|
+
(pointerenter)="preview.set(star)"
|
|
237
|
+
(click)="choose(star)"
|
|
238
|
+
(keydown)="onKeydown($event, star)"
|
|
239
|
+
>
|
|
240
|
+
<vd-icon name="star" />
|
|
241
|
+
</button>
|
|
242
|
+
}
|
|
243
|
+
</div>
|
|
244
|
+
</fieldset>
|
|
245
|
+
`,
|
|
246
|
+
isInline: true,
|
|
247
|
+
dependencies: [{
|
|
248
|
+
kind: "component",
|
|
249
|
+
type: VdIcon,
|
|
250
|
+
selector: "vd-icon",
|
|
251
|
+
inputs: ["name", "label"]
|
|
252
|
+
}],
|
|
253
|
+
changeDetection: i0.ChangeDetectionStrategy.OnPush,
|
|
254
|
+
encapsulation: i0.ViewEncapsulation.None
|
|
255
|
+
});
|
|
256
|
+
};
|
|
257
|
+
i0.ɵɵngDeclareClassMetadata({
|
|
258
|
+
minVersion: "12.0.0",
|
|
259
|
+
version: "22.2.1",
|
|
260
|
+
ngImport: i0,
|
|
261
|
+
type: VdRating,
|
|
262
|
+
decorators: [{
|
|
263
|
+
type: Component,
|
|
264
|
+
args: [{
|
|
265
|
+
selector: "vd-rating",
|
|
266
|
+
imports: [VdIcon],
|
|
267
|
+
template: `
|
|
268
|
+
<fieldset
|
|
269
|
+
class="vd-rating__group"
|
|
270
|
+
role="radiogroup"
|
|
271
|
+
[id]="controlId"
|
|
272
|
+
[attr.aria-required]="isRequired() || null"
|
|
273
|
+
[attr.aria-invalid]="showInvalid() || null"
|
|
274
|
+
[attr.aria-readonly]="readonly() || null"
|
|
275
|
+
[attr.aria-disabled]="isDisabled() || null"
|
|
276
|
+
[attr.aria-describedby]="field?.describedBy() ?? null"
|
|
277
|
+
[attr.aria-labelledby]="labelId"
|
|
278
|
+
>
|
|
279
|
+
<legend class="vd-rating__label vd-field__label" [id]="labelId">
|
|
280
|
+
{{ label() }}
|
|
281
|
+
@if (isRequired()) {
|
|
282
|
+
<span class="vd-field__required" aria-hidden="true">*</span>
|
|
283
|
+
}
|
|
284
|
+
</legend>
|
|
285
|
+
<div class="vd-rating__stars" (pointerleave)="preview.set(0)">
|
|
286
|
+
@for (star of stars; track star) {
|
|
287
|
+
<button
|
|
288
|
+
type="button"
|
|
289
|
+
class="vd-rating__star"
|
|
290
|
+
role="radio"
|
|
291
|
+
[attr.aria-label]="t().starLabel(star)"
|
|
292
|
+
[attr.aria-checked]="selected() === star"
|
|
293
|
+
[attr.tabindex]="(selected() || 1) === star ? 0 : -1"
|
|
294
|
+
[disabled]="isDisabled()"
|
|
295
|
+
[attr.data-filled]="star <= filled() ? '' : null"
|
|
296
|
+
[attr.data-preview]="!locked() && preview() > 0 ? '' : null"
|
|
297
|
+
(pointerenter)="preview.set(star)"
|
|
298
|
+
(click)="choose(star)"
|
|
299
|
+
(keydown)="onKeydown($event, star)"
|
|
300
|
+
>
|
|
301
|
+
<vd-icon name="star" />
|
|
302
|
+
</button>
|
|
303
|
+
}
|
|
304
|
+
</div>
|
|
305
|
+
</fieldset>
|
|
306
|
+
`,
|
|
307
|
+
host: {
|
|
308
|
+
class: "vd-rating",
|
|
309
|
+
"[attr.data-size]": "size()",
|
|
310
|
+
"[attr.data-invalid]": "showInvalid() ? \"\" : null",
|
|
311
|
+
"[attr.data-disabled]": "isDisabled() ? \"\" : null",
|
|
312
|
+
"[attr.data-readonly]": "readonly() ? \"\" : null",
|
|
313
|
+
"(focusout)": "onFocusOut($event)"
|
|
314
|
+
},
|
|
315
|
+
changeDetection: ChangeDetectionStrategy.OnPush,
|
|
316
|
+
encapsulation: ViewEncapsulation.None
|
|
317
|
+
}]
|
|
318
|
+
}],
|
|
319
|
+
ctorParameters: () => [],
|
|
320
|
+
propDecorators: {
|
|
321
|
+
value: [{
|
|
322
|
+
type: i0.Input,
|
|
323
|
+
args: [{
|
|
324
|
+
isSignal: true,
|
|
325
|
+
alias: "value",
|
|
326
|
+
required: false
|
|
327
|
+
}]
|
|
328
|
+
}, {
|
|
329
|
+
type: i0.Output,
|
|
330
|
+
args: ["valueChange"]
|
|
331
|
+
}],
|
|
332
|
+
label: [{
|
|
333
|
+
type: i0.Input,
|
|
334
|
+
args: [{
|
|
335
|
+
isSignal: true,
|
|
336
|
+
alias: "label",
|
|
337
|
+
required: true
|
|
338
|
+
}]
|
|
339
|
+
}],
|
|
340
|
+
starLabel: [{
|
|
341
|
+
type: i0.Input,
|
|
342
|
+
args: [{
|
|
343
|
+
isSignal: true,
|
|
344
|
+
alias: "starLabel",
|
|
345
|
+
required: false
|
|
346
|
+
}]
|
|
347
|
+
}],
|
|
348
|
+
size: [{
|
|
349
|
+
type: i0.Input,
|
|
350
|
+
args: [{
|
|
351
|
+
isSignal: true,
|
|
352
|
+
alias: "size",
|
|
353
|
+
required: false
|
|
354
|
+
}]
|
|
355
|
+
}],
|
|
356
|
+
disabled: [{
|
|
357
|
+
type: i0.Input,
|
|
358
|
+
args: [{
|
|
359
|
+
isSignal: true,
|
|
360
|
+
alias: "disabled",
|
|
361
|
+
required: false
|
|
362
|
+
}]
|
|
363
|
+
}],
|
|
364
|
+
readonly: [{
|
|
365
|
+
type: i0.Input,
|
|
366
|
+
args: [{
|
|
367
|
+
isSignal: true,
|
|
368
|
+
alias: "readonly",
|
|
369
|
+
required: false
|
|
370
|
+
}]
|
|
371
|
+
}],
|
|
372
|
+
invalid: [{
|
|
373
|
+
type: i0.Input,
|
|
374
|
+
args: [{
|
|
375
|
+
isSignal: true,
|
|
376
|
+
alias: "invalid",
|
|
377
|
+
required: false
|
|
378
|
+
}]
|
|
379
|
+
}],
|
|
380
|
+
touched: [{
|
|
381
|
+
type: i0.Input,
|
|
382
|
+
args: [{
|
|
383
|
+
isSignal: true,
|
|
384
|
+
alias: "touched",
|
|
385
|
+
required: false
|
|
386
|
+
}]
|
|
387
|
+
}],
|
|
388
|
+
required: [{
|
|
389
|
+
type: i0.Input,
|
|
390
|
+
args: [{
|
|
391
|
+
isSignal: true,
|
|
392
|
+
alias: "required",
|
|
393
|
+
required: false
|
|
394
|
+
}]
|
|
395
|
+
}],
|
|
396
|
+
touch: [{
|
|
397
|
+
type: i0.Output,
|
|
398
|
+
args: ["touch"]
|
|
399
|
+
}]
|
|
400
|
+
}
|
|
401
|
+
});
|
|
402
|
+
export { VdRating };
|
|
403
|
+
|
|
404
|
+
//# sourceMappingURL=vadem-ui-rating.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"vadem-ui-rating.mjs","names":[],"sources":["../../../projects/ui/rating/src/core/rating.ts","../../../projects/ui/rating/src/rating.ts"],"sourcesContent":["/** Only whole-star values 1..5 are displayed; 0 represents an unrated control. */\nexport function vdRatingValue(value: unknown): number {\n return typeof value === 'number' && Number.isInteger(value) && value >= 1 && value <= 5\n ? value\n : 0;\n}\n\n/** Radio navigation wraps in reading order; physical horizontal arrows respect RTL. */\nexport function vdRatingKey(value: number, key: string, rtl: boolean): number | null {\n if (key === 'Home') return 1;\n if (key === 'End') return 5;\n const delta =\n key === 'ArrowDown'\n ? 1\n : key === 'ArrowUp'\n ? -1\n : key === 'ArrowRight'\n ? rtl\n ? -1\n : 1\n : key === 'ArrowLeft'\n ? rtl\n ? 1\n : -1\n : 0;\n if (!delta) return null;\n return ((Math.max(1, vdRatingValue(value)) - 1 + delta + 5) % 5) + 1;\n}\n","import {\n ChangeDetectionStrategy,\n Component,\n DestroyRef,\n ElementRef,\n Injector,\n OnInit,\n Signal,\n ViewEncapsulation,\n booleanAttribute,\n computed,\n inject,\n input,\n model,\n output,\n signal,\n} from '@angular/core';\nimport { NgControl } from '@angular/forms';\nimport { FormField, FormValueControl } from '@angular/forms/signals';\nimport {\n VD_FIELD,\n VdFieldControl,\n VdNgControlState,\n vdNgControlState,\n vdUniqueId,\n} from '@vadem/ui/field';\nimport { VdIcon } from '@vadem/ui/icon';\nimport { vdRatingKey, vdRatingValue } from './core/rating';\nimport { vdTexts } from '@vadem/ui/locale';\n\nexport type VdRatingSize = 'sm' | 'md' | 'lg';\n\n/** Whole-star rating. The legend names the group; Field supplies hints/errors. */\n@Component({\n selector: 'vd-rating',\n imports: [VdIcon],\n template: `\n <fieldset\n class=\"vd-rating__group\"\n role=\"radiogroup\"\n [id]=\"controlId\"\n [attr.aria-required]=\"isRequired() || null\"\n [attr.aria-invalid]=\"showInvalid() || null\"\n [attr.aria-readonly]=\"readonly() || null\"\n [attr.aria-disabled]=\"isDisabled() || null\"\n [attr.aria-describedby]=\"field?.describedBy() ?? null\"\n [attr.aria-labelledby]=\"labelId\"\n >\n <legend class=\"vd-rating__label vd-field__label\" [id]=\"labelId\">\n {{ label() }}\n @if (isRequired()) {\n <span class=\"vd-field__required\" aria-hidden=\"true\">*</span>\n }\n </legend>\n <div class=\"vd-rating__stars\" (pointerleave)=\"preview.set(0)\">\n @for (star of stars; track star) {\n <button\n type=\"button\"\n class=\"vd-rating__star\"\n role=\"radio\"\n [attr.aria-label]=\"t().starLabel(star)\"\n [attr.aria-checked]=\"selected() === star\"\n [attr.tabindex]=\"(selected() || 1) === star ? 0 : -1\"\n [disabled]=\"isDisabled()\"\n [attr.data-filled]=\"star <= filled() ? '' : null\"\n [attr.data-preview]=\"!locked() && preview() > 0 ? '' : null\"\n (pointerenter)=\"preview.set(star)\"\n (click)=\"choose(star)\"\n (keydown)=\"onKeydown($event, star)\"\n >\n <vd-icon name=\"star\" />\n </button>\n }\n </div>\n </fieldset>\n `,\n host: {\n class: 'vd-rating',\n '[attr.data-size]': 'size()',\n '[attr.data-invalid]': 'showInvalid() ? \"\" : null',\n '[attr.data-disabled]': 'isDisabled() ? \"\" : null',\n '[attr.data-readonly]': 'readonly() ? \"\" : null',\n '(focusout)': 'onFocusOut($event)',\n },\n changeDetection: ChangeDetectionStrategy.OnPush,\n encapsulation: ViewEncapsulation.None,\n})\nexport class VdRating implements FormValueControl<number>, OnInit {\n readonly value = model(0);\n readonly label = input.required<string>();\n readonly starLabel = input<(value: number) => string>();\n /** Text inputs resolved against the active VD_LOCALE. */\n protected readonly t = vdTexts('rating', { starLabel: this.starLabel });\n readonly size = input<VdRatingSize>('md');\n readonly disabled = input(false, { transform: booleanAttribute });\n readonly readonly = input(false, { transform: booleanAttribute });\n readonly invalid = input(false, { transform: booleanAttribute });\n readonly touched = input(false, { transform: booleanAttribute });\n readonly required = input(false, { transform: booleanAttribute });\n readonly touch = output<void>();\n readonly controlId = vdUniqueId('vd-rating');\n protected readonly labelId = `${this.controlId}-label`;\n protected readonly stars = [1, 2, 3, 4, 5];\n protected readonly preview = signal(0);\n protected readonly selected = computed(() => vdRatingValue(this.value()));\n protected readonly filled = computed(() =>\n !this.locked() && this.preview() ? this.preview() : this.selected(),\n );\n protected readonly field = inject(VD_FIELD, { optional: true });\n private readonly host = inject<ElementRef<HTMLElement>>(ElementRef).nativeElement;\n private readonly injector = inject(Injector);\n private readonly destroyRef = inject(DestroyRef);\n private readonly formBound = signal(false);\n private readonly ngSource = signal<Signal<VdNgControlState> | null>(null);\n private readonly ngState = computed(\n () =>\n this.ngSource()?.() ?? { invalid: false, touched: false, disabled: false, required: false },\n );\n protected readonly isDisabled = computed(() => this.disabled() || this.ngState().disabled);\n protected readonly locked = computed(() => this.isDisabled() || this.readonly());\n protected readonly isRequired = computed(() => this.required() || this.ngState().required);\n protected readonly showInvalid = computed(\n () =>\n (this.invalid() && (!this.formBound() || this.touched())) ||\n (this.ngState().invalid && this.ngState().touched),\n );\n\n constructor() {\n const control: VdFieldControl = {\n id: signal(this.controlId),\n invalid: this.showInvalid,\n required: this.isRequired,\n disabled: this.isDisabled,\n };\n this.field?.register(control);\n this.destroyRef.onDestroy(() => this.field?.unregister(control));\n }\n ngOnInit(): void {\n const ng = this.injector.get(NgControl, null, { self: true, optional: true });\n this.formBound.set(\n !!ng || !!this.injector.get(FormField, null, { self: true, optional: true }),\n );\n this.ngSource.set(vdNgControlState(ng, this.destroyRef));\n }\n protected choose(value: number): void {\n if (!this.locked()) {\n this.preview.set(0);\n this.value.set(value);\n }\n }\n protected onKeydown(event: KeyboardEvent, star: number): void {\n if (event.altKey || event.ctrlKey || event.metaKey || event.shiftKey) return;\n const next = vdRatingKey(star, event.key, this.host.matches(':dir(rtl)'));\n if (next === null) return;\n event.preventDefault();\n if (this.locked()) return;\n this.choose(next);\n this.host.querySelectorAll<HTMLButtonElement>('button')[next - 1]?.focus();\n }\n protected onFocusOut(event: FocusEvent): void {\n if (!event.relatedTarget || !this.host.contains(event.relatedTarget as Node)) this.touch.emit();\n }\n}\n"],"mappings":";;;;;;;AACA,SAAgB,cAAc,OAAc;CAC1C,OAAO,OAAO,UAAU,YAAY,OAAO,UAAU,KAAK,KAAK,SAAS,KAAK,SAAS,IAClF,QACA;AACN;AAGA,SAAgB,YAAY,OAAe,KAAa,KAAY;CAClE,IAAI,QAAQ,QAAQ,OAAO;CAC3B,IAAI,QAAQ,OAAO,OAAO;CAC1B,MAAM,QACJ,QAAQ,cACJ,IACA,QAAQ,YACN,KACA,QAAQ,eACN,MACE,KACA,IACF,QAAQ,cACN,MACE,IACA,KACF;CACZ,IAAI,CAAC,OAAO,OAAO;CACnB,QAAS,KAAK,IAAI,GAAG,cAAc,KAAK,CAAC,IAAI,IAAI,QAAQ,KAAK,IAAK;AACrE;AC4DA,IAAa,WAAb,MAAa,SAAQ;CACV,QAAQ,MAAM,GAAE,GAAA,YAAA,CAAA,EAAA,WAAA,QAAA,CAAA,+BAAA,CAAA,CAAA;CAChB,QAAQ,MAAM,SAAkB,GAAA,YAAA,CAAA,EAAA,WAAA,QAAA,CAAA,+BAAA,CAAA,CAAA;CAChC,YAAY,MAAkC,GAAA,YAAA,CAAA,QAAA,EAAA,WAAA,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;IACpB,uBAAuB;IACvB,wBAAwB;IACxB,wBAAwB;IACxB,cAAc;GACf;GACD,iBAAiB,wBAAwB;GACzC,eAAe,kBAAkB;EAClC,CAAA"}
|
|
@@ -0,0 +1,217 @@
|
|
|
1
|
+
import * as i0 from "@angular/core";
|
|
2
|
+
import { ChangeDetectionStrategy, Component, Pipe, ViewEncapsulation, computed, inject, input } from "@angular/core";
|
|
3
|
+
import { VD_LOCALE, vdTexts } from "@vadem/ui/locale";
|
|
4
|
+
const MIN = -621355968e5;
|
|
5
|
+
const MAX = 0xe677d21fdbff;
|
|
6
|
+
function vdRelativeTimeValid(value) {
|
|
7
|
+
return typeof value === "number" && Number.isSafeInteger(value) && value >= MIN && value <= MAX;
|
|
8
|
+
}
|
|
9
|
+
const UNITS = [
|
|
10
|
+
[31536e6, "year"],
|
|
11
|
+
[2592e6, "month"],
|
|
12
|
+
[6048e5, "week"],
|
|
13
|
+
[864e5, "day"],
|
|
14
|
+
[36e5, "hour"],
|
|
15
|
+
[6e4, "minute"],
|
|
16
|
+
[1e3, "second"]
|
|
17
|
+
];
|
|
18
|
+
function vdFormatRelativeTime(value, now, options = {}) {
|
|
19
|
+
if (!vdRelativeTimeValid(value) || !vdRelativeTimeValid(now)) return options.unknownText ?? "Unknown time";
|
|
20
|
+
const delta = value - now;
|
|
21
|
+
if (delta <= 0 && delta > -5e3) return options.justNowText ?? "Just now";
|
|
22
|
+
const [span, unit] = UNITS.find(([span]) => Math.abs(delta) >= span) ?? UNITS[UNITS.length - 1];
|
|
23
|
+
const count = Math.sign(delta) * Math.max(1, Math.floor(Math.abs(delta) / span));
|
|
24
|
+
let formatter;
|
|
25
|
+
try {
|
|
26
|
+
formatter = new Intl.RelativeTimeFormat(options.locale ?? "en", { numeric: "always" });
|
|
27
|
+
} catch {
|
|
28
|
+
formatter = new Intl.RelativeTimeFormat("en", { numeric: "always" });
|
|
29
|
+
}
|
|
30
|
+
return formatter.format(count, unit);
|
|
31
|
+
}
|
|
32
|
+
var VdRelativeTimePipe = class VdRelativeTimePipe {
|
|
33
|
+
texts = inject(VD_LOCALE);
|
|
34
|
+
transform(value, now, locale = this.texts.code, justNowText = this.texts.relativeTime.justNowText, unknownText = this.texts.relativeTime.unknownText) {
|
|
35
|
+
return vdFormatRelativeTime(value, now, {
|
|
36
|
+
locale,
|
|
37
|
+
justNowText,
|
|
38
|
+
unknownText
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
static ɵfac = i0.ɵɵngDeclareFactory({
|
|
42
|
+
minVersion: "12.0.0",
|
|
43
|
+
version: "22.2.1",
|
|
44
|
+
ngImport: i0,
|
|
45
|
+
type: VdRelativeTimePipe,
|
|
46
|
+
deps: [],
|
|
47
|
+
target: i0.ɵɵFactoryTarget.Pipe
|
|
48
|
+
});
|
|
49
|
+
static ɵpipe = i0.ɵɵngDeclarePipe({
|
|
50
|
+
minVersion: "14.0.0",
|
|
51
|
+
version: "22.2.1",
|
|
52
|
+
ngImport: i0,
|
|
53
|
+
type: VdRelativeTimePipe,
|
|
54
|
+
isStandalone: true,
|
|
55
|
+
name: "vdRelativeTime"
|
|
56
|
+
});
|
|
57
|
+
};
|
|
58
|
+
i0.ɵɵngDeclareClassMetadata({
|
|
59
|
+
minVersion: "12.0.0",
|
|
60
|
+
version: "22.2.1",
|
|
61
|
+
ngImport: i0,
|
|
62
|
+
type: VdRelativeTimePipe,
|
|
63
|
+
decorators: [{
|
|
64
|
+
type: Pipe,
|
|
65
|
+
args: [{ name: "vdRelativeTime" }]
|
|
66
|
+
}]
|
|
67
|
+
});
|
|
68
|
+
var VdRelativeTime = class VdRelativeTime {
|
|
69
|
+
vdRelativeTime = input(...ngDevMode ? [void 0, { debugName: "vdRelativeTime" }] : /* istanbul ignore next */ []);
|
|
70
|
+
now = input.required(...ngDevMode ? [{ debugName: "now" }] : /* istanbul ignore next */ []);
|
|
71
|
+
locale = input(...ngDevMode ? [void 0, { debugName: "locale" }] : /* istanbul ignore next */ []);
|
|
72
|
+
justNowText = input(...ngDevMode ? [void 0, { debugName: "justNowText" }] : /* istanbul ignore next */ []);
|
|
73
|
+
unknownText = input(...ngDevMode ? [void 0, { debugName: "unknownText" }] : /* istanbul ignore next */ []);
|
|
74
|
+
texts = inject(VD_LOCALE);
|
|
75
|
+
t = vdTexts("relativeTime", {
|
|
76
|
+
justNowText: this.justNowText,
|
|
77
|
+
unknownText: this.unknownText
|
|
78
|
+
});
|
|
79
|
+
valid = computed(() => vdRelativeTimeValid(this.vdRelativeTime()) && vdRelativeTimeValid(this.now()), ...ngDevMode ? [{ debugName: "valid" }] : /* istanbul ignore next */ []);
|
|
80
|
+
datetime = computed(() => {
|
|
81
|
+
const value = this.vdRelativeTime();
|
|
82
|
+
return vdRelativeTimeValid(value) ? new Date(value).toISOString() : null;
|
|
83
|
+
}, ...ngDevMode ? [{ debugName: "datetime" }] : /* istanbul ignore next */ []);
|
|
84
|
+
text = computed(() => vdFormatRelativeTime(this.vdRelativeTime(), this.now(), {
|
|
85
|
+
locale: this.locale() ?? this.texts.code,
|
|
86
|
+
...this.t()
|
|
87
|
+
}), ...ngDevMode ? [{ debugName: "text" }] : /* istanbul ignore next */ []);
|
|
88
|
+
static ɵfac = i0.ɵɵngDeclareFactory({
|
|
89
|
+
minVersion: "12.0.0",
|
|
90
|
+
version: "22.2.1",
|
|
91
|
+
ngImport: i0,
|
|
92
|
+
type: VdRelativeTime,
|
|
93
|
+
deps: [],
|
|
94
|
+
target: i0.ɵɵFactoryTarget.Component
|
|
95
|
+
});
|
|
96
|
+
static ɵcmp = i0.ɵɵngDeclareComponent({
|
|
97
|
+
minVersion: "17.1.0",
|
|
98
|
+
version: "22.2.1",
|
|
99
|
+
type: VdRelativeTime,
|
|
100
|
+
isStandalone: true,
|
|
101
|
+
selector: "time[vdRelativeTime]",
|
|
102
|
+
inputs: {
|
|
103
|
+
vdRelativeTime: {
|
|
104
|
+
classPropertyName: "vdRelativeTime",
|
|
105
|
+
publicName: "vdRelativeTime",
|
|
106
|
+
isSignal: true,
|
|
107
|
+
isRequired: false,
|
|
108
|
+
transformFunction: null
|
|
109
|
+
},
|
|
110
|
+
now: {
|
|
111
|
+
classPropertyName: "now",
|
|
112
|
+
publicName: "now",
|
|
113
|
+
isSignal: true,
|
|
114
|
+
isRequired: true,
|
|
115
|
+
transformFunction: null
|
|
116
|
+
},
|
|
117
|
+
locale: {
|
|
118
|
+
classPropertyName: "locale",
|
|
119
|
+
publicName: "locale",
|
|
120
|
+
isSignal: true,
|
|
121
|
+
isRequired: false,
|
|
122
|
+
transformFunction: null
|
|
123
|
+
},
|
|
124
|
+
justNowText: {
|
|
125
|
+
classPropertyName: "justNowText",
|
|
126
|
+
publicName: "justNowText",
|
|
127
|
+
isSignal: true,
|
|
128
|
+
isRequired: false,
|
|
129
|
+
transformFunction: null
|
|
130
|
+
},
|
|
131
|
+
unknownText: {
|
|
132
|
+
classPropertyName: "unknownText",
|
|
133
|
+
publicName: "unknownText",
|
|
134
|
+
isSignal: true,
|
|
135
|
+
isRequired: false,
|
|
136
|
+
transformFunction: null
|
|
137
|
+
}
|
|
138
|
+
},
|
|
139
|
+
host: {
|
|
140
|
+
properties: {
|
|
141
|
+
"attr.datetime": "datetime()",
|
|
142
|
+
"attr.data-state": "valid() ? \"valid\" : \"unknown\""
|
|
143
|
+
},
|
|
144
|
+
classAttribute: "vd-relative-time"
|
|
145
|
+
},
|
|
146
|
+
ngImport: i0,
|
|
147
|
+
template: `<bdi>{{ text() }}</bdi>`,
|
|
148
|
+
isInline: true,
|
|
149
|
+
changeDetection: i0.ChangeDetectionStrategy.OnPush,
|
|
150
|
+
encapsulation: i0.ViewEncapsulation.None
|
|
151
|
+
});
|
|
152
|
+
};
|
|
153
|
+
i0.ɵɵngDeclareClassMetadata({
|
|
154
|
+
minVersion: "12.0.0",
|
|
155
|
+
version: "22.2.1",
|
|
156
|
+
ngImport: i0,
|
|
157
|
+
type: VdRelativeTime,
|
|
158
|
+
decorators: [{
|
|
159
|
+
type: Component,
|
|
160
|
+
args: [{
|
|
161
|
+
selector: "time[vdRelativeTime]",
|
|
162
|
+
template: `<bdi>{{ text() }}</bdi>`,
|
|
163
|
+
host: {
|
|
164
|
+
class: "vd-relative-time",
|
|
165
|
+
"[attr.datetime]": "datetime()",
|
|
166
|
+
"[attr.data-state]": "valid() ? \"valid\" : \"unknown\""
|
|
167
|
+
},
|
|
168
|
+
changeDetection: ChangeDetectionStrategy.OnPush,
|
|
169
|
+
encapsulation: ViewEncapsulation.None
|
|
170
|
+
}]
|
|
171
|
+
}],
|
|
172
|
+
propDecorators: {
|
|
173
|
+
vdRelativeTime: [{
|
|
174
|
+
type: i0.Input,
|
|
175
|
+
args: [{
|
|
176
|
+
isSignal: true,
|
|
177
|
+
alias: "vdRelativeTime",
|
|
178
|
+
required: false
|
|
179
|
+
}]
|
|
180
|
+
}],
|
|
181
|
+
now: [{
|
|
182
|
+
type: i0.Input,
|
|
183
|
+
args: [{
|
|
184
|
+
isSignal: true,
|
|
185
|
+
alias: "now",
|
|
186
|
+
required: true
|
|
187
|
+
}]
|
|
188
|
+
}],
|
|
189
|
+
locale: [{
|
|
190
|
+
type: i0.Input,
|
|
191
|
+
args: [{
|
|
192
|
+
isSignal: true,
|
|
193
|
+
alias: "locale",
|
|
194
|
+
required: false
|
|
195
|
+
}]
|
|
196
|
+
}],
|
|
197
|
+
justNowText: [{
|
|
198
|
+
type: i0.Input,
|
|
199
|
+
args: [{
|
|
200
|
+
isSignal: true,
|
|
201
|
+
alias: "justNowText",
|
|
202
|
+
required: false
|
|
203
|
+
}]
|
|
204
|
+
}],
|
|
205
|
+
unknownText: [{
|
|
206
|
+
type: i0.Input,
|
|
207
|
+
args: [{
|
|
208
|
+
isSignal: true,
|
|
209
|
+
alias: "unknownText",
|
|
210
|
+
required: false
|
|
211
|
+
}]
|
|
212
|
+
}]
|
|
213
|
+
}
|
|
214
|
+
});
|
|
215
|
+
export { VdRelativeTime, VdRelativeTimePipe, vdFormatRelativeTime };
|
|
216
|
+
|
|
217
|
+
//# sourceMappingURL=vadem-ui-relative-time.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"vadem-ui-relative-time.mjs","names":[],"sources":["../../../projects/ui/relative-time/src/core/relative-time.ts","../../../projects/ui/relative-time/src/relative-time.ts"],"sourcesContent":["export interface VdRelativeTimeOptions {\n readonly locale?: string;\n readonly justNowText?: string;\n readonly unknownText?: string;\n}\nconst MIN = -62135596800000; // 0001-01-01T00:00:00.000Z\nconst MAX = 253402300799999; // 9999-12-31T23:59:59.999Z\n\n/** Epoch milliseconds only, constrained to the native time element's four-digit year range. */\nexport function vdRelativeTimeValid(value: number | null | undefined): value is number {\n return typeof value === 'number' && Number.isSafeInteger(value) && value >= MIN && value <= MAX;\n}\nconst UNITS: readonly [number, Intl.RelativeTimeFormatUnit][] = [\n [365 * 86400000, 'year'],\n [30 * 86400000, 'month'],\n [7 * 86400000, 'week'],\n [86400000, 'day'],\n [3600000, 'hour'],\n [60000, 'minute'],\n [1000, 'second'],\n];\n\n/** Elapsed-duration labels; callers own the clock and refresh cadence. */\nexport function vdFormatRelativeTime(\n value: number | null | undefined,\n now: number | null | undefined,\n options: VdRelativeTimeOptions = {},\n): string {\n if (!vdRelativeTimeValid(value) || !vdRelativeTimeValid(now))\n return options.unknownText ?? 'Unknown time';\n const delta = value - now;\n if (delta <= 0 && delta > -5000) return options.justNowText ?? 'Just now';\n const [span, unit] = UNITS.find(([span]) => Math.abs(delta) >= span) ?? UNITS[UNITS.length - 1];\n const count = Math.sign(delta) * Math.max(1, Math.floor(Math.abs(delta) / span));\n let formatter: Intl.RelativeTimeFormat;\n try {\n formatter = new Intl.RelativeTimeFormat(options.locale ?? 'en', { numeric: 'always' });\n } catch {\n formatter = new Intl.RelativeTimeFormat('en', { numeric: 'always' });\n }\n return formatter.format(count, unit);\n}\n","import {\n ChangeDetectionStrategy,\n Component,\n Pipe,\n ViewEncapsulation,\n computed,\n inject,\n input,\n type PipeTransform,\n} from '@angular/core';\nimport { VD_LOCALE, vdTexts } from '@vadem/ui/locale';\nimport { vdFormatRelativeTime, vdRelativeTimeValid } from './core/relative-time';\n\n@Pipe({ name: 'vdRelativeTime' })\nexport class VdRelativeTimePipe implements PipeTransform {\n private readonly texts = inject(VD_LOCALE);\n transform(\n value: number | null | undefined,\n now: number | null | undefined,\n locale = this.texts.code,\n justNowText = this.texts.relativeTime.justNowText,\n unknownText = this.texts.relativeTime.unknownText,\n ): string {\n return vdFormatRelativeTime(value, now, { locale, justNowText, unknownText });\n }\n}\n\n@Component({\n // Preserve native time semantics and allow composition with vdTimelineTime.\n // eslint-disable-next-line @angular-eslint/component-selector\n selector: 'time[vdRelativeTime]',\n template: `<bdi>{{ text() }}</bdi>`,\n host: {\n class: 'vd-relative-time',\n '[attr.datetime]': 'datetime()',\n '[attr.data-state]': 'valid() ? \"valid\" : \"unknown\"',\n },\n changeDetection: ChangeDetectionStrategy.OnPush,\n encapsulation: ViewEncapsulation.None,\n})\nexport class VdRelativeTime {\n readonly vdRelativeTime = input<number | null>();\n readonly now = input.required<number>();\n readonly locale = input<string>();\n readonly justNowText = input<string>();\n readonly unknownText = input<string>();\n private readonly texts = inject(VD_LOCALE);\n private readonly t = vdTexts('relativeTime', {\n justNowText: this.justNowText,\n unknownText: this.unknownText,\n });\n protected readonly valid = computed(\n () => vdRelativeTimeValid(this.vdRelativeTime()) && vdRelativeTimeValid(this.now()),\n );\n protected readonly datetime = computed(() => {\n const value = this.vdRelativeTime();\n return vdRelativeTimeValid(value) ? new Date(value).toISOString() : null;\n });\n protected readonly text = computed(() =>\n vdFormatRelativeTime(this.vdRelativeTime(), this.now(), {\n locale: this.locale() ?? this.texts.code,\n ...this.t(),\n }),\n );\n}\n"],"mappings":";;;AAKA,MAAM,MAAM;AACZ,MAAM,MAAM;AAGZ,SAAgB,oBAAoB,OAAgC;CAClE,OAAO,OAAO,UAAU,YAAY,OAAO,cAAc,KAAK,KAAK,SAAS,OAAO,SAAS;AAC9F;AACA,MAAM,QA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