Skip to content

Commit

Permalink
Merge branch 'release/1.0.0-alpha.6'
Browse files Browse the repository at this point in the history
  • Loading branch information
titouanmathis committed Aug 27, 2024
2 parents f766d04 + 848c9bd commit 3c4491d
Show file tree
Hide file tree
Showing 14 changed files with 71 additions and 41 deletions.
11 changes: 11 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,17 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),

## [Unreleased]

## [v1.0.0-alpha.6](https://github.com/studiometa/ui/compare/1.0.0-alpha.5..1.0.0-alpha.6) (2024-08-27)

### Added

- Add support for targeting self by default ([#290](https://github.com/studiometa/ui/issues/290), [#291](https://github.com/studiometa/ui/pull/291), [2951299](https://github.com/studiometa/ui/commit/2951299))
- Add support for self reference in the effect ([#290](https://github.com/studiometa/ui/issues/290), [#291](https://github.com/studiometa/ui/pull/291), [0eac076](https://github.com/studiometa/ui/commit/0eac076))

### Changed

- Update [@studiometa/js-toolkit](https://github.com/studiometa/js-toolkit) to 3.0.0-alpha.9 ([6c1a8c7](https://github.com/studiometa/ui/commit/6c1a8c7))

## [v1.0.0-alpha.5](https://github.com/studiometa/ui/compare/1.0.0-alpha.4..1.0.0-alpha.5) (2024-08-06)

### Fixed
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "studiometa/ui",
"version": "1.0.0-alpha.5",
"version": "1.0.0-alpha.6",
"description": "A set of opiniated, unstyled and accessible components.",
"license": "MIT",
"require": {
Expand Down
24 changes: 12 additions & 12 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@studiometa/ui-workspace",
"version": "1.0.0-alpha.5",
"version": "1.0.0-alpha.6",
"private": true,
"workspaces": [
"packages/*"
Expand Down
4 changes: 2 additions & 2 deletions packages/docs/.vitepress/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,11 +76,11 @@ export default defineConfig({
},
{
text: 'Playground',
link: '/play/',
link: process.env.NODE_ENV === 'development' ? '/play/index.html' : '/play/',
target: '_blank',
},
{
text: `v${pkg.version}`,
text: `<span class="VPBadge font-bold bg-[var(--vp-button-brand-bg)] text-[var(--vp-button-brand-text)]">v${pkg.version}</span>`,
items: [{ text: 'Release Notes', link: 'https://github.com/studiometa/ui/releases' }],
},
],
Expand Down
10 changes: 2 additions & 8 deletions packages/docs/components/atoms/Action/index.md
Original file line number Diff line number Diff line change
@@ -1,14 +1,8 @@
---
outline: deep
badges: [JS]
---

# Action <Badges :texts="badges" />

<script setup>
import pkg from '@studiometa/ui/atoms/Action/package.json';

const badges = [`v${pkg.version}`, 'JS'];
</script>
# Action <Badges :texts="$frontmatter.badges" />

The `Action` atom is a component who trigger an action on other components.

Expand Down
15 changes: 14 additions & 1 deletion packages/docs/components/atoms/Action/js-api.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ Modifiers can be chained with a `.` as separator:
### `target`

- Type: `string`
- Required
- Available formats:
- `Name`
- `Name OtherName`
Expand All @@ -54,6 +53,19 @@ class Foo extends Base {
```
:::

#### No target

By not defining the `target` option, the default target will be the current `Action` instance. The following will toggle the `clicked` class on the `<button>` element:

```html
<button
data-component="Action"
data-option-effect="target.classList.toggle('clicked')"
class="clicked">
Click me
</button>
```

#### Single target

The following configuration will use all `Foo` components as targets, the effect callback will be triggered for each and every one of them.
Expand Down Expand Up @@ -111,6 +123,7 @@ The `effect` option must be used to define a small piece of JavaScript that will
- `ctx` (`Record<name, Base>`): the current targeted component in an object with a uniq key being its name set in the static `config.name` property and the value being the component instance
- `event` (`Event`): the event that triggered the action
- `target` (`Base`): a direct reference to the current targeted component
- `action` (`Base`): a direct reference to the current action component

#### Simple effect vs callback effect

Expand Down
6 changes: 3 additions & 3 deletions packages/docs/package.json
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
{
"name": "@studiometa/ui-docs",
"version": "1.0.0-alpha.5",
"version": "1.0.0-alpha.6",
"private": true,
"type": "module",
"scripts": {
"dev": "concurrently 'npm run dev:playground' 'npm run dev:vitepress' --names 'playground,vitepress'",
"dev": "concurrently 'npm run dev:playground' 'npm run dev:vitepress' --names 'play,docs'",
"dev:playground": "npm run watch --workspace=@studiometa/ui-playground",
"dev:vitepress": "vitepress dev .",
"prebuild": "npm run build --workspace=@studiometa/ui-playground",
"build": "vitepress build ."
},
"dependencies": {
"@studiometa/js-toolkit": "^3.0.0-alpha.6"
"@studiometa/js-toolkit": "^3.0.0-alpha.9"
},
"devDependencies": {
"@iconify-json/octicon": "1.1.56",
Expand Down
1 change: 0 additions & 1 deletion packages/docs/tailwind.config.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ const folders = fs
.map((item) => path.resolve(ui, item.name));

module.exports = {
important: '.story',
presets: [defaultConfig, tailwindConfig],
content: [
...folders.map((folder) => path.relative(__dirname, path.resolve(folder, '**/*.js'))),
Expand Down
2 changes: 1 addition & 1 deletion packages/playground/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@studiometa/ui-playground",
"version": "1.0.0-alpha.5",
"version": "1.0.0-alpha.6",
"private": true,
"type": "module",
"scripts": {
Expand Down
14 changes: 11 additions & 3 deletions packages/tests/atoms/Action.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,14 @@ describe('The Action component', () => {
await reset();
});

it('should resolve targets to self if option is not set', async () => {
const { action, reset } = await getContext({
target: '',
});
expect(action.targets).toEqual([{ Action: action }]);
await reset();
})

it('should resolve single target', async () => {
const { action, foo, reset } = await getContext({
target: 'Foo',
Expand Down Expand Up @@ -136,14 +144,14 @@ describe('The Action component', () => {
await reset();
});

it('should trigger the effect with ctx, target and event parameters', async () => {
it('should trigger the effect with ctx, target, event and action parameters', async () => {
const { action, foo, fooFn, reset } = await getContext({
target: 'Foo',
effect: 'target.fn(ctx, event, target)',
effect: 'target.fn(ctx, event, target, action)',
});
const event = new Event('click');
action.$el.dispatchEvent(event);
expect(fooFn).toHaveBeenCalledWith(action.targets[0], event, foo);
expect(fooFn).toHaveBeenCalledWith(action.targets[0], event, foo, action);
await reset();
});

Expand Down
2 changes: 1 addition & 1 deletion packages/tests/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@studiometa/ui-tests",
"version": "1.0.0-alpha.5",
"version": "1.0.0-alpha.6",
"private": true,
"type": "module",
"scripts": {
Expand Down
15 changes: 10 additions & 5 deletions packages/ui/atoms/Action/Action.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,13 +48,18 @@ export class Action<T extends BaseProps = BaseProps> extends Base<ActionProps &
get effect() {
const { effect } = this.$options;
if (!effectCache.has(effect)) {
effectCache.set(effect, new Function('ctx', 'event', 'target', `return ${effect}`));
effectCache.set(effect, new Function('ctx', 'event', 'target', 'action', `return ${effect}`));
}
return effectCache.get(effect);
}

get targets() {
get targets(): Array<Record<string, Base>> {
const { target } = this.$options;

if (!target) {
return [{ [this.__config.name]: this }];
}

const parts = target.split(' ').map((part) => {
const [, name, , selector] = part.match(TARGET_REGEX) ?? [];
return [name, selector];
Expand Down Expand Up @@ -93,10 +98,10 @@ export class Action<T extends BaseProps = BaseProps> extends Base<ActionProps &

for (const target of targets) {
try {
const [name, currentTarget] = Object.entries(target).flat();
const value = effect(target, event, currentTarget);
const [currentTarget] = Object.values(target).flat();
const value = effect(target, event, currentTarget, this);
if (typeof value === 'function') {
value(target, event, currentTarget);
value(target, event, currentTarget, this);
}
} catch (err) {
this.$warn(err);
Expand Down
4 changes: 2 additions & 2 deletions packages/ui/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@studiometa/ui",
"version": "1.0.0-alpha.5",
"version": "1.0.0-alpha.6",
"description": "A set of opiniated, unstyled and accessible components",
"publishConfig": {
"access": "public"
Expand Down Expand Up @@ -29,7 +29,7 @@
},
"homepage": "https://github.com/studiometa/ui#readme",
"dependencies": {
"@studiometa/js-toolkit": "^3.0.0-alpha.6",
"@studiometa/js-toolkit": "^3.0.0-alpha.9",
"deepmerge": "^4.3.1"
}
}

0 comments on commit 3c4491d

Please sign in to comment.