react-hook-core 0.5.15 → 0.5.17

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/lib/index.js CHANGED
@@ -192,3 +192,105 @@ exports.scrollToFocus = function (e, isUseTimeOut) {
192
192
  console.log(e)
193
193
  }
194
194
  }
195
+ var SHORTCUT_KEYS = new Set(["a", "c", "v", "x", "z", "y"])
196
+ var CONTROL_KEYS = new Set([
197
+ "Backspace",
198
+ "Delete",
199
+ "Tab",
200
+ "Enter",
201
+ "Escape",
202
+ "ArrowLeft",
203
+ "ArrowRight",
204
+ "ArrowUp",
205
+ "ArrowDown",
206
+ "Home",
207
+ "End",
208
+ "PageUp",
209
+ "PageDown",
210
+ "Insert",
211
+ ])
212
+ function detectShortcut(e) {
213
+ return (e.ctrlKey || e.metaKey) && SHORTCUT_KEYS.has(e.key.toLowerCase())
214
+ }
215
+ exports.detectShortcut = detectShortcut
216
+ function isDigit(key) {
217
+ return key.length === 1 && key >= "0" && key <= "9"
218
+ }
219
+ function isControlKey(key) {
220
+ return CONTROL_KEYS.has(key)
221
+ }
222
+ function digitKeyDown(e) {
223
+ if (detectShortcut(e)) {
224
+ return true
225
+ }
226
+ var key = e.key
227
+ if (isControlKey(key)) {
228
+ return true
229
+ }
230
+ return isDigit(key)
231
+ }
232
+ exports.digitKeyDown = digitKeyDown
233
+ function integerKeyDown(e) {
234
+ if (detectShortcut(e)) {
235
+ return true
236
+ }
237
+ var key = e.key
238
+ if (isControlKey(key)) {
239
+ return true
240
+ }
241
+ var input = e.target
242
+ if (key === "-") {
243
+ if (!input.min) {
244
+ return true
245
+ } else {
246
+ var min = Number(input.min)
247
+ return !Number.isNaN(min) && min < 0 && !input.value.includes("-")
248
+ }
249
+ }
250
+ return isDigit(key)
251
+ }
252
+ exports.integerKeyDown = integerKeyDown
253
+ function numberKeyDown(e, decimalSeparator) {
254
+ if (detectShortcut(e)) {
255
+ return true
256
+ }
257
+ var key = e.key
258
+ if (isControlKey(key)) {
259
+ return true
260
+ }
261
+ var input = e.target
262
+ if (key === "-") {
263
+ if (!input.min) {
264
+ return true
265
+ } else {
266
+ var min = Number(input.min)
267
+ return !Number.isNaN(min) && min < 0 && !input.value.includes("-")
268
+ }
269
+ }
270
+ if (key === "." || key === "," || key === "٫") {
271
+ if (!decimalSeparator) {
272
+ decimalSeparator = "."
273
+ }
274
+ return key === decimalSeparator && !input.value.includes(decimalSeparator)
275
+ }
276
+ return isDigit(key)
277
+ }
278
+ exports.numberKeyDown = numberKeyDown
279
+ function digitOnKeyDown(e) {
280
+ if (!digitKeyDown(e.nativeEvent)) {
281
+ e.preventDefault()
282
+ }
283
+ }
284
+ exports.digitOnKeyDown = digitOnKeyDown
285
+ function integerOnKeyDown(e) {
286
+ if (!integerKeyDown(e.nativeEvent)) {
287
+ e.preventDefault()
288
+ }
289
+ }
290
+ exports.integerOnKeyDown = integerOnKeyDown
291
+ function numberOnKeyDown(e, decimalSeparator) {
292
+ if (!numberKeyDown(e.nativeEvent, decimalSeparator)) {
293
+ e.preventDefault()
294
+ }
295
+ }
296
+ exports.numberOnKeyDown = numberOnKeyDown
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-hook-core",
3
- "version": "0.5.15",
3
+ "version": "0.5.17",
4
4
  "description": "react",
5
5
  "main": "./lib/index.js",
6
6
  "types": "./src/index.ts",
@@ -10,10 +10,10 @@
10
10
  },
11
11
  "devDependencies": {
12
12
  "@types/react": "^17.0.41",
13
- "@types/react-router-dom": "^5.3.3",
13
+ "@types/react-router": "^5.3.3",
14
14
  "query-string": "^9.2.2",
15
15
  "react": "^17.0.2",
16
- "react-router-dom": "^6.2.2",
16
+ "react-router": "^8.0.1",
17
17
  "tslint": "^5.10.0",
18
18
  "typescript": "^3.3.3333"
19
19
  },
package/src/edit.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { NavigateFunction } from "react-router-dom"
1
+ import { NavigateFunction } from "react-router"
2
2
  import { Attributes, ErrorMessage, StringMap } from "./core"
3
3
 
4
4
  export function isSuccessful<T>(x: number | T | ErrorMessage[]): boolean {
package/src/index.ts CHANGED
@@ -243,3 +243,138 @@ export const scrollToFocus = (e: any, isUseTimeOut?: boolean) => {
243
243
  console.log(e)
244
244
  }
245
245
  }
246
+
247
+ // Keyboard shortcuts that should always be allowed
248
+ const SHORTCUT_KEYS = new Set(["a", "c", "v", "x", "z", "y"])
249
+
250
+ // Non-printable keys that should always be allowed
251
+ const CONTROL_KEYS = new Set([
252
+ "Backspace",
253
+ "Delete",
254
+ "Tab",
255
+ "Enter",
256
+ "Escape",
257
+
258
+ "ArrowLeft",
259
+ "ArrowRight",
260
+ "ArrowUp",
261
+ "ArrowDown",
262
+
263
+ "Home",
264
+ "End",
265
+
266
+ "PageUp",
267
+ "PageDown",
268
+
269
+ "Insert",
270
+ ])
271
+
272
+ export function detectShortcut(e: KeyboardEvent): boolean {
273
+ return (e.ctrlKey || e.metaKey) && SHORTCUT_KEYS.has(e.key.toLowerCase())
274
+ }
275
+
276
+ function isDigit(key: string): boolean {
277
+ return key.length === 1 && key >= "0" && key <= "9"
278
+ }
279
+
280
+ function isControlKey(key: string): boolean {
281
+ return CONTROL_KEYS.has(key)
282
+ }
283
+
284
+ /**
285
+ * Digits only
286
+ * Allow:
287
+ * 0-9
288
+ */
289
+ export function digitKeyDown(e: KeyboardEvent): boolean {
290
+ if (detectShortcut(e)) {
291
+ return true
292
+ }
293
+ const key = e.key
294
+ if (isControlKey(key)) {
295
+ return true
296
+ }
297
+ return isDigit(key)
298
+ }
299
+
300
+ /**
301
+ * Integer input
302
+ * Allow:
303
+ * -123
304
+ * 123
305
+ */
306
+ export function integerKeyDown(e: KeyboardEvent): boolean {
307
+ if (detectShortcut(e)) {
308
+ return true
309
+ }
310
+ const key = e.key
311
+ if (isControlKey(key)) {
312
+ return true
313
+ }
314
+ const input = e.target as HTMLInputElement
315
+
316
+ if (key === "-") {
317
+ if (!input.min) {
318
+ return true
319
+ } else {
320
+ const min = Number(input.min)
321
+ return !Number.isNaN(min) && min < 0 && !input.value.includes("-")
322
+ }
323
+ }
324
+
325
+ return isDigit(key)
326
+ }
327
+
328
+ /**
329
+ * Decimal numbers
330
+ * Allow:
331
+ * -123.45
332
+ * -123,45
333
+ * -123٫45 (Arabic decimal separator)
334
+ * depending on decimalSeparator
335
+ */
336
+ export function numberKeyDown(e: KeyboardEvent, decimalSeparator?: "." | "," | "٫"): boolean {
337
+ if (detectShortcut(e)) {
338
+ return true
339
+ }
340
+
341
+ const key = e.key
342
+
343
+ if (isControlKey(key)) {
344
+ return true
345
+ }
346
+
347
+ const input = e.target as HTMLInputElement
348
+ if (key === "-") {
349
+ if (!input.min) {
350
+ return true
351
+ } else {
352
+ const min = Number(input.min)
353
+ return !Number.isNaN(min) && min < 0 && !input.value.includes("-")
354
+ }
355
+ }
356
+
357
+ if (key === "." || key === "," || key === "٫") {
358
+ if (!decimalSeparator) {
359
+ decimalSeparator = "."
360
+ }
361
+ return key === decimalSeparator && !input.value.includes(decimalSeparator)
362
+ }
363
+
364
+ return isDigit(key)
365
+ }
366
+ export function digitOnKeyDown(e: React.KeyboardEvent<HTMLInputElement>) {
367
+ if (!digitKeyDown(e.nativeEvent)) {
368
+ e.preventDefault()
369
+ }
370
+ }
371
+ export function integerOnKeyDown(e: React.KeyboardEvent<HTMLInputElement>) {
372
+ if (!integerKeyDown(e.nativeEvent)) {
373
+ e.preventDefault()
374
+ }
375
+ }
376
+ export function numberOnKeyDown(e: React.KeyboardEvent<HTMLInputElement>, decimalSeparator?: "." | "," | "٫") {
377
+ if (!numberKeyDown(e.nativeEvent, decimalSeparator)) {
378
+ e.preventDefault()
379
+ }
380
+ }
package/src/route.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  import queryString from "query-string"
2
2
  import * as React from "react"
3
- import { NavigateFunction } from "react-router-dom"
3
+ import { NavigateFunction } from "react-router"
4
4
  import { StringMap } from "./core"
5
5
  import { hasDiff } from "./reflect"
6
6
  import { Filter } from "./search"