@elia-ori/editor 0.1.24 → 0.1.26

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/README.md CHANGED
@@ -45,12 +45,34 @@ function MyEditor() {
45
45
  }
46
46
  ```
47
47
 
48
+ ### 儲存格式
49
+
50
+ 編輯器支援 HTML 和 JSON 兩種格式:
51
+
52
+ ```tsx
53
+ // 儲存為 JSON 格式(推薦)
54
+ <EliaEditor
55
+ content={content}
56
+ onChange={(html, json) => {
57
+ setContent(json) // 儲存 JSON,支援多平台渲染
58
+ }}
59
+ />
60
+
61
+ // 儲存為 HTML 格式(向後相容)
62
+ <EliaEditor
63
+ content={content}
64
+ onChange={(html) => {
65
+ setContent(html) // 只用第一個參數
66
+ }}
67
+ />
68
+ ```
69
+
48
70
  ## Props
49
71
 
50
72
  | Prop | 類型 | 預設值 | 說明 |
51
73
  |------|------|--------|------|
52
74
  | `content` | `string` | `''` | HTML 內容 |
53
- | `onChange` | `(html: string) => void` | - | 內容變更回調 |
75
+ | `onChange` | `(html: string, json: JSONContent) => void` | - | 內容變更時的回調,同時提供 HTML 和 JSON 格式 |
54
76
  | `placeholder` | `string` | `'開始寫作...'` | 佔位文字 |
55
77
  | `toolbar` | `ToolbarItem[]` | 全部 | 工具列項目 |
56
78
  | `onImageUpload` | `UploadFunction` | - | **必要** - 圖片上傳函數 |
package/dist/index.cjs CHANGED
@@ -32,7 +32,9 @@ var index_exports = {};
32
32
  __export(index_exports, {
33
33
  Callout: () => Callout,
34
34
  EliaEditor: () => EliaEditor,
35
- SimpleEditor: () => EliaEditor
35
+ SimpleEditor: () => EliaEditor,
36
+ contentExtensions: () => contentExtensions,
37
+ generateEditorHTML: () => generateEditorHTML
36
38
  });
37
39
  module.exports = __toCommonJS(index_exports);
38
40
 
@@ -6210,7 +6212,7 @@ function EliaEditor({
6210
6212
  const handleUpdate = (0, import_react86.useCallback)(
6211
6213
  ({ editor: editor2 }) => {
6212
6214
  isInternalUpdate.current = true;
6213
- onChange?.(editor2.getHTML());
6215
+ onChange?.(editor2.getHTML(), editor2.getJSON());
6214
6216
  },
6215
6217
  [onChange]
6216
6218
  );
@@ -6341,10 +6343,53 @@ function EliaEditor({
6341
6343
  }
6342
6344
  );
6343
6345
  }
6346
+
6347
+ // src/utils/content-renderer.ts
6348
+ var import_core2 = require("@tiptap/core");
6349
+ var import_starter_kit2 = __toESM(require("@tiptap/starter-kit"), 1);
6350
+ var import_extension_text_align2 = require("@tiptap/extension-text-align");
6351
+ var import_extension_list2 = require("@tiptap/extension-list");
6352
+ var import_extension_highlight2 = require("@tiptap/extension-highlight");
6353
+ var import_extension_typography2 = require("@tiptap/extension-typography");
6354
+ var import_extension_superscript2 = require("@tiptap/extension-superscript");
6355
+ var import_extension_subscript2 = require("@tiptap/extension-subscript");
6356
+ var import_extension_text_style2 = require("@tiptap/extension-text-style");
6357
+ var import_extension_color2 = require("@tiptap/extension-color");
6358
+ var import_extension_table2 = require("@tiptap/extension-table");
6359
+ var import_extension_table_row2 = require("@tiptap/extension-table-row");
6360
+ var import_extension_table_header2 = require("@tiptap/extension-table-header");
6361
+ var import_extension_table_cell2 = require("@tiptap/extension-table-cell");
6362
+ var import_tiptap_extension_resize_image2 = __toESM(require("tiptap-extension-resize-image"), 1);
6363
+ var contentExtensions = [
6364
+ import_starter_kit2.default.configure({
6365
+ horizontalRule: false
6366
+ }),
6367
+ HorizontalRule,
6368
+ import_extension_text_align2.TextAlign.configure({ types: ["heading", "paragraph"] }),
6369
+ import_extension_list2.TaskList,
6370
+ import_extension_list2.TaskItem.configure({ nested: true }),
6371
+ import_extension_highlight2.Highlight.configure({ multicolor: true }),
6372
+ import_extension_typography2.Typography,
6373
+ import_extension_superscript2.Superscript,
6374
+ import_extension_subscript2.Subscript,
6375
+ import_extension_text_style2.TextStyle,
6376
+ import_extension_color2.Color,
6377
+ import_extension_table2.Table.configure({ resizable: true }),
6378
+ import_extension_table_row2.TableRow,
6379
+ import_extension_table_header2.TableHeader,
6380
+ import_extension_table_cell2.TableCell,
6381
+ import_tiptap_extension_resize_image2.default.configure({ allowBase64: true }),
6382
+ Callout
6383
+ ];
6384
+ function generateEditorHTML(content) {
6385
+ return (0, import_core2.generateHTML)(content, contentExtensions);
6386
+ }
6344
6387
  // Annotate the CommonJS export names for ESM import in node:
6345
6388
  0 && (module.exports = {
6346
6389
  Callout,
6347
6390
  EliaEditor,
6348
- SimpleEditor
6391
+ SimpleEditor,
6392
+ contentExtensions,
6393
+ generateEditorHTML
6349
6394
  });
6350
6395
  //# sourceMappingURL=index.cjs.map