@histoire/shared 0.7.7 → 0.8.0

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,4 +1,3 @@
1
- import type { Variant } from './types';
2
1
  export declare function clone(data: any): any;
3
2
  export declare function omit(data: any, keys: string[]): {};
4
- export declare function applyStateToVariant(variant: Variant, state: any): void;
3
+ export declare function applyState(target: any, state: any, override?: boolean): void;
package/dist/state.js CHANGED
@@ -22,18 +22,13 @@ export function omit(data, keys) {
22
22
  }
23
23
  return copy;
24
24
  }
25
- export function applyStateToVariant(variant, state) {
26
- if (variant.state) {
27
- for (const key in state) {
28
- if (variant.state[key] && !key.startsWith('_h') && typeof variant.state[key] === 'object' && !Array.isArray(variant.state[key])) {
29
- Object.assign(variant.state[key], state[key]);
30
- }
31
- else {
32
- variant.state[key] = state[key];
33
- }
25
+ export function applyState(target, state, override = false) {
26
+ for (const key in state) {
27
+ if (!override && target[key] && !key.startsWith('_h') && typeof target[key] === 'object' && !Array.isArray(target[key])) {
28
+ Object.assign(target[key], state[key]);
29
+ }
30
+ else {
31
+ target[key] = state[key];
34
32
  }
35
- }
36
- else {
37
- variant.state = state;
38
33
  }
39
34
  }
package/dist/types.d.ts CHANGED
@@ -30,12 +30,12 @@ export interface Variant {
30
30
  title: string;
31
31
  icon?: string;
32
32
  iconColor?: string;
33
- initState?: () => any;
34
33
  setupApp?: (payload: any) => unknown;
35
34
  slots?: () => Readonly<any>;
36
- state?: any;
35
+ state: any;
37
36
  source?: string;
38
37
  responsiveDisabled?: boolean;
38
+ autoPropsDisabled?: boolean;
39
39
  configReady?: boolean;
40
40
  previewReady?: boolean;
41
41
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@histoire/shared",
3
- "version": "0.7.7",
3
+ "version": "0.8.0",
4
4
  "description": "Shared utilities for Histoire",
5
5
  "license": "MIT",
6
6
  "author": {
@@ -26,7 +26,7 @@
26
26
  "sideEffects": false,
27
27
  "dependencies": {},
28
28
  "devDependencies": {
29
- "typescript": "^4.6.3"
29
+ "typescript": "^4.7.4"
30
30
  },
31
31
  "scripts": {
32
32
  "build": "rimraf dist && tsc -d",
package/src/state.ts CHANGED
@@ -1,5 +1,3 @@
1
- import type { Variant } from './types'
2
-
3
1
  export function clone (data) {
4
2
  try {
5
3
  return structuredClone(data)
@@ -24,16 +22,12 @@ export function omit (data, keys: string[]) {
24
22
  return copy
25
23
  }
26
24
 
27
- export function applyStateToVariant (variant: Variant, state: any) {
28
- if (variant.state) {
29
- for (const key in state) {
30
- if (variant.state[key] && !key.startsWith('_h') && typeof variant.state[key] === 'object' && !Array.isArray(variant.state[key])) {
31
- Object.assign(variant.state[key], state[key])
32
- } else {
33
- variant.state[key] = state[key]
34
- }
25
+ export function applyState (target: any, state: any, override = false) {
26
+ for (const key in state) {
27
+ if (!override && target[key] && !key.startsWith('_h') && typeof target[key] === 'object' && !Array.isArray(target[key])) {
28
+ Object.assign(target[key], state[key])
29
+ } else {
30
+ target[key] = state[key]
35
31
  }
36
- } else {
37
- variant.state = state
38
32
  }
39
33
  }
package/src/types.ts CHANGED
@@ -33,12 +33,12 @@ export interface Variant {
33
33
  title: string
34
34
  icon?: string
35
35
  iconColor?: string
36
- initState?: () => any
37
36
  setupApp?: (payload: any) => unknown
38
37
  slots?: () => Readonly<any>
39
- state?: any
38
+ state: any
40
39
  source?: string
41
40
  responsiveDisabled?: boolean
41
+ autoPropsDisabled?: boolean
42
42
  configReady?: boolean
43
43
  previewReady?: boolean
44
44
  }