@teriusu/rich-editor 0.10.8 → 0.11.0

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 (147) hide show
  1. package/dist/components/BubbleToolbar.svelte +40 -36
  2. package/dist/components/BubbleToolbar.svelte.d.ts +3 -0
  3. package/dist/components/BubbleToolbar.svelte.d.ts.map +1 -1
  4. package/dist/components/EmojiSuggestionMenu.svelte +291 -0
  5. package/dist/components/EmojiSuggestionMenu.svelte.d.ts +9 -0
  6. package/dist/components/EmojiSuggestionMenu.svelte.d.ts.map +1 -0
  7. package/dist/components/FixedToolbar.svelte +53 -47
  8. package/dist/components/FixedToolbar.svelte.d.ts +3 -0
  9. package/dist/components/FixedToolbar.svelte.d.ts.map +1 -1
  10. package/dist/components/FloatingHelper.svelte +219 -0
  11. package/dist/components/FloatingHelper.svelte.d.ts +14 -0
  12. package/dist/components/FloatingHelper.svelte.d.ts.map +1 -0
  13. package/dist/components/InputModal.svelte +7 -3
  14. package/dist/components/InputModal.svelte.d.ts +3 -0
  15. package/dist/components/InputModal.svelte.d.ts.map +1 -1
  16. package/dist/components/MathModal.svelte +33 -29
  17. package/dist/components/MathModal.svelte.d.ts +3 -0
  18. package/dist/components/MathModal.svelte.d.ts.map +1 -1
  19. package/dist/components/MediaPickerModal.svelte +7 -3
  20. package/dist/components/MediaPickerModal.svelte.d.ts +3 -0
  21. package/dist/components/MediaPickerModal.svelte.d.ts.map +1 -1
  22. package/dist/components/SlashCommandMenu.svelte +88 -72
  23. package/dist/components/SlashCommandMenu.svelte.d.ts +3 -0
  24. package/dist/components/SlashCommandMenu.svelte.d.ts.map +1 -1
  25. package/dist/components/TableBubbleMenu.svelte +41 -33
  26. package/dist/components/TableBubbleMenu.svelte.d.ts +3 -0
  27. package/dist/components/TableBubbleMenu.svelte.d.ts.map +1 -1
  28. package/dist/components/TipTapEditor.svelte +239 -127
  29. package/dist/components/TipTapEditor.svelte.d.ts +7 -0
  30. package/dist/components/TipTapEditor.svelte.d.ts.map +1 -1
  31. package/dist/extensions/CardBlock.d.ts.map +1 -1
  32. package/dist/extensions/CardBlock.js +6 -4
  33. package/dist/extensions/FileAttachment.d.ts.map +1 -1
  34. package/dist/extensions/FileAttachment.js +2 -1
  35. package/dist/extensions/FixedDetails.d.ts.map +1 -1
  36. package/dist/extensions/FixedDetails.js +5 -3
  37. package/dist/extensions/LegacyBlock.d.ts.map +1 -1
  38. package/dist/extensions/LegacyBlock.js +8 -6
  39. package/dist/extensions/Math.d.ts.map +1 -1
  40. package/dist/extensions/Math.js +5 -2
  41. package/dist/extensions/MbusVideo.d.ts.map +1 -1
  42. package/dist/extensions/MbusVideo.js +73 -9
  43. package/dist/extensions/MediaToolbar.d.ts +41 -0
  44. package/dist/extensions/MediaToolbar.d.ts.map +1 -0
  45. package/dist/extensions/MediaToolbar.js +196 -0
  46. package/dist/extensions/MediaToolbar.test.d.ts +2 -0
  47. package/dist/extensions/MediaToolbar.test.d.ts.map +1 -0
  48. package/dist/extensions/MediaToolbar.test.js +231 -0
  49. package/dist/extensions/OrderedListMarker.d.ts +2 -0
  50. package/dist/extensions/OrderedListMarker.d.ts.map +1 -0
  51. package/dist/extensions/OrderedListMarker.js +114 -0
  52. package/dist/extensions/OrderedListMarker.test.d.ts +2 -0
  53. package/dist/extensions/OrderedListMarker.test.d.ts.map +1 -0
  54. package/dist/extensions/OrderedListMarker.test.js +176 -0
  55. package/dist/extensions/PdfBlock.d.ts.map +1 -1
  56. package/dist/extensions/PdfBlock.js +25 -23
  57. package/dist/extensions/ResizableImage.d.ts.map +1 -1
  58. package/dist/extensions/ResizableImage.js +20 -1
  59. package/dist/extensions/TableKeymap.d.ts +16 -0
  60. package/dist/extensions/TableKeymap.d.ts.map +1 -0
  61. package/dist/extensions/TableKeymap.js +97 -0
  62. package/dist/extensions/TableKeymap.test.d.ts +2 -0
  63. package/dist/extensions/TableKeymap.test.d.ts.map +1 -0
  64. package/dist/extensions/TableKeymap.test.js +147 -0
  65. package/dist/extensions/TabsBlock.d.ts.map +1 -1
  66. package/dist/extensions/TabsBlock.js +12 -9
  67. package/dist/extensions/TiptapMidibus.d.ts.map +1 -1
  68. package/dist/extensions/TiptapMidibus.js +60 -6
  69. package/dist/extensions/UploadSkeleton.d.ts +61 -0
  70. package/dist/extensions/UploadSkeleton.d.ts.map +1 -0
  71. package/dist/extensions/UploadSkeleton.js +233 -0
  72. package/dist/extensions/UploadSkeleton.test.d.ts +2 -0
  73. package/dist/extensions/UploadSkeleton.test.d.ts.map +1 -0
  74. package/dist/extensions/UploadSkeleton.test.js +128 -0
  75. package/dist/extensions/VideoEmbed.d.ts +8 -0
  76. package/dist/extensions/VideoEmbed.d.ts.map +1 -1
  77. package/dist/extensions/VideoEmbed.js +226 -45
  78. package/dist/extensions/VideoEmbed.test.js +131 -2
  79. package/dist/i18n/en.d.ts +3 -0
  80. package/dist/i18n/en.d.ts.map +1 -0
  81. package/dist/i18n/en.js +191 -0
  82. package/dist/i18n/es.d.ts +3 -0
  83. package/dist/i18n/es.d.ts.map +1 -0
  84. package/dist/i18n/es.js +191 -0
  85. package/dist/i18n/index.d.ts +43 -0
  86. package/dist/i18n/index.d.ts.map +1 -0
  87. package/dist/i18n/index.js +109 -0
  88. package/dist/i18n/index.test.d.ts +2 -0
  89. package/dist/i18n/index.test.d.ts.map +1 -0
  90. package/dist/i18n/index.test.js +173 -0
  91. package/dist/i18n/ja.d.ts +3 -0
  92. package/dist/i18n/ja.d.ts.map +1 -0
  93. package/dist/i18n/ja.js +191 -0
  94. package/dist/i18n/ko.d.ts +198 -0
  95. package/dist/i18n/ko.d.ts.map +1 -0
  96. package/dist/i18n/ko.js +215 -0
  97. package/dist/i18n/zh-hans.d.ts +3 -0
  98. package/dist/i18n/zh-hans.d.ts.map +1 -0
  99. package/dist/i18n/zh-hans.js +191 -0
  100. package/dist/i18n/zh-hant.d.ts +3 -0
  101. package/dist/i18n/zh-hant.d.ts.map +1 -0
  102. package/dist/i18n/zh-hant.js +192 -0
  103. package/dist/index.d.ts +7 -1
  104. package/dist/index.d.ts.map +1 -1
  105. package/dist/index.js +13 -1
  106. package/dist/static/highlight.d.ts +13 -0
  107. package/dist/static/highlight.d.ts.map +1 -0
  108. package/dist/static/highlight.js +99 -0
  109. package/dist/static/index.d.ts +33 -0
  110. package/dist/static/index.d.ts.map +1 -0
  111. package/dist/static/index.js +367 -0
  112. package/dist/static/index.test.d.ts +2 -0
  113. package/dist/static/index.test.d.ts.map +1 -0
  114. package/dist/static/index.test.js +194 -0
  115. package/dist/static/tokenizer.d.ts +52 -0
  116. package/dist/static/tokenizer.d.ts.map +1 -0
  117. package/dist/static/tokenizer.js +289 -0
  118. package/dist/styles/editor.css +1 -1
  119. package/dist/utils/emoji-data.d.ts +15 -0
  120. package/dist/utils/emoji-suggestion.d.ts +48 -0
  121. package/dist/utils/emoji-suggestion.d.ts.map +1 -0
  122. package/dist/utils/emoji-suggestion.js +51 -0
  123. package/dist/utils/emoji-suggestion.test.d.ts +2 -0
  124. package/dist/utils/emoji-suggestion.test.d.ts.map +1 -0
  125. package/dist/utils/emoji-suggestion.test.js +117 -0
  126. package/dist/utils/floating-helper.d.ts +60 -0
  127. package/dist/utils/floating-helper.d.ts.map +1 -0
  128. package/dist/utils/floating-helper.js +63 -0
  129. package/dist/utils/floating-helper.test.d.ts +2 -0
  130. package/dist/utils/floating-helper.test.d.ts.map +1 -0
  131. package/dist/utils/floating-helper.test.js +141 -0
  132. package/dist/utils/guard-vscode-paste.d.ts +19 -0
  133. package/dist/utils/guard-vscode-paste.d.ts.map +1 -0
  134. package/dist/utils/guard-vscode-paste.js +46 -0
  135. package/dist/utils/guard-vscode-paste.test.d.ts +2 -0
  136. package/dist/utils/guard-vscode-paste.test.d.ts.map +1 -0
  137. package/dist/utils/guard-vscode-paste.test.js +86 -0
  138. package/dist/utils/media-size.d.ts +29 -0
  139. package/dist/utils/media-size.d.ts.map +1 -0
  140. package/dist/utils/media-size.js +90 -0
  141. package/dist/utils/resize.d.ts +12 -0
  142. package/dist/utils/resize.d.ts.map +1 -1
  143. package/dist/utils/resize.js +5 -5
  144. package/dist/utils/sanitize.d.ts +2 -0
  145. package/dist/utils/sanitize.d.ts.map +1 -1
  146. package/dist/utils/sanitize.js +28 -3
  147. package/package.json +8 -1
@@ -0,0 +1,231 @@
1
+ import { describe, it, expect, afterEach } from "vitest";
2
+ import { Editor } from "@tiptap/core";
3
+ import StarterKit from "@tiptap/starter-kit";
4
+ import { MediaResizeToolbar, applyMediaToolbarAction } from "./MediaToolbar";
5
+ import { VideoEmbed } from "./VideoEmbed";
6
+ import { MbusVideo } from "./MbusVideo";
7
+ import { ResizableImage } from "./ResizableImage";
8
+ import { TiptapMidibus } from "./TiptapMidibus";
9
+ import { sanitizeHtml } from "../utils/sanitize";
10
+ import { normalizeMediaAlign, normalizeMediaHeight, normalizeMediaRatio, mediaRatioCss } from "../utils/media-size";
11
+ /* ─────────────────────────── 정규화 — 파싱은 관대, 쓰기는 좁게 ─────────────────────────── */
12
+ describe("media-size 정규화", () => {
13
+ it("높이 — px 정수만 남는다", () => {
14
+ expect(normalizeMediaHeight("420")).toBe(420);
15
+ expect(normalizeMediaHeight("420px")).toBe(420);
16
+ expect(normalizeMediaHeight(419.6)).toBe(420);
17
+ expect(normalizeMediaHeight("50%")).toBeNull();
18
+ expect(normalizeMediaHeight("auto")).toBeNull();
19
+ expect(normalizeMediaHeight(0)).toBeNull();
20
+ });
21
+ it("비율 — 어떤 꼴이든 `W:H` 정준형으로", () => {
22
+ expect(normalizeMediaRatio("16:9")).toBe("16:9");
23
+ expect(normalizeMediaRatio("16/9")).toBe("16:9");
24
+ expect(normalizeMediaRatio(" 4 : 3 ")).toBe("4:3");
25
+ expect(normalizeMediaRatio("1.78")).toBe("1.78:1");
26
+ expect(normalizeMediaRatio("0:9")).toBeNull();
27
+ expect(normalizeMediaRatio("가로세로")).toBeNull();
28
+ });
29
+ it("비율 → CSS aspect-ratio 값", () => {
30
+ expect(mediaRatioCss("4:3")).toBe("4 / 3");
31
+ expect(mediaRatioCss(null)).toBeNull();
32
+ });
33
+ it("정렬 — 세 값만, 대소문자·여백은 눈감는다", () => {
34
+ expect(normalizeMediaAlign(" CENTER ")).toBe("center");
35
+ expect(normalizeMediaAlign("left")).toBe("left");
36
+ expect(normalizeMediaAlign("middle")).toBeNull();
37
+ });
38
+ });
39
+ /* ─────────────────────────── 칩 한 번 = 속성 변경 한 벌 ─────────────────────────── */
40
+ describe("applyMediaToolbarAction", () => {
41
+ const full = { ratio: true, align: true, widthPresets: true };
42
+ it("비율 선택은 고정 높이를 함께 푼다 — 높이가 남으면 비율이 안 먹는다", () => {
43
+ expect(applyMediaToolbarAction({ height: "400" }, "ratio", "4:3", full)).toEqual({
44
+ ratio: "4:3",
45
+ height: null
46
+ });
47
+ });
48
+ it("켜진 칩을 다시 누르면 해제된다", () => {
49
+ expect(applyMediaToolbarAction({ ratio: "16:9" }, "ratio", "16:9", full)).toEqual({
50
+ ratio: null,
51
+ height: null
52
+ });
53
+ expect(applyMediaToolbarAction({ align: "center" }, "align", "center", full)).toEqual({
54
+ align: null
55
+ });
56
+ expect(applyMediaToolbarAction({ width: "50%" }, "width", "50%", full)).toEqual({
57
+ width: null
58
+ });
59
+ });
60
+ it("정렬·폭은 저장값이 좁다 — 모르는 값은 거절", () => {
61
+ expect(applyMediaToolbarAction({}, "align", "middle", full)).toBeNull();
62
+ expect(applyMediaToolbarAction({}, "width", "30%", full)).toBeNull();
63
+ });
64
+ it("구성에 없는 칩은 아무것도 하지 않는다 — 이미지에 폭 프리셋이 없는 이유", () => {
65
+ expect(applyMediaToolbarAction({}, "ratio", "16:9", { align: true })).toBeNull();
66
+ expect(applyMediaToolbarAction({}, "width", "50%", { align: true })).toBeNull();
67
+ });
68
+ });
69
+ /* ─────────────────────────── 속성 왕복 — renderHTML/parseHTML ─────────────────────────── */
70
+ describe("크기·정렬 속성 왕복", () => {
71
+ let editor;
72
+ function createEditor(extensions, content) {
73
+ editor = new Editor({
74
+ element: document.createElement("div"),
75
+ extensions: [StarterKit, ...extensions],
76
+ content
77
+ });
78
+ return editor;
79
+ }
80
+ afterEach(() => {
81
+ editor?.destroy();
82
+ });
83
+ function findNode(typeName) {
84
+ let found = null;
85
+ editor.state.doc.descendants((node, pos) => {
86
+ if (found)
87
+ return false;
88
+ if (node.type.name === typeName)
89
+ found = { pos, node };
90
+ return found === null;
91
+ });
92
+ return found;
93
+ }
94
+ it("VideoEmbed — 높이·정렬이 data-* 로 돌아온다", () => {
95
+ createEditor([VideoEmbed], '<div data-video-src="https://www.youtube.com/embed/abc" data-video-width="480px" data-video-height="360" data-video-align="center"></div>');
96
+ const html = editor.getHTML();
97
+ expect(html).toContain('data-video-height="360"');
98
+ expect(html).toContain('data-video-align="center"');
99
+ // style 은 거울일 뿐이지만 정렬이 정적 렌더에서도 서게 한다
100
+ expect(html).toContain("margin-left: auto");
101
+ });
102
+ it("VideoEmbed — 비율은 높이가 없을 때만 나간다(배타)", () => {
103
+ createEditor([VideoEmbed], '<div data-video-src="https://www.youtube.com/embed/abc" data-video-ratio="16:9"></div>');
104
+ expect(editor.getHTML()).toContain('data-video-ratio="16:9"');
105
+ editor.commands.setContent('<div data-video-src="https://www.youtube.com/embed/abc" data-video-height="360" data-video-ratio="16:9"></div>');
106
+ const html = editor.getHTML();
107
+ expect(html).toContain('data-video-height="360"');
108
+ expect(html).not.toContain("data-video-ratio");
109
+ });
110
+ it("MbusVideo — 같은 규칙, 이름만 data-mbus-*", () => {
111
+ createEditor([MbusVideo], '<div data-mbus-src="https://play.mbus.tv/v1/hls/x" data-mbus-height="500" data-mbus-align="right"></div>');
112
+ const html = editor.getHTML();
113
+ expect(html).toContain('data-mbus-height="500"');
114
+ expect(html).toContain('data-mbus-align="right"');
115
+ });
116
+ it("이미지 — 정렬은 style 이 아니라 data-align 속성으로", () => {
117
+ createEditor([ResizableImage.configure({ inline: false })], '<img src="/a.png" width="480" data-align="center">');
118
+ expect(editor.getHTML()).toContain('data-align="center"');
119
+ });
120
+ it("이미지 — 모르는 정렬 값은 버린다", () => {
121
+ createEditor([ResizableImage.configure({ inline: false })], '<img src="/a.png" data-align="middle">');
122
+ expect(editor.getHTML()).not.toContain("data-align");
123
+ });
124
+ it("살균기가 새 속성을 살려 보낸다 — 허용 목록 정합", () => {
125
+ const media = sanitizeHtml('<div data-video-src="https://www.youtube.com/embed/a" data-video-height="360" data-video-ratio="16:9" data-video-align="center" data-mbus-height="500" data-mbus-ratio="4:3" data-mbus-align="left"></div>');
126
+ for (const attr of [
127
+ 'data-video-height="360"',
128
+ 'data-video-ratio="16:9"',
129
+ 'data-video-align="center"',
130
+ 'data-mbus-height="500"',
131
+ 'data-mbus-ratio="4:3"',
132
+ 'data-mbus-align="left"'
133
+ ]) {
134
+ expect(media).toContain(attr);
135
+ }
136
+ expect(sanitizeHtml('<img src="/a.png" width="480" data-align="center">')).toContain('data-align="center"');
137
+ });
138
+ /*
139
+ * ⚠️ 강의영상(`tiptap-midibus`)은 `rawAttrs` 를 그대로 되뱉는 바이트 보존 노드라,
140
+ * 높이 드래그가 `height` 속성만 바꾸면 저장본에는 옛 높이가 남는다. 드래그 커밋이
141
+ * 하는 것과 같은 갱신(attrs + rawAttrs 동기)을 걸어 왕복을 확인한다.
142
+ */
143
+ it("TiptapMidibus — 높이 갱신이 rawAttrs 와 함께 가고 나머지는 바이트 보존", () => {
144
+ const source = '<tiptap-midibus id="abc" start="5" uuid="u-1" width="100%" height="600" data-bubble-menu="false"></tiptap-midibus>';
145
+ createEditor([TiptapMidibus], source);
146
+ expect(editor.getHTML()).toContain('id="abc" start="5" uuid="u-1" width="100%" height="600" data-bubble-menu="false"');
147
+ const found = findNode("tiptapMidibus");
148
+ const raw = found.node.attrs.rawAttrs;
149
+ // 높이 드래그 커밋과 같은 트랜잭션(`TiptapMidibus` 노드뷰의 `buildAttrs`)
150
+ editor.view.dispatch(editor.view.state.tr.setNodeMarkup(found.pos, undefined, {
151
+ ...found.node.attrs,
152
+ height: "420",
153
+ rawAttrs: { ...raw, height: "420" }
154
+ }));
155
+ expect(editor.getHTML()).toContain('id="abc" start="5" uuid="u-1" width="100%" height="420" data-bubble-menu="false"');
156
+ });
157
+ });
158
+ /* ─────────────────────────── 툴바 — 선택 시에만, 편집 모드에만 ─────────────────────────── */
159
+ describe("MediaResizeToolbar 데코레이션", () => {
160
+ let editor;
161
+ const CONTENT = '<p>글</p><div data-video-src="https://player.vimeo.com/video/1"></div>';
162
+ function createEditor(editable = true) {
163
+ editor = new Editor({
164
+ element: document.createElement("div"),
165
+ extensions: [StarterKit, VideoEmbed, MediaResizeToolbar],
166
+ content: CONTENT,
167
+ editable
168
+ });
169
+ return editor;
170
+ }
171
+ afterEach(() => {
172
+ editor?.destroy();
173
+ });
174
+ function videoPos() {
175
+ let at = -1;
176
+ editor.state.doc.descendants((node, pos) => {
177
+ if (at >= 0)
178
+ return false;
179
+ if (node.type.name === "videoEmbed")
180
+ at = pos;
181
+ return at < 0;
182
+ });
183
+ return at;
184
+ }
185
+ it("미디어 노드를 선택하면 칩 줄이 서고, 선택을 풀면 사라진다", () => {
186
+ createEditor();
187
+ expect(editor.view.dom.querySelector(".hce-media-toolbar")).toBeNull();
188
+ editor.commands.setNodeSelection(videoPos());
189
+ const toolbar = editor.view.dom.querySelector(".hce-media-toolbar");
190
+ expect(toolbar).not.toBeNull();
191
+ // 비율 3 + 정렬 3 + 폭 2
192
+ expect(toolbar.querySelectorAll(".hce-media-toolbar-chip").length).toBe(8);
193
+ editor.commands.setTextSelection(1);
194
+ expect(editor.view.dom.querySelector(".hce-media-toolbar")).toBeNull();
195
+ });
196
+ it("읽기 전용에는 절대 뜨지 않는다", () => {
197
+ createEditor(false);
198
+ editor.commands.setNodeSelection(videoPos());
199
+ expect(editor.view.dom.querySelector(".hce-media-toolbar")).toBeNull();
200
+ });
201
+ it("칩 mousedown 이 속성을 바꾸고 저장본까지 간다", () => {
202
+ createEditor();
203
+ editor.commands.setNodeSelection(videoPos());
204
+ const chip = editor.view.dom.querySelector('.hce-media-toolbar-chip[data-action="align"][data-value="center"]');
205
+ expect(chip).not.toBeNull();
206
+ chip.dispatchEvent(new MouseEvent("mousedown", { bubbles: true, cancelable: true }));
207
+ const node = editor.state.doc.nodeAt(videoPos());
208
+ expect(node?.attrs.align).toBe("center");
209
+ expect(editor.getHTML()).toContain('data-video-align="center"');
210
+ // 툴바가 새 상태로 다시 그려져 칩이 켜져 있어야 한다
211
+ const pressed = editor.view.dom.querySelector('.hce-media-toolbar-chip[data-action="align"][data-value="center"]');
212
+ expect(pressed?.getAttribute("aria-pressed")).toBe("true");
213
+ });
214
+ it("비율 칩은 높이를 풀면서 들어간다", () => {
215
+ createEditor();
216
+ const pos = videoPos();
217
+ editor.view.dispatch(editor.view.state.tr.setNodeMarkup(pos, undefined, {
218
+ ...editor.state.doc.nodeAt(pos).attrs,
219
+ height: "360"
220
+ }));
221
+ editor.commands.setNodeSelection(pos);
222
+ const chip = editor.view.dom.querySelector('.hce-media-toolbar-chip[data-action="ratio"][data-value="4:3"]');
223
+ chip.dispatchEvent(new MouseEvent("mousedown", { bubbles: true, cancelable: true }));
224
+ const node = editor.state.doc.nodeAt(pos);
225
+ expect(node?.attrs.ratio).toBe("4:3");
226
+ expect(node?.attrs.height).toBeNull();
227
+ const html = editor.getHTML();
228
+ expect(html).toContain('data-video-ratio="4:3"');
229
+ expect(html).not.toContain("data-video-height");
230
+ });
231
+ });
@@ -0,0 +1,2 @@
1
+ export declare const OrderedListMarker: import("@tiptap/core").Node<import("@tiptap/extension-list").OrderedListOptions, any>;
2
+ //# sourceMappingURL=OrderedListMarker.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"OrderedListMarker.d.ts","sourceRoot":"","sources":["../../src/extensions/OrderedListMarker.ts"],"names":[],"mappings":"AAgDA,eAAO,MAAM,iBAAiB,uFAwE5B,CAAC"}
@@ -0,0 +1,114 @@
1
+ /**
2
+ * 순서목록 마커 확장 — 정올 main(`packages/tiptap/plugin/orderedlist`, 커밋 9362eef6) 이식.
3
+ *
4
+ * `1. ` 만 받던 순서목록 입력 규칙을 여섯 마커로 넓힌다:
5
+ *
6
+ * | 치는 것 | type | 표시 |
7
+ * |---|---|---|
8
+ * | `1.` `2.` … | (없음) | decimal |
9
+ * | `a.` ~ `z.` | `a` | lower-alpha |
10
+ * | `A.` ~ `Z.` | `A` | upper-alpha |
11
+ * | `i.` | `i` | lower-roman |
12
+ * | `I.` | `I` | upper-roman |
13
+ * | `ㄱ.` ~ `ㅎ.` | `kors` | ㄱ. ㄴ. …(카운터 스타일) |
14
+ * | `가.` ~ `하.` | `korc` | 가. 나. …(카운터 스타일) |
15
+ *
16
+ * 중간 값으로 시작하면(`3.` `c.` `다.`) `start` 가 잡히고, **직전 목록의 다음 번호면 그
17
+ * 목록에 이어붙는다**(`canJoinSequentialList`). 마커 종류가 다르면 번호가 이어져도 안 붙는다.
18
+ *
19
+ * ⚠️ **main 과 다른 점 둘.**
20
+ * 1. 숫자 목록의 `type` 을 심지 않는다(main 은 default `'1'` 이라 모든 `<ol>` 에
21
+ * `type="1"` 이 붙는다). 기존 저장본·왕복 결과를 그대로 두기 위해서다 — 판정은
22
+ * `type ?? '1'` 로 동일하다.
23
+ * 2. `renderHTML` 이 `marker-<type>` 클래스를 함께 심는다. CSS 속성 선택자는 HTML `type`
24
+ * 값을 **대소문자 무시**로 매치해서(`[type='a']` 가 `A` 도 잡는다) 속성만으로는
25
+ * lower/upper 를 가를 수 없다 — 클래스 선택자는 대소문자를 구분한다.
26
+ * (main 은 앱 CSS 가 `ol` 의 list-style 을 안 덮어서 UA 의 type 속성 매핑으로 충분했다.
27
+ * 여기는 `editor.css` 가 `.tiptap ol { list-style: decimal }` 을 깔아 그 길이 막혀 있다.)
28
+ *
29
+ * 편집기 밖 표시: 정올 main 이 저장한 옛 본문(`<ol type="A">`, 클래스 없음)은 정적 렌더
30
+ * (`src/static/index.ts` 의 `annotateOrderedListMarkers`)가 같은 클래스를 표시 시점에 입힌다.
31
+ */
32
+ import { mergeAttributes, wrappingInputRule } from '@tiptap/core';
33
+ import { OrderedList } from '@tiptap/extension-list';
34
+ const KOREAN_CONSONANTS = ['ㄱ', 'ㄴ', 'ㄷ', 'ㄹ', 'ㅁ', 'ㅂ', 'ㅅ', 'ㅇ', 'ㅈ', 'ㅊ', 'ㅋ', 'ㅌ', 'ㅍ', 'ㅎ'];
35
+ const KOREAN_SYLLABLES = ['가', '나', '다', '라', '마', '바', '사', '아', '자', '차', '카', '타', '파', '하'];
36
+ /**
37
+ * 직전 목록에 이어붙일 수 있나 — 마커 종류가 같고, 목록의 다음 번호(start + 항목 수)가
38
+ * 방금 친 번호와 같아야 한다. `type` 없는 목록은 숫자 목록(`'1'`)으로 본다.
39
+ */
40
+ const canJoinSequentialList = (node, type, markerOrdinal) => {
41
+ const nodeType = node.attrs.type || '1';
42
+ const nodeStart = Number(node.attrs.start ?? 1);
43
+ return nodeType === type && nodeStart + node.childCount === markerOrdinal;
44
+ };
45
+ export const OrderedListMarker = OrderedList.extend({
46
+ renderHTML({ HTMLAttributes }) {
47
+ const { start, type, ...rest } = HTMLAttributes;
48
+ const attrs = { ...rest };
49
+ // 기본 확장과 같은 규칙 — start 1 은 안 적는다(적으나 안 적으나 같은 목록이다).
50
+ if (start !== undefined && start !== null && start !== 1)
51
+ attrs.start = start;
52
+ if (type) {
53
+ attrs.type = type;
54
+ attrs.class = `marker-${type}`;
55
+ }
56
+ return ['ol', mergeAttributes(this.options.HTMLAttributes, attrs), 0];
57
+ },
58
+ addInputRules() {
59
+ /*
60
+ * ⚠️ 규칙 순서가 곧 우선순위다. `i.`/`I.`(로마 숫자)는 `a-z`/`A-Z`(알파벳)에도
61
+ * 걸리므로 **로마 숫자 규칙이 먼저** 와야 한다 — main 과 같은 배치.
62
+ */
63
+ return [
64
+ wrappingInputRule({
65
+ find: /^(\d+)\.\s$/,
66
+ type: this.type,
67
+ getAttributes: (match) => ({ start: +match[1] }),
68
+ joinPredicate: (match, node) => canJoinSequentialList(node, '1', +match[1])
69
+ }),
70
+ wrappingInputRule({
71
+ find: /^i\.\s$/,
72
+ type: this.type,
73
+ getAttributes: () => ({ start: 1, type: 'i' }),
74
+ joinPredicate: (_match, node) => canJoinSequentialList(node, 'i', 1)
75
+ }),
76
+ wrappingInputRule({
77
+ find: /^I\.\s$/,
78
+ type: this.type,
79
+ getAttributes: () => ({ start: 1, type: 'I' }),
80
+ joinPredicate: (_match, node) => canJoinSequentialList(node, 'I', 1)
81
+ }),
82
+ wrappingInputRule({
83
+ find: /^([A-Z])\.\s$/,
84
+ type: this.type,
85
+ getAttributes: (match) => ({ start: match[1].charCodeAt(0) - 64, type: 'A' }),
86
+ joinPredicate: (match, node) => canJoinSequentialList(node, 'A', match[1].charCodeAt(0) - 64)
87
+ }),
88
+ wrappingInputRule({
89
+ find: /^([a-z])\.\s$/,
90
+ type: this.type,
91
+ getAttributes: (match) => ({ start: match[1].charCodeAt(0) - 96, type: 'a' }),
92
+ joinPredicate: (match, node) => canJoinSequentialList(node, 'a', match[1].charCodeAt(0) - 96)
93
+ }),
94
+ wrappingInputRule({
95
+ find: /^([ㄱㄴㄷㄹㅁㅂㅅㅇㅈㅊㅋㅌㅍㅎ])\.\s$/,
96
+ type: this.type,
97
+ getAttributes: (match) => ({
98
+ start: 1 + KOREAN_CONSONANTS.indexOf(match[1]),
99
+ type: 'kors'
100
+ }),
101
+ joinPredicate: (match, node) => canJoinSequentialList(node, 'kors', 1 + KOREAN_CONSONANTS.indexOf(match[1]))
102
+ }),
103
+ wrappingInputRule({
104
+ find: /^([가나다라마바사아자차카타파하])\.\s$/,
105
+ type: this.type,
106
+ getAttributes: (match) => ({
107
+ start: 1 + KOREAN_SYLLABLES.indexOf(match[1]),
108
+ type: 'korc'
109
+ }),
110
+ joinPredicate: (match, node) => canJoinSequentialList(node, 'korc', 1 + KOREAN_SYLLABLES.indexOf(match[1]))
111
+ })
112
+ ];
113
+ }
114
+ });
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=OrderedListMarker.test.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"OrderedListMarker.test.d.ts","sourceRoot":"","sources":["../../src/extensions/OrderedListMarker.test.ts"],"names":[],"mappings":""}
@@ -0,0 +1,176 @@
1
+ import { describe, it, expect, afterEach } from 'vitest';
2
+ import { Editor } from '@tiptap/core';
3
+ import StarterKit from '@tiptap/starter-kit';
4
+ import { OrderedListMarker } from './OrderedListMarker';
5
+ import { sanitizeHtml } from '../utils/sanitize';
6
+ import { renderStaticHtml } from '../static';
7
+ /*
8
+ * 순서목록 마커는 **입력 규칙이 전부다** — 명령으로는 못 만들고 쳐야만 나온다.
9
+ * 그래서 `handleTextInput` 을 한 글자씩 두드려 실제 타이핑을 재현한다
10
+ * (`insertContent` 는 입력 규칙을 태우지 않는다).
11
+ */
12
+ describe('순서목록 마커 (OrderedListMarker)', () => {
13
+ let editor;
14
+ function createEditor(content = '<p></p>') {
15
+ editor = new Editor({
16
+ element: document.createElement('div'),
17
+ extensions: [StarterKit.configure({ orderedList: false }), OrderedListMarker],
18
+ content
19
+ });
20
+ return editor;
21
+ }
22
+ function type(text) {
23
+ for (const char of text) {
24
+ const { from, to } = editor.state.selection;
25
+ const handled = editor.view.someProp('handleTextInput', (f) => f(editor.view, from, to, char, () => editor.state.tr.insertText(char, from, to)));
26
+ if (!handled)
27
+ editor.commands.insertContent(char);
28
+ }
29
+ }
30
+ const json = () => editor.getJSON();
31
+ const blocks = () => json().content ?? [];
32
+ const firstBlock = () => blocks()[0];
33
+ /*
34
+ * StarterKit v3 의 `TrailingNode` 가 문서 끝에 빈 문단을 항상 하나 붙여 두므로,
35
+ * "목록이 몇 개가 됐나"는 전체 블록 수가 아니라 orderedList 만 세야 한다.
36
+ */
37
+ const lists = () => blocks().filter((block) => block.type === 'orderedList');
38
+ /** 마지막 빈 문단 안(입력 규칙을 칠 자리)으로 커서를 옮긴다. */
39
+ function moveToTrailingParagraph() {
40
+ editor.commands.setTextSelection(editor.state.doc.content.size - 1);
41
+ }
42
+ afterEach(() => {
43
+ editor?.destroy();
44
+ });
45
+ describe('마커별 입력 규칙', () => {
46
+ it('`1. ` — 숫자 목록. type 을 심지 않아 저장본이 예전과 같다', () => {
47
+ createEditor();
48
+ type('1. ');
49
+ expect(firstBlock()?.type).toBe('orderedList');
50
+ expect(firstBlock()?.attrs?.start).toBe(1);
51
+ expect(firstBlock()?.attrs?.type ?? null).toBeNull();
52
+ expect(editor.getHTML()).toContain('<ol>');
53
+ });
54
+ it('`3. ` — 중간 번호로 시작하면 start 가 잡힌다', () => {
55
+ createEditor();
56
+ type('3. ');
57
+ expect(firstBlock()?.attrs?.start).toBe(3);
58
+ expect(editor.getHTML()).toContain('<ol start="3">');
59
+ });
60
+ it('`a. ` — lower-alpha. type 속성과 marker 클래스가 같이 남는다', () => {
61
+ createEditor();
62
+ type('a. ');
63
+ expect(firstBlock()?.attrs).toMatchObject({ start: 1, type: 'a' });
64
+ expect(editor.getHTML()).toContain('<ol type="a" class="marker-a">');
65
+ });
66
+ it('`c. ` — 알파벳 중간 시작은 서수로 환산된다 (c → 3)', () => {
67
+ createEditor();
68
+ type('c. ');
69
+ expect(firstBlock()?.attrs).toMatchObject({ start: 3, type: 'a' });
70
+ expect(editor.getHTML()).toContain('<ol start="3" type="a" class="marker-a">');
71
+ });
72
+ it('`B. ` — upper-alpha (B → 2)', () => {
73
+ createEditor();
74
+ type('B. ');
75
+ expect(firstBlock()?.attrs).toMatchObject({ start: 2, type: 'A' });
76
+ });
77
+ it('`i. `/`I. ` — 로마 숫자가 알파벳 규칙보다 먼저 잡는다', () => {
78
+ createEditor();
79
+ type('i. ');
80
+ expect(firstBlock()?.attrs).toMatchObject({ start: 1, type: 'i' });
81
+ editor.destroy();
82
+ createEditor();
83
+ type('I. ');
84
+ expect(firstBlock()?.attrs).toMatchObject({ start: 1, type: 'I' });
85
+ });
86
+ it('`ㄱ. ` — 한글 자음(kors)', () => {
87
+ createEditor();
88
+ type('ㄱ. ');
89
+ expect(firstBlock()?.attrs).toMatchObject({ start: 1, type: 'kors' });
90
+ expect(editor.getHTML()).toContain('<ol type="kors" class="marker-kors">');
91
+ });
92
+ it('`다. ` — 한글 음절(korc) 중간 시작 (다 → 3)', () => {
93
+ createEditor();
94
+ type('다. ');
95
+ expect(firstBlock()?.attrs).toMatchObject({ start: 3, type: 'korc' });
96
+ });
97
+ it('마커 뒤에 친 글자는 목록 항목 안으로 들어간다', () => {
98
+ createEditor();
99
+ type('a. 첫째');
100
+ const item = firstBlock()?.content?.[0];
101
+ expect(item?.type).toBe('listItem');
102
+ expect(item?.content?.[0].content?.[0].text).toBe('첫째');
103
+ });
104
+ });
105
+ describe('직전 목록에 이어붙기', () => {
106
+ it('숫자 — 다음 번호(3.)를 치면 두 항목짜리 목록에 붙는다', () => {
107
+ createEditor('<ol><li><p>하나</p></li><li><p>둘</p></li></ol><p></p>');
108
+ moveToTrailingParagraph();
109
+ type('3. ');
110
+ expect(lists()).toHaveLength(1);
111
+ expect(firstBlock()?.content).toHaveLength(3);
112
+ expect(firstBlock()?.attrs?.start).toBe(1);
113
+ });
114
+ it('알파벳 — `b. ` 가 type="a" 목록에 붙는다', () => {
115
+ createEditor('<ol type="a"><li><p>ㄱ</p></li></ol><p></p>');
116
+ moveToTrailingParagraph();
117
+ type('b. ');
118
+ expect(lists()).toHaveLength(1);
119
+ expect(firstBlock()?.content).toHaveLength(2);
120
+ expect(firstBlock()?.attrs?.type).toBe('a');
121
+ });
122
+ it('start 가 1 이 아닌 목록도 다음 번호부터 센다 (start=3 + 1항목 → D.)', () => {
123
+ createEditor('<ol type="A" start="3"><li><p>셋</p></li></ol><p></p>');
124
+ moveToTrailingParagraph();
125
+ type('D. ');
126
+ expect(lists()).toHaveLength(1);
127
+ expect(firstBlock()?.content).toHaveLength(2);
128
+ });
129
+ it('번호가 이어져도 마커 종류가 다르면 안 붙는다 (숫자 목록 뒤 `b. `)', () => {
130
+ createEditor('<ol><li><p>하나</p></li></ol><p></p>');
131
+ moveToTrailingParagraph();
132
+ type('b. ');
133
+ expect(lists()).toHaveLength(2);
134
+ expect(lists()[1]?.attrs).toMatchObject({ start: 2, type: 'a' });
135
+ });
136
+ it('번호가 안 이어지면 start 를 안고 새 목록이 선다 (1항목 뒤 `5. `)', () => {
137
+ createEditor('<ol><li><p>하나</p></li></ol><p></p>');
138
+ moveToTrailingParagraph();
139
+ type('5. ');
140
+ expect(lists()).toHaveLength(2);
141
+ expect(lists()[1]?.attrs?.start).toBe(5);
142
+ });
143
+ });
144
+ describe('sanitize 왕복', () => {
145
+ it('type·start·marker 클래스가 살균을 그대로 통과하고, 되읽어도 속성이 남는다', () => {
146
+ createEditor();
147
+ type('C. ');
148
+ const html = editor.getHTML();
149
+ expect(html).toContain('start="3"');
150
+ expect(html).toContain('type="A"');
151
+ expect(html).toContain('class="marker-A"');
152
+ const sanitized = sanitizeHtml(html);
153
+ expect(sanitized).toContain('start="3"');
154
+ expect(sanitized).toContain('type="A"');
155
+ expect(sanitized).toContain('class="marker-A"');
156
+ editor.commands.setContent(sanitized);
157
+ expect(firstBlock()?.attrs).toMatchObject({ start: 3, type: 'A' });
158
+ });
159
+ });
160
+ describe('정적 렌더 (renderStaticHtml)', () => {
161
+ it('정올 main 이 저장한 클래스 없는 ol[type] 에 marker 클래스를 입힌다', () => {
162
+ const out = renderStaticHtml('<ol type="A" start="3"><li><p>셋</p></li></ol>');
163
+ expect(out).toContain('type="A"');
164
+ expect(out).toContain('start="3"');
165
+ expect(out).toContain('class="marker-A"');
166
+ });
167
+ it('이미 marker 클래스가 있으면 원본을 그대로 돌려준다', () => {
168
+ const html = '<ol type="korc" class="marker-korc"><li><p>가</p></li></ol>';
169
+ expect(renderStaticHtml(html)).toBe(html);
170
+ });
171
+ it('type 없는 목록은 건드리지 않는다', () => {
172
+ const html = '<ol start="3"><li><p>x</p></li></ol>';
173
+ expect(renderStaticHtml(html)).toBe(html);
174
+ });
175
+ });
176
+ });
@@ -1 +1 @@
1
- {"version":3,"file":"PdfBlock.d.ts","sourceRoot":"","sources":["../../src/extensions/PdfBlock.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,IAAI,UAAU,EAAmB,MAAM,cAAc,CAAC;AAYnE,eAAO,MAAM,QAAQ,sBAs1BnB,CAAC"}
1
+ {"version":3,"file":"PdfBlock.d.ts","sourceRoot":"","sources":["../../src/extensions/PdfBlock.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,IAAI,UAAU,EAAmB,MAAM,cAAc,CAAC;AAanE,eAAO,MAAM,QAAQ,sBAu1BnB,CAAC"}