haori 0.68.0 → 0.70.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.ja.md +3 -2
- package/README.md +3 -2
- package/dist/haori.cjs.js +22 -22
- package/dist/haori.es.js +1374 -1250
- package/dist/haori.iife.js +22 -22
- package/dist/index.d.ts +52 -1
- package/package.json +1 -1
package/README.ja.md
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
Haori.js は、HTML 属性を中心にして動的な UI を実現する軽量なライブラリです。JavaScript をほとんど書かずに、データバインディング、条件分岐、繰り返し処理、フォームの双方向バインディング、サーバー通信などを HTML 属性で宣言できます。
|
|
4
4
|
|
|
5
|
-
バージョン: 0.
|
|
5
|
+
バージョン: 0.70.0
|
|
6
6
|
|
|
7
7
|
---
|
|
8
8
|
|
|
@@ -137,6 +137,7 @@ Haori.mount(document.body, {items: [{name: 'りんご'}, {name: 'みかん'}]});
|
|
|
137
137
|
- **CSS セレクタ**を値に取る属性(`data-{event}-bind`・`-form`・`-copy`・`-copy-source`・`-reset`・`-refetch`・`-click`・`-open`・`-close`・`-adjust`・`-row-*`・`data-fetch-bind`・`data-fetch-state` など)は、照会の前に `{{ ... }}` を評価します。`data-each` の行の中から「その行の要素」を対象にでき(`id="plan-scope-{{i}}"` と `data-change-bind="#plan-scope-{{i}}"` の組み合わせ)、行ごとのバインドや住所複写が属性だけで書けます。不正なセレクタは例外にせずログしてスキップし、単体プレースホルダの未解決参照は「値の指定なし」として扱います(値を省略したときの既定動作になります)。`-bind-arg`・`-copy-params` のようなキー名を並べる属性は評価しません。
|
|
138
138
|
- `data-click-copy-source` — `data-click-copy` のコピー元要素を明示指定します(既定は `data-click-form` のフォーム、無ければイベント発火元の binding)。
|
|
139
139
|
- `data-click-no-disabled` / `data-click-defer` — 他ライブラリとの併用補助です。`no-disabled` はクリック手続き実行中に `disabled` 属性を付与せず実行します(Bootstrap collapse など disabled 要素を無視するライブラリ・CSS が動作し続けます。多重実行は内部マーカーで防止)。`defer` はクリック手続きを次フレーム(`requestAnimationFrame`/`setTimeout(0)`)で実行し、他ライブラリの同期 click ハンドラを先に完了させます。遅延後は `preventDefault()` できないため、`<a href>` や `type="submit"` への `defer` 併用は避けてください。
|
|
140
|
+
- `data-click-lock="名前"` — 同じ名前の要素で、`click` 手続きの実行中のロックを 1 つ共有します。どれかの手続きが実行中の間は、同じ名前のほかの要素を押しても手続きを実行せず、それらの要素にも `disabled` を付けます(`data-click-no-disabled` を付けた要素には付けません)。終わると各要素の `data-attr-disabled` の評価結果へ揃えます。同じものを書き換える別々のボタン(「休憩開始」と「退勤」など)を、遅い応答を待つ間に続けて押しても、両方が走りません。名前は文書全体で共有し、名前の無い要素は今までどおり要素ごとのロックです。
|
|
140
141
|
- `data-{event}-click-await` — `data-{event}-click` が起動した手続きの完了を待ってから次の対象をクリックします。複数の更新を**宣言した順に直列で**送り(`#b, #a` のようにカンマで区切った対象は、文書の並びによらず書いた順に押します)、**いずれかが失敗した時点で後続を止めます**(HTTP エラー・通信の例外・検証エラー・確認ダイアログのキャンセル)。表示順を 2 件更新する並べ替えが JavaScript なしで書けます。止めた場合は呼び出し元の後続アクション(ダイアログ・トースト・リダイレクト)も実行しません。`data-{event}-if` が偽でスキップされた対象は失敗として扱いません。手続きが同期に起動しない対象(`data-click-defer`、クリックが発火しない `disabled` 要素)は待てず、その旨を記録します。
|
|
141
142
|
- `data-{event}-error-click` / `-error-click-await` / `-error-close` / `-error-toast` / `-error-toast-level` / `-error-status` / `-error-no-message` / `-error-bind` — 取得が失敗したとき(2xx 以外の応答と通信の例外。認証ガードで遷移する 401 / 403 を除く)にだけ、別要素のクリック・ダイアログを閉じる・トーストをこの順に実行します。「取り直しが 404 なら、ダイアログを閉じて検索し直す」が JavaScript なしで書けます。`-error-status="404&410"` で対象のステータスを絞れます(宣言すると通信の例外は対象外)。実行しても手続きは失敗のままで、エラー表示も今までどおり行います(`-error-no-message` で止められます)。`-error-bind` を宣言すると、応答本文を表示する代わりに `data-{event}-bind` と同じ規則でバインドします(400 で返る検証結果を表に出すなど)。応答本文のサーバのメッセージは `_fetch.responseMessage` で参照でき、`data-click-error-toast="{{_fetch.responseMessage}}"` でトーストに出せます。`data-click-error-404-close` のようにステータスを付けた組(`-click` / `-click-await` / `-close` / `-toast` / `-toast-level` / `-no-message` / `-bind`)は、そのステータスの失敗でだけ、ステータスの付かない属性の代わりに使います。`-toast-level` と `-error-toast-level` には式を書けます(例: `{{_fetch.statusCode === 409 ? 'warning' : 'error'}}`)。`data-poll-*` と非イベントの `data-fetch` では、応答本文の表示を止める宣言(`data-fetch-error-no-message` / `data-poll-error-no-message` と、その `-error-status`・`-error-{ステータス}-no-message`)だけを使えます。
|
|
142
143
|
- `data-{event}-clear-messages` — 取得が成功したときに、前回の失敗の表示を消します(範囲は失敗の表示と同じ)。値・バインドデータには触れないため、検索の条件を残したまま、前回の失敗の文言だけを消せます。ダウンロード(`-fetch-download`)では保存に成功した後に消します。
|
|
@@ -166,7 +167,7 @@ JS からバインドデータを読むには `Haori.Core.getBindingData(element
|
|
|
166
167
|
|
|
167
168
|
開発モードは `<script src="haori.js" data-dev>` で強制でき、**ローカルホストでは既定で有効**です。開発モードの診断は再描画のコストに乗るため、ローカルで本番相当の性能を測る場合は `data-dev="false"` を指定して無効化してください。
|
|
168
169
|
|
|
169
|
-
`data-fetch` と `data-import` は、バインディング更新時に評価結果が変化した場合のみ自動で再評価されます。`data-fetch` は評価後の URL、HTTP メソッド、ヘッダー、body を含む実行シグネチャで比較し、`data-import` は評価後 URL で比較します。これらの属性値に未解決参照が 1
|
|
170
|
+
`data-fetch` と `data-import` は、バインディング更新時に評価結果が変化した場合のみ自動で再評価されます。`data-fetch` は評価後の URL、HTTP メソッド、ヘッダー、body を含む実行シグネチャで比較し、`data-import` は評価後 URL で比較します。これらの属性値に未解決参照が 1 つでも含まれる場合、その時点では実行されず、後続のバインディング更新で参照が解決したときに初めて実行対象になります。`data-{event}-refetch` は、手続きのバインドの後に対象の要素で同じ条件の自動の取得が走った場合は取り直しません(条件を変えて押しても取得は 1 回です)。
|
|
170
171
|
|
|
171
172
|
`src` や `type="number"` の `value` のように、ブラウザが HTML 解析時に先に解釈する属性へテンプレート式を直接書くと、初期表示時に警告や不要なアクセスが発生することがあります。こうした属性は `data-attr-*` を使ってください。`data-attr-xxx` は対応する `xxx` 属性を更新します。加えて、入力欄の状態と DOM の食い違いを防ぐため、`value`(テキスト系入力)と `checked`(radio / checkbox)・`selected`(option)は DOM property(`input.value` / `element.checked` / `option.selected`)も同期します。ただし**フォーカス中(編集中)の入力**と、**`change` / `input` で確定した編集を抱えている入力**には再適用しません(利用者の入力を守るため)。確定した編集の印は、フェッチ応答の反映・`data-{event}-reset`・`Core.setBindingData()` などの明示的な値の供給で解除されます。
|
|
172
173
|
|
package/README.md
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
Haori.js is a lightweight, HTML-first UI library that enables dynamic user interfaces primarily through HTML attributes. It lets you declare data bindings, conditional rendering, list rendering, form two-way binding, server fetches, and HTML imports without writing much JavaScript.
|
|
4
4
|
|
|
5
|
-
Version: 0.
|
|
5
|
+
Version: 0.70.0
|
|
6
6
|
|
|
7
7
|
---
|
|
8
8
|
|
|
@@ -137,6 +137,7 @@ Event-driven actions:
|
|
|
137
137
|
- Attributes that take a **CSS selector** (`data-{event}-bind`, `-form`, `-copy`, `-copy-source`, `-reset`, `-refetch`, `-click`, `-open`, `-close`, `-adjust`, `-row-*`, `data-fetch-bind`, `data-fetch-state`, …) evaluate `{{ ... }}` before querying, so a row inside `data-each` can target *its own* elements (`data-change-bind="#plan-scope-{{i}}"` paired with `id="plan-scope-{{i}}"`). An invalid selector is logged and skipped instead of throwing, and an unresolved single placeholder is treated as "no value given" (falling back to the attribute's default behaviour). Key-list attributes such as `-bind-arg` / `-copy-params` are not evaluated.
|
|
138
138
|
- `data-click-copy-source` — explicitly set the copy source element for `data-click-copy` (defaults to the form given by `data-click-form`, otherwise the event element's binding).
|
|
139
139
|
- `data-click-no-disabled` / `data-click-defer` — coexistence helpers for other libraries. `no-disabled` runs the click procedure without adding the `disabled` attribute (so libraries/CSS that ignore disabled elements, e.g. Bootstrap collapse, keep working; double execution is still prevented internally). `defer` runs the click procedure on the next frame (`requestAnimationFrame`/`setTimeout(0)`) so other libraries' synchronous click handlers complete first. Avoid `defer` on `<a href>` / `type="submit"` because the deferred procedure cannot `preventDefault()` the default action.
|
|
140
|
+
- `data-click-lock="name"` — share one running-procedure lock among elements with the same name. While any of their `click` procedures is running, clicking another element with the same name does not run its procedure, and those elements get `disabled` (except with `data-click-no-disabled`); afterwards each one returns to the result of its own `data-attr-disabled`. This stops separate buttons that update the same thing (for example "start break" and "clock out") from both running while a slow response is pending. Names are shared across the document; elements without a name keep the per-element lock.
|
|
140
141
|
- `data-{event}-click-await` — wait for the procedure started by `data-{event}-click` before clicking the next target, so several updates are sent **serially in declaration order** (comma-separated targets such as `#b, #a` are clicked in the written order, regardless of document order) and **the rest is stopped as soon as one fails** (HTTP error, network exception, validation error, or a cancelled confirmation). Row reordering that has to persist two display orders no longer needs JavaScript. When it stops, the calling procedure also skips its remaining actions (dialog, toast, redirect). A target skipped by a false `data-{event}-if` is not a failure. Targets whose procedure does not start synchronously (`data-click-defer`, or a `disabled` element that fires no click) cannot be waited for; that is logged.
|
|
141
142
|
- `data-{event}-error-click` / `-error-click-await` / `-error-close` / `-error-toast` / `-error-toast-level` / `-error-status` / `-error-no-message` / `-error-bind` — run a click on another element, a dialog close and a toast, in that order, only when the fetch fails (a non-2xx response or a network exception, except 401 / 403 handled by the auth guard redirect). "If the reload returns 404, close the dialog and search again" no longer needs JavaScript. `-error-status="404&410"` narrows the statuses (once declared, network exceptions are excluded). The procedure still ends as a failure and the error display works as before, unless `-error-no-message` turns it off. `-error-bind` binds the response body by the same rules as `data-{event}-bind` instead of showing it (for example, a validation result returned with 400). The server's message in the response body is available as `_fetch.responseMessage`, so `data-click-error-toast="{{_fetch.responseMessage}}"` shows it in a toast. A group with a status in its name, such as `data-click-error-404-close` (`-click` / `-click-await` / `-close` / `-toast` / `-toast-level` / `-no-message` / `-bind`), replaces the attributes without a status only for failures with that status. `-toast-level` and `-error-toast-level` accept expressions (for example `{{_fetch.statusCode === 409 ? 'warning' : 'error'}}`). On `data-poll-*` and the non-event `data-fetch`, only the declarations that turn off the error display are read (`data-fetch-error-no-message` / `data-poll-error-no-message`, with their `-error-status` and `-error-{status}-no-message`).
|
|
142
143
|
- `data-{event}-clear-messages` — on a successful fetch, clear the messages left by the previous failure (in the same scope the failure was shown in). Input values and binding data are untouched, so a search form keeps its conditions while the stale error disappears. With `-fetch-download` it clears after the file is saved.
|
|
@@ -168,7 +169,7 @@ Helpers for tests and debugging: `waitForRenders()` (also `Haori.waitForRenders(
|
|
|
168
169
|
|
|
169
170
|
Dev mode can be forced with `<script src="haori.js" data-dev>` and is **enabled by default on localhost**. Its diagnostics add to render cost, so pass `data-dev="false"` when measuring production-like performance locally.
|
|
170
171
|
|
|
171
|
-
`data-fetch` and `data-import` are automatically re-evaluated only when their evaluated values change after a binding update. `data-fetch` compares a request signature composed of the resolved URL, HTTP method, headers, and body, while `data-import` compares only the resolved URL. If either attribute contains even one unresolved reference, it is treated as invalid for that evaluation cycle, is not executed, and becomes executable only after a later binding update resolves the reference.
|
|
172
|
+
`data-fetch` and `data-import` are automatically re-evaluated only when their evaluated values change after a binding update. `data-fetch` compares a request signature composed of the resolved URL, HTTP method, headers, and body, while `data-import` compares only the resolved URL. If either attribute contains even one unresolved reference, it is treated as invalid for that evaluation cycle, is not executed, and becomes executable only after a later binding update resolves the reference. `data-{event}-refetch` skips an element whose automatic fetch already ran with the same signature after the procedure's bind (changing the condition and clicking still fetches once).
|
|
172
173
|
|
|
173
174
|
When the browser interprets an attribute during HTML parsing, such as `src` or `value` on `input type="number"`, writing template expressions directly in that attribute can cause warnings or unwanted requests before Haori runs. Use `data-attr-*` for those cases. `data-attr-xxx` updates the matching `xxx` attribute, and to keep input state consistent with the DOM it also synchronizes DOM properties for `value` (text inputs), `checked` (radio / checkbox) and `selected` (option). These properties are **not** re-applied to a focused (being-edited) input, nor to an input that holds an edit committed through `change` / `input`, so user input is never rolled back. The committed-edit mark is cleared by an explicit supply of values (fetch response binding, `data-{event}-reset`, `data-{event}-copy`, `Core.setBindingData()`).
|
|
174
175
|
|