@burger-editor/client 4.0.0-alpha.7 → 4.0.0-alpha.70

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
@@ -1,3 +1,303 @@
1
- # core
1
+ # @burger-editor/client
2
2
 
3
- [![npm version](https://badge.fury.io/js/@burger-editor%2Fcore.svg)](https://badge.fury.io/js/@burger-editor%2Fcore)
3
+ [![npm version](https://badge.fury.io/js/@burger-editor%2Fclient.svg)](https://badge.fury.io/js/@burger-editor%2Fclient)
4
+
5
+ BurgerEditorのクライアント側UIパッケージです。Svelteベースのコンポーネントを提供し、既存のCMSやWebアプリケーションにBurgerEditorを統合できます。
6
+
7
+ ## インストール
8
+
9
+ ```bash
10
+ yarn add @burger-editor/client @burger-editor/core @burger-editor/blocks
11
+ ```
12
+
13
+ または
14
+
15
+ ```bash
16
+ npm install @burger-editor/client @burger-editor/core @burger-editor/blocks
17
+ ```
18
+
19
+ ## 公開API
20
+
21
+ ### `createBurgerEditorClient(options)`
22
+
23
+ BurgerEditorのクライアントインスタンスを作成します。この関数は、すべてのUI要素(ブロックカタログ、ブロックオプション、ファイルリストなど)を自動的にセットアップします。
24
+
25
+ #### 型定義
26
+
27
+ ```typescript
28
+ function createBurgerEditorClient(
29
+ options: Omit<BurgerEditorEngineOptions, 'ui' | 'blockMenu'>,
30
+ ): Promise<{
31
+ engine: BurgerEditorEngine;
32
+ }>;
33
+ ```
34
+
35
+ #### パラメータ
36
+
37
+ `options` は `BurgerEditorEngineOptions` から `ui` と `blockMenu` を除いたオプションです。client は内部で `ui`, `blockMenu`, `initialInsertionButton`, `defineCustomElement` を Svelte 実装で上書きするため、これらを手動で指定する必要はありません。以下の主要なプロパティがあります:
38
+
39
+ **必須プロパティ:**
40
+
41
+ - `root` (string): エディタをマウントするルート要素のセレクタ
42
+ - `config` (Config): エディタの設定
43
+ - `classList`: ブロックに適用するCSSクラスの配列
44
+ - `stylesheets`: 読み込むスタイルシートのパス配列
45
+ - `sampleImagePath`: サンプル画像のパス
46
+ - `sampleFilePath`: サンプルファイルのパス
47
+ - `googleMapsApiKey`: Google Maps APIキー (使用する場合)
48
+ - `experimental`: 実験的な機能の設定 (オプション)
49
+ - `items` (Record<string, ItemSeed>): 使用するアイテムの定義
50
+ - `catalog` (BlockCatalog): ブロックカタログの定義
51
+ - `generalCSS` (string): 一般的なCSS文字列
52
+ - `initialContents` (string | { main: string; draft?: string }): 初期コンテンツのHTML
53
+
54
+ **オプショナルプロパティ:**
55
+
56
+ - `viewAreaClassList`: ビューエリアに適用するCSSクラスの配列
57
+ - `blocks`: カスタムブロック定義
58
+ - `storageKey`: ローカルストレージのキー設定
59
+ - `defineCustomElement`: カスタム要素の定義関数
60
+ - `onUpdated`: コンテンツ更新時のコールバック
61
+ - `fileIO`: ファイルIO APIの実装
62
+ - `healthCheck`: ヘルスチェックの設定
63
+
64
+ #### 戻り値
65
+
66
+ ```typescript
67
+ Promise<{
68
+ engine: BurgerEditorEngine;
69
+ }>;
70
+ ```
71
+
72
+ - `engine`: BurgerEditorエンジンのインスタンス
73
+
74
+ ### `version`
75
+
76
+ パッケージのバージョン文字列定数です。
77
+
78
+ ### `attachDraftSwitcher(engine)`
79
+
80
+ 下書き切り替えUIを手動でアタッチする関数です。`engine.hasDraft()` が `true` の場合にのみ UI を生成します。
81
+
82
+ ```typescript
83
+ import { attachDraftSwitcher } from '@burger-editor/client';
84
+
85
+ attachDraftSwitcher(engine);
86
+ ```
87
+
88
+ ### `Migrator`
89
+
90
+ `@burger-editor/migrator` パッケージからの re-export です。
91
+
92
+ ### `getConfig()` (非推奨)
93
+
94
+ > **⚠️ @deprecated**: この関数は非推奨です。各プラットフォームで Config の型が異なるため、直接使用しないでください。
95
+
96
+ ## 使用例
97
+
98
+ 以下は基本的な使用例です:
99
+
100
+ ```typescript
101
+ import { createBurgerEditorClient } from '@burger-editor/client';
102
+ import { items, generalCSS, defaultCatalog } from '@burger-editor/blocks';
103
+ import { CSS_LAYER } from '@burger-editor/core';
104
+ import '@burger-editor/client/style';
105
+
106
+ async function initEditor() {
107
+ // エディタをマウントする要素を取得
108
+ const mainInput = document.getElementById('main') as HTMLInputElement;
109
+
110
+ if (!mainInput) {
111
+ console.error('Editable area not found');
112
+ return;
113
+ }
114
+
115
+ // エディタを作成
116
+ const { engine } = await createBurgerEditorClient({
117
+ root: '.editor',
118
+ config: {
119
+ classList: [],
120
+ stylesheets: [
121
+ {
122
+ path: '/path/to/your/styles.css',
123
+ layer: CSS_LAYER.ui,
124
+ },
125
+ {
126
+ path: generalCSS,
127
+ layer: CSS_LAYER.base,
128
+ },
129
+ ],
130
+ sampleImagePath: '/images/sample.jpg',
131
+ sampleFilePath: '/files/sample.pdf',
132
+ googleMapsApiKey: null,
133
+ },
134
+ items,
135
+ catalog: defaultCatalog,
136
+ generalCSS,
137
+ initialContents: mainInput.value,
138
+ viewAreaClassList: ['my-editor'],
139
+ onUpdated: async (main, draft) => {
140
+ // コンテンツが更新されたときの処理
141
+ mainInput.value = main;
142
+ console.log('Content updated:', { main, draft });
143
+ },
144
+ });
145
+
146
+ console.log('Editor initialized:', engine);
147
+ }
148
+
149
+ // 初期化実行
150
+ initEditor();
151
+ ```
152
+
153
+ ### カスタムブロックカタログの使用
154
+
155
+ ```typescript
156
+ import { createBurgerEditorClient } from '@burger-editor/client';
157
+ import { items, generalCSS, defaultCatalog } from '@burger-editor/blocks';
158
+
159
+ const customCatalog = {
160
+ ...defaultCatalog,
161
+ カスタムカテゴリ: [
162
+ {
163
+ label: 'カスタムブロック',
164
+ definition: {
165
+ name: 'custom-block',
166
+ containerProps: {
167
+ type: 'grid',
168
+ columns: 2,
169
+ },
170
+ items: [['wysiwyg', 'image']],
171
+ },
172
+ },
173
+ ],
174
+ };
175
+
176
+ await createBurgerEditorClient({
177
+ root: '.editor',
178
+ config: {
179
+ classList: [],
180
+ stylesheets: [],
181
+ sampleImagePath: '/images/sample.jpg',
182
+ sampleFilePath: '/files/sample.pdf',
183
+ googleMapsApiKey: null,
184
+ },
185
+ items,
186
+ catalog: customCatalog,
187
+ generalCSS,
188
+ initialContents: '<div class="editable"></div>',
189
+ });
190
+ ```
191
+
192
+ ### ファイルIOの実装
193
+
194
+ ```typescript
195
+ import { createBurgerEditorClient } from '@burger-editor/client';
196
+ import type { FileAPI } from '@burger-editor/core';
197
+
198
+ const fileIO: FileAPI = {
199
+ async getFileList(fileType, options) {
200
+ // ファイルリストを取得する実装
201
+ const response = await fetch(`/api/files/${fileType}?page=${options.page}`);
202
+ return response.json();
203
+ },
204
+ async postFile(fileType, file, progress) {
205
+ // ファイルをアップロードする実装
206
+ const formData = new FormData();
207
+ formData.append('file', file);
208
+
209
+ const response = await fetch(`/api/files/${fileType}`, {
210
+ method: 'POST',
211
+ body: formData,
212
+ });
213
+
214
+ return response.json();
215
+ },
216
+ async deleteFile(fileType, url) {
217
+ // ファイルを削除する実装
218
+ const response = await fetch(`/api/files/${fileType}`, {
219
+ method: 'DELETE',
220
+ body: JSON.stringify({ url }),
221
+ });
222
+
223
+ return response.json();
224
+ },
225
+ };
226
+
227
+ await createBurgerEditorClient({
228
+ root: '.editor',
229
+ config: {
230
+ classList: [],
231
+ stylesheets: [],
232
+ sampleImagePath: '/images/sample.jpg',
233
+ sampleFilePath: '/files/sample.pdf',
234
+ googleMapsApiKey: null,
235
+ },
236
+ items,
237
+ catalog: defaultCatalog,
238
+ generalCSS,
239
+ initialContents: '<div class="editable"></div>',
240
+ fileIO,
241
+ });
242
+ ```
243
+
244
+ ## ブロックのコピー&ペースト
245
+
246
+ BurgerEditorは、ブロック単位でのコピー&ペースト機能を提供します。
247
+
248
+ ### 使用方法
249
+
250
+ 1. **ブロックのコピー**
251
+ - コピーしたいブロックを選択
252
+ - ブロックメニューから「ブロックをコピー」をクリック
253
+ - ブロックのデータがクリップボード(sessionStorage)に保存されます
254
+
255
+ 2. **ブロックのペースト**
256
+ - ブロック追加ダイアログを開く
257
+ - クリップボードにデータがある場合、「クリップボードから貼り付け」ボタンが表示されます
258
+ - ボタンをクリックすると、コピーしたブロックが挿入されます
259
+
260
+ ### 仕様
261
+
262
+ - **保存形式**: JSON形式(BlockData)
263
+ - **保存先**: sessionStorage
264
+ - **有効期限**: ブラウザセッション内のみ(タブを閉じると消去)
265
+ - **保存キー**: `engine.storageKey.blockClipboard`(デフォルト: `'bge-copied-block'`)
266
+ - **動作**: ペースト後、クリップボードは自動的にクリアされます
267
+
268
+ ### ストレージキーのカスタマイズ
269
+
270
+ ```typescript
271
+ await createBurgerEditorClient({
272
+ root: '.editor',
273
+ config: {
274
+ classList: [],
275
+ stylesheets: [],
276
+ sampleImagePath: '/images/sample.jpg',
277
+ sampleFilePath: '/files/sample.pdf',
278
+ googleMapsApiKey: null,
279
+ },
280
+ items,
281
+ catalog: defaultCatalog,
282
+ generalCSS,
283
+ initialContents: '<div></div>',
284
+ storageKey: {
285
+ blockClipboard: 'my-custom-clipboard-key', // カスタムキー
286
+ },
287
+ });
288
+ ```
289
+
290
+ ## 詳細なAPI仕様
291
+
292
+ ブロックの構造やアイテムの作成方法など、より詳細な技術仕様については [@burger-editor/core のREADME](../core/README.md) を参照してください。
293
+
294
+ ## カスタマイズのヒント
295
+
296
+ - **カスタムアイテムの作成**: [@burger-editor/core のREADME](../core/README.md#カスタムアイテムの作成) を参照
297
+ - **カスタムブロックカタログ**: [@burger-editor/core のREADME](../core/README.md#カスタムブロックカタログの作成) を参照
298
+ - **スタイルのカスタマイズ**: `config.stylesheets` でCSSを指定し、`config.classList` でクラスを追加
299
+ - **実験的機能の利用**: `config.experimental` でボタンアイテムのオプションなどをカスタマイズ可能
300
+
301
+ ## ライセンス
302
+
303
+ Dual Licensed under MIT OR Apache-2.0