Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions apps/web/src/actions/keybinding.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,22 @@ export type SingleCharacterShortcutKey = `${Key}`;

export type ShortcutKey = ModifierBasedShortcutKey | SingleCharacterShortcutKey;

const MODIFIER_KEYS_SET: ReadonlySet<string> = new Set([
"ctrl", "alt", "shift",
"ctrl+shift", "alt+shift", "ctrl+alt", "ctrl+alt+shift",
]);

export function isShortcutKey(value: string): value is ShortcutKey {
// Single key (e.g. "a", "enter")
if (isKey(value)) return true;
// Modifier+key (e.g. "ctrl+s", "ctrl+shift+z")
const lastPlus = value.lastIndexOf("+");
if (lastPlus === -1) return false;
const modifier = value.slice(0, lastPlus);
const key = value.slice(lastPlus + 1);
return MODIFIER_KEYS_SET.has(modifier) && isKey(key);
}

export type KeybindingConfig = {
[key in ShortcutKey]?: TActionWithOptionalArgs;
};
17 changes: 17 additions & 0 deletions apps/web/src/actions/types.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import type { MutableRefObject } from "react";
import type { TAction } from "./definitions";
import { ACTIONS } from "./definitions";

export type { TAction };

Expand All @@ -24,6 +25,22 @@ export type TActionWithOptionalArgs =

export type TActionWithNoArgs = Exclude<TAction, TActionWithArgs>;

const ACTION_KEYS_SET: ReadonlySet<string> = new Set(Object.keys(ACTIONS));

export function isAction(value: string): value is TAction {
return ACTION_KEYS_SET.has(value);
}

export function isActionWithOptionalArgs(value: string): value is TActionWithOptionalArgs {
if (!isAction(value)) return false;
// Actions that require mandatory (non-undefined) args cannot be used as keybindings
const ACTIONS_WITH_REQUIRED_ARGS: ReadonlySet<string> = new Set([
"remove-media-asset",
"remove-media-assets",
]);
return !ACTIONS_WITH_REQUIRED_ARGS.has(value);
}

export type TArgOfAction<A extends TAction> = A extends TActionWithArgs
? TActionArgsMap[A]
: undefined;
Expand Down
12 changes: 6 additions & 6 deletions apps/web/src/services/storage/migrations/runner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,11 @@ export async function runStorageMigrations({
hasCleanedUpMetaDb = true;
}

const projectsAdapter = new IndexedDBAdapter<ProjectRecord>(
"video-editor-projects",
"projects",
1,
);
const projectsAdapter = new IndexedDBAdapter<ProjectRecord>({
dbName: "video-editor-projects",
storeName: "projects",
version: 1,
});

const projects = await projectsAdapter.getAll();

Expand Down Expand Up @@ -95,7 +95,7 @@ export async function runStorageMigrations({
break;
}

await projectsAdapter.set(projectId, result.project);
await projectsAdapter.set({ key: projectId, value: result.project });
migratedCount++;
currentVersion = migration.to;
projectRecord = result.project;
Expand Down
30 changes: 15 additions & 15 deletions apps/web/src/services/storage/migrations/v1-to-v2.ts
Original file line number Diff line number Diff line change
Expand Up @@ -121,20 +121,20 @@ async function loadLegacyTracksForScene({
const sceneDbName = `video-editor-timelines-${projectId}-${sceneId}`;
const projectDbName = `video-editor-timelines-${projectId}`;

const adapter = new IndexedDBAdapter<LegacyTimelineData>(
sceneDbName,
"timeline",
1,
);
const adapter = new IndexedDBAdapter<LegacyTimelineData>({
dbName: sceneDbName,
storeName: "timeline",
version: 1,
});

let data = await adapter.get("timeline");

if (!data && isMain) {
const projectAdapter = new IndexedDBAdapter<LegacyTimelineData>(
projectDbName,
"timeline",
1,
);
const projectAdapter = new IndexedDBAdapter<LegacyTimelineData>({
dbName: projectDbName,
storeName: "timeline",
version: 1,
});
data = await projectAdapter.get("timeline");
}

Expand All @@ -157,11 +157,11 @@ async function loadMediaTypesById({
return {};
}

const mediaMetadataAdapter = new IndexedDBAdapter<MediaAssetData>(
`video-editor-media-${projectId}`,
"media-metadata",
1,
);
const mediaMetadataAdapter = new IndexedDBAdapter<MediaAssetData>({
dbName: `video-editor-media-${projectId}`,
storeName: "media-metadata",
version: 1,
});

const mediaEntries = await Promise.all(
mediaIds.map(async (mediaId) => {
Expand Down
2 changes: 1 addition & 1 deletion apps/web/src/stickers/providers/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,6 @@ export function registerDefaultStickerProviders({
if (stickersRegistry.has(provider.id)) {
continue;
}
stickersRegistry.register(provider.id, provider);
stickersRegistry.register({ key: provider.id, definition: provider });
}
}