sinwan-ui-core 1.4.0 → 1.5.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/CHANGELOG.md CHANGED
@@ -2,6 +2,16 @@
2
2
 
3
3
  All notable changes to this package are documented in this file. The format follows [Keep a Changelog](https://keepachangelog.com/en/1.1.0/), and this package uses [Semantic Versioning](https://semver.org/).
4
4
 
5
+ ## [1.5.0]
6
+
7
+ ### Added
8
+
9
+ - **SW202, a controlled prop that is `undefined`**: in development, `TabsRoot`, `AccordionRoot`, `RadioGroupRoot` and `ToggleGroupRoot` (`value`), `CheckboxRoot` and `SwitchRoot` (`checked`), `DialogRoot`, `PopoverRoot`, `TooltipRoot` and `CollapsibleRoot` (`open`), and `useControllableState` warn once when the prop is present but `undefined`. For example: `[Sinwan] SW202: <SwitchRoot> checked is undefined: the control is controlled with no value and ignores input…`. Before, the control silently ignored clicks and keys. Behaviour is unchanged: a present prop still makes the control controlled. The check uses `devWarn` from `sinwan/dev`, so the production bundle of sinwan prints nothing and does no extra work.
10
+
11
+ ### Changed
12
+
13
+ - **Requires `sinwan` 2.5.0 or later** (peer `>=2.5.0 <3.0.0`) for `sinwan/dev`. `sinwan/dev` is kept as a bare external import in `dist/`.
14
+
5
15
  ## [1.4.0]
6
16
 
7
17
  ### Added
@@ -1,3 +1,18 @@
1
+ // src/internal/controlled.ts
2
+ import { devWarn } from "sinwan/dev";
3
+ function currentValue(props, key) {
4
+ const value = Reflect.get(props, key);
5
+ return typeof value === "function" && value.length === 0 ? value() : value;
6
+ }
7
+ function isControlledProp(props, key, component) {
8
+ if (!(key in props))
9
+ return false;
10
+ if (currentValue(props, key) === undefined) {
11
+ devWarn("SW202", `<${component}> ${key} is undefined: the control is controlled with no value and ignores input. Omit ${key}, or pass null or "" for an empty controlled value.`);
12
+ }
13
+ return true;
14
+ }
15
+
1
16
  // src/core.tsx
2
17
  import { unwrap as _$unwrap } from "sinwan/reactivity";
3
18
  import { cc, onMounted, onUnmounted } from "sinwan/component";
@@ -60,7 +75,7 @@ function readOptionValue(value) {
60
75
  return value;
61
76
  }
62
77
  function useControllableState2(options) {
63
- const isControlled = "value" in options;
78
+ const isControlled = isControlledProp(options, "value", "useControllableState");
64
79
  const read = () => isControlled ? readOptionValue(options.value) : options.defaultValue;
65
80
  const state = signal2(isControlled ? read() : options.defaultValue);
66
81
  const setState = (value) => {
@@ -104,4 +119,4 @@ function trapFocus2(event, root) {
104
119
  first.focus();
105
120
  }
106
121
  }
107
- export { SinwanPortal2, Show3, signal2, Presence2, UiPortal2, useControllableState2, getFocusableElements2, trapFocus2 };
122
+ export { isControlledProp, SinwanPortal2, Show3, signal2, Presence2, UiPortal2, useControllableState2, getFocusableElements2, trapFocus2 };
@@ -2,13 +2,14 @@ import {
2
2
  Slot2
3
3
  } from "./chunk-bw9vp0y9.js";
4
4
  import {
5
- useAnchorPosition2
6
- } from "./chunk-6r59k5mb.js";
7
- import {
5
+ isControlledProp,
8
6
  Presence2,
9
7
  UiPortal2,
10
8
  trapFocus2
11
- } from "./chunk-ejwby1pn.js";
9
+ } from "./chunk-dn425n4g.js";
10
+ import {
11
+ useAnchorPosition2
12
+ } from "./chunk-6r59k5mb.js";
12
13
  import {
13
14
  isDismissExemptPointerTarget2
14
15
  } from "./chunk-9whagkb6.js";
@@ -73,9 +74,9 @@ var _$tmpl_4 = {
73
74
  ]
74
75
  };
75
76
  var REOPEN_LOCK_MS = 280;
76
- function createOpenState(props) {
77
+ function createOpenState(props, component) {
77
78
  const openLocal = signal(props.defaultOpen ?? false);
78
- const open = "open" in props ? computed(() => Boolean(props.open)) : openLocal;
79
+ const open = isControlledProp(props, "open", component) ? computed(() => Boolean(props.open)) : openLocal;
79
80
  const set = (next) => {
80
81
  if (!("open" in props))
81
82
  openLocal.value = next;
@@ -133,7 +134,7 @@ var DialogKey2 = Symbol("sinwan-ui.dialog");
133
134
  var DialogLabelsKey2 = Symbol("sinwan-ui.dialog-labels");
134
135
  var dialogCount = 0;
135
136
  var DialogRoot2 = cc((props) => {
136
- const api = createOpenState(props);
137
+ const api = createOpenState(props, "DialogRoot");
137
138
  provide(DialogKey2, api);
138
139
  dialogCount += 1;
139
140
  provide(DialogLabelsKey2, {
@@ -325,7 +326,7 @@ var DialogContent2 = cc((props) => {
325
326
  var CollapsibleKey2 = Symbol("sinwan-ui.collapsible");
326
327
  var CollapsibleRoot2 = cc((props) => {
327
328
  const openLocal = signal(props.defaultOpen ?? false);
328
- const open = "open" in props ? computed(() => Boolean(props.open)) : openLocal;
329
+ const open = isControlledProp(props, "open", "CollapsibleRoot") ? computed(() => Boolean(props.open)) : openLocal;
329
330
  const set = (next) => {
330
331
  if (!("open" in props))
331
332
  openLocal.value = next;
@@ -396,7 +397,7 @@ var CollapsibleContent2 = cc((props) => {
396
397
  });
397
398
  var PopoverKey2 = Symbol("sinwan-ui.popover");
398
399
  var PopoverRoot2 = cc((props) => {
399
- const api = createOpenState(props);
400
+ const api = createOpenState(props, "PopoverRoot");
400
401
  provide(PopoverKey2, {
401
402
  ...api,
402
403
  placement: props.placement ?? "bottom",
@@ -495,7 +496,7 @@ var TooltipProvider2 = cc((props) => {
495
496
  return props.children ?? null;
496
497
  });
497
498
  var TooltipRoot2 = cc((props) => {
498
- const api = createOpenState(props);
499
+ const api = createOpenState(props, "TooltipRoot");
499
500
  provide(TooltipKey2, api);
500
501
  return /* @__PURE__ */ jsx(Fragment, {
501
502
  children: () => _$unwrap(props).children
@@ -1,6 +1,7 @@
1
1
  import {
2
+ isControlledProp,
2
3
  Presence2
3
- } from "./chunk-ejwby1pn.js";
4
+ } from "./chunk-dn425n4g.js";
4
5
  import {
5
6
  DirectionKey2
6
7
  } from "./chunk-f6hw8ash.js";
@@ -187,7 +188,7 @@ var LTR = { dir: { value: "ltr" } };
187
188
  var TabsKey2 = Symbol("sinwan-ui.tabs");
188
189
  var TabsRoot2 = cc((props) => {
189
190
  const valueLocal = signal(props.defaultValue ?? "");
190
- const value = "value" in props ? computed(() => props.value ?? "") : valueLocal;
191
+ const value = isControlledProp(props, "value", "TabsRoot") ? computed(() => props.value ?? "") : valueLocal;
191
192
  const set = (next) => {
192
193
  if (!("value" in props))
193
194
  valueLocal.value = next;
@@ -288,7 +289,7 @@ var AccordionRoot2 = cc((props) => {
288
289
  const type = () => props.type ?? "single";
289
290
  const collapsible = () => props.collapsible ?? true;
290
291
  const valueLocal = signal(toValueList(props.defaultValue));
291
- const value = "value" in props ? computed(() => toValueList(props.value)) : valueLocal;
292
+ const value = isControlledProp(props, "value", "AccordionRoot") ? computed(() => toValueList(props.value)) : valueLocal;
292
293
  const set = (next) => {
293
294
  if (!("value" in props))
294
295
  valueLocal.value = next;
@@ -363,7 +364,7 @@ var AccordionContent2 = cc((props) => {
363
364
  });
364
365
  var CheckboxRoot2 = cc((props) => {
365
366
  const checkedLocal = signal(props.defaultChecked ?? false);
366
- const checked = "checked" in props ? computed(() => Boolean(props.checked)) : checkedLocal;
367
+ const checked = isControlledProp(props, "checked", "CheckboxRoot") ? computed(() => Boolean(props.checked)) : checkedLocal;
367
368
  const setChecked = (next) => {
368
369
  if (!("checked" in props))
369
370
  checkedLocal.value = next;
@@ -396,7 +397,7 @@ var CheckboxRoot2 = cc((props) => {
396
397
  });
397
398
  var SwitchRoot2 = cc((props) => {
398
399
  const checkedLocal = signal(props.defaultChecked ?? false);
399
- const checked = "checked" in props ? computed(() => Boolean(props.checked)) : checkedLocal;
400
+ const checked = isControlledProp(props, "checked", "SwitchRoot") ? computed(() => Boolean(props.checked)) : checkedLocal;
400
401
  const set = (next) => {
401
402
  if (!("checked" in props))
402
403
  checkedLocal.value = next;
@@ -425,7 +426,7 @@ var SwitchRoot2 = cc((props) => {
425
426
  var RadioGroupKey2 = Symbol("sinwan-ui.radio-group");
426
427
  var RadioGroupRoot2 = cc((props) => {
427
428
  const valueLocal = signal(props.defaultValue ?? "");
428
- const value = "value" in props ? computed(() => props.value ?? "") : valueLocal;
429
+ const value = isControlledProp(props, "value", "RadioGroupRoot") ? computed(() => props.value ?? "") : valueLocal;
429
430
  const set = (next) => {
430
431
  if (!("value" in props))
431
432
  valueLocal.value = next;
@@ -516,7 +517,7 @@ var ToggleGroupRoot2 = cc((props) => {
516
517
  const type = () => props.type ?? "single";
517
518
  const ariaProps = ariaOf(props);
518
519
  const valueLocal = signal(toValueList(props.defaultValue));
519
- const value = "value" in props ? computed(() => toValueList(props.value)) : valueLocal;
520
+ const value = isControlledProp(props, "value", "ToggleGroupRoot") ? computed(() => toValueList(props.value)) : valueLocal;
520
521
  const set = (next) => {
521
522
  if (!("value" in props))
522
523
  valueLocal.value = next;
@@ -1,10 +1,10 @@
1
- import {
2
- useAnchorPosition2
3
- } from "./chunk-6r59k5mb.js";
4
1
  import {
5
2
  Presence2,
6
3
  UiPortal2
7
- } from "./chunk-ejwby1pn.js";
4
+ } from "./chunk-dn425n4g.js";
5
+ import {
6
+ useAnchorPosition2
7
+ } from "./chunk-6r59k5mb.js";
8
8
 
9
9
  // src/menu-sub.tsx
10
10
  import { unwrap as _$unwrap } from "sinwan/reactivity";
package/dist/controls.js CHANGED
@@ -21,13 +21,13 @@ import {
21
21
  ToggleGroupKey2,
22
22
  ToggleGroupRoot2,
23
23
  ToggleGroupItem2
24
- } from "./chunks/chunk-b3nbmmyq.js";
24
+ } from "./chunks/chunk-n6gs6631.js";
25
25
  import"./chunks/chunk-f6hw8ash.js";
26
26
  import {
27
27
  Slot2
28
28
  } from "./chunks/chunk-bw9vp0y9.js";
29
29
  import"./chunks/chunk-7r6fwdyt.js";
30
- import"./chunks/chunk-ejwby1pn.js";
30
+ import"./chunks/chunk-dn425n4g.js";
31
31
  import"./chunks/chunk-6r59k5mb.js";
32
32
  export {
33
33
  AccordionContent2 as AccordionContent,
package/dist/core.js CHANGED
@@ -7,7 +7,7 @@ import {
7
7
  useControllableState2,
8
8
  getFocusableElements2,
9
9
  trapFocus2
10
- } from "./chunks/chunk-ejwby1pn.js";
10
+ } from "./chunks/chunk-dn425n4g.js";
11
11
  import {
12
12
  toFloatingPlacement2,
13
13
  basePlacement2,
package/dist/index.js CHANGED
@@ -5,6 +5,15 @@ import {
5
5
  import {
6
6
  Slot2
7
7
  } from "./chunks/chunk-bw9vp0y9.js";
8
+ import {
9
+ SinwanPortal2,
10
+ signal2,
11
+ Presence2,
12
+ UiPortal2,
13
+ useControllableState2,
14
+ getFocusableElements2,
15
+ trapFocus2
16
+ } from "./chunks/chunk-dn425n4g.js";
8
17
  import {
9
18
  toFloatingPlacement2,
10
19
  basePlacement2,
@@ -17,15 +26,6 @@ import {
17
26
  useAnchorPosition2,
18
27
  usePointPosition2
19
28
  } from "./chunks/chunk-6r59k5mb.js";
20
- import {
21
- SinwanPortal2,
22
- signal2,
23
- Presence2,
24
- UiPortal2,
25
- useControllableState2,
26
- getFocusableElements2,
27
- trapFocus2
28
- } from "./chunks/chunk-ejwby1pn.js";
29
29
  import {
30
30
  DirectionKey2,
31
31
  DirectionProvider2,
@@ -53,7 +53,7 @@ import {
53
53
  ToggleGroupKey2,
54
54
  ToggleGroupRoot2,
55
55
  ToggleGroupItem2
56
- } from "./chunks/chunk-b3nbmmyq.js";
56
+ } from "./chunks/chunk-n6gs6631.js";
57
57
  import {
58
58
  isDismissExemptPointerTarget2
59
59
  } from "./chunks/chunk-9whagkb6.js";
@@ -62,7 +62,7 @@ import {
62
62
  createMenuSubTriggerHandlers2,
63
63
  isInsideMenuSubContent2,
64
64
  MenuSubContentLayer2
65
- } from "./chunks/chunk-8zvv4kad.js";
65
+ } from "./chunks/chunk-vwgz1k38.js";
66
66
  import {
67
67
  DialogKey2,
68
68
  DialogLabelsKey2,
@@ -86,7 +86,7 @@ import {
86
86
  TooltipRoot2,
87
87
  TooltipTrigger2,
88
88
  TooltipContent2
89
- } from "./chunks/chunk-648ssfj3.js";
89
+ } from "./chunks/chunk-hzq68qq0.js";
90
90
  import {
91
91
  ThemeKey2,
92
92
  ThemeProvider2,
@@ -0,0 +1,6 @@
1
+ /**
2
+ * Whether a control is controlled through `key`: the prop is present, even
3
+ * when its value is `undefined`. In development, a present prop that is
4
+ * `undefined` warns (SW202): the control would ignore input.
5
+ */
6
+ export declare function isControlledProp(props: object, key: string, component: string): boolean;
package/dist/menu-sub.js CHANGED
@@ -3,8 +3,8 @@ import {
3
3
  createMenuSubTriggerHandlers2,
4
4
  isInsideMenuSubContent2,
5
5
  MenuSubContentLayer2
6
- } from "./chunks/chunk-8zvv4kad.js";
7
- import"./chunks/chunk-ejwby1pn.js";
6
+ } from "./chunks/chunk-vwgz1k38.js";
7
+ import"./chunks/chunk-dn425n4g.js";
8
8
  import"./chunks/chunk-6r59k5mb.js";
9
9
  export {
10
10
  MenuSubContentLayer2 as MenuSubContentLayer,
package/dist/overlay.js CHANGED
@@ -21,11 +21,11 @@ import {
21
21
  TooltipRoot2,
22
22
  TooltipTrigger2,
23
23
  TooltipContent2
24
- } from "./chunks/chunk-648ssfj3.js";
24
+ } from "./chunks/chunk-hzq68qq0.js";
25
25
  import"./chunks/chunk-bw9vp0y9.js";
26
26
  import"./chunks/chunk-7r6fwdyt.js";
27
27
  import"./chunks/chunk-9whagkb6.js";
28
- import"./chunks/chunk-ejwby1pn.js";
28
+ import"./chunks/chunk-dn425n4g.js";
29
29
  import"./chunks/chunk-6r59k5mb.js";
30
30
  export {
31
31
  CollapsibleContent2 as CollapsibleContent,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "sinwan-ui-core",
3
- "version": "1.4.0",
3
+ "version": "1.5.0",
4
4
  "description": "Headless behaviour primitives for Sinwan UI components: overlays, floating positioning, dismiss layers, controls, slots, theme and direction.",
5
5
  "author": "Mohammed Ben Cheikh",
6
6
  "license": "MIT",
@@ -109,10 +109,10 @@
109
109
  "@types/bun": "latest",
110
110
  "bun-plugin-sinwan": "^1.0.1",
111
111
  "happy-dom": "^20.14.5",
112
- "sinwan": "^2.0.3",
112
+ "sinwan": "^2.5.0",
113
113
  "typescript": "^5.9.3"
114
114
  },
115
115
  "peerDependencies": {
116
- "sinwan": ">=2.0.3 <3.0.0"
116
+ "sinwan": ">=2.5.0 <3.0.0"
117
117
  }
118
118
  }