@moda-editor/core 0.1.3 → 0.1.5
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/collab.d.ts +61 -0
- package/dist/collab.d.ts.map +1 -0
- package/dist/collab.js +67 -0
- package/dist/collab.js.map +1 -0
- package/dist/commands.d.ts +11 -0
- package/dist/commands.d.ts.map +1 -1
- package/dist/commands.js +48 -4
- package/dist/commands.js.map +1 -1
- package/dist/conformance/editor-base.d.ts +7 -0
- package/dist/conformance/editor-base.d.ts.map +1 -0
- package/dist/conformance/editor-base.js +280 -0
- package/dist/conformance/editor-base.js.map +1 -0
- package/dist/conformance/editor-codeblock.d.ts +8 -0
- package/dist/conformance/editor-codeblock.d.ts.map +1 -0
- package/dist/conformance/editor-codeblock.js +402 -0
- package/dist/conformance/editor-codeblock.js.map +1 -0
- package/dist/conformance/editor-ime.d.ts +7 -0
- package/dist/conformance/editor-ime.d.ts.map +1 -0
- package/dist/conformance/editor-ime.js +166 -0
- package/dist/conformance/editor-ime.js.map +1 -0
- package/dist/conformance/editor-input.d.ts +8 -0
- package/dist/conformance/editor-input.d.ts.map +1 -0
- package/dist/conformance/editor-input.js +676 -0
- package/dist/conformance/editor-input.js.map +1 -0
- package/dist/conformance/editor-nodeview.d.ts +7 -0
- package/dist/conformance/editor-nodeview.d.ts.map +1 -0
- package/dist/conformance/editor-nodeview.js +120 -0
- package/dist/conformance/editor-nodeview.js.map +1 -0
- package/dist/conformance/editor-overlay.d.ts +8 -0
- package/dist/conformance/editor-overlay.d.ts.map +1 -0
- package/dist/conformance/editor-overlay.js +323 -0
- package/dist/conformance/editor-overlay.js.map +1 -0
- package/dist/conformance/fixtures.d.ts +4 -0
- package/dist/conformance/fixtures.d.ts.map +1 -0
- package/dist/conformance/fixtures.js +15 -0
- package/dist/conformance/fixtures.js.map +1 -0
- package/dist/conformance/index.d.ts +14 -0
- package/dist/conformance/index.d.ts.map +1 -0
- package/dist/conformance/index.js +28 -0
- package/dist/conformance/index.js.map +1 -0
- package/dist/conformance/types.d.ts +51 -0
- package/dist/conformance/types.d.ts.map +1 -0
- package/dist/conformance/types.js +2 -0
- package/dist/conformance/types.js.map +1 -0
- package/dist/conformance/widget.d.ts +3 -0
- package/dist/conformance/widget.d.ts.map +1 -0
- package/dist/conformance/widget.js +49 -0
- package/dist/conformance/widget.js.map +1 -0
- package/dist/conformance.d.ts +1 -58
- package/dist/conformance.d.ts.map +1 -1
- package/dist/conformance.js +3 -1748
- package/dist/conformance.js.map +1 -1
- package/dist/editor/extension.d.ts +47 -3
- package/dist/editor/extension.d.ts.map +1 -1
- package/dist/features/ace.d.ts +4 -0
- package/dist/features/ace.d.ts.map +1 -1
- package/dist/features/ace.js +34 -13
- package/dist/features/ace.js.map +1 -1
- package/dist/features/block-dnd.d.ts +7 -0
- package/dist/features/block-dnd.d.ts.map +1 -0
- package/dist/features/block-dnd.js +207 -0
- package/dist/features/block-dnd.js.map +1 -0
- package/dist/features/code-block.d.ts +9 -84
- package/dist/features/code-block.d.ts.map +1 -1
- package/dist/features/code-block.js +37 -1027
- package/dist/features/code-block.js.map +1 -1
- package/dist/features/code-context.d.ts +81 -0
- package/dist/features/code-context.d.ts.map +1 -0
- package/dist/features/code-context.js +322 -0
- package/dist/features/code-context.js.map +1 -0
- package/dist/features/code-edit.d.ts +50 -0
- package/dist/features/code-edit.d.ts.map +1 -0
- package/dist/features/code-edit.js +412 -0
- package/dist/features/code-edit.js.map +1 -0
- package/dist/features/code-format.d.ts +21 -0
- package/dist/features/code-format.d.ts.map +1 -0
- package/dist/features/code-format.js +410 -0
- package/dist/features/code-format.js.map +1 -0
- package/dist/features/doc.d.ts.map +1 -1
- package/dist/features/doc.js +1 -1
- package/dist/features/doc.js.map +1 -1
- package/dist/features/heading.d.ts.map +1 -1
- package/dist/features/heading.js.map +1 -1
- package/dist/features/image.d.ts.map +1 -1
- package/dist/features/image.js +11 -2
- package/dist/features/image.js.map +1 -1
- package/dist/features/index.d.ts +7 -0
- package/dist/features/index.d.ts.map +1 -1
- package/dist/features/index.js +16 -0
- package/dist/features/index.js.map +1 -1
- package/dist/features/inline-style.d.ts.map +1 -1
- package/dist/features/inline-style.js +4 -1
- package/dist/features/inline-style.js.map +1 -1
- package/dist/features/link.d.ts.map +1 -1
- package/dist/features/link.js +1 -1
- package/dist/features/link.js.map +1 -1
- package/dist/features/markdown.d.ts +15 -0
- package/dist/features/markdown.d.ts.map +1 -0
- package/dist/features/markdown.js +80 -0
- package/dist/features/markdown.js.map +1 -0
- package/dist/features/marks.d.ts.map +1 -1
- package/dist/features/marks.js +49 -4
- package/dist/features/marks.js.map +1 -1
- package/dist/features/mention.d.ts +30 -0
- package/dist/features/mention.d.ts.map +1 -0
- package/dist/features/mention.js +89 -0
- package/dist/features/mention.js.map +1 -0
- package/dist/features/script.d.ts.map +1 -1
- package/dist/features/script.js.map +1 -1
- package/dist/features/search.d.ts +73 -0
- package/dist/features/search.d.ts.map +1 -0
- package/dist/features/search.js +252 -0
- package/dist/features/search.js.map +1 -0
- package/dist/features/shared.d.ts +69 -0
- package/dist/features/shared.d.ts.map +1 -0
- package/dist/features/shared.js +272 -0
- package/dist/features/shared.js.map +1 -0
- package/dist/features/table.d.ts.map +1 -1
- package/dist/features/table.js +17 -3
- package/dist/features/table.js.map +1 -1
- package/dist/features/testkit.d.ts.map +1 -1
- package/dist/features/testkit.js +1 -1
- package/dist/features/testkit.js.map +1 -1
- package/dist/history.d.ts.map +1 -1
- package/dist/history.js +65 -20
- package/dist/history.js.map +1 -1
- package/dist/index.d.ts +19 -7
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +16 -6
- package/dist/index.js.map +1 -1
- package/dist/model/schema.d.ts.map +1 -1
- package/dist/model/schema.js +2 -1
- package/dist/model/schema.js.map +1 -1
- package/dist/parse/html.d.ts.map +1 -1
- package/dist/parse/html.js +38 -6
- package/dist/parse/html.js.map +1 -1
- package/dist/parse/sanitize.d.ts.map +1 -1
- package/dist/parse/sanitize.js +4 -1
- package/dist/parse/sanitize.js.map +1 -1
- package/dist/presets/highlight.d.ts.map +1 -1
- package/dist/presets/highlight.js +1 -4
- package/dist/presets/highlight.js.map +1 -1
- package/dist/presets/markdown-parse.d.ts +13 -0
- package/dist/presets/markdown-parse.d.ts.map +1 -0
- package/dist/presets/markdown-parse.js +398 -0
- package/dist/presets/markdown-parse.js.map +1 -0
- package/dist/presets/markdown.d.ts +45 -0
- package/dist/presets/markdown.d.ts.map +1 -0
- package/dist/presets/markdown.js +195 -0
- package/dist/presets/markdown.js.map +1 -0
- package/dist/state/apply.d.ts.map +1 -1
- package/dist/state/apply.js +19 -11
- package/dist/state/apply.js.map +1 -1
- package/dist/state/delete-ops.d.ts +34 -0
- package/dist/state/delete-ops.d.ts.map +1 -0
- package/dist/state/delete-ops.js +204 -0
- package/dist/state/delete-ops.js.map +1 -0
- package/dist/state/input-rules.d.ts +30 -0
- package/dist/state/input-rules.d.ts.map +1 -0
- package/dist/state/input-rules.js +70 -0
- package/dist/state/input-rules.js.map +1 -0
- package/dist/state/insert-ops.d.ts +54 -0
- package/dist/state/insert-ops.d.ts.map +1 -0
- package/dist/state/insert-ops.js +186 -0
- package/dist/state/insert-ops.js.map +1 -0
- package/dist/state/list-ops.d.ts +46 -0
- package/dist/state/list-ops.d.ts.map +1 -0
- package/dist/state/list-ops.js +231 -0
- package/dist/state/list-ops.js.map +1 -0
- package/dist/state/navigate.d.ts.map +1 -1
- package/dist/state/navigate.js +3 -1
- package/dist/state/navigate.js.map +1 -1
- package/dist/state/resolve-insert.d.ts +55 -0
- package/dist/state/resolve-insert.d.ts.map +1 -0
- package/dist/state/resolve-insert.js +118 -0
- package/dist/state/resolve-insert.js.map +1 -0
- package/dist/state/slice-ops.d.ts +46 -0
- package/dist/state/slice-ops.d.ts.map +1 -0
- package/dist/state/slice-ops.js +150 -0
- package/dist/state/slice-ops.js.map +1 -0
- package/dist/state/state.d.ts +6 -1
- package/dist/state/state.d.ts.map +1 -1
- package/dist/state/state.js +10 -0
- package/dist/state/state.js.map +1 -1
- package/dist/state/transaction.d.ts +43 -49
- package/dist/state/transaction.d.ts.map +1 -1
- package/dist/state/transaction.js +62 -858
- package/dist/state/transaction.js.map +1 -1
- package/dist/styles.css +160 -29
- package/dist/view/adapter.d.ts +84 -0
- package/dist/view/adapter.d.ts.map +1 -0
- package/dist/view/adapter.js +76 -0
- package/dist/view/adapter.js.map +1 -0
- package/dist/view/caret.d.ts +25 -0
- package/dist/view/caret.d.ts.map +1 -0
- package/dist/view/caret.js +43 -0
- package/dist/view/caret.js.map +1 -0
- package/dist/view/decoration.d.ts +9 -0
- package/dist/view/decoration.d.ts.map +1 -0
- package/dist/view/decoration.js +214 -0
- package/dist/view/decoration.js.map +1 -0
- package/dist/view/dirty-keys.d.ts +18 -0
- package/dist/view/dirty-keys.d.ts.map +1 -0
- package/dist/view/dirty-keys.js +31 -0
- package/dist/view/dirty-keys.js.map +1 -0
- package/dist/view/dom.d.ts.map +1 -1
- package/dist/view/dom.js +7 -5
- package/dist/view/dom.js.map +1 -1
- package/dist/view/hook-ctx.d.ts +32 -0
- package/dist/view/hook-ctx.d.ts.map +1 -0
- package/dist/view/hook-ctx.js +64 -0
- package/dist/view/hook-ctx.js.map +1 -0
- package/dist/view/ime.d.ts +72 -0
- package/dist/view/ime.d.ts.map +1 -0
- package/dist/view/ime.js +185 -0
- package/dist/view/ime.js.map +1 -0
- package/dist/view/input.d.ts +12 -12
- package/dist/view/input.d.ts.map +1 -1
- package/dist/view/input.js +83 -534
- package/dist/view/input.js.map +1 -1
- package/dist/view/keys.d.ts +25 -0
- package/dist/view/keys.d.ts.map +1 -0
- package/dist/view/keys.js +106 -0
- package/dist/view/keys.js.map +1 -0
- package/dist/view/line-nav.d.ts +13 -0
- package/dist/view/line-nav.d.ts.map +1 -0
- package/dist/view/line-nav.js +114 -0
- package/dist/view/line-nav.js.map +1 -0
- package/dist/view/mount.d.ts.map +1 -1
- package/dist/view/mount.js +43 -39
- package/dist/view/mount.js.map +1 -1
- package/dist/view/node-selection.d.ts +33 -0
- package/dist/view/node-selection.d.ts.map +1 -0
- package/dist/view/node-selection.js +107 -0
- package/dist/view/node-selection.js.map +1 -0
- package/dist/view/render.d.ts +4 -1
- package/dist/view/render.d.ts.map +1 -1
- package/dist/view/render.js +13 -3
- package/dist/view/render.js.map +1 -1
- package/dist/view/serialize.d.ts.map +1 -1
- package/dist/view/serialize.js +14 -5
- package/dist/view/serialize.js.map +1 -1
- package/package.json +1 -1
package/dist/view/input.js
CHANGED
|
@@ -1,132 +1,21 @@
|
|
|
1
1
|
import { nodeAt } from "../model/traverse.js";
|
|
2
2
|
import { parseHTML } from "../parse/html.js";
|
|
3
3
|
import { pointBefore, pointAfter } from "../state/navigate.js";
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
formatStrikeThrough: "strike",
|
|
13
|
-
formatSuperscript: "superscript",
|
|
14
|
-
formatSubscript: "subscript",
|
|
15
|
-
};
|
|
16
|
-
/** drop 좌표 → doc Point — caretPositionFromPoint / Range 폴백 */
|
|
17
|
-
function caretPointFromXY(doc, root, x, y) {
|
|
18
|
-
const d = doc;
|
|
19
|
-
const pos = doc.caretPositionFromPoint?.(x, y);
|
|
20
|
-
if (pos)
|
|
21
|
-
return domToPoint(root, pos.offsetNode, pos.offset);
|
|
22
|
-
const r = d.caretRangeFromPoint?.(x, y);
|
|
23
|
-
return r ? domToPoint(root, r.startContainer, r.startOffset) : null;
|
|
24
|
-
}
|
|
25
|
-
/**
|
|
26
|
-
* 텍스트 범위가 한 블록 안에 있으면 입력 훅용 컨텍스트 — 블록을
|
|
27
|
-
* 걸치는 범위는 훅이 받지 않는다 (BlockTextCtx 계약).
|
|
28
|
-
*/
|
|
29
|
-
function blockCtx(editor, r, tr) {
|
|
30
|
-
const blockPath = r.anchor.path.slice(0, -1);
|
|
31
|
-
if (r.focus.path.length !== blockPath.length + 1 ||
|
|
32
|
-
!r.focus.path.slice(0, -1).every((v, i) => v === blockPath[i])) {
|
|
33
|
-
return null;
|
|
34
|
-
}
|
|
35
|
-
const block = nodeAt(editor.state.doc, blockPath);
|
|
36
|
-
if (!block)
|
|
37
|
-
return null;
|
|
38
|
-
return {
|
|
39
|
-
state: editor.state,
|
|
40
|
-
tr,
|
|
41
|
-
dispatch: () => editor.dispatch(tr),
|
|
42
|
-
block,
|
|
43
|
-
blockPath,
|
|
44
|
-
text: blockText(block),
|
|
45
|
-
anchor: r.anchor,
|
|
46
|
-
focus: r.focus,
|
|
47
|
-
charPoint: (off) => blockTextPoint(block, blockPath, off),
|
|
48
|
-
offsetOf: (p) => blockTextOffset(block, p),
|
|
49
|
-
};
|
|
50
|
-
}
|
|
51
|
-
/**
|
|
52
|
-
* 어댑터 공용 dirty-key 헬퍼 — binding.dirtyPaths를 소비해 블록
|
|
53
|
-
* 렌더 키를 안정적으로 버전업한다. 일반 블록은 path 그대로,
|
|
54
|
-
* 외부 DOM 변경이 있었던 블록은 path@N으로 키가 바뀌어
|
|
55
|
-
* 프레임워크가 내부 diff 대신 리마운트를 택한다.
|
|
56
|
-
*/
|
|
57
|
-
export class DirtyKeyMap {
|
|
58
|
-
constructor() {
|
|
59
|
-
Object.defineProperty(this, "versions", {
|
|
60
|
-
enumerable: true,
|
|
61
|
-
configurable: true,
|
|
62
|
-
writable: true,
|
|
63
|
-
value: new Map()
|
|
64
|
-
});
|
|
65
|
-
}
|
|
66
|
-
/** rn.path.join(",")와 binding.dirtyPaths를 넣으면 렌더 키를 반환 */
|
|
67
|
-
key(pathKey, dirty) {
|
|
68
|
-
if (dirty?.delete(pathKey)) {
|
|
69
|
-
this.versions.set(pathKey, (this.versions.get(pathKey) ?? 0) + 1);
|
|
70
|
-
}
|
|
71
|
-
const v = this.versions.get(pathKey);
|
|
72
|
-
return v ? `${pathKey}@${v}` : pathKey;
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
|
-
/** KeyboardEvent → "Mod-b"/"Shift-Enter" 형태 키 문자열 (PM 관례) */
|
|
76
|
-
const LINE_NAV_KEYS = new Set([
|
|
77
|
-
"Home",
|
|
78
|
-
"End",
|
|
79
|
-
"Shift-Home",
|
|
80
|
-
"Shift-End",
|
|
81
|
-
"Mod-ArrowLeft",
|
|
82
|
-
"Mod-ArrowRight",
|
|
83
|
-
"Mod-Shift-ArrowLeft",
|
|
84
|
-
"Mod-Shift-ArrowRight",
|
|
85
|
-
"Mod-Home",
|
|
86
|
-
"Mod-End",
|
|
87
|
-
"Mod-Shift-Home",
|
|
88
|
-
"Mod-Shift-End",
|
|
89
|
-
]);
|
|
90
|
-
function normalizeKey(e) {
|
|
91
|
-
const mods = [];
|
|
92
|
-
if (e.ctrlKey || e.metaKey)
|
|
93
|
-
mods.push("Mod");
|
|
94
|
-
if (e.altKey)
|
|
95
|
-
mods.push("Alt");
|
|
96
|
-
if (e.shiftKey)
|
|
97
|
-
mods.push("Shift");
|
|
98
|
-
const name = e.key.length === 1 ? e.key.toLowerCase() : e.key;
|
|
99
|
-
return [...mods, name].join("-");
|
|
100
|
-
}
|
|
4
|
+
import { normalizeRange, pointEq, textSelection } from "../state/selection.js";
|
|
5
|
+
import { caretPointFromXY, isLeafPoint } from "./caret.js";
|
|
6
|
+
import { applyDomSelection, domSelection, domToPoint, PATH_ATTR, } from "./dom.js";
|
|
7
|
+
import { blockCtx, dispatchFiles, rangeCtx } from "./hook-ctx.js";
|
|
8
|
+
import { createImeSession } from "./ime.js";
|
|
9
|
+
import { lineNav } from "./line-nav.js";
|
|
10
|
+
import { nodeSelectionBeforeInput, nodeSelectionKeydown, trySelectAtom, } from "./node-selection.js";
|
|
11
|
+
import { dispatchFormatInput, LINE_NAV_KEYS, normalizeKey } from "./keys.js";
|
|
101
12
|
export function bindEditorInput(editor, el) {
|
|
102
|
-
let composing = false;
|
|
103
|
-
let compStart = null;
|
|
104
|
-
let compTimer = null;
|
|
105
|
-
// compositionend가 왔고 흡수만 남은 상태 — 이 창에 도착하는 구조
|
|
106
|
-
// 입력(Enter/Backspace)은 커밋이 끝난 뒤의 것이라 브라우저에 맡기면
|
|
107
|
-
// 네이티브 split/delete가 doc 밖 DOM을 만든다
|
|
108
|
-
let pendingAbsorb = false;
|
|
109
|
-
// 실제 IME는 compositionend 뒤 같은 텍스트의 최종 커밋 beforeinput을
|
|
110
|
-
// 한 번 더 보낸다(Safari 확정, Chromium도 비동기 커밋 경로가 있다) —
|
|
111
|
-
// 타이머보다 늦게 오면 에코를 구별하기 위해 종료 시각을 기록한다
|
|
112
|
-
let compEndedAt = 0;
|
|
113
13
|
const dirtyPaths = new Set();
|
|
114
|
-
/** p가 속한 최상위 블록 경로 — 프레임워크 리마운트 대상 */
|
|
115
|
-
const topBlockKey = (p) => p?.path[0] == null ? null : String(p.path[0]);
|
|
116
|
-
/**
|
|
117
|
-
* DOM 캐럿 바로 앞 텍스트가 data로 끝나는가 — IME 커밋 에코 감지.
|
|
118
|
-
* 조합 중 브라우저가 쓴 글자가 DOM에 남아있으면 뒤에 도착하는
|
|
119
|
-
* 커밋 beforeinput은 중복이다.
|
|
120
|
-
*/
|
|
121
|
-
const domEndsWith = (focus, data) => {
|
|
122
|
-
const holder = focus.path.length
|
|
123
|
-
? el.querySelector(`[${PATH_ATTR}="${focus.path.join(",")}"]`)
|
|
124
|
-
: null;
|
|
125
|
-
if (!holder || holder.querySelector(`[${PATH_ATTR}]`))
|
|
126
|
-
return false;
|
|
127
|
-
return (holder.textContent ?? "").slice(0, focus.offset).endsWith(data);
|
|
128
|
-
};
|
|
129
14
|
const readDomSel = () => domSelection(el);
|
|
15
|
+
// IME 조합 세션 — composing/compStart/타이머/에코 판별은 전부 세션
|
|
16
|
+
// 내부다. 이 파일은 DOM 이벤트를 세션 메서드로 변환하고 판정
|
|
17
|
+
// 결과(ImeGate)에 따라 preventDefault/무시만 수행한다
|
|
18
|
+
const ime = createImeSession({ editor, el, dirtyPaths, readDomSel });
|
|
130
19
|
/**
|
|
131
20
|
* 기능 DOM 오버레이 갱신 — 활성 줄 표시·괄호 하이라이트처럼
|
|
132
21
|
* 렌더 트리가 아니라 DOM을 직접 마킹하는 것들. 각 기능이
|
|
@@ -142,8 +31,7 @@ export function bindEditorInput(editor, el) {
|
|
|
142
31
|
el.querySelectorAll(".is-selected").forEach((n) => n.classList.remove("is-selected"));
|
|
143
32
|
const sel = editor.state.selection;
|
|
144
33
|
if (sel.type === "node") {
|
|
145
|
-
el.querySelector(`[${PATH_ATTR}="${sel.path.join(",")}"]`)
|
|
146
|
-
?.classList.add("is-selected");
|
|
34
|
+
el.querySelector(`[${PATH_ATTR}="${sel.path.join(",")}"]`)?.classList.add("is-selected");
|
|
147
35
|
}
|
|
148
36
|
};
|
|
149
37
|
/**
|
|
@@ -180,20 +68,16 @@ export function bindEditorInput(editor, el) {
|
|
|
180
68
|
// setSel이 먹지 않는 역효과 방지)
|
|
181
69
|
// - 리프 포인트 — 렌더가 노드를 교체하면 Chrome이 캐럿을 요소
|
|
182
70
|
// 경계로 재앵커하는데 그건 사용자 이동이 아니라 폐기 대상이다
|
|
183
|
-
const isLeaf = (p) => nodeAt(editor.state.doc, p.path)?.type === "text";
|
|
184
71
|
if (cur &&
|
|
185
72
|
lastApplied &&
|
|
186
|
-
|
|
187
|
-
|
|
73
|
+
isLeafPoint(editor.state.doc, cur.anchor) &&
|
|
74
|
+
isLeafPoint(editor.state.doc, cur.focus) &&
|
|
188
75
|
pointEq(sel.anchor, lastApplied.anchor) &&
|
|
189
76
|
pointEq(sel.focus, lastApplied.focus) &&
|
|
190
77
|
(!pointEq(cur.anchor, lastApplied.anchor) ||
|
|
191
78
|
!pointEq(cur.focus, lastApplied.focus))) {
|
|
192
79
|
lastApplied = cur;
|
|
193
|
-
editor.dispatch(editor.state
|
|
194
|
-
.tr()
|
|
195
|
-
.setSelection({ type: "text", ...cur })
|
|
196
|
-
.setStoredMarks([]));
|
|
80
|
+
editor.dispatch(editor.state.tr().setSelection({ type: "text", ...cur }));
|
|
197
81
|
paintOverlays();
|
|
198
82
|
return;
|
|
199
83
|
}
|
|
@@ -210,11 +94,9 @@ export function bindEditorInput(editor, el) {
|
|
|
210
94
|
pointEq(cur.focus, s.focus)) {
|
|
211
95
|
return;
|
|
212
96
|
}
|
|
213
|
-
//
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
.setSelection({ type: "text", ...s })
|
|
217
|
-
.setStoredMarks([]));
|
|
97
|
+
// 대기 서식(storedMarks)은 커서 이동에도 유지한다 — GDocs/Word
|
|
98
|
+
// 관례: 토글로 끌 때까지 다음 타이핑에 계속 적용된다
|
|
99
|
+
editor.dispatch(editor.state.tr().setSelection({ type: "text", ...s }));
|
|
218
100
|
};
|
|
219
101
|
const onBeforeInput = (e) => {
|
|
220
102
|
if (!editor.editable || e.isComposing)
|
|
@@ -223,29 +105,14 @@ export function bindEditorInput(editor, el) {
|
|
|
223
105
|
// 흡수된 텍스트를 포함해 정확하고, 플러시의 리렌더가 DOM
|
|
224
106
|
// 셀렉션을 doc(조합 시작점)으로 되돌리기 전의 값이다
|
|
225
107
|
const domSel = readDomSel();
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
e.inputType.startsWith("delete");
|
|
235
|
-
if (!pendingAbsorb || !structural) {
|
|
236
|
-
// 커밋 에코 — DOM에 이미 같은 텍스트가 쓰여 있으면(조합 중 브라우저가
|
|
237
|
-
// 넣은 상태) 통과시키면 브라우저가 한 번 더 써서 "세세"가 된다.
|
|
238
|
-
// DOM에 없으면(Safari 최종 커밋) 살려둬야 글자가 사라지지 않는다
|
|
239
|
-
if ((e.inputType === "insertText" ||
|
|
240
|
-
e.inputType === "insertCompositionText") &&
|
|
241
|
-
e.data &&
|
|
242
|
-
domSel &&
|
|
243
|
-
domEndsWith(domSel.focus, e.data)) {
|
|
244
|
-
e.preventDefault();
|
|
245
|
-
}
|
|
246
|
-
return;
|
|
247
|
-
}
|
|
248
|
-
flushComposition();
|
|
108
|
+
// 조합 세션 게이트 — swallow(조합 중 무시)/prevent(커밋 에코 차단)/
|
|
109
|
+
// proceed(정상 처리 — 흡수 대기 중의 구조 입력은 플러시 후 통과)
|
|
110
|
+
const gated = ime.gate(e, domSel);
|
|
111
|
+
if (gated === "swallow")
|
|
112
|
+
return;
|
|
113
|
+
if (gated === "prevent") {
|
|
114
|
+
e.preventDefault();
|
|
115
|
+
return;
|
|
249
116
|
}
|
|
250
117
|
const ds = editor.state.selection;
|
|
251
118
|
// 노드 셀렉션 — DOM 캐럿은 클릭 전 위치에 멈춰 있어 신뢰 불가.
|
|
@@ -253,28 +120,7 @@ export function bindEditorInput(editor, el) {
|
|
|
253
120
|
// 경계에서 일어나는 것으로 처리한다 (노드는 유지)
|
|
254
121
|
if (ds.type === "node") {
|
|
255
122
|
e.preventDefault();
|
|
256
|
-
|
|
257
|
-
const idx = ds.path[ds.path.length - 1] ?? 0;
|
|
258
|
-
const tr = editor.state.tr();
|
|
259
|
-
if (e.inputType.startsWith("delete")) {
|
|
260
|
-
tr.delete({
|
|
261
|
-
anchor: point(parent, idx),
|
|
262
|
-
focus: point(parent, idx + 1),
|
|
263
|
-
});
|
|
264
|
-
}
|
|
265
|
-
else if (e.inputType === "insertParagraph" ||
|
|
266
|
-
e.inputType === "insertLineBreak") {
|
|
267
|
-
tr.split(point(parent, idx + 1));
|
|
268
|
-
}
|
|
269
|
-
else if ((e.inputType === "insertText" ||
|
|
270
|
-
e.inputType === "insertCompositionText") &&
|
|
271
|
-
e.data) {
|
|
272
|
-
tr.insertText(e.data, point(parent, idx + 1));
|
|
273
|
-
}
|
|
274
|
-
else {
|
|
275
|
-
return;
|
|
276
|
-
}
|
|
277
|
-
editor.dispatch(tr);
|
|
123
|
+
nodeSelectionBeforeInput(editor, e);
|
|
278
124
|
return;
|
|
279
125
|
}
|
|
280
126
|
// DOM 셀렉션이 무효하면(리렌더로 분리된 노드 위 등) doc 셀렉션으로
|
|
@@ -290,12 +136,8 @@ export function bindEditorInput(editor, el) {
|
|
|
290
136
|
return;
|
|
291
137
|
// 커밋 에코가 흡수 타이머보다 늦게 도착한 경우 — DOM과 doc에
|
|
292
138
|
// 이미 같은 글자가 있으므로 다시 넣으면 "세세"가 된다
|
|
293
|
-
if (
|
|
294
|
-
performance.now() - compEndedAt < 300 &&
|
|
295
|
-
domSel &&
|
|
296
|
-
domEndsWith(domSel.focus, data)) {
|
|
139
|
+
if (ime.isLateEcho(data, domSel))
|
|
297
140
|
return;
|
|
298
|
-
}
|
|
299
141
|
// 범위 삭제 뒤엔 삭제 전 좌표가 무효 — 정규화한 앞점 기준으로 삽입
|
|
300
142
|
const r = normalizeRange(sel);
|
|
301
143
|
// 입력 훅 — 기능이 글자 가로채기(코드블록 자동 쌍·타입오버 등)를
|
|
@@ -417,8 +259,12 @@ export function bindEditorInput(editor, el) {
|
|
|
417
259
|
// 끝점이 요소 레벨 포인트(컨테이너 자식 경계, 블록 머지 시 Chrome이
|
|
418
260
|
// (P,0) 같은 위치를 줌)면 tr.delete가 해석하지 못한다 — 리프
|
|
419
261
|
// 포인트를 주는 pointBefore/After 폴백으로 돌린다
|
|
420
|
-
|
|
421
|
-
|
|
262
|
+
if (ta &&
|
|
263
|
+
tf &&
|
|
264
|
+
!pointEq(ta, tf) &&
|
|
265
|
+
onCaret &&
|
|
266
|
+
isLeafPoint(editor.state.doc, ta) &&
|
|
267
|
+
isLeafPoint(editor.state.doc, tf)) {
|
|
422
268
|
tr.delete(normalizeRange({ anchor: ta, focus: tf }));
|
|
423
269
|
tr.setMeta("history.group", "delete");
|
|
424
270
|
editor.dispatch(tr);
|
|
@@ -444,13 +290,7 @@ export function bindEditorInput(editor, el) {
|
|
|
444
290
|
const r = normalizeRange(sel);
|
|
445
291
|
// 기능 훅 — 링크 URL 감싸기·코드블록 순수 텍스트 등.
|
|
446
292
|
// 하나라도 소비하면 기본 경로를 건너뛴다
|
|
447
|
-
const ctx =
|
|
448
|
-
state: editor.state,
|
|
449
|
-
tr,
|
|
450
|
-
dispatch: () => editor.dispatch(tr),
|
|
451
|
-
anchor: r.anchor,
|
|
452
|
-
focus: r.focus,
|
|
453
|
-
};
|
|
293
|
+
const ctx = rangeCtx(editor, r, tr);
|
|
454
294
|
const data = { html, text };
|
|
455
295
|
let consumed = false;
|
|
456
296
|
for (const h of editor.inputHooks) {
|
|
@@ -487,8 +327,7 @@ export function bindEditorInput(editor, el) {
|
|
|
487
327
|
let r = normalizeRange(sel);
|
|
488
328
|
if (e.inputType === "insertReplacementText") {
|
|
489
329
|
const tr0 = e.getTargetRanges?.()[0];
|
|
490
|
-
const a = tr0 &&
|
|
491
|
-
domToPoint(el, tr0.startContainer, tr0.startOffset);
|
|
330
|
+
const a = tr0 && domToPoint(el, tr0.startContainer, tr0.startOffset);
|
|
492
331
|
const f = tr0 && domToPoint(el, tr0.endContainer, tr0.endOffset);
|
|
493
332
|
if (a && f)
|
|
494
333
|
r = normalizeRange({ anchor: a, focus: f });
|
|
@@ -501,14 +340,6 @@ export function bindEditorInput(editor, el) {
|
|
|
501
340
|
editor.dispatch(tr);
|
|
502
341
|
break;
|
|
503
342
|
}
|
|
504
|
-
case "historyUndo":
|
|
505
|
-
case "historyRedo": {
|
|
506
|
-
// iOS/Android의 OS 실행취소·재실행 제스처 — 네이티브가 DOM을
|
|
507
|
-
// 되돌리면 doc과 어긋나니 우리 히스토리로 돌린다
|
|
508
|
-
e.preventDefault();
|
|
509
|
-
editor.commands[e.inputType === "historyUndo" ? "undo" : "redo"]?.();
|
|
510
|
-
break;
|
|
511
|
-
}
|
|
512
343
|
// 단어/줄 단위·드래그·잘라내기 삭제 — macOS Option-Delete는
|
|
513
344
|
// deleteWord*, Ctrl-K는 deleteSoftLine*, Cmd-X는 deleteByCut으로
|
|
514
345
|
// 온다. getTargetRanges가 브라우저가 계산한 정확한 범위를 주므로
|
|
@@ -533,12 +364,11 @@ export function bindEditorInput(editor, el) {
|
|
|
533
364
|
// 레벨 포인트면 tr.delete가 해석 못하므로 리프만 받는다
|
|
534
365
|
const delBack = e.inputType.endsWith("Backward");
|
|
535
366
|
const delFwd = e.inputType.endsWith("Forward");
|
|
536
|
-
const leafP = (p) => !!p && nodeAt(editor.state.doc, p.path)?.type === "text";
|
|
537
367
|
const trusted = a &&
|
|
538
368
|
f &&
|
|
539
369
|
!pointEq(a, f) &&
|
|
540
|
-
|
|
541
|
-
|
|
370
|
+
isLeafPoint(editor.state.doc, a) &&
|
|
371
|
+
isLeafPoint(editor.state.doc, f) &&
|
|
542
372
|
(!delBack || pointEq(f, sel.focus)) &&
|
|
543
373
|
(!delFwd || pointEq(a, sel.focus));
|
|
544
374
|
const r = trusted
|
|
@@ -550,59 +380,7 @@ export function bindEditorInput(editor, el) {
|
|
|
550
380
|
}
|
|
551
381
|
// 모바일·컨텍스트 메뉴·리더의 서식 명령 — 네이티브 execCommand가
|
|
552
382
|
// DOM을 직접 바꾸면 어긋나므로 우리 커맨드로 매핑한다
|
|
553
|
-
|
|
554
|
-
case "formatItalic":
|
|
555
|
-
case "formatUnderline":
|
|
556
|
-
case "formatStrikeThrough":
|
|
557
|
-
case "formatSuperscript":
|
|
558
|
-
case "formatSubscript": {
|
|
559
|
-
e.preventDefault();
|
|
560
|
-
const mark = FORMAT_MARKS[e.inputType];
|
|
561
|
-
if (editor.state.schema.markSpec(mark)) {
|
|
562
|
-
toggleMark(mark)({
|
|
563
|
-
state: editor.state,
|
|
564
|
-
tr,
|
|
565
|
-
dispatch: () => editor.dispatch(tr),
|
|
566
|
-
});
|
|
567
|
-
}
|
|
568
|
-
break;
|
|
569
|
-
}
|
|
570
|
-
case "formatRemove": {
|
|
571
|
-
e.preventDefault();
|
|
572
|
-
editor.commands.clearFormat?.();
|
|
573
|
-
break;
|
|
574
|
-
}
|
|
575
|
-
case "formatJustifyLeft":
|
|
576
|
-
case "formatJustifyCenter":
|
|
577
|
-
case "formatJustifyRight": {
|
|
578
|
-
e.preventDefault();
|
|
579
|
-
const align = {
|
|
580
|
-
formatJustifyLeft: "left",
|
|
581
|
-
formatJustifyCenter: "center",
|
|
582
|
-
formatJustifyRight: "right",
|
|
583
|
-
}[e.inputType];
|
|
584
|
-
editor.commands.setAlign?.(align);
|
|
585
|
-
break;
|
|
586
|
-
}
|
|
587
|
-
case "formatIndent":
|
|
588
|
-
case "formatOutdent": {
|
|
589
|
-
e.preventDefault();
|
|
590
|
-
editor.commands[e.inputType === "formatIndent" ? "sinkListItem" : "liftListItem"]?.();
|
|
591
|
-
break;
|
|
592
|
-
}
|
|
593
|
-
case "insertUnorderedList":
|
|
594
|
-
case "insertOrderedList": {
|
|
595
|
-
e.preventDefault();
|
|
596
|
-
editor.commands[e.inputType === "insertOrderedList"
|
|
597
|
-
? "toggleOrderedList"
|
|
598
|
-
: "toggleBulletList"]?.();
|
|
599
|
-
break;
|
|
600
|
-
}
|
|
601
|
-
case "insertHorizontalRule": {
|
|
602
|
-
e.preventDefault();
|
|
603
|
-
editor.commands.insertHorizontalRule?.();
|
|
604
|
-
break;
|
|
605
|
-
}
|
|
383
|
+
// (매핑 테이블은 keys.ts의 dispatchFormatInput)
|
|
606
384
|
case "insertFromYank":
|
|
607
385
|
case "insertFromPasteAsQuotation": {
|
|
608
386
|
// macOS 킬링 붙여넣기(Ctrl-Y)·인용 붙여넣기 — 있으면 순수
|
|
@@ -618,10 +396,15 @@ export function bindEditorInput(editor, el) {
|
|
|
618
396
|
editor.dispatch(tr);
|
|
619
397
|
break;
|
|
620
398
|
}
|
|
621
|
-
// 나머지 타입(insertTranspose, formatFontColor 등)은 우리가
|
|
622
|
-
// 처리하지 않는다 — 그대로 두면 브라우저가 DOM만 바꿔 doc과
|
|
623
|
-
// 영구히 어긋나므로 기본 동작을 막아 no-op으로 둔다
|
|
624
399
|
default:
|
|
400
|
+
// format*/history*/insert*List 등 — 커맨드 디스패치 테이블에 위임
|
|
401
|
+
if (dispatchFormatInput(editor, e.inputType)) {
|
|
402
|
+
e.preventDefault();
|
|
403
|
+
break;
|
|
404
|
+
}
|
|
405
|
+
// 나머지 타입(insertTranspose, formatFontColor 등)은 우리가
|
|
406
|
+
// 처리하지 않는다 — 그대로 두면 브라우저가 DOM만 바꿔 doc과
|
|
407
|
+
// 영구히 어긋나므로 기본 동작을 막아 no-op으로 둔다
|
|
625
408
|
e.preventDefault();
|
|
626
409
|
break;
|
|
627
410
|
}
|
|
@@ -631,7 +414,7 @@ export function bindEditorInput(editor, el) {
|
|
|
631
414
|
* false 반환은 다음 바인딩으로 폴스루 (PM keymap 관례).
|
|
632
415
|
*/
|
|
633
416
|
const onKeydown = (e) => {
|
|
634
|
-
if (
|
|
417
|
+
if (ime.active || e.isComposing || !editor.editable)
|
|
635
418
|
return;
|
|
636
419
|
const key = normalizeKey(e);
|
|
637
420
|
// Mod-A 전체 선택은 직접 처리 — 중첩 편집 호스트(.me-node-view 안의
|
|
@@ -639,7 +422,9 @@ export function bindEditorInput(editor, el) {
|
|
|
639
422
|
// 셀렉션을 펼치지 못하고 문서 시작으로 collapse한다
|
|
640
423
|
if (key === "Mod-a") {
|
|
641
424
|
e.preventDefault();
|
|
642
|
-
editor.dispatch(editor.state
|
|
425
|
+
editor.dispatch(editor.state
|
|
426
|
+
.tr()
|
|
427
|
+
.setSelection(textSelection({ path: [], offset: 0 }, { path: [], offset: editor.state.doc.content?.length ?? 0 })));
|
|
643
428
|
return;
|
|
644
429
|
}
|
|
645
430
|
// 노드 셀렉션(이미지 클릭 등) — DOM 캐럿이 없으므로 네이티브
|
|
@@ -647,41 +432,9 @@ export function bindEditorInput(editor, el) {
|
|
|
647
432
|
// 노드 삭제, Enter는 노드 뒤에 새 블록, 화살표/Escape는 텍스트
|
|
648
433
|
// 셀렉션으로 붕괴, 인쇄 문자는 노드 뒤에 삽입(노드는 유지).
|
|
649
434
|
// Mod/Alt 조합(undo·키맵 등)은 아래 키맵 루프에 넘긴다
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
const idx = ds.path[ds.path.length - 1] ?? 0;
|
|
654
|
-
const before = point(parent, idx);
|
|
655
|
-
const after = point(parent, idx + 1);
|
|
656
|
-
const tr = editor.state.tr();
|
|
657
|
-
if (key === "Backspace" || key === "Delete") {
|
|
658
|
-
e.preventDefault();
|
|
659
|
-
tr.delete({ anchor: before, focus: after });
|
|
660
|
-
editor.dispatch(tr);
|
|
661
|
-
}
|
|
662
|
-
else if (key === "Enter") {
|
|
663
|
-
e.preventDefault();
|
|
664
|
-
tr.split(after);
|
|
665
|
-
editor.dispatch(tr);
|
|
666
|
-
}
|
|
667
|
-
else if (key === "Escape" ||
|
|
668
|
-
key === "ArrowLeft" ||
|
|
669
|
-
key === "ArrowUp") {
|
|
670
|
-
e.preventDefault();
|
|
671
|
-
editor.dispatch(tr.setSelection(textSelection(before)));
|
|
672
|
-
}
|
|
673
|
-
else if (key === "ArrowRight" || key === "ArrowDown") {
|
|
674
|
-
e.preventDefault();
|
|
675
|
-
editor.dispatch(tr.setSelection(textSelection(after)));
|
|
676
|
-
}
|
|
677
|
-
else if (e.key.length === 1 &&
|
|
678
|
-
!e.ctrlKey &&
|
|
679
|
-
!e.metaKey &&
|
|
680
|
-
!e.altKey) {
|
|
681
|
-
e.preventDefault();
|
|
682
|
-
tr.insertText(e.key, after);
|
|
683
|
-
editor.dispatch(tr);
|
|
684
|
-
}
|
|
435
|
+
if (editor.state.selection.type === "node" &&
|
|
436
|
+
nodeSelectionKeydown(editor, e, key)) {
|
|
437
|
+
e.preventDefault();
|
|
685
438
|
return;
|
|
686
439
|
}
|
|
687
440
|
for (const km of editor.keymaps) {
|
|
@@ -706,202 +459,10 @@ export function bindEditorInput(editor, el) {
|
|
|
706
459
|
// Ctrl+←/→는 비-Mac에서 단어 이동이라 metaKey(Cmd)일 때만 가로챈다
|
|
707
460
|
if (LINE_NAV_KEYS.has(key) &&
|
|
708
461
|
(!key.includes("Arrow") || e.metaKey) &&
|
|
709
|
-
lineNav(key)) {
|
|
462
|
+
lineNav(editor, el, key)) {
|
|
710
463
|
e.preventDefault();
|
|
711
464
|
}
|
|
712
465
|
};
|
|
713
|
-
/**
|
|
714
|
-
* caretRangeFromPoint로 시각적 줄 끝/시작의 doc 위치를 계산해 캐럿을 옮긴다.
|
|
715
|
-
* 클릭 배치와 같은 Blink 엔진이라 네이티브 줄 경계 계산보다 신뢰할 수 있다.
|
|
716
|
-
* Mod-Home/End는 doc 모델 기준 문서 가장자리로 간다. 실패 시 false → 네이티브 폴백.
|
|
717
|
-
*/
|
|
718
|
-
const lineNav = (key) => {
|
|
719
|
-
const doc = el.ownerDocument;
|
|
720
|
-
// DOM 셀렉션 우선 — 클릭 직후엔 doc 셀렉션이 아직 동기화 전이라
|
|
721
|
-
// stale할 수 있다. DOM이 분리 노드 위거나(리렌더 직후) 렌더
|
|
722
|
-
// 재앵커로 요소 레벨 포인트에 있으면 doc 포커스로 폴백한다
|
|
723
|
-
const domNow = readDomSel();
|
|
724
|
-
const ds = editor.state.selection;
|
|
725
|
-
const docFocus = ds.type === "text" ? ds.focus : null;
|
|
726
|
-
const leaf = (p) => !!p && nodeAt(editor.state.doc, p.path)?.type === "text";
|
|
727
|
-
const focus = leaf(domNow?.focus) ? domNow.focus : docFocus;
|
|
728
|
-
if (!focus)
|
|
729
|
-
return false;
|
|
730
|
-
const extend = key.startsWith("Shift-") || key.startsWith("Mod-Shift-");
|
|
731
|
-
const anchor = () => extend
|
|
732
|
-
? leaf(domNow?.anchor)
|
|
733
|
-
? domNow.anchor
|
|
734
|
-
: ds.type === "text"
|
|
735
|
-
? ds.anchor
|
|
736
|
-
: null
|
|
737
|
-
: null;
|
|
738
|
-
// 문서 가장자리 계열(Mod-Home/End) — doc 모델로 바로 적용.
|
|
739
|
-
// applySel이 아니라 dispatch로 간다 — doc이 동기 갱신돼야 뒤따르는
|
|
740
|
-
// 비동기 렌더 커밋이 DOM을 파괴해도 restore가 같은 위치를 다시
|
|
741
|
-
// 적용한다(DOM 직접 쓰기는 pending selchg 사이 커밋에 되돌아간다)
|
|
742
|
-
if (key.startsWith("Mod") &&
|
|
743
|
-
!key.endsWith("ArrowLeft") &&
|
|
744
|
-
!key.endsWith("ArrowRight")) {
|
|
745
|
-
const t = key.endsWith("Home")
|
|
746
|
-
? point([], 0)
|
|
747
|
-
: point([], editor.state.doc.content?.length ?? 0);
|
|
748
|
-
editor.dispatch(editor.state
|
|
749
|
-
.tr()
|
|
750
|
-
.setSelection({ type: "text", anchor: anchor() ?? t, focus: t }));
|
|
751
|
-
return true;
|
|
752
|
-
}
|
|
753
|
-
// 캐럿의 화면 y — 포커스의 DOM 위치에서 collapsed range rect을 잰다.
|
|
754
|
-
// pointToDOM이 현재 DOM으로 재해석하므로 리렌더로 분리된
|
|
755
|
-
// 노드 위의 브라우저 셀렉션에 흔들리지 않는다
|
|
756
|
-
const domPos = pointToDOM(el, focus);
|
|
757
|
-
if (!domPos || !el.contains(domPos.node))
|
|
758
|
-
return false;
|
|
759
|
-
const range = doc.createRange();
|
|
760
|
-
try {
|
|
761
|
-
range.setStart(domPos.node, domPos.offset);
|
|
762
|
-
range.collapse(true);
|
|
763
|
-
}
|
|
764
|
-
catch {
|
|
765
|
-
return false;
|
|
766
|
-
}
|
|
767
|
-
let rect = range.getClientRects()[0] ?? range.getBoundingClientRect();
|
|
768
|
-
// 줄 시작의 빈/경계 위치 캐럿이나 빈 텍스트 노드(Vue 앵커)에선
|
|
769
|
-
// collapsed range가 빈 rect을 준다 — 인접 한 글자 → 부모 요소 순으로
|
|
770
|
-
// 근사한다
|
|
771
|
-
if ((!rect || rect.height === 0) && domPos.node.nodeType === 3) {
|
|
772
|
-
const len = domPos.node.nodeValue?.length ?? 0;
|
|
773
|
-
if (domPos.offset < len) {
|
|
774
|
-
range.setEnd(domPos.node, domPos.offset + 1);
|
|
775
|
-
}
|
|
776
|
-
else if (domPos.offset > 0) {
|
|
777
|
-
range.setStart(domPos.node, domPos.offset - 1);
|
|
778
|
-
}
|
|
779
|
-
if (domPos.offset < len || domPos.offset > 0) {
|
|
780
|
-
rect = range.getClientRects()[0] ?? range.getBoundingClientRect();
|
|
781
|
-
}
|
|
782
|
-
}
|
|
783
|
-
if (!rect || rect.height === 0) {
|
|
784
|
-
const parent = domPos.node.nodeType === 3
|
|
785
|
-
? domPos.node.parentElement
|
|
786
|
-
: domPos.node;
|
|
787
|
-
rect = parent?.getBoundingClientRect();
|
|
788
|
-
}
|
|
789
|
-
if (!rect || rect.height === 0)
|
|
790
|
-
return false;
|
|
791
|
-
// 캐럿이 속한 블록 요소 — 시각적 줄이 갇힌 박스 (인라인 맥락 루트)
|
|
792
|
-
let block = domPos.node.nodeType === 3
|
|
793
|
-
? domPos.node.parentElement
|
|
794
|
-
: domPos.node;
|
|
795
|
-
while (block && block !== el) {
|
|
796
|
-
if (getComputedStyle(block).display !== "inline")
|
|
797
|
-
break;
|
|
798
|
-
block = block.parentElement;
|
|
799
|
-
}
|
|
800
|
-
const br = (block && block !== el ? block : el).getBoundingClientRect();
|
|
801
|
-
const y = rect.top + rect.height / 2;
|
|
802
|
-
const t = caretPointFromXY(doc, el, key.endsWith("End") || key.endsWith("ArrowRight")
|
|
803
|
-
? br.right - 1
|
|
804
|
-
: br.left + 1, y);
|
|
805
|
-
if (!t)
|
|
806
|
-
return false;
|
|
807
|
-
// 다른 블록의 위치가 잡히면 신뢰 불가 — 네이티브에 맡긴다
|
|
808
|
-
const sameBlock = t.path.length === focus.path.length &&
|
|
809
|
-
t.path.slice(0, -1).every((v, i) => v === focus.path[i]);
|
|
810
|
-
if (!sameBlock)
|
|
811
|
-
return false;
|
|
812
|
-
editor.dispatch(editor.state
|
|
813
|
-
.tr()
|
|
814
|
-
.setSelection({ type: "text", anchor: anchor() ?? t, focus: t }));
|
|
815
|
-
return true;
|
|
816
|
-
};
|
|
817
|
-
/**
|
|
818
|
-
* composition 중 브라우저가 직접 바꾼 DOM을 doc에 흡수한다.
|
|
819
|
-
* 캐럿이 위치한 텍스트 홀더의 DOM 텍스트와 doc 텍스트를 공통
|
|
820
|
-
* 접두/접미로 diff해 차이만큼만 트랜잭션으로 반영한다.
|
|
821
|
-
* (제약: 조합이 하나의 텍스트 홀더 안에 머문다고 가정 —
|
|
822
|
-
* 크로스-블록 조합 삭제는 미지원)
|
|
823
|
-
*/
|
|
824
|
-
const absorbComposition = () => {
|
|
825
|
-
const focus = readDomSel()?.focus ?? compStart;
|
|
826
|
-
if (!focus || focus.path.length === 0)
|
|
827
|
-
return;
|
|
828
|
-
const holder = el.querySelector(`[${PATH_ATTR}="${focus.path.join(",")}"]`);
|
|
829
|
-
// 텍스트 홀더가 아니면(안에 me-path 자식이 있으면) 흡수 불가
|
|
830
|
-
if (!holder || holder.querySelector(`[${PATH_ATTR}]`))
|
|
831
|
-
return;
|
|
832
|
-
const domText = holder.textContent ?? "";
|
|
833
|
-
const target = nodeAt(editor.state.doc, focus.path);
|
|
834
|
-
const docText = target?.type === "text" ? target.text ?? "" : "";
|
|
835
|
-
if (domText === docText)
|
|
836
|
-
return;
|
|
837
|
-
let lo = 0;
|
|
838
|
-
const max = Math.min(domText.length, docText.length);
|
|
839
|
-
while (lo < max && domText[lo] === docText[lo])
|
|
840
|
-
lo++;
|
|
841
|
-
let hiDom = domText.length;
|
|
842
|
-
let hiDoc = docText.length;
|
|
843
|
-
while (hiDom > lo && hiDoc > lo && domText[hiDom - 1] === docText[hiDoc - 1]) {
|
|
844
|
-
hiDom--;
|
|
845
|
-
hiDoc--;
|
|
846
|
-
}
|
|
847
|
-
const tr = editor.state.tr();
|
|
848
|
-
if (hiDoc > lo) {
|
|
849
|
-
tr.delete({
|
|
850
|
-
anchor: point(focus.path, lo),
|
|
851
|
-
focus: point(focus.path, hiDoc),
|
|
852
|
-
});
|
|
853
|
-
}
|
|
854
|
-
const inserted = domText.slice(lo, hiDom);
|
|
855
|
-
if (inserted)
|
|
856
|
-
tr.insertText(inserted, point(focus.path, lo));
|
|
857
|
-
if (!tr.docChanged)
|
|
858
|
-
return;
|
|
859
|
-
tr.setMeta("history.group", "type").setMeta("ime", true);
|
|
860
|
-
// 브라우저가 이 블록의 DOM을 직접 바꿨다 — 리렌더 시 프레임워크
|
|
861
|
-
// 리컨실이 깨지지 않게 블록 리마운트 대상으로 표시한다
|
|
862
|
-
const dk = topBlockKey(focus) ?? topBlockKey(compStart);
|
|
863
|
-
if (dk != null)
|
|
864
|
-
dirtyPaths.add(dk);
|
|
865
|
-
editor.dispatch(tr);
|
|
866
|
-
};
|
|
867
|
-
const onCompositionStart = () => {
|
|
868
|
-
// 이전 세션의 흡수 타이머가 남아있으면 취소한다 — 그대로 두면 새
|
|
869
|
-
// 조합 도중에 flushComposition이 composing을 해제하고 디스패치·
|
|
870
|
-
// 리렌더를 일으켜 브라우저가 살아있는 세션을 리셋한다
|
|
871
|
-
// ("안녕하세요"→"안ㄴ영ㅎ하세세요" 회귀). 커밋된 텍스트는 DOM에
|
|
872
|
-
// 남아 있으므로 다음 flush가 같은 홀더를 diff할 때 함께 흡수된다
|
|
873
|
-
if (compTimer !== null) {
|
|
874
|
-
clearTimeout(compTimer);
|
|
875
|
-
compTimer = null;
|
|
876
|
-
}
|
|
877
|
-
pendingAbsorb = false;
|
|
878
|
-
composing = true;
|
|
879
|
-
compStart = readDomSel()?.focus ?? null;
|
|
880
|
-
};
|
|
881
|
-
/**
|
|
882
|
-
* 대기 중인 흡수를 즉시 실행 — 커밋 직후의 구조 입력(Enter 등)이
|
|
883
|
-
* 최신 doc 기준으로 처리되게 하기 위해 beforeinput에서 호출한다.
|
|
884
|
-
*/
|
|
885
|
-
const flushComposition = () => {
|
|
886
|
-
if (compTimer !== null) {
|
|
887
|
-
clearTimeout(compTimer);
|
|
888
|
-
compTimer = null;
|
|
889
|
-
}
|
|
890
|
-
composing = false;
|
|
891
|
-
pendingAbsorb = false;
|
|
892
|
-
if (editor.editable)
|
|
893
|
-
absorbComposition();
|
|
894
|
-
compStart = null;
|
|
895
|
-
};
|
|
896
|
-
const onCompositionEnd = () => {
|
|
897
|
-
// composing 해제와 흡수를 다음 태스크로 미룬다 — 같은 태스크의
|
|
898
|
-
// 후속 beforeinput/keydown(Safari 최종 커밋, IME Enter 오커밋)을
|
|
899
|
-
// composing 가드가 계속 걸러내게 하기 위해서다. 단 그 창에 도착한
|
|
900
|
-
// 구조 입력은 flushComposition이 흡수를 앞당겨 정상 처리한다.
|
|
901
|
-
pendingAbsorb = true;
|
|
902
|
-
compEndedAt = performance.now();
|
|
903
|
-
compTimer = setTimeout(flushComposition, 0);
|
|
904
|
-
};
|
|
905
466
|
/**
|
|
906
467
|
* 체크박스 아이템(taskItem)의 마커 영역 클릭 — ::before 마커는
|
|
907
468
|
* 의사요소라 이벤트 타겟이 li 자신이 되고, 클릭이 li의 패딩
|
|
@@ -928,35 +489,14 @@ export function bindEditorInput(editor, el) {
|
|
|
928
489
|
.setNodeAttr(path, "checked", !node?.attrs?.["checked"]));
|
|
929
490
|
return;
|
|
930
491
|
}
|
|
931
|
-
|
|
932
|
-
|
|
933
|
-
|
|
934
|
-
|
|
935
|
-
|
|
936
|
-
*/
|
|
937
|
-
if (spec?.atom) {
|
|
492
|
+
// atom 노드(img/hr 등) 클릭 → NodeSelection — DOM 캐럿 이동을
|
|
493
|
+
// 막고(preventDefault) 모델 셀렉션만 둔다. 오버레이 표시는
|
|
494
|
+
// paintOverlays의 is-selected 마킹 + 각 기능의 paintOverlay가 담당.
|
|
495
|
+
// 같은 노드를 다시 누르면 트랜잭션을 생략한다
|
|
496
|
+
if (trySelectAtom(editor, t)) {
|
|
938
497
|
e.preventDefault();
|
|
939
|
-
const cur = editor.state.selection;
|
|
940
|
-
if (cur.type === "node" &&
|
|
941
|
-
cur.path.length === path.length &&
|
|
942
|
-
cur.path.every((v, i) => v === path[i])) {
|
|
943
|
-
return;
|
|
944
|
-
}
|
|
945
|
-
editor.dispatch(editor.state.tr().setSelection(nodeSelection(path)));
|
|
946
498
|
}
|
|
947
499
|
};
|
|
948
|
-
/**
|
|
949
|
-
* 파일 수신 — paste/drop의 File 목록을 기능 훅(files)에 넘긴다.
|
|
950
|
-
* 어느 기능도 소비하지 않으면 폴스루: paste는 beforeinput이
|
|
951
|
-
* 텍스트/HTML을 처리하고, drop은 브라우저 기본 동작을 따른다.
|
|
952
|
-
*/
|
|
953
|
-
const dispatchFiles = (dt, source, at) => {
|
|
954
|
-
const files = Array.from(dt?.files ?? []);
|
|
955
|
-
if (!files.length)
|
|
956
|
-
return false;
|
|
957
|
-
const ctx = { editor, files, at, source };
|
|
958
|
-
return editor.inputHooks.some((h) => h.files?.(ctx));
|
|
959
|
-
};
|
|
960
500
|
/**
|
|
961
501
|
* 붙여넣기 — 클립보드의 파일을 기능 훅으로 위임한다 (이미지 업로드는
|
|
962
502
|
* imageFeature 소유 — Summernote onImageUpload / Quill 관례).
|
|
@@ -964,11 +504,12 @@ export function bindEditorInput(editor, el) {
|
|
|
964
504
|
* 처리한다.
|
|
965
505
|
*/
|
|
966
506
|
const onPaste = (e) => {
|
|
967
|
-
if (
|
|
507
|
+
if (ime.active || !editor.editable)
|
|
968
508
|
return;
|
|
969
509
|
// preventDefault하면 beforeinput이 오지 않는다
|
|
970
|
-
if (dispatchFiles(e.clipboardData, "paste", null))
|
|
510
|
+
if (dispatchFiles(editor, e.clipboardData, "paste", null)) {
|
|
971
511
|
e.preventDefault();
|
|
512
|
+
}
|
|
972
513
|
};
|
|
973
514
|
/** 드롭을 받으려면 dragover를 먼저 막아야 한다 — 파일(업로드 훅)
|
|
974
515
|
* 외에 텍스트 드래그도 beforeinput insertFromDrop으로 트랜잭션 처리 */
|
|
@@ -981,15 +522,15 @@ export function bindEditorInput(editor, el) {
|
|
|
981
522
|
}
|
|
982
523
|
};
|
|
983
524
|
const onDrop = (e) => {
|
|
984
|
-
if (
|
|
525
|
+
if (ime.active || !editor.editable)
|
|
985
526
|
return;
|
|
986
527
|
const at = caretPointFromXY(el.ownerDocument, el, e.clientX, e.clientY);
|
|
987
528
|
// 소비되지 않으면 기본 동작(파일을 새 탭으로 여는 것)이 살아있다
|
|
988
|
-
if (dispatchFiles(e.dataTransfer, "drop", at))
|
|
529
|
+
if (dispatchFiles(editor, e.dataTransfer, "drop", at))
|
|
989
530
|
e.preventDefault();
|
|
990
531
|
};
|
|
991
532
|
const onSelectionChange = () => {
|
|
992
|
-
if (
|
|
533
|
+
if (ime.active)
|
|
993
534
|
return;
|
|
994
535
|
// 에디터 안의 셀렉션만 동기화 — 바깥 클릭은 무시
|
|
995
536
|
const sel = readDomSel();
|
|
@@ -1005,8 +546,8 @@ export function bindEditorInput(editor, el) {
|
|
|
1005
546
|
pointEq(cur.focus, next.focus)) {
|
|
1006
547
|
return;
|
|
1007
548
|
}
|
|
1008
|
-
//
|
|
1009
|
-
editor.dispatch(editor.state.tr().setSelection(next)
|
|
549
|
+
// 대기 서식(storedMarks)은 커서 이동에도 유지한다 — GDocs/Word 관례
|
|
550
|
+
editor.dispatch(editor.state.tr().setSelection(next));
|
|
1010
551
|
};
|
|
1011
552
|
el.addEventListener("beforeinput", onBeforeInput);
|
|
1012
553
|
el.addEventListener("keydown", onKeydown);
|
|
@@ -1014,26 +555,34 @@ export function bindEditorInput(editor, el) {
|
|
|
1014
555
|
el.addEventListener("paste", onPaste);
|
|
1015
556
|
el.addEventListener("dragover", onDragOver);
|
|
1016
557
|
el.addEventListener("drop", onDrop);
|
|
1017
|
-
el.addEventListener("compositionstart",
|
|
1018
|
-
el.addEventListener("compositionend",
|
|
558
|
+
el.addEventListener("compositionstart", ime.start);
|
|
559
|
+
el.addEventListener("compositionend", ime.end);
|
|
1019
560
|
el.ownerDocument.addEventListener("selectionchange", onSelectionChange);
|
|
561
|
+
// 오버레이 초기 페인트 — React/Vue2처럼 마운트 layoutEffect가
|
|
562
|
+
// 바인딩보다 먼저 도는 렌더러에서도 첫 커밋 전에 오버레이가
|
|
563
|
+
// 존재하도록 바인딩 시점에 한 번 그린다
|
|
564
|
+
paintOverlays();
|
|
1020
565
|
return {
|
|
1021
566
|
dirtyPaths,
|
|
1022
567
|
unbind() {
|
|
1023
|
-
|
|
1024
|
-
|
|
568
|
+
ime.destroy();
|
|
569
|
+
// 기능 오버레이 정리 — 거터/크롬 바 DOM + ResizeObserver 해제
|
|
570
|
+
for (const h of editor.inputHooks)
|
|
571
|
+
h.destroyOverlay?.(el);
|
|
1025
572
|
el.removeEventListener("beforeinput", onBeforeInput);
|
|
1026
573
|
el.removeEventListener("keydown", onKeydown);
|
|
1027
574
|
el.removeEventListener("mousedown", onMouseDown);
|
|
1028
575
|
el.removeEventListener("paste", onPaste);
|
|
1029
576
|
el.removeEventListener("dragover", onDragOver);
|
|
1030
577
|
el.removeEventListener("drop", onDrop);
|
|
1031
|
-
el.removeEventListener("compositionstart",
|
|
1032
|
-
el.removeEventListener("compositionend",
|
|
578
|
+
el.removeEventListener("compositionstart", ime.start);
|
|
579
|
+
el.removeEventListener("compositionend", ime.end);
|
|
1033
580
|
el.ownerDocument.removeEventListener("selectionchange", onSelectionChange);
|
|
1034
581
|
},
|
|
1035
582
|
restoreSelection,
|
|
1036
583
|
syncDocSelection,
|
|
1037
584
|
};
|
|
1038
585
|
}
|
|
586
|
+
// DirtyKeyMap은 dirty-keys.ts로 이동했다 — 공개 API 경로 유지를 위해 재수출
|
|
587
|
+
export { DirtyKeyMap } from "./dirty-keys.js";
|
|
1039
588
|
//# sourceMappingURL=input.js.map
|