@geoffcox/sterling-svelte 2.0.6 → 2.0.7

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.
@@ -8,10 +8,10 @@ type DeprecatedProps = {
8
8
  };
9
9
  export type DropdownProps = HTMLAttributes<HTMLDivElement> & DeprecatedProps & {
10
10
  disabled?: boolean | null | undefined;
11
+ icon?: Snippet;
12
+ onOpen?: (open: boolean | null | undefined) => void;
11
13
  open?: boolean | null | undefined;
12
14
  stayOpenOnClickAway?: boolean | null | undefined;
13
- onOpen?: (open: boolean | null | undefined) => void;
14
- icon?: Snippet;
15
15
  value?: string | Snippet;
16
16
  };
17
17
  export {};
package/dist/Label.svelte CHANGED
@@ -108,8 +108,6 @@
108
108
  targetRequired = targetRef && 'required' in targetRef && !!targetRef.required;
109
109
  };
110
110
 
111
- $inspect(targetRequired);
112
-
113
111
  const onTargetAttributeChanged: MutationCallback = (mutations) => {
114
112
  if (
115
113
  mutations.findIndex(
@@ -18,6 +18,21 @@
18
18
  ...rest
19
19
  }: SliderProps = $props();
20
20
 
21
+ const ensureValueValid = () => {
22
+ const clamped = Math.max(min, Math.min(max, value));
23
+ const newValue = precision !== undefined ? round(clamped, precision) : clamped;
24
+ if (value !== newValue) {
25
+ value = newValue;
26
+ }
27
+ };
28
+
29
+ // ensure incoming value is valid to avoid effect lag
30
+ if (min > max) {
31
+ console.warn('The slider min is greater than max.');
32
+ }
33
+
34
+ ensureValueValid();
35
+
21
36
  let sliderRef: HTMLDivElement;
22
37
 
23
38
  export const blur = () => {
@@ -32,28 +47,14 @@
32
47
  sliderRef?.parentElement?.focus(options);
33
48
  };
34
49
 
35
- let ratio = $derived((value - min) / (max - min));
50
+ let ratio = $derived(max - min > 0 ? (value - min) / (max - min) : 0);
36
51
 
52
+ // when value changes, ensure it is valid right away
37
53
  const setValue = (newValue: number) => {
38
54
  const clamped = Math.max(min, Math.min(max, newValue));
39
55
  value = precision !== undefined ? round(clamped, precision) : clamped;
40
56
  };
41
57
 
42
- // ensure min <= max
43
- $effect(() => {
44
- if (min > max) {
45
- min = max;
46
- }
47
- });
48
-
49
- $effect(() => {
50
- const clamped = Math.max(min, Math.min(max, value));
51
- const newValue = precision !== undefined ? round(clamped, precision) : clamped;
52
- if (value !== newValue) {
53
- value = newValue;
54
- }
55
- });
56
-
57
58
  const setValueByOffset = (offset: number) => {
58
59
  if (sliderSize > 0) {
59
60
  const positionRatio = Math.max(0, Math.min(1, offset / sliderSize));
@@ -62,6 +63,10 @@
62
63
  }
63
64
  };
64
65
 
66
+ $effect(() => {
67
+ ensureValueValid();
68
+ });
69
+
65
70
  // Raise change event when value changes
66
71
  $effect(() => {
67
72
  onChange?.(value);
@@ -10,6 +10,7 @@
10
10
  class: _class,
11
11
  disabled = false,
12
12
  hoverDelayMilliseconds = 1000,
13
+ onOpen,
13
14
  open = $bindable(false),
14
15
  tip,
15
16
  ...rest
@@ -45,6 +46,10 @@
45
46
  }
46
47
  };
47
48
 
49
+ $effect(() => {
50
+ onOpen?.(open);
51
+ });
52
+
48
53
  $effect(() => {
49
54
  if (disabled) {
50
55
  hide();
@@ -3,5 +3,6 @@ import type { CalloutProps } from './Callout.types';
3
3
  export type TooltipProps = Omit<CalloutProps, 'reference'> & {
4
4
  disabled?: boolean;
5
5
  hoverDelayMilliseconds?: number;
6
+ onOpen?: (open: boolean | null | undefined) => void;
6
7
  tip?: string | Snippet;
7
8
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@geoffcox/sterling-svelte",
3
- "version": "2.0.6",
3
+ "version": "2.0.7",
4
4
  "author": "Geoff Cox",
5
5
  "description": "A modern, accessible, and lightweight component library for Svelte.",
6
6
  "license": "MIT",
@@ -64,8 +64,7 @@
64
64
  "lint": "prettier --check . && eslint .",
65
65
  "package": "svelte-kit sync && svelte-package && publint",
66
66
  "preview": "vite preview",
67
- "test": "npm run test:integration && npm run test:unit",
68
- "test:unit": "vitest"
67
+ "test": "npm run test:integration && npm run test:unit"
69
68
  },
70
69
  "peerDependencies": {
71
70
  "svelte": "^5.0.0"
@@ -95,8 +94,7 @@
95
94
  "svelte-check": "^4.0.0",
96
95
  "typescript": "^5.0.0",
97
96
  "typescript-eslint": "^8.20.0",
98
- "vite": "^6.0.0",
99
- "vitest": "^3.0.0"
97
+ "vite": "^6.0.0"
100
98
  },
101
99
  "dependencies": {
102
100
  "@floating-ui/dom": "^1.1.0",