@burger-editor/client 4.0.0-alpha.3 → 4.0.0-alpha.30
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 +234 -2
- package/dist/client.css +609 -370
- package/dist/client.js +38250 -8289
- package/dist/client.js.map +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/replace-element.d.ts.map +1 -1
- package/dist/tabs.svelte.d.ts +1 -0
- package/package.json +17 -16
- package/LICENSE +0 -21
package/README.md
CHANGED
|
@@ -1,3 +1,235 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @burger-editor/client
|
|
2
2
|
|
|
3
|
-
[](https://badge.fury.io/js/@burger-editor%2Fclient)
|
|
4
|
+
|
|
5
|
+
BurgerEditorのクライアント側UIパッケージです。Svelteベースのコンポーネントを提供し、既存のCMSやWebアプリケーションにBurgerEditorを統合できます。
|
|
6
|
+
|
|
7
|
+
## インストール
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
npm install @burger-editor/client @burger-editor/core @burger-editor/blocks
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
または
|
|
14
|
+
|
|
15
|
+
```bash
|
|
16
|
+
yarn add @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` を除いたオプションです。以下の主要なプロパティがあります:
|
|
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
|
+
## 使用例
|
|
75
|
+
|
|
76
|
+
以下は基本的な使用例です:
|
|
77
|
+
|
|
78
|
+
```typescript
|
|
79
|
+
import { createBurgerEditorClient } from '@burger-editor/client';
|
|
80
|
+
import { items, generalCSS, defaultCatalog } from '@burger-editor/blocks';
|
|
81
|
+
import { CSS_LAYER } from '@burger-editor/core';
|
|
82
|
+
import '@burger-editor/client/style';
|
|
83
|
+
|
|
84
|
+
async function initEditor() {
|
|
85
|
+
// エディタをマウントする要素を取得
|
|
86
|
+
const mainInput = document.getElementById('main') as HTMLInputElement;
|
|
87
|
+
|
|
88
|
+
if (!mainInput) {
|
|
89
|
+
console.error('Editable area not found');
|
|
90
|
+
return;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
// エディタを作成
|
|
94
|
+
const { engine } = await createBurgerEditorClient({
|
|
95
|
+
root: '.editor',
|
|
96
|
+
config: {
|
|
97
|
+
classList: [],
|
|
98
|
+
stylesheets: [
|
|
99
|
+
{
|
|
100
|
+
path: '/path/to/your/styles.css',
|
|
101
|
+
layer: CSS_LAYER.ui,
|
|
102
|
+
},
|
|
103
|
+
{
|
|
104
|
+
path: generalCSS,
|
|
105
|
+
layer: CSS_LAYER.general,
|
|
106
|
+
},
|
|
107
|
+
],
|
|
108
|
+
sampleImagePath: '/images/sample.jpg',
|
|
109
|
+
sampleFilePath: '/files/sample.pdf',
|
|
110
|
+
googleMapsApiKey: null,
|
|
111
|
+
},
|
|
112
|
+
items,
|
|
113
|
+
catalog: defaultCatalog,
|
|
114
|
+
generalCSS,
|
|
115
|
+
initialContents: mainInput.value,
|
|
116
|
+
viewAreaClassList: ['my-editor'],
|
|
117
|
+
onUpdated: async (main, draft) => {
|
|
118
|
+
// コンテンツが更新されたときの処理
|
|
119
|
+
mainInput.value = main;
|
|
120
|
+
console.log('Content updated:', { main, draft });
|
|
121
|
+
},
|
|
122
|
+
});
|
|
123
|
+
|
|
124
|
+
console.log('Editor initialized:', engine);
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
// 初期化実行
|
|
128
|
+
initEditor();
|
|
129
|
+
```
|
|
130
|
+
|
|
131
|
+
### カスタムブロックカタログの使用
|
|
132
|
+
|
|
133
|
+
```typescript
|
|
134
|
+
import { createBurgerEditorClient } from '@burger-editor/client';
|
|
135
|
+
import { items, generalCSS, defaultCatalog } from '@burger-editor/blocks';
|
|
136
|
+
|
|
137
|
+
const customCatalog = {
|
|
138
|
+
...defaultCatalog,
|
|
139
|
+
カスタムカテゴリ: [
|
|
140
|
+
{
|
|
141
|
+
label: 'カスタムブロック',
|
|
142
|
+
definition: {
|
|
143
|
+
name: 'custom-block',
|
|
144
|
+
containerProps: {
|
|
145
|
+
type: 'grid',
|
|
146
|
+
columns: 2,
|
|
147
|
+
},
|
|
148
|
+
items: [['wysiwyg', 'image']],
|
|
149
|
+
},
|
|
150
|
+
},
|
|
151
|
+
],
|
|
152
|
+
};
|
|
153
|
+
|
|
154
|
+
await createBurgerEditorClient({
|
|
155
|
+
root: '.editor',
|
|
156
|
+
config: {
|
|
157
|
+
classList: [],
|
|
158
|
+
stylesheets: [],
|
|
159
|
+
sampleImagePath: '/images/sample.jpg',
|
|
160
|
+
sampleFilePath: '/files/sample.pdf',
|
|
161
|
+
googleMapsApiKey: null,
|
|
162
|
+
},
|
|
163
|
+
items,
|
|
164
|
+
catalog: customCatalog,
|
|
165
|
+
generalCSS,
|
|
166
|
+
initialContents: '<div class="editable"></div>',
|
|
167
|
+
});
|
|
168
|
+
```
|
|
169
|
+
|
|
170
|
+
### ファイルIOの実装
|
|
171
|
+
|
|
172
|
+
```typescript
|
|
173
|
+
import { createBurgerEditorClient } from '@burger-editor/client';
|
|
174
|
+
import type { FileAPI } from '@burger-editor/core';
|
|
175
|
+
|
|
176
|
+
const fileIO: FileAPI = {
|
|
177
|
+
async getFileList(fileType, options) {
|
|
178
|
+
// ファイルリストを取得する実装
|
|
179
|
+
const response = await fetch(`/api/files/${fileType}?page=${options.page}`);
|
|
180
|
+
return response.json();
|
|
181
|
+
},
|
|
182
|
+
async postFile(fileType, file, progress) {
|
|
183
|
+
// ファイルをアップロードする実装
|
|
184
|
+
const formData = new FormData();
|
|
185
|
+
formData.append('file', file);
|
|
186
|
+
|
|
187
|
+
const response = await fetch(`/api/files/${fileType}`, {
|
|
188
|
+
method: 'POST',
|
|
189
|
+
body: formData,
|
|
190
|
+
});
|
|
191
|
+
|
|
192
|
+
return response.json();
|
|
193
|
+
},
|
|
194
|
+
async deleteFile(fileType, url) {
|
|
195
|
+
// ファイルを削除する実装
|
|
196
|
+
const response = await fetch(`/api/files/${fileType}`, {
|
|
197
|
+
method: 'DELETE',
|
|
198
|
+
body: JSON.stringify({ url }),
|
|
199
|
+
});
|
|
200
|
+
|
|
201
|
+
return response.json();
|
|
202
|
+
},
|
|
203
|
+
};
|
|
204
|
+
|
|
205
|
+
await createBurgerEditorClient({
|
|
206
|
+
root: '.editor',
|
|
207
|
+
config: {
|
|
208
|
+
classList: [],
|
|
209
|
+
stylesheets: [],
|
|
210
|
+
sampleImagePath: '/images/sample.jpg',
|
|
211
|
+
sampleFilePath: '/files/sample.pdf',
|
|
212
|
+
googleMapsApiKey: null,
|
|
213
|
+
},
|
|
214
|
+
items,
|
|
215
|
+
catalog: defaultCatalog,
|
|
216
|
+
generalCSS,
|
|
217
|
+
initialContents: '<div class="editable"></div>',
|
|
218
|
+
fileIO,
|
|
219
|
+
});
|
|
220
|
+
```
|
|
221
|
+
|
|
222
|
+
## 詳細なAPI仕様
|
|
223
|
+
|
|
224
|
+
ブロックの構造やアイテムの作成方法など、より詳細な技術仕様については [@burger-editor/core のREADME](../core/README.md) を参照してください。
|
|
225
|
+
|
|
226
|
+
## カスタマイズのヒント
|
|
227
|
+
|
|
228
|
+
- **カスタムアイテムの作成**: [@burger-editor/core のREADME](../core/README.md#カスタムアイテムの作成) を参照
|
|
229
|
+
- **カスタムブロックカタログ**: [@burger-editor/core のREADME](../core/README.md#カスタムブロックカタログの作成) を参照
|
|
230
|
+
- **スタイルのカスタマイズ**: `config.stylesheets` でCSSを指定し、`config.classList` でクラスを追加
|
|
231
|
+
- **実験的機能の利用**: `config.experimental` でボタンアイテムのオプションなどをカスタマイズ可能
|
|
232
|
+
|
|
233
|
+
## ライセンス
|
|
234
|
+
|
|
235
|
+
Dual Licensed under MIT OR Apache-2.0
|