@ctzhian/tiptap 2.4.2 → 2.4.4
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/EditorMarkdown/demo.js +2 -4
- package/dist/extension/component/UploadProgress/index.d.ts +1 -1
- package/dist/extension/index.d.ts +1 -1
- package/dist/extension/index.js +13 -14
- package/dist/extension/node/Emoji.js +64 -2
- package/dist/extension/node/FileHandler.d.ts +1 -1
- package/dist/extension/node/Table.d.ts +1 -1
- package/dist/extension/node/Youtube.d.ts +1 -1
- package/dist/extension/node/Youtube.js +2 -2
- package/dist/hook/index.d.ts +1 -1
- package/dist/hook/index.js +19 -50
- package/dist/index.css +8 -5
- package/dist/type/index.d.ts +43 -3
- package/package.json +1 -1
|
@@ -13,7 +13,7 @@ import { Box } from '@mui/material';
|
|
|
13
13
|
import React, { useCallback, useEffect, useState } from 'react';
|
|
14
14
|
import "../index.css";
|
|
15
15
|
var Reader = function Reader() {
|
|
16
|
-
var _useState = useState("本文用以记录 Gitlab 相关问题及解答\n\n## 我在使用 `git@git.in.chaitin.net:ns/repo` 时可以访问仓库,但是 `https://git.in.chaitin.net/ns/repo` 无法访问\n\n问题通常出现 git clone 与其他依赖 git 进行的操作,如 `go get` 等,具体报错可能为 `Permission Denied`.\n\n在使用 curl 借助 `CI_JOB_TOKEN` 获取其他仓库 cicd job 产物或者 generic package 时,其具体报错为 `404 Not Found` 的问题.\n\n原因是在使用 `git@git.in.chaitin.net` 时,使用的是 ssh 协议,此时默认使用的是 `~/.ssh` 下的私钥进行认证你在 gitlab 中添加的 `SSH Keys`。而使用 `https://git.in.chaitin.net/ns/repo` 时,使用的是 http 协议,此时默认使用的是 `~/.netrc` 认证你在 gitlab 中申请的 `Access tokens`。部分软件如 `go get` 默认使用的便是 http 来拉取代码,因此需要额外配置。\n\n这里推荐两种解决方案:\n\n1. 配置 `~/.netrc` 文件(推荐)\n\n 在 ~/.netrc 文件中添加以下配置:\n\n ```text\n machine git.in.chaitin.net login git password <your access token>\n ```\n\n 在 gitlab cicd job 中遇到拉取其他仓库时遇到权限问题可以使用本配置,比如可以在 job 的 `before_script` 阶段添加以下命令:\n\n ```shell\n echo \"machine git.in.chaitin.net login git password $CI_JOB_TOKEN\" >> ~/.netrc\n ```\n\n 注意: 其中 `$CI_JOB_TOKEN` 是 job 运行期间生成的 token,其权限与 trigger 用户相同,详见 [CI Job Token](https://docs.gitlab.com/ci/jobs/ci_job_token/)。其 Token 权限由 `pipeline 触发者`权限以及`目标仓库权限`共同决定。因此被拉取的目标仓库也需要保证其 `Setting -> CI/CD -> Job token permissions` 配置正确,允许源仓库的 CI/CD 能够访问到该仓库,否则依然会出现如 `404 Not Found`, `403 Forbidden` 的权限问题。(如果你是 pipeline 触发者,可以手动在浏览器通过 gitlab api 访问目标仓库的 generic package 或者 job artifact 如果可以正常下载,说明是 `Job token permissions` 问题)\n\n2. 配置 `git url replace`\n\n 在 ~/.gitconfig 文件中添加以下配置:\n\n ```ini\n [url \"git@git.in.chaitin.net:\"]\n insteadOf = https://git.in.chaitin.net/\n ```\n\n 这个配置可以将所有 `https://git.in.chaitin.net/` 请求替换为 `git@git.in.chaitin.net:` 使用 ssh 来拉取代码仓库\n\n## 我在 clone gitlab 仓库时没问题,但是 lfs 遇到了 EOF 问题\n\nEOF 在大多数情况下由代理导致,如果代理不允许客户端访问某个网站,行为可能是提早结束连接,导致 `EOF` 错误。如\n\n> 在 ubunu 虚拟机里无法拉取 safeline-aliyun 项目里的 lfs 文件怎么处理?\n\n```bash\nroot@OPS-5108:~/proj/safeline-aliyun# git lfs fetch --all\nfetch: 34 object(s) found, done.\nfetch: Fetching all references...\nbatch response: Post https://git.in.chaitin.net/patronus/safeline-aliyun.git/info/lfs/objects/batch: EOF\nerror: failed to fetch some objects from 'https://git.in.chaitin.net/patronus/safeline-aliyun.git/info/lfs'\n```\n\n可以看到返回了 EOF 问题,经查代理未配置在 git config 中。从 `env` 中可以看到用户配置了 *_proxy 但其中发现 `no_proxy` 配置不正确:\n\n```shell\nroot@OPS-5108:~/proj/safeline-aliyun# env | grep pro\nno_proxy=localhost, 127.0.0.1, ::1\nPWD=/root/proj/safeline-aliyun\nftp_proxy=http://proxy.in.chaitin.net:8123\nhttps_proxy=http://proxy.in.chaitin.net:8123\nproxy=http://proxy.in.chaitin.net:8123\nhttp_proxy=http://proxy.in.chaitin.net:8123\nOLDPWD=/root/proj\n```\n\n需要按照 [代理配置](https://info.chaitin.net/colab-editor/page/%E7%A0%94%E5%8F%91%E4%BD%93%E7%B3%BB%2F%E7%A0%94%E5%8F%91%E6%94%AF%E6%8C%81%2F%E4%BB%A3%E7%90%86%E6%89%AB%E7%9B%B2) 进行正确配置后,重新执行操作,发现 EOF 问题被解决。\n\n## 我在访问公司内部服务时报错 `x509: certificate signed by unknown authority`\n\n公司部分内部服务采用自签名证书,导致客户端在访问这些服务时会遇到 `x509: certificate signed by unknown authority` 错误。为了确保客户端能够信任这些自签名证书,你需要配置信任自签名证书即 CA。\n\n以 debian 系系统举例:\n\n```shell\ncurl -o /usr/local/share/ca-certificates/chaitin_ca.crt -L https://chaitin-ops-public.cn-beijing.oss.aliyuncs.com/Chaitin_Ltd_Root_CA.pem\nupdate-ca-certificates\n```\n\n如果无法访问外网,可以尝试 `http://s3-ephemeral.in.chaitin.net/dev/Chaitin_Ltd_Root_CA.pem`\n\n其他系统 CA 证书安装请参考 [安装CA证书](https://info.chaitin.net/colab-editor/page/IT%E5%8A%9E%E5%85%AC/%E5%8A%9E%E5%85%AC%E7%BD%91%E7%BB%9C/windows%E7%94%A8%E6%88%B7/%E5%A4%87%E9%80%89%E6%96%B9%E6%A1%88%EF%BC%88Windows%EF%BC%89/%E8%AF%81%E4%B9%A6%E5%AE%89%E8%A3%85%28windows%29/%E9%95%BF%E4%BA%AD%E6%A0%B9%E8%AF%81%E4%B9%A6%E5%AE%89%E8%A3%85%28windows%29)\n"),
|
|
16
|
+
var _useState = useState(":wolf:\n\n本文用以记录 Gitlab 相关问题及解答\n\n## 我在使用 `git@git.in.chaitin.net:ns/repo` 时可以访问仓库,但是 `https://git.in.chaitin.net/ns/repo` 无法访问\n\n问题通常出现 git clone 与其他依赖 git 进行的操作,如 `go get` 等,具体报错可能为 `Permission Denied`.\n\n在使用 curl 借助 `CI_JOB_TOKEN` 获取其他仓库 cicd job 产物或者 generic package 时,其具体报错为 `404 Not Found` 的问题.\n\n原因是在使用 `git@git.in.chaitin.net` 时,使用的是 ssh 协议,此时默认使用的是 `~/.ssh` 下的私钥进行认证你在 gitlab 中添加的 `SSH Keys`。而使用 `https://git.in.chaitin.net/ns/repo` 时,使用的是 http 协议,此时默认使用的是 `~/.netrc` 认证你在 gitlab 中申请的 `Access tokens`。部分软件如 `go get` 默认使用的便是 http 来拉取代码,因此需要额外配置。\n\n这里推荐两种解决方案:\n\n1. 配置 `~/.netrc` 文件(推荐)\n\n 在 ~/.netrc 文件中添加以下配置:\n\n ```text\n machine git.in.chaitin.net login git password <your access token>\n ```\n\n 在 gitlab cicd job 中遇到拉取其他仓库时遇到权限问题可以使用本配置,比如可以在 job 的 `before_script` 阶段添加以下命令:\n\n ```shell\n echo \"machine git.in.chaitin.net login git password $CI_JOB_TOKEN\" >> ~/.netrc\n ```\n\n 注意: 其中 `$CI_JOB_TOKEN` 是 job 运行期间生成的 token,其权限与 trigger 用户相同,详见 [CI Job Token](https://docs.gitlab.com/ci/jobs/ci_job_token/)。其 Token 权限由 `pipeline 触发者`权限以及`目标仓库权限`共同决定。因此被拉取的目标仓库也需要保证其 `Setting -> CI/CD -> Job token permissions` 配置正确,允许源仓库的 CI/CD 能够访问到该仓库,否则依然会出现如 `404 Not Found`, `403 Forbidden` 的权限问题。(如果你是 pipeline 触发者,可以手动在浏览器通过 gitlab api 访问目标仓库的 generic package 或者 job artifact 如果可以正常下载,说明是 `Job token permissions` 问题)\n\n2. 配置 `git url replace`\n\n 在 ~/.gitconfig 文件中添加以下配置:\n\n ```ini\n [url \"git@git.in.chaitin.net:\"]\n insteadOf = https://git.in.chaitin.net/\n ```\n\n 这个配置可以将所有 `https://git.in.chaitin.net/` 请求替换为 `git@git.in.chaitin.net:` 使用 ssh 来拉取代码仓库\n\n## 我在 clone gitlab 仓库时没问题,但是 lfs 遇到了 EOF 问题\n\nEOF 在大多数情况下由代理导致,如果代理不允许客户端访问某个网站,行为可能是提早结束连接,导致 `EOF` 错误。如\n\n> 在 ubunu 虚拟机里无法拉取 safeline-aliyun 项目里的 lfs 文件怎么处理?\n\n```bash\nroot@OPS-5108:~/proj/safeline-aliyun# git lfs fetch --all\nfetch: 34 object(s) found, done.\nfetch: Fetching all references...\nbatch response: Post https://git.in.chaitin.net/patronus/safeline-aliyun.git/info/lfs/objects/batch: EOF\nerror: failed to fetch some objects from 'https://git.in.chaitin.net/patronus/safeline-aliyun.git/info/lfs'\n```\n\n可以看到返回了 EOF 问题,经查代理未配置在 git config 中。从 `env` 中可以看到用户配置了 *_proxy 但其中发现 `no_proxy` 配置不正确:\n\n```shell\nroot@OPS-5108:~/proj/safeline-aliyun# env | grep pro\nno_proxy=localhost, 127.0.0.1, ::1\nPWD=/root/proj/safeline-aliyun\nftp_proxy=http://proxy.in.chaitin.net:8123\nhttps_proxy=http://proxy.in.chaitin.net:8123\nproxy=http://proxy.in.chaitin.net:8123\nhttp_proxy=http://proxy.in.chaitin.net:8123\nOLDPWD=/root/proj\n```\n\n需要按照 [代理配置](https://info.chaitin.net/colab-editor/page/%E7%A0%94%E5%8F%91%E4%BD%93%E7%B3%BB%2F%E7%A0%94%E5%8F%91%E6%94%AF%E6%8C%81%2F%E4%BB%A3%E7%90%86%E6%89%AB%E7%9B%B2) 进行正确配置后,重新执行操作,发现 EOF 问题被解决。\n\n## 我在访问公司内部服务时报错 `x509: certificate signed by unknown authority`\n\n公司部分内部服务采用自签名证书,导致客户端在访问这些服务时会遇到 `x509: certificate signed by unknown authority` 错误。为了确保客户端能够信任这些自签名证书,你需要配置信任自签名证书即 CA。\n\n以 debian 系系统举例:\n\n```shell\ncurl -o /usr/local/share/ca-certificates/chaitin_ca.crt -L https://chaitin-ops-public.cn-beijing.oss.aliyuncs.com/Chaitin_Ltd_Root_CA.pem\nupdate-ca-certificates\n```\n\n如果无法访问外网,可以尝试 `http://s3-ephemeral.in.chaitin.net/dev/Chaitin_Ltd_Root_CA.pem`\n\n其他系统 CA 证书安装请参考 [安装CA证书](https://info.chaitin.net/colab-editor/page/IT%E5%8A%9E%E5%85%AC/%E5%8A%9E%E5%85%AC%E7%BD%91%E7%BB%9C/windows%E7%94%A8%E6%88%B7/%E5%A4%87%E9%80%89%E6%96%B9%E6%A1%88%EF%BC%88Windows%EF%BC%89/%E8%AF%81%E4%B9%A6%E5%AE%89%E8%A3%85%28windows%29/%E9%95%BF%E4%BA%AD%E6%A0%B9%E8%AF%81%E4%B9%A6%E5%AE%89%E8%A3%85%28windows%29)\n"),
|
|
17
17
|
_useState2 = _slicedToArray(_useState, 2),
|
|
18
18
|
mdContent = _useState2[0],
|
|
19
19
|
setMdContent = _useState2[1];
|
|
@@ -157,9 +157,7 @@ var Reader = function Reader() {
|
|
|
157
157
|
editor: editor,
|
|
158
158
|
height: '500px',
|
|
159
159
|
value: mdContent,
|
|
160
|
-
splitMode: true
|
|
161
|
-
// showToolbar={false}
|
|
162
|
-
,
|
|
160
|
+
splitMode: true,
|
|
163
161
|
defaultDisplayMode: "split",
|
|
164
162
|
placeholder: "\u8BF7\u8F93\u5165\u5185\u5BB9",
|
|
165
163
|
onUpload: onUpload,
|
|
@@ -7,6 +7,6 @@ export interface UploadProgressAttributes {
|
|
|
7
7
|
tempId: string;
|
|
8
8
|
}
|
|
9
9
|
export declare const getFileIcon: (fileType: string) => React.JSX.Element;
|
|
10
|
-
export declare const getFileTypeText: (fileType: string) => "
|
|
10
|
+
export declare const getFileTypeText: (fileType: string) => "图片" | "视频" | "音频" | "文件";
|
|
11
11
|
declare const UploadProgressView: React.FC<NodeViewProps>;
|
|
12
12
|
export default UploadProgressView;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
import { GetExtensionsProps } from '../type';
|
|
2
|
-
export declare const getExtensions: ({
|
|
2
|
+
export declare const getExtensions: ({ limit, exclude, extensions: extensionsProps, editable, mentionItems, onMentionFilter, onUpload, onError, onTocUpdate, onAiWritingGetSuggestion, onValidateUrl, placeholder, youtubeOptions, tableOfContentsOptions, }: GetExtensionsProps) => any;
|
package/dist/extension/index.js
CHANGED
|
@@ -16,11 +16,9 @@ import { AiWritingExtension, ImeComposition, SlashCommands, StructuredDiffExtens
|
|
|
16
16
|
import { CodeExtension } from "./mark/Code";
|
|
17
17
|
import { AlertExtension, AudioExtension, BlockAttachmentExtension, BlockLinkExtension, CodeBlockLowlightExtension, CustomBlockMathExtension, CustomHorizontalRule, CustomInlineMathExtension, CustomSubscript, CustomSuperscript, DetailsContentExtension, DetailsExtension, DetailsSummaryExtension, EmojiExtension, FileHandlerExtension, FlowExtension, IframeExtension, ImageExtension, Indent, InlineAttachmentExtension, InlineLinkExtension, InlineUploadProgressExtension, ListExtension, MentionExtension, TableExtension, TableOfContents, UploadProgressExtension, VerticalAlign, VideoExtension, YamlFormat, YoutubeExtension } from "./node";
|
|
18
18
|
export var getExtensions = function getExtensions(_ref) {
|
|
19
|
-
var
|
|
20
|
-
limit = _ref.limit,
|
|
19
|
+
var limit = _ref.limit,
|
|
21
20
|
exclude = _ref.exclude,
|
|
22
21
|
extensionsProps = _ref.extensions,
|
|
23
|
-
youtube = _ref.youtube,
|
|
24
22
|
editable = _ref.editable,
|
|
25
23
|
mentionItems = _ref.mentionItems,
|
|
26
24
|
onMentionFilter = _ref.onMentionFilter,
|
|
@@ -30,6 +28,7 @@ export var getExtensions = function getExtensions(_ref) {
|
|
|
30
28
|
onAiWritingGetSuggestion = _ref.onAiWritingGetSuggestion,
|
|
31
29
|
onValidateUrl = _ref.onValidateUrl,
|
|
32
30
|
_placeholder = _ref.placeholder,
|
|
31
|
+
youtubeOptions = _ref.youtubeOptions,
|
|
33
32
|
tableOfContentsOptions = _ref.tableOfContentsOptions;
|
|
34
33
|
var defaultExtensions = [ImeComposition, StarterKit.configure({
|
|
35
34
|
link: false,
|
|
@@ -45,7 +44,16 @@ export var getExtensions = function getExtensions(_ref) {
|
|
|
45
44
|
color: 'var(--mui-palette-primary-main)',
|
|
46
45
|
width: 2
|
|
47
46
|
}
|
|
48
|
-
}), TextStyleKit, CodeExtension, ListExtension, EmojiExtension, AlertExtension, CustomSubscript, DetailsExtension, CustomSuperscript, DetailsContentExtension, DetailsSummaryExtension, CodeBlockLowlightExtension, InlineUploadProgressExtension,
|
|
47
|
+
}), YamlFormat, TextStyleKit, CodeExtension, ListExtension, EmojiExtension, AlertExtension, CustomSubscript, DetailsExtension, CustomSuperscript, DetailsContentExtension, DetailsSummaryExtension, CodeBlockLowlightExtension, InlineUploadProgressExtension, CustomHorizontalRule].concat(_toConsumableArray(TableExtension({
|
|
48
|
+
editable: editable
|
|
49
|
+
})), [CustomBlockMathExtension({
|
|
50
|
+
onError: onError
|
|
51
|
+
}), CustomInlineMathExtension({
|
|
52
|
+
onError: onError
|
|
53
|
+
}), TableOfContents({
|
|
54
|
+
onTocUpdate: onTocUpdate,
|
|
55
|
+
tableOfContentsOptions: tableOfContentsOptions
|
|
56
|
+
}), InlineLinkExtension, BlockLinkExtension, IframeExtension({
|
|
49
57
|
onError: onError,
|
|
50
58
|
onValidateUrl: onValidateUrl
|
|
51
59
|
}), VideoExtension({
|
|
@@ -56,19 +64,10 @@ export var getExtensions = function getExtensions(_ref) {
|
|
|
56
64
|
onUpload: onUpload,
|
|
57
65
|
onError: onError,
|
|
58
66
|
onValidateUrl: onValidateUrl
|
|
59
|
-
})].concat(_toConsumableArray(TableExtension({
|
|
60
|
-
editable: editable
|
|
61
|
-
})), [TableOfContents({
|
|
62
|
-
onTocUpdate: onTocUpdate,
|
|
63
|
-
tableOfContentsOptions: tableOfContentsOptions
|
|
64
67
|
}), ImageExtension({
|
|
65
68
|
onUpload: onUpload,
|
|
66
69
|
onError: onError,
|
|
67
70
|
onValidateUrl: onValidateUrl
|
|
68
|
-
}), CustomBlockMathExtension({
|
|
69
|
-
onError: onError
|
|
70
|
-
}), CustomInlineMathExtension({
|
|
71
|
-
onError: onError
|
|
72
71
|
}), InlineAttachmentExtension({
|
|
73
72
|
onUpload: onUpload,
|
|
74
73
|
onError: onError
|
|
@@ -163,7 +162,7 @@ export var getExtensions = function getExtensions(_ref) {
|
|
|
163
162
|
defaultExtensions.push(Mention);
|
|
164
163
|
}
|
|
165
164
|
if (!(exclude !== null && exclude !== void 0 && exclude.includes('youtube'))) {
|
|
166
|
-
var Youtube = YoutubeExtension(
|
|
165
|
+
var Youtube = YoutubeExtension(youtubeOptions);
|
|
167
166
|
defaultExtensions.push(Youtube);
|
|
168
167
|
}
|
|
169
168
|
if (!(exclude !== null && exclude !== void 0 && exclude.includes('flow'))) {
|
|
@@ -1,6 +1,68 @@
|
|
|
1
|
-
import Emoji, { gitHubEmojis } from "@tiptap/extension-emoji";
|
|
1
|
+
import Emoji, { emojiToShortcode, gitHubEmojis, shortcodeToEmoji } from "@tiptap/extension-emoji";
|
|
2
2
|
import { emojiSuggestion } from "../suggestion/emoji";
|
|
3
|
-
|
|
3
|
+
var EMOJI_SHORTCODE_REGEX = /^:([a-zA-Z0-9_+-]+):/;
|
|
4
|
+
function extractEmojiName(token) {
|
|
5
|
+
if (token.name) {
|
|
6
|
+
return token.name;
|
|
7
|
+
}
|
|
8
|
+
if (token.shortcode) {
|
|
9
|
+
var emojiItem = shortcodeToEmoji(token.shortcode, gitHubEmojis);
|
|
10
|
+
if (emojiItem) {
|
|
11
|
+
return emojiItem.name;
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
if (typeof token.markup === 'string' && token.markup.startsWith(':') && token.markup.endsWith(':')) {
|
|
15
|
+
var shortcode = token.markup.slice(1, -1);
|
|
16
|
+
var _emojiItem = shortcodeToEmoji(shortcode, gitHubEmojis);
|
|
17
|
+
if (_emojiItem) {
|
|
18
|
+
return _emojiItem.name;
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
if (typeof token.emoji === 'string' && token.emoji) {
|
|
22
|
+
var _shortcode = emojiToShortcode(token.emoji, gitHubEmojis);
|
|
23
|
+
if (_shortcode) {
|
|
24
|
+
return _shortcode;
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
return null;
|
|
28
|
+
}
|
|
29
|
+
export var EmojiExtension = Emoji.extend({
|
|
30
|
+
markdownTokenName: 'emoji',
|
|
31
|
+
markdownTokenizer: {
|
|
32
|
+
name: 'emoji',
|
|
33
|
+
level: 'inline',
|
|
34
|
+
start: function start(src) {
|
|
35
|
+
return src.indexOf(':');
|
|
36
|
+
},
|
|
37
|
+
tokenize: function tokenize(src, _tokens, helpers) {
|
|
38
|
+
var match = EMOJI_SHORTCODE_REGEX.exec(src);
|
|
39
|
+
if (!match) {
|
|
40
|
+
return;
|
|
41
|
+
}
|
|
42
|
+
var shortcode = match[1];
|
|
43
|
+
var emojiItem = shortcodeToEmoji(shortcode, gitHubEmojis);
|
|
44
|
+
if (!emojiItem) {
|
|
45
|
+
return;
|
|
46
|
+
}
|
|
47
|
+
return {
|
|
48
|
+
type: 'emoji',
|
|
49
|
+
raw: match[0],
|
|
50
|
+
name: emojiItem.name,
|
|
51
|
+
shortcode: shortcode,
|
|
52
|
+
emoji: emojiItem.emoji || ''
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
},
|
|
56
|
+
parseMarkdown: function parseMarkdown(token, helpers) {
|
|
57
|
+
var name = extractEmojiName(token);
|
|
58
|
+
if (!name) {
|
|
59
|
+
return [];
|
|
60
|
+
}
|
|
61
|
+
return helpers.createNode('emoji', {
|
|
62
|
+
name: name
|
|
63
|
+
});
|
|
64
|
+
}
|
|
65
|
+
}).configure({
|
|
4
66
|
emojis: gitHubEmojis,
|
|
5
67
|
enableEmoticons: true,
|
|
6
68
|
suggestion: emojiSuggestion
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import { UploadFunction } from "../../type";
|
|
2
2
|
export declare const FileHandlerExtension: (props: {
|
|
3
3
|
onUpload?: UploadFunction;
|
|
4
|
-
}) => import("@tiptap/core").Extension<Omit<import("@tiptap/extension-file-handler").FileHandlePluginOptions, "
|
|
4
|
+
}) => import("@tiptap/core").Extension<Omit<import("@tiptap/extension-file-handler").FileHandlePluginOptions, "editor" | "key">, any>;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Extension } from '@tiptap/core';
|
|
2
2
|
export declare const TableExtension: ({ editable }: {
|
|
3
3
|
editable: boolean;
|
|
4
|
-
}) => (import("@tiptap/core").Node<import("@tiptap/extension-table").TableOptions, any> | import("@tiptap/core").Node<import("@tiptap/extension-table").TableHeaderOptions, any>
|
|
4
|
+
}) => (Extension<any, any> | import("@tiptap/core").Node<import("@tiptap/extension-table").TableOptions, any> | import("@tiptap/core").Node<import("@tiptap/extension-table").TableHeaderOptions, any>)[];
|
|
5
5
|
export default TableExtension;
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import { YoutubeOptions } from "@tiptap/extension-youtube";
|
|
2
|
-
export declare const YoutubeExtension: (
|
|
2
|
+
export declare const YoutubeExtension: (youtubeOptions?: Partial<YoutubeOptions>) => import("@tiptap/core").Node<YoutubeOptions, any>;
|
|
3
3
|
export default YoutubeExtension;
|
|
@@ -5,10 +5,10 @@ function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key i
|
|
|
5
5
|
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
|
|
6
6
|
function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
|
|
7
7
|
import Youtube from "@tiptap/extension-youtube";
|
|
8
|
-
export var YoutubeExtension = function YoutubeExtension(
|
|
8
|
+
export var YoutubeExtension = function YoutubeExtension(youtubeOptions) {
|
|
9
9
|
return Youtube.configure(_objectSpread({
|
|
10
10
|
ccLanguage: 'zh-CN',
|
|
11
11
|
nocookie: true
|
|
12
|
-
},
|
|
12
|
+
}, youtubeOptions));
|
|
13
13
|
};
|
|
14
14
|
export default YoutubeExtension;
|
package/dist/hook/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import { UseTiptapProps, UseTiptapReturn } from "../type";
|
|
2
2
|
import { UseEditorOptions } from '@tiptap/react';
|
|
3
|
-
declare const useTiptap: ({
|
|
3
|
+
declare const useTiptap: ({ editable, contentType, onSave, onError, ...options }: UseTiptapProps & UseEditorOptions) => UseTiptapReturn;
|
|
4
4
|
export default useTiptap;
|
package/dist/hook/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
|
|
2
|
-
var _excluded = ["
|
|
2
|
+
var _excluded = ["editable", "contentType", "onSave", "onError"];
|
|
3
3
|
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
4
4
|
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
5
5
|
function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
@@ -11,37 +11,17 @@ import { getExtensions } from "../extension";
|
|
|
11
11
|
import { migrateMathStrings } from '@tiptap/extension-mathematics';
|
|
12
12
|
import { useEditor } from '@tiptap/react';
|
|
13
13
|
var useTiptap = function useTiptap(_ref) {
|
|
14
|
-
var
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
14
|
+
var _ref$editable = _ref.editable,
|
|
15
|
+
editable = _ref$editable === void 0 ? true : _ref$editable,
|
|
16
|
+
_ref$contentType = _ref.contentType,
|
|
17
|
+
contentType = _ref$contentType === void 0 ? 'html' : _ref$contentType,
|
|
18
18
|
onSave = _ref.onSave,
|
|
19
19
|
onError = _ref.onError,
|
|
20
|
-
onUpload = _ref.onUpload,
|
|
21
|
-
onTocUpdate = _ref.onTocUpdate,
|
|
22
|
-
onAiWritingGetSuggestion = _ref.onAiWritingGetSuggestion,
|
|
23
|
-
onValidateUrl = _ref.onValidateUrl,
|
|
24
|
-
_ref$editable = _ref.editable,
|
|
25
|
-
editable = _ref$editable === void 0 ? true : _ref$editable,
|
|
26
|
-
contentType = _ref.contentType,
|
|
27
|
-
placeholder = _ref.placeholder,
|
|
28
|
-
tableOfContentsOptions = _ref.tableOfContentsOptions,
|
|
29
20
|
options = _objectWithoutProperties(_ref, _excluded);
|
|
30
|
-
var extensions = getExtensions({
|
|
31
|
-
contentType: contentType,
|
|
32
|
-
exclude: exclude,
|
|
33
|
-
extensions: extensionsProps,
|
|
21
|
+
var extensions = getExtensions(_objectSpread({
|
|
34
22
|
editable: editable,
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
onUpload: onUpload,
|
|
38
|
-
onError: onError,
|
|
39
|
-
onTocUpdate: onTocUpdate,
|
|
40
|
-
onAiWritingGetSuggestion: onAiWritingGetSuggestion,
|
|
41
|
-
onValidateUrl: onValidateUrl,
|
|
42
|
-
placeholder: placeholder,
|
|
43
|
-
tableOfContentsOptions: tableOfContentsOptions
|
|
44
|
-
});
|
|
23
|
+
onError: onError
|
|
24
|
+
}, options));
|
|
45
25
|
var editor = useEditor(_objectSpread(_objectSpread(_objectSpread({
|
|
46
26
|
editable: editable,
|
|
47
27
|
extensions: extensions
|
|
@@ -50,16 +30,13 @@ var useTiptap = function useTiptap(_ref) {
|
|
|
50
30
|
} : {}), options), {}, {
|
|
51
31
|
editorProps: {
|
|
52
32
|
handleKeyDown: function handleKeyDown(view, event) {
|
|
53
|
-
|
|
54
|
-
if (event.key === 's' && (event.metaKey || event.ctrlKey) && editable && onSave) {
|
|
33
|
+
if (editable && event.key === 's' && (event.metaKey || event.ctrlKey) && onSave) {
|
|
55
34
|
event.preventDefault();
|
|
56
35
|
onSave === null || onSave === void 0 || onSave(editor);
|
|
57
36
|
return true;
|
|
58
37
|
}
|
|
59
|
-
// tab
|
|
60
38
|
if (event.key === 'Tab') {
|
|
61
39
|
var _storage;
|
|
62
|
-
// 若开启了 aiWriting,则放行给扩展处理(Tab 接受建议),不再插入制表符
|
|
63
40
|
var aiWritingEnabled = !!(editor !== null && editor !== void 0 && (_storage = editor.storage) !== null && _storage !== void 0 && (_storage = _storage.aiWriting) !== null && _storage !== void 0 && _storage.enabled);
|
|
64
41
|
if (aiWritingEnabled) {
|
|
65
42
|
return false;
|
|
@@ -81,7 +58,6 @@ var useTiptap = function useTiptap(_ref) {
|
|
|
81
58
|
(_options$onCreate = options.onCreate) === null || _options$onCreate === void 0 || _options$onCreate.call(options, {
|
|
82
59
|
editor: currentEditor
|
|
83
60
|
});
|
|
84
|
-
// 处理数学公式 - 延迟执行确保文档完全准备好
|
|
85
61
|
setTimeout(function () {
|
|
86
62
|
try {
|
|
87
63
|
migrateMathStrings(currentEditor);
|
|
@@ -90,26 +66,16 @@ var useTiptap = function useTiptap(_ref) {
|
|
|
90
66
|
onError === null || onError === void 0 || onError(error);
|
|
91
67
|
}
|
|
92
68
|
}, 100);
|
|
93
|
-
},
|
|
94
|
-
onSelectionUpdate: function onSelectionUpdate(props) {
|
|
95
|
-
if (options.onSelectionUpdate) {
|
|
96
|
-
options.onSelectionUpdate(props);
|
|
97
|
-
}
|
|
98
|
-
},
|
|
99
|
-
onContentError: function onContentError(props) {
|
|
100
|
-
if (options.onContentError) {
|
|
101
|
-
options.onContentError(props);
|
|
102
|
-
}
|
|
103
|
-
onError === null || onError === void 0 || onError(props.error);
|
|
104
69
|
}
|
|
105
70
|
}));
|
|
106
71
|
return {
|
|
107
72
|
editor: editor,
|
|
108
73
|
setContent: function setContent(value, type) {
|
|
109
|
-
var _editor$chain;
|
|
110
|
-
|
|
74
|
+
var _editor$chain$focus$s;
|
|
75
|
+
if (!editor) return;
|
|
76
|
+
(_editor$chain$focus$s = editor.chain().focus().setContent(value, {
|
|
111
77
|
contentType: type || (contentType === 'markdown' ? 'markdown' : 'html')
|
|
112
|
-
})) === null || _editor$chain === void 0 || _editor$chain.run();
|
|
78
|
+
})) === null || _editor$chain$focus$s === void 0 || _editor$chain$focus$s.run();
|
|
113
79
|
},
|
|
114
80
|
getContent: function getContent() {
|
|
115
81
|
if (!editor) return '';
|
|
@@ -123,13 +89,16 @@ var useTiptap = function useTiptap(_ref) {
|
|
|
123
89
|
return editor.getMarkdown();
|
|
124
90
|
},
|
|
125
91
|
getText: function getText() {
|
|
126
|
-
|
|
92
|
+
if (!editor) return '';
|
|
93
|
+
return editor.getText() || '';
|
|
127
94
|
},
|
|
128
95
|
getHTML: function getHTML() {
|
|
129
|
-
|
|
96
|
+
if (!editor) return '';
|
|
97
|
+
return editor.getHTML() || '';
|
|
130
98
|
},
|
|
131
99
|
getJSON: function getJSON() {
|
|
132
|
-
|
|
100
|
+
if (!editor) return null;
|
|
101
|
+
return editor.getJSON() || null;
|
|
133
102
|
}
|
|
134
103
|
};
|
|
135
104
|
};
|
package/dist/index.css
CHANGED
|
@@ -4,6 +4,9 @@
|
|
|
4
4
|
--common-row-font-size: 16px;
|
|
5
5
|
--common-row-line-height: 1.625;
|
|
6
6
|
--udtoken-quote-bar-bg: #bbbfc4;
|
|
7
|
+
|
|
8
|
+
--table-head-background-color: #f2f3f5;
|
|
9
|
+
--table-cell-border-color: #dee0e3;
|
|
7
10
|
}
|
|
8
11
|
|
|
9
12
|
.tiptap.ProseMirror {
|
|
@@ -359,7 +362,7 @@
|
|
|
359
362
|
table-layout: fixed;
|
|
360
363
|
overflow: hidden;
|
|
361
364
|
caption-side: top;
|
|
362
|
-
border-left: 1px dotted var(--mui-palette-table-cell-border);
|
|
365
|
+
border-left: 1px dotted var(--mui-palette-table-cell-border, --table-cell-border-color);
|
|
363
366
|
}
|
|
364
367
|
|
|
365
368
|
.tiptap.ProseMirror table p {
|
|
@@ -374,8 +377,8 @@
|
|
|
374
377
|
.tiptap.ProseMirror table td,
|
|
375
378
|
.tiptap.ProseMirror table th {
|
|
376
379
|
border: none;
|
|
377
|
-
border-bottom: 1px solid var(--mui-palette-table-cell-border);
|
|
378
|
-
border-right: 1px dotted var(--mui-palette-table-cell-border);
|
|
380
|
+
border-bottom: 1px solid var(--mui-palette-table-cell-border, --table-cell-border-color);
|
|
381
|
+
border-right: 1px dotted var(--mui-palette-table-cell-border, --table-cell-border-color);
|
|
379
382
|
box-sizing: border-box;
|
|
380
383
|
padding: 12px 16px;
|
|
381
384
|
position: relative;
|
|
@@ -386,7 +389,7 @@
|
|
|
386
389
|
|
|
387
390
|
.tiptap.ProseMirror table tbody tr:first-child th,
|
|
388
391
|
.tiptap.ProseMirror table tbody tr:first-child td {
|
|
389
|
-
border-top: 1px solid var(--mui-palette-table-cell-border);
|
|
392
|
+
border-top: 1px solid var(--mui-palette-table-cell-border, --table-cell-border-color);
|
|
390
393
|
}
|
|
391
394
|
|
|
392
395
|
.tiptap.ProseMirror table td>*,
|
|
@@ -399,7 +402,7 @@
|
|
|
399
402
|
text-transform: uppercase;
|
|
400
403
|
letter-spacing: 0.5px;
|
|
401
404
|
text-align: left;
|
|
402
|
-
background-color: var(--mui-palette-table-head-background);
|
|
405
|
+
background-color: var(--mui-palette-table-head-background, --table-head-background-color);
|
|
403
406
|
}
|
|
404
407
|
|
|
405
408
|
.tiptap.ProseMirror[contenteditable="true"] table .selectedCell * {
|
package/dist/type/index.d.ts
CHANGED
|
@@ -76,13 +76,28 @@ export type TocItem = {
|
|
|
76
76
|
export type TocList = TocItem[];
|
|
77
77
|
export type ValidateUrlFunction = (url: string, type: 'image' | 'video' | 'audio' | 'iframe') => Promise<string> | string;
|
|
78
78
|
export type EditorFnProps = {
|
|
79
|
+
/**
|
|
80
|
+
* 错误处理
|
|
81
|
+
*/
|
|
79
82
|
onError?: (error: Error) => void;
|
|
83
|
+
/**
|
|
84
|
+
* 上传处理
|
|
85
|
+
*/
|
|
80
86
|
onUpload?: UploadFunction;
|
|
87
|
+
/**
|
|
88
|
+
* 目录更新
|
|
89
|
+
*/
|
|
81
90
|
onTocUpdate?: (toc: TocList) => void;
|
|
91
|
+
/**
|
|
92
|
+
* AI 写作建议
|
|
93
|
+
*/
|
|
82
94
|
onAiWritingGetSuggestion?: ({ prefix, suffix }: {
|
|
83
95
|
prefix: string;
|
|
84
96
|
suffix: string;
|
|
85
97
|
}) => Promise<string>;
|
|
98
|
+
/**
|
|
99
|
+
* 验证 URL
|
|
100
|
+
*/
|
|
86
101
|
onValidateUrl?: ValidateUrlFunction;
|
|
87
102
|
};
|
|
88
103
|
export type MentionItems = string[];
|
|
@@ -92,16 +107,41 @@ export type MentionExtensionProps = {
|
|
|
92
107
|
query: string;
|
|
93
108
|
}) => Promise<MentionItems>;
|
|
94
109
|
};
|
|
95
|
-
export type
|
|
110
|
+
export type NodeOrMetaOrSuggestionOrExtensionOptions = {
|
|
111
|
+
youtubeOptions?: Partial<YoutubeOptions>;
|
|
112
|
+
tableOfContentsOptions?: Partial<TableOfContentsOptions>;
|
|
113
|
+
};
|
|
114
|
+
export type BaseExtensionOptions = {
|
|
115
|
+
/**
|
|
116
|
+
* 字数限制
|
|
117
|
+
*/
|
|
96
118
|
limit?: number | null;
|
|
119
|
+
/**
|
|
120
|
+
* 排除的扩展
|
|
121
|
+
*/
|
|
97
122
|
exclude?: string[];
|
|
123
|
+
/**
|
|
124
|
+
* 扩展
|
|
125
|
+
* @default []
|
|
126
|
+
*/
|
|
98
127
|
extensions?: Extension[];
|
|
128
|
+
/**
|
|
129
|
+
* 是否可编辑
|
|
130
|
+
* @default true
|
|
131
|
+
*/
|
|
99
132
|
editable: boolean;
|
|
100
|
-
|
|
133
|
+
/**
|
|
134
|
+
* 内容类型
|
|
135
|
+
* @default 'html'
|
|
136
|
+
* @description 支持 'html' 和 'markdown' 和 'json'
|
|
137
|
+
*/
|
|
101
138
|
contentType?: UseEditorOptions['contentType'];
|
|
139
|
+
/**
|
|
140
|
+
* 占位符
|
|
141
|
+
*/
|
|
102
142
|
placeholder?: string;
|
|
103
|
-
tableOfContentsOptions?: TableOfContentsOptions;
|
|
104
143
|
};
|
|
144
|
+
export type ExtensionRelativeProps = MentionExtensionProps & NodeOrMetaOrSuggestionOrExtensionOptions & EditorFnProps & BaseExtensionOptions;
|
|
105
145
|
export type UseTiptapProps = {
|
|
106
146
|
onSave?: (editor: Editor) => void;
|
|
107
147
|
} & ExtensionRelativeProps;
|