Skip to content

Commit 65b39d3

Browse files
committed
Merge branch 'release/2.4.0'
2 parents aabd60d + 38ee3d7 commit 65b39d3

File tree

20 files changed

+254
-23
lines changed

20 files changed

+254
-23
lines changed

.github/workflows/tests.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,5 +68,5 @@ jobs:
6868
- uses: antfu/export-size-action@v1
6969
with:
7070
github_token: ${{ secrets.GITHUB_TOKEN }}
71-
build_script: npm run build-for-export-size
72-
paths: ./dist
71+
build_script: node ./scripts/add-utils-export.js
72+
paths: packages/js-toolkit

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
[![Dependency Status](https://img.shields.io/librariesio/release/npm/@studiometa/js-toolkit?style=flat-square)](https://david-dm.org/studiometa/js-toolkit)
66
![Codecov](https://img.shields.io/codecov/c/github/studiometa/js-toolkit?style=flat-square)
77

8-
> A set of useful little bits of JavaScript to boost your project! 🚀
8+
> A JavaScript data-attributes driven micro-framework shipped with plenty of useful utility functions to boost your project.
99
1010
## Installation
1111

@@ -15,9 +15,9 @@ Install the latest version via NPM:
1515
npm install @studiometa/js-toolkit
1616
```
1717

18-
## Documentation
18+
## What is it?
1919

20-
This project contains a JavaScript micro-framework and its utility functions whose main objectives are:
20+
This project is a JavaScript micro-framework (along with its utility functions) whose main objectives are:
2121

2222
- Enforcing best-practice and consistency between projects
2323
- Using elements from the DOM easily

package-lock.json

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

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@studiometa/js-toolkit-workspace",
3-
"version": "2.3.0",
3+
"version": "2.4.0",
44
"private": true,
55
"workspaces": [
66
"packages/*"

packages/demo/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@studiometa/js-toolkit-demo",
3-
"version": "2.3.0",
3+
"version": "2.4.0",
44
"private": true,
55
"type": "commonjs",
66
"scripts": {

packages/docs/.vitepress/config.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ const pkg = JSON.parse(
77

88
export default defineConfig({
99
lang: 'en-US',
10-
title: 'JS Toolkit',
11-
description: 'A set of useful little bits of JavaScript to boost your project! 🚀',
10+
title: 'A JavaScript data-attributes driven micro-framework',
11+
description: 'The JS Toolkit by Studio Meta is a JavaScript data-attributes driven micro-framework shipped with plenty of useful utility functions to boost your project.',
1212
lastUpdated: true,
1313
head: [['link', { rel: 'icon', type: 'image/x-icon', href: '/logo.png' }]],
1414
themeConfig: {
@@ -198,10 +198,12 @@ function getDecoratorsSidebar() {
198198
function getHelpersSidebar() {
199199
return [
200200
{ text: 'createApp', link: '/api/helpers/createApp.html' },
201+
{ text: 'getDirectChildren', link: '/api/helpers/getDirectChildren.html' },
201202
{ text: 'getInstanceFromElement', link: '/api/helpers/getInstanceFromElement.html' },
202203
{ text: 'importOnInteraction', link: '/api/helpers/importOnInteraction.html' },
203204
{ text: 'importWhenIdle', link: '/api/helpers/importWhenIdle.html' },
204205
{ text: 'importWhenVisible', link: '/api/helpers/importWhenVisible.html' },
206+
{ text: 'isDirectChild', link: '/api/helpers/isDirectChild.html' },
205207
];
206208
}
207209

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
# getDirectChildren
2+
3+
Use the `getDirectChildren` function to get a list components which are direct descendants of the given parent instance. This function is helpful when working with nested components which declare themselves as children.
4+
5+
:::tip
6+
If you need to only check if an instance is a direct descendant of another instance, prefer the [`isDirectChild` helper function](/api/helpers/isDirectChild.md) which will return a `boolean` directly.
7+
:::
8+
9+
## Usage
10+
11+
```js {1,9,16}
12+
import { Base, getDirectChildren } from '@studiometa/js-toolkit';
13+
import Child from './Child.js';
14+
15+
class Parent extends Base {
16+
static config = {
17+
name: 'Parent',
18+
components: {
19+
Child,
20+
Parent, // Useful for recursive components only
21+
},
22+
};
23+
24+
onChildClick(index, event) {
25+
const childInstance = this.$children.Child[index];
26+
const directChildren = getDirectChildren(this, 'Parent', 'Child');
27+
28+
if (directChildren.includes(childInstance)) {
29+
event.preventDefault();
30+
}
31+
}
32+
}
33+
```
34+
35+
**Parameters**
36+
37+
- `parentInstance` (`Base`): the target element
38+
- `parentName` (`string`): the name of the recursive parent as specified in the `config.components` object.
39+
- `childrenName` (`string`): the name of the children components as specified in the `config.components` object.
40+
41+
**Return value**
42+
43+
- `Base[]`: a list of the direct child components corresponding to the given `childrenName`

packages/docs/api/helpers/getInstanceFromElement.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ const componentInstance = getInstanceFromElement(document.body, Component);
1414
**Parameters**
1515

1616
- `element` (`HTMLElement`): the target element
17-
- `BaseConstructor`: (`BaseConstructor`): the class (constructor) of the component to look for
17+
- `BaseConstructor` (`BaseConstructor`): the class (constructor) of the component to look for
1818

1919
**Return value**
2020

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
# isDirectChild
2+
3+
Use the `isDirectChild` function to test if a child component instance is a direct descendant of the given parent instance. This function is helpful when working with nested components which declare themselves as children.
4+
5+
## Usage
6+
7+
```js {1,9,16}
8+
import { Base, isDirectChild } from '@studiometa/js-toolkit';
9+
import Child from './Child.js';
10+
11+
class Parent extends Base {
12+
static config = {
13+
name: 'Parent',
14+
components: {
15+
Child,
16+
Parent, // Useful for recursive components only
17+
},
18+
};
19+
20+
onChildClick(index, event) {
21+
const childInstance = this.$children.Child[index];
22+
23+
if (isDirectChild(this, 'Parent', 'Child', childInstance)) {
24+
event.preventDefault();
25+
}
26+
}
27+
}
28+
```
29+
30+
**Parameters**
31+
32+
- `parentInstance` (`Base`): the parent instance.
33+
- `parentName` (`string`): the name of the recursive parent as specified in the `config.components` object.
34+
- `childName` (`string`): the name of the child component as specified in the `config.components` object.
35+
- `childInstance` (`Base`): the child instance.
36+
37+
**Return value**
38+
39+
- `boolean`: `true` if the given child instance is a direct descendant of the given parent instance.

packages/docs/index.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
---
22
layout: home
33
sidebar: false
4+
title: A data-attributes driven micro-framework
5+
description: The JS Toolkit by Studio Meta is a JavaScript data-attributes driven micro-framework shipped with plenty of useful utility functions to boost your project.
46
hero:
57
name: JS Toolkit
68
text: A data-attributes driven micro framework

0 commit comments

Comments
 (0)