commit 18405def54d4ea00f2e3225b2d6da454065fa40c
Author: root <root@hub.scroll.pub> Date: 2024-12-28 02:29:34 +0000 Subject: Initial commit diff --git a/body.html b/body.html new file mode 100644 index 0000000..7948462 --- /dev/null +++ b/body.html @@ -0,0 +1,34 @@ +<header> + <nav> + <h1>CRUD API Demo</h1> + </nav> +</header> + +<main> + <section class="crud-container"> + <div class="form-container"> + <h2>Add/Edit Item</h2> + <form id="itemForm"> + <input type="hidden" id="itemId"> + <div class="input-group"> + <label for="itemName">Name</label> + <input type="text" id="itemName" required> + </div> + <div class="input-group"> + <label for="itemDescription">Description</label> + <textarea id="itemDescription" required></textarea> + </div> + <button type="submit" class="btn-primary">Save Item</button> + </form> + </div> + + <div class="items-container"> + <h2>Items List</h2> + <div id="itemsList" class="items-grid"></div> + </div> + </section> +</main> + +<footer> + <p>Built with vanilla JavaScript</p> +</footer> diff --git a/index.scroll b/index.scroll new file mode 100644 index 0000000..15fa6a2 --- /dev/null +++ b/index.scroll @@ -0,0 +1,8 @@ +buildHtml +baseUrl https://crud.scroll.pub +metaTags +editButton /edit.html +title CRUD API Demo +style.css +body.html +script.js diff --git a/prompt.json b/prompt.json new file mode 100644 index 0000000..0634932 --- /dev/null +++ b/prompt.json @@ -0,0 +1,20 @@ +{ + "id": "msg_01SyZgSjHf18J8QUWJa1Mo5W", + "type": "message", + "role": "assistant", + "model": "claude-3-5-sonnet-20241022", + "content": [ + { + "type": "text", + "text": "Let me create a sleek CRUD API demo website.\n\n---domain---\ncrud.scroll.pub\n\n---index.scroll---\nbuildHtml\nbaseUrl https://crud.scroll.pub\nmetaTags\neditButton /edit.html\ntitle CRUD API Demo\nstyle.css\nbody.html\nscript.js\n\n---body.html---\n<header>\n <nav>\n <h1>CRUD API Demo</h1>\n </nav>\n</header>\n\n<main>\n <section class=\"crud-container\">\n <div class=\"form-container\">\n <h2>Add/Edit Item</h2>\n <form id=\"itemForm\">\n <input type=\"hidden\" id=\"itemId\">\n <div class=\"input-group\">\n <label for=\"itemName\">Name</label>\n <input type=\"text\" id=\"itemName\" required>\n </div>\n <div class=\"input-group\">\n <label for=\"itemDescription\">Description</label>\n <textarea id=\"itemDescription\" required></textarea>\n </div>\n <button type=\"submit\" class=\"btn-primary\">Save Item</button>\n </form>\n </div>\n\n <div class=\"items-container\">\n <h2>Items List</h2>\n <div id=\"itemsList\" class=\"items-grid\"></div>\n </div>\n </section>\n</main>\n\n<footer>\n <p>Built with vanilla JavaScript</p>\n</footer>\n\n---style.css---\n:root {\n --primary-color: #2a6bf2;\n --secondary-color: #1a1b4b;\n --background-color: #f8f9fa;\n --text-color: #333;\n --shadow: 0 4px 6px rgba(0, 0, 0, 0.1);\n --transition: all 0.3s ease;\n}\n\n* {\n margin: 0;\n padding: 0;\n box-sizing: border-box;\n}\n\nbody {\n font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;\n line-height: 1.6;\n color: var(--text-color);\n background: var(--background-color);\n}\n\nheader {\n background: var(--secondary-color);\n color: white;\n padding: 1rem;\n box-shadow: var(--shadow);\n}\n\nh1 {\n font-size: 1.8rem;\n font-weight: 700;\n text-align: center;\n}\n\n.crud-container {\n max-width: 1200px;\n margin: 2rem auto;\n padding: 0 1rem;\n display: grid;\n grid-template-columns: 1fr;\n gap: 2rem;\n}\n\n@media (min-width: 768px) {\n .crud-container {\n grid-template-columns: 1fr 2fr;\n }\n}\n\n.form-container {\n background: white;\n padding: 2rem;\n border-radius: 8px;\n box-shadow: var(--shadow);\n}\n\n.input-group {\n margin-bottom: 1.5rem;\n}\n\nlabel {\n display: block;\n margin-bottom: 0.5rem;\n font-weight: 500;\n}\n\ninput, textarea {\n width: 100%;\n padding: 0.8rem;\n border: 2px solid #ddd;\n border-radius: 4px;\n transition: var(--transition);\n}\n\ninput:focus, textarea:focus {\n border-color: var(--primary-color);\n outline: none;\n}\n\n.btn-primary {\n background: var(--primary-color);\n color: white;\n padding: 0.8rem 1.5rem;\n border: none;\n border-radius: 4px;\n cursor: pointer;\n transition: var(--transition);\n}\n\n.btn-primary:hover {\n background: var(--secondary-color);\n transform: translateY(-2px);\n}\n\n.items-grid {\n display: grid;\n grid-template-columns: repeat(auto-fill, minmax(250px, 1fr));\n gap: 1.5rem;\n}\n\n.item-card {\n background: white;\n padding: 1.5rem;\n border-radius: 8px;\n box-shadow: var(--shadow);\n transition: var(--transition);\n}\n\n.item-card:hover {\n transform: translateY(-5px);\n}\n\n.item-actions {\n display: flex;\n gap: 1rem;\n margin-top: 1rem;\n}\n\n.btn-edit, .btn-delete {\n padding: 0.5rem 1rem;\n border: none;\n border-radius: 4px;\n cursor: pointer;\n transition: var(--transition);\n}\n\n.btn-edit {\n background: #ffd700;\n}\n\n.btn-delete {\n background: #ff4444;\n color: white;\n}\n\nfooter {\n text-align: center;\n padding: 2rem;\n background: var(--secondary-color);\n color: white;\n margin-top: 2rem;\n}\n\n---script.js---\nclass CrudAPI {\n constructor() {\n this.items = JSON.parse(localStorage.getItem('items')) || [];\n this.currentId = this.items.length > 0 ? Math.max(...this.items.map(item => item.id)) + 1 : 1;\n this.form = document.getElementById('itemForm');\n this.itemsList = document.getElementById('itemsList');\n this.init();\n }\n\n init() {\n this.form.addEventListener('submit', (e) => this.handleSubmit(e));\n this.renderItems();\n }\n\n handleSubmit(e) {\n e.preventDefault();\n const itemId = document.getElementById('itemId').value;\n const itemName = document.getElementById('itemName').value;\n const itemDescription = document.getElementById('itemDescription').value;\n\n if (itemId) {\n this.updateItem(parseInt(itemId), itemName, itemDescription);\n } else {\n this.createItem(itemName, itemDescription);\n }\n\n this.form.reset();\n document.getElementById('itemId').value = '';\n }\n\n createItem(name, description) {\n const item = {\n id: this.currentId++,\n name,\n description,\n createdAt: new Date().toISOString()\n };\n this.items.push(item);\n this.saveToLocalStorage();\n this.renderItems();\n }\n\n updateItem(id, name, description) {\n const index = this.items.findIndex(item => item.id === id);\n if (index !== -1) {\n this.items[index] = { ...this.items[index], name, description };\n this.saveToLocalStorage();\n this.renderItems();\n }\n }\n\n deleteItem(id) {\n this.items = this.items.filter(item => item.id !== id);\n this.saveToLocalStorage();\n this.renderItems();\n }\n\n editItem(id) {\n const item = this.items.find(item => item.id === id);\n if (item) {\n document.getElementById('itemId').value = item.id;\n document.getElementById('itemName').value = item.name;\n document.getElementById('itemDescription').value = item.description;\n }\n }\n\n renderItems() {\n this.itemsList.innerHTML = this.items\n .map(item => `\n <div class=\"item-card\">\n <h3>${this.escapeHtml(item.name)}</h3>\n <p>${this.escapeHtml(item.description)}</p>\n <div class=\"item-actions\">\n <button class=\"btn-edit\" onclick=\"crudApi.editItem(${item.id})\">Edit</button>\n <button class=\"btn-delete\" onclick=\"crudApi.deleteItem(${item.id})\">Delete</button>\n </div>\n </div>\n `)\n .join('');\n }\n\n saveToLocalStorage() {\n localStorage.setItem('items', JSON.stringify(this.items));\n }\n\n escapeHtml(unsafe) {\n return unsafe\n .replace(/&/g, \"&amp;\")\n .replace(/</g, \"&lt;\")\n .replace(/>/g, \"&gt;\")\n .replace(/\"/g, \"&quot;\")\n .replace(/'/g, \"&#039;\");\n }\n}\n\nconst crudApi = new CrudAPI();\n\n---end---\n\nThis creates a beautiful, responsive CRUD application with local storage persistence. The design features a modern, clean interface with smooth animations and transitions. It includes:\n\n- Form for creating/editing items\n- Grid layout for displaying items\n- Edit and delete functionality\n- Data persistence using localStorage\n- Security measures (HTML escaping)\n- Responsive design\n- Smooth animations\n- Professional color scheme\n- Accessibility features\n- Clean, semantic HTML\n\nUsers can create, read, update, and delete items with a smooth, professional interface that works great on both desktop and mobile devices." + } + ], + "stop_reason": "end_turn", + "stop_sequence": null, + "usage": { + "input_tokens": 278, + "cache_creation_input_tokens": 0, + "cache_read_input_tokens": 0, + "output_tokens": 2326 + } +} \ No newline at end of file diff --git a/readme.scroll b/readme.scroll new file mode 100644 index 0000000..9ebef58 --- /dev/null +++ b/readme.scroll @@ -0,0 +1,2 @@ +# crud.scroll.pub +Website generated by Claude from prompt: I want a website with a crud api \ No newline at end of file diff --git a/script.js b/script.js new file mode 100644 index 0000000..3b250a1 --- /dev/null +++ b/script.js @@ -0,0 +1,96 @@ +class CrudAPI { + constructor() { + this.items = JSON.parse(localStorage.getItem('items')) || []; + this.currentId = this.items.length > 0 ? Math.max(...this.items.map(item => item.id)) + 1 : 1; + this.form = document.getElementById('itemForm'); + this.itemsList = document.getElementById('itemsList'); + this.init(); + } + + init() { + this.form.addEventListener('submit', (e) => this.handleSubmit(e)); + this.renderItems(); + } + + handleSubmit(e) { + e.preventDefault(); + const itemId = document.getElementById('itemId').value; + const itemName = document.getElementById('itemName').value; + const itemDescription = document.getElementById('itemDescription').value; + + if (itemId) { + this.updateItem(parseInt(itemId), itemName, itemDescription); + } else { + this.createItem(itemName, itemDescription); + } + + this.form.reset(); + document.getElementById('itemId').value = ''; + } + + createItem(name, description) { + const item = { + id: this.currentId++, + name, + description, + createdAt: new Date().toISOString() + }; + this.items.push(item); + this.saveToLocalStorage(); + this.renderItems(); + } + + updateItem(id, name, description) { + const index = this.items.findIndex(item => item.id === id); + if (index !== -1) { + this.items[index] = { ...this.items[index], name, description }; + this.saveToLocalStorage(); + this.renderItems(); + } + } + + deleteItem(id) { + this.items = this.items.filter(item => item.id !== id); + this.saveToLocalStorage(); + this.renderItems(); + } + + editItem(id) { + const item = this.items.find(item => item.id === id); + if (item) { + document.getElementById('itemId').value = item.id; + document.getElementById('itemName').value = item.name; + document.getElementById('itemDescription').value = item.description; + } + } + + renderItems() { + this.itemsList.innerHTML = this.items + .map(item => ` + <div class="item-card"> + <h3>${this.escapeHtml(item.name)}</h3> + <p>${this.escapeHtml(item.description)}</p> + <div class="item-actions"> + <button class="btn-edit" onclick="crudApi.editItem(${item.id})">Edit</button> + <button class="btn-delete" onclick="crudApi.deleteItem(${item.id})">Delete</button> + </div> + </div> + `) + .join(''); + } + + saveToLocalStorage() { + localStorage.setItem('items', JSON.stringify(this.items)); + } + + escapeHtml(unsafe) { + return unsafe + .replace(/&/g, "&amp;") + .replace(/</g, "&lt;") + .replace(/>/g, "&gt;") + .replace(/"/g, "&quot;") + .replace(/'/g, "&#039;"); + } +} + +const crudApi = new CrudAPI(); diff --git a/style.css b/style.css new file mode 100644 index 0000000..f9661e9 --- /dev/null +++ b/style.css @@ -0,0 +1,143 @@ +:root { + --primary-color: #2a6bf2; + --secondary-color: #1a1b4b; + --background-color: #f8f9fa; + --text-color: #333; + --shadow: 0 4px 6px rgba(0, 0, 0, 0.1); + --transition: all 0.3s ease; +} + +* { + margin: 0; + padding: 0; + box-sizing: border-box; +} + +body { + font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif; + line-height: 1.6; + color: var(--text-color); + background: var(--background-color); +} + +header { + background: var(--secondary-color); + color: white; + padding: 1rem; + box-shadow: var(--shadow); +} + +h1 { + font-size: 1.8rem; + font-weight: 700; + text-align: center; +} + +.crud-container { + max-width: 1200px; + margin: 2rem auto; + padding: 0 1rem; + display: grid; + grid-template-columns: 1fr; + gap: 2rem; +} + +@media (min-width: 768px) { + .crud-container { + grid-template-columns: 1fr 2fr; + } +} + +.form-container { + background: white; + padding: 2rem; + border-radius: 8px; + box-shadow: var(--shadow); +} + +.input-group { + margin-bottom: 1.5rem; +} + +label { + display: block; + margin-bottom: 0.5rem; + font-weight: 500; +} + +input, textarea { + width: 100%; + padding: 0.8rem; + border: 2px solid #ddd; + border-radius: 4px; + transition: var(--transition); +} + +input:focus, textarea:focus { + border-color: var(--primary-color); + outline: none; +} + +.btn-primary { + background: var(--primary-color); + color: white; + padding: 0.8rem 1.5rem; + border: none; + border-radius: 4px; + cursor: pointer; + transition: var(--transition); +} + +.btn-primary:hover { + background: var(--secondary-color); + transform: translateY(-2px); +} + +.items-grid { + display: grid; + grid-template-columns: repeat(auto-fill, minmax(250px, 1fr)); + gap: 1.5rem; +} + +.item-card { + background: white; + padding: 1.5rem; + border-radius: 8px; + box-shadow: var(--shadow); + transition: var(--transition); +} + +.item-card:hover { + transform: translateY(-5px); +} + +.item-actions { + display: flex; + gap: 1rem; + margin-top: 1rem; +} + +.btn-edit, .btn-delete { + padding: 0.5rem 1rem; + border: none; + border-radius: 4px; + cursor: pointer; + transition: var(--transition); +} + +.btn-edit { + background: #ffd700; +} + +.btn-delete { + background: #ff4444; + color: white; +} + +footer { + text-align: center; + padding: 2rem; + background: var(--secondary-color); + color: white; + margin-top: 2rem; +}