@astryx-vue/richtext 0.0.0-stage → 0.5.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 +62 -2
- package/css.d.ts +3 -0
- package/dist/index.d.ts +394 -0
- package/dist/index.js +2288 -0
- package/dist/markdown.d.ts +2 -0
- package/dist/markdown.js +2 -0
- package/dist/markdownSerializers-BLgqlNe3.d.ts +88 -0
- package/dist/markdownSerializers-ByYsTuIA.js +2492 -0
- package/package.json +140 -3
- package/richtext.css +5 -0
- package/styles/richtext-document.css +269 -0
- package/styles/richtext-editor.css +117 -0
- package/styles/richtext-toolbar.css +54 -0
- package/styles/richtext-view.css +23 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 astryx-vue contributors
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,63 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @astryx-vue/richtext
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Astryx 富文本(`@astryxdesign/richtext`)的 Vue 3 移植版:基于 Lexical 的所见即所得编辑器、只读视图、工具栏,以及原样往返的 Markdown 导入导出。本项目是非官方移植,与 Meta 无关。
|
|
4
|
+
|
|
5
|
+
## 安装
|
|
6
|
+
|
|
7
|
+
```sh
|
|
8
|
+
pnpm add @astryx-vue/richtext
|
|
9
|
+
pnpm add lexical @lexical/code @lexical/extension @lexical/headless @lexical/history @lexical/html @lexical/link @lexical/list @lexical/markdown @lexical/rich-text @lexical/selection @lexical/table @lexical/utils
|
|
10
|
+
```
|
|
11
|
+
|
|
12
|
+
`vue` 和 `@astryx-vue/core` 是同级的必需依赖。Lexical 那一组是可选 peer 依赖,版本和上游锁在同一个次版本(现在是 `^0.52.0`),只有用到编辑器的部分才需要。
|
|
13
|
+
|
|
14
|
+
样式分文件,可以整份引入,也可以按需:
|
|
15
|
+
|
|
16
|
+
```ts
|
|
17
|
+
import '@astryx-vue/richtext/richtext.css'
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
> `@lexical/headless` 自己带 `happy-dom` 依赖,所以为了服务端转换装它也会装 `happy-dom`。这是 Lexical 的选择,上游也一样。
|
|
21
|
+
|
|
22
|
+
## 用法
|
|
23
|
+
|
|
24
|
+
```vue
|
|
25
|
+
<script setup lang="ts">
|
|
26
|
+
import { RichTextEditor, RichTextEditorToolbar } from '@astryx-vue/richtext'
|
|
27
|
+
</script>
|
|
28
|
+
|
|
29
|
+
<template>
|
|
30
|
+
<RichTextEditor label="发版说明" @change="(state) => save(JSON.stringify(state.toJSON()))">
|
|
31
|
+
<template #toolbar>
|
|
32
|
+
<RichTextEditorToolbar />
|
|
33
|
+
</template>
|
|
34
|
+
</RichTextEditor>
|
|
35
|
+
</template>
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
`RichTextEditor` 是非受控的:`defaultValue` 只在创建时读一次,之后内容的变化通过 `@change` 交出来。通过模板引用可以拿到 `focus()`、`clear()`、`getEditorState()`、`getMarkdown()`、`getHTML()`、`getEditor()`。
|
|
39
|
+
|
|
40
|
+
只读有两套:`<RichTextEditor is-read-only>` 是带标签的表单字段;`<RichTextView :value="json">` 是纯文档内容,没有表单控件的角色,适合展示读进来的持久化内容。
|
|
41
|
+
|
|
42
|
+
## Markdown 往返
|
|
43
|
+
|
|
44
|
+
`@astryx-vue/richtext/markdown` 不引入 Vue 组件、不碰 DOM,在 Node、Worker 或者服务端渲染里都能用。
|
|
45
|
+
|
|
46
|
+
```ts
|
|
47
|
+
import { editorStateJSONToMarkdown, markdownToEditorStateJSON } from '@astryx-vue/richtext/markdown'
|
|
48
|
+
|
|
49
|
+
const state = markdownToEditorStateJSON('# 标题\n\n一些 *强调*。\n')
|
|
50
|
+
const markdown = editorStateJSONToMarkdown(state)
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
导入时保留原文:没改过的块原样导出,列表标记、缩进、转义、`&` 这类字符引用、围栏的反引号个数都还在;只有改动过的块按规范写法重写。读文档用的是 core `Markdown` 组件同一套解析器,所以两边对同一篇文档的理解一致。
|
|
54
|
+
|
|
55
|
+
## 其它导出
|
|
56
|
+
|
|
57
|
+
- `createRichTextExtension`:采用一个用 `createMarkdownPlugin` 做的 Markdown 插件,让它的节点在编辑器和只读视图里按 core `Markdown` 的方式渲染。
|
|
58
|
+
- `sanitizeUrl`、`validateUrl`:链接地址的白名单检查,只放行 http、https、mailto、tel。
|
|
59
|
+
- `RichTextEditorAutoLinkPlugin`:把输入或粘贴的网址、邮箱自动变成链接,可选。
|
|
60
|
+
|
|
61
|
+
## 许可证
|
|
62
|
+
|
|
63
|
+
MIT
|
package/css.d.ts
ADDED
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,394 @@
|
|
|
1
|
+
import { a as RichTextMarkdownExtension, i as RichTextExtensionError, n as editorStateJSONToMarkdown, o as createRichTextExtension, r as markdownToEditorStateJSON, t as MarkdownSerializerOptions } from "./markdownSerializers-BLgqlNe3.js";
|
|
2
|
+
import { InjectionKey, PropType } from "vue";
|
|
3
|
+
import { LinkMatcher } from "@lexical/link";
|
|
4
|
+
import { Transformer } from "@lexical/markdown";
|
|
5
|
+
import { AnyLexicalExtensionArgument, EditorState, EditorThemeClasses, Klass, LexicalEditor, LexicalNode } from "lexical";
|
|
6
|
+
import "@astryx-vue/core";
|
|
7
|
+
import { MarkdownPluginEntry } from "@astryx-vue/core/Markdown/plugins";
|
|
8
|
+
//#region src/editor/context.d.ts
|
|
9
|
+
/** 编辑器根组件把 Lexical 编辑器挂在这个键上,工具栏和插件组件从它取。 */
|
|
10
|
+
export declare const editorKey: InjectionKey<LexicalEditor | (() => LexicalEditor | null)>;
|
|
11
|
+
/** 读当前的 Lexical 编辑器。只能在 `<RichTextEditor>` 或 `<RichTextView>` 里面用。 */
|
|
12
|
+
export declare function useLexicalEditor(): LexicalEditor;
|
|
13
|
+
//#endregion
|
|
14
|
+
//#region src/editor/createEditor.d.ts
|
|
15
|
+
interface CreateRichTextEditorOptions {
|
|
16
|
+
/** 编辑器的名字,用来区分同一页上的多个编辑器。 */
|
|
17
|
+
namespace?: string;
|
|
18
|
+
/** 初始内容:序列化后的编辑器状态(JSON 字符串)。只在创建时读一次。 */
|
|
19
|
+
initialState?: string;
|
|
20
|
+
/** 创建时是否可编辑。之后用 `editor.setEditable()` 改。 */
|
|
21
|
+
editable?: boolean;
|
|
22
|
+
/** 在默认节点之外额外注册的节点。 */
|
|
23
|
+
nodes?: ReadonlyArray<Klass<LexicalNode>>;
|
|
24
|
+
/** 是否开启 Markdown 快捷输入(`# ` 变标题、`- ` 变列表)。 */
|
|
25
|
+
hasMarkdownShortcuts?: boolean;
|
|
26
|
+
/** 快捷输入用的转换器;传了就整个替换默认值。 */
|
|
27
|
+
transformers?: ReadonlyArray<Transformer>;
|
|
28
|
+
/** 编辑器主题类名;不传就用包自带的。 */
|
|
29
|
+
theme?: EditorThemeClasses;
|
|
30
|
+
/** 额外的 Lexical 扩展。 */
|
|
31
|
+
extensions?: ReadonlyArray<AnyLexicalExtensionArgument>;
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* 建一个富文本编辑器。只用 Lexical 的「扩展」机制,不碰 Vue,服务端和测试里都能直接建。
|
|
35
|
+
*
|
|
36
|
+
* 行为和上游一致:标题、引用、列表、链接、代码、表格节点;撤销重做;Tab 缩进;
|
|
37
|
+
* 勾选列表;分割线;Markdown 快捷输入;代码块和表格之间及末尾可以用下方向键补出段落;
|
|
38
|
+
* 按过 Escape 之后 Tab 把焦点交还浏览器。
|
|
39
|
+
*/
|
|
40
|
+
type RichTextEditorInstance = LexicalEditor & {
|
|
41
|
+
dispose: () => void;
|
|
42
|
+
};
|
|
43
|
+
export declare function createRichTextEditor(options?: CreateRichTextEditorOptions): RichTextEditorInstance;
|
|
44
|
+
//#endregion
|
|
45
|
+
//#region src/editor/icons.d.ts
|
|
46
|
+
/**
|
|
47
|
+
* 工具栏每个控件用的图标键。主题可以用 `defineTheme({ icons: { 'richtext:bold': 'lucide:bold' } })`
|
|
48
|
+
* 按键换成自己的图标;没换的就用下面包内自带的图形。
|
|
49
|
+
* 键带 `richtext:` 前缀,不会和 core 的语义图标名冲突。
|
|
50
|
+
*/
|
|
51
|
+
export declare const RICHTEXT_ICON_KEYS: {
|
|
52
|
+
readonly bold: "richtext:bold";
|
|
53
|
+
readonly italic: "richtext:italic";
|
|
54
|
+
readonly underline: "richtext:underline";
|
|
55
|
+
readonly strikethrough: "richtext:strikethrough";
|
|
56
|
+
readonly code: "richtext:code";
|
|
57
|
+
readonly link: "richtext:link";
|
|
58
|
+
readonly paragraph: "richtext:paragraph";
|
|
59
|
+
readonly h1: "richtext:h1";
|
|
60
|
+
readonly h2: "richtext:h2";
|
|
61
|
+
readonly h3: "richtext:h3";
|
|
62
|
+
readonly quote: "richtext:quote";
|
|
63
|
+
readonly bullet: "richtext:bullet";
|
|
64
|
+
readonly number: "richtext:number";
|
|
65
|
+
readonly undo: "richtext:undo";
|
|
66
|
+
readonly redo: "richtext:redo";
|
|
67
|
+
};
|
|
68
|
+
type RichTextIconName = keyof typeof RICHTEXT_ICON_KEYS;
|
|
69
|
+
//#endregion
|
|
70
|
+
//#region src/editor/plugins/autoLink.d.ts
|
|
71
|
+
/**
|
|
72
|
+
* 自动生成的链接都带这两个属性,在新标签页打开。只要有 `target="_blank"`,
|
|
73
|
+
* 就必须同时有 `rel="noopener noreferrer"`,否则被打开的页面能通过 `window.opener` 反过来操控原页面。
|
|
74
|
+
*/
|
|
75
|
+
export declare const NEW_TAB_LINK_ATTRIBUTES: {
|
|
76
|
+
readonly target: "_blank";
|
|
77
|
+
readonly rel: "noopener noreferrer";
|
|
78
|
+
};
|
|
79
|
+
/**
|
|
80
|
+
* 默认的两个匹配器:网址(没写协议就补 `https://`)和邮箱(写成 `mailto:` 链接)。
|
|
81
|
+
* 网址都过一遍 `sanitizeUrl`,所以写进去的只可能是 http、https、mailto、tel。
|
|
82
|
+
*/
|
|
83
|
+
export declare const DEFAULT_LINK_MATCHERS: LinkMatcher[];
|
|
84
|
+
//#endregion
|
|
85
|
+
//#region src/editor/plugins/RichTextEditorAutoLinkPlugin.d.ts
|
|
86
|
+
/**
|
|
87
|
+
* 没有界面的组件:放在 `<RichTextEditor>` 的默认插槽里,输入或粘贴的网址、邮箱就会自动变成链接。
|
|
88
|
+
*
|
|
89
|
+
* ```vue
|
|
90
|
+
* <RichTextEditor label="Notes">
|
|
91
|
+
* <RichTextEditorAutoLinkPlugin />
|
|
92
|
+
* </RichTextEditor>
|
|
93
|
+
* ```
|
|
94
|
+
*/
|
|
95
|
+
export declare const RichTextEditorAutoLinkPlugin: import("vue").DefineComponent<import("vue").ExtractPropTypes<{
|
|
96
|
+
/** 要识别哪些写法,默认网址和邮箱。用 `createLinkMatcherWithRegExp` 可以加自己的,比如工单号。 */
|
|
97
|
+
matchers: {
|
|
98
|
+
type: PropType<LinkMatcher[]>;
|
|
99
|
+
default: undefined;
|
|
100
|
+
};
|
|
101
|
+
}>, () => null, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {
|
|
102
|
+
/** 自动加、改、去掉链接时触发:新网址(去掉时是 `null`)和原来的网址。 */
|
|
103
|
+
change: (_url: string | null, _prevUrl: string | null) => true;
|
|
104
|
+
}, string, import("vue").PublicProps, Readonly<import("vue").ExtractPropTypes<{
|
|
105
|
+
/** 要识别哪些写法,默认网址和邮箱。用 `createLinkMatcherWithRegExp` 可以加自己的,比如工单号。 */
|
|
106
|
+
matchers: {
|
|
107
|
+
type: PropType<LinkMatcher[]>;
|
|
108
|
+
default: undefined;
|
|
109
|
+
};
|
|
110
|
+
}>> & Readonly<{
|
|
111
|
+
onChange?: ((_url: string | null, _prevUrl: string | null) => any) | undefined;
|
|
112
|
+
}>, {
|
|
113
|
+
matchers: LinkMatcher[];
|
|
114
|
+
}, {}, {}, {}, string, import("vue").ComponentProvideOptions, true, {}, any>;
|
|
115
|
+
//#endregion
|
|
116
|
+
//#region src/editor/types.d.ts
|
|
117
|
+
type RichTextEditorStatusType = 'warning' | 'error' | 'success';
|
|
118
|
+
type RichTextEditorSize = 'sm' | 'md' | 'lg';
|
|
119
|
+
interface RichTextEditorStatus {
|
|
120
|
+
/** 状态类型,决定边框颜色。 */
|
|
121
|
+
type: RichTextEditorStatusType;
|
|
122
|
+
/** 显示在编辑器下面的说明文字。 */
|
|
123
|
+
message?: string;
|
|
124
|
+
}
|
|
125
|
+
interface RichTextEditorProps {
|
|
126
|
+
/** 编辑器的标签文字。无障碍用,所以一定要写。 */
|
|
127
|
+
label: string;
|
|
128
|
+
/**
|
|
129
|
+
* 是否只对读屏软件显示标签。
|
|
130
|
+
* @default false
|
|
131
|
+
*/
|
|
132
|
+
isLabelHidden?: boolean;
|
|
133
|
+
/** 标签和编辑区之间的说明文字。 */
|
|
134
|
+
description?: string;
|
|
135
|
+
/**
|
|
136
|
+
* 是否选填。和 `isRequired` 互斥。
|
|
137
|
+
* @default false
|
|
138
|
+
*/
|
|
139
|
+
isOptional?: boolean;
|
|
140
|
+
/**
|
|
141
|
+
* 是否必填。和 `isOptional` 互斥。
|
|
142
|
+
* @default false
|
|
143
|
+
*/
|
|
144
|
+
isRequired?: boolean;
|
|
145
|
+
/**
|
|
146
|
+
* 初始内容:`JSON.stringify(editorState.toJSON())` 得到的字符串。
|
|
147
|
+
* 编辑器是非受控的,只在创建时读一次。
|
|
148
|
+
*/
|
|
149
|
+
defaultValue?: string;
|
|
150
|
+
/** 内容为空时显示的提示文字。 */
|
|
151
|
+
placeholder?: string;
|
|
152
|
+
/**
|
|
153
|
+
* 是否只读。内容保持原来的不透明度、仍然可以用 Tab 走到、读屏软件读作「只读」,
|
|
154
|
+
* 所以使用者依然能读到、复制到内容。改变后立即生效。
|
|
155
|
+
* @default false
|
|
156
|
+
*/
|
|
157
|
+
isReadOnly?: boolean;
|
|
158
|
+
/**
|
|
159
|
+
* 是否禁用:不可编辑、变淡、不在 Tab 顺序里、读屏软件读作「禁用」。
|
|
160
|
+
* 和 `isReadOnly` 一起设时以它为准。改变后立即生效。
|
|
161
|
+
* @default false
|
|
162
|
+
*/
|
|
163
|
+
isDisabled?: boolean;
|
|
164
|
+
/** 状态:有了它编辑器会画出对应颜色的边框;带 `message` 时在下面显示说明。 */
|
|
165
|
+
status?: RichTextEditorStatus;
|
|
166
|
+
/**
|
|
167
|
+
* 状态说明相对编辑器怎么放。
|
|
168
|
+
* @default 'attached'
|
|
169
|
+
*/
|
|
170
|
+
statusVariant?: 'attached' | 'detached' | 'tooltip';
|
|
171
|
+
/** 整个字段的宽度。数字当像素,字符串原样当 CSS 长度。 */
|
|
172
|
+
width?: number | string;
|
|
173
|
+
/**
|
|
174
|
+
* 编辑区的最小高度。数字当像素,字符串原样当 CSS 长度。
|
|
175
|
+
* @default '4.5rem'
|
|
176
|
+
*/
|
|
177
|
+
minHeight?: number | string;
|
|
178
|
+
/** 标签末尾信息图标里的提示文字。 */
|
|
179
|
+
labelTooltip?: string;
|
|
180
|
+
/**
|
|
181
|
+
* 编辑器尺寸,影响内边距。
|
|
182
|
+
* @default 'md'
|
|
183
|
+
*/
|
|
184
|
+
size?: RichTextEditorSize;
|
|
185
|
+
/** 在默认节点(标题、引用、列表、链接、代码、表格)之外额外注册的 Lexical 节点。 */
|
|
186
|
+
nodes?: ReadonlyArray<Klass<LexicalNode>>;
|
|
187
|
+
/**
|
|
188
|
+
* 额外的 Lexical 扩展。想加提及、图片这类功能,写成扩展传进来,
|
|
189
|
+
* 或者在默认插槽里放一个调用 `useLexicalEditor()` 的组件。
|
|
190
|
+
*/
|
|
191
|
+
extensions?: ReadonlyArray<AnyLexicalExtensionArgument>;
|
|
192
|
+
/**
|
|
193
|
+
* 这个编辑器要画哪些 Markdown 插件的节点,每个都用 `createRichTextExtension` 采用。
|
|
194
|
+
* 插件节点画出来和 core 的 `Markdown` 一样;没在这里给出插件的节点显示它的原文。
|
|
195
|
+
* 传内容转换时用的那些扩展。要在客户端模块里创建:它们带着插件的函数,不是能序列化的 props。
|
|
196
|
+
*/
|
|
197
|
+
markdownExtensions?: ReadonlyArray<RichTextMarkdownExtension>;
|
|
198
|
+
/**
|
|
199
|
+
* 是否开启 Markdown 快捷输入(输入 `# ` 变标题、`- ` 变列表)。
|
|
200
|
+
* @default true
|
|
201
|
+
*/
|
|
202
|
+
hasMarkdownShortcuts?: boolean;
|
|
203
|
+
/**
|
|
204
|
+
* Markdown 转换器:快捷输入、导出 Markdown 共用这一份。
|
|
205
|
+
* 默认是 `@lexical/markdown` 的标准转换器加 GFM 表格;传了就整个替换。
|
|
206
|
+
*/
|
|
207
|
+
transformers?: ReadonlyArray<Transformer>;
|
|
208
|
+
/**
|
|
209
|
+
* 挂载时是否自动聚焦。
|
|
210
|
+
* @default false
|
|
211
|
+
*/
|
|
212
|
+
hasAutoFocus?: boolean;
|
|
213
|
+
/**
|
|
214
|
+
* 给读屏软件的提示:怎么把焦点移出编辑器(Tab 用来缩进,所以要先按 Escape 再按 Tab)。
|
|
215
|
+
* 视觉上隐藏,由编辑区的 `aria-describedby` 引用。传空字符串则不输出。
|
|
216
|
+
*/
|
|
217
|
+
tabEscapeHint?: string;
|
|
218
|
+
/**
|
|
219
|
+
* 字数上限。设了之后编辑器下面显示「当前/上限」。和 TextArea 一样不强行截断,
|
|
220
|
+
* 超出后计数变红。字数按纯文本长度算。
|
|
221
|
+
*/
|
|
222
|
+
maxLength?: number;
|
|
223
|
+
/**
|
|
224
|
+
* Lexical 编辑器的名字,用来区分同一页上的多个编辑器。
|
|
225
|
+
* @default 'astryx-editor'
|
|
226
|
+
*/
|
|
227
|
+
namespace?: string;
|
|
228
|
+
}
|
|
229
|
+
interface RichTextEditorEmits {
|
|
230
|
+
/** 内容变化时触发。参数是最新的编辑器状态和编辑器实例;用 `editorState.toJSON()` 存起来。 */
|
|
231
|
+
change: [editorState: EditorState, editor: LexicalEditor];
|
|
232
|
+
}
|
|
233
|
+
interface RichTextEditorSlots {
|
|
234
|
+
/** 放在编辑区上面、顶到两边的工具栏。 */
|
|
235
|
+
toolbar?: () => unknown;
|
|
236
|
+
/** 额外的内容,渲染在编辑器里面。放调用 `useLexicalEditor()` 的组件来扩展行为。 */
|
|
237
|
+
default?: () => unknown;
|
|
238
|
+
}
|
|
239
|
+
/** 通过模板引用拿到的方法。 */
|
|
240
|
+
interface RichTextEditorExposed {
|
|
241
|
+
/** 把焦点移进编辑区。只读或禁用时什么也不做。 */
|
|
242
|
+
focus: () => void;
|
|
243
|
+
/** 清空内容,回到只有一个空段落。只读或禁用时什么也不做。 */
|
|
244
|
+
clear: () => void;
|
|
245
|
+
/** 当前的编辑器状态;用 `.toJSON()` 序列化后保存。 */
|
|
246
|
+
getEditorState: () => EditorState;
|
|
247
|
+
/** 导出 Markdown。导入时没动过的块原样导出,改过或新加的块用规范写法。 */
|
|
248
|
+
getMarkdown: () => string;
|
|
249
|
+
/** 导出 HTML。需要 DOM。 */
|
|
250
|
+
getHTML: () => string;
|
|
251
|
+
/** 底层的 Lexical 编辑器,给高级用法用。 */
|
|
252
|
+
getEditor: () => LexicalEditor;
|
|
253
|
+
}
|
|
254
|
+
//#endregion
|
|
255
|
+
//#region src/editor/RichTextEditor.vue.d.ts
|
|
256
|
+
type __VLS_Slots$2 = RichTextEditorSlots;
|
|
257
|
+
declare const __VLS_base$2: import("vue").DefineComponent<RichTextEditorProps, RichTextEditorExposed, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {
|
|
258
|
+
change: (editorState: import("lexical").EditorState, editor: LexicalEditor) => any;
|
|
259
|
+
}, string, import("vue").PublicProps, Readonly<RichTextEditorProps> & Readonly<{
|
|
260
|
+
onChange?: ((editorState: import("lexical").EditorState, editor: LexicalEditor) => any) | undefined;
|
|
261
|
+
}>, {
|
|
262
|
+
namespace: string;
|
|
263
|
+
size: RichTextEditorSize;
|
|
264
|
+
statusVariant: "attached" | "detached" | "tooltip";
|
|
265
|
+
minHeight: string | number;
|
|
266
|
+
hasMarkdownShortcuts: boolean;
|
|
267
|
+
}, {}, {}, {}, string, import("vue").ComponentProvideOptions, false, {}, any>;
|
|
268
|
+
declare const __VLS_export$2: __VLS_WithSlots$2<typeof __VLS_base$2, __VLS_Slots$2>;
|
|
269
|
+
declare const _default: typeof __VLS_export$2;
|
|
270
|
+
type __VLS_WithSlots$2<T, S> = T & {
|
|
271
|
+
new (): {
|
|
272
|
+
$slots: S;
|
|
273
|
+
};
|
|
274
|
+
};
|
|
275
|
+
//#endregion
|
|
276
|
+
//#region src/editor/toolbarTypes.d.ts
|
|
277
|
+
type RichTextToolbarSize = 'sm' | 'md' | 'lg';
|
|
278
|
+
interface RichTextEditorToolbarProps {
|
|
279
|
+
/**
|
|
280
|
+
* 工具栏的无障碍名称。
|
|
281
|
+
* @default 'Text formatting',按当前语言翻译
|
|
282
|
+
*/
|
|
283
|
+
label?: string;
|
|
284
|
+
/**
|
|
285
|
+
* 「块格式」下拉里提供哪几级标题,按这个顺序排。
|
|
286
|
+
* @default ['h1', 'h2', 'h3']
|
|
287
|
+
*/
|
|
288
|
+
headingLevels?: ReadonlyArray<'h1' | 'h2' | 'h3'>;
|
|
289
|
+
/**
|
|
290
|
+
* 工具栏尺寸,同时影响里面各个控件。
|
|
291
|
+
* @default 'sm'
|
|
292
|
+
*/
|
|
293
|
+
size?: RichTextToolbarSize;
|
|
294
|
+
/**
|
|
295
|
+
* 是否显示插入、编辑链接的按钮。默认点开一个对话框,里面可以添加、更新、移除链接,
|
|
296
|
+
* 选区不会丢。写进去的网址会先过 `sanitizeUrl`,只放行 http、https、mailto、tel。
|
|
297
|
+
* @default true
|
|
298
|
+
*/
|
|
299
|
+
hasLink?: boolean;
|
|
300
|
+
/**
|
|
301
|
+
* 自己提供网址输入界面时用:在没有链接的选区上按链接按钮,会带着选中的文字调用它;
|
|
302
|
+
* 返回网址就加链接,返回空就取消。不传就用内置的对话框。
|
|
303
|
+
*/
|
|
304
|
+
promptForUrl?: (selectedText: string) => string | null | undefined;
|
|
305
|
+
/**
|
|
306
|
+
* 工具栏里创建的链接是否在新标签页打开:带 `target="_blank"` 和 `rel="noopener noreferrer"`,
|
|
307
|
+
* 写进链接节点的数据里,所以能随文档保存、往返。设为 `false` 就是同页打开。
|
|
308
|
+
* @default true
|
|
309
|
+
*/
|
|
310
|
+
hasNewTabLinks?: boolean;
|
|
311
|
+
}
|
|
312
|
+
interface RichTextEditorToolbarSlots {
|
|
313
|
+
/** 放在默认按钮后面(隔一条分隔线)的内容,用来加自己的控件,比如提及、AI。 */
|
|
314
|
+
end?: () => unknown;
|
|
315
|
+
}
|
|
316
|
+
//#endregion
|
|
317
|
+
//#region src/editor/RichTextEditorToolbar.vue.d.ts
|
|
318
|
+
type __VLS_Slots$1 = RichTextEditorToolbarSlots;
|
|
319
|
+
declare const __VLS_base$1: import("vue").DefineComponent<RichTextEditorToolbarProps, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").PublicProps, Readonly<RichTextEditorToolbarProps> & Readonly<{}>, {
|
|
320
|
+
headingLevels: readonly ("h1" | "h2" | "h3")[];
|
|
321
|
+
size: RichTextToolbarSize;
|
|
322
|
+
hasLink: boolean;
|
|
323
|
+
hasNewTabLinks: boolean;
|
|
324
|
+
}, {}, {}, {}, string, import("vue").ComponentProvideOptions, false, {}, any>;
|
|
325
|
+
declare const __VLS_export$1: __VLS_WithSlots$1<typeof __VLS_base$1, __VLS_Slots$1>;
|
|
326
|
+
declare const _default$1: typeof __VLS_export$1;
|
|
327
|
+
type __VLS_WithSlots$1<T, S> = T & {
|
|
328
|
+
new (): {
|
|
329
|
+
$slots: S;
|
|
330
|
+
};
|
|
331
|
+
};
|
|
332
|
+
//#endregion
|
|
333
|
+
//#region src/editor/viewTypes.d.ts
|
|
334
|
+
interface RichTextViewProps {
|
|
335
|
+
/** 要渲染的编辑器状态:`JSON.stringify(editorState.toJSON())` 得到的字符串。 */
|
|
336
|
+
value: string;
|
|
337
|
+
/** 在默认节点之外额外注册的 Lexical 节点。要和写这份 `value` 时用的一致,自定义节点才读得回来。 */
|
|
338
|
+
nodes?: ReadonlyArray<Klass<LexicalNode>>;
|
|
339
|
+
/**
|
|
340
|
+
* 这个视图要画哪些 Markdown 插件的节点,每个都用 `createRichTextExtension` 采用。
|
|
341
|
+
* 插件节点画出来和 core 的 `Markdown` 一样;没在这里给出插件的节点显示它的原文。
|
|
342
|
+
* 传内容转换时用的那些扩展。要在客户端模块里创建:它们带着插件的函数,不是能序列化的 props。
|
|
343
|
+
*/
|
|
344
|
+
markdownExtensions?: ReadonlyArray<RichTextMarkdownExtension>;
|
|
345
|
+
/**
|
|
346
|
+
* Lexical 编辑器的名字。
|
|
347
|
+
* @default 'astryx-view'
|
|
348
|
+
*/
|
|
349
|
+
namespace?: string;
|
|
350
|
+
}
|
|
351
|
+
interface RichTextViewSlots {
|
|
352
|
+
/**
|
|
353
|
+
* `value` 解析不了(JSON 坏了,或者用了没通过 `nodes` 注册的节点类型)时显示的内容,默认什么也不画。
|
|
354
|
+
* 只读视图读的是持久化的内容,过期或者别的结构的状态恰恰出现在这里,所以不抛错、不带崩宿主页面。
|
|
355
|
+
*/
|
|
356
|
+
errorFallback?: () => unknown;
|
|
357
|
+
/** 额外的只读内容,渲染在视图里面。放调用 `useLexicalEditor()` 的组件来扩展。 */
|
|
358
|
+
default?: () => unknown;
|
|
359
|
+
}
|
|
360
|
+
//#endregion
|
|
361
|
+
//#region src/editor/RichTextView.vue.d.ts
|
|
362
|
+
type __VLS_Slots = RichTextViewSlots;
|
|
363
|
+
declare const __VLS_base: import("vue").DefineComponent<RichTextViewProps, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {
|
|
364
|
+
parseError: (error: Error) => any;
|
|
365
|
+
}, string, import("vue").PublicProps, Readonly<RichTextViewProps> & Readonly<{
|
|
366
|
+
onParseError?: ((error: Error) => any) | undefined;
|
|
367
|
+
}>, {
|
|
368
|
+
namespace: string;
|
|
369
|
+
}, {}, {}, {}, string, import("vue").ComponentProvideOptions, false, {}, any>;
|
|
370
|
+
declare const __VLS_export: __VLS_WithSlots<typeof __VLS_base, __VLS_Slots>;
|
|
371
|
+
declare const _default$2: typeof __VLS_export;
|
|
372
|
+
type __VLS_WithSlots<T, S> = T & {
|
|
373
|
+
new (): {
|
|
374
|
+
$slots: S;
|
|
375
|
+
};
|
|
376
|
+
};
|
|
377
|
+
//#endregion
|
|
378
|
+
//#region src/linkUtils.d.ts
|
|
379
|
+
/**
|
|
380
|
+
* Return a safe href for `url`, or `'about:blank'` if it can't be parsed or uses
|
|
381
|
+
* a disallowed scheme. A scheme-less input like `example.com` is treated as
|
|
382
|
+
* `https://example.com`. Use this before writing any user-supplied string into
|
|
383
|
+
* a link's href.
|
|
384
|
+
*/
|
|
385
|
+
export declare function sanitizeUrl(url: string): string;
|
|
386
|
+
/**
|
|
387
|
+
* Whether `url` is a well-formed, safe (http/https/mailto/tel) URL. Used to
|
|
388
|
+
* decide whether an entered link value is acceptable before dispatching the
|
|
389
|
+
* toggle-link command. Shares the {@link SAFE_PROTOCOLS} allowlist with
|
|
390
|
+
* {@link sanitizeUrl} so the two never disagree.
|
|
391
|
+
*/
|
|
392
|
+
export declare function validateUrl(url: string): boolean;
|
|
393
|
+
//#endregion
|
|
394
|
+
export { type CreateRichTextEditorOptions, type MarkdownSerializerOptions, _default as RichTextEditor, type RichTextEditorEmits, type RichTextEditorExposed, type RichTextEditorProps, type RichTextEditorSize, type RichTextEditorSlots, type RichTextEditorStatus, type RichTextEditorStatusType, _default$1 as RichTextEditorToolbar, type RichTextEditorToolbarProps, type RichTextEditorToolbarSlots, RichTextExtensionError, type RichTextIconName, type RichTextMarkdownExtension, type RichTextToolbarSize, _default$2 as RichTextView, type RichTextViewProps, type RichTextViewSlots, createRichTextExtension, editorStateJSONToMarkdown, markdownToEditorStateJSON };
|