@stonecrop/block-editor 0.0.0-stage → 0.61.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +37 -2
- package/dist/assets/index.css +56 -0
- package/dist/block-editor.js +318 -0
- package/dist/block-editor.js.map +1 -0
- package/dist/src/components/AEditor.vue.d.ts +36 -0
- package/dist/src/components/AEditor.vue.d.ts.map +1 -0
- package/dist/src/index.d.ts +12 -0
- package/dist/src/index.d.ts.map +1 -0
- package/dist/src/types/index.d.ts +21 -0
- package/dist/src/types/index.d.ts.map +1 -0
- package/dist/src/utils/load.d.ts +13 -0
- package/dist/src/utils/load.d.ts.map +1 -0
- package/dist/src/utils/render.d.ts +20 -0
- package/dist/src/utils/render.d.ts.map +1 -0
- package/package.json +82 -3
package/README.md
CHANGED
|
@@ -1,3 +1,38 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @stonecrop/block-editor
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
A block editor for rich-text fields, built on [Editor.js](https://editorjs.io). It ships one component, `AEditor`, which AForm renders for any field whose schema names it:
|
|
4
|
+
|
|
5
|
+
```json
|
|
6
|
+
{ "fieldname": "notes", "label": "Notes", "component": "AEditor" }
|
|
7
|
+
```
|
|
8
|
+
|
|
9
|
+
## Install
|
|
10
|
+
|
|
11
|
+
The Stonecrop Nuxt module installs it for you. Elsewhere, register the component with `install`:
|
|
12
|
+
|
|
13
|
+
```ts
|
|
14
|
+
import { install as BlockEditor } from '@stonecrop/block-editor'
|
|
15
|
+
|
|
16
|
+
app.use(BlockEditor)
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
## The value
|
|
20
|
+
|
|
21
|
+
The field holds the Editor.js `OutputData` that `save()` returns: `{ time, blocks, version }`. The whole document is one field, so `blocks` and the text inside them are properties of its value, not fields of their own.
|
|
22
|
+
|
|
23
|
+
- `AEditor` binds it with `v-model`. On each change it calls `save()` and emits the new object `save()` returns. It never mutates an object it has emitted.
|
|
24
|
+
- A field the user has not edited stays `null`.
|
|
25
|
+
- A record loaded from a JSON column already holds the object, and the field binds it directly.
|
|
26
|
+
|
|
27
|
+
## Modes
|
|
28
|
+
|
|
29
|
+
- `edit` mounts Editor.js. It is imported the first time a field is edited, so a page that only shows documents never loads it.
|
|
30
|
+
- `read` and `display` render the saved blocks as static HTML (`read` with the field outline). Stored text is rebuilt tag by tag, so a value can never put its own elements or attributes on the page.
|
|
31
|
+
|
|
32
|
+
## Blocks
|
|
33
|
+
|
|
34
|
+
Paragraph, Header (levels 1–4), List (ordered, unordered, checklist), Quote and Delimiter. A block from any other tool is shown as its text, if it has any.
|
|
35
|
+
|
|
36
|
+
## In ATable
|
|
37
|
+
|
|
38
|
+
A column whose component is `AEditor` (category `richtext`) shows the document's plain text, cut off with an ellipsis, and its text filter searches that text. The cell is not editable.
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
|
|
2
|
+
/* Editor.js hangs the + and drag handle left of the text (right: 100%); the left padding keeps them inside the outline. */
|
|
3
|
+
.a-editor__holder {
|
|
4
|
+
min-height: 6rem;
|
|
5
|
+
padding: 0.5rem 0.75rem 0.5rem 4rem;
|
|
6
|
+
}
|
|
7
|
+
.a-editor__holder .codex-editor__redactor {
|
|
8
|
+
padding-bottom: 1rem !important;
|
|
9
|
+
}
|
|
10
|
+
.a-editor__holder .ce-block__content,
|
|
11
|
+
.a-editor__holder .ce-toolbar__content {
|
|
12
|
+
max-width: none;
|
|
13
|
+
}
|
|
14
|
+
.a-editor__static {
|
|
15
|
+
display: block;
|
|
16
|
+
padding: 0.5rem;
|
|
17
|
+
min-height: 2rem;
|
|
18
|
+
color: var(--sc-cell-text-color);
|
|
19
|
+
word-break: break-word;
|
|
20
|
+
}
|
|
21
|
+
.a-editor__static > :first-child {
|
|
22
|
+
margin-top: 0;
|
|
23
|
+
}
|
|
24
|
+
.a-editor__static > :last-child {
|
|
25
|
+
margin-bottom: 0;
|
|
26
|
+
}
|
|
27
|
+
.a-editor__static blockquote {
|
|
28
|
+
margin: 0.75rem 0;
|
|
29
|
+
padding-left: 1rem;
|
|
30
|
+
border-left: 3px solid var(--sc-input-border-color);
|
|
31
|
+
}
|
|
32
|
+
.a-editor__static blockquote cite {
|
|
33
|
+
display: block;
|
|
34
|
+
font-size: 0.875em;
|
|
35
|
+
opacity: 0.75;
|
|
36
|
+
}
|
|
37
|
+
.a-editor__static .a-editor__quote--center {
|
|
38
|
+
text-align: center;
|
|
39
|
+
}
|
|
40
|
+
.a-editor__static hr {
|
|
41
|
+
border: none;
|
|
42
|
+
text-align: center;
|
|
43
|
+
margin: 1rem 0;
|
|
44
|
+
}
|
|
45
|
+
.a-editor__static hr::before {
|
|
46
|
+
content: '***';
|
|
47
|
+
letter-spacing: 0.5em;
|
|
48
|
+
}
|
|
49
|
+
.a-editor__static .a-editor__checklist {
|
|
50
|
+
list-style: none;
|
|
51
|
+
padding-left: 0.25rem;
|
|
52
|
+
}
|
|
53
|
+
.a-editor__static .a-editor__checked {
|
|
54
|
+
text-decoration: line-through;
|
|
55
|
+
opacity: 0.75;
|
|
56
|
+
}
|
|
@@ -0,0 +1,318 @@
|
|
|
1
|
+
import { computed, createCommentVNode, createElementBlock, createElementVNode, defineComponent, mergeModels, normalizeClass, onBeforeUnmount, onMounted, openBlock, shallowRef, toDisplayString, useModel, useTemplateRef, vShow, watch, withDirectives } from "vue";
|
|
2
|
+
import { richTextBlocks } from "@stonecrop/utilities";
|
|
3
|
+
import './assets/index.css';// src/utils/load.ts
|
|
4
|
+
var loading;
|
|
5
|
+
/**
|
|
6
|
+
* Editor.js and its tools, imported the first time a field is edited. A form that only shows documents never loads
|
|
7
|
+
* them, and nothing touches the DOM while a page renders on the server.
|
|
8
|
+
*/
|
|
9
|
+
function loadEditor() {
|
|
10
|
+
loading ??= Promise.all([
|
|
11
|
+
import("@editorjs/editorjs"),
|
|
12
|
+
import("@editorjs/header"),
|
|
13
|
+
import("@editorjs/list"),
|
|
14
|
+
import("@editorjs/quote"),
|
|
15
|
+
import("@editorjs/delimiter")
|
|
16
|
+
]).then(([editor, header, list, quote, delimiter]) => ({
|
|
17
|
+
EditorJS: editor.default,
|
|
18
|
+
tools: {
|
|
19
|
+
header: {
|
|
20
|
+
class: header.default,
|
|
21
|
+
inlineToolbar: true,
|
|
22
|
+
config: {
|
|
23
|
+
levels: [
|
|
24
|
+
1,
|
|
25
|
+
2,
|
|
26
|
+
3,
|
|
27
|
+
4
|
|
28
|
+
],
|
|
29
|
+
defaultLevel: 2
|
|
30
|
+
}
|
|
31
|
+
},
|
|
32
|
+
list: {
|
|
33
|
+
class: list.default,
|
|
34
|
+
inlineToolbar: true
|
|
35
|
+
},
|
|
36
|
+
quote: {
|
|
37
|
+
class: quote.default,
|
|
38
|
+
inlineToolbar: true
|
|
39
|
+
},
|
|
40
|
+
delimiter: delimiter.default
|
|
41
|
+
}
|
|
42
|
+
})).catch((error) => {
|
|
43
|
+
loading = void 0;
|
|
44
|
+
throw error;
|
|
45
|
+
});
|
|
46
|
+
return loading;
|
|
47
|
+
}
|
|
48
|
+
// src/utils/render.ts
|
|
49
|
+
var INLINE_TAGS = /* @__PURE__ */ new Set([
|
|
50
|
+
"a",
|
|
51
|
+
"b",
|
|
52
|
+
"br",
|
|
53
|
+
"code",
|
|
54
|
+
"em",
|
|
55
|
+
"i",
|
|
56
|
+
"mark",
|
|
57
|
+
"s",
|
|
58
|
+
"strong",
|
|
59
|
+
"u"
|
|
60
|
+
]);
|
|
61
|
+
var SAFE_HREF = /^(https?:|mailto:|tel:|\/|#)/i;
|
|
62
|
+
var escapeText = (text) => text.replace(/</g, "<").replace(/>/g, ">");
|
|
63
|
+
var escapeAttr = (text) => text.replace(/&/g, "&").replace(/"/g, """).replace(/</g, "<");
|
|
64
|
+
/** The href an `<a>` tag carries, decoded only as far as needed to read its scheme. */
|
|
65
|
+
function hrefOf(attrs) {
|
|
66
|
+
const match = /\bhref\s*=\s*(?:"([^"]*)"|'([^']*)'|([^\s>]+))/i.exec(attrs);
|
|
67
|
+
const href = (match?.[1] ?? match?.[2] ?? match?.[3])?.replace(/&/g, "&").trim();
|
|
68
|
+
return href && SAFE_HREF.test(href) ? href : void 0;
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* A block's inline HTML, rebuilt from the tags Editor.js writes. Each allowed tag is written anew without its
|
|
72
|
+
* attributes, a link keeping only an http(s), mailto, tel or relative href; every other `<` and `>` is escaped.
|
|
73
|
+
* Entities already in the text (`&`, ` `) are left as they are.
|
|
74
|
+
*/
|
|
75
|
+
function sanitizeInline(html) {
|
|
76
|
+
if (typeof html !== "string") return "";
|
|
77
|
+
let out = "";
|
|
78
|
+
let last = 0;
|
|
79
|
+
for (const match of html.matchAll(/<(\/?)([a-z][a-z0-9]*)\b([^<>]*)>/gi)) {
|
|
80
|
+
out += escapeText(html.slice(last, match.index));
|
|
81
|
+
last = match.index + match[0].length;
|
|
82
|
+
const [, closing, rawName, attrs] = match;
|
|
83
|
+
const name = rawName.toLowerCase();
|
|
84
|
+
if (!INLINE_TAGS.has(name)) continue;
|
|
85
|
+
if (name === "br") out += closing ? "" : "<br>";
|
|
86
|
+
else if (closing) out += `</${name}>`;
|
|
87
|
+
else if (name === "a") {
|
|
88
|
+
const href = hrefOf(attrs);
|
|
89
|
+
out += href ? `<a href="${escapeAttr(href)}" target="_blank" rel="nofollow noopener noreferrer">` : "<a>";
|
|
90
|
+
} else out += `<${name}>`;
|
|
91
|
+
}
|
|
92
|
+
return out + escapeText(html.slice(last));
|
|
93
|
+
}
|
|
94
|
+
function renderListItems(items, tag, checklist) {
|
|
95
|
+
return items.map(({ html, checked, items: nested }) => {
|
|
96
|
+
const box = checklist ? `<span class="a-editor__check" role="img" aria-label="${checked ? "done" : "not done"}">${checked ? "☑" : "☐"}</span> ` : "";
|
|
97
|
+
const sublist = nested.length ? renderList(nested, tag, checklist) : "";
|
|
98
|
+
return `<li${checklist && checked ? " class=\"a-editor__checked\"" : ""}>${box}${sanitizeInline(html)}${sublist}</li>`;
|
|
99
|
+
}).join("");
|
|
100
|
+
}
|
|
101
|
+
function renderList(items, tag, checklist, start) {
|
|
102
|
+
const startAttr = tag === "ol" && start !== void 0 ? ` start="${start}"` : "";
|
|
103
|
+
return `<${tag}${checklist ? " class=\"a-editor__checklist\"" : ""}${startAttr}>${renderListItems(items, tag, checklist)}</${tag}>`;
|
|
104
|
+
}
|
|
105
|
+
function renderBlock(block) {
|
|
106
|
+
switch (block.kind) {
|
|
107
|
+
case "paragraph": return `<p>${sanitizeInline(block.html)}</p>`;
|
|
108
|
+
case "header": return `<h${block.level}>${sanitizeInline(block.html)}</h${block.level}>`;
|
|
109
|
+
case "list": return renderList(block.items, block.style === "ordered" ? "ol" : "ul", block.style === "checklist", block.start);
|
|
110
|
+
case "quote": {
|
|
111
|
+
const align = block.centered ? " class=\"a-editor__quote--center\"" : "";
|
|
112
|
+
const caption = sanitizeInline(block.caption);
|
|
113
|
+
return `<blockquote${align}><p>${sanitizeInline(block.html)}</p>${caption ? `<cite>${caption}</cite>` : ""}</blockquote>`;
|
|
114
|
+
}
|
|
115
|
+
default: return "<hr>";
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
/**
|
|
119
|
+
* An Editor.js document as static HTML, for a field that is not being edited. Every piece of stored text passes
|
|
120
|
+
* through `sanitizeInline`, so the result is safe to bind with `v-html`. Empty for a field never edited.
|
|
121
|
+
* @public
|
|
122
|
+
*/
|
|
123
|
+
function renderBlocks(value) {
|
|
124
|
+
return richTextBlocks(value).map(renderBlock).join("");
|
|
125
|
+
}
|
|
126
|
+
/** A value with every string in it, however deep, passed through `sanitizeInline`. */
|
|
127
|
+
function sanitizeData(value) {
|
|
128
|
+
if (typeof value === "string") return sanitizeInline(value);
|
|
129
|
+
if (Array.isArray(value)) return value.map(sanitizeData);
|
|
130
|
+
if (value !== null && typeof value === "object") return sanitizeFields(value);
|
|
131
|
+
return value;
|
|
132
|
+
}
|
|
133
|
+
var sanitizeFields = (value) => Object.fromEntries(Object.entries(value).map(([key, entry]) => [key, sanitizeData(entry)]));
|
|
134
|
+
/**
|
|
135
|
+
* A copy of a document that is safe to hand Editor.js, which puts each block's HTML on the page as it is. Every
|
|
136
|
+
* string in each block's data passes through `sanitizeInline`, whatever tool the block is from, so a stored
|
|
137
|
+
* `<img onerror=…>` reaches the editor as text.
|
|
138
|
+
*/
|
|
139
|
+
function sanitizeDocument(value) {
|
|
140
|
+
const blocks = Array.isArray(value.blocks) ? value.blocks : [];
|
|
141
|
+
return {
|
|
142
|
+
...value,
|
|
143
|
+
blocks: blocks.filter((block) => block !== null && typeof block === "object").map((block) => ({
|
|
144
|
+
...block,
|
|
145
|
+
data: sanitizeFields(block.data ?? {})
|
|
146
|
+
}))
|
|
147
|
+
};
|
|
148
|
+
}
|
|
149
|
+
// src/components/AEditor.vue?vue&type=script&setup=true&lang.ts
|
|
150
|
+
var _hoisted_1 = [
|
|
151
|
+
"id",
|
|
152
|
+
"aria-labelledby",
|
|
153
|
+
"aria-required",
|
|
154
|
+
"aria-invalid",
|
|
155
|
+
"aria-describedby"
|
|
156
|
+
];
|
|
157
|
+
var _hoisted_2 = ["aria-labelledby", "innerHTML"];
|
|
158
|
+
var _hoisted_3 = ["id"];
|
|
159
|
+
var _hoisted_4 = ["id"];
|
|
160
|
+
// src/components/AEditor.vue
|
|
161
|
+
var AEditor_default = /* @__PURE__ */ defineComponent({
|
|
162
|
+
__name: "AEditor",
|
|
163
|
+
props: /*@__PURE__*/ mergeModels({
|
|
164
|
+
label: { default: "" },
|
|
165
|
+
mode: { default: "edit" },
|
|
166
|
+
uuid: { default: () => void 0 },
|
|
167
|
+
required: {
|
|
168
|
+
type: Boolean,
|
|
169
|
+
default: false
|
|
170
|
+
},
|
|
171
|
+
errors: { default: () => void 0 },
|
|
172
|
+
placeholder: { default: "" },
|
|
173
|
+
validation: { default: () => void 0 }
|
|
174
|
+
}, {
|
|
175
|
+
"modelValue": { default: null },
|
|
176
|
+
"modelModifiers": {}
|
|
177
|
+
}),
|
|
178
|
+
emits: ["update:modelValue"],
|
|
179
|
+
setup(__props) {
|
|
180
|
+
/**
|
|
181
|
+
* The document: Editor.js `OutputData` (`time`, `blocks`, `version`), or `null` for a field never edited or
|
|
182
|
+
* emptied of every block. Each change is emitted as the new object `save()` returns, and nothing here mutates an
|
|
183
|
+
* object once it is emitted.
|
|
184
|
+
*/
|
|
185
|
+
const model = useModel(__props, "modelValue");
|
|
186
|
+
const labelId = computed(() => __props.uuid ? `${__props.uuid}-label` : void 0);
|
|
187
|
+
const errorText = computed(() => __props.errors?.length ? __props.errors.join("; ") : __props.validation?.errorMessage ?? "");
|
|
188
|
+
const errorId = computed(() => __props.uuid ? `${__props.uuid}-error` : void 0);
|
|
189
|
+
const describedBy = computed(() => errorText.value ? errorId.value : void 0);
|
|
190
|
+
const invalid = computed(() => errorText.value ? true : void 0);
|
|
191
|
+
const staticHtml = computed(() => renderBlocks(model.value));
|
|
192
|
+
const holder = useTemplateRef("holder");
|
|
193
|
+
const editor = shallowRef(null);
|
|
194
|
+
/** The blocks of a document, as the text they compare by. A field never edited holds no blocks. */
|
|
195
|
+
const blocksKey = (value) => JSON.stringify(value?.blocks ?? []);
|
|
196
|
+
/**
|
|
197
|
+
* A copy of the bound value for Editor.js to hold. Editor.js keeps the object it is handed, and the bound one may
|
|
198
|
+
* be the record's own value, which the operation log keeps by reference for undo. Editor.js also puts each
|
|
199
|
+
* block's HTML on the page unsanitized, so the copy's text is sanitized as the static view's is.
|
|
200
|
+
*/
|
|
201
|
+
const editorData = (value) => value?.blocks?.length ? sanitizeDocument(JSON.parse(JSON.stringify(value))) : void 0;
|
|
202
|
+
/** What a saved document is bound as: `null` once no blocks are left, as every other emptied field holds. */
|
|
203
|
+
const boundValue = (saved) => saved.blocks.length ? saved : null;
|
|
204
|
+
let generation = 0;
|
|
205
|
+
let lastEmitted;
|
|
206
|
+
let syncedKey;
|
|
207
|
+
function emit(saved) {
|
|
208
|
+
syncedKey = blocksKey(saved);
|
|
209
|
+
const value = boundValue(saved);
|
|
210
|
+
lastEmitted = value;
|
|
211
|
+
model.value = value;
|
|
212
|
+
}
|
|
213
|
+
async function mountEditor() {
|
|
214
|
+
const current = ++generation;
|
|
215
|
+
const el = holder.value;
|
|
216
|
+
if (!el) return;
|
|
217
|
+
const { EditorJS: Editor, tools } = await loadEditor();
|
|
218
|
+
if (current !== generation || !holder.value) return;
|
|
219
|
+
const instance = new Editor({
|
|
220
|
+
holder: el,
|
|
221
|
+
data: editorData(model.value),
|
|
222
|
+
placeholder: __props.placeholder || void 0,
|
|
223
|
+
minHeight: 0,
|
|
224
|
+
tools,
|
|
225
|
+
onChange: async (api) => {
|
|
226
|
+
const saved = await api.saver.save();
|
|
227
|
+
if (current !== generation || blocksKey(saved) === blocksKey(model.value)) return;
|
|
228
|
+
emit(saved);
|
|
229
|
+
}
|
|
230
|
+
});
|
|
231
|
+
editor.value = instance;
|
|
232
|
+
await instance.isReady;
|
|
233
|
+
if (current === generation) syncedKey = blocksKey(await instance.save());
|
|
234
|
+
}
|
|
235
|
+
async function destroyEditor() {
|
|
236
|
+
generation++;
|
|
237
|
+
const instance = editor.value;
|
|
238
|
+
editor.value = null;
|
|
239
|
+
if (!instance) return;
|
|
240
|
+
try {
|
|
241
|
+
await instance.isReady;
|
|
242
|
+
const saved = await instance.save();
|
|
243
|
+
if (syncedKey !== void 0 && blocksKey(saved) !== syncedKey) emit(saved);
|
|
244
|
+
syncedKey = void 0;
|
|
245
|
+
instance.destroy();
|
|
246
|
+
} catch {}
|
|
247
|
+
}
|
|
248
|
+
watch(() => model.value, async (value) => {
|
|
249
|
+
const instance = editor.value;
|
|
250
|
+
if (!instance || value === lastEmitted) return;
|
|
251
|
+
lastEmitted = void 0;
|
|
252
|
+
await instance.isReady;
|
|
253
|
+
if (instance !== editor.value) return;
|
|
254
|
+
const shown = await instance.save();
|
|
255
|
+
if (blocksKey(shown) === blocksKey(value)) {
|
|
256
|
+
syncedKey = blocksKey(shown);
|
|
257
|
+
return;
|
|
258
|
+
}
|
|
259
|
+
const data = editorData(value);
|
|
260
|
+
if (data) await instance.render(data);
|
|
261
|
+
else instance.clear();
|
|
262
|
+
if (instance === editor.value) syncedKey = blocksKey(await instance.save());
|
|
263
|
+
});
|
|
264
|
+
watch(() => __props.mode, async (m) => {
|
|
265
|
+
await destroyEditor();
|
|
266
|
+
if (m === "edit") await mountEditor();
|
|
267
|
+
}, { flush: "post" });
|
|
268
|
+
onMounted(() => {
|
|
269
|
+
if (__props.mode === "edit") mountEditor();
|
|
270
|
+
});
|
|
271
|
+
onBeforeUnmount(() => {
|
|
272
|
+
destroyEditor();
|
|
273
|
+
});
|
|
274
|
+
return (_ctx, _cache) => {
|
|
275
|
+
return openBlock(), createElementBlock("div", { class: normalizeClass(["aform_form-element a-editor", `a-editor--${__props.mode}`]) }, [
|
|
276
|
+
__props.mode === "edit" ? (openBlock(), createElementBlock("div", {
|
|
277
|
+
key: 0,
|
|
278
|
+
id: __props.uuid,
|
|
279
|
+
ref_key: "holder",
|
|
280
|
+
ref: holder,
|
|
281
|
+
class: "aform_input-field a-editor__holder",
|
|
282
|
+
role: "group",
|
|
283
|
+
"aria-labelledby": labelId.value,
|
|
284
|
+
"aria-required": __props.required || void 0,
|
|
285
|
+
"aria-invalid": invalid.value,
|
|
286
|
+
"aria-describedby": describedBy.value
|
|
287
|
+
}, null, 8, _hoisted_1)) : (openBlock(), createElementBlock("div", {
|
|
288
|
+
key: 1,
|
|
289
|
+
class: normalizeClass(["a-editor__static", { "aform_input-field": __props.mode === "read" }]),
|
|
290
|
+
"aria-labelledby": labelId.value,
|
|
291
|
+
innerHTML: staticHtml.value
|
|
292
|
+
}, null, 10, _hoisted_2)),
|
|
293
|
+
createElementVNode("label", {
|
|
294
|
+
id: labelId.value,
|
|
295
|
+
class: "aform_field-label"
|
|
296
|
+
}, toDisplayString(__props.label), 9, _hoisted_3),
|
|
297
|
+
__props.mode === "edit" ? withDirectives((openBlock(), createElementBlock("p", {
|
|
298
|
+
key: 2,
|
|
299
|
+
id: errorId.value,
|
|
300
|
+
class: "aform_error",
|
|
301
|
+
role: "alert"
|
|
302
|
+
}, toDisplayString(errorText.value), 9, _hoisted_4)), [[vShow, errorText.value]]) : createCommentVNode("", true)
|
|
303
|
+
], 2);
|
|
304
|
+
};
|
|
305
|
+
}
|
|
306
|
+
});
|
|
307
|
+
// src/index.ts
|
|
308
|
+
/**
|
|
309
|
+
* Install all Editor components
|
|
310
|
+
* @param app - Vue app instance
|
|
311
|
+
* @public
|
|
312
|
+
*/
|
|
313
|
+
function install(app) {
|
|
314
|
+
app.component("AEditor", AEditor_default);
|
|
315
|
+
}
|
|
316
|
+
export { AEditor_default as AEditor, install, renderBlocks };
|
|
317
|
+
|
|
318
|
+
//# sourceMappingURL=block-editor.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"block-editor.js","names":["_useModel","_openBlock","_createElementBlock","_normalizeClass","_createElementVNode","_toDisplayString","_withDirectives","_vShow","_createCommentVNode","_sfc_main","AEditor"],"sources":["../src/utils/load.ts","../src/utils/render.ts","../src/components/AEditor.vue","../src/components/AEditor.vue","../src/index.ts"],"sourcesContent":["import type EditorJS from '@editorjs/editorjs'\nimport type { ToolConstructable, ToolSettings } from '@editorjs/editorjs'\n\n/** Editor.js and the block tools this package ships. Paragraph is Editor.js's own default block. */\nexport type LoadedEditor = {\n\tEditorJS: typeof EditorJS\n\ttools: Record<string, ToolConstructable | ToolSettings>\n}\n\nlet loading: Promise<LoadedEditor> | undefined\n\n/**\n * Editor.js and its tools, imported the first time a field is edited. A form that only shows documents never loads\n * them, and nothing touches the DOM while a page renders on the server.\n */\nexport function loadEditor(): Promise<LoadedEditor> {\n\tloading ??= Promise.all([\n\t\timport('@editorjs/editorjs'),\n\t\timport('@editorjs/header'),\n\t\timport('@editorjs/list'),\n\t\timport('@editorjs/quote'),\n\t\timport('@editorjs/delimiter'),\n\t])\n\t\t.then(([editor, header, list, quote, delimiter]) => ({\n\t\t\tEditorJS: editor.default,\n\t\t\ttools: {\n\t\t\t\theader: {\n\t\t\t\t\tclass: header.default,\n\t\t\t\t\tinlineToolbar: true,\n\t\t\t\t\tconfig: { levels: [1, 2, 3, 4], defaultLevel: 2 },\n\t\t\t\t},\n\t\t\t\tlist: { class: list.default, inlineToolbar: true },\n\t\t\t\tquote: { class: quote.default, inlineToolbar: true },\n\t\t\t\tdelimiter: delimiter.default,\n\t\t\t},\n\t\t}))\n\t\t.catch((error: unknown) => {\n\t\t\t// A failed import (a dropped connection, say) is tried again by the next field that mounts.\n\t\t\tloading = undefined\n\t\t\tthrow error\n\t\t})\n\treturn loading\n}\n","import { richTextBlocks, type RichTextBlockParts, type RichTextListItem } from '@stonecrop/utilities'\n\nimport type { EditorBlock, EditorDocument } from '../types'\n\n// The inline markup Editor.js writes into a block's text: its bold, italic and link tools, and line breaks.\n// Anything else is shown as text, so a stored value can never put its own elements or attributes on the page.\nconst INLINE_TAGS = new Set(['a', 'b', 'br', 'code', 'em', 'i', 'mark', 's', 'strong', 'u'])\nconst SAFE_HREF = /^(https?:|mailto:|tel:|\\/|#)/i\n\nconst escapeText = (text: string) => text.replace(/</g, '<').replace(/>/g, '>')\nconst escapeAttr = (text: string) => text.replace(/&/g, '&').replace(/\"/g, '"').replace(/</g, '<')\n\n/** The href an `<a>` tag carries, decoded only as far as needed to read its scheme. */\nfunction hrefOf(attrs: string): string | undefined {\n\tconst match = /\\bhref\\s*=\\s*(?:\"([^\"]*)\"|'([^']*)'|([^\\s>]+))/i.exec(attrs)\n\tconst href = (match?.[1] ?? match?.[2] ?? match?.[3])?.replace(/&/g, '&').trim()\n\treturn href && SAFE_HREF.test(href) ? href : undefined\n}\n\n/**\n * A block's inline HTML, rebuilt from the tags Editor.js writes. Each allowed tag is written anew without its\n * attributes, a link keeping only an http(s), mailto, tel or relative href; every other `<` and `>` is escaped.\n * Entities already in the text (`&`, ` `) are left as they are.\n */\nexport function sanitizeInline(html: unknown): string {\n\tif (typeof html !== 'string') return ''\n\tlet out = ''\n\tlet last = 0\n\tfor (const match of html.matchAll(/<(\\/?)([a-z][a-z0-9]*)\\b([^<>]*)>/gi)) {\n\t\tout += escapeText(html.slice(last, match.index))\n\t\tlast = match.index + match[0].length\n\t\tconst [, closing, rawName, attrs] = match\n\t\tconst name = rawName.toLowerCase()\n\t\tif (!INLINE_TAGS.has(name)) continue\n\t\tif (name === 'br') out += closing ? '' : '<br>'\n\t\telse if (closing) out += `</${name}>`\n\t\telse if (name === 'a') {\n\t\t\tconst href = hrefOf(attrs)\n\t\t\tout += href ? `<a href=\"${escapeAttr(href)}\" target=\"_blank\" rel=\"nofollow noopener noreferrer\">` : '<a>'\n\t\t} else out += `<${name}>`\n\t}\n\treturn out + escapeText(html.slice(last))\n}\n\nfunction renderListItems(items: RichTextListItem[], tag: 'ol' | 'ul', checklist: boolean): string {\n\treturn items\n\t\t.map(({ html, checked, items: nested }) => {\n\t\t\tconst box = checklist\n\t\t\t\t? `<span class=\"a-editor__check\" role=\"img\" aria-label=\"${checked ? 'done' : 'not done'}\">${checked ? '☑' : '☐'}</span> `\n\t\t\t\t: ''\n\t\t\tconst sublist = nested.length ? renderList(nested, tag, checklist) : ''\n\t\t\treturn `<li${checklist && checked ? ' class=\"a-editor__checked\"' : ''}>${box}${sanitizeInline(html)}${sublist}</li>`\n\t\t})\n\t\t.join('')\n}\n\nfunction renderList(items: RichTextListItem[], tag: 'ol' | 'ul', checklist: boolean, start?: number): string {\n\tconst startAttr = tag === 'ol' && start !== undefined ? ` start=\"${start}\"` : ''\n\tconst cls = checklist ? ' class=\"a-editor__checklist\"' : ''\n\treturn `<${tag}${cls}${startAttr}>${renderListItems(items, tag, checklist)}</${tag}>`\n}\n\n// Which blocks there are, and what each shows, is `richTextBlockParts`'s to say, which the table cell's text reads too.\nfunction renderBlock(block: RichTextBlockParts): string {\n\tswitch (block.kind) {\n\t\tcase 'paragraph':\n\t\t\treturn `<p>${sanitizeInline(block.html)}</p>`\n\t\tcase 'header':\n\t\t\treturn `<h${block.level}>${sanitizeInline(block.html)}</h${block.level}>`\n\t\tcase 'list':\n\t\t\treturn renderList(block.items, block.style === 'ordered' ? 'ol' : 'ul', block.style === 'checklist', block.start)\n\t\tcase 'quote': {\n\t\t\tconst align = block.centered ? ' class=\"a-editor__quote--center\"' : ''\n\t\t\tconst caption = sanitizeInline(block.caption)\n\t\t\treturn `<blockquote${align}><p>${sanitizeInline(block.html)}</p>${caption ? `<cite>${caption}</cite>` : ''}</blockquote>`\n\t\t}\n\t\t// The delimiter, the one kind left.\n\t\tdefault:\n\t\t\treturn '<hr>'\n\t}\n}\n\n/**\n * An Editor.js document as static HTML, for a field that is not being edited. Every piece of stored text passes\n * through `sanitizeInline`, so the result is safe to bind with `v-html`. Empty for a field never edited.\n * @public\n */\nexport function renderBlocks(value: EditorDocument | null | undefined): string {\n\treturn richTextBlocks(value).map(renderBlock).join('')\n}\n\n/** A value with every string in it, however deep, passed through `sanitizeInline`. */\nfunction sanitizeData(value: unknown): unknown {\n\tif (typeof value === 'string') return sanitizeInline(value)\n\tif (Array.isArray(value)) return value.map(sanitizeData)\n\tif (value !== null && typeof value === 'object') return sanitizeFields(value)\n\treturn value\n}\n\nconst sanitizeFields = (value: object): Record<string, unknown> =>\n\tObject.fromEntries(Object.entries(value).map(([key, entry]) => [key, sanitizeData(entry)]))\n\n/**\n * A copy of a document that is safe to hand Editor.js, which puts each block's HTML on the page as it is. Every\n * string in each block's data passes through `sanitizeInline`, whatever tool the block is from, so a stored\n * `<img onerror=…>` reaches the editor as text.\n */\nexport function sanitizeDocument(value: EditorDocument): EditorDocument {\n\tconst blocks: unknown[] = Array.isArray(value.blocks) ? value.blocks : []\n\treturn {\n\t\t...value,\n\t\tblocks: blocks\n\t\t\t.filter((block): block is EditorBlock => block !== null && typeof block === 'object')\n\t\t\t.map(block => ({ ...block, data: sanitizeFields(block.data ?? {}) })),\n\t}\n}\n","<template>\n\t<div class=\"aform_form-element a-editor\" :class=\"`a-editor--${mode}`\">\n\t\t<div\n\t\t\tv-if=\"mode === 'edit'\"\n\t\t\t:id=\"uuid\"\n\t\t\tref=\"holder\"\n\t\t\tclass=\"aform_input-field a-editor__holder\"\n\t\t\trole=\"group\"\n\t\t\t:aria-labelledby=\"labelId\"\n\t\t\t:aria-required=\"required || undefined\"\n\t\t\t:aria-invalid=\"invalid\"\n\t\t\t:aria-describedby=\"describedBy\" />\n\t\t<!-- Rendered by renderBlocks, which rebuilds every stored tag, so v-html takes no markup from the value -->\n\t\t<!-- oxlint-disable-next-line vue/no-v-html -->\n\t\t<div\n\t\t\tv-else\n\t\t\tclass=\"a-editor__static\"\n\t\t\t:class=\"{ 'aform_input-field': mode === 'read' }\"\n\t\t\t:aria-labelledby=\"labelId\"\n\t\t\tv-html=\"staticHtml\" />\n\t\t<label :id=\"labelId\" class=\"aform_field-label\">{{ label }}</label>\n\t\t<p v-if=\"mode === 'edit'\" v-show=\"errorText\" :id=\"errorId\" class=\"aform_error\" role=\"alert\">{{ errorText }}</p>\n\t</div>\n</template>\n\n<script setup lang=\"ts\">\nimport type EditorJS from '@editorjs/editorjs'\nimport { computed, onBeforeUnmount, onMounted, shallowRef, useTemplateRef, watch } from 'vue'\n\nimport type { EditorDocument } from '../types'\nimport { loadEditor } from '../utils/load'\nimport { renderBlocks, sanitizeDocument } from '../utils/render'\n\nconst {\n\tlabel = '',\n\tmode = 'edit',\n\tuuid = undefined,\n\trequired = false,\n\terrors = undefined,\n\tplaceholder = '',\n\tvalidation = undefined,\n} = defineProps<{\n\t/** The field's label */\n\tlabel?: string\n\t/** `edit` mounts Editor.js; `read` and `display` render the saved blocks as static HTML. */\n\tmode?: 'edit' | 'read' | 'display'\n\t/** The id that ties the label and error message to the editor */\n\tuuid?: string\n\t/** Whether the field must hold a document */\n\trequired?: boolean\n\t/** Errors for this field, as AForm passes them */\n\terrors?: string[]\n\t/** Shown in the first empty block */\n\tplaceholder?: string\n\t/** A static error message from the schema, shown when there are no `errors` */\n\tvalidation?: { errorMessage?: string }\n}>()\n\n/**\n * The document: Editor.js `OutputData` (`time`, `blocks`, `version`), or `null` for a field never edited or\n * emptied of every block. Each change is emitted as the new object `save()` returns, and nothing here mutates an\n * object once it is emitted.\n */\nconst model = defineModel<EditorDocument | null>({ default: null })\n\nconst labelId = computed(() => (uuid ? `${uuid}-label` : undefined))\nconst errorText = computed(() => (errors?.length ? errors.join('; ') : (validation?.errorMessage ?? '')))\nconst errorId = computed(() => (uuid ? `${uuid}-error` : undefined))\nconst describedBy = computed(() => (errorText.value ? errorId.value : undefined))\nconst invalid = computed(() => (errorText.value ? true : undefined))\n\nconst staticHtml = computed(() => renderBlocks(model.value))\n\nconst holder = useTemplateRef<HTMLDivElement>('holder')\nconst editor = shallowRef<EditorJS | null>(null)\n\n/** The blocks of a document, as the text they compare by. A field never edited holds no blocks. */\nconst blocksKey = (value: EditorDocument | null | undefined) => JSON.stringify(value?.blocks ?? [])\n\n/**\n * A copy of the bound value for Editor.js to hold. Editor.js keeps the object it is handed, and the bound one may\n * be the record's own value, which the operation log keeps by reference for undo. Editor.js also puts each\n * block's HTML on the page unsanitized, so the copy's text is sanitized as the static view's is.\n */\nconst editorData = (value: EditorDocument | null | undefined): EditorDocument | undefined =>\n\tvalue?.blocks?.length ? sanitizeDocument(JSON.parse(JSON.stringify(value)) as EditorDocument) : undefined\n\n/** What a saved document is bound as: `null` once no blocks are left, as every other emptied field holds. */\nconst boundValue = (saved: EditorDocument): EditorDocument | null => (saved.blocks.length ? saved : null)\n\n// Each mount gets its own number, so a mode change that destroys an editor while another is still starting\n// leaves the newer one alone.\nlet generation = 0\n// The last document this editor emitted. When it comes back bound, the editor already shows it.\nlet lastEmitted: EditorDocument | null | undefined\n// The blocks the editor showed when it last agreed with the bound value: after it started, rendered a value set\n// from outside, or emitted. Blocks that differ from these on the way out are an edit not yet emitted.\nlet syncedKey: string | undefined\n\nfunction emit(saved: EditorDocument) {\n\tsyncedKey = blocksKey(saved)\n\tconst value = boundValue(saved)\n\tlastEmitted = value\n\tmodel.value = value\n}\n\nasync function mountEditor() {\n\tconst current = ++generation\n\tconst el = holder.value\n\tif (!el) return\n\tconst { EditorJS: Editor, tools } = await loadEditor()\n\tif (current !== generation || !holder.value) return\n\n\tconst instance = new Editor({\n\t\tholder: el,\n\t\tdata: editorData(model.value),\n\t\tplaceholder: placeholder || undefined,\n\t\tminHeight: 0,\n\t\ttools,\n\t\tonChange: async api => {\n\t\t\tconst saved = await api.saver.save()\n\t\t\t// Editor.js reports a change for a render or a focus as well as an edit. Only a change to the blocks is\n\t\t\t// emitted, so a field the user has not edited stays null.\n\t\t\tif (current !== generation || blocksKey(saved) === blocksKey(model.value)) return\n\t\t\temit(saved)\n\t\t},\n\t})\n\teditor.value = instance\n\tawait instance.isReady\n\tif (current === generation) syncedKey = blocksKey(await instance.save())\n}\n\nasync function destroyEditor() {\n\tgeneration++\n\tconst instance = editor.value\n\teditor.value = null\n\tif (!instance) return\n\ttry {\n\t\tawait instance.isReady\n\t\t// Editor.js reports a change only once typing has paused, so an edit made just before the mode changes has\n\t\t// not been emitted yet. It is saved once more here, or the edit would be lost with the editor.\n\t\tconst saved = await instance.save()\n\t\tif (syncedKey !== undefined && blocksKey(saved) !== syncedKey) emit(saved)\n\t\tsyncedKey = undefined\n\t\tinstance.destroy()\n\t} catch {\n\t\t// It failed to start, so there is nothing to tear down.\n\t}\n}\n\n// A value set from outside, such as undo or a reloaded record, is shown in the editor. A value this editor\n// emitted already matches its blocks, so it is not rendered again, which would move the caret.\nwatch(\n\t() => model.value,\n\tasync value => {\n\t\tconst instance = editor.value\n\t\tif (!instance || value === lastEmitted) return\n\t\t// The bound value has moved on from this editor's last emission, so a later value equal to it (a redo\n\t\t// bringing back a null emitted earlier) comes from outside and must be shown.\n\t\tlastEmitted = undefined\n\t\tawait instance.isReady\n\t\tif (instance !== editor.value) return\n\t\tconst shown = await instance.save()\n\t\tif (blocksKey(shown) === blocksKey(value)) {\n\t\t\tsyncedKey = blocksKey(shown)\n\t\t\treturn\n\t\t}\n\t\tconst data = editorData(value)\n\t\tif (data) await instance.render(data)\n\t\telse instance.clear()\n\t\tif (instance === editor.value) syncedKey = blocksKey(await instance.save())\n\t}\n)\n\nwatch(\n\t() => mode,\n\tasync m => {\n\t\tawait destroyEditor()\n\t\tif (m === 'edit') await mountEditor()\n\t},\n\t// After the render, so the holder the mode change brings in is there to mount on.\n\t{ flush: 'post' }\n)\n\nonMounted(() => {\n\tif (mode === 'edit') void mountEditor()\n})\n\nonBeforeUnmount(() => {\n\tvoid destroyEditor()\n})\n</script>\n\n<style>\n/* Editor.js hangs the + and drag handle left of the text (right: 100%); the left padding keeps them inside the outline. */\n.a-editor__holder {\n\tmin-height: 6rem;\n\tpadding: 0.5rem 0.75rem 0.5rem 4rem;\n}\n\n.a-editor__holder .codex-editor__redactor {\n\tpadding-bottom: 1rem !important;\n}\n\n.a-editor__holder .ce-block__content,\n.a-editor__holder .ce-toolbar__content {\n\tmax-width: none;\n}\n\n.a-editor__static {\n\tdisplay: block;\n\tpadding: 0.5rem;\n\tmin-height: 2rem;\n\tcolor: var(--sc-cell-text-color);\n\tword-break: break-word;\n}\n\n.a-editor__static > :first-child {\n\tmargin-top: 0;\n}\n\n.a-editor__static > :last-child {\n\tmargin-bottom: 0;\n}\n\n.a-editor__static blockquote {\n\tmargin: 0.75rem 0;\n\tpadding-left: 1rem;\n\tborder-left: 3px solid var(--sc-input-border-color);\n}\n\n.a-editor__static blockquote cite {\n\tdisplay: block;\n\tfont-size: 0.875em;\n\topacity: 0.75;\n}\n\n.a-editor__static .a-editor__quote--center {\n\ttext-align: center;\n}\n\n.a-editor__static hr {\n\tborder: none;\n\ttext-align: center;\n\tmargin: 1rem 0;\n}\n\n.a-editor__static hr::before {\n\tcontent: '***';\n\tletter-spacing: 0.5em;\n}\n\n.a-editor__static .a-editor__checklist {\n\tlist-style: none;\n\tpadding-left: 0.25rem;\n}\n\n.a-editor__static .a-editor__checked {\n\ttext-decoration: line-through;\n\topacity: 0.75;\n}\n</style>\n","<template>\n\t<div class=\"aform_form-element a-editor\" :class=\"`a-editor--${mode}`\">\n\t\t<div\n\t\t\tv-if=\"mode === 'edit'\"\n\t\t\t:id=\"uuid\"\n\t\t\tref=\"holder\"\n\t\t\tclass=\"aform_input-field a-editor__holder\"\n\t\t\trole=\"group\"\n\t\t\t:aria-labelledby=\"labelId\"\n\t\t\t:aria-required=\"required || undefined\"\n\t\t\t:aria-invalid=\"invalid\"\n\t\t\t:aria-describedby=\"describedBy\" />\n\t\t<!-- Rendered by renderBlocks, which rebuilds every stored tag, so v-html takes no markup from the value -->\n\t\t<!-- oxlint-disable-next-line vue/no-v-html -->\n\t\t<div\n\t\t\tv-else\n\t\t\tclass=\"a-editor__static\"\n\t\t\t:class=\"{ 'aform_input-field': mode === 'read' }\"\n\t\t\t:aria-labelledby=\"labelId\"\n\t\t\tv-html=\"staticHtml\" />\n\t\t<label :id=\"labelId\" class=\"aform_field-label\">{{ label }}</label>\n\t\t<p v-if=\"mode === 'edit'\" v-show=\"errorText\" :id=\"errorId\" class=\"aform_error\" role=\"alert\">{{ errorText }}</p>\n\t</div>\n</template>\n\n<script setup lang=\"ts\">\nimport type EditorJS from '@editorjs/editorjs'\nimport { computed, onBeforeUnmount, onMounted, shallowRef, useTemplateRef, watch } from 'vue'\n\nimport type { EditorDocument } from '../types'\nimport { loadEditor } from '../utils/load'\nimport { renderBlocks, sanitizeDocument } from '../utils/render'\n\nconst {\n\tlabel = '',\n\tmode = 'edit',\n\tuuid = undefined,\n\trequired = false,\n\terrors = undefined,\n\tplaceholder = '',\n\tvalidation = undefined,\n} = defineProps<{\n\t/** The field's label */\n\tlabel?: string\n\t/** `edit` mounts Editor.js; `read` and `display` render the saved blocks as static HTML. */\n\tmode?: 'edit' | 'read' | 'display'\n\t/** The id that ties the label and error message to the editor */\n\tuuid?: string\n\t/** Whether the field must hold a document */\n\trequired?: boolean\n\t/** Errors for this field, as AForm passes them */\n\terrors?: string[]\n\t/** Shown in the first empty block */\n\tplaceholder?: string\n\t/** A static error message from the schema, shown when there are no `errors` */\n\tvalidation?: { errorMessage?: string }\n}>()\n\n/**\n * The document: Editor.js `OutputData` (`time`, `blocks`, `version`), or `null` for a field never edited or\n * emptied of every block. Each change is emitted as the new object `save()` returns, and nothing here mutates an\n * object once it is emitted.\n */\nconst model = defineModel<EditorDocument | null>({ default: null })\n\nconst labelId = computed(() => (uuid ? `${uuid}-label` : undefined))\nconst errorText = computed(() => (errors?.length ? errors.join('; ') : (validation?.errorMessage ?? '')))\nconst errorId = computed(() => (uuid ? `${uuid}-error` : undefined))\nconst describedBy = computed(() => (errorText.value ? errorId.value : undefined))\nconst invalid = computed(() => (errorText.value ? true : undefined))\n\nconst staticHtml = computed(() => renderBlocks(model.value))\n\nconst holder = useTemplateRef<HTMLDivElement>('holder')\nconst editor = shallowRef<EditorJS | null>(null)\n\n/** The blocks of a document, as the text they compare by. A field never edited holds no blocks. */\nconst blocksKey = (value: EditorDocument | null | undefined) => JSON.stringify(value?.blocks ?? [])\n\n/**\n * A copy of the bound value for Editor.js to hold. Editor.js keeps the object it is handed, and the bound one may\n * be the record's own value, which the operation log keeps by reference for undo. Editor.js also puts each\n * block's HTML on the page unsanitized, so the copy's text is sanitized as the static view's is.\n */\nconst editorData = (value: EditorDocument | null | undefined): EditorDocument | undefined =>\n\tvalue?.blocks?.length ? sanitizeDocument(JSON.parse(JSON.stringify(value)) as EditorDocument) : undefined\n\n/** What a saved document is bound as: `null` once no blocks are left, as every other emptied field holds. */\nconst boundValue = (saved: EditorDocument): EditorDocument | null => (saved.blocks.length ? saved : null)\n\n// Each mount gets its own number, so a mode change that destroys an editor while another is still starting\n// leaves the newer one alone.\nlet generation = 0\n// The last document this editor emitted. When it comes back bound, the editor already shows it.\nlet lastEmitted: EditorDocument | null | undefined\n// The blocks the editor showed when it last agreed with the bound value: after it started, rendered a value set\n// from outside, or emitted. Blocks that differ from these on the way out are an edit not yet emitted.\nlet syncedKey: string | undefined\n\nfunction emit(saved: EditorDocument) {\n\tsyncedKey = blocksKey(saved)\n\tconst value = boundValue(saved)\n\tlastEmitted = value\n\tmodel.value = value\n}\n\nasync function mountEditor() {\n\tconst current = ++generation\n\tconst el = holder.value\n\tif (!el) return\n\tconst { EditorJS: Editor, tools } = await loadEditor()\n\tif (current !== generation || !holder.value) return\n\n\tconst instance = new Editor({\n\t\tholder: el,\n\t\tdata: editorData(model.value),\n\t\tplaceholder: placeholder || undefined,\n\t\tminHeight: 0,\n\t\ttools,\n\t\tonChange: async api => {\n\t\t\tconst saved = await api.saver.save()\n\t\t\t// Editor.js reports a change for a render or a focus as well as an edit. Only a change to the blocks is\n\t\t\t// emitted, so a field the user has not edited stays null.\n\t\t\tif (current !== generation || blocksKey(saved) === blocksKey(model.value)) return\n\t\t\temit(saved)\n\t\t},\n\t})\n\teditor.value = instance\n\tawait instance.isReady\n\tif (current === generation) syncedKey = blocksKey(await instance.save())\n}\n\nasync function destroyEditor() {\n\tgeneration++\n\tconst instance = editor.value\n\teditor.value = null\n\tif (!instance) return\n\ttry {\n\t\tawait instance.isReady\n\t\t// Editor.js reports a change only once typing has paused, so an edit made just before the mode changes has\n\t\t// not been emitted yet. It is saved once more here, or the edit would be lost with the editor.\n\t\tconst saved = await instance.save()\n\t\tif (syncedKey !== undefined && blocksKey(saved) !== syncedKey) emit(saved)\n\t\tsyncedKey = undefined\n\t\tinstance.destroy()\n\t} catch {\n\t\t// It failed to start, so there is nothing to tear down.\n\t}\n}\n\n// A value set from outside, such as undo or a reloaded record, is shown in the editor. A value this editor\n// emitted already matches its blocks, so it is not rendered again, which would move the caret.\nwatch(\n\t() => model.value,\n\tasync value => {\n\t\tconst instance = editor.value\n\t\tif (!instance || value === lastEmitted) return\n\t\t// The bound value has moved on from this editor's last emission, so a later value equal to it (a redo\n\t\t// bringing back a null emitted earlier) comes from outside and must be shown.\n\t\tlastEmitted = undefined\n\t\tawait instance.isReady\n\t\tif (instance !== editor.value) return\n\t\tconst shown = await instance.save()\n\t\tif (blocksKey(shown) === blocksKey(value)) {\n\t\t\tsyncedKey = blocksKey(shown)\n\t\t\treturn\n\t\t}\n\t\tconst data = editorData(value)\n\t\tif (data) await instance.render(data)\n\t\telse instance.clear()\n\t\tif (instance === editor.value) syncedKey = blocksKey(await instance.save())\n\t}\n)\n\nwatch(\n\t() => mode,\n\tasync m => {\n\t\tawait destroyEditor()\n\t\tif (m === 'edit') await mountEditor()\n\t},\n\t// After the render, so the holder the mode change brings in is there to mount on.\n\t{ flush: 'post' }\n)\n\nonMounted(() => {\n\tif (mode === 'edit') void mountEditor()\n})\n\nonBeforeUnmount(() => {\n\tvoid destroyEditor()\n})\n</script>\n\n<style>\n/* Editor.js hangs the + and drag handle left of the text (right: 100%); the left padding keeps them inside the outline. */\n.a-editor__holder {\n\tmin-height: 6rem;\n\tpadding: 0.5rem 0.75rem 0.5rem 4rem;\n}\n\n.a-editor__holder .codex-editor__redactor {\n\tpadding-bottom: 1rem !important;\n}\n\n.a-editor__holder .ce-block__content,\n.a-editor__holder .ce-toolbar__content {\n\tmax-width: none;\n}\n\n.a-editor__static {\n\tdisplay: block;\n\tpadding: 0.5rem;\n\tmin-height: 2rem;\n\tcolor: var(--sc-cell-text-color);\n\tword-break: break-word;\n}\n\n.a-editor__static > :first-child {\n\tmargin-top: 0;\n}\n\n.a-editor__static > :last-child {\n\tmargin-bottom: 0;\n}\n\n.a-editor__static blockquote {\n\tmargin: 0.75rem 0;\n\tpadding-left: 1rem;\n\tborder-left: 3px solid var(--sc-input-border-color);\n}\n\n.a-editor__static blockquote cite {\n\tdisplay: block;\n\tfont-size: 0.875em;\n\topacity: 0.75;\n}\n\n.a-editor__static .a-editor__quote--center {\n\ttext-align: center;\n}\n\n.a-editor__static hr {\n\tborder: none;\n\ttext-align: center;\n\tmargin: 1rem 0;\n}\n\n.a-editor__static hr::before {\n\tcontent: '***';\n\tletter-spacing: 0.5em;\n}\n\n.a-editor__static .a-editor__checklist {\n\tlist-style: none;\n\tpadding-left: 0.25rem;\n}\n\n.a-editor__static .a-editor__checked {\n\ttext-decoration: line-through;\n\topacity: 0.75;\n}\n</style>\n","import { App } from 'vue'\n\nimport AEditor from './components/AEditor.vue'\nimport { renderBlocks } from './utils/render'\nexport type * from './types'\n\n/**\n * Install all Editor components\n * @param app - Vue app instance\n * @public\n */\nfunction install(app: App) {\n\tapp.component('AEditor', AEditor)\n}\n\nexport { install, AEditor, renderBlocks }\n"],"mappings":";;;AASA,IAAI;;;;;AAMJ,SAAgB,aAAoC;CACnD,YAAY,QAAQ,IAAI;EACvB,OAAO;EACP,OAAO;EACP,OAAO;EACP,OAAO;EACP,OAAO;CACR,CAAC,CAAC,CACA,MAAM,CAAC,QAAQ,QAAQ,MAAM,OAAO,gBAAgB;EACpD,UAAU,OAAO;EACjB,OAAO;GACN,QAAQ;IACP,OAAO,OAAO;IACd,eAAe;IACf,QAAQ;KAAE,QAAQ;MAAC;MAAG;MAAG;MAAG;KAAC;KAAG,cAAc;IAAE;GACjD;GACA,MAAM;IAAE,OAAO,KAAK;IAAS,eAAe;GAAK;GACjD,OAAO;IAAE,OAAO,MAAM;IAAS,eAAe;GAAK;GACnD,WAAW,UAAU;EACtB;CACD,EAAE,CAAC,CACF,OAAO,UAAmB;EAE1B,UAAU,KAAA;EACV,MAAM;CACP,CAAC;CACF,OAAO;AACR;;ACpCA,IAAM,8BAAc,IAAI,IAAI;CAAC;CAAK;CAAK;CAAM;CAAQ;CAAM;CAAK;CAAQ;CAAK;CAAU;AAAG,CAAC;AAC3F,IAAM,YAAY;AAElB,IAAM,cAAc,SAAiB,KAAK,QAAQ,MAAM,MAAM,CAAC,CAAC,QAAQ,MAAM,MAAM;AACpF,IAAM,cAAc,SAAiB,KAAK,QAAQ,MAAM,OAAO,CAAC,CAAC,QAAQ,MAAM,QAAQ,CAAC,CAAC,QAAQ,MAAM,MAAM;;AAG7G,SAAS,OAAO,OAAmC;CAClD,MAAM,QAAQ,kDAAkD,KAAK,KAAK;CAC1E,MAAM,QAAQ,QAAQ,MAA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M,MAAK;GACV,MAAM,cAAc;GACpB,IAAI,MAAM,QAAQ,MAAM,YAAY;EACrC,GAEA,EAAE,OAAO,OAAO,CACjB;EAEA,gBAAgB;GACf,IAAI,QAAA,SAAS,QAAQ,YAAiB;EACvC,CAAC;EAED,sBAAsB;GACrB,cAAmB;EACpB,CAAC;;GA7LA,OAAAC,UAAA,GAAAC,mBAqBM,OAAA,EArBD,OAAKC,eAAA,CAAC,+BAA6B,aAAsB,QAAA,MAAI,CAAA,E;IAE1D,QAAA,SAAI,UADXF,UAAA,GAAAC,mBASmC,OAAA;;KAPjC,IAAI,QAAA;KACD,SAAA;KAAJ,KAAI;KACJ,OAAM;KACN,MAAK;KACJ,mBAAiB,QAAA;KACjB,iBAAe,QAAA,YAAY,KAAA;KAC3B,gBAAc,QAAA;KACd,oBAAkB,YAAA;I,4BAGpBD,UAAA,GAAAC,mBAKuB,OAAA;;KAHtB,OAAKC,eAAA,CAAC,oBAAkB,EAAA,qBACO,QAAA,SAAI,OAAA,CAAA,CAAA;KAClC,mBAAiB,QAAA;KAClB,WAAQ,WAAA;;IACTC,mBAAkE,SAAA;KAA1D,IAAI,QAAA;KAAS,OAAM;IAAuB,GAAAC,gBAAA,QAAA,KAAK,GAAA,GAAA,UAAA;IAC9C,QAAA,SAAI,SAAbC,gBAAAL,UAAA,GAAAC,mBAA+G,KAAA;;KAAjE,IAAI,QAAA;KAAS,OAAM;KAAc,MAAK;IAAW,GAAAG,gBAAA,UAAA,KAAS,GAAA,GAAA,UAAA,IAAA,CAAtE,CAAAE,OAAA,UAAA,KAAS,C;;;;;;;;;;;AEV7C,SAAS,QAAQ,KAAU;CAC1B,IAAI,UAAU,WAAWG,eAAO;AACjC"}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import type { EditorDocument } from '../types';
|
|
2
|
+
type __VLS_Props = {
|
|
3
|
+
/** The field's label */
|
|
4
|
+
label?: string;
|
|
5
|
+
/** `edit` mounts Editor.js; `read` and `display` render the saved blocks as static HTML. */
|
|
6
|
+
mode?: 'edit' | 'read' | 'display';
|
|
7
|
+
/** The id that ties the label and error message to the editor */
|
|
8
|
+
uuid?: string;
|
|
9
|
+
/** Whether the field must hold a document */
|
|
10
|
+
required?: boolean;
|
|
11
|
+
/** Errors for this field, as AForm passes them */
|
|
12
|
+
errors?: string[];
|
|
13
|
+
/** Shown in the first empty block */
|
|
14
|
+
placeholder?: string;
|
|
15
|
+
/** A static error message from the schema, shown when there are no `errors` */
|
|
16
|
+
validation?: {
|
|
17
|
+
errorMessage?: string;
|
|
18
|
+
};
|
|
19
|
+
};
|
|
20
|
+
type __VLS_ModelProps = {
|
|
21
|
+
/**
|
|
22
|
+
* The document: Editor.js `OutputData` (`time`, `blocks`, `version`), or `null` for a field never edited or
|
|
23
|
+
* emptied of every block. Each change is emitted as the new object `save()` returns, and nothing here mutates an
|
|
24
|
+
* object once it is emitted.
|
|
25
|
+
*/
|
|
26
|
+
modelValue?: EditorDocument | null;
|
|
27
|
+
};
|
|
28
|
+
type __VLS_PublicProps = __VLS_Props & __VLS_ModelProps;
|
|
29
|
+
declare const __VLS_export: import("vue").DefineComponent<__VLS_PublicProps, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {
|
|
30
|
+
"update:modelValue": (value: EditorDocument | null) => any;
|
|
31
|
+
}, string, import("vue").PublicProps, Readonly<__VLS_PublicProps> & Readonly<{
|
|
32
|
+
"onUpdate:modelValue"?: ((value: EditorDocument | null) => any) | undefined;
|
|
33
|
+
}>, {}, {}, {}, {}, string, import("vue").ComponentProvideOptions, false, {}, any>;
|
|
34
|
+
declare const _default: typeof __VLS_export;
|
|
35
|
+
export default _default;
|
|
36
|
+
//# sourceMappingURL=AEditor.vue.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"AEditor.vue.d.ts","sourceRoot":"","sources":["../../../src/components/AEditor.vue"],"names":[],"mappings":"AA4QA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,UAAU,CAAA;AAI9C,KAAK,WAAW,GAAG;IAClB,wBAAwB;IACxB,KAAK,CAAC,EAAE,MAAM,CAAA;IACd,4FAA4F;IAC5F,IAAI,CAAC,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,CAAA;IAClC,iEAAiE;IACjE,IAAI,CAAC,EAAE,MAAM,CAAA;IACb,6CAA6C;IAC7C,QAAQ,CAAC,EAAE,OAAO,CAAA;IAClB,kDAAkD;IAClD,MAAM,CAAC,EAAE,MAAM,EAAE,CAAA;IACjB,qCAAqC;IACrC,WAAW,CAAC,EAAE,MAAM,CAAA;IACpB,+EAA+E;IAC/E,UAAU,CAAC,EAAE;QAAE,YAAY,CAAC,EAAE,MAAM,CAAA;KAAE,CAAA;CACtC,CAAC;AAsJF,KAAK,gBAAgB,GAAG;IACxB;;;;OAIG;IACH,UAAU,CAAC,EAAE,cAAc,GAAG,IAAI,CAAC;CAClC,CAAC;AAKF,KAAK,iBAAiB,GAAG,WAAW,GAAG,gBAAgB,CAAC;AA2ExD,QAAA,MAAM,YAAY;;;;kFAGhB,CAAC;wBACkB,OAAO,YAAY;AAAxC,wBAAyC"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { App } from 'vue';
|
|
2
|
+
import AEditor from './components/AEditor.vue';
|
|
3
|
+
import { renderBlocks } from './utils/render';
|
|
4
|
+
export type * from './types';
|
|
5
|
+
/**
|
|
6
|
+
* Install all Editor components
|
|
7
|
+
* @param app - Vue app instance
|
|
8
|
+
* @public
|
|
9
|
+
*/
|
|
10
|
+
declare function install(app: App): void;
|
|
11
|
+
export { install, AEditor, renderBlocks };
|
|
12
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,MAAM,KAAK,CAAA;AAEzB,OAAO,OAAO,MAAM,0BAA0B,CAAA;AAC9C,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAA;AAC7C,mBAAmB,SAAS,CAAA;AAE5B;;;;GAIG;AACH,iBAAS,OAAO,CAAC,GAAG,EAAE,GAAG,QAExB;AAED,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,YAAY,EAAE,CAAA"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* One block of an {@link EditorDocument}: its tool's name and that tool's data.
|
|
3
|
+
* @public
|
|
4
|
+
*/
|
|
5
|
+
export type EditorBlock = {
|
|
6
|
+
id?: string;
|
|
7
|
+
type: string;
|
|
8
|
+
data: Record<string, unknown>;
|
|
9
|
+
tunes?: Record<string, unknown>;
|
|
10
|
+
};
|
|
11
|
+
/**
|
|
12
|
+
* The value an `AEditor` field holds: the `OutputData` Editor.js's `save()` returns. Declared here rather than
|
|
13
|
+
* re-exported, so the package's types do not reach into Editor.js's own.
|
|
14
|
+
* @public
|
|
15
|
+
*/
|
|
16
|
+
export type EditorDocument = {
|
|
17
|
+
time?: number;
|
|
18
|
+
blocks: EditorBlock[];
|
|
19
|
+
version?: string;
|
|
20
|
+
};
|
|
21
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/types/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,MAAM,MAAM,WAAW,GAAG;IACzB,EAAE,CAAC,EAAE,MAAM,CAAA;IACX,IAAI,EAAE,MAAM,CAAA;IACZ,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;IAC7B,KAAK,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;CAC/B,CAAA;AAED;;;;GAIG;AACH,MAAM,MAAM,cAAc,GAAG;IAC5B,IAAI,CAAC,EAAE,MAAM,CAAA;IACb,MAAM,EAAE,WAAW,EAAE,CAAA;IACrB,OAAO,CAAC,EAAE,MAAM,CAAA;CAChB,CAAA"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type EditorJS from '@editorjs/editorjs';
|
|
2
|
+
import type { ToolConstructable, ToolSettings } from '@editorjs/editorjs';
|
|
3
|
+
/** Editor.js and the block tools this package ships. Paragraph is Editor.js's own default block. */
|
|
4
|
+
export type LoadedEditor = {
|
|
5
|
+
EditorJS: typeof EditorJS;
|
|
6
|
+
tools: Record<string, ToolConstructable | ToolSettings>;
|
|
7
|
+
};
|
|
8
|
+
/**
|
|
9
|
+
* Editor.js and its tools, imported the first time a field is edited. A form that only shows documents never loads
|
|
10
|
+
* them, and nothing touches the DOM while a page renders on the server.
|
|
11
|
+
*/
|
|
12
|
+
export declare function loadEditor(): Promise<LoadedEditor>;
|
|
13
|
+
//# sourceMappingURL=load.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"load.d.ts","sourceRoot":"","sources":["../../../src/utils/load.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,QAAQ,MAAM,oBAAoB,CAAA;AAC9C,OAAO,KAAK,EAAE,iBAAiB,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAA;AAEzE,oGAAoG;AACpG,MAAM,MAAM,YAAY,GAAG;IAC1B,QAAQ,EAAE,OAAO,QAAQ,CAAA;IACzB,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,iBAAiB,GAAG,YAAY,CAAC,CAAA;CACvD,CAAA;AAID;;;GAGG;AACH,wBAAgB,UAAU,IAAI,OAAO,CAAC,YAAY,CAAC,CA2BlD"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import type { EditorDocument } from '../types';
|
|
2
|
+
/**
|
|
3
|
+
* A block's inline HTML, rebuilt from the tags Editor.js writes. Each allowed tag is written anew without its
|
|
4
|
+
* attributes, a link keeping only an http(s), mailto, tel or relative href; every other `<` and `>` is escaped.
|
|
5
|
+
* Entities already in the text (`&`, ` `) are left as they are.
|
|
6
|
+
*/
|
|
7
|
+
export declare function sanitizeInline(html: unknown): string;
|
|
8
|
+
/**
|
|
9
|
+
* An Editor.js document as static HTML, for a field that is not being edited. Every piece of stored text passes
|
|
10
|
+
* through `sanitizeInline`, so the result is safe to bind with `v-html`. Empty for a field never edited.
|
|
11
|
+
* @public
|
|
12
|
+
*/
|
|
13
|
+
export declare function renderBlocks(value: EditorDocument | null | undefined): string;
|
|
14
|
+
/**
|
|
15
|
+
* A copy of a document that is safe to hand Editor.js, which puts each block's HTML on the page as it is. Every
|
|
16
|
+
* string in each block's data passes through `sanitizeInline`, whatever tool the block is from, so a stored
|
|
17
|
+
* `<img onerror=…>` reaches the editor as text.
|
|
18
|
+
*/
|
|
19
|
+
export declare function sanitizeDocument(value: EditorDocument): EditorDocument;
|
|
20
|
+
//# sourceMappingURL=render.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"render.d.ts","sourceRoot":"","sources":["../../../src/utils/render.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAe,cAAc,EAAE,MAAM,UAAU,CAAA;AAiB3D;;;;GAIG;AACH,wBAAgB,cAAc,CAAC,IAAI,EAAE,OAAO,GAAG,MAAM,CAkBpD;AAwCD;;;;GAIG;AACH,wBAAgB,YAAY,CAAC,KAAK,EAAE,cAAc,GAAG,IAAI,GAAG,SAAS,GAAG,MAAM,CAE7E;AAaD;;;;GAIG;AACH,wBAAgB,gBAAgB,CAAC,KAAK,EAAE,cAAc,GAAG,cAAc,CAQtE"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,85 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@stonecrop/block-editor",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
3
|
+
"version": "0.61.0",
|
|
4
|
+
"description": "Editor.js-based block editor component for Stonecrop",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"block-editor",
|
|
7
|
+
"components",
|
|
8
|
+
"editorjs",
|
|
9
|
+
"rich-text",
|
|
10
|
+
"stonecrop",
|
|
11
|
+
"vue"
|
|
12
|
+
],
|
|
13
|
+
"homepage": "https://github.com/agritheory/stonecrop#readme",
|
|
14
|
+
"bugs": {
|
|
15
|
+
"url": "https://github.com/agritheory/stonecrop/issues"
|
|
16
|
+
},
|
|
17
|
+
"license": "MIT",
|
|
18
|
+
"author": {
|
|
19
|
+
"name": "Tyler Matteson",
|
|
20
|
+
"email": "tyler@agritheory.com"
|
|
21
|
+
},
|
|
22
|
+
"repository": {
|
|
23
|
+
"type": "git",
|
|
24
|
+
"url": "https://github.com/agritheory/stonecrop",
|
|
25
|
+
"directory": "block_editor"
|
|
26
|
+
},
|
|
27
|
+
"files": [
|
|
28
|
+
"dist"
|
|
29
|
+
],
|
|
30
|
+
"type": "module",
|
|
31
|
+
"sideEffects": [
|
|
32
|
+
"**/*.vue",
|
|
33
|
+
"**/*.css"
|
|
34
|
+
],
|
|
35
|
+
"types": "./dist/src/index.d.ts",
|
|
36
|
+
"exports": {
|
|
37
|
+
".": {
|
|
38
|
+
"types": "./dist/src/index.d.ts",
|
|
39
|
+
"import": "./dist/block-editor.js"
|
|
40
|
+
},
|
|
41
|
+
"./styles": "./dist/assets/index.css",
|
|
42
|
+
"./package.json": "./package.json"
|
|
43
|
+
},
|
|
44
|
+
"publishConfig": {
|
|
45
|
+
"access": "public"
|
|
46
|
+
},
|
|
47
|
+
"dependencies": {
|
|
48
|
+
"@editorjs/delimiter": "^1.4.2",
|
|
49
|
+
"@editorjs/editorjs": "^2.31.7",
|
|
50
|
+
"@editorjs/header": "^2.8.9",
|
|
51
|
+
"@editorjs/list": "^2.0.9",
|
|
52
|
+
"@editorjs/quote": "^2.7.6",
|
|
53
|
+
"@stonecrop/utilities": "0.61.0"
|
|
54
|
+
},
|
|
55
|
+
"devDependencies": {
|
|
56
|
+
"@microsoft/api-extractor": "^7.58.7",
|
|
57
|
+
"@vitejs/plugin-vue": "^6.0.6",
|
|
58
|
+
"@vue/test-utils": "^2.4.10",
|
|
59
|
+
"jsdom": "^29.1.1",
|
|
60
|
+
"typescript": "^6.0.3",
|
|
61
|
+
"vite": "npm:@voidzero-dev/vite-plus-core@1.4.0",
|
|
62
|
+
"vite-plugin-lib-inject-css": "^2.2.2",
|
|
63
|
+
"vue": "^3.5.33",
|
|
64
|
+
"vue-component-meta": "^3.3.11",
|
|
65
|
+
"vue-router": "^5.0.6",
|
|
66
|
+
"vue-tsc": "^3.3.6"
|
|
67
|
+
},
|
|
68
|
+
"peerDependencies": {
|
|
69
|
+
"vue": "^3.5.33"
|
|
70
|
+
},
|
|
71
|
+
"engines": {
|
|
72
|
+
"node": ">=24.0.0"
|
|
73
|
+
},
|
|
74
|
+
"scripts": {
|
|
75
|
+
"dev": "vp build --watch",
|
|
76
|
+
"docs": "bash ../tools/scripts/run-docs.sh block_editor",
|
|
77
|
+
"lint": "vp lint",
|
|
78
|
+
"lint:fix": "vp lint --fix",
|
|
79
|
+
"preview": "vp preview",
|
|
80
|
+
"test": "vp test run",
|
|
81
|
+
"test:coverage": "vp test run --coverage",
|
|
82
|
+
"test:types": "vue-tsc --noEmit",
|
|
83
|
+
"test:watch": "vp test"
|
|
84
|
+
}
|
|
6
85
|
}
|