@wcstack/fetch 4.0.0-rc.8 → 4.0.0-rc.9

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/dist/index.esm.js CHANGED
@@ -941,6 +941,61 @@ function upgradeProperties(element) {
941
941
  }
942
942
  }
943
943
 
944
+ // ===========================================================================
945
+ // AUTO-GENERATED FILE - DO NOT EDIT.
946
+ // Generated from /protocol/input-attribute.ts by scripts/sync-protocol-types.mjs.
947
+ // Run `node scripts/sync-protocol-types.mjs` after editing the source.
948
+ // ===========================================================================
949
+ // 属性へ反映する wc-bindable 入力の producer 側(SPEC-extensions § Producer guidance for inputs の P1〜P3)。
950
+ // 入力の setter は属性をこの 2 関数で書く。それで次が揃う:
951
+ // - `undefined` は「値が無い」(P1): 属性を、この関数で最初に書く前の状態 — マークアップに書かれた値、
952
+ // 無ければ属性なし(= その入力の文書化した既定値)— へ戻す。applier プロファイルを宣言する binder は
953
+ // 値の後の `undefined` を書き(A2)、React 19 も書き、直接の代入でも届く。
954
+ // - `null` はクリア(P2): 属性なし、つまり文書化した既定値。
955
+ // - どちらも文字列 "undefined" / "null" として属性に入らない。
956
+ //
957
+ // 「最初に書く前」は、その最初の書き込みのときに読む(遅延)。upgrade 前に代入されたプロパティは
958
+ // connectedCallback の upgradeProperties() が通し直すので、そのときにはパーサが書いた属性が揃っている。
959
+ // 要素自身が setter を通さずに書いた属性は、最初の書き込みより前なら「最初の状態」に含まれる。
960
+ //
961
+ // SINGLE SOURCE OF TRUTH: edit only this file (/protocol/input-attribute.ts), then run
962
+ // `node scripts/sync-protocol-types.mjs` to regenerate the per-package copies
963
+ // (packages/<pkg>/src/protocol/inputAttribute.ts). Those copies are generated — do not edit them.
964
+ const initialAttributes = new WeakMap();
965
+ /** The attribute as it stood before the first write through these helpers. */
966
+ function initialAttribute(el, name) {
967
+ let byName = initialAttributes.get(el);
968
+ if (byName === undefined) {
969
+ byName = new Map();
970
+ initialAttributes.set(el, byName);
971
+ }
972
+ if (!byName.has(name))
973
+ byName.set(name, el.getAttribute(name));
974
+ return byName.get(name);
975
+ }
976
+ function writeAttribute(el, name, value) {
977
+ if (value === null)
978
+ el.removeAttribute(name);
979
+ else
980
+ el.setAttribute(name, value);
981
+ }
982
+ /**
983
+ * A value attribute. `value` is written as `String(value)`; `null` removes the attribute;
984
+ * `undefined` restores the attribute the element started with.
985
+ */
986
+ function reflectAttribute(el, name, value) {
987
+ const initial = initialAttribute(el, name);
988
+ writeAttribute(el, name, value === undefined ? initial : value === null ? null : String(value));
989
+ }
990
+ /**
991
+ * A boolean attribute, present while `value` is truthy (`null` and `false` remove it);
992
+ * `undefined` restores the attribute the element started with.
993
+ */
994
+ function reflectBooleanAttribute(el, name, value) {
995
+ const initial = initialAttribute(el, name);
996
+ writeAttribute(el, name, value === undefined ? initial : value ? "" : null);
997
+ }
998
+
944
999
  /**
945
1000
  * Trusted Types (`require-trusted-types-for 'script'`) 対応。正本は docs/csp.md §7。
946
1001
  *
@@ -1059,8 +1114,8 @@ class Fetch extends HTMLElement {
1059
1114
  ],
1060
1115
  // Shell-level input surface. The Core declares only the portable `url` / `method`;
1061
1116
  // the Shell adds the DOM-driven settable surface. No `attribute` hints are given:
1062
- // these setters already reflect to their attributes themselves, so a binding system
1063
- // that mirrors inputs[].attribute would set the attribute twice. `commands`
1117
+ // these setters reflect to their attributes themselves, and a binding system that
1118
+ // mirrored inputs[].attribute (@wcstack/state 3.x) would set the attribute twice. `commands`
1064
1119
  // (fetch / abort) are inherited unchanged from the Core via the spread above.
1065
1120
  inputs: [
1066
1121
  { name: "url" },
@@ -1144,42 +1199,28 @@ class Fetch extends HTMLElement {
1144
1199
  });
1145
1200
  }
1146
1201
  }
1147
- // Input setters normalize null/undefined to attribute removal instead of
1148
- // letting setAttribute stringify them ("undefined" url would auto-fetch
1149
- // /undefined, "undefined" method is an invalid HTTP method). The binder
1150
- // already skips undefined writes; this guards direct JS assignment too.
1202
+ // Input setters never let setAttribute stringify null / undefined ("undefined"
1203
+ // url would auto-fetch /undefined, "undefined" method is an invalid HTTP
1204
+ // method): `null` removes the attribute (the default), `undefined` restores
1205
+ // the attribute the element started with (wc-bindable producer guidance P1;
1206
+ // React 19 and a direct assignment deliver it, @wcstack/state does not).
1151
1207
  get url() {
1152
1208
  return this.getAttribute("url") || "";
1153
1209
  }
1154
1210
  set url(value) {
1155
- if (value == null) {
1156
- this.removeAttribute("url");
1157
- }
1158
- else {
1159
- this.setAttribute("url", value);
1160
- }
1211
+ reflectAttribute(this, "url", value);
1161
1212
  }
1162
1213
  get method() {
1163
1214
  return (this.getAttribute("method") || "GET").toUpperCase();
1164
1215
  }
1165
1216
  set method(value) {
1166
- if (value == null) {
1167
- this.removeAttribute("method");
1168
- }
1169
- else {
1170
- this.setAttribute("method", value);
1171
- }
1217
+ reflectAttribute(this, "method", value);
1172
1218
  }
1173
1219
  get target() {
1174
1220
  return this.getAttribute("target");
1175
1221
  }
1176
1222
  set target(value) {
1177
- if (value == null) {
1178
- this.removeAttribute("target");
1179
- }
1180
- else {
1181
- this.setAttribute("target", value);
1182
- }
1223
+ reflectAttribute(this, "target", value);
1183
1224
  }
1184
1225
  // Response body interpretation. Backed by the `response-type` attribute so it is
1185
1226
  // settable from HTML, JS, or a binding. An unknown value falls through to the
@@ -1188,12 +1229,7 @@ class Fetch extends HTMLElement {
1188
1229
  return this.getAttribute("response-type") || "auto";
1189
1230
  }
1190
1231
  set responseType(value) {
1191
- if (value == null) {
1192
- this.removeAttribute("response-type");
1193
- }
1194
- else {
1195
- this.setAttribute("response-type", value);
1196
- }
1232
+ reflectAttribute(this, "response-type", value);
1197
1233
  }
1198
1234
  get value() {
1199
1235
  return this._core.value;
@@ -1223,12 +1259,7 @@ class Fetch extends HTMLElement {
1223
1259
  return this.hasAttribute("manual");
1224
1260
  }
1225
1261
  set manual(value) {
1226
- if (value) {
1227
- this.setAttribute("manual", "");
1228
- }
1229
- else {
1230
- this.removeAttribute("manual");
1231
- }
1262
+ reflectBooleanAttribute(this, "manual", value);
1232
1263
  }
1233
1264
  get body() {
1234
1265
  return this._body;