@ignite-ember/ui-react 0.0.0-stage → 0.2.1
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 +202 -0
- package/NOTICE +5 -0
- package/README.md +260 -2
- package/dist/CopySource.d.ts +4 -0
- package/dist/CopySource.d.ts.map +1 -0
- package/dist/CopySource.js +50 -0
- package/dist/CopySource.js.map +1 -0
- package/dist/DataTable.d.ts +77 -0
- package/dist/DataTable.d.ts.map +1 -0
- package/dist/DataTable.js +45 -0
- package/dist/DataTable.js.map +1 -0
- package/dist/Dialog.d.ts +41 -0
- package/dist/Dialog.d.ts.map +1 -0
- package/dist/Dialog.js +94 -0
- package/dist/Dialog.js.map +1 -0
- package/dist/ErrorBoundary.d.ts +97 -0
- package/dist/ErrorBoundary.d.ts.map +1 -0
- package/dist/ErrorBoundary.js +97 -0
- package/dist/ErrorBoundary.js.map +1 -0
- package/dist/LiveRegion.d.ts +41 -0
- package/dist/LiveRegion.d.ts.map +1 -0
- package/dist/LiveRegion.js +76 -0
- package/dist/LiveRegion.js.map +1 -0
- package/dist/Markdown.d.ts +22 -0
- package/dist/Markdown.d.ts.map +1 -0
- package/dist/Markdown.js +56 -0
- package/dist/Markdown.js.map +1 -0
- package/dist/MarkdownInline.d.ts +53 -0
- package/dist/MarkdownInline.d.ts.map +1 -0
- package/dist/MarkdownInline.js +159 -0
- package/dist/MarkdownInline.js.map +1 -0
- package/dist/MenuIcon.d.ts +60 -0
- package/dist/MenuIcon.d.ts.map +1 -0
- package/dist/MenuIcon.js +102 -0
- package/dist/MenuIcon.js.map +1 -0
- package/dist/Mermaid.d.ts +40 -0
- package/dist/Mermaid.d.ts.map +1 -0
- package/dist/Mermaid.js +121 -0
- package/dist/Mermaid.js.map +1 -0
- package/dist/Monogram.d.ts +46 -0
- package/dist/Monogram.d.ts.map +1 -0
- package/dist/Monogram.js +96 -0
- package/dist/Monogram.js.map +1 -0
- package/dist/OverflowMenu.d.ts +60 -0
- package/dist/OverflowMenu.d.ts.map +1 -0
- package/dist/OverflowMenu.js +149 -0
- package/dist/OverflowMenu.js.map +1 -0
- package/dist/Shell.d.ts +67 -0
- package/dist/Shell.d.ts.map +1 -0
- package/dist/Shell.js +44 -0
- package/dist/Shell.js.map +1 -0
- package/dist/Skeleton.d.ts +62 -0
- package/dist/Skeleton.d.ts.map +1 -0
- package/dist/Skeleton.js +56 -0
- package/dist/Skeleton.js.map +1 -0
- package/dist/Split.d.ts +85 -0
- package/dist/Split.d.ts.map +1 -0
- package/dist/Split.js +156 -0
- package/dist/Split.js.map +1 -0
- package/dist/Tabs.d.ts +77 -0
- package/dist/Tabs.d.ts.map +1 -0
- package/dist/Tabs.js +91 -0
- package/dist/Tabs.js.map +1 -0
- package/dist/Toast.d.ts +98 -0
- package/dist/Toast.d.ts.map +1 -0
- package/dist/Toast.js +129 -0
- package/dist/Toast.js.map +1 -0
- package/dist/Tooltip.d.ts +24 -0
- package/dist/Tooltip.d.ts.map +1 -0
- package/dist/Tooltip.js +166 -0
- package/dist/Tooltip.js.map +1 -0
- package/dist/controls.d.ts +117 -0
- package/dist/controls.d.ts.map +1 -0
- package/dist/controls.js +59 -0
- package/dist/controls.js.map +1 -0
- package/dist/cx.d.ts +3 -0
- package/dist/cx.d.ts.map +1 -0
- package/dist/cx.js +5 -0
- package/dist/cx.js.map +1 -0
- package/dist/fenceInfo.d.ts +26 -0
- package/dist/fenceInfo.d.ts.map +1 -0
- package/dist/fenceInfo.js +22 -0
- package/dist/fenceInfo.js.map +1 -0
- package/dist/formControls.d.ts +143 -0
- package/dist/formControls.d.ts.map +1 -0
- package/dist/formControls.js +108 -0
- package/dist/formControls.js.map +1 -0
- package/dist/index.d.ts +78 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +78 -0
- package/dist/index.js.map +1 -0
- package/dist/layout.d.ts +95 -0
- package/dist/layout.d.ts.map +1 -0
- package/dist/layout.js +93 -0
- package/dist/layout.js.map +1 -0
- package/dist/primitives.d.ts +33 -0
- package/dist/primitives.d.ts.map +1 -0
- package/dist/primitives.js +33 -0
- package/dist/primitives.js.map +1 -0
- package/dist/progress.d.ts +64 -0
- package/dist/progress.d.ts.map +1 -0
- package/dist/progress.js +51 -0
- package/dist/progress.js.map +1 -0
- package/dist/text.d.ts +63 -0
- package/dist/text.d.ts.map +1 -0
- package/dist/text.js +61 -0
- package/dist/text.js.map +1 -0
- package/package.json +56 -4
- package/src/CopySource.tsx +67 -0
- package/src/DataTable.tsx +120 -0
- package/src/Dialog.tsx +158 -0
- package/src/ErrorBoundary.tsx +137 -0
- package/src/LiveRegion.tsx +127 -0
- package/src/Markdown.tsx +75 -0
- package/src/MarkdownInline.tsx +177 -0
- package/src/MenuIcon.tsx +209 -0
- package/src/Mermaid.tsx +144 -0
- package/src/Monogram.tsx +112 -0
- package/src/OverflowMenu.tsx +359 -0
- package/src/Shell.tsx +99 -0
- package/src/Skeleton.tsx +98 -0
- package/src/Split.tsx +267 -0
- package/src/Tabs.tsx +194 -0
- package/src/Toast.tsx +269 -0
- package/src/Tooltip.tsx +213 -0
- package/src/controls.tsx +159 -0
- package/src/cx.ts +4 -0
- package/src/fenceInfo.ts +36 -0
- package/src/formControls.tsx +249 -0
- package/src/index.ts +149 -0
- package/src/layout.tsx +141 -0
- package/src/primitives.tsx +33 -0
- package/src/progress.tsx +129 -0
- package/src/text.tsx +99 -0
package/dist/Dialog.d.ts
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The dialog: the one primitive that is behaviour rather than a box.
|
|
3
|
+
*
|
|
4
|
+
* Part of the primitives; see `primitives.tsx`. **Under the
|
|
5
|
+
* compatibility floor.**
|
|
6
|
+
*/
|
|
7
|
+
import type { HTMLAttributes, ReactNode } from "react";
|
|
8
|
+
/** What a {@link Dialog} takes. */
|
|
9
|
+
export interface DialogProps extends Omit<HTMLAttributes<HTMLDivElement>, "title"> {
|
|
10
|
+
/** Its title. Also the accessible name of the dialog. */
|
|
11
|
+
title: ReactNode;
|
|
12
|
+
/** Shown under the title. A sentence, not a paragraph. */
|
|
13
|
+
sub?: ReactNode;
|
|
14
|
+
/** The body. */
|
|
15
|
+
children?: ReactNode;
|
|
16
|
+
/** The buttons. Rendered in an `Actions` row at the foot. */
|
|
17
|
+
actions?: ReactNode;
|
|
18
|
+
/** Escape, or a click on the backdrop. */
|
|
19
|
+
onClose: () => void;
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* The one primitive here that is behaviour rather than a box.
|
|
23
|
+
*
|
|
24
|
+
* A dialog has to trap focus, close on Escape, restore focus to
|
|
25
|
+
* whatever opened it, and not let a click inside the panel count as a
|
|
26
|
+
* click on the backdrop. Every extension that built its own would get
|
|
27
|
+
* some of that wrong, and the ones they get wrong are the ones only
|
|
28
|
+
* keyboard and screen-reader users notice.
|
|
29
|
+
*
|
|
30
|
+
* @param title — its title, also the accessible name of the dialog.
|
|
31
|
+
* @param sub — shown under the title: a sentence, not a paragraph.
|
|
32
|
+
* @param children — the body.
|
|
33
|
+
* @param actions — the buttons, rendered in an `Actions` row at the
|
|
34
|
+
* foot.
|
|
35
|
+
* @param onClose — escape, or a click on the backdrop.
|
|
36
|
+
* @param className — added to the element's classes, beside the one the
|
|
37
|
+
* theme gives it.
|
|
38
|
+
* @param rest — the remaining props, spread onto the dialog panel.
|
|
39
|
+
*/
|
|
40
|
+
export declare function Dialog({ title, sub, children, actions, onClose, className, ...rest }: DialogProps): import("react").JSX.Element;
|
|
41
|
+
//# sourceMappingURL=Dialog.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Dialog.d.ts","sourceRoot":"","sources":["../src/Dialog.tsx"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,EAAE,cAAc,EAAiB,SAAS,EAAE,MAAM,OAAO,CAAC;AAMtE,mCAAmC;AACnC,MAAM,WAAW,WAAY,SAAQ,IAAI,CACvC,cAAc,CAAC,cAAc,CAAC,EAC9B,OAAO,CACR;IACC,yDAAyD;IACzD,KAAK,EAAE,SAAS,CAAC;IACjB,0DAA0D;IAC1D,GAAG,CAAC,EAAE,SAAS,CAAC;IAChB,gBAAgB;IAChB,QAAQ,CAAC,EAAE,SAAS,CAAC;IACrB,6DAA6D;IAC7D,OAAO,CAAC,EAAE,SAAS,CAAC;IACpB,0CAA0C;IAC1C,OAAO,EAAE,MAAM,IAAI,CAAC;CACrB;AAED;;;;;;;;;;;;;;;;;;GAkBG;AACH,wBAAgB,MAAM,CAAC,EACrB,KAAK,EACL,GAAG,EACH,QAAQ,EACR,OAAO,EACP,OAAO,EACP,SAAS,EACT,GAAG,IAAI,EACR,EAAE,WAAW,+BAoGb"}
|
package/dist/Dialog.js
ADDED
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { useCallback, useEffect, useId, useRef } from "react";
|
|
3
|
+
import { cx } from "./cx.js";
|
|
4
|
+
import { Actions } from "./layout.js";
|
|
5
|
+
/**
|
|
6
|
+
* The one primitive here that is behaviour rather than a box.
|
|
7
|
+
*
|
|
8
|
+
* A dialog has to trap focus, close on Escape, restore focus to
|
|
9
|
+
* whatever opened it, and not let a click inside the panel count as a
|
|
10
|
+
* click on the backdrop. Every extension that built its own would get
|
|
11
|
+
* some of that wrong, and the ones they get wrong are the ones only
|
|
12
|
+
* keyboard and screen-reader users notice.
|
|
13
|
+
*
|
|
14
|
+
* @param title — its title, also the accessible name of the dialog.
|
|
15
|
+
* @param sub — shown under the title: a sentence, not a paragraph.
|
|
16
|
+
* @param children — the body.
|
|
17
|
+
* @param actions — the buttons, rendered in an `Actions` row at the
|
|
18
|
+
* foot.
|
|
19
|
+
* @param onClose — escape, or a click on the backdrop.
|
|
20
|
+
* @param className — added to the element's classes, beside the one the
|
|
21
|
+
* theme gives it.
|
|
22
|
+
* @param rest — the remaining props, spread onto the dialog panel.
|
|
23
|
+
*/
|
|
24
|
+
export function Dialog({ title, sub, children, actions, onClose, className, ...rest }) {
|
|
25
|
+
const panel = useRef(null);
|
|
26
|
+
const opener = useRef(null);
|
|
27
|
+
const titleId = useId();
|
|
28
|
+
useEffect(() => {
|
|
29
|
+
opener.current = document.activeElement;
|
|
30
|
+
// Focus the panel itself rather than the first control: reading
|
|
31
|
+
// the title before the buttons is the point of having one.
|
|
32
|
+
panel.current?.focus();
|
|
33
|
+
return () => {
|
|
34
|
+
// Only if it is still in the document: an opener that has
|
|
35
|
+
// unmounted drops focus to <body> silently, which is worse than
|
|
36
|
+
// leaving it where the closing action put it.
|
|
37
|
+
const back = opener.current;
|
|
38
|
+
if (back instanceof HTMLElement && back.isConnected)
|
|
39
|
+
back.focus();
|
|
40
|
+
};
|
|
41
|
+
}, []);
|
|
42
|
+
const onKeyDown = useCallback((event) => {
|
|
43
|
+
if (event.key === "Escape") {
|
|
44
|
+
event.stopPropagation();
|
|
45
|
+
onClose();
|
|
46
|
+
return;
|
|
47
|
+
}
|
|
48
|
+
if (event.key !== "Tab")
|
|
49
|
+
return;
|
|
50
|
+
// `:not([disabled])` matters more than it looks: a modal whose
|
|
51
|
+
// confirm button is disabled until a field is typed is the
|
|
52
|
+
// commonest pattern there is, and without this the wrap targets
|
|
53
|
+
// a disabled element, preventDefault fires, focus() is a no-op
|
|
54
|
+
// and Tab appears dead. Dead Tab is worse than escaping Tab.
|
|
55
|
+
// `iframe` is here because an extension *is* one.
|
|
56
|
+
const focusable = panel.current?.querySelectorAll([
|
|
57
|
+
"button:not([disabled])",
|
|
58
|
+
"a[href]",
|
|
59
|
+
"input:not([disabled]):not([type=hidden])",
|
|
60
|
+
"select:not([disabled])",
|
|
61
|
+
"textarea:not([disabled])",
|
|
62
|
+
"iframe",
|
|
63
|
+
"summary",
|
|
64
|
+
"[contenteditable]",
|
|
65
|
+
'[tabindex]:not([tabindex="-1"])',
|
|
66
|
+
].join(", "));
|
|
67
|
+
if (!focusable || focusable.length === 0) {
|
|
68
|
+
// Nothing to move to, so hold the focus here rather than let
|
|
69
|
+
// Tab walk into the page behind a modal with no way back.
|
|
70
|
+
event.preventDefault();
|
|
71
|
+
return;
|
|
72
|
+
}
|
|
73
|
+
const first = focusable[0];
|
|
74
|
+
const last = focusable[focusable.length - 1];
|
|
75
|
+
if (event.shiftKey && document.activeElement === first) {
|
|
76
|
+
event.preventDefault();
|
|
77
|
+
last.focus();
|
|
78
|
+
}
|
|
79
|
+
else if (!event.shiftKey && document.activeElement === last) {
|
|
80
|
+
event.preventDefault();
|
|
81
|
+
first.focus();
|
|
82
|
+
}
|
|
83
|
+
}, [onClose]);
|
|
84
|
+
return (_jsx("div", { className: "overlay", onMouseDown: (e) => {
|
|
85
|
+
// Primary button only, and only on the backdrop itself, so a
|
|
86
|
+
// right-click raising a context menu leaves the modal open.
|
|
87
|
+
if (e.button === 0 && e.target === e.currentTarget)
|
|
88
|
+
onClose();
|
|
89
|
+
}, children: _jsxs("div", { ...rest, ref: panel, className: cx("dialog", className), role: "dialog", "aria-modal": "true", "aria-labelledby": titleId, tabIndex: -1, onKeyDown: onKeyDown,
|
|
90
|
+
// Without this a drag that starts inside and ends outside
|
|
91
|
+
// closes the dialog, which eats a selection.
|
|
92
|
+
onMouseDown: (e) => e.stopPropagation(), children: [_jsx("h2", { className: "dialog-title", id: titleId, children: title }), sub ? _jsx("p", { className: "dialog-sub", children: sub }) : null, children, actions ? (_jsx(Actions, { className: "dialog-actions", children: actions })) : null] }) }));
|
|
93
|
+
}
|
|
94
|
+
//# sourceMappingURL=Dialog.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Dialog.js","sourceRoot":"","sources":["../src/Dialog.tsx"],"names":[],"mappings":";AAQA,OAAO,EAAE,WAAW,EAAE,SAAS,EAAE,KAAK,EAAE,MAAM,EAAE,MAAM,OAAO,CAAC;AAE9D,OAAO,EAAE,EAAE,EAAE,MAAM,SAAS,CAAC;AAC7B,OAAO,EAAE,OAAO,EAAE,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D,6CAA6C;YAC7C,WAAW,EAAE,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,eAAe,EAAE,aAEvC,aAAI,SAAS,EAAC,cAAc,EAAC,EAAE,EAAE,OAAO,YACrC,KAAK,GACH,EACJ,GAAG,CAAC,CAAC,CAAC,YAAG,SAAS,EAAC,YAAY,YAAE,GAAG,GAAK,CAAC,CAAC,CAAC,IAAI,EAChD,QAAQ,EACR,OAAO,CAAC,CAAC,CAAC,CACT,KAAC,OAAO,IAAC,SAAS,EAAC,gBAAgB,YAAE,OAAO,GAAW,CACxD,CAAC,CAAC,CAAC,IAAI,IACJ,GACF,CACP,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* What is shown where a subtree threw.
|
|
3
|
+
*
|
|
4
|
+
* EXTENSIBILITY §7 promises "UI throws → its own error boundary" and
|
|
5
|
+
* nothing provided one. The iframe does protect the *host*: igni's
|
|
6
|
+
* shell survives whatever an extension does. It does not protect the
|
|
7
|
+
* extension from itself. A React tree that throws unmounts, so what
|
|
8
|
+
* an author actually shipped was a blank frame inside a working app —
|
|
9
|
+
* the worst-looking failure available, and the one a partner demo
|
|
10
|
+
* finds.
|
|
11
|
+
*
|
|
12
|
+
* A class, because `componentDidCatch` and
|
|
13
|
+
* `getDerivedStateFromError` have no hook equivalent. This is the
|
|
14
|
+
* only class component under the floor and it is not a style
|
|
15
|
+
* preference.
|
|
16
|
+
*
|
|
17
|
+
* **It catches less than people expect**, and saying so is part of
|
|
18
|
+
* the contract: render, lifecycle and constructor throws, in the
|
|
19
|
+
* subtree below it. Not event handlers, not `setTimeout`, not
|
|
20
|
+
* promise rejections, not anything during SSR. An extension still
|
|
21
|
+
* needs to handle its own async failures — the reference extension's
|
|
22
|
+
* `ScannerClient` is what that looks like.
|
|
23
|
+
*/
|
|
24
|
+
import { Component, type ErrorInfo, type ReactNode } from "react";
|
|
25
|
+
/** What an {@link ErrorBoundary} takes. */
|
|
26
|
+
export interface ErrorBoundaryProps {
|
|
27
|
+
/** The subtree this boundary guards. */
|
|
28
|
+
children: ReactNode;
|
|
29
|
+
/**
|
|
30
|
+
* Shown instead of the subtree. Receives the error and a function
|
|
31
|
+
* that clears the boundary and remounts the children.
|
|
32
|
+
*
|
|
33
|
+
* The default is deliberately plain and deliberately shows the
|
|
34
|
+
* message: the reader is an extension's user, and "something went
|
|
35
|
+
* wrong" has never once helped anybody report a bug.
|
|
36
|
+
*/
|
|
37
|
+
fallback?: (error: Error, reset: () => void) => ReactNode;
|
|
38
|
+
/** Somewhere to send this — a logger, telemetry, a toast. */
|
|
39
|
+
onError?: (error: Error, info: ErrorInfo) => void;
|
|
40
|
+
/**
|
|
41
|
+
* Changing any of these clears the boundary.
|
|
42
|
+
*
|
|
43
|
+
* Without it a boundary that has caught once stays caught forever,
|
|
44
|
+
* so navigating away from the thing that broke shows the error
|
|
45
|
+
* page for the thing that works. Compared by identity, in order,
|
|
46
|
+
* like a hook dependency array.
|
|
47
|
+
*/
|
|
48
|
+
resetKeys?: readonly unknown[];
|
|
49
|
+
}
|
|
50
|
+
interface State {
|
|
51
|
+
error: Error | null;
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* What is shown where a subtree threw.
|
|
55
|
+
*
|
|
56
|
+
* It catches less than people expect: render, lifecycle and
|
|
57
|
+
* constructor throws in the subtree below it, and not event handlers,
|
|
58
|
+
* `setTimeout`, promise rejections or anything during SSR. The default
|
|
59
|
+
* fallback shows the error's message on purpose.
|
|
60
|
+
*/
|
|
61
|
+
export declare class ErrorBoundary extends Component<ErrorBoundaryProps, State> {
|
|
62
|
+
/**
|
|
63
|
+
* The error the subtree threw, or null while nothing has thrown.
|
|
64
|
+
*/
|
|
65
|
+
state: State;
|
|
66
|
+
/**
|
|
67
|
+
* The state the boundary holds after a throw.
|
|
68
|
+
*
|
|
69
|
+
* @param error — the error the subtree threw.
|
|
70
|
+
*/
|
|
71
|
+
static getDerivedStateFromError(error: Error): State;
|
|
72
|
+
/**
|
|
73
|
+
* Reports the error to whoever asked for it.
|
|
74
|
+
*
|
|
75
|
+
* @param error — the error the subtree threw.
|
|
76
|
+
* @param info — React's account of where it was thrown: the component
|
|
77
|
+
* stack.
|
|
78
|
+
*/
|
|
79
|
+
componentDidCatch(error: Error, info: ErrorInfo): void;
|
|
80
|
+
/**
|
|
81
|
+
* Clears the boundary when the reset keys change.
|
|
82
|
+
*
|
|
83
|
+
* @param previous — the props from the previous render, whose
|
|
84
|
+
* `resetKeys` are compared with the new ones.
|
|
85
|
+
*/
|
|
86
|
+
componentDidUpdate(previous: ErrorBoundaryProps): void;
|
|
87
|
+
/**
|
|
88
|
+
* Clears the error and renders the children again.
|
|
89
|
+
*/
|
|
90
|
+
reset: () => void;
|
|
91
|
+
/**
|
|
92
|
+
* The children, or the error page when the subtree threw.
|
|
93
|
+
*/
|
|
94
|
+
render(): ReactNode;
|
|
95
|
+
}
|
|
96
|
+
export {};
|
|
97
|
+
//# sourceMappingURL=ErrorBoundary.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ErrorBoundary.d.ts","sourceRoot":"","sources":["../src/ErrorBoundary.tsx"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,OAAO,EAAE,SAAS,EAAE,KAAK,SAAS,EAAE,KAAK,SAAS,EAAE,MAAM,OAAO,CAAC;AAElE,2CAA2C;AAC3C,MAAM,WAAW,kBAAkB;IACjC,wCAAwC;IACxC,QAAQ,EAAE,SAAS,CAAC;IACpB;;;;;;;OAOG;IACH,QAAQ,CAAC,EAAE,CAAC,KAAK,EAAE,KAAK,EAAE,KAAK,EAAE,MAAM,IAAI,KAAK,SAAS,CAAC;IAC1D,6DAA6D;IAC7D,OAAO,CAAC,EAAE,CAAC,KAAK,EAAE,KAAK,EAAE,IAAI,EAAE,SAAS,KAAK,IAAI,CAAC;IAClD;;;;;;;OAOG;IACH,SAAS,CAAC,EAAE,SAAS,OAAO,EAAE,CAAC;CAChC;AAED,UAAU,KAAK;IACb,KAAK,EAAE,KAAK,GAAG,IAAI,CAAC;CACrB;AAYD;;;;;;;GAOG;AACH,qBAAa,aAAc,SAAQ,SAAS,CAAC,kBAAkB,EAAE,KAAK,CAAC;IACrE;;OAEG;IACH,KAAK,EAAE,KAAK,CAAmB;IAE/B;;;;OAIG;IACH,MAAM,CAAC,wBAAwB,CAAC,KAAK,EAAE,KAAK,GAAG,KAAK;IAIpD;;;;;;OAMG;IACH,iBAAiB,CAAC,KAAK,EAAE,KAAK,EAAE,IAAI,EAAE,SAAS,GAAG,IAAI;IAItD;;;;;OAKG;IACH,kBAAkB,CAAC,QAAQ,EAAE,kBAAkB,GAAG,IAAI;IAOtD;;OAEG;IACH,KAAK,QAAO,IAAI,CAEd;IAEF;;OAEG;IACH,MAAM,IAAI,SAAS;CAcpB"}
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
/**
|
|
3
|
+
* What is shown where a subtree threw.
|
|
4
|
+
*
|
|
5
|
+
* EXTENSIBILITY §7 promises "UI throws → its own error boundary" and
|
|
6
|
+
* nothing provided one. The iframe does protect the *host*: igni's
|
|
7
|
+
* shell survives whatever an extension does. It does not protect the
|
|
8
|
+
* extension from itself. A React tree that throws unmounts, so what
|
|
9
|
+
* an author actually shipped was a blank frame inside a working app —
|
|
10
|
+
* the worst-looking failure available, and the one a partner demo
|
|
11
|
+
* finds.
|
|
12
|
+
*
|
|
13
|
+
* A class, because `componentDidCatch` and
|
|
14
|
+
* `getDerivedStateFromError` have no hook equivalent. This is the
|
|
15
|
+
* only class component under the floor and it is not a style
|
|
16
|
+
* preference.
|
|
17
|
+
*
|
|
18
|
+
* **It catches less than people expect**, and saying so is part of
|
|
19
|
+
* the contract: render, lifecycle and constructor throws, in the
|
|
20
|
+
* subtree below it. Not event handlers, not `setTimeout`, not
|
|
21
|
+
* promise rejections, not anything during SSR. An extension still
|
|
22
|
+
* needs to handle its own async failures — the reference extension's
|
|
23
|
+
* `ScannerClient` is what that looks like.
|
|
24
|
+
*/
|
|
25
|
+
import { Component } from "react";
|
|
26
|
+
// Anything can be thrown. The fallback and `onError` are typed to get an
|
|
27
|
+
// Error, and `null` held as the error would read as "nothing thrown".
|
|
28
|
+
function toError(thrown) {
|
|
29
|
+
return thrown instanceof Error ? thrown : new Error(String(thrown));
|
|
30
|
+
}
|
|
31
|
+
function changed(a, b) {
|
|
32
|
+
return a.length !== b.length || a.some((value, i) => !Object.is(value, b[i]));
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* What is shown where a subtree threw.
|
|
36
|
+
*
|
|
37
|
+
* It catches less than people expect: render, lifecycle and
|
|
38
|
+
* constructor throws in the subtree below it, and not event handlers,
|
|
39
|
+
* `setTimeout`, promise rejections or anything during SSR. The default
|
|
40
|
+
* fallback shows the error's message on purpose.
|
|
41
|
+
*/
|
|
42
|
+
export class ErrorBoundary extends Component {
|
|
43
|
+
/**
|
|
44
|
+
* The error the subtree threw, or null while nothing has thrown.
|
|
45
|
+
*/
|
|
46
|
+
state = { error: null };
|
|
47
|
+
/**
|
|
48
|
+
* The state the boundary holds after a throw.
|
|
49
|
+
*
|
|
50
|
+
* @param error — the error the subtree threw.
|
|
51
|
+
*/
|
|
52
|
+
static getDerivedStateFromError(error) {
|
|
53
|
+
return { error: toError(error) };
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* Reports the error to whoever asked for it.
|
|
57
|
+
*
|
|
58
|
+
* @param error — the error the subtree threw.
|
|
59
|
+
* @param info — React's account of where it was thrown: the component
|
|
60
|
+
* stack.
|
|
61
|
+
*/
|
|
62
|
+
componentDidCatch(error, info) {
|
|
63
|
+
this.props.onError?.(toError(error), info);
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* Clears the boundary when the reset keys change.
|
|
67
|
+
*
|
|
68
|
+
* @param previous — the props from the previous render, whose
|
|
69
|
+
* `resetKeys` are compared with the new ones.
|
|
70
|
+
*/
|
|
71
|
+
componentDidUpdate(previous) {
|
|
72
|
+
if (this.state.error === null)
|
|
73
|
+
return;
|
|
74
|
+
const before = previous.resetKeys ?? [];
|
|
75
|
+
const now = this.props.resetKeys ?? [];
|
|
76
|
+
if (changed(before, now))
|
|
77
|
+
this.reset();
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* Clears the error and renders the children again.
|
|
81
|
+
*/
|
|
82
|
+
reset = () => {
|
|
83
|
+
this.setState({ error: null });
|
|
84
|
+
};
|
|
85
|
+
/**
|
|
86
|
+
* The children, or the error page when the subtree threw.
|
|
87
|
+
*/
|
|
88
|
+
render() {
|
|
89
|
+
const { error } = this.state;
|
|
90
|
+
if (error === null)
|
|
91
|
+
return this.props.children;
|
|
92
|
+
if (this.props.fallback)
|
|
93
|
+
return this.props.fallback(error, this.reset);
|
|
94
|
+
return (_jsxs("div", { className: "ui-crash", role: "alert", children: [_jsx("p", { className: "ui-text", children: "Something in this view stopped working." }), _jsx("pre", { className: "ui-crash-detail", children: error.message }), _jsx("button", { type: "button", className: "btn", onClick: this.reset, children: "Try again" })] }));
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
//# sourceMappingURL=ErrorBoundary.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ErrorBoundary.js","sourceRoot":"","sources":["../src/ErrorBoundary.tsx"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,OAAO,EAAE,SAAS,EAAkC,MAAM,OAAO,CAAC;AAgClE,yEAAyE;AACzE,sEAAsE;AACtE,SAAS,OAAO,CAAC,MAAe;IAC9B,OAAO,MAAM,YAAY,KAAK,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,IAAI,KAAK,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC,CAAC;AACtE,CAAC;AAED,SAAS,OAAO,CAAC,CAA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AK,KAAK,IAAI;YAAE,OAAO,IAAI,CAAC,KAAK,CAAC,QAAQ,CAAC;QAC/C,IAAI,IAAI,CAAC,KAAK,CAAC,QAAQ;YAAE,OAAO,IAAI,CAAC,KAAK,CAAC,QAAQ,CAAC,KAAK,EAAE,IAAI,CAAC,KAAK,CAAC,CAAC;QACvE,OAAO,CACL,eAAK,SAAS,EAAC,UAAU,EAAC,IAAI,EAAC,OAAO,aACpC,YAAG,SAAS,EAAC,SAAS,wDAA4C,EAClE,cAAK,SAAS,EAAC,iBAAiB,YAAE,KAAK,CAAC,OAAO,GAAO,EACtD,iBAAQ,IAAI,EAAC,QAAQ,EAAC,SAAS,EAAC,KAAK,EAAC,OAAO,EAAE,IAAI,CAAC,KAAK,0BAEhD,IACL,CACP,CAAC;IACJ,CAAC;CACF"}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
/** Which way to say it. */
|
|
2
|
+
export type Urgency = "polite" | "assertive";
|
|
3
|
+
/** A live region and the function that speaks into it. */
|
|
4
|
+
export interface Announcer {
|
|
5
|
+
/** Say something. Re-saying the same thing still announces. */
|
|
6
|
+
announce: (message: string, urgency?: Urgency) => void;
|
|
7
|
+
/** Render this. It must be in the tree before anything is said. */
|
|
8
|
+
region: React.ReactElement;
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* A live region and the function that speaks into it.
|
|
12
|
+
*
|
|
13
|
+
* Two regions are rendered, not one. A single region whose
|
|
14
|
+
* `aria-live` value changes is unreliable: the attribute is read
|
|
15
|
+
* when the region is observed, so flipping it at the same moment the
|
|
16
|
+
* text changes races, and the announcement comes out at whichever
|
|
17
|
+
* urgency the implementation noticed first.
|
|
18
|
+
*/
|
|
19
|
+
export declare function useAnnounce(): Announcer;
|
|
20
|
+
/** What a {@link LiveRegion} takes. */
|
|
21
|
+
export interface LiveRegionProps {
|
|
22
|
+
/** What to say. Changing it announces; clearing it says nothing. */
|
|
23
|
+
children?: string;
|
|
24
|
+
/** How insistently it is announced: politely, or assertively. */
|
|
25
|
+
urgency?: Urgency;
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* The declarative form, for a value that already lives in state.
|
|
29
|
+
*
|
|
30
|
+
* `<LiveRegion>{`${n} results`}</LiveRegion>` is the whole usage.
|
|
31
|
+
* Mounted empty on the first render so the region exists before it
|
|
32
|
+
* has anything to say: a live region added to the page with its
|
|
33
|
+
* message already in it is frequently not announced.
|
|
34
|
+
*
|
|
35
|
+
* @param children — what to say; changing it announces, and clearing it
|
|
36
|
+
* says nothing.
|
|
37
|
+
* @param urgency — how insistently it is announced: politely, or
|
|
38
|
+
* assertively.
|
|
39
|
+
*/
|
|
40
|
+
export declare function LiveRegion({ children, urgency }: LiveRegionProps): import("react").JSX.Element;
|
|
41
|
+
//# sourceMappingURL=LiveRegion.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"LiveRegion.d.ts","sourceRoot":"","sources":["../src/LiveRegion.tsx"],"names":[],"mappings":"AA2BA,2BAA2B;AAC3B,MAAM,MAAM,OAAO,GAAG,QAAQ,GAAG,WAAW,CAAC;AAE7C,0DAA0D;AAC1D,MAAM,WAAW,SAAS;IACxB,+DAA+D;IAC/D,QAAQ,EAAE,CAAC,OAAO,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,OAAO,KAAK,IAAI,CAAC;IACvD,mEAAmE;IACnE,MAAM,EAAE,KAAK,CAAC,YAAY,CAAC;CAC5B;AAED;;;;;;;;GAQG;AACH,wBAAgB,WAAW,IAAI,SAAS,CAyCvC;AAED,uCAAuC;AACvC,MAAM,WAAW,eAAe;IAC9B,oEAAoE;IACpE,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,iEAAiE;IACjE,OAAO,CAAC,EAAE,OAAO,CAAC;CACnB;AAED;;;;;;;;;;;;GAYG;AACH,wBAAgB,UAAU,CAAC,EAAE,QAAa,EAAE,OAAkB,EAAE,EAAE,eAAe,+BAehF"}
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
/**
|
|
3
|
+
* Saying what changed, to somebody who cannot see it change.
|
|
4
|
+
*
|
|
5
|
+
* A filtered count, a finished scan, a saved draft: all of them move
|
|
6
|
+
* nothing and focus nothing, so a screen reader is told none of it.
|
|
7
|
+
* The reference extension hand-rolled an `aria-live` paragraph with
|
|
8
|
+
* `ui-visually-hidden`, which is the right shape and the wrong place
|
|
9
|
+
* — every extension would write it, and most would get one of the
|
|
10
|
+
* three details wrong.
|
|
11
|
+
*
|
|
12
|
+
* The three details:
|
|
13
|
+
*
|
|
14
|
+
* 1. **The region must exist before the text does.** A live region
|
|
15
|
+
* added to the DOM with its message already in it is frequently
|
|
16
|
+
* not announced at all — the assistive technology has nothing to
|
|
17
|
+
* observe a change against. So this renders an empty element and
|
|
18
|
+
* fills it afterwards.
|
|
19
|
+
* 2. **The same message twice is not a change.** Scanning 40 files
|
|
20
|
+
* and then scanning 40 files again is silence, because the text
|
|
21
|
+
* never differed. A zero-width space is toggled on repeats.
|
|
22
|
+
* 3. **Polite waits, assertive interrupts.** Almost everything is
|
|
23
|
+
* polite. Assertive is for something the user must act on, and
|
|
24
|
+
* using it for a count makes the product unusable by the people
|
|
25
|
+
* it is meant to help.
|
|
26
|
+
*/
|
|
27
|
+
import { useCallback, useEffect, useRef, useState } from "react";
|
|
28
|
+
/**
|
|
29
|
+
* A live region and the function that speaks into it.
|
|
30
|
+
*
|
|
31
|
+
* Two regions are rendered, not one. A single region whose
|
|
32
|
+
* `aria-live` value changes is unreliable: the attribute is read
|
|
33
|
+
* when the region is observed, so flipping it at the same moment the
|
|
34
|
+
* text changes races, and the announcement comes out at whichever
|
|
35
|
+
* urgency the implementation noticed first.
|
|
36
|
+
*/
|
|
37
|
+
export function useAnnounce() {
|
|
38
|
+
const [polite, setPolite] = useState("");
|
|
39
|
+
const [assertive, setAssertive] = useState("");
|
|
40
|
+
const last = useRef({ polite: "", assertive: "" });
|
|
41
|
+
const announce = useCallback((message, urgency = "polite") => {
|
|
42
|
+
// Identical consecutive text is not a mutation, so nothing is
|
|
43
|
+
// announced. A zero-width space makes it one, and is not read
|
|
44
|
+
// aloud.
|
|
45
|
+
const previous = last.current[urgency];
|
|
46
|
+
const text = message === previous ? `${message}` : message;
|
|
47
|
+
last.current[urgency] = text;
|
|
48
|
+
if (urgency === "assertive")
|
|
49
|
+
setAssertive(text);
|
|
50
|
+
else
|
|
51
|
+
setPolite(text);
|
|
52
|
+
}, []);
|
|
53
|
+
const region = (_jsxs(_Fragment, { children: [_jsx("div", { className: "ui-visually-hidden", role: "status", "aria-live": "polite", "aria-atomic": "true", children: polite }), _jsx("div", { className: "ui-visually-hidden", role: "alert", "aria-live": "assertive", "aria-atomic": "true", children: assertive })] }));
|
|
54
|
+
return { announce, region };
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* The declarative form, for a value that already lives in state.
|
|
58
|
+
*
|
|
59
|
+
* `<LiveRegion>{`${n} results`}</LiveRegion>` is the whole usage.
|
|
60
|
+
* Mounted empty on the first render so the region exists before it
|
|
61
|
+
* has anything to say: a live region added to the page with its
|
|
62
|
+
* message already in it is frequently not announced.
|
|
63
|
+
*
|
|
64
|
+
* @param children — what to say; changing it announces, and clearing it
|
|
65
|
+
* says nothing.
|
|
66
|
+
* @param urgency — how insistently it is announced: politely, or
|
|
67
|
+
* assertively.
|
|
68
|
+
*/
|
|
69
|
+
export function LiveRegion({ children = "", urgency = "polite" }) {
|
|
70
|
+
const [text, setText] = useState("");
|
|
71
|
+
useEffect(() => {
|
|
72
|
+
setText(children);
|
|
73
|
+
}, [children]);
|
|
74
|
+
return (_jsx("div", { className: "ui-visually-hidden", role: urgency === "assertive" ? "alert" : "status", "aria-live": urgency, "aria-atomic": "true", children: text }));
|
|
75
|
+
}
|
|
76
|
+
//# sourceMappingURL=LiveRegion.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
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ACL,CACJ,CAAC;IAEF,OAAO,EAAE,QAAQ,EAAE,MAAM,EAAE,CAAC;AAC9B,CAAC;AAUD;;;;;;;;;;;;GAYG;AACH,MAAM,UAAU,UAAU,CAAC,EAAE,QAAQ,GAAG,EAAE,EAAE,OAAO,GAAG,QAAQ,EAAmB;IAC/E,MAAM,CAAC,IAAI,EAAE,OAAO,CAAC,GAAG,QAAQ,CAAC,EAAE,CAAC,CAAC;IACrC,SAAS,CAAC,GAAG,EAAE;QACb,OAAO,CAAC,QAAQ,CAAC,CAAC;IACpB,CAAC,EAAE,CAAC,QAAQ,CAAC,CAAC,CAAC;IACf,OAAO,CACL,cACE,SAAS,EAAC,oBAAoB,EAC9B,IAAI,EAAE,OAAO,KAAK,WAAW,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,QAAQ,eACvC,OAAO,iBACN,MAAM,YAEjB,IAAI,GACD,CACP,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/** What a {@link Markdown} takes. */
|
|
2
|
+
export interface MarkdownProps {
|
|
3
|
+
/** The source. Rendered as a document, not flattened. */
|
|
4
|
+
children: string;
|
|
5
|
+
/** Added to the element's classes, beside the one the theme gives it. */
|
|
6
|
+
className?: string;
|
|
7
|
+
}
|
|
8
|
+
/**
|
|
9
|
+
* Render markdown as prose.
|
|
10
|
+
*
|
|
11
|
+
* GitHub-flavoured, because that is what people write: tables,
|
|
12
|
+
* strikethrough, task lists and autolinks. Raw HTML is **not**
|
|
13
|
+
* enabled and will not be — `rehype-raw` in a surface that renders
|
|
14
|
+
* text somebody else wrote is a script tag waiting to happen, and an
|
|
15
|
+
* extension's frame has a CSP precisely so that it cannot.
|
|
16
|
+
*
|
|
17
|
+
* @param children — the source; rendered as a document, not flattened.
|
|
18
|
+
* @param className — added to the element's classes, beside the one the
|
|
19
|
+
* theme gives it.
|
|
20
|
+
*/
|
|
21
|
+
export declare function Markdown({ children, className }: MarkdownProps): import("react").JSX.Element;
|
|
22
|
+
//# sourceMappingURL=Markdown.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Markdown.d.ts","sourceRoot":"","sources":["../src/Markdown.tsx"],"names":[],"mappings":"AA6CA,qCAAqC;AACrC,MAAM,WAAW,aAAa;IAC5B,yDAAyD;IACzD,QAAQ,EAAE,MAAM,CAAC;IACjB,yEAAyE;IACzE,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB;AAED;;;;;;;;;;;;GAYG;AACH,wBAAgB,QAAQ,CAAC,EAAE,QAAQ,EAAE,SAAS,EAAE,EAAE,aAAa,+BAQ9D"}
|
package/dist/Markdown.js
ADDED
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
/**
|
|
3
|
+
* Markdown with its block structure intact.
|
|
4
|
+
*
|
|
5
|
+
* The floor published exactly one markdown component and it was
|
|
6
|
+
* `MarkdownInline`, which is *designed* to destroy block structure:
|
|
7
|
+
* headings lose their size, lists become middots, images return
|
|
8
|
+
* null. That is right for a two-line preview and exactly wrong for a
|
|
9
|
+
* document, so an extension with prose in it bundled its own
|
|
10
|
+
* renderer — and then had nothing to style it against, because
|
|
11
|
+
* igni's prose rules live in `theme.css` and were not published
|
|
12
|
+
* either.
|
|
13
|
+
*
|
|
14
|
+
* `examples/release-notes` hand-rolls a deliberately small subset
|
|
15
|
+
* and says so. This is what that was missing.
|
|
16
|
+
*
|
|
17
|
+
* **Not a configurable pipeline.** No plugin prop, no component
|
|
18
|
+
* overrides. The value here is that prose in an extension looks like
|
|
19
|
+
* prose in igni, and every escape hatch is a way for that to stop
|
|
20
|
+
* being true. An extension that needs a different pipeline should
|
|
21
|
+
* bundle react-markdown directly — it is a peer dependency it
|
|
22
|
+
* already has — and wrap the result in `.ui-prose`.
|
|
23
|
+
*/
|
|
24
|
+
import ReactMarkdown from "react-markdown";
|
|
25
|
+
import remarkGfm from "remark-gfm";
|
|
26
|
+
function cx(...parts) {
|
|
27
|
+
return parts.filter(Boolean).join(" ");
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Links open where they point, safely.
|
|
31
|
+
*
|
|
32
|
+
* A document can arrive from a colleague, so the href is somebody
|
|
33
|
+
* else's. `noopener` is the one that matters: without it the opened
|
|
34
|
+
* page gets a handle on this frame through `window.opener` and can
|
|
35
|
+
* navigate it somewhere else.
|
|
36
|
+
*/
|
|
37
|
+
const COMPONENTS = {
|
|
38
|
+
a: ({ href, children, ...rest }) => (_jsx("a", { ...rest, href: href, target: "_blank", rel: "noopener noreferrer", children: children })),
|
|
39
|
+
};
|
|
40
|
+
/**
|
|
41
|
+
* Render markdown as prose.
|
|
42
|
+
*
|
|
43
|
+
* GitHub-flavoured, because that is what people write: tables,
|
|
44
|
+
* strikethrough, task lists and autolinks. Raw HTML is **not**
|
|
45
|
+
* enabled and will not be — `rehype-raw` in a surface that renders
|
|
46
|
+
* text somebody else wrote is a script tag waiting to happen, and an
|
|
47
|
+
* extension's frame has a CSP precisely so that it cannot.
|
|
48
|
+
*
|
|
49
|
+
* @param children — the source; rendered as a document, not flattened.
|
|
50
|
+
* @param className — added to the element's classes, beside the one the
|
|
51
|
+
* theme gives it.
|
|
52
|
+
*/
|
|
53
|
+
export function Markdown({ children, className }) {
|
|
54
|
+
return (_jsx("div", { className: cx("ui-prose", className), children: _jsx(ReactMarkdown, { remarkPlugins: [remarkGfm], components: COMPONENTS, children: children }) }));
|
|
55
|
+
}
|
|
56
|
+
//# sourceMappingURL=Markdown.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Markdown.js","sourceRoot":"","sources":["../src/Markdown.tsx"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,OAAO,aAAkC,MAAM,gBAAgB,CAAC;AAChE,OAAO,SAAS,MAAM,YAAY,CAAC;AAEnC,SAAS,EAAE,CAAC,GAAG,KAA4C;IACzD,OAAO,KAAK,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;AACzC,CAAC;AAED;;;;;;;GAOG;AACH,MAAM,UAAU,GAAe;IAC7B,CAAC,EAAE,CAAC,EAAE,IAAI,EAAE,QAAQ,EAAE,GAAG,IAAI,EAAE,EAAE,EAAE,CAAC,CAClC,eAAO,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,MAAM,EAAC,QAAQ,EAAC,GAAG,EAAC,qBAAqB,YAC/D,QAAQ,GACP,CACL;CACF,CAAC;AAUF;;;;;;;;;;;;GAYG;AACH,MAAM,UAAU,QAAQ,CAAC,EAAE,QAAQ,EAAE,SAAS,EAAiB;IAC7D,OAAO,CACL,cAAK,SAAS,EAAE,EAAE,CAAC,UAAU,EAAE,SAAS,CAAC,YACvC,KAAC,aAAa,IAAC,aAAa,EAAE,CAAC,SAAS,CAAC,EAAE,UAAU,EAAE,UAAU,YAC9D,QAAQ,GACK,GACZ,CACP,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Repair markdown cut mid-syntax.
|
|
3
|
+
*
|
|
4
|
+
* Previews arrive pre-truncated, and the cut lands wherever it lands
|
|
5
|
+
* — often inside `**bold` or an unclosed backtick. Rendered as-is the
|
|
6
|
+
* marker shows up literally, which is the thing this component
|
|
7
|
+
* exists to stop. Closing what was left open is cheaper than asking
|
|
8
|
+
* every producer of a preview to cut carefully.
|
|
9
|
+
*/
|
|
10
|
+
export declare function closeOpenMarks(text: string): string;
|
|
11
|
+
/**
|
|
12
|
+
* Drop a leading line that only repeats the document's name.
|
|
13
|
+
*
|
|
14
|
+
* Most documents open with their own title. In a list the name is
|
|
15
|
+
* already the row's first line, so rendering it again spends the
|
|
16
|
+
* preview — the two lines somebody reads to tell this document from
|
|
17
|
+
* the next one — saying what they just read.
|
|
18
|
+
*
|
|
19
|
+
* Heading or plain line: the duplication is the same either way, and
|
|
20
|
+
* whether the author marked it up is not the reader's problem. The
|
|
21
|
+
* line has to *be* the name, though, not merely open with it —
|
|
22
|
+
* "Session handling is a signed JWT flow" is the first sentence of
|
|
23
|
+
* the document and belongs in the preview.
|
|
24
|
+
*/
|
|
25
|
+
export declare function dropEchoedTitle(text: string, name: string): string;
|
|
26
|
+
/**
|
|
27
|
+
* Markdown rendered as one flowing line of text.
|
|
28
|
+
*
|
|
29
|
+
* Every block becomes inline: headings keep their emphasis but not
|
|
30
|
+
* their size, list items are separated by middots, tables flatten to
|
|
31
|
+
* their cells, and links and images are dropped to their text or to
|
|
32
|
+
* nothing. `limit` bounds the work, not the appearance: the clamp is
|
|
33
|
+
* visual, and a document longer than `limit` is cut with an ellipsis,
|
|
34
|
+
* back to a word boundary when one falls in the last 40% of it.
|
|
35
|
+
*
|
|
36
|
+
* @param text — the markdown to render as one flowing line.
|
|
37
|
+
* @param name — the document's name, so a title echo can be dropped.
|
|
38
|
+
* @param limit — characters to keep; the clamp is visual, and this
|
|
39
|
+
* bounds the work.
|
|
40
|
+
* @param className — added to the element's classes, beside the one the
|
|
41
|
+
* theme gives it.
|
|
42
|
+
*/
|
|
43
|
+
export declare function MarkdownInline({ text,
|
|
44
|
+
/** The document's name, so a title echo can be dropped. */
|
|
45
|
+
name,
|
|
46
|
+
/** Characters to keep. The clamp is visual; this bounds the work. */
|
|
47
|
+
limit, className, }: {
|
|
48
|
+
text: string;
|
|
49
|
+
name?: string;
|
|
50
|
+
limit?: number;
|
|
51
|
+
className?: string;
|
|
52
|
+
}): import("react").JSX.Element | null;
|
|
53
|
+
//# sourceMappingURL=MarkdownInline.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"MarkdownInline.d.ts","sourceRoot":"","sources":["../src/MarkdownInline.tsx"],"names":[],"mappings":"AAqEA;;;;;;;;GAQG;AACH,wBAAgB,cAAc,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAWnD;AAED;;;;;;;;;;;;;GAaG;AACH,wBAAgB,eAAe,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,MAAM,CAelE;AAED;;;;;;;;;;;;;;;;GAgBG;AACH,wBAAgB,cAAc,CAAC,EAC7B,IAAI;AACJ,2DAA2D;AAC3D,IAAS;AACT,qEAAqE;AACrE,KAAW,EACX,SAAc,GACf,EAAE;IACD,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB,sCAyBA"}
|