@wrnrlr/prelude 0.1.9 → 0.2.1
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/publish.yml +12 -11
- package/{deno.json → deno.jsonc} +10 -9
- package/example/index.html +43 -0
- package/package.json +6 -2
- package/src/constants.ts +110 -52
- package/src/controlflow.ts +140 -92
- package/src/hyperscript.ts +81 -106
- package/src/mod.ts +11 -19
- package/src/reactive.ts +29 -17
- package/src/runtime.ts +126 -66
- package/test/hyperscript.js +7 -6
- package/test/reactive.js +22 -2
- package/test/types.ts +44 -0
- package/src/components.js +0 -20
- package/src/ui/accordion.ts +0 -8
- package/src/ui/button.ts +0 -9
- package/src/ui/canvas.ts +0 -8
- package/src/ui/date.ts +0 -8
- package/src/ui/dialog.ts +0 -12
- package/src/ui/filter.ts +0 -8
- package/src/ui/form.ts +0 -7
- package/src/ui/h.ts +0 -48
- package/src/ui/image.ts +0 -5
- package/src/ui/input.ts +0 -49
- package/src/ui/mod.ts +0 -12
- package/src/ui/multiselect.ts +0 -42
- package/src/ui/option.ts +0 -1
- package/src/ui/select.ts +0 -28
- package/src/ui/tab.ts +0 -7
- package/src/ui/table.ts +0 -9
- package/src/ui/upload.ts +0 -7
- package/www/assets/css/presets.css +0 -504
- package/www/assets/css/style.css +0 -90
- package/www/demo.html +0 -28
- package/www/index.html +0 -211
- package/www/playground.html +0 -184
- package/www/public/banner.svg +0 -6
- package/www/public/example/admin.html +0 -88
- package/www/public/example/counter.html +0 -24
- package/www/public/example/greeting.html +0 -25
- package/www/public/example/select.html +0 -27
- package/www/public/example/show.html +0 -18
- package/www/public/example/todo.html +0 -70
- package/www/public/fonts/fab.ttf +0 -0
- package/www/public/fonts/fab.woff2 +0 -0
- package/www/public/fonts/far.ttf +0 -0
- package/www/public/fonts/far.woff2 +0 -0
- package/www/public/fonts/fas.ttf +0 -0
- package/www/public/fonts/fas.woff2 +0 -0
- package/www/public/logo.svg +0 -16
- package/www/typedoc.json +0 -13
- package/www/ui.html +0 -49
- package/www/vite.config.js +0 -106
package/src/ui/dialog.ts
DELETED
@@ -1,12 +0,0 @@
|
|
1
|
-
import { effect } from '../reactive.ts'
|
2
|
-
import { h } from './h.ts'
|
3
|
-
|
4
|
-
export function Dialog(props) {
|
5
|
-
return h('dialog', {
|
6
|
-
ref(r) {
|
7
|
-
r.addEventListener('cancel', ()=>props.show(false))
|
8
|
-
const show = props.modal ? ()=>r.showModal() : ()=>r.show()
|
9
|
-
effect(() => props.show() ? show() : r.close())
|
10
|
-
},
|
11
|
-
}, props.children)
|
12
|
-
}
|
package/src/ui/filter.ts
DELETED
package/src/ui/form.ts
DELETED
package/src/ui/h.ts
DELETED
@@ -1,48 +0,0 @@
|
|
1
|
-
import {runtime,type Runtime} from '../runtime.ts'
|
2
|
-
import {hyperscript,type HyperScript} from '../hyperscript.ts'
|
3
|
-
|
4
|
-
let _fontMetricsCtx:undefined|CanvasRenderingContext2D
|
5
|
-
|
6
|
-
export function fontMetrics(font:string, text:string) {
|
7
|
-
if (!_fontMetricsCtx) _fontMetricsCtx = document.createElement('canvas').getContext('2d')
|
8
|
-
_fontMetricsCtx!.font = font;
|
9
|
-
return _fontMetricsCtx!.measureText(text)
|
10
|
-
}
|
11
|
-
|
12
|
-
export function renderEffect(fn:any):any {
|
13
|
-
return requestAnimationFrame(()=>effect(fn))
|
14
|
-
}
|
15
|
-
|
16
|
-
const r:Runtime|undefined = /*#__PURE__*/ (typeof window === 'object') ? runtime(window as any) : undefined
|
17
|
-
|
18
|
-
/** h
|
19
|
-
@example Element with a single child
|
20
|
-
```js
|
21
|
-
h('h1','Hello World!')
|
22
|
-
```
|
23
|
-
@example Element with multiple children
|
24
|
-
```js
|
25
|
-
h('p',['Hello ',h('em','World!')])
|
26
|
-
```
|
27
|
-
@example Component with event handler
|
28
|
-
```js
|
29
|
-
h(Input,{onInput:e => {}})
|
30
|
-
```
|
31
|
-
@group Hyperscript
|
32
|
-
*/
|
33
|
-
const h:HyperScript|undefined = /*#__PURE__*/ r ? hyperscript(r) : undefined
|
34
|
-
|
35
|
-
const render = /*#__PURE__*/ r?.render
|
36
|
-
|
37
|
-
// import {signal,wrap} from './reactive.ts'
|
38
|
-
|
39
|
-
// /**
|
40
|
-
// @group Utils
|
41
|
-
// */
|
42
|
-
// export function $(a:any,b:any):any {
|
43
|
-
// const t = typeof a
|
44
|
-
// if (t==='function') return wrap(a,b)
|
45
|
-
// else return signal(a,b)
|
46
|
-
// }
|
47
|
-
|
48
|
-
export {h,render}
|
package/src/ui/image.ts
DELETED
package/src/ui/input.ts
DELETED
@@ -1,49 +0,0 @@
|
|
1
|
-
import {h,fontMetrics,renderEffect} from './h.ts'
|
2
|
-
import {type Getter, type Setter} from '../reactive.ts'
|
3
|
-
|
4
|
-
export type InputProps = {
|
5
|
-
ref?: (r:HTMLElement)=>void,
|
6
|
-
id?: string,
|
7
|
-
autocomplete?: 'on'|'off',
|
8
|
-
autosize?: (r:HTMLElement, props:any)=>(r:HTMLElement)=>void,
|
9
|
-
class?: string,
|
10
|
-
disabled?: boolean,
|
11
|
-
name?: string,
|
12
|
-
placeholder?: string,
|
13
|
-
onInput?: (e:Event) => void,
|
14
|
-
value: (Getter<string>&Setter<string>)|(Getter<number>&Setter<number>),
|
15
|
-
style?: string,
|
16
|
-
type?: string,
|
17
|
-
}
|
18
|
-
|
19
|
-
export function Input(props: InputProps): any {
|
20
|
-
props.onInput = props.onInput || ((e:Event) => props.value(e?.target?.value))
|
21
|
-
props.autocomplete = props.autocomplete || 'off'
|
22
|
-
if (props.autosize) props.ref = (r)=>props.autosize(r,props)
|
23
|
-
return h('input', props)
|
24
|
-
}
|
25
|
-
|
26
|
-
const autosize = (r:HTMLElement, props:any) => {
|
27
|
-
const style = window.getComputedStyle(r)
|
28
|
-
renderEffect(() => {
|
29
|
-
const font = style.getPropertyValue('font')
|
30
|
-
const metrics = fontMetrics(font, props.value().toString())
|
31
|
-
r.style.width = metrics.width + 'px'
|
32
|
-
})
|
33
|
-
}
|
34
|
-
|
35
|
-
Input.prototype.autosize = autosize
|
36
|
-
|
37
|
-
// return h('input', {
|
38
|
-
// ref,
|
39
|
-
// id: props.id,
|
40
|
-
// autocomplete: props.autocomplete || 'off',
|
41
|
-
// class: props.class,
|
42
|
-
// disabled: props.disabled,
|
43
|
-
// onInput: (e:Event) => props.value(e?.target?.value),
|
44
|
-
// name: props.name,
|
45
|
-
// placeholder: props.placeholder,
|
46
|
-
// type: props.type,
|
47
|
-
// style: props.style,
|
48
|
-
// value: props.value,
|
49
|
-
// })
|
package/src/ui/mod.ts
DELETED
@@ -1,12 +0,0 @@
|
|
1
|
-
export {Accordion, type AccordionProps} from './accordion.ts'
|
2
|
-
export {Button, type ButtonProps} from './button.ts'
|
3
|
-
export {Canvas} from './canvas.ts'
|
4
|
-
export {DateInput} from './date.ts'
|
5
|
-
export {Input, type InputProps} from './input.ts'
|
6
|
-
export {Form} from './form.ts'
|
7
|
-
export {Tab} from './tab.ts'
|
8
|
-
export {Filter, type FilterProps} from './filter.ts'
|
9
|
-
export {Multiselect, type MultiselectProps} from './multiselect.ts'
|
10
|
-
export {Select, type SelectProps} from './select.ts'
|
11
|
-
export {Table, type TableProps} from './table.ts'
|
12
|
-
export {Upload} from './upload.ts'
|
package/src/ui/multiselect.ts
DELETED
@@ -1,42 +0,0 @@
|
|
1
|
-
import {h} from './h.ts'
|
2
|
-
import {signal} from "../reactive.ts"
|
3
|
-
import {Dialog} from './dialog.ts'
|
4
|
-
import {Button} from './button.ts'
|
5
|
-
|
6
|
-
export type MultiselectProps = {
|
7
|
-
key: string | ((item:unknown)=>string),
|
8
|
-
label: string | ((item:unknown)=>string),
|
9
|
-
options: string[] | (()=>string[]),
|
10
|
-
disabled: boolean | (()=>boolean),
|
11
|
-
value: string[] | ((value:string[])=>void),
|
12
|
-
}
|
13
|
-
|
14
|
-
export function Multiselect(props:MultiselectProps) {
|
15
|
-
const showDialog = signal(true)
|
16
|
-
const key = props.key || (f => f)
|
17
|
-
const label = props.label || (f => f)
|
18
|
-
const add = item => props.value([...props.value(), key(item)])
|
19
|
-
const remove = i => _ => props.value(items=>items.toSpliced(i,1))
|
20
|
-
const options = () => (props.options.call ? props.options() : props.options).filter(e=>!props.value().includes(e))
|
21
|
-
const value = (...args:any[]) => (!args.length) ? props.value() : (show(false), add(key(args[0])))
|
22
|
-
const disabled = () => ((props?.disabled?.call ? props.disabled() : props.disabled))
|
23
|
-
|
24
|
-
return h('span.multiselect', [
|
25
|
-
h(List, {each:()=>value}, (e,i) => h('span', [
|
26
|
-
h(Button, {disabled}, ()=>label(e())),
|
27
|
-
h(Button, {disabled, onClick:remove(i())})
|
28
|
-
])),
|
29
|
-
h('span', {style:'position:relative'}, [
|
30
|
-
h(Button, {
|
31
|
-
onClick: _ => showDialog(b=>!b),
|
32
|
-
class: () => showDialog() ? 'minus' : 'add',
|
33
|
-
disabled: () => disabled() || !options().length,
|
34
|
-
}, '+'),
|
35
|
-
h(Dialog, {show:()=>showDialog}, h(Options, {
|
36
|
-
options: () => options,
|
37
|
-
value: () => value,
|
38
|
-
label
|
39
|
-
}))
|
40
|
-
])
|
41
|
-
])
|
42
|
-
}
|
package/src/ui/option.ts
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
import {h} from './h.ts'
|
package/src/ui/select.ts
DELETED
@@ -1,28 +0,0 @@
|
|
1
|
-
import {signal} from '../reactive.ts'
|
2
|
-
import { h } from './h.ts'
|
3
|
-
import {Dialog} from './dialog.ts'
|
4
|
-
import {Button} from './button.ts'
|
5
|
-
|
6
|
-
export type SelectProps = {
|
7
|
-
label?: (value:any)=>string,
|
8
|
-
key?: (value:any)=>string,
|
9
|
-
options: any[] | (()=>any[]),
|
10
|
-
}
|
11
|
-
|
12
|
-
export function Select(props:SelectProps) {
|
13
|
-
const show = signal(false)
|
14
|
-
const label = props.label || (f => f)
|
15
|
-
const key = props.key || (f => f)
|
16
|
-
const placeholder = h('span.placeholder', props.placeholder)
|
17
|
-
const display = () => props?.value?.() ? label(props.value()) : placeholder
|
18
|
-
const value = (...args) => (!args.length) ? props.value() : (show(false), props.value(key(args[0])))
|
19
|
-
|
20
|
-
return h('span.select', {id: props.id, class:props.class, style:'position:relative'}, [
|
21
|
-
h(Button, {onClick:_ => show(b=>!b)}, display),
|
22
|
-
h(Dialog, {show:()=>show}, h(Options, {
|
23
|
-
options: props.options,
|
24
|
-
value: ()=>value,
|
25
|
-
label
|
26
|
-
}))
|
27
|
-
])
|
28
|
-
}
|
package/src/ui/tab.ts
DELETED
package/src/ui/table.ts
DELETED