ab-nextjs-components 0.4.2 โ 0.6.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/CHANGELOG.md +81 -17
- package/README.md +16 -2
- package/ab-app-bar/index.tsx +5 -5
- package/ab-app-bar/styles.module.css +5 -5
- package/ab-bottom-drawer/index.tsx +3 -3
- package/ab-bottom-drawer/styles.module.css +2 -2
- package/ab-bottom-drawer/use-ab-swipe-down.ts +1 -1
- package/ab-breadcrumbs/index.tsx +1 -1
- package/ab-breadcrumbs/styles.module.css +5 -5
- package/ab-button/index.tsx +1 -1
- package/ab-button/styles.module.css +5 -5
- package/ab-callout/index.tsx +1 -1
- package/ab-callout/styles.module.css +1 -1
- package/ab-carousel/helpers.ts +1 -1
- package/ab-carousel/index.tsx +4 -4
- package/ab-carousel/styles.module.css +2 -2
- package/ab-chip/styles.module.css +1 -1
- package/ab-code-block/focus.tsx +63 -0
- package/ab-code-block/index.tsx +55 -28
- package/ab-code-block/styles.module.css +4 -3
- package/ab-content-tabs/index.tsx +25 -3
- package/ab-demo-box/index.tsx +45 -7
- package/ab-demo-box/styles.module.css +19 -7
- package/ab-demo-code/index.tsx +38 -34
- package/ab-demo-code/styles.module.css +3 -41
- package/ab-doc-pager/index.tsx +1 -1
- package/ab-drawer/gestures.ts +1 -1
- package/ab-drawer/index.tsx +12 -4
- package/ab-drawer/kit.module.css +13 -13
- package/ab-drawer/styles.module.css +2 -2
- package/ab-drawer/use-ab-edge-swipe.ts +2 -2
- package/ab-flow-diagram/helpers.ts +2 -2
- package/ab-flow-diagram/index.tsx +2 -2
- package/ab-flow-diagram/styles.module.css +3 -3
- package/ab-icon/builtin.ts +4 -0
- package/ab-icon/helpers.ts +1 -1
- package/ab-icon/index.tsx +3 -3
- package/ab-icon/registrar.tsx +1 -1
- package/ab-icon-button/index.tsx +1 -1
- package/ab-install-snippet/styles.module.css +1 -1
- package/ab-link/index.tsx +2 -2
- package/ab-link/locale.ts +1 -1
- package/ab-list/styles.module.css +1 -1
- package/ab-locale-switcher/index.tsx +6 -6
- package/ab-locale-switcher/styles.module.css +5 -5
- package/ab-mobile-header/index.tsx +6 -6
- package/ab-nav-drawer/index.tsx +11 -6
- package/ab-navbar/index.tsx +1 -1
- package/ab-navbar/styles.module.css +1 -1
- package/ab-navbar/view.tsx +1 -1
- package/ab-package-card/index.tsx +3 -3
- package/ab-package-card/previews.tsx +1 -1
- package/ab-package-card/styles.module.css +2 -2
- package/ab-playground-scene/i18n.module.css +1 -1
- package/ab-playground-scene/icons.tsx +1 -1
- package/ab-playground-scene/index.tsx +4 -4
- package/ab-playground-scene/labels.ts +3 -3
- package/ab-playground-scene/scenes.tsx +4 -4
- package/ab-playground-scene/styles.module.css +6 -6
- package/ab-playground-scene/upgraded.tsx +3 -3
- package/ab-playground-scene/welcome.tsx +1 -1
- package/ab-preview-code/index.tsx +115 -0
- package/ab-preview-code/stage.tsx +153 -0
- package/ab-preview-code/styles.module.css +43 -0
- package/ab-progress-chips/index.tsx +1 -1
- package/ab-search-drawer/index.tsx +4 -4
- package/ab-search-trigger/index.tsx +5 -5
- package/ab-search-trigger/styles.module.css +3 -3
- package/ab-settings-drawer/index.tsx +2 -2
- package/ab-sidebar/active.ts +105 -0
- package/ab-sidebar/index.tsx +10 -6
- package/ab-sidebar/profile-button.tsx +2 -2
- package/ab-sidebar/styles.module.css +4 -4
- package/ab-sidebar/view.tsx +16 -8
- package/ab-theme-mode/index.tsx +3 -3
- package/ab-theme-toggle/index.tsx +6 -6
- package/ab-theme-toggle/styles.module.css +2 -2
- package/ab-toc/index.tsx +3 -3
- package/ab-toc/promo.tsx +2 -2
- package/ab-toc/styles.module.css +1 -1
- package/ab-toc-drawer/index.tsx +1 -1
- package/ab-version-switcher/index.tsx +2 -2
- package/css/dialog.css +1 -1
- package/index.ts +29 -18
- package/package.json +3 -1
- package/server/ab-button/index.tsx +1 -1
- package/server/ab-icon/index.tsx +2 -2
- package/server/ab-sidebar/index.tsx +3 -2
- package/types/index.d.ts +8 -7
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* @license MIT
|
|
3
|
+
* ~~~~~~~~~~~~
|
|
4
|
+
* ab-nextjs-components
|
|
5
|
+
* ~~~~~~~~~~~~
|
|
6
|
+
* Copyright (c) 2026 Abraham Ukachi. The abElements Project.
|
|
7
|
+
*
|
|
8
|
+
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
9
|
+
* of this software and associated documentation files (the 'Software'), to deal
|
|
10
|
+
* in the Software without restriction, including without limitation the rights
|
|
11
|
+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
12
|
+
* copies of the Software, and to permit persons to whom the Software is
|
|
13
|
+
* furnished to do so, subject to the following conditions:
|
|
14
|
+
*
|
|
15
|
+
* The above copyright notice and this permission notice shall be included in all
|
|
16
|
+
* copies or substantial portions of the Software.
|
|
17
|
+
*
|
|
18
|
+
* THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
19
|
+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
20
|
+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
21
|
+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
22
|
+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
23
|
+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
24
|
+
* SOFTWARE.
|
|
25
|
+
*
|
|
26
|
+
* @project: ab-nextjs-components
|
|
27
|
+
* @name: AbCodeBlockFocus (0.6.0)
|
|
28
|
+
* @file: ab-code-block/focus.tsx
|
|
29
|
+
* @type: Client component (island)
|
|
30
|
+
* @authors: Abraham Ukachi <abrahamukachi@gmail.com>
|
|
31
|
+
*/
|
|
32
|
+
|
|
33
|
+
/*
|
|
34
|
+
* !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
|
|
35
|
+
* MOTTO: We'll always do more ๐!!!
|
|
36
|
+
* !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
|
|
37
|
+
*/
|
|
38
|
+
|
|
39
|
+
'use client';
|
|
40
|
+
|
|
41
|
+
// โ๏ธ React
|
|
42
|
+
import { useEffect, useRef, type ReactElement } from 'react';
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* โจ๏ธ AbCodeBlockFocus โ keeps ONE tab stop in a `trustedHtml` block. Shiki's string carries
|
|
46
|
+
* `<pre tabindex="0">`; we never edit that string, so after hydration this island sets the inner <pre>'s
|
|
47
|
+
* tabindex to -1 in the DOM (the wrapper scroller stays the stop). Before hydration / without JS the
|
|
48
|
+
* leftover tabindex remains (a harmless second stop); pass `highlighted` / children to avoid it entirely.
|
|
49
|
+
*/
|
|
50
|
+
const AbCodeBlockFocus = (): ReactElement => {
|
|
51
|
+
const ref = useRef<HTMLSpanElement>(null); // ๐ to find our block
|
|
52
|
+
useEffect(() => {
|
|
53
|
+
const block = ref.current?.closest('[data-ab-part="code-block"]'); // ๐งฑ our AbCodeBlock
|
|
54
|
+
block?.querySelectorAll<HTMLElement>('[data-ab-part="code-block-code"] pre[tabindex]').forEach((pre) => {
|
|
55
|
+
if (pre.tabIndex >= 0) pre.setAttribute('tabindex', '-1'); // โ๏ธ demote Shiki's stop (string untouched)
|
|
56
|
+
});
|
|
57
|
+
}); // ๐ every render: a new trustedHtml string brings a new <pre>
|
|
58
|
+
return <span ref={ref} hidden data-ab-part="code-block-focus" />; // ๐ซฅ an invisible anchor
|
|
59
|
+
};
|
|
60
|
+
|
|
61
|
+
// ๐ฆ exports
|
|
62
|
+
export default AbCodeBlockFocus;
|
|
63
|
+
export { AbCodeBlockFocus };
|
package/ab-code-block/index.tsx
CHANGED
|
@@ -24,13 +24,13 @@
|
|
|
24
24
|
* SOFTWARE.
|
|
25
25
|
*
|
|
26
26
|
* @project: ab-nextjs-components
|
|
27
|
-
* @name: AbCodeBlock (0.3.4,
|
|
27
|
+
* @name: AbCodeBlock (0.3.4, QA 0.2.24 MDX docs)
|
|
28
28
|
* @file: ab-code-block/index.tsx
|
|
29
29
|
* @type: Server component (no hooks; the copy button is a client island)
|
|
30
30
|
* @authors: Abraham Ukachi <abrahamukachi@gmail.com>
|
|
31
31
|
*
|
|
32
32
|
* Example usage:
|
|
33
|
-
* 1+|> <AbCodeBlock filename="app/page.tsx" language="tsx" code={source}
|
|
33
|
+
* 1+|> <AbCodeBlock filename="app/page.tsx" language="tsx" code={source} trustedHtml={await codeToHtml(source, โฆ)} />
|
|
34
34
|
* 2+|> <AbCodeBlock language="bash" copyLabel={t('copy')} copiedLabel={t('copied')}><pre><code>pnpm add ab-nextjs-components</code></pre></AbCodeBlock>
|
|
35
35
|
*/
|
|
36
36
|
|
|
@@ -46,40 +46,52 @@ import { Children, cloneElement, isValidElement, type ReactElement, type ReactNo
|
|
|
46
46
|
import clsx from 'clsx';
|
|
47
47
|
// ๐ the copy button (the only client part)
|
|
48
48
|
import AbCodeBlockCopy from './copy';
|
|
49
|
+
// โจ๏ธ 0.6.0: demotes Shiki's <pre tabindex="0"> inside a trustedHtml block after hydration (one tab stop)
|
|
50
|
+
import AbCodeBlockFocus from './focus';
|
|
49
51
|
// ๐จ styles
|
|
50
52
|
import styles from './styles.module.css';
|
|
51
53
|
|
|
52
|
-
|
|
53
|
-
|
|
54
|
+
/**
|
|
55
|
+
* ๐จ risky patterns in a `trustedHtml` string (dev warning only, NOT a sanitizer):
|
|
56
|
+
* <script, an onโฆ= event handler, javascript:, <iframe, srcdoc
|
|
57
|
+
*/
|
|
58
|
+
const AB_RISKY_HTML: ReadonlyArray<[string, RegExp]> = [
|
|
59
|
+
['<script', /<script\b/i], // ๐ inline script
|
|
60
|
+
['onโฆ= handler', /\son[a-z]+\s*=/i], // ๐ฑ๏ธ onclick=, onerror=, โฆ
|
|
61
|
+
['javascript:', /javascript\s*:/i], // ๐ script URL
|
|
62
|
+
['<iframe', /<iframe\b/i], // ๐ช embedded frame
|
|
63
|
+
['srcdoc', /\bsrcdoc\b/i], // ๐ inline frame document
|
|
64
|
+
];
|
|
65
|
+
|
|
66
|
+
/** โ ๏ธ dev only: warn when `trustedHtml` looks like it carries script (silent in production) */
|
|
67
|
+
export function warnAbRiskyHtml(html: string, where = 'AbCodeBlock'): void {
|
|
68
|
+
if (process.env.NODE_ENV === 'production') return; // ๐คซ never in production
|
|
69
|
+
const hits = AB_RISKY_HTML.filter(([, re]) => re.test(html)).map(([n]) => n); // ๐
|
|
70
|
+
if (hits.length) console.warn(`[${where}] trustedHtml contains ${hits.join(', ')}. It is injected without sanitizing: only pass HTML you render yourself (e.g. Shiki), never user input. Prefer \`highlighted\`/children.`); // โ ๏ธ
|
|
71
|
+
}
|
|
54
72
|
|
|
55
73
|
/**
|
|
56
|
-
* โจ๏ธ 0.
|
|
57
|
-
*
|
|
74
|
+
* โจ๏ธ 0.6.0: ONE tab stop per block. The wrapper (`code-block-code`) is the horizontal scroller and the focus
|
|
75
|
+
* target (arrow keys scroll long lines), so a direct <pre> child loses an auto/Shiki `tabIndex={0}` (it would be
|
|
76
|
+
* a second stop). An author's explicit negative tabIndex and any aria-label on the <pre> are kept.
|
|
58
77
|
*/
|
|
59
|
-
function
|
|
78
|
+
function withAbSingleStopPre(children: ReactNode): ReactNode {
|
|
60
79
|
return Children.map(children, (c) => {
|
|
61
80
|
if (!isValidElement<Record<string, unknown>>(c) || c.type !== 'pre') return c; // ๐
only a direct <pre>
|
|
62
|
-
const
|
|
63
|
-
if (
|
|
64
|
-
|
|
65
|
-
return Object.keys(extra).length ? cloneElement(c, extra) : c; // โ
|
|
66
|
-
});
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
/** ๐งพ the same for an `html` string: patch the FIRST <pre โฆ> tag only */
|
|
70
|
-
function withAbFocusablePreHtml(html: string, name?: string): string {
|
|
71
|
-
return html.replace(/<pre\b([^>]*)>/i, (tag, attrs: string) => {
|
|
72
|
-
let a = attrs; // ๐งฉ
|
|
73
|
-
if (!/\stabindex\s*=/i.test(a)) a += ' tabindex="0"'; // โจ๏ธ Shiki already has one โ untouched
|
|
74
|
-
if (name && !/\saria-label(ledby)?\s*=/i.test(a)) a += ` aria-label="${escAttr(name)}"`; // ๐ท๏ธ
|
|
75
|
-
return `<pre${a}>`; // โ
|
|
81
|
+
const t = c.props.tabIndex ?? c.props.tabindex; // ๐ Shiki sets 0
|
|
82
|
+
if (t == null || Number(t) < 0) return c; // โ
nothing to drop (or an author's -1)
|
|
83
|
+
return cloneElement(c, { tabIndex: undefined, tabindex: undefined }); // โ๏ธ the wrapper is the stop now
|
|
76
84
|
});
|
|
77
85
|
}
|
|
78
86
|
|
|
79
87
|
/** โ๏ธ props */
|
|
80
88
|
export interface AbCodeBlockProps {
|
|
81
89
|
children?: ReactNode; // ๐๏ธ Shiki-rendered (or plain) <pre><code>โฆ</code></pre>, e.g. from rehype-pretty-code in MDX
|
|
82
|
-
|
|
90
|
+
/**
|
|
91
|
+
* ๐งพ OR a pre-rendered HTML string (Shiki `codeToHtml`). โ ๏ธ Injected via dangerouslySetInnerHTML WITHOUT
|
|
92
|
+
* sanitizing: it MUST be trusted (you render it at build/server time), never user input. Prefer children.
|
|
93
|
+
*/
|
|
94
|
+
trustedHtml?: string;
|
|
83
95
|
code?: string; // ๐ the raw source to copy (best). Without it the button copies the rendered <pre>'s text
|
|
84
96
|
title?: ReactNode; // ๐ท๏ธ a caption in the header bar (e.g. "Install")
|
|
85
97
|
filename?: string; // ๐ a file name in the header bar (mono), e.g. "app/page.tsx"
|
|
@@ -92,15 +104,16 @@ export interface AbCodeBlockProps {
|
|
|
92
104
|
|
|
93
105
|
/**
|
|
94
106
|
* ๐ป AbCodeBlock โ a server-rendered code block for MDX docs: an optional header (title / filename ยท language),
|
|
95
|
-
* the highlighted code (children or
|
|
107
|
+
* the highlighted code (children or a `trustedHtml` string, both from Shiki), and a small client copy button. It is a
|
|
96
108
|
* <figure> (with a <figcaption> when there is a header), so the caption names the code for assistive tech; the
|
|
97
|
-
*
|
|
109
|
+
* scroller wrapper is the single focusable, named tab stop, so keyboard users can scroll long lines with the arrows.
|
|
98
110
|
*/
|
|
99
|
-
const AbCodeBlock = ({ children,
|
|
111
|
+
const AbCodeBlock = ({ children, trustedHtml, code, title, filename, language, copyLabel = 'Copy code', copiedLabel = 'Copied', copy = true, className }: AbCodeBlockProps): ReactElement => {
|
|
100
112
|
const hasHeader = title != null || !!filename || !!language; // ๐ท๏ธ a header bar?
|
|
101
113
|
const caption = (title ?? filename) != null; // ๐ฌ a visible name for the figure
|
|
102
114
|
// ๐ท๏ธ the scroller's name: the title (if text), else the filename, else "<language> code"
|
|
103
115
|
const preName = typeof title === 'string' ? title : filename || (language ? `${language} code` : undefined);
|
|
116
|
+
if (trustedHtml != null) warnAbRiskyHtml(trustedHtml); // โ ๏ธ dev-only check
|
|
104
117
|
return (
|
|
105
118
|
<figure
|
|
106
119
|
className={clsx('AbCodeBlock', 'ab-prose-none', styles.abCodeBlock, className)} // ๐จ (opts out of theme .ab-prose)
|
|
@@ -116,9 +129,23 @@ const AbCodeBlock = ({ children, html, code, title, filename, language, copyLabe
|
|
|
116
129
|
</figcaption>
|
|
117
130
|
)}
|
|
118
131
|
<div className={styles.abCodeBlockBody}>
|
|
119
|
-
{
|
|
120
|
-
? <div
|
|
121
|
-
|
|
132
|
+
{trustedHtml != null
|
|
133
|
+
? <div
|
|
134
|
+
className={styles.abCodeBlockCode} // โ๏ธ 0.6.0: the scroller (the inner <pre> is overflow: visible)
|
|
135
|
+
data-ab-part="code-block-code"
|
|
136
|
+
tabIndex={0} // โจ๏ธ the ONE tab stop: arrow keys scroll long lines (no regex patching of the HTML)
|
|
137
|
+
role="group" // โฟ a named, focusable group (aria-label needs a role)
|
|
138
|
+
aria-label={preName} // ๐ท๏ธ
|
|
139
|
+
dangerouslySetInnerHTML={{ __html: trustedHtml }} // ๐งพ trusted Shiki string, injected as-is
|
|
140
|
+
/>
|
|
141
|
+
: <div
|
|
142
|
+
className={styles.abCodeBlockCode} // โ๏ธ the scroller
|
|
143
|
+
data-ab-part="code-block-code"
|
|
144
|
+
tabIndex={0} // โจ๏ธ the ONE tab stop
|
|
145
|
+
role="group" // โฟ
|
|
146
|
+
aria-label={preName} // ๐ท๏ธ
|
|
147
|
+
>{withAbSingleStopPre(children) /* ๐๏ธ Shiki children, minus their own tab stop */}</div>}
|
|
148
|
+
{trustedHtml != null && <AbCodeBlockFocus /> /* โจ๏ธ client island: Shiki's leftover <pre tabindex> โ -1 */}
|
|
122
149
|
{copy && <AbCodeBlockCopy code={code} label={copyLabel} copiedLabel={copiedLabel} /> /* ๐ client island */}
|
|
123
150
|
</div>
|
|
124
151
|
</figure>
|
|
@@ -44,7 +44,7 @@
|
|
|
44
44
|
border-radius: var(--ab-radius-code, 12px); /* ๐ข */
|
|
45
45
|
background: var(--ab-color-code-surface, #231a14); /* ๐จ */
|
|
46
46
|
color: var(--ab-color-on-code-surface, #f4ece5); /* ๐๏ธ */
|
|
47
|
-
color-scheme: dark; /* ๐ 0.4.1 (
|
|
47
|
+
color-scheme: dark; /* ๐ 0.4.1 (0.2.24, gap 3): scrollbars, selection + the copy button match the dark surface in every page scheme */
|
|
48
48
|
}
|
|
49
49
|
/* ๐ท๏ธ header: title ยท filename ยท language badge */
|
|
50
50
|
.abCodeBlockHead { display: flex; align-items: center; gap: 8px; min-height: 36px; padding: 0 12px 0 16px; border-bottom: 1px solid rgb(255 255 255 / 0.08); font: 500 12.5px/1.2 var(--ab-font-body, system-ui, sans-serif); } /* ๐ */
|
|
@@ -53,8 +53,9 @@
|
|
|
53
53
|
.abCodeBlockLang { margin-inline-start: auto; padding: 2px 6px; border-radius: 4px; background: rgb(255 255 255 / 0.08); font: 600 11px/1 var(--ab-font-code, ui-monospace, monospace); text-transform: lowercase; } /* ๐ค badge */
|
|
54
54
|
/* ๐งฑ body: the code + the copy button in its top-end corner */
|
|
55
55
|
.abCodeBlockBody { position: relative; } /* ๐ */
|
|
56
|
-
.abCodeBlockCode :
|
|
57
|
-
.abCodeBlockCode
|
|
56
|
+
.abCodeBlockCode { overflow-x: auto; margin-inline-end: 48px; } /* โ๏ธ 0.6.0: the WRAPPER is the scroller + the one tab stop; ๐ its end stops 48px short, so long lines (390px phones too) never scroll UNDER the 44px copy button */
|
|
57
|
+
.abCodeBlockCode:focus-visible { outline: 2px solid var(--ab-color-accent, #a67c52); outline-offset: -2px; } /* โฟ */
|
|
58
|
+
.abCodeBlockCode :where(pre) { margin: 0; padding: 14px 8px 14px 16px; overflow: visible; inline-size: max-content; min-inline-size: 100%; box-sizing: border-box; background: transparent !important; font: 13.5px/1.6 var(--ab-font-code, ui-monospace, monospace); } /* ๐ (end room comes from the scroller's gutter) grows with its longest line, the wrapper scrolls it; Shiki's inline bg yields to ours */
|
|
58
59
|
.abCodeBlockCode :where(code) { font: inherit; } /* ๐ค */
|
|
59
60
|
.abCodeBlockCopy { position: absolute; inset-block-start: 4px; inset-inline-end: 4px; color: inherit; } /* ๐ 44px button (AbIconButton) */
|
|
60
61
|
.srOnly { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; } /* ๐ถ๏ธ */
|
|
@@ -24,7 +24,7 @@
|
|
|
24
24
|
* SOFTWARE.
|
|
25
25
|
*
|
|
26
26
|
* @project: ab-nextjs-components
|
|
27
|
-
* @name: AbContentTabs + AbContentTab (0.3.4,
|
|
27
|
+
* @name: AbContentTabs + AbContentTab (0.3.4, QA 0.2.24 MDX docs)
|
|
28
28
|
* @file: ab-content-tabs/index.tsx
|
|
29
29
|
* @type: Client component
|
|
30
30
|
* @authors: Abraham Ukachi <abrahamukachi@gmail.com>
|
|
@@ -43,12 +43,18 @@
|
|
|
43
43
|
'use client';
|
|
44
44
|
|
|
45
45
|
// โ๏ธ React
|
|
46
|
-
import { Children, isValidElement, useId, useRef, useState, type KeyboardEvent, type ReactElement, type ReactNode } from 'react';
|
|
46
|
+
import { Children, isValidElement, useEffect, useId, useRef, useState, type KeyboardEvent, type ReactElement, type ReactNode } from 'react';
|
|
47
47
|
// ๐งต classes
|
|
48
48
|
import clsx from 'clsx';
|
|
49
49
|
// ๐จ styles
|
|
50
50
|
import styles from './styles.module.css';
|
|
51
51
|
|
|
52
|
+
/**
|
|
53
|
+
* โจ๏ธ 0.6.0: what counts as "already focusable" inside a panel. A panel that holds one of these is left OUT of
|
|
54
|
+
* the tab order (its content is the stop, e.g. a code block's scroller); an empty / text-only panel stays tabIndex 0.
|
|
55
|
+
*/
|
|
56
|
+
export const AB_FOCUSABLE_SELECTOR = 'a[href], button, input, select, textarea, [tabindex]:not([tabindex="-1"]), [contenteditable]:not([contenteditable="false"]), summary';
|
|
57
|
+
|
|
52
58
|
/** โ๏ธ one tab (a marker element: AbContentTabs reads its props, it renders only its children) */
|
|
53
59
|
export interface AbContentTabProps {
|
|
54
60
|
label: ReactNode; // ๐ท๏ธ the tab's text, e.g. "pnpm"
|
|
@@ -85,6 +91,21 @@ const AbContentTabs = ({ children, label, defaultValue, onChange, className }: A
|
|
|
85
91
|
const [selected, setSelected] = useState(() => (defaultValue && values.includes(defaultValue) ? defaultValue : values[0])); // ๐ฏ
|
|
86
92
|
const current = values.includes(selected) ? selected : values[0]; // ๐ children changed
|
|
87
93
|
const refs = useRef<Array<HTMLButtonElement | null>>([]); // ๐ to move focus
|
|
94
|
+
const panels = useRef<Array<HTMLDivElement | null>>([]); // ๐ the tabpanels (focusable-content check)
|
|
95
|
+
// โจ๏ธ 0.6.0: which panels already contain a focusable element. SSR + the first client render say "none"
|
|
96
|
+
// (every panel tabIndex 0, the APG-safe no-JS default), so hydration matches; the effect then refines it.
|
|
97
|
+
const [hasFocusable, setHasFocusable] = useState<boolean[]>([]);
|
|
98
|
+
useEffect(() => {
|
|
99
|
+
const check = () => {
|
|
100
|
+
const next = panels.current.slice(0, tabs.length).map((el) => !!el?.querySelector(AB_FOCUSABLE_SELECTOR)); // ๐
|
|
101
|
+
setHasFocusable((prev) => (prev.length === next.length && prev.every((v, k) => v === next[k]) ? prev : next)); // ๐ง no-op when unchanged
|
|
102
|
+
};
|
|
103
|
+
check(); // ๐ after mount
|
|
104
|
+
if (typeof MutationObserver === 'undefined') return; // ๐ very old engines: the mount check only
|
|
105
|
+
const mo = new MutationObserver(check); // ๐ content changes (MDX, islands, hydration fixes)
|
|
106
|
+
panels.current.forEach((el) => el && mo.observe(el, { childList: true, subtree: true, attributes: true, attributeFilter: ['tabindex', 'href', 'contenteditable', 'disabled'] }));
|
|
107
|
+
return () => mo.disconnect(); // ๐งน
|
|
108
|
+
}, [tabs.length]);
|
|
88
109
|
const select = (v: string) => { setSelected(v); onChange?.(v); }; // โ
|
|
89
110
|
// โจ๏ธ roving keys on the tablist
|
|
90
111
|
const onKeyDown = (e: KeyboardEvent<HTMLDivElement>) => {
|
|
@@ -128,7 +149,8 @@ const AbContentTabs = ({ children, label, defaultValue, onChange, className }: A
|
|
|
128
149
|
id={`${id}-panel-${i}`} // ๐
|
|
129
150
|
aria-labelledby={`${id}-tab-${i}`} // ๐
|
|
130
151
|
hidden={values[i] !== current} // ๐ inactive
|
|
131
|
-
|
|
152
|
+
ref={(el) => { panels.current[i] = el; }} // ๐
|
|
153
|
+
tabIndex={hasFocusable[i] ? undefined : 0} // โจ๏ธ 0.6.0 (APG): a stop ONLY when nothing inside is focusable
|
|
132
154
|
className={styles.abContentTabsPanel} // ๐จ
|
|
133
155
|
data-ab-part="content-tab-panel" // ๐๏ธ
|
|
134
156
|
>
|
package/ab-demo-box/index.tsx
CHANGED
|
@@ -6,34 +6,72 @@
|
|
|
6
6
|
* Copyright (c) 2026 Abraham Ukachi. The abElements Project.
|
|
7
7
|
*
|
|
8
8
|
* @project: ab-nextjs-components
|
|
9
|
-
* @name: AbDemoBox
|
|
9
|
+
* @name: AbDemoBox (port of lyd-demo-box; 0.6.0: the G16 preview scope)
|
|
10
10
|
* @file: ab-demo-box/index.tsx
|
|
11
|
+
* @type: Server-safe component (no 'use client', no hooks)
|
|
11
12
|
* @authors: Abraham Ukachi <abrahamukachi@gmail.com>
|
|
13
|
+
*
|
|
14
|
+
* Example usage:
|
|
15
|
+
* 1+|> <AbDemoBox label="Button preview" scheme="dark"><AbButton label="Save" /></AbDemoBox>
|
|
12
16
|
*/
|
|
13
17
|
|
|
14
|
-
|
|
18
|
+
/*
|
|
19
|
+
* !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
|
|
20
|
+
* MOTTO: We'll always do more ๐!!!
|
|
21
|
+
* !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
|
|
22
|
+
*/
|
|
15
23
|
|
|
24
|
+
// โ๏ธ React (forwardRef works in server components too)
|
|
16
25
|
import type { ReactElement, ReactNode } from 'react';
|
|
17
26
|
import { forwardRef } from 'react';
|
|
27
|
+
// ๐งต classes
|
|
18
28
|
import clsx from 'clsx';
|
|
29
|
+
// ๐จ styles
|
|
19
30
|
import styles from './styles.module.css';
|
|
20
31
|
|
|
32
|
+
/** ๐ the preview's colour scheme: follow the page, or force one (theme `[data-theme]` tokens re-apply inside) */
|
|
33
|
+
export type AbDemoBoxScheme = 'inherit' | 'light' | 'dark';
|
|
34
|
+
|
|
35
|
+
/** โ๏ธ props */
|
|
21
36
|
export interface AbDemoBoxProps {
|
|
22
|
-
className?: string;
|
|
23
|
-
hidden?: boolean;
|
|
24
|
-
children?: ReactNode;
|
|
37
|
+
className?: string; // ๐ท๏ธ
|
|
38
|
+
hidden?: boolean; // ๐
|
|
39
|
+
children?: ReactNode; // ๐งช the live preview: real JSX (package components), never eval'd strings
|
|
40
|
+
label?: string; // โฟ 0.6.0: names the preview as a region, e.g. "AbButton preview" (no role without it)
|
|
41
|
+
scheme?: AbDemoBoxScheme; // ๐ 0.6.0: default 'inherit'
|
|
42
|
+
align?: 'center' | 'start' | 'stretch'; // ๐ 0.6.0: how the content sits in the box (default 'center')
|
|
25
43
|
}
|
|
26
44
|
|
|
45
|
+
/**
|
|
46
|
+
* ๐งช AbDemoBox โ the G16 **preview scope**: an isolated surface for a live component preview.
|
|
47
|
+
*
|
|
48
|
+
* - ๐ `scheme` forces light / dark through the theme's `[data-theme]` tokens, with matching `color-scheme`.
|
|
49
|
+
* - ๐ฆ `contain: layout paint` + `isolation: isolate`: fixed / absolute children (balloons, drawers) are positioned
|
|
50
|
+
* and clipped by the box, and z-indexes can't climb over the page. AbDrawer hosts its layer here (any scope).
|
|
51
|
+
* - ๐งฑ its own text + background from the theme tokens, so the page's prose styles don't leak in (`ab-prose-none`).
|
|
52
|
+
* - โฟ with `label` it is a named `role="region"`. No motion (all motion lives in ab-nextjs-animations).
|
|
53
|
+
*/
|
|
27
54
|
const AbDemoBox = forwardRef<HTMLDivElement, AbDemoBoxProps>(function AbDemoBox(
|
|
28
|
-
{ className, hidden = false, children },
|
|
55
|
+
{ className, hidden = false, children, label, scheme = 'inherit', align = 'center' },
|
|
29
56
|
ref,
|
|
30
57
|
): ReactElement {
|
|
31
58
|
return (
|
|
32
|
-
<div
|
|
59
|
+
<div
|
|
60
|
+
ref={ref}
|
|
61
|
+
hidden={hidden}
|
|
62
|
+
className={clsx('AbDemoBox', 'ab-prose-none', styles.abDemoBox, className)} // ๐จ + opt out of theme prose
|
|
63
|
+
data-ab-part="demo-box" // ๐๏ธ
|
|
64
|
+
data-ab-preview-scope="" // ๐ฆ drawers + portals inside stay inside (AbDrawer reads it)
|
|
65
|
+
data-theme={scheme === 'inherit' ? undefined : scheme} // ๐ theme tokens re-declared on this box
|
|
66
|
+
data-align={align === 'center' ? undefined : align} // ๐
|
|
67
|
+
role={label ? 'region' : undefined} // โฟ a landmark only when it has a name
|
|
68
|
+
aria-label={label} // ๐ท๏ธ
|
|
69
|
+
>
|
|
33
70
|
{children}
|
|
34
71
|
</div>
|
|
35
72
|
);
|
|
36
73
|
});
|
|
37
74
|
|
|
75
|
+
// ๐ฆ exports
|
|
38
76
|
export default AbDemoBox;
|
|
39
77
|
export { AbDemoBox };
|
|
@@ -30,16 +30,28 @@
|
|
|
30
30
|
* @authors: Abraham Ukachi <abrahamukachi@gmail.com>
|
|
31
31
|
*/
|
|
32
32
|
|
|
33
|
+
/* ๐งช 0.6.0 (G16): the preview scope. Theme tokens first, the old M3 names as fallbacks */
|
|
33
34
|
.abDemoBox {
|
|
34
|
-
position: relative;
|
|
35
|
+
position: relative; /* ๐ the drawer layer + absolute children anchor here */
|
|
36
|
+
contain: layout paint; /* ๐ฆ a containing block for position: fixed too, and clips paint to the box */
|
|
37
|
+
isolation: isolate; /* ๐ฅ z-indexes stay inside */
|
|
35
38
|
display: flex;
|
|
36
39
|
flex-direction: column;
|
|
40
|
+
align-items: center; /* ๐ default: centred */
|
|
41
|
+
justify-content: center;
|
|
37
42
|
gap: 1rem;
|
|
43
|
+
min-block-size: 160px; /* ๐ room for a drawer / menu demo */
|
|
38
44
|
padding: 1.25rem;
|
|
39
|
-
border-radius:
|
|
40
|
-
border: 1px solid color-mix(in srgb, currentColor 12%, transparent);
|
|
41
|
-
background:
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
+
border-radius: var(--ab-radius-code, 12px); /* ๐ข same corner as AbCodeBlock */
|
|
46
|
+
border: 1px solid var(--ab-color-border, color-mix(in srgb, currentColor 12%, transparent)); /* ๐ฒ */
|
|
47
|
+
background: var(--ab-color-card, var(--ab-surface, #fff)); /* ๐ its own surface */
|
|
48
|
+
color: var(--ab-color-on-background, var(--ab-color-on-surface, inherit)); /* ๐๏ธ its own text colour */
|
|
49
|
+
font-family: var(--ab-font-body, system-ui, sans-serif); /* ๐ค the page's prose font size doesn't leak in */
|
|
50
|
+
font-size: 1rem;
|
|
51
|
+
line-height: 1.5;
|
|
52
|
+
overflow: hidden; /* โ๏ธ */
|
|
45
53
|
}
|
|
54
|
+
.abDemoBox[data-theme='light'] { color-scheme: light; } /* ๐ native UI follows (also without the theme) */
|
|
55
|
+
.abDemoBox[data-theme='dark'] { color-scheme: dark; } /* ๐ */
|
|
56
|
+
.abDemoBox[data-align='start'] { align-items: flex-start; justify-content: flex-start; } /* ๐ */
|
|
57
|
+
.abDemoBox[data-align='stretch'] { align-items: stretch; justify-content: flex-start; } /* ๐ */
|
package/ab-demo-code/index.tsx
CHANGED
|
@@ -6,58 +6,62 @@
|
|
|
6
6
|
* Copyright (c) 2026 Abraham Ukachi. The abElements Project.
|
|
7
7
|
*
|
|
8
8
|
* @project: ab-nextjs-components
|
|
9
|
-
* @name: AbDemoCode
|
|
9
|
+
* @name: AbDemoCode (port of lyd-demo-code; 0.6.0: built on AbCodeBlock)
|
|
10
10
|
* @file: ab-demo-code/index.tsx
|
|
11
|
+
* @type: Server-safe component (the copy button is AbCodeBlock's client island)
|
|
11
12
|
* @authors: Abraham Ukachi <abrahamukachi@gmail.com>
|
|
13
|
+
*
|
|
14
|
+
* Example usage:
|
|
15
|
+
* 1+|> <AbDemoCode language="tsx" code={`<AbButton label="Save" />`} />
|
|
12
16
|
*/
|
|
13
17
|
|
|
14
|
-
|
|
18
|
+
/*
|
|
19
|
+
* !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
|
|
20
|
+
* MOTTO: We'll always do more ๐!!!
|
|
21
|
+
* !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
|
|
22
|
+
*/
|
|
15
23
|
|
|
16
|
-
|
|
17
|
-
import {
|
|
24
|
+
// โ๏ธ React
|
|
25
|
+
import type { ReactElement, ReactNode } from 'react';
|
|
26
|
+
import { forwardRef } from 'react';
|
|
27
|
+
// ๐งต classes
|
|
18
28
|
import clsx from 'clsx';
|
|
29
|
+
// ๐ป the docs code block (header, focusable <pre>, AbIcon copy button with a polite "Copied")
|
|
30
|
+
import AbCodeBlock from '../ab-code-block';
|
|
31
|
+
// ๐จ styles
|
|
19
32
|
import styles from './styles.module.css';
|
|
20
33
|
|
|
34
|
+
/** โ๏ธ props (the 0.1.x shape, plus the AbCodeBlock options a preview pair needs) */
|
|
21
35
|
export interface AbDemoCodeProps {
|
|
22
|
-
className?: string;
|
|
23
|
-
hidden?: boolean;
|
|
24
|
-
language?: 'tsx' | 'css' | 'ts' | 'js' | string;
|
|
25
|
-
code: string;
|
|
36
|
+
className?: string; // ๐ท๏ธ
|
|
37
|
+
hidden?: boolean; // ๐
|
|
38
|
+
language?: 'tsx' | 'css' | 'ts' | 'js' | string; // ๐ค default 'tsx'
|
|
39
|
+
code: string; // ๐ the raw source (shown when there is no `trustedHtml` / `children`, always what Copy copies)
|
|
40
|
+
trustedHtml?: string; // ๐งพ 0.6.0: Shiki `codeToHtml` output, โ ๏ธ NOT sanitized: trusted HTML only, never user input (prefer children)
|
|
41
|
+
children?: ReactNode; // ๐๏ธ 0.6.0: OR an already highlighted <pre> (e.g. an MDX fenced block)
|
|
42
|
+
filename?: string; // ๐ 0.6.0
|
|
43
|
+
copyLabel?: string; // โฟ 0.6.0 (default "Copy code")
|
|
44
|
+
copiedLabel?: string; // โ
0.6.0 (default "Copied")
|
|
26
45
|
}
|
|
27
46
|
|
|
47
|
+
/**
|
|
48
|
+
* ๐ป AbDemoCode โ the source half of a preview pair. Since 0.6.0 it is an AbCodeBlock, so it shares the
|
|
49
|
+
* highlighted rendering, the named + focusable <pre> and the SVG copy button (no icon font, no local timer).
|
|
50
|
+
* The plain fallback is a <pre><code> of `code` (React escapes it; nothing is ever evaluated).
|
|
51
|
+
*/
|
|
28
52
|
const AbDemoCode = forwardRef<HTMLDivElement, AbDemoCodeProps>(function AbDemoCode(
|
|
29
|
-
{ className, hidden = false, language = 'tsx', code },
|
|
53
|
+
{ className, hidden = false, language = 'tsx', code, trustedHtml, children, filename, copyLabel, copiedLabel },
|
|
30
54
|
ref,
|
|
31
55
|
): ReactElement {
|
|
32
|
-
const [copied, setCopied] = useState(false);
|
|
33
|
-
|
|
34
|
-
const copy = async () => {
|
|
35
|
-
try {
|
|
36
|
-
await navigator.clipboard.writeText(code);
|
|
37
|
-
setCopied(true);
|
|
38
|
-
window.setTimeout(() => setCopied(false), 1500);
|
|
39
|
-
} catch {
|
|
40
|
-
setCopied(false);
|
|
41
|
-
}
|
|
42
|
-
};
|
|
43
|
-
|
|
44
56
|
return (
|
|
45
|
-
<div ref={ref} hidden={hidden} className={clsx('AbDemoCode', styles.abDemoCode, className)}>
|
|
46
|
-
<
|
|
47
|
-
<
|
|
48
|
-
|
|
49
|
-
<span className="material-symbols-rounded" aria-hidden style={{ fontSize: 16 }}>
|
|
50
|
-
{copied ? 'check' : 'content_copy'}
|
|
51
|
-
</span>
|
|
52
|
-
{copied ? 'Copied' : 'Copy'}
|
|
53
|
-
</button>
|
|
54
|
-
</div>
|
|
55
|
-
<pre className={styles.abDemoCodePre}>
|
|
56
|
-
<code className={styles.abDemoCodeCode}>{code}</code>
|
|
57
|
-
</pre>
|
|
57
|
+
<div ref={ref} hidden={hidden} className={clsx('AbDemoCode', styles.abDemoCode, className)} data-ab-part="demo-code">
|
|
58
|
+
<AbCodeBlock code={code} trustedHtml={trustedHtml} language={language} filename={filename} copyLabel={copyLabel} copiedLabel={copiedLabel}>
|
|
59
|
+
{children ?? <pre><code>{code}</code></pre> /* ๐งพ plain, escaped */}
|
|
60
|
+
</AbCodeBlock>
|
|
58
61
|
</div>
|
|
59
62
|
);
|
|
60
63
|
});
|
|
61
64
|
|
|
65
|
+
// ๐ฆ exports
|
|
62
66
|
export default AbDemoCode;
|
|
63
67
|
export { AbDemoCode };
|
|
@@ -30,44 +30,6 @@
|
|
|
30
30
|
* @authors: Abraham Ukachi <abrahamukachi@gmail.com>
|
|
31
31
|
*/
|
|
32
32
|
|
|
33
|
-
.
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
overflow: hidden;
|
|
37
|
-
background: #1e1e2e;
|
|
38
|
-
color: #cdd6f4;
|
|
39
|
-
font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
|
|
40
|
-
font-size: 0.8125rem;
|
|
41
|
-
line-height: 1.5;
|
|
42
|
-
}
|
|
43
|
-
.abDemoCodeHeader {
|
|
44
|
-
display: flex;
|
|
45
|
-
align-items: center;
|
|
46
|
-
justify-content: space-between;
|
|
47
|
-
gap: 0.5rem;
|
|
48
|
-
padding: 0.4rem 0.75rem;
|
|
49
|
-
background: color-mix(in srgb, #000 25%, transparent);
|
|
50
|
-
font-size: 0.7rem;
|
|
51
|
-
text-transform: uppercase;
|
|
52
|
-
letter-spacing: 0.06em;
|
|
53
|
-
opacity: 0.85;
|
|
54
|
-
}
|
|
55
|
-
.abDemoCodeCopy {
|
|
56
|
-
border: none;
|
|
57
|
-
background: transparent;
|
|
58
|
-
color: inherit;
|
|
59
|
-
cursor: pointer;
|
|
60
|
-
display: inline-flex;
|
|
61
|
-
align-items: center;
|
|
62
|
-
gap: 0.25rem;
|
|
63
|
-
font: inherit;
|
|
64
|
-
opacity: 0.8;
|
|
65
|
-
}
|
|
66
|
-
.abDemoCodeCopy:hover { opacity: 1; }
|
|
67
|
-
.abDemoCodePre {
|
|
68
|
-
margin: 0;
|
|
69
|
-
padding: 0.85rem 1rem 1rem;
|
|
70
|
-
overflow: auto;
|
|
71
|
-
max-height: 24rem;
|
|
72
|
-
}
|
|
73
|
-
.abDemoCodeCode { white-space: pre; }
|
|
33
|
+
/* ๐ป 0.6.0: AbCodeBlock draws the block; this wrapper only drops its bottom margin inside a preview pair */
|
|
34
|
+
.abDemoCode { min-inline-size: 0; } /* โ๏ธ long lines scroll in the <pre>, never widen the page */
|
|
35
|
+
.abDemoCode > :global(.AbCodeBlock) { margin: 0; } /* โ๏ธ */
|
package/ab-doc-pager/index.tsx
CHANGED
|
@@ -24,7 +24,7 @@
|
|
|
24
24
|
* SOFTWARE.
|
|
25
25
|
*
|
|
26
26
|
* @project: ab-nextjs-components
|
|
27
|
-
* @name: AbDocPager (0.3.4,
|
|
27
|
+
* @name: AbDocPager (0.3.4, QA 0.2.24 MDX docs)
|
|
28
28
|
* @file: ab-doc-pager/index.tsx
|
|
29
29
|
* @type: Server-safe component (links via AbLinkProvider)
|
|
30
30
|
* @authors: Abraham Ukachi <abrahamukachi@gmail.com>
|
package/ab-drawer/gestures.ts
CHANGED
|
@@ -36,7 +36,7 @@
|
|
|
36
36
|
* !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
|
|
37
37
|
*/
|
|
38
38
|
|
|
39
|
-
// ๐ค drawers v2 (
|
|
39
|
+
// ๐ค drawers v2 (01:22): the thresholds and decisions behind every drawer swipe, as pure functions,
|
|
40
40
|
// so the rules are unit-tested without a DOM and the components only feed them numbers.
|
|
41
41
|
|
|
42
42
|
/** ๐๏ธ the spec numbers (drawer-spec.md "Gestures" + "Edge zones") */
|
package/ab-drawer/index.tsx
CHANGED
|
@@ -90,7 +90,7 @@ export interface AbDrawerProps {
|
|
|
90
90
|
closeLabel?: string; // ๐ default "Close"
|
|
91
91
|
noJsFallback?: boolean; // ๐งฉ D41: without JS, render the content in flow (default `true`)
|
|
92
92
|
initialFocus?: 'first' | 'panel' | (string & {}); // ๐ฏ on open: the first control (default), the panel itself, or (0.2.0) a CSS selector inside the panel, e.g. `[role=radio][aria-checked=true]`
|
|
93
|
-
// ๐ 0.2.0 drawers v2 (
|
|
93
|
+
// ๐ 0.2.0 drawers v2 (01:22): all opt-in, the defaults keep the old drawer
|
|
94
94
|
tier?: AbDrawerTier; // ๐ฅ stacking tier: 'aside' (z 60) < 'nav' (61) < 'sheet' (62)
|
|
95
95
|
swipe?: boolean; // ๐ค side drawers: swipe the sheet back toward its edge to close (30% of the width or โฅ 0.5px/ms)
|
|
96
96
|
snapPoints?: boolean; // ๐งฒ bottom only, below 768px: snaps at 70% (S1) and full height (S2) with a handle; gestures per the spec
|
|
@@ -122,9 +122,17 @@ const SCOPE_SELECTOR: Record<AbDrawerScope, string> = {
|
|
|
122
122
|
*/
|
|
123
123
|
export function getAbDrawerHost(scope: AbDrawerScope, from?: Element | null): HTMLElement {
|
|
124
124
|
const sel = SCOPE_SELECTOR[scope]; // ๐
|
|
125
|
-
|
|
125
|
+
const own = from?.closest<HTMLElement>(sel) ?? null; // ๐ฏ the nearest scope box around the drawer
|
|
126
|
+
// ๐งช 0.6.0 (G16): inside a docs preview (AbDemoBox / AbPreviewCode) the preview box is the app: a drawer never
|
|
127
|
+
// escapes to the real page layout. A scope box that is itself INSIDE the preview (a layout demo) still wins.
|
|
128
|
+
const preview = from?.closest<HTMLElement>(AB_PREVIEW_SCOPE_SELECTOR) ?? null;
|
|
129
|
+
if (preview && (!own || !preview.contains(own))) return preview; // ๐ฆ clipped by the preview
|
|
130
|
+
return own ?? document.querySelector<HTMLElement>(sel) ?? document.body; // ๐ฏ
|
|
126
131
|
}
|
|
127
132
|
|
|
133
|
+
/** ๐งช 0.6.0 (G16): the attribute that marks a preview scope (AbDemoBox sets it); drawers inside stay inside */
|
|
134
|
+
export const AB_PREVIEW_SCOPE_SELECTOR = '[data-ab-preview-scope]';
|
|
135
|
+
|
|
128
136
|
// โฟ everything that can take focus inside the panel
|
|
129
137
|
const FOCUSABLE = 'a[href], button:not([disabled]), input:not([disabled]), select:not([disabled]), textarea:not([disabled]), [tabindex]:not([tabindex="-1"]), [contenteditable="true"]';
|
|
130
138
|
|
|
@@ -146,7 +154,7 @@ const isTopDrawer = (token: symbol): boolean => openStack[openStack.length - 1]
|
|
|
146
154
|
|
|
147
155
|
// โฟ reduced-motion check, read once per open / close on purpose: it only picks the unmount delay for THAT
|
|
148
156
|
// toggle (the slide itself is CSS, which follows the media query live), so a listener would buy nothing
|
|
149
|
-
/** โฉ๏ธ 0.2.1
|
|
157
|
+
/** โฉ๏ธ 0.2.1: where focus goes after a drawer that had no focusable opener closes (an edge swipe): the
|
|
150
158
|
* mobile header's logo link, else AbAppBar's brand link, else AbSidebar's logo row link. `returnFocus` overrides it. */
|
|
151
159
|
export const AB_DRAWER_RETURN_FOCUS = '[data-ab-part="mobile-header"] a[href], [data-ab-part="app-bar-brand"] a[href], [data-ab-part="sidebar-logo"] a[href]';
|
|
152
160
|
const reducedMotion = (): boolean => typeof window !== 'undefined' && typeof window.matchMedia === 'function' && window.matchMedia('(prefers-reduced-motion: reduce)').matches;
|
|
@@ -237,7 +245,7 @@ const AbDrawer = (props: AbDrawerProps): ReactElement => {
|
|
|
237
245
|
const had = opener.current as HTMLElement | null; // โฉ๏ธ
|
|
238
246
|
const usable = had && had !== document.body && had.isConnected ? had : null; // ๐ค a swipe has no opener
|
|
239
247
|
// โฉ๏ธ 0.2.0 fallback: the first VISIBLE match (an app often renders the logo twice, one hidden per breakpoint)
|
|
240
|
-
const pool = Array.from(document.querySelectorAll<HTMLElement>(returnFocus ?? AB_DRAWER_RETURN_FOCUS)).filter((el) => !node.contains(el)); // ๐ท๏ธ 0.2.1
|
|
248
|
+
const pool = Array.from(document.querySelectorAll<HTMLElement>(returnFocus ?? AB_DRAWER_RETURN_FOCUS)).filter((el) => !node.contains(el)); // ๐ท๏ธ 0.2.1: default = the header / brand logo
|
|
241
249
|
const back = usable ?? pool.find((el) => el.getClientRects().length > 0) ?? pool[0] ?? null; // ๐ the visible one, else the first
|
|
242
250
|
// โญ๏ธ a microtask later: the inert cleanup below runs after this one, and an inert opener can't take focus
|
|
243
251
|
queueMicrotask(() => { if (back && back.isConnected && typeof back.focus === 'function') back.focus({ preventScroll: true }); });
|