Skip to content

Commit 7d5bd5d

Browse files
committed
update wc demo page
1 parent 2b7cdfa commit 7d5bd5d

File tree

1 file changed

+36
-15
lines changed

1 file changed

+36
-15
lines changed

packages/jsonforms-vuetify-webcomponent/index.html

Lines changed: 36 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -137,29 +137,30 @@
137137
<script type="module">
138138
import { examples } from './src/examples/index.js';
139139

140-
let currentExampleIndex = 0;
140+
let currentExampleId = null;
141141
const form = document.querySelector('vuetify-json-forms');
142142
const exampleIcon = document.getElementById('exampleIcon');
143143
const exampleList = document.getElementById('exampleList');
144144

145-
// Function to load an example
146-
function loadExample(exampleIndex) {
147-
// Check if examples array exists and index is valid
145+
// Function to find example by ID
146+
function findExampleById(exampleId) {
148147
if (!examples || examples.length === 0) {
149-
console.warn('No examples available');
150-
return;
148+
return null;
151149
}
150+
return examples.find((example) => example.id === exampleId);
151+
}
152152

153-
if (exampleIndex < 0 || exampleIndex >= examples.length) {
154-
console.warn(
155-
`Invalid example index: ${exampleIndex}. Available: 0-${examples.length - 1}`,
156-
);
153+
// Function to load an example by ID
154+
function loadExample(exampleId) {
155+
// Check if examples array exists
156+
if (!examples || examples.length === 0) {
157+
console.warn('No examples available');
157158
return;
158159
}
159160

160-
const example = examples[exampleIndex];
161+
const example = findExampleById(exampleId);
161162
if (!example) {
162-
console.warn(`Example at index ${exampleIndex} is null or undefined`);
163+
console.warn(`Example with ID '${exampleId}' not found`);
163164
return;
164165
}
165166

@@ -192,7 +193,7 @@
192193
}
193194
}
194195

195-
currentExampleIndex = exampleIndex;
196+
currentExampleId = exampleId;
196197
console.log('Selected example:', example);
197198
}
198199

@@ -207,14 +208,22 @@
207208

208209
// Populate example list
209210
function populateExampleList() {
211+
if (!examples || examples.length === 0) {
212+
console.warn('No examples available for list');
213+
return;
214+
}
215+
210216
exampleList.innerHTML = '';
211217
examples.forEach((example, index) => {
212218
const item = document.createElement('div');
213219
item.className = 'example-item';
214220
item.innerHTML = `<div class="example-item-name">${example.title || `Example ${index + 1}`}</div>`;
215221

222+
// Store the example ID in a data attribute for easier access
223+
item.dataset.exampleId = example.id;
224+
216225
item.addEventListener('click', () => {
217-
loadExample(index);
226+
loadExample(example.id);
218227
exampleList.classList.remove('show');
219228
});
220229

@@ -240,7 +249,19 @@
240249

241250
// Initialize
242251
populateExampleList();
243-
loadExample(1); // Load first example by default
252+
253+
// Load first example by ID if available
254+
if (examples && examples.length > 0) {
255+
// get the demo example and if not registered get the first available
256+
const example = findExampleById('demo') ?? examples[0];
257+
if (example?.id) {
258+
loadExample(example.id);
259+
} else {
260+
console.warn('First example does not have an ID');
261+
}
262+
} else {
263+
console.warn('No examples available to load');
264+
}
244265
</script>
245266
</body>
246267
</html>

0 commit comments

Comments
 (0)