@wrnrlr/prelude 0.1.2 → 0.1.4
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/deno.json +1 -1
- package/package.json +1 -1
- package/src/controlflow.ts +1 -1
- package/src/hyperscript.ts +6 -4
- package/src/mod.ts +1 -1
- package/src/reactive.ts +11 -0
- package/www/assets/css/style.css +3 -3
- package/www/demo.html +28 -0
- package/www/index.html +2 -2
- package/www/playground.html +1 -1
- package/www/public/example/counter.html +1 -1
- package/www/public/example/todo.html +1 -1
- /package/www/{assets → public}/fonts/fab.ttf +0 -0
- /package/www/{assets → public}/fonts/fab.woff2 +0 -0
- /package/www/{assets → public}/fonts/far.ttf +0 -0
- /package/www/{assets → public}/fonts/far.woff2 +0 -0
- /package/www/{assets → public}/fonts/fas.ttf +0 -0
- /package/www/{assets → public}/fonts/fas.woff2 +0 -0
package/deno.json
CHANGED
package/package.json
CHANGED
package/src/controlflow.ts
CHANGED
@@ -81,7 +81,7 @@ export function List<T>(props:ListProps<T>) {
|
|
81
81
|
}
|
82
82
|
const mapper = indexes ? mapperWithIndexes : mapperWithoutIndexes
|
83
83
|
return memo(() => {
|
84
|
-
const newItems = list.call ? list() :
|
84
|
+
const newItems = list.call ? list() : list
|
85
85
|
// (newItems)[$TRACK]; // top level tracking
|
86
86
|
return untrack(() => {
|
87
87
|
const temp = new Array(newItems.length) // new mapped array
|
package/src/hyperscript.ts
CHANGED
@@ -126,15 +126,17 @@ export function hyperscript(r:Runtime, patch?:any):HyperScript {
|
|
126
126
|
if (tag.id) e.setAttribute('id',tag.id)
|
127
127
|
if (tag.classes?.length) {
|
128
128
|
const cd = Object.getOwnPropertyDescriptor(props2,'class') ?? ({value:'',writable:true,enumerable:true} as any);
|
129
|
-
|
130
|
-
|
131
|
-
|
129
|
+
if (cd.value) {
|
130
|
+
(props2 as any).class = (cd.value?.call) ?
|
131
|
+
() => [...tag.classes,...cd.value().split(' ')].filter(c=>c).join(' ') :
|
132
|
+
[...tag.classes,...cd.value.split(' ')].filter(c=>c).join(' ')
|
133
|
+
}
|
132
134
|
}
|
133
135
|
if (patch) patch(props2)
|
134
136
|
let dynamic = false
|
135
137
|
const d = Object.getOwnPropertyDescriptors(props2)
|
136
138
|
for (const k in d) {
|
137
|
-
if (k !==
|
139
|
+
if (k !== 'ref' && !k.startsWith('on') && d[k].value?.call) {
|
138
140
|
dynamicProperty(props2 as any, k)
|
139
141
|
dynamic = true
|
140
142
|
} else if (d[k].get) dynamic = true
|
package/src/mod.ts
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
// @ts-nocheck:
|
2
2
|
export type {Getter,Setter,Fn,EqualsFn,ErrorFn,RootFn,UpdateFn} from './reactive.ts'
|
3
|
-
export {signal,effect,untrack,batch,memo,root,wrap,onMount} from './reactive.ts'
|
3
|
+
export {signal,effect,untrack,batch,memo,root,wrap,onMount,onCleanup} from './reactive.ts'
|
4
4
|
export {nbsp} from './constants.ts'
|
5
5
|
export {Show,List} from './controlflow.ts'
|
6
6
|
export {runtime, type Runtime} from './runtime.ts'
|
package/src/reactive.ts
CHANGED
@@ -327,10 +327,21 @@ export function onMount(fn: () => void) {
|
|
327
327
|
effect(() => untrack(fn));
|
328
328
|
}
|
329
329
|
|
330
|
+
/** Runs an effect `fn` once before the reactive scope is disposed */
|
330
331
|
export function onCleanup(fn: Fn):void {
|
331
332
|
OBSERVER?.cleanups.push(fn)
|
332
333
|
}
|
333
334
|
|
335
|
+
|
336
|
+
/**
|
337
|
+
@internal
|
338
|
+
@experimental
|
339
|
+
*/
|
340
|
+
export function autoclean(fn: Fn):Fn {
|
341
|
+
const cleanup = untrack(fn)
|
342
|
+
if (cleanup) OBSERVER?.cleanups.push(fn)
|
343
|
+
}
|
344
|
+
|
334
345
|
export function onError(fn: ErrorFn):void {
|
335
346
|
if ( !OBSERVER ) return
|
336
347
|
OBSERVER.contexts[SYMBOL_ERRORS] ||= []
|
package/www/assets/css/style.css
CHANGED
@@ -5,7 +5,7 @@
|
|
5
5
|
font-style: normal;
|
6
6
|
font-weight: 400;
|
7
7
|
font-display: block;
|
8
|
-
src: url("
|
8
|
+
src: url("/fonts/far.woff2") format("woff2"), url("/fonts/far.ttf") format("truetype");
|
9
9
|
}
|
10
10
|
|
11
11
|
@font-face {
|
@@ -13,7 +13,7 @@
|
|
13
13
|
font-style: normal;
|
14
14
|
font-weight: 900;
|
15
15
|
font-display: block;
|
16
|
-
src: url("
|
16
|
+
src: url("/fonts/fas.woff2") format("woff2"), url("/fonts/fas.ttf") format("truetype");
|
17
17
|
};
|
18
18
|
|
19
19
|
@font-face {
|
@@ -21,7 +21,7 @@
|
|
21
21
|
font-style: normal;
|
22
22
|
font-weight: 400;
|
23
23
|
font-display: block;
|
24
|
-
src: url("
|
24
|
+
src: url("/fonts/fab.woff2") format("woff2"), url("/fonts/fab.ttf") format("truetype");
|
25
25
|
}
|
26
26
|
|
27
27
|
.icon {display:flex; display:inline-block}
|
package/www/demo.html
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
<!DOCTYPE html>
|
2
|
+
<title>Demo</title>
|
3
|
+
|
4
|
+
<script type="module">
|
5
|
+
|
6
|
+
import {h,signal,effect,batch,wrap,render,onMount,List} from '../src/mod.ts'
|
7
|
+
|
8
|
+
function Test(props) {
|
9
|
+
return h('h1.red', {class:'yellow'}, 'Hello')
|
10
|
+
}
|
11
|
+
|
12
|
+
function App() {
|
13
|
+
const fruits = ['apple', 'banana', 'cherry']
|
14
|
+
return h(List, {each:fruits}, f => f)
|
15
|
+
}
|
16
|
+
|
17
|
+
render(Test, document.body)
|
18
|
+
|
19
|
+
</script>
|
20
|
+
|
21
|
+
<style>
|
22
|
+
.red {
|
23
|
+
background-color: red;
|
24
|
+
}
|
25
|
+
.yellow {
|
26
|
+
color:yellow;
|
27
|
+
}
|
28
|
+
</style>
|
package/www/index.html
CHANGED
@@ -36,7 +36,7 @@
|
|
36
36
|
<section class="flex column items-center py-8 gap-8">
|
37
37
|
<h1 class="center text-5xl">Just write JavaScript!</h1>
|
38
38
|
<p class="center text-2xl">Instead of JSX, Prelude uses HyperScript,<br>
|
39
|
-
a DSL that lets you
|
39
|
+
a DSL that lets you define components in JavaScript.</p>
|
40
40
|
<div class="flex items-center content-center gap-8">
|
41
41
|
<pre><code class="language-js">import {h, signal, render} from 'prelude'
|
42
42
|
|
@@ -70,7 +70,7 @@ render(Counter, window.counter)</code></pre>
|
|
70
70
|
|
71
71
|
<footer class="flex px-2 py-2 gap-8" style="background-color: var(--neutral-100);">
|
72
72
|
<div class="flex column justify-center gap-3">
|
73
|
-
<a href="https://
|
73
|
+
<a href="https://www.npmjs.com/package/@wrnrlr/prelude">NPM</a>
|
74
74
|
<a href="https://jsr.io/@wrnrlr/prelude">JSR</a>
|
75
75
|
</div>
|
76
76
|
<div class="flex column justify-center gap-3">
|
package/www/playground.html
CHANGED
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|