@rebasepro/cms 0.29.2 → 0.30.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.
Files changed (33) hide show
  1. package/dist/components/CollectionTableBinding/fields/TableStorageUpload.js +1 -1
  2. package/dist/components/CollectionTableBinding/fields/TableStorageUpload.js.map +1 -1
  3. package/dist/components/EntityPreviewBinding.d.ts +20 -0
  4. package/dist/components/EntityPreviewBinding.js +121 -18
  5. package/dist/components/EntityPreviewBinding.js.map +1 -1
  6. package/dist/index.d.ts +2 -0
  7. package/dist/index.js +3 -1
  8. package/dist/mcp_view/bridge.d.ts +21 -1
  9. package/dist/mcp_view/bridge.js.map +1 -1
  10. package/dist/mcp_view/index.d.ts +7 -7
  11. package/dist/mcp_view/index.js +6 -1
  12. package/dist/mcp_view/index.js.map +1 -1
  13. package/dist/mcp_view/screen.d.ts +6 -4
  14. package/dist/mcp_view/screen.js +14 -42
  15. package/dist/mcp_view/screen.js.map +1 -1
  16. package/dist/mcp_view/tool_driver.d.ts +33 -0
  17. package/dist/mcp_view/tool_driver.js +186 -85
  18. package/dist/mcp_view/tool_driver.js.map +1 -1
  19. package/dist/mcp_view/write_review.d.ts +35 -0
  20. package/dist/mcp_view/write_review.js +144 -0
  21. package/dist/mcp_view/write_review.js.map +1 -0
  22. package/dist/preview/components/RelationPreview.js +7 -2
  23. package/dist/preview/components/RelationPreview.js.map +1 -1
  24. package/dist/saved_apps/SavedAppsView.d.ts +17 -0
  25. package/dist/saved_apps/SavedAppsView.js +167 -0
  26. package/dist/saved_apps/SavedAppsView.js.map +1 -0
  27. package/dist/saved_apps/admin_apps_client.d.ts +24 -0
  28. package/dist/saved_apps/admin_apps_client.js +46 -0
  29. package/dist/saved_apps/admin_apps_client.js.map +1 -0
  30. package/dist/saved_apps/saved_app_frame.d.ts +20 -0
  31. package/dist/saved_apps/saved_app_frame.js +143 -0
  32. package/dist/saved_apps/saved_app_frame.js.map +1 -0
  33. package/package.json +9 -9
@@ -0,0 +1,35 @@
1
+ import React from "react";
2
+ import type { AdminCollection } from "@rebasepro/cms-types";
3
+ import type { Property } from "@rebasepro/types";
4
+ import type { WriteIntent, WritePlan } from "./tool_driver.js";
5
+ /**
6
+ * A write, as the person reads it before or after it happens.
7
+ *
8
+ * The server's plan is written for the model — a row id, which tools run, how
9
+ * to undo through `details.current` — and it was shown as it came. The
10
+ * person is told the same thing in their terms instead: the row by its title,
11
+ * and each field it changes with the value it has and the value it gets, by
12
+ * the field's own label and the enum's own label.
13
+ */
14
+ interface FieldChange {
15
+ label: string;
16
+ from?: string;
17
+ to: string;
18
+ }
19
+ /** One value as text, the way the field names it. */
20
+ export declare function shownValue(value: unknown, property: Property | undefined): string;
21
+ /** Each field a write sets, labelled, with its old value where it is known and differs. */
22
+ export declare function fieldChanges(intent: WriteIntent, collection: AdminCollection | undefined): FieldChange[];
23
+ /** The person's yes or no on a write that needs one. */
24
+ export declare function WriteConfirmDialog({ plan, collectionOf, onAnswer }: {
25
+ plan: WritePlan | undefined;
26
+ collectionOf: (name: string) => AdminCollection | undefined;
27
+ onAnswer: (confirmed: boolean) => void;
28
+ }): React.JSX.Element;
29
+ /** What a write that did not ask first changed, said once it is saved, then gone. */
30
+ export declare function SavedNotice({ intent, collectionOf, onDismiss }: {
31
+ intent: WriteIntent | undefined;
32
+ collectionOf: (name: string) => AdminCollection | undefined;
33
+ onDismiss: () => void;
34
+ }): React.JSX.Element | null;
35
+ export {};
@@ -0,0 +1,144 @@
1
+ import { getPropertyInPath } from "../util/property_utils.js";
2
+ import React, { useEffect } from "react";
3
+ import { jsx, jsxs } from "react/jsx-runtime";
4
+ import { Alert, Button, Dialog, DialogActions, DialogContent, DialogTitle, Typography } from "@rebasepro/ui";
5
+ import { enumToObjectEntries } from "@rebasepro/common";
6
+ //#region src/mcp_view/write_review.tsx
7
+ var MAX_VALUE = 80;
8
+ /** One value as text, the way the field names it. */
9
+ function shownValue(value, property) {
10
+ if (value === void 0 || value === null || value === "") return "empty";
11
+ if (property && (property.type === "string" || property.type === "number") && property.enum) {
12
+ const entry = enumToObjectEntries(property.enum).find((option) => String(option.id) === String(value));
13
+ if (entry) return entry.label;
14
+ }
15
+ if (typeof value === "boolean") return value ? "Yes" : "No";
16
+ if (property?.type === "date" && (typeof value === "string" || value instanceof Date)) {
17
+ const date = new Date(value);
18
+ if (!Number.isNaN(date.getTime())) return date.toLocaleString();
19
+ }
20
+ if (Array.isArray(value)) return value.length === 1 ? "1 item" : `${value.length} items`;
21
+ if (typeof value === "object") {
22
+ const id = value.id;
23
+ return id !== void 0 ? String(id) : "changed";
24
+ }
25
+ const text = String(value).replace(/\s+/g, " ").trim();
26
+ return text.length > MAX_VALUE ? `${text.slice(0, MAX_VALUE - 1)}…` : text;
27
+ }
28
+ /** Each field a write sets, labelled, with its old value where it is known and differs. */
29
+ function fieldChanges(intent, collection) {
30
+ return Object.entries(intent.values ?? {}).flatMap(([key, value]) => {
31
+ const property = collection ? getPropertyInPath(collection.properties, key) : void 0;
32
+ const to = shownValue(value, property);
33
+ const before = intent.previous && key in intent.previous ? shownValue(intent.previous[key], property) : void 0;
34
+ if (before === to) return [];
35
+ return [{
36
+ label: property?.name ?? key,
37
+ ...before !== void 0 && { from: before },
38
+ to
39
+ }];
40
+ });
41
+ }
42
+ /** What the row is called: its title, else the collection's word for one. */
43
+ function rowName(intent, collection) {
44
+ if (intent.title) return `“${intent.title}”`;
45
+ return `this ${(collection?.singularName ?? collection?.name ?? intent.collection).toLowerCase()}`;
46
+ }
47
+ function heading(intent, collection) {
48
+ if (intent.action === "create") return `Create a new ${(collection?.singularName ?? collection?.name ?? intent.collection).toLowerCase()}?`;
49
+ if (intent.action === "delete") return `Delete ${rowName(intent, collection)}?`;
50
+ return `Save changes to ${rowName(intent, collection)}?`;
51
+ }
52
+ function Changes({ changes }) {
53
+ if (changes.length === 0) return null;
54
+ return /* @__PURE__ */ jsx("div", {
55
+ className: "grid gap-x-4 gap-y-1.5",
56
+ style: { gridTemplateColumns: "auto 1fr" },
57
+ children: changes.map((change) => /* @__PURE__ */ jsxs(React.Fragment, { children: [/* @__PURE__ */ jsx(Typography, {
58
+ variant: "body2",
59
+ color: "secondary",
60
+ children: change.label
61
+ }), /* @__PURE__ */ jsxs(Typography, {
62
+ variant: "body2",
63
+ className: "min-w-0 break-words",
64
+ children: [
65
+ change.from !== void 0 && /* @__PURE__ */ jsx("span", {
66
+ className: "text-text-secondary dark:text-text-secondary-dark line-through",
67
+ children: change.from
68
+ }),
69
+ change.from !== void 0 && /* @__PURE__ */ jsx("span", {
70
+ className: "text-text-secondary dark:text-text-secondary-dark",
71
+ children: " → "
72
+ }),
73
+ /* @__PURE__ */ jsx("span", {
74
+ className: "font-medium",
75
+ children: change.to
76
+ })
77
+ ]
78
+ })] }, change.label))
79
+ });
80
+ }
81
+ /** The person's yes or no on a write that needs one. */
82
+ function WriteConfirmDialog({ plan, collectionOf, onAnswer }) {
83
+ const intent = plan?.write;
84
+ const collection = intent ? collectionOf(intent.collection) : void 0;
85
+ const changes = intent && intent.action !== "delete" ? fieldChanges(intent, collection) : [];
86
+ const deleting = intent?.action === "delete";
87
+ return /* @__PURE__ */ jsxs(Dialog, {
88
+ open: plan !== void 0,
89
+ onOpenChange: (open) => !open && onAnswer(false),
90
+ maxWidth: "sm",
91
+ children: [
92
+ /* @__PURE__ */ jsx(DialogTitle, {
93
+ variant: "subtitle1",
94
+ children: intent ? heading(intent, collection) : "Save this change?"
95
+ }),
96
+ /* @__PURE__ */ jsxs(DialogContent, {
97
+ className: "flex flex-col gap-3",
98
+ children: [intent ? /* @__PURE__ */ jsx(Changes, { changes }) : /* @__PURE__ */ jsx(Typography, {
99
+ variant: "body2",
100
+ children: plan?.summary
101
+ }), deleting && /* @__PURE__ */ jsx(Typography, {
102
+ variant: "body2",
103
+ color: "secondary",
104
+ children: "It is removed from the project for everyone."
105
+ })]
106
+ }),
107
+ /* @__PURE__ */ jsxs(DialogActions, { children: [/* @__PURE__ */ jsx(Button, {
108
+ variant: "text",
109
+ color: "neutral",
110
+ onClick: () => onAnswer(false),
111
+ children: "Cancel"
112
+ }), /* @__PURE__ */ jsx(Button, {
113
+ variant: "filled",
114
+ color: deleting ? "error" : "primary",
115
+ onClick: () => onAnswer(true),
116
+ children: deleting ? "Delete" : intent?.action === "create" ? "Create" : "Save"
117
+ })] })
118
+ ]
119
+ });
120
+ }
121
+ var NOTICE_MS = 5e3;
122
+ /** What a write that did not ask first changed, said once it is saved, then gone. */
123
+ function SavedNotice({ intent, collectionOf, onDismiss }) {
124
+ useEffect(() => {
125
+ if (!intent) return;
126
+ const timer = setTimeout(onDismiss, NOTICE_MS);
127
+ return () => clearTimeout(timer);
128
+ }, [intent, onDismiss]);
129
+ if (!intent) return null;
130
+ const collection = collectionOf(intent.collection);
131
+ const what = fieldChanges(intent, collection).map((change) => `${change.label} → ${change.to}`).join(", ");
132
+ const name = intent.title ? `“${intent.title}”` : (collection?.singularName ?? "the row").toLowerCase();
133
+ return /* @__PURE__ */ jsx(Alert, {
134
+ color: "success",
135
+ size: "small",
136
+ outerClassName: "sticky top-0 z-10",
137
+ onDismiss,
138
+ children: what ? `Saved ${name}: ${what}.` : `Saved ${name}.`
139
+ });
140
+ }
141
+ //#endregion
142
+ export { SavedNotice, WriteConfirmDialog, fieldChanges, shownValue };
143
+
144
+ //# sourceMappingURL=write_review.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"write_review.js","names":[],"sources":["../../src/mcp_view/write_review.tsx"],"sourcesContent":["import React, { useEffect } from \"react\";\nimport type { AdminCollection } from \"@rebasepro/cms-types\";\nimport type { Property } from \"@rebasepro/types\";\nimport { enumToObjectEntries } from \"@rebasepro/common\";\nimport { Alert, Button, Dialog, DialogActions, DialogContent, DialogTitle, Typography } from \"@rebasepro/ui\";\nimport { getPropertyInPath } from \"../util/property_utils\";\nimport type { WriteIntent, WritePlan } from \"./tool_driver\";\n\n/**\n * A write, as the person reads it before or after it happens.\n *\n * The server's plan is written for the model — a row id, which tools run, how\n * to undo through `details.current` — and it was shown as it came. The\n * person is told the same thing in their terms instead: the row by its title,\n * and each field it changes with the value it has and the value it gets, by\n * the field's own label and the enum's own label.\n */\n\ninterface FieldChange {\n label: string;\n from?: string;\n to: string;\n}\n\nconst MAX_VALUE = 80;\n\n/** One value as text, the way the field names it. */\nexport function shownValue(value: unknown, property: Property | undefined): string {\n if (value === undefined || value === null || value === \"\") return \"empty\";\n if (property && (property.type === \"string\" || property.type === \"number\") && property.enum) {\n const entry = enumToObjectEntries(property.enum).find(option => String(option.id) === String(value));\n if (entry) return entry.label;\n }\n if (typeof value === \"boolean\") return value ? \"Yes\" : \"No\";\n if (property?.type === \"date\" && (typeof value === \"string\" || value instanceof Date)) {\n const date = new Date(value);\n if (!Number.isNaN(date.getTime())) return date.toLocaleString();\n }\n if (Array.isArray(value)) return value.length === 1 ? \"1 item\" : `${value.length} items`;\n if (typeof value === \"object\") {\n const id = (value as { id?: unknown }).id;\n return id !== undefined ? String(id) : \"changed\";\n }\n const text = String(value).replace(/\\s+/g, \" \").trim();\n return text.length > MAX_VALUE ? `${text.slice(0, MAX_VALUE - 1)}…` : text;\n}\n\n/** Each field a write sets, labelled, with its old value where it is known and differs. */\nexport function fieldChanges(intent: WriteIntent, collection: AdminCollection | undefined): FieldChange[] {\n return Object.entries(intent.values ?? {}).flatMap(([key, value]) => {\n const property = collection ? getPropertyInPath(collection.properties, key) as Property | undefined : undefined;\n const to = shownValue(value, property);\n const before = intent.previous && key in intent.previous ? shownValue(intent.previous[key], property) : undefined;\n if (before === to) return [];\n return [{ label: property?.name ?? key, ...(before !== undefined && { from: before }), to }];\n });\n}\n\n/** What the row is called: its title, else the collection's word for one. */\nfunction rowName(intent: WriteIntent, collection: AdminCollection | undefined): string {\n if (intent.title) return `“${intent.title}”`;\n const singular = collection?.singularName ?? collection?.name ?? intent.collection;\n return `this ${singular.toLowerCase()}`;\n}\n\nfunction heading(intent: WriteIntent, collection: AdminCollection | undefined): string {\n if (intent.action === \"create\") {\n const singular = (collection?.singularName ?? collection?.name ?? intent.collection).toLowerCase();\n return `Create a new ${singular}?`;\n }\n if (intent.action === \"delete\") return `Delete ${rowName(intent, collection)}?`;\n return `Save changes to ${rowName(intent, collection)}?`;\n}\n\nfunction Changes({ changes }: { changes: FieldChange[] }) {\n if (changes.length === 0) return null;\n return (\n <div className=\"grid gap-x-4 gap-y-1.5\" style={{ gridTemplateColumns: \"auto 1fr\" }}>\n {changes.map(change => (\n <React.Fragment key={change.label}>\n <Typography variant=\"body2\" color=\"secondary\">{change.label}</Typography>\n <Typography variant=\"body2\" className=\"min-w-0 break-words\">\n {change.from !== undefined && (\n <span className=\"text-text-secondary dark:text-text-secondary-dark line-through\">{change.from}</span>\n )}\n {change.from !== undefined && <span className=\"text-text-secondary dark:text-text-secondary-dark\"> → </span>}\n <span className=\"font-medium\">{change.to}</span>\n </Typography>\n </React.Fragment>\n ))}\n </div>\n );\n}\n\n/** The person's yes or no on a write that needs one. */\nexport function WriteConfirmDialog({ plan, collectionOf, onAnswer }: {\n plan: WritePlan | undefined;\n collectionOf: (name: string) => AdminCollection | undefined;\n onAnswer: (confirmed: boolean) => void;\n}) {\n const intent = plan?.write;\n const collection = intent ? collectionOf(intent.collection) : undefined;\n const changes = intent && intent.action !== \"delete\" ? fieldChanges(intent, collection) : [];\n const deleting = intent?.action === \"delete\";\n return (\n <Dialog open={plan !== undefined} onOpenChange={open => !open && onAnswer(false)} maxWidth=\"sm\">\n <DialogTitle variant=\"subtitle1\">{intent ? heading(intent, collection) : \"Save this change?\"}</DialogTitle>\n <DialogContent className=\"flex flex-col gap-3\">\n {intent\n ? <Changes changes={changes}/>\n : <Typography variant=\"body2\">{plan?.summary}</Typography>}\n {deleting && (\n <Typography variant=\"body2\" color=\"secondary\">It is removed from the project for everyone.</Typography>\n )}\n </DialogContent>\n <DialogActions>\n <Button variant=\"text\" color=\"neutral\" onClick={() => onAnswer(false)}>Cancel</Button>\n <Button variant=\"filled\" color={deleting ? \"error\" : \"primary\"} onClick={() => onAnswer(true)}>\n {deleting ? \"Delete\" : intent?.action === \"create\" ? \"Create\" : \"Save\"}\n </Button>\n </DialogActions>\n </Dialog>\n );\n}\n\nconst NOTICE_MS = 5000;\n\n/** What a write that did not ask first changed, said once it is saved, then gone. */\nexport function SavedNotice({ intent, collectionOf, onDismiss }: {\n intent: WriteIntent | undefined;\n collectionOf: (name: string) => AdminCollection | undefined;\n onDismiss: () => void;\n}) {\n useEffect(() => {\n if (!intent) return;\n const timer = setTimeout(onDismiss, NOTICE_MS);\n return () => clearTimeout(timer);\n }, [intent, onDismiss]);\n if (!intent) return null;\n const collection = collectionOf(intent.collection);\n const changes = fieldChanges(intent, collection);\n const what = changes.map(change => `${change.label} → ${change.to}`).join(\", \");\n const name = intent.title ? `“${intent.title}”` : (collection?.singularName ?? \"the row\").toLowerCase();\n return (\n <Alert color=\"success\" size=\"small\" outerClassName=\"sticky top-0 z-10\" onDismiss={onDismiss}>\n {what ? `Saved ${name}: ${what}.` : `Saved ${name}.`}\n </Alert>\n );\n}\n"],"mappings":";;;;;;AAwBA,IAAM,YAAY;;AAGlB,SAAgB,WAAW,OAAgB,UAAwC;CAC/E,IAAI,UAAU,KAAA,KAAa,UAAU,QAAQ,UAAU,IAAI,OAAO;CAClE,IAAI,aAAa,SAAS,SAAS,YAAY,SAAS,SAAS,aAAa,SAAS,MAAM;EACzF,MAAM,QAAQ,oBAAoB,SAAS,IAAI,CAAC,CAAC,MAAK,WAAU,OAAO,OAAO,EAAE,MAAM,OAAO,KAAK,CAAC;EACnG,IAAI,OAAO,OAAO,MAAM;CAC5B;CACA,IAAI,OAAO,UAAU,WAAW,OAAO,QAAQ,QAAQ;CACvD,IAAI,UAAU,SAAS,WAAW,OAAO,UAAU,YAAY,iBAAiB,OAAO;EACnF,MAAM,OAAO,IAAI,KAAK,KAAK;EAC3B,IAAI,CAAC,OAAO,MAAM,KAAK,QAAQ,CAAC,GAAG,OAAO,KAAK,eAAe;CAClE;CACA,IAAI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D,CAAA,CAE/F;;GACf,qBAAC,eAAD,EAAA,UAAA,CACI,oBAAC,QAAD;IAAQ,SAAQ;IAAO,OAAM;IAAU,eAAe,SAAS,KAAK;cAAG;GAAc,CAAA,GACrF,oBAAC,QAAD;IAAQ,SAAQ;IAAS,OAAO,WAAW,UAAU;IAAW,eAAe,SAAS,IAAI;cACvF,WAAW,WAAW,QAAQ,WAAW,WAAW,WAAW;GAC5D,CAAA,CACG,EAAA,CAAA;EACX;;AAEhB;AAEA,IAAM,YAAY;;AAGlB,SAAgB,YAAY,EAAE,QAAQ,cAAc,aAIjD;CACC,gBAAgB;EACZ,IAAI,CAAC,QAAQ;EACb,MAAM,QAAQ,WAAW,WAAW,SAAS;EAC7C,aAAa,aAAa,KAAK;CACnC,GAAG,CAAC,QAAQ,SAAS,CAAC;CACtB,IAAI,CAAC,QAAQ,OAAO;CACpB,MAAM,aAAa,aAAa,OAAO,UAAU;CAEjD,MAAM,OADU,aAAa,QAAQ,UACxB,CAAA,CAAQ,KAAI,WAAU,GAAG,OAAO,MAAM,KAAK,OAAO,IAAI,CAAC,CAAC,KAAK,IAAI;CAC9E,MAAM,OAAO,OAAO,QAAQ,IAAI,OAAO,MAAM,MAAM,YAAY,gBAAgB,UAAA,CAAW,YAAY;CACtG,OACI,oBAAC,OAAD;EAAO,OAAM;EAAU,MAAK;EAAQ,gBAAe;EAA+B;YAC7E,OAAO,SAAS,KAAK,IAAI,KAAK,KAAK,SAAS,KAAK;CAC/C,CAAA;AAEf"}
@@ -1,7 +1,7 @@
1
1
  import { DefaultMissingReference } from "../../components/DefaultMissingReference.js";
2
2
  import { useCollectionRegistryController } from "../../hooks/navigation/contexts/CollectionRegistryContext.js";
3
3
  import { useEntityPreviewLayout, useIsNestedEntityPreview } from "../../components/EntityPreviewNesting.js";
4
- import { EntityPreviewBinding, EntityPreviewBindingData, EntityPreviewContainer } from "../../components/EntityPreviewBinding.js";
4
+ import { EntityPreviewBinding, EntityPreviewBindingData, EntityPreviewBindingSkeleton, EntityPreviewContainer } from "../../components/EntityPreviewBinding.js";
5
5
  import { InlineEntityPreview, InlineEntityPreviewMissing, InlineEntityPreviewSkeleton } from "../../components/InlineEntityPreview.js";
6
6
  import "react";
7
7
  import { jsx } from "react/jsx-runtime";
@@ -148,7 +148,12 @@ function RelationPreviewExisting({ relation, collection, previewProperties, size
148
148
  onClick: disabled ? void 0 : onClick,
149
149
  hover: disabled ? void 0 : hover,
150
150
  size,
151
- children: /* @__PURE__ */ jsx(Skeleton, {})
151
+ children: layout !== "row" && ResolvedEntityPreview === EntityPreviewBinding ? /* @__PURE__ */ jsx(EntityPreviewBindingSkeleton, {
152
+ collection,
153
+ previewKeys: previewProperties,
154
+ size,
155
+ includeEntityLink
156
+ }) : /* @__PURE__ */ jsx(Skeleton, {})
152
157
  });
153
158
  }
154
159
  if (!usedEntity) {
@@ -1 +1 @@
1
- {"version":3,"file":"RelationPreview.js","names":[],"sources":["../../../src/preview/components/RelationPreview.tsx"],"sourcesContent":["\nimport * as React from \"react\";\nimport { DefaultMissingReference } from \"../../components/DefaultMissingReference\";\n\nimport { Entity, EntityRelation } from \"@rebasepro/types\";\nimport type { PreviewSize } from \"../../types/components/PropertyPreviewProps\";\nimport { useCustomizationController, useFetch, ErrorView, useComponentOverride, CollectionScopeProvider } from \"@rebasepro/app\";\nimport { Skeleton } from \"@rebasepro/ui\";\nimport { EntityPreviewBinding, EntityPreviewBindingData, EntityPreviewContainer } from \"../../components/EntityPreviewBinding\";\nimport {\n InlineEntityPreview,\n InlineEntityPreviewMissing,\n InlineEntityPreviewSkeleton\n} from \"../../components/InlineEntityPreview\";\nimport { useEntityPreviewLayout, useIsNestedEntityPreview } from \"../../components/EntityPreviewNesting\";\nimport { useCollectionRegistryController } from \"../../hooks/navigation/contexts/CollectionRegistryContext\";\nimport type { AdminCollection } from \"@rebasepro/cms-types\";\n\nexport type RelationPreviewProps = {\n disabled?: boolean;\n relation: EntityRelation,\n size?: PreviewSize;\n previewProperties?: string[];\n onClick?: (e: React.SyntheticEvent) => void;\n hover?: boolean;\n includeEntityLink?: boolean;\n includeId?: boolean;\n textOnly?: boolean;\n};\n\n/**\n * Extract a display name from a plain relation-shaped object that isn't\n * a proper EntityRelation instance. Tries common name fields in the\n * entity's values, then falls back to the id.\n */\nfunction extractDisplayFromPlainObject(obj: unknown): string {\n if (!obj || typeof obj !== \"object\") return \"—\";\n const record = obj as Record<string, unknown>;\n\n // Try data.values.{name,title,...} (EntityRelation.data is a Entity with .values)\n const data = record.data;\n if (data && typeof data === \"object\") {\n const dataRecord = data as Record<string, unknown>;\n const values = (dataRecord.values && typeof dataRecord.values === \"object\")\n ? dataRecord.values as Record<string, unknown>\n : dataRecord;\n const nameFields = [\"name\", \"title\", \"label\", \"display_name\", \"displayName\", \"email\", \"username\"];\n for (const field of nameFields) {\n const v = values[field];\n if (v && typeof v === \"string\") return v;\n }\n }\n\n // Try direct fields on the object itself (some serialization paths flatten the data)\n const directFields = [\"name\", \"title\", \"label\", \"display_name\", \"displayName\", \"email\"];\n for (const field of directFields) {\n const v = record[field];\n if (v && typeof v === \"string\") return v;\n }\n\n // Last resort: show the id\n if (\"id\" in record && record.id != null) return String(record.id);\n\n return \"—\";\n}\n\n/**\n * @group Preview components\n */\nexport const RelationPreview = function RelationPreview(props: RelationPreviewProps) {\n const relation = props.relation;\n const nested = useIsNestedEntityPreview();\n if (!(typeof relation === \"object\" && \"isEntityRelation\" in relation && relation.isEntityRelation())) {\n console.warn(\"Relation preview received value of type\", typeof relation);\n if (props.textOnly || nested) {\n const display = extractDisplayFromPlainObject(relation);\n return <span className=\"truncate\">{display}</span>;\n }\n return <EntityPreviewContainer\n onClick={props.onClick}\n size={props.size}>\n <ErrorView error={\"Unexpected value. Click to edit\"}\n tooltip={JSON.stringify(relation)}/>\n </EntityPreviewContainer>;\n }\n return <RelationPreviewInternal {...props}/>;\n};\n\n\nfunction RelationPreviewInternalInner({\n disabled,\n relation,\n previewProperties,\n size,\n hover,\n onClick,\n includeEntityLink = true,\n includeId = true,\n textOnly,\n collection\n}: RelationPreviewProps & { collection?: AdminCollection }) {\n const ResolvedMissingReference = useComponentOverride(\"Entity.MissingReference\", DefaultMissingReference);\n const nested = useIsNestedEntityPreview();\n\n if (!collection) {\n if (ResolvedMissingReference !== DefaultMissingReference) {\n return <ResolvedMissingReference path={relation.path}/>;\n } else {\n if (textOnly) {\n return <span>{relation.path}</span>;\n }\n if (nested) {\n return <InlineEntityPreviewMissing label={String(relation.id)}\n tooltip={`Collection not found: ${relation.path}`}/>;\n }\n return <EntityPreviewContainer size={size}>\n <ErrorView error={`Collection not found: ${relation.path}`}/>\n </EntityPreviewContainer>;\n }\n }\n\n return <RelationPreviewExisting\n relation={relation}\n collection={collection}\n previewProperties={previewProperties}\n size={size}\n disabled={disabled}\n includeEntityLink={includeEntityLink}\n includeId={includeId}\n onClick={onClick}\n textOnly={textOnly}\n hover={hover}/>\n}\n\nfunction RelationPreviewInternal(props: RelationPreviewProps) {\n const collectionRegistryController = useCollectionRegistryController();\n const collection = collectionRegistryController.getCollection(props.relation.path);\n\n const content = (\n <RelationPreviewInternalInner\n {...props}\n collection={collection}\n />\n );\n\n if (collection) {\n return (\n <CollectionScopeProvider collection={collection}>\n {content}\n </CollectionScopeProvider>\n );\n }\n return content;\n}\n\nfunction RelationPreviewExisting<M extends Record<string, unknown> = Record<string, unknown>>({\n relation,\n collection,\n previewProperties,\n size,\n disabled,\n includeEntityLink,\n includeId,\n onClick,\n hover,\n textOnly\n}: RelationPreviewProps & {\n collection: AdminCollection<M>\n}) {\n\n // admin wire format embeds relation data as { id, path, values }\n const passedEntity = relation.data as Entity<M> | undefined;\n const ResolvedEntityPreview = useComponentOverride(\"EntityPreview\", EntityPreviewBinding);\n const customizationController = useCustomizationController();\n const nested = useIsNestedEntityPreview();\n const layout = useEntityPreviewLayout();\n\n // Nested inside another preview, filling a title slot, or rendered small\n // (a table cell, a list row): one line of text, not a second card. The\n // card only makes sense where there is room for it. See {@link InlineEntityPreview}.\n const inline = nested || Boolean(textOnly) || size === \"small\";\n\n const {\n entity,\n dataLoading,\n dataLoadingError\n } = useFetch({\n path: relation.path,\n entityId: passedEntity ? undefined : relation.id,\n collection,\n useCache: true\n });\n\n // Only what the fetch currently reports. There used to be a module-level\n // Map behind this, written on every successful fetch and never invalidated:\n // when the target row was deleted `useFetch` correctly reported it gone and\n // the card carried on rendering the copy in the Map, so the \"missing\"\n // branches below were unreachable for anything previewed this session — and\n // the Map outlived a sign-out. `useFetch` keeps its own cache, seeds the\n // first render from it, and clears the entry when the row disappears.\n const usedEntity = passedEntity ?? entity;\n\n let body: React.ReactNode;\n\n if (!relation) {\n body = <ErrorView error={\"Relation not set\"}/>;\n } else if (usedEntity && !usedEntity.values) {\n body = <ErrorView error={\"Relation does not exist\"}\n tooltip={relation.path}/>;\n }\n\n if (body) {\n if (inline) {\n return <InlineEntityPreviewMissing label={String(relation.id)}\n tooltip={relation.pathWithId}/>;\n }\n return (\n <EntityPreviewContainer onClick={disabled ? undefined : onClick}\n hover={disabled ? undefined : hover}\n size={size}>\n {body}\n </EntityPreviewContainer>\n );\n }\n\n if (dataLoading && !usedEntity) {\n if (inline) {\n return <InlineEntityPreviewSkeleton/>;\n }\n return (\n <EntityPreviewContainer onClick={disabled ? undefined : onClick}\n hover={disabled ? undefined : hover}\n size={size}>\n <Skeleton/>\n </EntityPreviewContainer>\n );\n }\n\n if (!usedEntity) {\n if (inline) {\n return <InlineEntityPreviewMissing label={String(relation.id)}\n tooltip={\"Entity not found\"}/>;\n }\n return (\n <EntityPreviewContainer onClick={disabled ? undefined : onClick}\n hover={disabled ? undefined : hover}\n size={size}>\n <ErrorView error={\"Entity not found\"}/>\n </EntityPreviewContainer>\n );\n }\n\n if (inline) {\n return <InlineEntityPreview entity={usedEntity}\n collection={collection}\n disabled={disabled}\n onClick={onClick}\n // In a title slot the row itself is the click target; only a\n // preview nested inside a card opens its own side panel.\n includeEntityLink={!textOnly && includeEntityLink !== false}/>;\n }\n\n // A table cell tall enough for more than a line: the record as a row of\n // it, not a card taller than the row. An overridden preview is the\n // developer's own and is drawn as given.\n if (layout === \"row\" && ResolvedEntityPreview === EntityPreviewBinding) {\n return <EntityPreviewBindingData layout={\"row\"}\n size={size}\n entity={usedEntity}\n collection={collection}\n previewKeys={previewProperties}\n includeEntityLink={!disabled && includeEntityLink !== false}/>;\n }\n\n return <ResolvedEntityPreview size={size}\n previewKeys={previewProperties}\n disabled={disabled}\n entity={usedEntity}\n collection={collection}\n onClick={onClick}\n includeEntityLink={includeEntityLink}\n includeId={false}\n hover={hover}/>;\n\n}\n"],"mappings":";;;;;;;;;;;;;;;AAmCA,SAAS,8BAA8B,KAAsB;CACzD,IAAI,CAAC,OAAO,OAAO,QAAQ,UAAU,OAAO;CAC5C,MAAM,SAAS;CAGf,MAAM,OAAO,OAAO;CACpB,IAAI,QAAQ,OAAO,SAAS,UAAU;EAClC,MAAM,aAAa;EACnB,MAAM,SAAU,WAAW,UAAU,OAAO,WAAW,WAAW,WAC5D,WAAW,SACX;EAEN,KAAK,MAAM,SAAS;GADA;GAAQ;GAAS;GAAS;GAAgB;GAAe;GAAS;EAClE,GAAY;GAC5B,MAAM,IAAI,OAAO;GACjB,IAAI,KAAK,OAAO,MAAM,UAAU,OAAO;EAC3C;CACJ;CAIA,KAAK,MAAM,SAAS;EADE;EAAQ;EAAS;EAAS;EAAgB;EAAe;CAC3D,GAAc;EAC9B,MAAM,IAAI,OAAO;EACjB,IAAI,KAAK,OAAO,MAAM,UAAU,OAAO;CAC3C;CAGA,IAAI,QAAQ,UAAU,OAAO,MAAM,MAAM,OAAO,OAAO,OAAO,EAAE;CAEhE,OAAO;AACX;;;;AAKA,IAAa,kBAAkB,SAAS,gBAAgB,OAA6B;CACjF,MAAM,WAAW,MAAM;CACvB,MAAM,SAAS,yBAAyB;CACxC,IAAI,EAAE,OAAO,aAAa,YAAY,sBAAsB,YAAY,SAAS,iBAAiB,IAAI;EAClG,QAAQ,KAAK,2CAA2C,OAAO,Q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AC,WAAD,EAAW,OAAO,mBAAoB,CAAA;EAClB,CAAA;CAEhC;CAEA,IAAI,QACA,OAAO,oBAAC,qBAAD;EAAqB,QAAQ;EACpB;EACF;EACD;EAGT,mBAAmB,CAAC,YAAY,sBAAsB;CAAO,CAAA;CAMrE,IAAI,WAAW,SAAS,0BAA0B,sBAC9C,OAAO,oBAAC,0BAAD;EAA0B,QAAQ;EAC/B;EACN,QAAQ;EACI;EACZ,aAAa;EACb,mBAAmB,CAAC,YAAY,sBAAsB;CAAO,CAAA;CAGrE,OAAO,oBAAC,uBAAD;EAA6B;EAChC,aAAa;EACH;EACV,QAAQ;EACI;EACH;EACU;EACnB,WAAW;EACJ;CAAO,CAAA;AAEtB"}
1
+ {"version":3,"file":"RelationPreview.js","names":[],"sources":["../../../src/preview/components/RelationPreview.tsx"],"sourcesContent":["\nimport * as React from \"react\";\nimport { DefaultMissingReference } from \"../../components/DefaultMissingReference\";\n\nimport { Entity, EntityRelation } from \"@rebasepro/types\";\nimport type { PreviewSize } from \"../../types/components/PropertyPreviewProps\";\nimport { useCustomizationController, useFetch, ErrorView, useComponentOverride, CollectionScopeProvider } from \"@rebasepro/app\";\nimport { Skeleton } from \"@rebasepro/ui\";\nimport { EntityPreviewBinding, EntityPreviewBindingData, EntityPreviewBindingSkeleton, EntityPreviewContainer } from \"../../components/EntityPreviewBinding\";\nimport {\n InlineEntityPreview,\n InlineEntityPreviewMissing,\n InlineEntityPreviewSkeleton\n} from \"../../components/InlineEntityPreview\";\nimport { useEntityPreviewLayout, useIsNestedEntityPreview } from \"../../components/EntityPreviewNesting\";\nimport { useCollectionRegistryController } from \"../../hooks/navigation/contexts/CollectionRegistryContext\";\nimport type { AdminCollection } from \"@rebasepro/cms-types\";\n\nexport type RelationPreviewProps = {\n disabled?: boolean;\n relation: EntityRelation,\n size?: PreviewSize;\n previewProperties?: string[];\n onClick?: (e: React.SyntheticEvent) => void;\n hover?: boolean;\n includeEntityLink?: boolean;\n includeId?: boolean;\n textOnly?: boolean;\n};\n\n/**\n * Extract a display name from a plain relation-shaped object that isn't\n * a proper EntityRelation instance. Tries common name fields in the\n * entity's values, then falls back to the id.\n */\nfunction extractDisplayFromPlainObject(obj: unknown): string {\n if (!obj || typeof obj !== \"object\") return \"—\";\n const record = obj as Record<string, unknown>;\n\n // Try data.values.{name,title,...} (EntityRelation.data is a Entity with .values)\n const data = record.data;\n if (data && typeof data === \"object\") {\n const dataRecord = data as Record<string, unknown>;\n const values = (dataRecord.values && typeof dataRecord.values === \"object\")\n ? dataRecord.values as Record<string, unknown>\n : dataRecord;\n const nameFields = [\"name\", \"title\", \"label\", \"display_name\", \"displayName\", \"email\", \"username\"];\n for (const field of nameFields) {\n const v = values[field];\n if (v && typeof v === \"string\") return v;\n }\n }\n\n // Try direct fields on the object itself (some serialization paths flatten the data)\n const directFields = [\"name\", \"title\", \"label\", \"display_name\", \"displayName\", \"email\"];\n for (const field of directFields) {\n const v = record[field];\n if (v && typeof v === \"string\") return v;\n }\n\n // Last resort: show the id\n if (\"id\" in record && record.id != null) return String(record.id);\n\n return \"—\";\n}\n\n/**\n * @group Preview components\n */\nexport const RelationPreview = function RelationPreview(props: RelationPreviewProps) {\n const relation = props.relation;\n const nested = useIsNestedEntityPreview();\n if (!(typeof relation === \"object\" && \"isEntityRelation\" in relation && relation.isEntityRelation())) {\n console.warn(\"Relation preview received value of type\", typeof relation);\n if (props.textOnly || nested) {\n const display = extractDisplayFromPlainObject(relation);\n return <span className=\"truncate\">{display}</span>;\n }\n return <EntityPreviewContainer\n onClick={props.onClick}\n size={props.size}>\n <ErrorView error={\"Unexpected value. Click to edit\"}\n tooltip={JSON.stringify(relation)}/>\n </EntityPreviewContainer>;\n }\n return <RelationPreviewInternal {...props}/>;\n};\n\n\nfunction RelationPreviewInternalInner({\n disabled,\n relation,\n previewProperties,\n size,\n hover,\n onClick,\n includeEntityLink = true,\n includeId = true,\n textOnly,\n collection\n}: RelationPreviewProps & { collection?: AdminCollection }) {\n const ResolvedMissingReference = useComponentOverride(\"Entity.MissingReference\", DefaultMissingReference);\n const nested = useIsNestedEntityPreview();\n\n if (!collection) {\n if (ResolvedMissingReference !== DefaultMissingReference) {\n return <ResolvedMissingReference path={relation.path}/>;\n } else {\n if (textOnly) {\n return <span>{relation.path}</span>;\n }\n if (nested) {\n return <InlineEntityPreviewMissing label={String(relation.id)}\n tooltip={`Collection not found: ${relation.path}`}/>;\n }\n return <EntityPreviewContainer size={size}>\n <ErrorView error={`Collection not found: ${relation.path}`}/>\n </EntityPreviewContainer>;\n }\n }\n\n return <RelationPreviewExisting\n relation={relation}\n collection={collection}\n previewProperties={previewProperties}\n size={size}\n disabled={disabled}\n includeEntityLink={includeEntityLink}\n includeId={includeId}\n onClick={onClick}\n textOnly={textOnly}\n hover={hover}/>\n}\n\nfunction RelationPreviewInternal(props: RelationPreviewProps) {\n const collectionRegistryController = useCollectionRegistryController();\n const collection = collectionRegistryController.getCollection(props.relation.path);\n\n const content = (\n <RelationPreviewInternalInner\n {...props}\n collection={collection}\n />\n );\n\n if (collection) {\n return (\n <CollectionScopeProvider collection={collection}>\n {content}\n </CollectionScopeProvider>\n );\n }\n return content;\n}\n\nfunction RelationPreviewExisting<M extends Record<string, unknown> = Record<string, unknown>>({\n relation,\n collection,\n previewProperties,\n size,\n disabled,\n includeEntityLink,\n includeId,\n onClick,\n hover,\n textOnly\n}: RelationPreviewProps & {\n collection: AdminCollection<M>\n}) {\n\n // admin wire format embeds relation data as { id, path, values }\n const passedEntity = relation.data as Entity<M> | undefined;\n const ResolvedEntityPreview = useComponentOverride(\"EntityPreview\", EntityPreviewBinding);\n const customizationController = useCustomizationController();\n const nested = useIsNestedEntityPreview();\n const layout = useEntityPreviewLayout();\n\n // Nested inside another preview, filling a title slot, or rendered small\n // (a table cell, a list row): one line of text, not a second card. The\n // card only makes sense where there is room for it. See {@link InlineEntityPreview}.\n const inline = nested || Boolean(textOnly) || size === \"small\";\n\n const {\n entity,\n dataLoading,\n dataLoadingError\n } = useFetch({\n path: relation.path,\n entityId: passedEntity ? undefined : relation.id,\n collection,\n useCache: true\n });\n\n // Only what the fetch currently reports. There used to be a module-level\n // Map behind this, written on every successful fetch and never invalidated:\n // when the target row was deleted `useFetch` correctly reported it gone and\n // the card carried on rendering the copy in the Map, so the \"missing\"\n // branches below were unreachable for anything previewed this session — and\n // the Map outlived a sign-out. `useFetch` keeps its own cache, seeds the\n // first render from it, and clears the entry when the row disappears.\n const usedEntity = passedEntity ?? entity;\n\n let body: React.ReactNode;\n\n if (!relation) {\n body = <ErrorView error={\"Relation not set\"}/>;\n } else if (usedEntity && !usedEntity.values) {\n body = <ErrorView error={\"Relation does not exist\"}\n tooltip={relation.path}/>;\n }\n\n if (body) {\n if (inline) {\n return <InlineEntityPreviewMissing label={String(relation.id)}\n tooltip={relation.pathWithId}/>;\n }\n return (\n <EntityPreviewContainer onClick={disabled ? undefined : onClick}\n hover={disabled ? undefined : hover}\n size={size}>\n {body}\n </EntityPreviewContainer>\n );\n }\n\n if (dataLoading && !usedEntity) {\n if (inline) {\n return <InlineEntityPreviewSkeleton/>;\n }\n // The card it will be, so it does not grow when the record arrives;\n // an overridden preview or a table row is the developer's own shape,\n // and the bar stands in for it as before.\n const asCard = layout !== \"row\" && ResolvedEntityPreview === EntityPreviewBinding;\n return (\n <EntityPreviewContainer onClick={disabled ? undefined : onClick}\n hover={disabled ? undefined : hover}\n size={size}>\n {asCard\n ? <EntityPreviewBindingSkeleton collection={collection}\n previewKeys={previewProperties}\n size={size}\n includeEntityLink={includeEntityLink}/>\n : <Skeleton/>}\n </EntityPreviewContainer>\n );\n }\n\n if (!usedEntity) {\n if (inline) {\n return <InlineEntityPreviewMissing label={String(relation.id)}\n tooltip={\"Entity not found\"}/>;\n }\n return (\n <EntityPreviewContainer onClick={disabled ? undefined : onClick}\n hover={disabled ? undefined : hover}\n size={size}>\n <ErrorView error={\"Entity not found\"}/>\n </EntityPreviewContainer>\n );\n }\n\n if (inline) {\n return <InlineEntityPreview entity={usedEntity}\n collection={collection}\n disabled={disabled}\n onClick={onClick}\n // In a title slot the row itself is the click target; only a\n // preview nested inside a card opens its own side panel.\n includeEntityLink={!textOnly && includeEntityLink !== false}/>;\n }\n\n // A table cell tall enough for more than a line: the record as a row of\n // it, not a card taller than the row. An overridden preview is the\n // developer's own and is drawn as given.\n if (layout === \"row\" && ResolvedEntityPreview === EntityPreviewBinding) {\n return <EntityPreviewBindingData layout={\"row\"}\n size={size}\n entity={usedEntity}\n collection={collection}\n previewKeys={previewProperties}\n includeEntityLink={!disabled && includeEntityLink !== false}/>;\n }\n\n return <ResolvedEntityPreview size={size}\n previewKeys={previewProperties}\n disabled={disabled}\n entity={usedEntity}\n collection={collection}\n onClick={onClick}\n includeEntityLink={includeEntityLink}\n includeId={false}\n hover={hover}/>;\n\n}\n"],"mappings":";;;;;;;;;;;;;;;AAmCA,SAAS,8BAA8B,KAAsB;CACzD,IAAI,CAAC,OAAO,OAAO,QAAQ,UAAU,OAAO;CAC5C,MAAM,SAAS;CAGf,MAAM,OAAO,OAAO;CACpB,IAAI,QAAQ,OAAO,SAAS,UAAU;EAClC,MAAM,aAAa;EACnB,MAAM,SAAU,WAAW,UAAU,OAAO,WAAW,WAAW,WAC5D,WAAW,SACX;EAEN,KAAK,MAAM,SAAS;GADA;GAAQ;GAAS;GAAS;GAAgB;GAAe;GAAS;EAClE,GAAY;GAC5B,MAAM,IAAI,OAAO;GACjB,IAAI,KAAK,OAAO,MAAM,UAAU,OAAO;EAC3C;CACJ;CAIA,KAAK,MAAM,SAAS;EADE;EAAQ;EAAS;EAAS;EAAgB;EAAe;CAC3D,GAAc;EAC9B,MAAM,IAAI,OAAO;EACjB,IAAI,KAAK,OAAO,MAAM,UAAU,OAAO;CAC3C;CAGA,IAAI,QAAQ,UAAU,OAAO,MAAM,MAAM,OAAO,OAAO,OAAO,EAAE;CAEhE,OAAO;AACX;;;;AAKA,IAAa,kBAAkB,SAAS,gBAAgB,OAA6B;CACjF,MAAM,WAAW,MAAM;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;CAEhC;CAEA,IAAI,CAAC,YAAY;EACb,IAAI,QACA,OAAO,oBAAC,4BAAD;GAA4B,OAAO,OAAO,SAAS,EAAE;GACxD,SAAS;EAAoB,CAAA;EAErC,OACI,oBAAC,wBAAD;GAAwB,SAAS,WAAW,KAAA,IAAY;GACpD,OAAO,WAAW,KAAA,IAAY;GACxB;aACN,oBAAC,WAAD,EAAW,OAAO,mBAAoB,CAAA;EAClB,CAAA;CAEhC;CAEA,IAAI,QACA,OAAO,oBAAC,qBAAD;EAAqB,QAAQ;EACpB;EACF;EACD;EAGT,mBAAmB,CAAC,YAAY,sBAAsB;CAAO,CAAA;CAMrE,IAAI,WAAW,SAAS,0BAA0B,sBAC9C,OAAO,oBAAC,0BAAD;EAA0B,QAAQ;EAC/B;EACN,QAAQ;EACI;EACZ,aAAa;EACb,mBAAmB,CAAC,YAAY,sBAAsB;CAAO,CAAA;CAGrE,OAAO,oBAAC,uBAAD;EAA6B;EAChC,aAAa;EACH;EACV,QAAQ;EACI;EACH;EACU;EACnB,WAAW;EACJ;CAAO,CAAA;AAEtB"}
@@ -0,0 +1,17 @@
1
+ /**
2
+ * EXPERIMENTAL. The apps saved to the project (save_app), for the person
3
+ * signed in: theirs, their roles' and the team's. Opening one runs it as
4
+ * Claude runs it, sandboxed (`SavedAppFrame`).
5
+ *
6
+ * Not in the navigation by default. A project that wants it adds the view:
7
+ *
8
+ * ```tsx
9
+ * import { savedAppsView } from "@rebasepro/cms";
10
+ * <RebaseCMS collections={collections} views={[savedAppsView]} />
11
+ * ```
12
+ */
13
+ import React from "react";
14
+ import type { AppView } from "@rebasepro/cms-types";
15
+ export declare function SavedAppsView(): React.JSX.Element;
16
+ /** The view to add to `views` for saved apps in the navigation. */
17
+ export declare const savedAppsView: AppView;
@@ -0,0 +1,167 @@
1
+ import { createAdminAppsClient, isRecord } from "./admin_apps_client.js";
2
+ import { SavedAppFrame } from "./saved_app_frame.js";
3
+ import { useEffect, useMemo, useState } from "react";
4
+ import { Fragment, jsx, jsxs } from "react/jsx-runtime";
5
+ import { Alert, ArrowLeftIcon, Card, Chip, CircularProgress, Container, IconButton, Typography, cls } from "@rebasepro/ui";
6
+ import { useApiBase, useApiConfig } from "@rebasepro/app";
7
+ //#region src/saved_apps/SavedAppsView.tsx
8
+ /**
9
+ * EXPERIMENTAL. The apps saved to the project (save_app), for the person
10
+ * signed in: theirs, their roles' and the team's. Opening one runs it as
11
+ * Claude runs it, sandboxed (`SavedAppFrame`).
12
+ *
13
+ * Not in the navigation by default. A project that wants it adds the view:
14
+ *
15
+ * ```tsx
16
+ * import { savedAppsView } from "@rebasepro/cms";
17
+ * <RebaseCMS collections={collections} views={[savedAppsView]} />
18
+ * ```
19
+ */
20
+ /** Who an app is for, as the list says it. */
21
+ function audience(app) {
22
+ if (app.visibility === "team") return "Team";
23
+ if (app.visibility === "roles") return app.roles.join(", ");
24
+ return "Only you";
25
+ }
26
+ function summariesOf(result) {
27
+ const content = isRecord(result) ? result.structuredContent : void 0;
28
+ return (isRecord(content) && Array.isArray(content.apps) ? content.apps : []).filter(isRecord).flatMap((app) => typeof app.id === "string" && typeof app.title === "string" ? [{
29
+ id: app.id,
30
+ title: app.title,
31
+ visibility: app.visibility === "team" || app.visibility === "roles" ? app.visibility : "personal",
32
+ roles: Array.isArray(app.roles) ? app.roles.filter((role) => typeof role === "string") : [],
33
+ collections: Array.isArray(app.collections) ? app.collections.filter((name) => typeof name === "string") : [],
34
+ updatedAt: typeof app.updatedAt === "string" ? app.updatedAt : ""
35
+ }] : []);
36
+ }
37
+ function SavedAppsView() {
38
+ const apiBase = useApiBase();
39
+ const getAuthToken = useApiConfig()?.getAuthToken;
40
+ const client = useMemo(() => apiBase ? createAdminAppsClient(apiBase, getAuthToken) : void 0, [apiBase, getAuthToken]);
41
+ const [apps, setApps] = useState();
42
+ const [error, setError] = useState();
43
+ const [open, setOpen] = useState();
44
+ useEffect(() => {
45
+ if (!client) return;
46
+ let cancelled = false;
47
+ client.request("tools/call", {
48
+ name: "list_apps",
49
+ arguments: {}
50
+ }).then((result) => {
51
+ if (!cancelled) setApps(summariesOf(result));
52
+ }).catch((reason) => {
53
+ if (!cancelled) setError(reason instanceof Error ? reason.message : String(reason));
54
+ });
55
+ return () => {
56
+ cancelled = true;
57
+ };
58
+ }, [client]);
59
+ return /* @__PURE__ */ jsx(Container, {
60
+ maxWidth: "6xl",
61
+ className: "flex flex-col gap-4 py-6",
62
+ children: open && client ? /* @__PURE__ */ jsxs(Fragment, { children: [/* @__PURE__ */ jsxs("div", {
63
+ className: "flex items-center gap-2",
64
+ children: [
65
+ /* @__PURE__ */ jsx(IconButton, {
66
+ size: "small",
67
+ "aria-label": "Back to saved apps",
68
+ onClick: () => setOpen(void 0),
69
+ children: /* @__PURE__ */ jsx(ArrowLeftIcon, {})
70
+ }),
71
+ /* @__PURE__ */ jsx(Typography, {
72
+ variant: "h6",
73
+ className: "truncate",
74
+ children: open.title
75
+ }),
76
+ /* @__PURE__ */ jsx(Chip, {
77
+ size: "small",
78
+ children: audience(open)
79
+ })
80
+ ]
81
+ }), /* @__PURE__ */ jsx(SavedAppFrame, {
82
+ client,
83
+ appId: open.id
84
+ })] }) : /* @__PURE__ */ jsxs(Fragment, { children: [
85
+ /* @__PURE__ */ jsxs("div", {
86
+ className: "flex flex-col gap-1",
87
+ children: [/* @__PURE__ */ jsx(Typography, {
88
+ variant: "h5",
89
+ children: "Saved apps"
90
+ }), /* @__PURE__ */ jsx(Typography, {
91
+ variant: "body2",
92
+ color: "secondary",
93
+ children: "Apps built with Claude and saved to this project. Each one runs as you, on the data you can reach."
94
+ })]
95
+ }),
96
+ !client && /* @__PURE__ */ jsx(Alert, {
97
+ color: "warning",
98
+ size: "small",
99
+ children: "This admin panel has no API address to load saved apps from."
100
+ }),
101
+ error && /* @__PURE__ */ jsx(Alert, {
102
+ color: "error",
103
+ size: "small",
104
+ children: error
105
+ }),
106
+ client && !error && !apps && /* @__PURE__ */ jsxs("div", {
107
+ className: "flex items-center gap-2",
108
+ children: [/* @__PURE__ */ jsx(CircularProgress, { size: "small" }), /* @__PURE__ */ jsx(Typography, {
109
+ variant: "body2",
110
+ color: "secondary",
111
+ children: "Loading saved apps…"
112
+ })]
113
+ }),
114
+ apps && apps.length === 0 && /* @__PURE__ */ jsx(Typography, {
115
+ variant: "body2",
116
+ color: "secondary",
117
+ children: "No saved apps yet. Ask Claude to build one with show_app, then to save it with save_app."
118
+ }),
119
+ apps && apps.length > 0 && /* @__PURE__ */ jsx("div", {
120
+ className: "grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-3 gap-3",
121
+ children: apps.map((app) => /* @__PURE__ */ jsxs(Card, {
122
+ onClick: () => setOpen(app),
123
+ className: cls("flex flex-col gap-2 p-4 cursor-pointer hover:bg-surface-card-hover"),
124
+ children: [
125
+ /* @__PURE__ */ jsx(Typography, {
126
+ variant: "subtitle2",
127
+ className: "truncate",
128
+ children: app.title
129
+ }),
130
+ /* @__PURE__ */ jsx(Typography, {
131
+ variant: "caption",
132
+ color: "secondary",
133
+ className: "truncate",
134
+ children: app.collections.join(", ")
135
+ }),
136
+ /* @__PURE__ */ jsxs("div", {
137
+ className: "flex items-center justify-between gap-2",
138
+ children: [/* @__PURE__ */ jsx(Chip, {
139
+ size: "small",
140
+ children: audience(app)
141
+ }), app.updatedAt && /* @__PURE__ */ jsx(Typography, {
142
+ variant: "caption",
143
+ color: "secondary",
144
+ children: new Date(app.updatedAt).toLocaleDateString(void 0, {
145
+ month: "short",
146
+ day: "numeric"
147
+ })
148
+ })]
149
+ })
150
+ ]
151
+ }, app.id))
152
+ })
153
+ ] })
154
+ });
155
+ }
156
+ /** The view to add to `views` for saved apps in the navigation. */
157
+ var savedAppsView = {
158
+ slug: "apps",
159
+ name: "Saved apps",
160
+ description: "Apps built with Claude and saved to this project.",
161
+ icon: "LayoutDashboard",
162
+ view: /* @__PURE__ */ jsx(SavedAppsView, {})
163
+ };
164
+ //#endregion
165
+ export { SavedAppsView, savedAppsView };
166
+
167
+ //# sourceMappingURL=SavedAppsView.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"SavedAppsView.js","names":[],"sources":["../../src/saved_apps/SavedAppsView.tsx"],"sourcesContent":["/**\n * EXPERIMENTAL. The apps saved to the project (save_app), for the person\n * signed in: theirs, their roles' and the team's. Opening one runs it as\n * Claude runs it, sandboxed (`SavedAppFrame`).\n *\n * Not in the navigation by default. A project that wants it adds the view:\n *\n * ```tsx\n * import { savedAppsView } from \"@rebasepro/cms\";\n * <RebaseCMS collections={collections} views={[savedAppsView]} />\n * ```\n */\nimport React, { useEffect, useMemo, useState } from \"react\";\nimport type { AppView } from \"@rebasepro/cms-types\";\nimport { useApiBase, useApiConfig } from \"@rebasepro/app\";\nimport { Alert, ArrowLeftIcon, Card, Chip, CircularProgress, Container, IconButton, Typography, cls } from \"@rebasepro/ui\";\nimport { createAdminAppsClient, isRecord } from \"./admin_apps_client\";\nimport { SavedAppFrame } from \"./saved_app_frame\";\n\ninterface AppSummary {\n id: string;\n title: string;\n visibility: \"personal\" | \"roles\" | \"team\";\n roles: string[];\n collections: string[];\n updatedAt: string;\n}\n\n/** Who an app is for, as the list says it. */\nfunction audience(app: AppSummary): string {\n if (app.visibility === \"team\") return \"Team\";\n if (app.visibility === \"roles\") return app.roles.join(\", \");\n return \"Only you\";\n}\n\nfunction summariesOf(result: unknown): AppSummary[] {\n const content = isRecord(result) ? result.structuredContent : undefined;\n const apps = isRecord(content) && Array.isArray(content.apps) ? content.apps : [];\n return apps.filter(isRecord).flatMap(app => typeof app.id === \"string\" && typeof app.title === \"string\"\n ? [{\n id: app.id,\n title: app.title,\n visibility: app.visibility === \"team\" || app.visibility === \"roles\" ? app.visibility : \"personal\",\n roles: Array.isArray(app.roles) ? app.roles.filter((role): role is string => typeof role === \"string\") : [],\n collections: Array.isArray(app.collections) ? app.collections.filter((name): name is string => typeof name === \"string\") : [],\n updatedAt: typeof app.updatedAt === \"string\" ? app.updatedAt : \"\"\n }]\n : []);\n}\n\nexport function SavedAppsView() {\n const apiBase = useApiBase();\n const getAuthToken = useApiConfig()?.getAuthToken;\n const client = useMemo(() => apiBase ? createAdminAppsClient(apiBase, getAuthToken) : undefined, [apiBase, getAuthToken]);\n const [apps, setApps] = useState<AppSummary[]>();\n const [error, setError] = useState<string>();\n const [open, setOpen] = useState<AppSummary>();\n\n useEffect(() => {\n if (!client) return;\n let cancelled = false;\n client.request(\"tools/call\", { name: \"list_apps\", arguments: {} })\n .then(result => {\n if (!cancelled) setApps(summariesOf(result));\n })\n .catch((reason: unknown) => {\n if (!cancelled) setError(reason instanceof Error ? reason.message : String(reason));\n });\n return () => {\n cancelled = true;\n };\n }, [client]);\n\n return (\n <Container maxWidth=\"6xl\" className=\"flex flex-col gap-4 py-6\">\n {open && client ? (\n <>\n <div className=\"flex items-center gap-2\">\n <IconButton size=\"small\" aria-label=\"Back to saved apps\" onClick={() => setOpen(undefined)}>\n <ArrowLeftIcon/>\n </IconButton>\n <Typography variant=\"h6\" className=\"truncate\">{open.title}</Typography>\n <Chip size=\"small\">{audience(open)}</Chip>\n </div>\n <SavedAppFrame client={client} appId={open.id}/>\n </>\n ) : (\n <>\n <div className=\"flex flex-col gap-1\">\n <Typography variant=\"h5\">Saved apps</Typography>\n <Typography variant=\"body2\" color=\"secondary\">\n Apps built with Claude and saved to this project. Each one runs as you, on the data you can reach.\n </Typography>\n </div>\n {!client && <Alert color=\"warning\" size=\"small\">This admin panel has no API address to load saved apps from.</Alert>}\n {error && <Alert color=\"error\" size=\"small\">{error}</Alert>}\n {client && !error && !apps && (\n <div className=\"flex items-center gap-2\"><CircularProgress size=\"small\"/><Typography variant=\"body2\" color=\"secondary\">Loading saved apps…</Typography></div>\n )}\n {apps && apps.length === 0 && (\n <Typography variant=\"body2\" color=\"secondary\">\n No saved apps yet. Ask Claude to build one with show_app, then to save it with save_app.\n </Typography>\n )}\n {apps && apps.length > 0 && (\n <div className=\"grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-3 gap-3\">\n {apps.map(app => (\n <Card key={app.id} onClick={() => setOpen(app)} className={cls(\"flex flex-col gap-2 p-4 cursor-pointer hover:bg-surface-card-hover\")}>\n <Typography variant=\"subtitle2\" className=\"truncate\">{app.title}</Typography>\n <Typography variant=\"caption\" color=\"secondary\" className=\"truncate\">{app.collections.join(\", \")}</Typography>\n <div className=\"flex items-center justify-between gap-2\">\n <Chip size=\"small\">{audience(app)}</Chip>\n {app.updatedAt && (\n <Typography variant=\"caption\" color=\"secondary\">\n {new Date(app.updatedAt).toLocaleDateString(undefined, { month: \"short\", day: \"numeric\" })}\n </Typography>\n )}\n </div>\n </Card>\n ))}\n </div>\n )}\n </>\n )}\n </Container>\n );\n}\n\n/** The view to add to `views` for saved apps in the navigation. */\nexport const savedAppsView: AppView = {\n slug: \"apps\",\n name: \"Saved apps\",\n description: \"Apps built with Claude and saved to this project.\",\n icon: \"LayoutDashboard\",\n view: <SavedAppsView/>\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AA6BA,SAAS,SAAS,KAAyB;CACvC,IAAI,IAAI,eAAe,QAAQ,OAAO;CACtC,IAAI,IAAI,eAAe,SAAS,OAAO,IAAI,MAAM,KAAK,IAAI;CAC1D,OAAO;AACX;AAEA,SAAS,YAAY,QAA+B;CAChD,MAAM,UAAU,SAAS,MAAM,IAAI,OAAO,oBAAoB,KAAA;CAE9D,QADa,SAAS,OAAO,KAAK,MAAM,QAAQ,QAAQ,IAAI,IAAI,QAAQ,OAAO,CAAC,EAAA,CACpE,OAAO,QAAQ,CAAC,CAAC,SAAQ,QAAO,OAAO,IAAI,OAAO,YAAY,OAAO,IAAI,UAAU,WACzF,CAAC;EACC,IAAI,IAAI;EACR,OAAO,IAAI;EACX,YAAY,IAAI,eAAe,UAAU,IAAI,eAAe,UAAU,IAAI,aAAa;EACvF,OAAO,MAAM,QAAQ,IAAI,KAAK,IAAI,IAAI,MAAM,QAAQ,SAAyB,OAAO,SAAS,QAAQ,IAAI,CAAC;EAC1G,aAAa,MAAM,QAA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;SAAS,KAAK;QAAU,CAAC;OACjF,CAAA,CAEf;;KACH;OAXK,IAAI,EAWT,CACT;GACA,CAAA;EAEX,EAAA,CAAA;CAEC,CAAA;AAEnB;;AAGA,IAAa,gBAAyB;CAClC,MAAM;CACN,MAAM;CACN,aAAa;CACb,MAAM;CACN,MAAM,oBAAC,eAAD,CAAe,CAAA;AACzB"}
@@ -0,0 +1,24 @@
1
+ /**
2
+ * EXPERIMENTAL. The admin panel's side of `POST /api/admin/apps/mcp`
3
+ * (`mcp/admin-apps-mcp.ts` in `@rebasepro/server`): JSON-RPC to the backend's
4
+ * MCP surface with the admin panel's own session.
5
+ */
6
+ /** What a tool answers, as MCP shapes it. */
7
+ export interface AdminToolResult {
8
+ content?: Array<{
9
+ type: string;
10
+ text?: string;
11
+ }>;
12
+ structuredContent?: unknown;
13
+ isError?: boolean;
14
+ }
15
+ export interface AdminAppsClient {
16
+ /** A JSON-RPC method's result; rejects with the server's message. */
17
+ request(method: string, params: Record<string, unknown>): Promise<unknown>;
18
+ /** A tool's whole answer, a refusal included: the view shows its reason. */
19
+ callTool(name: string, args: Record<string, unknown>): Promise<AdminToolResult>;
20
+ }
21
+ export declare function createAdminAppsClient(apiBase: string, getAuthToken?: () => Promise<string | null | undefined>): AdminAppsClient;
22
+ /** The first text a tool answered: its refusal, when it refused. */
23
+ export declare function toolText(result: AdminToolResult): string | undefined;
24
+ export declare function isRecord(value: unknown): value is Record<string, unknown>;
@@ -0,0 +1,46 @@
1
+ //#region src/saved_apps/admin_apps_client.ts
2
+ function createAdminAppsClient(apiBase, getAuthToken) {
3
+ let nextId = 1;
4
+ const request = async (method, params) => {
5
+ const token = await getAuthToken?.();
6
+ const response = await fetch(`${apiBase}/admin/apps/mcp`, {
7
+ method: "POST",
8
+ headers: {
9
+ "Content-Type": "application/json",
10
+ ...token && { Authorization: `Bearer ${token}` }
11
+ },
12
+ body: JSON.stringify({
13
+ jsonrpc: "2.0",
14
+ id: nextId++,
15
+ method,
16
+ params
17
+ })
18
+ });
19
+ const body = await response.json().catch(() => void 0);
20
+ if (!isRecord(body)) throw new Error(`The server answered ${response.status} without a result.`);
21
+ if (isRecord(body.error)) throw new Error(String(body.error.message ?? "The server refused the request."));
22
+ if (!response.ok) throw new Error(`The server answered ${response.status}.`);
23
+ return body.result;
24
+ };
25
+ return {
26
+ request,
27
+ async callTool(name, args) {
28
+ const result = await request("tools/call", {
29
+ name,
30
+ arguments: args
31
+ });
32
+ return isRecord(result) ? result : {};
33
+ }
34
+ };
35
+ }
36
+ /** The first text a tool answered: its refusal, when it refused. */
37
+ function toolText(result) {
38
+ return result.content?.find((block) => block.type === "text" && typeof block.text === "string")?.text;
39
+ }
40
+ function isRecord(value) {
41
+ return typeof value === "object" && value !== null && !Array.isArray(value);
42
+ }
43
+ //#endregion
44
+ export { createAdminAppsClient, isRecord, toolText };
45
+
46
+ //# sourceMappingURL=admin_apps_client.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"admin_apps_client.js","names":[],"sources":["../../src/saved_apps/admin_apps_client.ts"],"sourcesContent":["/**\n * EXPERIMENTAL. The admin panel's side of `POST /api/admin/apps/mcp`\n * (`mcp/admin-apps-mcp.ts` in `@rebasepro/server`): JSON-RPC to the backend's\n * MCP surface with the admin panel's own session.\n */\n\n/** What a tool answers, as MCP shapes it. */\nexport interface AdminToolResult {\n content?: Array<{ type: string; text?: string }>;\n structuredContent?: unknown;\n isError?: boolean;\n}\n\nexport interface AdminAppsClient {\n /** A JSON-RPC method's result; rejects with the server's message. */\n request(method: string, params: Record<string, unknown>): Promise<unknown>;\n /** A tool's whole answer, a refusal included: the view shows its reason. */\n callTool(name: string, args: Record<string, unknown>): Promise<AdminToolResult>;\n}\n\nexport function createAdminAppsClient(apiBase: string, getAuthToken?: () => Promise<string | null | undefined>): AdminAppsClient {\n let nextId = 1;\n const request = async (method: string, params: Record<string, unknown>): Promise<unknown> => {\n const token = await getAuthToken?.();\n const response = await fetch(`${apiBase}/admin/apps/mcp`, {\n method: \"POST\",\n headers: { \"Content-Type\": \"application/json\", ...(token && { Authorization: `Bearer ${token}` }) },\n body: JSON.stringify({ jsonrpc: \"2.0\", id: nextId++, method, params })\n });\n const body: unknown = await response.json().catch(() => undefined);\n if (!isRecord(body)) throw new Error(`The server answered ${response.status} without a result.`);\n if (isRecord(body.error)) throw new Error(String(body.error.message ?? \"The server refused the request.\"));\n if (!response.ok) throw new Error(`The server answered ${response.status}.`);\n return body.result;\n };\n return {\n request,\n async callTool(name, args) {\n const result = await request(\"tools/call\", { name, arguments: args });\n return isRecord(result) ? result : {};\n }\n };\n}\n\n/** The first text a tool answered: its refusal, when it refused. */\nexport function toolText(result: AdminToolResult): string | undefined {\n return result.content?.find(block => block.type === \"text\" && typeof block.text === \"string\")?.text;\n}\n\nexport function isRecord(value: unknown): value is Record<string, unknown> {\n return typeof value === \"object\" && value !== null && !Array.isArray(value);\n}\n"],"mappings":";AAoBA,SAAgB,sBAAsB,SAAiB,cAA0E;CAC7H,IAAI,SAAS;CACb,MAAM,UAAU,OAAO,QAAgB,WAAsD;EACzF,MAAM,QAAQ,MAAM,eAAe;EACnC,MAAM,WAAW,MAAM,MAAM,GAAG,QAAQ,kBAAkB;GACtD,QAAQ;GACR,SAAS;IAAE,gBAAgB;IAAoB,GAAI,SAAS,EAAE,eAAe,UAAU,QAAQ;GAAG;GAClG,MAAM,KAAK,UAAU;IAAE,SAAS;IAAO,IAAI;IAAU;IAAQ;GAAO,CAAC;EACzE,CAAC;EACD,MAAM,OAAgB,MAAM,SAAS,KAAK,CAAC,CAAC,YAAY,KAAA,CAAS;EACjE,IAAI,CAAC,SAAS,IAAI,GAAG,MAAM,IAAI,MAAM,uBAAuB,SAAS,OAAO,mBAAmB;EAC/F,IAAI,SAAS,KAAK,KAAK,GAAG,MAAM,IAAI,MAAM,OAAO,KAAK,MAAM,WAAW,iCAAiC,CAAC;EACzG,IAAI,CAAC,SAAS,IAAI,MAAM,IAAI,MAAM,uBAAuB,SAAS,OAAO,EAAE;EAC3E,OAAO,KAAK;CAChB;CACA,OAAO;EACH;EACA,MAAM,SAAS,MAAM,MAAM;GACvB,MAAM,SAAS,MAAM,QAAQ,cAAc;IAAE;IAAM,WAAW;GAAK,CAAC;GACpE,OAAO,SAAS,MAAM,IAAI,SAAS,CAAC;EACxC;CACJ;AACJ;;AAGA,SAAgB,SAAS,QAA6C;CAClE,OAAO,OAAO,SAAS,MAAK,UAAS,MAAM,SAAS,UAAU,OAAO,MAAM,SAAS,QAAQ,CAAC,EAAE;AACnG;AAEA,SAAgB,SAAS,OAAkD;CACvE,OAAO,OAAO,UAAU,YAAY,UAAU,QAAQ,CAAC,MAAM,QAAQ,KAAK;AAC9E"}
@@ -0,0 +1,20 @@
1
+ /**
2
+ * EXPERIMENTAL. A saved app in the admin panel, run as Claude runs it: the
3
+ * MCP App view in a frame, with this page as its host.
4
+ *
5
+ * The frame is sandboxed without `allow-same-origin`, so it has an opaque
6
+ * origin: no cookies, no storage of the admin panel's, no reach into this
7
+ * page. Its policy allows no network at all. Every read and write the app
8
+ * makes is a message to this page, which relays it to the admin panel's MCP
9
+ * endpoint as the person signed in, where it runs under their RLS — so stored
10
+ * code someone else wrote can do nothing the viewer could not, and cannot
11
+ * send their session anywhere.
12
+ */
13
+ import React from "react";
14
+ import { type AdminAppsClient } from "./admin_apps_client.js";
15
+ /** The view document with the frame's policy at the top of its head. */
16
+ export declare function sandboxedViewDocument(html: string): string;
17
+ export declare function SavedAppFrame({ client, appId }: {
18
+ client: AdminAppsClient;
19
+ appId: string;
20
+ }): React.JSX.Element;