shirkasoft-ui-components 2.0.1 → 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.
package/README.md CHANGED
@@ -15,9 +15,36 @@
15
15
  <img src="projects/showcase/public/readme.png" alt="Shirkasoft UI Components showcase" />
16
16
  </p>
17
17
 
18
+ ## Shirkasoft UI Components 2.1
19
+
20
+ > **Version 2.1 has arrived.** Version 2.1 turns the configuration registry into
21
+ > **layers** (device / shared / draft) with an admin preview, ships **theme
22
+ > packs as data** with a generated **dark scale for any primary color**, and
23
+ > adds an **inline theme picker**, translated library labels and a table
24
+ > pagination fix.
25
+
26
+ ### What's new in 2.1
27
+
28
+ - **Capas de configuración**: cada opción se lee de `draft` → `device` →
29
+ `shared` → `default`. `ShkConfigService.set()` escribe en la capa del
30
+ `scope` de la opción (`device` por defecto), o en el borrador mientras hay
31
+ una previsualización (`beginDraft()`/`commitDraft()`/`discardDraft()`).
32
+ - **`ShkConfigSync` + `ShkConfigStore`**: cargar, previsualizar y guardar la
33
+ configuración del sistema, con `isDirty`, `status`, `revision` y conflicto
34
+ mediante `ShkConfigConflictError`.
35
+ - **Packs de tema como datos** (`vars`/`darkVars`): el CSS se genera en runtime,
36
+ así que `theme.name` funciona sin importar `themes/*.css`.
37
+ - **Escala oscura para cualquier primario**: cada tema (incluidos los
38
+ personalizados) tiene su variante oscura generada.
39
+ - **`shk-theme-picker [inline]`** para incrustarlo en una pantalla de ajustes,
40
+ y labels de la librería traducibles con Transloco (`withLabels()` como
41
+ alternativa), con inglés como respaldo.
42
+ - **Tabla**: cambiar las filas por página vuelve a trocear la página y ajusta
43
+ la página actual en lugar de quedarse con el corte anterior.
44
+
18
45
  ## Shirkasoft UI Components 2.0
19
46
 
20
- > **La 2.0 ha llegado.** Version 2.0 is built on **Angular 22.3** and drops Tailwind from the library in favor of plain CSS driven by `--shk-*` custom properties. It ships **four color themes**, provider-based configuration and explicit `OnPush` change detection across every component.
47
+ > **Version 2.0 has arrived.** Version 2.0 is built on **Angular 22.3** and drops Tailwind from the library in favor of plain CSS driven by `--shk-*` custom properties. It ships **four color themes**, provider-based configuration and explicit `OnPush` change detection across every component.
21
48
 
22
49
  Angular 22 UI component library built with **standalone components**, **Angular signals**, **pure CSS + CSS custom properties**, and **light/dark theme** support.
23
50
 
@@ -163,29 +190,37 @@ separate files scoped by a `data-shk-theme` attribute:
163
190
  ### Theme service and providers
164
191
 
165
192
  The `shirkasoft-ui-components/theme` entry point exposes `ShkThemeService` and
166
- `provideShkTheme()`. The service persists the selection in `localStorage`, follows
167
- `prefers-color-scheme` when the scheme is `system`, and only flips an attribute on
168
- `<html>` — switching themes never re-renders components. `provideShkTheme()` also
169
- applies the stored/default theme during app initialization, so it is active even if
170
- no component injects `ShkThemeService`. It returns `EnvironmentProviders`, so register
171
- it in the application (or route/environment) providers — not in a component's
172
- `providers` array.
193
+ `provideShkTheme()`. The service **only applies** the theme: it flips an
194
+ attribute and a class on `<html>`, follows `prefers-color-scheme` when the
195
+ scheme is `system`, and never re-renders components.
196
+
197
+ Since 2.1 the values are owned by the configuration registry
198
+ (`theme.name`/`theme.scheme` in `shirkasoft-ui-components/config`), which also
199
+ persists them (device layer, shared layer or an admin preview). The recommended
200
+ setup is `provideShk(withTheme(...))`; `provideShkTheme()` still works for
201
+ existing apps but no longer persists — a pre-2.1 `shk-theme`/`shk-scheme`
202
+ selection is migrated once into `shk-config` and removed.
173
203
 
174
204
  ```typescript
175
- // app.config.ts
176
- import { provideShkTheme } from 'shirkasoft-ui-components/theme';
205
+ // app.config.ts — recommended
206
+ import { provideShk, withTheme } from 'shirkasoft-ui-components/config';
177
207
 
178
208
  export const appConfig: ApplicationConfig = {
179
209
  providers: [
180
- provideShkTheme({
181
- defaultTheme: 'ocean',
182
- defaultScheme: 'system',
183
- persist: true,
184
- }),
210
+ provideShk(withTheme({ defaultTheme: 'ocean', defaultScheme: 'system' })),
185
211
  ],
186
212
  };
187
213
  ```
188
214
 
215
+ ```typescript
216
+ // app.config.ts — previous releases, still supported
217
+ import { provideShkTheme } from 'shirkasoft-ui-components/theme';
218
+
219
+ export const appConfig: ApplicationConfig = {
220
+ providers: [provideShkTheme({ defaultTheme: 'ocean', defaultScheme: 'system' })],
221
+ };
222
+ ```
223
+
189
224
  ```typescript
190
225
  import { ShkThemeService } from 'shirkasoft-ui-components/theme';
191
226
 
@@ -199,35 +234,49 @@ export class ThemeSwitcher {
199
234
  }
200
235
  ```
201
236
 
237
+ `setTheme`/`setScheme` on the service apply the value without storing it; the
238
+ settings UI should write the options instead (`config.set('theme.name', …)`) so
239
+ the choice survives a reload.
240
+
202
241
  | Option | Default | Description |
203
242
  | ------------------ | ----------------- | ---------------------------------------------- |
204
243
  | `defaultTheme` | `'default'` | Theme applied when nothing is stored. |
205
244
  | `defaultScheme` | `'system'` | `light`, `dark` or `system`. |
206
- | `persist` | `true` | Store the selection in `localStorage`. |
207
- | `storageKey` | `'shk-theme'` | Theme storage key. |
208
- | `schemeStorageKey` | `'shk-scheme'` | Scheme storage key. |
209
245
  | `attribute` | `'data-shk-theme'`| Attribute written on `<html>`. |
210
246
  | `darkClass` | `'dark'` | Class toggled on `<html>` for dark mode. |
247
+ | `persist` | `true` | Deprecated: the registry persists the values. |
248
+ | `storageKey` | `'shk-theme'` | Deprecated: only read to migrate pre-2.1 keys. |
249
+ | `schemeStorageKey` | `'shk-scheme'` | Deprecated: only read to migrate pre-2.1 keys. |
211
250
 
212
251
  ### Dark mode
213
252
 
214
253
  Dark mode uses the `.dark` class on `<html>` and inverts `--shk-surface-50..900`.
215
- `ShkThemeService` handles it for you; without the service, toggle the class manually:
254
+ Every primary color gets its own dark scale (dark tints for `primary-50…200`,
255
+ light tones for `300…500`, the brand color for `600` and a light hover for
256
+ `700`), so buttons keep their brand color and white text stays readable.
257
+ `ShkThemeService` handles the class for you; without the service, toggle it
258
+ manually:
216
259
 
217
260
  ```typescript
218
261
  document.documentElement.classList.toggle('dark');
219
262
  ```
220
263
 
221
- To avoid a flash of the wrong theme, apply the stored values before first paint:
264
+ To avoid a flash of the wrong theme, apply the stored values before first paint.
265
+ Since 2.1 the options live in the `shk-config` JSON:
222
266
 
223
267
  ```html
224
268
  <script>
225
269
  (function () {
226
- var scheme = localStorage.getItem('shk-scheme');
227
- var theme = localStorage.getItem('shk-theme');
228
- var dark = scheme === 'dark' || (scheme !== 'light' && matchMedia('(prefers-color-scheme: dark)').matches);
229
- if (dark) document.documentElement.classList.add('dark');
230
- if (theme && theme !== 'default') document.documentElement.setAttribute('data-shk-theme', theme);
270
+ try {
271
+ var config = JSON.parse(localStorage.getItem('shk-config') || '{}');
272
+ var scheme = config['theme.scheme'];
273
+ var theme = config['theme.name'];
274
+ var dark = scheme === 'dark' || (scheme !== 'light' && matchMedia('(prefers-color-scheme: dark)').matches);
275
+ if (dark) document.documentElement.classList.add('dark');
276
+ if (theme && theme !== 'default') document.documentElement.setAttribute('data-shk-theme', theme);
277
+ if (config['theme.primary']) document.documentElement.setAttribute('data-shk-primary', '');
278
+ if (config['theme.surface']) document.documentElement.setAttribute('data-shk-surface', config['theme.surface']);
279
+ } catch (e) { /* storage blocked or empty */ }
231
280
  })();
232
281
  </script>
233
282
  ```
@@ -244,7 +293,7 @@ updates by itself. Component inputs always win over the configured value.
244
293
  ```typescript
245
294
  // app.config.ts
246
295
  import {
247
- provideShk, withDates, withNumbers, withTheme, withOptions, withPersistence,
296
+ provideShk, withDates, withNumbers, withTheme, withOptions, withLabels,
248
297
  } from 'shirkasoft-ui-components/config';
249
298
 
250
299
  export const appConfig: ApplicationConfig = {
@@ -258,18 +307,24 @@ export const appConfig: ApplicationConfig = {
258
307
  themes: { indigo: { primary: '#4f46e5', label: 'Índigo' }, marca: '#0f766e' },
259
308
  }),
260
309
  withOptions([{ key: 'app.pageSize', module: 'app', type: 'number', default: 20, label: 'Filas' }]),
261
- withPersistence(), // remembers changed options in localStorage
310
+ withLabels({ 'theme.presets.indigo': 'Índigo' }), // optional, for non-Transloco apps
262
311
  ),
263
312
  ],
264
313
  };
265
314
  ```
266
315
 
267
- | Module | Options | Used by |
268
- | --------------- | ------------------------------------------------------------------------------------------- | ----------------------------------------- |
269
- | `withDates` | `dates.locale` · `dates.format` · `dates.displayStyle` · `dates.hourFormat` · `dates.weekStart` | date picker, table `date` columns |
270
- | `withNumbers` | `numbers.locale` · `numbers.currency` · `numbers.currencySymbol` · `numbers.decimals` | price input, table `currency` columns |
271
- | `withTheme` | `theme.name` · `theme.scheme` · `theme.primary` | the whole UI (CSS variables) |
272
- | `withOptions` | your own keys | your app |
316
+ Options persist in `localStorage` (`shk-config`) by default; use
317
+ `withPersistence({ storageKey })` only to change the key.
318
+
319
+ | Module | Options | Used by |
320
+ | ----------------- | --------------------------------------------------------------------------------------------- | ----------------------------------------- |
321
+ | `withDates` | `dates.locale` · `dates.format` · `dates.displayStyle` · `dates.hourFormat` · `dates.weekStart` | date picker, table `date` columns |
322
+ | `withNumbers` | `numbers.locale` · `numbers.currency` · `numbers.currencySymbol` · `numbers.decimals` | price input, table `currency` columns |
323
+ | `withTheme` | `theme.name` · `theme.scheme` · `theme.primary` · `theme.surface` | the whole UI (CSS variables) |
324
+ | `withOptions` | your own keys | your app |
325
+ | `withPersistence` | — (storage key) | the registry |
326
+ | `withSharedConfig`| — (a `ShkConfigStore`) | the shared layer (usually the backend) |
327
+ | `withLabels` | — (translation overrides) | the library's own labels |
273
328
 
274
329
  Without any configuration the components behave as before: dates `dd/MM/yyyy`
275
330
  (`MM/dd/yyyy` for English locales), month names in Spanish, `$` and two decimals.
@@ -279,10 +334,11 @@ Without any configuration the components behave as before: dates `dd/MM/yyyy`
279
334
  ```typescript
280
335
  const config = inject(ShkConfigService);
281
336
 
282
- config.options(); // every option: definition + current value
337
+ config.options(); // every option: definition + value + source
283
338
  config.modules(); // ['dates', 'numbers', 'theme', 'app']
284
339
  config.get('dates.format')(); // signal → 'dd/MM/yyyy'
285
340
  config.set('numbers.currency', 'CUP'); // validated; invalid values throw
341
+ config.set('theme.primary', '#2563eb', 'shared'); // force a layer
286
342
  config.reset('numbers.currency'); // back to the default (or reset() for all)
287
343
  ```
288
344
 
@@ -302,11 +358,95 @@ the locale's casing (`31 dic 2026`, `Dec 31, 2026`).
302
358
  digits (`$1,234.50`, `¥1,000`, `BD 1.500`); set a number to force them. The helpers `formatDate`, `formatCurrency`,
303
359
  `formatNumber` and `currencySymbol` are exported for app code too.
304
360
 
361
+ ### Layers, preview and shared configuration
362
+
363
+ Every option is read from four places, in this order:
364
+
365
+ 1. `draft` — the preview an admin screen is editing.
366
+ 2. `device` — the user's own choice (localStorage).
367
+ 3. `shared` — the system-wide value (the backend).
368
+ 4. the option's `default`.
369
+
370
+ `set()` writes to the draft while a preview is active; otherwise to the layer
371
+ given as third argument, or to the option's `scope` (`device` by default).
372
+ `ShkOptionEntry.source` tells a settings screen where the current value comes
373
+ from, so the same screen serves users and administrators.
374
+
375
+ ```typescript
376
+ import { SHK_CONFIG_STORE, ShkConfigStore, ShkConfigSync } from 'shirkasoft-ui-components/config';
377
+
378
+ // The app implements the store (usually over HTTP); the library never does.
379
+ @Injectable({ providedIn: 'root' })
380
+ export class ApiConfigStore implements ShkConfigStore {
381
+ load() { /* GET /config → { values, revision } */ }
382
+ save(values, revision) { /* PUT /config → { values, revision } */ }
383
+ }
384
+
385
+ provideShk(
386
+ withTheme({ scope: 'shared' }), // system-wide theme
387
+ withSharedConfig({ provide: SHK_CONFIG_STORE, useClass: ApiConfigStore }),
388
+ );
389
+ ```
390
+
391
+ ```typescript
392
+ const sync = inject(ShkConfigSync);
393
+
394
+ await sync.load(); // shared values from the backend
395
+ sync.preview(); // the screen now edits a draft (live preview)
396
+ sync.isDirty(); // true once something changed
397
+ await sync.save(); // draft → backend
398
+ sync.discard(); // throw the draft away
399
+ ```
400
+
401
+ `save()` sends the revision it loaded; a store must reject a stale one with
402
+ `ShkConfigConflictError` so a lost update is detected instead of overwriting
403
+ another admin. `configRevision(values)` (`sha256(canonical_json(values))`, first
404
+ 16 hex characters) computes the same string the library uses, and
405
+ `sync.status()` / `sync.error()` expose the operation state.
406
+
407
+ ### Library labels
408
+
409
+ The library's own texts — option names, descriptions, theme pack names, color
410
+ names, surface palettes — are translated through **Transloco** when it is
411
+ configured (they follow `langChanges$` without a reload), then through
412
+ `withLabels()` overrides, and finally fall back to **English**. The keys are
413
+ `theme.options.*`, `theme.schemes.*`, `theme.surfaces.*`, `theme.presets.*`,
414
+ `theme.colors.*` and `theme.picker.*`.
415
+
416
+ ```typescript
417
+ withLabels({
418
+ 'theme.presets.ocean': 'Océano',
419
+ 'theme.options.name': 'Tema',
420
+ 'theme.surfaces.slate': 'Pizarra',
421
+ });
422
+ ```
423
+
424
+ ### Theme packs as data
425
+
426
+ A pack is plain data — `{ primary, label?, surface?, vars?, darkVars? }` — and
427
+ the stylesheet is generated at runtime, so `theme.name` works **without**
428
+ importing `themes/*.css` (those files are still published for apps that prefer a
429
+ static import). `vars` are light-mode custom properties, `darkVars` are merged
430
+ over the generated dark scale:
431
+
432
+ ```typescript
433
+ withTheme({
434
+ themes: {
435
+ marca: {
436
+ primary: '#0f766e', // --shk-primary-600 + derived scale
437
+ surface: 'stone', // neutral palette
438
+ darkVars: { '--shk-surface-900': '#0b1120' },
439
+ },
440
+ },
441
+ });
442
+ ```
443
+
305
444
  **Custom themes** are generated from one color with CSS `color-mix()`: the color
306
- becomes `--shk-primary-600` and the rest of the 50–950 scale is derived. They
307
- are activated like the built-in ones (`theme.name`, `ShkThemeService.setTheme`).
308
- `theme.primary` overrides the primary color on top of any theme at runtime.
309
- `withTheme()` replaces `provideShkTheme()`; do not register both.
445
+ becomes `--shk-primary-600` and the rest of the 50–950 scale is derived. The
446
+ dark scale is generated too, so any primary color works in both schemes.
447
+ `theme.primary` overrides the primary color on top of any theme at runtime
448
+ (`<html data-shk-primary>`), and `withTheme()` replaces `provideShkTheme()`; do
449
+ not register both.
310
450
 
311
451
  **Surface palettes** (`theme.surface`): `slate`, `gray`, `zinc`, `neutral`,
312
452
  `stone` replace the neutral scale (backgrounds, borders, text) on top of any
@@ -314,18 +454,23 @@ theme, in light and dark mode (`<html data-shk-surface="slate">`).
314
454
 
315
455
  ### Theme picker (`shk-theme-picker`)
316
456
 
317
- A palette button that opens a panel to change the theme at runtime: **primary
318
- color** (`theme.primary`), **surface** (`theme.surface`) and **presets** (the
319
- theme packs, `theme.name`; picking one clears the color/surface overrides).
320
- It needs `withTheme()`; add `withPersistence()` to remember the choice.
457
+ A palette button that opens a panel to change the theme at runtime: **presets**
458
+ (the theme packs, `theme.name`; picking one clears the color/surface overrides),
459
+ **primary color** (`theme.primary`) and **surface** (`theme.surface`). It needs
460
+ `withTheme()`; options persist by default.
321
461
 
322
462
  ```typescript
323
463
  import { ThemePickerComponent } from 'shirkasoft-ui-components/theme-picker';
324
464
  ```
325
465
 
326
466
  ```html
467
+ <!-- User preference (header) -->
327
468
  <shk-theme-picker />
328
- <!-- custom colors / labels -->
469
+
470
+ <!-- Embedded in a settings screen, no button or popover -->
471
+ <shk-theme-picker [inline]="true" />
472
+
473
+ <!-- Custom colors / labels -->
329
474
  <shk-theme-picker
330
475
  [primaryColors]="[{ color: '#0f766e', label: 'Marca' }, { color: '#2563eb', label: 'Azul' }]"
331
476
  [showPresets]="false"
@@ -333,15 +478,19 @@ import { ThemePickerComponent } from 'shirkasoft-ui-components/theme-picker';
333
478
  />
334
479
  ```
335
480
 
336
- | Input | Type | Default |
337
- | --------------- | ------------------ | ----------------------------------------- |
338
- | `primaryColors` | `ShkPickerColor[]` | 16 colors (Tailwind 600, no red/rose) |
339
- | `showSurface` | `boolean` | `true` |
340
- | `showPresets` | `boolean` | `true` (shown with more than one preset) |
341
- | `triggerLabel` | `string` | `'Personalizar tema'` |
342
- | `primaryLabel` | `string` | `'Primario'` |
343
- | `surfaceLabel` | `string` | `'Superficie'` |
344
- | `presetsLabel` | `string` | `'Temas'` |
481
+ While `ShkConfigSync.preview()` is active, every write of the picker goes to the
482
+ draft, so the same component serves users and administrators.
483
+
484
+ | Input | Type | Default |
485
+ | --------------- | ------------------ | -------------------------------------------- |
486
+ | `primaryColors` | `ShkPickerColor[]` | 16 colors (Tailwind 600, no red/rose) |
487
+ | `showSurface` | `boolean` | `true` |
488
+ | `showPresets` | `boolean` | `true` (shown with more than one preset) |
489
+ | `inline` | `boolean` | `false` (renders the panel without a trigger)|
490
+ | `triggerLabel` | `string` | translated, `'Customize theme'` fallback |
491
+ | `primaryLabel` | `string` | translated, `'Primary'` fallback |
492
+ | `surfaceLabel` | `string` | translated, `'Surface'` fallback |
493
+ | `presetsLabel` | `string` | translated, `'Themes'` fallback |
345
494
 
346
495
  ## Signal Forms (Angular 22)
347
496