payload-markdown 1.7.2 → 1.8.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 -0
- package/dist/agent/access.d.ts +1 -1
- package/dist/agent/access.js.map +1 -1
- package/dist/agent/guide.d.ts +3 -0
- package/dist/agent/guide.js +28 -2
- package/dist/agent/guide.js.map +1 -1
- package/dist/agent/palettes.d.ts +55 -0
- package/dist/agent/palettes.js +194 -0
- package/dist/agent/palettes.js.map +1 -0
- package/dist/agent/skill.d.ts +2 -2
- package/dist/agent/skill.js +2 -2
- package/dist/agent/skill.js.map +1 -1
- package/dist/agent/validate.d.ts +1 -1
- package/dist/agent/validate.js +3 -0
- package/dist/agent/validate.js.map +1 -1
- package/dist/appearance/PaletteRowLabel.client.d.ts +2 -0
- package/dist/appearance/PaletteRowLabel.client.js +70 -0
- package/dist/appearance/PaletteRowLabel.client.js.map +1 -0
- package/dist/appearance/config.d.ts +8 -0
- package/dist/appearance/config.js +172 -0
- package/dist/appearance/config.js.map +1 -0
- package/dist/appearance/options.d.ts +11 -0
- package/dist/appearance/options.js +15 -0
- package/dist/appearance/options.js.map +1 -0
- package/dist/appearance/runtime.d.ts +25 -0
- package/dist/appearance/runtime.js +126 -0
- package/dist/appearance/runtime.js.map +1 -0
- package/dist/components/MarkdownRenderer/Component.client.js +9 -19
- package/dist/components/MarkdownRenderer/Component.client.js.map +1 -1
- package/dist/components/MarkdownRenderer/Component.js +59 -21
- package/dist/components/MarkdownRenderer/Component.js.map +1 -1
- package/dist/components/MarkdownRenderer/index.css +93 -42
- package/dist/components/MarkdownRenderer/index.scss +128 -57
- package/dist/core/codeToHtml.js +6 -0
- package/dist/core/codeToHtml.js.map +1 -1
- package/dist/core/plugins/directiveBadge.js +2 -0
- package/dist/core/plugins/directiveBadge.js.map +1 -1
- package/dist/core/plugins/directiveButton.d.ts +1 -1
- package/dist/core/plugins/directiveButton.js +26 -6
- package/dist/core/plugins/directiveButton.js.map +1 -1
- package/dist/core/plugins/rehypeContentLayout.d.ts +12 -0
- package/dist/core/plugins/rehypeContentLayout.js +64 -0
- package/dist/core/plugins/rehypeContentLayout.js.map +1 -0
- package/dist/core/plugins/rehypeResolveIcons.js +10 -1
- package/dist/core/plugins/rehypeResolveIcons.js.map +1 -1
- package/dist/core/plugins/remarkHeadingAnchorsAndToc.js +8 -0
- package/dist/core/plugins/remarkHeadingAnchorsAndToc.js.map +1 -1
- package/dist/core/plugins/remarkValidatePalettes.d.ts +9 -0
- package/dist/core/plugins/remarkValidatePalettes.js +51 -0
- package/dist/core/plugins/remarkValidatePalettes.js.map +1 -0
- package/dist/core/renderMarkdown.js +19 -4
- package/dist/core/renderMarkdown.js.map +1 -1
- package/dist/directive-spec.json +60 -0
- package/dist/directives/definitions/button.d.ts +1 -1
- package/dist/directives/definitions/button.js +9 -2
- package/dist/directives/definitions/button.js.map +1 -1
- package/dist/directives/definitions/callout.js +29 -13
- package/dist/directives/definitions/callout.js.map +1 -1
- package/dist/directives/definitions/card.d.ts +2 -2
- package/dist/directives/definitions/card.js +44 -11
- package/dist/directives/definitions/card.js.map +1 -1
- package/dist/directives/definitions/cards.js +19 -6
- package/dist/directives/definitions/cards.js.map +1 -1
- package/dist/directives/definitions/cell.js +4 -2
- package/dist/directives/definitions/cell.js.map +1 -1
- package/dist/directives/definitions/columns.js +2 -1
- package/dist/directives/definitions/columns.js.map +1 -1
- package/dist/directives/definitions/details.js +9 -3
- package/dist/directives/definitions/details.js.map +1 -1
- package/dist/directives/definitions/section.js +5 -1
- package/dist/directives/definitions/section.js.map +1 -1
- package/dist/directives/definitions/steps.js +38 -14
- package/dist/directives/definitions/steps.js.map +1 -1
- package/dist/directives/definitions/tab.js +2 -1
- package/dist/directives/definitions/tab.js.map +1 -1
- package/dist/directives/definitions/tabs.js +13 -6
- package/dist/directives/definitions/tabs.js.map +1 -1
- package/dist/directives/definitions/toc.js +2 -1
- package/dist/directives/definitions/toc.js.map +1 -1
- package/dist/directives/diagnostics.d.ts +5 -0
- package/dist/directives/diagnostics.js +26 -10
- package/dist/directives/diagnostics.js.map +1 -1
- package/dist/directives/iconPlaceholder.d.ts +9 -3
- package/dist/directives/iconPlaceholder.js +8 -1
- package/dist/directives/iconPlaceholder.js.map +1 -1
- package/dist/directives/palette.d.ts +23 -0
- package/dist/directives/palette.js +40 -0
- package/dist/directives/palette.js.map +1 -0
- package/dist/directives/shields.js +16 -3
- package/dist/directives/shields.js.map +1 -1
- package/dist/directives/spec.d.ts +6 -2
- package/dist/directives/spec.js +5 -0
- package/dist/directives/spec.js.map +1 -1
- package/dist/directives/themes.js +13 -13
- package/dist/directives/themes.js.map +1 -1
- package/dist/editor/directiveConfig.d.ts +15 -1
- package/dist/editor/directiveConfig.js +21 -1
- package/dist/editor/directiveConfig.js.map +1 -1
- package/dist/editor/directives/completions.d.ts +4 -2
- package/dist/editor/directives/completions.js +22 -3
- package/dist/editor/directives/completions.js.map +1 -1
- package/dist/editor/directives/diagnostics.d.ts +2 -2
- package/dist/editor/directives/diagnostics.js +10 -3
- package/dist/editor/directives/diagnostics.js.map +1 -1
- package/dist/exports/client.d.ts +4 -1
- package/dist/exports/client.js +5 -2
- package/dist/exports/client.js.map +1 -1
- package/dist/exports/render.d.ts +2 -1
- package/dist/exports/render.js +1 -0
- package/dist/exports/render.js.map +1 -1
- package/dist/field/MarkdownField/Component.js +54 -3
- package/dist/field/MarkdownField/Component.js.map +1 -1
- package/dist/icons/entries.d.ts +22 -0
- package/dist/icons/entries.js +50 -0
- package/dist/icons/entries.js.map +1 -0
- package/dist/icons/resolve.d.ts +2 -1
- package/dist/icons/resolve.js +2 -2
- package/dist/icons/resolve.js.map +1 -1
- package/dist/icons/sanitizeSvg.d.ts +12 -2
- package/dist/icons/sanitizeSvg.js +104 -3
- package/dist/icons/sanitizeSvg.js.map +1 -1
- package/dist/index.d.ts +11 -4
- package/dist/index.js +34 -3
- package/dist/index.js.map +1 -1
- package/dist/mcp/index.d.ts +2 -2
- package/dist/mcp/index.js +65 -4
- package/dist/mcp/index.js.map +1 -1
- package/dist/palettes/colors.d.ts +21 -0
- package/dist/palettes/colors.js +43 -0
- package/dist/palettes/colors.js.map +1 -0
- package/dist/palettes/contrast.d.ts +7 -0
- package/dist/palettes/contrast.js +63 -0
- package/dist/palettes/contrast.js.map +1 -0
- package/dist/palettes/defaults.d.ts +8 -0
- package/dist/palettes/defaults.js +275 -0
- package/dist/palettes/defaults.js.map +1 -0
- package/dist/palettes/diagnostics.d.ts +10 -0
- package/dist/palettes/diagnostics.js +38 -0
- package/dist/palettes/diagnostics.js.map +1 -0
- package/dist/palettes/index.d.ts +61 -0
- package/dist/palettes/index.js +246 -0
- package/dist/palettes/index.js.map +1 -0
- package/dist/render/renderMarkdown.d.ts +3 -1
- package/dist/render/renderMarkdown.js +9 -1
- package/dist/render/renderMarkdown.js.map +1 -1
- package/dist/runtime/index.d.ts +12 -1
- package/dist/runtime/index.js +23 -2
- package/dist/runtime/index.js.map +1 -1
- package/dist/styles/directiveSurface.d.ts +39 -5
- package/dist/styles/directiveSurface.js +56 -13
- package/dist/styles/directiveSurface.js.map +1 -1
- package/dist/types/core.d.ts +56 -0
- package/dist/types/core.js.map +1 -1
- package/dist/types.d.ts +46 -2
- package/dist/types.js.map +1 -1
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/dist/version.js.map +1 -1
- package/package.json +2 -1
- package/skills/payload-markdown/claude/SKILL.md +1 -0
- package/skills/payload-markdown/claude/reference/directive-spec.json +60 -0
- package/skills/payload-markdown/claude/reference/mcp-content-workflow.md +7 -0
- package/skills/payload-markdown/claude/reference/payload-markdown-directives.md +22 -2
- package/skills/payload-markdown/claude/skill.json +2 -2
- package/skills/payload-markdown/codex/SKILL.md +1 -0
- package/skills/payload-markdown/codex/reference/directive-spec.json +60 -0
- package/skills/payload-markdown/codex/reference/mcp-content-workflow.md +7 -0
- package/skills/payload-markdown/codex/reference/payload-markdown-directives.md +22 -2
- package/skills/payload-markdown/codex/skill.json +2 -2
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/agent/validate.ts"],"sourcesContent":["import type { Payload } from 'payload'\n\nimport type { RenderDiagnostic } from '../core/diagnostics.js'\nimport type { MarkdownRenderConfig } from '../types/core.js'\n\nimport { renderMarkdown } from '../render/renderMarkdown.js'\n\nexport type MarkdownValidationOptions = {\n /** Collection whose payload-markdown settings (themes, icons, code) apply. */\n collection?: string\n /** Per-block `md-params` overrides (markdown blocks only). */\n overrides?: MarkdownRenderConfig\n /** Payload instance whose config carries the plugin settings. */\n payload?: Pick<Payload, 'config'>\n /** `blocks` for markdown blocks, `field` for markdown fields (default). */\n scope?: 'blocks' | 'field'\n}\n\nexport type MarkdownValidationResult = {\n counts: Record<RenderDiagnostic['severity'], number>\n diagnostics: RenderDiagnostic[]\n /** Fatal compilation errors; the page would show a failure placeholder. */\n errors: string[]\n headings: Array<{ depth: number; id: string; text: string }>\n /** No errors and no warnings: the markdown renders exactly as written. */\n ok: boolean\n}\n\n/**\n * Renders markdown the way the site does (same settings, scope and overrides)\n * and reports what the renderer would flag. `ok` requires zero errors and zero\n * warnings; `info` diagnostics (for example an unloaded code language that\n * falls back to plain text) never fail validation.\n */\nexport async function validateMarkdown(\n markdown: string,\n options: MarkdownValidationOptions = {},\n): Promise<MarkdownValidationResult> {\n const result = await renderMarkdown(markdown, {\n collectionSlug: options.collection,\n ...(options.overrides ? { overrides: options.overrides } : {}),\n scope: options.scope ?? 'field',\n ...(options.payload ? { settings: options.payload } : {}),\n })\n\n const counts = { error: 0, info: 0, warning: 0 }\n for (const diagnostic of result.diagnostics) counts[diagnostic.severity] += 1\n\n return {\n counts,\n diagnostics: result.diagnostics,\n errors: result.errors,\n headings: result.headings.map((heading) => ({ id: heading.id, depth: heading.depth, text: heading.text })),\n ok: result.errors.length === 0 && counts.error === 0 && counts.warning === 0,\n }\n}\n"],"names":["renderMarkdown","validateMarkdown","markdown","options","result","collectionSlug","collection","
|
|
1
|
+
{"version":3,"sources":["../../src/agent/validate.ts"],"sourcesContent":["import type { Payload } from 'payload'\n\nimport type { RenderDiagnostic } from '../core/diagnostics.js'\nimport type { MarkdownRenderConfig } from '../types/core.js'\n\nimport { loadAppearancePalettes } from '../appearance/runtime.js'\nimport { renderMarkdown } from '../render/renderMarkdown.js'\n\nexport type MarkdownValidationOptions = {\n /** Collection whose payload-markdown settings (themes, icons, code) apply. */\n collection?: string\n /** Per-block `md-params` overrides (markdown blocks only). */\n overrides?: MarkdownRenderConfig\n /** Payload instance whose config carries the plugin settings. */\n payload?: Partial<Pick<Payload, 'findGlobal'>> & Pick<Payload, 'config'>\n /** `blocks` for markdown blocks, `field` for markdown fields (default). */\n scope?: 'blocks' | 'field'\n}\n\nexport type MarkdownValidationResult = {\n counts: Record<RenderDiagnostic['severity'], number>\n diagnostics: RenderDiagnostic[]\n /** Fatal compilation errors; the page would show a failure placeholder. */\n errors: string[]\n headings: Array<{ depth: number; id: string; text: string }>\n /** No errors and no warnings: the markdown renders exactly as written. */\n ok: boolean\n}\n\n/**\n * Renders markdown the way the site does (same settings, scope and overrides)\n * and reports what the renderer would flag. `ok` requires zero errors and zero\n * warnings; `info` diagnostics (for example an unloaded code language that\n * falls back to plain text) never fail validation.\n */\nexport async function validateMarkdown(\n markdown: string,\n options: MarkdownValidationOptions = {},\n): Promise<MarkdownValidationResult> {\n const result = await renderMarkdown(markdown, {\n collectionSlug: options.collection,\n // Palettes managed in the admin, so agents validate against what the site renders.\n runtimePalettes: await loadAppearancePalettes(options.payload),\n ...(options.overrides ? { overrides: options.overrides } : {}),\n scope: options.scope ?? 'field',\n ...(options.payload ? { settings: options.payload } : {}),\n })\n\n const counts = { error: 0, info: 0, warning: 0 }\n for (const diagnostic of result.diagnostics) counts[diagnostic.severity] += 1\n\n return {\n counts,\n diagnostics: result.diagnostics,\n errors: result.errors,\n headings: result.headings.map((heading) => ({ id: heading.id, depth: heading.depth, text: heading.text })),\n ok: result.errors.length === 0 && counts.error === 0 && counts.warning === 0,\n }\n}\n"],"names":["loadAppearancePalettes","renderMarkdown","validateMarkdown","markdown","options","result","collectionSlug","collection","runtimePalettes","payload","overrides","scope","settings","counts","error","info","warning","diagnostic","diagnostics","severity","errors","headings","map","heading","id","depth","text","ok","length"],"mappings":"AAKA,SAASA,sBAAsB,QAAQ,2BAA0B;AACjE,SAASC,cAAc,QAAQ,8BAA6B;AAuB5D;;;;;CAKC,GACD,OAAO,eAAeC,iBACpBC,QAAgB,EAChBC,UAAqC,CAAC,CAAC;IAEvC,MAAMC,SAAS,MAAMJ,eAAeE,UAAU;QAC5CG,gBAAgBF,QAAQG,UAAU;QAClC,mFAAmF;QACnFC,iBAAiB,MAAMR,uBAAuBI,QAAQK,OAAO;QAC7D,GAAIL,QAAQM,SAAS,GAAG;YAAEA,WAAWN,QAAQM,SAAS;QAAC,IAAI,CAAC,CAAC;QAC7DC,OAAOP,QAAQO,KAAK,IAAI;QACxB,GAAIP,QAAQK,OAAO,GAAG;YAAEG,UAAUR,QAAQK,OAAO;QAAC,IAAI,CAAC,CAAC;IAC1D;IAEA,MAAMI,SAAS;QAAEC,OAAO;QAAGC,MAAM;QAAGC,SAAS;IAAE;IAC/C,KAAK,MAAMC,cAAcZ,OAAOa,WAAW,CAAEL,MAAM,CAACI,WAAWE,QAAQ,CAAC,IAAI;IAE5E,OAAO;QACLN;QACAK,aAAab,OAAOa,WAAW;QAC/BE,QAAQf,OAAOe,MAAM;QACrBC,UAAUhB,OAAOgB,QAAQ,CAACC,GAAG,CAAC,CAACC,UAAa,CAAA;gBAAEC,IAAID,QAAQC,EAAE;gBAAEC,OAAOF,QAAQE,KAAK;gBAAEC,MAAMH,QAAQG,IAAI;YAAC,CAAA;QACvGC,IAAItB,OAAOe,MAAM,CAACQ,MAAM,KAAK,KAAKf,OAAOC,KAAK,KAAK,KAAKD,OAAOG,OAAO,KAAK;IAC7E;AACF"}
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
|
+
import { useRowLabel } from '@payloadcms/ui';
|
|
4
|
+
import React from 'react';
|
|
5
|
+
import { normalizePaletteColor } from '../palettes/colors.js';
|
|
6
|
+
function Swatch({ title, value }) {
|
|
7
|
+
// Rows hold unsaved input while editing: only validated colours reach style.
|
|
8
|
+
const color = normalizePaletteColor(value);
|
|
9
|
+
if (!color) return null;
|
|
10
|
+
return /*#__PURE__*/ _jsx("span", {
|
|
11
|
+
"aria-label": `${title}: ${color}`,
|
|
12
|
+
style: {
|
|
13
|
+
background: color,
|
|
14
|
+
border: '1px solid rgb(128 128 128 / 0.4)',
|
|
15
|
+
borderRadius: 4,
|
|
16
|
+
display: 'inline-block',
|
|
17
|
+
height: 14,
|
|
18
|
+
width: 14
|
|
19
|
+
},
|
|
20
|
+
title: `${title}: ${color}`
|
|
21
|
+
});
|
|
22
|
+
}
|
|
23
|
+
/** Row label for the appearance global's palettes: name, label and colour swatches. */ export function MarkdownPaletteRowLabel() {
|
|
24
|
+
const { data, rowNumber } = useRowLabel();
|
|
25
|
+
const name = data?.name || `Palette ${String((rowNumber ?? 0) + 1).padStart(2, '0')}`;
|
|
26
|
+
return /*#__PURE__*/ _jsxs("span", {
|
|
27
|
+
style: {
|
|
28
|
+
alignItems: 'center',
|
|
29
|
+
display: 'inline-flex',
|
|
30
|
+
gap: 8
|
|
31
|
+
},
|
|
32
|
+
children: [
|
|
33
|
+
/*#__PURE__*/ _jsxs("span", {
|
|
34
|
+
style: {
|
|
35
|
+
display: 'inline-flex',
|
|
36
|
+
gap: 3
|
|
37
|
+
},
|
|
38
|
+
children: [
|
|
39
|
+
/*#__PURE__*/ _jsx(Swatch, {
|
|
40
|
+
title: "Color",
|
|
41
|
+
value: data?.color
|
|
42
|
+
}),
|
|
43
|
+
/*#__PURE__*/ _jsx(Swatch, {
|
|
44
|
+
title: "Secondary",
|
|
45
|
+
value: data?.secondaryColor
|
|
46
|
+
}),
|
|
47
|
+
/*#__PURE__*/ _jsx(Swatch, {
|
|
48
|
+
title: "Background",
|
|
49
|
+
value: data?.background
|
|
50
|
+
}),
|
|
51
|
+
/*#__PURE__*/ _jsx(Swatch, {
|
|
52
|
+
title: "Dark color",
|
|
53
|
+
value: data?.dark?.color
|
|
54
|
+
})
|
|
55
|
+
]
|
|
56
|
+
}),
|
|
57
|
+
/*#__PURE__*/ _jsx("code", {
|
|
58
|
+
children: name
|
|
59
|
+
}),
|
|
60
|
+
data?.label ? /*#__PURE__*/ _jsx("span", {
|
|
61
|
+
style: {
|
|
62
|
+
opacity: 0.7
|
|
63
|
+
},
|
|
64
|
+
children: data.label
|
|
65
|
+
}) : null
|
|
66
|
+
]
|
|
67
|
+
});
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
//# sourceMappingURL=PaletteRowLabel.client.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/appearance/PaletteRowLabel.client.tsx"],"sourcesContent":["'use client'\n\nimport { useRowLabel } from '@payloadcms/ui'\nimport React from 'react'\n\nimport { normalizePaletteColor } from '../palettes/colors.js'\n\ntype PaletteRow = {\n accent?: null | string\n background?: null | string\n border?: null | string\n color?: null | string\n dark?: { color?: null | string } | null\n label?: null | string\n name?: null | string\n secondaryColor?: null | string\n}\n\nfunction Swatch({ title, value }: { title: string; value?: null | string }) {\n // Rows hold unsaved input while editing: only validated colours reach style.\n const color = normalizePaletteColor(value)\n if (!color) return null\n\n return (\n <span\n aria-label={`${title}: ${color}`}\n style={{\n background: color,\n border: '1px solid rgb(128 128 128 / 0.4)',\n borderRadius: 4,\n display: 'inline-block',\n height: 14,\n width: 14,\n }}\n title={`${title}: ${color}`}\n />\n )\n}\n\n/** Row label for the appearance global's palettes: name, label and colour swatches. */\nexport function MarkdownPaletteRowLabel() {\n const { data, rowNumber } = useRowLabel<PaletteRow>()\n const name = data?.name || `Palette ${String((rowNumber ?? 0) + 1).padStart(2, '0')}`\n\n return (\n <span style={{ alignItems: 'center', display: 'inline-flex', gap: 8 }}>\n <span style={{ display: 'inline-flex', gap: 3 }}>\n <Swatch title=\"Color\" value={data?.color} />\n <Swatch title=\"Secondary\" value={data?.secondaryColor} />\n <Swatch title=\"Background\" value={data?.background} />\n <Swatch title=\"Dark color\" value={data?.dark?.color} />\n </span>\n <code>{name}</code>\n {data?.label ? <span style={{ opacity: 0.7 }}>{data.label}</span> : null}\n </span>\n )\n}\n"],"names":["useRowLabel","React","normalizePaletteColor","Swatch","title","value","color","span","aria-label","style","background","border","borderRadius","display","height","width","MarkdownPaletteRowLabel","data","rowNumber","name","String","padStart","alignItems","gap","secondaryColor","dark","code","label","opacity"],"mappings":"AAAA;;AAEA,SAASA,WAAW,QAAQ,iBAAgB;AAC5C,OAAOC,WAAW,QAAO;AAEzB,SAASC,qBAAqB,QAAQ,wBAAuB;AAa7D,SAASC,OAAO,EAAEC,KAAK,EAAEC,KAAK,EAA4C;IACxE,6EAA6E;IAC7E,MAAMC,QAAQJ,sBAAsBG;IACpC,IAAI,CAACC,OAAO,OAAO;IAEnB,qBACE,KAACC;QACCC,cAAY,GAAGJ,MAAM,EAAE,EAAEE,OAAO;QAChCG,OAAO;YACLC,YAAYJ;YACZK,QAAQ;YACRC,cAAc;YACdC,SAAS;YACTC,QAAQ;YACRC,OAAO;QACT;QACAX,OAAO,GAAGA,MAAM,EAAE,EAAEE,OAAO;;AAGjC;AAEA,qFAAqF,GACrF,OAAO,SAASU;IACd,MAAM,EAAEC,IAAI,EAAEC,SAAS,EAAE,GAAGlB;IAC5B,MAAMmB,OAAOF,MAAME,QAAQ,CAAC,QAAQ,EAAEC,OAAO,AAACF,CAAAA,aAAa,CAAA,IAAK,GAAGG,QAAQ,CAAC,GAAG,MAAM;IAErF,qBACE,MAACd;QAAKE,OAAO;YAAEa,YAAY;YAAUT,SAAS;YAAeU,KAAK;QAAE;;0BAClE,MAAChB;gBAAKE,OAAO;oBAAEI,SAAS;oBAAeU,KAAK;gBAAE;;kCAC5C,KAACpB;wBAAOC,OAAM;wBAAQC,OAAOY,MAAMX;;kCACnC,KAACH;wBAAOC,OAAM;wBAAYC,OAAOY,MAAMO;;kCACvC,KAACrB;wBAAOC,OAAM;wBAAaC,OAAOY,MAAMP;;kCACxC,KAACP;wBAAOC,OAAM;wBAAaC,OAAOY,MAAMQ,MAAMnB;;;;0BAEhD,KAACoB;0BAAMP;;YACNF,MAAMU,sBAAQ,KAACpB;gBAAKE,OAAO;oBAAEmB,SAAS;gBAAI;0BAAIX,KAAKU,KAAK;iBAAW;;;AAG1E"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { GlobalConfig } from 'payload';
|
|
2
|
+
import { type ResolvedAppearanceOptions } from './options.js';
|
|
3
|
+
export { DEFAULT_APPEARANCE_SLUG, resolveAppearanceOptions } from './options.js';
|
|
4
|
+
/**
|
|
5
|
+
* The "Markdown Appearance" global: palettes editors and MCP agents manage at
|
|
6
|
+
* runtime. Saving refreshes this process's palette cache and revalidates pages.
|
|
7
|
+
*/
|
|
8
|
+
export declare function createAppearanceGlobal(resolved: ResolvedAppearanceOptions): GlobalConfig;
|
|
@@ -0,0 +1,172 @@
|
|
|
1
|
+
import { PAYLOAD_MARKDOWN_PACKAGE } from '../package.js';
|
|
2
|
+
import { normalizePaletteColor, PALETTE_COLOR_FORMATS } from '../palettes/colors.js';
|
|
3
|
+
import { PALETTE_NAME_PATTERN } from '../palettes/index.js';
|
|
4
|
+
import { APPEARANCE_PALETTES_FIELD } from './options.js';
|
|
5
|
+
import { primeAppearancePalettes, readAppearancePalettes } from './runtime.js';
|
|
6
|
+
export { DEFAULT_APPEARANCE_SLUG, resolveAppearanceOptions } from './options.js';
|
|
7
|
+
const validateColor = (value)=>{
|
|
8
|
+
if (value === null || value === undefined || value === '') return true;
|
|
9
|
+
return normalizePaletteColor(value) ? true : `Use ${PALETTE_COLOR_FORMATS}.`;
|
|
10
|
+
};
|
|
11
|
+
function colorField(name, label, description) {
|
|
12
|
+
return {
|
|
13
|
+
name,
|
|
14
|
+
type: 'text',
|
|
15
|
+
admin: {
|
|
16
|
+
description,
|
|
17
|
+
placeholder: '#e95420',
|
|
18
|
+
width: '33%'
|
|
19
|
+
},
|
|
20
|
+
label,
|
|
21
|
+
validate: validateColor
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
function colorFields(prefix) {
|
|
25
|
+
const scheme = prefix === 'dark' ? ' in the dark scheme (empty: the light value)' : '';
|
|
26
|
+
return [
|
|
27
|
+
{
|
|
28
|
+
type: 'row',
|
|
29
|
+
fields: [
|
|
30
|
+
colorField('color', 'Color', `Icon colour and duotone primary layer${scheme}.`),
|
|
31
|
+
colorField('secondaryColor', 'Secondary color', `Duotone secondary layer${scheme} (empty: the colour).`),
|
|
32
|
+
colorField('accent', 'Accent', `Links and hovered titles inside directives${scheme}.`)
|
|
33
|
+
]
|
|
34
|
+
},
|
|
35
|
+
{
|
|
36
|
+
type: 'row',
|
|
37
|
+
fields: [
|
|
38
|
+
colorField('background', 'Background', `Surface of directives that use the palette${scheme}.`),
|
|
39
|
+
colorField('border', 'Border', `Border of directives that use the palette${scheme}.`)
|
|
40
|
+
]
|
|
41
|
+
}
|
|
42
|
+
];
|
|
43
|
+
}
|
|
44
|
+
const validatePaletteRows = (rows)=>{
|
|
45
|
+
if (!Array.isArray(rows)) return true;
|
|
46
|
+
const seen = new Set();
|
|
47
|
+
for (const row of rows){
|
|
48
|
+
const name = row && typeof row === 'object' ? row.name : undefined;
|
|
49
|
+
if (typeof name !== 'string') continue;
|
|
50
|
+
if (seen.has(name)) return `Palette names must be unique: "${name}" is used more than once.`;
|
|
51
|
+
seen.add(name);
|
|
52
|
+
}
|
|
53
|
+
return true;
|
|
54
|
+
};
|
|
55
|
+
const validateName = (value)=>typeof value === 'string' && PALETTE_NAME_PATTERN.test(value) ? true : 'Use 1–48 lowercase letters, digits and dashes, starting with a letter (it is what markdown references).';
|
|
56
|
+
function palettesField() {
|
|
57
|
+
return {
|
|
58
|
+
name: APPEARANCE_PALETTES_FIELD,
|
|
59
|
+
type: 'array',
|
|
60
|
+
admin: {
|
|
61
|
+
components: {
|
|
62
|
+
RowLabel: `${PAYLOAD_MARKDOWN_PACKAGE}/client#MarkdownPaletteRowLabel`
|
|
63
|
+
},
|
|
64
|
+
description: 'Named colour themes for markdown. Use one with palette="name" on a directive or "@pack/icon palette=name" on an icon. A palette here replaces a built-in or configured one with the same name.',
|
|
65
|
+
initCollapsed: true
|
|
66
|
+
},
|
|
67
|
+
fields: [
|
|
68
|
+
{
|
|
69
|
+
type: 'row',
|
|
70
|
+
fields: [
|
|
71
|
+
{
|
|
72
|
+
name: 'name',
|
|
73
|
+
type: 'text',
|
|
74
|
+
admin: {
|
|
75
|
+
description: 'Referenced from markdown, for example "debian".',
|
|
76
|
+
width: '50%'
|
|
77
|
+
},
|
|
78
|
+
required: true,
|
|
79
|
+
validate: validateName
|
|
80
|
+
},
|
|
81
|
+
{
|
|
82
|
+
name: 'label',
|
|
83
|
+
type: 'text',
|
|
84
|
+
admin: {
|
|
85
|
+
description: 'Optional display name.',
|
|
86
|
+
width: '50%'
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
]
|
|
90
|
+
},
|
|
91
|
+
...colorFields('light'),
|
|
92
|
+
{
|
|
93
|
+
name: 'secondaryOpacity',
|
|
94
|
+
type: 'number',
|
|
95
|
+
admin: {
|
|
96
|
+
description: 'Opacity of the duotone secondary layer, 0–1 (empty: the icon’s own, 0.4 for Font Awesome).',
|
|
97
|
+
step: 0.05
|
|
98
|
+
},
|
|
99
|
+
max: 1,
|
|
100
|
+
min: 0
|
|
101
|
+
},
|
|
102
|
+
{
|
|
103
|
+
name: 'dark',
|
|
104
|
+
type: 'group',
|
|
105
|
+
admin: {
|
|
106
|
+
description: 'Optional dark-scheme colours.'
|
|
107
|
+
},
|
|
108
|
+
fields: colorFields('dark'),
|
|
109
|
+
label: 'Dark scheme'
|
|
110
|
+
}
|
|
111
|
+
],
|
|
112
|
+
labels: {
|
|
113
|
+
plural: 'Palettes',
|
|
114
|
+
singular: 'Palette'
|
|
115
|
+
},
|
|
116
|
+
validate: validatePaletteRows
|
|
117
|
+
};
|
|
118
|
+
}
|
|
119
|
+
async function revalidateAfterChange(options, payload) {
|
|
120
|
+
const revalidate = options.revalidate ?? true;
|
|
121
|
+
if (revalidate === false) return;
|
|
122
|
+
if (typeof revalidate === 'function') {
|
|
123
|
+
await revalidate({
|
|
124
|
+
payload
|
|
125
|
+
});
|
|
126
|
+
return;
|
|
127
|
+
}
|
|
128
|
+
try {
|
|
129
|
+
// Next.js only: statically rendered pages hold the palettes they were
|
|
130
|
+
// built with. Outside a Next.js request (scripts, seeding) this throws
|
|
131
|
+
// and there is nothing to revalidate.
|
|
132
|
+
const { revalidatePath } = await import('next/cache.js');
|
|
133
|
+
revalidatePath('/', 'layout');
|
|
134
|
+
} catch {
|
|
135
|
+
// Not running in a Next.js request context.
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
/**
|
|
139
|
+
* The "Markdown Appearance" global: palettes editors and MCP agents manage at
|
|
140
|
+
* runtime. Saving refreshes this process's palette cache and revalidates pages.
|
|
141
|
+
*/ export function createAppearanceGlobal(resolved) {
|
|
142
|
+
return {
|
|
143
|
+
slug: resolved.slug,
|
|
144
|
+
access: {
|
|
145
|
+
read: ({ req })=>Boolean(req.user),
|
|
146
|
+
update: ({ req })=>Boolean(req.user),
|
|
147
|
+
...resolved.options.access ?? {}
|
|
148
|
+
},
|
|
149
|
+
admin: {
|
|
150
|
+
description: 'Colour palettes for payload-markdown content.',
|
|
151
|
+
group: 'Markdown',
|
|
152
|
+
...resolved.options.admin ?? {}
|
|
153
|
+
},
|
|
154
|
+
fields: [
|
|
155
|
+
palettesField()
|
|
156
|
+
],
|
|
157
|
+
hooks: {
|
|
158
|
+
afterChange: [
|
|
159
|
+
async ({ doc, req })=>{
|
|
160
|
+
// afterChange runs before the transaction commits, so a reload here
|
|
161
|
+
// could read (and cache) the previous rows. The saved document is
|
|
162
|
+
// the new state: cache it directly.
|
|
163
|
+
primeAppearancePalettes(readAppearancePalettes(doc));
|
|
164
|
+
await revalidateAfterChange(resolved.options, req.payload);
|
|
165
|
+
}
|
|
166
|
+
]
|
|
167
|
+
},
|
|
168
|
+
label: 'Markdown Appearance'
|
|
169
|
+
};
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
//# sourceMappingURL=config.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/appearance/config.ts"],"sourcesContent":["import type { ArrayField, Field, GlobalConfig, Payload, Validate } from 'payload'\n\nimport type { PayloadMarkdownAppearanceOptions } from '../types.js'\n\nimport { PAYLOAD_MARKDOWN_PACKAGE } from '../package.js'\nimport { normalizePaletteColor, PALETTE_COLOR_FORMATS } from '../palettes/colors.js'\nimport { PALETTE_NAME_PATTERN } from '../palettes/index.js'\nimport { APPEARANCE_PALETTES_FIELD, type ResolvedAppearanceOptions } from './options.js'\nimport { primeAppearancePalettes, readAppearancePalettes } from './runtime.js'\n\nexport { DEFAULT_APPEARANCE_SLUG, resolveAppearanceOptions } from './options.js'\n\nconst validateColor: Validate<null | string | undefined> = (value) => {\n if (value === null || value === undefined || value === '') return true\n\n return normalizePaletteColor(value) ? true : `Use ${PALETTE_COLOR_FORMATS}.`\n}\n\nfunction colorField(name: string, label: string, description: string): Field {\n return {\n name,\n type: 'text',\n admin: { description, placeholder: '#e95420', width: '33%' },\n label,\n validate: validateColor,\n }\n}\n\nfunction colorFields(prefix: 'dark' | 'light'): Field[] {\n const scheme = prefix === 'dark' ? ' in the dark scheme (empty: the light value)' : ''\n\n return [\n {\n type: 'row',\n fields: [\n colorField('color', 'Color', `Icon colour and duotone primary layer${scheme}.`),\n colorField('secondaryColor', 'Secondary color', `Duotone secondary layer${scheme} (empty: the colour).`),\n colorField('accent', 'Accent', `Links and hovered titles inside directives${scheme}.`),\n ],\n },\n {\n type: 'row',\n fields: [\n colorField('background', 'Background', `Surface of directives that use the palette${scheme}.`),\n colorField('border', 'Border', `Border of directives that use the palette${scheme}.`),\n ],\n },\n ]\n}\n\nconst validatePaletteRows: Validate<null | undefined | unknown[]> = (rows) => {\n if (!Array.isArray(rows)) return true\n\n const seen = new Set<string>()\n\n for (const row of rows) {\n const name = row && typeof row === 'object' ? (row as { name?: unknown }).name : undefined\n if (typeof name !== 'string') continue\n if (seen.has(name)) return `Palette names must be unique: \"${name}\" is used more than once.`\n seen.add(name)\n }\n\n return true\n}\n\nconst validateName: Validate<null | string | undefined> = (value) =>\n typeof value === 'string' && PALETTE_NAME_PATTERN.test(value)\n ? true\n : 'Use 1–48 lowercase letters, digits and dashes, starting with a letter (it is what markdown references).'\n\nfunction palettesField(): ArrayField {\n return {\n name: APPEARANCE_PALETTES_FIELD,\n type: 'array',\n admin: {\n components: { RowLabel: `${PAYLOAD_MARKDOWN_PACKAGE}/client#MarkdownPaletteRowLabel` },\n description:\n 'Named colour themes for markdown. Use one with palette=\"name\" on a directive or \"@pack/icon palette=name\" on an icon. A palette here replaces a built-in or configured one with the same name.',\n initCollapsed: true,\n },\n fields: [\n {\n type: 'row',\n fields: [\n {\n name: 'name',\n type: 'text',\n admin: { description: 'Referenced from markdown, for example \"debian\".', width: '50%' },\n required: true,\n validate: validateName,\n },\n {\n name: 'label',\n type: 'text',\n admin: { description: 'Optional display name.', width: '50%' },\n },\n ],\n },\n ...colorFields('light'),\n {\n name: 'secondaryOpacity',\n type: 'number',\n admin: {\n description: 'Opacity of the duotone secondary layer, 0–1 (empty: the icon’s own, 0.4 for Font Awesome).',\n step: 0.05,\n },\n max: 1,\n min: 0,\n },\n {\n name: 'dark',\n type: 'group',\n admin: { description: 'Optional dark-scheme colours.' },\n fields: colorFields('dark'),\n label: 'Dark scheme',\n },\n ],\n labels: { plural: 'Palettes', singular: 'Palette' },\n validate: validatePaletteRows,\n }\n}\n\nasync function revalidateAfterChange(options: PayloadMarkdownAppearanceOptions, payload: Payload) {\n const revalidate = options.revalidate ?? true\n if (revalidate === false) return\n\n if (typeof revalidate === 'function') {\n await revalidate({ payload })\n return\n }\n\n try {\n // Next.js only: statically rendered pages hold the palettes they were\n // built with. Outside a Next.js request (scripts, seeding) this throws\n // and there is nothing to revalidate.\n const { revalidatePath } = await import('next/cache.js')\n revalidatePath('/', 'layout')\n } catch {\n // Not running in a Next.js request context.\n }\n}\n\n/**\n * The \"Markdown Appearance\" global: palettes editors and MCP agents manage at\n * runtime. Saving refreshes this process's palette cache and revalidates pages.\n */\nexport function createAppearanceGlobal(resolved: ResolvedAppearanceOptions): GlobalConfig {\n return {\n slug: resolved.slug,\n access: {\n read: ({ req }) => Boolean(req.user),\n update: ({ req }) => Boolean(req.user),\n ...(resolved.options.access ?? {}),\n },\n admin: {\n description: 'Colour palettes for payload-markdown content.',\n group: 'Markdown',\n ...(resolved.options.admin ?? {}),\n },\n fields: [palettesField()],\n hooks: {\n afterChange: [\n async ({ doc, req }) => {\n // afterChange runs before the transaction commits, so a reload here\n // could read (and cache) the previous rows. The saved document is\n // the new state: cache it directly.\n primeAppearancePalettes(readAppearancePalettes(doc))\n await revalidateAfterChange(resolved.options, req.payload)\n },\n ],\n },\n label: 'Markdown Appearance',\n }\n}\n"],"names":["PAYLOAD_MARKDOWN_PACKAGE","normalizePaletteColor","PALETTE_COLOR_FORMATS","PALETTE_NAME_PATTERN","APPEARANCE_PALETTES_FIELD","primeAppearancePalettes","readAppearancePalettes","DEFAULT_APPEARANCE_SLUG","resolveAppearanceOptions","validateColor","value","undefined","colorField","name","label","description","type","admin","placeholder","width","validate","colorFields","prefix","scheme","fields","validatePaletteRows","rows","Array","isArray","seen","Set","row","has","add","validateName","test","palettesField","components","RowLabel","initCollapsed","required","step","max","min","labels","plural","singular","revalidateAfterChange","options","payload","revalidate","revalidatePath","createAppearanceGlobal","resolved","slug","access","read","req","Boolean","user","update","group","hooks","afterChange","doc"],"mappings":"AAIA,SAASA,wBAAwB,QAAQ,gBAAe;AACxD,SAASC,qBAAqB,EAAEC,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ACF,sEAAsE;QACtE,uEAAuE;QACvE,sCAAsC;QACtC,MAAM,EAAEE,cAAc,EAAE,GAAG,MAAM,MAAM,CAAC;QACxCA,eAAe,KAAK;IACtB,EAAE,OAAM;IACN,4CAA4C;IAC9C;AACF;AAEA;;;CAGC,GACD,OAAO,SAASC,uBAAuBC,QAAmC;IACxE,OAAO;QACLC,MAAMD,SAASC,IAAI;QACnBC,QAAQ;YACNC,MAAM,CAAC,EAAEC,GAAG,EAAE,GAAKC,QAAQD,IAAIE,IAAI;YACnCC,QAAQ,CAAC,EAAEH,GAAG,EAAE,GAAKC,QAAQD,IAAIE,IAAI;YACrC,GAAIN,SAASL,OAAO,CAACO,MAAM,IAAI,CAAC,CAAC;QACnC;QACAtC,OAAO;YACLF,aAAa;YACb8C,OAAO;YACP,GAAIR,SAASL,OAAO,CAAC/B,KAAK,IAAI,CAAC,CAAC;QAClC;QACAO,QAAQ;YAACY;SAAgB;QACzB0B,OAAO;YACLC,aAAa;gBACX,OAAO,EAAEC,GAAG,EAAEP,GAAG,EAAE;oBACjB,oEAAoE;oBACpE,kEAAkE;oBAClE,oCAAoC;oBACpCpD,wBAAwBC,uBAAuB0D;oBAC/C,MAAMjB,sBAAsBM,SAASL,OAAO,EAAES,IAAIR,OAAO;gBAC3D;aACD;QACH;QACAnC,OAAO;IACT;AACF"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { PayloadMarkdownAppearanceOptions } from '../types.js';
|
|
2
|
+
export declare const DEFAULT_APPEARANCE_SLUG = "markdown-appearance";
|
|
3
|
+
export declare const DEFAULT_APPEARANCE_CACHE_TTL = 30000;
|
|
4
|
+
/** Name of the palettes array field on the appearance global. */
|
|
5
|
+
export declare const APPEARANCE_PALETTES_FIELD = "palettes";
|
|
6
|
+
export type ResolvedAppearanceOptions = {
|
|
7
|
+
cacheTtl: number;
|
|
8
|
+
options: PayloadMarkdownAppearanceOptions;
|
|
9
|
+
slug: string;
|
|
10
|
+
};
|
|
11
|
+
export declare function resolveAppearanceOptions(value: boolean | PayloadMarkdownAppearanceOptions | undefined): ResolvedAppearanceOptions | undefined;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
export const DEFAULT_APPEARANCE_SLUG = 'markdown-appearance';
|
|
2
|
+
export const DEFAULT_APPEARANCE_CACHE_TTL = 30_000;
|
|
3
|
+
/** Name of the palettes array field on the appearance global. */ export const APPEARANCE_PALETTES_FIELD = 'palettes';
|
|
4
|
+
export function resolveAppearanceOptions(value) {
|
|
5
|
+
if (!value) return undefined;
|
|
6
|
+
const options = value === true ? {} : value;
|
|
7
|
+
const cacheTtl = typeof options.cacheTtl === 'number' && Number.isFinite(options.cacheTtl) && options.cacheTtl >= 0 ? options.cacheTtl : DEFAULT_APPEARANCE_CACHE_TTL;
|
|
8
|
+
return {
|
|
9
|
+
slug: options.slug?.trim() || DEFAULT_APPEARANCE_SLUG,
|
|
10
|
+
cacheTtl,
|
|
11
|
+
options
|
|
12
|
+
};
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
//# sourceMappingURL=options.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/appearance/options.ts"],"sourcesContent":["import type { PayloadMarkdownAppearanceOptions } from '../types.js'\n\nexport const DEFAULT_APPEARANCE_SLUG = 'markdown-appearance'\nexport const DEFAULT_APPEARANCE_CACHE_TTL = 30_000\n\n/** Name of the palettes array field on the appearance global. */\nexport const APPEARANCE_PALETTES_FIELD = 'palettes'\n\nexport type ResolvedAppearanceOptions = {\n cacheTtl: number\n options: PayloadMarkdownAppearanceOptions\n slug: string\n}\n\nexport function resolveAppearanceOptions(\n value: boolean | PayloadMarkdownAppearanceOptions | undefined,\n): ResolvedAppearanceOptions | undefined {\n if (!value) return undefined\n\n const options = value === true ? {} : value\n const cacheTtl =\n typeof options.cacheTtl === 'number' && Number.isFinite(options.cacheTtl) && options.cacheTtl >= 0\n ? options.cacheTtl\n : DEFAULT_APPEARANCE_CACHE_TTL\n\n return { slug: options.slug?.trim() || DEFAULT_APPEARANCE_SLUG, cacheTtl, options }\n}\n\n"],"names":["DEFAULT_APPEARANCE_SLUG","DEFAULT_APPEARANCE_CACHE_TTL","APPEARANCE_PALETTES_FIELD","resolveAppearanceOptions","value","undefined","options","cacheTtl","Number","isFinite","slug","trim"],"mappings":"AAEA,OAAO,MAAMA,0BAA0B,sBAAqB;AAC5D,OAAO,MAAMC,+BAA+B,OAAM;AAElD,+DAA+D,GAC/D,OAAO,MAAMC,4BAA4B,WAAU;AAQnD,OAAO,SAASC,yBACdC,KAA6D;IAE7D,IAAI,CAACA,OAAO,OAAOC;IAEnB,MAAMC,UAAUF,UAAU,OAAO,CAAC,IAAIA;IACtC,MAAMG,WACJ,OAAOD,QAAQC,QAAQ,KAAK,YAAYC,OAAOC,QAAQ,CAACH,QAAQC,QAAQ,KAAKD,QAAQC,QAAQ,IAAI,IAC7FD,QAAQC,QAAQ,GAChBN;IAEN,OAAO;QAAES,MAAMJ,QAAQI,IAAI,EAAEC,UAAUX;QAAyBO;QAAUD;IAAQ;AACpF"}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import type { Payload } from 'payload';
|
|
2
|
+
import type { MarkdownPalette } from '../types/core.js';
|
|
3
|
+
/** Called while the Payload config is built when `appearance` is enabled. */
|
|
4
|
+
export declare function registerAppearance({ slug, ttl }: {
|
|
5
|
+
slug: string;
|
|
6
|
+
ttl: number;
|
|
7
|
+
}): void;
|
|
8
|
+
/** Called from `onInit` so renders without an explicit Payload instance can load palettes. */
|
|
9
|
+
export declare function attachAppearancePayload(payload: Payload): void;
|
|
10
|
+
/** Disables runtime palettes (the plugin was rebuilt without `appearance`). */
|
|
11
|
+
export declare function clearAppearance(): void;
|
|
12
|
+
export declare function invalidateAppearancePalettes(): void;
|
|
13
|
+
/** Replaces the cached palettes with ones just saved (see the global's afterChange hook). */
|
|
14
|
+
export declare function primeAppearancePalettes(palettes: MarkdownPalette[]): void;
|
|
15
|
+
/** Slug of the appearance global, or `undefined` when it is not enabled. */
|
|
16
|
+
export declare function getAppearanceSlug(): string | undefined;
|
|
17
|
+
/** Converts stored rows into palettes (validation happens where palettes are resolved). */
|
|
18
|
+
export declare function readAppearancePalettes(doc: unknown): MarkdownPalette[];
|
|
19
|
+
/**
|
|
20
|
+
* Palettes managed in the appearance global, cached per process. Returns `[]`
|
|
21
|
+
* when the global is not enabled, no Payload instance is available, or it
|
|
22
|
+
* cannot be read (for example before its migration ran); the render then uses
|
|
23
|
+
* the configured palettes only.
|
|
24
|
+
*/
|
|
25
|
+
export declare function loadAppearancePalettes(source?: unknown): Promise<MarkdownPalette[]>;
|
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
import { PAYLOAD_MARKDOWN_APPEARANCE_RUNTIME_KEY } from '../runtime/index.js';
|
|
2
|
+
function getRuntime() {
|
|
3
|
+
const host = globalThis;
|
|
4
|
+
if (!host[PAYLOAD_MARKDOWN_APPEARANCE_RUNTIME_KEY]) Object.defineProperty(globalThis, PAYLOAD_MARKDOWN_APPEARANCE_RUNTIME_KEY, {
|
|
5
|
+
configurable: true,
|
|
6
|
+
enumerable: false,
|
|
7
|
+
value: {
|
|
8
|
+
ttl: 30_000
|
|
9
|
+
},
|
|
10
|
+
writable: false
|
|
11
|
+
});
|
|
12
|
+
return host[PAYLOAD_MARKDOWN_APPEARANCE_RUNTIME_KEY];
|
|
13
|
+
}
|
|
14
|
+
/** Called while the Payload config is built when `appearance` is enabled. */ export function registerAppearance({ slug, ttl }) {
|
|
15
|
+
const runtime = getRuntime();
|
|
16
|
+
if (runtime.slug !== slug) {
|
|
17
|
+
runtime.cache = undefined;
|
|
18
|
+
runtime.lastGood = undefined;
|
|
19
|
+
}
|
|
20
|
+
runtime.slug = slug;
|
|
21
|
+
runtime.ttl = ttl;
|
|
22
|
+
}
|
|
23
|
+
/** Called from `onInit` so renders without an explicit Payload instance can load palettes. */ export function attachAppearancePayload(payload) {
|
|
24
|
+
getRuntime().payload = payload;
|
|
25
|
+
}
|
|
26
|
+
/** Disables runtime palettes (the plugin was rebuilt without `appearance`). */ export function clearAppearance() {
|
|
27
|
+
const runtime = getRuntime();
|
|
28
|
+
runtime.slug = undefined;
|
|
29
|
+
runtime.cache = undefined;
|
|
30
|
+
runtime.lastGood = undefined;
|
|
31
|
+
runtime.pending = undefined;
|
|
32
|
+
}
|
|
33
|
+
export function invalidateAppearancePalettes() {
|
|
34
|
+
const runtime = getRuntime();
|
|
35
|
+
runtime.cache = undefined;
|
|
36
|
+
runtime.pending = undefined;
|
|
37
|
+
}
|
|
38
|
+
/** Replaces the cached palettes with ones just saved (see the global's afterChange hook). */ export function primeAppearancePalettes(palettes) {
|
|
39
|
+
const runtime = getRuntime();
|
|
40
|
+
runtime.pending = undefined;
|
|
41
|
+
runtime.lastGood = palettes;
|
|
42
|
+
runtime.cache = {
|
|
43
|
+
expires: Date.now() + runtime.ttl,
|
|
44
|
+
palettes
|
|
45
|
+
};
|
|
46
|
+
// A save went through, so the next read error is a new outage worth logging.
|
|
47
|
+
runtime.warned = false;
|
|
48
|
+
}
|
|
49
|
+
/** After a failed load, how long to wait before trying the database again. */ const RETRY_AFTER_ERROR_MS = 5_000;
|
|
50
|
+
/** Slug of the appearance global, or `undefined` when it is not enabled. */ export function getAppearanceSlug() {
|
|
51
|
+
return getRuntime().slug;
|
|
52
|
+
}
|
|
53
|
+
/** Converts stored rows into palettes (validation happens where palettes are resolved). */ export function readAppearancePalettes(doc) {
|
|
54
|
+
const rows = doc && typeof doc === 'object' ? doc.palettes : undefined;
|
|
55
|
+
if (!Array.isArray(rows)) return [];
|
|
56
|
+
return rows.flatMap((row)=>{
|
|
57
|
+
if (!row || typeof row !== 'object') return [];
|
|
58
|
+
const { id: _id, dark, ...rest } = row;
|
|
59
|
+
const palette = Object.fromEntries(Object.entries(rest).filter(([, value])=>value !== null && value !== ''));
|
|
60
|
+
const darkColors = dark && typeof dark === 'object' ? Object.fromEntries(Object.entries(dark).filter(([key, value])=>key !== 'id' && value !== null && value !== '')) : {};
|
|
61
|
+
return typeof palette.name === 'string' ? [
|
|
62
|
+
{
|
|
63
|
+
...palette,
|
|
64
|
+
...Object.keys(darkColors).length > 0 ? {
|
|
65
|
+
dark: darkColors
|
|
66
|
+
} : {}
|
|
67
|
+
}
|
|
68
|
+
] : [];
|
|
69
|
+
});
|
|
70
|
+
}
|
|
71
|
+
function isPaletteSource(value) {
|
|
72
|
+
return Boolean(value) && typeof value.findGlobal === 'function';
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* Palettes managed in the appearance global, cached per process. Returns `[]`
|
|
76
|
+
* when the global is not enabled, no Payload instance is available, or it
|
|
77
|
+
* cannot be read (for example before its migration ran); the render then uses
|
|
78
|
+
* the configured palettes only.
|
|
79
|
+
*/ export async function loadAppearancePalettes(source) {
|
|
80
|
+
const runtime = getRuntime();
|
|
81
|
+
const slug = runtime.slug;
|
|
82
|
+
if (!slug) return [];
|
|
83
|
+
const now = Date.now();
|
|
84
|
+
if (runtime.cache && runtime.cache.expires > now) return runtime.cache.palettes;
|
|
85
|
+
if (runtime.pending) return runtime.pending;
|
|
86
|
+
const payload = isPaletteSource(source) ? source : runtime.payload;
|
|
87
|
+
if (!payload) return [];
|
|
88
|
+
const pending = payload.findGlobal({
|
|
89
|
+
slug: slug,
|
|
90
|
+
depth: 0,
|
|
91
|
+
overrideAccess: true
|
|
92
|
+
}).then((doc)=>{
|
|
93
|
+
const palettes = readAppearancePalettes(doc);
|
|
94
|
+
runtime.warned = false;
|
|
95
|
+
if (runtime.pending === pending) {
|
|
96
|
+
runtime.lastGood = palettes;
|
|
97
|
+
runtime.cache = {
|
|
98
|
+
expires: Date.now() + runtime.ttl,
|
|
99
|
+
palettes
|
|
100
|
+
};
|
|
101
|
+
runtime.pending = undefined;
|
|
102
|
+
}
|
|
103
|
+
return palettes;
|
|
104
|
+
}).catch((error)=>{
|
|
105
|
+
if (!runtime.warned) {
|
|
106
|
+
runtime.warned = true;
|
|
107
|
+
// eslint-disable-next-line no-console
|
|
108
|
+
console.warn(`[payload-markdown] Could not load palettes from the "${slug}" global; rendering with the last palettes loaded (or the configured ones). ` + `If you just enabled appearance on a SQL database, create and run a migration. (${error instanceof Error ? error.message : String(error)})`);
|
|
109
|
+
}
|
|
110
|
+
// A transient error must not strip palettes for a whole cache lifetime:
|
|
111
|
+
// keep serving the last good ones and retry soon.
|
|
112
|
+
const palettes = runtime.lastGood ?? [];
|
|
113
|
+
if (runtime.pending === pending) {
|
|
114
|
+
runtime.cache = {
|
|
115
|
+
expires: Date.now() + Math.min(runtime.ttl, RETRY_AFTER_ERROR_MS),
|
|
116
|
+
palettes
|
|
117
|
+
};
|
|
118
|
+
runtime.pending = undefined;
|
|
119
|
+
}
|
|
120
|
+
return palettes;
|
|
121
|
+
});
|
|
122
|
+
runtime.pending = pending;
|
|
123
|
+
return pending;
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
//# sourceMappingURL=runtime.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/appearance/runtime.ts"],"sourcesContent":["import type { Payload } from 'payload'\n\nimport type { MarkdownPalette } from '../types/core.js'\n\nimport { PAYLOAD_MARKDOWN_APPEARANCE_RUNTIME_KEY } from '../runtime/index.js'\n\n/**\n * Runtime state of the \"Markdown Appearance\" global, shared process-wide (like\n * the settings registry) so every copy of the package reads one cache.\n *\n * Renders read palettes from here, never per icon: the global is loaded at\n * most once per `ttl` per process (concurrent renders share one load), and a\n * save clears the cache of the process that saved it.\n */\ntype AppearanceRuntime = {\n cache?: { expires: number; palettes: MarkdownPalette[] }\n /** Last palettes loaded successfully: served while the global cannot be read. */\n lastGood?: MarkdownPalette[]\n /** Set at `onInit`; renders without their own Payload instance use it. */\n payload?: Payload\n pending?: Promise<MarkdownPalette[]>\n slug?: string\n ttl: number\n warned?: boolean\n}\n\n\n\ntype RuntimeHost = { [PAYLOAD_MARKDOWN_APPEARANCE_RUNTIME_KEY]?: AppearanceRuntime }\n\nfunction getRuntime(): AppearanceRuntime {\n const host = globalThis as RuntimeHost\n\n if (!host[PAYLOAD_MARKDOWN_APPEARANCE_RUNTIME_KEY])\n Object.defineProperty(globalThis, PAYLOAD_MARKDOWN_APPEARANCE_RUNTIME_KEY, {\n configurable: true,\n enumerable: false,\n value: { ttl: 30_000 },\n writable: false,\n })\n\n return host[PAYLOAD_MARKDOWN_APPEARANCE_RUNTIME_KEY]!\n}\n\n/** Called while the Payload config is built when `appearance` is enabled. */\nexport function registerAppearance({ slug, ttl }: { slug: string; ttl: number }) {\n const runtime = getRuntime()\n\n if (runtime.slug !== slug) {\n runtime.cache = undefined\n runtime.lastGood = undefined\n }\n runtime.slug = slug\n runtime.ttl = ttl\n}\n\n/** Called from `onInit` so renders without an explicit Payload instance can load palettes. */\nexport function attachAppearancePayload(payload: Payload) {\n getRuntime().payload = payload\n}\n\n/** Disables runtime palettes (the plugin was rebuilt without `appearance`). */\nexport function clearAppearance() {\n const runtime = getRuntime()\n\n runtime.slug = undefined\n runtime.cache = undefined\n runtime.lastGood = undefined\n runtime.pending = undefined\n}\n\nexport function invalidateAppearancePalettes() {\n const runtime = getRuntime()\n\n runtime.cache = undefined\n runtime.pending = undefined\n}\n\n/** Replaces the cached palettes with ones just saved (see the global's afterChange hook). */\nexport function primeAppearancePalettes(palettes: MarkdownPalette[]) {\n const runtime = getRuntime()\n\n runtime.pending = undefined\n runtime.lastGood = palettes\n runtime.cache = { expires: Date.now() + runtime.ttl, palettes }\n // A save went through, so the next read error is a new outage worth logging.\n runtime.warned = false\n}\n\n/** After a failed load, how long to wait before trying the database again. */\nconst RETRY_AFTER_ERROR_MS = 5_000\n\n/** Slug of the appearance global, or `undefined` when it is not enabled. */\nexport function getAppearanceSlug(): string | undefined {\n return getRuntime().slug\n}\n\n/** Converts stored rows into palettes (validation happens where palettes are resolved). */\nexport function readAppearancePalettes(doc: unknown): MarkdownPalette[] {\n const rows = doc && typeof doc === 'object' ? (doc as { palettes?: unknown }).palettes : undefined\n if (!Array.isArray(rows)) return []\n\n return rows.flatMap((row): MarkdownPalette[] => {\n if (!row || typeof row !== 'object') return []\n\n const { id: _id, dark, ...rest } = row as Record<string, unknown>\n const palette = Object.fromEntries(Object.entries(rest).filter(([, value]) => value !== null && value !== ''))\n const darkColors =\n dark && typeof dark === 'object'\n ? Object.fromEntries(\n Object.entries(dark as Record<string, unknown>).filter(\n ([key, value]) => key !== 'id' && value !== null && value !== '',\n ),\n )\n : {}\n\n return typeof palette.name === 'string'\n ? [{ ...(palette as MarkdownPalette), ...(Object.keys(darkColors).length > 0 ? { dark: darkColors } : {}) }]\n : []\n })\n}\n\ntype PaletteSource = Pick<Payload, 'findGlobal'>\n\nfunction isPaletteSource(value: unknown): value is PaletteSource {\n return Boolean(value) && typeof (value as PaletteSource).findGlobal === 'function'\n}\n\n/**\n * Palettes managed in the appearance global, cached per process. Returns `[]`\n * when the global is not enabled, no Payload instance is available, or it\n * cannot be read (for example before its migration ran); the render then uses\n * the configured palettes only.\n */\nexport async function loadAppearancePalettes(source?: unknown): Promise<MarkdownPalette[]> {\n const runtime = getRuntime()\n const slug = runtime.slug\n if (!slug) return []\n\n const now = Date.now()\n if (runtime.cache && runtime.cache.expires > now) return runtime.cache.palettes\n if (runtime.pending) return runtime.pending\n\n const payload = isPaletteSource(source) ? source : runtime.payload\n if (!payload) return []\n\n const pending = payload\n .findGlobal({ slug: slug as never, depth: 0, overrideAccess: true })\n .then((doc) => {\n const palettes = readAppearancePalettes(doc)\n\n runtime.warned = false\n\n if (runtime.pending === pending) {\n runtime.lastGood = palettes\n runtime.cache = { expires: Date.now() + runtime.ttl, palettes }\n runtime.pending = undefined\n }\n\n return palettes\n })\n .catch((error: unknown) => {\n if (!runtime.warned) {\n runtime.warned = true\n // eslint-disable-next-line no-console\n console.warn(\n `[payload-markdown] Could not load palettes from the \"${slug}\" global; rendering with the last palettes loaded (or the configured ones). ` +\n `If you just enabled appearance on a SQL database, create and run a migration. (${error instanceof Error ? error.message : String(error)})`,\n )\n }\n\n // A transient error must not strip palettes for a whole cache lifetime:\n // keep serving the last good ones and retry soon.\n const palettes = runtime.lastGood ?? []\n\n if (runtime.pending === pending) {\n runtime.cache = { expires: Date.now() + Math.min(runtime.ttl, RETRY_AFTER_ERROR_MS), palettes }\n runtime.pending = undefined\n }\n\n return palettes\n })\n\n runtime.pending = pending\n\n return pending\n}\n"],"names":["PAYLOAD_MARKDOWN_APPEARANCE_RUNTIME_KEY","getRuntime","host","globalThis","Object","defineProperty","configurable","enumerable","value","ttl","writable","registerAppearance","slug","runtime","cache","undefined","lastGood","attachAppearancePayload","payload","clearAppearance","pending","invalidateAppearancePalettes","primeAppearancePalettes","palettes","expires","Date","now","warned","RETRY_AFTER_ERROR_MS","getAppearanceSlug","readAppearancePalettes","doc","rows","Array","isArray","flatMap","row","id","_id","dark","rest","palette","fromEntries","entries","filter","darkColors","key","name","keys","length","isPaletteSource","Boolean","findGlobal","loadAppearancePalettes","source","depth","overrideAccess","then","catch","error","console","warn","Error","message","String","Math","min"],"mappings":"AAIA,SAASA,uCAAuC,QAAQ,sBAAqB;AA0B7E,SAASC;IACP,MAAMC,OAAOC;IAEb,IAAI,CAACD,IAAI,CAACF,wCAAwC,EAChDI,OAAOC,cAAc,CAACF,YAAYH,yCAAyC;QACzEM,cAAc;QACdC,YAAY;QACZC,OAAO;YAAEC,KAAK;QAAO;QACrBC,UAAU;IACZ;IAEF,OAAOR,IAAI,CAACF,wCAAwC;AACtD;AAEA,2EAA2E,GAC3E,OAAO,SAASW,mBAAmB,EAAEC,IAAI,EAAEH,GAAG,EAAiC;IAC7E,MAAMI,UAAUZ;IAEhB,IAAIY,QAAQD,IAAI,KAAKA,MAAM;QACzBC,QAAQC,KAAK,GAAGC;QAChBF,QAAQG,QAAQ,GAAGD;IACrB;IACAF,QAAQD,IAAI,GAAGA;IACfC,QAAQJ,GAAG,GAAGA;AAChB;AAEA,4FAA4F,GAC5F,OAAO,SAASQ,wBAAwBC,OAAgB;IACtDjB,aAA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B;QAEA,OAAOQ;IACT,GACCmC,KAAK,CAAC,CAACC;QACN,IAAI,CAAC9C,QAAQc,MAAM,EAAE;YACnBd,QAAQc,MAAM,GAAG;YACjB,sCAAsC;YACtCiC,QAAQC,IAAI,CACV,CAAC,qDAAqD,EAAEjD,KAAK,4EAA4E,CAAC,GACxI,CAAC,+EAA+E,EAAE+C,iBAAiBG,QAAQH,MAAMI,OAAO,GAAGC,OAAOL,OAAO,CAAC,CAAC;QAEjJ;QAEA,wEAAwE;QACxE,kDAAkD;QAClD,MAAMpC,WAAWV,QAAQG,QAAQ,IAAI,EAAE;QAEvC,IAAIH,QAAQO,OAAO,KAAKA,SAAS;YAC/BP,QAAQC,KAAK,GAAG;gBAAEU,SAASC,KAAKC,GAAG,KAAKuC,KAAKC,GAAG,CAACrD,QAAQJ,GAAG,EAAEmB;gBAAuBL;YAAS;YAC9FV,QAAQO,OAAO,GAAGL;QACpB;QAEA,OAAOQ;IACT;IAEFV,QAAQO,OAAO,GAAGA;IAElB,OAAOA;AACT"}
|
|
@@ -15,9 +15,12 @@ function extractCodeText(pre) {
|
|
|
15
15
|
function getTabsContainer(element) {
|
|
16
16
|
return element?.closest('[data-directive="tabs"]');
|
|
17
17
|
}
|
|
18
|
+
/** Elements of this tabs block only, not of tabs nested in its panels. */ function getOwnTabElements(tabs, selector) {
|
|
19
|
+
return Array.from(tabs.querySelectorAll(selector)).filter((element)=>getTabsContainer(element) === tabs);
|
|
20
|
+
}
|
|
18
21
|
function setActiveTab(tabs, value) {
|
|
19
|
-
const triggers =
|
|
20
|
-
const panels =
|
|
22
|
+
const triggers = getOwnTabElements(tabs, '[data-tab-trigger]');
|
|
23
|
+
const panels = getOwnTabElements(tabs, '[data-tab-panel]');
|
|
21
24
|
for (const trigger of triggers){
|
|
22
25
|
const active = trigger.getAttribute('data-tab-value') === value;
|
|
23
26
|
trigger.setAttribute('aria-selected', active ? 'true' : 'false');
|
|
@@ -30,7 +33,7 @@ function setActiveTab(tabs, value) {
|
|
|
30
33
|
}
|
|
31
34
|
}
|
|
32
35
|
function getEnabledTabTriggers(tabs) {
|
|
33
|
-
return
|
|
36
|
+
return getOwnTabElements(tabs, '[data-tab-trigger]').filter((trigger)=>!trigger.hasAttribute('disabled'));
|
|
34
37
|
}
|
|
35
38
|
function focusTabTrigger(triggers, index) {
|
|
36
39
|
const trigger = triggers[index];
|
|
@@ -54,22 +57,9 @@ export function MarkdownRendererClient({ containerId }) {
|
|
|
54
57
|
button.setAttribute('data-md-copy-label', 'Copy');
|
|
55
58
|
button.setAttribute('aria-label', 'Copy code block');
|
|
56
59
|
button.textContent = 'Copy';
|
|
57
|
-
button
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
button.style.zIndex = '1';
|
|
61
|
-
button.style.border = '1px solid rgba(255,255,255,0.12)';
|
|
62
|
-
button.style.borderRadius = '0.5rem';
|
|
63
|
-
button.style.background = 'rgba(24,24,27,0.9)';
|
|
64
|
-
button.style.color = '#e5e7eb';
|
|
65
|
-
button.style.fontSize = '0.75rem';
|
|
66
|
-
button.style.fontWeight = '500';
|
|
67
|
-
button.style.lineHeight = '1';
|
|
68
|
-
button.style.padding = '0.45rem 0.65rem';
|
|
69
|
-
button.style.cursor = 'pointer';
|
|
70
|
-
button.style.userSelect = 'none';
|
|
71
|
-
const preStyle = window.getComputedStyle(pre);
|
|
72
|
-
if (preStyle.position === 'static') pre.style.position = 'relative';
|
|
60
|
+
// Styled by `[data-md-copy-button]` in the renderer stylesheet, which
|
|
61
|
+
// positions it against the pre.
|
|
62
|
+
if (window.getComputedStyle(pre).position === 'static') pre.style.position = 'relative';
|
|
73
63
|
pre.appendChild(button);
|
|
74
64
|
});
|
|
75
65
|
const resetButtonLabel = (button, originalLabel)=>{
|