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.
- package/README.md +16 -0
- package/dist/agent/access.d.ts +1 -1
- package/dist/agent/access.js.map +1 -1
- package/dist/agent/guide.d.ts +3 -0
- package/dist/agent/guide.js +28 -2
- package/dist/agent/guide.js.map +1 -1
- package/dist/agent/palettes.d.ts +55 -0
- package/dist/agent/palettes.js +194 -0
- package/dist/agent/palettes.js.map +1 -0
- package/dist/agent/skill.d.ts +2 -2
- package/dist/agent/skill.js +2 -2
- package/dist/agent/skill.js.map +1 -1
- package/dist/agent/validate.d.ts +1 -1
- package/dist/agent/validate.js +3 -0
- package/dist/agent/validate.js.map +1 -1
- package/dist/appearance/PaletteRowLabel.client.d.ts +2 -0
- package/dist/appearance/PaletteRowLabel.client.js +70 -0
- package/dist/appearance/PaletteRowLabel.client.js.map +1 -0
- package/dist/appearance/config.d.ts +8 -0
- package/dist/appearance/config.js +172 -0
- package/dist/appearance/config.js.map +1 -0
- package/dist/appearance/options.d.ts +11 -0
- package/dist/appearance/options.js +15 -0
- package/dist/appearance/options.js.map +1 -0
- package/dist/appearance/runtime.d.ts +25 -0
- package/dist/appearance/runtime.js +126 -0
- package/dist/appearance/runtime.js.map +1 -0
- package/dist/components/MarkdownRenderer/Component.js +4 -0
- package/dist/components/MarkdownRenderer/Component.js.map +1 -1
- package/dist/core/plugins/rehypeResolveIcons.js +10 -1
- package/dist/core/plugins/rehypeResolveIcons.js.map +1 -1
- package/dist/core/plugins/remarkCompileLayouts.js.map +1 -1
- package/dist/core/plugins/remarkDirectiveLines.d.ts +7 -5
- package/dist/core/plugins/remarkDirectiveLines.js +29 -18
- package/dist/core/plugins/remarkDirectiveLines.js.map +1 -1
- package/dist/core/plugins/remarkLayoutDirectives.js +1 -1
- package/dist/core/plugins/remarkLayoutDirectives.js.map +1 -1
- package/dist/core/plugins/remarkValidateDirectiveThemes.js +7 -14
- package/dist/core/plugins/remarkValidateDirectiveThemes.js.map +1 -1
- package/dist/core/plugins/remarkValidatePalettes.d.ts +9 -0
- package/dist/core/plugins/remarkValidatePalettes.js +51 -0
- package/dist/core/plugins/remarkValidatePalettes.js.map +1 -0
- package/dist/core/renderMarkdown.js +4 -221
- package/dist/core/renderMarkdown.js.map +1 -1
- package/dist/core/sanitizeSchema.d.ts +11 -0
- package/dist/core/sanitizeSchema.js +176 -0
- package/dist/core/sanitizeSchema.js.map +1 -0
- package/dist/directive-spec.json +60 -0
- package/dist/directives/definitions/badge.d.ts +5 -2
- package/dist/directives/definitions/badge.js +138 -10
- package/dist/directives/definitions/badge.js.map +1 -1
- package/dist/directives/definitions/badges.d.ts +1 -2
- package/dist/directives/definitions/badges.js +12 -3
- package/dist/directives/definitions/badges.js.map +1 -1
- package/dist/directives/definitions/button.d.ts +7 -3
- package/dist/directives/definitions/button.js +211 -14
- package/dist/directives/definitions/button.js.map +1 -1
- package/dist/directives/definitions/buttons.d.ts +1 -2
- package/dist/directives/definitions/buttons.js +12 -3
- package/dist/directives/definitions/buttons.js.map +1 -1
- package/dist/directives/definitions/callout.d.ts +1 -2
- package/dist/directives/definitions/callout.js +46 -5
- package/dist/directives/definitions/callout.js.map +1 -1
- package/dist/directives/definitions/card.d.ts +6 -4
- package/dist/directives/definitions/card.js +64 -11
- package/dist/directives/definitions/card.js.map +1 -1
- package/dist/directives/definitions/cards.d.ts +1 -2
- package/dist/directives/definitions/cards.js +49 -4
- package/dist/directives/definitions/cards.js.map +1 -1
- package/dist/directives/definitions/cell.d.ts +2 -2
- package/dist/directives/definitions/cell.js +9 -3
- package/dist/directives/definitions/cell.js.map +1 -1
- package/dist/directives/definitions/columns.d.ts +3 -4
- package/dist/directives/definitions/columns.js +17 -3
- package/dist/directives/definitions/columns.js.map +1 -1
- package/dist/directives/definitions/details.d.ts +1 -2
- package/dist/directives/definitions/details.js +28 -3
- package/dist/directives/definitions/details.js.map +1 -1
- package/dist/directives/definitions/section.d.ts +1 -2
- package/dist/directives/definitions/section.js +26 -3
- package/dist/directives/definitions/section.js.map +1 -1
- package/dist/directives/definitions/steps.d.ts +1 -2
- package/dist/directives/definitions/steps.js +26 -3
- package/dist/directives/definitions/steps.js.map +1 -1
- package/dist/directives/definitions/tab.d.ts +8 -2
- package/dist/directives/definitions/tab.js +45 -3
- package/dist/directives/definitions/tab.js.map +1 -1
- package/dist/directives/definitions/tabs.d.ts +1 -1
- package/dist/directives/definitions/tabs.js +44 -3
- package/dist/directives/definitions/tabs.js.map +1 -1
- package/dist/directives/definitions/toc.d.ts +1 -2
- package/dist/directives/definitions/toc.js +33 -5
- package/dist/directives/definitions/toc.js.map +1 -1
- package/dist/directives/diagnostics.d.ts +2 -10
- package/dist/directives/diagnostics.js +27 -141
- package/dist/directives/diagnostics.js.map +1 -1
- package/dist/directives/iconPlaceholder.d.ts +9 -3
- package/dist/directives/iconPlaceholder.js +8 -1
- package/dist/directives/iconPlaceholder.js.map +1 -1
- package/dist/directives/lint.d.ts +11 -0
- package/dist/directives/lint.js +33 -0
- package/dist/directives/lint.js.map +1 -0
- package/dist/directives/palette.d.ts +23 -0
- package/dist/directives/palette.js +40 -0
- package/dist/directives/palette.js.map +1 -0
- package/dist/directives/registry.d.ts +23 -5
- package/dist/directives/registry.js +52 -40
- package/dist/directives/registry.js.map +1 -1
- package/dist/directives/spec.d.ts +6 -2
- package/dist/directives/spec.js +29 -50
- package/dist/directives/spec.js.map +1 -1
- package/dist/directives/themeDiagnostics.d.ts +8 -0
- package/dist/directives/themeDiagnostics.js +21 -0
- package/dist/directives/themeDiagnostics.js.map +1 -0
- package/dist/directives/types.d.ts +157 -14
- package/dist/directives/types.js +6 -1
- package/dist/directives/types.js.map +1 -1
- package/dist/editor/directiveConfig.d.ts +15 -1
- package/dist/editor/directiveConfig.js +21 -1
- package/dist/editor/directiveConfig.js.map +1 -1
- package/dist/editor/directives/completions.d.ts +4 -2
- package/dist/editor/directives/completions.js +33 -7
- package/dist/editor/directives/completions.js.map +1 -1
- package/dist/editor/directives/diagnostics.d.ts +2 -2
- package/dist/editor/directives/diagnostics.js +10 -3
- package/dist/editor/directives/diagnostics.js.map +1 -1
- package/dist/editor/themes/payload.js +2 -1
- package/dist/editor/themes/payload.js.map +1 -1
- package/dist/exports/client.d.ts +4 -1
- package/dist/exports/client.js +5 -2
- package/dist/exports/client.js.map +1 -1
- package/dist/field/MarkdownField/Component.js +54 -3
- package/dist/field/MarkdownField/Component.js.map +1 -1
- package/dist/icons/entries.d.ts +22 -0
- package/dist/icons/entries.js +50 -0
- package/dist/icons/entries.js.map +1 -0
- package/dist/icons/resolve.d.ts +2 -1
- package/dist/icons/resolve.js +2 -2
- package/dist/icons/resolve.js.map +1 -1
- package/dist/icons/sanitizeSvg.d.ts +12 -2
- package/dist/icons/sanitizeSvg.js +104 -3
- package/dist/icons/sanitizeSvg.js.map +1 -1
- package/dist/index.d.ts +11 -4
- package/dist/index.js +34 -3
- package/dist/index.js.map +1 -1
- package/dist/mcp/index.d.ts +2 -2
- package/dist/mcp/index.js +65 -4
- package/dist/mcp/index.js.map +1 -1
- package/dist/palettes/colors.d.ts +21 -0
- package/dist/palettes/colors.js +43 -0
- package/dist/palettes/colors.js.map +1 -0
- package/dist/palettes/contrast.d.ts +7 -0
- package/dist/palettes/contrast.js +63 -0
- package/dist/palettes/contrast.js.map +1 -0
- package/dist/palettes/defaults.d.ts +8 -0
- package/dist/palettes/defaults.js +275 -0
- package/dist/palettes/defaults.js.map +1 -0
- package/dist/palettes/diagnostics.d.ts +10 -0
- package/dist/palettes/diagnostics.js +38 -0
- package/dist/palettes/diagnostics.js.map +1 -0
- package/dist/palettes/index.d.ts +61 -0
- package/dist/palettes/index.js +246 -0
- package/dist/palettes/index.js.map +1 -0
- package/dist/render/renderMarkdown.d.ts +3 -1
- package/dist/render/renderMarkdown.js +9 -1
- package/dist/render/renderMarkdown.js.map +1 -1
- package/dist/runtime/index.d.ts +12 -1
- package/dist/runtime/index.js +21 -2
- package/dist/runtime/index.js.map +1 -1
- package/dist/types/core.d.ts +43 -0
- package/dist/types/core.js.map +1 -1
- package/dist/types.d.ts +46 -2
- package/dist/types.js.map +1 -1
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/dist/version.js.map +1 -1
- package/package.json +1 -1
- package/skills/payload-markdown/claude/SKILL.md +1 -0
- package/skills/payload-markdown/claude/reference/directive-spec.json +60 -0
- package/skills/payload-markdown/claude/reference/mcp-content-workflow.md +7 -0
- package/skills/payload-markdown/claude/reference/payload-markdown-directives.md +22 -2
- package/skills/payload-markdown/claude/skill.json +2 -2
- package/skills/payload-markdown/codex/SKILL.md +1 -0
- package/skills/payload-markdown/codex/reference/directive-spec.json +60 -0
- package/skills/payload-markdown/codex/reference/mcp-content-workflow.md +7 -0
- package/skills/payload-markdown/codex/reference/payload-markdown-directives.md +22 -2
- package/skills/payload-markdown/codex/skill.json +2 -2
- package/dist/core/plugins/directiveBadge.d.ts +0 -6
- package/dist/core/plugins/directiveBadge.js +0 -94
- package/dist/core/plugins/directiveBadge.js.map +0 -1
- package/dist/core/plugins/directiveButton.d.ts +0 -6
- package/dist/core/plugins/directiveButton.js +0 -115
- package/dist/core/plugins/directiveButton.js.map +0 -1
- package/dist/directives/buttonSyntax.d.ts +0 -7
- package/dist/directives/buttonSyntax.js +0 -6
- package/dist/directives/buttonSyntax.js.map +0 -1
|
@@ -1,10 +1,12 @@
|
|
|
1
|
-
import type { LayoutDirectiveDefinition } from '../types.js';
|
|
2
1
|
export declare const CARD_BODY_CLASS_NAMES: string;
|
|
3
2
|
export declare const CARD_TITLE_CLASS_NAMES = "not-prose mb-3 text-lg font-semibold tracking-tight text-(--tw-prose-headings)";
|
|
4
3
|
export declare const CARD_LINK_SCOPES: readonly ["full", "title"];
|
|
5
4
|
export declare const DEFAULT_CARD_LINK_SCOPE = "full";
|
|
6
5
|
export type CardLinkScope = (typeof CARD_LINK_SCOPES)[number];
|
|
6
|
+
/** Editor-linter state of an open `cards` frame (set by the `cards` lint hook). */
|
|
7
|
+
export type CardsLintState = {
|
|
8
|
+
hasHref: boolean;
|
|
9
|
+
linkScope?: string;
|
|
10
|
+
};
|
|
7
11
|
export declare function isCardLinkScope(value: unknown): value is CardLinkScope;
|
|
8
|
-
|
|
9
|
-
export declare function parseCardIcons(value: string | undefined): string[];
|
|
10
|
-
export declare const cardDirective: LayoutDirectiveDefinition;
|
|
12
|
+
export declare const cardDirective: import("../types.js").LayoutDirectiveDefinition<"card", "card">;
|
|
@@ -1,7 +1,11 @@
|
|
|
1
|
+
import { parseIconEntries } from '../../icons/entries.js';
|
|
1
2
|
import { DIRECTIVE_BODY_CLASS } from '../../styles/directiveSurface.js';
|
|
2
3
|
import { makeDirectiveIconPlaceholder } from '../iconPlaceholder.js';
|
|
3
4
|
import { getDirectiveLabelOrAttribute } from '../labels.js';
|
|
5
|
+
import { findNearestLintFrame } from '../lint.js';
|
|
6
|
+
import { applyDirectivePalette, getPaletteRenderProperties, PALETTE_ATTRIBUTES, resolveIconPaletteName } from '../palette.js';
|
|
4
7
|
import { resolveDirectiveTheme } from '../themes.js';
|
|
8
|
+
import { defineDirective } from '../types.js';
|
|
5
9
|
import { getSafeHref, getUnsafeHrefWarnings } from '../urls.js';
|
|
6
10
|
export const CARD_BODY_CLASS_NAMES = DIRECTIVE_BODY_CLASS;
|
|
7
11
|
export const CARD_TITLE_CLASS_NAMES = 'not-prose mb-3 text-lg font-semibold tracking-tight text-(--tw-prose-headings)';
|
|
@@ -11,6 +15,11 @@ export const CARD_LINK_SCOPES = [
|
|
|
11
15
|
'title'
|
|
12
16
|
];
|
|
13
17
|
export const DEFAULT_CARD_LINK_SCOPE = 'full';
|
|
18
|
+
const CARD_LINK_OVERRIDE_ATTRIBUTES = [
|
|
19
|
+
'href',
|
|
20
|
+
'linkScope',
|
|
21
|
+
'newTab'
|
|
22
|
+
];
|
|
14
23
|
export function isCardLinkScope(value) {
|
|
15
24
|
return typeof value === 'string' && CARD_LINK_SCOPES.includes(value);
|
|
16
25
|
}
|
|
@@ -93,15 +102,15 @@ function makeFullCardLink(href, title, newTab) {
|
|
|
93
102
|
tagName: 'a'
|
|
94
103
|
};
|
|
95
104
|
}
|
|
96
|
-
/**
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
function makeIcons(icons, hasEyebrow) {
|
|
105
|
+
/**
|
|
106
|
+
* `icon` takes one icon or a comma-separated list; each entry may carry its
|
|
107
|
+
* own palette (`@fa-brands/debian palette=debian`, see icons/entries.ts).
|
|
108
|
+
*/ function makeIcons(card, icons, hasEyebrow) {
|
|
100
109
|
return {
|
|
101
110
|
type: 'element',
|
|
102
|
-
children: icons.map((icon)=>makeDirectiveIconPlaceholder(icon, [
|
|
111
|
+
children: icons.map((icon)=>makeDirectiveIconPlaceholder(icon.ref, [
|
|
103
112
|
'pmd-card__icon inline-flex size-5 text-current'
|
|
104
|
-
])),
|
|
113
|
+
], resolveIconPaletteName(card, icon))),
|
|
105
114
|
properties: {
|
|
106
115
|
className: [
|
|
107
116
|
'not-prose pmd-card__icons mb-3 flex flex-wrap items-center gap-2',
|
|
@@ -134,7 +143,7 @@ function makeEyebrow(eyebrow) {
|
|
|
134
143
|
tagName: 'p'
|
|
135
144
|
};
|
|
136
145
|
}
|
|
137
|
-
export const cardDirective = {
|
|
146
|
+
export const cardDirective = defineDirective({
|
|
138
147
|
name: 'card',
|
|
139
148
|
allowedAttributes: [
|
|
140
149
|
'eyebrow',
|
|
@@ -142,6 +151,7 @@ export const cardDirective = {
|
|
|
142
151
|
'icon',
|
|
143
152
|
'linkScope',
|
|
144
153
|
'newTab',
|
|
154
|
+
...PALETTE_ATTRIBUTES,
|
|
145
155
|
'theme',
|
|
146
156
|
'title'
|
|
147
157
|
],
|
|
@@ -153,7 +163,7 @@ export const cardDirective = {
|
|
|
153
163
|
const linkScope = typeof node.properties.dataLinkScope === 'string' && isCardLinkScope(node.properties.dataLinkScope) ? node.properties.dataLinkScope : DEFAULT_CARD_LINK_SCOPE;
|
|
154
164
|
const newTab = node.properties.dataNewTab === 'true';
|
|
155
165
|
const eyebrow = typeof node.properties.dataEyebrow === 'string' ? node.properties.dataEyebrow : undefined;
|
|
156
|
-
const icons =
|
|
166
|
+
const { entries: icons } = parseIconEntries(typeof node.properties.dataIcon === 'string' ? node.properties.dataIcon : undefined);
|
|
157
167
|
const theme = resolveDirectiveTheme('card', typeof node.properties.dataTheme === 'string' ? node.properties.dataTheme : undefined, config.themes);
|
|
158
168
|
const children = node.children;
|
|
159
169
|
node.properties.dataTheme = theme.name;
|
|
@@ -162,6 +172,7 @@ export const cardDirective = {
|
|
|
162
172
|
node.properties.dataNewTab = newTab ? 'true' : 'false';
|
|
163
173
|
}
|
|
164
174
|
node.properties.className = mergeClassNames('my-6', href && linkScope === 'full' ? 'relative cursor-pointer transition-colors hover:border-[color:color-mix(in_oklab,rgb(255_255_255/0.15)_calc(var(--pmd-scheme-dark,1)*100%),rgb(0_0_0/0.2))] [&>[data-directive-title]]:transition-colors hover:[&>[data-directive-title]]:text-[color:var(--pmd-accent-hover,color-mix(in_oklab,#67e8f9_calc(var(--pmd-scheme-dark,1)*100%),#155e75))] [&_a:not([data-directive-link])]:relative [&_a:not([data-directive-link])]:z-20' : undefined, theme.hookClassName, theme.modifierClassName, theme.classes);
|
|
175
|
+
applyDirectivePalette(node, config);
|
|
165
176
|
node.children = [
|
|
166
177
|
...href && linkScope === 'full' ? [
|
|
167
178
|
makeFullCardLink(href, title, newTab)
|
|
@@ -170,7 +181,7 @@ export const cardDirective = {
|
|
|
170
181
|
makeEyebrow(eyebrow)
|
|
171
182
|
] : [],
|
|
172
183
|
...icons.length > 0 ? [
|
|
173
|
-
makeIcons(icons, Boolean(eyebrow))
|
|
184
|
+
makeIcons(node, icons, Boolean(eyebrow))
|
|
174
185
|
] : [],
|
|
175
186
|
...title ? [
|
|
176
187
|
makeTitle(title, href && linkScope === 'title' ? href : undefined, newTab)
|
|
@@ -188,6 +199,20 @@ export const cardDirective = {
|
|
|
188
199
|
}
|
|
189
200
|
];
|
|
190
201
|
},
|
|
202
|
+
attributeTypes: {
|
|
203
|
+
href: {
|
|
204
|
+
type: 'url'
|
|
205
|
+
},
|
|
206
|
+
icon: {
|
|
207
|
+
type: 'icon'
|
|
208
|
+
},
|
|
209
|
+
iconPalette: {
|
|
210
|
+
type: 'palette'
|
|
211
|
+
},
|
|
212
|
+
palette: {
|
|
213
|
+
type: 'palette'
|
|
214
|
+
}
|
|
215
|
+
},
|
|
191
216
|
attributeValues: {
|
|
192
217
|
linkScope: CARD_LINK_SCOPES,
|
|
193
218
|
newTab: [
|
|
@@ -195,6 +220,9 @@ export const cardDirective = {
|
|
|
195
220
|
'false'
|
|
196
221
|
]
|
|
197
222
|
},
|
|
223
|
+
container: {
|
|
224
|
+
labelAttribute: 'title'
|
|
225
|
+
},
|
|
198
226
|
defaultAttributes: {
|
|
199
227
|
linkScope: DEFAULT_CARD_LINK_SCOPE,
|
|
200
228
|
newTab: 'false'
|
|
@@ -211,6 +239,7 @@ export const cardDirective = {
|
|
|
211
239
|
dataEyebrow: getAttribute(node, 'eyebrow'),
|
|
212
240
|
dataHref: getSafeHref(getAttribute(node, 'href')),
|
|
213
241
|
dataIcon: getAttribute(node, 'icon'),
|
|
242
|
+
...getPaletteRenderProperties(node),
|
|
214
243
|
dataLinkScope: getLinkScope(node),
|
|
215
244
|
dataNewTab: 'newTab' in (node.attributes ?? {}) ? getBooleanAttribute(node, 'newTab') ? 'true' : 'false' : undefined,
|
|
216
245
|
dataTheme: getAttribute(node, 'theme'),
|
|
@@ -218,8 +247,32 @@ export const cardDirective = {
|
|
|
218
247
|
};
|
|
219
248
|
},
|
|
220
249
|
kind: 'card',
|
|
221
|
-
|
|
250
|
+
lint: {
|
|
251
|
+
// Mirrors cards' validateMdast: a section-linked grid ignores card link overrides.
|
|
252
|
+
open ({ attributes, stack }) {
|
|
253
|
+
const cards = findNearestLintFrame(stack, 'cards')?.state;
|
|
254
|
+
const sectionLink = cards?.hasHref && (cards.linkScope === undefined || cards.linkScope === 'section');
|
|
255
|
+
const overrides = CARD_LINK_OVERRIDE_ATTRIBUTES.some((name)=>Object.prototype.hasOwnProperty.call(attributes, name));
|
|
256
|
+
return sectionLink && overrides ? [
|
|
257
|
+
'Directive "cards" with linkScope="section" ignores child "card" link overrides.'
|
|
258
|
+
] : [];
|
|
259
|
+
}
|
|
260
|
+
},
|
|
222
261
|
public: true,
|
|
262
|
+
sanitize: {
|
|
263
|
+
article: [
|
|
264
|
+
'dataDirective',
|
|
265
|
+
'dataEyebrow',
|
|
266
|
+
'dataHref',
|
|
267
|
+
'dataIcon',
|
|
268
|
+
'dataIconPalette',
|
|
269
|
+
'dataLinkScope',
|
|
270
|
+
'dataNewTab',
|
|
271
|
+
'dataPalette',
|
|
272
|
+
'dataTheme',
|
|
273
|
+
'dataTitle'
|
|
274
|
+
]
|
|
275
|
+
},
|
|
223
276
|
supportsAttributes: true,
|
|
224
277
|
tagName: 'article',
|
|
225
278
|
themeAttributes: {
|
|
@@ -232,6 +285,6 @@ export const cardDirective = {
|
|
|
232
285
|
if (typeof attributes.linkScope === 'string' && !isCardLinkScope(attributes.linkScope)) warnings.push(`Invalid card linkScope "${attributes.linkScope}". Falling back to "${DEFAULT_CARD_LINK_SCOPE}".`);
|
|
233
286
|
return warnings;
|
|
234
287
|
}
|
|
235
|
-
};
|
|
288
|
+
});
|
|
236
289
|
|
|
237
290
|
//# sourceMappingURL=card.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/directives/definitions/card.ts"],"sourcesContent":["import type { Element, ElementContent } from 'hast'\nimport type { ContainerDirective } from 'mdast-util-directive'\n\nimport type { LayoutDirectiveDefinition } from '../types.js'\n\nimport { DIRECTIVE_BODY_CLASS } from '../../styles/directiveSurface.js'\nimport { makeDirectiveIconPlaceholder } from '../iconPlaceholder.js'\nimport { getDirectiveLabelOrAttribute } from '../labels.js'\nimport { resolveDirectiveTheme } from '../themes.js'\nimport { getSafeHref, getUnsafeHrefWarnings } from '../urls.js'\n\nexport const CARD_BODY_CLASS_NAMES = DIRECTIVE_BODY_CLASS\nexport const CARD_TITLE_CLASS_NAMES =\n 'not-prose mb-3 text-lg font-semibold tracking-tight text-(--tw-prose-headings)'\nconst CARD_TITLE_LINK_CLASS_NAMES =\n 'rounded-sm transition-colors hover:text-[color:var(--pmd-accent-hover,color-mix(in_oklab,#67e8f9_calc(var(--pmd-scheme-dark,1)*100%),#155e75))] focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-[color:var(--pmd-accent,color-mix(in_oklab,#22d3ee_calc(var(--pmd-scheme-dark,1)*100%),#0e7490))]'\nexport const CARD_LINK_SCOPES = ['full', 'title'] as const\nexport const DEFAULT_CARD_LINK_SCOPE = 'full'\n\nexport type CardLinkScope = (typeof CARD_LINK_SCOPES)[number]\n\nexport function isCardLinkScope(value: unknown): value is CardLinkScope {\n return typeof value === 'string' && CARD_LINK_SCOPES.includes(value as CardLinkScope)\n}\n\nfunction getAttribute(node: ContainerDirective, name: string): string | undefined {\n const value = node.attributes?.[name]\n\n return typeof value === 'string' && value.trim() ? value.trim() : undefined\n}\n\nfunction getBooleanAttribute(node: ContainerDirective, name: string): boolean {\n const attributes = node.attributes as\n | null\n | Record<string, boolean | null | string | undefined>\n | undefined\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 getLinkScope(node: ContainerDirective): CardLinkScope | undefined {\n const value = node.attributes?.linkScope\n\n if (typeof value !== 'string') return undefined\n\n return isCardLinkScope(value) ? value : DEFAULT_CARD_LINK_SCOPE\n}\n\nfunction getLinkProperties(href: string, newTab: boolean): Element['properties'] {\n return {\n href,\n ...(newTab\n ? {\n rel: ['noopener', 'noreferrer'],\n target: '_blank',\n }\n : {}),\n }\n}\n\nfunction makeTitle(title: string, href?: string, newTab = false): Element {\n const children: ElementContent[] = href\n ? [\n {\n type: 'element',\n children: [{ type: 'text', value: title }],\n properties: { ...getLinkProperties(href, newTab), className: [CARD_TITLE_LINK_CLASS_NAMES] },\n tagName: 'a',\n },\n ]\n : [{ type: 'text', value: title }]\n\n return {\n type: 'element',\n children,\n properties: {\n className: [CARD_TITLE_CLASS_NAMES],\n dataDirectiveTitle: 'card',\n },\n tagName: 'h3',\n }\n}\n\nfunction makeFullCardLink(href: string, title: string | undefined, newTab: boolean): Element {\n return {\n type: 'element',\n children: [],\n properties: {\n ...getLinkProperties(href, newTab),\n ariaLabel: title ? `Open ${title}` : 'Open card',\n className: [\n 'not-prose absolute inset-0 z-10 rounded-[inherit] focus:outline-none focus-visible:ring-2 focus-visible:ring-[color:var(--pmd-accent,color-mix(in_oklab,#22d3ee_calc(var(--pmd-scheme-dark,1)*100%),#0e7490))]',\n ],\n dataDirectiveLink: 'card',\n },\n tagName: 'a',\n }\n}\n\n/** `icon` takes one icon ref or a comma-separated list (`@fa/debian, @fa/ubuntu`). */\nexport function parseCardIcons(value: string | undefined): string[] {\n return value?.split(',').map((icon) => icon.trim()).filter(Boolean) ?? []\n}\n\nfunction makeIcons(icons: string[], hasEyebrow: boolean): Element {\n return {\n type: 'element',\n children: icons.map((icon) =>\n makeDirectiveIconPlaceholder(icon, ['pmd-card__icon inline-flex size-5 text-current']),\n ),\n properties: {\n className: [\n 'not-prose pmd-card__icons mb-3 flex flex-wrap items-center gap-2',\n // Clear of the eyebrow; its mb-2 collapses into this margin.\n ...(hasEyebrow ? ['mt-4'] : []),\n ],\n },\n tagName: 'div',\n }\n}\n\nfunction makeEyebrow(eyebrow: string): Element {\n return {\n type: 'element',\n children: [{ type: 'text', value: eyebrow }],\n properties: {\n // Muted relative to the body text rather than a fixed grey, so small\n // uppercase labels keep AA contrast on tinted or custom surfaces.\n className: ['not-prose mb-2 text-xs font-semibold uppercase tracking-[0.18em] text-(--tw-prose-body)/80'],\n dataDirectiveEyebrow: 'card',\n },\n tagName: 'p',\n }\n}\n\nexport const cardDirective: LayoutDirectiveDefinition = {\n name: 'card',\n allowedAttributes: ['eyebrow', 'href', 'icon', 'linkScope', 'newTab', 'theme', 'title'],\n applyHast(node, config, { mergeClassNames }) {\n const title = typeof node.properties.dataTitle === 'string' ? node.properties.dataTitle : undefined\n // Re-validate at the hast stage: this is where the live <a href> is built.\n const href = getSafeHref(node.properties.dataHref)\n if (!href) delete node.properties.dataHref\n const linkScope =\n typeof node.properties.dataLinkScope === 'string' && isCardLinkScope(node.properties.dataLinkScope)\n ? node.properties.dataLinkScope\n : DEFAULT_CARD_LINK_SCOPE\n const newTab = node.properties.dataNewTab === 'true'\n const eyebrow =\n typeof node.properties.dataEyebrow === 'string' ? node.properties.dataEyebrow : undefined\n const icons = parseCardIcons(\n typeof node.properties.dataIcon === 'string' ? node.properties.dataIcon : undefined,\n )\n const theme = resolveDirectiveTheme(\n 'card',\n typeof node.properties.dataTheme === 'string' ? node.properties.dataTheme : undefined,\n config.themes,\n )\n const children = node.children\n\n node.properties.dataTheme = theme.name\n if (href) {\n node.properties.dataLinkScope = linkScope\n node.properties.dataNewTab = newTab ? 'true' : 'false'\n }\n node.properties.className = mergeClassNames(\n 'my-6',\n href && linkScope === 'full'\n ? 'relative cursor-pointer transition-colors hover:border-[color:color-mix(in_oklab,rgb(255_255_255/0.15)_calc(var(--pmd-scheme-dark,1)*100%),rgb(0_0_0/0.2))] [&>[data-directive-title]]:transition-colors hover:[&>[data-directive-title]]:text-[color:var(--pmd-accent-hover,color-mix(in_oklab,#67e8f9_calc(var(--pmd-scheme-dark,1)*100%),#155e75))] [&_a:not([data-directive-link])]:relative [&_a:not([data-directive-link])]:z-20'\n : undefined,\n theme.hookClassName,\n theme.modifierClassName,\n theme.classes,\n )\n node.children = [\n ...(href && linkScope === 'full' ? [makeFullCardLink(href, title, newTab)] : []),\n ...(eyebrow ? [makeEyebrow(eyebrow)] : []),\n ...(icons.length > 0 ? [makeIcons(icons, Boolean(eyebrow))] : []),\n ...(title ? [makeTitle(title, href && linkScope === 'title' ? href : undefined, newTab)] : []),\n {\n type: 'element',\n children,\n properties: {\n className: [CARD_BODY_CLASS_NAMES],\n dataDirectiveBody: 'card',\n },\n tagName: 'div',\n },\n ]\n },\n attributeValues: {\n linkScope: CARD_LINK_SCOPES,\n newTab: ['true', 'false'],\n },\n defaultAttributes: {\n linkScope: DEFAULT_CARD_LINK_SCOPE,\n newTab: 'false',\n },\n description: 'Card content block with optional title, eyebrow, and card link.',\n editor: {\n detail: 'Layout directive',\n label: 'Card',\n snippet: ':::card[${Title}]\\n${Content}\\n:::\\n${}',\n },\n getMdastRenderProperties(node) {\n return {\n dataDirective: 'card',\n dataEyebrow: getAttribute(node, 'eyebrow'),\n dataHref: getSafeHref(getAttribute(node, 'href')),\n dataIcon: getAttribute(node, 'icon'),\n dataLinkScope: getLinkScope(node),\n dataNewTab: 'newTab' in (node.attributes ?? {})\n ? getBooleanAttribute(node, 'newTab') ? 'true' : 'false'\n : undefined,\n dataTheme: getAttribute(node, 'theme'),\n dataTitle: getDirectiveLabelOrAttribute(node, 'title'),\n }\n },\n kind: 'card',\n openMarker: ':::card',\n public: true,\n supportsAttributes: true,\n tagName: 'article',\n themeAttributes: {\n theme: 'card',\n },\n validateAttributes({ attributes }) {\n const warnings: string[] = [...getUnsafeHrefWarnings('card', attributes)]\n\n if (typeof attributes.linkScope === 'string' && !isCardLinkScope(attributes.linkScope))\n warnings.push(\n `Invalid card linkScope \"${attributes.linkScope}\". Falling back to \"${DEFAULT_CARD_LINK_SCOPE}\".`,\n )\n\n return warnings\n },\n}\n"],"names":["DIRECTIVE_BODY_CLASS","makeDirectiveIconPlaceholder","getDirectiveLabelOrAttribute","resolveDirectiveTheme","getSafeHref","getUnsafeHrefWarnings","CARD_BODY_CLASS_NAMES","CARD_TITLE_CLASS_NAMES","CARD_TITLE_LINK_CLASS_NAMES","CARD_LINK_SCOPES","DEFAULT_CARD_LINK_SCOPE","isCardLinkScope","value","includes","getAttribute","node","name","attributes","trim","undefined","getBooleanAttribute","getLinkScope","linkScope","getLinkProperties","href","newTab","rel","target","makeTitle","title","children","type","properties","className","tagName","dataDirectiveTitle","makeFullCardLink","ariaLabel","dataDirectiveLink","parseCardIcons","split","map","icon","filter","Boolean","makeIcons","icons","hasEyebrow","makeEyebrow","eyebrow","dataDirectiveEyebrow","cardDirective","allowedAttributes","applyHast","config","mergeClassNames","dataTitle","dataHref","dataLinkScope","dataNewTab","dataEyebrow","dataIcon","theme","dataTheme","themes","hookClassName","modifierClassName","classes","length","dataDirectiveBody","attributeValues","defaultAttributes","description","editor","detail","label","snippet","getMdastRenderProperties","dataDirective","kind","openMarker","public","supportsAttributes","themeAttributes","validateAttributes","warnings","push"],"mappings":"AAKA,SAASA,oBAAoB,QAAQ,mCAAkC;AACvE,SAASC,4BAA4B,QAAQ,wBAAuB;AACpE,SAASC,4BAA4B,QAAQ,eAAc;AAC3D,SAASC,qBAAqB,QAAQ,eAAc;AACpD,SAASC,WAAW,EAAEC,qBAAqB,QAAQ,aAAY;AAE/D,OAAO,MAAMC,wBAAwBN,qBAAoB;AACzD,OAAO,MAAMO,yBACX,iFAAgF;AAClF,MAAMC,8BACJ;AACF,OAAO,MAAMC,mBAAmB;IAAC;IAAQ;CAAQ,CAAS;AAC1D,OAAO,MAAMC,0BAA0B,OAAM;AAI7C,OAAO,SAASC,gBAAgBC,KAAc;IAC5C,OAAO,OAAOA,UAAU,YAAYH,iBAAiBI,QAAQ,CAACD;AAChE;AAEA,SAASE,aAAaC,IAAwB,EAAEC,IAAY;IAC1D,MAAMJ,QAAQG,KAAKE,UAAU,EAAE,CAACD,KAAK;IAErC,OAAO,OAAOJ,UAAU,YAAYA,MAAMM,IAAI,KAAKN,MAAMM,IAAI,KAAKC;AACpE;AAEA,SAASC,oBAAoBL,IAAwB,EAAEC,IAAY;IACjE,MAAMC,aAAaF,KAAKE,UAAU;IAIlC,MAAML,QAAQK,YAAY,CAACD,KAAK;IAEhC,IAAIJ,UAAU,MAAM,OAAO;IAC3B,IAAI,OAAOA,UAAU,UAAU,OAAO;IAEtC,OAAOA,UAAU;AACn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AC,0BAAyB9D,IAAI;QAC3B,OAAO;YACL+D,eAAe;YACflB,aAAa9C,aAAaC,MAAM;YAChC0C,UAAUrD,YAAYU,aAAaC,MAAM;YACzC8C,UAAU/C,aAAaC,MAAM;YAC7B2C,eAAerC,aAAaN;YAC5B4C,YAAY,YAAa5C,CAAAA,KAAKE,UAAU,IAAI,CAAC,CAAA,IACzCG,oBAAoBL,MAAM,YAAY,SAAS,UAC/CI;YACJ4C,WAAWjD,aAAaC,MAAM;YAC9ByC,WAAWtD,6BAA6Ba,MAAM;QAChD;IACF;IACAgE,MAAM;IACNC,YAAY;IACZC,QAAQ;IACRC,oBAAoB;IACpBhD,SAAS;IACTiD,iBAAiB;QACfrB,OAAO;IACT;IACAsB,oBAAmB,EAAEnE,UAAU,EAAE;QAC/B,MAAMoE,WAAqB;eAAIhF,sBAAsB,QAAQY;SAAY;QAEzE,IAAI,OAAOA,WAAWK,SAAS,KAAK,YAAY,CAACX,gBAAgBM,WAAWK,SAAS,GACnF+D,SAASC,IAAI,CACX,CAAC,wBAAwB,EAAErE,WAAWK,SAAS,CAAC,oBAAoB,EAAEZ,wBAAwB,EAAE,CAAC;QAGrG,OAAO2E;IACT;AACF,EAAC"}
|
|
1
|
+
{"version":3,"sources":["../../../src/directives/definitions/card.ts"],"sourcesContent":["import type { Element, ElementContent } from 'hast'\nimport type { ContainerDirective } from 'mdast-util-directive'\n\nimport { type IconEntry, parseIconEntries } from '../../icons/entries.js'\nimport { DIRECTIVE_BODY_CLASS } from '../../styles/directiveSurface.js'\nimport { makeDirectiveIconPlaceholder } from '../iconPlaceholder.js'\nimport { getDirectiveLabelOrAttribute } from '../labels.js'\nimport { findNearestLintFrame } from '../lint.js'\nimport {\n applyDirectivePalette,\n getPaletteRenderProperties,\n PALETTE_ATTRIBUTES,\n resolveIconPaletteName,\n} from '../palette.js'\nimport { resolveDirectiveTheme } from '../themes.js'\nimport { defineDirective } from '../types.js'\nimport { getSafeHref, getUnsafeHrefWarnings } from '../urls.js'\n\nexport const CARD_BODY_CLASS_NAMES = DIRECTIVE_BODY_CLASS\nexport const CARD_TITLE_CLASS_NAMES =\n 'not-prose mb-3 text-lg font-semibold tracking-tight text-(--tw-prose-headings)'\nconst CARD_TITLE_LINK_CLASS_NAMES =\n 'rounded-sm transition-colors hover:text-[color:var(--pmd-accent-hover,color-mix(in_oklab,#67e8f9_calc(var(--pmd-scheme-dark,1)*100%),#155e75))] focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-[color:var(--pmd-accent,color-mix(in_oklab,#22d3ee_calc(var(--pmd-scheme-dark,1)*100%),#0e7490))]'\nexport const CARD_LINK_SCOPES = ['full', 'title'] as const\nexport const DEFAULT_CARD_LINK_SCOPE = 'full'\n\nexport type CardLinkScope = (typeof CARD_LINK_SCOPES)[number]\n\n/** Editor-linter state of an open `cards` frame (set by the `cards` lint hook). */\nexport type CardsLintState = {\n hasHref: boolean\n linkScope?: string\n}\n\nconst CARD_LINK_OVERRIDE_ATTRIBUTES = ['href', 'linkScope', 'newTab'] as const\n\nexport function isCardLinkScope(value: unknown): value is CardLinkScope {\n return typeof value === 'string' && CARD_LINK_SCOPES.includes(value as CardLinkScope)\n}\n\nfunction getAttribute(node: ContainerDirective, name: string): string | undefined {\n const value = node.attributes?.[name]\n\n return typeof value === 'string' && value.trim() ? value.trim() : undefined\n}\n\nfunction getBooleanAttribute(node: ContainerDirective, name: string): boolean {\n const attributes = node.attributes as\n | null\n | Record<string, boolean | null | string | undefined>\n | undefined\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 getLinkScope(node: ContainerDirective): CardLinkScope | undefined {\n const value = node.attributes?.linkScope\n\n if (typeof value !== 'string') return undefined\n\n return isCardLinkScope(value) ? value : DEFAULT_CARD_LINK_SCOPE\n}\n\nfunction getLinkProperties(href: string, newTab: boolean): Element['properties'] {\n return {\n href,\n ...(newTab\n ? {\n rel: ['noopener', 'noreferrer'],\n target: '_blank',\n }\n : {}),\n }\n}\n\nfunction makeTitle(title: string, href?: string, newTab = false): Element {\n const children: ElementContent[] = href\n ? [\n {\n type: 'element',\n children: [{ type: 'text', value: title }],\n properties: { ...getLinkProperties(href, newTab), className: [CARD_TITLE_LINK_CLASS_NAMES] },\n tagName: 'a',\n },\n ]\n : [{ type: 'text', value: title }]\n\n return {\n type: 'element',\n children,\n properties: {\n className: [CARD_TITLE_CLASS_NAMES],\n dataDirectiveTitle: 'card',\n },\n tagName: 'h3',\n }\n}\n\nfunction makeFullCardLink(href: string, title: string | undefined, newTab: boolean): Element {\n return {\n type: 'element',\n children: [],\n properties: {\n ...getLinkProperties(href, newTab),\n ariaLabel: title ? `Open ${title}` : 'Open card',\n className: [\n 'not-prose absolute inset-0 z-10 rounded-[inherit] focus:outline-none focus-visible:ring-2 focus-visible:ring-[color:var(--pmd-accent,color-mix(in_oklab,#22d3ee_calc(var(--pmd-scheme-dark,1)*100%),#0e7490))]',\n ],\n dataDirectiveLink: 'card',\n },\n tagName: 'a',\n }\n}\n\n/**\n * `icon` takes one icon or a comma-separated list; each entry may carry its\n * own palette (`@fa-brands/debian palette=debian`, see icons/entries.ts).\n */\nfunction makeIcons(card: Element, icons: IconEntry[], hasEyebrow: boolean): Element {\n return {\n type: 'element',\n children: icons.map((icon) =>\n makeDirectiveIconPlaceholder(\n icon.ref,\n ['pmd-card__icon inline-flex size-5 text-current'],\n resolveIconPaletteName(card, icon),\n ),\n ),\n properties: {\n className: [\n 'not-prose pmd-card__icons mb-3 flex flex-wrap items-center gap-2',\n // Clear of the eyebrow; its mb-2 collapses into this margin.\n ...(hasEyebrow ? ['mt-4'] : []),\n ],\n },\n tagName: 'div',\n }\n}\n\nfunction makeEyebrow(eyebrow: string): Element {\n return {\n type: 'element',\n children: [{ type: 'text', value: eyebrow }],\n properties: {\n // Muted relative to the body text rather than a fixed grey, so small\n // uppercase labels keep AA contrast on tinted or custom surfaces.\n className: ['not-prose mb-2 text-xs font-semibold uppercase tracking-[0.18em] text-(--tw-prose-body)/80'],\n dataDirectiveEyebrow: 'card',\n },\n tagName: 'p',\n }\n}\n\nexport const cardDirective = defineDirective({\n name: 'card',\n allowedAttributes: ['eyebrow', 'href', 'icon', 'linkScope', 'newTab', ...PALETTE_ATTRIBUTES, 'theme', 'title'],\n applyHast(node, config, { mergeClassNames }) {\n const title = typeof node.properties.dataTitle === 'string' ? node.properties.dataTitle : undefined\n // Re-validate at the hast stage: this is where the live <a href> is built.\n const href = getSafeHref(node.properties.dataHref)\n if (!href) delete node.properties.dataHref\n const linkScope =\n typeof node.properties.dataLinkScope === 'string' && isCardLinkScope(node.properties.dataLinkScope)\n ? node.properties.dataLinkScope\n : DEFAULT_CARD_LINK_SCOPE\n const newTab = node.properties.dataNewTab === 'true'\n const eyebrow =\n typeof node.properties.dataEyebrow === 'string' ? node.properties.dataEyebrow : undefined\n const { entries: icons } = parseIconEntries(\n typeof node.properties.dataIcon === 'string' ? node.properties.dataIcon : undefined,\n )\n const theme = resolveDirectiveTheme(\n 'card',\n typeof node.properties.dataTheme === 'string' ? node.properties.dataTheme : undefined,\n config.themes,\n )\n const children = node.children\n\n node.properties.dataTheme = theme.name\n if (href) {\n node.properties.dataLinkScope = linkScope\n node.properties.dataNewTab = newTab ? 'true' : 'false'\n }\n node.properties.className = mergeClassNames(\n 'my-6',\n href && linkScope === 'full'\n ? 'relative cursor-pointer transition-colors hover:border-[color:color-mix(in_oklab,rgb(255_255_255/0.15)_calc(var(--pmd-scheme-dark,1)*100%),rgb(0_0_0/0.2))] [&>[data-directive-title]]:transition-colors hover:[&>[data-directive-title]]:text-[color:var(--pmd-accent-hover,color-mix(in_oklab,#67e8f9_calc(var(--pmd-scheme-dark,1)*100%),#155e75))] [&_a:not([data-directive-link])]:relative [&_a:not([data-directive-link])]:z-20'\n : undefined,\n theme.hookClassName,\n theme.modifierClassName,\n theme.classes,\n )\n applyDirectivePalette(node, config)\n\n node.children = [\n ...(href && linkScope === 'full' ? [makeFullCardLink(href, title, newTab)] : []),\n ...(eyebrow ? [makeEyebrow(eyebrow)] : []),\n ...(icons.length > 0 ? [makeIcons(node, icons, Boolean(eyebrow))] : []),\n ...(title ? [makeTitle(title, href && linkScope === 'title' ? href : undefined, newTab)] : []),\n {\n type: 'element',\n children,\n properties: {\n className: [CARD_BODY_CLASS_NAMES],\n dataDirectiveBody: 'card',\n },\n tagName: 'div',\n },\n ]\n },\n attributeTypes: {\n href: { type: 'url' },\n icon: { type: 'icon' },\n iconPalette: { type: 'palette' },\n palette: { type: 'palette' },\n },\n attributeValues: {\n linkScope: CARD_LINK_SCOPES,\n newTab: ['true', 'false'],\n },\n container: {\n labelAttribute: 'title',\n },\n defaultAttributes: {\n linkScope: DEFAULT_CARD_LINK_SCOPE,\n newTab: 'false',\n },\n description: 'Card content block with optional title, eyebrow, and card link.',\n editor: {\n detail: 'Layout directive',\n label: 'Card',\n snippet: ':::card[${Title}]\\n${Content}\\n:::\\n${}',\n },\n getMdastRenderProperties(node) {\n return {\n dataDirective: 'card',\n dataEyebrow: getAttribute(node, 'eyebrow'),\n dataHref: getSafeHref(getAttribute(node, 'href')),\n dataIcon: getAttribute(node, 'icon'),\n ...getPaletteRenderProperties(node),\n dataLinkScope: getLinkScope(node),\n dataNewTab: 'newTab' in (node.attributes ?? {})\n ? getBooleanAttribute(node, 'newTab') ? 'true' : 'false'\n : undefined,\n dataTheme: getAttribute(node, 'theme'),\n dataTitle: getDirectiveLabelOrAttribute(node, 'title'),\n }\n },\n kind: 'card',\n lint: {\n // Mirrors cards' validateMdast: a section-linked grid ignores card link overrides.\n open({ attributes, stack }) {\n const cards = findNearestLintFrame(stack, 'cards')?.state as CardsLintState | undefined\n const sectionLink = cards?.hasHref && (cards.linkScope === undefined || cards.linkScope === 'section')\n const overrides = CARD_LINK_OVERRIDE_ATTRIBUTES.some((name) =>\n Object.prototype.hasOwnProperty.call(attributes, name),\n )\n\n return sectionLink && overrides\n ? ['Directive \"cards\" with linkScope=\"section\" ignores child \"card\" link overrides.']\n : []\n },\n },\n public: true,\n sanitize: {\n article: [\n 'dataDirective',\n 'dataEyebrow',\n 'dataHref',\n 'dataIcon',\n 'dataIconPalette',\n 'dataLinkScope',\n 'dataNewTab',\n 'dataPalette',\n 'dataTheme',\n 'dataTitle',\n ],\n },\n supportsAttributes: true,\n tagName: 'article',\n themeAttributes: {\n theme: 'card',\n },\n validateAttributes({ attributes }) {\n const warnings: string[] = [...getUnsafeHrefWarnings('card', attributes)]\n\n if (typeof attributes.linkScope === 'string' && !isCardLinkScope(attributes.linkScope))\n warnings.push(\n `Invalid card linkScope \"${attributes.linkScope}\". Falling back to \"${DEFAULT_CARD_LINK_SCOPE}\".`,\n )\n\n return warnings\n },\n})\n"],"names":["parseIconEntries","DIRECTIVE_BODY_CLASS","makeDirectiveIconPlaceholder","getDirectiveLabelOrAttribute","findNearestLintFrame","applyDirectivePalette","getPaletteRenderProperties","PALETTE_ATTRIBUTES","resolveIconPaletteName","resolveDirectiveTheme","defineDirective","getSafeHref","getUnsafeHrefWarnings","CARD_BODY_CLASS_NAMES","CARD_TITLE_CLASS_NAMES","CARD_TITLE_LINK_CLASS_NAMES","CARD_LINK_SCOPES","DEFAULT_CARD_LINK_SCOPE","CARD_LINK_OVERRIDE_ATTRIBUTES","isCardLinkScope","value","includes","getAttribute","node","name","attributes","trim","undefined","getBooleanAttribute","getLinkScope","linkScope","getLinkProperties","href","newTab","rel","target","makeTitle","title","children","type","properties","className","tagName","dataDirectiveTitle","makeFullCardLink","ariaLabel","dataDirectiveLink","makeIcons","card","icons","hasEyebrow","map","icon","ref","makeEyebrow","eyebrow","dataDirectiveEyebrow","cardDirective","allowedAttributes","applyHast","config","mergeClassNames","dataTitle","dataHref","dataLinkScope","dataNewTab","dataEyebrow","entries","dataIcon","theme","dataTheme","themes","hookClassName","modifierClassName","classes","length","Boolean","dataDirectiveBody","attributeTypes","iconPalette","palette","attributeValues","container","labelAttribute","defaultAttributes","description","editor","detail","label","snippet","getMdastRenderProperties","dataDirective","kind","lint","open","stack","cards","state","sectionLink","hasHref","overrides","some","Object","prototype","hasOwnProperty","call","public","sanitize","article","supportsAttributes","themeAttributes","validateAttributes","warnings","push"],"mappings":"AAGA,SAAyBA,gBAAgB,QAAQ,yBAAwB;AACzE,SAASC,oBAAoB,QAAQ,mCAAkC;AACvE,SAASC,4BAA4B,QAAQ,wBAAuB;AACpE,SAASC,4BAA4B,QAAQ,eAAc;AAC3D,SAASC,oBAAoB,QAAQ,aAAY;AACjD,SACEC,qBAAqB,EACrBC,0BAA0B,EAC1BC,kBAAkB,EAClBC,sBAAsB,QACjB,gBAAe;AACtB,SAASC,qBAAqB,QAAQ,eAAc;AACpD,SAASC,eAAe,QAAQ,cAAa;AAC7C,SAASC,WAAW,EAAEC,qBAAqB,QAAQ,aAAY;AAE/D,OAAO,MAAMC,wBAAwBZ,qBAAoB;AACzD,OAAO,MAAMa,yBACX,iFAAgF;AAClF,MAAMC,8BACJ;AACF,OAAO,MAAMC,mBAAmB;IAAC;IAAQ;CAAQ,CAAS;AAC1D,OAAO,MAAMC,0BAA0B,OAAM;AAU7C,MAAMC,gCAAgC;IAAC;IAAQ;IAAa;CAAS;AAErE,OAAO,SAASC,gBAAgBC,KAAc;IAC5C,OAAO,OAAOA,UAAU,YAAYJ,iBAAiBK,QAAQ,CAACD;AAChE;AAEA,SAASE,aAAaC,IAAwB,EAAEC,IAAY;IAC1D,MAAMJ,QAAQG,KAAKE,UAAU,EAAE,CAACD,KAAK;IAErC,OAAO,OAAOJ,UAAU,YAAYA,MAAMM,IAAI,KAAKN,MAAMM,IAAI,KAAKC;AACpE;AAEA,SAASC,oBAAoBL,IAAwB,EAAEC,IAAY;IACjE,MAAMC,aAAaF,KAAKE,UAAU;IAIlC,MAAML,QAAQK,YAAY,CAACD,KAAK;IAEhC,IAAIJ,UAAU,MAAM,OAAO;IAC3B,IAAI,OAAOA,UAAU,UAAU,OAAO;IAEtC,OAAOA,UAAU;AACnB;AAEA,SAASS,aAAaN,IAAwB;IAC5C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Y,CAACX,gBAAgBM,WAAWK,SAAS,GACnFkF,SAASC,IAAI,CACX,CAAC,wBAAwB,EAAExF,WAAWK,SAAS,CAAC,oBAAoB,EAAEb,wBAAwB,EAAE,CAAC;QAGrG,OAAO+F;IACT;AACF,GAAE"}
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import type { ContainerDirective } from 'mdast-util-directive';
|
|
2
|
-
import type { LayoutDirectiveDefinition } from '../types.js';
|
|
3
2
|
export declare const CARD_GRID_COLUMNS: readonly ["1", "2", "3", "4", "auto"];
|
|
4
3
|
export declare const DEFAULT_CARD_GRID_COLUMNS = "3";
|
|
5
4
|
export declare const CARDS_LINK_SCOPES: readonly ["section", "card", "title"];
|
|
@@ -8,4 +7,4 @@ export declare const FALLBACK_CARDS_LINK_SCOPE = "card";
|
|
|
8
7
|
export type CardGridColumns = (typeof CARD_GRID_COLUMNS)[number];
|
|
9
8
|
export type CardsLinkScope = (typeof CARDS_LINK_SCOPES)[number];
|
|
10
9
|
export declare function resolveCardGridColumns(node: ContainerDirective): CardGridColumns;
|
|
11
|
-
export declare const cardsDirective: LayoutDirectiveDefinition
|
|
10
|
+
export declare const cardsDirective: import("../types.js").LayoutDirectiveDefinition<"cards", "cards">;
|
|
@@ -1,5 +1,7 @@
|
|
|
1
|
+
import { applyDirectivePalette, getPaletteRenderProperties } from '../palette.js';
|
|
1
2
|
import { resolveDirectiveTheme } from '../themes.js';
|
|
2
|
-
import {
|
|
3
|
+
import { defineDirective } from '../types.js';
|
|
4
|
+
import { getSafeHref, getUnsafeHrefWarnings, isSafeHref } from '../urls.js';
|
|
3
5
|
import { DEFAULT_CARD_LINK_SCOPE } from './card.js';
|
|
4
6
|
export const CARD_GRID_COLUMNS = [
|
|
5
7
|
'1',
|
|
@@ -92,14 +94,16 @@ export function resolveCardGridColumns(node) {
|
|
|
92
94
|
const columns = node.attributes?.columns;
|
|
93
95
|
return isCardGridColumns(columns) ? columns : DEFAULT_CARD_GRID_COLUMNS;
|
|
94
96
|
}
|
|
95
|
-
export const cardsDirective = {
|
|
97
|
+
export const cardsDirective = defineDirective({
|
|
96
98
|
name: 'cards',
|
|
97
99
|
allowedAttributes: [
|
|
98
100
|
'cardTheme',
|
|
99
101
|
'columns',
|
|
100
102
|
'href',
|
|
103
|
+
'iconPalette',
|
|
101
104
|
'linkScope',
|
|
102
105
|
'newTab',
|
|
106
|
+
'palette',
|
|
103
107
|
'theme'
|
|
104
108
|
],
|
|
105
109
|
applyHast (node, config, { mergeClassNames }) {
|
|
@@ -115,6 +119,10 @@ export const cardsDirective = {
|
|
|
115
119
|
for (const child of node.children){
|
|
116
120
|
if (child.type !== 'element' || child.properties?.dataVlLayout !== 'card') continue;
|
|
117
121
|
if (typeof child.properties.dataTheme !== 'string' && cardTheme) child.properties.dataTheme = cardTheme;
|
|
122
|
+
// Cards without a palette of their own paint their icons with the
|
|
123
|
+
// grid's iconPalette (or palette); the grid's surface tokens are inherited.
|
|
124
|
+
const iconPaletteDefault = node.properties.dataIconPalette ?? node.properties.dataPalette;
|
|
125
|
+
if (typeof iconPaletteDefault === 'string' && typeof child.properties.dataPalette !== 'string' && typeof child.properties.dataIconPalette !== 'string') child.properties.dataIconPalette = iconPaletteDefault;
|
|
118
126
|
if (href && linkScope === 'section') {
|
|
119
127
|
delete child.properties.dataHref;
|
|
120
128
|
delete child.properties.dataLinkScope;
|
|
@@ -131,6 +139,7 @@ export const cardsDirective = {
|
|
|
131
139
|
node.properties.dataLinkScope = linkScope;
|
|
132
140
|
node.properties.dataNewTab = newTab ? 'true' : 'false';
|
|
133
141
|
}
|
|
142
|
+
applyDirectivePalette(node, config);
|
|
134
143
|
node.properties.className = mergeClassNames(// Spacing lives in the theme; the base only sets what every grid needs.
|
|
135
144
|
'grid [&>article]:my-0', href && linkScope === 'section' ? 'relative cursor-pointer [&>article]:transition-colors hover:[&>article]:border-[color:color-mix(in_oklab,rgb(255_255_255/0.15)_calc(var(--pmd-scheme-dark,1)*100%),rgb(0_0_0/0.2))] [&_a:not([data-directive-link])]:relative [&_a:not([data-directive-link])]:z-20' : undefined, theme.hookClassName, theme.modifierClassName, theme.classes, cardGridColumnClasses[isCardGridColumns(columns) ? columns : DEFAULT_CARD_GRID_COLUMNS]);
|
|
136
145
|
if (href && linkScope === 'section') node.children = [
|
|
@@ -138,6 +147,17 @@ export const cardsDirective = {
|
|
|
138
147
|
...node.children
|
|
139
148
|
];
|
|
140
149
|
},
|
|
150
|
+
attributeTypes: {
|
|
151
|
+
href: {
|
|
152
|
+
type: 'url'
|
|
153
|
+
},
|
|
154
|
+
iconPalette: {
|
|
155
|
+
type: 'palette'
|
|
156
|
+
},
|
|
157
|
+
palette: {
|
|
158
|
+
type: 'palette'
|
|
159
|
+
}
|
|
160
|
+
},
|
|
141
161
|
attributeValues: {
|
|
142
162
|
columns: CARD_GRID_COLUMNS,
|
|
143
163
|
linkScope: CARDS_LINK_SCOPES,
|
|
@@ -146,6 +166,7 @@ export const cardsDirective = {
|
|
|
146
166
|
'false'
|
|
147
167
|
]
|
|
148
168
|
},
|
|
169
|
+
container: {},
|
|
149
170
|
defaultAttributes: {
|
|
150
171
|
columns: DEFAULT_CARD_GRID_COLUMNS,
|
|
151
172
|
linkScope: DEFAULT_CARDS_LINK_SCOPE,
|
|
@@ -160,6 +181,7 @@ export const cardsDirective = {
|
|
|
160
181
|
getMdastRenderProperties (node) {
|
|
161
182
|
const href = getSafeHref(getAttribute(node, 'href'));
|
|
162
183
|
return {
|
|
184
|
+
...getPaletteRenderProperties(node),
|
|
163
185
|
dataCardTheme: typeof node.attributes?.cardTheme === 'string' ? node.attributes.cardTheme : undefined,
|
|
164
186
|
dataColumns: resolveCardGridColumns(node),
|
|
165
187
|
dataDirective: 'cards',
|
|
@@ -170,8 +192,31 @@ export const cardsDirective = {
|
|
|
170
192
|
};
|
|
171
193
|
},
|
|
172
194
|
kind: 'cards',
|
|
173
|
-
|
|
195
|
+
lint: {
|
|
196
|
+
// Read by the lint hook of `card` (see CardsLintState).
|
|
197
|
+
open ({ attributes, frame }) {
|
|
198
|
+
const state = {
|
|
199
|
+
hasHref: typeof attributes.href === 'string' && isSafeHref(attributes.href.trim()),
|
|
200
|
+
linkScope: typeof attributes.linkScope === 'string' ? attributes.linkScope : undefined
|
|
201
|
+
};
|
|
202
|
+
frame.state = state;
|
|
203
|
+
return [];
|
|
204
|
+
}
|
|
205
|
+
},
|
|
174
206
|
public: true,
|
|
207
|
+
sanitize: {
|
|
208
|
+
section: [
|
|
209
|
+
'dataCardTheme',
|
|
210
|
+
'dataColumns',
|
|
211
|
+
'dataDirective',
|
|
212
|
+
'dataHref',
|
|
213
|
+
'dataIconPalette',
|
|
214
|
+
'dataLinkScope',
|
|
215
|
+
'dataNewTab',
|
|
216
|
+
'dataPalette',
|
|
217
|
+
'dataTheme'
|
|
218
|
+
]
|
|
219
|
+
},
|
|
175
220
|
supportsAttributes: true,
|
|
176
221
|
tagName: 'section',
|
|
177
222
|
themeAttributes: {
|
|
@@ -194,6 +239,6 @@ export const cardsDirective = {
|
|
|
194
239
|
}
|
|
195
240
|
return warnings;
|
|
196
241
|
}
|
|
197
|
-
};
|
|
242
|
+
});
|
|
198
243
|
|
|
199
244
|
//# sourceMappingURL=cards.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/directives/definitions/cards.ts"],"sourcesContent":["import type { Element } from 'hast'\nimport type { ContainerDirective } from 'mdast-util-directive'\n\nimport type { LayoutDirectiveDefinition } from '../types.js'\n\nimport { resolveDirectiveTheme } from '../themes.js'\nimport { getSafeHref, getUnsafeHrefWarnings } from '../urls.js'\nimport { DEFAULT_CARD_LINK_SCOPE } from './card.js'\n\nexport const CARD_GRID_COLUMNS = ['1', '2', '3', '4', 'auto'] as const\nexport const DEFAULT_CARD_GRID_COLUMNS = '3'\nexport const CARDS_LINK_SCOPES = ['section', 'card', 'title'] as const\nexport const DEFAULT_CARDS_LINK_SCOPE = 'section'\nexport const FALLBACK_CARDS_LINK_SCOPE = 'card'\n\nexport type CardGridColumns = (typeof CARD_GRID_COLUMNS)[number]\nexport type CardsLinkScope = (typeof CARDS_LINK_SCOPES)[number]\n\n// Columns collapse on the grid's own width (not the viewport): up to N\n// columns while each stays at least 14rem wide. The 2rem term covers the\n// widest theme gap, so a theme's gap never costs a column that would fit.\nconst cardGridColumnClasses: Record<CardGridColumns, string> = {\n '1': 'grid-cols-1',\n '2': 'grid-cols-[repeat(auto-fill,minmax(min(100%,max(14rem,calc((100%_-_2rem)/2))),1fr))]',\n '3': 'grid-cols-[repeat(auto-fill,minmax(min(100%,max(14rem,calc((100%_-_2*2rem)/3))),1fr))]',\n '4': 'grid-cols-[repeat(auto-fill,minmax(min(100%,max(14rem,calc((100%_-_3*2rem)/4))),1fr))]',\n auto: 'grid-cols-[repeat(auto-fit,minmax(min(100%,16rem),1fr))]',\n}\n\nfunction isCardGridColumns(value: unknown): value is CardGridColumns {\n return typeof value === 'string' && CARD_GRID_COLUMNS.includes(value as CardGridColumns)\n}\n\nfunction isCardsLinkScope(value: unknown): value is CardsLinkScope {\n return typeof value === 'string' && CARDS_LINK_SCOPES.includes(value as CardsLinkScope)\n}\n\nfunction getAttribute(node: ContainerDirective, name: string): string | undefined {\n const value = node.attributes?.[name]\n\n return typeof value === 'string' && value.trim() ? value.trim() : undefined\n}\n\nfunction getBooleanAttribute(node: ContainerDirective, name: string): boolean {\n const attributes = node.attributes as\n | null\n | Record<string, boolean | null | string | undefined>\n | undefined\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 hasAttribute(node: ContainerDirective, name: string): boolean {\n return Object.prototype.hasOwnProperty.call(node.attributes ?? {}, name)\n}\n\nfunction getCardsLinkScope(node: ContainerDirective): CardsLinkScope {\n const value = node.attributes?.linkScope\n\n if (typeof value !== 'string') return DEFAULT_CARDS_LINK_SCOPE\n\n return isCardsLinkScope(value) ? value : FALLBACK_CARDS_LINK_SCOPE\n}\n\nfunction getLinkProperties(href: string, newTab: boolean): Element['properties'] {\n return {\n href,\n ...(newTab\n ? {\n rel: ['noopener', 'noreferrer'],\n target: '_blank',\n }\n : {}),\n }\n}\n\nfunction makeSectionLink(href: string, newTab: boolean): Element {\n return {\n type: 'element',\n children: [],\n properties: {\n ...getLinkProperties(href, newTab),\n ariaLabel: 'Open card section',\n className: [\n 'not-prose absolute -inset-2 z-10 rounded-3xl focus:outline-none focus-visible:ring-2 focus-visible:ring-[color:var(--pmd-accent,color-mix(in_oklab,#22d3ee_calc(var(--pmd-scheme-dark,1)*100%),#0e7490))]',\n ],\n dataDirectiveLink: 'cards',\n },\n tagName: 'a',\n }\n}\n\nfunction hasCardLinkOverride(node: ContainerDirective): boolean {\n return ['href', 'linkScope', 'newTab'].some((name) => hasAttribute(node, name))\n}\n\nfunction isContainerDirective(node: unknown): node is ContainerDirective {\n return Boolean(\n node &&\n typeof node === 'object' &&\n 'type' in node &&\n (node as { type?: string }).type === 'containerDirective',\n )\n}\n\nexport function resolveCardGridColumns(node: ContainerDirective): CardGridColumns {\n const columns = node.attributes?.columns\n\n return isCardGridColumns(columns) ? columns : DEFAULT_CARD_GRID_COLUMNS\n}\n\nexport const cardsDirective: LayoutDirectiveDefinition = {\n name: 'cards',\n allowedAttributes: ['cardTheme', 'columns', 'href', 'linkScope', 'newTab', 'theme'],\n applyHast(node, config, { mergeClassNames }) {\n const columns =\n typeof node.properties.dataColumns === 'string'\n ? node.properties.dataColumns\n : DEFAULT_CARD_GRID_COLUMNS\n // Re-validate at the hast stage: this is where the live <a href> is built.\n const href = getSafeHref(node.properties.dataHref)\n if (!href) delete node.properties.dataHref\n const linkScope =\n typeof node.properties.dataLinkScope === 'string' && isCardsLinkScope(node.properties.dataLinkScope)\n ? node.properties.dataLinkScope\n : DEFAULT_CARDS_LINK_SCOPE\n const newTab = node.properties.dataNewTab === 'true'\n const theme = resolveDirectiveTheme(\n 'cards',\n typeof node.properties.dataTheme === 'string' ? node.properties.dataTheme : undefined,\n config.themes,\n )\n const cardTheme =\n typeof node.properties.dataCardTheme === 'string' ? node.properties.dataCardTheme : undefined\n const childLinkScope = linkScope === 'title' ? 'title' : DEFAULT_CARD_LINK_SCOPE\n\n for (const child of node.children) {\n if (child.type !== 'element' || child.properties?.dataVlLayout !== 'card') continue\n\n if (typeof child.properties.dataTheme !== 'string' && cardTheme)\n child.properties.dataTheme = cardTheme\n\n if (href && linkScope === 'section') {\n delete child.properties.dataHref\n delete child.properties.dataLinkScope\n delete child.properties.dataNewTab\n continue\n }\n\n if (!href) continue\n\n if (typeof child.properties.dataHref !== 'string') child.properties.dataHref = href\n if (typeof child.properties.dataLinkScope !== 'string')\n child.properties.dataLinkScope = childLinkScope\n if (typeof child.properties.dataNewTab !== 'string')\n child.properties.dataNewTab = newTab ? 'true' : 'false'\n }\n\n node.properties.dataTheme = theme.name\n if (href) {\n node.properties.dataLinkScope = linkScope\n node.properties.dataNewTab = newTab ? 'true' : 'false'\n }\n node.properties.className = mergeClassNames(\n // Spacing lives in the theme; the base only sets what every grid needs.\n 'grid [&>article]:my-0',\n href && linkScope === 'section'\n ? 'relative cursor-pointer [&>article]:transition-colors hover:[&>article]:border-[color:color-mix(in_oklab,rgb(255_255_255/0.15)_calc(var(--pmd-scheme-dark,1)*100%),rgb(0_0_0/0.2))] [&_a:not([data-directive-link])]:relative [&_a:not([data-directive-link])]:z-20'\n : undefined,\n theme.hookClassName,\n theme.modifierClassName,\n theme.classes,\n cardGridColumnClasses[isCardGridColumns(columns) ? columns : DEFAULT_CARD_GRID_COLUMNS],\n )\n\n if (href && linkScope === 'section') node.children = [makeSectionLink(href, newTab), ...node.children]\n },\n attributeValues: {\n columns: CARD_GRID_COLUMNS,\n linkScope: CARDS_LINK_SCOPES,\n newTab: ['true', 'false'],\n },\n defaultAttributes: {\n columns: DEFAULT_CARD_GRID_COLUMNS,\n linkScope: DEFAULT_CARDS_LINK_SCOPE,\n newTab: 'false',\n },\n description: 'Responsive card grid for docs and landing-page content.',\n editor: {\n detail: 'Layout directive',\n label: 'Cards',\n snippet:\n ':::cards{\\n columns=\"${3}\"\\n}\\n\\n:::card[${Title}]\\n${Content}\\n:::\\n\\n:::card[${Title}]\\n${Content}\\n:::\\n\\n:::\\n${}',\n },\n getMdastRenderProperties(node) {\n const href = getSafeHref(getAttribute(node, 'href'))\n\n return {\n dataCardTheme: typeof node.attributes?.cardTheme === 'string' ? node.attributes.cardTheme : undefined,\n dataColumns: resolveCardGridColumns(node),\n dataDirective: 'cards',\n dataHref: href,\n dataLinkScope: href || hasAttribute(node, 'linkScope') ? getCardsLinkScope(node) : undefined,\n dataNewTab: href && hasAttribute(node, 'newTab')\n ? getBooleanAttribute(node, 'newTab') ? 'true' : 'false'\n : undefined,\n dataTheme: typeof node.attributes?.theme === 'string' ? node.attributes.theme : 'default',\n }\n },\n kind: 'cards',\n openMarker: ':::cards',\n public: true,\n supportsAttributes: true,\n tagName: 'section',\n themeAttributes: {\n cardTheme: 'card',\n theme: 'cards',\n },\n validateAttributes({ attributes }) {\n const warnings: string[] = [...getUnsafeHrefWarnings('cards', attributes)]\n\n if (typeof attributes.columns === 'string' && !isCardGridColumns(attributes.columns))\n warnings.push(\n `Invalid cards columns \"${attributes.columns}\". Falling back to \"${DEFAULT_CARD_GRID_COLUMNS}\".`,\n )\n\n if (typeof attributes.linkScope === 'string' && !isCardsLinkScope(attributes.linkScope))\n warnings.push(\n `Invalid cards linkScope \"${attributes.linkScope}\". Falling back to \"${FALLBACK_CARDS_LINK_SCOPE}\".`,\n )\n\n return warnings\n },\n validateMdast(node) {\n const warnings: string[] = []\n\n if (getSafeHref(getAttribute(node, 'href')) && getCardsLinkScope(node) === 'section') {\n const hasOverrides = node.children.some(\n (child) => isContainerDirective(child) && child.name === 'card' && hasCardLinkOverride(child),\n )\n\n if (hasOverrides)\n warnings.push(\n 'Directive \"cards\" with linkScope=\"section\" ignores child \"card\" link overrides.',\n )\n }\n\n return warnings\n },\n}\n"],"names":["resolveDirectiveTheme","getSafeHref","getUnsafeHrefWarnings","DEFAULT_CARD_LINK_SCOPE","CARD_GRID_COLUMNS","DEFAULT_CARD_GRID_COLUMNS","CARDS_LINK_SCOPES","DEFAULT_CARDS_LINK_SCOPE","FALLBACK_CARDS_LINK_SCOPE","cardGridColumnClasses","auto","isCardGridColumns","value","includes","isCardsLinkScope","getAttribute","node","name","attributes","trim","undefined","getBooleanAttribute","hasAttribute","Object","prototype","hasOwnProperty","call","getCardsLinkScope","linkScope","getLinkProperties","href","newTab","rel","target","makeSectionLink","type","children","properties","ariaLabel","className","dataDirectiveLink","tagName","hasCardLinkOverride","some","isContainerDirective","Boolean","resolveCardGridColumns","columns","cardsDirective","allowedAttributes","applyHast","config","mergeClassNames","dataColumns","dataHref","dataLinkScope","dataNewTab","theme","dataTheme","themes","cardTheme","dataCardTheme","childLinkScope","child","dataVlLayout","hookClassName","modifierClassName","classes","attributeValues","defaultAttributes","description","editor","detail","label","snippet","getMdastRenderProperties","dataDirective","kind","openMarker","public","supportsAttributes","themeAttributes","validateAttributes","warnings","push","validateMdast","hasOverrides"],"mappings":"AAKA,SAASA,qBAAqB,QAAQ,eAAc;AACpD,SAASC,WAAW,EAAEC,qBAAqB,QAAQ,aAAY;AAC/D,SAASC,uBAAuB,QAAQ,YAAW;AAEnD,OAAO,MAAMC,oBAAoB;IAAC;IAAK;IAAK;IAAK;IAAK;CAAO,CAAS;AACtE,OAAO,MAAMC,4BAA4B,IAAG;AAC5C,OAAO,MAAMC,oBAAoB;IAAC;IAAW;IAAQ;CAAQ,CAAS;AACtE,OAAO,MAAMC,2BAA2B,UAAS;AACjD,OAAO,MAAMC,4BAA4B,OAAM;AAK/C,uEAAuE;AACvE,yEAAyE;AACzE,0EAA0E;AAC1E,MAAMC,wBAAyD;IAC7D,KAAK;IACL,KAAK;IACL,KAAK;IACL,KAAK;IACLC,MAAM;AACR;AAEA,SAASC,kBAAkBC,KAAc;IACvC,OAAO,OAAOA,UAAU,YAAYR,kBAAkBS,QAAQ,CAACD;AACjE;AAEA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BAA0B,EAAE,CAAC;QAGxG,OAAO2E;IACT;IACAE,eAAcrE,IAAI;QAChB,MAAMmE,WAAqB,EAAE;QAE7B,IAAIlF,YAAYc,aAAaC,MAAM,YAAYW,kBAAkBX,UAAU,WAAW;YACpF,MAAMsE,eAAetE,KAAKoB,QAAQ,CAACO,IAAI,CACrC,CAACoB,QAAUnB,qBAAqBmB,UAAUA,MAAM9C,IAAI,KAAK,UAAUyB,oBAAoBqB;YAGzF,IAAIuB,cACFH,SAASC,IAAI,CACX;QAEN;QAEA,OAAOD;IACT;AACF,EAAC"}
|
|
1
|
+
{"version":3,"sources":["../../../src/directives/definitions/cards.ts"],"sourcesContent":["import type { Element } from 'hast'\nimport type { ContainerDirective } from 'mdast-util-directive'\n\nimport type { CardsLintState } from './card.js'\n\nimport { applyDirectivePalette, getPaletteRenderProperties } from '../palette.js'\nimport { resolveDirectiveTheme } from '../themes.js'\nimport { defineDirective } from '../types.js'\nimport { getSafeHref, getUnsafeHrefWarnings, isSafeHref } from '../urls.js'\nimport { DEFAULT_CARD_LINK_SCOPE } from './card.js'\n\nexport const CARD_GRID_COLUMNS = ['1', '2', '3', '4', 'auto'] as const\nexport const DEFAULT_CARD_GRID_COLUMNS = '3'\nexport const CARDS_LINK_SCOPES = ['section', 'card', 'title'] as const\nexport const DEFAULT_CARDS_LINK_SCOPE = 'section'\nexport const FALLBACK_CARDS_LINK_SCOPE = 'card'\n\nexport type CardGridColumns = (typeof CARD_GRID_COLUMNS)[number]\nexport type CardsLinkScope = (typeof CARDS_LINK_SCOPES)[number]\n\n// Columns collapse on the grid's own width (not the viewport): up to N\n// columns while each stays at least 14rem wide. The 2rem term covers the\n// widest theme gap, so a theme's gap never costs a column that would fit.\nconst cardGridColumnClasses: Record<CardGridColumns, string> = {\n '1': 'grid-cols-1',\n '2': 'grid-cols-[repeat(auto-fill,minmax(min(100%,max(14rem,calc((100%_-_2rem)/2))),1fr))]',\n '3': 'grid-cols-[repeat(auto-fill,minmax(min(100%,max(14rem,calc((100%_-_2*2rem)/3))),1fr))]',\n '4': 'grid-cols-[repeat(auto-fill,minmax(min(100%,max(14rem,calc((100%_-_3*2rem)/4))),1fr))]',\n auto: 'grid-cols-[repeat(auto-fit,minmax(min(100%,16rem),1fr))]',\n}\n\nfunction isCardGridColumns(value: unknown): value is CardGridColumns {\n return typeof value === 'string' && CARD_GRID_COLUMNS.includes(value as CardGridColumns)\n}\n\nfunction isCardsLinkScope(value: unknown): value is CardsLinkScope {\n return typeof value === 'string' && CARDS_LINK_SCOPES.includes(value as CardsLinkScope)\n}\n\nfunction getAttribute(node: ContainerDirective, name: string): string | undefined {\n const value = node.attributes?.[name]\n\n return typeof value === 'string' && value.trim() ? value.trim() : undefined\n}\n\nfunction getBooleanAttribute(node: ContainerDirective, name: string): boolean {\n const attributes = node.attributes as\n | null\n | Record<string, boolean | null | string | undefined>\n | undefined\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 hasAttribute(node: ContainerDirective, name: string): boolean {\n return Object.prototype.hasOwnProperty.call(node.attributes ?? {}, name)\n}\n\nfunction getCardsLinkScope(node: ContainerDirective): CardsLinkScope {\n const value = node.attributes?.linkScope\n\n if (typeof value !== 'string') return DEFAULT_CARDS_LINK_SCOPE\n\n return isCardsLinkScope(value) ? value : FALLBACK_CARDS_LINK_SCOPE\n}\n\nfunction getLinkProperties(href: string, newTab: boolean): Element['properties'] {\n return {\n href,\n ...(newTab\n ? {\n rel: ['noopener', 'noreferrer'],\n target: '_blank',\n }\n : {}),\n }\n}\n\nfunction makeSectionLink(href: string, newTab: boolean): Element {\n return {\n type: 'element',\n children: [],\n properties: {\n ...getLinkProperties(href, newTab),\n ariaLabel: 'Open card section',\n className: [\n 'not-prose absolute -inset-2 z-10 rounded-3xl focus:outline-none focus-visible:ring-2 focus-visible:ring-[color:var(--pmd-accent,color-mix(in_oklab,#22d3ee_calc(var(--pmd-scheme-dark,1)*100%),#0e7490))]',\n ],\n dataDirectiveLink: 'cards',\n },\n tagName: 'a',\n }\n}\n\nfunction hasCardLinkOverride(node: ContainerDirective): boolean {\n return ['href', 'linkScope', 'newTab'].some((name) => hasAttribute(node, name))\n}\n\nfunction isContainerDirective(node: unknown): node is ContainerDirective {\n return Boolean(\n node &&\n typeof node === 'object' &&\n 'type' in node &&\n (node as { type?: string }).type === 'containerDirective',\n )\n}\n\nexport function resolveCardGridColumns(node: ContainerDirective): CardGridColumns {\n const columns = node.attributes?.columns\n\n return isCardGridColumns(columns) ? columns : DEFAULT_CARD_GRID_COLUMNS\n}\n\nexport const cardsDirective = defineDirective({\n name: 'cards',\n allowedAttributes: ['cardTheme', 'columns', 'href', 'iconPalette', 'linkScope', 'newTab', 'palette', 'theme'],\n applyHast(node, config, { mergeClassNames }) {\n const columns =\n typeof node.properties.dataColumns === 'string'\n ? node.properties.dataColumns\n : DEFAULT_CARD_GRID_COLUMNS\n // Re-validate at the hast stage: this is where the live <a href> is built.\n const href = getSafeHref(node.properties.dataHref)\n if (!href) delete node.properties.dataHref\n const linkScope =\n typeof node.properties.dataLinkScope === 'string' && isCardsLinkScope(node.properties.dataLinkScope)\n ? node.properties.dataLinkScope\n : DEFAULT_CARDS_LINK_SCOPE\n const newTab = node.properties.dataNewTab === 'true'\n const theme = resolveDirectiveTheme(\n 'cards',\n typeof node.properties.dataTheme === 'string' ? node.properties.dataTheme : undefined,\n config.themes,\n )\n const cardTheme =\n typeof node.properties.dataCardTheme === 'string' ? node.properties.dataCardTheme : undefined\n const childLinkScope = linkScope === 'title' ? 'title' : DEFAULT_CARD_LINK_SCOPE\n\n for (const child of node.children) {\n if (child.type !== 'element' || child.properties?.dataVlLayout !== 'card') continue\n\n if (typeof child.properties.dataTheme !== 'string' && cardTheme)\n child.properties.dataTheme = cardTheme\n\n // Cards without a palette of their own paint their icons with the\n // grid's iconPalette (or palette); the grid's surface tokens are inherited.\n const iconPaletteDefault = node.properties.dataIconPalette ?? node.properties.dataPalette\n if (\n typeof iconPaletteDefault === 'string' &&\n typeof child.properties.dataPalette !== 'string' &&\n typeof child.properties.dataIconPalette !== 'string'\n )\n child.properties.dataIconPalette = iconPaletteDefault\n\n if (href && linkScope === 'section') {\n delete child.properties.dataHref\n delete child.properties.dataLinkScope\n delete child.properties.dataNewTab\n continue\n }\n\n if (!href) continue\n\n if (typeof child.properties.dataHref !== 'string') child.properties.dataHref = href\n if (typeof child.properties.dataLinkScope !== 'string')\n child.properties.dataLinkScope = childLinkScope\n if (typeof child.properties.dataNewTab !== 'string')\n child.properties.dataNewTab = newTab ? 'true' : 'false'\n }\n\n node.properties.dataTheme = theme.name\n if (href) {\n node.properties.dataLinkScope = linkScope\n node.properties.dataNewTab = newTab ? 'true' : 'false'\n }\n applyDirectivePalette(node, config)\n node.properties.className = mergeClassNames(\n // Spacing lives in the theme; the base only sets what every grid needs.\n 'grid [&>article]:my-0',\n href && linkScope === 'section'\n ? 'relative cursor-pointer [&>article]:transition-colors hover:[&>article]:border-[color:color-mix(in_oklab,rgb(255_255_255/0.15)_calc(var(--pmd-scheme-dark,1)*100%),rgb(0_0_0/0.2))] [&_a:not([data-directive-link])]:relative [&_a:not([data-directive-link])]:z-20'\n : undefined,\n theme.hookClassName,\n theme.modifierClassName,\n theme.classes,\n cardGridColumnClasses[isCardGridColumns(columns) ? columns : DEFAULT_CARD_GRID_COLUMNS],\n )\n\n if (href && linkScope === 'section') node.children = [makeSectionLink(href, newTab), ...node.children]\n },\n attributeTypes: {\n href: { type: 'url' },\n iconPalette: { type: 'palette' },\n palette: { type: 'palette' },\n },\n attributeValues: {\n columns: CARD_GRID_COLUMNS,\n linkScope: CARDS_LINK_SCOPES,\n newTab: ['true', 'false'],\n },\n container: {},\n defaultAttributes: {\n columns: DEFAULT_CARD_GRID_COLUMNS,\n linkScope: DEFAULT_CARDS_LINK_SCOPE,\n newTab: 'false',\n },\n description: 'Responsive card grid for docs and landing-page content.',\n editor: {\n detail: 'Layout directive',\n label: 'Cards',\n snippet:\n ':::cards{\\n columns=\"${3}\"\\n}\\n\\n:::card[${Title}]\\n${Content}\\n:::\\n\\n:::card[${Title}]\\n${Content}\\n:::\\n\\n:::\\n${}',\n },\n getMdastRenderProperties(node) {\n const href = getSafeHref(getAttribute(node, 'href'))\n\n return {\n ...getPaletteRenderProperties(node),\n dataCardTheme: typeof node.attributes?.cardTheme === 'string' ? node.attributes.cardTheme : undefined,\n dataColumns: resolveCardGridColumns(node),\n dataDirective: 'cards',\n dataHref: href,\n dataLinkScope: href || hasAttribute(node, 'linkScope') ? getCardsLinkScope(node) : undefined,\n dataNewTab: href && hasAttribute(node, 'newTab')\n ? getBooleanAttribute(node, 'newTab') ? 'true' : 'false'\n : undefined,\n dataTheme: typeof node.attributes?.theme === 'string' ? node.attributes.theme : 'default',\n }\n },\n kind: 'cards',\n lint: {\n // Read by the lint hook of `card` (see CardsLintState).\n open({ attributes, frame }) {\n const state: CardsLintState = {\n hasHref: typeof attributes.href === 'string' && isSafeHref(attributes.href.trim()),\n linkScope: typeof attributes.linkScope === 'string' ? attributes.linkScope : undefined,\n }\n\n frame.state = state\n return []\n },\n },\n public: true,\n sanitize: {\n section: [\n 'dataCardTheme',\n 'dataColumns',\n 'dataDirective',\n 'dataHref',\n 'dataIconPalette',\n 'dataLinkScope',\n 'dataNewTab',\n 'dataPalette',\n 'dataTheme',\n ],\n },\n supportsAttributes: true,\n tagName: 'section',\n themeAttributes: {\n cardTheme: 'card',\n theme: 'cards',\n },\n validateAttributes({ attributes }) {\n const warnings: string[] = [...getUnsafeHrefWarnings('cards', attributes)]\n\n if (typeof attributes.columns === 'string' && !isCardGridColumns(attributes.columns))\n warnings.push(\n `Invalid cards columns \"${attributes.columns}\". Falling back to \"${DEFAULT_CARD_GRID_COLUMNS}\".`,\n )\n\n if (typeof attributes.linkScope === 'string' && !isCardsLinkScope(attributes.linkScope))\n warnings.push(\n `Invalid cards linkScope \"${attributes.linkScope}\". Falling back to \"${FALLBACK_CARDS_LINK_SCOPE}\".`,\n )\n\n return warnings\n },\n validateMdast(node) {\n const warnings: string[] = []\n\n if (getSafeHref(getAttribute(node, 'href')) && getCardsLinkScope(node) === 'section') {\n const hasOverrides = node.children.some(\n (child) => isContainerDirective(child) && child.name === 'card' && hasCardLinkOverride(child),\n )\n\n if (hasOverrides)\n warnings.push(\n 'Directive \"cards\" with linkScope=\"section\" ignores child \"card\" link overrides.',\n )\n }\n\n return warnings\n },\n})\n"],"names":["applyDirectivePalette","getPaletteRenderProperties","resolveDirectiveTheme","defineDirective","getSafeHref","getUnsafeHrefWarnings","isSafeHref","DEFAULT_CARD_LINK_SCOPE","CARD_GRID_COLUMNS","DEFAULT_CARD_GRID_COLUMNS","CARDS_LINK_SCOPES","DEFAULT_CARDS_LINK_SCOPE","FALLBACK_CARDS_LINK_SCOPE","cardGridColumnClasses","auto","isCardGridColumns","value","includes","isCardsLinkScope","getAttribute","node","name","attributes","trim","undefined","getBooleanAttribute","hasAttribute","Object","prototype","hasOwnProperty","call","getCardsLinkScope","linkScope","getLinkProperties","href","newTab","rel","target","makeSectionLink","type","children","properties","ariaLabel","className","dataDirectiveLink","tagName","hasCardLinkOverride","some","isContainerDirective","Boolean","resolveCardGridColumns","columns","cardsDirective","allowedAttributes","applyHast","config","mergeClassNames","dataColumns","dataHref","dataLinkScope","dataNewTab","theme","dataTheme","themes","cardTheme","dataCardTheme","childLinkScope","child","dataVlLayout","iconPaletteDefault","dataIconPalette","dataPalette","hookClassName","modifierClassName","classes","attributeTypes","iconPalette","palette","attributeValues","container","defaultAttributes","description","editor","detail","label","snippet","getMdastRenderProperties","dataDirective","kind","lint","open","frame","state","hasHref","public","sanitize","section","supportsAttributes","themeAttributes","validateAttributes","warnings","push","validateMdast","hasOverrides"],"mappings":"AAKA,SAASA,qBAAqB,EAAEC,0BAA0B,QAAQ,gBAAe;AACjF,SAASC,qBAAqB,QAAQ,eAAc;AACpD,SAASC,eAAe,QAAQ,cAAa;AAC7C,SAASC,WAAW,EAAEC,qBAAqB,EAAEC,U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BAA0B,EAAE,CAAC;QAGpG,IAAI,OAAOa,WAAWU,SAAS,KAAK,YAAY,CAACd,iBAAiBI,WAAWU,SAAS,GACpFoE,SAASC,IAAI,CACX,CAAC,yBAAyB,EAAE/E,WAAWU,SAAS,CAAC,oBAAoB,EAAEpB,0BAA0B,EAAE,CAAC;QAGxG,OAAOwF;IACT;IACAE,eAAclF,IAAI;QAChB,MAAMgF,WAAqB,EAAE;QAE7B,IAAIhG,YAAYe,aAAaC,MAAM,YAAYW,kBAAkBX,UAAU,WAAW;YACpF,MAAMmF,eAAenF,KAAKoB,QAAQ,CAACO,IAAI,CACrC,CAACoB,QAAUnB,qBAAqBmB,UAAUA,MAAM9C,IAAI,KAAK,UAAUyB,oBAAoBqB;YAGzF,IAAIoC,cACFH,SAASC,IAAI,CACX;QAEN;QAEA,OAAOD;IACT;AACF,GAAE"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import type { ContainerDirective } from 'mdast-util-directive';
|
|
2
|
-
import type { DirectiveChild
|
|
3
|
-
export declare const cellDirective: LayoutDirectiveDefinition
|
|
2
|
+
import type { DirectiveChild } from '../types.js';
|
|
3
|
+
export declare const cellDirective: import("../types.js").LayoutDirectiveDefinition<"cell", "cell">;
|
|
4
4
|
export declare function makeCellDirective(children: DirectiveChild[]): ContainerDirective;
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { setDirectiveRenderData } from '../renderData.js';
|
|
2
2
|
import { resolveDirectiveTheme } from '../themes.js';
|
|
3
|
-
|
|
3
|
+
import { defineDirective } from '../types.js';
|
|
4
|
+
export const cellDirective = defineDirective({
|
|
4
5
|
name: 'cell',
|
|
5
6
|
allowedAttributes: [
|
|
6
7
|
'theme'
|
|
@@ -10,6 +11,7 @@ export const cellDirective = {
|
|
|
10
11
|
node.properties.dataTheme = theme.name;
|
|
11
12
|
node.properties.className = mergeClassNames('[&>:first-child]:mt-0 [&>:last-child]:mb-0', theme.hookClassName, theme.modifierClassName, theme.classes, config.columnClassName);
|
|
12
13
|
},
|
|
14
|
+
container: {},
|
|
13
15
|
editor: {
|
|
14
16
|
detail: 'Layout directive',
|
|
15
17
|
label: 'Layout cell',
|
|
@@ -23,14 +25,18 @@ export const cellDirective = {
|
|
|
23
25
|
};
|
|
24
26
|
},
|
|
25
27
|
kind: 'cell',
|
|
26
|
-
openMarker: ':::cell',
|
|
27
28
|
public: true,
|
|
29
|
+
sanitize: {
|
|
30
|
+
div: [
|
|
31
|
+
'dataTheme'
|
|
32
|
+
]
|
|
33
|
+
},
|
|
28
34
|
supportsAttributes: true,
|
|
29
35
|
tagName: 'div',
|
|
30
36
|
themeAttributes: {
|
|
31
37
|
theme: 'cell'
|
|
32
38
|
}
|
|
33
|
-
};
|
|
39
|
+
});
|
|
34
40
|
export function makeCellDirective(children) {
|
|
35
41
|
const node = {
|
|
36
42
|
name: 'cell',
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/directives/definitions/cell.ts"],"sourcesContent":["import type { ContainerDirective } from 'mdast-util-directive'\n\nimport type { DirectiveChild
|
|
1
|
+
{"version":3,"sources":["../../../src/directives/definitions/cell.ts"],"sourcesContent":["import type { ContainerDirective } from 'mdast-util-directive'\n\nimport type { DirectiveChild } from '../types.js'\n\nimport { setDirectiveRenderData } from '../renderData.js'\nimport { resolveDirectiveTheme } from '../themes.js'\nimport { defineDirective } from '../types.js'\n\nexport const cellDirective = defineDirective({\n name: 'cell',\n allowedAttributes: ['theme'],\n applyHast(node, config, { mergeClassNames }) {\n const theme = resolveDirectiveTheme(\n 'cell',\n typeof node.properties.dataTheme === 'string' ? node.properties.dataTheme : undefined,\n config.themes,\n )\n\n node.properties.dataTheme = theme.name\n node.properties.className = mergeClassNames(\n '[&>:first-child]:mt-0 [&>:last-child]:mb-0',\n theme.hookClassName,\n theme.modifierClassName,\n theme.classes,\n config.columnClassName,\n )\n },\n container: {},\n editor: {\n detail: 'Layout directive',\n label: 'Layout cell',\n snippet: ':::cell\\n${Content}\\n:::\\n${}',\n },\n getMdastRenderProperties(node) {\n // Leave an unthemed cell unset so its 2col/3col parent can apply cellTheme;\n // applyHast falls back to the default theme.\n return {\n dataTheme: typeof node.attributes?.theme === 'string' ? node.attributes.theme : undefined,\n }\n },\n kind: 'cell',\n public: true,\n sanitize: {\n div: ['dataTheme'],\n },\n supportsAttributes: true,\n tagName: 'div',\n themeAttributes: {\n theme: 'cell',\n },\n})\n\nexport function makeCellDirective(children: DirectiveChild[]): ContainerDirective {\n const node: ContainerDirective = {\n name: 'cell',\n type: 'containerDirective',\n attributes: {},\n children,\n data: {},\n }\n\n setDirectiveRenderData(node, cellDirective)\n\n return node\n}\n"],"names":["setDirectiveRenderData","resolveDirectiveTheme","defineDirective","cellDirective","name","allowedAttributes","applyHast","node","config","mergeClassNames","theme","properties","dataTheme","undefined","themes","className","hookClassName","modifierClassName","classes","columnClassName","container","editor","detail","label","snippet","getMdastRenderProperties","attributes","kind","public","sanitize","div","supportsAttributes","tagName","themeAttributes","makeCellDirective","children","type","data"],"mappings":"AAIA,SAASA,sBAAsB,QAAQ,mBAAkB;AACzD,SAASC,qBAAqB,QAAQ,eAAc;AACpD,SAASC,eAAe,QAAQ,cAAa;AAE7C,OAAO,MAAMC,gBAAgBD,gBAAgB;IAC3CE,MAAM;IACNC,mBAAmB;QAAC;KAAQ;IAC5BC,WAAUC,IAAI,EAAEC,MAAM,EAAE,EAAEC,eAAe,EAAE;QACzC,MAAMC,QAAQT,sBACZ,QACA,OAAOM,KAAKI,UAAU,CAACC,SAAS,KAAK,WAAWL,KAAKI,UAAU,CAACC,SAAS,GAAGC,WAC5EL,OAAOM,MAAM;QAGfP,KAAKI,UAAU,CAACC,SAAS,GAAGF,MAAMN,IAAI;QACtCG,KAAKI,UAAU,CAACI,SAAS,GAAGN,gBAC1B,8CACAC,MAAMM,aAAa,EACnBN,MAAMO,iBAAiB,EACvBP,MAAMQ,OAAO,EACbV,OAAOW,eAAe;IAE1B;IACAC,WAAW,CAAC;IACZC,QAAQ;QACNC,QAAQ;QACRC,OAAO;QACPC,SAAS;IACX;IACAC,0BAAyBlB,IAAI;QAC3B,4EAA4E;QAC5E,6CAA6C;QAC7C,OAAO;YACLK,WAAW,OAAOL,KAAKmB,UAAU,EAAEhB,UAAU,WAAWH,KAAKmB,UAAU,CAAChB,KAAK,GAAGG;QAClF;IACF;IACAc,MAAM;IACNC,QAAQ;IACRC,UAAU;QACRC,KAAK;YAAC;SAAY;IACpB;IACAC,oBAAoB;IACpBC,SAAS;IACTC,iBAAiB;QACfvB,OAAO;IACT;AACF,GAAE;AAEF,OAAO,SAASwB,kBAAkBC,QAA0B;IAC1D,MAAM5B,OAA2B;QAC/BH,MAAM;QACNgC,MAAM;QACNV,YAAY,CAAC;QACbS;QACAE,MAAM,CAAC;IACT;IAEArC,uBAAuBO,MAAMJ;IAE7B,OAAOI;AACT"}
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
|
|
2
|
-
export declare const
|
|
3
|
-
export declare const
|
|
4
|
-
export declare const columnDirectives: LayoutDirectiveDefinition[];
|
|
1
|
+
export declare const twoColumnDirective: import("../types.js").LayoutDirectiveDefinition<"2col", "grid">;
|
|
2
|
+
export declare const threeColumnDirective: import("../types.js").LayoutDirectiveDefinition<"3col", "grid">;
|
|
3
|
+
export declare const columnDirectives: readonly [import("../types.js").LayoutDirectiveDefinition<"2col", "grid">, import("../types.js").LayoutDirectiveDefinition<"3col", "grid">];
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { resolveDirectiveTheme } from '../themes.js';
|
|
2
|
+
import { defineDirective } from '../types.js';
|
|
2
3
|
import { makeCellDirective } from './cell.js';
|
|
3
4
|
function isContainerDirective(node) {
|
|
4
5
|
return Boolean(node && typeof node === 'object' && 'type' in node && node.type === 'containerDirective');
|
|
@@ -36,7 +37,7 @@ function groupGridChildren(children, cellHeadingDepth, context) {
|
|
|
36
37
|
return grouped;
|
|
37
38
|
}
|
|
38
39
|
function createColumnDirective(name, columns) {
|
|
39
|
-
return {
|
|
40
|
+
return defineDirective({
|
|
40
41
|
name,
|
|
41
42
|
allowedAttributes: [
|
|
42
43
|
'cellTheme',
|
|
@@ -53,6 +54,13 @@ function createColumnDirective(name, columns) {
|
|
|
53
54
|
const hasExplicitCells = node.children.some((child)=>child.type === 'element' && child.properties?.dataVlLayout === 'cell');
|
|
54
55
|
if (!hasExplicitCells) node.children = groupChildrenIntoCells(node.children, config.columnClassName, resolvedCellTheme);
|
|
55
56
|
},
|
|
57
|
+
container: {
|
|
58
|
+
closeLabel: 'endcol',
|
|
59
|
+
closeMarkers: [
|
|
60
|
+
':::',
|
|
61
|
+
':::endcol'
|
|
62
|
+
]
|
|
63
|
+
},
|
|
56
64
|
editor: {
|
|
57
65
|
detail: 'Layout directive',
|
|
58
66
|
label: `${columns}-column layout`,
|
|
@@ -66,8 +74,14 @@ function createColumnDirective(name, columns) {
|
|
|
66
74
|
};
|
|
67
75
|
},
|
|
68
76
|
kind: 'grid',
|
|
69
|
-
openMarker: `:::${name}`,
|
|
70
77
|
public: true,
|
|
78
|
+
sanitize: {
|
|
79
|
+
div: [
|
|
80
|
+
'dataCellTheme',
|
|
81
|
+
'dataTheme',
|
|
82
|
+
'dataVlCellHeadingDepth'
|
|
83
|
+
]
|
|
84
|
+
},
|
|
71
85
|
supportsAttributes: true,
|
|
72
86
|
tagName: 'div',
|
|
73
87
|
themeAttributes: {
|
|
@@ -78,7 +92,7 @@ function createColumnDirective(name, columns) {
|
|
|
78
92
|
const cellHeadingDepth = resolveCellHeadingDepth(node);
|
|
79
93
|
node.children = groupGridChildren(node.children, cellHeadingDepth, context);
|
|
80
94
|
}
|
|
81
|
-
};
|
|
95
|
+
});
|
|
82
96
|
}
|
|
83
97
|
export const twoColumnDirective = createColumnDirective('2col', 2);
|
|
84
98
|
export const threeColumnDirective = createColumnDirective('3col', 3);
|