@zag-js/toc 1.37.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/LICENSE +21 -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/toc.anatomy.d.mts +6 -0
- package/dist/toc.anatomy.d.ts +6 -0
- package/dist/toc.anatomy.js +34 -0
- package/dist/toc.anatomy.mjs +8 -0
- package/dist/toc.connect.d.mts +7 -0
- package/dist/toc.connect.d.ts +7 -0
- package/dist/toc.connect.js +139 -0
- package/dist/toc.connect.mjs +104 -0
- package/dist/toc.dom.d.mts +19 -0
- package/dist/toc.dom.d.ts +19 -0
- package/dist/toc.dom.js +66 -0
- package/dist/toc.dom.mjs +31 -0
- package/dist/toc.machine.d.mts +7 -0
- package/dist/toc.machine.d.ts +7 -0
- package/dist/toc.machine.js +219 -0
- package/dist/toc.machine.mjs +184 -0
- package/dist/toc.props.d.mts +10 -0
- package/dist/toc.props.d.ts +10 -0
- package/dist/toc.props.js +55 -0
- package/dist/toc.props.mjs +27 -0
- package/dist/toc.types.d.mts +159 -0
- package/dist/toc.types.d.ts +159 -0
- package/dist/toc.types.js +18 -0
- package/dist/toc.types.mjs +0 -0
- package/package.json +72 -0
|
@@ -0,0 +1,159 @@
|
|
|
1
|
+
import { Machine, EventObject, Service } from '@zag-js/core';
|
|
2
|
+
import { PropTypes, RequiredBy, DirectionProperty, CommonProperties, Rect } from '@zag-js/types';
|
|
3
|
+
|
|
4
|
+
interface TocItem {
|
|
5
|
+
/**
|
|
6
|
+
* The slug/id of the heading element in the document
|
|
7
|
+
*/
|
|
8
|
+
value: string;
|
|
9
|
+
/**
|
|
10
|
+
* The nesting depth (e.g., 2 for h2, 3 for h3)
|
|
11
|
+
*/
|
|
12
|
+
depth: number;
|
|
13
|
+
}
|
|
14
|
+
interface ActiveChangeDetails {
|
|
15
|
+
/**
|
|
16
|
+
* All currently active (visible) heading ids
|
|
17
|
+
*/
|
|
18
|
+
activeIds: string[];
|
|
19
|
+
/**
|
|
20
|
+
* The active (visible) TOC items
|
|
21
|
+
*/
|
|
22
|
+
activeItems: TocItem[];
|
|
23
|
+
}
|
|
24
|
+
type ElementIds = Partial<{
|
|
25
|
+
root: string;
|
|
26
|
+
title: string;
|
|
27
|
+
list: string;
|
|
28
|
+
item: (value: string) => string;
|
|
29
|
+
link: (value: string) => string;
|
|
30
|
+
indicator: string;
|
|
31
|
+
}>;
|
|
32
|
+
interface TocProps extends DirectionProperty, CommonProperties {
|
|
33
|
+
/**
|
|
34
|
+
* The ids of the elements in the TOC. Useful for composition.
|
|
35
|
+
*/
|
|
36
|
+
ids?: ElementIds | undefined;
|
|
37
|
+
/**
|
|
38
|
+
* The TOC items with `value` (slug/id) and `depth` (heading level).
|
|
39
|
+
*/
|
|
40
|
+
items: TocItem[];
|
|
41
|
+
/**
|
|
42
|
+
* The root margin for the IntersectionObserver.
|
|
43
|
+
* Controls the effective viewport area for determining active headings.
|
|
44
|
+
*
|
|
45
|
+
* @default "-20px 0px -40% 0px"
|
|
46
|
+
*/
|
|
47
|
+
rootMargin?: string | undefined;
|
|
48
|
+
/**
|
|
49
|
+
* The IntersectionObserver threshold. A value of `0` means the heading is
|
|
50
|
+
* active as soon as even one pixel is visible within the root margin area.
|
|
51
|
+
* @default 0
|
|
52
|
+
*/
|
|
53
|
+
threshold?: number | number[] | undefined;
|
|
54
|
+
/**
|
|
55
|
+
* Function that returns the scroll container element to observe within.
|
|
56
|
+
* Defaults to the document/viewport.
|
|
57
|
+
*/
|
|
58
|
+
getScrollEl?: (() => HTMLElement | null) | undefined;
|
|
59
|
+
/**
|
|
60
|
+
* Whether to auto-scroll the TOC container so the first active item
|
|
61
|
+
* is visible when active headings change.
|
|
62
|
+
* @default true
|
|
63
|
+
*/
|
|
64
|
+
autoScroll?: boolean | undefined;
|
|
65
|
+
/**
|
|
66
|
+
* The scroll behavior for auto-scrolling the TOC container.
|
|
67
|
+
* @default "smooth"
|
|
68
|
+
*/
|
|
69
|
+
scrollBehavior?: ScrollBehavior | undefined;
|
|
70
|
+
/**
|
|
71
|
+
* Callback when the active (visible) headings change.
|
|
72
|
+
*/
|
|
73
|
+
onActiveChange?: ((details: ActiveChangeDetails) => void) | undefined;
|
|
74
|
+
/**
|
|
75
|
+
* The controlled active heading ids.
|
|
76
|
+
*/
|
|
77
|
+
activeIds?: string[] | undefined;
|
|
78
|
+
/**
|
|
79
|
+
* The default active heading ids when rendered.
|
|
80
|
+
* Use when you don't need to control the active headings.
|
|
81
|
+
*/
|
|
82
|
+
defaultActiveIds?: string[] | undefined;
|
|
83
|
+
}
|
|
84
|
+
type PropsWithDefault = "rootMargin" | "threshold" | "autoScroll" | "scrollBehavior" | "items";
|
|
85
|
+
interface TocSchema {
|
|
86
|
+
state: "idle";
|
|
87
|
+
props: RequiredBy<TocProps, PropsWithDefault>;
|
|
88
|
+
context: {
|
|
89
|
+
activeIds: string[];
|
|
90
|
+
indicatorRect: Rect | null;
|
|
91
|
+
};
|
|
92
|
+
refs: {
|
|
93
|
+
visibilityMap: Map<string, boolean>;
|
|
94
|
+
indicatorCleanup: VoidFunction | null;
|
|
95
|
+
};
|
|
96
|
+
computed: {
|
|
97
|
+
activeItems: TocItem[];
|
|
98
|
+
};
|
|
99
|
+
action: string;
|
|
100
|
+
guard: string;
|
|
101
|
+
effect: string;
|
|
102
|
+
event: EventObject;
|
|
103
|
+
}
|
|
104
|
+
type TocService = Service<TocSchema>;
|
|
105
|
+
type TocMachine = Machine<TocSchema>;
|
|
106
|
+
interface ItemProps {
|
|
107
|
+
/**
|
|
108
|
+
* The TOC item
|
|
109
|
+
*/
|
|
110
|
+
item: TocItem;
|
|
111
|
+
}
|
|
112
|
+
interface ItemState {
|
|
113
|
+
/**
|
|
114
|
+
* Whether this heading is currently visible/active
|
|
115
|
+
*/
|
|
116
|
+
active: boolean;
|
|
117
|
+
/**
|
|
118
|
+
* Whether this is the first active heading
|
|
119
|
+
*/
|
|
120
|
+
first: boolean;
|
|
121
|
+
/**
|
|
122
|
+
* Whether this is the last active heading
|
|
123
|
+
*/
|
|
124
|
+
last: boolean;
|
|
125
|
+
/**
|
|
126
|
+
* The depth of this heading (for indentation)
|
|
127
|
+
*/
|
|
128
|
+
depth: number;
|
|
129
|
+
}
|
|
130
|
+
interface TocApi<T extends PropTypes = PropTypes> {
|
|
131
|
+
/**
|
|
132
|
+
* All currently active (visible) heading ids
|
|
133
|
+
*/
|
|
134
|
+
activeIds: string[];
|
|
135
|
+
/**
|
|
136
|
+
* The active (visible) TOC items
|
|
137
|
+
*/
|
|
138
|
+
activeItems: TocItem[];
|
|
139
|
+
/**
|
|
140
|
+
* The resolved items list
|
|
141
|
+
*/
|
|
142
|
+
items: TocItem[];
|
|
143
|
+
/**
|
|
144
|
+
* Manually set the active heading ids
|
|
145
|
+
*/
|
|
146
|
+
setActiveIds(value: string[]): void;
|
|
147
|
+
/**
|
|
148
|
+
* Returns the state of a TOC item
|
|
149
|
+
*/
|
|
150
|
+
getItemState(props: ItemProps): ItemState;
|
|
151
|
+
getRootProps(): T["element"];
|
|
152
|
+
getTitleProps(): T["element"];
|
|
153
|
+
getListProps(): T["element"];
|
|
154
|
+
getItemProps(props: ItemProps): T["element"];
|
|
155
|
+
getLinkProps(props: ItemProps): T["element"];
|
|
156
|
+
getIndicatorProps(): T["element"];
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
export type { ActiveChangeDetails, ElementIds, ItemProps, ItemState, TocApi, TocItem, TocMachine, TocProps, TocSchema, TocService };
|
|
@@ -0,0 +1,18 @@
|
|
|
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 __copyProps = (to, from, except, desc) => {
|
|
7
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
8
|
+
for (let key of __getOwnPropNames(from))
|
|
9
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
10
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
11
|
+
}
|
|
12
|
+
return to;
|
|
13
|
+
};
|
|
14
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
15
|
+
|
|
16
|
+
// src/toc.types.ts
|
|
17
|
+
var toc_types_exports = {};
|
|
18
|
+
module.exports = __toCommonJS(toc_types_exports);
|
|
File without changes
|
package/package.json
ADDED
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@zag-js/toc",
|
|
3
|
+
"version": "1.37.0",
|
|
4
|
+
"description": "Core logic for the table of contents widget implemented as a state machine",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"js",
|
|
7
|
+
"machine",
|
|
8
|
+
"xstate",
|
|
9
|
+
"statechart",
|
|
10
|
+
"component",
|
|
11
|
+
"chakra-ui",
|
|
12
|
+
"toc",
|
|
13
|
+
"table-of-contents",
|
|
14
|
+
"scroll-spy"
|
|
15
|
+
],
|
|
16
|
+
"author": "Segun Adebayo <sage@adebayosegun.com>",
|
|
17
|
+
"homepage": "https://github.com/chakra-ui/zag#readme",
|
|
18
|
+
"license": "MIT",
|
|
19
|
+
"repository": "https://github.com/chakra-ui/zag/tree/main/packages/toc",
|
|
20
|
+
"sideEffects": false,
|
|
21
|
+
"files": [
|
|
22
|
+
"dist"
|
|
23
|
+
],
|
|
24
|
+
"publishConfig": {
|
|
25
|
+
"access": "public"
|
|
26
|
+
},
|
|
27
|
+
"bugs": {
|
|
28
|
+
"url": "https://github.com/chakra-ui/zag/issues"
|
|
29
|
+
},
|
|
30
|
+
"dependencies": {
|
|
31
|
+
"@zag-js/anatomy": "1.37.0",
|
|
32
|
+
"@zag-js/dom-query": "1.37.0",
|
|
33
|
+
"@zag-js/utils": "1.37.0",
|
|
34
|
+
"@zag-js/core": "1.37.0",
|
|
35
|
+
"@zag-js/types": "1.37.0"
|
|
36
|
+
},
|
|
37
|
+
"devDependencies": {
|
|
38
|
+
"clean-package": "2.2.0"
|
|
39
|
+
},
|
|
40
|
+
"clean-package": "./clean-package.config.json",
|
|
41
|
+
"main": "dist/index.js",
|
|
42
|
+
"module": "dist/index.mjs",
|
|
43
|
+
"types": "dist/index.d.ts",
|
|
44
|
+
"exports": {
|
|
45
|
+
".": {
|
|
46
|
+
"import": {
|
|
47
|
+
"types": "./dist/index.d.mts",
|
|
48
|
+
"default": "./dist/index.mjs"
|
|
49
|
+
},
|
|
50
|
+
"require": {
|
|
51
|
+
"types": "./dist/index.d.ts",
|
|
52
|
+
"default": "./dist/index.js"
|
|
53
|
+
}
|
|
54
|
+
},
|
|
55
|
+
"./anatomy": {
|
|
56
|
+
"import": {
|
|
57
|
+
"types": "./dist/toc.anatomy.d.mts",
|
|
58
|
+
"default": "./dist/toc.anatomy.mjs"
|
|
59
|
+
},
|
|
60
|
+
"require": {
|
|
61
|
+
"types": "./dist/toc.anatomy.d.ts",
|
|
62
|
+
"default": "./dist/toc.anatomy.js"
|
|
63
|
+
}
|
|
64
|
+
},
|
|
65
|
+
"./package.json": "./package.json"
|
|
66
|
+
},
|
|
67
|
+
"scripts": {
|
|
68
|
+
"build": "tsup",
|
|
69
|
+
"lint": "eslint src",
|
|
70
|
+
"typecheck": "tsc --noEmit"
|
|
71
|
+
}
|
|
72
|
+
}
|