mirror of
https://github.com/jaandrle/deka-dom-el
synced 2025-07-01 20:32:13 +02:00
🚚
This commit is contained in:
7
src/jsdom.d.ts
vendored
7
src/jsdom.d.ts
vendored
@ -1,7 +0,0 @@
|
||||
import { el, assign, on } from "../index.d";
|
||||
export * from "../index.d";
|
||||
export function register(dom: typeof document): Promise<{
|
||||
el: typeof el,
|
||||
assign: typeof assign,
|
||||
on: typeof on
|
||||
}>
|
38
src/jsdom.js
38
src/jsdom.js
@ -1,38 +0,0 @@
|
||||
import { prop_process } from './dom-common.js';
|
||||
const { setDelete }= prop_process;
|
||||
/** @param {HTMLElement} obj */
|
||||
prop_process.setDelete= function(obj, prop, value){
|
||||
if("checked"!==prop) return setDelete(obj, prop, value);
|
||||
if(value) return obj.setAttribute("checked", "");
|
||||
obj.removeAttribute("checked");
|
||||
};
|
||||
const keys= [ "HTMLElement", "SVGElement", "DocumentFragment", "MutationObserver", "document" ];
|
||||
let dom_last;
|
||||
export let el;
|
||||
export let assign;
|
||||
export let on;
|
||||
export async function register(dom, keys_aditional= []){
|
||||
if(dom_last===dom)
|
||||
return import("../index.js");
|
||||
|
||||
keys.push(...keys_aditional);
|
||||
const w= dom.window;
|
||||
keys.forEach(key=> globalThis[key]= w[key]);
|
||||
globalThis.window= w;
|
||||
w.console= globalThis.console;
|
||||
|
||||
const m= await import("../index.js");
|
||||
el= m.el;
|
||||
assign= m.assign;
|
||||
on= m.on;
|
||||
return m;
|
||||
}
|
||||
export function unregister(){
|
||||
if(!dom_last)
|
||||
return false;
|
||||
|
||||
keys.forEach(key=> Reflect.deleteProperty(globalThis, key));
|
||||
Reflect.deleteProperty(globalThis, "window");
|
||||
dom_last= undefined;
|
||||
return true;
|
||||
}
|
50
src/signals.d.ts
vendored
50
src/signals.d.ts
vendored
@ -1,50 +0,0 @@
|
||||
export type Signal<V, A>= (set?: V)=> V & A;
|
||||
type Action<V>= (this: { value: V }, ...a: any[])=> typeof S._ | void;
|
||||
type SymbolOnclear= Symbol;
|
||||
type SymbolSignal= Symbol;
|
||||
type Actions<V>= Record<string, Action<V>>;
|
||||
interface S {
|
||||
_: Symbol
|
||||
/**
|
||||
* Simple example:
|
||||
* ```js
|
||||
* const hello= S("Hello Signal");
|
||||
* ```
|
||||
* …simple todo signal:
|
||||
* ```js
|
||||
* const todos= S([], {
|
||||
* add(v){ this.value.push(S(v)); },
|
||||
* remove(i){ this.value.splice(i, 1); },
|
||||
* [S.symbols.onclear](){ S.clear(...this.value); },
|
||||
* });
|
||||
* ```
|
||||
* …computed signal:
|
||||
* ```js
|
||||
* const name= S("Jan");
|
||||
* const surname= S("Andrle");
|
||||
* const fullname= S(()=> name()+" "+surname());
|
||||
* ```
|
||||
* @param value Initial signal value. Or function computing value from other signals.
|
||||
* @param actions Use to define actions on the signal. Such as add item to the array.
|
||||
* There is also a reserved function `S.symbol.onclear` which is called when the signal is cleared
|
||||
* by `S.clear`.
|
||||
* */
|
||||
<V, A extends Actions<V>>(value: V, actions?: A): Signal<V, A>;
|
||||
action<S extends Signal<any, Actions<any>>, A extends (S extends Signal<any, infer A> ? A : never), N extends keyof A>(
|
||||
signal: S,
|
||||
name: N,
|
||||
...params: A[N] extends (...args: infer P)=> any ? P : never
|
||||
): void;
|
||||
clear(...signals: Signal<any, any>): void;
|
||||
on<T>(signal: Signal<T, any>, onchange: (a: T)=> void, options?: AddEventListenerOptions): void;
|
||||
symbols: {
|
||||
signal: SymbolSignal;
|
||||
onclear: SymbolOnclear;
|
||||
}
|
||||
el<S extends any, T extends HTMLElement>(signal: Signal<S, any>, el: (v: S)=> T): T;
|
||||
}
|
||||
export const S: S;
|
||||
declare global {
|
||||
type ddeSignal<T, A= {}>= Signal<T, A>;
|
||||
type ddeActions<V>= Actions<V>
|
||||
}
|
@ -1,4 +0,0 @@
|
||||
export { S, isSignal } from "./signals-lib.js";
|
||||
import { signals_config } from "./signals-lib.js";
|
||||
import { registerReactivity } from "./signals-common.js";
|
||||
registerReactivity(signals_config);
|
Reference in New Issue
Block a user