import { makeObservable, computed } from "mobx"; import { underscore } from "eez-studio-shared/string"; import { EezObject, IEezObject } from "project-editor/core/object"; import type { Action } from "project-editor/features/action/action"; import type { Bitmap } from "project-editor/features/bitmap/bitmap"; import type { Font } from "project-editor/features/font/font"; import type { Page } from "project-editor/features/page/page"; import type { Style } from "project-editor/features/style/style"; import type { LVGLStyle } from "project-editor/lvgl/style"; import type { Color } from "project-editor/features/style/theme"; import type { Variable } from "project-editor/features/variable/variable"; import type { Project } from "project-editor/project/project"; import { ProjectEditor } from "project-editor/project-editor-interface"; //////////////////////////////////////////////////////////////////////////////// export const IMPORT_AS_PREFIX = "."; //////////////////////////////////////////////////////////////////////////////// export type AssetType = | "pages" | "actions" | "variables/globalVariables" | "allStyles" | "allLvglStyles" | "fonts" | "bitmaps" | "colors"; //////////////////////////////////////////////////////////////////////////////// function findAsset( project: Project, assetType: AssetType, name: string | undefined ) { if (name == undefined) { return undefined; } let objects = project._assets.maps["name"].allAssets.get( assetType + "/" + name ); if (objects && objects.length === 1) { return objects[0] as T; } return undefined; } function findAssetDeep( project: Project, assetType: AssetType, name: string | undefined ) { if (name == undefined) { return undefined; } const importAsList = name.split(IMPORT_AS_PREFIX); for (let i = 0; i < importAsList.length - 1; i++) { const importDirective = project.settings.general.imports.find( importDirective => importDirective.importAs == importAsList[i] ); if (!importDirective || !importDirective.project) { return undefined; } project = importDirective.project; } return findAsset( project, assetType, importAsList[importAsList.length - 1] ); } export function findPage(project: Project, name: string) { return findAsset(project, "pages", name); } export function findAction(project: Project, name: string) { return findAsset(project, "actions", name); } export function findVariable(project: Project, name: string) { return findAsset(project, "variables/globalVariables", name); } export function findVariableDeep(project: Project, name: string) { return findAssetDeep(project, "variables/globalVariables", name); } export function findBitmap(project: Project, name: any) { return findAsset(project, "bitmaps", name); } export function findStyle(project: Project, name: string | undefined) { return findAsset