histoire 0.7.3 → 0.7.4

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.
Files changed (109) hide show
  1. package/client.d.ts +1 -1
  2. package/dist/bundled/StoryView.js +22 -19
  3. package/dist/bundled/dark.js +4 -0
  4. package/dist/bundled/index.js +0 -1
  5. package/dist/bundled/index2.js +6 -6
  6. package/dist/bundled/mapping.js +78 -0
  7. package/dist/bundled/sandbox.js +7 -6
  8. package/dist/bundled/state.js +4 -39
  9. package/dist/bundled/style.css +3 -3
  10. package/dist/client/app/App.vue +2 -2
  11. package/dist/client/app/components/panel/ControlsComponentPropItem.vue +13 -6
  12. package/dist/client/app/components/panel/ControlsComponentProps.vue +2 -1
  13. package/dist/client/app/components/panel/StatePresets.vue +2 -1
  14. package/dist/client/app/components/panel/StoryControls.vue +1 -1
  15. package/dist/client/app/components/panel/StorySourceCode.vue +2 -2
  16. package/dist/client/app/components/story/StoryVariantGridItem.vue +1 -1
  17. package/dist/client/app/components/story/StoryVariantSinglePreviewNative.vue +1 -1
  18. package/dist/client/app/components/story/StoryVariantSinglePreviewRemote.vue +3 -2
  19. package/dist/client/app/components/story/StoryVariantSingleView.vue +1 -1
  20. package/dist/client/app/components/toolbar/StoryVariantNewTab.vue +1 -1
  21. package/dist/client/app/components/tree/StoryGroup.vue +1 -1
  22. package/dist/client/app/index.js +0 -2
  23. package/dist/client/app/sandbox.js +4 -5
  24. package/dist/client/app/types.d.ts +1 -52
  25. package/dist/client/app/util/mapping.d.ts +1 -1
  26. package/dist/client/app/util/mapping.js +50 -36
  27. package/dist/client/app/{components/sandbox/lib.d.ts → util/sandbox.d.ts} +1 -1
  28. package/dist/client/app/{components/sandbox/lib.js → util/sandbox.js} +1 -1
  29. package/dist/client/app/util/state.d.ts +0 -4
  30. package/dist/client/app/util/state.js +3 -39
  31. package/dist/node/collect/index.d.ts +2 -2
  32. package/dist/node/collect/index.js +3 -0
  33. package/dist/node/collect/run.d.ts +2 -0
  34. package/dist/{client/server/index.js → node/collect/run.js} +1 -1
  35. package/dist/node/collect/worker.d.ts +3 -3
  36. package/dist/node/collect/worker.js +4 -1
  37. package/dist/node/config.d.ts +3 -3
  38. package/dist/node/context.d.ts +2 -2
  39. package/dist/node/plugin.d.ts +3 -3
  40. package/dist/node/stories.d.ts +4 -4
  41. package/dist/node/tree.d.ts +3 -22
  42. package/package.json +4 -2
  43. package/src/client/app/App.vue +2 -2
  44. package/src/client/app/components/panel/ControlsComponentPropItem.vue +13 -6
  45. package/src/client/app/components/panel/ControlsComponentProps.vue +2 -1
  46. package/src/client/app/components/panel/StatePresets.vue +2 -1
  47. package/src/client/app/components/panel/StoryControls.vue +1 -1
  48. package/src/client/app/components/panel/StorySourceCode.vue +2 -2
  49. package/src/client/app/components/story/StoryVariantGridItem.vue +1 -1
  50. package/src/client/app/components/story/StoryVariantSinglePreviewNative.vue +1 -1
  51. package/src/client/app/components/story/StoryVariantSinglePreviewRemote.vue +3 -2
  52. package/src/client/app/components/story/StoryVariantSingleView.vue +1 -1
  53. package/src/client/app/components/toolbar/StoryVariantNewTab.vue +1 -1
  54. package/src/client/app/components/tree/StoryGroup.vue +1 -1
  55. package/src/client/app/index.ts +0 -2
  56. package/src/client/app/sandbox.ts +4 -5
  57. package/src/client/app/types.ts +6 -57
  58. package/src/client/app/util/mapping.ts +47 -34
  59. package/src/client/app/{components/sandbox/lib.ts → util/sandbox.ts} +2 -2
  60. package/src/client/app/util/state.ts +4 -39
  61. package/src/node/collect/index.ts +5 -2
  62. package/src/node/collect/run.ts +13 -0
  63. package/src/node/collect/worker.ts +8 -6
  64. package/src/node/config.ts +3 -3
  65. package/src/node/context.ts +2 -2
  66. package/src/node/plugin.ts +2 -2
  67. package/src/node/server.ts +2 -2
  68. package/src/node/stories.ts +4 -4
  69. package/src/node/tree.ts +7 -31
  70. package/vite.config.ts +12 -7
  71. package/dist/bundled/SandboxVue3.js +0 -717
  72. package/dist/bundled/global-components.js +0 -213
  73. package/dist/client/app/codegen/const.d.ts +0 -1
  74. package/dist/client/app/codegen/const.js +0 -3
  75. package/dist/client/app/codegen/serialize-js.d.ts +0 -1
  76. package/dist/client/app/codegen/serialize-js.js +0 -126
  77. package/dist/client/app/codegen/util.d.ts +0 -10
  78. package/dist/client/app/codegen/util.js +0 -70
  79. package/dist/client/app/codegen/vue3.d.ts +0 -4
  80. package/dist/client/app/codegen/vue3.js +0 -357
  81. package/dist/client/app/components/exposed/Story.vue +0 -106
  82. package/dist/client/app/components/exposed/Variant.vue +0 -78
  83. package/dist/client/app/components/sandbox/RouterLinkStub.d.ts +0 -21
  84. package/dist/client/app/components/sandbox/RouterLinkStub.js +0 -43
  85. package/dist/client/app/components/sandbox/SandboxVue3.vue +0 -185
  86. package/dist/client/app/global-components.d.ts +0 -2
  87. package/dist/client/app/global-components.js +0 -10
  88. package/dist/client/server/index.d.ts +0 -7
  89. package/dist/client/server/vue3/Story.vue +0 -120
  90. package/dist/client/server/vue3/Variant.vue +0 -52
  91. package/dist/client/server/vue3/run.d.ts +0 -2
  92. package/dist/client/server/vue3/run.js +0 -45
  93. package/dist/node/types.d.ts +0 -50
  94. package/dist/node/types.js +0 -1
  95. package/src/client/app/codegen/const.ts +0 -3
  96. package/src/client/app/codegen/serialize-js.ts +0 -133
  97. package/src/client/app/codegen/util.ts +0 -79
  98. package/src/client/app/codegen/vue3.ts +0 -361
  99. package/src/client/app/components/exposed/Story.vue +0 -106
  100. package/src/client/app/components/exposed/Variant.vue +0 -78
  101. package/src/client/app/components/sandbox/RouterLinkStub.ts +0 -49
  102. package/src/client/app/components/sandbox/SandboxVue3.vue +0 -185
  103. package/src/client/app/global-components.ts +0 -13
  104. package/src/client/server/index.ts +0 -19
  105. package/src/client/server/vue3/Story.vue +0 -120
  106. package/src/client/server/vue3/Variant.vue +0 -52
  107. package/src/client/server/vue3/run.ts +0 -55
  108. package/src/components.d.ts +0 -143
  109. package/src/node/types.ts +0 -53
@@ -1,213 +0,0 @@
1
- var __defProp = Object.defineProperty;
2
- var __defProps = Object.defineProperties;
3
- var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
4
- var __getOwnPropSymbols = Object.getOwnPropertySymbols;
5
- var __hasOwnProp = Object.prototype.hasOwnProperty;
6
- var __propIsEnum = Object.prototype.propertyIsEnumerable;
7
- var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
8
- var __spreadValues = (a, b) => {
9
- for (var prop in b || (b = {}))
10
- if (__hasOwnProp.call(b, prop))
11
- __defNormalProp(a, prop, b[prop]);
12
- if (__getOwnPropSymbols)
13
- for (var prop of __getOwnPropSymbols(b)) {
14
- if (__propIsEnum.call(b, prop))
15
- __defNormalProp(a, prop, b[prop]);
16
- }
17
- return a;
18
- };
19
- var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
20
- import { markRaw, defineComponent, useAttrs, getCurrentInstance, inject, watch, computed, provide, h } from "vue";
21
- import { registerVueComponents } from "@histoire/controls";
22
- import { a as applyStateToVariant } from "./state.js";
23
- const copiedFromExistingVariant = [
24
- "state",
25
- "slots",
26
- "initState",
27
- "source",
28
- "responsiveDisabled",
29
- "setupApp",
30
- "configReady",
31
- "previewReady"
32
- ];
33
- function mapFile(file, existingFile) {
34
- const result = __spreadProps(__spreadValues({}, file), {
35
- component: markRaw(file.component),
36
- story: __spreadProps(__spreadValues({}, file.story), {
37
- title: file.story.title,
38
- file: markRaw(file),
39
- variants: file.story.variants.map((v) => mapVariant(v)),
40
- slots: () => ({})
41
- })
42
- });
43
- if (existingFile) {
44
- for (const index in result.story.variants) {
45
- const variant = result.story.variants[index];
46
- const existingVariant = existingFile.story.variants[index];
47
- if (existingVariant) {
48
- for (const key of copiedFromExistingVariant) {
49
- if (typeof existingVariant[key] !== "undefined") {
50
- if (key === "state") {
51
- variant.state = existingVariant.state;
52
- continue;
53
- }
54
- variant[key] = existingVariant[key];
55
- }
56
- }
57
- }
58
- }
59
- if (existingFile.story.lastSelectedVariant) {
60
- result.story.lastSelectedVariant = result.story.variants.find((v) => v.id === existingFile.story.lastSelectedVariant.id);
61
- }
62
- }
63
- return result;
64
- }
65
- function mapVariant(variant) {
66
- return __spreadProps(__spreadValues({}, variant), {
67
- state: null,
68
- initState: null,
69
- setupApp: null,
70
- slots: () => ({}),
71
- previewReady: false
72
- });
73
- }
74
- const _sfc_main$1 = defineComponent({
75
- name: "Variant",
76
- __histoireType: "variant",
77
- props: {
78
- initState: {
79
- type: Function,
80
- default: null
81
- },
82
- source: {
83
- type: String,
84
- default: null
85
- },
86
- responsiveDisabled: {
87
- type: Boolean,
88
- default: false
89
- },
90
- setupApp: {
91
- type: Function,
92
- default: null
93
- }
94
- },
95
- setup(props) {
96
- const attrs = useAttrs();
97
- const vm = getCurrentInstance();
98
- const implicitState = inject("implicitState");
99
- watch(() => implicitState, (value) => {
100
- applyStateToVariant(attrs.variant, value());
101
- }, {
102
- immediate: true
103
- });
104
- function updateVariant() {
105
- Object.assign(attrs.variant, {
106
- initState: async () => {
107
- if (typeof props.initState === "function") {
108
- const state = await props.initState();
109
- applyStateToVariant(attrs.variant, state);
110
- }
111
- },
112
- slots: () => vm.proxy.$slots,
113
- source: props.source,
114
- responsiveDisabled: props.responsiveDisabled,
115
- setupApp: props.setupApp,
116
- configReady: true
117
- });
118
- }
119
- updateVariant();
120
- return {
121
- updateVariant
122
- };
123
- },
124
- render() {
125
- this.updateVariant();
126
- return null;
127
- }
128
- });
129
- const _sfc_main = defineComponent({
130
- name: "Story",
131
- __histoireType: "story",
132
- inheritAttrs: false,
133
- props: {
134
- initState: {
135
- type: Function,
136
- default: null
137
- }
138
- },
139
- setup() {
140
- const vm = getCurrentInstance();
141
- const attrs = useAttrs();
142
- const story = computed(() => attrs.story);
143
- provide("story", story);
144
- const storyComponent = vm.parent;
145
- const implicitState = {
146
- $data: storyComponent.data
147
- };
148
- function addImplicitState(key, value) {
149
- if (typeof value === "function" || value && value.__file) {
150
- return;
151
- }
152
- implicitState[key] = value;
153
- }
154
- for (const key in storyComponent.exposed) {
155
- addImplicitState(key, storyComponent.exposed[key]);
156
- }
157
- for (const key in storyComponent.devtoolsRawSetupState) {
158
- addImplicitState(key, storyComponent.devtoolsRawSetupState[key]);
159
- }
160
- provide("implicitState", () => __spreadValues({}, implicitState));
161
- function updateStory() {
162
- Object.assign(attrs.story, {
163
- slots: () => vm.proxy.$slots
164
- });
165
- }
166
- return {
167
- story,
168
- updateStory
169
- };
170
- },
171
- render() {
172
- this.updateStory();
173
- const [firstVariant] = this.story.variants;
174
- if (firstVariant.id === "_default") {
175
- return h(_sfc_main$1, __spreadValues({
176
- variant: firstVariant,
177
- initState: this.initState
178
- }, this.$attrs), this.$slots);
179
- }
180
- let index = 0;
181
- const applyAttrs = (vnodes2) => {
182
- var _a, _b;
183
- for (const vnode of vnodes2) {
184
- if (((_a = vnode.type) == null ? void 0 : _a.__histoireType) === "variant") {
185
- if (!vnode.props) {
186
- vnode.props = {};
187
- }
188
- vnode.props.variant = this.story.variants[index];
189
- if (!vnode.props.initState && !vnode.props["init-state"]) {
190
- vnode.props.initState = this.initState;
191
- }
192
- for (const attr in this.$attrs) {
193
- if (typeof vnode.props[attr] === "undefined") {
194
- vnode.props[attr] = this.$attrs[attr];
195
- }
196
- }
197
- index++;
198
- } else if ((_b = vnode.children) == null ? void 0 : _b.length) {
199
- applyAttrs(vnode.children);
200
- }
201
- }
202
- };
203
- const vnodes = this.$slots.default();
204
- applyAttrs(vnodes);
205
- return vnodes;
206
- }
207
- });
208
- function registerGlobalComponents(app) {
209
- app.component("Story", _sfc_main);
210
- app.component("Variant", _sfc_main$1);
211
- registerVueComponents(app);
212
- }
213
- export { mapFile as m, registerGlobalComponents as r };
@@ -1 +0,0 @@
1
- export declare const voidElements: string[];
@@ -1,3 +0,0 @@
1
- export const voidElements = [
2
- 'area', 'base', 'br', 'col', 'embed', 'hr', 'img', 'input', 'keygen', 'link', 'meta', 'param', 'source', 'track', 'wbr',
3
- ];
@@ -1 +0,0 @@
1
- export declare function serializeJs(value: any): string;
@@ -1,126 +0,0 @@
1
- const KEY_ESCAPE_REG = /[\s-.:|#@$£*%]/;
2
- const MAX_SINGLE_LINE_ARRAY_LENGTH = 3;
3
- export function serializeJs(value) {
4
- const seen = new Set();
5
- if (value === undefined) {
6
- return 'undefined';
7
- }
8
- if (value === null) {
9
- return 'null';
10
- }
11
- if (typeof value === 'string') {
12
- return `'${value}'`;
13
- }
14
- if (typeof value === 'boolean') {
15
- return value ? 'true' : 'false';
16
- }
17
- if (Array.isArray(value)) {
18
- return printLines(arrayToSourceLines(value, seen));
19
- }
20
- if (typeof value === 'object') {
21
- return printLines(objectToSourceLines(value, seen));
22
- }
23
- if (value?.__autoBuildingObject) {
24
- return value;
25
- }
26
- if (typeof value === 'function' && value.name) {
27
- return value.name;
28
- }
29
- return value.toString();
30
- }
31
- function printLines(lines) {
32
- return lines.map(line => ' '.repeat(line.spaces) + line.line).join('\n');
33
- }
34
- function objectToSourceLines(object, seen, indentCount = 0) {
35
- if (seen.has(object)) {
36
- object = {};
37
- }
38
- else {
39
- seen.add(object);
40
- }
41
- return createLines(indentCount, lines => {
42
- lines.push('{');
43
- lines.push(...createLines(1, lines => {
44
- for (const key in object) {
45
- const value = object[key];
46
- let printedKey = key;
47
- if (KEY_ESCAPE_REG.test(key)) {
48
- printedKey = `'${printedKey}'`;
49
- }
50
- addLinesFromValue(lines, value, `${printedKey}: `, ',', seen);
51
- }
52
- }));
53
- lines.push('}');
54
- });
55
- }
56
- function arrayToSourceLines(array, seen, indentCount = 0) {
57
- if (seen.has(array)) {
58
- array = [];
59
- }
60
- else {
61
- seen.add(array);
62
- }
63
- return createLines(indentCount, lines => {
64
- const contentLines = createLines(1, lines => {
65
- for (const value of array) {
66
- addLinesFromValue(lines, value, '', ',', seen);
67
- }
68
- });
69
- if (contentLines.length === 0) {
70
- lines.push('[]');
71
- }
72
- else if (contentLines.length <= MAX_SINGLE_LINE_ARRAY_LENGTH && !contentLines.some(line => line.spaces > 1)) {
73
- const [first] = contentLines;
74
- first.line = contentLines.map(({ line }) => line.substring(0, line.length - 1)).join(', ');
75
- first.line = `[${first.line}]`;
76
- first.spaces--;
77
- lines.push(first);
78
- }
79
- else {
80
- lines.push('[', ...contentLines, ']');
81
- }
82
- });
83
- }
84
- function createLines(indentCount, handler) {
85
- const lines = [];
86
- handler(lines);
87
- return lines.map(line => {
88
- if (line.spaces != null) {
89
- line.spaces += indentCount;
90
- return line;
91
- }
92
- return { spaces: indentCount, line };
93
- });
94
- }
95
- function addLinesFromValue(lines, value, before, after, seen) {
96
- let result;
97
- if (Array.isArray(value)) {
98
- lines.push(...wrap(arrayToSourceLines(value, seen), before, after));
99
- return;
100
- }
101
- else if (value && typeof value === 'object') {
102
- lines.push(...wrap(objectToSourceLines(value, seen), before, after));
103
- return;
104
- }
105
- else if (typeof value === 'string') {
106
- result = value.includes('\'') ? `\`${value}\`` : `'${value}'`;
107
- }
108
- else if (typeof value === 'undefined') {
109
- result = 'undefined';
110
- }
111
- else if (value === null) {
112
- result = 'null';
113
- }
114
- else if (typeof value === 'boolean') {
115
- result = value ? 'true' : 'false';
116
- }
117
- else {
118
- result = value;
119
- }
120
- lines.push(before + result + after);
121
- }
122
- function wrap(lines, before, after) {
123
- lines[0].line = before + lines[0].line;
124
- lines[lines.length - 1].line += after;
125
- return lines;
126
- }
@@ -1,10 +0,0 @@
1
- export declare function indent(lines: string[], count?: number): string[];
2
- export declare function unindent(code: string): string;
3
- interface AutoBuildingOject {
4
- key: string;
5
- cache: Record<string | symbol, AutoBuildingOject>;
6
- target: any;
7
- proxy: any;
8
- }
9
- export declare function createAutoBuildingObject(format?: (key: string) => string, specialKeysHandler?: (target: any, p: string | symbol) => (() => unknown) | null, key?: string, depth?: number): AutoBuildingOject;
10
- export {};
@@ -1,70 +0,0 @@
1
- /* eslint-disable @typescript-eslint/ban-types */
2
- export function indent(lines, count = 1) {
3
- return lines.map(line => `${' '.repeat(count)}${line}`);
4
- }
5
- export function unindent(code) {
6
- const lines = code.split('\n');
7
- let indentLevel = -1;
8
- let indentText;
9
- const linesToAnalyze = lines.filter(line => line.trim().length > 0);
10
- for (const line of linesToAnalyze) {
11
- const match = /^\s*/.exec(line);
12
- if (match && (indentLevel === -1 || indentLevel > match[0].length)) {
13
- indentLevel = match[0].length;
14
- indentText = match[0];
15
- }
16
- }
17
- const result = [];
18
- for (const line of lines) {
19
- result.push(line.replace(indentText, ''));
20
- }
21
- return result.join('\n').trim();
22
- }
23
- export function createAutoBuildingObject(format, specialKeysHandler, key = '', depth = 0) {
24
- const cache = {};
25
- if (depth > 32)
26
- return { key, cache, target: {}, proxy: () => key };
27
- const target = () => {
28
- const k = key + '()';
29
- return format ? format(k) : k;
30
- };
31
- const proxy = new Proxy(target, {
32
- get(_, p) {
33
- if (p === '__autoBuildingObject') {
34
- return true;
35
- }
36
- if (p === '__autoBuildingObjectGetKey') {
37
- return key;
38
- }
39
- if (specialKeysHandler) {
40
- const fn = specialKeysHandler(target, p);
41
- if (fn) {
42
- return fn();
43
- }
44
- }
45
- if (p === 'toString') {
46
- const k = key + '.toString()';
47
- return () => format ? format(k) : k;
48
- }
49
- if (p === Symbol.toPrimitive) {
50
- return () => format ? format(key) : key;
51
- }
52
- if (!cache[p]) {
53
- const childKey = key ? `${key}.${p.toString()}` : p.toString();
54
- const child = createAutoBuildingObject(format, specialKeysHandler, childKey, depth + 1);
55
- cache[p] = { key: childKey, ...child };
56
- }
57
- return cache[p].proxy;
58
- },
59
- apply(_, thisArg, args) {
60
- const k = `${key}(${args.join(', ')})`;
61
- return format ? format(k) : k;
62
- },
63
- });
64
- return {
65
- key,
66
- cache,
67
- target,
68
- proxy,
69
- };
70
- }
@@ -1,4 +0,0 @@
1
- import { VNode } from 'vue';
2
- import type { Variant } from '../types';
3
- export declare function generateSourceCode(variant: Variant): Promise<string>;
4
- export declare function getTagName(vnode: VNode): any;