mirror of
https://github.com/webstudio-is/webstudio.git
synced 2026-10-30 00:27:43 +09:00
## Description 1. What is this PR about (link the issue and add a short description) ## Steps for reproduction 1. click button 2. expect xyz ## Code Review - [ ] hi @kof, I need you to do - conceptual review (architecture, feature-correctness) - detailed review (read every line) - test it on preview ## Before requesting a review - [ ] made a self-review - [ ] added inline comments where things may be not obvious (the "why", not "what") ## Before merging - [ ] tested locally and on preview environment (preview dev login: 0000) - [ ] updated [test cases](https://github.com/webstudio-is/webstudio/blob/main/apps/builder/docs/test-cases.md) document - [ ] added tests - [ ] if any new env variables are added, added them to `.env` file
103 lines
2.9 KiB
TypeScript
103 lines
2.9 KiB
TypeScript
/**
|
|
* All data stores used by the sync infrastructure.
|
|
* This provides a single source of truth for stores used in sync-server and sync-stores.
|
|
*/
|
|
|
|
import { atom } from "nanostores";
|
|
import type {
|
|
Assets,
|
|
Breakpoints,
|
|
DataSources,
|
|
Instances,
|
|
Pages,
|
|
Props,
|
|
Resource,
|
|
Styles,
|
|
StyleSources,
|
|
StyleSourceSelections,
|
|
} from "@webstudio-is/sdk";
|
|
import type { Project } from "@webstudio-is/project";
|
|
import type { MarketplaceProduct } from "@webstudio-is/project-build";
|
|
|
|
export const $project = atom<Project | undefined>();
|
|
|
|
export const $pages = atom<undefined | Pages>(undefined);
|
|
|
|
export const $assets = atom<Assets>(new Map());
|
|
|
|
export const $instances = atom<Instances>(new Map());
|
|
|
|
export const $props = atom<Props>(new Map());
|
|
|
|
export const $dataSources = atom<DataSources>(new Map());
|
|
|
|
export const $resources = atom(new Map<Resource["id"], Resource>());
|
|
|
|
export const $breakpoints = atom<Breakpoints>(new Map());
|
|
|
|
/**
|
|
* styleSources defines where styles come from (local or token).
|
|
*
|
|
* $styles contains actual styling rules, tied to styleSourceIds.
|
|
* $styles.styleSourceId -> $styleSources.id
|
|
*/
|
|
export const $styleSources = atom<StyleSources>(new Map());
|
|
|
|
/**
|
|
* This is a list of connections between instances (instanceIds) and styleSources.
|
|
* $styleSourceSelections.values[] -> $styleSources.id[]
|
|
*/
|
|
export const $styleSourceSelections = atom<StyleSourceSelections>(new Map());
|
|
|
|
/**
|
|
* $styles contains actual styling rules
|
|
* (breakpointId, styleSourceId, property, value, listed), tied to styleSourceIds
|
|
* $styles.styleSourceId -> $styleSources.id
|
|
*/
|
|
export const $styles = atom<Styles>(new Map());
|
|
|
|
export const $marketplaceProduct = atom<undefined | MarketplaceProduct>();
|
|
|
|
export const $publisherHost = atom<string>("wstd.work");
|
|
|
|
/**
|
|
* Get initial values for all data stores.
|
|
* Used for resetting stores when switching between projects.
|
|
*/
|
|
const getInitialDataStoreValues = () => ({
|
|
project: undefined,
|
|
pages: undefined,
|
|
assets: new Map(),
|
|
instances: new Map(),
|
|
props: new Map(),
|
|
dataSources: new Map(),
|
|
resources: new Map(),
|
|
breakpoints: new Map(),
|
|
styleSources: new Map(),
|
|
styleSourceSelections: new Map(),
|
|
styles: new Map(),
|
|
marketplaceProduct: undefined,
|
|
publisherHost: "wstd.work",
|
|
});
|
|
|
|
/**
|
|
* Reset all data stores to their initial values.
|
|
* Call this when switching between projects to prevent data leakage.
|
|
*/
|
|
export const resetDataStores = () => {
|
|
const initial = getInitialDataStoreValues();
|
|
$project.set(initial.project);
|
|
$pages.set(initial.pages);
|
|
$assets.set(initial.assets);
|
|
$instances.set(initial.instances);
|
|
$props.set(initial.props);
|
|
$dataSources.set(initial.dataSources);
|
|
$resources.set(initial.resources);
|
|
$breakpoints.set(initial.breakpoints);
|
|
$styleSources.set(initial.styleSources);
|
|
$styleSourceSelections.set(initial.styleSourceSelections);
|
|
$styles.set(initial.styles);
|
|
$marketplaceProduct.set(initial.marketplaceProduct);
|
|
$publisherHost.set(initial.publisherHost);
|
|
};
|