itmar-block-packages 1.10.0 → 2.0.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.
Files changed (157) hide show
  1. package/README.md +81 -2
  2. package/build/cjs/AnimationBlock.js +107 -0
  3. package/build/cjs/AnimationBlock.js.map +1 -0
  4. package/build/cjs/BlockEditWrapper.js +20 -0
  5. package/build/cjs/BlockEditWrapper.js.map +1 -0
  6. package/build/cjs/BlockPlace.js +509 -0
  7. package/build/cjs/BlockPlace.js.map +1 -0
  8. package/build/cjs/BrockInserter.js +204 -0
  9. package/build/cjs/BrockInserter.js.map +1 -0
  10. package/build/cjs/DateElm.js +321 -0
  11. package/build/cjs/DateElm.js.map +1 -0
  12. package/build/cjs/DraggableBox.js +143 -0
  13. package/build/cjs/DraggableBox.js.map +1 -0
  14. package/build/cjs/GridControls.js +421 -0
  15. package/build/cjs/GridControls.js.map +1 -0
  16. package/build/cjs/IconSelectControl.js +167 -0
  17. package/build/cjs/IconSelectControl.js.map +1 -0
  18. package/build/cjs/JapaneseHolidays.js +99 -0
  19. package/build/cjs/JapaneseHolidays.js.map +1 -0
  20. package/build/cjs/MasonryControl.js +124 -0
  21. package/build/cjs/MasonryControl.js.map +1 -0
  22. package/build/cjs/PseudoElm.js +66 -0
  23. package/build/cjs/PseudoElm.js.map +1 -0
  24. package/build/cjs/ShadowStyle.js +453 -0
  25. package/build/cjs/ShadowStyle.js.map +1 -0
  26. package/build/cjs/SwiperControl.js +267 -0
  27. package/build/cjs/SwiperControl.js.map +1 -0
  28. package/build/cjs/ToggleElement.js +17 -0
  29. package/build/cjs/ToggleElement.js.map +1 -0
  30. package/build/cjs/TypographyControls.js +151 -0
  31. package/build/cjs/TypographyControls.js.map +1 -0
  32. package/build/cjs/UpdateAllPostsBlockAttributes.js +137 -0
  33. package/build/cjs/UpdateAllPostsBlockAttributes.js.map +1 -0
  34. package/build/cjs/ZipAddress.js +34 -0
  35. package/build/cjs/ZipAddress.js.map +1 -0
  36. package/build/cjs/_virtual/_rollupPluginBabelHelpers.js +117 -0
  37. package/build/cjs/_virtual/_rollupPluginBabelHelpers.js.map +1 -0
  38. package/build/cjs/blockStore.js +65 -0
  39. package/build/cjs/blockStore.js.map +1 -0
  40. package/build/cjs/cssPropertes.js +157 -0
  41. package/build/cjs/cssPropertes.js.map +1 -0
  42. package/build/cjs/customFooks.js +300 -0
  43. package/build/cjs/customFooks.js.map +1 -0
  44. package/build/cjs/formatCreate.js +160 -0
  45. package/build/cjs/formatCreate.js.map +1 -0
  46. package/build/cjs/hslToRgb.js +133 -0
  47. package/build/cjs/hslToRgb.js.map +1 -0
  48. package/build/cjs/index.js +115 -0
  49. package/build/cjs/index.js.map +1 -0
  50. package/build/cjs/mediaUpload.js +182 -0
  51. package/build/cjs/mediaUpload.js.map +1 -0
  52. package/build/cjs/node_modules/nanoid/index.js +30 -0
  53. package/build/cjs/node_modules/nanoid/index.js.map +1 -0
  54. package/build/cjs/node_modules/nanoid/url-alphabet/index.js +7 -0
  55. package/build/cjs/node_modules/nanoid/url-alphabet/index.js.map +1 -0
  56. package/build/cjs/shopfiApi.js +188 -0
  57. package/build/cjs/shopfiApi.js.map +1 -0
  58. package/build/cjs/validationCheck.js +15 -0
  59. package/build/cjs/validationCheck.js.map +1 -0
  60. package/build/cjs/wordpressApi.js +631 -0
  61. package/build/cjs/wordpressApi.js.map +1 -0
  62. package/build/esm/AnimationBlock.js +102 -0
  63. package/build/esm/AnimationBlock.js.map +1 -0
  64. package/build/esm/BlockEditWrapper.js +16 -0
  65. package/build/esm/BlockEditWrapper.js.map +1 -0
  66. package/build/esm/BlockPlace.js +503 -0
  67. package/build/esm/BlockPlace.js.map +1 -0
  68. package/build/esm/BrockInserter.js +202 -0
  69. package/build/esm/BrockInserter.js.map +1 -0
  70. package/build/esm/DateElm.js +309 -0
  71. package/build/esm/DateElm.js.map +1 -0
  72. package/build/esm/DraggableBox.js +138 -0
  73. package/build/esm/DraggableBox.js.map +1 -0
  74. package/build/esm/GridControls.js +417 -0
  75. package/build/esm/GridControls.js.map +1 -0
  76. package/build/esm/IconSelectControl.js +163 -0
  77. package/build/esm/IconSelectControl.js.map +1 -0
  78. package/build/esm/JapaneseHolidays.js +97 -0
  79. package/build/esm/JapaneseHolidays.js.map +1 -0
  80. package/{src → build/esm}/MasonryControl.js +108 -113
  81. package/build/esm/MasonryControl.js.map +1 -0
  82. package/build/esm/PseudoElm.js +61 -0
  83. package/build/esm/PseudoElm.js.map +1 -0
  84. package/build/esm/ShadowStyle.js +448 -0
  85. package/build/esm/ShadowStyle.js.map +1 -0
  86. package/{src → build/esm}/SwiperControl.js +265 -265
  87. package/build/esm/SwiperControl.js.map +1 -0
  88. package/build/esm/ToggleElement.js +13 -0
  89. package/build/esm/ToggleElement.js.map +1 -0
  90. package/build/esm/TypographyControls.js +147 -0
  91. package/build/esm/TypographyControls.js.map +1 -0
  92. package/build/esm/UpdateAllPostsBlockAttributes.js +133 -0
  93. package/build/esm/UpdateAllPostsBlockAttributes.js.map +1 -0
  94. package/build/esm/ZipAddress.js +32 -0
  95. package/build/esm/ZipAddress.js.map +1 -0
  96. package/build/esm/_virtual/_rollupPluginBabelHelpers.js +107 -0
  97. package/build/esm/_virtual/_rollupPluginBabelHelpers.js.map +1 -0
  98. package/build/esm/blockStore.js +60 -0
  99. package/build/esm/blockStore.js.map +1 -0
  100. package/build/esm/cssPropertes.js +144 -0
  101. package/build/esm/cssPropertes.js.map +1 -0
  102. package/{src → build/esm}/customFooks.js +290 -337
  103. package/build/esm/customFooks.js.map +1 -0
  104. package/build/esm/formatCreate.js +157 -0
  105. package/build/esm/formatCreate.js.map +1 -0
  106. package/build/esm/hslToRgb.js +129 -0
  107. package/build/esm/hslToRgb.js.map +1 -0
  108. package/build/esm/index.js +27 -0
  109. package/build/esm/index.js.map +1 -0
  110. package/build/esm/mediaUpload.js +176 -0
  111. package/build/esm/mediaUpload.js.map +1 -0
  112. package/build/esm/node_modules/nanoid/index.js +27 -0
  113. package/build/esm/node_modules/nanoid/index.js.map +1 -0
  114. package/build/esm/node_modules/nanoid/url-alphabet/index.js +5 -0
  115. package/build/esm/node_modules/nanoid/url-alphabet/index.js.map +1 -0
  116. package/build/esm/shopfiApi.js +184 -0
  117. package/build/esm/shopfiApi.js.map +1 -0
  118. package/build/esm/validationCheck.js +13 -0
  119. package/build/esm/validationCheck.js.map +1 -0
  120. package/build/esm/wordpressApi.js +618 -0
  121. package/build/esm/wordpressApi.js.map +1 -0
  122. package/package.json +22 -6
  123. package/build/index.asset.php +0 -1
  124. package/build/index.js +0 -25
  125. package/css/editor.css +0 -23
  126. package/css/editor.css.map +0 -1
  127. package/img/animation.png +0 -0
  128. package/img/blockplace.png +0 -0
  129. package/img/grid.png +0 -0
  130. package/img/iconControl.png +0 -0
  131. package/img/pseudo.png +0 -0
  132. package/img/shadow.png +0 -0
  133. package/img/typography.png +0 -0
  134. package/src/AnimationBlock.js +0 -112
  135. package/src/BlockEditWrapper.js +0 -11
  136. package/src/BlockPlace.js +0 -904
  137. package/src/BrockInserter.js +0 -247
  138. package/src/DateElm.js +0 -354
  139. package/src/DraggableBox.js +0 -143
  140. package/src/GridControls.js +0 -462
  141. package/src/IconSelectControl.js +0 -186
  142. package/src/PseudoElm.js +0 -54
  143. package/src/ShadowStyle.js +0 -520
  144. package/src/ToggleElement.js +0 -18
  145. package/src/TypographyControls.js +0 -145
  146. package/src/UpdateAllPostsBlockAttributes.js +0 -127
  147. package/src/ZipAddress.js +0 -35
  148. package/src/blockStore.js +0 -75
  149. package/src/cssPropertes.js +0 -212
  150. package/src/formatCreate.js +0 -179
  151. package/src/hslToRgb.js +0 -162
  152. package/src/index.js +0 -131
  153. package/src/mediaUpload.js +0 -178
  154. package/src/shopfiApi.js +0 -187
  155. package/src/validationCheck.js +0 -10
  156. package/src/wordpressApi.js +0 -686
  157. package/webpack.config.js +0 -10
@@ -1,686 +0,0 @@
1
- import { useState, useEffect } from "@wordpress/element";
2
- import { __ } from "@wordpress/i18n";
3
- import {
4
- ComboboxControl,
5
- CheckboxControl,
6
- ToggleControl,
7
- } from "@wordpress/components";
8
- import apiFetch from "@wordpress/api-fetch";
9
-
10
- //const _ = require("lodash");
11
-
12
- export const restFetchData = async (path) => {
13
- try {
14
- const ret_data = await apiFetch({ path: path });
15
- return ret_data;
16
- } catch (error) {
17
- console.error("Error fetching data:", error.message);
18
- }
19
- };
20
-
21
- //コンボボックスコントロールのレンダリング関数
22
- const SelectControl = (props) => {
23
- const { selectedSlug, label, homeUrl, fetchOptions } = props;
24
- const [options, setOptions] = useState([]);
25
-
26
- useEffect(() => {
27
- const fetchData = async () => {
28
- try {
29
- const fetchedOptions = await fetchOptions(homeUrl);
30
- setOptions(fetchedOptions);
31
- } catch (error) {
32
- console.error("Error fetching data:", error.message);
33
- }
34
- };
35
-
36
- fetchData();
37
- }, [fetchOptions]);
38
-
39
- const selectedInfo = options.find((info) => info.slug === selectedSlug);
40
- return (
41
- <ComboboxControl
42
- label={label}
43
- options={options}
44
- value={selectedInfo ? selectedInfo.value : -1}
45
- onChange={(newValue) => {
46
- const newInfo = options.find((info) => info.value === newValue);
47
- props.onChange(newInfo);
48
- }}
49
- />
50
- );
51
- };
52
-
53
- //選択コントロールのレンダリング関数
54
- const ChoiceControl = (props) => {
55
- const {
56
- selectedSlug,
57
- choiceItems,
58
- dispTaxonomies,
59
- type,
60
- blockMap,
61
- textDomain,
62
- fetchFunction,
63
- } = props;
64
-
65
- const [choices, setChoices] = useState([]);
66
- useEffect(() => {
67
- if (!selectedSlug) return; //ポストタイプのスラッグが選択されていないときは処理終了
68
- const fetchData = async () => {
69
- try {
70
- const fetchChoices = await fetchFunction(selectedSlug);
71
- setChoices(fetchChoices);
72
- //指定の投稿タイプに含まれないフィールドを削除する
73
- pruneChoiceItemsByObjectKeys(fetchChoices[0], choiceItems);
74
- } catch (error) {
75
- console.error("Error fetching data:", error.message);
76
- }
77
- };
78
- fetchData();
79
- }, [selectedSlug, fetchFunction]);
80
-
81
- //選択肢が変わったときに選択されている項目の配列内容を更新するハンドラ
82
- const handleChoiceChange = (checked, target, setItems) => {
83
- if (checked) {
84
- // targetが重複していない場合のみ追加
85
- if (!setItems.some((item) => _.isEqual(item, target))) {
86
- return [...setItems, target];
87
- }
88
- } else {
89
- // targetを配列から削除
90
- return setItems.filter((item) => !_.isEqual(item, target));
91
- }
92
- return setItems;
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
- }
146
-
147
- //階層化されたカスタムフィールドのフィールド名を表示する関数
148
- let groupLabel = "";
149
- const dispCustumFields = (obj, prefix = "", isImage = false, onChange) => {
150
- return Object.entries(obj).map(([key, value]) => {
151
- const fieldName = prefix ? `${prefix}.${key}` : key; //prefixはグループ名
152
-
153
- const fieldLabel = key.replace(/^(meta_|acf_)/, "");
154
- //オブジェクトであって配列でないものがグループと考える
155
- if (
156
- typeof value === "object" &&
157
- !Array.isArray(value) &&
158
- value !== null
159
- ) {
160
- groupLabel = `${fieldLabel}.`;
161
- return (
162
- <div className="group_area">
163
- <div className="group_label">{fieldLabel}</div>
164
- <div key={fieldName} className="field_group">
165
- {dispCustumFields(value, fieldName, isImage, onChange)}
166
- </div>
167
- </div>
168
- );
169
- } else {
170
- if (key === "meta__acf_changed" || key === "meta_footnotes") return; //_acf_changedは対象外
171
-
172
- //フィールドを表示するブロックの選択肢
173
- const options = [
174
- { value: "itmar/design-title", label: "itmar/design-title" },
175
- { value: "core/paragraph", label: "core/paragraph" },
176
- { value: "core/image", label: "core/image" },
177
- { value: "itmar/slide-mv", label: "itmar/slide-mv" },
178
- ];
179
- return (
180
- <div className="itmar_custom_field_set">
181
- <ToggleControl
182
- key={fieldName}
183
- className="field_choice"
184
- label={fieldLabel}
185
- checked={choiceItems.some(
186
- (choiceField) => choiceField === fieldName
187
- )}
188
- onChange={(checked) => {
189
- const newChoiceFields = handleChoiceChange(
190
- checked,
191
- fieldName,
192
- choiceItems
193
- );
194
- props.onChange(newChoiceFields);
195
- }}
196
- />
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
- )}
214
- </div>
215
- );
216
- }
217
- });
218
- };
219
-
220
- return (
221
- <div className={`${type}_section`}>
222
- {type === "taxonomy" &&
223
- choices.map((choice, index) => {
224
- return (
225
- <div key={index} className="term_section">
226
- <div className="tax_label">
227
- {choice.name}
228
- <ToggleControl
229
- label={__("Display", "block-collections")}
230
- checked={dispTaxonomies.some((tax) => tax === choice.slug)}
231
- onChange={(checked) => {
232
- const newChoiceFields = handleChoiceChange(
233
- checked,
234
- choice.slug,
235
- dispTaxonomies
236
- );
237
- props.onSetDispTax(newChoiceFields);
238
- }}
239
- />
240
- </div>
241
- {choice.terms.map((term, index) => {
242
- return (
243
- <CheckboxControl
244
- className="term_check"
245
- key={index}
246
- label={term.name}
247
- checked={choiceItems.some((choiceTerm) => {
248
- return (
249
- choiceTerm.taxonomy === choice.slug &&
250
- choiceTerm.term.id === term.id
251
- );
252
- })}
253
- onChange={(checked) => {
254
- const target = {
255
- taxonomy: choice.slug,
256
- term: { id: term.id, slug: term.slug, name: term.name },
257
- };
258
- const newChoiceTerms = handleChoiceChange(
259
- checked,
260
- target,
261
- choiceItems
262
- );
263
- props.onChange(newChoiceTerms);
264
- }}
265
- />
266
- );
267
- })}
268
- </div>
269
- );
270
- })}
271
- {type === "field" &&
272
- choices.map((choice, index) => {
273
- //metaの対象カスタムフィールドが含まれるかのフラグ
274
- const metaFlg =
275
- choice.meta &&
276
- !Object.keys(choice.meta).every(
277
- (key) => key === "_acf_changed" || key === "footnotes"
278
- );
279
- //acfの対象カスタムフィールドが含まれるかのフラグ
280
- const acfFlg =
281
- choice.acf &&
282
- typeof choice.acf === "object" &&
283
- !Array.isArray(choice.acf);
284
-
285
- return (
286
- <div key={index} className="field_section">
287
- {choice.title && (
288
- <ToggleControl
289
- className="field_choice"
290
- label={__("Title", "block-collections")}
291
- checked={choiceItems.some(
292
- (choiceField) => choiceField === "title"
293
- )}
294
- onChange={(checked) => {
295
- const newChoiceFields = handleChoiceChange(
296
- checked,
297
- "title",
298
- choiceItems
299
- );
300
- props.onChange(newChoiceFields);
301
- }}
302
- />
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
- )}
321
- {choice.date && (
322
- <ToggleControl
323
- className="field_choice"
324
- label={__("Date", "block-collections")}
325
- checked={choiceItems.some(
326
- (choiceField) => choiceField === "date"
327
- )}
328
- onChange={(checked) => {
329
- const newChoiceFields = handleChoiceChange(
330
- checked,
331
- "date",
332
- choiceItems
333
- );
334
- props.onChange(newChoiceFields);
335
- }}
336
- />
337
- )}
338
- {choice.excerpt && (
339
- <ToggleControl
340
- className="field_choice"
341
- label={__("Excerpt", "block-collections")}
342
- checked={choiceItems.some(
343
- (choiceField) => choiceField === "excerpt"
344
- )}
345
- onChange={(checked) => {
346
- const newChoiceFields = handleChoiceChange(
347
- checked,
348
- "excerpt",
349
- choiceItems
350
- );
351
- props.onChange(newChoiceFields);
352
- }}
353
- />
354
- )}
355
- {(choice.featured_media || choice.featured_media === 0) && (
356
- <ToggleControl
357
- className="field_choice"
358
- label={__("Featured Image", "block-collections")}
359
- checked={choiceItems.some(
360
- (choiceField) => choiceField === "featured_media"
361
- )}
362
- onChange={(checked) => {
363
- const newChoiceFields = handleChoiceChange(
364
- checked,
365
- "featured_media",
366
- choiceItems
367
- );
368
- props.onChange(newChoiceFields);
369
- }}
370
- />
371
- )}
372
- {choice.link && (
373
- <div className="itmar_custom_field_set">
374
- <ToggleControl
375
- className="field_choice"
376
- label={__("Single Page Link", "block-collections")}
377
- checked={choiceItems.some(
378
- (choiceField) => choiceField === "link"
379
- )}
380
- onChange={(checked) => {
381
- const newChoiceFields = handleChoiceChange(
382
- checked,
383
- "link",
384
- choiceItems
385
- );
386
- props.onChange(newChoiceFields);
387
- }}
388
- />
389
- <ComboboxControl
390
- options={[
391
- {
392
- value: "itmar/design-button",
393
- label: "itmar/design-button",
394
- },
395
- {
396
- value: "itmar/design-title",
397
- label: "itmar/design-title",
398
- },
399
- ]}
400
- value={blockMap["link"]}
401
- onChange={(newValue) => {
402
- const newBlockMap = {
403
- ...blockMap,
404
- link: newValue,
405
- };
406
- props.onBlockMapChange(newBlockMap);
407
- }}
408
- />
409
- <p>
410
- {__(
411
- "If no block is specified, a link will be set to the parent block, Design Group.",
412
- "block-collections"
413
- )}
414
- </p>
415
- </div>
416
- )}
417
- {(metaFlg || acfFlg) && (
418
- <>
419
- <div className="custom_field_label">
420
- {__("Custom Field", "block-collections")}
421
- </div>
422
- <div className="custom_field_area">
423
- {dispCustumFields({
424
- // meta はそのまま
425
- ...Object.entries(choice.meta).reduce(
426
- (acc, [key, value]) => ({
427
- ...acc,
428
- [`meta_${key}`]: value,
429
- }),
430
- {}
431
- ),
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
- ),
442
- })}
443
- </div>
444
- </>
445
- )}
446
- </div>
447
- );
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
- })}
536
- </div>
537
- );
538
- };
539
-
540
- //固定ページ取得RestAPI関数
541
- export const fetchPagesOptions = async (home_url) => {
542
- const pages = await apiFetch({ path: "/wp/v2/pages" });
543
- //ページIDが-1である要素をホーム要素として作成
544
- if (pages && !pages.some((page) => page.id === -1)) {
545
- pages.unshift({
546
- id: -1,
547
- title: { rendered: "ホーム" },
548
- link: home_url,
549
- slug: "",
550
- });
551
- }
552
-
553
- const ret_pages = pages
554
- ? pages.map((page) => ({
555
- value: page.id,
556
- slug: page.slug,
557
- label: page.title.rendered,
558
- link: `${home_url}/${page.slug}`,
559
- }))
560
- : [];
561
-
562
- return ret_pages;
563
- };
564
-
565
- //アーカイブ情報取得RestAPI関数
566
- export const fetchArchiveOptions = async (home_url) => {
567
- const response = await apiFetch({ path: "/wp/v2/types" });
568
-
569
- let idCounter = 0;
570
- return Object.keys(response).reduce((acc, key) => {
571
- const postType = response[key];
572
- if (postType.has_archive === true) {
573
- acc.push({
574
- value: idCounter++,
575
- slug: postType.slug,
576
- rest_base: postType.rest_base,
577
- link: `${home_url}/${postType.slug}`,
578
- label: postType.name,
579
- });
580
- } else if (typeof postType.has_archive === "string") {
581
- //アーカイブ名がついているとき
582
- acc.push({
583
- value: idCounter++,
584
- slug: postType.slug,
585
- rest_base: postType.rest_base,
586
- link: `${home_url}/${postType.has_archive}`,
587
- label: postType.name,
588
- });
589
- }
590
- return acc;
591
- }, []);
592
- };
593
-
594
- //タクソノミー取得RestAPI関数
595
- export const restTaxonomies = async (post_type) => {
596
- if (!post_type) return;
597
-
598
- const response = await apiFetch({
599
- path: `/wp/v2/types/${post_type}?context=edit`,
600
- });
601
-
602
- const taxonomies = response.taxonomies;
603
-
604
- const taxonomyPromises = taxonomies.map(async (slug) => {
605
- const taxonomyResponse = await apiFetch({
606
- path: `/wp/v2/taxonomies/${slug}?context=edit`,
607
- });
608
- const terms = await apiFetch({
609
- path: `/wp/v2/${taxonomyResponse.rest_base}`,
610
- });
611
-
612
- return {
613
- slug: slug,
614
- name: taxonomyResponse.name,
615
- rest_base: taxonomyResponse.rest_base,
616
- terms: terms,
617
- };
618
- });
619
-
620
- const taxonomyObjects = await Promise.all(taxonomyPromises);
621
- return taxonomyObjects;
622
- };
623
-
624
- //タームの文字列化
625
- export const termToDispObj = (terms, connectString) => {
626
- // taxonomyごとにterm.nameをまとめる
627
- const result = terms.reduce((acc, item) => {
628
- const taxonomy = item.taxonomy;
629
- const termName = item.term.name;
630
-
631
- // taxonomyがまだ存在しない場合は初期化
632
- if (!acc[taxonomy]) {
633
- acc[taxonomy] = [];
634
- }
635
-
636
- // term.nameを配列に追加
637
- acc[taxonomy].push(termName);
638
-
639
- return acc;
640
- }, {});
641
-
642
- // 各taxonomyの配列を connectString でつなげて文字列化
643
- for (const taxonomy in result) {
644
- result[taxonomy] = result[taxonomy].join(connectString);
645
- }
646
-
647
- return result;
648
- };
649
-
650
- //フィールド情報取得RestAPI関数
651
- export const restFieldes = async (rest_base) => {
652
- //投稿データに以下のフィールドが含まれているかを調べる
653
- const selectedFields = [
654
- "title",
655
- "content",
656
- "date",
657
- "excerpt",
658
- "featured_media",
659
- "link",
660
- "meta",
661
- "acf",
662
- ];
663
- const fieldsParam = selectedFields.join(",");
664
- //最新の投稿データから1件分のデータを抽出
665
- const response = await apiFetch({
666
- path: `/wp/v2/${rest_base}?_fields=${fieldsParam}&per_page=1&order=desc`,
667
- });
668
-
669
- return response;
670
- };
671
-
672
- export const PageSelectControl = (props) => (
673
- <SelectControl {...props} fetchOptions={fetchPagesOptions} />
674
- );
675
-
676
- export const ArchiveSelectControl = (props) => (
677
- <SelectControl {...props} fetchOptions={fetchArchiveOptions} />
678
- );
679
-
680
- export const TermChoiceControl = (props) => (
681
- <ChoiceControl {...props} fetchFunction={restTaxonomies} />
682
- );
683
-
684
- export const FieldChoiceControl = (props) => (
685
- <ChoiceControl {...props} fetchFunction={restFieldes} />
686
- );
package/webpack.config.js DELETED
@@ -1,10 +0,0 @@
1
- const defaultConfig = require("@wordpress/scripts/config/webpack.config");
2
-
3
- // オリジナルをカスタマイズ
4
- module.exports = {
5
- ...defaultConfig,
6
- output: {
7
- ...defaultConfig.output,
8
- libraryTarget: "commonjs2",
9
- },
10
- };