x-star-editor 0.0.3 → 0.0.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/XStarEditor/index.d.ts +1 -0
- package/dist/XStarEditor/index.js +4 -7
- package/dist/XStarEditor/index.less +24 -0
- package/dist/XStarMdEditor/index.d.ts +11 -1
- package/dist/XStarMdEditor/index.js +6 -6
- package/dist/XStarMdEditor/{index.module.css → index.less} +7 -1
- package/dist/XStarMdViewer/index.d.ts +2 -1
- package/dist/XStarMdViewer/index.js +7 -6
- package/dist/XStarMdViewer/{index.module.css → index.less} +7 -1
- package/dist/components/FileInput.d.ts +1 -0
- package/dist/components/FileInput.js +23 -23
- package/dist/components/FileInput.less +83 -0
- package/dist/components/Toolbar.d.ts +1 -0
- package/dist/components/Toolbar.js +21 -19
- package/dist/components/Toolbar.less +118 -0
- package/dist/styles/global.less +1 -0
- package/dist/styles/{markdown.css → markdown.less} +38 -32
- package/dist/styles/prism.less +171 -0
- package/dist/utils/global.d.ts +1 -0
- package/dist/utils/global.js +1 -0
- package/dist/utils/history.d.ts +1 -1
- package/dist/utils/markdown.d.ts +7 -0
- package/dist/utils/markdown.js +17 -15
- package/package.json +38 -33
- package/dist/XStarEditor/index.module.css +0 -19
- package/dist/components/FileInput.module.css +0 -81
- package/dist/components/Toolbar.module.css +0 -115
- package/dist/styles/prism.css +0 -182
- package/dist/utils/module-css.d.ts +0 -3
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
import type { XStarMdEditorHandle, XStarMdEditorProps } from '../XStarMdEditor';
|
|
3
3
|
import type { XStarMdViewerHandle, XStarMdViewerProps } from '../XStarMdViewer';
|
|
4
|
+
import './index.less';
|
|
4
5
|
export interface XStarEditorHandle {
|
|
5
6
|
getEditor: () => XStarMdEditorHandle | null;
|
|
6
7
|
getViewer: () => XStarMdViewerHandle | null;
|
|
@@ -11,12 +11,12 @@ function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o =
|
|
|
11
11
|
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
|
|
12
12
|
function _iterableToArrayLimit(arr, i) { var _i = null == arr ? null : "undefined" != typeof Symbol && arr[Symbol.iterator] || arr["@@iterator"]; if (null != _i) { var _s, _e, _x, _r, _arr = [], _n = !0, _d = !1; try { if (_x = (_i = _i.call(arr)).next, 0 === i) { if (Object(_i) !== _i) return; _n = !1; } else for (; !(_n = (_s = _x.call(_i)).done) && (_arr.push(_s.value), _arr.length !== i); _n = !0); } catch (err) { _d = !0, _e = err; } finally { try { if (!_n && null != _i.return && (_r = _i.return(), Object(_r) !== _r)) return; } finally { if (_d) throw _e; } } return _arr; } }
|
|
13
13
|
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
|
|
14
|
-
import classNames from 'classnames
|
|
14
|
+
import classNames from 'classnames';
|
|
15
15
|
import React, { useEffect, useImperativeHandle, useRef, useState } from 'react';
|
|
16
16
|
import XStarMdEditor, { useMdEditorRef } from "../XStarMdEditor";
|
|
17
17
|
import XStarMdViewer, { useMdViewerRef } from "../XStarMdViewer";
|
|
18
|
-
import
|
|
19
|
-
|
|
18
|
+
import { prefix } from "../utils/global";
|
|
19
|
+
import "./index.less";
|
|
20
20
|
var XStarEditor = /*#__PURE__*/React.forwardRef(function (_ref, ref) {
|
|
21
21
|
var height = _ref.height,
|
|
22
22
|
initialValue = _ref.initialValue,
|
|
@@ -137,15 +137,13 @@ var XStarEditor = /*#__PURE__*/React.forwardRef(function (_ref, ref) {
|
|
|
137
137
|
};
|
|
138
138
|
}, []);
|
|
139
139
|
return /*#__PURE__*/React.createElement("div", {
|
|
140
|
-
className:
|
|
140
|
+
className: classNames("".concat(prefix, "editor"))
|
|
141
141
|
}, /*#__PURE__*/React.createElement(XStarMdEditor, _extends({
|
|
142
142
|
ref: editorRef
|
|
143
143
|
}, editorProps, {
|
|
144
|
-
className: cx('editor', editorProps === null || editorProps === void 0 ? void 0 : editorProps.className),
|
|
145
144
|
style: _objectSpread({
|
|
146
145
|
height: height
|
|
147
146
|
}, editorProps === null || editorProps === void 0 ? void 0 : editorProps.style),
|
|
148
|
-
toolbarClassName: cx('toolbar', editorProps === null || editorProps === void 0 ? void 0 : editorProps.toolbarClassName),
|
|
149
147
|
initialValue: initialValue,
|
|
150
148
|
onChange: function onChange(value) {
|
|
151
149
|
setValue(value);
|
|
@@ -154,7 +152,6 @@ var XStarEditor = /*#__PURE__*/React.forwardRef(function (_ref, ref) {
|
|
|
154
152
|
})), /*#__PURE__*/React.createElement(XStarMdViewer, _extends({
|
|
155
153
|
ref: viewerRef
|
|
156
154
|
}, viewerProps, {
|
|
157
|
-
className: cx('viewer', viewerProps === null || viewerProps === void 0 ? void 0 : viewerProps.className),
|
|
158
155
|
style: _objectSpread({
|
|
159
156
|
height: height
|
|
160
157
|
}, viewerProps === null || viewerProps === void 0 ? void 0 : viewerProps.style),
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
@import '../styles/global.less';
|
|
2
|
+
|
|
3
|
+
.@{prefix}editor {
|
|
4
|
+
display: flex;
|
|
5
|
+
flex-wrap: wrap;
|
|
6
|
+
|
|
7
|
+
.@{prefix}toolbar {
|
|
8
|
+
width: 100%;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
.@{prefix}md-editor {
|
|
12
|
+
flex: 1;
|
|
13
|
+
border-top: none;
|
|
14
|
+
border-bottom-right-radius: 0;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
.@{prefix}md-viewer {
|
|
18
|
+
flex: 1;
|
|
19
|
+
border-top: none;
|
|
20
|
+
border-left: none;
|
|
21
|
+
border-radius: 0;
|
|
22
|
+
border-bottom-right-radius: 0.2em;
|
|
23
|
+
}
|
|
24
|
+
}
|
|
@@ -1,10 +1,20 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
import type { ToolbarItem } from '../components/Toolbar';
|
|
3
|
-
import '../styles/markdown.
|
|
3
|
+
import '../styles/markdown.less';
|
|
4
4
|
import type { Executor, KeyboardEventHandler } from '../utils/handler';
|
|
5
|
+
import './index.less';
|
|
5
6
|
interface EditorOptions {
|
|
7
|
+
/**
|
|
8
|
+
* 工具栏项映射
|
|
9
|
+
*/
|
|
6
10
|
toolbarItemMap: Partial<Record<string, ToolbarItem>>;
|
|
11
|
+
/**
|
|
12
|
+
* 工具栏项
|
|
13
|
+
*/
|
|
7
14
|
toolbarItems: (string | ToolbarItem)[][];
|
|
15
|
+
/**
|
|
16
|
+
* 键盘事件处理函数
|
|
17
|
+
*/
|
|
8
18
|
keyboardEventHandlers: KeyboardEventHandler[];
|
|
9
19
|
}
|
|
10
20
|
export interface XStarMdEditorPlugin {
|
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
import classNames from 'classnames
|
|
1
|
+
import classNames from 'classnames';
|
|
2
2
|
import React, { useEffect, useImperativeHandle, useRef } from 'react';
|
|
3
3
|
import Toolbar, { getDefaultToolbarItemMap, getDefaultToolbarItems } from "../components/Toolbar";
|
|
4
|
-
import "../styles/markdown.
|
|
4
|
+
import "../styles/markdown.less";
|
|
5
5
|
import { createSelection, getRange, useContainer } from "../utils/container";
|
|
6
|
+
import { prefix } from "../utils/global";
|
|
6
7
|
import { composeHandlers, getDefaultKeyboardEventHandlers } from "../utils/handler";
|
|
7
8
|
import { useHistory } from "../utils/history";
|
|
8
|
-
import
|
|
9
|
-
var cx = classNames.bind(styles);
|
|
9
|
+
import "./index.less";
|
|
10
10
|
var XStarMdEditor = /*#__PURE__*/React.forwardRef(function (_ref, ref) {
|
|
11
11
|
var className = _ref.className,
|
|
12
12
|
style = _ref.style,
|
|
@@ -238,14 +238,14 @@ var XStarMdEditor = /*#__PURE__*/React.forwardRef(function (_ref, ref) {
|
|
|
238
238
|
}
|
|
239
239
|
};
|
|
240
240
|
return /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement(Toolbar, {
|
|
241
|
-
className:
|
|
241
|
+
className: classNames(toolbarClassName),
|
|
242
242
|
style: toolbarStyle,
|
|
243
243
|
itemMap: toolbarItemMap,
|
|
244
244
|
items: toolbarItems,
|
|
245
245
|
exec: exec
|
|
246
246
|
}), /*#__PURE__*/React.createElement("div", {
|
|
247
247
|
ref: container.ref,
|
|
248
|
-
className:
|
|
248
|
+
className: classNames("".concat(prefix, "md-editor"), className),
|
|
249
249
|
style: style,
|
|
250
250
|
contentEditable: true,
|
|
251
251
|
onBeforeInput: formEventHandler,
|
|
@@ -1,4 +1,6 @@
|
|
|
1
|
-
.
|
|
1
|
+
@import '../styles/global.less';
|
|
2
|
+
|
|
3
|
+
.@{prefix}md-editor {
|
|
2
4
|
position: relative;
|
|
3
5
|
line-height: 1.6em;
|
|
4
6
|
white-space: break-spaces;
|
|
@@ -9,4 +11,8 @@
|
|
|
9
11
|
border-bottom-left-radius: 0.2em;
|
|
10
12
|
outline: none;
|
|
11
13
|
overflow: auto;
|
|
14
|
+
|
|
15
|
+
::selection {
|
|
16
|
+
background: #c1def1;
|
|
17
|
+
}
|
|
12
18
|
}
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
import '../styles/katex.css';
|
|
3
|
-
import '../styles/prism.
|
|
3
|
+
import '../styles/prism.less';
|
|
4
4
|
import type { ViewerOptions } from '../utils/markdown';
|
|
5
|
+
import './index.less';
|
|
5
6
|
export interface XStarMdViewerPlugin {
|
|
6
7
|
(ctx: ViewerOptions): void;
|
|
7
8
|
}
|
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import classNames from 'classnames
|
|
1
|
+
import classNames from 'classnames';
|
|
2
2
|
import React, { useImperativeHandle, useRef } from 'react';
|
|
3
3
|
import "../styles/katex.css";
|
|
4
|
-
import "../styles/prism.
|
|
4
|
+
import "../styles/prism.less";
|
|
5
|
+
import { prefix } from "../utils/global";
|
|
5
6
|
import { composeHandlers } from "../utils/handler";
|
|
6
|
-
import { viewerRender } from "../utils/markdown";
|
|
7
|
-
import
|
|
8
|
-
var cx = classNames.bind(styles);
|
|
7
|
+
import { getDefaultSchema, viewerRender } from "../utils/markdown";
|
|
8
|
+
import "./index.less";
|
|
9
9
|
var XStarMdViewer = /*#__PURE__*/React.forwardRef(function (_ref, ref) {
|
|
10
10
|
var className = _ref.className,
|
|
11
11
|
style = _ref.style,
|
|
@@ -22,9 +22,10 @@ var XStarMdViewer = /*#__PURE__*/React.forwardRef(function (_ref, ref) {
|
|
|
22
22
|
}, []);
|
|
23
23
|
return /*#__PURE__*/React.createElement("div", {
|
|
24
24
|
ref: container,
|
|
25
|
-
className:
|
|
25
|
+
className: classNames("".concat(prefix, "md-viewer"), className),
|
|
26
26
|
style: style
|
|
27
27
|
}, viewerRender(value, composeHandlers(plugins)({
|
|
28
|
+
customSchema: getDefaultSchema(),
|
|
28
29
|
customHTMLElements: {},
|
|
29
30
|
customBlocks: {}
|
|
30
31
|
})));
|
|
@@ -1,4 +1,6 @@
|
|
|
1
|
-
.
|
|
1
|
+
@import '../styles/global.less';
|
|
2
|
+
|
|
3
|
+
.@{prefix}md-viewer {
|
|
2
4
|
position: relative;
|
|
3
5
|
padding: 0 1em;
|
|
4
6
|
color: #000000d9;
|
|
@@ -6,4 +8,8 @@
|
|
|
6
8
|
border: 1px solid #d0d0d0;
|
|
7
9
|
border-radius: 0.2em;
|
|
8
10
|
overflow: auto;
|
|
11
|
+
|
|
12
|
+
::selection {
|
|
13
|
+
background: #c1def1;
|
|
14
|
+
}
|
|
9
15
|
}
|
|
@@ -1,13 +1,17 @@
|
|
|
1
|
+
function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
|
|
2
|
+
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; }
|
|
3
|
+
function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return _typeof(key) === "symbol" ? key : String(key); }
|
|
4
|
+
function _toPrimitive(input, hint) { if (_typeof(input) !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (_typeof(res) !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
|
|
1
5
|
function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
|
|
2
6
|
function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
|
|
3
7
|
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
|
|
4
8
|
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
|
|
5
9
|
function _iterableToArrayLimit(arr, i) { var _i = null == arr ? null : "undefined" != typeof Symbol && arr[Symbol.iterator] || arr["@@iterator"]; if (null != _i) { var _s, _e, _x, _r, _arr = [], _n = !0, _d = !1; try { if (_x = (_i = _i.call(arr)).next, 0 === i) { if (Object(_i) !== _i) return; _n = !1; } else for (; !(_n = (_s = _x.call(_i)).done) && (_arr.push(_s.value), _arr.length !== i); _n = !0); } catch (err) { _d = !0, _e = err; } finally { try { if (!_n && null != _i.return && (_r = _i.return(), Object(_r) !== _r)) return; } finally { if (_d) throw _e; } } return _arr; } }
|
|
6
10
|
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
|
|
7
|
-
import classNames from 'classnames
|
|
11
|
+
import classNames from 'classnames';
|
|
8
12
|
import React, { useState } from 'react';
|
|
9
|
-
import
|
|
10
|
-
|
|
13
|
+
import { prefix } from "../utils/global";
|
|
14
|
+
import "./FileInput.less";
|
|
11
15
|
var FileInput = function FileInput(_ref) {
|
|
12
16
|
var _file$name;
|
|
13
17
|
var onCancel = _ref.onCancel,
|
|
@@ -29,59 +33,55 @@ var FileInput = function FileInput(_ref) {
|
|
|
29
33
|
description = _useState8[0],
|
|
30
34
|
setDescription = _useState8[1];
|
|
31
35
|
return /*#__PURE__*/React.createElement("div", {
|
|
32
|
-
className:
|
|
36
|
+
className: classNames("".concat(prefix, "file-input"))
|
|
33
37
|
}, /*#__PURE__*/React.createElement("div", {
|
|
34
|
-
className:
|
|
38
|
+
className: classNames("".concat(prefix, "tabs"))
|
|
35
39
|
}, /*#__PURE__*/React.createElement("div", {
|
|
36
|
-
className:
|
|
37
|
-
active: type === 'file'
|
|
38
|
-
}),
|
|
40
|
+
className: classNames("".concat(prefix, "tab"), _defineProperty({}, "".concat(prefix, "active"), type === 'file')),
|
|
39
41
|
onClick: function onClick() {
|
|
40
42
|
return setType('file');
|
|
41
43
|
}
|
|
42
44
|
}, "\u6587\u4EF6"), /*#__PURE__*/React.createElement("div", {
|
|
43
|
-
className:
|
|
44
|
-
active: type === 'url'
|
|
45
|
-
}),
|
|
45
|
+
className: classNames("".concat(prefix, "tab"), _defineProperty({}, "".concat(prefix, "active"), type === 'url')),
|
|
46
46
|
onClick: function onClick() {
|
|
47
47
|
return setType('url');
|
|
48
48
|
}
|
|
49
49
|
}, "\u7F51\u5740")), type === 'file' ? /*#__PURE__*/React.createElement("label", {
|
|
50
|
-
className:
|
|
50
|
+
className: classNames("".concat(prefix, "field"))
|
|
51
51
|
}, "\u6587\u4EF6", /*#__PURE__*/React.createElement("div", {
|
|
52
|
-
className:
|
|
52
|
+
className: classNames("".concat(prefix, "file-container"))
|
|
53
53
|
}, /*#__PURE__*/React.createElement("input", {
|
|
54
|
-
className:
|
|
54
|
+
className: classNames("".concat(prefix, "hidden")),
|
|
55
55
|
type: "file",
|
|
56
56
|
onChange: function onChange(e) {
|
|
57
57
|
var _e$target$files;
|
|
58
58
|
return setFile((_e$target$files = e.target.files) === null || _e$target$files === void 0 ? void 0 : _e$target$files[0]);
|
|
59
59
|
}
|
|
60
60
|
}), /*#__PURE__*/React.createElement("input", {
|
|
61
|
-
className:
|
|
61
|
+
className: classNames("".concat(prefix, "input")),
|
|
62
62
|
readOnly: true,
|
|
63
63
|
value: (_file$name = file === null || file === void 0 ? void 0 : file.name) !== null && _file$name !== void 0 ? _file$name : ''
|
|
64
64
|
}), /*#__PURE__*/React.createElement("button", {
|
|
65
|
-
className:
|
|
65
|
+
className: classNames("".concat(prefix, "button")),
|
|
66
66
|
type: "button"
|
|
67
67
|
}, "\u9009\u62E9\u6587\u4EF6"))) : /*#__PURE__*/React.createElement("label", {
|
|
68
|
-
className:
|
|
68
|
+
className: classNames("".concat(prefix, "field"))
|
|
69
69
|
}, "\u7F51\u5740", /*#__PURE__*/React.createElement("input", {
|
|
70
|
-
className:
|
|
70
|
+
className: classNames("".concat(prefix, "input")),
|
|
71
71
|
onChange: function onChange(e) {
|
|
72
72
|
return setUrl(e.target.value);
|
|
73
73
|
}
|
|
74
74
|
})), /*#__PURE__*/React.createElement("label", {
|
|
75
|
-
className:
|
|
75
|
+
className: classNames("".concat(prefix, "field"))
|
|
76
76
|
}, "\u63CF\u8FF0", /*#__PURE__*/React.createElement("input", {
|
|
77
|
-
className:
|
|
77
|
+
className: classNames("".concat(prefix, "input")),
|
|
78
78
|
onChange: function onChange(e) {
|
|
79
79
|
return setDescription(e.target.value);
|
|
80
80
|
}
|
|
81
81
|
})), /*#__PURE__*/React.createElement("div", {
|
|
82
|
-
className:
|
|
82
|
+
className: classNames("".concat(prefix, "buttons"))
|
|
83
83
|
}, /*#__PURE__*/React.createElement("button", {
|
|
84
|
-
className:
|
|
84
|
+
className: classNames("".concat(prefix, "button"), "".concat(prefix, "primary")),
|
|
85
85
|
type: "button",
|
|
86
86
|
onClick: function onClick() {
|
|
87
87
|
if (type === 'file' && file) {
|
|
@@ -99,7 +99,7 @@ var FileInput = function FileInput(_ref) {
|
|
|
99
99
|
}
|
|
100
100
|
}
|
|
101
101
|
}, "\u786E\u5B9A"), /*#__PURE__*/React.createElement("button", {
|
|
102
|
-
className:
|
|
102
|
+
className: classNames("".concat(prefix, "button")),
|
|
103
103
|
type: "button",
|
|
104
104
|
onClick: onCancel
|
|
105
105
|
}, "\u53D6\u6D88")));
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
@import '../styles/global.less';
|
|
2
|
+
|
|
3
|
+
.@{prefix}file-input {
|
|
4
|
+
margin: 0.5em 1em 1em;
|
|
5
|
+
|
|
6
|
+
.@{prefix}tabs {
|
|
7
|
+
display: flex;
|
|
8
|
+
|
|
9
|
+
.@{prefix}tab {
|
|
10
|
+
padding: 0.4em 1em;
|
|
11
|
+
border-bottom: 1px solid #f5771280;
|
|
12
|
+
cursor: pointer;
|
|
13
|
+
user-select: none;
|
|
14
|
+
|
|
15
|
+
&.@{prefix}active {
|
|
16
|
+
color: #f57712;
|
|
17
|
+
border-bottom: 2px solid #f57712;
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
.@{prefix}buttons {
|
|
23
|
+
display: flex;
|
|
24
|
+
flex-direction: row-reverse;
|
|
25
|
+
gap: 0.4em;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
.@{prefix}button {
|
|
29
|
+
padding: 0.4em 1em;
|
|
30
|
+
background-color: #f0f0f0;
|
|
31
|
+
border: 1px solid #d0d0d0;
|
|
32
|
+
border-radius: 0.2em;
|
|
33
|
+
cursor: pointer;
|
|
34
|
+
user-select: none;
|
|
35
|
+
|
|
36
|
+
&.@{prefix}primary {
|
|
37
|
+
color: #fff;
|
|
38
|
+
background-color: #f57712;
|
|
39
|
+
border: none;
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
.@{prefix}field {
|
|
44
|
+
margin: 0.8em;
|
|
45
|
+
display: flex;
|
|
46
|
+
flex-direction: column;
|
|
47
|
+
gap: 0.2em;
|
|
48
|
+
font-size: 0.9em;
|
|
49
|
+
|
|
50
|
+
.@{prefix}input {
|
|
51
|
+
width: 20em;
|
|
52
|
+
padding: 0.4em;
|
|
53
|
+
border: 1px solid #d0d0d0;
|
|
54
|
+
border-radius: 0.2em;
|
|
55
|
+
outline: none;
|
|
56
|
+
|
|
57
|
+
&:focus {
|
|
58
|
+
border: 1px solid #f57712;
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
.@{prefix}file-container {
|
|
63
|
+
position: relative;
|
|
64
|
+
display: flex;
|
|
65
|
+
align-items: center;
|
|
66
|
+
justify-content: space-between;
|
|
67
|
+
|
|
68
|
+
.@{prefix}hidden {
|
|
69
|
+
position: absolute;
|
|
70
|
+
inset: 0;
|
|
71
|
+
opacity: 0;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
.@{prefix}input {
|
|
75
|
+
width: 14em;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
.@{prefix}button {
|
|
79
|
+
padding: 0.3em 0.4em;
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
}
|
|
@@ -1,15 +1,19 @@
|
|
|
1
|
+
function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
|
|
2
|
+
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; }
|
|
3
|
+
function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return _typeof(key) === "symbol" ? key : String(key); }
|
|
4
|
+
function _toPrimitive(input, hint) { if (_typeof(input) !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (_typeof(res) !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
|
|
1
5
|
function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
|
|
2
6
|
function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
|
|
3
7
|
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
|
|
4
8
|
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
|
|
5
9
|
function _iterableToArrayLimit(arr, i) { var _i = null == arr ? null : "undefined" != typeof Symbol && arr[Symbol.iterator] || arr["@@iterator"]; if (null != _i) { var _s, _e, _x, _r, _arr = [], _n = !0, _d = !1; try { if (_x = (_i = _i.call(arr)).next, 0 === i) { if (Object(_i) !== _i) return; _n = !1; } else for (; !(_n = (_s = _x.call(_i)).done) && (_arr.push(_s.value), _arr.length !== i); _n = !0); } catch (err) { _d = !0, _e = err; } finally { try { if (!_n && null != _i.return && (_r = _i.return(), Object(_r) !== _r)) return; } finally { if (_d) throw _e; } } return _arr; } }
|
|
6
10
|
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
|
|
7
|
-
import classNames from 'classnames
|
|
11
|
+
import classNames from 'classnames';
|
|
8
12
|
import React, { useEffect, useRef, useState } from 'react';
|
|
13
|
+
import { prefix } from "../utils/global";
|
|
9
14
|
import { toggleHandler } from "../utils/handler";
|
|
10
15
|
import FileInput from "./FileInput";
|
|
11
|
-
import
|
|
12
|
-
var cx = classNames.bind(styles);
|
|
16
|
+
import "./Toolbar.less";
|
|
13
17
|
var Button = function Button(_ref) {
|
|
14
18
|
var toolbarRef = _ref.toolbarRef,
|
|
15
19
|
children = _ref.children,
|
|
@@ -55,11 +59,9 @@ var Button = function Button(_ref) {
|
|
|
55
59
|
}
|
|
56
60
|
}, [popoverMount]);
|
|
57
61
|
return /*#__PURE__*/React.createElement("div", {
|
|
58
|
-
className:
|
|
62
|
+
className: classNames("".concat(prefix, "button-container"))
|
|
59
63
|
}, /*#__PURE__*/React.createElement("div", {
|
|
60
|
-
className:
|
|
61
|
-
active: tooltipOpen || popoverMount
|
|
62
|
-
}),
|
|
64
|
+
className: classNames("".concat(prefix, "button"), _defineProperty({}, "".concat(prefix, "active"), tooltipOpen || popoverMount)),
|
|
63
65
|
onClick: function onClick() {
|
|
64
66
|
setPopoverOpen(true);
|
|
65
67
|
_onClick === null || _onClick === void 0 ? void 0 : _onClick();
|
|
@@ -74,10 +76,10 @@ var Button = function Button(_ref) {
|
|
|
74
76
|
return setTooltipOpen(false);
|
|
75
77
|
}
|
|
76
78
|
}, children, tooltipMount && /*#__PURE__*/React.createElement("div", {
|
|
77
|
-
className:
|
|
79
|
+
className: classNames("".concat(prefix, "tooltip"))
|
|
78
80
|
}, tooltip)), popoverMount && /*#__PURE__*/React.createElement("div", {
|
|
79
81
|
ref: popoverRef,
|
|
80
|
-
className:
|
|
82
|
+
className: classNames("".concat(prefix, "popover"))
|
|
81
83
|
}, popover));
|
|
82
84
|
};
|
|
83
85
|
export var getDefaultToolbarItemMap = function getDefaultToolbarItemMap(onInsertFile) {
|
|
@@ -88,7 +90,7 @@ export var getDefaultToolbarItemMap = function getDefaultToolbarItemMap(onInsert
|
|
|
88
90
|
popoverRender: function popoverRender(exec, close) {
|
|
89
91
|
var optionRender = function optionRender(depth, fontSize) {
|
|
90
92
|
return /*#__PURE__*/React.createElement("div", {
|
|
91
|
-
className:
|
|
93
|
+
className: classNames("".concat(prefix, "option")),
|
|
92
94
|
style: {
|
|
93
95
|
fontSize: fontSize
|
|
94
96
|
},
|
|
@@ -124,7 +126,7 @@ export var getDefaultToolbarItemMap = function getDefaultToolbarItemMap(onInsert
|
|
|
124
126
|
},
|
|
125
127
|
code: {
|
|
126
128
|
children: /*#__PURE__*/React.createElement("div", {
|
|
127
|
-
className:
|
|
129
|
+
className: classNames("".concat(prefix, "icon"), "".concat(prefix, "code-library"))
|
|
128
130
|
}),
|
|
129
131
|
tooltip: '代码块',
|
|
130
132
|
onClick: function onClick(exec) {
|
|
@@ -135,7 +137,7 @@ export var getDefaultToolbarItemMap = function getDefaultToolbarItemMap(onInsert
|
|
|
135
137
|
},
|
|
136
138
|
emphasis: {
|
|
137
139
|
children: /*#__PURE__*/React.createElement("div", {
|
|
138
|
-
className:
|
|
140
|
+
className: classNames("".concat(prefix, "icon"), "".concat(prefix, "italic"))
|
|
139
141
|
}),
|
|
140
142
|
tooltip: '斜体',
|
|
141
143
|
onClick: function onClick(exec) {
|
|
@@ -146,7 +148,7 @@ export var getDefaultToolbarItemMap = function getDefaultToolbarItemMap(onInsert
|
|
|
146
148
|
},
|
|
147
149
|
strong: {
|
|
148
150
|
children: /*#__PURE__*/React.createElement("div", {
|
|
149
|
-
className:
|
|
151
|
+
className: classNames("".concat(prefix, "icon"), "".concat(prefix, "bold"))
|
|
150
152
|
}),
|
|
151
153
|
tooltip: '粗体',
|
|
152
154
|
onClick: function onClick(exec) {
|
|
@@ -157,7 +159,7 @@ export var getDefaultToolbarItemMap = function getDefaultToolbarItemMap(onInsert
|
|
|
157
159
|
},
|
|
158
160
|
inlineCode: {
|
|
159
161
|
children: /*#__PURE__*/React.createElement("div", {
|
|
160
|
-
className:
|
|
162
|
+
className: classNames("".concat(prefix, "icon"), "".concat(prefix, "code"))
|
|
161
163
|
}),
|
|
162
164
|
tooltip: '行内代码',
|
|
163
165
|
onClick: function onClick(exec) {
|
|
@@ -168,7 +170,7 @@ export var getDefaultToolbarItemMap = function getDefaultToolbarItemMap(onInsert
|
|
|
168
170
|
},
|
|
169
171
|
link: {
|
|
170
172
|
children: /*#__PURE__*/React.createElement("div", {
|
|
171
|
-
className:
|
|
173
|
+
className: classNames("".concat(prefix, "icon"), "".concat(prefix, "link"))
|
|
172
174
|
}),
|
|
173
175
|
tooltip: '链接',
|
|
174
176
|
popoverRender: function popoverRender(exec, close) {
|
|
@@ -194,7 +196,7 @@ export var getDefaultToolbarItemMap = function getDefaultToolbarItemMap(onInsert
|
|
|
194
196
|
},
|
|
195
197
|
image: {
|
|
196
198
|
children: /*#__PURE__*/React.createElement("div", {
|
|
197
|
-
className:
|
|
199
|
+
className: classNames("".concat(prefix, "icon"), "".concat(prefix, "image"))
|
|
198
200
|
}),
|
|
199
201
|
tooltip: '图片',
|
|
200
202
|
popoverRender: function popoverRender(exec, close) {
|
|
@@ -220,7 +222,7 @@ export var getDefaultToolbarItemMap = function getDefaultToolbarItemMap(onInsert
|
|
|
220
222
|
},
|
|
221
223
|
delete: {
|
|
222
224
|
children: /*#__PURE__*/React.createElement("div", {
|
|
223
|
-
className:
|
|
225
|
+
className: classNames("".concat(prefix, "icon"), "".concat(prefix, "strikethrough"))
|
|
224
226
|
}),
|
|
225
227
|
tooltip: '删除线',
|
|
226
228
|
onClick: function onClick(exec) {
|
|
@@ -261,13 +263,13 @@ var Toolbar = function Toolbar(_ref2) {
|
|
|
261
263
|
var toolbarRef = useRef(null);
|
|
262
264
|
return /*#__PURE__*/React.createElement("div", {
|
|
263
265
|
ref: toolbarRef,
|
|
264
|
-
className:
|
|
266
|
+
className: classNames("".concat(prefix, "toolbar"), className),
|
|
265
267
|
style: style
|
|
266
268
|
}, items.map(function (group, index) {
|
|
267
269
|
return /*#__PURE__*/React.createElement(React.Fragment, {
|
|
268
270
|
key: index
|
|
269
271
|
}, !!index && /*#__PURE__*/React.createElement("div", {
|
|
270
|
-
className:
|
|
272
|
+
className: classNames("".concat(prefix, "divider"))
|
|
271
273
|
}), group.map(function (item, index) {
|
|
272
274
|
var toolbarItem = typeof item === 'string' ? itemMap[item] : item;
|
|
273
275
|
if (!toolbarItem) {
|