diff --git a/types/d3-random/d3-random-tests.ts b/types/d3-random/d3-random-tests.ts index 5b0586870833fe..c76d2a488b160f 100644 --- a/types/d3-random/d3-random-tests.ts +++ b/types/d3-random/d3-random-tests.ts @@ -141,7 +141,7 @@ let prngBinomial: d3Random.RandomBinomial; prngBinomial = d3Random.randomBinomial; prngBinomial = d3Random.randomBinomial.source(seedrandom("Schroedinger's flea.")); -randomNumberGenerator = prngBinomial(0.5); +randomNumberGenerator = prngBinomial(10, 0.5); // ------------------------------------------------------------ // randomGamma diff --git a/types/d3-random/index.d.ts b/types/d3-random/index.d.ts index 62eaf44b5c3daf..d91face6949f2a 100644 --- a/types/d3-random/index.d.ts +++ b/types/d3-random/index.d.ts @@ -191,12 +191,13 @@ export const randomGeometric: RandomGeometric; */ export interface RandomBinomial extends RandomNumberGenerationSource { /** - * Returns a function for generating numbers with a geometric distribution with success probability p. - * The value p is in the range (0, 1]. + * Returns a function for generating random numbers with a binomial distribution with n the number of trials and p the success probability. + * The value p is in the range [0, 1]. * + * @param n Number of trials * @param p Success probability */ - (p: number): () => number; + (n: number, p: number): () => number; } export const randomBinomial: RandomBinomial; diff --git a/types/jquery.fancytree/index.d.ts b/types/jquery.fancytree/index.d.ts index e0ea48732a2594..7239c715d5cc87 100644 --- a/types/jquery.fancytree/index.d.ts +++ b/types/jquery.fancytree/index.d.ts @@ -300,13 +300,19 @@ declare namespace Fancytree { /** Folder nodes have different default icons and click behavior. Note: Also non-folders may have children. */ folder: boolean; /** Icon of the tree node. */ - icon: string; + icon: boolean | GlyphIcon; + /** Description used as hover popup for the node's icon. @since 2.27 */ + iconTooltip: string; /** null or type of temporarily generated system node like 'loading', or 'error'. */ statusNodeType: string; /** True if this node is loaded on demand, i.e. on first expansion. */ lazy: boolean; + /** Use isSelected(), setSelected() to access this property. */ + selected: boolean; /** Alternative description used as hover banner */ tooltip: string; + /** Node type, used with the `tree.types` map. @since 2.27 */ + type: string; /** Outer element of single nodes */ span: HTMLElement; /** Outer element of single nodes for table extension */ @@ -606,14 +612,14 @@ declare namespace Fancytree { /** Move this node to targetNode. * * @param mode 'child': append this node as last child of targetNode. - * This is the default. To be compatble with the D'n'd - * hitMode, we also accept 'over'. + * This is the default (used when `mode` is omitted). To be + * compatble with the D'n'd hitMode, we also accept 'over'. * 'before': add this node as sibling before targetNode. * 'after': add this node as sibling after targetNode. * * @param map optional callback(FancytreeNode) to allow modifcations */ - moveTo(targetNode: FancytreeNode, mode: string, map?: (node: FancytreeNode) => void): void; + moveTo(targetNode: FancytreeNode, mode?: string, map?: (node: FancytreeNode) => void): void; /** Set focus relative to this node and optionally activate. * @@ -638,8 +644,8 @@ declare namespace Fancytree { */ removeClass(className: string): void; - /** Replace this paging node with source result. */ - replaceWith(source: NodeData | NodeData[]): JQueryPromise; + /** (experimental) Replace this node with `source`. (Currently only available for paging nodes.) */ + replaceWith(source: Exclude): JQueryPromise; /** This method renders and updates all HTML markup that is required to display this node in its current state. * @@ -984,8 +990,8 @@ declare namespace Fancytree { focusOnSelect?: boolean | undefined; /** Add `id="..."` to node markup (default: true). */ generateIds?: boolean | undefined; - /** Node icon url, if only filename, please use imagePath to set the path */ - icon?: boolean | string | undefined; + /** Node icon url, if only filename, please use imagePath to set the path. May also be a callback returning the icon. */ + icon?: boolean | GlyphIcon | ((event: JQueryEventObject, data: EventData) => boolean | GlyphIcon) | undefined; /** Prefix (default: "ft_") */ idPrefix?: string | undefined; /** Path to a folder containing icons (default: null, using 'skin/' subdirectory). */ @@ -1044,8 +1050,11 @@ declare namespace Fancytree { //////////////// // EXTENSIONS // //////////////// + /** @deprecated since v2.31, use `dnd5` instead. Legacy drag-and-drop, based on jQuery UI draggable/droppable. */ + dnd?: Extensions.DragAndDrop | undefined; dnd5?: Extensions.DragAndDrop5 | undefined; filter?: Extensions.Filter | undefined; + glyph?: Extensions.Glyph | undefined; table?: Extensions.Table | undefined; /** Options for misc extensions - see docs for typings */ @@ -1083,8 +1092,11 @@ declare namespace Fancytree { namespace Extensions { interface List { + /** @deprecated since v2.31, use `dnd5` instead. */ + dnd?: DragAndDrop | undefined; dnd5?: DragAndDrop5 | undefined; filter?: Filter | undefined; + glyph?: Glyph | undefined; table?: Table | undefined; [extension: string]: unknown; } @@ -1166,6 +1178,95 @@ declare namespace Fancytree { */ [key: string]: unknown; } + /** Drop position relative to the target node, used by the `dnd` and `dnd5` extensions. */ + type HitMode = "over" | "before" | "after"; + /** Event data passed to the legacy `dnd` extension callbacks. */ + interface DragAndDropEventData extends BaseEventData { + /** The other node, e.g. the drag source if this is a drop event. `null` in `dragStart`/`dragStop`. */ + otherNode: FancytreeNode | null; + /** Drop position relative to the target node. */ + hitMode?: HitMode | undefined; + /** The shared drop marker element used by the legacy dnd extension. */ + dropMarker?: JQuery | undefined; + /** The `ui` object of the underlying jQuery UI draggable event. */ + ui: JQueryUI.DraggableEventUIParams; + /** The jQuery UI draggable widget instance. */ + draggable: JQueryUI.Draggable; + } + /** Data passed to the legacy `dnd` extension `initHelper` callback. */ + interface InitHelperData { + node: FancytreeNode; + tree: Fancytree; + originalEvent: JQueryEventObject; + ui: { helper: JQuery }; + } + /** + * Define dnd-extension (legacy, jQuery UI based) options. + * @deprecated since v2.31, use the `dnd5` (native HTML5) extension instead. + */ + interface DragAndDrop { + /** Expand nodes after n milliseconds of hovering (default: 1000). */ + autoExpandMS?: number | undefined; + /** Additional options passed to jQuery `draggable()`. */ + draggable?: JQueryUI.DraggableOptions | undefined; + /** Additional options passed to jQuery `droppable()`. */ + droppable?: JQueryUI.DroppableOptions | undefined; + /** Focus, although draggable cancels mousedown event (default: false). */ + focusOnClick?: boolean | undefined; + /** Prevent dropping nodes 'before self', etc. (default: true). */ + preventVoidMoves?: boolean | undefined; + /** Prevent dropping nodes on own descendants (default: true). */ + preventRecursiveMoves?: boolean | undefined; + /** Set draggable.revert = true if drop was rejected (default: true). */ + smartRevert?: boolean | undefined; + /** Absolute position offset for .fancytree-drop-marker. */ + dropMarkerOffsetX?: number | undefined; + /** Additional offset for drop-marker with hitMode = "before"/"after". */ + dropMarkerInsertOffsetX?: number | undefined; + /** Callback(sourceNode, data); return `true` to enable dragging this node. */ + dragStart?: ((sourceNode: FancytreeNode, data: DragAndDropEventData) => boolean) | undefined; + /** Callback(sourceNode, data). */ + dragStop?: ((sourceNode: FancytreeNode, data: DragAndDropEventData) => void) | undefined; + /** Callback(sourceNode, data). */ + initHelper?: ((sourceNode: FancytreeNode, data: InitHelperData) => void) | undefined; + /** Callback(sourceNode, data). */ + updateHelper?: ((sourceNode: FancytreeNode, data: DragAndDropEventData) => void) | undefined; + /** + * Callback(targetNode, data); return `false` to reject the drop, `true` to allow all + * positions, or a hit mode / array of hit modes to allow only those. + */ + dragEnter?: + | ((targetNode: FancytreeNode, data: DragAndDropEventData) => boolean | HitMode | HitMode[]) + | undefined; + /** Callback(targetNode, data), return false to reject the drop. */ + // eslint-disable-next-line @typescript-eslint/no-invalid-void-type + dragOver?: ((targetNode: FancytreeNode, data: DragAndDropEventData) => boolean | void) | undefined; + /** Callback(targetNode, data), return false to prevent autoExpand. */ + // eslint-disable-next-line @typescript-eslint/no-invalid-void-type + dragExpand?: ((targetNode: FancytreeNode, data: DragAndDropEventData) => boolean | void) | undefined; + /** Callback(targetNode, data). */ + dragDrop?: ((targetNode: FancytreeNode, data: DragAndDropEventData) => void) | undefined; + /** Callback(targetNode, data). */ + dragLeave?: ((targetNode: FancytreeNode, data: DragAndDropEventData) => void) | undefined; + /** + * Support misc options + */ + [key: string]: unknown; + } + /** + * Define glyph-extension options. Maps logical icon names to CSS classes, + * e.g. for Font Awesome or Bootstrap icon sets. + */ + interface Glyph { + /** Icon set preset, e.g. "awesome3", "awesome4", "bootstrap3", or "material". */ + preset?: string | null | undefined; + /** Maps icon names (e.g. `expanderClosed`, `loading`, `checkbox`) to glyph definitions. */ + map?: Record | undefined; + /** + * Support misc options + */ + [key: string]: unknown; + } /** * Define filter-extension options */ @@ -1242,7 +1343,7 @@ declare namespace Fancytree { interface NodeData { /** node text (may contain HTML tags) */ title: string; - icon?: boolean | string | undefined; + icon?: boolean | GlyphIcon | undefined; /** unique key for this node (auto-generated if omitted) */ key?: string | undefined; /** (reserved) */ @@ -1263,7 +1364,7 @@ declare namespace Fancytree { /** class names added to the node markup (separate with space) */ extraClasses?: string | undefined; /** all properties from will be copied to `node.data` */ - data?: Object | undefined; + data?: Record | undefined; /** Will be added as title attribute of the node's icon span,thus enabling a tooltip. */ iconTooltip?: string | undefined; @@ -1281,6 +1382,14 @@ declare namespace Fancytree { unselectableStatus?: boolean | undefined; } + /** A glyph definition: a CSS class string or a `{ text | html, addClass }` object. */ + type GlyphIcon = + | string + | { text?: string | undefined; html?: string | undefined; addClass?: string | undefined }; + + /** A `glyph.map` entry: a glyph definition or a callback returning one. */ + type GlyphMapEntry = GlyphIcon | ((node: FancytreeNode, span: HTMLElement, type: string) => GlyphIcon); + /** Node data, or a descriptor of how to load it: inline data, a URL string, * `$.ajax` options (with a required `url`), or a promise resolving to node data. */ type SourceData = @@ -1372,6 +1481,12 @@ declare namespace Fancytree { /** Add Fancytree extension definition to the list of globally available extensions. */ registerExtension(definition: Object): void; + /** + * Set the expander, checkbox, or node icon HTML (used by extensions to render glyph icons). + * `icon` is either a CSS class string or an object describing the glyph. + */ + setSpanIcon(span: Element | JQuery, baseClass: string, icon: GlyphIcon): void; + unescapeHtml(s: string): string; warn(msg: string): void; diff --git a/types/jquery.fancytree/jquery.fancytree-tests.ts b/types/jquery.fancytree/jquery.fancytree-tests.ts index 9400b43d689bf0..717ec567d2e1b3 100644 --- a/types/jquery.fancytree/jquery.fancytree-tests.ts +++ b/types/jquery.fancytree/jquery.fancytree-tests.ts @@ -288,3 +288,81 @@ const sourceFromFunction: Fancytree.FancytreeOptions = { const sourceFromFunctionPromise: Fancytree.FancytreeOptions = { source: () => $.getJSON("/api/tree"), }; + +// `icon` option/NodeData also accepts a callback. +const iconCallback: Fancytree.FancytreeOptions = { + icon: (event, data) => (data.node.isFolder() ? false : { text: "folder", addClass: "material-icons" }), +}; +activeNode.addChildren({ title: "Static icon", icon: "my-icon" }); +activeNode.addChildren({ title: "Object icon", icon: { text: "description", addClass: "material-icons" } }); + +// Node-level documented properties. +const nodeSelected: boolean = activeNode.selected; +const nodeType: string = activeNode.type; +const nodeIconTooltip: string = activeNode.iconTooltip; +const nodeIcon: boolean | Fancytree.GlyphIcon = activeNode.icon; +console.log(nodeSelected, nodeType, nodeIconTooltip, nodeIcon); + +// replaceWith accepts inline data, `$.ajax` options, or a promise — but not a URL string. +if (node) { + node.replaceWith({ url: "/api/page", cache: false }); + node.replaceWith([{ title: "More" }]); + // @ts-expect-error -- plain URL strings are not supported + node.replaceWith("/api/page"); +} + +// FancytreeStatic.setSpanIcon +$.ui.fancytree.setSpanIcon(activeNode.span, "fancytree-icon", "my-glyph"); +$.ui.fancytree.setSpanIcon($(activeNode.span), "fancytree-icon", { text: "folder", addClass: "material-icons" }); + +// Legacy (jQuery UI based) `dnd` extension. +const dndOptions: Fancytree.FancytreeOptions = { + extensions: ["dnd"], + dnd: { + autoExpandMS: 400, + preventVoidMoves: true, + preventRecursiveMoves: true, + focusOnClick: false, + dragStart: (sourceNode, data) => { + console.log(sourceNode.title, data.otherNode, data.hitMode, data.ui.helper, data.draggable); + return true; + }, + initHelper: (sourceNode, data) => { + data.ui.helper.addClass("my-drag-helper"); + }, + dragEnter: (targetNode, data) => { + console.log(targetNode.key, data.otherNode?.key); + return ["over", "before"]; + }, + dragOver: (targetNode, data) => { + data.dropMarker?.toggleClass("is-active", true); + return data.otherNode !== null; + }, + dragDrop: (targetNode, data) => { + if (data.hitMode === "over") { + data.otherNode?.moveTo(targetNode); // mode is optional; defaults to "child" + } + }, + dragStop: (sourceNode, data) => { + console.log(sourceNode, data.tree); + }, + }, +}; +console.log(iconCallback, dndOptions); + +// `glyph` extension options. +const glyphOptions: Fancytree.FancytreeOptions = { + extensions: ["glyph"], + glyph: { + preset: "awesome4", + map: { + _addClass: "fa", + expanderClosed: "fa fa-caret-right", + expanderOpen: "fa fa-caret-down", + loading: { html: "" }, + checkbox: (glyphNode, span, type) => (glyphNode.isSelected() ? { text: "check_box" } : "fa-square-o"), + }, + }, +}; +const loadingGlyph: Fancytree.GlyphMapEntry = glyphOptions.glyph!.map!.loading; +console.log(glyphOptions, loadingGlyph); diff --git a/types/office-js-preview/index.d.ts b/types/office-js-preview/index.d.ts index cc6c449bec7251..e8909970408651 100644 --- a/types/office-js-preview/index.d.ts +++ b/types/office-js-preview/index.d.ts @@ -3329,10 +3329,8 @@ declare namespace Office { /** * Shows the task pane associated with the add-in. * @returns A promise that is resolved when the UI is shown. - * + * * @remarks - * This method applies only to centrally deployed or sideloaded add-ins. For add-ins published in the Microsoft Marketplace, the method is ignored and the task pane doesn't open. - * * **Requirement set**: {@link https://learn.microsoft.com/javascript/api/requirement-sets/common/shared-runtime-requirement-sets | SharedRuntime 1.1} */ showAsTaskpane(): Promise; @@ -13853,8 +13851,8 @@ declare namespace Office { * make it render efficiently with its rendering engine. This means that the value returned from a subsequent call to the `Body.getAsync` method * (introduced in Mailbox 1.3) won't necessarily contain the exact value that was passed in the previous `prependAsync` call. * - * - When including links in HTML markup, you can disable online link preview by setting the `id` attribute on the anchor (\) to "LPNoLP" - * (see the **Examples** section for a sample). + * - When including links in HTML markup, you can disable online link preview by setting the `id` attribute on the anchor (\) to "LPNoLP". + * For example, `'Click here!'`. * * - In Outlook on Android and on iOS, this method isn't supported in the Message Compose mode. Only the Appointment Organizer mode is * supported. For more information on supported APIs in Outlook mobile, see @@ -13903,8 +13901,8 @@ declare namespace Office { * make it render efficiently with its rendering engine. This means that the value returned from a subsequent call to the `Body.getAsync` method * (introduced in Mailbox 1.3) won't necessarily contain the exact value that was passed in the previous `prependAsync` call. * - * - When including links in HTML markup, you can disable online link preview by setting the `id` attribute on the anchor (\) to "LPNoLP" - * (see the **Examples** section for a sample). + * - When including links in HTML markup, you can disable online link preview by setting the `id` attribute on the anchor (\) to "LPNoLP". + * For example, `'Click here!'`. * * - In Outlook on Android and on iOS, this method isn't supported in the Message Compose mode. Only the Appointment Organizer mode is * supported. For more information on supported APIs in Outlook mobile, see @@ -14043,8 +14041,8 @@ declare namespace Office { * be the exact same value that was previously passed in the `Body.setAsync` method. The client may modify the value passed to `setAsync` to make it * render efficiently with its rendering engine. * - * - When including links in HTML markup, you can disable online link preview by setting the `id` attribute on the anchor (\) to "LPNoLP" - * (see the **Examples** section for a sample). + * - When including links in HTML markup, you can disable online link preview by setting the `id` attribute on the anchor (\) to "LPNoLP". + * For example, `'Click here!'`. * * - In Outlook on Windows (classic) and on Mac, the add-in user isn't able to revert this action with the **Undo** command. * @@ -14113,8 +14111,8 @@ declare namespace Office { * be the exact same value that was previously passed in the `Body.setAsync` method. The client may modify the value passed to `setAsync` to make it * render efficiently with its rendering engine. * - * - When including links in HTML markup, you can disable online link preview by setting the `id` attribute on the anchor (\) to "LPNoLP" - * (see the **Examples** section for a sample). + * - When including links in HTML markup, you can disable online link preview by setting the `id` attribute on the anchor (\) to "LPNoLP". + * For example, `'Click here!'`. * * - In Outlook on Windows (classic) and on Mac, the add-in user isn't able to revert this action with the **Undo** command. * @@ -14171,8 +14169,8 @@ declare namespace Office { * * **Important**: * - * - When including links in HTML markup, you can disable online link preview by setting the `id` attribute on the anchor (\) to "LPNoLP" - * (see the **Examples** section for a sample). + * - When including links in HTML markup, you can disable online link preview by setting the `id` attribute on the anchor (\) to "LPNoLP". + * For example, `'Click here!'`. * * - SVG files aren't supported. Use JPG or PNG files instead. * @@ -14213,8 +14211,8 @@ declare namespace Office { * * **Important**: * - * - When including links in HTML markup, you can disable online link preview by setting the `id` attribute on the anchor (\) to "LPNoLP" - * (see the **Examples** section for a sample). + * - When including links in HTML markup, you can disable online link preview by setting the `id` attribute on the anchor (\) to "LPNoLP". + * For example, `'Click here!'`. * * - SVG files aren't supported. Use JPG or PNG files instead. * diff --git a/types/office-js/index.d.ts b/types/office-js/index.d.ts index f3d752f69b7f8f..a5f7d566eaee5e 100644 --- a/types/office-js/index.d.ts +++ b/types/office-js/index.d.ts @@ -3329,10 +3329,8 @@ declare namespace Office { /** * Shows the task pane associated with the add-in. * @returns A promise that is resolved when the UI is shown. - * + * * @remarks - * This method applies only to centrally deployed or sideloaded add-ins. For add-ins published in the Microsoft Marketplace, the method is ignored and the task pane doesn't open. - * * **Requirement set**: {@link https://learn.microsoft.com/javascript/api/requirement-sets/common/shared-runtime-requirement-sets | SharedRuntime 1.1} */ showAsTaskpane(): Promise; @@ -13804,8 +13802,8 @@ declare namespace Office { * make it render efficiently with its rendering engine. This means that the value returned from a subsequent call to the `Body.getAsync` method * (introduced in Mailbox 1.3) won't necessarily contain the exact value that was passed in the previous `prependAsync` call. * - * - When including links in HTML markup, you can disable online link preview by setting the `id` attribute on the anchor (\) to "LPNoLP" - * (see the **Examples** section for a sample). + * - When including links in HTML markup, you can disable online link preview by setting the `id` attribute on the anchor (\) to "LPNoLP". + * For example, `'Click here!'`. * * - In Outlook on Android and on iOS, this method isn't supported in the Message Compose mode. Only the Appointment Organizer mode is * supported. For more information on supported APIs in Outlook mobile, see @@ -13854,8 +13852,8 @@ declare namespace Office { * make it render efficiently with its rendering engine. This means that the value returned from a subsequent call to the `Body.getAsync` method * (introduced in Mailbox 1.3) won't necessarily contain the exact value that was passed in the previous `prependAsync` call. * - * - When including links in HTML markup, you can disable online link preview by setting the `id` attribute on the anchor (\) to "LPNoLP" - * (see the **Examples** section for a sample). + * - When including links in HTML markup, you can disable online link preview by setting the `id` attribute on the anchor (\) to "LPNoLP". + * For example, `'Click here!'`. * * - In Outlook on Android and on iOS, this method isn't supported in the Message Compose mode. Only the Appointment Organizer mode is * supported. For more information on supported APIs in Outlook mobile, see @@ -13994,8 +13992,8 @@ declare namespace Office { * be the exact same value that was previously passed in the `Body.setAsync` method. The client may modify the value passed to `setAsync` to make it * render efficiently with its rendering engine. * - * - When including links in HTML markup, you can disable online link preview by setting the `id` attribute on the anchor (\) to "LPNoLP" - * (see the **Examples** section for a sample). + * - When including links in HTML markup, you can disable online link preview by setting the `id` attribute on the anchor (\) to "LPNoLP". + * For example, `'Click here!'`. * * - In Outlook on Windows (classic) and on Mac, the add-in user isn't able to revert this action with the **Undo** command. * @@ -14064,8 +14062,8 @@ declare namespace Office { * be the exact same value that was previously passed in the `Body.setAsync` method. The client may modify the value passed to `setAsync` to make it * render efficiently with its rendering engine. * - * - When including links in HTML markup, you can disable online link preview by setting the `id` attribute on the anchor (\) to "LPNoLP" - * (see the **Examples** section for a sample). + * - When including links in HTML markup, you can disable online link preview by setting the `id` attribute on the anchor (\) to "LPNoLP". + * For example, `'Click here!'`. * * - In Outlook on Windows (classic) and on Mac, the add-in user isn't able to revert this action with the **Undo** command. * @@ -14122,8 +14120,8 @@ declare namespace Office { * * **Important*: * - * - When including links in HTML markup, you can disable online link preview by setting the `id` attribute on the anchor (\) to "LPNoLP" - * (see the **Examples** section for a sample). + * - When including links in HTML markup, you can disable online link preview by setting the `id` attribute on the anchor (\) to "LPNoLP". + * For example, `'Click here!'`. * * - SVG files aren't supported. Use JPG or PNG files instead. * @@ -14164,8 +14162,8 @@ declare namespace Office { * * **Important*: * - * - When including links in HTML markup, you can disable online link preview by setting the `id` attribute on the anchor (\) to "LPNoLP" - * (see the **Examples** section for a sample). + * - When including links in HTML markup, you can disable online link preview by setting the `id` attribute on the anchor (\) to "LPNoLP". + * For example, `'Click here!'`. * * - SVG files aren't supported. Use JPG or PNG files instead. * diff --git a/types/wicg-cross-origin-storage/.npmignore b/types/wicg-cross-origin-storage/.npmignore new file mode 100644 index 00000000000000..93e307400a5456 --- /dev/null +++ b/types/wicg-cross-origin-storage/.npmignore @@ -0,0 +1,5 @@ +* +!**/*.d.ts +!**/*.d.cts +!**/*.d.mts +!**/*.d.*.ts diff --git a/types/wicg-cross-origin-storage/index.d.ts b/types/wicg-cross-origin-storage/index.d.ts new file mode 100644 index 00000000000000..7a559b09749218 --- /dev/null +++ b/types/wicg-cross-origin-storage/index.d.ts @@ -0,0 +1,38 @@ +export {}; + +declare global { + /** + * Represents the dictionary for hash algorithm and value. + */ + interface CrossOriginStorageRequestFileHandleHash { + value: string; + algorithm: string; + } + + /** + * Represents the options for requesting a file handle. + */ + interface CrossOriginStorageRequestFileHandleOptions { + create?: boolean | undefined; + origins?: string[] | string | undefined; + } + + /** + * The CrossOriginStorageManager interface. + * [SecureContext] + */ + interface CrossOriginStorageManager { + requestFileHandle( + hash: CrossOriginStorageRequestFileHandleHash, + options?: CrossOriginStorageRequestFileHandleOptions, + ): Promise; + } + + interface Navigator { + readonly crossOriginStorage: CrossOriginStorageManager; + } + + interface WorkerNavigator { + readonly crossOriginStorage: CrossOriginStorageManager; + } +} diff --git a/types/wicg-cross-origin-storage/package.json b/types/wicg-cross-origin-storage/package.json new file mode 100644 index 00000000000000..b2ab49a53a60bd --- /dev/null +++ b/types/wicg-cross-origin-storage/package.json @@ -0,0 +1,23 @@ +{ + "private": true, + "name": "@types/wicg-cross-origin-storage", + "version": "2026.7.9999", + "nonNpm": true, + "nonNpmDescription": "Cross-Origin Storage", + "projects": [ + "https://github.com/WICG/cross-origin-storage" + ], + "devDependencies": { + "@types/wicg-cross-origin-storage": "workspace:." + }, + "owners": [ + { + "name": "Thomas Steiner", + "githubUsername": "tomayac" + }, + { + "name": "Christian Liebel", + "githubUsername": "christianliebel" + } + ] +} diff --git a/types/wicg-cross-origin-storage/tsconfig.json b/types/wicg-cross-origin-storage/tsconfig.json new file mode 100644 index 00000000000000..8a13197599ca4b --- /dev/null +++ b/types/wicg-cross-origin-storage/tsconfig.json @@ -0,0 +1,20 @@ +{ + "compilerOptions": { + "module": "node16", + "lib": [ + "es6", + "dom" + ], + "noImplicitAny": true, + "noImplicitThis": true, + "strictNullChecks": true, + "strictFunctionTypes": true, + "types": [], + "noEmit": true, + "forceConsistentCasingInFileNames": true + }, + "files": [ + "index.d.ts", + "wicg-cross-origin-storage-tests.ts" + ] +} diff --git a/types/wicg-cross-origin-storage/wicg-cross-origin-storage-tests.ts b/types/wicg-cross-origin-storage/wicg-cross-origin-storage-tests.ts new file mode 100644 index 00000000000000..6ac7f53ab409e2 --- /dev/null +++ b/types/wicg-cross-origin-storage/wicg-cross-origin-storage-tests.ts @@ -0,0 +1,30 @@ +const hash: CrossOriginStorageRequestFileHandleHash = { + algorithm: "SHA-256", + value: "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", +}; + +async function testLookup() { + const handle: FileSystemFileHandle = await navigator.crossOriginStorage.requestFileHandle(hash); + const file: File = await handle.getFile(); +} + +async function testCreate() { + const handle: FileSystemFileHandle = await navigator.crossOriginStorage.requestFileHandle(hash, { + create: true, + }); + const writable = await handle.createWritable(); + await writable.write(new Blob(["export default 1;"], { type: "text/javascript" })); + await writable.close(); +} + +async function testCreateWithOrigins() { + await navigator.crossOriginStorage.requestFileHandle(hash, { create: true, origins: "*" }); + await navigator.crossOriginStorage.requestFileHandle(hash, { + create: true, + origins: ["https://example.com", "https://example.org"], + }); +} + +async function testWorkerNavigator(workerNavigator: WorkerNavigator) { + const handle: FileSystemFileHandle = await workerNavigator.crossOriginStorage.requestFileHandle(hash); +}