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