@onderwijsin/nuxt-markdown-renderer 0.2.3 → 0.3.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 (35) hide show
  1. package/README.md +192 -27
  2. package/dist/metadata/runtime/app/components/renderer/MarkdownAnchor.vue +17 -0
  3. package/dist/metadata/runtime/app/components/renderer/MarkdownItemList.vue +52 -0
  4. package/dist/metadata/runtime/app/components/renderer/MarkdownRelatedItemList.vue +22 -0
  5. package/dist/metadata/runtime/shared/types.ts +41 -0
  6. package/dist/module.d.mts +14 -2
  7. package/dist/module.json +1 -1
  8. package/dist/module.mjs +16 -4
  9. package/dist/runtime/app/components/renderer/MarkdownAnchor.d.vue.ts +7 -0
  10. package/dist/runtime/app/components/renderer/MarkdownAnchor.vue +14 -0
  11. package/dist/runtime/app/components/renderer/MarkdownAnchor.vue.d.ts +7 -0
  12. package/dist/runtime/app/components/renderer/MarkdownButton.d.vue.ts +2 -2
  13. package/dist/runtime/app/components/renderer/MarkdownButton.vue.d.ts +2 -2
  14. package/dist/runtime/app/components/renderer/MarkdownCallout.d.vue.ts +1 -1
  15. package/dist/runtime/app/components/renderer/MarkdownCallout.vue.d.ts +1 -1
  16. package/dist/runtime/app/components/renderer/MarkdownItemList.d.vue.ts +12 -0
  17. package/dist/runtime/app/components/renderer/MarkdownItemList.vue +44 -0
  18. package/dist/runtime/app/components/renderer/MarkdownItemList.vue.d.ts +12 -0
  19. package/dist/runtime/app/components/renderer/MarkdownRelatedItemList.d.vue.ts +8 -0
  20. package/dist/runtime/app/components/renderer/MarkdownRelatedItemList.vue +16 -0
  21. package/dist/runtime/app/components/renderer/MarkdownRelatedItemList.vue.d.ts +8 -0
  22. package/dist/runtime/app/utils/component-manifest.js +1 -1
  23. package/dist/runtime/app/utils/map-related-item.d.ts +7 -0
  24. package/dist/runtime/app/utils/map-related-item.js +2 -0
  25. package/dist/runtime/app/utils/map-related-items.d.ts +11 -0
  26. package/dist/runtime/app/utils/map-related-items.js +7 -0
  27. package/dist/runtime/app/utils/resolve-related-item-path.d.ts +7 -0
  28. package/dist/runtime/app/utils/resolve-related-item-path.js +2 -0
  29. package/dist/runtime/index.css +1 -1
  30. package/dist/runtime/index.d.ts +1 -1
  31. package/dist/runtime/server/utils/component-metadata-handler.d.ts +3 -3
  32. package/dist/runtime/server/utils/metadata.d.ts +2 -2
  33. package/dist/runtime/server/utils/metadata.js +1 -1
  34. package/dist/runtime/shared/types.d.ts +30 -0
  35. package/package.json +2 -2
package/README.md CHANGED
@@ -6,7 +6,8 @@ components, and component metadata for the Directus Markdown editor.
6
6
  ## Features
7
7
 
8
8
  - Renders Markdown and MDC through the global `MarkdownRenderer` component.
9
- - Includes `MarkdownButton`, `MarkdownCallout`, and the persisted `Reference` node.
9
+ - Includes `MarkdownItemList`, `MarkdownRelatedItemList`, `MarkdownAnchor`, `MarkdownButton`,
10
+ `MarkdownCallout`, and the persisted `Reference` node.
10
11
  - Discovers application renderer components through Nuxt's component registry.
11
12
  - Lazily imports custom components and optionally restricts them with named component sets.
12
13
  - Exposes Directus-compatible component metadata, including CORS preflight handling.
@@ -66,11 +67,14 @@ Import the module stylesheet in the consuming application's main CSS file after
66
67
 
67
68
  The built-in MDC nodes are:
68
69
 
69
- | Markdown node | Vue implementation | Editor label | Behavior |
70
- | ----------------- | ------------------- | ------------ | -------------------------------------------- |
71
- | `MarkdownButton` | `MarkdownButton` | Button | Inline Nuxt UI button or link. |
72
- | `MarkdownCallout` | `MarkdownCallout` | Callout | Block Nuxt UI alert with editable content. |
73
- | `Reference` | `MarkdownReference` | — | Directus item reference; excluded from menu. |
70
+ | Markdown node | Vue implementation | Editor label | Behavior |
71
+ | ----------------- | ------------------------- | ------------ | -------------------------------------------- |
72
+ | `ItemList` | `MarkdownItemList` | Item list | Stacked page cards with optional dividers. |
73
+ | `MarkdownAnchor` | `MarkdownAnchor` | Anchor | Invisible block target for fragment links. |
74
+ | `MarkdownButton` | `MarkdownButton` | Button | Inline Nuxt UI button or link. |
75
+ | `MarkdownCallout` | `MarkdownCallout` | Callout | Block Nuxt UI alert with editable content. |
76
+ | `Reference` | `MarkdownReference` | — | Directus item reference; excluded from menu. |
77
+ | `RelatedItemList` | `MarkdownRelatedItemList` | — | CMS selections rendered as mapped item rows. |
74
78
 
75
79
  The built-in button's icon editor metadata uses the `lucide` collection by default. To offer other
76
80
  icon collections in component metadata, override the relevant renderer component and define its own
@@ -83,6 +87,151 @@ For example:
83
87
  :MarkdownButton{label="documentation" to="/docs" variant="soft"}. ::
84
88
  ```
85
89
 
90
+ ### Fragment anchors
91
+
92
+ Insert an invisible block anchor with a required string `id` and no slots:
93
+
94
+ ```mdc
95
+ ::MarkdownAnchor{id="existing-fragment"}
96
+ ::
97
+ ```
98
+
99
+ This renders `<span id="existing-fragment" class="markdown-anchor"></span>`. Link to it with
100
+ `[Jump to section](#existing-fragment)`. Include `MarkdownAnchor` in any component set used to
101
+ render it.
102
+
103
+ The module stylesheet uses `display: block` and `scroll-margin-top: 100px` to give the empty span a
104
+ −100px scroll offset without adding visible content or layout space. Override the offset in your own
105
+ CSS after the module stylesheet:
106
+
107
+ ```css
108
+ .markdown-anchor {
109
+ scroll-margin-top: 64px;
110
+ }
111
+ ```
112
+
113
+ ### Item lists
114
+
115
+ The `ItemList` node is rendered by `MarkdownItemList`, wrapping Nuxt UI's `UPageList` and ghost
116
+ `UPageCard` components. It accepts a required `items` array and an optional boolean `divide` prop
117
+ (default `false`). It exposes no content slots. All item fields are optional:
118
+
119
+ | Field | Type | Behavior |
120
+ | ------------- | --------- | ------------------------------------------------------------------ |
121
+ | `image` | `string` | Image URL, displayed instead of the icon when supplied. |
122
+ | `title` | `string` | Item heading. |
123
+ | `description` | `string` | Supporting text. |
124
+ | `to` | `string` | Internal path or full URL. Omit to render an unlinked item. |
125
+ | `external` | `boolean` | Opens `to` as an external link in a new tab. Ignored without `to`. |
126
+ | `icon` | `string` | Iconify icon name, used when no image is supplied. |
127
+
128
+ ```mdc
129
+ ::ItemList
130
+ ---
131
+ divide: true
132
+ items:
133
+ - title: Our services
134
+ description: Explore how we can help.
135
+ image: /images/services.jpg
136
+ to: /services
137
+ - title: Nuxt UI
138
+ icon: i-lucide-external-link
139
+ to: https://ui.nuxt.com
140
+ external: true
141
+ ---
142
+ ::
143
+ ```
144
+
145
+ Include `ItemList` in any component set used to render it. Editor metadata provides image, URL, and
146
+ Lucide icon controls for the nested fields. Conditional field visibility is not supported by the
147
+ current metadata contract: `icon` and `external` remain visible in the editor; rendering gives
148
+ images precedence and ignores `external` when `to` is empty.
149
+
150
+ ### Related item lists
151
+
152
+ The `RelatedItemList` node is rendered by `MarkdownRelatedItemList`, reusing `MarkdownItemList` to
153
+ render CMS-selected content in its original order. Its only prop is the required `items` array; it
154
+ has no slots or additional display props. Like `MarkdownReference` → `Reference`, the Vue names are
155
+ prefixed while persisted Markdown keeps the `ItemList` and `RelatedItemList` node names. Component
156
+ sets use those persisted node names. Each selection has a required `collection: string` and
157
+ `item: string | number`, plus optional `label: string` and `data: Record<string, unknown>`.
158
+
159
+ ```mdc
160
+ ::RelatedItemList
161
+ ---
162
+ items:
163
+ - collection: articles
164
+ item: article-7
165
+ label: Becoming a teacher
166
+ data:
167
+ slug: becoming-a-teacher
168
+ summary: Explore the routes into teaching.
169
+ image: image-uuid
170
+ - collection: programs
171
+ item: 42
172
+ label: Teaching traineeship
173
+ data:
174
+ slug: teaching-traineeship
175
+ duration: 24
176
+ ---
177
+ ::
178
+ ```
179
+
180
+ Set `markdownRenderer.relatedItemListConfig.mapItem` and `.linkResolver` to Nuxt-resolvable callback
181
+ file paths. Without configuration, rows display their source labels and remain unlinked; the
182
+ renderer does not guess snapshot fields, image URLs, or application routes.
183
+
184
+ ```ts
185
+ // app/utils/mapRelatedItem.ts
186
+ import type { MapRelatedItem } from "@onderwijsin/nuxt-markdown-renderer/runtime";
187
+
188
+ const mapRelatedItem: MapRelatedItem = (item) => {
189
+ const { summary, duration, image } = item.data ?? {};
190
+ return {
191
+ description:
192
+ typeof summary === "string"
193
+ ? summary
194
+ : typeof duration === "number"
195
+ ? `${duration} months`
196
+ : undefined,
197
+ image:
198
+ typeof image === "string"
199
+ ? `https://cms.example.com/assets/${encodeURIComponent(image)}`
200
+ : undefined
201
+ };
202
+ };
203
+
204
+ export default mapRelatedItem;
205
+ ```
206
+
207
+ ```ts
208
+ // app/utils/resolveRelatedItemPath.ts
209
+ import type { ResolveRelatedItemPath } from "@onderwijsin/nuxt-markdown-renderer/runtime";
210
+
211
+ const resolveRelatedItemPath: ResolveRelatedItemPath = (item) => {
212
+ const slug = item.data?.slug;
213
+ if (typeof slug !== "string") return undefined;
214
+ if (item.collection === "articles") return `/articles/${encodeURIComponent(slug)}`;
215
+ if (item.collection === "programs") return `/programs/${encodeURIComponent(slug)}`;
216
+ return undefined;
217
+ };
218
+
219
+ export default resolveRelatedItemPath;
220
+ ```
221
+
222
+ Both callbacks are optional, synchronous, and receive the full selection. `mapItem` returns any
223
+ `ItemListItem` fields except `to`; the source label remains the title unless overridden.
224
+ `linkResolver` returns the `to` string, or `undefined` to keep a row unlinked. The `/runtime`
225
+ entrypoint exports `RelatedItem`, `ItemListItem`, `MapRelatedItem`, and `ResolveRelatedItemPath`
226
+ types. Callback code is bundled for SSR and client rendering; do not put secrets in it.
227
+
228
+ Like `Reference`, this node resolves independently of component sets and is excluded from generic
229
+ editor metadata because the CMS owns its selection UI. It accepts no additional attributes,
230
+ including `divide`, and uses the default undivided layout. Like `Reference`, related items use a
231
+ TypeScript contract without runtime prop validation. Consumers own validation at their CMS/content
232
+ ingestion boundary and conversion of collection-specific snapshot fields. Snapshots are rendered as
233
+ provided, without fetching data.
234
+
86
235
  ## Configuration
87
236
 
88
237
  ```ts
@@ -95,22 +244,37 @@ export default defineNuxtConfig({
95
244
  article: ["MarkdownButton", "MarkdownCallout", "MarkdownHero"],
96
245
  landing: ["MarkdownButton", "MarkdownHero"]
97
246
  },
98
- resolveReferencePath: "~/utils/resolveReferencePath",
247
+ referenceConfig: { linkResolver: "~/utils/resolveReferencePath" },
248
+ relatedItemListConfig: {
249
+ mapItem: "~/utils/mapRelatedItem",
250
+ linkResolver: "~/utils/resolveRelatedItemPath"
251
+ },
99
252
  videoBaseUrl: "https://media.example.com/assets/",
100
253
  corsOrigin: "https://directus.example.com"
101
254
  }
102
255
  });
103
256
  ```
104
257
 
105
- | Option | Type | Default | Description |
106
- | ---------------------- | -------------------------- | ------------ | ----------------------------------------------------------------- |
107
- | `enabled` | `boolean` | `true` | Enables component, manifest, and metadata endpoint registration. |
108
- | `scopeComponentMeta` | `boolean` | `true` | Limits global component metadata extraction to renderer sources. |
109
- | `componentsDir` | `string` | `"renderer"` | Directory below `app/components/` containing renderer components. |
110
- | `componentSets` | `Record<string, string[]>` | `{}` | Named allowlists used by rendering and metadata endpoints. |
111
- | `resolveReferencePath` | `string` | unset | Nuxt-resolvable path to a default-exported Reference resolver. |
112
- | `videoBaseUrl` | `string` | unset | Absolute base URL for relative video sources. |
113
- | `corsOrigin` | `string \| string[]` | `"*"` | Origins allowed to call the metadata endpoint from a browser. |
258
+ | Option | Type | Default | Description |
259
+ | ----------------------- | --------------------------------------------- | ------------ | ----------------------------------------------------------------- |
260
+ | `enabled` | `boolean` | `true` | Enables component, manifest, and metadata endpoint registration. |
261
+ | `scopeComponentMeta` | `boolean` | `true` | Limits global component metadata extraction to renderer sources. |
262
+ | `componentsDir` | `string` | `"renderer"` | Directory below `app/components/` containing renderer components. |
263
+ | `componentSets` | `Record<string, string[]>` | `{}` | Named allowlists used by rendering and metadata endpoints. |
264
+ | `referenceConfig` | `{ linkResolver?: string }` | unset | Reference callback file paths. |
265
+ | `relatedItemListConfig` | `{ mapItem?: string; linkResolver?: string }` | unset | Related-list callback file paths. |
266
+ | `videoBaseUrl` | `string` | unset | Absolute base URL for relative video sources. |
267
+ | `corsOrigin` | `string \| string[]` | `"*"` | Origins allowed to call the metadata endpoint from a browser. |
268
+
269
+ Both configuration objects and their callback paths are optional. Each path resolves through Nuxt
270
+ aliases and extensions and points to a default-exported function. A missing reference link resolver
271
+ keeps references as plain text; a missing related-item mapper keeps source labels; a missing
272
+ related-item link resolver keeps rows unlinked. Callback code runs during SSR and in the browser.
273
+
274
+ **Breaking migration:** replace `resolveReferencePath: "~/utils/resolveReferencePath"` with
275
+ `referenceConfig: { linkResolver: "~/utils/resolveReferencePath" }`. The resolver file, its function
276
+ signature, and stored `Reference` nodes remain unchanged. The old option is rejected rather than
277
+ silently ignored. This breaking configuration change is intentionally released as a minor.
114
278
 
115
279
  A single `corsOrigin` string is accepted and normalized to an allowlist. Use `"null"` only when a
116
280
  sandboxed or local client intentionally sends an opaque origin.
@@ -237,8 +401,9 @@ Component-set values use the public Markdown node names. Passing `component-set=
237
401
  URL returns only that set. An unknown set prevents custom component resolution and its metadata URL
238
402
  returns HTTP 404.
239
403
 
240
- The reserved `Reference` node always resolves regardless of the selected set, including empty or
241
- unknown sets. It remains excluded from all metadata endpoints and does not need a set entry.
404
+ The CMS-owned `Reference` and `RelatedItemList` nodes always resolve regardless of the selected set,
405
+ including empty or unknown sets. They remain excluded from all metadata endpoints and need no set
406
+ entry.
242
407
 
243
408
  Omit `component-set` to allow every discovered renderer component.
244
409
 
@@ -251,7 +416,7 @@ https://website.example.com/api/markdown-renderer/components/article
251
416
  ```
252
417
 
253
418
  The endpoint returns a bare component array. Omit the final set name to return all discovered
254
- components. `Reference` is deliberately omitted because the Directus editor owns that reserved node.
419
+ components. `Reference` and `RelatedItemList` are omitted because the CMS owns those editor nodes.
255
420
  Both `GET` and browser `OPTIONS` preflight requests are handled.
256
421
 
257
422
  The endpoint is public and sends no authentication challenge. CORS controls which browser origins
@@ -296,14 +461,14 @@ auto-imports, templates, and routes are not registered.
296
461
 
297
462
  ## Troubleshooting
298
463
 
299
- | Symptom | Check |
300
- | ------------------------------------ | --------------------------------------------------------------------------- |
301
- | Custom component renders as Markdown | Put it directly in `app/components/<componentsDir>/` and use its Nuxt name. |
302
- | Component is missing for one field | Include its public name in the selected `componentSets` entry. |
303
- | Metadata URL returns 404 | The requested component-set name is not configured. |
304
- | Directus reports a CORS failure | Add the exact Directus origin to `corsOrigin`, including scheme and port. |
305
- | Metadata omits a custom component | Ensure the SFC is discoverable and exposes parseable component metadata. |
306
- | Reference is not linked | Configure `resolveReferencePath` and return a route for that collection. |
464
+ | Symptom | Check |
465
+ | ------------------------------------ | -------------------------------------------------------------------------------- |
466
+ | Custom component renders as Markdown | Put it directly in `app/components/<componentsDir>/` and use its Nuxt name. |
467
+ | Component is missing for one field | Include its public name in the selected `componentSets` entry. |
468
+ | Metadata URL returns 404 | The requested component-set name is not configured. |
469
+ | Directus reports a CORS failure | Add the exact Directus origin to `corsOrigin`, including scheme and port. |
470
+ | Metadata omits a custom component | Ensure the SFC is discoverable and exposes parseable component metadata. |
471
+ | Reference is not linked | Configure `referenceConfig.linkResolver` and return a route for that collection. |
307
472
 
308
473
  ## Development
309
474
 
@@ -0,0 +1,17 @@
1
+ <script setup lang="ts">
2
+ import { defineEditorComponentSchema } from "../../utils/define-editor-component-schema";
3
+
4
+ defineEditorComponentSchema({
5
+ label: "Anchor",
6
+ type: "block"
7
+ });
8
+
9
+ defineProps<{
10
+ /** Fragment identifier targeted by anchor links. */
11
+ id: string;
12
+ }>();
13
+ </script>
14
+
15
+ <template>
16
+ <span :id="id" class="markdown-anchor" />
17
+ </template>
@@ -0,0 +1,52 @@
1
+ <script setup lang="ts">
2
+ import { defineEditorComponentSchema } from "../../utils/define-editor-component-schema";
3
+ import type { ItemListItem } from "../../../shared/types";
4
+
5
+ defineEditorComponentSchema({
6
+ label: "Item list",
7
+ type: "block",
8
+ properties: {
9
+ items: {
10
+ items: {
11
+ properties: {
12
+ image: { input: "image" },
13
+ to: { input: "url" },
14
+ icon: { input: { type: "icon", collections: ["lucide"] } }
15
+ }
16
+ }
17
+ }
18
+ }
19
+ });
20
+
21
+ withDefaults(
22
+ defineProps<{
23
+ /** Whether to show dividers between items. */
24
+ divide?: boolean;
25
+ /** Items displayed as stacked page cards. */
26
+ items: ItemListItem[];
27
+ }>(),
28
+ { divide: false }
29
+ );
30
+ </script>
31
+
32
+ <template>
33
+ <UPageList as="ul" :divide="divide">
34
+ <UPageCard
35
+ v-for="(item, index) in items"
36
+ :key="index"
37
+ as="li"
38
+ variant="ghost"
39
+ :title="item.title"
40
+ :description="item.description"
41
+ :to="item.to"
42
+ :external="!!item.to && item.external"
43
+ :target="item.to && item.external ? '_blank' : undefined"
44
+ :icon="item.image ? undefined : item.icon"
45
+ :ui="{ wrapper: 'flex-row items-center gap-4', leading: 'mb-0' }"
46
+ >
47
+ <template v-if="item.image" #leading>
48
+ <img :src="item.image" alt="" loading="lazy" class="size-12 rounded-md object-cover" />
49
+ </template>
50
+ </UPageCard>
51
+ </UPageList>
52
+ </template>
@@ -0,0 +1,22 @@
1
+ <script setup lang="ts">
2
+ import { computed } from "vue";
3
+
4
+ import mapItem from "#markdown-renderer/related-item-mapper";
5
+ import linkResolver from "#markdown-renderer/related-item-resolver";
6
+ import type { RelatedItem } from "../../../shared/types";
7
+ import { mapRelatedItems } from "../../utils/map-related-items";
8
+ import MarkdownItemList from "./MarkdownItemList.vue";
9
+
10
+ defineOptions({ inheritAttrs: false });
11
+
12
+ const props = defineProps<{
13
+ /** Ordered CMS selections with collection-specific source snapshots. */
14
+ items: RelatedItem[];
15
+ }>();
16
+
17
+ const mappedItems = computed(() => mapRelatedItems(props.items, { mapItem, linkResolver }));
18
+ </script>
19
+
20
+ <template>
21
+ <MarkdownItemList :items="mappedItems" />
22
+ </template>
@@ -0,0 +1,41 @@
1
+ /** One persisted CMS selection, retaining string or numeric primary keys. */
2
+ export interface RelatedItem {
3
+ /** Source collection name. */
4
+ collection: string;
5
+ /** Source item primary key. */
6
+ item: string | number;
7
+ /** Source display label. */
8
+ label?: string;
9
+ /** Collection-specific source snapshot supplied by the CMS. */
10
+ data?: Record<string, unknown>;
11
+ }
12
+
13
+ /** Display fields shared by the item-list components. */
14
+ export interface ItemListItem {
15
+ /** Image URL; takes precedence over the icon. */
16
+ image?: string;
17
+ /** Item title. */
18
+ title?: string;
19
+ /** Supporting text below the title. */
20
+ description?: string;
21
+ /** Link destination, either an internal path or a full URL. */
22
+ to?: string;
23
+ /** Whether to open the destination as an external link in a new tab. */
24
+ external?: boolean;
25
+ /** Iconify icon name, displayed when no image is provided. */
26
+ icon?: string;
27
+ }
28
+
29
+ /** Maps a CMS selection to display fields; the title defaults to the source label. */
30
+ export type MapRelatedItem = (item: RelatedItem) => Omit<ItemListItem, "to">;
31
+
32
+ /** Resolves a CMS selection's destination, or leaves the row unlinked. */
33
+ export type ResolveRelatedItemPath = (item: RelatedItem) => string | undefined;
34
+
35
+ export type ResolveReferencePath = (
36
+ collection: string,
37
+ item: string,
38
+ label?: string,
39
+ text?: string,
40
+ data?: Record<string, unknown>
41
+ ) => string | undefined;
package/dist/module.d.mts CHANGED
@@ -6,7 +6,13 @@ declare const _default: _nuxt_schema.NuxtModule<{
6
6
  scopeComponentMeta?: boolean | undefined;
7
7
  componentsDir?: string | undefined;
8
8
  componentSets?: Record<string, string[]> | undefined;
9
- resolveReferencePath?: string | undefined;
9
+ referenceConfig?: {
10
+ linkResolver?: string | undefined;
11
+ } | undefined;
12
+ relatedItemListConfig?: {
13
+ mapItem?: string | undefined;
14
+ linkResolver?: string | undefined;
15
+ } | undefined;
10
16
  videoBaseUrl?: string | undefined;
11
17
  corsOrigin?: string | string[] | undefined;
12
18
  }, {
@@ -14,7 +20,13 @@ declare const _default: _nuxt_schema.NuxtModule<{
14
20
  scopeComponentMeta?: boolean | undefined;
15
21
  componentsDir?: string | undefined;
16
22
  componentSets?: Record<string, string[]> | undefined;
17
- resolveReferencePath?: string | undefined;
23
+ referenceConfig?: {
24
+ linkResolver?: string | undefined;
25
+ } | undefined;
26
+ relatedItemListConfig?: {
27
+ mapItem?: string | undefined;
28
+ linkResolver?: string | undefined;
29
+ } | undefined;
18
30
  videoBaseUrl?: string | undefined;
19
31
  corsOrigin?: string | string[] | undefined;
20
32
  }, false>;
package/dist/module.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@onderwijsin/nuxt-markdown-renderer",
3
3
  "configKey": "markdownRenderer",
4
- "version": "0.2.3",
4
+ "version": "0.3.0",
5
5
  "compatibility": {
6
6
  "nuxt": "^4.0.0"
7
7
  },
package/dist/module.mjs CHANGED
@@ -6,11 +6,14 @@ import { isRecord, isString, fromEntries, toEntries } from '@onderwijsin/nuxt-mo
6
6
  import { z } from 'zod';
7
7
  import { EditorComponentInputSchema, EditorComponentEnrichmentSchema, SPECIAL_INPUT_TAG_NAME } from '../dist/schema/editor-component-schema.js';
8
8
 
9
- const version = "0.2.3";
9
+ const version = "0.3.0";
10
10
 
11
11
  function resolveRendererNodeName(filePath) {
12
12
  const fileName = basename(filePath, extname(filePath));
13
- return fileName === "MarkdownReference" ? "Reference" : fileName;
13
+ if (fileName === "MarkdownReference") return "Reference";
14
+ if (fileName === "MarkdownItemList") return "ItemList";
15
+ if (fileName === "MarkdownRelatedItemList") return "RelatedItemList";
16
+ return fileName;
14
17
  }
15
18
  function selectRendererComponents(components, directories) {
16
19
  const rendererDirectories = new Set(directories.map((directory) => resolve(directory)));
@@ -107,13 +110,20 @@ ${z.prettifyError(parsed.error)}`
107
110
  }
108
111
 
109
112
  const origin = z.string().trim().min(1);
113
+ const callbackPath = z.string().trim().min(1);
110
114
  const markdownRendererOptionsSchema = z.strictObject({
111
115
  enabled: enabled.default(true),
112
116
  /** Scope the global component-meta parser to renderer sources; disable for application metadata. */
113
117
  scopeComponentMeta: z.boolean().default(true),
114
118
  componentsDir: z.string().trim().min(1).default("renderer"),
115
119
  componentSets: z.record(z.string(), z.array(z.string().trim().min(1))).default({}),
116
- resolveReferencePath: z.string().trim().min(1).optional(),
120
+ /** Consumer-owned reference callbacks, resolved through Nuxt aliases and extensions. */
121
+ referenceConfig: z.strictObject({ linkResolver: callbackPath.optional() }).optional(),
122
+ /** Consumer-owned related-list callbacks, resolved through Nuxt aliases and extensions. */
123
+ relatedItemListConfig: z.strictObject({
124
+ mapItem: callbackPath.optional(),
125
+ linkResolver: callbackPath.optional()
126
+ }).optional(),
117
127
  videoBaseUrl: z.url().optional(),
118
128
  corsOrigin: z.union([
119
129
  z.literal("*"),
@@ -218,7 +228,7 @@ export default createComponentMetadataHandler(
218
228
  );
219
229
  `
220
230
  });
221
- const referenceResolver = options.resolveReferencePath ? await resolvePath(options.resolveReferencePath) : resolver.resolve(runtimeDir, "app", "utils", "resolve-reference-path");
231
+ const referenceResolver = options.referenceConfig?.linkResolver ? await resolvePath(options.referenceConfig.linkResolver) : resolver.resolve(runtimeDir, "app", "utils", "resolve-reference-path");
222
232
  nuxt.options.alias["#markdown-renderer/manifest"] = manifest.dst;
223
233
  nuxt.options.alias["#markdown-renderer/manifest-factory"] = resolver.resolve(
224
234
  runtimeDir,
@@ -227,6 +237,8 @@ export default createComponentMetadataHandler(
227
237
  "component-manifest"
228
238
  );
229
239
  nuxt.options.alias["#markdown-renderer/reference-resolver"] = referenceResolver;
240
+ nuxt.options.alias["#markdown-renderer/related-item-mapper"] = options.relatedItemListConfig?.mapItem ? await resolvePath(options.relatedItemListConfig.mapItem) : resolver.resolve(runtimeDir, "app", "utils", "map-related-item");
241
+ nuxt.options.alias["#markdown-renderer/related-item-resolver"] = options.relatedItemListConfig?.linkResolver ? await resolvePath(options.relatedItemListConfig.linkResolver) : resolver.resolve(runtimeDir, "app", "utils", "resolve-related-item-path");
230
242
  nuxt.options.appConfig.markdownRenderer = {
231
243
  videoBaseUrl: options.videoBaseUrl
232
244
  };
@@ -0,0 +1,7 @@
1
+ type __VLS_Props = {
2
+ /** Fragment identifier targeted by anchor links. */
3
+ id: string;
4
+ };
5
+ declare const __VLS_export: import("vue").DefineComponent<__VLS_Props, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").PublicProps, Readonly<__VLS_Props> & Readonly<{}>, {}, {}, {}, {}, string, import("vue").ComponentProvideOptions, false, {}, any>;
6
+ declare const _default: typeof __VLS_export;
7
+ export default _default;
@@ -0,0 +1,14 @@
1
+ <script setup>
2
+ import { defineEditorComponentSchema } from "../../utils/define-editor-component-schema";
3
+ defineEditorComponentSchema({
4
+ label: "Anchor",
5
+ type: "block"
6
+ });
7
+ defineProps({
8
+ id: { type: String, required: true }
9
+ });
10
+ </script>
11
+
12
+ <template>
13
+ <span :id="id" class="markdown-anchor" />
14
+ </template>
@@ -0,0 +1,7 @@
1
+ type __VLS_Props = {
2
+ /** Fragment identifier targeted by anchor links. */
3
+ id: string;
4
+ };
5
+ declare const __VLS_export: import("vue").DefineComponent<__VLS_Props, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").PublicProps, Readonly<__VLS_Props> & Readonly<{}>, {}, {}, {}, {}, string, import("vue").ComponentProvideOptions, false, {}, any>;
6
+ declare const _default: typeof __VLS_export;
7
+ export default _default;
@@ -19,8 +19,8 @@ type __VLS_Props = {
19
19
  };
20
20
  declare const __VLS_export: import("vue").DefineComponent<__VLS_Props, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").PublicProps, Readonly<__VLS_Props> & Readonly<{}>, {
21
21
  size: "xs" | "sm" | "md" | "lg" | "xl";
22
- color: "primary" | "secondary" | "success" | "info" | "warning" | "error" | "neutral";
23
- variant: "solid" | "outline" | "soft" | "subtle" | "ghost" | "link";
22
+ color: "success" | "error" | "primary" | "secondary" | "info" | "warning" | "neutral";
23
+ variant: "link" | "ghost" | "solid" | "outline" | "soft" | "subtle";
24
24
  }, {}, {}, {}, string, import("vue").ComponentProvideOptions, false, {}, any>;
25
25
  declare const _default: typeof __VLS_export;
26
26
  export default _default;
@@ -19,8 +19,8 @@ type __VLS_Props = {
19
19
  };
20
20
  declare const __VLS_export: import("vue").DefineComponent<__VLS_Props, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").PublicProps, Readonly<__VLS_Props> & Readonly<{}>, {
21
21
  size: "xs" | "sm" | "md" | "lg" | "xl";
22
- color: "primary" | "secondary" | "success" | "info" | "warning" | "error" | "neutral";
23
- variant: "solid" | "outline" | "soft" | "subtle" | "ghost" | "link";
22
+ color: "success" | "error" | "primary" | "secondary" | "info" | "warning" | "neutral";
23
+ variant: "link" | "ghost" | "solid" | "outline" | "soft" | "subtle";
24
24
  }, {}, {}, {}, string, import("vue").ComponentProvideOptions, false, {}, any>;
25
25
  declare const _default: typeof __VLS_export;
26
26
  export default _default;
@@ -35,7 +35,7 @@ type __VLS_Slots = {} & {
35
35
  description?: (props: typeof __VLS_9) => any;
36
36
  };
37
37
  declare const __VLS_base: import("vue").DefineComponent<__VLS_Props, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").PublicProps, Readonly<__VLS_Props> & Readonly<{}>, {
38
- color: "primary" | "secondary" | "success" | "info" | "warning" | "error" | "neutral";
38
+ color: "success" | "error" | "primary" | "secondary" | "info" | "warning" | "neutral";
39
39
  variant: "solid" | "outline" | "soft" | "subtle";
40
40
  orientation: "horizontal" | "vertical";
41
41
  }, {}, {}, {}, string, import("vue").ComponentProvideOptions, false, {}, any>;
@@ -35,7 +35,7 @@ type __VLS_Slots = {} & {
35
35
  description?: (props: typeof __VLS_9) => any;
36
36
  };
37
37
  declare const __VLS_base: import("vue").DefineComponent<__VLS_Props, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").PublicProps, Readonly<__VLS_Props> & Readonly<{}>, {
38
- color: "primary" | "secondary" | "success" | "info" | "warning" | "error" | "neutral";
38
+ color: "success" | "error" | "primary" | "secondary" | "info" | "warning" | "neutral";
39
39
  variant: "solid" | "outline" | "soft" | "subtle";
40
40
  orientation: "horizontal" | "vertical";
41
41
  }, {}, {}, {}, string, import("vue").ComponentProvideOptions, false, {}, any>;
@@ -0,0 +1,12 @@
1
+ import type { ItemListItem } from "../../../shared/types.js";
2
+ type __VLS_Props = {
3
+ /** Whether to show dividers between items. */
4
+ divide?: boolean;
5
+ /** Items displayed as stacked page cards. */
6
+ items: ItemListItem[];
7
+ };
8
+ declare const __VLS_export: import("vue").DefineComponent<__VLS_Props, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").PublicProps, Readonly<__VLS_Props> & Readonly<{}>, {
9
+ divide: boolean;
10
+ }, {}, {}, {}, string, import("vue").ComponentProvideOptions, false, {}, any>;
11
+ declare const _default: typeof __VLS_export;
12
+ export default _default;
@@ -0,0 +1,44 @@
1
+ <script setup>
2
+ import { defineEditorComponentSchema } from "../../utils/define-editor-component-schema";
3
+ defineEditorComponentSchema({
4
+ label: "Item list",
5
+ type: "block",
6
+ properties: {
7
+ items: {
8
+ items: {
9
+ properties: {
10
+ image: { input: "image" },
11
+ to: { input: "url" },
12
+ icon: { input: { type: "icon", collections: ["lucide"] } }
13
+ }
14
+ }
15
+ }
16
+ }
17
+ });
18
+ defineProps({
19
+ divide: { type: Boolean, required: false, default: false },
20
+ items: { type: Array, required: true }
21
+ });
22
+ </script>
23
+
24
+ <template>
25
+ <UPageList as="ul" :divide="divide">
26
+ <UPageCard
27
+ v-for="(item, index) in items"
28
+ :key="index"
29
+ as="li"
30
+ variant="ghost"
31
+ :title="item.title"
32
+ :description="item.description"
33
+ :to="item.to"
34
+ :external="!!item.to && item.external"
35
+ :target="item.to && item.external ? '_blank' : void 0"
36
+ :icon="item.image ? void 0 : item.icon"
37
+ :ui="{ wrapper: 'flex-row items-center gap-4', leading: 'mb-0' }"
38
+ >
39
+ <template v-if="item.image" #leading>
40
+ <img :src="item.image" alt="" loading="lazy" class="size-12 rounded-md object-cover" />
41
+ </template>
42
+ </UPageCard>
43
+ </UPageList>
44
+ </template>
@@ -0,0 +1,12 @@
1
+ import type { ItemListItem } from "../../../shared/types.js";
2
+ type __VLS_Props = {
3
+ /** Whether to show dividers between items. */
4
+ divide?: boolean;
5
+ /** Items displayed as stacked page cards. */
6
+ items: ItemListItem[];
7
+ };
8
+ declare const __VLS_export: import("vue").DefineComponent<__VLS_Props, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").PublicProps, Readonly<__VLS_Props> & Readonly<{}>, {
9
+ divide: boolean;
10
+ }, {}, {}, {}, string, import("vue").ComponentProvideOptions, false, {}, any>;
11
+ declare const _default: typeof __VLS_export;
12
+ export default _default;
@@ -0,0 +1,8 @@
1
+ import type { RelatedItem } from "../../../shared/types.js";
2
+ type __VLS_Props = {
3
+ /** Ordered CMS selections with collection-specific source snapshots. */
4
+ items: RelatedItem[];
5
+ };
6
+ declare const __VLS_export: import("vue").DefineComponent<__VLS_Props, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").PublicProps, Readonly<__VLS_Props> & Readonly<{}>, {}, {}, {}, {}, string, import("vue").ComponentProvideOptions, false, {}, any>;
7
+ declare const _default: typeof __VLS_export;
8
+ export default _default;
@@ -0,0 +1,16 @@
1
+ <script setup>
2
+ import { computed } from "vue";
3
+ import mapItem from "#markdown-renderer/related-item-mapper";
4
+ import linkResolver from "#markdown-renderer/related-item-resolver";
5
+ import { mapRelatedItems } from "../../utils/map-related-items";
6
+ import MarkdownItemList from "./MarkdownItemList.vue";
7
+ defineOptions({ inheritAttrs: false });
8
+ const props = defineProps({
9
+ items: { type: Array, required: true }
10
+ });
11
+ const mappedItems = computed(() => mapRelatedItems(props.items, { mapItem, linkResolver }));
12
+ </script>
13
+
14
+ <template>
15
+ <MarkdownItemList :items="mappedItems" />
16
+ </template>
@@ -0,0 +1,8 @@
1
+ import type { RelatedItem } from "../../../shared/types.js";
2
+ type __VLS_Props = {
3
+ /** Ordered CMS selections with collection-specific source snapshots. */
4
+ items: RelatedItem[];
5
+ };
6
+ declare const __VLS_export: import("vue").DefineComponent<__VLS_Props, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").PublicProps, Readonly<__VLS_Props> & Readonly<{}>, {}, {}, {}, {}, string, import("vue").ComponentProvideOptions, false, {}, any>;
7
+ declare const _default: typeof __VLS_export;
8
+ export default _default;
@@ -8,7 +8,7 @@ export function createRendererManifest(componentLoaders, componentSets) {
8
8
  resolveRendererComponent(name, componentSet) {
9
9
  const normalizedName = resolveComponentName(name);
10
10
  const allowedComponents = componentSet ? componentSets[componentSet] : void 0;
11
- if (normalizedName !== "Reference" && componentSet && (!allowedComponents || !allowedComponents.includes(normalizedName))) {
11
+ if (normalizedName !== "Reference" && normalizedName !== "RelatedItemList" && componentSet && (!allowedComponents || !allowedComponents.includes(normalizedName))) {
12
12
  return null;
13
13
  }
14
14
  return componentLoaders[normalizedName]?.() ?? null;
@@ -0,0 +1,7 @@
1
+ import type { MapRelatedItem } from "../../shared/types.js";
2
+ /**
3
+ * Keeps the source label without guessing collection-specific display fields.
4
+ * @returns No display overrides.
5
+ */
6
+ declare const mapRelatedItem: MapRelatedItem;
7
+ export default mapRelatedItem;
@@ -0,0 +1,2 @@
1
+ const mapRelatedItem = () => ({});
2
+ export default mapRelatedItem;
@@ -0,0 +1,11 @@
1
+ import type { ItemListItem, MapRelatedItem, RelatedItem, ResolveRelatedItemPath } from "../../shared/types.js";
2
+ /**
3
+ * Maps persisted selections to display rows without changing their order.
4
+ * @param items Persisted CMS selections.
5
+ * @param config Consumer-owned display mapping and link resolver.
6
+ * @returns Rows for the item-list renderer.
7
+ */
8
+ export declare function mapRelatedItems(items: RelatedItem[], config: {
9
+ mapItem?: MapRelatedItem;
10
+ linkResolver?: ResolveRelatedItemPath;
11
+ }): ItemListItem[];
@@ -0,0 +1,7 @@
1
+ export function mapRelatedItems(items, config) {
2
+ return items.map((item) => ({
3
+ title: item.label,
4
+ ...config.mapItem?.(item),
5
+ to: config.linkResolver?.(item)
6
+ }));
7
+ }
@@ -0,0 +1,7 @@
1
+ import type { ResolveRelatedItemPath } from "../../shared/types.js";
2
+ /**
3
+ * Leaves related rows unlinked until the consumer defines its route semantics.
4
+ * @returns No destination.
5
+ */
6
+ declare const resolveRelatedItemPath: ResolveRelatedItemPath;
7
+ export default resolveRelatedItemPath;
@@ -0,0 +1,2 @@
1
+ const resolveRelatedItemPath = () => void 0;
2
+ export default resolveRelatedItemPath;
@@ -1 +1 @@
1
- @source "./app";@tailwindcss/typography;
1
+ @source "./app";@tailwindcss/typography;.markdown-anchor{display:block;scroll-margin-top:100px}
@@ -1 +1 @@
1
- export type { ResolveReferencePath } from "./shared/types.js";
1
+ export type { ItemListItem, MapRelatedItem, RelatedItem, ResolveRelatedItemPath, ResolveReferencePath } from "./shared/types.js";
@@ -12,9 +12,9 @@ export declare function createComponentMetadataHandler(componentMeta: unknown, r
12
12
  props: Record<string, {
13
13
  name: string;
14
14
  type: "string" | "number" | "boolean" | "object" | "array";
15
+ description?: string | undefined;
15
16
  values?: string[] | undefined;
16
17
  default?: unknown;
17
- description?: string | undefined;
18
18
  required?: boolean | undefined;
19
19
  tags?: {
20
20
  name: string;
@@ -25,9 +25,9 @@ export declare function createComponentMetadataHandler(componentMeta: unknown, r
25
25
  properties?: Record<string, {
26
26
  name: string;
27
27
  type: "string" | "number" | "boolean" | "object" | "array";
28
+ description?: string | undefined;
28
29
  values?: string[] | undefined;
29
30
  default?: unknown;
30
- description?: string | undefined;
31
31
  required?: boolean | undefined;
32
32
  tags?: {
33
33
  name: string;
@@ -38,9 +38,9 @@ export declare function createComponentMetadataHandler(componentMeta: unknown, r
38
38
  items?: {
39
39
  name: string;
40
40
  type: "string" | "number" | "boolean" | "object" | "array";
41
+ description?: string | undefined;
41
42
  values?: string[] | undefined;
42
43
  default?: unknown;
43
- description?: string | undefined;
44
44
  required?: boolean | undefined;
45
45
  tags?: {
46
46
  name: string;
@@ -9,8 +9,8 @@ export interface EditorComponentSource {
9
9
  * Converts Nuxt component metadata to the Directus Markdown editor contract.
10
10
  *
11
11
  * The registry is an external/generated boundary, so every value is narrowed before use. Reserved
12
- * `Reference` nodes are omitted because Directus owns that editor node. Components without parsed
13
- * metadata are also omitted rather than returning an incomplete contract.
12
+ * `Reference` and `RelatedItemList` are omitted because the CMS owns those editor nodes.
13
+ * Components without parsed metadata are also omitted rather than returning an incomplete contract.
14
14
  *
15
15
  * The result is a bare array. The Directus extension accepts either this shape or a legacy
16
16
  * `{ components: [...] }` wrapper and normalizes both; the array avoids an unnecessary envelope.
@@ -141,7 +141,7 @@ function resolveCustomComponentMetadata(meta) {
141
141
  export function createEditorComponentMetadata(registry, components) {
142
142
  if (!isRecord(registry)) return [];
143
143
  const output = components.flatMap(({ name, componentName }) => {
144
- if (name === "Reference") return [];
144
+ if (name === "Reference" || name === "RelatedItemList") return [];
145
145
  const component = registry[componentName];
146
146
  if (!isRecord(component) || !isRecord(component.meta)) return [];
147
147
  const custom = resolveCustomComponentMetadata(component.meta);
@@ -1 +1,31 @@
1
+ /** One persisted CMS selection, retaining string or numeric primary keys. */
2
+ export interface RelatedItem {
3
+ /** Source collection name. */
4
+ collection: string;
5
+ /** Source item primary key. */
6
+ item: string | number;
7
+ /** Source display label. */
8
+ label?: string;
9
+ /** Collection-specific source snapshot supplied by the CMS. */
10
+ data?: Record<string, unknown>;
11
+ }
12
+ /** Display fields shared by the item-list components. */
13
+ export interface ItemListItem {
14
+ /** Image URL; takes precedence over the icon. */
15
+ image?: string;
16
+ /** Item title. */
17
+ title?: string;
18
+ /** Supporting text below the title. */
19
+ description?: string;
20
+ /** Link destination, either an internal path or a full URL. */
21
+ to?: string;
22
+ /** Whether to open the destination as an external link in a new tab. */
23
+ external?: boolean;
24
+ /** Iconify icon name, displayed when no image is provided. */
25
+ icon?: string;
26
+ }
27
+ /** Maps a CMS selection to display fields; the title defaults to the source label. */
28
+ export type MapRelatedItem = (item: RelatedItem) => Omit<ItemListItem, "to">;
29
+ /** Resolves a CMS selection's destination, or leaves the row unlinked. */
30
+ export type ResolveRelatedItemPath = (item: RelatedItem) => string | undefined;
1
31
  export type ResolveReferencePath = (collection: string, item: string, label?: string, text?: string, data?: Record<string, unknown>) => string | undefined;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@onderwijsin/nuxt-markdown-renderer",
3
- "version": "0.2.3",
3
+ "version": "0.3.0",
4
4
  "description": "Nuxt module for rendering Markdown content.",
5
5
  "homepage": "https://github.com/onderwijsin/nuxt-modules#readme",
6
6
  "bugs": {
@@ -47,7 +47,7 @@
47
47
  "shiki": "4.4.3",
48
48
  "ufo": "1.6.4",
49
49
  "zod": "4.4.3",
50
- "@onderwijsin/nuxt-module-utils": "^0.5.1"
50
+ "@onderwijsin/nuxt-module-utils": "^0.5.2"
51
51
  },
52
52
  "devDependencies": {
53
53
  "@comark/nuxt": "0.7.0",