itmar-block-packages 1.1.0 → 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.
@@ -1,4 +1,7 @@
1
- import { css } from "styled-components";
1
+ // sideの最初の文字を大文字にする関数
2
+ const capitalizeFirstLetter = (string) => {
3
+ return string.charAt(0).toUpperCase() + string.slice(1);
4
+ };
2
5
 
3
6
  //角丸のパラメータを返す
4
7
  export const radius_prm = (radius) => {
@@ -19,15 +22,40 @@ export const space_prm = (space) => {
19
22
  : "";
20
23
  return ret_space_prm;
21
24
  };
25
+ //positionのオブジェクトを返します
26
+ export const position_prm = (pos, type) => {
27
+ if (pos) {
28
+ const resetVertBase = pos.vertBase === "top" ? "bottom" : "top";
29
+ const resetHorBase = pos.horBase === "left" ? "right" : "left";
30
+ const ret_pos_prm =
31
+ pos && (type === "absolute" || type === "fixed" || type === "sticky")
32
+ ? `
33
+ ${pos.vertBase}: ${pos.vertValue};
34
+ ${pos.horBase}: ${pos.horValue};
35
+ ${resetVertBase}: auto;
36
+ ${resetHorBase}: auto;
37
+ ${
38
+ type === "fixed" || type === "sticky"
39
+ ? "margin-block-start:0;z-index: 50;"
40
+ : "z-index: auto;"
41
+ }
42
+ `
43
+ : "";
44
+ return ret_pos_prm;
45
+ }
46
+ return null;
47
+ };
22
48
  //ブロック幅を返す
23
49
  export const max_width_prm = (width, free_val) => {
24
50
  const ret_width_prm =
25
51
  width === "wideSize"
26
- ? " width: 100%; max-width: var(--wp--style--global--wide-size);"
52
+ ? "width: 100%; max-width: var(--wp--style--global--wide-size);"
27
53
  : width === "contentSize"
28
- ? " width: 100%; max-width: var(--wp--style--global--content-size);"
54
+ ? "width: 100%; max-width: var(--wp--style--global--content-size);"
29
55
  : width === "free"
30
- ? ` width: 100%; max-width: ${free_val}px; `
56
+ ? `width: 100%; max-width: ${free_val}px;`
57
+ : width === "full"
58
+ ? "width: 100%; max-width: 100%;"
31
59
  : " width: fit-content;";
32
60
  return ret_width_prm;
33
61
  };
@@ -43,6 +71,12 @@ export const width_prm = (width, free_val) => {
43
71
  : " width: fit-content;";
44
72
  return ret_width_prm;
45
73
  };
74
+
75
+ export const height_prm = (height) => {
76
+ const ret_height_prm =
77
+ height === "fit" ? " height: fit-content;" : "height: 100%;";
78
+ return ret_height_prm;
79
+ };
46
80
  //配置を返す
47
81
  export const align_prm = (align) => {
48
82
  const ret_align_prm =
@@ -70,13 +104,12 @@ export const convertToScss = (styleObject) => {
70
104
  export const borderProperty = (borderObj) => {
71
105
  if (borderObj) {
72
106
  //borderObjがundefinedでない
73
-
74
107
  let keys = ["top", "bottom", "left", "right"];
75
108
  let ret_prop = null;
76
109
  let doesKeyExist = keys.some((key) => key in borderObj);
77
110
  if (doesKeyExist) {
78
111
  //'top', 'bottom', 'left', 'right'が別設定
79
- let cssString = "";
112
+ let cssObj = {};
80
113
  for (let side in borderObj) {
81
114
  const sideData = borderObj[side];
82
115
  const startsWithZero = String(sideData.width || "").match(/^0/);
@@ -85,29 +118,57 @@ export const borderProperty = (borderObj) => {
85
118
  continue;
86
119
  }
87
120
  const border_style = sideData.style || "solid";
88
- cssString += `border-${side}: ${sideData.width} ${border_style} ${sideData.color};\n`;
121
+ let camelCaseSide = `border${capitalizeFirstLetter(side)}`;
122
+ cssObj[
123
+ camelCaseSide
124
+ ] = `${sideData.width} ${border_style} ${sideData.color}`;
89
125
  }
90
- ret_prop = css`
91
- ${cssString}
92
- `;
126
+ ret_prop = cssObj;
93
127
  return ret_prop;
94
128
  } else {
95
129
  //同一のボーダー
96
130
  const startsWithZero = String(borderObj.width || "").match(/^0/);
97
-
98
131
  if (startsWithZero) {
99
- //widthが0ならnoneを返す
100
- return css`
101
- border: none;
102
- `;
132
+ //widthが0ならnullを返す
133
+ return null;
103
134
  }
104
135
  const border_style = borderObj.style || "solid";
105
- ret_prop = css`
106
- border: ${borderObj.width} ${border_style} ${borderObj.color};
107
- `;
136
+ ret_prop = {
137
+ border: `${borderObj.width} ${border_style} ${borderObj.color}`,
138
+ };
139
+
108
140
  return ret_prop;
109
141
  }
110
142
  } else {
111
143
  return null;
112
144
  }
113
145
  };
146
+
147
+ //角丸の設定
148
+ export const radiusProperty = (radiusObj) => {
149
+ const ret_prop =
150
+ radiusObj && Object.keys(radiusObj).length === 1
151
+ ? radiusObj.value
152
+ : `${(radiusObj && radiusObj.topLeft) || ""} ${
153
+ (radiusObj && radiusObj.topRight) || ""
154
+ } ${(radiusObj && radiusObj.bottomRight) || ""} ${
155
+ (radiusObj && radiusObj.bottomLeft) || ""
156
+ }`;
157
+ const ret_val = { borderRadius: ret_prop };
158
+ return ret_val;
159
+ };
160
+
161
+ //マージンの設定
162
+ export const marginProperty = (marginObj) => {
163
+ const ret_prop = `${marginObj.top} ${marginObj.right} ${marginObj.bottom} ${marginObj.left}`;
164
+
165
+ const ret_val = { margin: ret_prop };
166
+ return ret_val;
167
+ };
168
+ //パディングの設定
169
+ export function paddingProperty(paddingObj) {
170
+ const ret_prop = `${paddingObj.top} ${paddingObj.right} ${paddingObj.bottom} ${paddingObj.left}`;
171
+
172
+ const ret_val = { padding: ret_prop };
173
+ return ret_val;
174
+ }
package/src/index.js CHANGED
@@ -8,31 +8,60 @@ export {
8
8
  useFontawesomeIframe,
9
9
  } from "./customFooks";
10
10
 
11
+ //WordPressデータを取得するためのRestAPI
12
+ export {
13
+ fetchPagesOptions,
14
+ fetchArchiveOptions,
15
+ PageSelectControl,
16
+ ArchiveSelectControl,
17
+ } from "./wordpressApi";
18
+
19
+ //styled-componet用のcssプロパティ生成関数
20
+ export {
21
+ space_prm,
22
+ max_width_prm,
23
+ width_prm,
24
+ height_prm,
25
+ align_prm,
26
+ position_prm,
27
+ radius_prm,
28
+ convertToScss,
29
+ borderProperty,
30
+ radiusProperty,
31
+ marginProperty,
32
+ paddingProperty,
33
+ } from "./cssPropertes";
34
+
11
35
  //ボックスシャドーを設定するコントロール
12
- export { ShadowElm } from "./ShadowElm";
13
- export { default as ShadowCtrl } from "./ShadowCtrl";
36
+ export { default as ShadowStyle, ShadowElm } from "./ShadowStyle";
14
37
 
15
38
  //疑似要素を設定するコントロール
16
- export { Arrow } from "./Arrow";
17
- export { default as PseudoElm } from "./PseudoElm";
39
+ export { default as PseudoElm, Arrow } from "./PseudoElm";
18
40
 
19
41
  //メディアライブラリから複数の画像を選択するコントロール
20
- export { MultiImageSelect } from "./mediaUpload";
42
+ export { SingleImageSelect, MultiImageSelect } from "./mediaUpload";
21
43
 
22
44
  //ブロックのドラッガブルを設定するコントロール
23
- export { default as DraggableBox } from "./DraggableBox";
24
- export { useDraggingMove } from "./draggingFook";
45
+ export { default as DraggableBox, useDraggingMove } from "./DraggableBox";
46
+
47
+ //アニメーションを設定するコントロール
48
+ export { default as AnimationBlock, anime_comp } from "./AnimationBlock";
49
+
50
+ //ブロックの配置を設定するコントロール
51
+ export { default as BlockPlace } from "./BlockPlace";
52
+ export { default as GridControls } from "./GridControls";
53
+
54
+ //DOM要素の表示を反転させるコントロール
55
+ export { default as ToggleElement } from "./ToggleElement";
56
+
57
+ //タイポグラフィーの設定をするコントロール
58
+ export { default as TypographyControls } from "./TypographyControls";
59
+
60
+ //アイコンの表示を設定するコントロール
61
+ export { default as IconSelectControl } from "./IconSelectControl";
25
62
 
26
63
  //ブロックをlazy Loadさせるためのラッパーモジュール
27
64
  export { default as BlockEditWrapper } from "./BlockEditWrapper";
28
65
 
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";
66
+ //色コードの変換関数
67
+ export { hslToRgb16, rgb16ToHsl, HexToRGB } from "./hslToRgb";
@@ -2,6 +2,51 @@ import { MediaUpload, MediaUploadCheck } from "@wordpress/block-editor";
2
2
  import { __ } from "@wordpress/i18n";
3
3
  import { Button, PanelBody } from "@wordpress/components";
4
4
 
5
+ export function SingleImageSelect(props) {
6
+ const { attributes } = props;
7
+ const { mediaID, media } = attributes;
8
+
9
+ //URL の配列から画像を生成
10
+ const getImage = (image) => {
11
+ //メディアオブジェクトの配列をループ処理
12
+ return (
13
+ <figure>
14
+ <img src={image.url} className="image" alt="アップロード画像" />
15
+ </figure>
16
+ );
17
+ };
18
+
19
+ //メディアライブラリを開くボタンをレンダリングする関数
20
+ const getImageButton = (open) => {
21
+ if (media) {
22
+ return (
23
+ <div onClick={open} className="block-container">
24
+ {getImage(media)}
25
+ </div>
26
+ );
27
+ } else {
28
+ return (
29
+ <div className="button-container">
30
+ <Button onClick={open} className="button button-large">
31
+ {__("Sel", "itmar_mv_blocks")}
32
+ </Button>
33
+ </div>
34
+ );
35
+ }
36
+ };
37
+
38
+ return (
39
+ <MediaUploadCheck>
40
+ <MediaUpload
41
+ onSelect={(media) => props.onSelectChange(media)}
42
+ allowedTypes={["image"]}
43
+ value={mediaID}
44
+ render={({ open }) => getImageButton(open)}
45
+ />
46
+ </MediaUploadCheck>
47
+ );
48
+ }
49
+
5
50
  export function MultiImageSelect(props) {
6
51
  const { attributes, label } = props;
7
52
  const { mediaID, media } = attributes;
@@ -0,0 +1,73 @@
1
+ import { useState, useEffect } from '@wordpress/element';
2
+ import { ComboboxControl } from '@wordpress/components';
3
+ import apiFetch from '@wordpress/api-fetch';
4
+
5
+ //コントロールのレンダリング関数
6
+ const SelectControl = ({ setAttributes, attributes, label, homeUrl, fetchOptions }) => {
7
+ const { selectedPageId } = attributes;
8
+ const [options, setOptions] = useState([]);
9
+
10
+ useEffect(() => {
11
+ const fetchData = async () => {
12
+ try {
13
+ const fetchedOptions = await fetchOptions(homeUrl);
14
+ setOptions(fetchedOptions);
15
+ } catch (error) {
16
+ console.error('Error fetching data:', error.message);
17
+ }
18
+ };
19
+
20
+ fetchData();
21
+ }, [fetchOptions]);
22
+
23
+ const handleChange = (selectedId) => {
24
+ const selectedPage = options.find(page => page.value === selectedId);
25
+ setAttributes({
26
+ selectedPageId: selectedId,
27
+ selectedPageUrl: selectedPage ? selectedPage.link : homeUrl
28
+ });
29
+ };
30
+
31
+ return (
32
+ <ComboboxControl
33
+ label={label}
34
+ options={options}
35
+ value={selectedPageId}
36
+ onChange={handleChange}
37
+ />
38
+ );
39
+ };
40
+
41
+ export const fetchPagesOptions = async (home_url) => {
42
+ const pages = await apiFetch({ path: '/wp/v2/pages' });
43
+ if (pages && !pages.some(page => page.id === -1)) {
44
+ pages.unshift({ id: -1, title: { rendered: 'ホーム' }, link: home_url });
45
+ }
46
+ return pages ? pages.map(page => ({
47
+ value: page.id,
48
+ label: page.title.rendered,
49
+ link: page.link
50
+ })) : [];
51
+ };
52
+
53
+ export const fetchArchiveOptions = async (home_url) => {
54
+ const response = await apiFetch({ path: '/wp/v2/types' });
55
+ let idCounter = 0;
56
+ return Object.keys(response).reduce((acc, key) => {
57
+ const postType = response[key];
58
+ if (postType.has_archive === true) {
59
+ acc.push({ value: idCounter++, link: `${home_url}/${postType.slug}`, label: postType.name });
60
+ } else if (typeof postType.has_archive === 'string') {
61
+ acc.push({ value: idCounter++, link: `${home_url}/${postType.has_archive}`, label: postType.name });
62
+ }
63
+ return acc;
64
+ }, []);
65
+ };
66
+
67
+ export const PageSelectControl = (props) => (
68
+ <SelectControl {...props} fetchOptions={fetchPagesOptions} />
69
+ );
70
+
71
+ export const ArchiveSelectControl = (props) => (
72
+ <SelectControl {...props} fetchOptions={fetchArchiveOptions} />
73
+ );
package/webpack.config.js CHANGED
@@ -1,28 +1,10 @@
1
1
  const defaultConfig = require("@wordpress/scripts/config/webpack.config");
2
2
 
3
- // オリジナルのoptimizationをカスタマイズ
3
+ // オリジナルをカスタマイズ
4
4
  module.exports = {
5
5
  ...defaultConfig,
6
6
  output: {
7
7
  ...defaultConfig.output,
8
- //libraryTarget: "commonjs2",
9
8
  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
9
  },
28
10
  };
package/babel.config.js DELETED
@@ -1,16 +0,0 @@
1
- module.exports = {
2
- presets: [
3
- // 他のプリセットがあればここに追加
4
- "@wordpress/default", // WordPressのデフォルトプリセットを追加
5
- ],
6
- plugins: [
7
- [
8
- "@babel/plugin-transform-modules-commonjs",
9
- {
10
- allowTopLevelThis: true,
11
- strict: false,
12
- strictMode: false,
13
- },
14
- ],
15
- ],
16
- };
package/src/Arrow.js DELETED
@@ -1,35 +0,0 @@
1
- import { __ } from "@wordpress/i18n";
2
- import { css } from "styled-components";
3
- import { RadioControl } from "@wordpress/components";
4
-
5
- // 矢印の向きに応じたスタイルを生成するヘルパー関数
6
- const arrowDirectionStyles = (direction) => {
7
- switch (direction) {
8
- case "left":
9
- return "transform: translate(-50%, -50%) rotate(-135deg);";
10
- case "right":
11
- return "transform: translate(-50%, -50%) rotate(45deg);";
12
- case "upper":
13
- return "transform: translate(-50%, -50%) rotate(-45deg);";
14
- case "under":
15
- return "transform: translate(-50%, -50%) rotate(135deg);";
16
- default:
17
- return "transform: translate(-50%, -50%) rotate(45deg);"; // default to 'down'
18
- }
19
- };
20
-
21
- // 矢印のスタイルを適用するコンポーネント
22
- export const Arrow = ({ direction = "down" }) => css`
23
- &::after {
24
- content: "";
25
- position: absolute;
26
- display: block;
27
- width: 15%;
28
- height: 15%;
29
- border-top: 3px solid var(--wp--preset--color--accent-2);
30
- border-right: 3px solid var(--wp--preset--color--accent-2);
31
- top: 50%;
32
- left: 50%;
33
- ${arrowDirectionStyles(direction)}
34
- }
35
- `;