@@ -16,13 +16,9 @@ import {
1616} from "zmk-studio-ts-client/keymap" ;
1717import type { GetBehaviorDetailsResponse } from "zmk-studio-ts-client/behaviors" ;
1818
19- import {
20- hid_usage_get_label ,
21- hid_usage_page_and_id_from_usage ,
22- } from "../hid-usages" ;
2319import { LayerPicker } from "./LayerPicker" ;
24- import { PhysicalLayout as PhysicalLayoutComp } from "./PhysicalLayout" ;
2520import { PhysicalLayoutPicker } from "./PhysicalLayoutPicker" ;
21+ import { Keymap as KeymapComp } from "./Keymap" ;
2622import { useConnectedDeviceData } from "../rpc/useConnectedDeviceData" ;
2723import { ConnectionContext } from "../rpc/ConnectionContext" ;
2824import { UndoRedoContext } from "../undoRedo" ;
@@ -31,49 +27,6 @@ import { produce } from "immer";
3127
3228type BehaviorMap = Record < number , GetBehaviorDetailsResponse > ;
3329
34- function renderLayout (
35- layout : PhysicalLayout ,
36- keymap : Keymap ,
37- behaviors : BehaviorMap ,
38- selectedLayoutIndex : number ,
39- selectedKeyPosition : number | undefined ,
40- setSelectedKeyPosition : React . Dispatch < SetStateAction < number | undefined > > ,
41- ) {
42- if ( ! keymap . layers [ selectedLayoutIndex ] ) {
43- return < > </ > ;
44- }
45-
46- let positions = layout . keys . map ( ( k , i ) => {
47- let [ page , id ] = hid_usage_page_and_id_from_usage (
48- keymap . layers [ selectedLayoutIndex ] . bindings [ i ] . param1 ,
49- ) ;
50-
51- // TODO: Do something with implicit mods!
52- page &= 0xff ;
53-
54- let label = hid_usage_get_label ( page , id ) ?. replace ( / ^ K e y b o a r d / , "" ) ;
55-
56- return {
57- header :
58- behaviors [ keymap . layers [ selectedLayoutIndex ] . bindings [ i ] . behaviorId ]
59- ?. displayName || "Unknown" ,
60- x : k . x / 100.0 ,
61- y : k . y / 100.0 ,
62- width : k . width / 100 ,
63- height : k . height / 100.0 ,
64- children : < span > { label } </ span > ,
65- } ;
66- } ) ;
67-
68- return (
69- < PhysicalLayoutComp
70- positions = { positions }
71- selectedPosition = { selectedKeyPosition }
72- onPositionClicked = { setSelectedKeyPosition }
73- />
74- ) ;
75- }
76-
7730function useBehaviors ( ) : BehaviorMap {
7831 let connection = useContext ( ConnectionContext ) ;
7932
@@ -349,14 +302,7 @@ export default function Keyboard() {
349302 ) }
350303 { layouts && keymap && behaviors && (
351304 < div className = "col-start-2 row-start-1 grid items-center justify-center" >
352- { renderLayout (
353- layouts [ selectedPhysicalLayoutIndex ] ,
354- keymap ,
355- behaviors ,
356- selectedLayerIndex ,
357- selectedKeyPosition ,
358- setSelectedKeyPosition ,
359- ) }
305+ < KeymapComp keymap = { keymap } layout = { layouts [ selectedPhysicalLayoutIndex ] } behaviors = { behaviors } selectedLayerIndex = { selectedLayerIndex } selectedKeyPosition = { selectedKeyPosition } onKeyPositionClicked = { setSelectedKeyPosition } />
360306 </ div >
361307 ) }
362308 { keymap && selectedBinding && (
0 commit comments