x-star-editor 0.3.6 → 0.3.7

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.
@@ -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' /** 'table' */], ['link', 'image', 'mermaid'], ['inlineCode', 'code', 'inlineMath', 'math'], ['orderedList', 'unorderedList', 'taskList'], ['toMarkdown', 'toHTML'], ['undo', 'redo']
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
  };
@@ -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 {
@@ -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;
@@ -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 {
@@ -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$attrib3, _defaultSchema$attrib4, _defaultSchema$attrib5, _defaultSchema$attrib6, _defaultSchema$attrib7, _defaultSchema$attrib8, _defaultSchema$protoc, _defaultSchema$protoc2, _defaultSchema$tagNam;
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
- 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']),
315
- 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']),
316
- 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']),
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 : []), ['svg', 'path', 'custom'])
321
+ tagNames: [].concat(_toConsumableArray((_defaultSchema$tagNam = defaultSchema.tagNames) !== null && _defaultSchema$tagNam !== void 0 ? _defaultSchema$tagNam : []), ['custom'])
326
322
  });
327
323
  };
328
324
 
@@ -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),
@@ -78,6 +78,12 @@ var XStarMdViewer = /*#__PURE__*/React.forwardRef(function (_ref, ref) {
78
78
  }, _callee);
79
79
  }))();
80
80
  }, [value, options]);
81
+
82
+ // 确保在末尾输入时能同步滚动
83
+ useEffect(function () {
84
+ var _containerRef$current;
85
+ (_containerRef$current = containerRef.current) === null || _containerRef$current === void 0 ? void 0 : _containerRef$current.dispatchEvent(new Event('render'));
86
+ }, [children]);
81
87
  return /*#__PURE__*/React.createElement("div", {
82
88
  ref: containerRef,
83
89
  className: classNames("".concat(prefix, "md-viewer"), _defineProperty({}, "".concat(prefix, "theme-").concat(theme), theme), className),
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "x-star-editor",
3
- "version": "0.3.6",
3
+ "version": "0.3.7",
4
4
  "description": "An editor developed by turingstar",
5
5
  "license": "MIT",
6
6
  "module": "dist/index.js",