Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
51 changes: 24 additions & 27 deletions src/lib/components/tree/ConfigTree.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import {
} from "./TreeNode.svelte";
import { v4 as uuidv4 } from "uuid";
import { ElementType, grid, ModuleType } from "@intechstudio/grid-protocol";
import { isModuleTypeCompatible } from "../../utils";

export namespace Tree {
export interface Options {
Expand Down Expand Up @@ -98,33 +99,29 @@ export namespace Tree {
}

function isCompatible(config: Config, types: string[]) {
if (config.type === ModuleType.VSN1L || config.type === ModuleType.VSN1R) {
return (
types.includes(ModuleType.VSN1L) || types.includes(ModuleType.VSN1R)
);
} else {
switch (config.configType) {
case "profile": {
const moduleTypes = types.filter((t): t is ModuleType =>
isModuleType(t),
);
return moduleTypes.includes(config.type as ModuleType);
}
case "preset": {
const elementTypes = types.filter((t): t is ElementType =>
isElementType(t),
);
const leftCompatible = elementTypes.some((e) =>
grid.is_element_compatible_with(e, config.type as ElementType),
);
const rightCompatible = elementTypes.some((e) =>
grid.is_element_compatible_with(config.type as ElementType, e),
);
return leftCompatible || rightCompatible;
}
case "snippet": {
return true;
}
switch (config.configType) {
case "profile": {
const moduleTypes = types.filter((t): t is ModuleType =>
isModuleType(t),
);
return moduleTypes.some((t) =>
isModuleTypeCompatible(config.type as ModuleType, t),
);
}
case "preset": {
const elementTypes = types.filter((t): t is ElementType =>
isElementType(t),
);
const leftCompatible = elementTypes.some((e) =>
grid.is_element_compatible_with(e, config.type as ElementType),
);
const rightCompatible = elementTypes.some((e) =>
grid.is_element_compatible_with(config.type as ElementType, e),
);
return leftCompatible || rightCompatible;
}
case "snippet": {
return true;
}
}
}
Expand Down
16 changes: 16 additions & 0 deletions src/lib/utils.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,25 @@
import type { EditorReturnType } from "./types";
import { ModuleType } from "@intechstudio/grid-protocol";

export function applyFocus(el: HTMLElement) {
el.focus();
}

/**
* Module-type-level compatibility, e.g. for profile overwrite/load and the
* config tree's module grouping. VSN1L and VSN1R share a profile format and
* are treated as interchangeable; every other module type must match exactly.
* Not for element/preset compatibility - use grid.is_element_compatible_with
* for that, since a module match doesn't imply per-element event support.
*/
export function isModuleTypeCompatible(a: ModuleType, b: ModuleType): boolean {
const vsn1Modules = [ModuleType.VSN1L, ModuleType.VSN1R];
if (vsn1Modules.includes(a)) {
return vsn1Modules.includes(b);
}
return a === b;
}

export async function parentIframeCommunication({
windowPostMessageName,
dataForParent,
Expand Down
12 changes: 10 additions & 2 deletions src/routes/EditorLayout.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,10 @@
} from "../lib/schemas";
import { fade } from "svelte/transition";
import { Toggle } from "@intechstudio/grid-uikit";
import { parentIframeCommunication } from "../lib/utils";
import {
parentIframeCommunication,
isModuleTypeCompatible,
} from "../lib/utils";
import {
createConfigManager,
updateLocalConfigs,
Expand Down Expand Up @@ -261,7 +264,12 @@
files: editorConfig?.files,
};

if (newConfig.type !== config.type) {
if (
!isModuleTypeCompatible(
newConfig.type as ModuleType,
config.type as ModuleType,
)
) {
parentIframeCommunication({
windowPostMessageName: "sendLogMessage",
dataForParent: {
Expand Down
Loading