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,357 +0,0 @@
1
- // @TODO remove @ts-ignore
2
- import { vModelText, vModelCheckbox, vModelSelect, vModelRadio, vModelDynamic, Text } from 'vue';
3
- import { pascal } from 'case';
4
- import { createAutoBuildingObject, indent } from './util';
5
- import { serializeJs } from './serialize-js';
6
- import { voidElements } from './const';
7
- export async function generateSourceCode(variant) {
8
- const vnode = variant.slots().default?.({ state: variant.state ?? {} }) ?? [];
9
- const list = Array.isArray(vnode) ? vnode : [vnode];
10
- const lines = [];
11
- for (const n in list) {
12
- const vnode = list[n];
13
- lines.push(...(await printVNode(vnode, variant.state?._hPropState?.[n])).lines);
14
- }
15
- return lines.join('\n');
16
- }
17
- async function printVNode(vnode, propsOverrides = null) {
18
- if (vnode.type === Text) {
19
- return {
20
- // @ts-ignore
21
- lines: [vnode.children],
22
- isText: true,
23
- };
24
- }
25
- const lines = [];
26
- if (typeof vnode.type === 'object' || typeof vnode.type === 'string') {
27
- // Wait for async component
28
- // @ts-ignore
29
- if (vnode.type?.__asyncLoader && !vnode.type.__asyncResolved) {
30
- // @ts-ignore
31
- await vnode.type.__asyncLoader();
32
- }
33
- const attrs = [];
34
- let multilineAttrs = false;
35
- const skipProps = [
36
- 'key',
37
- ];
38
- // Directives
39
- function genDirective(dirName, dir, valueCode = null) {
40
- let modifiers = '';
41
- for (const key in dir.modifiers) {
42
- if (dir.modifiers[key]) {
43
- modifiers += `.${key}`;
44
- }
45
- }
46
- let arg = '';
47
- if (dir.arg) {
48
- arg = `:${dir.arg}`;
49
- }
50
- if (valueCode) {
51
- // Cleanup render code
52
- valueCode = valueCode.replace(/^\$(setup|props|data)\./g, '');
53
- }
54
- const valueLines = valueCode ? [valueCode] : serializeAndCleanJs(dir.value);
55
- const attr = [];
56
- const dirAttr = `v-${dirName}${arg}${modifiers}="`;
57
- if (valueLines.length > 1) {
58
- attr.push(`${dirAttr}${valueLines[0]}`);
59
- attr.push(...valueLines.slice(1, valueLines.length - 1));
60
- attr.push(`${valueLines[valueLines.length - 1]}"`);
61
- multilineAttrs = true;
62
- }
63
- else {
64
- attr.push(`${dirAttr}${valueLines[0] ?? ''}"`);
65
- }
66
- attrs.push(attr);
67
- }
68
- if (vnode.dirs) {
69
- for (const dir of vnode.dirs) {
70
- // Vmodel
71
- if (dir.dir === vModelText || dir.dir === vModelSelect || dir.dir === vModelRadio || dir.dir === vModelCheckbox || dir.dir === vModelDynamic) {
72
- const listenerKey = `onUpdate:${dir.arg ?? 'modelValue'}`;
73
- const listener = vnode.props[listenerKey];
74
- let valueCode = null;
75
- if (listener) {
76
- skipProps.push(listenerKey);
77
- const listenerSource = listener.toString();
78
- const result = /\(\$event\) => (.*?) = \$event/.exec(listenerSource);
79
- if (result) {
80
- valueCode = result[1];
81
- }
82
- }
83
- genDirective('model', dir, valueCode);
84
- // @ts-ignore
85
- }
86
- else if (dir.instance._ || dir.instance.$) {
87
- // @ts-ignore
88
- const target = dir.instance.$ ?? dir.instance._;
89
- let dirName;
90
- for (const directives of [target.directives, target.appContext.directives]) {
91
- for (const key in directives) {
92
- if (target.directives[key] === dir.dir) {
93
- dirName = key;
94
- break;
95
- }
96
- }
97
- if (dirName)
98
- break;
99
- }
100
- if (dirName) {
101
- genDirective(dirName, dir);
102
- }
103
- }
104
- }
105
- }
106
- // Attributes
107
- function addAttr(prop, value) {
108
- // @ts-ignore
109
- if (typeof value !== 'string' || vnode.dynamicProps?.includes(prop)) {
110
- let directive = ':';
111
- if (prop.startsWith('on')) {
112
- directive = '@';
113
- }
114
- const arg = directive === '@' ? `${prop[2].toLowerCase()}${prop.slice(3)}` : prop;
115
- // v-model on component
116
- const vmodelListener = `onUpdate:${prop}`;
117
- // @ts-ignore
118
- if (directive === ':' && vnode.dynamicProps?.includes(vmodelListener)) {
119
- // Listener
120
- skipProps.push(vmodelListener);
121
- const listener = vnode.props[vmodelListener];
122
- const listenerSource = listener.toString();
123
- let valueCode;
124
- const result = /\(\$event\) => (.*?) = \$event/.exec(listenerSource);
125
- if (result) {
126
- valueCode = result[1];
127
- }
128
- // Modifiers
129
- const modifiersKey = `${prop === 'modelValue' ? 'model' : prop}Modifiers`;
130
- const modifiers = vnode.props[modifiersKey] ?? {};
131
- skipProps.push(modifiersKey);
132
- // Directive
133
- genDirective('model', {
134
- arg: prop === 'modelValue' ? null : prop,
135
- modifiers,
136
- value,
137
- }, valueCode);
138
- return;
139
- }
140
- let serialized;
141
- if (typeof value === 'string' && value.startsWith('{{') && value.endsWith('}}')) {
142
- // It was formatted from auto building object (slot props)
143
- serialized = cleanupExpression(value.substring(2, value.length - 2).trim()).split('\n');
144
- }
145
- else if (typeof value === 'function') {
146
- let code = cleanupExpression(value.toString().replace(/'/g, '\\\'').replace(/"/g, '\''));
147
- const testResult = /function ([^\s]+)\(/.exec(code);
148
- if (testResult) {
149
- // Function name only
150
- serialized = [testResult[1]];
151
- }
152
- else {
153
- if (code.startsWith('($event) => ')) {
154
- // Remove unnecessary `($event) => `
155
- code = code.substring('($event) => '.length);
156
- }
157
- serialized = code.split('\n');
158
- }
159
- }
160
- else {
161
- serialized = serializeAndCleanJs(value);
162
- }
163
- if (serialized.length > 1) {
164
- multilineAttrs = true;
165
- const indented = [`${directive}${arg}="${serialized[0]}`];
166
- indented.push(...serialized.slice(1, serialized.length - 1));
167
- indented.push(`${serialized[serialized.length - 1]}"`);
168
- attrs.push(indented);
169
- }
170
- else {
171
- attrs.push([`${directive}${arg}="${serialized[0]}"`]);
172
- }
173
- }
174
- else {
175
- attrs.push([`${prop}="${value}"`]);
176
- }
177
- }
178
- for (const prop in vnode.props) {
179
- if (skipProps.includes(prop) || (propsOverrides && prop in propsOverrides)) {
180
- continue;
181
- }
182
- const value = vnode.props[prop];
183
- addAttr(prop, value);
184
- }
185
- if (propsOverrides) {
186
- for (const prop in propsOverrides) {
187
- addAttr(prop, propsOverrides[prop]);
188
- }
189
- }
190
- if (attrs.length > 1) {
191
- multilineAttrs = true;
192
- }
193
- // Tags
194
- const tagName = getTagName(vnode);
195
- // Children
196
- let isChildText = false;
197
- const childLines = [];
198
- if (typeof vnode.children === 'string') {
199
- if (tagName === 'pre') {
200
- childLines.push(vnode.children);
201
- }
202
- else {
203
- childLines.push(...vnode.children.split('\n'));
204
- }
205
- isChildText = true;
206
- }
207
- else if (Array.isArray(vnode.children)) {
208
- let isAllChildText;
209
- for (const child of vnode.children) {
210
- // @ts-ignore
211
- const result = await printVNode(child);
212
- if (result.isText) {
213
- if (isAllChildText === undefined) {
214
- isAllChildText = true;
215
- }
216
- const text = result.lines[0];
217
- if (!childLines.length || /^\s/.test(text)) {
218
- childLines.push(text.trim());
219
- }
220
- else {
221
- childLines[childLines.length - 1] += text;
222
- }
223
- }
224
- else {
225
- if (isAllChildText === undefined) {
226
- isAllChildText = false;
227
- }
228
- childLines.push(...result.lines);
229
- }
230
- }
231
- if (isAllChildText !== undefined) {
232
- isChildText = isAllChildText;
233
- }
234
- }
235
- // Slots
236
- if (vnode.children && typeof vnode.children === 'object' && !Array.isArray(vnode.children)) {
237
- for (const key in vnode.children) {
238
- if (typeof vnode.children[key] === 'function') {
239
- const autoObject = createAutoBuildingObject(key => `{{ ${key} }}`, (target, p) => {
240
- // Vue 3
241
- if (p === '__v_isRef') {
242
- return () => false;
243
- }
244
- });
245
- // @ts-ignore
246
- const children = vnode.children[key](autoObject.proxy);
247
- const slotLines = [];
248
- for (const child of children) {
249
- slotLines.push(...(await printVNode(child)).lines);
250
- }
251
- const slotProps = Object.keys(autoObject.cache);
252
- if (slotProps.length) {
253
- childLines.push(`<template #${key}="{ ${slotProps.join(', ')} }">`);
254
- childLines.push(...indent(slotLines));
255
- childLines.push('</template>');
256
- }
257
- else if (key === 'default') {
258
- childLines.push(...slotLines);
259
- }
260
- else {
261
- childLines.push(`<template #${key}>`);
262
- childLines.push(...indent(slotLines));
263
- childLines.push(`</template>`);
264
- }
265
- }
266
- }
267
- }
268
- // Template
269
- const tag = [`<${tagName}`];
270
- if (multilineAttrs) {
271
- for (const attrLines of attrs) {
272
- tag.push(...indent(attrLines));
273
- }
274
- if (childLines.length > 0) {
275
- tag.push('>');
276
- }
277
- }
278
- else {
279
- if (attrs.length === 1) {
280
- tag[0] += ` ${attrs[0]}`;
281
- }
282
- if (childLines.length > 0) {
283
- tag[0] += '>';
284
- }
285
- }
286
- const isVoid = voidElements.includes(tagName.toLowerCase());
287
- if (childLines.length > 0) {
288
- if (childLines.length === 1 && tag.length === 1 && !attrs.length && isChildText) {
289
- lines.push(`${tag[0]}${childLines[0]}</${tagName}>`);
290
- }
291
- else {
292
- lines.push(...tag);
293
- lines.push(...indent(childLines));
294
- lines.push(`</${tagName}>`);
295
- }
296
- }
297
- else if (tag.length > 1) {
298
- lines.push(...tag);
299
- lines.push(isVoid ? '>' : '/>');
300
- }
301
- else {
302
- lines.push(`${tag[0]}${isVoid ? '' : ' /'}>`);
303
- }
304
- }
305
- else if (vnode?.shapeFlag & 1 << 4) {
306
- // @ts-ignore
307
- for (const child of vnode.children) {
308
- lines.push(...(await printVNode(child)).lines);
309
- }
310
- }
311
- return {
312
- lines,
313
- };
314
- }
315
- export function getTagName(vnode) {
316
- if (typeof vnode.type === 'string') {
317
- return vnode.type;
318
- // @ts-ignore
319
- }
320
- else if (vnode.type?.__asyncResolved) {
321
- // @ts-ignore
322
- const asyncComp = vnode.type?.__asyncResolved;
323
- return asyncComp.name ?? getNameFromFile(asyncComp.__file);
324
- // @ts-ignore
325
- }
326
- else if (vnode.type?.name) {
327
- // @ts-ignore
328
- return vnode.type.name;
329
- // @ts-ignore
330
- }
331
- else if (vnode.type?.__file) {
332
- // @ts-ignore
333
- return getNameFromFile(vnode.type.__file);
334
- }
335
- return 'Anonymous';
336
- }
337
- function getNameFromFile(file) {
338
- const parts = /([^/]+)\.vue$/.exec(file);
339
- if (parts) {
340
- return pascal(parts[1]);
341
- }
342
- return 'Anonymous';
343
- }
344
- function serializeAndCleanJs(value) {
345
- const isAutoBuildingObject = !!value?.__autoBuildingObject;
346
- const result = serializeJs(value);
347
- if (isAutoBuildingObject) {
348
- // @ts-ignore
349
- return [cleanupExpression(result.__autoBuildingObjectGetKey)];
350
- }
351
- else {
352
- return cleanupExpression(result).split('\n');
353
- }
354
- }
355
- function cleanupExpression(expr) {
356
- return expr.replace(/\$setup\./g, '');
357
- }
@@ -1,106 +0,0 @@
1
- <script lang="ts">
2
- import { computed, defineComponent, provide, useAttrs, VNode, h, PropType, getCurrentInstance } from 'vue'
3
- import type { Story } from '../../types.js'
4
- import Variant from './Variant.vue'
5
-
6
- export default defineComponent({
7
- // eslint-disable-next-line vue/multi-word-component-names
8
- name: 'Story',
9
- __histoireType: 'story',
10
-
11
- inheritAttrs: false,
12
-
13
- props: {
14
- initState: {
15
- type: Function as PropType<() => any | Promise<any>>,
16
- default: null,
17
- },
18
- },
19
-
20
- setup () {
21
- const vm = getCurrentInstance()
22
-
23
- const attrs = useAttrs() as {
24
- story: Story
25
- }
26
-
27
- const story = computed(() => attrs.story)
28
- provide('story', story)
29
-
30
- const storyComponent: any = vm.parent
31
- // Allows tracking reactivity with watchers to sync state
32
- const implicitState = {
33
- $data: storyComponent.data,
34
- }
35
- function addImplicitState (key, value) {
36
- if (typeof value === 'function' || (value && value.__file)) {
37
- return
38
- }
39
- implicitState[key] = value
40
- }
41
- // From `<script setup>`'s `defineExpose`
42
- for (const key in storyComponent.exposed) {
43
- addImplicitState(key, storyComponent.exposed[key])
44
- }
45
- // We needs __VUE_PROD_DEVTOOLS__ flag set to `true` to enable `devtoolsRawSetupState`
46
- for (const key in storyComponent.devtoolsRawSetupState) {
47
- addImplicitState(key, storyComponent.devtoolsRawSetupState[key])
48
- }
49
- // Shallow copy to prevent sharing object with different variants
50
- provide('implicitState', () => ({ ...implicitState }))
51
-
52
- function updateStory () {
53
- Object.assign(attrs.story, {
54
- slots: () => vm.proxy.$slots,
55
- })
56
- }
57
-
58
- return {
59
- story,
60
- updateStory,
61
- }
62
- },
63
-
64
- render () {
65
- this.updateStory()
66
-
67
- const [firstVariant] = this.story.variants
68
- if (firstVariant.id === '_default') {
69
- return h(Variant, {
70
- variant: firstVariant,
71
- initState: this.initState,
72
- ...this.$attrs,
73
- }, this.$slots)
74
- }
75
-
76
- let index = 0
77
- const applyAttrs = (vnodes: VNode[]) => {
78
- for (const vnode of vnodes) {
79
- // @ts-expect-error custom option
80
- if (vnode.type?.__histoireType === 'variant') {
81
- if (!vnode.props) {
82
- vnode.props = {}
83
- }
84
- vnode.props.variant = this.story.variants[index]
85
- if (!vnode.props.initState && !vnode.props['init-state']) {
86
- vnode.props.initState = this.initState
87
- }
88
- for (const attr in this.$attrs) {
89
- if (typeof vnode.props[attr] === 'undefined') {
90
- vnode.props[attr] = this.$attrs[attr]
91
- }
92
- }
93
- index++
94
- } else if (vnode.children?.length) {
95
- applyAttrs(vnode.children as VNode[])
96
- }
97
- }
98
- }
99
-
100
- // Apply variant as attribute to each child vnode (should be `<Variant>` components)
101
- const vnodes: VNode[] = this.$slots.default()
102
- applyAttrs(vnodes)
103
- return vnodes
104
- },
105
- })
106
- </script>
@@ -1,78 +0,0 @@
1
- <script lang="ts">
2
- import { defineComponent, getCurrentInstance, inject, PropType, useAttrs, watch } from 'vue'
3
- import { Variant } from '../../types'
4
- import { applyStateToVariant } from '../../util/state'
5
-
6
- // const logLocation = location.href.includes('__sandbox') ? '[Sandbox]' : '[Host]'
7
-
8
- export default defineComponent({
9
- // eslint-disable-next-line vue/multi-word-component-names
10
- name: 'Variant',
11
- __histoireType: 'variant',
12
-
13
- props: {
14
- initState: {
15
- type: Function as PropType<() => any | Promise<any>>,
16
- default: null,
17
- },
18
-
19
- source: {
20
- type: String,
21
- default: null,
22
- },
23
-
24
- responsiveDisabled: {
25
- type: Boolean,
26
- default: false,
27
- },
28
-
29
- setupApp: {
30
- type: Function,
31
- default: null,
32
- },
33
- },
34
-
35
- setup (props) {
36
- const attrs = useAttrs() as {
37
- variant: Variant
38
- }
39
-
40
- const vm = getCurrentInstance()
41
-
42
- const implicitState = inject<() => any>('implicitState')
43
-
44
- watch(() => implicitState, value => {
45
- applyStateToVariant(attrs.variant, value())
46
- }, {
47
- immediate: true,
48
- })
49
-
50
- function updateVariant () {
51
- Object.assign(attrs.variant, {
52
- initState: async () => {
53
- if (typeof props.initState === 'function') {
54
- const state = await props.initState()
55
- applyStateToVariant(attrs.variant, state)
56
- }
57
- },
58
- slots: () => vm.proxy.$slots,
59
- source: props.source,
60
- responsiveDisabled: props.responsiveDisabled,
61
- setupApp: props.setupApp,
62
- configReady: true,
63
- })
64
- }
65
- updateVariant()
66
-
67
- return {
68
- updateVariant,
69
- }
70
- },
71
-
72
- render () {
73
- // Trigger variant updates to (re-)render slots
74
- this.updateVariant()
75
- return null
76
- },
77
- })
78
- </script>
@@ -1,21 +0,0 @@
1
- export declare const RouterLinkStub: import("vue").DefineComponent<{
2
- to: {
3
- type: (ObjectConstructor | StringConstructor)[];
4
- required: true;
5
- };
6
- custom: {
7
- type: BooleanConstructor;
8
- default: boolean;
9
- };
10
- }, unknown, unknown, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, Record<string, any>, string, import("vue").VNodeProps & import("vue").AllowedComponentProps & import("vue").ComponentCustomProps, Readonly<import("vue").ExtractPropTypes<{
11
- to: {
12
- type: (ObjectConstructor | StringConstructor)[];
13
- required: true;
14
- };
15
- custom: {
16
- type: BooleanConstructor;
17
- default: boolean;
18
- };
19
- }>>, {
20
- custom: boolean;
21
- }>;
@@ -1,43 +0,0 @@
1
- // From: https://github.com/vuejs/test-utils/blob/main/src/components/RouterLinkStub.ts
2
- import { defineComponent, h, computed } from 'vue';
3
- // match return type of router.resolve: RouteLocation & { href: string }
4
- const defaultRoute = {
5
- path: '/',
6
- name: undefined,
7
- redirectedFrom: undefined,
8
- params: {},
9
- query: {},
10
- hash: '',
11
- fullPath: '/',
12
- matched: [],
13
- meta: {},
14
- href: '/',
15
- };
16
- // TODO: Borrow typings from vue-router-next
17
- export const RouterLinkStub = defineComponent({
18
- name: 'RouterLinkStub',
19
- compatConfig: { MODE: 3 },
20
- props: {
21
- to: {
22
- type: [String, Object],
23
- required: true,
24
- },
25
- custom: {
26
- type: Boolean,
27
- default: false,
28
- },
29
- },
30
- render() {
31
- const route = computed(() => defaultRoute);
32
- // mock reasonable return values to mimic vue-router's useLink
33
- const children = this.$slots?.default?.({
34
- route,
35
- href: computed(() => route.value.href),
36
- isActive: computed(() => false),
37
- isExactActive: computed(() => false),
38
- // eslint-disable-next-line @typescript-eslint/no-empty-function
39
- navigate: async () => { },
40
- });
41
- return this.custom ? children : h('a', undefined, children);
42
- },
43
- });