zidan-select 2.3.1 → 2.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/docs/build.md CHANGED
@@ -25,8 +25,11 @@ zidan-select/
25
25
  ├─ scripts/
26
26
  │ ├─ serve.mjs # dependency-free dev server (port 4173)
27
27
  │ ├─ build.mjs # assembles dist/ and the select/file subset bundles
28
- │ └─ test.mjs # syntax / split-CSS / API checks
28
+ │ ├─ test.mjs # syntax / split-CSS / API checks
29
+ │ └─ release.mjs # one-command version bump, changelog roll, commit and tag
29
30
  ├─ docs/ # comparison, options, validation, frameworks, theming, build
31
+ ├─ .github/workflows/ # pages.yml (demo) and release.yml (npm publish with provenance)
32
+ ├─ CHANGELOG.md
30
33
  ├─ README.md
31
34
  └─ LICENSE
32
35
  ```
@@ -55,6 +58,7 @@ side by side at the [builds section](https://akhtar1985.github.io/zidan-select/#
55
58
  | `npm test` | `node --check` on every script, asserts `plugin-core.css` has no colour literals, checks all presets/adapters and the exported API. |
56
59
  | `npm run lint` | Syntax check only. |
57
60
  | `npm run build` | Cleans `dist/`, copies the four assets, writes `dist/zidan-form.cjs`, generates the select-only and file-only bundles, and minifies **if** esbuild is installed. |
61
+ | `npm run release -- patch` | Bumps every version site, rolls `CHANGELOG.md`, runs the checks, commits and tags `vX.Y.Z`. |
58
62
 
59
63
  There is no watch task: the JS and CSS are the distributables, so edit and reload. `npm run
60
64
  dev` sends `Cache-Control: no-store`, which is enough for the demo.
@@ -99,7 +103,7 @@ Without esbuild the build still succeeds and prints that minification was skippe
99
103
  | Select-only | `/dist/select/zidan-select.min.js` | `/dist/select/plugin-select-core.min.css` | `/dist/select/plugin-select-theme.min.css` |
100
104
  | File-only | `/dist/file/zidan-file.min.js` | `/dist/file/plugin-file-core.min.css` | `/dist/file/plugin-file-theme.min.css` |
101
105
 
102
- Prepend `https://cdn.jsdelivr.net/npm/zidan-select@2.3.1` to each path (or your own origin).
106
+ Prepend `https://cdn.jsdelivr.net/npm/zidan-select@2.4.0` to each path (or your own origin).
103
107
  These are real files in the npm tarball, so unpkg and self-hosted CDNs serve the same bytes;
104
108
  jsDelivr additionally auto-minifies the readable root files, but do not rely on that trick.
105
109
  Check the three you use with `curl -I` before changing a version, then update the URLs in the
@@ -122,7 +126,7 @@ Both theme stylesheets keep the token set, the five preset themes (`default`, `m
122
126
  adapters, so `data-zidan-theme`, `data-zidan-layout` and `data-zidan-framework` behave the same
123
127
  as in the full build.
124
128
 
125
- Approximate v2.3.1 sizes (readable → minified): select ≈104 → 62 kB JS, 12 → 9 kB core CSS,
129
+ Approximate v2.4.0 sizes (readable → minified): select ≈104 → 62 kB JS, 12 → 9 kB core CSS,
126
130
  32 → 27 kB theme; file ≈82 → 49 kB JS, 9 → 7 kB core, 34 → 29 kB theme; full ≈208 → 123 kB
127
131
  JS, 38 → 29 kB core, 47 → 39 kB theme.
128
132
 
@@ -150,25 +154,63 @@ abort the build instead of producing a partial bundle.
150
154
 
151
155
  ## Versioning
152
156
 
153
- Semantic versioning, with the changelog living in GitHub releases:
157
+ Semantic versioning, with the history in [`CHANGELOG.md`](../CHANGELOG.md):
154
158
 
155
159
  - **patch** — bug fixes, no token/API changes.
156
160
  - **minor** — new themes, layouts, adapters, options (backwards compatible).
157
161
  - **major** — renamed tokens, removed attributes, changed defaults.
158
162
 
159
- Keep `VERSION` in `zidan-form.js`, `package.json` and the CSS headers in step. The runtime
160
- guard (`__zidanFormGuard`) uses that version to avoid double-initialising when the file is
161
- loaded twice.
163
+ The runtime guard (`__zidanFormGuard`) compares `VERSION` in `zidan-form.js`, so the version
164
+ constant, the `package.json` field, the lockfile and the CSS banners must always agree —
165
+ `npm test` fails when they drift.
166
+
167
+ ## Releasing
168
+
169
+ ```bash
170
+ npm run release -- patch --note "Fix the thing that broke" # or: minor | major | 2.3.2
171
+ git push origin main --follow-tags
172
+ ```
173
+
174
+ `scripts/release.mjs` is the whole release:
175
+
176
+ 1. writes the new version into `package.json`, `package-lock.json`, the banner and `VERSION` in
177
+ `zidan-form.js`, both CSS banners, the README CDN URLs, `index.html`, `advanced.html`,
178
+ `docs/build.md` and `docs/html-and-wordpress.md`;
179
+ 2. moves `## [Unreleased]` in `CHANGELOG.md` under `## [X.Y.Z] - YYYY-MM-DD` — write your notes
180
+ there, or pass `--note "…"`; it refuses to cut a release with no notes;
181
+ 3. runs `npm run types && npm test`;
182
+ 4. commits `Release X.Y.Z` and creates the annotated tag `vX.Y.Z`.
183
+
184
+ Flags: `--dry-run` (print the plan, write nothing), `--no-commit` (edit files and the changelog
185
+ only), `--skip-checks`. It requires a clean tracked working tree, so the release commit holds only
186
+ the bump, and it refuses a version that is already tagged.
187
+
188
+ Pushing the tag starts `.github/workflows/release.yml`. Nothing else to run.
162
189
 
163
190
  ## Publishing to npm
164
191
 
192
+ Publishing happens in CI:
193
+
194
+ | Trigger | What happens |
195
+ | --- | --- |
196
+ | Tag `vX.Y.Z` pushed | Verifies the tag against `package.json`, refuses an existing version, runs `prepublishOnly` (types → build → test), publishes with `--provenance`. |
197
+ | **Actions → Publish to npm → Run workflow** | The same job without a tag, for publishing the version already committed. |
198
+
199
+ Authentication is **npm trusted publishing** over OIDC: the job requests `id-token: write` and
200
+ needs no token secret. One-time setup on npmjs.com — **zidan-select → Settings → Trusted
201
+ publishing → GitHub Actions**, owner `akhtar1985`, repository `zidan-select`, workflow
202
+ `release.yml`, environment left empty. Requires npm 11.5.1+; the workflow runs `node-version: 24`.
203
+
204
+ Without trusted publishing, create a granular access token with read+write on `zidan-select`,
205
+ store it as the `NPM_TOKEN` repository secret, and uncomment the `NODE_AUTH_TOKEN` env block at
206
+ the bottom of the workflow. Remove it once OIDC works.
207
+
208
+ Manual publishing remains a last resort:
209
+
165
210
  ```bash
166
211
  npm login
167
212
  npm test
168
- npm version minor -m "release: v%s"
169
- npm run build
170
213
  npm publish # tarball limited by package.json "files"
171
- git push --follow-tags
172
214
  ```
173
215
 
174
216
  First publish: `npm publish --access public`. Scoped forks need `--access public` on every
@@ -225,31 +267,9 @@ One-time setup: **Settings → Pages → Build and deployment → Source: GitHub
225
267
  The workflow only copies demo assets, so `scripts/`, `dist/`, `package.json` and local scratch
226
268
  files are never published.
227
269
 
228
- ## Release automation (optional)
229
-
230
- ```yaml
231
- # .github/workflows/publish.yml
232
- name: publish
233
- on:
234
- release:
235
- types: [published]
236
- jobs:
237
- npm:
238
- runs-on: ubuntu-latest
239
- permissions:
240
- contents: read
241
- id-token: write
242
- steps:
243
- - uses: actions/checkout@v4
244
- - uses: actions/setup-node@v4
245
- with:
246
- node-version: 20
247
- registry-url: https://registry.npmjs.org
248
- - run: npm test
249
- - run: npm run build
250
- - run: npm publish --provenance --access public
251
- env:
252
- NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
253
- ```
270
+ ## Release automation
254
271
 
255
- The workflow needs no install step because the project has no dependencies.
272
+ [`.github/workflows/release.yml`](../.github/workflows/release.yml) is the complete workflow:
273
+ tag-triggered, provenance-enabled, dist-tag aware (`latest`, or `next` for prereleases), with
274
+ guards against a mismatched tag and a duplicate version. It installs the dev tooling with
275
+ `npm ci` only to build and test — the published package still has no runtime dependencies.
@@ -33,15 +33,15 @@ colours), `plugin-theme.css` carries colours, presets and skins.
33
33
  | File uploads only | `dist/file/zidan-file.js` + `plugin-file-core.css` + `plugin-file-theme.css` |
34
34
  | Several control types together | `zidan-form.js` + `plugin-core.css` + `plugin-theme.css` |
35
35
 
36
- Pinned CDN URLs (replace `2.3.1` when you upgrade):
36
+ Pinned CDN URLs (replace `2.4.0` when you upgrade):
37
37
 
38
38
  | Build | JavaScript | CSS |
39
39
  | --- | --- | --- |
40
- | Full | `https://cdn.jsdelivr.net/npm/zidan-select@2.3.1/zidan-form.js` | `…@2.3.1/plugin-core.css` + `…@2.3.1/plugin-theme.css` |
41
- | Select-only | `https://cdn.jsdelivr.net/npm/zidan-select@2.3.1/dist/select/zidan-select.js` | `…@2.3.1/dist/select/plugin-select-core.css` + `…plugin-select-theme.css` |
42
- | File-only | `https://cdn.jsdelivr.net/npm/zidan-select@2.3.1/dist/file/zidan-file.js` | `…@2.3.1/dist/file/plugin-file-core.css` + `…plugin-file-theme.css` |
40
+ | Full | `https://cdn.jsdelivr.net/npm/zidan-select@2.4.0/zidan-form.js` | `…@2.4.0/plugin-core.css` + `…@2.4.0/plugin-theme.css` |
41
+ | Select-only | `https://cdn.jsdelivr.net/npm/zidan-select@2.4.0/dist/select/zidan-select.js` | `…@2.4.0/dist/select/plugin-select-core.css` + `…plugin-select-theme.css` |
42
+ | File-only | `https://cdn.jsdelivr.net/npm/zidan-select@2.4.0/dist/file/zidan-file.js` | `…@2.4.0/dist/file/plugin-file-core.css` + `…plugin-file-theme.css` |
43
43
 
44
- Prefer self-hosting? Download the same files (`npm pack zidan-select@2.3.1`, or the raw files
44
+ Prefer self-hosting? Download the same files (`npm pack zidan-select@2.4.0`, or the raw files
45
45
  from GitHub) and keep them next to your page:
46
46
 
47
47
  ```
@@ -174,8 +174,8 @@ see the native `FormData`.
174
174
  <title>ZidanForm static example</title>
175
175
 
176
176
  <!-- structure first, theme second -->
177
- <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/zidan-select@2.3.1/plugin-core.css">
178
- <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/zidan-select@2.3.1/plugin-theme.css">
177
+ <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/zidan-select@2.4.0/plugin-core.css">
178
+ <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/zidan-select@2.4.0/plugin-theme.css">
179
179
  </head>
180
180
  <body>
181
181
 
@@ -251,7 +251,7 @@ see the native `FormData`.
251
251
  </form>
252
252
  </main>
253
253
 
254
- <script src="https://cdn.jsdelivr.net/npm/zidan-select@2.3.1/zidan-form.js"></script>
254
+ <script src="https://cdn.jsdelivr.net/npm/zidan-select@2.4.0/zidan-form.js"></script>
255
255
  <script>
256
256
  // Demo only: show the native FormData instead of navigating away.
257
257
  document.querySelector('.zidan-form').addEventListener('submit', function (event) {
@@ -289,9 +289,9 @@ and `ZidanSelect`; `zidanField` does not exist here.
289
289
  <meta name="viewport" content="width=device-width, initial-scale=1">
290
290
  <title>Select-only example</title>
291
291
  <link rel="stylesheet"
292
- href="https://cdn.jsdelivr.net/npm/zidan-select@2.3.1/dist/select/plugin-select-core.css">
292
+ href="https://cdn.jsdelivr.net/npm/zidan-select@2.4.0/dist/select/plugin-select-core.css">
293
293
  <link rel="stylesheet"
294
- href="https://cdn.jsdelivr.net/npm/zidan-select@2.3.1/dist/select/plugin-select-theme.css">
294
+ href="https://cdn.jsdelivr.net/npm/zidan-select@2.4.0/dist/select/plugin-select-theme.css">
295
295
  </head>
296
296
  <body style="max-width:520px;margin:40px auto;padding:0 20px">
297
297
 
@@ -311,7 +311,7 @@ and `ZidanSelect`; `zidanField` does not exist here.
311
311
  </select>
312
312
  </p>
313
313
 
314
- <script src="https://cdn.jsdelivr.net/npm/zidan-select@2.3.1/dist/select/zidan-select.js"></script>
314
+ <script src="https://cdn.jsdelivr.net/npm/zidan-select@2.4.0/dist/select/zidan-select.js"></script>
315
315
  <script>
316
316
  zidanSelect('#country', {
317
317
  mode: 'combobox',
@@ -342,9 +342,9 @@ Only uploads on this page? Load the file-only build. It exposes `zidanField`,
342
342
  <meta name="viewport" content="width=device-width, initial-scale=1">
343
343
  <title>File upload example</title>
344
344
  <link rel="stylesheet"
345
- href="https://cdn.jsdelivr.net/npm/zidan-select@2.3.1/dist/file/plugin-file-core.css">
345
+ href="https://cdn.jsdelivr.net/npm/zidan-select@2.4.0/dist/file/plugin-file-core.css">
346
346
  <link rel="stylesheet"
347
- href="https://cdn.jsdelivr.net/npm/zidan-select@2.3.1/dist/file/plugin-file-theme.css">
347
+ href="https://cdn.jsdelivr.net/npm/zidan-select@2.4.0/dist/file/plugin-file-theme.css">
348
348
  </head>
349
349
  <body style="max-width:520px;margin:40px auto;padding:0 20px">
350
350
 
@@ -356,7 +356,7 @@ Only uploads on this page? Load the file-only build. It exposes `zidanField`,
356
356
  <input id="shots" type="file" name="shots" multiple accept="image/*">
357
357
  </form>
358
358
 
359
- <script src="https://cdn.jsdelivr.net/npm/zidan-select@2.3.1/dist/file/zidan-file.js"></script>
359
+ <script src="https://cdn.jsdelivr.net/npm/zidan-select@2.4.0/dist/file/zidan-file.js"></script>
360
360
  <script>
361
361
  zidanField('#cv', {
362
362
  variant: 'dropzone',
@@ -475,9 +475,9 @@ add_action('wp_enqueue_scripts', function () {
475
475
 
476
476
  $base = get_stylesheet_directory_uri() . '/assets/zidan';
477
477
 
478
- wp_enqueue_style('zidan-core', $base . '/plugin-core.css', array(), '2.3.1');
479
- wp_enqueue_style('zidan-theme', $base . '/plugin-theme.css', array('zidan-core'), '2.3.1');
480
- wp_enqueue_script('zidan-form', $base . '/zidan-form.js', array(), '2.3.1', true);
478
+ wp_enqueue_style('zidan-core', $base . '/plugin-core.css', array(), '2.4.0');
479
+ wp_enqueue_style('zidan-theme', $base . '/plugin-theme.css', array('zidan-core'), '2.4.0');
480
+ wp_enqueue_script('zidan-form', $base . '/zidan-form.js', array(), '2.4.0', true);
481
481
 
482
482
  // Optional: configure fields by ID/class without inline HTML scripts.
483
483
  wp_add_inline_script('zidan-form', "window.ZIDAN_FORM_CONFIG = {
@@ -552,9 +552,9 @@ Shopify has its own section: [9. Shopify](#9-shopify).
552
552
  ```html
553
553
  <!-- inside one embed block: markup first, script last -->
554
554
  <select class="zidan-select" data-zidan-options='{"mode":"combobox"}'>…</select>
555
- <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/zidan-select@2.3.1/plugin-core.css">
556
- <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/zidan-select@2.3.1/plugin-theme.css">
557
- <script src="https://cdn.jsdelivr.net/npm/zidan-select@2.3.1/zidan-form.js"></script>
555
+ <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/zidan-select@2.4.0/plugin-core.css">
556
+ <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/zidan-select@2.4.0/plugin-theme.css">
557
+ <script src="https://cdn.jsdelivr.net/npm/zidan-select@2.4.0/zidan-form.js"></script>
558
558
  ```
559
559
 
560
560
  For the single-select case, the select-only build is smaller: swap in the
package/docs/index.html CHANGED
@@ -64,12 +64,16 @@
64
64
  <strong><a href="../playground.html">Field playground</a></strong>
65
65
  <span>Pick one control, toggle its options, preview it live and copy the matching HTML attributes or vanilla JavaScript call.</span>
66
66
  </li>
67
+ <li>
68
+ <strong><a href="../ajax.html">AJAX &amp; remote data demo</a></strong>
69
+ <span>Declarative <code>data-zidan-fetch-url</code> against a real API, plus a hand-written <code>fetchOptions</code> example with paging, abort and cache state on screen.</span>
70
+ </li>
67
71
  <li>
68
72
  <strong><a href="../index.html#controls">Controls &amp; options reference</a></strong>
69
73
  <span>Every control family in one place: the options you reach for most, the two ways to initialise a field, and live examples — with links into the playground for the remaining options and the advanced reference for callbacks and the API.</span>
70
74
  </li>
71
75
  <li>
72
- <strong><a href="https://github.com/akhtar1985/zidan-select/blob/main/docs/html-and-wordpress.md">Static HTML &amp; WordPress cookbook</a></strong>
76
+ <strong><a href="html-and-wordpress.html">Static HTML &amp; WordPress cookbook</a></strong>
73
77
  <span>Complete copy-paste pages for plain HTML, select-only and file-only builds, ID/class targeting, WordPress <code>functions.php</code>, Shopify <code>asset_url</code> + Liquid sections, and troubleshooting for page builders and caching plugins.</span>
74
78
  </li>
75
79
  <li>
@@ -81,31 +85,31 @@
81
85
  <span>Only want a select, or only a file upload? Load only that build — you do not need the full bundle. The complete form JS and CSS is for forms that enhance every input at once.</span>
82
86
  </li>
83
87
  <li>
84
- <strong><a href="https://github.com/akhtar1985/zidan-select/blob/main/docs/comparison.md">Why ZidanForm &amp; comparison</a></strong>
88
+ <strong><a href="comparison.html">Why ZidanForm &amp; comparison</a></strong>
85
89
  <span>Feature matrix against Select2, Choices.js, Tom Select, Slim Select and Bootstrap, plus benefits, trade-offs and migration notes.</span>
86
90
  </li>
87
91
  <li>
88
- <strong><a href="https://github.com/akhtar1985/zidan-select/blob/main/docs/options.md">Options &amp; data attributes</a></strong>
92
+ <strong><a href="options.html">Options &amp; data attributes</a></strong>
89
93
  <span>Every JS option, data attribute, callback, event and instance method — remote pagination and cache controls, no-JS init by marker class, form scope, <code>data-zidan-options</code> JSON and config targets, in the full build and both subsets. TypeScript declarations ship with the package.</span>
90
94
  </li>
91
95
  <li>
92
- <strong><a href="https://github.com/akhtar1985/zidan-select/blob/main/docs/validation.md">Validation compatibility</a></strong>
96
+ <strong><a href="validation-guide.html">Validation compatibility</a></strong>
93
97
  <span>Native constraint validation, jQuery Validation, JustValidate, Parsley and double-submit guards. <a href="validation.html">Runnable test bench →</a></span>
94
98
  </li>
95
99
  <li>
96
- <strong><a href="https://github.com/akhtar1985/zidan-select/blob/main/docs/theming.md">Theming</a></strong>
100
+ <strong><a href="theming.html">Theming</a></strong>
97
101
  <span>Token reference, five presets, layouts, framework adapters and custom themes.</span>
98
102
  </li>
99
103
  <li>
100
- <strong><a href="https://github.com/akhtar1985/zidan-select/blob/main/docs/frameworks.md">Framework integration</a></strong>
104
+ <strong><a href="frameworks.html">Framework integration</a></strong>
101
105
  <span>React, Next.js (with SSR), Vue, Angular and state-sync patterns.</span>
102
106
  </li>
103
107
  <li>
104
- <strong><a href="https://github.com/akhtar1985/zidan-select/blob/main/docs/build.md#select-only-and-file-only-builds">Select-only &amp; file-only builds</a></strong>
108
+ <strong><a href="build.html#select-only-and-file-only-builds">Select-only &amp; file-only builds</a></strong>
105
109
  <span>Trimmed JS and matching CSS for pages that only need a select or a file upload, with every theme and framework adapter included.</span>
106
110
  </li>
107
111
  <li>
108
- <strong><a href="https://github.com/akhtar1985/zidan-select/blob/main/docs/build.md">Build &amp; publish</a></strong>
112
+ <strong><a href="build.html">Build &amp; publish</a></strong>
109
113
  <span>Repository layout, scripts, dist output, npm publishing and GitHub Pages.</span>
110
114
  </li>
111
115
  </ul>
package/docs/options.md CHANGED
@@ -546,6 +546,15 @@ Callbacks: `onUploadStart`, `onUploadProgress`, `onUploadSuccess` / `onUpload`,
546
546
  | --- | --- | --- |
547
547
  | `fetchOptions(query, signal, context)` | — | Return an array of items, or a page `{ items, hasMore }` (or `{ items, total }`). `signal` aborts stale requests; `context` is `{ page, pageSize, append, instance }`. |
548
548
  | `fetchPageSize` | `0` | Page size handed to `fetchOptions`. `0` keeps the legacy single-request behaviour. |
549
+ | `fetchUrl` | `null` | **Declarative AJAX.** GET this URL and the select builds its own `fetchOptions` — no JavaScript needed. Attribute: `data-zidan-fetch-url`. |
550
+ | `fetchQueryParam` | `'q'` | Query-string parameter that receives the search term (`''` omits it). |
551
+ | `fetchPageParam` | `'page'` | 1-based page number sent with every request (`''` omits it). |
552
+ | `fetchSkipParam` | `null` | Send `skip = page × pageSize` instead of `fetchPageParam`, for APIs that page by offset (dummyjson, Laravel, many REST APIs). |
553
+ | `fetchPageSizeParam` | `'limit'` | Parameter that receives `fetchPageSize`. |
554
+ | `fetchItemsPath` | `null` | Dot path to the array of rows in the JSON body (`products`, `data.items`). Without it the plugin looks for `items`, `data`, `results`, `options`, `rows`, `products` or `records`. |
555
+ | `fetchTotalPath` | `null` | Dot path to the total row count; with `fetchPageSize` it decides `hasMore`. Falls back to a top-level `total`. |
556
+ | `fetchHasMorePath` | `null` | Dot path to a boolean instead of a count. |
557
+ | `fetchMethod`, `fetchHeaders`, `fetchCredentials` | `'GET'`, `null`, `'same-origin'` | Request tuning for `fetchUrl` (JavaScript only). |
549
558
  | `autoLoadMore` | `true` | Scrolling near the dropdown bottom fetches the next page automatically. |
550
559
  | `loadMoreText` | `Load more` | Label of the footer button rendered while `hasMore` is true. |
551
560
  | `cacheResults` | `true` | Cache pages per query + page. Clear with `select.clearCache()`. |
@@ -588,6 +597,29 @@ failures emit the usual `zidan:error`.
588
597
 
589
598
  The cache size is global: `ZidanSelect.cacheLimit = 50` pages (least-recently-used eviction).
590
599
 
600
+ ### AJAX from markup only
601
+
602
+ One URL is enough to turn a combobox into a remote search. The plugin sends the query, page
603
+ and page size, reads the rows out of the JSON, and keeps every other behaviour (debounce,
604
+ abort, cache, load-more, errors) identical to a hand-written `fetchOptions`.
605
+
606
+ ```html
607
+ <select id="product" name="product"
608
+ data-zidan-select="combobox"
609
+ data-zidan-fetch-url="/api/products/search"
610
+ data-zidan-fetch-items-path="data.items"
611
+ data-zidan-fetch-total-path="data.total"
612
+ data-zidan-fetch-skip-param="skip"
613
+ data-zidan-fetch-page-size="20">
614
+ </select>
615
+ ```
616
+
617
+ That markup calls `GET /api/products/search?q=…&limit=20&skip=0`, then `skip=20` for the next
618
+ page, and stops when `skip + limit >= data.total`. Rows map automatically: `value` / `label`, or
619
+ `id` / `slug` / `code` for the value and `name` / `title` / `full_name` for the label. A live page
620
+ with both modes, against a real API and a static JSON file, ships as
621
+ [`ajax.html`](https://akhtar1985.github.io/zidan-select/ajax.html).
622
+
591
623
  ### Tags
592
624
 
593
625
  | Option | Data attribute | Default |
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "zidan-select",
3
- "version": "2.3.1",
3
+ "version": "2.4.0",
4
4
  "description": "Zero-dependency form enhancement library: select/combobox/tags, checkboxes, switches, radio groups, drag & drop file upload with progress, text/number/phone/date/range inputs and textarea with input icons and steppers. Split core/theme CSS, 5 themes, 11 layouts, framework adapters. Load only the select-only or file-only build if that is all you need, or the full form bundle to enhance every input at once.",
5
5
  "keywords": [
6
6
  "select",
@@ -101,8 +101,9 @@
101
101
  "build": "node scripts/build.mjs",
102
102
  "test": "node scripts/test.mjs",
103
103
  "types": "tsc -p tsconfig.types.json",
104
- "prepublishOnly": "npm run types && npm run build && npm test",
104
+ "prepublishOnly": "npm run build && npm run types && npm test",
105
105
  "lint": "node --check zidan-form.js && node --check demo.js && node --check advanced.js && node --check playground.js && node --check nav.js && node --check zidan-form.mjs",
106
+ "release": "node scripts/release.mjs",
106
107
  "search": "node scripts/exa-search.mjs"
107
108
  },
108
109
  "engines": {
package/plugin-core.css CHANGED
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * ZidanForm v2.3.1 — plugin-core.css
2
+ * ZidanForm v2.4.0 — plugin-core.css
3
3
  * Structure and mechanics only: layout, positioning, visibility, focus
4
4
  * plumbing and accessible native-input handling. No colours, borders colours,
5
5
  * shadows or decorative skin — load plugin-theme.css (or your own theme) for
package/plugin-theme.css CHANGED
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * ZidanForm v2.3.1 — plugin-theme.css
2
+ * ZidanForm v2.4.0 — plugin-theme.css
3
3
  * Design tokens, paint, state colours, preset themes (default, modern,
4
4
  * minimal, dark, glass), the five select layouts and framework adapters
5
5
  * (bootstrap, tailwind, bulma, foundation).
package/zidan-form.d.ts CHANGED
@@ -106,6 +106,24 @@ export interface SelectOptions extends SelectCallbacks {
106
106
  autoLoadMore?: boolean;
107
107
  cacheResults?: boolean;
108
108
  loadMoreText?: string;
109
+ /** AJAX without JS: GET this URL and the select builds its own fetchOptions */
110
+ fetchUrl?: string | null;
111
+ fetchMethod?: string;
112
+ /** Query-string parameter for the search term (set to '' to omit it) */
113
+ fetchQueryParam?: string;
114
+ /** 1-based page parameter (set to '' to omit it) */
115
+ fetchPageParam?: string;
116
+ /** When set, send skip = page * pageSize instead of fetchPageParam */
117
+ fetchSkipParam?: string | null;
118
+ fetchPageSizeParam?: string;
119
+ /** Dot path to the array of rows in the JSON body, e.g. 'data.items' */
120
+ fetchItemsPath?: string | null;
121
+ /** Dot path to the total row count, used to decide hasMore */
122
+ fetchTotalPath?: string | null;
123
+ /** Dot path to a boolean hasMore flag */
124
+ fetchHasMorePath?: string | null;
125
+ fetchHeaders?: Record<string, string> | null;
126
+ fetchCredentials?: RequestCredentials;
109
127
  maxTags?: number;
110
128
  minTagLength?: number;
111
129
  maxTagLength?: number;
package/zidan-form.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * ZidanForm v2.3.1
2
+ * ZidanForm v2.4.0
3
3
  * Zero-dependency form enhancement library: select / combobox / tags,
4
4
  * checkboxes, switches, radio groups, file upload with drag & drop and
5
5
  * upload progress, text / number / phone / date / range inputs and textarea.
@@ -32,7 +32,7 @@
32
32
  })(typeof window !== 'undefined' ? window : this, function (global) {
33
33
  'use strict';
34
34
 
35
- var VERSION = '2.3.1';
35
+ var VERSION = '2.4.0';
36
36
 
37
37
  // Loading the file twice (classic script + module wrapper, or two bundles)
38
38
  // must not replace the classes and orphan the live instances.
@@ -671,6 +671,17 @@
671
671
  autoLoadMore: true,
672
672
  cacheResults: true,
673
673
  loadMoreText: 'Load more',
674
+ fetchUrl: null, // declarative AJAX: GET this endpoint instead of writing fetchOptions
675
+ fetchMethod: 'GET',
676
+ fetchQueryParam: 'q',
677
+ fetchPageParam: 'page', // 1-based page number sent with every request
678
+ fetchSkipParam: null, // when set, send skip = page * pageSize instead of fetchPageParam
679
+ fetchPageSizeParam: 'limit',
680
+ fetchItemsPath: null, // dot path to the array in the JSON body ('data.items')
681
+ fetchTotalPath: null, // dot path to the number of rows available
682
+ fetchHasMorePath: null, // dot path to a boolean
683
+ fetchHeaders: null,
684
+ fetchCredentials: 'same-origin',
674
685
  /* tags */
675
686
  maxTags: Infinity,
676
687
  minTagLength: 1,
@@ -708,6 +719,112 @@
708
719
  * ZidanSelect
709
720
  * ------------------------------------------------------------------ */
710
721
 
722
+ /* ---------------- declarative AJAX (fetchUrl) ---------------- */
723
+
724
+ function readDotPath(source, path) {
725
+ if (!path) return undefined;
726
+ return String(path).split('.').reduce(function (node, key) {
727
+ return node === null || node === undefined ? undefined : node[key];
728
+ }, source);
729
+ }
730
+
731
+ function firstRemoteArray(body) {
732
+ if (Array.isArray(body)) return body;
733
+ if (!body || typeof body !== 'object') return [];
734
+ var keys = ['items', 'data', 'results', 'options', 'rows', 'products', 'records'];
735
+ for (var i = 0; i < keys.length; i++) {
736
+ if (Array.isArray(body[keys[i]])) return body[keys[i]];
737
+ }
738
+ return [];
739
+ }
740
+
741
+ /* Map common API shapes ({id,title}, {value,label}, plain strings) to select items. */
742
+ function remoteItem(raw) {
743
+ if (raw === null || raw === undefined) return null;
744
+ if (typeof raw !== 'object') {
745
+ var text = String(raw);
746
+ return { value: text, label: text };
747
+ }
748
+ var value = raw.value !== undefined ? raw.value
749
+ : raw.id !== undefined ? raw.id
750
+ : raw.slug !== undefined ? raw.slug
751
+ : raw.code !== undefined ? raw.code
752
+ : raw.key !== undefined ? raw.key : undefined;
753
+ var label = raw.label !== undefined ? raw.label
754
+ : raw.name !== undefined ? raw.name
755
+ : raw.title !== undefined ? raw.title
756
+ : raw.full_name !== undefined ? raw.full_name
757
+ : raw.text !== undefined ? raw.text : undefined;
758
+ if (label === undefined) label = value === undefined ? '' : value;
759
+ if (value === undefined) value = label;
760
+ return { value: value, label: label, disabled: !!raw.disabled };
761
+ }
762
+
763
+ /*
764
+ * Turns fetchUrl + fetch* options into the same promise fetchOptions would return:
765
+ * { items, hasMore, total }. Honours AbortSignal and the paging context the
766
+ * select passes in, so caching, debounce and "Load more" work unchanged.
767
+ */
768
+ function createRemoteFetcher(opts) {
769
+ return function (query, signal, context) {
770
+ if (typeof fetch !== 'function') {
771
+ return Promise.reject(new Error('This environment has no fetch().'));
772
+ }
773
+ var page = context && context.page ? context.page : 0;
774
+ var pageSize = opts.fetchPageSize > 0 ? opts.fetchPageSize : 0;
775
+ var url;
776
+ try {
777
+ url = new URL(opts.fetchUrl, (typeof location !== 'undefined' && location.href) || undefined);
778
+ } catch (error) {
779
+ return Promise.reject(new Error('Invalid fetchUrl: ' + opts.fetchUrl));
780
+ }
781
+ if (opts.fetchQueryParam) url.searchParams.set(opts.fetchQueryParam, query || '');
782
+ if (pageSize > 0 && opts.fetchPageSizeParam) {
783
+ url.searchParams.set(opts.fetchPageSizeParam, String(pageSize));
784
+ }
785
+ if (opts.fetchSkipParam) {
786
+ if (pageSize > 0) url.searchParams.set(opts.fetchSkipParam, String(page * pageSize));
787
+ } else if (opts.fetchPageParam) {
788
+ url.searchParams.set(opts.fetchPageParam, String(page + 1));
789
+ }
790
+
791
+ var headers = { Accept: 'application/json' };
792
+ if (opts.fetchHeaders && typeof opts.fetchHeaders === 'object') {
793
+ Object.keys(opts.fetchHeaders).forEach(function (key) {
794
+ headers[key] = opts.fetchHeaders[key];
795
+ });
796
+ }
797
+
798
+ return fetch(url.toString(), {
799
+ method: opts.fetchMethod || 'GET',
800
+ headers: headers,
801
+ signal: signal,
802
+ credentials: opts.fetchCredentials || 'same-origin'
803
+ }).then(function (response) {
804
+ if (!response.ok) {
805
+ throw new Error('Request failed (' + response.status + ' ' + (response.statusText || 'error') + ')');
806
+ }
807
+ return response.json();
808
+ }).then(function (body) {
809
+ var rows = opts.fetchItemsPath ? readDotPath(body, opts.fetchItemsPath) : firstRemoteArray(body);
810
+ if (!Array.isArray(rows)) rows = rows === undefined || rows === null ? [] : [rows];
811
+ var items = rows.map(remoteItem).filter(Boolean);
812
+
813
+ var hasMore;
814
+ if (opts.fetchHasMorePath) hasMore = !!readDotPath(body, opts.fetchHasMorePath);
815
+ var rawTotal = opts.fetchTotalPath ? readDotPath(body, opts.fetchTotalPath)
816
+ : (body && typeof body === 'object' ? body.total : undefined);
817
+ var total = rawTotal === undefined || rawTotal === null ? NaN : Number(rawTotal);
818
+ if (hasMore === undefined && isFinite(total) && pageSize > 0) {
819
+ hasMore = (page + 1) * pageSize < total;
820
+ }
821
+ if (hasMore === undefined) hasMore = pageSize > 0 && items.length >= pageSize;
822
+
823
+ return { items: items, hasMore: hasMore, total: isFinite(total) ? total : undefined };
824
+ });
825
+ };
826
+ }
827
+
711
828
  function ZidanSelect(target, options) {
712
829
  if (!(this instanceof ZidanSelect)) return new ZidanSelect(target, options);
713
830
  if (!doc) throw new Error('ZidanSelect requires a DOM environment.');
@@ -828,6 +945,15 @@
828
945
  merged.autoLoadMore = pick('autoLoadMore', readBoolAttr(d.zidanAutoLoadMore, DEFAULTS.autoLoadMore));
829
946
  merged.cacheResults = pick('cacheResults', readBoolAttr(d.zidanCacheResults, DEFAULTS.cacheResults));
830
947
  merged.loadMoreText = pick('loadMoreText', d.zidanLoadMoreText || DEFAULTS.loadMoreText);
948
+ merged.fetchUrl = pick('fetchUrl', d.zidanFetchUrl || null);
949
+ merged.fetchMethod = pick('fetchMethod', d.zidanFetchMethod || DEFAULTS.fetchMethod);
950
+ merged.fetchQueryParam = pick('fetchQueryParam', d.zidanFetchQueryParam !== undefined ? d.zidanFetchQueryParam : DEFAULTS.fetchQueryParam);
951
+ merged.fetchPageParam = pick('fetchPageParam', d.zidanFetchPageParam !== undefined ? d.zidanFetchPageParam : DEFAULTS.fetchPageParam);
952
+ merged.fetchSkipParam = pick('fetchSkipParam', d.zidanFetchSkipParam || null);
953
+ merged.fetchPageSizeParam = pick('fetchPageSizeParam', d.zidanFetchPageSizeParam !== undefined ? d.zidanFetchPageSizeParam : DEFAULTS.fetchPageSizeParam);
954
+ merged.fetchItemsPath = pick('fetchItemsPath', d.zidanFetchItemsPath || null);
955
+ merged.fetchTotalPath = pick('fetchTotalPath', d.zidanFetchTotalPath || null);
956
+ merged.fetchHasMorePath = pick('fetchHasMorePath', d.zidanFetchHasMorePath || null);
831
957
 
832
958
  // carry over every explicitly-passed option (callbacks, custom classes, ...)
833
959
  Object.keys(options).forEach(function (key) {
@@ -843,6 +969,11 @@
843
969
  if (mode === 'combobox') merged.searchable = true;
844
970
  if (mode === 'tags' && merged.searchable === false) merged.searchable = true;
845
971
  if (mode === 'tags') merged.multiple = true;
972
+
973
+ // declarative AJAX: one URL is enough to opt into remote loading
974
+ if (merged.fetchUrl && typeof merged.fetchOptions !== 'function') {
975
+ merged.fetchOptions = createRemoteFetcher(merged);
976
+ }
846
977
  return merged;
847
978
  };
848
979