x-star-editor 0.2.6 → 0.3.1

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.
@@ -27,43 +27,6 @@ var stateReducer = function stateReducer(_ref, action) {
27
27
  selection: createSelection(startOffset + text.length)
28
28
  };
29
29
  }
30
- case 'delete':
31
- {
32
- // 选区不为空
33
- if (startOffset < endOffset) {
34
- return {
35
- sourceCode: "".concat(before).concat(after),
36
- selection: createSelection(startOffset)
37
- };
38
- }
39
-
40
- // 选区为空,根据删除方向和边界生成新状态
41
- if (action.payload) {
42
- var _action$payload = action.payload,
43
- direction = _action$payload.direction,
44
- boundary = _action$payload.boundary;
45
- if (direction === 'backward' && startOffset) {
46
- var index = before.lastIndexOf('\n');
47
- var length = boundary === 'char' || index === before.length - 1 ? 1 : before.length - 1 - index;
48
- return {
49
- sourceCode: "".concat(before.slice(0, before.length - length)).concat(after),
50
- selection: createSelection(startOffset - length)
51
- };
52
- }
53
- if (direction === 'forward' && startOffset < sourceCode.length) {
54
- var _index = "".concat(after, "\n").indexOf('\n');
55
- var _length = boundary === 'char' || !_index ? 1 : _index;
56
- return {
57
- sourceCode: "".concat(before).concat(after.slice(_length)),
58
- selection: createSelection(startOffset)
59
- };
60
- }
61
- }
62
- return {
63
- sourceCode: sourceCode,
64
- selection: action.selection
65
- };
66
- }
67
30
  case 'toggle':
68
31
  {
69
32
  var lineStartOffset = before.lastIndexOf('\n') + 1;
@@ -97,10 +60,10 @@ var stateReducer = function stateReducer(_ref, action) {
97
60
  }
98
61
  case 'code':
99
62
  {
100
- var _action$payload2 = action.payload,
101
- lang = _action$payload2.lang,
102
- value = _action$payload2.value,
103
- showLineNumbers = _action$payload2.showLineNumbers;
63
+ var _action$payload = action.payload,
64
+ lang = _action$payload.lang,
65
+ value = _action$payload.value,
66
+ showLineNumbers = _action$payload.showLineNumbers;
104
67
  var _startOffset = lineEndOffset + lang.length + (showLineNumbers ? 21 : 5);
105
68
  return {
106
69
  sourceCode: "".concat(sourceCode.slice(0, lineEndOffset), "\n```").concat(lang).concat(showLineNumbers ? ' showLineNumbers' : '', "\n").concat(value, "\n```\n").concat(lineAfter),
@@ -164,13 +127,13 @@ var stateReducer = function stateReducer(_ref, action) {
164
127
  case 'image':
165
128
  case 'link':
166
129
  {
167
- var _action$payload3 = action.payload,
168
- _type = _action$payload3.type,
169
- url = _action$payload3.url,
170
- description = _action$payload3.description;
130
+ var _action$payload2 = action.payload,
131
+ _type = _action$payload2.type,
132
+ url = _action$payload2.url,
133
+ description = _action$payload2.description;
171
134
  return {
172
- sourceCode: "".concat(before).concat(_type === 'link' ? '' : '!', "[").concat(description, "](").concat(url, ")").concat(after),
173
- selection: createSelection(startOffset + url.length + description.length + 4 + (_type === 'link' ? 0 : 1))
135
+ sourceCode: "".concat(before).concat(_type === 'image' ? '!' : '', "[").concat(description, "](").concat(url, ")").concat(after),
136
+ selection: createSelection(startOffset + url.length + description.length + 4 + (_type === 'image' ? 1 : 0))
174
137
  };
175
138
  }
176
139
  case 'math':
@@ -196,9 +159,9 @@ var stateReducer = function stateReducer(_ref, action) {
196
159
  }
197
160
  case 'set':
198
161
  {
199
- var _action$payload4 = action.payload,
200
- _sourceCode = _action$payload4.sourceCode,
201
- selection = _action$payload4.selection;
162
+ var _action$payload3 = action.payload,
163
+ _sourceCode = _action$payload3.sourceCode,
164
+ selection = _action$payload3.selection;
202
165
  return {
203
166
  sourceCode: _sourceCode.replace(/\r\n?/g, '\n'),
204
167
  selection: selection
@@ -251,6 +214,20 @@ var historyReducer = function historyReducer(_ref2, action) {
251
214
  selection: states[index + 1].selection
252
215
  };
253
216
  }
217
+ case 'batch':
218
+ {
219
+ var _action$selection2, _action$selection3;
220
+ return {
221
+ states: [].concat(_toConsumableArray(states.slice(0, index)), [_objectSpread(_objectSpread({}, states[index]), {}, {
222
+ selection: (_action$selection2 = action.selection) !== null && _action$selection2 !== void 0 ? _action$selection2 : states[index].selection,
223
+ action: _objectSpread(_objectSpread({}, states[index].action), {}, {
224
+ batch: false
225
+ })
226
+ })]),
227
+ index: index,
228
+ selection: (_action$selection3 = action.selection) !== null && _action$selection3 !== void 0 ? _action$selection3 : selection
229
+ };
230
+ }
254
231
  case 'select':
255
232
  {
256
233
  return {
@@ -270,8 +247,19 @@ var historyReducer = function historyReducer(_ref2, action) {
270
247
  selection: selection
271
248
  };
272
249
  }
250
+ if (states[index].action.batch && action.batch) {
251
+ return {
252
+ states: [].concat(_toConsumableArray(states.slice(0, index)), [_objectSpread(_objectSpread({}, states[index]), state)]),
253
+ index: index,
254
+ selection: state.selection
255
+ };
256
+ }
273
257
  return {
274
- states: [].concat(_toConsumableArray(states.slice(index < 100 ? 0 : index - 99, index + 1)), [_objectSpread(_objectSpread({}, state), {}, {
258
+ states: [].concat(_toConsumableArray(states.slice(index < 100 ? 0 : index - 99, index)), [_objectSpread(_objectSpread({}, states[index]), {}, {
259
+ action: _objectSpread(_objectSpread({}, states[index].action), {}, {
260
+ batch: false
261
+ })
262
+ }), _objectSpread(_objectSpread({}, state), {}, {
275
263
  action: action
276
264
  })]),
277
265
  index: index < 100 ? index + 1 : 100,
@@ -3,7 +3,6 @@ import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
3
3
  import _regeneratorRuntime from "@babel/runtime/helpers/esm/regeneratorRuntime";
4
4
  import _asyncToGenerator from "@babel/runtime/helpers/esm/asyncToGenerator";
5
5
  import _createForOfIteratorHelper from "@babel/runtime/helpers/esm/createForOfIteratorHelper";
6
- import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
7
6
  import { toJsxRuntime } from 'hast-util-to-jsx-runtime';
8
7
  import { toText as hastToText } from 'hast-util-to-text';
9
8
  import { Fragment, jsx, jsxs } from 'react/jsx-runtime';
@@ -32,20 +31,6 @@ import rehypeRawPositions from "./rehype/rehype-raw-positions";
32
31
  */
33
32
  var toMdastProcessor = unified().use(remarkParse).use(remarkGfm).use(remarkMath).freeze();
34
33
 
35
- /**
36
- * 带缓存的解析函数
37
- *
38
- * @param sourceCode Markdown 文本
39
- * @returns Mdast 树
40
- */
41
- var cachedParse = function () {
42
- var cache = {};
43
- return function (sourceCode) {
44
- var _cache$sourceCode;
45
- return (_cache$sourceCode = cache[sourceCode]) !== null && _cache$sourceCode !== void 0 ? _cache$sourceCode : (cache = _defineProperty({}, sourceCode, toMdastProcessor.parse(sourceCode)))[sourceCode];
46
- };
47
- }();
48
-
49
34
  /**
50
35
  * 将 Markdown 文本映射到 DOM 树,第一层为 `<div>` 块元素,第二层为 `<div>` 行元素,之后均为 `<span>` 元素
51
36
  *
@@ -243,7 +228,7 @@ export var editorRender = function editorRender(sourceCode) {
243
228
  }
244
229
  addText(sourceCode.slice(scanOffset, parentEndOffset), true);
245
230
  };
246
- getChildren(cachedParse(sourceCode).children, sourceCode.length);
231
+ getChildren(toMdastProcessor.parse(sourceCode).children, sourceCode.length);
247
232
  if (scanOffset <= sourceCode.length) {
248
233
  // 添加最后一行文本
249
234
  block.append(createLine(sourceCode.slice(scanOffset)));
@@ -289,7 +274,7 @@ export var preViewerRender = /*#__PURE__*/function () {
289
274
  while (1) switch (_context.prev = _context.next) {
290
275
  case 0:
291
276
  _context.next = 2;
292
- return toHastProcessor.run(cachedParse(sourceCode));
277
+ return toHastProcessor.run(toMdastProcessor.parse(sourceCode));
293
278
  case 2:
294
279
  return _context.abrupt("return", _context.sent);
295
280
  case 3:
@@ -3,7 +3,7 @@ import classNames from 'classnames';
3
3
  import React, { useEffect, useImperativeHandle, useMemo, useRef } from 'react';
4
4
  import Toolbar, { getDefaultToolbarItemMap, getDefaultToolbarItems } from "../components/Toolbar";
5
5
  import { LocaleProvider } from "../locales";
6
- import { getRange, useContainer } from "../utils/container";
6
+ import { createSelection, getRange, useContainer } from "../utils/container";
7
7
  import { prefix } from "../utils/global";
8
8
  import { composeHandlers, getDefaultKeyboardEventHandlers } from "../utils/handler";
9
9
  import { useHistory } from "../utils/history";
@@ -26,11 +26,14 @@ var XStarMdEditor = /*#__PURE__*/React.forwardRef(function (_ref, ref) {
26
26
  sourceCode = _useHistory.sourceCode,
27
27
  selection = _useHistory.selection,
28
28
  dispatch = _useHistory.dispatch;
29
+ var ignoreNext = useRef(false);
29
30
  var initialized = useRef(false);
30
31
 
31
32
  // 将文本同步到容器
32
33
  useEffect(function () {
33
- container.setText(sourceCode);
34
+ if (!ignoreNext.current) {
35
+ container.setText(sourceCode);
36
+ }
34
37
  if (initialized.current) {
35
38
  onChange === null || onChange === void 0 ? void 0 : onChange(sourceCode);
36
39
  }
@@ -38,16 +41,14 @@ var XStarMdEditor = /*#__PURE__*/React.forwardRef(function (_ref, ref) {
38
41
 
39
42
  // 将选区同步到容器
40
43
  useEffect(function () {
41
- if (initialized.current) {
44
+ if (!ignoreNext.current && initialized.current) {
42
45
  container.setSelection(selection);
43
46
  }
44
47
  }, [selection]);
45
48
  useEffect(function () {
49
+ ignoreNext.current = false;
46
50
  initialized.current = true;
47
- return function () {
48
- initialized.current = false;
49
- };
50
- }, []);
51
+ }, [sourceCode, selection]);
51
52
  var historyLatest = useRef(history);
52
53
  historyLatest.current = history;
53
54
  var sourceCodeLatest = useRef(sourceCode);
@@ -92,115 +93,52 @@ var XStarMdEditor = /*#__PURE__*/React.forwardRef(function (_ref, ref) {
92
93
  case 'copy':
93
94
  case 'cut':
94
95
  {
96
+ // 防止传输其他类型数据
95
97
  e.preventDefault();
96
98
  if (startOffset < endOffset) {
97
99
  e.clipboardData.setData('text/plain', sourceCode.slice(startOffset, endOffset));
98
100
  if (e.type === 'cut') {
99
101
  dispatch({
100
- type: 'delete',
102
+ type: 'insert',
103
+ payload: {
104
+ text: ''
105
+ },
101
106
  selection: selection
102
107
  });
103
108
  }
104
109
  }
105
110
  break;
106
111
  }
107
- case 'paste':
108
- {
109
- e.preventDefault();
110
- if (e.clipboardData.types.includes('text/plain')) {
111
- dispatch({
112
- type: 'insert',
113
- payload: {
114
- text: e.clipboardData.getData('text/plain')
115
- },
116
- selection: selection
117
- });
118
- } else if (e.clipboardData.types.includes('Files')) {
119
- var _file = e.clipboardData.files[0];
120
- onInsertFile === null || onInsertFile === void 0 ? void 0 : onInsertFile(_file, {
121
- description: _file.name,
122
- image: _file.type.startsWith('image/')
123
- });
124
- }
125
- break;
126
- }
127
112
  }
128
113
  };
129
-
130
- /**
131
- * 开始组合时的选区
132
- */
133
- var compositionStartSelection = useRef();
134
-
135
- /**
136
- * 容器同步控制器
137
- */
138
- var syncController = useMemo(function () {
139
- var timer = 0;
140
-
141
- /**
142
- * 将最新的文本和选区同步到容器
143
- */
144
- var sync = function sync() {
145
- if (compositionStartSelection.current) {
146
- var _selection = getSelection();
147
- container.setText(sourceCodeLatest.current);
148
- container.setSelection(_selection);
149
- compositionStartSelection.current = undefined;
150
- }
151
- timer = 0;
152
- };
153
- return {
154
- /**
155
- * 在下个事件循环中同步
156
- */
157
- start: function start() {
158
- if (!timer) {
159
- timer = window.setTimeout(sync);
160
- }
161
- },
162
- /**
163
- * 立即执行下个事件循环中的同步
164
- */
165
- flush: function flush() {
166
- if (timer) {
167
- window.clearTimeout(timer);
168
- sync();
169
- }
170
- }
171
- };
172
- }, []);
173
114
  var compositionEventHandler = function compositionEventHandler(e) {
174
115
  switch (e.type) {
175
116
  case 'compositionend':
176
117
  {
177
- syncController.start();
178
- break;
179
- }
180
- case 'compositionstart':
181
- {
182
- syncController.flush();
183
- compositionStartSelection.current = getSelection();
118
+ // 组合时不更新 DOM,组合结束统一更新
119
+ var _selection = getSelection();
120
+ container.setText(sourceCodeLatest.current);
121
+ container.setSelection(_selection);
122
+ dispatch({
123
+ type: 'batch'
124
+ });
184
125
  break;
185
126
  }
186
127
  }
187
128
  };
188
129
  var dragEventHandler = function dragEventHandler(e) {
130
+ var selection = getSelection();
131
+ var _getRange2 = getRange(selection),
132
+ startOffset = _getRange2.startOffset,
133
+ endOffset = _getRange2.endOffset;
189
134
  switch (e.type) {
190
- case 'drop':
135
+ case 'dragstart':
191
136
  {
192
- var _selection2 = getSelection();
193
- window.setTimeout(function () {
194
- container.normalize();
195
- dispatch({
196
- type: 'set',
197
- payload: {
198
- sourceCode: container.getText(),
199
- selection: getSelection()
200
- },
201
- selection: _selection2
202
- });
203
- });
137
+ if (startOffset < endOffset) {
138
+ // 防止传输其他类型数据
139
+ e.dataTransfer.clearData();
140
+ e.dataTransfer.setData('text/plain', sourceCode.slice(startOffset, endOffset));
141
+ }
204
142
  break;
205
143
  }
206
144
  }
@@ -214,26 +152,6 @@ var XStarMdEditor = /*#__PURE__*/React.forwardRef(function (_ref, ref) {
214
152
  }
215
153
  }
216
154
  };
217
- var formEventHandler = function formEventHandler(e) {
218
- switch (e.type) {
219
- case 'beforeinput':
220
- {
221
- e.preventDefault();
222
- if ('data' in e && typeof e.data === 'string') {
223
- var _compositionStartSele;
224
- dispatch({
225
- type: 'insert',
226
- payload: {
227
- text: e.data
228
- },
229
- selection: (_compositionStartSele = compositionStartSelection.current) !== null && _compositionStartSele !== void 0 ? _compositionStartSele : getSelection()
230
- });
231
- compositionStartSelection.current = undefined;
232
- }
233
- break;
234
- }
235
- }
236
- };
237
155
  var onInsertFileLatest = useRef(onInsertFile);
238
156
  onInsertFileLatest.current = onInsertFile;
239
157
  var options = useMemo(function () {
@@ -250,9 +168,8 @@ var XStarMdEditor = /*#__PURE__*/React.forwardRef(function (_ref, ref) {
250
168
  switch (e.type) {
251
169
  case 'keydown':
252
170
  {
253
- if (compositionStartSelection.current) {
254
- e.preventDefault();
255
- } else {
171
+ // 组合时不触发快捷键
172
+ if (!e.nativeEvent.isComposing) {
256
173
  composeHandlers(options.keyboardEventHandlers)({
257
174
  history: history,
258
175
  sourceCode: sourceCode,
@@ -265,6 +182,176 @@ var XStarMdEditor = /*#__PURE__*/React.forwardRef(function (_ref, ref) {
265
182
  }
266
183
  }
267
184
  };
185
+ useEffect(function () {
186
+ var _containerRef$current;
187
+ var listener = function listener(e) {
188
+ var targetRange = e.getTargetRanges()[0];
189
+ if (!containerRef.current || !targetRange) {
190
+ return;
191
+ }
192
+ var startOffset = container.getOffset(containerRef.current, targetRange.startContainer, targetRange.startOffset);
193
+ var endOffset = container.getOffset(containerRef.current, targetRange.endContainer, targetRange.endOffset);
194
+ var selection = createSelection(startOffset, endOffset);
195
+ switch (e.inputType) {
196
+ case 'insertText':
197
+ {
198
+ e.preventDefault();
199
+ if (e.data !== null) {
200
+ dispatch({
201
+ type: 'insert',
202
+ payload: {
203
+ text: e.data
204
+ },
205
+ selection: selection
206
+ });
207
+ }
208
+ break;
209
+ }
210
+ case 'insertReplacementText':
211
+ case 'insertFromDrop':
212
+ case 'insertFromPaste':
213
+ {
214
+ var _e$dataTransfer, _e$dataTransfer2;
215
+ e.preventDefault();
216
+ if ((_e$dataTransfer = e.dataTransfer) !== null && _e$dataTransfer !== void 0 && _e$dataTransfer.types.includes('text/plain')) {
217
+ dispatch({
218
+ type: 'insert',
219
+ payload: {
220
+ text: e.dataTransfer.getData('text/plain')
221
+ },
222
+ selection: selection,
223
+ batch: true
224
+ });
225
+ dispatch({
226
+ type: 'batch'
227
+ });
228
+ } else if ((_e$dataTransfer2 = e.dataTransfer) !== null && _e$dataTransfer2 !== void 0 && _e$dataTransfer2.types.includes('Files')) {
229
+ var _file = e.dataTransfer.files[0];
230
+ onInsertFile === null || onInsertFile === void 0 ? void 0 : onInsertFile(_file, {
231
+ description: _file.name,
232
+ image: _file.type.startsWith('image/')
233
+ });
234
+ }
235
+ break;
236
+ }
237
+ case 'insertLineBreak':
238
+ case 'insertParagraph':
239
+ {
240
+ e.preventDefault();
241
+ dispatch({
242
+ type: 'insert',
243
+ payload: {
244
+ text: '\n'
245
+ },
246
+ selection: selection
247
+ });
248
+ break;
249
+ }
250
+ case 'insertCompositionText':
251
+ case 'insertFromComposition':
252
+ {
253
+ // 避免 DOM 更新扰乱组合
254
+ ignoreNext.current = true;
255
+ if (e.data !== null) {
256
+ dispatch({
257
+ type: 'insert',
258
+ payload: {
259
+ text: e.data
260
+ },
261
+ selection: selection,
262
+ batch: true
263
+ });
264
+ }
265
+ break;
266
+ }
267
+ case 'deleteWordBackward':
268
+ case 'deleteWordForward':
269
+ case 'deleteContentBackward':
270
+ case 'deleteContentForward':
271
+ {
272
+ e.preventDefault();
273
+ if (startOffset < endOffset) {
274
+ dispatch({
275
+ type: 'insert',
276
+ payload: {
277
+ text: ''
278
+ },
279
+ selection: selection
280
+ });
281
+ } else if (e.inputType.endsWith('Backward')) {
282
+ if (startOffset) {
283
+ dispatch({
284
+ type: 'insert',
285
+ payload: {
286
+ text: ''
287
+ },
288
+ selection: createSelection(startOffset - 1, endOffset)
289
+ });
290
+ }
291
+ } else {
292
+ if (endOffset < sourceCodeLatest.current.length) {
293
+ dispatch({
294
+ type: 'insert',
295
+ payload: {
296
+ text: ''
297
+ },
298
+ selection: createSelection(startOffset, endOffset + 1)
299
+ });
300
+ }
301
+ }
302
+ break;
303
+ }
304
+ case 'deleteByDrag':
305
+ case 'deleteCompositionText':
306
+ {
307
+ ignoreNext.current = true;
308
+ dispatch({
309
+ type: 'insert',
310
+ payload: {
311
+ text: ''
312
+ },
313
+ selection: selection,
314
+ batch: true
315
+ });
316
+ break;
317
+ }
318
+ case 'formatBold':
319
+ {
320
+ e.preventDefault();
321
+ dispatch({
322
+ type: 'toggle',
323
+ payload: {
324
+ type: 'strong'
325
+ },
326
+ selection: selection
327
+ });
328
+ break;
329
+ }
330
+ case 'formatItalic':
331
+ {
332
+ e.preventDefault();
333
+ dispatch({
334
+ type: 'toggle',
335
+ payload: {
336
+ type: 'emphasis'
337
+ },
338
+ selection: selection
339
+ });
340
+ break;
341
+ }
342
+ default:
343
+ {
344
+ e.preventDefault();
345
+ break;
346
+ }
347
+ }
348
+ };
349
+ (_containerRef$current = containerRef.current) === null || _containerRef$current === void 0 ? void 0 : _containerRef$current.addEventListener('beforeinput', listener);
350
+ return function () {
351
+ var _containerRef$current2;
352
+ return (_containerRef$current2 = containerRef.current) === null || _containerRef$current2 === void 0 ? void 0 : _containerRef$current2.removeEventListener('beforeinput', listener);
353
+ };
354
+ }, []);
268
355
  return /*#__PURE__*/React.createElement(LocaleProvider, {
269
356
  locale: locale
270
357
  }, /*#__PURE__*/React.createElement(Toolbar, {
@@ -280,15 +367,12 @@ var XStarMdEditor = /*#__PURE__*/React.forwardRef(function (_ref, ref) {
280
367
  height: height
281
368
  }),
282
369
  contentEditable: true,
283
- onBeforeInput: formEventHandler,
284
370
  onBlur: focusEventHandler,
285
371
  onCompositionEnd: compositionEventHandler,
286
- onCompositionStart: compositionEventHandler,
287
372
  onCopy: clipboardEventHandler,
288
373
  onCut: clipboardEventHandler,
289
- onDrop: dragEventHandler,
290
- onKeyDown: keyboardEventHandler,
291
- onPaste: clipboardEventHandler
374
+ onDragStart: dragEventHandler,
375
+ onKeyDown: keyboardEventHandler
292
376
  }));
293
377
  });
294
378
  if (process.env.NODE_ENV !== 'production') {
@@ -36,6 +36,10 @@ export interface XStarMdViewerProps {
36
36
  * 查看器的高度
37
37
  */
38
38
  height?: React.CSSProperties['height'];
39
+ /**
40
+ * 内置主题
41
+ */
42
+ theme?: string;
39
43
  /**
40
44
  * 文本
41
45
  */
@@ -1,4 +1,5 @@
1
1
  import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
2
+ import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
2
3
  import _regeneratorRuntime from "@babel/runtime/helpers/esm/regeneratorRuntime";
3
4
  import _asyncToGenerator from "@babel/runtime/helpers/esm/asyncToGenerator";
4
5
  import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
@@ -9,13 +10,11 @@ var workerRaw = "(()=>{var e={470:e=>{\"use strict\";var t=Object.prototype.hasO
9
10
  import { prefix } from "../utils/global";
10
11
  import { composeHandlers } from "../utils/handler";
11
12
  import { getDefaultSchema, postViewerRender, preViewerRender, viewerRender } from "../utils/markdown";
12
- var workerURL = URL.createObjectURL(new Blob([workerRaw], {
13
- type: 'text/javascript'
14
- }));
15
13
  var XStarMdViewer = /*#__PURE__*/React.forwardRef(function (_ref, ref) {
16
14
  var className = _ref.className,
17
15
  style = _ref.style,
18
16
  height = _ref.height,
17
+ theme = _ref.theme,
19
18
  _ref$value = _ref.value,
20
19
  value = _ref$value === void 0 ? '' : _ref$value,
21
20
  plugins = _ref.plugins,
@@ -44,7 +43,9 @@ var XStarMdViewer = /*#__PURE__*/React.forwardRef(function (_ref, ref) {
44
43
  var worker = useRef();
45
44
  useEffect(function () {
46
45
  if (enableWebWorker) {
47
- worker.current = new Worker(workerURL);
46
+ worker.current = new Worker(URL.createObjectURL(new Blob([workerRaw], {
47
+ type: 'text/javascript'
48
+ })));
48
49
  worker.current.addEventListener('message', function (_ref2) {
49
50
  var data = _ref2.data;
50
51
  return setChildren(postViewerRender(data, optionsLatest.current));
@@ -79,7 +80,7 @@ var XStarMdViewer = /*#__PURE__*/React.forwardRef(function (_ref, ref) {
79
80
  }, [value, options]);
80
81
  return /*#__PURE__*/React.createElement("div", {
81
82
  ref: containerRef,
82
- className: classNames("".concat(prefix, "md-viewer"), className),
83
+ className: classNames("".concat(prefix, "md-viewer"), _defineProperty({}, "".concat(prefix, "theme-").concat(theme), theme), className),
83
84
  style: _objectSpread(_objectSpread({}, style), {}, {
84
85
  height: height
85
86
  })
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "x-star-editor",
3
- "version": "0.2.6",
3
+ "version": "0.3.1",
4
4
  "description": "An editor developed by turingstar",
5
5
  "license": "MIT",
6
6
  "module": "dist/index.js",