@hexdspace/react 0.1.53 → 0.1.54

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/index.d.ts CHANGED
@@ -729,6 +729,7 @@ interface ShortcutRegistration {
729
729
  bindings: ShortcutBinding[];
730
730
  ignoreTyping?: boolean;
731
731
  preventDefault?: boolean;
732
+ blockWhileTyping?: (event: KeyboardEvent) => boolean;
732
733
  }
733
734
 
734
735
  interface ShortcutScope {
@@ -852,6 +853,7 @@ declare function useKeyboardController(): KeyboardController;
852
853
  declare function useShortcut(scopeId: string, bindings: ShortcutBinding[], opts?: {
853
854
  ignoreTyping?: boolean;
854
855
  preventDefault?: boolean;
856
+ blockWhileTyping?: (event: KeyboardEvent) => boolean;
855
857
  }): void;
856
858
 
857
859
  declare function useShortcutScope(scopeId: string, enabled?: boolean): void;
package/dist/index.js CHANGED
@@ -3006,7 +3006,7 @@ var RegisterShortcutUseCase = class {
3006
3006
  const id = uuid2();
3007
3007
  const reg = { preventDefault: true, ignoreTyping: true, ...regInput, id };
3008
3008
  const guard = (e) => {
3009
- if (reg.ignoreTyping && isTyping(e)) return false;
3009
+ if (reg.ignoreTyping && isTyping(e, reg.blockWhileTyping)) return false;
3010
3010
  return this.scopes.isScopeActive(reg.scopeId);
3011
3011
  };
3012
3012
  const handle = this.engine.register(reg.bindings, { guard, preventDefault: reg.preventDefault });
@@ -3030,11 +3030,12 @@ var RegisterShortcutUseCase = class {
3030
3030
  this.registry.removeByRegistration(id);
3031
3031
  }
3032
3032
  };
3033
- function isTyping(e) {
3033
+ function isTyping(e, blockWhileTyping) {
3034
3034
  const el = e.target;
3035
3035
  if (!el) return false;
3036
3036
  const inText = el.tagName === "INPUT" || el.tagName === "TEXTAREA" || el.isContentEditable;
3037
3037
  if (!inText) return false;
3038
+ if (blockWhileTyping?.(e)) return true;
3038
3039
  const k = e.key;
3039
3040
  const allow = k === "Escape" || k === "Tab" || k.startsWith("Arrow") || k === "PageUp" || k === "PageDown" || k === "Home" || k === "End" || e.ctrlKey || e.metaKey || e.altKey;
3040
3041
  return !allow;
@@ -3229,10 +3230,11 @@ function useShortcut(scopeId, bindings, opts) {
3229
3230
  scopeId,
3230
3231
  bindings: stableBindings,
3231
3232
  ignoreTyping: opts?.ignoreTyping ?? true,
3232
- preventDefault: opts?.preventDefault ?? true
3233
+ preventDefault: opts?.preventDefault ?? true,
3234
+ blockWhileTyping: opts?.blockWhileTyping
3233
3235
  });
3234
3236
  return () => controller.handleUnregisterShortcut(id);
3235
- }, [controller, stableBindings, opts?.ignoreTyping, opts?.preventDefault, scopeId]);
3237
+ }, [controller, stableBindings, opts?.ignoreTyping, opts?.preventDefault, opts?.blockWhileTyping, scopeId]);
3236
3238
  }
3237
3239
 
3238
3240
  // src/feature/keyboard/infra/web/react/useShortcutScope.tsx
@@ -3700,6 +3702,10 @@ function useVimBindings(regionKey, keyboardScopeId, options = {}) {
3700
3702
  setIsOwner(entry.ownerId === ownerIdRef.current);
3701
3703
  setModifierActionsVersion(entry.modifierActionsVersion);
3702
3704
  }, []);
3705
+ const blockWhileTyping = useCallback5(
3706
+ (e) => allowArrowKeys && e.key.startsWith("Arrow"),
3707
+ [allowArrowKeys]
3708
+ );
3703
3709
  useEffect7(() => {
3704
3710
  if (!enabled) {
3705
3711
  setIsOwner(false);
@@ -3855,7 +3861,11 @@ function useVimBindings(regionKey, keyboardScopeId, options = {}) {
3855
3861
  ...modifierBindings("ctrlShift", modifierAvailability?.ctrlShift)
3856
3862
  ];
3857
3863
  }, [allowArrowKeys, enabled, isOwner, keyboardScopeId, modifierActionsVersion, vim]);
3858
- useShortcut(keyboardScopeId, bindings, { ignoreTyping: true, preventDefault: true });
3864
+ useShortcut(keyboardScopeId, bindings, {
3865
+ ignoreTyping: true,
3866
+ preventDefault: true,
3867
+ blockWhileTyping
3868
+ });
3859
3869
  }
3860
3870
  function getModifierAvailability(keyboardScopeId) {
3861
3871
  const entry = scopeBindings.get(keyboardScopeId);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hexdspace/react",
3
- "version": "0.1.53",
3
+ "version": "0.1.54",
4
4
  "type": "module",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",