itmar-block-packages 1.7.1 → 1.9.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 +107 -0
- package/build/index.asset.php +1 -1
- package/build/index.js +3 -3
- package/package.json +1 -1
- package/src/formatCreate.js +179 -0
- package/src/index.js +10 -0
- package/src/shopfiApi.js +187 -0
package/README.md
CHANGED
|
@@ -14,6 +14,12 @@ import {関数名又はコンポーネント名} from "itmar-block-packages"
|
|
|
14
14
|
npm i @wordpress/scripts@^27.6.0 --save-dev
|
|
15
15
|
|
|
16
16
|
## 更新履歴
|
|
17
|
+
= 1.9.0 =
|
|
18
|
+
- shopfiApi.jsを新設。
|
|
19
|
+
|
|
20
|
+
= 1.8.0 =
|
|
21
|
+
- formatCreate.jsを新設。Gutenberg ブロックにおける数値・日付・自由書式の表示形式を選択・制御するための UI コンポーネントおよびフォーマット関数を含みます。
|
|
22
|
+
|
|
17
23
|
= 1.7.1 =
|
|
18
24
|
- serializeBlockTree,createBlockTreeをblockStore.jsに加えた。
|
|
19
25
|
- BlockPlace.jsでdesign-groupがフレックス要素の場合は主軸の大きさの設定がflex-grow,flex-shrink,flex-basisとなるよう修正した加えた。
|
|
@@ -1251,4 +1257,105 @@ if (isValidUrlWithUrlApi(headingContent)) {
|
|
|
1251
1257
|
}
|
|
1252
1258
|
```
|
|
1253
1259
|
|
|
1260
|
+
## データのフォーマットを設定、表示するコンポーネント
|
|
1261
|
+
|
|
1262
|
+
Gutenberg ブロックにおける数値・日付・自由書式の表示形式を選択・制御するための UI コンポーネントおよびフォーマット関数です。
|
|
1263
|
+
|
|
1264
|
+
---
|
|
1265
|
+
|
|
1266
|
+
### 概要
|
|
1267
|
+
|
|
1268
|
+
このライブラリは、以下の2つの機能を提供します:
|
|
1269
|
+
|
|
1270
|
+
1. **`<FormatSelectControl />`**
|
|
1271
|
+
ブロックエディターの「インスペクター設定」内で、表示形式を選択する UI コンポーネント。
|
|
1272
|
+
|
|
1273
|
+
2. **`displayFormated()`**
|
|
1274
|
+
保存された設定に基づき、日付・数値・自由文字列の値を整形する表示用関数。
|
|
1275
|
+
|
|
1276
|
+
---
|
|
1277
|
+
|
|
1278
|
+
### `FormatSelectControl`
|
|
1279
|
+
|
|
1280
|
+
#### 説明
|
|
1281
|
+
|
|
1282
|
+
ブロック編集画面で「日付」「数値」「自由文字列」のいずれかの表示形式を選択・設定可能にする `PanelBody` コンポーネントです。
|
|
1283
|
+
|
|
1284
|
+
#### 引数
|
|
1285
|
+
|
|
1286
|
+
| 名前 | 型 | 必須 | 説明 |
|
|
1287
|
+
|------|----|------|------|
|
|
1288
|
+
| `titleType` | `"date"` \| `"plaine"` \| `"user"` | ✅ | フォーマット対象の種類を指定します。 |
|
|
1289
|
+
| `userFormat` | `string` | ✅ | 現在選択中のフォーマットのキー(例: `"num_comma"`)。 |
|
|
1290
|
+
| `freeStrFormat` | `string` | ✅ | 自由書式入力時の書式文字列(例: `"¥%s円"`)。 |
|
|
1291
|
+
| `decimal` | `number` | ✅ | 数値の小数点以下の桁数(0〜5) |
|
|
1292
|
+
| `onFormatChange` | `(info: FormatSettings) => void` | ✅ | 各設定項目の更新を通知するコールバック |
|
|
1293
|
+
|
|
1294
|
+
#### フォーマットオプション例(SelectControlで使用)
|
|
1295
|
+
|
|
1296
|
+
- 日付形式:`Y-m-d H:i:s`、`Y年n月j日 (l)` など
|
|
1297
|
+
- 数値形式:カンマ区切りあり/なし、金額表示など
|
|
1298
|
+
- 自由書式:`"%s"` を含む文字列で、実際の値が置換されます
|
|
1299
|
+
|
|
1300
|
+
---
|
|
1301
|
+
|
|
1302
|
+
### `displayFormated(content, userFormat, freeStrFormat, decimal)`
|
|
1303
|
+
|
|
1304
|
+
#### 説明
|
|
1305
|
+
|
|
1306
|
+
指定されたフォーマットに従って、値を整形して文字列として返します。
|
|
1307
|
+
|
|
1308
|
+
#### 引数
|
|
1309
|
+
|
|
1310
|
+
| 名前 | 型 | 説明 |
|
|
1311
|
+
|------|----|------|
|
|
1312
|
+
| `content` | `string` \| `number` | 整形対象の生の値 |
|
|
1313
|
+
| `userFormat` | `string` | 日付または数値のフォーマットキー(例: `"num_comma"`、`"Y-m-d"`) |
|
|
1314
|
+
| `freeStrFormat` | `string` | `"%s"` を含む自由書式文字列 |
|
|
1315
|
+
| `decimal` | `number` | 小数点以下の桁数指定(`0` なら整数扱い) |
|
|
1316
|
+
|
|
1317
|
+
#### 戻り値
|
|
1318
|
+
|
|
1319
|
+
整形後の文字列(`string`)
|
|
1320
|
+
|
|
1321
|
+
---
|
|
1322
|
+
|
|
1323
|
+
### 使用例
|
|
1324
|
+
|
|
1325
|
+
#### 1. コンポーネントの設置例
|
|
1326
|
+
|
|
1327
|
+
```jsx
|
|
1328
|
+
<FormatSelectControl
|
|
1329
|
+
titleType="plaine"
|
|
1330
|
+
userFormat={attributes.userFormat}
|
|
1331
|
+
freeStrFormat={attributes.freeStrFormat}
|
|
1332
|
+
decimal={attributes.decimal}
|
|
1333
|
+
onFormatChange={(newSettings) => setAttributes(newSettings)}
|
|
1334
|
+
/>
|
|
1335
|
+
```
|
|
1336
|
+
#### 2. 表示用フォーマット関数の使用例
|
|
1337
|
+
```
|
|
1338
|
+
const display = displayFormated(
|
|
1339
|
+
1234567.89,
|
|
1340
|
+
attributes.userFormat,
|
|
1341
|
+
attributes.freeStrFormat,
|
|
1342
|
+
attributes.decimal
|
|
1343
|
+
);
|
|
1344
|
+
// → "1,234,567.89"(例: num_comma + decimal: 2 の場合)
|
|
1345
|
+
```
|
|
1346
|
+
|
|
1347
|
+
### 注意事項・ルール
|
|
1348
|
+
✅ 自由書式(freeStrFormat)について
|
|
1349
|
+
- %s を含まない文字列は 置換せず、値をそのまま返します
|
|
1350
|
+
- 例:"¥%s" → "¥1234"、"Total: " → "1234"(%s なし)
|
|
1351
|
+
|
|
1352
|
+
✅ 日付フォーマットの安全性
|
|
1353
|
+
- userFormat が dateFormats に存在しない限り format() は呼び出されません(安全)
|
|
1354
|
+
- Gutenberg 標準の PHP形式に準拠(例:Y-m-d, F j, Y)
|
|
1355
|
+
|
|
1356
|
+
✅ 数値フォーマットの条件
|
|
1357
|
+
- decimal が 1 以上のときは minimumFractionDigits / maximumFractionDigits が指定され、常に小数点以下を表示
|
|
1358
|
+
- decimal = 0 の場合は整数として表示
|
|
1359
|
+
|
|
1360
|
+
|
|
1254
1361
|
|
package/build/index.asset.php
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
<?php return array('dependencies' => array('react', 'react-dom', 'wp-api-fetch', 'wp-block-editor', 'wp-blocks', 'wp-components', 'wp-data', 'wp-element', 'wp-i18n', 'wp-primitives'), 'version' => '
|
|
1
|
+
<?php return array('dependencies' => array('react', 'react-dom', 'wp-api-fetch', 'wp-block-editor', 'wp-blocks', 'wp-components', 'wp-data', 'wp-date', 'wp-element', 'wp-i18n', 'wp-primitives'), 'version' => 'ee8c6bfdb53817b8eb3b');
|