@dou-ui/editor 0.0.0-stage → 0.1.0-alpha.1
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/LICENSE +21 -0
- package/README.md +10 -2
- package/dist/catalog.js +18 -0
- package/dist/catalog.js.map +1 -0
- package/dist/code/code-editor-block.js +6 -0
- package/dist/code/code-editor-block.js.map +1 -0
- package/dist/code/code-editor-block.vue_vue_type_script_setup_true_lang.js +116 -0
- package/dist/code/code-editor-block.vue_vue_type_script_setup_true_lang.js.map +1 -0
- package/dist/code/index.js +69 -0
- package/dist/code/index.js.map +1 -0
- package/dist/code/languages.js +51 -0
- package/dist/code/languages.js.map +1 -0
- package/dist/code/view.js +255 -0
- package/dist/code/view.js.map +1 -0
- package/dist/collaboration/binding.js +381 -0
- package/dist/collaboration/binding.js.map +1 -0
- package/dist/collaboration/cursors.js +150 -0
- package/dist/collaboration/cursors.js.map +1 -0
- package/dist/collaboration/index.js +108 -0
- package/dist/collaboration/index.js.map +1 -0
- package/dist/collaboration/order.js +88 -0
- package/dist/collaboration/order.js.map +1 -0
- package/dist/collaboration/table.js +234 -0
- package/dist/collaboration/table.js.map +1 -0
- package/dist/collaboration/text.js +91 -0
- package/dist/collaboration/text.js.map +1 -0
- package/dist/components/block-handle.js +6 -0
- package/dist/components/block-handle.js.map +1 -0
- package/dist/components/block-handle.vue_vue_type_script_setup_true_lang.js +474 -0
- package/dist/components/block-handle.vue_vue_type_script_setup_true_lang.js.map +1 -0
- package/dist/components/bubble-toolbar.js +6 -0
- package/dist/components/bubble-toolbar.js.map +1 -0
- package/dist/components/bubble-toolbar.vue_vue_type_script_setup_true_lang.js +381 -0
- package/dist/components/bubble-toolbar.vue_vue_type_script_setup_true_lang.js.map +1 -0
- package/dist/components/comment-button.js +6 -0
- package/dist/components/comment-button.js.map +1 -0
- package/dist/components/comment-button.vue_vue_type_script_setup_true_lang.js +83 -0
- package/dist/components/comment-button.vue_vue_type_script_setup_true_lang.js.map +1 -0
- package/dist/components/comment-card.js +6 -0
- package/dist/components/comment-card.js.map +1 -0
- package/dist/components/comment-card.vue_vue_type_script_setup_true_lang.js +104 -0
- package/dist/components/comment-card.vue_vue_type_script_setup_true_lang.js.map +1 -0
- package/dist/components/menu-escape.js +25 -0
- package/dist/components/menu-escape.js.map +1 -0
- package/dist/components/search-bar.js +6 -0
- package/dist/components/search-bar.js.map +1 -0
- package/dist/components/search-bar.vue_vue_type_script_setup_true_lang.js +192 -0
- package/dist/components/search-bar.vue_vue_type_script_setup_true_lang.js.map +1 -0
- package/dist/components/slash-menu.js +6 -0
- package/dist/components/slash-menu.js.map +1 -0
- package/dist/components/slash-menu.vue_vue_type_script_setup_true_lang.js +164 -0
- package/dist/components/slash-menu.vue_vue_type_script_setup_true_lang.js.map +1 -0
- package/dist/core/align.js +94 -0
- package/dist/core/align.js.map +1 -0
- package/dist/core/block-selection.js +155 -0
- package/dist/core/block-selection.js.map +1 -0
- package/dist/core/blocks.js +132 -0
- package/dist/core/blocks.js.map +1 -0
- package/dist/core/changes.js +85 -0
- package/dist/core/changes.js.map +1 -0
- package/dist/core/colors.js +16 -0
- package/dist/core/colors.js.map +1 -0
- package/dist/core/commands.js +379 -0
- package/dist/core/commands.js.map +1 -0
- package/dist/core/comments.js +186 -0
- package/dist/core/comments.js.map +1 -0
- package/dist/core/compare.js +106 -0
- package/dist/core/compare.js.map +1 -0
- package/dist/core/convert.js +28 -0
- package/dist/core/convert.js.map +1 -0
- package/dist/core/diff.js +141 -0
- package/dist/core/diff.js.map +1 -0
- package/dist/core/editor.js +138 -0
- package/dist/core/editor.js.map +1 -0
- package/dist/core/extension.js +99 -0
- package/dist/core/extension.js.map +1 -0
- package/dist/core/file-drop.js +56 -0
- package/dist/core/file-drop.js.map +1 -0
- package/dist/core/highlight.js +120 -0
- package/dist/core/highlight.js.map +1 -0
- package/dist/core/input-rules.js +61 -0
- package/dist/core/input-rules.js.map +1 -0
- package/dist/core/keymap.js +38 -0
- package/dist/core/keymap.js.map +1 -0
- package/dist/core/model.js +196 -0
- package/dist/core/model.js.map +1 -0
- package/dist/core/output.js +263 -0
- package/dist/core/output.js.map +1 -0
- package/dist/core/plugins.js +102 -0
- package/dist/core/plugins.js.map +1 -0
- package/dist/core/prepare.js +102 -0
- package/dist/core/prepare.js.map +1 -0
- package/dist/core/schema.js +158 -0
- package/dist/core/schema.js.map +1 -0
- package/dist/core/search.js +197 -0
- package/dist/core/search.js.map +1 -0
- package/dist/core/selection.js +16 -0
- package/dist/core/selection.js.map +1 -0
- package/dist/core/slash.js +83 -0
- package/dist/core/slash.js.map +1 -0
- package/dist/core/transaction.js +311 -0
- package/dist/core/transaction.js.map +1 -0
- package/dist/define-block.js +177 -0
- package/dist/define-block.js.map +1 -0
- package/dist/document.js +157 -0
- package/dist/document.js.map +1 -0
- package/dist/dom.js +48 -0
- package/dist/dom.js.map +1 -0
- package/dist/editor.js +33 -0
- package/dist/editor.js.map +1 -0
- package/dist/editor.vue_vue_type_script_setup_true_lang.js +564 -0
- package/dist/editor.vue_vue_type_script_setup_true_lang.js.map +1 -0
- package/dist/editor2.js +6 -0
- package/dist/editor2.js.map +1 -0
- package/dist/extensions/align/align-menu.js +6 -0
- package/dist/extensions/align/align-menu.js.map +1 -0
- package/dist/extensions/align/align-menu.vue_vue_type_script_setup_true_lang.js +82 -0
- package/dist/extensions/align/align-menu.vue_vue_type_script_setup_true_lang.js.map +1 -0
- package/dist/extensions/align/align-sub.js +6 -0
- package/dist/extensions/align/align-sub.js.map +1 -0
- package/dist/extensions/align/align-sub.vue_vue_type_script_setup_true_lang.js +57 -0
- package/dist/extensions/align/align-sub.vue_vue_type_script_setup_true_lang.js.map +1 -0
- package/dist/extensions/align/commands.js +40 -0
- package/dist/extensions/align/commands.js.map +1 -0
- package/dist/extensions/align/index.js +27 -0
- package/dist/extensions/align/index.js.map +1 -0
- package/dist/extensions/attachment/attachment-block.js +6 -0
- package/dist/extensions/attachment/attachment-block.js.map +1 -0
- package/dist/extensions/attachment/attachment-block.vue_vue_type_script_setup_true_lang.js +119 -0
- package/dist/extensions/attachment/attachment-block.vue_vue_type_script_setup_true_lang.js.map +1 -0
- package/dist/extensions/attachment/files.js +66 -0
- package/dist/extensions/attachment/files.js.map +1 -0
- package/dist/extensions/attachment/index.js +132 -0
- package/dist/extensions/attachment/index.js.map +1 -0
- package/dist/extensions/blocks.js +170 -0
- package/dist/extensions/blocks.js.map +1 -0
- package/dist/extensions/callout/callout-block.js +6 -0
- package/dist/extensions/callout/callout-block.js.map +1 -0
- package/dist/extensions/callout/callout-block.vue_vue_type_script_setup_true_lang.js +71 -0
- package/dist/extensions/callout/callout-block.vue_vue_type_script_setup_true_lang.js.map +1 -0
- package/dist/extensions/callout/html.js +61 -0
- package/dist/extensions/callout/html.js.map +1 -0
- package/dist/extensions/callout/index.js +52 -0
- package/dist/extensions/callout/index.js.map +1 -0
- package/dist/extensions/callout/tones.js +12 -0
- package/dist/extensions/callout/tones.js.map +1 -0
- package/dist/extensions/code-block/code-block-view.js +6 -0
- package/dist/extensions/code-block/code-block-view.js.map +1 -0
- package/dist/extensions/code-block/code-block-view.vue_vue_type_script_setup_true_lang.js +87 -0
- package/dist/extensions/code-block/code-block-view.vue_vue_type_script_setup_true_lang.js.map +1 -0
- package/dist/extensions/code-block/index.js +98 -0
- package/dist/extensions/code-block/index.js.map +1 -0
- package/dist/extensions/code-block/languages.js +116 -0
- package/dist/extensions/code-block/languages.js.map +1 -0
- package/dist/extensions/colors/color-menu.js +6 -0
- package/dist/extensions/colors/color-menu.js.map +1 -0
- package/dist/extensions/colors/color-menu.vue_vue_type_script_setup_true_lang.js +113 -0
- package/dist/extensions/colors/color-menu.vue_vue_type_script_setup_true_lang.js.map +1 -0
- package/dist/extensions/colors/index.js +49 -0
- package/dist/extensions/colors/index.js.map +1 -0
- package/dist/extensions/colors/palette.js +26 -0
- package/dist/extensions/colors/palette.js.map +1 -0
- package/dist/extensions/editor-kit.js +35 -0
- package/dist/extensions/editor-kit.js.map +1 -0
- package/dist/extensions/embed/embed-block.js +6 -0
- package/dist/extensions/embed/embed-block.js.map +1 -0
- package/dist/extensions/embed/embed-block.vue_vue_type_script_setup_true_lang.js +210 -0
- package/dist/extensions/embed/embed-block.vue_vue_type_script_setup_true_lang.js.map +1 -0
- package/dist/extensions/embed/index.js +118 -0
- package/dist/extensions/embed/index.js.map +1 -0
- package/dist/extensions/embed/targets.js +79 -0
- package/dist/extensions/embed/targets.js.map +1 -0
- package/dist/extensions/formatting.js +153 -0
- package/dist/extensions/formatting.js.map +1 -0
- package/dist/extensions/image/image-block.js +6 -0
- package/dist/extensions/image/image-block.js.map +1 -0
- package/dist/extensions/image/image-block.vue_vue_type_script_setup_true_lang.js +206 -0
- package/dist/extensions/image/image-block.vue_vue_type_script_setup_true_lang.js.map +1 -0
- package/dist/extensions/image/index.js +125 -0
- package/dist/extensions/image/index.js.map +1 -0
- package/dist/extensions/image/uploads.js +96 -0
- package/dist/extensions/image/uploads.js.map +1 -0
- package/dist/extensions/list-html.js +58 -0
- package/dist/extensions/list-html.js.map +1 -0
- package/dist/extensions/lists.js +182 -0
- package/dist/extensions/lists.js.map +1 -0
- package/dist/extensions/mention/index.js +56 -0
- package/dist/extensions/mention/index.js.map +1 -0
- package/dist/extensions/mention/mention-menu.js +6 -0
- package/dist/extensions/mention/mention-menu.js.map +1 -0
- package/dist/extensions/mention/mention-menu.vue_vue_type_script_setup_true_lang.js +132 -0
- package/dist/extensions/mention/mention-menu.vue_vue_type_script_setup_true_lang.js.map +1 -0
- package/dist/extensions/mention/state.js +113 -0
- package/dist/extensions/mention/state.js.map +1 -0
- package/dist/extensions/table/commands.js +356 -0
- package/dist/extensions/table/commands.js.map +1 -0
- package/dist/extensions/table/html.js +134 -0
- package/dist/extensions/table/html.js.map +1 -0
- package/dist/extensions/table/index.js +56 -0
- package/dist/extensions/table/index.js.map +1 -0
- package/dist/extensions/table/plugin.js +81 -0
- package/dist/extensions/table/plugin.js.map +1 -0
- package/dist/extensions/table/schema.js +258 -0
- package/dist/extensions/table/schema.js.map +1 -0
- package/dist/extensions/table/table-controls.js +6 -0
- package/dist/extensions/table/table-controls.js.map +1 -0
- package/dist/extensions/table/table-controls.vue_vue_type_script_setup_true_lang.js +698 -0
- package/dist/extensions/table/table-controls.vue_vue_type_script_setup_true_lang.js.map +1 -0
- package/dist/extensions/table/view.js +19 -0
- package/dist/extensions/table/view.js.map +1 -0
- package/dist/extensions/toggle/index.js +87 -0
- package/dist/extensions/toggle/index.js.map +1 -0
- package/dist/extensions/toggle/state.js +120 -0
- package/dist/extensions/toggle/state.js.map +1 -0
- package/dist/extensions/toggle/toggle-block.js +6 -0
- package/dist/extensions/toggle/toggle-block.js.map +1 -0
- package/dist/extensions/toggle/toggle-block.vue_vue_type_script_setup_true_lang.js +42 -0
- package/dist/extensions/toggle/toggle-block.vue_vue_type_script_setup_true_lang.js.map +1 -0
- package/dist/index.js +49 -0
- package/dist/index.js.map +1 -0
- package/dist/locale.js +522 -0
- package/dist/locale.js.map +1 -0
- package/dist/markdown/index.js +24 -0
- package/dist/markdown/index.js.map +1 -0
- package/dist/style.css +1 -0
- package/dist/style.d.ts +1 -0
- package/dist/style.js +8 -0
- package/dist/types/catalog.d.ts +8 -0
- package/dist/types/code/code-editor-block.vue.d.ts +17 -0
- package/dist/types/code/index.d.ts +18 -0
- package/dist/types/code/languages.d.ts +7 -0
- package/dist/types/code/types.d.ts +37 -0
- package/dist/types/code/view.d.ts +12 -0
- package/dist/types/collaboration/binding.d.ts +32 -0
- package/dist/types/collaboration/cursors.d.ts +26 -0
- package/dist/types/collaboration/index.d.ts +47 -0
- package/dist/types/collaboration/order.d.ts +20 -0
- package/dist/types/collaboration/table.d.ts +25 -0
- package/dist/types/collaboration/text.d.ts +9 -0
- package/dist/types/components/block-handle.vue.d.ts +3 -0
- package/dist/types/components/bubble-toolbar.vue.d.ts +7 -0
- package/dist/types/components/comment-button.vue.d.ts +3 -0
- package/dist/types/components/comment-card.vue.d.ts +3 -0
- package/dist/types/components/menu-escape.d.ts +7 -0
- package/dist/types/components/search-bar.vue.d.ts +22 -0
- package/dist/types/components/slash-menu.vue.d.ts +11 -0
- package/dist/types/core/align.d.ts +16 -0
- package/dist/types/core/block-selection.d.ts +22 -0
- package/dist/types/core/blocks.d.ts +52 -0
- package/dist/types/core/changes.d.ts +14 -0
- package/dist/types/core/colors.d.ts +4 -0
- package/dist/types/core/commands.d.ts +61 -0
- package/dist/types/core/comments.d.ts +44 -0
- package/dist/types/core/compare.d.ts +10 -0
- package/dist/types/core/convert.d.ts +12 -0
- package/dist/types/core/diff.d.ts +49 -0
- package/dist/types/core/editor.d.ts +64 -0
- package/dist/types/core/extension.d.ts +167 -0
- package/dist/types/core/file-drop.d.ts +19 -0
- package/dist/types/core/highlight.d.ts +32 -0
- package/dist/types/core/input-rules.d.ts +21 -0
- package/dist/types/core/keymap.d.ts +8 -0
- package/dist/types/core/model.d.ts +158 -0
- package/dist/types/core/output.d.ts +64 -0
- package/dist/types/core/plugins.d.ts +24 -0
- package/dist/types/core/prepare.d.ts +23 -0
- package/dist/types/core/schema.d.ts +38 -0
- package/dist/types/core/search.d.ts +83 -0
- package/dist/types/core/selection.d.ts +8 -0
- package/dist/types/core/slash.d.ts +21 -0
- package/dist/types/core/transaction.d.ts +97 -0
- package/dist/types/define-block.d.ts +66 -0
- package/dist/types/document.d.ts +46 -0
- package/dist/types/dom.d.ts +17 -0
- package/dist/types/editor.d.ts +252 -0
- package/dist/types/editor.vue.d.ts +210 -0
- package/dist/types/extensions/align/align-menu.vue.d.ts +3 -0
- package/dist/types/extensions/align/align-sub.vue.d.ts +7 -0
- package/dist/types/extensions/align/commands.d.ts +13 -0
- package/dist/types/extensions/align/index.d.ts +7 -0
- package/dist/types/extensions/attachment/attachment-block.vue.d.ts +17 -0
- package/dist/types/extensions/attachment/files.d.ts +6 -0
- package/dist/types/extensions/attachment/index.d.ts +20 -0
- package/dist/types/extensions/blocks.d.ts +8 -0
- package/dist/types/extensions/callout/callout-block.vue.d.ts +14 -0
- package/dist/types/extensions/callout/html.d.ts +4 -0
- package/dist/types/extensions/callout/index.d.ts +3 -0
- package/dist/types/extensions/callout/tones.d.ts +8 -0
- package/dist/types/extensions/code-block/code-block-view.vue.d.ts +16 -0
- package/dist/types/extensions/code-block/index.d.ts +19 -0
- package/dist/types/extensions/code-block/languages.d.ts +9 -0
- package/dist/types/extensions/colors/color-menu.vue.d.ts +3 -0
- package/dist/types/extensions/colors/index.d.ts +7 -0
- package/dist/types/extensions/colors/palette.d.ts +7 -0
- package/dist/types/extensions/editor-kit.d.ts +37 -0
- package/dist/types/extensions/embed/embed-block.vue.d.ts +16 -0
- package/dist/types/extensions/embed/index.d.ts +18 -0
- package/dist/types/extensions/embed/targets.d.ts +32 -0
- package/dist/types/extensions/formatting.d.ts +8 -0
- package/dist/types/extensions/image/image-block.vue.d.ts +16 -0
- package/dist/types/extensions/image/index.d.ts +16 -0
- package/dist/types/extensions/image/uploads.d.ts +35 -0
- package/dist/types/extensions/list-html.d.ts +11 -0
- package/dist/types/extensions/lists.d.ts +6 -0
- package/dist/types/extensions/mention/index.d.ts +11 -0
- package/dist/types/extensions/mention/mention-menu.vue.d.ts +7 -0
- package/dist/types/extensions/mention/state.d.ts +28 -0
- package/dist/types/extensions/table/commands.d.ts +69 -0
- package/dist/types/extensions/table/html.d.ts +4 -0
- package/dist/types/extensions/table/index.d.ts +8 -0
- package/dist/types/extensions/table/plugin.d.ts +4 -0
- package/dist/types/extensions/table/schema.d.ts +23 -0
- package/dist/types/extensions/table/table-controls.vue.d.ts +3 -0
- package/dist/types/extensions/table/view.d.ts +13 -0
- package/dist/types/extensions/toggle/index.d.ts +7 -0
- package/dist/types/extensions/toggle/state.d.ts +17 -0
- package/dist/types/extensions/toggle/toggle-block.vue.d.ts +14 -0
- package/dist/types/index.d.ts +266 -0
- package/dist/types/locale.d.ts +195 -0
- package/dist/types/markdown/index.d.ts +14 -0
- package/dist/types/use-comments.d.ts +17 -0
- package/dist/use-comments.js +141 -0
- package/dist/use-comments.js.map +1 -0
- package/package.json +98 -4
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
import { escapeHTML, escapeMarkdown } from "../../core/output.js";
|
|
2
|
+
import { defineBlock } from "../../define-block.js";
|
|
3
|
+
import { fileDropPlugin } from "../../core/file-drop.js";
|
|
4
|
+
import { createUploads, readAsDataUrl } from "../image/uploads.js";
|
|
5
|
+
import { formatFileSize, isSafeFileSrc } from "./files.js";
|
|
6
|
+
import attachment_block_default from "./attachment-block.js";
|
|
7
|
+
import { defineComponent, h } from "vue";
|
|
8
|
+
import { PaperclipIcon } from "@dou-ui/icons";
|
|
9
|
+
// src/extensions/attachment/index.ts
|
|
10
|
+
var propsOf = (file) => ({
|
|
11
|
+
name: file.name,
|
|
12
|
+
size: file.size,
|
|
13
|
+
mime: file.type
|
|
14
|
+
});
|
|
15
|
+
function attrsOf(dom) {
|
|
16
|
+
const src = dom.getAttribute("href") ?? "";
|
|
17
|
+
if (!src || !isSafeFileSrc(src)) return false;
|
|
18
|
+
const size = Number(dom.dataset.size);
|
|
19
|
+
return {
|
|
20
|
+
src,
|
|
21
|
+
name: dom.getAttribute("download") || dom.textContent?.trim() || "",
|
|
22
|
+
size: Number.isFinite(size) && dom.dataset.size ? size : null,
|
|
23
|
+
mime: dom.dataset.mime ?? ""
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Attachment blocks: a file with its name and size and a download button.
|
|
28
|
+
* Files dropped or pasted into the editor become attachments (images stay
|
|
29
|
+
* images when the image block is there).
|
|
30
|
+
*/
|
|
31
|
+
function attachment(options = {}) {
|
|
32
|
+
const uploads = createUploads(options.upload ?? readAsDataUrl, {
|
|
33
|
+
type: "attachment",
|
|
34
|
+
isSafe: isSafeFileSrc,
|
|
35
|
+
propsOf,
|
|
36
|
+
allowed: "http, https, blob, relative addresses or data: URLs"
|
|
37
|
+
});
|
|
38
|
+
const View = defineComponent({
|
|
39
|
+
name: "DouEditorAttachmentView",
|
|
40
|
+
inheritAttrs: false,
|
|
41
|
+
setup(_props, { attrs }) {
|
|
42
|
+
return () => h(attachment_block_default, {
|
|
43
|
+
...attrs,
|
|
44
|
+
uploads,
|
|
45
|
+
accept: options.accept
|
|
46
|
+
});
|
|
47
|
+
}
|
|
48
|
+
});
|
|
49
|
+
return {
|
|
50
|
+
...defineBlock({
|
|
51
|
+
type: "attachment",
|
|
52
|
+
props: {
|
|
53
|
+
src: "",
|
|
54
|
+
name: "",
|
|
55
|
+
size: null,
|
|
56
|
+
mime: ""
|
|
57
|
+
},
|
|
58
|
+
content: "none",
|
|
59
|
+
component: View,
|
|
60
|
+
menu: {
|
|
61
|
+
label: (m) => m.types.attachment,
|
|
62
|
+
hint: (m) => m.hints.attachment,
|
|
63
|
+
icon: PaperclipIcon,
|
|
64
|
+
keywords: [
|
|
65
|
+
"file",
|
|
66
|
+
"attachment",
|
|
67
|
+
"upload",
|
|
68
|
+
"fj",
|
|
69
|
+
"fujian",
|
|
70
|
+
"wenjian"
|
|
71
|
+
]
|
|
72
|
+
},
|
|
73
|
+
spec: {
|
|
74
|
+
parseDOM: [{
|
|
75
|
+
tag: "a[data-attachment]",
|
|
76
|
+
priority: 60,
|
|
77
|
+
getAttrs: (dom) => attrsOf(dom)
|
|
78
|
+
}],
|
|
79
|
+
toDOM: (node) => [
|
|
80
|
+
"div",
|
|
81
|
+
{
|
|
82
|
+
class: "dou-editor__content dou-editor__content--attachment",
|
|
83
|
+
"data-content-type": "attachment"
|
|
84
|
+
},
|
|
85
|
+
[
|
|
86
|
+
"a",
|
|
87
|
+
{
|
|
88
|
+
href: isSafeFileSrc(String(node.attrs.src)) ? node.attrs.src : null,
|
|
89
|
+
download: node.attrs.name || "",
|
|
90
|
+
"data-attachment": "",
|
|
91
|
+
"data-size": node.attrs.size ?? null,
|
|
92
|
+
"data-mime": node.attrs.mime || null
|
|
93
|
+
},
|
|
94
|
+
node.attrs.name || node.attrs.src
|
|
95
|
+
]
|
|
96
|
+
]
|
|
97
|
+
}
|
|
98
|
+
}),
|
|
99
|
+
output: { blocks: { attachment: {
|
|
100
|
+
html: (node, { children }) => {
|
|
101
|
+
const { src, name, size, mime } = node.props;
|
|
102
|
+
if (!src || !isSafeFileSrc(String(src))) return children;
|
|
103
|
+
const label = escapeHTML(String(name || src));
|
|
104
|
+
const extra = [size != null && size !== "" ? ` data-size="${Number(size)}"` : "", mime ? ` data-mime="${escapeHTML(String(mime))}"` : ""].join("");
|
|
105
|
+
const shown = size != null && size !== "" ? ` (${formatFileSize(size)})` : "";
|
|
106
|
+
return `<p><a href="${escapeHTML(String(src))}" download="${escapeHTML(String(name ?? ""))}" data-attachment${extra}>${label}</a>${escapeHTML(shown)}</p>${children}`;
|
|
107
|
+
},
|
|
108
|
+
markdown: (node, { children }) => {
|
|
109
|
+
const { src, name } = node.props;
|
|
110
|
+
if (!src || !isSafeFileSrc(String(src))) return children;
|
|
111
|
+
const address = /[\s()<>]/.test(String(src)) ? `<${String(src)}>` : String(src);
|
|
112
|
+
const written = `[${escapeMarkdown(String(name || src))}](${address})`;
|
|
113
|
+
return children ? `${written}\n\n${children}` : written;
|
|
114
|
+
}
|
|
115
|
+
} } },
|
|
116
|
+
prepareHTML: (root) => {
|
|
117
|
+
for (const link of Array.from(root.querySelectorAll("p > a[data-attachment]"))) {
|
|
118
|
+
const paragraph = link.parentElement;
|
|
119
|
+
if (paragraph.children.length > 1) continue;
|
|
120
|
+
paragraph.replaceWith(link);
|
|
121
|
+
}
|
|
122
|
+
},
|
|
123
|
+
plugins: () => [fileDropPlugin({
|
|
124
|
+
accepts: () => true,
|
|
125
|
+
fallback: true,
|
|
126
|
+
insert: uploads.insert
|
|
127
|
+
})]
|
|
128
|
+
};
|
|
129
|
+
}
|
|
130
|
+
export { attachment, formatFileSize, isSafeFileSrc };
|
|
131
|
+
|
|
132
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","names":["AttachmentBlock"],"sources":["../../../src/extensions/attachment/index.ts"],"sourcesContent":["import { PaperclipIcon } from '@dou-ui/icons'\nimport { fileDropPlugin } from '../../core/file-drop'\nimport { defineComponent, h } from 'vue'\nimport type { EditorExtension } from '../../core/extension'\nimport { escapeHTML, escapeMarkdown } from '../../core/output'\nimport { defineBlock } from '../../define-block'\nimport { createUploads, readAsDataUrl, type FileUploader } from '../image/uploads'\nimport AttachmentBlock from './attachment-block.vue'\nimport { formatFileSize, isSafeFileSrc } from './files'\n\nexport interface AttachmentOptions {\n /**\n * Store the file and resolve with its address. Without it, files are\n * kept in the document as data URLs, which suits trying things out but\n * makes documents large.\n */\n upload?: FileUploader\n /** The file types the picker offers, as the `accept` of a file input. */\n accept?: string\n}\n\nconst propsOf = (file: File) => ({ name: file.name, size: file.size, mime: file.type })\n\nfunction attrsOf(dom: HTMLElement) {\n const src = dom.getAttribute('href') ?? ''\n if (!src || !isSafeFileSrc(src)) return false\n const size = Number(dom.dataset.size)\n return {\n src,\n name: dom.getAttribute('download') || dom.textContent?.trim() || '',\n size: Number.isFinite(size) && dom.dataset.size ? size : null,\n mime: dom.dataset.mime ?? '',\n }\n}\n\n/**\n * Attachment blocks: a file with its name and size and a download button.\n * Files dropped or pasted into the editor become attachments (images stay\n * images when the image block is there).\n */\nexport function attachment(options: AttachmentOptions = {}): EditorExtension {\n const uploads = createUploads(options.upload ?? readAsDataUrl, {\n type: 'attachment',\n isSafe: isSafeFileSrc,\n propsOf,\n allowed: 'http, https, blob, relative addresses or data: URLs',\n })\n const View = defineComponent({\n name: 'DouEditorAttachmentView',\n inheritAttrs: false,\n setup(_props, { attrs }) {\n return () => h(AttachmentBlock, { ...attrs, uploads, accept: options.accept } as never)\n },\n })\n const block = defineBlock({\n type: 'attachment',\n props: { src: '', name: '', size: null, mime: '' },\n content: 'none',\n component: View,\n menu: {\n label: (m) => m.types.attachment,\n hint: (m) => m.hints.attachment,\n icon: PaperclipIcon,\n keywords: ['file', 'attachment', 'upload', 'fj', 'fujian', 'wenjian'],\n },\n spec: {\n parseDOM: [\n { tag: 'a[data-attachment]', priority: 60, getAttrs: (dom) => attrsOf(dom as HTMLElement) },\n ],\n toDOM: (node) => [\n 'div',\n {\n class: 'dou-editor__content dou-editor__content--attachment',\n 'data-content-type': 'attachment',\n },\n [\n 'a',\n {\n href: isSafeFileSrc(String(node.attrs.src)) ? node.attrs.src : null,\n download: node.attrs.name || '',\n 'data-attachment': '',\n 'data-size': node.attrs.size ?? null,\n 'data-mime': node.attrs.mime || null,\n },\n node.attrs.name || node.attrs.src,\n ],\n ],\n },\n })\n return {\n ...block,\n output: {\n blocks: {\n attachment: {\n html: (node, { children }) => {\n const { src, name, size, mime } = node.props\n if (!src || !isSafeFileSrc(String(src))) return children\n const label = escapeHTML(String(name || src))\n const extra = [\n size != null && size !== '' ? ` data-size=\"${Number(size)}\"` : '',\n mime ? ` data-mime=\"${escapeHTML(String(mime))}\"` : '',\n ].join('')\n const shown = size != null && size !== '' ? ` (${formatFileSize(size)})` : ''\n return `<p><a href=\"${escapeHTML(String(src))}\" download=\"${escapeHTML(String(name ?? ''))}\" data-attachment${extra}>${label}</a>${escapeHTML(shown)}</p>${children}`\n },\n markdown: (node, { children }) => {\n const { src, name } = node.props\n if (!src || !isSafeFileSrc(String(src))) return children\n const address = /[\\s()<>]/.test(String(src)) ? `<${String(src)}>` : String(src)\n const written = `[${escapeMarkdown(String(name || src))}](${address})`\n return children ? `${written}\\n\\n${children}` : written\n },\n },\n },\n },\n // an attachment written as HTML sits in a paragraph of its own\n prepareHTML: (root) => {\n for (const link of Array.from(root.querySelectorAll('p > a[data-attachment]'))) {\n const paragraph = link.parentElement!\n if (paragraph.children.length > 1) continue\n paragraph.replaceWith(link)\n }\n },\n plugins: () => [\n fileDropPlugin({ accepts: () => true, fallback: true, insert: uploads.insert }),\n ],\n }\n}\n\nexport { formatFileSize, isSafeFileSrc, type FileUploader }\n"],"mappings":";;;;;;;;;AAqBA,IAAM,WAAW,U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Q,MAAM,KAAK,KAAK,iBAAiB,wBAAwB,CAAC,GAAG;IAC9E,MAAM,YAAY,KAAK;IACvB,IAAI,UAAU,SAAS,SAAS,GAAG;IACnC,UAAU,YAAY,IAAI;GAC5B;EACF;EACA,eAAe,CACb,eAAe;GAAE,eAAe;GAAM,UAAU;GAAM,QAAQ,QAAQ;EAAO,CAAC,CAChF;CACF;AACF"}
|
|
@@ -0,0 +1,170 @@
|
|
|
1
|
+
import { alignable } from "../core/align.js";
|
|
2
|
+
import { textBlock } from "../core/schema.js";
|
|
3
|
+
import { defineEditorExtension } from "../core/extension.js";
|
|
4
|
+
import { setBlockType } from "../core/commands.js";
|
|
5
|
+
import { atomInputRule, blockInputRule } from "../core/input-rules.js";
|
|
6
|
+
import { blockElement, splitContainer } from "../core/prepare.js";
|
|
7
|
+
import { indentLines } from "../core/output.js";
|
|
8
|
+
import { Heading1Icon, Heading2Icon, Heading3Icon, MinusIcon, PilcrowIcon, QuoteIcon } from "@dou-ui/icons";
|
|
9
|
+
// src/extensions/blocks.ts
|
|
10
|
+
/** The paragraph itself is part of the frame; this adds its menu entry and shortcut. */
|
|
11
|
+
var paragraph = defineEditorExtension({
|
|
12
|
+
name: "paragraph",
|
|
13
|
+
blockOptions: [{
|
|
14
|
+
key: "paragraph",
|
|
15
|
+
type: "paragraph",
|
|
16
|
+
label: (m) => m.types.paragraph,
|
|
17
|
+
hint: (m) => m.hints.paragraph,
|
|
18
|
+
icon: PilcrowIcon,
|
|
19
|
+
keywords: [
|
|
20
|
+
"text",
|
|
21
|
+
"p",
|
|
22
|
+
"zw",
|
|
23
|
+
"zhengwen",
|
|
24
|
+
"wenben"
|
|
25
|
+
]
|
|
26
|
+
}]
|
|
27
|
+
});
|
|
28
|
+
var LEVELS = [
|
|
29
|
+
1,
|
|
30
|
+
2,
|
|
31
|
+
3
|
|
32
|
+
];
|
|
33
|
+
var levelOf = (level) => Math.min(3, Math.max(1, Number(level) || 1));
|
|
34
|
+
var headingIcons = {
|
|
35
|
+
1: Heading1Icon,
|
|
36
|
+
2: Heading2Icon,
|
|
37
|
+
3: Heading3Icon
|
|
38
|
+
};
|
|
39
|
+
/** Headings, levels 1 to 3. `# ` to `### ` turn a paragraph into one. */
|
|
40
|
+
var heading = defineEditorExtension({
|
|
41
|
+
name: "heading",
|
|
42
|
+
blocks: { heading: alignable(textBlock("heading", {
|
|
43
|
+
attrs: { level: { default: 1 } },
|
|
44
|
+
normalizeProps: (attrs) => attrs.level === void 0 ? attrs : {
|
|
45
|
+
...attrs,
|
|
46
|
+
level: Math.min(3, Math.max(1, attrs.level))
|
|
47
|
+
},
|
|
48
|
+
parseDOM: [
|
|
49
|
+
1,
|
|
50
|
+
2,
|
|
51
|
+
3,
|
|
52
|
+
4,
|
|
53
|
+
5,
|
|
54
|
+
6
|
|
55
|
+
].map((level) => ({
|
|
56
|
+
tag: `h${level}`,
|
|
57
|
+
attrs: { level: Math.min(level, 3) }
|
|
58
|
+
})),
|
|
59
|
+
toDOM: (node) => [
|
|
60
|
+
`h${node.attrs.level}`,
|
|
61
|
+
{
|
|
62
|
+
class: "dou-editor__content dou-editor__content--heading",
|
|
63
|
+
"data-content-type": "heading"
|
|
64
|
+
},
|
|
65
|
+
0
|
|
66
|
+
]
|
|
67
|
+
})) },
|
|
68
|
+
output: { blocks: { heading: {
|
|
69
|
+
html: (block, { content, children }) => `<h${levelOf(block.props.level)}>${content}</h${levelOf(block.props.level)}>${children}`,
|
|
70
|
+
markdown: (block, { content, children }) => [`${"#".repeat(levelOf(block.props.level))} ${content}`.trimEnd(), children].filter(Boolean).join("\n\n")
|
|
71
|
+
} } },
|
|
72
|
+
inputRules: () => [blockInputRule(/^(#{1,3})\s$/, "heading", (match) => ({ level: match[1].length }))],
|
|
73
|
+
keymap: () => Object.fromEntries(LEVELS.map((level) => [`mod+alt+${level}`, setBlockType("heading", { level })])),
|
|
74
|
+
blockOptions: LEVELS.map((level) => ({
|
|
75
|
+
key: `heading${level}`,
|
|
76
|
+
type: "heading",
|
|
77
|
+
props: { level },
|
|
78
|
+
label: (m) => m.types[`heading${level}`],
|
|
79
|
+
hint: (m) => m.hints[`heading${level}`],
|
|
80
|
+
icon: headingIcons[level],
|
|
81
|
+
keywords: [
|
|
82
|
+
`h${level}`,
|
|
83
|
+
"heading",
|
|
84
|
+
"title",
|
|
85
|
+
"bt",
|
|
86
|
+
"biaoti"
|
|
87
|
+
],
|
|
88
|
+
shortcut: "#".repeat(level)
|
|
89
|
+
}))
|
|
90
|
+
});
|
|
91
|
+
/** A quotation. `> ` turns a paragraph into one. */
|
|
92
|
+
var quote = defineEditorExtension({
|
|
93
|
+
name: "quote",
|
|
94
|
+
blocks: { quote: alignable(textBlock("quote", {
|
|
95
|
+
parseDOM: [{ tag: "div[data-content-type=\"quote\"]" }, { tag: "blockquote" }],
|
|
96
|
+
toDOM: () => [
|
|
97
|
+
"blockquote",
|
|
98
|
+
{
|
|
99
|
+
class: "dou-editor__content dou-editor__content--quote",
|
|
100
|
+
"data-content-type": "quote"
|
|
101
|
+
},
|
|
102
|
+
0
|
|
103
|
+
]
|
|
104
|
+
})) },
|
|
105
|
+
output: { blocks: { quote: {
|
|
106
|
+
html: (_block, { content, children }) => `<blockquote><p>${content}</p>${children}</blockquote>`,
|
|
107
|
+
markdown: (_block, { content, children }) => indentLines([content, children].filter(Boolean).join("\n\n"), "> ", "> ")
|
|
108
|
+
} } },
|
|
109
|
+
prepareHTML: (root) => {
|
|
110
|
+
for (const element of Array.from(root.querySelectorAll("blockquote"))) {
|
|
111
|
+
const { content, children } = splitContainer(element);
|
|
112
|
+
element.replaceWith(blockElement(element.ownerDocument, "quote", content, children));
|
|
113
|
+
}
|
|
114
|
+
},
|
|
115
|
+
inputRules: () => [blockInputRule(/^>\s$/, "quote")],
|
|
116
|
+
blockOptions: [{
|
|
117
|
+
key: "quote",
|
|
118
|
+
type: "quote",
|
|
119
|
+
label: (m) => m.types.quote,
|
|
120
|
+
hint: (m) => m.hints.quote,
|
|
121
|
+
icon: QuoteIcon,
|
|
122
|
+
keywords: [
|
|
123
|
+
"quote",
|
|
124
|
+
"blockquote",
|
|
125
|
+
"yy",
|
|
126
|
+
"yinyong"
|
|
127
|
+
],
|
|
128
|
+
shortcut: ">"
|
|
129
|
+
}]
|
|
130
|
+
});
|
|
131
|
+
/** A horizontal line. `---` in an empty paragraph. */
|
|
132
|
+
var divider = defineEditorExtension({
|
|
133
|
+
name: "divider",
|
|
134
|
+
blocks: { divider: {
|
|
135
|
+
atom: true,
|
|
136
|
+
selectable: true,
|
|
137
|
+
parseDOM: [{ tag: "hr" }],
|
|
138
|
+
toDOM: () => [
|
|
139
|
+
"div",
|
|
140
|
+
{
|
|
141
|
+
class: "dou-editor__content dou-editor__content--divider",
|
|
142
|
+
"data-content-type": "divider"
|
|
143
|
+
},
|
|
144
|
+
["hr"]
|
|
145
|
+
]
|
|
146
|
+
} },
|
|
147
|
+
output: { blocks: { divider: {
|
|
148
|
+
html: () => "<hr>",
|
|
149
|
+
markdown: () => "---"
|
|
150
|
+
} } },
|
|
151
|
+
inputRules: () => [atomInputRule(/^(?:---|___|\*\*\*)$/, "divider")],
|
|
152
|
+
blockOptions: [{
|
|
153
|
+
key: "divider",
|
|
154
|
+
type: "divider",
|
|
155
|
+
label: (m) => m.types.divider,
|
|
156
|
+
hint: (m) => m.hints.divider,
|
|
157
|
+
icon: MinusIcon,
|
|
158
|
+
keywords: [
|
|
159
|
+
"hr",
|
|
160
|
+
"divider",
|
|
161
|
+
"line",
|
|
162
|
+
"fgx",
|
|
163
|
+
"fengexian"
|
|
164
|
+
],
|
|
165
|
+
shortcut: "---"
|
|
166
|
+
}]
|
|
167
|
+
});
|
|
168
|
+
export { divider, heading, paragraph, quote };
|
|
169
|
+
|
|
170
|
+
//# sourceMappingURL=blocks.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"blocks.js","names":[],"sources":["../../src/extensions/blocks.ts"],"sourcesContent":["import {\n Heading1Icon,\n Heading2Icon,\n Heading3Icon,\n MinusIcon,\n PilcrowIcon,\n QuoteIcon,\n} from '@dou-ui/icons'\nimport { setBlockType } from '../core/commands'\nimport { defineEditorExtension } from '../core/extension'\nimport { atomInputRule, blockInputRule } from '../core/input-rules'\nimport { indentLines } from '../core/output'\nimport { blockElement, splitContainer } from '../core/prepare'\nimport { alignable } from '../core/align'\nimport { textBlock } from '../core/schema'\n\n/** The paragraph itself is part of the frame; this adds its menu entry and shortcut. */\nexport const paragraph = defineEditorExtension({\n name: 'paragraph',\n blockOptions: [\n {\n key: 'paragraph',\n type: 'paragraph',\n label: (m) => m.types.paragraph,\n hint: (m) => m.hints.paragraph,\n icon: PilcrowIcon,\n keywords: ['text', 'p', 'zw', 'zhengwen', 'wenben'],\n },\n ],\n})\n\nconst LEVELS = [1, 2, 3] as const\nconst levelOf = (level: unknown) => Math.min(3, Math.max(1, Number(level) || 1))\nconst headingIcons = { 1: Heading1Icon, 2: Heading2Icon, 3: Heading3Icon }\n\n/** Headings, levels 1 to 3. `# ` to `### ` turn a paragraph into one. */\nexport const heading = defineEditorExtension({\n name: 'heading',\n blocks: {\n heading: alignable(\n textBlock('heading', {\n attrs: { level: { default: 1 } },\n normalizeProps: (attrs: { level?: number }) =>\n attrs.level === undefined\n ? attrs\n : { ...attrs, level: Math.min(3, Math.max(1, attrs.level)) },\n parseDOM: [1, 2, 3, 4, 5, 6].map((level) => ({\n tag: `h${level}`,\n attrs: { level: Math.min(level, 3) },\n })),\n toDOM: (node) => [\n `h${node.attrs.level}`,\n {\n class: 'dou-editor__content dou-editor__content--heading',\n 'data-content-type': 'heading',\n },\n 0,\n ],\n }),\n ),\n },\n output: {\n blocks: {\n heading: {\n html: (block, { content, children }) =>\n `<h${levelOf(block.props.level)}>${content}</h${levelOf(block.props.level)}>${children}`,\n markdown: (block, { content, children }) =>\n [`${'#'.repeat(levelOf(block.props.level))} ${content}`.trimEnd(), children]\n .filter(Boolean)\n .join('\\n\\n'),\n },\n },\n },\n inputRules: () => [\n blockInputRule(/^(#{1,3})\\s$/, 'heading', (match) => ({ level: match[1]!.length })),\n ],\n keymap: () =>\n Object.fromEntries(\n LEVELS.map((level) => [`mod+alt+${level}`, setBlockType('heading', { level })]),\n ),\n blockOptions: LEVELS.map((level) => ({\n key: `heading${level}`,\n type: 'heading',\n props: { level },\n label: (m) => m.types[`heading${level}`],\n hint: (m) => m.hints[`heading${level}`],\n icon: headingIcons[level],\n keywords: [`h${level}`, 'heading', 'title', 'bt', 'biaoti'],\n shortcut: '#'.repeat(level),\n })),\n})\n\n/** A quotation. `> ` turns a paragraph into one. */\nexport const quote = defineEditorExtension({\n name: 'quote',\n blocks: {\n quote: alignable(\n textBlock('quote', {\n parseDOM: [{ tag: 'div[data-content-type=\"quote\"]' }, { tag: 'blockquote' }],\n toDOM: () => [\n 'blockquote',\n { class: 'dou-editor__content dou-editor__content--quote', 'data-content-type': 'quote' },\n 0,\n ],\n }),\n ),\n },\n output: {\n blocks: {\n quote: {\n html: (_block, { content, children }) =>\n `<blockquote><p>${content}</p>${children}</blockquote>`,\n markdown: (_block, { content, children }) =>\n indentLines([content, children].filter(Boolean).join('\\n\\n'), '> ', '> '),\n },\n },\n },\n // a quote holds its first paragraph; what follows becomes its children\n prepareHTML: (root) => {\n for (const element of Array.from(root.querySelectorAll('blockquote'))) {\n const { content, children } = splitContainer(element)\n element.replaceWith(blockElement(element.ownerDocument, 'quote', content, children))\n }\n },\n inputRules: () => [blockInputRule(/^>\\s$/, 'quote')],\n blockOptions: [\n {\n key: 'quote',\n type: 'quote',\n label: (m) => m.types.quote,\n hint: (m) => m.hints.quote,\n icon: QuoteIcon,\n keywords: ['quote', 'blockquote', 'yy', 'yinyong'],\n shortcut: '>',\n },\n ],\n})\n\n/** A horizontal line. `---` in an empty paragraph. */\nexport const divider = defineEditorExtension({\n name: 'divider',\n blocks: {\n divider: {\n atom: true,\n selectable: true,\n parseDOM: [{ tag: 'hr' }],\n toDOM: () => [\n 'div',\n {\n class: 'dou-editor__content dou-editor__content--divider',\n 'data-content-type': 'divider',\n },\n ['hr'],\n ],\n },\n },\n output: {\n blocks: {\n divider: { html: () => '<hr>', markdown: () => '---' },\n },\n },\n inputRules: () => [atomInputRule(/^(?:---|___|\\*\\*\\*)$/, 'divider')],\n blockOptions: [\n {\n key: 'divider',\n type: 'divider',\n label: (m) => m.types.divider,\n hint: (m) => m.hints.divider,\n icon: MinusIcon,\n keywords: ['hr', 'divider', 'line', 'fgx', 'fengexian'],\n shortcut: '---',\n },\n ],\n})\n"],"mappings":";;;;;;;;;;AAiBA,IAAa,YAAY,sBAAsB;CAC7C,MAAM;CACN,cAAc,CACZ;EACE,KAAK;EACL,MAAM;EACN,QAAQ,MAAM,EAAE,MAAM;EACtB,OAAO,MAAM,EAAE,MAAM;EACrB,MAAM;EACN,UAAU;GAAC;GAAQ;GAAK;GAAM;GAAY;EAAQ;CACpD,CACF;AACF,CAAC;AAED,IAAM,SAAS;CAAC;CAAG;CAAG;AAAC;AACvB,IAAM,WAAW,UAAmB,KAAK,IAAI,GAAG,KAAK,IAAI,GAAG,OAAO,KAAK,KAAK,CAAC,CAAC;AAC/E,IAAM,eAAe;CAAE,GAAG;CAAc,GAAG;CAAc,GAAG;AAAa;;AAGzE,IAAa,UAAU,sBAAsB;CAC3C,MAAM;CACN,QAAQ,EACN,SAAS,UACP,UAAU,WAAW;EACnB,OAAO,EAAE,OAAO,EAAE,SAAS,EAAE,EAAE;EAC/B,iBAAiB,UACf,MAAM,UAAU,KAAA,IACZ,QACA;GAAE,GAAG;GAAO,OAAO,KAAK,IAAI,GAAG,KAAK,IAAI,GAAG,MAAM,KAAK,CAAC;EAAE;EAC/D,UAAU;GAAC;GAAG;GAAG;GAAG;GAAG;GAAG;EAAC,CAAC,CAAC,KAAK,WAAW;GAC3C,KAAK,IAAI;GACT,OAAO,EAAE,OAAO,KAAK,IAAI,OAAO,CAAC,EAAE;EACrC,EAAE;EACF,QAAQ,SAAS;GACf,IAAI,KAAK,MAAM;GACf;IACE,OAA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3C,WAAW,QAAQ,EAAE,SAAS,eAC5B,YAAY,CAAC,SAAS,QAAQ,CAAC,CAAC,OAAO,OAAO,CAAC,CAAC,KAAK,MAAM,GAAG,MAAM,IAAI;CAC5E,EACF,EACF;CAEA,cAAc,SAAS;EACrB,KAAK,MAAM,WAAW,MAAM,KAAK,KAAK,iBAAiB,YAAY,CAAC,GAAG;GACrE,MAAM,EAAE,SAAS,aAAa,eAAe,OAAO;GACpD,QAAQ,YAAY,aAAa,QAAQ,eAAe,SAAS,SAAS,QAAQ,CAAC;EACrF;CACF;CACA,kBAAkB,CAAC,eAAe,SAAS,OAAO,CAAC;CACnD,cAAc,CACZ;EACE,KAAK;EACL,MAAM;EACN,QAAQ,MAAM,EAAE,MAAM;EACtB,OAAO,MAAM,EAAE,MAAM;EACrB,MAAM;EACN,UAAU;GAAC;GAAS;GAAc;GAAM;EAAS;EACjD,UAAU;CACZ,CACF;AACF,CAAC;;AAGD,IAAa,UAAU,sBAAsB;CAC3C,MAAM;CACN,QAAQ,EACN,SAAS;EACP,MAAM;EACN,YAAY;EACZ,UAAU,CAAC,EAAE,KAAK,KAAK,CAAC;EACxB,aAAa;GACX;GACA;IACE,OAAO;IACP,qBAAqB;GACvB;GACA,CAAC,IAAI;EACP;CACF,EACF;CACA,QAAQ,EACN,QAAQ,EACN,SAAS;EAAE,YAAY;EAAQ,gBAAgB;CAAM,EACvD,EACF;CACA,kBAAkB,CAAC,cAAc,wBAAwB,SAAS,CAAC;CACnE,cAAc,CACZ;EACE,KAAK;EACL,MAAM;EACN,QAAQ,MAAM,EAAE,MAAM;EACtB,OAAO,MAAM,EAAE,MAAM;EACrB,MAAM;EACN,UAAU;GAAC;GAAM;GAAW;GAAQ;GAAO;EAAW;EACtD,UAAU;CACZ,CACF;AACF,CAAC"}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import callout_block_vue_vue_type_script_setup_true_lang_default from "./callout-block.vue_vue_type_script_setup_true_lang.js";
|
|
2
|
+
// src/extensions/callout/callout-block.vue
|
|
3
|
+
var callout_block_default = callout_block_vue_vue_type_script_setup_true_lang_default;
|
|
4
|
+
export { callout_block_default as default };
|
|
5
|
+
|
|
6
|
+
//# sourceMappingURL=callout-block.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"callout-block.js","names":["_sfc_main"],"sources":["../../../src/extensions/callout/callout-block.vue"],"sourcesContent":["<script setup lang=\"ts\">\nimport { DouDropdown, DouDropdownItem, DouDropdownRadioGroup } from 'dou-ui'\nimport { computed } from 'vue'\nimport type { BlockProps } from '../../core/model'\nimport { EditorContent } from '../../define-block'\nimport { useEditor } from '../../editor'\nimport { calloutTones, type CalloutTone } from './tones'\n\nconst props = defineProps<{\n block: { id: string; type: string; props: BlockProps }\n updateProps: (props: BlockProps) => void\n selected: boolean\n editable: boolean\n}>()\n\nconst { messages, view } = useEditor()\n\nconst tone = computed<CalloutTone>(() => {\n const value = props.block.props.tone as CalloutTone\n return value in calloutTones ? value : 'info'\n})\nconst icon = computed(() => calloutTones[tone.value])\n\nfunction choose(value: unknown) {\n props.updateProps({ tone: String(value) })\n view.value?.focus()\n}\n</script>\n\n<template>\n <div class=\"dou-editor-callout\" :class=\"`is-${tone}`\">\n <span class=\"dou-editor-callout__control\" contenteditable=\"false\">\n <DouDropdown v-if=\"editable\" placement=\"bottom-start\">\n <button\n type=\"button\"\n class=\"dou-editor-callout__icon\"\n :aria-label=\"`${messages.callout.tones[tone]},${messages.callout.change}`\"\n >\n <component :is=\"icon\" />\n </button>\n <template #menu>\n <DouDropdownRadioGroup :model-value=\"tone\" @update:model-value=\"choose\">\n <DouDropdownItem v-for=\"(item, name) in calloutTones\" :key=\"name\" :value=\"name\">\n <template #prefix><component :is=\"item\" /></template>\n {{ messages.callout.tones[name] }}\n </DouDropdownItem>\n </DouDropdownRadioGroup>\n </template>\n </DouDropdown>\n <span\n v-else\n class=\"dou-editor-callout__icon\"\n role=\"img\"\n :aria-label=\"messages.callout.tones[tone]\"\n >\n <component :is=\"icon\" />\n </span>\n </span>\n <EditorContent />\n </div>\n</template>\n"],"mappings":""}
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import { useEditor } from "../../editor.js";
|
|
2
|
+
import { EditorContent } from "../../define-block.js";
|
|
3
|
+
import { calloutTones } from "./tones.js";
|
|
4
|
+
import { DouDropdown, DouDropdownItem, DouDropdownRadioGroup } from "dou-ui";
|
|
5
|
+
import { Fragment, computed, createBlock, createElementBlock, createElementVNode, createTextVNode, createVNode, defineComponent, normalizeClass, openBlock, renderList, resolveDynamicComponent, toDisplayString, unref, withCtx } from "vue";
|
|
6
|
+
// src/extensions/callout/callout-block.vue?vue&type=script&setup=true&lang.ts
|
|
7
|
+
var _hoisted_1 = {
|
|
8
|
+
class: "dou-editor-callout__control",
|
|
9
|
+
contenteditable: "false"
|
|
10
|
+
};
|
|
11
|
+
var _hoisted_2 = ["aria-label"];
|
|
12
|
+
var _hoisted_3 = ["aria-label"];
|
|
13
|
+
var callout_block_vue_vue_type_script_setup_true_lang_default = /*@__PURE__*/ defineComponent({
|
|
14
|
+
__name: "callout-block",
|
|
15
|
+
props: {
|
|
16
|
+
block: {},
|
|
17
|
+
updateProps: { type: Function },
|
|
18
|
+
selected: { type: Boolean },
|
|
19
|
+
editable: { type: Boolean }
|
|
20
|
+
},
|
|
21
|
+
setup(__props) {
|
|
22
|
+
const props = __props;
|
|
23
|
+
const { messages, view } = useEditor();
|
|
24
|
+
const tone = computed(() => {
|
|
25
|
+
const value = props.block.props.tone;
|
|
26
|
+
return value in calloutTones ? value : "info";
|
|
27
|
+
});
|
|
28
|
+
const icon = computed(() => calloutTones[tone.value]);
|
|
29
|
+
function choose(value) {
|
|
30
|
+
props.updateProps({ tone: String(value) });
|
|
31
|
+
view.value?.focus();
|
|
32
|
+
}
|
|
33
|
+
return (_ctx, _cache) => {
|
|
34
|
+
return openBlock(), createElementBlock("div", { class: normalizeClass(["dou-editor-callout", `is-${tone.value}`]) }, [createElementVNode("span", _hoisted_1, [__props.editable ? (openBlock(), createBlock(unref(DouDropdown), {
|
|
35
|
+
key: 0,
|
|
36
|
+
placement: "bottom-start"
|
|
37
|
+
}, {
|
|
38
|
+
menu: withCtx(() => [createVNode(unref(DouDropdownRadioGroup), {
|
|
39
|
+
"model-value": tone.value,
|
|
40
|
+
"onUpdate:modelValue": choose
|
|
41
|
+
}, {
|
|
42
|
+
default: withCtx(() => [(openBlock(true), createElementBlock(Fragment, null, renderList(unref(calloutTones), (item, name) => {
|
|
43
|
+
return openBlock(), createBlock(unref(DouDropdownItem), {
|
|
44
|
+
key: name,
|
|
45
|
+
value: name
|
|
46
|
+
}, {
|
|
47
|
+
prefix: withCtx(() => [(openBlock(), createBlock(resolveDynamicComponent(item)))]),
|
|
48
|
+
default: withCtx(() => [createTextVNode(" " + toDisplayString(unref(messages).callout.tones[name]), 1)]),
|
|
49
|
+
_: 2
|
|
50
|
+
}, 1032, ["value"]);
|
|
51
|
+
}), 128))]),
|
|
52
|
+
_: 1
|
|
53
|
+
}, 8, ["model-value"])]),
|
|
54
|
+
default: withCtx(() => [createElementVNode("button", {
|
|
55
|
+
type: "button",
|
|
56
|
+
class: "dou-editor-callout__icon",
|
|
57
|
+
"aria-label": `${unref(messages).callout.tones[tone.value]},${unref(messages).callout.change}`
|
|
58
|
+
}, [(openBlock(), createBlock(resolveDynamicComponent(icon.value)))], 8, _hoisted_2)]),
|
|
59
|
+
_: 1
|
|
60
|
+
})) : (openBlock(), createElementBlock("span", {
|
|
61
|
+
key: 1,
|
|
62
|
+
class: "dou-editor-callout__icon",
|
|
63
|
+
role: "img",
|
|
64
|
+
"aria-label": unref(messages).callout.tones[tone.value]
|
|
65
|
+
}, [(openBlock(), createBlock(resolveDynamicComponent(icon.value)))], 8, _hoisted_3))]), createVNode(unref(EditorContent))], 2);
|
|
66
|
+
};
|
|
67
|
+
}
|
|
68
|
+
});
|
|
69
|
+
export { callout_block_vue_vue_type_script_setup_true_lang_default as default };
|
|
70
|
+
|
|
71
|
+
//# sourceMappingURL=callout-block.vue_vue_type_script_setup_true_lang.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"callout-block.vue_vue_type_script_setup_true_lang.js","names":["_openBlock","_createElementBlock","_normalizeClass","_createElementVNode","_createBlock","_unref","_withCtx","_createVNode","_Fragment","_renderList","_resolveDynamicComponent","_createTextVNode","_toDisplayString"],"sources":["../../../src/extensions/callout/callout-block.vue"],"sourcesContent":["<script setup lang=\"ts\">\nimport { DouDropdown, DouDropdownItem, DouDropdownRadioGroup } from 'dou-ui'\nimport { computed } from 'vue'\nimport type { BlockProps } from '../../core/model'\nimport { EditorContent } from '../../define-block'\nimport { useEditor } from '../../editor'\nimport { calloutTones, type CalloutTone } from './tones'\n\nconst props = defineProps<{\n block: { id: string; type: string; props: BlockProps }\n updateProps: (props: BlockProps) => void\n selected: boolean\n editable: boolean\n}>()\n\nconst { messages, view } = useEditor()\n\nconst tone = computed<CalloutTone>(() => {\n const value = props.block.props.tone as CalloutTone\n return value in calloutTones ? value : 'info'\n})\nconst icon = computed(() => calloutTones[tone.value])\n\nfunction choose(value: unknown) {\n props.updateProps({ tone: String(value) })\n view.value?.focus()\n}\n</script>\n\n<template>\n <div class=\"dou-editor-callout\" :class=\"`is-${tone}`\">\n <span class=\"dou-editor-callout__control\" contenteditable=\"false\">\n <DouDropdown v-if=\"editable\" placement=\"bottom-start\">\n <button\n type=\"button\"\n class=\"dou-editor-callout__icon\"\n :aria-label=\"`${messages.callout.tones[tone]},${messages.callout.change}`\"\n >\n <component :is=\"icon\" />\n </button>\n <template #menu>\n <DouDropdownRadioGroup :model-value=\"tone\" @update:model-value=\"choose\">\n <DouDropdownItem v-for=\"(item, name) in calloutTones\" :key=\"name\" :value=\"name\">\n <template #prefix><component :is=\"item\" /></template>\n {{ messages.callout.tones[name] }}\n </DouDropdownItem>\n </DouDropdownRadioGroup>\n </template>\n </DouDropdown>\n <span\n v-else\n class=\"dou-editor-callout__icon\"\n role=\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AAM,KAAA,OAAI,GAAKA,MAAA,QAAA,CAAQ,CAAC,QAAQ;I,KAEjEL,UAAA,GAAAI,YAAwBM,wBAAR,KAAA,KAAI,CAAA,E;;G,OAWxBV,UAAA,GAAAC,mBAOO,QAAA;;IALL,OAAM;IACN,MAAK;IACJ,cAAYI,MAAA,QAAA,CAAQ,CAAC,QAAQ,MAAM,KAAA;G,KAEpCL,UAAA,GAAAI,YAAwBM,wBAAR,KAAA,KAAI,CAAA,E,sBAGxBH,YAAiBF,MAAA,aAAA,CAAA,C"}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import { blockElement, splitContainer } from "../../core/prepare.js";
|
|
2
|
+
import { indentLines } from "../../core/output.js";
|
|
3
|
+
import { calloutTones } from "./tones.js";
|
|
4
|
+
// src/extensions/callout/html.ts
|
|
5
|
+
/** The alert labels of GitHub's Markdown, and the tone each one reads as. */
|
|
6
|
+
var ALERTS = {
|
|
7
|
+
NOTE: "info",
|
|
8
|
+
IMPORTANT: "info",
|
|
9
|
+
TIP: "tip",
|
|
10
|
+
WARNING: "warning",
|
|
11
|
+
CAUTION: "danger"
|
|
12
|
+
};
|
|
13
|
+
var LABELS = {
|
|
14
|
+
info: "NOTE",
|
|
15
|
+
tip: "TIP",
|
|
16
|
+
warning: "WARNING",
|
|
17
|
+
danger: "CAUTION"
|
|
18
|
+
};
|
|
19
|
+
var MARKER = /^\s*\[!(NOTE|IMPORTANT|TIP|WARNING|CAUTION)\][ \t]*\n?/i;
|
|
20
|
+
var toneOf = (tone) => String(tone) in calloutTones ? String(tone) : "info";
|
|
21
|
+
var calloutOutput = {
|
|
22
|
+
html: (block, { content, children }) => `<aside data-callout="${toneOf(block.props.tone)}"><p>${content}</p>${children}</aside>`,
|
|
23
|
+
markdown: (block, { content, children }) => {
|
|
24
|
+
const head = [`[!${LABELS[toneOf(block.props.tone)]}]`, content].filter(Boolean).join("\n");
|
|
25
|
+
return indentLines(children ? `${head}\n\n${children}` : head, "> ", "> ");
|
|
26
|
+
}
|
|
27
|
+
};
|
|
28
|
+
/** Take the `[!TIP]` off the start of a quote's text; returns the tone, or null without one. */
|
|
29
|
+
function takeMarker(content) {
|
|
30
|
+
const first = content.find((node) => node.textContent?.trim());
|
|
31
|
+
if (!(first instanceof Text)) return null;
|
|
32
|
+
const match = MARKER.exec(first.data);
|
|
33
|
+
if (!match) return null;
|
|
34
|
+
first.data = first.data.slice(match[0].length);
|
|
35
|
+
const next = content[content.indexOf(first) + 1];
|
|
36
|
+
if (!first.data.trim() && next instanceof Element && next.tagName === "BR") next.remove();
|
|
37
|
+
return ALERTS[match[1].toUpperCase()];
|
|
38
|
+
}
|
|
39
|
+
/** `<aside data-callout>` from `blocksToHTML`, and quotes that start with `[!TIP]` as Markdown writes them. */
|
|
40
|
+
function prepareCallouts(root) {
|
|
41
|
+
for (const element of Array.from(root.querySelectorAll("aside[data-callout]"))) {
|
|
42
|
+
const { content, children } = splitContainer(element);
|
|
43
|
+
const tone = toneOf(element.dataset.callout);
|
|
44
|
+
element.replaceWith(blockElement(element.ownerDocument, "callout", content, children, { tone }));
|
|
45
|
+
}
|
|
46
|
+
for (const element of Array.from(root.querySelectorAll("blockquote"))) {
|
|
47
|
+
const { content, children } = splitContainer(element);
|
|
48
|
+
const tone = takeMarker(content);
|
|
49
|
+
if (tone) element.replaceWith(blockElement(element.ownerDocument, "callout", content, children, { tone }));
|
|
50
|
+
}
|
|
51
|
+
for (const element of Array.from(root.querySelectorAll("div[data-content-type=\"quote\"]"))) {
|
|
52
|
+
const tone = takeMarker(Array.from(element.childNodes));
|
|
53
|
+
if (tone) {
|
|
54
|
+
element.dataset.contentType = "callout";
|
|
55
|
+
element.dataset.tone = tone;
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
export { calloutOutput, prepareCallouts };
|
|
60
|
+
|
|
61
|
+
//# sourceMappingURL=html.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"html.js","names":[],"sources":["../../../src/extensions/callout/html.ts"],"sourcesContent":["import { indentLines, type BlockOutput } from '../../core/output'\nimport { blockElement, splitContainer } from '../../core/prepare'\nimport { calloutTones } from './tones'\n\n/** The alert labels of GitHub's Markdown, and the tone each one reads as. */\nconst ALERTS: Record<string, string> = {\n NOTE: 'info',\n IMPORTANT: 'info',\n TIP: 'tip',\n WARNING: 'warning',\n CAUTION: 'danger',\n}\nconst LABELS: Record<string, string> = {\n info: 'NOTE',\n tip: 'TIP',\n warning: 'WARNING',\n danger: 'CAUTION',\n}\nconst MARKER = /^\\s*\\[!(NOTE|IMPORTANT|TIP|WARNING|CAUTION)\\][ \\t]*\\n?/i\n\nconst toneOf = (tone: unknown) => (String(tone) in calloutTones ? String(tone) : 'info')\n\nexport const calloutOutput: BlockOutput = {\n html: (block, { content, children }) =>\n `<aside data-callout=\"${toneOf(block.props.tone)}\"><p>${content}</p>${children}</aside>`,\n // GitHub's alert syntax: a quote that starts with `[!TIP]`\n markdown: (block, { content, children }) => {\n const head = [`[!${LABELS[toneOf(block.props.tone)]}]`, content].filter(Boolean).join('\\n')\n return indentLines(children ? `${head}\\n\\n${children}` : head, '> ', '> ')\n },\n}\n\n/** Take the `[!TIP]` off the start of a quote's text; returns the tone, or null without one. */\nfunction takeMarker(content: Node[]): string | null {\n const first = content.find((node) => node.textContent?.trim())\n if (!(first instanceof Text)) return null\n const match = MARKER.exec(first.data)\n if (!match) return null\n first.data = first.data.slice(match[0].length)\n // the text after the marker starts on the next line\n const index = content.indexOf(first)\n const next = content[index + 1]\n if (!first.data.trim() && next instanceof Element && next.tagName === 'BR') next.remove()\n return ALERTS[match[1]!.toUpperCase()]!\n}\n\n/** `<aside data-callout>` from `blocksToHTML`, and quotes that start with `[!TIP]` as Markdown writes them. */\nexport function prepareCallouts(root: HTMLElement) {\n for (const element of Array.from(root.querySelectorAll('aside[data-callout]'))) {\n const { content, children } = splitContainer(element)\n const tone = toneOf((element as HTMLElement).dataset.callout)\n element.replaceWith(blockElement(element.ownerDocument, 'callout', content, children, { tone }))\n }\n for (const element of Array.from(root.querySelectorAll('blockquote'))) {\n const { content, children } = splitContainer(element)\n const tone = takeMarker(content)\n if (tone)\n element.replaceWith(\n blockElement(element.ownerDocument, 'callout', content, children, { tone }),\n )\n }\n // a quote another extension already turned into a block\n for (const element of Array.from(\n root.querySelectorAll<HTMLElement>('div[data-content-type=\"quote\"]'),\n )) {\n const tone = takeMarker(Array.from(element.childNodes))\n if (tone) {\n element.dataset.contentType = 'callout'\n element.dataset.tone = tone\n }\n }\n}\n"],"mappings":";;;;;AAKA,IAAM,SAAiC;CACrC,MAAM;CACN,WAAW;CACX,KAAK;CACL,SAAS;CACT,SAAS;AACX;AACA,IAAM,SAAiC;CACrC,MAAM;CACN,KAAK;CACL,SAAS;CACT,QAAQ;AACV;AACA,IAAM,SAAS;AAEf,IAAM,UAAU,SAAmB,OAAO,IAAI,KAAK,eAAe,OAAO,IAAI,IAAI;AAEjF,IAAa,gBAA6B;CACxC,OAAO,OAAO,EAAE,SAAS,eACvB,wBAAwB,OAAO,MAAM,MAAM,IAAI,EAAE,OAAO,QAAQ,MAAM,SAAS;CAEjF,WAAW,OAAO,EAAE,SAAS,eAAe;EAC1C,MAAM,OAAO,CAAC,KAAK,OAAO,OAAO,MAAM,MAAM,IAAI,GAAG,IAAI,OAAO,CAAC,CAAC,OAAO,OAAO,CAAC,CAAC,KAAK,IAAI;EAC1F,OAAO,YAAY,WAAW,GAAG,KAAK,MAAM,aAAa,MAAM,MAAM,IAAI;CAC3E;AACF;;AAGA,SAAS,WAAW,SAAgC;CAClD,MAAM,QAAQ,QAAQ,MAAM,SAAS,KAAK,aAAa,KAAK,CAAC;CAC7D,IAAI,EAAE,iBAAiB,OAAO,OAAO;CACrC,MAAM,QAAQ,OAAO,KAAK,MAAM,IAAI;CACpC,IAAI,CAAC,OAAO,OAAO;CACnB,MAAM,OAAO,MAAM,KAAK,MAAM,MAAM,EAAE,CAAC,MAAM;CAG7C,MAAM,OAAO,QADC,QAAQ,QAAQ,KACT,IAAQ;CAC7B,IAAI,CAAC,MAAM,KAAK,KAAK,KAAK,gBAAgB,WAAW,KAAK,YAAY,MAAM,KAAK,OAAO;CACxF,OAAO,OAAO,MAAM,EAAE,CAAE,YAAY;AACtC;;AAGA,SAAgB,gBAAgB,MAAmB;CACjD,KAAK,MAAM,WAAW,MAAM,KAAK,KAAK,iBAAiB,qBAAqB,CAAC,GAAG;EAC9E,MAAM,EAAE,SAAS,aAAa,eAAe,OAAO;EACpD,MAAM,OAAO,OAAQ,QAAwB,QAAQ,OAAO;EAC5D,QAAQ,YAAY,aAAa,QAAQ,eAAe,WAAW,SAAS,UAAU,EAAE,KAAK,CAAC,CAAC;CACjG;CACA,KAAK,MAAM,WAAW,MAAM,KAAK,KAAK,iBAAiB,YAAY,CAAC,GAAG;EACrE,MAAM,EAAE,SAAS,aAAa,eAAe,OAAO;EACpD,MAAM,OAAO,WAAW,OAAO;EAC/B,IAAI,MACF,QAAQ,YACN,aAAa,QAAQ,eAAe,WAAW,SAAS,UAAU,EAAE,KAAK,CAAC,CAC5E;CACJ;CAEA,KAAK,MAAM,WAAW,MAAM,KAC1B,KAAK,iBAA8B,kCAAgC,CACrE,GAAG;EACD,MAAM,OAAO,WAAW,MAAM,KAAK,QAAQ,UAAU,CAAC;EACtD,IAAI,MAAM;GACR,QAAQ,QAAQ,cAAc;GAC9B,QAAQ,QAAQ,OAAO;EACzB;CACF;AACF"}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { defineEditorExtension } from "../../core/extension.js";
|
|
2
|
+
import { calloutTones } from "./tones.js";
|
|
3
|
+
import callout_block_default from "./callout-block.js";
|
|
4
|
+
import { calloutOutput, prepareCallouts } from "./html.js";
|
|
5
|
+
import { StickyNoteIcon } from "@dou-ui/icons";
|
|
6
|
+
// src/extensions/callout/index.ts
|
|
7
|
+
/** A callout: text in a tinted box with an icon; the icon picks the tone. */
|
|
8
|
+
var callout = defineEditorExtension({
|
|
9
|
+
name: "callout",
|
|
10
|
+
blocks: { callout: {
|
|
11
|
+
content: "inline*",
|
|
12
|
+
defining: true,
|
|
13
|
+
component: callout_block_default,
|
|
14
|
+
attrs: { tone: { default: "info" } },
|
|
15
|
+
parseDOM: [{
|
|
16
|
+
tag: "div[data-content-type=\"callout\"]",
|
|
17
|
+
getAttrs: (dom) => {
|
|
18
|
+
const tone = dom.dataset.tone ?? "";
|
|
19
|
+
return { tone: tone in calloutTones ? tone : "info" };
|
|
20
|
+
}
|
|
21
|
+
}],
|
|
22
|
+
toDOM: (node) => [
|
|
23
|
+
"div",
|
|
24
|
+
{
|
|
25
|
+
class: "dou-editor__content dou-editor__content--callout",
|
|
26
|
+
"data-content-type": "callout",
|
|
27
|
+
"data-tone": node.attrs.tone
|
|
28
|
+
},
|
|
29
|
+
0
|
|
30
|
+
]
|
|
31
|
+
} },
|
|
32
|
+
output: { blocks: { callout: calloutOutput } },
|
|
33
|
+
prepareHTML: prepareCallouts,
|
|
34
|
+
blockOptions: [{
|
|
35
|
+
key: "callout",
|
|
36
|
+
type: "callout",
|
|
37
|
+
label: (m) => m.types.callout,
|
|
38
|
+
hint: (m) => m.hints.callout,
|
|
39
|
+
icon: StickyNoteIcon,
|
|
40
|
+
keywords: [
|
|
41
|
+
"callout",
|
|
42
|
+
"note",
|
|
43
|
+
"tip",
|
|
44
|
+
"warning",
|
|
45
|
+
"ts",
|
|
46
|
+
"tishi"
|
|
47
|
+
]
|
|
48
|
+
}]
|
|
49
|
+
});
|
|
50
|
+
export { callout };
|
|
51
|
+
|
|
52
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","names":["CalloutBlock"],"sources":["../../../src/extensions/callout/index.ts"],"sourcesContent":["import { StickyNoteIcon } from '@dou-ui/icons'\nimport { defineEditorExtension } from '../../core/extension'\nimport CalloutBlock from './callout-block.vue'\nimport { calloutOutput, prepareCallouts } from './html'\nimport { calloutTones } from './tones'\n\n/** A callout: text in a tinted box with an icon; the icon picks the tone. */\nexport const callout = defineEditorExtension({\n name: 'callout',\n blocks: {\n callout: {\n content: 'inline*',\n defining: true,\n component: CalloutBlock,\n attrs: { tone: { default: 'info' } },\n parseDOM: [\n {\n tag: 'div[data-content-type=\"callout\"]',\n getAttrs: (dom) => {\n const tone = (dom as HTMLElement).dataset.tone ?? ''\n return { tone: tone in calloutTones ? tone : 'info' }\n },\n },\n ],\n toDOM: (node) => [\n 'div',\n {\n class: 'dou-editor__content dou-editor__content--callout',\n 'data-content-type': 'callout',\n 'data-tone': node.attrs.tone,\n },\n 0,\n ],\n },\n },\n output: { blocks: { callout: calloutOutput } },\n prepareHTML: prepareCallouts,\n blockOptions: [\n {\n key: 'callout',\n type: 'callout',\n label: (m) => m.types.callout,\n hint: (m) => m.hints.callout,\n icon: StickyNoteIcon,\n keywords: ['callout', 'note', 'tip', 'warning', 'ts', 'tishi'],\n },\n ],\n})\n\nexport type { CalloutTone } from './tones'\n"],"mappings":";;;;;;;AAOA,IAAa,UAAU,sBAAsB;CAC3C,MAAM;CACN,QAAQ,EACN,SAAS;EACP,SAAS;EACT,UAAU;EACV,WAAWA;EACX,OAAO,EAAE,MAAM,EAAE,SAAS,OAAO,EAAE;EACnC,UAAU,CACR;GACE,KAAK;GACL,WAAW,QAAQ;IACjB,MAAM,OAAQ,IAAoB,QAAQ,QAAQ;IAClD,OAAO,EAAE,MAAM,QAAQ,eAAe,OAAO,OAAO;GACtD;EACF,CACF;EACA,QAAQ,SAAS;GACf;GACA;IACE,OAAO;IACP,qBAAqB;IACrB,aAAa,KAAK,MAAM;GAC1B;GACA;EACF;CACF,EACF;CACA,QAAQ,EAAE,QAAQ,EAAE,SAAS,cAAc,EAAE;CAC7C,aAAa;CACb,cAAc,CACZ;EACE,KAAK;EACL,MAAM;EACN,QAAQ,MAAM,EAAE,MAAM;EACtB,OAAO,MAAM,EAAE,MAAM;EACrB,MAAM;EACN,UAAU;GAAC;GAAW;GAAQ;GAAO;GAAW;GAAM;EAAO;CAC/D,CACF;AACF,CAAC"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { AlertOctagonIcon, AlertTriangleIcon, InfoIcon, LightbulbIcon } from "@dou-ui/icons";
|
|
2
|
+
// src/extensions/callout/tones.ts
|
|
3
|
+
/** The callout's tones and their icons. */
|
|
4
|
+
var calloutTones = {
|
|
5
|
+
info: InfoIcon,
|
|
6
|
+
tip: LightbulbIcon,
|
|
7
|
+
warning: AlertTriangleIcon,
|
|
8
|
+
danger: AlertOctagonIcon
|
|
9
|
+
};
|
|
10
|
+
export { calloutTones };
|
|
11
|
+
|
|
12
|
+
//# sourceMappingURL=tones.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tones.js","names":[],"sources":["../../../src/extensions/callout/tones.ts"],"sourcesContent":["import { AlertOctagonIcon, AlertTriangleIcon, InfoIcon, LightbulbIcon } from '@dou-ui/icons'\n\n/** The callout's tones and their icons. */\nexport const calloutTones = {\n info: InfoIcon,\n tip: LightbulbIcon,\n warning: AlertTriangleIcon,\n danger: AlertOctagonIcon,\n}\n\nexport type CalloutTone = keyof typeof calloutTones\n"],"mappings":";;;AAGA,IAAa,eAAe;CAC1B,MAAM;CACN,KAAK;CACL,SAAS;CACT,QAAQ;AACV"}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import code_block_view_vue_vue_type_script_setup_true_lang_default from "./code-block-view.vue_vue_type_script_setup_true_lang.js";
|
|
2
|
+
// src/extensions/code-block/code-block-view.vue
|
|
3
|
+
var code_block_view_default = code_block_view_vue_vue_type_script_setup_true_lang_default;
|
|
4
|
+
export { code_block_view_default as default };
|
|
5
|
+
|
|
6
|
+
//# sourceMappingURL=code-block-view.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"code-block-view.js","names":["_sfc_main"],"sources":["../../../src/extensions/code-block/code-block-view.vue"],"sourcesContent":["<script setup lang=\"ts\">\nimport { ChevronDownIcon } from '@dou-ui/icons'\nimport { DouCopyButton, DouDropdown, DouDropdownItem, DouDropdownRadioGroup } from 'dou-ui'\nimport { computed } from 'vue'\nimport { findBlockById } from '../../core/blocks'\nimport type { BlockProps } from '../../core/model'\nimport { EditorContent } from '../../define-block'\nimport { useEditor } from '../../editor'\nimport type { CodeLanguage } from './languages'\n\nconst props = defineProps<{\n block: { id: string; type: string; props: BlockProps }\n updateProps: (props: BlockProps) => void\n selected: boolean\n editable: boolean\n languages: CodeLanguage[]\n}>()\n\nconst { messages, view } = useEditor()\n\nconst language = computed(() => String(props.block.props.language ?? ''))\n// a language from elsewhere (pasted, or set in code) still shows by its name\nconst choices = computed(() => {\n const list = [{ value: '', label: messages.value.codeBlock.plainText }, ...props.languages]\n if (language.value && !list.some((item) => item.value === language.value))\n list.push({ value: language.value, label: language.value })\n return list\n})\nconst label = computed(\n () => choices.value.find((item) => item.value === language.value)?.label ?? language.value,\n)\n\nfunction choose(value: unknown) {\n props.updateProps({ language: String(value ?? '') })\n view.value?.focus()\n}\n\n// read when the button is pressed: the text changes while the block is edited\nfunction code() {\n const current = view.value\n if (!current) return ''\n return findBlockById(current.state.doc, props.block.id)?.content.textContent ?? ''\n}\n</script>\n\n<template>\n <div class=\"dou-editor-code__bar\" contenteditable=\"false\">\n <DouDropdown v-if=\"editable\" placement=\"bottom-end\">\n <button type=\"button\" class=\"dou-editor-code__language\" :title=\"messages.codeBlock.language\">\n {{ label }}\n <ChevronDownIcon />\n </button>\n <template #menu>\n <DouDropdownRadioGroup :model-value=\"language\" @update:model-value=\"choose\">\n <DouDropdownItem v-for=\"item in choices\" :key=\"item.value\" :value=\"item.value\">\n {{ item.label }}\n </DouDropdownItem>\n </DouDropdownRadioGroup>\n </template>\n </DouDropdown>\n <span v-else-if=\"language\" class=\"dou-editor-code__language is-static\">{{ label }}</span>\n <DouCopyButton :text=\"code\" size=\"sm\" />\n </div>\n <pre class=\"dou-editor-code__pre\"><EditorContent as=\"code\" /></pre>\n</template>\n"],"mappings":""}
|