@rebasepro/cms 0.25.0 → 0.26.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 (125) hide show
  1. package/dist/collection_editor/liveSchemaClient.d.ts +3 -3
  2. package/dist/collection_editor/liveSchemaClient.js.map +1 -1
  3. package/dist/collection_editor/ui/collection_editor/AICollectionGeneratorPopover.js +1 -1
  4. package/dist/collection_editor/ui/collection_editor/AICollectionGeneratorPopover.js.map +1 -1
  5. package/dist/collection_editor/ui/collection_editor/SchemaChangeDialog.d.ts +7 -1
  6. package/dist/collection_editor/ui/collection_editor/SchemaChangeDialog.js +61 -50
  7. package/dist/collection_editor/ui/collection_editor/SchemaChangeDialog.js.map +1 -1
  8. package/dist/collection_editor/ui/collection_editor/properties/DateTimePropertyField.js +22 -22
  9. package/dist/collection_editor/ui/collection_editor/properties/DateTimePropertyField.js.map +1 -1
  10. package/dist/collection_editor/ui/collection_editor/properties/NumberPropertyField.js +14 -14
  11. package/dist/collection_editor/ui/collection_editor/properties/NumberPropertyField.js.map +1 -1
  12. package/dist/collection_editor/ui/collection_editor/properties/StringPropertyField.js +24 -24
  13. package/dist/collection_editor/ui/collection_editor/properties/StringPropertyField.js.map +1 -1
  14. package/dist/collection_editor/useLiveSchemaEditing.js +4 -1
  15. package/dist/collection_editor/useLiveSchemaEditing.js.map +1 -1
  16. package/dist/components/CollectionTableBinding/fields/TableReferenceField.js +1 -1
  17. package/dist/components/CollectionTableBinding/fields/TableReferenceField.js.map +1 -1
  18. package/dist/components/CollectionTableBinding/internal/CollectionTableToolbar.d.ts +1 -2
  19. package/dist/components/CollectionTableBinding/internal/CollectionTableToolbar.js.map +1 -1
  20. package/dist/components/CollectionTableBinding/internal/EntityTableCell.d.ts +1 -2
  21. package/dist/components/CollectionTableBinding/internal/EntityTableCell.js.map +1 -1
  22. package/dist/components/CollectionViewBinding/CollectionViewActions.js +1 -1
  23. package/dist/components/CollectionViewBinding/CollectionViewActions.js.map +1 -1
  24. package/dist/components/CollectionViewBinding/CollectionViewBinding.js +2 -28
  25. package/dist/components/CollectionViewBinding/CollectionViewBinding.js.map +1 -1
  26. package/dist/components/CollectionViewBinding/DefaultCollectionEmptyState.d.ts +12 -0
  27. package/dist/components/CollectionViewBinding/DefaultCollectionEmptyState.js +33 -0
  28. package/dist/components/CollectionViewBinding/DefaultCollectionEmptyState.js.map +1 -0
  29. package/dist/components/CollectionsScopeContext.d.ts +5 -1
  30. package/dist/components/CollectionsScopeContext.js +10 -2
  31. package/dist/components/CollectionsScopeContext.js.map +1 -1
  32. package/dist/components/DefaultAppBar.js +2 -1
  33. package/dist/components/DefaultAppBar.js.map +1 -1
  34. package/dist/components/DefaultDrawer.js +16 -4
  35. package/dist/components/DefaultDrawer.js.map +1 -1
  36. package/dist/components/DefaultMissingReference.d.ts +8 -0
  37. package/dist/components/DefaultMissingReference.js +13 -0
  38. package/dist/components/DefaultMissingReference.js.map +1 -0
  39. package/dist/components/DeleteEntityDialog.js +9 -9
  40. package/dist/components/DeleteEntityDialog.js.map +1 -1
  41. package/dist/components/EntityFormPanel.d.ts +7 -2
  42. package/dist/components/EntityFormPanel.js +72 -29
  43. package/dist/components/EntityFormPanel.js.map +1 -1
  44. package/dist/components/HomePage/ContentHomePage.js +4 -3
  45. package/dist/components/HomePage/ContentHomePage.js.map +1 -1
  46. package/dist/components/HomePage/HomePageDnD.js +3 -1
  47. package/dist/components/HomePage/HomePageDnD.js.map +1 -1
  48. package/dist/components/HomePage/SmallNavigationCard.js +25 -0
  49. package/dist/components/HomePage/SmallNavigationCard.js.map +1 -0
  50. package/dist/components/RebaseAuthGate.js +3 -2
  51. package/dist/components/RebaseAuthGate.js.map +1 -1
  52. package/dist/components/RebaseLayout.d.ts +4 -1
  53. package/dist/components/RebaseLayout.js +7 -1
  54. package/dist/components/RebaseLayout.js.map +1 -1
  55. package/dist/components/RebaseShell.d.ts +4 -1
  56. package/dist/components/RebaseShell.js.map +1 -1
  57. package/dist/components/ReferenceTable/SelectionTableBinding.js +4 -3
  58. package/dist/components/ReferenceTable/SelectionTableBinding.js.map +1 -1
  59. package/dist/components/RelationSelector.js +2 -2
  60. package/dist/components/RelationSelector.js.map +1 -1
  61. package/dist/components/SideDialogs.js +10 -4
  62. package/dist/components/SideDialogs.js.map +1 -1
  63. package/dist/components/app/Scaffold.js +5 -1
  64. package/dist/components/app/Scaffold.js.map +1 -1
  65. package/dist/components/field_configs.js +1 -1
  66. package/dist/components/history/EntityHistoryView.js +6 -4
  67. package/dist/components/history/EntityHistoryView.js.map +1 -1
  68. package/dist/components/history/LastEditedByIndicator.d.ts +2 -1
  69. package/dist/data_export/export/export.d.ts +2 -13
  70. package/dist/data_export/export/export.js +1 -36
  71. package/dist/data_export/export/export.js.map +1 -1
  72. package/dist/form/EntityForm.d.ts +1 -1
  73. package/dist/form/EntityForm.js +17 -13
  74. package/dist/form/EntityForm.js.map +1 -1
  75. package/dist/form/EntityFormBinding.d.ts +1 -1
  76. package/dist/form/EntityFormBinding.js +42 -4
  77. package/dist/form/EntityFormBinding.js.map +1 -1
  78. package/dist/form/PropertyFieldBinding.js +1 -1
  79. package/dist/form/components/FieldBlock.d.ts +8 -1
  80. package/dist/form/components/FieldBlock.js +16 -2
  81. package/dist/form/components/FieldBlock.js.map +1 -1
  82. package/dist/form/components/FormSections.js +1 -1
  83. package/dist/form/components/FormSections.js.map +1 -1
  84. package/dist/form/components/LabelWithIcon.js +5 -2
  85. package/dist/form/components/LabelWithIcon.js.map +1 -1
  86. package/dist/form/field_bindings/DateTimeFieldBinding.js +2 -1
  87. package/dist/form/field_bindings/DateTimeFieldBinding.js.map +1 -1
  88. package/dist/form/field_bindings/ReadOnlyFieldBinding.js +28 -1
  89. package/dist/form/field_bindings/ReadOnlyFieldBinding.js.map +1 -1
  90. package/dist/form/field_bindings/RelationFieldBinding.js +7 -3
  91. package/dist/form/field_bindings/RelationFieldBinding.js.map +1 -1
  92. package/dist/form/field_bindings/SelectFieldBinding.js +63 -42
  93. package/dist/form/field_bindings/SelectFieldBinding.js.map +1 -1
  94. package/dist/form/field_bindings/SwitchFieldBinding.js +2 -1
  95. package/dist/form/field_bindings/SwitchFieldBinding.js.map +1 -1
  96. package/dist/form/field_bindings/TextFieldBinding.js +8 -6
  97. package/dist/form/field_bindings/TextFieldBinding.js.map +1 -1
  98. package/dist/form/form_utils.d.ts +18 -1
  99. package/dist/form/form_utils.js +38 -2
  100. package/dist/form/form_utils.js.map +1 -1
  101. package/dist/form/index.d.ts +1 -1
  102. package/dist/form/label_placement.d.ts +23 -0
  103. package/dist/form/label_placement.js +71 -0
  104. package/dist/form/label_placement.js.map +1 -0
  105. package/dist/form/resolve_form_properties.d.ts +35 -3
  106. package/dist/form/resolve_form_properties.js +67 -6
  107. package/dist/form/resolve_form_properties.js.map +1 -1
  108. package/dist/hooks/useHistory.d.ts +5 -0
  109. package/dist/hooks/useHistory.js +22 -6
  110. package/dist/hooks/useHistory.js.map +1 -1
  111. package/dist/index.d.ts +50 -0
  112. package/dist/index.js +34 -7
  113. package/dist/preview/components/ReferencePreview.js +1 -1
  114. package/dist/preview/components/ReferencePreview.js.map +1 -1
  115. package/dist/preview/components/RelationPreview.js +1 -1
  116. package/dist/preview/components/RelationPreview.js.map +1 -1
  117. package/dist/types/components/EntityFormProps.d.ts +11 -0
  118. package/package.json +11 -10
  119. package/recipes/README.md +131 -0
  120. package/recipes/bulk-set-status.tsx +62 -0
  121. package/recipes/calendar-view.tsx +123 -0
  122. package/recipes/custom-login.tsx +60 -0
  123. package/recipes/my-preferences.tsx +68 -0
  124. package/recipes/orders-dashboard.tsx +125 -0
  125. package/recipes/site-settings.tsx +63 -0
@@ -17,7 +17,7 @@
17
17
  * JSON, which had lost every handler, shared property and imported value.
18
18
  * A new collection is still sent whole.
19
19
  */
20
- import type { CollectionPatch } from "@rebasepro/types";
20
+ import type { CollectionPatch, SchemaChangeVerdict } from "@rebasepro/types";
21
21
  /** A constraint the change asks for that the statements will not carry. */
22
22
  export interface WithheldConstraint {
23
23
  target: string;
@@ -28,10 +28,10 @@ export interface WithheldConstraint {
28
28
  /** What the server says a change would do. Mirrors `SchemaChangePlan`. */
29
29
  export interface LiveSchemaPlan {
30
30
  applicable: boolean;
31
- verdict: "safe" | "diverges" | "needs-migration";
31
+ verdict: SchemaChangeVerdict;
32
32
  changes: Array<{
33
33
  kind: string;
34
- verdict: "safe" | "diverges" | "needs-migration";
34
+ verdict: SchemaChangeVerdict;
35
35
  collection: string;
36
36
  property?: string;
37
37
  detail: string;
@@ -1 +1 @@
1
- {"version":3,"file":"liveSchemaClient.js","names":[],"sources":["../../src/collection_editor/liveSchemaClient.ts"],"sourcesContent":["/**\n * The panel's client for live schema editing.\n *\n * Three calls, mirroring the routes: ask whether this backend can do it, ask\n * what a change would do, then do it. `plan` and `apply` are deliberately\n * separate here as well as on the server, because a UI that could only\n * try-and-see would be asking somebody to discover that their change is refused\n * by pressing a button on a live database.\n *\n * ## A change to an existing collection is a patch\n *\n * What the person changed — the difference between the collection the editor\n * loaded and the one it is saving, from `diffCollections` in\n * `@rebasepro/types` — not the collection. The server applies it to the\n * collection as it is to plan the change, and writes only those keys into the\n * file. Posting the whole collection had the server write back the panel's\n * JSON, which had lost every handler, shared property and imported value.\n * A new collection is still sent whole.\n */\n\nimport type { CollectionPatch } from \"@rebasepro/types\";\n\n/** A constraint the change asks for that the statements will not carry. */\nexport interface WithheldConstraint {\n target: string;\n kind: \"not-null\";\n reason: string;\n remedy: string;\n}\n\n/** What the server says a change would do. Mirrors `SchemaChangePlan`. */\nexport interface LiveSchemaPlan {\n applicable: boolean;\n verdict: \"safe\" | \"diverges\" | \"needs-migration\";\n changes: Array<{\n kind: string;\n verdict: \"safe\" | \"diverges\" | \"needs-migration\";\n collection: string;\n property?: string;\n detail: string;\n remedy?: string;\n /**\n * What \"Edit source only\" leaves behind for this change. Absent on a\n * change that may not be written to the source alone.\n */\n sourceOnly?: string;\n kept?: string;\n }>;\n statements: string[];\n files: string[];\n message: string;\n /**\n * Applicable, and still not fully enforced.\n *\n * Not a refusal, so it does not belong in `changes` — but it is the one\n * thing on a plan somebody might want to stop and read, so the dialog gives\n * it its own place rather than another bullet in the list.\n */\n withheldConstraints: WithheldConstraint[];\n /**\n * What still has to happen after this lands.\n *\n * Empty almost always. The case it exists for: a project that replays\n * versioned migrations, where applying here changes *this* database and\n * commits the collection, but writes no migration — so the next\n * environment built from migrations would not have the change.\n */\n followUp?: string[];\n}\n\nexport interface LiveSchemaResult {\n applied: boolean;\n /** Committed as \"Edit source only\": nothing was meant to run. */\n sourceOnly?: boolean;\n applyError?: string;\n /**\n * How many statements ran before the one that failed. The statements run\n * one at a time with no transaction around them, so a failure part-way\n * leaves the earlier ones applied. `undefined` when the server could not\n * say.\n */\n appliedStatements?: number;\n committed: { sha: string; branch: string; files: string[] };\n statements: string[];\n summary: string;\n withheldConstraints: WithheldConstraint[];\n followUp?: string[];\n}\n\n/**\n * Whether this backend can edit its schema, and what is missing when it cannot.\n *\n * `canPlan` is separate from `enabled` deliberately: previewing a change needs\n * no repository, so a deployment running from a bundle can still show somebody\n * exactly what their change would do. Greying out the preview as well would be\n * a worse answer than the truth.\n */\nexport interface LiveSchemaStatus {\n enabled: boolean;\n canPlan: boolean;\n /**\n * Whether *this caller* may apply, as opposed to whether the server can.\n *\n * Applying commits to the repository under an author, and a credential is\n * not an author — so an API key or the service key may preview a change and\n * not make one. Reported here so the panel can grey out the button and say\n * why, rather than letting somebody read a plan, decide, press, and only\n * then be refused.\n */\n canApply: boolean;\n applyRefusedBecause?: string;\n applyRefusedCode?: string;\n repository?: string;\n /** The branch a commit would land on. */\n branch?: string;\n code?: string;\n reason?: string;\n}\n\n/**\n * Why live editing is not available here.\n *\n * Distinguished from an ordinary failure because both are expected states with\n * their own explanation, and a UI should say which rather than showing a\n * stack: a Mongo backend will never support this, and a bundle deployment has\n * no source to edit.\n */\nexport type LiveSchemaUnavailable =\n | { reason: \"unsupported\"; message: string }\n | { reason: \"no-repository\"; message: string };\n\nexport class LiveSchemaError extends Error {\n constructor(\n message: string,\n readonly code: string | undefined,\n readonly changes?: LiveSchemaPlan[\"changes\"]\n ) {\n super(message);\n this.name = \"LiveSchemaError\";\n }\n}\n\nconst UNAVAILABLE: Record<string, LiveSchemaUnavailable[\"reason\"]> = {\n SCHEMA_EDITING_UNSUPPORTED: \"unsupported\",\n SCHEMA_EDITING_NO_REPOSITORY: \"no-repository\"\n};\n\nexport interface LiveSchemaClientOptions {\n /** Base for the routes, e.g. `https://api.example.com/api/schema`. */\n baseUrl: string;\n getAuthToken?: () => Promise<string | null> | string | null;\n fetchImpl?: typeof fetch;\n}\n\nexport interface ProposedCollectionChange {\n collectionId: string;\n /** A new collection, whole. */\n collection?: Record<string, unknown>;\n /** What changed about an existing one. See the module comment. */\n patch?: CollectionPatch;\n /** Delete the collection's source — its file and its `index.ts` entry. The table stays. */\n remove?: true;\n}\n\nexport function createLiveSchemaClient(options: LiveSchemaClientOptions) {\n const doFetch = options.fetchImpl ?? fetch;\n const base = options.baseUrl.replace(/\\/$/, \"\");\n\n const post = async <T>(path: string, body: ProposedCollectionChange & { sourceOnly?: boolean }): Promise<T> => {\n const token = await options.getAuthToken?.();\n const headers: Record<string, string> = { \"Content-Type\": \"application/json\" };\n if (token) headers.Authorization = `Bearer ${token}`;\n\n const response = await doFetch(`${base}${path}`, {\n method: \"POST\",\n headers,\n body: JSON.stringify(body)\n });\n\n if (response.ok) return await response.json() as T;\n\n // Parsed rather than assumed: the server answers a structured error, and\n // the code is what tells an expected refusal from a broken request.\n let payload: { error?: { code?: string; message?: string; details?: { changes?: LiveSchemaPlan[\"changes\"] } } } = {};\n try {\n payload = await response.json() as typeof payload;\n } catch {\n payload = { error: { message: await response.text().catch(() => \"\") } };\n }\n\n throw new LiveSchemaError(\n payload.error?.message || `Schema request failed with ${response.status}`,\n payload.error?.code,\n payload.error?.details?.changes\n );\n };\n\n return {\n /**\n * Whether this backend can edit its schema.\n *\n * Never throws. Every way of failing to get an answer — a backend too\n * old to have the endpoint, an unreachable one, a session that is not\n * an admin — means the same thing to a caller deciding whether to offer\n * the control, and turning that into an exception each caller has to\n * catch would only produce four copies of this `catch`.\n */\n status: async (): Promise<LiveSchemaStatus> => {\n try {\n const token = await options.getAuthToken?.();\n const response = await doFetch(`${base}/status`, {\n headers: token ? { Authorization: `Bearer ${token}` } : {}\n });\n const body = await response.json().catch(() => ({})) as\n Partial<LiveSchemaStatus> & { error?: { code?: string; message?: string } };\n\n if (response.ok) {\n return {\n enabled: body.enabled === true,\n canPlan: body.canPlan === true,\n // Absent on a backend from before capabilities existed.\n // Read as \"yes\" there, because on that server being\n // through the admin gate *was* the whole permission —\n // defaulting to no would take the feature away from\n // every deployment that has not upgraded.\n canApply: body.canApply ?? body.enabled === true,\n applyRefusedBecause: body.applyRefusedBecause,\n applyRefusedCode: body.applyRefusedCode,\n repository: body.repository,\n branch: body.branch,\n code: body.code,\n reason: body.reason\n };\n }\n return {\n enabled: false,\n canPlan: false,\n canApply: false,\n code: body.error?.code,\n reason: body.error?.message\n ?? `The backend refused to say whether its schema is editable (HTTP ${response.status}).`\n };\n } catch (err) {\n return {\n enabled: false,\n canPlan: false,\n canApply: false,\n reason: err instanceof Error ? err.message : \"The backend could not be reached.\"\n };\n }\n },\n\n /** What the change would do. No side effects. */\n plan: (change: ProposedCollectionChange) => post<LiveSchemaPlan>(\"/plan\", change),\n\n /**\n * Commit the change, then apply it — or, with `sourceOnly`, commit it\n * and run nothing (\"Edit source only\").\n */\n apply: (change: ProposedCollectionChange & { sourceOnly?: boolean }) => post<LiveSchemaResult>(\"/apply\", change)\n };\n}\n\n/** The client's shape, for the hook and the tests that fake it. */\nexport type LiveSchemaClient = ReturnType<typeof createLiveSchemaClient>;\n\n/**\n * Whether an error means live editing is unavailable here, rather than that the\n * change was wrong.\n *\n * Returns the reason so a caller can say which, and `undefined` for anything\n * else — a refused change is not an unavailable feature, and conflating them\n * would hide the refusal that the user needs to read.\n */\nexport function asUnavailable(err: unknown): LiveSchemaUnavailable | undefined {\n if (!(err instanceof LiveSchemaError) || !err.code) return undefined;\n const reason = UNAVAILABLE[err.code];\n return reason ? { reason, message: err.message } : undefined;\n}\n\n/** The person closed the dialog without applying. Not an error; an answer. */\nexport class SchemaChangeCancelled extends Error {\n constructor() {\n super(\"The schema change was not applied.\");\n this.name = \"SchemaChangeCancelled\";\n }\n}\n\n/**\n * Was this rejection the person saying no?\n *\n * A save has to *reject* when it is cancelled — resolving would leave the form\n * believing it saved. But a caller that treats every rejection as a failure\n * then reports the user's own choice back to them as an error, which is what\n * the collection editor did: a console error and a red snackbar reading \"Error\n * persisting collection: The schema change was not applied.\"\n *\n * Matched by name rather than `instanceof`, which is unreliable the moment two\n * copies of this module end up in one bundle — the class is then a different\n * identity and every check silently answers false.\n */\nexport function isSchemaChangeCancelled(err: unknown): boolean {\n return err instanceof Error && err.name === \"SchemaChangeCancelled\";\n}\n"],"mappings":";AAmIA,IAAa,kBAAb,cAAqC,MAAM;CAG1B;CACA;CAHb,YACI,SACA,MACA,SACF;EACE,MAAM,OAAO;EAHJ,KAAA,OAAA;EACA,KAAA,UAAA;EAGT,KAAK,OAAO;CAChB;AACJ;AAEA,IAAM,cAA+D;CACjE,4BAA4B;CAC5B,8BAA8B;AAClC;AAmBA,SAAgB,uBAAuB,SAAkC;CACrE,MAAM,UAAU,QAAQ,aAAa;CACrC,MAAM,OAAO,QAAQ,QAAQ,QAAQ,OAAO,EAAE;CAE9C,MAAM,OAAO,OAAU,MAAc,SAA0E;EAC3G,MAAM,QAAQ,MAAM,QAAQ,eAAe;EAC3C,MAAM,UAAkC,EAAE,gBAAgB,mBAAmB;EAC7E,IAAI,OAAO,QAAQ,gBAAgB,UAAU;EAE7C,MAAM,WAAW,MAAM,QAAQ,GAAG,OAAO,QAAQ;GAC7C,QAAQ;GACR;GACA,MAAM,KAAK,UAAU,IAAI;EAC7B,CAAC;EAED,IAAI,SAAS,IAAI,OAAO,MAAM,SAAS,KAAK;EAI5C,IAAI,U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AA;CAC3D,MAAM,SAAS,YAAY,IAAI;CAC/B,OAAO,SAAS;EAAE;EAAQ,SAAS,IAAI;CAAQ,IAAI,KAAA;AACvD;;AAGA,IAAa,wBAAb,cAA2C,MAAM;CAC7C,cAAc;EACV,MAAM,oCAAoC;EAC1C,KAAK,OAAO;CAChB;AACJ;;;;;;;;;;;;;;AAeA,SAAgB,wBAAwB,KAAuB;CAC3D,OAAO,eAAe,SAAS,IAAI,SAAS;AAChD"}
1
+ {"version":3,"file":"liveSchemaClient.js","names":[],"sources":["../../src/collection_editor/liveSchemaClient.ts"],"sourcesContent":["/**\n * The panel's client for live schema editing.\n *\n * Three calls, mirroring the routes: ask whether this backend can do it, ask\n * what a change would do, then do it. `plan` and `apply` are deliberately\n * separate here as well as on the server, because a UI that could only\n * try-and-see would be asking somebody to discover that their change is refused\n * by pressing a button on a live database.\n *\n * ## A change to an existing collection is a patch\n *\n * What the person changed — the difference between the collection the editor\n * loaded and the one it is saving, from `diffCollections` in\n * `@rebasepro/types` — not the collection. The server applies it to the\n * collection as it is to plan the change, and writes only those keys into the\n * file. Posting the whole collection had the server write back the panel's\n * JSON, which had lost every handler, shared property and imported value.\n * A new collection is still sent whole.\n */\n\nimport type { CollectionPatch, SchemaChangeVerdict } from \"@rebasepro/types\";\n\n/** A constraint the change asks for that the statements will not carry. */\nexport interface WithheldConstraint {\n target: string;\n kind: \"not-null\";\n reason: string;\n remedy: string;\n}\n\n/** What the server says a change would do. Mirrors `SchemaChangePlan`. */\nexport interface LiveSchemaPlan {\n applicable: boolean;\n verdict: SchemaChangeVerdict;\n changes: Array<{\n kind: string;\n verdict: SchemaChangeVerdict;\n collection: string;\n property?: string;\n detail: string;\n remedy?: string;\n /**\n * What \"Edit source only\" leaves behind for this change. Absent on a\n * change that may not be written to the source alone.\n */\n sourceOnly?: string;\n kept?: string;\n }>;\n statements: string[];\n files: string[];\n message: string;\n /**\n * Applicable, and still not fully enforced.\n *\n * Not a refusal, so it does not belong in `changes` — but it is the one\n * thing on a plan somebody might want to stop and read, so the dialog gives\n * it its own place rather than another bullet in the list.\n */\n withheldConstraints: WithheldConstraint[];\n /**\n * What still has to happen after this lands.\n *\n * Empty almost always. The case it exists for: a project that replays\n * versioned migrations, where applying here changes *this* database and\n * commits the collection, but writes no migration — so the next\n * environment built from migrations would not have the change.\n */\n followUp?: string[];\n}\n\nexport interface LiveSchemaResult {\n applied: boolean;\n /** Committed as \"Edit source only\": nothing was meant to run. */\n sourceOnly?: boolean;\n applyError?: string;\n /**\n * How many statements ran before the one that failed. The statements run\n * one at a time with no transaction around them, so a failure part-way\n * leaves the earlier ones applied. `undefined` when the server could not\n * say.\n */\n appliedStatements?: number;\n committed: { sha: string; branch: string; files: string[] };\n statements: string[];\n summary: string;\n withheldConstraints: WithheldConstraint[];\n followUp?: string[];\n}\n\n/**\n * Whether this backend can edit its schema, and what is missing when it cannot.\n *\n * `canPlan` is separate from `enabled` deliberately: previewing a change needs\n * no repository, so a deployment running from a bundle can still show somebody\n * exactly what their change would do. Greying out the preview as well would be\n * a worse answer than the truth.\n */\nexport interface LiveSchemaStatus {\n enabled: boolean;\n canPlan: boolean;\n /**\n * Whether *this caller* may apply, as opposed to whether the server can.\n *\n * Applying commits to the repository under an author, and a credential is\n * not an author — so an API key or the service key may preview a change and\n * not make one. Reported here so the panel can grey out the button and say\n * why, rather than letting somebody read a plan, decide, press, and only\n * then be refused.\n */\n canApply: boolean;\n applyRefusedBecause?: string;\n applyRefusedCode?: string;\n repository?: string;\n /** The branch a commit would land on. */\n branch?: string;\n code?: string;\n reason?: string;\n}\n\n/**\n * Why live editing is not available here.\n *\n * Distinguished from an ordinary failure because both are expected states with\n * their own explanation, and a UI should say which rather than showing a\n * stack: a Mongo backend will never support this, and a bundle deployment has\n * no source to edit.\n */\nexport type LiveSchemaUnavailable =\n | { reason: \"unsupported\"; message: string }\n | { reason: \"no-repository\"; message: string };\n\nexport class LiveSchemaError extends Error {\n constructor(\n message: string,\n readonly code: string | undefined,\n readonly changes?: LiveSchemaPlan[\"changes\"]\n ) {\n super(message);\n this.name = \"LiveSchemaError\";\n }\n}\n\nconst UNAVAILABLE: Record<string, LiveSchemaUnavailable[\"reason\"]> = {\n SCHEMA_EDITING_UNSUPPORTED: \"unsupported\",\n SCHEMA_EDITING_NO_REPOSITORY: \"no-repository\"\n};\n\nexport interface LiveSchemaClientOptions {\n /** Base for the routes, e.g. `https://api.example.com/api/schema`. */\n baseUrl: string;\n getAuthToken?: () => Promise<string | null> | string | null;\n fetchImpl?: typeof fetch;\n}\n\nexport interface ProposedCollectionChange {\n collectionId: string;\n /** A new collection, whole. */\n collection?: Record<string, unknown>;\n /** What changed about an existing one. See the module comment. */\n patch?: CollectionPatch;\n /** Delete the collection's source — its file and its `index.ts` entry. The table stays. */\n remove?: true;\n}\n\nexport function createLiveSchemaClient(options: LiveSchemaClientOptions) {\n const doFetch = options.fetchImpl ?? fetch;\n const base = options.baseUrl.replace(/\\/$/, \"\");\n\n const post = async <T>(path: string, body: ProposedCollectionChange & { sourceOnly?: boolean }): Promise<T> => {\n const token = await options.getAuthToken?.();\n const headers: Record<string, string> = { \"Content-Type\": \"application/json\" };\n if (token) headers.Authorization = `Bearer ${token}`;\n\n const response = await doFetch(`${base}${path}`, {\n method: \"POST\",\n headers,\n body: JSON.stringify(body)\n });\n\n if (response.ok) return await response.json() as T;\n\n // Parsed rather than assumed: the server answers a structured error, and\n // the code is what tells an expected refusal from a broken request.\n let payload: { error?: { code?: string; message?: string; details?: { changes?: LiveSchemaPlan[\"changes\"] } } } = {};\n try {\n payload = await response.json() as typeof payload;\n } catch {\n payload = { error: { message: await response.text().catch(() => \"\") } };\n }\n\n throw new LiveSchemaError(\n payload.error?.message || `Schema request failed with ${response.status}`,\n payload.error?.code,\n payload.error?.details?.changes\n );\n };\n\n return {\n /**\n * Whether this backend can edit its schema.\n *\n * Never throws. Every way of failing to get an answer — a backend too\n * old to have the endpoint, an unreachable one, a session that is not\n * an admin — means the same thing to a caller deciding whether to offer\n * the control, and turning that into an exception each caller has to\n * catch would only produce four copies of this `catch`.\n */\n status: async (): Promise<LiveSchemaStatus> => {\n try {\n const token = await options.getAuthToken?.();\n const response = await doFetch(`${base}/status`, {\n headers: token ? { Authorization: `Bearer ${token}` } : {}\n });\n const body = await response.json().catch(() => ({})) as\n Partial<LiveSchemaStatus> & { error?: { code?: string; message?: string } };\n\n if (response.ok) {\n return {\n enabled: body.enabled === true,\n canPlan: body.canPlan === true,\n // Absent on a backend from before capabilities existed.\n // Read as \"yes\" there, because on that server being\n // through the admin gate *was* the whole permission —\n // defaulting to no would take the feature away from\n // every deployment that has not upgraded.\n canApply: body.canApply ?? body.enabled === true,\n applyRefusedBecause: body.applyRefusedBecause,\n applyRefusedCode: body.applyRefusedCode,\n repository: body.repository,\n branch: body.branch,\n code: body.code,\n reason: body.reason\n };\n }\n return {\n enabled: false,\n canPlan: false,\n canApply: false,\n code: body.error?.code,\n reason: body.error?.message\n ?? `The backend refused to say whether its schema is editable (HTTP ${response.status}).`\n };\n } catch (err) {\n return {\n enabled: false,\n canPlan: false,\n canApply: false,\n reason: err instanceof Error ? err.message : \"The backend could not be reached.\"\n };\n }\n },\n\n /** What the change would do. No side effects. */\n plan: (change: ProposedCollectionChange) => post<LiveSchemaPlan>(\"/plan\", change),\n\n /**\n * Commit the change, then apply it — or, with `sourceOnly`, commit it\n * and run nothing (\"Edit source only\").\n */\n apply: (change: ProposedCollectionChange & { sourceOnly?: boolean }) => post<LiveSchemaResult>(\"/apply\", change)\n };\n}\n\n/** The client's shape, for the hook and the tests that fake it. */\nexport type LiveSchemaClient = ReturnType<typeof createLiveSchemaClient>;\n\n/**\n * Whether an error means live editing is unavailable here, rather than that the\n * change was wrong.\n *\n * Returns the reason so a caller can say which, and `undefined` for anything\n * else — a refused change is not an unavailable feature, and conflating them\n * would hide the refusal that the user needs to read.\n */\nexport function asUnavailable(err: unknown): LiveSchemaUnavailable | undefined {\n if (!(err instanceof LiveSchemaError) || !err.code) return undefined;\n const reason = UNAVAILABLE[err.code];\n return reason ? { reason, message: err.message } : undefined;\n}\n\n/** The person closed the dialog without applying. Not an error; an answer. */\nexport class SchemaChangeCancelled extends Error {\n constructor() {\n super(\"The schema change was not applied.\");\n this.name = \"SchemaChangeCancelled\";\n }\n}\n\n/**\n * Was this rejection the person saying no?\n *\n * A save has to *reject* when it is cancelled — resolving would leave the form\n * believing it saved. But a caller that treats every rejection as a failure\n * then reports the user's own choice back to them as an error, which is what\n * the collection editor did: a console error and a red snackbar reading \"Error\n * persisting collection: The schema change was not applied.\"\n *\n * Matched by name rather than `instanceof`, which is unreliable the moment two\n * copies of this module end up in one bundle — the class is then a different\n * identity and every check silently answers false.\n */\nexport function isSchemaChangeCancelled(err: unknown): boolean {\n return err instanceof Error && err.name === \"SchemaChangeCancelled\";\n}\n"],"mappings":";AAmIA,IAAa,kBAAb,cAAqC,MAAM;CAG1B;CACA;CAHb,YACI,SACA,MACA,SACF;EACE,MAAM,OAAO;EAHJ,KAAA,OAAA;EACA,KAAA,UAAA;EAGT,KAAK,OAAO;CAChB;AACJ;AAEA,IAAM,cAA+D;CACjE,4BAA4B;CAC5B,8BAA8B;AAClC;AAmBA,SAAgB,uBAAuB,SAAkC;CACrE,MAAM,UAAU,QAAQ,aAAa;CACrC,MAAM,OAAO,QAAQ,QAAQ,QAAQ,OAAO,EAAE;CAE9C,MAAM,OAAO,OAAU,MAAc,SAA0E;EAC3G,MAAM,QAAQ,MAAM,QAAQ,eAAe;EAC3C,MAAM,UAAkC,EAAE,gBAAgB,mBAAmB;EAC7E,IAAI,OAAO,QAAQ,gBAAgB,UAAU;EAE7C,MAAM,WAAW,MAAM,QAAQ,GAAG,OAAO,QAAQ;GAC7C,QAAQ;GACR;GACA,MAAM,KAAK,UAAU,IAAI;EAC7B,CAAC;EAED,IAAI,SAAS,IAAI,OAAO,MAAM,SAAS,KAAK;EAI5C,IAAI,UAA8G,CAAC;EACnH,IAAI;GACA,UAAU,MAAM,SAAS,KAAK;EAClC,QA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AAQ,SAAS,IAAI;CAAQ,IAAI,KAAA;AACvD;;AAGA,IAAa,wBAAb,cAA2C,MAAM;CAC7C,cAAc;EACV,MAAM,oCAAoC;EAC1C,KAAK,OAAO;CAChB;AACJ;;;;;;;;;;;;;;AAeA,SAAgB,wBAAwB,KAAuB;CAC3D,OAAO,eAAe,SAAS,IAAI,SAAS;AAChD"}
@@ -102,7 +102,7 @@ function AICollectionGeneratorPopover({ existingCollection, onGenerated, generat
102
102
  },
103
103
  trigger: trigger ?? defaultTrigger,
104
104
  children: /* @__PURE__ */ jsxs("div", {
105
- className: "p-4 flex flex-col gap-3 min-w-[360px] max-w-[480px]",
105
+ className: "p-4 flex flex-col gap-3 w-[calc(100vw-2rem)] sm:w-auto sm:min-w-[360px] max-w-[480px]",
106
106
  children: [
107
107
  /* @__PURE__ */ jsxs("div", {
108
108
  className: "flex items-center gap-2",
@@ -1 +1 @@
1
- {"version":3,"file":"AICollectionGeneratorPopover.js","names":[],"sources":["../../../../src/collection_editor/ui/collection_editor/AICollectionGeneratorPopover.tsx"],"sourcesContent":["\nimport { AIIcon, useTranslation } from \"@rebasepro/app\";\nimport { useCollectionRegistryController } from \"../../_cms_internals\";\nimport React, { useState } from \"react\";\nimport { useSafeSnackbarController } from \"../../useSafeSnackbarController\";\n\nimport {\n Button,\n CircularProgress,\n IconButton,\n Menu,\n SendIcon,\n TextField,\n Tooltip,\n Typography\n} from \"@rebasepro/ui\";\nimport {\n CollectionGenerationCallback,\n CollectionGenerationApiError,\n CollectionOperation\n} from \"../../api/generateCollectionApi\";\nimport { useCollectionsConfigController } from \"../../useCollectionsConfigController\";\nimport type { AdminCollection } from \"@rebasepro/cms-types\";\n\nexport interface AICollectionGeneratorPopoverProps {\n /**\n * Current collection being edited (if modifying an existing collection)\n */\n existingCollection?: AdminCollection<any>;\n\n /**\n * Callback when a collection is generated or modified.\n * Includes the collection and optionally the operations that were applied.\n */\n onGenerated: (collection: AdminCollection, operations?: CollectionOperation[]) => void;\n\n /**\n * Callback function for generating/modifying collections.\n * The plugin is API-agnostic - the consumer provides the implementation.\n */\n generateCollection: CollectionGenerationCallback;\n\n /**\n * Optional custom trigger button. If not provided, a default AI button is used.\n */\n trigger?: React.ReactNode | any;\n\n /**\n * Size of the button\n */\n size?: \"small\" | \"medium\" | \"large\";\n\n /**\n * Whether to show the label text\n */\n showLabel?: boolean;\n\n /**\n * Optional analytics callback\n */\n onAnalyticsEvent?: (event: string, params?: object) => void;\n}\n\nexport function AICollectionGeneratorPopover({\n existingCollection,\n onGenerated,\n generateCollection,\n trigger,\n size = \"small\",\n showLabel = true,\n onAnalyticsEvent\n}: AICollectionGeneratorPopoverProps) {\n const { t } = useTranslation();\n const [menuOpen, setMenuOpen] = useState(false);\n const [prompt, setPrompt] = useState(\"\");\n const [loading, setLoading] = useState(false);\n const [error, setError] = useState<string | null>(null);\n\n const collectionRegistry = useCollectionRegistryController();\n const configController = useCollectionsConfigController();\n const snackbarController = useSafeSnackbarController();\n\n const existingCollections = collectionRegistry.collections ?? [];\n\n const handleGenerate = async () => {\n if (!prompt.trim()) return;\n\n setLoading(true);\n setError(null);\n\n const mode = existingCollection ? \"modify\" : \"create\";\n onAnalyticsEvent?.(\"ai_collection_generate_start\", { mode });\n\n try {\n const collectionsContext = existingCollections.map(c => ({\n slug: c.slug,\n name: c.name,\n properties: c.properties,\n propertiesOrder: c.propertiesOrder\n } as Partial<AdminCollection>));\n\n const result = await generateCollection({\n prompt: prompt.trim(),\n existingCollections: collectionsContext.slice(0, 30),\n ...(existingCollection && {\n existingCollection: {\n slug: existingCollection.slug,\n name: existingCollection.name,\n properties: existingCollection.properties,\n propertiesOrder: existingCollection.propertiesOrder\n } as Partial<AdminCollection>\n })\n });\n\n onGenerated(result.collection, result.operations);\n setMenuOpen(false);\n setPrompt(\"\");\n onAnalyticsEvent?.(\"ai_collection_generate_success\", {\n mode,\n operationsCount: result.operations?.length\n });\n snackbarController?.open({\n type: \"success\",\n message: existingCollection\n ? \"Collection updated with AI suggestions\"\n : \"Collection generated successfully\"\n });\n } catch (e) {\n console.error(\"Error generating collection:\", e);\n const errorMessage = e instanceof CollectionGenerationApiError\n ? e.message\n : \"Failed to generate collection. Please try again.\";\n setError(errorMessage);\n onAnalyticsEvent?.(\"ai_collection_generate_error\", {\n mode,\n error: errorMessage\n });\n snackbarController?.open({\n type: \"error\",\n message: errorMessage\n });\n } finally {\n setLoading(false);\n }\n };\n\n const handleKeyDown = (e: React.KeyboardEvent) => {\n if (e.key === \"Enter\" && !e.shiftKey) {\n e.preventDefault();\n handleGenerate();\n }\n };\n\n const tooltipTitle = configController?.readOnly\n ? (configController.readOnlyReason || \"Collection generation is disabled\")\n : undefined;\n\n const defaultTrigger = showLabel ? (\n <Tooltip title={tooltipTitle} asChild={true}>\n <Button\n variant=\"text\"\n size={size}\n disabled={loading || configController?.readOnly}\n startIcon={loading\n ? <CircularProgress size=\"smallest\"/>\n : <AIIcon size=\"small\"/>\n }\n >\n AI Assist\n </Button>\n </Tooltip>\n ) : (\n <Tooltip title={tooltipTitle} asChild={true}>\n <IconButton\n size={size}\n disabled={loading || configController?.readOnly}\n aria-label=\"AI Assist\"\n >\n {loading\n ? <CircularProgress size=\"smallest\"/>\n : <AIIcon size=\"small\"/>\n }\n </IconButton>\n </Tooltip>\n );\n\n return (\n <Menu\n open={menuOpen}\n onOpenChange={(open) => {\n setMenuOpen(open);\n if (!open) {\n setError(null);\n }\n }}\n trigger={trigger ?? defaultTrigger}\n >\n <div className=\"p-4 flex flex-col gap-3 min-w-[360px] max-w-[480px]\">\n <div className=\"flex items-center gap-2\">\n <AIIcon size=\"small\"/>\n <Typography variant=\"subtitle2\">\n {existingCollection ? \"Modify Collection with AI\" : \"Generate Collection with AI\"}\n </Typography>\n </div>\n\n <Typography variant=\"caption\" color=\"secondary\">\n {existingCollection\n ? t(\"describe_changes_to_make\")\n : t(\"describe_collection_to_create\")\n }\n </Typography>\n\n <TextField\n size=\"small\"\n multiline\n autoFocus\n aria-label={existingCollection\n ? t(\"describe_changes_to_make\")\n : t(\"describe_collection_to_create\")\n }\n className=\"w-full text-text-primary dark:text-text-primary-dark\"\n value={prompt}\n onChange={(e) => setPrompt(e.target.value)}\n onKeyDown={handleKeyDown}\n placeholder={existingCollection\n ? \"e.g., Add a thumbnail image field with storage, make price required...\"\n : \"e.g., Create a products collection with name, price, description, and category...\"\n }\n disabled={loading}\n />\n\n {error && (\n <Typography variant=\"caption\" className=\"text-red-500\">\n {error}\n </Typography>\n )}\n\n <div className=\"flex justify-end gap-2\">\n <Button\n variant=\"text\"\n size=\"small\"\n onClick={() => setMenuOpen(false)}\n disabled={loading}\n >\n Cancel\n </Button>\n <Button\n variant=\"filled\"\n size=\"small\"\n onClick={handleGenerate}\n disabled={!prompt.trim() || loading}\n startIcon={loading ? <CircularProgress size=\"smallest\"/> : undefined}\n >\n {loading ? \"Generating...\" : \"Generate\"}\n </Button>\n </div>\n </div>\n </Menu>\n );\n}\n"],"mappings":";;;;;;;;;AA+DA,SAAgB,6BAA6B,EACzC,oBACA,aACA,oBACA,SACA,OAAO,SACP,YAAY,MACZ,oBACkC;CAClC,MAAM,EAAE,MAAM,eAAe;CAC7B,MAAM,CAAC,UAAU,eAAe,SAAS,KAAK;CAC9C,MAAM,CAAC,QAAQ,aAAa,SAAS,EAAE;CACvC,MAAM,CAAC,SAAS,cAAc,SAAS,KAAK;CAC5C,MAAM,CAAC,OAAO,YAAY,SAAwB,IAAI;CAEtD,MAAM,qBAAqB,gCAAgC;CAC3D,MAAM,mBAAmB,+BAA+B;CACxD,MAAM,qBAAqB,0BAA0B;CAErD,MAAM,sBAAsB,mBAAmB,eAAe,CAAC;CAE/D,MAAM,iBAAiB,YAAY;EAC/B,IAAI,CAAC,OAAO,KAAK,GAAG;EAEpB,WAAW,IAAI;EACf,SAAS,IAAI;EAEb,MAAM,OAAO,qBAAqB,WAAW;EAC7C,mBAAmB,gCAAgC,EAAE,KAAK,CAAC;EAE3D,IAAI;GACA,MAAM,qBAAqB,oBAA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A,IAAI,KAAA;gBAE1D,UAAU,kBAAkB;KACzB,CAAA,CACP;;GACJ;;CACH,CAAA;AAEd"}
1
+ {"version":3,"file":"AICollectionGeneratorPopover.js","names":[],"sources":["../../../../src/collection_editor/ui/collection_editor/AICollectionGeneratorPopover.tsx"],"sourcesContent":["\nimport { AIIcon, useTranslation } from \"@rebasepro/app\";\nimport { useCollectionRegistryController } from \"../../_cms_internals\";\nimport React, { useState } from \"react\";\nimport { useSafeSnackbarController } from \"../../useSafeSnackbarController\";\n\nimport {\n Button,\n CircularProgress,\n IconButton,\n Menu,\n SendIcon,\n TextField,\n Tooltip,\n Typography\n} from \"@rebasepro/ui\";\nimport {\n CollectionGenerationCallback,\n CollectionGenerationApiError,\n CollectionOperation\n} from \"../../api/generateCollectionApi\";\nimport { useCollectionsConfigController } from \"../../useCollectionsConfigController\";\nimport type { AdminCollection } from \"@rebasepro/cms-types\";\n\nexport interface AICollectionGeneratorPopoverProps {\n /**\n * Current collection being edited (if modifying an existing collection)\n */\n existingCollection?: AdminCollection<any>;\n\n /**\n * Callback when a collection is generated or modified.\n * Includes the collection and optionally the operations that were applied.\n */\n onGenerated: (collection: AdminCollection, operations?: CollectionOperation[]) => void;\n\n /**\n * Callback function for generating/modifying collections.\n * The plugin is API-agnostic - the consumer provides the implementation.\n */\n generateCollection: CollectionGenerationCallback;\n\n /**\n * Optional custom trigger button. If not provided, a default AI button is used.\n */\n trigger?: React.ReactNode | any;\n\n /**\n * Size of the button\n */\n size?: \"small\" | \"medium\" | \"large\";\n\n /**\n * Whether to show the label text\n */\n showLabel?: boolean;\n\n /**\n * Optional analytics callback\n */\n onAnalyticsEvent?: (event: string, params?: object) => void;\n}\n\nexport function AICollectionGeneratorPopover({\n existingCollection,\n onGenerated,\n generateCollection,\n trigger,\n size = \"small\",\n showLabel = true,\n onAnalyticsEvent\n}: AICollectionGeneratorPopoverProps) {\n const { t } = useTranslation();\n const [menuOpen, setMenuOpen] = useState(false);\n const [prompt, setPrompt] = useState(\"\");\n const [loading, setLoading] = useState(false);\n const [error, setError] = useState<string | null>(null);\n\n const collectionRegistry = useCollectionRegistryController();\n const configController = useCollectionsConfigController();\n const snackbarController = useSafeSnackbarController();\n\n const existingCollections = collectionRegistry.collections ?? [];\n\n const handleGenerate = async () => {\n if (!prompt.trim()) return;\n\n setLoading(true);\n setError(null);\n\n const mode = existingCollection ? \"modify\" : \"create\";\n onAnalyticsEvent?.(\"ai_collection_generate_start\", { mode });\n\n try {\n const collectionsContext = existingCollections.map(c => ({\n slug: c.slug,\n name: c.name,\n properties: c.properties,\n propertiesOrder: c.propertiesOrder\n } as Partial<AdminCollection>));\n\n const result = await generateCollection({\n prompt: prompt.trim(),\n existingCollections: collectionsContext.slice(0, 30),\n ...(existingCollection && {\n existingCollection: {\n slug: existingCollection.slug,\n name: existingCollection.name,\n properties: existingCollection.properties,\n propertiesOrder: existingCollection.propertiesOrder\n } as Partial<AdminCollection>\n })\n });\n\n onGenerated(result.collection, result.operations);\n setMenuOpen(false);\n setPrompt(\"\");\n onAnalyticsEvent?.(\"ai_collection_generate_success\", {\n mode,\n operationsCount: result.operations?.length\n });\n snackbarController?.open({\n type: \"success\",\n message: existingCollection\n ? \"Collection updated with AI suggestions\"\n : \"Collection generated successfully\"\n });\n } catch (e) {\n console.error(\"Error generating collection:\", e);\n const errorMessage = e instanceof CollectionGenerationApiError\n ? e.message\n : \"Failed to generate collection. Please try again.\";\n setError(errorMessage);\n onAnalyticsEvent?.(\"ai_collection_generate_error\", {\n mode,\n error: errorMessage\n });\n snackbarController?.open({\n type: \"error\",\n message: errorMessage\n });\n } finally {\n setLoading(false);\n }\n };\n\n const handleKeyDown = (e: React.KeyboardEvent) => {\n if (e.key === \"Enter\" && !e.shiftKey) {\n e.preventDefault();\n handleGenerate();\n }\n };\n\n const tooltipTitle = configController?.readOnly\n ? (configController.readOnlyReason || \"Collection generation is disabled\")\n : undefined;\n\n const defaultTrigger = showLabel ? (\n <Tooltip title={tooltipTitle} asChild={true}>\n <Button\n variant=\"text\"\n size={size}\n disabled={loading || configController?.readOnly}\n startIcon={loading\n ? <CircularProgress size=\"smallest\"/>\n : <AIIcon size=\"small\"/>\n }\n >\n AI Assist\n </Button>\n </Tooltip>\n ) : (\n <Tooltip title={tooltipTitle} asChild={true}>\n <IconButton\n size={size}\n disabled={loading || configController?.readOnly}\n aria-label=\"AI Assist\"\n >\n {loading\n ? <CircularProgress size=\"smallest\"/>\n : <AIIcon size=\"small\"/>\n }\n </IconButton>\n </Tooltip>\n );\n\n return (\n <Menu\n open={menuOpen}\n onOpenChange={(open) => {\n setMenuOpen(open);\n if (!open) {\n setError(null);\n }\n }}\n trigger={trigger ?? defaultTrigger}\n >\n {/* A phone's width less its margins below `sm`, as the panel is\n positioned inside the viewport but never shrunk to it. */}\n <div className=\"p-4 flex flex-col gap-3 w-[calc(100vw-2rem)] sm:w-auto sm:min-w-[360px] max-w-[480px]\">\n <div className=\"flex items-center gap-2\">\n <AIIcon size=\"small\"/>\n <Typography variant=\"subtitle2\">\n {existingCollection ? \"Modify Collection with AI\" : \"Generate Collection with AI\"}\n </Typography>\n </div>\n\n <Typography variant=\"caption\" color=\"secondary\">\n {existingCollection\n ? t(\"describe_changes_to_make\")\n : t(\"describe_collection_to_create\")\n }\n </Typography>\n\n <TextField\n size=\"small\"\n multiline\n autoFocus\n aria-label={existingCollection\n ? t(\"describe_changes_to_make\")\n : t(\"describe_collection_to_create\")\n }\n className=\"w-full text-text-primary dark:text-text-primary-dark\"\n value={prompt}\n onChange={(e) => setPrompt(e.target.value)}\n onKeyDown={handleKeyDown}\n placeholder={existingCollection\n ? \"e.g., Add a thumbnail image field with storage, make price required...\"\n : \"e.g., Create a products collection with name, price, description, and category...\"\n }\n disabled={loading}\n />\n\n {error && (\n <Typography variant=\"caption\" className=\"text-red-500\">\n {error}\n </Typography>\n )}\n\n <div className=\"flex justify-end gap-2\">\n <Button\n variant=\"text\"\n size=\"small\"\n onClick={() => setMenuOpen(false)}\n disabled={loading}\n >\n Cancel\n </Button>\n <Button\n variant=\"filled\"\n size=\"small\"\n onClick={handleGenerate}\n disabled={!prompt.trim() || loading}\n startIcon={loading ? <CircularProgress size=\"smallest\"/> : undefined}\n >\n {loading ? \"Generating...\" : \"Generate\"}\n </Button>\n </div>\n </div>\n </Menu>\n );\n}\n"],"mappings":";;;;;;;;;AA+DA,SAAgB,6BAA6B,EACzC,oBACA,aACA,oBACA,SACA,OAAO,SACP,YAAY,MACZ,oBACkC;CAClC,MAAM,EAAE,MAAM,eAAe;CAC7B,MAAM,CAAC,UAAU,eAAe,SAAS,KAAK;CAC9C,MAAM,CAAC,QAAQ,aAAa,SAAS,EAAE;CACvC,MAAM,CAAC,SAAS,cAAc,SAAS,KAAK;CAC5C,MAAM,CAAC,OAAO,YAAY,SAAwB,IAAI;CAEtD,MAAM,qBAAqB,gCAAgC;CAC3D,MAAM,mBAAmB,+BAA+B;CACxD,MAAM,qBAAqB,0BAA0B;CAErD,MAAM,sBAAsB,mBAAmB,eAAe,CAAC;CAE/D,MAAM,iBAAiB,YAAY;EAC/B,IAAI,CAAC,OAAO,KAAK,GAAG;EAEpB,WAAW,IAAI;EACf,SAAS,IAAI;EAEb,MAAM,OAAO,qBAAqB,WAAW;EAC7C,mBAAmB,gCAAgC,EAAE,KAAK,CAAC;EAE3D,IAAI;GACA,MAAM,qBAAqB,oBAAoB,KAAI,OAAM;IACrD,MAAM,EAAE;IACR,MAAM,EAAE;IACR,YAAY,EAAE;IACd,iBAAiB,EAAE;GACvB,EAA8B;GAE9B,MAAM,SAAS,MAAM,mBAAmB;IACpC,QAAQ,OAAO,KAAK;IACpB,qBAAqB,mBAAmB,MAAM,GAAG,EAAE;IACnD,GAAI,sBAAsB,EACtB,oBAAoB;KAChB,MAAM,mBAAmB;KACzB,MAAM,mBAAmB;KACzB,YAAY,mBAAmB;KAC/B,iBAAiB,mBAAmB;IACxC,EACJ;GACJ,CAAC;GAED,YAAY,OAAO,YAAY,OAAO,UAAU;GAChD,YAAY,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U;aAAf;IACI,qBAAC,OAAD;KAAK,WAAU;eAAf,CACI,oBAAC,QAAD,EAAQ,MAAK,QAAQ,CAAA,GACrB,oBAAC,YAAD;MAAY,SAAQ;gBACf,qBAAqB,8BAA8B;KAC5C,CAAA,CACX;;IAEL,oBAAC,YAAD;KAAY,SAAQ;KAAU,OAAM;eAC/B,qBACK,EAAE,0BAA0B,IAC5B,EAAE,+BAA+B;IAE/B,CAAA;IAEZ,oBAAC,WAAD;KACI,MAAK;KACL,WAAA;KACA,WAAA;KACA,cAAY,qBACN,EAAE,0BAA0B,IAC5B,EAAE,+BAA+B;KAEvC,WAAU;KACV,OAAO;KACP,WAAW,MAAM,UAAU,EAAE,OAAO,KAAK;KACzC,WAAW;KACX,aAAa,qBACP,2EACA;KAEN,UAAU;IACb,CAAA;IAEA,SACG,oBAAC,YAAD;KAAY,SAAQ;KAAU,WAAU;eACnC;IACO,CAAA;IAGhB,qBAAC,OAAD;KAAK,WAAU;eAAf,CACI,oBAAC,QAAD;MACI,SAAQ;MACR,MAAK;MACL,eAAe,YAAY,KAAK;MAChC,UAAU;gBACb;KAEO,CAAA,GACR,oBAAC,QAAD;MACI,SAAQ;MACR,MAAK;MACL,SAAS;MACT,UAAU,CAAC,OAAO,KAAK,KAAK;MAC5B,WAAW,UAAU,oBAAC,kBAAD,EAAkB,MAAK,WAAW,CAAA,IAAI,KAAA;gBAE1D,UAAU,kBAAkB;KACzB,CAAA,CACP;;GACJ;;CACH,CAAA;AAEd"}
@@ -70,6 +70,12 @@ export interface SchemaChangeDialogProps {
70
70
  * they have decided.
71
71
  */
72
72
  applyRefusedBecause?: string;
73
+ /**
74
+ * The change can only be committed as source — the deployment applies
75
+ * nothing to its database — so {@link onSourceOnly} is the main action,
76
+ * labelled "Commit", and not refused by {@link applyRefusedBecause}.
77
+ */
78
+ sourceOnlyIsTheCommit?: boolean;
73
79
  /**
74
80
  * Where a confirmation would land — `owner/repo` and a branch.
75
81
  *
@@ -82,4 +88,4 @@ export interface SchemaChangeDialogProps {
82
88
  branch?: string;
83
89
  };
84
90
  }
85
- export declare function SchemaChangeDialog({ open, collectionId, plan, planError, result, applying, applyError, onConfirm, onRetry, onSourceOnly, onClose, applyRefusedBecause, target }: SchemaChangeDialogProps): React.JSX.Element;
91
+ export declare function SchemaChangeDialog({ open, collectionId, plan, planError, result, applying, applyError, onConfirm, onRetry, onSourceOnly, onClose, applyRefusedBecause, sourceOnlyIsTheCommit, target }: SchemaChangeDialogProps): React.JSX.Element;
@@ -1,8 +1,8 @@
1
1
  import "react";
2
2
  import { Fragment, jsx, jsxs } from "react/jsx-runtime";
3
3
  import { Alert, Button, Chip, CircularProgress, Dialog, DialogActions, DialogContent, DialogTitle, ExpandablePanel, Typography, cls } from "@rebasepro/ui";
4
+ import { useTranslation } from "@rebasepro/app";
4
5
  //#region src/collection_editor/ui/collection_editor/SchemaChangeDialog.tsx
5
- /** What the verdict means, in the words the reader needs rather than the enum's. */
6
6
  /**
7
7
  * What the verdict means, in the words the reader needs rather than the enum's.
8
8
  *
@@ -14,32 +14,32 @@ import { Alert, Button, Chip, CircularProgress, Dialog, DialogActions, DialogCon
14
14
  */
15
15
  var VERDICT_COPY = {
16
16
  safe: {
17
- title: "Ready to apply",
18
- body: "Every change here can be made against the running database.",
17
+ titleKey: "schema_change_verdict_safe_title",
18
+ bodyKey: "schema_change_verdict_safe_body",
19
19
  color: "info"
20
20
  },
21
21
  diverges: {
22
- title: "This would leave the database out of step",
23
- body: "The change can be written, but the database will not end up matching it. The details below say which part, and what would make it applicable.",
22
+ titleKey: "schema_change_verdict_diverges_title",
23
+ bodyKey: "schema_change_verdict_diverges_body",
24
24
  color: "warning"
25
25
  },
26
26
  "needs-migration": {
27
- title: "This needs a migration",
28
- body: "Some of this cannot be done to a running database at all — it drops or rewrites something, and that belongs in a migration somebody has read.",
27
+ titleKey: "schema_change_verdict_migration_title",
28
+ bodyKey: "schema_change_verdict_migration_body",
29
29
  color: "error"
30
30
  }
31
31
  };
32
32
  var VERDICT_CHIP = {
33
33
  safe: {
34
- label: "safe",
34
+ labelKey: "schema_change_chip_safe",
35
35
  scheme: "greenLighter"
36
36
  },
37
37
  diverges: {
38
- label: "diverges",
38
+ labelKey: "schema_change_chip_diverges",
39
39
  scheme: "orangeLighter"
40
40
  },
41
41
  "needs-migration": {
42
- label: "needs migration",
42
+ labelKey: "schema_change_chip_migration",
43
43
  scheme: "redLighter"
44
44
  }
45
45
  };
@@ -73,13 +73,14 @@ function Details({ summary, count, children }) {
73
73
  * to be done or a later environment will differ from this one.
74
74
  */
75
75
  function FollowUp({ items }) {
76
+ const { t } = useTranslation();
76
77
  if (items.length === 0) return null;
77
78
  return /* @__PURE__ */ jsxs(Alert, {
78
79
  color: "info",
79
80
  children: [/* @__PURE__ */ jsx(Typography, {
80
81
  variant: "body2",
81
82
  className: "font-medium mb-1",
82
- children: items.length === 1 ? "One thing to do afterwards" : "To do afterwards"
83
+ children: items.length === 1 ? t("schema_change_follow_up_one") : t("schema_change_follow_up")
83
84
  }), /* @__PURE__ */ jsx("ul", {
84
85
  className: "space-y-2",
85
86
  children: items.map((item) => /* @__PURE__ */ jsx("li", {
@@ -102,13 +103,14 @@ function repositoryLabel(repository) {
102
103
  return repository.split("/").filter(Boolean).pop() ?? repository;
103
104
  }
104
105
  function WithheldConstraints({ constraints }) {
106
+ const { t } = useTranslation();
105
107
  if (constraints.length === 0) return null;
106
108
  return /* @__PURE__ */ jsxs(Alert, {
107
109
  color: "warning",
108
110
  children: [/* @__PURE__ */ jsx(Typography, {
109
111
  variant: "body2",
110
112
  className: "font-medium mb-1",
111
- children: constraints.length === 1 ? "One constraint will not be enforced" : `${constraints.length} constraints will not be enforced`
113
+ children: constraints.length === 1 ? t("schema_change_withheld_one") : t("schema_change_withheld_many", { count: constraints.length })
112
114
  }), /* @__PURE__ */ jsx("ul", {
113
115
  className: "space-y-2",
114
116
  children: constraints.map((constraint) => /* @__PURE__ */ jsxs("li", {
@@ -142,14 +144,18 @@ function WithheldConstraints({ constraints }) {
142
144
  * The statements run one at a time with no transaction around them, so only
143
145
  * "none ran" means the database is as it was.
144
146
  */
145
- function partialApplyHeading(result) {
147
+ function partialApplyHeading(result, t) {
146
148
  const ran = result.appliedStatements;
147
- if (ran === 0) return "The database was not changed";
148
- if (ran === void 0) return "The database may have been changed in part";
149
- return `${ran} of ${result.statements.length} statements ran, then one failed`;
149
+ if (ran === 0) return t("schema_change_db_not_changed");
150
+ if (ran === void 0) return t("schema_change_db_maybe_changed");
151
+ return t("schema_change_statements_partial", {
152
+ ran,
153
+ total: result.statements.length
154
+ });
150
155
  }
151
156
  /** The receipt. Shown in place of the plan once the change has been applied. */
152
157
  function Applied({ result }) {
158
+ const { t } = useTranslation();
153
159
  return /* @__PURE__ */ jsxs("div", {
154
160
  className: "flex flex-col gap-4",
155
161
  children: [
@@ -166,24 +172,16 @@ function Applied({ result }) {
166
172
  /* @__PURE__ */ jsx(Typography, {
167
173
  variant: "body2",
168
174
  className: "font-medium mb-1",
169
- children: partialApplyHeading(result)
175
+ children: partialApplyHeading(result, t)
170
176
  }),
171
177
  /* @__PURE__ */ jsx(Typography, {
172
178
  variant: "body2",
173
179
  children: result.applyError
174
180
  }),
175
- /* @__PURE__ */ jsxs(Typography, {
181
+ /* @__PURE__ */ jsx(Typography, {
176
182
  variant: "body2",
177
183
  className: "mt-2",
178
- children: [
179
- "The commit is on ",
180
- /* @__PURE__ */ jsx(Typography, {
181
- component: "code",
182
- variant: "mono",
183
- children: result.committed.branch
184
- }),
185
- " either way, so whatever did not run will be applied on the next boot."
186
- ]
184
+ children: t("schema_change_commit_holds", { branch: result.committed.branch })
187
185
  })
188
186
  ]
189
187
  }),
@@ -192,13 +190,14 @@ function Applied({ result }) {
192
190
  /* @__PURE__ */ jsxs("div", { children: [/* @__PURE__ */ jsx(Typography, {
193
191
  variant: "label",
194
192
  color: "secondary",
195
- children: "Committed"
193
+ children: t("schema_change_committed")
196
194
  }), /* @__PURE__ */ jsxs("div", {
197
195
  className: cls(codeBlock, "mt-1"),
198
196
  children: [
199
- result.committed.sha.slice(0, 9),
200
- " on ",
201
- result.committed.branch,
197
+ t("schema_change_committed_on", {
198
+ sha: result.committed.sha.slice(0, 9),
199
+ branch: result.committed.branch
200
+ }),
202
201
  "\n",
203
202
  result.committed.files.map((file) => ` ${file}`).join("\n")
204
203
  ]
@@ -206,15 +205,20 @@ function Applied({ result }) {
206
205
  ]
207
206
  });
208
207
  }
209
- function SchemaChangeDialog({ open, collectionId, plan, planError, result, applying, applyError, onConfirm, onRetry, onSourceOnly, onClose, applyRefusedBecause, target }) {
208
+ function SchemaChangeDialog({ open, collectionId, plan, planError, result, applying, applyError, onConfirm, onRetry, onSourceOnly, onClose, applyRefusedBecause, sourceOnlyIsTheCommit, target }) {
209
+ const { t } = useTranslation();
210
210
  const verdict = plan?.verdict;
211
211
  const statements = plan?.statements.length ?? 0;
212
212
  const commitOnly = Boolean(plan?.applicable) && statements === 0;
213
213
  const copy = verdict === "safe" && commitOnly ? {
214
- title: "Ready to commit",
215
- body: plan && plan.changes.length > 0 ? "Nothing runs against the database now. Each change below says what it does and when it takes effect." : "This changes what your project declares. Nothing runs against the database — there is no schema change to make.",
214
+ title: t("schema_change_commit_only_title"),
215
+ body: plan && plan.changes.length > 0 ? t("schema_change_commit_only_body") : t("schema_change_commit_only_body_no_changes"),
216
216
  color: "info"
217
- } : verdict ? VERDICT_COPY[verdict] : void 0;
217
+ } : verdict ? {
218
+ title: t(VERDICT_COPY[verdict].titleKey),
219
+ body: t(VERDICT_COPY[verdict].bodyKey),
220
+ color: VERDICT_COPY[verdict].color
221
+ } : void 0;
218
222
  return /* @__PURE__ */ jsxs(Dialog, {
219
223
  open,
220
224
  onOpenChange: (value) => {
@@ -224,7 +228,7 @@ function SchemaChangeDialog({ open, collectionId, plan, planError, result, apply
224
228
  children: [
225
229
  /* @__PURE__ */ jsxs(DialogTitle, {
226
230
  className: "flex items-center gap-2",
227
- children: [result ? result.sourceOnly ? "Schema change committed" : "Schema change applied" : "Review schema change", /* @__PURE__ */ jsx(Typography, {
231
+ children: [result ? result.sourceOnly ? t("schema_change_title_committed") : t("schema_change_title_applied") : t("schema_change_title_review"), /* @__PURE__ */ jsx(Typography, {
228
232
  component: "code",
229
233
  variant: "mono",
230
234
  color: "secondary",
@@ -239,7 +243,7 @@ function SchemaChangeDialog({ open, collectionId, plan, planError, result, apply
239
243
  children: [/* @__PURE__ */ jsx(Typography, {
240
244
  variant: "body2",
241
245
  className: "font-medium mb-1",
242
- children: "The change could not be planned"
246
+ children: t("schema_change_plan_failed")
243
247
  }), /* @__PURE__ */ jsx(Typography, {
244
248
  variant: "body2",
245
249
  children: planError
@@ -250,7 +254,7 @@ function SchemaChangeDialog({ open, collectionId, plan, planError, result, apply
250
254
  children: [/* @__PURE__ */ jsx(CircularProgress, { size: "small" }), /* @__PURE__ */ jsx(Typography, {
251
255
  variant: "body2",
252
256
  color: "secondary",
253
- children: "Working out what this change would do…"
257
+ children: t("schema_change_planning")
254
258
  })]
255
259
  }),
256
260
  result && /* @__PURE__ */ jsx(Applied, { result }),
@@ -276,14 +280,14 @@ function SchemaChangeDialog({ open, collectionId, plan, planError, result, apply
276
280
  plan.changes.length === 0 && /* @__PURE__ */ jsx(Typography, {
277
281
  variant: "body2",
278
282
  color: "secondary",
279
- children: "Nothing here changes the shape of your data. Only the collection source changes, and it is committed."
283
+ children: t("schema_change_source_only_changes")
280
284
  }),
281
285
  !plan.applicable && onSourceOnly && /* @__PURE__ */ jsxs(Alert, {
282
286
  color: "warning",
283
287
  children: [/* @__PURE__ */ jsx(Typography, {
284
288
  variant: "body2",
285
289
  className: "font-medium mb-1",
286
- children: "Edit source only: commit the collection, leave the database"
290
+ children: t("schema_change_source_only_title")
287
291
  }), /* @__PURE__ */ jsx("ul", {
288
292
  className: "space-y-1",
289
293
  children: plan.changes.filter((change) => change.verdict !== "safe" && change.sourceOnly).map((change, index) => /* @__PURE__ */ jsx("li", {
@@ -300,7 +304,7 @@ function SchemaChangeDialog({ open, collectionId, plan, planError, result, apply
300
304
  size: "smallest",
301
305
  colorScheme: VERDICT_CHIP[change.verdict].scheme,
302
306
  className: "shrink-0 mt-0.5",
303
- children: VERDICT_CHIP[change.verdict].label
307
+ children: t(VERDICT_CHIP[change.verdict].labelKey)
304
308
  }), /* @__PURE__ */ jsxs("div", {
305
309
  className: "min-w-0",
306
310
  children: [/* @__PURE__ */ jsx(Typography, {
@@ -322,14 +326,14 @@ function SchemaChangeDialog({ open, collectionId, plan, planError, result, apply
322
326
  children: [/* @__PURE__ */ jsx(Typography, {
323
327
  variant: "body2",
324
328
  className: "font-medium mb-1",
325
- children: "You can preview this change, but not apply it"
329
+ children: t("schema_change_preview_only")
326
330
  }), /* @__PURE__ */ jsx(Typography, {
327
331
  variant: "body2",
328
332
  children: applyRefusedBecause
329
333
  })]
330
334
  }),
331
335
  /* @__PURE__ */ jsx(Details, {
332
- summary: "Statements that will run",
336
+ summary: t("schema_change_statements"),
333
337
  count: plan.statements.length,
334
338
  children: /* @__PURE__ */ jsx("div", {
335
339
  className: codeBlock,
@@ -337,7 +341,7 @@ function SchemaChangeDialog({ open, collectionId, plan, planError, result, apply
337
341
  })
338
342
  }),
339
343
  /* @__PURE__ */ jsx(Details, {
340
- summary: "Files that will be committed",
344
+ summary: t("schema_change_files"),
341
345
  count: plan.files.length,
342
346
  children: /* @__PURE__ */ jsx("div", {
343
347
  className: codeBlock,
@@ -345,7 +349,7 @@ function SchemaChangeDialog({ open, collectionId, plan, planError, result, apply
345
349
  })
346
350
  }),
347
351
  /* @__PURE__ */ jsx(Details, {
348
- summary: "Commit message",
352
+ summary: t("schema_change_message"),
349
353
  count: plan.message ? 1 : 0,
350
354
  children: /* @__PURE__ */ jsx("div", {
351
355
  className: codeBlock,
@@ -370,25 +374,32 @@ function SchemaChangeDialog({ open, collectionId, plan, planError, result, apply
370
374
  variant: "text",
371
375
  onClick: onClose,
372
376
  disabled: applying,
373
- children: result ? "Close" : "Cancel"
377
+ children: result ? t("close") : t("cancel")
374
378
  }),
375
379
  !result && planError && onRetry && /* @__PURE__ */ jsx(Button, {
376
380
  variant: "outlined",
377
381
  onClick: onRetry,
378
- children: "Try again"
382
+ children: t("retry")
379
383
  }),
380
384
  !result && plan && !plan.applicable && onSourceOnly && /* @__PURE__ */ jsx(Button, {
381
385
  variant: "outlined",
382
386
  onClick: onSourceOnly,
383
387
  disabled: applying,
384
- children: "Edit source only"
388
+ children: t("schema_change_edit_source_only")
389
+ }),
390
+ !result && sourceOnlyIsTheCommit && onSourceOnly && /* @__PURE__ */ jsx(Button, {
391
+ variant: "filled",
392
+ color: "primary",
393
+ onClick: onSourceOnly,
394
+ disabled: applying,
395
+ children: applying ? t("schema_change_committing") : t("schema_change_commit")
385
396
  }),
386
- !result && /* @__PURE__ */ jsx(Button, {
397
+ !result && !(sourceOnlyIsTheCommit && onSourceOnly) && /* @__PURE__ */ jsx(Button, {
387
398
  variant: "filled",
388
399
  color: "primary",
389
400
  onClick: onConfirm,
390
401
  disabled: !plan?.applicable || applying || Boolean(applyRefusedBecause),
391
- children: applying ? commitOnly ? "Committing…" : "Applying…" : commitOnly ? "Commit" : "Commit and apply"
402
+ children: applying ? commitOnly ? t("schema_change_committing") : t("schema_change_applying") : commitOnly ? t("schema_change_commit") : t("schema_change_commit_and_apply")
392
403
  })
393
404
  ] })
394
405
  ]