x-star-editor 0.3.2 → 0.3.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/components/Toolbar.js +58 -50
- package/dist/locales/index.d.ts +1 -1
- package/dist/locales/index.js +3 -1
- package/dist/styles/index.css +59 -36
- package/dist/utils/container.js +2 -7
- package/dist/utils/markdown.js +17 -2
- package/dist/x-star-editor/index.js +75 -17
- package/dist/x-star-md-editor/index.js +1 -1
- package/package.json +1 -1
|
@@ -5,10 +5,7 @@ import React, { useEffect, useRef, useState } from 'react';
|
|
|
5
5
|
import SvgBlockquote from "../icons/Blockquote";
|
|
6
6
|
import SvgCode from "../icons/Code";
|
|
7
7
|
import SvgDelete from "../icons/Delete";
|
|
8
|
-
import SvgEditOnly from "../icons/EditOnly";
|
|
9
8
|
import SvgEmphasis from "../icons/Emphasis";
|
|
10
|
-
import SvgEnterFullscreen from "../icons/EnterFullscreen";
|
|
11
|
-
import SvgExitFullscreen from "../icons/ExitFullscreen";
|
|
12
9
|
import SvgHeading from "../icons/Heading";
|
|
13
10
|
import SvgHelp from "../icons/Help";
|
|
14
11
|
import SvgImage from "../icons/Image";
|
|
@@ -27,14 +24,13 @@ import SvgToHTML from "../icons/ToHtml";
|
|
|
27
24
|
import SvgToMarkdown from "../icons/ToMarkdown";
|
|
28
25
|
import SvgUndo from "../icons/Undo";
|
|
29
26
|
import SvgUnorderedList from "../icons/UnorderedList";
|
|
30
|
-
import SvgViewOnly from "../icons/ViewOnly";
|
|
31
27
|
import { getFormat } from "../locales";
|
|
32
28
|
import { prefix } from "../utils/global";
|
|
33
29
|
import { redoHandler, toggleHandler, undoHandler } from "../utils/handler";
|
|
34
30
|
import { toHTML, toMarkdown } from "../utils/markdown";
|
|
35
31
|
import Fade from "./Fade";
|
|
36
32
|
import FileInput from "./FileInput";
|
|
37
|
-
var
|
|
33
|
+
var Item = function Item(_ref) {
|
|
38
34
|
var _classNames;
|
|
39
35
|
var children = _ref.children,
|
|
40
36
|
toolbarRef = _ref.toolbarRef,
|
|
@@ -70,8 +66,7 @@ var Button = function Button(_ref) {
|
|
|
70
66
|
}
|
|
71
67
|
};
|
|
72
68
|
document.addEventListener('click', listener, {
|
|
73
|
-
capture: true
|
|
74
|
-
passive: true
|
|
69
|
+
capture: true
|
|
75
70
|
});
|
|
76
71
|
return function () {
|
|
77
72
|
return document.removeEventListener('click', listener, {
|
|
@@ -81,11 +76,12 @@ var Button = function Button(_ref) {
|
|
|
81
76
|
}
|
|
82
77
|
}, [popoverMount]);
|
|
83
78
|
return /*#__PURE__*/React.createElement("div", {
|
|
84
|
-
className: classNames("".concat(prefix, "
|
|
79
|
+
className: classNames("".concat(prefix, "item-container"))
|
|
85
80
|
}, /*#__PURE__*/React.createElement("div", {
|
|
86
|
-
className: classNames("".concat(prefix, "
|
|
81
|
+
className: classNames("".concat(prefix, "item"), (_classNames = {}, _defineProperty(_classNames, "".concat(prefix, "disabled"), disabled), _defineProperty(_classNames, "".concat(prefix, "active"), tooltipOpen || popoverMount), _classNames)),
|
|
87
82
|
onClick: function onClick() {
|
|
88
83
|
if (!disabled) {
|
|
84
|
+
setTooltipOpen(false);
|
|
89
85
|
setPopoverOpen(true);
|
|
90
86
|
_onClick === null || _onClick === void 0 ? void 0 : _onClick();
|
|
91
87
|
}
|
|
@@ -144,22 +140,42 @@ var headingOptions = [{
|
|
|
144
140
|
depth: 6,
|
|
145
141
|
fontSize: '0.9em'
|
|
146
142
|
}];
|
|
147
|
-
var mermaidOptions = [
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
143
|
+
var mermaidOptions = [
|
|
144
|
+
// {
|
|
145
|
+
// label: 'Flowchart',
|
|
146
|
+
// value: `flowchart TD
|
|
147
|
+
// A[Start] --> B{Is it?}
|
|
148
|
+
// B -- Yes --> C[OK]
|
|
149
|
+
// C --> D[Rethink]
|
|
150
|
+
// D --> B
|
|
151
|
+
// B -- No ----> E[End]`,
|
|
152
|
+
// },
|
|
153
|
+
{
|
|
151
154
|
label: 'Sequence Diagram',
|
|
152
155
|
value: "sequenceDiagram\n Alice->>John: Hello John, how are you?\n John-->>Alice: Great!\n Alice-)John: See you later!"
|
|
153
156
|
}, {
|
|
154
157
|
label: 'Class Diagram',
|
|
155
158
|
value: "classDiagram\n class BankAccount\n BankAccount : +String owner\n BankAccount : +Bigdecimal balance\n BankAccount : +deposit(amount)\n BankAccount : +withdrawal(amount)"
|
|
156
|
-
},
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
159
|
+
},
|
|
160
|
+
// {
|
|
161
|
+
// label: 'State Diagram',
|
|
162
|
+
// value: `stateDiagram-v2
|
|
163
|
+
// [*] --> Still
|
|
164
|
+
// Still --> [*]
|
|
165
|
+
|
|
166
|
+
// Still --> Moving
|
|
167
|
+
// Moving --> Still
|
|
168
|
+
// Moving --> Crash
|
|
169
|
+
// Crash --> [*]`,
|
|
170
|
+
// },
|
|
171
|
+
// {
|
|
172
|
+
// label: 'Entity Relationship Diagram',
|
|
173
|
+
// value: `erDiagram
|
|
174
|
+
// CUSTOMER ||--o{ ORDER : places
|
|
175
|
+
// ORDER ||--|{ LINE-ITEM : contains
|
|
176
|
+
// CUSTOMER }|..|{ DELIVERY-ADDRESS : uses`,
|
|
177
|
+
// },
|
|
178
|
+
{
|
|
163
179
|
label: 'User Journey',
|
|
164
180
|
value: "journey\n title My working day\n section Go to work\n Make tea: 5: Me\n Go upstairs: 3: Me\n Do work: 1: Me, Cat\n section Go home\n Go downstairs: 5: Me\n Sit down: 5: Me"
|
|
165
181
|
}, {
|
|
@@ -171,10 +187,25 @@ var mermaidOptions = [{
|
|
|
171
187
|
}, {
|
|
172
188
|
label: 'Quadrant Chart',
|
|
173
189
|
value: "quadrantChart\n title Reach and engagement of campaigns\n x-axis Low Reach --> High Reach\n y-axis Low Engagement --> High Engagement\n quadrant-1 We should expand\n quadrant-2 Need to promote\n quadrant-3 Re-evaluate\n quadrant-4 May be improved\n Campaign A: [0.3, 0.6]\n Campaign B: [0.45, 0.23]\n Campaign C: [0.57, 0.69]\n Campaign D: [0.78, 0.34]\n Campaign E: [0.40, 0.34]\n Campaign F: [0.35, 0.78]"
|
|
174
|
-
},
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
190
|
+
},
|
|
191
|
+
// {
|
|
192
|
+
// label: 'Requirement Diagram',
|
|
193
|
+
// value: `requirementDiagram
|
|
194
|
+
|
|
195
|
+
// requirement test_req {
|
|
196
|
+
// id: 1
|
|
197
|
+
// text: the test text.
|
|
198
|
+
// risk: high
|
|
199
|
+
// verifymethod: test
|
|
200
|
+
// }
|
|
201
|
+
|
|
202
|
+
// element test_entity {
|
|
203
|
+
// type: simulation
|
|
204
|
+
// }
|
|
205
|
+
|
|
206
|
+
// test_entity - satisfies -> test_req`,
|
|
207
|
+
// },
|
|
208
|
+
{
|
|
178
209
|
label: 'Gitgraph (Git) Diagram',
|
|
179
210
|
value: "gitGraph\n commit\n commit\n branch develop\n checkout develop\n commit\n commit\n checkout main\n merge develop\n commit\n commit"
|
|
180
211
|
}, {
|
|
@@ -184,10 +215,7 @@ var mermaidOptions = [{
|
|
|
184
215
|
label: 'Timeline',
|
|
185
216
|
value: "timeline\n title History of Social Media Platform\n 2002 : LinkedIn\n 2004 : Facebook\n : Google\n 2005 : Youtube\n 2006 : Twitter"
|
|
186
217
|
}];
|
|
187
|
-
export var getDefaultToolbarItemMap = function getDefaultToolbarItemMap() {
|
|
188
|
-
var _SvgEnterFullscreen, _t;
|
|
189
|
-
var locale = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : '';
|
|
190
|
-
var onInsertFile = arguments.length > 1 ? arguments[1] : undefined;
|
|
218
|
+
export var getDefaultToolbarItemMap = function getDefaultToolbarItemMap(locale, onInsertFile) {
|
|
191
219
|
var t = getFormat(locale, 'toolbarItem');
|
|
192
220
|
return {
|
|
193
221
|
blockquote: {
|
|
@@ -237,12 +265,6 @@ export var getDefaultToolbarItemMap = function getDefaultToolbarItemMap() {
|
|
|
237
265
|
}));
|
|
238
266
|
}
|
|
239
267
|
},
|
|
240
|
-
editOnly: {
|
|
241
|
-
children: /*#__PURE__*/React.createElement(SvgEditOnly, {
|
|
242
|
-
className: classNames("".concat(prefix, "icon"))
|
|
243
|
-
}),
|
|
244
|
-
tooltip: t('editOnly')
|
|
245
|
-
},
|
|
246
268
|
emphasis: {
|
|
247
269
|
children: /*#__PURE__*/React.createElement(SvgEmphasis, {
|
|
248
270
|
className: classNames("".concat(prefix, "icon"))
|
|
@@ -254,14 +276,6 @@ export var getDefaultToolbarItemMap = function getDefaultToolbarItemMap() {
|
|
|
254
276
|
}));
|
|
255
277
|
}
|
|
256
278
|
},
|
|
257
|
-
fullscreen: {
|
|
258
|
-
children: (_SvgEnterFullscreen = /*#__PURE__*/React.createElement(SvgEnterFullscreen, {
|
|
259
|
-
className: classNames("".concat(prefix, "icon"))
|
|
260
|
-
})) !== null && _SvgEnterFullscreen !== void 0 ? _SvgEnterFullscreen : /*#__PURE__*/React.createElement(SvgExitFullscreen, {
|
|
261
|
-
className: classNames("".concat(prefix, "icon"))
|
|
262
|
-
}),
|
|
263
|
-
tooltip: (_t = t('enterFullscreen')) !== null && _t !== void 0 ? _t : t('exitFullscreen')
|
|
264
|
-
},
|
|
265
279
|
heading: {
|
|
266
280
|
children: /*#__PURE__*/React.createElement(SvgHeading, {
|
|
267
281
|
className: classNames("".concat(prefix, "icon"))
|
|
@@ -517,12 +531,6 @@ export var getDefaultToolbarItemMap = function getDefaultToolbarItemMap() {
|
|
|
517
531
|
className: classNames("".concat(prefix, "icon"))
|
|
518
532
|
}),
|
|
519
533
|
tooltip: t('unorderedList')
|
|
520
|
-
},
|
|
521
|
-
viewOnly: {
|
|
522
|
-
children: /*#__PURE__*/React.createElement(SvgViewOnly, {
|
|
523
|
-
className: classNames("".concat(prefix, "icon"))
|
|
524
|
-
}),
|
|
525
|
-
tooltip: t('viewOnly')
|
|
526
534
|
}
|
|
527
535
|
};
|
|
528
536
|
};
|
|
@@ -530,7 +538,7 @@ export var getDefaultToolbarItems = function getDefaultToolbarItems() {
|
|
|
530
538
|
return [['heading', 'strong', 'emphasis', 'delete'], ['thematicBreak', 'blockquote' /** 'table' */], ['link', 'image', 'mermaid'], ['inlineCode', 'code', 'inlineMath', 'math'], ['undo', 'redo'],
|
|
531
539
|
// ['orderedList', 'unorderedList', 'taskList'],
|
|
532
540
|
['toMarkdown', 'toHTML']
|
|
533
|
-
// ['help'
|
|
541
|
+
// ['help'],
|
|
534
542
|
];
|
|
535
543
|
};
|
|
536
544
|
|
|
@@ -564,7 +572,7 @@ var Toolbar = function Toolbar(_ref9) {
|
|
|
564
572
|
tooltip = _ref10.tooltip,
|
|
565
573
|
_popoverRender = _ref10.popoverRender,
|
|
566
574
|
_onClick2 = _ref10.onClick;
|
|
567
|
-
return /*#__PURE__*/React.createElement(
|
|
575
|
+
return /*#__PURE__*/React.createElement(Item, {
|
|
568
576
|
key: index,
|
|
569
577
|
toolbarRef: toolbarRef,
|
|
570
578
|
disabled: disabled,
|
package/dist/locales/index.d.ts
CHANGED
|
@@ -85,7 +85,7 @@ export declare const useLocale: <T extends "fileInput" | "toolbarItem">(slice: T
|
|
|
85
85
|
};
|
|
86
86
|
})[T][U];
|
|
87
87
|
};
|
|
88
|
-
export declare const getFormat: <T extends "fileInput" | "toolbarItem">(locale: string, slice: T) => <U extends keyof MessageMap[T]>(key: U) => ({
|
|
88
|
+
export declare const getFormat: <T extends "fileInput" | "toolbarItem">(locale: string | undefined, slice: T) => <U extends keyof MessageMap[T]>(key: U) => ({
|
|
89
89
|
readonly fileInput: {
|
|
90
90
|
readonly cancel: "取消";
|
|
91
91
|
readonly chooseFile: "选择文件";
|
package/dist/locales/index.js
CHANGED
|
@@ -30,8 +30,10 @@ export var useLocale = function useLocale(slice) {
|
|
|
30
30
|
format: format
|
|
31
31
|
};
|
|
32
32
|
};
|
|
33
|
-
export var getFormat = function getFormat(
|
|
33
|
+
export var getFormat = function getFormat() {
|
|
34
34
|
var _zh_CN$en_US$locale2;
|
|
35
|
+
var locale = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : '';
|
|
36
|
+
var slice = arguments.length > 1 ? arguments[1] : undefined;
|
|
35
37
|
var message = ((_zh_CN$en_US$locale2 = {
|
|
36
38
|
zh_CN: zh_CN,
|
|
37
39
|
en_US: en_US
|
package/dist/styles/index.css
CHANGED
|
@@ -75,6 +75,8 @@
|
|
|
75
75
|
}
|
|
76
76
|
|
|
77
77
|
.x-star-editor-toolbar {
|
|
78
|
+
position: relative;
|
|
79
|
+
color: rgba(0, 0, 0, 0.88);
|
|
78
80
|
padding: 0.5em 1em;
|
|
79
81
|
display: flex;
|
|
80
82
|
flex-wrap: wrap;
|
|
@@ -83,13 +85,19 @@
|
|
|
83
85
|
border: 1px solid #dedede;
|
|
84
86
|
border-top-left-radius: 0.3em;
|
|
85
87
|
border-top-right-radius: 0.3em;
|
|
86
|
-
position: relative;
|
|
87
|
-
color: rgba(0, 0, 0, 0.88);
|
|
88
88
|
}
|
|
89
|
-
.x-star-editor-toolbar
|
|
89
|
+
.x-star-editor-toolbar *,
|
|
90
|
+
.x-star-editor-toolbar ::before,
|
|
91
|
+
.x-star-editor-toolbar ::after {
|
|
92
|
+
box-sizing: border-box;
|
|
93
|
+
}
|
|
94
|
+
.x-star-editor-toolbar ::selection {
|
|
95
|
+
background-color: #c1def1;
|
|
96
|
+
}
|
|
97
|
+
.x-star-editor-toolbar .x-star-editor-item-container {
|
|
90
98
|
position: relative;
|
|
91
99
|
}
|
|
92
|
-
.x-star-editor-toolbar .x-star-editor-
|
|
100
|
+
.x-star-editor-toolbar .x-star-editor-item-container .x-star-editor-item {
|
|
93
101
|
width: 2em;
|
|
94
102
|
height: 2em;
|
|
95
103
|
display: flex;
|
|
@@ -99,20 +107,23 @@
|
|
|
99
107
|
cursor: pointer;
|
|
100
108
|
user-select: none;
|
|
101
109
|
}
|
|
102
|
-
.x-star-editor-toolbar .x-star-editor-
|
|
110
|
+
.x-star-editor-toolbar .x-star-editor-item-container .x-star-editor-item.x-star-editor-disabled::before {
|
|
103
111
|
content: "";
|
|
104
112
|
position: absolute;
|
|
105
113
|
inset: 0;
|
|
106
114
|
background-color: rgba(230, 247, 255, 0.7);
|
|
107
115
|
cursor: not-allowed;
|
|
108
116
|
}
|
|
109
|
-
.x-star-editor-toolbar .x-star-editor-
|
|
117
|
+
.x-star-editor-toolbar .x-star-editor-item-container .x-star-editor-item.x-star-editor-active {
|
|
110
118
|
background-color: #cbedfd;
|
|
111
119
|
}
|
|
112
|
-
.x-star-editor-toolbar .x-star-editor-
|
|
120
|
+
.x-star-editor-toolbar .x-star-editor-item-container .x-star-editor-item .x-star-editor-icon {
|
|
113
121
|
font-size: 1.75em;
|
|
114
122
|
}
|
|
115
|
-
.x-star-editor-toolbar .x-star-editor-
|
|
123
|
+
.x-star-editor-toolbar .x-star-editor-item-container .x-star-editor-item .x-star-editor-icon.x-star-editor-active {
|
|
124
|
+
color: #1890ff;
|
|
125
|
+
}
|
|
126
|
+
.x-star-editor-toolbar .x-star-editor-item-container .x-star-editor-tooltip {
|
|
116
127
|
position: absolute;
|
|
117
128
|
top: 3em;
|
|
118
129
|
width: max-content;
|
|
@@ -127,7 +138,7 @@
|
|
|
127
138
|
transform: translate(calc(1.25em - 50%));
|
|
128
139
|
transition: opacity 0.3s;
|
|
129
140
|
}
|
|
130
|
-
.x-star-editor-toolbar .x-star-editor-
|
|
141
|
+
.x-star-editor-toolbar .x-star-editor-item-container .x-star-editor-tooltip::before {
|
|
131
142
|
content: "";
|
|
132
143
|
position: absolute;
|
|
133
144
|
top: -0.3em;
|
|
@@ -137,7 +148,7 @@
|
|
|
137
148
|
transform-origin: 0 0;
|
|
138
149
|
transform: rotate(45deg);
|
|
139
150
|
}
|
|
140
|
-
.x-star-editor-toolbar .x-star-editor-
|
|
151
|
+
.x-star-editor-toolbar .x-star-editor-item-container .x-star-editor-popover {
|
|
141
152
|
position: absolute;
|
|
142
153
|
width: max-content;
|
|
143
154
|
background-color: #fff;
|
|
@@ -148,68 +159,74 @@
|
|
|
148
159
|
z-index: 1;
|
|
149
160
|
transition: opacity 0.3s;
|
|
150
161
|
}
|
|
151
|
-
.x-star-editor-toolbar .x-star-editor-
|
|
162
|
+
.x-star-editor-toolbar .x-star-editor-item-container .x-star-editor-popover .x-star-editor-option {
|
|
152
163
|
padding: 6px 12px;
|
|
153
164
|
cursor: pointer;
|
|
154
165
|
user-select: none;
|
|
155
166
|
}
|
|
156
|
-
.x-star-editor-toolbar .x-star-editor-
|
|
167
|
+
.x-star-editor-toolbar .x-star-editor-item-container .x-star-editor-popover .x-star-editor-option:hover {
|
|
157
168
|
background-color: #e6f7ff;
|
|
158
169
|
}
|
|
159
170
|
.x-star-editor-toolbar .x-star-editor-divider {
|
|
160
171
|
margin: 0.4em;
|
|
161
172
|
border: 1px solid #dedede;
|
|
162
173
|
}
|
|
163
|
-
.x-star-editor-toolbar *,
|
|
164
|
-
.x-star-editor-toolbar ::before,
|
|
165
|
-
.x-star-editor-toolbar ::after {
|
|
166
|
-
box-sizing: border-box;
|
|
167
|
-
}
|
|
168
|
-
.x-star-editor-toolbar ::selection {
|
|
169
|
-
background-color: #c1def1;
|
|
170
|
-
}
|
|
171
174
|
|
|
172
175
|
.x-star-editor-editor {
|
|
173
176
|
display: flex;
|
|
174
177
|
flex-wrap: wrap;
|
|
175
178
|
}
|
|
176
|
-
.x-star-editor-editor
|
|
179
|
+
.x-star-editor-editor.x-star-editor-fullscreen {
|
|
180
|
+
position: fixed;
|
|
181
|
+
inset: 0;
|
|
182
|
+
z-index: 1000;
|
|
183
|
+
}
|
|
184
|
+
.x-star-editor-editor.x-star-editor-fullscreen > .x-star-editor-md-editor,
|
|
185
|
+
.x-star-editor-editor.x-star-editor-fullscreen > .x-star-editor-md-viewer {
|
|
186
|
+
height: calc(100% - 3em) !important;
|
|
187
|
+
}
|
|
188
|
+
.x-star-editor-editor > .x-star-editor-toolbar {
|
|
177
189
|
width: 100%;
|
|
178
190
|
}
|
|
179
|
-
.x-star-editor-editor .x-star-editor-md-editor {
|
|
191
|
+
.x-star-editor-editor > .x-star-editor-md-editor {
|
|
180
192
|
flex: 1;
|
|
181
193
|
border-right: none;
|
|
182
194
|
border-bottom-right-radius: 0;
|
|
183
195
|
}
|
|
184
|
-
.x-star-editor-editor .x-star-editor-md-viewer {
|
|
196
|
+
.x-star-editor-editor > .x-star-editor-md-viewer {
|
|
197
|
+
border: 1px solid #dedede;
|
|
198
|
+
border-top: none;
|
|
199
|
+
border-bottom-right-radius: 0.3em;
|
|
200
|
+
border-bottom-left-radius: 0.3em;
|
|
185
201
|
padding: 0 1em;
|
|
186
202
|
flex: 1;
|
|
187
203
|
background-color: #fff;
|
|
204
|
+
border-bottom-left-radius: 0;
|
|
205
|
+
overflow: auto;
|
|
206
|
+
}
|
|
207
|
+
.x-star-editor-editor > .x-star-editor-active {
|
|
188
208
|
border: 1px solid #dedede;
|
|
189
209
|
border-top: none;
|
|
190
210
|
border-bottom-right-radius: 0.3em;
|
|
191
|
-
|
|
211
|
+
border-bottom-left-radius: 0.3em;
|
|
212
|
+
}
|
|
213
|
+
.x-star-editor-editor > .x-star-editor-hidden {
|
|
214
|
+
display: none;
|
|
192
215
|
}
|
|
193
216
|
|
|
194
217
|
.x-star-editor-md-editor {
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
white-space: break-spaces;
|
|
198
|
-
background-color: #fff;
|
|
218
|
+
position: relative;
|
|
219
|
+
color: rgba(0, 0, 0, 0.88);
|
|
199
220
|
border: 1px solid #dedede;
|
|
200
221
|
border-top: none;
|
|
201
222
|
border-bottom-right-radius: 0.3em;
|
|
202
223
|
border-bottom-left-radius: 0.3em;
|
|
224
|
+
padding: 0 1em;
|
|
225
|
+
line-height: 1.6em;
|
|
226
|
+
white-space: break-spaces;
|
|
227
|
+
background-color: #fff;
|
|
203
228
|
outline: none;
|
|
204
229
|
overflow: auto;
|
|
205
|
-
position: relative;
|
|
206
|
-
color: rgba(0, 0, 0, 0.88);
|
|
207
|
-
}
|
|
208
|
-
.x-star-editor-md-editor > :first-child {
|
|
209
|
-
margin-top: 1em;
|
|
210
|
-
}
|
|
211
|
-
.x-star-editor-md-editor > :last-child {
|
|
212
|
-
margin-bottom: 1em;
|
|
213
230
|
}
|
|
214
231
|
.x-star-editor-md-editor *,
|
|
215
232
|
.x-star-editor-md-editor ::before,
|
|
@@ -219,6 +236,12 @@
|
|
|
219
236
|
.x-star-editor-md-editor ::selection {
|
|
220
237
|
background-color: #c1def1;
|
|
221
238
|
}
|
|
239
|
+
.x-star-editor-md-editor > :first-child {
|
|
240
|
+
margin-top: 1em;
|
|
241
|
+
}
|
|
242
|
+
.x-star-editor-md-editor > :last-child {
|
|
243
|
+
margin-bottom: 1em;
|
|
244
|
+
}
|
|
222
245
|
|
|
223
246
|
.x-star-editor-md-viewer {
|
|
224
247
|
position: relative;
|
package/dist/utils/container.js
CHANGED
|
@@ -330,14 +330,9 @@ export var useContainer = function useContainer(ref) {
|
|
|
330
330
|
selection.setBaseAndExtent(anchorNode, anchorOffset, focusNode, focusOffset);
|
|
331
331
|
}
|
|
332
332
|
};
|
|
333
|
-
document.addEventListener('selectionchange', listener
|
|
334
|
-
capture: true,
|
|
335
|
-
passive: true
|
|
336
|
-
});
|
|
333
|
+
document.addEventListener('selectionchange', listener);
|
|
337
334
|
return function () {
|
|
338
|
-
return document.removeEventListener('selectionchange', listener
|
|
339
|
-
capture: true
|
|
340
|
-
});
|
|
335
|
+
return document.removeEventListener('selectionchange', listener);
|
|
341
336
|
};
|
|
342
337
|
}, []);
|
|
343
338
|
return useRef({
|
package/dist/utils/markdown.js
CHANGED
|
@@ -3,6 +3,7 @@ import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
|
|
|
3
3
|
import _regeneratorRuntime from "@babel/runtime/helpers/esm/regeneratorRuntime";
|
|
4
4
|
import _asyncToGenerator from "@babel/runtime/helpers/esm/asyncToGenerator";
|
|
5
5
|
import _createForOfIteratorHelper from "@babel/runtime/helpers/esm/createForOfIteratorHelper";
|
|
6
|
+
import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
|
|
6
7
|
import { toJsxRuntime } from 'hast-util-to-jsx-runtime';
|
|
7
8
|
import { toText as hastToText } from 'hast-util-to-text';
|
|
8
9
|
import { Fragment, jsx, jsxs } from 'react/jsx-runtime';
|
|
@@ -31,6 +32,20 @@ import rehypeRawPositions from "./rehype/rehype-raw-positions";
|
|
|
31
32
|
*/
|
|
32
33
|
var toMdastProcessor = unified().use(remarkParse).use(remarkGfm).use(remarkMath).freeze();
|
|
33
34
|
|
|
35
|
+
/**
|
|
36
|
+
* 带缓存的解析函数
|
|
37
|
+
*
|
|
38
|
+
* @param sourceCode Markdown 文本
|
|
39
|
+
* @returns Mdast 树
|
|
40
|
+
*/
|
|
41
|
+
var cachedParse = function () {
|
|
42
|
+
var cache = {};
|
|
43
|
+
return function (sourceCode) {
|
|
44
|
+
var _cache$sourceCode;
|
|
45
|
+
return (_cache$sourceCode = cache[sourceCode]) !== null && _cache$sourceCode !== void 0 ? _cache$sourceCode : (cache = _defineProperty({}, sourceCode, toMdastProcessor.parse(sourceCode)))[sourceCode];
|
|
46
|
+
};
|
|
47
|
+
}();
|
|
48
|
+
|
|
34
49
|
/**
|
|
35
50
|
* 将 Markdown 文本映射到 DOM 树,第一层为 `<div>` 块元素,第二层为 `<div>` 行元素,之后均为 `<span>` 元素
|
|
36
51
|
*
|
|
@@ -228,7 +243,7 @@ export var editorRender = function editorRender(sourceCode) {
|
|
|
228
243
|
}
|
|
229
244
|
addText(sourceCode.slice(scanOffset, parentEndOffset), true);
|
|
230
245
|
};
|
|
231
|
-
getChildren(
|
|
246
|
+
getChildren(cachedParse(sourceCode).children, sourceCode.length);
|
|
232
247
|
if (scanOffset <= sourceCode.length) {
|
|
233
248
|
// 添加最后一行文本
|
|
234
249
|
block.append(createLine(sourceCode.slice(scanOffset)));
|
|
@@ -274,7 +289,7 @@ export var preViewerRender = /*#__PURE__*/function () {
|
|
|
274
289
|
while (1) switch (_context.prev = _context.next) {
|
|
275
290
|
case 0:
|
|
276
291
|
_context.next = 2;
|
|
277
|
-
return toHastProcessor.run(
|
|
292
|
+
return toHastProcessor.run(JSON.parse(JSON.stringify(cachedParse(sourceCode))));
|
|
278
293
|
case 2:
|
|
279
294
|
return _context.abrupt("return", _context.sent);
|
|
280
295
|
case 3:
|
|
@@ -1,8 +1,15 @@
|
|
|
1
1
|
import _extends from "@babel/runtime/helpers/esm/extends";
|
|
2
|
+
import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
|
|
3
|
+
import _toConsumableArray from "@babel/runtime/helpers/esm/toConsumableArray";
|
|
2
4
|
import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
|
|
3
5
|
import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
|
|
4
6
|
import classNames from 'classnames';
|
|
5
|
-
import React, { useEffect, useImperativeHandle, useRef, useState } from 'react';
|
|
7
|
+
import React, { useEffect, useImperativeHandle, useMemo, useRef, useState } from 'react';
|
|
8
|
+
import SvgEditOnly from "../icons/EditOnly";
|
|
9
|
+
import SvgEnterFullscreen from "../icons/EnterFullscreen";
|
|
10
|
+
import SvgExitFullscreen from "../icons/ExitFullscreen";
|
|
11
|
+
import SvgViewOnly from "../icons/ViewOnly";
|
|
12
|
+
import { getFormat } from "../locales";
|
|
6
13
|
import { prefix } from "../utils/global";
|
|
7
14
|
import XStarMdEditor, { useMdEditorRef } from "../x-star-md-editor";
|
|
8
15
|
import XStarMdViewer, { useMdViewerRef } from "../x-star-md-viewer";
|
|
@@ -28,6 +35,7 @@ var ViewerRenderWrapper = /*#__PURE__*/React.forwardRef(function (_ref, ref) {
|
|
|
28
35
|
}, children);
|
|
29
36
|
});
|
|
30
37
|
var XStarEditor = /*#__PURE__*/React.forwardRef(function (_ref2, ref) {
|
|
38
|
+
var _classNames4, _classNames5, _classNames6;
|
|
31
39
|
var className = _ref2.className,
|
|
32
40
|
style = _ref2.style,
|
|
33
41
|
height = _ref2.height,
|
|
@@ -136,37 +144,86 @@ var XStarEditor = /*#__PURE__*/React.forwardRef(function (_ref2, ref) {
|
|
|
136
144
|
}
|
|
137
145
|
}
|
|
138
146
|
};
|
|
139
|
-
editor === null || editor === void 0 ? void 0 : editor.addEventListener('scroll', listener
|
|
140
|
-
|
|
141
|
-
passive: true
|
|
142
|
-
});
|
|
143
|
-
viewer === null || viewer === void 0 ? void 0 : viewer.addEventListener('scroll', listener, {
|
|
144
|
-
capture: true,
|
|
145
|
-
passive: true
|
|
146
|
-
});
|
|
147
|
+
editor === null || editor === void 0 ? void 0 : editor.addEventListener('scroll', listener);
|
|
148
|
+
viewer === null || viewer === void 0 ? void 0 : viewer.addEventListener('scroll', listener);
|
|
147
149
|
return function () {
|
|
148
|
-
editor === null || editor === void 0 ? void 0 : editor.removeEventListener('scroll', listener
|
|
149
|
-
|
|
150
|
-
});
|
|
151
|
-
viewer === null || viewer === void 0 ? void 0 : viewer.removeEventListener('scroll', listener, {
|
|
152
|
-
capture: true
|
|
153
|
-
});
|
|
150
|
+
editor === null || editor === void 0 ? void 0 : editor.removeEventListener('scroll', listener);
|
|
151
|
+
viewer === null || viewer === void 0 ? void 0 : viewer.removeEventListener('scroll', listener);
|
|
154
152
|
};
|
|
155
153
|
}, []);
|
|
156
154
|
var _useState = useState(initialValue),
|
|
157
155
|
_useState2 = _slicedToArray(_useState, 2),
|
|
158
156
|
value = _useState2[0],
|
|
159
157
|
setValue = _useState2[1];
|
|
158
|
+
var _useState3 = useState(['editor', 'viewer']),
|
|
159
|
+
_useState4 = _slicedToArray(_useState3, 2),
|
|
160
|
+
layout = _useState4[0],
|
|
161
|
+
setLayout = _useState4[1];
|
|
162
|
+
var editOnly = layout.includes('editor') && !layout.includes('viewer');
|
|
163
|
+
var viewOnly = !layout.includes('editor') && layout.includes('viewer');
|
|
164
|
+
var _useState5 = useState(false),
|
|
165
|
+
_useState6 = _slicedToArray(_useState5, 2),
|
|
166
|
+
fullscreen = _useState6[0],
|
|
167
|
+
setFullscreen = _useState6[1];
|
|
168
|
+
var editorPlugins = useMemo(function () {
|
|
169
|
+
var _editorProps$plugins;
|
|
170
|
+
return [function (ctx) {
|
|
171
|
+
var t = getFormat(locale, 'toolbarItem');
|
|
172
|
+
ctx.toolbarItemMap.editOnly = {
|
|
173
|
+
children: /*#__PURE__*/React.createElement(SvgEditOnly, {
|
|
174
|
+
className: classNames("".concat(prefix, "icon"), _defineProperty({}, "".concat(prefix, "active"), editOnly))
|
|
175
|
+
}),
|
|
176
|
+
tooltip: t('editOnly'),
|
|
177
|
+
onClick: function onClick() {
|
|
178
|
+
return setLayout(editOnly ? ['editor', 'viewer'] : ['editor']);
|
|
179
|
+
}
|
|
180
|
+
};
|
|
181
|
+
ctx.toolbarItemMap.viewOnly = {
|
|
182
|
+
children: /*#__PURE__*/React.createElement(SvgViewOnly, {
|
|
183
|
+
className: classNames("".concat(prefix, "icon"), _defineProperty({}, "".concat(prefix, "active"), viewOnly))
|
|
184
|
+
}),
|
|
185
|
+
tooltip: t('viewOnly'),
|
|
186
|
+
onClick: function onClick() {
|
|
187
|
+
return setLayout(viewOnly ? ['editor', 'viewer'] : ['viewer']);
|
|
188
|
+
}
|
|
189
|
+
};
|
|
190
|
+
ctx.toolbarItemMap.fullscreen = {
|
|
191
|
+
children: fullscreen ? /*#__PURE__*/React.createElement(SvgExitFullscreen, {
|
|
192
|
+
className: classNames("".concat(prefix, "icon"))
|
|
193
|
+
}) : /*#__PURE__*/React.createElement(SvgEnterFullscreen, {
|
|
194
|
+
className: classNames("".concat(prefix, "icon"))
|
|
195
|
+
}),
|
|
196
|
+
tooltip: fullscreen ? t('exitFullscreen') : t('enterFullscreen'),
|
|
197
|
+
onClick: function onClick() {
|
|
198
|
+
return setFullscreen(!fullscreen);
|
|
199
|
+
}
|
|
200
|
+
};
|
|
201
|
+
ctx.toolbarItems.push(['editOnly', 'viewOnly', 'fullscreen']);
|
|
202
|
+
}].concat(_toConsumableArray((_editorProps$plugins = editorProps === null || editorProps === void 0 ? void 0 : editorProps.plugins) !== null && _editorProps$plugins !== void 0 ? _editorProps$plugins : []));
|
|
203
|
+
}, [locale, editOnly, viewOnly, fullscreen, editorProps === null || editorProps === void 0 ? void 0 : editorProps.plugins]);
|
|
204
|
+
|
|
205
|
+
// 防止出现两个滚动条
|
|
206
|
+
useEffect(function () {
|
|
207
|
+
if (fullscreen) {
|
|
208
|
+
var overflow = document.body.style.overflow;
|
|
209
|
+
document.body.style.overflow = 'hidden';
|
|
210
|
+
return function () {
|
|
211
|
+
document.body.style.overflow = overflow;
|
|
212
|
+
};
|
|
213
|
+
}
|
|
214
|
+
}, [fullscreen]);
|
|
160
215
|
return /*#__PURE__*/React.createElement("div", {
|
|
161
216
|
ref: containerRef,
|
|
162
|
-
className: classNames("".concat(prefix, "editor"), className),
|
|
217
|
+
className: classNames("".concat(prefix, "editor"), _defineProperty({}, "".concat(prefix, "fullscreen"), fullscreen), className),
|
|
163
218
|
style: style
|
|
164
219
|
}, /*#__PURE__*/React.createElement(XStarMdEditor, _extends({
|
|
165
220
|
ref: editorRef
|
|
166
221
|
}, editorProps, {
|
|
222
|
+
className: classNames((_classNames4 = {}, _defineProperty(_classNames4, "".concat(prefix, "active"), editOnly), _defineProperty(_classNames4, "".concat(prefix, "hidden"), viewOnly), _classNames4), editorProps === null || editorProps === void 0 ? void 0 : editorProps.className),
|
|
167
223
|
height: height,
|
|
168
224
|
locale: locale,
|
|
169
225
|
initialValue: initialValue,
|
|
226
|
+
plugins: editorPlugins,
|
|
170
227
|
onChange: function onChange(value) {
|
|
171
228
|
setValue(value);
|
|
172
229
|
_onChange === null || _onChange === void 0 ? void 0 : _onChange(value);
|
|
@@ -174,12 +231,13 @@ var XStarEditor = /*#__PURE__*/React.forwardRef(function (_ref2, ref) {
|
|
|
174
231
|
onInsertFile: onInsertFile
|
|
175
232
|
})), viewerRender ? /*#__PURE__*/React.createElement(ViewerRenderWrapper, {
|
|
176
233
|
ref: viewerRef,
|
|
177
|
-
className: viewerProps === null || viewerProps === void 0 ? void 0 : viewerProps.className,
|
|
234
|
+
className: classNames((_classNames5 = {}, _defineProperty(_classNames5, "".concat(prefix, "active"), viewOnly), _defineProperty(_classNames5, "".concat(prefix, "hidden"), editOnly), _classNames5), viewerProps === null || viewerProps === void 0 ? void 0 : viewerProps.className),
|
|
178
235
|
style: viewerProps === null || viewerProps === void 0 ? void 0 : viewerProps.style,
|
|
179
236
|
height: height
|
|
180
237
|
}, viewerRender(value)) : /*#__PURE__*/React.createElement(XStarMdViewer, _extends({
|
|
181
238
|
ref: viewerRef
|
|
182
239
|
}, viewerProps, {
|
|
240
|
+
className: classNames((_classNames6 = {}, _defineProperty(_classNames6, "".concat(prefix, "active"), viewOnly), _defineProperty(_classNames6, "".concat(prefix, "hidden"), editOnly), _classNames6), viewerProps === null || viewerProps === void 0 ? void 0 : viewerProps.className),
|
|
183
241
|
height: height,
|
|
184
242
|
value: value,
|
|
185
243
|
enableWebWorker: enableWebWorker
|
|
@@ -186,7 +186,7 @@ var XStarMdEditor = /*#__PURE__*/React.forwardRef(function (_ref, ref) {
|
|
|
186
186
|
var _containerRef$current;
|
|
187
187
|
var listener = function listener(e) {
|
|
188
188
|
var targetRange = e.getTargetRanges()[0];
|
|
189
|
-
if (!
|
|
189
|
+
if (!targetRange || !containerRef.current) {
|
|
190
190
|
return;
|
|
191
191
|
}
|
|
192
192
|
var startOffset = container.getOffset(containerRef.current, targetRange.startContainer, targetRange.startOffset);
|