@protobase/cli 0.22.13 → 0.23.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 (49) hide show
  1. package/dist/main.js +2 -0
  2. package/dist/package.js +1 -1
  3. package/dist/skill/install.js +29 -0
  4. package/dist/skill/register.js +14 -0
  5. package/package.json +8 -7
  6. package/skills/protobase/SKILL.md +89 -0
  7. package/skills/protobase/references/getting-started.md +78 -0
  8. package/skills/protobase/references/guides/api-functions.md +240 -0
  9. package/skills/protobase/references/guides/billing-page.md +288 -0
  10. package/skills/protobase/references/guides/create-page.md +108 -0
  11. package/skills/protobase/references/guides/deploy.md +52 -0
  12. package/skills/protobase/references/guides/export-a-list.md +44 -0
  13. package/skills/protobase/references/guides/field-type.md +131 -0
  14. package/skills/protobase/references/guides/first-composed-page.md +230 -0
  15. package/skills/protobase/references/guides/first-plugin.md +166 -0
  16. package/skills/protobase/references/guides/import-records.md +43 -0
  17. package/skills/protobase/references/guides/plugin-build.md +64 -0
  18. package/skills/protobase/references/guides/record-card.md +70 -0
  19. package/skills/protobase/references/guides/remote-resources.md +185 -0
  20. package/skills/protobase/references/guides/table-to-admin.md +205 -0
  21. package/skills/protobase/references/guides/theme-an-app.md +87 -0
  22. package/skills/protobase/references/reference/access.md +115 -0
  23. package/skills/protobase/references/reference/ai.md +106 -0
  24. package/skills/protobase/references/reference/api.md +231 -0
  25. package/skills/protobase/references/reference/architecture.md +63 -0
  26. package/skills/protobase/references/reference/assistant.md +157 -0
  27. package/skills/protobase/references/reference/auth.md +462 -0
  28. package/skills/protobase/references/reference/blocks.md +341 -0
  29. package/skills/protobase/references/reference/bottom-bar.md +44 -0
  30. package/skills/protobase/references/reference/cli.md +493 -0
  31. package/skills/protobase/references/reference/client.md +38 -0
  32. package/skills/protobase/references/reference/comments.md +83 -0
  33. package/skills/protobase/references/reference/custom-components.md +285 -0
  34. package/skills/protobase/references/reference/data-config.md +266 -0
  35. package/skills/protobase/references/reference/email.md +166 -0
  36. package/skills/protobase/references/reference/events.md +121 -0
  37. package/skills/protobase/references/reference/files.md +291 -0
  38. package/skills/protobase/references/reference/forms.md +133 -0
  39. package/skills/protobase/references/reference/history.md +86 -0
  40. package/skills/protobase/references/reference/jobs.md +174 -0
  41. package/skills/protobase/references/reference/layouts.md +126 -0
  42. package/skills/protobase/references/reference/plugins.md +328 -0
  43. package/skills/protobase/references/reference/remote-resources.md +198 -0
  44. package/skills/protobase/references/reference/sidebar.md +51 -0
  45. package/skills/protobase/references/reference/theme.md +132 -0
  46. package/skills/protobase/references/reference/ui-config.md +880 -0
  47. package/skills/protobase/references/reference/user-menu.md +38 -0
  48. package/skills/protobase/references/reference/versioning.md +91 -0
  49. package/skills/protobase/references/reference/webhooks.md +136 -0
@@ -0,0 +1,230 @@
1
+ <!-- Generated by scripts/protobase-skill.ts from website/src/content/docs/guides/first-composed-page.mdx: run `bun run docs:skill`, do not edit. -->
2
+
3
+ # Your first composed page
4
+
5
+ Build the sales team's start page in four steps, from four numbers to a row of leads you can add to.
6
+
7
+ It is Monday morning at Veldhuis Supply. Sam, who runs sales, opens the admin and starts the usual round: Orders filtered to drafts, Orders again for deliveries nobody paid, Invoices filtered to overdue, Companies filtered to leads. Four lists, four filters, every week.
8
+
9
+ What Sam wants is one page that says what needs attention. In Protobase that is a **composed page**: a layout in the config, made of blocks that read the same API as the lists, under the same access rules. No endpoints to write and no React to maintain. By the end of this guide the page looks like the last step below, and every step is a live story you can click through.
10
+
11
+ The page lives in one file next to the rest of the config, `config/overview/page.tsx`, exported from `config/index.ts` like a resource or a view:
12
+
13
+ ```ts
14
+ // config/index.ts
15
+ export { salesOverview } from './overview/page'
16
+ ```
17
+
18
+ ## 1. Four numbers
19
+
20
+ Start with what Sam counts every Monday.
21
+
22
+ ```tsx title="config/overview/page.tsx"
23
+ /** @jsxImportSource @protobase/layout */
24
+ import { Grid, Page, Stat, page } from '@protobase/layout'
25
+
26
+ export const overview = page(
27
+ 'overview',
28
+ <Page title="Sales overview" description="What needs attention today.">
29
+ <Grid columns={4}>
30
+ <Stat label="Draft orders" resource="orders" filter="status = 'draft'" />
31
+ <Stat label="Delivered, not paid" resource="orders" filter="status = 'delivered' AND paid = false" />
32
+ <Stat label="Overdue invoices" resource="invoices" filter="status = 'overdue'" />
33
+ <Stat label="Open leads" resource="companies" filter="status = 'lead'" />
34
+ </Grid>
35
+ </Page>,
36
+ { nav: { group: 'Sales', order: 0 }, icon: 'layout-dashboard' },
37
+ )
38
+ ```
39
+
40
+ That first comment matters. `@jsxImportSource @protobase/layout` makes the JSX build plain data instead of React elements: `<Stat label="Draft orders" ... />` becomes `{ type: 'Stat', props: { label: 'Draft orders', ... }, children: [] }`. The server sends that to the browser in `/api/meta`, and the admin renders it. So a layout holds no functions and no state, and the build refuses one that tries (see [Layouts](../reference/layouts.md#what-a-layout-may-hold))).
41
+
42
+ Each `Stat` counts the records of `resource` that match `filter`, written in the same AIP-160 syntax as the list's `?filter=`. The count is a link to exactly that filtered list. `page('overview', ...)` puts it at `/overview`, and `nav` puts it first in the Sales group of the sidebar.
43
+
44
+ ## 2. The lists behind the numbers
45
+
46
+ A number says *how many*; Sam also wants to see *which*. Two tables under the numbers:
47
+
48
+ ```tsx title="config/overview/page.tsx"
49
+ /** @jsxImportSource @protobase/layout */
50
+ import { Grid, Page, Stat, Table, page } from '@protobase/layout'
51
+
52
+ export const overview = page(
53
+ 'overview',
54
+ <Page title="Sales overview" description="What needs attention today.">
55
+ <Grid columns={4}>
56
+ <Stat label="Draft orders" resource="orders" filter="status = 'draft'" />
57
+ <Stat label="Delivered, not paid" resource="orders" filter="status = 'delivered' AND paid = false" />
58
+ <Stat label="Overdue invoices" resource="invoices" filter="status = 'overdue'" />
59
+ <Stat label="Open leads" resource="companies" filter="status = 'lead'" />
60
+ </Grid>
61
+ <Grid columns={2}>
62
+ <Table title="Overdue invoices" resource="invoices" filter="status = 'overdue'" sort="issued_at" columns={['number', 'company_id', 'due_at', 'total']} limit={2} empty="Nothing is overdue." />
63
+ <Table title="Latest orders" resource="orders" sort="created_at desc" columns={['number', 'company_id', 'status', 'total']} limit={5} />
64
+ </Grid>
65
+ </Page>,
66
+ { nav: { group: 'Sales', order: 0 }, icon: 'layout-dashboard' },
67
+ )
68
+ ```
69
+
70
+ A `Table` takes the same `resource`, `filter` and `sort` (AIP-132, like `?order_by=`), plus the `columns` to show and a `limit`. Relations such as `company_id` show the company's name, a row opens the record, and **View all** opens the list with the same filter and order. Try it on the overdue invoices: there are three, and the table shows two.
71
+
72
+ ## 3. One order to chase
73
+
74
+ Hollis & Rowe took a large delivery and has not paid. Sam wants that order on top, with a button that records the payment when it comes in.
75
+
76
+ ```tsx title="config/overview/page.tsx"
77
+ /** @jsxImportSource @protobase/layout */
78
+ import { Action, Field, Grid, Page, RecordCard, Show, Stat, Table, page } from '@protobase/layout'
79
+
80
+ export const overview = page(
81
+ 'overview',
82
+ <Page title="Sales overview" description="What needs attention today.">
83
+ <Grid columns={4}>
84
+ <Stat label="Draft orders" resource="orders" filter="status = 'draft'" />
85
+ <Stat label="Delivered, not paid" resource="orders" filter="status = 'delivered' AND paid = false" />
86
+ <Stat label="Overdue invoices" resource="invoices" filter="status = 'overdue'" />
87
+ <Stat label="Open leads" resource="companies" filter="status = 'lead'" />
88
+ </Grid>
89
+ <RecordCard
90
+ title="Biggest unpaid delivery"
91
+ resource="orders"
92
+ filter="status = 'delivered' AND paid = false"
93
+ sort="total desc"
94
+ empty="Every delivered order is paid."
95
+ actions={<Action name="markPaid" variant="primary" />}
96
+ >
97
+ <Grid columns={4}>
98
+ <Field name="number" />
99
+ <Field name="total" />
100
+ <Field name="company_id" label="Customer" />
101
+ <Field name="company_id.city" label="City" />
102
+ </Grid>
103
+ <Show when="company_id.status = 'dormant'">The customer has gone quiet: call before sending a reminder.</Show>
104
+ </RecordCard>
105
+ <Grid columns={2}>
106
+ <Table title="Overdue invoices" resource="invoices" filter="status = 'overdue'" sort="issued_at" columns={['number', 'company_id', 'due_at', 'total']} limit={2} empty="Nothing is overdue." />
107
+ <Table title="Latest orders" resource="orders" sort="created_at desc" columns={['number', 'company_id', 'status', 'total']} limit={5} />
108
+ </Grid>
109
+ </Page>,
110
+ { nav: { group: 'Sales', order: 0 }, icon: 'layout-dashboard' },
111
+ )
112
+ ```
113
+
114
+ A `RecordCard` shows one record: the first that matches its `filter` in `sort` order, here the biggest unpaid delivery. Inside it, `Field` shows a field of that record. A dotted name follows a relation: `company_id.city` is the city of the order's company, fetched the way the record page fetches it.
115
+
116
+ The button is `<Action name="markPaid" />`, a named action of the orders view. The layout only names it; what it does is declared once, in the view:
117
+
118
+ ```ts title="config/orders/ui.ts"
119
+ import { view } from '@protobase/schema'
120
+ import type { orders } from './data'
121
+
122
+ export const ordersView = view<typeof orders>('orders')
123
+ .title((r) => r.number)
124
+ .names({ singular: 'Order', plural: 'Orders' })
125
+ .nav({
126
+ recent: {
127
+ status: 'status',
128
+ tones: { draft: 'neutral', confirmed: 'info', picking: 'warning', shipped: 'success' },
129
+ pulse: ['picking'],
130
+ filter: 'status != "delivered" AND status != "cancelled"',
131
+ orderBy: 'created_at desc',
132
+ },
133
+ })
134
+ .fields((r) => ({
135
+ status: r.status.help('Where the order is in its life. Moving it forward can notify the customer.').format('badge')
136
+ .valueLabels({ draft: 'Draft', confirmed: 'Confirmed', picking: 'Picking', shipped: 'Shipped', delivered: 'Delivered', cancelled: 'Cancelled' }),
137
+ total: r.total.help('Order total including VAT.').prefix('€').decimals(2),
138
+ discount_percent: r.discount_percent.label('Discount').help('Percentage taken off the order total.').format('percent'),
139
+ paid: r.paid.help('Set when the payment has been received.'),
140
+ created_at: r.created_at.label('Created').format('absolute'),
141
+ }))
142
+ .list((r) => ({
143
+ columns: [r.number, r.company_id, r.status, r.total, r.discount_percent, r.paid, r.owner_id, r.created_at],
144
+ sort: [[r.created_at, 'desc']],
145
+ search: [r.number],
146
+ }))
147
+ .filters((r, w) => [
148
+ w.facets(r.status),
149
+ w.facets(r.owner_id),
150
+ w.dateRange(r.created_at, { presets: ['7d', '30d', '90d', 'quarter', 'year'] }),
151
+ w.range(r.total, { histogram: true }),
152
+ w.toggle(r.paid),
153
+ ])
154
+ .chart((r) => ({ field: r.created_at, range: '30d', granularity: 'day' }))
155
+ .saveFeedback('toast')
156
+ .actions((a) => [
157
+ a.update('markPaid', { label: 'Mark as paid', icon: 'wallet', set: { paid: true }, confirm: 'Record that the customer paid this order?' }),
158
+ a.action('createInvoice', { label: 'Create invoice', icon: 'file-text' }),
159
+ ])
160
+ ```
161
+
162
+ `a.update('markPaid', { set: { paid: true } })` patches the record with its ETag, after the `confirm` question. Because it is an ordinary update, the access rules decide whether this user may do it, and a user who may not sees the button disabled.
163
+
164
+ `Show` keeps its children only while `when` holds. The condition reads fields of the record around it, through relations too: the warning appears because Hollis & Rowe is `dormant`. Mark the order as paid in the story: the card moves on to the next unpaid delivery, the warning disappears, and the number above drops to one.
165
+
166
+ ## 4. Leads, and a way to add them
167
+
168
+ Last on Sam's list: new leads, with a quick way to add the one met at a trade fair.
169
+
170
+ ```tsx title="config/overview/page.tsx"
171
+ /** @jsxImportSource @protobase/layout */
172
+ import { Action, CardRow, Field, Grid, ModalForm, Page, RecordCard, Show, Stat, Table, page } from '@protobase/layout'
173
+
174
+ export const overview = page(
175
+ 'overview',
176
+ <Page title="Sales overview" description="What needs attention today.">
177
+ <Grid columns={4}>
178
+ <Stat label="Draft orders" resource="orders" filter="status = 'draft'" />
179
+ <Stat label="Delivered, not paid" resource="orders" filter="status = 'delivered' AND paid = false" />
180
+ <Stat label="Overdue invoices" resource="invoices" filter="status = 'overdue'" />
181
+ <Stat label="Open leads" resource="companies" filter="status = 'lead'" />
182
+ </Grid>
183
+ <RecordCard
184
+ title="Biggest unpaid delivery"
185
+ resource="orders"
186
+ filter="status = 'delivered' AND paid = false"
187
+ sort="total desc"
188
+ empty="Every delivered order is paid."
189
+ actions={<Action name="markPaid" variant="primary" />}
190
+ >
191
+ <Grid columns={4}>
192
+ <Field name="number" />
193
+ <Field name="total" />
194
+ <Field name="company_id" label="Customer" />
195
+ <Field name="company_id.city" label="City" />
196
+ </Grid>
197
+ <Show when="company_id.status = 'dormant'">The customer has gone quiet: call before sending a reminder.</Show>
198
+ </RecordCard>
199
+ <Grid columns={2}>
200
+ <Table title="Overdue invoices" resource="invoices" filter="status = 'overdue'" sort="issued_at" columns={['number', 'company_id', 'due_at', 'total']} limit={2} empty="Nothing is overdue." />
201
+ <Table title="Latest orders" resource="orders" sort="created_at desc" columns={['number', 'company_id', 'status', 'total']} limit={5} />
202
+ </Grid>
203
+ <CardRow
204
+ title="New leads"
205
+ description="Companies that have not ordered yet."
206
+ resource="companies"
207
+ filter="status = 'lead'"
208
+ sort="created_at desc"
209
+ actions={<ModalForm mode="create" label="Add lead" resource="companies" fields={['name', 'city', 'email']} values={{ status: 'lead' }} />}
210
+ >
211
+ <Field name="name" label={false} />
212
+ <Field name="city" />
213
+ <Field name="email" />
214
+ <ModalForm mode="edit" label="Edit" fields={['name', 'city', 'email', 'status']} />
215
+ </CardRow>
216
+ </Page>,
217
+ { nav: { group: 'Sales', order: 0 }, icon: 'layout-dashboard' },
218
+ )
219
+ ```
220
+
221
+ A `CardRow` shows a few records side by side, and its children are the template of each card. Inside a card, `Field`, `Action` and `ModalForm` work on that card's record. The header's `ModalForm mode="create"` opens a form for a new company, and `values` adds `status: 'lead'` to what is filled in. The `ModalForm mode="edit"` in each card edits that lead. Add a lead in the story, then edit another one to `active`: it leaves the row, and the count of open leads follows.
222
+
223
+ ## What the page did without
224
+
225
+ There is no endpoint for "biggest unpaid delivery" and no component for "lead card". Every block reads the regular API with Sam's token, so the access rules apply exactly as on the lists. A sales rep with `orders.read.own` sees only their own orders in every count, table and card, and a field they may not read is not on their page at all (see [Access](../reference/layouts.md#access))).
226
+
227
+ The ERP example carries this page, with a few more blocks, in `examples/erp/config/overview/page.tsx`. Next:
228
+
229
+ - [A billing page](billing-page.md)) adds forms, delete and link actions, and a React component of your own.
230
+ - [Blocks](../reference/blocks.md)) lists every block and its props.
@@ -0,0 +1,166 @@
1
+ <!-- Generated by scripts/protobase-skill.ts from website/src/content/docs/guides/first-plugin.md: run `bun run docs:skill`, do not edit. -->
2
+
3
+ # Your first plugin
4
+
5
+ Build a plugin, serve it, load it into an app and change it without rebuilding the app.
6
+
7
+ Sam's sales team wants the newest draft orders on their start page, each a link to the order. That is a few lines of React. Written in the app's `protobase.ui.tsx`, it would be that app's alone, shipped with each of its builds. Written as a [plugin](../reference/plugins.md)) of its own, it is built once, served on its own, and loaded by every app that lists it when it starts, whatever release the app runs.
8
+
9
+ This guide builds that plugin, serves it, loads it into an app and changes it without touching the app. It uses the orders of the ERP example (`examples/erp`); any resource of yours works the same.
10
+
11
+ ## 1. A folder for the plugin
12
+
13
+ A plugin is a folder of its own, next to the app's project or anywhere else, with a `package.json` that names it:
14
+
15
+ ```json
16
+ {
17
+ "name": "sales-tools",
18
+ "version": "1.0.0",
19
+ "private": true,
20
+ "type": "module"
21
+ }
22
+ ```
23
+
24
+ It depends on `@protobase/ui`, the version it is built for, on `react`, and on `@protobase/cli` to build it:
25
+
26
+ ```sh
27
+ bun add @protobase/ui react
28
+ bun add -d @protobase/cli @types/react
29
+ ```
30
+
31
+ Its entry is a `protobase.ui.tsx`, written like a project's: each component exported under its name, from a file of its own, and the rest in `definePlugin`:
32
+
33
+ ```tsx
34
+ // protobase.ui.tsx
35
+ import { definePlugin } from '@protobase/ui'
36
+
37
+ // The plugin's components, each from a file of its own, exported by the name the config declares.
38
+ export { DraftOrders } from './components/draft-orders'
39
+
40
+ export default definePlugin({ name: 'sales-tools' })
41
+ ```
42
+
43
+ ## 2. The component
44
+
45
+ ```tsx
46
+ // components/draft-orders.tsx
47
+ import { RecordLink, useList, usePlugin } from '@protobase/ui'
48
+
49
+ /** The five newest draft orders, each a link to its page, signed with the plugin that draws them. */
50
+ export const DraftOrders = () => {
51
+ const plugin = usePlugin()
52
+ const drafts = useList('orders', { filter: "status = 'draft'", orderBy: 'created_at desc', pageSize: 5 })
53
+ return (
54
+ <div>
55
+ <ul className="divide-y divide-border">
56
+ {drafts.items.map((order) => (
57
+ <li key={String(order.id)} className="flex justify-between py-1.5">
58
+ <RecordLink resource="orders" recordKey={String(order.id)} className="font-medium text-primary-text hover:underline">
59
+ {String(order.number)}
60
+ </RecordLink>
61
+ <span className="tabular-nums text-muted-foreground">{String(order.total)}</span>
62
+ </li>
63
+ ))}
64
+ </ul>
65
+ <p className="mt-2 text-xs text-faint-foreground">{`${plugin.name} ${plugin.version}`}</p>
66
+ </div>
67
+ )
68
+ }
69
+ ```
70
+
71
+ Everything it imports from `@protobase/ui` and `react` will be the app's own at runtime: `useList` reads the API as the signed-in user, through the app's cache, and `RecordLink` goes to the order's page through the app's addresses. `usePlugin()` tells it which plugin it is part of. The Tailwind classes draw with the app's theme: `text-primary-text` is the app's link color.
72
+
73
+ ## 3. Build it
74
+
75
+ ```sh
76
+ bun run protobase build-plugin
77
+ ```
78
+
79
+ ```
80
+ built dist: plugin.json, assets/index-DDnoullN.js and assets/styles-CToS5pKa.css (sales-tools, plugin API 1, Protobase >=0.11.1)
81
+ ```
82
+
83
+ `dist/assets/index-<hash>.js` is the plugin's module: its own code, with `react`, `react/jsx-runtime`, `react-dom` and `@protobase/ui` left as imports for the app to supply. `styles-<hash>.css` holds the utilities its classes use, and nothing else. `plugin.json` names both, the plugin API they are built for and the Protobase versions they run on:
84
+
85
+ ```json
86
+ {
87
+ "name": "sales-tools",
88
+ "version": "1.0.0",
89
+ "api": 1,
90
+ "protobase": ">=0.11.1",
91
+ "entry": "assets/index-DDnoullN.js",
92
+ "css": "assets/styles-CToS5pKa.css"
93
+ }
94
+ ```
95
+
96
+ ## 4. Serve it
97
+
98
+ Any static host serves a plugin: a CDN, a bucket, another app. The app loads it from wherever its `plugin.json` is, with CORS when that is another origin. While you work on it, a few lines of Bun do:
99
+
100
+ ```ts
101
+ // serve.ts: the plugin's dist folder with CORS, as any static host or CDN would serve it.
102
+ Bun.serve({
103
+ port: 4000,
104
+ async fetch(request) {
105
+ const file = Bun.file(`dist${new URL(request.url).pathname}`)
106
+ if (!(await file.exists())) return new Response('Not found', { status: 404 })
107
+ return new Response(file, { headers: { 'access-control-allow-origin': '*' } })
108
+ },
109
+ })
110
+ ```
111
+
112
+ ```sh
113
+ bun serve.ts
114
+ ```
115
+
116
+ `http://localhost:4000/plugin.json` now answers.
117
+
118
+ ## 5. Load it into the app
119
+
120
+ In the app's project, list the plugin in `.env`:
121
+
122
+ ```sh
123
+ PROTOBASE_PLUGINS=http://localhost:4000/plugin.json
124
+ ```
125
+
126
+ and put its component on the start page, declared with the plugin that provides it:
127
+
128
+ ```tsx
129
+ // config/overview/page.tsx
130
+ /** @jsxImportSource @protobase/layout */
131
+ import { Card, component, page, Page } from '@protobase/layout'
132
+
133
+ /** The newest draft orders, drawn by the sales-tools plugin. */
134
+ export const DraftOrders = component('DraftOrders', { plugin: 'sales-tools' })
135
+
136
+ export const salesOverview = page(
137
+ 'overview',
138
+ <Page title="Sales overview">
139
+ <Card title="Draft orders">
140
+ <DraftOrders />
141
+ </Card>
142
+ </Page>,
143
+ )
144
+ ```
145
+
146
+ `{ plugin: 'sales-tools' }` tells `protobase build` that the project's own `protobase.ui.tsx` does not have the component, so it does not fail on it. Start the app with `bun run protobase dev` and sign in: the start page shows the card with the five newest drafts, and `sales-tools 1.0.0` under them. `/api/meta` named the plugin, the app read its `plugin.json`, saw that it fits, and loaded its module and stylesheet.
147
+
148
+ ## 6. Change the plugin, not the app
149
+
150
+ Show three orders instead of five: set `pageSize: 3` in `components/draft-orders.tsx` and build the plugin again:
151
+
152
+ ```sh
153
+ bun run protobase build-plugin
154
+ ```
155
+
156
+ Reload the app. The card shows three orders, and the app was neither rebuilt nor restarted: it found the new module through the same `plugin.json`. That is how a plugin ships: a new build where its `plugin.json` is served.
157
+
158
+ ## 7. Ship it
159
+
160
+ Put `dist/` on a static host, and list its `plugin.json` in the deployed app's `PROTOBASE_PLUGINS`, or in `options.plugins` of its `protobase.config.ts`, which can also give the plugin settings and limit it to some roles (see [loading](../reference/plugins.md#loading))). Serve `plugin.json` without caching, so a new build reaches the apps on their next load, and the files in `assets/`, whose names change with their content, as long as you like.
161
+
162
+ ## When the app moves on
163
+
164
+ The app updates to a new release of Protobase. Nothing happens to the plugin: within plugin API 1, every release keeps what the plugin imports, and the plugin runs on the newer `@protobase/ui` it is handed, its fixes included.
165
+
166
+ If the app were older than the plugin needs, it would not load the plugin at all. Its admins would see a notice above the app, such as "The plugin sales-tools is off: it needs Protobase >=0.12.0, and this app runs 0.11.1.", and the card would show a warning in place of the drafts, while the rest of the app works as before. [Versions](../reference/plugins.md#versions)) has the rules.
@@ -0,0 +1,43 @@
1
+ <!-- Generated by scripts/protobase-skill.ts from website/src/content/docs/guides/import-records.md: run `bun run docs:skill`, do not edit. -->
2
+
3
+ # Importing records from a spreadsheet
4
+
5
+ Bring a spreadsheet of companies into the admin app with the list's Import, update them from another, and turn Import off where it does not belong.
6
+
7
+ Rijnland's sales team keeps a spreadsheet of companies they met at a trade fair, and wants them in the ERP example (`examples/erp`) without typing each one. Every list offers **Import** to a user who may create its records, so there is nothing to build: this guide walks through an import, an update from a second file, and turning Import off. The [reference](../reference/ui-config.md#importing-records)) has every rule.
8
+
9
+ ## 1. Import new records
10
+
11
+ Save the spreadsheet as it is (`.xlsx`), or as **CSV UTF-8**. Its first row names the columns:
12
+
13
+ | Name | City | Country | Status | Email |
14
+ | --- | --- | --- | --- | --- |
15
+ | Hoogland Fietsen | Leiden | NL | Lead | inkoop@hoogland.test |
16
+ | De Spaak | Delft | NL | lead | |
17
+
18
+ Open **Companies**, press **Import** and choose the file. Each column whose header is a field's label or name is mapped already: Country is the label the companies' view gives `country_code`, a relation whose column holds each country's key. Map other columns, or leave them at **Do not import**. Set **Numbers** and **Dates** to how the file writes them. Fields a new company needs that no column fills are named above **Check rows**, which waits for them.
19
+
20
+ **Check rows** reads the whole file and writes nothing. It shows the first rows as they will be saved and lists each row with a problem, such as a country no record has or a status that is none of Lead, Active and Dormant (`lead` is fine: case and spacing do not count). Those rows are skipped. An empty Email is saved empty; an empty cell is never filled with a default.
21
+
22
+ **Import** saves the rows in batches of 100, each batch on its own. A row the server refuses is listed with the server's reason while the rest are saved, and **Cancel import** stops after the batch it is in. The summary counts what was created, updated, skipped and failed; **Download** gives the rows not imported, with their line in the file and why, to fix and import again.
23
+
24
+ ## 2. Update records from a file
25
+
26
+ A second sheet has the companies' VAT numbers, by name:
27
+
28
+ | Name | VAT number |
29
+ | --- | --- |
30
+ | Hoogland Fietsen | NL001234567B01 |
31
+
32
+ Choose **Update** under **Rows**, then **Find records by** Name and **Found in column** Name. Name is a filterable field, so the import can look the companies up; a name two companies share is a problem on its row rather than a guess. A row whose name finds no company is not imported; **Create or update** would create it instead.
33
+
34
+ ## 3. Turn Import off
35
+
36
+ When a list's records should never come from a file, such as invoices that only orders should make, turn its Import off in the view:
37
+
38
+ ```ts
39
+ // invoices/ui.ts
40
+ export const invoicesView = view<typeof invoices>('invoices').import(false)
41
+ ```
42
+
43
+ Turning it off removes the button, not a right: the API takes the same writes from any client, and the server checks each one, so a user who may not create a record, or write one of its fields, is refused per row as on the record page.
@@ -0,0 +1,64 @@
1
+ <!-- Generated by scripts/protobase-skill.ts from website/src/content/docs/guides/plugin-build.md: run `bun run docs:skill`, do not edit. -->
2
+
3
+ # Moving onto the plugin build
4
+
5
+ What changes for a project whose protobase.ui.tsx was built into the admin app, now that protobase build makes it a plugin beside a prebuilt app.
6
+
7
+ Until 0.12, `protobase build` built the whole admin app into each bundle, with the project's `protobase.ui.tsx` and every `--extend` folder's compiled into it. Each bundle was frozen at the `@protobase/ui` it was built with: the app's fixes reached it only with a rebuild. From 0.12 the admin app is prebuilt once per release, and `protobase build` builds the project's `protobase.ui.tsx` as a [plugin](../reference/plugins.md)) beside it. The project's code is written the same way; this guide moves a project over and says what to look at.
8
+
9
+ ## 1. Update and rebuild
10
+
11
+ Move the project's `@protobase` packages to 0.12 or newer, as for any release, and build:
12
+
13
+ ```sh
14
+ bun add @protobase/cli@^0.12 @protobase/server@^0.12 @protobase/schema@^0.12 @protobase/layout@^0.12 @protobase/ui@^0.12
15
+ bun run protobase build
16
+ ```
17
+
18
+ ```
19
+ built dist: protobase.config.js, public/ with plugins app and protobase.bundle.json (api /api)
20
+ ```
21
+
22
+ A bundle of an older release is refused by the 0.12 runtime, as every new minor below 1.0 is; this one rebuild is the whole migration for most projects. The new bundle holds:
23
+
24
+ ```
25
+ dist/
26
+ protobase.config.js
27
+ public/
28
+ index.html, assets/ the prebuilt admin app
29
+ plugins/app/ protobase.ui.tsx, as the plugin app
30
+ protobase.theme.css empty until the project has a theme
31
+ protobase.favicon.svg Protobase's until the project has its own
32
+ protobase.bundle.json version 3, naming the plugins and the app's version
33
+ ```
34
+
35
+ ## 2. Check protobase.ui.tsx
36
+
37
+ Nothing in it has to change: its named component exports, `defineUi({ actions, shell, extends })` and the components it registers work as before. `definePlugin` is the same function under its new name, and also takes [field types](../reference/plugins.md#field-types)). Three things a plugin cannot do, which a built-in `protobase.ui.tsx` could, fail the build or show at once:
38
+
39
+ - **Modules of the shared packages.** `react`, `react/jsx-runtime`, `react-dom` and `@protobase/ui` come from the app, by those names. An import of another module of theirs, such as `react-dom/client` or a file inside `@protobase/ui`, fails the build: import from the package's main entry instead.
40
+ - **Browser work at the top level.** The build loads `protobase.ui.tsx` once in Node to read its field types. Code that touches `window`, `document` or `localStorage` when a module loads fails the build; move it into a component, a hook or a handler.
41
+ - **A data library of its own.** A component that used `@tanstack/react-query` directly found the app's query client while it was built into the app; as a plugin it carries its own copy, which does not. Read through `@protobase/ui`'s hooks (`useList`, `useRecord`, `useClient`), which share the app's cache and session.
42
+
43
+ ## 3. Check its styles
44
+
45
+ The project's Tailwind classes are built into the plugin's own stylesheet, `plugins/app/assets/styles-<hash>.css`: utilities only, each reading the app's [tokens](../reference/theme.md)). `bg-primary` and `rounded-md` look as before. A class that only worked because the app's own stylesheet happened to have it is now in the plugin's too, so nothing is lost. To change the app's colors, radius or font, write a [`protobase.theme.css`](theme-an-app.md)), not rules against the app's markup.
46
+
47
+ ## 4. Extensions
48
+
49
+ Each `--extend` folder's `protobase.ui.tsx` becomes a plugin of its own, `plugins/<name>/`, named by its `package.json`, else its folder, and merged before the project's, as before. Its `protobase.config.ts` is merged into the config module as before. Two extensions that would be plugins of one name fail the build: give one's `package.json` another `name`.
50
+
51
+ ## 5. Hosts
52
+
53
+ A host that serves `public/` as before keeps working: `index.html` for navigations, files for the rest. Two things are new:
54
+
55
+ - The plugins' `assets/` folders, `public/plugins/<name>/assets/`, are named by their content like `public/assets/`: serve them as immutable too. `plugin.json`, `protobase.theme.css` and `protobase.favicon.svg` are served with `no-cache`.
56
+ - A host that keeps the prebuilt app of newer releases may serve it for the manifest's `shell.paths`, so the app gets that release's fixes without a rebuild (see [the shell](../reference/plugins.md#the-shell))). `protobase serve` does so with its own when every plugin of the bundle loads in it.
57
+
58
+ ## 6. protobase dev
59
+
60
+ Nothing changes: `protobase dev` builds `protobase.ui.tsx` into its page with hot reload, as before, and serves the theme too. `protobase build && protobase serve dist` runs the bundle as a host does, with the project's UI loaded as the plugin `app`.
61
+
62
+ ## After the move
63
+
64
+ From now on, a release of Protobase within the same minor needs no rebuild of the project's UI: the app it runs in is the release's, and the plugin keeps working within its [plugin API](../reference/plugins.md#versions)). The server config still follows the [bundle's rule](../reference/versioning.md#bundles-and-runtimes)), so a new minor below 1.0 is still a rebuild.
@@ -0,0 +1,70 @@
1
+ <!-- Generated by scripts/protobase-skill.ts from website/src/content/docs/guides/record-card.md: run `bun run docs:skill`, do not edit. -->
2
+
3
+ # A custom record card
4
+
5
+ Draw each card of a cards display with a component of your own, and keep the built-in card as its fallback.
6
+
7
+ A list can show its records as [cards](../reference/ui-config.md#list-displays)) beside its table: a title, a subtitle, a badge and a few small fields. Rijnland's sales team wants order cards that lead with the total and the customer, the way they talk about orders. That is a card component: the list page still loads the orders, filters, sorts and links each card to its order; the component only draws what is inside a card. This guide adds one to the ERP example (`examples/erp`).
8
+
9
+ ## 1. The card
10
+
11
+ A card component gets `row`, one record of the list:
12
+
13
+ ```tsx
14
+ // components/order-card.tsx
15
+ import type { RecordCardProps } from '@protobase/ui'
16
+
17
+ /** An order as a card: its number and total, the customer, and its status. */
18
+ export const OrderCard = ({ row }: RecordCardProps) => (
19
+ <span className="flex flex-col gap-1">
20
+ <span className="flex items-baseline justify-between gap-2">
21
+ <span className="font-mono text-xs text-muted-foreground">{String(row.record.number)}</span>
22
+ <span className="font-semibold tabular-nums">€{Number(row.record.total).toFixed(2)}</span>
23
+ </span>
24
+ <span className="truncate font-medium">{row.labels.company_id ?? String(row.record.company_id)}</span>
25
+ <span className="mt-1 self-start rounded-md bg-primary-soft px-1.5 py-0.5 text-xs text-primary-text">{String(row.record.status)}</span>
26
+ </span>
27
+ )
28
+ ```
29
+
30
+ `row.record` is the order as the list API gives it, and `row.labels` the name of the record each relation points at: `company_id` is the company's id, `labels.company_id` its name. `row.key` is the order's key.
31
+
32
+ The whole card is a link to the order, so the component draws no links or buttons of its own; the app draws the card's border, padding and hover, in the app's [theme](../reference/theme.md)).
33
+
34
+ ## 2. Export it
35
+
36
+ ```tsx
37
+ // protobase.ui.tsx
38
+ export { OrderCard } from './components/order-card'
39
+ ```
40
+
41
+ ## 3. Use it in the view
42
+
43
+ Declare the component in the view and give it to a cards display. The fields the display names are the fields the cards get, so name every field the card reads:
44
+
45
+ ```ts
46
+ // config/orders/ui.ts
47
+ import { component } from '@protobase/layout'
48
+
49
+ export const OrderCard = component('OrderCard')
50
+
51
+ // ...
52
+ .list((r, d) => ({
53
+ columns: [r.number, r.company_id, r.status, r.total, r.created_at],
54
+ sort: [[r.created_at, 'desc']],
55
+ displays: [d.cards({ title: r.number, subtitle: r.company_id, badge: r.status, meta: [r.total] }, { card: OrderCard })],
56
+ }))
57
+ ```
58
+
59
+ Run `bun run protobase dev`, open the orders and switch to Cards: each order is drawn by `OrderCard`. The display keeps everything else the list has: its search, filters, sort menu, the count of orders and loading more as you scroll.
60
+
61
+ `protobase build` fails when the config declares `OrderCard` and `protobase.ui.tsx` does not export it. A card from a [plugin](../reference/plugins.md)) is declared with the plugin's name, `component('OrderCard', { plugin: 'sales-tools' })`.
62
+
63
+ ## 4. When the card fails
64
+
65
+ The fields in `d.cards` do double duty: they are also the built-in card, `title` over `subtitle` with `badge` and the `meta` fields. Each card falls back to it:
66
+
67
+ - when the component throws while drawing, that card alone;
68
+ - when no component is registered under the name, for instance because its plugin is off, every card.
69
+
70
+ So a broken card still shows each order's number, customer and status, and still opens it.