@elia-ori/editor 0.1.24 → 0.1.25

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
@@ -6210,7 +6210,7 @@ function EliaEditor({
6210
6210
  const handleUpdate = (0, import_react86.useCallback)(
6211
6211
  ({ editor: editor2 }) => {
6212
6212
  isInternalUpdate.current = true;
6213
- onChange?.(editor2.getHTML());
6213
+ onChange?.(editor2.getHTML(), editor2.getJSON());
6214
6214
  },
6215
6215
  [onChange]
6216
6216
  );