ziggy-js 1.8.0 → 2.0.0-beta.1
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 +170 -241
- package/dist/index.esm.js +1 -0
- package/dist/index.js +1 -1
- package/package.json +27 -26
- package/src/js/index.d.ts +33 -24
- package/dist/index.es.js +0 -1
- package/dist/index.m.js +0 -1
- package/dist/react.es.js +0 -1
- package/dist/react.js +0 -1
- package/dist/react.m.js +0 -1
- package/dist/vue.es.js +0 -1
- package/dist/vue.js +0 -1
- package/dist/vue.m.js +0 -1
package/README.md
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-

|
|
2
2
|
|
|
3
3
|
# Ziggy – Use your Laravel routes in JavaScript
|
|
4
4
|
|
|
@@ -8,146 +8,131 @@
|
|
|
8
8
|
[](https://npmjs.com/package/ziggy-js)
|
|
9
9
|
[](https://npmjs.com/package/ziggy-js)
|
|
10
10
|
|
|
11
|
-
Ziggy provides a JavaScript `route()`
|
|
12
|
-
|
|
13
|
-
Ziggy supports all versions of Laravel from `5.4` onward, and all modern browsers.
|
|
11
|
+
Ziggy provides a JavaScript `route()` function that works like Laravel's, making it a breeze to use your named Laravel routes in JavaScript.
|
|
14
12
|
|
|
15
13
|
- [**Installation**](#installation)
|
|
16
14
|
- [**Usage**](#usage)
|
|
17
|
-
- [
|
|
18
|
-
- [
|
|
15
|
+
- [`route()` function](#route-function)
|
|
16
|
+
- [`Router` class](#router-class)
|
|
19
17
|
- [Route-model binding](#route-model-binding)
|
|
20
18
|
- [TypeScript](#typescript)
|
|
21
|
-
- [**
|
|
22
|
-
- [
|
|
19
|
+
- [**JavaScript frameworks**](#javascript-frameworks)
|
|
20
|
+
- [Generating and importing Ziggy's configuration](#generating-and-importing-ziggys-configuration)
|
|
21
|
+
- [Importing the `route()` function](#importing-the-route-function)
|
|
23
22
|
- [Vue](#vue)
|
|
24
23
|
- [React](#react)
|
|
25
24
|
- [SPAs or separate repos](#spas-or-separate-repos)
|
|
26
25
|
- [**Filtering Routes**](#filtering-routes)
|
|
27
|
-
- [
|
|
28
|
-
- [Filtering
|
|
26
|
+
- [Including/excluding routes](#includingexcluding-routes)
|
|
27
|
+
- [Filtering with groups](#filtering-with-groups)
|
|
29
28
|
- [**Other**](#other)
|
|
30
29
|
- [**Contributing**](#contributing)
|
|
31
30
|
|
|
32
31
|
## Installation
|
|
33
32
|
|
|
34
|
-
Install Ziggy in your Laravel app:
|
|
33
|
+
Install Ziggy in your Laravel app with Composer:
|
|
35
34
|
|
|
36
35
|
```bash
|
|
37
36
|
composer require tightenco/ziggy
|
|
38
37
|
```
|
|
39
38
|
|
|
40
|
-
Add the `@routes` Blade directive to your main layout (_before_ your application's JavaScript), and the `route()` helper function will
|
|
39
|
+
Add the `@routes` Blade directive to your main layout (_before_ your application's JavaScript), and the `route()` helper function will be available globally!
|
|
41
40
|
|
|
42
41
|
> By default, the output of the `@routes` Blade directive includes a list of all your application's routes and their parameters. This route list is included in the HTML of the page and can be viewed by end users. To configure which routes are included in this list, or to show and hide different routes on different pages, see [Filtering Routes](#filtering-routes).
|
|
43
42
|
|
|
44
43
|
## Usage
|
|
45
44
|
|
|
46
|
-
|
|
45
|
+
### `route()` function
|
|
47
46
|
|
|
48
|
-
Ziggy's `route()`
|
|
47
|
+
Ziggy's `route()` function works like [Laravel's `route()` helper](https://laravel.com/docs/10.x/helpers#method-route)—you can pass it the name of a route, and the parameters you want to pass to the route, and it will generate a URL.
|
|
49
48
|
|
|
50
|
-
|
|
49
|
+
#### Basic usage
|
|
51
50
|
|
|
52
51
|
```php
|
|
53
|
-
// routes/web.php
|
|
54
|
-
|
|
55
52
|
Route::get('posts', fn (Request $request) => /* ... */)->name('posts.index');
|
|
56
53
|
```
|
|
57
54
|
|
|
58
55
|
```js
|
|
59
|
-
// app.js
|
|
60
|
-
|
|
61
56
|
route('posts.index'); // 'https://ziggy.test/posts'
|
|
62
57
|
```
|
|
63
58
|
|
|
64
|
-
|
|
59
|
+
#### Parameters
|
|
65
60
|
|
|
66
61
|
```php
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
Route::get('posts/{post}', fn (Request $request, Post $post) => /* ... */)->name('posts.show');
|
|
62
|
+
Route::get('posts/{post}', fn (Post $post) => /* ... */)->name('posts.show');
|
|
70
63
|
```
|
|
71
64
|
|
|
72
65
|
```js
|
|
73
|
-
// app.js
|
|
74
|
-
|
|
75
66
|
route('posts.show', 1); // 'https://ziggy.test/posts/1'
|
|
76
67
|
route('posts.show', [1]); // 'https://ziggy.test/posts/1'
|
|
77
68
|
route('posts.show', { post: 1 }); // 'https://ziggy.test/posts/1'
|
|
78
69
|
```
|
|
79
70
|
|
|
80
|
-
|
|
71
|
+
#### Multiple parameters
|
|
81
72
|
|
|
82
73
|
```php
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
Route::get('events/{event}/venues/{venue}', fn (Request $request, Event $event, Venue $venue) => /* ... */)->name('events.venues.show');
|
|
74
|
+
Route::get('venues/{venue}/events/{event}', fn (Venue $venue, Event $event) => /* ... */)
|
|
75
|
+
->name('venues.events.show');
|
|
86
76
|
```
|
|
87
77
|
|
|
88
78
|
```js
|
|
89
|
-
//
|
|
90
|
-
|
|
91
|
-
route('events.venues.show', [1, 2]); // 'https://ziggy.test/events/1/venues/2'
|
|
92
|
-
route('events.venues.show', { event: 1, venue: 2 }); // 'https://ziggy.test/events/1/venues/2'
|
|
79
|
+
route('venues.events.show', [1, 2]); // 'https://ziggy.test/venues/1/events/2'
|
|
80
|
+
route('venues.events.show', { venue: 1, event: 2 }); // 'https://ziggy.test/venues/1/events/2'
|
|
93
81
|
```
|
|
94
82
|
|
|
95
|
-
|
|
83
|
+
#### Query parameters
|
|
96
84
|
|
|
97
|
-
|
|
98
|
-
// routes/web.php
|
|
85
|
+
Ziggy adds arguments that don't match any named route parameters as query parameters:
|
|
99
86
|
|
|
100
|
-
|
|
87
|
+
```php
|
|
88
|
+
Route::get('venues/{venue}/events/{event}', fn (Venue $venue, Event $event) => /* ... */)
|
|
89
|
+
->name('venues.events.show');
|
|
101
90
|
```
|
|
102
91
|
|
|
103
92
|
```js
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
event: 1,
|
|
108
|
-
venue: 2,
|
|
93
|
+
route('venues.events.show', {
|
|
94
|
+
venue: 1,
|
|
95
|
+
event: 2,
|
|
109
96
|
page: 5,
|
|
110
97
|
count: 10,
|
|
111
98
|
});
|
|
112
|
-
// 'https://ziggy.test/
|
|
99
|
+
// 'https://ziggy.test/venues/1/events/2?page=5&count=10'
|
|
113
100
|
```
|
|
114
101
|
|
|
115
|
-
If you
|
|
102
|
+
If you need to pass a query parameter with the same name as a route parameter, nest it under the special `_query` key:
|
|
116
103
|
|
|
117
104
|
```js
|
|
118
|
-
route('events.
|
|
119
|
-
|
|
120
|
-
|
|
105
|
+
route('venues.events.show', {
|
|
106
|
+
venue: 1,
|
|
107
|
+
event: 2,
|
|
121
108
|
_query: {
|
|
122
109
|
event: 3,
|
|
123
110
|
page: 5,
|
|
124
111
|
},
|
|
125
112
|
});
|
|
126
|
-
// 'https://ziggy.test/
|
|
113
|
+
// 'https://ziggy.test/venues/1/events/2?event=3&page=5'
|
|
127
114
|
```
|
|
128
115
|
|
|
129
|
-
Like Laravel
|
|
116
|
+
Like Laravel, Ziggy automatically encodes boolean query parameters as integers in the query string:
|
|
130
117
|
|
|
131
118
|
```js
|
|
132
|
-
route('events.
|
|
133
|
-
|
|
134
|
-
|
|
119
|
+
route('venues.events.show', {
|
|
120
|
+
venue: 1,
|
|
121
|
+
event: 2,
|
|
135
122
|
_query: {
|
|
136
123
|
draft: false,
|
|
137
124
|
overdue: true,
|
|
138
125
|
},
|
|
139
126
|
});
|
|
140
|
-
// 'https://ziggy.test/
|
|
127
|
+
// 'https://ziggy.test/venues/1/events/2?draft=0&overdue=1'
|
|
141
128
|
```
|
|
142
129
|
|
|
143
|
-
|
|
130
|
+
#### Default parameter values
|
|
144
131
|
|
|
145
|
-
|
|
132
|
+
Ziggy supports default route parameter values ([Laravel docs](https://laravel.com/docs/urls#default-values)).
|
|
146
133
|
|
|
147
134
|
```php
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
Route::get('{locale}/posts/{post}', fn (Request $request, Post $post) => /* ... */)->name('posts.show');
|
|
135
|
+
Route::get('{locale}/posts/{post}', fn (Post $post) => /* ... */)->name('posts.show');
|
|
151
136
|
```
|
|
152
137
|
|
|
153
138
|
```php
|
|
@@ -157,12 +142,12 @@ URL::defaults(['locale' => $request->user()->locale ?? 'de']);
|
|
|
157
142
|
```
|
|
158
143
|
|
|
159
144
|
```js
|
|
160
|
-
// app.js
|
|
161
|
-
|
|
162
145
|
route('posts.show', 1); // 'https://ziggy.test/de/posts/1'
|
|
163
146
|
```
|
|
164
147
|
|
|
165
|
-
|
|
148
|
+
#### Examples
|
|
149
|
+
|
|
150
|
+
HTTP request with `axios`:
|
|
166
151
|
|
|
167
152
|
```js
|
|
168
153
|
const post = { id: 1, title: 'Ziggy Stardust' };
|
|
@@ -170,14 +155,14 @@ const post = { id: 1, title: 'Ziggy Stardust' };
|
|
|
170
155
|
return axios.get(route('posts.show', post)).then((response) => response.data);
|
|
171
156
|
```
|
|
172
157
|
|
|
173
|
-
|
|
158
|
+
### `Router` class
|
|
174
159
|
|
|
175
|
-
Calling Ziggy's `route()`
|
|
160
|
+
Calling Ziggy's `route()` function with no arguments will return an instance of its JavaScript `Router` class, which has some other useful properties and methods.
|
|
176
161
|
|
|
177
|
-
|
|
162
|
+
#### Check the current route: `route().current()`
|
|
178
163
|
|
|
179
164
|
```js
|
|
180
|
-
//
|
|
165
|
+
// Laravel route called 'events.index' with URI '/events'
|
|
181
166
|
// Current window URL is https://ziggy.test/events
|
|
182
167
|
|
|
183
168
|
route().current(); // 'events.index'
|
|
@@ -186,40 +171,41 @@ route().current('events.*'); // true
|
|
|
186
171
|
route().current('events.show'); // false
|
|
187
172
|
```
|
|
188
173
|
|
|
189
|
-
|
|
174
|
+
`route().current()` optionally accepts parameters as its second argument, and will check that their values also match in the current URL:
|
|
190
175
|
|
|
191
176
|
```js
|
|
192
|
-
//
|
|
193
|
-
// Current window URL is https://myapp.com/
|
|
177
|
+
// Laravel route called 'venues.events.show' with URI '/venues/{venue}/events/{event}'
|
|
178
|
+
// Current window URL is https://myapp.com/venues/1/events/2?hosts=all
|
|
194
179
|
|
|
195
|
-
route().current('events.
|
|
196
|
-
route().current('events.
|
|
197
|
-
route().current('events.
|
|
180
|
+
route().current('venues.events.show', { venue: 1 }); // true
|
|
181
|
+
route().current('venues.events.show', { venue: 1, event: 2 }); // true
|
|
182
|
+
route().current('venues.events.show', { hosts: 'all' }); // true
|
|
183
|
+
route().current('venues.events.show', { venue: 6 }); // false
|
|
198
184
|
```
|
|
199
185
|
|
|
200
|
-
|
|
186
|
+
#### Check if a route exists: `route().has()`
|
|
201
187
|
|
|
202
188
|
```js
|
|
203
|
-
//
|
|
189
|
+
// Laravel app has only one named route, 'home'
|
|
204
190
|
|
|
205
191
|
route().has('home'); // true
|
|
206
192
|
route().has('orders'); // false
|
|
207
193
|
```
|
|
208
194
|
|
|
209
|
-
|
|
195
|
+
#### Retrieve the current route params: `route().params`
|
|
210
196
|
|
|
211
197
|
```js
|
|
212
|
-
//
|
|
213
|
-
// Current window URL is https://myapp.com/
|
|
198
|
+
// Laravel route called 'venues.events.show' with URI '/venues/{venue}/events/{event}'
|
|
199
|
+
// Current window URL is https://myapp.com/venues/1/events/2?hosts=all
|
|
214
200
|
|
|
215
|
-
route().params; // {
|
|
201
|
+
route().params; // { venue: '1', event: '2', hosts: 'all' }
|
|
216
202
|
```
|
|
217
203
|
|
|
218
204
|
> Note: parameter values retrieved with `route().params` will always be returned as strings.
|
|
219
205
|
|
|
220
|
-
|
|
206
|
+
### Route-model binding
|
|
221
207
|
|
|
222
|
-
Ziggy supports Laravel [route-model binding](https://laravel.com/docs/routing#route-model-binding), and can even recognize custom route key names. If you pass `route()` a JavaScript object as
|
|
208
|
+
Ziggy supports Laravel's [route-model binding](https://laravel.com/docs/routing#route-model-binding), and can even recognize custom route key names. If you pass `route()` a JavaScript object as a route parameter, Ziggy will use the registered route-model binding keys for that route to find the correct parameter value inside the object. If no route-model binding keys are explicitly registered for a parameter, Ziggy will use the object's `id` key.
|
|
223
209
|
|
|
224
210
|
```php
|
|
225
211
|
// app/Models/Post.php
|
|
@@ -234,62 +220,46 @@ class Post extends Model
|
|
|
234
220
|
```
|
|
235
221
|
|
|
236
222
|
```php
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
{
|
|
241
|
-
public function show(Request $request, Post $post)
|
|
242
|
-
{
|
|
243
|
-
return view('posts.show', ['post' => $post]);
|
|
244
|
-
}
|
|
245
|
-
}
|
|
246
|
-
```
|
|
247
|
-
|
|
248
|
-
```php
|
|
249
|
-
// routes/web.php
|
|
250
|
-
|
|
251
|
-
Route::get('blog/{post}', [PostController::class, 'show'])->name('posts.show');
|
|
223
|
+
Route::get('blog/{post}', function (Post $post) {
|
|
224
|
+
return view('posts.show', ['post' => $post]);
|
|
225
|
+
})->name('posts.show');
|
|
252
226
|
```
|
|
253
227
|
|
|
254
228
|
```js
|
|
255
|
-
// app.js
|
|
256
|
-
|
|
257
229
|
const post = {
|
|
230
|
+
id: 3,
|
|
258
231
|
title: 'Introducing Ziggy v1',
|
|
259
232
|
slug: 'introducing-ziggy-v1',
|
|
260
233
|
date: '2020-10-23T20:59:24.359278Z',
|
|
261
234
|
};
|
|
262
235
|
|
|
263
|
-
// Ziggy knows that this route uses the 'slug' route-model binding key
|
|
236
|
+
// Ziggy knows that this route uses the 'slug' route-model binding key:
|
|
264
237
|
|
|
265
238
|
route('posts.show', post); // 'https://ziggy.test/blog/introducing-ziggy-v1'
|
|
266
239
|
```
|
|
267
240
|
|
|
268
|
-
Ziggy also supports [custom keys](https://laravel.com/docs/routing#customizing-the-key) for scoped bindings in
|
|
241
|
+
Ziggy also supports [custom keys](https://laravel.com/docs/routing#customizing-the-key) for scoped bindings declared directly in a route definition:
|
|
269
242
|
|
|
270
243
|
```php
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
Route::get('authors/{author}/photos/{photo:uuid}', fn (Request $request, Author $author, Photo $photo) => /* ... */)->name('authors.photos.show');
|
|
244
|
+
Route::get('authors/{author}/photos/{photo:uuid}', fn (Author $author, Photo $photo) => /* ... */)
|
|
245
|
+
->name('authors.photos.show');
|
|
274
246
|
```
|
|
275
247
|
|
|
276
248
|
```js
|
|
277
|
-
// app.js
|
|
278
|
-
|
|
279
249
|
const photo = {
|
|
280
250
|
uuid: '714b19e8-ac5e-4dab-99ba-34dc6fdd24a5',
|
|
281
251
|
filename: 'sunset.jpg',
|
|
282
252
|
}
|
|
283
253
|
|
|
284
|
-
route('authors.photos.show', [{ id: 1, name: '
|
|
254
|
+
route('authors.photos.show', [{ id: 1, name: 'Ansel' }, photo]);
|
|
285
255
|
// 'https://ziggy.test/authors/1/photos/714b19e8-ac5e-4dab-99ba-34dc6fdd24a5'
|
|
286
256
|
```
|
|
287
257
|
|
|
288
|
-
|
|
258
|
+
### TypeScript
|
|
289
259
|
|
|
290
|
-
Ziggy includes TypeScript type definitions, and
|
|
260
|
+
Ziggy includes TypeScript type definitions, and an Artisan command that can generate additional type definitions to enable route name and parameter autocompletion.
|
|
291
261
|
|
|
292
|
-
To generate
|
|
262
|
+
To generate route types, run the `ziggy:generate` command with the `--types` or `--types-only` option:
|
|
293
263
|
|
|
294
264
|
```bash
|
|
295
265
|
php artisan ziggy:generate --types
|
|
@@ -298,14 +268,14 @@ php artisan ziggy:generate --types
|
|
|
298
268
|
To make your IDE aware that Ziggy's `route()` helper is available globally, and to type it correctly, add a declaration like this in a `.d.ts` file somewhere in your project:
|
|
299
269
|
|
|
300
270
|
```ts
|
|
301
|
-
import routeFn from 'ziggy-js';
|
|
271
|
+
import { route as routeFn } from 'ziggy-js';
|
|
302
272
|
|
|
303
273
|
declare global {
|
|
304
274
|
var route: typeof routeFn;
|
|
305
275
|
}
|
|
306
276
|
```
|
|
307
277
|
|
|
308
|
-
If you don't have Ziggy's NPM package installed, add the following to your `jsconfig.json` or `tsconfig.json` to load Ziggy's types from
|
|
278
|
+
If you don't have Ziggy's NPM package installed, add the following to your `jsconfig.json` or `tsconfig.json` to load Ziggy's types from your vendor directory:
|
|
309
279
|
|
|
310
280
|
```json
|
|
311
281
|
{
|
|
@@ -317,175 +287,161 @@ If you don't have Ziggy's NPM package installed, add the following to your `jsco
|
|
|
317
287
|
}
|
|
318
288
|
```
|
|
319
289
|
|
|
320
|
-
##
|
|
290
|
+
## JavaScript frameworks
|
|
291
|
+
|
|
292
|
+
> [!NOTE]
|
|
293
|
+
> Many applications don't need the additional setup described here—the `@routes` Blade directive makes Ziggy's `route()` function and config available globally, including within bundled JavaScript files.
|
|
321
294
|
|
|
322
|
-
|
|
295
|
+
If you are not using the `@routes` Blade directive, you can import Ziggy's `route()` function and configuration directly into JavaScript/TypeScript files.
|
|
323
296
|
|
|
324
|
-
|
|
297
|
+
### Generating and importing Ziggy's configuration
|
|
325
298
|
|
|
326
|
-
|
|
299
|
+
Ziggy provides an Artisan command to output its config and routes to a file:
|
|
300
|
+
|
|
301
|
+
```bash
|
|
302
|
+
php artisan ziggy:generate
|
|
303
|
+
```
|
|
304
|
+
|
|
305
|
+
This command places your configuration in `resources/js/ziggy.js` by default, but you can customize this path by passing an argument to the Artisan command or setting the `ziggy.output.path` config value.
|
|
306
|
+
|
|
307
|
+
The file `ziggy:generate` creates looks something like this:
|
|
327
308
|
|
|
328
309
|
```js
|
|
329
|
-
// ziggy.js
|
|
310
|
+
// resources/js/ziggy.js
|
|
330
311
|
|
|
331
312
|
const Ziggy = {
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
313
|
+
url: 'https://ziggy.test',
|
|
314
|
+
port: null,
|
|
315
|
+
routes: {
|
|
316
|
+
home: {
|
|
317
|
+
uri: '/',
|
|
318
|
+
methods: [ 'GET', 'HEAD'],
|
|
319
|
+
domain: null,
|
|
320
|
+
},
|
|
321
|
+
login: {
|
|
322
|
+
uri: 'login',
|
|
323
|
+
methods: ['GET', 'HEAD'],
|
|
324
|
+
domain: null,
|
|
325
|
+
},
|
|
326
|
+
},
|
|
335
327
|
};
|
|
336
328
|
|
|
337
329
|
export { Ziggy };
|
|
338
330
|
```
|
|
339
331
|
|
|
340
|
-
|
|
332
|
+
### Importing the `route()` function
|
|
341
333
|
|
|
342
|
-
|
|
343
|
-
// vite.config.js
|
|
344
|
-
export default defineConfig({
|
|
345
|
-
resolve: {
|
|
346
|
-
alias: {
|
|
347
|
-
ziggy: 'vendor/tightenco/ziggy/dist',
|
|
348
|
-
// 'vendor/tightenco/ziggy/dist/vue.es.js' if using the Vue plugin
|
|
349
|
-
},
|
|
350
|
-
},
|
|
351
|
-
});
|
|
352
|
-
```
|
|
334
|
+
You can import Ziggy like any other JavaScript library. Without the `@routes` Blade directive Ziggy's config is not available globally, so it must be passed to the `route()` function manually:
|
|
353
335
|
|
|
354
336
|
```js
|
|
355
|
-
|
|
337
|
+
import { route } from '../../vendor/tightenco/ziggy';
|
|
338
|
+
import { Ziggy } from './ziggy.js';
|
|
356
339
|
|
|
357
|
-
|
|
358
|
-
|
|
340
|
+
route('home', undefined, undefined, Ziggy);
|
|
341
|
+
```
|
|
359
342
|
|
|
360
|
-
|
|
361
|
-
ziggy: path.resolve('vendor/tightenco/ziggy/dist'),
|
|
362
|
-
// 'vendor/tightenco/ziggy/dist/vue' if using the Vue plugin
|
|
363
|
-
});
|
|
343
|
+
To simplify importing the `route()` function, you can create an alias to the vendor path:
|
|
364
344
|
|
|
365
|
-
|
|
366
|
-
|
|
345
|
+
```js
|
|
346
|
+
// vite.config.js
|
|
367
347
|
|
|
368
|
-
|
|
348
|
+
export default defineConfig({
|
|
369
349
|
resolve: {
|
|
370
350
|
alias: {
|
|
371
|
-
ziggy: path.resolve('vendor/tightenco/ziggy
|
|
351
|
+
'ziggy-js': path.resolve('vendor/tightenco/ziggy'),
|
|
372
352
|
},
|
|
373
353
|
},
|
|
374
354
|
});
|
|
375
355
|
```
|
|
376
356
|
|
|
377
|
-
|
|
357
|
+
Now your imports can be shortened to:
|
|
378
358
|
|
|
379
359
|
```js
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
import route from 'ziggy';
|
|
383
|
-
import { Ziggy } from './ziggy';
|
|
384
|
-
|
|
385
|
-
// ...
|
|
386
|
-
|
|
387
|
-
route('home', undefined, undefined, Ziggy);
|
|
360
|
+
import { route } from 'ziggy-js';
|
|
388
361
|
```
|
|
389
362
|
|
|
390
|
-
|
|
363
|
+
### Vue
|
|
391
364
|
|
|
392
365
|
Ziggy includes a Vue plugin to make it easy to use the `route()` helper throughout your Vue app:
|
|
393
366
|
|
|
394
367
|
```js
|
|
395
368
|
import { createApp } from 'vue';
|
|
396
|
-
import { ZiggyVue } from 'ziggy';
|
|
397
|
-
import
|
|
398
|
-
import App from './App';
|
|
369
|
+
import { ZiggyVue } from 'ziggy-js';
|
|
370
|
+
import App from './App.vue';
|
|
399
371
|
|
|
400
|
-
createApp(App).use(ZiggyVue
|
|
372
|
+
createApp(App).use(ZiggyVue);
|
|
373
|
+
```
|
|
401
374
|
|
|
402
|
-
|
|
403
|
-
import Vue from 'vue'
|
|
404
|
-
import { ZiggyVue } from 'ziggy';
|
|
405
|
-
import { Ziggy } from './ziggy';
|
|
375
|
+
Now you can use the `route()` function anywhere in your Vue components and templates:
|
|
406
376
|
|
|
407
|
-
|
|
377
|
+
```vue
|
|
378
|
+
<a class="nav-link" :href="route('home')">Home</a>
|
|
408
379
|
```
|
|
409
380
|
|
|
410
|
-
If you
|
|
381
|
+
If you are not using the `@routes` Blade directive, import Ziggy's configuration too and pass it to `.use()`:
|
|
411
382
|
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
383
|
+
```js
|
|
384
|
+
import { createApp } from 'vue';
|
|
385
|
+
import { ZiggyVue } from 'ziggy-js';
|
|
386
|
+
import { Ziggy } from './ziggy.js';
|
|
387
|
+
import App from './App.vue';
|
|
415
388
|
|
|
416
|
-
|
|
417
|
-
<a class="nav-link" :href="route('home')">Home</a>
|
|
389
|
+
createApp(App).use(ZiggyVue, Ziggy);
|
|
418
390
|
```
|
|
419
391
|
|
|
420
|
-
|
|
392
|
+
### React
|
|
421
393
|
|
|
422
394
|
Ziggy includes a `useRoute()` hook to make it easy to use the `route()` helper in your React app:
|
|
423
395
|
|
|
424
396
|
```jsx
|
|
425
|
-
// PostsLink.js
|
|
426
397
|
import React from 'react';
|
|
427
398
|
import { useRoute } from 'ziggy-js';
|
|
428
|
-
import { Ziggy } from './ziggy';
|
|
429
399
|
|
|
430
400
|
export default function PostsLink() {
|
|
431
|
-
const route = useRoute(
|
|
401
|
+
const route = useRoute();
|
|
432
402
|
|
|
433
403
|
return <a href={route('posts.index')}>Posts</a>;
|
|
434
404
|
}
|
|
435
405
|
```
|
|
436
406
|
|
|
437
|
-
If you
|
|
438
|
-
|
|
439
|
-
```js
|
|
440
|
-
// app.js
|
|
441
|
-
import { Ziggy } from './ziggy';
|
|
442
|
-
globalThis.Ziggy = Ziggy;
|
|
443
|
-
```
|
|
407
|
+
If you are not using the `@routes` Blade directive, import Ziggy's configuration too and pass it to `useRoute()`:
|
|
444
408
|
|
|
445
409
|
```jsx
|
|
446
|
-
// PostsLink.js
|
|
447
410
|
import React from 'react';
|
|
448
411
|
import { useRoute } from 'ziggy-js';
|
|
412
|
+
import { Ziggy } from './ziggy.js';
|
|
449
413
|
|
|
450
414
|
export default function PostsLink() {
|
|
451
|
-
const route = useRoute();
|
|
415
|
+
const route = useRoute(Ziggy);
|
|
452
416
|
|
|
453
417
|
return <a href={route('posts.index')}>Posts</a>;
|
|
454
418
|
}
|
|
455
419
|
```
|
|
456
420
|
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
#### SPAs or separate repos
|
|
460
|
-
|
|
461
|
-
Ziggy's `route()` helper function is also available as an NPM package, for use in JavaScript projects managed separately from their Laravel backend (i.e. without Composer or a `vendor` directory). You can install the NPM package with `npm install ziggy-js`.
|
|
462
|
-
|
|
463
|
-
To make your routes available on the frontend for this function to use, you can either run `php artisan ziggy:generate` and add the generated routes file to your project, or you can return Ziggy's config as JSON from an endpoint in your Laravel API (see [Retrieving Ziggy's routes and config from an API endpoint](#retrieving-ziggys-routes-and-config-from-an-api-endpoint) below for an example of how to set this up).
|
|
464
|
-
|
|
465
|
-
Then, import and use Ziggy as above:
|
|
421
|
+
You can also make the `Ziggy` config object available globally, so you can call `useRoute()` without passing Ziggy's configuration to it every time:
|
|
466
422
|
|
|
467
423
|
```js
|
|
468
424
|
// app.js
|
|
425
|
+
import { Ziggy } from './ziggy.js';
|
|
426
|
+
globalThis.Ziggy = Ziggy;
|
|
427
|
+
```
|
|
469
428
|
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
import { Ziggy } from './ziggy';
|
|
473
|
-
// or...
|
|
474
|
-
const response = await fetch('/api/ziggy');
|
|
475
|
-
const Ziggy = await response.json();
|
|
429
|
+
### SPAs or separate repos
|
|
476
430
|
|
|
477
|
-
|
|
431
|
+
Ziggy's `route()` function is available as an NPM package, for use in JavaScript projects managed separately from their Laravel backend (i.e. without Composer or a `vendor` directory). You can install the NPM package with `npm install ziggy-js`.
|
|
478
432
|
|
|
479
|
-
|
|
480
|
-
```
|
|
433
|
+
To make your routes available on the frontend for this function to use, you can either run `php artisan ziggy:generate` and add the generated config file to your frontend project, or you can return Ziggy's config as JSON from an endpoint in your Laravel API (see [Retrieving Ziggy's config from an API endpoint](#retrieving-ziggys-routes-from-an-api-endpoint) below for an example of how to set this up).
|
|
481
434
|
|
|
482
435
|
## Filtering Routes
|
|
483
436
|
|
|
484
|
-
Ziggy supports filtering the routes it
|
|
437
|
+
Ziggy supports filtering the list of routes it outputs, which is useful if you have certain routes that you don't want to be included and visible in your HTML source.
|
|
485
438
|
|
|
486
|
-
|
|
439
|
+
> [!IMPORTANT]
|
|
440
|
+
> Hiding routes from Ziggy's output is not a replacement for thorough authentication and authorization. Routes that should not be accessibly publicly should be protected by authentication whether they're filtered out of Ziggy's output or not.
|
|
487
441
|
|
|
488
|
-
|
|
442
|
+
### Including/excluding routes
|
|
443
|
+
|
|
444
|
+
To set up route filtering, create a config file in your Laravel app at `config/ziggy.php` and add **either** an `only` or `except` key containing an array of route name patterns.
|
|
489
445
|
|
|
490
446
|
> Note: You have to choose one or the other. Setting both `only` and `except` will disable filtering altogether and return all named routes.
|
|
491
447
|
|
|
@@ -497,7 +453,7 @@ return [
|
|
|
497
453
|
];
|
|
498
454
|
```
|
|
499
455
|
|
|
500
|
-
You can
|
|
456
|
+
You can use asterisks as wildcards in route filters. In the example below, `admin.*` will exclude routes named `admin.login`, `admin.register`, etc.:
|
|
501
457
|
|
|
502
458
|
```php
|
|
503
459
|
// config/ziggy.php
|
|
@@ -507,7 +463,7 @@ return [
|
|
|
507
463
|
];
|
|
508
464
|
```
|
|
509
465
|
|
|
510
|
-
|
|
466
|
+
### Filtering with groups
|
|
511
467
|
|
|
512
468
|
You can also define groups of routes that you want make available in different places in your app, using a `groups` key in your config file:
|
|
513
469
|
|
|
@@ -542,69 +498,42 @@ To expose multiple groups you can pass an array of group names:
|
|
|
542
498
|
|
|
543
499
|
## Other
|
|
544
500
|
|
|
545
|
-
|
|
501
|
+
### TLS/SSL termination and trusted proxies
|
|
546
502
|
|
|
547
503
|
<!-- Or: What to do if your app is served over `https` but Ziggy's `route()` helper generates `http` URLs -->
|
|
548
504
|
|
|
549
|
-
If your application is using [TLS/SSL termination](https://en.wikipedia.org/wiki/TLS_termination_proxy) or is behind a load balancer or proxy, or if it's hosted on a service that is, Ziggy may generate URLs with a scheme of `http` instead of `https`, even if your app URL uses `https`. To
|
|
505
|
+
If your application is using [TLS/SSL termination](https://en.wikipedia.org/wiki/TLS_termination_proxy) or is behind a load balancer or proxy, or if it's hosted on a service that is, Ziggy may generate URLs with a scheme of `http` instead of `https`, even if your app URL uses `https`. To fix this, set up your Laravel app's trusted proxies according to the documentation on [Configuring Trusted Proxies](https://laravel.com/docs/requests#configuring-trusted-proxies).
|
|
550
506
|
|
|
551
|
-
|
|
507
|
+
### Using `@routes` with a Content Security Policy
|
|
552
508
|
|
|
553
|
-
A [Content Security Policy](https://developer.mozilla.org/en-US/docs/Web/HTTP/CSP) (CSP) may block inline scripts, including those output by Ziggy's `@routes` Blade directive. If you have a CSP and are using a nonce to flag safe inline scripts, you can pass the nonce
|
|
509
|
+
A [Content Security Policy](https://developer.mozilla.org/en-US/docs/Web/HTTP/CSP) (CSP) may block inline scripts, including those output by Ziggy's `@routes` Blade directive. If you have a CSP and are using a nonce to flag safe inline scripts, you can pass the nonce to the `@routes` directive and it will be added to Ziggy's script tag:
|
|
554
510
|
|
|
555
511
|
```php
|
|
556
|
-
// PHP ^8.0
|
|
557
512
|
@routes(nonce: 'your-nonce-here')
|
|
558
|
-
|
|
559
|
-
// PHP <=7.4
|
|
560
|
-
@routes(null, 'your-nonce-here')
|
|
561
513
|
```
|
|
562
514
|
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
If you only want to use the `@routes` directive to make your app's routes available in JavaScript, but don't need the `route()` helper function, set the `skip-route-function` config value to `true`:
|
|
566
|
-
|
|
567
|
-
```php
|
|
568
|
-
// config/ziggy.php
|
|
515
|
+
### Disabling the `route()` helper
|
|
569
516
|
|
|
570
|
-
|
|
571
|
-
'skip-route-function' => true,
|
|
572
|
-
];
|
|
573
|
-
```
|
|
517
|
+
If you only want to use the `@routes` directive to make Ziggy's configuration available in JavaScript, but don't need the `route()` helper function, set the `ziggy.skip-route-function` config to `true`.
|
|
574
518
|
|
|
575
|
-
|
|
519
|
+
### Retrieving Ziggy's config from an API endpoint
|
|
576
520
|
|
|
577
|
-
|
|
521
|
+
If you need to retrieve Ziggy's config from your Laravel backend over the network, you can create a route that looks something like this:
|
|
578
522
|
|
|
579
523
|
```php
|
|
580
524
|
// routes/api.php
|
|
581
525
|
|
|
582
|
-
use
|
|
526
|
+
use Tighten\Ziggy\Ziggy;
|
|
583
527
|
|
|
584
528
|
Route::get('api/ziggy', fn () => response()->json(new Ziggy));
|
|
585
529
|
```
|
|
586
530
|
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
```js
|
|
590
|
-
// app.js
|
|
591
|
-
|
|
592
|
-
import route from 'ziggy-js';
|
|
593
|
-
|
|
594
|
-
const response = await fetch('/api/ziggy');
|
|
595
|
-
const Ziggy = await response.toJson();
|
|
596
|
-
|
|
597
|
-
// ...
|
|
598
|
-
|
|
599
|
-
route('home', undefined, undefined, Ziggy);
|
|
600
|
-
```
|
|
601
|
-
|
|
602
|
-
#### Re-generating the routes file when your app routes change
|
|
531
|
+
### Re-generating the routes file when your app routes change
|
|
603
532
|
|
|
604
|
-
If you
|
|
533
|
+
If you are generating your Ziggy config as a file by running `php artisan ziggy:generate`, you may want to re-run that command when your app's route files change. The example below is a Laravel Mix plugin, but similar functionality could be achieved without Mix. Huge thanks to [Nuno Rodrigues](https://github.com/nacr) for [the idea and a sample implementation](https://github.com/tighten/ziggy/issues/321#issuecomment-689150082). See [#655 for a Vite example](https://github.com/tighten/ziggy/pull/655/files#diff-4aeb78f813e14842fcf95bdace9ced23b8a6eed60b23c165eaa52e8db2f97b61).
|
|
605
534
|
|
|
606
535
|
<details>
|
|
607
|
-
<summary>
|
|
536
|
+
<summary>Laravel Mix plugin example</summary>
|
|
608
537
|
<p></p>
|
|
609
538
|
|
|
610
539
|
```js
|
|
@@ -664,4 +593,4 @@ Please review our [security policy](../../security/policy) on how to report secu
|
|
|
664
593
|
|
|
665
594
|
## License
|
|
666
595
|
|
|
667
|
-
Ziggy is open
|
|
596
|
+
Ziggy is open-source software released under the MIT license. See [LICENSE](LICENSE) for more information.
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{parse as t,stringify as r}from"qs";function n(t,r){for(var n=0;n<r.length;n++){var e=r[n];e.enumerable=e.enumerable||!1,e.configurable=!0,"value"in e&&(e.writable=!0),Object.defineProperty(t,"symbol"==typeof(i=function(t,r){if("object"!=typeof t||null===t)return t;var n=t[Symbol.toPrimitive];if(void 0!==n){var e=n.call(t,"string");if("object"!=typeof e)return e;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(t)}(e.key))?i:String(i),e)}var i}function e(t,r,e){return r&&n(t.prototype,r),e&&n(t,e),Object.defineProperty(t,"prototype",{writable:!1}),t}function i(){return i=Object.assign?Object.assign.bind():function(t){for(var r=1;r<arguments.length;r++){var n=arguments[r];for(var e in n)Object.prototype.hasOwnProperty.call(n,e)&&(t[e]=n[e])}return t},i.apply(this,arguments)}function u(t){return u=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(t){return t.__proto__||Object.getPrototypeOf(t)},u(t)}function o(t,r){return o=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(t,r){return t.__proto__=r,t},o(t,r)}function f(t,r,n){return f=function(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){})),!0}catch(t){return!1}}()?Reflect.construct.bind():function(t,r,n){var e=[null];e.push.apply(e,r);var i=new(Function.bind.apply(t,e));return n&&o(i,n.prototype),i},f.apply(null,arguments)}function c(t){var r="function"==typeof Map?new Map:void 0;return c=function(t){if(null===t||!function(t){try{return-1!==Function.toString.call(t).indexOf("[native code]")}catch(r){return"function"==typeof t}}(t))return t;if("function"!=typeof t)throw new TypeError("Super expression must either be null or a function");if(void 0!==r){if(r.has(t))return r.get(t);r.set(t,n)}function n(){return f(t,arguments,u(this).constructor)}return n.prototype=Object.create(t.prototype,{constructor:{value:n,enumerable:!1,writable:!0,configurable:!0}}),o(n,t)},c(t)}var a=/*#__PURE__*/function(){function r(t,r,n){var e,i;this.name=t,this.definition=r,this.bindings=null!=(e=r.bindings)?e:{},this.wheres=null!=(i=r.wheres)?i:{},this.config=n}var n=r.prototype;return n.matchesUrl=function(r){var n=this;if(!this.definition.methods.includes("GET"))return!1;var e=this.template.replace(/(\/?){([^}?]*)(\??)}/g,function(t,r,e,i){var u,o="(?<"+e+">"+((null==(u=n.wheres[e])?void 0:u.replace(/(^\^)|(\$$)/g,""))||"[^/?]+")+")";return i?"("+r+o+")?":""+r+o}).replace(/^\w+:\/\//,""),i=r.replace(/^\w+:\/\//,"").split("?"),u=i[0],o=i[1],f=new RegExp("^"+e+"/?$").exec(decodeURI(u));if(f){for(var c in f.groups)f.groups[c]="string"==typeof f.groups[c]?decodeURIComponent(f.groups[c]):f.groups[c];return{params:f.groups,query:t(o)}}return!1},n.compile=function(t){var r=this;return this.parameterSegments.length?this.template.replace(/{([^}?]+)(\??)}/g,function(n,e,i){var u,o;if(!i&&[null,void 0].includes(t[e]))throw new Error("Ziggy error: '"+e+"' parameter is required for route '"+r.name+"'.");if(r.wheres[e]&&!new RegExp("^"+(i?"("+r.wheres[e]+")?":r.wheres[e])+"$").test(null!=(o=t[e])?o:""))throw new Error("Ziggy error: '"+e+"' parameter does not match required format '"+r.wheres[e]+"' for route '"+r.name+"'.");return encodeURI(null!=(u=t[e])?u:"").replace(/%7C/g,"|").replace(/%25/g,"%").replace(/\$/g,"%24")}).replace(this.origin+"//",this.origin+"/").replace(/\/+$/,""):this.template},e(r,[{key:"template",get:function(){var t=(this.origin+"/"+this.definition.uri).replace(/\/+$/,"");return""===t?"/":t}},{key:"origin",get:function(){return this.config.absolute?this.definition.domain?""+this.config.url.match(/^\w+:\/\//)[0]+this.definition.domain+(this.config.port?":"+this.config.port:""):this.config.url:""}},{key:"parameterSegments",get:function(){var t,r;return null!=(t=null==(r=this.template.match(/{[^}?]+\??}/g))?void 0:r.map(function(t){return{name:t.replace(/{|\??}/g,""),required:!/\?}$/.test(t)}}))?t:[]}}]),r}(),s=/*#__PURE__*/function(t){var n,u;function f(r,n,e,u){var o;if(void 0===e&&(e=!0),(o=t.call(this)||this).t=null!=u?u:"undefined"!=typeof Ziggy?Ziggy:null==globalThis?void 0:globalThis.Ziggy,o.t=i({},o.t,{absolute:e}),r){if(!o.t.routes[r])throw new Error("Ziggy error: route '"+r+"' is not in the route list.");o.i=new a(r,o.t.routes[r],o.t),o.u=o.o(n)}return o}u=t,(n=f).prototype=Object.create(u.prototype),n.prototype.constructor=n,o(n,u);var c=f.prototype;return c.toString=function(){var t=this,n=Object.keys(this.u).filter(function(r){return!t.i.parameterSegments.some(function(t){return t.name===r})}).filter(function(t){return"_query"!==t}).reduce(function(r,n){var e;return i({},r,((e={})[n]=t.u[n],e))},{});return this.i.compile(this.u)+r(i({},n,this.u._query),{addQueryPrefix:!0,arrayFormat:"indices",encodeValuesOnly:!0,skipNulls:!0,encoder:function(t,r){return"boolean"==typeof t?Number(t):r(t)}})},c.l=function(t){var r=this;t?this.t.absolute&&t.startsWith("/")&&(t=this.h().host+t):t=this.v();var n={},e=Object.entries(this.t.routes).find(function(e){return n=new a(e[0],e[1],r.t).matchesUrl(t)})||[void 0,void 0];return i({name:e[0]},n,{route:e[1]})},c.v=function(){var t=this.h(),r=t.pathname,n=t.search;return(this.t.absolute?t.host+r:r.replace(this.t.url.replace(/^\w*:\/\/[^/]+/,""),"").replace(/^\/+/,"/"))+n},c.current=function(t,r){var n=this.l(),e=n.name,u=n.params,o=n.query,f=n.route;if(!t)return e;var c=new RegExp("^"+t.replace(/\./g,"\\.").replace(/\*/g,".*")+"$").test(e);if([null,void 0].includes(r)||!c)return c;var s=new a(e,f,this.t);r=this.o(r,s);var l=i({},u,o);return!(!Object.values(r).every(function(t){return!t})||Object.values(l).some(function(t){return void 0!==t}))||Object.entries(r).every(function(t){return l[t[0]]==t[1]})},c.h=function(){var t,r,n,e,i,u,o="undefined"!=typeof window?window.location:{},f=o.host,c=o.pathname,a=o.search;return{host:null!=(t=null==(r=this.t.location)?void 0:r.host)?t:void 0===f?"":f,pathname:null!=(n=null==(e=this.t.location)?void 0:e.pathname)?n:void 0===c?"":c,search:null!=(i=null==(u=this.t.location)?void 0:u.search)?i:void 0===a?"":a}},c.has=function(t){return Object.keys(this.t.routes).includes(t)},c.o=function(t,r){var n=this;void 0===t&&(t={}),void 0===r&&(r=this.i),null!=t||(t={}),t=["string","number"].includes(typeof t)?[t]:t;var e=r.parameterSegments.filter(function(t){return!n.t.defaults[t.name]});if(Array.isArray(t))t=t.reduce(function(t,r,n){var u,o;return i({},t,e[n]?((u={})[e[n].name]=r,u):"object"==typeof r?r:((o={})[r]="",o))},{});else if(1===e.length&&!t[e[0].name]&&(t.hasOwnProperty(Object.values(r.bindings)[0])||t.hasOwnProperty("id"))){var u;(u={})[e[0].name]=t,t=u}return i({},this.p(r),this.m(t,r))},c.p=function(t){var r=this;return t.parameterSegments.filter(function(t){return r.t.defaults[t.name]}).reduce(function(t,n,e){var u,o=n.name;return i({},t,((u={})[o]=r.t.defaults[o],u))},{})},c.m=function(t,r){var n=r.bindings,e=r.parameterSegments;return Object.entries(t).reduce(function(t,r){var u,o,f=r[0],c=r[1];if(!c||"object"!=typeof c||Array.isArray(c)||!e.some(function(t){return t.name===f}))return i({},t,((o={})[f]=c,o));if(!c.hasOwnProperty(n[f])){if(!c.hasOwnProperty("id"))throw new Error("Ziggy error: object passed as '"+f+"' parameter is missing route model binding key '"+n[f]+"'.");n[f]="id"}return i({},t,((u={})[f]=c[n[f]],u))},{})},c.valueOf=function(){return this.toString()},e(f,[{key:"params",get:function(){var t=this.l();return i({},t.params,t.query)}}]),f}(/*#__PURE__*/c(String));function l(t,r,n,e){var i=new s(t,r,n,e);return t?i.toString():i}var h={install:function(t,r){var n=function(t,n,e,i){return void 0===i&&(i=r),l(t,n,e,i)};t.config.globalProperties.route=n,parseInt(t.version)>2&&t.provide("route",n)}};function v(t){if(!t&&!globalThis.Ziggy&&"undefined"==typeof Ziggy)throw new Error("Ziggy error: missing configuration. Ensure that a `Ziggy` variable is defined globally or pass a config object into the useRoute hook.");return function(r,n,e,i){return void 0===i&&(i=t),l(r,n,e,i)}}export{h as ZiggyVue,l as route,v as useRoute};
|
package/dist/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
|
|
1
|
+
import{parse as t,stringify as r}from"qs";function e(){return e=Object.assign?Object.assign.bind():function(t){for(var r=1;r<arguments.length;r++){var e=arguments[r];for(var i in e)Object.prototype.hasOwnProperty.call(e,i)&&(t[i]=e[i])}return t},e.apply(this,arguments)}class i{constructor(t,r,e){var i,n;this.name=t,this.definition=r,this.bindings=null!=(i=r.bindings)?i:{},this.wheres=null!=(n=r.wheres)?n:{},this.config=e}get template(){const t=`${this.origin}/${this.definition.uri}`.replace(/\/+$/,"");return""===t?"/":t}get origin(){return this.config.absolute?this.definition.domain?`${this.config.url.match(/^\w+:\/\//)[0]}${this.definition.domain}${this.config.port?`:${this.config.port}`:""}`:this.config.url:""}get parameterSegments(){var t,r;return null!=(t=null==(r=this.template.match(/{[^}?]+\??}/g))?void 0:r.map(t=>({name:t.replace(/{|\??}/g,""),required:!/\?}$/.test(t)})))?t:[]}matchesUrl(r){if(!this.definition.methods.includes("GET"))return!1;const e=this.template.replace(/(\/?){([^}?]*)(\??)}/g,(t,r,e,i)=>{var n;const s=`(?<${e}>${(null==(n=this.wheres[e])?void 0:n.replace(/(^\^)|(\$$)/g,""))||"[^/?]+"})`;return i?`(${r}${s})?`:`${r}${s}`}).replace(/^\w+:\/\//,""),[i,n]=r.replace(/^\w+:\/\//,"").split("?"),s=new RegExp(`^${e}/?$`).exec(decodeURI(i));if(s){for(const t in s.groups)s.groups[t]="string"==typeof s.groups[t]?decodeURIComponent(s.groups[t]):s.groups[t];return{params:s.groups,query:t(n)}}return!1}compile(t){return this.parameterSegments.length?this.template.replace(/{([^}?]+)(\??)}/g,(r,e,i)=>{var n,s;if(!i&&[null,void 0].includes(t[e]))throw new Error(`Ziggy error: '${e}' parameter is required for route '${this.name}'.`);if(this.wheres[e]&&!new RegExp(`^${i?`(${this.wheres[e]})?`:this.wheres[e]}$`).test(null!=(s=t[e])?s:""))throw new Error(`Ziggy error: '${e}' parameter does not match required format '${this.wheres[e]}' for route '${this.name}'.`);return encodeURI(null!=(n=t[e])?n:"").replace(/%7C/g,"|").replace(/%25/g,"%").replace(/\$/g,"%24")}).replace(`${this.origin}//`,`${this.origin}/`).replace(/\/+$/,""):this.template}}class n extends String{constructor(t,r,n=!0,s){if(super(),this.t=null!=s?s:"undefined"!=typeof Ziggy?Ziggy:null==globalThis?void 0:globalThis.Ziggy,this.t=e({},this.t,{absolute:n}),t){if(!this.t.routes[t])throw new Error(`Ziggy error: route '${t}' is not in the route list.`);this.i=new i(t,this.t.routes[t],this.t),this.o=this.h(r)}}toString(){const t=Object.keys(this.o).filter(t=>!this.i.parameterSegments.some(({name:r})=>r===t)).filter(t=>"_query"!==t).reduce((t,r)=>e({},t,{[r]:this.o[r]}),{});return this.i.compile(this.o)+r(e({},t,this.o._query),{addQueryPrefix:!0,arrayFormat:"indices",encodeValuesOnly:!0,skipNulls:!0,encoder:(t,r)=>"boolean"==typeof t?Number(t):r(t)})}u(t){t?this.t.absolute&&t.startsWith("/")&&(t=this.l().host+t):t=this.m();let r={};const[n,s]=Object.entries(this.t.routes).find(([e,n])=>r=new i(e,n,this.t).matchesUrl(t))||[void 0,void 0];return e({name:n},r,{route:s})}m(){const{host:t,pathname:r,search:e}=this.l();return(this.t.absolute?t+r:r.replace(this.t.url.replace(/^\w*:\/\/[^/]+/,""),"").replace(/^\/+/,"/"))+e}current(t,r){const{name:n,params:s,query:o,route:h}=this.u();if(!t)return n;const u=new RegExp(`^${t.replace(/\./g,"\\.").replace(/\*/g,".*")}$`).test(n);if([null,void 0].includes(r)||!u)return u;const a=new i(n,h,this.t);r=this.h(r,a);const l=e({},s,o);return!(!Object.values(r).every(t=>!t)||Object.values(l).some(t=>void 0!==t))||Object.entries(r).every(([t,r])=>l[t]==r)}l(){var t,r,e,i,n,s;const{host:o="",pathname:h="",search:u=""}="undefined"!=typeof window?window.location:{};return{host:null!=(t=null==(r=this.t.location)?void 0:r.host)?t:o,pathname:null!=(e=null==(i=this.t.location)?void 0:i.pathname)?e:h,search:null!=(n=null==(s=this.t.location)?void 0:s.search)?n:u}}get params(){const{params:t,query:r}=this.u();return e({},t,r)}has(t){return Object.keys(this.t.routes).includes(t)}h(t={},r=this.i){null!=t||(t={}),t=["string","number"].includes(typeof t)?[t]:t;const i=r.parameterSegments.filter(({name:t})=>!this.t.defaults[t]);return Array.isArray(t)?t=t.reduce((t,r,n)=>e({},t,i[n]?{[i[n].name]:r}:"object"==typeof r?r:{[r]:""}),{}):1!==i.length||t[i[0].name]||!t.hasOwnProperty(Object.values(r.bindings)[0])&&!t.hasOwnProperty("id")||(t={[i[0].name]:t}),e({},this.$(r),this.p(t,r))}$(t){return t.parameterSegments.filter(({name:t})=>this.t.defaults[t]).reduce((t,{name:r},i)=>e({},t,{[r]:this.t.defaults[r]}),{})}p(t,{bindings:r,parameterSegments:i}){return Object.entries(t).reduce((t,[n,s])=>{if(!s||"object"!=typeof s||Array.isArray(s)||!i.some(({name:t})=>t===n))return e({},t,{[n]:s});if(!s.hasOwnProperty(r[n])){if(!s.hasOwnProperty("id"))throw new Error(`Ziggy error: object passed as '${n}' parameter is missing route model binding key '${r[n]}'.`);r[n]="id"}return e({},t,{[n]:s[r[n]]})},{})}valueOf(){return this.toString()}}function s(t,r,e,i){const s=new n(t,r,e,i);return t?s.toString():s}const o={install(t,r){const e=(t,e,i,n=r)=>s(t,e,i,n);t.config.globalProperties.route=e,parseInt(t.version)>2&&t.provide("route",e)}};function h(t){if(!t&&!globalThis.Ziggy&&"undefined"==typeof Ziggy)throw new Error("Ziggy error: missing configuration. Ensure that a `Ziggy` variable is defined globally or pass a config object into the useRoute hook.");return(r,e,i,n=t)=>s(r,e,i,n)}export{o as ZiggyVue,s as route,h as useRoute};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "ziggy-js",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "2.0.0-beta.1",
|
|
4
4
|
"description": "Use your Laravel named routes in JavaScript.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"laravel",
|
|
@@ -10,6 +10,10 @@
|
|
|
10
10
|
"homepage": "https://github.com/tighten/ziggy",
|
|
11
11
|
"bugs": "https://github.com/tighten/ziggy/issues",
|
|
12
12
|
"license": "MIT",
|
|
13
|
+
"repository": {
|
|
14
|
+
"type": "git",
|
|
15
|
+
"url": "git+https://github.com/tighten/ziggy.git"
|
|
16
|
+
},
|
|
13
17
|
"authors": [
|
|
14
18
|
{
|
|
15
19
|
"name": "Daniel Coulbourne",
|
|
@@ -28,28 +32,20 @@
|
|
|
28
32
|
"src/js/index.d.ts",
|
|
29
33
|
"dist"
|
|
30
34
|
],
|
|
31
|
-
"
|
|
32
|
-
"
|
|
33
|
-
"
|
|
34
|
-
"
|
|
35
|
-
"
|
|
36
|
-
"module": "dist/index.m.js",
|
|
37
|
-
"esmodule": "dist/index.es.js",
|
|
38
|
-
"types": "src/js/index.d.ts",
|
|
39
|
-
"repository": {
|
|
40
|
-
"type": "git",
|
|
41
|
-
"url": "https://github.com/tighten/ziggy.git"
|
|
42
|
-
},
|
|
35
|
+
"type": "module",
|
|
36
|
+
"source": "./src/js/index.js",
|
|
37
|
+
"exports": "./dist/ziggy.js",
|
|
38
|
+
"module": "./dist/ziggy.esm.js",
|
|
39
|
+
"types": "./src/js/index.d.ts",
|
|
43
40
|
"scripts": {
|
|
44
|
-
"build": "
|
|
45
|
-
"build:
|
|
46
|
-
"build:
|
|
47
|
-
"
|
|
48
|
-
"
|
|
49
|
-
"
|
|
50
|
-
"
|
|
51
|
-
"
|
|
52
|
-
"prepublishOnly": "npm run build:npm && npm run build:npm:vue && npm run build:npm:react"
|
|
41
|
+
"build": "npm run build:esm && npm run build:umd",
|
|
42
|
+
"build:esm": "microbundle -i ./src/js/index.js -o ./dist/index.js --format modern,esm --no-sourcemap --external none --no-generateTypes",
|
|
43
|
+
"build:npm": "microbundle -i ./src/js/index.js -o ./dist/index.js --format modern,esm --no-sourcemap --no-generateTypes",
|
|
44
|
+
"build:umd": "microbundle -i ./src/js/browser.js -o ./dist/route.js --format umd --no-sourcemap --external none --no-generateTypes",
|
|
45
|
+
"test": "vitest",
|
|
46
|
+
"typecheck": "vitest typecheck",
|
|
47
|
+
"format": "prettier . --write",
|
|
48
|
+
"prepublishOnly": "rm -r ./dist/* && npm run build:npm"
|
|
53
49
|
},
|
|
54
50
|
"mangle": {
|
|
55
51
|
"regex": "^_(?!query)"
|
|
@@ -58,10 +54,15 @@
|
|
|
58
54
|
"qs": "~6.9.7"
|
|
59
55
|
},
|
|
60
56
|
"devDependencies": {
|
|
61
|
-
"
|
|
62
|
-
"jest": "^29.0.3",
|
|
63
|
-
"jest-environment-jsdom": "^29.0.3",
|
|
57
|
+
"jsdom": "^22.1.0",
|
|
64
58
|
"microbundle": "^0.15.1",
|
|
65
|
-
"
|
|
59
|
+
"prettier": "^3.0.3",
|
|
60
|
+
"typescript": "^5.2.2",
|
|
61
|
+
"vitest": "^1.0.0-beta.1"
|
|
62
|
+
},
|
|
63
|
+
"prettier": {
|
|
64
|
+
"printWidth": 100,
|
|
65
|
+
"singleQuote": true,
|
|
66
|
+
"tabWidth": 4
|
|
66
67
|
}
|
|
67
68
|
}
|
package/src/js/index.d.ts
CHANGED
|
@@ -21,7 +21,7 @@ type RouteName = KnownRouteName | (string & {});
|
|
|
21
21
|
/**
|
|
22
22
|
* Information about a single route parameter.
|
|
23
23
|
*/
|
|
24
|
-
type ParameterInfo = { name: string
|
|
24
|
+
type ParameterInfo = { name: string; binding?: string };
|
|
25
25
|
|
|
26
26
|
/**
|
|
27
27
|
* A primitive route parameter value, as it would appear in a URL.
|
|
@@ -65,14 +65,18 @@ type GenericRouteParamsObject = Record<keyof any, unknown> & HasQueryParam;
|
|
|
65
65
|
* An object of parameters for a specific named route.
|
|
66
66
|
*/
|
|
67
67
|
// TODO: The keys here could be non-optional (or more detailed) if we can determine which params are required/not.
|
|
68
|
-
type KnownRouteParamsObject<I extends readonly ParameterInfo[]> = {
|
|
68
|
+
type KnownRouteParamsObject<I extends readonly ParameterInfo[]> = {
|
|
69
|
+
[T in I[number] as T['name']]?: Routable<T>;
|
|
70
|
+
} & GenericRouteParamsObject;
|
|
69
71
|
// `readonly` allows TypeScript to determine the actual values of all the
|
|
70
72
|
// parameter names inside the array, instead of just seeing `string`.
|
|
71
73
|
// See https://github.com/tighten/ziggy/pull/664#discussion_r1329978447.
|
|
72
74
|
/**
|
|
73
75
|
* An object of route parameters.
|
|
74
76
|
*/
|
|
75
|
-
type RouteParamsObject<N extends RouteName> = N extends KnownRouteName
|
|
77
|
+
type RouteParamsObject<N extends RouteName> = N extends KnownRouteName
|
|
78
|
+
? KnownRouteParamsObject<RouteList[N]>
|
|
79
|
+
: GenericRouteParamsObject;
|
|
76
80
|
|
|
77
81
|
/**
|
|
78
82
|
* An array of parameters for an unspecified route.
|
|
@@ -83,7 +87,10 @@ type GenericRouteParamsArray = unknown[];
|
|
|
83
87
|
/**
|
|
84
88
|
* An array of parameters for a specific named route.
|
|
85
89
|
*/
|
|
86
|
-
type KnownRouteParamsArray<I extends readonly ParameterInfo[]> = [
|
|
90
|
+
type KnownRouteParamsArray<I extends readonly ParameterInfo[]> = [
|
|
91
|
+
...{ [K in keyof I]: Routable<I[K]> },
|
|
92
|
+
...unknown[],
|
|
93
|
+
];
|
|
87
94
|
// Because `K in keyof I` for a `readonly` array is always a number, even though this
|
|
88
95
|
// looks like `{ 0: T, 1: U, 2: V }` TypeScript generates `[T, U, V]`. The nested
|
|
89
96
|
// array destructing lets us type the first n items in the array, which are known
|
|
@@ -97,7 +104,9 @@ type KnownRouteParamsArray<I extends readonly ParameterInfo[]> = [...{ [K in key
|
|
|
97
104
|
/**
|
|
98
105
|
* An array of route parameters.
|
|
99
106
|
*/
|
|
100
|
-
type RouteParamsArray<N extends RouteName> = N extends KnownRouteName
|
|
107
|
+
type RouteParamsArray<N extends RouteName> = N extends KnownRouteName
|
|
108
|
+
? KnownRouteParamsArray<RouteList[N]>
|
|
109
|
+
: GenericRouteParamsArray;
|
|
101
110
|
|
|
102
111
|
/**
|
|
103
112
|
* All possible parameter argument shapes for a route.
|
|
@@ -108,38 +117,38 @@ type RouteParams<N extends RouteName> = ParameterValue | RouteParamsObject<N> |
|
|
|
108
117
|
* A route.
|
|
109
118
|
*/
|
|
110
119
|
interface Route {
|
|
111
|
-
uri: string
|
|
112
|
-
methods: ('GET' | 'HEAD' | 'POST' | 'PATCH' | 'PUT' | 'OPTIONS' | 'DELETE')[]
|
|
113
|
-
domain?: string
|
|
114
|
-
parameters?: string[]
|
|
115
|
-
bindings?: Record<string, string
|
|
116
|
-
wheres?: Record<string, unknown
|
|
117
|
-
middleware?: string[]
|
|
120
|
+
uri: string;
|
|
121
|
+
methods: ('GET' | 'HEAD' | 'POST' | 'PATCH' | 'PUT' | 'OPTIONS' | 'DELETE')[];
|
|
122
|
+
domain?: string;
|
|
123
|
+
parameters?: string[];
|
|
124
|
+
bindings?: Record<string, string>;
|
|
125
|
+
wheres?: Record<string, unknown>;
|
|
126
|
+
middleware?: string[];
|
|
118
127
|
}
|
|
119
128
|
|
|
120
129
|
/**
|
|
121
130
|
* Ziggy's config object.
|
|
122
131
|
*/
|
|
123
132
|
interface Config {
|
|
124
|
-
url: string
|
|
125
|
-
port: number | null
|
|
126
|
-
defaults: Record<string, RawParameterValue
|
|
127
|
-
routes: Record<string, Route
|
|
133
|
+
url: string;
|
|
134
|
+
port: number | null;
|
|
135
|
+
defaults: Record<string, RawParameterValue>;
|
|
136
|
+
routes: Record<string, Route>;
|
|
128
137
|
location?: {
|
|
129
|
-
host?: string
|
|
130
|
-
pathname?: string
|
|
131
|
-
search?: string
|
|
132
|
-
}
|
|
138
|
+
host?: string;
|
|
139
|
+
pathname?: string;
|
|
140
|
+
search?: string;
|
|
141
|
+
};
|
|
133
142
|
}
|
|
134
143
|
|
|
135
144
|
/**
|
|
136
145
|
* Ziggy's Router class.
|
|
137
146
|
*/
|
|
138
147
|
interface Router {
|
|
139
|
-
current(): RouteName | undefined
|
|
140
|
-
current<T extends RouteName>(name: T, params?: RouteParams<T>): boolean
|
|
141
|
-
get params(): Record<string, unknown
|
|
142
|
-
has<T extends RouteName>(name: T): boolean
|
|
148
|
+
current(): RouteName | undefined;
|
|
149
|
+
current<T extends RouteName>(name: T, params?: RouteParams<T>): boolean;
|
|
150
|
+
get params(): Record<string, unknown>;
|
|
151
|
+
has<T extends RouteName>(name: T): boolean;
|
|
143
152
|
}
|
|
144
153
|
|
|
145
154
|
/**
|
package/dist/index.es.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{parse as t,stringify as r}from"qs";function e(){return e=Object.assign?Object.assign.bind():function(t){for(var r=1;r<arguments.length;r++){var e=arguments[r];for(var i in e)Object.prototype.hasOwnProperty.call(e,i)&&(t[i]=e[i])}return t},e.apply(this,arguments)}class i{constructor(t,r,e){var i,s;this.name=t,this.definition=r,this.bindings=null!=(i=r.bindings)?i:{},this.wheres=null!=(s=r.wheres)?s:{},this.config=e}get template(){const t=`${this.origin}/${this.definition.uri}`.replace(/\/+$/,"");return""===t?"/":t}get origin(){return this.config.absolute?this.definition.domain?`${this.config.url.match(/^\w+:\/\//)[0]}${this.definition.domain}${this.config.port?`:${this.config.port}`:""}`:this.config.url:""}get parameterSegments(){var t,r;return null!=(t=null==(r=this.template.match(/{[^}?]+\??}/g))?void 0:r.map(t=>({name:t.replace(/{|\??}/g,""),required:!/\?}$/.test(t)})))?t:[]}matchesUrl(r){if(!this.definition.methods.includes("GET"))return!1;const e=this.template.replace(/(\/?){([^}?]*)(\??)}/g,(t,r,e,i)=>{var s;const n=`(?<${e}>${(null==(s=this.wheres[e])?void 0:s.replace(/(^\^)|(\$$)/g,""))||"[^/?]+"})`;return i?`(${r}${n})?`:`${r}${n}`}).replace(/^\w+:\/\//,""),[i,s]=r.replace(/^\w+:\/\//,"").split("?"),n=new RegExp(`^${e}/?$`).exec(i);if(n){for(const t in n.groups)n.groups[t]="string"==typeof n.groups[t]?decodeURIComponent(n.groups[t]):n.groups[t];return{params:n.groups,query:t(s)}}return!1}compile(t){return this.parameterSegments.length?this.template.replace(/{([^}?]+)(\??)}/g,(r,e,i)=>{var s,n;if(!i&&[null,void 0].includes(t[e]))throw new Error(`Ziggy error: '${e}' parameter is required for route '${this.name}'.`);if(this.wheres[e]&&!new RegExp(`^${i?`(${this.wheres[e]})?`:this.wheres[e]}$`).test(null!=(n=t[e])?n:""))throw new Error(`Ziggy error: '${e}' parameter does not match required format '${this.wheres[e]}' for route '${this.name}'.`);return encodeURI(null!=(s=t[e])?s:"").replace(/%7C/g,"|").replace(/%25/g,"%").replace(/\$/g,"%24")}).replace(`${this.origin}//`,`${this.origin}/`).replace(/\/+$/,""):this.template}}class s extends String{constructor(t,r,s=!0,n){if(super(),this.t=null!=n?n:"undefined"!=typeof Ziggy?Ziggy:null==globalThis?void 0:globalThis.Ziggy,this.t=e({},this.t,{absolute:s}),t){if(!this.t.routes[t])throw new Error(`Ziggy error: route '${t}' is not in the route list.`);this.i=new i(t,this.t.routes[t],this.t),this.o=this.h(r)}}toString(){const t=Object.keys(this.o).filter(t=>!this.i.parameterSegments.some(({name:r})=>r===t)).filter(t=>"_query"!==t).reduce((t,r)=>e({},t,{[r]:this.o[r]}),{});return this.i.compile(this.o)+r(e({},t,this.o._query),{addQueryPrefix:!0,arrayFormat:"indices",encodeValuesOnly:!0,skipNulls:!0,encoder:(t,r)=>"boolean"==typeof t?Number(t):r(t)})}u(t){t?this.t.absolute&&t.startsWith("/")&&(t=this.l().host+t):t=this.g();let r={};const[s,n]=Object.entries(this.t.routes).find(([e,s])=>r=new i(e,s,this.t).matchesUrl(t))||[void 0,void 0];return e({name:s},r,{route:n})}g(){const{host:t,pathname:r,search:e}=this.l();return(this.t.absolute?t+r:r.replace(this.t.url.replace(/^\w*:\/\/[^/]+/,""),"").replace(/^\/+/,"/"))+e}current(t,r){const{name:s,params:n,query:o,route:h}=this.u();if(!t)return s;const u=new RegExp(`^${t.replace(/\./g,"\\.").replace(/\*/g,".*")}$`).test(s);if([null,void 0].includes(r)||!u)return u;const a=new i(s,h,this.t);r=this.h(r,a);const l=e({},n,o);return!(!Object.values(r).every(t=>!t)||Object.values(l).some(t=>void 0!==t))||Object.entries(r).every(([t,r])=>l[t]==r)}l(){var t,r,e,i,s,n;const{host:o="",pathname:h="",search:u=""}="undefined"!=typeof window?window.location:{};return{host:null!=(t=null==(r=this.t.location)?void 0:r.host)?t:o,pathname:null!=(e=null==(i=this.t.location)?void 0:i.pathname)?e:h,search:null!=(s=null==(n=this.t.location)?void 0:n.search)?s:u}}get params(){const{params:t,query:r}=this.u();return e({},t,r)}has(t){return Object.keys(this.t.routes).includes(t)}h(t={},r=this.i){null!=t||(t={}),t=["string","number"].includes(typeof t)?[t]:t;const i=r.parameterSegments.filter(({name:t})=>!this.t.defaults[t]);return Array.isArray(t)?t=t.reduce((t,r,s)=>e({},t,i[s]?{[i[s].name]:r}:"object"==typeof r?r:{[r]:""}),{}):1!==i.length||t[i[0].name]||!t.hasOwnProperty(Object.values(r.bindings)[0])&&!t.hasOwnProperty("id")||(t={[i[0].name]:t}),e({},this.m(r),this.$(t,r))}m(t){return t.parameterSegments.filter(({name:t})=>this.t.defaults[t]).reduce((t,{name:r},i)=>e({},t,{[r]:this.t.defaults[r]}),{})}$(t,{bindings:r,parameterSegments:i}){return Object.entries(t).reduce((t,[s,n])=>{if(!n||"object"!=typeof n||Array.isArray(n)||!i.some(({name:t})=>t===s))return e({},t,{[s]:n});if(!n.hasOwnProperty(r[s])){if(!n.hasOwnProperty("id"))throw new Error(`Ziggy error: object passed as '${s}' parameter is missing route model binding key '${r[s]}'.`);r[s]="id"}return e({},t,{[s]:n[r[s]]})},{})}valueOf(){return this.toString()}check(t){return this.has(t)}}function n(t,r,e,i){const n=new s(t,r,e,i);return t?n.toString():n}export{n as default};
|
package/dist/index.m.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{parse as t,stringify as r}from"qs";function n(t,r){for(var n=0;n<r.length;n++){var e=r[n];e.enumerable=e.enumerable||!1,e.configurable=!0,"value"in e&&(e.writable=!0),Object.defineProperty(t,"symbol"==typeof(i=function(t,r){if("object"!=typeof t||null===t)return t;var n=t[Symbol.toPrimitive];if(void 0!==n){var e=n.call(t,"string");if("object"!=typeof e)return e;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(t)}(e.key))?i:String(i),e)}var i}function e(t,r,e){return r&&n(t.prototype,r),e&&n(t,e),Object.defineProperty(t,"prototype",{writable:!1}),t}function i(){return i=Object.assign?Object.assign.bind():function(t){for(var r=1;r<arguments.length;r++){var n=arguments[r];for(var e in n)Object.prototype.hasOwnProperty.call(n,e)&&(t[e]=n[e])}return t},i.apply(this,arguments)}function u(t){return u=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(t){return t.__proto__||Object.getPrototypeOf(t)},u(t)}function o(t,r){return o=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(t,r){return t.__proto__=r,t},o(t,r)}function f(t,r,n){return f=function(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){})),!0}catch(t){return!1}}()?Reflect.construct.bind():function(t,r,n){var e=[null];e.push.apply(e,r);var i=new(Function.bind.apply(t,e));return n&&o(i,n.prototype),i},f.apply(null,arguments)}function c(t){var r="function"==typeof Map?new Map:void 0;return c=function(t){if(null===t||-1===Function.toString.call(t).indexOf("[native code]"))return t;if("function"!=typeof t)throw new TypeError("Super expression must either be null or a function");if(void 0!==r){if(r.has(t))return r.get(t);r.set(t,n)}function n(){return f(t,arguments,u(this).constructor)}return n.prototype=Object.create(t.prototype,{constructor:{value:n,enumerable:!1,writable:!0,configurable:!0}}),o(n,t)},c(t)}var a=/*#__PURE__*/function(){function r(t,r,n){var e,i;this.name=t,this.definition=r,this.bindings=null!=(e=r.bindings)?e:{},this.wheres=null!=(i=r.wheres)?i:{},this.config=n}var n=r.prototype;return n.matchesUrl=function(r){var n=this;if(!this.definition.methods.includes("GET"))return!1;var e=this.template.replace(/(\/?){([^}?]*)(\??)}/g,function(t,r,e,i){var u,o="(?<"+e+">"+((null==(u=n.wheres[e])?void 0:u.replace(/(^\^)|(\$$)/g,""))||"[^/?]+")+")";return i?"("+r+o+")?":""+r+o}).replace(/^\w+:\/\//,""),i=r.replace(/^\w+:\/\//,"").split("?"),u=i[0],o=i[1],f=new RegExp("^"+e+"/?$").exec(u);if(f){for(var c in f.groups)f.groups[c]="string"==typeof f.groups[c]?decodeURIComponent(f.groups[c]):f.groups[c];return{params:f.groups,query:t(o)}}return!1},n.compile=function(t){var r=this;return this.parameterSegments.length?this.template.replace(/{([^}?]+)(\??)}/g,function(n,e,i){var u,o;if(!i&&[null,void 0].includes(t[e]))throw new Error("Ziggy error: '"+e+"' parameter is required for route '"+r.name+"'.");if(r.wheres[e]&&!new RegExp("^"+(i?"("+r.wheres[e]+")?":r.wheres[e])+"$").test(null!=(o=t[e])?o:""))throw new Error("Ziggy error: '"+e+"' parameter does not match required format '"+r.wheres[e]+"' for route '"+r.name+"'.");return encodeURI(null!=(u=t[e])?u:"").replace(/%7C/g,"|").replace(/%25/g,"%").replace(/\$/g,"%24")}).replace(this.origin+"//",this.origin+"/").replace(/\/+$/,""):this.template},e(r,[{key:"template",get:function(){var t=(this.origin+"/"+this.definition.uri).replace(/\/+$/,"");return""===t?"/":t}},{key:"origin",get:function(){return this.config.absolute?this.definition.domain?""+this.config.url.match(/^\w+:\/\//)[0]+this.definition.domain+(this.config.port?":"+this.config.port:""):this.config.url:""}},{key:"parameterSegments",get:function(){var t,r;return null!=(t=null==(r=this.template.match(/{[^}?]+\??}/g))?void 0:r.map(function(t){return{name:t.replace(/{|\??}/g,""),required:!/\?}$/.test(t)}}))?t:[]}}]),r}(),s=/*#__PURE__*/function(t){var n,u;function f(r,n,e,u){var o;if(void 0===e&&(e=!0),(o=t.call(this)||this).t=null!=u?u:"undefined"!=typeof Ziggy?Ziggy:null==globalThis?void 0:globalThis.Ziggy,o.t=i({},o.t,{absolute:e}),r){if(!o.t.routes[r])throw new Error("Ziggy error: route '"+r+"' is not in the route list.");o.i=new a(r,o.t.routes[r],o.t),o.u=o.o(n)}return o}u=t,(n=f).prototype=Object.create(u.prototype),n.prototype.constructor=n,o(n,u);var c=f.prototype;return c.toString=function(){var t=this,n=Object.keys(this.u).filter(function(r){return!t.i.parameterSegments.some(function(t){return t.name===r})}).filter(function(t){return"_query"!==t}).reduce(function(r,n){var e;return i({},r,((e={})[n]=t.u[n],e))},{});return this.i.compile(this.u)+r(i({},n,this.u._query),{addQueryPrefix:!0,arrayFormat:"indices",encodeValuesOnly:!0,skipNulls:!0,encoder:function(t,r){return"boolean"==typeof t?Number(t):r(t)}})},c.l=function(t){var r=this;t?this.t.absolute&&t.startsWith("/")&&(t=this.h().host+t):t=this.v();var n={},e=Object.entries(this.t.routes).find(function(e){return n=new a(e[0],e[1],r.t).matchesUrl(t)})||[void 0,void 0];return i({name:e[0]},n,{route:e[1]})},c.v=function(){var t=this.h(),r=t.pathname,n=t.search;return(this.t.absolute?t.host+r:r.replace(this.t.url.replace(/^\w*:\/\/[^/]+/,""),"").replace(/^\/+/,"/"))+n},c.current=function(t,r){var n=this.l(),e=n.name,u=n.params,o=n.query,f=n.route;if(!t)return e;var c=new RegExp("^"+t.replace(/\./g,"\\.").replace(/\*/g,".*")+"$").test(e);if([null,void 0].includes(r)||!c)return c;var s=new a(e,f,this.t);r=this.o(r,s);var l=i({},u,o);return!(!Object.values(r).every(function(t){return!t})||Object.values(l).some(function(t){return void 0!==t}))||Object.entries(r).every(function(t){return l[t[0]]==t[1]})},c.h=function(){var t,r,n,e,i,u,o="undefined"!=typeof window?window.location:{},f=o.host,c=o.pathname,a=o.search;return{host:null!=(t=null==(r=this.t.location)?void 0:r.host)?t:void 0===f?"":f,pathname:null!=(n=null==(e=this.t.location)?void 0:e.pathname)?n:void 0===c?"":c,search:null!=(i=null==(u=this.t.location)?void 0:u.search)?i:void 0===a?"":a}},c.has=function(t){return Object.keys(this.t.routes).includes(t)},c.o=function(t,r){var n=this;void 0===t&&(t={}),void 0===r&&(r=this.i),null!=t||(t={}),t=["string","number"].includes(typeof t)?[t]:t;var e=r.parameterSegments.filter(function(t){return!n.t.defaults[t.name]});if(Array.isArray(t))t=t.reduce(function(t,r,n){var u,o;return i({},t,e[n]?((u={})[e[n].name]=r,u):"object"==typeof r?r:((o={})[r]="",o))},{});else if(1===e.length&&!t[e[0].name]&&(t.hasOwnProperty(Object.values(r.bindings)[0])||t.hasOwnProperty("id"))){var u;(u={})[e[0].name]=t,t=u}return i({},this.g(r),this.p(t,r))},c.g=function(t){var r=this;return t.parameterSegments.filter(function(t){return r.t.defaults[t.name]}).reduce(function(t,n,e){var u,o=n.name;return i({},t,((u={})[o]=r.t.defaults[o],u))},{})},c.p=function(t,r){var n=r.bindings,e=r.parameterSegments;return Object.entries(t).reduce(function(t,r){var u,o,f=r[0],c=r[1];if(!c||"object"!=typeof c||Array.isArray(c)||!e.some(function(t){return t.name===f}))return i({},t,((o={})[f]=c,o));if(!c.hasOwnProperty(n[f])){if(!c.hasOwnProperty("id"))throw new Error("Ziggy error: object passed as '"+f+"' parameter is missing route model binding key '"+n[f]+"'.");n[f]="id"}return i({},t,((u={})[f]=c[n[f]],u))},{})},c.valueOf=function(){return this.toString()},c.check=function(t){return this.has(t)},e(f,[{key:"params",get:function(){var t=this.l();return i({},t.params,t.query)}}]),f}(/*#__PURE__*/c(String));function l(t,r,n,e){var i=new s(t,r,n,e);return t?i.toString():i}export{l as default};
|
package/dist/react.es.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{parse as t,stringify as r}from"qs";function e(){return e=Object.assign?Object.assign.bind():function(t){for(var r=1;r<arguments.length;r++){var e=arguments[r];for(var i in e)Object.prototype.hasOwnProperty.call(e,i)&&(t[i]=e[i])}return t},e.apply(this,arguments)}class i{constructor(t,r,e){var i,n;this.name=t,this.definition=r,this.bindings=null!=(i=r.bindings)?i:{},this.wheres=null!=(n=r.wheres)?n:{},this.config=e}get template(){const t=`${this.origin}/${this.definition.uri}`.replace(/\/+$/,"");return""===t?"/":t}get origin(){return this.config.absolute?this.definition.domain?`${this.config.url.match(/^\w+:\/\//)[0]}${this.definition.domain}${this.config.port?`:${this.config.port}`:""}`:this.config.url:""}get parameterSegments(){var t,r;return null!=(t=null==(r=this.template.match(/{[^}?]+\??}/g))?void 0:r.map(t=>({name:t.replace(/{|\??}/g,""),required:!/\?}$/.test(t)})))?t:[]}matchesUrl(r){if(!this.definition.methods.includes("GET"))return!1;const e=this.template.replace(/(\/?){([^}?]*)(\??)}/g,(t,r,e,i)=>{var n;const s=`(?<${e}>${(null==(n=this.wheres[e])?void 0:n.replace(/(^\^)|(\$$)/g,""))||"[^/?]+"})`;return i?`(${r}${s})?`:`${r}${s}`}).replace(/^\w+:\/\//,""),[i,n]=r.replace(/^\w+:\/\//,"").split("?"),s=new RegExp(`^${e}/?$`).exec(i);if(s){for(const t in s.groups)s.groups[t]="string"==typeof s.groups[t]?decodeURIComponent(s.groups[t]):s.groups[t];return{params:s.groups,query:t(n)}}return!1}compile(t){return this.parameterSegments.length?this.template.replace(/{([^}?]+)(\??)}/g,(r,e,i)=>{var n,s;if(!i&&[null,void 0].includes(t[e]))throw new Error(`Ziggy error: '${e}' parameter is required for route '${this.name}'.`);if(this.wheres[e]&&!new RegExp(`^${i?`(${this.wheres[e]})?`:this.wheres[e]}$`).test(null!=(s=t[e])?s:""))throw new Error(`Ziggy error: '${e}' parameter does not match required format '${this.wheres[e]}' for route '${this.name}'.`);return encodeURI(null!=(n=t[e])?n:"").replace(/%7C/g,"|").replace(/%25/g,"%").replace(/\$/g,"%24")}).replace(`${this.origin}//`,`${this.origin}/`).replace(/\/+$/,""):this.template}}class n extends String{constructor(t,r,n=!0,s){if(super(),this.t=null!=s?s:"undefined"!=typeof Ziggy?Ziggy:null==globalThis?void 0:globalThis.Ziggy,this.t=e({},this.t,{absolute:n}),t){if(!this.t.routes[t])throw new Error(`Ziggy error: route '${t}' is not in the route list.`);this.i=new i(t,this.t.routes[t],this.t),this.o=this.h(r)}}toString(){const t=Object.keys(this.o).filter(t=>!this.i.parameterSegments.some(({name:r})=>r===t)).filter(t=>"_query"!==t).reduce((t,r)=>e({},t,{[r]:this.o[r]}),{});return this.i.compile(this.o)+r(e({},t,this.o._query),{addQueryPrefix:!0,arrayFormat:"indices",encodeValuesOnly:!0,skipNulls:!0,encoder:(t,r)=>"boolean"==typeof t?Number(t):r(t)})}u(t){t?this.t.absolute&&t.startsWith("/")&&(t=this.l().host+t):t=this.g();let r={};const[n,s]=Object.entries(this.t.routes).find(([e,n])=>r=new i(e,n,this.t).matchesUrl(t))||[void 0,void 0];return e({name:n},r,{route:s})}g(){const{host:t,pathname:r,search:e}=this.l();return(this.t.absolute?t+r:r.replace(this.t.url.replace(/^\w*:\/\/[^/]+/,""),"").replace(/^\/+/,"/"))+e}current(t,r){const{name:n,params:s,query:o,route:h}=this.u();if(!t)return n;const u=new RegExp(`^${t.replace(/\./g,"\\.").replace(/\*/g,".*")}$`).test(n);if([null,void 0].includes(r)||!u)return u;const a=new i(n,h,this.t);r=this.h(r,a);const l=e({},s,o);return!(!Object.values(r).every(t=>!t)||Object.values(l).some(t=>void 0!==t))||Object.entries(r).every(([t,r])=>l[t]==r)}l(){var t,r,e,i,n,s;const{host:o="",pathname:h="",search:u=""}="undefined"!=typeof window?window.location:{};return{host:null!=(t=null==(r=this.t.location)?void 0:r.host)?t:o,pathname:null!=(e=null==(i=this.t.location)?void 0:i.pathname)?e:h,search:null!=(n=null==(s=this.t.location)?void 0:s.search)?n:u}}get params(){const{params:t,query:r}=this.u();return e({},t,r)}has(t){return Object.keys(this.t.routes).includes(t)}h(t={},r=this.i){null!=t||(t={}),t=["string","number"].includes(typeof t)?[t]:t;const i=r.parameterSegments.filter(({name:t})=>!this.t.defaults[t]);return Array.isArray(t)?t=t.reduce((t,r,n)=>e({},t,i[n]?{[i[n].name]:r}:"object"==typeof r?r:{[r]:""}),{}):1!==i.length||t[i[0].name]||!t.hasOwnProperty(Object.values(r.bindings)[0])&&!t.hasOwnProperty("id")||(t={[i[0].name]:t}),e({},this.m(r),this.$(t,r))}m(t){return t.parameterSegments.filter(({name:t})=>this.t.defaults[t]).reduce((t,{name:r},i)=>e({},t,{[r]:this.t.defaults[r]}),{})}$(t,{bindings:r,parameterSegments:i}){return Object.entries(t).reduce((t,[n,s])=>{if(!s||"object"!=typeof s||Array.isArray(s)||!i.some(({name:t})=>t===n))return e({},t,{[n]:s});if(!s.hasOwnProperty(r[n])){if(!s.hasOwnProperty("id"))throw new Error(`Ziggy error: object passed as '${n}' parameter is missing route model binding key '${r[n]}'.`);r[n]="id"}return e({},t,{[n]:s[r[n]]})},{})}valueOf(){return this.toString()}check(t){return this.has(t)}}function s(t){if(!t&&!globalThis.Ziggy&&"undefined"==typeof Ziggy)throw new Error("Ziggy error: missing configuration. Ensure that a `Ziggy` variable is defined globally or pass a config object into `useRoute()`.");return(r,e,i,s=t)=>function(t,r,e,i){const s=new n(t,r,e,i);return t?s.toString():s}(r,e,i,s)}export{s as useRoute};
|
package/dist/react.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
!function(t,n){"object"==typeof exports&&"undefined"!=typeof module?n(exports,require("qs")):"function"==typeof define&&define.amd?define(["exports","qs"],n):n((t||self).ZiggyReact={},t.qs)}(this,function(t,n){function r(t,n){for(var r=0;r<n.length;r++){var e=n[r];e.enumerable=e.enumerable||!1,e.configurable=!0,"value"in e&&(e.writable=!0),Object.defineProperty(t,"symbol"==typeof(i=function(t,n){if("object"!=typeof t||null===t)return t;var r=t[Symbol.toPrimitive];if(void 0!==r){var e=r.call(t,"string");if("object"!=typeof e)return e;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(t)}(e.key))?i:String(i),e)}var i}function e(t,n,e){return n&&r(t.prototype,n),e&&r(t,e),Object.defineProperty(t,"prototype",{writable:!1}),t}function i(){return i=Object.assign?Object.assign.bind():function(t){for(var n=1;n<arguments.length;n++){var r=arguments[n];for(var e in r)Object.prototype.hasOwnProperty.call(r,e)&&(t[e]=r[e])}return t},i.apply(this,arguments)}function u(t){return u=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(t){return t.__proto__||Object.getPrototypeOf(t)},u(t)}function o(t,n){return o=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(t,n){return t.__proto__=n,t},o(t,n)}function f(t,n,r){return f=function(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){})),!0}catch(t){return!1}}()?Reflect.construct.bind():function(t,n,r){var e=[null];e.push.apply(e,n);var i=new(Function.bind.apply(t,e));return r&&o(i,r.prototype),i},f.apply(null,arguments)}function c(t){var n="function"==typeof Map?new Map:void 0;return c=function(t){if(null===t||-1===Function.toString.call(t).indexOf("[native code]"))return t;if("function"!=typeof t)throw new TypeError("Super expression must either be null or a function");if(void 0!==n){if(n.has(t))return n.get(t);n.set(t,r)}function r(){return f(t,arguments,u(this).constructor)}return r.prototype=Object.create(t.prototype,{constructor:{value:r,enumerable:!1,writable:!0,configurable:!0}}),o(r,t)},c(t)}var s=/*#__PURE__*/function(){function t(t,n,r){var e,i;this.name=t,this.definition=n,this.bindings=null!=(e=n.bindings)?e:{},this.wheres=null!=(i=n.wheres)?i:{},this.config=r}var r=t.prototype;return r.matchesUrl=function(t){var r=this;if(!this.definition.methods.includes("GET"))return!1;var e=this.template.replace(/(\/?){([^}?]*)(\??)}/g,function(t,n,e,i){var u,o="(?<"+e+">"+((null==(u=r.wheres[e])?void 0:u.replace(/(^\^)|(\$$)/g,""))||"[^/?]+")+")";return i?"("+n+o+")?":""+n+o}).replace(/^\w+:\/\//,""),i=t.replace(/^\w+:\/\//,"").split("?"),u=i[0],o=i[1],f=new RegExp("^"+e+"/?$").exec(u);if(f){for(var c in f.groups)f.groups[c]="string"==typeof f.groups[c]?decodeURIComponent(f.groups[c]):f.groups[c];return{params:f.groups,query:n.parse(o)}}return!1},r.compile=function(t){var n=this;return this.parameterSegments.length?this.template.replace(/{([^}?]+)(\??)}/g,function(r,e,i){var u,o;if(!i&&[null,void 0].includes(t[e]))throw new Error("Ziggy error: '"+e+"' parameter is required for route '"+n.name+"'.");if(n.wheres[e]&&!new RegExp("^"+(i?"("+n.wheres[e]+")?":n.wheres[e])+"$").test(null!=(o=t[e])?o:""))throw new Error("Ziggy error: '"+e+"' parameter does not match required format '"+n.wheres[e]+"' for route '"+n.name+"'.");return encodeURI(null!=(u=t[e])?u:"").replace(/%7C/g,"|").replace(/%25/g,"%").replace(/\$/g,"%24")}).replace(this.origin+"//",this.origin+"/").replace(/\/+$/,""):this.template},e(t,[{key:"template",get:function(){var t=(this.origin+"/"+this.definition.uri).replace(/\/+$/,"");return""===t?"/":t}},{key:"origin",get:function(){return this.config.absolute?this.definition.domain?""+this.config.url.match(/^\w+:\/\//)[0]+this.definition.domain+(this.config.port?":"+this.config.port:""):this.config.url:""}},{key:"parameterSegments",get:function(){var t,n;return null!=(t=null==(n=this.template.match(/{[^}?]+\??}/g))?void 0:n.map(function(t){return{name:t.replace(/{|\??}/g,""),required:!/\?}$/.test(t)}}))?t:[]}}]),t}(),a=/*#__PURE__*/function(t){var r,u;function f(n,r,e,u){var o;if(void 0===e&&(e=!0),(o=t.call(this)||this).t=null!=u?u:"undefined"!=typeof Ziggy?Ziggy:null==globalThis?void 0:globalThis.Ziggy,o.t=i({},o.t,{absolute:e}),n){if(!o.t.routes[n])throw new Error("Ziggy error: route '"+n+"' is not in the route list.");o.i=new s(n,o.t.routes[n],o.t),o.u=o.o(r)}return o}u=t,(r=f).prototype=Object.create(u.prototype),r.prototype.constructor=r,o(r,u);var c=f.prototype;return c.toString=function(){var t=this,r=Object.keys(this.u).filter(function(n){return!t.i.parameterSegments.some(function(t){return t.name===n})}).filter(function(t){return"_query"!==t}).reduce(function(n,r){var e;return i({},n,((e={})[r]=t.u[r],e))},{});return this.i.compile(this.u)+n.stringify(i({},r,this.u._query),{addQueryPrefix:!0,arrayFormat:"indices",encodeValuesOnly:!0,skipNulls:!0,encoder:function(t,n){return"boolean"==typeof t?Number(t):n(t)}})},c.l=function(t){var n=this;t?this.t.absolute&&t.startsWith("/")&&(t=this.h().host+t):t=this.v();var r={},e=Object.entries(this.t.routes).find(function(e){return r=new s(e[0],e[1],n.t).matchesUrl(t)})||[void 0,void 0];return i({name:e[0]},r,{route:e[1]})},c.v=function(){var t=this.h(),n=t.pathname,r=t.search;return(this.t.absolute?t.host+n:n.replace(this.t.url.replace(/^\w*:\/\/[^/]+/,""),"").replace(/^\/+/,"/"))+r},c.current=function(t,n){var r=this.l(),e=r.name,u=r.params,o=r.query,f=r.route;if(!t)return e;var c=new RegExp("^"+t.replace(/\./g,"\\.").replace(/\*/g,".*")+"$").test(e);if([null,void 0].includes(n)||!c)return c;var a=new s(e,f,this.t);n=this.o(n,a);var l=i({},u,o);return!(!Object.values(n).every(function(t){return!t})||Object.values(l).some(function(t){return void 0!==t}))||Object.entries(n).every(function(t){return l[t[0]]==t[1]})},c.h=function(){var t,n,r,e,i,u,o="undefined"!=typeof window?window.location:{},f=o.host,c=o.pathname,s=o.search;return{host:null!=(t=null==(n=this.t.location)?void 0:n.host)?t:void 0===f?"":f,pathname:null!=(r=null==(e=this.t.location)?void 0:e.pathname)?r:void 0===c?"":c,search:null!=(i=null==(u=this.t.location)?void 0:u.search)?i:void 0===s?"":s}},c.has=function(t){return Object.keys(this.t.routes).includes(t)},c.o=function(t,n){var r=this;void 0===t&&(t={}),void 0===n&&(n=this.i),null!=t||(t={}),t=["string","number"].includes(typeof t)?[t]:t;var e=n.parameterSegments.filter(function(t){return!r.t.defaults[t.name]});if(Array.isArray(t))t=t.reduce(function(t,n,r){var u,o;return i({},t,e[r]?((u={})[e[r].name]=n,u):"object"==typeof n?n:((o={})[n]="",o))},{});else if(1===e.length&&!t[e[0].name]&&(t.hasOwnProperty(Object.values(n.bindings)[0])||t.hasOwnProperty("id"))){var u;(u={})[e[0].name]=t,t=u}return i({},this.g(n),this.p(t,n))},c.g=function(t){var n=this;return t.parameterSegments.filter(function(t){return n.t.defaults[t.name]}).reduce(function(t,r,e){var u,o=r.name;return i({},t,((u={})[o]=n.t.defaults[o],u))},{})},c.p=function(t,n){var r=n.bindings,e=n.parameterSegments;return Object.entries(t).reduce(function(t,n){var u,o,f=n[0],c=n[1];if(!c||"object"!=typeof c||Array.isArray(c)||!e.some(function(t){return t.name===f}))return i({},t,((o={})[f]=c,o));if(!c.hasOwnProperty(r[f])){if(!c.hasOwnProperty("id"))throw new Error("Ziggy error: object passed as '"+f+"' parameter is missing route model binding key '"+r[f]+"'.");r[f]="id"}return i({},t,((u={})[f]=c[r[f]],u))},{})},c.valueOf=function(){return this.toString()},c.check=function(t){return this.has(t)},e(f,[{key:"params",get:function(){var t=this.l();return i({},t.params,t.query)}}]),f}(/*#__PURE__*/c(String));t.useRoute=function(t){if(!t&&!globalThis.Ziggy&&"undefined"==typeof Ziggy)throw new Error("Ziggy error: missing configuration. Ensure that a `Ziggy` variable is defined globally or pass a config object into `useRoute()`.");return function(n,r,e,i){return void 0===i&&(i=t),function(t,n,r,e){var i=new a(t,n,r,e);return t?i.toString():i}(n,r,e,i)}}});
|
package/dist/react.m.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{parse as r,stringify as t}from"qs";function n(r,t){for(var n=0;n<t.length;n++){var e=t[n];e.enumerable=e.enumerable||!1,e.configurable=!0,"value"in e&&(e.writable=!0),Object.defineProperty(r,"symbol"==typeof(i=function(r,t){if("object"!=typeof r||null===r)return r;var n=r[Symbol.toPrimitive];if(void 0!==n){var e=n.call(r,"string");if("object"!=typeof e)return e;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(r)}(e.key))?i:String(i),e)}var i}function e(r,t,e){return t&&n(r.prototype,t),e&&n(r,e),Object.defineProperty(r,"prototype",{writable:!1}),r}function i(){return i=Object.assign?Object.assign.bind():function(r){for(var t=1;t<arguments.length;t++){var n=arguments[t];for(var e in n)Object.prototype.hasOwnProperty.call(n,e)&&(r[e]=n[e])}return r},i.apply(this,arguments)}function u(r){return u=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(r){return r.__proto__||Object.getPrototypeOf(r)},u(r)}function o(r,t){return o=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(r,t){return r.__proto__=t,r},o(r,t)}function f(r,t,n){return f=function(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){})),!0}catch(r){return!1}}()?Reflect.construct.bind():function(r,t,n){var e=[null];e.push.apply(e,t);var i=new(Function.bind.apply(r,e));return n&&o(i,n.prototype),i},f.apply(null,arguments)}function c(r){var t="function"==typeof Map?new Map:void 0;return c=function(r){if(null===r||-1===Function.toString.call(r).indexOf("[native code]"))return r;if("function"!=typeof r)throw new TypeError("Super expression must either be null or a function");if(void 0!==t){if(t.has(r))return t.get(r);t.set(r,n)}function n(){return f(r,arguments,u(this).constructor)}return n.prototype=Object.create(r.prototype,{constructor:{value:n,enumerable:!1,writable:!0,configurable:!0}}),o(n,r)},c(r)}var a=/*#__PURE__*/function(){function t(r,t,n){var e,i;this.name=r,this.definition=t,this.bindings=null!=(e=t.bindings)?e:{},this.wheres=null!=(i=t.wheres)?i:{},this.config=n}var n=t.prototype;return n.matchesUrl=function(t){var n=this;if(!this.definition.methods.includes("GET"))return!1;var e=this.template.replace(/(\/?){([^}?]*)(\??)}/g,function(r,t,e,i){var u,o="(?<"+e+">"+((null==(u=n.wheres[e])?void 0:u.replace(/(^\^)|(\$$)/g,""))||"[^/?]+")+")";return i?"("+t+o+")?":""+t+o}).replace(/^\w+:\/\//,""),i=t.replace(/^\w+:\/\//,"").split("?"),u=i[0],o=i[1],f=new RegExp("^"+e+"/?$").exec(u);if(f){for(var c in f.groups)f.groups[c]="string"==typeof f.groups[c]?decodeURIComponent(f.groups[c]):f.groups[c];return{params:f.groups,query:r(o)}}return!1},n.compile=function(r){var t=this;return this.parameterSegments.length?this.template.replace(/{([^}?]+)(\??)}/g,function(n,e,i){var u,o;if(!i&&[null,void 0].includes(r[e]))throw new Error("Ziggy error: '"+e+"' parameter is required for route '"+t.name+"'.");if(t.wheres[e]&&!new RegExp("^"+(i?"("+t.wheres[e]+")?":t.wheres[e])+"$").test(null!=(o=r[e])?o:""))throw new Error("Ziggy error: '"+e+"' parameter does not match required format '"+t.wheres[e]+"' for route '"+t.name+"'.");return encodeURI(null!=(u=r[e])?u:"").replace(/%7C/g,"|").replace(/%25/g,"%").replace(/\$/g,"%24")}).replace(this.origin+"//",this.origin+"/").replace(/\/+$/,""):this.template},e(t,[{key:"template",get:function(){var r=(this.origin+"/"+this.definition.uri).replace(/\/+$/,"");return""===r?"/":r}},{key:"origin",get:function(){return this.config.absolute?this.definition.domain?""+this.config.url.match(/^\w+:\/\//)[0]+this.definition.domain+(this.config.port?":"+this.config.port:""):this.config.url:""}},{key:"parameterSegments",get:function(){var r,t;return null!=(r=null==(t=this.template.match(/{[^}?]+\??}/g))?void 0:t.map(function(r){return{name:r.replace(/{|\??}/g,""),required:!/\?}$/.test(r)}}))?r:[]}}]),t}(),s=/*#__PURE__*/function(r){var n,u;function f(t,n,e,u){var o;if(void 0===e&&(e=!0),(o=r.call(this)||this).t=null!=u?u:"undefined"!=typeof Ziggy?Ziggy:null==globalThis?void 0:globalThis.Ziggy,o.t=i({},o.t,{absolute:e}),t){if(!o.t.routes[t])throw new Error("Ziggy error: route '"+t+"' is not in the route list.");o.i=new a(t,o.t.routes[t],o.t),o.u=o.o(n)}return o}u=r,(n=f).prototype=Object.create(u.prototype),n.prototype.constructor=n,o(n,u);var c=f.prototype;return c.toString=function(){var r=this,n=Object.keys(this.u).filter(function(t){return!r.i.parameterSegments.some(function(r){return r.name===t})}).filter(function(r){return"_query"!==r}).reduce(function(t,n){var e;return i({},t,((e={})[n]=r.u[n],e))},{});return this.i.compile(this.u)+t(i({},n,this.u._query),{addQueryPrefix:!0,arrayFormat:"indices",encodeValuesOnly:!0,skipNulls:!0,encoder:function(r,t){return"boolean"==typeof r?Number(r):t(r)}})},c.l=function(r){var t=this;r?this.t.absolute&&r.startsWith("/")&&(r=this.h().host+r):r=this.v();var n={},e=Object.entries(this.t.routes).find(function(e){return n=new a(e[0],e[1],t.t).matchesUrl(r)})||[void 0,void 0];return i({name:e[0]},n,{route:e[1]})},c.v=function(){var r=this.h(),t=r.pathname,n=r.search;return(this.t.absolute?r.host+t:t.replace(this.t.url.replace(/^\w*:\/\/[^/]+/,""),"").replace(/^\/+/,"/"))+n},c.current=function(r,t){var n=this.l(),e=n.name,u=n.params,o=n.query,f=n.route;if(!r)return e;var c=new RegExp("^"+r.replace(/\./g,"\\.").replace(/\*/g,".*")+"$").test(e);if([null,void 0].includes(t)||!c)return c;var s=new a(e,f,this.t);t=this.o(t,s);var l=i({},u,o);return!(!Object.values(t).every(function(r){return!r})||Object.values(l).some(function(r){return void 0!==r}))||Object.entries(t).every(function(r){return l[r[0]]==r[1]})},c.h=function(){var r,t,n,e,i,u,o="undefined"!=typeof window?window.location:{},f=o.host,c=o.pathname,a=o.search;return{host:null!=(r=null==(t=this.t.location)?void 0:t.host)?r:void 0===f?"":f,pathname:null!=(n=null==(e=this.t.location)?void 0:e.pathname)?n:void 0===c?"":c,search:null!=(i=null==(u=this.t.location)?void 0:u.search)?i:void 0===a?"":a}},c.has=function(r){return Object.keys(this.t.routes).includes(r)},c.o=function(r,t){var n=this;void 0===r&&(r={}),void 0===t&&(t=this.i),null!=r||(r={}),r=["string","number"].includes(typeof r)?[r]:r;var e=t.parameterSegments.filter(function(r){return!n.t.defaults[r.name]});if(Array.isArray(r))r=r.reduce(function(r,t,n){var u,o;return i({},r,e[n]?((u={})[e[n].name]=t,u):"object"==typeof t?t:((o={})[t]="",o))},{});else if(1===e.length&&!r[e[0].name]&&(r.hasOwnProperty(Object.values(t.bindings)[0])||r.hasOwnProperty("id"))){var u;(u={})[e[0].name]=r,r=u}return i({},this.g(t),this.p(r,t))},c.g=function(r){var t=this;return r.parameterSegments.filter(function(r){return t.t.defaults[r.name]}).reduce(function(r,n,e){var u,o=n.name;return i({},r,((u={})[o]=t.t.defaults[o],u))},{})},c.p=function(r,t){var n=t.bindings,e=t.parameterSegments;return Object.entries(r).reduce(function(r,t){var u,o,f=t[0],c=t[1];if(!c||"object"!=typeof c||Array.isArray(c)||!e.some(function(r){return r.name===f}))return i({},r,((o={})[f]=c,o));if(!c.hasOwnProperty(n[f])){if(!c.hasOwnProperty("id"))throw new Error("Ziggy error: object passed as '"+f+"' parameter is missing route model binding key '"+n[f]+"'.");n[f]="id"}return i({},r,((u={})[f]=c[n[f]],u))},{})},c.valueOf=function(){return this.toString()},c.check=function(r){return this.has(r)},e(f,[{key:"params",get:function(){var r=this.l();return i({},r.params,r.query)}}]),f}(/*#__PURE__*/c(String));function l(r){if(!r&&!globalThis.Ziggy&&"undefined"==typeof Ziggy)throw new Error("Ziggy error: missing configuration. Ensure that a `Ziggy` variable is defined globally or pass a config object into `useRoute()`.");return function(t,n,e,i){return void 0===i&&(i=r),function(r,t,n,e){var i=new s(r,t,n,e);return r?i.toString():i}(t,n,e,i)}}export{l as useRoute};
|
package/dist/vue.es.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{parse as t,stringify as r}from"qs";function e(){return e=Object.assign?Object.assign.bind():function(t){for(var r=1;r<arguments.length;r++){var e=arguments[r];for(var i in e)Object.prototype.hasOwnProperty.call(e,i)&&(t[i]=e[i])}return t},e.apply(this,arguments)}class i{constructor(t,r,e){var i,s;this.name=t,this.definition=r,this.bindings=null!=(i=r.bindings)?i:{},this.wheres=null!=(s=r.wheres)?s:{},this.config=e}get template(){const t=`${this.origin}/${this.definition.uri}`.replace(/\/+$/,"");return""===t?"/":t}get origin(){return this.config.absolute?this.definition.domain?`${this.config.url.match(/^\w+:\/\//)[0]}${this.definition.domain}${this.config.port?`:${this.config.port}`:""}`:this.config.url:""}get parameterSegments(){var t,r;return null!=(t=null==(r=this.template.match(/{[^}?]+\??}/g))?void 0:r.map(t=>({name:t.replace(/{|\??}/g,""),required:!/\?}$/.test(t)})))?t:[]}matchesUrl(r){if(!this.definition.methods.includes("GET"))return!1;const e=this.template.replace(/(\/?){([^}?]*)(\??)}/g,(t,r,e,i)=>{var s;const n=`(?<${e}>${(null==(s=this.wheres[e])?void 0:s.replace(/(^\^)|(\$$)/g,""))||"[^/?]+"})`;return i?`(${r}${n})?`:`${r}${n}`}).replace(/^\w+:\/\//,""),[i,s]=r.replace(/^\w+:\/\//,"").split("?"),n=new RegExp(`^${e}/?$`).exec(i);if(n){for(const t in n.groups)n.groups[t]="string"==typeof n.groups[t]?decodeURIComponent(n.groups[t]):n.groups[t];return{params:n.groups,query:t(s)}}return!1}compile(t){return this.parameterSegments.length?this.template.replace(/{([^}?]+)(\??)}/g,(r,e,i)=>{var s,n;if(!i&&[null,void 0].includes(t[e]))throw new Error(`Ziggy error: '${e}' parameter is required for route '${this.name}'.`);if(this.wheres[e]&&!new RegExp(`^${i?`(${this.wheres[e]})?`:this.wheres[e]}$`).test(null!=(n=t[e])?n:""))throw new Error(`Ziggy error: '${e}' parameter does not match required format '${this.wheres[e]}' for route '${this.name}'.`);return encodeURI(null!=(s=t[e])?s:"").replace(/%7C/g,"|").replace(/%25/g,"%").replace(/\$/g,"%24")}).replace(`${this.origin}//`,`${this.origin}/`).replace(/\/+$/,""):this.template}}class s extends String{constructor(t,r,s=!0,n){if(super(),this.t=null!=n?n:"undefined"!=typeof Ziggy?Ziggy:null==globalThis?void 0:globalThis.Ziggy,this.t=e({},this.t,{absolute:s}),t){if(!this.t.routes[t])throw new Error(`Ziggy error: route '${t}' is not in the route list.`);this.i=new i(t,this.t.routes[t],this.t),this.o=this.h(r)}}toString(){const t=Object.keys(this.o).filter(t=>!this.i.parameterSegments.some(({name:r})=>r===t)).filter(t=>"_query"!==t).reduce((t,r)=>e({},t,{[r]:this.o[r]}),{});return this.i.compile(this.o)+r(e({},t,this.o._query),{addQueryPrefix:!0,arrayFormat:"indices",encodeValuesOnly:!0,skipNulls:!0,encoder:(t,r)=>"boolean"==typeof t?Number(t):r(t)})}u(t){t?this.t.absolute&&t.startsWith("/")&&(t=this.l().host+t):t=this.g();let r={};const[s,n]=Object.entries(this.t.routes).find(([e,s])=>r=new i(e,s,this.t).matchesUrl(t))||[void 0,void 0];return e({name:s},r,{route:n})}g(){const{host:t,pathname:r,search:e}=this.l();return(this.t.absolute?t+r:r.replace(this.t.url.replace(/^\w*:\/\/[^/]+/,""),"").replace(/^\/+/,"/"))+e}current(t,r){const{name:s,params:n,query:o,route:h}=this.u();if(!t)return s;const u=new RegExp(`^${t.replace(/\./g,"\\.").replace(/\*/g,".*")}$`).test(s);if([null,void 0].includes(r)||!u)return u;const a=new i(s,h,this.t);r=this.h(r,a);const l=e({},n,o);return!(!Object.values(r).every(t=>!t)||Object.values(l).some(t=>void 0!==t))||Object.entries(r).every(([t,r])=>l[t]==r)}l(){var t,r,e,i,s,n;const{host:o="",pathname:h="",search:u=""}="undefined"!=typeof window?window.location:{};return{host:null!=(t=null==(r=this.t.location)?void 0:r.host)?t:o,pathname:null!=(e=null==(i=this.t.location)?void 0:i.pathname)?e:h,search:null!=(s=null==(n=this.t.location)?void 0:n.search)?s:u}}get params(){const{params:t,query:r}=this.u();return e({},t,r)}has(t){return Object.keys(this.t.routes).includes(t)}h(t={},r=this.i){null!=t||(t={}),t=["string","number"].includes(typeof t)?[t]:t;const i=r.parameterSegments.filter(({name:t})=>!this.t.defaults[t]);return Array.isArray(t)?t=t.reduce((t,r,s)=>e({},t,i[s]?{[i[s].name]:r}:"object"==typeof r?r:{[r]:""}),{}):1!==i.length||t[i[0].name]||!t.hasOwnProperty(Object.values(r.bindings)[0])&&!t.hasOwnProperty("id")||(t={[i[0].name]:t}),e({},this.m(r),this.$(t,r))}m(t){return t.parameterSegments.filter(({name:t})=>this.t.defaults[t]).reduce((t,{name:r},i)=>e({},t,{[r]:this.t.defaults[r]}),{})}$(t,{bindings:r,parameterSegments:i}){return Object.entries(t).reduce((t,[s,n])=>{if(!n||"object"!=typeof n||Array.isArray(n)||!i.some(({name:t})=>t===s))return e({},t,{[s]:n});if(!n.hasOwnProperty(r[s])){if(!n.hasOwnProperty("id"))throw new Error(`Ziggy error: object passed as '${s}' parameter is missing route model binding key '${r[s]}'.`);r[s]="id"}return e({},t,{[s]:n[r[s]]})},{})}valueOf(){return this.toString()}check(t){return this.has(t)}}const n={install(t,r){const e=(t,e,i,n=r)=>function(t,r,e,i){const n=new s(t,r,e,i);return t?n.toString():n}(t,e,i,n);t.mixin({methods:{route:e}}),parseInt(t.version)>2&&t.provide("route",e)}};export{n as ZiggyVue};
|
package/dist/vue.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
!function(t,n){"object"==typeof exports&&"undefined"!=typeof module?n(exports,require("qs")):"function"==typeof define&&define.amd?define(["exports","qs"],n):n((t||self).ZiggyVue={},t.qs)}(this,function(t,n){function r(t,n){for(var r=0;r<n.length;r++){var e=n[r];e.enumerable=e.enumerable||!1,e.configurable=!0,"value"in e&&(e.writable=!0),Object.defineProperty(t,"symbol"==typeof(i=function(t,n){if("object"!=typeof t||null===t)return t;var r=t[Symbol.toPrimitive];if(void 0!==r){var e=r.call(t,"string");if("object"!=typeof e)return e;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(t)}(e.key))?i:String(i),e)}var i}function e(t,n,e){return n&&r(t.prototype,n),e&&r(t,e),Object.defineProperty(t,"prototype",{writable:!1}),t}function i(){return i=Object.assign?Object.assign.bind():function(t){for(var n=1;n<arguments.length;n++){var r=arguments[n];for(var e in r)Object.prototype.hasOwnProperty.call(r,e)&&(t[e]=r[e])}return t},i.apply(this,arguments)}function u(t){return u=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(t){return t.__proto__||Object.getPrototypeOf(t)},u(t)}function o(t,n){return o=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(t,n){return t.__proto__=n,t},o(t,n)}function f(t,n,r){return f=function(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){})),!0}catch(t){return!1}}()?Reflect.construct.bind():function(t,n,r){var e=[null];e.push.apply(e,n);var i=new(Function.bind.apply(t,e));return r&&o(i,r.prototype),i},f.apply(null,arguments)}function c(t){var n="function"==typeof Map?new Map:void 0;return c=function(t){if(null===t||-1===Function.toString.call(t).indexOf("[native code]"))return t;if("function"!=typeof t)throw new TypeError("Super expression must either be null or a function");if(void 0!==n){if(n.has(t))return n.get(t);n.set(t,r)}function r(){return f(t,arguments,u(this).constructor)}return r.prototype=Object.create(t.prototype,{constructor:{value:r,enumerable:!1,writable:!0,configurable:!0}}),o(r,t)},c(t)}var s=/*#__PURE__*/function(){function t(t,n,r){var e,i;this.name=t,this.definition=n,this.bindings=null!=(e=n.bindings)?e:{},this.wheres=null!=(i=n.wheres)?i:{},this.config=r}var r=t.prototype;return r.matchesUrl=function(t){var r=this;if(!this.definition.methods.includes("GET"))return!1;var e=this.template.replace(/(\/?){([^}?]*)(\??)}/g,function(t,n,e,i){var u,o="(?<"+e+">"+((null==(u=r.wheres[e])?void 0:u.replace(/(^\^)|(\$$)/g,""))||"[^/?]+")+")";return i?"("+n+o+")?":""+n+o}).replace(/^\w+:\/\//,""),i=t.replace(/^\w+:\/\//,"").split("?"),u=i[0],o=i[1],f=new RegExp("^"+e+"/?$").exec(u);if(f){for(var c in f.groups)f.groups[c]="string"==typeof f.groups[c]?decodeURIComponent(f.groups[c]):f.groups[c];return{params:f.groups,query:n.parse(o)}}return!1},r.compile=function(t){var n=this;return this.parameterSegments.length?this.template.replace(/{([^}?]+)(\??)}/g,function(r,e,i){var u,o;if(!i&&[null,void 0].includes(t[e]))throw new Error("Ziggy error: '"+e+"' parameter is required for route '"+n.name+"'.");if(n.wheres[e]&&!new RegExp("^"+(i?"("+n.wheres[e]+")?":n.wheres[e])+"$").test(null!=(o=t[e])?o:""))throw new Error("Ziggy error: '"+e+"' parameter does not match required format '"+n.wheres[e]+"' for route '"+n.name+"'.");return encodeURI(null!=(u=t[e])?u:"").replace(/%7C/g,"|").replace(/%25/g,"%").replace(/\$/g,"%24")}).replace(this.origin+"//",this.origin+"/").replace(/\/+$/,""):this.template},e(t,[{key:"template",get:function(){var t=(this.origin+"/"+this.definition.uri).replace(/\/+$/,"");return""===t?"/":t}},{key:"origin",get:function(){return this.config.absolute?this.definition.domain?""+this.config.url.match(/^\w+:\/\//)[0]+this.definition.domain+(this.config.port?":"+this.config.port:""):this.config.url:""}},{key:"parameterSegments",get:function(){var t,n;return null!=(t=null==(n=this.template.match(/{[^}?]+\??}/g))?void 0:n.map(function(t){return{name:t.replace(/{|\??}/g,""),required:!/\?}$/.test(t)}}))?t:[]}}]),t}(),a=/*#__PURE__*/function(t){var r,u;function f(n,r,e,u){var o;if(void 0===e&&(e=!0),(o=t.call(this)||this).t=null!=u?u:"undefined"!=typeof Ziggy?Ziggy:null==globalThis?void 0:globalThis.Ziggy,o.t=i({},o.t,{absolute:e}),n){if(!o.t.routes[n])throw new Error("Ziggy error: route '"+n+"' is not in the route list.");o.i=new s(n,o.t.routes[n],o.t),o.u=o.o(r)}return o}u=t,(r=f).prototype=Object.create(u.prototype),r.prototype.constructor=r,o(r,u);var c=f.prototype;return c.toString=function(){var t=this,r=Object.keys(this.u).filter(function(n){return!t.i.parameterSegments.some(function(t){return t.name===n})}).filter(function(t){return"_query"!==t}).reduce(function(n,r){var e;return i({},n,((e={})[r]=t.u[r],e))},{});return this.i.compile(this.u)+n.stringify(i({},r,this.u._query),{addQueryPrefix:!0,arrayFormat:"indices",encodeValuesOnly:!0,skipNulls:!0,encoder:function(t,n){return"boolean"==typeof t?Number(t):n(t)}})},c.l=function(t){var n=this;t?this.t.absolute&&t.startsWith("/")&&(t=this.h().host+t):t=this.v();var r={},e=Object.entries(this.t.routes).find(function(e){return r=new s(e[0],e[1],n.t).matchesUrl(t)})||[void 0,void 0];return i({name:e[0]},r,{route:e[1]})},c.v=function(){var t=this.h(),n=t.pathname,r=t.search;return(this.t.absolute?t.host+n:n.replace(this.t.url.replace(/^\w*:\/\/[^/]+/,""),"").replace(/^\/+/,"/"))+r},c.current=function(t,n){var r=this.l(),e=r.name,u=r.params,o=r.query,f=r.route;if(!t)return e;var c=new RegExp("^"+t.replace(/\./g,"\\.").replace(/\*/g,".*")+"$").test(e);if([null,void 0].includes(n)||!c)return c;var a=new s(e,f,this.t);n=this.o(n,a);var l=i({},u,o);return!(!Object.values(n).every(function(t){return!t})||Object.values(l).some(function(t){return void 0!==t}))||Object.entries(n).every(function(t){return l[t[0]]==t[1]})},c.h=function(){var t,n,r,e,i,u,o="undefined"!=typeof window?window.location:{},f=o.host,c=o.pathname,s=o.search;return{host:null!=(t=null==(n=this.t.location)?void 0:n.host)?t:void 0===f?"":f,pathname:null!=(r=null==(e=this.t.location)?void 0:e.pathname)?r:void 0===c?"":c,search:null!=(i=null==(u=this.t.location)?void 0:u.search)?i:void 0===s?"":s}},c.has=function(t){return Object.keys(this.t.routes).includes(t)},c.o=function(t,n){var r=this;void 0===t&&(t={}),void 0===n&&(n=this.i),null!=t||(t={}),t=["string","number"].includes(typeof t)?[t]:t;var e=n.parameterSegments.filter(function(t){return!r.t.defaults[t.name]});if(Array.isArray(t))t=t.reduce(function(t,n,r){var u,o;return i({},t,e[r]?((u={})[e[r].name]=n,u):"object"==typeof n?n:((o={})[n]="",o))},{});else if(1===e.length&&!t[e[0].name]&&(t.hasOwnProperty(Object.values(n.bindings)[0])||t.hasOwnProperty("id"))){var u;(u={})[e[0].name]=t,t=u}return i({},this.p(n),this.g(t,n))},c.p=function(t){var n=this;return t.parameterSegments.filter(function(t){return n.t.defaults[t.name]}).reduce(function(t,r,e){var u,o=r.name;return i({},t,((u={})[o]=n.t.defaults[o],u))},{})},c.g=function(t,n){var r=n.bindings,e=n.parameterSegments;return Object.entries(t).reduce(function(t,n){var u,o,f=n[0],c=n[1];if(!c||"object"!=typeof c||Array.isArray(c)||!e.some(function(t){return t.name===f}))return i({},t,((o={})[f]=c,o));if(!c.hasOwnProperty(r[f])){if(!c.hasOwnProperty("id"))throw new Error("Ziggy error: object passed as '"+f+"' parameter is missing route model binding key '"+r[f]+"'.");r[f]="id"}return i({},t,((u={})[f]=c[r[f]],u))},{})},c.valueOf=function(){return this.toString()},c.check=function(t){return this.has(t)},e(f,[{key:"params",get:function(){var t=this.l();return i({},t.params,t.query)}}]),f}(/*#__PURE__*/c(String));t.ZiggyVue={install:function(t,n){var r=function(t,r,e,i){return void 0===i&&(i=n),function(t,n,r,e){var i=new a(t,n,r,e);return t?i.toString():i}(t,r,e,i)};t.mixin({methods:{route:r}}),parseInt(t.version)>2&&t.provide("route",r)}}});
|
package/dist/vue.m.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{parse as t,stringify as r}from"qs";function n(t,r){for(var n=0;n<r.length;n++){var e=r[n];e.enumerable=e.enumerable||!1,e.configurable=!0,"value"in e&&(e.writable=!0),Object.defineProperty(t,"symbol"==typeof(i=function(t,r){if("object"!=typeof t||null===t)return t;var n=t[Symbol.toPrimitive];if(void 0!==n){var e=n.call(t,"string");if("object"!=typeof e)return e;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(t)}(e.key))?i:String(i),e)}var i}function e(t,r,e){return r&&n(t.prototype,r),e&&n(t,e),Object.defineProperty(t,"prototype",{writable:!1}),t}function i(){return i=Object.assign?Object.assign.bind():function(t){for(var r=1;r<arguments.length;r++){var n=arguments[r];for(var e in n)Object.prototype.hasOwnProperty.call(n,e)&&(t[e]=n[e])}return t},i.apply(this,arguments)}function u(t){return u=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(t){return t.__proto__||Object.getPrototypeOf(t)},u(t)}function o(t,r){return o=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(t,r){return t.__proto__=r,t},o(t,r)}function f(t,r,n){return f=function(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){})),!0}catch(t){return!1}}()?Reflect.construct.bind():function(t,r,n){var e=[null];e.push.apply(e,r);var i=new(Function.bind.apply(t,e));return n&&o(i,n.prototype),i},f.apply(null,arguments)}function c(t){var r="function"==typeof Map?new Map:void 0;return c=function(t){if(null===t||-1===Function.toString.call(t).indexOf("[native code]"))return t;if("function"!=typeof t)throw new TypeError("Super expression must either be null or a function");if(void 0!==r){if(r.has(t))return r.get(t);r.set(t,n)}function n(){return f(t,arguments,u(this).constructor)}return n.prototype=Object.create(t.prototype,{constructor:{value:n,enumerable:!1,writable:!0,configurable:!0}}),o(n,t)},c(t)}var a=/*#__PURE__*/function(){function r(t,r,n){var e,i;this.name=t,this.definition=r,this.bindings=null!=(e=r.bindings)?e:{},this.wheres=null!=(i=r.wheres)?i:{},this.config=n}var n=r.prototype;return n.matchesUrl=function(r){var n=this;if(!this.definition.methods.includes("GET"))return!1;var e=this.template.replace(/(\/?){([^}?]*)(\??)}/g,function(t,r,e,i){var u,o="(?<"+e+">"+((null==(u=n.wheres[e])?void 0:u.replace(/(^\^)|(\$$)/g,""))||"[^/?]+")+")";return i?"("+r+o+")?":""+r+o}).replace(/^\w+:\/\//,""),i=r.replace(/^\w+:\/\//,"").split("?"),u=i[0],o=i[1],f=new RegExp("^"+e+"/?$").exec(u);if(f){for(var c in f.groups)f.groups[c]="string"==typeof f.groups[c]?decodeURIComponent(f.groups[c]):f.groups[c];return{params:f.groups,query:t(o)}}return!1},n.compile=function(t){var r=this;return this.parameterSegments.length?this.template.replace(/{([^}?]+)(\??)}/g,function(n,e,i){var u,o;if(!i&&[null,void 0].includes(t[e]))throw new Error("Ziggy error: '"+e+"' parameter is required for route '"+r.name+"'.");if(r.wheres[e]&&!new RegExp("^"+(i?"("+r.wheres[e]+")?":r.wheres[e])+"$").test(null!=(o=t[e])?o:""))throw new Error("Ziggy error: '"+e+"' parameter does not match required format '"+r.wheres[e]+"' for route '"+r.name+"'.");return encodeURI(null!=(u=t[e])?u:"").replace(/%7C/g,"|").replace(/%25/g,"%").replace(/\$/g,"%24")}).replace(this.origin+"//",this.origin+"/").replace(/\/+$/,""):this.template},e(r,[{key:"template",get:function(){var t=(this.origin+"/"+this.definition.uri).replace(/\/+$/,"");return""===t?"/":t}},{key:"origin",get:function(){return this.config.absolute?this.definition.domain?""+this.config.url.match(/^\w+:\/\//)[0]+this.definition.domain+(this.config.port?":"+this.config.port:""):this.config.url:""}},{key:"parameterSegments",get:function(){var t,r;return null!=(t=null==(r=this.template.match(/{[^}?]+\??}/g))?void 0:r.map(function(t){return{name:t.replace(/{|\??}/g,""),required:!/\?}$/.test(t)}}))?t:[]}}]),r}(),s=/*#__PURE__*/function(t){var n,u;function f(r,n,e,u){var o;if(void 0===e&&(e=!0),(o=t.call(this)||this).t=null!=u?u:"undefined"!=typeof Ziggy?Ziggy:null==globalThis?void 0:globalThis.Ziggy,o.t=i({},o.t,{absolute:e}),r){if(!o.t.routes[r])throw new Error("Ziggy error: route '"+r+"' is not in the route list.");o.i=new a(r,o.t.routes[r],o.t),o.u=o.o(n)}return o}u=t,(n=f).prototype=Object.create(u.prototype),n.prototype.constructor=n,o(n,u);var c=f.prototype;return c.toString=function(){var t=this,n=Object.keys(this.u).filter(function(r){return!t.i.parameterSegments.some(function(t){return t.name===r})}).filter(function(t){return"_query"!==t}).reduce(function(r,n){var e;return i({},r,((e={})[n]=t.u[n],e))},{});return this.i.compile(this.u)+r(i({},n,this.u._query),{addQueryPrefix:!0,arrayFormat:"indices",encodeValuesOnly:!0,skipNulls:!0,encoder:function(t,r){return"boolean"==typeof t?Number(t):r(t)}})},c.l=function(t){var r=this;t?this.t.absolute&&t.startsWith("/")&&(t=this.v().host+t):t=this.h();var n={},e=Object.entries(this.t.routes).find(function(e){return n=new a(e[0],e[1],r.t).matchesUrl(t)})||[void 0,void 0];return i({name:e[0]},n,{route:e[1]})},c.h=function(){var t=this.v(),r=t.pathname,n=t.search;return(this.t.absolute?t.host+r:r.replace(this.t.url.replace(/^\w*:\/\/[^/]+/,""),"").replace(/^\/+/,"/"))+n},c.current=function(t,r){var n=this.l(),e=n.name,u=n.params,o=n.query,f=n.route;if(!t)return e;var c=new RegExp("^"+t.replace(/\./g,"\\.").replace(/\*/g,".*")+"$").test(e);if([null,void 0].includes(r)||!c)return c;var s=new a(e,f,this.t);r=this.o(r,s);var l=i({},u,o);return!(!Object.values(r).every(function(t){return!t})||Object.values(l).some(function(t){return void 0!==t}))||Object.entries(r).every(function(t){return l[t[0]]==t[1]})},c.v=function(){var t,r,n,e,i,u,o="undefined"!=typeof window?window.location:{},f=o.host,c=o.pathname,a=o.search;return{host:null!=(t=null==(r=this.t.location)?void 0:r.host)?t:void 0===f?"":f,pathname:null!=(n=null==(e=this.t.location)?void 0:e.pathname)?n:void 0===c?"":c,search:null!=(i=null==(u=this.t.location)?void 0:u.search)?i:void 0===a?"":a}},c.has=function(t){return Object.keys(this.t.routes).includes(t)},c.o=function(t,r){var n=this;void 0===t&&(t={}),void 0===r&&(r=this.i),null!=t||(t={}),t=["string","number"].includes(typeof t)?[t]:t;var e=r.parameterSegments.filter(function(t){return!n.t.defaults[t.name]});if(Array.isArray(t))t=t.reduce(function(t,r,n){var u,o;return i({},t,e[n]?((u={})[e[n].name]=r,u):"object"==typeof r?r:((o={})[r]="",o))},{});else if(1===e.length&&!t[e[0].name]&&(t.hasOwnProperty(Object.values(r.bindings)[0])||t.hasOwnProperty("id"))){var u;(u={})[e[0].name]=t,t=u}return i({},this.g(r),this.p(t,r))},c.g=function(t){var r=this;return t.parameterSegments.filter(function(t){return r.t.defaults[t.name]}).reduce(function(t,n,e){var u,o=n.name;return i({},t,((u={})[o]=r.t.defaults[o],u))},{})},c.p=function(t,r){var n=r.bindings,e=r.parameterSegments;return Object.entries(t).reduce(function(t,r){var u,o,f=r[0],c=r[1];if(!c||"object"!=typeof c||Array.isArray(c)||!e.some(function(t){return t.name===f}))return i({},t,((o={})[f]=c,o));if(!c.hasOwnProperty(n[f])){if(!c.hasOwnProperty("id"))throw new Error("Ziggy error: object passed as '"+f+"' parameter is missing route model binding key '"+n[f]+"'.");n[f]="id"}return i({},t,((u={})[f]=c[n[f]],u))},{})},c.valueOf=function(){return this.toString()},c.check=function(t){return this.has(t)},e(f,[{key:"params",get:function(){var t=this.l();return i({},t.params,t.query)}}]),f}(/*#__PURE__*/c(String)),l={install:function(t,r){var n=function(t,n,e,i){return void 0===i&&(i=r),function(t,r,n,e){var i=new s(t,r,n,e);return t?i.toString():i}(t,n,e,i)};t.mixin({methods:{route:n}}),parseInt(t.version)>2&&t.provide("route",n)}};export{l as ZiggyVue};
|