@dou-ui/editor 0.1.0-alpha.11 → 0.1.0-alpha.13
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/cursors.js +42 -10
- package/dist/collaboration/cursors.js.map +1 -1
- package/dist/collaboration/index.js +30 -3
- package/dist/collaboration/index.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 +73 -15
- 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/commands.js +125 -13
- package/dist/core/commands.js.map +1 -1
- package/dist/core/extension.js +6 -2
- package/dist/core/extension.js.map +1 -1
- package/dist/core/model.js +8 -2
- package/dist/core/model.js.map +1 -1
- package/dist/core/schema.js.map +1 -1
- package/dist/core/transaction.js +12 -3
- package/dist/core/transaction.js.map +1 -1
- package/dist/document.js +40 -4
- package/dist/document.js.map +1 -1
- package/dist/dom.js +96 -13
- package/dist/dom.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/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/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/index.js +3 -2
- package/dist/index.js.map +1 -1
- package/dist/locale.js +30 -0
- package/dist/locale.js.map +1 -1
- package/dist/style.css +1 -1
- package/dist/types/collaboration/cursors.d.ts +29 -1
- package/dist/types/collaboration/index.d.ts +17 -2
- 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/extension.d.ts +53 -2
- package/dist/types/core/model.d.ts +6 -1
- package/dist/types/core/schema.d.ts +1 -1
- package/dist/types/document.d.ts +4 -2
- package/dist/types/dom.d.ts +34 -4
- package/dist/types/editor.vue.d.ts +10 -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/index.d.ts +12 -2
- package/dist/types/locale.d.ts +17 -0
- package/package.json +5 -5
|
@@ -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\"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AAoB;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"}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import { defineEditorExtension } from "../../core/extension.js";
|
|
2
|
+
import column_picker_default from "./column-picker.js";
|
|
3
|
+
import { columnsPlugin } from "./plugin.js";
|
|
4
|
+
import { columnSpec, columnsSpec } from "./schema.js";
|
|
5
|
+
import columns_controls_default from "./columns-controls.js";
|
|
6
|
+
import { columnsOutput, prepareColumns } from "./html.js";
|
|
7
|
+
import { columnKeys } from "./keys.js";
|
|
8
|
+
import select_columns_default from "./select-columns.js";
|
|
9
|
+
import { LayoutColumnsIcon } from "@dou-ui/icons";
|
|
10
|
+
// src/extensions/columns/index.ts
|
|
11
|
+
var counts = Array.from({ length: 4 }, (_, index) => 2 + index);
|
|
12
|
+
/**
|
|
13
|
+
* Columns: blocks side by side, two to five of them. In the slash menu,
|
|
14
|
+
* “Columns” opens a picker for how many. Each column holds any blocks,
|
|
15
|
+
* which move between columns like anywhere else; dropping blocks between
|
|
16
|
+
* two columns makes a new one there, and dragging the bar between two
|
|
17
|
+
* columns resizes them. On a narrow screen the columns stack.
|
|
18
|
+
*/
|
|
19
|
+
var columns = defineEditorExtension({
|
|
20
|
+
name: "columns",
|
|
21
|
+
blocks: {
|
|
22
|
+
columns: columnsSpec,
|
|
23
|
+
column: columnSpec
|
|
24
|
+
},
|
|
25
|
+
keymap: columnKeys,
|
|
26
|
+
plugins: ({ messages }) => [columnsPlugin((index, count) => messages().columns.column.replace("{index}", String(index)).replace("{count}", String(count)))],
|
|
27
|
+
output: { blocks: columnsOutput },
|
|
28
|
+
prepareHTML: prepareColumns,
|
|
29
|
+
overlays: [columns_controls_default],
|
|
30
|
+
blockMenu: [select_columns_default],
|
|
31
|
+
blockOptions: [{
|
|
32
|
+
key: "columns",
|
|
33
|
+
type: "columns",
|
|
34
|
+
props: { count: 2 },
|
|
35
|
+
label: (m) => m.types.columns,
|
|
36
|
+
hint: (m) => m.hints.columns,
|
|
37
|
+
icon: LayoutColumnsIcon,
|
|
38
|
+
keywords: [
|
|
39
|
+
"columns",
|
|
40
|
+
"layout",
|
|
41
|
+
"grid",
|
|
42
|
+
"fl",
|
|
43
|
+
"fenlan"
|
|
44
|
+
],
|
|
45
|
+
choices: {
|
|
46
|
+
title: (m) => m.columns.pick,
|
|
47
|
+
items: counts.map((count) => ({
|
|
48
|
+
props: { count },
|
|
49
|
+
label: (m) => m.columns.count.replace("{count}", String(count))
|
|
50
|
+
})),
|
|
51
|
+
component: column_picker_default
|
|
52
|
+
}
|
|
53
|
+
}]
|
|
54
|
+
});
|
|
55
|
+
export { columns };
|
|
56
|
+
|
|
57
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","names":["ColumnsControls","SelectColumns","ColumnPicker"],"sources":["../../../src/extensions/columns/index.ts"],"sourcesContent":["import { LayoutColumnsIcon } from '@dou-ui/icons'\nimport { defineEditorExtension } from '../../core/extension'\nimport ColumnPicker from './column-picker.vue'\nimport ColumnsControls from './columns-controls.vue'\nimport { columnsOutput, prepareColumns } from './html'\nimport { columnKeys } from './keys'\nimport { columnsPlugin } from './plugin'\nimport { columnSpec, columnsSpec, MAX_COLUMNS, MIN_COLUMNS } from './schema'\nimport SelectColumns from './select-columns.vue'\n\nconst counts = Array.from(\n { length: MAX_COLUMNS - MIN_COLUMNS + 1 },\n (_, index) => MIN_COLUMNS + index,\n)\n\n/**\n * Columns: blocks side by side, two to five of them. In the slash menu,\n * “Columns” opens a picker for how many. Each column holds any blocks,\n * which move between columns like anywhere else; dropping blocks between\n * two columns makes a new one there, and dragging the bar between two\n * columns resizes them. On a narrow screen the columns stack.\n */\nexport const columns = defineEditorExtension({\n name: 'columns',\n blocks: { columns: columnsSpec, column: columnSpec },\n keymap: columnKeys,\n plugins: ({ messages }) => [\n columnsPlugin((index, count) =>\n messages().columns.column.replace('{index}', String(index)).replace('{count}', String(count)),\n ),\n ],\n output: { blocks: columnsOutput },\n prepareHTML: prepareColumns,\n overlays: [ColumnsControls],\n blockMenu: [SelectColumns],\n blockOptions: [\n {\n key: 'columns',\n type: 'columns',\n props: { count: MIN_COLUMNS },\n label: (m) => m.types.columns,\n hint: (m) => m.hints.columns,\n icon: LayoutColumnsIcon,\n keywords: ['columns', 'layout', 'grid', 'fl', 'fenlan'],\n choices: {\n title: (m) => m.columns.pick,\n items: counts.map((count) => ({\n props: { count },\n label: (m) => m.columns.count.replace('{count}', String(count)),\n })),\n component: ColumnPicker,\n },\n },\n ],\n})\n\nexport { MAX_COLUMNS } from './schema'\n"],"mappings":";;;;;;;;;;AAUA,IAAM,SAAS,MAAM,KACnB,EAAE,QAAA,EAAsC,IACvC,GAAG,UAAA,IAAwB,KAC9B;;;;;;;;AASA,IAAa,UAAU,sBAAsB;CAC3C,MAAM;CACN,QAAQ;EAAE,SAAS;EAAa,QAAQ;CAAW;CACnD,QAAQ;CACR,UAAU,EAAE,eAAe,CACzB,eAAe,OAAO,UACpB,SAAS,CAAC,CAAC,QAAQ,OAAO,QAAQ,WAAW,OAAO,KAAK,CAAC,CAAC,CAAC,QAAQ,WAAW,OAAO,KAAK,CAAC,CAC9F,CACF;CACA,QAAQ,EAAE,QAAQ,cAAc;CAChC,aAAa;CACb,UAAU,CAACA,wBAAe;CAC1B,WAAW,CAACC,sBAAa;CACzB,cAAc,CACZ;EACE,KAAK;EACL,MAAM;EACN,OAAO,EAAE,OAAA,EAAmB;EAC5B,QAAQ,MAAM,EAAE,MAAM;EACtB,OAAO,MAAM,EAAE,MAAM;EACrB,MAAM;EACN,UAAU;GAAC;GAAW;GAAU;GAAQ;GAAM;EAAQ;EACtD,SAAS;GACP,QAAQ,MAAM,EAAE,QAAQ;GACxB,OAAO,OAAO,KAAK,WAAW;IAC5B,OAAO,EAAE,MAAM;IACf,QAAQ,MAAM,EAAE,QAAQ,MAAM,QAAQ,WAAW,OAAO,KAAK,CAAC;GAChE,EAAE;GACF,WAAWC;EACb;CACF,CACF;AACF,CAAC"}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { blockAround, layoutOf, nextInDocument, parentBlock, previousInDocument } from "../../core/blocks.js";
|
|
2
|
+
import { sinkBlocks } from "../../core/commands.js";
|
|
3
|
+
import { Selection } from "prosemirror-state";
|
|
4
|
+
// src/extensions/columns/keys.ts
|
|
5
|
+
/**
|
|
6
|
+
* `↑` on the first line of a column and `↓` on its last: the cursor goes to
|
|
7
|
+
* the block above or below the set of columns, as it looks, instead of
|
|
8
|
+
* into the column beside (the next one in the document).
|
|
9
|
+
*/
|
|
10
|
+
function leave(direction) {
|
|
11
|
+
return (state, dispatch, view) => {
|
|
12
|
+
const { selection } = state;
|
|
13
|
+
if (!selection.empty || !view?.endOfTextblock(direction < 0 ? "up" : "down")) return false;
|
|
14
|
+
const doc = state.doc;
|
|
15
|
+
const block = blockAround(selection.$head);
|
|
16
|
+
if (!block) return false;
|
|
17
|
+
if ((direction < 0 ? previousInDocument : nextInDocument)(doc, block)) return false;
|
|
18
|
+
let row = parentBlock(doc, block);
|
|
19
|
+
while (row && layoutOf(row.node) !== "row") row = parentBlock(doc, row);
|
|
20
|
+
if (!row) return false;
|
|
21
|
+
const pos = direction < 0 ? row.pos : row.pos + row.node.nodeSize;
|
|
22
|
+
if (direction < 0 ? pos <= 0 : pos >= doc.content.size) return false;
|
|
23
|
+
const target = Selection.findFrom(doc.resolve(pos), direction, true);
|
|
24
|
+
if (!target) return false;
|
|
25
|
+
if (dispatch) dispatch(state.tr.setSelection(target).scrollIntoView());
|
|
26
|
+
return true;
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* `Tab` in a column where it can't indent (and not in code): to the bar
|
|
31
|
+
* beside the column, to resize it with `←` `→`.
|
|
32
|
+
*/
|
|
33
|
+
var toBar = (state, _dispatch, view) => {
|
|
34
|
+
const { $from } = state.selection;
|
|
35
|
+
if (!view || $from.parent.type.spec.code || sinkBlocks(state)) return false;
|
|
36
|
+
let column = blockAround($from);
|
|
37
|
+
while (column && layoutOf(column.node) !== "column") column = parentBlock(state.doc, column);
|
|
38
|
+
const row = column && parentBlock(state.doc, column);
|
|
39
|
+
if (!column || !row?.group) return false;
|
|
40
|
+
const index = state.doc.resolve(column.pos).index();
|
|
41
|
+
const bar = (view.dom.closest(".dou-editor")?.querySelectorAll(".dou-editor-columns__bar.is-key"))?.[Math.min(index, row.group.childCount - 2)];
|
|
42
|
+
if (!bar) return false;
|
|
43
|
+
bar.focus();
|
|
44
|
+
return true;
|
|
45
|
+
};
|
|
46
|
+
var columnKeys = () => ({
|
|
47
|
+
ArrowUp: leave(-1),
|
|
48
|
+
ArrowDown: leave(1),
|
|
49
|
+
Tab: toBar
|
|
50
|
+
});
|
|
51
|
+
export { columnKeys };
|
|
52
|
+
|
|
53
|
+
//# sourceMappingURL=keys.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"keys.js","names":[],"sources":["../../../src/extensions/columns/keys.ts"],"sourcesContent":["import { Selection, type Command } from 'prosemirror-state'\nimport {\n blockAround,\n layoutOf,\n nextInDocument,\n parentBlock,\n previousInDocument,\n} from '../../core/blocks'\nimport { sinkBlocks } from '../../core/commands'\n\n/**\n * `↑` on the first line of a column and `↓` on its last: the cursor goes to\n * the block above or below the set of columns, as it looks, instead of\n * into the column beside (the next one in the document).\n */\nfunction leave(direction: -1 | 1): Command {\n return (state, dispatch, view) => {\n const { selection } = state\n if (!selection.empty || !view?.endOfTextblock(direction < 0 ? 'up' : 'down')) return false\n const doc = state.doc\n const block = blockAround(selection.$head)\n if (!block) return false\n // only at the first or last block of the column\n if ((direction < 0 ? previousInDocument : nextInDocument)(doc, block)) return false\n let row = parentBlock(doc, block)\n while (row && layoutOf(row.node) !== 'row') row = parentBlock(doc, row)\n if (!row) return false\n const pos = direction < 0 ? row.pos : row.pos + row.node.nodeSize\n if (direction < 0 ? pos <= 0 : pos >= doc.content.size) return false\n const target = Selection.findFrom(doc.resolve(pos), direction, true)\n if (!target) return false\n if (dispatch) dispatch(state.tr.setSelection(target).scrollIntoView())\n return true\n }\n}\n\n/**\n * `Tab` in a column where it can't indent (and not in code): to the bar\n * beside the column, to resize it with `←` `→`.\n */\nconst toBar: Command = (state, _dispatch, view) => {\n const { $from } = state.selection\n if (!view || $from.parent.type.spec.code || sinkBlocks(state)) return false\n let column = blockAround($from)\n while (column && layoutOf(column.node) !== 'column') column = parentBlock(state.doc, column)\n const row = column && parentBlock(state.doc, column)\n if (!column || !row?.group) return false\n const index = state.doc.resolve(column.pos).index()\n const bars = view.dom\n .closest('.dou-editor')\n ?.querySelectorAll<HTMLElement>('.dou-editor-columns__bar.is-key')\n const bar = bars?.[Math.min(index, row.group.childCount - 2)]\n if (!bar) return false\n bar.focus()\n return true\n}\n\nexport const columnKeys = () => ({ ArrowUp: leave(-1), ArrowDown: leave(1), Tab: toBar })\n"],"mappings":";;;;;;;;;AAeA,SAAS,MAAM,WAA4B;CACzC,QAAQ,OAAO,UAAU,SAAS;EAChC,MAAM,EAAE,cAAc;EACtB,IAAI,CAAC,UAAU,SAAS,CAAC,MAAM,eAAe,YAAY,IAAI,OAAO,MAAM,GAAG,OAAO;EACrF,M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