@customviews-js/customviews 1.0.3 → 1.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +147 -31
- package/dist/{custom-views.cjs.js → custom-views.core.cjs.js} +813 -113
- package/dist/custom-views.core.cjs.js.map +1 -0
- package/dist/custom-views.core.esm.js +2296 -0
- package/dist/custom-views.core.esm.js.map +1 -0
- package/dist/custom-views.esm.js +813 -112
- package/dist/custom-views.esm.js.map +1 -1
- package/dist/{custom-views.umd.js → custom-views.js} +813 -113
- package/dist/custom-views.js.map +1 -0
- package/dist/custom-views.min.js +7 -0
- package/dist/custom-views.min.js.map +1 -0
- package/dist/types/{models/AssetsManager.d.ts → core/assets-manager.d.ts} +1 -1
- package/dist/types/{models/AssetsManager.d.ts.map → core/assets-manager.d.ts.map} +1 -1
- package/dist/types/core/core.d.ts +25 -9
- package/dist/types/core/core.d.ts.map +1 -1
- package/dist/types/core/custom-elements.d.ts +8 -0
- package/dist/types/core/custom-elements.d.ts.map +1 -0
- package/dist/types/core/render.d.ts +1 -1
- package/dist/types/core/render.d.ts.map +1 -1
- package/dist/types/core/tab-manager.d.ts +35 -0
- package/dist/types/core/tab-manager.d.ts.map +1 -0
- package/dist/types/core/url-state-manager.d.ts.map +1 -1
- package/dist/types/core/visibility-manager.d.ts +1 -1
- package/dist/types/core/widget.d.ts +2 -0
- package/dist/types/core/widget.d.ts.map +1 -1
- package/dist/types/entry/browser-entry.d.ts +13 -0
- package/dist/types/entry/browser-entry.d.ts.map +1 -0
- package/dist/types/index.d.ts +11 -21
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/lib/custom-views.d.ts +29 -0
- package/dist/types/lib/custom-views.d.ts.map +1 -0
- package/dist/types/styles/styles.d.ts +2 -0
- package/dist/types/styles/styles.d.ts.map +1 -1
- package/dist/types/styles/tab-styles.d.ts +5 -0
- package/dist/types/styles/tab-styles.d.ts.map +1 -0
- package/dist/types/styles/toggle-styles.d.ts +5 -0
- package/dist/types/styles/toggle-styles.d.ts.map +1 -0
- package/dist/types/styles/widget-styles.d.ts +1 -1
- package/dist/types/styles/widget-styles.d.ts.map +1 -1
- package/dist/types/types/types.d.ts +85 -0
- package/dist/types/types/types.d.ts.map +1 -1
- package/dist/types/utils/url-utils.d.ts +8 -0
- package/dist/types/utils/url-utils.d.ts.map +1 -0
- package/package.json +13 -9
- package/dist/custom-views.cjs.js.map +0 -1
- package/dist/custom-views.umd.js.map +0 -1
- package/dist/custom-views.umd.min.js +0 -7
- package/dist/custom-views.umd.min.js.map +0 -1
- package/dist/types/models/Config.d.ts +0 -10
- package/dist/types/models/Config.d.ts.map +0 -1
package/README.md
CHANGED
|
@@ -1,61 +1,75 @@
|
|
|
1
1
|
# Custom Views
|
|
2
2
|
|
|
3
|
-
v1.
|
|
3
|
+
v1.1.0
|
|
4
4
|
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
## Installation
|
|
5
|
+
[npm package link](https://www.npmjs.com/package/@customviews-js/customviews)
|
|
8
6
|
|
|
9
|
-
|
|
10
|
-
npm install customviews
|
|
11
|
-
```
|
|
7
|
+
A JavaScript library for creating contextual, adaptive web content. Perfect for educational websites, documentation, and multi-audience platforms.
|
|
12
8
|
|
|
13
9
|
## Quick Start
|
|
14
10
|
|
|
15
11
|
### HTML Setup
|
|
16
12
|
|
|
17
13
|
```html
|
|
18
|
-
<!-- Mark content with data-
|
|
19
|
-
<div data-
|
|
14
|
+
<!-- Mark content with data-cv-toggle attribute -->
|
|
15
|
+
<div data-cv-toggle="beginner">
|
|
20
16
|
<p>Beginner content here</p>
|
|
21
17
|
</div>
|
|
22
18
|
|
|
23
|
-
<div data-
|
|
19
|
+
<div data-cv-toggle="advanced">
|
|
24
20
|
<p>Advanced content here</p>
|
|
25
21
|
</div>
|
|
26
22
|
|
|
27
23
|
<!-- Dynamic content with ID -->
|
|
28
|
-
<div data-
|
|
24
|
+
<div data-cv-toggle="beginner" data-cv-id="intro-guide"></div>
|
|
29
25
|
```
|
|
30
26
|
|
|
31
|
-
###
|
|
27
|
+
### Simple Setup
|
|
32
28
|
|
|
33
29
|
```html
|
|
34
|
-
<script src="https://unpkg.com/@customviews-js/customviews
|
|
30
|
+
<script src="https://unpkg.com/@customviews-js/customviews"></script>
|
|
35
31
|
```
|
|
36
|
-
Additionally, you can bundle or copy the script into your own site.
|
|
37
32
|
|
|
33
|
+
This auto-init script will:
|
|
34
|
+
1. Automatically load configuration from `/customviews.config.json`
|
|
35
|
+
2. Initialize the core library
|
|
36
|
+
3. Create and render the widget if enabled
|
|
38
37
|
|
|
39
|
-
|
|
38
|
+
#### Configuration File
|
|
40
39
|
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
40
|
+
Create a `customviews.config.json` file in your site root:
|
|
41
|
+
|
|
42
|
+
```json
|
|
43
|
+
{
|
|
44
|
+
"core": {
|
|
45
|
+
"config": {
|
|
46
|
+
"allToggles": ["beginner", "advanced"],
|
|
47
|
+
"defaultState": {
|
|
48
|
+
"toggles": ["beginner"]
|
|
49
|
+
}
|
|
50
|
+
},
|
|
51
|
+
"assetsJsonPath": "/assets.json"
|
|
47
52
|
},
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
53
|
+
"widget": {
|
|
54
|
+
"enabled": true,
|
|
55
|
+
"position": "middle-left",
|
|
56
|
+
"showWelcome": true
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
```
|
|
51
60
|
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
61
|
+
#### Script Attributes
|
|
62
|
+
|
|
63
|
+
The auto-init script supports these data attributes:
|
|
64
|
+
- `data-base-url`: Base URL for all paths (e.g., `/customviews`)
|
|
65
|
+
- `data-config-path`: Custom path to config file (default: `/customviews.config.json`)
|
|
66
|
+
|
|
67
|
+
```html
|
|
68
|
+
<script
|
|
69
|
+
src="https://unpkg.com/@customviews-js/customviews"
|
|
70
|
+
data-base-url="/my-site"
|
|
71
|
+
data-config-path="/configs/custom-views.json">
|
|
72
|
+
</script>
|
|
59
73
|
```
|
|
60
74
|
|
|
61
75
|
## Widget Features
|
|
@@ -83,6 +97,66 @@ widget.render();
|
|
|
83
97
|
- `baseURL` is automatically prepended to `configPath`, `assetsJsonPath`, and all asset `src` paths.
|
|
84
98
|
- Absolute URLs (starting with `http://` or `https://`) are not modified.
|
|
85
99
|
|
|
100
|
+
## Configuration File Format
|
|
101
|
+
|
|
102
|
+
When using auto-initialization, the config file follows this structure:
|
|
103
|
+
|
|
104
|
+
```typescript
|
|
105
|
+
{
|
|
106
|
+
core: {
|
|
107
|
+
config?: any; // Core configuration object
|
|
108
|
+
configPath?: string; // Path to the configuration file
|
|
109
|
+
assetsJsonPath?: string; // Path to the assets JSON file
|
|
110
|
+
baseURL?: string; // Base URL for all paths
|
|
111
|
+
};
|
|
112
|
+
|
|
113
|
+
widget?: {
|
|
114
|
+
enabled?: boolean; // Whether the widget is enabled
|
|
115
|
+
position?: string; // Widget position
|
|
116
|
+
theme?: 'light' | 'dark'; // Widget theme
|
|
117
|
+
showReset?: boolean; // Whether to show reset button
|
|
118
|
+
title?: string; // Widget title
|
|
119
|
+
description?: string; // Widget description text
|
|
120
|
+
showWelcome?: boolean; // Whether to show welcome modal on first visit
|
|
121
|
+
welcomeTitle?: string; // Welcome modal title
|
|
122
|
+
welcomeMessage?: string; // Welcome modal message
|
|
123
|
+
};
|
|
124
|
+
}
|
|
125
|
+
```
|
|
126
|
+
|
|
127
|
+
## Events
|
|
128
|
+
|
|
129
|
+
### `customviews:ready` Event
|
|
130
|
+
|
|
131
|
+
When using auto-initialization, a `customviews:ready` event is dispatched when CustomViews is fully initialized:
|
|
132
|
+
|
|
133
|
+
```javascript
|
|
134
|
+
document.addEventListener('customviews:ready', (event) => {
|
|
135
|
+
const { core, widget } = event.detail;
|
|
136
|
+
|
|
137
|
+
// You can now access the core and widget instances
|
|
138
|
+
console.log('CustomViews initialized!');
|
|
139
|
+
|
|
140
|
+
// Example: Programmatically change state
|
|
141
|
+
core.applyState({ toggles: ['advanced'] });
|
|
142
|
+
});
|
|
143
|
+
```
|
|
144
|
+
|
|
145
|
+
### Global Instance Access
|
|
146
|
+
|
|
147
|
+
When using auto-initialization, the core and widget instances are stored on the `window` object:
|
|
148
|
+
|
|
149
|
+
```javascript
|
|
150
|
+
// Access the core instance
|
|
151
|
+
const core = window.customViewsInstance.core;
|
|
152
|
+
|
|
153
|
+
// Access the widget instance (if enabled)
|
|
154
|
+
const widget = window.customViewsInstance.widget;
|
|
155
|
+
|
|
156
|
+
// Example: Programmatically change state
|
|
157
|
+
core.applyState({ toggles: ['advanced'] });
|
|
158
|
+
```
|
|
159
|
+
|
|
86
160
|
## Widget Options
|
|
87
161
|
|
|
88
162
|
```typescript
|
|
@@ -99,6 +173,48 @@ widget.render();
|
|
|
99
173
|
}
|
|
100
174
|
```
|
|
101
175
|
|
|
176
|
+
## Assets JSON Setup
|
|
177
|
+
|
|
178
|
+
The `assets.json` file defines reusable content that can be dynamically injected into your pages. Each asset is referenced by a unique key and can contain images, HTML, or text.
|
|
179
|
+
* Note that `baseURL` defined during initialization is automatically prepended to all asset `src` paths.
|
|
180
|
+
|
|
181
|
+
### Structure
|
|
182
|
+
|
|
183
|
+
```json
|
|
184
|
+
{
|
|
185
|
+
"htmlContent": {
|
|
186
|
+
"content": "<h2>Dynamic HTML</h2><p>This content is injected dynamically.</p>"
|
|
187
|
+
},
|
|
188
|
+
"textContent": {
|
|
189
|
+
"content": "Plain text content"
|
|
190
|
+
},
|
|
191
|
+
"imageContent": {
|
|
192
|
+
"src": "/assets/mac.png"
|
|
193
|
+
},
|
|
194
|
+
"assetKey": {
|
|
195
|
+
"src": "/path/to/image.png",
|
|
196
|
+
"alt": "Description",
|
|
197
|
+
"className": "custom-class",
|
|
198
|
+
"style": "border-radius: 8px;"
|
|
199
|
+
},
|
|
200
|
+
}
|
|
201
|
+
```
|
|
202
|
+
|
|
203
|
+
### Asset Properties
|
|
204
|
+
|
|
205
|
+
- **`src`**: Image URL (makes it an image asset), **`content`**: Text or HTML content (auto-detected)
|
|
206
|
+
- **`alt`**: Alt text for images, **`className`**: CSS classes to apply, **`style`**: Inline CSS styles
|
|
207
|
+
|
|
208
|
+
### Usage in HTML
|
|
209
|
+
|
|
210
|
+
```html
|
|
211
|
+
<!-- Reference asset by key using data-cv-id (or data-customviews-id for backward compatibility) -->
|
|
212
|
+
<div data-cv-toggle="beginner" data-cv-id="assetKey"></div>
|
|
213
|
+
```
|
|
214
|
+
|
|
215
|
+
When the toggle is active, the asset will be automatically rendered into the element.
|
|
216
|
+
|
|
217
|
+
|
|
102
218
|
## License
|
|
103
219
|
|
|
104
220
|
MIT
|