@canonical/prism 0.0.0-stage → 0.51.0-experimental.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/README.md +357 -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 +107 -4
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @generated SignedSource<<2c053e50927532c24f39f8b857780a96>>
|
|
3
|
+
* @lightSyntaxTransform
|
|
4
|
+
*/
|
|
5
|
+
import type { ReaderFragment } from 'relay-runtime';
|
|
6
|
+
import type { FragmentRefs } from "relay-runtime";
|
|
7
|
+
export type PrismPageHeader_node$data = {
|
|
8
|
+
readonly _meta: {
|
|
9
|
+
readonly curie: string;
|
|
10
|
+
readonly slots: {
|
|
11
|
+
readonly category: string;
|
|
12
|
+
readonly description: string | null | undefined;
|
|
13
|
+
readonly label: string;
|
|
14
|
+
readonly location: {
|
|
15
|
+
readonly " $fragmentSpreads": FragmentRefs<"PrismFact_fact">;
|
|
16
|
+
} | null | undefined;
|
|
17
|
+
readonly parent: {
|
|
18
|
+
readonly node: {
|
|
19
|
+
readonly _meta: {
|
|
20
|
+
readonly slots: {
|
|
21
|
+
readonly parent: {
|
|
22
|
+
readonly node: {
|
|
23
|
+
readonly _meta: {
|
|
24
|
+
readonly slots: {
|
|
25
|
+
readonly parent: {
|
|
26
|
+
readonly node: {
|
|
27
|
+
readonly uri: string;
|
|
28
|
+
readonly " $fragmentSpreads": FragmentRefs<"PrismChip_node">;
|
|
29
|
+
} | null | undefined;
|
|
30
|
+
} | null | undefined;
|
|
31
|
+
};
|
|
32
|
+
};
|
|
33
|
+
readonly uri: string;
|
|
34
|
+
readonly " $fragmentSpreads": FragmentRefs<"PrismChip_node">;
|
|
35
|
+
} | null | undefined;
|
|
36
|
+
} | null | undefined;
|
|
37
|
+
};
|
|
38
|
+
};
|
|
39
|
+
readonly uri: string;
|
|
40
|
+
readonly " $fragmentSpreads": FragmentRefs<"PrismChip_node">;
|
|
41
|
+
} | null | undefined;
|
|
42
|
+
} | null | undefined;
|
|
43
|
+
readonly status: {
|
|
44
|
+
readonly " $fragmentSpreads": FragmentRefs<"PrismFact_fact">;
|
|
45
|
+
} | null | undefined;
|
|
46
|
+
readonly version: {
|
|
47
|
+
readonly " $fragmentSpreads": FragmentRefs<"PrismFact_fact">;
|
|
48
|
+
} | null | undefined;
|
|
49
|
+
};
|
|
50
|
+
};
|
|
51
|
+
readonly uri: string;
|
|
52
|
+
readonly " $fragmentSpreads": FragmentRefs<"PrismClasses_node">;
|
|
53
|
+
readonly " $fragmentType": "PrismPageHeader_node";
|
|
54
|
+
};
|
|
55
|
+
export type PrismPageHeader_node$key = {
|
|
56
|
+
readonly " $data"?: PrismPageHeader_node$data;
|
|
57
|
+
readonly " $fragmentSpreads": FragmentRefs<"PrismPageHeader_node">;
|
|
58
|
+
};
|
|
59
|
+
declare const node: ReaderFragment;
|
|
60
|
+
export default node;
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @generated SignedSource<<cf76fbf26467e2b6af5c7d2212890e21>>
|
|
3
|
+
* @lightSyntaxTransform
|
|
4
|
+
*/
|
|
5
|
+
import type { ReaderFragment } from 'relay-runtime';
|
|
6
|
+
import type { FragmentRefs } from "relay-runtime";
|
|
7
|
+
export type PrismRow_node$data = {
|
|
8
|
+
readonly _meta: {
|
|
9
|
+
readonly curie: string;
|
|
10
|
+
readonly slots: {
|
|
11
|
+
readonly category: string;
|
|
12
|
+
readonly label: string;
|
|
13
|
+
readonly status: {
|
|
14
|
+
readonly node: {
|
|
15
|
+
readonly _meta: {
|
|
16
|
+
readonly curie: string;
|
|
17
|
+
readonly slots: {
|
|
18
|
+
readonly label: string;
|
|
19
|
+
};
|
|
20
|
+
};
|
|
21
|
+
} | null | undefined;
|
|
22
|
+
readonly value: string;
|
|
23
|
+
} | null | undefined;
|
|
24
|
+
};
|
|
25
|
+
};
|
|
26
|
+
readonly uri: string;
|
|
27
|
+
readonly " $fragmentSpreads": FragmentRefs<"PrismClasses_node">;
|
|
28
|
+
readonly " $fragmentType": "PrismRow_node";
|
|
29
|
+
};
|
|
30
|
+
export type PrismRow_node$key = {
|
|
31
|
+
readonly " $data"?: PrismRow_node$data;
|
|
32
|
+
readonly " $fragmentSpreads": FragmentRefs<"PrismRow_node">;
|
|
33
|
+
};
|
|
34
|
+
declare const node: ReaderFragment;
|
|
35
|
+
export default node;
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import type { AnyRoute, RouteMap } from "@canonical/router-core";
|
|
2
|
+
import type { Lens, LensEntry } from "./types.js";
|
|
3
|
+
/** The `meta.lensOf` of a route, read whatever meta type the site declared. */
|
|
4
|
+
export declare function readLensOf(route: AnyRoute | undefined): string | undefined;
|
|
5
|
+
/**
|
|
6
|
+
* The site's lenses, read and checked once per route table: every route
|
|
7
|
+
* carrying `meta.lens`, in the order the lenses state.
|
|
8
|
+
*
|
|
9
|
+
* @throws On a mistake in the route table, so the site fails on its first
|
|
10
|
+
* render or request rather than drawing a wrong navigation: a malformed
|
|
11
|
+
* `meta.lens`; a lens whose list route takes parameters; two lenses in one
|
|
12
|
+
* place or on one shortcut; a shortcut on the palette's key; a `lensOf`
|
|
13
|
+
* that names no lens.
|
|
14
|
+
*/
|
|
15
|
+
export declare function checkLenses(routes: RouteMap): readonly (Lens & {
|
|
16
|
+
readonly name: string;
|
|
17
|
+
})[];
|
|
18
|
+
/**
|
|
19
|
+
* The site's lenses with their addresses, built by the caller's router: the
|
|
20
|
+
* checked list is cached by route table, the addresses are not.
|
|
21
|
+
*/
|
|
22
|
+
export declare function readLenses(routes: RouteMap, buildPath: (name: string) => string): readonly LensEntry[];
|
|
23
|
+
/**
|
|
24
|
+
* The name of the lens the current page belongs to: the matched route's
|
|
25
|
+
* `meta.lensOf`, or the matched route itself.
|
|
26
|
+
*/
|
|
27
|
+
export declare function readCurrentLens(routes: RouteMap, matchedName: string | undefined): string | undefined;
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import type { ReactElement } from "react";
|
|
2
|
+
/** What the navigation shows for a lens: the `meta.lens` of its list route. */
|
|
3
|
+
export interface Lens {
|
|
4
|
+
/** The lens's name, as the navigation and the search show it. */
|
|
5
|
+
readonly label: string;
|
|
6
|
+
/**
|
|
7
|
+
* Where the lens sits in the navigation, ascending. Two lenses may not
|
|
8
|
+
* share a place.
|
|
9
|
+
*/
|
|
10
|
+
readonly order: number;
|
|
11
|
+
/**
|
|
12
|
+
* A decorative icon drawn before the label, such as `<ComponentsIcon />`;
|
|
13
|
+
* the label stays the name.
|
|
14
|
+
*/
|
|
15
|
+
readonly icon?: ReactElement;
|
|
16
|
+
/** One key that opens the lens from anywhere, such as `"2"`; never `/`. */
|
|
17
|
+
readonly shortcut?: string;
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* The part of a route's `meta` Prism reads. A site declares its meta type
|
|
21
|
+
* once, through the router's `RouterRegister`, as this type or a type that
|
|
22
|
+
* extends it.
|
|
23
|
+
*/
|
|
24
|
+
export interface PrismRouteMeta {
|
|
25
|
+
/** On a lens's list route: the lens's label, place, icon and shortcut. */
|
|
26
|
+
readonly lens?: Lens;
|
|
27
|
+
/**
|
|
28
|
+
* On any other route of a lens, such as an item page: the name of the
|
|
29
|
+
* lens's list route, so the navigation marks that lens as current.
|
|
30
|
+
*/
|
|
31
|
+
readonly lensOf?: string;
|
|
32
|
+
/**
|
|
33
|
+
* On a route that shows one thing, with a `:uri` param: the class whose
|
|
34
|
+
* things it shows, by its IRI or its compact name, such as `"ds:Component"`.
|
|
35
|
+
* Chips, rows and cards link a thing to the home route of its nearest class
|
|
36
|
+
* that has one, with the thing's IRI as `uri`. Name each class one way
|
|
37
|
+
* across the route table: a class named once by IRI and once by compact
|
|
38
|
+
* name would have two home routes.
|
|
39
|
+
*/
|
|
40
|
+
readonly home?: string;
|
|
41
|
+
}
|
|
42
|
+
/** One lens as the navigation, the palette and the search page draw it. */
|
|
43
|
+
export interface LensEntry extends Lens {
|
|
44
|
+
/** The name of the lens's list route. */
|
|
45
|
+
readonly name: string;
|
|
46
|
+
/** The address of the lens's list route. */
|
|
47
|
+
readonly href: string;
|
|
48
|
+
}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { ClassName } from "./types.js";
|
|
2
|
+
/**
|
|
3
|
+
* The first answer `lookup` gives along a chain of classes, nearest first,
|
|
4
|
+
* asking each class by its IRI and then by its compact name.
|
|
5
|
+
*/
|
|
6
|
+
export default function findNearest<T>(chain: readonly ClassName[], lookup: (name: string) => T | undefined): T | undefined;
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export { default as findNearest } from "./findNearest.js";
|
|
2
|
+
export { default as orderClasses } from "./orderClasses.js";
|
|
3
|
+
export { default as readHomes } from "./readHomes.js";
|
|
4
|
+
export type * from "./types.js";
|
|
5
|
+
export { default as useProjection } from "./useProjection.js";
|
|
6
|
+
export { default as withLabel } from "./withLabel.js";
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import type { ClassName } from "./types.js";
|
|
2
|
+
/** A class as the graph gives it, with its own ancestors. */
|
|
3
|
+
export interface ClassWithAncestors {
|
|
4
|
+
readonly uri: string;
|
|
5
|
+
readonly _meta: {
|
|
6
|
+
readonly curie: string;
|
|
7
|
+
};
|
|
8
|
+
readonly superclasses: readonly unknown[];
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* A thing's classes, nearest first: its own class, then its ancestors, each
|
|
12
|
+
* after every class below it. An ancestor of a class has strictly fewer
|
|
13
|
+
* ancestors than that class, so ordering by how many ancestors each has puts
|
|
14
|
+
* every class before its superclasses, whatever order the graph lists them
|
|
15
|
+
* in; ancestors on separate branches keep the graph's order.
|
|
16
|
+
*/
|
|
17
|
+
export default function orderClasses(type: ClassWithAncestors & {
|
|
18
|
+
readonly superclasses: readonly ClassWithAncestors[];
|
|
19
|
+
}): readonly ClassName[];
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { RouteMap } from "@canonical/router-core";
|
|
2
|
+
/**
|
|
3
|
+
* The home routes of a site, by the class each one shows: the routes whose
|
|
4
|
+
* `meta.home` names a class. Read once per route table, however many
|
|
5
|
+
* projections ask.
|
|
6
|
+
*
|
|
7
|
+
* @throws When a home route takes any param but `:uri`, or when two routes
|
|
8
|
+
* claim the same class: both are mistakes in the site's route table,
|
|
9
|
+
* found on the first render.
|
|
10
|
+
*/
|
|
11
|
+
export default function readHomes(routes: RouteMap): ReadonlyMap<string, string>;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { ComponentType } from "react";
|
|
2
|
+
/** A class as a chain names it: its IRI and its compact name. */
|
|
3
|
+
export interface ClassName {
|
|
4
|
+
readonly uri: string;
|
|
5
|
+
readonly curie: string;
|
|
6
|
+
}
|
|
7
|
+
/** What a projection needs to know about a thing before drawing it. */
|
|
8
|
+
export interface Projection<TProps> {
|
|
9
|
+
/** The thing's IRI. */
|
|
10
|
+
readonly uri: string;
|
|
11
|
+
/** The site's replacement for this projection, from the nearest class. */
|
|
12
|
+
readonly Override: ComponentType<TProps> | undefined;
|
|
13
|
+
/** The name of the route that shows the thing, from the nearest class. */
|
|
14
|
+
readonly home: string | undefined;
|
|
15
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { type PrismClasses_node$key } from "../graphql/index.js";
|
|
2
|
+
import type { ProjectionOverride, ProjectionViewProps } from "../Prism/index.js";
|
|
3
|
+
import type { Projection } from "./types.js";
|
|
4
|
+
/**
|
|
5
|
+
* Find, along a thing's classes, the site's replacement for one projection
|
|
6
|
+
* and the route that shows the thing. Both come from the nearest class that
|
|
7
|
+
* has one, among the classes the graph serves with the thing.
|
|
8
|
+
*/
|
|
9
|
+
export default function useProjection<TKey extends keyof ProjectionOverride>(node: PrismClasses_node$key, key: TKey): Projection<ProjectionViewProps[TKey]>;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A thing's slots with a label that can name it: the graph's label when it
|
|
3
|
+
* has any text, else the thing's compact name, else its IRI. A link or a
|
|
4
|
+
* heading with no text has no accessible name.
|
|
5
|
+
*/
|
|
6
|
+
export default function withLabel<TSlots extends {
|
|
7
|
+
readonly label: string;
|
|
8
|
+
}>(slots: TSlots, curie: string, uri: string): TSlots;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import type { AnyRoute, RouteMap } from "@canonical/router-core";
|
|
2
|
+
import type { RenderPageOptions } from "./types.js";
|
|
3
|
+
/**
|
|
4
|
+
* Render the page for a request, as one step of the site's server: decide
|
|
5
|
+
* the redirect or the status from the route table, wait for the matched
|
|
6
|
+
* routes' `warm`, then stream the document with the router's state and the
|
|
7
|
+
* site's `data` embedded for the browser entry.
|
|
8
|
+
*
|
|
9
|
+
* One deadline bounds the whole answer. When the routes' `warm` has not
|
|
10
|
+
* settled by then, the page fails closed with a 503: a `warm` still running
|
|
11
|
+
* may be a guard about to redirect, and the page it guards must not render.
|
|
12
|
+
* When the deadline passes while the page streams, the stream is cut.
|
|
13
|
+
*
|
|
14
|
+
* @returns The redirect, the 405 for a method other than GET and HEAD, the
|
|
15
|
+
* 503 for a deadline missed while fetching, or the streamed document with
|
|
16
|
+
* its status: 404 for an address no route matches, 400 for one that does
|
|
17
|
+
* not decode.
|
|
18
|
+
* @throws The request's abort reason when the client has gone before the
|
|
19
|
+
* page renders, for the server to drop.
|
|
20
|
+
*/
|
|
21
|
+
export default function renderPage<const TRoutes extends RouteMap, const TNotFound extends AnyRoute | undefined = undefined, TData = unknown>(request: Request, { routes, notFound, middleware, Shell, context, data, html, }: RenderPageOptions<TRoutes, TNotFound, TData>): Promise<Response>;
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import type { AnyRoute, RouteMap, RouteMiddleware, Router, RouterContext, RouterDehydratedState } from "@canonical/router-core";
|
|
2
|
+
import type { ComponentType } from "react";
|
|
3
|
+
/** What the site's root component receives, on the server and in the browser. */
|
|
4
|
+
export interface ShellProps<TRoutes extends RouteMap = RouteMap, TNotFound extends AnyRoute | undefined = AnyRoute | undefined> {
|
|
5
|
+
/** The page's router, already holding the matched route. */
|
|
6
|
+
readonly router: Router<TRoutes, TNotFound>;
|
|
7
|
+
/** The router's context, the value every `warm` received. */
|
|
8
|
+
readonly context: RouterContext;
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* What the server embeds in the page for the browser entry, under
|
|
12
|
+
* `INITIAL_DATA_KEY` from `@canonical/react-ssr/renderer/constants`.
|
|
13
|
+
*/
|
|
14
|
+
export type PageData<TData = unknown> = {
|
|
15
|
+
/** The router's state, for `createRouter`'s `hydratedState`. */
|
|
16
|
+
readonly router?: RouterDehydratedState<RouteMap>;
|
|
17
|
+
/** What the site's `data` returned, such as the answers it captured. */
|
|
18
|
+
readonly data?: TData;
|
|
19
|
+
};
|
|
20
|
+
export interface RenderPageOptions<TRoutes extends RouteMap, TNotFound extends AnyRoute | undefined, TData> {
|
|
21
|
+
/** The site's route table. */
|
|
22
|
+
readonly routes: TRoutes;
|
|
23
|
+
/** The route rendered for an address no route matches, or that is malformed. */
|
|
24
|
+
readonly notFound?: TNotFound;
|
|
25
|
+
/**
|
|
26
|
+
* The site's route middleware, the same the browser's router gets, so the
|
|
27
|
+
* server answers as navigation does.
|
|
28
|
+
*/
|
|
29
|
+
readonly middleware?: readonly RouteMiddleware[];
|
|
30
|
+
/** The site's root component: its providers around the router's outlet. */
|
|
31
|
+
readonly Shell: ComponentType<ShellProps<TRoutes, TNotFound>>;
|
|
32
|
+
/**
|
|
33
|
+
* The router context of this request, built by the site: what every `warm`
|
|
34
|
+
* receives, such as the request's Relay environment.
|
|
35
|
+
*/
|
|
36
|
+
readonly context: RouterContext;
|
|
37
|
+
/**
|
|
38
|
+
* Called once the routes' `warm` has settled: what the browser entry needs
|
|
39
|
+
* to start where the server stopped, such as the answers the request's
|
|
40
|
+
* environment captured. It must be serialisable as JSON.
|
|
41
|
+
*/
|
|
42
|
+
readonly data: () => TData;
|
|
43
|
+
/**
|
|
44
|
+
* The HTML page whose script and link tags the response carries: the
|
|
45
|
+
* site's `index.html` as Vite transforms it in development, the built one
|
|
46
|
+
* in production.
|
|
47
|
+
*/
|
|
48
|
+
readonly html: string;
|
|
49
|
+
}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { LensEntry } from "../lens/index.js";
|
|
2
|
+
/**
|
|
3
|
+
* The lenses whose label contains every word of `query`, ignoring case, in
|
|
4
|
+
* the order given. An empty query keeps them all.
|
|
5
|
+
*/
|
|
6
|
+
export default function filterLenses(lenses: readonly LensEntry[], query: string): readonly LensEntry[];
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { PrismSearchQuery } from "../searchQuery/index.js";
|
|
2
|
+
/** How many things one search shows, in the palette and on the search page. */
|
|
3
|
+
export declare const SEARCH_LIMIT = 20;
|
|
4
|
+
/**
|
|
5
|
+
* The search query's variables for what the reader typed, the same for the
|
|
6
|
+
* palette, the search page and a route's `warm`, so all three share one
|
|
7
|
+
* answer in the store. `undefined` when there is nothing to search for.
|
|
8
|
+
*/
|
|
9
|
+
export default function searchVariables(query: string): PrismSearchQuery["variables"] | undefined;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { Environment } from "relay-runtime";
|
|
2
|
+
/**
|
|
3
|
+
* Fetch the things matching a query into a Relay environment ahead of the
|
|
4
|
+
* search page: the body of the search route's `warm`, for a site whose
|
|
5
|
+
* search page finds things in the graph. It does nothing for an empty query.
|
|
6
|
+
*/
|
|
7
|
+
export default function warmSearch(environment: Environment, query: string, options?: {
|
|
8
|
+
readonly signal?: AbortSignal;
|
|
9
|
+
}): Promise<void>;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export type { PrismSearchQuery } from "./__generated__/PrismSearchQuery.graphql.js";
|
|
2
|
+
/**
|
|
3
|
+
* The things whose text matches the reader's words, each drawn as a row. It
|
|
4
|
+
* selects the graph's `search` field, which the contract does not have yet,
|
|
5
|
+
* so it sits apart from the projections' fragments: only a site that turns
|
|
6
|
+
* `graph` on compiles it.
|
|
7
|
+
*/
|
|
8
|
+
export declare const prismSearchQuery: import("relay-runtime").ConcreteRequest;
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @generated SignedSource<<dd76cf01ae66340bd32b6e085e5dfd47>>
|
|
3
|
+
* @lightSyntaxTransform
|
|
4
|
+
*/
|
|
5
|
+
import type { ConcreteRequest } from 'relay-runtime';
|
|
6
|
+
import type { FragmentRefs } from "relay-runtime";
|
|
7
|
+
export type PrismSearchQuery$variables = {
|
|
8
|
+
first: number;
|
|
9
|
+
text: string;
|
|
10
|
+
};
|
|
11
|
+
export type PrismSearchQuery$data = {
|
|
12
|
+
readonly search: {
|
|
13
|
+
readonly edges: ReadonlyArray<{
|
|
14
|
+
readonly node: {
|
|
15
|
+
readonly uri: string;
|
|
16
|
+
readonly " $fragmentSpreads": FragmentRefs<"PrismClasses_node" | "PrismRow_node">;
|
|
17
|
+
};
|
|
18
|
+
}>;
|
|
19
|
+
};
|
|
20
|
+
};
|
|
21
|
+
export type PrismSearchQuery = {
|
|
22
|
+
response: PrismSearchQuery$data;
|
|
23
|
+
variables: PrismSearchQuery$variables;
|
|
24
|
+
};
|
|
25
|
+
declare const node: ConcreteRequest;
|
|
26
|
+
export default node;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./PrismSearchQuery.js";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { default as warmQuery } from "./warmQuery.js";
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { type Environment, type GraphQLTaggedNode, type OperationType } from "relay-runtime";
|
|
2
|
+
/**
|
|
3
|
+
* Fetch a query into a Relay environment ahead of the page that reads it:
|
|
4
|
+
* the body of a route's `warm`. It does nothing when the environment's store
|
|
5
|
+
* already holds the answer.
|
|
6
|
+
*
|
|
7
|
+
* @param environment - The environment the page reads from; a route's `warm`
|
|
8
|
+
* receives it in the router's `context`.
|
|
9
|
+
* @param query - The compiled query.
|
|
10
|
+
* @param variables - The query's variables.
|
|
11
|
+
* @param options.signal - Stops the fetch: a route's `warm` passes the
|
|
12
|
+
* navigation's signal.
|
|
13
|
+
* @returns A promise that settles when the answer is in the store, or at once
|
|
14
|
+
* when the signal aborts; it rejects when the query fails. The server waits
|
|
15
|
+
* for it before rendering; navigation in the browser does not.
|
|
16
|
+
*/
|
|
17
|
+
export default function warmQuery<TQuery extends OperationType>(environment: Environment, query: GraphQLTaggedNode, variables: TQuery["variables"], { signal }?: {
|
|
18
|
+
readonly signal?: AbortSignal;
|
|
19
|
+
}): Promise<void>;
|
package/package.json
CHANGED
|
@@ -1,6 +1,109 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@canonical/prism",
|
|
3
|
-
"
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"description": "The site engine of Prism: a site's navigation, layout, command palette, search page and server render, built on its own route table",
|
|
4
|
+
"version": "0.51.0-experimental.0",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"module": "dist/esm/index.js",
|
|
7
|
+
"types": "dist/types/index.d.ts",
|
|
8
|
+
"exports": {
|
|
9
|
+
".": {
|
|
10
|
+
"types": "./dist/types/index.d.ts",
|
|
11
|
+
"import": "./dist/esm/index.js"
|
|
12
|
+
},
|
|
13
|
+
"./server": {
|
|
14
|
+
"types": "./dist/types/server.d.ts",
|
|
15
|
+
"import": "./dist/esm/server.js"
|
|
16
|
+
}
|
|
17
|
+
},
|
|
18
|
+
"sideEffects": [
|
|
19
|
+
"**/*.css"
|
|
20
|
+
],
|
|
21
|
+
"files": [
|
|
22
|
+
"dist"
|
|
23
|
+
],
|
|
24
|
+
"author": {
|
|
25
|
+
"email": "webteam@canonical.com",
|
|
26
|
+
"name": "Canonical Webteam"
|
|
27
|
+
},
|
|
28
|
+
"repository": {
|
|
29
|
+
"type": "git",
|
|
30
|
+
"url": "https://github.com/canonical/pragma-web"
|
|
31
|
+
},
|
|
32
|
+
"license": "LGPL-3.0",
|
|
33
|
+
"bugs": {
|
|
34
|
+
"url": "https://github.com/canonical/pragma-web/issues"
|
|
35
|
+
},
|
|
36
|
+
"homepage": "https://github.com/canonical/pragma-web#readme",
|
|
37
|
+
"publishConfig": {
|
|
38
|
+
"access": "public"
|
|
39
|
+
},
|
|
40
|
+
"scripts": {
|
|
41
|
+
"build": "bun run build:package",
|
|
42
|
+
"build:all": "bun run build:package && bun run build:storybook",
|
|
43
|
+
"build:package": "bun run build:package:tsc && bun run build:package:copycss",
|
|
44
|
+
"build:package:tsc": "tsc -p tsconfig.build.json",
|
|
45
|
+
"build:package:copycss": "copyfiles -u 1 'src/lib/{,**/}*.css' dist/esm",
|
|
46
|
+
"build:storybook": "storybook build",
|
|
47
|
+
"check": "bun run check:biome && bun run check:ts && bun run check:relay && bun run check:webarchitect",
|
|
48
|
+
"check:webarchitect": "webarchitect library",
|
|
49
|
+
"check:fix": "bun run check:biome:fix && bun run check:ts",
|
|
50
|
+
"check:biome": "biome check",
|
|
51
|
+
"check:biome:fix": "biome check --write",
|
|
52
|
+
"check:relay": "bun run relay && git diff --exit-code -- src/lib/graphql/__generated__/ src/lib/searchQuery/__generated__/ src/testing/graph/__generated__/ && test -z \"$(git ls-files --others --exclude-standard -- src/lib/graphql/__generated__/ src/lib/searchQuery/__generated__/ src/testing/graph/__generated__/)\"",
|
|
53
|
+
"check:ts": "tsc --noEmit",
|
|
54
|
+
"relay": "bun scripts/writeSchema.ts && relay-compiler",
|
|
55
|
+
"storybook": "storybook dev -p 6016 --no-open --host 0.0.0.0",
|
|
56
|
+
"test": "vitest run",
|
|
57
|
+
"test:watch": "vitest",
|
|
58
|
+
"test:coverage": "vitest run --coverage"
|
|
59
|
+
},
|
|
60
|
+
"dependencies": {
|
|
61
|
+
"@canonical/react-ds-global": "^0.50.0",
|
|
62
|
+
"@canonical/react-ssr": "^0.50.0"
|
|
63
|
+
},
|
|
64
|
+
"peerDependencies": {
|
|
65
|
+
"@canonical/react-hooks": "^0.50.0",
|
|
66
|
+
"@canonical/router-core": "^0.50.0",
|
|
67
|
+
"@canonical/router-react": "^0.50.0",
|
|
68
|
+
"react": "^19.2.4",
|
|
69
|
+
"react-dom": "^19.2.4",
|
|
70
|
+
"react-relay": "^21.0.1",
|
|
71
|
+
"relay-runtime": "^21.0.1"
|
|
72
|
+
},
|
|
73
|
+
"devDependencies": {
|
|
74
|
+
"@biomejs/biome": "2.6.9",
|
|
75
|
+
"@canonical/biome-config": "0.47.0",
|
|
76
|
+
"@canonical/prism-contract": "^0.50.0",
|
|
77
|
+
"@canonical/react-hooks": "^0.50.0",
|
|
78
|
+
"@canonical/router-core": "^0.50.0",
|
|
79
|
+
"@canonical/router-react": "^0.50.0",
|
|
80
|
+
"@canonical/storybook-config": "^0.50.0",
|
|
81
|
+
"@canonical/styles": "^0.50.0",
|
|
82
|
+
"@canonical/typescript-config-react": "^0.50.0",
|
|
83
|
+
"@canonical/vitest-config-react": "^0.50.0",
|
|
84
|
+
"@canonical/webarchitect": "0.46.0",
|
|
85
|
+
"@storybook/react-vite": "^10.6.0",
|
|
86
|
+
"@testing-library/jest-dom": "^7.0.0",
|
|
87
|
+
"@testing-library/react": "^16.3.2",
|
|
88
|
+
"@types/node": "^26.0.0",
|
|
89
|
+
"@types/react": "^19.2.14",
|
|
90
|
+
"@types/react-dom": "^19.2.3",
|
|
91
|
+
"@types/react-relay": "^18.2.1",
|
|
92
|
+
"@types/relay-runtime": "^20.1.1",
|
|
93
|
+
"@vitejs/plugin-react": "^6.0.0",
|
|
94
|
+
"@vitest/coverage-v8": "^5.0.0",
|
|
95
|
+
"axe-core": "^4.11.1",
|
|
96
|
+
"copyfiles": "^2.4.1",
|
|
97
|
+
"graphql": "^17.0.0",
|
|
98
|
+
"jsdom": "^31.0.0",
|
|
99
|
+
"react": "^19.2.4",
|
|
100
|
+
"react-dom": "^19.2.4",
|
|
101
|
+
"react-relay": "^21.0.1",
|
|
102
|
+
"relay-compiler": "^21.0.1",
|
|
103
|
+
"relay-runtime": "^21.0.1",
|
|
104
|
+
"storybook": "^10.6.0",
|
|
105
|
+
"typescript": "^7.0.2",
|
|
106
|
+
"vite": "^8.0.1",
|
|
107
|
+
"vitest": "^5.0.0"
|
|
108
|
+
}
|
|
109
|
+
}
|