@dou-ui/editor 0.1.0-alpha.3 → 0.1.0-alpha.30
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/collaboration/binding.js +371 -57
- package/dist/collaboration/binding.js.map +1 -1
- package/dist/collaboration/cursors.js +42 -10
- package/dist/collaboration/cursors.js.map +1 -1
- package/dist/collaboration/index.js +61 -11
- package/dist/collaboration/index.js.map +1 -1
- package/dist/collaboration/inline-diff.js +138 -0
- package/dist/collaboration/inline-diff.js.map +1 -0
- package/dist/collaboration/merged-props.js +152 -0
- package/dist/collaboration/merged-props.js.map +1 -0
- package/dist/collaboration/order.js +41 -1
- package/dist/collaboration/order.js.map +1 -1
- package/dist/collaboration/table.js +64 -25
- package/dist/collaboration/table.js.map +1 -1
- package/dist/collaboration/text.js +213 -1
- package/dist/collaboration/text.js.map +1 -1
- package/dist/components/block-handle.js.map +1 -1
- package/dist/components/block-handle.vue_vue_type_script_setup_true_lang.js +127 -17
- package/dist/components/block-handle.vue_vue_type_script_setup_true_lang.js.map +1 -1
- package/dist/components/slash-choices.js +6 -0
- package/dist/components/slash-choices.js.map +1 -0
- package/dist/components/slash-choices.vue_vue_type_script_setup_true_lang.js +56 -0
- package/dist/components/slash-choices.vue_vue_type_script_setup_true_lang.js.map +1 -0
- package/dist/components/slash-menu.js.map +1 -1
- package/dist/components/slash-menu.vue_vue_type_script_setup_true_lang.js +185 -20
- package/dist/components/slash-menu.vue_vue_type_script_setup_true_lang.js.map +1 -1
- package/dist/core/block-selection.js +32 -4
- package/dist/core/block-selection.js.map +1 -1
- package/dist/core/blocks.js +21 -3
- package/dist/core/blocks.js.map +1 -1
- package/dist/core/cjk.js +54 -0
- package/dist/core/cjk.js.map +1 -0
- package/dist/core/commands.js +125 -13
- package/dist/core/commands.js.map +1 -1
- package/dist/core/comments.js +85 -3
- package/dist/core/comments.js.map +1 -1
- package/dist/core/convert.js +3 -3
- package/dist/core/convert.js.map +1 -1
- package/dist/core/extension.js +6 -2
- package/dist/core/extension.js.map +1 -1
- package/dist/core/model.js +10 -3
- package/dist/core/model.js.map +1 -1
- package/dist/core/output.js +26 -10
- package/dist/core/output.js.map +1 -1
- package/dist/core/prepare.js +12 -5
- package/dist/core/prepare.js.map +1 -1
- package/dist/core/schema.js.map +1 -1
- package/dist/core/transaction.js +19 -4
- package/dist/core/transaction.js.map +1 -1
- package/dist/define-block.js +8 -4
- package/dist/define-block.js.map +1 -1
- package/dist/document.js +59 -4
- package/dist/document.js.map +1 -1
- package/dist/dom.js +109 -13
- package/dist/dom.js.map +1 -1
- package/dist/editor.js.map +1 -1
- package/dist/editor.vue_vue_type_script_setup_true_lang.js +6 -5
- package/dist/editor.vue_vue_type_script_setup_true_lang.js.map +1 -1
- package/dist/editor2.js.map +1 -1
- package/dist/extensions/callout/html.js +5 -4
- package/dist/extensions/callout/html.js.map +1 -1
- package/dist/extensions/columns/column-picker.js +6 -0
- package/dist/extensions/columns/column-picker.js.map +1 -0
- package/dist/extensions/columns/column-picker.vue_vue_type_script_setup_true_lang.js +57 -0
- package/dist/extensions/columns/column-picker.vue_vue_type_script_setup_true_lang.js.map +1 -0
- package/dist/extensions/columns/columns-controls.js +6 -0
- package/dist/extensions/columns/columns-controls.js.map +1 -0
- package/dist/extensions/columns/columns-controls.vue_vue_type_script_setup_true_lang.js +341 -0
- package/dist/extensions/columns/columns-controls.vue_vue_type_script_setup_true_lang.js.map +1 -0
- package/dist/extensions/columns/html.js +34 -0
- package/dist/extensions/columns/html.js.map +1 -0
- package/dist/extensions/columns/index.js +57 -0
- package/dist/extensions/columns/index.js.map +1 -0
- package/dist/extensions/columns/keys.js +53 -0
- package/dist/extensions/columns/keys.js.map +1 -0
- package/dist/extensions/columns/plugin.js +213 -0
- package/dist/extensions/columns/plugin.js.map +1 -0
- package/dist/extensions/columns/schema.js +58 -0
- package/dist/extensions/columns/schema.js.map +1 -0
- package/dist/extensions/columns/select-columns.js +6 -0
- package/dist/extensions/columns/select-columns.js.map +1 -0
- package/dist/extensions/columns/select-columns.vue_vue_type_script_setup_true_lang.js +71 -0
- package/dist/extensions/columns/select-columns.vue_vue_type_script_setup_true_lang.js.map +1 -0
- package/dist/extensions/editor-kit.js +3 -1
- package/dist/extensions/editor-kit.js.map +1 -1
- package/dist/extensions/list-html.js +1 -1
- package/dist/extensions/list-html.js.map +1 -1
- package/dist/extensions/table/plugin.js +33 -1
- package/dist/extensions/table/plugin.js.map +1 -1
- package/dist/extensions/table/schema.js +5 -1
- package/dist/extensions/table/schema.js.map +1 -1
- package/dist/extensions/table/table-controls.js.map +1 -1
- package/dist/extensions/table/table-controls.vue_vue_type_script_setup_true_lang.js +80 -9
- package/dist/extensions/table/table-controls.vue_vue_type_script_setup_true_lang.js.map +1 -1
- package/dist/extensions/table/view.js +181 -3
- package/dist/extensions/table/view.js.map +1 -1
- package/dist/flow/board-block.js +6 -0
- package/dist/flow/board-block.js.map +1 -0
- package/dist/flow/board-block.vue_vue_type_script_setup_true_lang.js +659 -0
- package/dist/flow/board-block.vue_vue_type_script_setup_true_lang.js.map +1 -0
- package/dist/flow/board.js +221 -0
- package/dist/flow/board.js.map +1 -0
- package/dist/flow/index.js +173 -0
- package/dist/flow/index.js.map +1 -0
- package/dist/index.js +3 -2
- package/dist/index.js.map +1 -1
- package/dist/locale.js +78 -6
- package/dist/locale.js.map +1 -1
- package/dist/markdown/cjk-friendly.js +62 -0
- package/dist/markdown/cjk-friendly.js.map +1 -0
- package/dist/markdown/index.js +4 -3
- package/dist/markdown/index.js.map +1 -1
- package/dist/style.css +1 -1
- package/dist/style.js +2 -0
- package/dist/types/collaboration/binding.d.ts +12 -0
- package/dist/types/collaboration/cursors.d.ts +29 -1
- package/dist/types/collaboration/index.d.ts +53 -6
- package/dist/types/collaboration/inline-diff.d.ts +9 -0
- package/dist/types/collaboration/merged-props.d.ts +20 -0
- package/dist/types/collaboration/order.d.ts +5 -0
- package/dist/types/collaboration/table.d.ts +5 -1
- package/dist/types/collaboration/text.d.ts +20 -0
- package/dist/types/components/slash-choices.vue.d.ts +18 -0
- package/dist/types/core/blocks.d.ts +10 -0
- package/dist/types/core/cjk.d.ts +23 -0
- package/dist/types/core/commands.d.ts +17 -2
- package/dist/types/core/comments.d.ts +39 -3
- package/dist/types/core/convert.d.ts +10 -2
- package/dist/types/core/extension.d.ts +58 -4
- package/dist/types/core/model.d.ts +6 -1
- package/dist/types/core/prepare.d.ts +16 -2
- package/dist/types/core/schema.d.ts +1 -1
- package/dist/types/core/transaction.d.ts +6 -0
- package/dist/types/define-block.d.ts +16 -4
- package/dist/types/document.d.ts +5 -2
- package/dist/types/dom.d.ts +41 -4
- package/dist/types/editor.d.ts +15 -1
- package/dist/types/editor.vue.d.ts +24 -0
- package/dist/types/extensions/columns/column-picker.vue.d.ts +10 -0
- package/dist/types/extensions/columns/columns-controls.vue.d.ts +3 -0
- package/dist/types/extensions/columns/html.d.ts +10 -0
- package/dist/types/extensions/columns/index.d.ts +9 -0
- package/dist/types/extensions/columns/keys.d.ts +6 -0
- package/dist/types/extensions/columns/plugin.d.ts +28 -0
- package/dist/types/extensions/columns/schema.d.ts +17 -0
- package/dist/types/extensions/columns/select-columns.vue.d.ts +13 -0
- package/dist/types/extensions/editor-kit.d.ts +4 -1
- package/dist/types/extensions/table/view.d.ts +36 -2
- package/dist/types/flow/board-block.vue.d.ts +16 -0
- package/dist/types/flow/board.d.ts +53 -0
- package/dist/types/flow/index.d.ts +65 -0
- package/dist/types/index.d.ts +29 -4
- package/dist/types/locale.d.ts +34 -0
- package/dist/types/markdown/cjk-friendly.d.ts +6 -0
- package/dist/types/markdown/index.d.ts +11 -4
- package/dist/types/use-comments.d.ts +1 -0
- package/dist/use-comments.js +63 -9
- package/dist/use-comments.js.map +1 -1
- package/package.json +14 -5
|
@@ -28,12 +28,13 @@ var calloutOutput = {
|
|
|
28
28
|
/** Take the `[!TIP]` off the start of a quote's text; returns the tone, or null without one. */
|
|
29
29
|
function takeMarker(content) {
|
|
30
30
|
const first = content.find((node) => node.textContent?.trim());
|
|
31
|
-
if (
|
|
32
|
-
const
|
|
31
|
+
if (first?.nodeType !== 3) return null;
|
|
32
|
+
const text = first;
|
|
33
|
+
const match = MARKER.exec(text.data);
|
|
33
34
|
if (!match) return null;
|
|
34
|
-
|
|
35
|
+
text.data = text.data.slice(match[0].length);
|
|
35
36
|
const next = content[content.indexOf(first) + 1];
|
|
36
|
-
if (!
|
|
37
|
+
if (!text.data.trim() && next?.nodeType === 1 && next.tagName === "BR") next.remove();
|
|
37
38
|
return ALERTS[match[1].toUpperCase()];
|
|
38
39
|
}
|
|
39
40
|
/** `<aside data-callout>` from `blocksToHTML`, and quotes that start with `[!TIP]` as Markdown writes them. */
|
|
@@ -1 +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 (
|
|
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 // by node type, not `instanceof`: the DOM may come from a library, without globals\n if (first?.nodeType !== 3) return null\n const text = first as Text\n const match = MARKER.exec(text.data)\n if (!match) return null\n text.data = text.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 (!text.data.trim() && next?.nodeType === 1 && (next as Element).tagName === 'BR')\n (next as Element).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,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|
2
|
+
// src/extensions/columns/column-picker.vue
|
|
3
|
+
var column_picker_default = column_picker_vue_vue_type_script_setup_true_lang_default;
|
|
4
|
+
export { column_picker_default as default };
|
|
5
|
+
|
|
6
|
+
//# sourceMappingURL=column-picker.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"column-picker.js","names":["_sfc_main"],"sources":["../../../src/extensions/columns/column-picker.vue"],"sourcesContent":["<script setup lang=\"ts\">\nimport { computed } from 'vue'\nimport {\n labelOf,\n type BlockOptionChoicesEmits,\n type BlockOptionChoicesProps,\n} from '../../core/extension'\n\n/**\n * The column count picker beside “Columns” in the slash menu: a row of\n * bars, as many as the most columns; pointing at one lights the bars up to\n * it, the count a click inserts.\n */\nconst props = defineProps<BlockOptionChoicesProps>()\nconst emit = defineEmits<BlockOptionChoicesEmits>()\n\nconst counts = computed(() => props.items.map((item) => Number(item.props.count)))\nconst bars = computed(() => Math.max(...counts.value))\n/** Bars lit up to here; none while the option itself is highlighted. */\nconst lit = computed(() => (props.active < 0 ? 0 : (counts.value[props.active] ?? 0)))\n\n/** The choice a bar stands for: its count, or the fewest there can be. */\nconst indexOf = (bar: number) => {\n const index = counts.value.indexOf(Math.max(bar, counts.value[0]!))\n return index < 0 ? 0 : index\n}\n</script>\n\n<template>\n <div class=\"dou-editor-column-picker\">\n <div\n v-for=\"bar in bars\"\n :id=\"bar >= counts[0]! ? `${idPrefix}-${indexOf(bar)}` : undefined\"\n :key=\"bar\"\n :role=\"bar >= counts[0]! ? 'option' : 'presentation'\"\n :aria-selected=\"bar >= counts[0]! ? bar === lit : undefined\"\n :aria-label=\"bar >= counts[0]! ? labelOf(items[indexOf(bar)]!.label, messages) : undefined\"\n :class=\"['dou-editor-column-picker__bar', { 'is-lit': bar <= lit }]\"\n @pointermove=\"emit('hover', indexOf(bar))\"\n @click=\"emit('choose', indexOf(bar))\"\n />\n </div>\n</template>\n"],"mappings":""}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import { labelOf } from "../../core/extension.js";
|
|
2
|
+
import { Fragment, computed, createElementBlock, defineComponent, normalizeClass, openBlock, renderList, unref } from "vue";
|
|
3
|
+
// src/extensions/columns/column-picker.vue?vue&type=script&setup=true&lang.ts
|
|
4
|
+
var _hoisted_1 = { class: "dou-editor-column-picker" };
|
|
5
|
+
var _hoisted_2 = [
|
|
6
|
+
"id",
|
|
7
|
+
"role",
|
|
8
|
+
"aria-selected",
|
|
9
|
+
"aria-label",
|
|
10
|
+
"onPointermove",
|
|
11
|
+
"onClick"
|
|
12
|
+
];
|
|
13
|
+
/**
|
|
14
|
+
* The column count picker beside “Columns” in the slash menu: a row of
|
|
15
|
+
* bars, as many as the most columns; pointing at one lights the bars up to
|
|
16
|
+
* it, the count a click inserts.
|
|
17
|
+
*/
|
|
18
|
+
var column_picker_vue_vue_type_script_setup_true_lang_default = /*@__PURE__*/ defineComponent({
|
|
19
|
+
__name: "column-picker",
|
|
20
|
+
props: {
|
|
21
|
+
items: {},
|
|
22
|
+
active: {},
|
|
23
|
+
messages: {},
|
|
24
|
+
idPrefix: {}
|
|
25
|
+
},
|
|
26
|
+
emits: ["hover", "choose"],
|
|
27
|
+
setup(__props, { emit: __emit }) {
|
|
28
|
+
const props = __props;
|
|
29
|
+
const emit = __emit;
|
|
30
|
+
const counts = computed(() => props.items.map((item) => Number(item.props.count)));
|
|
31
|
+
const bars = computed(() => Math.max(...counts.value));
|
|
32
|
+
/** Bars lit up to here; none while the option itself is highlighted. */
|
|
33
|
+
const lit = computed(() => props.active < 0 ? 0 : counts.value[props.active] ?? 0);
|
|
34
|
+
/** The choice a bar stands for: its count, or the fewest there can be. */
|
|
35
|
+
const indexOf = (bar) => {
|
|
36
|
+
const index = counts.value.indexOf(Math.max(bar, counts.value[0]));
|
|
37
|
+
return index < 0 ? 0 : index;
|
|
38
|
+
};
|
|
39
|
+
return (_ctx, _cache) => {
|
|
40
|
+
return openBlock(), createElementBlock("div", _hoisted_1, [(openBlock(true), createElementBlock(Fragment, null, renderList(bars.value, (bar) => {
|
|
41
|
+
return openBlock(), createElementBlock("div", {
|
|
42
|
+
id: bar >= counts.value[0] ? `${__props.idPrefix}-${indexOf(bar)}` : void 0,
|
|
43
|
+
key: bar,
|
|
44
|
+
role: bar >= counts.value[0] ? "option" : "presentation",
|
|
45
|
+
"aria-selected": bar >= counts.value[0] ? bar === lit.value : void 0,
|
|
46
|
+
"aria-label": bar >= counts.value[0] ? unref(labelOf)(__props.items[indexOf(bar)].label, __props.messages) : void 0,
|
|
47
|
+
class: normalizeClass(["dou-editor-column-picker__bar", { "is-lit": bar <= lit.value }]),
|
|
48
|
+
onPointermove: ($event) => emit("hover", indexOf(bar)),
|
|
49
|
+
onClick: ($event) => emit("choose", indexOf(bar))
|
|
50
|
+
}, null, 42, _hoisted_2);
|
|
51
|
+
}), 128))]);
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
});
|
|
55
|
+
export { column_picker_vue_vue_type_script_setup_true_lang_default as default };
|
|
56
|
+
|
|
57
|
+
//# sourceMappingURL=column-picker.vue_vue_type_script_setup_true_lang.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"column-picker.vue_vue_type_script_setup_true_lang.js","names":["_openBlock","_createElementBlock","_Fragment","_renderList","_unref","_normalizeClass"],"sources":["../../../src/extensions/columns/column-picker.vue"],"sourcesContent":["<script setup lang=\"ts\">\nimport { computed } from 'vue'\nimport {\n labelOf,\n type BlockOptionChoicesEmits,\n type BlockOptionChoicesProps,\n} from '../../core/extension'\n\n/**\n * The column count picker beside “Columns” in the slash menu: a row of\n * bars, as many as the most columns; pointing at one lights the bars up to\n * it, the count a click inserts.\n */\nconst props = defineProps<BlockOptionChoicesProps>()\nconst emit = defineEmits<BlockOptionChoicesEmits>()\n\nconst counts = computed(() => props.items.map((item) => Number(item.props.count)))\nconst bars = computed(() => Math.max(...counts.value))\n/** Bars lit up to here; none while the option itself is highlighted. */\nconst lit = computed(() => (props.active < 0 ? 0 : (counts.value[props.active] ?? 0)))\n\n/** The choice a bar stands for: its count, or the fewest there can be. */\nconst indexOf = (bar: number) => {\n const index = counts.value.indexOf(Math.max(bar, counts.value[0]!))\n return index < 0 ? 0 : index\n}\n</script>\n\n<template>\n <div class=\"dou-editor-column-picker\">\n <div\n v-for=\"bar in bars\"\n :id=\"bar >= counts[0]! ? `${idPrefix}-${indexOf(bar)}` : undefined\"\n :key=\"bar\"\n :role=\"bar >= counts[0]! ? 'option' : 'presentation'\"\n :aria-selected=\"bar >= counts[0]! ? bar === lit : undefined\"\n :aria-label=\"bar >= counts[0]! ? labelOf(items[indexOf(bar)]!.label, messages) : undefined\"\n :class=\"['dou-editor-column-picker__bar', { 'is-lit': bar <= lit }]\"\n @pointermove=\"emit('hover', indexOf(bar))\"\n @click=\"emit('choose', indexOf(bar))\"\n />\n </div>\n</template>\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;EAaA,MAAM,QAAQ;EACd,MAAM,OAAO;EAEb,MAAM,SAAS,eAAe,MAAM,MAAM,KAAK,SAAS,OAAO,KAAK,MAAM,KAAK,CAAC,CAAC;EACjF,MAAM,OAAO,eAAe,KAAK,IAAI,GAAG,OAAO,KAAK,CAAC;;EAErD,MAAM,MAAM,eAAgB,MAAM,SAAS,IAAI,IAAK,OAAO,MAAM,MAAM,WAAW,CAAG;;EAGrF,MAAM,WAAW,QAAgB;GAC/B,MAAM,QAAQ,OAAO,MAAM,QAAQ,KAAK,IAAI,KAAK,OAAO,MAAM,EAAG,CAAC;GAClE,OAAO,QAAQ,IAAI,IAAI;EACzB;;GAIE,OAAAA,UAAA,GAAAC,mBAYM,OAZN,YAYM,EAXJD,UAAA,IAAA,GAAAC,mBAUEC,UAAA,MAAAC,WATc,KAAA,QAAP,QAAG;IADZ,OAAAH,UAAA,GAAAC,mBAUE,OAAA;KARC,IAAI,OAAO,OAAA,MAAM,KAAA,GAAU,QAAA,SAAQ,GAAI,QAAQ,GAAG,MAAM,KAAA;KACxD,KAAK;KACL,MAAM,OAAO,OAAA,MAAM,KAAA,WAAA;KACnB,iBAAe,OAAO,OAAA,MAAM,KAAO,QAAQ,IAAA,QAAM,KAAA;KACjD,cAAY,OAAO,OAAA,MAAM,KAAOG,MAAA,OAAA,CAAO,CAAC,QAAA,MAAM,QAAQ,GAAG,EAAA,CAAI,OAAO,QAAA,QAAQ,IAAI,KAAA;KAChF,OAAKC,eAAA,CAAA,iCAAA,EAAA,UAAgD,OAAO,IAAA,MAAG,CAAA,CAAA;KAC/D,gBAAW,WAAE,KAAI,SAAU,QAAQ,GAAG,CAAA;KACtC,UAAK,WAAE,KAAI,UAAW,QAAQ,GAAG,CAAA"}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import columns_controls_vue_vue_type_script_setup_true_lang_default from "./columns-controls.vue_vue_type_script_setup_true_lang.js";
|
|
2
|
+
// src/extensions/columns/columns-controls.vue
|
|
3
|
+
var columns_controls_default = columns_controls_vue_vue_type_script_setup_true_lang_default;
|
|
4
|
+
export { columns_controls_default as default };
|
|
5
|
+
|
|
6
|
+
//# sourceMappingURL=columns-controls.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"columns-controls.js","names":["_sfc_main"],"sources":["../../../src/extensions/columns/columns-controls.vue"],"sourcesContent":["<script setup lang=\"ts\">\nimport { computed, nextTick, onBeforeUnmount, onMounted, shallowRef, watch } from 'vue'\nimport { findBlockById, layoutOf, parentBlock, blockAround } from '../../core/blocks'\nimport { childBlocks, COLUMNS_GROUP, sideBySide } from '../../dom'\nimport { useEditor } from '../../editor'\nimport { previewColumns, refreshColumns, type ColumnPreview } from './plugin'\nimport { widthOf } from './schema'\n\n/**\n * The bars between columns. One shows when the pointer is in the middle of\n * the gap between two columns (on a touch screen, after a tap there);\n * dragging it moves width from one column to the other, `Esc` takes the\n * drag back, a double click makes all the columns of the set even. While\n * the cursor is in a set of columns, its bars can also be reached with\n * `Tab` and moved with `←` `→`. A drag is shown as it goes and written to\n * the document when it ends: one undo step.\n */\nconst { view, state, root, messages, dragging } = useEditor()\n\n/** How far from the middle of the gap the bar can be grabbed, and on a touch screen tapped. */\nconst REACH = 5\nconst TOUCH_REACH = 20\n/** The narrowest a column gets by resizing. */\nconst MIN_WIDTH = 96\n/** How much of the two columns' width a key press moves. */\nconst STEP = 0.05\n\ninterface Bar {\n /** The set of columns, by id, and the column left of the bar. */\n row: string\n index: number\n top: number\n left: number\n height: number\n /** The left column's share of the two, in percent, for screen readers. */\n value: number\n}\n\n/** The bar under the pointer. */\nconst bar = shallowRef<Bar | null>(null)\n/** The bars of the set of columns the cursor is in, for the keyboard. */\nconst keyBars = shallowRef<Bar[]>([])\nconst active = shallowRef(false)\n\n/** The column blocks of a set: where each block is, and its width. */\nfunction columnsInDoc(row: string) {\n const current = view.value\n const info = current && findBlockById(current.state.doc, row)\n if (!info?.group || layoutOf(info.node) !== 'row') return null\n const list: { pos: number; width: number }[] = []\n let pos = info.contentPos + info.content.nodeSize + 1\n info.group.forEach((column) => {\n list.push({ pos, width: widthOf(column.firstChild!.attrs.width) ?? 1 })\n pos += column.nodeSize\n })\n return list\n}\n\nfunction findGroup(row: string) {\n const block = view.value?.dom.querySelector(`[data-block-id=\"${CSS.escape(row)}\"]`)\n return block?.querySelector<HTMLElement>(`:scope > ${COLUMNS_GROUP}`) ?? null\n}\n\n/** The middle of the gap after column `index`, on the screen. */\nconst middleOf = (columns: HTMLElement[], index: number) =>\n (columns[index]!.getBoundingClientRect().right +\n columns[index + 1]!.getBoundingClientRect().left) /\n 2\n\nfunction barAt(group: HTMLElement, index: number): Bar | null {\n const host = root.value\n const columns = childBlocks(group)\n const id = (group.parentElement as HTMLElement | null)?.dataset.blockId\n const weights = id && columnsInDoc(id)\n if (!host || !id || !weights || !columns[index + 1]) return null\n const box = host.getBoundingClientRect()\n const rect = group.getBoundingClientRect()\n const left = weights[index]!.width\n const right = weights[index + 1]!.width\n return {\n row: id,\n index,\n top: rect.top - box.top,\n left: middleOf(columns, index) - box.left,\n height: rect.height,\n value: Math.round((left / (left + right)) * 100),\n }\n}\n\n/** The bar near `x` in the set of columns `target` is in, if any. */\nfunction barNear(target: Element, x: number, reach: number): Bar | null {\n const group = target.closest<HTMLElement>(COLUMNS_GROUP)\n const columns = group ? childBlocks(group) : []\n if (!group || !sideBySide(columns)) return null\n for (let index = 0; index < columns.length - 1; index++)\n if (Math.abs(x - middleOf(columns, index)) <= reach) return barAt(group, index)\n return null\n}\n\nfunction track(event: PointerEvent) {\n if (event.pointerType === 'touch' || resize || dragging.value) return\n const target = event.target as Element\n if (target.closest('.dou-editor-columns__bar')) return\n bar.value = barNear(target, event.clientX, REACH)\n}\n\n/** A tap in the middle of a gap shows the bar there, to drag next. */\nfunction tap(event: PointerEvent) {\n if (event.pointerType === 'mouse' || resize) return\n const target = event.target as Element\n if (target.closest('.dou-editor-columns__bar')) return\n bar.value = barNear(target, event.clientX, TOUCH_REACH)\n}\n\nfunction leave(event: PointerEvent) {\n if (!resize && event.pointerType === 'mouse') bar.value = null\n}\n\n/** The bars of the set of columns around the cursor. */\nfunction placeKeyBars() {\n const current = state.value\n const block = current && blockAround(current.selection.$from)\n let row = block && parentBlock(current.doc, block)\n while (row && layoutOf(row.node) !== 'row') row = parentBlock(current!.doc, row)\n const group = row && findGroup(row.node.attrs.id as string)\n const columns = group ? childBlocks(group) : []\n if (!group || !sideBySide(columns)) {\n keyBars.value = []\n return\n }\n keyBars.value = columns\n .slice(1)\n .map((_, index) => barAt(group, index))\n .filter((entry): entry is Bar => !!entry)\n}\n\nwatch(state, () => void nextTick(placeKeyBars), { flush: 'post' })\n// the columns' names follow the locale\nwatch(messages, () => {\n const current = view.value\n if (current) current.dispatch(refreshColumns(current.state.tr))\n})\n\n/* dragging */\n\nlet resize: {\n pointer: number\n bar: Bar\n /** The two columns' widths together, in pixels, and the gap between them. */\n start: number\n span: number\n gap: number\n /** Their weights together, shared out again. */\n total: number\n /** Where the two columns are in the document. */\n columns: [number, number]\n weights: [number, number]\n} | null = null\n\n/** The two columns beside a bar: where they are, their weights and their size on the screen. */\nfunction pairOf(current: Bar) {\n const group = findGroup(current.row)\n const columns = group ? childBlocks(group) : []\n const weights = columnsInDoc(current.row)\n const left = columns[current.index]\n const right = columns[current.index + 1]\n const a = weights?.[current.index]\n const b = weights?.[current.index + 1]\n if (!group || !left || !right || !a || !b) return null\n const first = left.getBoundingClientRect()\n const second = right.getBoundingClientRect()\n return {\n group,\n start: first.left,\n span: first.width + second.width,\n gap: second.left - first.right,\n columns: [a.pos, b.pos] as [number, number],\n weights: [a.width, b.width] as [number, number],\n }\n}\n\n/** The left column's weight for a width in pixels, the narrowest kept. */\nfunction share(total: number, span: number, width: number): [number, number] {\n const min = Math.min(MIN_WIDTH, span / 2)\n const clamped = Math.min(span - min, Math.max(min, width))\n const left = Math.round((total * clamped * 1000) / span) / 1000\n return [left, Math.round((total - left) * 1000) / 1000]\n}\n\nfunction show(preview: ColumnPreview[] | null) {\n const current = view.value\n if (current) current.dispatch(previewColumns(current.state.tr, preview))\n}\n\n/** Write the two columns' widths: one undo step. */\nfunction commit(columns: [number, number], weights: [number, number]) {\n const current = view.value\n if (!current) return\n const tr = previewColumns(current.state.tr, null).setMeta('addToHistory', true)\n columns.forEach((pos, offset) => {\n const weight = weights[offset]!\n tr.setNodeAttribute(pos + 1, 'width', weight === 1 ? null : widthOf(weight))\n })\n current.dispatch(tr)\n}\n\nfunction onDown(event: PointerEvent, current: Bar) {\n if (event.button !== 0) return\n const pair = pairOf(current)\n if (!pair) return\n event.preventDefault()\n ;(event.currentTarget as HTMLElement).setPointerCapture(event.pointerId)\n resize = {\n pointer: event.pointerId,\n bar: current,\n start: pair.start,\n span: pair.span,\n gap: pair.gap,\n total: pair.weights[0] + pair.weights[1],\n columns: pair.columns,\n weights: pair.weights,\n }\n active.value = true\n window.addEventListener('keydown', onEscape, true)\n}\n\nfunction onMove(event: PointerEvent) {\n if (!resize || event.pointerId !== resize.pointer) return\n const { start, span, gap, total, columns } = resize\n resize.weights = share(total, span, event.clientX - gap / 2 - start)\n show(columns.map((pos, offset) => ({ pos, width: resize!.weights[offset]! })))\n const group = findGroup(resize.bar.row)\n const moved = group && barAt(group, resize.bar.index)\n if (moved) bar.value = moved\n}\n\nfunction end() {\n resize = null\n active.value = false\n window.removeEventListener('keydown', onEscape, true)\n}\n\nfunction onUp(event: PointerEvent) {\n if (!resize || event.pointerId !== resize.pointer) return\n const { columns, weights } = resize\n end()\n commit(columns, weights)\n}\n\n/** `Esc` or a cancelled pointer: the widths as they were. */\nfunction cancel() {\n if (!resize) return\n end()\n show(null)\n const current = bar.value\n const group = current && findGroup(current.row)\n if (current && group) bar.value = barAt(group, current.index)\n}\n\nfunction onEscape(event: KeyboardEvent) {\n if (event.key !== 'Escape') return\n event.preventDefault()\n event.stopPropagation()\n cancel()\n}\n\n/** `←` `→` on a bar: move a little width from one column to the other; `Esc` or `Shift+Tab` back to the text. */\nfunction onKey(event: KeyboardEvent, current: Bar) {\n if (event.key === 'Escape' || (event.key === 'Tab' && event.shiftKey)) {\n event.preventDefault()\n view.value?.focus()\n return\n }\n const direction = { ArrowLeft: -1, ArrowRight: 1 }[event.key]\n if (!direction) return\n event.preventDefault()\n const pair = pairOf(current)\n if (!pair) return\n const total = pair.weights[0] + pair.weights[1]\n const width = (pair.weights[0] / total) * pair.span + direction * STEP * pair.span\n commit(pair.columns, share(total, pair.span, width))\n void nextTick(placeKeyBars)\n}\n\n/** A double click: every column of the set as wide as the others. */\nfunction even(current: Bar) {\n const columns = columnsInDoc(current.row)\n const instance = view.value\n if (!columns || !instance) return\n const tr = instance.state.tr\n for (const column of columns)\n if (column.width !== 1) tr.setNodeAttribute(column.pos + 1, 'width', null)\n if (tr.docChanged) instance.dispatch(tr)\n}\n\n/** The bars to draw: the keyboard's, and the pointer's when it is at another gap. */\nconst bars = computed(() => {\n const list = keyBars.value.map((entry) => ({ ...entry, key: true, shown: false }))\n const pointed = bar.value\n if (!pointed) return list\n const same = list.findIndex((entry) => entry.row === pointed.row && entry.index === pointed.index)\n if (same < 0) return [...list, { ...pointed, key: false, shown: true }]\n list[same] = { ...pointed, key: true, shown: true }\n return list\n})\n\nconst onScroll = () => {\n if (!resize) bar.value = null\n}\n\n// the editor narrower or wider (a window resized, a tablet turned): the bars move with the columns\nlet observer: ResizeObserver | undefined\n\nonMounted(() => {\n if (typeof ResizeObserver !== 'undefined' && root.value) {\n observer = new ResizeObserver(() => {\n if (!resize) bar.value = null\n placeKeyBars()\n })\n observer.observe(root.value)\n }\n root.value?.addEventListener('pointermove', track)\n root.value?.addEventListener('pointerdown', tap)\n root.value?.addEventListener('pointerleave', leave)\n window.addEventListener('scroll', onScroll, true)\n placeKeyBars()\n})\nonBeforeUnmount(() => {\n observer?.disconnect()\n root.value?.removeEventListener('pointermove', track)\n root.value?.removeEventListener('pointerdown', tap)\n root.value?.removeEventListener('pointerleave', leave)\n window.removeEventListener('scroll', onScroll, true)\n window.removeEventListener('keydown', onEscape, true)\n})\n</script>\n\n<template>\n <div\n v-for=\"entry in bars\"\n :key=\"`${entry.row}-${entry.index}`\"\n :class=\"[\n 'dou-editor-columns__bar',\n { 'is-key': entry.key, 'is-shown': entry.shown, 'is-active': active && entry.shown },\n ]\"\n role=\"separator\"\n aria-orientation=\"vertical\"\n :tabindex=\"entry.key ? 0 : -1\"\n :aria-label=\"messages.columns.resize\"\n :aria-valuenow=\"entry.value\"\n aria-valuemin=\"0\"\n aria-valuemax=\"100\"\n :title=\"messages.columns.resize\"\n :style=\"{ top: `${entry.top}px`, left: `${entry.left}px`, height: `${entry.height}px` }\"\n @mousedown.prevent\n @pointerdown=\"onDown($event, entry)\"\n @pointermove=\"onMove\"\n @pointerup=\"onUp\"\n @pointercancel=\"cancel\"\n @lostpointercapture=\"cancel\"\n @keydown=\"onKey($event, entry)\"\n @focus=\"placeKeyBars\"\n @dblclick=\"even(entry)\"\n />\n</template>\n"],"mappings":""}
|
|
@@ -0,0 +1,341 @@
|
|
|
1
|
+
import { blockAround, findBlockById, layoutOf, parentBlock } from "../../core/blocks.js";
|
|
2
|
+
import { COLUMNS_GROUP, childBlocks, sideBySide } from "../../dom.js";
|
|
3
|
+
import { useEditor } from "../../editor.js";
|
|
4
|
+
import { previewColumns, refreshColumns } from "./plugin.js";
|
|
5
|
+
import { widthOf } from "./schema.js";
|
|
6
|
+
import { Fragment, computed, createElementBlock, defineComponent, nextTick, normalizeClass, normalizeStyle, onBeforeUnmount, onMounted, openBlock, renderList, shallowRef, unref, watch, withModifiers } from "vue";
|
|
7
|
+
// src/extensions/columns/columns-controls.vue?vue&type=script&setup=true&lang.ts
|
|
8
|
+
var _hoisted_1 = [
|
|
9
|
+
"tabindex",
|
|
10
|
+
"aria-label",
|
|
11
|
+
"aria-valuenow",
|
|
12
|
+
"title",
|
|
13
|
+
"onPointerdown",
|
|
14
|
+
"onKeydown",
|
|
15
|
+
"onDblclick"
|
|
16
|
+
];
|
|
17
|
+
/**
|
|
18
|
+
* The bars between columns. One shows when the pointer is in the middle of
|
|
19
|
+
* the gap between two columns (on a touch screen, after a tap there);
|
|
20
|
+
* dragging it moves width from one column to the other, `Esc` takes the
|
|
21
|
+
* drag back, a double click makes all the columns of the set even. While
|
|
22
|
+
* the cursor is in a set of columns, its bars can also be reached with
|
|
23
|
+
* `Tab` and moved with `←` `→`. A drag is shown as it goes and written to
|
|
24
|
+
* the document when it ends: one undo step.
|
|
25
|
+
*/
|
|
26
|
+
var REACH = 5;
|
|
27
|
+
var TOUCH_REACH = 20;
|
|
28
|
+
/** The narrowest a column gets by resizing. */
|
|
29
|
+
var MIN_WIDTH = 96;
|
|
30
|
+
/** How much of the two columns' width a key press moves. */
|
|
31
|
+
var STEP = .05;
|
|
32
|
+
/** The bar under the pointer. */
|
|
33
|
+
var columns_controls_vue_vue_type_script_setup_true_lang_default = /*@__PURE__*/ defineComponent({
|
|
34
|
+
__name: "columns-controls",
|
|
35
|
+
setup(__props) {
|
|
36
|
+
const { view, state, root, messages, dragging } = useEditor();
|
|
37
|
+
/** How far from the middle of the gap the bar can be grabbed, and on a touch screen tapped. */
|
|
38
|
+
const bar = shallowRef(null);
|
|
39
|
+
/** The bars of the set of columns the cursor is in, for the keyboard. */
|
|
40
|
+
const keyBars = shallowRef([]);
|
|
41
|
+
const active = shallowRef(false);
|
|
42
|
+
/** The column blocks of a set: where each block is, and its width. */
|
|
43
|
+
function columnsInDoc(row) {
|
|
44
|
+
const current = view.value;
|
|
45
|
+
const info = current && findBlockById(current.state.doc, row);
|
|
46
|
+
if (!info?.group || layoutOf(info.node) !== "row") return null;
|
|
47
|
+
const list = [];
|
|
48
|
+
let pos = info.contentPos + info.content.nodeSize + 1;
|
|
49
|
+
info.group.forEach((column) => {
|
|
50
|
+
list.push({
|
|
51
|
+
pos,
|
|
52
|
+
width: widthOf(column.firstChild.attrs.width) ?? 1
|
|
53
|
+
});
|
|
54
|
+
pos += column.nodeSize;
|
|
55
|
+
});
|
|
56
|
+
return list;
|
|
57
|
+
}
|
|
58
|
+
function findGroup(row) {
|
|
59
|
+
return (view.value?.dom.querySelector(`[data-block-id="${CSS.escape(row)}"]`))?.querySelector(`:scope > .dou-editor__content--columns + .dou-editor__group`) ?? null;
|
|
60
|
+
}
|
|
61
|
+
/** The middle of the gap after column `index`, on the screen. */
|
|
62
|
+
const middleOf = (columns, index) => (columns[index].getBoundingClientRect().right + columns[index + 1].getBoundingClientRect().left) / 2;
|
|
63
|
+
function barAt(group, index) {
|
|
64
|
+
const host = root.value;
|
|
65
|
+
const columns = childBlocks(group);
|
|
66
|
+
const id = group.parentElement?.dataset.blockId;
|
|
67
|
+
const weights = id && columnsInDoc(id);
|
|
68
|
+
if (!host || !id || !weights || !columns[index + 1]) return null;
|
|
69
|
+
const box = host.getBoundingClientRect();
|
|
70
|
+
const rect = group.getBoundingClientRect();
|
|
71
|
+
const left = weights[index].width;
|
|
72
|
+
const right = weights[index + 1].width;
|
|
73
|
+
return {
|
|
74
|
+
row: id,
|
|
75
|
+
index,
|
|
76
|
+
top: rect.top - box.top,
|
|
77
|
+
left: middleOf(columns, index) - box.left,
|
|
78
|
+
height: rect.height,
|
|
79
|
+
value: Math.round(left / (left + right) * 100)
|
|
80
|
+
};
|
|
81
|
+
}
|
|
82
|
+
/** The bar near `x` in the set of columns `target` is in, if any. */
|
|
83
|
+
function barNear(target, x, reach) {
|
|
84
|
+
const group = target.closest(COLUMNS_GROUP);
|
|
85
|
+
const columns = group ? childBlocks(group) : [];
|
|
86
|
+
if (!group || !sideBySide(columns)) return null;
|
|
87
|
+
for (let index = 0; index < columns.length - 1; index++) if (Math.abs(x - middleOf(columns, index)) <= reach) return barAt(group, index);
|
|
88
|
+
return null;
|
|
89
|
+
}
|
|
90
|
+
function track(event) {
|
|
91
|
+
if (event.pointerType === "touch" || resize || dragging.value) return;
|
|
92
|
+
const target = event.target;
|
|
93
|
+
if (target.closest(".dou-editor-columns__bar")) return;
|
|
94
|
+
bar.value = barNear(target, event.clientX, REACH);
|
|
95
|
+
}
|
|
96
|
+
/** A tap in the middle of a gap shows the bar there, to drag next. */
|
|
97
|
+
function tap(event) {
|
|
98
|
+
if (event.pointerType === "mouse" || resize) return;
|
|
99
|
+
const target = event.target;
|
|
100
|
+
if (target.closest(".dou-editor-columns__bar")) return;
|
|
101
|
+
bar.value = barNear(target, event.clientX, TOUCH_REACH);
|
|
102
|
+
}
|
|
103
|
+
function leave(event) {
|
|
104
|
+
if (!resize && event.pointerType === "mouse") bar.value = null;
|
|
105
|
+
}
|
|
106
|
+
/** The bars of the set of columns around the cursor. */
|
|
107
|
+
function placeKeyBars() {
|
|
108
|
+
const current = state.value;
|
|
109
|
+
const block = current && blockAround(current.selection.$from);
|
|
110
|
+
let row = block && parentBlock(current.doc, block);
|
|
111
|
+
while (row && layoutOf(row.node) !== "row") row = parentBlock(current.doc, row);
|
|
112
|
+
const group = row && findGroup(row.node.attrs.id);
|
|
113
|
+
const columns = group ? childBlocks(group) : [];
|
|
114
|
+
if (!group || !sideBySide(columns)) {
|
|
115
|
+
keyBars.value = [];
|
|
116
|
+
return;
|
|
117
|
+
}
|
|
118
|
+
keyBars.value = columns.slice(1).map((_, index) => barAt(group, index)).filter((entry) => !!entry);
|
|
119
|
+
}
|
|
120
|
+
watch(state, () => void nextTick(placeKeyBars), { flush: "post" });
|
|
121
|
+
watch(messages, () => {
|
|
122
|
+
const current = view.value;
|
|
123
|
+
if (current) current.dispatch(refreshColumns(current.state.tr));
|
|
124
|
+
});
|
|
125
|
+
let resize = null;
|
|
126
|
+
/** The two columns beside a bar: where they are, their weights and their size on the screen. */
|
|
127
|
+
function pairOf(current) {
|
|
128
|
+
const group = findGroup(current.row);
|
|
129
|
+
const columns = group ? childBlocks(group) : [];
|
|
130
|
+
const weights = columnsInDoc(current.row);
|
|
131
|
+
const left = columns[current.index];
|
|
132
|
+
const right = columns[current.index + 1];
|
|
133
|
+
const a = weights?.[current.index];
|
|
134
|
+
const b = weights?.[current.index + 1];
|
|
135
|
+
if (!group || !left || !right || !a || !b) return null;
|
|
136
|
+
const first = left.getBoundingClientRect();
|
|
137
|
+
const second = right.getBoundingClientRect();
|
|
138
|
+
return {
|
|
139
|
+
group,
|
|
140
|
+
start: first.left,
|
|
141
|
+
span: first.width + second.width,
|
|
142
|
+
gap: second.left - first.right,
|
|
143
|
+
columns: [a.pos, b.pos],
|
|
144
|
+
weights: [a.width, b.width]
|
|
145
|
+
};
|
|
146
|
+
}
|
|
147
|
+
/** The left column's weight for a width in pixels, the narrowest kept. */
|
|
148
|
+
function share(total, span, width) {
|
|
149
|
+
const min = Math.min(MIN_WIDTH, span / 2);
|
|
150
|
+
const clamped = Math.min(span - min, Math.max(min, width));
|
|
151
|
+
const left = Math.round(total * clamped * 1e3 / span) / 1e3;
|
|
152
|
+
return [left, Math.round((total - left) * 1e3) / 1e3];
|
|
153
|
+
}
|
|
154
|
+
function show(preview) {
|
|
155
|
+
const current = view.value;
|
|
156
|
+
if (current) current.dispatch(previewColumns(current.state.tr, preview));
|
|
157
|
+
}
|
|
158
|
+
/** Write the two columns' widths: one undo step. */
|
|
159
|
+
function commit(columns, weights) {
|
|
160
|
+
const current = view.value;
|
|
161
|
+
if (!current) return;
|
|
162
|
+
const tr = previewColumns(current.state.tr, null).setMeta("addToHistory", true);
|
|
163
|
+
columns.forEach((pos, offset) => {
|
|
164
|
+
const weight = weights[offset];
|
|
165
|
+
tr.setNodeAttribute(pos + 1, "width", weight === 1 ? null : widthOf(weight));
|
|
166
|
+
});
|
|
167
|
+
current.dispatch(tr);
|
|
168
|
+
}
|
|
169
|
+
function onDown(event, current) {
|
|
170
|
+
if (event.button !== 0) return;
|
|
171
|
+
const pair = pairOf(current);
|
|
172
|
+
if (!pair) return;
|
|
173
|
+
event.preventDefault();
|
|
174
|
+
event.currentTarget.setPointerCapture(event.pointerId);
|
|
175
|
+
resize = {
|
|
176
|
+
pointer: event.pointerId,
|
|
177
|
+
bar: current,
|
|
178
|
+
start: pair.start,
|
|
179
|
+
span: pair.span,
|
|
180
|
+
gap: pair.gap,
|
|
181
|
+
total: pair.weights[0] + pair.weights[1],
|
|
182
|
+
columns: pair.columns,
|
|
183
|
+
weights: pair.weights
|
|
184
|
+
};
|
|
185
|
+
active.value = true;
|
|
186
|
+
window.addEventListener("keydown", onEscape, true);
|
|
187
|
+
}
|
|
188
|
+
function onMove(event) {
|
|
189
|
+
if (!resize || event.pointerId !== resize.pointer) return;
|
|
190
|
+
const { start, span, gap, total, columns } = resize;
|
|
191
|
+
resize.weights = share(total, span, event.clientX - gap / 2 - start);
|
|
192
|
+
show(columns.map((pos, offset) => ({
|
|
193
|
+
pos,
|
|
194
|
+
width: resize.weights[offset]
|
|
195
|
+
})));
|
|
196
|
+
const group = findGroup(resize.bar.row);
|
|
197
|
+
const moved = group && barAt(group, resize.bar.index);
|
|
198
|
+
if (moved) bar.value = moved;
|
|
199
|
+
}
|
|
200
|
+
function end() {
|
|
201
|
+
resize = null;
|
|
202
|
+
active.value = false;
|
|
203
|
+
window.removeEventListener("keydown", onEscape, true);
|
|
204
|
+
}
|
|
205
|
+
function onUp(event) {
|
|
206
|
+
if (!resize || event.pointerId !== resize.pointer) return;
|
|
207
|
+
const { columns, weights } = resize;
|
|
208
|
+
end();
|
|
209
|
+
commit(columns, weights);
|
|
210
|
+
}
|
|
211
|
+
/** `Esc` or a cancelled pointer: the widths as they were. */
|
|
212
|
+
function cancel() {
|
|
213
|
+
if (!resize) return;
|
|
214
|
+
end();
|
|
215
|
+
show(null);
|
|
216
|
+
const current = bar.value;
|
|
217
|
+
const group = current && findGroup(current.row);
|
|
218
|
+
if (current && group) bar.value = barAt(group, current.index);
|
|
219
|
+
}
|
|
220
|
+
function onEscape(event) {
|
|
221
|
+
if (event.key !== "Escape") return;
|
|
222
|
+
event.preventDefault();
|
|
223
|
+
event.stopPropagation();
|
|
224
|
+
cancel();
|
|
225
|
+
}
|
|
226
|
+
/** `←` `→` on a bar: move a little width from one column to the other; `Esc` or `Shift+Tab` back to the text. */
|
|
227
|
+
function onKey(event, current) {
|
|
228
|
+
if (event.key === "Escape" || event.key === "Tab" && event.shiftKey) {
|
|
229
|
+
event.preventDefault();
|
|
230
|
+
view.value?.focus();
|
|
231
|
+
return;
|
|
232
|
+
}
|
|
233
|
+
const direction = {
|
|
234
|
+
ArrowLeft: -1,
|
|
235
|
+
ArrowRight: 1
|
|
236
|
+
}[event.key];
|
|
237
|
+
if (!direction) return;
|
|
238
|
+
event.preventDefault();
|
|
239
|
+
const pair = pairOf(current);
|
|
240
|
+
if (!pair) return;
|
|
241
|
+
const total = pair.weights[0] + pair.weights[1];
|
|
242
|
+
const width = pair.weights[0] / total * pair.span + direction * STEP * pair.span;
|
|
243
|
+
commit(pair.columns, share(total, pair.span, width));
|
|
244
|
+
nextTick(placeKeyBars);
|
|
245
|
+
}
|
|
246
|
+
/** A double click: every column of the set as wide as the others. */
|
|
247
|
+
function even(current) {
|
|
248
|
+
const columns = columnsInDoc(current.row);
|
|
249
|
+
const instance = view.value;
|
|
250
|
+
if (!columns || !instance) return;
|
|
251
|
+
const tr = instance.state.tr;
|
|
252
|
+
for (const column of columns) if (column.width !== 1) tr.setNodeAttribute(column.pos + 1, "width", null);
|
|
253
|
+
if (tr.docChanged) instance.dispatch(tr);
|
|
254
|
+
}
|
|
255
|
+
/** The bars to draw: the keyboard's, and the pointer's when it is at another gap. */
|
|
256
|
+
const bars = computed(() => {
|
|
257
|
+
const list = keyBars.value.map((entry) => ({
|
|
258
|
+
...entry,
|
|
259
|
+
key: true,
|
|
260
|
+
shown: false
|
|
261
|
+
}));
|
|
262
|
+
const pointed = bar.value;
|
|
263
|
+
if (!pointed) return list;
|
|
264
|
+
const same = list.findIndex((entry) => entry.row === pointed.row && entry.index === pointed.index);
|
|
265
|
+
if (same < 0) return [...list, {
|
|
266
|
+
...pointed,
|
|
267
|
+
key: false,
|
|
268
|
+
shown: true
|
|
269
|
+
}];
|
|
270
|
+
list[same] = {
|
|
271
|
+
...pointed,
|
|
272
|
+
key: true,
|
|
273
|
+
shown: true
|
|
274
|
+
};
|
|
275
|
+
return list;
|
|
276
|
+
});
|
|
277
|
+
const onScroll = () => {
|
|
278
|
+
if (!resize) bar.value = null;
|
|
279
|
+
};
|
|
280
|
+
let observer;
|
|
281
|
+
onMounted(() => {
|
|
282
|
+
if (typeof ResizeObserver !== "undefined" && root.value) {
|
|
283
|
+
observer = new ResizeObserver(() => {
|
|
284
|
+
if (!resize) bar.value = null;
|
|
285
|
+
placeKeyBars();
|
|
286
|
+
});
|
|
287
|
+
observer.observe(root.value);
|
|
288
|
+
}
|
|
289
|
+
root.value?.addEventListener("pointermove", track);
|
|
290
|
+
root.value?.addEventListener("pointerdown", tap);
|
|
291
|
+
root.value?.addEventListener("pointerleave", leave);
|
|
292
|
+
window.addEventListener("scroll", onScroll, true);
|
|
293
|
+
placeKeyBars();
|
|
294
|
+
});
|
|
295
|
+
onBeforeUnmount(() => {
|
|
296
|
+
observer?.disconnect();
|
|
297
|
+
root.value?.removeEventListener("pointermove", track);
|
|
298
|
+
root.value?.removeEventListener("pointerdown", tap);
|
|
299
|
+
root.value?.removeEventListener("pointerleave", leave);
|
|
300
|
+
window.removeEventListener("scroll", onScroll, true);
|
|
301
|
+
window.removeEventListener("keydown", onEscape, true);
|
|
302
|
+
});
|
|
303
|
+
return (_ctx, _cache) => {
|
|
304
|
+
return openBlock(true), createElementBlock(Fragment, null, renderList(bars.value, (entry) => {
|
|
305
|
+
return openBlock(), createElementBlock("div", {
|
|
306
|
+
key: `${entry.row}-${entry.index}`,
|
|
307
|
+
class: normalizeClass(["dou-editor-columns__bar", {
|
|
308
|
+
"is-key": entry.key,
|
|
309
|
+
"is-shown": entry.shown,
|
|
310
|
+
"is-active": active.value && entry.shown
|
|
311
|
+
}]),
|
|
312
|
+
role: "separator",
|
|
313
|
+
"aria-orientation": "vertical",
|
|
314
|
+
tabindex: entry.key ? 0 : -1,
|
|
315
|
+
"aria-label": unref(messages).columns.resize,
|
|
316
|
+
"aria-valuenow": entry.value,
|
|
317
|
+
"aria-valuemin": "0",
|
|
318
|
+
"aria-valuemax": "100",
|
|
319
|
+
title: unref(messages).columns.resize,
|
|
320
|
+
style: normalizeStyle({
|
|
321
|
+
top: `${entry.top}px`,
|
|
322
|
+
left: `${entry.left}px`,
|
|
323
|
+
height: `${entry.height}px`
|
|
324
|
+
}),
|
|
325
|
+
onMousedown: _cache[0] || (_cache[0] = withModifiers(() => {}, ["prevent"])),
|
|
326
|
+
onPointerdown: ($event) => onDown($event, entry),
|
|
327
|
+
onPointermove: onMove,
|
|
328
|
+
onPointerup: onUp,
|
|
329
|
+
onPointercancel: cancel,
|
|
330
|
+
onLostpointercapture: cancel,
|
|
331
|
+
onKeydown: ($event) => onKey($event, entry),
|
|
332
|
+
onFocus: placeKeyBars,
|
|
333
|
+
onDblclick: ($event) => even(entry)
|
|
334
|
+
}, null, 46, _hoisted_1);
|
|
335
|
+
}), 128);
|
|
336
|
+
};
|
|
337
|
+
}
|
|
338
|
+
});
|
|
339
|
+
export { columns_controls_vue_vue_type_script_setup_true_lang_default as default };
|
|
340
|
+
|
|
341
|
+
//# sourceMappingURL=columns-controls.vue_vue_type_script_setup_true_lang.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"columns-controls.vue_vue_type_script_setup_true_lang.js","names":["_openBlock","_createElementBlock","_Fragment","_renderList","_normalizeClass","_unref","_normalizeStyle","_withModifiers"],"sources":["../../../src/extensions/columns/columns-controls.vue"],"sourcesContent":["<script setup lang=\"ts\">\nimport { computed, nextTick, onBeforeUnmount, onMounted, shallowRef, watch } from 'vue'\nimport { findBlockById, layoutOf, parentBlock, blockAround } from '../../core/blocks'\nimport { childBlocks, COLUMNS_GROUP, sideBySide } from '../../dom'\nimport { useEditor } from '../../editor'\nimport { previewColumns, refreshColumns, type ColumnPreview } from './plugin'\nimport { widthOf } from './schema'\n\n/**\n * The bars between columns. One shows when the pointer is in the middle of\n * the gap between two columns (on a touch screen, after a tap there);\n * dragging it moves width from one column to the other, `Esc` takes the\n * drag back, a double click makes all the columns of the set even. While\n * the cursor is in a set of columns, its bars can also be reached with\n * `Tab` and moved with `←` `→`. A drag is shown as it goes and written to\n * the document when it ends: one undo step.\n */\nconst { view, state, root, messages, dragging } = useEditor()\n\n/** How far from the middle of the gap the bar can be grabbed, and on a touch screen tapped. */\nconst REACH = 5\nconst TOUCH_REACH = 20\n/** The narrowest a column gets by resizing. */\nconst MIN_WIDTH = 96\n/** How much of the two columns' width a key press moves. */\nconst STEP = 0.05\n\ninterface Bar {\n /** The set of columns, by id, and the column left of the bar. */\n row: string\n index: number\n top: number\n left: number\n height: number\n /** The left column's share of the two, in percent, for screen readers. */\n value: number\n}\n\n/** The bar under the pointer. */\nconst bar = shallowRef<Bar | null>(null)\n/** The bars of the set of columns the cursor is in, for the keyboard. */\nconst keyBars = shallowRef<Bar[]>([])\nconst active = shallowRef(false)\n\n/** The column blocks of a set: where each block is, and its width. */\nfunction columnsInDoc(row: string) {\n const current = view.value\n const info = current && findBlockById(current.state.doc, row)\n if (!info?.group || layoutOf(info.node) !== 'row') return null\n const list: { pos: number; width: number }[] = []\n let pos = info.contentPos + info.content.nodeSize + 1\n info.group.forEach((column) => {\n list.push({ pos, width: widthOf(column.firstChild!.attrs.width) ?? 1 })\n pos += column.nodeSize\n })\n return list\n}\n\nfunction findGroup(row: string) {\n const block = view.value?.dom.querySelector(`[data-block-id=\"${CSS.escape(row)}\"]`)\n return block?.querySelector<HTMLElement>(`:scope > ${COLUMNS_GROUP}`) ?? null\n}\n\n/** The middle of the gap after column `index`, on the screen. */\nconst middleOf = (columns: HTMLElement[], index: number) =>\n (columns[index]!.getBoundingClientRect().right +\n columns[index + 1]!.getBoundingClientRect().left) /\n 2\n\nfunction barAt(group: HTMLElement, index: number): Bar | null {\n const host = root.value\n const columns = childBlocks(group)\n const id = (group.parentElement as HTMLElement | null)?.dataset.blockId\n const weights = id && columnsInDoc(id)\n if (!host || !id || !weights || !columns[index + 1]) return null\n const box = host.getBoundingClientRect()\n const rect = group.getBoundingClientRect()\n const left = weights[index]!.width\n const right = weights[index + 1]!.width\n return {\n row: id,\n index,\n top: rect.top - box.top,\n left: middleOf(columns, index) - box.left,\n height: rect.height,\n value: Math.round((left / (left + right)) * 100),\n }\n}\n\n/** The bar near `x` in the set of columns `target` is in, if any. */\nfunction barNear(target: Element, x: number, reach: number): Bar | null {\n const group = target.closest<HTMLElement>(COLUMNS_GROUP)\n const columns = group ? childBlocks(group) : []\n if (!group || !sideBySide(columns)) return null\n for (let index = 0; index < columns.length - 1; index++)\n if (Math.abs(x - middleOf(columns, index)) <= reach) return barAt(group, index)\n return null\n}\n\nfunction track(event: PointerEvent) {\n if (event.pointerType === 'touch' || resize || dragging.value) return\n const target = event.target as Element\n if (target.closest('.dou-editor-columns__bar')) return\n bar.value = barNear(target, event.clientX, REACH)\n}\n\n/** A tap in the middle of a gap shows the bar there, to drag next. */\nfunction tap(event: PointerEvent) {\n if (event.pointerType === 'mouse' || resize) return\n const target = event.target as Element\n if (target.closest('.dou-editor-columns__bar')) return\n bar.value = barNear(target, event.clientX, TOUCH_REACH)\n}\n\nfunction leave(event: PointerEvent) {\n if (!resize && event.pointerType === 'mouse') bar.value = null\n}\n\n/** The bars of the set of columns around the cursor. */\nfunction placeKeyBars() {\n const current = state.value\n const block = current && blockAround(current.selection.$from)\n let row = block && parentBlock(current.doc, block)\n while (row && layoutOf(row.node) !== 'row') row = parentBlock(current!.doc, row)\n const group = row && findGroup(row.node.attrs.id as string)\n const columns = group ? childBlocks(group) : []\n if (!group || !sideBySide(columns)) {\n keyBars.value = []\n return\n }\n keyBars.value = columns\n .slice(1)\n .map((_, index) => barAt(group, index))\n .filter((entry): entry is Bar => !!entry)\n}\n\nwatch(state, () => void nextTick(placeKeyBars), { flush: 'post' })\n// the columns' names follow the locale\nwatch(messages, () => {\n const current = view.value\n if (current) current.dispatch(refreshColumns(current.state.tr))\n})\n\n/* dragging */\n\nlet resize: {\n pointer: number\n bar: Bar\n /** The two columns' widths together, in pixels, and the gap between them. */\n start: number\n span: number\n gap: number\n /** Their weights together, shared out again. */\n total: number\n /** Where the two columns are in the document. */\n columns: [number, number]\n weights: [number, number]\n} | null = null\n\n/** The two columns beside a bar: where they are, their weights and their size on the screen. */\nfunction pairOf(current: Bar) {\n const group = findGroup(current.row)\n const columns = group ? childBlocks(group) : []\n const weights = columnsInDoc(current.row)\n const left = columns[current.index]\n const right = columns[current.index + 1]\n const a = weights?.[current.index]\n const b = weights?.[current.index + 1]\n if (!group || !left || !right || !a || !b) return null\n const first = left.getBoundingClientRect()\n const second = right.getBoundingClientRect()\n return {\n group,\n start: first.left,\n span: first.width + second.width,\n gap: second.left - first.right,\n columns: [a.pos, b.pos] as [number, number],\n weights: [a.width, b.width] as [number, number],\n }\n}\n\n/** The left column's weight for a width in pixels, the narrowest kept. */\nfunction share(total: number, span: number, width: number): [number, number] {\n const min = Math.min(MIN_WIDTH, span / 2)\n const clamped = Math.min(span - min, Math.max(min, width))\n const left = Math.round((total * clamped * 1000) / span) / 1000\n return [left, Math.round((total - left) * 1000) / 1000]\n}\n\nfunction show(preview: ColumnPreview[] | null) {\n const current = view.value\n if (current) current.dispatch(previewColumns(current.state.tr, preview))\n}\n\n/** Write the two columns' widths: one undo step. */\nfunction commit(columns: [number, number], weights: [number, number]) {\n const current = view.value\n if (!current) return\n const tr = previewColumns(current.state.tr, null).setMeta('addToHistory', true)\n columns.forEach((pos, offset) => {\n const weight = weights[offset]!\n tr.setNodeAttribute(pos + 1, 'width', weight === 1 ? null : widthOf(weight))\n })\n current.dispatch(tr)\n}\n\nfunction onDown(event: PointerEvent, current: Bar) {\n if (event.button !== 0) return\n const pair = pairOf(current)\n if (!pair) return\n event.preventDefault()\n ;(event.currentTarget as HTMLElement).setPointerCapture(event.pointerId)\n resize = {\n pointer: event.pointerId,\n bar: current,\n start: pair.start,\n span: pair.span,\n gap: pair.gap,\n total: pair.weights[0] + pair.weights[1],\n columns: pair.columns,\n weights: pair.weights,\n }\n active.value = true\n window.addEventListener('keydown', onEscape, true)\n}\n\nfunction onMove(event: PointerEvent) {\n if (!resize || event.pointerId !== resize.pointer) return\n const { start, span, gap, total, columns } = resize\n resize.weights = share(total, span, event.clientX - gap / 2 - start)\n show(columns.map((pos, offset) => ({ pos, width: resize!.weights[offset]! })))\n const group = findGroup(resize.bar.row)\n const moved = group && barAt(group, resize.bar.index)\n if (moved) bar.value = moved\n}\n\nfunction end() {\n resize = null\n active.value = false\n window.removeEventListener('keydown', onEscape, true)\n}\n\nfunction onUp(event: PointerEvent) {\n if (!resize || event.pointerId !== resize.pointer) return\n const { columns, weights } = resize\n end()\n commit(columns, weights)\n}\n\n/** `Esc` or a cancelled pointer: the widths as they were. */\nfunction cancel() {\n if (!resize) return\n end()\n show(null)\n const current = bar.value\n const group = current && findGroup(current.row)\n if (current && group) bar.value = barAt(group, current.index)\n}\n\nfunction onEscape(event: KeyboardEvent) {\n if (event.key !== 'Escape') return\n event.preventDefault()\n event.stopPropagation()\n cancel()\n}\n\n/** `←` `→` on a bar: move a little width from one column to the other; `Esc` or `Shift+Tab` back to the text. */\nfunction onKey(event: KeyboardEvent, current: Bar) {\n if (event.key === 'Escape' || (event.key === 'Tab' && event.shiftKey)) {\n event.preventDefault()\n view.value?.focus()\n return\n }\n const direction = { ArrowLeft: -1, ArrowRight: 1 }[event.key]\n if (!direction) return\n event.preventDefault()\n const pair = pairOf(current)\n if (!pair) return\n const total = pair.weights[0] + pair.weights[1]\n const width = (pair.weights[0] / total) * pair.span + direction * STEP * pair.span\n commit(pair.columns, share(total, pair.span, width))\n void nextTick(placeKeyBars)\n}\n\n/** A double click: every column of the set as wide as the others. */\nfunction even(current: Bar) {\n const columns = columnsInDoc(current.row)\n const instance = view.value\n if (!columns || !instance) return\n const tr = instance.state.tr\n for (const column of columns)\n if (column.width !== 1) tr.setNodeAttribute(column.pos + 1, 'width', null)\n if (tr.docChanged) instance.dispatch(tr)\n}\n\n/** The bars to draw: the keyboard's, and the pointer's when it is at another gap. */\nconst bars = computed(() => {\n const list = keyBars.value.map((entry) => ({ ...entry, key: true, shown: false }))\n const pointed = bar.value\n if (!pointed) return list\n const same = list.findIndex((entry) => entry.row === pointed.row && entry.index === pointed.index)\n if (same < 0) return [...list, { ...pointed, key: false, shown: true }]\n list[same] = { ...pointed, key: true, shown: true }\n return list\n})\n\nconst onScroll = () => {\n if (!resize) bar.value = null\n}\n\n// the editor narrower or wider (a window resized, a tablet turned): the bars move with the columns\nlet observer: ResizeObserver | undefined\n\nonMounted(() => {\n if (typeof ResizeObserver !== 'undefined' && root.value) {\n observer = new ResizeObserver(() => {\n if (!resize) bar.value = null\n placeKeyBars()\n })\n observer.observe(root.value)\n }\n root.value?.addEventListener('pointermove', track)\n root.value?.addEventListener('pointerdown', tap)\n root.value?.addEventListener('pointerleave', leave)\n window.addEventListener('scroll', onScroll, true)\n placeKeyBars()\n})\nonBeforeUnmount(() => {\n observer?.disconnect()\n root.value?.removeEventListener('pointermove', track)\n root.value?.removeEventListener('pointerdown', tap)\n root.value?.removeEventListener('pointerleave', leave)\n window.removeEventListener('scroll', onScroll, true)\n window.removeEventListener('keydown', onEscape, true)\n})\n</script>\n\n<template>\n <div\n v-for=\"entry in bars\"\n :key=\"`${entry.row}-${entry.index}`\"\n :class=\"[\n 'dou-editor-columns__bar',\n { 'is-key': entry.key, 'is-shown': entry.shown, 'is-active': active && entry.shown },\n ]\"\n role=\"separator\"\n aria-orientation=\"vertical\"\n :tabindex=\"entry.key ? 0 : -1\"\n :aria-label=\"messages.columns.resize\"\n :aria-valuenow=\"entry.value\"\n aria-valuemin=\"0\"\n aria-valuemax=\"100\"\n :title=\"messages.columns.resize\"\n :style=\"{ top: `${entry.top}px`, left: `${entry.left}px`, height: `${entry.height}px` }\"\n @mousedown.prevent\n @pointerdown=\"onDown($event, entry)\"\n @pointermove=\"onMove\"\n @pointerup=\"onUp\"\n @pointercancel=\"cancel\"\n @lostpointercapture=\"cancel\"\n @keydown=\"onKey($event, entry)\"\n @focus=\"placeKeyBars\"\n @dblclick=\"even(entry)\"\n />\n</template>\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;AAoBA,IAAM,QAAQ;AACd,IAAM,cAAc;;AAEpB,IAAM,YAAY;;AAElB,IAAM,OAAO;;;;;EARb,MAAM,EAAE,MAAM,OAAO,MAAM,UAAU,aAAa,UAAU;;EAsB5D,MAAM,MAAM,WAAuB,IAAI;;EAEvC,MAAM,UAAU,WAAkB,CAAC,CAAC;EACpC,MAAM,SAAS,WAAW,KAAK;;EAG/B,SAAS,aAAa,KAAa;GACjC,MAAM,UAAU,KAAK;GACrB,MAAM,OAAO,WAAW,cAAc,QAAQ,MAAM,KAAK,GAAG;GAC5D,IAAI,CAAC,MAAM,SAAS,SAAS,KAAK,IAAI,MAAM,OAAO,OAAO;GAC1D,MAAM,OAAyC,CAAC;GAChD,IAAI,MAAM,KAAK,aAAa,KAAK,QAAQ,WAAW;GACpD,KAAK,MAAM,SAAS,WAAW;IAC7B,KAAK,KAAK;KAAE;KAAK,OAAO,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AAK,MAAM,IAAG,GAAI,MAAM;KAC3B,OAAKG,eAAA,C,2BAAuD;MAAA,UAAA,MAAM;MAAG,YAAc,MAAM;MAAK,aAAe,OAAA,SAAU,MAAM;KAAK,C;KAInI,MAAK;KACL,oBAAiB;KAChB,UAAU,MAAM,MAAG,IAAA;KACnB,cAAYC,MAAA,QAAA,CAAQ,CAAC,QAAQ;KAC7B,iBAAe,MAAM;KACtB,iBAAc;KACd,iBAAc;KACb,OAAOA,MAAA,QAAA,CAAQ,CAAC,QAAQ;KACxB,OAAKC,eAAA;MAAA,KAAA,GAAY,MAAM,IAAG;MAAA,MAAA,GAAe,MAAM,KAAI;MAAA,QAAA,GAAiB,MAAM,OAAM;KAAA,CAAA;KAChF,aAAS,OAAA,OAAA,OAAA,KAAAC,oBAAV,CAAA,GAAkB,CAAA,SAAA,CAAA;KACjB,gBAAW,WAAE,OAAO,QAAQ,KAAK;KACjC,eAAa;KACb,aAAW;KACX,iBAAe;KACf,sBAAoB;KACpB,YAAO,WAAE,MAAM,QAAQ,KAAK;KAC5B,SAAO;KACP,aAAQ,WAAE,KAAK,KAAK"}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { blockElement } from "../../core/prepare.js";
|
|
2
|
+
import { widthOf } from "./schema.js";
|
|
3
|
+
// src/extensions/columns/html.ts
|
|
4
|
+
/**
|
|
5
|
+
* Columns in HTML: a flex row of `div`s, each with its share of the row,
|
|
6
|
+
* so the page shows them side by side without the editor's styles; on a
|
|
7
|
+
* narrow page they wrap, one under the other.
|
|
8
|
+
* Markdown has no columns: their blocks follow one another.
|
|
9
|
+
*/
|
|
10
|
+
var columnsOutput = {
|
|
11
|
+
columns: {
|
|
12
|
+
html: (_block, { children }) => `<div data-columns style="display: flex; flex-wrap: wrap; gap: 1em 2em">${children}</div>`,
|
|
13
|
+
markdown: (_block, { children }) => children
|
|
14
|
+
},
|
|
15
|
+
column: {
|
|
16
|
+
html: (block, { children }) => {
|
|
17
|
+
const width = widthOf(block.props.width);
|
|
18
|
+
return `<div data-column${width ? ` data-width="${width}"` : ""} style="flex: ${width ?? 1} 1 0; min-width: min(100%, 12em)">${children}</div>`;
|
|
19
|
+
},
|
|
20
|
+
markdown: (_block, { children }) => children
|
|
21
|
+
}
|
|
22
|
+
};
|
|
23
|
+
/** Back from that HTML: `div[data-columns]` and the `div[data-column]` in it. */
|
|
24
|
+
function prepareColumns(root) {
|
|
25
|
+
const doc = root.ownerDocument;
|
|
26
|
+
for (const element of Array.from(root.querySelectorAll("div[data-column]"))) {
|
|
27
|
+
const width = widthOf(element.dataset.width);
|
|
28
|
+
element.replaceWith(blockElement(doc, "column", [], Array.from(element.childNodes), width ? { width: String(width) } : {}));
|
|
29
|
+
}
|
|
30
|
+
for (const element of Array.from(root.querySelectorAll("div[data-columns]"))) element.replaceWith(blockElement(doc, "columns", [], Array.from(element.childNodes)));
|
|
31
|
+
}
|
|
32
|
+
export { columnsOutput, prepareColumns };
|
|
33
|
+
|
|
34
|
+
//# sourceMappingURL=html.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"html.js","names":[],"sources":["../../../src/extensions/columns/html.ts"],"sourcesContent":["import type { BlockOutput } from '../../core/output'\nimport { blockElement } from '../../core/prepare'\nimport { widthOf } from './schema'\n\n/**\n * Columns in HTML: a flex row of `div`s, each with its share of the row,\n * so the page shows them side by side without the editor's styles; on a\n * narrow page they wrap, one under the other.\n * Markdown has no columns: their blocks follow one another.\n */\nexport const columnsOutput: Record<string, BlockOutput> = {\n columns: {\n html: (_block, { children }) =>\n `<div data-columns style=\"display: flex; flex-wrap: wrap; gap: 1em 2em\">${children}</div>`,\n markdown: (_block, { children }) => children,\n },\n column: {\n html: (block, { children }) => {\n const width = widthOf(block.props.width)\n const data = width ? ` data-width=\"${width}\"` : ''\n return `<div data-column${data} style=\"flex: ${width ?? 1} 1 0; min-width: min(100%, 12em)\">${children}</div>`\n },\n markdown: (_block, { children }) => children,\n },\n}\n\n/** Back from that HTML: `div[data-columns]` and the `div[data-column]` in it. */\nexport function prepareColumns(root: HTMLElement) {\n const doc = root.ownerDocument\n for (const element of Array.from(root.querySelectorAll('div[data-column]'))) {\n const width = widthOf((element as HTMLElement).dataset.width)\n element.replaceWith(\n blockElement(\n doc,\n 'column',\n [],\n Array.from(element.childNodes),\n width ? { width: String(width) } : {},\n ),\n )\n }\n for (const element of Array.from(root.querySelectorAll('div[data-columns]')))\n element.replaceWith(blockElement(doc, 'columns', [], Array.from(element.childNodes)))\n}\n"],"mappings":";;;;;;;;;AAUA,IAAa,gBAA6C;CACxD,SAAS;EACP,OAAO,QAAQ,EAAE,eACf,0EAA0E,SAAS;EACrF,WAAW,QAAQ,EAAE,eAAe;CACtC;CACA,QAAQ;EACN,OAAO,OAAO,EAAE,eAAe;GAC7B,MAAM,QAAQ,QAAQ,MAAM,MAAM,KAAK;GAEvC,OAAO,mBADM,QAAQ,gBAAgB,MAAM,KAAK,GACjB,gBAAgB,SAAS,EAAE,oCAAoC,SAAS;EACzG;EACA,WAAW,QAAQ,EAAE,eAAe;CACtC;AACF;;AAGA,SAAgB,eAAe,MAAmB;CAChD,MAAM,MAAM,KAAK;CACjB,KAAK,MAAM,WAAW,MAAM,KAAK,KAAK,iBAAiB,kBAAkB,CAAC,GAAG;EAC3E,MAAM,QAAQ,QAAS,QAAwB,QAAQ,KAAK;EAC5D,QAAQ,YACN,aACE,KACA,UACA,CAAC,GACD,MAAM,KAAK,QAAQ,UAAU,GAC7B,QAAQ,EAAE,OAAO,OAAO,KAAK,EAAE,IAAI,CAAC,CACtC,CACF;CACF;CACA,KAAK,MAAM,WAAW,MAAM,KAAK,KAAK,iBAAiB,mBAAmB,CAAC,GACzE,QAAQ,YAAY,aAAa,KAAK,WAAW,CAAC,GAAG,MAAM,KAAK,QAAQ,UAAU,CAAC,CAAC;AACxF"}
|