Pagelove - DOM Primitives

  • Home
  • The CLI
  • Range Selectors
  • DOM Primitives
  • Schemas
  • Overview

    Pagelove applications use the selector Range unit to surgically modify documents on the server. DOM primitives provide a set of HTTP verbs on each DOM Element so that developers can easily manipulate the DOM on the server.

    Core Features

    Server Detection

    The system automatically detects DOM-aware servers by checking for Accept-Ranges: selector in OPTIONS responses. When detected, HTTP methods on DOM elements are activated.

    Element Methods

    Selector Property

    Every element gains a .selector property that generates a unique CSS path. This selector is sent via Range headers to identify specific elements server-side.

    Permission System

    window.server.can()

    Check if HTTP methods are allowed for specific targets:

    // Check single method
    await window.server.can('PUT', '/api/resource');
    
    // Check multiple methods
    await window.server.can(['PUT', 'DELETE'], '#(selector=.item)');
    
    // With caching control
    await window.server.can('POST', target, { ttl: 60 });

    Conditional Components

    Web components that show/hide content based on permissions:

    <http-can method="PUT,DELETE" selector=".editable">
        <button>Edit</button>
    </http-can>

    Events

    The system emits custom events for monitoring operations:

    JavaScript Library

    The DOM Primitives functionality is available as a JavaScript module that you can import into your applications:

    <script type="module" src="https://pagelove.org/js/dom-primitives/index.mjs"></script>

    This library provides the client-side implementation that extends DOM elements with HTTP methods and manages server communication using the selector range unit.

    The module is available at: https://pagelove.org/js/dom-primitives/index.mjs