From 460022f1e5f370aa03cd87d91df41493db00db82 Mon Sep 17 00:00:00 2001 From: Kevin Moore Date: Tue, 25 Feb 2025 15:33:47 -0800 Subject: [PATCH] Delete all deprecated members --- web/CHANGELOG.md | 1 + web/lib/helpers.dart | 8 - web/lib/src/helpers.dart | 73 ------- web/lib/src/helpers/events/streams.dart | 4 +- web/lib/src/helpers/extensions.dart | 32 --- web/lib/src/helpers/http.dart | 259 ------------------------ web/lib/src/helpers/renames.dart | 49 ----- 7 files changed, 3 insertions(+), 423 deletions(-) delete mode 100644 web/lib/helpers.dart delete mode 100644 web/lib/src/helpers/http.dart delete mode 100644 web/lib/src/helpers/renames.dart diff --git a/web/CHANGELOG.md b/web/CHANGELOG.md index 6bb16bca..66bfb9fb 100644 --- a/web/CHANGELOG.md +++ b/web/CHANGELOG.md @@ -4,6 +4,7 @@ - Removed renames `UnderlyingSource` and `UnderlyingSourceBase` where the types don't exist. - Fixed generation of variadic arguments to generate 4 optional parameters. +- Removed all `@Deprecated` members. ## 1.1.0 diff --git a/web/lib/helpers.dart b/web/lib/helpers.dart deleted file mode 100644 index fc24d4e3..00000000 --- a/web/lib/helpers.dart +++ /dev/null @@ -1,8 +0,0 @@ -// Copyright (c) 2023, the Dart project authors. Please see the AUTHORS file -// for details. All rights reserved. Use of this source code is governed by a -// BSD-style license that can be found in the LICENSE file. - -@Deprecated('See instead package:web/web.dart.') -library; - -export 'web.dart'; diff --git a/web/lib/src/helpers.dart b/web/lib/src/helpers.dart index caaf4f46..ecb0f1d9 100644 --- a/web/lib/src/helpers.dart +++ b/web/lib/src/helpers.dart @@ -21,83 +21,10 @@ /// whether to consume some of the APIs provided here. library; -import 'dart:js_interop'; -import 'dart:js_interop_unsafe'; - -import 'dom.dart'; -import 'helpers/lists.dart'; - export 'helpers/cross_origin.dart' show CrossOriginLocation, CrossOriginWindow; export 'helpers/enums.dart'; export 'helpers/events/events.dart'; export 'helpers/events/providers.dart'; export 'helpers/events/streams.dart' show ElementStream, EventStreamProvider; export 'helpers/extensions.dart'; -export 'helpers/http.dart'; export 'helpers/lists.dart'; -export 'helpers/renames.dart'; - -/// Create an [HTMLElement] with the specified [tagName]. -/// If no element with [tagName] exists, returns an [HTMLUnknownElement]. -/// -/// Deprecated in favor of creating the element like other HTML elements: -/// -/// ```dart -/// final anchor = document.createElement('a') as HTMLElement; -/// ``` -@Deprecated('Use the specific HTMLElement constructor instead.') -HTMLElement createElementTag(String tagName) => - document.createElement(tagName) as HTMLElement; - -/// Create an [HTMLCanvasElement] in the current [document]. -/// -/// Deprecated in favor of creating the element like other HTML elements: -/// -/// ```dart -/// final canvas = document.createElement('canvas') as HTMLCanvasElement -/// ..width = 256 -/// ..height = 256; -/// ``` -@Deprecated('Use the HTMLCanvasElement constructor instead.') -HTMLCanvasElement createCanvasElement({int? width, int? height}) { - final result = document.createElement('canvas') as HTMLCanvasElement; - if (width != null) result.width = width; - if (height != null) result.height = height; - return result; -} - -/// Create an [HTMLIFrameElement] in the current [document]. -/// -/// Deprecated in favor of creating the element like other HTML elements: -/// -/// ```dart -/// final embed = document.createElement('iframe') as HTMLIFrameElement; -/// ``` -@Deprecated('Use the HTMLIFrameElement constructor instead.') -HTMLIFrameElement createIFrameElement() => - document.createElement('iframe') as HTMLIFrameElement; - -@JS('Audio') -external JSFunction get _audioConstructor; -// While `new Audio()` is a different syntax from -// `document.createElement('audio')`, it looks like they're the same: -// https://developer.mozilla.org/en-US/docs/Web/API/HTMLAudioElement/Audio#usage_notes -@Deprecated('Use the HTMLAudioElement constructor instead.') -HTMLAudioElement createAudioElement() => _audioConstructor.callAsConstructor(); - -/// Finds and returns the first element within the [document] -/// that matches the specified CSS [selector] string. -/// If no match is found, `null` is returned. -/// -/// Deprecated in favor of querying directly on the [document]: -/// -/// ```dart -/// final dartDiv = document.querySelector('div.dart'); -/// ``` -@Deprecated('Directly use document.querySelector instead.') -Element? querySelector(String selector) => document.querySelector(selector); - -@Deprecated('Use JSImmutableListWrapper instead.') -class TouchListWrapper extends JSImmutableListWrapper { - TouchListWrapper(super._original); -} diff --git a/web/lib/src/helpers/events/streams.dart b/web/lib/src/helpers/events/streams.dart index 266a49de..060ea482 100644 --- a/web/lib/src/helpers/events/streams.dart +++ b/web/lib/src/helpers/events/streams.dart @@ -176,9 +176,9 @@ class _EventStreamSubscription // `dart:html` it would have printed 1, 2, 4, 3 // // ```dart - // import 'package:web/helpers.dart'; + // import 'package:web/web.dart'; // - // main() { + // void main() { // print('1'); // final body = document.body!; // body.onTouchStart.first.whenComplete(() { diff --git a/web/lib/src/helpers/extensions.dart b/web/lib/src/helpers/extensions.dart index bdcfc20b..8fc1157f 100644 --- a/web/lib/src/helpers/extensions.dart +++ b/web/lib/src/helpers/extensions.dart @@ -23,10 +23,8 @@ library; import 'dart:convert'; import 'dart:js_interop'; -import 'dart:math' show Point; import '../dom.dart'; -import 'lists.dart'; export 'cross_origin.dart' show CrossOriginContentWindowExtension, CrossOriginWindowExtension; @@ -71,30 +69,6 @@ extension CanvasRenderingContext2DGlue on CanvasRenderingContext2D { extension NodeGlue on Node { set text(String s) => textContent = s; - @Deprecated('See Node.appendChild()') - Node append(Node other) => appendChild(other); - @Deprecated('See Node.cloneNode()') - Node clone(bool? deep) => cloneNode(deep ?? false); -} - -extension EventGlue on MouseEvent { - /// A [Point] representation of the [clientX] and [clientY] properties - /// of this [MouseEvent]. - /// - /// **Deprecated:** Prefer directly accessing - /// the [clientX] and [clientY] properties on [MouseEvent]. - @Deprecated('Instead directly access the clientX and clientY properties.') - Point get client => Point(clientX, clientY); -} - -extension TouchGlue on Touch { - /// A [Point] representation of the [clientX] and [clientY] properties - /// of this [Touch] event. - /// - /// **Deprecated:** Prefer directly accessing - /// the [clientX] and [clientY] properties on [Touch]. - @Deprecated('Instead directly access the clientX and clientY properties.') - Point get client => Point(clientX, clientY); } extension StorageGlue on Storage { @@ -102,12 +76,6 @@ extension StorageGlue on Storage { void operator []=(String key, String value) => setItem(key, value); } -@Deprecated('Use JSImmutableListWrapper instead.') -extension TouchListConvert on TouchList { - @Deprecated('Use JSImmutableListWrapper directly instead.') - List toList() => JSImmutableListWrapper(this); -} - extension XMLHttpRequestGlue on XMLHttpRequest { /// Returns all response headers as a key-value map. /// diff --git a/web/lib/src/helpers/http.dart b/web/lib/src/helpers/http.dart deleted file mode 100644 index 2a93d033..00000000 --- a/web/lib/src/helpers/http.dart +++ /dev/null @@ -1,259 +0,0 @@ -// Copyright (c) 2023, the Dart project authors. Please see the AUTHORS file -// for details. All rights reserved. Use of this source code is governed by a -// BSD-style license that can be found in the LICENSE file. - -import 'dart:async'; -import 'dart:js_interop'; -import 'dart:typed_data'; - -import '../dom.dart'; -import 'events/events.dart' show XHRGetters; - -/// > [!WARNING] -/// > This class is deprecated and will be -/// > removed in a future release of `package:web`. -/// > -/// > You should instead use the cross-platform -/// > [`package:http`](https://pub.dev/packages/http) and its -/// > [`BrowserClient`](https://pub.dev/documentation/http/latest/browser_client/BrowserClient-class.html) -/// > adapter on top of [XMLHttpRequest]. -/// -/// A helper used to make it easier to operate over [XMLHttpRequest]s. -/// -/// The logic here was copied from `dart:html` to help bridge a functionality -/// gap missing in `package:web`. -/// -/// HttpRequest can be used to obtain data from HTTP and FTP protocols, -/// and is useful for AJAX-style page updates. -/// -/// The simplest way to get the contents of a text file, such as a -/// JSON-formatted file, is with [getString]. -/// For example, the following code gets the contents of a JSON file -/// and prints its length: -/// -/// var path = 'myData.json'; -/// HttpRequest.getString(path).then((String fileContents) { -/// print(fileContents.length); -/// }).catchError((error) { -/// print(error.toString()); -/// }); -/// -/// ## Fetching data from other servers -/// -/// For security reasons, browsers impose restrictions on requests -/// made by embedded apps. -/// With the default behavior of this class, -/// the code making the request must be served from the same origin -/// (domain name, port, and application layer protocol) -/// as the requested resource. -/// In the example above, the myData.json file must be co-located with the -/// app that uses it. -/// -/// ## Other resources -/// -/// * [Fetch data dynamically](https://dart.dev/tutorials/web/fetch-data/), -/// a tutorial shows how to load data from a static file or from a server. -/// * [JS XMLHttpRequest](https://developer.mozilla.org/en-US/docs/Web/API/XMLHttpRequest) -/// * [Using XMLHttpRequest](https://developer.mozilla.org/en-US/docs/Web/API/XMLHttpRequest_API/Using_XMLHttpRequest) -@Deprecated('Instead use package:http.') -class HttpRequest { - // The lint is ignored because these are purposely made to match the old - // names used in `dart:html` - // ignore:constant_identifier_names - static const int DONE = 4; - // ignore:constant_identifier_names - static const int HEADERS_RECEIVED = 2; - // ignore:constant_identifier_names - static const int LOADING = 3; - // ignore:constant_identifier_names - static const int OPENED = 1; - // ignore:constant_identifier_names - static const int UNSENT = 0; - - /// Creates a GET request for the specified [url]. - /// - /// This is similar to [request] but specialized for HTTP GET requests which - /// return text content. - /// - /// To add query parameters, append them to the [url] following a `?`, joining - /// each key to its value with `=` and separating key-value pairs with `&`. - /// - /// var name = Uri.encodeQueryComponent('John'); - /// var id = Uri.encodeQueryComponent('42'); - /// HttpRequest.getString('users.json?name=$name&id=$id') - /// .then((String resp) { - /// // Do something with the response. - /// }); - /// - /// See also [request]. - static Future getString(String url, - {bool? withCredentials, void Function(ProgressEvent)? onProgress}) => - request(url, withCredentials: withCredentials, onProgress: onProgress) - .then((r) => r.responseText); - - /// Makes a server POST request with the specified data encoded as form data. - /// - /// This is roughly the POST equivalent of [getString]. This method is similar - /// to sending a [FormData] object with broader browser support but limited to - /// String values. - /// - /// If [data] is supplied, the key/value pairs are URI encoded with - /// [Uri.encodeQueryComponent] and converted into an HTTP query string. - /// - /// Unless otherwise specified, this method appends the following header: - /// - /// Content-Type: application/x-www-form-urlencoded; charset=UTF-8 - /// - /// Here's an example of using this method: - /// - /// var data = { 'firstName' : 'John', 'lastName' : 'Doe' }; - /// HttpRequest.postFormData('/send', data).then((HttpRequest resp) { - /// // Do something with the response. - /// }); - /// - /// See also [request]. - static Future postFormData( - String url, Map data, - {bool? withCredentials, - String? responseType, - Map? requestHeaders, - void Function(ProgressEvent)? onProgress}) { - final parts = []; - data.forEach((key, value) { - parts.add('${Uri.encodeQueryComponent(key)}=' - '${Uri.encodeQueryComponent(value)}'); - }); - final formData = parts.join('&'); - requestHeaders ??= {}; - requestHeaders.putIfAbsent('Content-Type', - () => 'application/x-www-form-urlencoded; charset=UTF-8'); - - return request(url, - method: 'POST', - withCredentials: withCredentials, - responseType: responseType, - requestHeaders: requestHeaders, - sendData: formData, - onProgress: onProgress); - } - - /// Creates and sends a URL request for the specified [url]. - /// - /// By default `request` will perform an HTTP GET request, but a different - /// method (`POST`, `PUT`, `DELETE`, etc) can be used by specifying the - /// [method] parameter. (See also [HttpRequest.postFormData] for `POST` - /// requests only. - /// - /// The Future is completed when the response is available. - /// - /// If specified, `sendData` will send data in the form of a [ByteBuffer], - /// [Blob], [Document], [String], or [FormData] along with the HttpRequest. - /// - /// If specified, [responseType] sets the desired response format for the - /// request. By default it is [String], but can also be 'arraybuffer', 'blob', - /// 'document', 'json', or 'text'. - /// for more information. - /// - /// The [withCredentials] parameter specified that credentials such as a - /// cookie (already) set in the header or - /// [authorization headers](http://tools.ietf.org/html/rfc1945#section-10.2) - /// should be specified for the request. Details to keep in mind when using - /// credentials: - /// - /// * Using credentials is only useful for cross-origin requests. - /// * The `Access-Control-Allow-Origin` header of `url` cannot contain a - /// wildcard (*). - /// * The `Access-Control-Allow-Credentials` header of `url` must be set to - /// true. - /// * If `Access-Control-Expose-Headers` has not been set to true, only a - /// subset of all the response headers will be returned when calling - /// `getAllResponseHeaders`. - /// - /// The following is equivalent to the [getString] sample above: - /// - /// var name = Uri.encodeQueryComponent('John'); - /// var id = Uri.encodeQueryComponent('42'); - /// HttpRequest.request('users.json?name=$name&id=$id') - /// .then((HttpRequest resp) { - /// // Do something with the response. - /// }); - /// - /// Here's an example of submitting an entire form with [FormData]. - /// - /// var myForm = querySelector('form#myForm'); - /// var data = new FormData(myForm); - /// HttpRequest.request('/submit', method: 'POST', sendData: data) - /// .then((HttpRequest resp) { - /// // Do something with the response. - /// }); - /// - /// Note that requests for file:// URIs are only supported by Chrome - /// extensions with appropriate permissions in their manifest. Requests to - /// file:// URIs will also never fail- the Future will always complete - /// successfully, even when the file cannot be found. - /// - /// See also: [authorization headers][1]. - /// - /// [1]: http://en.wikipedia.org/wiki/Basic_access_authentication - static Future request(String url, - {String? method, - bool? withCredentials, - String? responseType, - String? mimeType, - Map? requestHeaders, - Object? sendData, - void Function(ProgressEvent)? onProgress}) { - final completer = Completer(); - final xhr = XMLHttpRequest(); - method ??= 'GET'; - xhr.open(method, url, true); - - if (withCredentials != null) { - xhr.withCredentials = withCredentials; - } - - if (responseType != null) { - xhr.responseType = responseType; - } - - if (mimeType != null) { - xhr.overrideMimeType(mimeType); - } - - // ignore: unnecessary_lambdas - requestHeaders?.forEach((a, b) => xhr.setRequestHeader(a, b)); - - if (onProgress != null) { - xhr.onProgress.listen(onProgress); - } - - xhr.onLoad.listen((ProgressEvent e) { - final status = xhr.status; - final accepted = status >= 200 && status < 300; - final fileUri = status == 0; // file:// URIs have status of 0. - final notModified = status == 304; - // Redirect status is specified up to 307, but others have been used in - // practice. Notably Google Drive uses 308 Resume Incomplete for - // resumable uploads, and it's also been used as a redirect. The - // redirect case will be handled by the browser before it gets to us, - // so if we see it we should pass it through to the user. - final unknownRedirect = status > 307 && status < 400; - - if (accepted || fileUri || notModified || unknownRedirect) { - completer.complete(xhr); - } else { - completer.completeError(e); - } - }); - - xhr.onError.listen(completer.completeError); - - if (sendData != null) { - xhr.send(sendData is String ? sendData.toJS : sendData.jsify()); - } else { - xhr.send(); - } - - return completer.future; - } -} diff --git a/web/lib/src/helpers/renames.dart b/web/lib/src/helpers/renames.dart deleted file mode 100644 index 84b2c0f2..00000000 --- a/web/lib/src/helpers/renames.dart +++ /dev/null @@ -1,49 +0,0 @@ -// Copyright (c) 2023, the Dart project authors. Please see the AUTHORS file -// for details. All rights reserved. Use of this source code is governed by a -// BSD-style license that can be found in the LICENSE file. - -/// Helper layer that exposes some `package:web` types using their legacy -/// `dart:html` type names. -library; - -import '../../web.dart'; - -/// All usages of this type alias should be updated to -/// the more consistent [HTMLAudioElement]. -@Deprecated('Use HTMLAudioElement instead.') -typedef AudioElement = HTMLAudioElement; - -/// All usages of this type alias should be updated to -/// the more consistent [HTMLElement]. -@Deprecated('Use HTMLElement instead.') -typedef HtmlElement = HTMLElement; - -/// All usages of this type alias should be updated to -/// the more consistent [HTMLCanvasElement]. -@Deprecated('Use HTMLCanvasElement instead.') -typedef CanvasElement = HTMLCanvasElement; - -/// All usages of this type alias should be updated to -/// the more consistent [HTMLImageElement]. -@Deprecated('Use HTMLImageElement instead.') -typedef ImageElement = HTMLImageElement; - -/// All usages of this type alias should be updated to -/// the more consistent [HTMLVideoElement]. -@Deprecated('Use HTMLVideoElement instead.') -typedef VideoElement = HTMLVideoElement; - -/// All usages of this type alias should be updated to -/// the more consistent [CSSStyleDeclaration]. -@Deprecated('Use CSSStyleDeclaration instead.') -typedef CssStyleDeclaration = CSSStyleDeclaration; - -/// All usages of this type alias should be updated to -/// the more consistent [WebGLContextEvent]. -@Deprecated('Use WebGLContextEvent instead.') -typedef ContextEvent = WebGLContextEvent; - -/// All usages of this type alias should be updated to -/// the more consistent [WebGLRenderingContext]. -@Deprecated('Use WebGLRenderingContext instead.') -typedef WebGL = WebGLRenderingContext;