@14ch/svelte-md-outliner 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (153) hide show
  1. package/README.ja.md +190 -0
  2. package/README.md +190 -0
  3. package/dist/assets/styles/editor.css +1459 -0
  4. package/dist/assets/styles/theme.css +486 -0
  5. package/dist/components/ContextMenu.svelte +279 -0
  6. package/dist/components/ContextMenu.svelte.d.ts +9 -0
  7. package/dist/components/EditorSurface.svelte +99 -0
  8. package/dist/components/EditorSurface.svelte.d.ts +16 -0
  9. package/dist/components/FocusBreadcrumb.svelte +138 -0
  10. package/dist/components/FocusBreadcrumb.svelte.d.ts +16 -0
  11. package/dist/components/MarkdownEditor.svelte +393 -0
  12. package/dist/components/MarkdownEditor.svelte.d.ts +119 -0
  13. package/dist/components/ShortcutHelpDialog.svelte +155 -0
  14. package/dist/components/ShortcutHelpDialog.svelte.d.ts +12 -0
  15. package/dist/components/internal/Dialog.svelte +157 -0
  16. package/dist/components/internal/Dialog.svelte.d.ts +23 -0
  17. package/dist/components/internal/Modal.svelte +181 -0
  18. package/dist/components/internal/Modal.svelte.d.ts +18 -0
  19. package/dist/components/internal/Popup.svelte +248 -0
  20. package/dist/components/internal/Popup.svelte.d.ts +26 -0
  21. package/dist/index.d.ts +32 -0
  22. package/dist/index.js +28 -0
  23. package/dist/markdown.d.ts +13 -0
  24. package/dist/markdown.js +10 -0
  25. package/dist/messages/en.d.ts +2 -0
  26. package/dist/messages/en.js +107 -0
  27. package/dist/messages/index.d.ts +13 -0
  28. package/dist/messages/index.js +31 -0
  29. package/dist/messages/ja.d.ts +2 -0
  30. package/dist/messages/ja.js +112 -0
  31. package/dist/messages/messages.types.d.ts +59 -0
  32. package/dist/messages/messages.types.js +1 -0
  33. package/dist/models/document/bodySelection.d.ts +32 -0
  34. package/dist/models/document/bodySelection.js +43 -0
  35. package/dist/models/document/document.types.d.ts +27 -0
  36. package/dist/models/document/document.types.js +8 -0
  37. package/dist/models/document/foldable.d.ts +18 -0
  38. package/dist/models/document/foldable.js +21 -0
  39. package/dist/models/document/schema.d.ts +2 -0
  40. package/dist/models/document/schema.js +428 -0
  41. package/dist/models/document/sectionTree.d.ts +15 -0
  42. package/dist/models/document/sectionTree.js +123 -0
  43. package/dist/models/markdown/blockOutline.d.ts +9 -0
  44. package/dist/models/markdown/blockOutline.js +82 -0
  45. package/dist/models/markdown/frontMatter.d.ts +98 -0
  46. package/dist/models/markdown/frontMatter.js +300 -0
  47. package/dist/models/markdown/markdown.types.d.ts +60 -0
  48. package/dist/models/markdown/markdown.types.js +1 -0
  49. package/dist/models/markdown/markdownIt.d.ts +1 -0
  50. package/dist/models/markdown/markdownIt.js +92 -0
  51. package/dist/models/markdown/parser.d.ts +4 -0
  52. package/dist/models/markdown/parser.js +505 -0
  53. package/dist/models/markdown/plainText.d.ts +1 -0
  54. package/dist/models/markdown/plainText.js +25 -0
  55. package/dist/models/markdown/serializer.d.ts +17 -0
  56. package/dist/models/markdown/serializer.js +453 -0
  57. package/dist/models/viewState/viewState.types.d.ts +38 -0
  58. package/dist/models/viewState/viewState.types.js +17 -0
  59. package/dist/models/viewState/viewStateCodec.d.ts +31 -0
  60. package/dist/models/viewState/viewStateCodec.js +173 -0
  61. package/dist/operations/autoformat.d.ts +9 -0
  62. package/dist/operations/autoformat.js +86 -0
  63. package/dist/operations/commands/block.d.ts +24 -0
  64. package/dist/operations/commands/block.js +139 -0
  65. package/dist/operations/commands/codeBlock.d.ts +7 -0
  66. package/dist/operations/commands/codeBlock.js +26 -0
  67. package/dist/operations/commands/element.d.ts +67 -0
  68. package/dist/operations/commands/element.js +269 -0
  69. package/dist/operations/commands/frontMatter.d.ts +35 -0
  70. package/dist/operations/commands/frontMatter.js +120 -0
  71. package/dist/operations/commands/lineBreak.d.ts +9 -0
  72. package/dist/operations/commands/lineBreak.js +16 -0
  73. package/dist/operations/commands/link.d.ts +7 -0
  74. package/dist/operations/commands/link.js +21 -0
  75. package/dist/operations/commands/list.d.ts +126 -0
  76. package/dist/operations/commands/list.js +652 -0
  77. package/dist/operations/commands/mermaidBlock.d.ts +9 -0
  78. package/dist/operations/commands/mermaidBlock.js +28 -0
  79. package/dist/operations/commands/section.d.ts +217 -0
  80. package/dist/operations/commands/section.js +865 -0
  81. package/dist/operations/commands/sectionFold.d.ts +36 -0
  82. package/dist/operations/commands/sectionFold.js +219 -0
  83. package/dist/operations/commands/sectionJump.d.ts +8 -0
  84. package/dist/operations/commands/sectionJump.js +144 -0
  85. package/dist/operations/commands/selectedBlock.d.ts +37 -0
  86. package/dist/operations/commands/selectedBlock.js +170 -0
  87. package/dist/operations/commands/table.d.ts +64 -0
  88. package/dist/operations/commands/table.js +437 -0
  89. package/dist/operations/keymap/assemble.d.ts +22 -0
  90. package/dist/operations/keymap/assemble.js +165 -0
  91. package/dist/operations/keymap/coreActions.d.ts +2 -0
  92. package/dist/operations/keymap/coreActions.js +711 -0
  93. package/dist/operations/keymap/menuItems.d.ts +52 -0
  94. package/dist/operations/keymap/menuItems.js +114 -0
  95. package/dist/operations/keymap/shortcutKeys.d.ts +42 -0
  96. package/dist/operations/keymap/shortcutKeys.js +114 -0
  97. package/dist/operations/keymap/viewActions.d.ts +30 -0
  98. package/dist/operations/keymap/viewActions.js +182 -0
  99. package/dist/operations/operations.types.d.ts +121 -0
  100. package/dist/operations/operations.types.js +1 -0
  101. package/dist/operations/plugins/blockHandle.d.ts +25 -0
  102. package/dist/operations/plugins/blockHandle.js +112 -0
  103. package/dist/operations/plugins/contextMenu.d.ts +33 -0
  104. package/dist/operations/plugins/contextMenu.js +204 -0
  105. package/dist/operations/plugins/focus.d.ts +39 -0
  106. package/dist/operations/plugins/focus.js +350 -0
  107. package/dist/operations/plugins/foldClick.d.ts +11 -0
  108. package/dist/operations/plugins/foldClick.js +117 -0
  109. package/dist/operations/plugins/foldGuard.d.ts +15 -0
  110. package/dist/operations/plugins/foldGuard.js +31 -0
  111. package/dist/operations/plugins/frontMatterGuard.d.ts +21 -0
  112. package/dist/operations/plugins/frontMatterGuard.js +150 -0
  113. package/dist/operations/plugins/frontMatterView.d.ts +34 -0
  114. package/dist/operations/plugins/frontMatterView.js +137 -0
  115. package/dist/operations/plugins/linkPaste.d.ts +3 -0
  116. package/dist/operations/plugins/linkPaste.js +20 -0
  117. package/dist/operations/plugins/listStructure.d.ts +13 -0
  118. package/dist/operations/plugins/listStructure.js +18 -0
  119. package/dist/operations/plugins/markdownClipboard.d.ts +8 -0
  120. package/dist/operations/plugins/markdownClipboard.js +208 -0
  121. package/dist/operations/plugins/mermaidView.d.ts +20 -0
  122. package/dist/operations/plugins/mermaidView.js +206 -0
  123. package/dist/operations/plugins/requiredSelectionEntry.d.ts +10 -0
  124. package/dist/operations/plugins/requiredSelectionEntry.js +124 -0
  125. package/dist/operations/plugins/sectionView.d.ts +12 -0
  126. package/dist/operations/plugins/sectionView.js +44 -0
  127. package/dist/operations/plugins/tabEscape.d.ts +21 -0
  128. package/dist/operations/plugins/tabEscape.js +41 -0
  129. package/dist/operations/plugins/tableHandles.d.ts +24 -0
  130. package/dist/operations/plugins/tableHandles.js +89 -0
  131. package/dist/operations/transaction.d.ts +26 -0
  132. package/dist/operations/transaction.js +51 -0
  133. package/dist/operations/transactionOrigin.d.ts +17 -0
  134. package/dist/operations/transactionOrigin.js +9 -0
  135. package/dist/states/contextMenuController.svelte.d.ts +57 -0
  136. package/dist/states/contextMenuController.svelte.js +206 -0
  137. package/dist/states/editorSession.d.ts +12 -0
  138. package/dist/states/editorSession.js +268 -0
  139. package/dist/states/editorSession.types.d.ts +57 -0
  140. package/dist/states/editorSession.types.js +1 -0
  141. package/dist/states/outlineViewController.svelte.d.ts +52 -0
  142. package/dist/states/outlineViewController.svelte.js +134 -0
  143. package/dist/utils/dateText.d.ts +25 -0
  144. package/dist/utils/dateText.js +71 -0
  145. package/dist/utils/geometry.types.d.ts +13 -0
  146. package/dist/utils/geometry.types.js +1 -0
  147. package/dist/utils/json.types.d.ts +4 -0
  148. package/dist/utils/json.types.js +1 -0
  149. package/dist/utils/platform.d.ts +8 -0
  150. package/dist/utils/platform.js +10 -0
  151. package/dist/utils/result.types.d.ts +7 -0
  152. package/dist/utils/result.types.js +1 -0
  153. package/package.json +109 -0
@@ -0,0 +1,157 @@
1
+ <!--
2
+ ダイアログ。`Modal` の上に、見出し・本文・脚の枠組みを載せる。
3
+ `scrollable` のときはヘッダーとフッターを固定し、本文だけを巻き取る。
4
+ -->
5
+ <script lang="ts">
6
+ import type { Snippet } from 'svelte';
7
+ import Modal from './Modal.svelte';
8
+
9
+ interface Props {
10
+ header?: Snippet;
11
+ children?: Snippet;
12
+ footer?: Snippet;
13
+ title?: string;
14
+ /** dialog 要素へ足すクラス(外から指す・見た目を上書きするための印) */
15
+ class?: string;
16
+ /** CSS の幅(例: 'min(40em, 90vw)') */
17
+ width?: string;
18
+ /** 本文が収まらないとき、ヘッダー・フッターを固定して本文だけをスクロールさせる */
19
+ scrollable?: boolean;
20
+ closeIfClickOutside?: boolean;
21
+ ariaLabel?: string;
22
+ /** 閉じたときの通知。閉じる経路によらず 1 度呼ばれる */
23
+ onClose?: () => void;
24
+ }
25
+
26
+ let {
27
+ header,
28
+ children,
29
+ footer,
30
+ title = '',
31
+ class: className = '',
32
+ width = '20em',
33
+ scrollable = false,
34
+ closeIfClickOutside = true,
35
+ ariaLabel,
36
+ onClose
37
+ }: Props = $props();
38
+
39
+ let modalRef: Modal;
40
+
41
+ export function open(): void {
42
+ modalRef?.open();
43
+ }
44
+
45
+ export function close(): void {
46
+ modalRef?.close();
47
+ }
48
+ </script>
49
+
50
+ <Modal
51
+ bind:this={modalRef}
52
+ class={className}
53
+ style={`width: ${width}; border-radius: var(--markdown-editor-radius); overflow: hidden;`}
54
+ {closeIfClickOutside}
55
+ ariaLabel={ariaLabel ?? title}
56
+ {onClose}
57
+ >
58
+ <div class="dialog {scrollable ? 'dialog--scrollable' : ''}">
59
+ {#if header || title}
60
+ <div class="dialog__header">
61
+ {#if header}
62
+ {@render header()}
63
+ {:else}
64
+ <div class="dialog__title">{title}</div>
65
+ {/if}
66
+ </div>
67
+ {/if}
68
+ {#if children}
69
+ <div class="dialog__body">
70
+ {@render children()}
71
+ </div>
72
+ {/if}
73
+ {#if footer}
74
+ <div class="dialog__footer">
75
+ {@render footer()}
76
+ </div>
77
+ {/if}
78
+ </div>
79
+ </Modal>
80
+
81
+ <style>
82
+ .dialog {
83
+ display: flex;
84
+ flex-direction: column;
85
+ justify-content: stretch;
86
+ border: 1px solid var(--markdown-editor-dialog-border);
87
+ border-radius: var(--markdown-editor-radius);
88
+ max-height: calc(100dvh - 2em - 6px);
89
+ overflow: auto;
90
+ font-family: var(--markdown-editor-font);
91
+ }
92
+
93
+ /*
94
+ * グローバルの `* { box-sizing: border-box }` を敷けないモジュールなので、
95
+ * その前提をこのブロックの中へ持ち込む(56px は padding 込みの高さ)。
96
+ */
97
+ .dialog,
98
+ .dialog *,
99
+ .dialog *::before,
100
+ .dialog *::after {
101
+ box-sizing: border-box;
102
+ }
103
+
104
+ .dialog__header {
105
+ display: flex;
106
+ gap: 16px;
107
+ align-items: center;
108
+ justify-content: stretch;
109
+ min-height: 56px;
110
+ padding: 16px 24px;
111
+ }
112
+
113
+ .dialog__title {
114
+ flex-grow: 1;
115
+ font-size: var(--markdown-editor-font-size-xl);
116
+ line-height: normal;
117
+ color: var(--markdown-editor-dialog-title-color);
118
+ }
119
+
120
+ /**
121
+ * **左右の空きは持たない。** 中身の箱がそのぶん内側へ寄ると、中身が引く区切りの線が
122
+ * 箱の端まで届かなくなる。左右は中身の側が
123
+ * `--markdown-editor-dialog-inset` で取る。
124
+ */
125
+ .dialog__body {
126
+ flex-shrink: 1;
127
+ position: relative;
128
+ padding: 0 0 var(--markdown-editor-dialog-inset);
129
+ }
130
+
131
+ .dialog__footer {
132
+ display: flex;
133
+ gap: 8px;
134
+ justify-content: end;
135
+ padding: 8px;
136
+ }
137
+
138
+ /* scrollable のとき: ヘッダー・フッター固定 + 本文のみスクロール */
139
+ .dialog--scrollable {
140
+ overflow: hidden;
141
+ }
142
+
143
+ .dialog--scrollable .dialog__header {
144
+ margin-bottom: 0;
145
+ border-bottom: 1px solid var(--markdown-editor-dialog-divider);
146
+ }
147
+
148
+ .dialog--scrollable .dialog__body {
149
+ flex-shrink: 1;
150
+ padding: var(--markdown-editor-dialog-inset) 0;
151
+ overflow: auto;
152
+ }
153
+
154
+ .dialog--scrollable .dialog__footer {
155
+ border-top: 1px solid var(--markdown-editor-dialog-divider);
156
+ }
157
+ </style>
@@ -0,0 +1,23 @@
1
+ import type { Snippet } from 'svelte';
2
+ interface Props {
3
+ header?: Snippet;
4
+ children?: Snippet;
5
+ footer?: Snippet;
6
+ title?: string;
7
+ /** dialog 要素へ足すクラス(外から指す・見た目を上書きするための印) */
8
+ class?: string;
9
+ /** CSS の幅(例: 'min(40em, 90vw)') */
10
+ width?: string;
11
+ /** 本文が収まらないとき、ヘッダー・フッターを固定して本文だけをスクロールさせる */
12
+ scrollable?: boolean;
13
+ closeIfClickOutside?: boolean;
14
+ ariaLabel?: string;
15
+ /** 閉じたときの通知。閉じる経路によらず 1 度呼ばれる */
16
+ onClose?: () => void;
17
+ }
18
+ declare const Dialog: import("svelte").Component<Props, {
19
+ open: () => void;
20
+ close: () => void;
21
+ }, "">;
22
+ type Dialog = ReturnType<typeof Dialog>;
23
+ export default Dialog;
@@ -0,0 +1,181 @@
1
+ <!--
2
+ ネイティブの `dialog` を土台にした覆い。開閉は命令的 API(open / close)で受ける。
3
+
4
+ `Escape` は `cancel` イベントで受け、ネイティブの即時 close を止めてフェードアウトを
5
+ 経てから閉じる。
6
+ -->
7
+ <script lang="ts">
8
+ import type { Snippet } from 'svelte';
9
+
10
+ interface Props {
11
+ children?: Snippet;
12
+ /** dialog 要素へ足すクラス(外から指す・見た目を上書きするための印) */
13
+ class?: string;
14
+ style?: string;
15
+ /** 背景(backdrop)のクリックで閉じる */
16
+ closeIfClickOutside?: boolean;
17
+ ariaLabel?: string;
18
+ /** 閉じたときの通知。閉じる経路(ボタン・背景・Escape)によらず 1 度呼ばれる */
19
+ onClose?: () => void;
20
+ }
21
+
22
+ let {
23
+ children,
24
+ class: className = '',
25
+ style = '',
26
+ closeIfClickOutside = true,
27
+ ariaLabel,
28
+ onClose
29
+ }: Props = $props();
30
+
31
+ let dialogRef: HTMLDialogElement | undefined = $state();
32
+ let contentsRef: HTMLDivElement | undefined = $state();
33
+
34
+ /** 独立したダイアログとして開く(キーボードの操作対象が中に限られる) */
35
+ export function open(): void {
36
+ if (!dialogRef || dialogRef.open) return;
37
+ // 閉じの途中で開き直されたら、進行中の閉じを取り消す
38
+ dialogRef.removeEventListener('animationend', finishClose);
39
+ dialogRef.classList.remove('fade-out');
40
+ dialogRef.showModal();
41
+ // showModal は最初のフォーカス可能要素へ移り、その位置までスクロールしてしまう。
42
+ // コンテナ自身へ移せば、開いた直後は必ず先頭が見える
43
+ dialogRef.focus();
44
+ }
45
+
46
+ /** フェードアウトを始める。実際に閉じるのはアニメーション完了時 */
47
+ export function close(): void {
48
+ if (!dialogRef?.open) return;
49
+ if (dialogRef.classList.contains('fade-out')) return;
50
+ dialogRef.classList.add('fade-out');
51
+ dialogRef.addEventListener('animationend', finishClose, { once: true });
52
+ }
53
+
54
+ function finishClose(): void {
55
+ if (!dialogRef) return;
56
+ dialogRef.classList.remove('fade-out');
57
+ if (dialogRef.open) dialogRef.close();
58
+ }
59
+
60
+ /** 背景のクリックは、ヒットテスト上 dialog 要素自身が対象になる(中身の外) */
61
+ function handleClick(event: MouseEvent): void {
62
+ if (!closeIfClickOutside || !contentsRef) return;
63
+ if (!contentsRef.contains(event.target as Node)) close();
64
+ }
65
+
66
+ /** Escape。ネイティブの即時 close を止め、フェードアウトを経て閉じる */
67
+ function handleCancel(event: Event): void {
68
+ event.preventDefault();
69
+ close();
70
+ }
71
+
72
+ /** Tab を中で循環させる */
73
+ function handleKeydown(event: KeyboardEvent): void {
74
+ if (event.key !== 'Tab' || !dialogRef) return;
75
+
76
+ const focusable = dialogRef.querySelectorAll<HTMLElement>(
77
+ 'button, [href], input, select, textarea, [tabindex]:not([tabindex="-1"])'
78
+ );
79
+ if (focusable.length === 0) return;
80
+
81
+ const first = focusable[0];
82
+ const last = focusable[focusable.length - 1];
83
+ if (event.shiftKey && document.activeElement === first) {
84
+ event.preventDefault();
85
+ last.focus();
86
+ } else if (!event.shiftKey && document.activeElement === last) {
87
+ event.preventDefault();
88
+ first.focus();
89
+ }
90
+ }
91
+ </script>
92
+
93
+ <dialog
94
+ bind:this={dialogRef}
95
+ class="modal {className}"
96
+ {style}
97
+ tabindex="-1"
98
+ aria-label={ariaLabel}
99
+ onclick={handleClick}
100
+ onkeydown={handleKeydown}
101
+ oncancel={handleCancel}
102
+ onclose={onClose}
103
+ >
104
+ <div class="modal-contents" bind:this={contentsRef}>
105
+ {@render children?.()}
106
+ </div>
107
+ </dialog>
108
+
109
+ <style>
110
+ .modal {
111
+ padding: 0;
112
+ border-width: 0;
113
+ background-color: var(--markdown-editor-dialog-background);
114
+ color: var(--markdown-editor-dialog-text);
115
+ box-shadow:
116
+ 0 11px 15px -7px rgb(0 0 0 / 20%),
117
+ 0 24px 38px 3px rgb(0 0 0 / 14%),
118
+ 0 9px 46px 8px rgb(0 0 0 / 12%);
119
+ }
120
+
121
+ .modal::backdrop {
122
+ position: fixed;
123
+ inset: 0;
124
+ background: var(--markdown-editor-dialog-backdrop);
125
+ }
126
+
127
+ .modal:focus {
128
+ outline: none;
129
+ }
130
+
131
+ .modal-contents {
132
+ width: 100%;
133
+ height: 100%;
134
+ display: flex;
135
+ flex-direction: column;
136
+ }
137
+
138
+ @keyframes fade-in {
139
+ from {
140
+ opacity: 0;
141
+ }
142
+ to {
143
+ opacity: 1;
144
+ }
145
+ }
146
+
147
+ @keyframes fade-out {
148
+ from {
149
+ opacity: 1;
150
+ }
151
+ to {
152
+ opacity: 0;
153
+ }
154
+ }
155
+
156
+ .modal[open] {
157
+ animation: fade-in 300ms forwards;
158
+ }
159
+
160
+ .modal[open]::backdrop {
161
+ animation: fade-in 300ms forwards;
162
+ }
163
+
164
+ /* 後に置く(開いたままフェードアウトが始まるため、[open] の指定に勝つ必要がある) */
165
+ .modal.fade-out {
166
+ animation: fade-out 300ms forwards;
167
+ }
168
+
169
+ .modal.fade-out::backdrop {
170
+ animation: fade-out 300ms forwards;
171
+ }
172
+
173
+ @media (prefers-reduced-motion: reduce) {
174
+ .modal[open],
175
+ .modal[open]::backdrop,
176
+ .modal.fade-out,
177
+ .modal.fade-out::backdrop {
178
+ animation-duration: 0.01s;
179
+ }
180
+ }
181
+ </style>
@@ -0,0 +1,18 @@
1
+ import type { Snippet } from 'svelte';
2
+ interface Props {
3
+ children?: Snippet;
4
+ /** dialog 要素へ足すクラス(外から指す・見た目を上書きするための印) */
5
+ class?: string;
6
+ style?: string;
7
+ /** 背景(backdrop)のクリックで閉じる */
8
+ closeIfClickOutside?: boolean;
9
+ ariaLabel?: string;
10
+ /** 閉じたときの通知。閉じる経路(ボタン・背景・Escape)によらず 1 度呼ばれる */
11
+ onClose?: () => void;
12
+ }
13
+ declare const Modal: import("svelte").Component<Props, {
14
+ open: () => void;
15
+ close: () => void;
16
+ }, "">;
17
+ type Modal = ReturnType<typeof Modal>;
18
+ export default Modal;
@@ -0,0 +1,248 @@
1
+ <!--
2
+ 最前面へ出すコンテナ。`popover="manual"` で重ね、錨の矩形(AnchorRect)に対して置く。
3
+ 錨を要素ではなく矩形で受けるのは、ポインタの座標と要素の箱を同じ型に落とすため。
4
+
5
+ 開閉は `open` prop で受ける(状態はエディタ 1 つにつき 1 つのコントローラが持つ)。
6
+ スクロール・リサイズで閉じたいことは `onClose` で外へ伝えるだけで、自分では閉じない。
7
+ -->
8
+ <script lang="ts">
9
+ import type { Snippet } from 'svelte';
10
+
11
+ import type { AnchorRect } from '../../utils/geometry.types';
12
+
13
+ interface Props {
14
+ children: Snippet;
15
+ /** 錨の矩形。開くたびに読み直す */
16
+ anchor: AnchorRect | null;
17
+ open: boolean;
18
+ /** コンテナの役割。既定は menu */
19
+ role?: string;
20
+ ariaLabel?: string;
21
+ /** いま選んでいる子要素の id。中身の側は実フォーカスもそこへ移す */
22
+ ariaActivedescendant?: string;
23
+ class?: string;
24
+ /**
25
+ * 中で押されたキー。`Tab` の循環より**先**に呼ぶ。
26
+ * 既定動作を止めた(受け止めた)ときは、循環の判定へ進まない
27
+ */
28
+ onKeyDown?: (event: KeyboardEvent) => void;
29
+ /** 操作対象がポップアップの外へ移ったときの通知。中での移動では呼ばない */
30
+ onFocusOut?: () => void;
31
+ /** 外の動き(スクロール・リサイズ)で閉じたいときの通知。自分では閉じない */
32
+ onClose?: () => void;
33
+ }
34
+
35
+ let {
36
+ children,
37
+ anchor,
38
+ open,
39
+ role = 'menu',
40
+ ariaLabel,
41
+ ariaActivedescendant,
42
+ class: className = '',
43
+ onKeyDown,
44
+ onFocusOut,
45
+ onClose
46
+ }: Props = $props();
47
+
48
+ /** 錨と表示領域の端から空ける距離 */
49
+ const MARGIN = 8;
50
+
51
+ let popupRef: HTMLDivElement | undefined = $state();
52
+
53
+ $effect(() => {
54
+ const element = popupRef;
55
+ if (!element) return;
56
+
57
+ if (!open || !anchor) {
58
+ hide(element);
59
+ return;
60
+ }
61
+
62
+ show(element, anchor);
63
+ // 開いているあいだだけ、外の動きを見る
64
+ window.addEventListener('resize', requestClose);
65
+ document.addEventListener('scroll', handleScroll, true);
66
+ return () => {
67
+ window.removeEventListener('resize', requestClose);
68
+ document.removeEventListener('scroll', handleScroll, true);
69
+ };
70
+ });
71
+
72
+ function show(element: HTMLDivElement, rect: AnchorRect): void {
73
+ if (!element.matches(':popover-open')) {
74
+ element.showPopover();
75
+ // 操作対象を中へ移す。開いた直後は何も選んでいないので、行き先はコンテナになる
76
+ element.focus();
77
+ }
78
+ // 前回の寄せの跡を消してから測る(残すと 2 回目以降が前回の高さに縛られる)
79
+ element.style.maxHeight = '';
80
+ element.style.overflowY = '';
81
+ place(element, rect);
82
+ }
83
+
84
+ function hide(element: HTMLDivElement): void {
85
+ if (element.matches(':popover-open')) element.hidePopover();
86
+ }
87
+
88
+ /**
89
+ * 錨の**右上**に置き、表示領域からはみ出すときは中へ寄せる。
90
+ * 高さが収まらないときは、押し込めるだけ押し込んで中をスクロールさせる。
91
+ *
92
+ * 右へ出すのは、錨そのもの(対象にしている行)を覆わないためである。
93
+ * 上端をそろえるので、どの行に対して開いたのかが目で追える。
94
+ */
95
+ function place(element: HTMLDivElement, rect: AnchorRect): void {
96
+ const box = element.getBoundingClientRect();
97
+ const viewport = { width: window.innerWidth, height: window.innerHeight };
98
+
99
+ let top = rect.top;
100
+ // 下に入らず、上のほうが広ければ、錨の下端に合わせて上へ返す
101
+ const below = viewport.height - top - MARGIN;
102
+ const above = rect.bottom - MARGIN * 2;
103
+ if (box.height > below && above > below) top = rect.bottom - box.height;
104
+
105
+ const left = clamp(rect.right + MARGIN, MARGIN, viewport.width - box.width - MARGIN);
106
+ top = clamp(top, MARGIN, viewport.height - box.height - MARGIN);
107
+
108
+ const available = viewport.height - top - MARGIN;
109
+ if (box.height > available) {
110
+ element.style.maxHeight = `${available}px`;
111
+ element.style.overflowY = 'auto';
112
+ }
113
+
114
+ element.style.transform = `translate(${left}px, ${top}px)`;
115
+ }
116
+
117
+ /** 収まらない値を渡されたら手前の端に付ける(`max < min` でも表示領域の外へ出さない) */
118
+ function clamp(value: number, min: number, max: number): number {
119
+ return Math.max(min, Math.min(value, max));
120
+ }
121
+
122
+ function requestClose(): void {
123
+ onClose?.();
124
+ }
125
+
126
+ /** 中身のスクロールは閉じるきっかけにしない */
127
+ function handleScroll(event: Event): void {
128
+ const target = event.target;
129
+ if (target instanceof Node && popupRef?.contains(target)) return;
130
+ requestClose();
131
+ }
132
+
133
+ /** 移り先がポップアップの中なら、外へ出たことにはしない */
134
+ function handleFocusOut(event: FocusEvent): void {
135
+ const next = event.relatedTarget;
136
+ if (next instanceof Node && popupRef?.contains(next)) return;
137
+ onFocusOut?.();
138
+ }
139
+
140
+ /** 中で押されたキー。使う側へ先に渡し、残りは Tab の循環だけを見る */
141
+ function handleKeydown(event: KeyboardEvent): void {
142
+ onKeyDown?.(event);
143
+ if (event.defaultPrevented) return;
144
+ cycleTab(event);
145
+ }
146
+
147
+ /** Tab を中で循環させる */
148
+ function cycleTab(event: KeyboardEvent): void {
149
+ if (event.key !== 'Tab' || !popupRef) return;
150
+
151
+ const focusable = popupRef.querySelectorAll<HTMLElement>(
152
+ 'button, [href], input, select, textarea, [tabindex]:not([tabindex="-1"])'
153
+ );
154
+ if (focusable.length === 0) return;
155
+
156
+ const first = focusable[0];
157
+ const last = focusable[focusable.length - 1];
158
+ if (event.shiftKey && document.activeElement === first) {
159
+ event.preventDefault();
160
+ last.focus();
161
+ } else if (!event.shiftKey && document.activeElement === last) {
162
+ event.preventDefault();
163
+ first.focus();
164
+ }
165
+ }
166
+ </script>
167
+
168
+ <div
169
+ bind:this={popupRef}
170
+ popover="manual"
171
+ class="markdown-editor-popup {className}"
172
+ {role}
173
+ tabindex="-1"
174
+ aria-label={ariaLabel}
175
+ aria-activedescendant={ariaActivedescendant}
176
+ onkeydown={handleKeydown}
177
+ onfocusout={handleFocusOut}
178
+ >
179
+ {@render children()}
180
+ </div>
181
+
182
+ <style>
183
+ /*
184
+ * 位置は transform で与える。`inset` と `margin` は popover の既定(中央寄せ)を
185
+ * 打ち消すために置き直す。
186
+ */
187
+ .markdown-editor-popup {
188
+ position: fixed;
189
+ inset: 0 auto auto 0;
190
+ margin: 0;
191
+ padding: 0;
192
+ border: 1px solid var(--markdown-editor-popup-border);
193
+ border-radius: var(--markdown-editor-radius);
194
+ background: var(--markdown-editor-popup-background);
195
+ color: var(--markdown-editor-popup-text);
196
+ font-family: var(--markdown-editor-font);
197
+ box-shadow:
198
+ 0 11px 15px -7px rgb(0 0 0 / 20%),
199
+ 0 24px 38px 3px rgb(0 0 0 / 14%),
200
+ 0 9px 46px 8px rgb(0 0 0 / 12%);
201
+ overflow: hidden;
202
+ /*
203
+ * 巻き取りを中で止める。端まで来た続きが背後のページへ流れると、
204
+ * ページが動いたぶんを**外側のスクロール**として受け取り(→ handleScroll)、
205
+ * 中を読んでいるだけなのに閉じてしまう。
206
+ */
207
+ overscroll-behavior: contain;
208
+ }
209
+
210
+ /*
211
+ * グローバルの `* { box-sizing: border-box }` を敷けないモジュールなので、
212
+ * その前提をこの中へ持ち込む。
213
+ */
214
+ .markdown-editor-popup,
215
+ .markdown-editor-popup :global(*),
216
+ .markdown-editor-popup :global(*::before),
217
+ .markdown-editor-popup :global(*::after) {
218
+ box-sizing: border-box;
219
+ }
220
+
221
+ .markdown-editor-popup:focus {
222
+ outline: none;
223
+ }
224
+
225
+ @keyframes fade-in {
226
+ from {
227
+ opacity: 0;
228
+ }
229
+ to {
230
+ opacity: 1;
231
+ }
232
+ }
233
+
234
+ /*
235
+ * 開いたときだけ動かす。**動かすのは不透明度だけ**にする。
236
+ * 位置は inline の transform で与えており、アニメーションは inline より強いため、
237
+ * transform を動かすと再生中だけ別の場所へ飛ぶ。
238
+ */
239
+ .markdown-editor-popup:popover-open {
240
+ animation: fade-in 120ms forwards;
241
+ }
242
+
243
+ @media (prefers-reduced-motion: reduce) {
244
+ .markdown-editor-popup:popover-open {
245
+ animation-duration: 0.01s;
246
+ }
247
+ }
248
+ </style>
@@ -0,0 +1,26 @@
1
+ import type { Snippet } from 'svelte';
2
+ import type { AnchorRect } from '../../utils/geometry.types';
3
+ interface Props {
4
+ children: Snippet;
5
+ /** 錨の矩形。開くたびに読み直す */
6
+ anchor: AnchorRect | null;
7
+ open: boolean;
8
+ /** コンテナの役割。既定は menu */
9
+ role?: string;
10
+ ariaLabel?: string;
11
+ /** いま選んでいる子要素の id。中身の側は実フォーカスもそこへ移す */
12
+ ariaActivedescendant?: string;
13
+ class?: string;
14
+ /**
15
+ * 中で押されたキー。`Tab` の循環より**先**に呼ぶ。
16
+ * 既定動作を止めた(受け止めた)ときは、循環の判定へ進まない
17
+ */
18
+ onKeyDown?: (event: KeyboardEvent) => void;
19
+ /** 操作対象がポップアップの外へ移ったときの通知。中での移動では呼ばない */
20
+ onFocusOut?: () => void;
21
+ /** 外の動き(スクロール・リサイズ)で閉じたいときの通知。自分では閉じない */
22
+ onClose?: () => void;
23
+ }
24
+ declare const Popup: import("svelte").Component<Props, {}, "">;
25
+ type Popup = ReturnType<typeof Popup>;
26
+ export default Popup;
@@ -0,0 +1,32 @@
1
+ /**
2
+ * 公開 API のエントリ。
3
+ *
4
+ * ここから export したものだけが利用者に見える。文書モデル(ProseMirror のスキーマ・
5
+ * プラグイン・コマンド)は内部実装であり、公開しない。export したものは互換性の約束になる。
6
+ */
7
+ export { default as MarkdownEditor } from './components/MarkdownEditor.svelte';
8
+ export type { MarkdownEditorProps, MarkdownEditorApi } from './components/MarkdownEditor.svelte';
9
+ export { en, ja } from './messages';
10
+ export type { EditorMessages, EditorMessagesOverride, EditorLang, EditorShortcutCategory } from './messages/messages.types';
11
+ export type { ViewState, ViewSectionRef } from './models/viewState/viewState.types';
12
+ /**
13
+ * マークダウン文字列を、エディタを置かずに読み書きするための純関数。
14
+ *
15
+ * - `readFrontMatterField`: 指定した項目の値。一覧のような場所でタイトルを出すために使う
16
+ * - `readFrontMatterFields`: フロントマターの全項目。何が書かれているかをキーを知らずに読む
17
+ * - `readBody`: フロントマターを除いた本文
18
+ * - `readBodyBlocks`: 本文のブロックの並び。種別・本文の中での範囲・見出しの経路を返す
19
+ * - `readPlainText`: インラインの記法を落とした読める文字列
20
+ * - `writeFrontMatterFields`: 項目の書き込み。キーと JSON の値を渡し、区切り・引用・
21
+ * 改行・差し込む位置はモジュールが持つ
22
+ *
23
+ * **どれも「マークダウンをどう読むか」の規則である。** 利用側に書けば同じ解釈が 2 か所に
24
+ * 生まれる——何をフロントマターと見なすかの素朴な規則は水平線で始まる文書を食い、記法を
25
+ * 落とす正規表現の表は入れ子の記法とエスケープで取りこぼす。
26
+ *
27
+ * 項目の値は文字列のまま返し、**型として解釈しない**。これが、利用者がモジュールを
28
+ * YAML の解析器として扱い始めるのを避けるための境界である。
29
+ */
30
+ export { readBody, readBodyBlocks, readFrontMatterField, readFrontMatterFields, readPlainText, writeFrontMatterFields } from './markdown';
31
+ export type { FrontMatterFields, FrontMatterValues, FrontMatterWriteError, FrontMatterWriteOutcome, JsonValue, MarkdownBlock, MarkdownBlockKind, Result } from './markdown';
32
+ export type { MarkdownParseError } from './models/markdown/markdown.types';