@zag-js/toolbar 2.0.0-next.1
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/LICENSE +21 -0
- package/README.md +19 -0
- package/dist/index.d.mts +8 -0
- package/dist/index.d.ts +8 -0
- package/dist/index.js +39 -0
- package/dist/index.mjs +10 -0
- package/dist/toolbar.anatomy.d.mts +6 -0
- package/dist/toolbar.anatomy.d.ts +6 -0
- package/dist/toolbar.anatomy.js +34 -0
- package/dist/toolbar.anatomy.mjs +8 -0
- package/dist/toolbar.connect.d.mts +7 -0
- package/dist/toolbar.connect.d.ts +7 -0
- package/dist/toolbar.connect.js +229 -0
- package/dist/toolbar.connect.mjs +202 -0
- package/dist/toolbar.dom.d.mts +14 -0
- package/dist/toolbar.dom.d.ts +14 -0
- package/dist/toolbar.dom.js +76 -0
- package/dist/toolbar.dom.mjs +42 -0
- package/dist/toolbar.machine.d.mts +7 -0
- package/dist/toolbar.machine.d.ts +7 -0
- package/dist/toolbar.machine.js +190 -0
- package/dist/toolbar.machine.mjs +155 -0
- package/dist/toolbar.props.d.mts +10 -0
- package/dist/toolbar.props.d.ts +10 -0
- package/dist/toolbar.props.js +49 -0
- package/dist/toolbar.props.mjs +21 -0
- package/dist/toolbar.types.d.mts +148 -0
- package/dist/toolbar.types.d.ts +148 -0
- package/dist/toolbar.types.js +18 -0
- package/dist/toolbar.types.mjs +0 -0
- package/package.json +73 -0
|
@@ -0,0 +1,76 @@
|
|
|
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
|
+
|
|
20
|
+
// src/toolbar.dom.ts
|
|
21
|
+
var toolbar_dom_exports = {};
|
|
22
|
+
__export(toolbar_dom_exports, {
|
|
23
|
+
getElements: () => getElements,
|
|
24
|
+
getFirstEl: () => getFirstEl,
|
|
25
|
+
getGroupId: () => getGroupId,
|
|
26
|
+
getItemId: () => getItemId,
|
|
27
|
+
getLastEl: () => getLastEl,
|
|
28
|
+
getNextEl: () => getNextEl,
|
|
29
|
+
getPrevEl: () => getPrevEl,
|
|
30
|
+
getRootEl: () => getRootEl,
|
|
31
|
+
getRootId: () => getRootId,
|
|
32
|
+
hasFocusableItem: () => hasFocusableItem
|
|
33
|
+
});
|
|
34
|
+
module.exports = __toCommonJS(toolbar_dom_exports);
|
|
35
|
+
var import_dom_query = require("@zag-js/dom-query");
|
|
36
|
+
var import_utils = require("@zag-js/utils");
|
|
37
|
+
var import_toolbar = require("./toolbar.anatomy.js");
|
|
38
|
+
var getRootId = (ctx) => ctx.ids?.root ?? `toolbar:${ctx.id}`;
|
|
39
|
+
var getItemId = (ctx, value) => ctx.ids?.item?.(value) ?? `toolbar:${ctx.id}:item:${value}`;
|
|
40
|
+
var getGroupId = (ctx, value) => ctx.ids?.group?.(value) ?? `toolbar:${ctx.id}:group:${value}`;
|
|
41
|
+
var getRootEl = (ctx) => ctx.query(ctx.selector(import_toolbar.parts.root));
|
|
42
|
+
var getElements = (ctx) => {
|
|
43
|
+
const root = getRootEl(ctx);
|
|
44
|
+
if (!root) return [];
|
|
45
|
+
const els = ctx.queryAll(`${ctx.selector(import_toolbar.parts.item)}, [data-toggle-group-item]`);
|
|
46
|
+
return els.filter((el) => {
|
|
47
|
+
if (el.closest(ctx.selector(import_toolbar.parts.root)) !== root) return false;
|
|
48
|
+
return !el.hasAttribute("data-disabled") || el.hasAttribute("data-focusable-when-disabled");
|
|
49
|
+
});
|
|
50
|
+
};
|
|
51
|
+
var getFirstEl = (ctx) => (0, import_utils.first)(getElements(ctx));
|
|
52
|
+
var getLastEl = (ctx) => (0, import_utils.last)(getElements(ctx));
|
|
53
|
+
var hasFocusableItem = (ctx) => getElements(ctx).some((el) => el.tabIndex === 0);
|
|
54
|
+
var getNextEl = (ctx, loopFocus) => {
|
|
55
|
+
const id = ctx.getActiveElement()?.id;
|
|
56
|
+
const els = getElements(ctx);
|
|
57
|
+
return id ? (0, import_dom_query.nextById)(els, id, loopFocus) : (0, import_utils.first)(els);
|
|
58
|
+
};
|
|
59
|
+
var getPrevEl = (ctx, loopFocus) => {
|
|
60
|
+
const id = ctx.getActiveElement()?.id;
|
|
61
|
+
const els = getElements(ctx);
|
|
62
|
+
return id ? (0, import_dom_query.prevById)(els, id, loopFocus) : (0, import_utils.first)(els);
|
|
63
|
+
};
|
|
64
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
65
|
+
0 && (module.exports = {
|
|
66
|
+
getElements,
|
|
67
|
+
getFirstEl,
|
|
68
|
+
getGroupId,
|
|
69
|
+
getItemId,
|
|
70
|
+
getLastEl,
|
|
71
|
+
getNextEl,
|
|
72
|
+
getPrevEl,
|
|
73
|
+
getRootEl,
|
|
74
|
+
getRootId,
|
|
75
|
+
hasFocusableItem
|
|
76
|
+
});
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
// src/toolbar.dom.ts
|
|
2
|
+
import { nextById, prevById } from "@zag-js/dom-query";
|
|
3
|
+
import { first, last } from "@zag-js/utils";
|
|
4
|
+
import { parts } from "./toolbar.anatomy.mjs";
|
|
5
|
+
var getRootId = (ctx) => ctx.ids?.root ?? `toolbar:${ctx.id}`;
|
|
6
|
+
var getItemId = (ctx, value) => ctx.ids?.item?.(value) ?? `toolbar:${ctx.id}:item:${value}`;
|
|
7
|
+
var getGroupId = (ctx, value) => ctx.ids?.group?.(value) ?? `toolbar:${ctx.id}:group:${value}`;
|
|
8
|
+
var getRootEl = (ctx) => ctx.query(ctx.selector(parts.root));
|
|
9
|
+
var getElements = (ctx) => {
|
|
10
|
+
const root = getRootEl(ctx);
|
|
11
|
+
if (!root) return [];
|
|
12
|
+
const els = ctx.queryAll(`${ctx.selector(parts.item)}, [data-toggle-group-item]`);
|
|
13
|
+
return els.filter((el) => {
|
|
14
|
+
if (el.closest(ctx.selector(parts.root)) !== root) return false;
|
|
15
|
+
return !el.hasAttribute("data-disabled") || el.hasAttribute("data-focusable-when-disabled");
|
|
16
|
+
});
|
|
17
|
+
};
|
|
18
|
+
var getFirstEl = (ctx) => first(getElements(ctx));
|
|
19
|
+
var getLastEl = (ctx) => last(getElements(ctx));
|
|
20
|
+
var hasFocusableItem = (ctx) => getElements(ctx).some((el) => el.tabIndex === 0);
|
|
21
|
+
var getNextEl = (ctx, loopFocus) => {
|
|
22
|
+
const id = ctx.getActiveElement()?.id;
|
|
23
|
+
const els = getElements(ctx);
|
|
24
|
+
return id ? nextById(els, id, loopFocus) : first(els);
|
|
25
|
+
};
|
|
26
|
+
var getPrevEl = (ctx, loopFocus) => {
|
|
27
|
+
const id = ctx.getActiveElement()?.id;
|
|
28
|
+
const els = getElements(ctx);
|
|
29
|
+
return id ? prevById(els, id, loopFocus) : first(els);
|
|
30
|
+
};
|
|
31
|
+
export {
|
|
32
|
+
getElements,
|
|
33
|
+
getFirstEl,
|
|
34
|
+
getGroupId,
|
|
35
|
+
getItemId,
|
|
36
|
+
getLastEl,
|
|
37
|
+
getNextEl,
|
|
38
|
+
getPrevEl,
|
|
39
|
+
getRootEl,
|
|
40
|
+
getRootId,
|
|
41
|
+
hasFocusableItem
|
|
42
|
+
};
|
|
@@ -0,0 +1,190 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __export = (target, all) => {
|
|
9
|
+
for (var name in all)
|
|
10
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
+
};
|
|
12
|
+
var __copyProps = (to, from, except, desc) => {
|
|
13
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
+
for (let key of __getOwnPropNames(from))
|
|
15
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
+
}
|
|
18
|
+
return to;
|
|
19
|
+
};
|
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
+
mod
|
|
27
|
+
));
|
|
28
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
+
|
|
30
|
+
// src/toolbar.machine.ts
|
|
31
|
+
var toolbar_machine_exports = {};
|
|
32
|
+
__export(toolbar_machine_exports, {
|
|
33
|
+
machine: () => machine
|
|
34
|
+
});
|
|
35
|
+
module.exports = __toCommonJS(toolbar_machine_exports);
|
|
36
|
+
var import_core = require("@zag-js/core");
|
|
37
|
+
var import_dom_query = require("@zag-js/dom-query");
|
|
38
|
+
var dom = __toESM(require("./toolbar.dom.js"));
|
|
39
|
+
var { not } = (0, import_core.createGuards)();
|
|
40
|
+
var machine = (0, import_core.createMachine)({
|
|
41
|
+
props({ props }) {
|
|
42
|
+
return {
|
|
43
|
+
orientation: "horizontal",
|
|
44
|
+
loopFocus: true,
|
|
45
|
+
...props
|
|
46
|
+
};
|
|
47
|
+
},
|
|
48
|
+
initialState() {
|
|
49
|
+
return "idle";
|
|
50
|
+
},
|
|
51
|
+
effects: ["trackItemMutations"],
|
|
52
|
+
context({ bindable }) {
|
|
53
|
+
return {
|
|
54
|
+
focusedValue: bindable(() => ({
|
|
55
|
+
defaultValue: null
|
|
56
|
+
})),
|
|
57
|
+
hasInteracted: bindable(() => ({
|
|
58
|
+
defaultValue: false
|
|
59
|
+
})),
|
|
60
|
+
isClickFocus: bindable(() => ({
|
|
61
|
+
defaultValue: false
|
|
62
|
+
}))
|
|
63
|
+
};
|
|
64
|
+
},
|
|
65
|
+
on: {
|
|
66
|
+
"ROOT.MOUSE_DOWN": {
|
|
67
|
+
actions: ["setClickFocus"]
|
|
68
|
+
},
|
|
69
|
+
"ROOT.BLUR": {
|
|
70
|
+
actions: ["clearClickFocus"]
|
|
71
|
+
},
|
|
72
|
+
// A nested composite's own item was focused directly, bypassing ITEM.FOCUS.
|
|
73
|
+
"DESCENDANT.FOCUS": {
|
|
74
|
+
target: "focused",
|
|
75
|
+
actions: ["setHasInteracted"]
|
|
76
|
+
},
|
|
77
|
+
"ITEMS.CHANGE": {
|
|
78
|
+
actions: ["syncHasInteracted"]
|
|
79
|
+
}
|
|
80
|
+
},
|
|
81
|
+
states: {
|
|
82
|
+
// Active only before the first successful focus — the root then permanently cedes its tabindex.
|
|
83
|
+
idle: {
|
|
84
|
+
on: {
|
|
85
|
+
"ROOT.FOCUS": {
|
|
86
|
+
target: "focused",
|
|
87
|
+
guard: not("isClickFocus"),
|
|
88
|
+
actions: ["focusFirstItem", "setHasInteracted", "clearClickFocus"]
|
|
89
|
+
},
|
|
90
|
+
"ITEM.FOCUS": {
|
|
91
|
+
target: "focused",
|
|
92
|
+
actions: ["setFocusedValue", "setHasInteracted"]
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
},
|
|
96
|
+
focused: {
|
|
97
|
+
on: {
|
|
98
|
+
"ROOT.FOCUS": {
|
|
99
|
+
guard: not("isClickFocus"),
|
|
100
|
+
actions: ["focusFirstItem", "clearClickFocus"]
|
|
101
|
+
},
|
|
102
|
+
"ITEM.FOCUS": {
|
|
103
|
+
actions: ["setFocusedValue"]
|
|
104
|
+
},
|
|
105
|
+
"ITEM.FOCUS_NEXT": {
|
|
106
|
+
actions: ["focusNextItem"]
|
|
107
|
+
},
|
|
108
|
+
"ITEM.FOCUS_PREV": {
|
|
109
|
+
actions: ["focusPrevItem"]
|
|
110
|
+
},
|
|
111
|
+
"ITEM.FOCUS_FIRST": {
|
|
112
|
+
actions: ["focusFirstItem"]
|
|
113
|
+
},
|
|
114
|
+
"ITEM.FOCUS_LAST": {
|
|
115
|
+
actions: ["focusLastItem"]
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
},
|
|
120
|
+
implementations: {
|
|
121
|
+
guards: {
|
|
122
|
+
isClickFocus: ({ context }) => context.get("isClickFocus")
|
|
123
|
+
},
|
|
124
|
+
actions: {
|
|
125
|
+
setClickFocus({ context }) {
|
|
126
|
+
context.set("isClickFocus", true);
|
|
127
|
+
},
|
|
128
|
+
clearClickFocus({ context }) {
|
|
129
|
+
context.set("isClickFocus", false);
|
|
130
|
+
},
|
|
131
|
+
setHasInteracted({ context }) {
|
|
132
|
+
context.set("hasInteracted", true);
|
|
133
|
+
},
|
|
134
|
+
syncHasInteracted({ context, scope }) {
|
|
135
|
+
if (!context.get("hasInteracted")) return;
|
|
136
|
+
if (dom.hasFocusableItem(scope)) return;
|
|
137
|
+
context.set("hasInteracted", false);
|
|
138
|
+
context.set("focusedValue", null);
|
|
139
|
+
},
|
|
140
|
+
setFocusedValue({ context, event }) {
|
|
141
|
+
context.set("focusedValue", event.value);
|
|
142
|
+
},
|
|
143
|
+
focusNextItem({ scope, prop }) {
|
|
144
|
+
const before = scope.getActiveElement();
|
|
145
|
+
(0, import_dom_query.raf)(() => {
|
|
146
|
+
if (scope.getActiveElement() !== before) return;
|
|
147
|
+
dom.getNextEl(scope, prop("loopFocus"))?.focus({ preventScroll: true });
|
|
148
|
+
});
|
|
149
|
+
},
|
|
150
|
+
focusPrevItem({ scope, prop }) {
|
|
151
|
+
const before = scope.getActiveElement();
|
|
152
|
+
(0, import_dom_query.raf)(() => {
|
|
153
|
+
if (scope.getActiveElement() !== before) return;
|
|
154
|
+
dom.getPrevEl(scope, prop("loopFocus"))?.focus({ preventScroll: true });
|
|
155
|
+
});
|
|
156
|
+
},
|
|
157
|
+
focusFirstItem({ scope }) {
|
|
158
|
+
const before = scope.getActiveElement();
|
|
159
|
+
(0, import_dom_query.raf)(() => {
|
|
160
|
+
if (scope.getActiveElement() !== before) return;
|
|
161
|
+
dom.getFirstEl(scope)?.focus({ preventScroll: true });
|
|
162
|
+
});
|
|
163
|
+
},
|
|
164
|
+
focusLastItem({ scope }) {
|
|
165
|
+
const before = scope.getActiveElement();
|
|
166
|
+
(0, import_dom_query.raf)(() => {
|
|
167
|
+
if (scope.getActiveElement() !== before) return;
|
|
168
|
+
dom.getLastEl(scope)?.focus({ preventScroll: true });
|
|
169
|
+
});
|
|
170
|
+
}
|
|
171
|
+
},
|
|
172
|
+
effects: {
|
|
173
|
+
trackItemMutations({ scope, send }) {
|
|
174
|
+
const root = dom.getRootEl(scope);
|
|
175
|
+
if (!root) return;
|
|
176
|
+
return (0, import_dom_query.observeChildren)(root, {
|
|
177
|
+
attributes: true,
|
|
178
|
+
attributeFilter: ["disabled", "data-disabled"],
|
|
179
|
+
callback() {
|
|
180
|
+
send({ type: "ITEMS.CHANGE" });
|
|
181
|
+
}
|
|
182
|
+
});
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
});
|
|
187
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
188
|
+
0 && (module.exports = {
|
|
189
|
+
machine
|
|
190
|
+
});
|
|
@@ -0,0 +1,155 @@
|
|
|
1
|
+
// src/toolbar.machine.ts
|
|
2
|
+
import { createGuards, createMachine } from "@zag-js/core";
|
|
3
|
+
import { observeChildren, raf } from "@zag-js/dom-query";
|
|
4
|
+
import * as dom from "./toolbar.dom.mjs";
|
|
5
|
+
var { not } = createGuards();
|
|
6
|
+
var machine = createMachine({
|
|
7
|
+
props({ props }) {
|
|
8
|
+
return {
|
|
9
|
+
orientation: "horizontal",
|
|
10
|
+
loopFocus: true,
|
|
11
|
+
...props
|
|
12
|
+
};
|
|
13
|
+
},
|
|
14
|
+
initialState() {
|
|
15
|
+
return "idle";
|
|
16
|
+
},
|
|
17
|
+
effects: ["trackItemMutations"],
|
|
18
|
+
context({ bindable }) {
|
|
19
|
+
return {
|
|
20
|
+
focusedValue: bindable(() => ({
|
|
21
|
+
defaultValue: null
|
|
22
|
+
})),
|
|
23
|
+
hasInteracted: bindable(() => ({
|
|
24
|
+
defaultValue: false
|
|
25
|
+
})),
|
|
26
|
+
isClickFocus: bindable(() => ({
|
|
27
|
+
defaultValue: false
|
|
28
|
+
}))
|
|
29
|
+
};
|
|
30
|
+
},
|
|
31
|
+
on: {
|
|
32
|
+
"ROOT.MOUSE_DOWN": {
|
|
33
|
+
actions: ["setClickFocus"]
|
|
34
|
+
},
|
|
35
|
+
"ROOT.BLUR": {
|
|
36
|
+
actions: ["clearClickFocus"]
|
|
37
|
+
},
|
|
38
|
+
// A nested composite's own item was focused directly, bypassing ITEM.FOCUS.
|
|
39
|
+
"DESCENDANT.FOCUS": {
|
|
40
|
+
target: "focused",
|
|
41
|
+
actions: ["setHasInteracted"]
|
|
42
|
+
},
|
|
43
|
+
"ITEMS.CHANGE": {
|
|
44
|
+
actions: ["syncHasInteracted"]
|
|
45
|
+
}
|
|
46
|
+
},
|
|
47
|
+
states: {
|
|
48
|
+
// Active only before the first successful focus — the root then permanently cedes its tabindex.
|
|
49
|
+
idle: {
|
|
50
|
+
on: {
|
|
51
|
+
"ROOT.FOCUS": {
|
|
52
|
+
target: "focused",
|
|
53
|
+
guard: not("isClickFocus"),
|
|
54
|
+
actions: ["focusFirstItem", "setHasInteracted", "clearClickFocus"]
|
|
55
|
+
},
|
|
56
|
+
"ITEM.FOCUS": {
|
|
57
|
+
target: "focused",
|
|
58
|
+
actions: ["setFocusedValue", "setHasInteracted"]
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
},
|
|
62
|
+
focused: {
|
|
63
|
+
on: {
|
|
64
|
+
"ROOT.FOCUS": {
|
|
65
|
+
guard: not("isClickFocus"),
|
|
66
|
+
actions: ["focusFirstItem", "clearClickFocus"]
|
|
67
|
+
},
|
|
68
|
+
"ITEM.FOCUS": {
|
|
69
|
+
actions: ["setFocusedValue"]
|
|
70
|
+
},
|
|
71
|
+
"ITEM.FOCUS_NEXT": {
|
|
72
|
+
actions: ["focusNextItem"]
|
|
73
|
+
},
|
|
74
|
+
"ITEM.FOCUS_PREV": {
|
|
75
|
+
actions: ["focusPrevItem"]
|
|
76
|
+
},
|
|
77
|
+
"ITEM.FOCUS_FIRST": {
|
|
78
|
+
actions: ["focusFirstItem"]
|
|
79
|
+
},
|
|
80
|
+
"ITEM.FOCUS_LAST": {
|
|
81
|
+
actions: ["focusLastItem"]
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
},
|
|
86
|
+
implementations: {
|
|
87
|
+
guards: {
|
|
88
|
+
isClickFocus: ({ context }) => context.get("isClickFocus")
|
|
89
|
+
},
|
|
90
|
+
actions: {
|
|
91
|
+
setClickFocus({ context }) {
|
|
92
|
+
context.set("isClickFocus", true);
|
|
93
|
+
},
|
|
94
|
+
clearClickFocus({ context }) {
|
|
95
|
+
context.set("isClickFocus", false);
|
|
96
|
+
},
|
|
97
|
+
setHasInteracted({ context }) {
|
|
98
|
+
context.set("hasInteracted", true);
|
|
99
|
+
},
|
|
100
|
+
syncHasInteracted({ context, scope }) {
|
|
101
|
+
if (!context.get("hasInteracted")) return;
|
|
102
|
+
if (dom.hasFocusableItem(scope)) return;
|
|
103
|
+
context.set("hasInteracted", false);
|
|
104
|
+
context.set("focusedValue", null);
|
|
105
|
+
},
|
|
106
|
+
setFocusedValue({ context, event }) {
|
|
107
|
+
context.set("focusedValue", event.value);
|
|
108
|
+
},
|
|
109
|
+
focusNextItem({ scope, prop }) {
|
|
110
|
+
const before = scope.getActiveElement();
|
|
111
|
+
raf(() => {
|
|
112
|
+
if (scope.getActiveElement() !== before) return;
|
|
113
|
+
dom.getNextEl(scope, prop("loopFocus"))?.focus({ preventScroll: true });
|
|
114
|
+
});
|
|
115
|
+
},
|
|
116
|
+
focusPrevItem({ scope, prop }) {
|
|
117
|
+
const before = scope.getActiveElement();
|
|
118
|
+
raf(() => {
|
|
119
|
+
if (scope.getActiveElement() !== before) return;
|
|
120
|
+
dom.getPrevEl(scope, prop("loopFocus"))?.focus({ preventScroll: true });
|
|
121
|
+
});
|
|
122
|
+
},
|
|
123
|
+
focusFirstItem({ scope }) {
|
|
124
|
+
const before = scope.getActiveElement();
|
|
125
|
+
raf(() => {
|
|
126
|
+
if (scope.getActiveElement() !== before) return;
|
|
127
|
+
dom.getFirstEl(scope)?.focus({ preventScroll: true });
|
|
128
|
+
});
|
|
129
|
+
},
|
|
130
|
+
focusLastItem({ scope }) {
|
|
131
|
+
const before = scope.getActiveElement();
|
|
132
|
+
raf(() => {
|
|
133
|
+
if (scope.getActiveElement() !== before) return;
|
|
134
|
+
dom.getLastEl(scope)?.focus({ preventScroll: true });
|
|
135
|
+
});
|
|
136
|
+
}
|
|
137
|
+
},
|
|
138
|
+
effects: {
|
|
139
|
+
trackItemMutations({ scope, send }) {
|
|
140
|
+
const root = dom.getRootEl(scope);
|
|
141
|
+
if (!root) return;
|
|
142
|
+
return observeChildren(root, {
|
|
143
|
+
attributes: true,
|
|
144
|
+
attributeFilter: ["disabled", "data-disabled"],
|
|
145
|
+
callback() {
|
|
146
|
+
send({ type: "ITEMS.CHANGE" });
|
|
147
|
+
}
|
|
148
|
+
});
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
});
|
|
153
|
+
export {
|
|
154
|
+
machine
|
|
155
|
+
};
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { ItemProps, ToolbarProps } from './toolbar.types.mjs';
|
|
2
|
+
import '@zag-js/core';
|
|
3
|
+
import '@zag-js/types';
|
|
4
|
+
|
|
5
|
+
declare const props: (keyof ToolbarProps)[];
|
|
6
|
+
declare const splitProps: <Props extends Partial<ToolbarProps>>(props: Props) => [Partial<ToolbarProps>, Omit<Props, keyof ToolbarProps>];
|
|
7
|
+
declare const itemProps: (keyof ItemProps)[];
|
|
8
|
+
declare const splitItemProps: <Props extends ItemProps>(props: Props) => [ItemProps, Omit<Props, keyof ItemProps>];
|
|
9
|
+
|
|
10
|
+
export { itemProps, props, splitItemProps, splitProps };
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { ItemProps, ToolbarProps } from './toolbar.types.js';
|
|
2
|
+
import '@zag-js/core';
|
|
3
|
+
import '@zag-js/types';
|
|
4
|
+
|
|
5
|
+
declare const props: (keyof ToolbarProps)[];
|
|
6
|
+
declare const splitProps: <Props extends Partial<ToolbarProps>>(props: Props) => [Partial<ToolbarProps>, Omit<Props, keyof ToolbarProps>];
|
|
7
|
+
declare const itemProps: (keyof ItemProps)[];
|
|
8
|
+
declare const splitItemProps: <Props extends ItemProps>(props: Props) => [ItemProps, Omit<Props, keyof ItemProps>];
|
|
9
|
+
|
|
10
|
+
export { itemProps, props, splitItemProps, splitProps };
|
|
@@ -0,0 +1,49 @@
|
|
|
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
|
+
|
|
20
|
+
// src/toolbar.props.ts
|
|
21
|
+
var toolbar_props_exports = {};
|
|
22
|
+
__export(toolbar_props_exports, {
|
|
23
|
+
itemProps: () => itemProps,
|
|
24
|
+
props: () => props,
|
|
25
|
+
splitItemProps: () => splitItemProps,
|
|
26
|
+
splitProps: () => splitProps
|
|
27
|
+
});
|
|
28
|
+
module.exports = __toCommonJS(toolbar_props_exports);
|
|
29
|
+
var import_types = require("@zag-js/types");
|
|
30
|
+
var import_utils = require("@zag-js/utils");
|
|
31
|
+
var props = (0, import_types.createProps)()([
|
|
32
|
+
"dir",
|
|
33
|
+
"disabled",
|
|
34
|
+
"getRootNode",
|
|
35
|
+
"id",
|
|
36
|
+
"ids",
|
|
37
|
+
"loopFocus",
|
|
38
|
+
"orientation"
|
|
39
|
+
]);
|
|
40
|
+
var splitProps = (0, import_utils.createSplitProps)(props);
|
|
41
|
+
var itemProps = (0, import_types.createProps)()(["value", "disabled", "focusableWhenDisabled"]);
|
|
42
|
+
var splitItemProps = (0, import_utils.createSplitProps)(itemProps);
|
|
43
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
44
|
+
0 && (module.exports = {
|
|
45
|
+
itemProps,
|
|
46
|
+
props,
|
|
47
|
+
splitItemProps,
|
|
48
|
+
splitProps
|
|
49
|
+
});
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
// src/toolbar.props.ts
|
|
2
|
+
import { createProps } from "@zag-js/types";
|
|
3
|
+
import { createSplitProps } from "@zag-js/utils";
|
|
4
|
+
var props = createProps()([
|
|
5
|
+
"dir",
|
|
6
|
+
"disabled",
|
|
7
|
+
"getRootNode",
|
|
8
|
+
"id",
|
|
9
|
+
"ids",
|
|
10
|
+
"loopFocus",
|
|
11
|
+
"orientation"
|
|
12
|
+
]);
|
|
13
|
+
var splitProps = createSplitProps(props);
|
|
14
|
+
var itemProps = createProps()(["value", "disabled", "focusableWhenDisabled"]);
|
|
15
|
+
var splitItemProps = createSplitProps(itemProps);
|
|
16
|
+
export {
|
|
17
|
+
itemProps,
|
|
18
|
+
props,
|
|
19
|
+
splitItemProps,
|
|
20
|
+
splitProps
|
|
21
|
+
};
|