@dou-ui/editor 0.1.0-alpha.2 → 0.1.0-alpha.20
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/code/code-editor-block.js.map +1 -1
- package/dist/code/code-editor-block.vue_vue_type_script_setup_true_lang.js +1 -0
- package/dist/code/code-editor-block.vue_vue_type_script_setup_true_lang.js.map +1 -1
- 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 +125 -17
- package/dist/components/block-handle.vue_vue_type_script_setup_true_lang.js.map +1 -1
- package/dist/components/bubble-toolbar.js.map +1 -1
- package/dist/components/bubble-toolbar.vue_vue_type_script_setup_true_lang.js +2 -1
- package/dist/components/bubble-toolbar.vue_vue_type_script_setup_true_lang.js.map +1 -1
- package/dist/components/comment-card.js.map +1 -1
- package/dist/components/comment-card.vue_vue_type_script_setup_true_lang.js +2 -1
- package/dist/components/comment-card.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/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/editor.js +2 -1
- package/dist/core/editor.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/plugins.js +108 -5
- package/dist/core/plugins.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 +112 -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 +3 -3
- package/dist/editor.vue_vue_type_script_setup_true_lang.js.map +1 -1
- package/dist/editor2.js.map +1 -1
- package/dist/extensions/align/align-menu.js.map +1 -1
- package/dist/extensions/align/align-menu.vue_vue_type_script_setup_true_lang.js +4 -6
- package/dist/extensions/align/align-menu.vue_vue_type_script_setup_true_lang.js.map +1 -1
- package/dist/extensions/callout/html.js +5 -4
- package/dist/extensions/callout/html.js.map +1 -1
- package/dist/extensions/colors/color-menu.js.map +1 -1
- package/dist/extensions/colors/color-menu.vue_vue_type_script_setup_true_lang.js +6 -8
- package/dist/extensions/colors/color-menu.vue_vue_type_script_setup_true_lang.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/table-controls.js.map +1 -1
- package/dist/extensions/table/table-controls.vue_vue_type_script_setup_true_lang.js +1 -1
- package/dist/extensions/table/table-controls.vue_vue_type_script_setup_true_lang.js.map +1 -1
- package/dist/extensions/table/view.js +25 -1
- 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/index.js +2 -2
- package/dist/markdown/index.js.map +1 -1
- package/dist/style.css +1 -1
- package/dist/style.js +2 -1
- 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/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/plugins.d.ts +9 -0
- 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 +43 -4
- package/dist/types/editor.d.ts +9 -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 +8 -1
- 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/index.d.ts +8 -1
- package/dist/use-comments.js +2 -2
- package/dist/use-comments.js.map +1 -1
- package/package.json +14 -5
|
@@ -2,9 +2,12 @@ import { labelOf } from "../core/extension.js";
|
|
|
2
2
|
import { filterOptions } from "../catalog.js";
|
|
3
3
|
import { insertBlockAfter, setBlockType } from "../core/commands.js";
|
|
4
4
|
import { slashKey } from "../core/slash.js";
|
|
5
|
+
import { scrollParent } from "../dom.js";
|
|
5
6
|
import { editorKey } from "../editor.js";
|
|
7
|
+
import slash_choices_default from "./slash-choices.js";
|
|
6
8
|
import { isComposing, useFloating, useLayer, useZIndex } from "dou-ui";
|
|
7
|
-
import { Fragment, Transition, computed, createBlock, createCommentVNode, createElementBlock, createElementVNode, defineComponent, inject, nextTick, normalizeClass, normalizeStyle, openBlock, renderList, resolveDynamicComponent, shallowRef, toDisplayString, unref, useId, useTemplateRef, watch, withCtx, withModifiers } from "vue";
|
|
9
|
+
import { Fragment, Transition, computed, createBlock, createCommentVNode, createElementBlock, createElementVNode, createVNode, defineComponent, inject, nextTick, normalizeClass, normalizeStyle, openBlock, renderList, resolveDynamicComponent, shallowRef, toDisplayString, unref, useId, useTemplateRef, watch, withCtx, withModifiers } from "vue";
|
|
10
|
+
import { ChevronRightIcon } from "@dou-ui/icons";
|
|
8
11
|
// src/components/slash-menu.vue?vue&type=script&setup=true&lang.ts
|
|
9
12
|
var _hoisted_1 = ["aria-label", "data-placement"];
|
|
10
13
|
var _hoisted_2 = [
|
|
@@ -24,21 +27,61 @@ var _hoisted_7 = {
|
|
|
24
27
|
key: 0,
|
|
25
28
|
class: "dou-editor-slash__shortcut"
|
|
26
29
|
};
|
|
27
|
-
var _hoisted_8 =
|
|
30
|
+
var _hoisted_8 = ["aria-label"];
|
|
31
|
+
var _hoisted_9 = {
|
|
28
32
|
key: 0,
|
|
29
33
|
class: "dou-editor-slash__empty"
|
|
30
34
|
};
|
|
35
|
+
var _hoisted_10 = [
|
|
36
|
+
"id",
|
|
37
|
+
"aria-label",
|
|
38
|
+
"data-placement"
|
|
39
|
+
];
|
|
31
40
|
var slash_menu_vue_vue_type_script_setup_true_lang_default = /*@__PURE__*/ defineComponent({
|
|
32
41
|
__name: "slash-menu",
|
|
33
42
|
props: { slash: {} },
|
|
34
43
|
setup(__props, { expose: __expose }) {
|
|
35
44
|
const props = __props;
|
|
36
|
-
const { view, messages, kit } = inject(editorKey);
|
|
45
|
+
const { view, state, messages, kit } = inject(editorKey);
|
|
37
46
|
const id = `dou-editor-slash-${useId()}`;
|
|
38
47
|
const panel = useTemplateRef("panel");
|
|
48
|
+
const choicePanel = useTemplateRef("choicePanel");
|
|
39
49
|
const active = shallowRef(0);
|
|
40
|
-
|
|
50
|
+
/**
|
|
51
|
+
* The highlighted variant of the active option, when it has some (e.g. how
|
|
52
|
+
* many columns); -1 while the option itself is highlighted, which inserts
|
|
53
|
+
* the first variant.
|
|
54
|
+
*/
|
|
55
|
+
const choice = shallowRef(-1);
|
|
56
|
+
/**
|
|
57
|
+
* With a coarse pointer (a phone), the variants unfold in the menu under
|
|
58
|
+
* their option, once it is tapped, instead of in a panel beside it that
|
|
59
|
+
* would cover the menu on a narrow screen. Read when the menu opens.
|
|
60
|
+
*/
|
|
61
|
+
const coarse = shallowRef(false);
|
|
62
|
+
/** The option whose variants are unfolded in the menu, or -1. */
|
|
63
|
+
const unfolded = shallowRef(-1);
|
|
64
|
+
const options = computed(() => {
|
|
65
|
+
if (!props.slash) return [];
|
|
66
|
+
const current = state.value;
|
|
67
|
+
const usable = current ? kit.blockOptions.filter((option) => setBlockType(option.type, option.props)(current)) : kit.blockOptions;
|
|
68
|
+
return filterOptions(usable, props.slash.query, messages.value);
|
|
69
|
+
});
|
|
41
70
|
const open = computed(() => !!props.slash);
|
|
71
|
+
const activeOption = computed(() => options.value[active.value]);
|
|
72
|
+
const activeChoices = computed(() => open.value ? activeOption.value?.choices : void 0);
|
|
73
|
+
/** The variants in the panel beside the menu. */
|
|
74
|
+
const choices = computed(() => coarse.value ? void 0 : activeChoices.value);
|
|
75
|
+
/** The variants unfolded in the menu, or shown beside it: where the keys pick from. */
|
|
76
|
+
const shownChoices = computed(() => coarse.value ? unfolded.value === active.value ? activeChoices.value : void 0 : choices.value);
|
|
77
|
+
watch(activeOption, () => {
|
|
78
|
+
if (unfolded.value === active.value) return;
|
|
79
|
+
choice.value = -1;
|
|
80
|
+
unfolded.value = -1;
|
|
81
|
+
});
|
|
82
|
+
watch(open, (value) => {
|
|
83
|
+
if (value) coarse.value = window.matchMedia?.("(pointer: coarse)").matches ?? false;
|
|
84
|
+
});
|
|
42
85
|
const anchor = { getBoundingClientRect() {
|
|
43
86
|
const current = view.value;
|
|
44
87
|
const from = props.slash?.from;
|
|
@@ -51,12 +94,23 @@ var slash_menu_vue_vue_type_script_setup_true_lang_default = /*@__PURE__*/ defin
|
|
|
51
94
|
placement: "bottom-start",
|
|
52
95
|
offset: 6
|
|
53
96
|
});
|
|
97
|
+
const activeItem = () => choices.value ? document.getElementById(`${id}-${active.value}`) : null;
|
|
98
|
+
const { style: choiceStyle, placement: choicePlacement, update: updateChoices } = useFloating(activeItem, choicePanel, {
|
|
99
|
+
open: () => !!choices.value,
|
|
100
|
+
placement: "right-start",
|
|
101
|
+
offset: 4
|
|
102
|
+
});
|
|
103
|
+
watch([choices, active], () => void nextTick(updateChoices), { flush: "post" });
|
|
54
104
|
const { next } = useZIndex();
|
|
55
105
|
const zIndex = shallowRef(0);
|
|
56
106
|
watch(open, (value) => value && (zIndex.value = next()), { immediate: true });
|
|
57
107
|
useLayer({
|
|
58
108
|
open,
|
|
59
|
-
elements: () => [
|
|
109
|
+
elements: () => [
|
|
110
|
+
panel.value,
|
|
111
|
+
choicePanel.value,
|
|
112
|
+
view.value?.dom
|
|
113
|
+
],
|
|
60
114
|
onOutside: () => close(),
|
|
61
115
|
onEscape: () => close()
|
|
62
116
|
});
|
|
@@ -67,13 +121,15 @@ var slash_menu_vue_vue_type_script_setup_true_lang_default = /*@__PURE__*/ defin
|
|
|
67
121
|
watch([
|
|
68
122
|
open,
|
|
69
123
|
active,
|
|
70
|
-
options
|
|
124
|
+
options,
|
|
125
|
+
choice,
|
|
126
|
+
shownChoices
|
|
71
127
|
], () => {
|
|
72
128
|
const dom = view.value?.dom;
|
|
73
129
|
if (!dom) return;
|
|
74
|
-
const option = open.value && options.value.length ? `${id}-${active.value}` : null;
|
|
130
|
+
const option = open.value && options.value.length ? shownChoices.value && choice.value >= 0 ? `${id}-choice-${choice.value}` : `${id}-${active.value}` : null;
|
|
75
131
|
if (open.value) {
|
|
76
|
-
dom.setAttribute("aria-controls", id);
|
|
132
|
+
dom.setAttribute("aria-controls", choices.value ? `${id} ${id}-choices` : id);
|
|
77
133
|
dom.setAttribute("aria-expanded", "true");
|
|
78
134
|
} else {
|
|
79
135
|
dom.removeAttribute("aria-controls");
|
|
@@ -83,15 +139,60 @@ var slash_menu_vue_vue_type_script_setup_true_lang_default = /*@__PURE__*/ defin
|
|
|
83
139
|
else dom.removeAttribute("aria-activedescendant");
|
|
84
140
|
if (option) document.getElementById(option)?.scrollIntoView({ block: "nearest" });
|
|
85
141
|
}, { flush: "post" });
|
|
86
|
-
|
|
142
|
+
/** On a touch screen, the first tap on an option with variants only shows them. */
|
|
143
|
+
let touched = false;
|
|
144
|
+
const onItemPointer = (event) => touched = event.pointerType !== "mouse";
|
|
145
|
+
function onItemMove(event, index) {
|
|
146
|
+
if (event.pointerType === "touch") return;
|
|
147
|
+
active.value = index;
|
|
148
|
+
choice.value = -1;
|
|
149
|
+
}
|
|
150
|
+
/**
|
|
151
|
+
* On a phone: the variants under option `index`, the first one lit (what
|
|
152
|
+
* a tap on the option inserts), and in sight, the page scrolled up when
|
|
153
|
+
* the menu has no room left below.
|
|
154
|
+
*/
|
|
155
|
+
function unfold(index) {
|
|
156
|
+
active.value = index;
|
|
157
|
+
unfolded.value = index;
|
|
158
|
+
choice.value = 0;
|
|
159
|
+
nextTick(() => {
|
|
160
|
+
const menu = panel.value;
|
|
161
|
+
const group = menu?.querySelector(".dou-editor-slash__unfolded");
|
|
162
|
+
const dom = view.value?.dom;
|
|
163
|
+
if (!menu || !group || !dom) return;
|
|
164
|
+
const hidden = menu.scrollHeight - menu.clientHeight;
|
|
165
|
+
if (hidden > 0) {
|
|
166
|
+
const scroller = scrollParent(dom);
|
|
167
|
+
if (scroller) scroller.scrollBy({ top: hidden });
|
|
168
|
+
else window.scrollBy({ top: hidden });
|
|
169
|
+
}
|
|
170
|
+
requestAnimationFrame(() => {
|
|
171
|
+
update();
|
|
172
|
+
requestAnimationFrame(() => group.scrollIntoView({ block: "nearest" }));
|
|
173
|
+
});
|
|
174
|
+
});
|
|
175
|
+
}
|
|
176
|
+
function onItemClick(option, index) {
|
|
177
|
+
if (option.choices && (coarse.value || touched) && unfolded.value !== index) {
|
|
178
|
+
unfold(index);
|
|
179
|
+
return;
|
|
180
|
+
}
|
|
181
|
+
choose(option);
|
|
182
|
+
}
|
|
183
|
+
function choose(option, variant = option.choices ? Math.max(0, choice.value) : -1) {
|
|
87
184
|
const current = view.value;
|
|
88
185
|
const slash = props.slash;
|
|
89
186
|
if (!current || !slash) return;
|
|
187
|
+
const chosen = {
|
|
188
|
+
...option.props,
|
|
189
|
+
...option.choices?.items[variant]?.props
|
|
190
|
+
};
|
|
90
191
|
const removed = current.state.tr.delete(slash.from, current.state.selection.from);
|
|
91
192
|
current.dispatch(removed.setMeta(slashKey, null));
|
|
92
193
|
const { $from } = current.state.selection;
|
|
93
194
|
if ($from.parent.content.size > 0) insertBlockAfter($from.pos)(current.state, current.dispatch);
|
|
94
|
-
if (option.type !== "paragraph" || $from.parent.content.size === 0) setBlockType(option.type,
|
|
195
|
+
if (option.type !== "paragraph" || $from.parent.content.size === 0) setBlockType(option.type, chosen)(current.state, current.dispatch);
|
|
95
196
|
current.focus();
|
|
96
197
|
}
|
|
97
198
|
function close() {
|
|
@@ -108,6 +209,21 @@ var slash_menu_vue_vue_type_script_setup_true_lang_default = /*@__PURE__*/ defin
|
|
|
108
209
|
if (!count) return false;
|
|
109
210
|
active.value = (active.value + (event.key === "ArrowDown" ? 1 : -1) + count) % count;
|
|
110
211
|
return true;
|
|
212
|
+
case "ArrowRight": {
|
|
213
|
+
const items = activeChoices.value?.items;
|
|
214
|
+
if (!items) return false;
|
|
215
|
+
if (coarse.value && unfolded.value !== active.value) {
|
|
216
|
+
unfold(active.value);
|
|
217
|
+
return true;
|
|
218
|
+
}
|
|
219
|
+
if (choice.value >= items.length - 1) return false;
|
|
220
|
+
choice.value++;
|
|
221
|
+
return true;
|
|
222
|
+
}
|
|
223
|
+
case "ArrowLeft":
|
|
224
|
+
if (!activeChoices.value || choice.value < 0) return false;
|
|
225
|
+
choice.value--;
|
|
226
|
+
return true;
|
|
111
227
|
case "Enter":
|
|
112
228
|
case "Tab": {
|
|
113
229
|
const option = options.value[active.value];
|
|
@@ -123,7 +239,7 @@ var slash_menu_vue_vue_type_script_setup_true_lang_default = /*@__PURE__*/ defin
|
|
|
123
239
|
}
|
|
124
240
|
__expose({ onKey });
|
|
125
241
|
return (_ctx, _cache) => {
|
|
126
|
-
return openBlock(),
|
|
242
|
+
return openBlock(), createElementBlock(Fragment, null, [createVNode(Transition, { name: "dou-floating" }, {
|
|
127
243
|
default: withCtx(() => [open.value ? (openBlock(), createElementBlock("div", {
|
|
128
244
|
key: 0,
|
|
129
245
|
id,
|
|
@@ -134,11 +250,10 @@ var slash_menu_vue_vue_type_script_setup_true_lang_default = /*@__PURE__*/ defin
|
|
|
134
250
|
class: "dou-dropdown dou-floating dou-editor-slash",
|
|
135
251
|
style: normalizeStyle([unref(style), { zIndex: zIndex.value }]),
|
|
136
252
|
"data-placement": unref(placement),
|
|
137
|
-
onMousedown: _cache[
|
|
253
|
+
onMousedown: _cache[1] || (_cache[1] = withModifiers(() => {}, ["prevent"]))
|
|
138
254
|
}, [(openBlock(true), createElementBlock(Fragment, null, renderList(options.value, (option, index) => {
|
|
139
|
-
return openBlock(), createElementBlock("div", {
|
|
255
|
+
return openBlock(), createElementBlock(Fragment, { key: option.key }, [createElementVNode("div", {
|
|
140
256
|
id: `${id}-${index}`,
|
|
141
|
-
key: option.key,
|
|
142
257
|
role: "option",
|
|
143
258
|
"aria-selected": index === active.value,
|
|
144
259
|
class: normalizeClass([
|
|
@@ -146,16 +261,66 @@ var slash_menu_vue_vue_type_script_setup_true_lang_default = /*@__PURE__*/ defin
|
|
|
146
261
|
"dou-editor-slash__item",
|
|
147
262
|
{ "is-active": index === active.value }
|
|
148
263
|
]),
|
|
149
|
-
|
|
150
|
-
|
|
264
|
+
onPointerdown: onItemPointer,
|
|
265
|
+
onPointermove: ($event) => onItemMove($event, index),
|
|
266
|
+
onClick: ($event) => onItemClick(option, index)
|
|
151
267
|
}, [
|
|
152
268
|
createElementVNode("span", _hoisted_3, [(openBlock(), createBlock(resolveDynamicComponent(option.icon)))]),
|
|
153
269
|
createElementVNode("span", _hoisted_4, [createElementVNode("span", _hoisted_5, toDisplayString(unref(labelOf)(option.label, unref(messages))), 1), option.hint ? (openBlock(), createElementBlock("span", _hoisted_6, toDisplayString(unref(labelOf)(option.hint, unref(messages))), 1)) : createCommentVNode("", true)]),
|
|
154
|
-
option.shortcut ? (openBlock(), createElementBlock("kbd", _hoisted_7, toDisplayString(option.shortcut), 1)) : createCommentVNode("", true)
|
|
155
|
-
|
|
156
|
-
|
|
270
|
+
option.shortcut ? (openBlock(), createElementBlock("kbd", _hoisted_7, toDisplayString(option.shortcut), 1)) : createCommentVNode("", true),
|
|
271
|
+
option.choices ? (openBlock(), createBlock(unref(ChevronRightIcon), {
|
|
272
|
+
key: 1,
|
|
273
|
+
class: normalizeClass(["dou-editor-slash__more", { "is-unfolded": coarse.value && unfolded.value === index }]),
|
|
274
|
+
"aria-hidden": "true"
|
|
275
|
+
}, null, 8, ["class"])) : createCommentVNode("", true)
|
|
276
|
+
], 42, _hoisted_2), option.choices && coarse.value && unfolded.value === index ? (openBlock(), createElementBlock("div", {
|
|
277
|
+
key: 0,
|
|
278
|
+
role: "group",
|
|
279
|
+
"aria-label": unref(labelOf)(option.choices.title, unref(messages)),
|
|
280
|
+
class: "dou-editor-slash__unfolded"
|
|
281
|
+
}, [createVNode(slash_choices_default, {
|
|
282
|
+
choices: option.choices,
|
|
283
|
+
active: choice.value,
|
|
284
|
+
messages: unref(messages),
|
|
285
|
+
"id-prefix": `${id}-choice`,
|
|
286
|
+
onHover: _cache[0] || (_cache[0] = ($event) => choice.value = $event),
|
|
287
|
+
onChoose: ($event) => choose(option, $event)
|
|
288
|
+
}, null, 8, [
|
|
289
|
+
"choices",
|
|
290
|
+
"active",
|
|
291
|
+
"messages",
|
|
292
|
+
"id-prefix",
|
|
293
|
+
"onChoose"
|
|
294
|
+
])], 8, _hoisted_8)) : createCommentVNode("", true)], 64);
|
|
295
|
+
}), 128)), !options.value.length ? (openBlock(), createElementBlock("div", _hoisted_9, toDisplayString(unref(messages).noResults), 1)) : createCommentVNode("", true)], 44, _hoisted_1)) : createCommentVNode("", true)]),
|
|
157
296
|
_: 1
|
|
158
|
-
})
|
|
297
|
+
}), createVNode(Transition, { name: "dou-floating" }, {
|
|
298
|
+
default: withCtx(() => [choices.value && activeOption.value ? (openBlock(), createElementBlock("div", {
|
|
299
|
+
key: 0,
|
|
300
|
+
id: `${id}-choices`,
|
|
301
|
+
ref_key: "choicePanel",
|
|
302
|
+
ref: choicePanel,
|
|
303
|
+
role: "listbox",
|
|
304
|
+
"aria-label": unref(labelOf)(choices.value.title, unref(messages)),
|
|
305
|
+
class: "dou-dropdown dou-floating dou-editor-slash__choices",
|
|
306
|
+
style: normalizeStyle([unref(choiceStyle), { zIndex: zIndex.value }]),
|
|
307
|
+
"data-placement": unref(choicePlacement),
|
|
308
|
+
onMousedown: _cache[4] || (_cache[4] = withModifiers(() => {}, ["prevent"]))
|
|
309
|
+
}, [createVNode(slash_choices_default, {
|
|
310
|
+
choices: choices.value,
|
|
311
|
+
active: choice.value,
|
|
312
|
+
messages: unref(messages),
|
|
313
|
+
"id-prefix": `${id}-choice`,
|
|
314
|
+
onHover: _cache[2] || (_cache[2] = ($event) => choice.value = $event),
|
|
315
|
+
onChoose: _cache[3] || (_cache[3] = ($event) => choose(activeOption.value, $event))
|
|
316
|
+
}, null, 8, [
|
|
317
|
+
"choices",
|
|
318
|
+
"active",
|
|
319
|
+
"messages",
|
|
320
|
+
"id-prefix"
|
|
321
|
+
])], 44, _hoisted_10)) : createCommentVNode("", true)]),
|
|
322
|
+
_: 1
|
|
323
|
+
})], 64);
|
|
159
324
|
};
|
|
160
325
|
}
|
|
161
326
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"slash-menu.vue_vue_type_script_setup_true_lang.js","names":["_openBlock","_createBlock","_Transition","_withCtx","_createElementBlock","_unref","_normalizeStyle","_withModifiers","_Fragment","_renderList","_normalizeClass","_createElementVNode","_resolveDynamicComponent","_toDisplayString","_createCommentVNode"],"sources":["../../src/components/slash-menu.vue"],"sourcesContent":["<script setup lang=\"ts\">\nimport { isComposing, useFloating, useLayer, useZIndex, type VirtualElement } from 'dou-ui'\nimport { computed, inject, nextTick, shallowRef, useId, useTemplateRef, watch } from 'vue'\nimport { filterOptions } from '../catalog'\nimport { labelOf, type BlockOption } from '../core/extension'\nimport { insertBlockAfter, setBlockType } from '../core/commands'\nimport { slashKey, type SlashState } from '../core/slash'\nimport { editorKey } from '../editor'\n\nconst props = defineProps<{ slash: SlashState | null }>()\n\nconst { view, messages, kit } = inject(editorKey)!\nconst id = `dou-editor-slash-${useId()}`\nconst panel = useTemplateRef<HTMLElement>('panel')\nconst active = shallowRef(0)\n\nconst options = computed(() =>\n props.slash ? filterOptions(kit.blockOptions, props.slash.query, messages.value) : [],\n)\nconst open = computed(() => !!props.slash)\n\n// the menu hangs below the `/` that opened it\nconst anchor: VirtualElement = {\n getBoundingClientRect() {\n const current = view.value\n const from = props.slash?.from\n if (!current || from === undefined) return new DOMRect()\n const { left, top, bottom } = current.coordsAtPos(from)\n return new DOMRect(left, top, 0, bottom - top)\n },\n}\nconst { style, placement, update } = useFloating(() => (open.value ? anchor : null), panel, {\n open,\n placement: 'bottom-start',\n offset: 6,\n})\n// stacked like DouUI's own popups, above whatever opened before\nconst { next } = useZIndex()\nconst zIndex = shallowRef(0)\nwatch(open, (value) => value && (zIndex.value = next()), { immediate: true })\n// a press outside the editor and the menu closes it; inside, the cursor move does\nuseLayer({\n open,\n elements: () => [panel.value, view.value?.dom],\n onOutside: () => close(),\n onEscape: () => close(),\n})\n\nwatch(\n () => props.slash?.query,\n () => {\n active.value = 0\n void nextTick(update)\n },\n)\n\n// the editor keeps focus; the active option is announced through it\nwatch(\n [open, active, options],\n () => {\n const dom = view.value?.dom\n if (!dom) return\n const option = open.value && options.value.length ? `${id}-${active.value}` : null\n if (open.value) {\n dom.setAttribute('aria-controls', id)\n dom.setAttribute('aria-expanded', 'true')\n } else {\n dom.removeAttribute('aria-controls')\n dom.removeAttribute('aria-expanded')\n }\n if (option) dom.setAttribute('aria-activedescendant', option)\n else dom.removeAttribute('aria-activedescendant')\n if (option) document.getElementById(option)?.scrollIntoView({ block: 'nearest' })\n },\n { flush: 'post' },\n)\n\nfunction choose(option: BlockOption) {\n const current = view.value\n const slash = props.slash\n if (!current || !slash) return\n // remove the `/query`, then turn the block, or add one below when it has text\n const removed = current.state.tr.delete(slash.from, current.state.selection.from)\n current.dispatch(removed.setMeta(slashKey, null))\n const { $from } = current.state.selection\n if ($from.parent.content.size > 0) insertBlockAfter($from.pos)(current.state, current.dispatch)\n if (option.type !== 'paragraph' || $from.parent.content.size === 0)\n setBlockType(option.type, option.props)(current.state, current.dispatch)\n current.focus()\n}\n\nfunction close() {\n const current = view.value\n if (current) current.dispatch(current.state.tr.setMeta(slashKey, null))\n}\n\n/** Keys the editor passes on while the menu is open. */\nfunction onKey(event: KeyboardEvent): boolean {\n if (isComposing(event)) return false\n const count = options.value.length\n switch (event.key) {\n case 'ArrowDown':\n case 'ArrowUp':\n if (!count) return false\n active.value = (active.value + (event.key === 'ArrowDown' ? 1 : -1) + count) % count\n return true\n case 'Enter':\n case 'Tab': {\n const option = options.value[active.value]\n if (!option) {\n close()\n return false\n }\n choose(option)\n return true\n }\n default:\n return false\n }\n}\n\ndefineExpose({ onKey })\n</script>\n\n<template>\n <Transition name=\"dou-floating\">\n <div\n v-if=\"open\"\n :id=\"id\"\n ref=\"panel\"\n role=\"listbox\"\n :aria-label=\"messages.blockTypes\"\n class=\"dou-dropdown dou-floating dou-editor-slash\"\n :style=\"[style, { zIndex }]\"\n :data-placement=\"placement\"\n @mousedown.prevent\n >\n <div\n v-for=\"(option, index) in options\"\n :id=\"`${id}-${index}`\"\n :key=\"option.key\"\n role=\"option\"\n :aria-selected=\"index === active\"\n :class=\"['dou-dropdown__item', 'dou-editor-slash__item', { 'is-active': index === active }]\"\n @pointermove=\"active = index\"\n @click=\"choose(option)\"\n >\n <span class=\"dou-editor-slash__icon\"><component :is=\"option.icon\" /></span>\n <span class=\"dou-editor-slash__text\">\n <span class=\"dou-editor-slash__label\">{{ labelOf(option.label, messages) }}</span>\n <span v-if=\"option.hint\" class=\"dou-editor-slash__hint\">{{\n labelOf(option.hint, messages)\n }}</span>\n </span>\n <kbd v-if=\"option.shortcut\" class=\"dou-editor-slash__shortcut\">{{ option.shortcut }}</kbd>\n </div>\n <div v-if=\"!options.length\" class=\"dou-editor-slash__empty\">{{ messages.noResults }}</div>\n </div>\n </Transition>\n</template>\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EASA,MAAM,QAAQ;EAEd,MAAM,EAAE,MAAM,U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BADPR,MAAA,OAAA,CAAO,CAAC,OAAO,MAAMA,MAAA,QAAA,CAAQ,CAAA,GAAA,CAAA,K;MAGtB,OAAO,YAAlBL,UAAA,GAAAI,mBAA0F,OAA1F,YAA0FS,gBAAxB,OAAO,QAAQ,GAAA,CAAA,K;;I,WAEvE,CAAA,QAAA,MAAQ,UAApBb,UAAA,GAAAI,mBAA0F,OAA1F,YAA0FS,gBAA3BR,MAAA,QAAA,CAAQ,CAAC,SAAS,GAAA,CAAA,K"}
|
|
1
|
+
{"version":3,"file":"slash-menu.vue_vue_type_script_setup_true_lang.js","names":["_openBlock","_createElementBlock","_Fragment","_createVNode","_Transition","_withCtx","_unref","_normalizeStyle","_withModifiers","_renderList","_createElementVNode","_normalizeClass","_createBlock","_resolveDynamicComponent","_toDisplayString","_createCommentVNode","SlashChoices"],"sources":["../../src/components/slash-menu.vue"],"sourcesContent":["<script setup lang=\"ts\">\nimport { ChevronRightIcon } from '@dou-ui/icons'\nimport { isComposing, useFloating, useLayer, useZIndex, type VirtualElement } from 'dou-ui'\nimport { computed, inject, nextTick, shallowRef, useId, useTemplateRef, watch } from 'vue'\nimport { filterOptions } from '../catalog'\nimport { labelOf, type BlockOption } from '../core/extension'\nimport SlashChoices from './slash-choices.vue'\nimport { insertBlockAfter, setBlockType } from '../core/commands'\nimport { slashKey, type SlashState } from '../core/slash'\nimport { scrollParent } from '../dom'\nimport { editorKey } from '../editor'\n\nconst props = defineProps<{ slash: SlashState | null }>()\n\nconst { view, state, messages, kit } = inject(editorKey)!\nconst id = `dou-editor-slash-${useId()}`\nconst panel = useTemplateRef<HTMLElement>('panel')\nconst choicePanel = useTemplateRef<HTMLElement>('choicePanel')\nconst active = shallowRef(0)\n/**\n * The highlighted variant of the active option, when it has some (e.g. how\n * many columns); -1 while the option itself is highlighted, which inserts\n * the first variant.\n */\nconst choice = shallowRef(-1)\n/**\n * With a coarse pointer (a phone), the variants unfold in the menu under\n * their option, once it is tapped, instead of in a panel beside it that\n * would cover the menu on a narrow screen. Read when the menu opens.\n */\nconst coarse = shallowRef(false)\n/** The option whose variants are unfolded in the menu, or -1. */\nconst unfolded = shallowRef(-1)\n\nconst options = computed(() => {\n if (!props.slash) return []\n const current = state.value\n // only what can go here, e.g. no columns in a column\n const usable = current\n ? kit.blockOptions.filter((option) => setBlockType(option.type, option.props)(current))\n : kit.blockOptions\n return filterOptions(usable, props.slash.query, messages.value)\n})\nconst open = computed(() => !!props.slash)\nconst activeOption = computed(() => options.value[active.value])\nconst activeChoices = computed(() => (open.value ? activeOption.value?.choices : undefined))\n/** The variants in the panel beside the menu. */\nconst choices = computed(() => (coarse.value ? undefined : activeChoices.value))\n/** The variants unfolded in the menu, or shown beside it: where the keys pick from. */\nconst shownChoices = computed(() =>\n coarse.value\n ? unfolded.value === active.value\n ? activeChoices.value\n : undefined\n : choices.value,\n)\nwatch(activeOption, () => {\n // an option just unfolded keeps its variants\n if (unfolded.value === active.value) return\n choice.value = -1\n unfolded.value = -1\n})\nwatch(open, (value) => {\n if (value) coarse.value = window.matchMedia?.('(pointer: coarse)').matches ?? false\n})\n\n// the menu hangs below the `/` that opened it\nconst anchor: VirtualElement = {\n getBoundingClientRect() {\n const current = view.value\n const from = props.slash?.from\n if (!current || from === undefined) return new DOMRect()\n const { left, top, bottom } = current.coordsAtPos(from)\n return new DOMRect(left, top, 0, bottom - top)\n },\n}\nconst { style, placement, update } = useFloating(() => (open.value ? anchor : null), panel, {\n open,\n placement: 'bottom-start',\n offset: 6,\n})\n// the variants of the active option, in a panel beside it\nconst activeItem = () => (choices.value ? document.getElementById(`${id}-${active.value}`) : null)\nconst {\n style: choiceStyle,\n placement: choicePlacement,\n update: updateChoices,\n} = useFloating(activeItem, choicePanel, {\n open: () => !!choices.value,\n placement: 'right-start',\n offset: 4,\n})\nwatch([choices, active], () => void nextTick(updateChoices), { flush: 'post' })\n\n// stacked like DouUI's own popups, above whatever opened before\nconst { next } = useZIndex()\nconst zIndex = shallowRef(0)\nwatch(open, (value) => value && (zIndex.value = next()), { immediate: true })\n// a press outside the editor and the menu closes it; inside, the cursor move does\nuseLayer({\n open,\n elements: () => [panel.value, choicePanel.value, view.value?.dom],\n onOutside: () => close(),\n onEscape: () => close(),\n})\n\nwatch(\n () => props.slash?.query,\n () => {\n active.value = 0\n void nextTick(update)\n },\n)\n\n// the editor keeps focus; the active option, or variant, is announced through it\nwatch(\n [open, active, options, choice, shownChoices],\n () => {\n const dom = view.value?.dom\n if (!dom) return\n const option =\n open.value && options.value.length\n ? shownChoices.value && choice.value >= 0\n ? `${id}-choice-${choice.value}`\n : `${id}-${active.value}`\n : null\n if (open.value) {\n dom.setAttribute('aria-controls', choices.value ? `${id} ${id}-choices` : id)\n dom.setAttribute('aria-expanded', 'true')\n } else {\n dom.removeAttribute('aria-controls')\n dom.removeAttribute('aria-expanded')\n }\n if (option) dom.setAttribute('aria-activedescendant', option)\n else dom.removeAttribute('aria-activedescendant')\n if (option) document.getElementById(option)?.scrollIntoView({ block: 'nearest' })\n },\n { flush: 'post' },\n)\n\n/** On a touch screen, the first tap on an option with variants only shows them. */\nlet touched = false\nconst onItemPointer = (event: PointerEvent) => (touched = event.pointerType !== 'mouse')\n\nfunction onItemMove(event: PointerEvent, index: number) {\n if (event.pointerType === 'touch') return\n active.value = index\n // back on the option: clicking it inserts the first variant again\n choice.value = -1\n}\n\n/**\n * On a phone: the variants under option `index`, the first one lit (what\n * a tap on the option inserts), and in sight, the page scrolled up when\n * the menu has no room left below.\n */\nfunction unfold(index: number) {\n active.value = index\n unfolded.value = index\n choice.value = 0\n void nextTick(() => {\n const menu = panel.value\n const group = menu?.querySelector<HTMLElement>('.dou-editor-slash__unfolded')\n const dom = view.value?.dom\n if (!menu || !group || !dom) return\n const hidden = menu.scrollHeight - menu.clientHeight\n if (hidden > 0) {\n const scroller = scrollParent(dom)\n if (scroller) scroller.scrollBy({ top: hidden })\n else window.scrollBy({ top: hidden })\n }\n requestAnimationFrame(() => {\n update()\n requestAnimationFrame(() => group.scrollIntoView({ block: 'nearest' }))\n })\n })\n}\n\nfunction onItemClick(option: BlockOption, index: number) {\n if (option.choices && (coarse.value || touched) && unfolded.value !== index) {\n unfold(index)\n return\n }\n choose(option)\n}\n\nfunction choose(option: BlockOption, variant = option.choices ? Math.max(0, choice.value) : -1) {\n const current = view.value\n const slash = props.slash\n if (!current || !slash) return\n const chosen = { ...option.props, ...option.choices?.items[variant]?.props }\n // remove the `/query`, then turn the block, or add one below when it has text\n const removed = current.state.tr.delete(slash.from, current.state.selection.from)\n current.dispatch(removed.setMeta(slashKey, null))\n const { $from } = current.state.selection\n if ($from.parent.content.size > 0) insertBlockAfter($from.pos)(current.state, current.dispatch)\n if (option.type !== 'paragraph' || $from.parent.content.size === 0)\n setBlockType(option.type, chosen)(current.state, current.dispatch)\n current.focus()\n}\n\nfunction close() {\n const current = view.value\n if (current) current.dispatch(current.state.tr.setMeta(slashKey, null))\n}\n\n/** Keys the editor passes on while the menu is open. */\nfunction onKey(event: KeyboardEvent): boolean {\n if (isComposing(event)) return false\n const count = options.value.length\n switch (event.key) {\n case 'ArrowDown':\n case 'ArrowUp':\n if (!count) return false\n active.value = (active.value + (event.key === 'ArrowDown' ? 1 : -1) + count) % count\n return true\n case 'ArrowRight': {\n const items = activeChoices.value?.items\n if (!items) return false\n if (coarse.value && unfolded.value !== active.value) {\n unfold(active.value)\n return true\n }\n // past the last variant the key moves the cursor again\n if (choice.value >= items.length - 1) return false\n choice.value++\n return true\n }\n case 'ArrowLeft':\n // from the first variant back to the option; on the option the key moves the cursor\n if (!activeChoices.value || choice.value < 0) return false\n choice.value--\n return true\n case 'Enter':\n case 'Tab': {\n const option = options.value[active.value]\n if (!option) {\n close()\n return false\n }\n choose(option)\n return true\n }\n default:\n return false\n }\n}\n\ndefineExpose({ onKey })\n</script>\n\n<template>\n <Transition name=\"dou-floating\">\n <div\n v-if=\"open\"\n :id=\"id\"\n ref=\"panel\"\n role=\"listbox\"\n :aria-label=\"messages.blockTypes\"\n class=\"dou-dropdown dou-floating dou-editor-slash\"\n :style=\"[style, { zIndex }]\"\n :data-placement=\"placement\"\n @mousedown.prevent\n >\n <template v-for=\"(option, index) in options\" :key=\"option.key\">\n <div\n :id=\"`${id}-${index}`\"\n role=\"option\"\n :aria-selected=\"index === active\"\n :class=\"[\n 'dou-dropdown__item',\n 'dou-editor-slash__item',\n { 'is-active': index === active },\n ]\"\n @pointerdown=\"onItemPointer\"\n @pointermove=\"onItemMove($event, index)\"\n @click=\"onItemClick(option, index)\"\n >\n <span class=\"dou-editor-slash__icon\"><component :is=\"option.icon\" /></span>\n <span class=\"dou-editor-slash__text\">\n <span class=\"dou-editor-slash__label\">{{ labelOf(option.label, messages) }}</span>\n <span v-if=\"option.hint\" class=\"dou-editor-slash__hint\">{{\n labelOf(option.hint, messages)\n }}</span>\n </span>\n <kbd v-if=\"option.shortcut\" class=\"dou-editor-slash__shortcut\">{{ option.shortcut }}</kbd>\n <ChevronRightIcon\n v-if=\"option.choices\"\n :class=\"['dou-editor-slash__more', { 'is-unfolded': coarse && unfolded === index }]\"\n aria-hidden=\"true\"\n />\n </div>\n <!-- on a phone: the variants under their option -->\n <div\n v-if=\"option.choices && coarse && unfolded === index\"\n role=\"group\"\n :aria-label=\"labelOf(option.choices.title, messages)\"\n class=\"dou-editor-slash__unfolded\"\n >\n <SlashChoices\n :choices=\"option.choices\"\n :active=\"choice\"\n :messages=\"messages\"\n :id-prefix=\"`${id}-choice`\"\n @hover=\"choice = $event\"\n @choose=\"choose(option, $event)\"\n />\n </div>\n </template>\n <div v-if=\"!options.length\" class=\"dou-editor-slash__empty\">{{ messages.noResults }}</div>\n </div>\n </Transition>\n <Transition name=\"dou-floating\">\n <div\n v-if=\"choices && activeOption\"\n :id=\"`${id}-choices`\"\n ref=\"choicePanel\"\n role=\"listbox\"\n :aria-label=\"labelOf(choices.title, messages)\"\n class=\"dou-dropdown dou-floating dou-editor-slash__choices\"\n :style=\"[choiceStyle, { zIndex }]\"\n :data-placement=\"choicePlacement\"\n @mousedown.prevent\n >\n <SlashChoices\n :choices=\"choices\"\n :active=\"choice\"\n :messages=\"messages\"\n :id-prefix=\"`${id}-choice`\"\n @hover=\"choice = $event\"\n @choose=\"choose(activeOption!, $event)\"\n />\n </div>\n </Transition>\n</template>\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAYA,MAAM,QAAQ;EAEd,MAAM,EAAE,MAAM,OAAO,UAAU,QAAQ,OAAO,SAAS;EACvD,MAAM,KAAK,oBAAoB,MAAM;EACrC,MAAM,QAAQ,eAA4B,OAAO;EACjD,MAAM,cAAc,eAA4B,aAAa;EAC7D,MAAM,SAAS,WAAW,CAAC;;;;;;EAM3B,MAAM,SAAS,WAAW,EAAE;;;;;;EAM5B,MAAM,SAAS,WAAW,KAAK;;EAE/B,MAAM,WAAW,WAAW,EAAE;EAE9B,MAAM,UAAU,eAAe;GAC7B,IAAI,CAAC,MAAM,OAAO,OAAO,CAAC;GAC1B,MAAM,UAAU,MAAM;GAEtB,MAAM,SAAS,UACX,IAAI,aAAa,QAAQ,WAAW,aAAa,OAAO,MAAM,OAAO,KAAK,CAAC,CAAC,OAAO,CAAC,IACpF,IAAI;GACR,OAAO,cAAc,QAAQ,MAAM,MAAM,OAAO,SAAS,KAAK;EAChE,CAAC;EACD,MAAM,OAAO,eAAe,CAAC,CAAC,MAAM,KAAK;EACzC,MAAM,eAAe,eAAe,QAAQ,MAAM,OAAO,MAAM;EAC/D,MAAM,gBAAgB,eAAgB,KAAK,QAAQ,aAAa,OAAO,UAAU,KAAA,CAAU;;EAE3F,MAAM,UAAU,eAAgB,OAAO,QAAQ,KAAA,IAAY,cAAc,KAAM;;EAE/E,MAAM,eAAe,eACnB,OAAO,QACH,SAAS,UAAU,OAAO,QACxB,cAAc,QACd,KAAA,IACF,QAAQ,KACd;EACA,MAAM,oBAAoB;GAExB,IAAI,SAAS,UAAU,OAAO,OAAO;GACrC,OAAO,QAAQ;GACf,SAAS,QAAQ;EAC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,IAGrFH,YAqBaC,YAAA,EArBD,MAAK,eAAc,GAAA;IAC7B,SAAAC,cAmBM,CAlBE,QAAA,SAAW,aAAA,SADnBL,UAAA,GAAAC,mBAmBM,OAAA;;KAjBH,IAAE,GAAK,GAAE;KACN,SAAA;KAAJ,KAAI;KACJ,MAAK;KACJ,cAAYK,MAAA,OAAA,CAAO,CAAC,QAAA,MAAQ,OAAOA,MAAA,QAAA,CAAQ;KAC5C,OAAM;KACL,OAAKC,eAAA,CAAGD,MAAA,WAAA,GAAW,EAAA,QAAI,OAAA,MAAM,CAAA,CAAA;KAC7B,kBAAgBA,MAAA,eAAA;KAChB,aAAS,OAAA,OAAA,OAAA,KAAAE,oBAAV,CAAA,GAAkB,CAAA,SAAA,CAAA;I,IAElBL,YAOEa,uBAAA;KANC,SAAS,QAAA;KACT,QAAQ,OAAA;KACR,UAAUV,MAAA,QAAA;KACV,aAAS,GAAK,GAAE;KAChB,SAAK,OAAA,OAAA,OAAA,MAAA,WAAE,OAAA,QAAS;KAChB,UAAM,OAAA,OAAA,OAAA,MAAA,WAAE,OAAO,aAAA,OAAe,MAAM"}
|
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
import { blocksIn, findBlockById, selectedRange, siblingRangeBetween } from "./blocks.js";
|
|
1
|
+
import { blocksIn, findBlockById, layoutOf, parentBlock, selectedRange, siblingRangeBetween } from "./blocks.js";
|
|
2
2
|
import { deleteBlocks, duplicateBlocks, liftBlocks, sinkBlocks, swapBlocks } from "./commands.js";
|
|
3
3
|
import { keydownHandler } from "prosemirror-keymap";
|
|
4
4
|
import { Plugin, PluginKey, TextSelection } from "prosemirror-state";
|
|
5
|
+
import { Fragment, Slice } from "prosemirror-model";
|
|
5
6
|
import { Decoration, DecorationSet } from "prosemirror-view";
|
|
6
7
|
// src/core/block-selection.ts
|
|
7
8
|
var blockSelectionKey = new PluginKey("dou-editor-block-selection");
|
|
@@ -75,7 +76,12 @@ function moveHead(view, direction, extend) {
|
|
|
75
76
|
if (!range) return false;
|
|
76
77
|
const head = findBlockById(state.doc, current.head);
|
|
77
78
|
const index = state.doc.resolve(head.pos).index() + direction;
|
|
78
|
-
if (index < 0 || index >= range.parent.childCount)
|
|
79
|
+
if (index < 0 || index >= range.parent.childCount) {
|
|
80
|
+
const column = parentBlock(state.doc, head);
|
|
81
|
+
const row = column && layoutOf(column.node) === "column" && parentBlock(state.doc, column);
|
|
82
|
+
if (row) selectBlocks(row.node.attrs.id)(state, view.dispatch);
|
|
83
|
+
return true;
|
|
84
|
+
}
|
|
79
85
|
const id = range.parent.child(index).attrs.id;
|
|
80
86
|
return selectBlocks(extend ? current.anchor : id, id)(state, view.dispatch);
|
|
81
87
|
}
|
|
@@ -115,6 +121,24 @@ var blockKeys = keydownHandler({
|
|
|
115
121
|
return true;
|
|
116
122
|
}
|
|
117
123
|
});
|
|
124
|
+
/** Put the selected blocks on the clipboard, and remove them when cutting. */
|
|
125
|
+
function copyBlocks(view, event, cut) {
|
|
126
|
+
const range = blockSelectionRange(view.state);
|
|
127
|
+
const data = event.clipboardData;
|
|
128
|
+
if (!range || !data) return false;
|
|
129
|
+
const blocks = blocksIn(range);
|
|
130
|
+
const slice = new Slice(Fragment.from(blocks.map((block) => block.node)), 0, 0);
|
|
131
|
+
const { dom, text } = view.serializeForClipboard(slice);
|
|
132
|
+
event.preventDefault();
|
|
133
|
+
data.clearData();
|
|
134
|
+
data.setData("text/html", dom.innerHTML);
|
|
135
|
+
data.setData("text/plain", text);
|
|
136
|
+
if (cut && view.editable) {
|
|
137
|
+
const tr = deleteBlocks(view.state.tr, blocks).setMeta(blockSelectionKey, null);
|
|
138
|
+
view.dispatch(tr.scrollIntoView().setMeta("uiEvent", "cut"));
|
|
139
|
+
}
|
|
140
|
+
return true;
|
|
141
|
+
}
|
|
118
142
|
function blockSelectionPlugin() {
|
|
119
143
|
return new Plugin({
|
|
120
144
|
key: blockSelectionKey,
|
|
@@ -123,15 +147,19 @@ function blockSelectionPlugin() {
|
|
|
123
147
|
apply(tr, value) {
|
|
124
148
|
const meta = tr.getMeta(blockSelectionKey);
|
|
125
149
|
if (meta !== void 0) return meta;
|
|
126
|
-
if (value && tr.selectionSet && !tr.docChanged) return null;
|
|
150
|
+
if (value && tr.selectionSet && !tr.docChanged && !tr.getMeta("appendedTransaction")) return null;
|
|
127
151
|
return value;
|
|
128
152
|
}
|
|
129
153
|
},
|
|
130
154
|
props: {
|
|
155
|
+
handleDOMEvents: {
|
|
156
|
+
copy: (view, event) => copyBlocks(view, event, false),
|
|
157
|
+
cut: (view, event) => copyBlocks(view, event, true)
|
|
158
|
+
},
|
|
131
159
|
decorations(state) {
|
|
132
160
|
const range = blockSelectionRange(state);
|
|
133
161
|
if (!range) return null;
|
|
134
|
-
return DecorationSet.create(state.doc, blocksIn(range).map((block) => Decoration.node(block.pos, block.pos + block.node.nodeSize, { class: "is-selected" })));
|
|
162
|
+
return DecorationSet.create(state.doc, blocksIn(range).map((block) => Decoration.node(block.pos, block.pos + block.node.nodeSize, { class: block.node.firstChild?.type.spec.tableRole === "table" ? "is-selected has-table" : "is-selected" })));
|
|
135
163
|
},
|
|
136
164
|
attributes(state) {
|
|
137
165
|
return getBlockSelection(state) ? { class: "is-block-selecting" } : {};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"block-selection.js","names":[],"sources":["../../src/core/block-selection.ts"],"sourcesContent":["import { keydownHandler } from 'prosemirror-keymap'\nimport {\n Plugin,\n PluginKey,\n TextSelection,\n type Command,\n type EditorState,\n type Transaction,\n} from 'prosemirror-state'\nimport { Decoration, DecorationSet, type EditorView } from 'prosemirror-view'\nimport {\n blocksIn,\n findBlockById,\n selectedRange,\n siblingRangeBetween,\n type BlockInfo,\n type SiblingRange,\n} from './blocks'\nimport { duplicateBlocks, liftBlocks, swapBlocks, deleteBlocks, sinkBlocks } from './commands'\n\n/**\n * Whole blocks selected with `Esc` or from the block handle. The selected\n * blocks are siblings, from `anchor` to `head`. Underneath, the editor's\n * own selection spans their text, so copy and cut work as usual; the text\n * highlight is hidden and the blocks are tinted instead.\n */\nexport interface BlockSelection {\n anchor: string\n head: string\n}\n\nexport const blockSelectionKey = new PluginKey<BlockSelection | null>('dou-editor-block-selection')\n\nexport function getBlockSelection(state: EditorState): BlockSelection | null {\n return blockSelectionKey.getState(state) ?? null\n}\n\n/** The blocks of a block selection, or `null` when they can't be found. */\nexport function blockSelectionRange(state: EditorState): SiblingRange | null {\n const current = getBlockSelection(state)\n if (!current) return null\n const anchor = findBlockById(state.doc, current.anchor)\n const head = findBlockById(state.doc, current.head)\n if (!anchor || !head) return null\n const [first, last] = anchor.pos <= head.pos ? [anchor, head] : [head, anchor]\n const range = siblingRangeBetween(state.doc, first.pos + 1, last.pos + 1)\n return range && range.depth === anchor.depth ? range : null\n}\n\n/** Put the editor's own selection over the text of the selected blocks. */\nfunction spanSelection(tr: Transaction, range: SiblingRange) {\n const blocks = blocksIn(range)\n const first = blocks[0]!\n const last = blocks.at(-1)!\n const $from = tr.doc.resolve(first.contentPos + 1)\n const $to = tr.doc.resolve(last.pos + last.node.nodeSize - 1)\n tr.setSelection(TextSelection.between($from, $to))\n}\n\n/** Select whole blocks, from `anchor` to `head` (siblings). */\nexport function selectBlocks(anchor: string, head = anchor): Command {\n return (state, dispatch) => {\n const tr = state.tr.setMeta(blockSelectionKey, { anchor, head })\n const preview = state.apply(tr)\n const range = blockSelectionRange(preview)\n if (!range) return false\n if (dispatch) {\n spanSelection(tr, range)\n tr.setMeta(blockSelectionKey, { anchor, head })\n dispatch(tr.scrollIntoView())\n }\n return true\n }\n}\n\nexport const clearBlockSelection: Command = (state, dispatch) => {\n if (!getBlockSelection(state)) return false\n if (dispatch) dispatch(state.tr.setMeta(blockSelectionKey, null))\n return true\n}\n\n/** `Esc`: select the blocks the cursor or text selection is in. */\nexport const selectCurrentBlocks: Command = (state, dispatch) => {\n if (getBlockSelection(state)) return false\n const range = selectedRange(state)\n if (!range) return false\n const blocks = blocksIn(range)\n return selectBlocks(blocks[0]!.node.attrs.id, blocks.at(-1)!.node.attrs.id)(state, dispatch)\n}\n\n/** Leave the block selection with the cursor at the end of a block. */\nfunction placeCursor(view: EditorView, block: BlockInfo, atEnd = true) {\n const tr = view.state.tr.setMeta(blockSelectionKey, null)\n const pos = atEnd ? block.contentPos + block.content.nodeSize - 1 : block.contentPos + 1\n tr.setSelection(TextSelection.near(tr.doc.resolve(pos), atEnd ? -1 : 1))\n view.dispatch(tr.scrollIntoView())\n}\n\nfunction moveHead(view: EditorView, direction: -1 | 1, extend: boolean) {\n const state = view.state\n const current = getBlockSelection(state)!\n const range = blockSelectionRange(state)\n if (!range) return false\n const head = findBlockById(state.doc, current.head)!\n const $head = state.doc.resolve(head.pos)\n const index = $head.index() + direction\n if (index < 0 || index >= range.parent.childCount) return true\n const id = range.parent.child(index).attrs.id as string\n return selectBlocks(extend ? current.anchor : id, id)(state, view.dispatch)\n}\n\n/** Run a block command, then select the same blocks again. */\nfunction keepSelected(command: Command): (view: EditorView) => boolean {\n return (view) => {\n const current = getBlockSelection(view.state)\n if (!current || !command(view.state, view.dispatch)) return false\n selectBlocks(current.anchor, current.head)(view.state, view.dispatch)\n return true\n }\n}\n\nconst removeSelected = (view: EditorView) => {\n const range = blockSelectionRange(view.state)\n if (!range) return false\n const tr = deleteBlocks(view.state.tr, blocksIn(range)).setMeta(blockSelectionKey, null)\n view.dispatch(tr.scrollIntoView())\n return true\n}\n\nconst blockKeys = keydownHandler({\n ArrowUp: (_state, _dispatch, view) => moveHead(view!, -1, false),\n ArrowDown: (_state, _dispatch, view) => moveHead(view!, 1, false),\n 'Shift-ArrowUp': (_state, _dispatch, view) => moveHead(view!, -1, true),\n 'Shift-ArrowDown': (_state, _dispatch, view) => moveHead(view!, 1, true),\n Backspace: (_state, _dispatch, view) => removeSelected(view!),\n Delete: (_state, _dispatch, view) => removeSelected(view!),\n 'Mod-d': (_state, _dispatch, view) => keepSelected(duplicateBlocks)(view!),\n 'Mod-Shift-ArrowUp': (_state, _dispatch, view) => keepSelected(swapBlocks(-1))(view!),\n 'Mod-Shift-ArrowDown': (_state, _dispatch, view) => keepSelected(swapBlocks(1))(view!),\n Tab: (_state, _dispatch, view) => keepSelected(sinkBlocks)(view!),\n 'Shift-Tab': (_state, _dispatch, view) => keepSelected(liftBlocks)(view!),\n Escape: (state, dispatch) => clearBlockSelection(state, dispatch),\n Enter: (state, _dispatch, view) => {\n const current = getBlockSelection(state)!\n const head = findBlockById(state.doc, current.head)\n if (head) placeCursor(view!, head)\n return true\n },\n})\n\nexport function blockSelectionPlugin(): Plugin<BlockSelection | null> {\n return new Plugin<BlockSelection | null>({\n key: blockSelectionKey,\n state: {\n init: () => null,\n apply(tr, value) {\n const meta = tr.getMeta(blockSelectionKey) as BlockSelection | null | undefined\n if (meta !== undefined) return meta\n // any other selection change (a click, typing) ends it\n if (value && tr.selectionSet && !tr.docChanged) return null\n return value\n },\n },\n props: {\n decorations(state) {\n const range = blockSelectionRange(state)\n if (!range) return null\n return DecorationSet.create(\n state.doc,\n blocksIn(range).map((block) =>\n Decoration.node(block.pos, block.pos + block.node.nodeSize, { class: 'is-selected' }),\n ),\n )\n },\n attributes(state): Record<string, string> {\n return getBlockSelection(state) ? { class: 'is-block-selecting' } : {}\n },\n handleKeyDown(view, event) {\n const current = getBlockSelection(view.state)\n if (!current) return false\n if (blockKeys(view, event)) return true\n // typing a character: back to text editing at the end of the head block\n if (event.key.length === 1 && !event.metaKey && !event.ctrlKey && !event.altKey) {\n const head = findBlockById(view.state.doc, current.head)\n if (head) placeCursor(view, head)\n return false\n }\n return false\n },\n },\n })\n}\n"],"mappings":";;;;;;AA+BA,IAAa,oBAAoB,IAAI,UAAiC,4BAA4B;AAElG,SAAgB,kBAAkB,OAA2C;CAC3E,OAAO,kBAAkB,SAAS,KAAK,KAAK;AAC9C;;AAGA,SAAgB,oBAAoB,OAAyC;CAC3E,MAAM,UAAU,kBAAkB,KAAK;CACvC,IAAI,CAAC,SAAS,OAAO;CACrB,MAAM,SAAS,cAAc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AC;AAED,SAAgB,uBAAsD;CACpE,OAAO,IAAI,OAA8B;EACvC,KAAK;EACL,OAAO;GACL,YAAY;GACZ,MAAM,IAAI,OAAO;IACf,MAAM,OAAO,GAAG,QAAQ,iBAAiB;IACzC,IAAI,SAAS,KAAA,GAAW,OAAO;IAE/B,IAAI,SAAS,GAAG,gBAAgB,CAAC,GAAG,YAAY,OAAO;IACvD,OAAO;GACT;EACF;EACA,OAAO;GACL,YAAY,OAAO;IACjB,MAAM,QAAQ,oBAAoB,KAAK;IACvC,IAAI,CAAC,OAAO,OAAO;IACnB,OAAO,cAAc,OACnB,MAAM,KACN,SAAS,KAAK,CAAC,CAAC,KAAK,UACnB,WAAW,KAAK,MAAM,KAAK,MAAM,MAAM,MAAM,KAAK,UAAU,EAAE,OAAO,cAAc,CAAC,CACtF,CACF;GACF;GACA,WAAW,OAA+B;IACxC,OAAO,kBAAkB,KAAK,IAAI,EAAE,OAAO,qBAAqB,IAAI,CAAC;GACvE;GACA,cAAc,MAAM,OAAO;IACzB,MAAM,UAAU,kBAAkB,KAAK,KAAK;IAC5C,IAAI,CAAC,SAAS,OAAO;IACrB,IAAI,UAAU,MAAM,KAAK,GAAG,OAAO;IAEnC,IAAI,MAAM,IAAI,WAAW,KAAK,CAAC,MAAM,WAAW,CAAC,MAAM,WAAW,CAAC,MAAM,QAAQ;KAC/E,MAAM,OAAO,cAAc,KAAK,MAAM,KAAK,QAAQ,IAAI;KACvD,IAAI,MAAM,YAAY,MAAM,IAAI;KAChC,OAAO;IACT;IACA,OAAO;GACT;EACF;CACF,CAAC;AACH"}
|
|
1
|
+
{"version":3,"file":"block-selection.js","names":[],"sources":["../../src/core/block-selection.ts"],"sourcesContent":["import { keydownHandler } from 'prosemirror-keymap'\nimport { Fragment, Slice } from 'prosemirror-model'\nimport {\n Plugin,\n PluginKey,\n TextSelection,\n type Command,\n type EditorState,\n type Transaction,\n} from 'prosemirror-state'\nimport { Decoration, DecorationSet, type EditorView } from 'prosemirror-view'\nimport {\n blocksIn,\n findBlockById,\n layoutOf,\n parentBlock,\n selectedRange,\n siblingRangeBetween,\n type BlockInfo,\n type SiblingRange,\n} from './blocks'\nimport { duplicateBlocks, liftBlocks, swapBlocks, deleteBlocks, sinkBlocks } from './commands'\n\n/**\n * Whole blocks selected with `Esc` or from the block handle. The selected\n * blocks are siblings, from `anchor` to `head`. Underneath, the editor's\n * own selection spans their text, so copy and cut work as usual; the text\n * highlight is hidden and the blocks are tinted instead.\n */\nexport interface BlockSelection {\n anchor: string\n head: string\n}\n\nexport const blockSelectionKey = new PluginKey<BlockSelection | null>('dou-editor-block-selection')\n\nexport function getBlockSelection(state: EditorState): BlockSelection | null {\n return blockSelectionKey.getState(state) ?? null\n}\n\n/** The blocks of a block selection, or `null` when they can't be found. */\nexport function blockSelectionRange(state: EditorState): SiblingRange | null {\n const current = getBlockSelection(state)\n if (!current) return null\n const anchor = findBlockById(state.doc, current.anchor)\n const head = findBlockById(state.doc, current.head)\n if (!anchor || !head) return null\n const [first, last] = anchor.pos <= head.pos ? [anchor, head] : [head, anchor]\n const range = siblingRangeBetween(state.doc, first.pos + 1, last.pos + 1)\n return range && range.depth === anchor.depth ? range : null\n}\n\n/** Put the editor's own selection over the text of the selected blocks. */\nfunction spanSelection(tr: Transaction, range: SiblingRange) {\n const blocks = blocksIn(range)\n const first = blocks[0]!\n const last = blocks.at(-1)!\n const $from = tr.doc.resolve(first.contentPos + 1)\n const $to = tr.doc.resolve(last.pos + last.node.nodeSize - 1)\n tr.setSelection(TextSelection.between($from, $to))\n}\n\n/** Select whole blocks, from `anchor` to `head` (siblings). */\nexport function selectBlocks(anchor: string, head = anchor): Command {\n return (state, dispatch) => {\n const tr = state.tr.setMeta(blockSelectionKey, { anchor, head })\n const preview = state.apply(tr)\n const range = blockSelectionRange(preview)\n if (!range) return false\n if (dispatch) {\n spanSelection(tr, range)\n tr.setMeta(blockSelectionKey, { anchor, head })\n dispatch(tr.scrollIntoView())\n }\n return true\n }\n}\n\nexport const clearBlockSelection: Command = (state, dispatch) => {\n if (!getBlockSelection(state)) return false\n if (dispatch) dispatch(state.tr.setMeta(blockSelectionKey, null))\n return true\n}\n\n/** `Esc`: select the blocks the cursor or text selection is in. */\nexport const selectCurrentBlocks: Command = (state, dispatch) => {\n if (getBlockSelection(state)) return false\n const range = selectedRange(state)\n if (!range) return false\n const blocks = blocksIn(range)\n return selectBlocks(blocks[0]!.node.attrs.id, blocks.at(-1)!.node.attrs.id)(state, dispatch)\n}\n\n/** Leave the block selection with the cursor at the end of a block. */\nfunction placeCursor(view: EditorView, block: BlockInfo, atEnd = true) {\n const tr = view.state.tr.setMeta(blockSelectionKey, null)\n const pos = atEnd ? block.contentPos + block.content.nodeSize - 1 : block.contentPos + 1\n tr.setSelection(TextSelection.near(tr.doc.resolve(pos), atEnd ? -1 : 1))\n view.dispatch(tr.scrollIntoView())\n}\n\nfunction moveHead(view: EditorView, direction: -1 | 1, extend: boolean) {\n const state = view.state\n const current = getBlockSelection(state)!\n const range = blockSelectionRange(state)\n if (!range) return false\n const head = findBlockById(state.doc, current.head)!\n const $head = state.doc.resolve(head.pos)\n const index = $head.index() + direction\n if (index < 0 || index >= range.parent.childCount) {\n // past the edge of a column: the whole set of columns\n const column = parentBlock(state.doc, head)\n const row = column && layoutOf(column.node) === 'column' && parentBlock(state.doc, column)\n if (row) selectBlocks(row.node.attrs.id as string)(state, view.dispatch)\n return true\n }\n const id = range.parent.child(index).attrs.id as string\n return selectBlocks(extend ? current.anchor : id, id)(state, view.dispatch)\n}\n\n/** Run a block command, then select the same blocks again. */\nfunction keepSelected(command: Command): (view: EditorView) => boolean {\n return (view) => {\n const current = getBlockSelection(view.state)\n if (!current || !command(view.state, view.dispatch)) return false\n selectBlocks(current.anchor, current.head)(view.state, view.dispatch)\n return true\n }\n}\n\nconst removeSelected = (view: EditorView) => {\n const range = blockSelectionRange(view.state)\n if (!range) return false\n const tr = deleteBlocks(view.state.tr, blocksIn(range)).setMeta(blockSelectionKey, null)\n view.dispatch(tr.scrollIntoView())\n return true\n}\n\nconst blockKeys = keydownHandler({\n ArrowUp: (_state, _dispatch, view) => moveHead(view!, -1, false),\n ArrowDown: (_state, _dispatch, view) => moveHead(view!, 1, false),\n 'Shift-ArrowUp': (_state, _dispatch, view) => moveHead(view!, -1, true),\n 'Shift-ArrowDown': (_state, _dispatch, view) => moveHead(view!, 1, true),\n Backspace: (_state, _dispatch, view) => removeSelected(view!),\n Delete: (_state, _dispatch, view) => removeSelected(view!),\n 'Mod-d': (_state, _dispatch, view) => keepSelected(duplicateBlocks)(view!),\n 'Mod-Shift-ArrowUp': (_state, _dispatch, view) => keepSelected(swapBlocks(-1))(view!),\n 'Mod-Shift-ArrowDown': (_state, _dispatch, view) => keepSelected(swapBlocks(1))(view!),\n Tab: (_state, _dispatch, view) => keepSelected(sinkBlocks)(view!),\n 'Shift-Tab': (_state, _dispatch, view) => keepSelected(liftBlocks)(view!),\n Escape: (state, dispatch) => clearBlockSelection(state, dispatch),\n Enter: (state, _dispatch, view) => {\n const current = getBlockSelection(state)!\n const head = findBlockById(state.doc, current.head)\n if (head) placeCursor(view!, head)\n return true\n },\n})\n\n/** Put the selected blocks on the clipboard, and remove them when cutting. */\nfunction copyBlocks(view: EditorView, event: ClipboardEvent, cut: boolean): boolean {\n const range = blockSelectionRange(view.state)\n const data = event.clipboardData\n if (!range || !data) return false\n const blocks = blocksIn(range)\n const slice = new Slice(Fragment.from(blocks.map((block) => block.node)), 0, 0)\n const { dom, text } = view.serializeForClipboard(slice)\n event.preventDefault()\n data.clearData()\n data.setData('text/html', dom.innerHTML)\n data.setData('text/plain', text)\n if (cut && view.editable) {\n const tr = deleteBlocks(view.state.tr, blocks).setMeta(blockSelectionKey, null)\n view.dispatch(tr.scrollIntoView().setMeta('uiEvent', 'cut'))\n }\n return true\n}\n\nexport function blockSelectionPlugin(): Plugin<BlockSelection | null> {\n return new Plugin<BlockSelection | null>({\n key: blockSelectionKey,\n state: {\n init: () => null,\n apply(tr, value) {\n const meta = tr.getMeta(blockSelectionKey) as BlockSelection | null | undefined\n if (meta !== undefined) return meta\n // any other selection change (a click, typing) ends it; not a plugin\n // adjusting the selection under it (a table's turns into cells)\n if (value && tr.selectionSet && !tr.docChanged && !tr.getMeta('appendedTransaction'))\n return null\n return value\n },\n },\n props: {\n // copy and cut take the whole blocks, not the text under them (a\n // table's would be one cell)\n handleDOMEvents: {\n copy: (view, event) => copyBlocks(view, event, false),\n cut: (view, event) => copyBlocks(view, event, true),\n },\n decorations(state) {\n const range = blockSelectionRange(state)\n if (!range) return null\n return DecorationSet.create(\n state.doc,\n blocksIn(range).map((block) =>\n Decoration.node(block.pos, block.pos + block.node.nodeSize, {\n // a top-level table reaches into the margins: its tint goes with it\n class:\n block.node.firstChild?.type.spec.tableRole === 'table'\n ? 'is-selected has-table'\n : 'is-selected',\n }),\n ),\n )\n },\n attributes(state): Record<string, string> {\n return getBlockSelection(state) ? { class: 'is-block-selecting' } : {}\n },\n handleKeyDown(view, event) {\n const current = getBlockSelection(view.state)\n if (!current) return false\n if (blockKeys(view, event)) return true\n // typing a character: back to text editing at the end of the head block\n if (event.key.length === 1 && !event.metaKey && !event.ctrlKey && !event.altKey) {\n const head = findBlockById(view.state.doc, current.head)\n if (head) placeCursor(view, head)\n return false\n }\n return false\n },\n },\n })\n}\n"],"mappings":";;;;;;;AAkCA,IAAa,oBAAoB,IAAI,UAAiC,4BAA4B;AAElG,SAAgB,kBAAkB,OAA2C;CAC3E,OAAO,kBAAkB,SAAS,KAAK,KAAK;AAC9C;;AAGA,SAAgB,oBAAoB,OAAyC;CAC3E,MAAM,UAAU,kBAAkB,KAAK;CACvC,IAAI,CAAC,SAAS,OAAO;CACrB,MAAM,SAAS,cAAc,MAAM,KAAK,QAAQ,MAAM;CACtD,MAAM,OAAO,cAAc,MAAM,KAAK,QAAQ,IAAI;CAClD,IAAI,CAAC,UAAU,CAAC,MAAM,OAAO;CAC7B,MAAM,CAAC,OAAO,QAAQ,OAAO,OAAO,KAAK,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C,CAAC,KAAK,UACnB,WAAW,KAAK,MAAM,KAAK,MAAM,MAAM,MAAM,KAAK,UAAU,EAE1D,OACE,MAAM,KAAK,YAAY,KAAK,KAAK,cAAc,UAC3C,0BACA,cACR,CAAC,CACH,CACF;GACF;GACA,WAAW,OAA+B;IACxC,OAAO,kBAAkB,KAAK,IAAI,EAAE,OAAO,qBAAqB,IAAI,CAAC;GACvE;GACA,cAAc,MAAM,OAAO;IACzB,MAAM,UAAU,kBAAkB,KAAK,KAAK;IAC5C,IAAI,CAAC,SAAS,OAAO;IACrB,IAAI,UAAU,MAAM,KAAK,GAAG,OAAO;IAEnC,IAAI,MAAM,IAAI,WAAW,KAAK,CAAC,MAAM,WAAW,CAAC,MAAM,WAAW,CAAC,MAAM,QAAQ;KAC/E,MAAM,OAAO,cAAc,KAAK,MAAM,KAAK,QAAQ,IAAI;KACvD,IAAI,MAAM,YAAY,MAAM,IAAI;KAChC,OAAO;IACT;IACA,OAAO;GACT;EACF;CACF,CAAC;AACH"}
|
package/dist/core/blocks.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
// src/core/blocks.ts
|
|
2
|
+
var layoutOf = (block) => block?.firstChild?.type.spec.layout;
|
|
2
3
|
function infoAt(node, pos, depth) {
|
|
3
4
|
return {
|
|
4
5
|
node,
|
|
@@ -19,6 +20,12 @@ function blockAround($pos) {
|
|
|
19
20
|
if (after?.type.name === "block") return infoAt(after, $pos.pos, $pos.depth + 1);
|
|
20
21
|
return null;
|
|
21
22
|
}
|
|
23
|
+
/** The block whose children `info` is one of, or `null` at the top level. */
|
|
24
|
+
function parentBlock(doc, info) {
|
|
25
|
+
if (info.depth <= 1) return null;
|
|
26
|
+
const $pos = doc.resolve(info.pos);
|
|
27
|
+
return infoAt($pos.node(info.depth - 2), $pos.before(info.depth - 2), info.depth - 2);
|
|
28
|
+
}
|
|
22
29
|
/** The block with an id, by scanning the document. */
|
|
23
30
|
function findBlockById(doc, id) {
|
|
24
31
|
let found = null;
|
|
@@ -66,6 +73,11 @@ function siblingRangeBetween(doc, from, to) {
|
|
|
66
73
|
if (doc.resolve(a.pos).start() === doc.resolve(b.pos).start()) break;
|
|
67
74
|
depth -= 2;
|
|
68
75
|
}
|
|
76
|
+
if (depth > 1) {
|
|
77
|
+
const $a = doc.resolve(a.pos);
|
|
78
|
+
const owner = $a.node(depth - 2);
|
|
79
|
+
if (layoutOf(owner) === "row") a = b = infoAt(owner, $a.before(depth - 2), depth - 2);
|
|
80
|
+
}
|
|
69
81
|
return rangeOf(doc, a, b);
|
|
70
82
|
}
|
|
71
83
|
function selectedRange(state) {
|
|
@@ -112,7 +124,11 @@ function previousInDocument(doc, info) {
|
|
|
112
124
|
const before = $pos.parent.child(index - 1);
|
|
113
125
|
return lastDescendant(infoAt(before, info.pos - before.nodeSize, info.depth));
|
|
114
126
|
}
|
|
115
|
-
if (info.depth > 1)
|
|
127
|
+
if (info.depth > 1) {
|
|
128
|
+
const parent = $pos.node(info.depth - 2);
|
|
129
|
+
if (layoutOf(parent) === "column") return null;
|
|
130
|
+
return infoAt(parent, $pos.before(info.depth - 2), info.depth - 2);
|
|
131
|
+
}
|
|
116
132
|
return null;
|
|
117
133
|
}
|
|
118
134
|
/** The block that comes after `info` when reading top to bottom. */
|
|
@@ -124,9 +140,11 @@ function nextInDocument(doc, info) {
|
|
|
124
140
|
const end = current.pos + current.node.nodeSize;
|
|
125
141
|
if ($pos.index() < $pos.parent.childCount - 1) return infoAt($pos.parent.child($pos.index() + 1), end, current.depth);
|
|
126
142
|
if (current.depth <= 1) return null;
|
|
127
|
-
|
|
143
|
+
const parent = $pos.node(current.depth - 2);
|
|
144
|
+
if (layoutOf(parent) === "column") return null;
|
|
145
|
+
current = infoAt(parent, $pos.before(current.depth - 2), current.depth - 2);
|
|
128
146
|
}
|
|
129
147
|
}
|
|
130
|
-
export { allBlocks, blockAround, blocksIn, findBlockById, infoAt, lastDescendant, nextInDocument, previousInDocument, selectedRange, siblingRangeBetween };
|
|
148
|
+
export { allBlocks, blockAround, blocksIn, findBlockById, infoAt, lastDescendant, layoutOf, nextInDocument, parentBlock, previousInDocument, selectedRange, siblingRangeBetween };
|
|
131
149
|
|
|
132
150
|
//# sourceMappingURL=blocks.js.map
|
package/dist/core/blocks.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"blocks.js","names":[],"sources":["../../src/core/blocks.ts"],"sourcesContent":["import type { Node as PMNode, ResolvedPos } from 'prosemirror-model'\nimport type { EditorState } from 'prosemirror-state'\n\n/** A `block` node and where it sits. */\nexport interface BlockInfo {\n node: PMNode\n /** The position right before the block. */\n pos: number\n /** Its depth in the document; top-level blocks are at depth 1. */\n depth: number\n /** The block's content node (paragraph, heading, …). */\n content: PMNode\n /** The position right before the content node. */\n contentPos: number\n /** The children, if any. */\n group: PMNode | null\n}\n\nexport function infoAt(node: PMNode, pos: number, depth: number): BlockInfo {\n return {\n node,\n pos,\n depth,\n content: node.firstChild!,\n contentPos: pos + 1,\n group: node.childCount > 1 ? node.child(1) : null,\n }\n}\n\n/** The innermost block around a position, or `null` between blocks. */\nexport function blockAround($pos: ResolvedPos): BlockInfo | null {\n for (let depth = $pos.depth; depth > 0; depth--) {\n const node = $pos.node(depth)\n if (node.type.name === 'block') return infoAt(node, $pos.before(depth), depth)\n }\n // right before a block, e.g. a node selection of it\n const after = $pos.nodeAfter\n if (after?.type.name === 'block') return infoAt(after, $pos.pos, $pos.depth + 1)\n return null\n}\n\n/** The block with an id, by scanning the document. */\nexport function findBlockById(doc: PMNode, id: string): BlockInfo | null {\n let found: BlockInfo | null = null\n doc.descendants((node, pos) => {\n if (found) return false\n if (node.type.name === 'block' && node.attrs.id === id) {\n found = infoAt(node, pos, doc.resolve(pos).depth + 1)\n return false\n }\n // blocks only live in the doc and in groups; skip inline content\n return node.type.name === 'block' || node.type.name === 'blockGroup'\n })\n return found\n}\n\n/** A run of sibling blocks inside one container (the doc or a group). */\nexport interface SiblingRange {\n /** The container: the doc or a `blockGroup`. */\n parent: PMNode\n /** The position where the container's content starts. */\n parentStart: number\n /** Depth of the blocks. */\n depth: number\n /** First and last index, inclusive. */\n from: number\n to: number\n /** Positions before the first and after the last block. */\n start: number\n end: number\n}\n\nfunction rangeOf(doc: PMNode, a: BlockInfo, b: BlockInfo): SiblingRange {\n const $a = doc.resolve(a.pos)\n const $b = doc.resolve(b.pos)\n const parent = $a.parent\n return {\n parent,\n parentStart: $a.start(),\n depth: a.depth,\n from: $a.index(),\n to: $b.index(),\n start: a.pos,\n end: b.pos + b.node.nodeSize,\n }\n}\n\n/** The outer block at `depth` that contains `info`. */\nfunction climb(doc: PMNode, info: BlockInfo, depth: number): BlockInfo {\n if (info.depth === depth) return info\n const $pos = doc.resolve(info.pos + 1)\n return infoAt($pos.node(depth), $pos.before(depth), depth)\n}\n\n/**\n * The sibling blocks a selection spans. When its ends sit at different\n * levels, the range climbs to the level they share.\n */\nexport function siblingRangeBetween(doc: PMNode, from: number, to: number): SiblingRange | null {\n let a = blockAround(doc.resolve(from))\n let b = blockAround(doc.resolve(to))\n if (!a || !b) return null\n // climb two levels at a time (block > group > block) until both share a parent\n let depth = Math.min(a.depth, b.depth)\n for (;;) {\n a = climb(doc, a, depth)\n b = climb(doc, b, depth)\n if (doc.resolve(a.pos).start() === doc.resolve(b.pos).start()) break\n depth -= 2\n }\n return rangeOf(doc, a, b)\n}\n\nexport function selectedRange(state: EditorState): SiblingRange | null {\n const { from, to } = state.selection\n return siblingRangeBetween(state.doc, from, to)\n}\n\n/** The blocks of a range, in order. */\nexport function blocksIn(range: SiblingRange): BlockInfo[] {\n const list: BlockInfo[] = []\n let pos = range.parentStart\n range.parent.forEach((node, offset, index) => {\n if (index >= range.from && index <= range.to) list.push(infoAt(node, pos + offset, range.depth))\n })\n return list\n}\n\n/** Every block in document order, outer before inner. */\nexport function allBlocks(doc: PMNode): BlockInfo[] {\n const list: BlockInfo[] = []\n // walked by hand: resolving every position would scan the document again each time\n const visit = (container: PMNode, start: number, depth: number) => {\n container.forEach((block, offset) => {\n const pos = start + offset\n list.push(infoAt(block, pos, depth))\n if (block.childCount > 1)\n visit(block.child(1), pos + 1 + block.firstChild!.nodeSize + 1, depth + 2)\n })\n }\n visit(doc, 0, 1)\n return list\n}\n\n/** The deepest last block inside a block (itself when it has no children). */\nexport function lastDescendant(info: BlockInfo): BlockInfo {\n let current = info\n while (current.group) {\n const group = current.group\n const lastPos =\n current.pos +\n 1 +\n current.content.nodeSize +\n 1 +\n group.content.size -\n group.lastChild!.nodeSize\n current = infoAt(group.lastChild!, lastPos, current.depth + 2)\n }\n return current\n}\n\n/** The block that comes before `info` when reading top to bottom. */\nexport function previousInDocument(doc: PMNode, info: BlockInfo): BlockInfo | null {\n const $pos = doc.resolve(info.pos)\n const index = $pos.index()\n if (index > 0) {\n const before = $pos.parent.child(index - 1)\n return lastDescendant(infoAt(before, info.pos - before.nodeSize, info.depth))\n }\n // the first child: the previous is its parent block\n if (info.depth > 1)\n return infoAt($pos.node(info.depth - 2), $pos.before(info.depth - 2), info.depth - 2)\n return null\n}\n\n/** The block that comes after `info` when reading top to bottom. */\nexport function nextInDocument(doc: PMNode, info: BlockInfo): BlockInfo | null {\n if (info.group)\n return infoAt(info.group.firstChild!, info.pos + 1 + info.content.nodeSize + 1, info.depth + 2)\n let current = info\n for (;;) {\n const $pos = doc.resolve(current.pos)\n const end = current.pos + current.node.nodeSize\n if ($pos.index() < $pos.parent.childCount - 1)\n return infoAt($pos.parent.child($pos.index() + 1), end, current.depth)\n if (current.depth <= 1) return null\n current = infoAt(\n $pos.node(current.depth - 2),\n $pos.before(current.depth - 2),\n current.depth - 2,\n )\n }\n}\n"],"mappings":";AAkBA,SAAgB,OAAO,MAAc,KAAa,OAA0B;CAC1E,OAAO;EACL;EACA;EACA;EACA,SAAS,KAAK;EACd,YAAY,MAAM;EAClB,OAAO,KAAK,aAAa,IAAI,KAAK,MAAM,CAAC,IAAI;CAC/C;AACF;;AAGA,SAAgB,YAAY,MAAqC;CAC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[],"sources":["../../src/core/blocks.ts"],"sourcesContent":["import type { Node as PMNode, ResolvedPos } from 'prosemirror-model'\nimport type { EditorState } from 'prosemirror-state'\n\n/** A `block` node and where it sits. */\nexport interface BlockInfo {\n node: PMNode\n /** The position right before the block. */\n pos: number\n /** Its depth in the document; top-level blocks are at depth 1. */\n depth: number\n /** The block's content node (paragraph, heading, …). */\n content: PMNode\n /** The position right before the content node. */\n contentPos: number\n /** The children, if any. */\n group: PMNode | null\n}\n\n/**\n * How a block lays out its children, from its content node's `layout`\n * spec field: `row` puts them side by side (a set of columns) and only\n * holds `column` blocks; a `column` only sits in a row and holds the\n * blocks shown in it. Such a block has no text of its own.\n */\nexport type BlockLayout = 'row' | 'column'\n\nexport const layoutOf = (block: PMNode | null | undefined): BlockLayout | undefined =>\n block?.firstChild?.type.spec.layout as BlockLayout | undefined\n\nexport function infoAt(node: PMNode, pos: number, depth: number): BlockInfo {\n return {\n node,\n pos,\n depth,\n content: node.firstChild!,\n contentPos: pos + 1,\n group: node.childCount > 1 ? node.child(1) : null,\n }\n}\n\n/** The innermost block around a position, or `null` between blocks. */\nexport function blockAround($pos: ResolvedPos): BlockInfo | null {\n for (let depth = $pos.depth; depth > 0; depth--) {\n const node = $pos.node(depth)\n if (node.type.name === 'block') return infoAt(node, $pos.before(depth), depth)\n }\n // right before a block, e.g. a node selection of it\n const after = $pos.nodeAfter\n if (after?.type.name === 'block') return infoAt(after, $pos.pos, $pos.depth + 1)\n return null\n}\n\n/** The block whose children `info` is one of, or `null` at the top level. */\nexport function parentBlock(doc: PMNode, info: BlockInfo): BlockInfo | null {\n if (info.depth <= 1) return null\n const $pos = doc.resolve(info.pos)\n return infoAt($pos.node(info.depth - 2), $pos.before(info.depth - 2), info.depth - 2)\n}\n\n/** The block with an id, by scanning the document. */\nexport function findBlockById(doc: PMNode, id: string): BlockInfo | null {\n let found: BlockInfo | null = null\n doc.descendants((node, pos) => {\n if (found) return false\n if (node.type.name === 'block' && node.attrs.id === id) {\n found = infoAt(node, pos, doc.resolve(pos).depth + 1)\n return false\n }\n // blocks only live in the doc and in groups; skip inline content\n return node.type.name === 'block' || node.type.name === 'blockGroup'\n })\n return found\n}\n\n/** A run of sibling blocks inside one container (the doc or a group). */\nexport interface SiblingRange {\n /** The container: the doc or a `blockGroup`. */\n parent: PMNode\n /** The position where the container's content starts. */\n parentStart: number\n /** Depth of the blocks. */\n depth: number\n /** First and last index, inclusive. */\n from: number\n to: number\n /** Positions before the first and after the last block. */\n start: number\n end: number\n}\n\nfunction rangeOf(doc: PMNode, a: BlockInfo, b: BlockInfo): SiblingRange {\n const $a = doc.resolve(a.pos)\n const $b = doc.resolve(b.pos)\n const parent = $a.parent\n return {\n parent,\n parentStart: $a.start(),\n depth: a.depth,\n from: $a.index(),\n to: $b.index(),\n start: a.pos,\n end: b.pos + b.node.nodeSize,\n }\n}\n\n/** The outer block at `depth` that contains `info`. */\nfunction climb(doc: PMNode, info: BlockInfo, depth: number): BlockInfo {\n if (info.depth === depth) return info\n const $pos = doc.resolve(info.pos + 1)\n return infoAt($pos.node(depth), $pos.before(depth), depth)\n}\n\n/**\n * The sibling blocks a selection spans. When its ends sit at different\n * levels, the range climbs to the level they share.\n */\nexport function siblingRangeBetween(doc: PMNode, from: number, to: number): SiblingRange | null {\n let a = blockAround(doc.resolve(from))\n let b = blockAround(doc.resolve(to))\n if (!a || !b) return null\n // climb two levels at a time (block > group > block) until both share a parent\n let depth = Math.min(a.depth, b.depth)\n for (;;) {\n a = climb(doc, a, depth)\n b = climb(doc, b, depth)\n if (doc.resolve(a.pos).start() === doc.resolve(b.pos).start()) break\n depth -= 2\n }\n // columns go together: a selection across them takes the whole row\n if (depth > 1) {\n const $a = doc.resolve(a.pos)\n const owner = $a.node(depth - 2)\n if (layoutOf(owner) === 'row') a = b = infoAt(owner, $a.before(depth - 2), depth - 2)\n }\n return rangeOf(doc, a, b)\n}\n\nexport function selectedRange(state: EditorState): SiblingRange | null {\n const { from, to } = state.selection\n return siblingRangeBetween(state.doc, from, to)\n}\n\n/** The blocks of a range, in order. */\nexport function blocksIn(range: SiblingRange): BlockInfo[] {\n const list: BlockInfo[] = []\n let pos = range.parentStart\n range.parent.forEach((node, offset, index) => {\n if (index >= range.from && index <= range.to) list.push(infoAt(node, pos + offset, range.depth))\n })\n return list\n}\n\n/** Every block in document order, outer before inner. */\nexport function allBlocks(doc: PMNode): BlockInfo[] {\n const list: BlockInfo[] = []\n // walked by hand: resolving every position would scan the document again each time\n const visit = (container: PMNode, start: number, depth: number) => {\n container.forEach((block, offset) => {\n const pos = start + offset\n list.push(infoAt(block, pos, depth))\n if (block.childCount > 1)\n visit(block.child(1), pos + 1 + block.firstChild!.nodeSize + 1, depth + 2)\n })\n }\n visit(doc, 0, 1)\n return list\n}\n\n/** The deepest last block inside a block (itself when it has no children). */\nexport function lastDescendant(info: BlockInfo): BlockInfo {\n let current = info\n while (current.group) {\n const group = current.group\n const lastPos =\n current.pos +\n 1 +\n current.content.nodeSize +\n 1 +\n group.content.size -\n group.lastChild!.nodeSize\n current = infoAt(group.lastChild!, lastPos, current.depth + 2)\n }\n return current\n}\n\n/** The block that comes before `info` when reading top to bottom. */\nexport function previousInDocument(doc: PMNode, info: BlockInfo): BlockInfo | null {\n const $pos = doc.resolve(info.pos)\n const index = $pos.index()\n if (index > 0) {\n const before = $pos.parent.child(index - 1)\n return lastDescendant(infoAt(before, info.pos - before.nodeSize, info.depth))\n }\n // the first child: the previous is its parent block, unless that is a\n // column, where reading starts over\n if (info.depth > 1) {\n const parent = $pos.node(info.depth - 2)\n if (layoutOf(parent) === 'column') return null\n return infoAt(parent, $pos.before(info.depth - 2), info.depth - 2)\n }\n return null\n}\n\n/** The block that comes after `info` when reading top to bottom. */\nexport function nextInDocument(doc: PMNode, info: BlockInfo): BlockInfo | null {\n if (info.group)\n return infoAt(info.group.firstChild!, info.pos + 1 + info.content.nodeSize + 1, info.depth + 2)\n let current = info\n for (;;) {\n const $pos = doc.resolve(current.pos)\n const end = current.pos + current.node.nodeSize\n if ($pos.index() < $pos.parent.childCount - 1)\n return infoAt($pos.parent.child($pos.index() + 1), end, current.depth)\n if (current.depth <= 1) return null\n const parent = $pos.node(current.depth - 2)\n // the end of a column: the next column is beside it, not after it\n if (layoutOf(parent) === 'column') return null\n current = infoAt(parent, $pos.before(current.depth - 2), current.depth - 2)\n }\n}\n"],"mappings":";AA0BA,IAAa,YAAY,UACvB,OAAO,YAAY,KAAK,KAAK;AAE/B,SAAgB,OAAO,MAAc,KAAa,OAA0B;CAC1E,OAAO;EACL;EACA;EACA;EACA,SAAS,KAAK;EACd,YAAY,MAAM;EAClB,OAAO,KAAK,aAAa,IAAI,KAAK,MAAM,CAAC,IAAI;CAC/C;AACF;;AAGA,SAAgB,YAAY,MAAqC;CAC/D,KAAK,IAAI,QAAQ,KAAK,OAAO,QAAQ,GAAG,SAAS;EAC/C,MAAM,OAAO,KAAK,KAAK,KAAK;EAC5B,IAAI,KAAK,KAAK,SAAS,SAAS,OAAO,OAAO,MAAM,KAAK,OAAO,KAAK,GAAG,KAAK;CAC/E;CAEA,MAAM,QAAQ,KAAK;CACnB,IAAI,OAAO,KAAK,SAAS,SAAS,OAAO,OAAO,OAAO,KAAK,KAAK,KAAK,QAAQ,CAAC;CAC/E,OAAO;AACT;;AAGA,SAAgB,YAAY,KAAa,MAAmC;CAC1E,IAAI,KAAK,SAAS,GAAG,OAAO;CAC5B,MAAM,OAAO,IAAI,QAAQ,KAAK,GAAG;CACjC,OAAO,OAAO,KAAK,KAAK,KAAK,QAAQ,CAAC,GAAG,KAAK,OAAO,KAAK,QAAQ,CAAC,GAAG,KAAK,QAAQ,CAAC;AACtF;;AAGA,SAAgB,cAAc,KAAa,IAA8B;CACvE,IAAI,QAA0B;CAC9B,IAAI,aAAa,MAAM,QAAQ;EAC7B,IAAI,OAAO,OAAO;EAClB,IAAI,KAAK,KAAK,SAAS,WAAW,KAAK,MAAM,OAAO,IAAI;GACtD,QAAQ,OAAO,MAAM,KAAK,IAAI,QA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