@stealthscale/sdk-host 0.1.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.
@@ -0,0 +1,62 @@
1
+ import { t as pluginWordsOf } from "./words-yI-WdYM3.js";
2
+ import { targetKeyOf } from "@stealthscale/sdk-core";
3
+ import { Slot, useResolvedProduct } from "@stealthscale/sdk-plugin";
4
+ import { EmptyState } from "@stealthscale/component-feedback";
5
+ import { Outlet, useChildMatches } from "@stealthscale/provider-router";
6
+ import { jsx, jsxs } from "react/jsx-runtime";
7
+ import { useTranslation } from "@stealthscale/provider-i18n";
8
+ import { Stack } from "@stealthscale/component-layout";
9
+ import { Heading } from "@stealthscale/component-typography";
10
+ //#region src/standalone/page.tsx
11
+ /**
12
+ * The props a slot without a sample renders with.
13
+ */
14
+ const NONE = {};
15
+ /**
16
+ * Returns the values a slot renders with: each value the extensions placed in a keyed slot match,
17
+ * and no value for a slot that is not keyed.
18
+ */
19
+ function matchesOf(slot, extensions) {
20
+ if (slot.keyed !== true) return [void 0];
21
+ const target = targetKeyOf(slot);
22
+ return [...new Set(extensions.filter((one) => one.target === target).map(({ match }) => match))];
23
+ }
24
+ /**
25
+ * Returns the component of the placeholder page of one route.
26
+ *
27
+ * @remarks
28
+ * The page names the route and states that its plugin is installed from its contract alone. Where
29
+ * the address matches a child route, the child's page renders in the route's outlet.
30
+ * Otherwise each slot of the contract renders under a heading that names the slot, with the
31
+ * slot's sample props, and a keyed slot renders once per value the extensions placed in it match.
32
+ * @param routeId - Qualified id of the route.
33
+ * @param contract - The contract of the route's plugin.
34
+ */
35
+ function placeholderPageOf(routeId, contract) {
36
+ const slots = Object.values(contract.slots);
37
+ /**
38
+ * Renders the page in its plugin's scope.
39
+ */
40
+ return function PlaceholderPage() {
41
+ const { i18n, t } = useTranslation("host");
42
+ const { extensions } = useResolvedProduct();
43
+ const nested = useChildMatches().length > 0;
44
+ const plugin = pluginWordsOf(i18n).t(contract.pluginId, "plugin.name");
45
+ return /* @__PURE__ */ jsxs(Stack, { children: [/* @__PURE__ */ jsx(EmptyState.Root, { children: /* @__PURE__ */ jsxs(EmptyState.Content, { children: [/* @__PURE__ */ jsx(EmptyState.Title, {
46
+ as: "h1",
47
+ children: routeId
48
+ }), /* @__PURE__ */ jsx(EmptyState.Description, { children: t("standalone.page", { plugin }) })] }) }), nested ? /* @__PURE__ */ jsx(Outlet, {}) : slots.map((slot) => /* @__PURE__ */ jsxs(Stack, {
49
+ as: "section",
50
+ children: [/* @__PURE__ */ jsx(Heading, {
51
+ as: "h2",
52
+ children: slot.id
53
+ }), matchesOf(slot, extensions).map((match) => /* @__PURE__ */ jsx(Slot, {
54
+ match,
55
+ props: slot.sample ?? NONE,
56
+ slot
57
+ }, match ?? ""))]
58
+ }, slot.id))] });
59
+ };
60
+ }
61
+ //#endregion
62
+ export { placeholderPageOf };
@@ -0,0 +1,41 @@
1
+ import { t as pluginWordsOf } from "./words-yI-WdYM3.js";
2
+ import { pluginOf } from "@stealthscale/sdk-core";
3
+ import { c } from "react/compiler-runtime";
4
+ import { jsx } from "react/jsx-runtime";
5
+ import { useTranslation } from "@stealthscale/provider-i18n";
6
+ import { Text } from "@stealthscale/component-typography";
7
+ //#region src/standalone/section.tsx
8
+ /**
9
+ * Renders a sentence that names the section's plugin and states that it is installed from its
10
+ * contract alone.
11
+ */
12
+ function PlaceholderSection(t0) {
13
+ const $ = c(8);
14
+ const { sectionId } = t0;
15
+ const { i18n, t } = useTranslation("host");
16
+ let T0;
17
+ let t1;
18
+ if ($[0] !== i18n || $[1] !== sectionId || $[2] !== t) {
19
+ const plugin = pluginWordsOf(i18n).t(pluginOf(sectionId), "plugin.name");
20
+ T0 = Text;
21
+ t1 = t("standalone.section", { plugin });
22
+ $[0] = i18n;
23
+ $[1] = sectionId;
24
+ $[2] = t;
25
+ $[3] = T0;
26
+ $[4] = t1;
27
+ } else {
28
+ T0 = $[3];
29
+ t1 = $[4];
30
+ }
31
+ let t2;
32
+ if ($[5] !== T0 || $[6] !== t1) {
33
+ t2 = /* @__PURE__ */ jsx(T0, { children: t1 });
34
+ $[5] = T0;
35
+ $[6] = t1;
36
+ $[7] = t2;
37
+ } else t2 = $[7];
38
+ return t2;
39
+ }
40
+ //#endregion
41
+ export { PlaceholderSection };
@@ -0,0 +1,65 @@
1
+ import "../standalone-XfUZYt9b.js";
2
+ import "@stealthscale/provider-data";
3
+ import { Product, ResolvedProduct } from "@stealthscale/sdk-core";
4
+ import { RouteMap } from "@stealthscale/provider-router";
5
+ import { ReactNode } from "react";
6
+ import { Catalogues } from "@stealthscale/provider-i18n";
7
+ import { FormGlyphs } from "@stealthscale/component-forms/form";
8
+ import { Root } from "react-dom/client";
9
+ //#region src/standalone/context.d.ts
10
+ /**
11
+ * Lists the glyphs of the standalone page: the settings forms' glyphs, and those of the panel's
12
+ * stage triggers. A trigger without its glyph is left out.
13
+ */
14
+ interface StandaloneGlyphs extends FormGlyphs {
15
+ /**
16
+ * Glyph of the trigger that minimizes the panel to its header.
17
+ */
18
+ readonly minimize?: ReactNode;
19
+ /**
20
+ * Glyph of the trigger that restores a minimized panel.
21
+ */
22
+ readonly restore?: ReactNode;
23
+ }
24
+ //#endregion
25
+ //#region src/standalone/app.d.ts
26
+ /**
27
+ * Lists what the standalone page renders with.
28
+ */
29
+ export interface StandalonePageOptions {
30
+ /**
31
+ * The catalogues, from `virtual:i18n`. Every key renders as itself where left out.
32
+ */
33
+ readonly catalogues?: Catalogues | undefined;
34
+ /**
35
+ * The element the page renders into. The element with the id `root` where left out.
36
+ */
37
+ readonly element?: Element | null | undefined;
38
+ /**
39
+ * The glyphs of the settings forms and of the panel's stage triggers. None where left out.
40
+ */
41
+ readonly glyphs?: StandaloneGlyphs | undefined;
42
+ /**
43
+ * The locales the page offers, the first its fallback. American English alone where left out.
44
+ */
45
+ readonly locales?: readonly [string, ...string[]] | undefined;
46
+ /**
47
+ * The standalone product, from `virtual:product`.
48
+ */
49
+ readonly product: Product;
50
+ /**
51
+ * The themes the page offers. The page renders the first until a person picks another. The
52
+ * application's one theme where left out.
53
+ */
54
+ readonly themes?: readonly string[] | undefined;
55
+ }
56
+ /**
57
+ * Renders the standalone page once the host is ready.
58
+ *
59
+ * @param options - The product, the catalogues, the glyphs, the locales, the themes and the
60
+ * element.
61
+ * @returns The React root the page renders in, which `unmount` takes down.
62
+ * @throws {@link Error} Where no element is given and the document has none with the id `root`.
63
+ */
64
+ export declare function renderStandalone({ catalogues, element, glyphs, locales, product, themes }: StandalonePageOptions): Promise<Root>;
65
+ //#endregion