toolmark-monorepo / @toolmark/core/dom / scanDom
Function: scanDom()
scanDom(
opts?): (tm) => () =>void
Defined in: packages/core/src/dom/scan.ts:225
Scans the DOM for declarative tools and keeps them registered (spec §10.2). Use it as a consumer: tm.use(scanDom()).
- Trusted root: nothing under
[data-tool-ignore],[contenteditable](any value but"false"),<iframe>or<template>is scanned (nor anything at all whenrootitself is inside such a region). Tool and field descriptions come from the scanned markup, which must be app-authored (§14). - Forms: a form with native
toolname+tooldescriptionregisters<toolname>.fill/.submit(and.options) through domFormAdapter and the synthesized schema, withorigin: 'native-form'andnativeName = toolnameon.filland.submit;toolautosubmitremoves the submit's confirmation hint, otherwise it isconsequential. A form withdata-tool+data-tool-descriptionregisters the same withorigin: 'dom'(data-tool-destructivemakes its submitdestructive;data-tool-confirmis its submit summary).data-tool-options-urlon a field adds a same-origin options lookup (other URLs are ignored with anoptions_url_rejectedevent). Fill and submit results are markeduntrustedContent. - Buttons (
<button>/ button<input>withdata-toolanddata-tool-description; without a description the button is skipped with aninvalid_nameevent in development, never described from its text) → an action tool that clicks the button; a button that submits or resets its form is always at leastconsequential, uses the form'sdata-tool-confirmas its summary, and its approval is refusedstalewhen the form's values changed after the confirmation was requested. - Tables with
data-toolandth[data-tool-column](at most 32 columns) → a read-only query tool whose rows are capped at 200 000 JSON characters (truncated: true). data-tool-groupon an ancestor puts the tools in a scope of that name. An invalid tool or group name is skipped with aninvalid_nameevent (never thrown, also in development); registration errors are reported aserrorevents too.- Observation (
observe, defaulttrue): oneMutationObserverwatchesrootand every open shadow root found; only mutations touching forms, form controls, labels, tool elements or tool attributes outside ignored regions schedule a rescan; changes are batched per animation frame; a tool is re-registered only when its synthesized schema (load-timedefaults aside) or tool attributes changed; removed elements' tools and form adapters are disposed.
Without document (SSR) it does nothing.
Parameters
opts?
ScanDomOptions = {}
root (default document) and observe (default true).
Returns
A consumer for tm.use; its disposer disconnects the observer and disposes every adapter, tool and group scope it created.
(tm) => () => void