@mapled/vanilla 0.0.1 → 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,84 @@
1
+ /** The runtime of Mapled attributes (§19.2): finds what a page declared
2
+ with `data-mapled-*`, reads the release that is live, fills the page,
3
+ and says what it couldn't fill. The page's own HTML is the fallback —
4
+ nothing is touched before its replacement is in hand, and every run
5
+ starts again from what the author wrote.
6
+
7
+ What a page may declare:
8
+
9
+ data-mapled-bind="home.headline" the element's content — text;
10
+ on <img>, the picture
11
+ data-mapled-format="markdown" …as rich text; or "date",
12
+ "datetime", "number"
13
+ data-mapled-bind-href="home.cta-link" an attribute: href, src, alt,
14
+ title, aria-label,
15
+ placeholder, datetime
16
+ data-mapled-link="/post.html?slug={slug}" an address from a template
17
+ data-mapled-show / data-mapled-hide shown while there is a value
18
+ data-mapled-list="posts" a <template> inside, once per
19
+ record: data-mapled-sort,
20
+ -limit, -filter, -expand
21
+ data-mapled-each="features" the same for the items of a
22
+ repeatable group
23
+ data-mapled-record="posts" one record for what is inside:
24
+ data-mapled-slug, or
25
+ data-mapled-slug-param="slug"
26
+ <form data-mapled-form="contact"> posted to Mapled's form
27
+
28
+ Paths start at a single from the document (`home.headline`) and at the
29
+ record inside a list, an each or a record (`title`, `author.name`). */
30
+ import { type MapledClient } from "@mapled/client";
31
+ /** Why a place wasn't filled. `missing` — no such single, record or
32
+ collection in the release; `empty` — the record is there, a value at
33
+ this path isn't; `failed` — the read didn't come back; `bad-path` —
34
+ the page's attribute isn't a path, a key or an option Mapled reads;
35
+ the rest are the sinks' refusals. */
36
+ export declare const ISSUE_REASONS: readonly ["missing", "empty", "failed", "bad-path", "unsafe-url", "type", "refused-element", "unsupported"];
37
+ export type IssueReason = (typeof ISSUE_REASONS)[number];
38
+ /** A place the runtime couldn't fill: the page's own path, why, and the
39
+ element as the page names it. Never a value. */
40
+ export type Issue = {
41
+ path: string;
42
+ reason: IssueReason;
43
+ on: string;
44
+ };
45
+ export type Report = {
46
+ /** ready — filled from Mapled; unpublished — nothing is published yet;
47
+ fallback — Mapled couldn't be reached, the page is as written */
48
+ state: "ready" | "unpublished" | "fallback";
49
+ release: number | null;
50
+ preview: boolean;
51
+ /** places filled */
52
+ bound: number;
53
+ issues: Issue[];
54
+ };
55
+ export type MountOptions = {
56
+ /** The project's delivery key — the one key that is safe in a page. */
57
+ key: string;
58
+ apiUrl?: string;
59
+ /** Mapled's app — where an expired preview link sends the person. */
60
+ appUrl?: string;
61
+ /** Where to look for attributes (default: the whole document). */
62
+ root?: Element;
63
+ /** Fill the page again when a publish lands while it is open: true
64
+ (a check a minute), or the seconds between checks — at least 15.
65
+ Every check is a request of the key's budget. */
66
+ live?: boolean | number;
67
+ fetch?: typeof fetch;
68
+ };
69
+ export type MapledPage = {
70
+ /** The first fill: resolves with its report, never rejects. */
71
+ ready: Promise<Report>;
72
+ /** The last report, once there is one. */
73
+ readonly report: Report | null;
74
+ /** Read and fill again — after the page changed its own DOM. */
75
+ refresh: () => Promise<Report>;
76
+ /** Leave preview and show what is published. */
77
+ endPreview: () => Promise<Report>;
78
+ /** Stop live updates. */
79
+ stop: () => void;
80
+ client: MapledClient;
81
+ };
82
+ /** Every attribute the runtime reads or writes, besides `bind-…`. */
83
+ export declare const NAMES: Set<string>;
84
+ export declare function mount(options: MountOptions): MapledPage;