@peektravel/app-utilities 0.5.2 → 0.5.4

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.
@@ -858,7 +858,9 @@ interface OdyCheckboxOption {
858
858
  * indeterminate when some are, and toggling it selects/clears every child.
859
859
  *
860
860
  * Attributes:
861
- * - `options` — JSON array, e.g. `options='[{"label":"A","value":"a"}]'`.
861
+ * - `options` — JSON array, e.g. `options='[{"label":"A","value":"a"}]'`. Also
862
+ * a settable JS property ({@link options}): `el.options = [...]` mirrors
863
+ * `<ody-dropdown-*>` and writes the JSON attribute.
862
864
  * - `value` — comma-separated selected values (also a JS array property,
863
865
  * {@link value}).
864
866
  * - `select-all-label` — when present, renders the parent select-all row.
@@ -875,6 +877,13 @@ declare class OdyCheckboxGroup extends OdyElement {
875
877
  set value(next: string[]);
876
878
  /** Parsed `options`; malformed JSON yields an empty list. */
877
879
  get options(): OdyCheckboxOption[];
880
+ /**
881
+ * Accepts an array of `{ label, value }` and stores it as the JSON `options`
882
+ * attribute. Mirrors `<ody-dropdown-*>` so `el.options = [...]` works across
883
+ * the data-driven elements. `options` is observed, so this triggers a
884
+ * re-render via `attributeChangedCallback`.
885
+ */
886
+ set options(next: OdyCheckboxOption[]);
878
887
  protected render(): void;
879
888
  }
880
889
 
@@ -858,7 +858,9 @@ interface OdyCheckboxOption {
858
858
  * indeterminate when some are, and toggling it selects/clears every child.
859
859
  *
860
860
  * Attributes:
861
- * - `options` — JSON array, e.g. `options='[{"label":"A","value":"a"}]'`.
861
+ * - `options` — JSON array, e.g. `options='[{"label":"A","value":"a"}]'`. Also
862
+ * a settable JS property ({@link options}): `el.options = [...]` mirrors
863
+ * `<ody-dropdown-*>` and writes the JSON attribute.
862
864
  * - `value` — comma-separated selected values (also a JS array property,
863
865
  * {@link value}).
864
866
  * - `select-all-label` — when present, renders the parent select-all row.
@@ -875,6 +877,13 @@ declare class OdyCheckboxGroup extends OdyElement {
875
877
  set value(next: string[]);
876
878
  /** Parsed `options`; malformed JSON yields an empty list. */
877
879
  get options(): OdyCheckboxOption[];
880
+ /**
881
+ * Accepts an array of `{ label, value }` and stores it as the JSON `options`
882
+ * attribute. Mirrors `<ody-dropdown-*>` so `el.options = [...]` works across
883
+ * the data-driven elements. `options` is observed, so this triggers a
884
+ * re-render via `attributeChangedCallback`.
885
+ */
886
+ set options(next: OdyCheckboxOption[]);
878
887
  protected render(): void;
879
888
  }
880
889
 
package/dist/ui/index.js CHANGED
@@ -160,9 +160,43 @@ function classes(...parts) {
160
160
  function reflectControlValue(control, value) {
161
161
  if (control && control.value !== value) control.value = value;
162
162
  }
163
+ function attrNameFor(propName) {
164
+ return propName.replace(/([a-z0-9])([A-Z])/g, "$1-$2").toLowerCase();
165
+ }
166
+ function reflectToAttribute(el, attr, value) {
167
+ if (value === null || value === void 0 || value === false) {
168
+ el.removeAttribute(attr);
169
+ } else if (value === true) {
170
+ el.setAttribute(attr, "");
171
+ } else if (typeof value === "object") {
172
+ el.setAttribute(attr, JSON.stringify(value));
173
+ } else {
174
+ el.setAttribute(attr, String(value));
175
+ }
176
+ }
177
+ function addReactSafeSetters(ctor) {
178
+ const observed = new Set(
179
+ ctor.observedAttributes ?? []
180
+ );
181
+ let proto = ctor.prototype;
182
+ while (proto && proto !== OdyElement.prototype && proto !== HTMLElement.prototype && proto !== Object.prototype) {
183
+ for (const [name, desc] of Object.entries(Object.getOwnPropertyDescriptors(proto))) {
184
+ if (typeof desc.get !== "function" || desc.set) continue;
185
+ const attr = attrNameFor(name);
186
+ const set = observed.has(attr) ? function reflectingSetter(value) {
187
+ reflectToAttribute(this, attr, value);
188
+ } : function ignoringSetter() {
189
+ };
190
+ Object.defineProperty(proto, name, { ...desc, set });
191
+ }
192
+ proto = Object.getPrototypeOf(proto);
193
+ }
194
+ }
163
195
  function define(tag, ctor) {
164
196
  if (typeof customElements === "undefined") return;
165
- if (!customElements.get(tag)) customElements.define(tag, ctor);
197
+ if (customElements.get(tag)) return;
198
+ addReactSafeSetters(ctor);
199
+ customElements.define(tag, ctor);
166
200
  }
167
201
 
168
202
  // src/ui/icons-data.ts
@@ -1958,6 +1992,15 @@ var OdyCheckboxGroup = class extends OdyElement {
1958
1992
  get options() {
1959
1993
  return parseOptions2(this.attr("options"));
1960
1994
  }
1995
+ /**
1996
+ * Accepts an array of `{ label, value }` and stores it as the JSON `options`
1997
+ * attribute. Mirrors `<ody-dropdown-*>` so `el.options = [...]` works across
1998
+ * the data-driven elements. `options` is observed, so this triggers a
1999
+ * re-render via `attributeChangedCallback`.
2000
+ */
2001
+ set options(next) {
2002
+ this.setAttribute("options", JSON.stringify(Array.isArray(next) ? next : []));
2003
+ }
1961
2004
  render() {
1962
2005
  const size = this.attr("size", "small");
1963
2006
  const isDisabled = this.flag("disabled");