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

Release: v1.0.2 #19

Merged
merged 42 commits into from
Feb 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
42 commits
Select commit Hold shift + click to select a range
49935d9
chore: update comment
jorenrui Feb 26, 2024
3b9864b
feat: add custom events
jorenrui Feb 26, 2024
9de0652
refactor: update initial value of update and reload
jorenrui Feb 26, 2024
374701e
refactor: encapsulate minijs properties/methods
jorenrui Feb 26, 2024
f45eb52
refactor: rename parent to group
jorenrui Feb 27, 2024
baa101f
feat: evaluate :group attr on load
jorenrui Feb 27, 2024
5b6bb76
refactor: make isNativeVariable a helper
jorenrui Feb 27, 2024
af54dbb
refactor: relocate ignored ids to lexer
jorenrui Feb 27, 2024
a693e66
refactor: rename this.base to this.entity
jorenrui Feb 27, 2024
b85ca1d
fix: entity undefined in events
jorenrui Feb 27, 2024
115c6e7
chore: setup path alias
jorenrui Feb 27, 2024
3dad3e1
refactor: use alias imports
jorenrui Feb 27, 2024
d83ba95
refactor: extract variables logic from entity
jorenrui Feb 27, 2024
b91a66d
refactor: relocate state of variables
jorenrui Feb 27, 2024
3f25d2a
fix: group variables not working
jorenrui Feb 27, 2024
df4c0a2
refactor: expose main on debug true
jorenrui Feb 27, 2024
db507b2
feat: track variables per entity attribute
jorenrui Feb 27, 2024
0a1cfbd
fix: check if region is selected
jorenrui Feb 27, 2024
39866e6
refactor: update usage of attribute variables and attach helpers
jorenrui Feb 27, 2024
200e85f
optimization: only re-evaluate relevant attributes on state update
jorenrui Feb 27, 2024
d1ca1a0
feat: dispose attributes and events on observer remove attribute
jorenrui Feb 27, 2024
3c6054e
docs: relocate installation steps
jorenrui Feb 27, 2024
f42c86c
refactor: update text in changing id demo
jorenrui Feb 27, 2024
757e3f7
feat: initialize variables on attribute change
jorenrui Feb 27, 2024
23f7e52
optimize: grouped usage of new Set
jorenrui Feb 27, 2024
f033eca
fix: missing group variables
jorenrui Feb 27, 2024
f467db0
refactor: update accordion
jorenrui Feb 27, 2024
ed27712
refactor: rename groupID to entityID in disposeEntityVariable
jorenrui Feb 27, 2024
101a6de
Merge branch 'jr.refactor/group-variables' into jr.refactor/entity-va…
jorenrui Feb 27, 2024
1f820e5
refactor: update variable checker and waiting for promises
jorenrui Feb 27, 2024
7e018d6
fix: update isNativeVariable checker
jorenrui Feb 27, 2024
a6adeed
Merge pull request #20 from Group-One-Technology/jr.refactor/group-va…
jorenrui Feb 27, 2024
bcb1765
fix: missing async await for state.evaluate promise
jorenrui Feb 27, 2024
3db67f4
Merge pull request #21 from Group-One-Technology/jr.refactor/entity-v…
jorenrui Feb 27, 2024
2efa956
build: automated tests ci
jorenrui Feb 27, 2024
723d5c4
docs: add description
jorenrui Feb 27, 2024
8581287
build: remove pull_request on the trigger
jorenrui Feb 27, 2024
76d24c3
build: fix extra = operator
jorenrui Feb 27, 2024
5a0dc37
build: update github.ref to a string
jorenrui Feb 27, 2024
98dd0c8
build: fix duplicate actions running
jorenrui Feb 27, 2024
152ead4
fix: remove promises on attributes evaluate
jorenrui Feb 27, 2024
c651a29
fix: revert removal of grid class in accordion
jorenrui Feb 27, 2024
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
21 changes: 21 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,26 @@ name: NPM Publish
on: [push]

jobs:
automated_tests:
runs-on: ubuntu-latest
if: "!contains(github.event.head_commit.message, 'ci skip') && !contains(github.event.head_commit.message, 'skip ci') && github.ref != 'main'"
steps:
- uses: actions/checkout@v2
- name: Use Node.js 20.x
uses: actions/setup-node@v1
with:
node-version: 20.x
- name: Cache node modules
uses: actions/cache@v1
with:
path: node_modules
key: yarn-deps-${{ hashFiles('yarn.lock') }}
restore-keys: |
yarn-deps-${{ hashFiles('yarn.lock') }}
- name: Run tests
run: |
yarn install --frozen-lockfile
yarn test
release:
runs-on: ubuntu-latest
if: "!contains(github.event.head_commit.message, 'ci skip') && !contains(github.event.head_commit.message, 'skip ci')"
Expand All @@ -17,6 +37,7 @@ jobs:
- name: Prepare repository
run: |
git fetch --unshallow --tags

- name: Cache node modules
uses: actions/cache@v1
with:
Expand Down
56 changes: 31 additions & 25 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,15 +1,6 @@
# MiniJS

## Installation

To setup MiniJS in your local machine, you can do the following:

1. Clone the [repository](https://github.com/Group-One-Technology/minijs).
2. Run `yarn` to install dependencies.
3. Run `yarn build` to create the `dist` folder -> output for MiniJS.
4. Run `yarn dev` to run the demo page locally.
5. Run `yarn build-watch` on another terminal to build the code whenever the Mini.js code changes.
6. Run `yarn test` to run the tests.
Mini is a ~~library~~ extension for HTML which lets you add interactivity to your app without needing a full blown frontend framework.

## The Idea

Expand All @@ -22,6 +13,17 @@ To setup MiniJS in your local machine, you can do the following:

Read the [documentation](https://jorenrui.notion.site/Mini-js-7a51523e0a5845c782097782f49a5bae?pvs=74)

## Installation

To setup MiniJS in your local machine, you can do the following:

1. Clone the [repository](https://github.com/Group-One-Technology/minijs).
2. Run `yarn` to install dependencies.
3. Run `yarn build` to create the `dist` folder -> output for MiniJS.
4. Run `yarn dev` to run the demo page locally.
5. Run `yarn build-watch` on another terminal to build the code whenever the Mini.js code changes.
6. Run `yarn test` to run the tests.

## Setting State

`State` are variables that changes the UI or the DOM that uses it when they get updated.
Expand Down Expand Up @@ -340,30 +342,26 @@ If you want to use the variable across an element's attributes and events, you c

Like the example above, `:load` can be used to set the initial value of the variable.

### Parent Element Variables
### Group Variables

Adding a `:parent` attribute to an element will allow you to access its variables from its children using `parent.` variables.

A children's `parent.` variable is the same as the parent's `el.` variable.
Adding a `:group` attribute to an element will allow you to access its variables from its children using `group.` variables.

```html
<div id="accordion" class="accordion" :parent>
<!-- Parent Element -->

<!-- Group Element -->
<div id="accordion" class="accordion" :group>
<!-- Children Elements -->
<!-- parent.variable == #accordion's el.variable -->
<section
class="grid transition-all border-gray-300 border border-b-0 rounded hover:bg-gray-100"
>
<button
:click="parent.activeSection = 'about'"
:click="group.activeSection = 'about'"
class="cursor-pointer font-bold p-4"
>
About Us
</button>
<div
class="p-4 pt-2 overflow-hidden hidden"
:class="parent.activeSection =='about' ? 'block' : 'hidden'"
:class="group.activeSection =='about' ? 'block' : 'hidden'"
>
Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy
eirmod.
Expand All @@ -374,14 +372,14 @@ A children's `parent.` variable is the same as the parent's `el.` variable.
class="grid transition-all border-gray-300 border border-b-0 rounded hover:bg-gray-100"
>
<button
:click="parent.activeSection = 'contact'"
:click="group.activeSection = 'contact'"
class="cursor-pointer font-bold p-4"
>
Contact Us
</button>
<div
class="p-4 pt-2 overflow-hidden"
:class="parent.activeSection =='contact' ? 'block' : 'hidden'"
:class="group.activeSection =='contact' ? 'block' : 'hidden'"
>
Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy
eirmod.
Expand All @@ -390,17 +388,17 @@ A children's `parent.` variable is the same as the parent's `el.` variable.

<section
class="grid transition-all border-gray-300 border rounded hover:bg-gray-100"
:class="parent.activeSection =='team' ? 'active' : ''"
:class="group.activeSection =='team' ? 'active' : ''"
>
<button
:click="parent.activeSection = 'team'"
:click="group.activeSection = 'team'"
class="cursor-pointer font-bold p-4"
>
Team 3
</button>
<div
class="p-4 pt-2 overflow-hidden"
:class="parent.activeSection =='team' ? 'block' : 'hidden'"
:class="group.activeSection =='team' ? 'block' : 'hidden'"
>
Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy
eirmod.
Expand All @@ -409,6 +407,14 @@ A children's `parent.` variable is the same as the parent's `el.` variable.
</div>
```

You can set the default value of the group variables in the `:group` directive:

```html
<div id="accordion" class="accordion" :group="activeSection = 'about'">
<!-- ... -->
</div>
```

### Variable Methods

MiniJS added some commonly-used custom methods to variables.
Expand Down
24 changes: 24 additions & 0 deletions demo/custom-event.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Mini Custom Events</title>
<script src="/dist/minijs.umd.js"></script>
<script src="https://cdn.tailwindcss.com"></script>
</head>
<body class="p-40">
<script>
MiniJS.extendEvents({ ':htmx:afteronload': 'htmx:afterOnLoad' })
</script>

<button
:htmx:afteronload="console.log('custom event!', event)"
:click="const event = document.createEvent('CustomEvent');
event.initCustomEvent('htmx:afterOnLoad', true, true, { name: 'htmx:afterOnLoad' });
this.dispatchEvent(event)"
>
Click Me
</button>
</body>
</html>
2 changes: 1 addition & 1 deletion demo/observer.html
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
<li>
<button
:click="this.parentNode.parentNode.removeChild(this.parentNode)"
:text="`my id is ${this.getAttribute('id')} (hover me to change) list item (click to delete)`"
:text="`look at my id list item (click to delete)`"
:mouseenter="el.isHovered = true"
:mouseleave="el.isHovered = false"
:class="el.isHovered ? 'bg-red-200' : ''"
Expand Down
34 changes: 19 additions & 15 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -263,13 +263,14 @@ <h3 class="font-bold font-mono">AirBnB Search Bar:</h3>
:change="destination = this.value;
filteredDestinations = destinations.search(destination)

if (filteredDestinations.length)
selectedDestination = filteredDestinations.first
else {
const region = regions.find((region) => region.name === destination)
if (region) selectedDestination = region.name
else selectedDestination = null
}"
const region = regions.find((region) => region.name === destination)

if (region)
selectedDestination = region.name
else if (filteredDestinations.length)
selectedDestination = filteredDestinations.first
else
selectedDestination = null"
:keyup.up="selectedDestination = filteredDestinations.previousItem(selectedDestination)"
:keyup.down="selectedDestination = filteredDestinations.nextItem(selectedDestination)"
placeholder="Search destinations"
Expand Down Expand Up @@ -1268,7 +1269,7 @@ <h3 class="font-bold font-mono">Storing to Local Storage:</h3>
/>
<h2
class="ml-3 mt-2 text-lg font-medium font-mono"
:text="$storedValue"
:text="$storedValue || 'Update and Reload'"
>
Loading...
</h2>
Expand Down Expand Up @@ -1471,14 +1472,15 @@ <h3 class="font-bold font-mono">Multi Select:</h3>
grid-template-rows: 0fr 1fr;
}
</style>
<div class="accordion" :parent>
<div class="accordion" :group="activeSection = 'about'">
<section
class="grid transition-all border-gray-300 border border-b-0 rounded hover:bg-gray-100"
:class="parent.activeSection == 'about' ? 'active' : ''"
:class="group.activeSection == 'about' ? 'active' : ''"
>
<a
:click="parent.activeSection='about'"
:click="group.activeSection = 'about'"
class="cursor-pointer font-bold p-4"
:aria-expanded="group.activeSection == 'about'"
>
About Us
</a>
Expand All @@ -1492,11 +1494,12 @@ <h3 class="font-bold font-mono">Multi Select:</h3>

<section
class="grid transition-all border-gray-300 border border-b-0 rounded hover:bg-gray-100"
:class="parent.activeSection =='contact' ? 'active' : ''"
:class="group.activeSection =='contact' ? 'active' : ''"
>
<a
:click="parent.activeSection='contact'"
:click="group.activeSection = 'contact'"
class="cursor-pointer font-bold p-4"
:aria-expanded="group.activeSection == 'contact'"
>
Contact Us
</a>
Expand All @@ -1510,10 +1513,11 @@ <h3 class="font-bold font-mono">Multi Select:</h3>

<section
class="grid transition-all border-gray-300 border rounded hover:bg-gray-100"
:class="parent.activeSection =='team' ? 'active' : ''"
:class="group.activeSection == 'team' ? 'active' : ''"
>
<a
:click="parent.activeSection='team'"
:click="group.activeSection = 'team'"
:aria-expanded="group.activeSection == 'team'"
class="cursor-pointer font-bold p-4"
>
Team 3
Expand Down
Loading
Loading