@humanonlyweb/writer 0.1.1 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/components/WriterEditor.js +24 -5
- package/dist/components/WriterEditor.vue.d.ts +13 -1
- package/dist/components/WriterToolbar.js +11 -6
- package/dist/docs/changelog.md +5 -0
- package/dist/docs/images.md +13 -0
- package/dist/docs/styling.md +11 -11
- package/dist/editor/images.js +14 -8
- package/dist/editor/setup.d.ts +1 -0
- package/dist/editor/setup.js +1 -0
- package/dist/package.js +1 -1
- package/dist/styles/core.css +7 -0
- package/package.json +6 -6
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { useTranslations, useWriterConfig } from "../config.js";
|
|
2
2
|
import { loadParser } from "../load-parser.js";
|
|
3
3
|
import WriterContent_default from "./WriterContent.js";
|
|
4
|
-
import { computed, createCommentVNode, createElementBlock, createElementVNode, createVNode, defineComponent, getCurrentInstance, h, mergeModels, nextTick, onBeforeUnmount, onMounted, openBlock, render, shallowRef, unref, useModel, useTemplateRef, watch } from "vue";
|
|
4
|
+
import { computed, createCommentVNode, createElementBlock, createElementVNode, createVNode, defineComponent, getCurrentInstance, h, mergeModels, nextTick, onBeforeUnmount, onMounted, openBlock, render, renderSlot, shallowRef, unref, useModel, useSlots, useTemplateRef, watch } from "vue";
|
|
5
5
|
// src/components/WriterEditor.vue
|
|
6
6
|
const _hoisted_1 = [
|
|
7
7
|
"data-mode",
|
|
@@ -23,7 +23,9 @@ const _hoisted_3 = [
|
|
|
23
23
|
"readonly"
|
|
24
24
|
];
|
|
25
25
|
const _hoisted_4 = ["hidden"];
|
|
26
|
-
const _hoisted_5 =
|
|
26
|
+
const _hoisted_5 = { "data-slot": "replace" };
|
|
27
|
+
const _hoisted_6 = { "data-slot": "remove" };
|
|
28
|
+
const _hoisted_7 = ["name", "value"];
|
|
27
29
|
const _sfc_main = /*@__PURE__*/ defineComponent({
|
|
28
30
|
__name: "WriterEditor",
|
|
29
31
|
props: /*@__PURE__*/ mergeModels({
|
|
@@ -50,6 +52,7 @@ const _sfc_main = /*@__PURE__*/ defineComponent({
|
|
|
50
52
|
setup(__props, { expose: __expose, emit: __emit }) {
|
|
51
53
|
const model = useModel(__props, "modelValue");
|
|
52
54
|
const props = __props;
|
|
55
|
+
const slots = useSlots();
|
|
53
56
|
const emit = __emit;
|
|
54
57
|
const t = useTranslations();
|
|
55
58
|
const config = useWriterConfig();
|
|
@@ -71,6 +74,12 @@ const _sfc_main = /*@__PURE__*/ defineComponent({
|
|
|
71
74
|
const fallback = useTemplateRef("fallback");
|
|
72
75
|
const host = useTemplateRef("host");
|
|
73
76
|
const picker = useTemplateRef("picker");
|
|
77
|
+
const iconSource = useTemplateRef("iconSource");
|
|
78
|
+
const slotIcon = (name) => slots[`image-${name}`] ? () => {
|
|
79
|
+
const copy = document.createDocumentFragment();
|
|
80
|
+
for (const node of iconSource.value?.querySelector(`[data-slot="${name}"]`)?.childNodes ?? []) copy.append(node.cloneNode(true));
|
|
81
|
+
return copy;
|
|
82
|
+
} : void 0;
|
|
74
83
|
const editorCode = typeof window === "undefined" ? void 0 : import("../editor/setup.js");
|
|
75
84
|
const ready = shallowRef(false);
|
|
76
85
|
const active = shallowRef(/* @__PURE__ */ new Set());
|
|
@@ -116,6 +125,10 @@ const _sfc_main = /*@__PURE__*/ defineComponent({
|
|
|
116
125
|
codeLanguages: props.codeLanguages,
|
|
117
126
|
extensions: props.extensions,
|
|
118
127
|
upload: props.upload,
|
|
128
|
+
imageIcons: {
|
|
129
|
+
replace: slotIcon("replace"),
|
|
130
|
+
remove: slotIcon("remove")
|
|
131
|
+
},
|
|
119
132
|
links: props.links,
|
|
120
133
|
onChange: (doc) => model.value = doc,
|
|
121
134
|
onState: (state) => {
|
|
@@ -208,14 +221,20 @@ const _sfc_main = /*@__PURE__*/ defineComponent({
|
|
|
208
221
|
"data-part": "writer-host",
|
|
209
222
|
hidden: !ready.value
|
|
210
223
|
}, null, 8, _hoisted_4),
|
|
211
|
-
|
|
224
|
+
_ctx.$slots["image-replace"] || _ctx.$slots["image-remove"] ? (openBlock(), createElementBlock("div", {
|
|
212
225
|
key: 2,
|
|
226
|
+
ref_key: "iconSource",
|
|
227
|
+
ref: iconSource,
|
|
228
|
+
hidden: ""
|
|
229
|
+
}, [createElementVNode("span", _hoisted_5, [renderSlot(_ctx.$slots, "image-replace")]), createElementVNode("span", _hoisted_6, [renderSlot(_ctx.$slots, "image-remove")])], 512)) : createCommentVNode("v-if", true),
|
|
230
|
+
__props.name && (ready.value || __props.mode !== "source") ? (openBlock(), createElementBlock("input", {
|
|
231
|
+
key: 3,
|
|
213
232
|
type: "hidden",
|
|
214
233
|
name: __props.name,
|
|
215
234
|
value: model.value
|
|
216
|
-
}, null, 8,
|
|
235
|
+
}, null, 8, _hoisted_7)) : createCommentVNode("v-if", true),
|
|
217
236
|
__props.upload ? (openBlock(), createElementBlock("input", {
|
|
218
|
-
key:
|
|
237
|
+
key: 4,
|
|
219
238
|
ref_key: "picker",
|
|
220
239
|
ref: picker,
|
|
221
240
|
type: "file",
|
|
@@ -28,11 +28,17 @@ type __VLS_Props = {
|
|
|
28
28
|
/** Extra CodeMirror extensions. Read once, on mount. */
|
|
29
29
|
extensions?: Extension;
|
|
30
30
|
};
|
|
31
|
+
type __VLS_Slots = {
|
|
32
|
+
/** An image card's Replace button content, e.g. an icon. Its word stays the accessible name. */
|
|
33
|
+
"image-replace"?(): unknown;
|
|
34
|
+
/** An image card's Remove button content, e.g. an icon. Its word stays the accessible name. */
|
|
35
|
+
"image-remove"?(): unknown;
|
|
36
|
+
};
|
|
31
37
|
type __VLS_ModelProps = {
|
|
32
38
|
modelValue?: string;
|
|
33
39
|
};
|
|
34
40
|
type __VLS_PublicProps = __VLS_Props & __VLS_ModelProps;
|
|
35
|
-
declare const
|
|
41
|
+
declare const __VLS_base: import("vue").DefineComponent<__VLS_PublicProps, {
|
|
36
42
|
/** True once CodeMirror has replaced the server-rendered fallback. */
|
|
37
43
|
ready: import("vue").ShallowRef<boolean, boolean>;
|
|
38
44
|
/** Formatting at the cursor. */
|
|
@@ -66,5 +72,11 @@ declare const __VLS_export: import("vue").DefineComponent<__VLS_PublicProps, {
|
|
|
66
72
|
"onUpdate:modelValue"?: ((value: string) => any) | undefined;
|
|
67
73
|
onUploadError?: ((error: unknown, file: File) => any) | undefined;
|
|
68
74
|
}>, {}, {}, {}, {}, string, import("vue").ComponentProvideOptions, false, {}, any>;
|
|
75
|
+
declare const __VLS_export: __VLS_WithSlots<typeof __VLS_base, __VLS_Slots>;
|
|
69
76
|
declare const _default: typeof __VLS_export;
|
|
77
|
+
type __VLS_WithSlots<T, S> = T & {
|
|
78
|
+
new (): {
|
|
79
|
+
$slots: S;
|
|
80
|
+
};
|
|
81
|
+
};
|
|
70
82
|
export { _default as default };
|
|
@@ -73,9 +73,7 @@ const _sfc_main = /*@__PURE__*/ defineComponent({
|
|
|
73
73
|
unavailable: name === "undo" && !__props.editor?.canUndo || name === "redo" && !__props.editor?.canRedo
|
|
74
74
|
})));
|
|
75
75
|
const disabled = computed(() => !__props.editor?.ready);
|
|
76
|
-
|
|
77
|
-
return [...el.querySelectorAll("button")];
|
|
78
|
-
}
|
|
76
|
+
const toolbarItems = useTemplateRef("toolbarItems");
|
|
79
77
|
const last = shallowRef();
|
|
80
78
|
const tabStop = computed(() => last.value && __props.items.includes(last.value) ? last.value : __props.items[0]);
|
|
81
79
|
function rove(target) {
|
|
@@ -84,14 +82,18 @@ const _sfc_main = /*@__PURE__*/ defineComponent({
|
|
|
84
82
|
}
|
|
85
83
|
function onKeydown(event) {
|
|
86
84
|
if (!root.value || !(event.target instanceof HTMLButtonElement)) return;
|
|
87
|
-
const list =
|
|
88
|
-
const index = list
|
|
85
|
+
const list = toolbarItems.value;
|
|
86
|
+
const index = list?.indexOf(event.target);
|
|
87
|
+
if (index === void 0 || index === -1) return;
|
|
89
88
|
const rtl = getComputedStyle(root.value).direction === "rtl";
|
|
90
89
|
const step = {
|
|
91
90
|
ArrowRight: rtl ? -1 : 1,
|
|
92
91
|
ArrowLeft: rtl ? 1 : -1
|
|
93
92
|
}[event.key];
|
|
94
|
-
|
|
93
|
+
let target;
|
|
94
|
+
if (event.key === "Home") target = list?.[0];
|
|
95
|
+
else if (event.key === "End") target = list?.at(-1);
|
|
96
|
+
else if (step) target = list?.[(index + step + list.length) % list.length];
|
|
95
97
|
if (!target) return;
|
|
96
98
|
event.preventDefault();
|
|
97
99
|
rove(target);
|
|
@@ -114,6 +116,9 @@ const _sfc_main = /*@__PURE__*/ defineComponent({
|
|
|
114
116
|
key: button.name,
|
|
115
117
|
type: "button",
|
|
116
118
|
"data-part": "writer-toolbar-item",
|
|
119
|
+
ref_for: true,
|
|
120
|
+
ref_key: "toolbarItems",
|
|
121
|
+
ref: toolbarItems,
|
|
117
122
|
"data-command": button.name,
|
|
118
123
|
tabindex: button.name === tabStop.value ? 0 : -1,
|
|
119
124
|
"aria-label": button.label,
|
package/dist/docs/changelog.md
CHANGED
|
@@ -2,6 +2,11 @@
|
|
|
2
2
|
|
|
3
3
|
> Changes in each release.
|
|
4
4
|
|
|
5
|
+
## 0.2.0 (2026-11-23)
|
|
6
|
+
|
|
7
|
+
- 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)
|
|
8
|
+
- chore: update dependencies and improve editor functionality
|
|
9
|
+
|
|
5
10
|
## 0.1.1 (2026-11-02)
|
|
6
11
|
|
|
7
12
|
- chore: bump version to 0.1.1 in package.json
|
package/dist/docs/images.md
CHANGED
|
@@ -27,6 +27,19 @@ Size it with attributes so the page doesn't shift: `{width="800"
|
|
|
27
27
|
|
|
28
28
|
Images on their own line are cards: the picture, its caption and its alt text, edited in place. Arrowing onto a card selects it; Backspace or Delete removes it, Enter adds a paragraph after it. A card never turns back into Markdown; switch to source mode for that.
|
|
29
29
|
|
|
30
|
+
### Icons for Replace and Remove
|
|
31
|
+
|
|
32
|
+
A card's buttons say Replace and Remove. To show icons instead, fill the editor's `image-replace` and `image-remove` slots. The words stay the buttons' accessible names, and the buttons get `data-icon` for styling. Cards are built outside Vue, so each card gets a copy of what the slot rendered: keep it static, like an icon.
|
|
33
|
+
|
|
34
|
+
```vue
|
|
35
|
+
<template>
|
|
36
|
+
<WriterEditor v-model="body" :upload="upload">
|
|
37
|
+
<template #image-replace><MyIcon name="photo" /></template>
|
|
38
|
+
<template #image-remove><MyIcon name="trash" /></template>
|
|
39
|
+
</WriterEditor>
|
|
40
|
+
</template>
|
|
41
|
+
```
|
|
42
|
+
|
|
30
43
|
## Uploads
|
|
31
44
|
|
|
32
45
|
Give the editor an `upload` function: it gets the `File` and resolves to its URL.
|
package/dist/docs/styling.md
CHANGED
|
@@ -34,14 +34,14 @@ If your prose CSS sets heading sizes directly, set these to the same values, or
|
|
|
34
34
|
|
|
35
35
|
## Hooks
|
|
36
36
|
|
|
37
|
-
| Selector | Description
|
|
38
|
-
| ------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
39
|
-
| `[data-part="writer-editor"]` | Editor root: `[data-mode]`, `[data-ready]`, `[data-readonly]`.
|
|
40
|
-
| `[data-part="writer-fallback"]` | What shows before CodeMirror loads.
|
|
41
|
-
| `[data-part="writer-host"] .cm-editor` | CodeMirror.
|
|
42
|
-
| `[data-part="writer-content"]` | Rendered content, on the page and in the editor's previews.
|
|
43
|
-
| `.cm-md-preview`, `.cm-md-block-open`, `.cm-md-block-fence` | Rendered blocks, and the lines of a block open for editing.
|
|
44
|
-
| `[data-part="writer-image"]`, `.cm-md-image-frame`, `.cm-md-image-caption`, `.cm-md-image-alt` | Image cards: `[data-selected]`; the frame `[data-empty]`, `[data-uploading]`, `[data-dropping]`. |
|
|
45
|
-
| `.cm-md-bullet`, `.cm-md-task`, `.cm-md-quote-line`, `.cm-md-hr` | Live preview's stand-ins for list, task, quote and rule syntax.
|
|
46
|
-
| `.cm-md-h1`…`.cm-md-h6`, `.cm-md-codeblock`, `.cm-md-strong`, `.cm-md-em`, `.cm-md-strike`, `.cm-md-code`, `.cm-md-link`, `.cm-md-quote`, `.cm-md-mark`, `.cm-md-comment` | Markdown source.
|
|
47
|
-
| `[data-part="writer-toolbar"]`, `[data-part="writer-toolbar-item"][data-command]` | Toolbar and buttons: `[aria-pressed]`, `[aria-disabled]`.
|
|
37
|
+
| Selector | Description |
|
|
38
|
+
| ------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
39
|
+
| `[data-part="writer-editor"]` | Editor root: `[data-mode]`, `[data-ready]`, `[data-readonly]`. |
|
|
40
|
+
| `[data-part="writer-fallback"]` | What shows before CodeMirror loads. |
|
|
41
|
+
| `[data-part="writer-host"] .cm-editor` | CodeMirror. |
|
|
42
|
+
| `[data-part="writer-content"]` | Rendered content, on the page and in the editor's previews. |
|
|
43
|
+
| `.cm-md-preview`, `.cm-md-block-open`, `.cm-md-block-fence` | Rendered blocks, and the lines of a block open for editing. |
|
|
44
|
+
| `[data-part="writer-image"]`, `.cm-md-image-frame`, `.cm-md-image-caption`, `.cm-md-image-alt` | Image cards: `[data-selected]`; the frame `[data-empty]`, `[data-uploading]`, `[data-dropping]`; `.cm-md-image-actions button[data-icon]` with the `image-replace` and `image-remove` slots. |
|
|
45
|
+
| `.cm-md-bullet`, `.cm-md-task`, `.cm-md-quote-line`, `.cm-md-hr` | Live preview's stand-ins for list, task, quote and rule syntax. |
|
|
46
|
+
| `.cm-md-h1`…`.cm-md-h6`, `.cm-md-codeblock`, `.cm-md-strong`, `.cm-md-em`, `.cm-md-strike`, `.cm-md-code`, `.cm-md-link`, `.cm-md-quote`, `.cm-md-mark`, `.cm-md-comment` | Markdown source. |
|
|
47
|
+
| `[data-part="writer-toolbar"]`, `[data-part="writer-toolbar-item"][data-command]` | Toolbar and buttons: `[aria-pressed]`, `[aria-disabled]`. |
|
package/dist/editor/images.js
CHANGED
|
@@ -167,6 +167,18 @@ async function uploadFiles(view, files, options, target) {
|
|
|
167
167
|
}
|
|
168
168
|
await Promise.all(uploads.map(({ file, token }) => finish(view, file, token, options, previous)));
|
|
169
169
|
}
|
|
170
|
+
/** A card button: its words, or an icon named by them (`data-icon`, for styling). */
|
|
171
|
+
function action(label, icon) {
|
|
172
|
+
const button = element("button", { type: "button" });
|
|
173
|
+
if (!icon) {
|
|
174
|
+
button.textContent = label;
|
|
175
|
+
return button;
|
|
176
|
+
}
|
|
177
|
+
button.setAttribute("aria-label", label);
|
|
178
|
+
button.dataset.icon = "";
|
|
179
|
+
button.append(icon());
|
|
180
|
+
return button;
|
|
181
|
+
}
|
|
170
182
|
function element(tag, props = {}, ...children) {
|
|
171
183
|
const { dataPart, ...rest } = props;
|
|
172
184
|
const node = Object.assign(document.createElement(tag), rest);
|
|
@@ -254,14 +266,8 @@ var ImageCardWidget = class extends WidgetType {
|
|
|
254
266
|
textContent: t.imageUploading
|
|
255
267
|
});
|
|
256
268
|
status.setAttribute("role", "status");
|
|
257
|
-
const replace =
|
|
258
|
-
|
|
259
|
-
textContent: t.imageReplace
|
|
260
|
-
});
|
|
261
|
-
const remove = element("button", {
|
|
262
|
-
type: "button",
|
|
263
|
-
textContent: t.imageRemove
|
|
264
|
-
});
|
|
269
|
+
const replace = action(t.imageReplace, this.options.icons?.replace);
|
|
270
|
+
const remove = action(t.imageRemove, this.options.icons?.remove);
|
|
265
271
|
const frame = element("div", { className: "cm-md-image-frame" }, image, empty, status, element("div", { className: "cm-md-image-actions" }, ...upload ? [replace] : [], remove));
|
|
266
272
|
const caption = element("input", {
|
|
267
273
|
type: "text",
|
package/dist/editor/setup.d.ts
CHANGED
package/dist/editor/setup.js
CHANGED
|
@@ -177,6 +177,7 @@ function createEditor(options) {
|
|
|
177
177
|
const liveOptions = (render) => ({
|
|
178
178
|
render,
|
|
179
179
|
translations: t,
|
|
180
|
+
icons: options.imageIcons,
|
|
180
181
|
uploadInto: uploadOptions ? (target, file, range) => void uploadFiles(target, [file], uploadOptions, { replace: range }) : void 0
|
|
181
182
|
});
|
|
182
183
|
const slashItems = [
|
package/dist/package.js
CHANGED
package/dist/styles/core.css
CHANGED
|
@@ -215,6 +215,13 @@
|
|
|
215
215
|
transition: opacity 0.15s;
|
|
216
216
|
}
|
|
217
217
|
|
|
218
|
+
/* An icon in place of the words (the `image-replace` and `image-remove` slots): centred, no line box around it. */
|
|
219
|
+
.cm-md-image-actions button[data-icon] {
|
|
220
|
+
display: inline-grid;
|
|
221
|
+
place-items: center;
|
|
222
|
+
line-height: 0;
|
|
223
|
+
}
|
|
224
|
+
|
|
218
225
|
.cm-md-image:is(:hover, :focus-within, [data-selected]) .cm-md-image-actions {
|
|
219
226
|
opacity: 1;
|
|
220
227
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@humanonlyweb/writer",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.2.0",
|
|
4
4
|
"description": "Markdown block editor and renderer for Vue and Nuxt: CodeMirror editing, Comark rendering, SSR-safe.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"a11y",
|
|
@@ -62,20 +62,20 @@
|
|
|
62
62
|
"@codemirror/view": "^6.43.15",
|
|
63
63
|
"@lezer/highlight": "^1.2.5",
|
|
64
64
|
"@lezer/markdown": "^1.8.1",
|
|
65
|
-
"comark": "^0.
|
|
65
|
+
"comark": "^0.9.0",
|
|
66
66
|
"rangi": "^2.2.0"
|
|
67
67
|
},
|
|
68
68
|
"devDependencies": {
|
|
69
|
-
"@humanonlyweb/ui": "^0.
|
|
69
|
+
"@humanonlyweb/ui": "^0.2.2",
|
|
70
70
|
"@nuxt/fonts": "1.0.1",
|
|
71
|
-
"@nuxt/kit": "^4.6.
|
|
72
|
-
"@nuxt/schema": "^4.6.
|
|
71
|
+
"@nuxt/kit": "^4.6.4",
|
|
72
|
+
"@nuxt/schema": "^4.6.4",
|
|
73
73
|
"@types/node": "26.6.5",
|
|
74
74
|
"@vitejs/plugin-vue": "6.0.10",
|
|
75
75
|
"@vitest/browser-playwright": "5.0.5",
|
|
76
76
|
"@vue/test-utils": "2.5.1",
|
|
77
77
|
"axe-core": "4.14.0",
|
|
78
|
-
"nuxt": "^4.6.
|
|
78
|
+
"nuxt": "^4.6.4",
|
|
79
79
|
"playwright": "1.64.1",
|
|
80
80
|
"typescript": "npm:typescript-native-bridge@6.0.3-bridge.19.tsgo.7.0.2",
|
|
81
81
|
"unplugin-vue": "8.0.0",
|