diff --git a/docs/content/docs/api-surface.mdx b/docs/content/docs/api-surface.mdx index 1b182e9c..c3c7fed8 100644 --- a/docs/content/docs/api-surface.mdx +++ b/docs/content/docs/api-surface.mdx @@ -81,6 +81,9 @@ WebAPI.URL WebAPI.Fetch WebAPI.UIEvents WebAPI.Observers WebAPI.Media WebAPI.WebAudio WebAPI.Storage WebAPI.Messaging WebAPI.Workers WebAPI.Crypto WebAPI.Performance WebAPI.ViewTransitions +WebAPI.DOMTree WebAPI.CSSOMCore +WebAPI.Touch WebAPI.DataTransfer WebAPI.FileEntries +WebAPI.FormData WebAPI.History WebAPI.Location WebAPI.SafeFetch ``` @@ -115,23 +118,73 @@ and depends only on the core `WebAPI.DOM` feature. `WebAPI.Window` includes both features, so existing Window consumers keep the same API and type identities. For React bindings that need element, event, window, document, history, and location -types without the complete Window API, select: +types without the DOM operation modules, select: ```json { "dependencies": [ { "name": "@rescript/webapi", - "features": ["WebAPI.DOMNodes", "WebAPI.History", "WebAPI.Location"] + "features": ["WebAPI.DOMTree", "WebAPI.History", "WebAPI.Location"] } ] } ``` -DOMNodes already includes DOM transitively. This selection does not expose -`WebAPI.Window` or `WebAPI.Document`; add `WebAPI.Window` if you need their methods. +DOMTree includes the lightweight DOM types and the shared CSSOMCore records. +It does not enable Element, Node, or HTMLCollection operation modules. The small +CSS declaration modules are kept intact, including their own operations. Select +DOMNodes for element/node operations and CSSOM for the complete CSS API, +and Window for Window or Document methods. Existing operation features include +their required type features automatically. An unrestricted WebAPI dependency elsewhere in the dependency graph enables all features. +## Narrow touch, clipboard and form-data features + +Select `WebAPI.Touch` for Touch/TouchList and `WebAPI.FormData` for FormData and +its unboxed string/file entry values. Each depends only on basic DOM and compiles +five source modules including that dependency. + +`WebAPI.DataTransfer` includes its item/list APIs, DOMTree for `setDragImage`, +and `WebAPI.FileEntries` for the existing `webkitGetAsEntry` operation. +FileEntries is the five-module legacy entry family, not the modern filesystem +handle or stream APIs. UIEvents, Fetch, and File continue to include all their +previous modules through these smaller features. + +For React bindings selecting DOMTree, History, and Location, adding Touch, +DataTransfer, and FormData selects **27 WebAPI source modules**, rather than +102 with broad UIEvents and Fetch. These are source counts, not speed claims. +Basic DOM is unchanged. FileList operations still require WebAPI.File; a +DataTransfer's `files` field exposes the core file-list type and its length. + +```json +{ + "dependencies": [ + { + "name": "@rescript/webapi", + "features": [ + "WebAPI.DOMTree", + "WebAPI.History", + "WebAPI.Location", + "WebAPI.Touch", + "WebAPI.DataTransfer", + "WebAPI.FormData" + ] + } + ] +} +``` + +Use `Touch.init` for constructor options and `Touch.Direct` / `Touch.Stylus` +for its touch-type variant. Existing broad event and fetch APIs accept these +same types without casts. FormDataEntryValue remains an **unboxed** union; +it is not interchangeable with a separately defined boxed React variant. + +The declared private empty FormData representation is unchanged. ReScript +13.0.0-alpha.7 still accepts an empty-record literal for this type, as it did +before this split; use the FormData constructor rather than constructing records. +The split does not claim to fix that existing compiler limitation. + ## Fetch Use `WebAPI.Fetch.fetch` for string URLs and `WebAPI.Fetch.fetchWithRequest` @@ -434,6 +487,17 @@ let redirect = WebAPI.Response.redirect(~url="/login", ~status=302) ## DOM +`WebAPI.DOM` stays lightweight: it supplies basic types such as window, document, +and event without pulling in the rich element or CSS declaration records. +`WebAPI.DOMTree` is the independently selectable rich DOM type surface, including +recursive element fields and HTML element styles. `WebAPI.CSSOMCore` supplies +the required CSS declaration modules without selecting Event or DOMTree. + +```ReScript +let parentNode = (element: WebAPI.DOMTree.element) => element.parentNode +let style = (element: WebAPI.DOMTree.htmlElement) => element.style +``` + DOM values are operated on through public interface modules. ```ReScript diff --git a/package.json b/package.json index 717b237c..3ac11e8b 100644 --- a/package.json +++ b/package.json @@ -44,8 +44,8 @@ "check:consumer": "node scripts/check-consumer.mjs", "check:release": "node --test scripts/validate-release-artifact.test.mjs scripts/check-release.test.mjs && node scripts/check-release.mjs", "check:docs-links": "node --test scripts/check-doc-links.test.mjs scripts/check-doc-type-links.test.mjs && node scripts/check-doc-links.mjs", - "format": "rescript format && oxfmt ./tests/index.js ./tests/fixtures.json ./tests/browser/*.mjs ./scripts/negative-fixtures.json ./scripts/validate-release-artifact.mjs ./scripts/validate-release-artifact.test.mjs ./playwright.config.mjs ./astro.config.mjs ./scripts/check-consumer.mjs ./scripts/check-release.mjs ./scripts/check-release.test.mjs ./scripts/check-features.mjs ./scripts/check-features.test.mjs ./scripts/check-doc-links.mjs ./scripts/check-doc-links.test.mjs ./scripts/check-doc-type-links.test.mjs ./package.json ./README.md ./CHANGELOG.md ./docs && prettier --write .github/workflows/*.yml ./docs/pages", - "format:check": "rescript format --check && oxfmt ./tests/index.js ./tests/fixtures.json ./tests/browser/*.mjs ./scripts/negative-fixtures.json ./scripts/validate-release-artifact.mjs ./scripts/validate-release-artifact.test.mjs ./playwright.config.mjs ./astro.config.mjs ./scripts/check-consumer.mjs ./scripts/check-release.mjs ./scripts/check-release.test.mjs ./scripts/check-features.mjs ./scripts/check-features.test.mjs ./scripts/check-doc-links.mjs ./scripts/check-doc-links.test.mjs ./scripts/check-doc-type-links.test.mjs ./package.json ./README.md ./CHANGELOG.md ./docs --check && prettier --check .github/workflows/*.yml ./docs/pages", + "format": "rescript format && oxfmt ./tests/index.js ./tests/fixtures.json ./tests/browser/*.mjs ./scripts/negative-fixtures.json ./scripts/validate-release-artifact.mjs ./scripts/validate-release-artifact.test.mjs ./playwright.config.mjs ./astro.config.mjs ./scripts/check-consumer.mjs ./scripts/check-release.mjs ./scripts/check-release.test.mjs ./scripts/check-features.mjs ./scripts/check-features.test.mjs ./scripts/data-feature-consumers.mjs ./scripts/check-doc-links.mjs ./scripts/check-doc-links.test.mjs ./scripts/check-doc-type-links.test.mjs ./package.json ./README.md ./CHANGELOG.md ./docs && prettier --write .github/workflows/*.yml ./docs/pages", + "format:check": "rescript format --check && oxfmt ./tests/index.js ./tests/fixtures.json ./tests/browser/*.mjs ./scripts/negative-fixtures.json ./scripts/validate-release-artifact.mjs ./scripts/validate-release-artifact.test.mjs ./playwright.config.mjs ./astro.config.mjs ./scripts/check-consumer.mjs ./scripts/check-release.mjs ./scripts/check-release.test.mjs ./scripts/check-features.mjs ./scripts/check-features.test.mjs ./scripts/data-feature-consumers.mjs ./scripts/check-doc-links.mjs ./scripts/check-doc-links.test.mjs ./scripts/check-doc-type-links.test.mjs ./package.json ./README.md ./CHANGELOG.md ./docs --check && prettier --check .github/workflows/*.yml ./docs/pages", "docs": "astro dev", "prebuild:docs": "node docs/llm.js", "build:docs": "astro build" diff --git a/rescript.json b/rescript.json index 83f718c2..a1042a90 100644 --- a/rescript.json +++ b/rescript.json @@ -10,8 +10,11 @@ "WebAPI.DOMPlatform": ["WebAPI.Event", "DOMPlatform"], "WebAPI.Animation": ["WebAPI.Event", "Animation"], "WebAPI.Geometry": ["WebAPI.DOM", "Geometry"], - "WebAPI.CSSOM": ["WebAPI.Event", "CSSOM"], + "WebAPI.CSSOMCore": ["CSSOMCore"], + "WebAPI.CSSOM": ["WebAPI.Event", "WebAPI.CSSOMCore", "CSSOM"], + "WebAPI.DOMTree": ["WebAPI.DOM", "WebAPI.CSSOMCore", "DOMTree"], "WebAPI.DOMNodes": [ + "WebAPI.DOMTree", "WebAPI.DOMPlatform", "WebAPI.Animation", "WebAPI.CSSOM", @@ -41,7 +44,9 @@ "WebAPI.Geometry", "Observers" ], - "WebAPI.UIEvents": ["WebAPI.DOMNodes", "WebAPI.File", "UIEvents"], + "WebAPI.Touch": ["WebAPI.DOM", "Touch"], + "WebAPI.DataTransfer": ["WebAPI.DOMTree", "WebAPI.FileEntries", "DataTransfer"], + "WebAPI.UIEvents": ["WebAPI.DOMNodes", "WebAPI.File", "WebAPI.Touch", "WebAPI.DataTransfer", "UIEvents"], "WebAPI.Canvas": [ "WebAPI.Geometry", "WebAPI.HTML", @@ -59,9 +64,11 @@ "WebAPI.Workers", "Navigator" ], - "WebAPI.File": ["WebAPI.Event", "File"], + "WebAPI.FileEntries": ["WebAPI.DOM", "FileEntries"], + "WebAPI.File": ["WebAPI.Event", "WebAPI.FileEntries", "File"], "WebAPI.URL": ["WebAPI.DOM", "URL"], - "WebAPI.Fetch": ["WebAPI.Event", "WebAPI.File", "WebAPI.URL", "Fetch"], + "WebAPI.FormData": ["WebAPI.DOM", "FormData"], + "WebAPI.Fetch": ["WebAPI.Event", "WebAPI.File", "WebAPI.URL", "WebAPI.FormData", "Fetch"], "WebAPI.SafeFetch": ["WebAPI.Fetch", "SafeFetch"], "WebAPI.CSSFontLoading": ["WebAPI.Event", "CSSFontLoading"], "WebAPI.Device": ["WebAPI.Event", "Device"], @@ -90,6 +97,18 @@ "DOMTokenList" ] }, + { + "dir": "src/cssom-core", + "subdirs": true, + "feature": "CSSOMCore", + "public": ["CSSStyleDeclaration", "CSSStyleValue", "MediaList", "StylePropertyMap", "StylePropertyMapReadOnly", "StyleSheet", "StyleSheetList"] + }, + { + "dir": "src/dom-tree", + "subdirs": true, + "feature": "DOMTree", + "public": ["DOMTree"] + }, { "dir": "src/dom-nodes", "subdirs": true, @@ -102,7 +121,6 @@ "CharacterData", "Comment", "DOMImplementation", - "DOMTree", "DocumentFragment", "Element", "ElementInternals", @@ -138,14 +156,7 @@ "feature": "CSSOM", "public": [ "CSSRuleList", - "CSSStyleDeclaration", - "CSSStyleValue", - "MediaList", - "MediaQueryList", - "StylePropertyMap", - "StylePropertyMapReadOnly", - "StyleSheet", - "StyleSheetList" + "MediaQueryList" ] }, { @@ -343,8 +354,6 @@ "public": [ "BodyInit", "Fetch", - "FormData", - "FormDataEntryValue", "Headers", "HeadersInit", "Request", @@ -365,10 +374,7 @@ "Blob", "File", "FileList", - "FileSystemDirectoryEntry", "FileSystemDirectoryHandle", - "FileSystemDirectoryReader", - "FileSystemEntry", "FileSystemFileHandle", "FileSystemHandle", "FileSystemWritableFileStream", @@ -481,23 +487,42 @@ "WorkerLocation" ] }, + { + "dir": "src/touch", + "subdirs": true, + "feature": "Touch", + "public": ["Touch", "TouchList"] + }, + { + "dir": "src/form-data", + "subdirs": true, + "feature": "FormData", + "public": ["FormData", "FormDataEntryValue"] + }, + { + "dir": "src/file-entries", + "subdirs": true, + "feature": "FileEntries", + "public": ["FileSystemEntry", "FileSystemDirectoryEntry", "FileSystemDirectoryReader"] + }, + { + "dir": "src/data-transfer", + "subdirs": true, + "feature": "DataTransfer", + "public": ["DataTransfer", "DataTransferItem", "DataTransferItemList"] + }, { "dir": "src/ui-events", "subdirs": true, "feature": "UIEvents", "public": [ "CompositionEvent", - "DataTransfer", - "DataTransferItem", - "DataTransferItemList", "FocusEvent", "InputEvent", "KeyboardEvent", "MouseEvent", "PointerEvent", - "Touch", "TouchEvent", - "TouchList", "UIEvent", "WheelEvent" ] diff --git a/scripts/check-consumer.mjs b/scripts/check-consumer.mjs index af4af15a..9c3246e06 100644 --- a/scripts/check-consumer.mjs +++ b/scripts/check-consumer.mjs @@ -4,6 +4,7 @@ import os from "node:os"; import path from "node:path"; import { fileURLToPath, pathToFileURL } from "node:url"; import { validateReleaseArtifact } from "./validate-release-artifact.mjs"; +import { dataFeatureConsumers } from "./data-feature-consumers.mjs"; const repoRoot = path.resolve(path.dirname(fileURLToPath(import.meta.url)), ".."); const packageJson = JSON.parse(readFileSync(path.join(repoRoot, "package.json"), "utf8")); @@ -193,6 +194,14 @@ const checkConsumers = async () => { if (!negativeOnly) { const scenarios = [ + ...dataFeatureConsumers.map((consumer) => ({ + ...consumer, + fixture: `scripts/${consumer.fixture}`, + expectedFailure: + consumer.missingModule === undefined + ? null + : `The module or file WebAPI.${consumer.missingModule} can\'t be found.`, + })), { name: "default", fixture: "scripts/consumer-default.res", features: null }, { name: "concrete public types", @@ -240,6 +249,18 @@ const checkConsumers = async () => { projectDirectory, ); console.log(`[ok] packed consumer runtime using ReScript ${compilerVersion}`); + writeProject(projectDirectory, "scripts/consumer-data-form-runtime.res", ["WebAPI.FormData"]); + compile(projectDirectory); + runCommand( + process.execPath, + [ + "--input-type=module", + "--eval", + `await import(${JSON.stringify(pathToFileURL(path.join(projectDirectory, "src/Consumer.js")).href)} + "?formdata")`, + ], + projectDirectory, + ); + console.log("[ok] packed narrow FormData runtime"); } const negativeCases = JSON.parse( diff --git a/scripts/check-features.mjs b/scripts/check-features.mjs index 4b2940d0..45590c8d 100644 --- a/scripts/check-features.mjs +++ b/scripts/check-features.mjs @@ -4,6 +4,7 @@ import { mkdtempSync, mkdirSync, readFileSync, + readdirSync, rmSync, statSync, symlinkSync, @@ -14,6 +15,8 @@ import path from "node:path"; import { spawnSync } from "node:child_process"; import { fileURLToPath } from "node:url"; +import { dataFeatureConsumers } from "./data-feature-consumers.mjs"; + const scriptPath = fileURLToPath(import.meta.url); const repoRoot = path.resolve(path.dirname(scriptPath), ".."); const configPath = path.join(repoRoot, "rescript.json"); @@ -22,12 +25,14 @@ const expectedFeatureOwners = new Map([ ["WebAPI.DOM", "DOM"], ["WebAPI.Event", "Event"], ["WebAPI.DOMPlatform", "DOMPlatform"], + ["WebAPI.DOMTree", "DOMTree"], ["WebAPI.DOMNodes", "DOMNodes"], ["WebAPI.File", "File"], ["WebAPI.HTML", "HTML"], ["WebAPI.History", "History"], ["WebAPI.Location", "Location"], ["WebAPI.Window", "Window"], + ["WebAPI.CSSOMCore", "CSSOMCore"], ["WebAPI.CSSOM", "CSSOM"], ["WebAPI.CSSFontLoading", "CSSFontLoading"], ["WebAPI.Geometry", "Geometry"], @@ -40,6 +45,10 @@ const expectedFeatureOwners = new Map([ ["WebAPI.Fetch", "Fetch"], ["WebAPI.SafeFetch", "SafeFetch"], ["WebAPI.UIEvents", "UIEvents"], + ["WebAPI.Touch", "Touch"], + ["WebAPI.FormData", "FormData"], + ["WebAPI.DataTransfer", "DataTransfer"], + ["WebAPI.FileEntries", "FileEntries"], ["WebAPI.Observers", "Observers"], ["WebAPI.Media", "Media"], ["WebAPI.WebAudio", "WebAudio"], @@ -294,10 +303,22 @@ const prepareConsumer = (directory, features, fixture) => { ); }; -export const isMissingSafeFetchDiagnostic = (output) => - /The module or file (?:WebAPI\.)?SafeFetch can't be found\./.test(output.replace(/\s+/g, " ")); +export const isMissingModuleDiagnostic = (output, moduleName) => + new RegExp(`The module or file (?:WebAPI\\.)?${escapeRegExp(moduleName)} can't be found\\.`).test( + output.replace(/\s+/g, " "), + ); -const runConsumerCheck = ({ name, features, fixture, shouldCompile }) => { +export const isMissingSafeFetchDiagnostic = (output) => + isMissingModuleDiagnostic(output, "SafeFetch"); + +const runConsumerCheck = ({ + name, + features, + fixture, + shouldCompile, + missingModule, + expectedSources, +}) => { const directory = mkdtempSync(path.join(os.tmpdir(), "webapi-feature-consumer-")); try { prepareConsumer(directory, features, fixture); @@ -306,14 +327,27 @@ const runConsumerCheck = ({ name, features, fixture, shouldCompile }) => { encoding: "utf8", }); const output = `${result.stdout ?? ""}\n${result.stderr ?? ""}`; + if (result.status === 0 && expectedSources !== undefined) { + const sourceArtifacts = path.join(directory, "node_modules/@rescript/webapi/lib/bs/src"); + const count = readdirSync(sourceArtifacts, { recursive: true }).filter((file) => + file.endsWith(".cmj"), + ).length; + if (count !== expectedSources) + return { + _tag: "Failure", + message: `${name}: expected ${expectedSources} sources, got ${count}`, + }; + } const passed = shouldCompile ? result.status === 0 - : result.status !== null && result.status !== 0 && isMissingSafeFetchDiagnostic(output); + : result.status !== null && + result.status !== 0 && + isMissingModuleDiagnostic(output, missingModule ?? "SafeFetch"); return passed ? { _tag: "Success" } : { _tag: "Failure", - message: `${name} did not ${shouldCompile ? "compile" : "reject the unavailable SafeFetch module"}.\n${result.error?.message ?? ""}\n${output.trim()}`, + message: `${name} did not ${shouldCompile ? "compile" : `reject the unavailable ${missingModule ?? "SafeFetch"} module`}.\n${result.error?.message ?? ""}\n${output.trim()}`, }; } finally { rmSync(directory, { recursive: true, force: true }); @@ -362,6 +396,10 @@ if (process.argv[1] !== undefined && path.resolve(process.argv[1]) === scriptPat } for (const consumer of [ + ...dataFeatureConsumers.map((consumer) => ({ + ...consumer, + shouldCompile: consumer.missingModule === undefined, + })), { name: "SafeFetch consumer", features: ["WebAPI.SafeFetch"], @@ -380,6 +418,44 @@ if (process.argv[1] !== undefined && path.resolve(process.argv[1]) === scriptPat fixture: "consumer-safe-fetch-disabled.res", shouldCompile: false, }, + { + name: "Basic DOM type consumer", + features: ["WebAPI.DOM"], + fixture: "consumer-dom-core.res", + shouldCompile: true, + }, + { + name: "DOMTree feature does not expose Element operations", + features: ["WebAPI.DOMTree"], + fixture: "consumer-dom-element-disabled.res", + shouldCompile: false, + missingModule: "Element", + }, + { + name: "DOM-tree type consumer", + features: ["WebAPI.DOMTree"], + fixture: "consumer-dom-tree.res", + shouldCompile: true, + }, + { + name: "CSS declaration consumer", + features: ["WebAPI.CSSOMCore"], + fixture: "consumer-cssom-core.res", + shouldCompile: true, + }, + { + name: "CSSOM does not enable DOMTree", + features: ["WebAPI.CSSOM"], + fixture: "consumer-dom-tree-disabled.res", + shouldCompile: false, + missingModule: "DOMTree", + }, + { + name: "DOM moved type re-exports", + features: ["WebAPI.DOMNodes", "WebAPI.HTML", "WebAPI.Window", "WebAPI.CSSOM"], + fixture: "consumer-dom-reexports.res", + shouldCompile: true, + }, ]) { const result = runConsumerCheck(consumer); if (result._tag === "Failure") { diff --git a/scripts/check-features.test.mjs b/scripts/check-features.test.mjs index 70353ed6..14086852 100644 --- a/scripts/check-features.test.mjs +++ b/scripts/check-features.test.mjs @@ -64,3 +64,20 @@ test("does not accept an unrelated compiler failure mentioning SafeFetch", () => ); assert.equal(isMissingSafeFetchDiagnostic("SafeFetch consumer has a type error."), false); }); + +test("narrow data features preserve broad feature umbrellas", () => { + assert.deepEqual(validateConfig(config), []); + assert.deepEqual(config.features["WebAPI.Touch"], ["WebAPI.DOM", "Touch"]); + assert.deepEqual(config.features["WebAPI.FormData"], ["WebAPI.DOM", "FormData"]); + assert.deepEqual(config.features["WebAPI.FileEntries"], ["WebAPI.DOM", "FileEntries"]); + assert.deepEqual(config.features["WebAPI.DataTransfer"], [ + "WebAPI.DOMTree", + "WebAPI.FileEntries", + "DataTransfer", + ]); + assert.ok(config.features["WebAPI.UIEvents"].includes("WebAPI.Touch")); + assert.ok(config.features["WebAPI.UIEvents"].includes("WebAPI.DataTransfer")); + assert.ok(config.features["WebAPI.UIEvents"].includes("WebAPI.File")); + assert.ok(config.features["WebAPI.File"].includes("WebAPI.FileEntries")); + assert.ok(config.features["WebAPI.Fetch"].includes("WebAPI.FormData")); +}); diff --git a/scripts/consumer-cssom-core.res b/scripts/consumer-cssom-core.res new file mode 100644 index 00000000..0470fcdb --- /dev/null +++ b/scripts/consumer-cssom-core.res @@ -0,0 +1,2 @@ +let cssText = (style: WebAPI.CSSStyleDeclaration.t) => style.cssText +let rule = (style: WebAPI.CSSStyleDeclaration.t) => style.parentRule diff --git a/scripts/consumer-data-combined.res b/scripts/consumer-data-combined.res new file mode 100644 index 00000000..a88f7f47 --- /dev/null +++ b/scripts/consumer-data-combined.res @@ -0,0 +1,6 @@ +let data = (): WebAPI.DataTransfer.t => WebAPI.DataTransfer.make() +let touch = (list: WebAPI.TouchList.t) => list->WebAPI.TouchList.item(0) +let form = (): WebAPI.FormData.t => WebAPI.FormData.make() +let location = (location: WebAPI.Location.t) => location.pathname +let history = (history: WebAPI.History.t) => history.state +let element = (element: WebAPI.DOMTree.element) => element diff --git a/scripts/consumer-data-disabled-fetch.res b/scripts/consumer-data-disabled-fetch.res new file mode 100644 index 00000000..9413ddaa --- /dev/null +++ b/scripts/consumer-data-disabled-fetch.res @@ -0,0 +1 @@ +let fetch = WebAPI.Fetch.fetch diff --git a/scripts/consumer-data-disabled-filelist.res b/scripts/consumer-data-disabled-filelist.res new file mode 100644 index 00000000..3fbcf5d9 --- /dev/null +++ b/scripts/consumer-data-disabled-filelist.res @@ -0,0 +1 @@ +let item = WebAPI.FileList.item diff --git a/scripts/consumer-data-disabled-inputevent.res b/scripts/consumer-data-disabled-inputevent.res new file mode 100644 index 00000000..f8f57665 --- /dev/null +++ b/scripts/consumer-data-disabled-inputevent.res @@ -0,0 +1 @@ +let make = WebAPI.InputEvent.make diff --git a/scripts/consumer-data-disabled-readablestream.res b/scripts/consumer-data-disabled-readablestream.res new file mode 100644 index 00000000..33d6afa1 --- /dev/null +++ b/scripts/consumer-data-disabled-readablestream.res @@ -0,0 +1 @@ +let make = WebAPI.ReadableStream.make diff --git a/scripts/consumer-data-disabled-touchevent.res b/scripts/consumer-data-disabled-touchevent.res new file mode 100644 index 00000000..4587677f --- /dev/null +++ b/scripts/consumer-data-disabled-touchevent.res @@ -0,0 +1 @@ +let make = WebAPI.TouchEvent.make diff --git a/scripts/consumer-data-disabled-window.res b/scripts/consumer-data-disabled-window.res new file mode 100644 index 00000000..5c02199f --- /dev/null +++ b/scripts/consumer-data-disabled-window.res @@ -0,0 +1 @@ +let location = WebAPI.Window.location diff --git a/scripts/consumer-data-entries.res b/scripts/consumer-data-entries.res new file mode 100644 index 00000000..58caafe3 --- /dev/null +++ b/scripts/consumer-data-entries.res @@ -0,0 +1,5 @@ +let getParent = (entry: WebAPI.FileSystemEntry.t) => + entry->WebAPI.FileSystemEntry.getParent(~successCallback=parent => ignore(parent.name)) +let read = (directory: WebAPI.FileSystemDirectoryEntry.t) => + directory->WebAPI.FileSystemDirectoryEntry.createReader + ->WebAPI.FileSystemDirectoryReader.readEntries(~successCallback=ignore) diff --git a/scripts/consumer-data-form-runtime.res b/scripts/consumer-data-form-runtime.res new file mode 100644 index 00000000..44ab9bce --- /dev/null +++ b/scripts/consumer-data-form-runtime.res @@ -0,0 +1,22 @@ +open WebAPI +@new external blob: array => DOM.blob = "Blob" +let form = FormData.make() +form->FormData.append(~name="text", ~value="hello") +form->FormData.appendBlob(~name="file", ~blobValue=blob(["contents"]), ~filename="sample.txt") +assert(form->FormData.get("missing")->Null.toOption == None) + +assert(switch form->FormData.get("text")->Null.toOption { +| Some(String("hello")) => true +| _ => false +}) + +assert(switch form->FormData.get("file")->Null.toOption { +| Some(File(file)) => file.name == "sample.txt" && file.size == 8 +| _ => false +}) + +let values = form->FormData.getAll("text") +assert(values->Array.length == 1) +let entry: FormDataEntryValue.t = String("unboxed") +let isUnboxed = (_value: FormDataEntryValue.t): bool => %raw(`_value === "unboxed"`) +assert(isUnboxed(entry)) diff --git a/scripts/consumer-data-form.res b/scripts/consumer-data-form.res new file mode 100644 index 00000000..f4f6e95b --- /dev/null +++ b/scripts/consumer-data-form.res @@ -0,0 +1,12 @@ +let make = (): WebAPI.FormData.t => WebAPI.FormData.make() +let appendBlob = (form: WebAPI.FormData.t, blob: WebAPI.DOM.blob) => + form->WebAPI.FormData.appendBlob(~name="file", ~blobValue=blob, ~filename="file.txt") +let entry = (value: WebAPI.FormDataEntryValue.t) => + switch value { + | String(text) => text + | File(file) => file.name + } +let get = (form: WebAPI.FormData.t): Null.t => + form->WebAPI.FormData.get("name") +let entries = (form: WebAPI.FormData.t): iterable<(string, WebAPI.FormDataEntryValue.t)> => + form->WebAPI.FormData.entries diff --git a/scripts/consumer-data-touch.res b/scripts/consumer-data-touch.res new file mode 100644 index 00000000..4872dc70 --- /dev/null +++ b/scripts/consumer-data-touch.res @@ -0,0 +1,5 @@ +let make = (target: WebAPI.DOM.eventTarget): WebAPI.Touch.t => + WebAPI.Touch.make({identifier: 1, target, touchType: WebAPI.Touch.Direct}) +let item = (list: WebAPI.TouchList.t): Null.t => + list->WebAPI.TouchList.item(0) +let target = (touch: WebAPI.Touch.t): WebAPI.DOM.eventTarget => touch.target diff --git a/scripts/consumer-data-transfer.res b/scripts/consumer-data-transfer.res new file mode 100644 index 00000000..e41c9ff3 --- /dev/null +++ b/scripts/consumer-data-transfer.res @@ -0,0 +1,13 @@ +let make = (): WebAPI.DataTransfer.t => WebAPI.DataTransfer.make() +let addFile = (data: WebAPI.DataTransfer.t, file: WebAPI.DOM.file) => + data.items->WebAPI.DataTransferItemList.addFile(file) +let getFile = (item: WebAPI.DataTransferItem.t): Null.t => + item->WebAPI.DataTransferItem.getAsFile +let legacyEntry = (item: WebAPI.DataTransferItem.t): Null.t => + item->WebAPI.DataTransferItem.webkitGetAsEntry +let dragImage = (data: WebAPI.DataTransfer.t, element: WebAPI.DOMTree.element) => + data->WebAPI.DataTransfer.setDragImage(~image=element, ~x=0, ~y=0) +let mutate = (data: WebAPI.DataTransfer.t) => { + data.dropEffect = "copy" + data.effectAllowed = "copyMove" +} diff --git a/scripts/consumer-dom-core.res b/scripts/consumer-dom-core.res new file mode 100644 index 00000000..5624962e --- /dev/null +++ b/scripts/consumer-dom-core.res @@ -0,0 +1,6 @@ +let eventType = (event: WebAPI.DOM.event) => event.type_ +let windowIdentity: WebAPI.DOM.window => WebAPI.DOM.window = value => value +let inferredManual = WebAPI.DOM.Manual +let legacyManual: WebAPI.DOM.slotAssignmentMode = inferredManual +let inferredNamed = WebAPI.DOM.Named +let legacyNamed: WebAPI.DOM.slotAssignmentMode = inferredNamed diff --git a/scripts/consumer-dom-element-disabled.res b/scripts/consumer-dom-element-disabled.res new file mode 100644 index 00000000..8ec214b7 --- /dev/null +++ b/scripts/consumer-dom-element-disabled.res @@ -0,0 +1 @@ +let invalid = WebAPI.Element.asNode diff --git a/scripts/consumer-dom-reexports.res b/scripts/consumer-dom-reexports.res new file mode 100644 index 00000000..6921a261 --- /dev/null +++ b/scripts/consumer-dom-reexports.res @@ -0,0 +1,66 @@ +let domElement: WebAPI.DOMTree.element => WebAPI.Element.t = value => value +let elementDom: WebAPI.Element.t => WebAPI.DOMTree.element = value => value + +let collection: WebAPI.DOMTree.htmlCollection<'item> => WebAPI.HTMLCollection.t<'item> = value => + value + +let collectionBack: WebAPI.HTMLCollection.t<'item> => WebAPI.DOMTree.htmlCollection< + 'item, +> = value => value + +let mode: WebAPI.DOMTree.slotAssignmentMode = WebAPI.DOMTree.Manual + +let toPublic0: WebAPI.DOMTree.node => WebAPI.Node.t = value => value +let toCore0: WebAPI.Node.t => WebAPI.DOMTree.node = value => value + +let toPublic1: WebAPI.DOMTree.documentFragment => WebAPI.DocumentFragment.t = value => value +let toCore1: WebAPI.DocumentFragment.t => WebAPI.DOMTree.documentFragment = value => value + +let toPublic2: WebAPI.DOMTree.shadowRoot => WebAPI.ShadowRoot.t = value => value +let toCore2: WebAPI.ShadowRoot.t => WebAPI.DOMTree.shadowRoot = value => value + +let toPublic3: WebAPI.DOMTree.htmlElement => WebAPI.HTMLElement.t = value => value +let toCore3: WebAPI.HTMLElement.t => WebAPI.DOMTree.htmlElement = value => value + +let toPublic4: WebAPI.DOMTree.htmlFormElement => WebAPI.HTMLFormElement.t = value => value +let toCore4: WebAPI.HTMLFormElement.t => WebAPI.DOMTree.htmlFormElement = value => value + +let toPublic5: WebAPI.DOMTree.htmlFormControlsCollection => WebAPI.HTMLFormControlsCollection.t = value => + value + +let toCore5: WebAPI.HTMLFormControlsCollection.t => WebAPI.DOMTree.htmlFormControlsCollection = value => + value + +let toPublic6: WebAPI.DOMTree.htmlSlotElement => WebAPI.HTMLSlotElement.t = value => value +let toCore6: WebAPI.HTMLSlotElement.t => WebAPI.DOMTree.htmlSlotElement = value => value + +let toPublic7: WebAPI.DOMTree.elementInternals => WebAPI.ElementInternals.t = value => value +let toCore7: WebAPI.ElementInternals.t => WebAPI.DOMTree.elementInternals = value => value + +let toPublic11: WebAPI.StyleSheet.cssRuleList => WebAPI.CSSRuleList.t = value => value +let toCore11: WebAPI.CSSRuleList.t => WebAPI.StyleSheet.cssRuleList = value => value + +let treeMode = WebAPI.DOMTree.Manual +let preservedTreeMode: WebAPI.DOMTree.slotAssignmentMode = treeMode + +let adoptedSheets = (root: WebAPI.DOMTree.shadowRoot): array => + root.adoptedStyleSheets + +let styleParent = (style: WebAPI.CSSStyleDeclaration.t): Null.t => + style.parentRule + +let dataset = (element: WebAPI.HTMLElement.t) => element.dataset +let mutateStyle = (style: WebAPI.CSSStyleDeclaration.t, color: string) => style.color = color + +// The rich fields retain the original CSS operation-module types. +let htmlStyle = (element: WebAPI.DOMTree.htmlElement): WebAPI.CSSStyleDeclaration.t => element.style + +let slotStyle = (element: WebAPI.DOMTree.htmlSlotElement): WebAPI.CSSStyleDeclaration.t => + element.style + +let attributeStyle = (element: WebAPI.DOMTree.htmlElement): WebAPI.StylePropertyMap.t => + element.attributeStyleMap + +let sheets = (root: WebAPI.DOMTree.shadowRoot): WebAPI.StyleSheetList.t => root.styleSheets +let media = (sheet: WebAPI.StyleSheet.t): WebAPI.MediaList.t => sheet.media +let rules = (sheet: WebAPI.StyleSheet.cssStyleSheet): WebAPI.CSSRuleList.t => sheet.cssRules diff --git a/scripts/consumer-dom-tree-disabled.res b/scripts/consumer-dom-tree-disabled.res new file mode 100644 index 00000000..a51aa470 --- /dev/null +++ b/scripts/consumer-dom-tree-disabled.res @@ -0,0 +1 @@ +module Unavailable = WebAPI.DOMTree diff --git a/scripts/consumer-dom-tree.res b/scripts/consumer-dom-tree.res new file mode 100644 index 00000000..2f5023b7 --- /dev/null +++ b/scripts/consumer-dom-tree.res @@ -0,0 +1,6 @@ +let elementIdentity: WebAPI.DOMTree.element => WebAPI.DOMTree.element = value => value +let parentNode = (element: WebAPI.DOMTree.element) => element.parentNode +let childNodes = (element: WebAPI.DOMTree.element) => element.childNodes +let style = (element: WebAPI.DOMTree.htmlElement) => element.style +let inferredManual = WebAPI.DOMTree.Manual +let mode: WebAPI.DOMTree.slotAssignmentMode = inferredManual diff --git a/scripts/data-feature-consumers.mjs b/scripts/data-feature-consumers.mjs new file mode 100644 index 00000000..38a177bf --- /dev/null +++ b/scripts/data-feature-consumers.mjs @@ -0,0 +1,117 @@ +export const dataFeatureConsumers = [ + { + name: "Touch", + features: ["WebAPI.Touch"], + fixture: "consumer-data-touch.res", + expectedSources: 5, + }, + { + name: "FormData", + features: ["WebAPI.FormData"], + fixture: "consumer-data-form.res", + expectedSources: 5, + }, + { + name: "FileEntries", + features: ["WebAPI.FileEntries"], + fixture: "consumer-data-entries.res", + expectedSources: 8, + }, + { + name: "DataTransfer", + features: ["WebAPI.DataTransfer"], + fixture: "consumer-data-transfer.res", + expectedSources: 20, + }, + { + name: "combined React data selection", + features: [ + "WebAPI.DOMTree", + "WebAPI.History", + "WebAPI.Location", + "WebAPI.Touch", + "WebAPI.DataTransfer", + "WebAPI.FormData", + ], + fixture: "consumer-data-combined.res", + expectedSources: 27, + }, + { + name: "narrow excludes Fetch", + features: [ + "WebAPI.DOMTree", + "WebAPI.History", + "WebAPI.Location", + "WebAPI.Touch", + "WebAPI.DataTransfer", + "WebAPI.FormData", + ], + fixture: "consumer-data-disabled-fetch.res", + missingModule: "Fetch", + }, + { + name: "narrow excludes TouchEvent", + features: [ + "WebAPI.DOMTree", + "WebAPI.History", + "WebAPI.Location", + "WebAPI.Touch", + "WebAPI.DataTransfer", + "WebAPI.FormData", + ], + fixture: "consumer-data-disabled-touchevent.res", + missingModule: "TouchEvent", + }, + { + name: "narrow excludes InputEvent", + features: [ + "WebAPI.DOMTree", + "WebAPI.History", + "WebAPI.Location", + "WebAPI.Touch", + "WebAPI.DataTransfer", + "WebAPI.FormData", + ], + fixture: "consumer-data-disabled-inputevent.res", + missingModule: "InputEvent", + }, + { + name: "narrow excludes ReadableStream", + features: [ + "WebAPI.DOMTree", + "WebAPI.History", + "WebAPI.Location", + "WebAPI.Touch", + "WebAPI.DataTransfer", + "WebAPI.FormData", + ], + fixture: "consumer-data-disabled-readablestream.res", + missingModule: "ReadableStream", + }, + { + name: "narrow excludes Window", + features: [ + "WebAPI.DOMTree", + "WebAPI.History", + "WebAPI.Location", + "WebAPI.Touch", + "WebAPI.DataTransfer", + "WebAPI.FormData", + ], + fixture: "consumer-data-disabled-window.res", + missingModule: "Window", + }, + { + name: "narrow excludes FileList", + features: [ + "WebAPI.DOMTree", + "WebAPI.History", + "WebAPI.Location", + "WebAPI.Touch", + "WebAPI.DataTransfer", + "WebAPI.FormData", + ], + fixture: "consumer-data-disabled-filelist.res", + missingModule: "FileList", + }, +]; diff --git a/scripts/fixtures/negative/DOMCollectionCannotBeConstructed.res b/scripts/fixtures/negative/DOMCollectionCannotBeConstructed.res new file mode 100644 index 00000000..489728b3 --- /dev/null +++ b/scripts/fixtures/negative/DOMCollectionCannotBeConstructed.res @@ -0,0 +1 @@ +let invalid: WebAPI.DOMTree.htmlCollection = {length: 0} diff --git a/scripts/fixtures/negative/DOMSlotModeIsDistinct.res b/scripts/fixtures/negative/DOMSlotModeIsDistinct.res new file mode 100644 index 00000000..090cc07a --- /dev/null +++ b/scripts/fixtures/negative/DOMSlotModeIsDistinct.res @@ -0,0 +1 @@ +let invalid: WebAPI.DOM.slotAssignmentMode = WebAPI.DOMTree.Manual diff --git a/scripts/fixtures/negative/DOMStyleMapCannotBeConstructed.res b/scripts/fixtures/negative/DOMStyleMapCannotBeConstructed.res new file mode 100644 index 00000000..e57af803 --- /dev/null +++ b/scripts/fixtures/negative/DOMStyleMapCannotBeConstructed.res @@ -0,0 +1 @@ +let invalid: WebAPI.StylePropertyMap.t = {size: 0} diff --git a/scripts/fixtures/negative/FormDataRejectsString.res b/scripts/fixtures/negative/FormDataRejectsString.res new file mode 100644 index 00000000..a447b359 --- /dev/null +++ b/scripts/fixtures/negative/FormDataRejectsString.res @@ -0,0 +1 @@ +let fake: WebAPI.FormData.t = "not form data" diff --git a/scripts/fixtures/negative/TouchItemNullable.res b/scripts/fixtures/negative/TouchItemNullable.res new file mode 100644 index 00000000..b09bdf49 --- /dev/null +++ b/scripts/fixtures/negative/TouchItemNullable.res @@ -0,0 +1 @@ +let item = (list: WebAPI.TouchList.t): WebAPI.Touch.t => list->WebAPI.TouchList.item(0) diff --git a/scripts/fixtures/negative/TouchListPrivate.res b/scripts/fixtures/negative/TouchListPrivate.res new file mode 100644 index 00000000..ee3f7e29 --- /dev/null +++ b/scripts/fixtures/negative/TouchListPrivate.res @@ -0,0 +1 @@ +let fake: WebAPI.TouchList.t = {length: 0} diff --git a/scripts/fixtures/negative/TransferItemPrivate.res b/scripts/fixtures/negative/TransferItemPrivate.res new file mode 100644 index 00000000..6267f700 --- /dev/null +++ b/scripts/fixtures/negative/TransferItemPrivate.res @@ -0,0 +1 @@ +let fake: WebAPI.DataTransferItem.t = {kind: "file", type_: "text/plain"} diff --git a/scripts/negative-fixtures.json b/scripts/negative-fixtures.json index 89cb9005..9d0f418f 100644 --- a/scripts/negative-fixtures.json +++ b/scripts/negative-fixtures.json @@ -148,5 +148,47 @@ "fixture": "scripts/fixtures/negative/WebCryptoExportKeyFormatHasUnknownResult.res", "features": ["WebAPI.Crypto"], "expectedDiagnostic": "This has type:" + }, + { + "name": "DOM and DOMTree slot assignment modes stay distinct", + "fixture": "scripts/fixtures/negative/DOMSlotModeIsDistinct.res", + "features": ["WebAPI.DOMNodes"], + "expectedDiagnostic": "belongs to the variant type WebAPI.DOMTree.slotAssignmentMode" + }, + { + "name": "private DOM collection cannot be constructed", + "fixture": "scripts/fixtures/negative/DOMCollectionCannotBeConstructed.res", + "features": ["WebAPI.DOMTree"], + "expectedDiagnostic": "Cannot create values of the" + }, + { + "name": "private DOM style map cannot be constructed", + "fixture": "scripts/fixtures/negative/DOMStyleMapCannotBeConstructed.res", + "features": ["WebAPI.CSSOMCore"], + "expectedDiagnostic": "Cannot create values of the" + }, + { + "name": "TouchListPrivate", + "fixture": "scripts/fixtures/negative/TouchListPrivate.res", + "features": ["WebAPI.Touch"], + "expectedDiagnostic": "Cannot create values of the" + }, + { + "name": "TransferItemPrivate", + "fixture": "scripts/fixtures/negative/TransferItemPrivate.res", + "features": ["WebAPI.DataTransfer"], + "expectedDiagnostic": "Cannot create values of the" + }, + { + "name": "FormDataRejectsString", + "fixture": "scripts/fixtures/negative/FormDataRejectsString.res", + "features": ["WebAPI.FormData"], + "expectedDiagnostic": "This has type:" + }, + { + "name": "TouchItemNullable", + "fixture": "scripts/fixtures/negative/TouchItemNullable.res", + "features": ["WebAPI.Touch"], + "expectedDiagnostic": "This has type:" } ] diff --git a/src/cssom/CSSStyleDeclaration.res b/src/cssom-core/CSSStyleDeclaration.res similarity index 100% rename from src/cssom/CSSStyleDeclaration.res rename to src/cssom-core/CSSStyleDeclaration.res diff --git a/src/cssom/CSSStyleValue.res b/src/cssom-core/CSSStyleValue.res similarity index 100% rename from src/cssom/CSSStyleValue.res rename to src/cssom-core/CSSStyleValue.res diff --git a/src/cssom/MediaList.res b/src/cssom-core/MediaList.res similarity index 100% rename from src/cssom/MediaList.res rename to src/cssom-core/MediaList.res diff --git a/src/cssom/StylePropertyMap.res b/src/cssom-core/StylePropertyMap.res similarity index 100% rename from src/cssom/StylePropertyMap.res rename to src/cssom-core/StylePropertyMap.res diff --git a/src/cssom/StylePropertyMapReadOnly.res b/src/cssom-core/StylePropertyMapReadOnly.res similarity index 100% rename from src/cssom/StylePropertyMapReadOnly.res rename to src/cssom-core/StylePropertyMapReadOnly.res diff --git a/src/cssom/StyleSheet.res b/src/cssom-core/StyleSheet.res similarity index 100% rename from src/cssom/StyleSheet.res rename to src/cssom-core/StyleSheet.res diff --git a/src/cssom/StyleSheetList.res b/src/cssom-core/StyleSheetList.res similarity index 100% rename from src/cssom/StyleSheetList.res rename to src/cssom-core/StyleSheetList.res diff --git a/src/data-transfer/DataTransfer.res b/src/data-transfer/DataTransfer.res new file mode 100644 index 00000000..b977141b --- /dev/null +++ b/src/data-transfer/DataTransfer.res @@ -0,0 +1,70 @@ +@editor.completeFrom(DataTransfer) +type t = { + /** + Returns the kind of operation that is currently selected. If the kind of operation isn't one of those that is allowed by the effectAllowed attribute, then the operation will fail. + +Can be set, to change the selected operation. + +The possible values are "none", "copy", "link", and "move". + [Read more on MDN](https://developer.mozilla.org/docs/Web/API/DataTransfer/dropEffect) + */ + mutable dropEffect: string, + /** + Returns the kinds of operations that are to be allowed. + +Can be set (during the dragstart event), to change the allowed operations. + +The possible values are "none", "copy", "copyLink", "copyMove", "link", "linkMove", "move", "all", and "uninitialized", + [Read more on MDN](https://developer.mozilla.org/docs/Web/API/DataTransfer/effectAllowed) + */ + mutable effectAllowed: string, + /** + Returns a DataTransferItemList object, with the drag data. + [Read more on MDN](https://developer.mozilla.org/docs/Web/API/DataTransfer/items) + */ + items: DataTransferItemList.t, + /** + Returns a frozen array listing the formats that were set in the dragstart event. In addition, if any files are being dragged, then one of the types will be the string "Files". + [Read more on MDN](https://developer.mozilla.org/docs/Web/API/DataTransfer/types) + */ + types: array, + /** + Returns a FileList of the files being dragged, if any. + [Read more on MDN](https://developer.mozilla.org/docs/Web/API/DataTransfer/files) + */ + files: DOM.fileList, +} + +/** +[Read more on MDN](https://developer.mozilla.org/docs/Web/API/DataTransfer) +*/ +@new +external make: unit => t = "DataTransfer" + +/** +Uses the given element to update the drag feedback, replacing any previously specified feedback. +[Read more on MDN](https://developer.mozilla.org/docs/Web/API/DataTransfer/setDragImage) +*/ +@send +external setDragImage: (t, ~image: DOMTree.element, ~x: int, ~y: int) => unit = "setDragImage" + +/** +Returns the specified data. If there is no such data, returns the empty string. +[Read more on MDN](https://developer.mozilla.org/docs/Web/API/DataTransfer/getData) +*/ +@send +external getData: (t, string) => string = "getData" + +/** +Adds the specified data. +[Read more on MDN](https://developer.mozilla.org/docs/Web/API/DataTransfer/setData) +*/ +@send +external setData: (t, ~format: string, ~data: string) => unit = "setData" + +/** +Removes the data of the specified formats. Removes all data if the argument is omitted. +[Read more on MDN](https://developer.mozilla.org/docs/Web/API/DataTransfer/clearData) +*/ +@send +external clearData: (t, ~format: string=?) => unit = "clearData" diff --git a/src/data-transfer/DataTransferItem.res b/src/data-transfer/DataTransferItem.res new file mode 100644 index 00000000..c6f67f3d --- /dev/null +++ b/src/data-transfer/DataTransferItem.res @@ -0,0 +1,35 @@ +@editor.completeFrom(DataTransferItem) +type t = private { + /** + Returns the drag data item kind, one of: "string", "file". + [Read more on MDN](https://developer.mozilla.org/docs/Web/API/DataTransferItem/kind) + */ + kind: string, + /** + Returns the drag data item type string. + [Read more on MDN](https://developer.mozilla.org/docs/Web/API/DataTransferItem/type) + */ + @as("type") + type_: string, +} + +/** +Invokes the callback with the string data as the argument, if the drag data item kind is text. +[Read more on MDN](https://developer.mozilla.org/docs/Web/API/DataTransferItem/getAsString) +*/ +@send +external getAsString: (t, string => unit) => unit = "getAsString" + +/** +Returns a WebApiFile object, if the drag data item kind is File. +[Read more on MDN](https://developer.mozilla.org/docs/Web/API/DataTransferItem/getAsFile) +*/ +@send +external getAsFile: t => Null.t = "getAsFile" + +/** +[Read more on MDN](https://developer.mozilla.org/docs/Web/API/DataTransferItem/webkitGetAsEntry) +*/ +@send +external webkitGetAsEntry: t => Null.t = + "webkitGetAsEntry" diff --git a/src/ui-events/DataTransferItemList.res b/src/data-transfer/DataTransferItemList.res similarity index 61% rename from src/ui-events/DataTransferItemList.res rename to src/data-transfer/DataTransferItemList.res index 30c9eb50..362ccb55 100644 --- a/src/ui-events/DataTransferItemList.res +++ b/src/data-transfer/DataTransferItemList.res @@ -1,36 +1,36 @@ -type t = UiEventsTypes.dataTransferItemList = private {...UiEventsTypes.dataTransferItemList} +@editor.completeFrom(DataTransferItemList) +type t = private { + /** + Returns the number of items in the drag data store. + [Read more on MDN](https://developer.mozilla.org/docs/Web/API/DataTransferItemList/length) + */ + length: int, +} /** Adds a new entry for the given data to the drag data store. If the data is plain text then a type string has to be provided also. [Read more on MDN](https://developer.mozilla.org/docs/Web/API/DataTransferItemList/add) */ @throws(JsExn) @send -external add: ( - UiEventsTypes.dataTransferItemList, - ~data: string, - ~type_: string, -) => Null.t = "add" +external add: (t, ~data: string, ~type_: string) => Null.t = "add" /** Adds a new entry for the given data to the drag data store. If the data is plain text then a type string has to be provided also. [Read more on MDN](https://developer.mozilla.org/docs/Web/API/DataTransferItemList/add) */ @throws(JsExn) @send -external addFile: ( - UiEventsTypes.dataTransferItemList, - FileTypes.file, -) => Null.t = "add" +external addFile: (t, DOM.file) => Null.t = "add" /** Removes the indexth entry in the drag data store. [Read more on MDN](https://developer.mozilla.org/docs/Web/API/DataTransferItemList/remove) */ @throws(JsExn) @send -external remove: (UiEventsTypes.dataTransferItemList, int) => unit = "remove" +external remove: (t, int) => unit = "remove" /** Removes all the entries in the drag data store. [Read more on MDN](https://developer.mozilla.org/docs/Web/API/DataTransferItemList/clear) */ @send -external clear: UiEventsTypes.dataTransferItemList => unit = "clear" +external clear: t => unit = "clear" diff --git a/src/dom-nodes/HTMLCollection.res b/src/dom-nodes/HTMLCollection.res index ebc5280e..b77d589c 100644 --- a/src/dom-nodes/HTMLCollection.res +++ b/src/dom-nodes/HTMLCollection.res @@ -2,13 +2,7 @@ A generic collection (array-like object similar to arguments) of elements (in document order) and offers methods and properties for selecting from the list. [See HTMLCollection on MDN](https://developer.mozilla.org/docs/Web/API/HTMLCollection) */ -type t<'item> = private { - /** - Sets or retrieves the number of objects in a collection. - [Read more on MDN](https://developer.mozilla.org/docs/Web/API/HTMLCollection/length) - */ - length: int, -} +type t<'item> = DOMTree.htmlCollection<'item> = private {...DOMTree.htmlCollection<'item>} /** Retrieves an object from various collections. diff --git a/src/dom-platform/DOMStringMap.res b/src/dom-tree/DOMStringMap.res similarity index 100% rename from src/dom-platform/DOMStringMap.res rename to src/dom-tree/DOMStringMap.res diff --git a/src/dom-nodes/DOMTree.res b/src/dom-tree/DOMTree.res similarity index 98% rename from src/dom-nodes/DOMTree.res rename to src/dom-tree/DOMTree.res index 9611fd51..76fc0ca8 100644 --- a/src/dom-nodes/DOMTree.res +++ b/src/dom-tree/DOMTree.res @@ -1,5 +1,18 @@ @@warning("-30") +/** +A generic collection (array-like object similar to arguments) of elements (in document order) and offers methods and properties for selecting from the list. +[See HTMLCollection on MDN](https://developer.mozilla.org/docs/Web/API/HTMLCollection) +*/ +@editor.completeFrom(HTMLCollection) +type htmlCollection<'item> = private { + /** + Sets or retrieves the number of objects in a collection. + [Read more on MDN](https://developer.mozilla.org/docs/Web/API/HTMLCollection/length) + */ + length: int, +} + type shadowRootMode = | @as("closed") Closed | @as("open") Open @@ -263,7 +276,7 @@ TODO: mark as private once mutating fields of private records is allowed Returns the child elements. [Read more on MDN](https://developer.mozilla.org/docs/Web/API/Document/children) */ - children: HTMLCollection.t, + children: htmlCollection, /** Returns the first child that is an element, and null otherwise. [Read more on MDN](https://developer.mozilla.org/docs/Web/API/Document/firstElementChild) @@ -539,7 +552,7 @@ TODO: mark as private once mutating fields of private records is allowed Returns the child elements. [Read more on MDN](https://developer.mozilla.org/docs/Web/API/Document/children) */ - children: HTMLCollection.t, + children: htmlCollection, /** Returns the first child that is an element, and null otherwise. [Read more on MDN](https://developer.mozilla.org/docs/Web/API/Document/firstElementChild) diff --git a/src/fetch/FetchTypes.res b/src/fetch/FetchTypes.res index 7a4648fd..27e21ff7 100644 --- a/src/fetch/FetchTypes.res +++ b/src/fetch/FetchTypes.res @@ -208,7 +208,7 @@ Provides a way to easily construct a set of key/value pairs representing form fi [See FormData on MDN](https://developer.mozilla.org/docs/Web/API/FormData) */ @editor.completeFrom(FormData) -type formData = private {} +type formData = FormData.t = private {...FormData.t} @editor.completeFrom(HeadersInit) type headersInit @@ -217,9 +217,7 @@ type formData = private {} type requestInfo = unknown @editor.completeFrom(FormDataEntryValue) @unboxed -type formDataEntryValue = - | String(string) - | File(FileTypes.file) +type formDataEntryValue = FormDataEntryValue.t = | ...FormDataEntryValue.t type requestInit = { /** diff --git a/src/fetch/FormDataEntryValue.res b/src/fetch/FormDataEntryValue.res deleted file mode 100644 index da0973b2..00000000 --- a/src/fetch/FormDataEntryValue.res +++ /dev/null @@ -1,2 +0,0 @@ -@unboxed -type t = FetchTypes.formDataEntryValue = | ...FetchTypes.formDataEntryValue diff --git a/src/file/BaseFileAndDirectoryEntries.res b/src/file-entries/BaseFileAndDirectoryEntries.res similarity index 100% rename from src/file/BaseFileAndDirectoryEntries.res rename to src/file-entries/BaseFileAndDirectoryEntries.res diff --git a/src/file/FileAndDirectoryEntriesTypes.res b/src/file-entries/FileAndDirectoryEntriesTypes.res similarity index 100% rename from src/file/FileAndDirectoryEntriesTypes.res rename to src/file-entries/FileAndDirectoryEntriesTypes.res diff --git a/src/file/FileSystemDirectoryEntry.res b/src/file-entries/FileSystemDirectoryEntry.res similarity index 100% rename from src/file/FileSystemDirectoryEntry.res rename to src/file-entries/FileSystemDirectoryEntry.res diff --git a/src/file/FileSystemDirectoryReader.res b/src/file-entries/FileSystemDirectoryReader.res similarity index 100% rename from src/file/FileSystemDirectoryReader.res rename to src/file-entries/FileSystemDirectoryReader.res diff --git a/src/file/FileSystemEntry.res b/src/file-entries/FileSystemEntry.res similarity index 100% rename from src/file/FileSystemEntry.res rename to src/file-entries/FileSystemEntry.res diff --git a/src/fetch/FormData.res b/src/form-data/FormData.res similarity index 86% rename from src/fetch/FormData.res rename to src/form-data/FormData.res index c7388cf9..8ca8a777 100644 --- a/src/fetch/FormData.res +++ b/src/form-data/FormData.res @@ -1,7 +1,7 @@ /** [Read more on MDN](https://developer.mozilla.org/docs/Web/API/FormData) */ -type t = FetchTypes.formData = private {...FetchTypes.formData} +type t = private {} type formDataEntryValue = FormDataEntryValue.t @@ -21,7 +21,8 @@ external append: (t, ~name: string, ~value: string) => unit = "append" [Read more on MDN](https://developer.mozilla.org/docs/Web/API/FormData/append) */ @send -external appendBlob: (t, ~name: string, ~blobValue: Blob.t, ~filename: string=?) => unit = "append" +external appendBlob: (t, ~name: string, ~blobValue: DOM.blob, ~filename: string=?) => unit = + "append" /** [Read more on MDN](https://developer.mozilla.org/docs/Web/API/FormData/delete) @@ -69,4 +70,4 @@ external set: (t, ~name: string, ~value: string) => unit = "set" [Read more on MDN](https://developer.mozilla.org/docs/Web/API/FormData/set) */ @send -external setBlob: (t, ~name: string, ~blobValue: Blob.t, ~filename: string=?) => unit = "set" +external setBlob: (t, ~name: string, ~blobValue: DOM.blob, ~filename: string=?) => unit = "set" diff --git a/src/form-data/FormDataEntryValue.res b/src/form-data/FormDataEntryValue.res new file mode 100644 index 00000000..87c81187 --- /dev/null +++ b/src/form-data/FormDataEntryValue.res @@ -0,0 +1,4 @@ +@unboxed +type t = + | String(string) + | File(DOM.file) diff --git a/src/touch/Touch.res b/src/touch/Touch.res new file mode 100644 index 00000000..0d6b3e52 --- /dev/null +++ b/src/touch/Touch.res @@ -0,0 +1,79 @@ +type touchType = + | @as("direct") Direct + | @as("stylus") Stylus + +@editor.completeFrom(Touch) +type t = private { + /** + [Read more on MDN](https://developer.mozilla.org/docs/Web/API/Touch/identifier) + */ + identifier: int, + /** + [Read more on MDN](https://developer.mozilla.org/docs/Web/API/Touch/target) + */ + target: DOM.eventTarget, + /** + [Read more on MDN](https://developer.mozilla.org/docs/Web/API/Touch/screenX) + */ + screenX: float, + /** + [Read more on MDN](https://developer.mozilla.org/docs/Web/API/Touch/screenY) + */ + screenY: float, + /** + [Read more on MDN](https://developer.mozilla.org/docs/Web/API/Touch/clientX) + */ + clientX: float, + /** + [Read more on MDN](https://developer.mozilla.org/docs/Web/API/Touch/clientY) + */ + clientY: float, + /** + [Read more on MDN](https://developer.mozilla.org/docs/Web/API/Touch/pageX) + */ + pageX: float, + /** + [Read more on MDN](https://developer.mozilla.org/docs/Web/API/Touch/pageY) + */ + pageY: float, + /** + [Read more on MDN](https://developer.mozilla.org/docs/Web/API/Touch/radiusX) + */ + radiusX: float, + /** + [Read more on MDN](https://developer.mozilla.org/docs/Web/API/Touch/radiusY) + */ + radiusY: float, + /** + [Read more on MDN](https://developer.mozilla.org/docs/Web/API/Touch/rotationAngle) + */ + rotationAngle: float, + /** + [Read more on MDN](https://developer.mozilla.org/docs/Web/API/Touch/force) + */ + force: float, +} + +type init = { + mutable identifier: int, + mutable target: DOM.eventTarget, + mutable clientX?: float, + mutable clientY?: float, + mutable screenX?: float, + mutable screenY?: float, + mutable pageX?: float, + mutable pageY?: float, + mutable radiusX?: float, + mutable radiusY?: float, + mutable rotationAngle?: float, + mutable force?: float, + mutable altitudeAngle?: float, + mutable azimuthAngle?: float, + mutable touchType?: touchType, +} + +/** +[Read more on MDN](https://developer.mozilla.org/docs/Web/API/Touch) +*/ +@new +external make: init => t = "Touch" diff --git a/src/touch/TouchList.res b/src/touch/TouchList.res new file mode 100644 index 00000000..5d4848ab --- /dev/null +++ b/src/touch/TouchList.res @@ -0,0 +1,13 @@ +@editor.completeFrom(TouchList) +type t = private { + /** + [Read more on MDN](https://developer.mozilla.org/docs/Web/API/TouchList/length) + */ + length: int, +} + +/** +[Read more on MDN](https://developer.mozilla.org/docs/Web/API/TouchList/item) +*/ +@send +external item: (t, int) => Null.t = "item" diff --git a/src/ui-events/DataTransfer.res b/src/ui-events/DataTransfer.res deleted file mode 100644 index 4db56003..00000000 --- a/src/ui-events/DataTransfer.res +++ /dev/null @@ -1,40 +0,0 @@ -type t = UiEventsTypes.dataTransfer = {...UiEventsTypes.dataTransfer} - -/** -[Read more on MDN](https://developer.mozilla.org/docs/Web/API/DataTransfer) -*/ -@new -external make: unit => UiEventsTypes.dataTransfer = "DataTransfer" - -/** -Uses the given element to update the drag feedback, replacing any previously specified feedback. -[Read more on MDN](https://developer.mozilla.org/docs/Web/API/DataTransfer/setDragImage) -*/ -@send -external setDragImage: ( - UiEventsTypes.dataTransfer, - ~image: DOMTree.element, - ~x: int, - ~y: int, -) => unit = "setDragImage" - -/** -Returns the specified data. If there is no such data, returns the empty string. -[Read more on MDN](https://developer.mozilla.org/docs/Web/API/DataTransfer/getData) -*/ -@send -external getData: (UiEventsTypes.dataTransfer, string) => string = "getData" - -/** -Adds the specified data. -[Read more on MDN](https://developer.mozilla.org/docs/Web/API/DataTransfer/setData) -*/ -@send -external setData: (UiEventsTypes.dataTransfer, ~format: string, ~data: string) => unit = "setData" - -/** -Removes the data of the specified formats. Removes all data if the argument is omitted. -[Read more on MDN](https://developer.mozilla.org/docs/Web/API/DataTransfer/clearData) -*/ -@send -external clearData: (UiEventsTypes.dataTransfer, ~format: string=?) => unit = "clearData" diff --git a/src/ui-events/DataTransferItem.res b/src/ui-events/DataTransferItem.res deleted file mode 100644 index d3b73953..00000000 --- a/src/ui-events/DataTransferItem.res +++ /dev/null @@ -1,23 +0,0 @@ -type t = UiEventsTypes.dataTransferItem = private {...UiEventsTypes.dataTransferItem} - -/** -Invokes the callback with the string data as the argument, if the drag data item kind is text. -[Read more on MDN](https://developer.mozilla.org/docs/Web/API/DataTransferItem/getAsString) -*/ -@send -external getAsString: (UiEventsTypes.dataTransferItem, string => unit) => unit = "getAsString" - -/** -Returns a WebApiFile object, if the drag data item kind is File. -[Read more on MDN](https://developer.mozilla.org/docs/Web/API/DataTransferItem/getAsFile) -*/ -@send -external getAsFile: UiEventsTypes.dataTransferItem => Null.t = "getAsFile" - -/** -[Read more on MDN](https://developer.mozilla.org/docs/Web/API/DataTransferItem/webkitGetAsEntry) -*/ -@send -external webkitGetAsEntry: UiEventsTypes.dataTransferItem => Null.t< - FileAndDirectoryEntriesTypes.fileSystemEntry, -> = "webkitGetAsEntry" diff --git a/src/ui-events/Touch.res b/src/ui-events/Touch.res deleted file mode 100644 index 94885854..00000000 --- a/src/ui-events/Touch.res +++ /dev/null @@ -1,7 +0,0 @@ -type t = UiEventsTypes.touch = private {...UiEventsTypes.touch} - -/** -[Read more on MDN](https://developer.mozilla.org/docs/Web/API/Touch) -*/ -@new -external make: UiEventsTypes.touchInit => UiEventsTypes.touch = "Touch" diff --git a/src/ui-events/TouchList.res b/src/ui-events/TouchList.res deleted file mode 100644 index 2718ce1d..00000000 --- a/src/ui-events/TouchList.res +++ /dev/null @@ -1,7 +0,0 @@ -type t = UiEventsTypes.touchList = private {...UiEventsTypes.touchList} - -/** -[Read more on MDN](https://developer.mozilla.org/docs/Web/API/TouchList/item) -*/ -@send -external item: (UiEventsTypes.touchList, int) => Null.t = "item" diff --git a/src/ui-events/UiEventsTypes.res b/src/ui-events/UiEventsTypes.res index e9f8a8fd..405eda64 100644 --- a/src/ui-events/UiEventsTypes.res +++ b/src/ui-events/UiEventsTypes.res @@ -1,8 +1,6 @@ @@warning("-30") -type touchType = - | @as("direct") Direct - | @as("stylus") Stylus +type touchType = Touch.touchType = | ...Touch.touchType /** Simple user interface events. @@ -52,32 +50,14 @@ One drag data item. During a drag operation, each drag event has a dataTransfer [See DataTransferItem on MDN](https://developer.mozilla.org/docs/Web/API/DataTransferItem) */ @editor.completeFrom(DataTransferItem) -type dataTransferItem = private { - /** - Returns the drag data item kind, one of: "string", "file". - [Read more on MDN](https://developer.mozilla.org/docs/Web/API/DataTransferItem/kind) - */ - kind: string, - /** - Returns the drag data item type string. - [Read more on MDN](https://developer.mozilla.org/docs/Web/API/DataTransferItem/type) - */ - @as("type") - type_: string, -} +type dataTransferItem = DataTransferItem.t = private {...DataTransferItem.t} /** A list of DataTransferItem objects representing items being dragged. During a drag operation, each DragEvent has a dataTransfer property and that property is a DataTransferItemList. [See DataTransferItemList on MDN](https://developer.mozilla.org/docs/Web/API/DataTransferItemList) */ @editor.completeFrom(DataTransferItemList) -type dataTransferItemList = private { - /** - Returns the number of items in the drag data store. - [Read more on MDN](https://developer.mozilla.org/docs/Web/API/DataTransferItemList/length) - */ - length: int, -} +type dataTransferItemList = DataTransferItemList.t = private {...DataTransferItemList.t} /** Used to hold the data that is being dragged during a drag and drop operation. It may hold one or more data items, each of one or more data types. For more information about drag and drop, see HTML Drag and Drop API. @@ -85,41 +65,7 @@ Used to hold the data that is being dragged during a drag and drop operation. It TODO: mark as private once mutating fields of private records is allowed */ @editor.completeFrom(DataTransfer) -type dataTransfer = { - /** - Returns the kind of operation that is currently selected. If the kind of operation isn't one of those that is allowed by the effectAllowed attribute, then the operation will fail. - -Can be set, to change the selected operation. - -The possible values are "none", "copy", "link", and "move". - [Read more on MDN](https://developer.mozilla.org/docs/Web/API/DataTransfer/dropEffect) - */ - mutable dropEffect: string, - /** - Returns the kinds of operations that are to be allowed. - -Can be set (during the dragstart event), to change the allowed operations. - -The possible values are "none", "copy", "copyLink", "copyMove", "link", "linkMove", "move", "all", and "uninitialized", - [Read more on MDN](https://developer.mozilla.org/docs/Web/API/DataTransfer/effectAllowed) - */ - mutable effectAllowed: string, - /** - Returns a DataTransferItemList object, with the drag data. - [Read more on MDN](https://developer.mozilla.org/docs/Web/API/DataTransfer/items) - */ - items: dataTransferItemList, - /** - Returns a frozen array listing the formats that were set in the dragstart event. In addition, if any files are being dragged, then one of the types will be the string "Files". - [Read more on MDN](https://developer.mozilla.org/docs/Web/API/DataTransfer/types) - */ - types: array, - /** - Returns a FileList of the files being dragged, if any. - [Read more on MDN](https://developer.mozilla.org/docs/Web/API/DataTransfer/files) - */ - files: DOM.fileList, -} +type dataTransfer = DataTransfer.t = {...DataTransfer.t} /** [See InputEvent on MDN](https://developer.mozilla.org/docs/Web/API/InputEvent) @@ -313,68 +259,14 @@ A single contact point on a touch-sensitive device. The contact point is commonl [See Touch on MDN](https://developer.mozilla.org/docs/Web/API/Touch) */ @editor.completeFrom(Touch) -type touch = private { - /** - [Read more on MDN](https://developer.mozilla.org/docs/Web/API/Touch/identifier) - */ - identifier: int, - /** - [Read more on MDN](https://developer.mozilla.org/docs/Web/API/Touch/target) - */ - target: DOM.eventTarget, - /** - [Read more on MDN](https://developer.mozilla.org/docs/Web/API/Touch/screenX) - */ - screenX: float, - /** - [Read more on MDN](https://developer.mozilla.org/docs/Web/API/Touch/screenY) - */ - screenY: float, - /** - [Read more on MDN](https://developer.mozilla.org/docs/Web/API/Touch/clientX) - */ - clientX: float, - /** - [Read more on MDN](https://developer.mozilla.org/docs/Web/API/Touch/clientY) - */ - clientY: float, - /** - [Read more on MDN](https://developer.mozilla.org/docs/Web/API/Touch/pageX) - */ - pageX: float, - /** - [Read more on MDN](https://developer.mozilla.org/docs/Web/API/Touch/pageY) - */ - pageY: float, - /** - [Read more on MDN](https://developer.mozilla.org/docs/Web/API/Touch/radiusX) - */ - radiusX: float, - /** - [Read more on MDN](https://developer.mozilla.org/docs/Web/API/Touch/radiusY) - */ - radiusY: float, - /** - [Read more on MDN](https://developer.mozilla.org/docs/Web/API/Touch/rotationAngle) - */ - rotationAngle: float, - /** - [Read more on MDN](https://developer.mozilla.org/docs/Web/API/Touch/force) - */ - force: float, -} +type touch = Touch.t = private {...Touch.t} /** A list of contact points on a touch surface. For example, if the user has three fingers on the touch surface (such as a screen or trackpad), the corresponding TouchList object would have one Touch object for each finger, for a total of three entries. [See TouchList on MDN](https://developer.mozilla.org/docs/Web/API/TouchList) */ @editor.completeFrom(TouchList) -type touchList = private { - /** - [Read more on MDN](https://developer.mozilla.org/docs/Web/API/TouchList/length) - */ - length: int, -} +type touchList = TouchList.t = private {...TouchList.t} /** An event sent when the state of contacts with a touch-sensitive surface changes. This surface can be a touch screen or trackpad, for example. The event can describe one or more points of contact with the screen and includes support for detecting movement, addition and removal of contact points, and so forth. @@ -546,23 +438,7 @@ type inputEventInit = { mutable targetRanges?: array, } -type touchInit = { - mutable identifier: int, - mutable target: DOM.eventTarget, - mutable clientX?: float, - mutable clientY?: float, - mutable screenX?: float, - mutable screenY?: float, - mutable pageX?: float, - mutable pageY?: float, - mutable radiusX?: float, - mutable radiusY?: float, - mutable rotationAngle?: float, - mutable force?: float, - mutable altitudeAngle?: float, - mutable azimuthAngle?: float, - mutable touchType?: touchType, -} +type touchInit = Touch.init = {...Touch.init} type pointerEventInit = { ...mouseEventInit, diff --git a/tests/NarrowDataAliases__test.res b/tests/NarrowDataAliases__test.res new file mode 100644 index 00000000..bbf19470 --- /dev/null +++ b/tests/NarrowDataAliases__test.res @@ -0,0 +1,28 @@ +// These equalities must survive the move in both directions. +let touchToPublic = (value: UiEventsTypes.touch): Touch.t => value +let touchFromPublic = (value: Touch.t): UiEventsTypes.touch => value +let listToPublic = (value: UiEventsTypes.touchList): TouchList.t => value +let listFromPublic = (value: TouchList.t): UiEventsTypes.touchList => value +let transferToPublic = (value: UiEventsTypes.dataTransfer): DataTransfer.t => value +let transferFromPublic = (value: DataTransfer.t): UiEventsTypes.dataTransfer => value +let itemToPublic = (value: UiEventsTypes.dataTransferItem): DataTransferItem.t => value +let itemFromPublic = (value: DataTransferItem.t): UiEventsTypes.dataTransferItem => value +let itemsToPublic = (value: UiEventsTypes.dataTransferItemList): DataTransferItemList.t => value +let itemsFromPublic = (value: DataTransferItemList.t): UiEventsTypes.dataTransferItemList => value +let formToPublic = (value: FetchTypes.formData): FormData.t => value +let formFromPublic = (value: FormData.t): FetchTypes.formData => value +let entryToPublic = (value: FetchTypes.formDataEntryValue): FormDataEntryValue.t => value +let entryFromPublic = (value: FormDataEntryValue.t): FetchTypes.formDataEntryValue => value +let initToPublic = (value: UiEventsTypes.touchInit): Touch.init => value +let initFromPublic = (value: Touch.init): UiEventsTypes.touchInit => value +let oldDirect: Touch.touchType = UiEventsTypes.Direct +let oldStylus: Touch.touchType = UiEventsTypes.Stylus +let oldString: FormDataEntryValue.t = FetchTypes.String("string") +let oldFile = (file: DOM.file): FormDataEntryValue.t => FetchTypes.File(file) +let body = (form: FormData.t) => form->BodyInit.fromFormData +let response = (form: FetchTypes.formData) => Response.fromFormData(form) +let input = (event: UiEventsTypes.inputEvent): Null.t => event.dataTransfer +let touches = (event: UiEventsTypes.touchEvent): TouchList.t => event.touches + +let beacon = (navigator: Navigator.t, form: FormData.t) => + navigator->Navigator.sendBeacon5(~url="/beacon", ~data=form) diff --git a/tests/browser/NarrowData__test.res b/tests/browser/NarrowData__test.res new file mode 100644 index 00000000..bf6cbe59 --- /dev/null +++ b/tests/browser/NarrowData__test.res @@ -0,0 +1,40 @@ +let transfer = DataTransfer.make() +transfer->DataTransfer.setData(~format="text/plain", ~data="clipboard") +assert(transfer->DataTransfer.getData("text/plain") == "clipboard") +// Chromium ignores drag-effect changes outside an active native drag session. +// Keep the writable binding compile-checked, without assuming a synthetic session. +transfer.dropEffect = "copy" +transfer->DataTransfer.clearData(~format="text/plain") +assert(transfer->DataTransfer.getData("text/plain") == "") +let file = File.make(~fileBits=[String("data")], ~fileName="transfer.txt") +let item = transfer.items->DataTransferItemList.addFile(file)->Null.toOption + +switch item { +| Some(item) => + let recovered = item->DataTransferItem.getAsFile->Null.toOption + assert(switch recovered { + | Some(value) => value.name == "transfer.txt" + | None => false + }) + assert(item->DataTransferItem.webkitGetAsEntry->Null.toOption == None) +| None => assert(false) +} + +assert(transfer.files.length == 1) +let emptyTransfer = DataTransfer.make() +assert(emptyTransfer.items.length == 0) + +// Chromium is the supported runner; fail explicitly if Touch construction is absent. +let touchSupported: bool = %raw(`typeof Touch === "function" && typeof TouchEvent === "function"`) +assert(touchSupported) +let target: DOM.eventTarget = %raw(`document.body`) +let touch = Touch.make({identifier: 7, target, clientX: 12.5, touchType: Touch.Direct}) +assert(touch.identifier == 7 && touch.clientX == 12.5) +let event = TouchEvent.make(~type_="touchstart", ~eventInitDict={touches: [touch]}) +assert(event.touches.length == 1) +assert(event.touches->TouchList.item(1)->Null.toOption == None) + +assert(switch event.touches->TouchList.item(0)->Null.toOption { +| Some(value) => value.identifier == 7 +| None => false +}) diff --git a/tests/fixtures.json b/tests/fixtures.json index f066adb1..efce5575 100644 --- a/tests/fixtures.json +++ b/tests/fixtures.json @@ -35,7 +35,8 @@ "WebSocketsAPI/WebSocket__test.res", "WebStorageAPI/Storage__test.res", "WebWorkersAPI/SharedWorkerScope__test.res", - "WebWorkersAPI/SharedWorker__test.res" + "WebWorkersAPI/SharedWorker__test.res", + "NarrowDataAliases__test.res" ], "documentationExamples": ["Fetch__test.res", "VisualViewport__test.res"], "nodeRuntime": [ @@ -47,5 +48,9 @@ "FetchAPI/URLSearchParams__test.res", "URLAPI/URL__test.res" ], - "browserRuntime": ["browser/BindingContracts__test.res", "browser/NativeAPI__test.res"] + "browserRuntime": [ + "browser/BindingContracts__test.res", + "browser/NativeAPI__test.res", + "browser/NarrowData__test.res" + ] }