@streamscloud/kit 1.0.2 → 1.0.4

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 (77) hide show
  1. package/README.md +1 -1
  2. package/dist/core/actions/index.d.ts +1 -0
  3. package/dist/core/actions/index.js +1 -0
  4. package/dist/core/actions/stop-click-propagation.d.ts +3 -0
  5. package/dist/core/actions/stop-click-propagation.js +17 -0
  6. package/dist/core/continuation-token.js +1 -8
  7. package/dist/core/event-dispatcher.d.ts +1 -3
  8. package/dist/core/event-dispatcher.js +20 -12
  9. package/dist/core/files/file-service.js +3 -1
  10. package/dist/core/files/file-validator.js +1 -1
  11. package/dist/core/files/files-provider.js +2 -1
  12. package/dist/core/locale/app-locale.svelte.d.ts +2 -1
  13. package/dist/core/locale/app-locale.svelte.js +2 -1
  14. package/dist/core/repository/repository.svelte.js +4 -1
  15. package/dist/core/theme/app-theme.svelte.d.ts +2 -0
  16. package/dist/core/theme/app-theme.svelte.js +2 -0
  17. package/dist/core/utils/after-mount.svelte.d.ts +13 -0
  18. package/dist/core/utils/after-mount.svelte.js +21 -0
  19. package/dist/core/utils/array-helper.js +4 -3
  20. package/dist/core/utils/compact-number.js +1 -0
  21. package/dist/core/utils/date-helper.js +10 -35
  22. package/dist/core/utils/href-validator.js +4 -2
  23. package/dist/core/utils/html-helper.d.ts +2 -0
  24. package/dist/core/utils/html-helper.js +6 -1
  25. package/dist/core/utils/index.d.ts +1 -0
  26. package/dist/core/utils/index.js +1 -0
  27. package/dist/core/utils/string-helper.js +2 -2
  28. package/dist/core/utils/utils.d.ts +4 -2
  29. package/dist/core/utils/utils.js +4 -6
  30. package/dist/core/validation/form-validation-handler/yup-form-validator.d.ts +1 -1
  31. package/dist/core/validation/form-validation-handler/yup-form-validator.js +10 -5
  32. package/dist/core/validation/validation-schemas/email-validation.js +10 -10
  33. package/dist/ui/checkbox/cmp.checkbox.svelte +5 -4
  34. package/dist/ui/date-picker/cmp.date-picker.svelte +13 -2
  35. package/dist/ui/date-picker/cmp.date-picker.svelte.d.ts +1 -1
  36. package/dist/ui/dialog/cmp.dialog-container.svelte +2 -8
  37. package/dist/ui/dialog/dialog-store.svelte.js +1 -0
  38. package/dist/ui/drag-and-drop/cmp.drop-zone.svelte +31 -32
  39. package/dist/ui/drag-and-drop/cmp.drop-zone.svelte.d.ts +16 -21
  40. package/dist/ui/drag-and-drop/cmp.file-drop-zone.svelte +149 -0
  41. package/dist/ui/drag-and-drop/cmp.file-drop-zone.svelte.d.ts +36 -0
  42. package/dist/ui/drag-and-drop/index.d.ts +1 -0
  43. package/dist/ui/drag-and-drop/index.js +1 -0
  44. package/dist/ui/drawer/cmp.drawer.svelte +3 -1
  45. package/dist/ui/drawer/cmp.drawer.svelte.d.ts +3 -1
  46. package/dist/ui/duration/cmp.duration.svelte +7 -3
  47. package/dist/ui/duration/cmp.duration.svelte.d.ts +3 -3
  48. package/dist/ui/empty-state/cmp.empty-state.svelte +5 -5
  49. package/dist/ui/file-uploader/cmp.file-uploader.svelte +4 -4
  50. package/dist/ui/file-uploader/cmp.file-uploader.svelte.d.ts +2 -2
  51. package/dist/ui/grid-card/cmp.grid-card-media.svelte +1 -1
  52. package/dist/ui/grid-card/cmp.grid-card-media.svelte.d.ts +4 -1
  53. package/dist/ui/icon/cmp.icon.svelte +6 -10
  54. package/dist/ui/image/cmp.image.svelte +4 -3
  55. package/dist/ui/infinite-scroll/cmp.infinite-scroll.svelte +2 -2
  56. package/dist/ui/numeral-input/cmp.numeral-input.svelte +3 -0
  57. package/dist/ui/numeral-input/cmp.numeral-input.svelte.d.ts +1 -0
  58. package/dist/ui/pagination/pagination-state.svelte.d.ts +1 -0
  59. package/dist/ui/pagination/pagination-state.svelte.js +1 -0
  60. package/dist/ui/pin-input/cmp.pin-input.svelte +44 -26
  61. package/dist/ui/pin-input/cmp.pin-input.svelte.d.ts +3 -2
  62. package/dist/ui/player/carousel/cmp.carousel.svelte +8 -9
  63. package/dist/ui/player/carousel/cmp.carousel.svelte.d.ts +1 -1
  64. package/dist/ui/radio/cmp.radio.svelte +9 -4
  65. package/dist/ui/rich-text-input/validated-link-button.js +1 -1
  66. package/dist/ui/select/cmp.singleselect-async.svelte +2 -1
  67. package/dist/ui/select/multiselect-base.svelte +2 -1
  68. package/dist/ui/select/select-core.svelte.d.ts +2 -0
  69. package/dist/ui/select/select-core.svelte.js +18 -17
  70. package/dist/ui/slider/cmp.slider.svelte +28 -37
  71. package/dist/ui/slider/cmp.slider.svelte.d.ts +1 -0
  72. package/dist/ui/table/table-cells/table-text-cell.svelte +5 -3
  73. package/dist/ui/time-ago/cmp.time-ago.svelte +10 -1
  74. package/dist/ui/time-ago/cmp.time-ago.svelte.d.ts +1 -1
  75. package/dist/ui/toggle/cmp.toggle.svelte +4 -2
  76. package/dist/ui/video/cmp.video.svelte +6 -5
  77. package/package.json +1 -1
package/README.md CHANGED
@@ -24,7 +24,7 @@ npm run lint:fix # eslint --fix + prettier --write
24
24
 
25
25
  ## Release
26
26
 
27
- Through the `/sc:ship` skill.
27
+ Through the `/sc:deliver` skill.
28
28
 
29
29
  ## Context
30
30
 
@@ -1,2 +1,3 @@
1
1
  export { horizontalWheelScroll } from './horizontal-wheel-scroll';
2
+ export { stopClickPropagation } from './stop-click-propagation';
2
3
  export { swallowTouch } from './swallow-touch';
@@ -1,2 +1,3 @@
1
1
  export { horizontalWheelScroll } from './horizontal-wheel-scroll';
2
+ export { stopClickPropagation } from './stop-click-propagation';
2
3
  export { swallowTouch } from './swallow-touch';
@@ -0,0 +1,3 @@
1
+ import type { Action } from 'svelte/action';
2
+ /** Stops click propagation on the node — for a control's `<label>` wrapper nested in a clickable row. Pass `false` to let clicks bubble. */
3
+ export declare const stopClickPropagation: Action<HTMLElement, boolean | undefined>;
@@ -0,0 +1,17 @@
1
+ import { on } from 'svelte/events';
2
+ /** Stops click propagation on the node — for a control's `<label>` wrapper nested in a clickable row. Pass `false` to let clicks bubble. */
3
+ export const stopClickPropagation = (node, enabled = true) => {
4
+ let active = enabled;
5
+ // `on`, not addEventListener: it runs Svelte's delegated `onclick` handlers inside the node before stopping, so the inner button still fires.
6
+ const off = on(node, 'click', (e) => {
7
+ if (active) {
8
+ e.stopPropagation();
9
+ }
10
+ });
11
+ return {
12
+ update(next = true) {
13
+ active = next;
14
+ },
15
+ destroy: off
16
+ };
17
+ };
@@ -10,14 +10,7 @@ export class ContinuationToken {
10
10
  return new ContinuationToken(true, null);
11
11
  }
12
12
  static fromPayload(value) {
13
- if (value?.length && value.length > 1 && value.length < 5000) {
14
- // initialized with server response that there is more data, and value is valid
15
- return new ContinuationToken(true, value);
16
- }
17
- else {
18
- // initialized with server response that there is no more data or value is invalid
19
- return new ContinuationToken(false, null);
20
- }
13
+ return value ? new ContinuationToken(true, value) : new ContinuationToken(false, null);
21
14
  }
22
15
  static preventLoading() {
23
16
  // additional initilizer, to block further loading
@@ -1,9 +1,7 @@
1
1
  export declare class EventDispatcher {
2
2
  static dispatch: <T extends AppEvent>(event: T) => void;
3
- static subscribe: <T extends AppEvent>(eventType: new (...params: never[]) => T, handler: (event: T) => void) => (() => void);
3
+ static subscribe: <T extends AppEvent>(eventType: abstract new (...params: never[]) => T, handler: (event: T) => void) => (() => void);
4
4
  }
5
5
  export declare abstract class AppEvent {
6
- constructor();
7
6
  get classId(): string;
8
- set classId(value: string);
9
7
  }
@@ -1,28 +1,36 @@
1
1
  import { randomNanoid } from './utils/string-generator';
2
+ // Symbol.for, not a module-local key: two bundled copies of the kit must agree on a class's channel.
3
+ const CLASS_ID_KEY = Symbol.for('sc-kit.app-event-id');
4
+ const hasClassId = (eventType) => Object.hasOwn(eventType, CLASS_ID_KEY);
5
+ const getClassId = (eventType) => {
6
+ if (hasClassId(eventType)) {
7
+ return eventType[CLASS_ID_KEY];
8
+ }
9
+ const classId = randomNanoid();
10
+ Object.defineProperty(eventType, CLASS_ID_KEY, { value: classId });
11
+ return classId;
12
+ };
2
13
  export class EventDispatcher {
3
14
  static dispatch = (event) => {
4
- const appEvent = new CustomEvent(event.classId, { detail: event });
5
- document.dispatchEvent(appEvent);
15
+ if (typeof document === 'undefined') {
16
+ return;
17
+ }
18
+ document.dispatchEvent(new CustomEvent(event.classId, { detail: event }));
6
19
  };
7
20
  static subscribe = (eventType, handler) => {
21
+ if (typeof document === 'undefined') {
22
+ return () => { };
23
+ }
8
24
  const handlerFunc = (ev) => {
9
25
  handler(ev.detail);
10
26
  };
11
- const classId = new eventType().classId;
27
+ const classId = getClassId(eventType);
12
28
  document.addEventListener(classId, handlerFunc);
13
29
  return () => document.removeEventListener(classId, handlerFunc);
14
30
  };
15
31
  }
16
32
  export class AppEvent {
17
- constructor() {
18
- if (!this.classId) {
19
- this.classId = randomNanoid();
20
- }
21
- }
22
33
  get classId() {
23
- return this.constructor.prototype._uniqueClassId;
24
- }
25
- set classId(value) {
26
- this.constructor.prototype._uniqueClassId = value;
34
+ return getClassId(this.constructor);
27
35
  }
28
36
  }
@@ -44,11 +44,13 @@ export const downloadFromUrl = async (url, fileName) => {
44
44
  downloadBlob(file, fileName);
45
45
  return true;
46
46
  };
47
+ // Safari reads the blob URL after the click returns; revoking it at once can leave an empty download.
48
+ const DOWNLOAD_URL_REVOKE_DELAY_MS = 40_000;
47
49
  export const downloadBlob = (blob, fileName) => {
48
50
  const blobUrl = URL.createObjectURL(blob);
49
51
  const a = document.createElement('a');
50
52
  a.href = blobUrl;
51
53
  a.download = sanitizeFilename(fileName);
52
54
  a.click();
53
- URL.revokeObjectURL(blobUrl);
55
+ setTimeout(() => URL.revokeObjectURL(blobUrl), DOWNLOAD_URL_REVOKE_DELAY_MS);
54
56
  };
@@ -16,7 +16,7 @@ export class FileValidator {
16
16
  result = await rule(file);
17
17
  }
18
18
  catch {
19
- return { file, isValid: false, errors: [messages.invalidFile] };
19
+ return { file, isValid: false, errors: [...errors, messages.invalidFile] };
20
20
  }
21
21
  const msgs = toArray(result);
22
22
  if (msgs.length > 0) {
@@ -12,7 +12,8 @@ export class FilesProvider {
12
12
  }
13
13
  const cached = this.cache.get(fileSrc);
14
14
  if (cached) {
15
- return FileWithBlobDataHelper.fromFile(cached.file);
15
+ const { file } = cached;
16
+ return FileWithBlobDataHelper.fromFile(new File([file], file.name, { type: file.type }));
16
17
  }
17
18
  const file = await fetchFile(fileSrc);
18
19
  if (!file) {
@@ -3,11 +3,12 @@ declare class AppLocaleContainer {
3
3
  private _current;
4
4
  get current(): AppLocaleValue;
5
5
  get availableLocales(): readonly AppLocaleValue[];
6
+ /** Browser only — on the server this is process-wide state, so the value leaks into other requests. */
6
7
  init: (serverLocale?: AppLocaleValue) => void;
7
8
  /**
8
9
  * Change locale.
9
10
  * In the browser: persists to cookie and reloads the page (wuchale translations are compile-time).
10
- * On the server / in non-browser contexts: updates the reactive state directly.
11
+ * On the server / in non-browser contexts: updates the reactive state directly — process-wide on a server, so it leaks into other requests.
11
12
  */
12
13
  change: (newLocale: AppLocaleValue) => void;
13
14
  toggle: () => void;
@@ -9,13 +9,14 @@ class AppLocaleContainer {
9
9
  get availableLocales() {
10
10
  return APP_LOCALE_VALUES;
11
11
  }
12
+ /** Browser only — on the server this is process-wide state, so the value leaks into other requests. */
12
13
  init = (serverLocale) => {
13
14
  this._current = serverLocale ?? LocaleCookie.get() ?? APP_LOCALE_DEFAULT;
14
15
  };
15
16
  /**
16
17
  * Change locale.
17
18
  * In the browser: persists to cookie and reloads the page (wuchale translations are compile-time).
18
- * On the server / in non-browser contexts: updates the reactive state directly.
19
+ * On the server / in non-browser contexts: updates the reactive state directly — process-wide on a server, so it leaks into other requests.
19
20
  */
20
21
  change = (newLocale) => {
21
22
  if (newLocale === this._current) {
@@ -22,7 +22,10 @@ class RepositoryInstance {
22
22
  add(...items) {
23
23
  const itemsToNotify = [];
24
24
  for (const item of items) {
25
- if (!this._limit || this.items.length < this._limit) {
25
+ if (this.has(item.id)) {
26
+ this._container.add(item);
27
+ }
28
+ else if (!this._limit || this.items.length < this._limit) {
26
29
  this._container.add(item);
27
30
  itemsToNotify.push(item);
28
31
  }
@@ -7,7 +7,9 @@ declare class AppThemeContainer {
7
7
  get active(): AppThemeValue;
8
8
  /** Whether dark mode is currently active (resolves 'auto' based on system preference) */
9
9
  get isDarkMode(): boolean;
10
+ /** Browser only — on the server this is process-wide state, so the value leaks into other requests. */
10
11
  set active(value: AppThemeValue);
12
+ /** Browser only — on the server this is process-wide state, so the value leaks into other requests. */
11
13
  init: (serverTheme?: AppThemeValue) => void;
12
14
  toggle: () => void;
13
15
  private applyToDocument;
@@ -14,11 +14,13 @@ class AppThemeContainer {
14
14
  get isDarkMode() {
15
15
  return this._isDarkMode;
16
16
  }
17
+ /** Browser only — on the server this is process-wide state, so the value leaks into other requests. */
17
18
  set active(value) {
18
19
  this._active = value;
19
20
  ThemeCookie.set(value);
20
21
  this.applyToDocument();
21
22
  }
23
+ /** Browser only — on the server this is process-wide state, so the value leaks into other requests. */
22
24
  init = (serverTheme) => {
23
25
  this._active = serverTheme ?? ThemeCookie.get() ?? 'auto';
24
26
  if (isBrowser()) {
@@ -0,0 +1,13 @@
1
+ /**
2
+ * `current` is `fallback` on the server and until the component mounts, then `compute()` (reactive).
3
+ * For browser-only values rendered in a template — e.g. `HtmlHelper.sanitizeHtml` — since hydration keeps the
4
+ * server's `{@html}` value. Create it during component initialization.
5
+ */
6
+ export declare class AfterMount<T> {
7
+ private _mounted;
8
+ private _compute;
9
+ private _fallback;
10
+ private _current;
11
+ constructor(compute: () => T, fallback: T);
12
+ get current(): T;
13
+ }
@@ -0,0 +1,21 @@
1
+ /**
2
+ * `current` is `fallback` on the server and until the component mounts, then `compute()` (reactive).
3
+ * For browser-only values rendered in a template — e.g. `HtmlHelper.sanitizeHtml` — since hydration keeps the
4
+ * server's `{@html}` value. Create it during component initialization.
5
+ */
6
+ export class AfterMount {
7
+ _mounted = $state(false);
8
+ _compute;
9
+ _fallback;
10
+ _current = $derived.by(() => (this._mounted ? this._compute() : this._fallback));
11
+ constructor(compute, fallback) {
12
+ this._compute = compute;
13
+ this._fallback = fallback;
14
+ $effect(() => {
15
+ this._mounted = true;
16
+ });
17
+ }
18
+ get current() {
19
+ return this._current;
20
+ }
21
+ }
@@ -125,13 +125,14 @@ export class ArrayHelper {
125
125
  const b = propertyFunc(val2);
126
126
  const left = ascending ? a : b;
127
127
  const right = ascending ? b : a;
128
- if (!left && !right) {
128
+ const isMissing = (value) => value === null || value === undefined;
129
+ if (isMissing(left) && isMissing(right)) {
129
130
  return 0;
130
131
  }
131
- if (!left) {
132
+ if (isMissing(left)) {
132
133
  return -1;
133
134
  }
134
- if (!right) {
135
+ if (isMissing(right)) {
135
136
  return 1;
136
137
  }
137
138
  if (typeof left === 'string' && typeof right === 'string') {
@@ -32,5 +32,6 @@ const loc = {
32
32
  M: { en: 'M', no: 'M' },
33
33
  B: { en: 'B', no: 'B' },
34
34
  T: { en: 'T', no: 'T' },
35
+ // TEMP: Norwegian number format for both locales while every demo runs in Norway — map `en` to 'en-US' once English-market users arrive.
35
36
  numberLocale: { en: 'nb-NO', no: 'nb-NO' }
36
37
  };
@@ -194,59 +194,34 @@ export class DateHelper {
194
194
  }
195
195
  static startOfLastWeek() {
196
196
  const now = new Date();
197
- const day = now.getDay();
198
- const diffToMonday = (day === 0 ? 7 : day) - 1;
199
- const lastMonday = new Date(now);
200
- lastMonday.setDate(now.getDate() - diffToMonday - 7);
201
- lastMonday.setHours(0, 0, 0, 0);
202
- return lastMonday.toISOString().slice(0, 10);
197
+ const daysSinceMonday = (now.getDay() + 6) % 7;
198
+ return DateHelper.getDateOnlyString(new Date(now.getFullYear(), now.getMonth(), now.getDate() - daysSinceMonday - 7));
203
199
  }
204
200
  static endOfLastWeek() {
205
201
  const now = new Date();
206
- const day = now.getDay();
207
- const lastSunday = new Date(now);
208
- lastSunday.setDate(now.getDate() - (day === 0 ? 0 : day));
209
- lastSunday.setHours(23, 59, 59, 999);
210
- lastSunday.setDate(lastSunday.getDate() - 1);
211
- return lastSunday.toISOString().slice(0, 10);
202
+ const daysSinceLastSunday = now.getDay() || 7;
203
+ return DateHelper.getDateOnlyString(new Date(now.getFullYear(), now.getMonth(), now.getDate() - daysSinceLastSunday));
212
204
  }
213
205
  static startOfLastMonth() {
214
206
  const now = new Date();
215
- const firstDayOfThisMonth = new Date(now.getFullYear(), now.getMonth(), 1);
216
- const firstDayOfLastMonth = new Date(firstDayOfThisMonth);
217
- firstDayOfLastMonth.setMonth(firstDayOfThisMonth.getMonth() - 1);
218
- return firstDayOfLastMonth.toISOString().slice(0, 10);
207
+ return DateHelper.getDateOnlyString(new Date(now.getFullYear(), now.getMonth() - 1, 1));
219
208
  }
220
209
  static endOfLastMonth() {
221
210
  const now = new Date();
222
- const firstDayOfThisMonth = new Date(now.getFullYear(), now.getMonth(), 1);
223
- const lastDayOfLastMonth = new Date(firstDayOfThisMonth);
224
- lastDayOfLastMonth.setDate(0);
225
- lastDayOfLastMonth.setHours(23, 59, 59, 999);
226
- return lastDayOfLastMonth.toISOString().slice(0, 10);
211
+ return DateHelper.getDateOnlyString(new Date(now.getFullYear(), now.getMonth(), 0));
227
212
  }
228
213
  static startOfLastYear() {
229
- const now = new Date();
230
- const firstDayOfLastYear = new Date(now.getFullYear() - 1, 0, 1);
231
- return firstDayOfLastYear.toISOString().slice(0, 10);
214
+ return DateHelper.getDateOnlyString(new Date(new Date().getFullYear() - 1, 0, 1));
232
215
  }
233
216
  static endOfLastYear() {
234
- const now = new Date();
235
- const lastDayOfLastYear = new Date(now.getFullYear() - 1, 11, 31);
236
- lastDayOfLastYear.setHours(23, 59, 59, 999);
237
- return lastDayOfLastYear.toISOString().slice(0, 10);
217
+ return DateHelper.getDateOnlyString(new Date(new Date().getFullYear() - 1, 11, 31));
238
218
  }
239
219
  static startOfRollingDays(days) {
240
220
  const now = new Date();
241
- const start = new Date(now);
242
- start.setDate(now.getDate() - (days - 1));
243
- start.setHours(0, 0, 0, 0);
244
- return start.toISOString().slice(0, 10);
221
+ return DateHelper.getDateOnlyString(new Date(now.getFullYear(), now.getMonth(), now.getDate() - (days - 1)));
245
222
  }
246
223
  static endOfRollingDays() {
247
- const now = new Date();
248
- now.setHours(23, 59, 59, 999);
249
- return now.toISOString().slice(0, 10);
224
+ return DateHelper.getDateOnlyString(new Date());
250
225
  }
251
226
  static startOfCurrentMonthToNow() {
252
227
  const now = new Date();
@@ -44,12 +44,14 @@ export const validateHref = (input, opts = {}) => {
44
44
  if (!opts.allowRelative) {
45
45
  return { valid: false, error: 'Relative' };
46
46
  }
47
+ if (s.startsWith('//')) {
48
+ return validateHref(`https:${s}`, opts);
49
+ }
47
50
  const hasAllowedRelativePrefix = s.startsWith('/') ||
48
51
  s.startsWith('./') ||
49
52
  s.startsWith('../') ||
50
53
  s.startsWith('#') ||
51
- s.startsWith('?') ||
52
- s.startsWith('//');
54
+ s.startsWith('?');
53
55
  if (hasAllowedRelativePrefix) {
54
56
  return { valid: true };
55
57
  }
@@ -29,6 +29,8 @@ export declare class HtmlHelper {
29
29
  * Returns null when the markup isn't a well-formed SVG document, or when there is no window.
30
30
  */
31
31
  static sanitizeSvg(svg: string): string | null;
32
+ /** Returns '' when there is no window. */
32
33
  static sanitizeHtml(html: string): string;
34
+ /** Returns '' when there is no window. */
33
35
  static stripHtml(html: string, lineBreaksReplacer?: string | null, trimResult?: boolean): string;
34
36
  }
@@ -202,11 +202,16 @@ export class HtmlHelper {
202
202
  stripExternalLoadsAndHtmlBreakouts(root);
203
203
  return new XMLSerializer().serializeToString(root);
204
204
  }
205
+ /** Returns '' when there is no window. */
205
206
  static sanitizeHtml(html) {
207
+ if (typeof window === 'undefined') {
208
+ return '';
209
+ }
206
210
  return HtmlSanitizer.sanitize(html);
207
211
  }
212
+ /** Returns '' when there is no window. */
208
213
  static stripHtml(html, lineBreaksReplacer = null, trimResult = true) {
209
- if (!html) {
214
+ if (!html || typeof window === 'undefined') {
210
215
  return '';
211
216
  }
212
217
  html = HtmlHelper.sanitizeHtml(html);
@@ -1,3 +1,4 @@
1
+ export * from './after-mount.svelte';
1
2
  export * from './array-helper';
2
3
  export * from './color-helper';
3
4
  export * from './compact-number';
@@ -1,3 +1,4 @@
1
+ export * from './after-mount.svelte';
1
2
  export * from './array-helper';
2
3
  export * from './color-helper';
3
4
  export * from './compact-number';
@@ -1,3 +1,4 @@
1
+ const EMAIL_REGEX = /^[a-zA-Z0-9_]([.+-]?[a-zA-Z0-9_])*@[a-zA-Z0-9]([.-]?[a-zA-Z0-9])*\.[a-zA-Z]{2,}$/;
1
2
  export class StringHelper {
2
3
  static isBlobUrl(val) {
3
4
  return !!val && val.startsWith('blob:');
@@ -6,8 +7,7 @@ export class StringHelper {
6
7
  if (!val) {
7
8
  return false;
8
9
  }
9
- const re = /^(([^<>()[\]\\.,;:\s@"]+(\.[^<>()[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/;
10
- return re.test(String(val).toLowerCase());
10
+ return EMAIL_REGEX.test(val);
11
11
  }
12
12
  static isNumeric(n) {
13
13
  const parsed = parseFloat(n);
@@ -16,9 +16,11 @@ export declare class Utils {
16
16
  /**
17
17
  * Returns a function, that, as long as it continues to be invoked, will not
18
18
  * be triggered. The function will be called after it stops being called for
19
- * N milliseconds.
19
+ * N milliseconds. `cancel()` drops a pending call.
20
20
  */
21
- static debounce(func: (...args: any[]) => void, wait: number): (...args: unknown[]) => void;
21
+ static debounce(func: (...args: any[]) => void, wait: number): ((...args: unknown[]) => void) & {
22
+ cancel: () => void;
23
+ };
22
24
  static throttle<T extends (...args: any[]) => any>(func: T, wait: number): (...args: Parameters<T>) => ReturnType<T>;
23
25
  static sleep: (ms: number) => Promise<unknown>;
24
26
  static poll: <T>(fn: () => Promise<T>, continueWhileTrueFn: (input: T) => boolean, ms?: number) => Promise<T>;
@@ -49,18 +49,16 @@ export class Utils {
49
49
  /**
50
50
  * Returns a function, that, as long as it continues to be invoked, will not
51
51
  * be triggered. The function will be called after it stops being called for
52
- * N milliseconds.
52
+ * N milliseconds. `cancel()` drops a pending call.
53
53
  */
54
54
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
55
55
  static debounce(func, wait) {
56
56
  let timeout;
57
- return (...args) => {
58
- const later = () => {
59
- func.apply(this, args);
60
- };
57
+ const debounced = (...args) => {
61
58
  clearTimeout(timeout);
62
- timeout = window.setTimeout(later, wait);
59
+ timeout = setTimeout(() => func.apply(this, args), wait);
63
60
  };
61
+ return Object.assign(debounced, { cancel: () => clearTimeout(timeout) });
64
62
  }
65
63
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
66
64
  static throttle(func, wait) {
@@ -1,5 +1,5 @@
1
1
  import type { FormValidateResult, IFormHandlerValidator } from './types';
2
- import type { ObjectSchema } from 'yup';
2
+ import { type ObjectSchema } from 'yup';
3
3
  export declare class YupFormValidator<T> implements IFormHandlerValidator<T> {
4
4
  private validationSchema;
5
5
  private validationOptions;
@@ -1,3 +1,4 @@
1
+ import { ValidationError } from 'yup';
1
2
  export class YupFormValidator {
2
3
  validationSchema;
3
4
  validationOptions;
@@ -17,10 +18,12 @@ export class YupFormValidator {
17
18
  };
18
19
  }
19
20
  catch (error) {
20
- const yupErrors = error;
21
- if (yupErrors && yupErrors.inner) {
21
+ if (!ValidationError.isError(error)) {
22
+ throw error;
23
+ }
24
+ if (error.inner) {
22
25
  const updatedPathMap = {};
23
- yupErrors.inner.forEach((e) => {
26
+ error.inner.forEach((e) => {
24
27
  if (!e.path) {
25
28
  return;
26
29
  }
@@ -43,8 +46,10 @@ export class YupFormValidator {
43
46
  await this.validationSchema.validateAt(field, obj);
44
47
  return null;
45
48
  }
46
- catch (e) {
47
- const error = e;
49
+ catch (error) {
50
+ if (!ValidationError.isError(error)) {
51
+ throw error;
52
+ }
48
53
  return error.message;
49
54
  }
50
55
  };
@@ -1,21 +1,21 @@
1
+ import { StringHelper } from '../../utils';
1
2
  import { ValidationLocalization } from './validation-localization';
2
3
  import * as yup from 'yup';
3
- const EMAIL_REGEX = /^[a-zA-Z0-9_]([.+-]?[a-zA-Z0-9_])*@[a-zA-Z0-9]([.-]?[a-zA-Z0-9])*\.[a-zA-Z]{2,}$/;
4
4
  /** The email format both email schemas check. Presence — empty, `null`, `undefined` — is decided by the schema the caller picks. */
5
5
  export const isValidEmail = (value) => {
6
- return EMAIL_REGEX.test(value);
6
+ return StringHelper.isEmail(value);
7
7
  };
8
8
  export const emailValidationSchema = () => {
9
9
  const msg = new ValidationLocalization();
10
- return yup.string().required(msg.required).matches(EMAIL_REGEX, {
11
- excludeEmptyString: true,
12
- message: msg.email
13
- });
10
+ return yup
11
+ .string()
12
+ .required(msg.required)
13
+ .test('email', msg.email, (value) => !value || StringHelper.isEmail(value));
14
14
  };
15
15
  export const nullableEmailValidationSchema = () => {
16
16
  const msg = new ValidationLocalization();
17
- return yup.string().nullable().matches(EMAIL_REGEX, {
18
- excludeEmptyString: true,
19
- message: msg.email
20
- });
17
+ return yup
18
+ .string()
19
+ .nullable()
20
+ .test('email', msg.email, (value) => !value || StringHelper.isEmail(value));
21
21
  };
@@ -1,4 +1,5 @@
1
- <script lang="ts">import { getFormFieldLabel } from '../_internal/form-field-label-context';
1
+ <script lang="ts">import { stopClickPropagation } from '../../core/actions';
2
+ import { getFormFieldLabel } from '../_internal/form-field-label-context';
2
3
  import { Icon } from '../icon';
3
4
  import IconCheckmark from '@fluentui/svg-icons/icons/checkmark_12_regular.svg?raw';
4
5
  import IconSubtract from '@fluentui/svg-icons/icons/subtract_16_regular.svg?raw';
@@ -7,8 +8,7 @@ const isOn = $derived(checked === true);
7
8
  const isIndeterminate = $derived(checked === 'indeterminate');
8
9
  const ariaChecked = $derived(isIndeterminate ? 'mixed' : isOn ? 'true' : 'false');
9
10
  const formFieldLabel = getFormFieldLabel();
10
- const handleClick = (event) => {
11
- event.stopPropagation();
11
+ const handleClick = () => {
12
12
  if (disabled) {
13
13
  return;
14
14
  }
@@ -22,7 +22,8 @@ const handleClick = (event) => {
22
22
  class:check--on={isOn}
23
23
  class:check--indeterminate={isIndeterminate}
24
24
  class:check--disabled={disabled}
25
- title={title}>
25
+ title={title}
26
+ use:stopClickPropagation>
26
27
  <button
27
28
  type="button"
28
29
  class="check__box"
@@ -65,6 +65,16 @@ const handleClearClick = () => {
65
65
  }
66
66
  emit(null);
67
67
  };
68
+ const handleTriggerKeydown = (e) => {
69
+ if (e.key !== 'Backspace' && e.key !== 'Delete') {
70
+ return;
71
+ }
72
+ if (!mode.clearable || !selectedDate || disabled || readonly || inert) {
73
+ return;
74
+ }
75
+ e.preventDefault();
76
+ emit(null);
77
+ };
68
78
  </script>
69
79
 
70
80
  <div
@@ -89,7 +99,8 @@ const handleClearClick = () => {
89
99
  aria-expanded={open}
90
100
  aria-label={ariaLabel ?? name}
91
101
  aria-labelledby={resolveAriaLabelledby(formFieldLabel, ariaLabel, ariaLabelledby)}
92
- aria-describedby={ariaDescribedby}>
102
+ aria-describedby={ariaDescribedby}
103
+ onkeydown={handleTriggerKeydown}>
93
104
  {#if icon}
94
105
  <span class="date-picker__icon date-picker__icon--leading" aria-hidden="true"
95
106
  ><IconSlot icon={icon} /></span>
@@ -137,7 +148,7 @@ const handleClearClick = () => {
137
148
  <!--
138
149
  @component
139
150
  DatePicker — single-day calendar picker whose calendar opens in a `Popover`. Discriminated by
140
- `clearable`: `clearable: true` allows clearing to `null` and shows a clear (X) button;
151
+ `clearable`: `clearable: true` allows clearing to `null` and shows a clear (X) button — from the keyboard, Backspace / Delete on the trigger;
141
152
  `clearable: false` requires a value and renders no clear control. Emits ISO 8601 strings via
142
153
  `on.change` from local midnight of the picked day.
143
154
 
@@ -47,7 +47,7 @@ type RequiredProps = BaseProps & {
47
47
  type Props = ClearableProps | RequiredProps;
48
48
  /**
49
49
  * DatePicker — single-day calendar picker whose calendar opens in a `Popover`. Discriminated by
50
- * `clearable`: `clearable: true` allows clearing to `null` and shows a clear (X) button;
50
+ * `clearable`: `clearable: true` allows clearing to `null` and shows a clear (X) button — from the keyboard, Backspace / Delete on the trigger;
51
51
  * `clearable: false` requires a value and renders no clear control. Emits ISO 8601 strings via
52
52
  * `on.change` from local midnight of the picked day.
53
53
  *