@zag-js/dom-query
Advanced tools
Comparing version 0.0.0-dev-20240619115122 to 0.0.0-dev-20240619194623
@@ -150,3 +150,3 @@ type Booleanish = boolean | "true" | "false"; | ||
getWin: (ctx: ScopeContext) => Window & typeof globalThis; | ||
getActiveElement: (ctx: ScopeContext) => HTMLElement | null; | ||
getActiveElement: (ctx: ScopeContext) => Element | null; | ||
isActiveElement: (ctx: ScopeContext, elem: HTMLElement | null) => boolean; | ||
@@ -153,0 +153,0 @@ getById: <T_1 extends Element = HTMLElement>(ctx: ScopeContext, id: string) => T_1 | null; |
@@ -653,9 +653,9 @@ "use strict"; | ||
function createScope(methods) { | ||
const screen = { | ||
const dom = { | ||
getRootNode: (ctx) => ctx.getRootNode?.() ?? document, | ||
getDoc: (ctx) => getDocument(screen.getRootNode(ctx)), | ||
getWin: (ctx) => screen.getDoc(ctx).defaultView ?? window, | ||
getActiveElement: (ctx) => screen.getDoc(ctx).activeElement, | ||
isActiveElement: (ctx, elem) => elem === screen.getActiveElement(ctx), | ||
getById: (ctx, id) => screen.getRootNode(ctx).getElementById(id), | ||
getDoc: (ctx) => getDocument(dom.getRootNode(ctx)), | ||
getWin: (ctx) => dom.getDoc(ctx).defaultView ?? window, | ||
getActiveElement: (ctx) => dom.getRootNode(ctx).activeElement, | ||
isActiveElement: (ctx, elem) => elem === dom.getActiveElement(ctx), | ||
getById: (ctx, id) => dom.getRootNode(ctx).getElementById(id), | ||
setValue: (elem, value) => { | ||
@@ -668,3 +668,3 @@ if (elem == null || value == null) return; | ||
}; | ||
return { ...screen, ...methods }; | ||
return { ...dom, ...methods }; | ||
} | ||
@@ -671,0 +671,0 @@ |
{ | ||
"name": "@zag-js/dom-query", | ||
"version": "0.0.0-dev-20240619115122", | ||
"version": "0.0.0-dev-20240619194623", | ||
"description": "The dom helper library for zag.js machines", | ||
@@ -5,0 +5,0 @@ "keywords": [ |
@@ -8,10 +8,10 @@ import { getDocument } from "./env" | ||
export function createScope<T>(methods: T) { | ||
const screen = { | ||
const dom = { | ||
getRootNode: (ctx: ScopeContext) => (ctx.getRootNode?.() ?? document) as Document | ShadowRoot, | ||
getDoc: (ctx: ScopeContext) => getDocument(screen.getRootNode(ctx)), | ||
getWin: (ctx: ScopeContext) => screen.getDoc(ctx).defaultView ?? window, | ||
getActiveElement: (ctx: ScopeContext) => screen.getDoc(ctx).activeElement as HTMLElement | null, | ||
isActiveElement: (ctx: ScopeContext, elem: HTMLElement | null) => elem === screen.getActiveElement(ctx), | ||
getDoc: (ctx: ScopeContext) => getDocument(dom.getRootNode(ctx)), | ||
getWin: (ctx: ScopeContext) => dom.getDoc(ctx).defaultView ?? window, | ||
getActiveElement: (ctx: ScopeContext) => dom.getRootNode(ctx).activeElement, | ||
isActiveElement: (ctx: ScopeContext, elem: HTMLElement | null) => elem === dom.getActiveElement(ctx), | ||
getById: <T extends Element = HTMLElement>(ctx: ScopeContext, id: string) => | ||
screen.getRootNode(ctx).getElementById(id) as T | null, | ||
dom.getRootNode(ctx).getElementById(id) as T | null, | ||
setValue: <T extends { value: string }>(elem: T | null, value: string | number | null | undefined) => { | ||
@@ -25,3 +25,3 @@ if (elem == null || value == null) return | ||
return { ...screen, ...methods } | ||
return { ...dom, ...methods } | ||
} |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
211539