@uiwwsw/virtual-keyboard 1.0.1 → 1.1.1

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/README.md CHANGED
@@ -53,9 +53,36 @@ function App() {
53
53
  }
54
54
  ```
55
55
 
56
+ ### Input Modes
57
+
58
+ You can now assign an input policy per `VirtualInput`.
59
+
60
+ ```tsx
61
+ import { VirtualInput, VirtualInputProvider } from "@uiwwsw/virtual-keyboard";
62
+
63
+ function App() {
64
+ return (
65
+ <VirtualInputProvider>
66
+ <VirtualInput mode="number" placeholder="숫자만 입력" />
67
+ <VirtualInput mode="tel" placeholder="전화번호만 입력" />
68
+ <VirtualInput mode="alpha" placeholder="영문만 입력" />
69
+ </VirtualInputProvider>
70
+ );
71
+ }
72
+ ```
73
+
74
+ Supported modes:
75
+ - `text`
76
+ - `number`
77
+ - `tel`
78
+ - `hangul`
79
+ - `alpha`
80
+ - `alphanumeric`
81
+ - `custom`
82
+
56
83
  ### Custom Layout
57
84
 
58
- You can provide a custom layout for specialized inputs, such as a number pad for phone numbers.
85
+ You can still provide a custom layout for specialized inputs, such as a number pad for phone numbers.
59
86
 
60
87
  ```tsx
61
88
  import { VirtualInput, VirtualInputProvider } from "@uiwwsw/virtual-keyboard";
@@ -70,14 +97,26 @@ const numberPadLayout = [
70
97
 
71
98
  function App() {
72
99
  return (
73
- <VirtualInputProvider layout={numberPadLayout}>
100
+ <VirtualInputProvider>
74
101
  <p>Enter your phone number:</p>
75
- <VirtualInput placeholder="010-0000-0000" />
102
+ <VirtualInput layout={numberPadLayout} mode="tel" placeholder="010-0000-0000" />
76
103
  </VirtualInputProvider>
77
104
  );
78
105
  }
79
106
  ```
80
107
 
108
+ ### Custom Filter / Sanitizer
109
+
110
+ For advanced cases, you can override key filtering and pasted value sanitization.
111
+
112
+ ```tsx
113
+ <VirtualInput
114
+ mode="custom"
115
+ filterKey={(key) => /[ABC123]/.test(key)}
116
+ sanitizeValue={(value) => value.replace(/[^ABC123]/g, "")}
117
+ />
118
+ ```
119
+
81
120
  ## Components API
82
121
 
83
122
  ### `<VirtualInputProvider />`
@@ -86,13 +125,19 @@ The main provider that manages the keyboard state and UI.
86
125
 
87
126
  | Prop | Type | Description |
88
127
  | :--------- | :--------------------- | :-------------------------------------------------- |
89
- | `layout` | `Key[][][]` (optional) | A 2D array to define a custom keyboard layout. |
128
+ | `layout` | `Key[][][]` (optional) | Default fallback layout when an input does not provide its own mode/layout. |
90
129
  | `children` | `ReactNode` | Must contain at least one `VirtualInput` component. |
91
130
 
92
131
  ### `<VirtualInput />`
93
132
 
94
133
  The replacement for the standard `<input>` element. It accepts all standard input element props like `value`, `defaultValue`, `placeholder`, `onChange`, etc.
95
134
 
135
+ Additional props:
136
+ - `mode?: "text" | "number" | "tel" | "hangul" | "alpha" | "alphanumeric" | "custom"`
137
+ - `layout?: KeypadLayout`
138
+ - `filterKey?: (key: string) => boolean`
139
+ - `sanitizeValue?: (value: string) => string`
140
+
96
141
  ## Star History
97
142
 
98
143
  [![Star History Chart](https://api.star-history.com/svg?repos=uiwwsw/virtual-keyboard&type=Date)](https://www.star-history.com/#uiwwsw/virtual-keyboard&Date)
@@ -1,9 +1,10 @@
1
1
  import { type Dispatch, type SetStateAction, type RefObject } from "react";
2
2
  import type { VirtualInputHandle } from "./Input";
3
+ import type { InputPolicy } from "../types/inputPolicy";
3
4
  interface VirtualInputContextValue {
4
5
  inputRef: RefObject<VirtualInputHandle | null>;
5
6
  isCompositionRef: RefObject<boolean | undefined>;
6
- onFocus: (id: string, target?: HTMLElement | null) => void;
7
+ onFocus: (id: string, target?: HTMLElement | null, policy?: InputPolicy) => void;
7
8
  onBlur: (e?: React.FocusEvent | boolean) => void;
8
9
  focusId: string | undefined;
9
10
  setHangulMode: Dispatch<SetStateAction<boolean>>;
@@ -19,6 +20,7 @@ interface VirtualInputContextValue {
19
20
  selectionAdjusting: boolean;
20
21
  toggleSelectionAdjust: () => void;
21
22
  toggleKorean: () => void;
23
+ activeInputPolicy: Required<InputPolicy>;
22
24
  }
23
25
  export declare const VirtualInputContext: import("react").Context<VirtualInputContextValue | null>;
24
26
  export declare function useVirtualInputContext(): VirtualInputContextValue;
@@ -1,4 +1,6 @@
1
1
  import React from "react";
2
+ import type { InputMode } from "../types/inputPolicy";
3
+ import type { KeypadLayout } from "../hooks/useKeypadLayout";
2
4
  export interface VirtualInputHandle {
3
5
  handleKeyDown: (e: KeyboardEvent | React.KeyboardEvent) => void;
4
6
  scrollIntoView: () => void;
@@ -12,5 +14,9 @@ export interface VirtualInputProps extends React.HTMLAttributes<HTMLDivElement>
12
14
  defaultValue?: string;
13
15
  placeholder?: string;
14
16
  onChange?: (event: React.ChangeEvent<HTMLInputElement>) => void;
17
+ mode?: InputMode;
18
+ layout?: KeypadLayout;
19
+ filterKey?: (key: string) => boolean;
20
+ sanitizeValue?: (value: string) => string;
15
21
  }
16
- export declare function VirtualInput({ value: controlledValue, defaultValue, placeholder, onChange, ...props }: VirtualInputProps): import("react/jsx-runtime").JSX.Element;
22
+ export declare function VirtualInput({ value: controlledValue, defaultValue, placeholder, onChange, mode, layout, filterKey, sanitizeValue, ...props }: VirtualInputProps): import("react/jsx-runtime").JSX.Element;
@@ -0,0 +1,8 @@
1
+ import type { KeypadLayout } from "../hooks/useKeypadLayout";
2
+ export type InputMode = "text" | "number" | "tel" | "hangul" | "alpha" | "alphanumeric" | "custom";
3
+ export type InputPolicy = {
4
+ mode: InputMode;
5
+ layout?: KeypadLayout;
6
+ filterKey?: (key: string) => boolean;
7
+ sanitizeValue?: (value: string) => string;
8
+ };
@@ -0,0 +1,3 @@
1
+ import type { InputPolicy } from "../types/inputPolicy";
2
+ export declare function resolveInputPolicy(policy?: Partial<InputPolicy>): Required<InputPolicy>;
3
+ export declare function isSpecialKey(key: string): boolean;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@uiwwsw/virtual-keyboard",
3
- "version": "1.0.1",
3
+ "version": "1.1.1",
4
4
  "type": "module",
5
5
  "types": "dist/types/index.d.ts",
6
6
  "main": "dist/index.js",