@histoire/shared 0.11.8 → 0.11.9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/state.d.ts CHANGED
@@ -1,3 +1,3 @@
1
1
  export declare function clone(data: any): any;
2
2
  export declare function omit(data: any, keys: string[]): {};
3
- export declare function applyState(target: any, state: any): void;
3
+ export declare function applyState(target: any, state: any, override?: boolean): void;
package/dist/state.js CHANGED
@@ -22,8 +22,14 @@ export function omit(data, keys) {
22
22
  }
23
23
  return copy;
24
24
  }
25
- export function applyState(target, state) {
25
+ export function applyState(target, state, override = false) {
26
26
  for (const key in state) {
27
- target[key] = state[key];
27
+ // iframe sync needs to update properties without overriding them
28
+ if (!override && target[key] && !key.startsWith('_h') && typeof target[key] === 'object' && !Array.isArray(target[key])) {
29
+ Object.assign(target[key], state[key]);
30
+ }
31
+ else {
32
+ target[key] = state[key];
33
+ }
28
34
  }
29
35
  }
@@ -1 +1 @@
1
- export declare type Awaitable<T> = Promise<T> | T;
1
+ export type Awaitable<T> = Promise<T> | T;
@@ -7,9 +7,9 @@ export interface SupportMatchPattern {
7
7
  patterns: string[];
8
8
  pluginIds: string[];
9
9
  }
10
- export declare type CustomizableColors = 'primary' | 'gray';
11
- export declare type ColorKeys = '50' | '100' | '200' | '300' | '400' | '500' | '600' | '700' | '800' | '900';
12
- export declare type GrayColorKeys = ColorKeys | '750' | '850' | '950';
10
+ export type CustomizableColors = 'primary' | 'gray';
11
+ export type ColorKeys = '50' | '100' | '200' | '300' | '400' | '500' | '600' | '700' | '800' | '900';
12
+ export type GrayColorKeys = ColorKeys | '750' | '850' | '950';
13
13
  export interface ResponsivePreset {
14
14
  label: string;
15
15
  width: number;
@@ -202,4 +202,4 @@ export interface HistoireConfig {
202
202
  web?: RegExp[];
203
203
  };
204
204
  }
205
- export declare type ConfigMode = 'build' | 'dev';
205
+ export type ConfigMode = 'build' | 'dev';
@@ -32,8 +32,8 @@ export interface PluginApiBase {
32
32
  export interface PluginApiDev extends PluginApiBase {
33
33
  watcher: typeof chokidar;
34
34
  }
35
- export declare type BuildEndCallback = () => Promise<void> | void;
36
- export declare type PreviewStoryCallback = (payload: {
35
+ export type BuildEndCallback = () => Promise<void> | void;
36
+ export type PreviewStoryCallback = (payload: {
37
37
  file: string;
38
38
  story: ServerStory;
39
39
  variant: ServerVariant;
@@ -9,7 +9,7 @@ export interface StoryFile {
9
9
  default: string;
10
10
  }>;
11
11
  }
12
- export declare type StoryLayout = {
12
+ export type StoryLayout = {
13
13
  type: 'single';
14
14
  iframe?: boolean;
15
15
  } | {
@@ -170,7 +170,7 @@ export interface ServerTreeGroup {
170
170
  title: string;
171
171
  children: (ServerTreeFolder | ServerTreeLeaf)[];
172
172
  }
173
- export declare type ServerTree = (ServerTreeGroup | ServerTreeFolder | ServerTreeLeaf)[];
173
+ export type ServerTree = (ServerTreeGroup | ServerTreeFolder | ServerTreeLeaf)[];
174
174
  export interface ServerRunPayload {
175
175
  file: ServerStoryFile;
176
176
  storyData: ServerStory[];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@histoire/shared",
3
- "version": "0.11.8",
3
+ "version": "0.11.9",
4
4
  "description": "Shared utilities for Histoire",
5
5
  "license": "MIT",
6
6
  "author": {
package/src/state.ts CHANGED
@@ -22,8 +22,13 @@ export function omit (data, keys: string[]) {
22
22
  return copy
23
23
  }
24
24
 
25
- export function applyState (target: any, state: any) {
25
+ export function applyState (target: any, state: any, override = false) {
26
26
  for (const key in state) {
27
- target[key] = state[key]
27
+ // iframe sync needs to update properties without overriding them
28
+ if (!override && target[key] && !key.startsWith('_h') && typeof target[key] === 'object' && !Array.isArray(target[key])) {
29
+ Object.assign(target[key], state[key])
30
+ } else {
31
+ target[key] = state[key]
32
+ }
28
33
  }
29
34
  }