@foundrykit/guides-plugin 0.1.0 → 0.1.1
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 +17 -16
- package/dist/collections/guides.js.map +1 -1
- package/dist/collections/siteGuides.js.map +1 -1
- package/dist/components/GuideArticle.d.ts +1 -1
- package/dist/components/GuideArticle.js.map +1 -1
- package/dist/components/GuideSearch.js.map +1 -1
- package/dist/components/GuidesNavLink.js +1 -1
- package/dist/components/GuidesNavLink.js.map +1 -1
- package/dist/components/GuidesView.js.map +1 -1
- package/dist/components/Help.js.map +1 -1
- package/dist/exports/client.js.map +1 -1
- package/dist/exports/rsc.js.map +1 -1
- package/dist/hub.d.ts +2 -2
- package/dist/hub.js +2 -2
- package/dist/hub.js.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js.map +1 -1
- package/dist/searchGuides.js.map +1 -1
- package/dist/sync.js.map +1 -1
- package/package.json +37 -40
package/README.md
CHANGED
|
@@ -16,7 +16,7 @@ Extracted from the Turquoise CMS guides section. Spec: https://claude.ai/artifac
|
|
|
16
16
|
## Install
|
|
17
17
|
|
|
18
18
|
```ts
|
|
19
|
-
import { guidesPlugin } from '@foundrykit/guides-plugin'
|
|
19
|
+
import { guidesPlugin } from '@foundrykit/guides-plugin';
|
|
20
20
|
|
|
21
21
|
export default buildConfig({
|
|
22
22
|
plugins: [
|
|
@@ -24,10 +24,11 @@ export default buildConfig({
|
|
|
24
24
|
// Reported to the hub on each sync, to compare with the site's Sites record.
|
|
25
25
|
features: ['crm.inspiretec'],
|
|
26
26
|
// Who can write site guides here. Default: nobody.
|
|
27
|
-
canAuthor:
|
|
27
|
+
canAuthor: user =>
|
|
28
|
+
(user as { role?: string } | null)?.role === 'super-admin',
|
|
28
29
|
}),
|
|
29
30
|
],
|
|
30
|
-
})
|
|
31
|
+
});
|
|
31
32
|
```
|
|
32
33
|
|
|
33
34
|
Environment (from the site's record in the hub):
|
|
@@ -42,14 +43,14 @@ Then regenerate the import map (`payload generate:importmap`) and create a migra
|
|
|
42
43
|
|
|
43
44
|
### Options
|
|
44
45
|
|
|
45
|
-
| Option
|
|
46
|
-
|
|
|
47
|
-
| `hubURL`
|
|
48
|
-
| `siteKey`
|
|
49
|
-
| `features`
|
|
50
|
-
| `canAuthor` | `() => false`
|
|
51
|
-
| `schedule`
|
|
52
|
-
| `disabled`
|
|
46
|
+
| Option | Default | |
|
|
47
|
+
| ----------- | ---------------------------- | ------------------------------------------------------------------ |
|
|
48
|
+
| `hubURL` | `process.env.GUIDES_HUB_URL` | The guides hub. |
|
|
49
|
+
| `siteKey` | `process.env.GUIDES_HUB_KEY` | This site's guides key. Also verifies the hub's webhook signature. |
|
|
50
|
+
| `features` | `[]` | Feature keys reported to the hub. |
|
|
51
|
+
| `canAuthor` | `() => false` | Who sees and writes Site guides. |
|
|
52
|
+
| `schedule` | `'0 0 * * * *'` (hourly) | Cron for the backstop pull (Payload's 6-field form), or `false`. |
|
|
53
|
+
| `disabled` | `false` | |
|
|
53
54
|
|
|
54
55
|
### The scheduled pull
|
|
55
56
|
|
|
@@ -70,11 +71,11 @@ A guide shows there when its **help contexts** (set in the hub, or on a site gui
|
|
|
70
71
|
|
|
71
72
|
## How it talks to the hub
|
|
72
73
|
|
|
73
|
-
|
|
|
74
|
-
|
|
|
75
|
-
| Pull
|
|
76
|
-
| Ping
|
|
77
|
-
| Site guides | Publish → `POST`/`PATCH <hub>/api/guides[/:id]`; delete → `DELETE`.
|
|
74
|
+
| | |
|
|
75
|
+
| ----------- | ------------------------------------------------------------------------------------------------------------------------------------------ |
|
|
76
|
+
| Pull | `GET <hub>/api/sites/feed?pluginVersion=…&features=…` with `Authorization: sites API-Key <key>` |
|
|
77
|
+
| 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. |
|
|
78
|
+
| Site guides | Publish → `POST`/`PATCH <hub>/api/guides[/:id]`; delete → `DELETE`. |
|
|
78
79
|
|
|
79
80
|
## Development
|
|
80
81
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/collections/guides.ts"],"sourcesContent":["import type { CollectionConfig, Endpoint } from 'payload'
|
|
1
|
+
{"version":3,"sources":["../../src/collections/guides.ts"],"sourcesContent":["import type { CollectionConfig, Endpoint } from 'payload';\n\nimport {\n GUIDES_SLUG,\n type ResolvedConfig,\n SIGNATURE_HEADER,\n verifySignature,\n} 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 (\n !config.siteKey ||\n !verifySignature(config.siteKey, body, req.headers.get(SIGNATURE_HEADER))\n ) {\n return Response.json(\n { error: 'Signature does not match this site’s guides key.' },\n { status: 401 }\n );\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(\n { error: 'Could not sync from the guides hub.' },\n { status: 502 }\n );\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,SACEA,WAAW,EAEXC,gBAAgB,EAChBC,eAAe,QACV,YAAY;AACnB,SAASC,UAAU,QAAQ,aAAa;AAExC,2FAA2F,GAC3F,MAAMC,eAAe,CAACC,SAAsC,CAAA;QAC1DC,MAAM;QACNC,QAAQ;QACRC,SAAS,OAAMC;YACb,MAAMC,OAAO,AAAC,MAAMD,IAAIE,IAAI,QAAS;YACrC,IACE,CAACN,OAAOO,OAAO,IACf,CAACV,gBAAgBG,OAAOO,OAAO,EAAEF,MAAMD,IAAII,OAAO,CAACC,GAAG,CAACb,oBACvD;gBACA,OAAOc,SAASC,IAAI,CAClB;oBAAEC,OAAO;gBAAmD,GAC5D;oBAAEC,QAAQ;gBAAI;YAElB;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,CAClB;oBAAEC,OAAO;gBAAsC,GAC/C;oBAAEC,QAAQ;gBAAI;YAElB;QACF;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"version":3,"sources":["../../src/collections/siteGuides.ts"],"sourcesContent":["import { LinkFeature, lexicalEditor } from '@payloadcms/richtext-lexical'
|
|
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(\n config,\n hubId ? `/api/guides/${hubId}` : '/api/guides',\n {\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 }\n ).catch(() => null);\n if (!res?.ok) throw unreachable(res?.status);\n data.hubId = String(\n ((await res.json()) as { doc: { id: number | string } }).doc.id\n );\n return data;\n };\n\nconst deleteFromHub =\n (config: ResolvedConfig): CollectionBeforeDeleteHook =>\n async ({ id, req }) => {\n const doc = await req.payload.findByID({\n collection: SITE_GUIDES_SLUG as never,\n id,\n depth: 0,\n req,\n draft: true,\n });\n const hubId = (doc as { hubId?: string }).hubId;\n if (!hubId) return;\n const res = await hubFetch(config, `/api/guides/${hubId}`, {\n method: 'DELETE',\n }).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 = (\n config: ResolvedConfig\n): CollectionConfig => {\n const canAuthor = ({ req: { user } }: { req: { user: unknown } }) =>\n 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: {\n read: canAuthor,\n create: canAuthor,\n update: canAuthor,\n delete: canAuthor,\n readVersions: canAuthor,\n },\n hooks: {\n beforeChange: [publishToHub(config)],\n beforeDelete: [deleteFromHub(config)],\n },\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: {\n description:\n 'One or two sentences, shown in lists, search results and the Help panel.',\n },\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(\n f => !['link', 'relationship', 'upload', 'blocks'].includes(f.key)\n ),\n LinkFeature({ enabledCollections: [] }),\n ],\n }),\n },\n {\n name: 'helpContexts',\n type: 'text',\n hasMany: true,\n admin: {\n position: 'sidebar',\n description:\n '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: {\n position: 'sidebar',\n readOnly: true,\n description: 'Set once the guide is published to the hub.',\n },\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":"AAAA,SAASA,WAAW,EAAEC,aAAa,QAAQ,+BAA+B;AAC1E,SACEC,QAAQ,QAIH,UAAU;AAEjB,SAASC,QAAQ,EAAuBC,gBAAgB,QAAQ,YAAY;AAE5E,MAAMC,cAAc,CAACC,SACnB,IAAIJ,SACF,CAAC,0CAA0C,EAAEI,SAAS,CAAC,cAAc,EAAEA,OAAO,CAAC,CAAC,GAAG,GAAG,mEAAmE,CAAC,EAC1J;AAGJ;;;CAGC,GACD,MAAMC,eACJ,CAACC,SACD,OAAO,EAAEC,IAAI,EAAEC,WAAW,EAAE;QAC1B,IAAID,KAAKE,OAAO,KAAK,aAAa,OAAOF;QACzC,MAAMG,MAAM;YAAE,GAAGF,WAAW;YAAE,GAAGD,IAAI;QAAC;QACtC,MAAMI,QAAQD,IAAIC,KAAK;QACvB,MAAMC,MAAM,MAAMX,SAChBK,QACAK,QAAQ,CAAC,YAAY,EAAEA,OAAO,GAAG,eACjC;YACEE,QAAQF,QAAQ,UAAU;YAC1BG,MAAMC,KAAKC,SAAS,CAAC;gBACnBC,OAAOP,IAAIO,KAAK;gBAChBC,SAASR,IAAIQ,OAAO;gBACpBC,cAAcT,IAAIS,YAAY,IAAI,EAAE;gBACpCL,MAAMJ,IAAII,IAAI;gBACdL,SAAS;YACX;QACF,GACAW,KAAK,CAAC,IAAM;QACd,IAAI,CAACR,KAAKS,IAAI,MAAMlB,YAAYS,KAAKR;QACrCG,KAAKI,KAAK,GAAGW,OACX,AAAE,CAAA,MAAMV,IAAIW,IAAI,EAAC,EAAwCb,GAAG,CAACc,EAAE;QAEjE,OAAOjB;IACT;AAEF,MAAMkB,gBACJ,CAACnB,SACD,OAAO,EAAEkB,EAAE,EA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AQ7D,cAAc;oBACpB8D,UAAU,CAAC,EAAEC,eAAe,EAAE,GAAK;+BAC9BA,gBAAgBC,MAAM,CACvBC,CAAAA,IAAK,CAAC;oCAAC;oCAAQ;oCAAgB;oCAAU;iCAAS,CAACC,QAAQ,CAACD,EAAEE,GAAG;4BAEnEpE,YAAY;gCAAEqE,oBAAoB,EAAE;4BAAC;yBACtC;gBACH;YACF;YACA;gBACEX,MAAM;gBACNC,MAAM;gBACNW,SAAS;gBACT7B,OAAO;oBACL8B,UAAU;oBACV3B,aACE;gBACJ;YACF;YACA;gBACEc,MAAM;gBACNC,MAAM;gBACNlB,OAAO;oBACL8B,UAAU;oBACVC,UAAU;oBACV5B,aAAa;gBACf;YACF;SACD;IACH;AACF,EAAE"}
|
|
@@ -18,7 +18,7 @@ export type LocalGuide = {
|
|
|
18
18
|
* One guide as a readable article. Bodies come from the hub, so images load from the hub's
|
|
19
19
|
* storage and the default Lexical converters are enough (hub guides only allow external links).
|
|
20
20
|
*/
|
|
21
|
-
export declare function GuideArticle({ guide, canAuthor }: {
|
|
21
|
+
export declare function GuideArticle({ guide, canAuthor, }: {
|
|
22
22
|
guide: LocalGuide;
|
|
23
23
|
canAuthor: boolean;
|
|
24
24
|
}): import("react/jsx-runtime").JSX.Element;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/components/GuideArticle.tsx"],"sourcesContent":["import type { SerializedEditorState } from '@payloadcms/richtext-lexical/lexical'
|
|
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', {\n day: 'numeric',\n month: 'short',\n year: 'numeric',\n timeZone: 'Europe/London',\n });\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({\n guide,\n canAuthor,\n}: {\n guide: LocalGuide;\n canAuthor: boolean;\n}) {\n return (\n <article\n style={{\n display: 'flex',\n flexDirection: 'column',\n gap: '1rem',\n maxWidth: '48rem',\n }}\n >\n <style>{prose}</style>\n <header\n style={{ display: 'flex', flexDirection: 'column', gap: '0.25rem' }}\n >\n <h2 style={{ margin: 0 }}>{guide.title}</h2>\n <p\n style={{\n margin: 0,\n color: 'var(--theme-elevation-600)',\n fontSize: '0.875rem',\n }}\n >\n {guide.hubUpdatedAt\n ? `Updated ${formatDate(guide.hubUpdatedAt)}`\n : null}\n {canAuthor && guide.scope === 'site' && (\n <>\n {' · '}\n <a\n href={`/admin/collections/${SITE_GUIDES_SLUG}?where[hubId][equals]=${guide.hubId}`}\n >\n Edit this guide\n </a>\n </>\n )}\n </p>\n </header>\n <div className='guide-article__body'>\n {guide.body ? (\n <RichText data={guide.body as SerializedEditorState} />\n ) : 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,qCAAqC;AAE9D,SAASC,gBAAgB,QAAQ,YAAY;AAgB7C,MAAMC,aAAa,CAACC,MAClB,IAAIC,KAAKD,KAAKE,kBAAkB,CAAC,SAAS;QACxCC,KAAK;QACLC,OAAO;QACPC,MAAM;QACNC,UAAU;IACZ;AAEF,8DAA8D;AAC9D,MAAMC,QAAQ,CAAC;;;;;;;;AAQf,CAAC;AAED;;;CAGC,GACD,OAAO,SAASC,aAAa,EAC3BC,KAAK,EACLC,SAAS,EAIV;IACC,qBACE,MAACC;QACCC,OAAO;YACLC,SAAS;YACTC,eAAe;YACfC,KAAK;YACLC,UAAU;QACZ;;0BAEA,KAACJ;0BAAOL;;0BACR,MAACU;gBACCL,OAAO;oBAAEC,SAAS;oBAAQC,eAAe;oBAAUC,KAAK;gBAAU;;kCAElE,KAACG;wBAAGN,OAAO;4BAAEO,QAAQ;wBAAE;kCAAIV,MAAMW,KAAK;;kCACtC,MAACC;wBACCT,OAAO;4BACLO,QAAQ;4BACRG,OAAO;4BACPC,UAAU;wBACZ;;4BAECd,MAAMe,YAAY,GACf,CAAC,QAAQ,EAAEzB,WAAWU,MAAMe,YAAY,GAAG,GAC3C;4BACHd,aAAaD,MAAMgB,KAAK,KAAK,wBAC5B;;oCACG;kDACD,KAACC;wCACCC,MAAM,CAAC,mBAAmB,EAAE7B,iBAAiB,sBAAsB,EAAEW,MAAMmB,KAAK,EAAE;kDACnF;;;;;;;;0BAOT,KAACC;gBAAIC,WAAU;0BACZrB,MAAMsB,IAAI,iBACT,KAAClC;oBAASmC,MAAMvB,MAAMsB,IAAI;qBACxB;;;;AAIZ"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/components/GuideSearch.tsx"],"sourcesContent":["'use client'
|
|
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 = {\n color: 'var(--theme-elevation-600)',\n fontSize: '0.875rem',\n margin: 0,\n};\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\n style={{\n listStyle: 'none',\n margin: 0,\n padding: 0,\n display: 'flex',\n flexDirection: 'column',\n gap: '0.5rem',\n }}\n >\n {results.map(g => (\n <li key={g.slug}>\n <a\n href={`/admin/guides/${g.slug}`}\n style={{ display: 'block', textDecoration: 'none' }}\n >\n <span\n style={{\n display: 'block',\n fontWeight: 600,\n color: 'var(--theme-text)',\n }}\n >\n {g.title}\n </span>\n <span style={{ ...muted, display: 'block' }}>\n {g.summary}\n </span>\n </a>\n </li>\n ))}\n </ul>\n ) : (\n <p style={muted}>\n No guides match that. Try fewer or different words.\n </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,SAAS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fPT,EAAEI,IAAI;+BAsBnB,KAACM;gBAAE9B,OAAOb;0BAAO;cAGnB;;;AAGR"}
|
|
@@ -5,7 +5,7 @@ import { usePathname } from 'next/navigation.js';
|
|
|
5
5
|
const active = usePathname()?.startsWith('/admin/guides');
|
|
6
6
|
return /*#__PURE__*/ _jsx("a", {
|
|
7
7
|
href: "/admin/guides",
|
|
8
|
-
className: `nav__link${active ? '
|
|
8
|
+
className: `nav__link${active ? 'active' : ''}`,
|
|
9
9
|
children: /*#__PURE__*/ _jsx("span", {
|
|
10
10
|
className: "nav__link-label",
|
|
11
11
|
children: "Guides"
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/components/GuidesNavLink.tsx"],"sourcesContent":["'use client'
|
|
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,qBAAqB;AAEjD,mFAAmF,GACnF,OAAO,SAASC;IACd,MAAMC,SAASF,eAAeG,WAAW;IACzC,qBACE,KAACC;QAAEC,MAAK;QAAgBC,WAAW,CAAC,SAAS,EAAEJ,SAAS,WAAW,IAAI;kBACrE,cAAA,KAACK;YAAKD,WAAU;sBAAkB;;;AAGxC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/components/GuidesView.tsx"],"sourcesContent":["import { DefaultTemplate } from '@payloadcms/next/templates'\nimport { Gutter } from '@payloadcms/ui'\nimport { redirect } from 'next/navigation.js'\nimport type { AdminViewServerProps } from 'payload'\n\nimport { GUIDES_SLUG, SITE_GUIDES_SLUG } from '../hub.js'\nimport type { GuideHit } from '../searchGuides.js'\nimport { GuideArticle, type LocalGuide } from './GuideArticle.js'\nimport { GuideSearch } from './GuideSearch.js'\n\nconst muted = { color: 'var(--theme-elevation-600)', margin: 0 }\nconst OTHER = 'Other'\n\n/** Guides grouped under their hub topic, topics in hub order, untopicked guides last. */\nconst byTopic = (guides: LocalGuide[]) => {\n const groups = new Map<string, { order: number; guides: LocalGuide[] }>()\n for (const g of guides) {\n const title = g.topic?.title || OTHER\n const group = groups.get(title) ?? {\n order: title === OTHER ? Infinity : (g.topic?.order ?? Number.MAX_SAFE_INTEGER),\n guides: [],\n }\n group.guides.push(g)\n groups.set(title, group)\n }\n return [...groups.entries()].sort(([a, x], [b, y]) => x.order - y.order || a.localeCompare(b))\n}\n\n/**\n * /admin/guides and /admin/guides/<slug>: browse, search and read this site's guides. Reads the\n * local copy with the user's own access, so it works when the hub is down.\n */\nexport async function GuidesView(props: AdminViewServerProps) {\n const { initPageResult, params, searchParams } = props\n const { req, locale, permissions, visibleEntities } = initPageResult\n const segments = (params?.segments as string[] | undefined) ?? []\n const slug = segments[1]\n\n // Payload doesn't send signed-out visitors of custom views to the login page, and guides\n // aren't readable without a user, so the query below would throw and show an error page.\n if (!req.user) {\n redirect(`/admin/login?redirect=${encodeURIComponent(`/admin/${segments.join('/') || 'guides'}`)}`)\n }\n // Authors are whoever the plugin's canAuthor allows, as applied by site-guides access control.\n const canAuthor = Boolean(\n (permissions?.collections as Record<string, { create?: unknown }> | undefined)?.[SITE_GUIDES_SLUG]?.create,\n )\n\n const { docs } = await req.payload.find({\n collection: GUIDES_SLUG as never,\n pagination: false,\n depth: 0,\n sort: ['order', 'title'],\n overrideAccess: false,\n req,\n })\n const guides = docs as unknown as LocalGuide[]\n const selected = slug ? guides.find((g) => g.slug === slug) : undefined\n const hits: GuideHit[] = guides.map((g) => ({\n slug: g.slug ?? g.hubId,\n title: g.title,\n summary: g.summary ?? '',\n bodyText: g.bodyText ?? '',\n }))\n const recent = [...guides].sort((a, b) => (b.hubUpdatedAt ?? '').localeCompare(a.hubUpdatedAt ?? '')).slice(0, 3)\n\n return (\n <DefaultTemplate\n i18n={req.i18n}\n locale={locale}\n params={params}\n payload={req.payload}\n permissions={permissions}\n req={req}\n searchParams={searchParams}\n user={req.user ?? undefined}\n visibleEntities={visibleEntities}\n >\n <Gutter>\n <header style={{ margin: '1.5rem 0', display: 'flex', flexDirection: 'column', gap: '0.5rem' }}>\n <h1 style={{ margin: 0 }}>Guides</h1>\n <p style={muted}>How-tos for working in the CMS.</p>\n </header>\n <div\n style={{ display: 'grid', gap: '2rem', gridTemplateColumns: 'minmax(12rem, 16rem) minmax(0, 1fr)', paddingBottom: '3rem' }}\n >\n <nav aria-label=\"Guides by topic\" style={{ display: 'flex', flexDirection: 'column', gap: '1rem' }}>\n {canAuthor && <a href={`/admin/collections/${SITE_GUIDES_SLUG}/create`}>+ New site guide</a>}\n {byTopic(guides).map(([title, group]) => (\n <section key={title} style={{ display: 'flex', flexDirection: 'column', gap: '0.25rem' }}>\n <span\n style={{\n color: 'var(--theme-elevation-600)',\n fontSize: '0.75rem',\n textTransform: 'uppercase',\n letterSpacing: '0.05em',\n }}\n >\n {title}\n </span>\n {group.guides.map((g) => (\n <a\n key={g.id}\n href={`/admin/guides/${g.slug}`}\n aria-current={g.slug === slug ? 'page' : undefined}\n style={g.slug === slug ? { fontWeight: 600 } : undefined}\n >\n {g.title}\n </a>\n ))}\n </section>\n ))}\n {guides.length === 0 && <p style={muted}>No guides yet.</p>}\n </nav>\n\n <div style={{ display: 'flex', flexDirection: 'column', gap: '2rem', minWidth: 0 }}>\n <GuideSearch guides={hits} />\n {slug ? (\n selected ? (\n <GuideArticle guide={selected} canAuthor={canAuthor} />\n ) : (\n <p style={muted}>Guide not found.</p>\n )\n ) : (\n recent.length > 0 && (\n <div style={{ display: 'grid', gap: '1rem', gridTemplateColumns: 'repeat(auto-fill, minmax(14rem, 1fr))' }}>\n {recent.map((g) => (\n <a\n key={g.id}\n href={`/admin/guides/${g.slug}`}\n style={{\n display: 'block',\n padding: '1rem',\n textDecoration: 'none',\n borderRadius: 'var(--style-radius-m, 6px)',\n border: '1px solid var(--theme-border-color)',\n background: 'var(--theme-elevation-50)',\n }}\n >\n <span style={{ display: 'block', fontWeight: 600, color: 'var(--theme-text)' }}>{g.title}</span>\n <span style={{ ...muted, display: 'block', fontSize: '0.875rem', marginTop: '0.25rem' }}>\n {g.summary}\n </span>\n </a>\n ))}\n </div>\n )\n )}\n </div>\n </div>\n </Gutter>\n </DefaultTemplate>\n )\n}\n"],"names":["DefaultTemplate","Gutter","redirect","GUIDES_SLUG","SITE_GUIDES_SLUG","GuideArticle","GuideSearch","muted","color","margin","OTHER","byTopic","guides","groups","Map","g","title","topic","group","get","order","Infinity","Number","MAX_SAFE_INTEGER","push","set","entries","sort","a","x","b","y","localeCompare","GuidesView","props","initPageResult","params","searchParams","req","locale","permissions","visibleEntities","segments","slug","user","encodeURIComponent","join","canAuthor","Boolean","collections","create","docs","payload","find","collection","pagination","depth","overrideAccess","selected","undefined","hits","map","hubId","summary","bodyText","recent","hubUpdatedAt","slice","i18n","header","style","display","flexDirection","gap","h1","p","div","gridTemplateColumns","paddingBottom","nav","aria-label","href","section","span","fontSize","textTransform","letterSpacing","aria-current","fontWeight","id","length","minWidth","guide","padding","textDecoration","borderRadius","border","background","marginTop"],"mappings":";AAAA,SAASA,eAAe,QAAQ,6BAA4B;AAC5D,SAASC,MAAM,QAAQ,iBAAgB;AACvC,SAASC,QAAQ,QAAQ,qBAAoB;AAG7C,SAASC,WAAW,EAAEC,gBAAgB,QAAQ,YAAW;AAEzD,SAASC,YAAY,QAAyB,oBAAmB;AACjE,SAASC,WAAW,QAAQ,mBAAkB;AAE9C,MAAMC,QAAQ;IAAEC,OAAO;IAA8BC,QAAQ;AAAE;AAC/D,MAAMC,QAAQ;AAEd,uFAAuF,GACvF,MAAMC,UAAU,CAACC;IACf,MAAMC,SAAS,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AAO;oDAAoB;8DAAIO,EAAEC,KAAK;;8DACxF,KAACmE;oDAAKb,OAAO;wDAAE,GAAG/D,KAAK;wDAAEgE,SAAS;wDAASa,UAAU;wDAAYc,WAAW;oDAAU;8DACnFnF,EAAEgD,OAAO;;;2CAbPhD,EAAE0E,EAAE;;;;;;;;;AAyB/B"}
|
|
1
|
+
{"version":3,"sources":["../../src/components/GuidesView.tsx"],"sourcesContent":["import { DefaultTemplate } from '@payloadcms/next/templates';\nimport { Gutter } from '@payloadcms/ui';\nimport { redirect } from 'next/navigation.js';\nimport type { AdminViewServerProps } from 'payload';\n\nimport { GUIDES_SLUG, SITE_GUIDES_SLUG } from '../hub.js';\nimport type { GuideHit } from '../searchGuides.js';\nimport { GuideArticle, type LocalGuide } from './GuideArticle.js';\nimport { GuideSearch } from './GuideSearch.js';\n\nconst muted = { color: 'var(--theme-elevation-600)', margin: 0 };\nconst OTHER = 'Other';\n\n/** Guides grouped under their hub topic, topics in hub order, untopicked guides last. */\nconst byTopic = (guides: LocalGuide[]) => {\n const groups = new Map<string, { order: number; guides: LocalGuide[] }>();\n for (const g of guides) {\n const title = g.topic?.title || OTHER;\n const group = groups.get(title) ?? {\n order:\n title === OTHER\n ? Infinity\n : (g.topic?.order ?? Number.MAX_SAFE_INTEGER),\n guides: [],\n };\n group.guides.push(g);\n groups.set(title, group);\n }\n return [...groups.entries()].sort(\n ([a, x], [b, y]) => x.order - y.order || a.localeCompare(b)\n );\n};\n\n/**\n * /admin/guides and /admin/guides/<slug>: browse, search and read this site's guides. Reads the\n * local copy with the user's own access, so it works when the hub is down.\n */\nexport async function GuidesView(props: AdminViewServerProps) {\n const { initPageResult, params, searchParams } = props;\n const { req, locale, permissions, visibleEntities } = initPageResult;\n const segments = (params?.segments as string[] | undefined) ?? [];\n const slug = segments[1];\n\n // Payload doesn't send signed-out visitors of custom views to the login page, and guides\n // aren't readable without a user, so the query below would throw and show an error page.\n if (!req.user) {\n redirect(\n `/admin/login?redirect=${encodeURIComponent(`/admin/${segments.join('/') || 'guides'}`)}`\n );\n }\n // Authors are whoever the plugin's canAuthor allows, as applied by site-guides access control.\n const canAuthor = Boolean(\n (\n permissions?.collections as\n | Record<string, { create?: unknown }>\n | undefined\n )?.[SITE_GUIDES_SLUG]?.create\n );\n\n const { docs } = await req.payload.find({\n collection: GUIDES_SLUG as never,\n pagination: false,\n depth: 0,\n sort: ['order', 'title'],\n overrideAccess: false,\n req,\n });\n const guides = docs as unknown as LocalGuide[];\n const selected = slug ? guides.find(g => g.slug === slug) : undefined;\n const hits: GuideHit[] = guides.map(g => ({\n slug: g.slug ?? g.hubId,\n title: g.title,\n summary: g.summary ?? '',\n bodyText: g.bodyText ?? '',\n }));\n const recent = [...guides]\n .sort((a, b) => (b.hubUpdatedAt ?? '').localeCompare(a.hubUpdatedAt ?? ''))\n .slice(0, 3);\n\n return (\n <DefaultTemplate\n i18n={req.i18n}\n locale={locale}\n params={params}\n payload={req.payload}\n permissions={permissions}\n req={req}\n searchParams={searchParams}\n user={req.user ?? undefined}\n visibleEntities={visibleEntities}\n >\n <Gutter>\n <header\n style={{\n margin: '1.5rem 0',\n display: 'flex',\n flexDirection: 'column',\n gap: '0.5rem',\n }}\n >\n <h1 style={{ margin: 0 }}>Guides</h1>\n <p style={muted}>How-tos for working in the CMS.</p>\n </header>\n <div\n style={{\n display: 'grid',\n gap: '2rem',\n gridTemplateColumns: 'minmax(12rem, 16rem) minmax(0, 1fr)',\n paddingBottom: '3rem',\n }}\n >\n <nav\n aria-label='Guides by topic'\n style={{ display: 'flex', flexDirection: 'column', gap: '1rem' }}\n >\n {canAuthor && (\n <a href={`/admin/collections/${SITE_GUIDES_SLUG}/create`}>\n + New site guide\n </a>\n )}\n {byTopic(guides).map(([title, group]) => (\n <section\n key={title}\n style={{\n display: 'flex',\n flexDirection: 'column',\n gap: '0.25rem',\n }}\n >\n <span\n style={{\n color: 'var(--theme-elevation-600)',\n fontSize: '0.75rem',\n textTransform: 'uppercase',\n letterSpacing: '0.05em',\n }}\n >\n {title}\n </span>\n {group.guides.map(g => (\n <a\n key={g.id}\n href={`/admin/guides/${g.slug}`}\n aria-current={g.slug === slug ? 'page' : undefined}\n style={g.slug === slug ? { fontWeight: 600 } : undefined}\n >\n {g.title}\n </a>\n ))}\n </section>\n ))}\n {guides.length === 0 && <p style={muted}>No guides yet.</p>}\n </nav>\n\n <div\n style={{\n display: 'flex',\n flexDirection: 'column',\n gap: '2rem',\n minWidth: 0,\n }}\n >\n <GuideSearch guides={hits} />\n {slug ? (\n selected ? (\n <GuideArticle guide={selected} canAuthor={canAuthor} />\n ) : (\n <p style={muted}>Guide not found.</p>\n )\n ) : (\n recent.length > 0 && (\n <div\n style={{\n display: 'grid',\n gap: '1rem',\n gridTemplateColumns:\n 'repeat(auto-fill, minmax(14rem, 1fr))',\n }}\n >\n {recent.map(g => (\n <a\n key={g.id}\n href={`/admin/guides/${g.slug}`}\n style={{\n display: 'block',\n padding: '1rem',\n textDecoration: 'none',\n borderRadius: 'var(--style-radius-m, 6px)',\n border: '1px solid var(--theme-border-color)',\n background: 'var(--theme-elevation-50)',\n }}\n >\n <span\n style={{\n display: 'block',\n fontWeight: 600,\n color: 'var(--theme-text)',\n }}\n >\n {g.title}\n </span>\n <span\n style={{\n ...muted,\n display: 'block',\n fontSize: '0.875rem',\n marginTop: '0.25rem',\n }}\n >\n {g.summary}\n </span>\n </a>\n ))}\n </div>\n )\n )}\n </div>\n </div>\n </Gutter>\n </DefaultTemplate>\n );\n}\n"],"names":["DefaultTemplate","Gutter","redirect","GUIDES_SLUG","SITE_GUIDES_SLUG","GuideArticle","GuideSearch","muted","color","margin","OTHER","byTopic","guides","groups","Map","g","title","topic","group","get","order","Infinity","Number","MAX_SAFE_INTEGER","push","set","entries","sort","a","x","b","y","localeCompare","GuidesView","props","initPageResult","params","searchParams","req","locale","permissions","visibleEntities","segments","slug","user","encodeURIComponent","join","canAuthor","Boolean","collections","create","docs","payload","find","collection","pagination","depth","overrideAccess","selected","undefined","hits","map","hubId","summary","bodyText","recent","hubUpdatedAt","slice","i18n","header","style","display","flexDirection","gap","h1","p","div","gridTemplateColumns","paddingBottom","nav","aria-label","href","section","span","fontSize","textTransform","letterSpacing","aria-current","fontWeight","id","length","minWidth","guide","padding","textDecoration","borderRadius","border","background","marginTop"],"mappings":";AAAA,SAASA,eAAe,QAAQ,6BAA6B;AAC7D,SAASC,MAAM,QAAQ,iBAAiB;AACxC,SAASC,QAAQ,QAAQ,qBAAqB;AAG9C,SAASC,WAAW,EAAEC,gBAAgB,QAAQ,YAAY;AAE1D,SAASC,YAAY,QAAyB,oBAAoB;AAClE,SAASC,WAAW,QAAQ,mBAAmB;AAE/C,MAAMC,QAAQ;IAAEC,OAAO;IAA8BC,QAAQ;AAAE;AAC/D,MAAMC,QAAQ;AAEd,uFAAuF,GACvF,MAAMC,UAAU,CAACC;IACf,MAAMC,SAAS,IAAIC;IACnB,KAAK,MAAMC,KAAKH,OAAQ;QACtB,MAAMI,QAAQD,EAAEE,KAAK,EAAED,SAASN;QAChC,MAAMQ,QAAQL,OAAOM,GAAG,CAACH,UAAU;YACjCI,OACEJ,UAAUN,QACNW,WACCN,EAAEE,KAAK,EAAEG,SAASE,OAAOC,gBAAgB;YAChDX,QAAQ,EAAE;QACZ;QACAM,MAAMN,MAAM,CAACY,IAAI,CAACT;QAClBF,OAAOY,GAAG,CAACT,OAAOE;IACpB;IACA,OAAO;WAAIL,OAAOa,OAAO;KAAG,CAACC,IAAI,CAC/B,CAAC,CAACC,GAAGC,EAAE,EAAE,CAACC,GAAGC,EAAE,GAAKF,EAAET,KAAK,GAAGW,EAAEX,KAAK,IAAIQ,EAAEI,aAAa,CAACF;AAE7D;AAEA;;;CAGC,GACD,OAAO,eAAeG,WAAWC,KAA2B;IAC1D,MAAM,EAAEC,cAAc,EAAEC,MAAM,EAAEC,YAAY,EAAE,GAAGH;IACjD,MAAM,EAAEI,GAAG,EAAEC,MAAM,EAAEC,WAAW,EAAEC,eAAe,EAAE,GAAG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ACrF;oCAAYM,QAAQgD;;gCACpBjB,OACCe,yBACE,KAACrD;oCAAauF,OAAOlC;oCAAUX,WAAWA;mDAE1C,KAAC4B;oCAAEL,OAAO/D;8CAAO;qCAGnB0D,OAAOyB,MAAM,GAAG,mBACd,KAACd;oCACCN,OAAO;wCACLC,SAAS;wCACTE,KAAK;wCACLI,qBACE;oCACJ;8CAECZ,OAAOJ,GAAG,CAAC9C,CAAAA,kBACV,MAACa;4CAECqD,MAAM,CAAC,cAAc,EAAElE,EAAE4B,IAAI,EAAE;4CAC/B2B,OAAO;gDACLC,SAAS;gDACTsB,SAAS;gDACTC,gBAAgB;gDAChBC,cAAc;gDACdC,QAAQ;gDACRC,YAAY;4CACd;;8DAEA,KAACd;oDACCb,OAAO;wDACLC,SAAS;wDACTiB,YAAY;wDACZhF,OAAO;oDACT;8DAECO,EAAEC,KAAK;;8DAEV,KAACmE;oDACCb,OAAO;wDACL,GAAG/D,KAAK;wDACRgE,SAAS;wDACTa,UAAU;wDACVc,WAAW;oDACb;8DAECnF,EAAEgD,OAAO;;;2CA5BPhD,EAAE0E,EAAE;;;;;;;;;AAwC/B"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/components/Help.tsx"],"sourcesContent":["'use client'
|
|
1
|
+
{"version":3,"sources":["../../src/components/Help.tsx"],"sourcesContent":["'use client';\n\nimport {\n Button,\n Drawer,\n useConfig,\n useDocumentInfo,\n useModal,\n} from '@payloadcms/ui';\nimport { useEffect, useState } from 'react';\n\ntype GuideLink = { slug: string; title: string; summary: string };\n\nconst muted = {\n color: 'var(--theme-elevation-600)',\n fontSize: '0.875rem',\n margin: '0.25rem 0 0',\n};\n\n/**\n * A \"Help\" button listing the guides for one place in the admin, in a side drawer. Renders\n * nothing when no guide lists that place, so sections without guides look as before.\n *\n * `context` is a help context key (e.g. `media.create`); without one it uses the current\n * collection or global slug, which is how the plugin puts it on every edit page.\n */\nexport function Help({ context }: { context?: string }) {\n const { collectionSlug, globalSlug } = useDocumentInfo();\n const docSlug = collectionSlug ?? globalSlug;\n const key = context ?? docSlug;\n const { getEntityConfig } = useConfig();\n const { openModal } = useModal();\n const [guides, setGuides] = useState<GuideLink[]>([]);\n\n useEffect(() => {\n if (!key) return;\n const params = new URLSearchParams({\n 'where[helpContexts][in]': key,\n depth: '0',\n limit: '10',\n sort: 'order',\n 'select[title]': 'true',\n 'select[slug]': 'true',\n 'select[summary]': 'true',\n });\n let cancelled = false;\n fetch(`/api/guides?${params}`, { credentials: 'include' })\n .then(res => (res.ok ? res.json() : { docs: [] }))\n .then(\n (data: { docs?: GuideLink[] }) =>\n !cancelled && setGuides(data.docs ?? [])\n )\n .catch(() => !cancelled && setGuides([]));\n return () => {\n cancelled = true;\n };\n }, [key]);\n\n if (!key || guides.length === 0) return null;\n\n let label = key;\n if (!context && docSlug) {\n const entity = getEntityConfig(\n collectionSlug ? { collectionSlug } : { globalSlug: docSlug }\n ) as { labels?: { plural?: unknown }; label?: unknown } | undefined;\n const raw = entity?.labels?.plural ?? entity?.label;\n if (typeof raw === 'string') label = raw;\n }\n const drawerSlug = `guide-help-${key}`;\n\n return (\n <>\n <Button\n buttonStyle='secondary'\n size='small'\n margin={false}\n onClick={() => openModal(drawerSlug)}\n >\n ? Help\n </Button>\n <Drawer slug={drawerSlug} title={`Help with ${label}`}>\n <ul\n style={{\n listStyle: 'none',\n margin: 0,\n padding: 0,\n display: 'flex',\n flexDirection: 'column',\n gap: '1rem',\n }}\n >\n {guides.map(g => (\n <li key={g.slug}>\n <a href={`/admin/guides/${g.slug}`} style={{ fontWeight: 600 }}>\n {g.title}\n </a>\n <p style={muted}>{g.summary}</p>\n </li>\n ))}\n </ul>\n <p style={{ marginTop: '1.5rem' }}>\n <a href='/admin/guides'>All guides →</a>\n </p>\n </Drawer>\n </>\n );\n}\n\n/** The edit-page Help button the plugin adds to every collection and global. */\nexport const HelpButton = () => <Help />;\n"],"names":["Button","Drawer","useConfig","useDocumentInfo","useModal","useEffect","useState","muted","color","fontSize","margin","Help","context","collectionSlug","globalSlug","docSlug","key","getEntityConfig","openModal","guides","setGuides","params","URLSearchParams","depth","limit","sort","cancelled","fetch","credentials","then","res","ok","json","docs","data","catch","length","label","entity","raw","labels","plural","drawerSlug","buttonStyle","size","onClick","slug","title","ul","style","listStyle","padding","display","flexDirection","gap","map","g","li","a","href","fontWeight","p","summary","marginTop","HelpButton"],"mappings":"AAAA;;AAEA,SACEA,MAAM,EACNC,MAAM,EACNC,SAAS,EACTC,eAAe,EACfC,QAAQ,QACH,iBAAiB;AACxB,SAASC,SAAS,EAAEC,QAAQ,QAAQ,QAAQ;AAI5C,MAAMC,QAAQ;IACZC,OAAO;IACPC,UAAU;IACVC,QAAQ;AACV;AAEA;;;;;;CAMC,GACD,OAAO,SAASC,KAAK,EAAEC,OAAO,EAAwB;IACpD,MAAM,EAAEC,cAAc,EAAEC,UAAU,EAAE,GAAGX;IACvC,MAAMY,UAAUF,kBAAkBC;IAClC,MAAME,MAAMJ,WAAWG;IACvB,MAAM,EAAEE,eAAe,EAAE,GAAGf;IAC5B,MAAM,EAAEgB,SAAS,EAAE,GAAGd;IACtB,MAAM,CAACe,QAAQC,UAAU,GAAGd,SAAsB,EAAE;IAEpDD,UAAU;QACR,IAAI,CAACW,KAAK;QACV,MAAMK,SAAS,IAAIC,gBAAgB;YACjC,2BAA2BN;YAC3BO,OAAO;YACPC,OAAO;YACPC,MAAM;YACN,iBAAiB;YACjB,gBAAgB;YAChB,mBAAmB;QACrB;QACA,IAAIC,YAAY;QAChBC,MAAM,CAAC,YAAY,EAAEN,QAAQ,EAAE;YAAEO,aAAa;QAAU,GACrDC,IAAI,CAACC,CAAAA,MAAQA,IAAIC,EAAE,GAAGD,IAAIE,IAAI,KAAK;gBAAEC,MAAM,EAAE;YAAC,GAC9CJ,IAAI,CACH,CAACK,OACC,CAACR,aAAaN,UAAUc,KAAKD,IAAI,IAAI,EAAE,GAE1CE,KAAK,CAAC,IAAM,CAACT,aAAaN,UAAU,EAAE;QACzC,OAAO;YACLM,YAAY;QACd;IACF,GAAG;QAACV;KAAI;IAER,IAAI,CAACA,OAAOG,OAAOiB,MAAM,KAAK,GAAG,OAAO;IAExC,IAAIC,QAAQrB;IACZ,IAAI,CAACJ,WAAWG,SAAS;QACvB,MAAMuB,SAASrB,gBACbJ,iBAAiB;YAAEA;QAAe,IAAI;YAAEC,YAAYC;QAAQ;QAE9D,MAAMwB,MAAMD,QAAQE,QAAQC,UAAUH,QAAQD;QAC9C,IAAI,OAAOE,QAAQ,UAAUF,QAAQE;IACvC;IACA,MAAMG,aAAa,CAAC,WAAW,EAAE1B,KAAK;IAEtC,qBACE;;0BACE,KAAChB;gBACC2C,aAAY;gBACZC,MAAK;gBACLlC,QAAQ;gBACRmC,SAAS,IAAM3B,UAAUwB;0BAC1B;;0BAGD,MAACzC;gBAAO6C,MAAMJ;gBAAYK,OAAO,CAAC,UAAU,EAAEV,OAAO;;kCACnD,KAACW;wBACCC,OAAO;4BACLC,WAAW;4BACXxC,QAAQ;4BACRyC,SAAS;4BACTC,SAAS;4BACTC,eAAe;4BACfC,KAAK;wBACP;kCAECnC,OAAOoC,GAAG,CAACC,CAAAA,kBACV,MAACC;;kDACC,KAACC;wCAAEC,MAAM,CAAC,cAAc,EAAEH,EAAEV,IAAI,EAAE;wCAAEG,OAAO;4CAAEW,YAAY;wCAAI;kDAC1DJ,EAAET,KAAK;;kDAEV,KAACc;wCAAEZ,OAAO1C;kDAAQiD,EAAEM,OAAO;;;+BAJpBN,EAAEV,IAAI;;kCAQnB,KAACe;wBAAEZ,OAAO;4BAAEc,WAAW;wBAAS;kCAC9B,cAAA,KAACL;4BAAEC,MAAK;sCAAgB;;;;;;;AAKlC;AAEA,8EAA8E,GAC9E,OAAO,MAAMK,aAAa,kBAAM,KAACrD,UAAQ"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/exports/client.ts"],"sourcesContent":["export { GuidesNavLink } from '../components/GuidesNavLink.js'
|
|
1
|
+
{"version":3,"sources":["../../src/exports/client.ts"],"sourcesContent":["export { GuidesNavLink } from '../components/GuidesNavLink.js';\nexport { Help, HelpButton } from '../components/Help.js';\n"],"names":["GuidesNavLink","Help","HelpButton"],"mappings":"AAAA,SAASA,aAAa,QAAQ,iCAAiC;AAC/D,SAASC,IAAI,EAAEC,UAAU,QAAQ,wBAAwB"}
|
package/dist/exports/rsc.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/exports/rsc.ts"],"sourcesContent":["export { GuidesView } from '../components/GuidesView.js'
|
|
1
|
+
{"version":3,"sources":["../../src/exports/rsc.ts"],"sourcesContent":["export { GuidesView } from '../components/GuidesView.js';\n"],"names":["GuidesView"],"mappings":"AAAA,SAASA,UAAU,QAAQ,8BAA8B"}
|
package/dist/hub.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
/**
|
|
2
|
-
export declare const PLUGIN_VERSION = "0.1.
|
|
1
|
+
/** Synced from package.json by `pnpm version-packages` (scripts/sync-plugin-version.mjs); a unit test checks it. */
|
|
2
|
+
export declare const PLUGIN_VERSION = "0.1.1";
|
|
3
3
|
export declare const GUIDES_SLUG = "guides";
|
|
4
4
|
export declare const SITE_GUIDES_SLUG = "site-guides";
|
|
5
5
|
export declare const SIGNATURE_HEADER = "x-guides-signature";
|
package/dist/hub.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import crypto from 'crypto';
|
|
2
|
-
/**
|
|
1
|
+
import crypto from 'node:crypto';
|
|
2
|
+
/** Synced from package.json by `pnpm version-packages` (scripts/sync-plugin-version.mjs); a unit test checks it. */ export const PLUGIN_VERSION = '0.1.1';
|
|
3
3
|
export const GUIDES_SLUG = 'guides';
|
|
4
4
|
export const SITE_GUIDES_SLUG = 'site-guides';
|
|
5
5
|
export const SIGNATURE_HEADER = 'x-guides-signature';
|
package/dist/hub.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/hub.ts"],"sourcesContent":["import crypto from 'crypto'
|
|
1
|
+
{"version":3,"sources":["../src/hub.ts"],"sourcesContent":["import crypto from 'node:crypto';\n\n/** Synced from package.json by `pnpm version-packages` (scripts/sync-plugin-version.mjs); a unit test checks it. */\nexport const PLUGIN_VERSION = '0.1.1';\n\nexport const GUIDES_SLUG = 'guides';\nexport const SITE_GUIDES_SLUG = 'site-guides';\nexport const SIGNATURE_HEADER = 'x-guides-signature';\n\nexport type GuidesPluginConfig = {\n /** The guides hub's URL. Default `process.env.GUIDES_HUB_URL`. */\n hubURL?: string;\n /** This site's guides key, from its Sites record in the hub. Default `process.env.GUIDES_HUB_KEY`. */\n siteKey?: string;\n /** Feature keys this site has, reported to the hub on every sync so Umi can check its Sites record. */\n features?: string[];\n /** Who can write site-specific guides here (Umi staff). Default: nobody. */\n canAuthor?: (user: unknown) => boolean;\n /**\n * Cron (Payload's 6-field form, seconds first) for the backstop pull, run by Payload jobs on\n * the `default` queue. Default hourly, `0 0 * * * *`; `false` turns it off.\n */\n schedule?: string | false;\n disabled?: boolean;\n};\n\nexport type ResolvedConfig = {\n hubURL?: string;\n siteKey?: string;\n features: string[];\n canAuthor: (user: unknown) => boolean;\n schedule: string | false;\n};\n\n// Env is read when the hub is called, not when the plugin is registered, so config built before\n// env loads (or a rotated key) still works.\nexport const resolveConfig = (options: GuidesPluginConfig): ResolvedConfig => ({\n get hubURL() {\n return options.hubURL ?? process.env.GUIDES_HUB_URL;\n },\n get siteKey() {\n return options.siteKey ?? process.env.GUIDES_HUB_KEY;\n },\n features: options.features ?? [],\n canAuthor: options.canAuthor ?? (() => false),\n schedule: options.schedule ?? '0 0 * * * *',\n});\n\n/** A request to the hub, authenticated as this site. */\nexport const hubFetch = async (\n config: ResolvedConfig,\n path: string,\n init: RequestInit = {}\n) => {\n if (!config.hubURL || !config.siteKey) {\n throw new Error(\n 'Set GUIDES_HUB_URL and GUIDES_HUB_KEY (or the hubURL and siteKey options) to reach the guides hub.'\n );\n }\n return fetch(new URL(path, config.hubURL), {\n ...init,\n headers: {\n 'content-type': 'application/json',\n authorization: `sites API-Key ${config.siteKey}`,\n ...init.headers,\n },\n signal: AbortSignal.timeout(10_000),\n });\n};\n\n/** True when the header is the hub's HMAC of this exact body, keyed with this site's guides key. */\nexport const verifySignature = (\n key: string,\n body: string,\n header: string | null\n) => {\n if (!header) return false;\n const expected = Buffer.from(\n `sha256=${crypto.createHmac('sha256', key).update(body).digest('hex')}`\n );\n const received = Buffer.from(header);\n return (\n received.length === expected.length &&\n crypto.timingSafeEqual(received, expected)\n );\n};\n"],"names":["crypto","PLUGIN_VERSION","GUIDES_SLUG","SITE_GUIDES_SLUG","SIGNATURE_HEADER","resolveConfig","options","hubURL","process","env","GUIDES_HUB_URL","siteKey","GUIDES_HUB_KEY","features","canAuthor","schedule","hubFetch","config","path","init","Error","fetch","URL","headers","authorization","signal","AbortSignal","timeout","verifySignature","key","body","header","expected","Buffer","from","createHmac","update","digest","received","length","timingSafeEqual"],"mappings":"AAAA,OAAOA,YAAY,cAAc;AAEjC,kHAAkH,GAClH,OAAO,MAAMC,iBAAiB,QAAQ;AAEtC,OAAO,MAAMC,cAAc,SAAS;AACpC,OAAO,MAAMC,mBAAmB,cAAc;AAC9C,OAAO,MAAMC,mBAAmB,qBAAqB;AA2BrD,gGAAgG;AAChG,4CAA4C;AAC5C,OAAO,MAAMC,gBAAgB,CAACC,UAAiD,CAAA;QAC7E,IAAIC,UAAS;YACX,OAAOD,QAAQC,MAAM,IAAIC,QAAQC,GAAG,CAACC,cAAc;QACrD;QACA,IAAIC,WAAU;YACZ,OAAOL,QAAQK,OAAO,IAAIH,QAAQC,GAAG,CAACG,cAAc;QACtD;QACAC,UAAUP,QAAQO,QAAQ,IAAI,EAAE;QAChCC,WAAWR,QAAQQ,SAAS,IAAK,CAAA,IAAM,KAAI;QAC3CC,UAAUT,QAAQS,QAAQ,IAAI;IAChC,CAAA,EAAG;AAEH,sDAAsD,GACtD,OAAO,MAAMC,WAAW,OACtBC,QACAC,MACAC,OAAoB,CAAC,CAAC;IAEtB,IAAI,CAACF,OAAOV,MAAM,IAAI,CAACU,OAAON,OAAO,EAAE;QACrC,MAAM,IAAIS,MACR;IAEJ;IACA,OAAOC,MAAM,IAAIC,IAAIJ,MAAMD,OAAOV,MAAM,GAAG;QACzC,GAAGY,IAAI;QACPI,SAAS;YACP,gBAAgB;YAChBC,eAAe,CAAC,cAAc,EAAEP,OAAON,OAAO,EAAE;YAChD,GAAGQ,KAAKI,OAAO;QACjB;QACAE,QAAQC,YAAYC,OAAO,CAAC;IAC9B;AACF,EAAE;AAEF,kGAAkG,GAClG,OAAO,MAAMC,kBAAkB,CAC7BC,KACAC,MACAC;IAEA,IAAI,CAACA,QAAQ,OAAO;IACpB,MAAMC,WAAWC,OAAOC,IAAI,CAC1B,CAAC,OAAO,EAAElC,OAAOmC,UAAU,CAAC,UAAUN,KAAKO,MAAM,CAACN,MAAMO,MAAM,CAAC,QAAQ;IAEzE,MAAMC,WAAWL,OAAOC,IAAI,CAACH;IAC7B,OACEO,SAASC,MAAM,KAAKP,SAASO,MAAM,IACnCvC,OAAOwC,eAAe,CAACF,UAAUN;AAErC,EAAE"}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { Config } from 'payload';
|
|
2
2
|
import { type GuidesPluginConfig } from './hub.js';
|
|
3
|
-
export type { GuidesPluginConfig, GuidesPluginConfig as PluginConfig } from './hub.js';
|
|
3
|
+
export type { GuidesPluginConfig, GuidesPluginConfig as PluginConfig, } from './hub.js';
|
|
4
4
|
export { syncGuides } from './sync.js';
|
|
5
5
|
/**
|
|
6
6
|
* CMS guides from the Umi guides hub: a Guides page in the sidebar, a Help button on every edit
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/index.ts"],"sourcesContent":["import type {
|
|
1
|
+
{"version":3,"sources":["../src/index.ts"],"sourcesContent":["import type {\n CollectionConfig,\n Config,\n GlobalConfig,\n Payload,\n TaskConfig,\n} from 'payload';\n\nimport { guidesCollection } from './collections/guides.js';\nimport { siteGuidesCollection } from './collections/siteGuides.js';\nimport {\n GUIDES_SLUG,\n type GuidesPluginConfig,\n type ResolvedConfig,\n resolveConfig,\n SITE_GUIDES_SLUG,\n} from './hub.js';\nimport { syncGuides } from './sync.js';\n\nexport type {\n GuidesPluginConfig,\n GuidesPluginConfig as PluginConfig,\n} from './hub.js';\nexport { syncGuides } from './sync.js';\n\nconst HELP_BUTTON = '@foundrykit/guides-plugin/client#HelpButton';\n\nconst skipHelp = (slug: string) =>\n slug === GUIDES_SLUG ||\n slug === SITE_GUIDES_SLUG ||\n slug === 'users' ||\n slug.startsWith('payload-');\n\n// Payload reads beforeDocumentControls from `edit` on collections but from `elements` on globals\n// (@payloadcms/next views/Document/renderDocumentSlots), so the slot depends on the kind.\nconst withHelp =\n <T extends CollectionConfig | GlobalConfig>(slot: 'edit' | 'elements') =>\n (entry: T): T => {\n if (skipHelp(entry.slug)) return entry;\n const components = (entry.admin?.components ?? {}) as Record<\n string,\n { beforeDocumentControls?: unknown[] }\n >;\n const current = components[slot] ?? {};\n return {\n ...entry,\n admin: {\n ...entry.admin,\n components: {\n ...components,\n [slot]: {\n ...current,\n beforeDocumentControls: [\n ...(current.beforeDocumentControls ?? []),\n HELP_BUTTON,\n ],\n },\n },\n },\n } as T;\n };\n\nconst syncTask = (config: ResolvedConfig): TaskConfig => ({\n slug: 'guidesSync',\n label: 'Sync guides from the hub',\n handler: async ({ req }) => ({\n output: await syncGuides(req.payload, config),\n }),\n ...(config.schedule\n ? { schedule: [{ cron: config.schedule, queue: 'default' }] }\n : {}),\n});\n\n/** Fills an empty local copy on first boot, without holding startup up or failing it. */\nconst syncIfEmpty = async (payload: Payload, config: ResolvedConfig) => {\n try {\n const { totalDocs } = await payload.count({\n collection: GUIDES_SLUG as never,\n });\n if (totalDocs === 0) await syncGuides(payload, config);\n } catch (err) {\n payload.logger.warn(\n { err },\n 'Guides: first sync from the hub failed; the next webhook or scheduled pull will retry.'\n );\n }\n};\n\n/**\n * CMS guides from the Umi guides hub: a Guides page in the sidebar, a Help button on every edit\n * page, and local search, all read from a local copy the hub keeps in sync. Umi staff\n * (`canAuthor`) write site-specific guides in the Site guides collection; publishing saves\n * them to the hub.\n */\nexport const guidesPlugin =\n (options: GuidesPluginConfig = {}) =>\n (config: Config): Config => {\n if (options.disabled) return config;\n const resolved = resolveConfig(options);\n const components = config.admin?.components ?? {};\n const onInit = config.onInit;\n\n return {\n ...config,\n collections: [\n ...(config.collections ?? []).map(withHelp<CollectionConfig>('edit')),\n guidesCollection(resolved),\n siteGuidesCollection(resolved),\n ],\n globals: (config.globals ?? []).map(withHelp<GlobalConfig>('elements')),\n admin: {\n ...config.admin,\n components: {\n ...components,\n afterNavLinks: [\n ...(components.afterNavLinks ?? []),\n '@foundrykit/guides-plugin/client#GuidesNavLink',\n ],\n views: {\n ...components.views,\n guides: {\n Component: '@foundrykit/guides-plugin/rsc#GuidesView',\n path: '/guides',\n meta: { title: 'Guides' },\n },\n },\n },\n },\n jobs: {\n ...config.jobs,\n tasks: [...(config.jobs?.tasks ?? []), syncTask(resolved)],\n },\n onInit: async payload => {\n await onInit?.(payload);\n void syncIfEmpty(payload, resolved);\n },\n };\n };\n\nexport default guidesPlugin;\n"],"names":["guidesCollection","siteGuidesCollection","GUIDES_SLUG","resolveConfig","SITE_GUIDES_SLUG","syncGuides","HELP_BUTTON","skipHelp","slug","startsWith","withHelp","slot","entry","components","admin","current","beforeDocumentControls","syncTask","config","label","handler","req","output","payload","schedule","cron","queue","syncIfEmpty","totalDocs","count","collection","err","logger","warn","guidesPlugin","options","disabled","resolved","onInit","collections","map","globals","afterNavLinks","views","guides","Component","path","meta","title","jobs","tasks"],"mappings":"AAQA,SAASA,gBAAgB,QAAQ,0BAA0B;AAC3D,SAASC,oBAAoB,QAAQ,8BAA8B;AACnE,SACEC,WAAW,EAGXC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AAI,CACjB;YAAEF;QAAI,GACN;IAEJ;AACF;AAEA;;;;;CAKC,GACD,OAAO,MAAMG,eACX,CAACC,UAA8B,CAAC,CAAC,GACjC,CAACjB;QACC,IAAIiB,QAAQC,QAAQ,EAAE,OAAOlB;QAC7B,MAAMmB,WAAWlC,cAAcgC;QAC/B,MAAMtB,aAAaK,OAAOJ,KAAK,EAAED,cAAc,CAAC;QAChD,MAAMyB,SAASpB,OAAOoB,MAAM;QAE5B,OAAO;YACL,GAAGpB,MAAM;YACTqB,aAAa;mBACR,AAACrB,CAAAA,OAAOqB,WAAW,IAAI,EAAE,AAAD,EAAGC,GAAG,CAAC9B,SAA2B;gBAC7DV,iBAAiBqC;gBACjBpC,qBAAqBoC;aACtB;YACDI,SAAS,AAACvB,CAAAA,OAAOuB,OAAO,IAAI,EAAE,AAAD,EAAGD,GAAG,CAAC9B,SAAuB;YAC3DI,OAAO;gBACL,GAAGI,OAAOJ,KAAK;gBACfD,YAAY;oBACV,GAAGA,UAAU;oBACb6B,eAAe;2BACT7B,WAAW6B,aAAa,IAAI,EAAE;wBAClC;qBACD;oBACDC,OAAO;wBACL,GAAG9B,WAAW8B,KAAK;wBACnBC,QAAQ;4BACNC,WAAW;4BACXC,MAAM;4BACNC,MAAM;gCAAEC,OAAO;4BAAS;wBAC1B;oBACF;gBACF;YACF;YACAC,MAAM;gBACJ,GAAG/B,OAAO+B,IAAI;gBACdC,OAAO;uBAAKhC,OAAO+B,IAAI,EAAEC,SAAS,EAAE;oBAAGjC,SAASoB;iBAAU;YAC5D;YACAC,QAAQ,OAAMf;gBACZ,MAAMe,SAASf;gBACf,KAAKI,YAAYJ,SAASc;YAC5B;QACF;IACF,EAAE;AAEJ,eAAeH,aAAa"}
|
package/dist/searchGuides.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/searchGuides.ts"],"sourcesContent":["import Fuse from 'fuse.js'
|
|
1
|
+
{"version":3,"sources":["../src/searchGuides.ts"],"sourcesContent":["import Fuse from 'fuse.js';\n\nexport type GuideHit = {\n slug: string;\n title: string;\n summary: string;\n bodyText: string;\n};\n\nconst STOP_WORDS = new Set([\n 'how',\n 'do',\n 'i',\n 'the',\n 'a',\n 'an',\n 'to',\n 'in',\n 'on',\n 'my',\n 'of',\n 'for',\n 'is',\n 'can',\n]);\nconst LIMIT = 8;\n\n/**\n * Plain-question search over the guides (threshold 0.2, 3-char minimum, as tuned on Turquoise).\n * Each remaining word is matched on its own and the scores summed, so \"how do I take an offer\n * down\" ranks by \"take\", \"offer\", \"down\" rather than needing the whole phrase to appear.\n */\nexport const searchGuides = <T extends GuideHit>(\n guides: T[],\n query: string\n): T[] => {\n const words = query\n .toLowerCase()\n .split(/[^a-z0-9']+/)\n .filter(w => w.length >= 3 && !STOP_WORDS.has(w));\n if (words.length === 0) return [];\n\n const fuse = new Fuse(guides, {\n threshold: 0.2,\n minMatchCharLength: 3,\n ignoreLocation: true,\n includeScore: true,\n keys: [\n { name: 'title', weight: 3 },\n { name: 'summary', weight: 2 },\n { name: 'bodyText', weight: 1 },\n ],\n });\n\n // Lower Fuse score is better; a word that matches nothing contributes nothing.\n const totals = new Map<string, { guide: T; score: number }>();\n for (const word of words) {\n for (const { item, score = 1 } of fuse.search(word)) {\n const entry = totals.get(item.slug) ?? { guide: item, score: 0 };\n entry.score += 1 - score;\n totals.set(item.slug, entry);\n }\n }\n\n return [...totals.values()]\n .sort((a, b) => b.score - a.score)\n .slice(0, LIMIT)\n .map(e => e.guide);\n};\n"],"names":["Fuse","STOP_WORDS","Set","LIMIT","searchGuides","guides","query","words","toLowerCase","split","filter","w","length","has","fuse","threshold","minMatchCharLength","ignoreLocation","includeScore","keys","name","weight","totals","Map","word","item","score","search","entry","get","slug","guide","set","values","sort","a","b","slice","map","e"],"mappings":"AAAA,OAAOA,UAAU,UAAU;AAS3B,MAAMC,aAAa,IAAIC,IAAI;IACzB;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;CACD;AACD,MAAMC,QAAQ;AAEd;;;;CAIC,GACD,OAAO,MAAMC,eAAe,CAC1BC,QACAC;IAEA,MAAMC,QAAQD,MACXE,WAAW,GACXC,KAAK,CAAC,eACNC,MAAM,CAACC,CAAAA,IAAKA,EAAEC,MAAM,IAAI,KAAK,CAACX,WAAWY,GAAG,CAACF;IAChD,IAAIJ,MAAMK,MAAM,KAAK,GAAG,OAAO,EAAE;IAEjC,MAAME,OAAO,IAAId,KAAKK,QAAQ;QAC5BU,WAAW;QACXC,oBAAoB;QACpBC,gBAAgB;QAChBC,cAAc;QACdC,MAAM;YACJ;gBAAEC,MAAM;gBAASC,QAAQ;YAAE;YAC3B;gBAAED,MAAM;gBAAWC,QAAQ;YAAE;YAC7B;gBAAED,MAAM;gBAAYC,QAAQ;YAAE;SAC/B;IACH;IAEA,+EAA+E;IAC/E,MAAMC,SAAS,IAAIC;IACnB,KAAK,MAAMC,QAAQjB,MAAO;QACxB,KAAK,MAAM,EAAEkB,IAAI,EAAEC,QAAQ,CAAC,EAAE,IAAIZ,KAAKa,MAAM,CAACH,MAAO;YACnD,MAAMI,QAAQN,OAAOO,GAAG,CAACJ,KAAKK,IAAI,KAAK;gBAAEC,OAAON;gBAAMC,OAAO;YAAE;YAC/DE,MAAMF,KAAK,IAAI,IAAIA;YACnBJ,OAAOU,GAAG,CAACP,KAAKK,IAAI,EAAEF;QACxB;IACF;IAEA,OAAO;WAAIN,OAAOW,MAAM;KAAG,CACxBC,IAAI,CAAC,CAACC,GAAGC,IAAMA,EAAEV,KAAK,GAAGS,EAAET,KAAK,EAChCW,KAAK,CAAC,GAAGlC,OACTmC,GAAG,CAACC,CAAAA,IAAKA,EAAER,KAAK;AACrB,EAAE"}
|
package/dist/sync.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/sync.ts"],"sourcesContent":["import type { Payload } from 'payload'
|
|
1
|
+
{"version":3,"sources":["../src/sync.ts"],"sourcesContent":["import type { Payload } from 'payload';\n\nimport {\n GUIDES_SLUG,\n hubFetch,\n PLUGIN_VERSION,\n type ResolvedConfig,\n} from './hub.js';\n\n/** One guide as the hub's feed sends it. */\nexport type FeedGuide = {\n id: number | string;\n title: string;\n slug: string;\n summary: string;\n scope: 'general' | 'site';\n topic: { title?: string; order?: number | null } | null;\n helpContexts: string[];\n order: number | null;\n body: unknown;\n bodyText: string;\n updatedAt: string;\n};\n\nconst toLocal = (g: FeedGuide) => ({\n hubId: String(g.id),\n title: g.title,\n slug: g.slug,\n summary: g.summary,\n scope: g.scope,\n topic: { title: g.topic?.title ?? null, order: g.topic?.order ?? null },\n helpContexts: g.helpContexts,\n order: g.order,\n body: g.body,\n bodyText: g.bodyText,\n hubUpdatedAt: g.updatedAt,\n});\n\n/**\n * Makes the local guides collection match this site's feed from the hub: adds new guides,\n * updates changed ones and removes any the site is no longer entitled to. Reports the plugin\n * version and features on the way, so the hub's Sites record stays current.\n */\nexport const syncGuides = async (payload: Payload, config: ResolvedConfig) => {\n const params = new URLSearchParams({\n pluginVersion: PLUGIN_VERSION,\n features: config.features.join(','),\n });\n const res = await hubFetch(config, `/api/sites/feed?${params}`);\n if (!res.ok)\n throw new Error(\n `The guides hub answered ${res.status} to the feed request.`\n );\n const { guides } = (await res.json()) as { guides: FeedGuide[] };\n\n const { docs } = await payload.find({\n collection: GUIDES_SLUG as never,\n pagination: false,\n depth: 0,\n select: { hubId: true, hubUpdatedAt: true } as never,\n });\n const local = new Map(\n (docs as { id: number; hubId: string; hubUpdatedAt?: string }[]).map(d => [\n d.hubId,\n d,\n ])\n );\n\n let changed = 0;\n for (const guide of guides) {\n const existing = local.get(String(guide.id));\n local.delete(String(guide.id));\n if (existing?.hubUpdatedAt === guide.updatedAt) continue;\n const data = toLocal(guide) as never;\n if (existing)\n await payload.update({\n collection: GUIDES_SLUG as never,\n id: existing.id,\n data,\n });\n else await payload.create({ collection: GUIDES_SLUG as never, data });\n changed++;\n }\n for (const stale of local.values())\n await payload.delete({ collection: GUIDES_SLUG as never, id: stale.id });\n\n return { changed, removed: local.size, total: guides.length };\n};\n"],"names":["GUIDES_SLUG","hubFetch","PLUGIN_VERSION","toLocal","g","hubId","String","id","title","slug","summary","scope","topic","order","helpContexts","body","bodyText","hubUpdatedAt","updatedAt","syncGuides","payload","config","params","URLSearchParams","pluginVersion","features","join","res","ok","Error","status","guides","json","docs","find","collection","pagination","depth","select","local","Map","map","d","changed","guide","existing","get","delete","data","update","create","stale","values","removed","size","total","length"],"mappings":"AAEA,SACEA,WAAW,EACXC,QAAQ,EACRC,cAAc,QAET,WAAW;AAiBlB,MAAMC,UAAU,CAACC,IAAkB,CAAA;QACjCC,OAAOC,OAAOF,EAAEG,EAAE;QAClBC,OAAOJ,EAAEI,KAAK;QACdC,MAAML,EAAEK,IAAI;QACZC,SAASN,EAAEM,OAAO;QAClBC,OAAOP,EAAEO,KAAK;QACdC,OAAO;YAAEJ,OAAOJ,EAAEQ,KAAK,EAAEJ,SAAS;YAAMK,OAAOT,EAAEQ,KAAK,EAAEC,SAAS;QAAK;QACtEC,cAAcV,EAAEU,YAAY;QAC5BD,OAAOT,EAAES,KAAK;QACdE,MAAMX,EAAEW,IAAI;QACZC,UAAUZ,EAAEY,QAAQ;QACpBC,cAAcb,EAAEc,SAAS;IAC3B,CAAA;AAEA;;;;CAIC,GACD,OAAO,MAAMC,aAAa,OAAOC,SAAkBC;IACjD,MAAMC,SAAS,IAAIC,gBAAgB;QACjCC,eAAetB;QACfuB,UAAUJ,OAAOI,QAAQ,CAACC,IAAI,CAAC;IACjC;IACA,MAAMC,MAAM,MAAM1B,SAASoB,QAAQ,CAAC,gBAAgB,EAAEC,QAAQ;IAC9D,IAAI,CAACK,IAAIC,EAAE,EACT,MAAM,IAAIC,MACR,CAAC,wBAAwB,EAAEF,IAAIG,MAAM,CAAC,qBAAqB,CAAC;IAEhE,MAAM,EAAEC,MAAM,EAAE,GAAI,MAAMJ,IAAIK,IAAI;IAElC,MAAM,EAAEC,IAAI,EAAE,GAAG,MAAMb,QAAQc,IAAI,CAAC;QAClCC,YAAYnC;QACZoC,YAAY;QACZC,OAAO;QACPC,QAAQ;YAAEjC,OAAO;YAAMY,cAAc;QAAK;IAC5C;IACA,MAAMsB,QAAQ,IAAIC,IAChB,AAACP,KAAgEQ,GAAG,CAACC,CAAAA,IAAK;YACxEA,EAAErC,KAAK;YACPqC;SACD;IAGH,IAAIC,UAAU;IACd,KAAK,MAAMC,SAASb,OAAQ;QAC1B,MAAMc,WAAWN,MAAMO,GAAG,CAACxC,OAAOsC,MAAMrC,EAAE;QAC1CgC,MAAMQ,MAAM,CAACzC,OAAOsC,MAAMrC,EAAE;QAC5B,IAAIsC,UAAU5B,iBAAiB2B,MAAM1B,SAAS,EAAE;QAChD,MAAM8B,OAAO7C,QAAQyC;QACrB,IAAIC,UACF,MAAMzB,QAAQ6B,MAAM,CAAC;YACnBd,YAAYnC;YACZO,IAAIsC,SAAStC,EAAE;YACfyC;QACF;aACG,MAAM5B,QAAQ8B,MAAM,CAAC;YAAEf,YAAYnC;YAAsBgD;QAAK;QACnEL;IACF;IACA,KAAK,MAAMQ,SAASZ,MAAMa,MAAM,GAC9B,MAAMhC,QAAQ2B,MAAM,CAAC;QAAEZ,YAAYnC;QAAsBO,IAAI4C,MAAM5C,EAAE;IAAC;IAExE,OAAO;QAAEoC;QAASU,SAASd,MAAMe,IAAI;QAAEC,OAAOxB,OAAOyB,MAAM;IAAC;AAC9D,EAAE"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@foundrykit/guides-plugin",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.1",
|
|
4
4
|
"description": "CMS guides for Payload 3 client sites: a Guides page, Help buttons on edit pages and local search, synced read-only from the Umi guides hub, with site-specific guides written in place by Umi staff.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|
|
@@ -8,7 +8,14 @@
|
|
|
8
8
|
"name": "Isaac SJ",
|
|
9
9
|
"email": "isaac@umidigital.co.uk"
|
|
10
10
|
},
|
|
11
|
-
"keywords": [
|
|
11
|
+
"keywords": [
|
|
12
|
+
"payload",
|
|
13
|
+
"payloadcms",
|
|
14
|
+
"plugin",
|
|
15
|
+
"guides",
|
|
16
|
+
"help",
|
|
17
|
+
"documentation"
|
|
18
|
+
],
|
|
12
19
|
"exports": {
|
|
13
20
|
".": {
|
|
14
21
|
"import": "./dist/index.js",
|
|
@@ -28,29 +35,9 @@
|
|
|
28
35
|
},
|
|
29
36
|
"main": "./dist/index.js",
|
|
30
37
|
"types": "./dist/index.d.ts",
|
|
31
|
-
"files": [
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
"build:swc": "swc ./src -d ./dist --config-file .swcrc --strip-leading-paths --ignore \"**/*.test.ts\" --ignore \"**/*.test.tsx\" --ignore \"**/*.d.ts\"",
|
|
35
|
-
"build:types": "tsc --outDir dist --rootDir ./src",
|
|
36
|
-
"clean": "rimraf {dist,*.tsbuildinfo}",
|
|
37
|
-
"copyfiles": "copyfiles -u 1 \"src/**/*.{html,css,scss,ttf,woff,woff2,eot,svg,jpg,png,json}\" dist/",
|
|
38
|
-
"dev": "next dev dev",
|
|
39
|
-
"dev:generate-importmap": "pnpm dev:payload generate:importmap",
|
|
40
|
-
"dev:generate-types": "pnpm dev:payload generate:types",
|
|
41
|
-
"dev:payload": "cross-env PAYLOAD_CONFIG_PATH=./dev/payload.config.ts payload",
|
|
42
|
-
"generate:importmap": "pnpm dev:generate-importmap",
|
|
43
|
-
"generate:types": "pnpm dev:generate-types",
|
|
44
|
-
"lint": "eslint",
|
|
45
|
-
"lint:fix": "eslint ./src --fix",
|
|
46
|
-
"prepublishOnly": "pnpm build && node scripts/verify-pack.mjs",
|
|
47
|
-
"verify:pack": "node scripts/verify-pack.mjs",
|
|
48
|
-
"release": "release-it",
|
|
49
|
-
"test": "pnpm test:unit && pnpm test:int",
|
|
50
|
-
"test:unit": "vitest run src",
|
|
51
|
-
"test:int": "vitest run dev/int.spec.ts",
|
|
52
|
-
"release:dry": "release-it --dry-run"
|
|
53
|
-
},
|
|
38
|
+
"files": [
|
|
39
|
+
"dist"
|
|
40
|
+
],
|
|
54
41
|
"dependencies": {
|
|
55
42
|
"fuse.js": "7.5.0"
|
|
56
43
|
},
|
|
@@ -59,7 +46,6 @@
|
|
|
59
46
|
"@payloadcms/next": "3.84.1",
|
|
60
47
|
"@payloadcms/richtext-lexical": "3.84.1",
|
|
61
48
|
"@payloadcms/ui": "3.84.1",
|
|
62
|
-
"@release-it/conventional-changelog": "^11.0.1",
|
|
63
49
|
"@swc-node/register": "1.10.9",
|
|
64
50
|
"@swc/cli": "0.6.0",
|
|
65
51
|
"@testing-library/react": "16.3.0",
|
|
@@ -68,19 +54,17 @@
|
|
|
68
54
|
"@types/react-dom": "19.2.3",
|
|
69
55
|
"copyfiles": "2.4.1",
|
|
70
56
|
"cross-env": "^7.0.3",
|
|
71
|
-
"eslint": "^9",
|
|
72
57
|
"graphql": "^16.8.1",
|
|
73
58
|
"jsdom": "26.1.0",
|
|
74
59
|
"next": "16.2.6",
|
|
75
60
|
"payload": "3.84.1",
|
|
76
61
|
"react": "19.2.6",
|
|
77
62
|
"react-dom": "19.2.6",
|
|
78
|
-
"release-it": "^20.2.1",
|
|
79
63
|
"rimraf": "3.0.2",
|
|
80
64
|
"sharp": "0.34.2",
|
|
81
|
-
"typescript": "5.
|
|
65
|
+
"typescript": "5.9.2",
|
|
82
66
|
"vite-tsconfig-paths": "6.0.5",
|
|
83
|
-
"vitest": "4.
|
|
67
|
+
"vitest": "4.1.10"
|
|
84
68
|
},
|
|
85
69
|
"peerDependencies": {
|
|
86
70
|
"@payloadcms/next": "^3.37.0",
|
|
@@ -91,22 +75,35 @@
|
|
|
91
75
|
"react": "^19"
|
|
92
76
|
},
|
|
93
77
|
"engines": {
|
|
94
|
-
"node": "
|
|
95
|
-
"pnpm": "^9 || ^10"
|
|
78
|
+
"node": ">=20.9.0"
|
|
96
79
|
},
|
|
97
80
|
"publishConfig": {
|
|
98
81
|
"access": "public"
|
|
99
82
|
},
|
|
100
|
-
"pnpm": {
|
|
101
|
-
"onlyBuiltDependencies": ["sharp", "esbuild", "unrs-resolver"]
|
|
102
|
-
},
|
|
103
|
-
"registry": "https://registry.npmjs.org/",
|
|
104
83
|
"repository": {
|
|
105
84
|
"type": "git",
|
|
106
|
-
"url": "https://github.com/umi-labs/
|
|
85
|
+
"url": "git+https://github.com/umi-labs/foundry.git",
|
|
86
|
+
"directory": "packages/payload/guides-plugin"
|
|
107
87
|
},
|
|
108
|
-
"homepage": "https://github.com/umi-labs/guides-plugin#readme",
|
|
88
|
+
"homepage": "https://github.com/umi-labs/foundry/tree/prod/packages/payload/guides-plugin#readme",
|
|
109
89
|
"bugs": {
|
|
110
|
-
"url": "https://github.com/umi-labs/
|
|
90
|
+
"url": "https://github.com/umi-labs/foundry/issues"
|
|
91
|
+
},
|
|
92
|
+
"scripts": {
|
|
93
|
+
"build": "pnpm copyfiles && pnpm build:types && pnpm build:swc",
|
|
94
|
+
"build:swc": "swc ./src -d ./dist --config-file .swcrc --strip-leading-paths --ignore \"**/*.test.ts\" --ignore \"**/*.test.tsx\" --ignore \"**/*.d.ts\"",
|
|
95
|
+
"build:types": "tsc --outDir dist --rootDir ./src",
|
|
96
|
+
"clean": "rimraf {dist,*.tsbuildinfo}",
|
|
97
|
+
"copyfiles": "copyfiles -u 1 \"src/**/*.{html,css,scss,ttf,woff,woff2,eot,svg,jpg,png,json}\" dist/",
|
|
98
|
+
"dev": "next dev dev",
|
|
99
|
+
"dev:generate-importmap": "pnpm dev:payload generate:importmap",
|
|
100
|
+
"dev:generate-types": "pnpm dev:payload generate:types",
|
|
101
|
+
"dev:payload": "cross-env PAYLOAD_CONFIG_PATH=./dev/payload.config.ts payload",
|
|
102
|
+
"generate:importmap": "pnpm dev:generate-importmap",
|
|
103
|
+
"generate:types": "pnpm dev:generate-types",
|
|
104
|
+
"verify:pack": "node scripts/verify-pack.mjs",
|
|
105
|
+
"test": "pnpm test:unit && pnpm test:int",
|
|
106
|
+
"test:unit": "vitest run src",
|
|
107
|
+
"test:int": "vitest run dev/int.spec.ts"
|
|
111
108
|
}
|
|
112
|
-
}
|
|
109
|
+
}
|