@amazon/vinyl-tsx 1.1.1 → 2.0.0
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/dist/index.cjs +57 -87
- package/dist/index.cjs.map +4 -4
- package/dist/index.js +64 -91
- package/dist/index.js.map +4 -4
- package/dist/types/current/domUtil.d.ts.map +1 -1
- package/dist/types/current/domUtil.js +4 -1
- package/dist/types/current/extensions/applyClassList.d.ts +2 -2
- package/dist/types/current/extensions/applyClassList.d.ts.map +1 -1
- package/dist/types/current/extensions/applyClassList.js +6 -6
- package/dist/types/current/extensions/applyStyles.d.ts +6 -3
- package/dist/types/current/extensions/applyStyles.d.ts.map +1 -1
- package/dist/types/current/index.d.ts +7 -7
- package/dist/types/current/index.d.ts.map +1 -1
- package/dist/types/current/index.js +7 -7
- package/dist/types/current/jsx.d.ts +3 -8
- package/dist/types/current/jsx.d.ts.map +1 -1
- package/dist/types/current/jsx.js +18 -39
- package/dist/types/current/tsconfig.tsbuildinfo +1 -1
- package/dist/types/ts3.7/extensions/applyClassList.d.ts +2 -2
- package/dist/types/ts3.7/extensions/applyStyles.d.ts +6 -3
- package/dist/types/ts3.7/index.d.ts +7 -7
- package/dist/types/ts3.7/jsx.d.ts +3 -8
- package/dist/types/ts4.1/extensions/applyClassList.d.ts +2 -2
- package/dist/types/ts4.1/extensions/applyStyles.d.ts +6 -3
- package/dist/types/ts4.1/index.d.ts +7 -7
- package/dist/types/ts4.1/jsx.d.ts +3 -8
- package/dist/types/ts4.7/extensions/applyClassList.d.ts +2 -2
- package/dist/types/ts4.7/extensions/applyStyles.d.ts +6 -3
- package/dist/types/ts4.7/index.d.ts +7 -7
- package/dist/types/ts4.7/jsx.d.ts +3 -8
- package/dist/unit/types/current/tsconfig.tsbuildinfo +1 -0
- package/package.json +15 -18
package/dist/index.js.map
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
|
-
"sources": ["../src/domUtil.ts", "../src/extensions/connectedObserver.ts", "../src/
|
|
4
|
-
"sourcesContent": ["/*\n * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n * SPDX-License-Identifier: Apache-2.0\n */\n\nexport function el<K extends keyof HTMLElementTagNameMap>(\n selectors: K,\n parentNode?: ParentNode\n): HTMLElementTagNameMap[K]\nexport function el(selectors: string, parentNode?: ParentNode): HTMLElement\nexport function el<E extends Element = Element>(\n selectors: string,\n parentNode: ParentNode = document\n): E {\n const element = parentNode.querySelector(selectors)\n if (!element) throw new Error(`${selectors} must be a DOM element`)\n return element as E\n}\n\nexport interface QuerySelector {\n <K extends keyof HTMLElementTagNameMap>(\n selectors: K,\n parentNode?: ParentNode\n ): HTMLElementTagNameMap[K]\n (selectors: string): HTMLElement\n}\n\nexport function bindQuerySelector(parentNode: ParentNode): QuerySelector {\n return (selectors: string) => el(selectors, parentNode)\n}\n\nexport function hide(element: HTMLElement) {\n element.style.display = 'none'\n}\n\nexport function show(element: HTMLElement) {\n element.style.removeProperty('display')\n}\n\nexport function getVisible(element: HTMLElement): boolean {\n return element.style.display !== 'none'\n}\n\nexport function setVisible(element: HTMLElement, value: boolean) {\n if (getVisible(element) === value) return\n if (value) show(element)\n else hide(element)\n}\n\nexport function isHidden(element: HTMLElement) {\n let node: HTMLElement | null = element\n while (node) {\n if (getComputedStyle(node).display === 'none') return true\n node = node.parentElement\n }\n return false\n}\n\nexport function isInputElement(\n value: Element | null\n): value is HTMLInputElement {\n return value?.tagName.toLowerCase() === 'input'\n}\n\n/**\n * Adds or removes a class token to an element.\n *\n * @param value The element whose classList to modify.\n * @param token The class token.\n * @param toggled If true, the token is added, if false, removed.\n */\nexport function setClassToken(\n value: HTMLElement,\n token: string,\n toggled: boolean\n) {\n if (toggled) {\n value.classList.add(token)\n } else {\n value.classList.remove(token)\n }\n}\n\nexport type ElementInitOptions = {\n readonly parent?: HTMLElement\n readonly className?: string\n}\n\n/**\n * Recursively walks a node hierarchy, invoking a callback for every node, depth first.\n *\n * @param node\n * @param callback\n */\nexport function walkDomDepthFirst(\n node: Node | undefined | null,\n callback: (node: Node) => void\n) {\n if (!node) return\n let next = node.firstChild\n while (next) {\n walkDomDepthFirst(next, callback)\n next = next.nextSibling\n }\n callback(node)\n}\n", "/*\n * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n * SPDX-License-Identifier: Apache-2.0\n */\n\nimport { walkDomDepthFirst } from '../domUtil'\nimport type { Maybe, Unsubscribe } from '@amazon/vinyl-util'\n\n/**\n * Dispatches a 'connected' event on nodes attached to the dom, dispatches 'disconnected' when removed.\n * Allows nodes to observe connected changes without creating a memory leak.\n */\nexport function initializeConnectedObserver(): Unsubscribe {\n const observer = new MutationObserver((mutations) => {\n const removed = new Set<Node>()\n const added = new Set<Node>()\n\n // First pass: flatten removed and added nodes so we can detect nodes re-ordered.\n for (const mutation of mutations) {\n mutation.removedNodes.forEach((node) => removed.add(node))\n mutation.addedNodes.forEach((node) => added.add(node))\n }\n\n // Second pass: handle added/removed, skipping reorders\n for (const mutation of mutations) {\n for (const node of mutation.addedNodes) {\n if (removed.has(node)) continue\n walkDomDepthFirst(node, (iNode) => {\n iNode.dispatchEvent(\n new CustomEvent('connect', { bubbles: false })\n )\n })\n }\n\n for (const node of mutation.removedNodes) {\n if (added.has(node)) continue\n walkDomDepthFirst(node, (iNode) => {\n iNode.dispatchEvent(\n new CustomEvent('disconnect', { bubbles: false })\n )\n })\n }\n }\n })\n\n observer.observe(document, { childList: true, subtree: true })\n\n return () => {\n observer.disconnect()\n }\n}\n\n/**\n * Invokes a callback when the given target is connected to the DOM.\n * If the callback returns a function, that function will be invoked when disconnected.\n *\n * @param target\n * @param callback\n */\nexport function onConnect<T extends Node>(\n target: T,\n callback: (node: T) => Maybe<Unsubscribe> | void\n): Unsubscribe {\n let sub: Maybe<Unsubscribe> | void = null\n let connected = false\n const onConnect = () => {\n if (connected) return\n connected = true\n sub = callback(target)\n }\n const onDisconnect = () => {\n connected = false\n sub?.()\n sub = null\n }\n target.addEventListener('connect', onConnect)\n target.addEventListener('disconnect', onDisconnect)\n if (target.isConnected) onConnect()\n return () => {\n target.removeEventListener('connect', onConnect)\n target.removeEventListener('disconnect', onDisconnect)\n onDisconnect()\n }\n}\n", "/*\n * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n * SPDX-License-Identifier: Apache-2.0\n */\n\nimport type { AllowBindable } from '../jsx'\nimport { onConnect } from './connectedObserver'\nimport { toKebabCase } from '@amazon/vinyl-util'\nimport {\n isObservableValue,\n type MaybeObservableValue,\n} from '@amazon/vinyl-observable'\nimport type { Maybe } from '@amazon/vinyl-util'\n\n/**\n * The shape accepted by the `style` jsx prop. Allows the typed CSSStyleDeclaration\n * fields plus any CSS custom property key (must start with `--`).\n */\nexport type StyleProp = AllowBindable<Partial<CSSStyleDeclaration>> & {\n readonly [customProperty: `--${string}`]: MaybeObservableValue<\n Maybe<string>\n >\n}\n\nexport function applyStyles(element: HTMLElement, style: StyleProp) {\n // noinspection SuspiciousTypeOfGuard\n if (typeof style === 'string') {\n // A Partial style declaration type does not prohibit a string type.\n throw new Error('expected style property to be type object')\n }\n for (const k in style) {\n const v = (style as Record<string, unknown>)[k]\n // Custom properties (starting with `--`) are passed through as-is so\n // they aren't kebab-cased a second time, and so they remain valid keys\n // for setProperty.\n const property = k.startsWith('--') ? k : toKebabCase(k)\n if (isObservableValue(v)) {\n onConnect(element, () => {\n return v.onData((value) => {\n element.style.setProperty(\n property,\n (value ?? null) as string | null\n )\n })\n })\n } else {\n element.style.setProperty(property, (v ?? null) as string | null)\n }\n }\n}\n", "/*\n * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n * SPDX-License-Identifier: Apache-2.0\n */\n\nimport { onConnect } from './extensions/connectedObserver'\nimport type { Writable } from './type'\nimport { applyStyles } from './extensions/applyStyles'\nimport {\n isObservableValue,\n type MaybeObservableValue,\n type ObservableValue,\n} from '@amazon/vinyl-observable'\nimport { ActiveText } from './ActiveText'\nimport { applyVisibility } from './extensions/applyVisibility'\nimport { applyClassList } from './extensions/applyClassList'\nimport type { HookExtension } from './extensions/HookExtension'\nimport { passiveEventHandlers } from './extensions/applyPassiveHandler'\nimport type { AnyRecord, Maybe } from '@amazon/vinyl-util'\n\n/**\n * Maps JS property names to their corresponding HTML attribute names where they differ.\n * Extensible \u2014 add entries for custom elements or non-standard properties.\n */\nexport const propToAttr: Record<string, string> = {\n acceptCharset: 'accept-charset',\n accessKey: 'accesskey',\n className: 'class',\n colSpan: 'colspan',\n contentEditable: 'contenteditable',\n crossOrigin: 'crossorigin',\n dateTime: 'datetime',\n dirName: 'dirname',\n encType: 'enctype',\n formAction: 'formaction',\n formEnctype: 'formenctype',\n formMethod: 'formmethod',\n formNoValidate: 'formnovalidate',\n formTarget: 'formtarget',\n htmlFor: 'for',\n httpEquiv: 'http-equiv',\n inputMode: 'inputmode',\n maxLength: 'maxlength',\n minLength: 'minlength',\n noModule: 'nomodule',\n noValidate: 'novalidate',\n readOnly: 'readonly',\n referrerPolicy: 'referrerpolicy',\n rowSpan: 'rowspan',\n tabIndex: 'tabindex',\n useMap: 'usemap',\n}\n\n/**\n * Sets a property on an element. When value is non-null, assigns directly via\n * property. When null, resets the property to '' and removes the HTML attribute\n * using the mapped name from {@link propToAttr}.\n */\nfunction setProp(element: HTMLElement, k: string, value: unknown): void {\n if (value == null) {\n ;(element as any)[k] = ''\n const attr = propToAttr[k] ?? k\n element.removeAttribute(attr)\n } else {\n ;(element as any)[k] = value\n }\n}\n\nexport type JsxFactory = (props: any, children: any[]) => any\n\n/**\n * A map of custom jsx properties to be used in hook extensions.\n */\nexport const hookExtensions = {\n onConnect: onConnect<HTMLElement>,\n style: applyStyles,\n visible: applyVisibility,\n classList: applyClassList,\n ...passiveEventHandlers,\n} as const satisfies Record<keyof any, HookExtension<any>>\n\nexport type AllowBindable<T> = {\n [K in keyof T]: MaybeObservableValue<Maybe<T[K]>>\n}\n\n/**\n * A type map of the jsx extended properties to the type provided to the hook.\n */\nexport type HookExtensions = {\n [p in keyof typeof hookExtensions]?: Parameters<\n (typeof hookExtensions)[p]\n >[1]\n}\n\nexport type ElementProps<K extends keyof HTMLElementTagNameMap> = Omit<\n Partial<Writable<HTMLElementTagNameMap[K]>>,\n keyof HookExtensions\n>\n\nexport type BindableElementProps<K extends keyof HTMLElementTagNameMap> =\n AllowBindable<ElementProps<K>>\n\n/**\n * Allowed properties for intrinsic elements when writing jsx declarative markup.\n */\nexport type JsxElementProps<K extends keyof HTMLElementTagNameMap> =\n BindableElementProps<K> & HookExtensions\n\nexport type DomIntrinsicElements = {\n [K in keyof HTMLElementTagNameMap]: JsxElementProps<K>\n}\n\nexport type JsxChild = Node | string | ObservableValue<Node | string>\n\nexport function jsx<K extends keyof HTMLElementTagNameMap>(\n type: K,\n props: JsxElementProps<K>,\n ...children: JsxChild[]\n): HTMLElementTagNameMap[K]\n\nexport function jsx<Factory extends JsxFactory>(\n type: Factory,\n props: Parameters<Factory>[0],\n ...children: Parameters<Factory>[1]\n): ReturnType<Factory>\n\nexport function jsx(type: any, props: any, ...children: any) {\n if (typeof type === 'string') {\n const element = document.createElement(type)\n for (const k in props) {\n const v = props[k]\n if (k in hookExtensions) {\n hookExtensions[k as keyof typeof hookExtensions](element, v)\n continue\n }\n if (isObservableValue(v)) {\n onConnect(element, () => {\n return v.onData((data$) => setProp(element, k, data$))\n })\n } else {\n setProp(element, k, v)\n }\n }\n element.append(\n ...children\n .filter((child: JsxChild | null) => child != null)\n .map((child: JsxChild) => {\n return isObservableValue(child) ? ActiveText(child) : child\n })\n )\n return element\n } else {\n return type(props, children)\n }\n}\n\nexport function Fragment(_props: AnyRecord, children: (Node | string)[]) {\n return jsx(\n 'div',\n {\n style: {\n display: 'contents',\n },\n },\n ...children\n )\n}\n\ndeclare global {\n // eslint-disable-next-line @typescript-eslint/no-namespace\n namespace JSX {\n type IntrinsicElements = DomIntrinsicElements\n type Element = HTMLElement\n type Fragment = HTMLElement\n }\n}\n", "/*\n * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n * SPDX-License-Identifier: Apache-2.0\n */\n\nimport type { ObservableValue } from '@amazon/vinyl-observable'\nimport { onConnect } from './extensions/connectedObserver'\n\n/**\n * A Text node bound to a data provider.\n * Created automatically when a child is a ObservableValue.\n * textContent will only be updated when the node is on the DOM.\n */\nexport function ActiveText<T>(data: ObservableValue<T>): Text {\n const text = document.createTextNode(String(data.value ?? ''))\n onConnect(text, () => {\n return data.onData((value) => {\n text.textContent = String(value ?? '')\n })\n })\n return text\n}\n", "/*\n * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n * SPDX-License-Identifier: Apache-2.0\n */\n\nimport type { ObservableValue } from '@amazon/vinyl-observable'\nimport { onConnect } from './connectedObserver'\n\nexport function applyVisibility(\n element: HTMLElement,\n visible: boolean | ObservableValue<boolean>\n): void {\n if (typeof visible === 'boolean') {\n if (!visible) element.style.display = 'none'\n } else {\n onConnect(element, () => {\n return visible.onData((value) => {\n if (value) element.style.removeProperty('display')\n else element.style.display = 'none'\n })\n })\n }\n}\n", "/*\n * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n * SPDX-License-Identifier: Apache-2.0\n */\n\nimport {\n isObservableValue,\n type ObservableValue,\n} from '@amazon/vinyl-observable'\nimport { onConnect } from './connectedObserver'\nimport type { Maybe, Unsubscribe } from '@amazon/vinyl-util'\n\nexport function applyClassList(\n element: HTMLElement,\n classList: readonly (Maybe<string> | ObservableValue<Maybe<string>>)[]\n): void {\n const tokens = classList.filter((s) => typeof s === 'string')\n element.classList.add(...tokens)\n if (tokens.length < classList.length) {\n onConnect(element, () => {\n const subs: Unsubscribe[] = []\n for (const dP of classList.filter(isObservableValue)) {\n subs.push(bindClass(element, dP))\n }\n return () => {\n subs.forEach((sub) => sub())\n }\n })\n }\n}\n\nfunction bindClass(\n element: HTMLElement,\n tokenProvider: ObservableValue<Maybe<string>>\n): Unsubscribe {\n let current: string | null = null\n const dataSub = tokenProvider.onData((className) => {\n if (current) element.classList.remove(current)\n if (className) {\n current = className\n element.classList.add(className)\n } else {\n current = null\n }\n })\n return () => {\n if (current != null) element.classList.remove(current)\n dataSub()\n }\n}\n", "/*\n * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n * SPDX-License-Identifier: Apache-2.0\n */\n\nimport type { HookExtension } from './HookExtension'\n\nexport const passiveEventHandlers = {\n ontouchstart: /* @__PURE__ */ applyPassiveHandler('ontouchstart'),\n ontouchmove: /* @__PURE__ */ applyPassiveHandler('ontouchmove'),\n onwheel: /* @__PURE__ */ applyPassiveHandler('onwheel'),\n} as const\n\nfunction applyPassiveHandler<K extends keyof GlobalEventHandlers>(\n key: K\n): HookExtension<GlobalEventHandlers[K]> {\n const eventName = key.substring(2)\n return (element: HTMLElement, handler: GlobalEventHandlers[K]) => {\n element.addEventListener(eventName, handler as any, { passive: true })\n }\n}\n"],
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;AAUO,SAAS,GACZ,WACA,aAAyB,UACxB;AACD,QAAM,UAAU,WAAW,cAAc,SAAS;AAClD,MAAI,CAAC,QAAS,OAAM,IAAI,MAAM,GAAG,SAAS,wBAAwB;AAClE,SAAO;AACX;AAUO,SAAS,kBAAkB,YAAuC;AACrE,SAAO,CAAC,cAAsB,GAAG,WAAW,UAAU;AAC1D;AAEO,SAAS,KAAK,SAAsB;AACvC,UAAQ,MAAM,UAAU;AAC5B;AAEO,SAAS,KAAK,SAAsB;AACvC,UAAQ,MAAM,eAAe,SAAS;AAC1C;AAEO,SAAS,WAAW,SAA+B;AACtD,SAAO,QAAQ,MAAM,YAAY;AACrC;AAEO,SAAS,WAAW,SAAsB,OAAgB;AAC7D,MAAI,WAAW,OAAO,MAAM,MAAO;AACnC,MAAI,MAAO,MAAK,OAAO;AAAA,MAClB,MAAK,OAAO;AACrB;AAEO,SAAS,SAAS,SAAsB;AAC3C,MAAI,OAA2B;AAC/B,SAAO,MAAM;AACT,QAAI,iBAAiB,IAAI,EAAE,YAAY,OAAQ,QAAO;AACtD,WAAO,KAAK;AAAA,EAChB;AACA,SAAO;AACX;AAEO,SAAS,eACZ,OACyB;AACzB,UAAO,+BAAO,QAAQ,mBAAkB;AAC5C;AASO,SAAS,cACZ,OACA,OACA,SACF;AACE,MAAI,SAAS;AACT,UAAM,UAAU,IAAI,KAAK;AAAA,EAC7B,OAAO;AACH,UAAM,UAAU,OAAO,KAAK;AAAA,EAChC;AACJ;AAaO,SAAS,kBACZ,MACA,UACF;AACE,MAAI,CAAC,KAAM;AACX,MAAI,OAAO,KAAK;AAChB,SAAO,MAAM;
|
|
6
|
-
"names": ["onConnect", "isObservableValue", "isObservableValue", "isObservableValue"
|
|
3
|
+
"sources": ["../src/domUtil.ts", "../src/extensions/connectedObserver.ts", "../src/ActiveText.ts", "../src/extensions/applyClassList.ts", "../src/extensions/applyPassiveHandler.ts", "../src/extensions/applyStyles.ts", "../src/extensions/applyVisibility.ts", "../src/jsx.ts"],
|
|
4
|
+
"sourcesContent": ["/*\n * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n * SPDX-License-Identifier: Apache-2.0\n */\n\nexport function el<K extends keyof HTMLElementTagNameMap>(\n selectors: K,\n parentNode?: ParentNode\n): HTMLElementTagNameMap[K]\nexport function el(selectors: string, parentNode?: ParentNode): HTMLElement\nexport function el<E extends Element = Element>(\n selectors: string,\n parentNode: ParentNode = document\n): E {\n const element = parentNode.querySelector(selectors)\n if (!element) throw new Error(`${selectors} must be a DOM element`)\n return element as E\n}\n\nexport interface QuerySelector {\n <K extends keyof HTMLElementTagNameMap>(\n selectors: K,\n parentNode?: ParentNode\n ): HTMLElementTagNameMap[K]\n (selectors: string): HTMLElement\n}\n\nexport function bindQuerySelector(parentNode: ParentNode): QuerySelector {\n return (selectors: string) => el(selectors, parentNode)\n}\n\nexport function hide(element: HTMLElement) {\n element.style.display = 'none'\n}\n\nexport function show(element: HTMLElement) {\n element.style.removeProperty('display')\n}\n\nexport function getVisible(element: HTMLElement): boolean {\n return element.style.display !== 'none'\n}\n\nexport function setVisible(element: HTMLElement, value: boolean) {\n if (getVisible(element) === value) return\n if (value) show(element)\n else hide(element)\n}\n\nexport function isHidden(element: HTMLElement) {\n let node: HTMLElement | null = element\n while (node) {\n if (getComputedStyle(node).display === 'none') return true\n node = node.parentElement\n }\n return false\n}\n\nexport function isInputElement(\n value: Element | null\n): value is HTMLInputElement {\n return value?.tagName.toLowerCase() === 'input'\n}\n\n/**\n * Adds or removes a class token to an element.\n *\n * @param value The element whose classList to modify.\n * @param token The class token.\n * @param toggled If true, the token is added, if false, removed.\n */\nexport function setClassToken(\n value: HTMLElement,\n token: string,\n toggled: boolean\n) {\n if (toggled) {\n value.classList.add(token)\n } else {\n value.classList.remove(token)\n }\n}\n\nexport type ElementInitOptions = {\n readonly parent?: HTMLElement\n readonly className?: string\n}\n\n/**\n * Recursively walks a node hierarchy, invoking a callback for every node, depth first.\n *\n * @param node\n * @param callback\n */\nexport function walkDomDepthFirst(\n node: Node | undefined | null,\n callback: (node: Node) => void\n) {\n if (!node) return\n let next = node.firstChild\n while (next) {\n // Snapshot the sibling before recursing so a callback that moves\n // `next` can't sever the chain and skip the rest of the row.\n const after = next.nextSibling\n walkDomDepthFirst(next, callback)\n next = after\n }\n callback(node)\n}\n", "/*\n * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n * SPDX-License-Identifier: Apache-2.0\n */\n\nimport { walkDomDepthFirst } from '../domUtil'\nimport type { Maybe, Unsubscribe } from '@amazon/vinyl-util'\n\n/**\n * Dispatches a 'connected' event on nodes attached to the dom, dispatches 'disconnected' when removed.\n * Allows nodes to observe connected changes without creating a memory leak.\n */\nexport function initializeConnectedObserver(): Unsubscribe {\n const observer = new MutationObserver((mutations) => {\n const removed = new Set<Node>()\n const added = new Set<Node>()\n\n // First pass: flatten removed and added nodes so we can detect nodes re-ordered.\n for (const mutation of mutations) {\n mutation.removedNodes.forEach((node) => removed.add(node))\n mutation.addedNodes.forEach((node) => added.add(node))\n }\n\n // Second pass: handle added/removed, skipping reorders\n for (const mutation of mutations) {\n for (const node of mutation.addedNodes) {\n if (removed.has(node)) continue\n walkDomDepthFirst(node, (iNode) => {\n iNode.dispatchEvent(\n new CustomEvent('connect', { bubbles: false })\n )\n })\n }\n\n for (const node of mutation.removedNodes) {\n if (added.has(node)) continue\n walkDomDepthFirst(node, (iNode) => {\n iNode.dispatchEvent(\n new CustomEvent('disconnect', { bubbles: false })\n )\n })\n }\n }\n })\n\n observer.observe(document, { childList: true, subtree: true })\n\n return () => {\n observer.disconnect()\n }\n}\n\n/**\n * Invokes a callback when the given target is connected to the DOM.\n * If the callback returns a function, that function will be invoked when disconnected.\n *\n * @param target\n * @param callback\n */\nexport function onConnect<T extends Node>(\n target: T,\n callback: (node: T) => Maybe<Unsubscribe> | void\n): Unsubscribe {\n let sub: Maybe<Unsubscribe> | void = null\n let connected = false\n const onConnect = () => {\n if (connected) return\n connected = true\n sub = callback(target)\n }\n const onDisconnect = () => {\n connected = false\n sub?.()\n sub = null\n }\n target.addEventListener('connect', onConnect)\n target.addEventListener('disconnect', onDisconnect)\n if (target.isConnected) onConnect()\n return () => {\n target.removeEventListener('connect', onConnect)\n target.removeEventListener('disconnect', onDisconnect)\n onDisconnect()\n }\n}\n", "/*\n * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n * SPDX-License-Identifier: Apache-2.0\n */\n\nimport type { ObservableValue } from '@amazon/vinyl-observable'\nimport { onConnect } from './extensions/connectedObserver'\n\n/**\n * A Text node bound to a data provider.\n * Created automatically when a child is a ObservableValue.\n * textContent will only be updated when the node is on the DOM.\n */\nexport function ActiveText<T>(data: ObservableValue<T>): Text {\n const text = document.createTextNode(String(data.value ?? ''))\n onConnect(text, () => {\n return data.onData((value) => {\n text.textContent = String(value ?? '')\n })\n })\n return text\n}\n", "/*\n * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n * SPDX-License-Identifier: Apache-2.0\n */\n\nimport {\n isObservableValue,\n type ObservableValue,\n} from '@amazon/vinyl-observable'\nimport { onConnect } from './connectedObserver'\nimport {\n createDisposer,\n noop,\n type Maybe,\n type Unsubscribe,\n} from '@amazon/vinyl-util'\n\nexport function applyClassList(\n element: HTMLElement,\n classList: readonly (Maybe<string> | ObservableValue<Maybe<string>>)[]\n): Unsubscribe {\n const tokens = classList.filter((s) => typeof s === 'string')\n element.classList.add(...tokens)\n if (tokens.length < classList.length) {\n return onConnect(element, () => {\n const { add, dispose } = createDisposer()\n for (const dP of classList.filter(isObservableValue)) {\n add(bindClass(element, dP))\n }\n return dispose\n })\n }\n return noop\n}\n\nfunction bindClass(\n element: HTMLElement,\n tokenProvider: ObservableValue<Maybe<string>>\n): Unsubscribe {\n let current: string | null = null\n const dataSub = tokenProvider.onData((className) => {\n if (current) element.classList.remove(current)\n if (className) {\n current = className\n element.classList.add(className)\n } else {\n current = null\n }\n })\n return () => {\n if (current != null) element.classList.remove(current)\n dataSub()\n }\n}\n", "/*\n * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n * SPDX-License-Identifier: Apache-2.0\n */\n\nimport type { HookExtension } from './HookExtension'\n\nexport const passiveEventHandlers = {\n ontouchstart: /* @__PURE__ */ applyPassiveHandler('ontouchstart'),\n ontouchmove: /* @__PURE__ */ applyPassiveHandler('ontouchmove'),\n onwheel: /* @__PURE__ */ applyPassiveHandler('onwheel'),\n} as const\n\nfunction applyPassiveHandler<K extends keyof GlobalEventHandlers>(\n key: K\n): HookExtension<GlobalEventHandlers[K]> {\n const eventName = key.substring(2)\n return (element: HTMLElement, handler: GlobalEventHandlers[K]) => {\n element.addEventListener(eventName, handler as any, { passive: true })\n }\n}\n", "/*\n * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n * SPDX-License-Identifier: Apache-2.0\n */\n\nimport { onConnect } from './connectedObserver'\nimport { toKebabCase } from '@amazon/vinyl-util'\nimport {\n isObservableValue,\n type MaybeObservableValue,\n} from '@amazon/vinyl-observable'\nimport type { Maybe } from '@amazon/vinyl-util'\n\n/**\n * The shape accepted by the `style` jsx prop. Allows the typed CSSStyleDeclaration\n * fields plus any CSS custom property key (must start with `--`). Null / undefined\n * clear the CSS property (via setProperty(name, null)), so values are Maybe-wrapped\n * here even though bindable IDL props reject null.\n */\nexport type StyleProp = {\n [K in keyof Partial<CSSStyleDeclaration>]: MaybeObservableValue<\n Maybe<CSSStyleDeclaration[K]>\n >\n} & {\n readonly [customProperty: `--${string}`]: MaybeObservableValue<\n Maybe<string>\n >\n}\n\nexport function applyStyles(element: HTMLElement, style: StyleProp) {\n // noinspection SuspiciousTypeOfGuard\n if (typeof style === 'string') {\n // A Partial style declaration type does not prohibit a string type.\n throw new Error('expected style property to be type object')\n }\n for (const k in style) {\n const v = (style as Record<string, unknown>)[k]\n // Custom properties (starting with `--`) are passed through as-is so\n // they aren't kebab-cased a second time, and so they remain valid keys\n // for setProperty.\n const property = k.startsWith('--') ? k : toKebabCase(k)\n if (isObservableValue(v)) {\n onConnect(element, () => {\n return v.onData((value) => {\n element.style.setProperty(\n property,\n (value ?? null) as string | null\n )\n })\n })\n } else {\n element.style.setProperty(property, (v ?? null) as string | null)\n }\n }\n}\n", "/*\n * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n * SPDX-License-Identifier: Apache-2.0\n */\n\nimport type { ObservableValue } from '@amazon/vinyl-observable'\nimport { onConnect } from './connectedObserver'\n\nexport function applyVisibility(\n element: HTMLElement,\n visible: boolean | ObservableValue<boolean>\n): void {\n if (typeof visible === 'boolean') {\n if (!visible) element.style.display = 'none'\n } else {\n onConnect(element, () => {\n return visible.onData((value) => {\n if (value) element.style.removeProperty('display')\n else element.style.display = 'none'\n })\n })\n }\n}\n", "/*\n * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n * SPDX-License-Identifier: Apache-2.0\n */\n\nimport { onConnect } from './extensions/connectedObserver'\nimport type { Writable } from './type'\nimport { applyStyles } from './extensions/applyStyles'\nimport {\n isObservableValue,\n type MaybeObservableValue,\n type ObservableValue,\n} from '@amazon/vinyl-observable'\nimport { ActiveText } from './ActiveText'\nimport { applyVisibility } from './extensions/applyVisibility'\nimport { applyClassList } from './extensions/applyClassList'\nimport type { HookExtension } from './extensions/HookExtension'\nimport { passiveEventHandlers } from './extensions/applyPassiveHandler'\nimport type { AnyRecord } from '@amazon/vinyl-util'\n\n/**\n * Names like `aria-label` / `role` / `data-*` / any hyphenated prop are DOM\n * attributes with no matching IDL property \u2014 assigning them via `element[k]`\n * creates an inert expando and the a11y tree / CSS attribute selectors never\n * see the value. Route those through setAttribute so JSX like\n * `<div aria-label=\"foo\" />` actually reaches the DOM.\n */\nfunction isAttributeOnlyName(k: string): boolean {\n return k === 'role' || k.indexOf('-') >= 0\n}\n\n/**\n * Sets a property on an element. Hyphenated / aria / role / data names are\n * assigned as HTML attributes; everything else stays on the property path so\n * camelCase IDL props (className, tabIndex, onClick, \u2026) keep their existing\n * fast-path semantics.\n */\nfunction setProp(element: HTMLElement, k: string, value: unknown): void {\n if (isAttributeOnlyName(k)) {\n if (value == null) element.removeAttribute(k)\n else element.setAttribute(k, String(value))\n } else {\n ;(element as any)[k] = value\n }\n}\n\nexport type JsxFactory = (props: any, children: any[]) => any\n\n/**\n * A map of custom jsx properties to be used in hook extensions.\n */\nexport const hookExtensions = {\n onConnect: onConnect<HTMLElement>,\n style: applyStyles,\n visible: applyVisibility,\n classList: applyClassList,\n ...passiveEventHandlers,\n} as const satisfies Record<keyof any, HookExtension<any>>\n\nexport type AllowBindable<T> = {\n [K in keyof T]: MaybeObservableValue<T[K]>\n}\n\n/**\n * A type map of the jsx extended properties to the type provided to the hook.\n */\nexport type HookExtensions = {\n [p in keyof typeof hookExtensions]?: Parameters<\n (typeof hookExtensions)[p]\n >[1]\n}\n\nexport type ElementProps<K extends keyof HTMLElementTagNameMap> = Omit<\n Partial<Writable<HTMLElementTagNameMap[K]>>,\n keyof HookExtensions\n>\n\nexport type BindableElementProps<K extends keyof HTMLElementTagNameMap> =\n AllowBindable<ElementProps<K>>\n\n/**\n * Allowed properties for intrinsic elements when writing jsx declarative markup.\n */\nexport type JsxElementProps<K extends keyof HTMLElementTagNameMap> =\n BindableElementProps<K> & HookExtensions\n\nexport type DomIntrinsicElements = {\n [K in keyof HTMLElementTagNameMap]: JsxElementProps<K>\n}\n\nexport type JsxChild = Node | string | ObservableValue<Node | string>\n\nexport function jsx<K extends keyof HTMLElementTagNameMap>(\n type: K,\n props: JsxElementProps<K>,\n ...children: JsxChild[]\n): HTMLElementTagNameMap[K]\n\nexport function jsx<Factory extends JsxFactory>(\n type: Factory,\n props: Parameters<Factory>[0],\n ...children: Parameters<Factory>[1]\n): ReturnType<Factory>\n\nexport function jsx(type: any, props: any, ...children: any) {\n if (typeof type === 'string') {\n const element = document.createElement(type)\n for (const k in props) {\n const v = props[k]\n if (k in hookExtensions) {\n hookExtensions[k as keyof typeof hookExtensions](element, v)\n continue\n }\n if (isObservableValue(v)) {\n onConnect(element, () => {\n return v.onData((data$) => setProp(element, k, data$))\n })\n } else {\n setProp(element, k, v)\n }\n }\n element.append(\n ...children\n .filter((child: JsxChild | null) => child != null)\n .map((child: JsxChild) => {\n return isObservableValue(child) ? ActiveText(child) : child\n })\n )\n return element\n } else {\n return type(props ?? {}, children)\n }\n}\n\nexport function Fragment(_props: AnyRecord, children: (Node | string)[]) {\n return jsx(\n 'div',\n {\n style: {\n display: 'contents',\n },\n },\n ...children\n )\n}\n\ndeclare global {\n // eslint-disable-next-line @typescript-eslint/no-namespace\n namespace JSX {\n type IntrinsicElements = DomIntrinsicElements\n type Element = HTMLElement\n type Fragment = HTMLElement\n }\n}\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;AAUO,SAAS,GACZ,WACA,aAAyB,UACxB;AACD,QAAM,UAAU,WAAW,cAAc,SAAS;AAClD,MAAI,CAAC,QAAS,OAAM,IAAI,MAAM,GAAG,SAAS,wBAAwB;AAClE,SAAO;AACX;AAUO,SAAS,kBAAkB,YAA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,SAAS;AAAA,EACT,WAAW;AAAA,GACR;AAgDA,SAAS,IAAI,MAAW,UAAe,UAAe;AACzD,MAAI,OAAO,SAAS,UAAU;AAC1B,UAAM,UAAU,SAAS,cAAc,IAAI;AAC3C,eAAW,KAAK,OAAO;AACnB,YAAM,IAAI,MAAM,CAAC;AACjB,UAAI,KAAK,gBAAgB;AACrB,uBAAe,CAAgC,EAAE,SAAS,CAAC;AAC3D;AAAA,MACJ;AACA,UAAIC,mBAAkB,CAAC,GAAG;AACtB,kBAAU,SAAS,MAAM;AACrB,iBAAO,EAAE,OAAO,CAAC,UAAU,QAAQ,SAAS,GAAG,KAAK,CAAC;AAAA,QACzD,CAAC;AAAA,MACL,OAAO;AACH,gBAAQ,SAAS,GAAG,CAAC;AAAA,MACzB;AAAA,IACJ;AACA,YAAQ;AAAA,MACJ,GAAG,SACE,OAAO,CAAC,UAA2B,SAAS,IAAI,EAChD,IAAI,CAAC,UAAoB;AACtB,eAAOA,mBAAkB,KAAK,IAAI,WAAW,KAAK,IAAI;AAAA,MAC1D,CAAC;AAAA,IACT;AACA,WAAO;AAAA,EACX,OAAO;AACH,WAAO,KAAK,wBAAS,CAAC,GAAG,QAAQ;AAAA,EACrC;AACJ;AAEO,SAAS,SAAS,QAAmB,UAA6B;AACrE,SAAO;AAAA,IACH;AAAA,IACA;AAAA,MACI,OAAO;AAAA,QACH,SAAS;AAAA,MACb;AAAA,IACJ;AAAA,IACA,GAAG;AAAA,EACP;AACJ;",
|
|
6
|
+
"names": ["onConnect", "isObservableValue", "isObservableValue", "isObservableValue"]
|
|
7
7
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"domUtil.d.ts","sourceRoot":"","sources":["../../../src/domUtil.ts"],"names":[],"mappings":"AAKA,wBAAgB,EAAE,CAAC,CAAC,SAAS,MAAM,qBAAqB,EACpD,SAAS,EAAE,CAAC,EACZ,UAAU,CAAC,EAAE,UAAU,GACxB,qBAAqB,CAAC,CAAC,CAAC,CA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S,GAAG,IAAI,EAC7B,QAAQ,EAAE,CAAC,IAAI,EAAE,IAAI,KAAK,IAAI,QAYjC"}
|
|
@@ -66,8 +66,11 @@ export function walkDomDepthFirst(node, callback) {
|
|
|
66
66
|
return;
|
|
67
67
|
let next = node.firstChild;
|
|
68
68
|
while (next) {
|
|
69
|
+
// Snapshot the sibling before recursing so a callback that moves
|
|
70
|
+
// `next` can't sever the chain and skip the rest of the row.
|
|
71
|
+
const after = next.nextSibling;
|
|
69
72
|
walkDomDepthFirst(next, callback);
|
|
70
|
-
next =
|
|
73
|
+
next = after;
|
|
71
74
|
}
|
|
72
75
|
callback(node);
|
|
73
76
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import { type ObservableValue } from '@amazon/vinyl-observable';
|
|
2
|
-
import type
|
|
3
|
-
export declare function applyClassList(element: HTMLElement, classList: readonly (Maybe<string> | ObservableValue<Maybe<string>>)[]):
|
|
2
|
+
import { type Maybe, type Unsubscribe } from '@amazon/vinyl-util';
|
|
3
|
+
export declare function applyClassList(element: HTMLElement, classList: readonly (Maybe<string> | ObservableValue<Maybe<string>>)[]): Unsubscribe;
|
|
4
4
|
//# sourceMappingURL=applyClassList.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"applyClassList.d.ts","sourceRoot":"","sources":["../../../../src/extensions/applyClassList.ts"],"names":[],"mappings":"AAKA,OAAO,EAEH,KAAK,eAAe,EACvB,MAAM,0BAA0B,CAAA;AAEjC,OAAO,KAAK,
|
|
1
|
+
{"version":3,"file":"applyClassList.d.ts","sourceRoot":"","sources":["../../../../src/extensions/applyClassList.ts"],"names":[],"mappings":"AAKA,OAAO,EAEH,KAAK,eAAe,EACvB,MAAM,0BAA0B,CAAA;AAEjC,OAAO,EAGH,KAAK,KAAK,EACV,KAAK,WAAW,EACnB,MAAM,oBAAoB,CAAA;AAE3B,wBAAgB,cAAc,CAC1B,OAAO,EAAE,WAAW,EACpB,SAAS,EAAE,SAAS,CAAC,KAAK,CAAC,MAAM,CAAC,GAAG,eAAe,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,GACvE,WAAW,CAab"}
|
|
@@ -4,20 +4,20 @@
|
|
|
4
4
|
*/
|
|
5
5
|
import { isObservableValue, } from '@amazon/vinyl-observable';
|
|
6
6
|
import { onConnect } from './connectedObserver';
|
|
7
|
+
import { createDisposer, noop, } from '@amazon/vinyl-util';
|
|
7
8
|
export function applyClassList(element, classList) {
|
|
8
9
|
const tokens = classList.filter((s) => typeof s === 'string');
|
|
9
10
|
element.classList.add(...tokens);
|
|
10
11
|
if (tokens.length < classList.length) {
|
|
11
|
-
onConnect(element, () => {
|
|
12
|
-
const
|
|
12
|
+
return onConnect(element, () => {
|
|
13
|
+
const { add, dispose } = createDisposer();
|
|
13
14
|
for (const dP of classList.filter(isObservableValue)) {
|
|
14
|
-
|
|
15
|
+
add(bindClass(element, dP));
|
|
15
16
|
}
|
|
16
|
-
return
|
|
17
|
-
subs.forEach((sub) => sub());
|
|
18
|
-
};
|
|
17
|
+
return dispose;
|
|
19
18
|
});
|
|
20
19
|
}
|
|
20
|
+
return noop;
|
|
21
21
|
}
|
|
22
22
|
function bindClass(element, tokenProvider) {
|
|
23
23
|
let current = null;
|
|
@@ -1,11 +1,14 @@
|
|
|
1
|
-
import type { AllowBindable } from '../jsx';
|
|
2
1
|
import { type MaybeObservableValue } from '@amazon/vinyl-observable';
|
|
3
2
|
import type { Maybe } from '@amazon/vinyl-util';
|
|
4
3
|
/**
|
|
5
4
|
* The shape accepted by the `style` jsx prop. Allows the typed CSSStyleDeclaration
|
|
6
|
-
* fields plus any CSS custom property key (must start with `--`).
|
|
5
|
+
* fields plus any CSS custom property key (must start with `--`). Null / undefined
|
|
6
|
+
* clear the CSS property (via setProperty(name, null)), so values are Maybe-wrapped
|
|
7
|
+
* here even though bindable IDL props reject null.
|
|
7
8
|
*/
|
|
8
|
-
export type StyleProp =
|
|
9
|
+
export type StyleProp = {
|
|
10
|
+
[K in keyof Partial<CSSStyleDeclaration>]: MaybeObservableValue<Maybe<CSSStyleDeclaration[K]>>;
|
|
11
|
+
} & {
|
|
9
12
|
readonly [customProperty: `--${string}`]: MaybeObservableValue<Maybe<string>>;
|
|
10
13
|
};
|
|
11
14
|
export declare function applyStyles(element: HTMLElement, style: StyleProp): void;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"applyStyles.d.ts","sourceRoot":"","sources":["../../../../src/extensions/applyStyles.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"applyStyles.d.ts","sourceRoot":"","sources":["../../../../src/extensions/applyStyles.ts"],"names":[],"mappings":"AAOA,OAAO,EAEH,KAAK,oBAAoB,EAC5B,MAAM,0BAA0B,CAAA;AACjC,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,oBAAoB,CAAA;AAE/C;;;;;GAKG;AACH,MAAM,MAAM,SAAS,GAAG;KACnB,CAAC,IAAI,MAAM,OAAO,CAAC,mBAAmB,CAAC,GAAG,oBAAoB,CAC3D,KAAK,CAAC,mBAAmB,CAAC,CAAC,CAAC,CAAC,CAChC;CACJ,GAAG;IACA,QAAQ,EAAE,cAAc,EAAE,KAAK,MAAM,EAAE,GAAG,oBAAoB,CAC1D,KAAK,CAAC,MAAM,CAAC,CAChB,CAAA;CACJ,CAAA;AAED,wBAAgB,WAAW,CAAC,OAAO,EAAE,WAAW,EAAE,KAAK,EAAE,SAAS,QAyBjE"}
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
/** Auto-generated from build scripts */
|
|
2
|
-
export * from './type';
|
|
3
|
-
export * from './jsx';
|
|
4
|
-
export * from './domUtil';
|
|
5
2
|
export * from './ActiveText';
|
|
6
|
-
export * from './
|
|
7
|
-
export * from './extensions/applyVisibility';
|
|
8
|
-
export * from './extensions/applyStyles';
|
|
9
|
-
export * from './extensions/applyPassiveHandler';
|
|
3
|
+
export * from './domUtil';
|
|
10
4
|
export * from './extensions/applyClassList';
|
|
5
|
+
export * from './extensions/applyPassiveHandler';
|
|
6
|
+
export * from './extensions/applyStyles';
|
|
7
|
+
export * from './extensions/applyVisibility';
|
|
8
|
+
export * from './extensions/connectedObserver';
|
|
11
9
|
export * from './extensions/HookExtension';
|
|
10
|
+
export * from './jsx';
|
|
11
|
+
export * from './type';
|
|
12
12
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/index.ts"],"names":[],"mappings":"AAAA,wCAAwC;AACxC,cAAc,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/index.ts"],"names":[],"mappings":"AAAA,wCAAwC;AACxC,cAAc,cAAc,CAAA;AAC5B,cAAc,WAAW,CAAA;AACzB,cAAc,6BAA6B,CAAA;AAC3C,cAAc,kCAAkC,CAAA;AAChD,cAAc,0BAA0B,CAAA;AACxC,cAAc,8BAA8B,CAAA;AAC5C,cAAc,gCAAgC,CAAA;AAC9C,cAAc,4BAA4B,CAAA;AAC1C,cAAc,OAAO,CAAA;AACrB,cAAc,QAAQ,CAAA"}
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
/** Auto-generated from build scripts */
|
|
2
|
-
export * from './type';
|
|
3
|
-
export * from './jsx';
|
|
4
|
-
export * from './domUtil';
|
|
5
2
|
export * from './ActiveText';
|
|
6
|
-
export * from './
|
|
7
|
-
export * from './extensions/applyVisibility';
|
|
8
|
-
export * from './extensions/applyStyles';
|
|
9
|
-
export * from './extensions/applyPassiveHandler';
|
|
3
|
+
export * from './domUtil';
|
|
10
4
|
export * from './extensions/applyClassList';
|
|
5
|
+
export * from './extensions/applyPassiveHandler';
|
|
6
|
+
export * from './extensions/applyStyles';
|
|
7
|
+
export * from './extensions/applyVisibility';
|
|
8
|
+
export * from './extensions/connectedObserver';
|
|
11
9
|
export * from './extensions/HookExtension';
|
|
10
|
+
export * from './jsx';
|
|
11
|
+
export * from './type';
|
|
@@ -4,12 +4,7 @@ import { type MaybeObservableValue, type ObservableValue } from '@amazon/vinyl-o
|
|
|
4
4
|
import { applyVisibility } from './extensions/applyVisibility';
|
|
5
5
|
import { applyClassList } from './extensions/applyClassList';
|
|
6
6
|
import type { HookExtension } from './extensions/HookExtension';
|
|
7
|
-
import type { AnyRecord
|
|
8
|
-
/**
|
|
9
|
-
* Maps JS property names to their corresponding HTML attribute names where they differ.
|
|
10
|
-
* Extensible — add entries for custom elements or non-standard properties.
|
|
11
|
-
*/
|
|
12
|
-
export declare const propToAttr: Record<string, string>;
|
|
7
|
+
import type { AnyRecord } from '@amazon/vinyl-util';
|
|
13
8
|
export type JsxFactory = (props: any, children: any[]) => any;
|
|
14
9
|
/**
|
|
15
10
|
* A map of custom jsx properties to be used in hook extensions.
|
|
@@ -18,13 +13,13 @@ export declare const hookExtensions: {
|
|
|
18
13
|
readonly ontouchstart: HookExtension<((this: GlobalEventHandlers, ev: TouchEvent) => any) | null | undefined>;
|
|
19
14
|
readonly ontouchmove: HookExtension<((this: GlobalEventHandlers, ev: TouchEvent) => any) | null | undefined>;
|
|
20
15
|
readonly onwheel: HookExtension<((this: GlobalEventHandlers, ev: WheelEvent) => any) | null>;
|
|
21
|
-
readonly onConnect: (target: HTMLElement, callback: (node: HTMLElement) => Maybe<import("@amazon/vinyl-util").Unsubscribe> | void) => import("@amazon/vinyl-util").Unsubscribe;
|
|
16
|
+
readonly onConnect: (target: HTMLElement, callback: (node: HTMLElement) => import("@amazon/vinyl-util").Maybe<import("@amazon/vinyl-util").Unsubscribe> | void) => import("@amazon/vinyl-util").Unsubscribe;
|
|
22
17
|
readonly style: typeof applyStyles;
|
|
23
18
|
readonly visible: typeof applyVisibility;
|
|
24
19
|
readonly classList: typeof applyClassList;
|
|
25
20
|
};
|
|
26
21
|
export type AllowBindable<T> = {
|
|
27
|
-
[K in keyof T]: MaybeObservableValue<
|
|
22
|
+
[K in keyof T]: MaybeObservableValue<T[K]>;
|
|
28
23
|
};
|
|
29
24
|
/**
|
|
30
25
|
* A type map of the jsx extended properties to the type provided to the hook.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"jsx.d.ts","sourceRoot":"","sources":["../../../src/jsx.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,QAAQ,CAAA;AACtC,OAAO,EAAE,WAAW,EAAE,MAAM,0BAA0B,CAAA;AACtD,OAAO,EAEH,KAAK,oBAAoB,EACzB,KAAK,eAAe,EACvB,MAAM,0BAA0B,CAAA;AAEjC,OAAO,EAAE,eAAe,EAAE,MAAM,8BAA8B,CAAA;AAC9D,OAAO,EAAE,cAAc,EAAE,MAAM,6BAA6B,CAAA;AAC5D,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,4BAA4B,CAAA;AAE/D,OAAO,KAAK,EAAE,SAAS,EAAE,
|
|
1
|
+
{"version":3,"file":"jsx.d.ts","sourceRoot":"","sources":["../../../src/jsx.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,QAAQ,CAAA;AACtC,OAAO,EAAE,WAAW,EAAE,MAAM,0BAA0B,CAAA;AACtD,OAAO,EAEH,KAAK,oBAAoB,EACzB,KAAK,eAAe,EACvB,MAAM,0BAA0B,CAAA;AAEjC,OAAO,EAAE,eAAe,EAAE,MAAM,8BAA8B,CAAA;AAC9D,OAAO,EAAE,cAAc,EAAE,MAAM,6BAA6B,CAAA;AAC5D,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,4BAA4B,CAAA;AAE/D,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAA;AA4BnD,MAAM,MAAM,UAAU,GAAG,CAAC,KAAK,EAAE,GAAG,EAAE,QAAQ,EAAE,GAAG,EAAE,KAAK,GAAG,CAAA;AAE7D;;GAEG;AACH,eAAO,MAAM,cAAc;;;;;;;;CAM+B,CAAA;AAE1D,MAAM,MAAM,aAAa,CAAC,CAAC,IAAI;K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EAAE,UAAU,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,GACpC,UAAU,CAAC,OAAO,CAAC,CAAA;AAgCtB,wBAAgB,QAAQ,CAAC,MAAM,EAAE,SAAS,EAAE,QAAQ,EAAE,CAAC,IAAI,GAAG,MAAM,CAAC,EAAE,kBAUtE;AAED,OAAO,CAAC,MAAM,CAAC;IAEX,UAAU,GAAG,CAAC;QACV,KAAK,iBAAiB,GAAG,oBAAoB,CAAA;QAC7C,KAAK,OAAO,GAAG,WAAW,CAAA;QAC1B,KAAK,QAAQ,GAAG,WAAW,CAAA;KAC9B;CACJ"}
|
|
@@ -10,48 +10,27 @@ import { applyVisibility } from './extensions/applyVisibility';
|
|
|
10
10
|
import { applyClassList } from './extensions/applyClassList';
|
|
11
11
|
import { passiveEventHandlers } from './extensions/applyPassiveHandler';
|
|
12
12
|
/**
|
|
13
|
-
*
|
|
14
|
-
*
|
|
13
|
+
* Names like `aria-label` / `role` / `data-*` / any hyphenated prop are DOM
|
|
14
|
+
* attributes with no matching IDL property — assigning them via `element[k]`
|
|
15
|
+
* creates an inert expando and the a11y tree / CSS attribute selectors never
|
|
16
|
+
* see the value. Route those through setAttribute so JSX like
|
|
17
|
+
* `<div aria-label="foo" />` actually reaches the DOM.
|
|
15
18
|
*/
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
className: 'class',
|
|
20
|
-
colSpan: 'colspan',
|
|
21
|
-
contentEditable: 'contenteditable',
|
|
22
|
-
crossOrigin: 'crossorigin',
|
|
23
|
-
dateTime: 'datetime',
|
|
24
|
-
dirName: 'dirname',
|
|
25
|
-
encType: 'enctype',
|
|
26
|
-
formAction: 'formaction',
|
|
27
|
-
formEnctype: 'formenctype',
|
|
28
|
-
formMethod: 'formmethod',
|
|
29
|
-
formNoValidate: 'formnovalidate',
|
|
30
|
-
formTarget: 'formtarget',
|
|
31
|
-
htmlFor: 'for',
|
|
32
|
-
httpEquiv: 'http-equiv',
|
|
33
|
-
inputMode: 'inputmode',
|
|
34
|
-
maxLength: 'maxlength',
|
|
35
|
-
minLength: 'minlength',
|
|
36
|
-
noModule: 'nomodule',
|
|
37
|
-
noValidate: 'novalidate',
|
|
38
|
-
readOnly: 'readonly',
|
|
39
|
-
referrerPolicy: 'referrerpolicy',
|
|
40
|
-
rowSpan: 'rowspan',
|
|
41
|
-
tabIndex: 'tabindex',
|
|
42
|
-
useMap: 'usemap',
|
|
43
|
-
};
|
|
19
|
+
function isAttributeOnlyName(k) {
|
|
20
|
+
return k === 'role' || k.indexOf('-') >= 0;
|
|
21
|
+
}
|
|
44
22
|
/**
|
|
45
|
-
* Sets a property on an element.
|
|
46
|
-
*
|
|
47
|
-
*
|
|
23
|
+
* Sets a property on an element. Hyphenated / aria / role / data names are
|
|
24
|
+
* assigned as HTML attributes; everything else stays on the property path so
|
|
25
|
+
* camelCase IDL props (className, tabIndex, onClick, …) keep their existing
|
|
26
|
+
* fast-path semantics.
|
|
48
27
|
*/
|
|
49
28
|
function setProp(element, k, value) {
|
|
50
|
-
if (
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
29
|
+
if (isAttributeOnlyName(k)) {
|
|
30
|
+
if (value == null)
|
|
31
|
+
element.removeAttribute(k);
|
|
32
|
+
else
|
|
33
|
+
element.setAttribute(k, String(value));
|
|
55
34
|
}
|
|
56
35
|
else {
|
|
57
36
|
;
|
|
@@ -94,7 +73,7 @@ export function jsx(type, props, ...children) {
|
|
|
94
73
|
return element;
|
|
95
74
|
}
|
|
96
75
|
else {
|
|
97
|
-
return type(props, children);
|
|
76
|
+
return type(props ?? {}, children);
|
|
98
77
|
}
|
|
99
78
|
}
|
|
100
79
|
export function Fragment(_props, children) {
|