@smart-wizard/extension-url-hash 0.0.0-stage → 1.0.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/LICENSE +21 -0
- package/README.md +40 -2
- package/dist/index.d.mts +29 -0
- package/dist/index.d.ts +29 -0
- package/dist/index.js +81 -0
- package/dist/index.mjs +56 -0
- package/package.json +54 -3
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 Dipu Rajendran
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,41 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @smart-wizard/extension-url-hash
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
**Official URL hash and browser history navigation extension for SmartWizard.**
|
|
4
|
+
Synchronizes active steps with `window.location.hash` and integrates with browser back/forward buttons.
|
|
5
|
+
|
|
6
|
+
> This package is part of the **[SmartWizard](https://github.com/techlab/smart-wizard)** project, the next-generation continuation of the popular jQuery SmartWizard.
|
|
7
|
+
|
|
8
|
+
---
|
|
9
|
+
|
|
10
|
+
## 📖 Documentation & Links
|
|
11
|
+
|
|
12
|
+
* 📚 **Full Documentation & Guides**: [GitHub Readme](https://github.com/techlab/smart-wizard#-extension-system)
|
|
13
|
+
* 🌐 **Official Website & Demos**: [techlaboratory.net/smart-wizard](https://techlaboratory.net/smart-wizard)
|
|
14
|
+
* 🐙 **Repository**: [github.com/techlab/smart-wizard](https://github.com/techlab/smart-wizard)
|
|
15
|
+
* 🐛 **Issue Tracker**: [github.com/techlab/smart-wizard/issues](https://github.com/techlab/smart-wizard/issues)
|
|
16
|
+
|
|
17
|
+
---
|
|
18
|
+
|
|
19
|
+
## 📥 Installation
|
|
20
|
+
|
|
21
|
+
```bash
|
|
22
|
+
npm install @smart-wizard/extension-url-hash @smart-wizard/core
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
---
|
|
26
|
+
|
|
27
|
+
## ⚡ Quick Example
|
|
28
|
+
|
|
29
|
+
```typescript
|
|
30
|
+
import { SmartWizard } from '@smart-wizard/core';
|
|
31
|
+
import { createUrlHashExtension } from '@smart-wizard/extension-url-hash';
|
|
32
|
+
|
|
33
|
+
const wizard = new SmartWizard('#wizard', options)
|
|
34
|
+
.extend(createUrlHashExtension({ supportHistory: true })); // pushState vs location.hash
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
---
|
|
38
|
+
|
|
39
|
+
## 📝 License
|
|
40
|
+
|
|
41
|
+
Dual-licensed under [MIT](https://github.com/techlab/smart-wizard/blob/main/LICENSE) (open-source) and [Commercial License](https://techlaboratory.net/smart-wizard#license).
|
package/dist/index.d.mts
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { WizardExtension } from '@smart-wizard/core';
|
|
2
|
+
|
|
3
|
+
interface UrlHashOptions {
|
|
4
|
+
/**
|
|
5
|
+
* Push step changes to browser history so back/forward buttons work.
|
|
6
|
+
* Set to `false` to use `location.hash` (replaces history instead).
|
|
7
|
+
* @default true
|
|
8
|
+
*/
|
|
9
|
+
supportHistory?: boolean;
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* URL Hash Extension for SmartWizard.
|
|
13
|
+
*
|
|
14
|
+
* - Reads `window.location.hash` on load and navigates to the matching step.
|
|
15
|
+
* - Updates the URL hash after every step change.
|
|
16
|
+
* - Listens to `hashchange` so the browser back/forward buttons work.
|
|
17
|
+
*
|
|
18
|
+
* @example
|
|
19
|
+
* ```ts
|
|
20
|
+
* import { SmartWizard } from '@smart-wizard/core';
|
|
21
|
+
* import { createUrlHashExtension } from '@smart-wizard/extension-url-hash';
|
|
22
|
+
*
|
|
23
|
+
* const wizard = new SmartWizard('#wizard', options)
|
|
24
|
+
* .extend(createUrlHashExtension({ supportHistory: true }));
|
|
25
|
+
* ```
|
|
26
|
+
*/
|
|
27
|
+
declare function createUrlHashExtension(options?: UrlHashOptions): WizardExtension;
|
|
28
|
+
|
|
29
|
+
export { type UrlHashOptions, createUrlHashExtension };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { WizardExtension } from '@smart-wizard/core';
|
|
2
|
+
|
|
3
|
+
interface UrlHashOptions {
|
|
4
|
+
/**
|
|
5
|
+
* Push step changes to browser history so back/forward buttons work.
|
|
6
|
+
* Set to `false` to use `location.hash` (replaces history instead).
|
|
7
|
+
* @default true
|
|
8
|
+
*/
|
|
9
|
+
supportHistory?: boolean;
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* URL Hash Extension for SmartWizard.
|
|
13
|
+
*
|
|
14
|
+
* - Reads `window.location.hash` on load and navigates to the matching step.
|
|
15
|
+
* - Updates the URL hash after every step change.
|
|
16
|
+
* - Listens to `hashchange` so the browser back/forward buttons work.
|
|
17
|
+
*
|
|
18
|
+
* @example
|
|
19
|
+
* ```ts
|
|
20
|
+
* import { SmartWizard } from '@smart-wizard/core';
|
|
21
|
+
* import { createUrlHashExtension } from '@smart-wizard/extension-url-hash';
|
|
22
|
+
*
|
|
23
|
+
* const wizard = new SmartWizard('#wizard', options)
|
|
24
|
+
* .extend(createUrlHashExtension({ supportHistory: true }));
|
|
25
|
+
* ```
|
|
26
|
+
*/
|
|
27
|
+
declare function createUrlHashExtension(options?: UrlHashOptions): WizardExtension;
|
|
28
|
+
|
|
29
|
+
export { type UrlHashOptions, createUrlHashExtension };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/index.ts
|
|
21
|
+
var index_exports = {};
|
|
22
|
+
__export(index_exports, {
|
|
23
|
+
createUrlHashExtension: () => createUrlHashExtension
|
|
24
|
+
});
|
|
25
|
+
module.exports = __toCommonJS(index_exports);
|
|
26
|
+
function createUrlHashExtension(options = {}) {
|
|
27
|
+
const { supportHistory = true } = options;
|
|
28
|
+
let hashChangeHandler = null;
|
|
29
|
+
function findStepByHash(wizard, hash) {
|
|
30
|
+
for (let i = 0; i < wizard.stepItems.length; i++) {
|
|
31
|
+
if (wizard.stepItems[i].step.getAttribute("href") === hash) return i;
|
|
32
|
+
}
|
|
33
|
+
return null;
|
|
34
|
+
}
|
|
35
|
+
function updateUrl(wizard, stepIdx) {
|
|
36
|
+
const href = wizard.stepItems[stepIdx]?.step.getAttribute("href");
|
|
37
|
+
if (!href) return;
|
|
38
|
+
if (supportHistory && window.history?.pushState) {
|
|
39
|
+
window.history.pushState(null, "", href);
|
|
40
|
+
} else {
|
|
41
|
+
window.location.replace(
|
|
42
|
+
window.location.pathname + window.location.search + href
|
|
43
|
+
);
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
return {
|
|
47
|
+
name: "url-hash",
|
|
48
|
+
onLoad(wizard) {
|
|
49
|
+
const hash = window.location.hash;
|
|
50
|
+
if (hash) {
|
|
51
|
+
const idx = findStepByHash(wizard, hash);
|
|
52
|
+
if (idx !== null && idx !== wizard.activeIndex) {
|
|
53
|
+
wizard.goTo(idx);
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
if (hashChangeHandler) return;
|
|
57
|
+
hashChangeHandler = () => {
|
|
58
|
+
const h = window.location.hash;
|
|
59
|
+
if (!h) return;
|
|
60
|
+
const i = findStepByHash(wizard, h);
|
|
61
|
+
if (i !== null && i !== wizard.activeIndex) {
|
|
62
|
+
wizard.goTo(i);
|
|
63
|
+
}
|
|
64
|
+
};
|
|
65
|
+
window.addEventListener("hashchange", hashChangeHandler);
|
|
66
|
+
},
|
|
67
|
+
onAfterShow(wizard, { stepIdx }) {
|
|
68
|
+
updateUrl(wizard, stepIdx);
|
|
69
|
+
},
|
|
70
|
+
onDestroy() {
|
|
71
|
+
if (hashChangeHandler) {
|
|
72
|
+
window.removeEventListener("hashchange", hashChangeHandler);
|
|
73
|
+
hashChangeHandler = null;
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
};
|
|
77
|
+
}
|
|
78
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
79
|
+
0 && (module.exports = {
|
|
80
|
+
createUrlHashExtension
|
|
81
|
+
});
|
package/dist/index.mjs
ADDED
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
// src/index.ts
|
|
2
|
+
function createUrlHashExtension(options = {}) {
|
|
3
|
+
const { supportHistory = true } = options;
|
|
4
|
+
let hashChangeHandler = null;
|
|
5
|
+
function findStepByHash(wizard, hash) {
|
|
6
|
+
for (let i = 0; i < wizard.stepItems.length; i++) {
|
|
7
|
+
if (wizard.stepItems[i].step.getAttribute("href") === hash) return i;
|
|
8
|
+
}
|
|
9
|
+
return null;
|
|
10
|
+
}
|
|
11
|
+
function updateUrl(wizard, stepIdx) {
|
|
12
|
+
const href = wizard.stepItems[stepIdx]?.step.getAttribute("href");
|
|
13
|
+
if (!href) return;
|
|
14
|
+
if (supportHistory && window.history?.pushState) {
|
|
15
|
+
window.history.pushState(null, "", href);
|
|
16
|
+
} else {
|
|
17
|
+
window.location.replace(
|
|
18
|
+
window.location.pathname + window.location.search + href
|
|
19
|
+
);
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
return {
|
|
23
|
+
name: "url-hash",
|
|
24
|
+
onLoad(wizard) {
|
|
25
|
+
const hash = window.location.hash;
|
|
26
|
+
if (hash) {
|
|
27
|
+
const idx = findStepByHash(wizard, hash);
|
|
28
|
+
if (idx !== null && idx !== wizard.activeIndex) {
|
|
29
|
+
wizard.goTo(idx);
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
if (hashChangeHandler) return;
|
|
33
|
+
hashChangeHandler = () => {
|
|
34
|
+
const h = window.location.hash;
|
|
35
|
+
if (!h) return;
|
|
36
|
+
const i = findStepByHash(wizard, h);
|
|
37
|
+
if (i !== null && i !== wizard.activeIndex) {
|
|
38
|
+
wizard.goTo(i);
|
|
39
|
+
}
|
|
40
|
+
};
|
|
41
|
+
window.addEventListener("hashchange", hashChangeHandler);
|
|
42
|
+
},
|
|
43
|
+
onAfterShow(wizard, { stepIdx }) {
|
|
44
|
+
updateUrl(wizard, stepIdx);
|
|
45
|
+
},
|
|
46
|
+
onDestroy() {
|
|
47
|
+
if (hashChangeHandler) {
|
|
48
|
+
window.removeEventListener("hashchange", hashChangeHandler);
|
|
49
|
+
hashChangeHandler = null;
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
export {
|
|
55
|
+
createUrlHashExtension
|
|
56
|
+
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,57 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@smart-wizard/extension-url-hash",
|
|
3
|
-
"version": "
|
|
4
|
-
"
|
|
5
|
-
"
|
|
3
|
+
"version": "1.0.1",
|
|
4
|
+
"description": "URL hash + browser history navigation extension for SmartWizard",
|
|
5
|
+
"main": "dist/index.js",
|
|
6
|
+
"module": "dist/index.mjs",
|
|
7
|
+
"types": "dist/index.d.ts",
|
|
8
|
+
"keywords": [
|
|
9
|
+
"extension",
|
|
10
|
+
"history",
|
|
11
|
+
"smartwizard",
|
|
12
|
+
"url-hash",
|
|
13
|
+
"wizard"
|
|
14
|
+
],
|
|
15
|
+
"license": "MIT",
|
|
16
|
+
"peerDependencies": {
|
|
17
|
+
"@smart-wizard/core": ">=1.0.1"
|
|
18
|
+
},
|
|
19
|
+
"devDependencies": {
|
|
20
|
+
"tsup": "^8.0.0",
|
|
21
|
+
"typescript": "^5.0.0",
|
|
22
|
+
"@smart-wizard/core": "1.0.1"
|
|
23
|
+
},
|
|
24
|
+
"repository": {
|
|
25
|
+
"type": "git",
|
|
26
|
+
"url": "https://github.com/techlab/smart-wizard.git",
|
|
27
|
+
"directory": "packages/extensions/url-hash"
|
|
28
|
+
},
|
|
29
|
+
"homepage": "https://github.com/techlab/smart-wizard#readme",
|
|
30
|
+
"bugs": {
|
|
31
|
+
"url": "https://github.com/techlab/smart-wizard/issues"
|
|
32
|
+
},
|
|
33
|
+
"author": {
|
|
34
|
+
"name": "Dipu Rajendran",
|
|
35
|
+
"email": "hello.techlab@gmail.com",
|
|
36
|
+
"url": "https://github.com/techlab"
|
|
37
|
+
},
|
|
38
|
+
"publishConfig": {
|
|
39
|
+
"access": "public"
|
|
40
|
+
},
|
|
41
|
+
"files": [
|
|
42
|
+
"dist",
|
|
43
|
+
"README.md",
|
|
44
|
+
"LICENSE"
|
|
45
|
+
],
|
|
46
|
+
"exports": {
|
|
47
|
+
".": {
|
|
48
|
+
"types": "./dist/index.d.ts",
|
|
49
|
+
"import": "./dist/index.mjs",
|
|
50
|
+
"require": "./dist/index.js"
|
|
51
|
+
}
|
|
52
|
+
},
|
|
53
|
+
"scripts": {
|
|
54
|
+
"build": "tsup src/index.ts --format cjs,esm --dts --external @smart-wizard/core",
|
|
55
|
+
"dev": "tsup src/index.ts --format cjs,esm --dts --watch --external @smart-wizard/core"
|
|
56
|
+
}
|
|
6
57
|
}
|