payload-markdown 1.8.0 → 1.9.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (196) 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/rehypeResolveIcons.js +10 -1
  31. package/dist/core/plugins/rehypeResolveIcons.js.map +1 -1
  32. package/dist/core/plugins/remarkCompileLayouts.js.map +1 -1
  33. package/dist/core/plugins/remarkDirectiveLines.d.ts +7 -5
  34. package/dist/core/plugins/remarkDirectiveLines.js +29 -18
  35. package/dist/core/plugins/remarkDirectiveLines.js.map +1 -1
  36. package/dist/core/plugins/remarkLayoutDirectives.js +1 -1
  37. package/dist/core/plugins/remarkLayoutDirectives.js.map +1 -1
  38. package/dist/core/plugins/remarkValidateDirectiveThemes.js +7 -14
  39. package/dist/core/plugins/remarkValidateDirectiveThemes.js.map +1 -1
  40. package/dist/core/plugins/remarkValidatePalettes.d.ts +9 -0
  41. package/dist/core/plugins/remarkValidatePalettes.js +51 -0
  42. package/dist/core/plugins/remarkValidatePalettes.js.map +1 -0
  43. package/dist/core/renderMarkdown.js +4 -221
  44. package/dist/core/renderMarkdown.js.map +1 -1
  45. package/dist/core/sanitizeSchema.d.ts +11 -0
  46. package/dist/core/sanitizeSchema.js +176 -0
  47. package/dist/core/sanitizeSchema.js.map +1 -0
  48. package/dist/directive-spec.json +60 -0
  49. package/dist/directives/definitions/badge.d.ts +5 -2
  50. package/dist/directives/definitions/badge.js +138 -10
  51. package/dist/directives/definitions/badge.js.map +1 -1
  52. package/dist/directives/definitions/badges.d.ts +1 -2
  53. package/dist/directives/definitions/badges.js +12 -3
  54. package/dist/directives/definitions/badges.js.map +1 -1
  55. package/dist/directives/definitions/button.d.ts +7 -3
  56. package/dist/directives/definitions/button.js +211 -14
  57. package/dist/directives/definitions/button.js.map +1 -1
  58. package/dist/directives/definitions/buttons.d.ts +1 -2
  59. package/dist/directives/definitions/buttons.js +12 -3
  60. package/dist/directives/definitions/buttons.js.map +1 -1
  61. package/dist/directives/definitions/callout.d.ts +1 -2
  62. package/dist/directives/definitions/callout.js +46 -5
  63. package/dist/directives/definitions/callout.js.map +1 -1
  64. package/dist/directives/definitions/card.d.ts +6 -4
  65. package/dist/directives/definitions/card.js +64 -11
  66. package/dist/directives/definitions/card.js.map +1 -1
  67. package/dist/directives/definitions/cards.d.ts +1 -2
  68. package/dist/directives/definitions/cards.js +49 -4
  69. package/dist/directives/definitions/cards.js.map +1 -1
  70. package/dist/directives/definitions/cell.d.ts +2 -2
  71. package/dist/directives/definitions/cell.js +9 -3
  72. package/dist/directives/definitions/cell.js.map +1 -1
  73. package/dist/directives/definitions/columns.d.ts +3 -4
  74. package/dist/directives/definitions/columns.js +17 -3
  75. package/dist/directives/definitions/columns.js.map +1 -1
  76. package/dist/directives/definitions/details.d.ts +1 -2
  77. package/dist/directives/definitions/details.js +28 -3
  78. package/dist/directives/definitions/details.js.map +1 -1
  79. package/dist/directives/definitions/section.d.ts +1 -2
  80. package/dist/directives/definitions/section.js +26 -3
  81. package/dist/directives/definitions/section.js.map +1 -1
  82. package/dist/directives/definitions/steps.d.ts +1 -2
  83. package/dist/directives/definitions/steps.js +26 -3
  84. package/dist/directives/definitions/steps.js.map +1 -1
  85. package/dist/directives/definitions/tab.d.ts +8 -2
  86. package/dist/directives/definitions/tab.js +45 -3
  87. package/dist/directives/definitions/tab.js.map +1 -1
  88. package/dist/directives/definitions/tabs.d.ts +1 -1
  89. package/dist/directives/definitions/tabs.js +44 -3
  90. package/dist/directives/definitions/tabs.js.map +1 -1
  91. package/dist/directives/definitions/toc.d.ts +1 -2
  92. package/dist/directives/definitions/toc.js +33 -5
  93. package/dist/directives/definitions/toc.js.map +1 -1
  94. package/dist/directives/diagnostics.d.ts +2 -10
  95. package/dist/directives/diagnostics.js +27 -141
  96. package/dist/directives/diagnostics.js.map +1 -1
  97. package/dist/directives/iconPlaceholder.d.ts +9 -3
  98. package/dist/directives/iconPlaceholder.js +8 -1
  99. package/dist/directives/iconPlaceholder.js.map +1 -1
  100. package/dist/directives/lint.d.ts +11 -0
  101. package/dist/directives/lint.js +33 -0
  102. package/dist/directives/lint.js.map +1 -0
  103. package/dist/directives/palette.d.ts +23 -0
  104. package/dist/directives/palette.js +40 -0
  105. package/dist/directives/palette.js.map +1 -0
  106. package/dist/directives/registry.d.ts +23 -5
  107. package/dist/directives/registry.js +52 -40
  108. package/dist/directives/registry.js.map +1 -1
  109. package/dist/directives/spec.d.ts +6 -2
  110. package/dist/directives/spec.js +29 -50
  111. package/dist/directives/spec.js.map +1 -1
  112. package/dist/directives/themeDiagnostics.d.ts +8 -0
  113. package/dist/directives/themeDiagnostics.js +21 -0
  114. package/dist/directives/themeDiagnostics.js.map +1 -0
  115. package/dist/directives/types.d.ts +157 -14
  116. package/dist/directives/types.js +6 -1
  117. package/dist/directives/types.js.map +1 -1
  118. package/dist/editor/directiveConfig.d.ts +15 -1
  119. package/dist/editor/directiveConfig.js +21 -1
  120. package/dist/editor/directiveConfig.js.map +1 -1
  121. package/dist/editor/directives/completions.d.ts +4 -2
  122. package/dist/editor/directives/completions.js +33 -7
  123. package/dist/editor/directives/completions.js.map +1 -1
  124. package/dist/editor/directives/diagnostics.d.ts +2 -2
  125. package/dist/editor/directives/diagnostics.js +10 -3
  126. package/dist/editor/directives/diagnostics.js.map +1 -1
  127. package/dist/editor/themes/payload.js +2 -1
  128. package/dist/editor/themes/payload.js.map +1 -1
  129. package/dist/exports/client.d.ts +4 -1
  130. package/dist/exports/client.js +5 -2
  131. package/dist/exports/client.js.map +1 -1
  132. package/dist/field/MarkdownField/Component.js +54 -3
  133. package/dist/field/MarkdownField/Component.js.map +1 -1
  134. package/dist/icons/entries.d.ts +22 -0
  135. package/dist/icons/entries.js +50 -0
  136. package/dist/icons/entries.js.map +1 -0
  137. package/dist/icons/resolve.d.ts +2 -1
  138. package/dist/icons/resolve.js +2 -2
  139. package/dist/icons/resolve.js.map +1 -1
  140. package/dist/icons/sanitizeSvg.d.ts +12 -2
  141. package/dist/icons/sanitizeSvg.js +104 -3
  142. package/dist/icons/sanitizeSvg.js.map +1 -1
  143. package/dist/index.d.ts +11 -4
  144. package/dist/index.js +34 -3
  145. package/dist/index.js.map +1 -1
  146. package/dist/mcp/index.d.ts +2 -2
  147. package/dist/mcp/index.js +65 -4
  148. package/dist/mcp/index.js.map +1 -1
  149. package/dist/palettes/colors.d.ts +21 -0
  150. package/dist/palettes/colors.js +43 -0
  151. package/dist/palettes/colors.js.map +1 -0
  152. package/dist/palettes/contrast.d.ts +7 -0
  153. package/dist/palettes/contrast.js +63 -0
  154. package/dist/palettes/contrast.js.map +1 -0
  155. package/dist/palettes/defaults.d.ts +8 -0
  156. package/dist/palettes/defaults.js +275 -0
  157. package/dist/palettes/defaults.js.map +1 -0
  158. package/dist/palettes/diagnostics.d.ts +10 -0
  159. package/dist/palettes/diagnostics.js +38 -0
  160. package/dist/palettes/diagnostics.js.map +1 -0
  161. package/dist/palettes/index.d.ts +61 -0
  162. package/dist/palettes/index.js +246 -0
  163. package/dist/palettes/index.js.map +1 -0
  164. package/dist/render/renderMarkdown.d.ts +3 -1
  165. package/dist/render/renderMarkdown.js +9 -1
  166. package/dist/render/renderMarkdown.js.map +1 -1
  167. package/dist/runtime/index.d.ts +12 -1
  168. package/dist/runtime/index.js +21 -2
  169. package/dist/runtime/index.js.map +1 -1
  170. package/dist/types/core.d.ts +43 -0
  171. package/dist/types/core.js.map +1 -1
  172. package/dist/types.d.ts +46 -2
  173. package/dist/types.js.map +1 -1
  174. package/dist/version.d.ts +1 -1
  175. package/dist/version.js +1 -1
  176. package/dist/version.js.map +1 -1
  177. package/package.json +1 -1
  178. package/skills/payload-markdown/claude/SKILL.md +1 -0
  179. package/skills/payload-markdown/claude/reference/directive-spec.json +60 -0
  180. package/skills/payload-markdown/claude/reference/mcp-content-workflow.md +7 -0
  181. package/skills/payload-markdown/claude/reference/payload-markdown-directives.md +22 -2
  182. package/skills/payload-markdown/claude/skill.json +2 -2
  183. package/skills/payload-markdown/codex/SKILL.md +1 -0
  184. package/skills/payload-markdown/codex/reference/directive-spec.json +60 -0
  185. package/skills/payload-markdown/codex/reference/mcp-content-workflow.md +7 -0
  186. package/skills/payload-markdown/codex/reference/payload-markdown-directives.md +22 -2
  187. package/skills/payload-markdown/codex/skill.json +2 -2
  188. package/dist/core/plugins/directiveBadge.d.ts +0 -6
  189. package/dist/core/plugins/directiveBadge.js +0 -94
  190. package/dist/core/plugins/directiveBadge.js.map +0 -1
  191. package/dist/core/plugins/directiveButton.d.ts +0 -6
  192. package/dist/core/plugins/directiveButton.js +0 -115
  193. package/dist/core/plugins/directiveButton.js.map +0 -1
  194. package/dist/directives/buttonSyntax.d.ts +0 -7
  195. package/dist/directives/buttonSyntax.js +0 -6
  196. package/dist/directives/buttonSyntax.js.map +0 -1
@@ -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;
@@ -1,40 +1,22 @@
1
- import { CALLOUT_VARIANTS } from './definitions/callout.js';
2
1
  import { slugTabValue } from './definitions/tab.js';
3
2
  import { slugifyHeading } from './headingAnchors.js';
4
- import { DIRECTIVE_LABEL_ATTRIBUTES, layoutDirectiveRegistry } from './registry.js';
3
+ import { layoutDirectiveRegistry } from './registry.js';
5
4
  import { SHIELDS_BADGE_ORIGIN, SHIELDS_BADGE_QUERY_ATTRIBUTES, SHIELDS_BADGE_REQUIRED_ATTRIBUTES, SHIELDS_BADGE_TARGETS } from './shields.js';
6
5
  import { DEFAULT_DIRECTIVE_THEMES, getDirectiveFallbackThemeName } from './themes.js';
7
6
  /**
8
7
  * Version of the spec's JSON shape. Bump it on incompatible shape changes;
9
8
  * adding directives, attributes or values does not change it.
10
9
  */ export const DIRECTIVE_SPEC_VERSION = 1;
11
- const URL_ATTRIBUTES = new Set([
12
- 'href',
13
- 'src'
14
- ]);
15
- const BOOLEAN_ATTRIBUTES = new Set([
16
- 'disabled',
17
- 'open'
18
- ]);
19
- const NUMBER_ATTRIBUTES = {
20
- cacheSeconds: {
21
- min: 0
22
- },
23
- depth: {
24
- max: 6,
25
- min: 1
26
- }
27
- };
28
- /** Enumerations the definitions validate in code rather than through `attributeValues`. */ const EXTRA_ENUMS = {
29
- callout: {
30
- variant: CALLOUT_VARIANTS
31
- }
32
- };
33
10
  function isBooleanValues(values) {
34
11
  return Boolean(values && values.length === 2 && values.includes('true') && values.includes('false'));
35
12
  }
36
- function describeAttribute(definition, name) {
37
- const values = definition.attributeValues?.[name] ?? EXTRA_ENUMS[definition.name]?.[name];
13
+ /**
14
+ * An attribute's spec entry, from the definition alone: `themeAttributes`
15
+ * (theme names), `attributeTypes` (declared types), `attributeValues` (enums,
16
+ * or booleans when the values are exactly true/false), else a string.
17
+ */ function describeAttribute(definition, name) {
18
+ const declared = definition.attributeTypes?.[name];
19
+ const values = definition.attributeValues?.[name] ?? (declared?.type === 'enum' ? declared.values : undefined);
38
20
  const themeGroup = definition.themeAttributes?.[name];
39
21
  const defaultValue = definition.defaultAttributes?.[name];
40
22
  const base = {
@@ -48,11 +30,11 @@ function describeAttribute(definition, name) {
48
30
  type: 'string',
49
31
  themeGroup
50
32
  };
51
- if (URL_ATTRIBUTES.has(name)) return {
33
+ if (declared?.type === 'url') return {
52
34
  ...base,
53
35
  type: 'url'
54
36
  };
55
- if (BOOLEAN_ATTRIBUTES.has(name) || isBooleanValues(values)) return {
37
+ if (declared?.type === 'boolean' || isBooleanValues(values)) return {
56
38
  ...base,
57
39
  type: 'boolean',
58
40
  values: [
@@ -60,9 +42,14 @@ function describeAttribute(definition, name) {
60
42
  'false'
61
43
  ]
62
44
  };
63
- if (NUMBER_ATTRIBUTES[name]) return {
45
+ if (declared?.type === 'number') return {
64
46
  ...base,
65
- ...NUMBER_ATTRIBUTES[name],
47
+ ...declared.max !== undefined ? {
48
+ max: declared.max
49
+ } : {},
50
+ ...declared.min !== undefined ? {
51
+ min: declared.min
52
+ } : {},
66
53
  type: 'number'
67
54
  };
68
55
  if (values) return {
@@ -72,34 +59,24 @@ function describeAttribute(definition, name) {
72
59
  ...values
73
60
  ]
74
61
  };
75
- if (name === 'icon') return {
62
+ if (declared?.type === 'icon') return {
76
63
  ...base,
77
64
  type: 'string',
78
65
  format: 'icon'
79
66
  };
67
+ if (declared?.type === 'palette') return {
68
+ ...base,
69
+ type: 'string',
70
+ format: 'palette'
71
+ };
80
72
  return {
81
73
  ...base,
82
74
  type: 'string'
83
75
  };
84
76
  }
85
- function getCloseMarkers(definition) {
86
- if (!definition.openMarker) return [];
87
- if (layoutDirectiveRegistry.isGridName(definition.name)) return [
88
- ':::',
89
- ':::endcol'
90
- ];
91
- if (definition.name === 'section') return [
92
- ':::',
93
- ':::end',
94
- ':::endsection'
95
- ];
96
- return [
97
- ':::'
98
- ];
99
- }
100
77
  function describeDirective(definition) {
101
- const container = Boolean(definition.openMarker);
102
- const labelAttribute = DIRECTIVE_LABEL_ATTRIBUTES.get(definition.name);
78
+ const container = Boolean(definition.container);
79
+ const labelAttribute = definition.container?.labelAttribute;
103
80
  return {
104
81
  name: definition.name,
105
82
  attributes: [
@@ -108,7 +85,9 @@ function describeDirective(definition) {
108
85
  ...container ? {
109
86
  closeLabel: layoutDirectiveRegistry.getCloseLabel(definition.name)
110
87
  } : {},
111
- closeMarkers: getCloseMarkers(definition),
88
+ closeMarkers: [
89
+ ...layoutDirectiveRegistry.getCloseMarkers(definition)
90
+ ],
112
91
  ...definition.description ? {
113
92
  description: definition.description
114
93
  } : {},
@@ -116,7 +95,7 @@ function describeDirective(definition) {
116
95
  ...labelAttribute ? {
117
96
  labelAttribute
118
97
  } : {},
119
- open: definition.openMarker ?? `::${definition.name}`,
98
+ open: layoutDirectiveRegistry.getOpenMarker(definition),
120
99
  supportsAttributes: Boolean(definition.supportsAttributes)
121
100
  };
122
101
  }
@@ -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,EAC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AM;2BAAIgD;qBAAQ;iBAAC;YAErFC,OAAO;mBAAKpB,OAAOrC,iBAAiBQ,QAAQ,EAAE;aAAE;QAClD;QACAgB,cAAcnD,wBAAwBmD,YAAY,CAACH,GAAG,CAAC,CAAC,EAAEqC,MAAM,EAAEC,MAAM,EAAE,GAAM,CAAA;gBAC9EC,QAAQ/B,MAAM,CAAC6B,OAA8B;gBAC7CC;YACF,CAAA;QACAE,aAAa5B;QACb6B,YAAYzF,wBAAwB0F,GAAG,CAAC1C,GAAG,CAAC,CAACvB,aAAegB,kBAAkBhB;QAC9EkE,UAAU;YACRC,MAAM;gBACJ;gBACA;gBACA;aACD;YACDC,UAAU/B,iBAAiBd,GAAG,CAAC,CAAC8C,OAAS;oBAACA;oBAAMhG,eAAegG;iBAAM;QACvE;QACAC,SAAS;QACTC,aAAazF;QACb0F,MAAM;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 { slugTabValue } from './definitions/tab.js'\nimport { slugifyHeading } from './headingAnchors.js'\nimport { 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\nfunction isBooleanValues(values: readonly string[] | undefined): boolean {\n return Boolean(values && values.length === 2 && values.includes('true') && values.includes('false'))\n}\n\n/**\n * An attribute's spec entry, from the definition alone: `themeAttributes`\n * (theme names), `attributeTypes` (declared types), `attributeValues` (enums,\n * or booleans when the values are exactly true/false), else a string.\n */\nfunction describeAttribute(\n definition: LayoutDirectiveDefinition,\n name: string,\n): DirectiveSpecAttribute {\n const declared = definition.attributeTypes?.[name]\n const values =\n definition.attributeValues?.[name] ?? (declared?.type === 'enum' ? declared.values : undefined)\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 (declared?.type === 'url') return { ...base, type: 'url' }\n if (declared?.type === 'boolean' || isBooleanValues(values))\n return { ...base, type: 'boolean', values: ['true', 'false'] }\n if (declared?.type === 'number')\n return {\n ...base,\n ...(declared.max !== undefined ? { max: declared.max } : {}),\n ...(declared.min !== undefined ? { min: declared.min } : {}),\n type: 'number',\n }\n if (values) return { ...base, type: 'enum', values: [...values] }\n if (declared?.type === 'icon') return { ...base, type: 'string', format: 'icon' }\n if (declared?.type === 'palette') return { ...base, type: 'string', format: 'palette' }\n\n return { ...base, type: 'string' }\n}\n\nfunction describeDirective(definition: LayoutDirectiveDefinition): DirectiveSpecDirective {\n const container = Boolean(definition.container)\n const labelAttribute = definition.container?.labelAttribute\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: [...layoutDirectiveRegistry.getCloseMarkers(definition)],\n ...(definition.description ? { description: definition.description } : {}),\n kind: container ? 'container' : 'leaf',\n ...(labelAttribute ? { labelAttribute } : {}),\n open: layoutDirectiveRegistry.getOpenMarker(definition),\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":["slugTabValue","slugifyHeading","layoutDirectiveRegistry","SHIELDS_BADGE_ORIGIN","SHIELDS_BADGE_QUERY_ATTRIBUTES","SHIELDS_BADGE_REQUIRED_ATTRIBUTES","SHIELDS_BADGE_TARGETS","DEFAULT_DIRECTIVE_THEMES","getDirectiveFallbackThemeName","DIRECTIVE_SPEC_VERSION","isBooleanValues","values","Boolean","length","includes","describeAttribute","definition","name","declared","attributeTypes","attributeValues","type","undefined","themeGroup","themeAttributes","defaultValue","defaultAttributes","base","default","max","min","format","describeDirective","container","labelAttribute","attributes","allowedAttributes","sort","map","closeLabel","getCloseLabel","closeMarkers","getCloseMarkers","description","kind","open","getOpenMarker","supportsAttributes","CLOSES","close","closeGrid","closeSection","CONSTRAINTS","TAB_EXAMPLES","HEADING_EXAMPLES","getDirectiveSpec","badge","get","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,YAAY,QAAQ,uBAAsB;AACnD,SAASC,cAAc,QAAQ,sBAAqB;AACpD,SAASC,uBAAuB,QAAQ,gBAAe;AACvD,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,SAASC,gBAAgBC,MAAqC;IAC5D,OAAOC,QAAQD,UAAUA,OAAOE,MAAM,KAAK,KAAKF,OAAOG,QAAQ,CAAC,WAAWH,OAAOG,QAAQ,CAAC;AAC7F;AAEA;;;;CAIC,GACD,SAASC,kBACPC,UAAqC,EACrCC,IAAY;IAEZ,MAAMC,WAAWF,WAAWG,cAAc,EAAE,CAACF,KAAK;IAClD,MAAMN,SACJK,WAAWI,eAAe,EAAE,CAACH,KAAK,IAAKC,CAAAA,UAAUG,SAAS,SAASH,SAASP,MAAM,GAAGW,SAAQ;IAC/F,MAAMC,aAAaP,WAAWQ,eAAe,EAAE,CAACP,KAAK;IACrD,MAAMQ,eAAeT,WAAWU,iBAAiB,EAAE,CAACT,KAAK;IACzD,MAAMU,OAAO;QACXV;QACA,GAAIQ,iBAAiBH,YAAY;YAAEM,SAASH;QAAa,IAAI,CAAC,CAAC;IACjE;IAEA,IAAIF,YAAY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D;oBAAM;2BAAIoD;qBAAM;iBAAC;YAE7FC,QAAQ;mBAAKlB,OAAOpC,iBAAiBuD,SAAS,EAAE;aAAE;YAClDC,SAASjB,OAAOC,WAAW,CACzBD,OAAOa,OAAO,CAAClE,uBAAuBgC,GAAG,CAAC,CAAC,CAACjB,MAAMuD,QAAQ,GAAK;oBAACvD;oBAAM;2BAAIuD;qBAAQ;iBAAC;YAErFC,OAAO;mBAAKrB,OAAOpC,iBAAiBC,QAAQ,EAAE;aAAE;QAClD;QACAoB,cAAcvC,wBAAwBuC,YAAY,CAACH,GAAG,CAAC,CAAC,EAAEwC,MAAM,EAAEC,MAAM,EAAE,GAAM,CAAA;gBAC9EC,QAAQhC,MAAM,CAAC8B,OAA8B;gBAC7CC;YACF,CAAA;QACAE,aAAa7B;QACb8B,YAAYhF,wBAAwBiF,GAAG,CAAC7C,GAAG,CAAC,CAACtB,aAAegB,kBAAkBhB;QAC9EoE,UAAU;YACRC,MAAM;gBACJ;gBACA;gBACA;aACD;YACDC,UAAUhC,iBAAiBhB,GAAG,CAAC,CAACiD,OAAS;oBAACA;oBAAMtF,eAAesF;iBAAM;QACvE;QACAC,SAAS;QACTC,aAAahF;QACbiF,MAAM;YACJJ,UAAUjC,aAAaf,GAAG,CAAC,CAAC,CAACqD,KAAKC,MAAM,GAAM,CAAA;oBAAEA;oBAAOD;oBAAKE,OAAO7F,aAAa2F,KAAKC;gBAAO,CAAA;YAC5FC,OAAO;gBACL;gBACA;gBACA;gBACA;aACD;QACH;QACAnC;IACF;AACF"}
@@ -0,0 +1,8 @@
1
+ import type { MarkdownDirectiveThemes } from '../types/core.js';
2
+ import type { LayoutDirectiveDefinition } from './types.js';
3
+ /**
4
+ * "Unknown theme" diagnostics for a directive's theme attributes. Shared by
5
+ * the renderer (remarkValidateDirectiveThemes) and the editor linter, so both
6
+ * report the same messages.
7
+ */
8
+ export declare function getUnknownThemeDiagnostics(definition: LayoutDirectiveDefinition, attributes: null | Record<string, unknown> | undefined, themes: MarkdownDirectiveThemes | undefined): string[];
@@ -0,0 +1,21 @@
1
+ import { getDirectiveFallbackThemeName, hasDirectiveTheme } from './themes.js';
2
+ /**
3
+ * "Unknown theme" diagnostics for a directive's theme attributes. Shared by
4
+ * the renderer (remarkValidateDirectiveThemes) and the editor linter, so both
5
+ * report the same messages.
6
+ */ export function getUnknownThemeDiagnostics(definition, attributes, themes) {
7
+ if (!definition.themeAttributes) return [];
8
+ const diagnostics = [];
9
+ for (const [attribute, groupName] of Object.entries(definition.themeAttributes)){
10
+ if (!groupName) continue;
11
+ const value = attributes?.[attribute];
12
+ if (typeof value !== 'string' || !value.trim()) continue;
13
+ if (hasDirectiveTheme(groupName, value, themes)) continue;
14
+ const label = attribute === 'theme' ? 'theme' : attribute;
15
+ const hint = definition.unknownThemeHint?.(attribute, value);
16
+ diagnostics.push(`Unknown ${label} "${value}" on "${definition.name}". Falling back to "${getDirectiveFallbackThemeName(groupName, themes)}".${hint ? ` ${hint}` : ''}`);
17
+ }
18
+ return diagnostics;
19
+ }
20
+
21
+ //# sourceMappingURL=themeDiagnostics.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/directives/themeDiagnostics.ts"],"sourcesContent":["import type { MarkdownDirectiveThemes } from '../types/core.js'\nimport type { LayoutDirectiveDefinition } from './types.js'\n\nimport { getDirectiveFallbackThemeName, hasDirectiveTheme } from './themes.js'\n\n/**\n * \"Unknown theme\" diagnostics for a directive's theme attributes. Shared by\n * the renderer (remarkValidateDirectiveThemes) and the editor linter, so both\n * report the same messages.\n */\nexport function getUnknownThemeDiagnostics(\n definition: LayoutDirectiveDefinition,\n attributes: null | Record<string, unknown> | undefined,\n themes: MarkdownDirectiveThemes | undefined,\n): string[] {\n if (!definition.themeAttributes) return []\n\n const diagnostics: string[] = []\n\n for (const [attribute, groupName] of Object.entries(definition.themeAttributes)) {\n if (!groupName) continue\n\n const value = attributes?.[attribute]\n if (typeof value !== 'string' || !value.trim()) continue\n if (hasDirectiveTheme(groupName, value, themes)) continue\n\n const label = attribute === 'theme' ? 'theme' : attribute\n const hint = definition.unknownThemeHint?.(attribute, value)\n\n diagnostics.push(\n `Unknown ${label} \"${value}\" on \"${definition.name}\". Falling back to \"${getDirectiveFallbackThemeName(groupName, themes)}\".${hint ? ` ${hint}` : ''}`,\n )\n }\n\n return diagnostics\n}\n"],"names":["getDirectiveFallbackThemeName","hasDirectiveTheme","getUnknownThemeDiagnostics","definition","attributes","themes","themeAttributes","diagnostics","attribute","groupName","Object","entries","value","trim","label","hint","unknownThemeHint","push","name"],"mappings":"AAGA,SAASA,6BAA6B,EAAEC,iBAAiB,QAAQ,cAAa;AAE9E;;;;CAIC,GACD,OAAO,SAASC,2BACdC,UAAqC,EACrCC,UAAsD,EACtDC,MAA2C;IAE3C,IAAI,CAACF,WAAWG,eAAe,EAAE,OAAO,EAAE;IAE1C,MAAMC,cAAwB,EAAE;IAEhC,KAAK,MAAM,CAACC,WAAWC,UAAU,IAAIC,OAAOC,OAAO,CAACR,WAAWG,eAAe,EAAG;QAC/E,IAAI,CAACG,WAAW;QAEhB,MAAMG,QAAQR,YAAY,CAACI,UAAU;QACrC,IAAI,OAAOI,UAAU,YAAY,CAACA,MAAMC,IAAI,IAAI;QAChD,IAAIZ,kBAAkBQ,WAAWG,OAAOP,SAAS;QAEjD,MAAMS,QAAQN,cAAc,UAAU,UAAUA;QAChD,MAAMO,OAAOZ,WAAWa,gBAAgB,GAAGR,WAAWI;QAEtDL,YAAYU,IAAI,CACd,CAAC,QAAQ,EAAEH,MAAM,EAAE,EAAEF,MAAM,MAAM,EAAET,WAAWe,IAAI,CAAC,oBAAoB,EAAElB,8BAA8BS,WAAWJ,QAAQ,EAAE,EAAEU,OAAO,CAAC,CAAC,EAAEA,MAAM,GAAG,IAAI;IAE1J;IAEA,OAAOR;AACT"}
@@ -1,12 +1,20 @@
1
1
  import type { Element, ElementContent } from 'hast';
2
2
  import type { ContainerDirective, LeafDirective } from 'mdast-util-directive';
3
3
  import type { Data } from 'unist';
4
- import type { MarkdownRenderConfig } from '../types/core.js';
4
+ import type { MarkdownDirectiveThemes, MarkdownRenderConfig } from '../types/core.js';
5
+ import type { directiveDefinitions } from './registry.js';
5
6
  import type { DirectiveThemeGroupName, ResolvedDirectiveTheme } from './themes.js';
6
- export type LayoutDirectiveName = '2col' | '3col' | 'cell' | 'section';
7
- export type StaticDirectiveName = 'badge' | 'badges' | 'button' | 'buttons' | 'callout' | 'card' | 'cards' | 'details' | 'steps' | 'tab' | 'tabs' | 'toc';
8
- export type MarkdownDirectiveName = LayoutDirectiveName | StaticDirectiveName;
9
- export type GridDirectiveName = '2col' | '3col';
7
+ type RegisteredDefinition = (typeof directiveDefinitions)[number];
8
+ export type MarkdownDirectiveName = RegisteredDefinition['name'];
9
+ export type LayoutDirectiveKind = RegisteredDefinition['kind'];
10
+ export type GridDirectiveName = Extract<RegisteredDefinition, {
11
+ kind: 'grid';
12
+ }>['name'];
13
+ /** Structural layout directives (sections, grids and their cells). */
14
+ export type LayoutDirectiveName = Extract<RegisteredDefinition, {
15
+ kind: 'cell' | 'grid' | 'section';
16
+ }>['name'];
17
+ export type StaticDirectiveName = Exclude<MarkdownDirectiveName, LayoutDirectiveName>;
10
18
  export type LayoutName = MarkdownDirectiveName;
11
19
  /** Layout token data: `vlPlace` is the marker's 1-based source position. */
12
20
  export type LayoutTokenData = {
@@ -37,10 +45,8 @@ export type LayoutToken = {
37
45
  };
38
46
  export type DirectiveChild = ContainerDirective['children'][number];
39
47
  export type MarkdownDirectiveNode = ContainerDirective | LeafDirective;
40
- export type LayoutDirectiveKind = 'badge' | 'badges' | 'button' | 'buttons' | 'callout' | 'card' | 'cards' | 'cell' | 'details' | 'grid' | 'section' | 'steps' | 'tab' | 'tabs' | 'toc';
41
- export type LayoutDirectiveRenderTagName = 'a' | 'article' | 'details' | 'div' | 'img' | 'nav' | 'section';
42
48
  export type LayoutDirectiveTransformContext = {
43
- isSupportedDirectiveName: (name: string) => name is MarkdownDirectiveName;
49
+ isSupportedDirectiveName: (name: string) => boolean;
44
50
  };
45
51
  export type LayoutDirectiveClassHelpers = {
46
52
  groupChildrenIntoCells: (children: ElementContent[], columnClassName?: string, cellTheme?: ResolvedDirectiveTheme) => ElementContent[];
@@ -65,24 +71,161 @@ export type LayoutDirectiveEditorMetadata = {
65
71
  };
66
72
  export type DirectiveValidationContext = {
67
73
  attributes: Record<string, boolean | string>;
68
- name: MarkdownDirectiveName;
74
+ name: string;
69
75
  };
70
- export type LayoutDirectiveDefinition = {
76
+ /**
77
+ * Attribute types the directive spec cannot infer. An attribute listed in
78
+ * `attributeValues` is an enum (a boolean when its values are exactly `true`
79
+ * and `false`), one listed in `themeAttributes` names a theme; everything
80
+ * else is a plain string unless declared here.
81
+ */
82
+ export type DirectiveAttributeTypeDeclaration = {
83
+ max?: number;
84
+ min?: number;
85
+ type: 'number';
86
+ } | {
87
+ type: 'boolean';
88
+ }
89
+ /** An enum the definition validates in code (its values are not offered as editor completions). */
90
+ | {
91
+ type: 'enum';
92
+ values: readonly string[];
93
+ }
94
+ /** One `@pack/name` icon ref, or a comma-separated list of entries that may add `palette=<name>`. */
95
+ | {
96
+ type: 'icon';
97
+ }
98
+ /** A palette name (built-in, configured, or managed in the admin). */
99
+ | {
100
+ type: 'palette';
101
+ }
102
+ /** A link target, protocol-checked like Markdown links. */
103
+ | {
104
+ type: 'url';
105
+ };
106
+ /**
107
+ * Element properties (hast names, per tag name) that the directive's mdast
108
+ * stage emits and rehype-sanitize must keep. The registry adds the
109
+ * directive's own `tagName` with `dataVlLayout` for directives that carry the
110
+ * layout marker, and the sanitize schema is the base allowlist plus these.
111
+ * Elements built in `applyHast` run after sanitizing and need no entry.
112
+ */
113
+ export type DirectiveSanitizeAllowlist = Readonly<Partial<Record<string, readonly string[]>>>;
114
+ /** Receives the diagnostics of a leaf builder. */
115
+ export type DirectiveMessageSink = {
116
+ message: (reason: string) => unknown;
117
+ };
118
+ /** Options of the editor linter (`lintMarkdownDirectives`). */
119
+ export type LintMarkdownDirectivesOptions = {
120
+ /**
121
+ * Configured icon pack aliases. When provided, icon refs to other packs are
122
+ * reported exactly like the renderer does ("Unknown icon pack").
123
+ */
124
+ iconPacks?: readonly string[];
125
+ /**
126
+ * Known palette names. When provided, unknown `palette` / `iconPalette`
127
+ * values and icon-entry palettes are reported like the renderer does.
128
+ */
129
+ palettes?: readonly string[];
130
+ /** Configured directive themes (names are what matters). */
131
+ themes?: MarkdownDirectiveThemes;
132
+ };
133
+ /** Close markers the directive grammar knows; see `layoutDirectiveRegistry.closeMarkers`. */
134
+ export type DirectiveCloseMarker = ':::' | ':::end' | ':::endcol' | ':::endsection';
135
+ /** The `:::name[label]{attributes}` … `:::` form. */
136
+ export type DirectiveContainerForm = {
137
+ /** Editor close-label text shown after a generic `:::` closer (default `end<name>`). */
138
+ closeLabel?: string;
139
+ /** Markers that close the directive (default `[':::']`). */
140
+ closeMarkers?: readonly DirectiveCloseMarker[];
141
+ /** Attribute that the `[label]` stands for; both given and different is reported. */
142
+ labelAttribute?: string;
143
+ };
144
+ /** The `::name[label]{attributes}` form: one line (attributes may span lines). */
145
+ export type DirectiveLeafForm = {
146
+ /**
147
+ * Builds the leaf directive node for a directive line the scanner found,
148
+ * reporting problems to `sink`. `undefined` leaves the line as text.
149
+ */
150
+ build: (line: string, sink: DirectiveMessageSink, config: MarkdownRenderConfig) => LeafDirective | undefined;
151
+ /** Editor diagnostics for the same line; must cover what `build` reports. */
152
+ lint: (line: string, options: LintMarkdownDirectivesOptions) => string[];
153
+ /**
154
+ * Give the built element the layout marker (`data-vl-layout`), so the
155
+ * definition's `applyHast` runs on it after sanitizing. Leave it off when
156
+ * `build` emits the final element.
157
+ */
158
+ marker?: boolean;
159
+ };
160
+ /** A container directive the editor linter is tracking. */
161
+ export type DirectiveLintFrame = {
162
+ from: number;
163
+ /** Something other than a directive marker was seen inside the frame. */
164
+ hasContent?: boolean;
165
+ line: number;
166
+ name: string;
167
+ /** Heading depth a grid was opened under (grids only). */
168
+ parentHeadingDepth?: number;
169
+ /** Directive-specific state owned by the definition's lint hooks. */
170
+ state?: unknown;
171
+ };
172
+ export type DirectiveLintOpenContext = {
173
+ attributes: Record<string, boolean | string>;
174
+ /** The frame being opened; hooks may set `frame.state`. */
175
+ frame: DirectiveLintFrame;
176
+ label?: string;
177
+ /** Frames open before this one, innermost last. */
178
+ stack: readonly DirectiveLintFrame[];
179
+ };
180
+ /**
181
+ * Nesting checks for the editor linter, which reads the document as a stream
182
+ * of markers. They mirror what `validateMdast` reports on the compiled tree.
183
+ */
184
+ export type DirectiveLintHooks = {
185
+ /** Diagnostics when the frame closes (explicitly, by a parent closing, or at the end). */
186
+ close?: (frame: DirectiveLintFrame) => string[];
187
+ /** Diagnostics when the directive opens. */
188
+ open?: (context: DirectiveLintOpenContext) => string[];
189
+ };
190
+ export type LayoutDirectiveDefinition<Name extends string = string, Kind extends string = string> = {
191
+ /** Attribute names, in suggestion order ("Did you mean …?" prefers earlier names). */
71
192
  allowedAttributes?: readonly string[];
72
193
  applyHast?: (node: Element, config: MarkdownRenderConfig, helpers: LayoutDirectiveClassHelpers) => void;
194
+ /** Types not implied by `attributeValues` or `themeAttributes` (see the type). */
195
+ attributeTypes?: Partial<Record<string, DirectiveAttributeTypeDeclaration>>;
196
+ /** Values the editor offers; also makes the attribute an enum (or boolean) in the spec. */
73
197
  attributeValues?: Partial<Record<string, readonly string[]>>;
198
+ /** The container form; a directive has a container form, a leaf form, or both. */
199
+ container?: DirectiveContainerForm;
74
200
  defaultAttributes?: Record<string, string>;
75
201
  description?: string;
76
202
  editor: LayoutDirectiveEditorMetadata;
77
203
  getMdastRenderProperties?: (node: ContainerDirective) => Record<string, unknown>;
78
- kind: LayoutDirectiveKind;
79
- name: MarkdownDirectiveName;
80
- openMarker?: `:::${string}`;
204
+ /** `grid`, `section` and `cell` drive layout compilation; other kinds are the name. */
205
+ kind: Kind;
206
+ /** The leaf form. */
207
+ leaf?: DirectiveLeafForm;
208
+ /** Editor-linter nesting checks (container form). */
209
+ lint?: DirectiveLintHooks;
210
+ name: Name;
81
211
  public?: boolean;
212
+ sanitize?: DirectiveSanitizeAllowlist;
82
213
  supportsAttributes?: boolean;
83
- tagName: LayoutDirectiveRenderTagName;
214
+ /** Element the directive renders as (the layout marker and `applyHast` target). */
215
+ tagName: string;
84
216
  themeAttributes?: Partial<Record<string, DirectiveThemeGroupName>>;
85
217
  transformMdast?: (node: ContainerDirective, context: LayoutDirectiveTransformContext) => void;
218
+ /**
219
+ * Extra sentence for an "Unknown theme" diagnostic, for a value that is
220
+ * likely a mix-up (a callout variant given as its theme, say).
221
+ */
222
+ unknownThemeHint?: (attribute: string, value: string) => string | undefined;
86
223
  validateAttributes?: (context: DirectiveValidationContext) => string[];
87
224
  validateMdast?: (node: ContainerDirective) => string[];
88
225
  };
226
+ /**
227
+ * Declares a directive definition. Only a typing helper: it keeps the
228
+ * literal `name` and `kind`, so the registry can derive its unions.
229
+ */
230
+ export declare function defineDirective<const Name extends string, const Kind extends string>(definition: LayoutDirectiveDefinition<Name, Kind>): LayoutDirectiveDefinition<Name, Kind>;
231
+ export {};
@@ -1,3 +1,8 @@
1
- export { };
1
+ /**
2
+ * Declares a directive definition. Only a typing helper: it keeps the
3
+ * literal `name` and `kind`, so the registry can derive its unions.
4
+ */ export function defineDirective(definition) {
5
+ return definition;
6
+ }
2
7
 
3
8
  //# sourceMappingURL=types.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/directives/types.ts"],"sourcesContent":["import type { Element, ElementContent } from 'hast'\nimport type { ContainerDirective, LeafDirective } from 'mdast-util-directive'\nimport type { Data } from 'unist'\n\nimport type { MarkdownRenderConfig } from '../types/core.js'\nimport type { DirectiveThemeGroupName, ResolvedDirectiveTheme } from './themes.js'\n\nexport type LayoutDirectiveName = '2col' | '3col' | 'cell' | 'section'\nexport type StaticDirectiveName =\n | 'badge'\n | 'badges'\n | 'button'\n | 'buttons'\n | 'callout'\n | 'card'\n | 'cards'\n | 'details'\n | 'steps'\n | 'tab'\n | 'tabs'\n | 'toc'\nexport type MarkdownDirectiveName = LayoutDirectiveName | StaticDirectiveName\nexport type GridDirectiveName = '2col' | '3col'\nexport type LayoutName = MarkdownDirectiveName\n\n/** Layout token data: `vlPlace` is the marker's 1-based source position. */\nexport type LayoutTokenData = { vlPlace?: { column: number; line: number } } & Data\n\nexport type LayoutToken =\n | {\n action: 'close'\n data?: LayoutTokenData\n type: 'vlLayoutToken'\n }\n | {\n action: 'closeGrid'\n data?: LayoutTokenData\n type: 'vlLayoutToken'\n }\n | {\n action: 'closeSection'\n data?: LayoutTokenData\n type: 'vlLayoutToken'\n }\n | {\n action: 'open'\n attributes?: Record<string, boolean | string>\n data?: LayoutTokenData\n label?: string\n name: LayoutName\n type: 'vlLayoutToken'\n }\n\nexport type DirectiveChild = ContainerDirective['children'][number]\nexport type MarkdownDirectiveNode = ContainerDirective | LeafDirective\n\nexport type LayoutDirectiveKind =\n | 'badge'\n | 'badges'\n | 'button'\n | 'buttons'\n | 'callout'\n | 'card'\n | 'cards'\n | 'cell'\n | 'details'\n | 'grid'\n | 'section'\n | 'steps'\n | 'tab'\n | 'tabs'\n | 'toc'\n\nexport type LayoutDirectiveRenderTagName =\n | 'a'\n | 'article'\n | 'details'\n | 'div'\n | 'img'\n | 'nav'\n | 'section'\n\nexport type LayoutDirectiveTransformContext = {\n isSupportedDirectiveName: (name: string) => name is MarkdownDirectiveName\n}\n\nexport type LayoutDirectiveClassHelpers = {\n groupChildrenIntoCells: (\n children: ElementContent[],\n columnClassName?: string,\n cellTheme?: ResolvedDirectiveTheme,\n ) => ElementContent[]\n mergeClassNames: (...values: Array<string | undefined>) => string[]\n /**\n * Reserves a group of element ids that must stay unique within one render\n * (CORE-20). Returns the bases unchanged when all are free; otherwise every\n * base gets the same smallest free `-n` suffix. Ids already present in the\n * tree (headings, footnotes) are pre-reserved.\n */\n reserveIds: (bases: string[]) => string[]\n}\n\nexport type LayoutDirectiveEditorMetadata = {\n detail?: string\n label: string\n snippet: string\n snippets?: Array<{\n detail?: string\n label: string\n snippet: string\n }>\n}\n\nexport type DirectiveValidationContext = {\n attributes: Record<string, boolean | string>\n name: MarkdownDirectiveName\n}\n\nexport type LayoutDirectiveDefinition = {\n allowedAttributes?: readonly string[]\n applyHast?: (\n node: Element,\n config: MarkdownRenderConfig,\n helpers: LayoutDirectiveClassHelpers,\n ) => void\n attributeValues?: Partial<Record<string, readonly string[]>>\n defaultAttributes?: Record<string, string>\n description?: string\n editor: LayoutDirectiveEditorMetadata\n getMdastRenderProperties?: (node: ContainerDirective) => Record<string, unknown>\n kind: LayoutDirectiveKind\n name: MarkdownDirectiveName\n openMarker?: `:::${string}`\n public?: boolean\n supportsAttributes?: boolean\n tagName: LayoutDirectiveRenderTagName\n themeAttributes?: Partial<Record<string, DirectiveThemeGroupName>>\n transformMdast?: (\n node: ContainerDirective,\n context: LayoutDirectiveTransformContext,\n ) => void\n validateAttributes?: (context: DirectiveValidationContext) => string[]\n validateMdast?: (node: ContainerDirective) => string[]\n}\n"],"names":[],"mappings":"AAsHA,WAyBC"}
1
+ {"version":3,"sources":["../../src/directives/types.ts"],"sourcesContent":["import type { Element, ElementContent } from 'hast'\nimport type { ContainerDirective, LeafDirective } from 'mdast-util-directive'\nimport type { Data } from 'unist'\n\nimport type { MarkdownDirectiveThemes, MarkdownRenderConfig } from '../types/core.js'\nimport type { directiveDefinitions } from './registry.js'\nimport type { DirectiveThemeGroupName, ResolvedDirectiveTheme } from './themes.js'\n\n/*\n * Directive names, kinds and tag names are derived from the registry's\n * definitions (src/directives/registry.ts): adding a definition there is what\n * makes a name valid.\n */\ntype RegisteredDefinition = (typeof directiveDefinitions)[number]\n\nexport type MarkdownDirectiveName = RegisteredDefinition['name']\nexport type LayoutDirectiveKind = RegisteredDefinition['kind']\nexport type GridDirectiveName = Extract<RegisteredDefinition, { kind: 'grid' }>['name']\n/** Structural layout directives (sections, grids and their cells). */\nexport type LayoutDirectiveName = Extract<RegisteredDefinition, { kind: 'cell' | 'grid' | 'section' }>['name']\nexport type StaticDirectiveName = Exclude<MarkdownDirectiveName, LayoutDirectiveName>\nexport type LayoutName = MarkdownDirectiveName\n\n/** Layout token data: `vlPlace` is the marker's 1-based source position. */\nexport type LayoutTokenData = { vlPlace?: { column: number; line: number } } & Data\n\nexport type LayoutToken =\n | {\n action: 'close'\n data?: LayoutTokenData\n type: 'vlLayoutToken'\n }\n | {\n action: 'closeGrid'\n data?: LayoutTokenData\n type: 'vlLayoutToken'\n }\n | {\n action: 'closeSection'\n data?: LayoutTokenData\n type: 'vlLayoutToken'\n }\n | {\n action: 'open'\n attributes?: Record<string, boolean | string>\n data?: LayoutTokenData\n label?: string\n name: LayoutName\n type: 'vlLayoutToken'\n }\n\nexport type DirectiveChild = ContainerDirective['children'][number]\nexport type MarkdownDirectiveNode = ContainerDirective | LeafDirective\n\nexport type LayoutDirectiveTransformContext = {\n isSupportedDirectiveName: (name: string) => boolean\n}\n\nexport type LayoutDirectiveClassHelpers = {\n groupChildrenIntoCells: (\n children: ElementContent[],\n columnClassName?: string,\n cellTheme?: ResolvedDirectiveTheme,\n ) => ElementContent[]\n mergeClassNames: (...values: Array<string | undefined>) => string[]\n /**\n * Reserves a group of element ids that must stay unique within one render\n * (CORE-20). Returns the bases unchanged when all are free; otherwise every\n * base gets the same smallest free `-n` suffix. Ids already present in the\n * tree (headings, footnotes) are pre-reserved.\n */\n reserveIds: (bases: string[]) => string[]\n}\n\nexport type LayoutDirectiveEditorMetadata = {\n detail?: string\n label: string\n snippet: string\n snippets?: Array<{\n detail?: string\n label: string\n snippet: string\n }>\n}\n\nexport type DirectiveValidationContext = {\n attributes: Record<string, boolean | string>\n name: string\n}\n\n/**\n * Attribute types the directive spec cannot infer. An attribute listed in\n * `attributeValues` is an enum (a boolean when its values are exactly `true`\n * and `false`), one listed in `themeAttributes` names a theme; everything\n * else is a plain string unless declared here.\n */\nexport type DirectiveAttributeTypeDeclaration =\n | { max?: number; min?: number; type: 'number' }\n | { type: 'boolean' }\n /** An enum the definition validates in code (its values are not offered as editor completions). */\n | { type: 'enum'; values: readonly string[] }\n /** One `@pack/name` icon ref, or a comma-separated list of entries that may add `palette=<name>`. */\n | { type: 'icon' }\n /** A palette name (built-in, configured, or managed in the admin). */\n | { type: 'palette' }\n /** A link target, protocol-checked like Markdown links. */\n | { type: 'url' }\n\n/**\n * Element properties (hast names, per tag name) that the directive's mdast\n * stage emits and rehype-sanitize must keep. The registry adds the\n * directive's own `tagName` with `dataVlLayout` for directives that carry the\n * layout marker, and the sanitize schema is the base allowlist plus these.\n * Elements built in `applyHast` run after sanitizing and need no entry.\n */\nexport type DirectiveSanitizeAllowlist = Readonly<Partial<Record<string, readonly string[]>>>\n\n/** Receives the diagnostics of a leaf builder. */\nexport type DirectiveMessageSink = {\n message: (reason: string) => unknown\n}\n\n/** Options of the editor linter (`lintMarkdownDirectives`). */\nexport type LintMarkdownDirectivesOptions = {\n /**\n * Configured icon pack aliases. When provided, icon refs to other packs are\n * reported exactly like the renderer does (\"Unknown icon pack\").\n */\n iconPacks?: readonly string[]\n /**\n * Known palette names. When provided, unknown `palette` / `iconPalette`\n * values and icon-entry palettes are reported like the renderer does.\n */\n palettes?: readonly string[]\n /** Configured directive themes (names are what matters). */\n themes?: MarkdownDirectiveThemes\n}\n\n/** Close markers the directive grammar knows; see `layoutDirectiveRegistry.closeMarkers`. */\nexport type DirectiveCloseMarker = ':::' | ':::end' | ':::endcol' | ':::endsection'\n\n/** The `:::name[label]{attributes}` … `:::` form. */\nexport type DirectiveContainerForm = {\n /** Editor close-label text shown after a generic `:::` closer (default `end<name>`). */\n closeLabel?: string\n /** Markers that close the directive (default `[':::']`). */\n closeMarkers?: readonly DirectiveCloseMarker[]\n /** Attribute that the `[label]` stands for; both given and different is reported. */\n labelAttribute?: string\n}\n\n/** The `::name[label]{attributes}` form: one line (attributes may span lines). */\nexport type DirectiveLeafForm = {\n /**\n * Builds the leaf directive node for a directive line the scanner found,\n * reporting problems to `sink`. `undefined` leaves the line as text.\n */\n build: (line: string, sink: DirectiveMessageSink, config: MarkdownRenderConfig) => LeafDirective | undefined\n /** Editor diagnostics for the same line; must cover what `build` reports. */\n lint: (line: string, options: LintMarkdownDirectivesOptions) => string[]\n /**\n * Give the built element the layout marker (`data-vl-layout`), so the\n * definition's `applyHast` runs on it after sanitizing. Leave it off when\n * `build` emits the final element.\n */\n marker?: boolean\n}\n\n/** A container directive the editor linter is tracking. */\nexport type DirectiveLintFrame = {\n from: number\n /** Something other than a directive marker was seen inside the frame. */\n hasContent?: boolean\n line: number\n name: string\n /** Heading depth a grid was opened under (grids only). */\n parentHeadingDepth?: number\n /** Directive-specific state owned by the definition's lint hooks. */\n state?: unknown\n}\n\nexport type DirectiveLintOpenContext = {\n attributes: Record<string, boolean | string>\n /** The frame being opened; hooks may set `frame.state`. */\n frame: DirectiveLintFrame\n label?: string\n /** Frames open before this one, innermost last. */\n stack: readonly DirectiveLintFrame[]\n}\n\n/**\n * Nesting checks for the editor linter, which reads the document as a stream\n * of markers. They mirror what `validateMdast` reports on the compiled tree.\n */\nexport type DirectiveLintHooks = {\n /** Diagnostics when the frame closes (explicitly, by a parent closing, or at the end). */\n close?: (frame: DirectiveLintFrame) => string[]\n /** Diagnostics when the directive opens. */\n open?: (context: DirectiveLintOpenContext) => string[]\n}\n\nexport type LayoutDirectiveDefinition<Name extends string = string, Kind extends string = string> = {\n /** Attribute names, in suggestion order (\"Did you mean …?\" prefers earlier names). */\n allowedAttributes?: readonly string[]\n applyHast?: (\n node: Element,\n config: MarkdownRenderConfig,\n helpers: LayoutDirectiveClassHelpers,\n ) => void\n /** Types not implied by `attributeValues` or `themeAttributes` (see the type). */\n attributeTypes?: Partial<Record<string, DirectiveAttributeTypeDeclaration>>\n /** Values the editor offers; also makes the attribute an enum (or boolean) in the spec. */\n attributeValues?: Partial<Record<string, readonly string[]>>\n /** The container form; a directive has a container form, a leaf form, or both. */\n container?: DirectiveContainerForm\n defaultAttributes?: Record<string, string>\n description?: string\n editor: LayoutDirectiveEditorMetadata\n getMdastRenderProperties?: (node: ContainerDirective) => Record<string, unknown>\n /** `grid`, `section` and `cell` drive layout compilation; other kinds are the name. */\n kind: Kind\n /** The leaf form. */\n leaf?: DirectiveLeafForm\n /** Editor-linter nesting checks (container form). */\n lint?: DirectiveLintHooks\n name: Name\n public?: boolean\n sanitize?: DirectiveSanitizeAllowlist\n supportsAttributes?: boolean\n /** Element the directive renders as (the layout marker and `applyHast` target). */\n tagName: string\n themeAttributes?: Partial<Record<string, DirectiveThemeGroupName>>\n transformMdast?: (\n node: ContainerDirective,\n context: LayoutDirectiveTransformContext,\n ) => void\n /**\n * Extra sentence for an \"Unknown theme\" diagnostic, for a value that is\n * likely a mix-up (a callout variant given as its theme, say).\n */\n unknownThemeHint?: (attribute: string, value: string) => string | undefined\n validateAttributes?: (context: DirectiveValidationContext) => string[]\n validateMdast?: (node: ContainerDirective) => string[]\n}\n\n/**\n * Declares a directive definition. Only a typing helper: it keeps the\n * literal `name` and `kind`, so the registry can derive its unions.\n */\nexport function defineDirective<const Name extends string, const Kind extends string>(\n definition: LayoutDirectiveDefinition<Name, Kind>,\n): LayoutDirectiveDefinition<Name, Kind> {\n return definition\n}\n"],"names":["defineDirective","definition"],"mappings":"AAqPA;;;CAGC,GACD,OAAO,SAASA,gBACdC,UAAiD;IAEjD,OAAOA;AACT"}
@@ -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
  } : {},