@snupo/jmc 1.0.20 → 1.0.22

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/src/lib.ts ADDED
@@ -0,0 +1,28 @@
1
+ import type { Children, IClassComponent, IUpdateContext, H, J, HFragment } from './h';
2
+ import { HKind } from './h.js'
3
+ import { updateview } from './jmc.js'
4
+
5
+ export type DeepReadonly<T> = { readonly [K in keyof T]: T[K] extends Record<string, unknown> ? DeepReadonly<T[K]> : T[K]; }
6
+
7
+ export const When = ({ cond }: { cond: boolean }, cn: Children): HFragment | null => cond ? { kind: HKind.Fragment, cn } : null
8
+
9
+ export abstract class JMXComp<P extends J = {}> implements IClassComponent {
10
+
11
+ element!: HTMLElement // assigned by jmx framework
12
+ constructor(public props: P) { }
13
+
14
+ // overrides
15
+ mounted() { }
16
+ update(uc?: IUpdateContext): boolean | void { }
17
+ abstract view(): H
18
+
19
+ // utility: updates the component's view
20
+ updateview() { updateview(this.element) }
21
+ get ismounted(): boolean { return this.element as any }
22
+ }
23
+
24
+ export function cc(...namesOrObjects: (string | any)[]): string {
25
+ return namesOrObjects.flatMap(n => (n.trim ? n : Object.keys(n).filter(k => n[k]))).join(' ') // n.trim distinguishes strings from objects
26
+ }
27
+
28
+ export const focuselement = (e: Node) => (e as HTMLElement).focus()