├── .gitignore ├── CHANGELOG.md ├── LICENSE ├── README.md ├── examples ├── commits.html ├── grid.html ├── markdown.html ├── svg.html ├── todomvc.html └── tree.html ├── index.html ├── package.json ├── pnpm-lock.yaml ├── scripts └── release.js ├── src ├── app.ts ├── block.ts ├── context.ts ├── directives │ ├── bind.ts │ ├── effect.ts │ ├── for.ts │ ├── html.ts │ ├── if.ts │ ├── index.ts │ ├── model.ts │ ├── on.ts │ ├── ref.ts │ ├── show.ts │ └── text.ts ├── eval.ts ├── index.ts ├── scheduler.ts ├── utils.ts └── walk.ts ├── tests ├── bind.html ├── cloak.html ├── component.html ├── custom-delimiters.html ├── effect.html ├── for.html ├── html.html ├── if.html ├── model.html ├── multi-mount.html ├── on.html ├── once.html ├── pre.html ├── reactive.html ├── ref.html ├── scope.html ├── show.html └── text.html ├── tsconfig.json └── vite.config.ts /.gitignore: -------------------------------------------------------------------------------- 1 | TODOs.md 2 | node_modules 3 | dist 4 | explorations -------------------------------------------------------------------------------- /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | ## [0.4.1](https://github.com/vuejs/petite-vue/compare/v0.4.0...v0.4.1) (2022-01-18) 2 | 3 | ### Bug Fixes 4 | 5 | - custom delimiters in child contexts ([#90](https://github.com/vuejs/petite-vue/issues/90)) ([1bbd4d1](https://github.com/vuejs/petite-vue/commit/1bbd4d1c00c6c19f2ee6740e728fb274101fc6c9)) 6 | 7 | # [0.4.0](https://github.com/vuejs/petite-vue/compare/v0.3.0...v0.4.0) (2021-12-10) 8 | 9 | ### Breaking Changes 10 | 11 | - require vue: prefix for lifecycle hooks ([a981928](https://github.com/vuejs/petite-vue/commit/a9819283f8504a9c2d0cea4d9d122028eba2d10d)) 12 | 13 | # [0.3.0](https://github.com/vuejs/petite-vue/compare/v0.2.3...v0.3.0) (2021-09-14) 14 | 15 | ### Bug Fixes 16 | 17 | - fix parsing chained modifiers ([15f75e9](https://github.com/vuejs/petite-vue/commit/15f75e94db3ce1d3630d7ffc10e2db4748d94f3e)) 18 | - fix v-cloak on toggle ([#71](https://github.com/vuejs/petite-vue/issues/71)) ([f41981b](https://github.com/vuejs/petite-vue/commit/f41981b32ae4832e58223f55c209fd112dfbede7)) 19 | - v-for update on move ([#79](https://github.com/vuejs/petite-vue/issues/79)) ([9af4ea3](https://github.com/vuejs/petite-vue/commit/9af4ea35957053665e586556f7ffb90b9077db26)) 20 | - **v-model:** ensure v-model listeners are attached before v-on ([06d3aa7](https://github.com/vuejs/petite-vue/commit/06d3aa79b066410fe4e270b1a9dad65cb8d3fb97)), closes [#65](https://github.com/vuejs/petite-vue/issues/65) 21 | 22 | ### Features 23 | 24 | - bind methods to context ([#74](https://github.com/vuejs/petite-vue/issues/74)) ([167c49d](https://github.com/vuejs/petite-vue/commit/167c49d6940c6f35c6002093d8807ac0e835dcea)) 25 | - custom delimiters ([eda903c](https://github.com/vuejs/petite-vue/commit/eda903c0a93fe048219b74b0a44064c87b553ad4)) 26 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2021-present, Yuxi (Evan) You 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in 13 | all copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 21 | THE SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # petite-vue 2 | 3 | `petite-vue` is an alternative distribution of [Vue](https://vuejs.org) optimized for [progressive enhancement](https://developer.mozilla.org/en-US/docs/Glossary/Progressive_Enhancement). It provides the same template syntax and reactivity mental model as standard Vue. However, it is specifically optimized for "sprinkling" a small amount of interactions on an existing HTML page rendered by a server framework. See more details on [how it differs from standard Vue](#comparison-with-standard-vue). 4 | 5 | - Only ~6kb 6 | - Vue-compatible template syntax 7 | - DOM-based, mutates in place 8 | - Driven by `@vue/reactivity` 9 | 10 | ## Status 11 | 12 | - This is pretty new. There are probably bugs and there might still be API changes, so **use at your own risk.** Is it usable though? Very much. Check out the [examples](https://github.com/vuejs/petite-vue/tree/main/examples) to see what it's capable of. 13 | 14 | - The issue list is intentionally disabled because I have higher priority things to focus on for now and don't want to be distracted. If you found a bug, you'll have to either workaround it or submit a PR to fix it yourself. That said, feel free to use the discussions tab to help each other out. 15 | 16 | - Feature requests are unlikely to be accepted at this time - the scope of this project is intentionally kept to a bare minimum. 17 | 18 | ## Usage 19 | 20 | `petite-vue` can be used without a build step. Simply load it from a CDN: 21 | 22 | ```html 23 | 24 | 25 | 26 |
27 | {{ count }} 28 | 29 |
30 | ``` 31 | 32 | - Use `v-scope` to mark regions on the page that should be controlled by `petite-vue`. 33 | - The `defer` attribute makes the script execute after HTML content is parsed. 34 | - The `init` attribute tells `petite-vue` to automatically query and initialize all elements that have `v-scope` on the page. 35 | 36 | ### Manual Init 37 | 38 | If you don't want the auto init, remove the `init` attribute and move the scripts to end of ``: 39 | 40 | ```html 41 | 42 | 45 | ``` 46 | 47 | Or, use the ES module build: 48 | 49 | ```html 50 | 54 | ``` 55 | 56 | ### Production CDN URLs 57 | 58 | The short CDN URL is meant for prototyping. For production usage, use a fully resolved CDN URL to avoid resolving and redirect cost: 59 | 60 | - Global build: `https://unpkg.com/petite-vue@0.2.2/dist/petite-vue.iife.js` 61 | - exposes `PetiteVue` global, supports auto init 62 | - ESM build: `https://unpkg.com/petite-vue@0.2.2/dist/petite-vue.es.js` 63 | - Must be used with ` 86 | 87 | 88 |
89 |

{{ count }}

90 |

{{ plusOne }}

91 | 92 |
93 | ``` 94 | 95 | Note `v-scope` doesn't need to have a value here and simply serves as a hint for `petite-vue` to process the element. 96 | 97 | ### Explicit Mount Target 98 | 99 | You can specify a mount target (selector or element) to limit `petite-vue` to only that region of the page: 100 | 101 | ```js 102 | createApp().mount('#only-this-div') 103 | ``` 104 | 105 | This also means you can have multiple `petite-vue` apps to control different regions on the same page: 106 | 107 | ```js 108 | createApp({ 109 | // root scope for app one 110 | }).mount('#app1') 111 | 112 | createApp({ 113 | // root scope for app two 114 | }).mount('#app2') 115 | ``` 116 | 117 | ### Lifecycle Events 118 | 119 | You can listen to the special `vue:mounted` and `vue:unmounted` lifecycle events for each element (the `vue:` prefix is required since v0.4.0): 120 | 121 | ```html 122 |
127 | ``` 128 | 129 | ### `v-effect` 130 | 131 | Use `v-effect` to execute **reactive** inline statements: 132 | 133 | ```html 134 |
135 |
136 | 137 |
138 | ``` 139 | 140 | The effect uses `count` which is a reactive data source, so it will re-run whenever `count` changes. 141 | 142 | Another example of replacing the `todo-focus` directive found in the original Vue TodoMVC example: 143 | 144 | ```html 145 | 146 | ``` 147 | 148 | ### Components 149 | 150 | The concept of "Components" are different in `petite-vue`, as it is much more bare-bones. 151 | 152 | First, reusable scope logic can be created with functions: 153 | 154 | ```html 155 | 174 | 175 |
176 |

{{ count }}

177 | 178 |
179 | 180 |
181 |

{{ count }}

182 | 183 |
184 | ``` 185 | 186 | ### Components with Template 187 | 188 | If you also want to reuse a piece of template, you can provide a special `$template` key on a scope object. The value can be the template string, or an ID selector to a `