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/editor/directives/completions.ts"],"sourcesContent":["import type { Completion, CompletionContext } from '@codemirror/autocomplete'\n\nimport { autocompletion, snippetCompletion } from '@codemirror/autocomplete'\n\nimport type { MarkdownEditorDirectiveConfig } from '../directiveConfig.js'\n\nimport { layoutDirectiveRegistry } from '../../directives/registry.js'\nimport { getDirectiveThemeNames } from '../../directives/themes.js'\n\nexport function getDirectiveCompletionOptions() {\n return layoutDirectiveRegistry.getPublicDefinitions().flatMap((definition) => {\n const label = definition.editor.label.startsWith(':')\n ? definition.editor.label\n : `:::${definition.name}`\n const snippets = [\n {\n detail: definition.editor.detail,\n label,\n snippet: definition.editor.snippet,\n },\n ...(definition.editor.snippets ?? []).map((snippet) => ({\n detail: snippet.detail ?? definition.editor.detail,\n label: snippet.label,\n snippet: snippet.snippet,\n })),\n ]\n\n return snippets.map((snippet) =>\n snippetCompletion(snippet.snippet, {\n type: 'keyword',\n detail: snippet.detail,\n info: definition.description,\n label: snippet.label,\n }),\n )\n })\n}\n\nexport function getDirectiveAttributeCompletionOptions(name: string): Completion[] {\n const definition = layoutDirectiveRegistry.get(name)\n const attributes = definition?.allowedAttributes ?? []\n const detailPrefix = name === 'button' || name === 'badge' ? `::${name}` : `:::${name}`\n\n return attributes.map((attribute) =>\n snippetCompletion(`${attribute}=\"\\${${attribute}}\"`, {\n type: 'property',\n detail: `${detailPrefix} attribute`,\n label: attribute,\n }),\n )\n}\n\nexport function getDirectiveThemeValueCompletionOptions(\n name: string,\n attribute: string,\n config: MarkdownEditorDirectiveConfig = {},\n): Completion[] {\n const definition = layoutDirectiveRegistry.get(name)\n const groupName = definition?.themeAttributes?.[attribute]\n const detailPrefix = name === 'button' || name === 'badge' ? `::${name}` : `:::${name}`\n\n if (attribute === 'icon')\n return (config.iconPacks ?? []).map((alias) => ({\n type: 'constant',\n detail: 'icon pack',\n label: `@${alias}/`,\n }))\n\n if (!groupName)\n return (definition?.attributeValues?.[attribute] ?? []).map((value) => ({\n type: 'constant',\n detail: `${detailPrefix} ${attribute}`,\n label: value,\n }))\n\n return getDirectiveThemeNames(groupName, config.themes).map((themeName) => ({\n type: 'constant',\n detail: `${groupName} theme`,\n label: themeName,\n }))\n}\n\nfunction attributeCompletionSource(\n context: CompletionContext,\n config: MarkdownEditorDirectiveConfig,\n) {\n const line = context.state.doc.lineAt(context.pos)\n const beforeCursor = line.text.slice(0, context.pos - line.from)\n const containerMatch = beforeCursor.match(/^\\s*:::(\\w+)(?:\\[[^\\]]*\\])?\\s*\\{([^}]*)$/)\n const leafMatch = beforeCursor.match(/^\\s*::(button|badge)(?:\\[[^\\]]*\\])?\\s*\\{([^}]*)$/)\n const multilineMatch =\n containerMatch || leafMatch\n ? null\n : findOpenDirectiveAttributeBlock(context, beforeCursor)\n const directiveMatch = containerMatch\n ? {\n name: containerMatch[1],\n attributesBeforeCursor: containerMatch[2],\n }\n : leafMatch\n ? {\n name: leafMatch[1],\n attributesBeforeCursor: leafMatch[2],\n }\n : multilineMatch\n\n if (!directiveMatch) return null\n\n const { name, attributesBeforeCursor } = directiveMatch\n const valueMatch = attributesBeforeCursor.match(\n /(?:^|\\s)(align|gap|theme|cardTheme|cellTheme|icon|iconPosition|interval|linkScope|newTab|size|stack|stepTheme|style|tabTheme|target|type|variant|wrap)=[\"']?([^\"'\\s}]*)$/,\n )\n\n if (valueMatch) {\n const [, attribute, typedValue] = valueMatch\n const options = getDirectiveThemeValueCompletionOptions(name, attribute, config)\n\n if (options.length === 0) return null\n\n return {\n from: context.pos - typedValue.length,\n options,\n }\n }\n\n const attributeMatch = attributesBeforeCursor.match(/(?:^|\\s)([\\w-]*)$/)\n const typedAttribute = attributeMatch?.[1] ?? ''\n const options = getDirectiveAttributeCompletionOptions(name)\n\n if (options.length === 0) return null\n if (!context.explicit && typedAttribute.length === 0) return null\n\n return {\n from: context.pos - typedAttribute.length,\n options,\n }\n}\n\nfunction findOpenDirectiveAttributeBlock(\n context: CompletionContext,\n attributesBeforeCursor: string,\n): { attributesBeforeCursor: string; name: string } | null {\n const line = context.state.doc.lineAt(context.pos)\n\n for (let lineNumber = line.number - 1; lineNumber >= 1; --lineNumber) {\n const previousLine = context.state.doc.line(lineNumber).text\n const trimmed = previousLine.trim()\n\n if (!trimmed) break\n if (trimmed.includes('}')) break\n\n const containerMatch = previousLine.match(/^\\s*:::(\\w+)(?:\\[[^\\]]*\\])?\\s*\\{/)\n if (containerMatch)\n return {\n name: containerMatch[1],\n attributesBeforeCursor,\n }\n\n const leafMatch = previousLine.match(/^\\s*::(button|badge)(?:\\[[^\\]]*\\])?\\s*\\{/)\n if (leafMatch)\n return {\n name: leafMatch[1],\n attributesBeforeCursor,\n }\n }\n\n return null\n}\n\nfunction directiveCompletionSource(\n context: CompletionContext,\n config: MarkdownEditorDirectiveConfig = {},\n) {\n const attributeResult = attributeCompletionSource(context, config)\n if (attributeResult) return attributeResult\n\n const leafMatch = context.matchBefore(/::[\\w-]*/)\n if (leafMatch) {\n const line = context.state.doc.lineAt(context.pos)\n const beforeLeaf = line.text.slice(0, leafMatch.from - line.from)\n const typedLeaf = line.text.slice(leafMatch.from - line.from, leafMatch.to - line.from)\n\n if (!typedLeaf.startsWith(':::') && !beforeLeaf.trim())\n return {\n from: leafMatch.from,\n options: getDirectiveCompletionOptions().filter((option) =>\n typeof option.label === 'string'\n ? option.label.startsWith('::') && !option.label.startsWith(':::')\n : false,\n ),\n }\n }\n\n const match = context.matchBefore(/:::[\\w-]*/)\n\n if (!match) return null\n if (match.from === match.to && !context.explicit) return null\n\n return {\n from: match.from,\n options: getDirectiveCompletionOptions().filter((option) =>\n typeof option.label === 'string' ? option.label.startsWith(':::') : true,\n ),\n }\n}\n\n/**\n * Directive completions that know the field's configured themes and icon\n * packs (CORE-8). `config` comes from `field.admin.custom.payloadMarkdown`.\n */\nexport function createDirectiveCompletions(config: MarkdownEditorDirectiveConfig = {}) {\n return autocompletion({\n activateOnTyping: true,\n override: [(context: CompletionContext) => directiveCompletionSource(context, config)],\n })\n}\n\nexport const directiveCompletions = createDirectiveCompletions()\n"],"names":["autocompletion","snippetCompletion","layoutDirectiveRegistry","getDirectiveThemeNames","getDirectiveCompletionOptions","getPublicDefinitions","flatMap","definition","label","editor","startsWith","name","snippets","detail","snippet","map","type","info","description","getDirectiveAttributeCompletionOptions","get","attributes","allowedAttributes","detailPrefix","attribute","getDirectiveThemeValueCompletionOptions","config","groupName","themeAttributes","iconPacks","alias","attributeValues","value","themes","themeName","attributeCompletionSource","context","line","state","doc","lineAt","pos","beforeCursor","text","slice","from","containerMatch","match","leafMatch","multilineMatch","findOpenDirectiveAttributeBlock","directiveMatch","attributesBeforeCursor","valueMatch","typedValue","options","length","attributeMatch","typedAttribute","explicit","lineNumber","number","previousLine","trimmed","trim","includes","directiveCompletionSource","attributeResult","matchBefore","beforeLeaf","typedLeaf","to","filter","option","createDirectiveCompletions","activateOnTyping","override","directiveCompletions"],"mappings":"AAEA,SAASA,cAAc,EAAEC,iBAAiB,QAAQ,2BAA0B;AAI5E,SAASC,uBAAuB,QAAQ,+BAA8B;AACtE,SAASC,sBAAsB,QAAQ,6BAA4B;AAEnE,OAAO,SAASC;IACd,OAAOF,wBAAwBG,oBAAoB,GAAGC,OAAO,CAAC,CAACC;QAC7D,MAAMC,QAAQD,WAAWE,MAAM,CAACD,KAAK,CAACE,UAAU,CAAC,OAC7CH,WAAWE,MAAM,CAACD,KAAK,GACvB,CAAC,GAAG,EAAED,WAAWI,IAAI,EAAE;QAC3B,MAAMC,WAAW;YACf;gBACEC,QAAQN,WAAWE,MAAM,CAACI,MAAM;gBAChCL;gBACAM,SAASP,WAAWE,MAAM,CAACK,OAAO;YACpC;eACG,AAACP,CAAAA,WAAWE,MAAM,CAACG,QAAQ,IAAI,EAAE,AAAD,EAAGG,GAAG,CAAC,CAACD,UAAa,CAAA;oBACtDD,QAAQC,QAAQD,MAAM,IAAIN,WAAWE,MAAM,CAACI,MAAM;oBAClD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,aAAahC,KAAKM,IAAI,CAACC,KAAK,CAAC,GAAGI,UAAUH,IAAI,GAAGR,KAAKQ,IAAI;QAChE,MAAMyB,YAAYjC,KAAKM,IAAI,CAACC,KAAK,CAACI,UAAUH,IAAI,GAAGR,KAAKQ,IAAI,EAAEG,UAAUuB,EAAE,GAAGlC,KAAKQ,IAAI;QAEtF,IAAI,CAACyB,UAAU5D,UAAU,CAAC,UAAU,CAAC2D,WAAWL,IAAI,IAClD,OAAO;YACLnB,MAAMG,UAAUH,IAAI;YACpBU,SAASnD,gCAAgCoE,MAAM,CAAC,CAACC,SAC/C,OAAOA,OAAOjE,KAAK,KAAK,WACpBiE,OAAOjE,KAAK,CAACE,UAAU,CAAC,SAAS,CAAC+D,OAAOjE,KAAK,CAACE,UAAU,CAAC,SAC1D;QAER;IACJ;IAEA,MAAMqC,QAAQX,QAAQgC,WAAW,CAAC;IAElC,IAAI,CAACrB,OAAO,OAAO;IACnB,IAAIA,MAAMF,IAAI,KAAKE,MAAMwB,EAAE,IAAI,CAACnC,QAAQuB,QAAQ,EAAE,OAAO;IAEzD,OAAO;QACLd,MAAME,MAAMF,IAAI;QAChBU,SAASnD,gCAAgCoE,MAAM,CAAC,CAACC,SAC/C,OAAOA,OAAOjE,KAAK,KAAK,WAAWiE,OAAOjE,KAAK,CAACE,UAAU,CAAC,SAAS;IAExE;AACF;AAEA;;;CAGC,GACD,OAAO,SAASgE,2BAA2BhD,SAAwC,CAAC,CAAC;IACnF,OAAO1B,eAAe;QACpB2E,kBAAkB;QAClBC,UAAU;YAAC,CAACxC,UAA+B8B,0BAA0B9B,SAASV;SAAQ;IACxF;AACF;AAEA,OAAO,MAAMmD,uBAAuBH,6BAA4B"}
|
|
1
|
+
{"version":3,"sources":["../../../src/editor/directives/completions.ts"],"sourcesContent":["import type { Completion, CompletionContext } from '@codemirror/autocomplete'\n\nimport { autocompletion, snippetCompletion } from '@codemirror/autocomplete'\n\nimport type { MarkdownEditorDirectiveConfig } from '../directiveConfig.js'\n\nimport { layoutDirectiveRegistry } from '../../directives/registry.js'\nimport { getDirectiveThemeNames } from '../../directives/themes.js'\nimport { getEditorPaletteNames } from '../directiveConfig.js'\n\nexport function getDirectiveCompletionOptions() {\n return layoutDirectiveRegistry.getPublicDefinitions().flatMap((definition) => {\n const label = definition.editor.label.startsWith(':')\n ? definition.editor.label\n : `:::${definition.name}`\n const snippets = [\n {\n detail: definition.editor.detail,\n label,\n snippet: definition.editor.snippet,\n },\n ...(definition.editor.snippets ?? []).map((snippet) => ({\n detail: snippet.detail ?? definition.editor.detail,\n label: snippet.label,\n snippet: snippet.snippet,\n })),\n ]\n\n return snippets.map((snippet) =>\n snippetCompletion(snippet.snippet, {\n type: 'keyword',\n detail: snippet.detail,\n info: definition.description,\n label: snippet.label,\n }),\n )\n })\n}\n\nexport function getDirectiveAttributeCompletionOptions(name: string): Completion[] {\n const definition = layoutDirectiveRegistry.get(name)\n const attributes = definition?.allowedAttributes ?? []\n const detailPrefix = name === 'button' || name === 'badge' ? `::${name}` : `:::${name}`\n\n return attributes.map((attribute) =>\n snippetCompletion(`${attribute}=\"\\${${attribute}}\"`, {\n type: 'property',\n detail: `${detailPrefix} attribute`,\n label: attribute,\n }),\n )\n}\n\nexport function getDirectiveThemeValueCompletionOptions(\n name: string,\n attribute: string,\n config: MarkdownEditorDirectiveConfig = {},\n): Completion[] {\n const definition = layoutDirectiveRegistry.get(name)\n const groupName = definition?.themeAttributes?.[attribute]\n const detailPrefix = name === 'button' || name === 'badge' ? `::${name}` : `:::${name}`\n\n if (attribute === 'palette' || attribute === 'iconPalette') return getPaletteCompletionOptions(config)\n\n if (attribute === 'icon')\n return (config.iconPacks ?? []).map((alias) => ({\n type: 'constant',\n detail: 'icon pack',\n label: `@${alias}/`,\n }))\n\n if (!groupName)\n return (definition?.attributeValues?.[attribute] ?? []).map((value) => ({\n type: 'constant',\n detail: `${detailPrefix} ${attribute}`,\n label: value,\n }))\n\n return getDirectiveThemeNames(groupName, config.themes).map((themeName) => ({\n type: 'constant',\n detail: `${groupName} theme`,\n label: themeName,\n }))\n}\n\n/** Palette names: configured ones plus, once loaded, those managed in the admin. */\nexport function getPaletteCompletionOptions(config: MarkdownEditorDirectiveConfig = {}): Completion[] {\n const names = getEditorPaletteNames(config) ?? config.palettes ?? []\n\n return names.map((name) => ({ type: 'constant', detail: 'palette', label: name }))\n}\n\nfunction attributeCompletionSource(\n context: CompletionContext,\n config: MarkdownEditorDirectiveConfig,\n) {\n const line = context.state.doc.lineAt(context.pos)\n const beforeCursor = line.text.slice(0, context.pos - line.from)\n const containerMatch = beforeCursor.match(/^\\s*:::(\\w+)(?:\\[[^\\]]*\\])?\\s*\\{([^}]*)$/)\n const leafMatch = beforeCursor.match(/^\\s*::(button|badge)(?:\\[[^\\]]*\\])?\\s*\\{([^}]*)$/)\n const multilineMatch =\n containerMatch || leafMatch\n ? null\n : findOpenDirectiveAttributeBlock(context, beforeCursor)\n const directiveMatch = containerMatch\n ? {\n name: containerMatch[1],\n attributesBeforeCursor: containerMatch[2],\n }\n : leafMatch\n ? {\n name: leafMatch[1],\n attributesBeforeCursor: leafMatch[2],\n }\n : multilineMatch\n\n if (!directiveMatch) return null\n\n const { name, attributesBeforeCursor } = directiveMatch\n\n // `palette=` inside an icon entry: icon=\"@pack/a palette=|\"\n const iconPaletteMatch = attributesBeforeCursor.match(/(?:^|\\s)icon=[\"'][^\"']*\\spalette=([\\w-]*)$/)\n\n if (iconPaletteMatch) {\n const options = getPaletteCompletionOptions(config)\n\n return options.length > 0 ? { from: context.pos - iconPaletteMatch[1].length, options } : null\n }\n\n const valueMatch = attributesBeforeCursor.match(\n /(?:^|\\s)(align|gap|theme|cardTheme|cellTheme|icon|iconPalette|iconPosition|interval|linkScope|newTab|palette|size|stack|stepTheme|style|tabTheme|target|type|variant|wrap)=[\"']?([^\"'\\s}]*)$/,\n )\n\n if (valueMatch) {\n const [, attribute, typedValue] = valueMatch\n const options = getDirectiveThemeValueCompletionOptions(name, attribute, config)\n\n if (options.length === 0) return null\n\n return {\n from: context.pos - typedValue.length,\n options,\n }\n }\n\n const attributeMatch = attributesBeforeCursor.match(/(?:^|\\s)([\\w-]*)$/)\n const typedAttribute = attributeMatch?.[1] ?? ''\n const options = getDirectiveAttributeCompletionOptions(name)\n\n if (options.length === 0) return null\n if (!context.explicit && typedAttribute.length === 0) return null\n\n return {\n from: context.pos - typedAttribute.length,\n options,\n }\n}\n\nfunction findOpenDirectiveAttributeBlock(\n context: CompletionContext,\n attributesBeforeCursor: string,\n): { attributesBeforeCursor: string; name: string } | null {\n const line = context.state.doc.lineAt(context.pos)\n\n for (let lineNumber = line.number - 1; lineNumber >= 1; --lineNumber) {\n const previousLine = context.state.doc.line(lineNumber).text\n const trimmed = previousLine.trim()\n\n if (!trimmed) break\n if (trimmed.includes('}')) break\n\n const containerMatch = previousLine.match(/^\\s*:::(\\w+)(?:\\[[^\\]]*\\])?\\s*\\{/)\n if (containerMatch)\n return {\n name: containerMatch[1],\n attributesBeforeCursor,\n }\n\n const leafMatch = previousLine.match(/^\\s*::(button|badge)(?:\\[[^\\]]*\\])?\\s*\\{/)\n if (leafMatch)\n return {\n name: leafMatch[1],\n attributesBeforeCursor,\n }\n }\n\n return null\n}\n\nfunction directiveCompletionSource(\n context: CompletionContext,\n config: MarkdownEditorDirectiveConfig = {},\n) {\n const attributeResult = attributeCompletionSource(context, config)\n if (attributeResult) return attributeResult\n\n const leafMatch = context.matchBefore(/::[\\w-]*/)\n if (leafMatch) {\n const line = context.state.doc.lineAt(context.pos)\n const beforeLeaf = line.text.slice(0, leafMatch.from - line.from)\n const typedLeaf = line.text.slice(leafMatch.from - line.from, leafMatch.to - line.from)\n\n if (!typedLeaf.startsWith(':::') && !beforeLeaf.trim())\n return {\n from: leafMatch.from,\n options: getDirectiveCompletionOptions().filter((option) =>\n typeof option.label === 'string'\n ? option.label.startsWith('::') && !option.label.startsWith(':::')\n : false,\n ),\n }\n }\n\n const match = context.matchBefore(/:::[\\w-]*/)\n\n if (!match) return null\n if (match.from === match.to && !context.explicit) return null\n\n return {\n from: match.from,\n options: getDirectiveCompletionOptions().filter((option) =>\n typeof option.label === 'string' ? option.label.startsWith(':::') : true,\n ),\n }\n}\n\n/**\n * Directive completions that know the field's configured themes, icon packs\n * and palettes (CORE-8). `config` comes from `field.admin.custom.payloadMarkdown`.\n */\nexport function createDirectiveCompletions(config: MarkdownEditorDirectiveConfig = {}) {\n return autocompletion({\n activateOnTyping: true,\n override: [(context: CompletionContext) => directiveCompletionSource(context, config)],\n })\n}\n\nexport const directiveCompletions = createDirectiveCompletions()\n"],"names":["autocompletion","snippetCompletion","layoutDirectiveRegistry","getDirectiveThemeNames","getEditorPaletteNames","getDirectiveCompletionOptions","getPublicDefinitions","flatMap","definition","label","editor","startsWith","name","snippets","detail","snippet","map","type","info","description","getDirectiveAttributeCompletionOptions","get","attributes","allowedAttributes","detailPrefix","attribute","getDirectiveThemeValueCompletionOptions","config","groupName","themeAttributes","getPaletteCompletionOptions","iconPacks","alias","attributeValues","value","themes","themeName","names","palettes","attributeCompletionSource","context","line","state","doc","lineAt","pos","beforeCursor","text","slice","from","containerMatch","match","leafMatch","multilineMatch","findOpenDirectiveAttributeBlock","directiveMatch","attributesBeforeCursor","iconPaletteMatch","options","length","valueMatch","typedValue","attributeMatch","typedAttribute","explicit","lineNumber","number","previousLine","trimmed","trim","includes","directiveCompletionSource","attributeResult","matchBefore","beforeLeaf","typedLeaf","to","filter","option","createDirectiveCompletions","activateOnTyping","override","directiveCompletions"],"mappings":"AAEA,SAASA,cAAc,EAAEC,iBAAiB,QAAQ,2BAA0B;AAI5E,SAASC,uBAAuB,QAAQ,+BAA8B;AACtE,SAASC,sBAAsB,QAAQ,6BAA4B;AACnE,SAASC,qBAAqB,QAAQ,wBAAuB;AAE7D,OAAO,SAASC;IACd,OAAOH,wBAAwBI,oBAAoB,GAAGC,OAAO,CAAC,CAACC;QAC7D,MAAMC,QAAQD,WAAWE,MAAM,CAACD,KAAK,CAACE,UAAU,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O;YACLpB,MAAMG,UAAUH,IAAI;YACpBS,SAASrD,gCAAgCwE,MAAM,CAAC,CAACC,SAC/C,OAAOA,OAAOrE,KAAK,KAAK,WACpBqE,OAAOrE,KAAK,CAACE,UAAU,CAAC,SAAS,CAACmE,OAAOrE,KAAK,CAACE,UAAU,CAAC,SAC1D;QAER;IACJ;IAEA,MAAMwC,QAAQX,QAAQiC,WAAW,CAAC;IAElC,IAAI,CAACtB,OAAO,OAAO;IACnB,IAAIA,MAAMF,IAAI,KAAKE,MAAMyB,EAAE,IAAI,CAACpC,QAAQwB,QAAQ,EAAE,OAAO;IAEzD,OAAO;QACLf,MAAME,MAAMF,IAAI;QAChBS,SAASrD,gCAAgCwE,MAAM,CAAC,CAACC,SAC/C,OAAOA,OAAOrE,KAAK,KAAK,WAAWqE,OAAOrE,KAAK,CAACE,UAAU,CAAC,SAAS;IAExE;AACF;AAEA;;;CAGC,GACD,OAAO,SAASoE,2BAA2BpD,SAAwC,CAAC,CAAC;IACnF,OAAO3B,eAAe;QACpBgF,kBAAkB;QAClBC,UAAU;YAAC,CAACzC,UAA+B+B,0BAA0B/B,SAASb;SAAQ;IACxF;AACF;AAEA,OAAO,MAAMuD,uBAAuBH,6BAA4B"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { MarkdownEditorDirectiveConfig } from '../directiveConfig.js';
|
|
2
2
|
/**
|
|
3
|
-
* Directive lint source that knows the field's configured themes
|
|
4
|
-
*
|
|
3
|
+
* Directive lint source that knows the field's configured themes, icon packs
|
|
4
|
+
* and palettes (CORE-8), so custom ones are not reported as unknown.
|
|
5
5
|
*/
|
|
6
6
|
export declare const createDirectiveDiagnostics: (config?: MarkdownEditorDirectiveConfig) => import("@codemirror/state").Extension;
|
|
7
7
|
export declare const directiveDiagnostics: import("@codemirror/state").Extension;
|
|
@@ -1,11 +1,18 @@
|
|
|
1
1
|
import { linter } from '@codemirror/lint';
|
|
2
2
|
import { lintMarkdownDirectives } from '../../directives/diagnostics.js';
|
|
3
|
+
import { getEditorPaletteNames } from '../directiveConfig.js';
|
|
3
4
|
/**
|
|
4
|
-
* Directive lint source that knows the field's configured themes
|
|
5
|
-
*
|
|
5
|
+
* Directive lint source that knows the field's configured themes, icon packs
|
|
6
|
+
* and palettes (CORE-8), so custom ones are not reported as unknown.
|
|
6
7
|
*/ export const createDirectiveDiagnostics = (config = {})=>linter((view)=>{
|
|
7
8
|
try {
|
|
8
|
-
|
|
9
|
+
// Palettes managed in the admin load after the editor mounts; until then
|
|
10
|
+
// no palette is reported as unknown.
|
|
11
|
+
const options = {
|
|
12
|
+
...config,
|
|
13
|
+
palettes: getEditorPaletteNames(config)
|
|
14
|
+
};
|
|
15
|
+
return lintMarkdownDirectives(view.state.doc.toString(), options).map((diagnostic)=>({
|
|
9
16
|
from: diagnostic.from,
|
|
10
17
|
message: diagnostic.message,
|
|
11
18
|
severity: diagnostic.severity,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/editor/directives/diagnostics.ts"],"sourcesContent":["import type { Diagnostic } from '@codemirror/lint'\n\nimport { linter } from '@codemirror/lint'\n\nimport type { MarkdownEditorDirectiveConfig } from '../directiveConfig.js'\n\nimport { lintMarkdownDirectives } from '../../directives/diagnostics.js'\n\n/**\n * Directive lint source that knows the field's configured themes
|
|
1
|
+
{"version":3,"sources":["../../../src/editor/directives/diagnostics.ts"],"sourcesContent":["import type { Diagnostic } from '@codemirror/lint'\n\nimport { linter } from '@codemirror/lint'\n\nimport type { MarkdownEditorDirectiveConfig } from '../directiveConfig.js'\n\nimport { lintMarkdownDirectives } from '../../directives/diagnostics.js'\nimport { getEditorPaletteNames } from '../directiveConfig.js'\n\n/**\n * Directive lint source that knows the field's configured themes, icon packs\n * and palettes (CORE-8), so custom ones are not reported as unknown.\n */\nexport const createDirectiveDiagnostics = (config: MarkdownEditorDirectiveConfig = {}) =>\n linter((view): Diagnostic[] => {\n try {\n // Palettes managed in the admin load after the editor mounts; until then\n // no palette is reported as unknown.\n const options = { ...config, palettes: getEditorPaletteNames(config) }\n\n return lintMarkdownDirectives(view.state.doc.toString(), options).map((diagnostic) => ({\n from: diagnostic.from,\n message: diagnostic.message,\n severity: diagnostic.severity,\n to: diagnostic.to,\n }))\n } catch (error) {\n // A linter bug must never take the editor down or hide unrelated\n // diagnostics permanently; report it once at the top of the document.\n return [\n {\n from: 0,\n message: `Directive diagnostics failed: ${error instanceof Error ? error.message : String(error)}`,\n severity: 'info',\n to: 0,\n },\n ]\n }\n})\n\nexport const directiveDiagnostics = createDirectiveDiagnostics()\n"],"names":["linter","lintMarkdownDirectives","getEditorPaletteNames","createDirectiveDiagnostics","config","view","options","palettes","state","doc","toString","map","diagnostic","from","message","severity","to","error","Error","String","directiveDiagnostics"],"mappings":"AAEA,SAASA,MAAM,QAAQ,mBAAkB;AAIzC,SAASC,sBAAsB,QAAQ,kCAAiC;AACxE,SAASC,qBAAqB,QAAQ,wBAAuB;AAE7D;;;CAGC,GACD,OAAO,MAAMC,6BAA6B,CAACC,SAAwC,CAAC,CAAC,GACnFJ,OAAO,CAACK;QACR,IAAI;YACF,yEAAyE;YACzE,qCAAqC;YACrC,MAAMC,UAAU;gBAAE,GAAGF,MAAM;gBAAEG,UAAUL,sBAAsBE;YAAQ;YAErE,OAAOH,uBAAuBI,KAAKG,KAAK,CAACC,GAAG,CAACC,QAAQ,IAAIJ,SAASK,GAAG,CAAC,CAACC,aAAgB,CAAA;oBACrFC,MAAMD,WAAWC,IAAI;oBACrBC,SAASF,WAAWE,OAAO;oBAC3BC,UAAUH,WAAWG,QAAQ;oBAC7BC,IAAIJ,WAAWI,EAAE;gBACnB,CAAA;QACF,EAAE,OAAOC,OAAO;YACd,iEAAiE;YACjE,sEAAsE;YACtE,OAAO;gBACL;oBACEJ,MAAM;oBACNC,SAAS,CAAC,8BAA8B,EAAEG,iBAAiBC,QAAQD,MAAMH,OAAO,GAAGK,OAAOF,QAAQ;oBAClGF,UAAU;oBACVC,IAAI;gBACN;aACD;QACH;IACF,GAAE;AAEF,OAAO,MAAMI,uBAAuBjB,6BAA4B"}
|
package/dist/exports/client.d.ts
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
export { MarkdownBlockParamsEnableField } from '../blocks/MarkdownBlock/ParamsEnableField.client.js';
|
|
2
1
|
/**
|
|
3
2
|
* `payload-markdown/client` (or the scoped `@valkyrianlabs/...` name): the package's `'use client'`
|
|
4
3
|
* components, for bundled (Next.js / Payload admin) apps.
|
|
@@ -10,10 +9,14 @@ export { MarkdownBlockParamsEnableField } from '../blocks/MarkdownBlock/ParamsEn
|
|
|
10
9
|
* - `MarkdownBlockParamsEnableField` is the markdown block's "Enable Blocks
|
|
11
10
|
* Params" checkbox: it pre-fills the block's params with their effective
|
|
12
11
|
* values when checked.
|
|
12
|
+
* - `MarkdownPaletteRowLabel` labels palette rows in the "Markdown Appearance"
|
|
13
|
+
* global (`appearance` plugin option) with their name and colour swatches.
|
|
13
14
|
* - `MarkdownRendererClient` is the interactive island `MarkdownRenderer`
|
|
14
15
|
* mounts next to its HTML (tabs, code copy). Render it with the id of the
|
|
15
16
|
* element that contains HTML from `renderMarkdown()` to get the same
|
|
16
17
|
* behavior without `MarkdownRenderer`.
|
|
17
18
|
*/
|
|
19
|
+
export { MarkdownPaletteRowLabel } from '../appearance/PaletteRowLabel.client.js';
|
|
20
|
+
export { MarkdownBlockParamsEnableField } from '../blocks/MarkdownBlock/ParamsEnableField.client.js';
|
|
18
21
|
export { MarkdownRendererClient, type MarkdownRendererClientProps, } from '../components/MarkdownRenderer/Component.client.js';
|
|
19
22
|
export { PayloadMarkdownField } from '../field/MarkdownField/Component.js';
|
package/dist/exports/client.js
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
export { MarkdownBlockParamsEnableField } from '../blocks/MarkdownBlock/ParamsEnableField.client.js';
|
|
2
1
|
/**
|
|
3
2
|
* `payload-markdown/client` (or the scoped `@valkyrianlabs/...` name): the package's `'use client'`
|
|
4
3
|
* components, for bundled (Next.js / Payload admin) apps.
|
|
@@ -10,11 +9,15 @@ export { MarkdownBlockParamsEnableField } from '../blocks/MarkdownBlock/ParamsEn
|
|
|
10
9
|
* - `MarkdownBlockParamsEnableField` is the markdown block's "Enable Blocks
|
|
11
10
|
* Params" checkbox: it pre-fills the block's params with their effective
|
|
12
11
|
* values when checked.
|
|
12
|
+
* - `MarkdownPaletteRowLabel` labels palette rows in the "Markdown Appearance"
|
|
13
|
+
* global (`appearance` plugin option) with their name and colour swatches.
|
|
13
14
|
* - `MarkdownRendererClient` is the interactive island `MarkdownRenderer`
|
|
14
15
|
* mounts next to its HTML (tabs, code copy). Render it with the id of the
|
|
15
16
|
* element that contains HTML from `renderMarkdown()` to get the same
|
|
16
17
|
* behavior without `MarkdownRenderer`.
|
|
17
|
-
*/ export {
|
|
18
|
+
*/ export { MarkdownPaletteRowLabel } from '../appearance/PaletteRowLabel.client.js';
|
|
19
|
+
export { MarkdownBlockParamsEnableField } from '../blocks/MarkdownBlock/ParamsEnableField.client.js';
|
|
20
|
+
export { MarkdownRendererClient } from '../components/MarkdownRenderer/Component.client.js';
|
|
18
21
|
export { PayloadMarkdownField } from '../field/MarkdownField/Component.js';
|
|
19
22
|
|
|
20
23
|
//# sourceMappingURL=client.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/exports/client.ts"],"sourcesContent":["
|
|
1
|
+
{"version":3,"sources":["../../src/exports/client.ts"],"sourcesContent":["/**\n * `payload-markdown/client` (or the scoped `@valkyrianlabs/...` name): the package's `'use client'`\n * components, for bundled (Next.js / Payload admin) apps.\n *\n * - `PayloadMarkdownField` is the admin field component. The specifier\n * `<package>/server#PayloadMarkdownField` (used by\n * `markdownField()` and existing import maps) re-exports the same component\n * and keeps working.\n * - `MarkdownBlockParamsEnableField` is the markdown block's \"Enable Blocks\n * Params\" checkbox: it pre-fills the block's params with their effective\n * values when checked.\n * - `MarkdownPaletteRowLabel` labels palette rows in the \"Markdown Appearance\"\n * global (`appearance` plugin option) with their name and colour swatches.\n * - `MarkdownRendererClient` is the interactive island `MarkdownRenderer`\n * mounts next to its HTML (tabs, code copy). Render it with the id of the\n * element that contains HTML from `renderMarkdown()` to get the same\n * behavior without `MarkdownRenderer`.\n */\nexport { MarkdownPaletteRowLabel } from '../appearance/PaletteRowLabel.client.js'\nexport { MarkdownBlockParamsEnableField } from '../blocks/MarkdownBlock/ParamsEnableField.client.js'\nexport {\n MarkdownRendererClient,\n type MarkdownRendererClientProps,\n} from '../components/MarkdownRenderer/Component.client.js'\nexport { PayloadMarkdownField } from '../field/MarkdownField/Component.js'\n"],"names":["MarkdownPaletteRowLabel","MarkdownBlockParamsEnableField","MarkdownRendererClient","PayloadMarkdownField"],"mappings":"AAAA;;;;;;;;;;;;;;;;;CAiBC,GACD,SAASA,uBAAuB,QAAQ,0CAAyC;AACjF,SAASC,8BAA8B,QAAQ,sDAAqD;AACpG,SACEC,sBAAsB,QAEjB,qDAAoD;AAC3D,SAASC,oBAAoB,QAAQ,sCAAqC"}
|
package/dist/exports/render.d.ts
CHANGED
|
@@ -11,4 +11,5 @@ export { createHeadingSlugger, type HeadingAnchor, type HeadingSlugger, slugifyH
|
|
|
11
11
|
export { DIRECTIVE_SPEC_VERSION, type DirectiveAttributeType, type DirectiveSpec, type DirectiveSpecAttribute, type DirectiveSpecDirective, getDirectiveSpec, } from '../directives/spec.js';
|
|
12
12
|
export { renderMarkdown, type RenderMarkdownConfig } from '../render/renderMarkdown.js';
|
|
13
13
|
export { PAYLOAD_MARKDOWN_CONFIG_CUSTOM_KEY, type PayloadMarkdownResolvedSettings, type PayloadMarkdownSettingsSource, readPayloadMarkdownSettings, } from '../runtime/index.js';
|
|
14
|
-
export
|
|
14
|
+
export { PMD_COLOR_SCHEME_CLASS_NAMES } from '../styles/directiveSurface.js';
|
|
15
|
+
export type { MarkdownColorScheme, MarkdownRenderConfig, RenderMarkdownResult, } from '../types/core.js';
|
package/dist/exports/render.js
CHANGED
|
@@ -8,5 +8,6 @@ export { createHeadingSlugger, slugifyHeading } from '../directives/headingAncho
|
|
|
8
8
|
export { DIRECTIVE_SPEC_VERSION, getDirectiveSpec } from '../directives/spec.js';
|
|
9
9
|
export { renderMarkdown } from '../render/renderMarkdown.js';
|
|
10
10
|
export { PAYLOAD_MARKDOWN_CONFIG_CUSTOM_KEY, readPayloadMarkdownSettings } from '../runtime/index.js';
|
|
11
|
+
export { PMD_COLOR_SCHEME_CLASS_NAMES } from '../styles/directiveSurface.js';
|
|
11
12
|
|
|
12
13
|
//# sourceMappingURL=render.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/exports/render.ts"],"sourcesContent":["/**\n * `payload-markdown/render`: the headless, CSS-free and\n * React-free render API. Importable from plain Node (scripts, search\n * indexers, RSS/email, docs tooling) as well as from bundled apps.\n */\nexport type {\n DiagnosticPlace,\n RenderDiagnostic,\n RenderDiagnosticSeverity,\n RenderDiagnosticSource,\n} from '../core/diagnostics.js'\nexport type { MarkdownLink, MarkdownLinkKind } from '../core/renderData.js'\nexport { compileMarkdown, type RenderedMarkdown } from '../core/renderMarkdown.js'\nexport { extractHeadingAnchors } from '../directives/extractHeadings.js'\nexport {\n createHeadingSlugger,\n type HeadingAnchor,\n type HeadingSlugger,\n slugifyHeading,\n} from '../directives/headingAnchors.js'\nexport {\n DIRECTIVE_SPEC_VERSION,\n type DirectiveAttributeType,\n type DirectiveSpec,\n type DirectiveSpecAttribute,\n type DirectiveSpecDirective,\n getDirectiveSpec,\n} from '../directives/spec.js'\nexport { renderMarkdown, type RenderMarkdownConfig } from '../render/renderMarkdown.js'\nexport {\n PAYLOAD_MARKDOWN_CONFIG_CUSTOM_KEY,\n type PayloadMarkdownResolvedSettings,\n type PayloadMarkdownSettingsSource,\n readPayloadMarkdownSettings,\n} from '../runtime/index.js'\nexport type {
|
|
1
|
+
{"version":3,"sources":["../../src/exports/render.ts"],"sourcesContent":["/**\n * `payload-markdown/render`: the headless, CSS-free and\n * React-free render API. Importable from plain Node (scripts, search\n * indexers, RSS/email, docs tooling) as well as from bundled apps.\n */\nexport type {\n DiagnosticPlace,\n RenderDiagnostic,\n RenderDiagnosticSeverity,\n RenderDiagnosticSource,\n} from '../core/diagnostics.js'\nexport type { MarkdownLink, MarkdownLinkKind } from '../core/renderData.js'\nexport { compileMarkdown, type RenderedMarkdown } from '../core/renderMarkdown.js'\nexport { extractHeadingAnchors } from '../directives/extractHeadings.js'\nexport {\n createHeadingSlugger,\n type HeadingAnchor,\n type HeadingSlugger,\n slugifyHeading,\n} from '../directives/headingAnchors.js'\nexport {\n DIRECTIVE_SPEC_VERSION,\n type DirectiveAttributeType,\n type DirectiveSpec,\n type DirectiveSpecAttribute,\n type DirectiveSpecDirective,\n getDirectiveSpec,\n} from '../directives/spec.js'\nexport { renderMarkdown, type RenderMarkdownConfig } from '../render/renderMarkdown.js'\nexport {\n PAYLOAD_MARKDOWN_CONFIG_CUSTOM_KEY,\n type PayloadMarkdownResolvedSettings,\n type PayloadMarkdownSettingsSource,\n readPayloadMarkdownSettings,\n} from '../runtime/index.js'\nexport { PMD_COLOR_SCHEME_CLASS_NAMES } from '../styles/directiveSurface.js'\nexport type {\n MarkdownColorScheme,\n MarkdownRenderConfig,\n RenderMarkdownResult,\n} from '../types/core.js'\n"],"names":["compileMarkdown","extractHeadingAnchors","createHeadingSlugger","slugifyHeading","DIRECTIVE_SPEC_VERSION","getDirectiveSpec","renderMarkdown","PAYLOAD_MARKDOWN_CONFIG_CUSTOM_KEY","readPayloadMarkdownSettings","PMD_COLOR_SCHEME_CLASS_NAMES"],"mappings":"AAAA;;;;CAIC,GAQD,SAASA,eAAe,QAA+B,4BAA2B;AAClF,SAASC,qBAAqB,QAAQ,mCAAkC;AACxE,SACEC,oBAAoB,EAGpBC,cAAc,QACT,kCAAiC;AACxC,SACEC,sBAAsB,EAKtBC,gBAAgB,QACX,wBAAuB;AAC9B,SAASC,cAAc,QAAmC,8BAA6B;AACvF,SACEC,kCAAkC,EAGlCC,2BAA2B,QACtB,sBAAqB;AAC5B,SAASC,4BAA4B,QAAQ,gCAA+B"}
|
|
@@ -1,10 +1,26 @@
|
|
|
1
1
|
'use client';
|
|
2
2
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
|
-
import { FieldDescription, FieldError, FieldLabel, RenderCustomComponent, useField } from '@payloadcms/ui';
|
|
4
|
-
import React, { useCallback, useEffect, useMemo, useState } from 'react';
|
|
3
|
+
import { FieldDescription, FieldError, FieldLabel, RenderCustomComponent, useConfig, useField } from '@payloadcms/ui';
|
|
4
|
+
import React, { useCallback, useEffect, useMemo, useRef, useState } from 'react';
|
|
5
5
|
import { readEditorDirectiveConfig } from '../../editor/directiveConfig.js';
|
|
6
6
|
import { MarkdownCodeMirror } from '../../editor/MarkdownCodeMirror/Component.js';
|
|
7
7
|
const SAVE_DEBOUNCE_MS = 800;
|
|
8
|
+
/** How long the admin reuses palette names it loaded (every markdown field on a page shares one request). */ const PALETTE_NAMES_TTL_MS = 30_000;
|
|
9
|
+
const paletteNameRequests = new Map();
|
|
10
|
+
/** Names of the palettes in the appearance global, or `undefined` when they cannot be read. */ function loadAdminPaletteNames(url) {
|
|
11
|
+
const cached = paletteNameRequests.get(url);
|
|
12
|
+
if (cached && cached.expires > Date.now()) return cached.names;
|
|
13
|
+
const names = fetch(url, {
|
|
14
|
+
credentials: 'include'
|
|
15
|
+
}).then((response)=>response.ok ? response.json() : undefined).then((doc)=>doc ? (doc.palettes ?? []).flatMap((row)=>typeof row?.name === 'string' ? [
|
|
16
|
+
row.name
|
|
17
|
+
] : []) : undefined).catch(()=>undefined);
|
|
18
|
+
paletteNameRequests.set(url, {
|
|
19
|
+
expires: Date.now() + PALETTE_NAMES_TTL_MS,
|
|
20
|
+
names
|
|
21
|
+
});
|
|
22
|
+
return names;
|
|
23
|
+
}
|
|
8
24
|
const fieldBaseClass = 'field-type';
|
|
9
25
|
export const PayloadMarkdownField = (props)=>{
|
|
10
26
|
const { field, path: pathFromProps, readOnly: readOnlyFromProps, validate } = props;
|
|
@@ -34,9 +50,44 @@ export const PayloadMarkdownField = (props)=>{
|
|
|
34
50
|
// Configured themes and icon packs, injected by the plugin (CORE-8). Keyed
|
|
35
51
|
// by content so a new-but-equal config object does not rebuild the editor.
|
|
36
52
|
const directiveConfigKey = JSON.stringify(admin?.custom ?? null);
|
|
37
|
-
const
|
|
53
|
+
const staticDirectiveConfig = useMemo(()=>readEditorDirectiveConfig(JSON.parse(directiveConfigKey)), [
|
|
38
54
|
directiveConfigKey
|
|
39
55
|
]);
|
|
56
|
+
// Palettes managed in the admin are data, not config: load their names so
|
|
57
|
+
// completions and lint know palettes created after the app was built. The
|
|
58
|
+
// editor reads them through a getter, so their arrival does not rebuild it.
|
|
59
|
+
const { config: { routes, serverURL } } = useConfig();
|
|
60
|
+
const paletteNamesRef = useRef(undefined);
|
|
61
|
+
const appearanceSlug = staticDirectiveConfig?.appearanceSlug;
|
|
62
|
+
const staticPalettes = staticDirectiveConfig?.palettes;
|
|
63
|
+
useEffect(()=>{
|
|
64
|
+
if (!appearanceSlug) return;
|
|
65
|
+
let active = true;
|
|
66
|
+
const url = `${serverURL ?? ''}${routes.api}/globals/${encodeURIComponent(appearanceSlug)}?depth=0`;
|
|
67
|
+
void loadAdminPaletteNames(url).then((names)=>{
|
|
68
|
+
// Without read access the names stay unknown and no palette is linted.
|
|
69
|
+
if (active && names) paletteNamesRef.current = [
|
|
70
|
+
...new Set([
|
|
71
|
+
...staticPalettes ?? [],
|
|
72
|
+
...names
|
|
73
|
+
])
|
|
74
|
+
];
|
|
75
|
+
});
|
|
76
|
+
return ()=>{
|
|
77
|
+
active = false;
|
|
78
|
+
};
|
|
79
|
+
}, [
|
|
80
|
+
appearanceSlug,
|
|
81
|
+
routes.api,
|
|
82
|
+
serverURL,
|
|
83
|
+
staticPalettes
|
|
84
|
+
]);
|
|
85
|
+
const directiveConfig = useMemo(()=>staticDirectiveConfig && {
|
|
86
|
+
...staticDirectiveConfig,
|
|
87
|
+
getPaletteNames: ()=>paletteNamesRef.current
|
|
88
|
+
}, [
|
|
89
|
+
staticDirectiveConfig
|
|
90
|
+
]);
|
|
40
91
|
// Sync in external value changes only when they actually differ.
|
|
41
92
|
useEffect(()=>{
|
|
42
93
|
const nextValue = value ?? '';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/field/MarkdownField/Component.tsx"],"sourcesContent":["'use client'\n\nimport type { TextFieldClientComponent, Validate } from 'payload'\n\nimport {\n FieldDescription,\n FieldError,\n FieldLabel,\n RenderCustomComponent,\n useField,\n} from '@payloadcms/ui'\nimport React, { useCallback, useEffect, useMemo, useState } from 'react'\n\nimport { readEditorDirectiveConfig } from '../../editor/directiveConfig.js'\nimport { MarkdownCodeMirror } from '../../editor/MarkdownCodeMirror/Component.js'\n\nconst SAVE_DEBOUNCE_MS = 800\nconst fieldBaseClass = 'field-type'\n\nexport const PayloadMarkdownField: TextFieldClientComponent = (props) => {\n const { field, path: pathFromProps, readOnly: readOnlyFromProps, validate } = props\n const { admin, label, localized, maxLength, minLength, required } = field\n\n // Same client-side validation contract as Payload's own text field, so\n // length and required errors show before the server rejects a save.\n const memoizedValidate = useCallback<Validate>(\n (value, options) => {\n if (typeof validate !== 'function') return true\n\n return validate(value as string, {\n ...options,\n maxLength,\n minLength,\n required,\n } as Parameters<typeof validate>[1])\n },\n [validate, maxLength, minLength, required],\n )\n\n const {\n customComponents: { AfterInput, BeforeInput, Description, Error, Label } = {},\n disabled,\n path,\n setValue,\n showError,\n value,\n } = useField<string>({\n potentiallyStalePath: pathFromProps,\n validate: memoizedValidate,\n })\n\n const readOnly = Boolean(readOnlyFromProps || disabled || admin?.readOnly)\n const [draftValue, setDraftValue] = useState<string>(value ?? '')\n\n // Configured themes and icon packs, injected by the plugin (CORE-8). Keyed\n // by content so a new-but-equal config object does not rebuild the editor.\n const directiveConfigKey = JSON.stringify(admin?.custom ?? null)\n const directiveConfig = useMemo(\n () => readEditorDirectiveConfig(JSON.parse(directiveConfigKey)),\n [directiveConfigKey],\n )\n\n // Sync in external value changes only when they actually differ.\n useEffect(() => {\n const nextValue = value ?? ''\n if (nextValue === draftValue) return\n setDraftValue(nextValue)\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [value])\n\n // Debounce writes back into Payload form state / autosave machinery.\n useEffect(() => {\n if (readOnly) return\n if (draftValue === (value ?? '')) return\n\n const timer = window.setTimeout(() => {\n setValue(draftValue)\n }, SAVE_DEBOUNCE_MS)\n\n return () => window.clearTimeout(timer)\n }, [draftValue, readOnly, value, setValue])\n\n const placeholder =\n 'placeholder' in field && typeof field.placeholder === 'string'\n ? field.placeholder\n : typeof admin?.placeholder === 'string'\n ? admin.placeholder\n : 'Write markdown...'\n\n return (\n <div\n className={[\n fieldBaseClass,\n 'text',\n 'payload-markdown-field',\n admin?.className,\n showError && 'error',\n readOnly && 'read-only',\n ]\n .filter(Boolean)\n .join(' ')}\n >\n <RenderCustomComponent\n CustomComponent={Label}\n Fallback={<FieldLabel label={label} localized={localized} path={path} required={required} />}\n />\n <div className={`${fieldBaseClass}__wrap`}>\n <RenderCustomComponent\n CustomComponent={Error}\n Fallback={<FieldError path={path} showError={showError} />}\n />\n {BeforeInput}\n <MarkdownCodeMirror\n directiveConfig={directiveConfig}\n onChangeAction={setDraftValue}\n placeholder={placeholder}\n readOnly={readOnly}\n value={draftValue}\n />\n {AfterInput}\n <RenderCustomComponent\n CustomComponent={Description}\n Fallback={<FieldDescription description={admin?.description} path={path} />}\n />\n </div>\n </div>\n )\n}\n"],"names":["FieldDescription","FieldError","FieldLabel","RenderCustomComponent","useField","React","useCallback","useEffect","useMemo","useState","readEditorDirectiveConfig","MarkdownCodeMirror","SAVE_DEBOUNCE_MS","fieldBaseClass","PayloadMarkdownField","props","field","path","pathFromProps","readOnly","readOnlyFromProps","validate","admin","label","localized","maxLength","minLength","required","memoizedValidate","value","options","customComponents","AfterInput","BeforeInput","Description","Error","Label","disabled","setValue","showError","potentiallyStalePath","Boolean","draftValue","setDraftValue","directiveConfigKey","JSON","stringify","custom","directiveConfig","parse","nextValue","timer","window","setTimeout","clearTimeout","placeholder","div","className","filter","join","CustomComponent","Fallback","onChangeAction","description"],"mappings":"AAAA;;AAIA,SACEA,gBAAgB,EAChBC,UAAU,EACVC,UAAU,EACVC,qBAAqB,EACrBC,QAAQ,QACH,iBAAgB;AACvB,OAAOC,SAASC,WAAW,EAAEC,SAAS,EAAEC,OAAO,EAAEC,QAAQ,QAAQ,QAAO;AAExE,SAASC,yBAAyB,QAAQ,kCAAiC;AAC3E,SAASC,kBAAkB,QAAQ,+CAA8C;AAEjF,MAAMC,mBAAmB;AACzB,MAAMC,iBAAiB;AAEvB,OAAO,MAAMC,uBAAiD,CAACC;IAC7D,MAAM,EAAEC,KAAK,EAAEC,MAAMC,aAAa,EAAEC,UAAUC,iBAAiB,EAAEC,QAAQ,EAAE,GAAGN;IAC9E,MAAM,EAAEO,KAAK,EAAEC,KAAK,EAAEC,SAAS,EAAEC,SAAS,EAAEC,SAAS,EAAEC,QAAQ,EAAE,GAAGX;IAEpE,uEAAuE;IACvE,oEAAoE;IACpE,MAAMY,mBAAmBtB,YACvB,CAACuB,OAAOC;QACN,IAAI,OAAOT,aAAa,YAAY,OAAO;QAE3C,OAAOA,SAASQ,OAAiB;YAC/B,GAAGC,OAAO;YACVL;YACAC;YACAC;QACF;IACF,GACA;QAACN;QAAUI;QAAWC;QAAWC;KAAS;IAG5C,MAAM,EACJI,kBAAkB,EAAEC,UAAU,EAAEC,WAAW,EAAEC,WAAW,EAAEC,KAAK,EAAEC,KAAK,EAAE,GAAG,CAAC,CAAC,EAC7EC,QAAQ,EACRpB,IAAI,EACJqB,QAAQ,EACRC,SAAS,EACTV,KAAK,EACN,GAAGzB,SAAiB;QACnBoC,sBAAsBtB;QACtBG,UAAUO;IACZ;IAEA,MAAMT,WAAWsB,QAAQrB,qBAAqBiB,YAAYf,OAAOH;IACjE,MAAM,CAACu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Y,aAAaA;wBACbpC,UAAUA;wBACVU,OAAOa;;oBAERV;kCACD,KAAC7B;wBACCyD,iBAAiB1B;wBACjB2B,wBAAU,KAAC7D;4BAAiB+D,aAAazC,OAAOyC;4BAAa9C,MAAMA;;;;;;;AAK7E,EAAC"}
|
|
1
|
+
{"version":3,"sources":["../../../src/field/MarkdownField/Component.tsx"],"sourcesContent":["'use client'\n\nimport type { TextFieldClientComponent, Validate } from 'payload'\n\nimport {\n FieldDescription,\n FieldError,\n FieldLabel,\n RenderCustomComponent,\n useConfig,\n useField,\n} from '@payloadcms/ui'\nimport React, { useCallback, useEffect, useMemo, useRef, useState } from 'react'\n\nimport { readEditorDirectiveConfig } from '../../editor/directiveConfig.js'\nimport { MarkdownCodeMirror } from '../../editor/MarkdownCodeMirror/Component.js'\n\nconst SAVE_DEBOUNCE_MS = 800\n\n/** How long the admin reuses palette names it loaded (every markdown field on a page shares one request). */\nconst PALETTE_NAMES_TTL_MS = 30_000\nconst paletteNameRequests = new Map<string, { expires: number; names: Promise<string[] | undefined> }>()\n\n/** Names of the palettes in the appearance global, or `undefined` when they cannot be read. */\nfunction loadAdminPaletteNames(url: string): Promise<string[] | undefined> {\n const cached = paletteNameRequests.get(url)\n if (cached && cached.expires > Date.now()) return cached.names\n\n const names = fetch(url, { credentials: 'include' })\n .then((response) => (response.ok ? response.json() : undefined))\n .then((doc: { palettes?: Array<{ name?: unknown }> } | undefined) =>\n doc ? (doc.palettes ?? []).flatMap((row) => (typeof row?.name === 'string' ? [row.name] : [])) : undefined,\n )\n .catch(() => undefined)\n\n paletteNameRequests.set(url, { expires: Date.now() + PALETTE_NAMES_TTL_MS, names })\n\n return names\n}\nconst fieldBaseClass = 'field-type'\n\nexport const PayloadMarkdownField: TextFieldClientComponent = (props) => {\n const { field, path: pathFromProps, readOnly: readOnlyFromProps, validate } = props\n const { admin, label, localized, maxLength, minLength, required } = field\n\n // Same client-side validation contract as Payload's own text field, so\n // length and required errors show before the server rejects a save.\n const memoizedValidate = useCallback<Validate>(\n (value, options) => {\n if (typeof validate !== 'function') return true\n\n return validate(value as string, {\n ...options,\n maxLength,\n minLength,\n required,\n } as Parameters<typeof validate>[1])\n },\n [validate, maxLength, minLength, required],\n )\n\n const {\n customComponents: { AfterInput, BeforeInput, Description, Error, Label } = {},\n disabled,\n path,\n setValue,\n showError,\n value,\n } = useField<string>({\n potentiallyStalePath: pathFromProps,\n validate: memoizedValidate,\n })\n\n const readOnly = Boolean(readOnlyFromProps || disabled || admin?.readOnly)\n const [draftValue, setDraftValue] = useState<string>(value ?? '')\n\n // Configured themes and icon packs, injected by the plugin (CORE-8). Keyed\n // by content so a new-but-equal config object does not rebuild the editor.\n const directiveConfigKey = JSON.stringify(admin?.custom ?? null)\n const staticDirectiveConfig = useMemo(\n () => readEditorDirectiveConfig(JSON.parse(directiveConfigKey)),\n [directiveConfigKey],\n )\n\n // Palettes managed in the admin are data, not config: load their names so\n // completions and lint know palettes created after the app was built. The\n // editor reads them through a getter, so their arrival does not rebuild it.\n const {\n config: { routes, serverURL },\n } = useConfig()\n const paletteNamesRef = useRef<readonly string[] | undefined>(undefined)\n const appearanceSlug = staticDirectiveConfig?.appearanceSlug\n const staticPalettes = staticDirectiveConfig?.palettes\n\n useEffect(() => {\n if (!appearanceSlug) return\n\n let active = true\n const url = `${serverURL ?? ''}${routes.api}/globals/${encodeURIComponent(appearanceSlug)}?depth=0`\n\n void loadAdminPaletteNames(url).then((names) => {\n // Without read access the names stay unknown and no palette is linted.\n if (active && names) paletteNamesRef.current = [...new Set([...(staticPalettes ?? []), ...names])]\n })\n\n return () => {\n active = false\n }\n }, [appearanceSlug, routes.api, serverURL, staticPalettes])\n\n const directiveConfig = useMemo(\n () =>\n staticDirectiveConfig && {\n ...staticDirectiveConfig,\n getPaletteNames: () => paletteNamesRef.current,\n },\n [staticDirectiveConfig],\n )\n\n // Sync in external value changes only when they actually differ.\n useEffect(() => {\n const nextValue = value ?? ''\n if (nextValue === draftValue) return\n setDraftValue(nextValue)\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [value])\n\n // Debounce writes back into Payload form state / autosave machinery.\n useEffect(() => {\n if (readOnly) return\n if (draftValue === (value ?? '')) return\n\n const timer = window.setTimeout(() => {\n setValue(draftValue)\n }, SAVE_DEBOUNCE_MS)\n\n return () => window.clearTimeout(timer)\n }, [draftValue, readOnly, value, setValue])\n\n const placeholder =\n 'placeholder' in field && typeof field.placeholder === 'string'\n ? field.placeholder\n : typeof admin?.placeholder === 'string'\n ? admin.placeholder\n : 'Write markdown...'\n\n return (\n <div\n className={[\n fieldBaseClass,\n 'text',\n 'payload-markdown-field',\n admin?.className,\n showError && 'error',\n readOnly && 'read-only',\n ]\n .filter(Boolean)\n .join(' ')}\n >\n <RenderCustomComponent\n CustomComponent={Label}\n Fallback={<FieldLabel label={label} localized={localized} path={path} required={required} />}\n />\n <div className={`${fieldBaseClass}__wrap`}>\n <RenderCustomComponent\n CustomComponent={Error}\n Fallback={<FieldError path={path} showError={showError} />}\n />\n {BeforeInput}\n <MarkdownCodeMirror\n directiveConfig={directiveConfig}\n onChangeAction={setDraftValue}\n placeholder={placeholder}\n readOnly={readOnly}\n value={draftValue}\n />\n {AfterInput}\n <RenderCustomComponent\n CustomComponent={Description}\n Fallback={<FieldDescription description={admin?.description} path={path} />}\n />\n </div>\n </div>\n )\n}\n"],"names":["FieldDescription","FieldError","FieldLabel","RenderCustomComponent","useConfig","useField","React","useCallback","useEffect","useMemo","useRef","useState","readEditorDirectiveConfig","MarkdownCodeMirror","SAVE_DEBOUNCE_MS","PALETTE_NAMES_TTL_MS","paletteNameRequests","Map","loadAdminPaletteNames","url","cached","get","expires","Date","now","names","fetch","credentials","then","response","ok","json","undefined","doc","palettes","flatMap","row","name","catch","set","fieldBaseClass","PayloadMarkdownField","props","field","path","pathFromProps","readOnly","readOnlyFromProps","validate","admin","label","localized","maxLength","minLength","required","memoizedValidate","value","options","customComponents","AfterInput","BeforeInput","Description","Error","Label","disabled","setValue","showError","potentiallyStalePath","Boolean","draftValue","setDraftValue","directiveConfigKey","JSON","stringify","custom","staticDirectiveConfig","parse","config","routes","serverURL","paletteNamesRef","appearanceSlug","staticPalettes","active","api","encodeURIComponent","current","Set","directiveConfig","getPaletteNames","nextValue","timer","window","setTimeout","clearTimeout","placeholder","div","className","filter","join","CustomComponent","Fallback","onChangeAction","description"],"mappings":"AAAA;;AAIA,SACEA,gBAAgB,EAChBC,UAAU,EACVC,UAAU,EACVC,qBAAqB,EACrBC,SAAS,EACTC,QAAQ,QACH,iBAAgB;AACvB,OAAOC,SAASC,WAAW,EAAEC,SAAS,EAAEC,OAAO,EAAEC,MAAM,EAAEC,QAAQ,QAAQ,QAAO;AAEhF,SAASC,yBAAyB,QAAQ,kCAAiC;AAC3E,SAASC,kBAAkB,QAAQ,+CAA8C;AAEjF,MAAMC,mBAAmB;AAEzB,2GAA2G,GAC3G,MAAMC,uBAAuB;AAC7B,MAAMC,sBAAsB,IAAIC;AAEhC,6FAA6F,GAC7F,SAASC,sBAAsBC,GAAW;IACxC,MAAMC,SAASJ,oBAAoBK,GAAG,CAACF;IACvC,IAAIC,UAAUA,OAAOE,OAAO,GAAGC,KAAKC,GAAG,IAAI,OAAOJ,OAAOK,KAAK;IAE9D,MAAMA,QAAQC,MAAMP,KAAK;QAAEQ,aAAa;IAAU,GAC/CC,IAAI,CAAC,CAACC,WAAcA,SAASC,EAAE,GAAGD,SAASE,IAAI,KAAKC,WACpDJ,IAAI,CAAC,CAACK,MACLA,MAAM,AAACA,CAAAA,IAAIC,QAAQ,IAAI,EAAE,AAAD,EAAGC,OAAO,CAAC,CAACC,MAAS,OAAOA,KAAKC,SAAS,WAAW;gBAACD,IAAIC,IAAI;aAAC,GAAG,EAAE,IAAKL,WAElGM,KAAK,CAAC,IAAMN;IAEfhB,oBAAoBuB,GAAG,CAACpB,KAAK;QAAEG,SAASC,KAAKC,GAAG,KAAKT;QAAsBU;IAAM;IAEjF,OAAOA;AACT;AACA,MAAMe,iBAAiB;A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B,SACP+B,IAAI,CAAC;;0BAER,KAAChG;gBACCiG,iBAAiBrC;gBACjBsC,wBAAU,KAACnG;oBAAWgD,OAAOA;oBAAOC,WAAWA;oBAAWP,MAAMA;oBAAMU,UAAUA;;;0BAElF,MAAC0C;gBAAIC,WAAW,GAAGzD,eAAe,MAAM,CAAC;;kCACvC,KAACrC;wBACCiG,iBAAiBtC;wBACjBuC,wBAAU,KAACpG;4BAAW2C,MAAMA;4BAAMsB,WAAWA;;;oBAE9CN;kCACD,KAAC/C;wBACC2E,iBAAiBA;wBACjBc,gBAAgBhC;wBAChByB,aAAaA;wBACbjD,UAAUA;wBACVU,OAAOa;;oBAERV;kCACD,KAACxD;wBACCiG,iBAAiBvC;wBACjBwC,wBAAU,KAACrG;4BAAiBuG,aAAatD,OAAOsD;4BAAa3D,MAAMA;;;;;;;AAK7E,EAAC"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The `icon` attribute: one icon or a comma-separated list. Each entry is an
|
|
3
|
+
* icon ref, optionally followed by space-separated `key=value` options that
|
|
4
|
+
* belong to that icon alone:
|
|
5
|
+
*
|
|
6
|
+
* icon="@fa-brands/debian palette=debian, @fa-brands/ubuntu palette=ubuntu"
|
|
7
|
+
*
|
|
8
|
+
* Options travel with their icon, so reordering the list never swaps colours,
|
|
9
|
+
* and the same icon can appear twice with different palettes.
|
|
10
|
+
*/
|
|
11
|
+
export type IconEntry = {
|
|
12
|
+
/** Palette name for this icon only. */
|
|
13
|
+
palette?: string;
|
|
14
|
+
/** The `@pack/name` icon reference. */
|
|
15
|
+
ref: string;
|
|
16
|
+
};
|
|
17
|
+
export type ParsedIconEntries = {
|
|
18
|
+
entries: IconEntry[];
|
|
19
|
+
warnings: string[];
|
|
20
|
+
};
|
|
21
|
+
export declare function parseIconEntries(value: string | undefined): ParsedIconEntries;
|
|
22
|
+
export declare function getExtraIconWarnings(directive: string, entries: IconEntry[]): string[];
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The `icon` attribute: one icon or a comma-separated list. Each entry is an
|
|
3
|
+
* icon ref, optionally followed by space-separated `key=value` options that
|
|
4
|
+
* belong to that icon alone:
|
|
5
|
+
*
|
|
6
|
+
* icon="@fa-brands/debian palette=debian, @fa-brands/ubuntu palette=ubuntu"
|
|
7
|
+
*
|
|
8
|
+
* Options travel with their icon, so reordering the list never swaps colours,
|
|
9
|
+
* and the same icon can appear twice with different palettes.
|
|
10
|
+
*/ const ICON_ENTRY_OPTIONS = [
|
|
11
|
+
'palette'
|
|
12
|
+
];
|
|
13
|
+
export function parseIconEntries(value) {
|
|
14
|
+
const entries = [];
|
|
15
|
+
const warnings = [];
|
|
16
|
+
for (const raw of value?.split(',') ?? []){
|
|
17
|
+
const [ref, ...options] = raw.trim().split(/\s+/).filter(Boolean);
|
|
18
|
+
if (!ref) continue;
|
|
19
|
+
const entry = {
|
|
20
|
+
ref
|
|
21
|
+
};
|
|
22
|
+
for (const option of options){
|
|
23
|
+
const separator = option.indexOf('=');
|
|
24
|
+
const key = separator > 0 ? option.slice(0, separator) : '';
|
|
25
|
+
const optionValue = separator > 0 ? option.slice(separator + 1).replace(/^["']|["']$/g, '') : '';
|
|
26
|
+
if (!ICON_ENTRY_OPTIONS.includes(key) || !optionValue) {
|
|
27
|
+
warnings.push(`Unknown icon option "${option}" on "${ref}". Write options as key=value; supported: ${ICON_ENTRY_OPTIONS.join(', ')}.`);
|
|
28
|
+
continue;
|
|
29
|
+
}
|
|
30
|
+
entry.palette = optionValue;
|
|
31
|
+
}
|
|
32
|
+
entries.push(entry);
|
|
33
|
+
}
|
|
34
|
+
return {
|
|
35
|
+
entries,
|
|
36
|
+
warnings
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
/** Directives that show a single icon: extra entries of an `icon` list are reported. */ const SINGLE_ICON_DIRECTIVES = new Set([
|
|
40
|
+
'button',
|
|
41
|
+
'callout'
|
|
42
|
+
]);
|
|
43
|
+
export function getExtraIconWarnings(directive, entries) {
|
|
44
|
+
if (!SINGLE_ICON_DIRECTIVES.has(directive) || entries.length < 2) return [];
|
|
45
|
+
return [
|
|
46
|
+
`"${directive}" shows one icon; ${entries.slice(1).map((entry)=>`"${entry.ref}"`).join(', ')} ${entries.length > 2 ? 'are' : 'is'} ignored. Only cards show a list of icons.`
|
|
47
|
+
];
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
//# sourceMappingURL=entries.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/icons/entries.ts"],"sourcesContent":["/**\n * The `icon` attribute: one icon or a comma-separated list. Each entry is an\n * icon ref, optionally followed by space-separated `key=value` options that\n * belong to that icon alone:\n *\n * icon=\"@fa-brands/debian palette=debian, @fa-brands/ubuntu palette=ubuntu\"\n *\n * Options travel with their icon, so reordering the list never swaps colours,\n * and the same icon can appear twice with different palettes.\n */\n\nexport type IconEntry = {\n /** Palette name for this icon only. */\n palette?: string\n /** The `@pack/name` icon reference. */\n ref: string\n}\n\nexport type ParsedIconEntries = {\n entries: IconEntry[]\n warnings: string[]\n}\n\nconst ICON_ENTRY_OPTIONS = ['palette'] as const\n\nexport function parseIconEntries(value: string | undefined): ParsedIconEntries {\n const entries: IconEntry[] = []\n const warnings: string[] = []\n\n for (const raw of value?.split(',') ?? []) {\n const [ref, ...options] = raw.trim().split(/\\s+/).filter(Boolean)\n if (!ref) continue\n\n const entry: IconEntry = { ref }\n\n for (const option of options) {\n const separator = option.indexOf('=')\n const key = separator > 0 ? option.slice(0, separator) : ''\n const optionValue = separator > 0 ? option.slice(separator + 1).replace(/^[\"']|[\"']$/g, '') : ''\n\n if (!(ICON_ENTRY_OPTIONS as readonly string[]).includes(key) || !optionValue) {\n warnings.push(\n `Unknown icon option \"${option}\" on \"${ref}\". Write options as key=value; supported: ${ICON_ENTRY_OPTIONS.join(', ')}.`,\n )\n continue\n }\n\n entry.palette = optionValue\n }\n\n entries.push(entry)\n }\n\n return { entries, warnings }\n}\n\n/** Directives that show a single icon: extra entries of an `icon` list are reported. */\nconst SINGLE_ICON_DIRECTIVES = new Set(['button', 'callout'])\n\nexport function getExtraIconWarnings(directive: string, entries: IconEntry[]): string[] {\n if (!SINGLE_ICON_DIRECTIVES.has(directive) || entries.length < 2) return []\n\n return [\n `\"${directive}\" shows one icon; ${entries\n .slice(1)\n .map((entry) => `\"${entry.ref}\"`)\n .join(', ')} ${entries.length > 2 ? 'are' : 'is'} ignored. Only cards show a list of icons.`,\n ]\n}\n"],"names":["ICON_ENTRY_OPTIONS","parseIconEntries","value","entries","warnings","raw","split","ref","options","trim","filter","Boolean","entry","option","separator","indexOf","key","slice","optionValue","replace","includes","push","join","palette","SINGLE_ICON_DIRECTIVES","Set","getExtraIconWarnings","directive","has","length","map"],"mappings":"AAAA;;;;;;;;;CASC,GAcD,MAAMA,qBAAqB;IAAC;CAAU;AAEtC,OAAO,SAASC,iBAAiBC,KAAyB;IACxD,MAAMC,UAAuB,EAAE;IAC/B,MAAMC,WAAqB,EAAE;IAE7B,KAAK,MAAMC,OAAOH,OAAOI,MAAM,QAAQ,EAAE,CAAE;QACzC,MAAM,CAACC,KAAK,GAAGC,QAAQ,GAAGH,IAAII,IAAI,GAAGH,KAAK,CAAC,OAAOI,MAAM,CAACC;QACzD,IAAI,CAACJ,KAAK;QAEV,MAAMK,QAAmB;YAAEL;QAAI;QAE/B,KAAK,MAAMM,UAAUL,QAAS;YAC5B,MAAMM,YAAYD,OAAOE,OAAO,CAAC;YACjC,MAAMC,MAAMF,YAAY,IAAID,OAAOI,KAAK,CAAC,GAAGH,aAAa;YACzD,MAAMI,cAAcJ,YAAY,IAAID,OAAOI,KAAK,CAACH,YAAY,GAAGK,OAAO,CAAC,gBAAgB,MAAM;YAE9F,IAAI,CAAC,AAACnB,mBAAyCoB,QAAQ,CAACJ,QAAQ,CAACE,aAAa;gBAC5Ed,SAASiB,IAAI,CACX,CAAC,qBAAqB,EAAER,OAAO,MAAM,EAAEN,IAAI,0CAA0C,EAAEP,mBAAmBsB,IAAI,CAAC,MAAM,CAAC,CAAC;gBAEzH;YACF;YAEAV,MAAMW,OAAO,GAAGL;QAClB;QAEAf,QAAQkB,IAAI,CAACT;IACf;IAEA,OAAO;QAAET;QAASC;IAAS;AAC7B;AAEA,sFAAsF,GACtF,MAAMoB,yBAAyB,IAAIC,IAAI;IAAC;IAAU;CAAU;AAE5D,OAAO,SAASC,qBAAqBC,SAAiB,EAAExB,OAAoB;IAC1E,IAAI,CAACqB,uBAAuBI,GAAG,CAACD,cAAcxB,QAAQ0B,MAAM,GAAG,GAAG,OAAO,EAAE;IAE3E,OAAO;QACL,CAAC,CAAC,EAAEF,UAAU,kBAAkB,EAAExB,QAC/Bc,KAAK,CAAC,GACNa,GAAG,CAAC,CAAClB,QAAU,CAAC,CAAC,EAAEA,MAAML,GAAG,CAAC,CAAC,CAAC,EAC/Be,IAAI,CAAC,MAAM,CAAC,EAAEnB,QAAQ0B,MAAM,GAAG,IAAI,QAAQ,KAAK,0CAA0C,CAAC;KAC/F;AACH"}
|
package/dist/icons/resolve.d.ts
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import type { RootContent } from 'hast';
|
|
2
2
|
import type { PayloadMarkdownIconsConfig } from '../types/core.js';
|
|
3
|
+
import { type SvgPaint } from './sanitizeSvg.js';
|
|
3
4
|
export type PayloadMarkdownIconResolution = {
|
|
4
5
|
iconKey?: string;
|
|
5
6
|
nodes: RootContent[];
|
|
6
7
|
warnings: string[];
|
|
7
8
|
};
|
|
8
9
|
export declare function validatePayloadMarkdownIconsConfig(config: PayloadMarkdownIconsConfig | undefined): string[];
|
|
9
|
-
export declare function resolvePayloadMarkdownIcon(ref: string | undefined, config: PayloadMarkdownIconsConfig | undefined, className: string): PayloadMarkdownIconResolution;
|
|
10
|
+
export declare function resolvePayloadMarkdownIcon(ref: string | undefined, config: PayloadMarkdownIconsConfig | undefined, className: string, paint?: SvgPaint): PayloadMarkdownIconResolution;
|
package/dist/icons/resolve.js
CHANGED
|
@@ -50,7 +50,7 @@ function statFile(file) {
|
|
|
50
50
|
return undefined;
|
|
51
51
|
}
|
|
52
52
|
}
|
|
53
|
-
export function resolvePayloadMarkdownIcon(ref, config, className) {
|
|
53
|
+
export function resolvePayloadMarkdownIcon(ref, config, className, paint) {
|
|
54
54
|
if (!ref) return {
|
|
55
55
|
nodes: [],
|
|
56
56
|
warnings: []
|
|
@@ -103,7 +103,7 @@ export function resolvePayloadMarkdownIcon(ref, config, className) {
|
|
|
103
103
|
return {
|
|
104
104
|
iconKey: normalized.icon.key,
|
|
105
105
|
nodes: [
|
|
106
|
-
instantiateSanitizedSvg(svg, className)
|
|
106
|
+
instantiateSanitizedSvg(svg, className, paint)
|
|
107
107
|
],
|
|
108
108
|
warnings: []
|
|
109
109
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/icons/resolve.ts"],"sourcesContent":["import type { Element, RootContent } from 'hast'\n\nimport fs from 'node:fs'\nimport path from 'node:path'\n\nimport type { PayloadMarkdownIconsConfig } from '../types/core.js'\n\nimport {\n hasUnsafeIconPathSegments,\n normalizePayloadMarkdownIconRef,\n} from './refs.js'\nimport { instantiateSanitizedSvg, parseAndSanitizeSvg } from './sanitizeSvg.js'\n\nexport type PayloadMarkdownIconResolution = {\n iconKey?: string\n nodes: RootContent[]\n warnings: string[]\n}\n\nfunction isWithin(parent: string, child: string): boolean {\n const relative = path.relative(parent, child)\n\n return Boolean(relative) && !relative.startsWith('..') && !path.isAbsolute(relative)\n}\n\nexport function validatePayloadMarkdownIconsConfig(\n config: PayloadMarkdownIconsConfig | undefined,\n): string[] {\n if (!config) return []\n\n const warnings: string[] = []\n const seenAliases = new Set<string>()\n\n if (!config.baseDir?.trim()) warnings.push('Icon config baseDir must not be empty.')\n\n for (const pack of config.packs ?? []) {\n const alias = pack.alias.trim()\n const packPath = pack.path.trim()\n\n if (!alias) {\n warnings.push('Icon pack aliases must not be empty.')\n continue\n }\n\n if (seenAliases.has(alias)) warnings.push(`Duplicate icon pack alias \"${alias}\".`)\n seenAliases.add(alias)\n\n if (!packPath) warnings.push(`Icon pack \"${alias}\" path must not be empty.`)\n else if (hasUnsafeIconPathSegments(packPath))\n warnings.push(`Icon pack \"${alias}\" path must be a safe relative path.`)\n }\n\n return warnings\n}\n\ntype CachedIcon = {\n mtimeMs: number\n size: number\n svg: Element | undefined\n}\n\nconst MAX_CACHED_ICONS = 2000\nconst iconCache = new Map<string, CachedIcon>()\n\nfunction loadSanitizedIcon(iconFile: string, stats: fs.Stats): Element | undefined {\n const cached = iconCache.get(iconFile)\n\n if (cached && cached.mtimeMs === stats.mtimeMs && cached.size === stats.size) return cached.svg\n\n const svg = parseAndSanitizeSvg(fs.readFileSync(iconFile, 'utf8'))\n\n if (iconCache.size >= MAX_CACHED_ICONS) {\n const oldest = iconCache.keys().next().value\n if (oldest !== undefined) iconCache.delete(oldest)\n }\n\n iconCache.set(iconFile, { mtimeMs: stats.mtimeMs, size: stats.size, svg })\n\n return svg\n}\n\nfunction statFile(file: string): fs.Stats | undefined {\n try {\n const stats = fs.statSync(file)\n\n return stats.isFile() ? stats : undefined\n } catch {\n return undefined\n }\n}\n\nexport function resolvePayloadMarkdownIcon(\n ref: string | undefined,\n config: PayloadMarkdownIconsConfig | undefined,\n className: string,\n): PayloadMarkdownIconResolution {\n if (!ref) return { nodes: [], warnings: [] }\n\n const normalized = normalizePayloadMarkdownIconRef(ref)\n if (normalized.warning) return { nodes: [], warnings: [normalized.warning] }\n if (!normalized.icon) return { nodes: [], warnings: [] }\n\n const pack = config?.packs?.find((entry) => entry.alias === normalized.icon?.packAlias)\n if (!pack)\n return {\n iconKey: normalized.icon.key,\n nodes: [],\n warnings: [`Unknown icon pack \"${normalized.icon.packAlias}\".`],\n }\n\n const baseDir = path.resolve(process.cwd(), config?.baseDir ?? '')\n const packRoot = path.resolve(baseDir, pack.path)\n const iconFile = path.resolve(packRoot, `${normalized.icon.iconPath}.svg`)\n\n if (!isWithin(packRoot, iconFile))\n return {\n iconKey: normalized.icon.key,\n nodes: [],\n warnings: [`Malformed icon ref \"${ref}\". Icon paths must stay within their icon pack.`],\n }\n\n const stats = statFile(iconFile)\n\n if (!stats)\n return {\n iconKey: normalized.icon.key,\n nodes: [],\n warnings: [`Unknown icon \"${normalized.icon.key}\".`],\n }\n\n const svg = loadSanitizedIcon(iconFile, stats)\n\n if (!svg)\n return {\n iconKey: normalized.icon.key,\n nodes: [],\n warnings: [`Icon \"${normalized.icon.key}\" does not contain an <svg> element.`],\n }\n\n return {\n iconKey: normalized.icon.key,\n nodes: [instantiateSanitizedSvg(svg, className)],\n warnings: [],\n }\n}\n"],"names":["fs","path","hasUnsafeIconPathSegments","normalizePayloadMarkdownIconRef","instantiateSanitizedSvg","parseAndSanitizeSvg","isWithin","parent","child","relative","Boolean","startsWith","isAbsolute","validatePayloadMarkdownIconsConfig","config","warnings","seenAliases","Set","baseDir","trim","push","pack","packs","alias","packPath","has","add","MAX_CACHED_ICONS","iconCache","Map","loadSanitizedIcon","iconFile","stats","cached","get","mtimeMs","size","svg","readFileSync","oldest","keys","next","value","undefined","delete","set","statFile","file","statSync","isFile","resolvePayloadMarkdownIcon","ref","className","nodes","normalized","warning","icon","find","entry","packAlias","iconKey","key","resolve","process","cwd","packRoot","iconPath"],"mappings":"AAEA,OAAOA,QAAQ,UAAS;AACxB,OAAOC,UAAU,YAAW;AAI5B,SACEC,yBAAyB,EACzBC,+BAA+B,QAC1B,YAAW;AAClB,SAASC,uBAAuB,EAAEC,mBAAmB,
|
|
1
|
+
{"version":3,"sources":["../../src/icons/resolve.ts"],"sourcesContent":["import type { Element, RootContent } from 'hast'\n\nimport fs from 'node:fs'\nimport path from 'node:path'\n\nimport type { PayloadMarkdownIconsConfig } from '../types/core.js'\n\nimport {\n hasUnsafeIconPathSegments,\n normalizePayloadMarkdownIconRef,\n} from './refs.js'\nimport { instantiateSanitizedSvg, parseAndSanitizeSvg, type SvgPaint } from './sanitizeSvg.js'\n\nexport type PayloadMarkdownIconResolution = {\n iconKey?: string\n nodes: RootContent[]\n warnings: string[]\n}\n\nfunction isWithin(parent: string, child: string): boolean {\n const relative = path.relative(parent, child)\n\n return Boolean(relative) && !relative.startsWith('..') && !path.isAbsolute(relative)\n}\n\nexport function validatePayloadMarkdownIconsConfig(\n config: PayloadMarkdownIconsConfig | undefined,\n): string[] {\n if (!config) return []\n\n const warnings: string[] = []\n const seenAliases = new Set<string>()\n\n if (!config.baseDir?.trim()) warnings.push('Icon config baseDir must not be empty.')\n\n for (const pack of config.packs ?? []) {\n const alias = pack.alias.trim()\n const packPath = pack.path.trim()\n\n if (!alias) {\n warnings.push('Icon pack aliases must not be empty.')\n continue\n }\n\n if (seenAliases.has(alias)) warnings.push(`Duplicate icon pack alias \"${alias}\".`)\n seenAliases.add(alias)\n\n if (!packPath) warnings.push(`Icon pack \"${alias}\" path must not be empty.`)\n else if (hasUnsafeIconPathSegments(packPath))\n warnings.push(`Icon pack \"${alias}\" path must be a safe relative path.`)\n }\n\n return warnings\n}\n\ntype CachedIcon = {\n mtimeMs: number\n size: number\n svg: Element | undefined\n}\n\nconst MAX_CACHED_ICONS = 2000\nconst iconCache = new Map<string, CachedIcon>()\n\nfunction loadSanitizedIcon(iconFile: string, stats: fs.Stats): Element | undefined {\n const cached = iconCache.get(iconFile)\n\n if (cached && cached.mtimeMs === stats.mtimeMs && cached.size === stats.size) return cached.svg\n\n const svg = parseAndSanitizeSvg(fs.readFileSync(iconFile, 'utf8'))\n\n if (iconCache.size >= MAX_CACHED_ICONS) {\n const oldest = iconCache.keys().next().value\n if (oldest !== undefined) iconCache.delete(oldest)\n }\n\n iconCache.set(iconFile, { mtimeMs: stats.mtimeMs, size: stats.size, svg })\n\n return svg\n}\n\nfunction statFile(file: string): fs.Stats | undefined {\n try {\n const stats = fs.statSync(file)\n\n return stats.isFile() ? stats : undefined\n } catch {\n return undefined\n }\n}\n\nexport function resolvePayloadMarkdownIcon(\n ref: string | undefined,\n config: PayloadMarkdownIconsConfig | undefined,\n className: string,\n paint?: SvgPaint,\n): PayloadMarkdownIconResolution {\n if (!ref) return { nodes: [], warnings: [] }\n\n const normalized = normalizePayloadMarkdownIconRef(ref)\n if (normalized.warning) return { nodes: [], warnings: [normalized.warning] }\n if (!normalized.icon) return { nodes: [], warnings: [] }\n\n const pack = config?.packs?.find((entry) => entry.alias === normalized.icon?.packAlias)\n if (!pack)\n return {\n iconKey: normalized.icon.key,\n nodes: [],\n warnings: [`Unknown icon pack \"${normalized.icon.packAlias}\".`],\n }\n\n const baseDir = path.resolve(process.cwd(), config?.baseDir ?? '')\n const packRoot = path.resolve(baseDir, pack.path)\n const iconFile = path.resolve(packRoot, `${normalized.icon.iconPath}.svg`)\n\n if (!isWithin(packRoot, iconFile))\n return {\n iconKey: normalized.icon.key,\n nodes: [],\n warnings: [`Malformed icon ref \"${ref}\". Icon paths must stay within their icon pack.`],\n }\n\n const stats = statFile(iconFile)\n\n if (!stats)\n return {\n iconKey: normalized.icon.key,\n nodes: [],\n warnings: [`Unknown icon \"${normalized.icon.key}\".`],\n }\n\n const svg = loadSanitizedIcon(iconFile, stats)\n\n if (!svg)\n return {\n iconKey: normalized.icon.key,\n nodes: [],\n warnings: [`Icon \"${normalized.icon.key}\" does not contain an <svg> element.`],\n }\n\n return {\n iconKey: normalized.icon.key,\n nodes: [instantiateSanitizedSvg(svg, className, paint)],\n warnings: [],\n }\n}\n"],"names":["fs","path","hasUnsafeIconPathSegments","normalizePayloadMarkdownIconRef","instantiateSanitizedSvg","parseAndSanitizeSvg","isWithin","parent","child","relative","Boolean","startsWith","isAbsolute","validatePayloadMarkdownIconsConfig","config","warnings","seenAliases","Set","baseDir","trim","push","pack","packs","alias","packPath","has","add","MAX_CACHED_ICONS","iconCache","Map","loadSanitizedIcon","iconFile","stats","cached","get","mtimeMs","size","svg","readFileSync","oldest","keys","next","value","undefined","delete","set","statFile","file","statSync","isFile","resolvePayloadMarkdownIcon","ref","className","paint","nodes","normalized","warning","icon","find","entry","packAlias","iconKey","key","resolve","process","cwd","packRoot","iconPath"],"mappings":"AAEA,OAAOA,QAAQ,UAAS;AACxB,OAAOC,UAAU,YAAW;AAI5B,SACEC,yBAAyB,EACzBC,+BAA+B,QAC1B,YAAW;AAClB,SAASC,uBAAuB,EAAEC,mBAAmB,QAAuB,mBAAkB;AAQ9F,SAASC,SAASC,MAAc,EAAEC,KAAa;IAC7C,MAAMC,WAAWR,KAAKQ,QAAQ,CAACF,QAAQC;IAEvC,OAAOE,QAAQD,aAAa,CAACA,SAASE,UAAU,CAAC,SAAS,CAACV,KAAKW,UAAU,CAACH;AAC7E;AAEA,OAAO,SAASI,mCACdC,MAA8C;IAE9C,IAAI,CAACA,QAAQ,OAAO,EAAE;IAEtB,MAAMC,WAAqB,EAAE;IAC7B,MAAMC,cAAc,IAAIC;IAExB,IAAI,CAACH,OAAOI,OAAO,EAAEC,QAAQJ,SAASK,IAAI,CAAC;IAE3C,KAAK,MAAMC,QAAQP,OAAOQ,KAAK,IAAI,EAAE,CAAE;QACrC,MAAMC,QAAQF,KAAKE,KAAK,CAACJ,IAAI;QAC7B,MAAMK,WAAWH,KAAKpB,IAAI,CAACkB,IAAI;QAE/B,IAAI,CAACI,OAAO;YACVR,SAASK,IAAI,CAAC;YACd;QACF;QAEA,IAAIJ,YAAYS,GAAG,CAACF,QAAQR,SAASK,IAAI,CAAC,CAAC,2BAA2B,EAAEG,MAAM,EAAE,CAAC;QACjFP,YAAYU,GAAG,CAACH;QAEhB,IAAI,CAACC,UAAUT,SAASK,IAAI,CAAC,CAAC,WAAW,EAAEG,MAAM,yBAAyB,CAAC;aACtE,IAAIrB,0BAA0BsB,WACjCT,SAASK,IAAI,CAAC,CAAC,WAAW,EAAEG,MAAM,oCAAoC,CAAC;IAC3E;IAEA,OAAOR;AACT;AAQA,MAAMY,mBAAmB;AACzB,MAAMC,YAAY,IAAIC;AAEtB,SAASC,kBAAkBC,QAAgB,EAAEC,KAAe;IAC1D,MAAM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TvC,UAAU;YAAC,CAAC,mBAAmB,EAAEwC,WAAWE,IAAI,CAACG,SAAS,CAAC,EAAE,CAAC;SAAC;IACjE;IAEF,MAAM1C,UAAUjB,KAAK8D,OAAO,CAACC,QAAQC,GAAG,IAAInD,QAAQI,WAAW;IAC/D,MAAMgD,WAAWjE,KAAK8D,OAAO,CAAC7C,SAASG,KAAKpB,IAAI;IAChD,MAAM8B,WAAW9B,KAAK8D,OAAO,CAACG,UAAU,GAAGX,WAAWE,IAAI,CAACU,QAAQ,CAAC,IAAI,CAAC;IAEzE,IAAI,CAAC7D,SAAS4D,UAAUnC,WACtB,OAAO;QACL8B,SAASN,WAAWE,IAAI,CAACK,GAAG;QAC5BR,OAAO,EAAE;QACTvC,UAAU;YAAC,CAAC,oBAAoB,EAAEoC,IAAI,+CAA+C,CAAC;SAAC;IACzF;IAEF,MAAMnB,QAAQc,SAASf;IAEvB,IAAI,CAACC,OACH,OAAO;QACL6B,SAASN,WAAWE,IAAI,CAACK,GAAG;QAC5BR,OAAO,EAAE;QACTvC,UAAU;YAAC,CAAC,cAAc,EAAEwC,WAAWE,IAAI,CAACK,GAAG,CAAC,EAAE,CAAC;SAAC;IACtD;IAEF,MAAMzB,MAAMP,kBAAkBC,UAAUC;IAExC,IAAI,CAACK,KACH,OAAO;QACLwB,SAASN,WAAWE,IAAI,CAACK,GAAG;QAC5BR,OAAO,EAAE;QACTvC,UAAU;YAAC,CAAC,MAAM,EAAEwC,WAAWE,IAAI,CAACK,GAAG,CAAC,oCAAoC,CAAC;SAAC;IAChF;IAEF,OAAO;QACLD,SAASN,WAAWE,IAAI,CAACK,GAAG;QAC5BR,OAAO;YAAClD,wBAAwBiC,KAAKe,WAAWC;SAAO;QACvDtC,UAAU,EAAE;IACd;AACF"}
|
|
@@ -4,8 +4,18 @@ import type { Element } from 'hast';
|
|
|
4
4
|
* element, or `undefined` when the file has none.
|
|
5
5
|
*/
|
|
6
6
|
export declare function parseAndSanitizeSvg(content: string): Element | undefined;
|
|
7
|
+
/** How a palette paints an icon (all values are validated CSS colours). */
|
|
8
|
+
export type SvgPaint = {
|
|
9
|
+
/** Palette name, emitted as `data-pmd-palette`. */
|
|
10
|
+
name: string;
|
|
11
|
+
primary?: string;
|
|
12
|
+
secondary?: string;
|
|
13
|
+
secondaryOpacity?: number;
|
|
14
|
+
};
|
|
7
15
|
/**
|
|
8
16
|
* Returns a deep copy of a sanitized icon with the runtime class names and
|
|
9
|
-
* accessibility attributes the renderer adds to every inline icon.
|
|
17
|
+
* accessibility attributes the renderer adds to every inline icon. With a
|
|
18
|
+
* `paint`, the copy is recoloured with its palette (see `applyPaint`); without
|
|
19
|
+
* one it is left exactly as the icon file draws it.
|
|
10
20
|
*/
|
|
11
|
-
export declare function instantiateSanitizedSvg(svg: Element, className: string): Element;
|
|
21
|
+
export declare function instantiateSanitizedSvg(svg: Element, className: string, paint?: SvgPaint): Element;
|