@purplle/sidebar 1.0.0 → 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/CHANGELOG.md +1 -1
- package/README.md +143 -39
- package/dist/prism-sidebar.js +822 -0
- package/dist/prism-sidebar.js.map +1 -0
- package/dist/prism-sidebar.umd.js +185 -0
- package/dist/prism-sidebar.umd.js.map +1 -0
- package/package.json +9 -8
- package/dist/sidebar.js +0 -544
- package/dist/sidebar.js.map +0 -1
- package/dist/sidebar.umd.js +0 -45
- package/dist/sidebar.umd.js.map +0 -1
package/CHANGELOG.md
CHANGED
package/README.md
CHANGED
|
@@ -1,45 +1,28 @@
|
|
|
1
|
-
# @
|
|
1
|
+
# @avesh.k/prism-sidebar
|
|
2
2
|
|
|
3
|
-
Framework-agnostic sidebar package powered by native Web Components.
|
|
4
|
-
|
|
5
|
-
Custom element tag: `prism-sidebar`
|
|
3
|
+
Framework-agnostic Prism sidebar package powered by native Web Components.
|
|
6
4
|
|
|
7
5
|
## Install
|
|
8
6
|
|
|
9
7
|
```bash
|
|
10
|
-
npm i @
|
|
8
|
+
npm i @avesh.k/prism-sidebar
|
|
11
9
|
```
|
|
12
10
|
|
|
13
11
|
## Registration
|
|
14
12
|
|
|
15
13
|
```ts
|
|
16
|
-
import { registerPrismSidebar } from '@
|
|
14
|
+
import { registerPrismSidebar } from '@avesh.k/prism-sidebar'
|
|
17
15
|
registerPrismSidebar()
|
|
18
16
|
```
|
|
19
17
|
|
|
20
|
-
## Quick Start
|
|
21
|
-
|
|
22
|
-
```html
|
|
23
|
-
<script type="module">
|
|
24
|
-
import { registerPrismSidebar } from '@purplle/sidebar'
|
|
25
|
-
registerPrismSidebar()
|
|
26
|
-
</script>
|
|
27
|
-
<prism-sidebar
|
|
28
|
-
token="abc"
|
|
29
|
-
api-base-url="https://example.com/"
|
|
30
|
-
active-path="/path1"
|
|
31
|
-
target="_self"
|
|
32
|
-
aria-label="Main navigation"
|
|
33
|
-
width="240px"
|
|
34
|
-
></prism-sidebar>
|
|
35
|
-
```
|
|
36
|
-
|
|
37
18
|
## Attributes
|
|
38
19
|
|
|
39
|
-
- `token` (
|
|
40
|
-
- `api-
|
|
41
|
-
- `
|
|
42
|
-
- `
|
|
20
|
+
- `token` (required for API calls)
|
|
21
|
+
- `api-url` (preferred menu endpoint)
|
|
22
|
+
- `api-base-url` (legacy alias for `api-url`)
|
|
23
|
+
- `base-url` (default: current origin)
|
|
24
|
+
- `active-path`
|
|
25
|
+
- `target` (`_self | _blank | _top`, default: `_top`)
|
|
43
26
|
- `use-shadow-dom` (default: `true`)
|
|
44
27
|
- `aria-label` (default: `Sidebar navigation`)
|
|
45
28
|
- `collapsed` (default: `true`)
|
|
@@ -50,36 +33,157 @@ registerPrismSidebar()
|
|
|
50
33
|
- `home-url` (default: `/`)
|
|
51
34
|
- `logout-text` (default: `Logout`)
|
|
52
35
|
- `logout-path` (default: `/sentinel/logout`)
|
|
53
|
-
- `error` (
|
|
36
|
+
- `error` (fallback message override)
|
|
37
|
+
|
|
38
|
+
## JS Properties
|
|
39
|
+
|
|
40
|
+
- `token`
|
|
41
|
+
- `baseUrl`
|
|
42
|
+
- `apiBaseUrl`
|
|
43
|
+
- `apiUrl`
|
|
44
|
+
- `activePath`
|
|
45
|
+
- `target`
|
|
46
|
+
- `useShadowDom`
|
|
47
|
+
- `ariaLabel`
|
|
48
|
+
- `collapsed`
|
|
49
|
+
- `autoNavigate`
|
|
50
|
+
- `width`
|
|
51
|
+
- `title`
|
|
52
|
+
- `subtitle`
|
|
53
|
+
- `homeUrl`
|
|
54
|
+
- `logoutText`
|
|
55
|
+
- `logoutPath`
|
|
56
|
+
- `error`
|
|
57
|
+
|
|
58
|
+
## Events
|
|
59
|
+
|
|
60
|
+
- `sidebar-loaded` (`detail: { menu }`)
|
|
61
|
+
- `sidebar-error` (`detail: { message, cause? }`)
|
|
62
|
+
- `sidebar-item-click` (`detail: { item, resolvedPath, target }`)
|
|
63
|
+
|
|
64
|
+
## Methods
|
|
65
|
+
|
|
66
|
+
- `refresh()`
|
|
67
|
+
- `setActivePath(path)`
|
|
68
|
+
- `setConfig(partialConfig)`
|
|
69
|
+
|
|
70
|
+
## Menu API Shape
|
|
71
|
+
|
|
72
|
+
The component accepts either of the following API response formats:
|
|
73
|
+
|
|
74
|
+
```json
|
|
75
|
+
{ "data": { "menu": [/* items */] } }
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
or
|
|
79
|
+
|
|
80
|
+
```json
|
|
81
|
+
{ "menu": [/* items */] }
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
Each item requires:
|
|
85
|
+
|
|
86
|
+
```json
|
|
87
|
+
{ "id": "string", "name": "string", "path": "/route", "children": [] }
|
|
88
|
+
```
|
|
89
|
+
|
|
90
|
+
`url` is also accepted as a legacy alias for `path`.
|
|
91
|
+
|
|
92
|
+
## Plain HTML
|
|
93
|
+
|
|
94
|
+
```html
|
|
95
|
+
<script type="module">
|
|
96
|
+
import { registerPrismSidebar } from '@avesh.k/prism-sidebar'
|
|
97
|
+
registerPrismSidebar()
|
|
98
|
+
</script>
|
|
99
|
+
<prism-sidebar
|
|
100
|
+
token="abc"
|
|
101
|
+
base-url="https://example.com"
|
|
102
|
+
api-url="https://example.com/sentinel/api/v1/menu"
|
|
103
|
+
active-path="/orders"
|
|
104
|
+
target="_top"
|
|
105
|
+
width="240px"
|
|
106
|
+
></prism-sidebar>
|
|
107
|
+
```
|
|
108
|
+
|
|
109
|
+
## CDN Usage
|
|
110
|
+
|
|
111
|
+
```html
|
|
112
|
+
<script type="module">
|
|
113
|
+
import('https://cdn.jsdelivr.net/npm/@avesh.k/prism-sidebar@1.0.5/dist/prism-sidebar.js')
|
|
114
|
+
.then(({ registerPrismSidebar }) => registerPrismSidebar())
|
|
115
|
+
</script>
|
|
116
|
+
<prism-sidebar token="abc" base-url="https://example.com"></prism-sidebar>
|
|
117
|
+
```
|
|
54
118
|
|
|
55
119
|
## React
|
|
56
120
|
|
|
57
121
|
```tsx
|
|
58
122
|
import { useEffect } from 'react'
|
|
123
|
+
import { registerPrismSidebar } from '@avesh.k/prism-sidebar'
|
|
59
124
|
|
|
60
125
|
export function App() {
|
|
61
126
|
useEffect(() => {
|
|
62
|
-
|
|
63
|
-
if (mod?.registerPrismSidebar) mod.registerPrismSidebar();
|
|
64
|
-
}).catch(() => {});
|
|
127
|
+
registerPrismSidebar()
|
|
65
128
|
}, [])
|
|
66
|
-
return <prism-sidebar token="abc" api-
|
|
129
|
+
return <prism-sidebar token="abc" api-url="https://example.com/sentinel/api/v1/menu" />
|
|
67
130
|
}
|
|
68
131
|
```
|
|
69
132
|
|
|
133
|
+
## Angular
|
|
134
|
+
|
|
135
|
+
Register once in bootstrap and consume directly:
|
|
136
|
+
|
|
137
|
+
```html
|
|
138
|
+
<prism-sidebar [attr.token]="token" [attr.api-base-url]="apiBaseUrl"></prism-sidebar>
|
|
139
|
+
```
|
|
140
|
+
|
|
70
141
|
## SolidJS
|
|
71
142
|
|
|
72
143
|
```tsx
|
|
73
144
|
import { onMount } from 'solid-js'
|
|
74
|
-
import { registerPrismSidebar } from '@
|
|
145
|
+
import { registerPrismSidebar } from '@avesh.k/prism-sidebar'
|
|
75
146
|
|
|
76
147
|
export default function App() {
|
|
77
|
-
onMount(() =>
|
|
78
|
-
|
|
79
|
-
if (mod?.registerPrismSidebar) mod.registerPrismSidebar();
|
|
80
|
-
}).catch(() => {});
|
|
81
|
-
})
|
|
82
|
-
return <prism-sidebar token="abc" api-base-url="https://api.example.com/menu" />
|
|
148
|
+
onMount(() => registerPrismSidebar())
|
|
149
|
+
return <prism-sidebar token="abc" api-url="https://example.com/sentinel/api/v1/menu" />
|
|
83
150
|
}
|
|
84
151
|
```
|
|
85
152
|
|
|
153
|
+
## iframe-safe activePath
|
|
154
|
+
|
|
155
|
+
Pass `active-path` from the host application to avoid iframe routing mismatch. This is the recommended integration pattern in nested iframe environments.
|
|
156
|
+
|
|
157
|
+
## Type Exports
|
|
158
|
+
|
|
159
|
+
```ts
|
|
160
|
+
import type {
|
|
161
|
+
SidebarConfig,
|
|
162
|
+
SidebarConfigInput,
|
|
163
|
+
SidebarNavigationTarget,
|
|
164
|
+
SidebarMenuItem,
|
|
165
|
+
SidebarLoadedEventDetail,
|
|
166
|
+
SidebarErrorEventDetail,
|
|
167
|
+
SidebarItemClickEventDetail
|
|
168
|
+
} from '@avesh.k/prism-sidebar'
|
|
169
|
+
```
|
|
170
|
+
|
|
171
|
+
## Testing
|
|
172
|
+
|
|
173
|
+
```bash
|
|
174
|
+
npm run test
|
|
175
|
+
npm run test:e2e
|
|
176
|
+
```
|
|
177
|
+
|
|
178
|
+
## Publishing
|
|
179
|
+
|
|
180
|
+
Set `.npmrc` for internal registry and publish with:
|
|
181
|
+
|
|
182
|
+
```bash
|
|
183
|
+
npm run build
|
|
184
|
+
npm publish
|
|
185
|
+
```
|
|
186
|
+
|
|
187
|
+
## Versioning
|
|
188
|
+
|
|
189
|
+
Use semantic versioning: patch for fixes, minor for backward-compatible features, major for breaking changes.
|