├── .all-contributorsrc
├── .github
└── workflows
│ └── main.yml
├── .gitignore
├── .npmignore
├── CHANGELOG.md
├── README.md
├── demo
├── custom-event.html
└── observer.html
├── index.html
├── lib
├── __tests__
│ └── lexer
│ │ ├── lexer.arrays.test.js
│ │ ├── lexer.assignments.test.js
│ │ ├── lexer.block-statements.test.js
│ │ ├── lexer.declarations.test.js
│ │ ├── lexer.document-selector.test.js
│ │ ├── lexer.error.test.js
│ │ ├── lexer.expressions.test.js
│ │ ├── lexer.functions.test.js
│ │ ├── lexer.template-literals.test.js
│ │ └── lexer.variable-shadowing.test.js
├── entity.js
├── entity
│ ├── attributes.js
│ ├── data.js
│ └── events.js
├── extensions
│ └── events-extensions.js
├── generators
│ ├── interpreter.js
│ ├── lexer.js
│ └── observer.js
├── helpers.js
├── helpers
│ ├── array.js
│ ├── strings.js
│ ├── time.js
│ └── variables.js
├── main.js
└── state.js
├── package.json
└── vite.config.js
/.all-contributorsrc:
--------------------------------------------------------------------------------
1 | {
2 | "projectName": "minijs",
3 | "projectOwner": "Group-One-Technology",
4 | "repoType": "github",
5 | "repoHost": "https://github.com",
6 | "files": [
7 | "README.md"
8 | ],
9 | "imageSize": 100,
10 | "commit": true,
11 | "commitConvention": "angular",
12 | "contributors": [
13 | {
14 | "login": "jensnowww",
15 | "name": "Jen",
16 | "avatar_url": "https://avatars.githubusercontent.com/u/26903002?v=4",
17 | "profile": "https://github.com/jensnowww",
18 | "contributions": [
19 | "code",
20 | "infra",
21 | "doc"
22 | ]
23 | },
24 | {
25 | "login": "tonyennis145",
26 | "name": "tonyennis145",
27 | "avatar_url": "https://avatars.githubusercontent.com/u/3110339?v=4",
28 | "profile": "https://github.com/tonyennis145",
29 | "contributions": [
30 | "doc",
31 | "code"
32 | ]
33 | },
34 | {
35 | "login": "jorenrui",
36 | "name": "Joeylene",
37 | "avatar_url": "https://avatars.githubusercontent.com/u/23741509?v=4",
38 | "profile": "https://joeylene.com/",
39 | "contributions": [
40 | "infra",
41 | "code",
42 | "doc",
43 | "test"
44 | ]
45 | },
46 | {
47 | "login": "notthatjen",
48 | "name": "Jen",
49 | "avatar_url": "https://avatars.githubusercontent.com/u/26903002?v=4",
50 | "profile": "https://github.com/notthatjen",
51 | "contributions": [
52 | "doc",
53 | "code"
54 | ]
55 | }
56 | ],
57 | "contributorsPerLine": 7,
58 | "linkToUsage": false
59 | }
60 |
--------------------------------------------------------------------------------
/.github/workflows/main.yml:
--------------------------------------------------------------------------------
1 | name: NPM Publish
2 |
3 | on: [push]
4 |
5 | jobs:
6 | automated_tests:
7 | runs-on: ubuntu-latest
8 | if: "!contains(github.event.head_commit.message, 'ci skip') && !contains(github.event.head_commit.message, 'skip ci') && github.ref != 'main'"
9 | steps:
10 | - uses: actions/checkout@v2
11 | - name: Use Node.js 20.x
12 | uses: actions/setup-node@v1
13 | with:
14 | node-version: 20.x
15 | - name: Cache node modules
16 | uses: actions/cache@v1
17 | with:
18 | path: node_modules
19 | key: yarn-deps-${{ hashFiles('yarn.lock') }}
20 | restore-keys: |
21 | yarn-deps-${{ hashFiles('yarn.lock') }}
22 | - name: Run tests
23 | run: |
24 | yarn install --frozen-lockfile
25 | yarn test
26 | release:
27 | runs-on: ubuntu-latest
28 | if: "!contains(github.event.head_commit.message, 'ci skip') && !contains(github.event.head_commit.message, 'skip ci')"
29 | steps:
30 | - uses: actions/checkout@v2
31 |
32 | - name: Use Node.js 20.x
33 | uses: actions/setup-node@v1
34 | with:
35 | node-version: 20.x
36 |
37 | - name: Prepare repository
38 | run: |
39 | git fetch --unshallow --tags
40 |
41 | - name: Cache node modules
42 | uses: actions/cache@v1
43 | with:
44 | path: node_modules
45 | key: yarn-deps-${{ hashFiles('yarn.lock') }}
46 | restore-keys: |
47 | yarn-deps-${{ hashFiles('yarn.lock') }}
48 |
49 | - name: Create Release
50 | env:
51 | GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
52 | NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
53 | run: |
54 | git config user.name 'Tonic Labs'
55 | git config user.email '<>'
56 | yarn install --frozen-lockfile
57 | yarn build
58 | npx auto shipit
59 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | .env*
2 | node_modules
3 | yarn.lock
4 | yarn-error.log
5 | dist
6 | .DS_STORE
--------------------------------------------------------------------------------
/.npmignore:
--------------------------------------------------------------------------------
1 | src
2 | babel.config.js
3 | package.json
4 | vite.config.js
5 | .all-contributorsrc
6 | .github
--------------------------------------------------------------------------------
/CHANGELOG.md:
--------------------------------------------------------------------------------
1 | # v1.0.20 (Thu Jun 20 2024)
2 |
3 | #### ⚠️ Pushed to `main`
4 |
5 | - Merge branch 'main' of github.com:Group-One-Technology/minijs ([@notthatjen](https://github.com/notthatjen))
6 | - refactor: use math random better for uuid ([@notthatjen](https://github.com/notthatjen))
7 |
8 | #### Authors: 1
9 |
10 | - Jen ([@notthatjen](https://github.com/notthatjen))
11 |
12 | ---
13 |
14 | # v1.0.19 (Thu Jun 20 2024)
15 |
16 | #### ⚠️ Pushed to `main`
17 |
18 | - Merge branch 'main' of github.com:Group-One-Technology/minijs ([@notthatjen](https://github.com/notthatjen))
19 | - refactor: improve uuid generation ([@notthatjen](https://github.com/notthatjen))
20 |
21 | #### Authors: 1
22 |
23 | - Jen ([@notthatjen](https://github.com/notthatjen))
24 |
25 | ---
26 |
27 | # v1.0.18 (Wed Jun 19 2024)
28 |
29 | #### ⚠️ Pushed to `main`
30 |
31 | - Merge branch 'main' of github.com:Group-One-Technology/minijs ([@notthatjen](https://github.com/notthatjen))
32 | - refactor: failsafe domReady, wrap MiniJS init with domReady ([@notthatjen](https://github.com/notthatjen))
33 |
34 | #### Authors: 1
35 |
36 | - Jen ([@notthatjen](https://github.com/notthatjen))
37 |
38 | ---
39 |
40 | # v1.0.17 (Tue Jun 18 2024)
41 |
42 | #### ⚠️ Pushed to `main`
43 |
44 | - Merge branch 'main' of github.com:Group-One-Technology/minijs ([@notthatjen](https://github.com/notthatjen))
45 | - bugfix: fix domReady, wait for the entire page to load ([@notthatjen](https://github.com/notthatjen))
46 |
47 | #### Authors: 1
48 |
49 | - Jen ([@notthatjen](https://github.com/notthatjen))
50 |
51 | ---
52 |
53 | # v1.0.16 (Tue Jun 18 2024)
54 |
55 | #### 🐛 Bug Fix
56 |
57 | - feat: allow custom attributes to be dynamic [#26](https://github.com/Group-One-Technology/minijs/pull/26) ([@jorenrui](https://github.com/jorenrui) [@tonyennis145](https://github.com/tonyennis145))
58 |
59 | #### Authors: 2
60 |
61 | - [@tonyennis145](https://github.com/tonyennis145)
62 | - Joeylene ([@jorenrui](https://github.com/jorenrui))
63 |
64 | ---
65 |
66 | # v1.0.15 (Sat Apr 13 2024)
67 |
68 | #### ⚠️ Pushed to `main`
69 |
70 | - feat: add wait helper to mini ([@jorenrui](https://github.com/jorenrui))
71 |
72 | #### Authors: 1
73 |
74 | - Joeylene ([@jorenrui](https://github.com/jorenrui))
75 |
76 | ---
77 |
78 | # v1.0.14 (Mon Mar 25 2024)
79 |
80 | #### ⚠️ Pushed to `main`
81 |
82 | - fix: delay in applying custom helpers to current state ([@jorenrui](https://github.com/jorenrui))
83 |
84 | #### Authors: 1
85 |
86 | - Joeylene ([@jorenrui](https://github.com/jorenrui))
87 |
88 | ---
89 |
90 | # v1.0.13 (Mon Mar 25 2024)
91 |
92 | #### ⚠️ Pushed to `main`
93 |
94 | - fix: do not flatten arrays for array toggle, remove, and subtract ([@jorenrui](https://github.com/jorenrui))
95 | - fix: do not flatten array for array.add ([@jorenrui](https://github.com/jorenrui))
96 |
97 | #### Authors: 1
98 |
99 | - Joeylene ([@jorenrui](https://github.com/jorenrui))
100 |
101 | ---
102 |
103 | # v1.0.12 (Mon Mar 25 2024)
104 |
105 | #### ⚠️ Pushed to `main`
106 |
107 | - feat: deep clone mini array ([@jorenrui](https://github.com/jorenrui))
108 |
109 | #### Authors: 1
110 |
111 | - Joeylene ([@jorenrui](https://github.com/jorenrui))
112 |
113 | ---
114 |
115 | # v1.0.11 (Sun Mar 24 2024)
116 |
117 | #### ⚠️ Pushed to `main`
118 |
119 | - refactor: prevent array.nextItem and array.previousItem to return null ([@jorenrui](https://github.com/jorenrui))
120 | - refactor: update how array.previousItem and array.nextItem works for multi dimensional arrays ([@jorenrui](https://github.com/jorenrui))
121 |
122 | #### Authors: 1
123 |
124 | - Joeylene ([@jorenrui](https://github.com/jorenrui))
125 |
126 | ---
127 |
128 | # v1.0.10 (Sun Mar 24 2024)
129 |
130 | #### ⚠️ Pushed to `main`
131 |
132 | - refactor: update array.search to return the same structure of the searched array ([@jorenrui](https://github.com/jorenrui))
133 |
134 | #### Authors: 1
135 |
136 | - Joeylene ([@jorenrui](https://github.com/jorenrui))
137 |
138 | ---
139 |
140 | # v1.0.9 (Sat Mar 23 2024)
141 |
142 | #### ⚠️ Pushed to `main`
143 |
144 | - feat: add array.deepFirst and array.deepLast properties ([@jorenrui](https://github.com/jorenrui))
145 | - feat: add support for multi-dimensional arrays for array.add ([@jorenrui](https://github.com/jorenrui))
146 | - feat: add support for multi dimensional arrays for array.toggle ([@jorenrui](https://github.com/jorenrui))
147 | - feat: add deep equality checker for arrays with array.sameAs(array) ([@jorenrui](https://github.com/jorenrui))
148 | - feat: add support for multi dimensional array for array.remove and array.subtract ([@jorenrui](https://github.com/jorenrui))
149 | - feat: support multi-dimensional arrays in array.nextItem and array.previousItem ([@jorenrui](https://github.com/jorenrui))
150 | - feat: add array.deepFlat and support multi dimensional array in array.search ([@jorenrui](https://github.com/jorenrui))
151 | - feat: expose MiniArray as MiniJS.Array ([@jorenrui](https://github.com/jorenrui))
152 |
153 | #### Authors: 1
154 |
155 | - Joeylene ([@jorenrui](https://github.com/jorenrui))
156 |
157 | ---
158 |
159 | # v1.0.8 (Wed Mar 20 2024)
160 |
161 | #### ⚠️ Pushed to `main`
162 |
163 | - feat: make array mutations re-renders work for el and scope variables ([@jorenrui](https://github.com/jorenrui))
164 |
165 | #### Authors: 1
166 |
167 | - Joeylene ([@jorenrui](https://github.com/jorenrui))
168 |
169 | ---
170 |
171 | # v1.0.7 (Sun Mar 17 2024)
172 |
173 | #### ⚠️ Pushed to `main`
174 |
175 | - Update README.md ([@tonyennis145](https://github.com/tonyennis145))
176 |
177 | #### Authors: 1
178 |
179 | - [@tonyennis145](https://github.com/tonyennis145)
180 |
181 | ---
182 |
183 | # v1.0.6 (Sun Mar 17 2024)
184 |
185 | #### ⚠️ Pushed to `main`
186 |
187 | - refactor: update array add, remove, toggle and replaceAt to be mutating array methods ([@jorenrui](https://github.com/jorenrui))
188 | - feat: trigger re-render for array mutation variables ([@jorenrui](https://github.com/jorenrui))
189 | - feat: identify array method usage with the lexer ([@jorenrui](https://github.com/jorenrui))
190 |
191 | #### Authors: 1
192 |
193 | - Joeylene ([@jorenrui](https://github.com/jorenrui))
194 |
195 | ---
196 |
197 | # v1.0.5 (Fri Mar 08 2024)
198 |
199 | #### ⚠️ Pushed to `main`
200 |
201 | - fix: :scope not working for dynamically inserted nodes ([@jorenrui](https://github.com/jorenrui))
202 |
203 | #### Authors: 1
204 |
205 | - Joeylene ([@jorenrui](https://github.com/jorenrui))
206 |
207 | ---
208 |
209 | # v1.0.4 (Fri Mar 08 2024)
210 |
211 | #### ⚠️ Pushed to `main`
212 |
213 | - fix: non conditional :class not working ([@jorenrui](https://github.com/jorenrui))
214 |
215 | #### Authors: 1
216 |
217 | - Joeylene ([@jorenrui](https://github.com/jorenrui))
218 |
219 | ---
220 |
221 | # v1.0.3 (Thu Feb 29 2024)
222 |
223 | #### 🐛 Bug Fix
224 |
225 | - Refactor: Rename :group to :scope [#22](https://github.com/Group-One-Technology/minijs/pull/22) ([@jorenrui](https://github.com/jorenrui))
226 |
227 | #### Authors: 1
228 |
229 | - Joeylene ([@jorenrui](https://github.com/jorenrui))
230 |
231 | ---
232 |
233 | # v1.0.2 (Tue Feb 27 2024)
234 |
235 | #### 🐛 Bug Fix
236 |
237 | - Release: v1.0.2 [#19](https://github.com/Group-One-Technology/minijs/pull/19) ([@jorenrui](https://github.com/jorenrui))
238 | - Refactor: Entity Variable Restructure [#21](https://github.com/Group-One-Technology/minijs/pull/21) ([@jorenrui](https://github.com/jorenrui))
239 | - Refactor: Group Variables (rename of Parent Variables) [#20](https://github.com/Group-One-Technology/minijs/pull/20) ([@jorenrui](https://github.com/jorenrui))
240 |
241 | #### Authors: 1
242 |
243 | - Joeylene ([@jorenrui](https://github.com/jorenrui))
244 |
245 | ---
246 |
247 | # v1.0.1 (Mon Feb 26 2024)
248 |
249 | :tada: This release contains work from new contributors! :tada:
250 |
251 | Thanks for all your work!
252 |
253 | :heart: Joeylene ([@jorenrui](https://github.com/jorenrui))
254 |
255 | :heart: null[@tonyennis145](https://github.com/tonyennis145)
256 |
257 | :heart: Jen ([@jensnowww](https://github.com/jensnowww))
258 |
259 | #### 🐛 Bug Fix
260 |
261 | - Fix: Lexer Bugs Found [#18](https://github.com/Group-One-Technology/minijs/pull/18) ([@jorenrui](https://github.com/jorenrui))
262 | - Tests: Setup Vitest and Add Test Cases for the Lexer [#17](https://github.com/Group-One-Technology/minijs/pull/17) ([@jorenrui](https://github.com/jorenrui))
263 | - Refactor: Lexer with Variable Shadowing [#16](https://github.com/Group-One-Technology/minijs/pull/16) ([@jorenrui](https://github.com/jorenrui))
264 | - refactor: update condition for regions [#16](https://github.com/Group-One-Technology/minijs/pull/16) ([@jorenrui](https://github.com/jorenrui))
265 | - Feature: Support for Dynamically Inserted Scripts [#15](https://github.com/Group-One-Technology/minijs/pull/15) ([@jorenrui](https://github.com/jorenrui))
266 | - feat: add support for dynamically updated DOM element events [#15](https://github.com/Group-One-Technology/minijs/pull/15) ([@jorenrui](https://github.com/jorenrui))
267 | - Refactor: :each with variables [#14](https://github.com/Group-One-Technology/minijs/pull/14) ([@jorenrui](https://github.com/jorenrui))
268 | - Feat: Key Events - Key Modifiers [#13](https://github.com/Group-One-Technology/minijs/pull/13) ([@jorenrui](https://github.com/jorenrui))
269 | - Fix: :checked attribute when set to false [#12](https://github.com/Group-One-Technology/minijs/pull/12) ([@jorenrui](https://github.com/jorenrui))
270 | - Fix: Reactive El Variables; Refactor: Rehaul of State Dependencies; Feat: Parent El Variables [#11](https://github.com/Group-One-Technology/minijs/pull/11) ([@jorenrui](https://github.com/jorenrui))
271 | - Fix: SVG :class not working [#10](https://github.com/Group-One-Technology/minijs/pull/10) ([@jorenrui](https://github.com/jorenrui))
272 | - Refactor: Breakdown Entity [#9](https://github.com/Group-One-Technology/minijs/pull/9) ([@jorenrui](https://github.com/jorenrui))
273 | - Commit fully compiled files [#9](https://github.com/Group-One-Technology/minijs/pull/9) ([@tonyennis145](https://github.com/tonyennis145))
274 | - feat: remove event bindings on entity dispose [#8](https://github.com/Group-One-Technology/minijs/pull/8) ([@jorenrui](https://github.com/jorenrui))
275 | - refactor: add try-catch for create init children [#8](https://github.com/Group-One-Technology/minijs/pull/8) ([@jorenrui](https://github.com/jorenrui))
276 | - Feature: DOM Observer [#8](https://github.com/Group-One-Technology/minijs/pull/8) ([@jorenrui](https://github.com/jorenrui))
277 | - style: use prettier [#8](https://github.com/Group-One-Technology/minijs/pull/8) ([@jorenrui](https://github.com/jorenrui))
278 | - Refactor: Update Behavior of :class to Invert Classes [#7](https://github.com/Group-One-Technology/minijs/pull/7) ([@jorenrui](https://github.com/jorenrui))
279 | - Feat: Slider [#6](https://github.com/Group-One-Technology/minijs/pull/6) ([@jorenrui](https://github.com/jorenrui))
280 | - Refactor: Lexer Variables [#5](https://github.com/Group-One-Technology/minijs/pull/5) ([@jorenrui](https://github.com/jorenrui))
281 | - Feature: Tonic Modal [#4](https://github.com/Group-One-Technology/minijs/pull/4) ([@jorenrui](https://github.com/jorenrui))
282 | - Refactor: Use JS-Tokens for Lexer [#3](https://github.com/Group-One-Technology/minijs/pull/3) ([@jorenrui](https://github.com/jorenrui))
283 | - Feature: Dialog and Alert Dialog [#2](https://github.com/Group-One-Technology/minijs/pull/2) ([@jorenrui](https://github.com/jorenrui))
284 | - Feature: Multiple Select [#1](https://github.com/Group-One-Technology/minijs/pull/1) ([@jorenrui](https://github.com/jorenrui))
285 |
286 | #### ⚠️ Pushed to `main`
287 |
288 | - chore: update file in contributorsrc ([@jorenrui](https://github.com/jorenrui))
289 | - refactor: rename readme to README ([@jorenrui](https://github.com/jorenrui))
290 | - chore: update contributors ([@jorenrui](https://github.com/jorenrui))
291 | - build: setup git config ([@jorenrui](https://github.com/jorenrui))
292 | - build: update dependencies ([@jorenrui](https://github.com/jorenrui))
293 | - docs: add test script in readme ([@jorenrui](https://github.com/jorenrui))
294 | - feat: add lexer support for object expression, rest element, and arrow functions ([@jorenrui](https://github.com/jorenrui))
295 | - refactor: update fetch of variables in :each directive ([@jorenrui](https://github.com/jorenrui))
296 | - fix: attach helper variables to variables after evaluate event attribute ([@jorenrui](https://github.com/jorenrui))
297 | - docs: add link to notion docu ([@jorenrui](https://github.com/jorenrui))
298 | - docs: add info regarding re-rendering ([@jorenrui](https://github.com/jorenrui))
299 | - chore: add todo for lexer on object destructuring ([@jorenrui](https://github.com/jorenrui))
300 | - fix: disable re-rendering on el and parent variables re-assignement in dynamic attributes (prevents infinite loop) ([@jorenrui](https://github.com/jorenrui))
301 | - fix: prevent triggering re-render on evaluate dynamic attribute (prevent infinite loop) ([@jorenrui](https://github.com/jorenrui))
302 | - docs: update description of :value, :class, and :text ([@jorenrui](https://github.com/jorenrui))
303 | - refactor: remove unused helper ([@jorenrui](https://github.com/jorenrui))
304 | - chore: add comment regarding null parent ([@jorenrui](https://github.com/jorenrui))
305 | - docs: update previousItem usage ([@jorenrui](https://github.com/jorenrui))
306 | - feat: add replaceAt array method ([@jorenrui](https://github.com/jorenrui))
307 | - docs: update custom events ([@jorenrui](https://github.com/jorenrui))
308 | - fix: parent is null ([@jorenrui](https://github.com/jorenrui))
309 | - fix: prevent re-renders until ready ([@jorenrui](https://github.com/jorenrui))
310 | - refactor: update cloned child ([@jorenrui](https://github.com/jorenrui))
311 | - fix: :load event not running ([@jorenrui](https://github.com/jorenrui))
312 | - chore: update todo ([@jorenrui](https://github.com/jorenrui))
313 | - fix: ignore call expressions ([@jorenrui](https://github.com/jorenrui))
314 | - fix: add support for array pattern ([@jorenrui](https://github.com/jorenrui))
315 | - fix: ignore native variables and new expression for member identifiers ([@jorenrui](https://github.com/jorenrui))
316 | - refactor: dispose event before setting event ([@jorenrui](https://github.com/jorenrui))
317 | - refactor: relocate custom event setters to set event ([@jorenrui](https://github.com/jorenrui))
318 | - refactor: update demo to use :clickme ([@jorenrui](https://github.com/jorenrui))
319 | - refactor: update key of event listeners ([@jorenrui](https://github.com/jorenrui))
320 | - feat: add :clickme event ([@jorenrui](https://github.com/jorenrui))
321 | - refactor: rename special keys to system keys ([@jorenrui](https://github.com/jorenrui))
322 | - fix: set parent entity as document if there are no parents found ([@jorenrui](https://github.com/jorenrui))
323 | - feat: add support for aria-*, data-*, and dash-cased attributes ([@jorenrui](https://github.com/jorenrui))
324 | - refactor: update query selector ([@jorenrui](https://github.com/jorenrui))
325 | - fix: prevent returning current element as parent ([@jorenrui](https://github.com/jorenrui))
326 | - fix: remove array type event listeners ([@jorenrui](https://github.com/jorenrui))
327 | - fix: check if dynamic attribute before evaluating it for observeDOM ([@jorenrui](https://github.com/jorenrui))
328 | - chore: add comment on getParent ([@jorenrui](https://github.com/jorenrui))
329 | - refactor: remove unused logic ([@jorenrui](https://github.com/jorenrui))
330 | - docs: add dynamic attributes to README ([@jorenrui](https://github.com/jorenrui))
331 | - docs: update README ([@jorenrui](https://github.com/jorenrui))
332 | - feat: detect and apply changes to dynamic attributes ([@jorenrui](https://github.com/jorenrui))
333 | - fix: make :each children work with observe dom ([@jorenrui](https://github.com/jorenrui))
334 | - refactor: remove dom content loaded listener ([@jorenrui](https://github.com/jorenrui))
335 | - fix: prevent duplicate entity init for :each attribute ([@jorenrui](https://github.com/jorenrui))
336 | - fix: use mini events ([@jorenrui](https://github.com/jorenrui))
337 | - fix: array listeners not working ([@jorenrui](https://github.com/jorenrui))
338 | - refactor: add try-catch for parser ([@jorenrui](https://github.com/jorenrui))
339 | - fix: used variables by dynamically added dom are being removed during disposal of nodes ([@jorenrui](https://github.com/jorenrui))
340 | - feat: track event listeners of entity ([@jorenrui](https://github.com/jorenrui))
341 | - docs: run prettier ([@jorenrui](https://github.com/jorenrui))
342 | - chore: add comments ([@jorenrui](https://github.com/jorenrui))
343 | - refactor: expose window ([@jorenrui](https://github.com/jorenrui))
344 | - fix: escape html for :each directive ([@jorenrui](https://github.com/jorenrui))
345 | - refactor: relocate scope arg in async function ([@jorenrui](https://github.com/jorenrui))
346 | - refactor: update default scope and this for interpreter ([@jorenrui](https://github.com/jorenrui))
347 | - refactor: replace eval with async function ([@jorenrui](https://github.com/jorenrui))
348 | - style: remove semicolons ([@jorenrui](https://github.com/jorenrui))
349 | - feat: add try-catch for eval ([@jorenrui](https://github.com/jorenrui))
350 | - refactor: relocate files under generators and helpers ([@jorenrui](https://github.com/jorenrui))
351 | - feat: add interpreter and add eval in context ([@jorenrui](https://github.com/jorenrui))
352 | - refactor: remove commented proxy object ([@jorenrui](https://github.com/jorenrui))
353 | - fix: clickout not working when target is the html tag ([@jorenrui](https://github.com/jorenrui))
354 | - fix: non conditional classnames not working ([@jorenrui](https://github.com/jorenrui))
355 | - feat: add entity id on debug mode ([@jorenrui](https://github.com/jorenrui))
356 | - docs: fix typo ([@jorenrui](https://github.com/jorenrui))
357 | - docs: add installation steps ([@jorenrui](https://github.com/jorenrui))
358 | - refactor: add default state to avoid content shift ([@jorenrui](https://github.com/jorenrui))
359 | - refactor: hide unused button ([@jorenrui](https://github.com/jorenrui))
360 | - fix: access to local storage ([@jorenrui](https://github.com/jorenrui))
361 | - refactor: comment out proxy object ([@jorenrui](https://github.com/jorenrui))
362 | - refactor: remove object property shorthand syntax identifier ([@jorenrui](https://github.com/jorenrui))
363 | - refactor: replace document.querySelector with $ ([@jorenrui](https://github.com/jorenrui))
364 | - refactor: update time on months click ([@jorenrui](https://github.com/jorenrui))
365 | - feat: flexible option ui ([@jorenrui](https://github.com/jorenrui))
366 | - feat: set $ to document.querySelector ([@jorenrui](https://github.com/jorenrui))
367 | - fix: identifying object shorthand with operator, and calculated methods ([@jorenrui](https://github.com/jorenrui))
368 | - fix: update check if start of obejct ([@jorenrui](https://github.com/jorenrui))
369 | - feat: add dynamic attributes ([@jorenrui](https://github.com/jorenrui))
370 | - refactor: update MiniJS.ignore ([@jorenrui](https://github.com/jorenrui))
371 | - fix: ignore object with no assigned variable ([@jorenrui](https://github.com/jorenrui))
372 | - fix: check if object is not assigned to any variable ([@jorenrui](https://github.com/jorenrui))
373 | - refactor: remove initial class ([@jorenrui](https://github.com/jorenrui))
374 | - refactor: remove duplicate filter ([@jorenrui](https://github.com/jorenrui))
375 | - Merge branch 'jr.feat-proxy-variables' ([@jorenrui](https://github.com/jorenrui))
376 | - refactor: update keyup events ([@jorenrui](https://github.com/jorenrui))
377 | - refactor: set initial state for code blocks ([@jorenrui](https://github.com/jorenrui))
378 | - fix: element being set if null ([@jorenrui](https://github.com/jorenrui))
379 | - fix: update on enter trigger ([@jorenrui](https://github.com/jorenrui))
380 | - feat: add check-in / check out tabs ([@jorenrui](https://github.com/jorenrui))
381 | - fix: identifying object properties / method's parent ([@jorenrui](https://github.com/jorenrui))
382 | - refactor: update transition and add color ([@jorenrui](https://github.com/jorenrui))
383 | - fix: keypress working when not target element ([@jorenrui](https://github.com/jorenrui))
384 | - feat: set selected destination on enter ([@jorenrui](https://github.com/jorenrui))
385 | - feat: initial airbnb search bar clone ([@jorenrui](https://github.com/jorenrui))
386 | - feat: add touch events on :press ([@jorenrui](https://github.com/jorenrui))
387 | - fix: :value not changing when newValue is empty string ([@jorenrui](https://github.com/jorenrui))
388 | - feat: add :press custom event ([@jorenrui](https://github.com/jorenrui))
389 | - feat: add :keyup.enter and :keyup.space events ([@jorenrui](https://github.com/jorenrui))
390 | - Update readme.md ([@tonyennis145](https://github.com/tonyennis145))
391 | - feat: add proxy to nested objects ([@jorenrui](https://github.com/jorenrui))
392 | - feat: listen for object property changes ([@jorenrui](https://github.com/jorenrui))
393 | - refactor: update sample code for tonic modal ([@jorenrui](https://github.com/jorenrui))
394 | - refactor: use :class on tonic modal ([@jorenrui](https://github.com/jorenrui))
395 | - refactor: update html tags in multiple select ([@jorenrui](https://github.com/jorenrui))
396 | - refactor: update code example ([@jorenrui](https://github.com/jorenrui))
397 | - docs: update previousOf example ([@jorenrui](https://github.com/jorenrui))
398 | - Bump version manually ([@tonyennis145](https://github.com/tonyennis145))
399 | - Delete cached dist folder ([@tonyennis145](https://github.com/tonyennis145))
400 | - ignore dist file ([@tonyennis145](https://github.com/tonyennis145))
401 | - try version ([@tonyennis145](https://github.com/tonyennis145))
402 | - Publish .1 ([@tonyennis145](https://github.com/tonyennis145))
403 | - Fix variable assignment, add readme ([@tonyennis145](https://github.com/tonyennis145))
404 | - Add scoping ([@tonyennis145](https://github.com/tonyennis145))
405 | - Add each syntax and sample ([@tonyennis145](https://github.com/tonyennis145))
406 | - Search improvement ([@jensnowww](https://github.com/jensnowww))
407 | - Add each function ([@jensnowww](https://github.com/jensnowww))
408 | - rename package to tonic-minijs ([@jensnowww](https://github.com/jensnowww))
409 | - Add auth to npm ([@jensnowww](https://github.com/jensnowww))
410 | - Include dist to deployment ([@jensnowww](https://github.com/jensnowww))
411 | - Update demo ([@jensnowww](https://github.com/jensnowww))
412 | - add npm ignore ([@jensnowww](https://github.com/jensnowww))
413 | - Install specific package versions ([@jensnowww](https://github.com/jensnowww))
414 | - Clear cacche ([@jensnowww](https://github.com/jensnowww))
415 | - Add gitignore skip ci ([@jensnowww](https://github.com/jensnowww))
416 | - add auto to package ([@jensnowww](https://github.com/jensnowww))
417 | - add contributor package ([@jensnowww](https://github.com/jensnowww))
418 | - Add author in package.json ([@jensnowww](https://github.com/jensnowww))
419 | - remove watch on build ([@jensnowww](https://github.com/jensnowww))
420 | - Create main.yml ([@jensnowww](https://github.com/jensnowww))
421 | - Update node version ([@jensnowww](https://github.com/jensnowww))
422 | - Add auto release ([@jensnowww](https://github.com/jensnowww))
423 | - Initial commit ([@jensnowww](https://github.com/jensnowww))
424 |
425 | #### Authors: 3
426 |
427 | - [@tonyennis145](https://github.com/tonyennis145)
428 | - Jen ([@jensnowww](https://github.com/jensnowww))
429 | - Joeylene ([@jorenrui](https://github.com/jorenrui))
430 |
431 | ---
432 |
433 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # MiniJS
2 |
3 | Mini is a ~~library~~ extension for HTML which lets you add interactivity to your app without needing a full blown frontend framework.
4 |
5 | ## The Idea
6 |
7 | - HTML is great because it's easy to learn and extremely accessible. But HTML has shortcomings when it comes to building interfaces with interactivity.
8 | - Lots of libraries have emerged to address these shortcomings - react, vue etc. These libraries are great but they:
9 | - Have a high learning curve when it comes to code patterns and tooling.
10 | - Are primarily suited for interfaces with _lots_ of interactivity.
11 | - Mini JS lets you build interfaces with moderate amounts of interactivity without needing a heavyweight, javascript-centered library. Because it follows the same patterns as html, it doesn't require learning lots of new concepts. It's designed to be extremely minimal and learnable within an afternoon.
12 | - The key idea is that if we have
13 | 1. A way to set state when an interaction happens (e.g a user clicks a button or types in an input), and
14 | 2. A way to update other parts of the UI when those variables change, we can now easily do a range of things we previously couldn't do.
15 | - Technically vanilla HTML can already do (1), but it can't do (2).
16 |
17 | ## Setting State
18 |
19 | `State` are variables that changes the UI or the DOM that uses it when they get updated.
20 |
21 | Note: Only non-objects are supported for reactive state.
22 |
23 | ### Setting Initial State
24 |
25 | You can set the initial state of the variables using vanilla JS:
26 |
27 | ```html
28 |
32 | ```
33 |
34 | ### Syncing the DOM with your state
35 |
36 | These are the following **dynamic attributes** that you can use to sync the DOM with your state:
37 |
38 | - `:value`
39 | - Set the value of a form input to the result of the evaluated JS code.
40 | - `:class`
41 | - Set the class of a DOM element to the result of the evaluated JS code.
42 | - `:text`
43 | - Set the text content of a DOM element to the result of the evaluated JS code.
44 |
45 | ```html
46 |
49 |
50 |
51 |
52 |
53 |
54 | ```
55 |
56 | ### Triggering DOM Updates / Re-renders
57 |
58 | A DOM update or a re-render happens when the state variable is re-assigned in **dynamic events**.
59 |
60 | ```html
61 |
62 |
63 | ```
64 |
65 | When re-assignment happens in dynamic attributes, it will not trigger a re-render to avoid infinite loops.
66 |
67 | ```html
68 |
69 |
70 | ```
71 |
72 | ### Special Variables
73 |
74 | There are special variables that you can use inside dynamic attributes and events:
75 |
76 | - `this` - the current element
77 | - `$` - equal to the `document.querySelector`.
78 |
79 | ## Dynamic Attributes
80 |
81 | Besides `:value`, `:class`, and `:text`, you can also make **any** attribute dynamic by renaming it from `attribute` to `:attribute`. Values set to dynamic attributes are evaluated as JavaScript:
82 |
83 | ```html
84 |
87 |
88 |
My style is changing
89 |
97 | ```
98 |
99 | ## Classes
100 |
101 | You can make your class names reactive by using the `:class` attribute:
102 |
103 | ```html
104 |
107 |
108 |
111 | ```
112 |
113 | ### Setting the Default Classes
114 |
115 | To set default classes, you can use the `class` attribute:
116 |
117 | ```html
118 |
119 | ```
120 |
121 | ### Setting Multiple Reactive Classes
122 |
123 | To set multiple reactive classes, you can use the `:class` attribute:
124 |
125 | 1. Use multiple ternary operators enclosed in parentheses:
126 |
127 | ```html
128 |
132 | ```
133 |
134 | 2. Use if-else statements:
135 |
136 | ```html
137 |
150 | ```
151 |
152 | ## Events
153 |
154 | You can create, use, and update state variables inside DOM events.
155 |
156 | In events, you can get the current event using the `event` variable:
157 |
158 | ```html
159 |
160 | ```
161 |
162 | ### Native Events
163 |
164 | All native events are supported. You can use them like this:
165 |
166 | ```html
167 |
168 | ```
169 |
170 | You can access the current element in the event via `this`:
171 |
172 | ```html
173 |
174 |
175 |
176 | ```
177 |
178 | ### Custom Events
179 |
180 | These are the events added in by MiniJS:
181 |
182 | - `:clickout` - This will trigger when the user clicks outside of the current element.
183 | - `:clickme` - This will trigger when the user clicks the current element.
184 | - `:change` - This will trigger when the user changes the value of a form input.
185 | - `:press` - This will trigger when the user:
186 | - triggers the `click` event.
187 | - triggers the `keyup.enter` and `keyup.space` events.
188 | - triggers the `touchstart` event.
189 |
190 | ### Keyboard Events
191 |
192 | For keyboard events, you can listen to them using `:keyup`, `:keydown`, and `:keypress`:
193 |
194 | ```html
195 |
196 | ```
197 |
198 | #### Key Modifiers
199 |
200 | You can also use key modifiers to listen to specific keys. Modifiers are appended to the event name using a dot:
201 |
202 | ```html
203 |
208 | ```
209 |
210 | You can chain multiple key modifiers together:
211 |
212 | ```html
213 |
214 | ```
215 |
216 | For key values that have multiple words like `BracketLeft`, except for arrow keys, kebab case is used:
217 |
218 | ```html
219 |
223 | ```
224 |
225 | The following are the available key modifiers:
226 |
227 | | Type | Key Value | Modifier | Usage |
228 | | ---------------------------------- | ---------------------------------- | ------------------------------ | --------------------------------------------------- |
229 | | Digits (0-9) | Digit1, Digit2 | 1, 2 | :keyup.1, :keyup.2 |
230 | | Letters (A-Z, a-z) | KeyA, KeyB | a, b | :keyup.a, :keyup.b |
231 | | Numpad (0-9) | Numpad1, Numpad2 | 1, 2 | :keyup.1, :keyup.2 |
232 | | Arrow Keys (up, down, left, right) | ArrowLeft, ArrowRight | left, right | :keyup.left, :keyup.right |
233 | | Meta (left, right) | Meta, MetaLeft, MetaRight | meta, meta-left, meta-right | :keyup.meta, :keyup.meta-left, :keyup.meta-right |
234 | | Alt (left, right) | Alt, AltLeft, AltRight | alt, alt-left, alt-right | :keyup.alt, :keyup.alt-left, :keyup.alt-right |
235 | | Control (left, right) | Control, ControlLeft, ControlRight | ctrl, ctrl-left, ctrl-right | :keyup.ctrl, :keyup.ctrl-left, :keyup.ctrl-right |
236 | | Shift (left, right) | Shift, ShiftLeft, ShiftRight | shift, shift-left, shift-right | :keyup.shift, :keyup.shift-left, :keyup.shift-right |
237 | | Symbols (., /, =, etc.) | Period, BracketLeft, Slash | period, bracket-left, slash | :keyup.period, :keyup.bracket-left, :keyup.slash |
238 |
239 | > Note: If you don't know the "name" of a symbol key, you can use the `console.log(event.code)` to see the key value. Example for the "Enter" key: `:keyup="console.log(event.code)"` will log "Enter". So you can use `:keyup.enter` to listen to the "Enter" key.
240 |
241 | ---
242 |
243 | ## Statements
244 |
245 | ### Each Statement
246 |
247 | The `:each` statement is used to loop through an array and render a template for each item.
248 |
249 | ```html
250 |
253 |
254 |
255 |
256 |
257 |
258 |
259 |
260 |
261 | ```
262 |
263 | You can also use complex variables for the `:each` statement:
264 |
265 | ```html
266 |
274 |
275 |
276 |
277 |
278 | ```
279 |
280 | Note: Each item variables are **read-only**, which means you can't re-assign them like:
281 |
282 | ```html
283 |
284 |
285 |
286 | ```
287 |
288 | ## Variables
289 |
290 | ### Variables saved in Local Storage
291 |
292 | Appending `$` to the variable name will save the variable in the local storage:
293 |
294 | ```html
295 |
298 |
299 |
300 | ```
301 |
302 | Note: Currently, this is only available for globally declared variables.
303 |
304 | ### Variable Scoping
305 |
306 | #### Global Variables
307 |
308 | Whenever you create a variable, it will automatically be added to the global scope. This means that you can access it anywhere in your code.
309 |
310 | ```html
311 |
314 |
315 |
316 | ```
317 |
318 | #### Local Variables
319 |
320 | To use variables only in a current event, you can create a local variable using `const`, and `let`:
321 |
322 | ```html
323 |
329 | ```
330 |
331 | ### Element Variables
332 |
333 | If you want to use the variable across an element's attributes and events, you can use `el.`:
334 |
335 | ```html
336 |
339 |
340 |
347 | ```
348 |
349 | Like the example above, `:load` can be used to set the initial value of the variable.
350 |
351 | ### Scope Variables
352 |
353 | Adding a `:scope` attribute to an element will allow you to access its variables from its children using `scope.` variables.
354 |
355 | ```html
356 |
357 |
358 |
359 |
362 |
368 |
372 | Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy
373 | eirmod.
374 |
375 |
376 |
377 |
380 |
386 |
390 | Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy
391 | eirmod.
392 |
393 |
394 |
395 |
399 |
405 |
409 | Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy
410 | eirmod.
411 |
412 |
413 |
414 | ```
415 |
416 | You can set the default value of the scope variables in the `:scope` directive:
417 |
418 | ```html
419 |
420 |
421 |
422 | ```
423 |
424 | ### Variable Methods
425 |
426 | MiniJS added some commonly-used custom methods to variables.
427 |
428 | ### Array
429 |
430 | Here are the custom array methods which are available for you to use:
431 |
432 | - `first` - returns the first item in the array.
433 | Usage: `array.first`
434 |
435 | ```js
436 | array = ['Cherries', 'Chocolate', 'Blueberry', 'Vanilla']
437 | array.first // returns 'Cherries'
438 | ```
439 |
440 | - `last` - returns the last item in the array.
441 | Usage: `array.last`
442 |
443 | ```js
444 | array = ['Cherries', 'Chocolate', 'Blueberry', 'Vanilla']
445 | array.last // returns 'Vanilla'
446 | ```
447 |
448 | - `search` - returns a new array of items that match the query.
449 | Usage: `array.search('query')`
450 |
451 | ```js
452 | array = ['Cherries', 'Chocolate', 'Blueberry', 'Vanilla']
453 | array.search('c') // returns ['Cherries', 'Chocolate']
454 | ```
455 |
456 | - `subtract` - removes a list of items from the array if they exist.
457 | Usage: `array.subtract(['item1', 'item2'])`
458 |
459 | ```js
460 | array = ['Tag 1', 'Tag 2', 'Tag 3', 'Tag 4']
461 | array.subtract(['Tag 2', 'Tag 3']) // returns ['Tag 1', 'Tag 4']
462 | ```
463 |
464 | - `nextItem` - gets the next item based on the given item in the array.
465 | Usage: `array.nextItem('item')`
466 | ```js
467 | array = ['Tag 1', 'Tag 2', 'Tag 3', 'Tag 4']
468 | array.nextItem('Tag 2') // returns 'Tag 3'
469 | ```
470 | - `previousItem` - gets the next item based on the given item in the array.
471 | Usage: `array.previousItem('item')`
472 |
473 | ```js
474 | array = ['Tag 1', 'Tag 2', 'Tag 3', 'Tag 4']
475 | array.previousItem('Tag 2') // returns 'Tag 1'
476 | ```
477 |
478 | - `add` - adds an item to the original array if it doesn't exist.
479 | - This mutates the original array.
480 | Usage: `array.add('item')`
481 |
482 | ```js
483 | array = ['Tag 1', 'Tag 2', 'Tag 3', 'Tag 4']
484 | array.add('Tag 5') // returns ['Tag 1', 'Tag 2', 'Tag 3', 'Tag 4', 'Tag 5']
485 | ```
486 |
487 | - `remove` - removes an item from the original array if it exists.
488 | - This mutates the original array.
489 | Usage: `array.remove('item')`
490 |
491 | ```js
492 | array = ['Tag 1', 'Tag 2', 'Tag 3', 'Tag 4']
493 | array.remove('Tag 2') // returns ['Tag 1', 'Tag 3', 'Tag 4']
494 | ```
495 |
496 | - `toggle` - removes / adds the item in the original array
497 | - This mutates the original array.
498 | Usage: `array.toggle('item')`
499 |
500 | ```js
501 | array = ['Cherries', 'Chocolate', 'Blueberry', 'Vanilla']
502 | array.toggle('Cherries') // removes 'Cherries'
503 | // returns ['Chocolate', 'Blueberry', 'Vanilla']
504 |
505 | array.toggle('Cherries') // re-adds 'Cherries'
506 | // returns ['Cherries', 'Chocolate', 'Blueberry', 'Vanilla']
507 | ```
508 |
509 | - `replaceAt` - replaces the item at the given index with the new item.
510 | - This mutates the original array.
511 | Usage: `array.replaceAt(index, 'newItem')`
512 |
513 | ```js
514 | array = ['Tag 1', 'Tag 2', 'Tag 3', 'Tag 4']
515 | array.replaceAt(1, 'Tag 5') // returns ['Tag 1', 'Tag 5', 'Tag 3', 'Tag 4']
516 | ```
517 |
518 | ## Contributors
519 |
520 |
521 |
522 |
523 |