@zag-js/steps 1.34.1 → 1.35.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/dist/index.js CHANGED
@@ -1,350 +1,39 @@
1
- 'use strict';
2
-
3
- var anatomy$1 = require('@zag-js/anatomy');
4
- var domQuery = require('@zag-js/dom-query');
5
- var utils = require('@zag-js/utils');
6
- var core = require('@zag-js/core');
7
- var types = require('@zag-js/types');
8
-
9
- // src/steps.anatomy.ts
10
- var anatomy = anatomy$1.createAnatomy("steps").parts(
11
- "root",
12
- "list",
13
- "item",
14
- "trigger",
15
- "indicator",
16
- "separator",
17
- "content",
18
- "nextTrigger",
19
- "prevTrigger",
20
- "progress"
21
- );
22
- var parts = anatomy.build();
23
-
24
- // src/steps.dom.ts
25
- var getRootId = (ctx) => ctx.ids?.root ?? `steps:${ctx.id}`;
26
- var getListId = (ctx) => ctx.ids?.list ?? `steps:${ctx.id}:list`;
27
- var getTriggerId = (ctx, index) => ctx.ids?.triggerId?.(index) ?? `steps:${ctx.id}:trigger:${index}`;
28
- var getContentId = (ctx, index) => ctx.ids?.contentId?.(index) ?? `steps:${ctx.id}:content:${index}`;
29
-
30
- // src/steps.connect.ts
31
- function connect(service, normalize) {
32
- const { context, send, computed, prop, scope } = service;
33
- const step = context.get("step");
34
- const count = prop("count");
35
- const percent = computed("percent");
36
- const hasNextStep = computed("hasNextStep");
37
- const hasPrevStep = computed("hasPrevStep");
38
- const isStepValid = (index) => {
39
- return prop("isStepValid")?.(index) ?? true;
40
- };
41
- const isStepSkippable = (index) => {
42
- return prop("isStepSkippable")?.(index) ?? false;
43
- };
44
- const getItemState = (props2) => ({
45
- triggerId: getTriggerId(scope, props2.index),
46
- contentId: getContentId(scope, props2.index),
47
- current: props2.index === step,
48
- completed: props2.index < step,
49
- incomplete: props2.index > step,
50
- index: props2.index,
51
- first: props2.index === 0,
52
- last: props2.index === count - 1,
53
- skippable: isStepSkippable(props2.index),
54
- isValid: () => isStepValid(props2.index)
55
- });
56
- const goToNextStep = () => {
57
- send({ type: "STEP.NEXT", src: "next.trigger.click" });
58
- };
59
- const goToPrevStep = () => {
60
- send({ type: "STEP.PREV", src: "prev.trigger.click" });
61
- };
62
- const resetStep = () => {
63
- send({ type: "STEP.RESET", src: "reset.trigger.click" });
64
- };
65
- const setStep = (value) => {
66
- send({ type: "STEP.SET", value, src: "api.setValue" });
67
- };
68
- return {
69
- value: step,
70
- count,
71
- percent,
72
- hasNextStep,
73
- hasPrevStep,
74
- isCompleted: computed("completed"),
75
- isStepValid,
76
- isStepSkippable,
77
- goToNextStep,
78
- goToPrevStep,
79
- resetStep,
80
- getItemState,
81
- setStep,
82
- getRootProps() {
83
- return normalize.element({
84
- ...parts.root.attrs,
85
- id: getRootId(scope),
86
- dir: prop("dir"),
87
- "data-orientation": prop("orientation"),
88
- style: {
89
- "--percent": `${percent}%`
90
- }
91
- });
92
- },
93
- getListProps() {
94
- const arr = utils.fromLength(count);
95
- const triggerIds = arr.map((_, index) => getTriggerId(scope, index));
96
- return normalize.element({
97
- ...parts.list.attrs,
98
- dir: prop("dir"),
99
- id: getListId(scope),
100
- role: "tablist",
101
- "aria-owns": triggerIds.join(" "),
102
- "aria-orientation": prop("orientation"),
103
- "data-orientation": prop("orientation")
104
- });
105
- },
106
- getItemProps(props2) {
107
- const itemState = getItemState(props2);
108
- return normalize.element({
109
- ...parts.item.attrs,
110
- dir: prop("dir"),
111
- "aria-current": itemState.current ? "step" : void 0,
112
- "data-orientation": prop("orientation"),
113
- "data-skippable": domQuery.dataAttr(itemState.skippable)
114
- });
115
- },
116
- getTriggerProps(props2) {
117
- const itemState = getItemState(props2);
118
- return normalize.button({
119
- ...parts.trigger.attrs,
120
- id: itemState.triggerId,
121
- role: "tab",
122
- dir: prop("dir"),
123
- tabIndex: !prop("linear") || itemState.current ? 0 : -1,
124
- "aria-selected": itemState.current,
125
- "aria-controls": itemState.contentId,
126
- "data-state": itemState.current ? "open" : "closed",
127
- "data-orientation": prop("orientation"),
128
- "data-complete": domQuery.dataAttr(itemState.completed),
129
- "data-current": domQuery.dataAttr(itemState.current),
130
- "data-incomplete": domQuery.dataAttr(itemState.incomplete),
131
- onClick(event) {
132
- if (event.defaultPrevented) return;
133
- if (prop("linear")) return;
134
- send({ type: "STEP.SET", value: props2.index, src: "trigger.click" });
135
- }
136
- });
137
- },
138
- getContentProps(props2) {
139
- const itemState = getItemState(props2);
140
- return normalize.element({
141
- ...parts.content.attrs,
142
- dir: prop("dir"),
143
- id: itemState.contentId,
144
- role: "tabpanel",
145
- tabIndex: 0,
146
- hidden: !itemState.current,
147
- "data-state": itemState.current ? "open" : "closed",
148
- "data-orientation": prop("orientation"),
149
- "aria-labelledby": itemState.triggerId
150
- });
151
- },
152
- getIndicatorProps(props2) {
153
- const itemState = getItemState(props2);
154
- return normalize.element({
155
- ...parts.indicator.attrs,
156
- dir: prop("dir"),
157
- "aria-hidden": true,
158
- "data-complete": domQuery.dataAttr(itemState.completed),
159
- "data-current": domQuery.dataAttr(itemState.current),
160
- "data-incomplete": domQuery.dataAttr(itemState.incomplete)
161
- });
162
- },
163
- getSeparatorProps(props2) {
164
- const itemState = getItemState(props2);
165
- return normalize.element({
166
- ...parts.separator.attrs,
167
- dir: prop("dir"),
168
- "data-orientation": prop("orientation"),
169
- "data-complete": domQuery.dataAttr(itemState.completed),
170
- "data-current": domQuery.dataAttr(itemState.current),
171
- "data-incomplete": domQuery.dataAttr(itemState.incomplete)
172
- });
173
- },
174
- getNextTriggerProps() {
175
- return normalize.button({
176
- ...parts.nextTrigger.attrs,
177
- dir: prop("dir"),
178
- type: "button",
179
- disabled: !hasNextStep,
180
- onClick(event) {
181
- if (event.defaultPrevented) return;
182
- goToNextStep();
183
- }
184
- });
185
- },
186
- getPrevTriggerProps() {
187
- return normalize.button({
188
- dir: prop("dir"),
189
- ...parts.prevTrigger.attrs,
190
- type: "button",
191
- disabled: !hasPrevStep,
192
- onClick(event) {
193
- if (event.defaultPrevented) return;
194
- goToPrevStep();
195
- }
196
- });
197
- },
198
- getProgressProps() {
199
- return normalize.element({
200
- dir: prop("dir"),
201
- ...parts.progress.attrs,
202
- role: "progressbar",
203
- "aria-valuenow": percent,
204
- "aria-valuemin": 0,
205
- "aria-valuemax": 100,
206
- "aria-valuetext": `${percent}% complete`,
207
- "data-complete": domQuery.dataAttr(percent === 100)
208
- });
209
- }
210
- };
211
- }
212
- var machine = core.createMachine({
213
- props({ props: props2 }) {
214
- return {
215
- defaultStep: 0,
216
- count: 1,
217
- linear: false,
218
- orientation: "horizontal",
219
- ...props2
220
- };
221
- },
222
- context({ prop, bindable }) {
223
- return {
224
- step: bindable(() => ({
225
- defaultValue: prop("defaultStep"),
226
- value: prop("step"),
227
- onChange(value) {
228
- prop("onStepChange")?.({ step: value });
229
- const completed = value == prop("count");
230
- if (completed) prop("onStepComplete")?.();
231
- }
232
- }))
233
- };
234
- },
235
- computed: {
236
- percent: core.memo(
237
- ({ context, prop }) => [context.get("step"), prop("count")],
238
- ([step, count]) => step / count * 100
239
- ),
240
- hasNextStep: ({ context, prop }) => context.get("step") < prop("count"),
241
- hasPrevStep: ({ context }) => context.get("step") > 0,
242
- completed: ({ context, prop }) => context.get("step") === prop("count")
243
- },
244
- initialState() {
245
- return "idle";
246
- },
247
- entry: ["validateStepIndex"],
248
- states: {
249
- idle: {
250
- on: {
251
- "STEP.SET": [
252
- {
253
- guard: "isValidStepNavigation",
254
- actions: ["setStep"]
255
- },
256
- {
257
- actions: ["invokeOnStepInvalid"]
258
- }
259
- ],
260
- "STEP.NEXT": [
261
- {
262
- guard: "isCurrentStepValid",
263
- actions: ["goToNextStep"]
264
- },
265
- {
266
- actions: ["invokeOnStepInvalid"]
267
- }
268
- ],
269
- "STEP.PREV": {
270
- actions: ["goToPrevStep"]
271
- },
272
- "STEP.RESET": {
273
- actions: ["resetStep"]
274
- }
275
- }
276
- }
277
- },
278
- implementations: {
279
- guards: {
280
- isCurrentStepValid({ context, prop }) {
281
- const current = context.get("step");
282
- if (prop("isStepSkippable")?.(current)) return true;
283
- const isStepValid = prop("isStepValid");
284
- if (!isStepValid) return true;
285
- return isStepValid(current);
286
- },
287
- isValidStepNavigation({ context, event, prop }) {
288
- const current = context.get("step");
289
- if (event.value <= current) return true;
290
- if (prop("isStepSkippable")?.(current)) return true;
291
- const isStepValid = prop("isStepValid");
292
- if (!isStepValid) return true;
293
- return isStepValid(current);
294
- }
295
- },
296
- actions: {
297
- goToNextStep({ context, prop }) {
298
- const count = prop("count");
299
- context.set("step", Math.min(context.get("step") + 1, count));
300
- },
301
- goToPrevStep({ context }) {
302
- context.set("step", Math.max(context.get("step") - 1, 0));
303
- },
304
- resetStep({ context }) {
305
- context.set("step", 0);
306
- },
307
- setStep({ context, event }) {
308
- context.set("step", event.value);
309
- },
310
- validateStepIndex({ context, prop }) {
311
- validateStepIndex(prop("count"), context.get("step"));
312
- },
313
- invokeOnStepInvalid({ context, event, prop }) {
314
- prop("onStepInvalid")?.({
315
- step: context.get("step"),
316
- action: event.type === "STEP.NEXT" ? "next" : "set",
317
- targetStep: event.value
318
- });
319
- }
320
- }
321
- }
322
- });
323
- var validateStepIndex = (count, step) => {
324
- if (!utils.isValueWithinRange(step, 0, count)) {
325
- throw new RangeError(`[zag-js/steps] step index ${step} is out of bounds`);
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 });
326
15
  }
16
+ return to;
327
17
  };
328
- var props = types.createProps()([
329
- "count",
330
- "defaultStep",
331
- "dir",
332
- "getRootNode",
333
- "id",
334
- "ids",
335
- "isStepSkippable",
336
- "isStepValid",
337
- "linear",
338
- "onStepChange",
339
- "onStepComplete",
340
- "onStepInvalid",
341
- "orientation",
342
- "step"
343
- ]);
344
- var splitProps = utils.createSplitProps(props);
18
+ var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
19
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
345
20
 
346
- exports.anatomy = anatomy;
347
- exports.connect = connect;
348
- exports.machine = machine;
349
- exports.props = props;
350
- exports.splitProps = splitProps;
21
+ // src/index.ts
22
+ var index_exports = {};
23
+ __export(index_exports, {
24
+ anatomy: () => import_steps.anatomy,
25
+ connect: () => import_steps2.connect,
26
+ machine: () => import_steps3.machine
27
+ });
28
+ module.exports = __toCommonJS(index_exports);
29
+ var import_steps = require("./steps.anatomy.cjs");
30
+ var import_steps2 = require("./steps.connect.cjs");
31
+ var import_steps3 = require("./steps.machine.cjs");
32
+ __reExport(index_exports, require("./steps.props.cjs"), module.exports);
33
+ // Annotate the CommonJS export names for ESM import in node:
34
+ 0 && (module.exports = {
35
+ anatomy,
36
+ connect,
37
+ machine,
38
+ ...require("./steps.props.cjs")
39
+ });