md-editor-lite 0.1.4 → 0.1.6

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/index.js CHANGED
@@ -1,4 +1,3 @@
1
- "use strict";
2
1
  var __create = Object.create;
3
2
  var __defProp = Object.defineProperty;
4
3
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
@@ -28,8 +27,8 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
28
27
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
28
 
30
29
  // src/index.ts
31
- var index_exports = {};
32
- __export(index_exports, {
30
+ var src_exports = {};
31
+ __export(src_exports, {
33
32
  EditorHeader: () => EditorHeader,
34
33
  EditorTab: () => EditorTab,
35
34
  EditorTextarea: () => EditorTextarea,
@@ -45,47 +44,41 @@ __export(index_exports, {
45
44
  markdownToHtml: () => markdownToHtml,
46
45
  useMarkdownEditor: () => useMarkdownEditor
47
46
  });
48
- module.exports = __toCommonJS(index_exports);
47
+ module.exports = __toCommonJS(src_exports);
49
48
 
50
49
  // src/components/EditorHeader.tsx
51
- var import_jsx_runtime = require("react/jsx-runtime");
50
+ var import_editor = require("./editor-AUU3A4EA.css");
52
51
  function EditorHeader({
53
52
  mode,
54
53
  setMode,
55
54
  insertMarkdown
56
55
  }) {
57
- return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("header", { className: "editor-header", children: [
58
- /* @__PURE__ */ (0, import_jsx_runtime.jsx)(EditorTab, { mode, setMode }),
59
- mode === "write" && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Toolbar, { insertMarkdown })
60
- ] });
56
+ return /* @__PURE__ */ React.createElement("header", { className: "editor-header" }, /* @__PURE__ */ React.createElement(EditorTab, { mode, setMode }), mode === "write" && /* @__PURE__ */ React.createElement(Toolbar, { insertMarkdown }));
61
57
  }
62
58
 
63
59
  // src/components/EditorTab.tsx
64
- var import_jsx_runtime2 = require("react/jsx-runtime");
60
+ var import_editor2 = require("./editor-AUU3A4EA.css");
65
61
  function EditorTab({ mode, setMode }) {
66
- return /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("div", { className: "editor-tab-container", children: [
67
- /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
68
- "div",
69
- {
70
- className: `editor-tab ${mode === "write" ? "editor-tab--active" : ""}`,
71
- onClick: () => setMode("write"),
72
- children: "Write"
73
- }
74
- ),
75
- /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
76
- "div",
77
- {
78
- className: `editor-tab ${mode === "preview" ? "editor-tab--active" : ""}`,
79
- onClick: () => setMode("preview"),
80
- children: "Preview"
81
- }
82
- )
83
- ] });
62
+ return /* @__PURE__ */ React.createElement("div", { className: "editor-tab-container" }, /* @__PURE__ */ React.createElement(
63
+ "div",
64
+ {
65
+ className: `editor-tab ${mode === "write" ? "editor-tab--active" : ""}`,
66
+ onClick: () => setMode("write")
67
+ },
68
+ "Write"
69
+ ), /* @__PURE__ */ React.createElement(
70
+ "div",
71
+ {
72
+ className: `editor-tab ${mode === "preview" ? "editor-tab--active" : ""}`,
73
+ onClick: () => setMode("preview")
74
+ },
75
+ "Preview"
76
+ ));
84
77
  }
85
78
 
86
79
  // src/components/EditorTextarea.tsx
87
80
  var import_react = require("react");
88
- var import_jsx_runtime3 = require("react/jsx-runtime");
81
+ var import_editor3 = require("./editor-AUU3A4EA.css");
89
82
  var EditorTextarea = (0, import_react.forwardRef)(({ value, placeholder, setValue, onImageUpload }, ref) => {
90
83
  const handleDrop = async (e) => {
91
84
  e.preventDefault();
@@ -100,7 +93,7 @@ var EditorTextarea = (0, import_react.forwardRef)(({ value, placeholder, setValu
100
93
  `);
101
94
  }
102
95
  };
103
- return /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
96
+ return /* @__PURE__ */ React.createElement(
104
97
  "textarea",
105
98
  {
106
99
  ref,
@@ -147,7 +140,7 @@ function useMarkdownEditor({ value, setValue }) {
147
140
  }
148
141
 
149
142
  // src/components/MarkdownEditor.tsx
150
- var import_jsx_runtime4 = require("react/jsx-runtime");
143
+ var import_editor4 = require("./editor-AUU3A4EA.css");
151
144
  function MarkdownEditor({
152
145
  value,
153
146
  onChange: setValue,
@@ -158,25 +151,22 @@ function MarkdownEditor({
158
151
  setValue
159
152
  });
160
153
  const [mode, setMode] = (0, import_react3.useState)("write");
161
- return /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("div", { className: "editor", children: [
162
- /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
163
- EditorHeader,
164
- {
165
- mode,
166
- setMode,
167
- insertMarkdown
168
- }
169
- ),
170
- mode === "write" ? /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
171
- EditorTextarea,
172
- {
173
- ref: textareaRef,
174
- value,
175
- setValue,
176
- onImageUpload
177
- }
178
- ) : /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(Preview, { value })
179
- ] });
154
+ return /* @__PURE__ */ React.createElement("div", { className: "editor" }, /* @__PURE__ */ React.createElement(
155
+ EditorHeader,
156
+ {
157
+ mode,
158
+ setMode,
159
+ insertMarkdown
160
+ }
161
+ ), mode === "write" ? /* @__PURE__ */ React.createElement(
162
+ EditorTextarea,
163
+ {
164
+ ref: textareaRef,
165
+ value,
166
+ setValue,
167
+ onImageUpload
168
+ }
169
+ ) : /* @__PURE__ */ React.createElement(Preview, { value }));
180
170
  }
181
171
 
182
172
  // src/utils/markdown.ts
@@ -184,7 +174,7 @@ function parseBold(text) {
184
174
  return text.replace(/\*\*(.+?)\*\*/g, "<strong>$1</strong>");
185
175
  }
186
176
  function parseItalic(text) {
187
- return text.replace(/\*(.+?)\*/g, "<em>$1</em>");
177
+ return text.replace(/(?<!\*)\*(?!\*)(.+?)(?<!\*)\*(?!\*)/g, "<em>$1</em>");
188
178
  }
189
179
  function parseInlineCode(text) {
190
180
  return text.replace(/`(.+?)`/g, "<code>$1</code>");
@@ -192,6 +182,15 @@ function parseInlineCode(text) {
192
182
  function parseBlockquote(text) {
193
183
  return text.replace(/^> (.+)$/gm, "<blockquote>$1</blockquote>");
194
184
  }
185
+ function parseStrikethrough(text) {
186
+ return text.replace(/~~(.+?)~~/g, "<del>$1</del>");
187
+ }
188
+ function parseUnderline(text) {
189
+ return text.replace(/__(.+?)__/g, "<u>$1</u>");
190
+ }
191
+ function parseHr(text) {
192
+ return text.replace(/^---$/gm, "<hr />");
193
+ }
195
194
  function parseImages(text) {
196
195
  return text.replace(
197
196
  /!\[(.*?)\]\(([^)]*?)\)/g,
@@ -230,23 +229,26 @@ function parseLineBreaks(text) {
230
229
  }
231
230
  function markdownToHtml(markdown) {
232
231
  let html = markdown;
232
+ html = parseHr(html);
233
+ html = parseHeadings(html);
234
+ html = parseBlockquote(html);
235
+ html = parseUnorderedList(html);
236
+ html = parseOrderedList(html);
233
237
  html = parseBold(html);
238
+ html = parseUnderline(html);
239
+ html = parseStrikethrough(html);
234
240
  html = parseItalic(html);
235
241
  html = parseInlineCode(html);
236
- html = parseBlockquote(html);
237
242
  html = parseImages(html);
238
243
  html = parseLinks(html);
239
- html = parseHeadings(html);
240
- html = parseUnorderedList(html);
241
- html = parseOrderedList(html);
242
244
  html = parseLineBreaks(html);
243
245
  return html;
244
246
  }
245
247
 
246
248
  // src/components/Preview.tsx
247
- var import_jsx_runtime5 = require("react/jsx-runtime");
249
+ var import_preview = require("./preview-FACEHC73.css");
248
250
  function Preview({ value }) {
249
- return /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
251
+ return /* @__PURE__ */ React.createElement(
250
252
  "div",
251
253
  {
252
254
  className: "preview",
@@ -263,6 +265,9 @@ var TOOLBAR_BUTTONS = [
263
265
  { key: "italic", before: "*", after: "*", Icon: import_lucide_react.ItalicIcon },
264
266
  { key: "code", before: "`", after: "`", Icon: import_lucide_react.CodeIcon },
265
267
  { key: "blockquote", before: "> ", after: "", Icon: import_lucide_react.QuoteIcon },
268
+ { key: "strikethrough", before: "~~", after: "~~", Icon: import_lucide_react.StrikethroughIcon },
269
+ { key: "underline", before: "__", after: "__", Icon: import_lucide_react.UnderlineIcon },
270
+ { key: "horizontal rule", before: "\n---\n", after: "", Icon: import_lucide_react.ListEndIcon },
266
271
  { key: "link", before: "[", after: "]()", Icon: import_lucide_react.LinkIcon }
267
272
  ];
268
273
  var headingOptions = [
@@ -276,21 +281,17 @@ var listOptions = [
276
281
  ];
277
282
 
278
283
  // src/components/Toolbar.tsx
279
- var import_jsx_runtime6 = require("react/jsx-runtime");
284
+ var import_toolbar2 = require("./toolbar-YQKH6EMS.css");
280
285
  function Toolbar({ insertMarkdown }) {
281
- return /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)("menu", { className: "toolbar-menu", children: [
282
- TOOLBAR_BUTTONS.map(({ key, before, after, Icon }) => /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(
283
- "button",
284
- {
285
- className: "toolbar-button",
286
- onClick: () => insertMarkdown(before, after),
287
- children: /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(Icon, { size: 18 })
288
- },
289
- key
290
- )),
291
- /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(ToolbarDropdownHeading, { insertMarkdown }),
292
- /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(ToolbarDropdownList, { insertMarkdown })
293
- ] });
286
+ return /* @__PURE__ */ React.createElement("menu", { className: "toolbar-menu" }, TOOLBAR_BUTTONS.map(({ key, before, after, Icon }) => /* @__PURE__ */ React.createElement(
287
+ "button",
288
+ {
289
+ key,
290
+ className: "toolbar-button",
291
+ onClick: () => insertMarkdown(before, after)
292
+ },
293
+ /* @__PURE__ */ React.createElement(Icon, { size: 18 })
294
+ )), /* @__PURE__ */ React.createElement(ToolbarDropdownHeading, { insertMarkdown }), /* @__PURE__ */ React.createElement(ToolbarDropdownList, { insertMarkdown }));
294
295
  }
295
296
 
296
297
  // src/components/IconDropdown.tsx
@@ -302,7 +303,7 @@ function cx(...classes) {
302
303
  }
303
304
 
304
305
  // src/components/IconDropdown.tsx
305
- var import_jsx_runtime7 = require("react/jsx-runtime");
306
+ var import_dropdown = require("./dropdown-JYZ5KVXG.css");
306
307
  function IconDropdown({
307
308
  className,
308
309
  disabled,
@@ -325,52 +326,46 @@ function IconDropdown({
325
326
  document.addEventListener("mousedown", handleClickOutside);
326
327
  return () => document.removeEventListener("mousedown", handleClickOutside);
327
328
  }, []);
328
- return /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)("div", { ref: dropdownRef, className: cx("md-dropdown", className), children: [
329
- /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(
330
- "button",
331
- {
332
- type: "button",
333
- onClick: toggle,
334
- disabled,
335
- className: cx(
336
- "md-dropdown__trigger",
337
- disabled && "md-dropdown__trigger--disabled"
338
- ),
339
- children: triggerIcon
329
+ return /* @__PURE__ */ import_react4.default.createElement("div", { ref: dropdownRef, className: cx("md-dropdown", className) }, /* @__PURE__ */ import_react4.default.createElement(
330
+ "button",
331
+ {
332
+ type: "button",
333
+ onClick: toggle,
334
+ disabled,
335
+ className: cx(
336
+ "md-dropdown__trigger",
337
+ disabled && "md-dropdown__trigger--disabled"
338
+ )
339
+ },
340
+ triggerIcon
341
+ ), isOpen && /* @__PURE__ */ import_react4.default.createElement("ul", { className: "md-dropdown__menu" }, options.map((option) => /* @__PURE__ */ import_react4.default.createElement(
342
+ "li",
343
+ {
344
+ key: option.value,
345
+ className: cx(
346
+ "md-dropdown__item",
347
+ selected && "md-dropdown__item--selected"
348
+ ),
349
+ onClick: () => {
350
+ onChange(option.value);
351
+ setIsOpen(false);
340
352
  }
341
- ),
342
- isOpen && /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("ul", { className: "md-dropdown__menu", children: options.map((option) => /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)(
343
- "li",
344
- {
345
- className: cx(
346
- "md-dropdown__item",
347
- selected && "md-dropdown__item--selected"
348
- ),
349
- onClick: () => {
350
- onChange(option.value);
351
- setIsOpen(false);
352
- },
353
- children: [
354
- option.Icon && /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("span", { className: "md-dropdown__icon", children: /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(option.Icon, {}) }),
355
- option.label && /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("span", { className: "md-dropdown__label", children: option.label })
356
- ]
357
- },
358
- option.value
359
- )) })
360
- ] });
353
+ },
354
+ option.Icon && /* @__PURE__ */ import_react4.default.createElement("span", { className: "md-dropdown__icon" }, /* @__PURE__ */ import_react4.default.createElement(option.Icon, null)),
355
+ option.label && /* @__PURE__ */ import_react4.default.createElement("span", { className: "md-dropdown__label" }, option.label)
356
+ ))));
361
357
  }
362
358
 
363
359
  // src/components/ToolbarDropdown.tsx
364
360
  var import_lucide_react2 = require("lucide-react");
365
- var import_jsx_runtime8 = require("react/jsx-runtime");
366
361
  function ToolbarDropdownHeading({
367
362
  insertMarkdown
368
363
  }) {
369
- return /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(
364
+ return /* @__PURE__ */ React.createElement(
370
365
  IconDropdown,
371
366
  {
372
367
  options: headingOptions,
373
- triggerIcon: /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(import_lucide_react2.Heading1Icon, {}),
368
+ triggerIcon: /* @__PURE__ */ React.createElement(import_lucide_react2.Heading1Icon, null),
374
369
  onChange: (value) => {
375
370
  const option = headingOptions.find((o) => o.value === value);
376
371
  if (option) insertMarkdown(option.before);
@@ -379,11 +374,11 @@ function ToolbarDropdownHeading({
379
374
  );
380
375
  }
381
376
  function ToolbarDropdownList({ insertMarkdown }) {
382
- return /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(
377
+ return /* @__PURE__ */ React.createElement(
383
378
  IconDropdown,
384
379
  {
385
380
  options: listOptions,
386
- triggerIcon: /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(import_lucide_react2.ListIcon, {}),
381
+ triggerIcon: /* @__PURE__ */ React.createElement(import_lucide_react2.ListIcon, null),
387
382
  onChange: (value) => {
388
383
  const option = listOptions.find((o) => o.value === value);
389
384
  if (option) insertMarkdown(option.before);