@cajoa/core 0.8.0 → 0.10.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/dist/index.cjs +13 -3
- package/dist/index.d.cts +6 -5
- package/dist/index.d.ts +6 -5
- package/dist/index.js +13 -3
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -211,7 +211,12 @@ function getRenderer() {
|
|
|
211
211
|
function h(tag, props, ...children) {
|
|
212
212
|
const r = getRenderer();
|
|
213
213
|
const el = r.createElement(tag);
|
|
214
|
+
let ref;
|
|
214
215
|
for (const [key, value] of Object.entries(props ?? {})) {
|
|
216
|
+
if (key === "ref") {
|
|
217
|
+
if (typeof value === "function") ref = value;
|
|
218
|
+
continue;
|
|
219
|
+
}
|
|
215
220
|
if (typeof value === "function" && !key.startsWith("on")) {
|
|
216
221
|
createEffect(() => r.setProp(el, key, value()));
|
|
217
222
|
} else {
|
|
@@ -219,6 +224,8 @@ function h(tag, props, ...children) {
|
|
|
219
224
|
}
|
|
220
225
|
}
|
|
221
226
|
appendChildren(el, children);
|
|
227
|
+
const onRef = ref;
|
|
228
|
+
if (onRef) untrack(() => onRef(el));
|
|
222
229
|
return el;
|
|
223
230
|
}
|
|
224
231
|
function toNodes(value) {
|
|
@@ -276,9 +283,12 @@ function render(component, container) {
|
|
|
276
283
|
}
|
|
277
284
|
|
|
278
285
|
// src/components/show.ts
|
|
286
|
+
function resolve(value) {
|
|
287
|
+
return typeof value === "function" ? value() : value;
|
|
288
|
+
}
|
|
279
289
|
function Show(props) {
|
|
280
|
-
const visible = createMemo(() => !!props.when
|
|
281
|
-
return () => visible() ? untrack(() => props.children
|
|
290
|
+
const visible = createMemo(() => !!resolve(props.when));
|
|
291
|
+
return () => visible() ? untrack(() => resolve(props.children ?? null)) : untrack(() => resolve(props.fallback ?? null));
|
|
282
292
|
}
|
|
283
293
|
|
|
284
294
|
// src/components/for.ts
|
|
@@ -289,7 +299,7 @@ function For(props) {
|
|
|
289
299
|
cache.clear();
|
|
290
300
|
});
|
|
291
301
|
return () => {
|
|
292
|
-
const items = props.each();
|
|
302
|
+
const items = typeof props.each === "function" ? props.each() : props.each;
|
|
293
303
|
const next = /* @__PURE__ */ new Map();
|
|
294
304
|
const nodes = [];
|
|
295
305
|
items.forEach((item, i) => {
|
package/dist/index.d.cts
CHANGED
|
@@ -36,14 +36,15 @@ declare function h(tag: string, props: Record<string, any> | null, ...children:
|
|
|
36
36
|
|
|
37
37
|
declare function render(component: () => HostNode, container: HostNode): () => void;
|
|
38
38
|
|
|
39
|
+
type Lazy<T> = T | (() => T);
|
|
39
40
|
declare function Show<T>(props: {
|
|
40
|
-
when:
|
|
41
|
-
children
|
|
42
|
-
fallback?:
|
|
43
|
-
}): () =>
|
|
41
|
+
when: Lazy<T>;
|
|
42
|
+
children?: Lazy<Child>;
|
|
43
|
+
fallback?: Lazy<Child>;
|
|
44
|
+
}): () => string | number | boolean | object | null;
|
|
44
45
|
|
|
45
46
|
declare function For<T>(props: {
|
|
46
|
-
each: () => T[];
|
|
47
|
+
each: T[] | (() => T[]);
|
|
47
48
|
children: (item: T, index: number) => HostNode;
|
|
48
49
|
key?: (item: T, index: number) => unknown;
|
|
49
50
|
}): () => object[];
|
package/dist/index.d.ts
CHANGED
|
@@ -36,14 +36,15 @@ declare function h(tag: string, props: Record<string, any> | null, ...children:
|
|
|
36
36
|
|
|
37
37
|
declare function render(component: () => HostNode, container: HostNode): () => void;
|
|
38
38
|
|
|
39
|
+
type Lazy<T> = T | (() => T);
|
|
39
40
|
declare function Show<T>(props: {
|
|
40
|
-
when:
|
|
41
|
-
children
|
|
42
|
-
fallback?:
|
|
43
|
-
}): () =>
|
|
41
|
+
when: Lazy<T>;
|
|
42
|
+
children?: Lazy<Child>;
|
|
43
|
+
fallback?: Lazy<Child>;
|
|
44
|
+
}): () => string | number | boolean | object | null;
|
|
44
45
|
|
|
45
46
|
declare function For<T>(props: {
|
|
46
|
-
each: () => T[];
|
|
47
|
+
each: T[] | (() => T[]);
|
|
47
48
|
children: (item: T, index: number) => HostNode;
|
|
48
49
|
key?: (item: T, index: number) => unknown;
|
|
49
50
|
}): () => object[];
|
package/dist/index.js
CHANGED
|
@@ -165,7 +165,12 @@ function getRenderer() {
|
|
|
165
165
|
function h(tag, props, ...children) {
|
|
166
166
|
const r = getRenderer();
|
|
167
167
|
const el = r.createElement(tag);
|
|
168
|
+
let ref;
|
|
168
169
|
for (const [key, value] of Object.entries(props ?? {})) {
|
|
170
|
+
if (key === "ref") {
|
|
171
|
+
if (typeof value === "function") ref = value;
|
|
172
|
+
continue;
|
|
173
|
+
}
|
|
169
174
|
if (typeof value === "function" && !key.startsWith("on")) {
|
|
170
175
|
createEffect(() => r.setProp(el, key, value()));
|
|
171
176
|
} else {
|
|
@@ -173,6 +178,8 @@ function h(tag, props, ...children) {
|
|
|
173
178
|
}
|
|
174
179
|
}
|
|
175
180
|
appendChildren(el, children);
|
|
181
|
+
const onRef = ref;
|
|
182
|
+
if (onRef) untrack(() => onRef(el));
|
|
176
183
|
return el;
|
|
177
184
|
}
|
|
178
185
|
function toNodes(value) {
|
|
@@ -230,9 +237,12 @@ function render(component, container) {
|
|
|
230
237
|
}
|
|
231
238
|
|
|
232
239
|
// src/components/show.ts
|
|
240
|
+
function resolve(value) {
|
|
241
|
+
return typeof value === "function" ? value() : value;
|
|
242
|
+
}
|
|
233
243
|
function Show(props) {
|
|
234
|
-
const visible = createMemo(() => !!props.when
|
|
235
|
-
return () => visible() ? untrack(() => props.children
|
|
244
|
+
const visible = createMemo(() => !!resolve(props.when));
|
|
245
|
+
return () => visible() ? untrack(() => resolve(props.children ?? null)) : untrack(() => resolve(props.fallback ?? null));
|
|
236
246
|
}
|
|
237
247
|
|
|
238
248
|
// src/components/for.ts
|
|
@@ -243,7 +253,7 @@ function For(props) {
|
|
|
243
253
|
cache.clear();
|
|
244
254
|
});
|
|
245
255
|
return () => {
|
|
246
|
-
const items = props.each();
|
|
256
|
+
const items = typeof props.each === "function" ? props.each() : props.each;
|
|
247
257
|
const next = /* @__PURE__ */ new Map();
|
|
248
258
|
const nodes = [];
|
|
249
259
|
items.forEach((item, i) => {
|