@onderwijsin/nuxt-markdown-renderer 0.0.0-stage → 0.2.2

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 (44) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +332 -2
  3. package/dist/metadata/runtime/app/components/renderer/MarkdownButton.vue +67 -0
  4. package/dist/metadata/runtime/app/components/renderer/MarkdownCallout.vue +115 -0
  5. package/dist/metadata/runtime/app/components/renderer/MarkdownReference.vue +33 -0
  6. package/dist/metadata/runtime/app/utils/define-editor-component-schema.ts +12 -0
  7. package/dist/metadata/schema/editor-component-schema.ts +262 -0
  8. package/dist/module.d.mts +22 -0
  9. package/dist/module.json +12 -0
  10. package/dist/module.mjs +268 -0
  11. package/dist/runtime/app/comark-plugins/video-source.d.ts +8 -0
  12. package/dist/runtime/app/comark-plugins/video-source.js +31 -0
  13. package/dist/runtime/app/components/MarkdownRenderer.d.vue.ts +12 -0
  14. package/dist/runtime/app/components/MarkdownRenderer.vue +41 -0
  15. package/dist/runtime/app/components/MarkdownRenderer.vue.d.ts +12 -0
  16. package/dist/runtime/app/components/renderer/MarkdownButton.d.vue.ts +26 -0
  17. package/dist/runtime/app/components/renderer/MarkdownButton.vue +47 -0
  18. package/dist/runtime/app/components/renderer/MarkdownButton.vue.d.ts +26 -0
  19. package/dist/runtime/app/components/renderer/MarkdownCallout.d.vue.ts +49 -0
  20. package/dist/runtime/app/components/renderer/MarkdownCallout.vue +80 -0
  21. package/dist/runtime/app/components/renderer/MarkdownCallout.vue.d.ts +49 -0
  22. package/dist/runtime/app/components/renderer/MarkdownReference.d.vue.ts +17 -0
  23. package/dist/runtime/app/components/renderer/MarkdownReference.vue +24 -0
  24. package/dist/runtime/app/components/renderer/MarkdownReference.vue.d.ts +17 -0
  25. package/dist/runtime/app/utils/component-manifest.d.ts +13 -0
  26. package/dist/runtime/app/utils/component-manifest.js +17 -0
  27. package/dist/runtime/app/utils/define-editor-component-schema.d.ts +9 -0
  28. package/dist/runtime/app/utils/define-editor-component-schema.js +3 -0
  29. package/dist/runtime/app/utils/resolve-reference-path.d.ts +7 -0
  30. package/dist/runtime/app/utils/resolve-reference-path.js +2 -0
  31. package/dist/runtime/index.css +1 -0
  32. package/dist/runtime/index.d.ts +1 -0
  33. package/dist/runtime/index.js +0 -0
  34. package/dist/runtime/server/utils/component-metadata-handler.d.ts +61 -0
  35. package/dist/runtime/server/utils/component-metadata-handler.js +17 -0
  36. package/dist/runtime/server/utils/metadata.d.ts +22 -0
  37. package/dist/runtime/server/utils/metadata.js +186 -0
  38. package/dist/runtime/shared/types.d.ts +1 -0
  39. package/dist/runtime/shared/types.js +0 -0
  40. package/dist/runtime/types/markdown-renderer.d.ts +20 -0
  41. package/dist/schema/editor-component-schema.d.ts +223 -0
  42. package/dist/schema/editor-component-schema.js +151 -0
  43. package/dist/types.d.mts +7 -0
  44. package/package.json +78 -3
@@ -0,0 +1,186 @@
1
+ import {
2
+ fromEntries,
3
+ isArray,
4
+ isDefined,
5
+ isRecord,
6
+ isString
7
+ } from "@onderwijsin/nuxt-module-utils/shared";
8
+ import { z } from "zod";
9
+ import {
10
+ EditorComponentPartialEnrichmentSchema,
11
+ EditorComponentResponseSchema,
12
+ SPECIAL_INPUT_TAG_NAME,
13
+ SpecialInputNameSchema,
14
+ specialInputs
15
+ } from "../../../schema/editor-component-schema";
16
+ function resolveEditorType(type) {
17
+ if (!isString(type)) return "string";
18
+ if (type.includes("[]") || type.includes("Array<")) return "array";
19
+ if (type.includes("boolean")) return "boolean";
20
+ if (type.includes("number")) return "number";
21
+ return "string";
22
+ }
23
+ function resolveEnumMembers(schema) {
24
+ if (isArray(schema)) return schema;
25
+ return isRecord(schema) ? Object.values(schema) : [];
26
+ }
27
+ function resolveStructure(schema, custom, path) {
28
+ if (!isRecord(schema)) return void 0;
29
+ if (schema.kind === "enum") {
30
+ const members = resolveEnumMembers(schema.schema).filter((member) => member !== "undefined");
31
+ return members.length === 1 ? resolveStructure(members[0], custom, path) : void 0;
32
+ }
33
+ if (schema.kind === "object" && isRecord(schema.schema)) {
34
+ const overrides = custom?.properties;
35
+ const properties = fromEntries(
36
+ Object.entries(schema.schema).flatMap(([name, value]) => {
37
+ const property = transformProperty(
38
+ value,
39
+ overrides?.[name],
40
+ name,
41
+ `${path}.properties.${name}`
42
+ );
43
+ return property ? [createPropertyEntry(property)] : [];
44
+ })
45
+ );
46
+ return { type: "object", properties };
47
+ }
48
+ if (schema.kind === "array") {
49
+ const itemSchema = resolveEnumMembers(schema.schema)[0];
50
+ if (!isDefined(itemSchema)) return void 0;
51
+ const item = transformProperty(
52
+ {
53
+ name: "item",
54
+ type: isRecord(itemSchema) ? itemSchema.type : itemSchema,
55
+ schema: itemSchema
56
+ },
57
+ custom?.items,
58
+ void 0,
59
+ `${path}.items`
60
+ );
61
+ return item ? { type: "array", items: item } : { type: "array" };
62
+ }
63
+ return void 0;
64
+ }
65
+ function resolveSchemaValues(schema) {
66
+ if (!isRecord(schema) || schema.kind !== "enum") return void 0;
67
+ const values = resolveEnumMembers(schema.schema).flatMap((entry) => {
68
+ if (isRecord(entry) && entry.kind === "literal" && isString(entry.value)) {
69
+ return [entry.value];
70
+ }
71
+ if (isString(entry) && /^(['"]).*\1$/.test(entry)) return [entry.slice(1, -1)];
72
+ return [];
73
+ });
74
+ return values.length ? values : void 0;
75
+ }
76
+ function resolveDefault(value) {
77
+ if (!isString(value)) return value;
78
+ if (value === "true") return true;
79
+ if (value === "false") return false;
80
+ const numeric = Number(value);
81
+ if (value.trim() !== "" && Number.isFinite(numeric)) return numeric;
82
+ return value.replace(/^['"]|['"]$/g, "");
83
+ }
84
+ function resolveTags(value) {
85
+ if (!isArray(value)) return void 0;
86
+ const tags = value.flatMap((tag) => {
87
+ if (!isRecord(tag) || !isString(tag.name)) return [];
88
+ return [
89
+ {
90
+ name: tag.name,
91
+ ...isString(tag.text) ? { text: tag.text } : {},
92
+ ...isDefined(tag.config) ? { config: tag.config } : {}
93
+ }
94
+ ];
95
+ });
96
+ return tags.length ? tags : void 0;
97
+ }
98
+ function transformProperty(value, custom, fallbackName, path) {
99
+ if (!isRecord(value)) return void 0;
100
+ const name = isString(value.name) ? value.name : fallbackName;
101
+ if (!name) return void 0;
102
+ const description = custom?.description ?? value.description;
103
+ const values = custom?.values ?? resolveSchemaValues(value.schema);
104
+ const inferredType = resolveEditorType(value.type);
105
+ const propertyPath = path ?? name;
106
+ const structure = resolveStructure(value.schema, custom, propertyPath);
107
+ const sourceType = structure?.type ?? inferredType;
108
+ for (const tag of custom?.tags ?? []) {
109
+ if (tag.name !== SPECIAL_INPUT_TAG_NAME || !SpecialInputNameSchema.safeParse(tag.text).success)
110
+ continue;
111
+ if (specialInputs.safeParse({ inputType: tag.text, propertyType: sourceType, config: tag.config }).success)
112
+ continue;
113
+ throw new Error(
114
+ `Invalid editor input ${JSON.stringify(tag.text)} for ${propertyPath}: inferred property type is ${JSON.stringify(sourceType)}.`
115
+ );
116
+ }
117
+ const type = custom?.type ?? structure?.type ?? (values && inferredType !== "array" ? "string" : inferredType);
118
+ const tags = custom?.tags ?? resolveTags(value.tags);
119
+ const customDefault = custom?.default;
120
+ const defaultValue = isDefined(customDefault) ? customDefault : value.default;
121
+ const required = custom?.required === true || custom?.required !== false && value.required === true;
122
+ return {
123
+ name,
124
+ type,
125
+ ...structure?.properties ? { properties: structure.properties } : {},
126
+ ...structure?.items ? { items: structure.items } : {},
127
+ ...isString(description) && description ? { description } : {},
128
+ ...required ? { required: true } : {},
129
+ ...isDefined(defaultValue) ? { default: resolveDefault(defaultValue) } : {},
130
+ ...values ? { values } : {},
131
+ ...tags ? { tags } : {}
132
+ };
133
+ }
134
+ function createPropertyEntry(property) {
135
+ return [property.name, property];
136
+ }
137
+ function resolveCustomComponentMetadata(meta) {
138
+ const parsed = EditorComponentPartialEnrichmentSchema.safeParse(meta.markdownRenderer);
139
+ return parsed.success ? parsed.data : void 0;
140
+ }
141
+ export function createEditorComponentMetadata(registry, components) {
142
+ if (!isRecord(registry)) return [];
143
+ const output = components.flatMap(({ name, componentName }) => {
144
+ if (name === "Reference") return [];
145
+ const component = registry[componentName];
146
+ if (!isRecord(component) || !isRecord(component.meta)) return [];
147
+ const custom = resolveCustomComponentMetadata(component.meta);
148
+ const customProps = custom?.props;
149
+ const props = isArray(component.meta.props) ? component.meta.props.flatMap((value) => {
150
+ const propertyName = isRecord(value) && isString(value.name) ? value.name : void 0;
151
+ const property = transformProperty(
152
+ value,
153
+ propertyName ? customProps?.[propertyName] : void 0,
154
+ void 0,
155
+ `${name}.props.${propertyName ?? "unknown"}`
156
+ );
157
+ return property ? [createPropertyEntry(property)] : [];
158
+ }) : [];
159
+ const slots = isArray(component.meta.slots) ? component.meta.slots.flatMap(
160
+ (slot) => isRecord(slot) && isString(slot.name) ? [slot.name] : []
161
+ ) : [];
162
+ const label = custom?.label ?? name;
163
+ const nodeType = custom?.nodeType ? custom.nodeType : slots.length ? "block" : "inline";
164
+ const description = custom?.description ?? component.meta.description;
165
+ const tags = custom?.tags ?? resolveTags(component.meta.tags);
166
+ return [
167
+ {
168
+ name,
169
+ label,
170
+ ...isString(description) && description ? { description } : {},
171
+ nodeType,
172
+ props: fromEntries(props),
173
+ slots,
174
+ ...tags ? { tags } : {}
175
+ }
176
+ ];
177
+ });
178
+ const parsed = EditorComponentResponseSchema.safeParse(output);
179
+ if (!parsed.success) {
180
+ throw new Error(
181
+ `Invalid Markdown editor component metadata:
182
+ ${z.prettifyError(parsed.error)}`
183
+ );
184
+ }
185
+ return parsed.data;
186
+ }
@@ -0,0 +1 @@
1
+ export type ResolveReferencePath = (collection: string, item: string, label?: string, text?: string, data?: Record<string, unknown>) => string | undefined;
File without changes
@@ -0,0 +1,20 @@
1
+ declare module "#markdown-renderer/manifest" {
2
+ import type { ComponentManifest } from "comark";
3
+
4
+ export const componentSets: Record<string, string[]>;
5
+ export const rendererComponentNames: string[];
6
+ export const resolveRendererComponent: (
7
+ name: string,
8
+ componentSet?: string
9
+ ) => ReturnType<ComponentManifest>;
10
+ }
11
+
12
+ declare module "nuxt/schema" {
13
+ interface AppConfig {
14
+ markdownRenderer: {
15
+ videoBaseUrl?: string;
16
+ };
17
+ }
18
+ }
19
+
20
+ export {};
@@ -0,0 +1,223 @@
1
+ import { z } from "zod";
2
+ /**
3
+ * Special input types for one of the primitive property types, for which the
4
+ * editor needs to render a specialized input interface.
5
+ */
6
+ export declare const specialInputs: z.ZodDiscriminatedUnion<[z.ZodObject<{
7
+ inputType: z.ZodLiteral<"url">;
8
+ propertyType: z.ZodLiteral<"string">;
9
+ config: z.ZodObject<{}, z.core.$strip> | z.ZodOptional<z.ZodObject<{}, z.core.$strip>>;
10
+ }, z.core.$strip>, z.ZodObject<{
11
+ inputType: z.ZodLiteral<"image">;
12
+ propertyType: z.ZodLiteral<"string">;
13
+ config: z.ZodObject<{}, z.core.$strip> | z.ZodOptional<z.ZodObject<{}, z.core.$strip>>;
14
+ }, z.core.$strip>, z.ZodObject<{
15
+ inputType: z.ZodLiteral<"icon">;
16
+ propertyType: z.ZodLiteral<"string">;
17
+ config: z.ZodObject<{
18
+ collections: z.ZodArray<z.ZodString>;
19
+ }, z.core.$strip> | z.ZodOptional<z.ZodObject<{
20
+ collections: z.ZodArray<z.ZodString>;
21
+ }, z.core.$strip>>;
22
+ }, z.core.$strip>], "inputType">;
23
+ /** Accepted macro input names, derived from the special-input definitions. */
24
+ export declare const SpecialInputNameSchema: z.ZodUnion<readonly [z.ZodLiteral<"url">, z.ZodLiteral<"image">, z.ZodLiteral<"icon">]>;
25
+ /**
26
+ * Macro syntax for controls. Every control accepts an object form; controls without required
27
+ * configuration also accept their name as shorthand.
28
+ */
29
+ export declare const SpecialInputMacroSchema: z.ZodUnion<readonly [z.ZodCustom<"url", "url">, z.ZodCustom<"image", "image">, z.ZodCustom<never, never>, z.ZodDiscriminatedUnion<[z.ZodObject<{
30
+ type: z.ZodLiteral<"url">;
31
+ }, z.core.$strict>, z.ZodObject<{
32
+ type: z.ZodLiteral<"image">;
33
+ }, z.core.$strict>, z.ZodObject<{
34
+ type: z.ZodLiteral<"icon">;
35
+ collections: z.ZodArray<z.ZodString>;
36
+ }, z.core.$strict>], "type">]>;
37
+ /** Tag name used by the endpoint to identify a validated special editor input. */
38
+ export declare const SPECIAL_INPUT_TAG_NAME = "specialInputType";
39
+ /** Named JSDoc or editor hint transported in endpoint metadata. */
40
+ export declare const EditorTagSchema: z.ZodObject<{
41
+ name: z.ZodString;
42
+ text: z.ZodOptional<z.ZodString>;
43
+ config: z.ZodOptional<z.ZodUnknown>;
44
+ }, z.core.$strip>;
45
+ /** Non-recursive property overrides accepted by the authoring macro. */
46
+ declare const inputFields: z.ZodObject<{
47
+ values: z.ZodOptional<z.ZodArray<z.ZodString>>;
48
+ input: z.ZodOptional<z.ZodUnion<readonly [z.ZodCustom<"url", "url">, z.ZodCustom<"image", "image">, z.ZodCustom<never, never>, z.ZodDiscriminatedUnion<[z.ZodObject<{
49
+ type: z.ZodLiteral<"url">;
50
+ }, z.core.$strict>, z.ZodObject<{
51
+ type: z.ZodLiteral<"image">;
52
+ }, z.core.$strict>, z.ZodObject<{
53
+ type: z.ZodLiteral<"icon">;
54
+ collections: z.ZodArray<z.ZodString>;
55
+ }, z.core.$strict>], "type">]>>;
56
+ deprecated: z.ZodOptional<z.ZodUnion<readonly [z.ZodBoolean, z.ZodObject<{
57
+ text: z.ZodString;
58
+ }, z.core.$strip>, z.ZodString]>>;
59
+ type: z.ZodOptional<z.ZodEnum<{
60
+ string: "string";
61
+ number: "number";
62
+ boolean: "boolean";
63
+ object: "object";
64
+ array: "array";
65
+ }>>;
66
+ description: z.ZodOptional<z.ZodString>;
67
+ default: z.ZodOptional<z.ZodUnknown>;
68
+ required: z.ZodOptional<z.ZodBoolean>;
69
+ }, z.core.$strict>;
70
+ /** Macro field shape with recursive object properties and array items. */
71
+ type RecursiveInput = z.infer<typeof inputFields> & {
72
+ properties?: Record<string, RecursiveInput>;
73
+ items?: RecursiveInput;
74
+ };
75
+ /** One macro prop override, recursively covering object properties and array items. */
76
+ export declare const EditorPropertyInputSchema: z.ZodType<RecursiveInput>;
77
+ /** Complete author-written argument to `defineEditorComponentSchema`. */
78
+ export declare const EditorComponentInputSchema: z.ZodObject<{
79
+ label: z.ZodString;
80
+ description: z.ZodOptional<z.ZodString>;
81
+ type: z.ZodEnum<{
82
+ block: "block";
83
+ inline: "inline";
84
+ }>;
85
+ deprecated: z.ZodOptional<z.ZodUnion<readonly [z.ZodBoolean, z.ZodObject<{
86
+ text: z.ZodString;
87
+ }, z.core.$strip>, z.ZodString]>>;
88
+ properties: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodType<RecursiveInput, unknown, z.core.$ZodTypeInternals<RecursiveInput, unknown>>>>;
89
+ }, z.core.$strict>;
90
+ /** Macro property fields after `input` and `deprecated` become endpoint tags. */
91
+ declare const enrichmentFields: z.ZodObject<{
92
+ tags: z.ZodOptional<z.ZodArray<z.ZodObject<{
93
+ name: z.ZodString;
94
+ text: z.ZodOptional<z.ZodString>;
95
+ config: z.ZodOptional<z.ZodUnknown>;
96
+ }, z.core.$strip>>>;
97
+ default: z.ZodOptional<z.ZodUnknown>;
98
+ type: z.ZodOptional<z.ZodEnum<{
99
+ string: "string";
100
+ number: "number";
101
+ boolean: "boolean";
102
+ object: "object";
103
+ array: "array";
104
+ }>>;
105
+ values: z.ZodOptional<z.ZodArray<z.ZodString>>;
106
+ description: z.ZodOptional<z.ZodString>;
107
+ required: z.ZodOptional<z.ZodBoolean>;
108
+ }, z.core.$strip>;
109
+ /** Normalized macro property shape before inference from Vue props is merged. */
110
+ type RecursiveEnrichment = z.infer<typeof enrichmentFields> & {
111
+ properties?: Record<string, RecursiveEnrichment>;
112
+ items?: RecursiveEnrichment;
113
+ };
114
+ /** One normalized macro prop override stored in namespaced component metadata. */
115
+ export declare const EditorPropertyEnrichmentSchema: z.ZodType<RecursiveEnrichment>;
116
+ /** Complete namespaced macro enrichment before Vue prop inference is merged. */
117
+ export declare const EditorComponentEnrichmentSchema: z.ZodObject<{
118
+ nodeType: z.ZodEnum<{
119
+ block: "block";
120
+ inline: "inline";
121
+ }>;
122
+ props: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodType<RecursiveEnrichment, unknown, z.core.$ZodTypeInternals<RecursiveEnrichment, unknown>>>>;
123
+ tags: z.ZodOptional<z.ZodArray<z.ZodObject<{
124
+ name: z.ZodString;
125
+ text: z.ZodOptional<z.ZodString>;
126
+ config: z.ZodOptional<z.ZodUnknown>;
127
+ }, z.core.$strip>>>;
128
+ description: z.ZodOptional<z.ZodString>;
129
+ label: z.ZodString;
130
+ }, z.core.$strip>;
131
+ /** Partial namespaced enrichment allowed for direct `extendComponentMeta` usage. */
132
+ export declare const EditorComponentPartialEnrichmentSchema: z.ZodObject<{
133
+ nodeType: z.ZodOptional<z.ZodEnum<{
134
+ block: "block";
135
+ inline: "inline";
136
+ }>>;
137
+ props: z.ZodOptional<z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodType<RecursiveEnrichment, unknown, z.core.$ZodTypeInternals<RecursiveEnrichment, unknown>>>>>;
138
+ tags: z.ZodOptional<z.ZodOptional<z.ZodArray<z.ZodObject<{
139
+ name: z.ZodString;
140
+ text: z.ZodOptional<z.ZodString>;
141
+ config: z.ZodOptional<z.ZodUnknown>;
142
+ }, z.core.$strip>>>>;
143
+ description: z.ZodOptional<z.ZodOptional<z.ZodString>>;
144
+ label: z.ZodOptional<z.ZodString>;
145
+ }, z.core.$strip>;
146
+ /** Editor property fields after inference supplies a required name and type. */
147
+ declare const outputFields: z.ZodObject<{
148
+ name: z.ZodString;
149
+ type: z.ZodEnum<{
150
+ string: "string";
151
+ number: "number";
152
+ boolean: "boolean";
153
+ object: "object";
154
+ array: "array";
155
+ }>;
156
+ default: z.ZodOptional<z.ZodUnknown>;
157
+ values: z.ZodOptional<z.ZodArray<z.ZodString>>;
158
+ description: z.ZodOptional<z.ZodString>;
159
+ required: z.ZodOptional<z.ZodBoolean>;
160
+ tags: z.ZodOptional<z.ZodArray<z.ZodObject<{
161
+ name: z.ZodString;
162
+ text: z.ZodOptional<z.ZodString>;
163
+ config: z.ZodOptional<z.ZodUnknown>;
164
+ }, z.core.$strip>>>;
165
+ }, z.core.$strip>;
166
+ /** Endpoint property shape with recursive object properties and array items. */
167
+ type RecursiveOutput = z.infer<typeof outputFields> & {
168
+ properties?: Record<string, RecursiveOutput>;
169
+ items?: RecursiveOutput;
170
+ };
171
+ /** One inferred and enriched prop in the component metadata response. */
172
+ export declare const EditorPropertyOutputSchema: z.ZodType<RecursiveOutput>;
173
+ /** One component returned to the Directus editor after inference and enrichment. */
174
+ export declare const EditorComponentOutputSchema: z.ZodObject<{
175
+ name: z.ZodString;
176
+ props: z.ZodRecord<z.ZodString, z.ZodType<RecursiveOutput, unknown, z.core.$ZodTypeInternals<RecursiveOutput, unknown>>>;
177
+ slots: z.ZodArray<z.ZodString>;
178
+ description: z.ZodOptional<z.ZodString>;
179
+ label: z.ZodString;
180
+ tags: z.ZodOptional<z.ZodArray<z.ZodObject<{
181
+ name: z.ZodString;
182
+ text: z.ZodOptional<z.ZodString>;
183
+ config: z.ZodOptional<z.ZodUnknown>;
184
+ }, z.core.$strip>>>;
185
+ nodeType: z.ZodEnum<{
186
+ block: "block";
187
+ inline: "inline";
188
+ }>;
189
+ }, z.core.$strip>;
190
+ /** Array payload returned by the component metadata HTTP endpoint. */
191
+ export declare const EditorComponentResponseSchema: z.ZodArray<z.ZodObject<{
192
+ name: z.ZodString;
193
+ props: z.ZodRecord<z.ZodString, z.ZodType<RecursiveOutput, unknown, z.core.$ZodTypeInternals<RecursiveOutput, unknown>>>;
194
+ slots: z.ZodArray<z.ZodString>;
195
+ description: z.ZodOptional<z.ZodString>;
196
+ label: z.ZodString;
197
+ tags: z.ZodOptional<z.ZodArray<z.ZodObject<{
198
+ name: z.ZodString;
199
+ text: z.ZodOptional<z.ZodString>;
200
+ config: z.ZodOptional<z.ZodUnknown>;
201
+ }, z.core.$strip>>>;
202
+ nodeType: z.ZodEnum<{
203
+ block: "block";
204
+ inline: "inline";
205
+ }>;
206
+ }, z.core.$strip>>;
207
+ /** Tag inferred from JSDoc or generated from an editor-specific macro field. */
208
+ export type EditorTag = z.infer<typeof EditorTagSchema>;
209
+ /** TypeScript input for one recursive macro prop override. */
210
+ export type EditorPropertyInput = z.infer<typeof EditorPropertyInputSchema>;
211
+ /** TypeScript argument accepted by `defineEditorComponentSchema`. */
212
+ export type EditorComponentInput = z.infer<typeof EditorComponentInputSchema>;
213
+ /** TypeScript shape of one normalized macro prop override. */
214
+ export type EditorPropertyEnrichment = z.infer<typeof EditorPropertyEnrichmentSchema>;
215
+ /** TypeScript shape of the normalized namespaced macro payload. */
216
+ export type EditorComponentEnrichment = z.infer<typeof EditorComponentEnrichmentSchema>;
217
+ /** TypeScript shape for partial `extendComponentMeta` enrichment. */
218
+ export type EditorComponentPartialEnrichment = z.infer<typeof EditorComponentPartialEnrichmentSchema>;
219
+ /** TypeScript shape of one inferred and enriched endpoint prop. */
220
+ export type EditorPropertyOutput = z.infer<typeof EditorPropertyOutputSchema>;
221
+ /** TypeScript shape of one component in the endpoint response. */
222
+ export type EditorComponentOutput = z.infer<typeof EditorComponentOutputSchema>;
223
+ export {};
@@ -0,0 +1,151 @@
1
+ import { z } from "zod";
2
+ const choices = z.array(z.string());
3
+ const propertyType = z.enum(["array", "boolean", "number", "object", "string"]);
4
+ const nodeType = z.enum(["block", "inline"]);
5
+ const description = z.string().optional();
6
+ const defaultValue = z.unknown().optional();
7
+ const required = z.boolean().optional();
8
+ const label = z.string();
9
+ function defineSpecialInput(definition) {
10
+ const { inputType, propertyType: supportedType, config } = definition;
11
+ const nameSchema = z.literal(inputType);
12
+ const canUseShorthand = config?.safeParse({}).success;
13
+ const shorthandSchema = z.custom(
14
+ (value) => canUseShorthand && value === inputType
15
+ );
16
+ return {
17
+ name: nameSchema,
18
+ endpoint: z.object({
19
+ inputType: nameSchema,
20
+ propertyType: z.literal(supportedType),
21
+ config: canUseShorthand ? config.optional() : config
22
+ }),
23
+ macro: z.strictObject({ type: nameSchema, ...config?.shape }),
24
+ shorthand: shorthandSchema
25
+ };
26
+ }
27
+ const urlInput = defineSpecialInput({
28
+ inputType: "url",
29
+ propertyType: "string",
30
+ config: z.strictObject({})
31
+ });
32
+ const imageInput = defineSpecialInput({
33
+ inputType: "image",
34
+ propertyType: "string",
35
+ config: z.strictObject({})
36
+ });
37
+ const iconInput = defineSpecialInput({
38
+ inputType: "icon",
39
+ propertyType: "string",
40
+ config: z.strictObject({ collections: z.array(z.string().min(1)).min(1) })
41
+ });
42
+ export const specialInputs = z.discriminatedUnion("inputType", [
43
+ urlInput.endpoint,
44
+ imageInput.endpoint,
45
+ iconInput.endpoint
46
+ ]);
47
+ export const SpecialInputNameSchema = z.union([urlInput.name, imageInput.name, iconInput.name]);
48
+ export const SpecialInputMacroSchema = z.union([
49
+ urlInput.shorthand,
50
+ imageInput.shorthand,
51
+ iconInput.shorthand,
52
+ z.discriminatedUnion("type", [urlInput.macro, imageInput.macro, iconInput.macro])
53
+ ]);
54
+ export const SPECIAL_INPUT_TAG_NAME = "specialInputType";
55
+ export const EditorTagSchema = z.object({
56
+ name: z.string(),
57
+ text: z.string().optional(),
58
+ config: z.unknown().optional()
59
+ });
60
+ const tags = z.array(EditorTagSchema).optional();
61
+ const deprecation = z.union([z.boolean(), z.object({ text: z.string() }), z.string().min(1)]);
62
+ const inputFields = z.strictObject({
63
+ values: choices.optional(),
64
+ input: SpecialInputMacroSchema.optional(),
65
+ deprecated: deprecation.optional(),
66
+ type: propertyType.optional(),
67
+ description,
68
+ default: defaultValue,
69
+ required
70
+ });
71
+ export const EditorPropertyInputSchema = z.strictObject({
72
+ ...inputFields.shape,
73
+ get properties() {
74
+ return z.record(z.string(), EditorPropertyInputSchema).optional();
75
+ },
76
+ get items() {
77
+ return EditorPropertyInputSchema.optional();
78
+ }
79
+ });
80
+ export const EditorComponentInputSchema = z.strictObject({
81
+ label,
82
+ description,
83
+ type: nodeType,
84
+ deprecated: deprecation.optional(),
85
+ properties: z.record(z.string(), EditorPropertyInputSchema).optional()
86
+ });
87
+ const enrichmentFields = z.object({
88
+ ...inputFields.omit({ input: true, deprecated: true }).shape,
89
+ tags
90
+ });
91
+ export const EditorPropertyEnrichmentSchema = z.object({
92
+ ...enrichmentFields.shape,
93
+ get properties() {
94
+ return z.record(z.string(), EditorPropertyEnrichmentSchema).optional();
95
+ },
96
+ get items() {
97
+ return EditorPropertyEnrichmentSchema.optional();
98
+ }
99
+ });
100
+ export const EditorComponentEnrichmentSchema = z.object({
101
+ ...EditorComponentInputSchema.omit({ type: true, deprecated: true, properties: true }).shape,
102
+ nodeType,
103
+ props: z.record(z.string(), EditorPropertyEnrichmentSchema).optional(),
104
+ tags
105
+ });
106
+ export const EditorComponentPartialEnrichmentSchema = EditorComponentEnrichmentSchema.partial();
107
+ const outputFields = z.object({
108
+ ...enrichmentFields.omit({ type: true }).shape,
109
+ name: z.string(),
110
+ type: propertyType
111
+ });
112
+ export const EditorPropertyOutputSchema = z.object({
113
+ ...outputFields.shape,
114
+ get properties() {
115
+ return z.record(z.string(), EditorPropertyOutputSchema).optional();
116
+ },
117
+ get items() {
118
+ return EditorPropertyOutputSchema.optional();
119
+ }
120
+ }).superRefine((property, context) => {
121
+ for (const [index, tag] of (property.tags ?? []).entries()) {
122
+ if (tag.name !== SPECIAL_INPUT_TAG_NAME) continue;
123
+ if (!SpecialInputNameSchema.safeParse(tag.text).success) {
124
+ context.addIssue({
125
+ code: "custom",
126
+ path: ["tags", index, "text"],
127
+ message: "Unknown special input type."
128
+ });
129
+ continue;
130
+ }
131
+ if (specialInputs.safeParse({
132
+ inputType: tag.text,
133
+ propertyType: property.type,
134
+ config: tag.config
135
+ }).success) {
136
+ continue;
137
+ }
138
+ context.addIssue({
139
+ code: "custom",
140
+ path: ["tags", index],
141
+ message: `Editor input ${JSON.stringify(tag.text)} has invalid options or is incompatible with property type ${JSON.stringify(property.type)}.`
142
+ });
143
+ }
144
+ });
145
+ export const EditorComponentOutputSchema = z.object({
146
+ ...EditorComponentEnrichmentSchema.omit({ props: true }).shape,
147
+ name: z.string(),
148
+ props: z.record(z.string(), EditorPropertyOutputSchema),
149
+ slots: z.array(z.string())
150
+ });
151
+ export const EditorComponentResponseSchema = z.array(EditorComponentOutputSchema);
@@ -0,0 +1,7 @@
1
+ import type { NuxtModule } from '@nuxt/schema'
2
+
3
+ import type { default as Module } from './module.mjs'
4
+
5
+ export type ModuleOptions = typeof Module extends NuxtModule<infer O> ? Partial<O> : Record<string, any>
6
+
7
+ export { default } from './module.mjs'
package/package.json CHANGED
@@ -1,6 +1,81 @@
1
1
  {
2
2
  "name": "@onderwijsin/nuxt-markdown-renderer",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
3
+ "version": "0.2.2",
4
+ "description": "Nuxt module for rendering Markdown content.",
5
+ "homepage": "https://github.com/onderwijsin/nuxt-modules#readme",
6
+ "bugs": {
7
+ "url": "https://github.com/onderwijsin/nuxt-modules/issues"
8
+ },
9
+ "license": "MIT",
10
+ "author": {
11
+ "name": "Remi Huigen",
12
+ "email": "remihuigen@proton.me"
13
+ },
14
+ "repository": {
15
+ "type": "git",
16
+ "url": "git+https://github.com/onderwijsin/nuxt-modules.git",
17
+ "directory": "modules/markdown-renderer"
18
+ },
19
+ "files": [
20
+ "dist"
21
+ ],
22
+ "type": "module",
23
+ "main": "./dist/module.mjs",
24
+ "types": "./dist/types.d.mts",
25
+ "exports": {
26
+ ".": {
27
+ "types": "./dist/types.d.mts",
28
+ "style": "./dist/runtime/index.css",
29
+ "import": "./dist/module.mjs"
30
+ },
31
+ "./runtime": {
32
+ "types": "./dist/runtime/index.d.ts",
33
+ "import": "./dist/runtime/index.js"
34
+ }
35
+ },
36
+ "publishConfig": {
37
+ "access": "public"
38
+ },
39
+ "dependencies": {
40
+ "@nuxt/kit": "4.5.2",
41
+ "@nuxt/schema": "4.5.2",
42
+ "@shikijs/themes": "4.4.3",
43
+ "add": "2.0.9",
44
+ "h3": "1.15.11",
45
+ "nuxt-component-meta": "0.18.0",
46
+ "pathe": "2.0.3",
47
+ "shiki": "4.4.3",
48
+ "ufo": "1.6.4",
49
+ "zod": "4.4.3",
50
+ "@onderwijsin/nuxt-module-utils": "^0.5.1"
51
+ },
52
+ "devDependencies": {
53
+ "@comark/nuxt": "0.7.0",
54
+ "@comark/vue": "0.7.0",
55
+ "@nuxt/module-builder": "1.0.3",
56
+ "@nuxt/test-utils": "4.1.0",
57
+ "@nuxt/ui": "4.10.0",
58
+ "comark": "0.7.0",
59
+ "nuxt": "4.5.2",
60
+ "typescript": "5.9.3",
61
+ "unbuild": "3.6.1",
62
+ "vue": "3.5.41"
63
+ },
64
+ "peerDependencies": {
65
+ "@comark/nuxt": ">=0.6.2",
66
+ "@comark/vue": ">=0.6.2",
67
+ "@nuxt/ui": "^4.0.0",
68
+ "comark": ">=0.6.2",
69
+ "vue": "^3.5.0"
70
+ },
71
+ "engines": {
72
+ "node": ">=24"
73
+ },
74
+ "scripts": {
75
+ "build": "nuxt-module-build build",
76
+ "typecheck": "tsc --noEmit --project tsconfig.json",
77
+ "dev": "pnpm run dev:prepare && nuxt dev playground",
78
+ "dev:build": "nuxt build playground",
79
+ "dev:prepare": "nuxt-module-build build --stub && nuxt-module-build prepare && nuxt-module-build build && nuxt prepare playground"
80
+ }
6
81
  }