From 20d11da1f6ee91da0420da8225ca30e5f9a36632 Mon Sep 17 00:00:00 2001 From: Josh Vlk Date: Tue, 17 Nov 2026 08:35:10 -0300 Subject: [PATCH 1/3] feat(webapi): isolate History and Location features [Codex] (#413) React's DOM bindings need element, history, and location types, but History and Location currently belong to the Window feature. Selecting those types therefore also compiles the broader Window dependency graph. Add independent `WebAPI.History` and `WebAPI.Location` features and move their source files into their own directories. History depends only on the standard library; Location depends on core DOM. Window includes both features, preserving existing module names and type identities. Consumers can select `WebAPI.DOMNodes`, `WebAPI.History`, and `WebAPI.Location` without enabling Window. The feature-ownership checks register both new source groups and guard missing features and duplicate public-module ownership. The API guide documents the narrower selection. The compiler upgrade has already landed in #414. This branch now incorporates that main-branch update and retains its compiler checks, documentation renderer, and typed-array fixture. The remaining diff is limited to the History/Location feature split, its documentation, and feature validation. The further selective DOMTree/CSS layout is separate in #415; the React profiling and dependent JSX work remain in https://github.com/jderochervlk/rescript-react/pull/1 and https://github.com/jderochervlk/rescript-react/pull/2. --- docs/content/docs/api-surface.mdx | 26 +++++++++++++++++++ rescript.json | 18 +++++++++++-- scripts/check-features.mjs | 4 ++- scripts/check-features.test.mjs | 33 +++++++++++++++++++++++- src/{window => history}/History.res | 0 src/{window => history}/HistoryTypes.res | 0 src/{window => location}/Location.res | 0 7 files changed, 77 insertions(+), 4 deletions(-) rename src/{window => history}/History.res (100%) rename src/{window => history}/HistoryTypes.res (100%) rename src/{window => location}/Location.res (100%) diff --git a/docs/content/docs/api-surface.mdx b/docs/content/docs/api-surface.mdx index e7f4c651..1b182e9c 100644 --- a/docs/content/docs/api-surface.mdx +++ b/docs/content/docs/api-surface.mdx @@ -81,6 +81,7 @@ 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.History WebAPI.Location WebAPI.SafeFetch ``` @@ -106,6 +107,31 @@ helpers can select only the safe feature: The `let?` examples below require the experimental `LetUnwrap` setting with the current ReScript 13 alpha compiler. The SafeFetch API itself can also be used with ordinary `switch` expressions. +### DOM types without the Window bundle + +`WebAPI.History` independently exposes `WebAPI.History` and its existing +`WebAPI.History.Types.history` type. `WebAPI.Location` exposes `WebAPI.Location` +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: + +```json +{ + "dependencies": [ + { + "name": "@rescript/webapi", + "features": ["WebAPI.DOMNodes", "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. +An unrestricted WebAPI dependency elsewhere in the dependency graph enables all features. + ## Fetch Use `WebAPI.Fetch.fetch` for string URLs and `WebAPI.Fetch.fetchWithRequest` diff --git a/rescript.json b/rescript.json index 8ac1cd9c..83f718c2 100644 --- a/rescript.json +++ b/rescript.json @@ -19,7 +19,11 @@ "DOMNodes" ], "WebAPI.HTML": ["WebAPI.DOMNodes", "WebAPI.File", "HTML"], + "WebAPI.History": ["History"], + "WebAPI.Location": ["WebAPI.DOM", "Location"], "WebAPI.Window": [ + "WebAPI.History", + "WebAPI.Location", "WebAPI.HTML", "WebAPI.Media", "WebAPI.Storage", @@ -294,6 +298,18 @@ "HTMLUnknownElement" ] }, + { + "dir": "src/history", + "subdirs": true, + "feature": "History", + "public": ["History"] + }, + { + "dir": "src/location", + "subdirs": true, + "feature": "Location", + "public": ["Location"] + }, { "dir": "src/window", "subdirs": true, @@ -301,9 +317,7 @@ "public": [ "CustomElementRegistry", "Document", - "History", "IdleDeadline", - "Location", "VisualViewport", "Window", "XPathExpression", diff --git a/scripts/check-features.mjs b/scripts/check-features.mjs index 03ddf84b..4b2940d0 100644 --- a/scripts/check-features.mjs +++ b/scripts/check-features.mjs @@ -25,6 +25,8 @@ const expectedFeatureOwners = new Map([ ["WebAPI.DOMNodes", "DOMNodes"], ["WebAPI.File", "File"], ["WebAPI.HTML", "HTML"], + ["WebAPI.History", "History"], + ["WebAPI.Location", "Location"], ["WebAPI.Window", "Window"], ["WebAPI.CSSOM", "CSSOM"], ["WebAPI.CSSFontLoading", "CSSFontLoading"], @@ -237,7 +239,7 @@ const validateCompletionAliases = (sourceEntries) => { ); }; -const validateConfig = (config) => { +export const validateConfig = (config) => { const featureEntries = Object.entries(config.features ?? {}); const sourceEntries = (config.sources ?? []).filter( (source) => source !== null && typeof source === "object" && typeof source.feature === "string", diff --git a/scripts/check-features.test.mjs b/scripts/check-features.test.mjs index 590b42c8..70353ed6 100644 --- a/scripts/check-features.test.mjs +++ b/scripts/check-features.test.mjs @@ -1,7 +1,12 @@ import assert from "node:assert/strict"; +import { readFileSync } from "node:fs"; import test from "node:test"; -import { isMissingSafeFetchDiagnostic, parsePublicTypeAlias } from "./check-features.mjs"; +import { + isMissingSafeFetchDiagnostic, + parsePublicTypeAlias, + validateConfig, +} from "./check-features.mjs"; test("parses a public type alias without type parameters", () => { assert.deepEqual(parsePublicTypeAlias("type t = DOMTree.element"), { @@ -17,6 +22,32 @@ test("parses a public type alias with type parameters", () => { }); }); +const config = JSON.parse(readFileSync(new URL("../rescript.json", import.meta.url), "utf8")); + +test("validates independent History and Location feature ownership", () => { + assert.deepEqual(validateConfig(config), []); + assert.deepEqual(config.features["WebAPI.History"], ["History"]); + assert.deepEqual(config.features["WebAPI.Location"], ["WebAPI.DOM", "Location"]); + assert.ok(config.features["WebAPI.Window"].includes("WebAPI.History")); + assert.ok(config.features["WebAPI.Window"].includes("WebAPI.Location")); +}); + +test("rejects a missing History feature", () => { + const features = Object.fromEntries( + Object.entries(config.features).filter(([name]) => name !== "WebAPI.History"), + ); + assert.ok( + validateConfig({ ...config, features }).some((error) => error.includes("Expected exactly")), + ); +}); + +test("rejects duplicate Location public ownership", () => { + const sources = config.sources.map((source) => + source.feature === "Window" ? { ...source, public: [...source.public, "Location"] } : source, + ); + assert.ok(validateConfig({ ...config, sources }).includes("Duplicate public modules: Location")); +}); + test("recognizes the unavailable SafeFetch module diagnostic across line breaks", () => { assert.equal( isMissingSafeFetchDiagnostic("The module or file WebAPI.SafeFetch\ncan't be found."), diff --git a/src/window/History.res b/src/history/History.res similarity index 100% rename from src/window/History.res rename to src/history/History.res diff --git a/src/window/HistoryTypes.res b/src/history/HistoryTypes.res similarity index 100% rename from src/window/HistoryTypes.res rename to src/history/HistoryTypes.res diff --git a/src/window/Location.res b/src/location/Location.res similarity index 100% rename from src/window/Location.res rename to src/location/Location.res From 642f7b283e97b4cfdf32cb11ba3000a1d0c2464b Mon Sep 17 00:00:00 2001 From: Josh Vlk Date: Tue, 17 Nov 2026 07:15:16 -0500 Subject: [PATCH 2/3] feat(webapi): isolate touch transfer and form data features --- docs/content/docs/api-surface.mdx | 43 ++++++ package.json | 4 +- rescript.json | 44 ++++-- scripts/check-consumer.mjs | 21 +++ scripts/check-features.mjs | 31 +++- scripts/check-features.test.mjs | 17 +++ scripts/consumer-data-combined.res | 6 + scripts/consumer-data-disabled-fetch.res | 1 + scripts/consumer-data-disabled-filelist.res | 1 + scripts/consumer-data-disabled-inputevent.res | 1 + .../consumer-data-disabled-readablestream.res | 1 + scripts/consumer-data-disabled-touchevent.res | 1 + scripts/consumer-data-disabled-window.res | 1 + scripts/consumer-data-entries.res | 5 + scripts/consumer-data-form-runtime.res | 22 +++ scripts/consumer-data-form.res | 12 ++ scripts/consumer-data-touch.res | 5 + scripts/consumer-data-transfer.res | 13 ++ scripts/data-feature-consumers.mjs | 117 +++++++++++++++ scripts/fixtures/negative/FormDataPrivate.res | 1 + .../fixtures/negative/TouchItemNullable.res | 1 + .../fixtures/negative/TouchListPrivate.res | 1 + .../fixtures/negative/TransferItemPrivate.res | 1 + scripts/negative-fixtures.json | 24 +++ src/data-transfer/DataTransfer.res | 70 +++++++++ src/data-transfer/DataTransferItem.res | 35 +++++ .../DataTransferItemList.res | 24 +-- src/fetch/FetchTypes.res | 6 +- src/fetch/FormDataEntryValue.res | 2 - .../BaseFileAndDirectoryEntries.res | 0 .../FileAndDirectoryEntriesTypes.res | 0 .../FileSystemDirectoryEntry.res | 0 .../FileSystemDirectoryReader.res | 0 .../FileSystemEntry.res | 0 src/{fetch => form-data}/FormData.res | 7 +- src/form-data/FormDataEntryValue.res | 4 + src/touch/Touch.res | 79 ++++++++++ src/touch/TouchList.res | 13 ++ src/ui-events/DataTransfer.res | 40 ----- src/ui-events/DataTransferItem.res | 23 --- src/ui-events/Touch.res | 7 - src/ui-events/TouchList.res | 7 - src/ui-events/UiEventsTypes.res | 138 +----------------- tests/NarrowDataAliases__test.res | 28 ++++ tests/browser/NarrowData__test.res | 37 +++++ tests/fixtures.json | 9 +- 46 files changed, 656 insertions(+), 247 deletions(-) create mode 100644 scripts/consumer-data-combined.res create mode 100644 scripts/consumer-data-disabled-fetch.res create mode 100644 scripts/consumer-data-disabled-filelist.res create mode 100644 scripts/consumer-data-disabled-inputevent.res create mode 100644 scripts/consumer-data-disabled-readablestream.res create mode 100644 scripts/consumer-data-disabled-touchevent.res create mode 100644 scripts/consumer-data-disabled-window.res create mode 100644 scripts/consumer-data-entries.res create mode 100644 scripts/consumer-data-form-runtime.res create mode 100644 scripts/consumer-data-form.res create mode 100644 scripts/consumer-data-touch.res create mode 100644 scripts/consumer-data-transfer.res create mode 100644 scripts/data-feature-consumers.mjs create mode 100644 scripts/fixtures/negative/FormDataPrivate.res create mode 100644 scripts/fixtures/negative/TouchItemNullable.res create mode 100644 scripts/fixtures/negative/TouchListPrivate.res create mode 100644 scripts/fixtures/negative/TransferItemPrivate.res create mode 100644 src/data-transfer/DataTransfer.res create mode 100644 src/data-transfer/DataTransferItem.res rename src/{ui-events => data-transfer}/DataTransferItemList.res (61%) delete mode 100644 src/fetch/FormDataEntryValue.res rename src/{file => file-entries}/BaseFileAndDirectoryEntries.res (100%) rename src/{file => file-entries}/FileAndDirectoryEntriesTypes.res (100%) rename src/{file => file-entries}/FileSystemDirectoryEntry.res (100%) rename src/{file => file-entries}/FileSystemDirectoryReader.res (100%) rename src/{file => file-entries}/FileSystemEntry.res (100%) rename src/{fetch => form-data}/FormData.res (86%) create mode 100644 src/form-data/FormDataEntryValue.res create mode 100644 src/touch/Touch.res create mode 100644 src/touch/TouchList.res delete mode 100644 src/ui-events/DataTransfer.res delete mode 100644 src/ui-events/DataTransferItem.res delete mode 100644 src/ui-events/Touch.res delete mode 100644 src/ui-events/TouchList.res create mode 100644 tests/NarrowDataAliases__test.res create mode 100644 tests/browser/NarrowData__test.res diff --git a/docs/content/docs/api-surface.mdx b/docs/content/docs/api-surface.mdx index 1dfcbebc..3373d32c 100644 --- a/docs/content/docs/api-surface.mdx +++ b/docs/content/docs/api-surface.mdx @@ -82,6 +82,8 @@ 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 ``` @@ -137,6 +139,47 @@ 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. + ## Fetch Use `WebAPI.Fetch.fetch` for string URLs and `WebAPI.Fetch.fetchWithRequest` diff --git a/package.json b/package.json index 5e19d801..fed4b691 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 edb0e687..a1042a90 100644 --- a/rescript.json +++ b/rescript.json @@ -44,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", @@ -62,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"], @@ -350,8 +354,6 @@ "public": [ "BodyInit", "Fetch", - "FormData", - "FormDataEntryValue", "Headers", "HeadersInit", "Request", @@ -372,10 +374,7 @@ "Blob", "File", "FileList", - "FileSystemDirectoryEntry", "FileSystemDirectoryHandle", - "FileSystemDirectoryReader", - "FileSystemEntry", "FileSystemFileHandle", "FileSystemHandle", "FileSystemWritableFileStream", @@ -488,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 b99ce867..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"); @@ -42,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"], @@ -304,7 +311,14 @@ export const isMissingModuleDiagnostic = (output, moduleName) => export const isMissingSafeFetchDiagnostic = (output) => isMissingModuleDiagnostic(output, "SafeFetch"); -const runConsumerCheck = ({ name, features, fixture, shouldCompile, missingModule }) => { +const runConsumerCheck = ({ + name, + features, + fixture, + shouldCompile, + missingModule, + expectedSources, +}) => { const directory = mkdtempSync(path.join(os.tmpdir(), "webapi-feature-consumer-")); try { prepareConsumer(directory, features, fixture); @@ -313,6 +327,17 @@ const runConsumerCheck = ({ name, features, fixture, shouldCompile, missingModul 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 && @@ -371,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"], 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-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/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/FormDataPrivate.res b/scripts/fixtures/negative/FormDataPrivate.res new file mode 100644 index 00000000..a7d2e88d --- /dev/null +++ b/scripts/fixtures/negative/FormDataPrivate.res @@ -0,0 +1 @@ +let fake: WebAPI.FormData.t = {} 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 d5d3ecf5..ec3920ab 100644 --- a/scripts/negative-fixtures.json +++ b/scripts/negative-fixtures.json @@ -166,5 +166,29 @@ "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": "FormDataPrivate", + "fixture": "scripts/fixtures/negative/FormDataPrivate.res", + "features": ["WebAPI.FormData"], + "expectedDiagnostic": "Cannot create values of the" + }, + { + "name": "TouchItemNullable", + "fixture": "scripts/fixtures/negative/TouchItemNullable.res", + "features": ["WebAPI.Touch"], + "expectedDiagnostic": "This has type:" } ] 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/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..a84f2ce3 --- /dev/null +++ b/tests/browser/NarrowData__test.res @@ -0,0 +1,37 @@ +let transfer = DataTransfer.make() +transfer->DataTransfer.setData(~format="text/plain", ~data="clipboard") +assert(transfer->DataTransfer.getData("text/plain") == "clipboard") +transfer.dropEffect = "copy" +assert(transfer.dropEffect == "copy") +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" + ] } From 691bc3f20dc5d621d22f5bf9931b4ec086542d5f Mon Sep 17 00:00:00 2001 From: Josh Vlk Date: Tue, 17 Nov 2026 07:18:21 -0500 Subject: [PATCH 3/3] test(webapi): respect native data and empty-record semantics --- docs/content/docs/api-surface.mdx | 5 +++++ scripts/fixtures/negative/FormDataPrivate.res | 1 - scripts/fixtures/negative/FormDataRejectsString.res | 1 + scripts/negative-fixtures.json | 6 +++--- tests/browser/NarrowData__test.res | 5 ++++- 5 files changed, 13 insertions(+), 5 deletions(-) delete mode 100644 scripts/fixtures/negative/FormDataPrivate.res create mode 100644 scripts/fixtures/negative/FormDataRejectsString.res diff --git a/docs/content/docs/api-surface.mdx b/docs/content/docs/api-surface.mdx index 3373d32c..c3c7fed8 100644 --- a/docs/content/docs/api-surface.mdx +++ b/docs/content/docs/api-surface.mdx @@ -180,6 +180,11 @@ 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` diff --git a/scripts/fixtures/negative/FormDataPrivate.res b/scripts/fixtures/negative/FormDataPrivate.res deleted file mode 100644 index a7d2e88d..00000000 --- a/scripts/fixtures/negative/FormDataPrivate.res +++ /dev/null @@ -1 +0,0 @@ -let fake: WebAPI.FormData.t = {} 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/negative-fixtures.json b/scripts/negative-fixtures.json index ec3920ab..9d0f418f 100644 --- a/scripts/negative-fixtures.json +++ b/scripts/negative-fixtures.json @@ -180,10 +180,10 @@ "expectedDiagnostic": "Cannot create values of the" }, { - "name": "FormDataPrivate", - "fixture": "scripts/fixtures/negative/FormDataPrivate.res", + "name": "FormDataRejectsString", + "fixture": "scripts/fixtures/negative/FormDataRejectsString.res", "features": ["WebAPI.FormData"], - "expectedDiagnostic": "Cannot create values of the" + "expectedDiagnostic": "This has type:" }, { "name": "TouchItemNullable", diff --git a/tests/browser/NarrowData__test.res b/tests/browser/NarrowData__test.res index a84f2ce3..bf6cbe59 100644 --- a/tests/browser/NarrowData__test.res +++ b/tests/browser/NarrowData__test.res @@ -1,8 +1,11 @@ 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" -assert(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