@canonical/prism 0.0.0-stage → 0.51.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +166 -0
- package/README.md +355 -2
- package/dist/esm/index.js +22 -0
- package/dist/esm/lib/Card/Card.js +16 -0
- package/dist/esm/lib/Card/CardView.js +19 -0
- package/dist/esm/lib/Card/index.js +2 -0
- package/dist/esm/lib/Card/styles.css +68 -0
- package/dist/esm/lib/Card/types.js +1 -0
- package/dist/esm/lib/Chip/Chip.js +16 -0
- package/dist/esm/lib/Chip/ChipView.js +14 -0
- package/dist/esm/lib/Chip/index.js +2 -0
- package/dist/esm/lib/Chip/styles.css +11 -0
- package/dist/esm/lib/Chip/types.js +1 -0
- package/dist/esm/lib/CommandPalette/CommandPalette.js +166 -0
- package/dist/esm/lib/CommandPalette/ThingOptions.js +38 -0
- package/dist/esm/lib/CommandPalette/index.js +1 -0
- package/dist/esm/lib/CommandPalette/styles.css +91 -0
- package/dist/esm/lib/CommandPalette/types.js +1 -0
- package/dist/esm/lib/Fact/FactValue.js +12 -0
- package/dist/esm/lib/Fact/index.js +1 -0
- package/dist/esm/lib/Fact/types.js +1 -0
- package/dist/esm/lib/Navigation/Navigation.js +46 -0
- package/dist/esm/lib/Navigation/index.js +1 -0
- package/dist/esm/lib/Navigation/styles.css +44 -0
- package/dist/esm/lib/Navigation/types.js +1 -0
- package/dist/esm/lib/PageHeader/PageHeader.js +16 -0
- package/dist/esm/lib/PageHeader/PageHeaderView.js +18 -0
- package/dist/esm/lib/PageHeader/index.js +2 -0
- package/dist/esm/lib/PageHeader/readParents.js +19 -0
- package/dist/esm/lib/PageHeader/styles.css +67 -0
- package/dist/esm/lib/PageHeader/types.js +1 -0
- package/dist/esm/lib/Prism/Prism.js +14 -0
- package/dist/esm/lib/Prism/context.js +10 -0
- package/dist/esm/lib/Prism/index.js +2 -0
- package/dist/esm/lib/Prism/types.js +1 -0
- package/dist/esm/lib/Prose/Prose.js +26 -0
- package/dist/esm/lib/Prose/findMention.js +22 -0
- package/dist/esm/lib/Prose/index.js +2 -0
- package/dist/esm/lib/Prose/styles.css +10 -0
- package/dist/esm/lib/Prose/types.js +1 -0
- package/dist/esm/lib/Row/Row.js +16 -0
- package/dist/esm/lib/Row/RowView.js +18 -0
- package/dist/esm/lib/Row/index.js +2 -0
- package/dist/esm/lib/Row/styles.css +28 -0
- package/dist/esm/lib/Row/types.js +1 -0
- package/dist/esm/lib/SearchBoundary/SearchBoundary.js +37 -0
- package/dist/esm/lib/SearchBoundary/index.js +1 -0
- package/dist/esm/lib/SearchBoundary/types.js +1 -0
- package/dist/esm/lib/SearchPage/SearchPage.js +35 -0
- package/dist/esm/lib/SearchPage/index.js +1 -0
- package/dist/esm/lib/SearchPage/styles.css +62 -0
- package/dist/esm/lib/SearchPage/types.js +1 -0
- package/dist/esm/lib/SiteLayout/SiteLayout.js +20 -0
- package/dist/esm/lib/SiteLayout/index.js +1 -0
- package/dist/esm/lib/SiteLayout/styles.css +112 -0
- package/dist/esm/lib/SiteLayout/types.js +1 -0
- package/dist/esm/lib/ThingLink/ThingLink.js +10 -0
- package/dist/esm/lib/ThingLink/index.js +1 -0
- package/dist/esm/lib/ThingLink/types.js +1 -0
- package/dist/esm/lib/ThingResults/ThingList.js +11 -0
- package/dist/esm/lib/ThingResults/ThingResults.js +36 -0
- package/dist/esm/lib/ThingResults/index.js +1 -0
- package/dist/esm/lib/ThingResults/types.js +1 -0
- package/dist/esm/lib/graphql/PrismCard.js +35 -0
- package/dist/esm/lib/graphql/PrismChip.js +17 -0
- package/dist/esm/lib/graphql/PrismClasses.js +33 -0
- package/dist/esm/lib/graphql/PrismFact.js +17 -0
- package/dist/esm/lib/graphql/PrismPageHeader.js +59 -0
- package/dist/esm/lib/graphql/PrismRow.js +32 -0
- package/dist/esm/lib/graphql/__generated__/PrismCard_node.graphql.js +136 -0
- package/dist/esm/lib/graphql/__generated__/PrismChip_node.graphql.js +64 -0
- package/dist/esm/lib/graphql/__generated__/PrismClasses_node.graphql.js +92 -0
- package/dist/esm/lib/graphql/__generated__/PrismFact_fact.graphql.js +46 -0
- package/dist/esm/lib/graphql/__generated__/PrismPageHeader_node.graphql.js +237 -0
- package/dist/esm/lib/graphql/__generated__/PrismRow_node.graphql.js +127 -0
- package/dist/esm/lib/graphql/index.js +6 -0
- package/dist/esm/lib/lens/constants.js +2 -0
- package/dist/esm/lib/lens/index.js +3 -0
- package/dist/esm/lib/lens/isShortcutKey.js +22 -0
- package/dist/esm/lib/lens/readLenses.js +106 -0
- package/dist/esm/lib/lens/types.js +1 -0
- package/dist/esm/lib/projection/findNearest.js +12 -0
- package/dist/esm/lib/projection/index.js +5 -0
- package/dist/esm/lib/projection/orderClasses.js +14 -0
- package/dist/esm/lib/projection/readHomes.js +43 -0
- package/dist/esm/lib/projection/types.js +1 -0
- package/dist/esm/lib/projection/useProjection.js +34 -0
- package/dist/esm/lib/projection/withLabel.js +9 -0
- package/dist/esm/lib/renderPage/index.js +1 -0
- package/dist/esm/lib/renderPage/renderPage.js +125 -0
- package/dist/esm/lib/renderPage/types.js +1 -0
- package/dist/esm/lib/search/filterLenses.js +11 -0
- package/dist/esm/lib/search/index.js +3 -0
- package/dist/esm/lib/search/searchVariables.js +11 -0
- package/dist/esm/lib/search/warmSearch.js +14 -0
- package/dist/esm/lib/searchQuery/PrismSearchQuery.js +23 -0
- package/dist/esm/lib/searchQuery/__generated__/PrismSearchQuery.graphql.js +304 -0
- package/dist/esm/lib/searchQuery/index.js +1 -0
- package/dist/esm/lib/warmQuery/index.js +1 -0
- package/dist/esm/lib/warmQuery/warmQuery.js +43 -0
- package/dist/esm/server.js +6 -0
- package/dist/types/index.d.ts +24 -0
- package/dist/types/lib/Card/Card.d.ts +8 -0
- package/dist/types/lib/Card/CardView.d.ts +11 -0
- package/dist/types/lib/Card/index.d.ts +3 -0
- package/dist/types/lib/Card/types.d.ts +31 -0
- package/dist/types/lib/Chip/Chip.d.ts +8 -0
- package/dist/types/lib/Chip/ChipView.d.ts +9 -0
- package/dist/types/lib/Chip/index.d.ts +3 -0
- package/dist/types/lib/Chip/types.d.ts +24 -0
- package/dist/types/lib/CommandPalette/CommandPalette.d.ts +16 -0
- package/dist/types/lib/CommandPalette/ThingOptions.d.ts +7 -0
- package/dist/types/lib/CommandPalette/index.d.ts +2 -0
- package/dist/types/lib/CommandPalette/types.d.ts +45 -0
- package/dist/types/lib/Fact/FactValue.d.ts +7 -0
- package/dist/types/lib/Fact/index.d.ts +2 -0
- package/dist/types/lib/Fact/types.d.ts +5 -0
- package/dist/types/lib/Navigation/Navigation.d.ts +15 -0
- package/dist/types/lib/Navigation/index.d.ts +2 -0
- package/dist/types/lib/Navigation/types.d.ts +6 -0
- package/dist/types/lib/PageHeader/PageHeader.d.ts +8 -0
- package/dist/types/lib/PageHeader/PageHeaderView.d.ts +10 -0
- package/dist/types/lib/PageHeader/index.d.ts +3 -0
- package/dist/types/lib/PageHeader/readParents.d.ts +13 -0
- package/dist/types/lib/PageHeader/types.d.ts +32 -0
- package/dist/types/lib/Prism/Prism.d.ts +8 -0
- package/dist/types/lib/Prism/context.d.ts +7 -0
- package/dist/types/lib/Prism/index.d.ts +3 -0
- package/dist/types/lib/Prism/types.d.ts +67 -0
- package/dist/types/lib/Prose/Prose.d.ts +11 -0
- package/dist/types/lib/Prose/findMention.d.ts +8 -0
- package/dist/types/lib/Prose/index.d.ts +3 -0
- package/dist/types/lib/Prose/types.d.ts +7 -0
- package/dist/types/lib/Row/Row.d.ts +8 -0
- package/dist/types/lib/Row/RowView.d.ts +12 -0
- package/dist/types/lib/Row/index.d.ts +3 -0
- package/dist/types/lib/Row/types.d.ts +25 -0
- package/dist/types/lib/SearchBoundary/SearchBoundary.d.ts +17 -0
- package/dist/types/lib/SearchBoundary/index.d.ts +2 -0
- package/dist/types/lib/SearchBoundary/types.d.ts +22 -0
- package/dist/types/lib/SearchPage/SearchPage.d.ts +15 -0
- package/dist/types/lib/SearchPage/index.d.ts +2 -0
- package/dist/types/lib/SearchPage/types.d.ts +10 -0
- package/dist/types/lib/SiteLayout/SiteLayout.d.ts +17 -0
- package/dist/types/lib/SiteLayout/index.d.ts +2 -0
- package/dist/types/lib/SiteLayout/types.d.ts +11 -0
- package/dist/types/lib/ThingLink/ThingLink.d.ts +8 -0
- package/dist/types/lib/ThingLink/index.d.ts +2 -0
- package/dist/types/lib/ThingLink/types.d.ts +9 -0
- package/dist/types/lib/ThingResults/ThingList.d.ts +4 -0
- package/dist/types/lib/ThingResults/ThingResults.d.ts +16 -0
- package/dist/types/lib/ThingResults/index.d.ts +2 -0
- package/dist/types/lib/ThingResults/types.d.ts +14 -0
- package/dist/types/lib/graphql/PrismCard.d.ts +6 -0
- package/dist/types/lib/graphql/PrismChip.d.ts +3 -0
- package/dist/types/lib/graphql/PrismClasses.d.ts +8 -0
- package/dist/types/lib/graphql/PrismFact.d.ts +6 -0
- package/dist/types/lib/graphql/PrismPageHeader.d.ts +8 -0
- package/dist/types/lib/graphql/PrismRow.d.ts +6 -0
- package/dist/types/lib/graphql/__generated__/PrismCard_node.graphql.d.ts +38 -0
- package/dist/types/lib/graphql/__generated__/PrismChip_node.graphql.d.ts +23 -0
- package/dist/types/lib/graphql/__generated__/PrismClasses_node.graphql.d.ts +33 -0
- package/dist/types/lib/graphql/__generated__/PrismFact_fact.graphql.d.ts +20 -0
- package/dist/types/lib/graphql/__generated__/PrismPageHeader_node.graphql.d.ts +60 -0
- package/dist/types/lib/graphql/__generated__/PrismRow_node.graphql.d.ts +35 -0
- package/dist/types/lib/graphql/index.d.ts +6 -0
- package/dist/types/lib/lens/constants.d.ts +2 -0
- package/dist/types/lib/lens/index.d.ts +4 -0
- package/dist/types/lib/lens/isShortcutKey.d.ts +6 -0
- package/dist/types/lib/lens/readLenses.d.ts +27 -0
- package/dist/types/lib/lens/types.d.ts +48 -0
- package/dist/types/lib/projection/findNearest.d.ts +6 -0
- package/dist/types/lib/projection/index.d.ts +6 -0
- package/dist/types/lib/projection/orderClasses.d.ts +19 -0
- package/dist/types/lib/projection/readHomes.d.ts +11 -0
- package/dist/types/lib/projection/types.d.ts +15 -0
- package/dist/types/lib/projection/useProjection.d.ts +9 -0
- package/dist/types/lib/projection/withLabel.d.ts +8 -0
- package/dist/types/lib/renderPage/index.d.ts +2 -0
- package/dist/types/lib/renderPage/renderPage.d.ts +21 -0
- package/dist/types/lib/renderPage/types.d.ts +49 -0
- package/dist/types/lib/search/filterLenses.d.ts +6 -0
- package/dist/types/lib/search/index.d.ts +3 -0
- package/dist/types/lib/search/searchVariables.d.ts +9 -0
- package/dist/types/lib/search/warmSearch.d.ts +9 -0
- package/dist/types/lib/searchQuery/PrismSearchQuery.d.ts +8 -0
- package/dist/types/lib/searchQuery/__generated__/PrismSearchQuery.graphql.d.ts +26 -0
- package/dist/types/lib/searchQuery/index.d.ts +1 -0
- package/dist/types/lib/warmQuery/index.d.ts +1 -0
- package/dist/types/lib/warmQuery/warmQuery.d.ts +19 -0
- package/dist/types/server.d.ts +6 -0
- package/package.json +108 -4
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A target with every percent-escape read, reserved characters such as `#`,
|
|
3
|
+
* `/` and `?` included, or as it is when an escape is broken.
|
|
4
|
+
*/
|
|
5
|
+
function decode(target) {
|
|
6
|
+
try {
|
|
7
|
+
return decodeURIComponent(target);
|
|
8
|
+
}
|
|
9
|
+
catch {
|
|
10
|
+
return target;
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* The mentioned thing a link points at, by its IRI or its compact name,
|
|
15
|
+
* written as is or percent-encoded, as a Markdown parser hands a link's
|
|
16
|
+
* target over. A site's link component calls it to draw `<Chip>` for a
|
|
17
|
+
* thing and an ordinary link for anything else.
|
|
18
|
+
*/
|
|
19
|
+
export default function findMention(mentions, href) {
|
|
20
|
+
const target = decode(href);
|
|
21
|
+
return mentions.find(({ uri, curie }) => [uri, curie].some((name) => name === href || decode(name) === target));
|
|
22
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/* The text keeps the design system's own typography; only the last block
|
|
2
|
+
* gives up its space after, so the text ends where its container does. */
|
|
3
|
+
|
|
4
|
+
/* Layer: lib, the layer @canonical/styles keeps for a library outside the
|
|
5
|
+
* design system, above every design-system layer and below the site's app. */
|
|
6
|
+
@layer lib {
|
|
7
|
+
.prism-prose > :last-child {
|
|
8
|
+
margin-block-end: 0;
|
|
9
|
+
}
|
|
10
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { useFragment } from "react-relay";
|
|
3
|
+
import { prismRowFragment } from "../graphql/index.js";
|
|
4
|
+
import { useProjection, withLabel } from "../projection/index.js";
|
|
5
|
+
import RowView from "./RowView.js";
|
|
6
|
+
/**
|
|
7
|
+
* A thing as a row of a list, for any kind of thing: it reads the thing's
|
|
8
|
+
* slots and draws the site's row for the thing's nearest class, or the plain
|
|
9
|
+
* `RowView`.
|
|
10
|
+
*/
|
|
11
|
+
export default function Row({ node, linked = true, ...props }) {
|
|
12
|
+
const data = useFragment(prismRowFragment, node);
|
|
13
|
+
const { uri, Override, home } = useProjection(data, "row");
|
|
14
|
+
const View = Override ?? RowView;
|
|
15
|
+
return (_jsx(View, { ...props, home: linked ? home : undefined, slots: withLabel(data._meta.slots, data._meta.curie, uri), uri: uri }));
|
|
16
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { Fragment as _Fragment, jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { ThingLink } from "../ThingLink/index.js";
|
|
3
|
+
import "./styles.css";
|
|
4
|
+
const componentCssClassName = "prism-row";
|
|
5
|
+
/**
|
|
6
|
+
* The plain row: one line of a list, with the thing's label, linked to its
|
|
7
|
+
* page when it has one, then its category and, when it has one, its status,
|
|
8
|
+
* as text: the label of the thing a status names (its compact name when the
|
|
9
|
+
* label has no text), or its value.
|
|
10
|
+
* The spaces between them are for a screen reader, which reads the row as
|
|
11
|
+
* one phrase; the flex layout draws the gaps.
|
|
12
|
+
*/
|
|
13
|
+
export default function RowView({ uri, slots, home, className, ...props }) {
|
|
14
|
+
return (_jsxs("div", { className: [componentCssClassName, className].filter(Boolean).join(" "), ...props, children: [_jsx("span", { className: `${componentCssClassName}-label`, dir: "auto", children: home === undefined ? (slots.label) : (_jsx(ThingLink, { home: home, uri: uri, children: slots.label })) }), " ", _jsx("span", { className: `${componentCssClassName}-category`, children: slots.category }), slots.status ? (_jsxs(_Fragment, { children: [" ", _jsx("span", { className: `${componentCssClassName}-status`, children: slots.status.node
|
|
15
|
+
? slots.status.node._meta.slots.label.trim() ||
|
|
16
|
+
slots.status.node._meta.curie
|
|
17
|
+
: slots.status.value })] })) : null] }));
|
|
18
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
/* One line of a list, on the 8px rhythm: a 24px line in a 48px row. The
|
|
2
|
+
* label is in ink, the category and the status in the muted text colour, all
|
|
3
|
+
* at one size; a long label wraps rather than pushing the rest out. */
|
|
4
|
+
|
|
5
|
+
/* Layer: lib, the layer @canonical/styles keeps for a library outside the
|
|
6
|
+
* design system, above every design-system layer and below the site's app. */
|
|
7
|
+
@layer lib {
|
|
8
|
+
.prism-row {
|
|
9
|
+
display: flex;
|
|
10
|
+
flex-wrap: wrap;
|
|
11
|
+
align-items: baseline;
|
|
12
|
+
column-gap: var(--space-200);
|
|
13
|
+
min-block-size: var(--space-600);
|
|
14
|
+
padding-block: var(--space-150);
|
|
15
|
+
line-height: var(--space-300);
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
.prism-row-label {
|
|
19
|
+
min-inline-size: 0;
|
|
20
|
+
overflow-wrap: anywhere;
|
|
21
|
+
color: var(--color-text);
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
.prism-row-category,
|
|
25
|
+
.prism-row-status {
|
|
26
|
+
color: var(--color-text-muted);
|
|
27
|
+
}
|
|
28
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { Component } from "react";
|
|
2
|
+
/**
|
|
3
|
+
* Keeps a failed search to the results it would have drawn: the search
|
|
4
|
+
* field fails, the rest of the page stays. Its children stay mounted while
|
|
5
|
+
* nothing fails, so the last results stay on screen while the next answer
|
|
6
|
+
* is on its way. A failure is remembered only for the words that failed:
|
|
7
|
+
* any other words try again, and so do those words once the reader has
|
|
8
|
+
* typed something else.
|
|
9
|
+
*/
|
|
10
|
+
export default class SearchBoundary extends Component {
|
|
11
|
+
state = { failedText: undefined, attempt: 0 };
|
|
12
|
+
static getDerivedStateFromError() {
|
|
13
|
+
// The words are not known here; componentDidCatch records them.
|
|
14
|
+
return { failedText: null };
|
|
15
|
+
}
|
|
16
|
+
componentDidCatch() {
|
|
17
|
+
this.setState({ failedText: this.props.text });
|
|
18
|
+
}
|
|
19
|
+
componentDidUpdate(previous) {
|
|
20
|
+
const { failedText } = this.state;
|
|
21
|
+
if (previous.text !== this.props.text &&
|
|
22
|
+
typeof failedText === "string" &&
|
|
23
|
+
failedText !== this.props.text) {
|
|
24
|
+
this.setState(({ attempt }) => ({
|
|
25
|
+
failedText: undefined,
|
|
26
|
+
attempt: attempt + 1,
|
|
27
|
+
}));
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
render() {
|
|
31
|
+
const { failedText } = this.state;
|
|
32
|
+
const failed = failedText === null || failedText === this.props.text;
|
|
33
|
+
return failed
|
|
34
|
+
? this.props.fallback
|
|
35
|
+
: this.props.children(this.state.attempt);
|
|
36
|
+
}
|
|
37
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { default as SearchBoundary } from "./SearchBoundary.js";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { Button } from "@canonical/react-ds-global";
|
|
3
|
+
import { Link, useRoute, useRouter } from "@canonical/router-react";
|
|
4
|
+
import { useMemo } from "react";
|
|
5
|
+
import { readLenses } from "../lens/index.js";
|
|
6
|
+
import { filterLenses, searchVariables } from "../search/index.js";
|
|
7
|
+
import { ThingResults } from "../ThingResults/index.js";
|
|
8
|
+
import "./styles.css";
|
|
9
|
+
const componentCssClassName = "prism-search-page";
|
|
10
|
+
/**
|
|
11
|
+
* The field's id. A page has one search page, and the server renders the
|
|
12
|
+
* whole document while the browser hydrates only its root, so an id from
|
|
13
|
+
* `useId` would differ between the two: this one is fixed.
|
|
14
|
+
*/
|
|
15
|
+
const id = `${componentCssClassName}-query`;
|
|
16
|
+
/**
|
|
17
|
+
* The search page: what the command palette does, at its own address, for a
|
|
18
|
+
* reader without scripts. It reads the query from the address's `q`, and its
|
|
19
|
+
* form sends a new one there with a plain GET, so it works the same rendered
|
|
20
|
+
* on the server or in the browser.
|
|
21
|
+
*
|
|
22
|
+
* With `graph`, it also lists the things the graph's `search` field finds,
|
|
23
|
+
* each drawn as a `Row`; the search route's `warm` fetches them with
|
|
24
|
+
* `warmSearch`, so the server renders them. A failed search says so and
|
|
25
|
+
* leaves the rest of the page.
|
|
26
|
+
*/
|
|
27
|
+
export default function SearchPage({ className, graph = false, }) {
|
|
28
|
+
const router = useRouter();
|
|
29
|
+
const location = useRoute();
|
|
30
|
+
const lenses = useMemo(() => readLenses(router.routes, (name) => router.buildPath(name)), [router]);
|
|
31
|
+
const query = location.searchParams.get("q") ?? "";
|
|
32
|
+
const results = filterLenses(lenses, query);
|
|
33
|
+
const variables = graph ? searchVariables(query) : undefined;
|
|
34
|
+
return (_jsxs("section", { "aria-labelledby": `${id}-heading`, className: [componentCssClassName, className].filter(Boolean).join(" "), children: [_jsx("h1", { className: `${componentCssClassName}-heading`, id: `${id}-heading`, children: "Search" }), _jsx("search", { children: _jsxs("form", { action: location.pathname, className: `${componentCssClassName}-form`, method: "get", children: [_jsx("label", { className: `${componentCssClassName}-label`, htmlFor: id, children: graph ? "Search the site" : "Search the lenses" }), _jsx("input", { className: `${componentCssClassName}-input`, defaultValue: query, id: id, name: "q", type: "search" }, query), _jsx(Button, { type: "submit", children: "Search" })] }) }), _jsxs("p", { className: `${componentCssClassName}-count`, role: "status", children: [results.length === 1 ? "1 lens" : `${results.length} lenses`, query ? ` match “${query}”` : ""] }), _jsx("ul", { className: `${componentCssClassName}-results`, children: results.map(({ name, label }) => (_jsx("li", { className: `${componentCssClassName}-result`, children: _jsx(Link, { to: name, children: label }) }, name))) }), variables ? (_jsx(ThingResults, { query: query.trim(), variables: variables })) : null] }));
|
|
35
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { default as SearchPage } from "./SearchPage.js";
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
/* The search page sits on the page's intrinsic grid as a subgrid: the
|
|
2
|
+
* heading, the form and the count take whole rows, and each result is a cell
|
|
3
|
+
* of four columns, so the results run one to a row on a phone and two, three
|
|
4
|
+
* or more side by side as the page widens, with no breakpoint. Rows are
|
|
5
|
+
* spaced on the 8px rhythm. */
|
|
6
|
+
|
|
7
|
+
/* Layer: lib, the layer @canonical/styles keeps for a library outside the
|
|
8
|
+
* design system, above every design-system layer and below the site's app. */
|
|
9
|
+
@layer lib {
|
|
10
|
+
.prism-search-page {
|
|
11
|
+
display: grid;
|
|
12
|
+
grid-template-columns: subgrid;
|
|
13
|
+
row-gap: var(--space-300);
|
|
14
|
+
align-content: start;
|
|
15
|
+
padding: var(--space-300) var(--grid-margin);
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
.prism-search-page > * {
|
|
19
|
+
grid-column: 1 / -1;
|
|
20
|
+
margin: 0;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
.prism-search-page-form {
|
|
24
|
+
display: flex;
|
|
25
|
+
flex-wrap: wrap;
|
|
26
|
+
align-items: center;
|
|
27
|
+
gap: var(--space-100) var(--space-200);
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
.prism-search-page-label {
|
|
31
|
+
flex: 1 0 100%;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
.prism-search-page-input {
|
|
35
|
+
flex: 1 1 auto;
|
|
36
|
+
min-inline-size: 0;
|
|
37
|
+
font: inherit;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
.prism-search-page-count {
|
|
41
|
+
color: var(--color-text-muted);
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
.prism-search-page-results {
|
|
45
|
+
display: grid;
|
|
46
|
+
grid-template-columns: subgrid;
|
|
47
|
+
row-gap: var(--space-100);
|
|
48
|
+
padding: 0;
|
|
49
|
+
list-style: none;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
.prism-search-page-result {
|
|
53
|
+
grid-column: span 4;
|
|
54
|
+
line-height: var(--space-300);
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
/* A thing found in the graph takes a whole row of the page: its label, its
|
|
58
|
+
* category and its status read as one line. */
|
|
59
|
+
.prism-search-page-thing {
|
|
60
|
+
grid-column: 1 / -1;
|
|
61
|
+
}
|
|
62
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import "./styles.css";
|
|
3
|
+
const componentCssClassName = "prism-site-layout";
|
|
4
|
+
const canvasId = "prism-canvas";
|
|
5
|
+
/**
|
|
6
|
+
* The frame of a Prism site: the navigation in a column of its own, off the
|
|
7
|
+
* grid at a fixed width, and the page on the intrinsic grid beside it. Put it
|
|
8
|
+
* in a router wrapper shared by the site's routes, so it stays mounted while
|
|
9
|
+
* the reader moves between pages; on a small screen the navigation moves
|
|
10
|
+
* above the page.
|
|
11
|
+
*
|
|
12
|
+
* The page region is a `.grid.intrinsic` from `@canonical/styles`, with one
|
|
13
|
+
* correction: below the width of four 100px columns the minimum gives way, so
|
|
14
|
+
* a phone still gets four columns and never scrolls sideways. Each child of
|
|
15
|
+
* the page region takes a whole row; a page lays out its own parts on the
|
|
16
|
+
* grid with spans of 2, 4 or 8 columns.
|
|
17
|
+
*/
|
|
18
|
+
export default function SiteLayout({ navigation, header, children, className, }) {
|
|
19
|
+
return (_jsxs("div", { className: [componentCssClassName, className].filter(Boolean).join(" "), children: [_jsx("a", { className: `${componentCssClassName}-skip`, href: `#${canvasId}`, children: "Skip to content" }), _jsx("div", { className: `${componentCssClassName}-navigation`, children: navigation }), header === undefined ? null : (_jsx("div", { className: `${componentCssClassName}-header`, children: header })), _jsx("main", { className: `${componentCssClassName}-page grid intrinsic`, id: canvasId, tabIndex: -1, children: children })] }));
|
|
20
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { default as SiteLayout } from "./SiteLayout.js";
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
/* The frame: the navigation off the grid at a fixed width (30 lines of the
|
|
2
|
+
* 8px rhythm), the header band and the page beside it. Each region scrolls on
|
|
3
|
+
* its own; the frame never does. */
|
|
4
|
+
|
|
5
|
+
/* Layer: lib, the layer @canonical/styles keeps for a library outside the
|
|
6
|
+
* design system, above every design-system layer and below the site's app. */
|
|
7
|
+
@layer lib {
|
|
8
|
+
.prism-site-layout {
|
|
9
|
+
--prism-navigation-width: calc(30 * var(--space-100));
|
|
10
|
+
|
|
11
|
+
position: relative;
|
|
12
|
+
display: grid;
|
|
13
|
+
grid-template-columns: var(--prism-navigation-width) minmax(0, 1fr);
|
|
14
|
+
grid-template-rows: min-content minmax(0, 1fr);
|
|
15
|
+
grid-template-areas:
|
|
16
|
+
"navigation header"
|
|
17
|
+
"navigation page";
|
|
18
|
+
block-size: 100dvh;
|
|
19
|
+
overflow: clip;
|
|
20
|
+
background: var(--color-background);
|
|
21
|
+
color: var(--color-text);
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
.prism-site-layout-skip {
|
|
25
|
+
position: absolute;
|
|
26
|
+
inset-block-start: var(--space-100);
|
|
27
|
+
inset-inline-start: var(--space-100);
|
|
28
|
+
z-index: 1;
|
|
29
|
+
padding: var(--space-100) var(--space-200);
|
|
30
|
+
background: var(--color-background);
|
|
31
|
+
color: var(--color-text);
|
|
32
|
+
transform: translateY(-200%);
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
.prism-site-layout-skip:focus {
|
|
36
|
+
transform: none;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
.prism-site-layout-navigation {
|
|
40
|
+
grid-area: navigation;
|
|
41
|
+
min-block-size: 0;
|
|
42
|
+
overflow: auto;
|
|
43
|
+
border-inline-end: var(--space-025) solid var(--color-border-muted);
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
.prism-site-layout-header {
|
|
47
|
+
grid-area: header;
|
|
48
|
+
min-inline-size: 0;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/* The page is `.grid.intrinsic` with one correction: each column's minimum
|
|
52
|
+
* is the smaller of --grid-col-min and a quarter of the width (less three
|
|
53
|
+
* gaps), so below four columns' width the columns shrink instead of falling
|
|
54
|
+
* to fewer than four. A phone keeps four columns and never scrolls sideways. */
|
|
55
|
+
.prism-site-layout-page {
|
|
56
|
+
--prism-grid-gap: var(
|
|
57
|
+
--grid-column-gap,
|
|
58
|
+
var(--grid-gap, var(--grid-gutter))
|
|
59
|
+
);
|
|
60
|
+
--prism-grid-column: minmax(
|
|
61
|
+
min(var(--grid-col-min), calc((100% - 3 * var(--prism-grid-gap)) / 4)),
|
|
62
|
+
1fr
|
|
63
|
+
);
|
|
64
|
+
--grid-intrinsic: repeat(
|
|
65
|
+
auto-fill,
|
|
66
|
+
var(--prism-grid-column) var(--prism-grid-column) var(--prism-grid-column)
|
|
67
|
+
var(--prism-grid-column)
|
|
68
|
+
);
|
|
69
|
+
--grid-row-gap: 0;
|
|
70
|
+
|
|
71
|
+
grid-area: page;
|
|
72
|
+
min-inline-size: 0;
|
|
73
|
+
min-block-size: 0;
|
|
74
|
+
overflow: auto;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
.prism-site-layout-page:focus {
|
|
78
|
+
outline: none;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
.prism-site-layout-page > * {
|
|
82
|
+
grid-column: 1 / -1;
|
|
83
|
+
min-inline-size: 0;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
/* The one layout that changes with the screen: below the width of the
|
|
87
|
+
* navigation and four columns, the frame becomes a plain document, with the
|
|
88
|
+
* navigation above the page and the whole page scrolling. */
|
|
89
|
+
@media (width < 45rem) {
|
|
90
|
+
.prism-site-layout {
|
|
91
|
+
grid-template-columns: minmax(0, 1fr);
|
|
92
|
+
grid-template-rows: min-content min-content min-content;
|
|
93
|
+
grid-template-areas:
|
|
94
|
+
"navigation"
|
|
95
|
+
"header"
|
|
96
|
+
"page";
|
|
97
|
+
block-size: auto;
|
|
98
|
+
min-block-size: 100dvh;
|
|
99
|
+
overflow: visible;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
.prism-site-layout-navigation {
|
|
103
|
+
overflow: visible;
|
|
104
|
+
border-inline-end: 0;
|
|
105
|
+
border-block-end: var(--space-025) solid var(--color-border-muted);
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
.prism-site-layout-page {
|
|
109
|
+
overflow: visible;
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { Link } from "@canonical/router-react";
|
|
3
|
+
/**
|
|
4
|
+
* A link to a thing's page: its home route, with its IRI as `uri`. A home
|
|
5
|
+
* route's name is read from the route table at run time, so the router's
|
|
6
|
+
* types cannot check it or its params.
|
|
7
|
+
*/
|
|
8
|
+
export default function ThingLink({ home, uri, ...props }) {
|
|
9
|
+
return _jsx(Link, { ...props, params: { uri }, to: home });
|
|
10
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { default as ThingLink } from "./ThingLink.js";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { Fragment as _Fragment, jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { useLazyLoadQuery } from "react-relay";
|
|
3
|
+
import { Row } from "../Row/index.js";
|
|
4
|
+
import { prismSearchQuery, } from "../searchQuery/index.js";
|
|
5
|
+
const componentCssClassName = "prism-search-page";
|
|
6
|
+
/** The things matching a query, each drawn as a row in a list, under a count. */
|
|
7
|
+
export default function ThingList({ variables, query, fetchPolicy, fetchKey, }) {
|
|
8
|
+
const { search } = useLazyLoadQuery(prismSearchQuery, variables, { fetchPolicy, fetchKey });
|
|
9
|
+
const count = search.edges.length;
|
|
10
|
+
return (_jsxs(_Fragment, { children: [_jsxs("p", { className: `${componentCssClassName}-count`, role: "status", children: [count === 1 ? "1 thing matches" : `${count} things match`, " \u201C", query, "\u201D"] }), _jsx("ul", { className: `${componentCssClassName}-results`, children: search.edges.map(({ node }, index) => (_jsx("li", { className: `${componentCssClassName}-thing`, children: _jsx(Row, { node: node }) }, `${index}:${node.uri}`))) })] }));
|
|
11
|
+
}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { Suspense, useSyncExternalStore } from "react";
|
|
3
|
+
import { useRelayEnvironment } from "react-relay";
|
|
4
|
+
import { createOperationDescriptor, getRequest } from "relay-runtime";
|
|
5
|
+
import { SearchBoundary } from "../SearchBoundary/index.js";
|
|
6
|
+
import { prismSearchQuery } from "../searchQuery/index.js";
|
|
7
|
+
import ThingList from "./ThingList.js";
|
|
8
|
+
const componentCssClassName = "prism-search-page";
|
|
9
|
+
const subscribeToNothing = () => () => { };
|
|
10
|
+
/**
|
|
11
|
+
* `true` on the server and during the browser's hydration pass, `false`
|
|
12
|
+
* once the page has hydrated; React renders again when it flips.
|
|
13
|
+
*/
|
|
14
|
+
function useIsHydrating() {
|
|
15
|
+
return useSyncExternalStore(subscribeToNothing, () => false, () => true);
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* The things the graph's search finds, on the search page.
|
|
19
|
+
*
|
|
20
|
+
* On the server, error boundaries do not run and a fetch during the render
|
|
21
|
+
* would ask the graph a second time, in the middle of the stream: so the
|
|
22
|
+
* list renders only from what the search route's `warm` put in the store,
|
|
23
|
+
* read without fetching, and the page says the search is unavailable when
|
|
24
|
+
* the store does not have it. The browser's hydration pass makes the same
|
|
25
|
+
* choice from the records the server sent, so the markup matches; once
|
|
26
|
+
* hydrated, the list fetches what the server did not have, says
|
|
27
|
+
* "Searching…" meanwhile, and says the search is unavailable when it fails.
|
|
28
|
+
* Both sides render the same boundary and suspense around it.
|
|
29
|
+
*/
|
|
30
|
+
export default function ThingResults({ variables, query, }) {
|
|
31
|
+
const environment = useRelayEnvironment();
|
|
32
|
+
const hydrating = useIsHydrating();
|
|
33
|
+
const answered = environment.check(createOperationDescriptor(getRequest(prismSearchQuery), variables)).status === "available";
|
|
34
|
+
const unavailable = (_jsx("p", { className: `${componentCssClassName}-count`, role: "status", children: "Search is unavailable." }));
|
|
35
|
+
return (_jsx(SearchBoundary, { fallback: unavailable, text: variables.text, children: (attempt) => (_jsx(Suspense, { fallback: _jsx("p", { className: `${componentCssClassName}-count`, children: "Searching\u2026" }), children: !hydrating ? (_jsx(ThingList, { fetchKey: attempt, query: query, variables: variables })) : answered ? (_jsx(ThingList, { fetchPolicy: "store-only", query: query, variables: variables })) : (unavailable) })) }));
|
|
36
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { default as ThingResults } from "./ThingResults.js";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { graphql } from "react-relay";
|
|
2
|
+
import node from "./__generated__/PrismCard_node.graphql.js";
|
|
3
|
+
/**
|
|
4
|
+
* What a card reads: every slot but the parent, with the default three
|
|
5
|
+
* facts.
|
|
6
|
+
*/
|
|
7
|
+
export const prismCardFragment = node;
|
|
8
|
+
// Read by relay-compiler only; see PrismClasses.ts.
|
|
9
|
+
void (() => graphql `
|
|
10
|
+
fragment PrismCard_node on Node {
|
|
11
|
+
uri
|
|
12
|
+
...PrismClasses_node
|
|
13
|
+
_meta {
|
|
14
|
+
curie
|
|
15
|
+
slots {
|
|
16
|
+
label
|
|
17
|
+
category
|
|
18
|
+
description
|
|
19
|
+
location {
|
|
20
|
+
...PrismFact_fact
|
|
21
|
+
}
|
|
22
|
+
version {
|
|
23
|
+
...PrismFact_fact
|
|
24
|
+
}
|
|
25
|
+
status {
|
|
26
|
+
...PrismFact_fact
|
|
27
|
+
}
|
|
28
|
+
facts {
|
|
29
|
+
name
|
|
30
|
+
...PrismFact_fact
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
`);
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { graphql } from "react-relay";
|
|
2
|
+
import node from "./__generated__/PrismChip_node.graphql.js";
|
|
3
|
+
/** What a chip reads: the thing's label. */
|
|
4
|
+
export const prismChipFragment = node;
|
|
5
|
+
// Read by relay-compiler only; see PrismClasses.ts.
|
|
6
|
+
void (() => graphql `
|
|
7
|
+
fragment PrismChip_node on Node {
|
|
8
|
+
uri
|
|
9
|
+
...PrismClasses_node
|
|
10
|
+
_meta {
|
|
11
|
+
curie
|
|
12
|
+
slots {
|
|
13
|
+
label
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
`);
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { graphql } from "react-relay";
|
|
2
|
+
import node from "./__generated__/PrismClasses_node.graphql.js";
|
|
3
|
+
/**
|
|
4
|
+
* A thing's identity, its class and every ancestor of that class, each with
|
|
5
|
+
* how many ancestors it has in turn, from which the engine orders them
|
|
6
|
+
* nearest first. An override and a home route are each looked up along that
|
|
7
|
+
* order.
|
|
8
|
+
*/
|
|
9
|
+
export const prismClassesFragment = node;
|
|
10
|
+
// relay-compiler reads this tag; the module exports the compiled artifact, so
|
|
11
|
+
// neither the engine nor a site needs a bundler transform. Never invoked.
|
|
12
|
+
void (() => graphql `
|
|
13
|
+
fragment PrismClasses_node on Node {
|
|
14
|
+
uri
|
|
15
|
+
_meta {
|
|
16
|
+
type {
|
|
17
|
+
uri
|
|
18
|
+
_meta {
|
|
19
|
+
curie
|
|
20
|
+
}
|
|
21
|
+
superclasses {
|
|
22
|
+
uri
|
|
23
|
+
_meta {
|
|
24
|
+
curie
|
|
25
|
+
}
|
|
26
|
+
superclasses {
|
|
27
|
+
uri
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
`);
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { graphql } from "react-relay";
|
|
2
|
+
import node from "./__generated__/PrismFact_fact.graphql.js";
|
|
3
|
+
/**
|
|
4
|
+
* One value a thing shows: its property's name, its display value, and the
|
|
5
|
+
* thing it names, drawn as a chip, when it names one.
|
|
6
|
+
*/
|
|
7
|
+
export const prismFactFragment = node;
|
|
8
|
+
// Read by relay-compiler only; see PrismClasses.ts.
|
|
9
|
+
void (() => graphql `
|
|
10
|
+
fragment PrismFact_fact on EntityFact {
|
|
11
|
+
name
|
|
12
|
+
value
|
|
13
|
+
node {
|
|
14
|
+
...PrismChip_node
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
`);
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import { graphql } from "react-relay";
|
|
2
|
+
import node from "./__generated__/PrismPageHeader_node.graphql.js";
|
|
3
|
+
/**
|
|
4
|
+
* What a page header reads: the label, category, location, version, status
|
|
5
|
+
* and description, and the thing's parents three deep. Parents may form a
|
|
6
|
+
* cycle, so the walk stops at a fixed depth, and the header stops earlier at
|
|
7
|
+
* the first thing it has already shown.
|
|
8
|
+
*/
|
|
9
|
+
export const prismPageHeaderFragment = node;
|
|
10
|
+
// Read by relay-compiler only; see PrismClasses.ts.
|
|
11
|
+
void (() => graphql `
|
|
12
|
+
fragment PrismPageHeader_node on Node {
|
|
13
|
+
uri
|
|
14
|
+
...PrismClasses_node
|
|
15
|
+
_meta {
|
|
16
|
+
curie
|
|
17
|
+
slots {
|
|
18
|
+
label
|
|
19
|
+
category
|
|
20
|
+
description
|
|
21
|
+
location {
|
|
22
|
+
...PrismFact_fact
|
|
23
|
+
}
|
|
24
|
+
version {
|
|
25
|
+
...PrismFact_fact
|
|
26
|
+
}
|
|
27
|
+
status {
|
|
28
|
+
...PrismFact_fact
|
|
29
|
+
}
|
|
30
|
+
parent {
|
|
31
|
+
node {
|
|
32
|
+
uri
|
|
33
|
+
...PrismChip_node
|
|
34
|
+
_meta {
|
|
35
|
+
slots {
|
|
36
|
+
parent {
|
|
37
|
+
node {
|
|
38
|
+
uri
|
|
39
|
+
...PrismChip_node
|
|
40
|
+
_meta {
|
|
41
|
+
slots {
|
|
42
|
+
parent {
|
|
43
|
+
node {
|
|
44
|
+
uri
|
|
45
|
+
...PrismChip_node
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
`);
|