@geckou/ui-core 0.6.0 → 0.7.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
@@ -36,6 +36,7 @@ import {
36
36
  formatDateValue,
37
37
  splitDate,
38
38
  composeDateValue,
39
+ normalizeDateObject,
39
40
  validateDateObject,
40
41
  daysInMonth,
41
42
  } from '@geckou/ui-core'
@@ -46,6 +47,7 @@ import {
46
47
  | `formatDateValue(value, type?)` | `YYYY-MM-DD`(`type='month'` なら `YYYY-MM`)へ正規化。**`toISOString()` を使わないためタイムゾーンで日付がずれない**。不正な文字列は空文字を返す |
47
48
  | `splitDate(value)` | `YYYY-MM-DD` を `{ year, month, day }` へ分解 |
48
49
  | `composeDateValue(dateObject, type?)` | 年月日から日付文字列を組み立てる。要素が欠けていれば空文字 |
50
+ | `normalizeDateObject(dateObject)` | 月・日を 2 桁へゼロ埋めする(`'1'` → `'01'`)。入力途中の値を検証する前に通す |
49
51
  | `validateDateObject(dateObject, { type, isRequired })` | 桁数・月の範囲・その月に存在する日かを検証し `{ isValid, message }` を返す |
50
52
  | `daysInMonth(year, month)` | 指定した年月の日数(`month` は 1 始まり。うるう年を考慮) |
51
53
 
@@ -124,7 +126,7 @@ const onKeyDown = (event: KeyboardEvent) => {
124
126
  |---|---|
125
127
  | `handleTabKey(container, event, activeElement?)` | Tab / Shift+Tab を端で折り返す。フォーカスを移して既定動作を止めたら `true` を返す。Tab 以外と `container` が無い場合は何もしない |
126
128
  | `getFocusableElements(container)` | コンテナ内のフォーカス可能な要素を DOM 順(= Tab 順)で返す。`inert` が付いたものは除く |
127
- | `FOCUSABLE_SELECTOR` | 上記で使うセレクタ(`tabindex="-1"` と `disabled` を除く) |
129
+ | `FOCUSABLE_SELECTOR` | 上記で使うセレクタ(`tabindex="-1"` と `disabled` を除く。`contenteditable` / `audio[controls]` / `video[controls]` / `summary` / `iframe` を含む) |
128
130
 
129
131
  `ModalBox`(Vue / React)はこれを使っています。
130
132
 
@@ -169,6 +171,13 @@ import type { Validates, Option, StateVariation, DateObject } from '@geckou/ui-c
169
171
 
170
172
  型の一覧は [Vue パッケージの README](../vue/README.md#types) を参照してください。
171
173
 
174
+ ## 0.7.0 の変更
175
+
176
+ - `normalizeDateObject()` を追加(`DatePicker` が blur 時の正規化に使う)
177
+ - `FOCUSABLE_SELECTOR` に `[contenteditable]` / `audio[controls]` / `video[controls]` /
178
+ `summary` / `iframe` を追加。ダイアログ末尾がリッチエディタや埋め込みのときに
179
+ その手前で折り返していたのが直る
180
+
172
181
  ## 0.6.0 の変更
173
182
 
174
183
  - `modal-stack` を追加(`createModalLayer`)。重なったモーダルのうち最前面の 1 枚を
package/dist/date.d.ts CHANGED
@@ -17,6 +17,13 @@ export declare function splitDate(value: string): DateObject;
17
17
  * 月・日は 2 桁へゼロ埋めする('2024-1-5' ではなく '2024-01-05')
18
18
  */
19
19
  export declare function composeDateValue(dateObject: DateObject, type?: DateType): string;
20
+ /**
21
+ * 月・日を 2 桁へゼロ埋めする('1' → '01')。年はそのまま。
22
+ *
23
+ * 入力途中の値をそのまま検証すると「月は2桁の数字で入力してください」になるため、
24
+ * 欄を離れた時点でこれを通してから検証する
25
+ */
26
+ export declare function normalizeDateObject(dateObject: DateObject): DateObject;
20
27
  /**
21
28
  * 年・月・日の入力内容を検証する。
22
29
  * type='month' のときは日を見ない。
package/dist/date.js CHANGED
@@ -85,6 +85,20 @@ export function composeDateValue(dateObject, type = 'date') {
85
85
  const [yearPart, ...rest] = parts;
86
86
  return [yearPart, ...rest.map((part) => pad(Number(part)))].join('-');
87
87
  }
88
+ /**
89
+ * 月・日を 2 桁へゼロ埋めする('1' → '01')。年はそのまま。
90
+ *
91
+ * 入力途中の値をそのまま検証すると「月は2桁の数字で入力してください」になるため、
92
+ * 欄を離れた時点でこれを通してから検証する
93
+ */
94
+ export function normalizeDateObject(dateObject) {
95
+ const padPart = (value) => value.length === 1 && isNumeric(value) ? pad(Number(value)) : value;
96
+ return {
97
+ year: dateObject.year,
98
+ month: padPart(dateObject.month),
99
+ day: padPart(dateObject.day),
100
+ };
101
+ }
88
102
  /**
89
103
  * 年・月・日の入力内容を検証する。
90
104
  * type='month' のときは日を見ない。
@@ -15,6 +15,13 @@ export const FOCUSABLE_SELECTOR = [
15
15
  'input:not([disabled]):not([type="hidden"])',
16
16
  'select:not([disabled])',
17
17
  'textarea:not([disabled])',
18
+ // 既定でフォーカスを受ける要素。漏らすと、ダイアログの末尾がリッチエディタ
19
+ // (contenteditable)や埋め込み(iframe)のときにその手前で折り返してしまう
20
+ '[contenteditable]:not([contenteditable="false"])',
21
+ 'audio[controls]',
22
+ 'video[controls]',
23
+ 'summary',
24
+ 'iframe',
18
25
  '[tabindex]:not([tabindex="-1"])',
19
26
  ].join(', ');
20
27
  /**
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@geckou/ui-core",
3
- "version": "0.6.0",
3
+ "version": "0.7.0",
4
4
  "description": "Framework-agnostic logic shared by @geckou/ui-vue and @geckou/ui-react",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",