@iquji-community/web-editor 0.0.0-stage → 0.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +29 -2
- package/README.zh-CN.md +30 -0
- package/dist/colors.d.ts +9 -0
- package/dist/editor-color-control.d.ts +13 -0
- package/dist/editor-format-icon.d.ts +5 -0
- package/dist/editor-layout.d.ts +8 -0
- package/dist/editor-viewport.d.ts +12 -0
- package/dist/index.d.ts +12 -0
- package/dist/index.js +1053 -0
- package/dist/markdown.d.ts +2 -0
- package/dist/presets.d.ts +12 -0
- package/dist/rich-text-colors.d.ts +20 -0
- package/dist/rich-text-content.d.ts +2 -0
- package/dist/rich-text-editor.d.ts +23 -0
- package/dist/rich-text-preset.d.ts +4 -0
- package/dist/rich-text-toolbar.d.ts +30 -0
- package/dist/shell.d.ts +2 -0
- package/dist/styles.css +229 -0
- package/dist/text-editor.d.ts +28 -0
- package/dist/text.d.ts +8 -0
- package/dist/text.js +451 -0
- package/package.json +76 -4
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { type Diagnostic } from "@codemirror/lint";
|
|
2
|
+
import type { Extension } from "@codemirror/state";
|
|
3
|
+
export type IqujiTextPreset = "markdown" | "json" | "yaml" | "toml" | "shell" | "text";
|
|
4
|
+
export type IqujiEditorPreset = "richText" | IqujiTextPreset;
|
|
5
|
+
export declare const IQUJI_EDITOR_PRESETS: readonly ["richText", "markdown", "json", "yaml", "toml", "shell", "text"];
|
|
6
|
+
/** TOML 只提供高亮与语法诊断,不提供格式化:自动重排会丢失注释与键顺序。 */
|
|
7
|
+
export declare const IQUJI_FORMATTABLE_PRESETS: readonly ["json", "yaml"];
|
|
8
|
+
export declare function isFormattablePreset(preset: IqujiTextPreset): boolean;
|
|
9
|
+
export declare function textPresetExtensions(preset: IqujiTextPreset): Extension[];
|
|
10
|
+
export declare function yamlDiagnostics(value: string): Diagnostic[];
|
|
11
|
+
export declare function tomlDiagnostics(value: string): Diagnostic[];
|
|
12
|
+
export declare function formatEditorText(preset: IqujiTextPreset, value: string): string;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { Mark } from "@tiptap/core";
|
|
2
|
+
declare module "@tiptap/core" {
|
|
3
|
+
interface Commands<ReturnType> {
|
|
4
|
+
highlight: {
|
|
5
|
+
setHighlight: (attrs?: {
|
|
6
|
+
color?: string;
|
|
7
|
+
}) => ReturnType;
|
|
8
|
+
toggleHighlight: (attrs?: {
|
|
9
|
+
color?: string;
|
|
10
|
+
}) => ReturnType;
|
|
11
|
+
unsetHighlight: () => ReturnType;
|
|
12
|
+
};
|
|
13
|
+
textColor: {
|
|
14
|
+
setTextColor: (color: string) => ReturnType;
|
|
15
|
+
unsetTextColor: () => ReturnType;
|
|
16
|
+
};
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
export declare const EditorHighlight: Mark<any, any>;
|
|
20
|
+
export declare const EditorTextColor: Mark<any, any>;
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import type { Editor, Extensions, JSONContent } from "@tiptap/core";
|
|
2
|
+
import { type UseEditorOptions } from "@tiptap/react";
|
|
3
|
+
import { type ReactNode } from "react";
|
|
4
|
+
export interface IqujiRichTextAssembly {
|
|
5
|
+
extensions: Extensions;
|
|
6
|
+
serialize?(content: JSONContent): JSONContent;
|
|
7
|
+
}
|
|
8
|
+
export type IqujiRichTextOptions = UseEditorOptions & {
|
|
9
|
+
assembly: IqujiRichTextAssembly;
|
|
10
|
+
};
|
|
11
|
+
/** 使用给定扩展创建富文本编辑器实例。 */
|
|
12
|
+
export declare function useIqujiRichTextEditor({ assembly, ...options }: IqujiRichTextOptions): Editor | null;
|
|
13
|
+
export interface IqujiRichTextEditorProps {
|
|
14
|
+
assembly: IqujiRichTextAssembly;
|
|
15
|
+
value: JSONContent;
|
|
16
|
+
onChange(value: JSONContent): void;
|
|
17
|
+
readOnly?: boolean;
|
|
18
|
+
ariaLabel: string;
|
|
19
|
+
toolbar?: ReactNode | ((editor: Editor | null) => ReactNode);
|
|
20
|
+
footer?: ReactNode;
|
|
21
|
+
onReady?(editor: Editor | null): void;
|
|
22
|
+
}
|
|
23
|
+
export declare function IqujiRichTextEditor(props: IqujiRichTextEditorProps): import("react/jsx-runtime").JSX.Element;
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import type { Editor } from "@tiptap/core";
|
|
2
|
+
import type { ReactNode } from "react";
|
|
3
|
+
export declare const EDITOR_ALIGNMENT_TOOLS: {
|
|
4
|
+
readonly left: "alignLeft";
|
|
5
|
+
readonly center: "alignCenter";
|
|
6
|
+
readonly right: "alignRight";
|
|
7
|
+
readonly justify: "alignJustify";
|
|
8
|
+
};
|
|
9
|
+
export type EditorToolbarSlots = {
|
|
10
|
+
marks?: ReactNode;
|
|
11
|
+
history?: ReactNode;
|
|
12
|
+
paragraph?: ReactNode;
|
|
13
|
+
spacing?: ReactNode;
|
|
14
|
+
insert?: ReactNode;
|
|
15
|
+
};
|
|
16
|
+
export interface IqujiRichTextToolbarProps {
|
|
17
|
+
editor: Editor | null;
|
|
18
|
+
tools: readonly string[];
|
|
19
|
+
slots?: EditorToolbarSlots;
|
|
20
|
+
canClear?: boolean;
|
|
21
|
+
onClear?: () => void;
|
|
22
|
+
insertAvailable?: boolean;
|
|
23
|
+
className?: string;
|
|
24
|
+
disabled?: boolean;
|
|
25
|
+
t: (key: string) => string;
|
|
26
|
+
zoom: number;
|
|
27
|
+
onZoom: (zoom: number) => void;
|
|
28
|
+
actions?: ReactNode;
|
|
29
|
+
}
|
|
30
|
+
export declare function IqujiRichTextToolbar({ editor, disabled, t, zoom, onZoom, actions, tools, slots, canClear, onClear, insertAvailable, className, }: IqujiRichTextToolbarProps): import("react/jsx-runtime").JSX.Element | null;
|
package/dist/shell.d.ts
ADDED
package/dist/styles.css
ADDED
|
@@ -0,0 +1,229 @@
|
|
|
1
|
+
/* src/rich-text-toolbar.css */
|
|
2
|
+
.iquji-editor-format-toolbar {
|
|
3
|
+
display: flex;
|
|
4
|
+
gap: var(--iquji-space-1);
|
|
5
|
+
font-size: var(--font-size-text-body-sm);
|
|
6
|
+
padding: var(--iquji-space-2);
|
|
7
|
+
background: var(--iquji-color-surface);
|
|
8
|
+
border-bottom: 1px solid var(--iquji-color-border);
|
|
9
|
+
flex-direction: column;
|
|
10
|
+
flex: none;
|
|
11
|
+
min-width: 0;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
.iquji-editor-tool-row, .iquji-editor-tool-group {
|
|
15
|
+
border: 0;
|
|
16
|
+
min-inline-size: 0;
|
|
17
|
+
margin: 0;
|
|
18
|
+
padding: 0;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
.iquji-editor-tool-row {
|
|
22
|
+
display: flex;
|
|
23
|
+
justify-content: center;
|
|
24
|
+
align-items: center;
|
|
25
|
+
gap: var(--iquji-space-2) 0;
|
|
26
|
+
flex-wrap: wrap;
|
|
27
|
+
min-width: 0;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
.iquji-editor-tool-row + .iquji-editor-tool-row {
|
|
31
|
+
border-top: 1px solid var(--iquji-color-border);
|
|
32
|
+
padding-top: var(--iquji-space-1);
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
.iquji-editor-tool-group {
|
|
36
|
+
display: flex;
|
|
37
|
+
align-items: center;
|
|
38
|
+
gap: var(--iquji-space-1);
|
|
39
|
+
white-space: nowrap;
|
|
40
|
+
padding-inline: var(--iquji-space-2);
|
|
41
|
+
flex: none;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
.iquji-editor-tool-group + .iquji-editor-tool-group {
|
|
45
|
+
border-inline-start: 1px solid var(--iquji-color-border-strong);
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
.iquji-editor-format-toolbar button svg {
|
|
49
|
+
stroke-width: 1.8;
|
|
50
|
+
width: 15px;
|
|
51
|
+
height: 15px;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
.iquji-editor-format-toolbar .iquji-icon-button--compact {
|
|
55
|
+
width: 28px;
|
|
56
|
+
height: 28px;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
.iquji-editor-tool-group > span {
|
|
60
|
+
display: inline-flex;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
.iquji-editor-format-toolbar button[aria-pressed="true"]:not(:disabled):not([aria-disabled="true"]) {
|
|
64
|
+
background: var(--iquji-color-surface-muted);
|
|
65
|
+
color: var(--iquji-color-accent-strong);
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
.iquji-editor-zoom {
|
|
69
|
+
padding-inline: var(--iquji-space-1);
|
|
70
|
+
font-variant-numeric: tabular-nums;
|
|
71
|
+
min-width: 5ch;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
.iquji-editor-view-tools {
|
|
75
|
+
gap: 0;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
.iquji-editor-format-toolbar button, .iquji-editor-format-toolbar [role="combobox"] {
|
|
79
|
+
font-size: var(--font-size-text-body-sm);
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
/* src/styles.css */
|
|
83
|
+
.iquji-editor {
|
|
84
|
+
display: flex;
|
|
85
|
+
background: var(--iquji-color-surface, #fff);
|
|
86
|
+
color: var(--iquji-color-text-primary, #171717);
|
|
87
|
+
flex-direction: column;
|
|
88
|
+
min-width: 0;
|
|
89
|
+
min-height: 0;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
.iquji-editor-toolbar {
|
|
93
|
+
display: flex;
|
|
94
|
+
border-bottom: 1px solid var(--iquji-color-border, #e5e5e5);
|
|
95
|
+
flex: none;
|
|
96
|
+
align-items: center;
|
|
97
|
+
gap: 6px;
|
|
98
|
+
padding: 6px 12px;
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
.iquji-editor-body {
|
|
102
|
+
overflow: auto;
|
|
103
|
+
flex: 1;
|
|
104
|
+
min-width: 0;
|
|
105
|
+
min-height: 0;
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
.iquji-editor-footer {
|
|
109
|
+
position: sticky;
|
|
110
|
+
background: inherit;
|
|
111
|
+
border-top: none;
|
|
112
|
+
flex: none;
|
|
113
|
+
bottom: 0;
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
.iquji-text-editor .cm-editor {
|
|
117
|
+
background: none;
|
|
118
|
+
min-height: 360px;
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
.iquji-text-editor .cm-scroller {
|
|
122
|
+
font: 13px / 1.7 ui-monospace, SFMono-Regular, Consolas, monospace;
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
.iquji-text-editor .cm-gutters {
|
|
126
|
+
background: var(--iquji-color-surface-subtle, #f5f5f5);
|
|
127
|
+
color: var(--iquji-color-text-secondary, #666);
|
|
128
|
+
border-right: none;
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
.iquji-text-editor .cm-content {
|
|
132
|
+
padding: 16px 0;
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
.iquji-text-editor[hidden] {
|
|
136
|
+
display: none;
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
.iquji-editor-preview, .iquji-rich-editor {
|
|
140
|
+
overflow-wrap: anywhere;
|
|
141
|
+
min-height: 360px;
|
|
142
|
+
padding: 24px;
|
|
143
|
+
line-height: 1.8;
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
.iquji-editor-preview pre {
|
|
147
|
+
overflow: auto;
|
|
148
|
+
background: var(--iquji-color-surface-subtle, #f5f5f5);
|
|
149
|
+
border-radius: 8px;
|
|
150
|
+
padding: 16px;
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
.iquji-editor-preview table {
|
|
154
|
+
border-collapse: collapse;
|
|
155
|
+
width: 100%;
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
.iquji-editor-preview td, .iquji-editor-preview th {
|
|
159
|
+
border: 1px solid var(--iquji-color-border, #ddd);
|
|
160
|
+
padding: 6px 10px;
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
.iquji-editor-error {
|
|
164
|
+
color: var(--iquji-color-text-danger, #b91c1c);
|
|
165
|
+
padding: 8px 16px;
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
.ProseMirror mark {
|
|
169
|
+
color: inherit;
|
|
170
|
+
box-decoration-break: clone;
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
.ProseMirror mark:not([data-editor-highlight]), [data-editor-highlight="yellow"] {
|
|
174
|
+
background-color: var(--iquji-color-warning-fill, #fef08a);
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
[data-editor-highlight="green"] {
|
|
178
|
+
background-color: var(--iquji-color-positive-fill, #bbf7d0);
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
[data-editor-highlight="blue"] {
|
|
182
|
+
background-color: var(--iquji-color-info-fill, #bfdbfe);
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
[data-editor-highlight="purple"] {
|
|
186
|
+
background-color: #ddd6fe;
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
[data-editor-highlight="pink"] {
|
|
190
|
+
background-color: var(--iquji-color-accent-soft, #fbcfe8);
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
.iquji-editor-workspace {
|
|
194
|
+
display: flex;
|
|
195
|
+
flex-direction: column;
|
|
196
|
+
height: 100%;
|
|
197
|
+
min-height: 0;
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
.iquji-editor-viewport {
|
|
201
|
+
position: relative;
|
|
202
|
+
display: flex;
|
|
203
|
+
flex-direction: column;
|
|
204
|
+
flex: 1;
|
|
205
|
+
min-height: 0;
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
.iquji-editor-scroll {
|
|
209
|
+
overflow: auto;
|
|
210
|
+
flex: 1;
|
|
211
|
+
min-height: 0;
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
.iquji-editor-page {
|
|
215
|
+
max-width: 960px;
|
|
216
|
+
margin: 0 auto;
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
.iquji-editor-footer {
|
|
220
|
+
flex: none;
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
.iquji-editor-modes {
|
|
224
|
+
display: flex;
|
|
225
|
+
border: 0;
|
|
226
|
+
gap: 4px;
|
|
227
|
+
margin: 0;
|
|
228
|
+
padding: 0;
|
|
229
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { EditorView } from "@codemirror/view";
|
|
2
|
+
import { type ReactNode } from "react";
|
|
3
|
+
import { type IqujiTextPreset } from "./presets.js";
|
|
4
|
+
export type IqujiTextSelection = {
|
|
5
|
+
from: number;
|
|
6
|
+
to: number;
|
|
7
|
+
text: string;
|
|
8
|
+
document: string;
|
|
9
|
+
};
|
|
10
|
+
export interface IqujiTextEditorProps {
|
|
11
|
+
preset: IqujiTextPreset;
|
|
12
|
+
value: string;
|
|
13
|
+
onChange(value: string): void;
|
|
14
|
+
ariaLabel: string;
|
|
15
|
+
labels: {
|
|
16
|
+
edit: string;
|
|
17
|
+
preview: string;
|
|
18
|
+
format: string;
|
|
19
|
+
invalid: string;
|
|
20
|
+
};
|
|
21
|
+
documentKey?: string | undefined;
|
|
22
|
+
readOnly?: boolean | undefined;
|
|
23
|
+
footer?: ReactNode;
|
|
24
|
+
className?: string | undefined;
|
|
25
|
+
onSelectionChange?(selection: IqujiTextSelection): void;
|
|
26
|
+
onReady?(view: EditorView | null): void;
|
|
27
|
+
}
|
|
28
|
+
export declare function IqujiTextEditor(props: IqujiTextEditorProps): import("react/jsx-runtime").JSX.Element;
|