itmar-block-packages 1.3.17 → 1.3.19
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 +90 -12
- package/build/index.asset.php +1 -1
- package/build/index.js +3 -3
- package/package.json +1 -1
- package/src/BlockPlace.js +159 -158
- package/src/cssPropertes.js +7 -7
- package/src/customFooks.js +24 -0
- package/src/index.js +3 -0
- package/src/wordpressApi.js +131 -33
package/src/wordpressApi.js
CHANGED
|
@@ -9,9 +9,9 @@ import apiFetch from "@wordpress/api-fetch";
|
|
|
9
9
|
|
|
10
10
|
//const _ = require("lodash");
|
|
11
11
|
|
|
12
|
-
export const
|
|
12
|
+
export const restFetchData = async (path) => {
|
|
13
13
|
try {
|
|
14
|
-
const ret_data = await
|
|
14
|
+
const ret_data = await apiFetch({ path: path });
|
|
15
15
|
return ret_data;
|
|
16
16
|
} catch (error) {
|
|
17
17
|
console.error("Error fetching data:", error.message);
|
|
@@ -56,11 +56,13 @@ const ChoiceControl = (props) => {
|
|
|
56
56
|
const {
|
|
57
57
|
selectedSlug,
|
|
58
58
|
choiceItems,
|
|
59
|
+
dispTaxonomies,
|
|
59
60
|
type,
|
|
60
61
|
blockMap,
|
|
61
62
|
textDomain,
|
|
62
63
|
fetchFunction,
|
|
63
64
|
} = props;
|
|
65
|
+
|
|
64
66
|
const [choices, setChoices] = useState([]);
|
|
65
67
|
useEffect(() => {
|
|
66
68
|
if (!selectedSlug) return; //ポストタイプのスラッグが選択されていないときは処理終了
|
|
@@ -76,17 +78,17 @@ const ChoiceControl = (props) => {
|
|
|
76
78
|
}, [selectedSlug, fetchFunction]);
|
|
77
79
|
|
|
78
80
|
//選択肢が変わったときに選択されている項目の配列内容を更新するハンドラ
|
|
79
|
-
const handleChoiceChange = (checked, target) => {
|
|
81
|
+
const handleChoiceChange = (checked, target, setItems) => {
|
|
80
82
|
if (checked) {
|
|
81
83
|
// targetが重複していない場合のみ追加
|
|
82
|
-
if (!
|
|
83
|
-
return [...
|
|
84
|
+
if (!setItems.some((item) => _.isEqual(item, target))) {
|
|
85
|
+
return [...setItems, target];
|
|
84
86
|
}
|
|
85
87
|
} else {
|
|
86
88
|
// targetを配列から削除
|
|
87
|
-
return
|
|
89
|
+
return setItems.filter((item) => !_.isEqual(item, target));
|
|
88
90
|
}
|
|
89
|
-
return
|
|
91
|
+
return setItems;
|
|
90
92
|
};
|
|
91
93
|
|
|
92
94
|
//階層化されたカスタムフィールドのフィールド名を表示する関数
|
|
@@ -126,7 +128,11 @@ const ChoiceControl = (props) => {
|
|
|
126
128
|
(choiceField) => choiceField === fieldName
|
|
127
129
|
)}
|
|
128
130
|
onChange={(checked) => {
|
|
129
|
-
const newChoiceFields = handleChoiceChange(
|
|
131
|
+
const newChoiceFields = handleChoiceChange(
|
|
132
|
+
checked,
|
|
133
|
+
fieldName,
|
|
134
|
+
choiceItems
|
|
135
|
+
);
|
|
130
136
|
props.onChange(newChoiceFields);
|
|
131
137
|
}}
|
|
132
138
|
/>
|
|
@@ -156,7 +162,21 @@ const ChoiceControl = (props) => {
|
|
|
156
162
|
choices.map((choice, index) => {
|
|
157
163
|
return (
|
|
158
164
|
<div key={index} className="term_section">
|
|
159
|
-
<div className="tax_label">
|
|
165
|
+
<div className="tax_label">
|
|
166
|
+
{choice.name}
|
|
167
|
+
<ToggleControl
|
|
168
|
+
label={__("Display", "block-collections")}
|
|
169
|
+
checked={dispTaxonomies.some((tax) => tax === choice.slug)}
|
|
170
|
+
onChange={(checked) => {
|
|
171
|
+
const newChoiceFields = handleChoiceChange(
|
|
172
|
+
checked,
|
|
173
|
+
choice.slug,
|
|
174
|
+
dispTaxonomies
|
|
175
|
+
);
|
|
176
|
+
props.onSetDispTax(newChoiceFields);
|
|
177
|
+
}}
|
|
178
|
+
/>
|
|
179
|
+
</div>
|
|
160
180
|
{choice.terms.map((term, index) => {
|
|
161
181
|
return (
|
|
162
182
|
<CheckboxControl
|
|
@@ -172,11 +192,12 @@ const ChoiceControl = (props) => {
|
|
|
172
192
|
onChange={(checked) => {
|
|
173
193
|
const target = {
|
|
174
194
|
taxonomy: choice.slug,
|
|
175
|
-
term: { id: term.id, slug: term.slug },
|
|
195
|
+
term: { id: term.id, slug: term.slug, name: term.name },
|
|
176
196
|
};
|
|
177
197
|
const newChoiceTerms = handleChoiceChange(
|
|
178
198
|
checked,
|
|
179
|
-
target
|
|
199
|
+
target,
|
|
200
|
+
choiceItems
|
|
180
201
|
);
|
|
181
202
|
props.onChange(newChoiceTerms);
|
|
182
203
|
}}
|
|
@@ -212,7 +233,8 @@ const ChoiceControl = (props) => {
|
|
|
212
233
|
onChange={(checked) => {
|
|
213
234
|
const newChoiceFields = handleChoiceChange(
|
|
214
235
|
checked,
|
|
215
|
-
"title"
|
|
236
|
+
"title",
|
|
237
|
+
choiceItems
|
|
216
238
|
);
|
|
217
239
|
props.onChange(newChoiceFields);
|
|
218
240
|
}}
|
|
@@ -226,7 +248,11 @@ const ChoiceControl = (props) => {
|
|
|
226
248
|
(choiceField) => choiceField === "date"
|
|
227
249
|
)}
|
|
228
250
|
onChange={(checked) => {
|
|
229
|
-
const newChoiceFields = handleChoiceChange(
|
|
251
|
+
const newChoiceFields = handleChoiceChange(
|
|
252
|
+
checked,
|
|
253
|
+
"date",
|
|
254
|
+
choiceItems
|
|
255
|
+
);
|
|
230
256
|
props.onChange(newChoiceFields);
|
|
231
257
|
}}
|
|
232
258
|
/>
|
|
@@ -241,7 +267,8 @@ const ChoiceControl = (props) => {
|
|
|
241
267
|
onChange={(checked) => {
|
|
242
268
|
const newChoiceFields = handleChoiceChange(
|
|
243
269
|
checked,
|
|
244
|
-
"excerpt"
|
|
270
|
+
"excerpt",
|
|
271
|
+
choiceItems
|
|
245
272
|
);
|
|
246
273
|
props.onChange(newChoiceFields);
|
|
247
274
|
}}
|
|
@@ -257,36 +284,80 @@ const ChoiceControl = (props) => {
|
|
|
257
284
|
onChange={(checked) => {
|
|
258
285
|
const newChoiceFields = handleChoiceChange(
|
|
259
286
|
checked,
|
|
260
|
-
"featured_media"
|
|
287
|
+
"featured_media",
|
|
288
|
+
choiceItems
|
|
261
289
|
);
|
|
262
290
|
props.onChange(newChoiceFields);
|
|
263
291
|
}}
|
|
264
292
|
/>
|
|
265
293
|
)}
|
|
294
|
+
{choice.link && (
|
|
295
|
+
<div className="itmar_custom_field_set">
|
|
296
|
+
<ToggleControl
|
|
297
|
+
className="field_choice"
|
|
298
|
+
label={__("Single Page Link", "block-collections")}
|
|
299
|
+
checked={choiceItems.some(
|
|
300
|
+
(choiceField) => choiceField === "link"
|
|
301
|
+
)}
|
|
302
|
+
onChange={(checked) => {
|
|
303
|
+
const newChoiceFields = handleChoiceChange(
|
|
304
|
+
checked,
|
|
305
|
+
"link",
|
|
306
|
+
choiceItems
|
|
307
|
+
);
|
|
308
|
+
props.onChange(newChoiceFields);
|
|
309
|
+
}}
|
|
310
|
+
/>
|
|
311
|
+
<ComboboxControl
|
|
312
|
+
options={[
|
|
313
|
+
{
|
|
314
|
+
value: "itmar/design-button",
|
|
315
|
+
label: "itmar/design-button",
|
|
316
|
+
},
|
|
317
|
+
{
|
|
318
|
+
value: "itmar/design-title",
|
|
319
|
+
label: "itmar/design-title",
|
|
320
|
+
},
|
|
321
|
+
]}
|
|
322
|
+
value={blockMap["link"]}
|
|
323
|
+
onChange={(newValue) => {
|
|
324
|
+
const newBlockMap = {
|
|
325
|
+
...blockMap,
|
|
326
|
+
link: newValue,
|
|
327
|
+
};
|
|
328
|
+
props.onBlockMapChange(newBlockMap);
|
|
329
|
+
}}
|
|
330
|
+
/>
|
|
331
|
+
<p>
|
|
332
|
+
{__(
|
|
333
|
+
"If no block is specified, a link will be set to the parent block, Design Group.",
|
|
334
|
+
"block-collections"
|
|
335
|
+
)}
|
|
336
|
+
</p>
|
|
337
|
+
</div>
|
|
338
|
+
)}
|
|
266
339
|
{(metaFlg || acfFlg) && (
|
|
267
340
|
<>
|
|
268
341
|
<div className="custom_field_label">
|
|
269
342
|
{__("Custom Field", "block-collections")}
|
|
270
343
|
</div>
|
|
271
344
|
<div className="custom_field_area">
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
})}
|
|
289
|
-
</div>
|
|
345
|
+
{dispCustumFields({
|
|
346
|
+
...Object.entries(choice.meta).reduce(
|
|
347
|
+
(acc, [key, value]) => ({
|
|
348
|
+
...acc,
|
|
349
|
+
[`meta_${key}`]: value,
|
|
350
|
+
}),
|
|
351
|
+
{}
|
|
352
|
+
),
|
|
353
|
+
...Object.entries(choice.acf).reduce(
|
|
354
|
+
(acc, [key, value]) => ({
|
|
355
|
+
...acc,
|
|
356
|
+
[`acf_${key}`]: value,
|
|
357
|
+
}),
|
|
358
|
+
{}
|
|
359
|
+
),
|
|
360
|
+
})}
|
|
290
361
|
</div>
|
|
291
362
|
</>
|
|
292
363
|
)}
|
|
@@ -381,6 +452,32 @@ export const restTaxonomies = async (post_type) => {
|
|
|
381
452
|
return taxonomyObjects;
|
|
382
453
|
};
|
|
383
454
|
|
|
455
|
+
//タームの文字列化
|
|
456
|
+
export const termToDispObj = (terms, connectString) => {
|
|
457
|
+
// taxonomyごとにterm.nameをまとめる
|
|
458
|
+
const result = terms.reduce((acc, item) => {
|
|
459
|
+
const taxonomy = item.taxonomy;
|
|
460
|
+
const termName = item.term.name;
|
|
461
|
+
|
|
462
|
+
// taxonomyがまだ存在しない場合は初期化
|
|
463
|
+
if (!acc[taxonomy]) {
|
|
464
|
+
acc[taxonomy] = [];
|
|
465
|
+
}
|
|
466
|
+
|
|
467
|
+
// term.nameを配列に追加
|
|
468
|
+
acc[taxonomy].push(termName);
|
|
469
|
+
|
|
470
|
+
return acc;
|
|
471
|
+
}, {});
|
|
472
|
+
|
|
473
|
+
// 各taxonomyの配列を connectString でつなげて文字列化
|
|
474
|
+
for (const taxonomy in result) {
|
|
475
|
+
result[taxonomy] = result[taxonomy].join(connectString);
|
|
476
|
+
}
|
|
477
|
+
|
|
478
|
+
return result;
|
|
479
|
+
};
|
|
480
|
+
|
|
384
481
|
//フィールド情報取得RestAPI関数
|
|
385
482
|
export const restFieldes = async (rest_base) => {
|
|
386
483
|
//投稿データに以下のフィールドが含まれているかを調べる
|
|
@@ -389,6 +486,7 @@ export const restFieldes = async (rest_base) => {
|
|
|
389
486
|
"date",
|
|
390
487
|
"excerpt",
|
|
391
488
|
"featured_media",
|
|
489
|
+
"link",
|
|
392
490
|
"meta",
|
|
393
491
|
"acf",
|
|
394
492
|
];
|