@foundrykit/guides-plugin 0.0.0-stage → 0.1.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/README.md +91 -2
- package/dist/collections/guides.d.ts +8 -0
- package/dist/collections/guides.js +129 -0
- package/dist/collections/guides.js.map +1 -0
- package/dist/collections/siteGuides.d.ts +7 -0
- package/dist/collections/siteGuides.js +139 -0
- package/dist/collections/siteGuides.js.map +1 -0
- package/dist/components/GuideArticle.d.ts +24 -0
- package/dist/components/GuideArticle.js +79 -0
- package/dist/components/GuideArticle.js.map +1 -0
- package/dist/components/GuideSearch.d.ts +5 -0
- package/dist/components/GuideSearch.js +83 -0
- package/dist/components/GuideSearch.js.map +1 -0
- package/dist/components/GuidesNavLink.d.ts +2 -0
- package/dist/components/GuidesNavLink.js +16 -0
- package/dist/components/GuidesNavLink.js.map +1 -0
- package/dist/components/GuidesView.d.ts +6 -0
- package/dist/components/GuidesView.js +212 -0
- package/dist/components/GuidesView.js.map +1 -0
- package/dist/components/Help.d.ts +12 -0
- package/dist/components/Help.js +112 -0
- package/dist/components/Help.js.map +1 -0
- package/dist/exports/client.d.ts +2 -0
- package/dist/exports/client.js +4 -0
- package/dist/exports/client.js.map +1 -0
- package/dist/exports/rsc.d.ts +1 -0
- package/dist/exports/rsc.js +3 -0
- package/dist/exports/rsc.js.map +1 -0
- package/dist/hub.d.ts +33 -0
- package/dist/hub.js +40 -0
- package/dist/hub.js.map +1 -0
- package/dist/index.d.ts +12 -0
- package/dist/index.js +111 -0
- package/dist/index.js.map +1 -0
- package/dist/searchGuides.d.ts +12 -0
- package/dist/searchGuides.js +63 -0
- package/dist/searchGuides.js.map +1 -0
- package/dist/sync.d.ts +29 -0
- package/dist/sync.js +71 -0
- package/dist/sync.js.map +1 -0
- package/package.json +110 -4
package/README.md
CHANGED
|
@@ -1,3 +1,92 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @foundrykit/guides-plugin
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
CMS guides for Payload 3 client sites, served from the Umi [guides hub](https://github.com/umi-labs/guides-hub).
|
|
4
|
+
|
|
5
|
+
- **Guides page** at `/admin/guides` (linked in the sidebar): browse by topic, search, read.
|
|
6
|
+
- **Help button** on every edit page, listing the guides for that collection or global. Renders nothing when
|
|
7
|
+
there are none.
|
|
8
|
+
- **`<Help context="…" />`** for finer places, e.g. `media.create`.
|
|
9
|
+
- **Local read-only copy** of the guides this site is entitled to, so help works when the hub is down.
|
|
10
|
+
The hub pushes a signed ping on every change; a scheduled pull is the backstop.
|
|
11
|
+
- **Site guides**: Umi staff write guides for this site only. Publishing saves them straight to the hub
|
|
12
|
+
(scoped to this site); if the hub can't be reached the editor shows an error and the draft is kept.
|
|
13
|
+
|
|
14
|
+
Extracted from the Turquoise CMS guides section. Spec: https://claude.ai/artifact/RXzSKWXUPBH1K5Gu77CzbJ
|
|
15
|
+
|
|
16
|
+
## Install
|
|
17
|
+
|
|
18
|
+
```ts
|
|
19
|
+
import { guidesPlugin } from '@foundrykit/guides-plugin'
|
|
20
|
+
|
|
21
|
+
export default buildConfig({
|
|
22
|
+
plugins: [
|
|
23
|
+
guidesPlugin({
|
|
24
|
+
// Reported to the hub on each sync, to compare with the site's Sites record.
|
|
25
|
+
features: ['crm.inspiretec'],
|
|
26
|
+
// Who can write site guides here. Default: nobody.
|
|
27
|
+
canAuthor: (user) => (user as { role?: string } | null)?.role === 'super-admin',
|
|
28
|
+
}),
|
|
29
|
+
],
|
|
30
|
+
})
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
Environment (from the site's record in the hub):
|
|
34
|
+
|
|
35
|
+
```
|
|
36
|
+
GUIDES_HUB_URL=https://guides.example.com
|
|
37
|
+
GUIDES_HUB_KEY=<the site's guides key>
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
Then regenerate the import map (`payload generate:importmap`) and create a migration: the plugin adds the
|
|
41
|
+
`guides` and `site-guides` collections and a `guidesSync` job task.
|
|
42
|
+
|
|
43
|
+
### Options
|
|
44
|
+
|
|
45
|
+
| Option | Default | |
|
|
46
|
+
| --- | --- | --- |
|
|
47
|
+
| `hubURL` | `process.env.GUIDES_HUB_URL` | The guides hub. |
|
|
48
|
+
| `siteKey` | `process.env.GUIDES_HUB_KEY` | This site's guides key. Also verifies the hub's webhook signature. |
|
|
49
|
+
| `features` | `[]` | Feature keys reported to the hub. |
|
|
50
|
+
| `canAuthor` | `() => false` | Who sees and writes Site guides. |
|
|
51
|
+
| `schedule` | `'0 0 * * * *'` (hourly) | Cron for the backstop pull (Payload's 6-field form), or `false`. |
|
|
52
|
+
| `disabled` | `false` | |
|
|
53
|
+
|
|
54
|
+
### The scheduled pull
|
|
55
|
+
|
|
56
|
+
The plugin registers a `guidesSync` task scheduled on the `default` queue. Payload only runs schedules
|
|
57
|
+
when something runs the jobs: `jobs.autoRun` on a long-running server, or a cron hitting
|
|
58
|
+
`/api/payload-jobs/run` on serverless (e.g. a Vercel cron). Without either, the site still updates on every
|
|
59
|
+
hub ping and on first boot when the local copy is empty.
|
|
60
|
+
|
|
61
|
+
### Help in other places
|
|
62
|
+
|
|
63
|
+
Add the client component wherever an admin component path is accepted:
|
|
64
|
+
|
|
65
|
+
```ts
|
|
66
|
+
{ path: '@foundrykit/guides-plugin/client#Help', clientProps: { context: 'media.create' } }
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
A guide shows there when its **help contexts** (set in the hub, or on a site guide) include that key.
|
|
70
|
+
|
|
71
|
+
## How it talks to the hub
|
|
72
|
+
|
|
73
|
+
| | |
|
|
74
|
+
| --- | --- |
|
|
75
|
+
| Pull | `GET <hub>/api/sites/feed?pluginVersion=…&features=…` with `Authorization: sites API-Key <key>` |
|
|
76
|
+
| Ping | The hub POSTs to `/api/guides/sync` with `x-guides-signature: sha256=<HMAC of the body, keyed with the site key>`. Anything else gets 401. |
|
|
77
|
+
| Site guides | Publish → `POST`/`PATCH <hub>/api/guides[/:id]`; delete → `DELETE`. |
|
|
78
|
+
|
|
79
|
+
## Development
|
|
80
|
+
|
|
81
|
+
```bash
|
|
82
|
+
pnpm install
|
|
83
|
+
pnpm dev # dev app on :3000 (set GUIDES_HUB_URL / GUIDES_HUB_KEY to point at a hub)
|
|
84
|
+
pnpm test # unit + integration (SQLite in memory, hub stubbed)
|
|
85
|
+
pnpm build
|
|
86
|
+
```
|
|
87
|
+
|
|
88
|
+
## Releasing
|
|
89
|
+
|
|
90
|
+
Run `pnpm release` on `prod`. It bumps the version, updates the changelog and pushes a `v*` tag.
|
|
91
|
+
The tag triggers `.github/workflows/publish.yml`, which publishes to npm through trusted
|
|
92
|
+
publishing, so no npm token is stored locally or in GitHub.
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { CollectionConfig } from 'payload';
|
|
2
|
+
import { type ResolvedConfig } from '../hub.js';
|
|
3
|
+
/**
|
|
4
|
+
* The read-only local copy of the guides this site is entitled to. Only sync writes it, so help
|
|
5
|
+
* works when the hub is down and nothing waits on a network call. People read it through the
|
|
6
|
+
* Guides page and Help buttons, not the collection list.
|
|
7
|
+
*/
|
|
8
|
+
export declare const guidesCollection: (config: ResolvedConfig) => CollectionConfig;
|
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
import { GUIDES_SLUG, SIGNATURE_HEADER, verifySignature } from '../hub.js';
|
|
2
|
+
import { syncGuides } from '../sync.js';
|
|
3
|
+
/** POST /api/guides/sync: the hub's signed "guides changed" ping. Pulls this site's feed. */ const syncEndpoint = (config)=>({
|
|
4
|
+
path: '/sync',
|
|
5
|
+
method: 'post',
|
|
6
|
+
handler: async (req)=>{
|
|
7
|
+
const body = await req.text?.() ?? '';
|
|
8
|
+
if (!config.siteKey || !verifySignature(config.siteKey, body, req.headers.get(SIGNATURE_HEADER))) {
|
|
9
|
+
return Response.json({
|
|
10
|
+
error: 'Signature does not match this site’s guides key.'
|
|
11
|
+
}, {
|
|
12
|
+
status: 401
|
|
13
|
+
});
|
|
14
|
+
}
|
|
15
|
+
try {
|
|
16
|
+
return Response.json(await syncGuides(req.payload, config));
|
|
17
|
+
} catch (err) {
|
|
18
|
+
req.payload.logger.error({
|
|
19
|
+
err
|
|
20
|
+
}, 'Guides sync failed');
|
|
21
|
+
return Response.json({
|
|
22
|
+
error: 'Could not sync from the guides hub.'
|
|
23
|
+
}, {
|
|
24
|
+
status: 502
|
|
25
|
+
});
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
});
|
|
29
|
+
/**
|
|
30
|
+
* The read-only local copy of the guides this site is entitled to. Only sync writes it, so help
|
|
31
|
+
* works when the hub is down and nothing waits on a network call. People read it through the
|
|
32
|
+
* Guides page and Help buttons, not the collection list.
|
|
33
|
+
*/ export const guidesCollection = (config)=>({
|
|
34
|
+
slug: GUIDES_SLUG,
|
|
35
|
+
labels: {
|
|
36
|
+
singular: 'Guide',
|
|
37
|
+
plural: 'Guides'
|
|
38
|
+
},
|
|
39
|
+
admin: {
|
|
40
|
+
hidden: true,
|
|
41
|
+
useAsTitle: 'title'
|
|
42
|
+
},
|
|
43
|
+
access: {
|
|
44
|
+
read: ({ req: { user } })=>Boolean(user),
|
|
45
|
+
create: ()=>false,
|
|
46
|
+
update: ()=>false,
|
|
47
|
+
delete: ()=>false
|
|
48
|
+
},
|
|
49
|
+
endpoints: [
|
|
50
|
+
syncEndpoint(config)
|
|
51
|
+
],
|
|
52
|
+
fields: [
|
|
53
|
+
{
|
|
54
|
+
name: 'hubId',
|
|
55
|
+
type: 'text',
|
|
56
|
+
required: true,
|
|
57
|
+
unique: true,
|
|
58
|
+
index: true
|
|
59
|
+
},
|
|
60
|
+
{
|
|
61
|
+
name: 'title',
|
|
62
|
+
type: 'text',
|
|
63
|
+
required: true
|
|
64
|
+
},
|
|
65
|
+
{
|
|
66
|
+
name: 'slug',
|
|
67
|
+
type: 'text',
|
|
68
|
+
index: true
|
|
69
|
+
},
|
|
70
|
+
{
|
|
71
|
+
name: 'summary',
|
|
72
|
+
type: 'textarea'
|
|
73
|
+
},
|
|
74
|
+
{
|
|
75
|
+
name: 'scope',
|
|
76
|
+
type: 'select',
|
|
77
|
+
options: [
|
|
78
|
+
{
|
|
79
|
+
label: 'General',
|
|
80
|
+
value: 'general'
|
|
81
|
+
},
|
|
82
|
+
{
|
|
83
|
+
label: 'This site',
|
|
84
|
+
value: 'site'
|
|
85
|
+
}
|
|
86
|
+
]
|
|
87
|
+
},
|
|
88
|
+
{
|
|
89
|
+
name: 'topic',
|
|
90
|
+
type: 'group',
|
|
91
|
+
fields: [
|
|
92
|
+
{
|
|
93
|
+
name: 'title',
|
|
94
|
+
type: 'text'
|
|
95
|
+
},
|
|
96
|
+
{
|
|
97
|
+
name: 'order',
|
|
98
|
+
type: 'number'
|
|
99
|
+
}
|
|
100
|
+
]
|
|
101
|
+
},
|
|
102
|
+
{
|
|
103
|
+
name: 'helpContexts',
|
|
104
|
+
type: 'text',
|
|
105
|
+
hasMany: true,
|
|
106
|
+
index: true
|
|
107
|
+
},
|
|
108
|
+
{
|
|
109
|
+
name: 'order',
|
|
110
|
+
type: 'number'
|
|
111
|
+
},
|
|
112
|
+
// Lexical JSON from the hub, rendered as-is. Not a richText field: its images and nodes
|
|
113
|
+
// belong to the hub, so this site's editor shouldn't validate or populate them.
|
|
114
|
+
{
|
|
115
|
+
name: 'body',
|
|
116
|
+
type: 'json'
|
|
117
|
+
},
|
|
118
|
+
{
|
|
119
|
+
name: 'bodyText',
|
|
120
|
+
type: 'text'
|
|
121
|
+
},
|
|
122
|
+
{
|
|
123
|
+
name: 'hubUpdatedAt',
|
|
124
|
+
type: 'text'
|
|
125
|
+
}
|
|
126
|
+
]
|
|
127
|
+
});
|
|
128
|
+
|
|
129
|
+
//# sourceMappingURL=guides.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/collections/guides.ts"],"sourcesContent":["import type { CollectionConfig, Endpoint } from 'payload'\n\nimport { GUIDES_SLUG, SIGNATURE_HEADER, type ResolvedConfig, verifySignature } from '../hub.js'\nimport { syncGuides } from '../sync.js'\n\n/** POST /api/guides/sync: the hub's signed \"guides changed\" ping. Pulls this site's feed. */\nconst syncEndpoint = (config: ResolvedConfig): Endpoint => ({\n path: '/sync',\n method: 'post',\n handler: async (req) => {\n const body = (await req.text?.()) ?? ''\n if (!config.siteKey || !verifySignature(config.siteKey, body, req.headers.get(SIGNATURE_HEADER))) {\n return Response.json({ error: 'Signature does not match this site’s guides key.' }, { status: 401 })\n }\n try {\n return Response.json(await syncGuides(req.payload, config))\n } catch (err) {\n req.payload.logger.error({ err }, 'Guides sync failed')\n return Response.json({ error: 'Could not sync from the guides hub.' }, { status: 502 })\n }\n },\n})\n\n/**\n * The read-only local copy of the guides this site is entitled to. Only sync writes it, so help\n * works when the hub is down and nothing waits on a network call. People read it through the\n * Guides page and Help buttons, not the collection list.\n */\nexport const guidesCollection = (config: ResolvedConfig): CollectionConfig => ({\n slug: GUIDES_SLUG,\n labels: { singular: 'Guide', plural: 'Guides' },\n admin: { hidden: true, useAsTitle: 'title' },\n access: {\n read: ({ req: { user } }) => Boolean(user),\n create: () => false,\n update: () => false,\n delete: () => false,\n },\n endpoints: [syncEndpoint(config)],\n fields: [\n { name: 'hubId', type: 'text', required: true, unique: true, index: true },\n { name: 'title', type: 'text', required: true },\n { name: 'slug', type: 'text', index: true },\n { name: 'summary', type: 'textarea' },\n {\n name: 'scope',\n type: 'select',\n options: [\n { label: 'General', value: 'general' },\n { label: 'This site', value: 'site' },\n ],\n },\n {\n name: 'topic',\n type: 'group',\n fields: [\n { name: 'title', type: 'text' },\n { name: 'order', type: 'number' },\n ],\n },\n { name: 'helpContexts', type: 'text', hasMany: true, index: true },\n { name: 'order', type: 'number' },\n // Lexical JSON from the hub, rendered as-is. Not a richText field: its images and nodes\n // belong to the hub, so this site's editor shouldn't validate or populate them.\n { name: 'body', type: 'json' },\n { name: 'bodyText', type: 'text' },\n { name: 'hubUpdatedAt', type: 'text' },\n ],\n})\n"],"names":["GUIDES_SLUG","SIGNATURE_HEADER","verifySignature","syncGuides","syncEndpoint","config","path","method","handler","req","body","text","siteKey","headers","get","Response","json","error","status","payload","err","logger","guidesCollection","slug","labels","singular","plural","admin","hidden","useAsTitle","access","read","user","Boolean","create","update","delete","endpoints","fields","name","type","required","unique","index","options","label","value","hasMany"],"mappings":"AAEA,SAASA,WAAW,EAAEC,gBAAgB,EAAuBC,eAAe,QAAQ,YAAW;AAC/F,SAASC,UAAU,QAAQ,aAAY;AAEvC,2FAA2F,GAC3F,MAAMC,eAAe,CAACC,SAAsC,CAAA;QAC1DC,MAAM;QACNC,QAAQ;QACRC,SAAS,OAAOC;YACd,MAAMC,OAAO,AAAC,MAAMD,IAAIE,IAAI,QAAS;YACrC,IAAI,CAACN,OAAOO,OAAO,IAAI,CAACV,gBAAgBG,OAAOO,OAAO,EAAEF,MAAMD,IAAII,OAAO,CAACC,GAAG,CAACb,oBAAoB;gBAChG,OAAOc,SAASC,IAAI,CAAC;oBAAEC,OAAO;gBAAmD,GAAG;oBAAEC,QAAQ;gBAAI;YACpG;YACA,IAAI;gBACF,OAAOH,SAASC,IAAI,CAAC,MAAMb,WAAWM,IAAIU,OAAO,EAAEd;YACrD,EAAE,OAAOe,KAAK;gBACZX,IAAIU,OAAO,CAACE,MAAM,CAACJ,KAAK,CAAC;oBAAEG;gBAAI,GAAG;gBAClC,OAAOL,SAASC,IAAI,CAAC;oBAAEC,OAAO;gBAAsC,GAAG;oBAAEC,QAAQ;gBAAI;YACvF;QACF;IACF,CAAA;AAEA;;;;CAIC,GACD,OAAO,MAAMI,mBAAmB,CAACjB,SAA8C,CAAA;QAC7EkB,MAAMvB;QACNwB,QAAQ;YAAEC,UAAU;YAASC,QAAQ;QAAS;QAC9CC,OAAO;YAAEC,QAAQ;YAAMC,YAAY;QAAQ;QAC3CC,QAAQ;YACNC,MAAM,CAAC,EAAEtB,KAAK,EAAEuB,IAAI,EAAE,EAAE,GAAKC,QAAQD;YACrCE,QAAQ,IAAM;YACdC,QAAQ,IAAM;YACdC,QAAQ,IAAM;QAChB;QACAC,WAAW;YAACjC,aAAaC;SAAQ;QACjCiC,QAAQ;YACN;gBAAEC,MAAM;gBAASC,MAAM;gBAAQC,UAAU;gBAAMC,QAAQ;gBAAMC,OAAO;YAAK;YACzE;gBAAEJ,MAAM;gBAASC,MAAM;gBAAQC,UAAU;YAAK;YAC9C;gBAAEF,MAAM;gBAAQC,MAAM;gBAAQG,OAAO;YAAK;YAC1C;gBAAEJ,MAAM;gBAAWC,MAAM;YAAW;YACpC;gBACED,MAAM;gBACNC,MAAM;gBACNI,SAAS;oBACP;wBAAEC,OAAO;wBAAWC,OAAO;oBAAU;oBACrC;wBAAED,OAAO;wBAAaC,OAAO;oBAAO;iBACrC;YACH;YACA;gBACEP,MAAM;gBACNC,MAAM;gBACNF,QAAQ;oBACN;wBAAEC,MAAM;wBAASC,MAAM;oBAAO;oBAC9B;wBAAED,MAAM;wBAASC,MAAM;oBAAS;iBACjC;YACH;YACA;gBAAED,MAAM;gBAAgBC,MAAM;gBAAQO,SAAS;gBAAMJ,OAAO;YAAK;YACjE;gBAAEJ,MAAM;gBAASC,MAAM;YAAS;YAChC,wFAAwF;YACxF,gFAAgF;YAChF;gBAAED,MAAM;gBAAQC,MAAM;YAAO;YAC7B;gBAAED,MAAM;gBAAYC,MAAM;YAAO;YACjC;gBAAED,MAAM;gBAAgBC,MAAM;YAAO;SACtC;IACH,CAAA,EAAE"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { type CollectionConfig } from 'payload';
|
|
2
|
+
import { type ResolvedConfig } from '../hub.js';
|
|
3
|
+
/**
|
|
4
|
+
* Where Umi staff write guides for this site only (e.g. custom logic built for this client).
|
|
5
|
+
* Hidden from everyone who can't author.
|
|
6
|
+
*/
|
|
7
|
+
export declare const siteGuidesCollection: (config: ResolvedConfig) => CollectionConfig;
|
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
import { LinkFeature, lexicalEditor } from '@payloadcms/richtext-lexical';
|
|
2
|
+
import { APIError } from 'payload';
|
|
3
|
+
import { hubFetch, SITE_GUIDES_SLUG } from '../hub.js';
|
|
4
|
+
const unreachable = (status)=>new APIError(`Couldn't save this guide to the guides hub${status ? ` (it answered ${status})` : ''}, so nothing was published. Save it as a draft and try again later.`, 502);
|
|
5
|
+
/**
|
|
6
|
+
* Publishing sends the guide straight to the hub, which pins it to this site and sends it back
|
|
7
|
+
* down in the next sync. Drafts stay local, so if the hub is down the author's work is kept.
|
|
8
|
+
*/ const publishToHub = (config)=>async ({ data, originalDoc })=>{
|
|
9
|
+
if (data._status !== 'published') return data;
|
|
10
|
+
const doc = {
|
|
11
|
+
...originalDoc,
|
|
12
|
+
...data
|
|
13
|
+
};
|
|
14
|
+
const hubId = doc.hubId;
|
|
15
|
+
const res = await hubFetch(config, hubId ? `/api/guides/${hubId}` : '/api/guides', {
|
|
16
|
+
method: hubId ? 'PATCH' : 'POST',
|
|
17
|
+
body: JSON.stringify({
|
|
18
|
+
title: doc.title,
|
|
19
|
+
summary: doc.summary,
|
|
20
|
+
helpContexts: doc.helpContexts ?? [],
|
|
21
|
+
body: doc.body,
|
|
22
|
+
_status: 'published'
|
|
23
|
+
})
|
|
24
|
+
}).catch(()=>null);
|
|
25
|
+
if (!res?.ok) throw unreachable(res?.status);
|
|
26
|
+
data.hubId = String((await res.json()).doc.id);
|
|
27
|
+
return data;
|
|
28
|
+
};
|
|
29
|
+
const deleteFromHub = (config)=>async ({ id, req })=>{
|
|
30
|
+
const doc = await req.payload.findByID({
|
|
31
|
+
collection: SITE_GUIDES_SLUG,
|
|
32
|
+
id,
|
|
33
|
+
depth: 0,
|
|
34
|
+
req,
|
|
35
|
+
draft: true
|
|
36
|
+
});
|
|
37
|
+
const hubId = doc.hubId;
|
|
38
|
+
if (!hubId) return;
|
|
39
|
+
const res = await hubFetch(config, `/api/guides/${hubId}`, {
|
|
40
|
+
method: 'DELETE'
|
|
41
|
+
}).catch(()=>null);
|
|
42
|
+
if (!res?.ok && res?.status !== 404) throw unreachable(res?.status);
|
|
43
|
+
};
|
|
44
|
+
/**
|
|
45
|
+
* Where Umi staff write guides for this site only (e.g. custom logic built for this client).
|
|
46
|
+
* Hidden from everyone who can't author.
|
|
47
|
+
*/ export const siteGuidesCollection = (config)=>{
|
|
48
|
+
const canAuthor = ({ req: { user } })=>config.canAuthor(user);
|
|
49
|
+
return {
|
|
50
|
+
slug: SITE_GUIDES_SLUG,
|
|
51
|
+
labels: {
|
|
52
|
+
singular: 'Site guide',
|
|
53
|
+
plural: 'Site guides'
|
|
54
|
+
},
|
|
55
|
+
admin: {
|
|
56
|
+
useAsTitle: 'title',
|
|
57
|
+
defaultColumns: [
|
|
58
|
+
'title',
|
|
59
|
+
'_status',
|
|
60
|
+
'updatedAt'
|
|
61
|
+
],
|
|
62
|
+
description: 'Guides for this site only. Publishing saves them to the Umi guides hub; they then show under Guides and on Help buttons.',
|
|
63
|
+
hidden: ({ user })=>!config.canAuthor(user)
|
|
64
|
+
},
|
|
65
|
+
access: {
|
|
66
|
+
read: canAuthor,
|
|
67
|
+
create: canAuthor,
|
|
68
|
+
update: canAuthor,
|
|
69
|
+
delete: canAuthor,
|
|
70
|
+
readVersions: canAuthor
|
|
71
|
+
},
|
|
72
|
+
hooks: {
|
|
73
|
+
beforeChange: [
|
|
74
|
+
publishToHub(config)
|
|
75
|
+
],
|
|
76
|
+
beforeDelete: [
|
|
77
|
+
deleteFromHub(config)
|
|
78
|
+
]
|
|
79
|
+
},
|
|
80
|
+
versions: {
|
|
81
|
+
drafts: true
|
|
82
|
+
},
|
|
83
|
+
fields: [
|
|
84
|
+
{
|
|
85
|
+
name: 'title',
|
|
86
|
+
type: 'text',
|
|
87
|
+
required: true
|
|
88
|
+
},
|
|
89
|
+
{
|
|
90
|
+
name: 'summary',
|
|
91
|
+
type: 'textarea',
|
|
92
|
+
required: true,
|
|
93
|
+
maxLength: 240,
|
|
94
|
+
admin: {
|
|
95
|
+
description: 'One or two sentences, shown in lists, search results and the Help panel.'
|
|
96
|
+
}
|
|
97
|
+
},
|
|
98
|
+
{
|
|
99
|
+
name: 'body',
|
|
100
|
+
type: 'richText',
|
|
101
|
+
required: true,
|
|
102
|
+
// The hub stores this body, so nothing that points at this site's documents or uploads.
|
|
103
|
+
editor: lexicalEditor({
|
|
104
|
+
features: ({ defaultFeatures })=>[
|
|
105
|
+
...defaultFeatures.filter((f)=>![
|
|
106
|
+
'link',
|
|
107
|
+
'relationship',
|
|
108
|
+
'upload',
|
|
109
|
+
'blocks'
|
|
110
|
+
].includes(f.key)),
|
|
111
|
+
LinkFeature({
|
|
112
|
+
enabledCollections: []
|
|
113
|
+
})
|
|
114
|
+
]
|
|
115
|
+
})
|
|
116
|
+
},
|
|
117
|
+
{
|
|
118
|
+
name: 'helpContexts',
|
|
119
|
+
type: 'text',
|
|
120
|
+
hasMany: true,
|
|
121
|
+
admin: {
|
|
122
|
+
position: 'sidebar',
|
|
123
|
+
description: 'Where Help lists this guide: a collection or global slug (e.g. offers), or a finer key.'
|
|
124
|
+
}
|
|
125
|
+
},
|
|
126
|
+
{
|
|
127
|
+
name: 'hubId',
|
|
128
|
+
type: 'text',
|
|
129
|
+
admin: {
|
|
130
|
+
position: 'sidebar',
|
|
131
|
+
readOnly: true,
|
|
132
|
+
description: 'Set once the guide is published to the hub.'
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
]
|
|
136
|
+
};
|
|
137
|
+
};
|
|
138
|
+
|
|
139
|
+
//# sourceMappingURL=siteGuides.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/collections/siteGuides.ts"],"sourcesContent":["import { LinkFeature, lexicalEditor } from '@payloadcms/richtext-lexical'\nimport {\n APIError,\n type CollectionBeforeChangeHook,\n type CollectionBeforeDeleteHook,\n type CollectionConfig,\n} from 'payload'\n\nimport { hubFetch, type ResolvedConfig, SITE_GUIDES_SLUG } from '../hub.js'\n\nconst unreachable = (status?: number) =>\n new APIError(\n `Couldn't save this guide to the guides hub${status ? ` (it answered ${status})` : ''}, so nothing was published. Save it as a draft and try again later.`,\n 502,\n )\n\n/**\n * Publishing sends the guide straight to the hub, which pins it to this site and sends it back\n * down in the next sync. Drafts stay local, so if the hub is down the author's work is kept.\n */\nconst publishToHub =\n (config: ResolvedConfig): CollectionBeforeChangeHook =>\n async ({ data, originalDoc }) => {\n if (data._status !== 'published') return data\n const doc = { ...originalDoc, ...data }\n const hubId = doc.hubId as string | undefined\n const res = await hubFetch(config, hubId ? `/api/guides/${hubId}` : '/api/guides', {\n method: hubId ? 'PATCH' : 'POST',\n body: JSON.stringify({\n title: doc.title,\n summary: doc.summary,\n helpContexts: doc.helpContexts ?? [],\n body: doc.body,\n _status: 'published',\n }),\n }).catch(() => null)\n if (!res?.ok) throw unreachable(res?.status)\n data.hubId = String(((await res.json()) as { doc: { id: number | string } }).doc.id)\n return data\n }\n\nconst deleteFromHub =\n (config: ResolvedConfig): CollectionBeforeDeleteHook =>\n async ({ id, req }) => {\n const doc = await req.payload.findByID({ collection: SITE_GUIDES_SLUG as never, id, depth: 0, req, draft: true })\n const hubId = (doc as { hubId?: string }).hubId\n if (!hubId) return\n const res = await hubFetch(config, `/api/guides/${hubId}`, { method: 'DELETE' }).catch(() => null)\n if (!res?.ok && res?.status !== 404) throw unreachable(res?.status)\n }\n\n/**\n * Where Umi staff write guides for this site only (e.g. custom logic built for this client).\n * Hidden from everyone who can't author.\n */\nexport const siteGuidesCollection = (config: ResolvedConfig): CollectionConfig => {\n const canAuthor = ({ req: { user } }: { req: { user: unknown } }) => config.canAuthor(user)\n return {\n slug: SITE_GUIDES_SLUG,\n labels: { singular: 'Site guide', plural: 'Site guides' },\n admin: {\n useAsTitle: 'title',\n defaultColumns: ['title', '_status', 'updatedAt'],\n description:\n 'Guides for this site only. Publishing saves them to the Umi guides hub; they then show under Guides and on Help buttons.',\n hidden: ({ user }) => !config.canAuthor(user),\n },\n access: { read: canAuthor, create: canAuthor, update: canAuthor, delete: canAuthor, readVersions: canAuthor },\n hooks: { beforeChange: [publishToHub(config)], beforeDelete: [deleteFromHub(config)] },\n versions: { drafts: true },\n fields: [\n { name: 'title', type: 'text', required: true },\n {\n name: 'summary',\n type: 'textarea',\n required: true,\n maxLength: 240,\n admin: { description: 'One or two sentences, shown in lists, search results and the Help panel.' },\n },\n {\n name: 'body',\n type: 'richText',\n required: true,\n // The hub stores this body, so nothing that points at this site's documents or uploads.\n editor: lexicalEditor({\n features: ({ defaultFeatures }) => [\n ...defaultFeatures.filter((f) => !['link', 'relationship', 'upload', 'blocks'].includes(f.key)),\n LinkFeature({ enabledCollections: [] }),\n ],\n }),\n },\n {\n name: 'helpContexts',\n type: 'text',\n hasMany: true,\n admin: {\n position: 'sidebar',\n description: 'Where Help lists this guide: a collection or global slug (e.g. offers), or a finer key.',\n },\n },\n {\n name: 'hubId',\n type: 'text',\n admin: { position: 'sidebar', readOnly: true, description: 'Set once the guide is published to the hub.' },\n },\n ],\n }\n}\n"],"names":["LinkFeature","lexicalEditor","APIError","hubFetch","SITE_GUIDES_SLUG","unreachable","status","publishToHub","config","data","originalDoc","_status","doc","hubId","res","method","body","JSON","stringify","title","summary","helpContexts","catch","ok","String","json","id","deleteFromHub","req","payload","findByID","collection","depth","draft","siteGuidesCollection","canAuthor","user","slug","labels","singular","plural","admin","useAsTitle","defaultColumns","description","hidden","access","read","create","update","delete","readVersions","hooks","beforeChange","beforeDelete","versions","drafts","fields","name","type","required","maxLength","editor","features","defaultFeatures","filter","f","includes","key","enabledCollections","hasMany","position","readOnly"],"mappings":"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"}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
export type LocalGuide = {
|
|
2
|
+
id: number | string;
|
|
3
|
+
hubId: string;
|
|
4
|
+
title: string;
|
|
5
|
+
slug?: string | null;
|
|
6
|
+
summary?: string | null;
|
|
7
|
+
scope?: 'general' | 'site' | null;
|
|
8
|
+
topic?: {
|
|
9
|
+
title?: string | null;
|
|
10
|
+
order?: number | null;
|
|
11
|
+
} | null;
|
|
12
|
+
order?: number | null;
|
|
13
|
+
body?: unknown;
|
|
14
|
+
bodyText?: string | null;
|
|
15
|
+
hubUpdatedAt?: string | null;
|
|
16
|
+
};
|
|
17
|
+
/**
|
|
18
|
+
* One guide as a readable article. Bodies come from the hub, so images load from the hub's
|
|
19
|
+
* storage and the default Lexical converters are enough (hub guides only allow external links).
|
|
20
|
+
*/
|
|
21
|
+
export declare function GuideArticle({ guide, canAuthor }: {
|
|
22
|
+
guide: LocalGuide;
|
|
23
|
+
canAuthor: boolean;
|
|
24
|
+
}): import("react/jsx-runtime").JSX.Element;
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
2
|
+
import { RichText } from '@payloadcms/richtext-lexical/react';
|
|
3
|
+
import { SITE_GUIDES_SLUG } from '../hub.js';
|
|
4
|
+
const formatDate = (iso)=>new Date(iso).toLocaleDateString('en-GB', {
|
|
5
|
+
day: 'numeric',
|
|
6
|
+
month: 'short',
|
|
7
|
+
year: 'numeric',
|
|
8
|
+
timeZone: 'Europe/London'
|
|
9
|
+
});
|
|
10
|
+
// The admin has no type styles, so prose spacing is set here.
|
|
11
|
+
const prose = `
|
|
12
|
+
.guide-article__body { font-size: 1rem; line-height: 1.6; }
|
|
13
|
+
.guide-article__body h2 { margin: 1.5rem 0 0.5rem; }
|
|
14
|
+
.guide-article__body p { margin: 0.5rem 0; }
|
|
15
|
+
.guide-article__body ol { list-style: decimal; padding-left: 1.5rem; }
|
|
16
|
+
.guide-article__body ul { list-style: disc; padding-left: 1.5rem; }
|
|
17
|
+
.guide-article__body li { margin-bottom: 0.25rem; }
|
|
18
|
+
.guide-article__body img { max-width: 100%; height: auto; margin: 1rem 0; border-radius: 6px; border: 1px solid var(--theme-border-color); }
|
|
19
|
+
`;
|
|
20
|
+
/**
|
|
21
|
+
* One guide as a readable article. Bodies come from the hub, so images load from the hub's
|
|
22
|
+
* storage and the default Lexical converters are enough (hub guides only allow external links).
|
|
23
|
+
*/ export function GuideArticle({ guide, canAuthor }) {
|
|
24
|
+
return /*#__PURE__*/ _jsxs("article", {
|
|
25
|
+
style: {
|
|
26
|
+
display: 'flex',
|
|
27
|
+
flexDirection: 'column',
|
|
28
|
+
gap: '1rem',
|
|
29
|
+
maxWidth: '48rem'
|
|
30
|
+
},
|
|
31
|
+
children: [
|
|
32
|
+
/*#__PURE__*/ _jsx("style", {
|
|
33
|
+
children: prose
|
|
34
|
+
}),
|
|
35
|
+
/*#__PURE__*/ _jsxs("header", {
|
|
36
|
+
style: {
|
|
37
|
+
display: 'flex',
|
|
38
|
+
flexDirection: 'column',
|
|
39
|
+
gap: '0.25rem'
|
|
40
|
+
},
|
|
41
|
+
children: [
|
|
42
|
+
/*#__PURE__*/ _jsx("h2", {
|
|
43
|
+
style: {
|
|
44
|
+
margin: 0
|
|
45
|
+
},
|
|
46
|
+
children: guide.title
|
|
47
|
+
}),
|
|
48
|
+
/*#__PURE__*/ _jsxs("p", {
|
|
49
|
+
style: {
|
|
50
|
+
margin: 0,
|
|
51
|
+
color: 'var(--theme-elevation-600)',
|
|
52
|
+
fontSize: '0.875rem'
|
|
53
|
+
},
|
|
54
|
+
children: [
|
|
55
|
+
guide.hubUpdatedAt ? `Updated ${formatDate(guide.hubUpdatedAt)}` : null,
|
|
56
|
+
canAuthor && guide.scope === 'site' && /*#__PURE__*/ _jsxs(_Fragment, {
|
|
57
|
+
children: [
|
|
58
|
+
' · ',
|
|
59
|
+
/*#__PURE__*/ _jsx("a", {
|
|
60
|
+
href: `/admin/collections/${SITE_GUIDES_SLUG}?where[hubId][equals]=${guide.hubId}`,
|
|
61
|
+
children: "Edit this guide"
|
|
62
|
+
})
|
|
63
|
+
]
|
|
64
|
+
})
|
|
65
|
+
]
|
|
66
|
+
})
|
|
67
|
+
]
|
|
68
|
+
}),
|
|
69
|
+
/*#__PURE__*/ _jsx("div", {
|
|
70
|
+
className: "guide-article__body",
|
|
71
|
+
children: guide.body ? /*#__PURE__*/ _jsx(RichText, {
|
|
72
|
+
data: guide.body
|
|
73
|
+
}) : null
|
|
74
|
+
})
|
|
75
|
+
]
|
|
76
|
+
});
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
//# sourceMappingURL=GuideArticle.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/components/GuideArticle.tsx"],"sourcesContent":["import type { SerializedEditorState } from '@payloadcms/richtext-lexical/lexical'\nimport { RichText } from '@payloadcms/richtext-lexical/react'\n\nimport { SITE_GUIDES_SLUG } from '../hub.js'\n\nexport type LocalGuide = {\n id: number | string\n hubId: string\n title: string\n slug?: string | null\n summary?: string | null\n scope?: 'general' | 'site' | null\n topic?: { title?: string | null; order?: number | null } | null\n order?: number | null\n body?: unknown\n bodyText?: string | null\n hubUpdatedAt?: string | null\n}\n\nconst formatDate = (iso: string) =>\n new Date(iso).toLocaleDateString('en-GB', { day: 'numeric', month: 'short', year: 'numeric', timeZone: 'Europe/London' })\n\n// The admin has no type styles, so prose spacing is set here.\nconst prose = `\n.guide-article__body { font-size: 1rem; line-height: 1.6; }\n.guide-article__body h2 { margin: 1.5rem 0 0.5rem; }\n.guide-article__body p { margin: 0.5rem 0; }\n.guide-article__body ol { list-style: decimal; padding-left: 1.5rem; }\n.guide-article__body ul { list-style: disc; padding-left: 1.5rem; }\n.guide-article__body li { margin-bottom: 0.25rem; }\n.guide-article__body img { max-width: 100%; height: auto; margin: 1rem 0; border-radius: 6px; border: 1px solid var(--theme-border-color); }\n`\n\n/**\n * One guide as a readable article. Bodies come from the hub, so images load from the hub's\n * storage and the default Lexical converters are enough (hub guides only allow external links).\n */\nexport function GuideArticle({ guide, canAuthor }: { guide: LocalGuide; canAuthor: boolean }) {\n return (\n <article style={{ display: 'flex', flexDirection: 'column', gap: '1rem', maxWidth: '48rem' }}>\n <style>{prose}</style>\n <header style={{ display: 'flex', flexDirection: 'column', gap: '0.25rem' }}>\n <h2 style={{ margin: 0 }}>{guide.title}</h2>\n <p style={{ margin: 0, color: 'var(--theme-elevation-600)', fontSize: '0.875rem' }}>\n {guide.hubUpdatedAt ? `Updated ${formatDate(guide.hubUpdatedAt)}` : null}\n {canAuthor && guide.scope === 'site' && (\n <>\n {' · '}\n <a href={`/admin/collections/${SITE_GUIDES_SLUG}?where[hubId][equals]=${guide.hubId}`}>Edit this guide</a>\n </>\n )}\n </p>\n </header>\n <div className=\"guide-article__body\">\n {guide.body ? <RichText data={guide.body as SerializedEditorState} /> : null}\n </div>\n </article>\n )\n}\n"],"names":["RichText","SITE_GUIDES_SLUG","formatDate","iso","Date","toLocaleDateString","day","month","year","timeZone","prose","GuideArticle","guide","canAuthor","article","style","display","flexDirection","gap","maxWidth","header","h2","margin","title","p","color","fontSize","hubUpdatedAt","scope","a","href","hubId","div","className","body","data"],"mappings":";AACA,SAASA,QAAQ,QAAQ,qCAAoC;AAE7D,SAASC,gBAAgB,QAAQ,YAAW;AAgB5C,MAAMC,aAAa,CAACC,MAClB,IAAIC,KAAKD,KAAKE,kBAAkB,CAAC,SAAS;QAAEC,KAAK;QAAWC,OAAO;QAASC,MAAM;QAAWC,UAAU;IAAgB;AAEzH,8DAA8D;AAC9D,MAAMC,QAAQ,CAAC;;;;;;;;AAQf,CAAC;AAED;;;CAGC,GACD,OAAO,SAASC,aAAa,EAAEC,KAAK,EAAEC,SAAS,EAA6C;IAC1F,qBACE,MAACC;QAAQC,OAAO;YAAEC,SAAS;YAAQC,eAAe;YAAUC,KAAK;YAAQC,UAAU;QAAQ;;0BACzF,KAACJ;0BAAOL;;0BACR,MAACU;gBAAOL,OAAO;oBAAEC,SAAS;oBAAQC,eAAe;oBAAUC,KAAK;gBAAU;;kCACxE,KAACG;wBAAGN,OAAO;4BAAEO,QAAQ;wBAAE;kCAAIV,MAAMW,KAAK;;kCACtC,MAACC;wBAAET,OAAO;4BAAEO,QAAQ;4BAAGG,OAAO;4BAA8BC,UAAU;wBAAW;;4BAC9Ed,MAAMe,YAAY,GAAG,CAAC,QAAQ,EAAEzB,WAAWU,MAAMe,YAAY,GAAG,GAAG;4BACnEd,aAAaD,MAAMgB,KAAK,KAAK,wBAC5B;;oCACG;kDACD,KAACC;wCAAEC,MAAM,CAAC,mBAAmB,EAAE7B,iBAAiB,sBAAsB,EAAEW,MAAMmB,KAAK,EAAE;kDAAE;;;;;;;;0BAK/F,KAACC;gBAAIC,WAAU;0BACZrB,MAAMsB,IAAI,iBAAG,KAAClC;oBAASmC,MAAMvB,MAAMsB,IAAI;qBAAgC;;;;AAIhF"}
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
|
+
import { useMemo, useState } from 'react';
|
|
4
|
+
import { searchGuides } from '../searchGuides.js';
|
|
5
|
+
const muted = {
|
|
6
|
+
color: 'var(--theme-elevation-600)',
|
|
7
|
+
fontSize: '0.875rem',
|
|
8
|
+
margin: 0
|
|
9
|
+
};
|
|
10
|
+
/** Search box over the (small) list of guides the server already fetched for this user. */ export function GuideSearch({ guides }) {
|
|
11
|
+
const [query, setQuery] = useState('');
|
|
12
|
+
const results = useMemo(()=>searchGuides(guides, query), [
|
|
13
|
+
guides,
|
|
14
|
+
query
|
|
15
|
+
]);
|
|
16
|
+
const searching = query.trim().length > 0;
|
|
17
|
+
return /*#__PURE__*/ _jsxs("div", {
|
|
18
|
+
style: {
|
|
19
|
+
display: 'flex',
|
|
20
|
+
flexDirection: 'column',
|
|
21
|
+
gap: '0.75rem'
|
|
22
|
+
},
|
|
23
|
+
children: [
|
|
24
|
+
/*#__PURE__*/ _jsx("input", {
|
|
25
|
+
type: "search",
|
|
26
|
+
value: query,
|
|
27
|
+
onChange: (e)=>setQuery(e.target.value),
|
|
28
|
+
placeholder: 'Search the guides, e.g. "how do I upload an image"',
|
|
29
|
+
"aria-label": "Search the guides",
|
|
30
|
+
style: {
|
|
31
|
+
width: '100%',
|
|
32
|
+
padding: '0.5rem 0.75rem',
|
|
33
|
+
fontSize: '1rem',
|
|
34
|
+
borderRadius: 'var(--style-radius-s, 4px)',
|
|
35
|
+
border: '1px solid var(--theme-border-color)',
|
|
36
|
+
background: 'var(--theme-input-bg)',
|
|
37
|
+
color: 'var(--theme-text)'
|
|
38
|
+
}
|
|
39
|
+
}),
|
|
40
|
+
searching && (results.length > 0 ? /*#__PURE__*/ _jsx("ul", {
|
|
41
|
+
style: {
|
|
42
|
+
listStyle: 'none',
|
|
43
|
+
margin: 0,
|
|
44
|
+
padding: 0,
|
|
45
|
+
display: 'flex',
|
|
46
|
+
flexDirection: 'column',
|
|
47
|
+
gap: '0.5rem'
|
|
48
|
+
},
|
|
49
|
+
children: results.map((g)=>/*#__PURE__*/ _jsx("li", {
|
|
50
|
+
children: /*#__PURE__*/ _jsxs("a", {
|
|
51
|
+
href: `/admin/guides/${g.slug}`,
|
|
52
|
+
style: {
|
|
53
|
+
display: 'block',
|
|
54
|
+
textDecoration: 'none'
|
|
55
|
+
},
|
|
56
|
+
children: [
|
|
57
|
+
/*#__PURE__*/ _jsx("span", {
|
|
58
|
+
style: {
|
|
59
|
+
display: 'block',
|
|
60
|
+
fontWeight: 600,
|
|
61
|
+
color: 'var(--theme-text)'
|
|
62
|
+
},
|
|
63
|
+
children: g.title
|
|
64
|
+
}),
|
|
65
|
+
/*#__PURE__*/ _jsx("span", {
|
|
66
|
+
style: {
|
|
67
|
+
...muted,
|
|
68
|
+
display: 'block'
|
|
69
|
+
},
|
|
70
|
+
children: g.summary
|
|
71
|
+
})
|
|
72
|
+
]
|
|
73
|
+
})
|
|
74
|
+
}, g.slug))
|
|
75
|
+
}) : /*#__PURE__*/ _jsx("p", {
|
|
76
|
+
style: muted,
|
|
77
|
+
children: "No guides match that. Try fewer or different words."
|
|
78
|
+
}))
|
|
79
|
+
]
|
|
80
|
+
});
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
//# sourceMappingURL=GuideSearch.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/components/GuideSearch.tsx"],"sourcesContent":["'use client'\n\nimport { useMemo, useState } from 'react'\n\nimport { type GuideHit, searchGuides } from '../searchGuides.js'\n\nconst muted = { color: 'var(--theme-elevation-600)', fontSize: '0.875rem', margin: 0 }\n\n/** Search box over the (small) list of guides the server already fetched for this user. */\nexport function GuideSearch({ guides }: { guides: GuideHit[] }) {\n const [query, setQuery] = useState('')\n const results = useMemo(() => searchGuides(guides, query), [guides, query])\n const searching = query.trim().length > 0\n\n return (\n <div style={{ display: 'flex', flexDirection: 'column', gap: '0.75rem' }}>\n <input\n type=\"search\"\n value={query}\n onChange={(e) => setQuery(e.target.value)}\n placeholder='Search the guides, e.g. \"how do I upload an image\"'\n aria-label=\"Search the guides\"\n style={{\n width: '100%',\n padding: '0.5rem 0.75rem',\n fontSize: '1rem',\n borderRadius: 'var(--style-radius-s, 4px)',\n border: '1px solid var(--theme-border-color)',\n background: 'var(--theme-input-bg)',\n color: 'var(--theme-text)',\n }}\n />\n {searching &&\n (results.length > 0 ? (\n <ul style={{ listStyle: 'none', margin: 0, padding: 0, display: 'flex', flexDirection: 'column', gap: '0.5rem' }}>\n {results.map((g) => (\n <li key={g.slug}>\n <a href={`/admin/guides/${g.slug}`} style={{ display: 'block', textDecoration: 'none' }}>\n <span style={{ display: 'block', fontWeight: 600, color: 'var(--theme-text)' }}>{g.title}</span>\n <span style={{ ...muted, display: 'block' }}>{g.summary}</span>\n </a>\n </li>\n ))}\n </ul>\n ) : (\n <p style={muted}>No guides match that. Try fewer or different words.</p>\n ))}\n </div>\n )\n}\n"],"names":["useMemo","useState","searchGuides","muted","color","fontSize","margin","GuideSearch","guides","query","setQuery","results","searching","trim","length","div","style","display","flexDirection","gap","input","type","value","onChange","e","target","placeholder","aria-label","width","padding","borderRadius","border","background","ul","listStyle","map","g","li","a","href","slug","textDecoration","span","fontWeight","title","summary","p"],"mappings":"AAAA;;AAEA,SAASA,OAAO,EAAEC,QAAQ,QAAQ,QAAO;AAEzC,SAAwBC,YAAY,QAAQ,qBAAoB;AAEhE,MAAMC,QAAQ;IAAEC,OAAO;IAA8BC,UAAU;IAAYC,QAAQ;AAAE;AAErF,yFAAyF,GACzF,OAAO,SAASC,YAAY,EAAEC,MAAM,EAA0B;IAC5D,MAAM,CAACC,OAAOC,SAAS,GAAGT,SAAS;IACnC,MAAMU,UAAUX,QAAQ,IAAME,aAAaM,QAAQC,QAAQ;QAACD;QAAQC;KAAM;IAC1E,MAAMG,YAAYH,MAAMI,IAAI,GAAGC,MAAM,GAAG;IAExC,qBACE,MAACC;QAAIC,OAAO;YAAEC,SAAS;YAAQC,eAAe;YAAUC,KAAK;QAAU;;0BACrE,KAACC;gBACCC,MAAK;gBACLC,OAAOb;gBACPc,UAAU,CAACC,IAAMd,SAASc,EAAEC,MAAM,CAACH,KAAK;gBACxCI,aAAY;gBACZC,cAAW;gBACXX,OAAO;oBACLY,OAAO;oBACPC,SAAS;oBACTxB,UAAU;oBACVyB,cAAc;oBACdC,QAAQ;oBACRC,YAAY;oBACZ5B,OAAO;gBACT;;YAEDQ,aACED,CAAAA,QAAQG,MAAM,GAAG,kBAChB,KAACmB;gBAAGjB,OAAO;oBAAEkB,WAAW;oBAAQ5B,QAAQ;oBAAGuB,SAAS;oBAAGZ,SAAS;oBAAQC,eAAe;oBAAUC,KAAK;gBAAS;0BAC5GR,QAAQwB,GAAG,CAAC,CAACC,kBACZ,KAACC;kCACC,cAAA,MAACC;4BAAEC,MAAM,CAAC,cAAc,EAAEH,EAAEI,IAAI,EAAE;4BAAExB,OAAO;gCAAEC,SAAS;gCAASwB,gBAAgB;4BAAO;;8CACpF,KAACC;oCAAK1B,OAAO;wCAAEC,SAAS;wCAAS0B,YAAY;wCAAKvC,OAAO;oCAAoB;8CAAIgC,EAAEQ,KAAK;;8CACxF,KAACF;oCAAK1B,OAAO;wCAAE,GAAGb,KAAK;wCAAEc,SAAS;oCAAQ;8CAAImB,EAAES,OAAO;;;;uBAHlDT,EAAEI,IAAI;+BASnB,KAACM;gBAAE9B,OAAOb;0BAAO;cACnB;;;AAGR"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
3
|
+
import { usePathname } from 'next/navigation.js';
|
|
4
|
+
/** "Guides" in the sidebar for every signed-in user, below the collection groups. */ export function GuidesNavLink() {
|
|
5
|
+
const active = usePathname()?.startsWith('/admin/guides');
|
|
6
|
+
return /*#__PURE__*/ _jsx("a", {
|
|
7
|
+
href: "/admin/guides",
|
|
8
|
+
className: `nav__link${active ? ' active' : ''}`,
|
|
9
|
+
children: /*#__PURE__*/ _jsx("span", {
|
|
10
|
+
className: "nav__link-label",
|
|
11
|
+
children: "Guides"
|
|
12
|
+
})
|
|
13
|
+
});
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
//# sourceMappingURL=GuidesNavLink.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/components/GuidesNavLink.tsx"],"sourcesContent":["'use client'\n\nimport { usePathname } from 'next/navigation.js'\n\n/** \"Guides\" in the sidebar for every signed-in user, below the collection groups. */\nexport function GuidesNavLink() {\n const active = usePathname()?.startsWith('/admin/guides')\n return (\n <a href=\"/admin/guides\" className={`nav__link${active ? ' active' : ''}`}>\n <span className=\"nav__link-label\">Guides</span>\n </a>\n )\n}\n"],"names":["usePathname","GuidesNavLink","active","startsWith","a","href","className","span"],"mappings":"AAAA;;AAEA,SAASA,WAAW,QAAQ,qBAAoB;AAEhD,mFAAmF,GACnF,OAAO,SAASC;IACd,MAAMC,SAASF,eAAeG,WAAW;IACzC,qBACE,KAACC;QAAEC,MAAK;QAAgBC,WAAW,CAAC,SAAS,EAAEJ,SAAS,YAAY,IAAI;kBACtE,cAAA,KAACK;YAAKD,WAAU;sBAAkB;;;AAGxC"}
|