// Initialize display immediately when this cell runs
(asyncfunctioninitializeDisplay() {
try {
// Wait a brief moment to ensure DOM elements are readyawaitnewPromise(resolve => setTimeout(resolve, 100));
// Create the item data object with current input valuesconstinitialItemData = {
"title": titleInput,
"URL": urlInput,
"author": authorInput,
"date": dateInput,
"media": mediaInput,
"URLtext": urlTextInput
};
awaitputDataIntoDisplay(initialItemData);
console.log('Initialized iframe and caption');
display('Initialized iframe and caption');
} catch (error) {
display(`Error initializing display: ${error.message}`);
}
})();
// Input form for JSON data using view() for reactivityconsttitleInput = view(Inputs.text({label: "Title", value: "Reading"}));
consturlInput = view(Inputs.text({label: "URL", value: "https://shi.programmatology.com/reading"}));
constauthorInput = view(Inputs.text({label: "Author", value: "John Cayley"}));
constdateInput = view(Inputs.text({label: "Date", value: "2025"}));
constmediaInput = view(Inputs.text({label: "Media", value: ""}));
consturlTextInput = view(Inputs.text({label: "URL Text", value: "shi.programmatology.com/reading"}));
<buttonid="addButton">Add to Array</button>
// Button logic for adding current inputs to the arrayconstaddButton = document.getElementById('addButton');
// Use a mutable value that persists across cell re-evaluations// Only initialize if it doesn't existif (!window.itemsArrayGenerator) {
window.itemsArrayGenerator = Inputs.input([]);
}
addButton.addEventListener('click', async () => {
try {
addButton.disabled = true;
addButton.textContent = 'Adding...';
// Get current array value and add new itemconstcurrentArray = window.itemsArrayGenerator.value;
constnewArray = [...currentArray, {...itemData}];
// Update the input value to trigger reactivitywindow.itemsArrayGenerator.value = newArray;
window.itemsArrayGenerator.dispatchEvent(newEvent('input'));
addButton.textContent = 'Add to Array';
addButton.disabled = false;
} catch (error) {
display(`Error: ${error.message}`);
addButton.textContent = 'Add to Array';
addButton.disabled = false;
}
});
// Create a reactive view of the arrayconstitemsArray = view(window.itemsArrayGenerator);
display(itemsArray);