@yaks/render 0.0.0-stage → 0.2.36

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.
Files changed (53) hide show
  1. package/LICENSE +202 -0
  2. package/README.md +396 -2
  3. package/_dist/archetype.d.ts +3 -0
  4. package/_dist/archetype.d.ts.map +1 -0
  5. package/_dist/component.d.ts +15 -0
  6. package/_dist/component.d.ts.map +1 -0
  7. package/_dist/edit.d.ts +17 -0
  8. package/_dist/edit.d.ts.map +1 -0
  9. package/_dist/host.d.ts +59 -0
  10. package/_dist/host.d.ts.map +1 -0
  11. package/_dist/mod.d.ts +72 -0
  12. package/_dist/mod.d.ts.map +1 -0
  13. package/_dist/namespace.d.ts +12 -0
  14. package/_dist/namespace.d.ts.map +1 -0
  15. package/_dist/prepare.d.ts +11 -0
  16. package/_dist/prepare.d.ts.map +1 -0
  17. package/_dist/types.d.ts +66 -0
  18. package/_dist/types.d.ts.map +1 -0
  19. package/_dist/views.d.ts +88 -0
  20. package/_dist/views.d.ts.map +1 -0
  21. package/archetype.js +56 -0
  22. package/archetype.js.map +1 -0
  23. package/archetype.ts +76 -0
  24. package/component.js +39 -0
  25. package/component.js.map +1 -0
  26. package/component.ts +84 -0
  27. package/deno.json +1 -0
  28. package/edit.js +88 -0
  29. package/edit.js.map +1 -0
  30. package/edit.ts +113 -0
  31. package/host.js +191 -0
  32. package/host.js.map +1 -0
  33. package/host.ts +277 -0
  34. package/mod.js +158 -0
  35. package/mod.js.map +1 -0
  36. package/mod.ts +328 -0
  37. package/namespace.js +90 -0
  38. package/namespace.js.map +1 -0
  39. package/namespace.ts +121 -0
  40. package/package.json +31 -4
  41. package/prepare.js +32 -0
  42. package/prepare.js.map +1 -0
  43. package/prepare.ts +55 -0
  44. package/prop.js +37 -0
  45. package/prop.js.map +1 -0
  46. package/prop.ts +46 -0
  47. package/types.js +7 -0
  48. package/types.js.map +1 -0
  49. package/types.ts +116 -0
  50. package/views.js +333 -0
  51. package/views.js.map +1 -0
  52. package/views.ts +389 -0
  53. package/vocab.json +29 -0
@@ -0,0 +1,59 @@
1
+ import { type Vocab } from "@yaks/vocab";
2
+ import type { Store, Subscribe } from "./component.js";
3
+ /** What a views module exports: its registry, named as a package's `/views`
4
+ * facet names it. */ export type Views<R> = {
5
+ views: R;
6
+ };
7
+ /** A write to the draft a preview page follows, as `yak-draft` tells it:
8
+ * each file's path, the address it serves at, and its sha (null when the
9
+ * write deleted it). */ export type Draft = {
10
+ files: {
11
+ path: string;
12
+ sha: string | null;
13
+ url?: string;
14
+ entries?: string[];
15
+ }[];
16
+ };
17
+ /** What the page supplies: everything `entity` binds but the registry, the
18
+ * element the page draws into, the address of its views module, and what to
19
+ * draw there given the bound `Entity`. */ export type Binding = {
20
+ vocab: Vocab;
21
+ store: Store;
22
+ subscribe?: Subscribe;
23
+ extend?: (next: Vocab) => boolean;
24
+ };
25
+ export type Page<R, Render> = (Binding | {
26
+ client: {
27
+ vocab: Vocab;
28
+ ent: Store;
29
+ extend: (next: Vocab) => boolean;
30
+ watch: (query: string) => {
31
+ subscribe: (notify: () => void) => () => void;
32
+ close: () => void;
33
+ };
34
+ };
35
+ }) & {
36
+ root: Element;
37
+ views: string | URL;
38
+ draw: Render;
39
+ /** how a module is imported; `import()` by default */ load?: (url: string) => Promise<Views<R>>;
40
+ /** The page vocabulary endpoint, relative to its base URI (default: api/vocab.json). */ vocabulary?: string | URL;
41
+ /** How the vocabulary is fetched; the page's fetch by default. */ fetch?: (url: string) => Promise<Response>;
42
+ };
43
+ /** A drawn page. */ export type Host<R> = {
44
+ /** the registry drawn now */ registry: () => R;
45
+ /** resolves once the newest write the host took is drawn, or given up */ settled: () => Promise<void>;
46
+ /** stop following writes and empty the root */ close: () => void;
47
+ };
48
+ /** The sha of the views module a write brings when the write is that module
49
+ * alone; else null, and the page takes the write its own way (a stylesheet
50
+ * swapped, or a reload). */ export declare let taken: (news: Draft, views: string) => string | null;
51
+ /** Where the module a write brought is imported from: a new address for each
52
+ * sha, so the browser imports it again. */ export declare let addressed: (views: string, sha: string) => string;
53
+ /** Draw a page and follow its draft using the supplied renderer. */ export declare let host: <R extends {
54
+ renderers: readonly unknown[];
55
+ }, Render>(page: Page<R, Render>, mount: (root: Element, binding: Binding, initial: R, view: Render) => {
56
+ draw: (registry: R, vocab: Vocab) => void;
57
+ close: () => void;
58
+ }) => Promise<Host<R>>;
59
+ //# sourceMappingURL=host.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"host.d.ts","sources":["../host.ts"],"names":[],"mappings":"AAAA,SAAoB,KAAK,KAAK,2BAAgC;AAC9D,cAAc,KAAK,EAAE,SAAS,yBAAwB;AAEtD;mBACmB,GACnB,YAAY,MAAM;EAAO,OAAO;;AAEhC;;sBAEsB,GACtB,YAAY;EACV;IACE,MAAM,MAAM;IACZ,KAAK,MAAM,GAAG,IAAI;IAClB,MAAM,MAAM;IACZ,UAAU,MAAM;;;AAIpB;;wCAEwC,GACxC,YAAY;EACV,OAAO;EACP,OAAO;EACP,YAAY;EACZ,UAAU,MAAM,UAAU,OAAO;;AAGnC,YAAY,KAAK,GAAG,WACf;EACD;IACE,OAAO;IACP,KAAK;IACL,SAAS,MAAM,UAAU,OAAO;IAChC,QAAQ,OAAO,MAAM;MACnB,YAAY,cAAc,IAAI,WAAW,IAAI;MAC7C,aAAa,IAAI;;;;EAKrB,MAAM;EACN,OAAO,MAAM,GAAG;EAChB,MAAM;EACN,oDAAoD,GACpD,QAAQ,KAAK,MAAM,KAAK,QAAQ,MAAM;EACtC,sFAAsF,GACtF,aAAa,MAAM,GAAG;EACtB,gEAAgE,GAChE,SAAS,KAAK,MAAM,KAAK,QAAQ;;AAGrC,kBAAkB,GAClB,YAAY,KAAK;EACf,2BAA2B,GAC3B,gBAAgB;EAChB,uEAAuE,GACvE,eAAe,QAAQ,IAAI;EAC3B,6CAA6C,GAC7C,aAAa,IAAI;;AAKnB;;0BAE0B,GAC1B,OAAO,YAAI,QAAS,MAAM,OAAO,OAAO,MAAM,KAAG,MAAM,GAAG,IAAI,CAW7D;AAED;yCACyC,GACzC,OAAO,YAAI,YAAa,OAAO,MAAM,EAAE,KAAK,MAAM,KAAG,MAAM,CAI1D;AAkFD,kEAAkE,GAClE,OAAO,YAAI,OAAc;EAAY,oBAAoB,OAAO;GAAM,QACpE,MAAM,KAAK,GAAG,SACd,QAAQ,MAAM,SAAS,SAAS,SAAS,SAAS,GAAG,MAAM;EACzD,OAAO,UAAU,GAAG,OAAO,UAAU,IAAI;EACzC,aAAa,IAAI;MAElB,QAAQ,KAAK,IAoGf"}
package/_dist/mod.d.ts ADDED
@@ -0,0 +1,72 @@
1
+ /**
2
+ * @yaks/render selects which renderer draws a bundle, and lists the actions a
3
+ * bundle offers. A view name is tried from the right (Board.List.Tile →
4
+ * List.Tile → Tile), applying any alias at each step; within one step, the
5
+ * registration whose query has the most clauses wins, and registration order
6
+ * breaks ties. A catch-all `true` scores 0.5. No rendering backend is imported
7
+ * here.
8
+ *
9
+ * Editors use this same registry. Pass {comp, prop} to resolve and it matches
10
+ * against a bundle-shaped projection of that property's declared schema rather
11
+ * than against the entity: parse('.prop.type=string') selects a string
12
+ * editor. The renderer still receives the original bundle and that context, so
13
+ * it knows both the value and where a patch belongs. Property queries and
14
+ * entity queries describe different subjects; register them under separate
15
+ * view names. See prop.ts for the four queryable schema fields; @yaks/ux
16
+ * registers its `Edit` controls this way.
17
+ *
18
+ * A missing view returns undefined unless a matching JSON view is registered.
19
+ * An unnamed request considers the configured views (all by default).
20
+ *
21
+ * ```ts
22
+ * import { assertEquals } from '@std/assert'
23
+ * import { parse } from '@yaks/query'
24
+ * import { loadVocab } from '@yaks/vocab/runtime'
25
+ * import { define, resolve, type H } from '@yaks/render'
26
+ *
27
+ * let vocab = loadVocab([{ $defs: { doc: {
28
+ * component: true, properties: { title: { type: 'string' } },
29
+ * } } }])
30
+ * let bundle = { entity: { eid: 'a' }, doc: { title: 'A page' } }
31
+ * let registry = define([{
32
+ * view: 'Tile', match: parse('.doc'),
33
+ * render: (b, h) => h('h2', null, String((b.doc as {title: string}).title)),
34
+ * }])
35
+ * let calls: unknown[] = []
36
+ * let h: H<number> = (tag, props, ...children) =>
37
+ * calls.push({ tag, props, children })
38
+ * let renderer = resolve(registry, bundle, 'Board.Tile', vocab)!
39
+ * assertEquals(renderer.render(bundle, h, {}), 1)
40
+ * assertEquals(calls, [{ tag: 'h2', props: null, children: ['A page'] }])
41
+ * ```
42
+ *
43
+ * @module
44
+ */ import type { Bundle } from "@yaks/match";
45
+ import type { Vocab } from "@yaks/vocab/runtime";
46
+ export type { ArchetypeLookup } from "./archetype.js";
47
+ export { contributed, needsIn, viewIn } from "./namespace.js";
48
+ import type { Action, Context, Options, Registration, Registry, Renderer, Selection } from "./types.js";
49
+ export { edit, type EditOptions } from "./edit.js";
50
+ export type { Bundle } from "@yaks/match";
51
+ export type { Query } from "@yaks/query";
52
+ export type { Action, Child, Context, Contributor, H, Options, Patch, Registration, Registry, RenderContext, Renderer, Rendering, Selection } from "./types.js";
53
+ /** Build an independent registry; earlier registrations win equal scores. */ export declare function define<R extends Renderer = Renderer, A = Action, E = Bundle>(renderers: readonly R[], options?: Options<NoInfer<A>, E>): Registry<R & Renderer, A, E>;
54
+ export declare function define<R extends Registration, A = Action, E = Bundle>(renderers: readonly R[], options?: Options<NoInfer<A>, E>): Registry<R, A, E>;
55
+ /** Prepend an overlay of renderers to this registry; earlier rows win equal
56
+ * scores. */ export declare let extend: <R extends Registration>(registry: Selection<R>, renderers: readonly R[]) => void;
57
+ /**
58
+ * Resolve the closest view, then its most specific renderer: the walk strips
59
+ * the leftmost role at each step, so a short registration serves every longer
60
+ * ask.
61
+ */ export declare let resolve: <R extends Registration>(registry: Selection<R>, bundle: Bundle, view: string | undefined, vocab: Vocab, ctx?: Context) => R | undefined;
62
+ /** Exact, matching tab views in configured order, without JSON fallback. */ export declare let applicable: <R extends Registration>(registry: Selection<R>, bundle: Bundle, vocab: Vocab, ctx?: Context) => string[];
63
+ /**
64
+ * All matching contributions, preserving duplicates and registration order.
65
+ * Static offerings are keyed by the component an entity carries; dynamic
66
+ * contributors receive
67
+ * the source supplied by the caller, while their queries read the bundle.
68
+ * Conditions use the supplied vocabulary or define's default; run is never called.
69
+ */ export declare function actions<R extends Registration, A>(registry: Registry<R, A>, bundle: Bundle, vocab?: Vocab): A[];
70
+ export declare function actions<R extends Registration, A, E>(registry: Registry<R, A, E>, bundle: Bundle, vocab: Vocab | undefined, source: E): A[];
71
+ export { type Prepared, prepared, rendering } from "./prepare.js";
72
+ //# sourceMappingURL=mod.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"mod.d.ts","sources":["../mod.ts"],"names":[],"mappings":"AACA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CA2CC,GAED,cAAc,MAAM,2BAAwC;AAE5D,cAAc,KAAK,mCAAwC;AAE3D,cAAc,eAAe,yBAAwB;AAErD,SAAS,WAAW,EAAE,OAAO,EAAE,MAAM,yBAAwB;AAE7D,cACE,MAAM,EACN,OAAO,EAEP,OAAO,EACP,YAAY,EACZ,QAAQ,EACR,QAAQ,EACR,SAAS,qBACQ;AAEnB,SAAS,IAAI,EAAE,KAAK,WAAW,oBAAmB;AAElD,cAAc,MAAM,2BAAgC;AACpD,cAAc,KAAK,2BAAgC;AACnD,cACE,MAAM,EACN,KAAK,EACL,OAAO,EACP,WAAW,EACX,CAAC,EACD,OAAO,EACP,KAAK,EACL,YAAY,EACZ,QAAQ,EACR,aAAa,EACb,QAAQ,EACR,SAAS,EACT,SAAS,qBACQ;AAEnB,2EAA2E,GAC3E,OAAO,iBAAS,OAAO,UAAU,WAAW,UAAU,IAAI,QAAQ,IAAI,QACpE,oBAAoB,GAAG,EACvB,UAAU,QAAQ,QAAQ,IAAI,EAAE,GAC/B,SAAS,IAAI,UAAU,GAAG;AAC7B,OAAO,iBAAS,OAAO,UAAU,cAAc,IAAI,QAAQ,IAAI,QAC7D,oBAAoB,GAAG,EACvB,UAAU,QAAQ,QAAQ,IAAI,EAAE,GAC/B,SAAS,GAAG,GAAG;AAQlB;WACW,GACX,OAAO,YAAI,SAAU,UAAU,cAC7B,UAAU,UAAU,IACpB,oBAAoB,QACnB,IAAI,CAEN;AAqID;;;;CAIC,GACD,OAAO,YAAI,UAAW,UAAU,cAC9B,UAAU,UAAU,IACpB,QAAQ,QACR,MAAM,MAAM,GAAG,SAAS,EACxB,OAAO,OACP,MAAK,YACJ,IAAI,SAAS,CASf;AAED,0EAA0E,GAC1E,OAAO,YAAI,aAAc,UAAU,cACjC,UAAU,UAAU,IACpB,QAAQ,QACR,OAAO,OACP,MAAK,YACJ,MAAM,GAWR;AAED;;;;;;CAMC,GACD,OAAO,iBAAS,QAAQ,UAAU,cAAc,GAC9C,UAAU,SAAS,GAAG,EAAE,EACxB,QAAQ,MAAM,EACd,QAAQ,KAAK,GACZ;AACH,OAAO,iBAAS,QAAQ,UAAU,cAAc,GAAG,GACjD,UAAU,SAAS,GAAG,GAAG,EAAE,EAC3B,QAAQ,MAAM,EACd,OAAO,QAAQ,SAAS,EACxB,QAAQ,CAAC,GACR;AA4BH,SAAS,KAAK,QAAQ,EAAE,QAAQ,EAAE,SAAS,uBAAsB"}
@@ -0,0 +1,12 @@
1
+ import { namesBetween } from "@yaks/graph";
2
+ import type { Vocab } from "@yaks/vocab";
3
+ import type { Bundle } from "@yaks/match";
4
+ import type { Registration } from "./types.js";
5
+ /** Attribute renderers from one package so a match reads the package's words. */ export declare let contributed: <R extends Registration>(label: string, entries: readonly R[]) => R[];
6
+ export declare let viewIn: (entry: Registration, vocab: Vocab) => {
7
+ local: Vocab;
8
+ into: ReturnType<typeof namesBetween>;
9
+ out: ReturnType<typeof namesBetween>;
10
+ } | undefined;
11
+ export declare let needsIn: (entry: Registration, bundle: Bundle, vocab: Vocab) => string[];
12
+ //# sourceMappingURL=namespace.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"namespace.d.ts","sources":["../namespace.ts"],"names":[],"mappings":"AAAA,SAAS,YAAY,2BAAgC;AAErD,cAAc,KAAK,2BAAgC;AACnD,cAAc,MAAM,2BAAgC;AACpD,cAAuB,YAAY,qBAA+B;AAElE,+EAA+E,GAC/E,OAAO,YAAI,cAAe,UAAU,cAClC,OAAO,MAAM,EACb,kBAAkB,QACjB,IAIE;AAiBL,OAAO,YAAI,SACT,OAAO,cACP,OAAO;EAEP,OAAO;EACP,MAAM,kBAAkB;EACxB,KAAK,kBAAkB;IACrB,SAAS,CAQZ;AAED,OAAO,YAAI,UACT,OAAO,cACP,QAAQ,QACR,OAAO,UACN,MAAM,GACoE"}
@@ -0,0 +1,11 @@
1
+ import type { Registration, Registry, RenderContext, Renderer, Rendering } from "./types.js";
2
+ export type Prepared<R> = R extends {
3
+ load: () => Promise<Rendering>;
4
+ } ? Omit<R, 'load' | 'render'> & {
5
+ render: Rendering;
6
+ } : R;
7
+ /** Prepare all renderers, or only the selected registrations a host demanded. */ export declare function prepared<R extends Registration, A, E>(registry: Registry<R, A, E>): Promise<Registry<Prepared<R>, A, E>>;
8
+ export declare function prepared<R extends Registration, A, E>(registry: Registry<R, A, E>, requested: readonly R[]): Promise<Registry<R | Prepared<R>, A, E>>;
9
+ /** A pure lowering reports deferred selections to its host. Without that
10
+ * boundary, an unprepared renderer is an error, not an empty drawing. */ export declare let rendering: <Node>(renderer: Renderer, ctx: RenderContext<Node>) => Rendering | undefined;
11
+ //# sourceMappingURL=prepare.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"prepare.d.ts","sources":["../prepare.ts"],"names":[],"mappings":"AAIA,cACE,YAAY,EACZ,QAAQ,EACR,aAAa,EACb,QAAQ,EACR,SAAS,qBACQ;AAEnB,YAAY,SAAS,KAAK;EAAY,YAAY,QAAQ;IACtD,KAAK,GAAG,SAAS;EAAc,QAAQ;IACvC;AAEJ,+EAA+E,GAC/E,OAAO,iBAAS,SAAS,UAAU,cAAc,GAAG,GAClD,UAAU,SAAS,GAAG,GAAG,EAAE,GAC1B,QAAQ,SAAS,SAAS,IAAI,GAAG;AACpC,OAAO,iBAAS,SAAS,UAAU,cAAc,GAAG,GAClD,UAAU,SAAS,GAAG,GAAG,EAAE,EAC3B,oBAAoB,GAAG,GACtB,QAAQ,SAAS,IAAI,SAAS,IAAI,GAAG;AAgBxC;uEACuE,GACvE,OAAO,YAAI,YAAa,MACtB,UAAU,UACV,KAAK,cAAc,UAClB,YAAY,SAAS,CAUvB"}
@@ -0,0 +1,66 @@
1
+ /**
2
+ * The portable renderer contract: a tree belongs to the injected hyperscript,
3
+ * while selection and actions remain data. A renderer is generic over the node
4
+ * type its backend builds, so the same registration can be given to a browser
5
+ * backend or to a text one.
6
+ */ import type { Bundle } from "@yaks/match";
7
+ import type { Query } from "@yaks/query";
8
+ import type { Namespace, Vocab } from "@yaks/vocab";
9
+ import type { ArchetypeLookup } from "./archetype.js";
10
+ /** A node the backend built, literal content, an empty child, or nested
11
+ * children. */ export type Child<Node> = Node | string | number | boolean | null | undefined | readonly Child<Node>[];
12
+ /** The shared set of element names; each backend decides what a tag becomes. */ export type H<Node> = (tag: string, props: Record<string, unknown> | null, ...children: Child<Node>[]) => Node;
13
+ /** Extra values the caller supplies; comp and prop together select a property
14
+ * schema. */ export type Context = {
15
+ comp?: string;
16
+ prop?: string;
17
+ [key: string]: unknown;
18
+ };
19
+ /** The backend supplies nested rendering through the same registry and
20
+ * bundle, and the vocabulary the renderer was chosen by, for a view that
21
+ * reads what it declares (a computed status). */ export type RenderContext<Node> = Context & {
22
+ render?: (view: string, ctx?: Context) => Node | null;
23
+ vocab?: Vocab;
24
+ /** A lowering reports the selected renderer's declared reference needs. */ needed?: (eids: readonly string[]) => void;
25
+ /** Report a selected renderer whose implementation the host must prepare. */ deferred?: (renderer: Renderer) => void;
26
+ };
27
+ /** The fields selection needs, shared by portable renderers and by ones a
28
+ * backend defines itself. */ export type Registration = {
29
+ view: string;
30
+ namespace?: Namespace;
31
+ match: Query | true;
32
+ /** Additional entities this view reads, supplied by the host. */ needs?: (bundle: Bundle) => string[];
33
+ };
34
+ /** A pure view of a bundle, independent of any backend's node type. */ export type Rendering = <Node>(bundle: Bundle, h: H<Node>, ctx: RenderContext<Node>) => Node;
35
+ /** Selection reads the same metadata before and after preparation. */ export type Renderer = Registration & ({
36
+ render: Rendering;
37
+ load?: never;
38
+ } | {
39
+ load: () => Promise<Rendering>;
40
+ render?: never;
41
+ });
42
+ /** Component changes for the caller to apply to the action's entity. */ export type Patch = Record<string, Record<string, unknown> | null>;
43
+ /** An offered verb; listing it never invokes run or applies its patch. */ export type Action = {
44
+ name: string;
45
+ when?: Query;
46
+ run: (bundle: Bundle, input?: unknown) => Patch;
47
+ };
48
+ /** A dynamic contribution; selection reads a bundle, while the source stays typed. */ export type Contributor<A = Action, E = Bundle> = {
49
+ match: Query | true;
50
+ acts: (source: E) => readonly (A & {
51
+ when?: Query;
52
+ })[];
53
+ };
54
+ /** Registry configuration; actions preserve component and contribution order. */ export type Options<A = Action, E = Bundle> = {
55
+ /** Immutable table sets held by the caller's descriptor subscription. */ archetypes?: ArchetypeLookup;
56
+ actions?: Readonly<Record<string, readonly (A & {
57
+ when?: Query;
58
+ })[]>> | readonly Contributor<A, E>[];
59
+ /** Vocabulary for action conditions when actions() is called with two args. */ vocab?: Vocab;
60
+ /** Views eligible for an unnamed request; defaults to every registered view. */ views?: readonly string[];
61
+ };
62
+ /** One curated registry, with no global registrations and no backend state. */ export type Registry<R extends Registration = Renderer, A = Action, E = Bundle> = Options<A, E> & {
63
+ renderers: readonly R[];
64
+ };
65
+ /** The part of a registry selection needs, independent of its action types. */ export type Selection<R extends Registration = Renderer> = Pick<Registry<R>, 'renderers' | 'views' | 'archetypes'>;
66
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sources":["../types.ts"],"names":[],"mappings":"AAAA;;;;;CAKC,GAED,cAAc,MAAM,2BAAgC;AACpD,cAAc,KAAK,2BAAgC;AACnD,cAAc,SAAS,EAAE,KAAK,2BAAgC;AAC9D,cAAc,eAAe,yBAAwB;AAErD;aACa,GACb,YAAY,MAAM,QACd,OACA,MAAM,GACN,MAAM,GACN,OAAO,GACP,IAAI,GACJ,SAAS,YACA,MAAM;AAEnB,8EAA8E,GAC9E,YAAY,EAAE,SACZ,KAAK,MAAM,EACX,OAAO,OAAO,MAAM,EAAE,OAAO,IAAI,IAAI,EACrC,GAAG,UAAU,MAAM,YAChB;AAEL;WACW,GACX,YAAY;EACV,OAAO,MAAM;EACb,OAAO,MAAM;GACZ,KAAK,MAAM,GAAG,OAAO;;AAGxB;;+CAE+C,GAC/C,YAAY,cAAc,QAAQ;EAChC,UAAU,MAAM,MAAM,EAAE,MAAM,YAAY,OAAO,IAAI;EACrD,QAAQ;EACR,yEAAyE,GACzE,UAAU,eAAe,MAAM,OAAO,IAAI;EAC1C,2EAA2E,GAC3E,YAAY,UAAU,aAAa,IAAI;;AAGzC;2BAC2B,GAC3B,YAAY;EACV,MAAM,MAAM;EACZ,YAAY;EACZ,OAAO,QAAQ,IAAI;EACnB,+DAA+D,GAC/D,SAAS,QAAQ,WAAW,MAAM;;AAGpC,qEAAqE,GACrE,YAAY,aAAa,MACvB,QAAQ,QACR,GAAG,EAAE,OACL,KAAK,cAAc,UAChB;AAEL,oEAAoE,GACpE,YAAY,WACR;EAEI,QAAQ;EAAW,OAAO,KAAK;;EAC/B,YAAY,QAAQ;EAAY,SAAS,KAAK;;AAGtD,sEAAsE,GACtE,YAAY,QAAQ,OAAO,MAAM,EAAE,OAAO,MAAM,EAAE,OAAO,IAAI,IAAI;AAEjE,wEAAwE,GACxE,YAAY;EACV,MAAM,MAAM;EACZ,OAAO;EACP,MAAM,QAAQ,QAAQ,QAAQ,OAAO,KAAK;;AAG5C,oFAAoF,GACpF,YAAY,YAAY,IAAI,QAAQ,IAAI;EACtC,OAAO,QAAQ,IAAI;EACnB,OAAO,QAAQ,gBAAgB;IAAM,OAAO;;;AAG9C,+EAA+E,GAC/E,YAAY,QAAQ,IAAI,QAAQ,IAAI;EAClC,uEAAuE,GACvE,aAAa;EACb,UACI,SAAS,OAAO,MAAM,YAAY;IAAM,OAAO;oBACtC,YAAY,GAAG;EAC5B,6EAA6E,GAC7E,QAAQ;EACR,8EAA8E,GAC9E,iBAAiB,MAAM;;AAGzB,6EAA6E,GAC7E,YAAY,SACV,UAAU,eAAe,UACzB,IAAI,QACJ,IAAI,UACF,QAAQ,GAAG;EAAO,oBAAoB;;AAE1C,6EAA6E,GAC7E,YAAY,UAAU,UAAU,eAAe,YAAY,KACzD,SAAS,IACT,cAAc,UAAU"}
@@ -0,0 +1,88 @@
1
+ import { type Bundle, type Registry, type Renderer, type Rendering } from "./mod.js";
2
+ /** One group of related entities on a page: `requires`, `requires this`. */ export type Related = {
3
+ title: string;
4
+ items: Bundle[];
5
+ };
6
+ /** What the caller supplies so a view can show an entity among others. */ export type Shown<Node> = {
7
+ /** the id a person reads: `T-9` */ id: (b: Bundle) => string;
8
+ /** the kind it displays as: `task` */ kind: (b: Bundle) => string;
9
+ /** what to call an entity a property names, by eid */ name: (eid: string) => string;
10
+ /** where a link to an entity goes, by eid; absent where nothing links */ link?: (eid: string) => string | undefined;
11
+ /** how a moment reads */ when: (at: string) => string;
12
+ /** another entity, drawn through the same registry */ show: (b: Bundle, view: string) => Node | null;
13
+ /** the relation an edge states: `contains` */ relation?: (b: Bundle) => string | undefined;
14
+ /** a reference's complete bundle, when this host holds it */ get?: (eid: string) => Bundle | undefined;
15
+ /** the rows a query answers, when this host holds them: a host that can
16
+ * read more reads what a view asked for and draws it again */ query?: (q: string) => Bundle[] | undefined;
17
+ /** Entities pointing here through a relation, where the host holds its links. */ related?: (eid: string, relation: string) => Bundle[];
18
+ /** the groups of entities related to this one, for `Page` */ relations?: Related[];
19
+ /** the comments aimed at this one, oldest first, for `Page` */ comments?: Bundle[];
20
+ };
21
+ /** Where a passage reads its words, and what it says of them: the texts the
22
+ * words may be in, the first that matches what was sought giving the passage;
23
+ * the title, when the words are a document's own; what kind of words they
24
+ * are, when not plain prose (`tool result`); and the entity they sit in, with
25
+ * the word that says how (`in` a transcript, `on` what a comment is aimed
26
+ * at). */ export type Said = {
27
+ texts: (b: Bundle) => unknown[];
28
+ title?: (b: Bundle) => unknown;
29
+ what?: (b: Bundle) => string | undefined;
30
+ where?: (b: Bundle) => [word: string, eid: string] | undefined;
31
+ };
32
+ /**
33
+ * A long text as one row of a list (@yaks/ui's `Passage`): a line saying who
34
+ * said it, when and where, then the words around what was sought, every match
35
+ * marked; with nothing sought, the words it opens with. What was sought is the
36
+ * caller's `ctx.words`, the words of its query. The row names the entities it
37
+ * mentions, so it asks its host for them (`needs`).
38
+ *
39
+ * ```ts
40
+ * import { define } from '@yaks/render'
41
+ * import { passage } from '@yaks/render/views'
42
+ * import { parse } from '@yaks/query'
43
+ * import { plain, tree } from '@yaks/text'
44
+ * import { loadVocab } from '@yaks/vocab'
45
+ * import { equal } from '@yaks/testing'
46
+ *
47
+ * let said = passage({
48
+ * texts: (b) => [(b.note as { text?: string }).text],
49
+ * where: (b) => ['on', String((b.note as { on?: string }).on)],
50
+ * })
51
+ * let views = define([{ view: 'Tile', match: parse('.note'), ...said }])
52
+ * let note = {
53
+ * entity: { eid: 'n1' },
54
+ * note: { text: 'Results are often miles long.', on: 't1' },
55
+ * created: { by: 'p1', at: '2026-10-23T18:26:21Z' },
56
+ * }
57
+ * let ctx = {
58
+ * name: (eid: string) => ({ p1: 'Jeff', t1: 'T-9' })[eid] ?? eid,
59
+ * when: () => '2 hours ago',
60
+ * words: ['miles'],
61
+ * }
62
+ * let vocab = loadVocab({
63
+ * $defs: {
64
+ * note: {
65
+ * component: true,
66
+ * properties: { text: { type: 'string' }, on: { type: 'string' } },
67
+ * },
68
+ * },
69
+ * })
70
+ * equal(
71
+ * plain(tree(views, note, 'Tile', vocab, ctx)),
72
+ * 'Jeff · 2 hours ago · on T-9 Results are often miles long.',
73
+ * )
74
+ * equal(said.needs!(note), ['p1', 't1'])
75
+ * ```
76
+ */ export declare let passage: (said: Said) => {
77
+ render: Rendering;
78
+ needs: NonNullable<Renderer['needs']>;
79
+ };
80
+ /** The views any entity has. Register a package's own views ahead of these. */ export declare let views: Registry;
81
+ /** How these views dress in a terminal (@yaks/tui's painter): their own class
82
+ * names, in the colours of a theme (@yaks/ui `Colors`), named rather than
83
+ * imported: @yaks/tui builds on this package. A page's head, title and body
84
+ * and each section end with a blank line, where a browser has margins. */ export declare let sheet: (c: Record<'dim' | 'heading' | 'muted', string>) => Record<string, {
85
+ fg?: string;
86
+ gap?: boolean;
87
+ }>;
88
+ //# sourceMappingURL=views.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"views.d.ts","sources":["../views.ts"],"names":[],"mappings":"AA2BA,SACE,KAAK,MAAM,EAIX,KAAK,QAAQ,EAEb,KAAK,QAAQ,EACb,KAAK,SAAS,mBACC;AAEjB,0EAA0E,GAC1E,YAAY;EAAY,OAAO,MAAM;EAAE,OAAO;;AAE9C,wEAAwE,GACxE,YAAY,MAAM;EAChB,iCAAiC,GACjC,KAAK,GAAG,WAAW,MAAM;EACzB,oCAAoC,GACpC,OAAO,GAAG,WAAW,MAAM;EAC3B,oDAAoD,GACpD,OAAO,KAAK,MAAM,KAAK,MAAM;EAC7B,uEAAuE,GACvE,QAAQ,KAAK,MAAM,KAAK,MAAM,GAAG,SAAS;EAC1C,uBAAuB,GACvB,OAAO,IAAI,MAAM,KAAK,MAAM;EAC5B,oDAAoD,GACpD,OAAO,GAAG,QAAQ,MAAM,MAAM,KAAK,OAAO,IAAI;EAC9C,4CAA4C,GAC5C,YAAY,GAAG,WAAW,MAAM,GAAG,SAAS;EAC5C,2DAA2D,GAC3D,OAAO,KAAK,MAAM,KAAK,SAAS,SAAS;EACzC;8DAC4D,GAC5D,SAAS,GAAG,MAAM,KAAK,WAAW,SAAS;EAC3C,+EAA+E,GAC/E,WAAW,KAAK,MAAM,EAAE,UAAU,MAAM,KAAK;EAC7C,2DAA2D,GAC3D,YAAY;EACZ,6DAA6D,GAC7D,WAAW;;AAuIb;;;;;QAKQ,GACR,YAAY;EACV,QAAQ,GAAG,WAAW,OAAO;EAC7B,SAAS,GAAG,WAAW,OAAO;EAC9B,QAAQ,GAAG,WAAW,MAAM,GAAG,SAAS;EACxC,SAAS,GAAG,YAAY,MAAM,MAAM,EAAE,KAAK,MAAM,IAAI,SAAS;;AA4BhE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CA4CC,GACD,OAAO,YAAI,UACT,MAAM;EACH,QAAQ;EAAW,OAAO,YAAY,SAAS;EAoClD;AAuCF,6EAA6E,GAC7E,OAAO,YAAI,OAAO,SAQhB;AAEF;;;wEAGwE,GACxE,OAAO,YAAI,QACT,GAAG,OAAO,QAAQ,YAAY,SAAS,MAAM,MAC5C,OAAO,MAAM;EAAI,KAAK,MAAM;EAAE,MAAM,OAAO;GAS5C"}
package/archetype.js ADDED
@@ -0,0 +1,56 @@
1
+ // Presence-only queries have one answer per immutable table set. Property
2
+ // queries still read their bundle; an unknown descriptor declines the shortcut.
3
+ import { bare } from "@yaks/query/core";
4
+ import { filter } from "@yaks/match";
5
+ /** A registered query as a test of the bundle a view is handed. A view draws
6
+ * the bundle it is handed, a tombstone too (a history's deletion row): whether
7
+ * an entity still stands is a read's question, not a drawing's. */ export let drawable = (query, vocab)=>filter(query, vocab, {
8
+ graves: true
9
+ });
10
+ let presence = (c, vocab)=>{
11
+ if (c.kind == 'and' || c.kind == 'or') {
12
+ return c.clauses.every((c)=>presence(c, vocab));
13
+ }
14
+ if (c.kind == 'never') return true;
15
+ if (c.kind != 'pred' || c.path.length != 1) return false;
16
+ let hops = vocab.aim(c.path[0], bare(c));
17
+ return hops.length == 1 && !hops[0].prop && (c.op == '!' && c.value == null || c.op == '=' && c.value?.kind == 'scalar' && c.value.raw == '');
18
+ };
19
+ let queries = new WeakMap();
20
+ /** Undefined means this query or descriptor needs ordinary bundle matching. */ export let archetypeMatch = (query, bundle, vocab, lookup)=>{
21
+ if (!lookup) return;
22
+ let id = bundle.entity.archetype;
23
+ if (typeof id != 'string') return;
24
+ let byVocab = queries.get(query);
25
+ if (!byVocab) queries.set(query, byVocab = new WeakMap());
26
+ let compiled = byVocab.get(vocab);
27
+ if (compiled === undefined) {
28
+ compiled = presence(query, vocab) ? {
29
+ test: drawable(query, vocab),
30
+ answers: new WeakMap()
31
+ } : null;
32
+ byVocab.set(vocab, compiled);
33
+ }
34
+ if (!compiled) return;
35
+ // A caller that loads descriptors lazily should not fetch one for a query it
36
+ // cannot answer anyway.
37
+ let tables = lookup(id);
38
+ if (!tables) return;
39
+ let answer = compiled.answers.get(tables);
40
+ if (answer === undefined) {
41
+ // Use the existing evaluator once per set, preserving grouped-query rules
42
+ // and unknown table semantics without a second predicate implementation.
43
+ answer = compiled.test({
44
+ ...Object.fromEntries(tables.map((name)=>[
45
+ name,
46
+ {}
47
+ ])),
48
+ entity: {
49
+ eid: id
50
+ }
51
+ });
52
+ compiled.answers.set(tables, answer);
53
+ }
54
+ return answer;
55
+ };
56
+ //# sourceMappingURL=archetype.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"archetype.js","sources":["./archetype.ts"],"names":[],"mappings":"AAAA,0EAA0E;AAC1E,gFAAgF;AAChF,SAAS,IAAI,gCAA8D;AAC3E,SAAsB,MAAM,2BAAgC;AAO5D;;iEAEiE,GACjE,OAAO,IAAI,WAAW,CAAC,OAAc,QACnC,OAAO,OAAO,OAAO;IAAE,QAAQ;EAAK,GAAE;AAExC,IAAI,WAAW,CAAC,GAAW;EACzB,IAAI,EAAE,IAAI,IAAI,SAAS,EAAE,IAAI,IAAI,MAAM;IACrC,OAAO,EAAE,OAAO,CAAC,KAAK,CAAC,CAAC,IAAM,SAAS,GAAG;EAC5C;EACA,IAAI,EAAE,IAAI,IAAI,SAAS,OAAO;EAC9B,IAAI,EAAE,IAAI,IAAI,UAAU,EAAE,IAAI,CAAC,MAAM,IAAI,GAAG,OAAO;EACnD,IAAI,OAAO,MAAM,GAAG,CAAC,EAAE,IAAI,CAAC,EAAE,EAAE,KAAK;EACrC,OAAO,KAAK,MAAM,IAAI,KAAK,CAAC,IAAI,CAAC,EAAE,CAAC,IAAI,IAAI,CAC1C,EAAE,EAAE,IAAI,OAAO,EAAE,KAAK,IAAI,QAC1B,EAAE,EAAE,IAAI,OAAO,EAAE,KAAK,EAAE,QAAQ,YAAY,EAAE,KAAK,CAAC,GAAG,IAAI,EAC7D;AACF;AAEA,IAAI,UAAU,IAAI;AAWlB,6EAA6E,GAC7E,OAAO,IAAI,iBAAiB,CAC1B,OACA,QACA,OACA;EAEA,IAAI,CAAC,QAAQ;EACb,IAAI,KAAK,AAAC,OAAO,MAAM,CAA6B,SAAS;EAC7D,IAAI,OAAO,MAAM,UAAU;EAC3B,IAAI,UAAU,QAAQ,GAAG,CAAC;EAC1B,IAAI,CAAC,SAAS,QAAQ,GAAG,CAAC,OAAO,UAAU,IAAI;EAC/C,IAAI,WAAW,QAAQ,GAAG,CAAC;EAC3B,IAAI,aAAa,WAAW;IAC1B,WAAW,SAAS,OAAO,SACvB;MAAE,MAAM,SAAS,OAAO;MAAQ,SAAS,IAAI;IAAU,IACvD;IACJ,QAAQ,GAAG,CAAC,OAAO;EACrB;EACA,IAAI,CAAC,UAAU;EACf,6EAA6E;EAC7E,wBAAwB;EACxB,IAAI,SAAS,OAAO;EACpB,IAAI,CAAC,QAAQ;EACb,IAAI,SAAS,SAAS,OAAO,CAAC,GAAG,CAAC;EAClC,IAAI,WAAW,WAAW;IACxB,0EAA0E;IAC1E,yEAAyE;IACzE,SAAS,SAAS,IAAI,CAAC;MACrB,GAAG,OAAO,WAAW,CAAC,OAAO,GAAG,CAAC,CAAC,OAAS;UAAC;UAAM,CAAC;SAAE,EAAE;MACvD,QAAQ;QAAE,KAAK;MAAG;IACpB;IACA,SAAS,OAAO,CAAC,GAAG,CAAC,QAAQ;EAC/B;EACA,OAAO;AACT,EAAC"}
package/archetype.ts ADDED
@@ -0,0 +1,76 @@
1
+ // Presence-only queries have one answer per immutable table set. Property
2
+ // queries still read their bundle; an unknown descriptor declines the shortcut.
3
+ import { bare, type Clause, type Query } from '@yaks/query/core'
4
+ import { type Bundle, filter } from '@yaks/match'
5
+ import type { Vocab } from 'jsr:@yaks/vocab@0.2.36'
6
+
7
+ /** Resolve an archetype eid from a bundle to its immutable physical table
8
+ * names. */
9
+ export type ArchetypeLookup = (eid: string) => readonly string[] | undefined
10
+
11
+ /** A registered query as a test of the bundle a view is handed. A view draws
12
+ * the bundle it is handed, a tombstone too (a history's deletion row): whether
13
+ * an entity still stands is a read's question, not a drawing's. */
14
+ export let drawable = (query: Query, vocab: Vocab): ReturnType<typeof filter> =>
15
+ filter(query, vocab, { graves: true })
16
+
17
+ let presence = (c: Clause, vocab: Vocab): boolean => {
18
+ if (c.kind == 'and' || c.kind == 'or') {
19
+ return c.clauses.every((c) => presence(c, vocab))
20
+ }
21
+ if (c.kind == 'never') return true
22
+ if (c.kind != 'pred' || c.path.length != 1) return false
23
+ let hops = vocab.aim(c.path[0], bare(c))
24
+ return hops.length == 1 && !hops[0].prop && (
25
+ c.op == '!' && c.value == null ||
26
+ c.op == '=' && c.value?.kind == 'scalar' && c.value.raw == ''
27
+ )
28
+ }
29
+
30
+ let queries = new WeakMap<
31
+ Query,
32
+ WeakMap<
33
+ Vocab,
34
+ {
35
+ test: ReturnType<typeof filter>
36
+ answers: WeakMap<readonly string[], boolean>
37
+ } | null
38
+ >
39
+ >()
40
+
41
+ /** Undefined means this query or descriptor needs ordinary bundle matching. */
42
+ export let archetypeMatch = (
43
+ query: Query,
44
+ bundle: Bundle,
45
+ vocab: Vocab,
46
+ lookup?: ArchetypeLookup,
47
+ ): boolean | undefined => {
48
+ if (!lookup) return
49
+ let id = (bundle.entity as Record<string, unknown>).archetype
50
+ if (typeof id != 'string') return
51
+ let byVocab = queries.get(query)
52
+ if (!byVocab) queries.set(query, byVocab = new WeakMap())
53
+ let compiled = byVocab.get(vocab)
54
+ if (compiled === undefined) {
55
+ compiled = presence(query, vocab)
56
+ ? { test: drawable(query, vocab), answers: new WeakMap() }
57
+ : null
58
+ byVocab.set(vocab, compiled)
59
+ }
60
+ if (!compiled) return
61
+ // A caller that loads descriptors lazily should not fetch one for a query it
62
+ // cannot answer anyway.
63
+ let tables = lookup(id)
64
+ if (!tables) return
65
+ let answer = compiled.answers.get(tables)
66
+ if (answer === undefined) {
67
+ // Use the existing evaluator once per set, preserving grouped-query rules
68
+ // and unknown table semantics without a second predicate implementation.
69
+ answer = compiled.test({
70
+ ...Object.fromEntries(tables.map((name) => [name, {}])),
71
+ entity: { eid: id },
72
+ })
73
+ compiled.answers.set(tables, answer)
74
+ }
75
+ return answer
76
+ }
package/component.js ADDED
@@ -0,0 +1,39 @@
1
+ /** Whether a portable handler contains an action to run. */ export let action = (value)=>value != null && typeof value == 'object' && 'run' in value && typeof value.run == 'function';
2
+ /** Adapt a portable edit action to a control event and report its outcome. */ export let change = (act, bundle, ctx)=>(event)=>{
3
+ let control = event.currentTarget;
4
+ let input = control?.type == 'checkbox' ? control.checked : control?.value;
5
+ let patch;
6
+ try {
7
+ if (control?.validity?.badInput) {
8
+ throw new Error(control.validationMessage || 'Enter a valid value');
9
+ }
10
+ patch = act.run(bundle, input);
11
+ } catch (error) {
12
+ control?.setCustomValidity?.(error instanceof Error ? error.message : String(error));
13
+ control?.reportValidity?.();
14
+ ctx.onError?.(error, bundle);
15
+ return;
16
+ }
17
+ control?.setCustomValidity?.('');
18
+ ctx.onPatch?.(patch, bundle);
19
+ };
20
+ /** Preserve native change events for handlers in portable renders. */ export let committed = (props, bundle, ctx)=>{
21
+ if (!props) return props;
22
+ let { onChange, ref, ...rest } = props;
23
+ let changed = action(onChange) ? change(onChange, bundle, ctx) : typeof onChange == 'function' ? onChange : undefined;
24
+ if (!changed) return props;
25
+ let before = null;
26
+ return {
27
+ ...rest,
28
+ ref: (el)=>{
29
+ before?.removeEventListener('change', changed);
30
+ el?.addEventListener('change', changed);
31
+ before = el;
32
+ if (typeof ref == 'function') ref(el);
33
+ else if (ref && typeof ref == 'object' && 'current' in ref) {
34
+ ref.current = el;
35
+ }
36
+ }
37
+ };
38
+ };
39
+ //# sourceMappingURL=component.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"component.js","sources":["./component.ts"],"names":[],"mappings":"AAiBA,0DAA0D,GAC1D,OAAO,IAAI,SAAS,CAAC,QACnB,SAAS,QAAQ,OAAO,SAAS,YAAY,SAAS,SACtD,OAAO,MAAM,GAAG,IAAI,WAAU;AAYhC,4EAA4E,GAC5E,OAAO,IAAI,SACT,CAAC,KAAa,QAAgB,MAC9B,CAAC;IACC,IAAI,UAAU,MAAM,aAAa;IACjC,IAAI,QAAQ,SAAS,QAAQ,aAAa,QAAQ,OAAO,GAAG,SAAS;IACrE,IAAI;IACJ,IAAI;MACF,IAAI,SAAS,UAAU,UAAU;QAC/B,MAAM,IAAI,MAAM,QAAQ,iBAAiB,IAAI;MAC/C;MACA,QAAQ,IAAI,GAAG,CAAC,QAAQ;IAC1B,EAAE,OAAO,OAAO;MACd,SAAS,oBACP,iBAAiB,QAAQ,MAAM,OAAO,GAAG,OAAO;MAElD,SAAS;MACT,IAAI,OAAO,GAAG,OAAO;MACrB;IACF;IACA,SAAS,oBAAoB;IAC7B,IAAI,OAAO,GAAG,OAAO;EACvB,EAAC;AAEH,oEAAoE,GACpE,OAAO,IAAI,YAAY,CACrB,OACA,QACA;EAEA,IAAI,CAAC,OAAO,OAAO;EACnB,IAAI,EAAE,QAAQ,EAAE,GAAG,EAAE,GAAG,MAAM,GAAG;EACjC,IAAI,UAAU,OAAO,YACjB,OAAO,UAAU,QAAQ,OACzB,OAAO,YAAY,aACnB,WACA;EACJ,IAAI,CAAC,SAAS,OAAO;EACrB,IAAI,SAAyB;EAC7B,OAAO;IACL,GAAG,IAAI;IACP,KAAK,CAAC;MACJ,QAAQ,oBAAoB,UAAU;MACtC,IAAI,iBAAiB,UAAU;MAC/B,SAAS;MACT,IAAI,OAAO,OAAO,YAAY,IAAI;WAC7B,IAAI,OAAO,OAAO,OAAO,YAAY,aAAa,KAAK;QAC1D,IAAI,OAAO,GAAG;MAChB;IACF;EACF;AACF,EAAC"}
package/component.ts ADDED
@@ -0,0 +1,84 @@
1
+ import type { Action, Bundle, Context, Patch } from './mod.ts'
2
+
3
+ /** The application applies a successful edit and may display rejected input. */
4
+ export type Events = {
5
+ onPatch?: (patch: Patch, bundle: Bundle) => void
6
+ onError?: (error: unknown, bundle: Bundle) => void
7
+ }
8
+
9
+ /** A synchronous read; absence is allowed so a subscription can announce arrival. */
10
+ export type Store = (eid: string) => Bundle | undefined
11
+
12
+ /** Watch one entity and return the cleanup for that listener. */
13
+ export type Subscribe = (eid: string, notify: () => void) => () => void
14
+
15
+ /** An entity address and view; all remaining props are renderer context. */
16
+ export type EntityProps = Context & Events & { eid: string; view?: string }
17
+
18
+ /** Whether a portable handler contains an action to run. */
19
+ export let action = (value: unknown): value is Action =>
20
+ value != null && typeof value == 'object' && 'run' in value &&
21
+ typeof value.run == 'function'
22
+
23
+ type Control = {
24
+ type?: string
25
+ checked?: boolean
26
+ value?: string
27
+ validity?: { badInput: boolean }
28
+ validationMessage?: string
29
+ setCustomValidity?: (message: string) => void
30
+ reportValidity?: () => boolean
31
+ }
32
+
33
+ /** Adapt a portable edit action to a control event and report its outcome. */
34
+ export let change =
35
+ (act: Action, bundle: Bundle, ctx: Events): (event: Event) => void =>
36
+ (event) => {
37
+ let control = event.currentTarget as Control | null
38
+ let input = control?.type == 'checkbox' ? control.checked : control?.value
39
+ let patch: Patch
40
+ try {
41
+ if (control?.validity?.badInput) {
42
+ throw new Error(control.validationMessage || 'Enter a valid value')
43
+ }
44
+ patch = act.run(bundle, input)
45
+ } catch (error) {
46
+ control?.setCustomValidity?.(
47
+ error instanceof Error ? error.message : String(error),
48
+ )
49
+ control?.reportValidity?.()
50
+ ctx.onError?.(error, bundle)
51
+ return
52
+ }
53
+ control?.setCustomValidity?.('')
54
+ ctx.onPatch?.(patch, bundle)
55
+ }
56
+
57
+ /** Preserve native change events for handlers in portable renders. */
58
+ export let committed = (
59
+ props: Record<string, unknown> | null,
60
+ bundle: Bundle,
61
+ ctx: Events,
62
+ ): Record<string, unknown> | null => {
63
+ if (!props) return props
64
+ let { onChange, ref, ...rest } = props
65
+ let changed = action(onChange)
66
+ ? change(onChange, bundle, ctx)
67
+ : typeof onChange == 'function'
68
+ ? onChange as (event: Event) => void
69
+ : undefined
70
+ if (!changed) return props
71
+ let before: Element | null = null
72
+ return {
73
+ ...rest,
74
+ ref: (el: Element | null) => {
75
+ before?.removeEventListener('change', changed)
76
+ el?.addEventListener('change', changed)
77
+ before = el
78
+ if (typeof ref == 'function') ref(el)
79
+ else if (ref && typeof ref == 'object' && 'current' in ref) {
80
+ ref.current = el
81
+ }
82
+ },
83
+ }
84
+ }
package/deno.json ADDED
@@ -0,0 +1 @@
1
+ {"publish":{"exclude":["**/*_test.ts"]},"name":"@yaks/render","version":"0.2.36","license":"Apache-2.0","description":"Selects views, editors, and actions for entity bundles through a query-matched registry independent of the rendering host.","exports":{".":"./mod.ts","./views":"./views.ts","./component":"./component.ts","./host":"./host.ts"},"imports":{"@yaks/render":"./mod.ts","@yaks/render/views":"./views.ts","@yaks/render/component":"./component.ts","@yaks/render/host":"./host.ts"}}