x-star-editor 0.3.6 → 0.3.8
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 +7 -2
- package/dist/styles/index.css +24 -0
- package/dist/utils/history.d.ts +1 -1
- package/dist/utils/history.js +7 -0
- package/dist/utils/markdown.d.ts +1 -2
- package/dist/utils/markdown.js +32 -26
- package/dist/x-star-editor/index.js +8 -0
- package/dist/x-star-md-editor/index.js +1 -6
- package/dist/x-star-md-viewer/index.js +16 -2
- package/package.json +1 -1
|
@@ -458,7 +458,12 @@ export var getDefaultToolbarItemMap = function getDefaultToolbarItemMap(locale,
|
|
|
458
458
|
children: /*#__PURE__*/React.createElement(SvgTable, {
|
|
459
459
|
className: classNames("".concat(prefix, "icon"))
|
|
460
460
|
}),
|
|
461
|
-
tooltip: t('table')
|
|
461
|
+
tooltip: t('table'),
|
|
462
|
+
onClick: function onClick(exec) {
|
|
463
|
+
return exec(toggleHandler({
|
|
464
|
+
type: 'table'
|
|
465
|
+
}));
|
|
466
|
+
}
|
|
462
467
|
},
|
|
463
468
|
taskList: {
|
|
464
469
|
children: /*#__PURE__*/React.createElement(SvgTaskList, {
|
|
@@ -551,7 +556,7 @@ export var getDefaultToolbarItemMap = function getDefaultToolbarItemMap(locale,
|
|
|
551
556
|
};
|
|
552
557
|
};
|
|
553
558
|
export var getDefaultToolbarItems = function getDefaultToolbarItems() {
|
|
554
|
-
return [['heading', 'strong', 'emphasis', 'delete'], ['thematicBreak', 'blockquote'
|
|
559
|
+
return [['heading', 'strong', 'emphasis', 'delete'], ['thematicBreak', 'blockquote', 'table'], ['link', 'image', 'mermaid'], ['inlineCode', 'code', 'inlineMath', 'math'], ['orderedList', 'unorderedList', 'taskList'], ['toMarkdown', 'toHTML'], ['undo', 'redo']
|
|
555
560
|
// ['help'],
|
|
556
561
|
];
|
|
557
562
|
};
|
package/dist/styles/index.css
CHANGED
|
@@ -255,6 +255,30 @@
|
|
|
255
255
|
.x-star-editor-md-viewer ::selection {
|
|
256
256
|
background-color: #c1def1;
|
|
257
257
|
}
|
|
258
|
+
.x-star-editor-md-viewer h1,
|
|
259
|
+
.x-star-editor-md-viewer h2,
|
|
260
|
+
.x-star-editor-md-viewer h3,
|
|
261
|
+
.x-star-editor-md-viewer h4,
|
|
262
|
+
.x-star-editor-md-viewer h5,
|
|
263
|
+
.x-star-editor-md-viewer h6 {
|
|
264
|
+
font-weight: bold;
|
|
265
|
+
}
|
|
266
|
+
.x-star-editor-md-viewer table {
|
|
267
|
+
margin: 1em 0;
|
|
268
|
+
border-collapse: collapse;
|
|
269
|
+
}
|
|
270
|
+
.x-star-editor-md-viewer th,
|
|
271
|
+
.x-star-editor-md-viewer td {
|
|
272
|
+
padding: 0.5em;
|
|
273
|
+
border: 1px solid #dedede;
|
|
274
|
+
}
|
|
275
|
+
.x-star-editor-md-viewer th {
|
|
276
|
+
font-weight: bold;
|
|
277
|
+
background-color: rgba(0, 0, 0, 0.06);
|
|
278
|
+
}
|
|
279
|
+
.x-star-editor-md-viewer tr:nth-child(even) td {
|
|
280
|
+
background-color: rgba(0, 0, 0, 0.04);
|
|
281
|
+
}
|
|
258
282
|
|
|
259
283
|
/* stylelint-disable font-family-no-missing-generic-family-keyword */
|
|
260
284
|
@font-face {
|
package/dist/utils/history.d.ts
CHANGED
|
@@ -17,7 +17,7 @@ export interface InsertAction {
|
|
|
17
17
|
export interface ToggleAction {
|
|
18
18
|
type: 'toggle';
|
|
19
19
|
payload: {
|
|
20
|
-
type: 'blockquote' | 'delete' | 'emphasis' | 'inlineCode' | 'inlineMath' | 'math' | 'orderedList' | 'strong' | 'taskList' | 'thematicBreak' | 'unorderedList';
|
|
20
|
+
type: 'blockquote' | 'delete' | 'emphasis' | 'inlineCode' | 'inlineMath' | 'math' | 'orderedList' | 'strong' | 'table' | 'taskList' | 'thematicBreak' | 'unorderedList';
|
|
21
21
|
} | {
|
|
22
22
|
type: 'code';
|
|
23
23
|
lang: string;
|
package/dist/utils/history.js
CHANGED
|
@@ -148,6 +148,13 @@ var stateReducer = function stateReducer(_ref, action) {
|
|
|
148
148
|
selection: createSelection(lineEndOffset + 4)
|
|
149
149
|
};
|
|
150
150
|
}
|
|
151
|
+
case 'table':
|
|
152
|
+
{
|
|
153
|
+
return {
|
|
154
|
+
sourceCode: "".concat(sourceCode.slice(0, lineEndOffset), "\n| | |\n| - | - |\n| | |\n| | |\n").concat(lineAfter),
|
|
155
|
+
selection: createSelection(lineEndOffset + 3)
|
|
156
|
+
};
|
|
157
|
+
}
|
|
151
158
|
case 'thematicBreak':
|
|
152
159
|
{
|
|
153
160
|
return {
|
package/dist/utils/markdown.d.ts
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
/// <reference types="react" />
|
|
2
1
|
import type { Root as HastRoot } from 'hast';
|
|
3
2
|
import { defaultSchema } from 'rehype-sanitize';
|
|
4
3
|
import type { ViewerOptions } from '../x-star-md-viewer';
|
|
@@ -36,7 +35,7 @@ export declare const viewerRender: (root: HastRoot, schema: Schema) => HastRoot;
|
|
|
36
35
|
* @param options 配置项
|
|
37
36
|
* @returns React 虚拟 DOM 树
|
|
38
37
|
*/
|
|
39
|
-
export declare const postViewerRender: (root: HastRoot, options: ViewerOptions) =>
|
|
38
|
+
export declare const postViewerRender: (root: HastRoot, options: ViewerOptions) => any;
|
|
40
39
|
/**
|
|
41
40
|
* 将 Markdown 文本转成 HTML 文本
|
|
42
41
|
*
|
package/dist/utils/markdown.js
CHANGED
|
@@ -308,21 +308,17 @@ export var preViewerRender = /*#__PURE__*/function () {
|
|
|
308
308
|
*/
|
|
309
309
|
|
|
310
310
|
export var getDefaultSchema = function getDefaultSchema() {
|
|
311
|
-
var _defaultSchema$attrib, _defaultSchema$attrib2, _defaultSchema$
|
|
311
|
+
var _defaultSchema$attrib, _defaultSchema$attrib2, _defaultSchema$protoc, _defaultSchema$protoc2, _defaultSchema$tagNam;
|
|
312
312
|
return _objectSpread(_objectSpread({}, defaultSchema), {}, {
|
|
313
313
|
attributes: _objectSpread(_objectSpread({}, defaultSchema.attributes), {}, {
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
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']),
|
|
318
|
-
svg: ['xmlns', 'viewBox', 'preserveAspectRatio'],
|
|
319
|
-
path: ['d'],
|
|
320
|
-
custom: ['meta', 'value']
|
|
314
|
+
custom: ['meta', 'value'],
|
|
315
|
+
span: ['line'],
|
|
316
|
+
'*': [].concat(_toConsumableArray((_defaultSchema$attrib = (_defaultSchema$attrib2 = defaultSchema.attributes) === null || _defaultSchema$attrib2 === void 0 ? void 0 : _defaultSchema$attrib2['*']) !== null && _defaultSchema$attrib !== void 0 ? _defaultSchema$attrib : []), ['className', 'style'])
|
|
321
317
|
}),
|
|
322
318
|
protocols: _objectSpread(_objectSpread({}, defaultSchema.protocols), {}, {
|
|
323
319
|
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'])
|
|
324
320
|
}),
|
|
325
|
-
tagNames: [].concat(_toConsumableArray((_defaultSchema$tagNam = defaultSchema.tagNames) !== null && _defaultSchema$tagNam !== void 0 ? _defaultSchema$tagNam : []), ['
|
|
321
|
+
tagNames: [].concat(_toConsumableArray((_defaultSchema$tagNam = defaultSchema.tagNames) !== null && _defaultSchema$tagNam !== void 0 ? _defaultSchema$tagNam : []), ['custom'])
|
|
326
322
|
});
|
|
327
323
|
};
|
|
328
324
|
|
|
@@ -345,23 +341,33 @@ export var viewerRender = function viewerRender(root, schema) {
|
|
|
345
341
|
* @returns React 虚拟 DOM 树
|
|
346
342
|
*/
|
|
347
343
|
export var postViewerRender = function postViewerRender(root, options) {
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
344
|
+
try {
|
|
345
|
+
var components = _objectSpread(_objectSpread({}, options.customHTMLElements), {}, {
|
|
346
|
+
input: function input(props) {
|
|
347
|
+
return jsx('input', props);
|
|
348
|
+
},
|
|
349
|
+
custom: function custom(props) {
|
|
350
|
+
var _options$customBlocks;
|
|
351
|
+
return jsx((_options$customBlocks = options.customBlocks[props.meta]) !== null && _options$customBlocks !== void 0 ? _options$customBlocks : 'div', {
|
|
352
|
+
children: props.value
|
|
353
|
+
});
|
|
354
|
+
}
|
|
355
|
+
});
|
|
356
|
+
return toJsxRuntime(unified().use(rehypeKatex).runSync(root), {
|
|
357
|
+
Fragment: Fragment,
|
|
358
|
+
jsx: jsx,
|
|
359
|
+
jsxs: jsxs,
|
|
360
|
+
components: components
|
|
361
|
+
});
|
|
362
|
+
} catch (_unused) {
|
|
363
|
+
return jsx('div', {
|
|
364
|
+
style: {
|
|
365
|
+
fontStyle: 'italic',
|
|
366
|
+
color: 'red'
|
|
367
|
+
},
|
|
368
|
+
children: 'Parse error!'
|
|
369
|
+
});
|
|
370
|
+
}
|
|
365
371
|
};
|
|
366
372
|
var toHTMLProcessor = unified().use(remarkParse).use(remarkGfm).use(remarkMath).use(remarkRehype, {
|
|
367
373
|
allowDangerousHtml: true,
|
|
@@ -149,11 +149,19 @@ var XStarEditor = /*#__PURE__*/React.forwardRef(function (_ref2, ref) {
|
|
|
149
149
|
}
|
|
150
150
|
}
|
|
151
151
|
};
|
|
152
|
+
var render = function render() {
|
|
153
|
+
return listener({
|
|
154
|
+
currentTarget: editor
|
|
155
|
+
});
|
|
156
|
+
};
|
|
152
157
|
editor.addEventListener('scroll', listener);
|
|
153
158
|
viewer.addEventListener('scroll', listener);
|
|
159
|
+
// 查看器子节点更新时会手动触发该事件
|
|
160
|
+
viewer.addEventListener('render', render);
|
|
154
161
|
return function () {
|
|
155
162
|
editor.removeEventListener('scroll', listener);
|
|
156
163
|
viewer.removeEventListener('scroll', listener);
|
|
164
|
+
viewer.removeEventListener('render', render);
|
|
157
165
|
};
|
|
158
166
|
}, []);
|
|
159
167
|
var _useState = useState(initialValue),
|
|
@@ -125,11 +125,6 @@ var XStarMdEditor = /*#__PURE__*/React.forwardRef(function (_ref, ref) {
|
|
|
125
125
|
});
|
|
126
126
|
break;
|
|
127
127
|
}
|
|
128
|
-
case 'compositionstart':
|
|
129
|
-
{
|
|
130
|
-
container.normalizeSelection();
|
|
131
|
-
break;
|
|
132
|
-
}
|
|
133
128
|
}
|
|
134
129
|
};
|
|
135
130
|
var dragEventHandler = function dragEventHandler(e) {
|
|
@@ -176,6 +171,7 @@ var XStarMdEditor = /*#__PURE__*/React.forwardRef(function (_ref, ref) {
|
|
|
176
171
|
{
|
|
177
172
|
// 组合时不触发快捷键
|
|
178
173
|
if (!e.nativeEvent.isComposing) {
|
|
174
|
+
container.normalizeSelection();
|
|
179
175
|
composeHandlers(options.keyboardEventHandlers)({
|
|
180
176
|
history: history,
|
|
181
177
|
sourceCode: sourceCode,
|
|
@@ -377,7 +373,6 @@ var XStarMdEditor = /*#__PURE__*/React.forwardRef(function (_ref, ref) {
|
|
|
377
373
|
contentEditable: true,
|
|
378
374
|
onBlur: focusEventHandler,
|
|
379
375
|
onCompositionEnd: compositionEventHandler,
|
|
380
|
-
onCompositionStart: compositionEventHandler,
|
|
381
376
|
onCopy: clipboardEventHandler,
|
|
382
377
|
onCut: clipboardEventHandler,
|
|
383
378
|
onDragStart: dragEventHandler,
|
|
@@ -57,7 +57,7 @@ var XStarMdViewer = /*#__PURE__*/React.forwardRef(function (_ref, ref) {
|
|
|
57
57
|
}
|
|
58
58
|
}, [enableWebWorker]);
|
|
59
59
|
useEffect(function () {
|
|
60
|
-
_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee() {
|
|
60
|
+
var timer = window.setTimeout( /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee() {
|
|
61
61
|
var root, _worker$current2;
|
|
62
62
|
return _regeneratorRuntime().wrap(function _callee$(_context) {
|
|
63
63
|
while (1) switch (_context.prev = _context.next) {
|
|
@@ -76,8 +76,22 @@ var XStarMdViewer = /*#__PURE__*/React.forwardRef(function (_ref, ref) {
|
|
|
76
76
|
return _context.stop();
|
|
77
77
|
}
|
|
78
78
|
}, _callee);
|
|
79
|
-
}))
|
|
79
|
+
})), 100);
|
|
80
|
+
return function () {
|
|
81
|
+
return window.clearTimeout(timer);
|
|
82
|
+
};
|
|
80
83
|
}, [value, options]);
|
|
84
|
+
|
|
85
|
+
// 确保在末尾输入时能同步滚动
|
|
86
|
+
useEffect(function () {
|
|
87
|
+
var timer = window.setTimeout(function () {
|
|
88
|
+
var _containerRef$current;
|
|
89
|
+
return (_containerRef$current = containerRef.current) === null || _containerRef$current === void 0 ? void 0 : _containerRef$current.dispatchEvent(new Event('render'));
|
|
90
|
+
}, 100);
|
|
91
|
+
return function () {
|
|
92
|
+
return window.clearTimeout(timer);
|
|
93
|
+
};
|
|
94
|
+
}, [children]);
|
|
81
95
|
return /*#__PURE__*/React.createElement("div", {
|
|
82
96
|
ref: containerRef,
|
|
83
97
|
className: classNames("".concat(prefix, "md-viewer"), _defineProperty({}, "".concat(prefix, "theme-").concat(theme), theme), className),
|