x-star-editor 0.0.2 → 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.
@@ -1,12 +1,18 @@
1
1
  import React from 'react';
2
- import type { XStarMdEditorProps } from '../XStarMdEditor';
3
- import type { XStarMdViewerProps } from '../XStarMdViewer';
4
- export interface XStarMDProps {
2
+ import type { XStarMdEditorHandle, XStarMdEditorProps } from '../XStarMdEditor';
3
+ import type { XStarMdViewerHandle, XStarMdViewerProps } from '../XStarMdViewer';
4
+ import './index.less';
5
+ export interface XStarEditorHandle {
6
+ getEditor: () => XStarMdEditorHandle | null;
7
+ getViewer: () => XStarMdViewerHandle | null;
8
+ }
9
+ export interface XStarEditorProps {
5
10
  height?: React.CSSProperties['height'];
6
11
  initialValue?: string;
7
12
  editorProps?: Omit<XStarMdEditorProps, 'initialValue' | 'onChange'>;
8
13
  viewerProps?: Omit<XStarMdViewerProps, 'value'>;
9
14
  onChange?: (value: string) => void;
10
15
  }
11
- declare const XStarEditor: ({ height, initialValue, editorProps, viewerProps, onChange, }: XStarMDProps) => React.JSX.Element;
16
+ declare const XStarEditor: React.ForwardRefExoticComponent<XStarEditorProps & React.RefAttributes<XStarEditorHandle>>;
12
17
  export default XStarEditor;
18
+ export declare const useEditorRef: () => React.RefObject<XStarEditorHandle>;
@@ -11,13 +11,13 @@ 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/bind';
15
- import React, { useEffect, useRef, useState } from 'react';
16
- import XStarMdEditor from "../XStarMdEditor";
17
- import XStarMdViewer from "../XStarMdViewer";
18
- import styles from "./index.module.css";
19
- var cx = classNames.bind(styles);
20
- var XStarEditor = function XStarEditor(_ref) {
14
+ import classNames from 'classnames';
15
+ import React, { useEffect, useImperativeHandle, useRef, useState } from 'react';
16
+ import XStarMdEditor, { useMdEditorRef } from "../XStarMdEditor";
17
+ import XStarMdViewer, { useMdViewerRef } from "../XStarMdViewer";
18
+ import { prefix } from "../utils/global";
19
+ import "./index.less";
20
+ var XStarEditor = /*#__PURE__*/React.forwardRef(function (_ref, ref) {
21
21
  var height = _ref.height,
22
22
  initialValue = _ref.initialValue,
23
23
  editorProps = _ref.editorProps,
@@ -27,44 +27,94 @@ var XStarEditor = function XStarEditor(_ref) {
27
27
  _useState2 = _slicedToArray(_useState, 2),
28
28
  value = _useState2[0],
29
29
  setValue = _useState2[1];
30
- var editorRef = useRef(null);
31
- var viewerRef = useRef(null);
30
+ var editorRef = useMdEditorRef();
31
+ var viewerRef = useMdViewerRef();
32
+ useImperativeHandle(ref, function () {
33
+ return {
34
+ getEditor: function getEditor() {
35
+ return editorRef.current;
36
+ },
37
+ getViewer: function getViewer() {
38
+ return viewerRef.current;
39
+ }
40
+ };
41
+ }, []);
42
+
43
+ // 同步滚动
32
44
  useEffect(function () {
33
45
  var _editorRef$current, _viewerRef$current;
34
46
  var editor = (_editorRef$current = editorRef.current) === null || _editorRef$current === void 0 ? void 0 : _editorRef$current.getContainer();
35
47
  var viewer = (_viewerRef$current = viewerRef.current) === null || _viewerRef$current === void 0 ? void 0 : _viewerRef$current.getContainer();
36
48
 
37
49
  /**
38
- * 获取一个父元素的子元素到父元素顶部的距离
50
+ * 获取两个父元素的子元素到各自父元素顶部的距离
39
51
  *
40
- * @param element 父元素
41
- * @param index 是否只考虑有 `index` 属性的子元素
42
- * @returns 子元素到父元素顶部的距离
52
+ * @param fromElement 第一个父元素
53
+ * @param toElement 第二个父元素
54
+ * @returns 子元素到各自父元素顶部的距离
43
55
  */
44
- var getOffsetTops = function getOffsetTops(element, index) {
45
- var offsetTops = [0];
46
- for (var i = 0; i < element.children.length; i++) {
47
- var child = element.children[i];
48
- if (child instanceof HTMLElement && (!index || child.hasAttribute('index'))) {
49
- offsetTops.push(child.offsetTop);
56
+ var getOffsetTops = function getOffsetTops(fromElement, toElement) {
57
+ var fromOffsetTops = [0];
58
+ var toOffsetTops = [0];
59
+ var fromLimit = fromElement.scrollHeight - fromElement.clientHeight;
60
+ var toLimit = toElement.scrollHeight - toElement.clientHeight;
61
+ if (fromLimit > 0 && toLimit > 0) {
62
+ for (var i = 0, j = 0; i < fromElement.children.length && j < toElement.children.length;) {
63
+ var _fromChild$getAttribu, _toChild$getAttribute;
64
+ var fromChild = fromElement.children[i];
65
+ var toChild = toElement.children[j];
66
+ var fromLine = parseInt((_fromChild$getAttribu = fromChild.getAttribute('line')) !== null && _fromChild$getAttribu !== void 0 ? _fromChild$getAttribu : '');
67
+ var toLine = parseInt((_toChild$getAttribute = toChild.getAttribute('line')) !== null && _toChild$getAttribute !== void 0 ? _toChild$getAttribute : '');
68
+ if (!(fromChild instanceof HTMLElement) || !fromLine) {
69
+ i++;
70
+ } else if (!(toChild instanceof HTMLElement) || !toLine) {
71
+ j++;
72
+ } else if (fromLine < toLine) {
73
+ i++;
74
+ } else if (fromLine > toLine) {
75
+ j++;
76
+ } else {
77
+ fromOffsetTops.push(fromChild.offsetTop);
78
+ toOffsetTops.push(toChild.offsetTop);
79
+ i++;
80
+ j++;
81
+ }
50
82
  }
83
+ for (; fromOffsetTops[fromOffsetTops.length - 1] >= fromLimit || toOffsetTops[toOffsetTops.length - 1] >= toLimit;) {
84
+ fromOffsetTops.pop();
85
+ toOffsetTops.pop();
86
+ }
87
+ fromOffsetTops.push(fromLimit);
88
+ toOffsetTops.push(toLimit);
51
89
  }
52
- offsetTops.push(element.scrollHeight);
53
- return offsetTops;
90
+ return [fromOffsetTops, toOffsetTops];
54
91
  };
92
+
93
+ /**
94
+ * 是否忽略下一个滚动事件
95
+ */
96
+ var ignoreNext = false;
55
97
  var listener = function listener(e) {
56
- if (!editor || !viewer) {
98
+ var ignore = ignoreNext;
99
+ ignoreNext = false;
100
+ if (ignore || !editor || !viewer) {
57
101
  return;
58
102
  }
59
103
  var _ref2 = e.currentTarget === editor ? [editor, viewer] : [viewer, editor],
60
104
  _ref3 = _slicedToArray(_ref2, 2),
61
105
  fromElement = _ref3[0],
62
106
  toElement = _ref3[1];
63
- var fromOffsetTops = getOffsetTops(fromElement, fromElement === editor);
64
- var toOffsetTops = getOffsetTops(toElement, toElement === editor);
107
+ var _getOffsetTops = getOffsetTops(fromElement, toElement),
108
+ _getOffsetTops2 = _slicedToArray(_getOffsetTops, 2),
109
+ fromOffsetTops = _getOffsetTops2[0],
110
+ toOffsetTops = _getOffsetTops2[1];
65
111
  for (var i = 0; i < fromOffsetTops.length - 1; i++) {
66
112
  if (fromOffsetTops[i] <= fromElement.scrollTop && fromElement.scrollTop < fromOffsetTops[i + 1]) {
67
- toElement.scrollTop = (fromElement.scrollTop - fromOffsetTops[i]) / (fromOffsetTops[i + 1] - fromOffsetTops[i]) * (toOffsetTops[i + 1] - toOffsetTops[i]) + toOffsetTops[i];
113
+ var scrollTop = (fromElement.scrollTop - fromOffsetTops[i]) / (fromOffsetTops[i + 1] - fromOffsetTops[i]) * (toOffsetTops[i + 1] - toOffsetTops[i]) + toOffsetTops[i];
114
+ if (toElement.scrollTop !== scrollTop) {
115
+ ignoreNext = true;
116
+ toElement.scrollTop = scrollTop;
117
+ }
68
118
  break;
69
119
  }
70
120
  }
@@ -87,15 +137,13 @@ var XStarEditor = function XStarEditor(_ref) {
87
137
  };
88
138
  }, []);
89
139
  return /*#__PURE__*/React.createElement("div", {
90
- className: cx('container')
140
+ className: classNames("".concat(prefix, "editor"))
91
141
  }, /*#__PURE__*/React.createElement(XStarMdEditor, _extends({
92
142
  ref: editorRef
93
143
  }, editorProps, {
94
- className: cx('editor', editorProps === null || editorProps === void 0 ? void 0 : editorProps.className),
95
144
  style: _objectSpread({
96
145
  height: height
97
146
  }, editorProps === null || editorProps === void 0 ? void 0 : editorProps.style),
98
- toolbarClassName: cx('toolbar', editorProps === null || editorProps === void 0 ? void 0 : editorProps.toolbarClassName),
99
147
  initialValue: initialValue,
100
148
  onChange: function onChange(value) {
101
149
  setValue(value);
@@ -104,11 +152,14 @@ var XStarEditor = function XStarEditor(_ref) {
104
152
  })), /*#__PURE__*/React.createElement(XStarMdViewer, _extends({
105
153
  ref: viewerRef
106
154
  }, viewerProps, {
107
- className: cx('viewer', viewerProps === null || viewerProps === void 0 ? void 0 : viewerProps.className),
108
155
  style: _objectSpread({
109
156
  height: height
110
157
  }, viewerProps === null || viewerProps === void 0 ? void 0 : viewerProps.style),
111
158
  value: value
112
159
  })));
113
- };
114
- export default XStarEditor;
160
+ });
161
+ XStarEditor.displayName = 'XStarEditor';
162
+ export default XStarEditor;
163
+ export var useEditorRef = function useEditorRef() {
164
+ return useRef(null);
165
+ };
@@ -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.css';
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 {
@@ -29,3 +39,4 @@ export interface XStarMdEditorProps {
29
39
  }
30
40
  declare const XStarMdEditor: React.ForwardRefExoticComponent<XStarMdEditorProps & React.RefAttributes<XStarMdEditorHandle>>;
31
41
  export default XStarMdEditor;
42
+ export declare const useMdEditorRef: () => React.RefObject<XStarMdEditorHandle>;
@@ -1,12 +1,12 @@
1
- import classNames from 'classnames/bind';
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.css";
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 styles from "./index.module.css";
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: cx(toolbarClassName),
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: cx('container', className),
248
+ className: classNames("".concat(prefix, "md-editor"), className),
249
249
  style: style,
250
250
  contentEditable: true,
251
251
  onBeforeInput: formEventHandler,
@@ -260,4 +260,7 @@ var XStarMdEditor = /*#__PURE__*/React.forwardRef(function (_ref, ref) {
260
260
  }));
261
261
  });
262
262
  XStarMdEditor.displayName = 'XStarMdEditor';
263
- export default XStarMdEditor;
263
+ export default XStarMdEditor;
264
+ export var useMdEditorRef = function useMdEditorRef() {
265
+ return useRef(null);
266
+ };
@@ -1,6 +1,7 @@
1
- .container {
1
+ @import '../styles/global.less';
2
+
3
+ .@{prefix}md-editor {
2
4
  position: relative;
3
- margin: 0 -1px;
4
5
  line-height: 1.6em;
5
6
  white-space: break-spaces;
6
7
  color: #000000d9;
@@ -10,4 +11,8 @@
10
11
  border-bottom-left-radius: 0.2em;
11
12
  outline: none;
12
13
  overflow: auto;
14
+
15
+ ::selection {
16
+ background: #c1def1;
17
+ }
13
18
  }
@@ -1,7 +1,8 @@
1
1
  import React from 'react';
2
2
  import '../styles/katex.css';
3
- import '../styles/prism.css';
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
  }
@@ -16,3 +17,4 @@ export interface XStarMdViewerProps {
16
17
  }
17
18
  declare const XStarMdViewer: React.ForwardRefExoticComponent<XStarMdViewerProps & React.RefAttributes<XStarMdViewerHandle>>;
18
19
  export default XStarMdViewer;
20
+ export declare const useMdViewerRef: () => React.RefObject<XStarMdViewerHandle>;
@@ -1,11 +1,11 @@
1
- import classNames from 'classnames/bind';
1
+ import classNames from 'classnames';
2
2
  import React, { useImperativeHandle, useRef } from 'react';
3
3
  import "../styles/katex.css";
4
- import "../styles/prism.css";
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 styles from "./index.module.css";
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,12 +22,16 @@ var XStarMdViewer = /*#__PURE__*/React.forwardRef(function (_ref, ref) {
22
22
  }, []);
23
23
  return /*#__PURE__*/React.createElement("div", {
24
24
  ref: container,
25
- className: cx('x-star-md-viewer', 'container', 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
  })));
31
32
  });
32
33
  XStarMdViewer.displayName = 'XStarMdViewer';
33
- export default XStarMdViewer;
34
+ export default XStarMdViewer;
35
+ export var useMdViewerRef = function useMdViewerRef() {
36
+ return useRef(null);
37
+ };
@@ -1,10 +1,15 @@
1
- .container {
1
+ @import '../styles/global.less';
2
+
3
+ .@{prefix}md-viewer {
2
4
  position: relative;
3
- margin: 0 -1px;
4
5
  padding: 0 1em;
5
6
  color: #000000d9;
6
7
  background-color: white;
7
8
  border: 1px solid #d0d0d0;
8
9
  border-radius: 0.2em;
9
10
  overflow: auto;
11
+
12
+ ::selection {
13
+ background: #c1def1;
14
+ }
10
15
  }
@@ -1,4 +1,5 @@
1
1
  import React from 'react';
2
+ import './FileInput.less';
2
3
  interface FileInputProps {
3
4
  onCancel: () => void;
4
5
  onOk: (data: ({
@@ -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/bind';
11
+ import classNames from 'classnames';
8
12
  import React, { useState } from 'react';
9
- import styles from "./FileInput.module.css";
10
- var cx = classNames.bind(styles);
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: cx('container')
36
+ className: classNames("".concat(prefix, "file-input"))
33
37
  }, /*#__PURE__*/React.createElement("div", {
34
- className: cx('tabs')
38
+ className: classNames("".concat(prefix, "tabs"))
35
39
  }, /*#__PURE__*/React.createElement("div", {
36
- className: cx('tab', {
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: cx('tab', {
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: cx('field')
50
+ className: classNames("".concat(prefix, "field"))
51
51
  }, "\u6587\u4EF6", /*#__PURE__*/React.createElement("div", {
52
- className: cx('file-container')
52
+ className: classNames("".concat(prefix, "file-container"))
53
53
  }, /*#__PURE__*/React.createElement("input", {
54
- className: cx('hidden'),
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: cx('input', 'file-input'),
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: cx('button', 'file-button'),
65
+ className: classNames("".concat(prefix, "button")),
66
66
  type: "button"
67
67
  }, "\u9009\u62E9\u6587\u4EF6"))) : /*#__PURE__*/React.createElement("label", {
68
- className: cx('field')
68
+ className: classNames("".concat(prefix, "field"))
69
69
  }, "\u7F51\u5740", /*#__PURE__*/React.createElement("input", {
70
- className: cx('input'),
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: cx('field')
75
+ className: classNames("".concat(prefix, "field"))
76
76
  }, "\u63CF\u8FF0", /*#__PURE__*/React.createElement("input", {
77
- className: cx('input'),
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: cx('buttons')
82
+ className: classNames("".concat(prefix, "buttons"))
83
83
  }, /*#__PURE__*/React.createElement("button", {
84
- className: cx('button', 'primary'),
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: cx('button'),
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,5 +1,6 @@
1
1
  import React from 'react';
2
2
  import type { Executor } from '../utils/handler';
3
+ import './Toolbar.less';
3
4
  export interface ToolbarItem {
4
5
  children: React.ReactNode;
5
6
  tooltip?: React.ReactNode;