@eworkbase/sdk 0.3.5 → 0.4.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/dist/ExecutionLog.dto-CI-HpxZa.d.ts +116 -0
- package/dist/index.d.ts +3 -2
- package/dist/index.js +85 -1
- package/dist/markdown-link-C-qw7xuN.js +50 -0
- package/dist/markdown.d.ts +18 -0
- package/dist/markdown.js +112 -0
- package/dist/style.css +2376 -0
- package/dist/{types-Cl1kerLO.d.ts → types-Bv7aJizu.d.ts} +10 -0
- package/dist/types-C8byxPji.d.ts +154 -0
- package/dist/ui/error-panel.d.ts +15 -0
- package/dist/ui/error-panel.js +44 -0
- package/dist/ui/execution-log.d.ts +42 -0
- package/dist/ui/execution-log.js +446 -0
- package/dist/ui/index.css +16 -6
- package/dist/ui/index.d.ts +2 -151
- package/dist/ui/index.js +1 -0
- package/dist/ui/markdown-editor-assets/LICENSE +21 -0
- package/dist/ui/markdown-editor-assets/ant.js +174 -0
- package/dist/ui/markdown-editor-assets/dist/js/highlight.js/styles/github.min.css +10 -0
- package/dist/ui/markdown-editor-assets/lute.min.js +87 -0
- package/dist/ui/markdown-editor-assets/zh_CN.js +86 -0
- package/dist/ui/markdown-editor.d.ts +26 -0
- package/dist/ui/markdown-editor.js +361 -0
- package/dist/ui/markdown-links.d.ts +12 -0
- package/dist/ui/markdown-links.js +246 -0
- package/dist/ui/model.d.ts +2 -0
- package/dist/ui/model.js +5 -1
- package/dist/ui/theme.css +109 -0
- package/package.json +38 -2
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
window.VditorI18n = {
|
|
2
|
+
'alignCenter': '居中',
|
|
3
|
+
'alignLeft': '居左',
|
|
4
|
+
'alignRight': '居右',
|
|
5
|
+
'alternateText': '替代文本',
|
|
6
|
+
'bold': '粗体',
|
|
7
|
+
'both': '编辑 & 预览',
|
|
8
|
+
'cancelUpload': '取消上传',
|
|
9
|
+
'check': '任务列表',
|
|
10
|
+
'close': '关闭',
|
|
11
|
+
'code': '代码块',
|
|
12
|
+
'code-theme': '代码块主题预览',
|
|
13
|
+
'column': '列',
|
|
14
|
+
'comment': '评论',
|
|
15
|
+
'confirm': '确定',
|
|
16
|
+
'content-theme': '内容主题预览',
|
|
17
|
+
'copied': '已复制',
|
|
18
|
+
'copy': '复制',
|
|
19
|
+
'delete-column': '删除列',
|
|
20
|
+
'delete-row': '删除行',
|
|
21
|
+
'devtools': '开发者工具',
|
|
22
|
+
'down': '下',
|
|
23
|
+
'downloadTip': '该浏览器不支持下载功能',
|
|
24
|
+
'edit': '编辑',
|
|
25
|
+
'edit-mode': '切换编辑模式',
|
|
26
|
+
'emoji': '表情',
|
|
27
|
+
'export': '导出',
|
|
28
|
+
'fileTypeError': '文件类型不允许上传,请压缩后再试',
|
|
29
|
+
'footnoteRef': '脚注标识',
|
|
30
|
+
'fullscreen': '全屏切换',
|
|
31
|
+
'generate': '生成中',
|
|
32
|
+
'headings': '标题',
|
|
33
|
+
'heading1': '一级标题',
|
|
34
|
+
'heading2': '二级标题',
|
|
35
|
+
'heading3': '三级标题',
|
|
36
|
+
'heading4': '四级标题',
|
|
37
|
+
'heading5': '五级标题',
|
|
38
|
+
'heading6': '六级标题',
|
|
39
|
+
'help': '帮助',
|
|
40
|
+
'imageURL': '图片地址',
|
|
41
|
+
'indent': '列表缩进',
|
|
42
|
+
'info': '关于',
|
|
43
|
+
'inline-code': '行内代码',
|
|
44
|
+
'insert-after': '末尾插入行',
|
|
45
|
+
'insert-before': '起始插入行',
|
|
46
|
+
'insertColumnLeft': '在左边插入一列',
|
|
47
|
+
'insertColumnRight': '在右边插入一列',
|
|
48
|
+
'insertRowAbove': '在上方插入一行',
|
|
49
|
+
'insertRowBelow': '在下方插入一行',
|
|
50
|
+
'instantRendering': '即时渲染',
|
|
51
|
+
'italic': '斜体',
|
|
52
|
+
'language': '语言',
|
|
53
|
+
'line': '分隔线',
|
|
54
|
+
'link': '链接',
|
|
55
|
+
'linkRef': '引用标识',
|
|
56
|
+
'list': '无序列表',
|
|
57
|
+
'more': '更多',
|
|
58
|
+
'nameEmpty': '文件名不能为空',
|
|
59
|
+
'ordered-list': '有序列表',
|
|
60
|
+
'outdent': '列表反向缩进',
|
|
61
|
+
'outline': '大纲',
|
|
62
|
+
'over': '超过',
|
|
63
|
+
'performanceTip': '实时预览需 ${x}ms,可点击编辑 & 预览按钮进行关闭',
|
|
64
|
+
'preview': '预览',
|
|
65
|
+
'quote': '引用',
|
|
66
|
+
'record': '开始录音/结束录音',
|
|
67
|
+
'record-tip': '该设备不支持录音功能',
|
|
68
|
+
'recording': '录音中...',
|
|
69
|
+
'redo': '重做',
|
|
70
|
+
'remove': '删除',
|
|
71
|
+
'row': '行',
|
|
72
|
+
'spin': '旋转',
|
|
73
|
+
'splitView': '分屏预览',
|
|
74
|
+
'strike': '删除线',
|
|
75
|
+
'table': '表格',
|
|
76
|
+
'textIsNotEmpty': '文本(不能为空)',
|
|
77
|
+
'title': '标题',
|
|
78
|
+
'tooltipText': '提示文本',
|
|
79
|
+
'undo': '撤销',
|
|
80
|
+
'up': '上',
|
|
81
|
+
'update': '更新',
|
|
82
|
+
'upload': '上传图片或文件',
|
|
83
|
+
'uploadError': '上传错误',
|
|
84
|
+
'uploading': '上传中...',
|
|
85
|
+
'wysiwyg': '所见即所得',
|
|
86
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import "vditor";
|
|
2
|
+
//#region src/ui/MarkdownEditor.dto.d.ts
|
|
3
|
+
interface MarkdownCompletion {
|
|
4
|
+
readonly value: string;
|
|
5
|
+
readonly description?: string;
|
|
6
|
+
}
|
|
7
|
+
interface MarkdownEditorProps {
|
|
8
|
+
readonly value: string;
|
|
9
|
+
readonly onChange: (value: string) => void;
|
|
10
|
+
readonly label: string;
|
|
11
|
+
readonly sourcePath?: string;
|
|
12
|
+
readonly name?: string;
|
|
13
|
+
readonly placeholder?: string;
|
|
14
|
+
readonly isReadOnly?: boolean;
|
|
15
|
+
readonly isDisabled?: boolean;
|
|
16
|
+
readonly required?: boolean;
|
|
17
|
+
readonly maxLength?: number;
|
|
18
|
+
readonly completions?: readonly MarkdownCompletion[];
|
|
19
|
+
}
|
|
20
|
+
//#endregion
|
|
21
|
+
//#region src/ui/MarkdownEditor.d.ts
|
|
22
|
+
export declare const MarkdownEditor: import("react").NamedExoticComponent<MarkdownEditorProps>;
|
|
23
|
+
/** Reuses the bundled offline renderer for editors and linked document previews. */
|
|
24
|
+
export declare function renderMarkdownPreview(content: string): Promise<string>;
|
|
25
|
+
//#endregion
|
|
26
|
+
export type { MarkdownCompletion, MarkdownEditorProps };
|
|
@@ -0,0 +1,361 @@
|
|
|
1
|
+
import { memo, useCallback, useEffect, useId, useRef, useState } from "react";
|
|
2
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
3
|
+
//#region src/ui/MarkdownEditor.tsx
|
|
4
|
+
/** Local Vditor field with three editing modes, draft-safe updates and native form submission. */
|
|
5
|
+
const ASSET_DIRECTORY = "./markdown-editor-assets/";
|
|
6
|
+
const MINIMUM_EDITOR_HEIGHT = 360;
|
|
7
|
+
const MAXIMUM_HINTS = 12;
|
|
8
|
+
const LUTE_SKIP_CHILDREN = 1;
|
|
9
|
+
const PREVIEW_RENDERERS = {
|
|
10
|
+
renderHTMLBlock: skipRawHtml,
|
|
11
|
+
renderInlineHTML: skipRawHtml
|
|
12
|
+
};
|
|
13
|
+
const TOOLBAR = [
|
|
14
|
+
"bold",
|
|
15
|
+
"list",
|
|
16
|
+
"check",
|
|
17
|
+
"|",
|
|
18
|
+
"edit-mode",
|
|
19
|
+
"preview",
|
|
20
|
+
{
|
|
21
|
+
name: "more",
|
|
22
|
+
toolbar: [
|
|
23
|
+
"headings",
|
|
24
|
+
"italic",
|
|
25
|
+
"strike",
|
|
26
|
+
"ordered-list",
|
|
27
|
+
"quote",
|
|
28
|
+
"code",
|
|
29
|
+
"table",
|
|
30
|
+
"|",
|
|
31
|
+
"undo",
|
|
32
|
+
"redo",
|
|
33
|
+
"both"
|
|
34
|
+
]
|
|
35
|
+
}
|
|
36
|
+
];
|
|
37
|
+
const LOCAL_SCRIPTS = [
|
|
38
|
+
{
|
|
39
|
+
file: "zh_CN.js",
|
|
40
|
+
id: "vditorI18nScriptzh_CN"
|
|
41
|
+
},
|
|
42
|
+
{
|
|
43
|
+
file: "ant.js",
|
|
44
|
+
id: "vditorIconScript"
|
|
45
|
+
},
|
|
46
|
+
{
|
|
47
|
+
file: "lute.min.js",
|
|
48
|
+
id: "vditorLuteScript"
|
|
49
|
+
}
|
|
50
|
+
];
|
|
51
|
+
const MarkdownEditor = memo(function MarkdownEditor({ value, onChange, label, name, placeholder = "输入 Markdown…", isReadOnly = false, isDisabled = false, required, maxLength, completions = [], sourcePath }) {
|
|
52
|
+
const container = useRef(null);
|
|
53
|
+
const formValue = useRef(null);
|
|
54
|
+
const editor = useRef(null);
|
|
55
|
+
const latest = useRef({
|
|
56
|
+
value,
|
|
57
|
+
onChange,
|
|
58
|
+
isReadOnly,
|
|
59
|
+
isDisabled,
|
|
60
|
+
completions
|
|
61
|
+
});
|
|
62
|
+
const rendered = useRef(null);
|
|
63
|
+
const source = useRef(value);
|
|
64
|
+
const isUpdating = useRef(false);
|
|
65
|
+
const labelId = useId();
|
|
66
|
+
const [attempt, setAttempt] = useState(0);
|
|
67
|
+
const [isReady, setIsReady] = useState(false);
|
|
68
|
+
const [error, setError] = useState(null);
|
|
69
|
+
const [validationError, setValidationError] = useState(null);
|
|
70
|
+
latest.current = {
|
|
71
|
+
value,
|
|
72
|
+
onChange,
|
|
73
|
+
isReadOnly,
|
|
74
|
+
isDisabled,
|
|
75
|
+
completions
|
|
76
|
+
};
|
|
77
|
+
const handleOpenLink = useCallback((element) => {
|
|
78
|
+
const href = element.getAttribute("href") ?? element.textContent ?? "";
|
|
79
|
+
if (!!element.dispatchEvent(new CustomEvent("workbase-markdown-link", {
|
|
80
|
+
bubbles: true,
|
|
81
|
+
cancelable: true,
|
|
82
|
+
detail: href
|
|
83
|
+
}))) setValidationError("当前视图无法打开此链接。");
|
|
84
|
+
}, []);
|
|
85
|
+
const handleLinkClick = useCallback((event) => {
|
|
86
|
+
if (event.button !== 0 && event.button !== 1) return;
|
|
87
|
+
const link = event.target.closest?.("a[href]");
|
|
88
|
+
if (!link) return;
|
|
89
|
+
event.preventDefault();
|
|
90
|
+
event.stopPropagation();
|
|
91
|
+
handleOpenLink(link);
|
|
92
|
+
}, [handleOpenLink]);
|
|
93
|
+
useEffect(() => {
|
|
94
|
+
const element = container.current;
|
|
95
|
+
let stopped = false;
|
|
96
|
+
let instance = null;
|
|
97
|
+
let initialized = false;
|
|
98
|
+
if (!element) return;
|
|
99
|
+
const updateContent = (content) => {
|
|
100
|
+
if (stopped || isUpdating.current || !initialized || content === rendered.current) return;
|
|
101
|
+
rendered.current = content;
|
|
102
|
+
source.current = content;
|
|
103
|
+
latest.current.onChange(content);
|
|
104
|
+
};
|
|
105
|
+
const initialize = async () => {
|
|
106
|
+
setIsReady(false);
|
|
107
|
+
setError(null);
|
|
108
|
+
try {
|
|
109
|
+
const Editor = await loadMarkdownLibrary();
|
|
110
|
+
if (stopped) return;
|
|
111
|
+
instance = new Editor(element, {
|
|
112
|
+
value: latest.current.value,
|
|
113
|
+
placeholder,
|
|
114
|
+
lang: "zh_CN",
|
|
115
|
+
mode: "ir",
|
|
116
|
+
cdn: new URL(ASSET_DIRECTORY, document.baseURI).href,
|
|
117
|
+
cache: { enable: false },
|
|
118
|
+
minHeight: MINIMUM_EDITOR_HEIGHT,
|
|
119
|
+
toolbar: [...TOOLBAR],
|
|
120
|
+
toolbarConfig: { pin: false },
|
|
121
|
+
counter: {
|
|
122
|
+
enable: Boolean(maxLength),
|
|
123
|
+
max: maxLength,
|
|
124
|
+
type: "markdown"
|
|
125
|
+
},
|
|
126
|
+
link: {
|
|
127
|
+
isOpen: false,
|
|
128
|
+
click: handleOpenLink
|
|
129
|
+
},
|
|
130
|
+
image: { isPreview: false },
|
|
131
|
+
preview: {
|
|
132
|
+
actions: [],
|
|
133
|
+
hljs: { enable: false },
|
|
134
|
+
theme: {
|
|
135
|
+
current: "",
|
|
136
|
+
path: ""
|
|
137
|
+
},
|
|
138
|
+
markdown: {
|
|
139
|
+
sanitize: true,
|
|
140
|
+
autoSpace: false,
|
|
141
|
+
fixTermTypo: false,
|
|
142
|
+
codeBlockPreview: false,
|
|
143
|
+
mathBlockPreview: false,
|
|
144
|
+
inlineMath: false
|
|
145
|
+
},
|
|
146
|
+
render: { media: { enable: false } },
|
|
147
|
+
transform: plainCodePreview
|
|
148
|
+
},
|
|
149
|
+
hint: {
|
|
150
|
+
emoji: {},
|
|
151
|
+
parse: false,
|
|
152
|
+
extend: ["@", "/"].map((key) => ({
|
|
153
|
+
key,
|
|
154
|
+
hint: (query) => latest.current.completions.filter(({ value: token }) => token.startsWith(key) && token.slice(key.length).toLowerCase().includes(query.toLowerCase())).slice(0, MAXIMUM_HINTS).map(({ value: token, description }) => ({
|
|
155
|
+
value: token,
|
|
156
|
+
html: escapeText(description ? token + " · " + description : token)
|
|
157
|
+
}))
|
|
158
|
+
}))
|
|
159
|
+
},
|
|
160
|
+
input: updateContent,
|
|
161
|
+
blur: updateContent,
|
|
162
|
+
focus: () => labelEditorFields(element, labelId),
|
|
163
|
+
after: () => {
|
|
164
|
+
if (!instance) return;
|
|
165
|
+
initialized = true;
|
|
166
|
+
if (stopped) {
|
|
167
|
+
instance.destroy();
|
|
168
|
+
return;
|
|
169
|
+
}
|
|
170
|
+
editor.current = instance;
|
|
171
|
+
isUpdating.current = true;
|
|
172
|
+
instance.setValue(latest.current.value, true);
|
|
173
|
+
source.current = latest.current.value;
|
|
174
|
+
rendered.current = instance.getValue();
|
|
175
|
+
isUpdating.current = false;
|
|
176
|
+
setEditorReadOnly(instance, latest.current.isDisabled || latest.current.isReadOnly);
|
|
177
|
+
labelEditorFields(element, labelId);
|
|
178
|
+
setIsReady(true);
|
|
179
|
+
}
|
|
180
|
+
});
|
|
181
|
+
} catch (failure) {
|
|
182
|
+
if (!stopped) setError(failure instanceof Error ? failure.message : "编辑器初始化失败。");
|
|
183
|
+
}
|
|
184
|
+
};
|
|
185
|
+
initialize();
|
|
186
|
+
return () => {
|
|
187
|
+
stopped = true;
|
|
188
|
+
editor.current = null;
|
|
189
|
+
if (initialized) instance?.destroy();
|
|
190
|
+
};
|
|
191
|
+
}, [
|
|
192
|
+
attempt,
|
|
193
|
+
handleOpenLink,
|
|
194
|
+
labelId,
|
|
195
|
+
maxLength,
|
|
196
|
+
placeholder
|
|
197
|
+
]);
|
|
198
|
+
useEffect(() => {
|
|
199
|
+
const instance = editor.current;
|
|
200
|
+
if (!instance || !isReady) return;
|
|
201
|
+
if (value === source.current) return;
|
|
202
|
+
isUpdating.current = true;
|
|
203
|
+
instance.setValue(value, true);
|
|
204
|
+
source.current = value;
|
|
205
|
+
rendered.current = instance.getValue();
|
|
206
|
+
isUpdating.current = false;
|
|
207
|
+
}, [isReady, value]);
|
|
208
|
+
useEffect(() => {
|
|
209
|
+
if (editor.current && isReady) setEditorReadOnly(editor.current, isDisabled || isReadOnly);
|
|
210
|
+
}, [
|
|
211
|
+
isDisabled,
|
|
212
|
+
isReadOnly,
|
|
213
|
+
isReady
|
|
214
|
+
]);
|
|
215
|
+
useEffect(() => {
|
|
216
|
+
formValue.current?.setCustomValidity(maxLength && value.length > maxLength ? "内容不能超过 " + maxLength + " 个字符。" : "");
|
|
217
|
+
setValidationError(null);
|
|
218
|
+
}, [maxLength, value]);
|
|
219
|
+
const handleFallbackChange = useCallback((event) => onChange(event.currentTarget.value), [onChange]);
|
|
220
|
+
const handleRetry = useCallback(() => setAttempt((current) => current + 1), []);
|
|
221
|
+
const handleInvalid = useCallback((event) => {
|
|
222
|
+
if (editor.current) {
|
|
223
|
+
event.preventDefault();
|
|
224
|
+
setValidationError(event.currentTarget.validationMessage);
|
|
225
|
+
editor.current.focus();
|
|
226
|
+
}
|
|
227
|
+
}, []);
|
|
228
|
+
return /* @__PURE__ */ jsxs("div", {
|
|
229
|
+
className: "workbase-markdown-editor",
|
|
230
|
+
"data-readonly": isReadOnly,
|
|
231
|
+
"data-disabled": isDisabled,
|
|
232
|
+
"data-markdown-source": sourcePath ?? "",
|
|
233
|
+
onClickCapture: handleLinkClick,
|
|
234
|
+
onAuxClickCapture: handleLinkClick,
|
|
235
|
+
children: [
|
|
236
|
+
/* @__PURE__ */ jsx("span", {
|
|
237
|
+
className: "markdown-field-label",
|
|
238
|
+
id: labelId,
|
|
239
|
+
children: label
|
|
240
|
+
}),
|
|
241
|
+
error ? /* @__PURE__ */ jsxs("p", {
|
|
242
|
+
role: "alert",
|
|
243
|
+
className: "markdown-editor-error",
|
|
244
|
+
children: ["编辑器加载失败,可继续编辑源码。", /* @__PURE__ */ jsx("button", {
|
|
245
|
+
type: "button",
|
|
246
|
+
onClick: handleRetry,
|
|
247
|
+
children: "重试"
|
|
248
|
+
})]
|
|
249
|
+
}) : null,
|
|
250
|
+
validationError ? /* @__PURE__ */ jsx("p", {
|
|
251
|
+
role: "alert",
|
|
252
|
+
className: "markdown-editor-error",
|
|
253
|
+
children: validationError
|
|
254
|
+
}) : null,
|
|
255
|
+
!isReady && !error ? /* @__PURE__ */ jsx("p", {
|
|
256
|
+
role: "status",
|
|
257
|
+
className: "markdown-editor-loading",
|
|
258
|
+
children: "正在加载编辑器…"
|
|
259
|
+
}) : null,
|
|
260
|
+
/* @__PURE__ */ jsx("div", {
|
|
261
|
+
ref: container,
|
|
262
|
+
className: "markdown-editor-surface",
|
|
263
|
+
hidden: !isReady
|
|
264
|
+
}),
|
|
265
|
+
/* @__PURE__ */ jsx("textarea", {
|
|
266
|
+
ref: formValue,
|
|
267
|
+
className: error ? "markdown-editor-fallback" : "markdown-editor-form-value",
|
|
268
|
+
"aria-label": label,
|
|
269
|
+
"aria-hidden": !error,
|
|
270
|
+
tabIndex: error ? 0 : -1,
|
|
271
|
+
name,
|
|
272
|
+
value,
|
|
273
|
+
onChange: handleFallbackChange,
|
|
274
|
+
required,
|
|
275
|
+
maxLength,
|
|
276
|
+
onInvalid: handleInvalid,
|
|
277
|
+
readOnly: isReadOnly,
|
|
278
|
+
disabled: isDisabled,
|
|
279
|
+
spellCheck: false,
|
|
280
|
+
autoCapitalize: "none"
|
|
281
|
+
})
|
|
282
|
+
]
|
|
283
|
+
});
|
|
284
|
+
});
|
|
285
|
+
/** Reuses the bundled offline renderer for editors and linked document previews. */
|
|
286
|
+
async function renderMarkdownPreview(content) {
|
|
287
|
+
return plainCodePreview(await (await loadMarkdownLibrary()).md2html(content, {
|
|
288
|
+
mode: "light",
|
|
289
|
+
renderers: PREVIEW_RENDERERS,
|
|
290
|
+
cdn: new URL(ASSET_DIRECTORY, document.baseURI).href,
|
|
291
|
+
markdown: {
|
|
292
|
+
sanitize: true,
|
|
293
|
+
autoSpace: false,
|
|
294
|
+
fixTermTypo: false,
|
|
295
|
+
codeBlockPreview: false,
|
|
296
|
+
mathBlockPreview: false,
|
|
297
|
+
inlineMath: false
|
|
298
|
+
}
|
|
299
|
+
}));
|
|
300
|
+
}
|
|
301
|
+
async function loadMarkdownLibrary() {
|
|
302
|
+
await Promise.all(LOCAL_SCRIPTS.map(loadLocalScript));
|
|
303
|
+
const { default: Editor } = await import("vditor");
|
|
304
|
+
return Editor;
|
|
305
|
+
}
|
|
306
|
+
async function loadLocalScript({ file, id }) {
|
|
307
|
+
const previous = document.getElementById(id);
|
|
308
|
+
if (previous?.dataset.loaded === "true") return;
|
|
309
|
+
await new Promise((resolve, reject) => {
|
|
310
|
+
const script = previous ?? document.createElement("script");
|
|
311
|
+
const finish = () => {
|
|
312
|
+
script.dataset.loaded = "true";
|
|
313
|
+
const icons = document.getElementById("vditor-icon-bold")?.closest("svg");
|
|
314
|
+
icons?.classList.add("workbase-markdown-icons");
|
|
315
|
+
icons?.setAttribute("aria-hidden", "true");
|
|
316
|
+
cleanup();
|
|
317
|
+
resolve();
|
|
318
|
+
};
|
|
319
|
+
const fail = () => {
|
|
320
|
+
cleanup();
|
|
321
|
+
script.remove();
|
|
322
|
+
reject(/* @__PURE__ */ new Error("无法加载编辑器资源:" + file));
|
|
323
|
+
};
|
|
324
|
+
const cleanup = () => {
|
|
325
|
+
script.removeEventListener("load", finish);
|
|
326
|
+
script.removeEventListener("error", fail);
|
|
327
|
+
};
|
|
328
|
+
script.addEventListener("load", finish, { once: true });
|
|
329
|
+
script.addEventListener("error", fail, { once: true });
|
|
330
|
+
if (!previous) {
|
|
331
|
+
script.id = id;
|
|
332
|
+
script.src = new URL(ASSET_DIRECTORY + file, document.baseURI).href;
|
|
333
|
+
document.head.append(script);
|
|
334
|
+
}
|
|
335
|
+
});
|
|
336
|
+
}
|
|
337
|
+
function setEditorReadOnly(editor, isReadOnly) {
|
|
338
|
+
if (isReadOnly) editor.disabled();
|
|
339
|
+
else editor.enable();
|
|
340
|
+
}
|
|
341
|
+
function labelEditorFields(element, labelId) {
|
|
342
|
+
element.querySelectorAll("[contenteditable], textarea").forEach((field) => {
|
|
343
|
+
field.setAttribute("role", "textbox");
|
|
344
|
+
field.setAttribute("aria-labelledby", labelId);
|
|
345
|
+
field.setAttribute("aria-multiline", "true");
|
|
346
|
+
field.setAttribute("autocapitalize", "none");
|
|
347
|
+
});
|
|
348
|
+
}
|
|
349
|
+
function escapeText(text) {
|
|
350
|
+
const span = document.createElement("span");
|
|
351
|
+
span.textContent = text;
|
|
352
|
+
return span.innerHTML;
|
|
353
|
+
}
|
|
354
|
+
function plainCodePreview(html) {
|
|
355
|
+
return html.replace(/class="language-[^"]*"/g, "class=\"language-text\"");
|
|
356
|
+
}
|
|
357
|
+
function skipRawHtml() {
|
|
358
|
+
return ["", LUTE_SKIP_CHILDREN];
|
|
359
|
+
}
|
|
360
|
+
//#endregion
|
|
361
|
+
export { MarkdownEditor, renderMarkdownPreview };
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { D as WorkbasePluginUi } from "../types-C8byxPji.js";
|
|
2
|
+
import { ReactNode } from "react";
|
|
3
|
+
//#region src/ui/MarkdownLinks.dto.d.ts
|
|
4
|
+
interface MarkdownLinksProps {
|
|
5
|
+
readonly host: WorkbasePluginUi | null;
|
|
6
|
+
readonly contextKey: string;
|
|
7
|
+
readonly children: ReactNode;
|
|
8
|
+
}
|
|
9
|
+
//#endregion
|
|
10
|
+
//#region src/ui/MarkdownLinks.d.ts
|
|
11
|
+
export declare const MarkdownLinks: import("react").NamedExoticComponent<MarkdownLinksProps>;
|
|
12
|
+
//#endregion
|