jy-headless 0.0.19 → 0.0.20

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,5 +1,5 @@
1
1
  import React, { ButtonHTMLAttributes, ReactNode } from 'react';
2
- interface ButtonProps extends ButtonHTMLAttributes<HTMLButtonElement> {
2
+ export interface ButtonProps extends ButtonHTMLAttributes<HTMLButtonElement> {
3
3
  loading?: boolean;
4
4
  spinner?: ReactNode;
5
5
  prefixElement?: ReactNode;
@@ -0,0 +1,20 @@
1
+ import React, { CSSProperties } from 'react';
2
+ type KeyboardLayout = 'full-size' | 'tenkeyless' | 'compact-96';
3
+ interface DesktopKeyboardInputProps {
4
+ type?: KeyboardLayout;
5
+ hasFunction?: boolean;
6
+ hasNumpad?: boolean;
7
+ cellStyle?: CSSProperties;
8
+ cellClassName?: string;
9
+ activeCellStyle?: CSSProperties;
10
+ activeCellClassName?: string;
11
+ style?: CSSProperties;
12
+ className?: string;
13
+ resetStyle?: boolean;
14
+ isKor?: boolean;
15
+ onKeyDown?: (e: any) => void;
16
+ onKeyUp?: (e: any) => void;
17
+ cellSize?: string;
18
+ }
19
+ declare const DesktopKeyboardInput: ({ type, hasFunction, hasNumpad, cellStyle, cellClassName, activeCellStyle, activeCellClassName, style, className, onKeyDown, onKeyUp, }: DesktopKeyboardInputProps) => React.JSX.Element;
20
+ export default DesktopKeyboardInput;
@@ -0,0 +1,18 @@
1
+ import React, { ReactNode } from 'react';
2
+ import { ButtonProps } from '../button/Button';
3
+ interface ModalProps {
4
+ opener: ReactNode;
5
+ children: ReactNode;
6
+ targetSelector?: string;
7
+ }
8
+ interface ModalComposition {
9
+ Overlay?: React.FC<ModalOverlayProps>;
10
+ Closer?: React.FC<ButtonProps>;
11
+ }
12
+ declare const Modal: React.FC<ModalProps> & ModalComposition;
13
+ interface ModalOverlayProps {
14
+ backgroundColor?: string;
15
+ zIndex?: number;
16
+ children: ReactNode;
17
+ }
18
+ export default Modal;
package/dist/index.d.ts CHANGED
@@ -1,7 +1,8 @@
1
1
  import Button from './components/button/Button';
2
2
  import Input from './components/input/Input';
3
+ import DesktopKeyboardInput from './components/input/DesktopKeyboardInput';
3
4
  import Spinner from './components/spinner/Spinner';
4
5
  import RadioInput from './components/radio/RadioInput';
5
6
  import RadioGroup from './components/radio/RadioGroup';
6
7
  import { CallIcon, CloseIcon, HomeIcon, SearchIcon } from './components/icons';
7
- export { Button, Input, Spinner, CallIcon, CloseIcon, HomeIcon, SearchIcon, RadioInput, RadioGroup, };
8
+ export { Button, Input, DesktopKeyboardInput, Spinner, CallIcon, CloseIcon, HomeIcon, SearchIcon, RadioInput, RadioGroup, };
package/dist/index.esm.js CHANGED
@@ -1,4 +1,4 @@
1
- import React, { useState, useMemo, useEffect } from 'react';
1
+ import React, { useState, useEffect, useMemo } from 'react';
2
2
 
3
3
  /******************************************************************************
4
4
  Copyright (c) Microsoft Corporation.
@@ -58,7 +58,7 @@ const Spinner = ({ color = 'black', size = '1em', spinTime = '2s' }) => {
58
58
  };
59
59
 
60
60
  const Button = (_a) => {
61
- var { prefixElement, suffixElement, children, loading = false, spinner = React.createElement(Spinner, { color: 'black', size: '9px' }), style } = _a, restProps = __rest(_a, ["prefixElement", "suffixElement", "children", "loading", "spinner", "style"]);
61
+ var { prefixElement, suffixElement, children, loading = false, spinner = React.createElement(Spinner, { color: 'black', size: '1em' }), style } = _a, restProps = __rest(_a, ["prefixElement", "suffixElement", "children", "loading", "spinner", "style"]);
62
62
  return (React.createElement("button", Object.assign({}, restProps, { style: Object.assign({ display: 'inline-flex', alignItems: 'center' }, style) }),
63
63
  prefixElement,
64
64
  loading ? spinner : children,
@@ -75,6 +75,232 @@ const Input = (_a) => {
75
75
  (typeof error === 'string' ? (React.createElement("span", { style: { position: 'absolute', top: '100%', left: 0 } }, error)) : (error))));
76
76
  };
77
77
 
78
+ const functionRow = [
79
+ [
80
+ { code: 'Escape', label: 'Esc', key: 'Escape' },
81
+ { code: null, label: '', key: '' },
82
+ ],
83
+ [
84
+ { code: 'F1', label: 'F1', key: 'F1' },
85
+ { code: 'F2', label: 'F2', key: 'F2' },
86
+ { code: 'F3', label: 'F3', key: 'F3' },
87
+ { code: 'F4', label: 'F4', key: 'F4' },
88
+ { code: null, label: '', key: '' },
89
+ ],
90
+ [
91
+ { code: 'F5', label: 'F5', key: 'F5' },
92
+ { code: 'F6', label: 'F6', key: 'F6' },
93
+ { code: 'F7', label: 'F7', key: 'F7' },
94
+ { code: 'F8', label: 'F8', key: 'F8' },
95
+ { code: null, label: '', key: '' },
96
+ ],
97
+ [
98
+ { code: 'F9', label: 'F9', key: 'F9' },
99
+ { code: 'F10', label: 'F10', key: 'F10' },
100
+ { code: 'F11', label: 'F11', key: 'F11' },
101
+ { code: 'F12', label: 'F12', key: 'F12' },
102
+ { code: null, label: '', key: '' },
103
+ ],
104
+ [
105
+ { code: 'PrintScreen', label: 'Print Screen', key: 'PrintScreen' },
106
+ { code: 'ScrollLock', label: 'Scroll Lock', key: 'ScrollLock' },
107
+ { code: 'Pause', label: 'Pause', key: 'Pause' },
108
+ ],
109
+ ];
110
+ const numberRow = [
111
+ { code: 'Backquote', label: '~', shiftLabel: '¡', key: '`' },
112
+ { code: 'Digit1', label: '1', shiftLabel: '!', key: '1' },
113
+ { code: 'Digit2', label: '2', shiftLabel: '@', key: '2' },
114
+ { code: 'Digit3', label: '3', shiftLabel: '#', key: '3' },
115
+ { code: 'Digit4', label: '4', shiftLabel: '$', key: '4' },
116
+ { code: 'Digit5', label: '5', shiftLabel: '%', key: '5' },
117
+ { code: 'Digit6', label: '6', shiftLabel: '^', key: '6' },
118
+ { code: 'Digit7', label: '7', shiftLabel: '&', key: '7' },
119
+ { code: 'Digit8', label: '8', shiftLabel: '*', key: '8' },
120
+ { code: 'Digit9', label: '9', shiftLabel: '(', key: '9' },
121
+ { code: 'Digit0', label: '0', shiftLabel: ')', key: '0' },
122
+ { code: 'Minus', label: '-', shiftLabel: '_', key: '-' },
123
+ { code: 'Equal', label: '=', shiftLabel: '+', key: '=' },
124
+ { code: 'Backspace', label: 'Backspace', key: 'Backspace' },
125
+ ];
126
+ const qwertyRow = [
127
+ { code: 'Tab', label: 'Tab', key: 'Tab' },
128
+ { code: 'KeyQ', label: 'q', shiftLabel: 'Q', kor: 'ㅂ', korShift: 'ㅃ', key: 'q' },
129
+ { code: 'KeyW', label: 'w', shiftLabel: 'W', kor: 'ㅈ', korShift: 'ㅉ', key: 'w' },
130
+ { code: 'KeyE', label: 'e', shiftLabel: 'E', kor: 'ㄷ', korShift: 'ㄸ', key: 'e' },
131
+ { code: 'KeyR', label: 'r', shiftLabel: 'R', kor: 'ㄱ', korShift: 'ㄲ', key: 'r' },
132
+ { code: 'KeyT', label: 't', shiftLabel: 'T', kor: 'ㅅ', korShift: 'ㅆ', key: 't' },
133
+ { code: 'KeyY', label: 'y', shiftLabel: 'Y', kor: 'ㅛ', korShift: 'ㅕ', key: 'y' },
134
+ { code: 'KeyU', label: 'u', shiftLabel: 'U', kor: 'ㅕ', korShift: 'ㅕ', key: 'u' },
135
+ { code: 'KeyI', label: 'i', shiftLabel: 'I', kor: 'ㅑ', korShift: 'ㅑ', key: 'i' },
136
+ { code: 'KeyO', label: 'o', shiftLabel: 'O', kor: 'ㅐ', korShift: 'ㅒ', key: 'o' },
137
+ { code: 'KeyP', label: 'p', shiftLabel: 'P', kor: 'ㅔ', korShift: 'ㅖ', key: 'p' },
138
+ { code: 'BracketLeft', label: '[', shiftLabel: '{', kor: null, korShift: null, key: '[' },
139
+ { code: 'BracketRight', label: ']', shiftLabel: '}', kor: null, korShift: null, key: ']' },
140
+ { code: 'Backslash', label: '\\', shiftLabel: '|', kor: null, korShift: null, key: '\\' },
141
+ ];
142
+ const homeRow = [
143
+ { code: 'CapsLock', label: 'Caps Lock', kor: null, korShift: null, key: 'CapsLock' },
144
+ { code: 'KeyA', label: 'a', shiftLabel: 'A', kor: 'ㅁ', korShift: 'ㅁ', key: 'a' },
145
+ { code: 'KeyS', label: 's', shiftLabel: 'S', kor: 'ㄴ', korShift: 'ㄴ', key: 's' },
146
+ { code: 'KeyD', label: 'd', shiftLabel: 'D', kor: 'ㅇ', korShift: 'ㅇ', key: 'd' },
147
+ { code: 'KeyF', label: 'f', shiftLabel: 'F', kor: 'ㄹ', korShift: 'ㄹ', key: 'f' },
148
+ { code: 'KeyG', label: 'g', shiftLabel: 'G', kor: 'ㅎ', korShift: 'ㅎ', key: 'g' },
149
+ { code: 'KeyH', label: 'h', shiftLabel: 'H', kor: 'ㅗ', korShift: 'ㅗ', key: 'h' },
150
+ { code: 'KeyJ', label: 'j', shiftLabel: 'J', kor: 'ㅓ', korShift: 'ㅓ', key: 'j' },
151
+ { code: 'KeyK', label: 'k', shiftLabel: 'K', kor: 'ㅏ', korShift: 'ㅏ', key: 'k' },
152
+ { code: 'KeyL', label: 'l', shiftLabel: 'L', kor: 'ㅣ', korShift: 'ㅣ', key: 'l' },
153
+ { code: 'Semicolon', label: ';', shiftLabel: ':', kor: null, korShift: null, key: ';' },
154
+ { code: 'Quote', label: "'", shiftLabel: '"', kor: null, korShift: null, key: "'" },
155
+ { code: 'Enter', label: 'Enter', kor: null, korShift: null, key: 'Enter' },
156
+ ];
157
+ const bottomRow = [
158
+ { code: 'ShiftLeft', label: 'Shift', kor: null, key: 'Shift' },
159
+ { code: 'KeyZ', label: 'z', shiftLabel: 'Z', kor: 'ㅋ', key: 'z' },
160
+ { code: 'KeyX', label: 'x', shiftLabel: 'X', kor: 'ㅌ', key: 'x' },
161
+ { code: 'KeyC', label: 'c', shiftLabel: 'C', kor: 'ㅊ', key: 'c' },
162
+ { code: 'KeyV', label: 'v', shiftLabel: 'V', kor: 'ㅍ', key: 'v' },
163
+ { code: 'KeyB', label: 'b', shiftLabel: 'B', kor: 'ㅠ', key: 'b' },
164
+ { code: 'KeyN', label: 'n', shiftLabel: 'N', kor: 'ㅜ', key: 'n' },
165
+ { code: 'KeyM', label: 'm', shiftLabel: 'M', kor: 'ㅡ', key: 'm' },
166
+ { code: 'Comma', label: ',', shiftLabel: '<', kor: null, key: ',' },
167
+ { code: 'Period', label: '.', shiftLabel: '>', kor: null, key: '.' },
168
+ { code: 'Slash', label: '/', shiftLabel: '?', kor: null, key: '/' },
169
+ { code: 'ShiftRight', label: 'Shift', kor: null, key: 'Shift' },
170
+ ];
171
+ const spaceRow = [
172
+ { code: 'ControlLeft', label: 'Ctrl', key: 'Control' },
173
+ { code: 'MetaLeft', label: 'Win', key: 'Meta' },
174
+ { code: 'AltLeft', label: 'Alt', key: 'Alt' },
175
+ { code: 'Space', label: 'Space', key: ' ' },
176
+ { code: 'AltRight', label: 'Alt', key: 'Alt' },
177
+ { code: 'Fn', label: 'Fn', key: 'Fn' },
178
+ { code: 'ContextMenu', label: 'Menu', key: 'ContextMenu' },
179
+ { code: 'ControlRight', label: 'Ctrl', key: 'Control' },
180
+ ];
181
+ const DesktopKeyboardInput = ({ type = 'full-size', hasFunction = true, hasNumpad = true, cellStyle = {}, cellClassName = '', activeCellStyle = {}, activeCellClassName = '', style = {}, className = '', onKeyDown, onKeyUp, }) => {
182
+ const [inputKey, setInputKey] = useState([]);
183
+ const [isShift, setIsShift] = useState(false);
184
+ const [isHangulMode, setIsHangulMode] = useState(false);
185
+ const getKeyFromEvent = (keyCode) => {
186
+ var _a, _b;
187
+ let row = null;
188
+ const allRows = [
189
+ ...functionRow.flat(),
190
+ ...numberRow,
191
+ ...qwertyRow,
192
+ ...homeRow,
193
+ ...bottomRow,
194
+ ...spaceRow,
195
+ ];
196
+ row = allRows.find((row) => row.code === keyCode);
197
+ return {
198
+ code: (_a = row.code) !== null && _a !== undefined ? _a : '',
199
+ label: (_b = getLabel(row)) !== null && _b !== undefined ? _b : '',
200
+ };
201
+ };
202
+ const getLabel = (key) => {
203
+ if (isHangulMode) {
204
+ if (isShift) {
205
+ return key.korShift || key.kor || key.shiftLabel || key.label;
206
+ }
207
+ return key.kor || key.label;
208
+ }
209
+ if (isShift) {
210
+ return key.shiftLabel || key.label;
211
+ }
212
+ return key.label;
213
+ };
214
+ useEffect(() => {
215
+ const keyDown = (e) => {
216
+ e.preventDefault();
217
+ setInputKey((prevState) => [...prevState, e.code]);
218
+ if (e.key === 'Shift')
219
+ setIsShift(true);
220
+ onKeyDown === null || onKeyDown === undefined ? undefined : onKeyDown(getKeyFromEvent(e.code));
221
+ };
222
+ const keyUp = (e) => {
223
+ e.preventDefault();
224
+ if (e.key === 'HangulMode') {
225
+ setIsHangulMode((prev) => !prev);
226
+ }
227
+ setInputKey((prevState) => prevState.filter((it) => it !== e.code));
228
+ if (e.key === 'Shift')
229
+ setIsShift(false);
230
+ onKeyUp === null || onKeyUp === undefined ? undefined : onKeyUp(getKeyFromEvent(e.code));
231
+ };
232
+ window.addEventListener('keydown', keyDown);
233
+ window.addEventListener('keyup', keyUp);
234
+ return () => {
235
+ window.removeEventListener('keydown', keyDown);
236
+ window.removeEventListener('keyup', keyUp);
237
+ };
238
+ }, [onKeyDown, onKeyUp, isShift, isHangulMode]);
239
+ const renderRow = (row, rowType) => {
240
+ const getCellStyle = (key) => {
241
+ var _a;
242
+ if (key.code === null)
243
+ return;
244
+ const isActive = inputKey.map((it) => it === null || it === undefined ? undefined : it.toUpperCase()).includes((_a = key.code) === null || _a === undefined ? undefined : _a.toUpperCase()) ||
245
+ (inputKey.includes('HangulMode') && key.code === 'AltRight');
246
+ let gridColumn = '';
247
+ switch (key.code) {
248
+ case 'Space':
249
+ gridColumn = '4/12';
250
+ break;
251
+ case 'ShiftRight':
252
+ gridColumn = '13/15';
253
+ break;
254
+ case 'Backspace':
255
+ gridColumn = '14/16';
256
+ break;
257
+ case 'Tab':
258
+ case 'ShiftLeft':
259
+ case 'CapsLock':
260
+ gridColumn = '1/3';
261
+ break;
262
+ case 'Backslash':
263
+ gridColumn = '15/17';
264
+ break;
265
+ case 'Enter':
266
+ gridColumn = '14/16';
267
+ break;
268
+ }
269
+ return {
270
+ style: Object.assign({ gridColumn }, (isActive ? activeCellStyle : cellStyle)),
271
+ className: isActive ? activeCellClassName : cellClassName,
272
+ };
273
+ };
274
+ const onMouseDown = (key) => {
275
+ if (!key.code)
276
+ return;
277
+ setInputKey([key.code]);
278
+ if (['ShiftRight', 'ShiftLeft'].includes(key.code))
279
+ setIsShift(true);
280
+ onKeyDown === null || onKeyDown === undefined ? undefined : onKeyDown(getKeyFromEvent(key.code));
281
+ };
282
+ const onMouseUp = (key) => {
283
+ if (!key.code)
284
+ return;
285
+ if (key.code === 'AltRight') {
286
+ setIsHangulMode((prev) => !prev);
287
+ }
288
+ setInputKey((prevState) => prevState.filter((it) => it !== key.code));
289
+ if (['ShiftRight', 'ShiftLeft'].includes(key.code))
290
+ setIsShift(false);
291
+ onKeyUp === null || onKeyUp === undefined ? undefined : onKeyUp(getKeyFromEvent(key.code));
292
+ };
293
+ return row.map((key, idx) => (React.createElement("div", Object.assign({ key: `${key.code}-${idx}`, onMouseDown: () => onMouseDown(key), onMouseUp: () => onMouseUp(key) }, getCellStyle(key)), getLabel(key))));
294
+ };
295
+ return (React.createElement("div", { style: style, className: className },
296
+ (['full-size', 'tenkeyless'].includes(type) || hasFunction) && (React.createElement("div", { style: { display: 'grid', gridTemplateColumns: `repeat(20, 1fr)`, gap: '2px' } }, renderRow(functionRow.flat()))),
297
+ React.createElement("div", { style: { display: 'grid', gridTemplateColumns: 'repeat(15, 1fr)', gap: '2px' } }, renderRow(numberRow)),
298
+ React.createElement("div", { style: { display: 'grid', gridTemplateColumns: 'repeat(16, 1fr)', gap: '2px' } }, renderRow(qwertyRow)),
299
+ React.createElement("div", { style: { display: 'grid', gridTemplateColumns: 'repeat(15, 1fr)', gap: '2px' } }, renderRow(homeRow)),
300
+ React.createElement("div", { style: { display: 'grid', gridTemplateColumns: 'repeat(14, 1fr)', gap: '2px' } }, renderRow(bottomRow)),
301
+ React.createElement("div", { style: { display: 'grid', gridTemplateColumns: 'repeat(15, 1fr)', gap: '2px' } }, renderRow(spaceRow))));
302
+ };
303
+
78
304
  const RadioInput = (_a) => {
79
305
  var { clearable = false, children = '', checked = false, onChange, onToggle, style, className, id, defaultChecked, readOnly, showError = false, error = null } = _a, restProps = __rest(_a, ["clearable", "children", "checked", "onChange", "onToggle", "style", "className", "id", "defaultChecked", "readOnly", "showError", "error"]);
80
306
  const [selected, setSelected] = useState(checked || false);
@@ -199,5 +425,5 @@ const SearchIcon = ({ color = '#000', size = '1em', bgColor = 'transparent', fil
199
425
  // AUTHOR: Ankush Syal
200
426
  // https://www.svgrepo.com/svg/520583/call
201
427
 
202
- export { Button, CallIcon, CloseIcon, HomeIcon, Input, RadioGroup, RadioInput, SearchIcon, Spinner };
428
+ export { Button, CallIcon, CloseIcon, DesktopKeyboardInput, HomeIcon, Input, RadioGroup, RadioInput, SearchIcon, Spinner };
203
429
  //# sourceMappingURL=index.esm.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.esm.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
1
+ {"version":3,"file":"index.esm.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
package/dist/index.js CHANGED
@@ -60,7 +60,7 @@ const Spinner = ({ color = 'black', size = '1em', spinTime = '2s' }) => {
60
60
  };
61
61
 
62
62
  const Button = (_a) => {
63
- var { prefixElement, suffixElement, children, loading = false, spinner = React.createElement(Spinner, { color: 'black', size: '9px' }), style } = _a, restProps = __rest(_a, ["prefixElement", "suffixElement", "children", "loading", "spinner", "style"]);
63
+ var { prefixElement, suffixElement, children, loading = false, spinner = React.createElement(Spinner, { color: 'black', size: '1em' }), style } = _a, restProps = __rest(_a, ["prefixElement", "suffixElement", "children", "loading", "spinner", "style"]);
64
64
  return (React.createElement("button", Object.assign({}, restProps, { style: Object.assign({ display: 'inline-flex', alignItems: 'center' }, style) }),
65
65
  prefixElement,
66
66
  loading ? spinner : children,
@@ -77,6 +77,232 @@ const Input = (_a) => {
77
77
  (typeof error === 'string' ? (React.createElement("span", { style: { position: 'absolute', top: '100%', left: 0 } }, error)) : (error))));
78
78
  };
79
79
 
80
+ const functionRow = [
81
+ [
82
+ { code: 'Escape', label: 'Esc', key: 'Escape' },
83
+ { code: null, label: '', key: '' },
84
+ ],
85
+ [
86
+ { code: 'F1', label: 'F1', key: 'F1' },
87
+ { code: 'F2', label: 'F2', key: 'F2' },
88
+ { code: 'F3', label: 'F3', key: 'F3' },
89
+ { code: 'F4', label: 'F4', key: 'F4' },
90
+ { code: null, label: '', key: '' },
91
+ ],
92
+ [
93
+ { code: 'F5', label: 'F5', key: 'F5' },
94
+ { code: 'F6', label: 'F6', key: 'F6' },
95
+ { code: 'F7', label: 'F7', key: 'F7' },
96
+ { code: 'F8', label: 'F8', key: 'F8' },
97
+ { code: null, label: '', key: '' },
98
+ ],
99
+ [
100
+ { code: 'F9', label: 'F9', key: 'F9' },
101
+ { code: 'F10', label: 'F10', key: 'F10' },
102
+ { code: 'F11', label: 'F11', key: 'F11' },
103
+ { code: 'F12', label: 'F12', key: 'F12' },
104
+ { code: null, label: '', key: '' },
105
+ ],
106
+ [
107
+ { code: 'PrintScreen', label: 'Print Screen', key: 'PrintScreen' },
108
+ { code: 'ScrollLock', label: 'Scroll Lock', key: 'ScrollLock' },
109
+ { code: 'Pause', label: 'Pause', key: 'Pause' },
110
+ ],
111
+ ];
112
+ const numberRow = [
113
+ { code: 'Backquote', label: '~', shiftLabel: '¡', key: '`' },
114
+ { code: 'Digit1', label: '1', shiftLabel: '!', key: '1' },
115
+ { code: 'Digit2', label: '2', shiftLabel: '@', key: '2' },
116
+ { code: 'Digit3', label: '3', shiftLabel: '#', key: '3' },
117
+ { code: 'Digit4', label: '4', shiftLabel: '$', key: '4' },
118
+ { code: 'Digit5', label: '5', shiftLabel: '%', key: '5' },
119
+ { code: 'Digit6', label: '6', shiftLabel: '^', key: '6' },
120
+ { code: 'Digit7', label: '7', shiftLabel: '&', key: '7' },
121
+ { code: 'Digit8', label: '8', shiftLabel: '*', key: '8' },
122
+ { code: 'Digit9', label: '9', shiftLabel: '(', key: '9' },
123
+ { code: 'Digit0', label: '0', shiftLabel: ')', key: '0' },
124
+ { code: 'Minus', label: '-', shiftLabel: '_', key: '-' },
125
+ { code: 'Equal', label: '=', shiftLabel: '+', key: '=' },
126
+ { code: 'Backspace', label: 'Backspace', key: 'Backspace' },
127
+ ];
128
+ const qwertyRow = [
129
+ { code: 'Tab', label: 'Tab', key: 'Tab' },
130
+ { code: 'KeyQ', label: 'q', shiftLabel: 'Q', kor: 'ㅂ', korShift: 'ㅃ', key: 'q' },
131
+ { code: 'KeyW', label: 'w', shiftLabel: 'W', kor: 'ㅈ', korShift: 'ㅉ', key: 'w' },
132
+ { code: 'KeyE', label: 'e', shiftLabel: 'E', kor: 'ㄷ', korShift: 'ㄸ', key: 'e' },
133
+ { code: 'KeyR', label: 'r', shiftLabel: 'R', kor: 'ㄱ', korShift: 'ㄲ', key: 'r' },
134
+ { code: 'KeyT', label: 't', shiftLabel: 'T', kor: 'ㅅ', korShift: 'ㅆ', key: 't' },
135
+ { code: 'KeyY', label: 'y', shiftLabel: 'Y', kor: 'ㅛ', korShift: 'ㅕ', key: 'y' },
136
+ { code: 'KeyU', label: 'u', shiftLabel: 'U', kor: 'ㅕ', korShift: 'ㅕ', key: 'u' },
137
+ { code: 'KeyI', label: 'i', shiftLabel: 'I', kor: 'ㅑ', korShift: 'ㅑ', key: 'i' },
138
+ { code: 'KeyO', label: 'o', shiftLabel: 'O', kor: 'ㅐ', korShift: 'ㅒ', key: 'o' },
139
+ { code: 'KeyP', label: 'p', shiftLabel: 'P', kor: 'ㅔ', korShift: 'ㅖ', key: 'p' },
140
+ { code: 'BracketLeft', label: '[', shiftLabel: '{', kor: null, korShift: null, key: '[' },
141
+ { code: 'BracketRight', label: ']', shiftLabel: '}', kor: null, korShift: null, key: ']' },
142
+ { code: 'Backslash', label: '\\', shiftLabel: '|', kor: null, korShift: null, key: '\\' },
143
+ ];
144
+ const homeRow = [
145
+ { code: 'CapsLock', label: 'Caps Lock', kor: null, korShift: null, key: 'CapsLock' },
146
+ { code: 'KeyA', label: 'a', shiftLabel: 'A', kor: 'ㅁ', korShift: 'ㅁ', key: 'a' },
147
+ { code: 'KeyS', label: 's', shiftLabel: 'S', kor: 'ㄴ', korShift: 'ㄴ', key: 's' },
148
+ { code: 'KeyD', label: 'd', shiftLabel: 'D', kor: 'ㅇ', korShift: 'ㅇ', key: 'd' },
149
+ { code: 'KeyF', label: 'f', shiftLabel: 'F', kor: 'ㄹ', korShift: 'ㄹ', key: 'f' },
150
+ { code: 'KeyG', label: 'g', shiftLabel: 'G', kor: 'ㅎ', korShift: 'ㅎ', key: 'g' },
151
+ { code: 'KeyH', label: 'h', shiftLabel: 'H', kor: 'ㅗ', korShift: 'ㅗ', key: 'h' },
152
+ { code: 'KeyJ', label: 'j', shiftLabel: 'J', kor: 'ㅓ', korShift: 'ㅓ', key: 'j' },
153
+ { code: 'KeyK', label: 'k', shiftLabel: 'K', kor: 'ㅏ', korShift: 'ㅏ', key: 'k' },
154
+ { code: 'KeyL', label: 'l', shiftLabel: 'L', kor: 'ㅣ', korShift: 'ㅣ', key: 'l' },
155
+ { code: 'Semicolon', label: ';', shiftLabel: ':', kor: null, korShift: null, key: ';' },
156
+ { code: 'Quote', label: "'", shiftLabel: '"', kor: null, korShift: null, key: "'" },
157
+ { code: 'Enter', label: 'Enter', kor: null, korShift: null, key: 'Enter' },
158
+ ];
159
+ const bottomRow = [
160
+ { code: 'ShiftLeft', label: 'Shift', kor: null, key: 'Shift' },
161
+ { code: 'KeyZ', label: 'z', shiftLabel: 'Z', kor: 'ㅋ', key: 'z' },
162
+ { code: 'KeyX', label: 'x', shiftLabel: 'X', kor: 'ㅌ', key: 'x' },
163
+ { code: 'KeyC', label: 'c', shiftLabel: 'C', kor: 'ㅊ', key: 'c' },
164
+ { code: 'KeyV', label: 'v', shiftLabel: 'V', kor: 'ㅍ', key: 'v' },
165
+ { code: 'KeyB', label: 'b', shiftLabel: 'B', kor: 'ㅠ', key: 'b' },
166
+ { code: 'KeyN', label: 'n', shiftLabel: 'N', kor: 'ㅜ', key: 'n' },
167
+ { code: 'KeyM', label: 'm', shiftLabel: 'M', kor: 'ㅡ', key: 'm' },
168
+ { code: 'Comma', label: ',', shiftLabel: '<', kor: null, key: ',' },
169
+ { code: 'Period', label: '.', shiftLabel: '>', kor: null, key: '.' },
170
+ { code: 'Slash', label: '/', shiftLabel: '?', kor: null, key: '/' },
171
+ { code: 'ShiftRight', label: 'Shift', kor: null, key: 'Shift' },
172
+ ];
173
+ const spaceRow = [
174
+ { code: 'ControlLeft', label: 'Ctrl', key: 'Control' },
175
+ { code: 'MetaLeft', label: 'Win', key: 'Meta' },
176
+ { code: 'AltLeft', label: 'Alt', key: 'Alt' },
177
+ { code: 'Space', label: 'Space', key: ' ' },
178
+ { code: 'AltRight', label: 'Alt', key: 'Alt' },
179
+ { code: 'Fn', label: 'Fn', key: 'Fn' },
180
+ { code: 'ContextMenu', label: 'Menu', key: 'ContextMenu' },
181
+ { code: 'ControlRight', label: 'Ctrl', key: 'Control' },
182
+ ];
183
+ const DesktopKeyboardInput = ({ type = 'full-size', hasFunction = true, hasNumpad = true, cellStyle = {}, cellClassName = '', activeCellStyle = {}, activeCellClassName = '', style = {}, className = '', onKeyDown, onKeyUp, }) => {
184
+ const [inputKey, setInputKey] = React.useState([]);
185
+ const [isShift, setIsShift] = React.useState(false);
186
+ const [isHangulMode, setIsHangulMode] = React.useState(false);
187
+ const getKeyFromEvent = (keyCode) => {
188
+ var _a, _b;
189
+ let row = null;
190
+ const allRows = [
191
+ ...functionRow.flat(),
192
+ ...numberRow,
193
+ ...qwertyRow,
194
+ ...homeRow,
195
+ ...bottomRow,
196
+ ...spaceRow,
197
+ ];
198
+ row = allRows.find((row) => row.code === keyCode);
199
+ return {
200
+ code: (_a = row.code) !== null && _a !== undefined ? _a : '',
201
+ label: (_b = getLabel(row)) !== null && _b !== undefined ? _b : '',
202
+ };
203
+ };
204
+ const getLabel = (key) => {
205
+ if (isHangulMode) {
206
+ if (isShift) {
207
+ return key.korShift || key.kor || key.shiftLabel || key.label;
208
+ }
209
+ return key.kor || key.label;
210
+ }
211
+ if (isShift) {
212
+ return key.shiftLabel || key.label;
213
+ }
214
+ return key.label;
215
+ };
216
+ React.useEffect(() => {
217
+ const keyDown = (e) => {
218
+ e.preventDefault();
219
+ setInputKey((prevState) => [...prevState, e.code]);
220
+ if (e.key === 'Shift')
221
+ setIsShift(true);
222
+ onKeyDown === null || onKeyDown === undefined ? undefined : onKeyDown(getKeyFromEvent(e.code));
223
+ };
224
+ const keyUp = (e) => {
225
+ e.preventDefault();
226
+ if (e.key === 'HangulMode') {
227
+ setIsHangulMode((prev) => !prev);
228
+ }
229
+ setInputKey((prevState) => prevState.filter((it) => it !== e.code));
230
+ if (e.key === 'Shift')
231
+ setIsShift(false);
232
+ onKeyUp === null || onKeyUp === undefined ? undefined : onKeyUp(getKeyFromEvent(e.code));
233
+ };
234
+ window.addEventListener('keydown', keyDown);
235
+ window.addEventListener('keyup', keyUp);
236
+ return () => {
237
+ window.removeEventListener('keydown', keyDown);
238
+ window.removeEventListener('keyup', keyUp);
239
+ };
240
+ }, [onKeyDown, onKeyUp, isShift, isHangulMode]);
241
+ const renderRow = (row, rowType) => {
242
+ const getCellStyle = (key) => {
243
+ var _a;
244
+ if (key.code === null)
245
+ return;
246
+ const isActive = inputKey.map((it) => it === null || it === undefined ? undefined : it.toUpperCase()).includes((_a = key.code) === null || _a === undefined ? undefined : _a.toUpperCase()) ||
247
+ (inputKey.includes('HangulMode') && key.code === 'AltRight');
248
+ let gridColumn = '';
249
+ switch (key.code) {
250
+ case 'Space':
251
+ gridColumn = '4/12';
252
+ break;
253
+ case 'ShiftRight':
254
+ gridColumn = '13/15';
255
+ break;
256
+ case 'Backspace':
257
+ gridColumn = '14/16';
258
+ break;
259
+ case 'Tab':
260
+ case 'ShiftLeft':
261
+ case 'CapsLock':
262
+ gridColumn = '1/3';
263
+ break;
264
+ case 'Backslash':
265
+ gridColumn = '15/17';
266
+ break;
267
+ case 'Enter':
268
+ gridColumn = '14/16';
269
+ break;
270
+ }
271
+ return {
272
+ style: Object.assign({ gridColumn }, (isActive ? activeCellStyle : cellStyle)),
273
+ className: isActive ? activeCellClassName : cellClassName,
274
+ };
275
+ };
276
+ const onMouseDown = (key) => {
277
+ if (!key.code)
278
+ return;
279
+ setInputKey([key.code]);
280
+ if (['ShiftRight', 'ShiftLeft'].includes(key.code))
281
+ setIsShift(true);
282
+ onKeyDown === null || onKeyDown === undefined ? undefined : onKeyDown(getKeyFromEvent(key.code));
283
+ };
284
+ const onMouseUp = (key) => {
285
+ if (!key.code)
286
+ return;
287
+ if (key.code === 'AltRight') {
288
+ setIsHangulMode((prev) => !prev);
289
+ }
290
+ setInputKey((prevState) => prevState.filter((it) => it !== key.code));
291
+ if (['ShiftRight', 'ShiftLeft'].includes(key.code))
292
+ setIsShift(false);
293
+ onKeyUp === null || onKeyUp === undefined ? undefined : onKeyUp(getKeyFromEvent(key.code));
294
+ };
295
+ return row.map((key, idx) => (React.createElement("div", Object.assign({ key: `${key.code}-${idx}`, onMouseDown: () => onMouseDown(key), onMouseUp: () => onMouseUp(key) }, getCellStyle(key)), getLabel(key))));
296
+ };
297
+ return (React.createElement("div", { style: style, className: className },
298
+ (['full-size', 'tenkeyless'].includes(type) || hasFunction) && (React.createElement("div", { style: { display: 'grid', gridTemplateColumns: `repeat(20, 1fr)`, gap: '2px' } }, renderRow(functionRow.flat()))),
299
+ React.createElement("div", { style: { display: 'grid', gridTemplateColumns: 'repeat(15, 1fr)', gap: '2px' } }, renderRow(numberRow)),
300
+ React.createElement("div", { style: { display: 'grid', gridTemplateColumns: 'repeat(16, 1fr)', gap: '2px' } }, renderRow(qwertyRow)),
301
+ React.createElement("div", { style: { display: 'grid', gridTemplateColumns: 'repeat(15, 1fr)', gap: '2px' } }, renderRow(homeRow)),
302
+ React.createElement("div", { style: { display: 'grid', gridTemplateColumns: 'repeat(14, 1fr)', gap: '2px' } }, renderRow(bottomRow)),
303
+ React.createElement("div", { style: { display: 'grid', gridTemplateColumns: 'repeat(15, 1fr)', gap: '2px' } }, renderRow(spaceRow))));
304
+ };
305
+
80
306
  const RadioInput = (_a) => {
81
307
  var { clearable = false, children = '', checked = false, onChange, onToggle, style, className, id, defaultChecked, readOnly, showError = false, error = null } = _a, restProps = __rest(_a, ["clearable", "children", "checked", "onChange", "onToggle", "style", "className", "id", "defaultChecked", "readOnly", "showError", "error"]);
82
308
  const [selected, setSelected] = React.useState(checked || false);
@@ -204,6 +430,7 @@ const SearchIcon = ({ color = '#000', size = '1em', bgColor = 'transparent', fil
204
430
  exports.Button = Button;
205
431
  exports.CallIcon = CallIcon;
206
432
  exports.CloseIcon = CloseIcon;
433
+ exports.DesktopKeyboardInput = DesktopKeyboardInput;
207
434
  exports.HomeIcon = HomeIcon;
208
435
  exports.Input = Input;
209
436
  exports.RadioGroup = RadioGroup;
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
1
+ {"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "jy-headless",
3
- "version": "0.0.19",
3
+ "version": "0.0.20",
4
4
  "description": "",
5
5
  "main": "dist/index.cjs",
6
6
  "typings": "dist/index.d.ts",