itmar-block-packages 1.0.1 → 1.2.0

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 ADDED
@@ -0,0 +1,489 @@
1
+ # 概要
2
+ WordPressのカスタムブロックを作成するためのプラグインで活用するパッケージです。複数のプラグインで共通に使用する機能をパッケージにまとめました。
3
+
4
+ # 使用方法
5
+ ```
6
+ import {関数名又はコンポーネント名} from "itmar-block-packages"
7
+ ```
8
+ 名前付きインポートでお願いします。
9
+
10
+ # 各コンポーネント・関数の機能
11
+ ## カスタムフック
12
+ ### useIsIframeMobile
13
+ WordPressのエディタ(ブロックエディタ、サイトエディタ)の大きさを監視し、幅が767ピクセル以下であればtrueを返します。
14
+ ```
15
+ const is_mobile=useIsIframeMobile();
16
+ ```
17
+
18
+ ### useElementBackgroundColor
19
+ ブロックの背景色を返します。ユーザー設定で指定されていれば、その色を返し、指定されていないか、カスタムプロパティ(--wpで始まるプロパティ)であれば、getComputedStyleで実際にレンダリングされた色を取得します。
20
+ #### 引数
21
+ - `blockRef`
22
+ ブロックへの参照。useRefで取得
23
+ - `style`
24
+ ブロックに設定されているスタイル。useBlockPropsで取得
25
+ ```
26
+ //ブロックの参照
27
+ const blockRef = useRef(null);
28
+ //blockPropsの参照
29
+ const blockProps = useBlockProps({
30
+ ref: blockRef, // ここで参照を blockProps に渡しています
31
+ });
32
+
33
+ //背景色の取得
34
+ const baseColor = useElementBackgroundColor(blockRef, blockProps.style);
35
+ ```
36
+
37
+ ### useElementWidth
38
+
39
+ ### useIsMobile
40
+ ViewPortの大きさの大きさを監視し、幅が767ピクセル以下であればtrueを返します。
41
+ ```
42
+ const is_mobile=useIsMobile();
43
+ ```
44
+ ### useDeepCompareEffect
45
+ たくさんの要素をもつオブジェクトや配列の内容の変化で発火するuseEffect
46
+ #### 引数
47
+ - `callback` func
48
+ 発火させたい関数
49
+ - `dependencies` array
50
+ 依存変数にしたい配列
51
+ ```
52
+ useDeepCompareEffect(() => {
53
+ ・・・
54
+ },
55
+ [attributes]
56
+
57
+ ```
58
+ ### useFontawesomeIframe
59
+ iframeにfontawesomeを読み込むカスタムフック
60
+
61
+ ## styled-componet用のcssプロパティ生成関数
62
+ styled-componetのcssヘルパー関数内で使用するcssのパラメーターやプロパティを返します。
63
+ ### radius_prm
64
+ border-radiusに設定するプロパティを文字列で返します。
65
+ #### 引数
66
+ - `radius` object
67
+ topLeft,topRight,bottomRight,bottomLeftをキーとしてもつオブジェクト
68
+
69
+
70
+ ### space_prm
71
+ marginやpaddingに設定するプロパティを文字列で返します。
72
+ #### 引数
73
+ - `space` object
74
+ top,right,bottom,leftをキーとしてもつオブジェクト
75
+
76
+
77
+ ### max_width_prm
78
+ 最大幅を設定するためのCSSを返します。
79
+ #### 引数
80
+ - `width` string
81
+ wideSize,contentSize,free,fullの文字列
82
+ - `free_val` number
83
+ px値
84
+ #### 戻り値
85
+ - wideSizeのとき`width: 100%; max-width: var(--wp--style--global--wide-size);`
86
+ - contentSizeのとき`width: 100%; max-width: var(--wp--style--global--content-size);`
87
+ - freeのとき`width: 100%; max-width: ${free_val}px;`
88
+ - fullのとき`width: 100%; max-width: 100%;`
89
+ - その他の文字列`width: fit-content;`
90
+
91
+
92
+ ### width_prm
93
+ widthのCSSを返します。
94
+ #### 引数
95
+ - `width` string
96
+ wideSize,contentSize,freeの文字列
97
+ - `free_val` number
98
+ px値
99
+ #### 戻り値
100
+ - wideSizeのとき`width: var(--wp--style--global--wide-size);`
101
+ - contentSizeのとき`width: var(--wp--style--global--content-size);`
102
+ - freeのとき`width: ${free_val}px;`
103
+ - その他の文字列`width: fit-content;`
104
+
105
+
106
+ ### height_prm
107
+ heightのCSSを返します。
108
+ #### 引数
109
+ - `height` string
110
+ fitの文字列
111
+ #### 戻り値
112
+ - fitのとき`height: fit-content;`
113
+ - その他の文字列`height: 100%;`
114
+
115
+
116
+ ### align_prm
117
+ marginによる横方向の配置のためのCSSを返します。
118
+ #### 引数
119
+ - `align` string
120
+ center,rightの文字列
121
+ #### 戻り値
122
+ - centerのとき`margin-left: auto; margin-right: auto;`
123
+ - rightのとき`margin-left: auto; margin-right: 0`
124
+ - その他の文字列`margin-right: auto; margin-left: 0`
125
+
126
+
127
+ ### convertToScss
128
+ キャメルケースで与えられたstyleオブジェクトをscssの文字列に変換します。
129
+ #### 引数
130
+ - `styleObject` object
131
+ ブロックに設定されたスタイルオブジェクト
132
+
133
+ ```
134
+ const str_scss = convertToScss(styleObject)
135
+ ```
136
+
137
+
138
+ ### borderProperty
139
+ WordPressのBorderBoxControlコンポーネントが返すオブジェクトをキャメルケースのCSSに変換して返します。
140
+ #### 引数
141
+ - `borderObj` object
142
+ WordPressのBorderBoxControlコンポーネントが返すオブジェクト
143
+
144
+ ```
145
+ const css_obj = borderProperty(borderObj)
146
+ ```
147
+
148
+
149
+ ### radiusProperty
150
+ WordPressのBorderRadiusControlコンポーネントが返すオブジェクトをキャメルケースのCSSに変換して返します。
151
+ #### 引数
152
+ - `radiusObj` object
153
+ WordPressのBorderRadiusControlコンポーネントが返すオブジェクト
154
+
155
+ ```
156
+ const css_obj = radiusProperty(radiusObj)
157
+ ```
158
+
159
+
160
+ ### marginProperty
161
+ marginのcssを返します。
162
+ #### 引数
163
+ - `marginObj` object
164
+ top,right,bottom,leftをキーとしてもつオブジェクト。オブジェクトの値は単位(px,em,%等)付きにしてください。
165
+
166
+
167
+ ### paddingProperty
168
+ paddingのcssを返します。
169
+ #### 引数
170
+ - `paddingObj` object
171
+ top,right,bottom,leftをキーとしてもつオブジェクト。オブジェクトの値は単位(px,em,%等)付きにしてください。
172
+
173
+
174
+ ## ボックスシャドーを設定するコントロール
175
+ ### ShadowStyle
176
+ WordPressのブロックエディタのサイドバーにbox-shadowを設定するためのコントロールを表示させるReactコンポーネント。
177
+ ```
178
+ <ShadowStyle
179
+ shadowStyle={{ ...shadow_element }}
180
+ onChange={(newStyle, newState) => {
181
+ setAttributes({ shadow_result: newStyle.style });
182
+ setAttributes({ shadow_element: newState });
183
+ }}
184
+ />
185
+ ```
186
+
187
+ <img src="./img/shadow.png" alt="ShadowStyleのスクリーンショット" width="500" height="500">
188
+
189
+
190
+ ### ShadowElm
191
+ 設定されたbox-shadowをスタイルオブジェクトとして返します。
192
+ #### 引数
193
+ - `shadowState` object
194
+ ShadowStyleコンポーネントで生成され、ブロックの属性としてセットされるオブジェクト
195
+
196
+
197
+ ## 疑似要素を設定するコントロール
198
+ ### PseudoElm
199
+ WordPressのブロックエディタのサイドバーに疑似要素を設定するためのコントロールを表示させるReactコンポーネント。現時点のバージョンでは上下左右の矢印表示の設定のみが可能です。
200
+ ```
201
+ <PseudoElm
202
+ element="Arrow"
203
+ direction={pseudoInfo.option}
204
+ onChange={(direction) => {
205
+ setAttributes({
206
+ pseudoInfo: { ...pseudoInfo, option: direction },
207
+ });
208
+ }}
209
+ />
210
+ ```
211
+ <img src="./img/pseudo.png" alt="PseudoElmのスクリーンショット" width="200" height="100">
212
+
213
+ ### Arrow
214
+ 矢印を表示させる疑似要素を生成してscssの文字列で返します。
215
+ ```
216
+ const arrow = Arrow(direction);
217
+
218
+ ```
219
+ #### 引数
220
+ - `direction` object
221
+ キーをdirection、値をupper,left,right,underのいずれかとするオブジェクト
222
+
223
+
224
+
225
+ ## メディアライブラリから画像を選択するコントロール
226
+ ### SingleImageSelect
227
+ メディアライブラリ選択画面を開き、ブロックの属性にmediaとmedia.idをセットします。
228
+ ```
229
+ <SingleImageSelect
230
+ attributes={attributes}
231
+ onSelectChange={(media) => {
232
+ setAttributes({ media: media, mediaID: media.id });
233
+ }}
234
+ />
235
+ ```
236
+ ### MultiImageSelect
237
+ メディアライブラリ選択画面を開き、複数の画像を選択して、ブロックの属性にmediaとmedia.idをセットします。
238
+ ```
239
+ <MultiImageSelect
240
+ attributes={attributes}
241
+ label=__("Selected Images", "text-domain")
242
+ onSelectChange={(media) => {
243
+ // media から map で id プロパティの配列を生成
244
+ const media_ID = media.map((image) => image.id);
245
+ setAttributes({
246
+ mobile_val: { ...mobile_val, mediaID: media_ID, media: media },
247
+ });
248
+
249
+ }}
250
+ onAllDelete={() => {
251
+ setAttributes({
252
+ mobile_val: { ...mobile_val, mediaID: [], media: [] },
253
+ });
254
+ }}
255
+ />
256
+ ```
257
+
258
+
259
+ ## ブロックのドラッガブルを設定するコントロール
260
+ ### DraggableBox
261
+ ブロックを移動させる移動量を設定するコントロールをサイドバーに表示させます。
262
+ ```
263
+ <DraggableBox
264
+ attributes={position}
265
+ onPositionChange={(position) =>
266
+ setAttributes({ position: position })
267
+ }
268
+ />
269
+ ```
270
+
271
+
272
+ ### useDraggingMove
273
+ 参照したブロックを可能とするためのカスタムフックを設定します。
274
+ ```
275
+ useDraggingMove(
276
+ isMovable,
277
+ blockRef,
278
+ position,
279
+ onPositionChange
280
+ )
281
+ ```
282
+ #### 引数
283
+ - `isMovable` boolean
284
+ 移動を可とするかどうかのフラグ
285
+ - `blockRef` useRef
286
+ 移動させるブロックへの参照
287
+ - `position` object
288
+ 移動量を決定するためのx,yのキーをもつオブジェクト
289
+ - `onPositionChange` function
290
+ 移動量が変化したときに属性値を記録するためのコールバック関数
291
+
292
+
293
+ ## ブロックをlazy Loadさせるためのラッパーモジュール
294
+ ## BlockEditWrapper
295
+ registerBlockTypeの第2引数内にあるeditオブジェクトに、以下の使用例で生成したBlockEditを渡してやることで、ブロックの読み込みをレンダリングの時まで遅らせます。
296
+
297
+ ```
298
+ const LazyEditComponent = React.lazy(() => import("./edit"));
299
+ const BlockEdit = (props) => {
300
+ return <BlockEditWrapper lazyComponent={LazyEditComponent} {...props} />;
301
+ };
302
+ ```
303
+ ## ブロックにアニメーション効果をあたえるためのコントロール
304
+ ### AnimationBlock
305
+ WordPressのブロックエディタのサイドバーにアニメーションを設定するためのコントロールを表示させるReactコンポーネント。現時点のバージョンではflipDown,fadeUp,fadeLeft,fadeRightのアニメーション設定が可能です
306
+ ```
307
+ <AnimationBlock
308
+ attributes={attributes}
309
+ onChange={(newValue) => setAttributes(newValue)}
310
+ />
311
+ ```
312
+ <img src="./img/animation.png" alt="AnimationBlockのスクリーンショット" width="100" height="200">
313
+
314
+ ### anime_comp
315
+ 設定されたアニメーションのパラメータをオブジェクトとして渡すことで、SCSSの文字列に変換して返します。
316
+ #### 引数
317
+ - `anime_prm` object
318
+ AnimationBlockコンポーネントで生成され、ブロックの属性としてセットされるオブジェクト
319
+
320
+
321
+ ## Typographyを設定するコントロール
322
+ ### TypographyControls
323
+ WordPressのブロックエディタのサイドバーにTypographyを設定するためのコントロールを表示させるReactコンポーネント。
324
+ ```
325
+ <TypographyControls
326
+ title={__("Typography", "text-domain")}
327
+ fontStyle=
328
+ {
329
+ default_fontSize: "16px",
330
+ mobile_fontSize: "12px",
331
+ fontFamily: "Arial, sans-serif",
332
+ fontWeight: "500",
333
+ isItalic: false,
334
+ }
335
+ initialOpen={false}
336
+ isMobile={isMobile}
337
+ onChange={(newStyle) => {
338
+ setAttributes({ font_style_input: newStyle });
339
+ }}
340
+ />
341
+ ```
342
+ <img src="./img/typography.png" alt="Typographyのスクリーンショット" width="100" height="200">
343
+
344
+ ## WordPressのデータをRest APIを通して取得する関数等
345
+ ### fetchPagesOptions
346
+ 固定ページのid,title,linkを返します。
347
+ ### fetchArchiveOptions
348
+ 投稿タイプのアーカイブのurlを返します。
349
+ ### PageSelectControl
350
+ 固定ページのタイトルを表示し、そのリンクを返すセレクトコントロールを表示させます。
351
+ ```
352
+ <PageSelectControl
353
+ attributes={attributes}
354
+ setAttributes={setAttributes}
355
+ label={__("Select a fixed page to link to", "text-domain")}
356
+ homeUrl={block_collections.home_url}
357
+ />
358
+ ```
359
+ ### ArchiveSelectControl
360
+ 投稿タイプ名を表示し、そのアーカイブのURLを返すセレクトコントロールを表示させます。
361
+ ```
362
+ <ArchiveSelectControl
363
+ attributes={attributes}
364
+ setAttributes={setAttributes}
365
+ label={__("Select archive page to link to", "text-domain")}
366
+ homeUrl={block_collections.home_url}
367
+ />
368
+ ```
369
+
370
+ ## Font awesom のアイコンを選択するためのコントロール
371
+ ### IconSelectControl
372
+ WordPressのブロックエディタのサイドバーにFont awesomのアイコンを選択するためのコントロールを表示させるReactコンポーネント。
373
+ ```
374
+ <IconSelectControl
375
+ iconStyle={
376
+ icon_name: "f030",
377
+ icon_pos: "left",
378
+ icon_size: "24px",
379
+ icon_color: "var(--wp--preset--color--content)",
380
+ icon_space: "5px",
381
+ }
382
+ onChange={(newValue) => {
383
+ setAttributes({icon_style: newValue})
384
+ }}
385
+ />
386
+ ```
387
+
388
+ <img src="./img/iconControl.png" alt="IconSelectControlのスクリーンショット" width="100" height="200">
389
+
390
+ ## DOM要素をラップしてレンダリングを変化させるReactコンポーネント
391
+ ### ToggleElement
392
+ DOM要素をdiv要素でラップし、flgの値によって、その要素にopenというクラス名を付加します。呼び出し側でflgの値を変更することで、DOM要素の表示・非表示を操作するときに使用します。
393
+
394
+ ```
395
+ <ToggleElement
396
+ onToggle={handleHambergerToggle}
397
+ className="itmar_hamberger_btn"
398
+ openFlg={flg}
399
+ >
400
+ <span></span>
401
+ <span></span>
402
+ <span></span>
403
+ </ToggleElement>
404
+ ```
405
+
406
+ ## グリッドスタイルの各種設定を行うためのコントロール
407
+ ### GridControls
408
+ CSSでdisplay : grid が設定されたブロックに対し、gridの各種設定を行うため、モーダルウインドウを表示させるReactコンポーネント。
409
+ ```
410
+ <GridControls
411
+ attributes={props.grid_info}
412
+ clientId={clientId}
413
+ onChange={(newValue) => {
414
+ props.onGridChange(newValue)
415
+ }}
416
+ />
417
+ ```
418
+
419
+ <img src="./img/grid.png" alt="GridControlsのスクリーンショット" width="200" height="200">
420
+
421
+ ## ブロックの配置に関する各種設定を行うためのコントロール
422
+ ### BlockPlace
423
+ WordPressのブロックエディタのサイドバーにブロックの配置に関する設定のためのコントロールを表示させるReactコンポーネント。
424
+ ```
425
+ <BlockPlace
426
+ attributes={attributes}
427
+ clientId={clientId}
428
+ blockRef={blockRef}
429
+ isMobile={isMobile}
430
+ isSubmenu={is_submenu}
431
+ onDirectionChange={(position) => {
432
+ setAttributes({direction: position });
433
+ }}
434
+ onFlexChange={(position) => {
435
+ setAttributes({inner_align: position });
436
+ }}
437
+ onAlignChange={(position) => {
438
+ setAttributes({outer_align: position });
439
+ }}
440
+ onVerticalChange={(position) => {
441
+ setAttributes({outer_vertical: position });
442
+ }}
443
+ onWidthChange={(position) => {
444
+ setAttributes({outer_vertical: position });
445
+ }}
446
+ onHeightChange={(value) => {
447
+ setAttributes({ heightValue: value });
448
+ }}
449
+ onFreevalChange={(value) => {
450
+ setAttributes({free_val: position });
451
+ }}
452
+ onGridChange={(value) => {
453
+ setAttributes({grid_info: position });
454
+ }}
455
+ onPositionChange={(value) => {
456
+ setAttributes({ positionType: value });
457
+ }}
458
+ onPosValueChange={(value) => {
459
+ setAttributes({posValue: position });
460
+ }}
461
+ />
462
+ ```
463
+
464
+
465
+ <img src="./img/blockplace.png" alt="BlockPlaceのスクリーンショット" width="100" height="300">
466
+
467
+ ## 色コードを変換する関数
468
+ ### hslToRgb16
469
+ Hslオブジェクトの値を与えると#000000型のRGB表記に変換するためのユーティリティ関数です。
470
+ #### 引数
471
+ - `hue` number
472
+ Hslオブジェクトのhueの値
473
+ - `saturation` number
474
+ Hslオブジェクトのsaturationの値
475
+ - `lightness` number
476
+ Hslオブジェクトのlightnessの値
477
+
478
+ ### rgb16ToHsl
479
+ 16進数のRGB表記を受け取り、それをHslオブジェクトに変換するためのユーティリティ関数です。
480
+ #### 引数
481
+ - `strRgb16` string
482
+ #000000形式の16進数の文字列又はrgb(0,0,0) 形式の文字列
483
+   
484
+
485
+ ### HexToRGB
486
+ 16進数のRGB表記を受け取り、それを10進数のRGBオブジェクトに変換するためのユーティリティ関数です。
487
+ #### 引数
488
+ - `strRgb16` string
489
+ #000000形式の16進数の文字列又はrgb(0,0,0) 形式の文字列
@@ -1 +1 @@
1
- <?php return array('dependencies' => array('react', 'wp-block-editor', 'wp-components', 'wp-data', 'wp-element', 'wp-i18n'), 'version' => 'a3c45292157780c09446');
1
+ <?php return array('dependencies' => array('react', 'react-dom', 'wp-api-fetch', 'wp-block-editor', 'wp-components', 'wp-data', 'wp-element', 'wp-i18n', 'wp-primitives'), 'version' => '3374fe99c0756e1cc1e6');