From f1aa40de8848b2923eb8d8e4bd0929885c568d59 Mon Sep 17 00:00:00 2001 From: skyclouds2001 <95597335+skyclouds2001@users.noreply.github.com> Date: Mon, 18 Dec 2023 16:44:37 +0800 Subject: [PATCH] fix: KeyboardLayoutMap.keys/values/entries should have methods type (#29957) * update * update * fix readonly * update summary * update * update * add link * fix title * feat: update * Update files/en-us/web/api/keyboardlayoutmap/entries/index.md * add content for @@iterator * update * fix * specific spec-urls * fix word * add example section * Apply suggestions from code review Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> * Update files/en-us/web/api/keyboardlayoutmap/has/index.md --------- Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> --- .../api/keyboardlayoutmap/entries/index.md | 34 +++++++++++++------ .../api/keyboardlayoutmap/foreach/index.md | 19 +++++++++++ .../web/api/keyboardlayoutmap/get/index.md | 13 ++++--- .../web/api/keyboardlayoutmap/has/index.md | 17 ++++++++++ .../en-us/web/api/keyboardlayoutmap/index.md | 21 ++++++------ .../web/api/keyboardlayoutmap/keys/index.md | 32 ++++++++++++----- .../web/api/keyboardlayoutmap/size/index.md | 17 ++++++++++ .../web/api/keyboardlayoutmap/values/index.md | 32 ++++++++++++----- 8 files changed, 145 insertions(+), 40 deletions(-) diff --git a/files/en-us/web/api/keyboardlayoutmap/entries/index.md b/files/en-us/web/api/keyboardlayoutmap/entries/index.md index e500013de9972a7..4b90b0543985e81 100644 --- a/files/en-us/web/api/keyboardlayoutmap/entries/index.md +++ b/files/en-us/web/api/keyboardlayoutmap/entries/index.md @@ -1,25 +1,35 @@ --- -title: "KeyboardLayoutMap: entries property" -short-title: entries +title: "KeyboardLayoutMap: entries() method" +short-title: entries() slug: Web/API/KeyboardLayoutMap/entries -page-type: web-api-instance-property +page-type: web-api-instance-method status: - experimental browser-compat: api.KeyboardLayoutMap.entries +spec-urls: https://tc39.es/ecma262/multipage/keyed-collections.html#sec-map.prototype.entries --- {{SeeCompatTable}}{{APIRef("Keyboard API")}} -The **`entries`** read-only property -of the {{domxref("KeyboardLayoutMap")}} interface returns an array of a given object's -own enumerable property `[key, value]` pairs, in the same order as that -provided by a {{jsxref("Statements/for...in", "for...in")}} loop (the difference being -that a for-in loop enumerates properties in the prototype chain as well). +The **`entries()`** method of the {{domxref("KeyboardLayoutMap")}} interface returns a new [Iterator](/en-US/docs/Web/JavaScript/Reference/Global_Objects/Iterator) object that contains the key/value pairs, in the same order as that provided by a {{jsxref("Statements/for...in", "for...in")}} loop (the difference being that a `for-in` loop enumerates properties in the prototype chain as well). + +The method is otherwise the same as {{jsxref("Map.prototype.entries()")}}. ## Value -An array of the given `KeyboardLayoutMap` object's own enumerable property -`[key, value]` pairs. +A new [Iterator](/en-US/docs/Web/JavaScript/Reference/Global_Objects/Iterator) object. + +## Examples + +The following example iterates every location- or layout-specific string and its associated keyboard code on an English QWERTY keyboard. + +```js +navigator.keyboard.getLayoutMap().then((keyboardLayoutMap) => { + for (const [code, key] of keyboardLayoutMap.entries()) { + console.log(`${code} keyboard code represents ${key} key`); + } +}); +``` ## Specifications @@ -28,3 +38,7 @@ An array of the given `KeyboardLayoutMap` object's own enumerable property ## Browser compatibility {{Compat}} + +## See also + +- {{jsxref("Map.prototype.entries()")}} diff --git a/files/en-us/web/api/keyboardlayoutmap/foreach/index.md b/files/en-us/web/api/keyboardlayoutmap/foreach/index.md index 54e4b04130c7ceb..ff972a9965341c8 100644 --- a/files/en-us/web/api/keyboardlayoutmap/foreach/index.md +++ b/files/en-us/web/api/keyboardlayoutmap/foreach/index.md @@ -6,6 +6,7 @@ page-type: web-api-instance-method status: - experimental browser-compat: api.KeyboardLayoutMap.forEach +spec-urls: https://tc39.es/ecma262/multipage/keyed-collections.html#sec-map.prototype.foreach --- {{APIRef("Keyboard API")}}{{SeeCompatTable}} @@ -14,6 +15,8 @@ The **`forEach()`** method of the {{domxref('KeyboardLayoutMap')}} interface executes a provided function once for each element of the map. +The method is otherwise the same as {{jsxref("Map.prototype.forEach()")}}. + ## Syntax ```js-nolint @@ -42,6 +45,18 @@ forEach(callbackFn, thisArg) None ({{jsxref("undefined")}}). +## Examples + +The following example iterates every location- or layout-specific string and its associated keyboard code on an English QWERTY keyboard. + +```js +navigator.keyboard.getLayoutMap().then((keyboardLayoutMap) => { + keyboardLayoutMap.forEach((key, code) => { + console.log(`${code} keyboard code represents ${key} key`); + }); +}); +``` + ## Specifications {{Specifications}} @@ -49,3 +64,7 @@ None ({{jsxref("undefined")}}). ## Browser compatibility {{Compat}} + +## See also + +- {{jsxref("Map.prototype.forEach()")}} diff --git a/files/en-us/web/api/keyboardlayoutmap/get/index.md b/files/en-us/web/api/keyboardlayoutmap/get/index.md index 7b67dc7c92c8bf2..e8483ec3434b1c1 100644 --- a/files/en-us/web/api/keyboardlayoutmap/get/index.md +++ b/files/en-us/web/api/keyboardlayoutmap/get/index.md @@ -6,6 +6,7 @@ page-type: web-api-instance-method status: - experimental browser-compat: api.KeyboardLayoutMap.get +spec-urls: https://tc39.es/ecma262/multipage/keyed-collections.html#sec-map.prototype.get --- {{APIRef("Keyboard API")}}{{SeeCompatTable}} @@ -16,6 +17,8 @@ key. A list of valid keys is found in the [UI Events KeyboardEvent code Values](https://www.w3.org/TR/uievents-code/#key-alphanumeric-writing-system) spec. +The method is otherwise the same as {{jsxref("Map.prototype.get()")}}. + ## Syntax ```js-nolint @@ -33,12 +36,10 @@ The value of the specified key. ## Examples -The following example demonstrates how to get the location- or layout-specific string -associated with the key that corresponds to the 'W' key on an English QWERTY keyboard. +The following example demonstrates how to get the location- or layout-specific string associated with the keyboard code that corresponds to the 'W' key on an English QWERTY keyboard. ```js -const keyboard = navigator.keyboard; -keyboard.getLayoutMap().then((keyboardLayoutMap) => { +navigator.keyboard.getLayoutMap().then((keyboardLayoutMap) => { const upKey = keyboardLayoutMap.get("KeyW"); window.alert(`Press ${upKey} to move up.`); }); @@ -51,3 +52,7 @@ keyboard.getLayoutMap().then((keyboardLayoutMap) => { ## Browser compatibility {{Compat}} + +## See also + +- {{jsxref("Map.prototype.get()")}} diff --git a/files/en-us/web/api/keyboardlayoutmap/has/index.md b/files/en-us/web/api/keyboardlayoutmap/has/index.md index 966166e88c47d4d..a058bc0e5c5ea71 100644 --- a/files/en-us/web/api/keyboardlayoutmap/has/index.md +++ b/files/en-us/web/api/keyboardlayoutmap/has/index.md @@ -6,6 +6,7 @@ page-type: web-api-instance-method status: - experimental browser-compat: api.KeyboardLayoutMap.has +spec-urls: https://tc39.es/ecma262/multipage/keyed-collections.html#sec-map.prototype.has --- {{APIRef("Keyboard API")}}{{SeeCompatTable}} @@ -17,6 +18,8 @@ object has an element with the specified key. A list of valid keys is found in the [UI Events KeyboardEvent code Values](https://www.w3.org/TR/uievents-code/#key-alphanumeric-writing-system) spec. +The method is otherwise the same as {{jsxref("Map.prototype.has()")}}. + ## Syntax ```js-nolint @@ -32,6 +35,16 @@ has(key) A {{jsxref('Boolean')}} indicating whether the specified key was found. +## Examples + +The following example checks whether the location- or layout-specific string associated with the keyboard code that corresponds to the 'W' key on an English QWERTY keyboard existes. + +```js +navigator.keyboard.getLayoutMap().then((keyboardLayoutMap) => { + console.log(keyboardLayoutMap.has("KeyW")); +}); +``` + ## Specifications {{Specifications}} @@ -39,3 +52,7 @@ A {{jsxref('Boolean')}} indicating whether the specified key was found. ## Browser compatibility {{Compat}} + +## See also + +- {{jsxref("Map.prototype.has()")}} diff --git a/files/en-us/web/api/keyboardlayoutmap/index.md b/files/en-us/web/api/keyboardlayoutmap/index.md index 0e9c8dbf7c46ba1..0a36912d4440d5e 100644 --- a/files/en-us/web/api/keyboardlayoutmap/index.md +++ b/files/en-us/web/api/keyboardlayoutmap/index.md @@ -17,31 +17,32 @@ A list of valid keys is found in the [UI Events KeyboardEvent code Values](https ## Instance properties -- {{domxref('KeyboardLayoutMap.entries')}} {{ReadOnlyInline}} {{experimental_inline}} - - : Returns an array of a given object's own enumerable property `[key, value]` pairs, in the same order as that provided by a {{jsxref("Statements/for...in", "for...in")}} loop (the difference being that a `for-in` loop enumerates properties in the prototype chain as well). -- {{domxref('KeyboardLayoutMap.keys')}} {{ReadOnlyInline}} {{experimental_inline}} - - : Returns a new _array iterator_ object that contains the keys for each index in the array. - {{domxref('KeyboardLayoutMap.size')}} {{ReadOnlyInline}} {{experimental_inline}} - : Returns the number of elements in the `KeyboardLayoutMap` object. -- {{domxref('KeyboardLayoutMap.values')}} {{ReadOnlyInline}} {{experimental_inline}} - - : Returns a new _array iterator_ object that contains the values for each index in the `KeyboardLayoutMap` object. ## Instance methods -- {{domxref('KeyboardLayoutMap.forEach()')}} {{ReadOnlyInline}} {{experimental_inline}} +- `KeyboardLayoutMap.[@@iterator]()` {{experimental_inline}} + - : Returns a new [Iterator](/en-US/docs/Web/JavaScript/Reference/Global_Objects/Iterator) object that contains the key/value pairs. +- {{domxref('KeyboardLayoutMap.entries()')}} {{experimental_inline}} + - : Returns a new [Iterator](/en-US/docs/Web/JavaScript/Reference/Global_Objects/Iterator) object that contains the key/value pairs. +- {{domxref('KeyboardLayoutMap.forEach()')}} {{experimental_inline}} - : Executes a provided function once for each element of `KeyboardLayoutMap`. - {{domxref('KeyboardLayoutMap.get()')}} {{experimental_inline}} - : Returns the element with the given key from the `KeyboardLayoutMap` object. - {{domxref('KeyboardLayoutMap.has()')}} {{experimental_inline}} - : Returns a boolean indicating whether the `KeyboardLayoutMap` object has an element with the specified key. +- {{domxref('KeyboardLayoutMap.keys()')}} {{experimental_inline}} + - : Returns a new [Iterator](/en-US/docs/Web/JavaScript/Reference/Global_Objects/Iterator) object that contains the keys for each index in the `KeyboardLayoutMap` object. +- {{domxref('KeyboardLayoutMap.values()')}} {{experimental_inline}} + - : Returns a new [Iterator](/en-US/docs/Web/JavaScript/Reference/Global_Objects/Iterator) object that contains the values for each index in the `KeyboardLayoutMap` object. ## Examples -The following example demonstrates how to get the location- or layout-specific string associated with the key that corresponds to the 'W' key on an English QWERTY keyboard. +The following example demonstrates how to get the location- or layout-specific string associated with the keyboard code that corresponds to the 'W' key on an English QWERTY keyboard. ```js -const keyboard = navigator.keyboard; -keyboard.getLayoutMap().then((keyboardLayoutMap) => { +navigator.keyboard.getLayoutMap().then((keyboardLayoutMap) => { const upKey = keyboardLayoutMap.get("KeyW"); window.alert(`Press ${upKey} to move up.`); }); diff --git a/files/en-us/web/api/keyboardlayoutmap/keys/index.md b/files/en-us/web/api/keyboardlayoutmap/keys/index.md index 311c82705f49e75..11f732d4c58bd45 100644 --- a/files/en-us/web/api/keyboardlayoutmap/keys/index.md +++ b/files/en-us/web/api/keyboardlayoutmap/keys/index.md @@ -1,23 +1,35 @@ --- -title: "KeyboardLayoutMap: keys property" -short-title: keys +title: "KeyboardLayoutMap: keys() method" +short-title: keys() slug: Web/API/KeyboardLayoutMap/keys -page-type: web-api-instance-property +page-type: web-api-instance-method status: - experimental browser-compat: api.KeyboardLayoutMap.keys +spec-urls: https://tc39.es/ecma262/multipage/keyed-collections.html#sec-map.prototype.keys --- {{SeeCompatTable}}{{APIRef("Keyboard API")}} -The **`keys`** read-only property of -the {{domxref("KeyboardLayoutMap")}} interface returns a new Array -Iterator object that contains the keys for each index in the -array. +The **`keys()`** method of the {{domxref("KeyboardLayoutMap")}} interface returns a new [Iterator](/en-US/docs/Web/JavaScript/Reference/Global_Objects/Iterator) object that contains the keys for each index in the `KeyboardLayoutMap` object. + +The method is otherwise the same as {{jsxref("Map.prototype.keys()")}}. ## Value -An iterator. +A new [Iterator](/en-US/docs/Web/JavaScript/Reference/Global_Objects/Iterator) object. + +## Examples + +The following example iterates every keyboard code on an English QWERTY keyboard. + +```js +navigator.keyboard.getLayoutMap().then((keyboardLayoutMap) => { + for (const code of keyboardLayoutMap.keys()) { + console.log(`${code} keyboard code`); + } +}); +``` ## Specifications @@ -26,3 +38,7 @@ An iterator. ## Browser compatibility {{Compat}} + +## See also + +- {{jsxref("Map.prototype.keys()")}} diff --git a/files/en-us/web/api/keyboardlayoutmap/size/index.md b/files/en-us/web/api/keyboardlayoutmap/size/index.md index 8900a317fa51523..f1a2421c4b8b8e5 100644 --- a/files/en-us/web/api/keyboardlayoutmap/size/index.md +++ b/files/en-us/web/api/keyboardlayoutmap/size/index.md @@ -6,6 +6,7 @@ page-type: web-api-instance-property status: - experimental browser-compat: api.KeyboardLayoutMap.size +spec-urls: https://tc39.es/ecma262/multipage/keyed-collections.html#sec-get-map.prototype.size --- {{SeeCompatTable}}{{APIRef("Keyboard API")}} @@ -14,10 +15,22 @@ The **`size`** read-only property of the {{domxref("KeyboardLayoutMap")}} interface returns the number of elements in the map. +The property is otherwise the same as {{jsxref("Map.prototype.size")}}. + ## Value A number. +## Examples + +The following example get the count of the location- or layout-specific string and its associated keyboard code on an English QWERTY keyboard. + +```js +navigator.keyboard.getLayoutMap().then((keyboardLayoutMap) => { + console.log(keyboardLayoutMap.size); +}); +``` + ## Specifications {{Specifications}} @@ -25,3 +38,7 @@ A number. ## Browser compatibility {{Compat}} + +## See also + +- {{jsxref("Map.prototype.size")}} diff --git a/files/en-us/web/api/keyboardlayoutmap/values/index.md b/files/en-us/web/api/keyboardlayoutmap/values/index.md index 5a58eca905a04f6..246d95ef345b774 100644 --- a/files/en-us/web/api/keyboardlayoutmap/values/index.md +++ b/files/en-us/web/api/keyboardlayoutmap/values/index.md @@ -1,23 +1,35 @@ --- -title: "KeyboardLayoutMap: values property" -short-title: values +title: "KeyboardLayoutMap: values() method" +short-title: values() slug: Web/API/KeyboardLayoutMap/values -page-type: web-api-instance-property +page-type: web-api-instance-method status: - experimental browser-compat: api.KeyboardLayoutMap.values +spec-urls: https://tc39.es/ecma262/multipage/keyed-collections.html#sec-map.prototype.values --- {{SeeCompatTable}}{{APIRef("Keyboard API")}} -The **`values`** read-only property of -the {{domxref("KeyboardLayoutMap")}} interface returns a new Array -Iterator object that contains the values for each index in the -map. +The **`values()`** method of the {{domxref("KeyboardLayoutMap")}} interface returns a new [Iterator](/en-US/docs/Web/JavaScript/Reference/Global_Objects/Iterator) object that contains the values for each index in the `KeyboardLayoutMap` object. + +The method is otherwise the same as {{jsxref("Map.prototype.values()")}}. ## Value -An iterator. +A new [Iterator](/en-US/docs/Web/JavaScript/Reference/Global_Objects/Iterator) object. + +## Examples + +The following example iterates every location- or layout-specific string on an English QWERTY keyboard. + +```js +navigator.keyboard.getLayoutMap().then((keyboardLayoutMap) => { + for (const key of keyboardLayoutMap.values()) { + console.log(`${key} key`); + } +}); +``` ## Specifications @@ -26,3 +38,7 @@ An iterator. ## Browser compatibility {{Compat}} + +## See also + +- {{jsxref("Map.prototype.values()")}}