tycho-components 0.0.10-SNAPSHOT-7 → 0.0.10-SNAPSHOT-8
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.
- package/dist/VirtualKeyboard/KeyboardCustomLayout.d.ts +8 -0
- package/dist/VirtualKeyboard/KeyboardCustomLayout.js +25 -0
- package/dist/VirtualKeyboard/VirtualKeyboard.d.ts +9 -0
- package/dist/VirtualKeyboard/VirtualKeyboard.js +68 -0
- package/dist/VirtualKeyboard/index.d.ts +2 -0
- package/dist/VirtualKeyboard/index.js +2 -0
- package/dist/VirtualKeyboard/style.scss +33 -0
- package/dist/index.d.ts +4 -1
- package/dist/index.js +3 -1
- package/package.json +4 -2
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
export const KeyboardCustomLayouts = {
|
|
2
|
+
kadiwéu: {
|
|
3
|
+
layout: {
|
|
4
|
+
default: [
|
|
5
|
+
'1 2 3 4 5 6 7 8 9 0',
|
|
6
|
+
'q w e r t y u i o p',
|
|
7
|
+
'a s d f g h j k l',
|
|
8
|
+
'z x c v b n m ǥ',
|
|
9
|
+
'{shift} {space} {bksp}',
|
|
10
|
+
],
|
|
11
|
+
shift: [
|
|
12
|
+
'! @ # $ % ^ & * ( )',
|
|
13
|
+
'Q W E R T Y U I O P',
|
|
14
|
+
'A S D F G H J K L',
|
|
15
|
+
'Z X C V B N M Ǥ',
|
|
16
|
+
'{shift} {space} {bksp}',
|
|
17
|
+
],
|
|
18
|
+
},
|
|
19
|
+
display: {
|
|
20
|
+
'{bksp}': '⌫',
|
|
21
|
+
'{shift}': '⇧',
|
|
22
|
+
'{space}': '␣',
|
|
23
|
+
},
|
|
24
|
+
},
|
|
25
|
+
};
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import 'react-simple-keyboard/build/css/index.css';
|
|
2
|
+
import './style.scss';
|
|
3
|
+
type Props = {
|
|
4
|
+
onClose: () => void;
|
|
5
|
+
defaultLayout: string;
|
|
6
|
+
closeLabel: string;
|
|
7
|
+
};
|
|
8
|
+
export default function VirtualKeyboard({ onClose, defaultLayout, closeLabel, }: Props): import("react/jsx-runtime").JSX.Element;
|
|
9
|
+
export {};
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
// https://github.com/simple-keyboard/simple-keyboard-layouts/wiki/Adding-a-Layout
|
|
3
|
+
import { MenuItem, Select, ThemeProvider, useTheme } from '@mui/material';
|
|
4
|
+
import { useEffect, useState } from 'react';
|
|
5
|
+
import Draggable from 'react-draggable';
|
|
6
|
+
import Keyboard from 'react-simple-keyboard';
|
|
7
|
+
import 'react-simple-keyboard/build/css/index.css';
|
|
8
|
+
import KeyboardLayouts from 'simple-keyboard-layouts';
|
|
9
|
+
import { Button, getCurrentInput, getCurrentOnChange, removeCurrentInput, selectFieldTheme, } from 'tycho-storybook';
|
|
10
|
+
import { KeyboardCustomLayouts } from './KeyboardCustomLayout';
|
|
11
|
+
import './style.scss';
|
|
12
|
+
export default function VirtualKeyboard({ onClose, defaultLayout, closeLabel = 'Close', }) {
|
|
13
|
+
const outerTheme = useTheme();
|
|
14
|
+
const layouts = new KeyboardLayouts();
|
|
15
|
+
const layoutNames = [
|
|
16
|
+
...Object.keys(layouts.get()),
|
|
17
|
+
...Object.keys(KeyboardCustomLayouts),
|
|
18
|
+
].sort((a, b) => a.localeCompare(b));
|
|
19
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-explicit-any
|
|
20
|
+
const [layout, setLayout] = useState();
|
|
21
|
+
const [layoutName, setLayoutName] = useState('default');
|
|
22
|
+
const [selected, setSelected] = useState(defaultLayout);
|
|
23
|
+
const getLayoutByName = (name) => layouts.get(name) || KeyboardCustomLayouts[name];
|
|
24
|
+
const handleChangeLayout = (lang) => {
|
|
25
|
+
setSelected(lang);
|
|
26
|
+
setLayoutName('default');
|
|
27
|
+
const layoutObject = getLayoutByName(lang);
|
|
28
|
+
setLayout(layoutObject?.layout || layoutObject);
|
|
29
|
+
};
|
|
30
|
+
const handleShift = () => {
|
|
31
|
+
const newLayoutName = layoutName === 'default' ? 'shift' : 'default';
|
|
32
|
+
setLayoutName(newLayoutName);
|
|
33
|
+
};
|
|
34
|
+
const onKeyPress = (button) => {
|
|
35
|
+
if (button === '{shift}' || button === '{lock}') {
|
|
36
|
+
handleShift();
|
|
37
|
+
return;
|
|
38
|
+
}
|
|
39
|
+
if (button === '{space}') {
|
|
40
|
+
button = ' ';
|
|
41
|
+
}
|
|
42
|
+
const input = getCurrentInput();
|
|
43
|
+
const onChange = getCurrentOnChange();
|
|
44
|
+
if (input && onChange) {
|
|
45
|
+
const start = input.selectionStart || 0;
|
|
46
|
+
const end = input.selectionEnd || 0;
|
|
47
|
+
const value = input.value;
|
|
48
|
+
const newValue = button === '{bksp}'
|
|
49
|
+
? value.slice(0, -1)
|
|
50
|
+
: value.slice(0, start) + button + value.slice(end);
|
|
51
|
+
input.value = newValue;
|
|
52
|
+
input.setSelectionRange(start + 1, start + 1);
|
|
53
|
+
input.focus();
|
|
54
|
+
onChange({ target: input });
|
|
55
|
+
}
|
|
56
|
+
};
|
|
57
|
+
useEffect(() => {
|
|
58
|
+
setLayout(getLayoutByName(defaultLayout)?.layout);
|
|
59
|
+
}, []);
|
|
60
|
+
return (_jsx(Draggable, { children: _jsxs("div", { className: "keyboard-container", children: [_jsx("div", { className: "body", children: _jsx(Keyboard, { onKeyPress: onKeyPress, layoutName: layoutName,
|
|
61
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
|
|
62
|
+
layout: layout }) }), _jsxs("div", { className: "footer", children: [_jsx(ThemeProvider, { theme: selectFieldTheme(outerTheme), children: _jsx(Select, { value: selected, fullWidth: true, variant: "filled", color: "primary", className: "select-layout", onChange: (e) => {
|
|
63
|
+
handleChangeLayout(e.target.value);
|
|
64
|
+
}, children: layoutNames.map((option, idx) => (_jsx(MenuItem, { value: option, children: option }, idx.valueOf()))) }) }), _jsx(Button, { onClick: () => {
|
|
65
|
+
removeCurrentInput();
|
|
66
|
+
onClose();
|
|
67
|
+
}, text: closeLabel, color: "danger", size: "small" })] })] }) }));
|
|
68
|
+
}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
.keyboard-container {
|
|
2
|
+
display: flex;
|
|
3
|
+
flex-direction: column;
|
|
4
|
+
position: fixed;
|
|
5
|
+
bottom: 16px;
|
|
6
|
+
right: 16px;
|
|
7
|
+
background-color: var(--accent-100);
|
|
8
|
+
border: 1px solid var(--border-subtle-1);
|
|
9
|
+
border-radius: var(--radius-200);
|
|
10
|
+
box-shadow: 0 4px 20px rgba(0, 0, 0, 0.2);
|
|
11
|
+
padding: 12px;
|
|
12
|
+
gap: 8px;
|
|
13
|
+
z-index: 1000;
|
|
14
|
+
min-width: 20vw;
|
|
15
|
+
|
|
16
|
+
> .footer {
|
|
17
|
+
display: flex;
|
|
18
|
+
justify-content: end;
|
|
19
|
+
gap: 8px;
|
|
20
|
+
padding-top: var(--spacing-050);
|
|
21
|
+
|
|
22
|
+
.select-layout {
|
|
23
|
+
> .MuiSelect-select {
|
|
24
|
+
padding: 0px 16px !important;
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
.dropdown-menu {
|
|
29
|
+
max-height: 30vh;
|
|
30
|
+
overflow-y: auto;
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
}
|
package/dist/index.d.ts
CHANGED
|
@@ -5,11 +5,14 @@ export { default as Participants } from './Participants';
|
|
|
5
5
|
export { default as AppModal } from './AppModal';
|
|
6
6
|
export { default as AppModalConfirm } from './AppModal/AppModalConfirm';
|
|
7
7
|
export { default as AppModalRemove } from './AppModal/AppModalRemove';
|
|
8
|
-
export {
|
|
8
|
+
export { default as VirtualKeyboard } from './VirtualKeyboard';
|
|
9
9
|
export { CommonProvider } from './configs/CommonContext';
|
|
10
10
|
export { useMessageUtils } from './configs/useMessageUtils';
|
|
11
11
|
export { validateFormField } from './AppEditable/FormField';
|
|
12
12
|
export { convertEnum, convertList } from './AppEditable/FormFieldOption';
|
|
13
|
+
export { commonResources } from './configs/Localization';
|
|
14
|
+
export { KeyboardCustomLayouts } from './VirtualKeyboard/KeyboardCustomLayout';
|
|
13
15
|
export type { FormFieldOption } from './AppEditable/FormFieldOption';
|
|
14
16
|
export type { AppEditableField } from './AppEditable/AppEditableField';
|
|
15
17
|
export type { FieldOperations, FormField } from './AppEditable/FormField';
|
|
18
|
+
export type { KeyboardLayout } from './VirtualKeyboard/KeyboardCustomLayout';
|
package/dist/index.js
CHANGED
|
@@ -5,8 +5,10 @@ export { default as Participants } from './Participants';
|
|
|
5
5
|
export { default as AppModal } from './AppModal';
|
|
6
6
|
export { default as AppModalConfirm } from './AppModal/AppModalConfirm';
|
|
7
7
|
export { default as AppModalRemove } from './AppModal/AppModalRemove';
|
|
8
|
-
export {
|
|
8
|
+
export { default as VirtualKeyboard } from './VirtualKeyboard';
|
|
9
9
|
export { CommonProvider } from './configs/CommonContext';
|
|
10
10
|
export { useMessageUtils } from './configs/useMessageUtils';
|
|
11
11
|
export { validateFormField } from './AppEditable/FormField';
|
|
12
12
|
export { convertEnum, convertList } from './AppEditable/FormFieldOption';
|
|
13
|
+
export { commonResources } from './configs/Localization';
|
|
14
|
+
export { KeyboardCustomLayouts } from './VirtualKeyboard/KeyboardCustomLayout';
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "tycho-components",
|
|
3
3
|
"private": false,
|
|
4
|
-
"version": "0.0.10-SNAPSHOT-
|
|
4
|
+
"version": "0.0.10-SNAPSHOT-8",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
7
7
|
"exports": {
|
|
@@ -27,6 +27,8 @@
|
|
|
27
27
|
"js-cookie": "^3.0.5",
|
|
28
28
|
"react-colorful": "^5.6.1",
|
|
29
29
|
"react-easy-edit": "^2.0.0",
|
|
30
|
+
"react-simple-keyboard": "^3.8.66",
|
|
31
|
+
"simple-keyboard-layouts": "^3.4.82",
|
|
30
32
|
"react-loading": "^2.0.3",
|
|
31
33
|
"react-switch": "^7.1.0",
|
|
32
34
|
"react-toastify": "^9.1.3"
|
|
@@ -45,7 +47,7 @@
|
|
|
45
47
|
"react-dom": ">=17 <19",
|
|
46
48
|
"react-hook-form": "^7.45.2",
|
|
47
49
|
"react-i18next": "^13.0.2",
|
|
48
|
-
"tycho-storybook": "0.1.
|
|
50
|
+
"tycho-storybook": "0.1.5-SNAPSHOT",
|
|
49
51
|
"yup": "^1.2.0"
|
|
50
52
|
},
|
|
51
53
|
"devDependencies": {
|