@octanejs/radix 0.1.32 → 0.1.33
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/dist/cjs/AccessibleIcon.cjs +56 -0
- package/dist/cjs/Accordion.cjs +272 -0
- package/dist/cjs/AlertDialog.cjs +144 -0
- package/dist/cjs/Arrow.cjs +43 -0
- package/dist/cjs/AspectRatio.cjs +56 -0
- package/dist/cjs/Avatar.cjs +150 -0
- package/dist/cjs/Checkbox.cjs +281 -0
- package/dist/cjs/Collapsible.cjs +176 -0
- package/dist/cjs/ContextMenu.cjs +315 -0
- package/dist/cjs/Dialog.cjs +291 -0
- package/dist/cjs/DismissableLayer.cjs +382 -0
- package/dist/cjs/DropdownMenu.cjs +296 -0
- package/dist/cjs/FocusScope.cjs +257 -0
- package/dist/cjs/Form.cjs +537 -0
- package/dist/cjs/HoverCard.cjs +309 -0
- package/dist/cjs/Label.cjs +42 -0
- package/dist/cjs/Menu.cjs +925 -0
- package/dist/cjs/Menubar.cjs +475 -0
- package/dist/cjs/NavigationMenu.cjs +942 -0
- package/dist/cjs/OneTimePasswordField.cjs +729 -0
- package/dist/cjs/PasswordToggleField.cjs +377 -0
- package/dist/cjs/Popover.cjs +340 -0
- package/dist/cjs/Popper.cjs +368 -0
- package/dist/cjs/Portal.cjs +40 -0
- package/dist/cjs/Presence.cjs +183 -0
- package/dist/cjs/Primitive.cjs +63 -0
- package/dist/cjs/Progress.cjs +111 -0
- package/dist/cjs/Radio.cjs +240 -0
- package/dist/cjs/RadioGroup.cjs +216 -0
- package/dist/cjs/RovingFocusGroup.cjs +253 -0
- package/dist/cjs/ScrollArea.cjs +828 -0
- package/dist/cjs/Select.cjs +1429 -0
- package/dist/cjs/Separator.cjs +51 -0
- package/dist/cjs/Slider.cjs +634 -0
- package/dist/cjs/Slot.cjs +97 -0
- package/dist/cjs/Switch.cjs +253 -0
- package/dist/cjs/Tabs.cjs +195 -0
- package/dist/cjs/Toast.cjs +733 -0
- package/dist/cjs/Toggle.cjs +54 -0
- package/dist/cjs/ToggleGroup.cjs +174 -0
- package/dist/cjs/Toolbar.cjs +165 -0
- package/dist/cjs/Tooltip.cjs +628 -0
- package/dist/cjs/VisuallyHidden.cjs +52 -0
- package/dist/cjs/collection.cjs +95 -0
- package/dist/cjs/compose-event-handlers.cjs +35 -0
- package/dist/cjs/compose-refs.cjs +68 -0
- package/dist/cjs/context.cjs +96 -0
- package/dist/cjs/direction.cjs +41 -0
- package/dist/cjs/focus-guards.cjs +76 -0
- package/dist/cjs/index.cjs +174 -0
- package/dist/cjs/internal.cjs +51 -0
- package/dist/cjs/scroll-lock.cjs +67 -0
- package/dist/cjs/use-callback-ref.cjs +47 -0
- package/dist/cjs/use-effect-event.cjs +52 -0
- package/dist/cjs/use-is-hydrated.cjs +43 -0
- package/dist/cjs/use-previous.cjs +47 -0
- package/dist/cjs/use-size.cjs +69 -0
- package/dist/cjs/useControllableState.cjs +80 -0
- package/dist/cjs/useId.cjs +36 -0
- package/package.json +14 -7
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
var scroll_lock_exports = {};
|
|
20
|
+
__export(scroll_lock_exports, {
|
|
21
|
+
useScrollLock: () => useScrollLock
|
|
22
|
+
});
|
|
23
|
+
module.exports = __toCommonJS(scroll_lock_exports);
|
|
24
|
+
var import_octane = require("octane");
|
|
25
|
+
var import_internal = require("./internal.cjs");
|
|
26
|
+
let lockCount = 0;
|
|
27
|
+
let originalOverflow = "";
|
|
28
|
+
let originalPaddingRight = "";
|
|
29
|
+
function lockBody() {
|
|
30
|
+
if (lockCount === 0) {
|
|
31
|
+
const body = document.body;
|
|
32
|
+
originalOverflow = body.style.overflow;
|
|
33
|
+
originalPaddingRight = body.style.paddingRight;
|
|
34
|
+
const scrollbarWidth = window.innerWidth - document.documentElement.clientWidth;
|
|
35
|
+
if (scrollbarWidth > 0) {
|
|
36
|
+
const computedPadding = parseInt(getComputedStyle(body).paddingRight, 10) || 0;
|
|
37
|
+
body.style.paddingRight = `${computedPadding + scrollbarWidth}px`;
|
|
38
|
+
}
|
|
39
|
+
body.style.overflow = "hidden";
|
|
40
|
+
}
|
|
41
|
+
lockCount++;
|
|
42
|
+
}
|
|
43
|
+
function unlockBody() {
|
|
44
|
+
lockCount = Math.max(0, lockCount - 1);
|
|
45
|
+
if (lockCount === 0) {
|
|
46
|
+
document.body.style.overflow = originalOverflow;
|
|
47
|
+
document.body.style.paddingRight = originalPaddingRight;
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
function useScrollLock(...args) {
|
|
51
|
+
const [user, slotArg] = (0, import_internal.splitSlot)(args);
|
|
52
|
+
const slot = slotArg ?? (0, import_internal.S)("useScrollLock");
|
|
53
|
+
const enabled = user[0] ?? true;
|
|
54
|
+
(0, import_octane.useEffect)(
|
|
55
|
+
() => {
|
|
56
|
+
if (!enabled) return;
|
|
57
|
+
lockBody();
|
|
58
|
+
return unlockBody;
|
|
59
|
+
},
|
|
60
|
+
[enabled],
|
|
61
|
+
(0, import_internal.subSlot)(slot, "e")
|
|
62
|
+
);
|
|
63
|
+
}
|
|
64
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
65
|
+
0 && (module.exports = {
|
|
66
|
+
useScrollLock
|
|
67
|
+
});
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
var use_callback_ref_exports = {};
|
|
20
|
+
__export(use_callback_ref_exports, {
|
|
21
|
+
useCallbackRef: () => useCallbackRef
|
|
22
|
+
});
|
|
23
|
+
module.exports = __toCommonJS(use_callback_ref_exports);
|
|
24
|
+
var import_octane = require("octane");
|
|
25
|
+
var import_internal = require("./internal.cjs");
|
|
26
|
+
function useCallbackRef(...args) {
|
|
27
|
+
const [user, slotArg] = (0, import_internal.splitSlot)(args);
|
|
28
|
+
const slot = slotArg ?? (0, import_internal.S)("useCallbackRef");
|
|
29
|
+
const callback = user[0];
|
|
30
|
+
const callbackRef = (0, import_octane.useRef)(callback, (0, import_internal.subSlot)(slot, "ref"));
|
|
31
|
+
(0, import_octane.useEffect)(
|
|
32
|
+
() => {
|
|
33
|
+
callbackRef.current = callback;
|
|
34
|
+
},
|
|
35
|
+
void 0,
|
|
36
|
+
(0, import_internal.subSlot)(slot, "e")
|
|
37
|
+
);
|
|
38
|
+
return (0, import_octane.useMemo)(
|
|
39
|
+
() => ((...fnArgs) => callbackRef.current?.(...fnArgs)),
|
|
40
|
+
[],
|
|
41
|
+
(0, import_internal.subSlot)(slot, "m")
|
|
42
|
+
);
|
|
43
|
+
}
|
|
44
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
45
|
+
0 && (module.exports = {
|
|
46
|
+
useCallbackRef
|
|
47
|
+
});
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
var use_effect_event_exports = {};
|
|
20
|
+
__export(use_effect_event_exports, {
|
|
21
|
+
useEffectEvent: () => useEffectEvent
|
|
22
|
+
});
|
|
23
|
+
module.exports = __toCommonJS(use_effect_event_exports);
|
|
24
|
+
var import_octane = require("octane");
|
|
25
|
+
var import_internal = require("./internal.cjs");
|
|
26
|
+
function useEffectEvent(...args) {
|
|
27
|
+
const [user, slotArg] = (0, import_internal.splitSlot)(args);
|
|
28
|
+
const slot = slotArg ?? (0, import_internal.S)("useEffectEvent");
|
|
29
|
+
const callback = user[0];
|
|
30
|
+
const ref = (0, import_octane.useRef)(
|
|
31
|
+
() => {
|
|
32
|
+
throw new Error("Cannot call an event handler while rendering.");
|
|
33
|
+
},
|
|
34
|
+
(0, import_internal.subSlot)(slot, "ref")
|
|
35
|
+
);
|
|
36
|
+
(0, import_octane.useInsertionEffect)(
|
|
37
|
+
() => {
|
|
38
|
+
ref.current = callback;
|
|
39
|
+
},
|
|
40
|
+
void 0,
|
|
41
|
+
(0, import_internal.subSlot)(slot, "e")
|
|
42
|
+
);
|
|
43
|
+
return (0, import_octane.useMemo)(
|
|
44
|
+
() => ((...fnArgs) => ref.current?.(...fnArgs)),
|
|
45
|
+
[],
|
|
46
|
+
(0, import_internal.subSlot)(slot, "m")
|
|
47
|
+
);
|
|
48
|
+
}
|
|
49
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
50
|
+
0 && (module.exports = {
|
|
51
|
+
useEffectEvent
|
|
52
|
+
});
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
var use_is_hydrated_exports = {};
|
|
20
|
+
__export(use_is_hydrated_exports, {
|
|
21
|
+
useIsHydrated: () => useIsHydrated
|
|
22
|
+
});
|
|
23
|
+
module.exports = __toCommonJS(use_is_hydrated_exports);
|
|
24
|
+
var import_octane = require("octane");
|
|
25
|
+
var import_internal = require("./internal.cjs");
|
|
26
|
+
function subscribe() {
|
|
27
|
+
return () => {
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
function useIsHydrated(...args) {
|
|
31
|
+
const [, slotArg] = (0, import_internal.splitSlot)(args);
|
|
32
|
+
const slot = slotArg ?? (0, import_internal.S)("useIsHydrated");
|
|
33
|
+
return (0, import_octane.useSyncExternalStore)(
|
|
34
|
+
subscribe,
|
|
35
|
+
() => true,
|
|
36
|
+
() => false,
|
|
37
|
+
(0, import_internal.subSlot)(slot, "s")
|
|
38
|
+
);
|
|
39
|
+
}
|
|
40
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
41
|
+
0 && (module.exports = {
|
|
42
|
+
useIsHydrated
|
|
43
|
+
});
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
var use_previous_exports = {};
|
|
20
|
+
__export(use_previous_exports, {
|
|
21
|
+
usePrevious: () => usePrevious
|
|
22
|
+
});
|
|
23
|
+
module.exports = __toCommonJS(use_previous_exports);
|
|
24
|
+
var import_octane = require("octane");
|
|
25
|
+
var import_internal = require("./internal.cjs");
|
|
26
|
+
function previousCommittedValue(current, previous) {
|
|
27
|
+
return previous === void 0 ? current : previous.source;
|
|
28
|
+
}
|
|
29
|
+
const PREVIOUS_VALUE_OPTIONS = {
|
|
30
|
+
sourceEqual: (previous, next) => previous === next
|
|
31
|
+
};
|
|
32
|
+
function usePrevious(...args) {
|
|
33
|
+
const [user, slotArg] = (0, import_internal.splitSlot)(args);
|
|
34
|
+
const slot = slotArg ?? (0, import_internal.S)("usePrevious");
|
|
35
|
+
const value = user[0];
|
|
36
|
+
const [previous] = (0, import_octane.useLinkedState)(
|
|
37
|
+
value,
|
|
38
|
+
previousCommittedValue,
|
|
39
|
+
PREVIOUS_VALUE_OPTIONS,
|
|
40
|
+
(0, import_internal.subSlot)(slot, "previous")
|
|
41
|
+
);
|
|
42
|
+
return previous;
|
|
43
|
+
}
|
|
44
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
45
|
+
0 && (module.exports = {
|
|
46
|
+
usePrevious
|
|
47
|
+
});
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
var use_size_exports = {};
|
|
20
|
+
__export(use_size_exports, {
|
|
21
|
+
useSize: () => useSize
|
|
22
|
+
});
|
|
23
|
+
module.exports = __toCommonJS(use_size_exports);
|
|
24
|
+
var import_octane = require("octane");
|
|
25
|
+
var import_internal = require("./internal.cjs");
|
|
26
|
+
function useSize(...args) {
|
|
27
|
+
const [user, slotArg] = (0, import_internal.splitSlot)(args);
|
|
28
|
+
const slot = slotArg ?? (0, import_internal.S)("useSize");
|
|
29
|
+
const element = user[0];
|
|
30
|
+
const [size, setSize] = (0, import_octane.useState)(
|
|
31
|
+
void 0,
|
|
32
|
+
(0, import_internal.subSlot)(slot, "size")
|
|
33
|
+
);
|
|
34
|
+
(0, import_octane.useLayoutEffect)(
|
|
35
|
+
() => {
|
|
36
|
+
if (element) {
|
|
37
|
+
setSize({ width: element.offsetWidth, height: element.offsetHeight });
|
|
38
|
+
if (typeof ResizeObserver === "undefined") return;
|
|
39
|
+
const resizeObserver = new ResizeObserver((entries) => {
|
|
40
|
+
if (!Array.isArray(entries) || !entries.length) return;
|
|
41
|
+
const entry = entries[0];
|
|
42
|
+
let width;
|
|
43
|
+
let height;
|
|
44
|
+
if ("borderBoxSize" in entry) {
|
|
45
|
+
const borderSizeEntry = entry["borderBoxSize"];
|
|
46
|
+
const borderSize = Array.isArray(borderSizeEntry) ? borderSizeEntry[0] : borderSizeEntry;
|
|
47
|
+
width = borderSize["inlineSize"];
|
|
48
|
+
height = borderSize["blockSize"];
|
|
49
|
+
} else {
|
|
50
|
+
width = element.offsetWidth;
|
|
51
|
+
height = element.offsetHeight;
|
|
52
|
+
}
|
|
53
|
+
setSize({ width, height });
|
|
54
|
+
});
|
|
55
|
+
resizeObserver.observe(element, { box: "border-box" });
|
|
56
|
+
return () => resizeObserver.unobserve(element);
|
|
57
|
+
} else {
|
|
58
|
+
setSize(void 0);
|
|
59
|
+
}
|
|
60
|
+
},
|
|
61
|
+
[element],
|
|
62
|
+
(0, import_internal.subSlot)(slot, "e")
|
|
63
|
+
);
|
|
64
|
+
return size;
|
|
65
|
+
}
|
|
66
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
67
|
+
0 && (module.exports = {
|
|
68
|
+
useSize
|
|
69
|
+
});
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
var useControllableState_exports = {};
|
|
20
|
+
__export(useControllableState_exports, {
|
|
21
|
+
useControllableState: () => useControllableState
|
|
22
|
+
});
|
|
23
|
+
module.exports = __toCommonJS(useControllableState_exports);
|
|
24
|
+
var import_octane = require("octane");
|
|
25
|
+
var import_internal = require("./internal.cjs");
|
|
26
|
+
function useControllableState(...args) {
|
|
27
|
+
const [user, slotArg] = (0, import_internal.splitSlot)(args);
|
|
28
|
+
const slot = slotArg ?? (0, import_internal.S)("useControllableState");
|
|
29
|
+
const { prop, defaultProp, onChange } = user[0] ?? {};
|
|
30
|
+
const [uncontrolledProp, setUncontrolledProp, onChangeRef] = useUncontrolledState(
|
|
31
|
+
defaultProp,
|
|
32
|
+
onChange,
|
|
33
|
+
slot
|
|
34
|
+
);
|
|
35
|
+
const isControlled = prop !== void 0;
|
|
36
|
+
const value = isControlled ? prop : uncontrolledProp;
|
|
37
|
+
const setValue = (0, import_octane.useCallback)(
|
|
38
|
+
((nextValue) => {
|
|
39
|
+
if (isControlled) {
|
|
40
|
+
const resolved = isFunction(nextValue) ? nextValue(prop) : nextValue;
|
|
41
|
+
if (resolved !== prop) onChangeRef.current?.(resolved);
|
|
42
|
+
} else {
|
|
43
|
+
setUncontrolledProp(nextValue);
|
|
44
|
+
}
|
|
45
|
+
}),
|
|
46
|
+
[isControlled, prop, setUncontrolledProp],
|
|
47
|
+
(0, import_internal.subSlot)(slot, "setValue")
|
|
48
|
+
);
|
|
49
|
+
return [value, setValue];
|
|
50
|
+
}
|
|
51
|
+
function useUncontrolledState(defaultProp, onChange, slot) {
|
|
52
|
+
const [value, setValue] = (0, import_octane.useState)(defaultProp, (0, import_internal.subSlot)(slot, "state"));
|
|
53
|
+
const prevValueRef = (0, import_octane.useRef)(value, (0, import_internal.subSlot)(slot, "prev"));
|
|
54
|
+
const onChangeRef = (0, import_octane.useRef)(onChange, (0, import_internal.subSlot)(slot, "onChangeRef"));
|
|
55
|
+
(0, import_octane.useInsertionEffect)(
|
|
56
|
+
() => {
|
|
57
|
+
onChangeRef.current = onChange;
|
|
58
|
+
},
|
|
59
|
+
[onChange],
|
|
60
|
+
(0, import_internal.subSlot)(slot, "onChangeEffect")
|
|
61
|
+
);
|
|
62
|
+
(0, import_octane.useEffect)(
|
|
63
|
+
() => {
|
|
64
|
+
if (prevValueRef.current !== value) {
|
|
65
|
+
onChangeRef.current?.(value);
|
|
66
|
+
prevValueRef.current = value;
|
|
67
|
+
}
|
|
68
|
+
},
|
|
69
|
+
[value],
|
|
70
|
+
(0, import_internal.subSlot)(slot, "changeEffect")
|
|
71
|
+
);
|
|
72
|
+
return [value, setValue, onChangeRef];
|
|
73
|
+
}
|
|
74
|
+
function isFunction(value) {
|
|
75
|
+
return typeof value === "function";
|
|
76
|
+
}
|
|
77
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
78
|
+
0 && (module.exports = {
|
|
79
|
+
useControllableState
|
|
80
|
+
});
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
var useId_exports = {};
|
|
20
|
+
__export(useId_exports, {
|
|
21
|
+
useId: () => useId
|
|
22
|
+
});
|
|
23
|
+
module.exports = __toCommonJS(useId_exports);
|
|
24
|
+
var import_octane = require("octane");
|
|
25
|
+
var import_internal = require("./internal.cjs");
|
|
26
|
+
function useId(...args) {
|
|
27
|
+
const [user, slotArg] = (0, import_internal.splitSlot)(args);
|
|
28
|
+
const slot = slotArg ?? (0, import_internal.S)("useId");
|
|
29
|
+
const deterministicId = user[0];
|
|
30
|
+
const id = (0, import_octane.useId)(slot);
|
|
31
|
+
return deterministicId || `radix-${id}`;
|
|
32
|
+
}
|
|
33
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
34
|
+
0 && (module.exports = {
|
|
35
|
+
useId
|
|
36
|
+
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@octanejs/radix",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.33",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"sideEffects": false,
|
|
@@ -32,17 +32,23 @@
|
|
|
32
32
|
"types": "src/index.ts",
|
|
33
33
|
"files": [
|
|
34
34
|
"src",
|
|
35
|
-
"README.md"
|
|
35
|
+
"README.md",
|
|
36
|
+
"dist/cjs"
|
|
36
37
|
],
|
|
37
38
|
"exports": {
|
|
38
|
-
".":
|
|
39
|
+
".": {
|
|
40
|
+
"types": "./src/index.ts",
|
|
41
|
+
"import": "./src/index.ts",
|
|
42
|
+
"require": "./dist/cjs/index.cjs",
|
|
43
|
+
"default": "./src/index.ts"
|
|
44
|
+
}
|
|
39
45
|
},
|
|
40
46
|
"dependencies": {
|
|
41
47
|
"aria-hidden": "^1.2.6",
|
|
42
|
-
"@octanejs/floating-ui": "0.1.
|
|
48
|
+
"@octanejs/floating-ui": "0.1.33"
|
|
43
49
|
},
|
|
44
50
|
"peerDependencies": {
|
|
45
|
-
"octane": "0.1.
|
|
51
|
+
"octane": "0.1.34"
|
|
46
52
|
},
|
|
47
53
|
"devDependencies": {
|
|
48
54
|
"@tsrx/react": "^0.2.56",
|
|
@@ -51,9 +57,10 @@
|
|
|
51
57
|
"react": "^19.2.7",
|
|
52
58
|
"react-dom": "^19.2.7",
|
|
53
59
|
"vitest": "^4.1.10",
|
|
54
|
-
"octane": "0.1.
|
|
60
|
+
"octane": "0.1.34"
|
|
55
61
|
},
|
|
56
62
|
"scripts": {
|
|
57
|
-
"test": "vitest run"
|
|
63
|
+
"test": "vitest run",
|
|
64
|
+
"build:cjs": "node ../../scripts/build-package-commonjs.mjs"
|
|
58
65
|
}
|
|
59
66
|
}
|