@destyler/tabs 0.2.6 → 0.2.9
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.d.mts +9 -4
- package/dist/index.mjs +19 -8
- package/package.json +7 -7
package/dist/index.d.mts
CHANGED
|
@@ -42,9 +42,14 @@ interface PublicContext extends DirectionProperty, CommonProperties {
|
|
|
42
42
|
*/
|
|
43
43
|
loopFocus: boolean;
|
|
44
44
|
/**
|
|
45
|
-
* The selected tab id
|
|
45
|
+
* The controlled selected tab id
|
|
46
46
|
*/
|
|
47
|
-
value
|
|
47
|
+
value?: string | null | undefined;
|
|
48
|
+
/**
|
|
49
|
+
* The initial selected tab id when it is not controlled.
|
|
50
|
+
* Prefer this over seeding with `value` for uncontrolled usage.
|
|
51
|
+
*/
|
|
52
|
+
defaultValue?: string | null | undefined;
|
|
48
53
|
/**
|
|
49
54
|
* The orientation of the tabs. Can be `horizontal` or `vertical`
|
|
50
55
|
* - `horizontal`: only left and right arrow key navigation will work.
|
|
@@ -210,8 +215,8 @@ declare function connect<T extends PropTypes>(state: State, send: Send, normaliz
|
|
|
210
215
|
declare function machine(userContext: UserDefinedContext): _destyler_xstate0.Machine<MachineContext, MachineState, _destyler_xstate0.AnyEventObject>;
|
|
211
216
|
//#endregion
|
|
212
217
|
//#region src/props.d.ts
|
|
213
|
-
declare const props: ("
|
|
214
|
-
declare const splitProps: <Props extends Partial<UserDefinedContext>>(props: Props) => [Partial<UserDefinedContext>, Omit<Props, "
|
|
218
|
+
declare const props: ("value" | "ids" | "translations" | "loopFocus" | "defaultValue" | "orientation" | "activationMode" | "onValueChange" | "onFocusChange" | "composite" | "deselectable" | "navigate" | "dir" | "id" | "getRootNode")[];
|
|
219
|
+
declare const splitProps: <Props extends Partial<UserDefinedContext>>(props: Props) => [Partial<UserDefinedContext>, Omit<Props, "value" | "ids" | "translations" | "loopFocus" | "defaultValue" | "orientation" | "activationMode" | "onValueChange" | "onFocusChange" | "composite" | "deselectable" | "navigate" | "dir" | "id" | "getRootNode">];
|
|
215
220
|
declare const triggerProps: (keyof TriggerProps)[];
|
|
216
221
|
declare const splitTriggerProps: <Props extends TriggerProps>(props: Props) => [TriggerProps, Omit<Props, keyof TriggerProps>];
|
|
217
222
|
declare const contentProps: "value"[];
|
package/dist/index.mjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { createAnatomy } from "@destyler/anatomy";
|
|
2
2
|
import { clickIfLink, createScope, dataAttr, getEventKey, getFocusables, isAnchorElement, isComposingEvent, isSafari, isSelfTarget, itemById, nextById, nextTick, prevById, queryAll, raf } from "@destyler/dom";
|
|
3
|
-
import { compact, createSplitProps, first, isEqual, last } from "@destyler/utils";
|
|
3
|
+
import { compact, createSplitProps, first, isControlled, isEqual, isPropUserProvided, last, resolveControllableProp, withControllableProvided } from "@destyler/utils";
|
|
4
4
|
import { trackElementRect } from "@destyler/element-rect";
|
|
5
5
|
import { createMachine, guards } from "@destyler/xstate";
|
|
6
6
|
import { createProps } from "@destyler/types";
|
|
@@ -274,9 +274,9 @@ function connect(state, send, normalize) {
|
|
|
274
274
|
//#region src/machine.ts
|
|
275
275
|
const { not } = guards;
|
|
276
276
|
const invoke = {
|
|
277
|
-
change: (ctx) => {
|
|
278
|
-
if (
|
|
279
|
-
ctx.onValueChange?.({ value
|
|
277
|
+
change: (ctx, value) => {
|
|
278
|
+
if (value == null) return;
|
|
279
|
+
ctx.onValueChange?.({ value });
|
|
280
280
|
},
|
|
281
281
|
focusChange: (ctx) => {
|
|
282
282
|
if (ctx.focusedValue == null) return;
|
|
@@ -286,8 +286,12 @@ const invoke = {
|
|
|
286
286
|
const set = {
|
|
287
287
|
value: (ctx, value) => {
|
|
288
288
|
if (isEqual(value, ctx.value)) return;
|
|
289
|
+
if (isControlled(ctx, "value")) {
|
|
290
|
+
invoke.change(ctx, value);
|
|
291
|
+
return;
|
|
292
|
+
}
|
|
289
293
|
ctx.value = value;
|
|
290
|
-
invoke.change(ctx);
|
|
294
|
+
invoke.change(ctx, value);
|
|
291
295
|
},
|
|
292
296
|
focusedValue: (ctx, value) => {
|
|
293
297
|
if (isEqual(value, ctx.focusedValue)) return;
|
|
@@ -296,21 +300,27 @@ const set = {
|
|
|
296
300
|
}
|
|
297
301
|
};
|
|
298
302
|
function machine(userContext) {
|
|
299
|
-
const ctx = compact(userContext);
|
|
303
|
+
const ctx = compact(withControllableProvided(userContext, ["value"]));
|
|
304
|
+
const { initial: initialValue } = resolveControllableProp({
|
|
305
|
+
value: ctx.value,
|
|
306
|
+
defaultValue: ctx.defaultValue,
|
|
307
|
+
valueProvided: isPropUserProvided(ctx, "value"),
|
|
308
|
+
fallback: null
|
|
309
|
+
});
|
|
300
310
|
return createMachine({
|
|
301
311
|
initial: "idle",
|
|
302
312
|
context: {
|
|
303
313
|
dir: "ltr",
|
|
304
314
|
orientation: "horizontal",
|
|
305
315
|
activationMode: "automatic",
|
|
306
|
-
value: null,
|
|
307
316
|
loopFocus: true,
|
|
308
317
|
composite: true,
|
|
309
318
|
navigate(details) {
|
|
310
319
|
clickIfLink(details.node);
|
|
311
320
|
},
|
|
312
321
|
...ctx,
|
|
313
|
-
|
|
322
|
+
value: initialValue,
|
|
323
|
+
focusedValue: initialValue ?? null,
|
|
314
324
|
ssr: true,
|
|
315
325
|
indicatorState: {
|
|
316
326
|
rendered: false,
|
|
@@ -506,6 +516,7 @@ function machine(userContext) {
|
|
|
506
516
|
const props = createProps()([
|
|
507
517
|
"activationMode",
|
|
508
518
|
"composite",
|
|
519
|
+
"defaultValue",
|
|
509
520
|
"deselectable",
|
|
510
521
|
"dir",
|
|
511
522
|
"getRootNode",
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@destyler/tabs",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.2.
|
|
4
|
+
"version": "0.2.9",
|
|
5
5
|
"description": "A set of layered sections of content—known as tab panels—that are displayed one at a time.",
|
|
6
6
|
"author": "Elone Hoo <elonehoo@gmail.com>",
|
|
7
7
|
"license": "MIT",
|
|
@@ -22,12 +22,12 @@
|
|
|
22
22
|
"dist"
|
|
23
23
|
],
|
|
24
24
|
"dependencies": {
|
|
25
|
-
"@destyler/anatomy": "0.2.
|
|
26
|
-
"@destyler/dom": "0.2.
|
|
27
|
-
"@destyler/
|
|
28
|
-
"@destyler/
|
|
29
|
-
"@destyler/utils": "0.2.
|
|
30
|
-
"@destyler/xstate": "0.2.
|
|
25
|
+
"@destyler/anatomy": "0.2.9",
|
|
26
|
+
"@destyler/dom": "0.2.9",
|
|
27
|
+
"@destyler/types": "0.2.9",
|
|
28
|
+
"@destyler/element-rect": "0.2.9",
|
|
29
|
+
"@destyler/utils": "0.2.9",
|
|
30
|
+
"@destyler/xstate": "0.2.9"
|
|
31
31
|
},
|
|
32
32
|
"publishConfig": {
|
|
33
33
|
"access": "public"
|