@radishland/runtime 0.4.2 → 0.5.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/client/index.js +83 -116
- package/package.json +4 -4
package/client/index.js
CHANGED
|
@@ -128,6 +128,11 @@ var object = (init) => {
|
|
|
128
128
|
};
|
|
129
129
|
|
|
130
130
|
// src/handler-registry.ts
|
|
131
|
+
var DirectiveEvent = class extends CustomEvent {
|
|
132
|
+
constructor(type2, detail) {
|
|
133
|
+
super(type2, { bubbles: true, composed: true, cancelable: true, detail });
|
|
134
|
+
}
|
|
135
|
+
};
|
|
131
136
|
var HandlerRegistry = class extends HTMLElement {
|
|
132
137
|
#cleanup = [];
|
|
133
138
|
/**
|
|
@@ -154,47 +159,47 @@ var HandlerRegistry = class extends HTMLElement {
|
|
|
154
159
|
return this[identifier];
|
|
155
160
|
}
|
|
156
161
|
#handleAttr(e) {
|
|
157
|
-
if (e instanceof
|
|
158
|
-
const { identifier,
|
|
159
|
-
if (identifier in this && target instanceof HTMLElement &&
|
|
162
|
+
if (e instanceof DirectiveEvent) {
|
|
163
|
+
const { identifier, key, target } = e.detail;
|
|
164
|
+
if (identifier in this && target instanceof HTMLElement && key in target) {
|
|
160
165
|
const ref = this.lookup(identifier);
|
|
161
166
|
this.effect(() => {
|
|
162
|
-
if (booleanAttributes.includes(
|
|
163
|
-
target.toggleAttribute(
|
|
167
|
+
if (booleanAttributes.includes(key)) {
|
|
168
|
+
target.toggleAttribute(key, ref.valueOf());
|
|
164
169
|
} else {
|
|
165
|
-
target.setAttribute(
|
|
170
|
+
target.setAttribute(key, `${ref}`);
|
|
166
171
|
}
|
|
167
172
|
});
|
|
168
|
-
target.removeAttribute("attr:" +
|
|
173
|
+
target.removeAttribute("attr:" + key);
|
|
169
174
|
e.stopPropagation();
|
|
170
175
|
}
|
|
171
176
|
}
|
|
172
177
|
}
|
|
173
178
|
#handleBool(e) {
|
|
174
|
-
if (e instanceof
|
|
175
|
-
const { identifier,
|
|
179
|
+
if (e instanceof DirectiveEvent) {
|
|
180
|
+
const { identifier, key, target } = e.detail;
|
|
176
181
|
if (identifier in this && target instanceof HTMLElement) {
|
|
177
182
|
const ref = this.lookup(identifier);
|
|
178
183
|
this.effect(() => {
|
|
179
|
-
target.toggleAttribute(
|
|
184
|
+
target.toggleAttribute(key, ref.valueOf());
|
|
180
185
|
});
|
|
181
|
-
target.removeAttribute("bool:" +
|
|
186
|
+
target.removeAttribute("bool:" + key);
|
|
182
187
|
e.stopPropagation();
|
|
183
188
|
}
|
|
184
189
|
}
|
|
185
190
|
}
|
|
186
191
|
#handleOn(e) {
|
|
187
|
-
if (e instanceof
|
|
188
|
-
const { identifier,
|
|
192
|
+
if (e instanceof DirectiveEvent) {
|
|
193
|
+
const { identifier, key, target } = e.detail;
|
|
189
194
|
if (identifier in this && target instanceof HTMLElement && typeof this.lookup(identifier) === "function") {
|
|
190
|
-
target.addEventListener(
|
|
191
|
-
target.removeAttribute("on:" +
|
|
195
|
+
target.addEventListener(key, this.lookup(identifier).bind(this));
|
|
196
|
+
target.removeAttribute("on:" + key);
|
|
192
197
|
e.stopPropagation();
|
|
193
198
|
}
|
|
194
199
|
}
|
|
195
200
|
}
|
|
196
201
|
#handleClass(e) {
|
|
197
|
-
if (e instanceof
|
|
202
|
+
if (e instanceof DirectiveEvent) {
|
|
198
203
|
const { identifier, target } = e.detail;
|
|
199
204
|
if (identifier in this && target instanceof HTMLElement) {
|
|
200
205
|
this.effect(() => {
|
|
@@ -214,37 +219,37 @@ var HandlerRegistry = class extends HTMLElement {
|
|
|
214
219
|
}
|
|
215
220
|
}
|
|
216
221
|
#handleUse(e) {
|
|
217
|
-
if (e instanceof
|
|
218
|
-
const {
|
|
219
|
-
if (
|
|
220
|
-
const cleanup = this.lookup(
|
|
222
|
+
if (e instanceof DirectiveEvent) {
|
|
223
|
+
const { key, target } = e.detail;
|
|
224
|
+
if (key in this && typeof this.lookup(key) === "function" && target instanceof HTMLElement) {
|
|
225
|
+
const cleanup = this.lookup(key).bind(this)(target);
|
|
221
226
|
if (typeof cleanup === "function") {
|
|
222
227
|
this.#cleanup.push(cleanup);
|
|
223
228
|
}
|
|
224
|
-
target.removeAttribute("use:" +
|
|
229
|
+
target.removeAttribute("use:" + key);
|
|
225
230
|
e.stopPropagation();
|
|
226
231
|
}
|
|
227
232
|
}
|
|
228
233
|
}
|
|
229
234
|
#handleProp(e) {
|
|
230
|
-
if (e instanceof
|
|
231
|
-
const { identifier,
|
|
232
|
-
if (identifier in this &&
|
|
235
|
+
if (e instanceof DirectiveEvent) {
|
|
236
|
+
const { identifier, key, target } = e.detail;
|
|
237
|
+
if (identifier in this && key in target && target instanceof HTMLElement) {
|
|
233
238
|
const ref = this.lookup(identifier);
|
|
234
239
|
this.effect(() => {
|
|
235
|
-
if (isState(target[
|
|
236
|
-
target[
|
|
240
|
+
if (isState(target[key])) {
|
|
241
|
+
target[key].value = ref.valueOf();
|
|
237
242
|
} else {
|
|
238
|
-
target[
|
|
243
|
+
target[key] = ref.valueOf();
|
|
239
244
|
}
|
|
240
245
|
});
|
|
241
|
-
target.removeAttribute("prop:" +
|
|
246
|
+
target.removeAttribute("prop:" + key);
|
|
242
247
|
e.stopPropagation();
|
|
243
248
|
}
|
|
244
249
|
}
|
|
245
250
|
}
|
|
246
251
|
#handleText(e) {
|
|
247
|
-
if (e instanceof
|
|
252
|
+
if (e instanceof DirectiveEvent) {
|
|
248
253
|
const { identifier, target } = e.detail;
|
|
249
254
|
if (identifier in this && target instanceof HTMLElement) {
|
|
250
255
|
const ref = this.lookup(identifier);
|
|
@@ -257,7 +262,7 @@ var HandlerRegistry = class extends HTMLElement {
|
|
|
257
262
|
}
|
|
258
263
|
}
|
|
259
264
|
#handleHTML(e) {
|
|
260
|
-
if (e instanceof
|
|
265
|
+
if (e instanceof DirectiveEvent) {
|
|
261
266
|
const { identifier, target } = e.detail;
|
|
262
267
|
if (identifier in this && target instanceof HTMLElement) {
|
|
263
268
|
const ref = this.lookup(identifier);
|
|
@@ -270,20 +275,23 @@ var HandlerRegistry = class extends HTMLElement {
|
|
|
270
275
|
}
|
|
271
276
|
}
|
|
272
277
|
#handleBind(e) {
|
|
273
|
-
if (e instanceof
|
|
274
|
-
const { identifier,
|
|
275
|
-
if (identifier in this && target instanceof HTMLElement &&
|
|
278
|
+
if (e instanceof DirectiveEvent) {
|
|
279
|
+
const { identifier, key, target } = e.detail;
|
|
280
|
+
if (identifier in this && target instanceof HTMLElement && key in target) {
|
|
276
281
|
const state = this.lookup(identifier);
|
|
277
282
|
if (isState(state)) {
|
|
278
|
-
state.value = target[
|
|
279
|
-
target.addEventListener(
|
|
280
|
-
|
|
281
|
-
|
|
283
|
+
state.value = target[key];
|
|
284
|
+
target.addEventListener(
|
|
285
|
+
bindingConfig[key].event,
|
|
286
|
+
() => {
|
|
287
|
+
state.value = target[key];
|
|
288
|
+
}
|
|
289
|
+
);
|
|
282
290
|
this.effect(() => {
|
|
283
|
-
target[
|
|
291
|
+
target[key] = state.value;
|
|
284
292
|
});
|
|
285
293
|
}
|
|
286
|
-
target.removeAttribute("bind:" +
|
|
294
|
+
target.removeAttribute("bind:" + key);
|
|
287
295
|
e.stopPropagation();
|
|
288
296
|
}
|
|
289
297
|
}
|
|
@@ -295,30 +303,20 @@ var HandlerRegistry = class extends HTMLElement {
|
|
|
295
303
|
for (const attribute of attr) {
|
|
296
304
|
const [_, key] = attribute.localName.split(":");
|
|
297
305
|
if (!key) throw new Error("Missing <key> in attr:<key>");
|
|
298
|
-
const attrRequest = new
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
detail: {
|
|
303
|
-
attribute: key,
|
|
304
|
-
identifier: attribute.value || key,
|
|
305
|
-
target: element
|
|
306
|
-
}
|
|
306
|
+
const attrRequest = new DirectiveEvent("rad::attr", {
|
|
307
|
+
key,
|
|
308
|
+
identifier: attribute.value || key,
|
|
309
|
+
target: element
|
|
307
310
|
});
|
|
308
311
|
element.dispatchEvent(attrRequest);
|
|
309
312
|
}
|
|
310
313
|
for (const property of Object.keys(bindingConfig)) {
|
|
311
314
|
if (element.hasAttribute(`bind:${property}`)) {
|
|
312
315
|
const identifier = element.getAttribute(`bind:${property}`)?.trim() || property;
|
|
313
|
-
const bindRequest = new
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
detail: {
|
|
318
|
-
property,
|
|
319
|
-
identifier,
|
|
320
|
-
target: element
|
|
321
|
-
}
|
|
316
|
+
const bindRequest = new DirectiveEvent("rad::bind", {
|
|
317
|
+
key: property,
|
|
318
|
+
identifier,
|
|
319
|
+
target: element
|
|
322
320
|
});
|
|
323
321
|
element.dispatchEvent(bindRequest);
|
|
324
322
|
}
|
|
@@ -328,41 +326,28 @@ var HandlerRegistry = class extends HTMLElement {
|
|
|
328
326
|
const [_, key] = bool.localName.split(":");
|
|
329
327
|
if (!key) throw new Error("Missing <key> in bool:<key>");
|
|
330
328
|
element.dispatchEvent(
|
|
331
|
-
new
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
detail: {
|
|
336
|
-
attribute: key,
|
|
337
|
-
identifier: bool.value || key,
|
|
338
|
-
target: element
|
|
339
|
-
}
|
|
329
|
+
new DirectiveEvent("rad::bool", {
|
|
330
|
+
key,
|
|
331
|
+
identifier: bool.value || key,
|
|
332
|
+
target: element
|
|
340
333
|
})
|
|
341
334
|
);
|
|
342
335
|
}
|
|
343
336
|
const classList = element.getAttribute("classlist");
|
|
344
337
|
if (classList) {
|
|
345
|
-
const classRequest = new
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
detail: {
|
|
350
|
-
identifier: classList,
|
|
351
|
-
target: element
|
|
352
|
-
}
|
|
338
|
+
const classRequest = new DirectiveEvent("rad::classlist", {
|
|
339
|
+
identifier: classList,
|
|
340
|
+
key: "classList",
|
|
341
|
+
target: element
|
|
353
342
|
});
|
|
354
343
|
element.dispatchEvent(classRequest);
|
|
355
344
|
}
|
|
356
345
|
const html = element.getAttribute("html");
|
|
357
346
|
if (html) {
|
|
358
|
-
const htmlRequest = new
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
detail: {
|
|
363
|
-
identifier: html,
|
|
364
|
-
target: element
|
|
365
|
-
}
|
|
347
|
+
const htmlRequest = new DirectiveEvent("rad::html", {
|
|
348
|
+
identifier: html,
|
|
349
|
+
key: "innerHTML",
|
|
350
|
+
target: element
|
|
366
351
|
});
|
|
367
352
|
element.dispatchEvent(htmlRequest);
|
|
368
353
|
}
|
|
@@ -370,15 +355,10 @@ var HandlerRegistry = class extends HTMLElement {
|
|
|
370
355
|
for (const event of events) {
|
|
371
356
|
const [_, type2] = event.localName.split(":");
|
|
372
357
|
if (!type2) throw new Error("Missing <type> in on:<type>");
|
|
373
|
-
const onRequest = new
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
detail: {
|
|
378
|
-
type: type2,
|
|
379
|
-
identifier: event.value || type2,
|
|
380
|
-
target: element
|
|
381
|
-
}
|
|
358
|
+
const onRequest = new DirectiveEvent("rad::on", {
|
|
359
|
+
key: type2,
|
|
360
|
+
identifier: event.value || type2,
|
|
361
|
+
target: element
|
|
382
362
|
});
|
|
383
363
|
element.dispatchEvent(onRequest);
|
|
384
364
|
}
|
|
@@ -386,28 +366,19 @@ var HandlerRegistry = class extends HTMLElement {
|
|
|
386
366
|
for (const prop of props) {
|
|
387
367
|
const [_, key] = prop.localName.split(":");
|
|
388
368
|
if (!key) throw new Error("Missing <key> in prop:<key>");
|
|
389
|
-
const propRequest = new
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
detail: {
|
|
394
|
-
property: key,
|
|
395
|
-
identifier: prop.value || key,
|
|
396
|
-
target: element
|
|
397
|
-
}
|
|
369
|
+
const propRequest = new DirectiveEvent("rad::prop", {
|
|
370
|
+
key,
|
|
371
|
+
identifier: prop.value || key,
|
|
372
|
+
target: element
|
|
398
373
|
});
|
|
399
374
|
element.dispatchEvent(propRequest);
|
|
400
375
|
}
|
|
401
376
|
const text = element.getAttribute("text");
|
|
402
377
|
if (text) {
|
|
403
|
-
const textRequest = new
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
detail: {
|
|
408
|
-
identifier: text,
|
|
409
|
-
target: element
|
|
410
|
-
}
|
|
378
|
+
const textRequest = new DirectiveEvent("rad::text", {
|
|
379
|
+
identifier: text,
|
|
380
|
+
key: "textContent",
|
|
381
|
+
target: element
|
|
411
382
|
});
|
|
412
383
|
element.dispatchEvent(textRequest);
|
|
413
384
|
}
|
|
@@ -415,14 +386,10 @@ var HandlerRegistry = class extends HTMLElement {
|
|
|
415
386
|
for (const hook of hooks) {
|
|
416
387
|
const [_, identifier] = hook.localName.split(":");
|
|
417
388
|
if (!identifier) throw new Error("Missing <id> in use:<id>");
|
|
418
|
-
const useRequest = new
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
detail: {
|
|
423
|
-
identifier,
|
|
424
|
-
target: element
|
|
425
|
-
}
|
|
389
|
+
const useRequest = new DirectiveEvent("rad::use", {
|
|
390
|
+
key: identifier,
|
|
391
|
+
identifier: "",
|
|
392
|
+
target: element
|
|
426
393
|
});
|
|
427
394
|
element.dispatchEvent(useRequest);
|
|
428
395
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@radishland/runtime",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.5.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "The Radish runtime",
|
|
6
6
|
"author": "Frédéric Crozatier",
|
|
@@ -33,11 +33,11 @@
|
|
|
33
33
|
"runtime"
|
|
34
34
|
],
|
|
35
35
|
"dependencies": {
|
|
36
|
-
"@preact/signals-core": "^1.
|
|
36
|
+
"@preact/signals-core": "^1.10.0"
|
|
37
37
|
},
|
|
38
38
|
"devDependencies": {
|
|
39
|
-
"tsup": "^8.
|
|
40
|
-
"typescript": "^5.
|
|
39
|
+
"tsup": "^8.5.0",
|
|
40
|
+
"typescript": "^5.8.3"
|
|
41
41
|
},
|
|
42
42
|
"scripts": {
|
|
43
43
|
"build": "tsup"
|