payload-markdown 1.8.1 → 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 (94) hide show
  1. package/dist/core/plugins/remarkCompileLayouts.js.map +1 -1
  2. package/dist/core/plugins/remarkDirectiveLines.d.ts +7 -5
  3. package/dist/core/plugins/remarkDirectiveLines.js +29 -18
  4. package/dist/core/plugins/remarkDirectiveLines.js.map +1 -1
  5. package/dist/core/plugins/remarkLayoutDirectives.js +1 -1
  6. package/dist/core/plugins/remarkLayoutDirectives.js.map +1 -1
  7. package/dist/core/plugins/remarkValidateDirectiveThemes.js +7 -14
  8. package/dist/core/plugins/remarkValidateDirectiveThemes.js.map +1 -1
  9. package/dist/core/renderMarkdown.js +2 -231
  10. package/dist/core/renderMarkdown.js.map +1 -1
  11. package/dist/core/sanitizeSchema.d.ts +11 -0
  12. package/dist/core/sanitizeSchema.js +176 -0
  13. package/dist/core/sanitizeSchema.js.map +1 -0
  14. package/dist/directives/definitions/badge.d.ts +5 -2
  15. package/dist/directives/definitions/badge.js +138 -10
  16. package/dist/directives/definitions/badge.js.map +1 -1
  17. package/dist/directives/definitions/badges.d.ts +1 -2
  18. package/dist/directives/definitions/badges.js +12 -3
  19. package/dist/directives/definitions/badges.js.map +1 -1
  20. package/dist/directives/definitions/button.d.ts +6 -2
  21. package/dist/directives/definitions/button.js +202 -12
  22. package/dist/directives/definitions/button.js.map +1 -1
  23. package/dist/directives/definitions/buttons.d.ts +1 -2
  24. package/dist/directives/definitions/buttons.js +12 -3
  25. package/dist/directives/definitions/buttons.js.map +1 -1
  26. package/dist/directives/definitions/callout.d.ts +1 -2
  27. package/dist/directives/definitions/callout.js +37 -3
  28. package/dist/directives/definitions/callout.js.map +1 -1
  29. package/dist/directives/definitions/card.d.ts +6 -2
  30. package/dist/directives/definitions/card.js +51 -3
  31. package/dist/directives/definitions/card.js.map +1 -1
  32. package/dist/directives/definitions/cards.d.ts +1 -2
  33. package/dist/directives/definitions/cards.js +40 -4
  34. package/dist/directives/definitions/cards.js.map +1 -1
  35. package/dist/directives/definitions/cell.d.ts +2 -2
  36. package/dist/directives/definitions/cell.js +9 -3
  37. package/dist/directives/definitions/cell.js.map +1 -1
  38. package/dist/directives/definitions/columns.d.ts +3 -4
  39. package/dist/directives/definitions/columns.js +17 -3
  40. package/dist/directives/definitions/columns.js.map +1 -1
  41. package/dist/directives/definitions/details.d.ts +1 -2
  42. package/dist/directives/definitions/details.js +24 -3
  43. package/dist/directives/definitions/details.js.map +1 -1
  44. package/dist/directives/definitions/section.d.ts +1 -2
  45. package/dist/directives/definitions/section.js +22 -3
  46. package/dist/directives/definitions/section.js.map +1 -1
  47. package/dist/directives/definitions/steps.d.ts +1 -2
  48. package/dist/directives/definitions/steps.js +22 -3
  49. package/dist/directives/definitions/steps.js.map +1 -1
  50. package/dist/directives/definitions/tab.d.ts +8 -2
  51. package/dist/directives/definitions/tab.js +45 -3
  52. package/dist/directives/definitions/tab.js.map +1 -1
  53. package/dist/directives/definitions/tabs.d.ts +1 -1
  54. package/dist/directives/definitions/tabs.js +40 -3
  55. package/dist/directives/definitions/tabs.js.map +1 -1
  56. package/dist/directives/definitions/toc.d.ts +1 -2
  57. package/dist/directives/definitions/toc.js +32 -4
  58. package/dist/directives/definitions/toc.js.map +1 -1
  59. package/dist/directives/diagnostics.d.ts +2 -15
  60. package/dist/directives/diagnostics.js +27 -157
  61. package/dist/directives/diagnostics.js.map +1 -1
  62. package/dist/directives/lint.d.ts +11 -0
  63. package/dist/directives/lint.js +33 -0
  64. package/dist/directives/lint.js.map +1 -0
  65. package/dist/directives/registry.d.ts +23 -5
  66. package/dist/directives/registry.js +52 -40
  67. package/dist/directives/registry.js.map +1 -1
  68. package/dist/directives/spec.js +25 -51
  69. package/dist/directives/spec.js.map +1 -1
  70. package/dist/directives/themeDiagnostics.d.ts +8 -0
  71. package/dist/directives/themeDiagnostics.js +21 -0
  72. package/dist/directives/themeDiagnostics.js.map +1 -0
  73. package/dist/directives/types.d.ts +157 -14
  74. package/dist/directives/types.js +6 -1
  75. package/dist/directives/types.js.map +1 -1
  76. package/dist/editor/directives/completions.js +11 -4
  77. package/dist/editor/directives/completions.js.map +1 -1
  78. package/dist/editor/themes/payload.js +2 -1
  79. package/dist/editor/themes/payload.js.map +1 -1
  80. package/dist/version.d.ts +1 -1
  81. package/dist/version.js +1 -1
  82. package/dist/version.js.map +1 -1
  83. package/package.json +1 -1
  84. package/skills/payload-markdown/claude/skill.json +1 -1
  85. package/skills/payload-markdown/codex/skill.json +1 -1
  86. package/dist/core/plugins/directiveBadge.d.ts +0 -6
  87. package/dist/core/plugins/directiveBadge.js +0 -94
  88. package/dist/core/plugins/directiveBadge.js.map +0 -1
  89. package/dist/core/plugins/directiveButton.d.ts +0 -6
  90. package/dist/core/plugins/directiveButton.js +0 -132
  91. package/dist/core/plugins/directiveButton.js.map +0 -1
  92. package/dist/directives/buttonSyntax.d.ts +0 -7
  93. package/dist/directives/buttonSyntax.js +0 -6
  94. package/dist/directives/buttonSyntax.js.map +0 -1
@@ -1,94 +0,0 @@
1
- import { parseLeafDirectiveLine } from '../../directives/leafSyntax.js';
2
- import { layoutDirectiveRegistry } from '../../directives/registry.js';
3
- import { resolveShieldsBadge } from '../../directives/shields.js';
4
- import { getSafeHref } from '../../directives/urls.js';
5
- function getAttribute(attributes, name) {
6
- const value = attributes[name];
7
- return typeof value === 'string' && value.trim() ? value.trim() : undefined;
8
- }
9
- function getBooleanAttribute(attributes, name) {
10
- const value = attributes[name];
11
- if (value === true) return true;
12
- if (typeof value !== 'string') return false;
13
- return value === 'true';
14
- }
15
- function stringifyAttributes(attributes) {
16
- return Object.fromEntries(Object.entries(attributes).map(([key, value])=>[
17
- key,
18
- String(value)
19
- ]));
20
- }
21
- function makeBadgeImageProperties(src, alt, includeDirective) {
22
- return {
23
- alt,
24
- // Badge images opt out of Typography's image margins and rounding.
25
- className: [
26
- 'not-prose',
27
- 'pmd-badge'
28
- ],
29
- ...includeDirective ? {
30
- dataDirective: 'badge'
31
- } : {},
32
- src
33
- };
34
- }
35
- export function makeBadgeDirective(line, file) {
36
- const parsed = parseLeafDirectiveLine(line, 'badge');
37
- if (!parsed) return undefined;
38
- const definition = layoutDirectiveRegistry.get('badge');
39
- const attributes = parsed.attributes;
40
- const label = parsed.label.trim();
41
- const href = getSafeHref(getAttribute(attributes, 'href'));
42
- const newTab = getBooleanAttribute(attributes, 'newTab');
43
- const alt = getAttribute(attributes, 'alt') ?? label;
44
- for (const warning of parsed.warnings)file.message(warning);
45
- for (const warning of definition?.validateAttributes?.({
46
- name: 'badge',
47
- attributes
48
- }) ?? [])file.message(warning);
49
- const resolved = resolveShieldsBadge(attributes);
50
- for (const warning of resolved.warnings)file.message(warning);
51
- if (!resolved.src) return undefined;
52
- const imgProperties = makeBadgeImageProperties(resolved.src, alt, !href);
53
- return {
54
- name: 'badge',
55
- type: 'leafDirective',
56
- attributes: stringifyAttributes(attributes),
57
- children: label ? [
58
- {
59
- type: 'text',
60
- value: label
61
- }
62
- ] : [],
63
- data: href ? {
64
- hChildren: [
65
- {
66
- type: 'element',
67
- children: [],
68
- properties: imgProperties,
69
- tagName: 'img'
70
- }
71
- ],
72
- hName: 'a',
73
- hProperties: {
74
- className: [
75
- 'pmd-badge-link'
76
- ],
77
- dataDirective: 'badge',
78
- href,
79
- ...newTab ? {
80
- rel: 'noopener noreferrer',
81
- target: '_blank'
82
- } : {}
83
- }
84
- } : {
85
- // <img> is void: the [label] is the alt text and must not also be
86
- // emitted as visible text after the image.
87
- hChildren: [],
88
- hName: 'img',
89
- hProperties: imgProperties
90
- }
91
- };
92
- }
93
-
94
- //# sourceMappingURL=directiveBadge.js.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../../../src/core/plugins/directiveBadge.ts"],"sourcesContent":["import type { LeafDirective } from 'mdast-util-directive'\n\nimport { parseLeafDirectiveLine } from '../../directives/leafSyntax.js'\nimport { layoutDirectiveRegistry } from '../../directives/registry.js'\nimport { resolveShieldsBadge } from '../../directives/shields.js'\nimport { getSafeHref } from '../../directives/urls.js'\n\ntype MessageFile = {\n message: (reason: string) => unknown\n}\n\nfunction getAttribute(attributes: Record<string, boolean | string>, name: string): string | undefined {\n const value = attributes[name]\n\n return typeof value === 'string' && value.trim() ? value.trim() : undefined\n}\n\nfunction getBooleanAttribute(attributes: Record<string, boolean | string>, name: string): boolean {\n const value = attributes[name]\n\n if (value === true) return true\n if (typeof value !== 'string') return false\n\n return value === 'true'\n}\n\nfunction stringifyAttributes(attributes: Record<string, boolean | string>): Record<string, string> {\n return Object.fromEntries(Object.entries(attributes).map(([key, value]) => [key, String(value)]))\n}\n\nfunction makeBadgeImageProperties(src: string, alt: string, includeDirective: boolean) {\n return {\n alt,\n // Badge images opt out of Typography's image margins and rounding.\n className: ['not-prose', 'pmd-badge'],\n ...(includeDirective ? { dataDirective: 'badge' } : {}),\n src,\n }\n}\n\nexport function makeBadgeDirective(line: string, file: MessageFile): LeafDirective | undefined {\n const parsed = parseLeafDirectiveLine(line, 'badge')\n if (!parsed) return undefined\n\n const definition = layoutDirectiveRegistry.get('badge')\n const attributes = parsed.attributes\n const label = parsed.label.trim()\n const href = getSafeHref(getAttribute(attributes, 'href'))\n const newTab = getBooleanAttribute(attributes, 'newTab')\n const alt = getAttribute(attributes, 'alt') ?? label\n\n for (const warning of parsed.warnings) file.message(warning)\n for (const warning of definition?.validateAttributes?.({ name: 'badge', attributes }) ?? [])\n file.message(warning)\n\n const resolved = resolveShieldsBadge(attributes)\n\n for (const warning of resolved.warnings) file.message(warning)\n if (!resolved.src) return undefined\n\n const imgProperties = makeBadgeImageProperties(resolved.src, alt, !href)\n\n return {\n name: 'badge',\n type: 'leafDirective',\n attributes: stringifyAttributes(attributes),\n children: label ? [{ type: 'text', value: label }] : [],\n data: href\n ? {\n hChildren: [\n {\n type: 'element' as const,\n children: [],\n properties: imgProperties,\n tagName: 'img',\n },\n ],\n hName: 'a',\n hProperties: {\n className: ['pmd-badge-link'],\n dataDirective: 'badge',\n href,\n ...(newTab\n ? {\n rel: 'noopener noreferrer',\n target: '_blank',\n }\n : {}),\n },\n }\n : {\n // <img> is void: the [label] is the alt text and must not also be\n // emitted as visible text after the image.\n hChildren: [],\n hName: 'img',\n hProperties: imgProperties,\n },\n }\n}\n"],"names":["parseLeafDirectiveLine","layoutDirectiveRegistry","resolveShieldsBadge","getSafeHref","getAttribute","attributes","name","value","trim","undefined","getBooleanAttribute","stringifyAttributes","Object","fromEntries","entries","map","key","String","makeBadgeImageProperties","src","alt","includeDirective","className","dataDirective","makeBadgeDirective","line","file","parsed","definition","get","label","href","newTab","warning","warnings","message","validateAttributes","resolved","imgProperties","type","children","data","hChildren","properties","tagName","hName","hProperties","rel","target"],"mappings":"AAEA,SAASA,sBAAsB,QAAQ,iCAAgC;AACvE,SAASC,uBAAuB,QAAQ,+BAA8B;AACtE,SAASC,mBAAmB,QAAQ,8BAA6B;AACjE,SAASC,WAAW,QAAQ,2BAA0B;AAMtD,SAASC,aAAaC,UAA4C,EAAEC,IAAY;IAC9E,MAAMC,QAAQF,UAAU,CAACC,KAAK;IAE9B,OAAO,OAAOC,UAAU,YAAYA,MAAMC,IAAI,KAAKD,MAAMC,IAAI,KAAKC;AACpE;AAEA,SAASC,oBAAoBL,UAA4C,EAAEC,IAAY;IACrF,MAAMC,QAAQF,UAAU,CAACC,KAAK;IAE9B,IAAIC,UAAU,MAAM,OAAO;IAC3B,IAAI,OAAOA,UAAU,UAAU,OAAO;IAEtC,OAAOA,UAAU;AACnB;AAEA,SAASI,oBAAoBN,UAA4C;IACvE,OAAOO,OAAOC,WAAW,CAACD,OAAOE,OAAO,CAACT,YAAYU,GAAG,CAAC,CAAC,CAACC,KAAKT,MAAM,GAAK;YAACS;YAAKC,OAAOV;SAAO;AACjG;AAEA,SAASW,yBAAyBC,GAAW,EAAEC,GAAW,EAAEC,gBAAyB;IACnF,OAAO;QACLD;QACA,mEAAmE;QACnEE,WAAW;YAAC;YAAa;SAAY;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ACA,CAAC,CAAC;YACR;QACF,IACA;YACE,kEAAkE;YAClE,2CAA2C;YAC3CN,WAAW,EAAE;YACbG,OAAO;YACPC,aAAaR;QACf;IACN;AACF"}
@@ -1,6 +0,0 @@
1
- import type { LeafDirective } from 'mdast-util-directive';
2
- import type { MarkdownRenderConfig } from '../../types/core.js';
3
- export type MessageFile = {
4
- message: (reason: string) => unknown;
5
- };
6
- export declare function makeButtonDirective(line: string, file: MessageFile, config: MarkdownRenderConfig): LeafDirective | undefined;
@@ -1,132 +0,0 @@
1
- import { parseButtonDirectiveLine } from '../../directives/buttonSyntax.js';
2
- import { BUTTON_ALLOWED_ATTRIBUTES, DEFAULT_BUTTON_ICON_POSITION, DEFAULT_BUTTON_SIZE, DEFAULT_BUTTON_VARIANT, isButtonIconPosition, isButtonSize, isButtonVariant } from '../../directives/definitions/button.js';
3
- import { layoutDirectiveRegistry } from '../../directives/registry.js';
4
- import { getSafeHref } from '../../directives/urls.js';
5
- import { getExtraIconWarnings, parseIconEntries } from '../../icons/entries.js';
6
- import { normalizePayloadMarkdownIconRef } from '../../icons/refs.js';
7
- import { collectPaletteNames, getUnknownPaletteWarning } from '../../palettes/diagnostics.js';
8
- function getAttribute(attributes, name) {
9
- const value = attributes[name];
10
- return typeof value === 'string' && value.trim() ? value.trim() : undefined;
11
- }
12
- function getBooleanAttribute(attributes, name) {
13
- const value = attributes[name];
14
- if (value === true) return true;
15
- if (typeof value !== 'string') return false;
16
- return value === 'true';
17
- }
18
- function makeIconPlaceholder(icon, iconPosition, palette) {
19
- const normalized = normalizePayloadMarkdownIconRef(icon);
20
- const iconKey = normalized.icon?.key ?? icon;
21
- return {
22
- type: 'element',
23
- children: [],
24
- properties: {
25
- ariaHidden: 'true',
26
- className: [
27
- 'pmd-button__icon',
28
- `pmd-button__icon--${iconPosition}`
29
- ],
30
- dataPmdIcon: iconKey,
31
- ...palette ? {
32
- dataPmdIconPalette: palette
33
- } : {},
34
- dataPmdIconRef: icon,
35
- focusable: 'false'
36
- },
37
- tagName: 'span'
38
- };
39
- }
40
- export function makeButtonDirective(line, file, config) {
41
- const parsed = parseButtonDirectiveLine(line);
42
- if (!parsed) return undefined;
43
- const definition = layoutDirectiveRegistry.get('button');
44
- const attributes = parsed.attributes;
45
- const label = parsed.label.trim();
46
- const href = getSafeHref(getAttribute(attributes, 'href'));
47
- const variant = isButtonVariant(attributes.variant) ? attributes.variant : DEFAULT_BUTTON_VARIANT;
48
- const size = isButtonSize(attributes.size) ? attributes.size : DEFAULT_BUTTON_SIZE;
49
- const iconPosition = isButtonIconPosition(attributes.iconPosition) ? attributes.iconPosition : DEFAULT_BUTTON_ICON_POSITION;
50
- // A button shows one icon; it may carry its own palette (`@pack/name palette=x`).
51
- const iconEntries = parseIconEntries(getAttribute(attributes, 'icon'));
52
- const [iconEntry] = iconEntries.entries;
53
- const icon = iconEntry?.ref;
54
- const palette = getAttribute(attributes, 'palette');
55
- const iconPalette = iconEntry?.palette ?? getAttribute(attributes, 'iconPalette') ?? palette;
56
- const ariaLabel = getAttribute(attributes, 'ariaLabel');
57
- const newTab = getBooleanAttribute(attributes, 'newTab');
58
- for (const warning of parsed.warnings)file.message(warning);
59
- for (const warning of definition?.validateAttributes?.({
60
- name: 'button',
61
- attributes
62
- }) ?? [])file.message(warning);
63
- if (icon) {
64
- const normalized = normalizePayloadMarkdownIconRef(icon);
65
- if (normalized.warning) file.message(normalized.warning);
66
- }
67
- for (const warning of [
68
- ...iconEntries.warnings,
69
- ...getExtraIconWarnings('button', iconEntries.entries)
70
- ])file.message(warning);
71
- for (const name of collectPaletteNames(BUTTON_ALLOWED_ATTRIBUTES, attributes)){
72
- const warning = getUnknownPaletteWarning(name, 'button', config);
73
- if (warning) file.message(warning);
74
- }
75
- if (!label && !ariaLabel) file.message('Icon-only button requires an ariaLabel attribute.');
76
- const hChildren = [
77
- ...icon && iconPosition === 'left' ? [
78
- makeIconPlaceholder(icon, iconPosition, iconPalette)
79
- ] : [],
80
- ...label ? [
81
- {
82
- type: 'text',
83
- value: label
84
- }
85
- ] : [],
86
- ...icon && iconPosition === 'right' ? [
87
- makeIconPlaceholder(icon, iconPosition, iconPalette)
88
- ] : []
89
- ];
90
- return {
91
- name: 'button',
92
- type: 'leafDirective',
93
- attributes: Object.fromEntries(Object.entries(attributes).map(([key, value])=>[
94
- key,
95
- String(value)
96
- ])),
97
- children: label ? [
98
- {
99
- type: 'text',
100
- value: label
101
- }
102
- ] : [],
103
- data: {
104
- hChildren,
105
- hName: 'a',
106
- hProperties: {
107
- ...ariaLabel ? {
108
- ariaLabel
109
- } : {},
110
- className: [
111
- 'pmd-button',
112
- `pmd-button--${variant}`,
113
- `pmd-button--${size}`
114
- ],
115
- dataButton: '',
116
- dataDirective: 'button',
117
- dataIconPalette: getAttribute(attributes, 'iconPalette'),
118
- dataIconPosition: icon ? iconPosition : undefined,
119
- dataPalette: palette,
120
- dataSize: size,
121
- dataVariant: variant,
122
- href,
123
- ...newTab ? {
124
- rel: 'noopener noreferrer',
125
- target: '_blank'
126
- } : {}
127
- }
128
- }
129
- };
130
- }
131
-
132
- //# sourceMappingURL=directiveButton.js.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../../../src/core/plugins/directiveButton.ts"],"sourcesContent":["import type { LeafDirective } from 'mdast-util-directive'\n\nimport type { MarkdownRenderConfig } from '../../types/core.js'\n\nimport { parseButtonDirectiveLine } from '../../directives/buttonSyntax.js'\nimport {\n BUTTON_ALLOWED_ATTRIBUTES,\n DEFAULT_BUTTON_ICON_POSITION,\n DEFAULT_BUTTON_SIZE,\n DEFAULT_BUTTON_VARIANT,\n isButtonIconPosition,\n isButtonSize,\n isButtonVariant,\n} from '../../directives/definitions/button.js'\nimport { layoutDirectiveRegistry } from '../../directives/registry.js'\nimport { getSafeHref } from '../../directives/urls.js'\nimport { getExtraIconWarnings, parseIconEntries } from '../../icons/entries.js'\nimport { normalizePayloadMarkdownIconRef } from '../../icons/refs.js'\nimport { collectPaletteNames, getUnknownPaletteWarning } from '../../palettes/diagnostics.js'\n\nexport type MessageFile = {\n message: (reason: string) => unknown\n}\n\nfunction getAttribute(attributes: Record<string, boolean | string>, name: string): string | undefined {\n const value = attributes[name]\n\n return typeof value === 'string' && value.trim() ? value.trim() : undefined\n}\n\nfunction getBooleanAttribute(attributes: Record<string, boolean | string>, name: string): boolean {\n const value = attributes[name]\n\n if (value === true) return true\n if (typeof value !== 'string') return false\n\n return value === 'true'\n}\n\nfunction makeIconPlaceholder(icon: string, iconPosition: 'left' | 'right', palette?: string) {\n const normalized = normalizePayloadMarkdownIconRef(icon)\n const iconKey = normalized.icon?.key ?? icon\n\n return {\n type: 'element' as const,\n children: [],\n properties: {\n ariaHidden: 'true',\n className: [\n 'pmd-button__icon',\n `pmd-button__icon--${iconPosition}`,\n ],\n dataPmdIcon: iconKey,\n ...(palette ? { dataPmdIconPalette: palette } : {}),\n dataPmdIconRef: icon,\n focusable: 'false',\n },\n tagName: 'span',\n }\n}\n\nexport function makeButtonDirective(\n line: string,\n file: MessageFile,\n config: MarkdownRenderConfig,\n): LeafDirective | undefined {\n const parsed = parseButtonDirectiveLine(line)\n if (!parsed) return undefined\n\n const definition = layoutDirectiveRegistry.get('button')\n const attributes = parsed.attributes\n const label = parsed.label.trim()\n const href = getSafeHref(getAttribute(attributes, 'href'))\n const variant = isButtonVariant(attributes.variant) ? attributes.variant : DEFAULT_BUTTON_VARIANT\n const size = isButtonSize(attributes.size) ? attributes.size : DEFAULT_BUTTON_SIZE\n const iconPosition = isButtonIconPosition(attributes.iconPosition)\n ? attributes.iconPosition\n : DEFAULT_BUTTON_ICON_POSITION\n // A button shows one icon; it may carry its own palette (`@pack/name palette=x`).\n const iconEntries = parseIconEntries(getAttribute(attributes, 'icon'))\n const [iconEntry] = iconEntries.entries\n const icon = iconEntry?.ref\n const palette = getAttribute(attributes, 'palette')\n const iconPalette = iconEntry?.palette ?? getAttribute(attributes, 'iconPalette') ?? palette\n const ariaLabel = getAttribute(attributes, 'ariaLabel')\n const newTab = getBooleanAttribute(attributes, 'newTab')\n\n for (const warning of parsed.warnings) file.message(warning)\n for (const warning of definition?.validateAttributes?.({ name: 'button', attributes }) ?? [])\n file.message(warning)\n\n if (icon) {\n const normalized = normalizePayloadMarkdownIconRef(icon)\n if (normalized.warning) file.message(normalized.warning)\n }\n\n for (const warning of [...iconEntries.warnings, ...getExtraIconWarnings('button', iconEntries.entries)])\n file.message(warning)\n\n for (const name of collectPaletteNames(BUTTON_ALLOWED_ATTRIBUTES, attributes)) {\n const warning = getUnknownPaletteWarning(name, 'button', config)\n if (warning) file.message(warning)\n }\n\n if (!label && !ariaLabel) file.message('Icon-only button requires an ariaLabel attribute.')\n\n const hChildren = [\n ...(icon && iconPosition === 'left' ? [makeIconPlaceholder(icon, iconPosition, iconPalette)] : []),\n ...(label\n ? [\n {\n type: 'text' as const,\n value: label,\n },\n ]\n : []),\n ...(icon && iconPosition === 'right' ? [makeIconPlaceholder(icon, iconPosition, iconPalette)] : []),\n ]\n\n return {\n name: 'button',\n type: 'leafDirective',\n attributes: Object.fromEntries(\n Object.entries(attributes).map(([key, value]) => [key, String(value)]),\n ),\n children: label ? [{ type: 'text', value: label }] : [],\n data: {\n hChildren,\n hName: 'a',\n hProperties: {\n ...(ariaLabel ? { ariaLabel } : {}),\n className: [\n 'pmd-button',\n `pmd-button--${variant}`,\n `pmd-button--${size}`,\n ],\n dataButton: '',\n dataDirective: 'button',\n dataIconPalette: getAttribute(attributes, 'iconPalette'),\n dataIconPosition: icon ? iconPosition : undefined,\n dataPalette: palette,\n dataSize: size,\n dataVariant: variant,\n href,\n ...(newTab\n ? {\n rel: 'noopener noreferrer',\n target: '_blank',\n }\n : {}),\n },\n },\n }\n}\n"],"names":["parseButtonDirectiveLine","BUTTON_ALLOWED_ATTRIBUTES","DEFAULT_BUTTON_ICON_POSITION","DEFAULT_BUTTON_SIZE","DEFAULT_BUTTON_VARIANT","isButtonIconPosition","isButtonSize","isButtonVariant","layoutDirectiveRegistry","getSafeHref","getExtraIconWarnings","parseIconEntries","normalizePayloadMarkdownIconRef","collectPaletteNames","getUnknownPaletteWarning","getAttribute","attributes","name","value","trim","undefined","getBooleanAttribute","makeIconPlaceholder","icon","iconPosition","palette","normalized","iconKey","key","type","children","properties","ariaHidden","className","dataPmdIcon","dataPmdIconPalette","dataPmdIconRef","focusable","tagName","makeButtonDirective","line","file","config","parsed","definition","get","label","href","variant","size","iconEntries","iconEntry","entries","ref","iconPalette","ariaLabel","newTab","warning","warnings","message","validateAttributes","hChildren","Object","fromEntries","map","String","data","hName","hProperties","dataButton","dataDirective","dataIconPalette","dataIconPosition","dataPalette","dataSize","dataVariant","rel","target"],"mappings":"AAIA,SAASA,wBAAwB,QAAQ,mCAAkC;AAC3E,SACEC,yBAAyB,EACzBC,4BAA4B,EAC5BC,mBAAmB,EACnBC,sBAAsB,EACtBC,oBAAoB,EACpBC,YAAY,EACZC,eAAe,QACV,yCAAwC;AAC/C,SAASC,uBAAuB,QAAQ,+BAA8B;AACtE,SAASC,WAAW,QAAQ,2BAA0B;AACtD,SAASC,oBAAoB,EAAEC,gBAAgB,QAAQ,yBAAwB;AAC/E,SAASC,+BAA+B,QAAQ,sBAAqB;AACrE,SAASC,mBAAmB,EAAEC,wBAAwB,QAAQ,gCAA+B;AAM7F,SAASC,aAAaC,UAA4C,EAAEC,IAAY;IAC9E,MAAMC,QAAQF,UAAU,CAACC,KAAK;IAE9B,OAAO,OAAOC,UAAU,YAAYA,MAAMC,IAAI,KAAKD,MAAMC,IAAI,KAAKC;AACpE;AAEA,SAASC,oBAAoBL,UAA4C,EAAEC,IAAY;IACrF,MAAMC,QAAQF,UAAU,CAACC,KAAK;IAE9B,IAAIC,UAAU,MAAM,OAAO;IAC3B,IAAI,OAAOA,UAAU,UAAU,OAAO;IAEtC,OAAOA,UAAU;AACnB;AAEA,SAASI,oBAAoBC,IAAY,EAAEC,YAA8B,EAAEC,OAAgB;IACzF,MAAMC,aAAad,gCAAgCW;IACnD,MAAMI,UAAUD,WAAWH,I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BACDoB,YAAY;gBACZC,eAAe;gBACfC,iBAAiBxD,aAAaC,YAAY;gBAC1CwD,kBAAkBjD,OAAOC,eAAeJ;gBACxCqD,aAAahD;gBACbiD,UAAUzB;gBACV0B,aAAa3B;gBACbD;gBACA,GAAIS,SACA;oBACEoB,KAAK;oBACLC,QAAQ;gBACV,IACA,CAAC,CAAC;YACR;QACF;IACF;AACF"}
@@ -1,7 +0,0 @@
1
- import type { DirectiveAttributes } from './attributes.js';
2
- export type ParsedButtonDirectiveLine = {
3
- attributes: DirectiveAttributes;
4
- label: string;
5
- warnings: string[];
6
- };
7
- export declare function parseButtonDirectiveLine(text: string): null | ParsedButtonDirectiveLine;
@@ -1,6 +0,0 @@
1
- import { parseLeafDirectiveLine } from './leafSyntax.js';
2
- export function parseButtonDirectiveLine(text) {
3
- return parseLeafDirectiveLine(text, 'button');
4
- }
5
-
6
- //# sourceMappingURL=buttonSyntax.js.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../../src/directives/buttonSyntax.ts"],"sourcesContent":["import type { DirectiveAttributes } from './attributes.js'\n\nimport { parseLeafDirectiveLine } from './leafSyntax.js'\n\nexport type ParsedButtonDirectiveLine = {\n attributes: DirectiveAttributes\n label: string\n warnings: string[]\n}\n\nexport function parseButtonDirectiveLine(text: string): null | ParsedButtonDirectiveLine {\n return parseLeafDirectiveLine(text, 'button')\n}\n"],"names":["parseLeafDirectiveLine","parseButtonDirectiveLine","text"],"mappings":"AAEA,SAASA,sBAAsB,QAAQ,kBAAiB;AAQxD,OAAO,SAASC,yBAAyBC,IAAY;IACnD,OAAOF,uBAAuBE,MAAM;AACtC"}