MCPcopy Index your code
hub / github.com/Markonis/slim

github.com/Markonis/slim @1.23.0

Chat with this repo
repository ↗ · DeepWiki ↗ · release 1.23.0 ↗ · + Follow
40 symbols 89 edges 14 files 0 documented · 0% updated 53d ago1.10.0 · 2025-10-16★ 381 open issues
What it actually does AI analysis from the code graph — generated when you open this
loading…
README

Slim

A lightweight, declarative frontend framework that brings server-driven interactivity to HTML with minimal JavaScript. Slim lets you build dynamic web applications using simple HTML attributes.

Features

  • Declarative HTML attributes - Define behavior directly in your markup
  • HTTP method support - GET, POST, PUT, DELETE requests via attributes
  • Event-driven architecture - Custom events, event delegation, multiple listeners
  • Form handling - Automatic serialization, file uploads, GET/POST/PUT/DELETE
  • Drag and drop - Native DnD with JSON data transfer
  • Lazy loading - Intersection Observer with appear events
  • Real-time updates - WebSocket support with auto-reconnect
  • Query parameters - Hierarchical collection with inheritance
  • Response control - Server headers override client targets and emit events
  • Zero dependencies - Pure JavaScript, no external libraries

Quick Start

Include Slim in your HTML:

<script src="https://github.com/Markonis/slim/raw/1.23.0/slim.min.js"></script>

Add interactive behavior with attributes:

<button s-get="/api/data" s-target="#result">Load Data</button>





Core Attributes

HTTP Requests

  • s-get="/path" - GET request
  • s-post="/path" - POST request
  • s-put="/path" - PUT request
  • s-delete="/path" - DELETE request

Form data becomes query params for GET, FormData body for others. File uploads supported.

Event Handling

  • s-on="event" - Listen for an event
  • s-on="event1 | event2" - Multiple listeners
  • s-on="click on .selector" - Event delegation

Targeting

  • s-target="#selector" - Update matched elements (default: self)
  • Server override: S-Target: selector header

Emitting & Delays

  • s-emit="event-name" - Broadcast custom event
  • s-emit="event after 1.5s" - Delayed event

Debouncing

  • s-debounce="300" - Debounce the action by 300ms
  • s-debounce="0.5s" - Debounce using seconds notation

When an element has s-debounce, rapid events are collapsed — the action fires only after the element goes quiet for the specified duration. Useful for search inputs and live filters.

Executing JavaScript

  • s-eval="javascript code" - Execute JavaScript (with this = element)

Client-Side Templates

  • s-template="#selector" - Use the innerHTML of the template

History Management

  • s-push="/path" - Push URL to browser history on event

Other Attributes

  • s-confirm="message" - Confirmation dialog
  • s-query="key=value" - Add query parameters
  • s-ws="/websocket" - WebSocket URL

Drag & Drop

  • s-drag-json="{...}" - JSON data on dragstart
  • s-drag-effect="copy" - Drag effect (copy, move, link)
  • s-drop-effect="copy" - Drop effect (enables dragover)
  • s-drop-class="active" - Class added during dragover

Examples

Basic Request

<button s-get="/api/count">Get Count</button>

Form Submission

<form s-post="/api/users">
  <input name="name" required>
  <button type="submit">Create</button>
</form>

Event Chain

<button s-emit="refresh">Refresh</button>





Lazy Load






Query Params

<body s-query="v=1">
  <button s-get="/api/data">

  </button>
</body>

WebSocket

<body s-ws="/ws">





</body>

Drag & Drop











Delegation




  <button class="item">Item 1</button>
  <button class="item">Item 2</button>



Confirmation

<button s-confirm="Delete?" s-delete="/api/item"></button>

JavaScript Execution

<button s-eval="console.log('Button clicked!', this)">Log</button>
<button s-eval="this.style.color = 'red'" s-get="/api/data">Update and Log</button>

Debounce

<input s-on="input" s-debounce="300" s-get="/api/search" s-target="#results">

Client-Side Templates

<template id="card-template">



    <h3>New Card</h3>


Card content here





</template>

<button s-template="#card-template" s-target="#container">Add Card</button>





History Management


<button s-push="/dashboard">Go to Dashboard</button>


<button s-get="/api/data" s-push="/data-view">Load Data</button>


<form s-post="/api/submit" s-push="/success">
  <input name="item" required>
  <button type="submit">Submit</button>
</form>

Default Event Bindings

Elements trigger requests automatically when s-on is not specified:

  • <form>submit
  • <button>click
  • <input type="text">, <select>change (also input)
  • Other elements → appear

Request Headers

Every request sent by Slim includes:

  • S-Location - The URL of the current page (for server context/analytics)

Server Response Handling

Response Headers

  • S-Target: selector - Override update target
  • S-Emit: event-name - Broadcast event after update
  • S-Push: /path - Push URL to browser history
  • S-Refresh: true - Reload page
  • S-Redirect: /path - Redirect to URL

Response Content Types

  • text/html - Sets target's innerHTML
  • text/plain - Sets target's textContent
  • Other types - Process headers only

Custom Events Dispatched

Slim dispatches on request elements:

  • slim:ok - Request succeeded
  • slim:error - Request failed
  • slim:done - Request completed

Global events:

  • location:change - URL pushed / poped from browser history
  • hash:change - Location hash changed

Request Data

GET Requests

  • Form data → query parameters
  • Query params from s-query attributes (hierarchical)
  • File inputs skipped

POST/PUT/DELETE Requests

  • Form data → FormData body
  • Drag-drop → JSON body (from s-drag-json)
  • Files included

Query Parameter Inheritance

Parameters cascade from ancestors:

<body s-query="org=acme">







</body>

Best Practices

  1. Progressive Enhancement - Add Slim to working HTML
  2. Semantic HTML - Use correct elements (<button>, <form>)
  3. Error Handling - Listen for slim:error
  4. Confirmations - Use s-confirm for destructive actions

Browser Support

Requires: - ES6+ JavaScript - Fetch API - Custom Events - Intersection Observer - WebSockets (for s-ws)

License

MIT

Core symbols most depended-on inside this repo

broadcastEvent
called by 9
src/main.ts
getElementRequestConfig
called by 4
src/main.ts
scheduleEvent
called by 3
src/main.ts
observeElementsWithAppearEvent
called by 3
src/main.ts
createEmptyResult
called by 2
src/response.ts
processResponse
called by 2
src/response.ts
determineTargets
called by 2
src/response.ts
performSwap
called by 2
src/swap.ts

Shape

Function 40

Languages

TypeScript100%

Modules by API surface

src/main.ts13 symbols
src/swap.ts4 symbols
src/request.ts4 symbols
src/response.ts3 symbols
src/query.ts3 symbols
src/event.ts3 symbols
src/template.ts2 symbols
src/push.ts2 symbols
src/eval.ts2 symbols
src/time.ts1 symbols
src/server.ts1 symbols
src/emit.ts1 symbols

For agents

$ claude mcp add slim \
  -- python -m otcore.mcp_server <graph>

⬇ download graph artifact