@seedprotocol/react 0.7.4 → 0.7.5-next.871.g8788c94

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 (2) hide show
  1. package/README.md +119 -0
  2. package/package.json +19 -4
package/README.md ADDED
@@ -0,0 +1,119 @@
1
+ # @seedprotocol/react
2
+
3
+ [![npm](https://img.shields.io/npm/v/@seedprotocol/react.svg)](https://www.npmjs.com/package/@seedprotocol/react)
4
+ [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
5
+ [![Docs](https://img.shields.io/badge/docs-seedprotocol.io-0B6E4F)](https://seedprotocol.io)
6
+
7
+ React hooks and components for [Seed Protocol](https://seedprotocol.io). Read and write schemas, models, items and item properties from [`@seedprotocol/sdk`](https://www.npmjs.com/package/@seedprotocol/sdk) in React. Lists stay in sync with the local SQLite database through live queries and [TanStack Query](https://tanstack.com/query/latest). The package also ships components that render images, media, HTML and JSON from Seed items.
8
+
9
+ ## Installation
10
+
11
+ `@seedprotocol/sdk`, `react` (18 or 19) and `@tanstack/react-query` (v5) are peer dependencies:
12
+
13
+ ```bash
14
+ npm install @seedprotocol/react @seedprotocol/sdk @tanstack/react-query react
15
+ # or
16
+ bun add @seedprotocol/react @seedprotocol/sdk @tanstack/react-query react
17
+ # or
18
+ pnpm add @seedprotocol/react @seedprotocol/sdk @tanstack/react-query react
19
+ ```
20
+
21
+ For Vite browser apps, also add [`@seedprotocol/vite`](https://www.npmjs.com/package/@seedprotocol/vite).
22
+
23
+ ## Usage
24
+
25
+ Initialize the client and wrap your app. `SeedClientGate` calls `client.init()` and shows a loading UI until the client is ready. `SeedProvider` supplies the QueryClient the list hooks use.
26
+
27
+ ```tsx
28
+ import { SeedProvider, SeedClientGate } from '@seedprotocol/react'
29
+ import type { SeedConstructorOptions } from '@seedprotocol/sdk'
30
+
31
+ const initConfig: SeedConstructorOptions = {
32
+ config: {
33
+ filesDir: '.seed',
34
+ endpoints: { filePaths: '/api/seed/migrations', files: '/app-files' },
35
+ },
36
+ }
37
+
38
+ export function Root() {
39
+ return (
40
+ <SeedProvider>
41
+ <SeedClientGate initConfig={initConfig}>
42
+ <App />
43
+ </SeedClientGate>
44
+ </SeedProvider>
45
+ )
46
+ }
47
+ ```
48
+
49
+ You can also call `client.init()` from `@seedprotocol/sdk` yourself and render `<SeedProvider>` after it resolves.
50
+
51
+ List, create and read items:
52
+
53
+ ```tsx
54
+ import { useItems, useCreateItem, useItemProperty } from '@seedprotocol/react'
55
+
56
+ function Posts() {
57
+ const { items, isLoading } = useItems({ modelName: 'Post' })
58
+ const { createItem } = useCreateItem()
59
+
60
+ if (isLoading) return <p>Loading…</p>
61
+ return (
62
+ <>
63
+ <button onClick={() => createItem('Post', { title: 'New post' })}>New post</button>
64
+ <ul>
65
+ {items.map((item) => (
66
+ <PostTitle key={item.seedLocalId} seedLocalId={item.seedLocalId} />
67
+ ))}
68
+ </ul>
69
+ </>
70
+ )
71
+ }
72
+
73
+ function PostTitle({ seedLocalId }: { seedLocalId: string }) {
74
+ const { property } = useItemProperty({ seedLocalId, propertyName: 'title' })
75
+ return <li>{String(property?.value ?? '')}</li>
76
+ }
77
+ ```
78
+
79
+ By default `useItems` returns only local items that have no on-chain seed yet. Pass `includeEas: true` to include items that are already attested.
80
+
81
+ Render an `Html` property with a sanitizer you supply (the SDK does not sanitize HTML):
82
+
83
+ ```tsx
84
+ import DOMPurify from 'dompurify'
85
+ import { SeedHtml } from '@seedprotocol/react'
86
+
87
+ <SeedHtml html={body} sanitize={(html) => DOMPurify.sanitize(html)} />
88
+ ```
89
+
90
+ ## API
91
+
92
+ | Area | Exports |
93
+ |------|---------|
94
+ | Setup | `SeedProvider`, `SeedClientGate`, `createSeedQueryClient`, `getSeedQueryDefaultOptions`, `mergeSeedQueryDefaults` |
95
+ | Schemas | `useSchema`, `useSchemas`, `useCreateSchema`, `useDestroySchema`, `useAllSchemaVersions` |
96
+ | Models | `useModel`, `useModels`, `useCreateModel`, `useDestroyModel` |
97
+ | Model properties | `useModelProperty`, `useModelProperties`, `useCreateModelProperty`, `useDestroyModelProperty` |
98
+ | Items | `useItem`, `useItems`, `useCreateItem`, `usePublishItem`, `useDeleteItem` |
99
+ | Item properties | `useItemProperty`, `useItemProperties`, `useDebouncedItemProperty`, `useCreateItemProperty`, `useDestroyItemProperty`, `invalidateItemPropertiesForItem` |
100
+ | Live data | `useLiveQuery` (Drizzle query to live rows), `useDbsAreReady`, `useIsDbReady` |
101
+ | Sync and services | `useEasSyncProcesses`, `useEasSyncProcessById`, `useServices`, `useService`, `useGlobalServiceStatus`, `useSeedAddressRevision` |
102
+ | Files | `useFiles`, `useImageFiles`, `useOPFSFiles`, `useEnsureLocalImage`, `OPFSFilesManager` |
103
+ | Rendering | `SeedImage` (local `Image` property), `SeedMediaImage`, `SeedMediaAudio`, `SeedMediaVideo`, `SeedMediaFile`, `useResolvedMediaRef` (URL, Arweave tx id or seed UID strings), `SeedHtml`, `SeedJson`, `formatSeedJson` |
104
+
105
+ `useItem` and `useItemProperty` work without a provider: they fall back to a shared QueryClient with Seed defaults. The list hooks (`useSchemas`, `useModels`, `useItems`, `useItemProperties`, `useModelProperties`) should run inside `SeedProvider`, or inside your own `QueryClientProvider` with a client from `createSeedQueryClient()`.
106
+
107
+ If another tab already has the app's storage open, `client.init()` fails with a `FileSystemLockedError` (`code === 'OPFS_LOCKED'`). Handle it with `SeedClientGate`'s `onInitError` prop.
108
+
109
+ ## Documentation
110
+
111
+ - Full documentation: **https://seedprotocol.io**
112
+ - [Getting started](https://github.com/JournoLabs/seed-protocol-sdk/blob/main/docs/GETTING_STARTED.md) (includes a React hooks section)
113
+ - [Data access patterns](https://github.com/JournoLabs/seed-protocol-sdk/blob/main/docs/DATA_ACCESS_PATTERNS.md)
114
+ - [Multi-tab behavior](https://github.com/JournoLabs/seed-protocol-sdk/blob/main/docs/MULTI_TAB.md)
115
+ - Core SDK: [`@seedprotocol/sdk`](https://www.npmjs.com/package/@seedprotocol/sdk)
116
+
117
+ ## License
118
+
119
+ MIT
package/package.json CHANGED
@@ -1,7 +1,18 @@
1
1
  {
2
2
  "name": "@seedprotocol/react",
3
- "version": "0.7.4",
4
- "description": "React hooks and components for Seed Protocol",
3
+ "version": "0.7.5-next.871.g8788c94",
4
+ "description": "React hooks and components for Seed Protocol: live schemas, models, items and properties from @seedprotocol/sdk, backed by TanStack Query",
5
+ "keywords": [
6
+ "seed-protocol",
7
+ "react",
8
+ "react-hooks",
9
+ "local-first",
10
+ "tanstack-query",
11
+ "sqlite",
12
+ "opfs",
13
+ "eas",
14
+ "arweave"
15
+ ],
5
16
  "type": "module",
6
17
  "main": "./dist/index.js",
7
18
  "module": "./dist/index.js",
@@ -29,7 +40,7 @@
29
40
  "test:browser": "cd ../.. && vitest --config vite.config.js --project=browser"
30
41
  },
31
42
  "peerDependencies": {
32
- "@seedprotocol/sdk": "^0.6.0",
43
+ "@seedprotocol/sdk": "0.7.5-next.871.g8788c94",
33
44
  "react": "^18 || ^19",
34
45
  "@tanstack/react-query": "^5"
35
46
  },
@@ -44,7 +55,7 @@
44
55
  "xstate": "^5.28.0"
45
56
  },
46
57
  "devDependencies": {
47
- "@seedprotocol/sdk": "0.7.4",
58
+ "@seedprotocol/sdk": "0.7.5-next.871.g8788c94",
48
59
  "vite-plugin-dts": "^4.5.4",
49
60
  "@tanstack/react-query": "^5.104.1",
50
61
  "@testing-library/react": "^16.3.1",
@@ -62,6 +73,10 @@
62
73
  "url": "git+https://github.com/JournoLabs/seed-protocol-sdk.git",
63
74
  "directory": "packages/react"
64
75
  },
76
+ "homepage": "https://github.com/JournoLabs/seed-protocol-sdk/tree/main/packages/react#readme",
77
+ "bugs": {
78
+ "url": "https://github.com/JournoLabs/seed-protocol-sdk/issues"
79
+ },
65
80
  "publishConfig": {
66
81
  "access": "public"
67
82
  }