Skip to content

Commit 95f659d

Browse files
committed
Merge branch 'release/2.0.0-beta.6'
2 parents d6ce051 + 8972919 commit 95f659d

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

48 files changed

+33108
-13383
lines changed

package-lock.json

Lines changed: 31952 additions & 12523 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@studiometa/js-toolkit-workspace",
3-
"version": "2.0.0-beta.5",
3+
"version": "2.0.0-beta.6",
44
"private": true,
55
"workspaces": [
66
"packages/*"
@@ -25,25 +25,25 @@
2525
"build:bundle:umd": "NODE_TARGET=bundle microbundle -i packages/js-toolkit/index.js -o dist/index.umd.js -f umd --no-sourcemap --name Base --no-pkg-main --external none"
2626
},
2727
"devDependencies": {
28-
"@babel/cli": "^7.16.0",
29-
"@babel/core": "^7.16.0",
30-
"@babel/plugin-proposal-class-properties": "^7.16.0",
31-
"@babel/plugin-transform-runtime": "^7.16.4",
32-
"@babel/preset-env": "^7.16.4",
28+
"@babel/cli": "^7.16.7",
29+
"@babel/core": "^7.16.5",
30+
"@babel/plugin-proposal-class-properties": "^7.16.7",
31+
"@babel/plugin-transform-runtime": "^7.16.5",
32+
"@babel/preset-env": "^7.16.5",
3333
"@studiometa/browserslist-config": "^1.0.1",
3434
"@studiometa/eslint-config": "^2.1.3",
35-
"@studiometa/prettier-config": "^2.0.1",
35+
"@studiometa/prettier-config": "^2.1.1",
3636
"@studiometa/stylelint-config": "^2.0.0",
3737
"@types/estree": "^0.0.50",
38-
"@types/jest": "^27.0.3",
39-
"@types/node": "^16.11.11",
38+
"@types/jest": "^27.4.0",
39+
"@types/node": "^16.11.13",
4040
"@typescript-eslint/eslint-plugin": "^4.29.3",
4141
"@typescript-eslint/parser": "^4.29.3",
4242
"babel-plugin-add-import-extension": "^1.6.0",
4343
"eslint": "^7.32.0",
4444
"eslint-plugin-jest": "^24.4.0",
4545
"microbundle": "^0.13.3",
46-
"prettier": "^2.5.0",
47-
"typescript": "^4.5.2"
46+
"prettier": "^2.5.1",
47+
"typescript": "^4.5.4"
4848
}
4949
}

packages/demo/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@studiometa/js-toolkit-demo",
3-
"version": "2.0.0-beta.5",
3+
"version": "2.0.0-beta.6",
44
"private": true,
55
"type": "commonjs",
66
"scripts": {
@@ -16,6 +16,7 @@
1616
"eslint": "^7.32.0",
1717
"postcss": "^8.3.6",
1818
"prettier": "^2.3.2",
19+
"stylefire": "^7.0.3",
1920
"stylelint": "^13.13.1",
2021
"tailwindcss": "^2.2.9",
2122
"vue": "^2.6.14"
Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { Base, withScrolledInView } from '@studiometa/js-toolkit';
22
import { map } from '@studiometa/js-toolkit/utils';
3+
import stylefire from 'stylefire';
34

45
export default class Parallax extends withScrolledInView(Base) {
56
static config = {
@@ -10,9 +11,29 @@ export default class Parallax extends withScrolledInView(Base) {
1011
},
1112
};
1213

14+
/**
15+
* @type {import('stylefire').Styler}
16+
*/
17+
styler;
18+
19+
mounted() {
20+
this.styler = stylefire(this.$refs.target);
21+
}
22+
23+
get freezedOptions() {
24+
const options = this.$options;
25+
Object.defineProperty(this, 'freezeOptions', {
26+
value: Object.freeze(options),
27+
configurable: true,
28+
});
29+
30+
return options;
31+
}
32+
1333
scrolledInView({ progress }) {
14-
const y = map(progress.y, 0, 1, 100, -100) * this.$options.speed;
15-
const scale = map(progress.x, 0, 1, 0.5, 2);
16-
this.$refs.target.style.transform = `translateY(${y}px) scale(${scale})`;
34+
this.styler.set({
35+
y: map(progress.y, 0, 1, 100, -100) * this.freezedOptions.speed,
36+
scale: map(progress.x, 0, 1, 0.5, 2),
37+
});
1738
}
1839
}

packages/demo/src/js/components/Skew.js

Lines changed: 39 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,26 @@
1-
import { Base } from '@studiometa/js-toolkit';
2-
import { matrix } from '@studiometa/js-toolkit/utils/css';
3-
import { damp, clamp } from '@studiometa/js-toolkit/utils/math';
4-
import { withMountWhenInView } from '@studiometa/js-toolkit/decorators';
1+
import { Base, withMountWhenInView, useScroll, useRaf } from '@studiometa/js-toolkit';
2+
import { damp, clamp } from '@studiometa/js-toolkit/utils';
3+
import stylefire from 'stylefire';
4+
5+
const scroll = useScroll();
6+
const raf = useRaf();
7+
8+
let skewY = 0;
9+
let dampedSkewY = 0;
10+
11+
scroll.add('Skew.js', (props) => {
12+
skewY = clamp(props.delta.y * -0.005, -0.1, 0.1) * 40;
13+
14+
if (!raf.has('Skew.js')) {
15+
raf.add('Skew.js', () => {
16+
dampedSkewY = damp(skewY, dampedSkewY, 0.1);
17+
18+
if (dampedSkewY === skewY) {
19+
raf.remove('Skew.js');
20+
}
21+
});
22+
}
23+
});
524

625
export default class Skew extends withMountWhenInView(Base) {
726
static config = {
@@ -12,19 +31,29 @@ export default class Skew extends withMountWhenInView(Base) {
1231

1332
dampedSkewY = 0;
1433

15-
scrolled({ delta, changed }) {
34+
/**
35+
* @type {import('stylefire').Styler}
36+
*/
37+
styler;
38+
39+
mounted() {
40+
this.styler = stylefire(this.$el);
41+
}
42+
43+
scrolled({ changed }) {
1644
if (changed.y && !this.$services.has('ticked')) {
1745
this.$services.enable('ticked');
1846
}
19-
20-
this.skewY = clamp(delta.y * -0.005, -0.1, 0.1);
2147
}
2248

2349
ticked() {
24-
this.dampedSkewY = damp(this.skewY, this.dampedSkewY, 0.1);
25-
this.$el.style.transform = matrix({ skewY: this.dampedSkewY });
50+
if (!this.styler) {
51+
return;
52+
}
53+
54+
this.styler.set('skewY', dampedSkewY);
2655

27-
if (Math.abs(this.dampedSkewY - this.skewY) < 0.01) {
56+
if (dampedSkewY === skewY) {
2857
this.$services.disable('ticked');
2958
}
3059
}

packages/docs/.vitepress/config.js

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,12 @@
1-
module.exports = {
1+
const { defineConfig } = require('vitepress');
2+
const pkg = require('../package.json');
3+
4+
module.exports = defineConfig({
25
lang: 'en-US',
3-
title: '🔧 JS Toolkit',
6+
title: `🔧 JS Toolkit`,
47
description: 'A set of useful little bits of JavaScript to boost your project! 🚀',
58
themeConfig: {
9+
version: pkg.version,
610
repo: 'studiometa/js-toolkit',
711
docsDir: 'packages/docs',
812
lastUpdated: 'Last updated',
@@ -29,7 +33,7 @@ module.exports = {
2933
'/utils/': getUtilsSidebar(),
3034
},
3135
},
32-
};
36+
});
3337

3438
function getGuideSidebar() {
3539
return [
@@ -58,7 +62,12 @@ function getGuideSidebar() {
5862
},
5963
{
6064
text: 'Recipes',
61-
children: [{ text: 'todo' }],
65+
children: [
66+
{
67+
text: 'Teleport refs',
68+
link: '/guide/recipes/teleport-refs.html',
69+
},
70+
],
6271
},
6372
{
6473
text: 'Migration guide',

packages/docs/.vitepress/theme/components/Badge.vue

Lines changed: 15 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,5 @@
1-
<script>
2-
import { h } from 'vue';
3-
4-
const Badge = (props, { slots }) => {
5-
return h('span', {
6-
class: ['badge', props.type],
7-
style: {
8-
verticalAlign: props.vertical
9-
}
10-
}, props.text || slots().default)
11-
}
12-
13-
Badge.props = {
1+
<script setup>
2+
const { type, text, vertical } = defineProps({
143
type: {
154
type: String,
165
default: 'tip'
@@ -20,23 +9,32 @@
209
type: String,
2110
default: 'top'
2211
}
23-
};
24-
25-
export default Badge;
12+
});
2613
</script>
2714

15+
<template>
16+
<span :class="type" class="badge" :style="{ verticalAlign: vertical }">
17+
<slot>{{ text }}</slot>
18+
</span>
19+
</template>
20+
2821
<style scoped>
2922
.badge {
3023
display: inline-block;
3124
font-size: 14px;
25+
font-weight: bold;
3226
height: 18px;
3327
line-height: 18px;
3428
border-radius: 3px;
3529
padding: 0 6px;
3630
color: #fff;
3731
background-color: #42b983;
3832
}
39-
.badge.tip,
33+
34+
.badge.tip {
35+
background-color: #3f9ee3;
36+
}
37+
4038
.badge.green {
4139
background-color: #42b983;
4240
}
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
<script setup lang="ts">
2+
import { withBase, useData } from 'vitepress';
3+
import Badge from './Badge.vue';
4+
const { site, theme, localePath } = useData();
5+
</script>
6+
7+
<template>
8+
<div class="flex">
9+
<a class="nav-bar-title" :href="localePath" :aria-label="`${site.title}, back to home`">
10+
<img v-if="theme.logo" class="logo" :src="withBase(theme.logo)" alt="Logo" />
11+
{{ site.title }}
12+
</a>
13+
<Badge class="nav-bar-badge">v{{ theme.version }}</Badge>
14+
</div>
15+
</template>
16+
17+
<style scoped>
18+
.flex {
19+
display: flex;
20+
align-items: center;
21+
}
22+
23+
.nav-bar-title {
24+
font-size: 1.3rem;
25+
font-weight: 600;
26+
color: var(--c-text);
27+
display: inline-flex;
28+
justify-content: center;
29+
align-items: center;
30+
}
31+
32+
.nav-bar-title:hover {
33+
text-decoration: none;
34+
}
35+
36+
.logo {
37+
margin-right: 0.75rem;
38+
height: 1.3rem;
39+
vertical-align: bottom;
40+
}
41+
42+
.nav-bar-badge {
43+
margin-left: 10px;
44+
}
45+
</style>

packages/docs/api/configuration.md

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,34 @@ class Component extends Base {
131131
}
132132
```
133133

134+
## `config.emits`
135+
136+
- Type: `string[]`
137+
- Default: `undefined`
138+
139+
Define the events emitted by the component by specifying their name.
140+
141+
```js
142+
class Component extends Base {
143+
static config = {
144+
name: 'Component',
145+
emits: ['open', 'close'],
146+
};
147+
148+
open() {
149+
this.$emit('open');
150+
}
151+
152+
close() {
153+
this.$emit('close');
154+
}
155+
156+
toggle() {
157+
this.$emit('toggle'); // will not be emitted and will trigger a warning
158+
}
159+
}
160+
```
161+
134162
## `config.log`
135163

136164
- Type: `Boolean`

0 commit comments

Comments
 (0)