@radishland/runtime 0.4.1 → 0.4.2

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.
Files changed (2) hide show
  1. package/client/index.js +25 -19
  2. package/package.json +1 -1
package/client/index.js CHANGED
@@ -165,6 +165,7 @@ var HandlerRegistry = class extends HTMLElement {
165
165
  target.setAttribute(attribute, `${ref}`);
166
166
  }
167
167
  });
168
+ target.removeAttribute("attr:" + attribute);
168
169
  e.stopPropagation();
169
170
  }
170
171
  }
@@ -177,6 +178,7 @@ var HandlerRegistry = class extends HTMLElement {
177
178
  this.effect(() => {
178
179
  target.toggleAttribute(attribute, ref.valueOf());
179
180
  });
181
+ target.removeAttribute("bool:" + attribute);
180
182
  e.stopPropagation();
181
183
  }
182
184
  }
@@ -184,8 +186,9 @@ var HandlerRegistry = class extends HTMLElement {
184
186
  #handleOn(e) {
185
187
  if (e instanceof CustomEvent) {
186
188
  const { identifier, type: type2, target } = e.detail;
187
- if (identifier in this && typeof this.lookup(identifier) === "function") {
189
+ if (identifier in this && target instanceof HTMLElement && typeof this.lookup(identifier) === "function") {
188
190
  target.addEventListener(type2, this.lookup(identifier).bind(this));
191
+ target.removeAttribute("on:" + type2);
189
192
  e.stopPropagation();
190
193
  }
191
194
  }
@@ -193,21 +196,19 @@ var HandlerRegistry = class extends HTMLElement {
193
196
  #handleClass(e) {
194
197
  if (e instanceof CustomEvent) {
195
198
  const { identifier, target } = e.detail;
196
- if (identifier in this) {
199
+ if (identifier in this && target instanceof HTMLElement) {
197
200
  this.effect(() => {
198
201
  const classList = this.lookup(identifier)?.valueOf();
199
- if (classList && typeof classList === "object") {
202
+ if (target instanceof HTMLElement && classList && typeof classList === "object") {
200
203
  for (const [k, v] of Object.entries(classList)) {
201
204
  const force = !!v?.valueOf();
202
205
  for (const className of k.split(" ")) {
203
- target.classList.toggle(
204
- className,
205
- force
206
- );
206
+ target.classList.toggle(className, force);
207
207
  }
208
208
  }
209
209
  }
210
210
  });
211
+ target.removeAttribute("classList");
211
212
  e.stopPropagation();
212
213
  }
213
214
  }
@@ -215,11 +216,12 @@ var HandlerRegistry = class extends HTMLElement {
215
216
  #handleUse(e) {
216
217
  if (e instanceof CustomEvent) {
217
218
  const { identifier, target } = e.detail;
218
- if (identifier in this && typeof this.lookup(identifier) === "function") {
219
+ if (identifier in this && typeof this.lookup(identifier) === "function" && target instanceof HTMLElement) {
219
220
  const cleanup = this.lookup(identifier).bind(this)(target);
220
221
  if (typeof cleanup === "function") {
221
222
  this.#cleanup.push(cleanup);
222
223
  }
224
+ target.removeAttribute("use:" + identifier);
223
225
  e.stopPropagation();
224
226
  }
225
227
  }
@@ -227,7 +229,7 @@ var HandlerRegistry = class extends HTMLElement {
227
229
  #handleProp(e) {
228
230
  if (e instanceof CustomEvent) {
229
231
  const { identifier, property, target } = e.detail;
230
- if (identifier in this && property in target) {
232
+ if (identifier in this && property in target && target instanceof HTMLElement) {
231
233
  const ref = this.lookup(identifier);
232
234
  this.effect(() => {
233
235
  if (isState(target[property])) {
@@ -236,6 +238,7 @@ var HandlerRegistry = class extends HTMLElement {
236
238
  target[property] = ref.valueOf();
237
239
  }
238
240
  });
241
+ target.removeAttribute("prop:" + property);
239
242
  e.stopPropagation();
240
243
  }
241
244
  }
@@ -248,6 +251,7 @@ var HandlerRegistry = class extends HTMLElement {
248
251
  this.effect(() => {
249
252
  target.textContent = `${ref}`;
250
253
  });
254
+ target.removeAttribute("text");
251
255
  e.stopPropagation();
252
256
  }
253
257
  }
@@ -260,6 +264,7 @@ var HandlerRegistry = class extends HTMLElement {
260
264
  this.effect(() => {
261
265
  target.innerHTML = `${ref}`;
262
266
  });
267
+ target.removeAttribute("html");
263
268
  e.stopPropagation();
264
269
  }
265
270
  }
@@ -278,6 +283,7 @@ var HandlerRegistry = class extends HTMLElement {
278
283
  target[property] = state.value;
279
284
  });
280
285
  }
286
+ target.removeAttribute("bind:" + property);
281
287
  e.stopPropagation();
282
288
  }
283
289
  }
@@ -430,11 +436,11 @@ var HandlerRegistry = class extends HTMLElement {
430
436
  this.hydrate(node.shadowRoot);
431
437
  console.log("exiting shadow root");
432
438
  }
433
- let child = node.firstElementChild;
434
- while (child) {
435
- this.hydrate(child);
436
- child = child.nextElementSibling;
437
- }
439
+ }
440
+ let child = node.firstChild;
441
+ while (child) {
442
+ this.hydrate(child);
443
+ child = child.nextSibling;
438
444
  }
439
445
  }
440
446
  connectedCallback() {
@@ -468,13 +474,13 @@ customElements?.whenDefined("handler-registry").then(() => {
468
474
  return node instanceof HandlerRegistry ? NodeFilter.FILTER_ACCEPT : NodeFilter.FILTER_SKIP;
469
475
  }
470
476
  );
471
- let current = tw.currentNode;
472
- while (current && !(current instanceof HandlerRegistry)) {
477
+ let current = tw.firstChild();
478
+ while (current) {
479
+ if (current instanceof HandlerRegistry) {
480
+ current.hydrate();
481
+ }
473
482
  current = tw.nextNode();
474
483
  }
475
- if (current) {
476
- current.hydrate();
477
- }
478
484
  });
479
485
 
480
486
  export { HandlerRegistry, computed, effect, isState, reactive, signal };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@radishland/runtime",
3
- "version": "0.4.1",
3
+ "version": "0.4.2",
4
4
  "type": "module",
5
5
  "description": "The Radish runtime",
6
6
  "author": "Frédéric Crozatier",