@humanonlyweb/writer 0.2.0 → 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.
- package/dist/components/WriterContent.d.ts +35 -0
- package/dist/components/WriterContent.js +85 -40
- package/dist/components/WriterEditor.js +86 -57
- package/dist/components/WriterEditor.vue.d.ts +3 -1
- package/dist/config.d.ts +21 -6
- package/dist/config.js +4 -1
- package/dist/docs/blocks.md +8 -3
- package/dist/docs/changelog.md +9 -0
- package/dist/docs/components/content.md +11 -8
- package/dist/docs/components/editor.md +15 -14
- package/dist/docs/images.md +3 -3
- package/dist/docs/parsing.md +8 -7
- package/dist/docs/security.md +21 -5
- package/dist/docs/storing.md +1 -1
- package/dist/editor/commands.js +26 -10
- package/dist/editor/images.d.ts +2 -0
- package/dist/editor/images.js +94 -46
- package/dist/editor/live.js +67 -34
- package/dist/editor/setup.js +151 -84
- package/dist/index.d.ts +5 -5
- package/dist/load-parser.js +20 -9
- package/dist/nuxt/module.d.ts +5 -2
- package/dist/nuxt/module.js +16 -1
- package/dist/package.js +1 -1
- package/dist/parse.d.ts +3 -3
- package/dist/parse.js +35 -17
- package/dist/parser-options.d.ts +17 -3
- package/dist/render.d.ts +7 -0
- package/dist/render.js +194 -42
- package/dist/sanitize.d.ts +3 -1
- package/dist/sanitize.js +214 -23
- package/dist/stats.js +28 -2
- package/package.json +13 -12
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { ParserOptions } from "../parser-options.js";
|
|
2
|
+
import "../parse.js";
|
|
1
3
|
import { Component, PropType } from "vue";
|
|
2
4
|
import { MarkdownDocument } from "comark";
|
|
3
5
|
/**
|
|
@@ -10,11 +12,26 @@ declare const _default: import("vue").DefineComponent<import("vue").ExtractPropT
|
|
|
10
12
|
type: PropType<string | MarkdownDocument>;
|
|
11
13
|
default: string;
|
|
12
14
|
};
|
|
15
|
+
/** Merged over the app's `blocks` for this render. */
|
|
16
|
+
blocks: {
|
|
17
|
+
type: PropType<Record<string, Component>>;
|
|
18
|
+
default: undefined;
|
|
19
|
+
};
|
|
13
20
|
/** Merged over the app's `components` for this render. */
|
|
14
21
|
components: {
|
|
15
22
|
type: PropType<Record<string, Component>>;
|
|
16
23
|
default: undefined;
|
|
17
24
|
};
|
|
25
|
+
/** Parser options for this render. Defaults to the app's `parser`. */
|
|
26
|
+
parser: {
|
|
27
|
+
type: PropType<ParserOptions>;
|
|
28
|
+
default: undefined;
|
|
29
|
+
};
|
|
30
|
+
/** Extra data exposed as `data` for `:prop="data.key"` bindings. */
|
|
31
|
+
data: {
|
|
32
|
+
type: PropType<Record<string, unknown>>;
|
|
33
|
+
default: undefined;
|
|
34
|
+
};
|
|
18
35
|
/** Milliseconds to wait after the Markdown changes before parsing again. Use ~100 for live previews of long documents. */
|
|
19
36
|
debounce: {
|
|
20
37
|
type: NumberConstructor;
|
|
@@ -33,11 +50,26 @@ declare const _default: import("vue").DefineComponent<import("vue").ExtractPropT
|
|
|
33
50
|
type: PropType<string | MarkdownDocument>;
|
|
34
51
|
default: string;
|
|
35
52
|
};
|
|
53
|
+
/** Merged over the app's `blocks` for this render. */
|
|
54
|
+
blocks: {
|
|
55
|
+
type: PropType<Record<string, Component>>;
|
|
56
|
+
default: undefined;
|
|
57
|
+
};
|
|
36
58
|
/** Merged over the app's `components` for this render. */
|
|
37
59
|
components: {
|
|
38
60
|
type: PropType<Record<string, Component>>;
|
|
39
61
|
default: undefined;
|
|
40
62
|
};
|
|
63
|
+
/** Parser options for this render. Defaults to the app's `parser`. */
|
|
64
|
+
parser: {
|
|
65
|
+
type: PropType<ParserOptions>;
|
|
66
|
+
default: undefined;
|
|
67
|
+
};
|
|
68
|
+
/** Extra data exposed as `data` for `:prop="data.key"` bindings. */
|
|
69
|
+
data: {
|
|
70
|
+
type: PropType<Record<string, unknown>>;
|
|
71
|
+
default: undefined;
|
|
72
|
+
};
|
|
41
73
|
/** Milliseconds to wait after the Markdown changes before parsing again. Use ~100 for live previews of long documents. */
|
|
42
74
|
debounce: {
|
|
43
75
|
type: NumberConstructor;
|
|
@@ -49,8 +81,11 @@ declare const _default: import("vue").DefineComponent<import("vue").ExtractPropT
|
|
|
49
81
|
default: string;
|
|
50
82
|
};
|
|
51
83
|
}>> & Readonly<{}>, {
|
|
84
|
+
blocks: Record<string, Component>;
|
|
52
85
|
components: Record<string, Component>;
|
|
86
|
+
parser: ParserOptions;
|
|
53
87
|
value: string | MarkdownDocument<Record<string, any>, Record<string, any>>;
|
|
88
|
+
data: Record<string, unknown>;
|
|
54
89
|
debounce: number;
|
|
55
90
|
tag: string;
|
|
56
91
|
}, {}, {}, {}, string, import("vue").ComponentProvideOptions, true, {}, any>;
|
|
@@ -1,7 +1,11 @@
|
|
|
1
1
|
import { useWriterConfig } from "../config.js";
|
|
2
|
-
import {
|
|
2
|
+
import { loadParserEffect } from "../load-parser.js";
|
|
3
3
|
import { renderDocument } from "../render.js";
|
|
4
|
-
import { isMarkdownDocument } from "comark/utils";
|
|
4
|
+
import { isMarkdownDocument, kebabCase } from "comark/utils";
|
|
5
|
+
import * as Effect from "effect/Effect";
|
|
6
|
+
import * as Exit from "effect/Exit";
|
|
7
|
+
import * as Fiber from "effect/Fiber";
|
|
8
|
+
import * as Scope from "effect/Scope";
|
|
5
9
|
import { Suspense, computed, defineComponent, h, onScopeDispose, shallowRef, watch } from "vue";
|
|
6
10
|
// src/components/WriterContent.ts
|
|
7
11
|
const EMPTY = {
|
|
@@ -10,8 +14,8 @@ const EMPTY = {
|
|
|
10
14
|
meta: {}
|
|
11
15
|
};
|
|
12
16
|
/**
|
|
13
|
-
* Parses `source`, then again whenever it changes:
|
|
14
|
-
*
|
|
17
|
+
* Parses `source`, then again whenever it changes: Effect fiber interruption cancels
|
|
18
|
+
* superseded debounces and stale parses, always settling on the latest source.
|
|
15
19
|
*/
|
|
16
20
|
const ParsedContent = defineComponent({
|
|
17
21
|
name: "WriterParsedContent",
|
|
@@ -31,34 +35,34 @@ const ParsedContent = defineComponent({
|
|
|
31
35
|
},
|
|
32
36
|
async setup(props, { slots }) {
|
|
33
37
|
const document = shallowRef(EMPTY);
|
|
34
|
-
|
|
35
|
-
let
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
38
|
+
const scope = Scope.makeUnsafe("parallel");
|
|
39
|
+
let activeFiber;
|
|
40
|
+
const parseSource = Effect.fnUntraced(function* (source, parserOptions, delay) {
|
|
41
|
+
if (delay > 0) yield* Effect.sleep(delay);
|
|
42
|
+
const parse = yield* loadParserEffect(parserOptions);
|
|
43
|
+
const parsed = yield* Effect.tryPromise({
|
|
44
|
+
try: () => parse(source),
|
|
45
|
+
catch: (error) => error
|
|
46
|
+
});
|
|
47
|
+
document.value = parsed;
|
|
48
|
+
}, Effect.catch((error) => Effect.sync(() => {
|
|
49
|
+
console.error("[writer] couldn't parse Markdown:", error);
|
|
50
|
+
})));
|
|
51
|
+
function schedule(delay) {
|
|
52
|
+
const previous = activeFiber;
|
|
53
|
+
const next = Effect.gen(function* () {
|
|
54
|
+
if (previous) yield* Fiber.interrupt(previous);
|
|
55
|
+
yield* parseSource(props.source, props.parser, delay);
|
|
56
|
+
});
|
|
57
|
+
activeFiber = Effect.runSync(Effect.forkIn(next, scope));
|
|
53
58
|
}
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
clearTimeout(timer);
|
|
57
|
-
if (props.debounce > 0) timer = setTimeout(update, props.debounce);
|
|
58
|
-
else update();
|
|
59
|
+
watch([() => props.source, () => props.parser], () => {
|
|
60
|
+
schedule(props.debounce);
|
|
59
61
|
});
|
|
60
|
-
onScopeDispose(() =>
|
|
61
|
-
|
|
62
|
+
onScopeDispose(() => {
|
|
63
|
+
Effect.runFork(Scope.close(scope, Exit.void));
|
|
64
|
+
});
|
|
65
|
+
await Effect.runPromise(parseSource(props.source, props.parser, 0));
|
|
62
66
|
return () => slots.default?.(document.value);
|
|
63
67
|
}
|
|
64
68
|
});
|
|
@@ -74,11 +78,26 @@ var WriterContent_default = defineComponent({
|
|
|
74
78
|
type: [String, Object],
|
|
75
79
|
default: ""
|
|
76
80
|
},
|
|
81
|
+
/** Merged over the app's `blocks` for this render. */
|
|
82
|
+
blocks: {
|
|
83
|
+
type: Object,
|
|
84
|
+
default: void 0
|
|
85
|
+
},
|
|
77
86
|
/** Merged over the app's `components` for this render. */
|
|
78
87
|
components: {
|
|
79
88
|
type: Object,
|
|
80
89
|
default: void 0
|
|
81
90
|
},
|
|
91
|
+
/** Parser options for this render. Defaults to the app's `parser`. */
|
|
92
|
+
parser: {
|
|
93
|
+
type: Object,
|
|
94
|
+
default: void 0
|
|
95
|
+
},
|
|
96
|
+
/** Extra data exposed as `data` for `:prop="data.key"` bindings. */
|
|
97
|
+
data: {
|
|
98
|
+
type: Object,
|
|
99
|
+
default: void 0
|
|
100
|
+
},
|
|
82
101
|
/** Milliseconds to wait after the Markdown changes before parsing again. Use ~100 for live previews of long documents. */
|
|
83
102
|
debounce: {
|
|
84
103
|
type: Number,
|
|
@@ -90,24 +109,50 @@ var WriterContent_default = defineComponent({
|
|
|
90
109
|
default: "div"
|
|
91
110
|
}
|
|
92
111
|
},
|
|
93
|
-
setup(props) {
|
|
112
|
+
setup(props, { slots }) {
|
|
94
113
|
const config = useWriterConfig();
|
|
95
|
-
const
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
114
|
+
const baseBlocks = computed(() => {
|
|
115
|
+
const blocks = {};
|
|
116
|
+
const nodeBlocks = /* @__PURE__ */ new Set();
|
|
117
|
+
for (const [name, block] of Object.entries(config.blocks)) {
|
|
118
|
+
blocks[name] = block.component;
|
|
119
|
+
if (block.node) nodeBlocks.add(name);
|
|
120
|
+
}
|
|
121
|
+
return {
|
|
122
|
+
blocks,
|
|
123
|
+
nodeBlocks
|
|
124
|
+
};
|
|
125
|
+
});
|
|
126
|
+
const resolvedParser = computed(() => props.parser ?? config.parser);
|
|
127
|
+
const options = computed(() => {
|
|
128
|
+
let blocks = baseBlocks.value.blocks;
|
|
129
|
+
if (props.blocks) {
|
|
130
|
+
const merged = { ...blocks };
|
|
131
|
+
for (const [key, component] of Object.entries(props.blocks)) merged[kebabCase(key)] = component;
|
|
132
|
+
blocks = merged;
|
|
100
133
|
}
|
|
101
|
-
|
|
134
|
+
return {
|
|
135
|
+
blocks,
|
|
136
|
+
components: props.components ? {
|
|
137
|
+
...config.components,
|
|
138
|
+
...props.components
|
|
139
|
+
} : config.components,
|
|
140
|
+
nodeBlocks: baseBlocks.value.nodeBlocks.size ? baseBlocks.value.nodeBlocks : void 0,
|
|
141
|
+
security: resolvedParser.value.security,
|
|
142
|
+
data: props.data
|
|
143
|
+
};
|
|
144
|
+
});
|
|
102
145
|
const render = (document) => h(props.tag, { "data-part": "writer-content" }, renderDocument(document, options.value));
|
|
103
146
|
return () => {
|
|
104
147
|
const { value } = props;
|
|
105
148
|
if (isMarkdownDocument(value)) return render(value);
|
|
106
|
-
|
|
149
|
+
const suspenseSlots = { default: () => h(ParsedContent, {
|
|
107
150
|
source: value,
|
|
108
|
-
parser:
|
|
151
|
+
parser: resolvedParser.value,
|
|
109
152
|
debounce: props.debounce
|
|
110
|
-
}, { default: render }) }
|
|
153
|
+
}, { default: render }) };
|
|
154
|
+
if (slots.fallback) suspenseSlots.fallback = () => slots.fallback?.();
|
|
155
|
+
return h(Suspense, null, suspenseSlots);
|
|
111
156
|
};
|
|
112
157
|
}
|
|
113
158
|
});
|
|
@@ -1,7 +1,11 @@
|
|
|
1
1
|
import { useTranslations, useWriterConfig } from "../config.js";
|
|
2
|
-
import {
|
|
2
|
+
import { loadParserEffect } from "../load-parser.js";
|
|
3
3
|
import WriterContent_default from "./WriterContent.js";
|
|
4
|
+
import * as Effect from "effect/Effect";
|
|
5
|
+
import * as Exit from "effect/Exit";
|
|
6
|
+
import * as Scope from "effect/Scope";
|
|
4
7
|
import { computed, createCommentVNode, createElementBlock, createElementVNode, createVNode, defineComponent, getCurrentInstance, h, mergeModels, nextTick, onBeforeUnmount, onMounted, openBlock, render, renderSlot, shallowRef, unref, useModel, useSlots, useTemplateRef, watch } from "vue";
|
|
8
|
+
import * as Cache from "effect/Cache";
|
|
5
9
|
// src/components/WriterEditor.vue
|
|
6
10
|
const _hoisted_1 = [
|
|
7
11
|
"data-mode",
|
|
@@ -26,6 +30,7 @@ const _hoisted_4 = ["hidden"];
|
|
|
26
30
|
const _hoisted_5 = { "data-slot": "replace" };
|
|
27
31
|
const _hoisted_6 = { "data-slot": "remove" };
|
|
28
32
|
const _hoisted_7 = ["name", "value"];
|
|
33
|
+
const _hoisted_8 = ["accept"];
|
|
29
34
|
const _sfc_main = /*@__PURE__*/ defineComponent({
|
|
30
35
|
__name: "WriterEditor",
|
|
31
36
|
props: /*@__PURE__*/ mergeModels({
|
|
@@ -37,6 +42,7 @@ const _sfc_main = /*@__PURE__*/ defineComponent({
|
|
|
37
42
|
readonly: { type: Boolean },
|
|
38
43
|
mode: {},
|
|
39
44
|
upload: { type: Function },
|
|
45
|
+
accept: {},
|
|
40
46
|
links: { type: Function },
|
|
41
47
|
codeLanguages: {},
|
|
42
48
|
extensions: {}
|
|
@@ -57,14 +63,22 @@ const _sfc_main = /*@__PURE__*/ defineComponent({
|
|
|
57
63
|
const t = useTranslations();
|
|
58
64
|
const config = useWriterConfig();
|
|
59
65
|
const appContext = getCurrentInstance()?.appContext ?? null;
|
|
60
|
-
const
|
|
66
|
+
const componentScope = Scope.makeUnsafe("parallel");
|
|
67
|
+
const previewCache = Effect.runSync(Cache.make({
|
|
68
|
+
capacity: 200,
|
|
69
|
+
lookup: (source) => Effect.gen(function* () {
|
|
70
|
+
const parse = yield* loadParserEffect(config.parser);
|
|
71
|
+
return yield* Effect.tryPromise({
|
|
72
|
+
try: () => parse(source),
|
|
73
|
+
catch: (error) => error
|
|
74
|
+
});
|
|
75
|
+
})
|
|
76
|
+
}));
|
|
77
|
+
const parseBlockPreview = Effect.fnUntraced(function* (source) {
|
|
78
|
+
return yield* Cache.get(previewCache, source).pipe(Effect.tapError(() => Cache.invalidate(previewCache, source)));
|
|
79
|
+
});
|
|
61
80
|
const renderPreview = async (source, host) => {
|
|
62
|
-
|
|
63
|
-
if (!document) {
|
|
64
|
-
document = await (await loadParser(config.parser))(source);
|
|
65
|
-
previews.set(source, document);
|
|
66
|
-
if (previews.size > 200) previews.delete(previews.keys().next().value);
|
|
67
|
-
}
|
|
81
|
+
const document = await Effect.runPromise(parseBlockPreview(source));
|
|
68
82
|
const vnode = h(WriterContent_default, { value: document });
|
|
69
83
|
vnode.appContext = appContext;
|
|
70
84
|
render(vnode, host);
|
|
@@ -87,7 +101,6 @@ const _sfc_main = /*@__PURE__*/ defineComponent({
|
|
|
87
101
|
const uploading = shallowRef(0);
|
|
88
102
|
const canRedo = shallowRef(false);
|
|
89
103
|
let editor;
|
|
90
|
-
let unmounted = false;
|
|
91
104
|
const attributes = computed(() => {
|
|
92
105
|
const result = {
|
|
93
106
|
spellcheck: "true",
|
|
@@ -100,60 +113,76 @@ const _sfc_main = /*@__PURE__*/ defineComponent({
|
|
|
100
113
|
if (props.readonly) result["aria-readonly"] = "true";
|
|
101
114
|
return result;
|
|
102
115
|
});
|
|
103
|
-
onMounted(
|
|
104
|
-
const
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
116
|
+
onMounted(() => {
|
|
117
|
+
const mountEditor = Effect.gen(function* () {
|
|
118
|
+
const { createEditor } = yield* Effect.tryPromise({
|
|
119
|
+
try: () => editorCode ?? import("../editor/setup.js"),
|
|
120
|
+
catch: (error) => error
|
|
121
|
+
});
|
|
122
|
+
if (!host.value) return;
|
|
123
|
+
const textarea = fallback.value;
|
|
124
|
+
const focused = !!textarea && document.activeElement === textarea;
|
|
125
|
+
editor = createEditor({
|
|
126
|
+
parent: host.value,
|
|
127
|
+
doc: textarea?.value ?? model.value,
|
|
128
|
+
selection: textarea && focused ? {
|
|
129
|
+
anchor: textarea.selectionStart,
|
|
130
|
+
head: textarea.selectionEnd
|
|
131
|
+
} : void 0,
|
|
132
|
+
attributes: attributes.value,
|
|
133
|
+
placeholder: props.placeholder,
|
|
134
|
+
readonly: props.readonly,
|
|
135
|
+
preview: preview(),
|
|
136
|
+
blocks: Object.entries(config.blocks).map(([name, block]) => ({
|
|
137
|
+
name,
|
|
138
|
+
label: block.label,
|
|
139
|
+
snippet: block.snippet,
|
|
140
|
+
description: block.description,
|
|
141
|
+
keywords: block.keywords
|
|
142
|
+
})),
|
|
143
|
+
translations: t.value,
|
|
144
|
+
codeLanguages: props.codeLanguages,
|
|
145
|
+
extensions: props.extensions,
|
|
146
|
+
upload: props.upload,
|
|
147
|
+
accept: props.accept,
|
|
148
|
+
imageIcons: {
|
|
149
|
+
replace: slotIcon("replace"),
|
|
150
|
+
remove: slotIcon("remove")
|
|
151
|
+
},
|
|
152
|
+
links: props.links,
|
|
153
|
+
onChange: (doc) => model.value = doc,
|
|
154
|
+
onState: (state) => {
|
|
155
|
+
active.value = state.active;
|
|
156
|
+
canUndo.value = state.undo;
|
|
157
|
+
canRedo.value = state.redo;
|
|
158
|
+
},
|
|
159
|
+
onFocus: (value) => value ? emit("focus") : emit("blur"),
|
|
160
|
+
onUploadError: (error, file) => emit("uploadError", error, file),
|
|
161
|
+
onUploading: (count) => uploading.value = count
|
|
162
|
+
});
|
|
163
|
+
if (editor.getDoc() !== model.value) model.value = editor.getDoc();
|
|
164
|
+
ready.value = true;
|
|
165
|
+
yield* Effect.promise(() => nextTick());
|
|
166
|
+
editor.view.requestMeasure();
|
|
167
|
+
if (focused) editor.view.focus();
|
|
168
|
+
}).pipe(Effect.catch((error) => Effect.sync(() => {
|
|
169
|
+
console.error("[writer] couldn't load editor:", error);
|
|
170
|
+
})));
|
|
171
|
+
Effect.runSync(Effect.forkIn(mountEditor, componentScope));
|
|
148
172
|
});
|
|
149
173
|
onBeforeUnmount(() => {
|
|
150
|
-
|
|
174
|
+
Effect.runFork(Scope.close(componentScope, Exit.void));
|
|
151
175
|
editor?.destroy();
|
|
152
176
|
});
|
|
153
177
|
watch(model, (value) => editor?.setDoc(value ?? ""));
|
|
154
178
|
watch(() => props.readonly, (value) => editor?.setReadonly(value));
|
|
155
179
|
watch(attributes, (value) => editor?.setAttributes(value));
|
|
156
180
|
watch(() => props.mode, () => editor?.setPreview(preview()));
|
|
181
|
+
watch(() => props.placeholder, (value) => editor?.setPlaceholder(value));
|
|
182
|
+
watch(t, (value) => editor?.setTranslations(value));
|
|
183
|
+
watch(() => props.upload, (value) => editor?.setUpload(value));
|
|
184
|
+
watch(() => props.accept, (value) => editor?.setAccept(value));
|
|
185
|
+
watch(() => props.links, (value) => editor?.setLinks(value));
|
|
157
186
|
function onFallbackInput(event) {
|
|
158
187
|
model.value = event.target.value;
|
|
159
188
|
}
|
|
@@ -238,12 +267,12 @@ const _sfc_main = /*@__PURE__*/ defineComponent({
|
|
|
238
267
|
ref_key: "picker",
|
|
239
268
|
ref: picker,
|
|
240
269
|
type: "file",
|
|
241
|
-
accept: "image/*",
|
|
270
|
+
accept: __props.accept ?? "image/*",
|
|
242
271
|
multiple: "",
|
|
243
272
|
hidden: "",
|
|
244
273
|
tabindex: "-1",
|
|
245
274
|
onChange: onPick
|
|
246
|
-
}, null,
|
|
275
|
+
}, null, 40, _hoisted_8)) : createCommentVNode("v-if", true)
|
|
247
276
|
], 8, _hoisted_1);
|
|
248
277
|
};
|
|
249
278
|
}
|
|
@@ -20,7 +20,9 @@ type __VLS_Props = {
|
|
|
20
20
|
*/
|
|
21
21
|
mode?: "live" | "source";
|
|
22
22
|
/** Uploads a pasted, dropped or picked file and resolves to its URL. Enables file insertion. */
|
|
23
|
-
upload?: (file: File) => Promise<string>;
|
|
23
|
+
upload?: (file: File, signal?: AbortSignal) => Promise<string>;
|
|
24
|
+
/** Accepted file types for the file picker (e.g. `"image/*,.pdf"`). Defaults to `"image/*"`. */
|
|
25
|
+
accept?: string;
|
|
24
26
|
/** Suggests link targets as the author types `](`, e.g. the site's pages matching `query`. */
|
|
25
27
|
links?: (query: string) => LinkSuggestion[] | Promise<LinkSuggestion[]>;
|
|
26
28
|
/** Languages for highlighting fenced code, e.g. `languages` from `@codemirror/language-data`. */
|
package/dist/config.d.ts
CHANGED
|
@@ -1,17 +1,34 @@
|
|
|
1
|
-
import { WriterTranslations, WriterTranslationsInput } from "./translations.js";
|
|
2
1
|
import { ParserOptions } from "./parser-options.js";
|
|
3
2
|
import "./parse.js";
|
|
4
|
-
import {
|
|
3
|
+
import { WriterTranslations, WriterTranslationsInput } from "./translations.js";
|
|
4
|
+
import { Component, ComputedRef, InjectionKey, Plugin, Ref } from "vue";
|
|
5
5
|
export interface WriterBlock {
|
|
6
6
|
/** Rendered for `::name` in content. Receives the attributes as props and the body as slots. */
|
|
7
7
|
component: Component;
|
|
8
8
|
/** Slash menu entry. Defaults to the block name. */
|
|
9
9
|
label?: string;
|
|
10
|
+
/** Optional secondary text in the slash menu. Defaults to `::name`. */
|
|
11
|
+
description?: string;
|
|
12
|
+
/** Extra words that match this block in the slash menu. */
|
|
13
|
+
keywords?: readonly string[];
|
|
10
14
|
/**
|
|
11
15
|
* Inserted from the slash menu, in CodeMirror snippet syntax: `${}` marks where the
|
|
12
16
|
* cursor goes, `${name}` a field Tab moves to. Defaults to an empty block.
|
|
13
17
|
*/
|
|
14
18
|
snippet?: string;
|
|
19
|
+
/**
|
|
20
|
+
* Pass the raw Comark AST node as `__node`. Required for async components (such as
|
|
21
|
+
* Nuxt-discovered blocks) whose `props` aren't visible before they load.
|
|
22
|
+
*/
|
|
23
|
+
node?: boolean;
|
|
24
|
+
}
|
|
25
|
+
export interface ResolvedWriterBlock {
|
|
26
|
+
component: Component;
|
|
27
|
+
label: string;
|
|
28
|
+
snippet: string;
|
|
29
|
+
description?: string;
|
|
30
|
+
keywords?: readonly string[];
|
|
31
|
+
node?: boolean;
|
|
15
32
|
}
|
|
16
33
|
export interface WriterOptions {
|
|
17
34
|
/** Components authors can use, keyed by their Markdown name: `{ callout }` for `::callout`. */
|
|
@@ -24,16 +41,14 @@ export interface WriterOptions {
|
|
|
24
41
|
translations?: WriterTranslationsInput | Ref<WriterTranslationsInput>;
|
|
25
42
|
}
|
|
26
43
|
export interface WriterConfig {
|
|
27
|
-
blocks: Readonly<Record<string,
|
|
44
|
+
blocks: Readonly<Record<string, ResolvedWriterBlock>>;
|
|
28
45
|
components: Readonly<Record<string, Component>>;
|
|
29
46
|
parser: ParserOptions;
|
|
30
47
|
translations: Ref<WriterTranslationsInput>;
|
|
31
48
|
}
|
|
32
49
|
export declare const WRITER_CONFIG_KEY: InjectionKey<WriterConfig>;
|
|
33
50
|
/** `app.use(createWriter({ blocks }))`. Scoped to the app, so nothing leaks between SSR requests. */
|
|
34
|
-
export declare function createWriter(options?: WriterOptions):
|
|
35
|
-
install(app: App): void;
|
|
36
|
-
};
|
|
51
|
+
export declare function createWriter(options?: WriterOptions): Plugin;
|
|
37
52
|
export declare function useWriterConfig(): WriterConfig;
|
|
38
53
|
/** The built-in text: English, with the app's `translations` on top. */
|
|
39
54
|
export declare function useTranslations(): ComputedRef<WriterTranslations>;
|
package/dist/config.js
CHANGED
|
@@ -12,7 +12,10 @@ function resolveConfig(options = {}) {
|
|
|
12
12
|
blocks[name] = {
|
|
13
13
|
component: block.component,
|
|
14
14
|
label: block.label ?? name,
|
|
15
|
-
snippet: block.snippet ?? `::${name}\n\${}\n
|
|
15
|
+
snippet: block.snippet ?? `::${name}\n\${}\n::`,
|
|
16
|
+
description: block.description,
|
|
17
|
+
keywords: block.keywords,
|
|
18
|
+
node: block.node
|
|
16
19
|
};
|
|
17
20
|
}
|
|
18
21
|
const { translations = {} } = options;
|
package/dist/docs/blocks.md
CHANGED
|
@@ -39,13 +39,18 @@ In Nuxt, every component in `components/blocks/` is a block: `Callout.vue` is `:
|
|
|
39
39
|
|
|
40
40
|
In Vue, pass them to `createWriter({ blocks: { callout: Callout } })`.
|
|
41
41
|
|
|
42
|
-
The slash menu's labels and snippets go in `app.config.ts` (or `{ component, label, snippet }` in Vue):
|
|
42
|
+
The slash menu's labels, descriptions, keywords and snippets go in `app.config.ts` (or `{ component, label, description, keywords, snippet, node }` in Vue):
|
|
43
43
|
|
|
44
44
|
```ts
|
|
45
45
|
export default defineAppConfig({
|
|
46
46
|
writer: {
|
|
47
47
|
blocks: {
|
|
48
|
-
callout: {
|
|
48
|
+
callout: {
|
|
49
|
+
label: "Callout",
|
|
50
|
+
description: "Highlighted note",
|
|
51
|
+
keywords: ["note", "tip"],
|
|
52
|
+
snippet: '::callout{type="${note}"}\n${}\n::',
|
|
53
|
+
},
|
|
49
54
|
},
|
|
50
55
|
},
|
|
51
56
|
});
|
|
@@ -61,4 +66,4 @@ GitHub alerts (`> [!NOTE]`) render as a blockquote, or as your `note` block if y
|
|
|
61
66
|
|
|
62
67
|
## In the editor
|
|
63
68
|
|
|
64
|
-
Blocks render inside the editor through the app, not the page around it: they get app-level plugins and `provide`s, but nothing provided by a parent of `<WriterEditor>`. Declare a `__node` prop to receive the block's raw node.
|
|
69
|
+
Blocks render inside the editor through the app, not the page around it: they get app-level plugins and `provide`s, but nothing provided by a parent of `<WriterEditor>`. Declare a `__node` prop to receive the block's raw node (for async Nuxt blocks, set `node: true` in `app.config.ts` so it is passed before the component resolves).
|
package/dist/docs/changelog.md
CHANGED
|
@@ -2,6 +2,15 @@
|
|
|
2
2
|
|
|
3
3
|
> Changes in each release.
|
|
4
4
|
|
|
5
|
+
## 0.2.2 (2026-12-01)
|
|
6
|
+
|
|
7
|
+
- fix: harden sanitization, optimize parsing/rendering, move async orchestration to Effect v4 (0.2.2)
|
|
8
|
+
- chore: update deps
|
|
9
|
+
|
|
10
|
+
## 0.2.1 (2026-11-23)
|
|
11
|
+
|
|
12
|
+
- fix: bare domains (example.com, www.example.com) become links again, as before comark 0.9: linkify is registered as a plugin with fuzzyLink, replacing the deprecated linkify option (0.2.1)
|
|
13
|
+
|
|
5
14
|
## 0.2.0 (2026-11-23)
|
|
6
15
|
|
|
7
16
|
- feat: image cards' Replace and Remove take icons from the editor's image-replace and image-remove slots (copied into each card, built outside Vue), their words staying the accessible names; tests use the platform's Mod key and a Tab target Safari reaches, so the suite passes on macOS too (0.2.0)
|
|
@@ -31,14 +31,17 @@ A callout block.
|
|
|
31
31
|
|
|
32
32
|
## Props
|
|
33
33
|
|
|
34
|
-
| Prop | Type | Description
|
|
35
|
-
| ------------ | ---------------------------- |
|
|
36
|
-
| `value` | `string \| MarkdownDocument` | Markdown, or a document parsed ahead of time (no parser download).
|
|
37
|
-
| `
|
|
38
|
-
| `
|
|
39
|
-
| `
|
|
40
|
-
|
|
41
|
-
|
|
34
|
+
| Prop | Type | Description |
|
|
35
|
+
| ------------ | ---------------------------- | --------------------------------------------------------------------------- |
|
|
36
|
+
| `value` | `string \| MarkdownDocument` | Markdown, or a document parsed ahead of time (no parser download). |
|
|
37
|
+
| `blocks` | `Record<string, Component>` | Extra or overridden blocks for this render, merged over the app's `blocks`. |
|
|
38
|
+
| `components` | `Record<string, Component>` | Native element overrides for this render, e.g. `{ a: NuxtLink }`. |
|
|
39
|
+
| `parser` | `ParserOptions` | Parser options for this render. Defaults to the app's `parser`. |
|
|
40
|
+
| `data` | `Record<string, unknown>` | Extra data exposed as `data` for `:prop="data.key"` bindings (sanitized). |
|
|
41
|
+
| `debounce` | `number` | Ms to wait before parsing changed Markdown again. ~100 for previews. |
|
|
42
|
+
| `tag` | `string` | Wrapper element. Default `div`. |
|
|
43
|
+
|
|
44
|
+
A `#fallback` slot renders while a Markdown string is being parsed on the client. Give it a parsed document on public pages: they render without loading the parser. A string works anywhere, server rendering included, and loads the parser on demand.
|
|
42
45
|
|
|
43
46
|
## What renders
|
|
44
47
|
|
|
@@ -164,20 +164,21 @@ The document is always Markdown, but it reads like the page:
|
|
|
164
164
|
|
|
165
165
|
## Props
|
|
166
166
|
|
|
167
|
-
| Prop | Type
|
|
168
|
-
| --------------- |
|
|
169
|
-
| `v-model` | `string`
|
|
170
|
-
| `label` | `string`
|
|
171
|
-
| `labelledby` | `string`
|
|
172
|
-
| `describedby` | `string`
|
|
173
|
-
| `name` | `string`
|
|
174
|
-
| `placeholder` | `string`
|
|
175
|
-
| `readonly` | `boolean`
|
|
176
|
-
| `mode` | `"live" \| "source"`
|
|
177
|
-
| `upload` | `(file: File) => Promise<string>`
|
|
178
|
-
| `
|
|
179
|
-
| `
|
|
180
|
-
| `
|
|
167
|
+
| Prop | Type | Description |
|
|
168
|
+
| --------------- | ------------------------------------------------------- | -------------------------------------------------------------------------------------------- |
|
|
169
|
+
| `v-model` | `string` | The Markdown. |
|
|
170
|
+
| `label` | `string` | Accessible name. Default: "Markdown editor". |
|
|
171
|
+
| `labelledby` | `string` | Id of the element naming it, instead of `label`. |
|
|
172
|
+
| `describedby` | `string` | Id of a hint or error. |
|
|
173
|
+
| `name` | `string` | Submits the Markdown with its form. |
|
|
174
|
+
| `placeholder` | `string` | |
|
|
175
|
+
| `readonly` | `boolean` | |
|
|
176
|
+
| `mode` | `"live" \| "source"` | Live preview (default) or plain Markdown. |
|
|
177
|
+
| `upload` | `(file: File, signal?: AbortSignal) => Promise<string>` | Enables pasting, dropping and picking files. Resolve to the URL; `signal` aborts on unmount. |
|
|
178
|
+
| `accept` | `string` | Accepted file types for the file picker (e.g. `"image/*,.pdf"`). Default `"image/*"`. |
|
|
179
|
+
| `links` | `(query) => { label, url }[]` (or a promise) | Suggests link targets after `](`. |
|
|
180
|
+
| `codeLanguages` | `LanguageDescription[]` | Highlighting inside fenced code, e.g. `languages` from `@codemirror/language-data`. |
|
|
181
|
+
| `extensions` | `Extension` | Extra CodeMirror extensions. Read once, on mount. |
|
|
181
182
|
|
|
182
183
|
## Events
|
|
183
184
|
|