@14ch/svelte-md-outliner 0.0.32 → 0.0.33
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/CHANGELOG.md +19 -0
- package/dist/assets/styles/editor.css +147 -3
- package/dist/models/document/schema.js +16 -0
- package/dist/models/markdown/parser.js +29 -1
- package/dist/models/markdown/serializer.js +3 -1
- package/dist/operations/autoformat.js +10 -0
- package/dist/operations/commands/list.js +17 -1
- package/dist/operations/plugins/listView.d.ts +10 -0
- package/dist/operations/plugins/listView.js +57 -0
- package/dist/operations/plugins/tableCellView.d.ts +10 -0
- package/dist/operations/plugins/tableCellView.js +50 -0
- package/dist/operations/plugins/tableCheckbox.d.ts +8 -0
- package/dist/operations/plugins/tableCheckbox.js +45 -0
- package/dist/states/editorSession.js +5 -0
- package/dist/states/outlineViewController.svelte.js +2 -1
- package/package.json +8 -5
package/CHANGELOG.md
CHANGED
|
@@ -5,6 +5,25 @@ All notable changes to this project will be documented in this file.
|
|
|
5
5
|
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
|
|
6
6
|
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
|
7
7
|
|
|
8
|
+
## [0.0.33] - 2026-11-20
|
|
9
|
+
|
|
10
|
+
### Added
|
|
11
|
+
|
|
12
|
+
- Table cells can now hold a checkbox. A cell that starts with `[ ]`, `[x]` or
|
|
13
|
+
`[X]` followed by a space (or by the end of the cell) is shown as a checkbox,
|
|
14
|
+
in body rows and in the header row. Click the checkbox, press
|
|
15
|
+
`Mod+Alt+Enter` in the cell, or type `[ ] ` at the start of a cell to toggle
|
|
16
|
+
or create one. It is saved back as `[ ] ` / `[x] ` at the start of the cell.
|
|
17
|
+
|
|
18
|
+
### Changed
|
|
19
|
+
|
|
20
|
+
- A table cell that already started with `[ ]` or `[x]` is now shown as a
|
|
21
|
+
checkbox. The Markdown text is unchanged; write `\[ ]` to keep it as text.
|
|
22
|
+
- Checkboxes in lists and tables now look and animate like the svelte-ui
|
|
23
|
+
`Checkbox`.
|
|
24
|
+
- Updated `mermaid` to v12, which resolves known vulnerabilities in its
|
|
25
|
+
dependencies.
|
|
26
|
+
|
|
8
27
|
## [0.0.32] - 2026-11-20
|
|
9
28
|
|
|
10
29
|
### Changed
|
|
@@ -1479,8 +1479,15 @@
|
|
|
1479
1479
|
position: absolute;
|
|
1480
1480
|
right: 100%;
|
|
1481
1481
|
z-index: 1;
|
|
1482
|
-
|
|
1483
|
-
|
|
1482
|
+
/* 1 行目の中央に箱を置く。行の高さを本文と合わせる */
|
|
1483
|
+
display: flex;
|
|
1484
|
+
align-items: center;
|
|
1485
|
+
justify-content: center;
|
|
1486
|
+
/* 箱と本文の間隔は svelte-ui の `Checkbox` と同じ */
|
|
1487
|
+
box-sizing: content-box;
|
|
1488
|
+
width: var(--svelte-ui-checkbox-size);
|
|
1489
|
+
padding-right: var(--svelte-ui-checkbox-gap);
|
|
1490
|
+
height: calc(1em * var(--markdown-editor-line-height));
|
|
1484
1491
|
cursor: pointer;
|
|
1485
1492
|
}
|
|
1486
1493
|
|
|
@@ -1488,9 +1495,103 @@
|
|
|
1488
1495
|
cursor: pointer;
|
|
1489
1496
|
}
|
|
1490
1497
|
|
|
1498
|
+
.markdown-editor__surface .prosemirror-flat-list[data-list-kind='task'] > .list-marker label {
|
|
1499
|
+
display: flex;
|
|
1500
|
+
}
|
|
1501
|
+
|
|
1491
1502
|
.markdown-editor__surface .prosemirror-flat-list[data-list-kind='task'] > .list-marker input {
|
|
1492
1503
|
margin: 0;
|
|
1493
|
-
|
|
1504
|
+
}
|
|
1505
|
+
|
|
1506
|
+
/**
|
|
1507
|
+
* チェックボックスの見た目とアニメーションは svelte-ui の `Checkbox` と同じ。箱の寸法・枠・色、
|
|
1508
|
+
* チェックの字形、チェック済みへの切り替わり(背景色と、チェックが左から現れる動き)を持つ。
|
|
1509
|
+
* 項目の `<input>` と表のセルの擬似要素の両方へ同じ規則を当て、定義を 1 か所に置く。
|
|
1510
|
+
* 箱は `input` / `::before`、チェックは `input::after` / `::after` が描く。
|
|
1511
|
+
*/
|
|
1512
|
+
.markdown-editor__surface .prosemirror-flat-list[data-list-kind='task'] > .list-marker input,
|
|
1513
|
+
.markdown-editor__surface :is(th, td)[data-checked]::before {
|
|
1514
|
+
appearance: none;
|
|
1515
|
+
box-sizing: border-box;
|
|
1516
|
+
position: relative;
|
|
1517
|
+
display: inline-block;
|
|
1518
|
+
width: var(--svelte-ui-checkbox-size);
|
|
1519
|
+
height: var(--svelte-ui-checkbox-size);
|
|
1520
|
+
border: var(--svelte-ui-checkbox-border-width) solid var(--svelte-ui-checkbox-border-color);
|
|
1521
|
+
border-radius: var(--svelte-ui-checkbox-border-radius);
|
|
1522
|
+
background-color: transparent;
|
|
1523
|
+
cursor: pointer;
|
|
1524
|
+
transition-property: background-color, border-color, opacity;
|
|
1525
|
+
transition-duration: var(--svelte-ui-transition-duration);
|
|
1526
|
+
}
|
|
1527
|
+
|
|
1528
|
+
.markdown-editor__surface .prosemirror-flat-list[data-list-kind='task'] > .list-marker input::after,
|
|
1529
|
+
.markdown-editor__surface :is(th, td)[data-checked]::after {
|
|
1530
|
+
content: 'check';
|
|
1531
|
+
position: absolute;
|
|
1532
|
+
/* 字形の幅は箱の内側より広い。箱の中心に置いて、中心を字形の中心に合わせる */
|
|
1533
|
+
width: fit-content;
|
|
1534
|
+
transform: translate(-50%, -50%);
|
|
1535
|
+
clip-path: inset(0 100% 0 0);
|
|
1536
|
+
opacity: 0;
|
|
1537
|
+
color: var(--svelte-ui-checkbox-icon-color);
|
|
1538
|
+
font: bold var(--svelte-ui-checkbox-icon-size) / 1 'Material Symbols Outlined';
|
|
1539
|
+
font-feature-settings: 'liga';
|
|
1540
|
+
letter-spacing: normal;
|
|
1541
|
+
text-transform: none;
|
|
1542
|
+
white-space: nowrap;
|
|
1543
|
+
pointer-events: none;
|
|
1544
|
+
transition-property: clip-path, opacity;
|
|
1545
|
+
transition-duration: var(--svelte-ui-transition-duration);
|
|
1546
|
+
}
|
|
1547
|
+
|
|
1548
|
+
.markdown-editor__surface
|
|
1549
|
+
.prosemirror-flat-list[data-list-kind='task']
|
|
1550
|
+
> .list-marker
|
|
1551
|
+
input::after {
|
|
1552
|
+
top: 50%;
|
|
1553
|
+
left: 50%;
|
|
1554
|
+
}
|
|
1555
|
+
|
|
1556
|
+
.markdown-editor__surface
|
|
1557
|
+
.prosemirror-flat-list[data-list-kind='task']
|
|
1558
|
+
> .list-marker
|
|
1559
|
+
input:checked,
|
|
1560
|
+
.markdown-editor__surface :is(th, td)[data-checked='true']::before {
|
|
1561
|
+
background-color: var(--svelte-ui-checkbox-bg-checked);
|
|
1562
|
+
border-color: transparent;
|
|
1563
|
+
}
|
|
1564
|
+
|
|
1565
|
+
.markdown-editor__surface
|
|
1566
|
+
.prosemirror-flat-list[data-list-kind='task']
|
|
1567
|
+
> .list-marker
|
|
1568
|
+
input:checked::after,
|
|
1569
|
+
.markdown-editor__surface :is(th, td)[data-checked='true']::after {
|
|
1570
|
+
clip-path: inset(0);
|
|
1571
|
+
opacity: 1;
|
|
1572
|
+
transition-delay: var(--svelte-ui-transition-duration-fast);
|
|
1573
|
+
}
|
|
1574
|
+
|
|
1575
|
+
@media (hover: hover) {
|
|
1576
|
+
.markdown-editor__surface
|
|
1577
|
+
.prosemirror-flat-list[data-list-kind='task']
|
|
1578
|
+
> .list-marker
|
|
1579
|
+
input:not(:checked):hover,
|
|
1580
|
+
.markdown-editor__surface :is(th, td)[data-checked='false']:hover::before {
|
|
1581
|
+
border-color: var(--svelte-ui-checkbox-hover-color);
|
|
1582
|
+
}
|
|
1583
|
+
}
|
|
1584
|
+
|
|
1585
|
+
@media (prefers-reduced-motion: reduce) {
|
|
1586
|
+
.markdown-editor__surface .prosemirror-flat-list[data-list-kind='task'] > .list-marker input,
|
|
1587
|
+
.markdown-editor__surface
|
|
1588
|
+
.prosemirror-flat-list[data-list-kind='task']
|
|
1589
|
+
> .list-marker
|
|
1590
|
+
input::after,
|
|
1591
|
+
.markdown-editor__surface :is(th, td)[data-checked]::before,
|
|
1592
|
+
.markdown-editor__surface :is(th, td)[data-checked]::after {
|
|
1593
|
+
transition-duration: 0.01s;
|
|
1594
|
+
}
|
|
1494
1595
|
}
|
|
1495
1596
|
|
|
1496
1597
|
/* 項目の中の段落は詰めて置く(項目どうしが離れて見えないようにする) */
|
|
@@ -1570,6 +1671,49 @@
|
|
|
1570
1671
|
overflow-wrap: anywhere;
|
|
1571
1672
|
}
|
|
1572
1673
|
|
|
1674
|
+
/**
|
|
1675
|
+
* セルのチェックボックス。左の余白へ置き、本文はその分だけ右へ寄せる。
|
|
1676
|
+
* 押下の判定は描画された寸法から読む(→ `tableCheckbox`)ので、箱の位置と大きさはここだけが持つ。
|
|
1677
|
+
*/
|
|
1678
|
+
/**
|
|
1679
|
+
* 箱(`::before`)とチェック(`::after`)は、文字の大きさの違う別の要素である。`em` で位置を
|
|
1680
|
+
* 書くと基準がずれ、セルの文字が大きいとチェックだけが箱からはみ出す。位置はセルの上で
|
|
1681
|
+
* 長さとして確定させ(登録した変数は宣言した要素で計算される)、両方がそれを引く。
|
|
1682
|
+
*/
|
|
1683
|
+
@property --markdown-editor-checkbox-top {
|
|
1684
|
+
syntax: '<length>';
|
|
1685
|
+
inherits: true;
|
|
1686
|
+
initial-value: 0px;
|
|
1687
|
+
}
|
|
1688
|
+
|
|
1689
|
+
@property --markdown-editor-checkbox-left {
|
|
1690
|
+
syntax: '<length>';
|
|
1691
|
+
inherits: true;
|
|
1692
|
+
initial-value: 0px;
|
|
1693
|
+
}
|
|
1694
|
+
|
|
1695
|
+
.markdown-editor__surface :is(th, td)[data-checked] {
|
|
1696
|
+
/* 上の余白に、1 行目の高さと箱の差の半分を足す。箱が 1 行目の中央に来る */
|
|
1697
|
+
--markdown-editor-checkbox-top: calc(0.4em + (1lh - var(--svelte-ui-checkbox-size)) / 2);
|
|
1698
|
+
--markdown-editor-checkbox-left: var(--markdown-editor-cell-padding-x);
|
|
1699
|
+
padding-left: calc(
|
|
1700
|
+
var(--markdown-editor-checkbox-left) + var(--svelte-ui-checkbox-size) +
|
|
1701
|
+
var(--svelte-ui-checkbox-gap)
|
|
1702
|
+
);
|
|
1703
|
+
}
|
|
1704
|
+
|
|
1705
|
+
.markdown-editor__surface :is(th, td)[data-checked]::before {
|
|
1706
|
+
content: '';
|
|
1707
|
+
position: absolute;
|
|
1708
|
+
top: var(--markdown-editor-checkbox-top);
|
|
1709
|
+
left: var(--markdown-editor-checkbox-left);
|
|
1710
|
+
}
|
|
1711
|
+
|
|
1712
|
+
.markdown-editor__surface :is(th, td)[data-checked]::after {
|
|
1713
|
+
top: calc(var(--markdown-editor-checkbox-top) + var(--svelte-ui-checkbox-size) / 2);
|
|
1714
|
+
left: calc(var(--markdown-editor-checkbox-left) + var(--svelte-ui-checkbox-size) / 2);
|
|
1715
|
+
}
|
|
1716
|
+
|
|
1573
1717
|
/* 見出し行は背景で本文行と見分ける */
|
|
1574
1718
|
.markdown-editor__surface th {
|
|
1575
1719
|
background: var(--markdown-editor-table-header-background);
|
|
@@ -391,6 +391,22 @@ const tableNodeSpecs = tableNodes({
|
|
|
391
391
|
if (value)
|
|
392
392
|
attrs.style = `${attrs.style ?? ''}text-align: ${value};`;
|
|
393
393
|
}
|
|
394
|
+
},
|
|
395
|
+
/**
|
|
396
|
+
* セルの先頭のチェックボックス。`null` はチェックボックスの無いセル、
|
|
397
|
+
* `true` / `false` が完了・未完了。マークダウンでは先頭の `[ ] ` / `[x] ` と往復する。
|
|
398
|
+
* 見出し行のセルも同じ規則で持つ。
|
|
399
|
+
*/
|
|
400
|
+
checked: {
|
|
401
|
+
default: null,
|
|
402
|
+
getFromDOM: (element) => {
|
|
403
|
+
const value = element.getAttribute('data-checked');
|
|
404
|
+
return value === null ? null : value === 'true';
|
|
405
|
+
},
|
|
406
|
+
setDOMAttr: (value, attrs) => {
|
|
407
|
+
if (value !== null)
|
|
408
|
+
attrs['data-checked'] = String(value);
|
|
409
|
+
}
|
|
394
410
|
}
|
|
395
411
|
}
|
|
396
412
|
});
|
|
@@ -305,6 +305,32 @@ function extractTaskMarker(block) {
|
|
|
305
305
|
paragraph: n.paragraph.createChecked(null, remaining)
|
|
306
306
|
};
|
|
307
307
|
}
|
|
308
|
+
/**
|
|
309
|
+
* セルの先頭が `[ ]` / `[x]` ならチェックボックスとして切り出す。
|
|
310
|
+
*
|
|
311
|
+
* 判定は原文でも行う。`\[ ]` のようにエスケープされた記号は、読み込んだ後の文字では
|
|
312
|
+
* `[ ]` と区別できず、原文を見ないと文字として残す書き方が効かない。
|
|
313
|
+
*/
|
|
314
|
+
function extractCellTask(content, source) {
|
|
315
|
+
if (!TASK_MARKER.test(source))
|
|
316
|
+
return null;
|
|
317
|
+
const first = content.firstChild;
|
|
318
|
+
if (!first?.isText || !first.text)
|
|
319
|
+
return null;
|
|
320
|
+
const match = TASK_MARKER.exec(first.text);
|
|
321
|
+
if (!match)
|
|
322
|
+
return null;
|
|
323
|
+
// 空白の無い形は、印だけでセルが終わるときに限る。`[x]**太字**` を巻き込まない
|
|
324
|
+
if (!match[2] && content.childCount > 1)
|
|
325
|
+
return null;
|
|
326
|
+
const rest = first.text.slice(match[0].length);
|
|
327
|
+
const remaining = [];
|
|
328
|
+
if (rest)
|
|
329
|
+
remaining.push(outlineSchema.text(rest, first.marks));
|
|
330
|
+
for (let i = 1; i < content.childCount; i += 1)
|
|
331
|
+
remaining.push(content.child(i));
|
|
332
|
+
return { checked: match[1].toLowerCase() === 'x', content: Fragment.fromArray(remaining) };
|
|
333
|
+
}
|
|
308
334
|
function readTable(tokens, start) {
|
|
309
335
|
const end = matchingClose(tokens, start, 'table_open', 'table_close');
|
|
310
336
|
const rows = [];
|
|
@@ -323,7 +349,9 @@ function readTable(tokens, start) {
|
|
|
323
349
|
else if (token.type === 'th_open' || token.type === 'td_open') {
|
|
324
350
|
const inline = tokens[i + 1];
|
|
325
351
|
const type = isHeaderRow ? n.table_header : n.table_cell;
|
|
326
|
-
|
|
352
|
+
const content = parseInline(inline, type);
|
|
353
|
+
const task = extractCellTask(content, inline?.content ?? '');
|
|
354
|
+
cells.push(type.createChecked({ align: alignOf(token), checked: task?.checked ?? null }, task ? task.content : content));
|
|
327
355
|
i += 2;
|
|
328
356
|
}
|
|
329
357
|
}
|
|
@@ -348,7 +348,9 @@ const serializeTable = (state, node) => {
|
|
|
348
348
|
node.forEach((row, _offset, rowIndex) => {
|
|
349
349
|
const cells = [];
|
|
350
350
|
row.forEach((cell) => {
|
|
351
|
-
|
|
351
|
+
const text = writeLine(cell);
|
|
352
|
+
const checkbox = cell.attrs.checked === null ? '' : cell.attrs.checked ? '[x]' : '[ ]';
|
|
353
|
+
cells.push(escapeCell(checkbox && text ? `${checkbox} ${text}` : checkbox || text));
|
|
352
354
|
if (rowIndex === 0)
|
|
353
355
|
aligns.push(cell.attrs.align);
|
|
354
356
|
});
|
|
@@ -23,6 +23,16 @@ export const autoformatRules = [
|
|
|
23
23
|
kind: 'task',
|
|
24
24
|
checked: /[Xx]/.test(match[1])
|
|
25
25
|
})),
|
|
26
|
+
// 表のセルの先頭で打つと、セルのチェックボックスになる
|
|
27
|
+
new InputRule(/^\[([\sXx]?)\]\s$/, (state, match, start, end) => {
|
|
28
|
+
const $from = state.doc.resolve(start);
|
|
29
|
+
const cell = $from.parent.type;
|
|
30
|
+
if (cell !== outlineSchema.nodes.table_cell && cell !== outlineSchema.nodes.table_header) {
|
|
31
|
+
return null;
|
|
32
|
+
}
|
|
33
|
+
const tr = state.tr.delete(start, end);
|
|
34
|
+
return tr.setNodeAttribute($from.before(), 'checked', /[Xx]/.test(match[1]));
|
|
35
|
+
}),
|
|
26
36
|
/**
|
|
27
37
|
* 引用。**項目の行で打たれたら、項目を解いてから包む**(→ `changeLine`)。
|
|
28
38
|
* 項目の中に残すと「中黒の付いた引用」になり、読み直したときに項目の行が 1 つ増える。
|
|
@@ -680,8 +680,24 @@ function selectedItemRange(state) {
|
|
|
680
680
|
function spanOf(range) {
|
|
681
681
|
return { from: range.start + 1, to: range.end - 1 };
|
|
682
682
|
}
|
|
683
|
-
|
|
683
|
+
function enclosingCheckboxCell(state) {
|
|
684
|
+
const { $from } = state.selection;
|
|
685
|
+
for (let depth = $from.depth; depth > 0; depth -= 1) {
|
|
686
|
+
const node = $from.node(depth);
|
|
687
|
+
if (node.type === outlineSchema.nodes.table_cell ||
|
|
688
|
+
node.type === outlineSchema.nodes.table_header) {
|
|
689
|
+
return node.attrs.checked === null ? null : { node, pos: $from.before(depth) };
|
|
690
|
+
}
|
|
691
|
+
}
|
|
692
|
+
return null;
|
|
693
|
+
}
|
|
694
|
+
/** カーソルが属するチェック項目(表のセルのチェックボックスを含む)の完了状態を反転する */
|
|
684
695
|
function toggleTaskChecked(state, dispatch) {
|
|
696
|
+
const cell = enclosingCheckboxCell(state);
|
|
697
|
+
if (cell) {
|
|
698
|
+
dispatch?.(state.tr.setNodeAttribute(cell.pos, 'checked', !cell.node.attrs.checked));
|
|
699
|
+
return true;
|
|
700
|
+
}
|
|
685
701
|
const item = enclosingListItem(state);
|
|
686
702
|
if (!item || item.node.attrs.kind !== 'task')
|
|
687
703
|
return false;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { Plugin } from 'prosemirror-state';
|
|
2
|
+
/**
|
|
3
|
+
* チェック項目のチェックが変わっても、**項目の要素を作り直さない。**
|
|
4
|
+
*
|
|
5
|
+
* 一覧ライブラリの描画は、属性が変わった項目の要素を作り直す。そのままでは、チェックの
|
|
6
|
+
* 切り替えで要素が入れ替わり、チェックボックスの CSS の遷移(背景色とチェックの現れ方)が
|
|
7
|
+
* 走らない。チェックだけが変わるときは、属性と `<input>` の状態を当て直す。
|
|
8
|
+
* それ以外の変化は、ライブラリと同じく作り直す。
|
|
9
|
+
*/
|
|
10
|
+
export declare function listViewPlugin(): Plugin;
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import { DOMSerializer } from 'prosemirror-model';
|
|
2
|
+
import { Plugin } from 'prosemirror-state';
|
|
3
|
+
import { outlineSchema } from '../../models/document/schema.js';
|
|
4
|
+
const LIST = outlineSchema.nodes.list;
|
|
5
|
+
/**
|
|
6
|
+
* チェック項目のチェックが変わっても、**項目の要素を作り直さない。**
|
|
7
|
+
*
|
|
8
|
+
* 一覧ライブラリの描画は、属性が変わった項目の要素を作り直す。そのままでは、チェックの
|
|
9
|
+
* 切り替えで要素が入れ替わり、チェックボックスの CSS の遷移(背景色とチェックの現れ方)が
|
|
10
|
+
* 走らない。チェックだけが変わるときは、属性と `<input>` の状態を当て直す。
|
|
11
|
+
* それ以外の変化は、ライブラリと同じく作り直す。
|
|
12
|
+
*/
|
|
13
|
+
export function listViewPlugin() {
|
|
14
|
+
return new Plugin({ props: { nodeViews: { list: createListView } } });
|
|
15
|
+
}
|
|
16
|
+
function createListView(node) {
|
|
17
|
+
let previous = node;
|
|
18
|
+
const { dom, contentDOM } = DOMSerializer.renderSpec(document, LIST.spec.toDOM(node));
|
|
19
|
+
// 切り替えは押下(`mousedown`)で文書へ反映される。`<input>` の既定の切り替えを残すと、
|
|
20
|
+
// 反映した状態をもう一度反転してしまう
|
|
21
|
+
dom.addEventListener('click', (event) => {
|
|
22
|
+
if (event.target instanceof HTMLInputElement)
|
|
23
|
+
event.preventDefault();
|
|
24
|
+
});
|
|
25
|
+
return {
|
|
26
|
+
dom,
|
|
27
|
+
contentDOM,
|
|
28
|
+
update(next) {
|
|
29
|
+
if (next.type !== LIST || !sameExceptChecked(next, previous))
|
|
30
|
+
return false;
|
|
31
|
+
if (isNested(next) !== isNested(previous) || isSingle(next) !== isSingle(previous)) {
|
|
32
|
+
return false;
|
|
33
|
+
}
|
|
34
|
+
if (next.attrs.checked !== previous.attrs.checked)
|
|
35
|
+
applyChecked(dom, next);
|
|
36
|
+
previous = next;
|
|
37
|
+
return true;
|
|
38
|
+
}
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
function sameExceptChecked(a, b) {
|
|
42
|
+
return withoutChecked(a).sameMarkup(withoutChecked(b));
|
|
43
|
+
}
|
|
44
|
+
function withoutChecked(node) {
|
|
45
|
+
return LIST.create({ ...node.attrs, checked: false }, null, node.marks);
|
|
46
|
+
}
|
|
47
|
+
const isNested = (node) => node.firstChild?.type === LIST;
|
|
48
|
+
const isSingle = (node) => node.childCount === 1;
|
|
49
|
+
function applyChecked(dom, node) {
|
|
50
|
+
const checked = node.attrs.checked === true;
|
|
51
|
+
dom.toggleAttribute('data-list-checked', checked);
|
|
52
|
+
const input = dom.querySelector(':scope > .list-marker input[type="checkbox"]');
|
|
53
|
+
if (!input)
|
|
54
|
+
return;
|
|
55
|
+
input.checked = checked;
|
|
56
|
+
input.toggleAttribute('checked', checked);
|
|
57
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { Plugin } from 'prosemirror-state';
|
|
2
|
+
/**
|
|
3
|
+
* セルの属性が変わったとき、**セルの要素を作り直さず、属性だけを当て直す。**
|
|
4
|
+
*
|
|
5
|
+
* 基盤は属性の変わったノードの要素を作り直すため、そのままではチェックボックスの切り替えで
|
|
6
|
+
* 要素が入れ替わり、CSS の遷移(背景色とチェックの現れ方)が走らない。
|
|
7
|
+
* 要素の作り方は `toDOM` を唯一の出どころにし、ここでは属性を当て直すだけにする
|
|
8
|
+
* (→ `sectionView`)。
|
|
9
|
+
*/
|
|
10
|
+
export declare function tableCellViewPlugin(): Plugin;
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { Plugin } from 'prosemirror-state';
|
|
2
|
+
import { outlineSchema } from '../../models/document/schema.js';
|
|
3
|
+
/**
|
|
4
|
+
* セルの属性が変わったとき、**セルの要素を作り直さず、属性だけを当て直す。**
|
|
5
|
+
*
|
|
6
|
+
* 基盤は属性の変わったノードの要素を作り直すため、そのままではチェックボックスの切り替えで
|
|
7
|
+
* 要素が入れ替わり、CSS の遷移(背景色とチェックの現れ方)が走らない。
|
|
8
|
+
* 要素の作り方は `toDOM` を唯一の出どころにし、ここでは属性を当て直すだけにする
|
|
9
|
+
* (→ `sectionView`)。
|
|
10
|
+
*/
|
|
11
|
+
export function tableCellViewPlugin() {
|
|
12
|
+
const { table_cell, table_header } = outlineSchema.nodes;
|
|
13
|
+
return new Plugin({
|
|
14
|
+
props: {
|
|
15
|
+
nodeViews: {
|
|
16
|
+
table_cell: (node) => createCellView(node, table_cell),
|
|
17
|
+
table_header: (node) => createCellView(node, table_header)
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
});
|
|
21
|
+
}
|
|
22
|
+
function createCellView(node, type) {
|
|
23
|
+
const [tag] = renderedSpec(node);
|
|
24
|
+
const dom = document.createElement(tag);
|
|
25
|
+
applyAttributes(dom, node);
|
|
26
|
+
return {
|
|
27
|
+
dom,
|
|
28
|
+
contentDOM: dom,
|
|
29
|
+
update(next) {
|
|
30
|
+
if (next.type !== type)
|
|
31
|
+
return false;
|
|
32
|
+
applyAttributes(dom, next);
|
|
33
|
+
return true;
|
|
34
|
+
}
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
function applyAttributes(dom, node) {
|
|
38
|
+
const [, attrs] = renderedSpec(node);
|
|
39
|
+
for (const name of dom.getAttributeNames()) {
|
|
40
|
+
if (attrs[name] === undefined)
|
|
41
|
+
dom.removeAttribute(name);
|
|
42
|
+
}
|
|
43
|
+
for (const [name, value] of Object.entries(attrs)) {
|
|
44
|
+
if (value !== undefined)
|
|
45
|
+
dom.setAttribute(name, value);
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
function renderedSpec(node) {
|
|
49
|
+
return node.type.spec.toDOM(node);
|
|
50
|
+
}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { Plugin } from 'prosemirror-state';
|
|
2
|
+
/**
|
|
3
|
+
* 表のセルのチェックボックスを押して切り替える。
|
|
4
|
+
*
|
|
5
|
+
* チェックボックスはセルの左の余白に擬似要素として描かれ、文書には属さない。
|
|
6
|
+
* 押された位置が余白の中かどうかを、描画された寸法から読む(→ `foldClick`)。
|
|
7
|
+
*/
|
|
8
|
+
export function tableCheckboxPlugin() {
|
|
9
|
+
return new Plugin({
|
|
10
|
+
props: {
|
|
11
|
+
handleDOMEvents: {
|
|
12
|
+
mousedown: (view, event) => handleMouseDown(view, event)
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
});
|
|
16
|
+
}
|
|
17
|
+
function handleMouseDown(view, event) {
|
|
18
|
+
if (event.button !== 0 || !(event.target instanceof Element))
|
|
19
|
+
return false;
|
|
20
|
+
const cell = event.target.closest('td[data-checked], th[data-checked]');
|
|
21
|
+
if (!(cell instanceof HTMLElement) || !view.dom.contains(cell))
|
|
22
|
+
return false;
|
|
23
|
+
if (!isInCheckbox(cell, event))
|
|
24
|
+
return false;
|
|
25
|
+
const $pos = view.state.doc.resolve(view.posAtDOM(cell, 0));
|
|
26
|
+
const pos = $pos.before($pos.depth);
|
|
27
|
+
const node = view.state.doc.nodeAt(pos);
|
|
28
|
+
if (!node)
|
|
29
|
+
return false;
|
|
30
|
+
view.dispatch(view.state.tr.setNodeAttribute(pos, 'checked', !node.attrs.checked));
|
|
31
|
+
event.preventDefault();
|
|
32
|
+
return true;
|
|
33
|
+
}
|
|
34
|
+
/** 押された位置が、セルの先頭行の、本文より左の余白の中か */
|
|
35
|
+
function isInCheckbox(cell, event) {
|
|
36
|
+
const box = getComputedStyle(cell, '::before');
|
|
37
|
+
const height = parseFloat(box.height);
|
|
38
|
+
if (!(height > 0))
|
|
39
|
+
return false;
|
|
40
|
+
const style = getComputedStyle(cell);
|
|
41
|
+
const rect = cell.getBoundingClientRect();
|
|
42
|
+
const textLeft = rect.left + parseFloat(style.borderLeftWidth) + parseFloat(style.paddingLeft);
|
|
43
|
+
const top = rect.top + parseFloat(style.borderTopWidth) + (parseFloat(box.top) || 0);
|
|
44
|
+
return event.clientX < textLeft && event.clientY >= top && event.clientY < top + height;
|
|
45
|
+
}
|
|
@@ -9,6 +9,8 @@ import { serializeMarkdown } from '../models/markdown/serializer.js';
|
|
|
9
9
|
import { editorKeymap } from '../operations/keymap/assemble.js';
|
|
10
10
|
import { DEFAULT_LANG, resolveMessages } from '../messages/index.js';
|
|
11
11
|
import { sectionViewPlugin } from '../operations/plugins/sectionView.js';
|
|
12
|
+
import { listViewPlugin } from '../operations/plugins/listView.js';
|
|
13
|
+
import { tableCellViewPlugin } from '../operations/plugins/tableCellView.js';
|
|
12
14
|
import { codeHighlightPlugin } from '../operations/plugins/codeHighlight.js';
|
|
13
15
|
import { mermaidViewPlugin } from '../operations/plugins/mermaidView.js';
|
|
14
16
|
import { imagePastePlugin } from '../operations/plugins/imagePaste.js';
|
|
@@ -92,6 +94,9 @@ export function createEditorSession(element, options) {
|
|
|
92
94
|
// 表だけがブロックとして指せない状態になる(セル範囲の選択は変換とは無関係に働く)
|
|
93
95
|
tableEditing({ allowTableNodeSelection: true }),
|
|
94
96
|
tableHandlesPlugin(),
|
|
97
|
+
tableCellViewPlugin(),
|
|
98
|
+
// ライブラリの描画より先に置く(同じ種類の描画は最初に登録したものが使われる)
|
|
99
|
+
listViewPlugin(),
|
|
95
100
|
...createListPlugins({ schema: outlineSchema }),
|
|
96
101
|
listStructurePlugin(),
|
|
97
102
|
// 文書の形を整えるものどうしは並び順に左右されない。編集基盤は誰も足さなくなるまで
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { foldCommands } from '../operations/commands/sectionFold.js';
|
|
2
2
|
import { foldClickPlugin } from '../operations/plugins/foldClick.js';
|
|
3
|
+
import { tableCheckboxPlugin } from '../operations/plugins/tableCheckbox.js';
|
|
3
4
|
import { foldGuardPlugin } from '../operations/plugins/foldGuard.js';
|
|
4
5
|
import { createFocusPlugin } from '../operations/plugins/focus.js';
|
|
5
6
|
import { createViewActions } from '../operations/keymap/viewActions.js';
|
|
@@ -16,7 +17,7 @@ import { EMPTY_VIEW_STATE, viewStateCodec } from '../models/viewState/viewStateC
|
|
|
16
17
|
export function createOutlineViewController(options) {
|
|
17
18
|
const focus = createFocusPlugin();
|
|
18
19
|
const extension = {
|
|
19
|
-
plugins: [focus.plugin, foldGuardPlugin(), foldClickPlugin()],
|
|
20
|
+
plugins: [focus.plugin, foldGuardPlugin(), foldClickPlugin(), tableCheckboxPlugin()],
|
|
20
21
|
actions: createViewActions(focus, toggleShortcutHelp)
|
|
21
22
|
};
|
|
22
23
|
// 画面へ渡す投影。真実は文書とプラグインにあり、これはその控えである
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@14ch/svelte-md-outliner",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.33",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"description": "An outliner-style Markdown editor for Svelte 5. Headings form a real section tree you can fold, focus, and re-nest from the keyboard.",
|
|
@@ -69,13 +69,16 @@
|
|
|
69
69
|
"test:e2e": "playwright install && playwright test",
|
|
70
70
|
"release": "bash scripts/release.sh"
|
|
71
71
|
},
|
|
72
|
+
"imports": {
|
|
73
|
+
"#lib/*": "./src/lib/*"
|
|
74
|
+
},
|
|
72
75
|
"peerDependencies": {
|
|
73
76
|
"@14ch/svelte-ui": "^0.0.87",
|
|
74
77
|
"svelte": "^5.0.0"
|
|
75
78
|
},
|
|
76
79
|
"dependencies": {
|
|
77
80
|
"markdown-it": "^15.0.0",
|
|
78
|
-
"mermaid": "^
|
|
81
|
+
"mermaid": "^12.3.0",
|
|
79
82
|
"prosemirror-commands": "^1.7.1",
|
|
80
83
|
"prosemirror-flat-list": "0.7.1",
|
|
81
84
|
"prosemirror-gapcursor": "^1.4.0",
|
|
@@ -94,8 +97,8 @@
|
|
|
94
97
|
"@14ch/svelte-ui": "^0.0.87",
|
|
95
98
|
"@eslint/js": "^10.0.1",
|
|
96
99
|
"@playwright/test": "^1.60.0",
|
|
97
|
-
"@sveltejs/adapter-static": "^
|
|
98
|
-
"@sveltejs/kit": "^
|
|
100
|
+
"@sveltejs/adapter-static": "^4.0.1",
|
|
101
|
+
"@sveltejs/kit": "^3.4.0",
|
|
99
102
|
"@sveltejs/package": "^2.5.8",
|
|
100
103
|
"@sveltejs/vite-plugin-svelte": "^7.1.2",
|
|
101
104
|
"@types/node": "^24",
|
|
@@ -107,7 +110,7 @@
|
|
|
107
110
|
"playwright": "^1.60.0",
|
|
108
111
|
"prettier": "^3.8.3",
|
|
109
112
|
"prettier-plugin-svelte": "^4.1.0",
|
|
110
|
-
"svelte": "^5.
|
|
113
|
+
"svelte": "^5.58.0",
|
|
111
114
|
"svelte-check": "^4.6.0",
|
|
112
115
|
"typescript": "^6.0.3",
|
|
113
116
|
"typescript-eslint": "^8.60.1",
|