@writedocs/generator 0.10.2 → 0.10.3
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/package.json +1 -1
- package/src/layout/components/TopBar.astro +60 -11
- package/src/layout/styles/dropdown.css +104 -0
- package/src/lib/config-schema.js +13 -2
- package/src/lib/config-schema.ts +19 -2
- package/src/lib/config.ts +35 -19
- package/src/lib/json-schema-descriptions.js +1 -1
- package/src/lib/selector-placement.js +14 -6
- package/src/scripts/dropdowns.ts +85 -8
- package/src/scripts/tabs-strip.ts +23 -0
- package/writedocs.schema.json +10 -10
package/package.json
CHANGED
|
@@ -249,17 +249,66 @@ const tabRows = tabSelectors.length > 0 ? tabSelectors : globalDropdowns.length
|
|
|
249
249
|
</button>
|
|
250
250
|
<div class="wd-dropdown-menu">
|
|
251
251
|
<div class="wd-dropdown-menu-panel">
|
|
252
|
-
{opt.dropdown.map((d) =>
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
252
|
+
{opt.dropdown.map((d) =>
|
|
253
|
+
d.submenu ? (
|
|
254
|
+
// An entry holding dropdowns of its own: they open in
|
|
255
|
+
// a flyout beside it, on hover, or on a click on the
|
|
256
|
+
// arrow - or on the entry itself when it has no page
|
|
257
|
+
// of its own to open (src/scripts/dropdowns.ts).
|
|
258
|
+
<div class={`wd-submenu ${d.active ? 'wd-submenu-active' : ''}`}>
|
|
259
|
+
<div class="wd-submenu-row">
|
|
260
|
+
{d.pageHref ? (
|
|
261
|
+
<a href={d.pageHref} class={`wd-submenu-entry ${d.active ? 'active' : ''}`} aria-current={d.active ? 'true' : undefined}>
|
|
262
|
+
<AppIcon icon={d.icon} class="wd-tab-icon" />
|
|
263
|
+
<span class="wd-submenu-label">{d.label}</span>
|
|
264
|
+
</a>
|
|
265
|
+
) : null}
|
|
266
|
+
<button
|
|
267
|
+
type="button"
|
|
268
|
+
class={`wd-submenu-toggle ${d.pageHref ? 'wd-submenu-arrow' : `wd-submenu-entry ${d.active ? 'active' : ''}`}`}
|
|
269
|
+
aria-expanded="false"
|
|
270
|
+
aria-label={d.pageHref ? `${d.label} - more` : undefined}
|
|
271
|
+
>
|
|
272
|
+
{!d.pageHref && <AppIcon icon={d.icon} class="wd-tab-icon" />}
|
|
273
|
+
{!d.pageHref && <span class="wd-submenu-label">{d.label}</span>}
|
|
274
|
+
<svg class="wd-submenu-caret" width="10" height="10" viewBox="0 0 10 10" aria-hidden="true">
|
|
275
|
+
<path d="M3.5 2L6.5 5L3.5 8" stroke="currentColor" stroke-width="1.4" fill="none" stroke-linecap="round" stroke-linejoin="round" />
|
|
276
|
+
</svg>
|
|
277
|
+
</button>
|
|
278
|
+
</div>
|
|
279
|
+
<div class="wd-submenu-panel">
|
|
280
|
+
<div class="wd-dropdown-menu-panel">
|
|
281
|
+
{d.pageHref ? (
|
|
282
|
+
<a href={d.pageHref} class="wd-submenu-heading">{d.label}</a>
|
|
283
|
+
) : (
|
|
284
|
+
<span class="wd-submenu-heading">{d.label}</span>
|
|
285
|
+
)}
|
|
286
|
+
{d.submenu.map((sub) => (
|
|
287
|
+
<a
|
|
288
|
+
href={sub.href}
|
|
289
|
+
class={sub.active ? 'active' : ''} aria-current={sub.active ? 'true' : undefined}
|
|
290
|
+
target={isExternalHref(sub.href) ? '_blank' : undefined}
|
|
291
|
+
rel={isExternalHref(sub.href) ? 'noopener noreferrer' : undefined}
|
|
292
|
+
>
|
|
293
|
+
<AppIcon icon={sub.icon} class="wd-tab-icon" />
|
|
294
|
+
{sub.label}
|
|
295
|
+
</a>
|
|
296
|
+
))}
|
|
297
|
+
</div>
|
|
298
|
+
</div>
|
|
299
|
+
</div>
|
|
300
|
+
) : (
|
|
301
|
+
<a
|
|
302
|
+
href={d.href}
|
|
303
|
+
class={d.active ? 'active' : ''} aria-current={d.active ? 'true' : undefined}
|
|
304
|
+
target={isExternalHref(d.href) ? '_blank' : undefined}
|
|
305
|
+
rel={isExternalHref(d.href) ? 'noopener noreferrer' : undefined}
|
|
306
|
+
>
|
|
307
|
+
<AppIcon icon={d.icon} class="wd-tab-icon" />
|
|
308
|
+
{d.label}
|
|
309
|
+
</a>
|
|
310
|
+
)
|
|
311
|
+
)}
|
|
263
312
|
</div>
|
|
264
313
|
</div>
|
|
265
314
|
</div>
|
|
@@ -99,6 +99,110 @@
|
|
|
99
99
|
background: color-mix(in srgb, var(--wd-primary) 10%, transparent);
|
|
100
100
|
}
|
|
101
101
|
|
|
102
|
+
/* A tab menu's entry that holds dropdowns of its own (TopBar.astro): a row -
|
|
103
|
+
the entry, a link to its page when it has one, and an arrow button - with
|
|
104
|
+
a flyout beside it. The flyout opens on hover (below), or on a click/key
|
|
105
|
+
(.open, src/scripts/dropdowns.ts); near the right end of the tab row it
|
|
106
|
+
opens to the left instead (.wd-submenu-left, src/scripts/tabs-strip.ts). */
|
|
107
|
+
.wd-submenu {
|
|
108
|
+
position: relative;
|
|
109
|
+
}
|
|
110
|
+
.wd-submenu-row {
|
|
111
|
+
display: flex;
|
|
112
|
+
align-items: stretch;
|
|
113
|
+
border-radius: 0.35rem;
|
|
114
|
+
}
|
|
115
|
+
.wd-submenu-row:hover,
|
|
116
|
+
.wd-submenu.open > .wd-submenu-row {
|
|
117
|
+
background: var(--wd-surface);
|
|
118
|
+
}
|
|
119
|
+
.wd-submenu-active > .wd-submenu-row {
|
|
120
|
+
background: color-mix(in srgb, var(--wd-primary) 10%, transparent);
|
|
121
|
+
}
|
|
122
|
+
.wd-dropdown-menu .wd-submenu-entry {
|
|
123
|
+
flex: 1;
|
|
124
|
+
min-width: 0;
|
|
125
|
+
display: flex;
|
|
126
|
+
align-items: center;
|
|
127
|
+
gap: 0.5rem;
|
|
128
|
+
padding: 0.45rem 0.6rem;
|
|
129
|
+
border: none;
|
|
130
|
+
border-radius: 0.35rem;
|
|
131
|
+
background: none;
|
|
132
|
+
font: inherit;
|
|
133
|
+
font-size: 0.88rem;
|
|
134
|
+
color: var(--wd-text);
|
|
135
|
+
text-align: left;
|
|
136
|
+
text-decoration: none;
|
|
137
|
+
cursor: pointer;
|
|
138
|
+
}
|
|
139
|
+
.wd-dropdown-menu .wd-submenu-entry:hover,
|
|
140
|
+
.wd-dropdown-menu .wd-submenu-entry.active {
|
|
141
|
+
background: none;
|
|
142
|
+
}
|
|
143
|
+
.wd-dropdown-menu .wd-submenu-entry.active {
|
|
144
|
+
color: var(--wd-primary);
|
|
145
|
+
}
|
|
146
|
+
.wd-submenu-label {
|
|
147
|
+
flex: 1;
|
|
148
|
+
min-width: 0;
|
|
149
|
+
}
|
|
150
|
+
.wd-submenu-arrow {
|
|
151
|
+
display: flex;
|
|
152
|
+
align-items: center;
|
|
153
|
+
padding: 0 0.55rem;
|
|
154
|
+
border: none;
|
|
155
|
+
border-radius: 0.35rem;
|
|
156
|
+
background: none;
|
|
157
|
+
color: var(--wd-text-muted);
|
|
158
|
+
cursor: pointer;
|
|
159
|
+
}
|
|
160
|
+
.wd-submenu-arrow:hover {
|
|
161
|
+
color: var(--wd-text);
|
|
162
|
+
}
|
|
163
|
+
.wd-submenu-caret {
|
|
164
|
+
flex-shrink: 0;
|
|
165
|
+
color: var(--wd-text-muted);
|
|
166
|
+
}
|
|
167
|
+
/* Level with the row it opens from: up by the panel's own padding and
|
|
168
|
+
border. The gap is padding, not an offset, so the pointer crossing it
|
|
169
|
+
stays on the flyout - the same reason as .wd-dropdown-menu's. */
|
|
170
|
+
.wd-submenu-panel {
|
|
171
|
+
display: none;
|
|
172
|
+
position: absolute;
|
|
173
|
+
top: calc(-0.4rem - 1px);
|
|
174
|
+
left: 100%;
|
|
175
|
+
padding-left: 0.45rem;
|
|
176
|
+
z-index: 21;
|
|
177
|
+
}
|
|
178
|
+
.wd-submenu-panel .wd-dropdown-menu-panel {
|
|
179
|
+
min-width: 200px;
|
|
180
|
+
}
|
|
181
|
+
.wd-submenu:hover > .wd-submenu-panel,
|
|
182
|
+
.wd-submenu.open > .wd-submenu-panel {
|
|
183
|
+
display: block;
|
|
184
|
+
}
|
|
185
|
+
.wd-submenu-left > .wd-submenu-panel {
|
|
186
|
+
left: auto;
|
|
187
|
+
right: 100%;
|
|
188
|
+
padding-left: 0;
|
|
189
|
+
padding-right: 0.45rem;
|
|
190
|
+
}
|
|
191
|
+
.wd-dropdown-menu .wd-submenu-heading {
|
|
192
|
+
display: block;
|
|
193
|
+
padding: 0.45rem 0.6rem 0.35rem;
|
|
194
|
+
font-size: 0.72rem;
|
|
195
|
+
font-weight: 600;
|
|
196
|
+
letter-spacing: 0.04em;
|
|
197
|
+
text-transform: uppercase;
|
|
198
|
+
color: var(--wd-primary);
|
|
199
|
+
text-decoration: none;
|
|
200
|
+
}
|
|
201
|
+
.wd-dropdown-menu a.wd-submenu-heading:hover {
|
|
202
|
+
background: none;
|
|
203
|
+
text-decoration: underline;
|
|
204
|
+
}
|
|
205
|
+
|
|
102
206
|
/* .wd-tab-icon is shared by AppIcon's two render modes: a real <svg>
|
|
103
207
|
(astro-icon, sized to the surrounding text) or a <span> (literal
|
|
104
208
|
emoji/text, sized by inherited font-size alone). Used by every dropdown
|
package/src/lib/config-schema.js
CHANGED
|
@@ -65,6 +65,7 @@ const productSchema = z.lazy(
|
|
|
65
65
|
() => withChildren({ product: z.string(), icon: z.string().optional(), description: z.string().optional() })
|
|
66
66
|
);
|
|
67
67
|
const MAX_TAB_LEVELS = 2;
|
|
68
|
+
const MAX_TAB_MENU_LEVELS = 2;
|
|
68
69
|
const globalSchema = z.object({ dropdowns: z.array(dropdownSchema).min(1) });
|
|
69
70
|
const navigationSchema = z.union([
|
|
70
71
|
z.array(navItemSchema),
|
|
@@ -75,7 +76,7 @@ const navigationSchema = z.union([
|
|
|
75
76
|
z.object({ global: globalSchema.optional(), products: z.array(productSchema).min(1) }).strict()
|
|
76
77
|
]).superRefine((navigation, ctx) => {
|
|
77
78
|
const CONTAINERS = ["tabs", "versions", "languages", "dropdowns", "products"];
|
|
78
|
-
const walk = (node, path, language, tabs) => {
|
|
79
|
+
const walk = (node, path, language, tabs, menu = 0) => {
|
|
79
80
|
if (!node || typeof node !== "object" || Array.isArray(node)) return;
|
|
80
81
|
const own = node;
|
|
81
82
|
for (const key of CONTAINERS) {
|
|
@@ -97,6 +98,15 @@ const navigationSchema = z.union([
|
|
|
97
98
|
});
|
|
98
99
|
continue;
|
|
99
100
|
}
|
|
101
|
+
const menuLevel = key !== "dropdowns" ? 0 : "tab" in own ? 1 : "dropdown" in own && menu > 0 ? menu + 1 : 0;
|
|
102
|
+
if (menuLevel > MAX_TAB_MENU_LEVELS) {
|
|
103
|
+
ctx.addIssue({
|
|
104
|
+
code: "custom",
|
|
105
|
+
path: [...path, key],
|
|
106
|
+
message: `A tab's menu goes ${MAX_TAB_MENU_LEVELS} levels deep at most - its dropdowns, and the dropdowns inside each of them - and these are a third level (inside "${String(own.dropdown)}"). Use products or groups for this level instead.`
|
|
107
|
+
});
|
|
108
|
+
continue;
|
|
109
|
+
}
|
|
100
110
|
items.forEach((item, i) => {
|
|
101
111
|
const own2 = item;
|
|
102
112
|
if (own2?.page !== void 0 && own2.href !== void 0) {
|
|
@@ -115,7 +125,7 @@ const navigationSchema = z.union([
|
|
|
115
125
|
}
|
|
116
126
|
const inner = key === "languages" ? String(item?.language ?? "") : language;
|
|
117
127
|
const tab = item?.tab;
|
|
118
|
-
walk(item, [...path, key, i], inner, key === "tabs" ? [...tabs, String(tab ?? "")] : tabs);
|
|
128
|
+
walk(item, [...path, key, i], inner, key === "tabs" ? [...tabs, String(tab ?? "")] : tabs, menuLevel);
|
|
119
129
|
});
|
|
120
130
|
}
|
|
121
131
|
};
|
|
@@ -955,6 +965,7 @@ function validateDocsConfig(rawText) {
|
|
|
955
965
|
export {
|
|
956
966
|
CONTEXT_MENU_OPTIONS,
|
|
957
967
|
MAX_TAB_LEVELS,
|
|
968
|
+
MAX_TAB_MENU_LEVELS,
|
|
958
969
|
MCP_MENU_OPTIONS,
|
|
959
970
|
ROOT_ALLOWED_EXTRA_KEYS,
|
|
960
971
|
contextMenuOptions,
|
package/src/lib/config-schema.ts
CHANGED
|
@@ -220,6 +220,9 @@ export type NavigationConfig =
|
|
|
220
220
|
|
|
221
221
|
/** Levels of tabs a page can sit under - one row of the top bar each. */
|
|
222
222
|
export const MAX_TAB_LEVELS = 2;
|
|
223
|
+
/** Levels of dropdowns in a tab's menu - the menu, and a flyout beside an
|
|
224
|
+
* entry for the dropdowns inside it (lib/selector-placement.js). */
|
|
225
|
+
export const MAX_TAB_MENU_LEVELS = 2;
|
|
223
226
|
|
|
224
227
|
const globalSchema = z.object({ dropdowns: z.array(dropdownSchema).min(1) });
|
|
225
228
|
|
|
@@ -235,7 +238,9 @@ const navigationSchema = z.union([
|
|
|
235
238
|
// inside it would make a page two languages at once. And tabs take a row
|
|
236
239
|
// of the top bar per level: two levels at most (TopBar.astro).
|
|
237
240
|
const CONTAINERS = ['tabs', 'versions', 'languages', 'dropdowns', 'products'] as const;
|
|
238
|
-
|
|
241
|
+
// `menu`: the dropdown levels in a tab's menu down to `node` - 0 outside
|
|
242
|
+
// one, 1 for a dropdown right inside a tab, 2 for a dropdown inside that.
|
|
243
|
+
const walk = (node: unknown, path: (string | number)[], language: string | null, tabs: string[], menu = 0) => {
|
|
239
244
|
if (!node || typeof node !== 'object' || Array.isArray(node)) return;
|
|
240
245
|
const own = node as Record<string, unknown>;
|
|
241
246
|
for (const key of CONTAINERS) {
|
|
@@ -257,6 +262,18 @@ const navigationSchema = z.union([
|
|
|
257
262
|
});
|
|
258
263
|
continue;
|
|
259
264
|
}
|
|
265
|
+
// Dropdowns right inside a tab are its menu; dropdowns inside one of
|
|
266
|
+
// those, a flyout beside its entry. Any other level of dropdowns starts
|
|
267
|
+
// its own count.
|
|
268
|
+
const menuLevel = key !== 'dropdowns' ? 0 : 'tab' in own ? 1 : 'dropdown' in own && menu > 0 ? menu + 1 : 0;
|
|
269
|
+
if (menuLevel > MAX_TAB_MENU_LEVELS) {
|
|
270
|
+
ctx.addIssue({
|
|
271
|
+
code: 'custom',
|
|
272
|
+
path: [...path, key],
|
|
273
|
+
message: `A tab's menu goes ${MAX_TAB_MENU_LEVELS} levels deep at most - its dropdowns, and the dropdowns inside each of them - and these are a third level (inside "${String(own.dropdown)}"). Use products or groups for this level instead.`,
|
|
274
|
+
});
|
|
275
|
+
continue;
|
|
276
|
+
}
|
|
260
277
|
items.forEach((item, i) => {
|
|
261
278
|
const own = item as { hidden?: unknown; searchPublic?: unknown; page?: unknown; href?: unknown };
|
|
262
279
|
if (own?.page !== undefined && own.href !== undefined) {
|
|
@@ -275,7 +292,7 @@ const navigationSchema = z.union([
|
|
|
275
292
|
}
|
|
276
293
|
const inner = key === 'languages' ? String((item as { language?: unknown })?.language ?? '') : language;
|
|
277
294
|
const tab = (item as { tab?: unknown })?.tab;
|
|
278
|
-
walk(item, [...path, key, i], inner, key === 'tabs' ? [...tabs, String(tab ?? '')] : tabs);
|
|
295
|
+
walk(item, [...path, key, i], inner, key === 'tabs' ? [...tabs, String(tab ?? '')] : tabs, menuLevel);
|
|
279
296
|
});
|
|
280
297
|
}
|
|
281
298
|
};
|
package/src/lib/config.ts
CHANGED
|
@@ -804,7 +804,7 @@ export function landingSelectors(landing: Landing, hrefForSlug: (slug: string) =
|
|
|
804
804
|
description: 'description' in child ? child.description : undefined,
|
|
805
805
|
href: 'href' in child ? child.href : hrefForSlug(firstSlugOf(child as Container) ?? 'index'),
|
|
806
806
|
active: false,
|
|
807
|
-
dropdown: dropdownMenuOf(child as Container, hrefForSlug
|
|
807
|
+
dropdown: dropdownMenuOf(child as Container, hrefForSlug),
|
|
808
808
|
};
|
|
809
809
|
}),
|
|
810
810
|
});
|
|
@@ -993,11 +993,16 @@ export interface SelectorOption {
|
|
|
993
993
|
// Set when this option's own container is a `dropdowns` list (e.g. a
|
|
994
994
|
// tab whose content is `dropdowns` instead of `pages`) - the tab pill
|
|
995
995
|
// itself becomes a dropdown-trigger showing these as its menu, rather
|
|
996
|
-
// than a separate dropdown control rendered alongside it.
|
|
997
|
-
// populated one level deep (a dropdown option doesn't itself get a
|
|
998
|
-
// nested `dropdown` - matches the one level of "a tab/dropdown owns a
|
|
999
|
-
// dropdowns list" this is meant to cover).
|
|
996
|
+
// than a separate dropdown control rendered alongside it.
|
|
1000
997
|
dropdown?: SelectorOption[];
|
|
998
|
+
// On an entry of that menu holding dropdowns of its own: those, shown in a
|
|
999
|
+
// flyout beside the entry (TopBar.astro). A tab's menu goes two levels deep
|
|
1000
|
+
// at most (MAX_TAB_MENU_LEVELS in config-schema.ts), so a flyout's entries
|
|
1001
|
+
// have none.
|
|
1002
|
+
submenu?: SelectorOption[];
|
|
1003
|
+
// On an entry with a `submenu`: the entry's own `page`, if it has one -
|
|
1004
|
+
// clicking the entry opens it. Without one, clicking opens the flyout.
|
|
1005
|
+
pageHref?: string;
|
|
1001
1006
|
}
|
|
1002
1007
|
|
|
1003
1008
|
export interface Selector {
|
|
@@ -1015,27 +1020,38 @@ export interface Selector {
|
|
|
1015
1020
|
}
|
|
1016
1021
|
|
|
1017
1022
|
/** An option's own `dropdowns` menu, if it has one (see SelectorOption.dropdown
|
|
1018
|
-
* above)
|
|
1019
|
-
*
|
|
1020
|
-
*
|
|
1021
|
-
*
|
|
1022
|
-
* selected. */
|
|
1023
|
+
* above), with a `submenu` on each entry that holds dropdowns of its own.
|
|
1024
|
+
* `activePath` is the path *below* this option's own segment, only passed
|
|
1025
|
+
* when this option is the active one on its level, so a sibling option that
|
|
1026
|
+
* also happens to own `dropdowns` doesn't spuriously mark one of its entries
|
|
1027
|
+
* active just because some *other* option is currently selected. */
|
|
1023
1028
|
function dropdownMenuOf(
|
|
1024
1029
|
node: NavChildren,
|
|
1025
1030
|
hrefForSlug: (slug: string) => string,
|
|
1026
|
-
|
|
1031
|
+
activePath: PathSegment[] = [],
|
|
1032
|
+
depth = 1
|
|
1027
1033
|
): SelectorOption[] | undefined {
|
|
1028
1034
|
if (!('dropdowns' in node)) return undefined;
|
|
1029
|
-
|
|
1030
|
-
|
|
1035
|
+
const [segment, ...below] = activePath;
|
|
1036
|
+
return node.dropdowns.flatMap((d, i): SelectorOption[] => {
|
|
1037
|
+
if (isHidden(d)) return [];
|
|
1038
|
+
const active = segment?.kind === 'dropdown' && segment.index === i;
|
|
1039
|
+
const option: SelectorOption = {
|
|
1031
1040
|
label: d.dropdown,
|
|
1032
1041
|
icon: iconOf(d),
|
|
1033
1042
|
href: 'href' in d ? d.href : hrefForSlug(firstSlugOf(d) ?? 'index'),
|
|
1034
|
-
active
|
|
1035
|
-
|
|
1036
|
-
|
|
1037
|
-
|
|
1038
|
-
|
|
1043
|
+
active,
|
|
1044
|
+
};
|
|
1045
|
+
if (depth === 1 && 'dropdowns' in d) {
|
|
1046
|
+
const submenu = dropdownMenuOf(d, hrefForSlug, active ? below : [], depth + 1);
|
|
1047
|
+
if (submenu && submenu.length > 0) {
|
|
1048
|
+
option.submenu = submenu;
|
|
1049
|
+
const own = itemPage(d);
|
|
1050
|
+
if (own !== null) option.pageHref = hrefForSlug(own);
|
|
1051
|
+
}
|
|
1052
|
+
}
|
|
1053
|
+
return [option];
|
|
1054
|
+
});
|
|
1039
1055
|
}
|
|
1040
1056
|
|
|
1041
1057
|
/** `activePagePosition` is the reader's current page's own index within
|
|
@@ -1074,7 +1090,7 @@ export function buildSelectors(
|
|
|
1074
1090
|
description: 'description' in item ? item.description : undefined,
|
|
1075
1091
|
href: 'href' in item ? item.href : hrefForSlug(targetSlug),
|
|
1076
1092
|
active: isActive,
|
|
1077
|
-
dropdown: dropdownMenuOf(item, hrefForSlug, isActive ? path
|
|
1093
|
+
dropdown: dropdownMenuOf(item, hrefForSlug, isActive ? path.slice(segIndex + 1) : []),
|
|
1078
1094
|
};
|
|
1079
1095
|
}),
|
|
1080
1096
|
};
|
|
@@ -12,7 +12,7 @@ const CHILDREN = {
|
|
|
12
12
|
tabs: 'Tabs inside this one.',
|
|
13
13
|
versions: 'Versions inside this one - a version picker in the sidebar.',
|
|
14
14
|
languages: 'Languages inside this one - a language picker.',
|
|
15
|
-
dropdowns: 'Dropdowns inside this one
|
|
15
|
+
dropdowns: 'Dropdowns inside this one. Inside a tab they are its menu, and inside one of those a flyout beside its entry - two levels at most; elsewhere, a switcher.',
|
|
16
16
|
products: 'Products inside this one - a product picker.',
|
|
17
17
|
href: 'Makes this a link to another address instead of a section with pages of its own.',
|
|
18
18
|
};
|
|
@@ -3,6 +3,8 @@
|
|
|
3
3
|
//
|
|
4
4
|
// 'tabs' a row of tabs in the top bar (a second row for tabs inside tabs)
|
|
5
5
|
// 'tab-menu' the menu of the tab it sits in (dropdowns directly inside a tab)
|
|
6
|
+
// 'tab-submenu' a flyout beside its entry in that menu (dropdowns inside a
|
|
7
|
+
// 'tab-menu' dropdown - SelectorOption.submenu in lib/config.ts)
|
|
6
8
|
// 'sidebar' the top of the sidebar: products inside a tab or a dropdown,
|
|
7
9
|
// like Mintlify's - they pick what the sidebar shows
|
|
8
10
|
// 'topbar' a switcher next to the site name (everything else)
|
|
@@ -14,14 +16,20 @@
|
|
|
14
16
|
// either way.
|
|
15
17
|
|
|
16
18
|
export function selectorPlacements(selectors, { sidebar = true } = {}) {
|
|
17
|
-
|
|
18
|
-
|
|
19
|
+
const placements = [];
|
|
20
|
+
selectors.forEach((sel, i) => {
|
|
19
21
|
const parent = selectors[i - 1]?.kind;
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
22
|
+
const placement = (() => {
|
|
23
|
+
if (sel.hidden) return 'none';
|
|
24
|
+
if (sel.kind === 'tab') return 'tabs';
|
|
25
|
+
if (sel.kind === 'dropdown' && parent === 'tab') return 'tab-menu';
|
|
26
|
+
if (sel.kind === 'dropdown' && placements[i - 1] === 'tab-menu') return 'tab-submenu';
|
|
27
|
+
if (sel.kind === 'product' && (parent === 'tab' || parent === 'dropdown')) return sidebar ? 'sidebar' : 'topbar';
|
|
28
|
+
return 'topbar';
|
|
29
|
+
})();
|
|
30
|
+
placements.push(placement);
|
|
24
31
|
});
|
|
32
|
+
return placements;
|
|
25
33
|
}
|
|
26
34
|
|
|
27
35
|
/** Whether a page gets the mobile menu (its button in the top bar, and the
|
package/src/scripts/dropdowns.ts
CHANGED
|
@@ -15,14 +15,49 @@
|
|
|
15
15
|
// move between its options (Home/End jump to the ends); Escape closes it
|
|
16
16
|
// and puts focus back on its button; tabbing out of it closes it.
|
|
17
17
|
//
|
|
18
|
+
// A tab menu's entry can hold a flyout (`.wd-submenu`, TopBar.astro): it opens
|
|
19
|
+
// on hover, on a click on its arrow - or on the entry itself, when the entry
|
|
20
|
+
// has no page to open - and from the keyboard with Right. In the flyout,
|
|
21
|
+
// Down/Up move between its links, and Left or Escape close it, back on its
|
|
22
|
+
// entry.
|
|
23
|
+
//
|
|
18
24
|
// The document-level listeners are bound once per page load, and act on
|
|
19
25
|
// whichever dropdowns are open at the time - so they keep working for the
|
|
20
26
|
// ones a client-side navigation brings in.
|
|
21
27
|
let globalListenersBound = false;
|
|
22
28
|
|
|
23
29
|
const triggerOf = (dropdown: Element) => dropdown.querySelector<HTMLElement>('.wd-dropdown-trigger');
|
|
30
|
+
// The list's own options - not a flyout's links, and not a flyout's arrow
|
|
31
|
+
// button (Right opens the flyout from its entry instead).
|
|
24
32
|
const optionsOf = (dropdown: Element) =>
|
|
25
|
-
Array.from(dropdown.querySelectorAll<HTMLElement>('.wd-dropdown-menu a[href], .wd-dropdown-menu button'))
|
|
33
|
+
Array.from(dropdown.querySelectorAll<HTMLElement>('.wd-dropdown-menu a[href], .wd-dropdown-menu button')).filter(
|
|
34
|
+
(el) => !el.closest('.wd-submenu-panel') && !el.classList.contains('wd-submenu-arrow')
|
|
35
|
+
);
|
|
36
|
+
const flyoutLinksOf = (submenu: Element) =>
|
|
37
|
+
Array.from(submenu.querySelectorAll<HTMLElement>('.wd-submenu-panel a[href]'));
|
|
38
|
+
const entryOf = (submenu: Element) => submenu.querySelector<HTMLElement>('.wd-submenu-entry');
|
|
39
|
+
|
|
40
|
+
function setSubmenu(submenu: Element, isOpen: boolean) {
|
|
41
|
+
submenu.classList.toggle('open', isOpen);
|
|
42
|
+
submenu.querySelectorAll('.wd-submenu-toggle').forEach((toggle) => toggle.setAttribute('aria-expanded', String(isOpen)));
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
function closeSubmenus(dropdown: Element, except?: Element) {
|
|
46
|
+
dropdown.querySelectorAll('.wd-submenu.open').forEach((submenu) => {
|
|
47
|
+
if (submenu !== except) setSubmenu(submenu, false);
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/** Moves focus within `options` for an arrow/Home/End key. */
|
|
52
|
+
function moveFocus(options: HTMLElement[], key: string) {
|
|
53
|
+
const at = options.indexOf(document.activeElement as HTMLElement);
|
|
54
|
+
let next: number;
|
|
55
|
+
if (key === 'Home') next = 0;
|
|
56
|
+
else if (key === 'End') next = options.length - 1;
|
|
57
|
+
else if (at === -1) next = key === 'ArrowUp' ? options.length - 1 : 0;
|
|
58
|
+
else next = Math.min(Math.max(at + (key === 'ArrowDown' ? 1 : -1), 0), options.length - 1);
|
|
59
|
+
options[next]?.focus();
|
|
60
|
+
}
|
|
26
61
|
|
|
27
62
|
function open(dropdown: Element) {
|
|
28
63
|
closeAll(dropdown);
|
|
@@ -31,6 +66,7 @@ function open(dropdown: Element) {
|
|
|
31
66
|
}
|
|
32
67
|
|
|
33
68
|
function close(dropdown: Element) {
|
|
69
|
+
closeSubmenus(dropdown);
|
|
34
70
|
dropdown.classList.remove('open');
|
|
35
71
|
triggerOf(dropdown)?.setAttribute('aria-expanded', 'false');
|
|
36
72
|
// Focus on an option that just got hidden would drop to the top of the
|
|
@@ -57,27 +93,68 @@ export function initDropdowns(root: ParentNode) {
|
|
|
57
93
|
else open(dropdown);
|
|
58
94
|
});
|
|
59
95
|
|
|
96
|
+
// Flyouts: a click on an entry's toggle opens or closes its flyout and
|
|
97
|
+
// keeps the menu open; pointing at another entry closes the others.
|
|
98
|
+
dropdown.querySelectorAll<HTMLElement>('.wd-submenu').forEach((submenu) => {
|
|
99
|
+
submenu.querySelectorAll<HTMLElement>('.wd-submenu-toggle').forEach((toggle) => {
|
|
100
|
+
toggle.addEventListener('click', (e) => {
|
|
101
|
+
e.stopPropagation();
|
|
102
|
+
const isOpen = !submenu.classList.contains('open');
|
|
103
|
+
closeSubmenus(dropdown, submenu);
|
|
104
|
+
setSubmenu(submenu, isOpen);
|
|
105
|
+
});
|
|
106
|
+
});
|
|
107
|
+
});
|
|
108
|
+
dropdown.querySelectorAll<HTMLElement>('.wd-dropdown-menu-panel > a, .wd-dropdown-menu-panel > .wd-submenu').forEach((entry) => {
|
|
109
|
+
entry.addEventListener('pointerenter', () => closeSubmenus(dropdown, entry));
|
|
110
|
+
});
|
|
111
|
+
|
|
60
112
|
dropdown.addEventListener('keydown', (e) => {
|
|
113
|
+
const target = e.target as HTMLElement;
|
|
114
|
+
const submenu = target.closest('.wd-submenu');
|
|
115
|
+
// Inside a flyout.
|
|
116
|
+
if (submenu && target.closest('.wd-submenu-panel')) {
|
|
117
|
+
if (['ArrowDown', 'ArrowUp', 'Home', 'End'].includes(e.key)) {
|
|
118
|
+
e.preventDefault();
|
|
119
|
+
moveFocus(flyoutLinksOf(submenu), e.key);
|
|
120
|
+
} else if (e.key === 'ArrowLeft' || e.key === 'Escape') {
|
|
121
|
+
e.preventDefault();
|
|
122
|
+
e.stopPropagation();
|
|
123
|
+
setSubmenu(submenu, false);
|
|
124
|
+
entryOf(submenu)?.focus();
|
|
125
|
+
}
|
|
126
|
+
return;
|
|
127
|
+
}
|
|
128
|
+
// On an entry with a flyout: Right opens it, on its first link.
|
|
129
|
+
if (submenu && e.key === 'ArrowRight') {
|
|
130
|
+
e.preventDefault();
|
|
131
|
+
closeSubmenus(dropdown, submenu);
|
|
132
|
+
setSubmenu(submenu, true);
|
|
133
|
+
flyoutLinksOf(submenu)[0]?.focus();
|
|
134
|
+
return;
|
|
135
|
+
}
|
|
61
136
|
if (!['ArrowDown', 'ArrowUp', 'Home', 'End'].includes(e.key)) return;
|
|
62
137
|
const options = optionsOf(dropdown);
|
|
63
138
|
if (options.length === 0) return;
|
|
64
139
|
e.preventDefault();
|
|
65
140
|
if (!dropdown.classList.contains('open')) open(dropdown);
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
if (e.key === 'Home') next = 0;
|
|
69
|
-
else if (e.key === 'End') next = options.length - 1;
|
|
70
|
-
else if (at === -1) next = e.key === 'ArrowUp' ? options.length - 1 : 0;
|
|
71
|
-
else next = Math.min(Math.max(at + (e.key === 'ArrowDown' ? 1 : -1), 0), options.length - 1);
|
|
72
|
-
options[next].focus();
|
|
141
|
+
closeSubmenus(dropdown);
|
|
142
|
+
moveFocus(options, e.key);
|
|
73
143
|
});
|
|
74
144
|
|
|
75
145
|
// Focus moving somewhere outside the dropdown (Tab, Shift+Tab) closes
|
|
76
146
|
// it. No `relatedTarget` means focus went nowhere in particular - a
|
|
77
147
|
// click on the page, which the click-outside listener already handles.
|
|
148
|
+
// Focus moving to another entry closes the flyouts it isn't in.
|
|
149
|
+
dropdown.addEventListener('focusin', (e) => {
|
|
150
|
+
const into = (e.target as HTMLElement).closest('.wd-submenu') ?? undefined;
|
|
151
|
+
closeSubmenus(dropdown, into);
|
|
152
|
+
});
|
|
153
|
+
|
|
78
154
|
dropdown.addEventListener('focusout', (e) => {
|
|
79
155
|
const to = e.relatedTarget as Node | null;
|
|
80
156
|
if (to && !dropdown.contains(to) && dropdown.classList.contains('open')) {
|
|
157
|
+
closeSubmenus(dropdown);
|
|
81
158
|
dropdown.classList.remove('open');
|
|
82
159
|
trigger.setAttribute('aria-expanded', 'false');
|
|
83
160
|
}
|
|
@@ -162,6 +162,29 @@ function initStrip(strip: HTMLElement) {
|
|
|
162
162
|
dropdown.addEventListener('focusin', place);
|
|
163
163
|
});
|
|
164
164
|
|
|
165
|
+
// A flyout beside a menu entry (TopBar.astro) is cut off the same way past
|
|
166
|
+
// the row's right end - it opens to the left of its menu there, when that
|
|
167
|
+
// side has more room.
|
|
168
|
+
track.querySelectorAll<HTMLElement>('.wd-submenu').forEach((submenu) => {
|
|
169
|
+
const panel = submenu.querySelector<HTMLElement>('.wd-submenu-panel');
|
|
170
|
+
if (!panel) return;
|
|
171
|
+
const place = () => {
|
|
172
|
+
const shown = panel.style.display;
|
|
173
|
+
panel.style.visibility = 'hidden';
|
|
174
|
+
panel.style.display = 'block';
|
|
175
|
+
const width = panel.offsetWidth;
|
|
176
|
+
panel.style.display = shown;
|
|
177
|
+
panel.style.visibility = '';
|
|
178
|
+
const entry = submenu.getBoundingClientRect();
|
|
179
|
+
const row = viewport.getBoundingClientRect();
|
|
180
|
+
const roomRight = row.right - entry.right;
|
|
181
|
+
const roomLeft = entry.left - row.left;
|
|
182
|
+
submenu.classList.toggle('wd-submenu-left', roomRight < width && roomLeft > roomRight);
|
|
183
|
+
};
|
|
184
|
+
submenu.addEventListener('pointerenter', place);
|
|
185
|
+
submenu.addEventListener('focusin', place);
|
|
186
|
+
});
|
|
187
|
+
|
|
165
188
|
// Tabs change width as fonts load, and the space changes with the window.
|
|
166
189
|
const resized = () => (readerMoved ? apply() : settle());
|
|
167
190
|
new ResizeObserver(resized).observe(viewport);
|
package/writedocs.schema.json
CHANGED
|
@@ -1396,8 +1396,8 @@
|
|
|
1396
1396
|
"items": {
|
|
1397
1397
|
"$ref": "#/definitions/Dropdown"
|
|
1398
1398
|
},
|
|
1399
|
-
"description": "Dropdowns inside this one
|
|
1400
|
-
"markdownDescription": "Dropdowns inside this one
|
|
1399
|
+
"description": "Dropdowns inside this one. Inside a tab they are its menu, and inside one of those a flyout beside its entry - two levels at most; elsewhere, a switcher.",
|
|
1400
|
+
"markdownDescription": "Dropdowns inside this one. Inside a tab they are its menu, and inside one of those a flyout beside its entry - two levels at most; elsewhere, a switcher."
|
|
1401
1401
|
}
|
|
1402
1402
|
},
|
|
1403
1403
|
"required": [
|
|
@@ -1705,8 +1705,8 @@
|
|
|
1705
1705
|
"items": {
|
|
1706
1706
|
"$ref": "#/definitions/Dropdown"
|
|
1707
1707
|
},
|
|
1708
|
-
"description": "Dropdowns inside this one
|
|
1709
|
-
"markdownDescription": "Dropdowns inside this one
|
|
1708
|
+
"description": "Dropdowns inside this one. Inside a tab they are its menu, and inside one of those a flyout beside its entry - two levels at most; elsewhere, a switcher.",
|
|
1709
|
+
"markdownDescription": "Dropdowns inside this one. Inside a tab they are its menu, and inside one of those a flyout beside its entry - two levels at most; elsewhere, a switcher."
|
|
1710
1710
|
}
|
|
1711
1711
|
},
|
|
1712
1712
|
"required": [
|
|
@@ -2064,8 +2064,8 @@
|
|
|
2064
2064
|
"items": {
|
|
2065
2065
|
"$ref": "#/definitions/Dropdown"
|
|
2066
2066
|
},
|
|
2067
|
-
"description": "Dropdowns inside this one
|
|
2068
|
-
"markdownDescription": "Dropdowns inside this one
|
|
2067
|
+
"description": "Dropdowns inside this one. Inside a tab they are its menu, and inside one of those a flyout beside its entry - two levels at most; elsewhere, a switcher.",
|
|
2068
|
+
"markdownDescription": "Dropdowns inside this one. Inside a tab they are its menu, and inside one of those a flyout beside its entry - two levels at most; elsewhere, a switcher."
|
|
2069
2069
|
}
|
|
2070
2070
|
},
|
|
2071
2071
|
"required": [
|
|
@@ -2393,8 +2393,8 @@
|
|
|
2393
2393
|
"items": {
|
|
2394
2394
|
"$ref": "#/definitions/Dropdown"
|
|
2395
2395
|
},
|
|
2396
|
-
"description": "Dropdowns inside this one
|
|
2397
|
-
"markdownDescription": "Dropdowns inside this one
|
|
2396
|
+
"description": "Dropdowns inside this one. Inside a tab they are its menu, and inside one of those a flyout beside its entry - two levels at most; elsewhere, a switcher.",
|
|
2397
|
+
"markdownDescription": "Dropdowns inside this one. Inside a tab they are its menu, and inside one of those a flyout beside its entry - two levels at most; elsewhere, a switcher."
|
|
2398
2398
|
}
|
|
2399
2399
|
},
|
|
2400
2400
|
"required": [
|
|
@@ -2727,8 +2727,8 @@
|
|
|
2727
2727
|
"items": {
|
|
2728
2728
|
"$ref": "#/definitions/Dropdown"
|
|
2729
2729
|
},
|
|
2730
|
-
"description": "Dropdowns inside this one
|
|
2731
|
-
"markdownDescription": "Dropdowns inside this one
|
|
2730
|
+
"description": "Dropdowns inside this one. Inside a tab they are its menu, and inside one of those a flyout beside its entry - two levels at most; elsewhere, a switcher.",
|
|
2731
|
+
"markdownDescription": "Dropdowns inside this one. Inside a tab they are its menu, and inside one of those a flyout beside its entry - two levels at most; elsewhere, a switcher."
|
|
2732
2732
|
}
|
|
2733
2733
|
},
|
|
2734
2734
|
"required": [
|