@softr/sdk 0.0.56-alpha.0 → 0.0.56-alpha.2

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 (39) hide show
  1. package/dist/action.d.ts +1 -31
  2. package/dist/action.js +1 -26
  3. package/dist/auth/isomorphic.d.ts +1 -1
  4. package/dist/auth/isomorphic.js +2 -1
  5. package/dist/client.d.ts +1 -2
  6. package/dist/client.js +1 -2
  7. package/dist/codegen/datasource-types.js +1 -1
  8. package/dist/core/file-upload.d.ts +2 -7
  9. package/dist/core/file-upload.js +1 -6
  10. package/dist/core/use-file-upload.d.ts +2 -2
  11. package/dist/default-error-overlay.d.ts +2 -2
  12. package/dist/index.d.ts +3 -3
  13. package/dist/index.js +3 -2
  14. package/dist/mcp.d.ts +2 -2
  15. package/dist/package.js +1 -1
  16. package/dist/pwa.d.ts +54 -0
  17. package/dist/pwa.js +152 -0
  18. package/dist/server.d.ts +1 -2
  19. package/dist/server.js +1 -2
  20. package/package.json +1 -3
  21. package/skills/softr-sdk/SKILL.md +7 -7
  22. package/skills/softr-sdk/auth/SKILL.md +1 -1
  23. package/skills/softr-sdk/charts-and-metrics/SKILL.md +1 -1
  24. package/skills/softr-sdk/current-user/SKILL.md +1 -1
  25. package/skills/softr-sdk/file-uploads/SKILL.md +4 -5
  26. package/skills/softr-sdk/integrations/SKILL.md +1 -1
  27. package/skills/softr-sdk/mcp/SKILL.md +1 -1
  28. package/skills/softr-sdk/pwa/SKILL.md +77 -0
  29. package/skills/softr-sdk/record-mutations/SKILL.md +1 -1
  30. package/skills/softr-sdk/record-queries/SKILL.md +2 -2
  31. package/skills/softr-sdk/record-queries/references/field-types.md +1 -1
  32. package/skills/softr-sdk/region-visibility/SKILL.md +1 -1
  33. package/skills/softr-sdk/routes-and-visibility/SKILL.md +1 -1
  34. package/skills/softr-sdk/workflows/SKILL.md +1 -1
  35. package/dist/comments/comments.d.ts +0 -168
  36. package/dist/comments/comments.js +0 -413
  37. package/dist/comments/use-comment-composer.d.ts +0 -46
  38. package/dist/comments/use-comment-composer.js +0 -134
  39. package/skills/softr-sdk/comments/SKILL.md +0 -182
@@ -1,182 +0,0 @@
1
- ---
2
- name: comments
3
- description: >-
4
- Comment threads on records: defineComments from @softr/sdk declares which
5
- datasource has comments; comments.list, create, update, delete, react,
6
- subscription, setSubscription and searchMentions from @softr/sdk/server read
7
- and write one record's thread inside a server function; useCommentComposer
8
- and useFileUpload from @softr/sdk/client keep a textarea's text, its
9
- @mentions and its attachments in step. Bodies come back as sanitised
10
- bodyHtml. A null thread means render nothing.
11
- metadata:
12
- type: sub-skill
13
- library: softr-sdk
14
- library_version: 0.0.56-alpha.0
15
- ---
16
-
17
- **Boundary.** `comments` lives on `@softr/sdk/server` and runs only inside a `createServerFn` handler. Importing it into a component fails the build. `useCommentComposer` lives on `@softr/sdk/client` and runs in components. `defineComments` comes from `@softr/sdk` and can be imported anywhere.
18
-
19
- # Comments on records
20
-
21
- Every record of a commented datasource has one thread. The SDK reads and writes it. The app owns everything you see: layout, copy, sort order, dates.
22
-
23
- ## Setup
24
-
25
- ```ts
26
- import { createServerFn } from '@tanstack/react-start'
27
- import { defineComments, type CommentMention, type CommentAttachmentInput } from '@softr/sdk'
28
- import { comments } from '@softr/sdk/server'
29
- import { useCommentComposer, useFileUpload } from '@softr/sdk/client'
30
- ```
31
-
32
- ## Declare the comments action
33
-
34
- ```ts
35
- export const orderComments = defineComments({
36
- id: 'orderComments',
37
- datasourceId: '8f14e45f-ceea-467a-9d0b-2c1a0e3b5d77',
38
- })
39
- ```
40
-
41
- - `id` is a name you choose, unique across the app. `datasourceId` is the table whose records get threads.
42
- - There is no `permissions`. Who may read, post and delete is set in Softr under Settings → Comments, the same settings native comment blocks use.
43
- - Declare it once per datasource. Two declarations on the same datasource are the **same** threads, so "internal notes" next to "customer comments" on one table is not possible.
44
- - Write the object inline. Passing it through a variable hides it from the build.
45
-
46
- ## Read a thread
47
-
48
- ```ts
49
- const getThread = createServerFn({ method: 'GET' })
50
- .validator((data: { recordId: string; offset?: number | null }) => data)
51
- .handler(({ data }) => comments.list(orderComments, { recordId: data.recordId, offset: data.offset }))
52
- ```
53
-
54
- `comments.list` answers `null` when this visitor cannot see comments on the record: comments are off for the app, the table is not set up yet, or the visitor's group may not read them. Render nothing for `null`, not an error.
55
-
56
- Otherwise it answers:
57
-
58
- | Field | What it is |
59
- | --- | --- |
60
- | `items` | The comments for this page, newest first. Each is a `CommentView` |
61
- | `canPost` | Whether this visitor may post. Hide the composer when false |
62
- | `allowMentions` | Whether `@` opens a mention menu. Do not call `searchMentions` when false |
63
- | `quickReactions` | The five `{ emoji, label }` a comment can be reacted with. There are no others |
64
- | `total`, `nextOffset` | Paging. The first page is the newest comments; each further page, fetched by passing `nextOffset` back as `offset`, goes further back in time. `null` on the last page |
65
-
66
- A `CommentView` is `{ id, bodyHtml, attachments, author: { name, avatar, isDeactivated }, createdAt, canDelete, canEdit, edited, source, reactions }`. `createdAt` is ISO 8601. Format it with `useUserTimezone`. Each reaction is `{ emoji, label, count, isSelected }`.
67
-
68
- - `allowAttachments` (on the thread): whether the composer may attach files.
69
- - `attachments[].type` (per attachment): the file's content type, or `null` when the platform does not know it.
70
- - `notificationsEnabled` (on the thread): whether to show the notifications switch at all. Hide it when false, even for a visitor who may post.
71
- - `canEdit` (per comment): whether this visitor may edit it. Show Edit only then.
72
- - `edited` (per comment): whether it was changed since it was posted. Show "(edited)" beside its date.
73
- - `source` (per comment): `{ text, mentions }` to fill an edit box, or `null` when `canEdit` is false. It is the body as the visitor typed it, with each mention as its own `@name` and range, the same shape the composer works with.
74
-
75
- `bodyHtml` is already sanitised. Render it with `dangerouslySetInnerHTML` and nothing else:
76
-
77
- ```tsx
78
- <div className="comment-body" dangerouslySetInnerHTML={{ __html: comment.bodyHtml }} />
79
- ```
80
-
81
- It holds `p`, `br`, `strong`, `em`, `u`, `s`, `del`, `a`, `ul`, `ol`, `li`, `code`, `pre`, `blockquote`, `h1`–`h3` and mention `span[data-type="mention"]`. Links open in a new tab. Style those tags under the body's class, because the reset strips list bullets, link colour and spacing.
82
-
83
- ## Post a comment
84
-
85
- ```ts
86
- const postComment = createServerFn({ method: 'POST' })
87
- .validator(
88
- (data: {
89
- recordId: string
90
- body: string
91
- mentions: Array<CommentMention>
92
- attachments?: Array<CommentAttachmentInput>
93
- }) => data,
94
- )
95
- .handler(({ data }) => comments.create(orderComments, data))
96
- ```
97
-
98
- Pass the composer's `text` as `body` and its `mentions` as they are. The SDK stores the mentions in the format native blocks read, and the people mentioned get an email. A mention whose `@name` was edited is posted as plain text.
99
-
100
- `attachments` are the files the visitor uploaded with the post, from `useFileUpload(orderComments).files.filter((f) => f.status === 'done')`. Send them only when the thread's `allowAttachments` is true.
101
-
102
- `useFileUpload` takes the comments declaration as it takes a mutation. No extra declaration.
103
-
104
- ## The composer
105
-
106
- ```tsx
107
- const composer = useCommentComposer()
108
-
109
- <textarea {...composer.textareaProps} placeholder="Write a comment" />
110
- {/* While composer.query is not null, list findPeople's answer for it. Picking a person calls composer.pick(person). */}
111
- <button
112
- disabled={composer.text.trim() === ''}
113
- onClick={async () => {
114
- await postComment({ data: { recordId, body: composer.text, mentions: composer.mentions } })
115
- composer.reset()
116
- }}
117
- >
118
- Post
119
- </button>
120
- ```
121
-
122
- - Spread `textareaProps` onto the `<textarea>`. It carries the `ref`, `value`, `onChange` and `onSelect` the composer needs, so do not replace them.
123
- - `query` is what follows `@` before the caret, or `null`. It is `""` the moment `@` is typed.
124
- - `pick({ name, email })` writes `@name`, records the mention and puts the caret after it.
125
- - `reset()` empties the box. Call it after the post succeeds, never before.
126
-
127
- ## Editing a comment
128
-
129
- Offer Edit only where the comment's `canEdit` is true.
130
-
131
- - Fill the edit box with `useCommentComposer({ initial: comment.source })`, mounted only while editing.
132
- - Seed the edit's `useFileUpload` with the comment's kept files: `useFileUpload(orderComments, { initialAttachments: comment.attachments.map((a) => ({ ...a, id: a.url })) })`. A comment's attachment has no `id` of its own, so the url stands in for one.
133
- - Pass `comment.attachments` (the files kept) plus any new uploads to `comments.update` as `attachments`.
134
- - Re-read the thread after the write. `update` answers nothing.
135
-
136
- ## Mentions
137
-
138
- ```ts
139
- const findPeople = createServerFn({ method: 'GET' })
140
- .validator((data: { query: string }) => data)
141
- .handler(({ data }) => comments.searchMentions(orderComments, data))
142
- ```
143
-
144
- It answers `[{ name, email, avatar }]`, the people this visitor may mention whose name or email matches. Who is mentionable is set in Settings → Comments, per user group.
145
-
146
- ## Delete, update, react, subscribe
147
-
148
- ```ts
149
- await comments.delete(orderComments, { recordId, commentId })
150
- await comments.update(orderComments, { recordId, commentId, body, mentions, attachments })
151
- await comments.react(orderComments, { recordId, commentId, emoji: '👍', selected: !reaction.isSelected })
152
- const subscribed = await comments.subscription(orderComments, { recordId })
153
- await comments.setSubscription(orderComments, { recordId, subscribed: !subscribed })
154
- ```
155
-
156
- Each runs inside its own server function, like `list`.
157
-
158
- - Offer delete only where `canDelete` is true.
159
- - `update` saves an edit; see "Editing a comment" above for `attachments`.
160
- - `react` adds the visitor's reaction when `selected` is true and removes it when false. `emoji` must be one of `quickReactions`.
161
- - A subscription is whether the visitor gets an email when someone comments on this record. It needs a
162
- signed-in visitor. Posting subscribes the author, and a mention subscribes the person mentioned.
163
- - Mails go out a few minutes after a comment, never to its own author, and only while notifications are
164
- on in Settings → Comments.
165
-
166
- Re-read the thread after each write. The writes answer nothing.
167
-
168
- ## Failure modes
169
-
170
- **Keying the thread on the URL instead of the record.** Pass the fetched `record.id` as `recordId`, never a route param or a search param. A param can be a slug, stale, or a different record's id, and the thread then shows another record's comments.
171
-
172
- **Treating `null` as an error.** A visitor who may not read comments gets `null`. Render nothing. An error box for it shows every such visitor a broken page.
173
-
174
- **Rendering a body as text, or sanitising it again.** Use `bodyHtml` with `dangerouslySetInnerHTML`. As text it shows raw tags, and a second sanitiser strips the mention markup.
175
-
176
- **Inventing reactions.** Only the five in `quickReactions` can be stored. `react` throws for any other emoji.
177
-
178
- **Calling `comments.*` from a component.** It is server only. Wrap each call in a `createServerFn`.
179
-
180
- ## References
181
-
182
- - [record-queries/SKILL.md](../record-queries/SKILL.md): fetching the record whose `id` keys the thread