Skip to content

Commit

Permalink
Merge pull request #252 from gbishop/main
Browse files Browse the repository at this point in the history
Changes to enable Notes demo and several bug fixes.
  • Loading branch information
gbishop authored Jul 2, 2024
2 parents b753ac0 + fc9f83a commit c07dca8
Show file tree
Hide file tree
Showing 23 changed files with 687 additions and 229 deletions.
Binary file added Designs In Progress/Notes/notes_keyboard.osdpi
Binary file not shown.
Binary file added examples/updated/keyboard_predict_logging.osdpi
Binary file not shown.
5 changes: 5 additions & 0 deletions src/components/access/cues/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,11 @@ export class CueList extends DesignerPanel {
return this.children.find((cue) => cue.Default.value) || this.children[0];
}

/** @param {string} cue */
cueName(cue) {
return this.cueMap.get(cue);
}

/** @param {Object} obj */
static upgrade(obj) {
// update any CueCss entries to the new style interpolation
Expand Down
15 changes: 14 additions & 1 deletion src/components/access/method/pointerHandler.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,20 @@ export class PointerHandler extends Handler {
*/
function fromPointerEvent(event) {
return /** @type {RxJs.Observable<PointerEvent>} */ (
RxJs.fromEvent(document, event)
RxJs.fromEvent(document, event).pipe(
// fudge the target to be the button and not any contained thing
RxJs.tap((/** @type {PointerEvent} */ e) => {
if (
!(e.target instanceof HTMLButtonElement) &&
e.target instanceof HTMLElement
) {
const t = e.target.closest("button");
if (t) {
Object.defineProperty(e, "target", { value: t });
}
}
}),
)
);
}

Expand Down
42 changes: 28 additions & 14 deletions src/components/access/pattern/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,14 @@ import { toggleIndicator } from "app/components/helpers";
let animationNonce = 0;

/** @param {Target} target
* @param {string} defaultValue */
export function cueTarget(target, defaultValue) {
* @param {string} defaultValue
* @param {boolean} isGroup
* */
export function cueTarget(target, defaultValue, isGroup = false) {
if (target instanceof HTMLButtonElement) {
target.setAttribute("cue", defaultValue);
const video = target.querySelector("video");
if (video && !video.hasAttribute("autoplay")) {
if (!isGroup && video && !video.hasAttribute("autoplay")) {
if (video.hasAttribute("muted")) video.muted = true;
const promise = video.play();
if (promise !== undefined) {
Expand All @@ -28,7 +30,7 @@ export function cueTarget(target, defaultValue) {
}
}
} else if (target instanceof Group) {
target.cue();
target.cue(defaultValue);
}
}

Expand Down Expand Up @@ -72,13 +74,16 @@ export class Group {
}

/** @param {string} value */
cue(value = "") {
cue(value = "", top = true) {
if (!value) {
value = this.access.Cue;
}
for (const member of this.members) {
if (member instanceof HTMLButtonElement) cueTarget(member, value);
else if (member instanceof Group) member.cue(value);
if (member instanceof HTMLButtonElement)
cueTarget(member, value, !top || this.members.length > 1);
else if (member instanceof Group) {
member.cue(value, false);
}
}
}

Expand Down Expand Up @@ -175,7 +180,7 @@ export class PatternManager extends PatternBase {
/**
* Stack keeps track of the nesting as we walk the tree
*
* @type {{ group: Group; index: number }[]}
* @type {{ group: Group; cue: string, index: number }[]}
*/
stack = [];

Expand Down Expand Up @@ -272,7 +277,11 @@ export class PatternManager extends PatternBase {
}
this.targets = new Group(members, { ...this.propsAsObject, Cycles: 1 });
this.stack = [
{ group: this.targets, index: this.StartVisible.value ? 0 : -1 },
{
group: this.targets,
cue: this.Cue.value,
index: this.StartVisible.value ? 0 : -1,
},
];
this.cue();

Expand Down Expand Up @@ -326,12 +335,17 @@ export class PatternManager extends PatternBase {
}
let current = this.current;
if (!current) return;
while (current instanceof Group && current.members.length == 1) {
// manage currentCue while we walk through singleton groups
current = current.members[0];
}
if (current instanceof Group) {
while (current.length == 1 && current.members[0] instanceof Group) {
current = current.members[0];
}
// I need to work out the index here. Should be the group under the pointer
this.stack.unshift({ group: current, index: event?.groupIndex || 0 });
this.stack.unshift({
group: current,
cue: current.access.Cue,
index: event?.groupIndex || 0,
});
} else if (current instanceof HTMLButtonElement) {
if (current.hasAttribute("click")) {
current.dispatchEvent(new Event("Activate"));
Expand All @@ -353,7 +367,7 @@ export class PatternManager extends PatternBase {
const current = this.current;
if (!current) return;
this.cued = true;
cueTarget(current, this.Cue.value);
cueTarget(current, this.stack[0].cue);
}

/** Return the access info for current
Expand Down
102 changes: 1 addition & 101 deletions src/components/content.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,106 +7,6 @@ import "css/content.css";
import pleaseWait from "./wait";
import Globals from "app/globals";

/** @param {Blob} blob */
export async function readSheetFromBlob(blob) {
const XLSX = await import("xlsx");
const data = await blob.arrayBuffer();
const workbook = XLSX.read(data, { codepage: 65001 });
/** @type {Rows} */
const dataArray = [];
for (const sheetName of workbook.SheetNames) {
const sheet = workbook.Sheets[sheetName];
const ref = sheet["!ref"];
if (!ref) continue;
const range = XLSX.utils.decode_range(ref);
const names = [];
const handlers = [];
const validColumns = [];
// process the header and choose a handler for each column
for (let c = range.s.c; c <= range.e.c; c++) {
let columnName = sheet[XLSX.utils.encode_cell({ r: 0, c })]?.v;
if (typeof columnName !== "string" || !columnName) {
continue;
}
columnName = columnName.toLowerCase();
names.push(columnName.trim(" "));
validColumns.push(c);
switch (columnName) {
case "row":
case "column":
case "page":
handlers.push("number");
break;
default:
handlers.push("string");
break;
}
}
// Process the rows
for (let r = range.s.r + 1; r <= range.e.r; r++) {
/** @type {Row} */
const row = { sheetName };
for (let i = 0; i < validColumns.length; i++) {
/** @type {string} */
const name = names[i];
const c = validColumns[i];
let value = sheet[XLSX.utils.encode_cell({ r, c })]?.v;
switch (handlers[i]) {
case "string":
if (typeof value === "undefined") {
value = "";
}
if (typeof value !== "string") {
value = value.toString(10);
}
if (value && typeof value === "string") {
row[name] = value;
}
break;
case "number":
if (typeof value === "number") {
row[name] = Math.floor(value);
} else if (value && typeof value === "string") {
value = parseInt(value, 10);
if (isNaN(value)) {
value = 0;
}
row[name] = value;
}
break;
}
}
if (Object.keys(row).length > 1) dataArray.push(row);
}
}
return dataArray;
}

/** Save the content as a spreadsheet
* @param {string} name
* @param {Row[]} rows
* @param {string} type
*/
export async function saveContent(name, rows, type) {
const XLSX = await pleaseWait(import("xlsx"));
const sheetNames = new Set(rows.map((row) => row.sheetName || "sheet1"));
const workbook = XLSX.utils.book_new();
for (const sheetName of sheetNames) {
let sheetRows = rows.filter(
(row) => sheetName == (row.sheetName || "sheet1"),
);
if (type != "csv") {
sheetRows = sheetRows.map((row) => {
const { sheetName, ...rest } = row;
return rest;
});
}
const worksheet = XLSX.utils.json_to_sheet(sheetRows);
XLSX.utils.book_append_sheet(workbook, worksheet, sheetName);
}
XLSX.writeFileXLSX(workbook, `${name}.${type}`);
}

export class Content extends DesignerPanel {
name = new Props.String("Content");

Expand Down Expand Up @@ -151,7 +51,7 @@ export class Content extends DesignerPanel {
<div>
<h1>Content</h1>
<p>
${data.allrows.length} rows with these fields:
${data.length} rows with these fields:
${String([...data.allFields].sort()).replaceAll(",", ", ")}
</p>
<h2>Media files</h2>
Expand Down
Loading

0 comments on commit c07dca8

Please sign in to comment.