x-star-editor 0.0.8 → 0.0.9
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 +14 -4
- package/dist/styles/index.css +6 -8
- package/dist/utils/history.d.ts +4 -1
- package/dist/utils/history.js +18 -13
- package/dist/utils/markdown.js +37 -34
- package/package.json +1 -1
|
@@ -128,10 +128,20 @@ export var getDefaultToolbarItemMap = function getDefaultToolbarItemMap(onInsert
|
|
|
128
128
|
className: classNames("".concat(prefix, "icon"), "".concat(prefix, "code-library"))
|
|
129
129
|
}),
|
|
130
130
|
tooltip: '代码块',
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
131
|
+
popoverRender: function popoverRender(exec, close) {
|
|
132
|
+
var optionRender = function optionRender(label, language) {
|
|
133
|
+
return /*#__PURE__*/React.createElement("div", {
|
|
134
|
+
className: classNames("".concat(prefix, "option")),
|
|
135
|
+
onClick: function onClick() {
|
|
136
|
+
exec(toggleHandler({
|
|
137
|
+
type: 'code',
|
|
138
|
+
language: language
|
|
139
|
+
}));
|
|
140
|
+
close();
|
|
141
|
+
}
|
|
142
|
+
}, label);
|
|
143
|
+
};
|
|
144
|
+
return /*#__PURE__*/React.createElement(React.Fragment, null, optionRender('C++', 'cpp'), optionRender('Java', 'java'), optionRender('Python', 'py'), optionRender('Text', 'txt'));
|
|
135
145
|
}
|
|
136
146
|
},
|
|
137
147
|
emphasis: {
|
package/dist/styles/index.css
CHANGED
|
@@ -176,15 +176,17 @@
|
|
|
176
176
|
}
|
|
177
177
|
.x-star-editor .x-star-md-editor {
|
|
178
178
|
flex: 1;
|
|
179
|
-
border-
|
|
179
|
+
border-right: none;
|
|
180
180
|
border-bottom-right-radius: 0;
|
|
181
181
|
}
|
|
182
182
|
.x-star-editor .x-star-md-viewer {
|
|
183
|
+
padding: 0 1em;
|
|
183
184
|
flex: 1;
|
|
185
|
+
background-color: white;
|
|
186
|
+
border: 1px solid #d0d0d0;
|
|
184
187
|
border-top: none;
|
|
185
|
-
border-left: none;
|
|
186
|
-
border-radius: 0;
|
|
187
188
|
border-bottom-right-radius: 0.2em;
|
|
189
|
+
overflow: auto;
|
|
188
190
|
}
|
|
189
191
|
|
|
190
192
|
.x-star-md-editor {
|
|
@@ -194,6 +196,7 @@
|
|
|
194
196
|
color: rgba(0, 0, 0, 0.8509803922);
|
|
195
197
|
background-color: white;
|
|
196
198
|
border: 1px solid #d0d0d0;
|
|
199
|
+
border-top: none;
|
|
197
200
|
border-bottom-right-radius: 0.2em;
|
|
198
201
|
border-bottom-left-radius: 0.2em;
|
|
199
202
|
outline: none;
|
|
@@ -205,12 +208,7 @@
|
|
|
205
208
|
|
|
206
209
|
.x-star-md-viewer {
|
|
207
210
|
position: relative;
|
|
208
|
-
padding: 0 1em;
|
|
209
211
|
color: rgba(0, 0, 0, 0.8509803922);
|
|
210
|
-
background-color: white;
|
|
211
|
-
border: 1px solid #d0d0d0;
|
|
212
|
-
border-radius: 0.2em;
|
|
213
|
-
overflow: auto;
|
|
214
212
|
}
|
|
215
213
|
.x-star-md-viewer ::selection {
|
|
216
214
|
background: #c1def1;
|
package/dist/utils/history.d.ts
CHANGED
|
@@ -28,7 +28,10 @@ export interface ToggleAction {
|
|
|
28
28
|
type: 'heading';
|
|
29
29
|
depth: 1 | 2 | 3 | 4 | 5 | 6;
|
|
30
30
|
} | {
|
|
31
|
-
type: '
|
|
31
|
+
type: 'code';
|
|
32
|
+
language: string;
|
|
33
|
+
} | {
|
|
34
|
+
type: 'thematicBreak' | 'blockquote' | 'emphasis' | 'strong' | 'inlineCode' | 'delete' | 'math' | 'inlineMath';
|
|
32
35
|
} | {
|
|
33
36
|
type: 'link' | 'image';
|
|
34
37
|
url: string;
|
package/dist/utils/history.js
CHANGED
|
@@ -112,6 +112,14 @@ var stateReducer = function stateReducer(_ref, action) {
|
|
|
112
112
|
selection: createSelection(lineStartOffset + _text.length)
|
|
113
113
|
};
|
|
114
114
|
}
|
|
115
|
+
case 'code':
|
|
116
|
+
{
|
|
117
|
+
var language = action.payload.language;
|
|
118
|
+
return {
|
|
119
|
+
sourceCode: "".concat(sourceCode.slice(0, lineEndOffset), "\n```").concat(language, " showLineNumbers\n\n```\n").concat(lineAfter),
|
|
120
|
+
selection: createSelection(lineEndOffset + language.length + 21)
|
|
121
|
+
};
|
|
122
|
+
}
|
|
115
123
|
case 'thematicBreak':
|
|
116
124
|
{
|
|
117
125
|
return {
|
|
@@ -143,14 +151,11 @@ var stateReducer = function stateReducer(_ref, action) {
|
|
|
143
151
|
selection: createSelection(lineStartOffset + _text2.length)
|
|
144
152
|
};
|
|
145
153
|
}
|
|
146
|
-
case 'code':
|
|
147
154
|
case 'math':
|
|
148
155
|
{
|
|
149
|
-
var type = action.payload.type;
|
|
150
|
-
var delimiter = type === 'code' ? '```' : '$$';
|
|
151
156
|
return {
|
|
152
|
-
sourceCode: "".concat(sourceCode.slice(0, lineEndOffset), "\n
|
|
153
|
-
selection: createSelection(lineEndOffset +
|
|
157
|
+
sourceCode: "".concat(sourceCode.slice(0, lineEndOffset), "\n$$\n\n$$\n").concat(lineAfter),
|
|
158
|
+
selection: createSelection(lineEndOffset + 4)
|
|
154
159
|
};
|
|
155
160
|
}
|
|
156
161
|
case 'emphasis':
|
|
@@ -159,8 +164,8 @@ var stateReducer = function stateReducer(_ref, action) {
|
|
|
159
164
|
case 'delete':
|
|
160
165
|
case 'inlineMath':
|
|
161
166
|
{
|
|
162
|
-
var
|
|
163
|
-
var delimiters =
|
|
167
|
+
var type = action.payload.type;
|
|
168
|
+
var delimiters = type === 'emphasis' ? ['*', '_'] : type === 'strong' ? ['**', '__'] : type === 'inlineCode' ? ['`'] : type === 'delete' ? ['~~'] : ['$'];
|
|
164
169
|
var _text3 = sourceCode.slice(startOffset, endOffset);
|
|
165
170
|
for (var _i4 = 0, _delimiters = delimiters; _i4 < _delimiters.length; _i4++) {
|
|
166
171
|
var _delimiter = _delimiters[_i4];
|
|
@@ -172,23 +177,23 @@ var stateReducer = function stateReducer(_ref, action) {
|
|
|
172
177
|
};
|
|
173
178
|
}
|
|
174
179
|
}
|
|
175
|
-
var
|
|
180
|
+
var delimiter = delimiters[0];
|
|
176
181
|
// 插入分隔文本
|
|
177
182
|
return {
|
|
178
|
-
sourceCode: "".concat(before).concat(
|
|
179
|
-
selection: createSelection(anchorOffset +
|
|
183
|
+
sourceCode: "".concat(before).concat(delimiter).concat(_text3).concat(delimiter).concat(after),
|
|
184
|
+
selection: createSelection(anchorOffset + delimiter.length, focusOffset + delimiter.length)
|
|
180
185
|
};
|
|
181
186
|
}
|
|
182
187
|
case 'link':
|
|
183
188
|
case 'image':
|
|
184
189
|
{
|
|
185
190
|
var _action$payload2 = action.payload,
|
|
186
|
-
|
|
191
|
+
_type = _action$payload2.type,
|
|
187
192
|
url = _action$payload2.url,
|
|
188
193
|
description = _action$payload2.description;
|
|
189
194
|
return {
|
|
190
|
-
sourceCode: "".concat(before).concat(
|
|
191
|
-
selection: createSelection(startOffset + url.length + description.length + 4 + (
|
|
195
|
+
sourceCode: "".concat(before).concat(_type === 'link' ? '' : '!', "[").concat(description, "](").concat(url, ")").concat(after),
|
|
196
|
+
selection: createSelection(startOffset + url.length + description.length + 4 + (_type === 'link' ? 0 : 1))
|
|
192
197
|
};
|
|
193
198
|
}
|
|
194
199
|
default:
|
package/dist/utils/markdown.js
CHANGED
|
@@ -28,16 +28,19 @@ import remarkStringify from 'remark-stringify';
|
|
|
28
28
|
import { unified } from 'unified';
|
|
29
29
|
import { prefix } from "./global";
|
|
30
30
|
export var getDefaultSchema = function getDefaultSchema() {
|
|
31
|
-
var _defaultSchema$
|
|
31
|
+
var _defaultSchema$attrib, _defaultSchema$attrib2, _defaultSchema$attrib3, _defaultSchema$attrib4, _defaultSchema$attrib5, _defaultSchema$attrib6, _defaultSchema$attrib7, _defaultSchema$attrib8, _defaultSchema$protoc, _defaultSchema$protoc2, _defaultSchema$tagNam;
|
|
32
32
|
return _objectSpread(_objectSpread({}, defaultSchema), {}, {
|
|
33
|
-
tagNames: [].concat(_toConsumableArray((_defaultSchema$tagNam = defaultSchema.tagNames) !== null && _defaultSchema$tagNam !== void 0 ? _defaultSchema$tagNam : []), ['custom']),
|
|
34
33
|
attributes: _objectSpread(_objectSpread({}, defaultSchema.attributes), {}, {
|
|
35
34
|
pre: [].concat(_toConsumableArray((_defaultSchema$attrib = (_defaultSchema$attrib2 = defaultSchema.attributes) === null || _defaultSchema$attrib2 === void 0 ? void 0 : _defaultSchema$attrib2.pre) !== null && _defaultSchema$attrib !== void 0 ? _defaultSchema$attrib : []), ['className', 'style']),
|
|
36
35
|
code: [].concat(_toConsumableArray((_defaultSchema$attrib3 = (_defaultSchema$attrib4 = defaultSchema.attributes) === null || _defaultSchema$attrib4 === void 0 ? void 0 : _defaultSchema$attrib4.code) !== null && _defaultSchema$attrib3 !== void 0 ? _defaultSchema$attrib3 : []), ['className', 'style']),
|
|
37
36
|
div: [].concat(_toConsumableArray((_defaultSchema$attrib5 = (_defaultSchema$attrib6 = defaultSchema.attributes) === null || _defaultSchema$attrib6 === void 0 ? void 0 : _defaultSchema$attrib6.div) !== null && _defaultSchema$attrib5 !== void 0 ? _defaultSchema$attrib5 : []), ['className', 'style']),
|
|
38
37
|
span: [].concat(_toConsumableArray((_defaultSchema$attrib7 = (_defaultSchema$attrib8 = defaultSchema.attributes) === null || _defaultSchema$attrib8 === void 0 ? void 0 : _defaultSchema$attrib8.span) !== null && _defaultSchema$attrib7 !== void 0 ? _defaultSchema$attrib7 : []), ['className', 'style', 'line']),
|
|
39
38
|
custom: ['meta', 'value']
|
|
40
|
-
})
|
|
39
|
+
}),
|
|
40
|
+
protocols: _objectSpread(_objectSpread({}, defaultSchema.protocols), {}, {
|
|
41
|
+
src: [].concat(_toConsumableArray((_defaultSchema$protoc = (_defaultSchema$protoc2 = defaultSchema.protocols) === null || _defaultSchema$protoc2 === void 0 ? void 0 : _defaultSchema$protoc2.src) !== null && _defaultSchema$protoc !== void 0 ? _defaultSchema$protoc : []), ['data'])
|
|
42
|
+
}),
|
|
43
|
+
tagNames: [].concat(_toConsumableArray((_defaultSchema$tagNam = defaultSchema.tagNames) !== null && _defaultSchema$tagNam !== void 0 ? _defaultSchema$tagNam : []), ['custom'])
|
|
41
44
|
});
|
|
42
45
|
};
|
|
43
46
|
|
|
@@ -59,25 +62,7 @@ var processor = unified().use(remarkParse).use(remarkBreaks).use(remarkGfm).use(
|
|
|
59
62
|
}
|
|
60
63
|
}).use(rehypePrism, {
|
|
61
64
|
ignoreMissing: true
|
|
62
|
-
}).use(rehypeKatex).use(rehypeRaw).
|
|
63
|
-
return function (root) {
|
|
64
|
-
var _iterator = _createForOfIteratorHelper(root.children),
|
|
65
|
-
_step;
|
|
66
|
-
try {
|
|
67
|
-
for (_iterator.s(); !(_step = _iterator.n()).done;) {
|
|
68
|
-
var node = _step.value;
|
|
69
|
-
if ('properties' in node && node.properties) {
|
|
70
|
-
var _node$position;
|
|
71
|
-
node.properties.line = (_node$position = node.position) === null || _node$position === void 0 ? void 0 : _node$position.start.line;
|
|
72
|
-
}
|
|
73
|
-
}
|
|
74
|
-
} catch (err) {
|
|
75
|
-
_iterator.e(err);
|
|
76
|
-
} finally {
|
|
77
|
-
_iterator.f();
|
|
78
|
-
}
|
|
79
|
-
};
|
|
80
|
-
}).freeze();
|
|
65
|
+
}).use(rehypeKatex).use(rehypeRaw).freeze();
|
|
81
66
|
|
|
82
67
|
/**
|
|
83
68
|
* Mdast 节点
|
|
@@ -235,14 +220,14 @@ export var editorRender = function editorRender(sourceCode) {
|
|
|
235
220
|
* @param parentEndOffset 父节点终点偏移量
|
|
236
221
|
*/
|
|
237
222
|
var getChildren = function getChildren(nodes, parentEndOffset) {
|
|
238
|
-
var
|
|
239
|
-
|
|
223
|
+
var _iterator = _createForOfIteratorHelper(nodes),
|
|
224
|
+
_step;
|
|
240
225
|
try {
|
|
241
|
-
for (
|
|
242
|
-
var _node$
|
|
243
|
-
var node =
|
|
244
|
-
var startOffset = (_node$
|
|
245
|
-
var endOffset = (_node$
|
|
226
|
+
for (_iterator.s(); !(_step = _iterator.n()).done;) {
|
|
227
|
+
var _node$position, _node$position2;
|
|
228
|
+
var node = _step.value;
|
|
229
|
+
var startOffset = (_node$position = node.position) === null || _node$position === void 0 ? void 0 : _node$position.start.offset;
|
|
230
|
+
var endOffset = (_node$position2 = node.position) === null || _node$position2 === void 0 ? void 0 : _node$position2.end.offset;
|
|
246
231
|
if (startOffset === undefined || endOffset === undefined) {
|
|
247
232
|
continue;
|
|
248
233
|
}
|
|
@@ -272,11 +257,11 @@ export var editorRender = function editorRender(sourceCode) {
|
|
|
272
257
|
if (stack.length > 1) {
|
|
273
258
|
pushElement(stack.length - 1, true);
|
|
274
259
|
} else {
|
|
275
|
-
var _node$
|
|
260
|
+
var _node$position3;
|
|
276
261
|
// 如果栈大小为 1,说明为块级元素终点
|
|
277
262
|
stack[0].el.append("\u200B");
|
|
278
263
|
pushElement(0, true);
|
|
279
|
-
block.setAttribute('line', "".concat((_node$
|
|
264
|
+
block.setAttribute('line', "".concat((_node$position3 = node.position) === null || _node$position3 === void 0 ? void 0 : _node$position3.start.line));
|
|
280
265
|
pushBlock();
|
|
281
266
|
scanOffset++;
|
|
282
267
|
}
|
|
@@ -285,9 +270,9 @@ export var editorRender = function editorRender(sourceCode) {
|
|
|
285
270
|
|
|
286
271
|
// 添加扫描偏移量与父节点终点偏移量间的分隔文本
|
|
287
272
|
} catch (err) {
|
|
288
|
-
|
|
273
|
+
_iterator.e(err);
|
|
289
274
|
} finally {
|
|
290
|
-
|
|
275
|
+
_iterator.f();
|
|
291
276
|
}
|
|
292
277
|
addText(sourceCode.slice(scanOffset, parentEndOffset), true);
|
|
293
278
|
};
|
|
@@ -307,7 +292,25 @@ export var editorRender = function editorRender(sourceCode) {
|
|
|
307
292
|
* @returns React 虚拟 DOM 树
|
|
308
293
|
*/
|
|
309
294
|
export var viewerRender = function viewerRender(sourceCode, options) {
|
|
310
|
-
return toJsxRuntime(processor().use(rehypeSanitize, options.customSchema).
|
|
295
|
+
return toJsxRuntime(processor().use(rehypeSanitize, options.customSchema).use(function () {
|
|
296
|
+
return function (root) {
|
|
297
|
+
var _iterator2 = _createForOfIteratorHelper(root.children),
|
|
298
|
+
_step2;
|
|
299
|
+
try {
|
|
300
|
+
for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
|
|
301
|
+
var node = _step2.value;
|
|
302
|
+
if ('properties' in node && node.properties) {
|
|
303
|
+
var _node$position4;
|
|
304
|
+
node.properties.line = (_node$position4 = node.position) === null || _node$position4 === void 0 ? void 0 : _node$position4.start.line;
|
|
305
|
+
}
|
|
306
|
+
}
|
|
307
|
+
} catch (err) {
|
|
308
|
+
_iterator2.e(err);
|
|
309
|
+
} finally {
|
|
310
|
+
_iterator2.f();
|
|
311
|
+
}
|
|
312
|
+
};
|
|
313
|
+
}).runSync(processor.parse(sourceCode)), {
|
|
311
314
|
Fragment: Fragment,
|
|
312
315
|
jsx: jsx,
|
|
313
316
|
jsxs: jsxs,
|