@yaks/browse 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.
- package/LICENSE +202 -0
- package/README.md +324 -2
- package/_dist/app.d.ts +8 -0
- package/_dist/app.d.ts.map +1 -0
- package/_dist/cli.d.ts +16 -0
- package/_dist/cli.d.ts.map +1 -0
- package/_dist/hosting.d.ts +24 -0
- package/_dist/hosting.d.ts.map +1 -0
- package/_dist/mod.d.ts +7 -0
- package/_dist/mod.d.ts.map +1 -0
- package/_dist/types.d.ts +5 -0
- package/_dist/types.d.ts.map +1 -0
- package/_dist/url.d.ts +2 -0
- package/_dist/url.d.ts.map +1 -0
- package/app.js +10 -0
- package/app.js.map +1 -0
- package/app.ts +10 -0
- package/browser-links.js +22 -0
- package/browser-links.js.map +1 -0
- package/browser-links.ts +28 -0
- package/cli.js +172 -0
- package/cli.js.map +1 -0
- package/cli.ts +168 -0
- package/client.js +748 -0
- package/client.js.map +1 -0
- package/client.ts +734 -0
- package/clipboard.js +18 -0
- package/clipboard.js.map +1 -0
- package/clipboard.ts +17 -0
- package/commands.js +1157 -0
- package/commands.js.map +1 -0
- package/commands.ts +1108 -0
- package/components/Ansi.tsx +160 -0
- package/components/App.tsx +446 -0
- package/components/Canvas.tsx +625 -0
- package/components/Card.tsx +276 -0
- package/components/Chat.tsx +205 -0
- package/components/Configuration.tsx +218 -0
- package/components/Decision.tsx +49 -0
- package/components/Dot.tsx +52 -0
- package/components/Entity.tsx +609 -0
- package/components/Fault.tsx +43 -0
- package/components/Filter.tsx +103 -0
- package/components/Keybindings.tsx +100 -0
- package/components/Keys.tsx +67 -0
- package/components/Markdown.tsx +90 -0
- package/components/Navigation.tsx +161 -0
- package/components/New.tsx +490 -0
- package/components/Peek.tsx +168 -0
- package/components/Prio.tsx +20 -0
- package/components/Run.tsx +263 -0
- package/components/Search.tsx +280 -0
- package/components/Stamp.tsx +44 -0
- package/components/Status.tsx +514 -0
- package/components/Sync.tsx +173 -0
- package/components/Tile.tsx +50 -0
- package/components/answered.js +23 -0
- package/components/answered.js.map +1 -0
- package/components/answered.ts +25 -0
- package/components/comp.js +11 -0
- package/components/comp.js.map +1 -0
- package/components/comp.ts +10 -0
- package/components/drag.js +173 -0
- package/components/drag.js.map +1 -0
- package/components/drag.ts +198 -0
- package/components/fields.tsx +90 -0
- package/components/fixtures/README.md +10 -0
- package/components/fixtures/archetypes.json +3646 -0
- package/components/hits.js +63 -0
- package/components/hits.js.map +1 -0
- package/components/hits.ts +84 -0
- package/components/icons.tsx +177 -0
- package/components/inspect.tsx +331 -0
- package/components/mount.ts +79 -0
- package/components/nav.tsx +479 -0
- package/components/offers.js +26 -0
- package/components/offers.js.map +1 -0
- package/components/offers.ts +54 -0
- package/components/page.js +21 -0
- package/components/page.js.map +1 -0
- package/components/page.ts +18 -0
- package/components/read.js +5 -0
- package/components/read.js.map +1 -0
- package/components/read.ts +7 -0
- package/components/registry.js +285 -0
- package/components/registry.js.map +1 -0
- package/components/registry.ts +317 -0
- package/components/session_status.tsx +115 -0
- package/components/subscriptions.js +149 -0
- package/components/subscriptions.js.map +1 -0
- package/components/subscriptions.ts +161 -0
- package/components/title.tsx +21 -0
- package/components/useQuery.js +166 -0
- package/components/useQuery.js.map +1 -0
- package/components/useQuery.ts +211 -0
- package/components/views/Board.tsx +450 -0
- package/components/views/BoardTile.tsx +65 -0
- package/components/views/Dashboard.tsx +148 -0
- package/components/views/Debug.tsx +445 -0
- package/components/views/Dependency.tsx +51 -0
- package/components/views/Entry.tsx +500 -0
- package/components/views/Gist.tsx +28 -0
- package/components/views/Inline.tsx +54 -0
- package/components/views/Json.tsx +19 -0
- package/components/views/Layout.tsx +211 -0
- package/components/views/List.tsx +238 -0
- package/components/views/Md.tsx +43 -0
- package/components/views/Media.tsx +48 -0
- package/components/views/Memory.tsx +32 -0
- package/components/views/Relate.tsx +205 -0
- package/components/views/Search.tsx +42 -0
- package/components/views/Session.tsx +850 -0
- package/components/views/SessionManage.tsx +127 -0
- package/components/views/Show.tsx +758 -0
- package/components/views/Shown.tsx +72 -0
- package/components/views/Split.tsx +58 -0
- package/components/views/TaskTile.tsx +37 -0
- package/components/views/Title.tsx +105 -0
- package/components/views/Wake.tsx +77 -0
- package/components/views/Web.tsx +49 -0
- package/components/wells.js +30 -0
- package/components/wells.js.map +1 -0
- package/components/wells.ts +33 -0
- package/configuration.js +38 -0
- package/configuration.js.map +1 -0
- package/configuration.ts +41 -0
- package/decision_sync.js +88 -0
- package/decision_sync.js.map +1 -0
- package/decision_sync.ts +93 -0
- package/deno.json +1 -0
- package/domain-host.tsx +108 -0
- package/edge.js +193 -0
- package/edge.js.map +1 -0
- package/edge.ts +196 -0
- package/entry_log.js +241 -0
- package/entry_log.js.map +1 -0
- package/entry_log.ts +214 -0
- package/failure.js +22 -0
- package/failure.js.map +1 -0
- package/failure.ts +34 -0
- package/front.json +61 -0
- package/highlight.js +143 -0
- package/highlight.js.map +1 -0
- package/highlight.ts +149 -0
- package/history.js +68 -0
- package/history.js.map +1 -0
- package/history.ts +72 -0
- package/host_commands.js +107 -0
- package/host_commands.js.map +1 -0
- package/host_commands.ts +38 -0
- package/hosting.js +53 -0
- package/hosting.js.map +1 -0
- package/hosting.ts +72 -0
- package/idb.js +14 -0
- package/idb.js.map +1 -0
- package/idb.ts +15 -0
- package/index.js +232 -0
- package/index.js.map +1 -0
- package/index.ts +252 -0
- package/keybindings.js +136 -0
- package/keybindings.js.map +1 -0
- package/keybindings.ts +37 -0
- package/kit.js +103 -0
- package/kit.js.map +1 -0
- package/kit.ts +119 -0
- package/layout.js +254 -0
- package/layout.js.map +1 -0
- package/layout.ts +210 -0
- package/legacy_outbox.js +53 -0
- package/legacy_outbox.js.map +1 -0
- package/legacy_outbox.ts +63 -0
- package/live.js +2883 -0
- package/live.js.map +1 -0
- package/live.ts +3334 -0
- package/live_archetypes.js +92 -0
- package/live_archetypes.js.map +1 -0
- package/live_archetypes.ts +113 -0
- package/live_client.js +145 -0
- package/live_client.js.map +1 -0
- package/live_client.ts +120 -0
- package/main.tsx +5 -0
- package/mod.js +7 -0
- package/mod.js.map +1 -0
- package/mod.ts +7 -0
- package/mount.tsx +50 -0
- package/navigation.js +120 -0
- package/navigation.js.map +1 -0
- package/navigation.ts +152 -0
- package/near.js +83 -0
- package/near.js.map +1 -0
- package/near.ts +83 -0
- package/new.js +295 -0
- package/new.js.map +1 -0
- package/new.ts +361 -0
- package/outbox.js +112 -0
- package/outbox.js.map +1 -0
- package/outbox.ts +129 -0
- package/owner.js +39 -0
- package/owner.js.map +1 -0
- package/owner.ts +37 -0
- package/package.json +81 -4
- package/paste.js +157 -0
- package/paste.js.map +1 -0
- package/paste.ts +122 -0
- package/props.js +303 -0
- package/props.js.map +1 -0
- package/props.ts +358 -0
- package/providers.js +136 -0
- package/providers.js.map +1 -0
- package/providers.ts +194 -0
- package/query.js +987 -0
- package/query.js.map +1 -0
- package/query.ts +1113 -0
- package/remote.js +37 -0
- package/remote.js.map +1 -0
- package/remote.ts +46 -0
- package/resolver.js +149 -0
- package/resolver.js.map +1 -0
- package/resolver.ts +213 -0
- package/rfc2047.js +37 -0
- package/rfc2047.js.map +1 -0
- package/rfc2047.ts +40 -0
- package/row_holds.js +107 -0
- package/row_holds.js.map +1 -0
- package/row_holds.ts +93 -0
- package/served.ts +42 -0
- package/session_worktree.js +7 -0
- package/session_worktree.js.map +1 -0
- package/session_worktree.ts +16 -0
- package/sessions.js +57 -0
- package/sessions.js.map +1 -0
- package/sessions.ts +53 -0
- package/sha.js +161 -0
- package/sha.js.map +1 -0
- package/sha.ts +164 -0
- package/styles.css +2823 -0
- package/subs.js +36 -0
- package/subs.js.map +1 -0
- package/subs.ts +40 -0
- package/terminal-route.js +13 -0
- package/terminal-route.js.map +1 -0
- package/terminal-route.ts +17 -0
- package/terminal.js +251 -0
- package/terminal.js.map +1 -0
- package/terminal.ts +186 -0
- package/time.js +142 -0
- package/time.js.map +1 -0
- package/time.ts +133 -0
- package/title.js +25 -0
- package/title.js.map +1 -0
- package/title.ts +50 -0
- package/tui/doc.ts +6 -0
- package/tui/testing.ts +19 -0
- package/twin.js +11 -0
- package/twin.js.map +1 -0
- package/twin.ts +13 -0
- package/types.js +456 -0
- package/types.js.map +1 -0
- package/types.ts +1370 -0
- package/url.js +77 -0
- package/url.js.map +1 -0
- package/url.ts +85 -0
- package/verb.js +82 -0
- package/verb.js.map +1 -0
- package/verb.ts +137 -0
- package/warmth.js +41 -0
- package/warmth.js.map +1 -0
- package/warmth.ts +54 -0
- package/wire.js +86 -0
- package/wire.js.map +1 -0
- package/wire.ts +63 -0
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
/* @ts-types="npm:@types/react@19.3.0" */ import { useMemo } from "react";
|
|
2
|
+
import { computed } from "@preact/signals-core";
|
|
3
|
+
import { useObserved } from "@yaks/ux";
|
|
4
|
+
/** Read a derived snapshot and draw again when one of its inputs changes. */ export let useDerived = (read, dependencies)=>useObserved(useMemo(()=>computed(read), dependencies));
|
|
5
|
+
//# sourceMappingURL=read.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"read.js","sources":["./read.ts"],"names":[],"mappings":"AAAA,uCAAuC,GAAG,SAAS,OAAO,gBAA0B;AACpF,SAAS,QAAQ,+BAAyC;AAC1D,SAAS,WAAW,wBAA6B;AAEjD,2EAA2E,GAC3E,OAAO,IAAI,aAAa,CAAI,MAAe,eACzC,YAAY,QAAQ,IAAM,SAAS,OAAO,eAAc"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/* @ts-types="npm:@types/react@19.3.0" */ import { useMemo } from 'react'
|
|
2
|
+
import { computed } from '@preact/signals-core'
|
|
3
|
+
import { useObserved } from '@yaks/ux'
|
|
4
|
+
|
|
5
|
+
/** Read a derived snapshot and draw again when one of its inputs changes. */
|
|
6
|
+
export let useDerived = <T>(read: () => T, dependencies: unknown[]): T =>
|
|
7
|
+
useObserved(useMemo(() => computed(read), dependencies))
|
|
@@ -0,0 +1,285 @@
|
|
|
1
|
+
// The app's one registry and its Ent-to-bundle boundary. Selection, tab
|
|
2
|
+
// applicability, overlay precedence and action union belong to @yaks/render;
|
|
3
|
+
// the Preact host owns mounting. This page is also the host its UX
|
|
4
|
+
// components (@yaks/ux) are handed at the root: what a bundle they emit
|
|
5
|
+
// writes, where their own state lives (the page's graph, ./fields.tsx), and
|
|
6
|
+
// where what the person types waits (their drafts, ./drafts.ts).
|
|
7
|
+
import { needsIn } from "@yaks/render";
|
|
8
|
+
import { actions, applicable as offered, define as registryOf, extend as overlay, resolve as select } from "@yaks/render";
|
|
9
|
+
import { renderSelected } from "@yaks/react";
|
|
10
|
+
import { Float } from "@yaks/ui";
|
|
11
|
+
/* @ts-types="npm:@types/react@19.3.0" */ import { createElement as h } from "react";
|
|
12
|
+
import { signal } from "@preact/signals-core";
|
|
13
|
+
import { short } from "@yaks/id";
|
|
14
|
+
import { called } from "@yaks/inspect";
|
|
15
|
+
import { parseProp, propAt } from "../props.js";
|
|
16
|
+
import { backlinks, cache, capable, ent, findEid, heldId, mutate, parents, problem, row } from "../live.js";
|
|
17
|
+
import { useRows } from "./subscriptions.js";
|
|
18
|
+
import { names as edgeNames } from "@yaks/edge";
|
|
19
|
+
import { and, present } from "@yaks/query";
|
|
20
|
+
import { idIn, idOf, kindOf, statusOf, vocab } from "../types.js";
|
|
21
|
+
import { entityPath } from "../url.js";
|
|
22
|
+
import { archetypeTables, rememberArchetype } from "../live_archetypes.js";
|
|
23
|
+
import { markup } from './Markdown.tsx';
|
|
24
|
+
import { drawn } from "@yaks/markdown/structural";
|
|
25
|
+
import { Dot } from './Dot.tsx';
|
|
26
|
+
import { ago } from './Stamp.tsx';
|
|
27
|
+
import { fields, front } from './fields.tsx';
|
|
28
|
+
import { drafts } from "@yaks/draft/input";
|
|
29
|
+
import { read, rows } from "./hits.js";
|
|
30
|
+
import { useWell } from "./wells.js";
|
|
31
|
+
import { tabOffers } from "./offers.js";
|
|
32
|
+
export { vocab };
|
|
33
|
+
// The fleet adds its input language (P2, relative times and human ids);
|
|
34
|
+
// @yaks/render still owns column patches and vocabulary validation.
|
|
35
|
+
let editOptions = {
|
|
36
|
+
parse: (input, column)=>{
|
|
37
|
+
let p = propAt(column.comp, column.prop);
|
|
38
|
+
return p ? parseProp(p, input, {
|
|
39
|
+
resolve: findEid
|
|
40
|
+
}) : input;
|
|
41
|
+
}
|
|
42
|
+
};
|
|
43
|
+
export let registry = registryOf([], {
|
|
44
|
+
vocab,
|
|
45
|
+
archetypes: archetypeTables
|
|
46
|
+
});
|
|
47
|
+
// Ent flattens the spine and adds display/edge data. Queries read components;
|
|
48
|
+
// native views and action factories still receive the original Ent.
|
|
49
|
+
export let bundle = (e)=>{
|
|
50
|
+
rememberArchetype(cache.peek()[e.eid]);
|
|
51
|
+
let entity = {
|
|
52
|
+
...e.entity,
|
|
53
|
+
eid: e.eid,
|
|
54
|
+
num: e.num
|
|
55
|
+
};
|
|
56
|
+
// Presence selection reads only the spine. Bodies and derived task status
|
|
57
|
+
// are projected lazily when a value predicate or the selected view asks.
|
|
58
|
+
let row = (key)=>{
|
|
59
|
+
if (key == 'entity') return entity;
|
|
60
|
+
let value = e[key];
|
|
61
|
+
if (!value || typeof value != 'object' || Array.isArray(value)) return;
|
|
62
|
+
return key == 'task' ? {
|
|
63
|
+
...e.task,
|
|
64
|
+
status: statusOf(e)
|
|
65
|
+
} : value;
|
|
66
|
+
};
|
|
67
|
+
return new Proxy({
|
|
68
|
+
entity
|
|
69
|
+
}, {
|
|
70
|
+
get: (_target, key)=>typeof key == 'string' ? row(key) : undefined,
|
|
71
|
+
ownKeys: ()=>[
|
|
72
|
+
...new Set([
|
|
73
|
+
'entity',
|
|
74
|
+
...Object.keys(e).filter((k)=>row(k))
|
|
75
|
+
])
|
|
76
|
+
],
|
|
77
|
+
getOwnPropertyDescriptor: (_target, key)=>typeof key == 'string' && row(key) ? {
|
|
78
|
+
enumerable: true,
|
|
79
|
+
configurable: true,
|
|
80
|
+
value: row(key)
|
|
81
|
+
} : undefined
|
|
82
|
+
});
|
|
83
|
+
};
|
|
84
|
+
// Kept as the plugin's component-query builder; no predicate callbacks.
|
|
85
|
+
export let has = (...names)=>and(...names.map(present));
|
|
86
|
+
// Compose native contributions against the same plugin vocabulary as portable
|
|
87
|
+
// facets. Cache each composition so renderer selection keeps its fast memo.
|
|
88
|
+
let compositions = new WeakMap();
|
|
89
|
+
let installed = (entries)=>{
|
|
90
|
+
let prior = compositions.get(entries);
|
|
91
|
+
if (prior?.vocab == vocab) return prior.entries;
|
|
92
|
+
let selected = entries.filter((entry)=>!entry.plugin || capable(entry.plugin));
|
|
93
|
+
compositions.set(entries, {
|
|
94
|
+
vocab,
|
|
95
|
+
entries: selected
|
|
96
|
+
});
|
|
97
|
+
return selected;
|
|
98
|
+
};
|
|
99
|
+
// The tabs: the views packages offer (./offers.ts) ahead of the app's own, so
|
|
100
|
+
// an entity a package's view draws opens on it; each one only where some
|
|
101
|
+
// installed renderer draws it.
|
|
102
|
+
export let define = (rs, views)=>{
|
|
103
|
+
let tabs = [], selected, ahead = [];
|
|
104
|
+
Object.defineProperty(registry, 'renderers', {
|
|
105
|
+
configurable: true,
|
|
106
|
+
set: (entries)=>{
|
|
107
|
+
rs = entries;
|
|
108
|
+
},
|
|
109
|
+
get: ()=>installed(rs)
|
|
110
|
+
});
|
|
111
|
+
Object.defineProperty(registry, 'views', {
|
|
112
|
+
configurable: true,
|
|
113
|
+
set: (names)=>{
|
|
114
|
+
views = names;
|
|
115
|
+
selected = undefined;
|
|
116
|
+
},
|
|
117
|
+
get: ()=>{
|
|
118
|
+
let entries = installed(rs);
|
|
119
|
+
if (selected != entries || ahead != tabOffers()) {
|
|
120
|
+
selected = entries;
|
|
121
|
+
ahead = tabOffers();
|
|
122
|
+
tabs = [
|
|
123
|
+
...new Set([
|
|
124
|
+
...ahead.map((t)=>t.view),
|
|
125
|
+
...views
|
|
126
|
+
])
|
|
127
|
+
].filter((view)=>entries.some((r)=>r.view == view));
|
|
128
|
+
}
|
|
129
|
+
return tabs;
|
|
130
|
+
}
|
|
131
|
+
});
|
|
132
|
+
};
|
|
133
|
+
export let defineActions = (cs)=>{
|
|
134
|
+
Object.defineProperty(registry, 'actions', {
|
|
135
|
+
configurable: true,
|
|
136
|
+
set: (entries)=>{
|
|
137
|
+
cs = entries;
|
|
138
|
+
},
|
|
139
|
+
get: ()=>installed(cs)
|
|
140
|
+
});
|
|
141
|
+
};
|
|
142
|
+
/** Lay renderers over the app's registry, ahead of what it holds; the
|
|
143
|
+
* function returned puts back the renderers it found. */ export let extend = (rs)=>{
|
|
144
|
+
let prior = registry.renderers;
|
|
145
|
+
overlay(registry, rs);
|
|
146
|
+
return ()=>{
|
|
147
|
+
registry.renderers = prior;
|
|
148
|
+
};
|
|
149
|
+
};
|
|
150
|
+
export let applicable = (e)=>offered(registry, bundle(e), vocab);
|
|
151
|
+
export let actionsFor = (e)=>actions(registry, bundle(e), vocab, e);
|
|
152
|
+
// Some app callers inspect native component identity before mounting. Preserve
|
|
153
|
+
// that API for native views and mount portable selections through the host.
|
|
154
|
+
let components = new WeakMap();
|
|
155
|
+
export let resolve = (e, view)=>{
|
|
156
|
+
let entry = select(registry, bundle(e), view, vocab);
|
|
157
|
+
if ('Render' in entry) return entry;
|
|
158
|
+
let component = components.get(entry);
|
|
159
|
+
if (!component) {
|
|
160
|
+
component = {
|
|
161
|
+
...entry,
|
|
162
|
+
Render: ({ e, ...ctx })=>renderView(e, entry.view, ctx)
|
|
163
|
+
};
|
|
164
|
+
components.set(entry, component);
|
|
165
|
+
}
|
|
166
|
+
return component;
|
|
167
|
+
};
|
|
168
|
+
/** Apply a host patch through the fleet's optimistic write path. */ let applyPatch = (eid, patch)=>mutate(...Object.entries(patch).map(([name, comp])=>({
|
|
169
|
+
eid,
|
|
170
|
+
name,
|
|
171
|
+
comp
|
|
172
|
+
})));
|
|
173
|
+
/** All app views share the same host callbacks, including portable controls. */ export let renderView = (e, view, ctx = {})=>{
|
|
174
|
+
let b = bundle(e);
|
|
175
|
+
let entry = select(registry, b, view, vocab, ctx);
|
|
176
|
+
if (!entry) return null;
|
|
177
|
+
return 'Render' in entry ? mount(e, b, entry, ctx) : /*#__PURE__*/ h(Portable, {
|
|
178
|
+
e,
|
|
179
|
+
b,
|
|
180
|
+
ctx,
|
|
181
|
+
entry
|
|
182
|
+
});
|
|
183
|
+
};
|
|
184
|
+
// Portable views declare their reference reads; the browser holds them for
|
|
185
|
+
// the component's life, just as the CLI looks them up for its answer.
|
|
186
|
+
let Portable = ({ e, b, ctx, entry })=>{
|
|
187
|
+
useRows([
|
|
188
|
+
e.eid,
|
|
189
|
+
...needsIn(entry, b, vocab)
|
|
190
|
+
]);
|
|
191
|
+
return mount(e, b, entry, ctx);
|
|
192
|
+
};
|
|
193
|
+
let mount = (e, b, entry, ctx)=>{
|
|
194
|
+
let context = {
|
|
195
|
+
id: ux.id,
|
|
196
|
+
kind: ux.kind,
|
|
197
|
+
name: ux.name,
|
|
198
|
+
when: ux.when,
|
|
199
|
+
link: (eid)=>entityPath(idOf(ent(eid))),
|
|
200
|
+
show: (b, view, extra = {})=>renderView(ent(b.entity.eid), view, extra),
|
|
201
|
+
get: (eid)=>row(eid).value ? bundle(ent(eid)) : undefined,
|
|
202
|
+
query: answered,
|
|
203
|
+
related: (eid, relation)=>{
|
|
204
|
+
let type = edgeNames(vocab)[relation];
|
|
205
|
+
let peers = parents(eid).filter((r)=>r.type == type).map((r)=>r.parent);
|
|
206
|
+
let links = backlinks(eid).flatMap((ref)=>{
|
|
207
|
+
let b = bundle(ent(ref.from));
|
|
208
|
+
let edge = b.edge;
|
|
209
|
+
return b[relation] && edge?.to == eid && edge.from ? [
|
|
210
|
+
edge.from
|
|
211
|
+
] : [];
|
|
212
|
+
});
|
|
213
|
+
return [
|
|
214
|
+
...new Set([
|
|
215
|
+
...peers,
|
|
216
|
+
...links
|
|
217
|
+
])
|
|
218
|
+
].map((eid)=>bundle(ent(eid)));
|
|
219
|
+
},
|
|
220
|
+
onPatch: (patch)=>applyPatch(e.eid, patch),
|
|
221
|
+
onError: (error)=>{
|
|
222
|
+
problem.value = error instanceof Error ? error.message : String(error);
|
|
223
|
+
},
|
|
224
|
+
...ctx
|
|
225
|
+
};
|
|
226
|
+
return renderSelected(registry, entry, b, vocab, context, {
|
|
227
|
+
e,
|
|
228
|
+
...context
|
|
229
|
+
});
|
|
230
|
+
};
|
|
231
|
+
// What a portable view asks the graph (`query`): each query read once, its
|
|
232
|
+
// rows a signal, so a view drawn before they arrive draws again when they do.
|
|
233
|
+
// What a view asks this way is a name, not live state; the newest KEPT are
|
|
234
|
+
// held.
|
|
235
|
+
let KEPT = 500;
|
|
236
|
+
let asked = new Map();
|
|
237
|
+
let answered = (q)=>{
|
|
238
|
+
let held = asked.get(q);
|
|
239
|
+
if (!held) {
|
|
240
|
+
let rows = held = signal(undefined);
|
|
241
|
+
asked.set(q, rows);
|
|
242
|
+
if (asked.size > KEPT) asked.delete(asked.keys().next().value);
|
|
243
|
+
read(q).then((found)=>rows.value = found, ()=>rows.value = []);
|
|
244
|
+
}
|
|
245
|
+
return held.value;
|
|
246
|
+
};
|
|
247
|
+
/** What an entity is called, as @yaks/inspect's `called` says (its title,
|
|
248
|
+
* else the label or name its kind gives it: a model's `model.label`); one this page has
|
|
249
|
+
* never held, its short handle. */ export let named = (eid)=>{
|
|
250
|
+
if (!row(eid).value) return short(eid);
|
|
251
|
+
let e = ent(eid);
|
|
252
|
+
return called(bundle(e), idOf(e), e.kind);
|
|
253
|
+
};
|
|
254
|
+
// What a UX component emits: a value, written through the optimistic path;
|
|
255
|
+
// input it could not read, said where every refusal is.
|
|
256
|
+
let write = ({ entity, ...rest })=>{
|
|
257
|
+
let no = rest.Refused;
|
|
258
|
+
if (no) return void (problem.value = no.said ?? '');
|
|
259
|
+
applyPatch(entity.eid, rest);
|
|
260
|
+
};
|
|
261
|
+
/** The host this page hands its UX components (@yaks/ux) at the root. */ export let ux = {
|
|
262
|
+
get vocab () {
|
|
263
|
+
return vocab;
|
|
264
|
+
},
|
|
265
|
+
front,
|
|
266
|
+
drafts,
|
|
267
|
+
write,
|
|
268
|
+
name: named,
|
|
269
|
+
id: (b)=>idIn(b.entity.eid, b),
|
|
270
|
+
kind: (b)=>kindOf(b),
|
|
271
|
+
when: (at)=>ago(at),
|
|
272
|
+
find: rows,
|
|
273
|
+
editing: editOptions,
|
|
274
|
+
useValues: useWell,
|
|
275
|
+
get fields () {
|
|
276
|
+
return fields;
|
|
277
|
+
},
|
|
278
|
+
markup: (text)=>markup(text, null, true),
|
|
279
|
+
prose: (text)=>drawn(text, heldId),
|
|
280
|
+
wears: (comp, prop, v)=>comp == 'task' && prop == 'status' ? /*#__PURE__*/ h(Dot, {
|
|
281
|
+
status: v
|
|
282
|
+
}) : null,
|
|
283
|
+
Float
|
|
284
|
+
};
|
|
285
|
+
//# sourceMappingURL=registry.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"registry.js","sources":["./registry.ts"],"names":[],"mappings":"AAAA,wEAAwE;AACxE,6EAA6E;AAC7E,mEAAmE;AACnE,wEAAwE;AACxE,4EAA4E;AAC5E,iEAAiE;AACjE,SAAS,OAAO,4BAAiC;AACjD,SACE,OAAO,EACP,cAAc,OAAO,EAIrB,UAAU,UAAU,EAEpB,UAAU,OAAO,EAGjB,WAAW,MAAM,4BACa;AAChC,SAGE,cAAc,2BACe;AAE/B,SAAS,KAAK,wBAA6B;AAC3C,uCAAuC,GAAG,SAAS,iBAAiB,CAAC,gBAA0C;AAC/G,SAAsB,MAAM,+BAAyC;AACrE,SAAS,KAAK,wBAA6B;AAC3C,SAAS,MAAM,6BAAkC;AACjD,SAAS,SAAS,EAAE,MAAM,sBAAqB;AAC/C,SACE,SAAS,EACT,KAAK,EACL,OAAO,EACP,GAAG,EACH,OAAO,EACP,MAAM,EACN,MAAM,EACN,OAAO,EACP,OAAO,EACP,GAAG,qBACc;AACnB,SAAS,OAAO,6BAA4B;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I,OAAO,KAAK,CAAC,QAAQ,KAAK,GAAG,GAAG,IAAI,IAAI,EAAE;EAClD,WAAW,OAAO,GAAG,EAAE;AACzB;AAEA,uEAAuE,GACvE,OAAO,IAAI,KAAW;EACpB,IAAI,SAAQ;IACV,OAAO;EACT;EACA;EACA;EACA;EACA,MAAM;EACN,IAAI,CAAC,IAAM,KAAK,EAAE,MAAM,CAAC,GAAG,EAAE;EAC9B,MAAM,CAAC,IAAM,OAAO;EACpB,MAAM,CAAC,KAAO,IAAI;EAClB,MAAM;EACN,SAAS;EACT,WAAW;EACX,IAAI,UAAS;IACX,OAAO;EACT;EACA,QAAQ,CAAC,OAAS,OAAO,MAAM,MAAM;EACrC,OAAO,CAAC,OAAS,MAAM,MAAM;EAC7B,OAAO,CAAC,MAAM,MAAM,IAClB,QAAQ,UAAU,QAAQ,yBAAW,EAAE,KAAK;MAAE,QAAQ;IAAE,KAAK;EAC/D;AACF,EAAC"}
|
|
@@ -0,0 +1,317 @@
|
|
|
1
|
+
// The app's one registry and its Ent-to-bundle boundary. Selection, tab
|
|
2
|
+
// applicability, overlay precedence and action union belong to @yaks/render;
|
|
3
|
+
// the Preact host owns mounting. This page is also the host its UX
|
|
4
|
+
// components (@yaks/ux) are handed at the root: what a bundle they emit
|
|
5
|
+
// writes, where their own state lives (the page's graph, ./fields.tsx), and
|
|
6
|
+
// where what the person types waits (their drafts, ./drafts.ts).
|
|
7
|
+
import { needsIn } from '@yaks/render'
|
|
8
|
+
import {
|
|
9
|
+
actions,
|
|
10
|
+
applicable as offered,
|
|
11
|
+
type Bundle,
|
|
12
|
+
type Context,
|
|
13
|
+
type Contributor as Contribution,
|
|
14
|
+
define as registryOf,
|
|
15
|
+
type EditOptions,
|
|
16
|
+
extend as overlay,
|
|
17
|
+
type Patch,
|
|
18
|
+
type Renderer as PortableRenderer,
|
|
19
|
+
resolve as select,
|
|
20
|
+
} from '@yaks/render'
|
|
21
|
+
import {
|
|
22
|
+
type ComponentRenderer,
|
|
23
|
+
type Events,
|
|
24
|
+
renderSelected,
|
|
25
|
+
} from '@yaks/react'
|
|
26
|
+
import type { Host } from 'jsr:@yaks/ux@0.2.36'
|
|
27
|
+
import { Float } from '@yaks/ui'
|
|
28
|
+
/* @ts-types="npm:@types/react@19.3.0" */ import { createElement as h, type ReactNode } from 'react'
|
|
29
|
+
import { type Signal, signal } from '@preact/signals-core'
|
|
30
|
+
import { short } from '@yaks/id'
|
|
31
|
+
import { called } from '@yaks/inspect'
|
|
32
|
+
import { parseProp, propAt } from '../props.js'
|
|
33
|
+
import {
|
|
34
|
+
backlinks,
|
|
35
|
+
cache,
|
|
36
|
+
capable,
|
|
37
|
+
ent,
|
|
38
|
+
findEid,
|
|
39
|
+
heldId,
|
|
40
|
+
mutate,
|
|
41
|
+
parents,
|
|
42
|
+
problem,
|
|
43
|
+
row,
|
|
44
|
+
} from '../live.js'
|
|
45
|
+
import { useRows } from './subscriptions.js'
|
|
46
|
+
import { names as edgeNames } from '@yaks/edge'
|
|
47
|
+
import { and, present } from '@yaks/query'
|
|
48
|
+
import { type Ent, idIn, idOf, kindOf, statusOf, vocab } from '../types.js'
|
|
49
|
+
import { entityPath } from '../url.js'
|
|
50
|
+
import { archetypeTables, rememberArchetype } from '../live_archetypes.js'
|
|
51
|
+
import { markup } from './Markdown.tsx'
|
|
52
|
+
import { drawn } from '@yaks/markdown/structural'
|
|
53
|
+
import { Dot } from './Dot.tsx'
|
|
54
|
+
import { ago } from './Stamp.tsx'
|
|
55
|
+
import { fields, front } from './fields.tsx'
|
|
56
|
+
import { drafts } from '@yaks/draft/input'
|
|
57
|
+
import { read, rows } from './hits.js'
|
|
58
|
+
import { useWell } from './wells.js'
|
|
59
|
+
import { type Offer, tabOffers } from './offers.js'
|
|
60
|
+
|
|
61
|
+
export type Renderer = ComponentRenderer<Ent> & {
|
|
62
|
+
plugin?: string
|
|
63
|
+
file?: { ext: string; mime: string; text: (e: Ent) => string }
|
|
64
|
+
}
|
|
65
|
+
export type Entry = (Renderer | PortableRenderer) & { plugin?: string }
|
|
66
|
+
export type Render = Renderer['Render']
|
|
67
|
+
export type Action = { label: string; run: () => void; mod?: string }
|
|
68
|
+
export type Contributor = Contribution<Action, Ent> & { plugin?: string }
|
|
69
|
+
|
|
70
|
+
export { vocab }
|
|
71
|
+
// The fleet adds its input language (P2, relative times and human ids);
|
|
72
|
+
// @yaks/render still owns column patches and vocabulary validation.
|
|
73
|
+
let editOptions: EditOptions = {
|
|
74
|
+
parse: (input, column) => {
|
|
75
|
+
let p = propAt(column.comp, column.prop)
|
|
76
|
+
return p ? parseProp(p, input, { resolve: findEid }) : input
|
|
77
|
+
},
|
|
78
|
+
}
|
|
79
|
+
export let registry = registryOf<Entry, Action, Ent>([], {
|
|
80
|
+
vocab,
|
|
81
|
+
archetypes: archetypeTables,
|
|
82
|
+
})
|
|
83
|
+
|
|
84
|
+
// Ent flattens the spine and adds display/edge data. Queries read components;
|
|
85
|
+
// native views and action factories still receive the original Ent.
|
|
86
|
+
export let bundle = (e: Ent): Bundle => {
|
|
87
|
+
rememberArchetype(cache.peek()[e.eid])
|
|
88
|
+
let entity = { ...(e.entity as object), eid: e.eid, num: e.num }
|
|
89
|
+
// Presence selection reads only the spine. Bodies and derived task status
|
|
90
|
+
// are projected lazily when a value predicate or the selected view asks.
|
|
91
|
+
let row = (key: string) => {
|
|
92
|
+
if (key == 'entity') return entity
|
|
93
|
+
let value = e[key]
|
|
94
|
+
if (!value || typeof value != 'object' || Array.isArray(value)) return
|
|
95
|
+
return key == 'task' ? { ...e.task, status: statusOf(e) } : value
|
|
96
|
+
}
|
|
97
|
+
return new Proxy({ entity } as Bundle, {
|
|
98
|
+
get: (_target, key) => typeof key == 'string' ? row(key) : undefined,
|
|
99
|
+
ownKeys: () => [
|
|
100
|
+
...new Set([
|
|
101
|
+
'entity',
|
|
102
|
+
...Object.keys(e).filter((k) => row(k)),
|
|
103
|
+
]),
|
|
104
|
+
],
|
|
105
|
+
getOwnPropertyDescriptor: (_target, key) =>
|
|
106
|
+
typeof key == 'string' && row(key)
|
|
107
|
+
? { enumerable: true, configurable: true, value: row(key) }
|
|
108
|
+
: undefined,
|
|
109
|
+
})
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
// Kept as the plugin's component-query builder; no predicate callbacks.
|
|
113
|
+
export let has = (...names: string[]) => and(...names.map(present))
|
|
114
|
+
|
|
115
|
+
// Compose native contributions against the same plugin vocabulary as portable
|
|
116
|
+
// facets. Cache each composition so renderer selection keeps its fast memo.
|
|
117
|
+
let compositions = new WeakMap<
|
|
118
|
+
object,
|
|
119
|
+
{ vocab: typeof vocab; entries: unknown[] }
|
|
120
|
+
>()
|
|
121
|
+
let installed = <T extends { plugin?: string }>(entries: T[]): T[] => {
|
|
122
|
+
let prior = compositions.get(entries)
|
|
123
|
+
if (prior?.vocab == vocab) return prior.entries as T[]
|
|
124
|
+
let selected = entries.filter((entry) =>
|
|
125
|
+
!entry.plugin || capable(entry.plugin)
|
|
126
|
+
)
|
|
127
|
+
compositions.set(entries, { vocab, entries: selected })
|
|
128
|
+
return selected
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
// The tabs: the views packages offer (./offers.ts) ahead of the app's own, so
|
|
132
|
+
// an entity a package's view draws opens on it; each one only where some
|
|
133
|
+
// installed renderer draws it.
|
|
134
|
+
export let define = (rs: Entry[], views: string[]) => {
|
|
135
|
+
let tabs: string[] = [], selected: Entry[] | undefined, ahead: Offer[] = []
|
|
136
|
+
Object.defineProperty(registry, 'renderers', {
|
|
137
|
+
configurable: true,
|
|
138
|
+
set: (entries: Entry[]) => {
|
|
139
|
+
rs = entries
|
|
140
|
+
},
|
|
141
|
+
get: () => installed(rs),
|
|
142
|
+
})
|
|
143
|
+
Object.defineProperty(registry, 'views', {
|
|
144
|
+
configurable: true,
|
|
145
|
+
set: (names: string[]) => {
|
|
146
|
+
views = names
|
|
147
|
+
selected = undefined
|
|
148
|
+
},
|
|
149
|
+
get: () => {
|
|
150
|
+
let entries = installed(rs)
|
|
151
|
+
if (selected != entries || ahead != tabOffers()) {
|
|
152
|
+
selected = entries
|
|
153
|
+
ahead = tabOffers()
|
|
154
|
+
tabs = [...new Set([...ahead.map((t) => t.view), ...views])]
|
|
155
|
+
.filter((view) => entries.some((r) => r.view == view))
|
|
156
|
+
}
|
|
157
|
+
return tabs
|
|
158
|
+
},
|
|
159
|
+
})
|
|
160
|
+
}
|
|
161
|
+
export let defineActions = (cs: Contributor[]) => {
|
|
162
|
+
Object.defineProperty(registry, 'actions', {
|
|
163
|
+
configurable: true,
|
|
164
|
+
set: (entries: Contributor[]) => {
|
|
165
|
+
cs = entries
|
|
166
|
+
},
|
|
167
|
+
get: () => installed(cs),
|
|
168
|
+
})
|
|
169
|
+
}
|
|
170
|
+
/** Lay renderers over the app's registry, ahead of what it holds; the
|
|
171
|
+
* function returned puts back the renderers it found. */
|
|
172
|
+
export let extend = (rs: Entry[]): () => void => {
|
|
173
|
+
let prior = registry.renderers
|
|
174
|
+
overlay(registry, rs)
|
|
175
|
+
return () => {
|
|
176
|
+
registry.renderers = prior
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
export let applicable = (e: Ent) => offered(registry, bundle(e), vocab)
|
|
180
|
+
export let actionsFor = (e: Ent) => actions(registry, bundle(e), vocab, e)
|
|
181
|
+
// Some app callers inspect native component identity before mounting. Preserve
|
|
182
|
+
// that API for native views and mount portable selections through the host.
|
|
183
|
+
let components = new WeakMap<PortableRenderer, Renderer>()
|
|
184
|
+
export let resolve = (e: Ent, view?: string): Renderer => {
|
|
185
|
+
let entry = select(registry, bundle(e), view, vocab)!
|
|
186
|
+
if ('Render' in entry) return entry
|
|
187
|
+
let component = components.get(entry)
|
|
188
|
+
if (!component) {
|
|
189
|
+
component = {
|
|
190
|
+
...entry,
|
|
191
|
+
Render: ({ e, ...ctx }) => renderView(e, entry.view, ctx),
|
|
192
|
+
}
|
|
193
|
+
components.set(entry, component)
|
|
194
|
+
}
|
|
195
|
+
return component
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
/** Apply a host patch through the fleet's optimistic write path. */
|
|
199
|
+
let applyPatch = (eid: string, patch: Patch) =>
|
|
200
|
+
mutate(...Object.entries(patch).map(([name, comp]) => ({ eid, name, comp })))
|
|
201
|
+
|
|
202
|
+
/** All app views share the same host callbacks, including portable controls. */
|
|
203
|
+
export let renderView = (
|
|
204
|
+
e: Ent,
|
|
205
|
+
view?: string,
|
|
206
|
+
ctx: Context & Events = {},
|
|
207
|
+
): ReactNode => {
|
|
208
|
+
let b = bundle(e)
|
|
209
|
+
let entry = select(registry, b, view, vocab, ctx)
|
|
210
|
+
if (!entry) return null
|
|
211
|
+
return 'Render' in entry
|
|
212
|
+
? mount(e, b, entry, ctx)
|
|
213
|
+
: h(Portable, { e, b, ctx, entry })
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
// Portable views declare their reference reads; the browser holds them for
|
|
217
|
+
// the component's life, just as the CLI looks them up for its answer.
|
|
218
|
+
let Portable = ({ e, b, ctx, entry }: {
|
|
219
|
+
e: Ent
|
|
220
|
+
b: Bundle
|
|
221
|
+
ctx: Context & Events
|
|
222
|
+
entry: PortableRenderer
|
|
223
|
+
}) => {
|
|
224
|
+
useRows([e.eid, ...needsIn(entry, b, vocab)])
|
|
225
|
+
return mount(e, b, entry, ctx)
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
let mount = (e: Ent, b: Bundle, entry: Entry, ctx: Context & Events) => {
|
|
229
|
+
let context: Context & Events = {
|
|
230
|
+
id: ux.id,
|
|
231
|
+
kind: ux.kind,
|
|
232
|
+
name: ux.name,
|
|
233
|
+
when: ux.when,
|
|
234
|
+
link: (eid: string) => entityPath(idOf(ent(eid))),
|
|
235
|
+
show: (b: Bundle, view: string, extra: Context = {}) =>
|
|
236
|
+
renderView(ent(b.entity.eid), view, extra),
|
|
237
|
+
get: (eid: string) => row(eid).value ? bundle(ent(eid)) : undefined,
|
|
238
|
+
query: answered,
|
|
239
|
+
related: (eid: string, relation: string) => {
|
|
240
|
+
let type = edgeNames(vocab)[relation]
|
|
241
|
+
let peers = parents(eid)
|
|
242
|
+
.filter((r) => r.type == type)
|
|
243
|
+
.map((r) => r.parent)
|
|
244
|
+
let links = backlinks(eid).flatMap((ref) => {
|
|
245
|
+
let b = bundle(ent(ref.from))
|
|
246
|
+
let edge = b.edge as { from?: string; to?: string } | undefined
|
|
247
|
+
return b[relation] && edge?.to == eid && edge.from ? [edge.from] : []
|
|
248
|
+
})
|
|
249
|
+
return [...new Set([...peers, ...links])].map((eid) => bundle(ent(eid)))
|
|
250
|
+
},
|
|
251
|
+
onPatch: (patch) => applyPatch(e.eid, patch),
|
|
252
|
+
onError: (error) => {
|
|
253
|
+
problem.value = error instanceof Error ? error.message : String(error)
|
|
254
|
+
},
|
|
255
|
+
...ctx,
|
|
256
|
+
}
|
|
257
|
+
return renderSelected(registry, entry, b, vocab, context, { e, ...context })
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
// What a portable view asks the graph (`query`): each query read once, its
|
|
261
|
+
// rows a signal, so a view drawn before they arrive draws again when they do.
|
|
262
|
+
// What a view asks this way is a name, not live state; the newest KEPT are
|
|
263
|
+
// held.
|
|
264
|
+
let KEPT = 500
|
|
265
|
+
let asked = new Map<string, Signal<Bundle[] | undefined>>()
|
|
266
|
+
let answered = (q: string): Bundle[] | undefined => {
|
|
267
|
+
let held = asked.get(q)
|
|
268
|
+
if (!held) {
|
|
269
|
+
let rows = held = signal<Bundle[] | undefined>(undefined)
|
|
270
|
+
asked.set(q, rows)
|
|
271
|
+
if (asked.size > KEPT) asked.delete(asked.keys().next().value!)
|
|
272
|
+
read(q).then((found) => rows.value = found, () => rows.value = [])
|
|
273
|
+
}
|
|
274
|
+
return held.value
|
|
275
|
+
}
|
|
276
|
+
|
|
277
|
+
/** What an entity is called, as @yaks/inspect's `called` says (its title,
|
|
278
|
+
* else the label or name its kind gives it: a model's `model.label`); one this page has
|
|
279
|
+
* never held, its short handle. */
|
|
280
|
+
export let named = (eid: string): string => {
|
|
281
|
+
if (!row(eid).value) return short(eid)
|
|
282
|
+
let e = ent(eid)
|
|
283
|
+
return called(bundle(e), idOf(e), e.kind)
|
|
284
|
+
}
|
|
285
|
+
|
|
286
|
+
// What a UX component emits: a value, written through the optimistic path;
|
|
287
|
+
// input it could not read, said where every refusal is.
|
|
288
|
+
let write = ({ entity, ...rest }: Bundle) => {
|
|
289
|
+
let no = rest.Refused as { said?: string } | undefined
|
|
290
|
+
if (no) return void (problem.value = no.said ?? '')
|
|
291
|
+
applyPatch(entity.eid, rest as Patch)
|
|
292
|
+
}
|
|
293
|
+
|
|
294
|
+
/** The host this page hands its UX components (@yaks/ux) at the root. */
|
|
295
|
+
export let ux: Host = {
|
|
296
|
+
get vocab() {
|
|
297
|
+
return vocab
|
|
298
|
+
},
|
|
299
|
+
front,
|
|
300
|
+
drafts,
|
|
301
|
+
write,
|
|
302
|
+
name: named,
|
|
303
|
+
id: (b) => idIn(b.entity.eid, b),
|
|
304
|
+
kind: (b) => kindOf(b),
|
|
305
|
+
when: (at) => ago(at),
|
|
306
|
+
find: rows,
|
|
307
|
+
editing: editOptions,
|
|
308
|
+
useValues: useWell,
|
|
309
|
+
get fields() {
|
|
310
|
+
return fields
|
|
311
|
+
},
|
|
312
|
+
markup: (text) => markup(text, null, true),
|
|
313
|
+
prose: (text) => drawn(text, heldId),
|
|
314
|
+
wears: (comp, prop, v) =>
|
|
315
|
+
comp == 'task' && prop == 'status' ? h(Dot, { status: v }) : null,
|
|
316
|
+
Float,
|
|
317
|
+
}
|