shirkasoft-ui-components 2.0.0 → 2.1.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 (34) hide show
  1. package/README.md +209 -53
  2. package/fesm2022/shirkasoft-ui-components-config.mjs +610 -72
  3. package/fesm2022/shirkasoft-ui-components-config.mjs.map +1 -1
  4. package/fesm2022/shirkasoft-ui-components-date-picker.mjs +79 -6
  5. package/fesm2022/shirkasoft-ui-components-date-picker.mjs.map +1 -1
  6. package/fesm2022/shirkasoft-ui-components-file-upload.mjs +74 -3
  7. package/fesm2022/shirkasoft-ui-components-file-upload.mjs.map +1 -1
  8. package/fesm2022/shirkasoft-ui-components-icons.mjs +6 -6
  9. package/fesm2022/shirkasoft-ui-components-icons.mjs.map +1 -1
  10. package/fesm2022/shirkasoft-ui-components-price-input.mjs +70 -2
  11. package/fesm2022/shirkasoft-ui-components-price-input.mjs.map +1 -1
  12. package/fesm2022/shirkasoft-ui-components-select.mjs +76 -14
  13. package/fesm2022/shirkasoft-ui-components-select.mjs.map +1 -1
  14. package/fesm2022/shirkasoft-ui-components-table.mjs +11 -0
  15. package/fesm2022/shirkasoft-ui-components-table.mjs.map +1 -1
  16. package/fesm2022/shirkasoft-ui-components-text-field.mjs +80 -18
  17. package/fesm2022/shirkasoft-ui-components-text-field.mjs.map +1 -1
  18. package/fesm2022/shirkasoft-ui-components-theme-picker.mjs +262 -165
  19. package/fesm2022/shirkasoft-ui-components-theme-picker.mjs.map +1 -1
  20. package/fesm2022/shirkasoft-ui-components-theme.mjs +2 -24
  21. package/fesm2022/shirkasoft-ui-components-theme.mjs.map +1 -1
  22. package/fesm2022/shirkasoft-ui-components-utils.mjs +36 -1
  23. package/fesm2022/shirkasoft-ui-components-utils.mjs.map +1 -1
  24. package/package.json +1 -1
  25. package/types/shirkasoft-ui-components-config.d.ts +246 -20
  26. package/types/shirkasoft-ui-components-date-picker.d.ts +35 -1
  27. package/types/shirkasoft-ui-components-file-upload.d.ts +35 -1
  28. package/types/shirkasoft-ui-components-icons.d.ts +6 -6
  29. package/types/shirkasoft-ui-components-price-input.d.ts +36 -2
  30. package/types/shirkasoft-ui-components-select.d.ts +36 -2
  31. package/types/shirkasoft-ui-components-text-field.d.ts +36 -4
  32. package/types/shirkasoft-ui-components-theme-picker.d.ts +40 -12
  33. package/types/shirkasoft-ui-components-theme.d.ts +17 -9
  34. package/types/shirkasoft-ui-components-utils.d.ts +34 -1
@@ -4,7 +4,7 @@
4
4
  import * as i0 from "@angular/core";
5
5
  import { ElementRef } from "@angular/core";
6
6
  import { ControlValueAccessor, FormControl, FormGroup } from "@angular/forms";
7
- import { FormValueControl } from "@angular/forms/signals";
7
+ import { FormValueControl, ValidationError } from "@angular/forms/signals";
8
8
  /** Option rendered by the select, optionally prefixed with a "new entry" badge. */
9
9
  interface SelectOption {
10
10
  label: string;
@@ -53,6 +53,14 @@ export declare class SelectComponent implements ControlValueAccessor, FormValueC
53
53
  usePagination: import("@angular/core").InputSignal<boolean>;
54
54
  /** Disables the whole select. */
55
55
  disabled: import("@angular/core").InputSignal<boolean>;
56
+ /** Errors bound automatically by the Signal Forms `[formField]` directive. */
57
+ errors: import("@angular/core").InputSignal<readonly ValidationError.WithOptionalFieldTree[]>;
58
+ /** Invalid status bound automatically by `[formField]`. */
59
+ invalid: import("@angular/core").InputSignal<boolean>;
60
+ /** Touched status bound automatically by `[formField]`. */
61
+ touched: import("@angular/core").InputSignal<boolean>;
62
+ /** Dirty status bound automatically by `[formField]`. */
63
+ dirty: import("@angular/core").InputSignal<boolean>;
56
64
  /** Custom per-validation-error messages shown under the select. */
57
65
  errorMessages: import("@angular/core").InputSignal<{
58
66
  [key: string]: string;
@@ -108,7 +116,13 @@ export declare class SelectComponent implements ControlValueAccessor, FormValueC
108
116
  isDisabled: import("@angular/core").Signal<boolean>;
109
117
  /** Resolves the form control from `control` or from `formGroup`+`label`. */
110
118
  actualControl: import("@angular/core").Signal<FormControl<any> | undefined>;
111
- /** Whether the bound control should display its error (invalid + touched/dirty). */
119
+ /**
120
+ * True when the select is driven by Signal Forms instead of a reactive control.
121
+ * Detected by the absence of a reactive control: `[formField]` provides the
122
+ * state through its `errors`/`invalid`/`touched`/`dirty` inputs.
123
+ */
124
+ protected readonly usesSignalForms: import("@angular/core").Signal<boolean>;
125
+ /** Whether the select should display its validation errors. */
112
126
  shouldShowError: import("@angular/core").Signal<boolean | undefined>;
113
127
  /** Whether an error was shown before and the control is now valid + touched. */
114
128
  wasFixedError: import("@angular/core").Signal<boolean | undefined>;
@@ -275,6 +289,26 @@ export declare class SelectComponent implements ControlValueAccessor, FormValueC
275
289
  "required": false;
276
290
  "isSignal": true;
277
291
  };
292
+ "errors": {
293
+ "alias": "errors";
294
+ "required": false;
295
+ "isSignal": true;
296
+ };
297
+ "invalid": {
298
+ "alias": "invalid";
299
+ "required": false;
300
+ "isSignal": true;
301
+ };
302
+ "touched": {
303
+ "alias": "touched";
304
+ "required": false;
305
+ "isSignal": true;
306
+ };
307
+ "dirty": {
308
+ "alias": "dirty";
309
+ "required": false;
310
+ "isSignal": true;
311
+ };
278
312
  "errorMessages": {
279
313
  "alias": "errorMessages";
280
314
  "required": false;
@@ -4,7 +4,7 @@
4
4
  import * as i0 from "@angular/core";
5
5
  import { ElementRef } from "@angular/core";
6
6
  import { ControlValueAccessor, FormControl, FormGroup } from "@angular/forms";
7
- import { FormValueControl } from "@angular/forms/signals";
7
+ import { FormValueControl, ValidationError } from "@angular/forms/signals";
8
8
  /**
9
9
  * Shirkasoft UI Components.
10
10
  * Authors: Roberto Valladares Martin (Ansem13), Julio César García García (Sanjuli14).
@@ -44,6 +44,14 @@ export declare class TextFieldComponent implements ControlValueAccessor, FormVal
44
44
  control: import("@angular/core").InputSignal<FormControl<any> | undefined>;
45
45
  /** Disables the field. */
46
46
  disabled: import("@angular/core").InputSignal<boolean>;
47
+ /** Errors bound automatically by the Signal Forms `[formField]` directive. */
48
+ errors: import("@angular/core").InputSignal<readonly ValidationError.WithOptionalFieldTree[]>;
49
+ /** Invalid status bound automatically by `[formField]`. */
50
+ invalid: import("@angular/core").InputSignal<boolean>;
51
+ /** Touched status bound automatically by `[formField]`. */
52
+ touched: import("@angular/core").InputSignal<boolean>;
53
+ /** Dirty status bound automatically by `[formField]`. */
54
+ dirty: import("@angular/core").InputSignal<boolean>;
47
55
  /** Custom error message shown regardless of validation errors. */
48
56
  errorMessage: import("@angular/core").InputSignal<string>;
49
57
  /** Renders a textarea instead of an input. */
@@ -93,11 +101,15 @@ export declare class TextFieldComponent implements ControlValueAccessor, FormVal
93
101
  private readonly innerControl;
94
102
  /** Explicit `control`, or `formGroup.get(label)`, or `undefined` if none. */
95
103
  private externalControl;
96
- /** True when the field is driven by its internal control (no reactive control given). */
97
- private usesInnerControl;
104
+ /**
105
+ * True when the field is driven by Signal Forms (or plain `[(value)]`) instead
106
+ * of a reactive control. Detected by the absence of an external control:
107
+ * `[formField]` then provides `errors`/`invalid`/`touched`/`dirty`.
108
+ */
109
+ protected usesSignalForms: import("@angular/core").Signal<boolean>;
98
110
  /** Resolves the reactive control: external one if any, otherwise the internal one. */
99
111
  actualControl: import("@angular/core").Signal<FormControl<any>>;
100
- /** True when the resolved control is invalid and dirty or touched. */
112
+ /** True when the field should display its validation errors. */
101
113
  shouldShowError: import("@angular/core").Signal<boolean>;
102
114
  /** True when the control had an error before and is now valid (success state). */
103
115
  wasFixedError: import("@angular/core").Signal<boolean>;
@@ -197,6 +209,26 @@ export declare class TextFieldComponent implements ControlValueAccessor, FormVal
197
209
  "required": false;
198
210
  "isSignal": true;
199
211
  };
212
+ "errors": {
213
+ "alias": "errors";
214
+ "required": false;
215
+ "isSignal": true;
216
+ };
217
+ "invalid": {
218
+ "alias": "invalid";
219
+ "required": false;
220
+ "isSignal": true;
221
+ };
222
+ "touched": {
223
+ "alias": "touched";
224
+ "required": false;
225
+ "isSignal": true;
226
+ };
227
+ "dirty": {
228
+ "alias": "dirty";
229
+ "required": false;
230
+ "isSignal": true;
231
+ };
200
232
  "errorMessage": {
201
233
  "alias": "errorMessage";
202
234
  "required": false;
@@ -1,6 +1,7 @@
1
1
  /**
2
2
  * Generated bundle index. Do not edit.
3
3
  */
4
+ import { ShkThemePreset } from "shirkasoft-ui-components/config";
4
5
  import * as i0 from "@angular/core";
5
6
  /**
6
7
  * Shirkasoft UI Components.
@@ -11,8 +12,10 @@ import * as i0 from "@angular/core";
11
12
  interface ShkPickerColor {
12
13
  /** Hex color; it becomes `--shk-primary-600` (`theme.primary`). */
13
14
  color: string;
14
- /** Accessible name / tooltip. */
15
+ /** Accessible name / tooltip (English fallback). */
15
16
  label: string;
17
+ /** Translation key of the label. */
18
+ labelKey?: string;
16
19
  }
17
20
  /**
18
21
  * Default primary colors (Tailwind 600 shades). Red and rose are left out on
@@ -20,19 +23,27 @@ interface ShkPickerColor {
20
23
  */
21
24
  export declare const DEFAULT_PRIMARY_COLORS: readonly ShkPickerColor[];
22
25
  /**
23
- * Theme customizer: a palette button that opens a panel to pick the primary
24
- * color, the surface (neutral) palette and a theme preset at runtime.
26
+ * Theme customizer: a palette button that opens a panel to pick a theme preset,
27
+ * the primary color and the surface (neutral) palette at runtime.
25
28
  *
26
- * It edits the `theme.primary`, `theme.surface` and `theme.name` options, so it
27
- * needs `provideShk(withTheme(...))`; add `withPersistence()` to remember the
28
- * choice. Without `withTheme()` it renders nothing.
29
+ * It edits the `theme.name`, `theme.primary` and `theme.surface` options, so it
30
+ * needs `provideShk(withTheme(...))`. Without `withTheme()` it renders nothing.
29
31
  *
30
32
  * ```html
33
+ * <!-- User preference (device layer) -->
31
34
  * <shk-theme-picker />
35
+ *
36
+ * <!-- Embedded in a settings screen (admin preview writes the draft) -->
37
+ * <shk-theme-picker [inline]="true" />
32
38
  * ```
39
+ *
40
+ * While `ShkConfigSync.preview()` is active every write goes to the draft, so
41
+ * the same component serves the user and the admin without knowing about
42
+ * layers.
33
43
  */
34
44
  export declare class ThemePickerComponent {
35
45
  private readonly config;
46
+ private readonly labels;
36
47
  private readonly host;
37
48
  private readonly trigger;
38
49
  /** Primary colors offered. */
@@ -41,23 +52,29 @@ export declare class ThemePickerComponent {
41
52
  readonly showSurface: import("@angular/core").InputSignal<boolean>;
42
53
  /** Shows the theme presets section (needs more than one preset). */
43
54
  readonly showPresets: import("@angular/core").InputSignal<boolean>;
44
- /** Accessible name and tooltip of the button. */
45
- readonly triggerLabel: import("@angular/core").InputSignal<string>;
46
- readonly primaryLabel: import("@angular/core").InputSignal<string>;
47
- readonly surfaceLabel: import("@angular/core").InputSignal<string>;
48
- readonly presetsLabel: import("@angular/core").InputSignal<string>;
55
+ /** Renders the panel inline (no button, no popover) to embed it in a page. */
56
+ readonly inline: import("@angular/core").InputSignal<boolean>;
57
+ /** Accessible name and tooltip of the button. Defaults to the translated label. */
58
+ readonly triggerLabel: import("@angular/core").InputSignal<string | undefined>;
59
+ readonly primaryLabel: import("@angular/core").InputSignal<string | undefined>;
60
+ readonly surfaceLabel: import("@angular/core").InputSignal<string | undefined>;
61
+ readonly presetsLabel: import("@angular/core").InputSignal<string | undefined>;
49
62
  /** `theme.*` options exist only when the app uses `withTheme()`. */
50
63
  protected readonly available: boolean;
51
64
  protected readonly open: import("@angular/core").WritableSignal<boolean>;
52
65
  protected readonly panelId: string;
53
66
  protected readonly paletteIcon: import("shirkasoft-ui-components/icons").IconNode | null;
54
- protected readonly presets: readonly import("shirkasoft-ui-components/config").ShkThemePreset[];
67
+ protected readonly presets: readonly ShkThemePreset[];
55
68
  /** Surface palettes, each shown with its 500 shade. */
56
69
  protected readonly surfaces: {
57
70
  name: string;
58
71
  label: string;
59
72
  color: string;
60
73
  }[];
74
+ protected readonly triggerText: import("@angular/core").Signal<string>;
75
+ protected readonly primaryText: import("@angular/core").Signal<string>;
76
+ protected readonly surfaceText: import("@angular/core").Signal<string>;
77
+ protected readonly presetsText: import("@angular/core").Signal<string>;
61
78
  protected readonly themeName: import("@angular/core").Signal<string>;
62
79
  private readonly currentPreset;
63
80
  private readonly primaryOverride;
@@ -68,6 +85,12 @@ export declare class ThemePickerComponent {
68
85
  protected readonly activeSurface: import("@angular/core").Signal<string>;
69
86
  /** True while no primary/surface override is applied on top of the preset. */
70
87
  protected readonly isPresetPure: import("@angular/core").Signal<boolean>;
88
+ /** Translated name of a preset. */
89
+ protected presetLabel(preset: ShkThemePreset): string;
90
+ /** Translated name of a primary color. */
91
+ protected colorLabel(item: ShkPickerColor): string;
92
+ /** Translated name of a surface palette. */
93
+ protected surfaceName(name: string): string;
71
94
  protected toggle(): void;
72
95
  protected setPrimary(color: string): void;
73
96
  protected setSurface(name: string): void;
@@ -92,6 +115,11 @@ export declare class ThemePickerComponent {
92
115
  "required": false;
93
116
  "isSignal": true;
94
117
  };
118
+ "inline": {
119
+ "alias": "inline";
120
+ "required": false;
121
+ "isSignal": true;
122
+ };
95
123
  "triggerLabel": {
96
124
  "alias": "triggerLabel";
97
125
  "required": false;
@@ -12,10 +12,17 @@ interface ShkThemeConfig {
12
12
  defaultTheme?: ShkThemeName;
13
13
  /** Scheme applied when nothing is stored yet. Defaults to `system`. */
14
14
  defaultScheme?: ShkColorScheme;
15
- /** Persist the selection in localStorage. Defaults to `true`. */
15
+ /**
16
+ * @deprecated The selection is stored by `ShkConfigService`
17
+ * (`provideShk(withTheme())`). Kept so `provideShkTheme()` keeps compiling.
18
+ */
16
19
  persist?: boolean;
17
- /** localStorage keys. */
20
+ /**
21
+ * @deprecated Only read once to migrate a pre-2.1 selection into the
22
+ * registry (`shk-config`).
23
+ */
18
24
  storageKey?: string;
25
+ /** @deprecated Only read once, like {@link storageKey}. */
19
26
  schemeStorageKey?: string;
20
27
  /** Attribute written on <html>. Defaults to `data-shk-theme`. */
21
28
  attribute?: string;
@@ -38,10 +45,14 @@ export declare const SHK_THEME_CONFIG: InjectionToken<Required<ShkThemeConfig>>;
38
45
  */
39
46
  export declare function provideShkTheme(config?: ShkThemeConfig): EnvironmentProviders;
40
47
  /**
41
- * Applies and persists the color theme.
48
+ * Applies the color theme.
42
49
  *
43
50
  * Themes are plain CSS custom properties, so switching a theme is just an
44
51
  * attribute change on `<html>` — no component re-render involved.
52
+ *
53
+ * The service only *applies*: `theme.name` and `theme.scheme` are options of
54
+ * `ShkConfigService`, which owns the value and its persistence (device layer,
55
+ * shared layer or an admin preview). `withTheme()` connects both.
45
56
  */
46
57
  export declare class ShkThemeService {
47
58
  private readonly doc;
@@ -49,9 +60,9 @@ export declare class ShkThemeService {
49
60
  private readonly win;
50
61
  /** Every theme name the service knows about. */
51
62
  readonly availableThemes: readonly ShkThemeName[];
52
- /** Currently active theme. */
63
+ /** Currently applied theme. */
53
64
  readonly theme: import("@angular/core").WritableSignal<ShkThemeName>;
54
- /** Currently selected scheme (`light`, `dark` or `system`). */
65
+ /** Currently applied scheme (`light`, `dark` or `system`). */
55
66
  readonly scheme: import("@angular/core").WritableSignal<ShkColorScheme>;
56
67
  /** `true` when dark colors are being applied. */
57
68
  readonly isDark: import("@angular/core").WritableSignal<boolean>;
@@ -65,15 +76,12 @@ export declare class ShkThemeService {
65
76
  setScheme(scheme: ShkColorScheme): void;
66
77
  /** Flips between light and dark (leaves `system` on the opposite value). */
67
78
  toggleDark(): void;
68
- /** Applies a theme without persisting it (useful for previews). */
79
+ /** Applies a theme without changing the stored value (useful for previews). */
69
80
  previewTheme(theme: ShkThemeName): void;
70
- private restore;
71
81
  private applyTheme;
72
82
  private applyScheme;
73
83
  private watchSystem;
74
84
  private prefersDark;
75
- private read;
76
- private persist;
77
85
  static ɵfac: i0.ɵɵFactoryDeclaration<ShkThemeService, never>;
78
86
  static ɵprov: i0.ɵɵInjectableDeclaration<any>;
79
87
  }
@@ -3,6 +3,7 @@
3
3
  */
4
4
  import { IconNode } from "shirkasoft-ui-components/icons";
5
5
  import * as i0 from "@angular/core";
6
+ import { ValidationError } from "@angular/forms/signals";
6
7
  /** Maps the icon names used across the library to their SVG data. */
7
8
  export declare const ICONS: Record<string, IconNode>;
8
9
  /**
@@ -58,4 +59,36 @@ export declare class PortalDirective {
58
59
  constructor();
59
60
  static ɵfac: i0.ɵɵFactoryDeclaration<PortalDirective, never>;
60
61
  static ɵdir: i0.ɵɵDirectiveDeclaration<PortalDirective, "[shkPortal]", never, {}, {}, never, never, true, never>;
61
- }
62
+ }
63
+ /**
64
+ * Messages keyed by error kind. Accepts both Reactive Forms keys
65
+ * (`required`, `minlength`, `maxlength`…) and Signal Forms keys
66
+ * (`required`, `minLength`, `maxLength`, `minDate`…).
67
+ */
68
+ type ShkErrorMessages = {
69
+ [kind: string]: string;
70
+ };
71
+ /**
72
+ * Converts Signal Forms errors (the ones the `FormField` directive delivers to
73
+ * the `errors` input) into the same map exposed by `AbstractControl.errors`.
74
+ *
75
+ * This way controls reuse a single message mapping for Reactive Forms and
76
+ * Signal Forms, and the error parameters (`minLength`, `min`, `maxDate`…) are
77
+ * available under the names Signal Forms uses.
78
+ */
79
+ export declare function signalErrorsToMap(errors: readonly ValidationError.WithOptionalFieldTree[] | undefined): Record<string, any> | null;
80
+ /**
81
+ * Builds the readable message list for an error map.
82
+ *
83
+ * The map may come from `AbstractControl.errors` (Reactive Forms) or from
84
+ * `signalErrorsToMap` (Signal Forms). Priority order:
85
+ * 1. Message configured in `errorMessages`.
86
+ * 2. The error's own message (`message`), e.g. `requiredError({ message })`.
87
+ * 3. Translated message for the error kind.
88
+ *
89
+ * Signal Forms `minLength`/`maxLength` keys are translated with the same
90
+ * `validation.minlength`/`validation.maxlength` keys Reactive Forms uses, so no
91
+ * extra translations are needed.
92
+ */
93
+ export declare function errorMessagesFromMap(errors: Record<string, any> | null | undefined, customErrors: ShkErrorMessages, translate: (key: string, params?: Record<string, any>) => string): string[];
94
+ export type { ShkErrorMessages };