Skip to content

Commit

Permalink
Automated linting update and features.json sync
Browse files Browse the repository at this point in the history
  • Loading branch information
github-actions[bot] committed Oct 23, 2023
1 parent 04bf4dd commit 1f4fc4c
Showing 1 changed file with 22 additions and 7 deletions.
29 changes: 22 additions & 7 deletions packages/studio-ui/src/utils/loadUserAssets.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
import useStudioStore from "../store/useStudioStore";
import getFunctionComponent from "./getFunctionComponent";
import dynamicImportFromBrowser from "./dynamicImportFromBrowser";
import { ComponentMetadata, FileMetadataKind, LayoutState, PageState } from "@yext/studio-plugin";
import {
ComponentMetadata,
FileMetadataKind,
LayoutState,
PageState,
} from "@yext/studio-plugin";

export const USER_CUSTOM_STYLE_ATTRIBUTE = "studio-user-custom-style";

Expand Down Expand Up @@ -39,10 +44,18 @@ export async function loadStyling() {
const studioStore = useStudioStore.getState();
const pages = Object.values(studioStore.pages.pages);
const layouts = Object.values(studioStore.layouts.layoutNameToLayoutState);
const fileMetadatas = Object.values(studioStore.fileMetadatas.UUIDToFileMetadata);
const componentMetadatas = fileMetadatas.filter((fileMetadata) => fileMetadata.kind === FileMetadataKind.Component) as ComponentMetadata[]
const fileMetadatas = Object.values(
studioStore.fileMetadatas.UUIDToFileMetadata
);
const componentMetadatas = fileMetadatas.filter(
(fileMetadata) => fileMetadata.kind === FileMetadataKind.Component
) as ComponentMetadata[];

const userCssFilepaths = getCssImportsFromUserFiles([...pages, ...layouts, ...componentMetadatas])
const userCssFilepaths = getCssImportsFromUserFiles([
...pages,
...layouts,
...componentMetadatas,
]);
for (const filepath of userCssFilepaths) {
await dynamicImportFromBrowser(filepath).then((styling) => {
const styleEl = document.createElement("style");
Expand All @@ -54,8 +67,10 @@ export async function loadStyling() {
}
}

function getCssImportsFromUserFiles(cssImporters: (ComponentMetadata | PageState | LayoutState)[]) {
function getCssImportsFromUserFiles(
cssImporters: (ComponentMetadata | PageState | LayoutState)[]
) {
return Object.values(cssImporters).reduce((cssImports, importer) => {
return new Set([...cssImports, ...importer.cssImports])
}, new Set<string>())
return new Set([...cssImports, ...importer.cssImports]);
}, new Set<string>());
}

0 comments on commit 1f4fc4c

Please sign in to comment.