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.
@@ -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( /*#__PURE__*/function () {
344
- var _ref4 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(_ref3) {
345
- var sourceCode, selection, dispatch;
346
- return _regeneratorRuntime().wrap(function _callee$(_context) {
347
- while (1) switch (_context.prev = _context.next) {
348
- case 0:
349
- sourceCode = _ref3.sourceCode, selection = _ref3.selection, dispatch = _ref3.dispatch;
350
- _context.t0 = dispatch;
351
- _context.next = 4;
352
- return toHTML(sourceCode);
353
- case 4:
354
- _context.t1 = _context.sent;
355
- _context.t2 = createSelection(0);
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( /*#__PURE__*/function () {
386
- var _ref6 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2(_ref5) {
387
- var sourceCode, selection, dispatch;
388
- return _regeneratorRuntime().wrap(function _callee2$(_context2) {
389
- while (1) switch (_context2.prev = _context2.next) {
390
- case 0:
391
- sourceCode = _ref5.sourceCode, selection = _ref5.selection, dispatch = _ref5.dispatch;
392
- _context2.t0 = dispatch;
393
- _context2.next = 4;
394
- return toMarkdown(sourceCode);
395
- case 4:
396
- _context2.t1 = _context2.sent;
397
- _context2.t2 = createSelection(0);
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(_ref7) {
422
- var history = _ref7.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(_ref8) {
451
- var className = _ref8.className,
452
- style = _ref8.style,
453
- itemMap = _ref8.itemMap,
454
- items = _ref8.items,
455
- exec = _ref8.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 _ref9 = typeof toolbarItem === 'function' ? toolbarItem(ctx) : toolbarItem,
475
- children = _ref9.children,
476
- disabled = _ref9.disabled,
477
- tooltip = _ref9.tooltip,
478
- _popoverRender = _ref9.popoverRender,
479
- _onClick2 = _ref9.onClick;
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,
@@ -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) => Promise<import("hast").Root>;
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) => Promise<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) => Promise<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) => Promise<string>;
67
+ export declare const toText: (sourceCode: string) => string;
68
68
  export {};
@@ -340,43 +340,27 @@ export var getDefaultSchema = function getDefaultSchema() {
340
340
  * @param schema 过滤模式
341
341
  * @returns 新的 Hast 树
342
342
  */
343
- export var viewerRender = /*#__PURE__*/function () {
344
- var _ref2 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2(root, schema) {
345
- return _regeneratorRuntime().wrap(function _callee2$(_context2) {
346
- while (1) switch (_context2.prev = _context2.next) {
347
- case 0:
348
- _context2.next = 2;
349
- return unified().use(rehypeRaw).use(rehypeSanitize, schema).use(function () {
350
- return function (root) {
351
- var _iterator2 = _createForOfIteratorHelper(root.children),
352
- _step2;
353
- try {
354
- for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
355
- var node = _step2.value;
356
- if ('properties' in node && node.properties) {
357
- var _node$position4;
358
- node.properties['data-line'] = (_node$position4 = node.position) === null || _node$position4 === void 0 ? void 0 : _node$position4.start.line;
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
- }, _callee2);
375
- }));
376
- return function viewerRender(_x2, _x3) {
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(_ref3) {
378
+ custom: function custom(_ref2) {
395
379
  var _options$customBlocks;
396
- var meta = _ref3.meta,
397
- value = _ref3.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 = /*#__PURE__*/function () {
416
- var _ref4 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee3(sourceCode) {
417
- return _regeneratorRuntime().wrap(function _callee3$(_context3) {
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 = /*#__PURE__*/function () {
445
- var _ref5 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee4(sourceCode) {
446
- return _regeneratorRuntime().wrap(function _callee4$(_context4) {
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 = /*#__PURE__*/function () {
479
- var _ref6 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee5(sourceCode) {
480
- return _regeneratorRuntime().wrap(function _callee5$(_context5) {
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
+ };