itmar-block-packages 1.0.0 → 1.0.1
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/babel.config.js +16 -0
- package/build/index.asset.php +1 -0
- package/build/index.js +20 -0
- package/package.json +7 -2
- package/src/Arrow.js +35 -0
- package/src/DraggableBox.js +55 -0
- package/src/PseudoElm.js +21 -0
- package/{ShadowStyle.js → src/ShadowCtrl.js} +3 -236
- package/src/ShadowElm.js +235 -0
- package/src/draggingFook.js +88 -0
- package/{index.js → src/index.js} +18 -15
- package/src/mediaUpload.js +70 -0
- package/webpack.config.js +28 -0
- package/DraggableBox.js +0 -139
- package/mediaUpload.js +0 -90
- package/pseudo.js +0 -55
- /package/{BlockEditWrapper.js → src/BlockEditWrapper.js} +0 -0
- /package/{cssPropertes.js → src/cssPropertes.js} +0 -0
- /package/{customFooks.js → src/customFooks.js} +0 -0
- /package/{hslToRgb.js → src/hslToRgb.js} +0 -0
package/src/ShadowElm.js
ADDED
|
@@ -0,0 +1,235 @@
|
|
|
1
|
+
import { __ } from "@wordpress/i18n";
|
|
2
|
+
import { dispatch } from "@wordpress/data";
|
|
3
|
+
import { hslToRgb16, HexToRGB, rgb16ToHsl } from "./hslToRgb";
|
|
4
|
+
|
|
5
|
+
//方向と距離
|
|
6
|
+
const dirctionDigit = (direction, distance) => {
|
|
7
|
+
let destTopLeft, destTopRight, destBottomLeft, destBottomRight;
|
|
8
|
+
switch (direction) {
|
|
9
|
+
case "top_left":
|
|
10
|
+
destTopLeft = distance;
|
|
11
|
+
destTopRight = distance;
|
|
12
|
+
destBottomLeft = distance * -1;
|
|
13
|
+
destBottomRight = distance * -1;
|
|
14
|
+
break;
|
|
15
|
+
case "top_right":
|
|
16
|
+
destTopLeft = distance * -1;
|
|
17
|
+
destTopRight = distance;
|
|
18
|
+
destBottomLeft = distance;
|
|
19
|
+
destBottomRight = distance * -1;
|
|
20
|
+
break;
|
|
21
|
+
case "bottom_left":
|
|
22
|
+
destTopLeft = distance;
|
|
23
|
+
destTopRight = distance * -1;
|
|
24
|
+
destBottomLeft = distance * -1;
|
|
25
|
+
destBottomRight = distance;
|
|
26
|
+
break;
|
|
27
|
+
case "bottom_right":
|
|
28
|
+
destTopLeft = distance * -1;
|
|
29
|
+
destTopRight = distance * -1;
|
|
30
|
+
destBottomLeft = distance;
|
|
31
|
+
destBottomRight = distance;
|
|
32
|
+
break;
|
|
33
|
+
case "right_bottom":
|
|
34
|
+
destTopLeft = distance;
|
|
35
|
+
destTopRight = distance * -1;
|
|
36
|
+
destBottomLeft = distance * -1;
|
|
37
|
+
destBottomRight = distance;
|
|
38
|
+
break;
|
|
39
|
+
case "top":
|
|
40
|
+
destTopLeft = 0;
|
|
41
|
+
destTopRight = 0;
|
|
42
|
+
destBottomLeft = distance * -1;
|
|
43
|
+
destBottomRight = distance;
|
|
44
|
+
break;
|
|
45
|
+
}
|
|
46
|
+
return {
|
|
47
|
+
topLeft: destTopLeft,
|
|
48
|
+
topRight: destTopRight,
|
|
49
|
+
bottomLeft: destBottomLeft,
|
|
50
|
+
bottmRight: destBottomRight,
|
|
51
|
+
};
|
|
52
|
+
};
|
|
53
|
+
|
|
54
|
+
// グラデーションの色値は通常'linear-gradient'または'radial-gradient'で始まるので、
|
|
55
|
+
// これらのキーワードを探すことでグラデーションかどうかを判断します。
|
|
56
|
+
function isGradient(colorValue) {
|
|
57
|
+
return (
|
|
58
|
+
colorValue.includes("linear-gradient") ||
|
|
59
|
+
colorValue.includes("radial-gradient")
|
|
60
|
+
);
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
export const ShadowElm = (shadowState) => {
|
|
64
|
+
//let baseColor;
|
|
65
|
+
const {
|
|
66
|
+
shadowType,
|
|
67
|
+
spread,
|
|
68
|
+
lateral,
|
|
69
|
+
longitude,
|
|
70
|
+
nomalBlur,
|
|
71
|
+
shadowColor,
|
|
72
|
+
blur,
|
|
73
|
+
intensity,
|
|
74
|
+
distance,
|
|
75
|
+
newDirection,
|
|
76
|
+
clayDirection,
|
|
77
|
+
embos,
|
|
78
|
+
opacity,
|
|
79
|
+
depth,
|
|
80
|
+
bdBlur,
|
|
81
|
+
expand,
|
|
82
|
+
glassblur,
|
|
83
|
+
glassopa,
|
|
84
|
+
hasOutline,
|
|
85
|
+
baseColor,
|
|
86
|
+
} = shadowState;
|
|
87
|
+
|
|
88
|
+
//ノーマル
|
|
89
|
+
if (shadowType === "nomal") {
|
|
90
|
+
//boxshadowの生成
|
|
91
|
+
const ShadowStyle =
|
|
92
|
+
embos === "dent"
|
|
93
|
+
? {
|
|
94
|
+
style: {
|
|
95
|
+
boxShadow: `${lateral}px ${longitude}px ${nomalBlur}px ${spread}px transparent, inset ${lateral}px ${longitude}px ${nomalBlur}px ${spread}px ${shadowColor}`,
|
|
96
|
+
},
|
|
97
|
+
}
|
|
98
|
+
: {
|
|
99
|
+
style: {
|
|
100
|
+
boxShadow: `${lateral}px ${longitude}px ${nomalBlur}px ${spread}px ${shadowColor}, inset ${lateral}px ${longitude}px ${nomalBlur}px ${spread}px transparent`,
|
|
101
|
+
},
|
|
102
|
+
};
|
|
103
|
+
//Shadowのスタイルを返す
|
|
104
|
+
return ShadowStyle;
|
|
105
|
+
}
|
|
106
|
+
//ニューモフィズム
|
|
107
|
+
else if (shadowType === "newmor") {
|
|
108
|
+
//背景がグラデーションのときはセットしない
|
|
109
|
+
if (isGradient(baseColor)) {
|
|
110
|
+
dispatch("core/notices").createNotice(
|
|
111
|
+
"error",
|
|
112
|
+
__(
|
|
113
|
+
"Neumorphism cannot be set when the background color is a gradient. ",
|
|
114
|
+
"itmar_guest_contact_block"
|
|
115
|
+
),
|
|
116
|
+
{ type: "snackbar", isDismissible: true }
|
|
117
|
+
);
|
|
118
|
+
return null;
|
|
119
|
+
}
|
|
120
|
+
//ボタン背景色のHSL値
|
|
121
|
+
const hslValue = rgb16ToHsl(baseColor);
|
|
122
|
+
//影の明るさを変更
|
|
123
|
+
const lightVal =
|
|
124
|
+
hslValue.lightness + intensity < 100
|
|
125
|
+
? hslValue.lightness + intensity
|
|
126
|
+
: 100;
|
|
127
|
+
const darkVal =
|
|
128
|
+
hslValue.lightness - intensity > 0 ? hslValue.lightness - intensity : 0;
|
|
129
|
+
const lightValue = hslToRgb16(hslValue.hue, hslValue.saturation, lightVal);
|
|
130
|
+
const darkValue = hslToRgb16(hslValue.hue, hslValue.saturation, darkVal);
|
|
131
|
+
//boxshadowの生成
|
|
132
|
+
//立体の方向
|
|
133
|
+
const dircObj = dirctionDigit(newDirection, distance);
|
|
134
|
+
|
|
135
|
+
const baseStyle = {
|
|
136
|
+
style: {
|
|
137
|
+
border: "none",
|
|
138
|
+
background: baseColor,
|
|
139
|
+
},
|
|
140
|
+
};
|
|
141
|
+
|
|
142
|
+
const newmorStyle =
|
|
143
|
+
embos === "swell"
|
|
144
|
+
? {
|
|
145
|
+
style: {
|
|
146
|
+
...baseStyle.style,
|
|
147
|
+
boxShadow: `${dircObj.topLeft}px ${dircObj.topRight}px ${blur}px ${darkValue}, ${dircObj.bottomLeft}px ${dircObj.bottmRight}px ${blur}px ${lightValue}, inset ${dircObj.topLeft}px ${dircObj.topRight}px ${blur}px transparent, inset ${dircObj.bottomLeft}px ${dircObj.bottmRight}px ${blur}px transparent`,
|
|
148
|
+
},
|
|
149
|
+
}
|
|
150
|
+
: {
|
|
151
|
+
style: {
|
|
152
|
+
...baseStyle.style,
|
|
153
|
+
boxShadow: `${dircObj.topLeft}px ${dircObj.topRight}px ${blur}px transparent, ${dircObj.bottomLeft}px ${dircObj.bottmRight}px ${blur}px transparent, inset ${dircObj.topLeft}px ${dircObj.topRight}px ${blur}px ${darkValue}, inset ${dircObj.bottomLeft}px ${dircObj.bottmRight}px ${blur}px ${lightValue}`,
|
|
154
|
+
},
|
|
155
|
+
};
|
|
156
|
+
|
|
157
|
+
//Shadowのスタイルを返す
|
|
158
|
+
return newmorStyle;
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
//クレイモーフィズム
|
|
162
|
+
else if (shadowType === "claymor") {
|
|
163
|
+
//背景がグラデーションのときはセットしない
|
|
164
|
+
if (isGradient(baseColor)) {
|
|
165
|
+
dispatch("core/notices").createNotice(
|
|
166
|
+
"error",
|
|
167
|
+
__(
|
|
168
|
+
"claymorphism cannot be set when the background color is a gradient. ",
|
|
169
|
+
"itmar_guest_contact_block"
|
|
170
|
+
),
|
|
171
|
+
{ type: "snackbar", isDismissible: true }
|
|
172
|
+
);
|
|
173
|
+
return null;
|
|
174
|
+
}
|
|
175
|
+
const rgbValue = HexToRGB(baseColor);
|
|
176
|
+
const outsetObj = dirctionDigit(clayDirection, expand);
|
|
177
|
+
const insetObj = dirctionDigit(clayDirection, depth);
|
|
178
|
+
const baseStyle = {
|
|
179
|
+
style: {
|
|
180
|
+
background: `rgba(255, 255, 255, ${opacity})`,
|
|
181
|
+
backdropFilter: `blur(${bdBlur}px)`,
|
|
182
|
+
border: "none",
|
|
183
|
+
},
|
|
184
|
+
};
|
|
185
|
+
const claymorStyle = {
|
|
186
|
+
...baseStyle,
|
|
187
|
+
style: {
|
|
188
|
+
...baseStyle.style,
|
|
189
|
+
boxShadow: `${outsetObj.topLeft}px ${outsetObj.bottmRight}px ${
|
|
190
|
+
expand * 2
|
|
191
|
+
}px 0px rgba(${rgbValue.red}, ${rgbValue.green}, ${
|
|
192
|
+
rgbValue.blue
|
|
193
|
+
}, 0.5), inset ${insetObj.topRight}px ${
|
|
194
|
+
insetObj.bottomLeft
|
|
195
|
+
}px 16px 0px rgba(${rgbValue.red}, ${rgbValue.green}, ${
|
|
196
|
+
rgbValue.blue
|
|
197
|
+
}, 0.6), inset 0px 11px 28px 0px rgb(255, 255, 255)`,
|
|
198
|
+
},
|
|
199
|
+
};
|
|
200
|
+
//attributesに保存
|
|
201
|
+
return claymorStyle;
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
//グラスモーフィズム
|
|
205
|
+
else if (shadowType === "glassmor") {
|
|
206
|
+
const baseStyle = {
|
|
207
|
+
style: {
|
|
208
|
+
backgroundColor: `rgba(255, 255, 255, ${glassopa})`,
|
|
209
|
+
...(hasOutline ? { border: `1px solid rgba(255, 255, 255, 0.4)` } : {}),
|
|
210
|
+
borderRightColor: `rgba(255, 255, 255, 0.2)`,
|
|
211
|
+
borderBottomColor: `rgba(255, 255, 255, 0.2)`,
|
|
212
|
+
backdropFilter: `blur( ${glassblur}px )`,
|
|
213
|
+
},
|
|
214
|
+
};
|
|
215
|
+
const glassmorStyle =
|
|
216
|
+
embos === "swell"
|
|
217
|
+
? {
|
|
218
|
+
...baseStyle,
|
|
219
|
+
style: {
|
|
220
|
+
...baseStyle.style,
|
|
221
|
+
boxShadow: `0 8px 12px 0 rgba( 31, 38, 135, 0.37 ), inset 0 8px 12px 0 transparent`,
|
|
222
|
+
},
|
|
223
|
+
}
|
|
224
|
+
: {
|
|
225
|
+
...baseStyle,
|
|
226
|
+
style: {
|
|
227
|
+
...baseStyle.style,
|
|
228
|
+
boxShadow: `0 8px 12px 0 transparent, inset 0 8px 12px 0 rgba( 31, 38, 135, 0.37 )`,
|
|
229
|
+
},
|
|
230
|
+
};
|
|
231
|
+
|
|
232
|
+
//attributesに保存
|
|
233
|
+
return glassmorStyle;
|
|
234
|
+
}
|
|
235
|
+
};
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
import { useEffect, useRef } from "@wordpress/element";
|
|
2
|
+
import { __ } from "@wordpress/i18n";
|
|
3
|
+
|
|
4
|
+
export const useDraggingMove = (
|
|
5
|
+
isMovable,
|
|
6
|
+
blockRef,
|
|
7
|
+
position,
|
|
8
|
+
onPositionChange
|
|
9
|
+
) => {
|
|
10
|
+
const elmposition = useRef({ x: 0, y: 0 });
|
|
11
|
+
const isDragging = useRef(false);
|
|
12
|
+
const mousePosition = useRef({ x: 0, y: 0 });
|
|
13
|
+
|
|
14
|
+
useEffect(() => {
|
|
15
|
+
const element = blockRef.current;
|
|
16
|
+
|
|
17
|
+
if (!isMovable) {
|
|
18
|
+
if (element) {
|
|
19
|
+
element.classList.remove("itmar_isDraggable"); //移動カーソル表示クラス削除
|
|
20
|
+
}
|
|
21
|
+
return; // 移動許可がある場合のみ、後続のロジックを実行
|
|
22
|
+
}
|
|
23
|
+
//positionの変化に合わせて現在位置を変更
|
|
24
|
+
const pos_value_x = position.x.match(/(-?\d+)([%a-zA-Z]+)/);
|
|
25
|
+
const pos_value_y = position.y.match(/(-?\d+)([%a-zA-Z]+)/);
|
|
26
|
+
elmposition.current = {
|
|
27
|
+
x: parseInt(pos_value_x[1]),
|
|
28
|
+
y: parseInt(pos_value_y[1]),
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
//イベントハンドラ
|
|
32
|
+
const handleMouseDown = (event) => {
|
|
33
|
+
// 移動カーソル表示クラス名を追加します。
|
|
34
|
+
element.classList.add("itmar_isDraggable");
|
|
35
|
+
//ドラッグの開始フラグオン
|
|
36
|
+
isDragging.current = true;
|
|
37
|
+
//ドラッグ開始の絶対位置
|
|
38
|
+
mousePosition.current = { x: event.clientX, y: event.clientY };
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
const handleMouseMove = (event) => {
|
|
42
|
+
if (!isDragging.current) return; //ドラッグ中でなければ処理を中止
|
|
43
|
+
const dx = event.clientX - mousePosition.current.x;
|
|
44
|
+
const dy = event.clientY - mousePosition.current.y;
|
|
45
|
+
//ドラッグ後の位置を保存
|
|
46
|
+
const newPosition = {
|
|
47
|
+
x: elmposition.current.x + dx,
|
|
48
|
+
y: elmposition.current.y + dy,
|
|
49
|
+
};
|
|
50
|
+
elmposition.current = newPosition;
|
|
51
|
+
mousePosition.current = { x: event.clientX, y: event.clientY }; //マウス位置の保存
|
|
52
|
+
//ドラッグによるブロックの一時的移動
|
|
53
|
+
element.style.transform = `translate(${elmposition.current.x}px, ${elmposition.current.y}px)`;
|
|
54
|
+
};
|
|
55
|
+
|
|
56
|
+
const handleMouseUp = () => {
|
|
57
|
+
isDragging.current = false;
|
|
58
|
+
element.style.transform = null;
|
|
59
|
+
//呼出しもとに要素の位置を返す
|
|
60
|
+
onPositionChange({
|
|
61
|
+
x: `${elmposition.current.x}px`,
|
|
62
|
+
y: `${elmposition.current.y}px`,
|
|
63
|
+
});
|
|
64
|
+
};
|
|
65
|
+
const handleMouseLeave = () => {
|
|
66
|
+
isDragging.current = false;
|
|
67
|
+
};
|
|
68
|
+
|
|
69
|
+
if (element) {
|
|
70
|
+
// クラス名を追加します。
|
|
71
|
+
element.classList.add("itmar_isDraggable");
|
|
72
|
+
}
|
|
73
|
+
// イベントハンドラを追加します。
|
|
74
|
+
element.addEventListener("mousedown", handleMouseDown);
|
|
75
|
+
element.addEventListener("mousemove", handleMouseMove);
|
|
76
|
+
element.addEventListener("mouseup", handleMouseUp);
|
|
77
|
+
element.addEventListener("mouseleave", handleMouseLeave);
|
|
78
|
+
|
|
79
|
+
// イベントリスナーを削除するクリーンアップ関数を返します。
|
|
80
|
+
return () => {
|
|
81
|
+
element.removeEventListener("mousedown", handleMouseDown);
|
|
82
|
+
element.removeEventListener("mousemove", handleMouseMove);
|
|
83
|
+
element.removeEventListener("mouseup", handleMouseUp);
|
|
84
|
+
element.removeEventListener("mouseleave", handleMouseLeave);
|
|
85
|
+
element.style.transform = null;
|
|
86
|
+
};
|
|
87
|
+
}, [isMovable, blockRef, position, onPositionChange]); // 依存配列に isMovable を含めます
|
|
88
|
+
};
|
|
@@ -8,28 +8,31 @@ export {
|
|
|
8
8
|
useFontawesomeIframe,
|
|
9
9
|
} from "./customFooks";
|
|
10
10
|
|
|
11
|
-
|
|
12
|
-
export {
|
|
13
|
-
|
|
14
|
-
space_prm,
|
|
15
|
-
max_width_prm,
|
|
16
|
-
width_prm,
|
|
17
|
-
align_prm,
|
|
18
|
-
convertToScss,
|
|
19
|
-
borderProperty,
|
|
20
|
-
} from "./cssPropertes";
|
|
11
|
+
//ボックスシャドーを設定するコントロール
|
|
12
|
+
export { ShadowElm } from "./ShadowElm";
|
|
13
|
+
export { default as ShadowCtrl } from "./ShadowCtrl";
|
|
21
14
|
|
|
22
15
|
//疑似要素を設定するコントロール
|
|
23
|
-
export {
|
|
16
|
+
export { Arrow } from "./Arrow";
|
|
17
|
+
export { default as PseudoElm } from "./PseudoElm";
|
|
24
18
|
|
|
25
19
|
//メディアライブラリから複数の画像を選択するコントロール
|
|
26
20
|
export { MultiImageSelect } from "./mediaUpload";
|
|
27
21
|
|
|
28
|
-
//ボックスシャドーを設定するコントロール
|
|
29
|
-
export { default as ShadowStyle, ShadowElm } from "./ShadowStyle";
|
|
30
|
-
|
|
31
22
|
//ブロックのドラッガブルを設定するコントロール
|
|
32
|
-
export { default as DraggableBox
|
|
23
|
+
export { default as DraggableBox } from "./DraggableBox";
|
|
24
|
+
export { useDraggingMove } from "./draggingFook";
|
|
33
25
|
|
|
34
26
|
//ブロックをlazy Loadさせるためのラッパーモジュール
|
|
35
27
|
export { default as BlockEditWrapper } from "./BlockEditWrapper";
|
|
28
|
+
|
|
29
|
+
//styled-componet用のcssプロパティ生成関数
|
|
30
|
+
export {
|
|
31
|
+
radius_prm,
|
|
32
|
+
space_prm,
|
|
33
|
+
max_width_prm,
|
|
34
|
+
width_prm,
|
|
35
|
+
align_prm,
|
|
36
|
+
convertToScss,
|
|
37
|
+
borderProperty,
|
|
38
|
+
} from "./cssPropertes";
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import { MediaUpload, MediaUploadCheck } from "@wordpress/block-editor";
|
|
2
|
+
import { __ } from "@wordpress/i18n";
|
|
3
|
+
import { Button, PanelBody } from "@wordpress/components";
|
|
4
|
+
|
|
5
|
+
export function MultiImageSelect(props) {
|
|
6
|
+
const { attributes, label } = props;
|
|
7
|
+
const { mediaID, media } = attributes;
|
|
8
|
+
|
|
9
|
+
//URL の配列から画像を生成
|
|
10
|
+
const getImages = (media) => {
|
|
11
|
+
//メディアオブジェクトの配列をループ処理
|
|
12
|
+
let imagesArray = media.map((image, index) => {
|
|
13
|
+
return (
|
|
14
|
+
<figure key={index}>
|
|
15
|
+
<img src={image.url} className="image" alt="アップロード画像" />
|
|
16
|
+
<figcaption className="block-image-caption">
|
|
17
|
+
{image.caption ? image.caption : ""}
|
|
18
|
+
</figcaption>
|
|
19
|
+
</figure>
|
|
20
|
+
);
|
|
21
|
+
});
|
|
22
|
+
return imagesArray;
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
//メディアライブラリを開くボタンをレンダリングする関数
|
|
26
|
+
const getImageButton = (open) => {
|
|
27
|
+
if (media.length > 0) {
|
|
28
|
+
return (
|
|
29
|
+
<div key="media-container" onClick={open} className="block-container">
|
|
30
|
+
{getImages(media)}
|
|
31
|
+
</div>
|
|
32
|
+
);
|
|
33
|
+
} else {
|
|
34
|
+
return (
|
|
35
|
+
<div key="media-container" className="button-container">
|
|
36
|
+
<Button onClick={open} className="button button-large">
|
|
37
|
+
{__("Image Upload", "slide-blocks")}
|
|
38
|
+
</Button>
|
|
39
|
+
</div>
|
|
40
|
+
);
|
|
41
|
+
}
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
return (
|
|
45
|
+
<PanelBody title={label} initialOpen={true} className="itmar_image_display">
|
|
46
|
+
<MediaUploadCheck>
|
|
47
|
+
<MediaUpload
|
|
48
|
+
multiple={true}
|
|
49
|
+
gallery={true} //追加
|
|
50
|
+
onSelect={(media) => props.onSelectChange(media)}
|
|
51
|
+
allowedTypes={["image"]}
|
|
52
|
+
value={mediaID}
|
|
53
|
+
render={({ open }) => getImageButton(open)}
|
|
54
|
+
/>
|
|
55
|
+
</MediaUploadCheck>
|
|
56
|
+
{media.length != 0 && ( //メディアオブジェクト(配列の長さ)で判定
|
|
57
|
+
<MediaUploadCheck>
|
|
58
|
+
<Button
|
|
59
|
+
onClick={() => props.onAllDelete()}
|
|
60
|
+
variant="secondary"
|
|
61
|
+
isDestructive
|
|
62
|
+
className="removeImage"
|
|
63
|
+
>
|
|
64
|
+
{__("Delete All", "slide-blocks")}
|
|
65
|
+
</Button>
|
|
66
|
+
</MediaUploadCheck>
|
|
67
|
+
)}
|
|
68
|
+
</PanelBody>
|
|
69
|
+
);
|
|
70
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
const defaultConfig = require("@wordpress/scripts/config/webpack.config");
|
|
2
|
+
|
|
3
|
+
// オリジナルのoptimizationをカスタマイズ
|
|
4
|
+
module.exports = {
|
|
5
|
+
...defaultConfig,
|
|
6
|
+
output: {
|
|
7
|
+
...defaultConfig.output,
|
|
8
|
+
//libraryTarget: "commonjs2",
|
|
9
|
+
libraryTarget: "umd",
|
|
10
|
+
//globalObject: "this",
|
|
11
|
+
},
|
|
12
|
+
module: {
|
|
13
|
+
...defaultConfig.module,
|
|
14
|
+
rules: [
|
|
15
|
+
...defaultConfig.module.rules,
|
|
16
|
+
{
|
|
17
|
+
test: /\.jsx?$/,
|
|
18
|
+
exclude: /node_modules/,
|
|
19
|
+
use: {
|
|
20
|
+
loader: "babel-loader",
|
|
21
|
+
options: {
|
|
22
|
+
presets: ["@babel/preset-react"],
|
|
23
|
+
},
|
|
24
|
+
},
|
|
25
|
+
},
|
|
26
|
+
],
|
|
27
|
+
},
|
|
28
|
+
};
|
package/DraggableBox.js
DELETED
|
@@ -1,139 +0,0 @@
|
|
|
1
|
-
import { useEffect, useRef } from '@wordpress/element';
|
|
2
|
-
import { __ } from '@wordpress/i18n';
|
|
3
|
-
|
|
4
|
-
import {
|
|
5
|
-
Button,
|
|
6
|
-
PanelBody,
|
|
7
|
-
PanelRow,
|
|
8
|
-
__experimentalUnitControl as UnitControl
|
|
9
|
-
} from '@wordpress/components';
|
|
10
|
-
|
|
11
|
-
export const useDraggingMove = (isMovable, blockRef, position, onPositionChange) => {
|
|
12
|
-
const elmposition = useRef({ x: 0, y: 0 });
|
|
13
|
-
const isDragging = useRef(false);
|
|
14
|
-
const mousePosition = useRef({ x: 0, y: 0 });
|
|
15
|
-
|
|
16
|
-
useEffect(() => {
|
|
17
|
-
const element = blockRef.current;
|
|
18
|
-
|
|
19
|
-
if (!isMovable) {
|
|
20
|
-
if (element) {
|
|
21
|
-
element.classList.remove('itmar_isDraggable');//移動カーソル表示クラス削除
|
|
22
|
-
}
|
|
23
|
-
return; // 移動許可がある場合のみ、後続のロジックを実行
|
|
24
|
-
}
|
|
25
|
-
//positionの変化に合わせて現在位置を変更
|
|
26
|
-
const pos_value_x = position.x.match(/(-?\d+)([%a-zA-Z]+)/);
|
|
27
|
-
const pos_value_y = position.y.match(/(-?\d+)([%a-zA-Z]+)/);
|
|
28
|
-
elmposition.current = { x: parseInt(pos_value_x[1]), y: parseInt(pos_value_y[1]) }
|
|
29
|
-
|
|
30
|
-
//イベントハンドラ
|
|
31
|
-
const handleMouseDown = (event) => {
|
|
32
|
-
// 移動カーソル表示クラス名を追加します。
|
|
33
|
-
element.classList.add('itmar_isDraggable');
|
|
34
|
-
//ドラッグの開始フラグオン
|
|
35
|
-
isDragging.current = true;
|
|
36
|
-
//ドラッグ開始の絶対位置
|
|
37
|
-
mousePosition.current = { x: event.clientX, y: event.clientY };
|
|
38
|
-
};
|
|
39
|
-
|
|
40
|
-
const handleMouseMove = (event) => {
|
|
41
|
-
if (!isDragging.current) return;//ドラッグ中でなければ処理を中止
|
|
42
|
-
const dx = event.clientX - mousePosition.current.x;
|
|
43
|
-
const dy = event.clientY - mousePosition.current.y;
|
|
44
|
-
//ドラッグ後の位置を保存
|
|
45
|
-
const newPosition = {
|
|
46
|
-
x: elmposition.current.x + dx,
|
|
47
|
-
y: elmposition.current.y + dy,
|
|
48
|
-
};
|
|
49
|
-
elmposition.current = newPosition;
|
|
50
|
-
mousePosition.current = { x: event.clientX, y: event.clientY };//マウス位置の保存
|
|
51
|
-
//ドラッグによるブロックの一時的移動
|
|
52
|
-
element.style.transform = `translate(${elmposition.current.x}px, ${elmposition.current.y}px)`;
|
|
53
|
-
};
|
|
54
|
-
|
|
55
|
-
const handleMouseUp = () => {
|
|
56
|
-
isDragging.current = false;
|
|
57
|
-
element.style.transform = null;
|
|
58
|
-
//呼出しもとに要素の位置を返す
|
|
59
|
-
onPositionChange({ x: `${elmposition.current.x}px`, y: `${elmposition.current.y}px` });
|
|
60
|
-
};
|
|
61
|
-
const handleMouseLeave = () => {
|
|
62
|
-
isDragging.current = false;
|
|
63
|
-
};
|
|
64
|
-
|
|
65
|
-
if (element) {
|
|
66
|
-
// クラス名を追加します。
|
|
67
|
-
element.classList.add('itmar_isDraggable');
|
|
68
|
-
}
|
|
69
|
-
// イベントハンドラを追加します。
|
|
70
|
-
element.addEventListener('mousedown', handleMouseDown);
|
|
71
|
-
element.addEventListener('mousemove', handleMouseMove);
|
|
72
|
-
element.addEventListener('mouseup', handleMouseUp);
|
|
73
|
-
element.addEventListener('mouseleave', handleMouseLeave);
|
|
74
|
-
|
|
75
|
-
// イベントリスナーを削除するクリーンアップ関数を返します。
|
|
76
|
-
return () => {
|
|
77
|
-
element.removeEventListener('mousedown', handleMouseDown);
|
|
78
|
-
element.removeEventListener('mousemove', handleMouseMove);
|
|
79
|
-
element.removeEventListener('mouseup', handleMouseUp);
|
|
80
|
-
element.removeEventListener('mouseleave', handleMouseLeave);
|
|
81
|
-
element.style.transform = null;
|
|
82
|
-
};
|
|
83
|
-
}, [isMovable, blockRef, position, onPositionChange]); // 依存配列に isMovable を含めます
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
export default function DraggableBox(props) {
|
|
87
|
-
|
|
88
|
-
const position = props.attributes
|
|
89
|
-
|
|
90
|
-
//インスペクター内のコントロールからの移動操作
|
|
91
|
-
const chagePosition = (value, cordinate) => {
|
|
92
|
-
if (value) {
|
|
93
|
-
const newPos = { ...position, [cordinate]: value };
|
|
94
|
-
props.onPositionChange(newPos);
|
|
95
|
-
}
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
//リセット
|
|
99
|
-
const resetPos = () => {
|
|
100
|
-
const newPos = { "x": "0px", "y": "0px" };
|
|
101
|
-
props.onPositionChange(newPos);
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
return (
|
|
105
|
-
<>
|
|
106
|
-
<PanelBody
|
|
107
|
-
title={__("Position Setting", 'block-collections')}
|
|
108
|
-
initialOpen={true}
|
|
109
|
-
>
|
|
110
|
-
<PanelRow
|
|
111
|
-
className='distance_row'
|
|
112
|
-
>
|
|
113
|
-
<UnitControl
|
|
114
|
-
dragDirection="e"
|
|
115
|
-
onChange={(value) => chagePosition(value, 'x')}
|
|
116
|
-
label={__("Vertical", 'block-collections')}
|
|
117
|
-
value={position?.x || 0}
|
|
118
|
-
/>
|
|
119
|
-
<UnitControl
|
|
120
|
-
dragDirection="e"
|
|
121
|
-
onChange={(value) => chagePosition(value, 'y')}
|
|
122
|
-
label={__("Horizen", 'block-collections')}
|
|
123
|
-
value={position?.y || 0}
|
|
124
|
-
/>
|
|
125
|
-
</PanelRow>
|
|
126
|
-
<PanelRow
|
|
127
|
-
className='reset_row'
|
|
128
|
-
>
|
|
129
|
-
<Button
|
|
130
|
-
variant="secondary"
|
|
131
|
-
onClick={() => resetPos()}
|
|
132
|
-
>
|
|
133
|
-
{__("Reset", 'block-collections')}
|
|
134
|
-
</Button>
|
|
135
|
-
</PanelRow>
|
|
136
|
-
</PanelBody>
|
|
137
|
-
</>
|
|
138
|
-
)
|
|
139
|
-
}
|
package/mediaUpload.js
DELETED
|
@@ -1,90 +0,0 @@
|
|
|
1
|
-
import { MediaUpload, MediaUploadCheck } from '@wordpress/block-editor';
|
|
2
|
-
import { __ } from '@wordpress/i18n';
|
|
3
|
-
import {
|
|
4
|
-
Button,
|
|
5
|
-
PanelBody,
|
|
6
|
-
} from '@wordpress/components';
|
|
7
|
-
|
|
8
|
-
export function MultiImageSelect(props) {
|
|
9
|
-
const {
|
|
10
|
-
attributes,
|
|
11
|
-
label
|
|
12
|
-
} = props;
|
|
13
|
-
const {
|
|
14
|
-
mediaID,
|
|
15
|
-
media
|
|
16
|
-
} = attributes;
|
|
17
|
-
|
|
18
|
-
//URL の配列から画像を生成
|
|
19
|
-
const getImages = (media) => {
|
|
20
|
-
//メディアオブジェクトの配列をループ処理
|
|
21
|
-
let imagesArray = media.map((image) => {
|
|
22
|
-
return (
|
|
23
|
-
<figure>
|
|
24
|
-
<img
|
|
25
|
-
src={image.url}
|
|
26
|
-
className="image"
|
|
27
|
-
alt="アップロード画像"
|
|
28
|
-
/>
|
|
29
|
-
<figcaption className="block-image-caption">
|
|
30
|
-
{image.caption ? image.caption : ''}
|
|
31
|
-
</figcaption>
|
|
32
|
-
</figure>
|
|
33
|
-
);
|
|
34
|
-
});
|
|
35
|
-
return imagesArray;
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
//メディアライブラリを開くボタンをレンダリングする関数
|
|
39
|
-
const getImageButton = (open) => {
|
|
40
|
-
if (media.length > 0) {
|
|
41
|
-
return (
|
|
42
|
-
<div onClick={open} className="block-container">
|
|
43
|
-
{getImages(media)}
|
|
44
|
-
</div>
|
|
45
|
-
)
|
|
46
|
-
}
|
|
47
|
-
else {
|
|
48
|
-
return (
|
|
49
|
-
<div className="button-container">
|
|
50
|
-
<Button
|
|
51
|
-
onClick={open}
|
|
52
|
-
className="button button-large"
|
|
53
|
-
>
|
|
54
|
-
{__("Image Upload", 'slide-blocks')}
|
|
55
|
-
</Button>
|
|
56
|
-
</div>
|
|
57
|
-
);
|
|
58
|
-
}
|
|
59
|
-
};
|
|
60
|
-
|
|
61
|
-
return (
|
|
62
|
-
<PanelBody
|
|
63
|
-
title={label}
|
|
64
|
-
initialOpen={true}
|
|
65
|
-
className='itmar_image_display'
|
|
66
|
-
>
|
|
67
|
-
<MediaUploadCheck>
|
|
68
|
-
<MediaUpload
|
|
69
|
-
multiple={true}
|
|
70
|
-
gallery={true} //追加
|
|
71
|
-
onSelect={(media) => props.onSelectChange(media)}
|
|
72
|
-
allowedTypes={['image']}
|
|
73
|
-
value={mediaID}
|
|
74
|
-
render={({ open }) => getImageButton(open)}
|
|
75
|
-
/>
|
|
76
|
-
</MediaUploadCheck>
|
|
77
|
-
{media.length != 0 && //メディアオブジェクト(配列の長さ)で判定
|
|
78
|
-
<MediaUploadCheck>
|
|
79
|
-
<Button
|
|
80
|
-
onClick={() => props.onAllDelete()}
|
|
81
|
-
variant="secondary"
|
|
82
|
-
isDestructive
|
|
83
|
-
className="removeImage">
|
|
84
|
-
{__("Delete All", 'slide-blocks')}
|
|
85
|
-
</Button>
|
|
86
|
-
</MediaUploadCheck>
|
|
87
|
-
}
|
|
88
|
-
</PanelBody>
|
|
89
|
-
);
|
|
90
|
-
}
|