diff --git a/packages/dom-expressions/src/client.d.ts b/packages/dom-expressions/src/client.d.ts index 7b91ae05..2a155728 100644 --- a/packages/dom-expressions/src/client.d.ts +++ b/packages/dom-expressions/src/client.d.ts @@ -58,7 +58,7 @@ export function dynamicProperty(props: unknown, key: string): unknown; export function hydrate( fn: () => JSX.Element, node: MountableElement, - options?: { renderId?: string, owner?: unknown } + options?: { renderId?: string; owner?: unknown } ): () => void; export function getHydrationKey(): string; export function getNextElement(template?: HTMLTemplateElement): Element; @@ -76,3 +76,4 @@ export interface RequestEvent { } export declare const RequestContext: unique symbol; export function getRequestEvent(): RequestEvent | undefined; +export function runHydrationEvents(): void; diff --git a/packages/dom-expressions/src/server.d.ts b/packages/dom-expressions/src/server.d.ts index 9a11aaa0..6d39b01a 100644 --- a/packages/dom-expressions/src/server.d.ts +++ b/packages/dom-expressions/src/server.d.ts @@ -1,3 +1,15 @@ +import { JSX } from "./jsx.js"; +export const Aliases: Record; +export const Properties: Set; +export const ChildProperties: Set; +export const DelegatedEvents: Set; +export const DOMElements: Set; +export const SVGElements: Set; +export const SVGNamespace: Record; +export function getPropAlias(prop: string, tagName: string): string | undefined; + +type MountableElement = Element | Document | ShadowRoot | DocumentFragment | Node; + export function renderToString( fn: () => T, options?: { @@ -87,3 +99,79 @@ export function pipeToNodeWritable( onCompleteAll?: () => void; } ): void; + +export function untrack(fn: () => T): T; + +// client-only APIs + +/** @deprecated not supported on the server side */ +export function classList( + node: Element, + value: { [k: string]: boolean }, + prev?: { [k: string]: boolean } +): { [k: string]: boolean }; + +/** @deprecated not supported on the server side */ +export function style( + node: Element, + value: { [k: string]: string }, + prev?: { [k: string]: string } +): void; + +/** @deprecated not supported on the server side */ +export function insert( + parent: MountableElement, + accessor: (() => T) | T, + marker?: Node | null, + init?: JSX.Element +): JSX.Element; + +/** @deprecated not supported on the server side */ +export function spread( + node: Element, + accessor: (() => T) | T, + isSVG?: Boolean, + skipChildren?: Boolean +): void; + +/** @deprecated not supported on the server side */ +export function delegateEvents(eventNames: string[], d?: Document): void; +/** @deprecated not supported on the server side */ +export function dynamicProperty(props: unknown, key: string): unknown; +/** @deprecated not supported on the server side */ +export function setAttribute(node: Element, name: string, value: string): void; +/** @deprecated not supported on the server side */ +export function setAttributeNS(node: Element, namespace: string, name: string, value: string): void; + +/** @deprecated not supported on the server side */ +export function addEventListener( + node: Element, + name: string, + handler: () => void, + delegate: boolean +): void; + +/** @deprecated not supported on the server side */ +export function render(code: () => JSX.Element, element: MountableElement): () => void; +/** @deprecated not supported on the server side */ +export function template(html: string, isCE?: boolean, isSVG?: boolean): () => Element; +/** @deprecated not supported on the server side */ +export function setProperty(node: Element, name: string, value: any): void; +/** @deprecated not supported on the server side */ +export function className(node: Element, value: string): void; +/** @deprecated not supported on the server side */ +export function assign(node: Element, props: any, isSVG?: Boolean, skipChildren?: Boolean): void; + +/** @deprecated not supported on the server side */ +export function hydrate( + fn: () => JSX.Element, + node: MountableElement, + options?: { renderId?: string; owner?: unknown } +): () => void; + +/** @deprecated not supported on the server side */ +export function getNextElement(template?: HTMLTemplateElement): Element; +/** @deprecated not supported on the server side */ +export function getNextMatch(start: Node, elementName: string): Element; +/** @deprecated not supported on the server side */ +export function getNextMarker(start: Node): [Node, Array]; diff --git a/packages/dom-expressions/src/server.js b/packages/dom-expressions/src/server.js index 0652be21..5b143321 100644 --- a/packages/dom-expressions/src/server.js +++ b/packages/dom-expressions/src/server.js @@ -1,7 +1,19 @@ -import { Aliases, BooleanAttributes, ChildProperties } from "./constants"; +import { Aliases, BooleanAttributes, ChildProperties, Properties } from "./constants"; import { sharedConfig, root } from "rxcore"; import { createSerializer, getLocalHeaderScript } from "./serializer"; -export { createComponent } from "rxcore"; + +export { getOwner, createComponent, effect, memo, untrack } from "rxcore"; + +export { + Properties, + ChildProperties, + getPropAlias, + Aliases, + DOMElements, + SVGElements, + SVGNamespace, + DelegatedEvents +} from "./constants.js"; // Based on https://github.com/WebReflection/domtagger/blob/master/esm/sanitizer.js const VOID_ELEMENTS = @@ -686,3 +698,33 @@ export function ssrSpread(props, isSVG, skipChildren) { } return result; } + +// client-only APIs + +export { + notSup as classList, + notSup as style, + notSup as insert, + notSup as spread, + notSup as delegateEvents, + notSup as dynamicProperty, + notSup as setAttribute, + notSup as setAttributeNS, + notSup as addEventListener, + notSup as render, + notSup as template, + notSup as setProperty, + notSup as className, + notSup as assign, + notSup as hydrate, + notSup as getNextElement, + notSup as getNextMatch, + notSup as getNextMarker, + notSup as runHydrationEvents +}; + +function notSup() { + throw new Error( + "Client-only API called on the server side. Run client-only code in onMount, or conditionally run client-only component with ." + ); +}