directix 1.0.0-beta.2 → 1.1.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 +242 -35
- package/dist/index.cjs +3191 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.ts +1217 -200
- package/dist/index.iife.js +3193 -0
- package/dist/index.iife.js.map +1 -0
- package/dist/index.iife.min.js +7 -0
- package/dist/index.mjs +3191 -0
- package/dist/index.mjs.map +1 -0
- package/package.json +97 -95
- package/dist/index.cjs.js +0 -2
- package/dist/index.cjs.js.map +0 -1
- package/dist/index.esm.js +0 -1033
- package/dist/index.esm.js.map +0 -1
package/README.md
CHANGED
|
@@ -2,18 +2,29 @@
|
|
|
2
2
|
|
|
3
3
|
[](https://www.npmjs.com/package/directix)
|
|
4
4
|
[](https://www.npmjs.com/package/directix)
|
|
5
|
-
[](https://github.com/saqqdy/directix/blob/
|
|
5
|
+
[](https://github.com/saqqdy/directix/blob/master/LICENSE)
|
|
6
|
+
|
|
7
|
+
**[中文文档](README_CN.md)**
|
|
6
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
|
-
- 🎯 **Comprehensive** -
|
|
12
|
-
- 🔄 **Vue 2/3 Compatible** - Single codebase supports both
|
|
13
|
+
- 🎯 **Comprehensive** - 21+ commonly used directives
|
|
14
|
+
- 🔄 **Vue 2/3 Compatible** - Single codebase supports both Vue 2 and Vue 3
|
|
13
15
|
- 📦 **Tree-shakable** - Import only what you need
|
|
14
|
-
- 🔒 **TypeScript** - Full TypeScript support
|
|
15
|
-
- 🚀 **SSR Friendly** -
|
|
16
|
-
-
|
|
16
|
+
- 🔒 **TypeScript** - Full TypeScript support with type definitions
|
|
17
|
+
- 🚀 **SSR Friendly** - 7 directives support SSR out of the box
|
|
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 | [](https://stackblitz.com/github/saqqdy/directix/tree/master/examples/vue3) |
|
|
27
|
+
| Vue 2 | [](https://stackblitz.com/github/saqqdy/directix/tree/master/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 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,52 +100,81 @@ 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
|
|
67
114
|
|
|
68
115
|
### Event Directives
|
|
69
116
|
|
|
70
|
-
| Directive | Description | Status |
|
|
71
|
-
|
|
72
|
-
| `v-click-outside` | Detect clicks outside an element | ✅ |
|
|
73
|
-
| `v-debounce` | Debounce event handlers | ✅ |
|
|
74
|
-
| `v-throttle` | Throttle event handlers | ✅ |
|
|
75
|
-
| `v-long-press` | Detect long press events |
|
|
117
|
+
| Directive | Description | SSR | Status |
|
|
118
|
+
|-----------|-------------|-----|--------|
|
|
119
|
+
| `v-click-outside` | Detect clicks outside an element | ❌ | ✅ |
|
|
120
|
+
| `v-debounce` | Debounce event handlers | ✅ | ✅ |
|
|
121
|
+
| `v-throttle` | Throttle event handlers | ✅ | ✅ |
|
|
122
|
+
| `v-long-press` | Detect long press events | ❌ | ✅ |
|
|
76
123
|
|
|
77
124
|
### Form Directives
|
|
78
125
|
|
|
79
|
-
| Directive | Description | Status |
|
|
80
|
-
|
|
81
|
-
| `v-copy` | Copy text to clipboard | ✅ |
|
|
82
|
-
| `v-focus` | Auto focus an element | ✅ |
|
|
83
|
-
| `v-mask` | Input masking |
|
|
126
|
+
| Directive | Description | SSR | Status |
|
|
127
|
+
|-----------|-------------|-----|--------|
|
|
128
|
+
| `v-copy` | Copy text to clipboard | ❌ | ✅ |
|
|
129
|
+
| `v-focus` | Auto focus an element | ✅ | ✅ |
|
|
130
|
+
| `v-mask` | Input masking | ❌ | ✅ |
|
|
84
131
|
|
|
85
132
|
### Visibility Directives
|
|
86
133
|
|
|
87
|
-
| Directive | Description | Status |
|
|
88
|
-
|
|
89
|
-
| `v-lazy` | Lazy load images |
|
|
90
|
-
| `v-intersect` | Detect element intersection |
|
|
91
|
-
| `v-visible` | Control element visibility |
|
|
134
|
+
| Directive | Description | SSR | Status |
|
|
135
|
+
|-----------|-------------|-----|--------|
|
|
136
|
+
| `v-lazy` | Lazy load images | ❌ | ✅ |
|
|
137
|
+
| `v-intersect` | Detect element intersection | ❌ | ✅ |
|
|
138
|
+
| `v-visible` | Control element visibility | ✅ | ✅ |
|
|
139
|
+
| `v-loading` | Show loading overlay | ✅ | ✅ |
|
|
140
|
+
|
|
141
|
+
### Scroll Directives
|
|
142
|
+
|
|
143
|
+
| Directive | Description | SSR | Status |
|
|
144
|
+
|-----------|-------------|-----|--------|
|
|
145
|
+
| `v-scroll` | Scroll event handling | ❌ | ✅ |
|
|
146
|
+
| `v-infinite-scroll` | Infinite scrolling | ❌ | ✅ |
|
|
147
|
+
| `v-sticky` | Sticky positioning | ❌ | ✅ |
|
|
92
148
|
|
|
93
149
|
### Security Directives
|
|
94
150
|
|
|
95
|
-
| Directive | Description | Status |
|
|
96
|
-
|
|
97
|
-
| `v-permission` | Permission-based element control |
|
|
98
|
-
| `v-sanitize` | Sanitize HTML content |
|
|
151
|
+
| Directive | Description | SSR | Status |
|
|
152
|
+
|-----------|-------------|-----|--------|
|
|
153
|
+
| `v-permission` | Permission-based element control | ✅ | ✅ |
|
|
154
|
+
| `v-sanitize` | Sanitize HTML content | ✅ | ✅ |
|
|
99
155
|
|
|
100
|
-
|
|
156
|
+
### Effect Directives
|
|
157
|
+
|
|
158
|
+
| Directive | Description | SSR | Status |
|
|
159
|
+
|-----------|-------------|-----|--------|
|
|
160
|
+
| `v-hover` | Hover state detection | ❌ | ✅ |
|
|
161
|
+
| `v-ripple` | Material design ripple effect | ❌ | ✅ |
|
|
162
|
+
|
|
163
|
+
### Observer Directives
|
|
164
|
+
|
|
165
|
+
| Directive | Description | SSR | Status |
|
|
166
|
+
|-----------|-------------|-----|--------|
|
|
167
|
+
| `v-resize` | Element resize observer | ❌ | ✅ |
|
|
168
|
+
| `v-mutation` | DOM mutation observer | ❌ | ✅ |
|
|
169
|
+
|
|
170
|
+
> ✅ = Available | ❌ = Not SSR compatible
|
|
101
171
|
|
|
102
172
|
## Usage Examples
|
|
103
173
|
|
|
104
174
|
### v-click-outside
|
|
105
175
|
|
|
176
|
+
Detect clicks outside an element, useful for closing dropdowns, modals, etc.
|
|
177
|
+
|
|
106
178
|
```vue
|
|
107
179
|
<template>
|
|
108
180
|
<div v-click-outside="closeDropdown">
|
|
@@ -124,10 +196,17 @@ function closeDropdown() {
|
|
|
124
196
|
|
|
125
197
|
### v-copy
|
|
126
198
|
|
|
199
|
+
Copy text to clipboard with a simple directive.
|
|
200
|
+
|
|
127
201
|
```vue
|
|
128
202
|
<template>
|
|
203
|
+
<!-- Simple usage -->
|
|
129
204
|
<button v-copy="textToCopy">Copy to clipboard</button>
|
|
130
|
-
|
|
205
|
+
|
|
206
|
+
<!-- With callbacks -->
|
|
207
|
+
<button v-copy="{ value: text, onSuccess: handleSuccess, onError: handleError }">
|
|
208
|
+
Copy with callback
|
|
209
|
+
</button>
|
|
131
210
|
</template>
|
|
132
211
|
|
|
133
212
|
<script setup>
|
|
@@ -136,16 +215,27 @@ const textToCopy = 'Hello, World!'
|
|
|
136
215
|
function handleSuccess(text) {
|
|
137
216
|
console.log('Copied:', text)
|
|
138
217
|
}
|
|
218
|
+
|
|
219
|
+
function handleError(error) {
|
|
220
|
+
console.error('Copy failed:', error)
|
|
221
|
+
}
|
|
139
222
|
</script>
|
|
140
223
|
```
|
|
141
224
|
|
|
142
225
|
### v-debounce
|
|
143
226
|
|
|
227
|
+
Debounce event handlers to limit execution frequency.
|
|
228
|
+
|
|
144
229
|
```vue
|
|
145
230
|
<template>
|
|
231
|
+
<!-- Default: 300ms -->
|
|
146
232
|
<input v-debounce="handleInput" />
|
|
233
|
+
|
|
234
|
+
<!-- Custom wait time with modifier -->
|
|
147
235
|
<input v-debounce:500ms="handleInput" />
|
|
148
|
-
|
|
236
|
+
|
|
237
|
+
<!-- With options object -->
|
|
238
|
+
<input v-debounce="{ handler: handleInput, wait: 500, leading: true }" />
|
|
149
239
|
</template>
|
|
150
240
|
|
|
151
241
|
<script setup>
|
|
@@ -157,10 +247,20 @@ function handleInput(event) {
|
|
|
157
247
|
|
|
158
248
|
### v-throttle
|
|
159
249
|
|
|
250
|
+
Throttle event handlers to limit execution frequency.
|
|
251
|
+
|
|
160
252
|
```vue
|
|
161
253
|
<template>
|
|
254
|
+
<!-- Default: 300ms -->
|
|
162
255
|
<button v-throttle="handleClick">Throttled click</button>
|
|
256
|
+
|
|
257
|
+
<!-- Custom wait time with modifier -->
|
|
163
258
|
<button v-throttle:1s="handleClick">1 second throttle</button>
|
|
259
|
+
|
|
260
|
+
<!-- With options object -->
|
|
261
|
+
<button v-throttle="{ handler: handleClick, wait: 1000, leading: true, trailing: false }">
|
|
262
|
+
Throttle with options
|
|
263
|
+
</button>
|
|
164
264
|
</template>
|
|
165
265
|
|
|
166
266
|
<script setup>
|
|
@@ -172,28 +272,135 @@ function handleClick() {
|
|
|
172
272
|
|
|
173
273
|
### v-focus
|
|
174
274
|
|
|
275
|
+
Auto focus an element when mounted.
|
|
276
|
+
|
|
175
277
|
```vue
|
|
176
278
|
<template>
|
|
279
|
+
<!-- Simple usage -->
|
|
177
280
|
<input v-focus />
|
|
281
|
+
|
|
282
|
+
<!-- With options -->
|
|
178
283
|
<input v-focus="{ focus: true, refocus: true }" />
|
|
179
284
|
</template>
|
|
180
285
|
```
|
|
181
286
|
|
|
182
|
-
|
|
287
|
+
### v-permission
|
|
288
|
+
|
|
289
|
+
Control element visibility based on user permissions.
|
|
290
|
+
|
|
291
|
+
```vue
|
|
292
|
+
<template>
|
|
293
|
+
<!-- Simple permission check -->
|
|
294
|
+
<button v-permission="'admin'">Admin Only</button>
|
|
295
|
+
|
|
296
|
+
<!-- Multiple permissions (OR logic) -->
|
|
297
|
+
<button v-permission="['admin', 'editor']">Admin or Editor</button>
|
|
298
|
+
|
|
299
|
+
<!-- AND logic -->
|
|
300
|
+
<button v-permission="{ value: ['read', 'write'], mode: 'every' }">
|
|
301
|
+
Requires both permissions
|
|
302
|
+
</button>
|
|
303
|
+
|
|
304
|
+
<!-- Disable instead of remove -->
|
|
305
|
+
<button v-permission="{ value: 'admin', action: 'disable' }">
|
|
306
|
+
Disabled for non-admin
|
|
307
|
+
</button>
|
|
308
|
+
</template>
|
|
309
|
+
|
|
310
|
+
<script setup>
|
|
311
|
+
import { configurePermission } from 'directix'
|
|
312
|
+
|
|
313
|
+
configurePermission({
|
|
314
|
+
getPermissions: () => ['read', 'write'],
|
|
315
|
+
getRoles: () => ['editor'],
|
|
316
|
+
roleMap: {
|
|
317
|
+
admin: ['*'],
|
|
318
|
+
editor: ['read', 'write', 'edit']
|
|
319
|
+
}
|
|
320
|
+
})
|
|
321
|
+
</script>
|
|
322
|
+
```
|
|
323
|
+
|
|
324
|
+
### v-lazy
|
|
325
|
+
|
|
326
|
+
Lazy load images when they enter the viewport.
|
|
327
|
+
|
|
328
|
+
```vue
|
|
329
|
+
<template>
|
|
330
|
+
<!-- Simple usage -->
|
|
331
|
+
<img v-lazy="imageUrl" />
|
|
332
|
+
|
|
333
|
+
<!-- With placeholder and error image -->
|
|
334
|
+
<img v-lazy="{ src: imageUrl, placeholder: '/placeholder.png', error: '/error.png' }" />
|
|
335
|
+
</template>
|
|
336
|
+
```
|
|
337
|
+
|
|
338
|
+
### v-mask
|
|
339
|
+
|
|
340
|
+
Input masking for formatted input.
|
|
341
|
+
|
|
342
|
+
```vue
|
|
343
|
+
<template>
|
|
344
|
+
<!-- Phone number -->
|
|
345
|
+
<input v-mask="'(###) ###-####'" placeholder="Phone" />
|
|
346
|
+
|
|
347
|
+
<!-- Date -->
|
|
348
|
+
<input v-mask="'##/##/####'" placeholder="MM/DD/YYYY" />
|
|
349
|
+
|
|
350
|
+
<!-- SSN -->
|
|
351
|
+
<input v-mask="{ mask: '###-##-####', placeholder: '_' }" placeholder="SSN" />
|
|
352
|
+
</template>
|
|
353
|
+
```
|
|
354
|
+
|
|
355
|
+
### v-loading
|
|
356
|
+
|
|
357
|
+
Show loading overlay on elements.
|
|
358
|
+
|
|
359
|
+
```vue
|
|
360
|
+
<template>
|
|
361
|
+
<!-- Simple usage -->
|
|
362
|
+
<div v-loading="isLoading">Content</div>
|
|
363
|
+
|
|
364
|
+
<!-- With options -->
|
|
365
|
+
<div v-loading="{ value: isLoading, text: 'Loading...', lock: true }">
|
|
366
|
+
Content with locked scroll
|
|
367
|
+
</div>
|
|
368
|
+
</template>
|
|
369
|
+
```
|
|
370
|
+
|
|
371
|
+
### v-sanitize
|
|
372
|
+
|
|
373
|
+
Sanitize HTML content to prevent XSS attacks.
|
|
374
|
+
|
|
375
|
+
```vue
|
|
376
|
+
<template>
|
|
377
|
+
<!-- Simple usage -->
|
|
378
|
+
<div v-sanitize="userContent"></div>
|
|
379
|
+
|
|
380
|
+
<!-- With custom allowed tags -->
|
|
381
|
+
<div v-sanitize="{ html: userContent, allowedTags: ['b', 'i', 'u'] }"></div>
|
|
382
|
+
</template>
|
|
383
|
+
```
|
|
384
|
+
|
|
385
|
+
## API Reference
|
|
183
386
|
|
|
184
387
|
### DirectiveInstallOptions
|
|
185
388
|
|
|
186
389
|
```typescript
|
|
187
390
|
interface DirectiveInstallOptions {
|
|
188
|
-
/** Register specific directives */
|
|
391
|
+
/** Register specific directives only */
|
|
189
392
|
directives?: string[]
|
|
190
|
-
/** Register all directives */
|
|
393
|
+
/** Register all directives (default: true) */
|
|
191
394
|
all?: boolean
|
|
192
|
-
/** Global configuration */
|
|
395
|
+
/** Global configuration for directives */
|
|
193
396
|
config?: Record<string, any>
|
|
194
397
|
}
|
|
195
398
|
```
|
|
196
399
|
|
|
400
|
+
### Directive Options
|
|
401
|
+
|
|
402
|
+
Each directive accepts different options. See the [documentation](https://github.com/saqqdy/directix#usage-examples) for detailed API.
|
|
403
|
+
|
|
197
404
|
## Browser Support
|
|
198
405
|
|
|
199
406
|
| Browser | Version |
|