j20 0.0.1 → 0.0.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/README.md +3 -0
- package/dist/index.d.mts +3 -3
- package/dist/index.mjs +37 -12
- package/dist/jsx-runtime.mjs +5 -5
- package/package.json +1 -1
package/README.md
ADDED
package/dist/index.d.mts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import * as csstype from "csstype";
|
|
2
|
-
import { Computed, Effect, Signal, computed, effect as effect$1, signal } from "@j20org/signal";
|
|
2
|
+
import { Computed, Effect, Signal, computed, effect as effect$1, signal, untrack } from "@j20org/signal";
|
|
3
3
|
|
|
4
4
|
//#region src/jsx.d.ts
|
|
5
5
|
|
|
@@ -3466,7 +3466,7 @@ declare const instanceGetElements: (instance: Instance) => Node[];
|
|
|
3466
3466
|
declare const instanceDestroy: (parent: Instance, instance: Instance) => void;
|
|
3467
3467
|
//#endregion
|
|
3468
3468
|
//#region src/h/createRoot.d.ts
|
|
3469
|
-
declare const
|
|
3469
|
+
declare const createRoot: (boot: () => JSX.Element) => {
|
|
3470
3470
|
element: HTMLElement;
|
|
3471
3471
|
instance: Instance;
|
|
3472
3472
|
};
|
|
@@ -3483,4 +3483,4 @@ declare const template: (template: string) => (isSvg: boolean) => any;
|
|
|
3483
3483
|
//#region src/web-components.d.ts
|
|
3484
3484
|
declare const registerWebComponent: <C extends WC<any, any>>(Comp: C) => void;
|
|
3485
3485
|
//#endregion
|
|
3486
|
-
export { $, $useContext, AttrValueType, Case, CaseProps, Computed, CustomElement, Default, DefaultProps, Dynamic, DynamicProps, DynamicPropsInner, Effect, FC, For, Fragment, If, IfProps, Instance, ListProps, RefObject, Signal, Switch, SwitchProps, WC, computed,
|
|
3486
|
+
export { $, $useContext, AttrValueType, Case, CaseProps, Computed, CustomElement, Default, DefaultProps, Dynamic, DynamicProps, DynamicPropsInner, Effect, FC, For, Fragment, If, IfProps, Instance, ListProps, RefObject, Signal, Switch, SwitchProps, WC, computed, createComponent, createContext, createDom, createElement, createLogicComponent, createRoot, effect, getCurrentInstance, h2, instanceCreate, instanceCreateElement, instanceDestroy, instanceGetElements, instanceInit, jsx, jsxs, ref, registerWebComponent, signal, template, untrack, wc };
|
package/dist/index.mjs
CHANGED
|
@@ -229,7 +229,7 @@ const isEvent = (eventName) => {
|
|
|
229
229
|
return eventName.startsWith("on");
|
|
230
230
|
};
|
|
231
231
|
const getEventName = (eventName) => {
|
|
232
|
-
return eventName.slice(2).
|
|
232
|
+
return eventName.slice(2).toLowerCase();
|
|
233
233
|
};
|
|
234
234
|
const getChildren = (propChildren) => {
|
|
235
235
|
const arr = [];
|
|
@@ -257,6 +257,14 @@ const generateId = () => {
|
|
|
257
257
|
}
|
|
258
258
|
return `${overflow}${(count++).toString(32)}`;
|
|
259
259
|
};
|
|
260
|
+
const styleObjectToString = (style) => {
|
|
261
|
+
let styleString = "";
|
|
262
|
+
for (const key in style) {
|
|
263
|
+
const value = style[key];
|
|
264
|
+
styleString += `${key}: ${value}; `;
|
|
265
|
+
}
|
|
266
|
+
return styleString.trim();
|
|
267
|
+
};
|
|
260
268
|
|
|
261
269
|
//#endregion
|
|
262
270
|
//#region src/h/createDom.ts
|
|
@@ -265,7 +273,10 @@ const update = (node, key, oldValue, newValue) => {
|
|
|
265
273
|
node.removeEventListener(getEventName(key), oldValue);
|
|
266
274
|
node.addEventListener(getEventName(key), newValue);
|
|
267
275
|
} else if (newValue === false || newValue == null) node.removeAttribute(key);
|
|
268
|
-
else
|
|
276
|
+
else {
|
|
277
|
+
const value = key === "style" && typeof newValue === "object" ? styleObjectToString(newValue) : newValue === true ? "" : newValue;
|
|
278
|
+
node.setAttribute(key, value);
|
|
279
|
+
}
|
|
269
280
|
};
|
|
270
281
|
const unset = (node, key, oldValue) => {
|
|
271
282
|
if (isEvent(key)) node.removeEventListener(getEventName(key), oldValue);
|
|
@@ -279,7 +290,10 @@ const add = (node, key, newValue) => {
|
|
|
279
290
|
newValue.current = null;
|
|
280
291
|
});
|
|
281
292
|
newValue.current = node;
|
|
282
|
-
} else newValue !== false && newValue != null
|
|
293
|
+
} else if (newValue !== false && newValue != null) {
|
|
294
|
+
const value = key === "style" && typeof newValue === "object" ? styleObjectToString(newValue) : newValue === true ? "" : newValue;
|
|
295
|
+
node.setAttribute(key, value);
|
|
296
|
+
}
|
|
283
297
|
};
|
|
284
298
|
const createDom = (tag, props, children) => {
|
|
285
299
|
const node = tag;
|
|
@@ -339,10 +353,21 @@ const instanceGetElements = (instance) => {
|
|
|
339
353
|
const instanceDestroy = (parent, instance) => {
|
|
340
354
|
const stack$1 = [instance];
|
|
341
355
|
while (stack$1.length) {
|
|
342
|
-
const
|
|
343
|
-
|
|
344
|
-
|
|
356
|
+
const inst = stack$1.pop();
|
|
357
|
+
inst.disposes.forEach((dispose) => {
|
|
358
|
+
try {
|
|
359
|
+
dispose();
|
|
360
|
+
} catch (e) {
|
|
361
|
+
console.error("Error during instance dispose:", e);
|
|
362
|
+
}
|
|
363
|
+
});
|
|
364
|
+
inst.disposes = [];
|
|
365
|
+
if (inst.children) {
|
|
366
|
+
stack$1.push(...inst.children);
|
|
367
|
+
inst.children = [];
|
|
368
|
+
}
|
|
345
369
|
}
|
|
370
|
+
if (parent && parent.children) parent.children = parent.children.filter((c) => c !== instance);
|
|
346
371
|
};
|
|
347
372
|
|
|
348
373
|
//#endregion
|
|
@@ -851,7 +876,7 @@ const createElement = (tag, props, children) => {
|
|
|
851
876
|
|
|
852
877
|
//#endregion
|
|
853
878
|
//#region src/h/createRoot.ts
|
|
854
|
-
const
|
|
879
|
+
const createRoot = (boot) => {
|
|
855
880
|
let [instance, fragment] = instanceCreate(() => boot());
|
|
856
881
|
return {
|
|
857
882
|
element: fragment,
|
|
@@ -871,13 +896,13 @@ const template = (template$1) => {
|
|
|
871
896
|
let dom;
|
|
872
897
|
return (isSvg) => {
|
|
873
898
|
if (!dom) {
|
|
874
|
-
const templateEl = isSvg ? document.createElementNS("http://www.w3.org/2000/svg", "svg") : document.createElement("
|
|
899
|
+
const templateEl = isSvg ? document.createElementNS("http://www.w3.org/2000/svg", "svg") : document.createElement("template");
|
|
875
900
|
templateEl.innerHTML = template$1;
|
|
876
|
-
dom = templateEl.firstChild;
|
|
877
|
-
|
|
878
|
-
|
|
901
|
+
dom = isSvg ? templateEl.firstChild : templateEl.content.firstChild;
|
|
902
|
+
}
|
|
903
|
+
return dom.cloneNode();
|
|
879
904
|
};
|
|
880
905
|
};
|
|
881
906
|
|
|
882
907
|
//#endregion
|
|
883
|
-
export { $, $useContext, Case, Computed, Default, Dynamic, Effect, For, Fragment, If, Signal, Switch, computed,
|
|
908
|
+
export { $, $useContext, Case, Computed, Default, Dynamic, Effect, For, Fragment, If, Signal, Switch, computed, createComponent, createContext, createDom, createElement, createLogicComponent, createRoot, effect, getCurrentInstance, h2, instanceCreate, instanceCreateElement, instanceDestroy, instanceGetElements, instanceInit, jsx, jsxs, ref, registerWebComponent, signal, template, untrack, wc };
|
package/dist/jsx-runtime.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { createElement } from "
|
|
1
|
+
import { createElement } from "./index";
|
|
2
2
|
|
|
3
3
|
//#region src/jsx-runtime.ts
|
|
4
4
|
const h2 = (tag, props, children) => {
|
|
@@ -11,11 +11,11 @@ const template = (template$1) => {
|
|
|
11
11
|
let dom;
|
|
12
12
|
return (isSvg) => {
|
|
13
13
|
if (!dom) {
|
|
14
|
-
const templateEl = isSvg ? document.createElementNS("http://www.w3.org/2000/svg", "svg") : document.createElement("
|
|
14
|
+
const templateEl = isSvg ? document.createElementNS("http://www.w3.org/2000/svg", "svg") : document.createElement("template");
|
|
15
15
|
templateEl.innerHTML = template$1;
|
|
16
|
-
dom = templateEl.firstChild;
|
|
17
|
-
|
|
18
|
-
|
|
16
|
+
dom = isSvg ? templateEl.firstChild : templateEl.content.firstChild;
|
|
17
|
+
}
|
|
18
|
+
return dom.cloneNode();
|
|
19
19
|
};
|
|
20
20
|
};
|
|
21
21
|
|