Socket
Socket
Sign inDemoInstall

@benev/nubs

Package Overview
Dependencies
314
Maintainers
1
Versions
19
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 0.2.4 to 0.3.0-dev.1

s/elements/context/bindings/converters/1.ts

27

package.json
{
"name": "@benev/nubs",
"version": "0.2.4",
"version": "0.3.0-dev.1",
"description": "user-input system for web games",

@@ -31,10 +31,9 @@ "license": "MIT",

"watch-web": "chokidar \"x/web/**/*\" -c \"npm run web -s && echo 'rebuilt web'\"",
"test-old-debug": "node inspect node_modules/cynic/dist/cli.js node x/tests.test.js",
"test-old": "cynic node x/tests.test.js",
"test": "exit 0"
"test-debug": "node inspect node_modules/cynic/dist/cli.js node x/tests.test.js",
"test": "cynic node x/tests.test.js"
},
"dependencies": {
"@chasemoskal/magical": "^0.1.3",
"lit": "^2.6.1",
"xiome": "^0.0.41"
"@chasemoskal/magical": "^0.1.7",
"lit": "^2.8.0",
"xiome": "^0.0.45"
},

@@ -44,11 +43,11 @@ "devDependencies": {

"chokidar-cli": "^3.0.0",
"cynic": "^0.2.0",
"es-module-shims": "^1.7.0",
"cynic": "^0.2.1",
"es-module-shims": "^1.8.0",
"http-server": "^14.1.1",
"importly": "^0.2.0",
"mkdirp": "^2.1.5",
"importly": "^0.2.1",
"mkdirp": "^3.0.1",
"npm-run-all": "^4.1.5",
"rimraf": "^4.4.0",
"sass": "^1.59.3",
"typescript": "^5.0.2"
"rimraf": "^5.0.1",
"sass": "^1.66.1",
"typescript": "^5.2.2"
},

@@ -55,0 +54,0 @@ "keywords": [

@@ -7,2 +7,4 @@

import {default_bindings_schema} from "./default_bindings_schema.js"
import {detect_bindings_version} from "./utils/detect_bindings_version.js"
import {migrate_bindings_to_latest_version} from "./utils/migrate_bindings_to_latest_version.js"

@@ -56,8 +58,11 @@ export class Bindings_Controller {

load_from_storage() {
this.#bindings = (
const read_bindings = (
this.#store[this.storage_key]
?? this.defaults
)
this.#on_bindings_change(this.#bindings)
const bindings_version = detect_bindings_version(read_bindings)
this.bindings = migrate_bindings_to_latest_version(
read_bindings, bindings_version
)
}
}

@@ -9,32 +9,32 @@

pointer: {
look: {causes: ["Pointer", "Lookpad"]},
look: {causes: [["Pointer"], ["Lookpad"]]},
},
stick: {
move: {causes: ["Stick"]},
look: {causes: ["Stick2"]},
move: {causes: [["Stick"]]},
look: {causes: [["Stick2"]]},
},
key: {
open_menu: {causes: ["KeyQ", "Backquote"]},
open_menu: {causes: [["KeyQ"], ["Backquote"]]},
move_forward: {causes: ["KeyE", "ArrowUp"]},
move_backward: {causes: ["KeyD", "ArrowDown"]},
move_leftward: {causes: ["KeyS", "ArrowLeft"]},
move_rightward: {causes: ["KeyF", "ArrowRight"]},
move_forward: {causes: [["KeyE"], ["ArrowUp"]]},
move_backward: {causes: [["KeyD"], ["ArrowDown"]]},
move_leftward: {causes: [["KeyS"], ["ArrowLeft"]]},
move_rightward: {causes: [["KeyF"], ["ArrowRight"]]},
move_fast: {causes: ["ShiftLeft"]},
move_slow: {causes: ["CapsLock"]},
move_fast: {causes: [["ShiftLeft"]]},
move_slow: {causes: [["CapsLock"]]},
jump: {causes: ["Space"]},
crouch: {causes: ["KeyZ"]},
use: {causes: ["KeyG", "Mouse3"]},
primary: {causes: ["Mouse1"]},
secondary: {causes: ["Mouse2"]},
jump: {causes: [["Space"]]},
crouch: {causes: [["KeyZ"]]},
use: {causes: [["KeyG"], ["Mouse3"]]},
primary: {causes: [["Mouse1"]]},
secondary: {causes: [["Mouse2"]]},
look_up: {causes: ["KeyI"]},
look_down: {causes: ["KeyK"]},
look_left: {causes: ["KeyJ"]},
look_right: {causes: ["KeyL"]},
look_up: {causes: [["KeyI"]]},
look_down: {causes: [["KeyK"]]},
look_left: {causes: [["KeyJ"]]},
look_right: {causes: [["KeyL"]]},
look_fast: {causes: ["Slash"]},
look_slow: {causes: ["Period"]},
look_fast: {causes: [["Slash"]]},
look_slow: {causes: [["Period"]]},
},

@@ -44,5 +44,5 @@ },

key: {
close_menu: {causes: ["KeyQ", "Backquote"]},
close_menu: {causes: [["KeyQ"], ["Backquote"]]},
},
},
} satisfies BindingsSchema

@@ -7,9 +7,12 @@

export function extract_bindings(decorated: BindingsSchema): Bindings {
return obtool(decorated).map(
mode => obtool(mode).map(
kind => obtool(kind).map(
bind => bind.causes
return {
version: 2,
modes: obtool(decorated).map(
mode => obtool(mode).map(
kind => obtool(kind).map(
bind => bind.causes
)
)
)
)
}
}

@@ -5,2 +5,3 @@

import {ReadableSet} from "../../../tools/regulated-set/types/readable-set.js"
import {compareStringArrays} from "../../../tools/compare-string-arrays.js"

@@ -10,5 +11,7 @@ export function find_effects_for_cause_by_consulting_bindings({

bindings,
keys_pressed,
cause_detail,
}: {
bindings: Bindings
keys_pressed: Set<string>
modes: ReadableSet<string>

@@ -18,12 +21,15 @@ cause_detail: NubDetail.Any

const {kind, cause} = cause_detail
const {kind} = cause_detail
const cause = Array.from(keys_pressed)
const matching_effect_names = new Set<string>()
modes.forEach(mode => {
const kindbinds = bindings[mode] ?? {}
const kindbinds = bindings.modes[mode] ?? {}
const binds = kindbinds[kind] ?? {}
for (const [effect, bindlist] of Object.entries(binds)) {
if (bindlist.includes(cause)) {
matching_effect_names.add(effect)
for (const bind of bindlist) {
if(compareStringArrays(bind, cause)) {
matching_effect_names.add(effect)
}
}

@@ -30,0 +36,0 @@ }

@@ -8,3 +8,3 @@

[effect: string]: {
causes: string[]
causes: string[][]
label?: string

@@ -11,0 +11,0 @@ icon?: SVGTemplateResult | TemplateResult

export type Bindings = {
export type Bindings1 = {
[mode: string]: {

@@ -9,1 +9,14 @@ [kind: string]: {

}
export type Bindings2 = {
version: number,
modes: {
[mode: string]: {
[kind: string]: {
[effect: string]: string[][]
}
}
}
}
export type Bindings = Bindings2

@@ -8,3 +8,3 @@

export function setup_bindings_and_handle_changes(onChange: OnBindingsChange) {
let bindings: Bindings = {}
let bindings: Bindings
const cloneBindings = () => clone(bindings)

@@ -11,0 +11,0 @@

@@ -19,9 +19,21 @@

dispatch_effect: (detail: NubDetail.Effect) => void
}) => (
}) => {
({detail: cause_detail}: NubCauseEvent) => {
const keys_pressed = new Set<string>()
return ({detail: cause_detail}: NubCauseEvent) => {
if (cause_detail.kind === "key") {
if (cause_detail.pressed) {
keys_pressed.add(cause_detail.cause)
}
else {
keys_pressed.delete(cause_detail.cause)
}
}
const matching_effect_names = (
find_effects_for_cause_by_consulting_bindings({
modes,
keys_pressed,
cause_detail,

@@ -32,4 +44,6 @@ bindings: get_current_bindings(),

const causes = Array.from(keys_pressed).join(" ")
for (const effect of matching_effect_names) {
const effect_detail = {...cause_detail, effect}
const effect_detail = {...cause_detail, effect, cause: causes}
effects[cause_detail.kind][effect] = effect_detail

@@ -39,2 +53,2 @@ dispatch_effect(effect_detail)

}
)
}

@@ -33,3 +33,3 @@

const availableModes = Object.keys(bindingsDraft)
const availableModes = Object.keys(bindingsDraft.modes)
const [primaryMode = default_mode] = availableModes

@@ -36,0 +36,0 @@

@@ -139,2 +139,25 @@

.dialog {
position: fixed;
inset: 0;
display: grid;
place-items: center;
> div {
gap: 1rem;
padding: 2rem;
display: flex;
flex-direction: column;
background: fixed linear-gradient(180deg, #1b2941, #0c0511);
> input {
color: white;
background: transparent;
border: 1px solid #363636;
text-align: center;
padding: 0.5em;
}
}
}
.problem {

@@ -141,0 +164,0 @@ color: orange;

@@ -5,2 +5,3 @@

import {when} from "../../../tools/when.js"
import {Waiting} from "./gui/types/waiting.js"

@@ -10,2 +11,3 @@ import {GuiOptions} from "./gui/types/gui-options.js"

import {renderKeybind} from "./gui/renderers/render-keybind.js"
import {BindingsDialogView} from "./gui/views/bindings-dialog.js"
import {controlKeybindAssignments} from "./gui/utils/control-keybind-assignments.js"

@@ -28,2 +30,8 @@

const [showDialog, setShowDialog, getShowDialog] =
use.state(false)
const [keysPressed, setKeysPressed, getKeysPressed] =
use.state<string[]>([])
use.setup(() =>

@@ -38,2 +46,6 @@ NubCauseEvent

setBindingsDraft,
setKeysPressed,
getShowDialog,
setShowDialog,
getKeysPressed
}))

@@ -43,3 +55,3 @@ )

const mode = getMode()
const kindbinds = bindingsDraft[mode]
const kindbinds = bindingsDraft.modes[mode]
const keybinds = kindbinds?.key ?? {}

@@ -63,7 +75,12 @@

.entries(keybinds)
.map(renderKeybind(waiting, setWaiting))}
.map(renderKeybind(waiting, setWaiting, setShowDialog))}
</div>
${when(showDialog, () => BindingsDialogView({
keysPressed,
setKeysPressed
}))}
</div>
`
})

@@ -10,5 +10,6 @@

setWaiting: StateSetter<undefined | Waiting>,
setShowDialog: StateSetter<boolean>
) {
return ([effect, keycodes]: [string, string[]]) => KeybindView({
return ([effect, keycodes]: [string, string[][]]) => KeybindView({
effect,

@@ -18,2 +19,3 @@ keycodes,

onClickRebind(keyIndex) {
setShowDialog(true)
setWaiting({

@@ -25,2 +27,3 @@ effect,

onClickAddNewBind() {
setShowDialog(true)
setWaiting({

@@ -27,0 +30,0 @@ effect,

@@ -15,7 +15,7 @@

return (code: string, keyIndex: number) => KeycapView({
return (code: string[], keyIndex: number) => KeycapView({
keyIndex,
code: code ? code : "-",
code: code.length ? code.join(" ") : "-",

@@ -22,0 +22,0 @@ isWaiting: (

import {StateSetter} from "@chasemoskal/magical/x/view/types.js"
import {StateGetter, StateSetter} from "@chasemoskal/magical/x/view/types.js"

@@ -7,9 +7,14 @@ import {Waiting} from "../types/waiting.js"

import {Bindings} from "../../../../context/bindings/types/bindings.js"
import {compareStringArrays} from "../../../../../tools/compare-string-arrays.js"
export function controlKeybindAssignments({
getMode,
getWaiting,
setWaiting,
getShowDialog,
setShowDialog,
setKeysPressed,
getKeysPressed,
getBindingsDraft,
setBindingsDraft,
getWaiting,
setWaiting,
}: {

@@ -19,8 +24,15 @@ getMode: () => string

setBindingsDraft: (b: Bindings) => void
getWaiting: () => undefined | Waiting
getShowDialog: StateGetter<boolean>
setShowDialog: StateSetter<boolean>
getKeysPressed: StateGetter<string[]>
setKeysPressed: StateSetter<string[]>
getWaiting: StateGetter<Waiting | undefined>
setWaiting: StateSetter<undefined | Waiting>
}) {
const key_set = new Set<string>()
return (event: NubCauseEvent) => {
const waiting = getWaiting()
const is_dialog_shown = getShowDialog()

@@ -30,11 +42,23 @@ if (waiting && event.detail.kind === "key") {

const {effect, keyIndex} = waiting
if (pressed) {
setWaiting(undefined)
const isEscapeKey = cause === "Escape"
if (is_dialog_shown) {
if (isEscapeKey) {
setShowDialog(false)
setWaiting(undefined)
key_set.clear()
}
else {
key_set.add(cause)
setKeysPressed(Array.from(key_set))
}
}
const mode = getMode()
const bindings = getBindingsDraft()
const isEscapeKey = cause === "Escape"
const keybinds = bindings[mode].key[effect]
const redundant = keybinds.some(c => c === cause)
const combo_cause = getKeysPressed()
const keybinds = bindings.modes[mode].key[effect]
const redundant = keybinds.some(c => compareStringArrays(c, combo_cause))

@@ -45,3 +69,3 @@ if (!redundant) {

else
keybinds[keyIndex] = cause
keybinds[keyIndex] = combo_cause

@@ -48,0 +72,0 @@ setBindingsDraft(bindings)

@@ -6,5 +6,5 @@

import {Waiting} from "../types/waiting.js"
import {when} from "../../../../../tools/when.js"
import {buttonLabels} from "../../../utils/constants.js"
import {renderKeycap} from "../renderers/render-keycap.js"
import {when} from "../../../../../tools/when.js"

@@ -19,3 +19,3 @@ export const KeybindView = view({}, use => ({

effect: string
keycodes: string[]
keycodes: string[][]
waiting: undefined | Waiting

@@ -22,0 +22,0 @@ onClickRebind: (keyIndex: number) => void

@@ -10,3 +10,3 @@ import { Bindings } from "./types/bindings.js";

});
get defaults(): Bindings;
get defaults(): import("./types/bindings.js").Bindings2;
get schema(): BindingsSchema;

@@ -13,0 +13,0 @@ set schema(s: BindingsSchema);

@@ -16,2 +16,4 @@ var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {

import { default_bindings_schema } from "./default_bindings_schema.js";
import { detect_bindings_version } from "./utils/detect_bindings_version.js";
import { migrate_bindings_to_latest_version } from "./utils/migrate_bindings_to_latest_version.js";
export class Bindings_Controller {

@@ -50,4 +52,5 @@ constructor({ storage, on_bindings_change }) {

var _a;
__classPrivateFieldSet(this, _Bindings_Controller_bindings, ((_a = __classPrivateFieldGet(this, _Bindings_Controller_store, "f")[this.storage_key]) !== null && _a !== void 0 ? _a : this.defaults), "f");
__classPrivateFieldGet(this, _Bindings_Controller_on_bindings_change, "f").call(this, __classPrivateFieldGet(this, _Bindings_Controller_bindings, "f"));
const read_bindings = ((_a = __classPrivateFieldGet(this, _Bindings_Controller_store, "f")[this.storage_key]) !== null && _a !== void 0 ? _a : this.defaults);
const bindings_version = detect_bindings_version(read_bindings);
this.bindings = migrate_bindings_to_latest_version(read_bindings, bindings_version);
}

@@ -54,0 +57,0 @@ }

@@ -6,3 +6,3 @@ export declare const default_mode = "humanoid";

look: {
causes: string[];
causes: string[][];
};

@@ -12,6 +12,6 @@ };

move: {
causes: string[];
causes: string[][];
};
look: {
causes: string[];
causes: string[][];
};

@@ -21,54 +21,54 @@ };

open_menu: {
causes: string[];
causes: string[][];
};
move_forward: {
causes: string[];
causes: string[][];
};
move_backward: {
causes: string[];
causes: string[][];
};
move_leftward: {
causes: string[];
causes: string[][];
};
move_rightward: {
causes: string[];
causes: string[][];
};
move_fast: {
causes: string[];
causes: string[][];
};
move_slow: {
causes: string[];
causes: string[][];
};
jump: {
causes: string[];
causes: string[][];
};
crouch: {
causes: string[];
causes: string[][];
};
use: {
causes: string[];
causes: string[][];
};
primary: {
causes: string[];
causes: string[][];
};
secondary: {
causes: string[];
causes: string[][];
};
look_up: {
causes: string[];
causes: string[][];
};
look_down: {
causes: string[];
causes: string[][];
};
look_left: {
causes: string[];
causes: string[][];
};
look_right: {
causes: string[];
causes: string[][];
};
look_fast: {
causes: string[];
causes: string[][];
};
look_slow: {
causes: string[];
causes: string[][];
};

@@ -80,3 +80,3 @@ };

close_menu: {
causes: string[];
causes: string[][];
};

@@ -83,0 +83,0 @@ };

@@ -5,27 +5,27 @@ export const default_mode = "humanoid";

pointer: {
look: { causes: ["Pointer", "Lookpad"] },
look: { causes: [["Pointer"], ["Lookpad"]] },
},
stick: {
move: { causes: ["Stick"] },
look: { causes: ["Stick2"] },
move: { causes: [["Stick"]] },
look: { causes: [["Stick2"]] },
},
key: {
open_menu: { causes: ["KeyQ", "Backquote"] },
move_forward: { causes: ["KeyE", "ArrowUp"] },
move_backward: { causes: ["KeyD", "ArrowDown"] },
move_leftward: { causes: ["KeyS", "ArrowLeft"] },
move_rightward: { causes: ["KeyF", "ArrowRight"] },
move_fast: { causes: ["ShiftLeft"] },
move_slow: { causes: ["CapsLock"] },
jump: { causes: ["Space"] },
crouch: { causes: ["KeyZ"] },
use: { causes: ["KeyG", "Mouse3"] },
primary: { causes: ["Mouse1"] },
secondary: { causes: ["Mouse2"] },
look_up: { causes: ["KeyI"] },
look_down: { causes: ["KeyK"] },
look_left: { causes: ["KeyJ"] },
look_right: { causes: ["KeyL"] },
look_fast: { causes: ["Slash"] },
look_slow: { causes: ["Period"] },
open_menu: { causes: [["KeyQ"], ["Backquote"]] },
move_forward: { causes: [["KeyE"], ["ArrowUp"]] },
move_backward: { causes: [["KeyD"], ["ArrowDown"]] },
move_leftward: { causes: [["KeyS"], ["ArrowLeft"]] },
move_rightward: { causes: [["KeyF"], ["ArrowRight"]] },
move_fast: { causes: [["ShiftLeft"]] },
move_slow: { causes: [["CapsLock"]] },
jump: { causes: [["Space"]] },
crouch: { causes: [["KeyZ"]] },
use: { causes: [["KeyG"], ["Mouse3"]] },
primary: { causes: [["Mouse1"]] },
secondary: { causes: [["Mouse2"]] },
look_up: { causes: [["KeyI"]] },
look_down: { causes: [["KeyK"]] },
look_left: { causes: [["KeyJ"]] },
look_right: { causes: [["KeyL"]] },
look_fast: { causes: [["Slash"]] },
look_slow: { causes: [["Period"]] },
},

@@ -35,3 +35,3 @@ },

key: {
close_menu: { causes: ["KeyQ", "Backquote"] },
close_menu: { causes: [["KeyQ"], ["Backquote"]] },
},

@@ -38,0 +38,0 @@ },

import { obtool } from "@chasemoskal/magical";
export function extract_bindings(decorated) {
return obtool(decorated).map(mode => obtool(mode).map(kind => obtool(kind).map(bind => bind.causes)));
return {
version: 2,
modes: obtool(decorated).map(mode => obtool(mode).map(kind => obtool(kind).map(bind => bind.causes)))
};
}
//# sourceMappingURL=extract_bindings.js.map
import { Bindings } from "./types/bindings.js";
import { NubDetail } from "../../../events/types/detail.js";
import { ReadableSet } from "../../../tools/regulated-set/types/readable-set.js";
export declare function find_effects_for_cause_by_consulting_bindings({ modes, bindings, cause_detail, }: {
export declare function find_effects_for_cause_by_consulting_bindings({ modes, bindings, keys_pressed, cause_detail, }: {
bindings: Bindings;
keys_pressed: Set<string>;
modes: ReadableSet<string>;
cause_detail: NubDetail.Any;
}): Set<string>;

@@ -1,11 +0,15 @@

export function find_effects_for_cause_by_consulting_bindings({ modes, bindings, cause_detail, }) {
const { kind, cause } = cause_detail;
import { compareStringArrays } from "../../../tools/compare-string-arrays.js";
export function find_effects_for_cause_by_consulting_bindings({ modes, bindings, keys_pressed, cause_detail, }) {
const { kind } = cause_detail;
const cause = Array.from(keys_pressed);
const matching_effect_names = new Set();
modes.forEach(mode => {
var _a, _b;
const kindbinds = (_a = bindings[mode]) !== null && _a !== void 0 ? _a : {};
const kindbinds = (_a = bindings.modes[mode]) !== null && _a !== void 0 ? _a : {};
const binds = (_b = kindbinds[kind]) !== null && _b !== void 0 ? _b : {};
for (const [effect, bindlist] of Object.entries(binds)) {
if (bindlist.includes(cause)) {
matching_effect_names.add(effect);
for (const bind of bindlist) {
if (compareStringArrays(bind, cause)) {
matching_effect_names.add(effect);
}
}

@@ -12,0 +16,0 @@ }

@@ -1,2 +0,1 @@

import { Bindings } from "../types/bindings.js";
export declare function text_to_bindings(text: string | undefined): Bindings | undefined;
export declare function text_to_bindings(text: string | undefined): import("../types/bindings.js").Bindings2 | undefined;

@@ -6,3 +6,3 @@ import { SVGTemplateResult, TemplateResult } from "lit";

[effect: string]: {
causes: string[];
causes: string[][];
label?: string;

@@ -9,0 +9,0 @@ icon?: SVGTemplateResult | TemplateResult;

@@ -1,2 +0,2 @@

export type Bindings = {
export type Bindings1 = {
[mode: string]: {

@@ -8,1 +8,12 @@ [kind: string]: {

};
export type Bindings2 = {
version: number;
modes: {
[mode: string]: {
[kind: string]: {
[effect: string]: string[][];
};
};
};
};
export type Bindings = Bindings2;
import { Bindings } from "../bindings/types/bindings.js";
type OnBindingsChange = (bindings: Bindings) => void;
export declare function setup_bindings_and_handle_changes(onChange: OnBindingsChange): {
bindings: Bindings;
bindings: import("../bindings/types/bindings.js").Bindings2;
};
export {};
import { clone } from "../../../tools/clone.js";
export function setup_bindings_and_handle_changes(onChange) {
let bindings = {};
let bindings;
const cloneBindings = () => clone(bindings);

@@ -5,0 +5,0 @@ return {

import { find_effects_for_cause_by_consulting_bindings } from "../bindings/find_effects_for_cause_by_consulting_bindings.js";
export const setup_cause_and_effect_translation = ({ modes, effects, dispatch_effect, get_current_bindings, }) => (({ detail: cause_detail }) => {
const matching_effect_names = (find_effects_for_cause_by_consulting_bindings({
modes,
cause_detail,
bindings: get_current_bindings(),
}));
for (const effect of matching_effect_names) {
const effect_detail = { ...cause_detail, effect };
effects[cause_detail.kind][effect] = effect_detail;
dispatch_effect(effect_detail);
}
});
export const setup_cause_and_effect_translation = ({ modes, effects, dispatch_effect, get_current_bindings, }) => {
const keys_pressed = new Set();
return ({ detail: cause_detail }) => {
if (cause_detail.kind === "key") {
if (cause_detail.pressed) {
keys_pressed.add(cause_detail.cause);
}
else {
keys_pressed.delete(cause_detail.cause);
}
}
const matching_effect_names = (find_effects_for_cause_by_consulting_bindings({
modes,
keys_pressed,
cause_detail,
bindings: get_current_bindings(),
}));
const causes = Array.from(keys_pressed).join(" ");
for (const effect of matching_effect_names) {
const effect_detail = { ...cause_detail, effect, cause: causes };
effects[cause_detail.kind][effect] = effect_detail;
dispatch_effect(effect_detail);
}
};
};
//# sourceMappingURL=setup_cause_and_effect_translation.js.map

@@ -34,3 +34,3 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {

const [editingApproach, setEditingApproach] = use.state("gui");
const availableModes = Object.keys(bindingsDraft);
const availableModes = Object.keys(bindingsDraft.modes);
const [primaryMode = default_mode] = availableModes;

@@ -37,0 +37,0 @@ const [, setMode, getMode] = use.state(primaryMode);

@@ -137,2 +137,25 @@ import { css } from "@chasemoskal/magical";

.dialog {
position: fixed;
inset: 0;
display: grid;
place-items: center;
> div {
gap: 1rem;
padding: 2rem;
display: flex;
flex-direction: column;
background: fixed linear-gradient(180deg, #1b2941, #0c0511);
> input {
color: white;
background: transparent;
border: 1px solid #363636;
text-align: center;
padding: 0.5em;
}
}
}
.problem {

@@ -139,0 +162,0 @@ color: orange;

import { html } from "lit";
import { view } from "@chasemoskal/magical";
import { when } from "../../../tools/when.js";
import { NubCauseEvent } from "../../../events/cause.js";
import { renderKeybind } from "./gui/renderers/render-keybind.js";
import { BindingsDialogView } from "./gui/views/bindings-dialog.js";
import { controlKeybindAssignments } from "./gui/utils/control-keybind-assignments.js";

@@ -9,2 +11,4 @@ export const GuiEditorPanelView = view({}, use => ({ bindingsDraft, setBindingsDraft, getBindingsDraft, availableModes, getMode, setMode, listenForCauseEventsOn, }) => {

const [waiting, setWaiting, getWaiting] = use.state(undefined);
const [showDialog, setShowDialog, getShowDialog] = use.state(false);
const [keysPressed, setKeysPressed, getKeysPressed] = use.state([]);
use.setup(() => NubCauseEvent

@@ -18,5 +22,9 @@ .target(listenForCauseEventsOn)

setBindingsDraft,
setKeysPressed,
getShowDialog,
setShowDialog,
getKeysPressed
})));
const mode = getMode();
const kindbinds = bindingsDraft[mode];
const kindbinds = bindingsDraft.modes[mode];
const keybinds = (_a = kindbinds === null || kindbinds === void 0 ? void 0 : kindbinds.key) !== null && _a !== void 0 ? _a : {};

@@ -39,5 +47,10 @@ return html `

.entries(keybinds)
.map(renderKeybind(waiting, setWaiting))}
.map(renderKeybind(waiting, setWaiting, setShowDialog))}
</div>
${when(showDialog, () => BindingsDialogView({
keysPressed,
setKeysPressed
}))}
</div>

@@ -44,0 +57,0 @@ `;

import { StateSetter } from "@chasemoskal/magical";
import { Waiting } from "../types/waiting.js";
export declare function renderKeybind(waiting: undefined | Waiting, setWaiting: StateSetter<undefined | Waiting>): ([effect, keycodes]: [string, string[]]) => void | import("lit-html").TemplateResult;
export declare function renderKeybind(waiting: undefined | Waiting, setWaiting: StateSetter<undefined | Waiting>, setShowDialog: StateSetter<boolean>): ([effect, keycodes]: [string, string[][]]) => void | import("lit-html").TemplateResult;
import { KeybindView } from "../views/keybind.js";
export function renderKeybind(waiting, setWaiting) {
export function renderKeybind(waiting, setWaiting, setShowDialog) {
return ([effect, keycodes]) => KeybindView({

@@ -8,2 +8,3 @@ effect,

onClickRebind(keyIndex) {
setShowDialog(true);
setWaiting({

@@ -15,2 +16,3 @@ effect,

onClickAddNewBind() {
setShowDialog(true);
setWaiting({

@@ -17,0 +19,0 @@ effect,

@@ -6,2 +6,2 @@ import { Waiting } from "../types/waiting.js";

onClickRebind: (keyIndex: number) => void;
}): (code: string, keyIndex: number) => void | import("lit-html").TemplateResult;
}): (code: string[], keyIndex: number) => void | import("lit-html").TemplateResult;

@@ -5,3 +5,3 @@ import { KeycapView } from "../views/keycap.js";

keyIndex,
code: code ? code : "-",
code: code.length ? code.join(" ") : "-",
isWaiting: (currentlyWaitingForThisEffect &&

@@ -8,0 +8,0 @@ (waiting === null || waiting === void 0 ? void 0 : waiting.keyIndex) === keyIndex),

@@ -1,11 +0,15 @@

import { StateSetter } from "@chasemoskal/magical/x/view/types.js";
import { StateGetter, StateSetter } from "@chasemoskal/magical/x/view/types.js";
import { Waiting } from "../types/waiting.js";
import { NubCauseEvent } from "../../../../../events/cause.js";
import { Bindings } from "../../../../context/bindings/types/bindings.js";
export declare function controlKeybindAssignments({ getMode, getBindingsDraft, setBindingsDraft, getWaiting, setWaiting, }: {
export declare function controlKeybindAssignments({ getMode, getWaiting, setWaiting, getShowDialog, setShowDialog, setKeysPressed, getKeysPressed, getBindingsDraft, setBindingsDraft, }: {
getMode: () => string;
getBindingsDraft: () => Bindings;
setBindingsDraft: (b: Bindings) => void;
getWaiting: () => undefined | Waiting;
getShowDialog: StateGetter<boolean>;
setShowDialog: StateSetter<boolean>;
getKeysPressed: StateGetter<string[]>;
setKeysPressed: StateSetter<string[]>;
getWaiting: StateGetter<Waiting | undefined>;
setWaiting: StateSetter<undefined | Waiting>;
}): (event: NubCauseEvent) => void;

@@ -1,4 +0,7 @@

export function controlKeybindAssignments({ getMode, getBindingsDraft, setBindingsDraft, getWaiting, setWaiting, }) {
import { compareStringArrays } from "../../../../../tools/compare-string-arrays.js";
export function controlKeybindAssignments({ getMode, getWaiting, setWaiting, getShowDialog, setShowDialog, setKeysPressed, getKeysPressed, getBindingsDraft, setBindingsDraft, }) {
const key_set = new Set();
return (event) => {
const waiting = getWaiting();
const is_dialog_shown = getShowDialog();
if (waiting && event.detail.kind === "key") {

@@ -8,8 +11,19 @@ const { cause, pressed } = event.detail;

if (pressed) {
setWaiting(undefined);
const isEscapeKey = cause === "Escape";
if (is_dialog_shown) {
if (isEscapeKey) {
setShowDialog(false);
setWaiting(undefined);
key_set.clear();
}
else {
key_set.add(cause);
setKeysPressed(Array.from(key_set));
}
}
const mode = getMode();
const bindings = getBindingsDraft();
const isEscapeKey = cause === "Escape";
const keybinds = bindings[mode].key[effect];
const redundant = keybinds.some(c => c === cause);
const combo_cause = getKeysPressed();
const keybinds = bindings.modes[mode].key[effect];
const redundant = keybinds.some(c => compareStringArrays(c, combo_cause));
if (!redundant) {

@@ -19,3 +33,3 @@ if (isEscapeKey)

else
keybinds[keyIndex] = cause;
keybinds[keyIndex] = combo_cause;
setBindingsDraft(bindings);

@@ -22,0 +36,0 @@ }

import { Waiting } from "../types/waiting.js";
export declare const KeybindView: import("@chasemoskal/magical").View<[{
effect: string;
keycodes: string[];
keycodes: string[][];
waiting: undefined | Waiting;

@@ -6,0 +6,0 @@ onClickRebind: (keyIndex: number) => void;

import { html } from "lit";
import { view } from "@chasemoskal/magical";
import { when } from "../../../../../tools/when.js";
import { buttonLabels } from "../../../utils/constants.js";
import { renderKeycap } from "../renderers/render-keycap.js";
import { when } from "../../../../../tools/when.js";
export const KeybindView = view({}, use => ({ effect, keycodes, waiting, onClickRebind, onClickAddNewBind, }) => {

@@ -7,0 +7,0 @@ const currentlyWaitingForThisEffect = (waiting === null || waiting === void 0 ? void 0 : waiting.effect) === effect;

@@ -34,6 +34,6 @@ import { Bindings } from "../elements/context/bindings/types/bindings.js";

stopPropagation(): void;
readonly AT_TARGET: number;
readonly BUBBLING_PHASE: number;
readonly CAPTURING_PHASE: number;
readonly NONE: number;
readonly NONE: 0;
readonly CAPTURING_PHASE: 1;
readonly AT_TARGET: 2;
readonly BUBBLING_PHASE: 3;
};

@@ -70,6 +70,6 @@ readonly type: string;

stopPropagation(): void;
readonly AT_TARGET: number;
readonly BUBBLING_PHASE: number;
readonly CAPTURING_PHASE: number;
readonly NONE: number;
readonly NONE: 0;
readonly CAPTURING_PHASE: 1;
readonly AT_TARGET: 2;
readonly BUBBLING_PHASE: 3;
}) => void, options?: boolean | AddEventListenerOptions | undefined): () => void;

@@ -76,0 +76,0 @@ };

var _a;
import { ev, MagicEventBase } from "@chasemoskal/magical";
class NubCauseEvent extends MagicEventBase {
export class NubCauseEvent extends MagicEventBase {
}

@@ -8,3 +8,2 @@ _a = NubCauseEvent;

NubCauseEvent.target = ev(_a).target;
export { NubCauseEvent };
//# sourceMappingURL=cause.js.map
var _a;
import { ev, MagicEventBase } from "@chasemoskal/magical";
class NubEffectEvent extends MagicEventBase {
export class NubEffectEvent extends MagicEventBase {
static switch(event, handlers) {

@@ -15,3 +15,2 @@ switch (event.detail.kind) {

NubEffectEvent.target = ev(_a).target;
export { NubEffectEvent };
//# sourceMappingURL=effect.js.map

@@ -34,6 +34,6 @@ import { ReadableSet } from "../tools/regulated-set/types/readable-set.js";

stopPropagation(): void;
readonly AT_TARGET: number;
readonly BUBBLING_PHASE: number;
readonly CAPTURING_PHASE: number;
readonly NONE: number;
readonly NONE: 0;
readonly CAPTURING_PHASE: 1;
readonly AT_TARGET: 2;
readonly BUBBLING_PHASE: 3;
};

@@ -70,6 +70,6 @@ readonly type: string;

stopPropagation(): void;
readonly AT_TARGET: number;
readonly BUBBLING_PHASE: number;
readonly CAPTURING_PHASE: number;
readonly NONE: number;
readonly NONE: 0;
readonly CAPTURING_PHASE: 1;
readonly AT_TARGET: 2;
readonly BUBBLING_PHASE: 3;
}) => void, options?: boolean | AddEventListenerOptions | undefined): () => void;

@@ -76,0 +76,0 @@ };

@@ -21,2 +21,4 @@ {

"asynckit": "/node_modules/asynckit/index.js",
"axios/": "/node_modules/axios/",
"axios": "/node_modules/axios/index.js",
"balanced-match/": "/node_modules/balanced-match/",

@@ -26,4 +28,2 @@ "balanced-match": "/node_modules/balanced-match/index.js",

"base-64": "/node_modules/base-64/base64.js",
"base64-js/": "/node_modules/base64-js/",
"base64-js": "/node_modules/base64-js/index.js",
"body-parser/": "/node_modules/body-parser/",

@@ -33,5 +33,3 @@ "broadcastchannel-polyfill/": "/node_modules/broadcastchannel-polyfill/",

"bson/": "/node_modules/bson/",
"bson": "/node_modules/bson/dist/bson.esm.js",
"buffer/": "/node_modules/buffer/",
"buffer": "/node_modules/buffer/index.js",
"bson": "/node_modules/bson/lib/bson.mjs",
"buffer-equal-constant-time/": "/node_modules/buffer-equal-constant-time/",

@@ -79,3 +77,3 @@ "buffer-equal-constant-time": "/node_modules/buffer-equal-constant-time/index.js",

"glob/": "/node_modules/glob/",
"glob": "/node_modules/glob/glob.js",
"glob": "/node_modules/glob/dist/mjs/index.js",
"has/": "/node_modules/has/",

@@ -86,6 +84,2 @@ "has": "/node_modules/has/src",

"http-errors/": "/node_modules/http-errors/",
"ieee754/": "/node_modules/ieee754/",
"ieee754": "/node_modules/ieee754/index.js",
"inflight/": "/node_modules/inflight/",
"inflight": "/node_modules/inflight/inflight.js",
"inherits/": "/node_modules/inherits/",

@@ -113,4 +107,9 @@ "inherits": "/node_modules/inherits/inherits.js",

"lit-html": "/node_modules/lit-html/lit-html.js",
"lodash/": "/node_modules/lodash/",
"lodash": "/node_modules/lodash/lodash.js",
"lodash.includes/": "/node_modules/lodash.includes/",
"lodash.isboolean/": "/node_modules/lodash.isboolean/",
"lodash.isinteger/": "/node_modules/lodash.isinteger/",
"lodash.isnumber/": "/node_modules/lodash.isnumber/",
"lodash.isplainobject/": "/node_modules/lodash.isplainobject/",
"lodash.isstring/": "/node_modules/lodash.isstring/",
"lodash.once/": "/node_modules/lodash.once/",
"lru-cache/": "/node_modules/lru-cache/",

@@ -127,2 +126,4 @@ "lru-cache": "/node_modules/lru-cache/index.js",

"mime-types/": "/node_modules/mime-types/",
"minipass/": "/node_modules/minipass/",
"minipass": "/node_modules/minipass/dist/mjs/index.js",
"mongodb/": "/node_modules/mongodb/",

@@ -138,6 +139,10 @@ "mongodb": "/node_modules/mongodb/lib/index.js",

"on-finished/": "/node_modules/on-finished/",
"once/": "/node_modules/once/",
"once": "/node_modules/once/once.js",
"parseurl/": "/node_modules/parseurl/",
"path-scurry/": "/node_modules/path-scurry/",
"path-scurry": "/node_modules/path-scurry/dist/mjs/index.js",
"proxy-addr/": "/node_modules/proxy-addr/",
"proxy-from-env/": "/node_modules/proxy-from-env/",
"proxy-from-env": "/node_modules/proxy-from-env/index.js",
"punycode/": "/node_modules/punycode/",
"punycode": "/node_modules/punycode/punycode.es6.js",
"qs/": "/node_modules/qs/",

@@ -169,3 +174,3 @@ "qs": "/node_modules/qs/lib/index.js",

"stripe/": "/node_modules/stripe/",
"stripe": "/node_modules/stripe/lib/stripe.node.js",
"stripe": "/node_modules/stripe/cjs/stripe.cjs.node.js",
"toidentifier/": "/node_modules/toidentifier/",

@@ -191,4 +196,2 @@ "tr46/": "/node_modules/tr46/",

"whatwg-url": "/node_modules/whatwg-url/index.js",
"wrappy/": "/node_modules/wrappy/",
"wrappy": "/node_modules/wrappy/wrappy.js",
"ws/": "/node_modules/ws/",

@@ -202,6 +205,2 @@ "ws": "/node_modules/ws/index.js",

"scopes": {
"/node_modules/accepts/": {
"mime-db/": "/node_modules/accepts/node_modules/mime-db/",
"mime-types/": "/node_modules/accepts/node_modules/mime-types/"
},
"/node_modules/body-parser/": {

@@ -237,7 +236,9 @@ "bytes/": "/node_modules/body-parser/node_modules/bytes/",

"minimatch/": "/node_modules/glob/node_modules/minimatch/",
"minimatch": "/node_modules/glob/node_modules/minimatch/minimatch.js"
"minimatch": "/node_modules/glob/node_modules/minimatch/dist/mjs/index.js",
"minipass/": "/node_modules/glob/node_modules/minipass/",
"minipass": "/node_modules/glob/node_modules/minipass/index.mjs"
},
"/node_modules/mailgun.js/": {
"axios/": "/node_modules/mailgun.js/node_modules/axios/",
"axios": "/node_modules/mailgun.js/node_modules/axios/index.js"
"/node_modules/path-scurry/": {
"lru-cache/": "/node_modules/path-scurry/node_modules/lru-cache/",
"lru-cache": "/node_modules/path-scurry/node_modules/lru-cache/dist/mjs/index.js"
},

@@ -258,15 +259,9 @@ "/node_modules/raw-body/": {

},
"/node_modules/tr46/": {
"punycode/": "/node_modules/tr46/node_modules/punycode/",
"punycode": "/node_modules/tr46/node_modules/punycode/punycode.es6.js"
},
"/node_modules/type-is/": {
"mime-db/": "/node_modules/type-is/node_modules/mime-db/",
"mime-types/": "/node_modules/type-is/node_modules/mime-types/"
},
"/node_modules/xiome/": {
"chalk/": "/node_modules/xiome/node_modules/chalk/",
"chalk": "/node_modules/xiome/node_modules/chalk/source/index.js"
"chalk": "/node_modules/xiome/node_modules/chalk/source/index.js",
"renraku/": "/node_modules/xiome/node_modules/renraku/",
"renraku": "/node_modules/xiome/node_modules/renraku/x/renraku.js"
}
}
}

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc