@watalabs/lasee-mditor 0.0.0-stage → 0.1.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.
- package/LICENSE +21 -0
- package/README.md +230 -2
- package/dist/core.js +1 -0
- package/dist/editor-B1BHeyw9.js +2847 -0
- package/dist/html-BGPHBFj_.js +925 -0
- package/dist/index.js +4 -0
- package/dist/lasee-mditor.umd.js +177 -0
- package/dist/react.js +37 -0
- package/dist/rolldown-runtime-CGnMp29N.js +10 -0
- package/dist/style.css +990 -0
- package/dist/types/core/html.d.ts +15 -0
- package/dist/types/core/inline.d.ts +65 -0
- package/dist/types/core/parse.d.ts +32 -0
- package/dist/types/core/table.d.ts +10 -0
- package/dist/types/core/types.d.ts +74 -0
- package/dist/types/core/write.d.ts +12 -0
- package/dist/types/core.d.ts +6 -0
- package/dist/types/index.d.ts +8 -0
- package/dist/types/pm/commands.d.ts +50 -0
- package/dist/types/pm/convert.d.ts +37 -0
- package/dist/types/pm/plugins.d.ts +83 -0
- package/dist/types/pm/schema.d.ts +15 -0
- package/dist/types/react.d.ts +32 -0
- package/dist/types/ui/dom.d.ts +30 -0
- package/dist/types/ui/editor.d.ts +118 -0
- package/dist/types/ui/icons.d.ts +5 -0
- package/dist/types/ui/messages.d.ts +123 -0
- package/dist/types/ui/panels.d.ts +16 -0
- package/package.json +82 -4
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { Block, Doc, Item } from "./types";
|
|
2
|
+
export declare const escapeHtml: (s: string) => string;
|
|
3
|
+
export type HtmlOptions = {
|
|
4
|
+
/** 그림 이름 → 주소. 없으면 이름을 그대로 쓴다. */
|
|
5
|
+
resolveImage?: (src: string) => string | undefined;
|
|
6
|
+
/** 링크를 새 창으로 연다(기본 true). */
|
|
7
|
+
linkTarget?: "_blank" | null;
|
|
8
|
+
};
|
|
9
|
+
/** 서식 문자열 → HTML. */
|
|
10
|
+
export declare function inlineHtml(s: string, o?: HtmlOptions): string;
|
|
11
|
+
/** 목록 항목 번호 — MD 로 쓸 때와 같은 규칙(구간마다 start 또는 1부터). */
|
|
12
|
+
export declare function itemNumbers(items: Item[]): (number | null)[];
|
|
13
|
+
export declare function blockHtml(b: Block, o?: HtmlOptions): string;
|
|
14
|
+
/** 문서(또는 MD) → HTML. */
|
|
15
|
+
export declare function renderHtml(doc: Doc | string, o?: HtmlOptions): string;
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
export declare const INLINE_COLORS: Record<string, string>;
|
|
2
|
+
export declare const SHADE = "#d9d9d9";
|
|
3
|
+
export declare const MARK = "#fff3a3";
|
|
4
|
+
/** 정렬 태그 → CSS 정렬. 왼쪽은 기본이라 문단에 남기지 않는다. */
|
|
5
|
+
export declare const ALIGN_TAGS: Record<string, TextAlign | null>;
|
|
6
|
+
export type TextAlign = "center" | "right" | "justify";
|
|
7
|
+
export type Dialect = "ko" | "en";
|
|
8
|
+
export declare const ESCAPABLE = "\\*~{}<>^|#-+!`[]=._)";
|
|
9
|
+
/** 글자 색 태그인가 — 이름 붙은 색(빨강 · 파랑 · 회색) 또는 색 코드(#rrggbb). */
|
|
10
|
+
export declare const isColor: (name: string) => boolean;
|
|
11
|
+
/** 글자 색 태그 → 색 코드. */
|
|
12
|
+
export declare const colorCss: (name: string) => string;
|
|
13
|
+
export declare const PS = "[\\t\\n\\v\\f\\r \\u0085\\u00a0\\u1680\\u2000-\\u200a\\u2028\\u2029\\u202f\\u205f\\u3000]";
|
|
14
|
+
export declare const SPACES: RegExp;
|
|
15
|
+
/** 파이썬 str.strip() 과 같은 공백 떼기. */
|
|
16
|
+
export declare function pyStrip(s: string): string;
|
|
17
|
+
export type Script = "sup" | "sub";
|
|
18
|
+
export type Seg = {
|
|
19
|
+
text: string;
|
|
20
|
+
link?: string | null;
|
|
21
|
+
bold?: boolean;
|
|
22
|
+
strike?: boolean;
|
|
23
|
+
italic?: boolean;
|
|
24
|
+
underline?: boolean;
|
|
25
|
+
shade?: boolean;
|
|
26
|
+
mark?: boolean;
|
|
27
|
+
color?: string | null;
|
|
28
|
+
script?: Script | null;
|
|
29
|
+
code?: boolean;
|
|
30
|
+
};
|
|
31
|
+
/** 서식 문자열 → 조각. 줄바꿈(<br>)은 글자 "\n" 으로 들어간다. */
|
|
32
|
+
export declare function segments(s: string): Seg[];
|
|
33
|
+
/**
|
|
34
|
+
* 표준 꼴: 코드 안의 줄바꿈은 빈칸으로, 전체 앞뒤 공백·줄바꿈을 버리고,
|
|
35
|
+
* 굵게·취소선·형광펜 구간의 앞뒤 공백을 구간 밖으로 민다(짝 규칙 때문에 기호 안쪽에 공백을 둘 수 없다).
|
|
36
|
+
*/
|
|
37
|
+
export declare function normalize(segs: Seg[]): Seg[];
|
|
38
|
+
/** 태그 이름을 문서의 태그 언어로(`tag("음영", "en") === "shade"`). */
|
|
39
|
+
export declare const tag: (name: string, dialect?: Dialect) => string;
|
|
40
|
+
/** 링크 주소를 MD 에 쓸 꼴로 — 공백이나 짝 안 맞는 괄호가 있으면 퍼센트 부호로 바꾼다. */
|
|
41
|
+
export declare function linkHref(href: string): string;
|
|
42
|
+
/** 문서의 태그 언어 — 처음 나오는 짝 맞은 태그가 정한다. 태그가 없으면 null. */
|
|
43
|
+
export declare function dialectOf(text: string): Dialect | null;
|
|
44
|
+
export type Ctx = "cell" | "para" | "item" | null;
|
|
45
|
+
/**
|
|
46
|
+
* 조각 → 서식 문자열. `segs` 는 normalize 를 거친 것이어야 한다.
|
|
47
|
+
* ctx="cell": 칸 전체가 `<` · `^` 하나면 이스케이프(칸 합치기 기호와 구별).
|
|
48
|
+
* ctx="para": 문단이 블록 기호(#, >, -, |, 그림, 번호, 쪽 나눔)로 시작하거나 가로줄(---)로 읽히면 이스케이프.
|
|
49
|
+
* ctx="item": 항목이 `- ` 뒤에 붙어 가로줄로 읽히거나 할 일 칸(`[ ]`)으로 시작하면 이스케이프.
|
|
50
|
+
*/
|
|
51
|
+
export declare function write(segs: Seg[], ctx?: Ctx, dialect?: Dialect): string;
|
|
52
|
+
/** 서식 문자열을 표준 꼴로. */
|
|
53
|
+
export declare function canon(s: string, ctx?: Ctx, dialect?: Dialect): string;
|
|
54
|
+
/** 줄바꿈·빈칸 문자를 빈칸 하나로, 이어진 빈칸은 조각 경계를 넘어서도 하나로(서버 _one_space). */
|
|
55
|
+
export declare function oneSpace(segs: Seg[]): Seg[];
|
|
56
|
+
/** 제목(# ## ###)의 표준 꼴(서버 inline.title). 서식은 본문과 같고, 한 줄이므로 줄바꿈은 빈칸이며 이어진 빈칸은 하나다. */
|
|
57
|
+
export declare function title(s: string, dialect?: Dialect): string;
|
|
58
|
+
/** 서식을 뗀 글자만(줄바꿈은 공백). */
|
|
59
|
+
export declare function plainInline(s: string): string;
|
|
60
|
+
/** 칸 전체를 `{음영}…{/음영}` 으로 감쌌으면 [true, 속 내용] — 칸 배경이다. */
|
|
61
|
+
export declare function cellShade(s: string): [boolean, string];
|
|
62
|
+
/** 문단 전체를 정렬 태그(`{가운데}…{/가운데}`)로 감쌌으면 [정렬, 속 내용]. 왼쪽은 기본이라 null. */
|
|
63
|
+
export declare function blockAlign(s: string): [TextAlign | null, string, boolean];
|
|
64
|
+
/** 링크 주소가 열어도 되는 것인가(javascript: 같은 것은 막는다). 화면에 그릴 때 쓴다. */
|
|
65
|
+
export declare function safeHref(href: string): string | null;
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { type Dialect } from "./inline";
|
|
2
|
+
import { type BlockBody, type Doc, type Item } from "./types";
|
|
3
|
+
export declare const MAX_LEVEL = 3;
|
|
4
|
+
export declare const MAX_COLS = 40;
|
|
5
|
+
type Fence = {
|
|
6
|
+
indent: number;
|
|
7
|
+
size: number;
|
|
8
|
+
lang: string;
|
|
9
|
+
};
|
|
10
|
+
/** 코드 울타리(```)를 여는 줄이면 {들여쓰기, 백틱 수, 언어}. */
|
|
11
|
+
export declare function openFence(line: string): Fence | null;
|
|
12
|
+
export declare const oneLine: (s: unknown) => string;
|
|
13
|
+
/** 표 한 줄 → 칸. `\|` 는 칸 안의 글자 `|` 이다(다른 이스케이프는 글 서식 쪽에서 푼다). */
|
|
14
|
+
export declare function splitCells(line: string): string[];
|
|
15
|
+
type RawItem = {
|
|
16
|
+
text: string;
|
|
17
|
+
level: number;
|
|
18
|
+
ordered: boolean;
|
|
19
|
+
num: number;
|
|
20
|
+
checked: boolean | null;
|
|
21
|
+
};
|
|
22
|
+
/** 목록 항목들의 단계를 다듬고(앞 항목보다 한 단계까지만 깊어진다), 번호 구간의 첫 항목에 시작 번호를 단다. */
|
|
23
|
+
export declare function finishItems(raw: RawItem[]): Item[];
|
|
24
|
+
/** (줄 번호, 줄) → id 없는 블록 목록. 섹션 머리(##)는 여기 오기 전에 걸러진다. */
|
|
25
|
+
export declare function parseBlocks(lines: [number, string][], dialect?: Dialect): BlockBody[];
|
|
26
|
+
/**
|
|
27
|
+
* MD → 문서. 줄 번호가 든 MdError 를 낸다.
|
|
28
|
+
* 글 서식 태그는 문서의 태그 언어로 쓴다 — 문서에 태그가 있으면 그것, 없으면 dialect(부르는 쪽의 언어), 그것도 없으면 한국어.
|
|
29
|
+
* 섹션 key · 블록 id 는 차례대로 붙인다(s1, b1 …). 서버는 원본 문서의 id 를 잇는다(md.attach_ids).
|
|
30
|
+
*/
|
|
31
|
+
export declare function parseMarkdown(text: string, dialect?: Dialect | null): Doc;
|
|
32
|
+
export {};
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export type CellSpan = {
|
|
2
|
+
hidden: boolean;
|
|
3
|
+
rowSpan: number;
|
|
4
|
+
colSpan: number;
|
|
5
|
+
};
|
|
6
|
+
export declare function marker(cell: string): "<" | "^" | null;
|
|
7
|
+
/** 격자 → 칸마다 {숨은 칸인지, 행 수, 열 수}. */
|
|
8
|
+
export declare function spans(rows: string[][]): CellSpan[][];
|
|
9
|
+
/** 합치기 기호를 표준 꼴로: 숨은 칸이 기준 칸과 같은 행이면 `<`, 아니면 `^`. 합쳐지지 않는 기호는 이스케이프. */
|
|
10
|
+
export declare function canonical(rows: string[][]): string[][];
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import type { Dialect, TextAlign } from "./inline";
|
|
2
|
+
export type Align = "left" | "center" | "right" | null;
|
|
3
|
+
/** 목록 항목. ordered: 번호 항목(`1.`), start: 번호가 이어지는 구간의 첫 항목만 — 1이 아닐 때, checked: 할 일 항목(`[ ]` · `[x]`). */
|
|
4
|
+
export type Item = {
|
|
5
|
+
text: string;
|
|
6
|
+
level: number;
|
|
7
|
+
ordered?: boolean;
|
|
8
|
+
start?: number;
|
|
9
|
+
checked?: boolean;
|
|
10
|
+
};
|
|
11
|
+
type BlockBase = {
|
|
12
|
+
id: string;
|
|
13
|
+
title: string | null;
|
|
14
|
+
notes: string[];
|
|
15
|
+
};
|
|
16
|
+
export type TextBlock = BlockBase & {
|
|
17
|
+
kind: "text";
|
|
18
|
+
text: string;
|
|
19
|
+
align?: TextAlign;
|
|
20
|
+
};
|
|
21
|
+
export type ListBlock = BlockBase & {
|
|
22
|
+
kind: "list";
|
|
23
|
+
items: Item[];
|
|
24
|
+
};
|
|
25
|
+
export type TableBlock = BlockBase & {
|
|
26
|
+
kind: "table";
|
|
27
|
+
head: string[][];
|
|
28
|
+
rows: string[][];
|
|
29
|
+
align: Align[];
|
|
30
|
+
};
|
|
31
|
+
export type ImageBlock = BlockBase & {
|
|
32
|
+
kind: "image";
|
|
33
|
+
src: string;
|
|
34
|
+
caption: string;
|
|
35
|
+
};
|
|
36
|
+
export type CodeBlock = BlockBase & {
|
|
37
|
+
kind: "code";
|
|
38
|
+
lang: string;
|
|
39
|
+
code: string;
|
|
40
|
+
};
|
|
41
|
+
export type RuleBlock = BlockBase & {
|
|
42
|
+
kind: "rule";
|
|
43
|
+
};
|
|
44
|
+
export type PageBreakBlock = BlockBase & {
|
|
45
|
+
kind: "pagebreak";
|
|
46
|
+
};
|
|
47
|
+
export type Block = TextBlock | ListBlock | TableBlock | ImageBlock | CodeBlock | RuleBlock | PageBreakBlock;
|
|
48
|
+
export type BlockKind = Block["kind"];
|
|
49
|
+
/** id 없는 블록(읽는 중 · 쓰기 전). */
|
|
50
|
+
export type BlockBody = {
|
|
51
|
+
[K in BlockKind]: Omit<Extract<Block, {
|
|
52
|
+
kind: K;
|
|
53
|
+
}>, "id">;
|
|
54
|
+
}[BlockKind];
|
|
55
|
+
export type Section = {
|
|
56
|
+
key: string;
|
|
57
|
+
title: string;
|
|
58
|
+
blocks: Block[];
|
|
59
|
+
};
|
|
60
|
+
/** dialect: 문서의 태그 언어(읽을 때 정해진다). 정렬 태그를 쓸 때 쓴다. */
|
|
61
|
+
export type Doc = {
|
|
62
|
+
title: string;
|
|
63
|
+
sections: Section[];
|
|
64
|
+
dialect?: Dialect;
|
|
65
|
+
};
|
|
66
|
+
/** MD 를 읽다 난 오류. line 은 1부터 센다. code 는 문구를 고를 열쇠, params 는 문구에 채울 값. */
|
|
67
|
+
export declare class MdError extends Error {
|
|
68
|
+
line: number | null;
|
|
69
|
+
code: MdErrorCode;
|
|
70
|
+
params: Record<string, string | number>;
|
|
71
|
+
constructor(line: number | null, code: MdErrorCode, params?: Record<string, string | number>, message?: string);
|
|
72
|
+
}
|
|
73
|
+
export type MdErrorCode = "table-no-delim" | "table-no-head" | "table-too-wide" | "table-row-too-long";
|
|
74
|
+
export {};
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { type Dialect, type TextAlign } from "./inline";
|
|
2
|
+
import type { BlockBody, Doc, Item, Section } from "./types";
|
|
3
|
+
/** 목록 항목 → 줄들. 번호는 구간마다 시작 번호(start, 없으면 1)부터 이어 세고, 들여쓰기는 부모 항목의 글 시작 칸에 맞춘다. */
|
|
4
|
+
export declare function itemLines(items: Item[]): string[];
|
|
5
|
+
/** 코드 블록의 울타리 — 코드 안의 가장 긴 백틱보다 하나 길게(3개 이상). */
|
|
6
|
+
export declare function codeFence(code: string): string;
|
|
7
|
+
/** 문단의 정렬을 태그로 감싼다(`{가운데}…{/가운데}`). */
|
|
8
|
+
export declare function alignText(text: string, align: TextAlign | null | undefined, dialect: Dialect): string;
|
|
9
|
+
export declare function blockMd(b: BlockBody, dialect?: Dialect): string;
|
|
10
|
+
export declare function sectionMd(s: Pick<Section, "title" | "blocks">, heading?: boolean, dialect?: Dialect): string;
|
|
11
|
+
/** 문서 → MD. 블록 사이는 빈 줄 하나, 끝은 줄바꿈 하나. 정렬 태그는 문서의 태그 언어(doc.dialect)로 쓴다. */
|
|
12
|
+
export declare function docToMarkdown(doc: Doc, dialect?: Dialect): string;
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export { parseMarkdown, parseBlocks, splitCells, MAX_LEVEL, MAX_COLS } from "./core/parse";
|
|
2
|
+
export { docToMarkdown, blockMd, sectionMd, itemLines, codeFence } from "./core/write";
|
|
3
|
+
export { renderHtml, blockHtml, inlineHtml, escapeHtml, itemNumbers, type HtmlOptions } from "./core/html";
|
|
4
|
+
export { segments, normalize, write, canon, title, plainInline, dialectOf, cellShade, blockAlign, tag, isColor, colorCss, safeHref, linkHref, oneSpace, pyStrip, INLINE_COLORS, SHADE, MARK, SPACES, type Seg, type Ctx, type Dialect, type Script, type TextAlign, } from "./core/inline";
|
|
5
|
+
export { spans, canonical, marker, type CellSpan } from "./core/table";
|
|
6
|
+
export { MdError, type Doc, type Section, type Block, type BlockKind, type Item, type Align, type TextBlock, type ListBlock, type TableBlock, type ImageBlock, type CodeBlock, type RuleBlock, type PageBreakBlock, type MdErrorCode } from "./core/types";
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export * from "./core";
|
|
2
|
+
export { createEditor, DEFAULT_TOOLBAR, type MarkdownEditor, type MarkdownEditorOptions, type ToolbarItem, type ImageOptions, type EditorMode } from "./ui/editor";
|
|
3
|
+
export { messagesFor, ko as messagesKo, en as messagesEn, type Messages, type Locale } from "./ui/messages";
|
|
4
|
+
export { richExtensions, colorName, type RichOptions, type ImageResolver } from "./pm/schema";
|
|
5
|
+
export { toPM, fromPM, pmToDoc, inlineToPM, inlineToMd, titleToMd, tableData, tableMd } from "./pm/convert";
|
|
6
|
+
export * as commands from "./pm/commands";
|
|
7
|
+
export { ListNumbers, FindReplace, PageMarksExtension, listNumbers, findKey, pageMarkPlaces, pageMarksKey, type PageMarks, type PagePlace } from "./pm/plugins";
|
|
8
|
+
export type { DocTrace } from "./pm/convert";
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import type { Node as PMNode } from "@tiptap/pm/model";
|
|
2
|
+
import { type Command, type EditorState, type Transaction } from "@tiptap/pm/state";
|
|
3
|
+
export type CellAlign = "left" | "center" | "right";
|
|
4
|
+
export type BlockKind = "paragraph" | "docTitle" | "sectionHead" | "blockTitle" | "mdNote" | "codeBlock" | "list";
|
|
5
|
+
export type ListKind = "bullet" | "ordered" | "task";
|
|
6
|
+
export type ParagraphAlign = "left" | "center" | "right" | "justify";
|
|
7
|
+
/** 머리글 행 수 = 앞에서부터 연속으로 칸이 전부 머리글인 행(최소 1). */
|
|
8
|
+
export declare function headRows(table: PMNode): number;
|
|
9
|
+
/** 칸 합치기 — 머리글 칸과 본문 칸이 섞이면 거부한다(머리글과 본문은 따로 합친다). */
|
|
10
|
+
export declare const mergeSafe: Command;
|
|
11
|
+
/** 열 정렬 — 고른 열의 모든 칸에 건다. 같은 정렬을 다시 누르면 기본으로 돌아간다. */
|
|
12
|
+
export declare function setColumnAlign(align: CellAlign): Command;
|
|
13
|
+
/** 칸 음영 — 고른 칸들의 배경을 켜고 끈다. */
|
|
14
|
+
export declare const toggleCellShade: Command;
|
|
15
|
+
/** 아래에 행 넣기. */
|
|
16
|
+
export declare const addRowBelow: Command;
|
|
17
|
+
/** 위에 행 넣기. */
|
|
18
|
+
export declare const addRowAbove: Command;
|
|
19
|
+
/** 항목을 목록 밖으로 꺼내 문단(또는 다른 글 블록)으로 만든다. 목록은 그 자리에서 둘로 갈린다. */
|
|
20
|
+
export declare function liftItem(typeName?: string): Command;
|
|
21
|
+
/** 항목 단계 올리기·내리기(Tab / Shift-Tab). 앞 항목보다 한 단계까지만 깊어진다. */
|
|
22
|
+
export declare function shiftItem(delta: 1 | -1): Command;
|
|
23
|
+
/** Enter — 항목을 나눈다. 빈 항목이면 단계를 내리고, 맨 바깥 단계면 목록 밖으로 나간다. */
|
|
24
|
+
export declare const splitItem: Command;
|
|
25
|
+
/** 항목 맨 앞에서 Backspace — 단계를 내리고, 첫 항목이면 문단으로 꺼낸다. 그 밖에는 기본 동작(앞 항목과 합치기). */
|
|
26
|
+
export declare const backspaceItem: Command;
|
|
27
|
+
/** 지금 커서가 있는 블록의 종류(도구 막대 표시용). 표·그림 안이면 null. */
|
|
28
|
+
export declare function blockKind(state: EditorState): BlockKind | null;
|
|
29
|
+
/**
|
|
30
|
+
* 고른 블록들의 종류를 바꾼다(문단 ↔ 큰 제목 ↔ 작은 제목 ↔ 비고 ↔ 목록).
|
|
31
|
+
* 이미 그 종류면 문단으로 되돌린다. 표·그림은 건드리지 않는다.
|
|
32
|
+
*/
|
|
33
|
+
export declare function setBlockKind(kind: BlockKind): Command;
|
|
34
|
+
/** 맞닿은 목록을 하나로 합친다(MD 로 쓰면 어차피 한 목록으로 읽힌다). */
|
|
35
|
+
export declare function joinLists(tr: Transaction): void;
|
|
36
|
+
/** 항목의 목록 종류. */
|
|
37
|
+
export declare function itemKind(node: PMNode): ListKind;
|
|
38
|
+
/** 지금 커서가 있는 목록 항목의 종류(도구 막대 표시용). 목록 밖이면 null. */
|
|
39
|
+
export declare function listKind(state: EditorState): ListKind | null;
|
|
40
|
+
/**
|
|
41
|
+
* 글머리 · 번호 · 할 일 목록으로 만든다. 고른 것이 모두 이미 그 종류의 항목이면 문단으로 되돌린다.
|
|
42
|
+
* 항목이 아닌 글 블록은 항목으로 바꾼 뒤 종류를 건다.
|
|
43
|
+
*/
|
|
44
|
+
export declare function setListKind(kind: ListKind): Command;
|
|
45
|
+
/** 고른 문단(최상위)의 정렬. 섞여 있으면 null. */
|
|
46
|
+
export declare function paragraphAlign(state: EditorState): ParagraphAlign | null;
|
|
47
|
+
/** 문단 정렬 — 고른 최상위 문단에 건다(제목 · 목록 · 표는 건드리지 않는다). */
|
|
48
|
+
export declare function setParagraphAlign(align: ParagraphAlign): Command;
|
|
49
|
+
/** 쪽 나눔 넣기 — 커서가 있는 블록 뒤에. */
|
|
50
|
+
export declare const insertPageBreak: Command;
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import type { JSONContent } from "@tiptap/core";
|
|
2
|
+
import { type Ctx, type Dialect } from "../core/inline";
|
|
3
|
+
import type { Align, Doc } from "../core/types";
|
|
4
|
+
export declare function inlineToPM(s: string): JSONContent[];
|
|
5
|
+
export declare function toPM(doc: Doc): JSONContent;
|
|
6
|
+
export declare function inlineToMd(content: JSONContent[] | undefined, ctx?: Ctx, dialect?: Dialect): string;
|
|
7
|
+
/** 제목 노드 → 제목의 표준 꼴(서버 inline.title 과 같다). */
|
|
8
|
+
export declare function titleToMd(content: JSONContent[] | undefined, dialect?: Dialect): string;
|
|
9
|
+
/** 표 노드 → 문서의 표(머리글 · 본문 · 열 정렬). 합친 칸은 점유 격자를 만들고, 숨은 칸이 기준 칸과 같은 행이면 `<`, 아니면 `^`. */
|
|
10
|
+
export declare function tableData(t: JSONContent, dialect?: Dialect): {
|
|
11
|
+
head: string[][];
|
|
12
|
+
rows: string[][];
|
|
13
|
+
align: Align[];
|
|
14
|
+
};
|
|
15
|
+
/** 표 노드 → MD 줄들. */
|
|
16
|
+
export declare function tableMd(t: JSONContent, dialect?: Dialect): string[];
|
|
17
|
+
/**
|
|
18
|
+
* 편집기 문서의 자리 ↔ 문서(JSON)의 순번. pmToDoc 이 블록을 묶으면서 적는다.
|
|
19
|
+
* sections: 섹션마다 머리(sectionHead) 노드 순번(머리 없는 첫 섹션은 -1),
|
|
20
|
+
* blocks: 블록마다(문서 전체 순번) 시작 노드 · 목록 항목 · 표 노드.
|
|
21
|
+
*/
|
|
22
|
+
export type DocTrace = {
|
|
23
|
+
sections: number[];
|
|
24
|
+
blocks: {
|
|
25
|
+
node: number;
|
|
26
|
+
items: [number, number][];
|
|
27
|
+
table: number;
|
|
28
|
+
}[];
|
|
29
|
+
};
|
|
30
|
+
/**
|
|
31
|
+
* 편집기 문서 → 문서(JSON). 서버 parse_blocks 와 같은 규칙으로 블록을 묶는다:
|
|
32
|
+
* 제목이 새 블록을 연다. 본문은 아직 본문이 없을 때만 지금 블록에 붙고(목록 항목은 같은 목록에 이어 붙는다),
|
|
33
|
+
* 비고는 지금 블록에 붙는다. 빈 문단·빈 항목은 버린다.
|
|
34
|
+
*/
|
|
35
|
+
export declare function pmToDoc(doc: JSONContent, dialect?: Dialect, trace?: DocTrace): Doc;
|
|
36
|
+
/** 편집기 문서 → MD. */
|
|
37
|
+
export declare function fromPM(doc: JSONContent, dialect?: Dialect): string;
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
import { Extension } from "@tiptap/core";
|
|
2
|
+
import type { Node as PMNode } from "@tiptap/pm/model";
|
|
3
|
+
import { PluginKey, type EditorState, type Transaction } from "@tiptap/pm/state";
|
|
4
|
+
import { DecorationSet } from "@tiptap/pm/view";
|
|
5
|
+
/**
|
|
6
|
+
* 번호 항목마다 번호를 단다(data-num). MD 로 쓸 때와 같은 규칙 — 맞닿은 목록은 한 목록이고,
|
|
7
|
+
* 같은 단계의 번호 항목이 이어지는 동안 1(또는 첫 항목의 start)부터 센다. 더 얕은 항목이나 글머리 항목이 끼면 다시 센다.
|
|
8
|
+
*/
|
|
9
|
+
export declare function listNumbers(doc: PMNode): Map<number, number>;
|
|
10
|
+
export declare const ListNumbers: Extension<any, any>;
|
|
11
|
+
export type FindState = {
|
|
12
|
+
query: string;
|
|
13
|
+
caseSensitive: boolean;
|
|
14
|
+
matches: {
|
|
15
|
+
from: number;
|
|
16
|
+
to: number;
|
|
17
|
+
}[];
|
|
18
|
+
index: number;
|
|
19
|
+
};
|
|
20
|
+
export declare const findKey: PluginKey<FindState>;
|
|
21
|
+
type FindMeta = {
|
|
22
|
+
query?: string;
|
|
23
|
+
caseSensitive?: boolean;
|
|
24
|
+
index?: number;
|
|
25
|
+
};
|
|
26
|
+
export declare const FindReplace: Extension<any, any>;
|
|
27
|
+
/** 찾을 글 · 대소문자 구분을 바꾼다. */
|
|
28
|
+
export declare function setFind(state: EditorState, meta: FindMeta): Transaction;
|
|
29
|
+
/** 다음(1) · 이전(-1) 찾은 자리로 옮기고 골라 둔다. */
|
|
30
|
+
export declare function stepFind(state: EditorState, dir: 1 | -1): Transaction | null;
|
|
31
|
+
/** 지금 찾은 자리 하나를 바꾼다. */
|
|
32
|
+
export declare function replaceOne(state: EditorState, text: string): Transaction | null;
|
|
33
|
+
/** 찾은 자리를 모두 바꾼다(뒤에서부터 — 앞자리가 밀리지 않게). */
|
|
34
|
+
export declare function replaceAll(state: EditorState, text: string): Transaction | null;
|
|
35
|
+
/**
|
|
36
|
+
* 쪽 경계 — 쓰는 쪽이 계산해 넘긴다(MDitor 서버는 PDF 를 실제로 그려 본 쪽 배치로 만든다). 편집기는 쪽을 짐작하지 않는다.
|
|
37
|
+
* 자리는 문서(JSON)의 순번으로 적는다: sections 는 섹션 순번 → 그 머리에서 시작하는 쪽,
|
|
38
|
+
* blocks 는 블록 순번(문서 전체) → 블록 앞(before) · 목록 항목 앞(items, 항목 순번) · 표 본문 행 앞(rows, 본문 행 순번)에서 시작하는 쪽.
|
|
39
|
+
*/
|
|
40
|
+
export type PageMarks = {
|
|
41
|
+
total: number;
|
|
42
|
+
sections?: Record<number, number>;
|
|
43
|
+
blocks?: Record<number, {
|
|
44
|
+
before?: number | null;
|
|
45
|
+
items?: Record<number, number>;
|
|
46
|
+
rows?: Record<number, number>;
|
|
47
|
+
}>;
|
|
48
|
+
};
|
|
49
|
+
export type PagePlace = {
|
|
50
|
+
pos: number;
|
|
51
|
+
page: number;
|
|
52
|
+
kind: "block" | "item" | "row";
|
|
53
|
+
width: number;
|
|
54
|
+
};
|
|
55
|
+
/** 쪽 경계 → 편집기 문서의 자리(그 노드 바로 앞). */
|
|
56
|
+
export declare function pageMarkPlaces(doc: PMNode, marks: PageMarks): PagePlace[];
|
|
57
|
+
type MarksState = {
|
|
58
|
+
marks: PageMarks | null;
|
|
59
|
+
visible: boolean;
|
|
60
|
+
deco: DecorationSet;
|
|
61
|
+
};
|
|
62
|
+
type MarksMeta = {
|
|
63
|
+
marks?: PageMarks | null;
|
|
64
|
+
visible?: boolean;
|
|
65
|
+
};
|
|
66
|
+
export declare const pageMarksKey: PluginKey<MarksState>;
|
|
67
|
+
/**
|
|
68
|
+
* 쪽 경계 플러그인. setPageMarks 로 경계를 받으면 그 자리에 'n쪽' 줄을 그리고,
|
|
69
|
+
* 새 경계가 오기 전까지는 글을 고쳐도 경계가 글을 따라 움직인다.
|
|
70
|
+
*/
|
|
71
|
+
export declare const PageMarksExtension: Extension<{
|
|
72
|
+
label: (n: number) => string;
|
|
73
|
+
}, any>;
|
|
74
|
+
/** 쪽 경계를 바꾸거나 켜고 끈다. */
|
|
75
|
+
export declare function setPageMarksMeta(state: EditorState, meta: MarksMeta): Transaction;
|
|
76
|
+
/**
|
|
77
|
+
* 칸을 끌어 고른 직후의 고른 칸을 지킨다.
|
|
78
|
+
* 끌기를 마치면(mouseup) 브라우저가 가끔 놓은 자리의 커서로 selectionchange 를 한 번 더 보내고, 편집기는 그것을
|
|
79
|
+
* 마우스로 놓은 커서("pointer")로 읽어 고른 칸이 풀렸다(빨리 '칸 합치기' 를 누르면 듣지 않았다).
|
|
80
|
+
* 끌기가 끝난 뒤 짧은 동안, 새로 누르지 않았는데 들어온 그런 커서는 받지 않는다.
|
|
81
|
+
*/
|
|
82
|
+
export declare const CellSelectionGuard: Extension<any, any>;
|
|
83
|
+
export {};
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { type AnyExtension } from "@tiptap/core";
|
|
2
|
+
import { type Messages } from "../ui/messages";
|
|
3
|
+
export declare const MAX_LEVEL = 3;
|
|
4
|
+
export type MdItemOptions = {
|
|
5
|
+
messages: Messages;
|
|
6
|
+
};
|
|
7
|
+
export type ImageResolver = (src: string) => string | undefined;
|
|
8
|
+
/** 붙여 넣은 글자 색을 우리 색 이름으로(빨강·파랑·회색). 그 밖의 색은 버린다. */
|
|
9
|
+
export declare function colorName(css: string | null | undefined): string | null;
|
|
10
|
+
export type RichOptions = {
|
|
11
|
+
/** 그림 이름 → 화면에 그릴 주소. 없으면 그림 자리만 보인다. */
|
|
12
|
+
resolveImage?: ImageResolver;
|
|
13
|
+
messages?: Messages;
|
|
14
|
+
};
|
|
15
|
+
export declare function richExtensions(options?: RichOptions): AnyExtension[];
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { type CSSProperties, type ReactNode } from "react";
|
|
2
|
+
import { type MarkdownEditor, type MarkdownEditorOptions } from "./ui/editor";
|
|
3
|
+
export type MarkdownEditorViewProps = Omit<MarkdownEditorOptions, "element" | "onChange" | "markdown"> & {
|
|
4
|
+
/** 처음 MD(바꿔도 다시 열지 않는다). */
|
|
5
|
+
defaultValue?: string;
|
|
6
|
+
/** 바깥에서 정하는 MD — 편집기의 MD 와 다르면 그것으로 다시 연다. */
|
|
7
|
+
value?: string;
|
|
8
|
+
onChange?: (markdown: string) => void;
|
|
9
|
+
/** 편집기를 만든 뒤 한 번. */
|
|
10
|
+
onReady?: (editor: MarkdownEditor) => void;
|
|
11
|
+
className?: string;
|
|
12
|
+
style?: CSSProperties;
|
|
13
|
+
/** 도구 막대 앞 · 뒤에 넣을 쓰는 쪽의 단추. */
|
|
14
|
+
toolbarStart?: ReactNode;
|
|
15
|
+
toolbarEnd?: ReactNode;
|
|
16
|
+
};
|
|
17
|
+
/** 편집기는 처음 한 번 만든다. 바뀐 옵션은 value · editable · dialect · preview 만 따라간다(나머지는 key 를 바꿔 다시 만든다). */
|
|
18
|
+
export declare const MarkdownEditorView: import("react").ForwardRefExoticComponent<Omit<MarkdownEditorOptions, "element" | "onChange" | "markdown"> & {
|
|
19
|
+
/** 처음 MD(바꿔도 다시 열지 않는다). */
|
|
20
|
+
defaultValue?: string;
|
|
21
|
+
/** 바깥에서 정하는 MD — 편집기의 MD 와 다르면 그것으로 다시 연다. */
|
|
22
|
+
value?: string;
|
|
23
|
+
onChange?: (markdown: string) => void;
|
|
24
|
+
/** 편집기를 만든 뒤 한 번. */
|
|
25
|
+
onReady?: (editor: MarkdownEditor) => void;
|
|
26
|
+
className?: string;
|
|
27
|
+
style?: CSSProperties;
|
|
28
|
+
/** 도구 막대 앞 · 뒤에 넣을 쓰는 쪽의 단추. */
|
|
29
|
+
toolbarStart?: ReactNode;
|
|
30
|
+
toolbarEnd?: ReactNode;
|
|
31
|
+
} & import("react").RefAttributes<MarkdownEditor | null>>;
|
|
32
|
+
export type { MarkdownEditor, MarkdownEditorOptions };
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
type Child = Node | string | null | undefined | false;
|
|
2
|
+
type Props = {
|
|
3
|
+
className?: string;
|
|
4
|
+
html?: string;
|
|
5
|
+
text?: string;
|
|
6
|
+
title?: string;
|
|
7
|
+
attrs?: Record<string, string | number | boolean | null | undefined>;
|
|
8
|
+
style?: Partial<CSSStyleDeclaration> | Record<string, string>;
|
|
9
|
+
on?: Partial<{
|
|
10
|
+
[K in keyof HTMLElementEventMap]: (e: HTMLElementEventMap[K]) => void;
|
|
11
|
+
}>;
|
|
12
|
+
};
|
|
13
|
+
export declare function h<K extends keyof HTMLElementTagNameMap>(tag: K, props?: Props, ...children: Child[]): HTMLElementTagNameMap[K];
|
|
14
|
+
/** 열린 팝업 — 한 편집기 안에서 하나만 연다. */
|
|
15
|
+
export type Popover = {
|
|
16
|
+
wrap: HTMLElement;
|
|
17
|
+
button: HTMLButtonElement;
|
|
18
|
+
open(): void;
|
|
19
|
+
close(): void;
|
|
20
|
+
isOpen(): boolean;
|
|
21
|
+
};
|
|
22
|
+
export type PopoverHost = {
|
|
23
|
+
current: Popover | null;
|
|
24
|
+
};
|
|
25
|
+
/**
|
|
26
|
+
* 단추 + 팝업. 단추를 누르면 build() 로 내용을 새로 만들어 단추 아래에 연다.
|
|
27
|
+
* 바깥을 누르거나 Esc 를 누르면 닫는다.
|
|
28
|
+
*/
|
|
29
|
+
export declare function popover(host: PopoverHost, button: HTMLButtonElement, build: (close: () => void) => HTMLElement, align?: "left" | "right"): Popover;
|
|
30
|
+
export {};
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
import { Editor, type AnyExtension } from "@tiptap/core";
|
|
2
|
+
import { type Dialect } from "../core/inline";
|
|
3
|
+
import { type Doc } from "../core/types";
|
|
4
|
+
import { type PageMarks } from "../pm/plugins";
|
|
5
|
+
import { type Locale, type Messages } from "./messages";
|
|
6
|
+
export type EditorMode = "wysiwyg" | "source";
|
|
7
|
+
/** 도구 막대 항목 — 이름(아래 DEFAULT_TOOLBAR 참고), "|"(구분선), 또는 직접 그리는 항목. */
|
|
8
|
+
export type ToolbarItem = string | {
|
|
9
|
+
name: string;
|
|
10
|
+
render: (editor: MarkdownEditor) => HTMLElement;
|
|
11
|
+
};
|
|
12
|
+
export declare const DEFAULT_TOOLBAR: ToolbarItem[];
|
|
13
|
+
export type ImageOptions = {
|
|
14
|
+
/** 문서에 적힌 그림 이름 → 화면에 그릴 주소. 없으면 적힌 그대로 쓴다. */
|
|
15
|
+
resolve?: (src: string) => string | undefined;
|
|
16
|
+
/** 파일을 올리고 문서에 적을 주소를 돌려준다. 없으면 data: 주소로 넣는다. */
|
|
17
|
+
upload?: (file: File) => Promise<string>;
|
|
18
|
+
/** 그림 파일(붙여넣기 · 끌어다 놓기 · 단추)을 쓰는 쪽이 직접 다룬다 — 이것이 있으면 upload 는 쓰지 않는다. */
|
|
19
|
+
onFiles?: (files: File[]) => void;
|
|
20
|
+
/** 이미지 단추를 누르면 부른다(쓰는 쪽의 파일 고르기). 없으면 주소 · 파일 팝업을 연다. */
|
|
21
|
+
pick?: () => void;
|
|
22
|
+
};
|
|
23
|
+
export type MarkdownEditorOptions = {
|
|
24
|
+
/** 편집기를 넣을 요소. */
|
|
25
|
+
element: HTMLElement;
|
|
26
|
+
/** 처음 열 MD. */
|
|
27
|
+
markdown?: string;
|
|
28
|
+
/** 처음 열 문서(JSON) — markdown 대신. */
|
|
29
|
+
doc?: Doc;
|
|
30
|
+
/** 화면 글 언어(기본 ko). */
|
|
31
|
+
locale?: Locale;
|
|
32
|
+
/** 화면 글 바꾸기. */
|
|
33
|
+
messages?: Partial<Messages>;
|
|
34
|
+
/** 서식 태그를 쓸 언어({빨강} · {red}). 주지 않으면 MD 에 처음 나오는 태그, 없으면 locale. */
|
|
35
|
+
dialect?: Dialect;
|
|
36
|
+
/** 도구 막대 항목. false 면 도구 막대를 그리지 않는다. */
|
|
37
|
+
toolbar?: ToolbarItem[] | false;
|
|
38
|
+
/** 미리보기 창을 처음부터 연다(기본 false). 도구 막대의 '미리보기' 단추로 켜고 끈다. */
|
|
39
|
+
preview?: boolean;
|
|
40
|
+
/**
|
|
41
|
+
* 자동 쪽 나눔(쪽 경계)을 처음부터 보인다(기본 false). 경계 자리는 쓰는 쪽이 setPageMarks 로 넘긴다 —
|
|
42
|
+
* 편집기는 쪽을 짐작하지 않는다. 도구 막대 항목 "pageMarks" 로 켜고 끈다.
|
|
43
|
+
*/
|
|
44
|
+
pageMarks?: boolean;
|
|
45
|
+
/** 처음 모드 — 문서(wysiwyg) 또는 MD 원문(source). */
|
|
46
|
+
mode?: EditorMode;
|
|
47
|
+
/** 글자 수 줄(기본 true). */
|
|
48
|
+
statusbar?: boolean;
|
|
49
|
+
/** 고칠 수 있는가(기본 true). */
|
|
50
|
+
editable?: boolean;
|
|
51
|
+
/** 빈 문서에 보일 안내 글. */
|
|
52
|
+
placeholder?: string;
|
|
53
|
+
/** 문서 영역에 붙일 class(기본 "mde-doc" — 라이브러리의 문서 모양). */
|
|
54
|
+
contentClass?: string;
|
|
55
|
+
image?: ImageOptions;
|
|
56
|
+
/** 글이 바뀔 때마다(MD). */
|
|
57
|
+
onChange?: (markdown: string, editor: MarkdownEditor) => void;
|
|
58
|
+
/**
|
|
59
|
+
* 문서(MD) 길이 한도. 붙이면 이 길이를 넘는 붙여넣기는 받지 않는다(한 번에 큰 글을 붙여 서버 · 브라우저가 무거워지지 않게).
|
|
60
|
+
* 손으로 치는 글은 막지 않는다.
|
|
61
|
+
*/
|
|
62
|
+
maxLength?: number;
|
|
63
|
+
/** 한 번에 붙여 넣을 수 있는 글자 수. 넘는 붙여넣기는 받지 않는다(나눠서 붙이게). */
|
|
64
|
+
maxPaste?: number;
|
|
65
|
+
/** maxPaste · maxLength 때문에 붙여넣기를 막았을 때(kind: 어느 한도인지). 주지 않으면 편집기 위 줄에 알린다. */
|
|
66
|
+
onTooLong?: (info: {
|
|
67
|
+
kind: "paste" | "document";
|
|
68
|
+
length: number;
|
|
69
|
+
max: number;
|
|
70
|
+
}) => void;
|
|
71
|
+
/** 더 붙일 TipTap 확장. */
|
|
72
|
+
extensions?: AnyExtension[];
|
|
73
|
+
};
|
|
74
|
+
type Events = {
|
|
75
|
+
change: (md: string) => void;
|
|
76
|
+
mode: (mode: EditorMode) => void;
|
|
77
|
+
preview: (on: boolean) => void;
|
|
78
|
+
fullscreen: (on: boolean) => void;
|
|
79
|
+
pagemarks: (on: boolean) => void;
|
|
80
|
+
};
|
|
81
|
+
export interface MarkdownEditor {
|
|
82
|
+
/** 속의 TipTap 편집기. */
|
|
83
|
+
readonly tiptap: Editor;
|
|
84
|
+
readonly element: HTMLElement;
|
|
85
|
+
readonly messages: Messages;
|
|
86
|
+
getMarkdown(): string;
|
|
87
|
+
/** MD 로 바꾼다. 읽을 수 없는 MD 면 MdError 를 던진다. */
|
|
88
|
+
setMarkdown(markdown: string): void;
|
|
89
|
+
getDoc(): Doc;
|
|
90
|
+
setDoc(doc: Doc): void;
|
|
91
|
+
/** 미리보기와 같은 HTML. */
|
|
92
|
+
getHTML(): string;
|
|
93
|
+
insertImage(src: string, caption?: string): void;
|
|
94
|
+
/** 문서 안의 그림 주소를 바꾼다(null 이면 그 그림을 뺀다). 되돌리기 기록에 남기지 않는다. */
|
|
95
|
+
replaceImage(from: string, to: string | null): void;
|
|
96
|
+
/** 그림 주소 풀이(resolve)가 바뀌었을 때 그림을 다시 그린다. */
|
|
97
|
+
refreshImages(): void;
|
|
98
|
+
getMode(): EditorMode;
|
|
99
|
+
/** 모드를 바꾼다. MD 원문 → 문서가 실패하면(읽을 수 없는 MD) false. */
|
|
100
|
+
setMode(mode: EditorMode): boolean;
|
|
101
|
+
isPreview(): boolean;
|
|
102
|
+
setPreview(on: boolean): void;
|
|
103
|
+
/** 쪽 경계 자리를 넘긴다(null 이면 지운다). 새 경계가 오기 전까지는 글을 고쳐도 경계가 글을 따라 움직인다. */
|
|
104
|
+
setPageMarks(marks: PageMarks | null): void;
|
|
105
|
+
isPageMarksVisible(): boolean;
|
|
106
|
+
setPageMarksVisible(on: boolean): void;
|
|
107
|
+
isFullscreen(): boolean;
|
|
108
|
+
setFullscreen(on: boolean): void;
|
|
109
|
+
setEditable(on: boolean): void;
|
|
110
|
+
setDialect(dialect: Dialect): void;
|
|
111
|
+
/** 도구 막대의 앞 · 뒤 빈칸 — 쓰는 쪽의 단추를 넣는다. */
|
|
112
|
+
slot(name: "start" | "end"): HTMLElement;
|
|
113
|
+
focus(): void;
|
|
114
|
+
on<K extends keyof Events>(event: K, fn: Events[K]): () => void;
|
|
115
|
+
destroy(): void;
|
|
116
|
+
}
|
|
117
|
+
export declare function createEditor(options: MarkdownEditorOptions): MarkdownEditor;
|
|
118
|
+
export {};
|