itmar-block-packages 1.9.0 → 1.10.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 +5 -0
- package/build/index.asset.php +1 -1
- package/build/index.js +3 -3
- package/package.json +1 -1
- package/src/BrockInserter.js +247 -0
- package/src/MasonryControl.js +125 -0
- package/src/SwiperControl.js +265 -0
- package/src/customFooks.js +1 -0
- package/src/index.js +9 -0
- package/src/wordpressApi.js +197 -26
package/src/wordpressApi.js
CHANGED
|
@@ -68,8 +68,9 @@ const ChoiceControl = (props) => {
|
|
|
68
68
|
const fetchData = async () => {
|
|
69
69
|
try {
|
|
70
70
|
const fetchChoices = await fetchFunction(selectedSlug);
|
|
71
|
-
|
|
72
71
|
setChoices(fetchChoices);
|
|
72
|
+
//指定の投稿タイプに含まれないフィールドを削除する
|
|
73
|
+
pruneChoiceItemsByObjectKeys(fetchChoices[0], choiceItems);
|
|
73
74
|
} catch (error) {
|
|
74
75
|
console.error("Error fetching data:", error.message);
|
|
75
76
|
}
|
|
@@ -90,22 +91,78 @@ const ChoiceControl = (props) => {
|
|
|
90
91
|
}
|
|
91
92
|
return setItems;
|
|
92
93
|
};
|
|
94
|
+
/**
|
|
95
|
+
* dataObj のキー一覧を「choiceItems と比較する形」に変換して Set で返す
|
|
96
|
+
* - 通常キー: そのまま
|
|
97
|
+
* - acf / meta: 子キーに `${parent}_` を付けたもの(例: acf_relate_url, meta_footnotes)
|
|
98
|
+
*/
|
|
99
|
+
function buildComparableKeySet(dataObj) {
|
|
100
|
+
const keySet = new Set();
|
|
101
|
+
|
|
102
|
+
if (!dataObj || typeof dataObj !== "object") return keySet;
|
|
103
|
+
|
|
104
|
+
for (const [key, val] of Object.entries(dataObj)) {
|
|
105
|
+
if (
|
|
106
|
+
(key === "acf" || key === "meta") &&
|
|
107
|
+
val &&
|
|
108
|
+
typeof val === "object" &&
|
|
109
|
+
!Array.isArray(val)
|
|
110
|
+
) {
|
|
111
|
+
for (const childKey of Object.keys(val)) {
|
|
112
|
+
keySet.add(`${key}_${childKey}`);
|
|
113
|
+
}
|
|
114
|
+
continue;
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
keySet.add(key);
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
return keySet;
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
/**
|
|
124
|
+
* choiceItems を dataObj のキーに合わせて削除する
|
|
125
|
+
* - choiceItems が string 配列でも、{value: "..."} の配列でも動くようにしてあります
|
|
126
|
+
*/
|
|
127
|
+
function pruneChoiceItemsByObjectKeys(dataObj, choiceItems) {
|
|
128
|
+
const validKeys = buildComparableKeySet(dataObj);
|
|
129
|
+
|
|
130
|
+
const getItemKey = (item) => {
|
|
131
|
+
if (typeof item === "string") return item;
|
|
132
|
+
if (item && typeof item === "object")
|
|
133
|
+
return item.value ?? item.key ?? item.name ?? "";
|
|
134
|
+
return "";
|
|
135
|
+
};
|
|
136
|
+
|
|
137
|
+
const next = (choiceItems ?? []).filter((item) =>
|
|
138
|
+
validKeys.has(getItemKey(item))
|
|
139
|
+
);
|
|
140
|
+
|
|
141
|
+
// ★ 配列の参照はそのまま、中身だけ置き換える
|
|
142
|
+
choiceItems.splice(0, choiceItems.length, ...next);
|
|
143
|
+
|
|
144
|
+
return choiceItems; // 必要なら返す
|
|
145
|
+
}
|
|
93
146
|
|
|
94
147
|
//階層化されたカスタムフィールドのフィールド名を表示する関数
|
|
95
148
|
let groupLabel = "";
|
|
96
|
-
const dispCustumFields = (obj, prefix = "", onChange) => {
|
|
149
|
+
const dispCustumFields = (obj, prefix = "", isImage = false, onChange) => {
|
|
97
150
|
return Object.entries(obj).map(([key, value]) => {
|
|
98
151
|
const fieldName = prefix ? `${prefix}.${key}` : key; //prefixはグループ名
|
|
99
152
|
|
|
100
153
|
const fieldLabel = key.replace(/^(meta_|acf_)/, "");
|
|
101
|
-
|
|
102
|
-
if (
|
|
154
|
+
//オブジェクトであって配列でないものがグループと考える
|
|
155
|
+
if (
|
|
156
|
+
typeof value === "object" &&
|
|
157
|
+
!Array.isArray(value) &&
|
|
158
|
+
value !== null
|
|
159
|
+
) {
|
|
103
160
|
groupLabel = `${fieldLabel}.`;
|
|
104
161
|
return (
|
|
105
162
|
<div className="group_area">
|
|
106
163
|
<div className="group_label">{fieldLabel}</div>
|
|
107
164
|
<div key={fieldName} className="field_group">
|
|
108
|
-
{dispCustumFields(value, fieldName, onChange)}
|
|
165
|
+
{dispCustumFields(value, fieldName, isImage, onChange)}
|
|
109
166
|
</div>
|
|
110
167
|
</div>
|
|
111
168
|
);
|
|
@@ -117,6 +174,7 @@ const ChoiceControl = (props) => {
|
|
|
117
174
|
{ value: "itmar/design-title", label: "itmar/design-title" },
|
|
118
175
|
{ value: "core/paragraph", label: "core/paragraph" },
|
|
119
176
|
{ value: "core/image", label: "core/image" },
|
|
177
|
+
{ value: "itmar/slide-mv", label: "itmar/slide-mv" },
|
|
120
178
|
];
|
|
121
179
|
return (
|
|
122
180
|
<div className="itmar_custom_field_set">
|
|
@@ -136,20 +194,23 @@ const ChoiceControl = (props) => {
|
|
|
136
194
|
props.onChange(newChoiceFields);
|
|
137
195
|
}}
|
|
138
196
|
/>
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
: `${
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
197
|
+
{!isImage && (
|
|
198
|
+
<ComboboxControl
|
|
199
|
+
options={options}
|
|
200
|
+
value={
|
|
201
|
+
//blockMap[`${prefix ? groupLabel : ""}${key}`] || "itmar/design-title"
|
|
202
|
+
blockMap[`${prefix ? prefix + "." : ""}${key}`] ||
|
|
203
|
+
"itmar/design-title"
|
|
204
|
+
}
|
|
205
|
+
onChange={(newValue) => {
|
|
206
|
+
//const fieldKey = prefix ? `${groupLabel}${key}` : `${key}`;
|
|
207
|
+
const fieldKey = prefix ? `${prefix}.${key}` : `${key}`;
|
|
208
|
+
|
|
209
|
+
const newBlockMap = { ...blockMap, [fieldKey]: newValue };
|
|
210
|
+
props.onBlockMapChange(newBlockMap);
|
|
211
|
+
}}
|
|
212
|
+
/>
|
|
213
|
+
)}
|
|
153
214
|
</div>
|
|
154
215
|
);
|
|
155
216
|
}
|
|
@@ -240,6 +301,23 @@ const ChoiceControl = (props) => {
|
|
|
240
301
|
}}
|
|
241
302
|
/>
|
|
242
303
|
)}
|
|
304
|
+
{choice.content && (
|
|
305
|
+
<ToggleControl
|
|
306
|
+
className="field_choice"
|
|
307
|
+
label={__("Content", "block-collections")}
|
|
308
|
+
checked={choiceItems.some(
|
|
309
|
+
(choiceField) => choiceField === "content"
|
|
310
|
+
)}
|
|
311
|
+
onChange={(checked) => {
|
|
312
|
+
const newChoiceFields = handleChoiceChange(
|
|
313
|
+
checked,
|
|
314
|
+
"content",
|
|
315
|
+
choiceItems
|
|
316
|
+
);
|
|
317
|
+
props.onChange(newChoiceFields);
|
|
318
|
+
}}
|
|
319
|
+
/>
|
|
320
|
+
)}
|
|
243
321
|
{choice.date && (
|
|
244
322
|
<ToggleControl
|
|
245
323
|
className="field_choice"
|
|
@@ -343,6 +421,7 @@ const ChoiceControl = (props) => {
|
|
|
343
421
|
</div>
|
|
344
422
|
<div className="custom_field_area">
|
|
345
423
|
{dispCustumFields({
|
|
424
|
+
// meta はそのまま
|
|
346
425
|
...Object.entries(choice.meta).reduce(
|
|
347
426
|
(acc, [key, value]) => ({
|
|
348
427
|
...acc,
|
|
@@ -350,13 +429,16 @@ const ChoiceControl = (props) => {
|
|
|
350
429
|
}),
|
|
351
430
|
{}
|
|
352
431
|
),
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
432
|
+
// acf は「同名で _source があるもののベース側を除く」
|
|
433
|
+
...Object.entries(choice.acf)
|
|
434
|
+
.filter(([key]) => !key.endsWith("_source"))
|
|
435
|
+
.reduce(
|
|
436
|
+
(acc, [key, value]) => ({
|
|
437
|
+
...acc,
|
|
438
|
+
[`acf_${key}`]: value,
|
|
439
|
+
}),
|
|
440
|
+
{}
|
|
441
|
+
),
|
|
360
442
|
})}
|
|
361
443
|
</div>
|
|
362
444
|
</>
|
|
@@ -364,6 +446,93 @@ const ChoiceControl = (props) => {
|
|
|
364
446
|
</div>
|
|
365
447
|
);
|
|
366
448
|
})}
|
|
449
|
+
{type === "imgField" &&
|
|
450
|
+
choices.map((choice, index) => {
|
|
451
|
+
//metaの対象カスタムフィールドが含まれるかのフラグ
|
|
452
|
+
const metaFlg =
|
|
453
|
+
choice.meta &&
|
|
454
|
+
!Object.keys(choice.meta).every(
|
|
455
|
+
(key) => key === "_acf_changed" || key === "footnotes"
|
|
456
|
+
);
|
|
457
|
+
//acfの対象カスタムフィールドが含まれるかのフラグ
|
|
458
|
+
const acfFlg =
|
|
459
|
+
choice.acf &&
|
|
460
|
+
typeof choice.acf === "object" &&
|
|
461
|
+
!Array.isArray(choice.acf);
|
|
462
|
+
|
|
463
|
+
return (
|
|
464
|
+
<div key={index} className="field_section">
|
|
465
|
+
{choice.content && (
|
|
466
|
+
<ToggleControl
|
|
467
|
+
className="field_choice"
|
|
468
|
+
label={__("Content", "block-collections")}
|
|
469
|
+
checked={choiceItems.some(
|
|
470
|
+
(choiceField) => choiceField === "content"
|
|
471
|
+
)}
|
|
472
|
+
onChange={(checked) => {
|
|
473
|
+
const newChoiceFields = handleChoiceChange(
|
|
474
|
+
checked,
|
|
475
|
+
"content",
|
|
476
|
+
choiceItems
|
|
477
|
+
);
|
|
478
|
+
props.onChange(newChoiceFields);
|
|
479
|
+
}}
|
|
480
|
+
/>
|
|
481
|
+
)}
|
|
482
|
+
{(choice.featured_media || choice.featured_media === 0) && (
|
|
483
|
+
<ToggleControl
|
|
484
|
+
className="field_choice"
|
|
485
|
+
label={__("Featured Image", "block-collections")}
|
|
486
|
+
checked={choiceItems.some(
|
|
487
|
+
(choiceField) => choiceField === "featured_media"
|
|
488
|
+
)}
|
|
489
|
+
onChange={(checked) => {
|
|
490
|
+
const newChoiceFields = handleChoiceChange(
|
|
491
|
+
checked,
|
|
492
|
+
"featured_media",
|
|
493
|
+
choiceItems
|
|
494
|
+
);
|
|
495
|
+
props.onChange(newChoiceFields);
|
|
496
|
+
}}
|
|
497
|
+
/>
|
|
498
|
+
)}
|
|
499
|
+
|
|
500
|
+
{(metaFlg || acfFlg) && (
|
|
501
|
+
<>
|
|
502
|
+
<div className="custom_field_label">
|
|
503
|
+
{__("Custom Field", "block-collections")}
|
|
504
|
+
</div>
|
|
505
|
+
<div className="custom_field_area">
|
|
506
|
+
{dispCustumFields(
|
|
507
|
+
{
|
|
508
|
+
// meta はそのまま
|
|
509
|
+
...Object.entries(choice.meta).reduce(
|
|
510
|
+
(acc, [key, value]) => ({
|
|
511
|
+
...acc,
|
|
512
|
+
[`meta_${key}`]: value,
|
|
513
|
+
}),
|
|
514
|
+
{}
|
|
515
|
+
),
|
|
516
|
+
// acf は「同名で _source があるもののベース側を除く」
|
|
517
|
+
...Object.entries(choice.acf)
|
|
518
|
+
.filter(([key]) => !key.endsWith("_source"))
|
|
519
|
+
.reduce(
|
|
520
|
+
(acc, [key, value]) => ({
|
|
521
|
+
...acc,
|
|
522
|
+
[`acf_${key}`]: value,
|
|
523
|
+
}),
|
|
524
|
+
{}
|
|
525
|
+
),
|
|
526
|
+
},
|
|
527
|
+
"",
|
|
528
|
+
true
|
|
529
|
+
)}
|
|
530
|
+
</div>
|
|
531
|
+
</>
|
|
532
|
+
)}
|
|
533
|
+
</div>
|
|
534
|
+
);
|
|
535
|
+
})}
|
|
367
536
|
</div>
|
|
368
537
|
);
|
|
369
538
|
};
|
|
@@ -483,6 +652,7 @@ export const restFieldes = async (rest_base) => {
|
|
|
483
652
|
//投稿データに以下のフィールドが含まれているかを調べる
|
|
484
653
|
const selectedFields = [
|
|
485
654
|
"title",
|
|
655
|
+
"content",
|
|
486
656
|
"date",
|
|
487
657
|
"excerpt",
|
|
488
658
|
"featured_media",
|
|
@@ -495,6 +665,7 @@ export const restFieldes = async (rest_base) => {
|
|
|
495
665
|
const response = await apiFetch({
|
|
496
666
|
path: `/wp/v2/${rest_base}?_fields=${fieldsParam}&per_page=1&order=desc`,
|
|
497
667
|
});
|
|
668
|
+
|
|
498
669
|
return response;
|
|
499
670
|
};
|
|
500
671
|
|