Using display options with layoutCandidates. Fixes #1831

This commit is contained in:
Francisco Hodge 2023-01-04 01:48:06 -05:00
parent 040d4fc40f
commit 5e1df22e59
10 changed files with 20 additions and 12 deletions

View File

@ -1,12 +1,13 @@
import "./css/CandidateBox.css"; import "./css/CandidateBox.css";
import Utilities from "../services/Utilities"; import Utilities from "../services/Utilities";
import { CandidateBoxParams, CandidateBoxRenderParams, CandidateBoxShowParams } from "./../interfaces"; import { CandidateBoxParams, CandidateBoxRenderParams, CandidateBoxShowParams, KeyboardOptions } from "./../interfaces";
declare class CandidateBox { declare class CandidateBox {
utilities: Utilities; utilities: Utilities;
options: KeyboardOptions;
candidateBoxElement: HTMLDivElement; candidateBoxElement: HTMLDivElement;
pageIndex: number; pageIndex: number;
pageSize: number; pageSize: number;
constructor({ utilities }: CandidateBoxParams); constructor({ utilities, options }: CandidateBoxParams);
destroy(): void; destroy(): void;
show({ candidateValue, targetElement, onSelect, }: CandidateBoxShowParams): void; show({ candidateValue, targetElement, onSelect, }: CandidateBoxShowParams): void;
renderPage({ candidateListPages, targetElement, pageIndex, nbPages, onItemSelected, }: CandidateBoxRenderParams): void; renderPage({ candidateListPages, targetElement, pageIndex, nbPages, onItemSelected, }: CandidateBoxRenderParams): void;

View File

@ -1,6 +1,6 @@
/*! /*!
* *
* simple-keyboard v3.4.210 * simple-keyboard v3.5.0
* https://github.com/hodgef/simple-keyboard * https://github.com/hodgef/simple-keyboard
* *
* Copyright (c) Francisco Hodge (https://github.com/hodgef) and project contributors. * Copyright (c) Francisco Hodge (https://github.com/hodgef) and project contributors.

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -17,6 +17,7 @@ export interface KeyboardInput {
} }
export type CandidateBoxParams = { export type CandidateBoxParams = {
utilities: Utilities; utilities: Utilities;
options: KeyboardOptions;
}; };
export type CandidateBoxShowParams = { export type CandidateBoxShowParams = {
candidateValue: string; candidateValue: string;

View File

@ -1,6 +1,6 @@
{ {
"name": "simple-keyboard", "name": "simple-keyboard",
"version": "3.4.210", "version": "3.5.0",
"description": "On-screen Javascript Virtual Keyboard", "description": "On-screen Javascript Virtual Keyboard",
"main": "build/index.js", "main": "build/index.js",
"scripts": { "scripts": {

View File

@ -5,16 +5,19 @@ import {
CandidateBoxParams, CandidateBoxParams,
CandidateBoxRenderParams, CandidateBoxRenderParams,
CandidateBoxShowParams, CandidateBoxShowParams,
KeyboardOptions,
} from "./../interfaces"; } from "./../interfaces";
class CandidateBox { class CandidateBox {
utilities: Utilities; utilities: Utilities;
options: KeyboardOptions;
candidateBoxElement!: HTMLDivElement; candidateBoxElement!: HTMLDivElement;
pageIndex = 0; pageIndex = 0;
pageSize; pageSize;
constructor({ utilities }: CandidateBoxParams) { constructor({ utilities, options }: CandidateBoxParams) {
this.utilities = utilities; this.utilities = utilities;
this.options = options;
Utilities.bindMethods(CandidateBox, this); Utilities.bindMethods(CandidateBox, this);
this.pageSize = this.utilities.getOptions().layoutCandidatesPageSize || 5; this.pageSize = this.utilities.getOptions().layoutCandidatesPageSize || 5;
} }
@ -82,7 +85,7 @@ class CandidateBox {
}; };
candidateListLIElement.className = "hg-candidate-box-list-item"; candidateListLIElement.className = "hg-candidate-box-list-item";
candidateListLIElement.textContent = candidateListItem; candidateListLIElement.textContent = this.options.display?.[candidateListItem] || candidateListItem;
candidateListLIElement.onclick = (e = getMouseEvent()) => candidateListLIElement.onclick = (e = getMouseEvent()) =>
onItemSelected(candidateListItem, e); onItemSelected(candidateListItem, e);

View File

@ -215,6 +215,7 @@ class SimpleKeyboard {
this.candidateBox = this.options.enableLayoutCandidates this.candidateBox = this.options.enableLayoutCandidates
? new CandidateBox({ ? new CandidateBox({
utilities: this.utilities, utilities: this.utilities,
options: this.options,
}) })
: null; : null;
@ -878,6 +879,7 @@ class SimpleKeyboard {
this.candidateBox.destroy(); this.candidateBox.destroy();
this.candidateBox = new CandidateBox({ this.candidateBox = new CandidateBox({
utilities: this.utilities, utilities: this.utilities,
options: this.options,
}); });
} }
} }

View File

@ -22,7 +22,8 @@ export interface KeyboardInput {
} }
export type CandidateBoxParams = { export type CandidateBoxParams = {
utilities: Utilities utilities: Utilities,
options: KeyboardOptions
} }
export type CandidateBoxShowParams = { export type CandidateBoxShowParams = {