@wrnrlr/prelude 0.2.10 → 0.2.15
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/.github/workflows/cd.yml +32 -0
- package/.github/workflows/ci.yml +31 -0
- package/LICENSE +21 -1
- package/deno.jsonc +5 -2
- package/package.json +1 -1
- package/src/canvas.js +16 -0
- package/src/domdiff.ts +92 -0
- package/src/form.js +20 -0
- package/src/hyperscript.ts +5 -2
- package/src/{controlflow.ts → list.ts} +2 -24
- package/src/mod.ts +11 -11
- package/src/osm.js +0 -0
- package/src/reactive.ts +49 -0
- package/src/resource.js +27 -4
- package/src/router.js +26 -7
- package/src/runtime.ts +244 -309
- package/src/select.js +1 -0
- package/src/show.ts +48 -0
- package/src/svg.js +0 -0
- package/src/switch.ts +96 -0
- package/src/table.js +0 -0
- package/test/hyperscript.js +9 -6
- package/test/list.js +4 -4
- package/test/types.ts +8 -4
- package/.github/workflows/publish.yml +0 -67
package/src/switch.ts
ADDED
@@ -0,0 +1,96 @@
|
|
1
|
+
import {memo, untrack, children, type Getter} from './reactive.ts'
|
2
|
+
|
3
|
+
/**
|
4
|
+
* Switches between content based on mutually exclusive conditions
|
5
|
+
* ```typescript
|
6
|
+
* <Switch fallback={<FourOhFour />}>
|
7
|
+
* <Match when={state.route === 'home'}>
|
8
|
+
* <Home />
|
9
|
+
* </Match>
|
10
|
+
* <Match when={state.route === 'settings'}>
|
11
|
+
* <Settings />
|
12
|
+
* </Match>
|
13
|
+
* </Switch>
|
14
|
+
* ```
|
15
|
+
* @description https://docs.solidjs.com/reference/components/switch-and-match
|
16
|
+
*/
|
17
|
+
export function Switch(props: { fallback?: any; children: any }): any {
|
18
|
+
const chs = children(() => props.children);
|
19
|
+
const switchFunc = memo(() => {
|
20
|
+
const ch = chs() as unknown as MatchProps<unknown> | MatchProps<unknown>[];
|
21
|
+
const mps = Array.isArray(ch) ? ch : [ch];
|
22
|
+
let func: Getter<any | undefined> = () => undefined;
|
23
|
+
for (let i = 0; i < mps.length; i++) {
|
24
|
+
const index = i;
|
25
|
+
const mp = mps[i];
|
26
|
+
const prevFunc = func;
|
27
|
+
const conditionValue = memo(
|
28
|
+
() => (prevFunc() ? undefined : mp.when),
|
29
|
+
undefined, undefined
|
30
|
+
);
|
31
|
+
const condition = mp.keyed
|
32
|
+
? conditionValue
|
33
|
+
: memo(
|
34
|
+
conditionValue,
|
35
|
+
undefined,
|
36
|
+
{ equals: (a, b) => !a === !b }
|
37
|
+
);
|
38
|
+
func = () => prevFunc() || (condition() ? [index, conditionValue, mp] : undefined);
|
39
|
+
}
|
40
|
+
return func;
|
41
|
+
});
|
42
|
+
return memo(
|
43
|
+
() => {
|
44
|
+
const sel = switchFunc()();
|
45
|
+
if (!sel) return props.fallback;
|
46
|
+
const [index, conditionValue, mp] = sel;
|
47
|
+
const child = mp.children;
|
48
|
+
const fn = typeof child === "function" && child.length > 0;
|
49
|
+
return fn
|
50
|
+
? untrack(() =>
|
51
|
+
(child as any)(
|
52
|
+
mp.keyed
|
53
|
+
? (conditionValue() as any)
|
54
|
+
: () => {
|
55
|
+
if (untrack(switchFunc)()?.[0] !== index) throw 'Stale read from Switch'
|
56
|
+
return conditionValue();
|
57
|
+
}
|
58
|
+
)
|
59
|
+
)
|
60
|
+
: child;
|
61
|
+
},
|
62
|
+
undefined,
|
63
|
+
undefined
|
64
|
+
) as unknown as any;
|
65
|
+
}
|
66
|
+
|
67
|
+
export type MatchProps<T> = {
|
68
|
+
when: T | undefined | null | false;
|
69
|
+
keyed?: boolean;
|
70
|
+
children: any | ((item: NonNullable<T> | Getter<NonNullable<T>>) => any);
|
71
|
+
};
|
72
|
+
/**
|
73
|
+
* Selects a content based on condition when inside a `<Switch>` control flow
|
74
|
+
* ```typescript
|
75
|
+
* <Match when={condition()}>
|
76
|
+
* <Content/>
|
77
|
+
* </Match>
|
78
|
+
* ```
|
79
|
+
* @description https://docs.solidjs.com/reference/components/switch-and-match
|
80
|
+
*/
|
81
|
+
export function Match<
|
82
|
+
T,
|
83
|
+
TRenderFunction extends (item: Getter<NonNullable<T>>) => any
|
84
|
+
>(props: {
|
85
|
+
when: T | undefined | null | false;
|
86
|
+
keyed?: false;
|
87
|
+
children: any;
|
88
|
+
}): any;
|
89
|
+
export function Match<T, TRenderFunction extends (item: NonNullable<T>) => any>(props: {
|
90
|
+
when: T | undefined | null | false;
|
91
|
+
keyed: true;
|
92
|
+
children: any;
|
93
|
+
}): any;
|
94
|
+
export function Match<T>(props: MatchProps<T>) {
|
95
|
+
return props as unknown as any;
|
96
|
+
}
|
package/src/table.js
ADDED
File without changes
|
package/test/hyperscript.js
CHANGED
@@ -1,13 +1,16 @@
|
|
1
|
-
import {runtime} from '../src/runtime.ts'
|
2
|
-
import {hyperscript} from '../src/hyperscript.ts'
|
3
|
-
import {signal,root} from '../src/reactive.ts'
|
1
|
+
// import {runtime} from '../src/runtime.ts'
|
4
2
|
import { Window } from 'happy-dom'
|
5
3
|
import {assertEquals} from '@std/assert'
|
6
4
|
|
7
5
|
const window = new Window
|
8
|
-
|
9
|
-
globalThis = window
|
10
|
-
|
6
|
+
|
7
|
+
globalThis.window = window
|
8
|
+
globalThis.document = window.document
|
9
|
+
globalThis.navigator = window.navigator
|
10
|
+
|
11
|
+
import {signal,root} from '../src/reactive.ts'
|
12
|
+
import { r } from '../src/runtime.ts'
|
13
|
+
import {h} from '../src/hyperscript.ts'
|
11
14
|
|
12
15
|
function testing(name, props, f=props) {
|
13
16
|
const htest = t => (name, f) => {
|
package/test/list.js
CHANGED
@@ -1,8 +1,8 @@
|
|
1
|
-
import {assertEquals,assert} from '@std/assert'
|
2
|
-
import {describe,it} from '@std/testing/bdd'
|
1
|
+
// import {assertEquals,assert} from '@std/assert'
|
2
|
+
// import {describe,it} from '@std/testing/bdd'
|
3
3
|
|
4
|
-
import { signal } from '../src/reactive.ts'
|
5
|
-
import { listArray } from '../src/
|
4
|
+
// import { signal } from '../src/reactive.ts'
|
5
|
+
// import { listArray } from '../src/list.ts'
|
6
6
|
|
7
7
|
// Deno.test('listArray applies list to mapFn', ()=>{
|
8
8
|
// const l = signal([0,1,2])
|
package/test/types.ts
CHANGED
@@ -1,11 +1,15 @@
|
|
1
|
-
import {
|
2
|
-
import {
|
1
|
+
import { type Mountable } from '../src/runtime.ts'
|
2
|
+
import { h } from '../src/hyperscript.ts'
|
3
3
|
import { signal, root } from '../src/reactive.ts'
|
4
|
-
import { List } from '../src/
|
4
|
+
import { List } from '../src/list.ts'
|
5
5
|
import { Window } from 'happy-dom'
|
6
6
|
|
7
7
|
const window = new Window
|
8
|
-
|
8
|
+
|
9
|
+
globalThis.window = (window as any)
|
10
|
+
globalThis.document = (window as any).document
|
11
|
+
globalThis.navigator = (window as any).navigator
|
12
|
+
|
9
13
|
|
10
14
|
h('hr')
|
11
15
|
h('div', ['hello'])
|
@@ -1,67 +0,0 @@
|
|
1
|
-
name: Prelude CI/CD
|
2
|
-
|
3
|
-
on:
|
4
|
-
push:
|
5
|
-
branches:
|
6
|
-
- main
|
7
|
-
- release
|
8
|
-
|
9
|
-
jobs:
|
10
|
-
test:
|
11
|
-
runs-on: ubuntu-latest
|
12
|
-
# if: github.ref == 'refs/heads/main'
|
13
|
-
steps:
|
14
|
-
- name: Checkout the repository
|
15
|
-
uses: actions/checkout@v4
|
16
|
-
- name: Setup Deno
|
17
|
-
uses: denoland/setup-deno@v2
|
18
|
-
with:
|
19
|
-
deno-version: v2.x
|
20
|
-
- name: Deno install
|
21
|
-
run: deno install
|
22
|
-
# - name: Lint
|
23
|
-
# run: deno lint
|
24
|
-
- name: Run tests
|
25
|
-
run: deno task test
|
26
|
-
publish:
|
27
|
-
needs: test
|
28
|
-
if: github.ref == 'refs/heads/release'
|
29
|
-
runs-on: ubuntu-latest
|
30
|
-
permissions:
|
31
|
-
contents: read
|
32
|
-
id-token: write
|
33
|
-
steps:
|
34
|
-
- name: Checkout repository
|
35
|
-
uses: actions/checkout@v4
|
36
|
-
|
37
|
-
- name: Setup Deno
|
38
|
-
uses: denoland/setup-deno@v2
|
39
|
-
with:
|
40
|
-
deno-version: v2.x
|
41
|
-
|
42
|
-
- name: Publish to JSR
|
43
|
-
run: deno publish --allow-slow-types --allow-dirty
|
44
|
-
|
45
|
-
- name: Setup Node
|
46
|
-
uses: actions/setup-node@v4
|
47
|
-
with:
|
48
|
-
node-version: 20
|
49
|
-
registry-url: 'https://registry.npmjs.org/'
|
50
|
-
|
51
|
-
- name: Publish to NPM
|
52
|
-
run: npm publish --access public
|
53
|
-
env:
|
54
|
-
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
|
55
|
-
|
56
|
-
# Moving artifacts, website and docs into their own project...
|
57
|
-
# - name: Setup Pages
|
58
|
-
# uses: actions/configure-pages@v5
|
59
|
-
|
60
|
-
# - name: Upload artifact
|
61
|
-
# uses: actions/upload-pages-artifact@v3
|
62
|
-
# with:
|
63
|
-
# path: './www/dist'
|
64
|
-
|
65
|
-
# - name: Deploy to GitHub Pages
|
66
|
-
# id: deployment
|
67
|
-
# uses: actions/deploy-pages@v4
|