@graview/react 0.1.70 → 0.1.71
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/view-boundary.d.ts
CHANGED
|
@@ -20,17 +20,36 @@ export interface ViewBoundaryProps {
|
|
|
20
20
|
readonly kind: string;
|
|
21
21
|
/** The view that threw, when the registration named one. */
|
|
22
22
|
readonly view?: string;
|
|
23
|
+
/** What the panel says under its line in a person's words, in place of the kind's id; `""` says nothing more. */
|
|
24
|
+
readonly said?: string;
|
|
25
|
+
/** Told when the view threw, once its panel stands: a surface that drew less around a view that is the whole page draws its own again. */
|
|
26
|
+
readonly onCaught?: (error: Error) => void;
|
|
27
|
+
/** What the view is drawn from: a view that threw is drawn again once any of these changes (the store's version, another view). */
|
|
28
|
+
readonly reset?: readonly unknown[];
|
|
23
29
|
readonly children: ReactNode;
|
|
24
30
|
}
|
|
25
31
|
interface ViewBoundaryState {
|
|
26
32
|
readonly error?: Error;
|
|
27
33
|
}
|
|
34
|
+
/** Where the keyboard was before the boundary changed: on its panel, with where the panel stood, or elsewhere. */
|
|
35
|
+
type KeyboardWas = {
|
|
36
|
+
readonly onPanel: true;
|
|
37
|
+
readonly focused: Element;
|
|
38
|
+
readonly parent: ParentNode | null;
|
|
39
|
+
readonly before: ChildNode | null;
|
|
40
|
+
} | {
|
|
41
|
+
readonly onPanel: false;
|
|
42
|
+
readonly focused: Element | null;
|
|
43
|
+
} | null;
|
|
28
44
|
export declare class ViewBoundary extends Component<ViewBoundaryProps, ViewBoundaryState> {
|
|
29
45
|
static contextType: import("react").Context<ErrorReport | null>;
|
|
30
46
|
context: ErrorReport | null;
|
|
31
47
|
state: ViewBoundaryState;
|
|
32
48
|
static getDerivedStateFromError(error: Error): ViewBoundaryState;
|
|
33
49
|
componentDidCatch(error: Error, info: ErrorInfo): void;
|
|
50
|
+
private readonly panel;
|
|
51
|
+
getSnapshotBeforeUpdate(): KeyboardWas;
|
|
52
|
+
componentDidUpdate(previous: ViewBoundaryProps, previousState: ViewBoundaryState, was?: KeyboardWas): void;
|
|
34
53
|
render(): ReactNode;
|
|
35
54
|
}
|
|
36
55
|
//# sourceMappingURL=view-boundary.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"view-boundary.d.ts","sourceRoot":"","sources":["../src/view-boundary.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,
|
|
1
|
+
{"version":3,"file":"view-boundary.d.ts","sourceRoot":"","sources":["../src/view-boundary.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAa,KAAK,SAAS,EAAE,KAAK,SAAS,EAAE,MAAM,OAAO,CAAC;AAC7E,OAAO,EAAsB,KAAK,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAEzE,OAAO,EAAE,kBAAkB,EAAE,KAAK,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAEzE;;;;;;;;;;;;;GAaG;AACH,MAAM,WAAW,iBAAiB;IAChC,uDAAuD;IACvD,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,4DAA4D;IAC5D,QAAQ,CAAC,IAAI,CAAC,EAAE,MAAM,CAAC;IACvB,iHAAiH;IACjH,QAAQ,CAAC,IAAI,CAAC,EAAE,MAAM,CAAC;IACvB,0IAA0I;IAC1I,QAAQ,CAAC,QAAQ,CAAC,EAAE,CAAC,KAAK,EAAE,KAAK,KAAK,IAAI,CAAC;IAC3C,mIAAmI;IACnI,QAAQ,CAAC,KAAK,CAAC,EAAE,SAAS,OAAO,EAAE,CAAC;IACpC,QAAQ,CAAC,QAAQ,EAAE,SAAS,CAAC;CAC9B;AAED,UAAU,iBAAiB;IACzB,QAAQ,CAAC,KAAK,CAAC,EAAE,KAAK,CAAC;CACxB;AAkBD,kHAAkH;AAClH,KAAK,WAAW,GACZ;IAAE,QAAQ,CAAC,OAAO,EAAE,IAAI,CAAC;IAAC,QAAQ,CAAC,OAAO,EAAE,OAAO,CAAC;IAAC,QAAQ,CAAC,MAAM,EAAE,UAAU,GAAG,IAAI,CAAC;IAAC,QAAQ,CAAC,MAAM,EAAE,SAAS,GAAG,IAAI,CAAA;CAAE,GAC5H;IAAE,QAAQ,CAAC,OAAO,EAAE,KAAK,CAAC;IAAC,QAAQ,CAAC,OAAO,EAAE,OAAO,GAAG,IAAI,CAAA;CAAE,GAC7D,IAAI,CAAC;AAST,qBAAa,YAAa,SAAQ,SAAS,CAAC,iBAAiB,EAAE,iBAAiB,CAAC;IAC/E,OAAgB,WAAW,8CAAsB;IACzC,OAAO,EAAE,WAAW,GAAG,IAAI,CAAC;IAC3B,KAAK,EAAE,iBAAiB,CAAM;IAEvC,MAAM,CAAC,wBAAwB,CAAC,KAAK,EAAE,KAAK,GAAG,iBAAiB;IASvD,iBAAiB,CAAC,KAAK,EAAE,KAAK,EAAE,IAAI,EAAE,SAAS,GAAG,IAAI;IAiB/D,OAAO,CAAC,QAAQ,CAAC,KAAK,CAA+B;IAE5C,uBAAuB,IAAI,WAAW;IAQtC,kBAAkB,CAAC,QAAQ,EAAE,iBAAiB,EAAE,aAAa,EAAE,iBAAiB,EAAE,GAAG,CAAC,EAAE,WAAW,GAAG,IAAI;IAqB1G,MAAM,IAAI,SAAS;CAmC7B"}
|
package/dist/view-boundary.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
-
import { Component } from "react";
|
|
2
|
+
import { Component, createRef } from "react";
|
|
3
3
|
import { ErrorReportContext } from "./error-report.js";
|
|
4
4
|
export { ErrorReportContext } from "./error-report.js";
|
|
5
5
|
/**
|
|
@@ -17,6 +17,11 @@ function messageOf(error) {
|
|
|
17
17
|
const text = String(error);
|
|
18
18
|
return text === "[object Object]" ? "The view threw without a message." : text;
|
|
19
19
|
}
|
|
20
|
+
const FOCUSABLE = 'a[href], button:not([disabled]), input:not([disabled]), select:not([disabled]), textarea:not([disabled]), [tabindex]:not([tabindex="-1"]), [contenteditable="true"]';
|
|
21
|
+
/** Whether nothing holds the keyboard: the page's body, or no element at all. */
|
|
22
|
+
function keyboardLost() {
|
|
23
|
+
return document.activeElement === null || document.activeElement === document.body;
|
|
24
|
+
}
|
|
20
25
|
export class ViewBoundary extends Component {
|
|
21
26
|
static contextType = ErrorReportContext;
|
|
22
27
|
state = {};
|
|
@@ -31,13 +36,55 @@ export class ViewBoundary extends Component {
|
|
|
31
36
|
componentDidCatch(error, info) {
|
|
32
37
|
console.error(`[graview] the ${this.props.view ?? "view"} of ${this.props.kind} threw while rendering`, error, info.componentStack);
|
|
33
38
|
this.context?.(error, { module: "@graview/react" });
|
|
39
|
+
this.props.onCaught?.(error);
|
|
40
|
+
}
|
|
41
|
+
/*
|
|
42
|
+
* THE KEYBOARD IS NEVER LEFT ON <body> (the watch's first rule). A view
|
|
43
|
+
* that held it and threw — a press ticked the store, the view threw on
|
|
44
|
+
* its redraw — took the focused element away with it: the panel takes the
|
|
45
|
+
* keyboard instead. A view drawn again while the panel holds it gives the
|
|
46
|
+
* keyboard to what it drew. Read before the page changes, kept after.
|
|
47
|
+
*/
|
|
48
|
+
panel = createRef();
|
|
49
|
+
getSnapshotBeforeUpdate() {
|
|
50
|
+
if (typeof document === "undefined")
|
|
51
|
+
return null;
|
|
52
|
+
const focused = document.activeElement;
|
|
53
|
+
const panel = this.panel.current;
|
|
54
|
+
if (panel && focused === panel)
|
|
55
|
+
return { onPanel: true, focused, parent: panel.parentNode, before: panel.previousSibling };
|
|
56
|
+
return { onPanel: false, focused };
|
|
57
|
+
}
|
|
58
|
+
componentDidUpdate(previous, previousState, was) {
|
|
59
|
+
if (was && !previousState.error && this.state.error && was.focused && was.focused !== document.body && !was.focused.isConnected && keyboardLost()) {
|
|
60
|
+
this.panel.current?.focus();
|
|
61
|
+
}
|
|
62
|
+
if (was?.onPanel && previousState.error && !this.state.error && keyboardLost()) {
|
|
63
|
+
const drawn = was.before ? was.before.nextSibling : (was.parent?.firstChild ?? null);
|
|
64
|
+
if (drawn instanceof HTMLElement) {
|
|
65
|
+
const first = drawn.matches(FOCUSABLE) ? drawn : drawn.querySelector(FOCUSABLE);
|
|
66
|
+
if (first)
|
|
67
|
+
first.focus();
|
|
68
|
+
else {
|
|
69
|
+
if (!drawn.hasAttribute("tabindex"))
|
|
70
|
+
drawn.setAttribute("tabindex", "-1");
|
|
71
|
+
drawn.focus();
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
if (!this.state.error)
|
|
76
|
+
return;
|
|
77
|
+
const before = previous.reset ?? [];
|
|
78
|
+
const now = this.props.reset ?? [];
|
|
79
|
+
if (before.length !== now.length || before.some((value, at) => !Object.is(value, now[at])))
|
|
80
|
+
this.setState({ error: undefined });
|
|
34
81
|
}
|
|
35
82
|
render() {
|
|
36
83
|
const { error } = this.state;
|
|
37
84
|
if (!error)
|
|
38
85
|
return this.props.children;
|
|
39
86
|
const hint = hintOf(error);
|
|
40
|
-
return (_jsxs("div", { role: "alert", "data-graview-view-error": this.props.kind, style: {
|
|
87
|
+
return (_jsxs("div", { ref: this.panel, role: "alert", tabIndex: -1, "data-graview-view-error": this.props.kind, style: {
|
|
41
88
|
display: "flex",
|
|
42
89
|
flexDirection: "column",
|
|
43
90
|
gap: "0.375rem",
|
|
@@ -51,7 +98,7 @@ export class ViewBoundary extends Component {
|
|
|
51
98
|
font: "var(--graview-font-body, 13px/1.45 system-ui)",
|
|
52
99
|
fontSize: "0.875rem",
|
|
53
100
|
lineHeight: 1.45,
|
|
54
|
-
}, children: [_jsx("strong", { style: { color: "var(--graview-warn, #b4462a)" }, children: this.props.view ? `${this.props.view} could not draw` : "This view could not draw" }), _jsx("span", { style: { color: "var(--graview-ink-muted, #555)" }, children: this.props.kind }), _jsx("span", { children: messageOf(error) }), hint ? _jsx("span", { style: { color: "var(--graview-ink-muted, #555)" }, children: hint }) : null] }));
|
|
101
|
+
}, children: [_jsx("strong", { style: { color: "var(--graview-warn, #b4462a)" }, children: this.props.view ? `${this.props.view} could not draw` : "This view could not draw" }), this.props.said === "" ? null : _jsx("span", { style: { color: "var(--graview-ink-muted, #555)" }, children: this.props.said ?? this.props.kind }), _jsx("span", { children: messageOf(error) }), hint ? _jsx("span", { style: { color: "var(--graview-ink-muted, #555)" }, children: hint }) : null] }));
|
|
55
102
|
}
|
|
56
103
|
}
|
|
57
104
|
//# sourceMappingURL=view-boundary.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"view-boundary.js","sourceRoot":"","sources":["../src/view-boundary.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAE,SAAS,EAAkC,MAAM,OAAO,CAAC;
|
|
1
|
+
{"version":3,"file":"view-boundary.js","sourceRoot":"","sources":["../src/view-boundary.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAE,SAAS,EAAE,SAAS,EAAkC,MAAM,OAAO,CAAC;AAC7E,OAAO,EAAE,kBAAkB,EAAoB,MAAM,mBAAmB,CAAC;AAEzE,OAAO,EAAE,kBAAkB,EAAoB,MAAM,mBAAmB,CAAC;AAkCzE;;;;GAIG;AACH,SAAS,MAAM,CAAC,KAAc;IAC5B,MAAM,IAAI,GAAI,KAAmC,EAAE,IAAI,CAAC;IACxD,OAAO,OAAO,IAAI,KAAK,QAAQ,IAAI,IAAI,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,SAAS,CAAC;AACxE,CAAC;AAED,SAAS,SAAS,CAAC,KAAc;IAC/B,IAAI,KAAK,YAAY,KAAK,IAAI,KAAK,CAAC,OAAO;QAAE,OAAO,KAAK,CAAC,OAAO,CAAC;IAClE,MAAM,IAAI,GAAG,MAAM,CAAC,KAAK,CAAC,CAAC;IAC3B,OAAO,IAAI,KAAK,iBAAiB,CAAC,CAAC,CAAC,mCAAmC,CAAC,CAAC,CAAC,IAAI,CAAC;AACjF,CAAC;AAQD,MAAM,SAAS,GAAG,qKAAqK,CAAC;AAExL,iFAAiF;AAC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C5E,EACR,IAAI,CAAC,KAAK,CAAC,IAAI,KAAK,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,eAAM,KAAK,EAAE,EAAE,KAAK,EAAE,gCAAgC,EAAE,YAAG,IAAI,CAAC,KAAK,CAAC,IAAI,IAAI,IAAI,CAAC,KAAK,CAAC,IAAI,GAAQ,EACtI,yBAAO,SAAS,CAAC,KAAK,CAAC,GAAQ,EAC9B,IAAI,CAAC,CAAC,CAAC,eAAM,KAAK,EAAE,EAAE,KAAK,EAAE,gCAAgC,EAAE,YAAG,IAAI,GAAQ,CAAC,CAAC,CAAC,IAAI,IAClF,CACP,CAAC;IACJ,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@graview/react",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.71",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"main": "./dist/index.js",
|
|
6
6
|
"types": "./dist/index.d.ts",
|
|
@@ -19,10 +19,10 @@
|
|
|
19
19
|
}
|
|
20
20
|
},
|
|
21
21
|
"dependencies": {
|
|
22
|
-
"@graview/core": "0.1.
|
|
23
|
-
"@graview/
|
|
24
|
-
"@graview/
|
|
25
|
-
"@graview/
|
|
22
|
+
"@graview/core": "0.1.71",
|
|
23
|
+
"@graview/layout": "0.1.71",
|
|
24
|
+
"@graview/render": "0.1.71",
|
|
25
|
+
"@graview/tools": "0.1.71"
|
|
26
26
|
},
|
|
27
27
|
"peerDependencies": {
|
|
28
28
|
"react": ">=18",
|