@easy-cms/next 1.46.1 → 1.47.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.
package/dist/live.d.ts ADDED
@@ -0,0 +1,19 @@
1
+ import { ClientSchema, ClientCollection, EasyCMSClient, LiveQuery, ClientDocument, LiveState } from '@easy-cms/core/client';
2
+
3
+ /**
4
+ * A list (or one document, with `id`) of a collection with `realtime: true`, kept up to date in
5
+ * a Client Component: loaded through the client, then changed by what others save (ADR-0070).
6
+ * `initial` (e.g. what a Server Component loaded) shows until the first load.
7
+ *
8
+ * ```tsx
9
+ * 'use client'
10
+ * const cms = createClient<typeof config>({ url: '/api/cms' })
11
+ * export function Posts({ posts }: { posts: Post[] }) {
12
+ * const { docs } = useLive(cms, 'posts', { where: { status: { equals: 'published' } } }, posts)
13
+ * return <ul>{docs.map((p) => <li key={p.id}>{p.title}</li>)}</ul>
14
+ * }
15
+ * ```
16
+ */
17
+ declare function useLive<C extends ClientSchema, S extends ClientCollection<C>>(client: EasyCMSClient<C>, collection: S, query?: LiveQuery, initial?: readonly ClientDocument<C, S>[] | ClientDocument<C, S> | null): LiveState<ClientDocument<C, S>>;
18
+
19
+ export { useLive };
package/dist/live.js ADDED
@@ -0,0 +1,24 @@
1
+ 'use client'
2
+
3
+ // src/live.ts
4
+ import { useEffect, useState } from "react";
5
+ function useLive(client, collection, query = {}, initial) {
6
+ const [state, setState] = useState(() => {
7
+ const docs = initial === void 0 || initial === null ? [] : [initial].flat();
8
+ return {
9
+ docs,
10
+ doc: query.id === void 0 ? null : docs[0] ?? null,
11
+ ready: false,
12
+ error: null
13
+ };
14
+ });
15
+ const key = JSON.stringify([collection, query]);
16
+ useEffect(() => {
17
+ const handle = client.live(collection, query, setState);
18
+ return () => handle.close();
19
+ }, [client, key]);
20
+ return state;
21
+ }
22
+ export {
23
+ useLive
24
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@easy-cms/next",
3
- "version": "1.46.1",
3
+ "version": "1.47.0",
4
4
  "description": "Next.js adapter for Easy CMS",
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -17,6 +17,10 @@
17
17
  "types": "./dist/live-preview.d.ts",
18
18
  "default": "./dist/live-preview.js"
19
19
  },
20
+ "./live": {
21
+ "types": "./dist/live.d.ts",
22
+ "default": "./dist/live.js"
23
+ },
20
24
  "./package.json": "./package.json"
21
25
  },
22
26
  "files": [
@@ -26,19 +30,19 @@
26
30
  "node": ">=22.12"
27
31
  },
28
32
  "dependencies": {
29
- "@easy-cms/admin": "^1.46.1"
33
+ "@easy-cms/admin": "^1.47.0"
30
34
  },
31
35
  "peerDependencies": {
32
36
  "next": ">=15.0.0",
33
37
  "react": ">=19.0.0",
34
- "@easy-cms/core": "^1.46.1"
38
+ "@easy-cms/core": "^1.47.0"
35
39
  },
36
40
  "devDependencies": {
37
41
  "@types/react": "^19.2.0",
38
42
  "next": "^16.4.3",
39
43
  "react": "^19.2.0",
40
- "@easy-cms/core": "^1.46.1",
41
- "@easy-cms/db-sqlite": "^1.46.1"
44
+ "@easy-cms/core": "^1.47.0",
45
+ "@easy-cms/db-sqlite": "^1.47.0"
42
46
  },
43
47
  "publishConfig": {
44
48
  "access": "public"