@cngx/common 0.1.0-rc.7 → 0.1.0-rc.9

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 (69) hide show
  1. package/card/README.md +2 -1
  2. package/command/README.md +29 -0
  3. package/data/README.md +15 -3
  4. package/dialog/README.md +23 -1
  5. package/fesm2022/cngx-common-a11y.mjs +517 -184
  6. package/fesm2022/cngx-common-a11y.mjs.map +1 -1
  7. package/fesm2022/cngx-common-audio.mjs +62 -17
  8. package/fesm2022/cngx-common-audio.mjs.map +1 -1
  9. package/fesm2022/cngx-common-card.mjs +301 -46
  10. package/fesm2022/cngx-common-card.mjs.map +1 -1
  11. package/fesm2022/cngx-common-chart.mjs +1221 -479
  12. package/fesm2022/cngx-common-chart.mjs.map +1 -1
  13. package/fesm2022/cngx-common-command.mjs +97 -16
  14. package/fesm2022/cngx-common-command.mjs.map +1 -1
  15. package/fesm2022/cngx-common-data.mjs +1496 -499
  16. package/fesm2022/cngx-common-data.mjs.map +1 -1
  17. package/fesm2022/cngx-common-dialog.mjs +236 -61
  18. package/fesm2022/cngx-common-dialog.mjs.map +1 -1
  19. package/fesm2022/cngx-common-display.mjs +364 -93
  20. package/fesm2022/cngx-common-display.mjs.map +1 -1
  21. package/fesm2022/cngx-common-interactive.mjs +2040 -1046
  22. package/fesm2022/cngx-common-interactive.mjs.map +1 -1
  23. package/fesm2022/cngx-common-layout.mjs +955 -125
  24. package/fesm2022/cngx-common-layout.mjs.map +1 -1
  25. package/fesm2022/cngx-common-popover.mjs +1293 -89
  26. package/fesm2022/cngx-common-popover.mjs.map +1 -1
  27. package/fesm2022/cngx-common-stepper.mjs +997 -453
  28. package/fesm2022/cngx-common-stepper.mjs.map +1 -1
  29. package/fesm2022/cngx-common-tabs.mjs +1794 -1265
  30. package/fesm2022/cngx-common-tabs.mjs.map +1 -1
  31. package/fesm2022/cngx-common-timeline.mjs +151 -61
  32. package/fesm2022/cngx-common-timeline.mjs.map +1 -1
  33. package/fesm2022/cngx-common.mjs +1 -1
  34. package/interactive/README.md +15 -4
  35. package/layout/README.md +37 -1
  36. package/package.json +20 -7
  37. package/popover/README.md +58 -2
  38. package/schematics/collection.json +9 -0
  39. package/schematics/ng-add/index.js +9 -0
  40. package/schematics/ng-add/schema.json +91 -0
  41. package/schematics/package.json +3 -0
  42. package/stepper/README.md +11 -8
  43. package/theming/components/cngx-accordion.css +1 -1
  44. package/theming/components/cngx-backdrop.css +12 -0
  45. package/theming/components/cngx-button-toggle.css +29 -3
  46. package/theming/components/cngx-data-grid.css +168 -1
  47. package/theming/components/cngx-dialog.css +13 -0
  48. package/theming/components/cngx-listbox.css +21 -12
  49. package/theming/components/cngx-menu.css +56 -16
  50. package/theming/components/cngx-popover-sheet.css +402 -0
  51. package/theming/components/cngx-popover.css +28 -0
  52. package/theming/components/cngx-recycler-placeholder.css +196 -0
  53. package/theming/components/cngx-ripple.css +1 -1
  54. package/theming/components/cngx-slider.css +32 -1
  55. package/theming/components/cngx-tooltip.css +12 -0
  56. package/timeline/README.md +155 -0
  57. package/types/cngx-common-a11y.d.ts +205 -28
  58. package/types/cngx-common-card.d.ts +201 -17
  59. package/types/cngx-common-chart.d.ts +345 -48
  60. package/types/cngx-common-command.d.ts +50 -10
  61. package/types/cngx-common-data.d.ts +743 -92
  62. package/types/cngx-common-dialog.d.ts +161 -10
  63. package/types/cngx-common-display.d.ts +356 -142
  64. package/types/cngx-common-interactive.d.ts +910 -226
  65. package/types/cngx-common-layout.d.ts +603 -32
  66. package/types/cngx-common-popover.d.ts +612 -49
  67. package/types/cngx-common-stepper.d.ts +526 -237
  68. package/types/cngx-common-tabs.d.ts +358 -75
  69. package/types/cngx-common-timeline.d.ts +108 -22
@@ -1,7 +1,8 @@
1
1
  import * as i0 from '@angular/core';
2
- import { InjectionToken, inject, makeEnvironmentProviders, signal, DestroyRef, effect, isDevMode, SkipSelf, Optional, ElementRef, input, booleanAttribute, computed, untracked, afterNextRender, Directive, linkedSignal } from '@angular/core';
2
+ import { InjectionToken, inject, makeEnvironmentProviders, signal, DestroyRef, effect, SkipSelf, Optional, ElementRef, input, booleanAttribute, computed, untracked, afterNextRender, Directive, linkedSignal } from '@angular/core';
3
3
  import { DOCUMENT } from '@angular/common';
4
4
  import { injectMediaQuery } from '@cngx/common/layout';
5
+ import { cngxDevWarn, cngxDevError } from '@cngx/utils';
5
6
  import { CNGX_STATEFUL, createTransitionTracker } from '@cngx/core/utils';
6
7
 
7
8
  /**
@@ -371,6 +372,30 @@ const CNGX_AUDIO_TONE_GENERATOR_FACTORY = new InjectionToken('CngxAudioToneGener
371
372
  function clampVolume(v) {
372
373
  return Math.max(0, Math.min(1, v));
373
374
  }
375
+ /**
376
+ * Map a raw `AudioContext.state` onto {@link AudioStatus}. Safari reports a
377
+ * non-standard `'interrupted'` (phone call, Siri, audio-route change) that the
378
+ * spec union does not carry; it resumes on the next gesture exactly like a
379
+ * suspended context, so it folds to `'suspended'` rather than being cast into
380
+ * the union. Any unknown value degrades to `'suspended'`, the safe resting
381
+ * state a subsequent `resume()` can lift.
382
+ */
383
+ function mapAudioStatus(state) {
384
+ switch (state) {
385
+ case 'running':
386
+ return 'running';
387
+ case 'closed':
388
+ return 'closed';
389
+ case 'suspended':
390
+ case 'interrupted':
391
+ default:
392
+ return 'suspended';
393
+ }
394
+ }
395
+ /** A context that a `resume()` can lift - suspended, or Safari's interrupted. */
396
+ function isSuspendedLike(state) {
397
+ return state === 'suspended' || state === 'interrupted';
398
+ }
374
399
  /**
375
400
  * Apply a per-call `[0, 1]` scale to a tone's peak gain. Centralised here so
376
401
  * every play path (`play` / `tone` / `sequence`) scales identically and an
@@ -417,6 +442,9 @@ const createAudioEngine = (options) => {
417
442
  const gate = createAutoplayGate({ target: doc, destroyRef });
418
443
  const debouncer = createDebouncer({ windowMs: config.debounceMs });
419
444
  const earcons = new Map(Object.entries({ ...CNGX_AUDIO_DEFAULT_EARCONS, ...config.earcons }));
445
+ // Dev-only: an unknown earcon name is a fixed authoring mistake, so warn once
446
+ // per name rather than on every (debounced) play attempt.
447
+ const warnedUnknownEarcons = new Set();
420
448
  let context = null;
421
449
  let masterGain = null;
422
450
  const contextFactory = options?.contextFactory ??
@@ -429,9 +457,19 @@ const createAudioEngine = (options) => {
429
457
  context: () => context,
430
458
  destination: () => masterGain,
431
459
  });
460
+ // Single source of truth for `status`: the context's own statechange event.
461
+ // Browser-initiated transitions the page never requested (Safari interrupt,
462
+ // OS suspend) flow through here too, and because resume()/suspend() land
463
+ // their result via this listener there is no manual status write left to
464
+ // race - a stale resume resolution cannot clobber a later suspend.
465
+ const onStateChange = () => {
466
+ if (context) {
467
+ status.set(mapAudioStatus(context.state));
468
+ }
469
+ };
432
470
  function resumeIfArmed() {
433
- if (context && gate.armed() && context.state === 'suspended') {
434
- void context.resume().then(() => status.set('running'), () => undefined);
471
+ if (context && gate.armed() && isSuspendedLike(context.state)) {
472
+ void context.resume().catch(() => undefined);
435
473
  }
436
474
  }
437
475
  function ensureContext() {
@@ -447,7 +485,10 @@ const createAudioEngine = (options) => {
447
485
  masterGain = created.createGain();
448
486
  masterGain.gain.value = volume();
449
487
  masterGain.connect(created.destination);
450
- status.set(created.state);
488
+ // Born in its current state - no statechange fires for the initial value,
489
+ // so seed it directly; every later transition arrives via onStateChange.
490
+ status.set(mapAudioStatus(created.state));
491
+ created.addEventListener('statechange', onStateChange);
451
492
  resumeIfArmed();
452
493
  return context;
453
494
  }
@@ -470,7 +511,7 @@ const createAudioEngine = (options) => {
470
511
  }
471
512
  if (doc.hidden) {
472
513
  if (context.state === 'running') {
473
- void context.suspend().then(() => status.set('suspended'), () => undefined);
514
+ void context.suspend().catch(() => undefined);
474
515
  }
475
516
  }
476
517
  else {
@@ -480,6 +521,7 @@ const createAudioEngine = (options) => {
480
521
  doc.addEventListener('visibilitychange', onVisibility);
481
522
  destroyRef.onDestroy(() => {
482
523
  doc.removeEventListener('visibilitychange', onVisibility);
524
+ context?.removeEventListener('statechange', onStateChange);
483
525
  // close() rejects on an already-closed context; swallow it so a double
484
526
  // destroy does not surface an unhandled rejection.
485
527
  const closing = context?.close?.();
@@ -499,8 +541,9 @@ const createAudioEngine = (options) => {
499
541
  }
500
542
  const earcon = earcons.get(name);
501
543
  if (!earcon) {
502
- if (isDevMode()) {
503
- console.warn(`[cngxAudio] Unknown earcon "${name}". Register it via withEarcons({...}) or engine.register(name, config).`);
544
+ if (typeof ngDevMode !== 'undefined' && ngDevMode && !warnedUnknownEarcons.has(name)) {
545
+ warnedUnknownEarcons.add(name);
546
+ cngxDevWarn('CNGX1001', `[cngxAudio] Unknown earcon "${name}". Register it via withEarcons({...}) or engine.register(name, config).`);
504
547
  }
505
548
  return;
506
549
  }
@@ -792,16 +835,16 @@ class CngxAudio {
792
835
  untracked(() => this.syncListeners(wanted));
793
836
  });
794
837
  this.destroyRef.onDestroy(() => this.unbindAll());
795
- if (isDevMode()) {
838
+ if (typeof ngDevMode !== 'undefined' && ngDevMode) {
796
839
  // One-shot post-binding check, not a reactive node.
797
840
  afterNextRender(() => {
798
841
  const parsed = parseEventBindings(this.spec());
799
842
  if (parsed.lifecycleKeys.length > 0) {
800
- console.error(`[cngxAudio] Lifecycle keys "${parsed.lifecycleKeys.join(', ')}" are not DOM events. ` +
843
+ cngxDevError('CNGX1002', `[cngxAudio] Lifecycle keys "${parsed.lifecycleKeys.join(', ')}" are not DOM events. ` +
801
844
  'Use [cngxAudioStatus] for lifecycle bindings.');
802
845
  }
803
846
  if (parsed.unknownKeys.length > 0) {
804
- console.warn(`[cngxAudio] Unrecognised event keys "${parsed.unknownKeys.join(', ')}". ` +
847
+ cngxDevWarn('CNGX1003', `[cngxAudio] Unrecognised event keys "${parsed.unknownKeys.join(', ')}". ` +
805
848
  'Expected one of: click, focus, blur, pointerenter, pointerleave, submit, change, input.');
806
849
  }
807
850
  });
@@ -892,9 +935,11 @@ const DOM_EVENT_SET = new Set(CNGX_AUDIO_STATUS_DOM_EVENTS);
892
935
  /**
893
936
  * Parse the `status:earcon` grammar (`'pending:tap, succeeded:success'`) into a
894
937
  * status map. Pure - no DOM, no `inject()`. Keys are categorised so the
895
- * directive can dev-error on DOM-event keys that should have used `[cngxAudio]`
896
- * and dev-warn on unknown keys. `succeeded`/`failed` normalise to
897
- * `success`/`error` so a lookup by the tracker's raw `AsyncStatus` hits.
938
+ * directive can dev-error on DOM-event keys that should have used `[cngxAudio]`;
939
+ * unknown keys are collected in `unknownKeys` and not reported by the directive.
940
+ * Only own keys of the alias table resolve, so `constructor` or `toString` is
941
+ * an unknown key. `succeeded`/`failed` normalise to `success`/`error` so a
942
+ * lookup by the tracker's raw `AsyncStatus` hits.
898
943
  */
899
944
  function parseStatusBindings(spec) {
900
945
  const bindings = new Map();
@@ -912,7 +957,7 @@ function parseStatusBindings(spec) {
912
957
  }
913
958
  const key = trimmed.slice(0, colon).trim();
914
959
  const earcon = trimmed.slice(colon + 1).trim();
915
- const status = STATUS_ALIASES[key];
960
+ const status = Object.hasOwn(STATUS_ALIASES, key) ? STATUS_ALIASES[key] : undefined;
916
961
  if (status) {
917
962
  if (earcon) {
918
963
  bindings.set(status, earcon);
@@ -976,16 +1021,16 @@ class CngxAudioStatus {
976
1021
  effectiveState = computed(() => this.state() ?? this.statefulFallback?.state, ...(ngDevMode ? [{ debugName: "effectiveState" }] : /* istanbul ignore next */ []));
977
1022
  bindings = computed(() => parseStatusBindings(this.spec()).bindings, { ...(ngDevMode ? { debugName: "bindings" } : /* istanbul ignore next */ {}), equal: sameStringMap });
978
1023
  constructor() {
979
- if (isDevMode()) {
1024
+ if (typeof ngDevMode !== 'undefined' && ngDevMode) {
980
1025
  // One-shot post-binding check, not a reactive node.
981
1026
  afterNextRender(() => {
982
1027
  const parsed = parseStatusBindings(this.spec());
983
1028
  if (parsed.domEventKeys.length > 0) {
984
- console.error(`[cngxAudioStatus] DOM-event keys "${parsed.domEventKeys.join(', ')}" are not lifecycle ` +
1029
+ cngxDevError('CNGX1004', `[cngxAudioStatus] DOM-event keys "${parsed.domEventKeys.join(', ')}" are not lifecycle ` +
985
1030
  'statuses. Use [cngxAudio] for DOM-event bindings.');
986
1031
  }
987
1032
  if (this.state() === undefined && !this.statefulFallback) {
988
- console.error('[cngxAudioStatus] No state source. Bind [state]="state" explicitly or place inside a ' +
1033
+ cngxDevError('CNGX1005', '[cngxAudioStatus] No state source. Bind [state]="state" explicitly or place inside a ' +
989
1034
  'component that provides CNGX_STATEFUL.');
990
1035
  }
991
1036
  });