refactor(core): Studio's key combo and typing-target rules live in core (#7835)

* refactor(core): Studio's key combo and typing-target rules live in core

* chore(core): raise the packed size budget for the key-combo and typing-target subpaths
This commit is contained in:
Miguel Ángel
2026-11-15 15:42:04 +00:00
committed by GitHub
parent fb1a383bde
commit ef42bef9c3
32 changed files with 94 additions and 67 deletions
+12
View File
@@ -140,6 +140,18 @@
"types": "./dist/compositionContract.d.ts",
"environments": ["browser", "bun", "node"]
},
"./key-combo": {
"source": "./src/keyCombo.ts",
"runtime": "./dist/keyCombo.js",
"types": "./dist/keyCombo.d.ts",
"environments": ["browser", "bun", "node"]
},
"./typing-target": {
"source": "./src/typingTarget.ts",
"runtime": "./dist/typingTarget.js",
"types": "./dist/typingTarget.d.ts",
"environments": ["browser", "bun", "node"]
},
"./studio-preview-mark": {
"source": "./src/studioPreviewMark.ts",
"runtime": "./dist/studioPreviewMark.js",
+20
View File
@@ -152,6 +152,18 @@
"import": "./src/compositionContract.ts",
"types": "./src/compositionContract.ts"
},
"./key-combo": {
"bun": "./src/keyCombo.ts",
"node": "./dist/keyCombo.js",
"import": "./src/keyCombo.ts",
"types": "./src/keyCombo.ts"
},
"./typing-target": {
"bun": "./src/typingTarget.ts",
"node": "./dist/typingTarget.js",
"import": "./src/typingTarget.ts",
"types": "./src/typingTarget.ts"
},
"./studio-preview-mark": {
"bun": "./src/studioPreviewMark.ts",
"node": "./dist/studioPreviewMark.js",
@@ -740,6 +752,14 @@
"import": "./dist/compositionContract.js",
"types": "./dist/compositionContract.d.ts"
},
"./key-combo": {
"import": "./dist/keyCombo.js",
"types": "./dist/keyCombo.d.ts"
},
"./typing-target": {
"import": "./dist/typingTarget.js",
"types": "./dist/typingTarget.d.ts"
},
"./studio-preview-mark": {
"import": "./dist/studioPreviewMark.js",
"types": "./dist/studioPreviewMark.d.ts"
@@ -54,3 +54,30 @@ function asElement(target: EventTarget | null): HTMLElement | null {
const candidate = target as { closest?: unknown; isContentEditable?: unknown };
return typeof candidate.closest === "function" ? (target as HTMLElement) : null;
}
const PLAYBACK_SHORTCUT_IGNORED_SELECTOR = [
"button",
"a[href]",
"[role='button']",
"[role='checkbox']",
"[role='menuitem']",
// Base UI's menu radio item is a `<div>`, so `button` above no longer catches it.
"[role='menuitemradio']",
"[role='radio']",
"[role='spinbutton']",
].join(",");
export function shouldIgnorePlaybackShortcutTarget(target: EventTarget | null): boolean {
// Anything the user is typing into owns its keys outright, editable elements
// included: a letter claimed here never reaches the text. So does a native player.
if (ownsPlainKeys(target)) return true;
if (!target || typeof target !== "object") return false;
const candidate = target as { closest?: unknown };
if (typeof candidate.closest !== "function") return false;
return (
(candidate.closest as (selector: string) => Element | null).call(
target,
PLAYBACK_SHORTCUT_IGNORED_SELECTOR,
) !== null
);
}
+1 -1
View File
@@ -1,5 +1,5 @@
import { isEditableTarget } from "../utils/timelineDiscovery";
import { ownsPlainKeys } from "../utils/typingTarget";
import { ownsPlainKeys } from "@hyperframes/core/typing-target";
import { resolveCanvasNudgeDelta } from "../components/editor/domEditNudge";
type CaptionNudgeKeyEvent = Parameters<typeof resolveCanvasNudgeDelta>[0];
@@ -8,7 +8,7 @@ import React, { act } from "react";
import { createRoot, type Root } from "react-dom/client";
import { afterEach, expect, it, vi } from "vitest";
import { RightPanelTabs, type RightPanelTabDescriptor } from "./RightPanelTabs";
import { isTypingTarget } from "../utils/typingTarget";
import { isTypingTarget } from "@hyperframes/core/typing-target";
import { shouldIgnorePlaybackShortcutTarget } from "../player/lib/playbackShortcuts";
(globalThis as unknown as { IS_REACT_ACT_ENVIRONMENT: boolean }).IS_REACT_ACT_ENVIRONMENT = true;
@@ -8,7 +8,7 @@ import React, { act } from "react";
import { createRoot, type Root } from "react-dom/client";
import { afterEach, beforeEach, expect, it, vi } from "vitest";
import { buttonSizes, buttonVariants } from "./ui";
import { isTypingTarget } from "../utils/typingTarget";
import { isTypingTarget } from "@hyperframes/core/typing-target";
import { shouldIgnorePlaybackShortcutTarget } from "../player/lib/playbackShortcuts";
(globalThis as unknown as { IS_REACT_ACT_ENVIRONMENT: boolean }).IS_REACT_ACT_ENVIRONMENT = true;
@@ -3,7 +3,7 @@
import { act } from "react";
import { afterEach, beforeEach, expect, it, vi } from "vitest";
import { cleanupMounted, mountHost } from "./ui/mountHost.testHelpers";
import { isTypingTarget } from "../utils/typingTarget";
import { isTypingTarget } from "@hyperframes/core/typing-target";
import { shouldIgnorePlaybackShortcutTarget } from "../player/lib/playbackShortcuts";
const editHistory = {
@@ -39,7 +39,7 @@ import { useAudioMetersVisible } from "../utils/audioMeterVisibility";
import { LinkedSelectionToggle } from "./LinkedSelectionToggle";
import { useProjectHasAudio } from "../utils/audioMeterMath";
import { canAddBeatAt, addBeatAtCompositionTime } from "../utils/beatEditActions";
import { isTypingTarget } from "../utils/typingTarget";
import { isTypingTarget } from "@hyperframes/core/typing-target";
import { keyHint, matchesKey, useStudioKeys } from "../player/components/studioShortcuts";
import type { TimelineProps } from "../player/components/TimelineTypes";
@@ -3,7 +3,7 @@ import { memo, useCallback, useEffect, useRef, useState } from "react";
import { MagnetStraight, GridFour, Path, Ruler, FrameCorners } from "@phosphor-icons/react";
import { usePlayerStore } from "../../player/store/playerStore";
import { usePreviewOverlayContext } from "./PreviewOverlayProvider";
import { ownsPlainKeys } from "../../utils/typingTarget";
import { ownsPlainKeys } from "@hyperframes/core/typing-target";
import { keyHint, matchesKey, useStudioKeys } from "../../player/components/studioShortcuts";
// fallow-ignore-next-line complexity
@@ -8,7 +8,7 @@ import { trackPreviewEditResult } from "../../utils/previewFeatureUsage";
*/
import { useCallback, useEffect, useRef, type RefObject } from "react";
import { useMountEffect } from "../../hooks/useMountEffect";
import { ownsPlainKeys } from "../../utils/typingTarget";
import { ownsPlainKeys } from "@hyperframes/core/typing-target";
import { acquireCanvasNudgeKeys } from "../../utils/canvasNudgeGate";
import {
addStudioPendingEditFlushListener,
@@ -21,7 +21,7 @@ import { usePlayerStore } from "../../player";
import { useDomEditSelectionContext } from "../../contexts/DomEditContext";
import { useFileManagerContext } from "../../contexts/FileManagerContext";
import { generateId } from "../../utils/generateId";
import { isTypingTarget } from "../../utils/typingTarget";
import { isTypingTarget } from "@hyperframes/core/typing-target";
import {
SectionHeader,
SlideList,
@@ -6,7 +6,7 @@ import { afterEach, beforeEach, describe, expect, it, vi, type Mock } from "vite
import { RenderQueue, type StartRenderHandler } from "./RenderQueue";
import { getPersistedRenderSettings } from "./renderSettings";
import { buttonBase, buttonSizes, buttonVariants, cn } from "../ui";
import { isTypingTarget } from "../../utils/typingTarget";
import { isTypingTarget } from "@hyperframes/core/typing-target";
import { shouldIgnorePlaybackShortcutTarget } from "../../player/lib/playbackShortcuts";
import type { FfmpegStatus } from "./useFfmpegStatus";
@@ -14,7 +14,7 @@ import { Button, type ButtonSize, type ButtonVariant } from "./Button";
import { IconButton } from "./IconButton";
import { Tab, Tabs, TabsList } from "./Tabs";
import { cleanupMounted, mountHost } from "./mountHost.testHelpers";
import { isTypingTarget } from "../../utils/typingTarget";
import { isTypingTarget } from "@hyperframes/core/typing-target";
import { shouldIgnorePlaybackShortcutTarget } from "../../player/lib/playbackShortcuts";
const VARIANTS: ButtonVariant[] = ["primary", "secondary", "danger", "ghost"];
@@ -16,7 +16,7 @@ import {
MenuSeparator,
} from "./Menu";
import { Popover } from "./Popover";
import { isTypingTarget } from "../../utils/typingTarget";
import { isTypingTarget } from "@hyperframes/core/typing-target";
import { shouldIgnorePlaybackShortcutTarget } from "../../player/lib/playbackShortcuts";
import { cleanupMounted, mountHost as render } from "./mountHost.testHelpers";
@@ -17,7 +17,7 @@ import { NumberField } from "./NumberField";
import { Select } from "./Select";
import { Slider } from "./Slider";
import { Toggle } from "./Toggle";
import { isTypingTarget } from "../../utils/typingTarget";
import { isTypingTarget } from "@hyperframes/core/typing-target";
import { shouldIgnorePlaybackShortcutTarget } from "../../player/lib/playbackShortcuts";
import { __resetDesignInputThrottle, trackDesignInput } from "../../utils/designInputTracking";
import { cleanupMounted, mountHost as render } from "./mountHost.testHelpers";
@@ -3,7 +3,7 @@ import { usePlayerStore } from "../player";
import type { TimelineElement } from "../player";
import type { DomEditSelection } from "../components/editor/domEditing";
import { useDockLayoutStore } from "../components/dock/dockLayoutStore";
import { isTypingTarget, ownsPlainKeys } from "../utils/typingTarget";
import { isTypingTarget, ownsPlainKeys } from "@hyperframes/core/typing-target";
import { isEditableTarget } from "../utils/timelineDiscovery";
import { shouldIgnoreHistoryShortcut } from "../utils/studioHelpers";
import { canSplitElement } from "../utils/timelineElementSplit";
+1 -1
View File
@@ -1,7 +1,7 @@
import { usePlayerStore } from "../player";
import type { TimelineEditCallbacks } from "../player/components/timelineCallbacks";
import { resolveLinkMenuItems } from "../player/components/clipMenuLinkItems";
import { isTypingTarget } from "../utils/typingTarget";
import { isTypingTarget } from "@hyperframes/core/typing-target";
import { keyHint, matchesKey } from "../player/components/studioShortcuts";
export interface LinkShortcutCallbacks {
@@ -31,7 +31,7 @@ import {
type HfAutomationLane,
} from "@hyperframes/core/audio-automation";
import { clampNumber } from "../utils/studioHelpers";
import { isTypingTarget } from "../utils/typingTarget";
import { isTypingTarget } from "@hyperframes/core/typing-target";
import { matchesKey } from "../player/components/studioShortcuts";
import type { AutomationSelection } from "../player/store/automationSelectionSlice";
import type {
@@ -1,6 +1,6 @@
import { useEffect, useCallback } from "react";
import { matchesKey } from "../player/components/studioShortcuts";
import { isTypingTarget } from "../utils/typingTarget";
import { isTypingTarget } from "@hyperframes/core/typing-target";
interface KeyframeKeyboardOptions {
enabled: boolean;
+2 -2
View File
@@ -14,8 +14,8 @@ export {
studioKeyClash,
useStudioKeys,
} from "./player/components/studioShortcuts";
export { formatCombo, matchCombo, parseCombo } from "./player/components/studioCombo";
export type { Combo } from "./player/components/studioCombo";
export { formatCombo, matchCombo, parseCombo } from "@hyperframes/core/key-combo";
export type { Combo } from "@hyperframes/core/key-combo";
export type { StudioKeyAction, StudioKeys } from "./player/components/studioShortcuts";
export { ShortcutsButton } from "./player/components/ShortcutsPanel";
export { dispatchLinkShortcut } from "./hooks/linkShortcuts";
+5 -7
View File
@@ -31,15 +31,13 @@ function importGraph(entry: string): { files: string[]; packages: string[] } {
}
describe("@hyperframes/studio/keys", () => {
it("imports only the key helpers: no package and no editor module", () => {
it("imports only the key helpers: core's import-free matcher and no editor module", () => {
expect(importGraph("keys.ts")).toEqual({
files: [
"keys.ts",
"player/components/studioCombo.ts",
"player/components/studioKeyDefaults.ts",
],
packages: [],
files: ["keys.ts", "player/components/studioKeyDefaults.ts"],
packages: ["@hyperframes/core/key-combo"],
});
const matcher = readFileSync(join(src, "../../core/src/keyCombo.ts"), "utf8");
expect(ts.preProcessFile(matcher).importedFiles).toEqual([]);
});
it("is a published subpath sharing the defaults the root entry exports", async () => {
+1 -6
View File
@@ -1,9 +1,4 @@
export {
matchCombo,
parseCombo,
type Combo,
type ComboEvent,
} from "./player/components/studioCombo";
export { matchCombo, parseCombo, type Combo, type ComboEvent } from "@hyperframes/core/key-combo";
export {
DEFAULT_STUDIO_KEYS,
type StudioKeyAction,
@@ -5,7 +5,7 @@ import { flatActive, flatIdle } from "../../components/timelineToolbarStyles";
import { usePlayerStore } from "../store/playerStore";
import { useCompositionFps } from "../../utils/linkedClipPreferences";
import { matchesKey, useShortcutSections, type ShortcutSection } from "./studioShortcuts";
import { isTypingTarget } from "../../utils/typingTarget";
import { isTypingTarget } from "@hyperframes/core/typing-target";
interface ShortcutsPanelProps {
disabled: boolean;
@@ -1,6 +1,6 @@
// @vitest-environment happy-dom
import { afterEach, describe, expect, it, vi } from "vitest";
import { formatCombo, matchCombo, parseCombo } from "./studioCombo";
import { formatCombo, matchCombo, parseCombo } from "@hyperframes/core/key-combo";
import {
getStudioKey,
getStudioKeys,
@@ -6,7 +6,7 @@ import {
formatCombo,
matchCombo,
parseCombo,
} from "./studioCombo";
} from "@hyperframes/core/key-combo";
import { DEFAULT_STUDIO_KEYS, type StudioKeyAction, type StudioKeys } from "./studioKeyDefaults";
@@ -6,8 +6,8 @@
* is active and the user is navigating caption segments).
*/
import { ownsPlainKeys } from "../../utils/typingTarget";
import type { ComboEvent } from "../components/studioCombo";
import { shouldIgnorePlaybackShortcutTarget } from "@hyperframes/core/typing-target";
import type { ComboEvent } from "@hyperframes/core/key-combo";
import { matchesKey } from "../components/studioShortcuts";
import { usePlayerStore } from "../store/playerStore";
@@ -18,32 +18,7 @@ const FRAME_STEP_ACTIONS = [
"frameForwardTen",
] as const;
const PLAYBACK_SHORTCUT_IGNORED_SELECTOR = [
"button",
"a[href]",
"[role='button']",
"[role='checkbox']",
"[role='menuitem']",
// Base UI's menu radio item is a `<div>`, so `button` above no longer catches it.
"[role='menuitemradio']",
"[role='radio']",
"[role='spinbutton']",
].join(",");
export function shouldIgnorePlaybackShortcutTarget(target: EventTarget | null): boolean {
// Anything the user is typing into owns its keys outright, editable elements
// included: a letter claimed here never reaches the text. So does a native player.
if (ownsPlainKeys(target)) return true;
if (!target || typeof target !== "object") return false;
const candidate = target as { closest?: unknown };
if (typeof candidate.closest !== "function") return false;
return (
(candidate.closest as (selector: string) => Element | null).call(
target,
PLAYBACK_SHORTCUT_IGNORED_SELECTOR,
) !== null
);
}
export { shouldIgnorePlaybackShortcutTarget };
const MODAL_DIALOG_SELECTOR = "[role=dialog][aria-modal=true]";
+1 -1
View File
@@ -1,5 +1,5 @@
import { buildProjectApiPath } from "./projectRouting";
import { isTypingTarget } from "./typingTarget";
import { isTypingTarget } from "@hyperframes/core/typing-target";
import type { TimelineElement } from "../player/store/playerStore";
import type { DomEditSelection } from "../components/editor/domEditing";
import type { TimelineAssetKind } from "./timelineAssetDrop";
@@ -1,5 +1,5 @@
import { StudioFileConflictError, type StudioSaveDrainResult } from "./studioSaveDiagnostics";
import { isTypingTarget } from "./typingTarget";
import { isTypingTarget } from "@hyperframes/core/typing-target";
const STUDIO_FLUSH_PENDING_EDITS_EVENT = "hf-studio-flush-pending-edits";
@@ -1,3 +1,3 @@
// Compatibility name for downstream imports. The typing decision itself has
// one owner; new Studio callers import `isTypingTarget` directly.
export { isTypingTarget as isEditableTarget } from "./typingTarget";
export { isTypingTarget as isEditableTarget } from "@hyperframes/core/typing-target";
@@ -1,7 +1,7 @@
// @vitest-environment happy-dom
import { afterEach, describe, expect, it } from "vitest";
import { isTypingTarget, ownsPlainKeys } from "./typingTarget";
import { isTypingTarget, ownsPlainKeys } from "@hyperframes/core/typing-target";
import { isEditableTarget } from "./timelineDiscovery";
afterEach(() => {
+1 -1
View File
@@ -8,7 +8,7 @@
"unpacked": 25159107
},
"@hyperframes/core": {
"packed": 1762752,
"packed": 1800000,
"unpacked": 4374000
},
"@hyperframes/engine": {