directix 1.0.0-beta.1 → 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -4,16 +4,27 @@
4
4
  [![npm downloads](https://img.shields.io/npm/dm/directix.svg)](https://www.npmjs.com/package/directix)
5
5
  [![GitHub license](https://img.shields.io/github/license/saqqdy/directix)](https://github.com/saqqdy/directix/blob/main/LICENSE)
6
6
 
7
+ **[中文文档](README_CN.md)**
8
+
7
9
  A comprehensive, easy-to-use, and high-performance Vue custom directives library supporting both Vue 2 and Vue 3.
8
10
 
9
11
  ## Features
10
12
 
11
13
  - 🎯 **Comprehensive** - 30+ commonly used directives
12
- - 🔄 **Vue 2/3 Compatible** - Single codebase supports both versions
14
+ - 🔄 **Vue 2/3 Compatible** - Built on [vue-demi](https://github.com/vueuse/vue-demi), single codebase supports both versions
13
15
  - 📦 **Tree-shakable** - Import only what you need
14
- - 🔒 **TypeScript** - Full TypeScript support
15
- - 🚀 **SSR Friendly** - Works with server-side rendering
16
- - 🎨 **Zero Dependencies** - No external dependencies
16
+ - 🔒 **TypeScript** - Full TypeScript support with type definitions
17
+ - 🚀 **SSR Friendly** - Works with Nuxt and other SSR frameworks
18
+ - 📦 **Multiple Formats** - ESM, CJS, and IIFE (CDN) formats available
19
+
20
+ ## Online Demo
21
+
22
+ Try it online with StackBlitz:
23
+
24
+ | Demo | Link |
25
+ |------|------|
26
+ | Vue 3 | [![Open in StackBlitz](https://developer.stackblitz.com/img/open_in_stackblitz.svg)](https://stackblitz.com/github/saqqdy/directix/tree/main/examples/vue3) |
27
+ | Vue 2 | [![Open in StackBlitz](https://developer.stackblitz.com/img/open_in_stackblitz.svg)](https://stackblitz.com/github/saqqdy/directix/tree/main/examples/vue2) |
17
28
 
18
29
  ## Installation
19
30
 
@@ -28,6 +39,38 @@ yarn add directix
28
39
  pnpm add directix
29
40
  ```
30
41
 
42
+ ### Vue 2 Support
43
+
44
+ For Vue 2.0-2.6, you need to install `@vue/composition-api`:
45
+
46
+ ```bash
47
+ npm install @vue/composition-api
48
+ ```
49
+
50
+ Vue 2.7+ has built-in Composition API support, so no additional dependencies are needed.
51
+
52
+ ## CDN
53
+
54
+ You can also use Directix via CDN:
55
+
56
+ ```html
57
+ <!-- Vue 3 -->
58
+ <script src="https://unpkg.com/vue@3/dist/vue.global.js"></script>
59
+ <script src="https://unpkg.com/directix/dist/index.iife.min.js"></script>
60
+
61
+ <!-- Vue 2.7+ -->
62
+ <script src="https://unpkg.com/vue@2/dist/vue.js"></script>
63
+ <script src="https://unpkg.com/directix/dist/index.iife.min.js"></script>
64
+ ```
65
+
66
+ The CDN build includes `vue-demi` bundled internally, so it works seamlessly with both Vue 2 and Vue 3.
67
+
68
+ ## Requirements
69
+
70
+ - Vue 2.0+ or Vue 3.0+
71
+ - Node.js 12.20+ (for build tools)
72
+ - For Vue 2.0-2.6: `@vue/composition-api` is required
73
+
31
74
  ## Quick Start
32
75
 
33
76
  ### Global Registration
@@ -40,7 +83,7 @@ import Directix from 'directix'
40
83
  const app = createApp(App)
41
84
  app.use(Directix)
42
85
 
43
- // Or register specific directives
86
+ // Or register specific directives only
44
87
  app.use(Directix, {
45
88
  directives: ['click-outside', 'copy', 'debounce']
46
89
  })
@@ -57,10 +100,14 @@ Vue.use(Directix)
57
100
  ### On-Demand Import
58
101
 
59
102
  ```typescript
60
- import { vClickOutside, vCopy } from 'directix'
103
+ import { vClickOutside, vCopy, vDebounce } from 'directix'
61
104
 
105
+ // Vue 3
62
106
  app.directive('click-outside', vClickOutside)
63
107
  app.directive('copy', vCopy)
108
+
109
+ // Vue 2
110
+ Vue.directive('click-outside', vClickOutside)
64
111
  ```
65
112
 
66
113
  ## Available Directives
@@ -103,6 +150,8 @@ app.directive('copy', vCopy)
103
150
 
104
151
  ### v-click-outside
105
152
 
153
+ Detect clicks outside an element, useful for closing dropdowns, modals, etc.
154
+
106
155
  ```vue
107
156
  <template>
108
157
  <div v-click-outside="closeDropdown">
@@ -124,10 +173,17 @@ function closeDropdown() {
124
173
 
125
174
  ### v-copy
126
175
 
176
+ Copy text to clipboard with a simple directive.
177
+
127
178
  ```vue
128
179
  <template>
180
+ <!-- Simple usage -->
129
181
  <button v-copy="textToCopy">Copy to clipboard</button>
130
- <button v-copy="{ value: text, onSuccess: handleSuccess }">Copy with callback</button>
182
+
183
+ <!-- With callbacks -->
184
+ <button v-copy="{ value: text, onSuccess: handleSuccess, onError: handleError }">
185
+ Copy with callback
186
+ </button>
131
187
  </template>
132
188
 
133
189
  <script setup>
@@ -136,16 +192,27 @@ const textToCopy = 'Hello, World!'
136
192
  function handleSuccess(text) {
137
193
  console.log('Copied:', text)
138
194
  }
195
+
196
+ function handleError(error) {
197
+ console.error('Copy failed:', error)
198
+ }
139
199
  </script>
140
200
  ```
141
201
 
142
202
  ### v-debounce
143
203
 
204
+ Debounce event handlers to limit execution frequency.
205
+
144
206
  ```vue
145
207
  <template>
208
+ <!-- Default: 300ms -->
146
209
  <input v-debounce="handleInput" />
210
+
211
+ <!-- Custom wait time with modifier -->
147
212
  <input v-debounce:500ms="handleInput" />
148
- <input v-debounce="{ handler: handleInput, wait: 500 }" />
213
+
214
+ <!-- With options object -->
215
+ <input v-debounce="{ handler: handleInput, wait: 500, leading: true }" />
149
216
  </template>
150
217
 
151
218
  <script setup>
@@ -157,10 +224,20 @@ function handleInput(event) {
157
224
 
158
225
  ### v-throttle
159
226
 
227
+ Throttle event handlers to limit execution frequency.
228
+
160
229
  ```vue
161
230
  <template>
231
+ <!-- Default: 300ms -->
162
232
  <button v-throttle="handleClick">Throttled click</button>
233
+
234
+ <!-- Custom wait time with modifier -->
163
235
  <button v-throttle:1s="handleClick">1 second throttle</button>
236
+
237
+ <!-- With options object -->
238
+ <button v-throttle="{ handler: handleClick, wait: 1000, leading: true, trailing: false }">
239
+ Throttle with options
240
+ </button>
164
241
  </template>
165
242
 
166
243
  <script setup>
@@ -172,28 +249,37 @@ function handleClick() {
172
249
 
173
250
  ### v-focus
174
251
 
252
+ Auto focus an element when mounted.
253
+
175
254
  ```vue
176
255
  <template>
256
+ <!-- Simple usage -->
177
257
  <input v-focus />
258
+
259
+ <!-- With options -->
178
260
  <input v-focus="{ focus: true, refocus: true }" />
179
261
  </template>
180
262
  ```
181
263
 
182
- ## API
264
+ ## API Reference
183
265
 
184
266
  ### DirectiveInstallOptions
185
267
 
186
268
  ```typescript
187
269
  interface DirectiveInstallOptions {
188
- /** Register specific directives */
270
+ /** Register specific directives only */
189
271
  directives?: string[]
190
- /** Register all directives */
272
+ /** Register all directives (default: true) */
191
273
  all?: boolean
192
- /** Global configuration */
274
+ /** Global configuration for directives */
193
275
  config?: Record<string, any>
194
276
  }
195
277
  ```
196
278
 
279
+ ### Directive Options
280
+
281
+ Each directive accepts different options. See the [documentation](https://github.com/saqqdy/directix#usage-examples) for detailed API.
282
+
197
283
  ## Browser Support
198
284
 
199
285
  | Browser | Version |