x-star-editor 0.3.1 → 0.3.3
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.
|
@@ -34,7 +34,7 @@ import { redoHandler, toggleHandler, undoHandler } from "../utils/handler";
|
|
|
34
34
|
import { toHTML, toMarkdown } from "../utils/markdown";
|
|
35
35
|
import Fade from "./Fade";
|
|
36
36
|
import FileInput from "./FileInput";
|
|
37
|
-
var
|
|
37
|
+
var Item = function Item(_ref) {
|
|
38
38
|
var _classNames;
|
|
39
39
|
var children = _ref.children,
|
|
40
40
|
toolbarRef = _ref.toolbarRef,
|
|
@@ -81,9 +81,9 @@ var Button = function Button(_ref) {
|
|
|
81
81
|
}
|
|
82
82
|
}, [popoverMount]);
|
|
83
83
|
return /*#__PURE__*/React.createElement("div", {
|
|
84
|
-
className: classNames("".concat(prefix, "
|
|
84
|
+
className: classNames("".concat(prefix, "item-container"))
|
|
85
85
|
}, /*#__PURE__*/React.createElement("div", {
|
|
86
|
-
className: classNames("".concat(prefix, "
|
|
86
|
+
className: classNames("".concat(prefix, "item"), (_classNames = {}, _defineProperty(_classNames, "".concat(prefix, "disabled"), disabled), _defineProperty(_classNames, "".concat(prefix, "active"), tooltipOpen || popoverMount), _classNames)),
|
|
87
87
|
onClick: function onClick() {
|
|
88
88
|
if (!disabled) {
|
|
89
89
|
setPopoverOpen(true);
|
|
@@ -564,7 +564,7 @@ var Toolbar = function Toolbar(_ref9) {
|
|
|
564
564
|
tooltip = _ref10.tooltip,
|
|
565
565
|
_popoverRender = _ref10.popoverRender,
|
|
566
566
|
_onClick2 = _ref10.onClick;
|
|
567
|
-
return /*#__PURE__*/React.createElement(
|
|
567
|
+
return /*#__PURE__*/React.createElement(Item, {
|
|
568
568
|
key: index,
|
|
569
569
|
toolbarRef: toolbarRef,
|
|
570
570
|
disabled: disabled,
|
package/dist/styles/index.css
CHANGED
|
@@ -86,10 +86,10 @@
|
|
|
86
86
|
position: relative;
|
|
87
87
|
color: rgba(0, 0, 0, 0.88);
|
|
88
88
|
}
|
|
89
|
-
.x-star-editor-toolbar .x-star-editor-
|
|
89
|
+
.x-star-editor-toolbar .x-star-editor-item-container {
|
|
90
90
|
position: relative;
|
|
91
91
|
}
|
|
92
|
-
.x-star-editor-toolbar .x-star-editor-
|
|
92
|
+
.x-star-editor-toolbar .x-star-editor-item-container .x-star-editor-item {
|
|
93
93
|
width: 2em;
|
|
94
94
|
height: 2em;
|
|
95
95
|
display: flex;
|
|
@@ -99,20 +99,20 @@
|
|
|
99
99
|
cursor: pointer;
|
|
100
100
|
user-select: none;
|
|
101
101
|
}
|
|
102
|
-
.x-star-editor-toolbar .x-star-editor-
|
|
102
|
+
.x-star-editor-toolbar .x-star-editor-item-container .x-star-editor-item.x-star-editor-disabled::before {
|
|
103
103
|
content: "";
|
|
104
104
|
position: absolute;
|
|
105
105
|
inset: 0;
|
|
106
106
|
background-color: rgba(230, 247, 255, 0.7);
|
|
107
107
|
cursor: not-allowed;
|
|
108
108
|
}
|
|
109
|
-
.x-star-editor-toolbar .x-star-editor-
|
|
109
|
+
.x-star-editor-toolbar .x-star-editor-item-container .x-star-editor-item.x-star-editor-active {
|
|
110
110
|
background-color: #cbedfd;
|
|
111
111
|
}
|
|
112
|
-
.x-star-editor-toolbar .x-star-editor-
|
|
112
|
+
.x-star-editor-toolbar .x-star-editor-item-container .x-star-editor-item .x-star-editor-icon {
|
|
113
113
|
font-size: 1.75em;
|
|
114
114
|
}
|
|
115
|
-
.x-star-editor-toolbar .x-star-editor-
|
|
115
|
+
.x-star-editor-toolbar .x-star-editor-item-container .x-star-editor-tooltip {
|
|
116
116
|
position: absolute;
|
|
117
117
|
top: 3em;
|
|
118
118
|
width: max-content;
|
|
@@ -127,7 +127,7 @@
|
|
|
127
127
|
transform: translate(calc(1.25em - 50%));
|
|
128
128
|
transition: opacity 0.3s;
|
|
129
129
|
}
|
|
130
|
-
.x-star-editor-toolbar .x-star-editor-
|
|
130
|
+
.x-star-editor-toolbar .x-star-editor-item-container .x-star-editor-tooltip::before {
|
|
131
131
|
content: "";
|
|
132
132
|
position: absolute;
|
|
133
133
|
top: -0.3em;
|
|
@@ -137,7 +137,7 @@
|
|
|
137
137
|
transform-origin: 0 0;
|
|
138
138
|
transform: rotate(45deg);
|
|
139
139
|
}
|
|
140
|
-
.x-star-editor-toolbar .x-star-editor-
|
|
140
|
+
.x-star-editor-toolbar .x-star-editor-item-container .x-star-editor-popover {
|
|
141
141
|
position: absolute;
|
|
142
142
|
width: max-content;
|
|
143
143
|
background-color: #fff;
|
|
@@ -148,12 +148,12 @@
|
|
|
148
148
|
z-index: 1;
|
|
149
149
|
transition: opacity 0.3s;
|
|
150
150
|
}
|
|
151
|
-
.x-star-editor-toolbar .x-star-editor-
|
|
151
|
+
.x-star-editor-toolbar .x-star-editor-item-container .x-star-editor-popover .x-star-editor-option {
|
|
152
152
|
padding: 6px 12px;
|
|
153
153
|
cursor: pointer;
|
|
154
154
|
user-select: none;
|
|
155
155
|
}
|
|
156
|
-
.x-star-editor-toolbar .x-star-editor-
|
|
156
|
+
.x-star-editor-toolbar .x-star-editor-item-container .x-star-editor-popover .x-star-editor-option:hover {
|
|
157
157
|
background-color: #e6f7ff;
|
|
158
158
|
}
|
|
159
159
|
.x-star-editor-toolbar .x-star-editor-divider {
|
|
@@ -173,15 +173,15 @@
|
|
|
173
173
|
display: flex;
|
|
174
174
|
flex-wrap: wrap;
|
|
175
175
|
}
|
|
176
|
-
.x-star-editor-editor .x-star-editor-toolbar {
|
|
176
|
+
.x-star-editor-editor > .x-star-editor-toolbar {
|
|
177
177
|
width: 100%;
|
|
178
178
|
}
|
|
179
|
-
.x-star-editor-editor .x-star-editor-md-editor {
|
|
179
|
+
.x-star-editor-editor > .x-star-editor-md-editor {
|
|
180
180
|
flex: 1;
|
|
181
181
|
border-right: none;
|
|
182
182
|
border-bottom-right-radius: 0;
|
|
183
183
|
}
|
|
184
|
-
.x-star-editor-editor .x-star-editor-md-viewer {
|
|
184
|
+
.x-star-editor-editor > .x-star-editor-md-viewer {
|
|
185
185
|
padding: 0 1em;
|
|
186
186
|
flex: 1;
|
|
187
187
|
background-color: #fff;
|
package/dist/utils/handler.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import _createForOfIteratorHelper from "@babel/runtime/helpers/esm/createForOfIteratorHelper";
|
|
2
2
|
import { createKeybindingsHandler } from 'tinykeys';
|
|
3
|
-
import { createSelection
|
|
3
|
+
import { createSelection } from "./container";
|
|
4
4
|
|
|
5
5
|
/**
|
|
6
6
|
* 处理函数上下文
|
|
@@ -116,56 +116,22 @@ export var getDefaultKeyboardEventHandlers = function getDefaultKeyboardEventHan
|
|
|
116
116
|
type: 'redo'
|
|
117
117
|
});
|
|
118
118
|
},
|
|
119
|
-
|
|
120
|
-
e.preventDefault();
|
|
121
|
-
var _getRange = getRange(selection),
|
|
122
|
-
startOffset = _getRange.startOffset,
|
|
123
|
-
endOffset = _getRange.endOffset;
|
|
124
|
-
if (startOffset < endOffset) {
|
|
125
|
-
dispatch({
|
|
126
|
-
type: 'select',
|
|
127
|
-
selection: createSelection(startOffset)
|
|
128
|
-
});
|
|
129
|
-
} else if (startOffset) {
|
|
130
|
-
dispatch({
|
|
131
|
-
type: 'select',
|
|
132
|
-
selection: createSelection(startOffset - 1)
|
|
133
|
-
});
|
|
134
|
-
}
|
|
135
|
-
},
|
|
136
|
-
'Shift+ArrowLeft': function ShiftArrowLeft(e) {
|
|
137
|
-
e.preventDefault();
|
|
119
|
+
ArrowRight: function ArrowRight(e) {
|
|
138
120
|
var anchorOffset = selection.anchorOffset,
|
|
139
121
|
focusOffset = selection.focusOffset;
|
|
140
|
-
if (focusOffset) {
|
|
122
|
+
if (anchorOffset === focusOffset && sourceCode[focusOffset] === '\n') {
|
|
123
|
+
e.preventDefault();
|
|
141
124
|
dispatch({
|
|
142
125
|
type: 'select',
|
|
143
|
-
selection: createSelection(
|
|
144
|
-
});
|
|
145
|
-
}
|
|
146
|
-
},
|
|
147
|
-
ArrowRight: function ArrowRight(e) {
|
|
148
|
-
e.preventDefault();
|
|
149
|
-
var _getRange2 = getRange(selection),
|
|
150
|
-
startOffset = _getRange2.startOffset,
|
|
151
|
-
endOffset = _getRange2.endOffset;
|
|
152
|
-
if (startOffset < endOffset) {
|
|
153
|
-
dispatch({
|
|
154
|
-
type: 'select',
|
|
155
|
-
selection: createSelection(endOffset)
|
|
156
|
-
});
|
|
157
|
-
} else if (startOffset < sourceCode.length) {
|
|
158
|
-
dispatch({
|
|
159
|
-
type: 'select',
|
|
160
|
-
selection: createSelection(startOffset + 1)
|
|
126
|
+
selection: createSelection(focusOffset + 1)
|
|
161
127
|
});
|
|
162
128
|
}
|
|
163
129
|
},
|
|
164
130
|
'Shift+ArrowRight': function ShiftArrowRight(e) {
|
|
165
|
-
e.preventDefault();
|
|
166
131
|
var anchorOffset = selection.anchorOffset,
|
|
167
132
|
focusOffset = selection.focusOffset;
|
|
168
|
-
if (focusOffset
|
|
133
|
+
if (sourceCode[focusOffset] === '\n') {
|
|
134
|
+
e.preventDefault();
|
|
169
135
|
dispatch({
|
|
170
136
|
type: 'select',
|
|
171
137
|
selection: createSelection(anchorOffset, focusOffset + 1)
|
package/dist/utils/markdown.js
CHANGED
|
@@ -331,6 +331,9 @@ export var viewerRender = function viewerRender(root, schema) {
|
|
|
331
331
|
*/
|
|
332
332
|
export var postViewerRender = function postViewerRender(root, options) {
|
|
333
333
|
var components = _objectSpread(_objectSpread({}, options.customHTMLElements), {}, {
|
|
334
|
+
input: function input(props) {
|
|
335
|
+
return jsx('input', props);
|
|
336
|
+
},
|
|
334
337
|
custom: function custom(props) {
|
|
335
338
|
var _options$customBlocks;
|
|
336
339
|
return jsx((_options$customBlocks = options.customBlocks[props.meta]) !== null && _options$customBlocks !== void 0 ? _options$customBlocks : 'div', {
|
|
@@ -6,17 +6,40 @@ import React, { useEffect, useImperativeHandle, useRef, useState } from 'react';
|
|
|
6
6
|
import { prefix } from "../utils/global";
|
|
7
7
|
import XStarMdEditor, { useMdEditorRef } from "../x-star-md-editor";
|
|
8
8
|
import XStarMdViewer, { useMdViewerRef } from "../x-star-md-viewer";
|
|
9
|
-
var
|
|
10
|
-
var
|
|
9
|
+
var ViewerRenderWrapper = /*#__PURE__*/React.forwardRef(function (_ref, ref) {
|
|
10
|
+
var children = _ref.children,
|
|
11
|
+
className = _ref.className,
|
|
11
12
|
style = _ref.style,
|
|
12
|
-
height = _ref.height
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
13
|
+
height = _ref.height;
|
|
14
|
+
var containerRef = useRef(null);
|
|
15
|
+
useImperativeHandle(ref, function () {
|
|
16
|
+
return {
|
|
17
|
+
getViewerContainer: function getViewerContainer() {
|
|
18
|
+
return containerRef.current;
|
|
19
|
+
}
|
|
20
|
+
};
|
|
21
|
+
}, []);
|
|
22
|
+
return /*#__PURE__*/React.createElement("div", {
|
|
23
|
+
ref: containerRef,
|
|
24
|
+
className: classNames("".concat(prefix, "md-viewer"), className),
|
|
25
|
+
style: _objectSpread(_objectSpread({}, style), {}, {
|
|
26
|
+
height: height
|
|
27
|
+
})
|
|
28
|
+
}, children);
|
|
29
|
+
});
|
|
30
|
+
var XStarEditor = /*#__PURE__*/React.forwardRef(function (_ref2, ref) {
|
|
31
|
+
var className = _ref2.className,
|
|
32
|
+
style = _ref2.style,
|
|
33
|
+
height = _ref2.height,
|
|
34
|
+
locale = _ref2.locale,
|
|
35
|
+
_ref2$initialValue = _ref2.initialValue,
|
|
36
|
+
initialValue = _ref2$initialValue === void 0 ? '' : _ref2$initialValue,
|
|
37
|
+
enableWebWorker = _ref2.enableWebWorker,
|
|
38
|
+
editorProps = _ref2.editorProps,
|
|
39
|
+
viewerProps = _ref2.viewerProps,
|
|
40
|
+
viewerRender = _ref2.viewerRender,
|
|
41
|
+
_onChange = _ref2.onChange,
|
|
42
|
+
onInsertFile = _ref2.onInsertFile;
|
|
20
43
|
var editorRef = useMdEditorRef();
|
|
21
44
|
var viewerRef = useMdViewerRef();
|
|
22
45
|
var containerRef = useRef(null);
|
|
@@ -94,10 +117,10 @@ var XStarEditor = /*#__PURE__*/React.forwardRef(function (_ref, ref) {
|
|
|
94
117
|
if (ignore || !editor || !viewer) {
|
|
95
118
|
return;
|
|
96
119
|
}
|
|
97
|
-
var
|
|
98
|
-
|
|
99
|
-
fromElement =
|
|
100
|
-
toElement =
|
|
120
|
+
var _ref3 = e.currentTarget === editor ? [editor, viewer] : [viewer, editor],
|
|
121
|
+
_ref4 = _slicedToArray(_ref3, 2),
|
|
122
|
+
fromElement = _ref4[0],
|
|
123
|
+
toElement = _ref4[1];
|
|
101
124
|
var _getOffsetTops = getOffsetTops(fromElement, toElement),
|
|
102
125
|
_getOffsetTops2 = _slicedToArray(_getOffsetTops, 2),
|
|
103
126
|
fromOffsetTops = _getOffsetTops2[0],
|
|
@@ -149,7 +172,12 @@ var XStarEditor = /*#__PURE__*/React.forwardRef(function (_ref, ref) {
|
|
|
149
172
|
_onChange === null || _onChange === void 0 ? void 0 : _onChange(value);
|
|
150
173
|
},
|
|
151
174
|
onInsertFile: onInsertFile
|
|
152
|
-
})), /*#__PURE__*/React.createElement(
|
|
175
|
+
})), viewerRender ? /*#__PURE__*/React.createElement(ViewerRenderWrapper, {
|
|
176
|
+
ref: viewerRef,
|
|
177
|
+
className: viewerProps === null || viewerProps === void 0 ? void 0 : viewerProps.className,
|
|
178
|
+
style: viewerProps === null || viewerProps === void 0 ? void 0 : viewerProps.style,
|
|
179
|
+
height: height
|
|
180
|
+
}, viewerRender(value)) : /*#__PURE__*/React.createElement(XStarMdViewer, _extends({
|
|
153
181
|
ref: viewerRef
|
|
154
182
|
}, viewerProps, {
|
|
155
183
|
height: height,
|