payload-markdown 1.8.0 → 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.
Files changed (140) hide show
  1. package/README.md +16 -0
  2. package/dist/agent/access.d.ts +1 -1
  3. package/dist/agent/access.js.map +1 -1
  4. package/dist/agent/guide.d.ts +3 -0
  5. package/dist/agent/guide.js +28 -2
  6. package/dist/agent/guide.js.map +1 -1
  7. package/dist/agent/palettes.d.ts +55 -0
  8. package/dist/agent/palettes.js +194 -0
  9. package/dist/agent/palettes.js.map +1 -0
  10. package/dist/agent/skill.d.ts +2 -2
  11. package/dist/agent/skill.js +2 -2
  12. package/dist/agent/skill.js.map +1 -1
  13. package/dist/agent/validate.d.ts +1 -1
  14. package/dist/agent/validate.js +3 -0
  15. package/dist/agent/validate.js.map +1 -1
  16. package/dist/appearance/PaletteRowLabel.client.d.ts +2 -0
  17. package/dist/appearance/PaletteRowLabel.client.js +70 -0
  18. package/dist/appearance/PaletteRowLabel.client.js.map +1 -0
  19. package/dist/appearance/config.d.ts +8 -0
  20. package/dist/appearance/config.js +172 -0
  21. package/dist/appearance/config.js.map +1 -0
  22. package/dist/appearance/options.d.ts +11 -0
  23. package/dist/appearance/options.js +15 -0
  24. package/dist/appearance/options.js.map +1 -0
  25. package/dist/appearance/runtime.d.ts +25 -0
  26. package/dist/appearance/runtime.js +126 -0
  27. package/dist/appearance/runtime.js.map +1 -0
  28. package/dist/components/MarkdownRenderer/Component.js +4 -0
  29. package/dist/components/MarkdownRenderer/Component.js.map +1 -1
  30. package/dist/core/plugins/directiveButton.d.ts +1 -1
  31. package/dist/core/plugins/directiveButton.js +27 -10
  32. package/dist/core/plugins/directiveButton.js.map +1 -1
  33. package/dist/core/plugins/rehypeResolveIcons.js +10 -1
  34. package/dist/core/plugins/rehypeResolveIcons.js.map +1 -1
  35. package/dist/core/plugins/remarkValidatePalettes.d.ts +9 -0
  36. package/dist/core/plugins/remarkValidatePalettes.js +51 -0
  37. package/dist/core/plugins/remarkValidatePalettes.js.map +1 -0
  38. package/dist/core/renderMarkdown.js +13 -1
  39. package/dist/core/renderMarkdown.js.map +1 -1
  40. package/dist/directive-spec.json +60 -0
  41. package/dist/directives/definitions/button.d.ts +1 -1
  42. package/dist/directives/definitions/button.js +9 -2
  43. package/dist/directives/definitions/button.js.map +1 -1
  44. package/dist/directives/definitions/callout.js +9 -2
  45. package/dist/directives/definitions/callout.js.map +1 -1
  46. package/dist/directives/definitions/card.d.ts +0 -2
  47. package/dist/directives/definitions/card.js +13 -8
  48. package/dist/directives/definitions/card.js.map +1 -1
  49. package/dist/directives/definitions/cards.js +9 -0
  50. package/dist/directives/definitions/cards.js.map +1 -1
  51. package/dist/directives/definitions/details.js +4 -0
  52. package/dist/directives/definitions/details.js.map +1 -1
  53. package/dist/directives/definitions/section.js +4 -0
  54. package/dist/directives/definitions/section.js.map +1 -1
  55. package/dist/directives/definitions/steps.js +4 -0
  56. package/dist/directives/definitions/steps.js.map +1 -1
  57. package/dist/directives/definitions/tabs.js +4 -0
  58. package/dist/directives/definitions/tabs.js.map +1 -1
  59. package/dist/directives/definitions/toc.js +1 -1
  60. package/dist/directives/definitions/toc.js.map +1 -1
  61. package/dist/directives/diagnostics.d.ts +5 -0
  62. package/dist/directives/diagnostics.js +26 -10
  63. package/dist/directives/diagnostics.js.map +1 -1
  64. package/dist/directives/iconPlaceholder.d.ts +9 -3
  65. package/dist/directives/iconPlaceholder.js +8 -1
  66. package/dist/directives/iconPlaceholder.js.map +1 -1
  67. package/dist/directives/palette.d.ts +23 -0
  68. package/dist/directives/palette.js +40 -0
  69. package/dist/directives/palette.js.map +1 -0
  70. package/dist/directives/spec.d.ts +6 -2
  71. package/dist/directives/spec.js +5 -0
  72. package/dist/directives/spec.js.map +1 -1
  73. package/dist/editor/directiveConfig.d.ts +15 -1
  74. package/dist/editor/directiveConfig.js +21 -1
  75. package/dist/editor/directiveConfig.js.map +1 -1
  76. package/dist/editor/directives/completions.d.ts +4 -2
  77. package/dist/editor/directives/completions.js +22 -3
  78. package/dist/editor/directives/completions.js.map +1 -1
  79. package/dist/editor/directives/diagnostics.d.ts +2 -2
  80. package/dist/editor/directives/diagnostics.js +10 -3
  81. package/dist/editor/directives/diagnostics.js.map +1 -1
  82. package/dist/exports/client.d.ts +4 -1
  83. package/dist/exports/client.js +5 -2
  84. package/dist/exports/client.js.map +1 -1
  85. package/dist/field/MarkdownField/Component.js +54 -3
  86. package/dist/field/MarkdownField/Component.js.map +1 -1
  87. package/dist/icons/entries.d.ts +22 -0
  88. package/dist/icons/entries.js +50 -0
  89. package/dist/icons/entries.js.map +1 -0
  90. package/dist/icons/resolve.d.ts +2 -1
  91. package/dist/icons/resolve.js +2 -2
  92. package/dist/icons/resolve.js.map +1 -1
  93. package/dist/icons/sanitizeSvg.d.ts +12 -2
  94. package/dist/icons/sanitizeSvg.js +104 -3
  95. package/dist/icons/sanitizeSvg.js.map +1 -1
  96. package/dist/index.d.ts +11 -4
  97. package/dist/index.js +34 -3
  98. package/dist/index.js.map +1 -1
  99. package/dist/mcp/index.d.ts +2 -2
  100. package/dist/mcp/index.js +65 -4
  101. package/dist/mcp/index.js.map +1 -1
  102. package/dist/palettes/colors.d.ts +21 -0
  103. package/dist/palettes/colors.js +43 -0
  104. package/dist/palettes/colors.js.map +1 -0
  105. package/dist/palettes/contrast.d.ts +7 -0
  106. package/dist/palettes/contrast.js +63 -0
  107. package/dist/palettes/contrast.js.map +1 -0
  108. package/dist/palettes/defaults.d.ts +8 -0
  109. package/dist/palettes/defaults.js +275 -0
  110. package/dist/palettes/defaults.js.map +1 -0
  111. package/dist/palettes/diagnostics.d.ts +10 -0
  112. package/dist/palettes/diagnostics.js +38 -0
  113. package/dist/palettes/diagnostics.js.map +1 -0
  114. package/dist/palettes/index.d.ts +61 -0
  115. package/dist/palettes/index.js +246 -0
  116. package/dist/palettes/index.js.map +1 -0
  117. package/dist/render/renderMarkdown.d.ts +3 -1
  118. package/dist/render/renderMarkdown.js +9 -1
  119. package/dist/render/renderMarkdown.js.map +1 -1
  120. package/dist/runtime/index.d.ts +12 -1
  121. package/dist/runtime/index.js +21 -2
  122. package/dist/runtime/index.js.map +1 -1
  123. package/dist/types/core.d.ts +43 -0
  124. package/dist/types/core.js.map +1 -1
  125. package/dist/types.d.ts +46 -2
  126. package/dist/types.js.map +1 -1
  127. package/dist/version.d.ts +1 -1
  128. package/dist/version.js +1 -1
  129. package/dist/version.js.map +1 -1
  130. package/package.json +1 -1
  131. package/skills/payload-markdown/claude/SKILL.md +1 -0
  132. package/skills/payload-markdown/claude/reference/directive-spec.json +60 -0
  133. package/skills/payload-markdown/claude/reference/mcp-content-workflow.md +7 -0
  134. package/skills/payload-markdown/claude/reference/payload-markdown-directives.md +22 -2
  135. package/skills/payload-markdown/claude/skill.json +2 -2
  136. package/skills/payload-markdown/codex/SKILL.md +1 -0
  137. package/skills/payload-markdown/codex/reference/directive-spec.json +60 -0
  138. package/skills/payload-markdown/codex/reference/mcp-content-workflow.md +7 -0
  139. package/skills/payload-markdown/codex/reference/payload-markdown-directives.md +22 -2
  140. package/skills/payload-markdown/codex/skill.json +2 -2
@@ -0,0 +1,23 @@
1
+ import type { Element } from 'hast';
2
+ import type { ContainerDirective } from 'mdast-util-directive';
3
+ import type { IconEntry } from '../icons/entries.js';
4
+ import type { MarkdownRenderConfig } from '../types/core.js';
5
+ /** Attributes every palette-aware directive accepts. */
6
+ export declare const PALETTE_ATTRIBUTES: readonly ["iconPalette", "palette"];
7
+ /** Render properties carrying `palette` / `iconPalette` from mdast to hast. */
8
+ export declare function getPaletteRenderProperties(node: ContainerDirective): {
9
+ dataIconPalette: string | undefined;
10
+ dataPalette: string | undefined;
11
+ };
12
+ /**
13
+ * The palette an icon of this directive is painted with: its own entry, then
14
+ * the directive's `iconPalette`, then the directive's `palette`.
15
+ */
16
+ export declare function resolveIconPaletteName(node: Element, entry?: IconEntry): string | undefined;
17
+ /**
18
+ * Scopes the directive's palette to it: the palette colours become the public
19
+ * `--pmd-*` tokens (or button tokens) on the directive element, which the
20
+ * default themes read first. Unknown palettes were reported during validation
21
+ * and leave the directive unchanged.
22
+ */
23
+ export declare function applyDirectivePalette(node: Element, config: MarkdownRenderConfig, kind?: 'button' | 'surface'): void;
@@ -0,0 +1,40 @@
1
+ import { buttonPaletteStyle, directivePaletteStyle, getPaletteRegistry } from '../palettes/index.js';
2
+ /** Attributes every palette-aware directive accepts. */ export const PALETTE_ATTRIBUTES = [
3
+ 'iconPalette',
4
+ 'palette'
5
+ ];
6
+ function getAttribute(node, name) {
7
+ const value = node.attributes?.[name];
8
+ return typeof value === 'string' && value.trim() ? value.trim() : undefined;
9
+ }
10
+ /** Render properties carrying `palette` / `iconPalette` from mdast to hast. */ export function getPaletteRenderProperties(node) {
11
+ return {
12
+ dataIconPalette: getAttribute(node, 'iconPalette'),
13
+ dataPalette: getAttribute(node, 'palette')
14
+ };
15
+ }
16
+ function readProperty(node, name) {
17
+ const value = node.properties[name];
18
+ return typeof value === 'string' && value ? value : undefined;
19
+ }
20
+ /**
21
+ * The palette an icon of this directive is painted with: its own entry, then
22
+ * the directive's `iconPalette`, then the directive's `palette`.
23
+ */ export function resolveIconPaletteName(node, entry) {
24
+ return entry?.palette ?? readProperty(node, 'dataIconPalette') ?? readProperty(node, 'dataPalette');
25
+ }
26
+ /**
27
+ * Scopes the directive's palette to it: the palette colours become the public
28
+ * `--pmd-*` tokens (or button tokens) on the directive element, which the
29
+ * default themes read first. Unknown palettes were reported during validation
30
+ * and leave the directive unchanged.
31
+ */ export function applyDirectivePalette(node, config, kind = 'surface') {
32
+ const name = readProperty(node, 'dataPalette');
33
+ if (!name) return;
34
+ const palette = getPaletteRegistry(config.palettes).get(name);
35
+ if (!palette) return;
36
+ const style = kind === 'button' ? buttonPaletteStyle(palette) : directivePaletteStyle(palette);
37
+ if (style) node.properties.style = style;
38
+ }
39
+
40
+ //# sourceMappingURL=palette.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/directives/palette.ts"],"sourcesContent":["import type { Element } from 'hast'\nimport type { ContainerDirective } from 'mdast-util-directive'\n\nimport type { IconEntry } from '../icons/entries.js'\nimport type { MarkdownRenderConfig } from '../types/core.js'\n\nimport { buttonPaletteStyle, directivePaletteStyle, getPaletteRegistry } from '../palettes/index.js'\n\n/** Attributes every palette-aware directive accepts. */\nexport const PALETTE_ATTRIBUTES = ['iconPalette', 'palette'] as const\n\nfunction getAttribute(node: ContainerDirective, name: string): string | undefined {\n const value = node.attributes?.[name]\n\n return typeof value === 'string' && value.trim() ? value.trim() : undefined\n}\n\n/** Render properties carrying `palette` / `iconPalette` from mdast to hast. */\nexport function getPaletteRenderProperties(node: ContainerDirective) {\n return {\n dataIconPalette: getAttribute(node, 'iconPalette'),\n dataPalette: getAttribute(node, 'palette'),\n }\n}\n\nfunction readProperty(node: Element, name: 'dataIconPalette' | 'dataPalette'): string | undefined {\n const value = node.properties[name]\n\n return typeof value === 'string' && value ? value : undefined\n}\n\n/**\n * The palette an icon of this directive is painted with: its own entry, then\n * the directive's `iconPalette`, then the directive's `palette`.\n */\nexport function resolveIconPaletteName(node: Element, entry?: IconEntry): string | undefined {\n return entry?.palette ?? readProperty(node, 'dataIconPalette') ?? readProperty(node, 'dataPalette')\n}\n\n/**\n * Scopes the directive's palette to it: the palette colours become the public\n * `--pmd-*` tokens (or button tokens) on the directive element, which the\n * default themes read first. Unknown palettes were reported during validation\n * and leave the directive unchanged.\n */\nexport function applyDirectivePalette(\n node: Element,\n config: MarkdownRenderConfig,\n kind: 'button' | 'surface' = 'surface',\n): void {\n const name = readProperty(node, 'dataPalette')\n if (!name) return\n\n const palette = getPaletteRegistry(config.palettes).get(name)\n if (!palette) return\n\n const style = kind === 'button' ? buttonPaletteStyle(palette) : directivePaletteStyle(palette)\n if (style) node.properties.style = style\n}\n"],"names":["buttonPaletteStyle","directivePaletteStyle","getPaletteRegistry","PALETTE_ATTRIBUTES","getAttribute","node","name","value","attributes","trim","undefined","getPaletteRenderProperties","dataIconPalette","dataPalette","readProperty","properties","resolveIconPaletteName","entry","palette","applyDirectivePalette","config","kind","palettes","get","style"],"mappings":"AAMA,SAASA,kBAAkB,EAAEC,qBAAqB,EAAEC,kBAAkB,QAAQ,uBAAsB;AAEpG,sDAAsD,GACtD,OAAO,MAAMC,qBAAqB;IAAC;IAAe;CAAU,CAAS;AAErE,SAASC,aAAaC,IAAwB,EAAEC,IAAY;IAC1D,MAAMC,QAAQF,KAAKG,UAAU,EAAE,CAACF,KAAK;IAErC,OAAO,OAAOC,UAAU,YAAYA,MAAME,IAAI,KAAKF,MAAME,IAAI,KAAKC;AACpE;AAEA,6EAA6E,GAC7E,OAAO,SAASC,2BAA2BN,IAAwB;IACjE,OAAO;QACLO,iBAAiBR,aAAaC,MAAM;QACpCQ,aAAaT,aAAaC,MAAM;IAClC;AACF;AAEA,SAASS,aAAaT,IAAa,EAAEC,IAAuC;IAC1E,MAAMC,QAAQF,KAAKU,UAAU,CAACT,KAAK;IAEnC,OAAO,OAAOC,UAAU,YAAYA,QAAQA,QAAQG;AACtD;AAEA;;;CAGC,GACD,OAAO,SAASM,uBAAuBX,IAAa,EAAEY,KAAiB;IACrE,OAAOA,OAAOC,WAAWJ,aAAaT,MAAM,sBAAsBS,aAAaT,MAAM;AACvF;AAEA;;;;;CAKC,GACD,OAAO,SAASc,sBACdd,IAAa,EACbe,MAA4B,EAC5BC,OAA6B,SAAS;IAEtC,MAAMf,OAAOQ,aAAaT,MAAM;IAChC,IAAI,CAACC,MAAM;IAEX,MAAMY,UAAUhB,mBAAmBkB,OAAOE,QAAQ,EAAEC,GAAG,CAACjB;IACxD,IAAI,CAACY,SAAS;IAEd,MAAMM,QAAQH,SAAS,WAAWrB,mBAAmBkB,WAAWjB,sBAAsBiB;IACtF,IAAIM,OAAOnB,KAAKU,UAAU,CAACS,KAAK,GAAGA;AACrC"}
@@ -7,8 +7,12 @@ export declare const DIRECTIVE_SPEC_VERSION = 1;
7
7
  export type DirectiveAttributeType = 'boolean' | 'enum' | 'number' | 'string' | 'url';
8
8
  export type DirectiveSpecAttribute = {
9
9
  default?: string;
10
- /** Value format hint for `string` attributes (`icon`: an `@pack/name` icon ref). */
11
- format?: 'icon';
10
+ /**
11
+ * Value format hint for `string` attributes. `icon`: one `@pack/name` icon
12
+ * ref, or a comma-separated list where each entry may add `palette=<name>`.
13
+ * `palette`: a palette name (built-in, configured, or managed in the admin).
14
+ */
15
+ format?: 'icon' | 'palette';
12
16
  max?: number;
13
17
  min?: number;
14
18
  name: string;
@@ -77,6 +77,11 @@ function describeAttribute(definition, name) {
77
77
  type: 'string',
78
78
  format: 'icon'
79
79
  };
80
+ if (name === 'palette' || name === 'iconPalette') return {
81
+ ...base,
82
+ type: 'string',
83
+ format: 'palette'
84
+ };
80
85
  return {
81
86
  ...base,
82
87
  type: 'string'
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/directives/spec.ts"],"sourcesContent":["import type { DirectiveThemeGroupName } from './themes.js'\nimport type { LayoutDirectiveDefinition } from './types.js'\n\nimport { CALLOUT_VARIANTS } from './definitions/callout.js'\nimport { slugTabValue } from './definitions/tab.js'\nimport { slugifyHeading } from './headingAnchors.js'\nimport { DIRECTIVE_LABEL_ATTRIBUTES, layoutDirectiveRegistry } from './registry.js'\nimport {\n SHIELDS_BADGE_ORIGIN,\n SHIELDS_BADGE_QUERY_ATTRIBUTES,\n SHIELDS_BADGE_REQUIRED_ATTRIBUTES,\n SHIELDS_BADGE_TARGETS,\n} from './shields.js'\nimport { DEFAULT_DIRECTIVE_THEMES, getDirectiveFallbackThemeName } from './themes.js'\n\n/**\n * Version of the spec's JSON shape. Bump it on incompatible shape changes;\n * adding directives, attributes or values does not change it.\n */\nexport const DIRECTIVE_SPEC_VERSION = 1\n\nexport type DirectiveAttributeType = 'boolean' | 'enum' | 'number' | 'string' | 'url'\n\nexport type DirectiveSpecAttribute = {\n default?: string\n /** Value format hint for `string` attributes (`icon`: an `@pack/name` icon ref). */\n format?: 'icon'\n max?: number\n min?: number\n name: string\n /** Theme group whose names are valid (built-in themes plus configured ones). */\n themeGroup?: DirectiveThemeGroupName\n type: DirectiveAttributeType\n /** Allowed values of `enum` attributes; the literals of `boolean` attributes. */\n values?: string[]\n}\n\nexport type DirectiveSpecDirective = {\n attributes: DirectiveSpecAttribute[]\n /** Close-label text the editor shows after a generic `:::` closer. */\n closeLabel?: string\n /** Markers that close this directive; empty for leaf directives. */\n closeMarkers: string[]\n description?: string\n kind: 'container' | 'leaf'\n /** Attribute that `[label]` stands for, if any. */\n labelAttribute?: string\n name: string\n /** Opening marker: `:::name` (container) or `::name` (leaf). */\n open: string\n supportsAttributes: boolean\n}\n\nexport type DirectiveSpec = {\n badges: {\n intervals: string[]\n origin: string\n queryAttributes: string[]\n requiredAttributes: Record<string, string[]>\n styles: string[]\n targets: Record<string, string[]>\n types: string[]\n }\n closeMarkers: Array<{ closes: 'grid' | 'innermost' | 'section'; marker: string }>\n constraints: string[]\n directives: DirectiveSpecDirective[]\n headings: { examples: Array<[string, string]>; slug: string[] }\n package: string\n specVersion: number\n tabs: { examples: Array<{ index: number; raw: string; value: string }>; value: string[] }\n themes: Record<string, { builtIn: string[]; fallback: string }>\n}\n\nconst URL_ATTRIBUTES = new Set(['href', 'src'])\nconst BOOLEAN_ATTRIBUTES = new Set(['disabled', 'open'])\nconst NUMBER_ATTRIBUTES: Record<string, { max?: number; min?: number }> = {\n cacheSeconds: { min: 0 },\n depth: { max: 6, min: 1 },\n}\n/** Enumerations the definitions validate in code rather than through `attributeValues`. */\nconst EXTRA_ENUMS: Record<string, Record<string, readonly string[]>> = {\n callout: { variant: CALLOUT_VARIANTS },\n}\n\nfunction isBooleanValues(values: readonly string[] | undefined): boolean {\n return Boolean(values && values.length === 2 && values.includes('true') && values.includes('false'))\n}\n\nfunction describeAttribute(\n definition: LayoutDirectiveDefinition,\n name: string,\n): DirectiveSpecAttribute {\n const values = definition.attributeValues?.[name] ?? EXTRA_ENUMS[definition.name]?.[name]\n const themeGroup = definition.themeAttributes?.[name]\n const defaultValue = definition.defaultAttributes?.[name]\n const base = {\n name,\n ...(defaultValue !== undefined ? { default: defaultValue } : {}),\n }\n\n if (themeGroup) return { ...base, type: 'string', themeGroup }\n if (URL_ATTRIBUTES.has(name)) return { ...base, type: 'url' }\n if (BOOLEAN_ATTRIBUTES.has(name) || isBooleanValues(values))\n return { ...base, type: 'boolean', values: ['true', 'false'] }\n if (NUMBER_ATTRIBUTES[name]) return { ...base, ...NUMBER_ATTRIBUTES[name], type: 'number' }\n if (values) return { ...base, type: 'enum', values: [...values] }\n if (name === 'icon') return { ...base, type: 'string', format: 'icon' }\n\n return { ...base, type: 'string' }\n}\n\nfunction getCloseMarkers(definition: LayoutDirectiveDefinition): string[] {\n if (!definition.openMarker) return []\n if (layoutDirectiveRegistry.isGridName(definition.name)) return [':::', ':::endcol']\n if (definition.name === 'section') return [':::', ':::end', ':::endsection']\n\n return [':::']\n}\n\nfunction describeDirective(definition: LayoutDirectiveDefinition): DirectiveSpecDirective {\n const container = Boolean(definition.openMarker)\n const labelAttribute = DIRECTIVE_LABEL_ATTRIBUTES.get(definition.name)\n\n return {\n name: definition.name,\n attributes: [...(definition.allowedAttributes ?? [])]\n .sort()\n .map((name) => describeAttribute(definition, name)),\n ...(container ? { closeLabel: layoutDirectiveRegistry.getCloseLabel(definition.name) } : {}),\n closeMarkers: getCloseMarkers(definition),\n ...(definition.description ? { description: definition.description } : {}),\n kind: container ? 'container' : 'leaf',\n ...(labelAttribute ? { labelAttribute } : {}),\n open: definition.openMarker ?? `::${definition.name}`,\n supportsAttributes: Boolean(definition.supportsAttributes),\n }\n}\n\nconst CLOSES = {\n close: 'innermost',\n closeGrid: 'grid',\n closeSection: 'section',\n} as const\n\nconst CONSTRAINTS = [\n 'Directive markers are recognised only at the start of a line of a top-level paragraph. Markers inside lists, blockquotes, tables or footnotes render as text and are reported.',\n 'The marker must start the source line as plain text: inline code, emphasis, links, a backslash escape (\\\\:::) or a character reference never open a directive.',\n 'Container syntax is :::name[label]{attributes}; leaf syntax is ::name[label]{attributes} on its own line.',\n 'Attributes are written inside {…} as key=\"value\", key=value, bare boolean keys, #id or .class; the block may span lines until the closing }.',\n 'Unbraced key=value attributes after the marker are accepted for compatibility; any other text after a container marker is reported and the line renders as text.',\n 'Quoted attribute values are literal except for CommonMark backslash escapes and character references, which are decoded.',\n 'A generic ::: closes the innermost open container; :::endcol closes the nearest grid (2col, 3col); :::end and :::endsection close the nearest section.',\n 'Opening a grid inside a section closes a grid that is already open in that section.',\n 'Inside a grid, a heading shallower than the heading before the grid closes the grid; headings one level deeper than that start a new cell.',\n 'Containers still open at the end of the document are closed automatically and reported.',\n 'Unknown attributes, unknown theme names and invalid enum values are reported; the renderer falls back to defaults.',\n 'Directive href attributes accept relative URLs and http, https, irc, ircs, mailto and xmpp URLs; other links are removed and reported.',\n]\n\nconst TAB_EXAMPLES: Array<[string, number]> = [\n ['Install', 0],\n ['npmInstall', 1],\n ['Hello, World!', 2],\n ['日本', 3],\n]\n\nconst HEADING_EXAMPLES = ['Getting Started', \"What's New?\", '日本語', 'API v2.0']\n\n/**\n * The directive language as data: names, kinds, markers, attributes and\n * their types, theme groups, badge resolver tables, tab-value and heading\n * slug semantics, and parser constraints. Generated from the registry; the\n * build writes it to `dist/directive-spec.json` and the skill reference\n * copies are checked against it.\n */\nexport function getDirectiveSpec(): DirectiveSpec {\n const badge = layoutDirectiveRegistry.get('badge')\n const themes = Object.fromEntries(\n (Object.keys(DEFAULT_DIRECTIVE_THEMES) as DirectiveThemeGroupName[]).sort().map((group) => [\n group,\n {\n builtIn: DEFAULT_DIRECTIVE_THEMES[group].map((theme) => theme.name),\n fallback: getDirectiveFallbackThemeName(group),\n },\n ]),\n )\n\n return {\n badges: {\n intervals: [...(badge?.attributeValues?.interval ?? [])],\n origin: SHIELDS_BADGE_ORIGIN,\n queryAttributes: [...SHIELDS_BADGE_QUERY_ATTRIBUTES],\n requiredAttributes: Object.fromEntries(\n Object.entries(SHIELDS_BADGE_REQUIRED_ATTRIBUTES).map(([type, names]) => [type, [...names]]),\n ),\n styles: [...(badge?.attributeValues?.style ?? [])],\n targets: Object.fromEntries(\n Object.entries(SHIELDS_BADGE_TARGETS).map(([type, targets]) => [type, [...targets]]),\n ),\n types: [...(badge?.attributeValues?.type ?? [])],\n },\n closeMarkers: layoutDirectiveRegistry.closeMarkers.map(({ action, marker }) => ({\n closes: CLOSES[action as keyof typeof CLOSES],\n marker,\n })),\n constraints: CONSTRAINTS,\n directives: layoutDirectiveRegistry.all.map((definition) => describeDirective(definition)),\n headings: {\n slug: [\n 'Lowercase; remove quotes; replace every run of characters other than a-z and 0-9 with \"-\"; trim \"-\"; an empty result becomes \"section\".',\n 'Repeated slugs get -1, -2, … suffixes, skipping ids already emitted in the document.',\n 'Only top-level headings and headings directly inside container directives get ids.',\n ],\n examples: HEADING_EXAMPLES.map((text) => [text, slugifyHeading(text)]),\n },\n package: '@valkyrianlabs/payload-markdown',\n specVersion: DIRECTIVE_SPEC_VERSION,\n tabs: {\n examples: TAB_EXAMPLES.map(([raw, index]) => ({ index, raw, value: slugTabValue(raw, index) })),\n value: [\n 'A tab value comes from the value attribute, else the [label], else the label attribute, else tab-N (N is the 1-based tab position).',\n 'It is slugged: split camelCase with \"-\", lowercase, replace runs of characters other than a-z and 0-9 with \"-\", trim \"-\". An empty slug becomes tab-N.',\n 'Repeated values in one tabs block get -1, -2, … suffixes.',\n 'tabs default=\"…\" matches a tab value (after slugging) first, then a raw value or label; otherwise the first enabled tab is active.',\n ],\n },\n themes,\n }\n}\n"],"names":["CALLOUT_VARIANTS","slugTabValue","slugifyHeading","DIRECTIVE_LABEL_ATTRIBUTES","layoutDirectiveRegistry","SHIELDS_BADGE_ORIGIN","SHIELDS_BADGE_QUERY_ATTRIBUTES","SHIELDS_BADGE_REQUIRED_ATTRIBUTES","SHIELDS_BADGE_TARGETS","DEFAULT_DIRECTIVE_THEMES","getDirectiveFallbackThemeName","DIRECTIVE_SPEC_VERSION","URL_ATTRIBUTES","Set","BOOLEAN_ATTRIBUTES","NUMBER_ATTRIBUTES","cacheSeconds","min","depth","max","EXTRA_ENUMS","callout","variant","isBooleanValues","values","Boolean","length","includes","describeAttribute","definition","name","attributeValues","themeGroup","themeAttributes","defaultValue","defaultAttributes","base","undefined","default","type","has","format","getCloseMarkers","openMarker","isGridName","describeDirective","container","labelAttribute","get","attributes","allowedAttributes","sort","map","closeLabel","getCloseLabel","closeMarkers","description","kind","open","supportsAttributes","CLOSES","close","closeGrid","closeSection","CONSTRAINTS","TAB_EXAMPLES","HEADING_EXAMPLES","getDirectiveSpec","badge","themes","Object","fromEntries","keys","group","builtIn","theme","fallback","badges","intervals","interval","origin","queryAttributes","requiredAttributes","entries","names","styles","style","targets","types","action","marker","closes","constraints","directives","all","headings","slug","examples","text","package","specVersion","tabs","raw","index","value"],"mappings":"AAGA,SAASA,gBAAgB,QAAQ,2BAA0B;AAC3D,SAASC,YAAY,QAAQ,uBAAsB;AACnD,SAASC,cAAc,QAAQ,sBAAqB;AACpD,SAASC,0BAA0B,EAAEC,uBAAuB,QAAQ,gBAAe;AACnF,SACEC,oBAAoB,EACpBC,8BAA8B,EAC9BC,iCAAiC,EACjCC,qBAAqB,QAChB,eAAc;AACrB,SAASC,wBAAwB,EAAEC,6BAA6B,QAAQ,cAAa;AAErF;;;CAGC,GACD,OAAO,MAAMC,yBAAyB,EAAC;AAsDvC,MAAMC,iBAAiB,IAAIC,IAAI;IAAC;IAAQ;CAAM;AAC9C,MAAMC,qBAAqB,IAAID,IAAI;IAAC;IAAY;CAAO;AACvD,MAAME,oBAAoE;IACxEC,cAAc;QAAEC,KAAK;IAAE;IACvBC,OAAO;QAAEC,KAAK;QAAGF,KAAK;IAAE;AAC1B;AACA,yFAAyF,GACzF,MAAMG,cAAiE;IACrEC,SAAS;QAAEC,SAAStB;IAAiB;AACvC;AAEA,SAASuB,gBAAgBC,MAAqC;IAC5D,OAAOC,QAAQD,UAAUA,OAAOE,MAAM,KAAK,KAAK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AM;YACJJ,UAAUhC,aAAab,GAAG,CAAC,CAAC,CAACkD,KAAKC,MAAM,GAAM,CAAA;oBAAEA;oBAAOD;oBAAKE,OAAOvG,aAAaqG,KAAKC;gBAAO,CAAA;YAC5FC,OAAO;gBACL;gBACA;gBACA;gBACA;aACD;QACH;QACAnC;IACF;AACF"}
1
+ {"version":3,"sources":["../../src/directives/spec.ts"],"sourcesContent":["import type { DirectiveThemeGroupName } from './themes.js'\nimport type { LayoutDirectiveDefinition } from './types.js'\n\nimport { CALLOUT_VARIANTS } from './definitions/callout.js'\nimport { slugTabValue } from './definitions/tab.js'\nimport { slugifyHeading } from './headingAnchors.js'\nimport { DIRECTIVE_LABEL_ATTRIBUTES, layoutDirectiveRegistry } from './registry.js'\nimport {\n SHIELDS_BADGE_ORIGIN,\n SHIELDS_BADGE_QUERY_ATTRIBUTES,\n SHIELDS_BADGE_REQUIRED_ATTRIBUTES,\n SHIELDS_BADGE_TARGETS,\n} from './shields.js'\nimport { DEFAULT_DIRECTIVE_THEMES, getDirectiveFallbackThemeName } from './themes.js'\n\n/**\n * Version of the spec's JSON shape. Bump it on incompatible shape changes;\n * adding directives, attributes or values does not change it.\n */\nexport const DIRECTIVE_SPEC_VERSION = 1\n\nexport type DirectiveAttributeType = 'boolean' | 'enum' | 'number' | 'string' | 'url'\n\nexport type DirectiveSpecAttribute = {\n default?: string\n /**\n * Value format hint for `string` attributes. `icon`: one `@pack/name` icon\n * ref, or a comma-separated list where each entry may add `palette=<name>`.\n * `palette`: a palette name (built-in, configured, or managed in the admin).\n */\n format?: 'icon' | 'palette'\n max?: number\n min?: number\n name: string\n /** Theme group whose names are valid (built-in themes plus configured ones). */\n themeGroup?: DirectiveThemeGroupName\n type: DirectiveAttributeType\n /** Allowed values of `enum` attributes; the literals of `boolean` attributes. */\n values?: string[]\n}\n\nexport type DirectiveSpecDirective = {\n attributes: DirectiveSpecAttribute[]\n /** Close-label text the editor shows after a generic `:::` closer. */\n closeLabel?: string\n /** Markers that close this directive; empty for leaf directives. */\n closeMarkers: string[]\n description?: string\n kind: 'container' | 'leaf'\n /** Attribute that `[label]` stands for, if any. */\n labelAttribute?: string\n name: string\n /** Opening marker: `:::name` (container) or `::name` (leaf). */\n open: string\n supportsAttributes: boolean\n}\n\nexport type DirectiveSpec = {\n badges: {\n intervals: string[]\n origin: string\n queryAttributes: string[]\n requiredAttributes: Record<string, string[]>\n styles: string[]\n targets: Record<string, string[]>\n types: string[]\n }\n closeMarkers: Array<{ closes: 'grid' | 'innermost' | 'section'; marker: string }>\n constraints: string[]\n directives: DirectiveSpecDirective[]\n headings: { examples: Array<[string, string]>; slug: string[] }\n package: string\n specVersion: number\n tabs: { examples: Array<{ index: number; raw: string; value: string }>; value: string[] }\n themes: Record<string, { builtIn: string[]; fallback: string }>\n}\n\nconst URL_ATTRIBUTES = new Set(['href', 'src'])\nconst BOOLEAN_ATTRIBUTES = new Set(['disabled', 'open'])\nconst NUMBER_ATTRIBUTES: Record<string, { max?: number; min?: number }> = {\n cacheSeconds: { min: 0 },\n depth: { max: 6, min: 1 },\n}\n/** Enumerations the definitions validate in code rather than through `attributeValues`. */\nconst EXTRA_ENUMS: Record<string, Record<string, readonly string[]>> = {\n callout: { variant: CALLOUT_VARIANTS },\n}\n\nfunction isBooleanValues(values: readonly string[] | undefined): boolean {\n return Boolean(values && values.length === 2 && values.includes('true') && values.includes('false'))\n}\n\nfunction describeAttribute(\n definition: LayoutDirectiveDefinition,\n name: string,\n): DirectiveSpecAttribute {\n const values = definition.attributeValues?.[name] ?? EXTRA_ENUMS[definition.name]?.[name]\n const themeGroup = definition.themeAttributes?.[name]\n const defaultValue = definition.defaultAttributes?.[name]\n const base = {\n name,\n ...(defaultValue !== undefined ? { default: defaultValue } : {}),\n }\n\n if (themeGroup) return { ...base, type: 'string', themeGroup }\n if (URL_ATTRIBUTES.has(name)) return { ...base, type: 'url' }\n if (BOOLEAN_ATTRIBUTES.has(name) || isBooleanValues(values))\n return { ...base, type: 'boolean', values: ['true', 'false'] }\n if (NUMBER_ATTRIBUTES[name]) return { ...base, ...NUMBER_ATTRIBUTES[name], type: 'number' }\n if (values) return { ...base, type: 'enum', values: [...values] }\n if (name === 'icon') return { ...base, type: 'string', format: 'icon' }\n if (name === 'palette' || name === 'iconPalette') return { ...base, type: 'string', format: 'palette' }\n\n return { ...base, type: 'string' }\n}\n\nfunction getCloseMarkers(definition: LayoutDirectiveDefinition): string[] {\n if (!definition.openMarker) return []\n if (layoutDirectiveRegistry.isGridName(definition.name)) return [':::', ':::endcol']\n if (definition.name === 'section') return [':::', ':::end', ':::endsection']\n\n return [':::']\n}\n\nfunction describeDirective(definition: LayoutDirectiveDefinition): DirectiveSpecDirective {\n const container = Boolean(definition.openMarker)\n const labelAttribute = DIRECTIVE_LABEL_ATTRIBUTES.get(definition.name)\n\n return {\n name: definition.name,\n attributes: [...(definition.allowedAttributes ?? [])]\n .sort()\n .map((name) => describeAttribute(definition, name)),\n ...(container ? { closeLabel: layoutDirectiveRegistry.getCloseLabel(definition.name) } : {}),\n closeMarkers: getCloseMarkers(definition),\n ...(definition.description ? { description: definition.description } : {}),\n kind: container ? 'container' : 'leaf',\n ...(labelAttribute ? { labelAttribute } : {}),\n open: definition.openMarker ?? `::${definition.name}`,\n supportsAttributes: Boolean(definition.supportsAttributes),\n }\n}\n\nconst CLOSES = {\n close: 'innermost',\n closeGrid: 'grid',\n closeSection: 'section',\n} as const\n\nconst CONSTRAINTS = [\n 'Directive markers are recognised only at the start of a line of a top-level paragraph. Markers inside lists, blockquotes, tables or footnotes render as text and are reported.',\n 'The marker must start the source line as plain text: inline code, emphasis, links, a backslash escape (\\\\:::) or a character reference never open a directive.',\n 'Container syntax is :::name[label]{attributes}; leaf syntax is ::name[label]{attributes} on its own line.',\n 'Attributes are written inside {…} as key=\"value\", key=value, bare boolean keys, #id or .class; the block may span lines until the closing }.',\n 'Unbraced key=value attributes after the marker are accepted for compatibility; any other text after a container marker is reported and the line renders as text.',\n 'Quoted attribute values are literal except for CommonMark backslash escapes and character references, which are decoded.',\n 'A generic ::: closes the innermost open container; :::endcol closes the nearest grid (2col, 3col); :::end and :::endsection close the nearest section.',\n 'Opening a grid inside a section closes a grid that is already open in that section.',\n 'Inside a grid, a heading shallower than the heading before the grid closes the grid; headings one level deeper than that start a new cell.',\n 'Containers still open at the end of the document are closed automatically and reported.',\n 'Unknown attributes, unknown theme names and invalid enum values are reported; the renderer falls back to defaults.',\n 'Directive href attributes accept relative URLs and http, https, irc, ircs, mailto and xmpp URLs; other links are removed and reported.',\n]\n\nconst TAB_EXAMPLES: Array<[string, number]> = [\n ['Install', 0],\n ['npmInstall', 1],\n ['Hello, World!', 2],\n ['日本', 3],\n]\n\nconst HEADING_EXAMPLES = ['Getting Started', \"What's New?\", '日本語', 'API v2.0']\n\n/**\n * The directive language as data: names, kinds, markers, attributes and\n * their types, theme groups, badge resolver tables, tab-value and heading\n * slug semantics, and parser constraints. Generated from the registry; the\n * build writes it to `dist/directive-spec.json` and the skill reference\n * copies are checked against it.\n */\nexport function getDirectiveSpec(): DirectiveSpec {\n const badge = layoutDirectiveRegistry.get('badge')\n const themes = Object.fromEntries(\n (Object.keys(DEFAULT_DIRECTIVE_THEMES) as DirectiveThemeGroupName[]).sort().map((group) => [\n group,\n {\n builtIn: DEFAULT_DIRECTIVE_THEMES[group].map((theme) => theme.name),\n fallback: getDirectiveFallbackThemeName(group),\n },\n ]),\n )\n\n return {\n badges: {\n intervals: [...(badge?.attributeValues?.interval ?? [])],\n origin: SHIELDS_BADGE_ORIGIN,\n queryAttributes: [...SHIELDS_BADGE_QUERY_ATTRIBUTES],\n requiredAttributes: Object.fromEntries(\n Object.entries(SHIELDS_BADGE_REQUIRED_ATTRIBUTES).map(([type, names]) => [type, [...names]]),\n ),\n styles: [...(badge?.attributeValues?.style ?? [])],\n targets: Object.fromEntries(\n Object.entries(SHIELDS_BADGE_TARGETS).map(([type, targets]) => [type, [...targets]]),\n ),\n types: [...(badge?.attributeValues?.type ?? [])],\n },\n closeMarkers: layoutDirectiveRegistry.closeMarkers.map(({ action, marker }) => ({\n closes: CLOSES[action as keyof typeof CLOSES],\n marker,\n })),\n constraints: CONSTRAINTS,\n directives: layoutDirectiveRegistry.all.map((definition) => describeDirective(definition)),\n headings: {\n slug: [\n 'Lowercase; remove quotes; replace every run of characters other than a-z and 0-9 with \"-\"; trim \"-\"; an empty result becomes \"section\".',\n 'Repeated slugs get -1, -2, … suffixes, skipping ids already emitted in the document.',\n 'Only top-level headings and headings directly inside container directives get ids.',\n ],\n examples: HEADING_EXAMPLES.map((text) => [text, slugifyHeading(text)]),\n },\n package: '@valkyrianlabs/payload-markdown',\n specVersion: DIRECTIVE_SPEC_VERSION,\n tabs: {\n examples: TAB_EXAMPLES.map(([raw, index]) => ({ index, raw, value: slugTabValue(raw, index) })),\n value: [\n 'A tab value comes from the value attribute, else the [label], else the label attribute, else tab-N (N is the 1-based tab position).',\n 'It is slugged: split camelCase with \"-\", lowercase, replace runs of characters other than a-z and 0-9 with \"-\", trim \"-\". An empty slug becomes tab-N.',\n 'Repeated values in one tabs block get -1, -2, … suffixes.',\n 'tabs default=\"…\" matches a tab value (after slugging) first, then a raw value or label; otherwise the first enabled tab is active.',\n ],\n },\n themes,\n }\n}\n"],"names":["CALLOUT_VARIANTS","slugTabValue","slugifyHeading","DIRECTIVE_LABEL_ATTRIBUTES","layoutDirectiveRegistry","SHIELDS_BADGE_ORIGIN","SHIELDS_BADGE_QUERY_ATTRIBUTES","SHIELDS_BADGE_REQUIRED_ATTRIBUTES","SHIELDS_BADGE_TARGETS","DEFAULT_DIRECTIVE_THEMES","getDirectiveFallbackThemeName","DIRECTIVE_SPEC_VERSION","URL_ATTRIBUTES","Set","BOOLEAN_ATTRIBUTES","NUMBER_ATTRIBUTES","cacheSeconds","min","depth","max","EXTRA_ENUMS","callout","variant","isBooleanValues","values","Boolean","length","includes","describeAttribute","definition","name","attributeValues","themeGroup","themeAttributes","defaultValue","defaultAttributes","base","undefined","default","type","has","format","getCloseMarkers","openMarker","isGridName","describeDirective","container","labelAttribute","get","attributes","allowedAttributes","sort","map","closeLabel","getCloseLabel","closeMarkers","description","kind","open","supportsAttributes","CLOSES","close","closeGrid","closeSection","CONSTRAINTS","TAB_EXAMPLES","HEADING_EXAMPLES","getDirectiveSpec","badge","themes","Object","fromEntries","keys","group","builtIn","theme","fallback","badges","intervals","interval","origin","queryAttributes","requiredAttributes","entries","names","styles","style","targets","types","action","marker","closes","constraints","directives","all","headings","slug","examples","text","package","specVersion","tabs","raw","index","value"],"mappings":"AAGA,SAASA,gBAAgB,QAAQ,2BAA0B;AAC3D,SAASC,YAAY,QAAQ,uBAAsB;AACnD,SAASC,cAAc,QAAQ,sBAAqB;AACpD,SAASC,0BAA0B,EAAEC,uBAAuB,QAAQ,gBAAe;AACnF,SACEC,oBAAoB,EACpBC,8BAA8B,EAC9BC,iCAAiC,EACjCC,qBAAqB,QAChB,eAAc;AACrB,SAASC,wBAAwB,EAAEC,6BAA6B,QAAQ,cAAa;AAErF;;;CAGC,GACD,OAAO,MAAMC,yBAAyB,EAAC;AA0DvC,MAAMC,iBAAiB,IAAIC,IAAI;IAAC;IAAQ;CAAM;AAC9C,MAAMC,qBAAqB,IAAID,IAAI;IAAC;IAAY;CAAO;AACvD,MAAME,oBAAoE;IACxEC,cAAc;QAAEC,KAAK;IAAE;IACvBC,OAAO;QAAEC,KAAK;QAAGF,KAAK;IAAE;AAC1B;AACA,yFAAyF,GACzF,MAAMG,cAAiE;IACrEC,SAAS;QAAEC,SAAStB;IAAiB;AACvC;AAEA,SAASuB,gBAAgBC,MAAqC;IAC5D,OAAOC,QAAQD,UAAUA,OAAOE,MAAM,KAAK,KAAKF,OAAOG,QAAQ,CAAC,WAAWH,OAAOG,QAAQ,CAAC;AAC7F;AAEA,SAASC,kBACPC,UAAqC,EACrCC,IAAY;IAEZ,MAAMN,SAASK,WAAWE,eAAe,EAAE,CAACD,KAAK,IAAIV,WAAW,CAACS,WAAWC,IAAI,CAAC,EAAE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AAKE,OAAOvG,aAAaqG,KAAKC;gBAAO,CAAA;YAC5FC,OAAO;gBACL;gBACA;gBACA;gBACA;aACD;QACH;QACAnC;IACF;AACF"}
@@ -7,15 +7,29 @@ export declare const PAYLOAD_MARKDOWN_ADMIN_CUSTOM_KEY = "payloadMarkdown";
7
7
  * the directive theme registry (names only) and the icon pack aliases.
8
8
  */
9
9
  export type MarkdownEditorDirectiveConfig = {
10
+ /** Slug of the "Markdown Appearance" global, whose palettes the editor loads at runtime. */
11
+ appearanceSlug?: string;
12
+ /**
13
+ * Runtime palette names (configured plus admin-managed), set by the field
14
+ * component once loaded; `undefined` while they are still loading.
15
+ */
16
+ getPaletteNames?: () => readonly string[] | undefined;
10
17
  /** Configured icon pack aliases; `undefined` when unknown to the editor. */
11
18
  iconPacks?: string[];
19
+ /** Palette names known when the config was built (built-in and configured). */
20
+ palettes?: string[];
12
21
  themes?: MarkdownDirectiveThemes;
13
22
  };
23
+ /**
24
+ * Palette names the editor can check against, or `undefined` while palettes
25
+ * managed in the admin are still loading (nothing is reported as unknown then).
26
+ */
27
+ export declare function getEditorPaletteNames(config: MarkdownEditorDirectiveConfig): readonly string[] | undefined;
14
28
  /**
15
29
  * Builds the editor config from a resolved render config. Theme classes are
16
30
  * dropped (the editor only needs names), so the result is small and safe to
17
31
  * serialize into the admin client config.
18
32
  */
19
- export declare function createEditorDirectiveConfig(config: MarkdownRenderConfig | undefined): MarkdownEditorDirectiveConfig;
33
+ export declare function createEditorDirectiveConfig(config: MarkdownRenderConfig | undefined, appearanceSlug?: string): MarkdownEditorDirectiveConfig;
20
34
  /** Reads the editor config from `field.admin.custom`, tolerating bad input. */
21
35
  export declare function readEditorDirectiveConfig(custom: unknown): MarkdownEditorDirectiveConfig | undefined;
@@ -1,4 +1,13 @@
1
+ import { getPaletteRegistry } from '../palettes/index.js';
1
2
  /** Key under `field.admin.custom` that carries the editor's directive config. */ export const PAYLOAD_MARKDOWN_ADMIN_CUSTOM_KEY = 'payloadMarkdown';
3
+ /**
4
+ * Palette names the editor can check against, or `undefined` while palettes
5
+ * managed in the admin are still loading (nothing is reported as unknown then).
6
+ */ export function getEditorPaletteNames(config) {
7
+ const loaded = config.getPaletteNames?.();
8
+ if (loaded) return loaded;
9
+ return config.appearanceSlug ? undefined : config.palettes;
10
+ }
2
11
  function stripThemeGroup(group) {
3
12
  const toNameOnly = (theme)=>({
4
13
  name: theme.name,
@@ -16,11 +25,15 @@ function stripThemeGroup(group) {
16
25
  * Builds the editor config from a resolved render config. Theme classes are
17
26
  * dropped (the editor only needs names), so the result is small and safe to
18
27
  * serialize into the admin client config.
19
- */ export function createEditorDirectiveConfig(config) {
28
+ */ export function createEditorDirectiveConfig(config, appearanceSlug) {
20
29
  const themes = {};
21
30
  for (const [groupName, group] of Object.entries(config?.themes ?? {}))if (group) themes[groupName] = stripThemeGroup(group);
22
31
  return {
32
+ ...appearanceSlug ? {
33
+ appearanceSlug
34
+ } : {},
23
35
  iconPacks: (config?.icons?.packs ?? []).map((pack)=>pack.alias.trim()).filter((alias)=>alias.length > 0),
36
+ palettes: getPaletteRegistry(config?.palettes).names(),
24
37
  ...Object.keys(themes).length > 0 ? {
25
38
  themes
26
39
  } : {}
@@ -33,7 +46,14 @@ function isRecord(value) {
33
46
  if (!isRecord(custom)) return undefined;
34
47
  const value = custom[PAYLOAD_MARKDOWN_ADMIN_CUSTOM_KEY];
35
48
  if (!isRecord(value)) return undefined;
49
+ const strings = (list)=>Array.isArray(list) ? list.filter((item)=>typeof item === 'string') : undefined;
36
50
  return {
51
+ ...typeof value.appearanceSlug === 'string' && value.appearanceSlug ? {
52
+ appearanceSlug: value.appearanceSlug
53
+ } : {},
54
+ ...strings(value.palettes) ? {
55
+ palettes: strings(value.palettes)
56
+ } : {},
37
57
  ...Array.isArray(value.iconPacks) ? {
38
58
  iconPacks: value.iconPacks.filter((alias)=>typeof alias === 'string')
39
59
  } : {},
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/editor/directiveConfig.ts"],"sourcesContent":["import type {\n MarkdownDirectiveTheme,\n MarkdownDirectiveThemeGroup,\n MarkdownDirectiveThemes,\n MarkdownRenderConfig,\n} from '../types/core.js'\n\n/** Key under `field.admin.custom` that carries the editor's directive config. */\nexport const PAYLOAD_MARKDOWN_ADMIN_CUSTOM_KEY = 'payloadMarkdown'\n\n/**\n * Serializable subset of the render configuration that the admin editor needs\n * to lint and complete directives the same way the renderer resolves them:\n * the directive theme registry (names only) and the icon pack aliases.\n */\nexport type MarkdownEditorDirectiveConfig = {\n /** Configured icon pack aliases; `undefined` when unknown to the editor. */\n iconPacks?: string[]\n themes?: MarkdownDirectiveThemes\n}\n\nfunction stripThemeGroup(group: MarkdownDirectiveThemeGroup): MarkdownDirectiveThemeGroup {\n const toNameOnly = (theme: MarkdownDirectiveTheme): MarkdownDirectiveTheme => ({\n name: theme.name,\n classes: '',\n })\n\n if (Array.isArray(group)) return group.map(toNameOnly)\n\n return {\n ...(typeof group.extendDefaults === 'boolean' ? { extendDefaults: group.extendDefaults } : {}),\n items: (group.items ?? []).map(toNameOnly),\n }\n}\n\n/**\n * Builds the editor config from a resolved render config. Theme classes are\n * dropped (the editor only needs names), so the result is small and safe to\n * serialize into the admin client config.\n */\nexport function createEditorDirectiveConfig(\n config: MarkdownRenderConfig | undefined,\n): MarkdownEditorDirectiveConfig {\n const themes: MarkdownDirectiveThemes = {}\n\n for (const [groupName, group] of Object.entries(config?.themes ?? {}) as Array<\n [keyof MarkdownDirectiveThemes, MarkdownDirectiveThemeGroup | undefined]\n >)\n if (group) themes[groupName] = stripThemeGroup(group)\n\n return {\n iconPacks: (config?.icons?.packs ?? [])\n .map((pack) => pack.alias.trim())\n .filter((alias) => alias.length > 0),\n ...(Object.keys(themes).length > 0 ? { themes } : {}),\n }\n}\n\nfunction isRecord(value: unknown): value is Record<string, unknown> {\n return Boolean(value) && typeof value === 'object' && !Array.isArray(value)\n}\n\n/** Reads the editor config from `field.admin.custom`, tolerating bad input. */\nexport function readEditorDirectiveConfig(custom: unknown): MarkdownEditorDirectiveConfig | undefined {\n if (!isRecord(custom)) return undefined\n\n const value = custom[PAYLOAD_MARKDOWN_ADMIN_CUSTOM_KEY]\n if (!isRecord(value)) return undefined\n\n return {\n ...(Array.isArray(value.iconPacks)\n ? { iconPacks: value.iconPacks.filter((alias): alias is string => typeof alias === 'string') }\n : {}),\n ...(isRecord(value.themes) ? { themes: value.themes as MarkdownDirectiveThemes } : {}),\n }\n}\n"],"names":["PAYLOAD_MARKDOWN_ADMIN_CUSTOM_KEY","stripThemeGroup","group","toNameOnly","theme","name","classes","Array","isArray","map","extendDefaults","items","createEditorDirectiveConfig","config","themes","groupName","Object","entries","iconPacks","icons","packs","pack","alias","trim","filter","length","keys","isRecord","value","Boolean","readEditorDirectiveConfig","custom","undefined"],"mappings":"AAOA,+EAA+E,GAC/E,OAAO,MAAMA,oCAAoC,kBAAiB;AAalE,SAASC,gBAAgBC,KAAkC;IACzD,MAAMC,aAAa,CAACC,QAA2D,CAAA;YAC7EC,MAAMD,MAAMC,IAAI;YAChBC,SAAS;QACX,CAAA;IAEA,IAAIC,MAAMC,OAAO,CAACN,QAAQ,OAAOA,MAAMO,GAAG,CAACN;IAE3C,OAAO;QACL,GAAI,OAAOD,MAAMQ,cAAc,KAAK,YAAY;YAAEA,gBAAgBR,MAAMQ,cAAc;QAAC,IAAI,CAAC,CAAC;QAC7FC,OAAO,AAACT,CAAAA,MAAMS,KAAK,IAAI,EAAE,AAAD,EAAGF,GAAG,CAACN;IACjC;AACF;AAEA;;;;CAIC,GACD,OAAO,SAASS,4BACdC,MAAwC;IAExC,MAAMC,SAAkC,CAAC;IAEzC,KAAK,MAAM,CAACC,WAAWb,MAAM,IAAIc,OAAOC,OAAO,CAACJ,QAAQC,UAAU,CAAC,GAGjE,IAAIZ,OAAOY,MAAM,CAACC,UAAU,GAAGd,gBAAgBC;IAEjD,OAAO;QACLgB,WAAW,AAACL,CAAAA,QAAQM,OAAOC,SAAS,EAAE,AAAD,EAClCX,GAAG,CAAC,CAACY,OAASA,KAAKC,KAAK,CAACC,IAAI,IAC7BC,MAAM,CAAC,CAACF,QAAUA,MAAMG,MAAM,GAAG;QACpC,GAAIT,OAAOU,IAAI,CAACZ,QAAQW,MAAM,GAAG,IAAI;YAAEX;QAAO,IAAI,CAAC,CAAC;IACtD;AACF;AAEA,SAASa,SAASC,KAAc;IAC9B,OAAOC,QAAQD,UAAU,OAAOA,UAAU,YAAY,CAACrB,MAAMC,OAAO,CAACoB;AACvE;AAEA,6EAA6E,GAC7E,OAAO,SAASE,0BAA0BC,MAAe;IACvD,IAAI,CAACJ,SAASI,SAAS,OAAOC;IAE9B,MAAMJ,QAAQG,MAAM,CAAC/B,kCAAkC;IACvD,IAAI,CAAC2B,SAASC,QAAQ,OAAOI;IAE7B,OAAO;QACL,GAAIzB,MAAMC,OAAO,CAACoB,MAAMV,SAAS,IAC7B;YAAEA,WAAWU,MAAMV,SAAS,CAACM,MAAM,CAAC,CAACF,QAA2B,OAAOA,UAAU;QAAU,IAC3F,CAAC,CAAC;QACN,GAAIK,SAASC,MAAMd,MAAM,IAAI;YAAEA,QAAQc,MAAMd,MAAM;QAA4B,IAAI,CAAC,CAAC;IACvF;AACF"}
1
+ {"version":3,"sources":["../../src/editor/directiveConfig.ts"],"sourcesContent":["import type {\n MarkdownDirectiveTheme,\n MarkdownDirectiveThemeGroup,\n MarkdownDirectiveThemes,\n MarkdownRenderConfig,\n} from '../types/core.js'\n\nimport { getPaletteRegistry } from '../palettes/index.js'\n\n/** Key under `field.admin.custom` that carries the editor's directive config. */\nexport const PAYLOAD_MARKDOWN_ADMIN_CUSTOM_KEY = 'payloadMarkdown'\n\n/**\n * Serializable subset of the render configuration that the admin editor needs\n * to lint and complete directives the same way the renderer resolves them:\n * the directive theme registry (names only) and the icon pack aliases.\n */\nexport type MarkdownEditorDirectiveConfig = {\n /** Slug of the \"Markdown Appearance\" global, whose palettes the editor loads at runtime. */\n appearanceSlug?: string\n /**\n * Runtime palette names (configured plus admin-managed), set by the field\n * component once loaded; `undefined` while they are still loading.\n */\n getPaletteNames?: () => readonly string[] | undefined\n /** Configured icon pack aliases; `undefined` when unknown to the editor. */\n iconPacks?: string[]\n /** Palette names known when the config was built (built-in and configured). */\n palettes?: string[]\n themes?: MarkdownDirectiveThemes\n}\n\n/**\n * Palette names the editor can check against, or `undefined` while palettes\n * managed in the admin are still loading (nothing is reported as unknown then).\n */\nexport function getEditorPaletteNames(config: MarkdownEditorDirectiveConfig): readonly string[] | undefined {\n const loaded = config.getPaletteNames?.()\n if (loaded) return loaded\n\n return config.appearanceSlug ? undefined : config.palettes\n}\n\nfunction stripThemeGroup(group: MarkdownDirectiveThemeGroup): MarkdownDirectiveThemeGroup {\n const toNameOnly = (theme: MarkdownDirectiveTheme): MarkdownDirectiveTheme => ({\n name: theme.name,\n classes: '',\n })\n\n if (Array.isArray(group)) return group.map(toNameOnly)\n\n return {\n ...(typeof group.extendDefaults === 'boolean' ? { extendDefaults: group.extendDefaults } : {}),\n items: (group.items ?? []).map(toNameOnly),\n }\n}\n\n/**\n * Builds the editor config from a resolved render config. Theme classes are\n * dropped (the editor only needs names), so the result is small and safe to\n * serialize into the admin client config.\n */\nexport function createEditorDirectiveConfig(\n config: MarkdownRenderConfig | undefined,\n appearanceSlug?: string,\n): MarkdownEditorDirectiveConfig {\n const themes: MarkdownDirectiveThemes = {}\n\n for (const [groupName, group] of Object.entries(config?.themes ?? {}) as Array<\n [keyof MarkdownDirectiveThemes, MarkdownDirectiveThemeGroup | undefined]\n >)\n if (group) themes[groupName] = stripThemeGroup(group)\n\n return {\n ...(appearanceSlug ? { appearanceSlug } : {}),\n iconPacks: (config?.icons?.packs ?? [])\n .map((pack) => pack.alias.trim())\n .filter((alias) => alias.length > 0),\n palettes: getPaletteRegistry(config?.palettes).names(),\n ...(Object.keys(themes).length > 0 ? { themes } : {}),\n }\n}\n\nfunction isRecord(value: unknown): value is Record<string, unknown> {\n return Boolean(value) && typeof value === 'object' && !Array.isArray(value)\n}\n\n/** Reads the editor config from `field.admin.custom`, tolerating bad input. */\nexport function readEditorDirectiveConfig(custom: unknown): MarkdownEditorDirectiveConfig | undefined {\n if (!isRecord(custom)) return undefined\n\n const value = custom[PAYLOAD_MARKDOWN_ADMIN_CUSTOM_KEY]\n if (!isRecord(value)) return undefined\n\n const strings = (list: unknown) =>\n Array.isArray(list) ? list.filter((item): item is string => typeof item === 'string') : undefined\n\n return {\n ...(typeof value.appearanceSlug === 'string' && value.appearanceSlug ? { appearanceSlug: value.appearanceSlug } : {}),\n ...(strings(value.palettes) ? { palettes: strings(value.palettes) } : {}),\n ...(Array.isArray(value.iconPacks)\n ? { iconPacks: value.iconPacks.filter((alias): alias is string => typeof alias === 'string') }\n : {}),\n ...(isRecord(value.themes) ? { themes: value.themes as MarkdownDirectiveThemes } : {}),\n }\n}\n"],"names":["getPaletteRegistry","PAYLOAD_MARKDOWN_ADMIN_CUSTOM_KEY","getEditorPaletteNames","config","loaded","getPaletteNames","appearanceSlug","undefined","palettes","stripThemeGroup","group","toNameOnly","theme","name","classes","Array","isArray","map","extendDefaults","items","createEditorDirectiveConfig","themes","groupName","Object","entries","iconPacks","icons","packs","pack","alias","trim","filter","length","names","keys","isRecord","value","Boolean","readEditorDirectiveConfig","custom","strings","list","item"],"mappings":"AAOA,SAASA,kBAAkB,QAAQ,uBAAsB;AAEzD,+EAA+E,GAC/E,OAAO,MAAMC,oCAAoC,kBAAiB;AAsBlE;;;CAGC,GACD,OAAO,SAASC,sBAAsBC,MAAqC;IACzE,MAAMC,SAASD,OAAOE,eAAe;IACrC,IAAID,QAAQ,OAAOA;IAEnB,OAAOD,OAAOG,cAAc,GAAGC,YAAYJ,OAAOK,QAAQ;AAC5D;AAEA,SAASC,gBAAgBC,KAAkC;IACzD,MAAMC,aAAa,CAACC,QAA2D,CAAA;YAC7EC,MAAMD,MAAMC,IAAI;YAChBC,SAAS;QACX,CAAA;IAEA,IAAIC,MAAMC,OAAO,CAACN,QAAQ,OAAOA,M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YnC;IAE1F,OAAO;QACL,GAAI,OAAO6B,MAAM9B,cAAc,KAAK,YAAY8B,MAAM9B,cAAc,GAAG;YAAEA,gBAAgB8B,MAAM9B,cAAc;QAAC,IAAI,CAAC,CAAC;QACpH,GAAIkC,QAAQJ,MAAM5B,QAAQ,IAAI;YAAEA,UAAUgC,QAAQJ,MAAM5B,QAAQ;QAAE,IAAI,CAAC,CAAC;QACxE,GAAIO,MAAMC,OAAO,CAACoB,MAAMX,SAAS,IAC7B;YAAEA,WAAWW,MAAMX,SAAS,CAACM,MAAM,CAAC,CAACF,QAA2B,OAAOA,UAAU;QAAU,IAC3F,CAAC,CAAC;QACN,GAAIM,SAASC,MAAMf,MAAM,IAAI;YAAEA,QAAQe,MAAMf,MAAM;QAA4B,IAAI,CAAC,CAAC;IACvF;AACF"}
@@ -3,9 +3,11 @@ import type { MarkdownEditorDirectiveConfig } from '../directiveConfig.js';
3
3
  export declare function getDirectiveCompletionOptions(): Completion[];
4
4
  export declare function getDirectiveAttributeCompletionOptions(name: string): Completion[];
5
5
  export declare function getDirectiveThemeValueCompletionOptions(name: string, attribute: string, config?: MarkdownEditorDirectiveConfig): Completion[];
6
+ /** Palette names: configured ones plus, once loaded, those managed in the admin. */
7
+ export declare function getPaletteCompletionOptions(config?: MarkdownEditorDirectiveConfig): Completion[];
6
8
  /**
7
- * Directive completions that know the field's configured themes and icon
8
- * packs (CORE-8). `config` comes from `field.admin.custom.payloadMarkdown`.
9
+ * Directive completions that know the field's configured themes, icon packs
10
+ * and palettes (CORE-8). `config` comes from `field.admin.custom.payloadMarkdown`.
9
11
  */
10
12
  export declare function createDirectiveCompletions(config?: MarkdownEditorDirectiveConfig): import("@codemirror/state").Extension;
11
13
  export declare const directiveCompletions: import("@codemirror/state").Extension;
@@ -1,6 +1,7 @@
1
1
  import { autocompletion, snippetCompletion } from '@codemirror/autocomplete';
2
2
  import { layoutDirectiveRegistry } from '../../directives/registry.js';
3
3
  import { getDirectiveThemeNames } from '../../directives/themes.js';
4
+ import { getEditorPaletteNames } from '../directiveConfig.js';
4
5
  export function getDirectiveCompletionOptions() {
5
6
  return layoutDirectiveRegistry.getPublicDefinitions().flatMap((definition)=>{
6
7
  const label = definition.editor.label.startsWith(':') ? definition.editor.label : `:::${definition.name}`;
@@ -38,6 +39,7 @@ export function getDirectiveThemeValueCompletionOptions(name, attribute, config
38
39
  const definition = layoutDirectiveRegistry.get(name);
39
40
  const groupName = definition?.themeAttributes?.[attribute];
40
41
  const detailPrefix = name === 'button' || name === 'badge' ? `::${name}` : `:::${name}`;
42
+ if (attribute === 'palette' || attribute === 'iconPalette') return getPaletteCompletionOptions(config);
41
43
  if (attribute === 'icon') return (config.iconPacks ?? []).map((alias)=>({
42
44
  type: 'constant',
43
45
  detail: 'icon pack',
@@ -54,6 +56,14 @@ export function getDirectiveThemeValueCompletionOptions(name, attribute, config
54
56
  label: themeName
55
57
  }));
56
58
  }
59
+ /** Palette names: configured ones plus, once loaded, those managed in the admin. */ export function getPaletteCompletionOptions(config = {}) {
60
+ const names = getEditorPaletteNames(config) ?? config.palettes ?? [];
61
+ return names.map((name)=>({
62
+ type: 'constant',
63
+ detail: 'palette',
64
+ label: name
65
+ }));
66
+ }
57
67
  function attributeCompletionSource(context, config) {
58
68
  const line = context.state.doc.lineAt(context.pos);
59
69
  const beforeCursor = line.text.slice(0, context.pos - line.from);
@@ -69,7 +79,16 @@ function attributeCompletionSource(context, config) {
69
79
  } : multilineMatch;
70
80
  if (!directiveMatch) return null;
71
81
  const { name, attributesBeforeCursor } = directiveMatch;
72
- const valueMatch = attributesBeforeCursor.match(/(?:^|\s)(align|gap|theme|cardTheme|cellTheme|icon|iconPosition|interval|linkScope|newTab|size|stack|stepTheme|style|tabTheme|target|type|variant|wrap)=["']?([^"'\s}]*)$/);
82
+ // `palette=` inside an icon entry: icon="@pack/a palette=|"
83
+ const iconPaletteMatch = attributesBeforeCursor.match(/(?:^|\s)icon=["'][^"']*\spalette=([\w-]*)$/);
84
+ if (iconPaletteMatch) {
85
+ const options = getPaletteCompletionOptions(config);
86
+ return options.length > 0 ? {
87
+ from: context.pos - iconPaletteMatch[1].length,
88
+ options
89
+ } : null;
90
+ }
91
+ const valueMatch = attributesBeforeCursor.match(/(?:^|\s)(align|gap|theme|cardTheme|cellTheme|icon|iconPalette|iconPosition|interval|linkScope|newTab|palette|size|stack|stepTheme|style|tabTheme|target|type|variant|wrap)=["']?([^"'\s}]*)$/);
73
92
  if (valueMatch) {
74
93
  const [, attribute, typedValue] = valueMatch;
75
94
  const options = getDirectiveThemeValueCompletionOptions(name, attribute, config);
@@ -131,8 +150,8 @@ function directiveCompletionSource(context, config = {}) {
131
150
  };
132
151
  }
133
152
  /**
134
- * Directive completions that know the field's configured themes and icon
135
- * packs (CORE-8). `config` comes from `field.admin.custom.payloadMarkdown`.
153
+ * Directive completions that know the field's configured themes, icon packs
154
+ * and palettes (CORE-8). `config` comes from `field.admin.custom.payloadMarkdown`.
136
155
  */ export function createDirectiveCompletions(config = {}) {
137
156
  return autocompletion({
138
157
  activateOnTyping: true,
@@ -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":"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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,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;oBAClDL,OAAOM,QAAQN,KAAK;oBACpBM,SAASA,QAAQA,OAAO;gBAC1B,CAAA;SACD;QAED,OAAOF,SAASG,GAAG,CAAC,CAACD,UACnBd,kBAAkBc,QAAQA,OAAO,EAAE;gBACjCE,MAAM;gBACNH,QAAQC,QAAQD,MAAM;gBACtBI,MAAMV,WAAWW,WAAW;gBAC5BV,OAAOM,QAAQN,KAAK;YACt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nF,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 and icon
4
- * packs (CORE-8), so custom themes are not reported as unknown.
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 and icon
5
- * packs (CORE-8), so custom themes are not reported as unknown.
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
- return lintMarkdownDirectives(view.state.doc.toString(), config).map((diagnostic)=>({
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 and icon\n * packs (CORE-8), so custom themes are not reported as unknown.\n */\nexport const createDirectiveDiagnostics = (config: MarkdownEditorDirectiveConfig = {}) =>\n linter((view): Diagnostic[] => {\n try {\n return lintMarkdownDirectives(view.state.doc.toString(), config).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","createDirectiveDiagnostics","config","view","state","doc","toString","map","diagnostic","from","message","severity","to","error","Error","String","directiveDiagnostics"],"mappings":"AAEA,SAASA,MAAM,QAAQ,mBAAkB;AAIzC,SAASC,sBAAsB,QAAQ,kCAAiC;AAExE;;;CAGC,GACD,OAAO,MAAMC,6BAA6B,CAACC,SAAwC,CAAC,CAAC,GACnFH,OAAO,CAACI;QACR,IAAI;YACF,OAAOH,uBAAuBG,KAAKC,KAAK,CAACC,GAAG,CAACC,QAAQ,IAAIJ,QAAQK,GAAG,CAAC,CAACC,aAAgB,CAAA;oBACpFC,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,uBAAuBf,6BAA4B"}
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"}
@@ -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';
@@ -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 { MarkdownRendererClient } from '../components/MarkdownRenderer/Component.client.js';
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":["export { MarkdownBlockParamsEnableField } from '../blocks/MarkdownBlock/ParamsEnableField.client.js'\n/**\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 * - `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 {\n MarkdownRendererClient,\n type MarkdownRendererClientProps,\n} from '../components/MarkdownRenderer/Component.client.js'\nexport { PayloadMarkdownField } from '../field/MarkdownField/Component.js'\n"],"names":["MarkdownBlockParamsEnableField","MarkdownRendererClient","PayloadMarkdownField"],"mappings":"AAAA,SAASA,8BAA8B,QAAQ,sDAAqD;AACpG;;;;;;;;;;;;;;;CAeC,GACD,SACEC,sBAAsB,QAEjB,qDAAoD;AAC3D,SAASC,oBAAoB,QAAQ,sCAAqC"}
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"}