x-star-editor 0.2.3 → 0.2.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 +40 -84
- package/dist/utils/markdown.d.ts +4 -4
- package/dist/utils/markdown.js +32 -103
- package/dist/x-star-md-viewer/index.js +6 -18
- package/package.json +1 -1
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
import _regeneratorRuntime from "@babel/runtime/helpers/esm/regeneratorRuntime";
|
|
2
|
-
import _asyncToGenerator from "@babel/runtime/helpers/esm/asyncToGenerator";
|
|
3
1
|
import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
|
|
4
2
|
import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
|
|
5
3
|
import classNames from 'classnames';
|
|
@@ -340,40 +338,19 @@ export var getDefaultToolbarItemMap = function getDefaultToolbarItemMap() {
|
|
|
340
338
|
}),
|
|
341
339
|
tooltip: t('toHTML'),
|
|
342
340
|
onClick: function onClick(exec) {
|
|
343
|
-
return exec(
|
|
344
|
-
var
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
_context.t3 = {
|
|
357
|
-
sourceCode: _context.t1,
|
|
358
|
-
selection: _context.t2
|
|
359
|
-
};
|
|
360
|
-
_context.t4 = selection;
|
|
361
|
-
_context.t5 = {
|
|
362
|
-
type: 'set',
|
|
363
|
-
payload: _context.t3,
|
|
364
|
-
selection: _context.t4
|
|
365
|
-
};
|
|
366
|
-
return _context.abrupt("return", (0, _context.t0)(_context.t5));
|
|
367
|
-
case 10:
|
|
368
|
-
case "end":
|
|
369
|
-
return _context.stop();
|
|
370
|
-
}
|
|
371
|
-
}, _callee);
|
|
372
|
-
}));
|
|
373
|
-
return function (_x) {
|
|
374
|
-
return _ref4.apply(this, arguments);
|
|
375
|
-
};
|
|
376
|
-
}());
|
|
341
|
+
return exec(function (_ref3) {
|
|
342
|
+
var sourceCode = _ref3.sourceCode,
|
|
343
|
+
selection = _ref3.selection,
|
|
344
|
+
dispatch = _ref3.dispatch;
|
|
345
|
+
return dispatch({
|
|
346
|
+
type: 'set',
|
|
347
|
+
payload: {
|
|
348
|
+
sourceCode: toHTML(sourceCode),
|
|
349
|
+
selection: createSelection(0)
|
|
350
|
+
},
|
|
351
|
+
selection: selection
|
|
352
|
+
});
|
|
353
|
+
});
|
|
377
354
|
}
|
|
378
355
|
},
|
|
379
356
|
toMarkdown: {
|
|
@@ -382,44 +359,23 @@ export var getDefaultToolbarItemMap = function getDefaultToolbarItemMap() {
|
|
|
382
359
|
}),
|
|
383
360
|
tooltip: t('toMarkdown'),
|
|
384
361
|
onClick: function onClick(exec) {
|
|
385
|
-
return exec(
|
|
386
|
-
var
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
_context2.t3 = {
|
|
399
|
-
sourceCode: _context2.t1,
|
|
400
|
-
selection: _context2.t2
|
|
401
|
-
};
|
|
402
|
-
_context2.t4 = selection;
|
|
403
|
-
_context2.t5 = {
|
|
404
|
-
type: 'set',
|
|
405
|
-
payload: _context2.t3,
|
|
406
|
-
selection: _context2.t4
|
|
407
|
-
};
|
|
408
|
-
return _context2.abrupt("return", (0, _context2.t0)(_context2.t5));
|
|
409
|
-
case 10:
|
|
410
|
-
case "end":
|
|
411
|
-
return _context2.stop();
|
|
412
|
-
}
|
|
413
|
-
}, _callee2);
|
|
414
|
-
}));
|
|
415
|
-
return function (_x2) {
|
|
416
|
-
return _ref6.apply(this, arguments);
|
|
417
|
-
};
|
|
418
|
-
}());
|
|
362
|
+
return exec(function (_ref4) {
|
|
363
|
+
var sourceCode = _ref4.sourceCode,
|
|
364
|
+
selection = _ref4.selection,
|
|
365
|
+
dispatch = _ref4.dispatch;
|
|
366
|
+
return dispatch({
|
|
367
|
+
type: 'set',
|
|
368
|
+
payload: {
|
|
369
|
+
sourceCode: toMarkdown(sourceCode),
|
|
370
|
+
selection: createSelection(0)
|
|
371
|
+
},
|
|
372
|
+
selection: selection
|
|
373
|
+
});
|
|
374
|
+
});
|
|
419
375
|
}
|
|
420
376
|
},
|
|
421
|
-
undo: function undo(
|
|
422
|
-
var history =
|
|
377
|
+
undo: function undo(_ref5) {
|
|
378
|
+
var history = _ref5.history;
|
|
423
379
|
return {
|
|
424
380
|
children: /*#__PURE__*/React.createElement(SvgUndo, {
|
|
425
381
|
className: classNames("".concat(prefix, "icon"))
|
|
@@ -447,12 +403,12 @@ export var getDefaultToolbarItems = function getDefaultToolbarItems() {
|
|
|
447
403
|
];
|
|
448
404
|
};
|
|
449
405
|
|
|
450
|
-
var Toolbar = function Toolbar(
|
|
451
|
-
var className =
|
|
452
|
-
style =
|
|
453
|
-
itemMap =
|
|
454
|
-
items =
|
|
455
|
-
exec =
|
|
406
|
+
var Toolbar = function Toolbar(_ref6) {
|
|
407
|
+
var className = _ref6.className,
|
|
408
|
+
style = _ref6.style,
|
|
409
|
+
itemMap = _ref6.itemMap,
|
|
410
|
+
items = _ref6.items,
|
|
411
|
+
exec = _ref6.exec;
|
|
456
412
|
var toolbarRef = useRef(null);
|
|
457
413
|
var ctx = exec(function (ctx) {
|
|
458
414
|
return ctx;
|
|
@@ -471,12 +427,12 @@ var Toolbar = function Toolbar(_ref8) {
|
|
|
471
427
|
if (!toolbarItem) {
|
|
472
428
|
return undefined;
|
|
473
429
|
}
|
|
474
|
-
var
|
|
475
|
-
children =
|
|
476
|
-
disabled =
|
|
477
|
-
tooltip =
|
|
478
|
-
_popoverRender =
|
|
479
|
-
_onClick2 =
|
|
430
|
+
var _ref7 = typeof toolbarItem === 'function' ? toolbarItem(ctx) : toolbarItem,
|
|
431
|
+
children = _ref7.children,
|
|
432
|
+
disabled = _ref7.disabled,
|
|
433
|
+
tooltip = _ref7.tooltip,
|
|
434
|
+
_popoverRender = _ref7.popoverRender,
|
|
435
|
+
_onClick2 = _ref7.onClick;
|
|
480
436
|
return /*#__PURE__*/React.createElement(Button, {
|
|
481
437
|
key: index,
|
|
482
438
|
toolbarRef: toolbarRef,
|
package/dist/utils/markdown.d.ts
CHANGED
|
@@ -35,7 +35,7 @@ export declare const getDefaultSchema: () => Schema;
|
|
|
35
35
|
* @param schema 过滤模式
|
|
36
36
|
* @returns 新的 Hast 树
|
|
37
37
|
*/
|
|
38
|
-
export declare const viewerRender: (root: HastRoot, schema: Schema) =>
|
|
38
|
+
export declare const viewerRender: (root: HastRoot, schema: Schema) => import("hast").Root;
|
|
39
39
|
/**
|
|
40
40
|
* 将 Hast 树映射到 React 虚拟 DOM 树
|
|
41
41
|
*
|
|
@@ -50,19 +50,19 @@ export declare const postViewerRender: (root: HastRoot, options: ViewerOptions)
|
|
|
50
50
|
* @param sourceCode Markdown 文本
|
|
51
51
|
* @returns HTML 文本
|
|
52
52
|
*/
|
|
53
|
-
export declare const toHTML: (sourceCode: string) =>
|
|
53
|
+
export declare const toHTML: (sourceCode: string) => string;
|
|
54
54
|
/**
|
|
55
55
|
* 将带有 HTML 的 Markdown 文本转成 Markdown 文本
|
|
56
56
|
*
|
|
57
57
|
* @param sourceCode 带有 HTML 的 Markdown 文本
|
|
58
58
|
* @returns Markdown 文本
|
|
59
59
|
*/
|
|
60
|
-
export declare const toMarkdown: (sourceCode: string) =>
|
|
60
|
+
export declare const toMarkdown: (sourceCode: string) => string;
|
|
61
61
|
/**
|
|
62
62
|
* 将 Markdown 文本转成纯文本
|
|
63
63
|
*
|
|
64
64
|
* @param sourceCode Markdown 文本
|
|
65
65
|
* @returns 纯文本
|
|
66
66
|
*/
|
|
67
|
-
export declare const toText: (sourceCode: string) =>
|
|
67
|
+
export declare const toText: (sourceCode: string) => string;
|
|
68
68
|
export {};
|
package/dist/utils/markdown.js
CHANGED
|
@@ -340,43 +340,27 @@ export var getDefaultSchema = function getDefaultSchema() {
|
|
|
340
340
|
* @param schema 过滤模式
|
|
341
341
|
* @returns 新的 Hast 树
|
|
342
342
|
*/
|
|
343
|
-
export var viewerRender =
|
|
344
|
-
|
|
345
|
-
return
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
}
|
|
361
|
-
} catch (err) {
|
|
362
|
-
_iterator2.e(err);
|
|
363
|
-
} finally {
|
|
364
|
-
_iterator2.f();
|
|
365
|
-
}
|
|
366
|
-
};
|
|
367
|
-
}).run(root);
|
|
368
|
-
case 2:
|
|
369
|
-
return _context2.abrupt("return", _context2.sent);
|
|
370
|
-
case 3:
|
|
371
|
-
case "end":
|
|
372
|
-
return _context2.stop();
|
|
343
|
+
export var viewerRender = function viewerRender(root, schema) {
|
|
344
|
+
return unified().use(rehypeRaw).use(rehypeSanitize, schema).use(function () {
|
|
345
|
+
return function (root) {
|
|
346
|
+
var _iterator2 = _createForOfIteratorHelper(root.children),
|
|
347
|
+
_step2;
|
|
348
|
+
try {
|
|
349
|
+
for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
|
|
350
|
+
var node = _step2.value;
|
|
351
|
+
if ('properties' in node && node.properties) {
|
|
352
|
+
var _node$position4;
|
|
353
|
+
node.properties['data-line'] = (_node$position4 = node.position) === null || _node$position4 === void 0 ? void 0 : _node$position4.start.line;
|
|
354
|
+
}
|
|
355
|
+
}
|
|
356
|
+
} catch (err) {
|
|
357
|
+
_iterator2.e(err);
|
|
358
|
+
} finally {
|
|
359
|
+
_iterator2.f();
|
|
373
360
|
}
|
|
374
|
-
}
|
|
375
|
-
}));
|
|
376
|
-
|
|
377
|
-
return _ref2.apply(this, arguments);
|
|
378
|
-
};
|
|
379
|
-
}();
|
|
361
|
+
};
|
|
362
|
+
}).runSync(root);
|
|
363
|
+
};
|
|
380
364
|
|
|
381
365
|
/**
|
|
382
366
|
* 将 Hast 树映射到 React 虚拟 DOM 树
|
|
@@ -391,10 +375,10 @@ export var postViewerRender = function postViewerRender(root, options) {
|
|
|
391
375
|
jsx: jsx,
|
|
392
376
|
jsxs: jsxs,
|
|
393
377
|
components: _objectSpread(_objectSpread({}, options.customHTMLElements), {}, {
|
|
394
|
-
custom: function custom(
|
|
378
|
+
custom: function custom(_ref2) {
|
|
395
379
|
var _options$customBlocks;
|
|
396
|
-
var meta =
|
|
397
|
-
value =
|
|
380
|
+
var meta = _ref2.meta,
|
|
381
|
+
value = _ref2.value;
|
|
398
382
|
return jsx((_options$customBlocks = options.customBlocks[meta]) !== null && _options$customBlocks !== void 0 ? _options$customBlocks : 'div', {
|
|
399
383
|
children: value
|
|
400
384
|
});
|
|
@@ -412,25 +396,9 @@ var toHTMLProcessor = unified().use(remarkParse).use(remarkGfm).use(remarkRehype
|
|
|
412
396
|
* @param sourceCode Markdown 文本
|
|
413
397
|
* @returns HTML 文本
|
|
414
398
|
*/
|
|
415
|
-
export var toHTML =
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
while (1) switch (_context3.prev = _context3.next) {
|
|
419
|
-
case 0:
|
|
420
|
-
_context3.next = 2;
|
|
421
|
-
return toHTMLProcessor.process(sourceCode);
|
|
422
|
-
case 2:
|
|
423
|
-
return _context3.abrupt("return", _context3.sent.toString());
|
|
424
|
-
case 3:
|
|
425
|
-
case "end":
|
|
426
|
-
return _context3.stop();
|
|
427
|
-
}
|
|
428
|
-
}, _callee3);
|
|
429
|
-
}));
|
|
430
|
-
return function toHTML(_x4) {
|
|
431
|
-
return _ref4.apply(this, arguments);
|
|
432
|
-
};
|
|
433
|
-
}();
|
|
399
|
+
export var toHTML = function toHTML(sourceCode) {
|
|
400
|
+
return toHTMLProcessor.processSync(sourceCode).toString();
|
|
401
|
+
};
|
|
434
402
|
var toMarkdownProcessor = unified().use(rehypeRemark, {
|
|
435
403
|
newlines: true
|
|
436
404
|
}).use(remarkGfm).use(remarkStringify).freeze();
|
|
@@ -441,32 +409,9 @@ var toMarkdownProcessor = unified().use(rehypeRemark, {
|
|
|
441
409
|
* @param sourceCode 带有 HTML 的 Markdown 文本
|
|
442
410
|
* @returns Markdown 文本
|
|
443
411
|
*/
|
|
444
|
-
export var toMarkdown =
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
while (1) switch (_context4.prev = _context4.next) {
|
|
448
|
-
case 0:
|
|
449
|
-
_context4.t0 = toMarkdownProcessor;
|
|
450
|
-
_context4.t1 = toMarkdownProcessor;
|
|
451
|
-
_context4.next = 4;
|
|
452
|
-
return toHTMLProcessor.run(toHTMLProcessor.parse(sourceCode));
|
|
453
|
-
case 4:
|
|
454
|
-
_context4.t2 = _context4.sent;
|
|
455
|
-
_context4.next = 7;
|
|
456
|
-
return _context4.t1.run.call(_context4.t1, _context4.t2);
|
|
457
|
-
case 7:
|
|
458
|
-
_context4.t3 = _context4.sent;
|
|
459
|
-
return _context4.abrupt("return", _context4.t0.stringify.call(_context4.t0, _context4.t3));
|
|
460
|
-
case 9:
|
|
461
|
-
case "end":
|
|
462
|
-
return _context4.stop();
|
|
463
|
-
}
|
|
464
|
-
}, _callee4);
|
|
465
|
-
}));
|
|
466
|
-
return function toMarkdown(_x5) {
|
|
467
|
-
return _ref5.apply(this, arguments);
|
|
468
|
-
};
|
|
469
|
-
}();
|
|
412
|
+
export var toMarkdown = function toMarkdown(sourceCode) {
|
|
413
|
+
return toMarkdownProcessor.stringify(toMarkdownProcessor.runSync(toHTMLProcessor.runSync(toHTMLProcessor.parse(sourceCode))));
|
|
414
|
+
};
|
|
470
415
|
var toTextProcessor = unified().use(remarkParse).use(remarkGfm).use(strip).use(remarkStringify).freeze();
|
|
471
416
|
|
|
472
417
|
/**
|
|
@@ -475,22 +420,6 @@ var toTextProcessor = unified().use(remarkParse).use(remarkGfm).use(strip).use(r
|
|
|
475
420
|
* @param sourceCode Markdown 文本
|
|
476
421
|
* @returns 纯文本
|
|
477
422
|
*/
|
|
478
|
-
export var toText =
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
while (1) switch (_context5.prev = _context5.next) {
|
|
482
|
-
case 0:
|
|
483
|
-
_context5.next = 2;
|
|
484
|
-
return toTextProcessor.process(sourceCode);
|
|
485
|
-
case 2:
|
|
486
|
-
return _context5.abrupt("return", _context5.sent.toString());
|
|
487
|
-
case 3:
|
|
488
|
-
case "end":
|
|
489
|
-
return _context5.stop();
|
|
490
|
-
}
|
|
491
|
-
}, _callee5);
|
|
492
|
-
}));
|
|
493
|
-
return function toText(_x6) {
|
|
494
|
-
return _ref6.apply(this, arguments);
|
|
495
|
-
};
|
|
496
|
-
}();
|
|
423
|
+
export var toText = function toText(sourceCode) {
|
|
424
|
+
return toTextProcessor.processSync(sourceCode).toString();
|
|
425
|
+
};
|