diff --git a/build.sbt b/build.sbt index 9ab4a0f3..e882ba20 100644 --- a/build.sbt +++ b/build.sbt @@ -91,7 +91,7 @@ lazy val V = new { val munit = "1.0.0-M8" // "0.7.29" // https://mvnrepository.com/artifact/org.scala-js/scalajs-dom - val scalajsDom = "2.6.0" + val scalajsDom = "2.8.0" // val scalajsLogging = "1.1.2-SNAPSHOT" //"1.1.2" // https://mvnrepository.com/artifact/dev.zio/zio diff --git a/webapp/src/main/scala/fmgp/webapp/SandboxSettings.scala b/webapp/src/main/scala/fmgp/webapp/SandboxSettings.scala index ab2c4b8d..fa994c1f 100644 --- a/webapp/src/main/scala/fmgp/webapp/SandboxSettings.scala +++ b/webapp/src/main/scala/fmgp/webapp/SandboxSettings.scala @@ -15,7 +15,7 @@ object SandboxSettings { button( "Register URL protocol handler: web", onClick --> { _ => - val n = dom.window.navigator.asInstanceOf[dom.NavigatorProtocolHandler] + val n = dom.window.navigator n.registerProtocolHandler("did", "#/resolver/%s") println("""registerProtocolHandler("did", "#/resolver/%s")""") }, @@ -23,7 +23,7 @@ object SandboxSettings { button( "Unregister URL protocol handler: web", onClick --> { _ => - val n = dom.window.navigator.asInstanceOf[dom.NavigatorProtocolHandler] + val n = dom.window.navigator n.unregisterProtocolHandler("did", "#/resolver/%s") println("""unregisterProtocolHandler("did", "#/resolver/%s")""") }, @@ -41,7 +41,7 @@ object SandboxSettings { button( "Register URL protocol handler: web+did", onClick --> { _ => - val n = dom.window.navigator.asInstanceOf[dom.NavigatorProtocolHandler] + val n = dom.window.navigator n.registerProtocolHandler("web+did", "#/resolver/%s") println("""registerProtocolHandler("web+did", "#/resolver/%s")""") }, @@ -49,7 +49,7 @@ object SandboxSettings { button( "Unregister URL protocol handler: web+did", onClick --> { _ => - val n = dom.window.navigator.asInstanceOf[dom.NavigatorProtocolHandler] + val n = dom.window.navigator n.unregisterProtocolHandler("web+did", "#/resolver/%s") println("""unregisterProtocolHandler("web+did", "#/resolver/%s")""") }, diff --git a/webapp/src/main/scala/org/scalajs/dom/NDEFMessage.scala b/webapp/src/main/scala/org/scalajs/dom/NDEFMessage.scala index 1f3e2a8d..b2add223 100644 --- a/webapp/src/main/scala/org/scalajs/dom/NDEFMessage.scala +++ b/webapp/src/main/scala/org/scalajs/dom/NDEFMessage.scala @@ -7,13 +7,16 @@ import scala.scalajs.js.annotation.JSGlobal * or could be written to an NFC tag. An instance is acquired by calling the NDEFMessage() constructor or from the * NDEFReadingEvent.message property, which is passed to the reading event. * - * @param records - * The records property of NDEFMessage interface represents a list of NDEFRecords present in the NDEF message. + * @see + * https://w3c.github.io/web-nfc/#the-ndefmessage-interface + * + * @param messageInit + * property of NDEFMessage interface represents a list of NDEFRecords present in the NDEF message. */ @js.native @JSGlobal -class NDEFMessage extends js.Object { +class NDEFMessage(messageInit: js.Array[NDEFRecordInit]) extends js.Object { /** Returns the list of NDEF records contained in the message. */ - var records: FrozenArray[NDEFRecord] = js.native + def records: FrozenArray[NDEFRecord] = js.native } diff --git a/webapp/src/main/scala/org/scalajs/dom/NDEFReader.scala b/webapp/src/main/scala/org/scalajs/dom/NDEFReader.scala index 99bccdf5..d13ae5f2 100644 --- a/webapp/src/main/scala/org/scalajs/dom/NDEFReader.scala +++ b/webapp/src/main/scala/org/scalajs/dom/NDEFReader.scala @@ -6,6 +6,9 @@ import scala.scalajs.js.annotation.JSGlobal /** The [[NDEFReader]] interface of the Web NFC API (https://developer.mozilla.org/en-US/docs/Web/API/Web_NFC_API) is * used to read from and write data to compatible NFC devices, e.g. NFC tags supporting NDEF, when these devices are * within the reader's magnetic induction field. + * + * @see + * https://w3c.github.io/web-nfc/#the-ndefreader-object */ @JSGlobal("NDEFReader") @js.native @@ -36,7 +39,9 @@ class NDEFReader() extends EventTarget { */ def write(message: String, options: NDEFWriteOptions): js.Promise[Unit] = js.native def write(message: js.typedarray.ArrayBuffer, options: NDEFWriteOptions): js.Promise[Unit] = js.native - // def write(message:js.typedarray.TypedArray[NDEFRecord, ???] , options: NDEFWriteOptions = js.native): js.Promise[Unit] = js.native + + def write(message: js.typedarray.TypedArray[_, _], + options: NDEFWriteOptions = js.native): js.Promise[Unit] = js.native def write(message: js.typedarray.DataView, options: NDEFWriteOptions): js.Promise[Unit] = js.native def write(message: js.Array[NDEFRecord], options: NDEFWriteOptions): js.Promise[Unit] = js.native diff --git a/webapp/src/main/scala/org/scalajs/dom/NDEFReadingEvent.scala b/webapp/src/main/scala/org/scalajs/dom/NDEFReadingEvent.scala index 3bc402a9..bb2aaa28 100644 --- a/webapp/src/main/scala/org/scalajs/dom/NDEFReadingEvent.scala +++ b/webapp/src/main/scala/org/scalajs/dom/NDEFReadingEvent.scala @@ -1,22 +1,25 @@ package org.scalajs.dom import scala.scalajs.js +import scala.scalajs.js.annotation.JSGlobal /** The NDEFReadingEvent interface of the Web NFC API represents events dispatched on new NFC readings obtained by * NDEFReader. * * @see * https://developer.mozilla.org/en-US/docs/Web/API/NDEFReadingEvent + * @see + * https://w3c.github.io/web-nfc/#the-ndefreader-object */ @js.native -trait NDEFReadingEvent extends Event { +@JSGlobal +class NDEFReadingEvent(typeArg: String, init: NDEFReadingEventInit) extends Event(typeArg, init) { /** Returns an NDEFMessage object containing the received message. */ - var message: NDEFMessage = js.native + def message: NDEFMessage = js.native /** Returns the serial number of the device, which is used for anti-collision and identification, or an empty string * if no serial number is available. */ - var serialNumber: String = js.native - + def serialNumber: String = js.native } diff --git a/webapp/src/main/scala/org/scalajs/dom/NDEFReadingEventInit.scala b/webapp/src/main/scala/org/scalajs/dom/NDEFReadingEventInit.scala new file mode 100644 index 00000000..b6b5364f --- /dev/null +++ b/webapp/src/main/scala/org/scalajs/dom/NDEFReadingEventInit.scala @@ -0,0 +1,24 @@ +package org.scalajs.dom + +import scala.scalajs.js + +/** NDEFReadingEventInit is used to initialize a new event with a serial number and the NDEFMessageInit data via the + * message member. If serialNumber is not present or is null, empty string will be used to init the event. + * + * @see + * https://developer.mozilla.org/en-US/docs/Web/API/NDEFReadingEvent/NDEFReadingEvent#parameters + * @see + * https://w3c.github.io/web-nfc/#the-ndefreader-object + */ +trait NDEFReadingEventInit extends EventInit { + + /** A string with the name of the event. It is case-sensitive and browsers always set it to reading. Default is "" an + * empty string + */ + var serialNumber: js.UndefOr[AbortSignal] = js.undefined + + /** An object that, in addition of the properties defined in Event(), can have the following properties: serialNumber; + * message + */ + var message: NDEFRecordInit +} diff --git a/webapp/src/main/scala/org/scalajs/dom/NDEFRecord.scala b/webapp/src/main/scala/org/scalajs/dom/NDEFRecord.scala index 63702642..0e0aead4 100644 --- a/webapp/src/main/scala/org/scalajs/dom/NDEFRecord.scala +++ b/webapp/src/main/scala/org/scalajs/dom/NDEFRecord.scala @@ -5,37 +5,40 @@ import scala.scalajs.js.annotation.JSGlobal /** The [[NDEFRecord]] interface of the Web NFC API provides data that can be read from, or written to, compatible NFC * devices, e.g. NFC tags supporting NDEF. + * + * @see + * https://w3c.github.io/web-nfc/#the-ndefrecord-interface */ @js.native @JSGlobal -class NDEFRecord extends js.Object { +class NDEFRecord(init: NDEFRecordInit) extends js.Object { /** Returns the record type of the record. Records must have either a standardized well-known type name such as * "empty", "text", "url", "smart-poster", "absolute-url", "mime", or "unknown" or else an external type name, which * consists of a domain name and custom type name separated by a colon (":"). */ - var recordType: String = js.native + def recordType: String = js.native /** Returns the MIME type of the record. This value will be null if recordType is not equal to "mime". */ - var mediaType: js.UndefOr[String] = js.native + def mediaType: js.UndefOr[String] = js.native /** Returns the record identifier, which is an absolute or relative URL used to identify the record. * * Note: The uniqueness of the identifier is enforced only by the generator of the record. */ - var id: js.UndefOr[String] = js.native + def id: js.UndefOr[String] = js.native /** Returns a DataView containing the raw bytes of the record's payload. */ - var data: js.typedarray.DataView = js.native + def data: js.typedarray.DataView = js.native /** Returns the encoding of a textual payload, or null otherwise. */ - var encoding: js.UndefOr[String] = js.native + def encoding: js.UndefOr[String] = js.native /** Returns the language of a textual payload, or null if one was not supplied. */ - var lang: js.UndefOr[String] = js.native + def lang: js.UndefOr[String] = js.native /** Converts [[NDEFRecord.data]] to a sequence of records. This allows parsing the payloads of record types which may * contain nested records, such as smart poster and external type records. */ - def toRecords(): js.Array[NDEFRecord] = js.native + def toRecords(): js.UndefOr[js.Array[NDEFRecord]] = js.native } diff --git a/webapp/src/main/scala/org/scalajs/dom/NDEFRecordInit.scala b/webapp/src/main/scala/org/scalajs/dom/NDEFRecordInit.scala new file mode 100644 index 00000000..b88ac617 --- /dev/null +++ b/webapp/src/main/scala/org/scalajs/dom/NDEFRecordInit.scala @@ -0,0 +1,55 @@ +package org.scalajs.dom + +import scala.scalajs.js +import scala.scalajs.js.| + +/** The NDEFRecordInit dictionary is used to initialize an NDEF record with its record type recordType, and optional + * record identifier id and payload data data. + * @see + * https://developer.mozilla.org/en-US/docs/Web/API/NDEFMessage/NDEFMessage + * @see + * https://developer.mozilla.org/en-US/docs/Web/API/NDEFRecord/NDEFRecord + * @see + * https://w3c.github.io/web-nfc/#the-ndefrecord-interface + */ +trait NDEFRecordInit extends js.Object { + + /** Contains the data to be transmitted. It can be a string object or literal, an ArrayBuffer, a TypedArray, a + * DataView, or an array of nested records. + */ + var data: js.UndefOr[ + String | + js.typedarray.DataView | + js.typedarray.ArrayBuffer | + js.typedarray.TypedArray[_, _] | + js.typedarray.DataView | + js.Array[NDEFRecord] + ] = js.undefined + + /** A string specifying the record's encoding. */ + var encoding: js.UndefOr[String] = js.undefined + + /** A developer-defined identifier for the record. */ + var id: js.UndefOr[String] = js.undefined + + /** A valid language tag according to [RFC 5646: Tags for Identifying Languages (also known as BCP + * 47)](https://datatracker.ietf.org/doc/html/rfc5646). + */ + var lang: js.UndefOr[String] = js.undefined + + /** A valid MIME type. */ + var mediaType: js.UndefOr[String] = js.undefined + + /** A string indicating the type of data stored in data. + * + * It must be one of the following values: + * - "absolute-url" - An absolute URL to the data. + * - "empty" - An empty NDEFRecord. + * - "mime" - A valid MIME type. + * - "smart-poster" - A smart poster as defined by the NDEF-SMARTPOSTER specification. + * - "text" - Text as defined by the NDEF-TEXT specification. + * - "unknown" - The record type is not known. + * - "URL" - A URL as defined by the NDEF-URI specification. + */ + var recordType: String +} diff --git a/webapp/src/main/scala/org/scalajs/dom/NDEFScanOptions.scala b/webapp/src/main/scala/org/scalajs/dom/NDEFScanOptions.scala index cb19fdbc..2b2946b7 100644 --- a/webapp/src/main/scala/org/scalajs/dom/NDEFScanOptions.scala +++ b/webapp/src/main/scala/org/scalajs/dom/NDEFScanOptions.scala @@ -2,9 +2,9 @@ package org.scalajs.dom import scala.scalajs.js -@js.native +/** @see https://w3c.github.io/web-nfc/#the-ndefscanoptions-dictionary */ trait NDEFScanOptions extends js.Object { /** An AbortSignal that allows the current write operation to be canceled. */ - def `signal`: js.UndefOr[AbortSignal] = js.native + var `signal`: js.UndefOr[AbortSignal] = js.undefined } diff --git a/webapp/src/main/scala/org/scalajs/dom/NDEFWriteOptions.scala b/webapp/src/main/scala/org/scalajs/dom/NDEFWriteOptions.scala index a39612e5..c7836b55 100644 --- a/webapp/src/main/scala/org/scalajs/dom/NDEFWriteOptions.scala +++ b/webapp/src/main/scala/org/scalajs/dom/NDEFWriteOptions.scala @@ -2,12 +2,18 @@ package org.scalajs.dom import scala.scalajs.js -@js.native +/** @see + * https://w3c.github.io/web-nfc/#the-ndefwriteoptions-dictionary + * @see + * https://developer.mozilla.org/en-US/docs/Web/API/NDEFReader/write + */ trait NDEFWriteOptions extends js.Object { - /** A boolean value specifying whether or not existing records should be overwritten, if such exists. */ - def `overwrite`: Boolean = js.native + /** A boolean value specifying whether or not existing records should be overwritten, if such exists. Default is true + */ + var `overwrite`: js.UndefOr[Boolean] = js.undefined /** An AbortSignal that allows the current write operation to be canceled. */ - def `signal`: js.UndefOr[AbortSignal] = js.native + var `signal`: js.UndefOr[AbortSignal] = js.undefined + } diff --git a/webapp/src/main/scala/org/scalajs/dom/NavigatorProtocolHandler.scala b/webapp/src/main/scala/org/scalajs/dom/NavigatorProtocolHandler.scala deleted file mode 100644 index edea6eb0..00000000 --- a/webapp/src/main/scala/org/scalajs/dom/NavigatorProtocolHandler.scala +++ /dev/null @@ -1,69 +0,0 @@ -package org.scalajs.dom - -import scala.scalajs.js - -@js.native -trait NavigatorProtocolHandler extends js.Object { -// trait NavigatorContentUtils extends js.Object { - - /** The Navigator method registerProtocolHandler() lets websites register their ability to open or handle particular - * URL schemes (aka protocols). - * - * For example, this API lets webmail sites open mailto: URLs, or VoIP sites open tel: URLs. - * - * @see - * https://developer.mozilla.org/en-US/docs/Web/API/Navigator/registerProtocolHandler - * - * @param scheme - * A string containing the permitted scheme for the protocol that the site wishes to handle. For example, you can - * register to handle SMS text message links by passing the "sms" scheme. - * @param url - * A string containing the URL of the handler. This URL must include %s, as a placeholder that will be replaced - * with the escaped URL to be handled. - * @return - * undefined - * - * @throws DOMException.SECURITY_ERR - * The user agent blocked the registration. This might happen if: - * - The registered scheme (protocol) is invalid, such as a scheme the browser handles itself (https:, about:, - * etc.) - * - The handler URL's origin does not match the origin of the page calling this API. - * - The browser requires that this function is called from a secure context. - * - The browser requires that the handler's URL be over HTTPS. - * - * @throws DOMException.SYNTAX_ERR - * The %s placeholder is missing from the handler URL - */ - def registerProtocolHandler(scheme: String, url: String): Unit = js.native - def registerProtocolHandler(scheme: String, url: URL): Unit = js.native - - /** The Navigator method unregisterProtocolHandler() removes a protocol handler for a given URL scheme. - * - * This method is the inverse of registerProtocolHandler(). - * - * @see - * https://developer.mozilla.org/en-US/docs/Web/API/Navigator/unregisterProtocolHandler - * - * @param scheme - * A string containing the permitted scheme in the protocol handler that will be unregistered. For example, you can - * unregister the handler for SMS text message links by passing the "sms" scheme. - * @param url - * A string containing the URL of the handler. This URL should match the one that was used to register the handler - * (e.g. it must include %s). - * @return - * undefined - * - * @throws DOMException.SECURITY_ERR - * The user agent blocked unregistration. This might happen if: - * - The registered scheme (protocol) is invalid, such as a scheme the browser handles itself (https:, about:, - * etc.) - * - The handler URL's origin does not match the origin of the page calling this API. - * - The browser requires that this function is called from a secure context. - * - The browser requires that the handler's URL be over HTTPS. - * - * @throws DOMException.SYNTAX_ERR - * The %s placeholder is missing from the handler URL - */ - def unregisterProtocolHandler(scheme: String, url: String): Unit = js.native - def unregisterProtocolHandler(scheme: String, url: URL): Unit = js.native -}