Skip to content

Commit

Permalink
Reflect changes in scala-js/scala-js-dom#806 after review
Browse files Browse the repository at this point in the history
  • Loading branch information
FabioPinheiro committed Sep 29, 2023
1 parent e6586e2 commit 07fd6ce
Show file tree
Hide file tree
Showing 6 changed files with 43 additions and 23 deletions.
11 changes: 7 additions & 4 deletions webapp/src/main/scala/org/scalajs/dom/NDEFMessage.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
7 changes: 6 additions & 1 deletion webapp/src/main/scala/org/scalajs/dom/NDEFReader.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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

Expand Down
11 changes: 7 additions & 4 deletions webapp/src/main/scala/org/scalajs/dom/NDEFReadingEvent.scala
Original file line number Diff line number Diff line change
@@ -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
}
19 changes: 11 additions & 8 deletions webapp/src/main/scala/org/scalajs/dom/NDEFRecord.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
4 changes: 2 additions & 2 deletions webapp/src/main/scala/org/scalajs/dom/NDEFScanOptions.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
14 changes: 10 additions & 4 deletions webapp/src/main/scala/org/scalajs/dom/NDEFWriteOptions.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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

}

0 comments on commit 07fd6ce

Please sign in to comment.