@peektravel/app-utilities 0.5.2 → 0.5.3

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/ui/index.cjs CHANGED
@@ -162,9 +162,43 @@ function classes(...parts) {
162
162
  function reflectControlValue(control, value) {
163
163
  if (control && control.value !== value) control.value = value;
164
164
  }
165
+ function attrNameFor(propName) {
166
+ return propName.replace(/([a-z0-9])([A-Z])/g, "$1-$2").toLowerCase();
167
+ }
168
+ function reflectToAttribute(el, attr, value) {
169
+ if (value === null || value === void 0 || value === false) {
170
+ el.removeAttribute(attr);
171
+ } else if (value === true) {
172
+ el.setAttribute(attr, "");
173
+ } else if (typeof value === "object") {
174
+ el.setAttribute(attr, JSON.stringify(value));
175
+ } else {
176
+ el.setAttribute(attr, String(value));
177
+ }
178
+ }
179
+ function addReactSafeSetters(ctor) {
180
+ const observed = new Set(
181
+ ctor.observedAttributes ?? []
182
+ );
183
+ let proto = ctor.prototype;
184
+ while (proto && proto !== OdyElement.prototype && proto !== HTMLElement.prototype && proto !== Object.prototype) {
185
+ for (const [name, desc] of Object.entries(Object.getOwnPropertyDescriptors(proto))) {
186
+ if (typeof desc.get !== "function" || desc.set) continue;
187
+ const attr = attrNameFor(name);
188
+ const set = observed.has(attr) ? function reflectingSetter(value) {
189
+ reflectToAttribute(this, attr, value);
190
+ } : function ignoringSetter() {
191
+ };
192
+ Object.defineProperty(proto, name, { ...desc, set });
193
+ }
194
+ proto = Object.getPrototypeOf(proto);
195
+ }
196
+ }
165
197
  function define(tag, ctor) {
166
198
  if (typeof customElements === "undefined") return;
167
- if (!customElements.get(tag)) customElements.define(tag, ctor);
199
+ if (customElements.get(tag)) return;
200
+ addReactSafeSetters(ctor);
201
+ customElements.define(tag, ctor);
168
202
  }
169
203
 
170
204
  // src/ui/icons-data.ts