Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Vue: Add repro template for vue-cli #19165

Merged
merged 37 commits into from
Sep 18, 2022
Merged
Show file tree
Hide file tree
Changes from 18 commits
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
e757728
Vue: Add repro templates for vue-cli
shilman Sep 11, 2022
33a1d7d
Merge branch 'next' into shilman/vue-cli-repro-templates
shilman Sep 11, 2022
5f220b6
Vue-cli: Don't nuke cwd on init
shilman Sep 11, 2022
7e84537
Escape vue-cli vue2 preset properly
shilman Sep 11, 2022
06d885a
Vue2: Add template components for sandbox
shilman Sep 12, 2022
19f25e0
Merge branch 'next' into shilman/vue-cli-repro-templates
shilman Sep 13, 2022
3dbf5f6
CLI/Vue3: Upgrade vue-loader and install `@vue/compiler-sfc`
shilman Sep 13, 2022
60f1aa5
Vue: Fix typo in template Button
shilman Sep 13, 2022
55f4668
Merge branch 'next' into shilman/vue-cli-repro-templates
shilman Sep 14, 2022
10cfadd
Try fix missing typescript in JS-only project
shilman Sep 14, 2022
05dfc5c
Apply the same fix for vue3 webpack preset
shilman Sep 14, 2022
ac16a23
Vue3: Fix babel / ts-loader both run against .ts files
shilman Sep 14, 2022
fde61fc
Revert "Apply the same fix for vue3 webpack preset"
tmeasday Sep 14, 2022
024e8a7
Revert "Try fix missing typescript in JS-only project"
tmeasday Sep 14, 2022
2dc7254
Exclude all rules from template-stories
tmeasday Sep 14, 2022
48e3af9
Vue: Add Form/Html template components
shilman Sep 14, 2022
b8380fa
Vue2: Fix play's within(canvas) by preserving `#storybook-root`
shilman Sep 15, 2022
1aa24c9
Update snapshots
shilman Sep 15, 2022
70fc932
Don't run source snippet e2e on vue-cli's vue3
shilman Sep 15, 2022
1036cbc
Addon-a11y: Fix template stories
shilman Sep 15, 2022
398dadc
Vue: Fixed Pre template component
shilman Sep 15, 2022
7e7bffb
Fix skip logic for vue-cli snippet test
shilman Sep 15, 2022
5dbe451
Fix duplicate import
shilman Sep 15, 2022
5ef1742
Added Vue2 DOM breaking change to MIGRATION guide
shilman Sep 15, 2022
7571d14
CLI: Don't add babel dependencies
shilman Sep 15, 2022
cb4b205
Fix stories
shilman Sep 15, 2022
000e6a1
Actions/Interactions: Identify actions by isAction to fix production …
shilman Sep 16, 2022
18709fc
Task: Prefix chromatic junit keys with templateKey
shilman Sep 16, 2022
e957951
Merge branch 'next' into shilman/vue-cli-repro-templates
shilman Sep 16, 2022
b9add15
Vue: Disable Vue2 repro template until rendering is fixed
shilman Sep 17, 2022
b613372
Fix location of store manual title story
shilman Sep 17, 2022
150cf37
Skip story re-rendering test for vue3/svelte
shilman Sep 17, 2022
e5de18d
Fix typo
shilman Sep 17, 2022
4857588
Scripts: Prefix junit into base task runner
shilman Sep 17, 2022
c2042c3
fix typo
shilman Sep 17, 2022
aa3a8ea
Revert "Vue2: Fix play's within(canvas) by preserving `#storybook-root`"
shilman Sep 18, 2022
1034ba9
Revert "Added Vue2 DOM breaking change to MIGRATION guide"
shilman Sep 18, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -477,7 +477,7 @@ jobs:
executor:
class: medium+
name: sb_node_14_browsers
parallelism: 7
parallelism: 9
steps:
- git-shallow-clone/checkout_advanced:
clone_options: '--depth 1 --verbose'
Expand All @@ -497,7 +497,7 @@ jobs:
executor:
class: medium+
name: sb_node_14_browsers
parallelism: 7
parallelism: 9
steps:
- git-shallow-clone/checkout_advanced:
clone_options: '--depth 1 --verbose'
Expand All @@ -513,7 +513,7 @@ jobs:
executor:
class: medium+
name: sb_node_14_browsers
parallelism: 7
parallelism: 9
steps:
- git-shallow-clone/checkout_advanced:
clone_options: '--depth 1 --verbose'
Expand All @@ -533,7 +533,7 @@ jobs:
executor:
class: medium+
name: sb_node_14_browsers
parallelism: 7
parallelism: 9
steps:
- git-shallow-clone/checkout_advanced:
clone_options: '--depth 1 --verbose'
Expand All @@ -549,7 +549,7 @@ jobs:
executor:
class: medium+
name: sb_node_14_browsers
parallelism: 7
parallelism: 9
steps:
- git-shallow-clone/checkout_advanced:
clone_options: '--depth 1 --verbose'
Expand All @@ -565,7 +565,7 @@ jobs:
executor:
class: medium+
name: sb_playwright
parallelism: 7
parallelism: 9
steps:
- git-shallow-clone/checkout_advanced:
clone_options: '--depth 1 --verbose'
Expand Down
12 changes: 4 additions & 8 deletions code/frameworks/vue-webpack5/src/preset.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,7 @@ export const core: PresetProperty<'core', StorybookConfig> = async (config, opti
};
};

export const typescript = async (
config: StorybookConfig['typescript']
): Promise<StorybookConfig['typescript']> => {
return {
...config,
skipBabel: true,
};
};
export const typescript: PresetProperty<'typescript', StorybookConfig> = async (config) => ({
...config,
skipBabel: true,
});
5 changes: 5 additions & 0 deletions code/frameworks/vue3-webpack5/src/preset.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,8 @@ export const core: PresetProperty<'core', StorybookConfig> = async (config, opti
},
};
};

export const typescript: PresetProperty<'typescript', StorybookConfig> = async (config) => ({
...config,
skipBabel: true,
});
2 changes: 1 addition & 1 deletion code/lib/cli/src/generators/VUE3/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { Generator } from '../types';

const generator: Generator = async (packageManager, npmOptions, options) => {
await baseGenerator(packageManager, npmOptions, options, 'vue3', {
extraPackages: ['vue-loader@^16.0.0'],
extraPackages: ['vue-loader@^17.0.0', '@vue/compiler-sfc@^3.2.0'],
});
};

Expand Down
25 changes: 25 additions & 0 deletions code/lib/cli/src/repro-templates.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,11 +94,36 @@ const svelteViteTemplates = {
// }
};

const vueCliTemplates = {
'vue-cli/default-js': {
name: 'Vue-CLI (Default JS)',
script: 'npx -p @vue/cli vue create . --default --packageManager=yarn --force --merge',
cadence: ['ci', 'daily', 'weekly'],
expected: {
framework: '@storybook/vue3-webpack5',
renderer: '@storybook/vue3',
builder: '@storybook/builder-webpack5',
},
},
'vue-cli/vue2-default-js': {
name: 'Vue-CLI (Vue2 JS)',
script:
'npx -p @vue/cli vue create . --default --packageManager=yarn --force --merge --preset=Default\\ (Vue\\ 2)',
cadence: ['ci', 'daily', 'weekly'],
expected: {
framework: '@storybook/vue-webpack5',
renderer: '@storybook/vue',
builder: '@storybook/builder-webpack5',
},
},
};

export default {
...craTemplates,
...reactViteTemplates,
...vue3ViteTemplates,
...svelteViteTemplates,
...vueCliTemplates,
// FIXME: missing documentation.json
// 'angular/latest': {
// name: 'Angular (latest)',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ Object {
"include": Array [
"ROOT",
],
"test": "/\\\\.(mjs|tsx?|jsx?)$/",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I know this is just a snapshot update, but was the removal of tsx intentional?

"test": "/\\\\.(mjs|jsx?)$/",
"use": Array [
Object {
"loader": "NODE_MODULES/babel-loader/lib/index.js",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ Object {
"include": Array [
"ROOT",
],
"test": "/\\\\.(mjs|tsx?|jsx?)$/",
"test": "/\\\\.(mjs|jsx?)$/",
"use": Array [
Object {
"loader": "NODE_MODULES/babel-loader/lib/index.js",
Expand Down
19 changes: 12 additions & 7 deletions code/renderers/vue/src/render.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import type { VueFramework } from './types';
export const COMPONENT = 'STORYBOOK_COMPONENT';
export const VALUES = 'STORYBOOK_VALUES';

const map = new Map<Element, Instance>();
const map = new Map<Element, [Instance, Element]>();
type Instance = CombinedVueInstance<
Vue,
{
Expand All @@ -21,11 +21,16 @@ type Instance = CombinedVueInstance<
Record<never, any>,
unknown
>;
const getRoot = (domElement: Element): Instance => {
const getRoot = (domElement: Element): [Instance, Element] => {
if (map.has(domElement)) {
return map.get(domElement);
}

// Create a dummy "target" underneath #storybook-root
// that Vue2 will replace on first render with #storybook-vue-root
const target = document.createElement('div');
domElement.appendChild(target);

const instance = new Vue({
beforeDestroy() {
map.delete(domElement);
Expand All @@ -37,13 +42,13 @@ const getRoot = (domElement: Element): Instance => {
};
},
render(h) {
map.set(domElement, instance);
map.set(domElement, [instance, target]);
const children = this[COMPONENT] ? [h(this[COMPONENT])] : undefined;
return h('div', { attrs: { id: 'storybook-root' } }, children);
return h('div', { attrs: { id: 'storybook-vue-root' } }, children);
},
});

return instance;
return [instance, target];
};

export const render: ArgsStoryFn<VueFramework> = (props, context) => {
Expand Down Expand Up @@ -92,7 +97,7 @@ export function renderToDOM(
}: RenderContext<VueFramework>,
domElement: Element
) {
const root = getRoot(domElement);
const [root, target] = getRoot(domElement);
Vue.config.errorHandler = showException;
const element = storyFn();

Expand All @@ -116,7 +121,7 @@ export function renderToDOM(
root[VALUES] = { ...element.options[VALUES], ...args };

if (!map.has(domElement)) {
root.$mount(domElement);
root.$mount(target);
}

showMain();
Expand Down
54 changes: 54 additions & 0 deletions code/renderers/vue/template/components/Button.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
<template>
<button type="button" :class="classes" @click="onClick" :style="style">{{ children }}</button>
</template>

<script>
import './button.css';

export default {
name: 'my-button',

props: {
children: {
type: String,
required: true,
},
primary: {
type: Boolean,
default: false,
},
size: {
type: String,
default: 'medium',
validator: function (value) {
return ['small', 'medium', 'large'].indexOf(value) !== -1;
},
},
backgroundColor: {
type: String,
},
},

computed: {
classes() {
return {
'storybook-button': true,
'storybook-button--primary': this.primary,
'storybook-button--secondary': !this.primary,
[`storybook-button--${this.size}`]: true,
};
},
style() {
return {
backgroundColor: this.backgroundColor,
};
},
},

methods: {
onClick() {
this.$emit('onClick');
},
},
};
</script>
44 changes: 44 additions & 0 deletions code/renderers/vue/template/components/Form.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
<template>
<form id="interaction-test-form" @submit.prevent="onSubmit">
<label>
Enter Value
<input type="text" data-testid="value" :value="value" required @click="setValue" />
</label>
<button type="submit">Submit</button>
<p v-if="complete">Completed!!</p>
</form>
</template>

<script>
export default {
name: 'my-form',

props: {
onSuccess: {
type: Function,
},
},

data() {
return {
value: '',
complete: false,
};
},

methods: {
setValue(event) {
this.value = event.target.value;
},
onSubmit() {
this.onSuccess(this.value);
setTimeout(() => {
this.complete = true;
}, 500);
setTimeout(() => {
this.complete = false;
}, 1500);
},
},
};
</script>
17 changes: 17 additions & 0 deletions code/renderers/vue/template/components/Html.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<template>
<div v-html="content"></div>
</template>

<script>

export default {
name: 'my-html',

props: {
content: {
type: String,
required: true,
},
},
};
</script>
29 changes: 29 additions & 0 deletions code/renderers/vue/template/components/Pre.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<template>
<pre data-testid="pre" :style="style">{{ finalText }}</pre>
</template>

<script>
export default {
name: 'my-pre',

props: {
// deepscan-disable-next-line
style: {
type: Object,
},
object: {
type: Object,
},
text: {
type: String,
default: '',
},
},

computed: {
finalText() {
return props.object ? JSON.stringify(props.object, null, 2) : props.text;
},
},
};
</script>
30 changes: 30 additions & 0 deletions code/renderers/vue/template/components/button.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
.storybook-button {
font-family: 'Nunito Sans', 'Helvetica Neue', Helvetica, Arial, sans-serif;
font-weight: 700;
border: 0;
border-radius: 3em;
cursor: pointer;
display: inline-block;
line-height: 1;
}
.storybook-button--primary {
color: white;
background-color: #1ea7fd;
}
.storybook-button--secondary {
color: #333;
background-color: transparent;
box-shadow: rgba(0, 0, 0, 0.15) 0px 0px 0px 1px inset;
}
.storybook-button--small {
font-size: 12px;
padding: 10px 16px;
}
.storybook-button--medium {
font-size: 14px;
padding: 11px 20px;
}
.storybook-button--large {
font-size: 16px;
padding: 12px 24px;
}
8 changes: 8 additions & 0 deletions code/renderers/vue/template/components/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import globalThis from 'global';

import Button from './Button.vue';
import Pre from './Pre.vue';
import Form from './Form.vue';
import Html from './Html.vue';

globalThis.Components = { Button, Pre, Form, Html };
Loading