@ctzhian/tiptap 2.4.4 → 2.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/dist/extension/index.d.ts +1 -1
- package/dist/extension/index.js +7 -0
- package/dist/extension/node/Attachment.d.ts +5 -2
- package/dist/extension/node/Attachment.js +12 -28
- package/dist/extension/node/Audio.d.ts +3 -1
- package/dist/extension/node/Audio.js +3 -2
- package/dist/extension/node/Image.d.ts +3 -1
- package/dist/extension/node/Image.js +18 -1
- package/dist/extension/node/Video.d.ts +3 -1
- package/dist/extension/node/Video.js +3 -3
- package/dist/hook/index.d.ts +1 -1
- package/dist/hook/index.js +13 -2
- package/dist/type/index.d.ts +4 -0
- package/dist/util/index.d.ts +2 -0
- package/dist/util/index.js +38 -0
- package/package.json +1 -1
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
import { GetExtensionsProps } from '../type';
|
|
2
|
-
export declare const getExtensions: ({ limit, exclude, extensions: extensionsProps, editable, mentionItems, onMentionFilter, onUpload, onError, onTocUpdate, onAiWritingGetSuggestion, onValidateUrl, placeholder, youtubeOptions, tableOfContentsOptions, }: GetExtensionsProps) => any;
|
|
2
|
+
export declare const getExtensions: ({ limit, exclude, extensions: extensionsProps, editable, mentionItems, baseUrl, onMentionFilter, onUpload, onError, onTocUpdate, onAiWritingGetSuggestion, onValidateUrl, placeholder, youtubeOptions, tableOfContentsOptions, }: GetExtensionsProps) => any;
|
package/dist/extension/index.js
CHANGED
|
@@ -21,6 +21,8 @@ export var getExtensions = function getExtensions(_ref) {
|
|
|
21
21
|
extensionsProps = _ref.extensions,
|
|
22
22
|
editable = _ref.editable,
|
|
23
23
|
mentionItems = _ref.mentionItems,
|
|
24
|
+
_ref$baseUrl = _ref.baseUrl,
|
|
25
|
+
baseUrl = _ref$baseUrl === void 0 ? '' : _ref$baseUrl,
|
|
24
26
|
onMentionFilter = _ref.onMentionFilter,
|
|
25
27
|
onUpload = _ref.onUpload,
|
|
26
28
|
onError = _ref.onError,
|
|
@@ -57,21 +59,26 @@ export var getExtensions = function getExtensions(_ref) {
|
|
|
57
59
|
onError: onError,
|
|
58
60
|
onValidateUrl: onValidateUrl
|
|
59
61
|
}), VideoExtension({
|
|
62
|
+
baseUrl: baseUrl,
|
|
60
63
|
onUpload: onUpload,
|
|
61
64
|
onError: onError,
|
|
62
65
|
onValidateUrl: onValidateUrl
|
|
63
66
|
}), AudioExtension({
|
|
67
|
+
baseUrl: baseUrl,
|
|
64
68
|
onUpload: onUpload,
|
|
65
69
|
onError: onError,
|
|
66
70
|
onValidateUrl: onValidateUrl
|
|
67
71
|
}), ImageExtension({
|
|
72
|
+
baseUrl: baseUrl,
|
|
68
73
|
onUpload: onUpload,
|
|
69
74
|
onError: onError,
|
|
70
75
|
onValidateUrl: onValidateUrl
|
|
71
76
|
}), InlineAttachmentExtension({
|
|
77
|
+
baseUrl: baseUrl,
|
|
72
78
|
onUpload: onUpload,
|
|
73
79
|
onError: onError
|
|
74
80
|
}), BlockAttachmentExtension({
|
|
81
|
+
baseUrl: baseUrl,
|
|
75
82
|
onUpload: onUpload,
|
|
76
83
|
onError: onError
|
|
77
84
|
}), Highlight.configure({
|
|
@@ -24,5 +24,8 @@ declare module '@tiptap/core' {
|
|
|
24
24
|
};
|
|
25
25
|
}
|
|
26
26
|
}
|
|
27
|
-
export
|
|
28
|
-
|
|
27
|
+
export type AttachmentExtensionProps = EditorFnProps & {
|
|
28
|
+
baseUrl: string;
|
|
29
|
+
};
|
|
30
|
+
export declare const InlineAttachmentExtension: (props: AttachmentExtensionProps) => Node<any, any>;
|
|
31
|
+
export declare const BlockAttachmentExtension: (props: AttachmentExtensionProps) => Node<any, any>;
|
|
@@ -4,6 +4,7 @@ function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t =
|
|
|
4
4
|
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; }
|
|
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
|
+
import { removeBaseUrl, withBaseUrl } from "../../util";
|
|
7
8
|
import { mergeAttributes, Node } from "@tiptap/core";
|
|
8
9
|
import { ReactNodeViewRenderer } from "@tiptap/react";
|
|
9
10
|
import AttachmentViewWrapper from "../component/Attachment";
|
|
@@ -16,30 +17,21 @@ export var InlineAttachmentExtension = function InlineAttachmentExtension(props)
|
|
|
16
17
|
atom: true,
|
|
17
18
|
draggable: true,
|
|
18
19
|
selectable: true,
|
|
19
|
-
addOptions: function addOptions() {
|
|
20
|
-
return {
|
|
21
|
-
HTMLAttributes: {
|
|
22
|
-
url: '',
|
|
23
|
-
title: '',
|
|
24
|
-
size: '0'
|
|
25
|
-
}
|
|
26
|
-
};
|
|
27
|
-
},
|
|
28
20
|
addAttributes: function addAttributes() {
|
|
29
21
|
return {
|
|
30
22
|
url: {
|
|
31
|
-
default:
|
|
23
|
+
default: '',
|
|
32
24
|
parseHTML: function parseHTML(element) {
|
|
33
|
-
return element.getAttribute('data-url');
|
|
25
|
+
return withBaseUrl(element.getAttribute('data-url') || '', props.baseUrl);
|
|
34
26
|
},
|
|
35
27
|
renderHTML: function renderHTML(attributes) {
|
|
36
28
|
return {
|
|
37
|
-
'data-url': attributes.url
|
|
29
|
+
'data-url': removeBaseUrl(attributes.url, props.baseUrl)
|
|
38
30
|
};
|
|
39
31
|
}
|
|
40
32
|
},
|
|
41
33
|
title: {
|
|
42
|
-
default:
|
|
34
|
+
default: '',
|
|
43
35
|
parseHTML: function parseHTML(element) {
|
|
44
36
|
return element.getAttribute('data-title');
|
|
45
37
|
},
|
|
@@ -50,7 +42,7 @@ export var InlineAttachmentExtension = function InlineAttachmentExtension(props)
|
|
|
50
42
|
}
|
|
51
43
|
},
|
|
52
44
|
size: {
|
|
53
|
-
default:
|
|
45
|
+
default: '0',
|
|
54
46
|
parseHTML: function parseHTML(element) {
|
|
55
47
|
return element.getAttribute('data-size') || '0';
|
|
56
48
|
},
|
|
@@ -157,30 +149,22 @@ export var BlockAttachmentExtension = function BlockAttachmentExtension(props) {
|
|
|
157
149
|
atom: true,
|
|
158
150
|
draggable: true,
|
|
159
151
|
selectable: true,
|
|
160
|
-
addOptions: function addOptions() {
|
|
161
|
-
return {
|
|
162
|
-
HTMLAttributes: {
|
|
163
|
-
url: '',
|
|
164
|
-
title: '',
|
|
165
|
-
size: '0'
|
|
166
|
-
}
|
|
167
|
-
};
|
|
168
|
-
},
|
|
169
152
|
addAttributes: function addAttributes() {
|
|
170
153
|
return {
|
|
171
154
|
url: {
|
|
172
|
-
default:
|
|
155
|
+
default: '',
|
|
173
156
|
parseHTML: function parseHTML(element) {
|
|
174
|
-
return element.getAttribute('data-url');
|
|
157
|
+
return withBaseUrl(element.getAttribute('data-url') || '', props.baseUrl);
|
|
175
158
|
},
|
|
176
159
|
renderHTML: function renderHTML(attributes) {
|
|
160
|
+
if (!attributes.url) return {};
|
|
177
161
|
return {
|
|
178
|
-
'data-url': attributes.url
|
|
162
|
+
'data-url': removeBaseUrl(attributes.url, props.baseUrl)
|
|
179
163
|
};
|
|
180
164
|
}
|
|
181
165
|
},
|
|
182
166
|
title: {
|
|
183
|
-
default:
|
|
167
|
+
default: '',
|
|
184
168
|
parseHTML: function parseHTML(element) {
|
|
185
169
|
return element.getAttribute('data-title');
|
|
186
170
|
},
|
|
@@ -191,7 +175,7 @@ export var BlockAttachmentExtension = function BlockAttachmentExtension(props) {
|
|
|
191
175
|
}
|
|
192
176
|
},
|
|
193
177
|
size: {
|
|
194
|
-
default:
|
|
178
|
+
default: '0',
|
|
195
179
|
parseHTML: function parseHTML(element) {
|
|
196
180
|
return element.getAttribute('data-size') || '0';
|
|
197
181
|
},
|
|
@@ -18,6 +18,8 @@ declare module '@tiptap/core' {
|
|
|
18
18
|
};
|
|
19
19
|
}
|
|
20
20
|
}
|
|
21
|
-
export type AudioExtensionProps = EditorFnProps
|
|
21
|
+
export type AudioExtensionProps = EditorFnProps & {
|
|
22
|
+
baseUrl: string;
|
|
23
|
+
};
|
|
22
24
|
export declare const AudioExtension: (props: AudioExtensionProps) => Node<any, any>;
|
|
23
25
|
export default AudioExtension;
|
|
@@ -4,6 +4,7 @@ function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t =
|
|
|
4
4
|
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; }
|
|
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
|
+
import { removeBaseUrl, withBaseUrl } from "../../util";
|
|
7
8
|
import { InputRule, mergeAttributes, Node } from '@tiptap/core';
|
|
8
9
|
import { ReactNodeViewRenderer } from '@tiptap/react';
|
|
9
10
|
import AudioViewWrapper from "../component/Audio";
|
|
@@ -31,12 +32,12 @@ export var AudioExtension = function AudioExtension(props) {
|
|
|
31
32
|
src: {
|
|
32
33
|
default: null,
|
|
33
34
|
parseHTML: function parseHTML(element) {
|
|
34
|
-
return element.getAttribute('src');
|
|
35
|
+
return withBaseUrl(element.getAttribute('src') || '', props.baseUrl);
|
|
35
36
|
},
|
|
36
37
|
renderHTML: function renderHTML(attributes) {
|
|
37
38
|
if (!attributes.src) return {};
|
|
38
39
|
return {
|
|
39
|
-
src: attributes.src
|
|
40
|
+
src: removeBaseUrl(attributes.src, props.baseUrl)
|
|
40
41
|
};
|
|
41
42
|
}
|
|
42
43
|
},
|
|
@@ -1,3 +1,5 @@
|
|
|
1
1
|
import { EditorFnProps } from "../../type";
|
|
2
|
-
export type ImageExtensionProps = EditorFnProps
|
|
2
|
+
export type ImageExtensionProps = EditorFnProps & {
|
|
3
|
+
baseUrl: string;
|
|
4
|
+
};
|
|
3
5
|
export declare const ImageExtension: (props: ImageExtensionProps) => import("@tiptap/core").Node<import("@tiptap/extension-image").ImageOptions, any>;
|
|
@@ -7,13 +7,30 @@ function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t =
|
|
|
7
7
|
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; }
|
|
8
8
|
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
|
|
9
9
|
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); }
|
|
10
|
-
import { getFileType } from "../../util";
|
|
10
|
+
import { getFileType, removeBaseUrl, withBaseUrl } from "../../util";
|
|
11
11
|
import Image from "@tiptap/extension-image";
|
|
12
12
|
import { Plugin, PluginKey } from "@tiptap/pm/state";
|
|
13
13
|
import { ReactNodeViewRenderer } from "@tiptap/react";
|
|
14
14
|
import ImageViewWrapper, { getImageDimensionsFromFile } from "../component/Image";
|
|
15
15
|
var customImage = function customImage(props) {
|
|
16
16
|
return Image.extend({
|
|
17
|
+
addAttributes: function addAttributes() {
|
|
18
|
+
var _this$parent;
|
|
19
|
+
return _objectSpread(_objectSpread({}, (_this$parent = this.parent) === null || _this$parent === void 0 ? void 0 : _this$parent.call(this)), {}, {
|
|
20
|
+
src: {
|
|
21
|
+
default: null,
|
|
22
|
+
parseHTML: function parseHTML(element) {
|
|
23
|
+
return withBaseUrl(element.getAttribute('src') || '', props.baseUrl);
|
|
24
|
+
},
|
|
25
|
+
renderHTML: function renderHTML(attributes) {
|
|
26
|
+
if (!attributes.src) return {};
|
|
27
|
+
return {
|
|
28
|
+
src: removeBaseUrl(attributes.src, props.baseUrl)
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
});
|
|
33
|
+
},
|
|
17
34
|
addKeyboardShortcuts: function addKeyboardShortcuts() {
|
|
18
35
|
var _this = this;
|
|
19
36
|
return {
|
|
@@ -19,6 +19,8 @@ declare module '@tiptap/core' {
|
|
|
19
19
|
};
|
|
20
20
|
}
|
|
21
21
|
}
|
|
22
|
-
export type VideoExtensionProps = EditorFnProps
|
|
22
|
+
export type VideoExtensionProps = EditorFnProps & {
|
|
23
|
+
baseUrl: string;
|
|
24
|
+
};
|
|
23
25
|
export declare const VideoExtension: (props: VideoExtensionProps) => Node<any, any>;
|
|
24
26
|
export default VideoExtension;
|
|
@@ -7,7 +7,7 @@ function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t =
|
|
|
7
7
|
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; }
|
|
8
8
|
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
|
|
9
9
|
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); }
|
|
10
|
-
import { getFileType } from "../../util";
|
|
10
|
+
import { getFileType, removeBaseUrl, withBaseUrl } from "../../util";
|
|
11
11
|
import { InputRule, mergeAttributes, Node } from '@tiptap/core';
|
|
12
12
|
import { Plugin, PluginKey } from '@tiptap/pm/state';
|
|
13
13
|
import { ReactNodeViewRenderer } from '@tiptap/react';
|
|
@@ -37,12 +37,12 @@ export var VideoExtension = function VideoExtension(props) {
|
|
|
37
37
|
src: {
|
|
38
38
|
default: null,
|
|
39
39
|
parseHTML: function parseHTML(element) {
|
|
40
|
-
return element.getAttribute('src');
|
|
40
|
+
return withBaseUrl(element.getAttribute('src') || '', props.baseUrl);
|
|
41
41
|
},
|
|
42
42
|
renderHTML: function renderHTML(attributes) {
|
|
43
43
|
if (!attributes.src) return {};
|
|
44
44
|
return {
|
|
45
|
-
src: attributes.src
|
|
45
|
+
src: removeBaseUrl(attributes.src, props.baseUrl)
|
|
46
46
|
};
|
|
47
47
|
}
|
|
48
48
|
},
|
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: ({ editable, contentType, onSave, onError, ...options }: UseTiptapProps & UseEditorOptions) => UseTiptapReturn;
|
|
3
|
+
declare const useTiptap: ({ editable, contentType, onSave, onError, onUpload, baseUrl, ...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 = ["editable", "contentType", "onSave", "onError"];
|
|
2
|
+
var _excluded = ["editable", "contentType", "onSave", "onError", "onUpload", "baseUrl"];
|
|
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; }
|
|
@@ -8,6 +8,7 @@ function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e
|
|
|
8
8
|
function _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = _objectWithoutPropertiesLoose(source, excluded); var key, i; if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; }
|
|
9
9
|
function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }
|
|
10
10
|
import { getExtensions } from "../extension";
|
|
11
|
+
import { withBaseUrl } from "../util";
|
|
11
12
|
import { migrateMathStrings } from '@tiptap/extension-mathematics';
|
|
12
13
|
import { useEditor } from '@tiptap/react';
|
|
13
14
|
var useTiptap = function useTiptap(_ref) {
|
|
@@ -17,10 +18,20 @@ var useTiptap = function useTiptap(_ref) {
|
|
|
17
18
|
contentType = _ref$contentType === void 0 ? 'html' : _ref$contentType,
|
|
18
19
|
onSave = _ref.onSave,
|
|
19
20
|
onError = _ref.onError,
|
|
21
|
+
onUpload = _ref.onUpload,
|
|
22
|
+
_ref$baseUrl = _ref.baseUrl,
|
|
23
|
+
baseUrl = _ref$baseUrl === void 0 ? '' : _ref$baseUrl,
|
|
20
24
|
options = _objectWithoutProperties(_ref, _excluded);
|
|
25
|
+
var handleUpload = onUpload ? function (file, onProgress, abortSignal) {
|
|
26
|
+
return onUpload(file, onProgress, abortSignal).then(function (url) {
|
|
27
|
+
return withBaseUrl(url, baseUrl);
|
|
28
|
+
});
|
|
29
|
+
} : undefined;
|
|
21
30
|
var extensions = getExtensions(_objectSpread({
|
|
22
31
|
editable: editable,
|
|
23
|
-
onError: onError
|
|
32
|
+
onError: onError,
|
|
33
|
+
baseUrl: baseUrl,
|
|
34
|
+
onUpload: handleUpload
|
|
24
35
|
}, options));
|
|
25
36
|
var editor = useEditor(_objectSpread(_objectSpread(_objectSpread({
|
|
26
37
|
editable: editable,
|
package/dist/type/index.d.ts
CHANGED
|
@@ -140,6 +140,10 @@ export type BaseExtensionOptions = {
|
|
|
140
140
|
* 占位符
|
|
141
141
|
*/
|
|
142
142
|
placeholder?: string;
|
|
143
|
+
/**
|
|
144
|
+
* 静态资源基础路径
|
|
145
|
+
*/
|
|
146
|
+
baseUrl?: string;
|
|
143
147
|
};
|
|
144
148
|
export type ExtensionRelativeProps = MentionExtensionProps & NodeOrMetaOrSuggestionOrExtensionOptions & EditorFnProps & BaseExtensionOptions;
|
|
145
149
|
export type UseTiptapProps = {
|
package/dist/util/index.d.ts
CHANGED
|
@@ -7,6 +7,8 @@ export * from './shortcutKey';
|
|
|
7
7
|
import { Node } from '@tiptap/pm/model';
|
|
8
8
|
import { EditorState } from '@tiptap/pm/state';
|
|
9
9
|
import { Editor } from '@tiptap/react';
|
|
10
|
+
export declare const withBaseUrl: (url: string, baseUrl: string) => string;
|
|
11
|
+
export declare const removeBaseUrl: (url: string, baseUrl: string) => string;
|
|
10
12
|
export declare const formatFileSize: (bytes: number) => string;
|
|
11
13
|
export declare const insertNodeAfterPosition: (editor: Editor, pos: number, nodeContent: any) => void;
|
|
12
14
|
export declare const hasMarksInBlock: (node: Node | null | undefined) => boolean;
|
package/dist/util/index.js
CHANGED
|
@@ -4,6 +4,44 @@ export * from "./floating";
|
|
|
4
4
|
export * from "./linewiseConvert";
|
|
5
5
|
export * from "./resourceExtractor";
|
|
6
6
|
export * from "./shortcutKey";
|
|
7
|
+
export var withBaseUrl = function withBaseUrl(url, baseUrl) {
|
|
8
|
+
var _url$trim, _baseUrl$trim;
|
|
9
|
+
var trimmedUrl = (_url$trim = url === null || url === void 0 ? void 0 : url.trim()) !== null && _url$trim !== void 0 ? _url$trim : '';
|
|
10
|
+
if (!trimmedUrl) return trimmedUrl;
|
|
11
|
+
var isAbsolute = /^([a-z][a-z\d+\-.]*:)?\/\//i.test(trimmedUrl) || trimmedUrl.startsWith('data:');
|
|
12
|
+
if (isAbsolute) {
|
|
13
|
+
return trimmedUrl;
|
|
14
|
+
}
|
|
15
|
+
var trimmedBase = (_baseUrl$trim = baseUrl === null || baseUrl === void 0 ? void 0 : baseUrl.trim()) !== null && _baseUrl$trim !== void 0 ? _baseUrl$trim : '';
|
|
16
|
+
if (!trimmedBase) {
|
|
17
|
+
return trimmedUrl;
|
|
18
|
+
}
|
|
19
|
+
if (trimmedUrl.startsWith(trimmedBase)) {
|
|
20
|
+
return trimmedUrl;
|
|
21
|
+
}
|
|
22
|
+
var baseEndsWithSlash = trimmedBase.endsWith('/');
|
|
23
|
+
var urlStartsWithSlash = trimmedUrl.startsWith('/');
|
|
24
|
+
if (baseEndsWithSlash && urlStartsWithSlash) {
|
|
25
|
+
return "".concat(trimmedBase.slice(0, -1)).concat(trimmedUrl);
|
|
26
|
+
} else if (!baseEndsWithSlash && !urlStartsWithSlash) {
|
|
27
|
+
return "".concat(trimmedBase, "/").concat(trimmedUrl);
|
|
28
|
+
} else {
|
|
29
|
+
return "".concat(trimmedBase).concat(trimmedUrl);
|
|
30
|
+
}
|
|
31
|
+
};
|
|
32
|
+
export var removeBaseUrl = function removeBaseUrl(url, baseUrl) {
|
|
33
|
+
var _url$trim2, _baseUrl$trim2;
|
|
34
|
+
var trimmedUrl = (_url$trim2 = url === null || url === void 0 ? void 0 : url.trim()) !== null && _url$trim2 !== void 0 ? _url$trim2 : '';
|
|
35
|
+
if (!trimmedUrl) return trimmedUrl;
|
|
36
|
+
var trimmedBase = (_baseUrl$trim2 = baseUrl === null || baseUrl === void 0 ? void 0 : baseUrl.trim()) !== null && _baseUrl$trim2 !== void 0 ? _baseUrl$trim2 : '';
|
|
37
|
+
if (!trimmedBase) {
|
|
38
|
+
return trimmedUrl;
|
|
39
|
+
}
|
|
40
|
+
if (trimmedUrl.startsWith(trimmedBase)) {
|
|
41
|
+
return trimmedUrl.slice(trimmedBase.length);
|
|
42
|
+
}
|
|
43
|
+
return trimmedUrl;
|
|
44
|
+
};
|
|
7
45
|
export var formatFileSize = function formatFileSize(bytes) {
|
|
8
46
|
if (bytes === 0) return '0 B';
|
|
9
47
|
var k = 1024;
|