@hollis-labs/surface-page 0.0.0-stage → 0.2.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.
Files changed (57) hide show
  1. package/README.md +24 -2
  2. package/dist/chunks/chunk-ZT6LTRMY.js +220 -0
  3. package/dist/gallery.js +1730 -0
  4. package/dist/index.js +2706 -0
  5. package/dist/registry-items.json +37 -0
  6. package/dist/sdk.js +24 -0
  7. package/dist/types/ade/Overlay.d.ts +4 -0
  8. package/dist/types/ade/hub.d.ts +5 -0
  9. package/dist/types/agent/AgentPanel.d.ts +24 -0
  10. package/dist/types/agent/api.d.ts +61 -0
  11. package/dist/types/agent/index.d.ts +2 -0
  12. package/dist/types/agent/items.d.ts +25 -0
  13. package/dist/types/agent/session.d.ts +34 -0
  14. package/dist/types/boot.d.ts +12 -0
  15. package/dist/types/cards/renderers.d.ts +22 -0
  16. package/dist/types/cards/store.d.ts +41 -0
  17. package/dist/types/cards/views.d.ts +9 -0
  18. package/dist/types/desk/AttentionBadge.d.ts +4 -0
  19. package/dist/types/desk/Confirm.d.ts +2 -0
  20. package/dist/types/desk/ContextInspector.d.ts +2 -0
  21. package/dist/types/desk/Desktop.d.ts +6 -0
  22. package/dist/types/desk/GhostCursor.d.ts +1 -0
  23. package/dist/types/desk/Palette.d.ts +9 -0
  24. package/dist/types/desk/ThemePicker.d.ts +3 -0
  25. package/dist/types/desk/attention.d.ts +17 -0
  26. package/dist/types/desk/commands.d.ts +13 -0
  27. package/dist/types/desk/composing.d.ts +10 -0
  28. package/dist/types/desk/coreViews.d.ts +2 -0
  29. package/dist/types/desk/keys.d.ts +12 -0
  30. package/dist/types/desk/moduleApi.d.ts +3 -0
  31. package/dist/types/desk/store.d.ts +123 -0
  32. package/dist/types/gallery/Gallery.d.ts +64 -0
  33. package/dist/types/gallery/Specimen.d.ts +22 -0
  34. package/dist/types/gallery/ade.d.ts +1 -0
  35. package/dist/types/gallery/approval.d.ts +1 -0
  36. package/dist/types/gallery/cards.d.ts +1 -0
  37. package/dist/types/gallery/chat.d.ts +1 -0
  38. package/dist/types/gallery/composer.d.ts +1 -0
  39. package/dist/types/gallery/controls.d.ts +1 -0
  40. package/dist/types/gallery/display.d.ts +1 -0
  41. package/dist/types/gallery/genui.d.ts +1 -0
  42. package/dist/types/gallery/index.d.ts +9 -0
  43. package/dist/types/gallery/overlays.d.ts +1 -0
  44. package/dist/types/gallery/theme.d.ts +19 -0
  45. package/dist/types/gallery/windows.d.ts +1 -0
  46. package/dist/types/genui/card.d.ts +2 -0
  47. package/dist/types/index.d.ts +15 -0
  48. package/dist/types/sdk/anchors.d.ts +8 -0
  49. package/dist/types/sdk/hooks.d.ts +11 -0
  50. package/dist/types/sdk/icon.d.ts +5 -0
  51. package/dist/types/sdk/index.d.ts +9 -0
  52. package/dist/types/sdk/marks.d.ts +10 -0
  53. package/dist/types/sdk/runtime.d.ts +40 -0
  54. package/dist/types/sdk/types.d.ts +99 -0
  55. package/package.json +71 -4
  56. package/vite.d.ts +3 -0
  57. package/vite.js +42 -0
package/README.md CHANGED
@@ -1,3 +1,25 @@
1
- # Temporary Holding Version
1
+ # @hollis-labs/surface-page
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ The core of a Surface app's page: the desktop (the bar, windows that tile, tab and float, the palette), the
4
+ agent panel, cards, generated surfaces and ADE's overlays, plus the sdk a module's views import. It is built
5
+ from `web/src` in the [Surface](https://github.com/hollis-labs/surface) repository, where Surface's own apps
6
+ compile it from source.
7
+
8
+ It draws nothing of its own. Every control is one of the app's installed Surface registry components
9
+ (`@/components/ui/*`), so the app installs those first and keeps them in step with the registry:
10
+
11
+ ```sh
12
+ npx surface-ui init --ref v0.1.0
13
+ npx surface-ui add theme --for @hollis-labs/surface-page
14
+ ```
15
+
16
+ | Import | What |
17
+ |---|---|
18
+ | `@hollis-labs/surface-page` | `mountPage({ modules, core? })`, `Page`, `Desktop`, `CardHost`, `CardsWindow`, `coreWeb`, `registerCard` |
19
+ | `@hollis-labs/surface-page/sdk` | What a module's views may import: `useEvent`, `useSetting`, `useMarks`, `useAnchor`, `Icon`, the types |
20
+ | `@hollis-labs/surface-page/gallery` | `galleryViews`: the Components window, which needs every registry item installed |
21
+ | `@hollis-labs/surface-page/vite` | `surfacePage()`: the Vite settings the package needs |
22
+
23
+ The page talks to the app's server over `/api` and `/mcp`. The full setup is in the repository's
24
+ `registry/README.md`, under "An app in its own repository". The package's version is the Surface tag the app
25
+ is on: its registry `ref` and the other `@hollis-labs/surface-*` packages move with it.
@@ -0,0 +1,220 @@
1
+ // ../../web/src/sdk/anchors.ts
2
+ import { useCallback } from "react";
3
+
4
+ // ../../web/src/sdk/runtime.ts
5
+ var ApiError = class extends Error {
6
+ status;
7
+ body;
8
+ constructor(message, status, body) {
9
+ super(message);
10
+ this.status = status;
11
+ this.body = body;
12
+ }
13
+ };
14
+ async function call(method, path, body) {
15
+ const res = await fetch(path, {
16
+ method,
17
+ headers: body === void 0 ? void 0 : { "Content-Type": "application/json" },
18
+ body: body === void 0 ? void 0 : JSON.stringify(body)
19
+ });
20
+ const text = await res.text();
21
+ let data = null;
22
+ try {
23
+ data = text ? JSON.parse(text) : null;
24
+ } catch {
25
+ data = text;
26
+ }
27
+ if (!res.ok) {
28
+ const msg = data?.error ?? `${res.status} ${res.statusText}`;
29
+ throw new ApiError(msg, res.status, data);
30
+ }
31
+ return data;
32
+ }
33
+ var listeners = /* @__PURE__ */ new Set();
34
+ var matches = (prefix, topic) => prefix === "" || topic === prefix || topic.startsWith(`${prefix}.`);
35
+ function onEvent(prefix, fn) {
36
+ const entry = { prefix, fn };
37
+ listeners.add(entry);
38
+ return () => {
39
+ listeners.delete(entry);
40
+ };
41
+ }
42
+ function dispatch(ev) {
43
+ for (const l of [...listeners]) {
44
+ if (!matches(l.prefix, ev.topic)) continue;
45
+ try {
46
+ l.fn(ev);
47
+ } catch (err) {
48
+ console.error("surface: an event listener failed", ev.topic, err);
49
+ }
50
+ }
51
+ }
52
+ var source = null;
53
+ var connected = false;
54
+ var connectionListeners = /* @__PURE__ */ new Set();
55
+ var isConnected = () => connected;
56
+ function onConnection(fn) {
57
+ connectionListeners.add(fn);
58
+ return () => {
59
+ connectionListeners.delete(fn);
60
+ };
61
+ }
62
+ function connect() {
63
+ if (source) return;
64
+ source = new EventSource("/api/events");
65
+ source.addEventListener("surface", (e) => {
66
+ if (!connected) {
67
+ connected = true;
68
+ for (const fn of connectionListeners) fn(true);
69
+ }
70
+ try {
71
+ dispatch(JSON.parse(e.data));
72
+ } catch (err) {
73
+ console.error("surface: bad event", err);
74
+ }
75
+ });
76
+ source.onopen = () => {
77
+ connected = true;
78
+ for (const fn of connectionListeners) fn(true);
79
+ };
80
+ source.onerror = () => {
81
+ connected = false;
82
+ for (const fn of connectionListeners) fn(false);
83
+ };
84
+ }
85
+ var settings = /* @__PURE__ */ new Map();
86
+ async function loadSettings() {
87
+ const list = await call("GET", "/api/settings");
88
+ settings.clear();
89
+ for (const s of list) settings.set(s.full_key, s);
90
+ return list;
91
+ }
92
+ var getSetting = (fullKey) => settings.get(fullKey)?.value;
93
+ var allSettings = () => [...settings.values()];
94
+ onEvent("config.changed", (ev) => {
95
+ const d = ev.data;
96
+ const s = settings.get(d.key);
97
+ if (s) settings.set(d.key, { ...s, value: d.value, set: true });
98
+ });
99
+ async function setSetting(fullKey, value) {
100
+ await call("PUT", `/api/settings/${encodeURIComponent(fullKey)}`, { value });
101
+ }
102
+ var listMarks = (ref) => call("GET", `/api/marks?ref=${encodeURIComponent(ref)}`);
103
+
104
+ // ../../web/src/sdk/anchors.ts
105
+ var byWindow = /* @__PURE__ */ new Map();
106
+ var pending = /* @__PURE__ */ new Map();
107
+ function report(win) {
108
+ clearTimeout(pending.get(win));
109
+ pending.set(
110
+ win,
111
+ setTimeout(() => {
112
+ pending.delete(win);
113
+ const list = [...byWindow.get(win)?.entries() ?? []].map(([name, e]) => ({ name, label: e.label }));
114
+ void call("PUT", `/api/ade/anchors/${encodeURIComponent(win)}`, list).catch(() => {
115
+ });
116
+ }, 150)
117
+ );
118
+ }
119
+ function useAnchor(win, name, label) {
120
+ const id = typeof win === "string" ? win : win.id;
121
+ return useCallback(
122
+ (el) => {
123
+ if (!el) return;
124
+ let m = byWindow.get(id);
125
+ if (!m) {
126
+ m = /* @__PURE__ */ new Map();
127
+ byWindow.set(id, m);
128
+ }
129
+ m.set(name, { el, label });
130
+ report(id);
131
+ return () => {
132
+ const now = byWindow.get(id);
133
+ if (now?.get(name)?.el !== el) return;
134
+ now.delete(name);
135
+ if (!now.size) byWindow.delete(id);
136
+ report(id);
137
+ };
138
+ },
139
+ [id, name, label]
140
+ );
141
+ }
142
+ var anchorElement = (win, name) => byWindow.get(win)?.get(name)?.el ?? null;
143
+
144
+ // ../../web/src/sdk/hooks.ts
145
+ import { useEffect, useRef, useState } from "react";
146
+ function useEvent(prefix, fn) {
147
+ const ref = useRef(fn);
148
+ ref.current = fn;
149
+ useEffect(() => onEvent(prefix, (ev) => ref.current(ev)), [prefix]);
150
+ }
151
+ function useSetting(fullKey) {
152
+ const [value, setValue] = useState(() => getSetting(fullKey));
153
+ useEffect(() => {
154
+ setValue(getSetting(fullKey));
155
+ return onEvent("config.changed", (ev) => {
156
+ const d = ev.data;
157
+ if (d?.key === fullKey) setValue(d.value);
158
+ });
159
+ }, [fullKey]);
160
+ return value;
161
+ }
162
+ function useMarks(ref) {
163
+ const [marks, setMarks] = useState([]);
164
+ useEffect(() => {
165
+ if (!ref) {
166
+ setMarks([]);
167
+ return;
168
+ }
169
+ let live = true;
170
+ const load = () => listMarks(ref).then((m) => {
171
+ if (live) setMarks(m);
172
+ });
173
+ void load();
174
+ const off = onEvent("marks.changed", (ev) => {
175
+ if (ev.data?.ref === ref) void load();
176
+ });
177
+ return () => {
178
+ live = false;
179
+ off();
180
+ };
181
+ }, [ref]);
182
+ return marks;
183
+ }
184
+
185
+ // ../../web/src/sdk/icon.tsx
186
+ import { icons } from "lucide-react";
187
+ import { jsx } from "react/jsx-runtime";
188
+ var pascal = (name) => name.split("-").map((p) => p.charAt(0).toUpperCase() + p.slice(1)).join("");
189
+ function Icon({ name, ...props }) {
190
+ const Cmp = name ? icons[pascal(name)] : void 0;
191
+ if (!Cmp) return /* @__PURE__ */ jsx(icons.Dot, { ...props });
192
+ return /* @__PURE__ */ jsx(Cmp, { ...props });
193
+ }
194
+
195
+ // ../../web/src/sdk/marks.ts
196
+ var addMark = (m) => call("POST", "/api/marks", m);
197
+ var replyMark = (id, body) => call("POST", `/api/marks/${encodeURIComponent(id)}/replies`, { body });
198
+ var resolveMark = (id) => call("POST", `/api/marks/${encodeURIComponent(id)}/resolve`);
199
+
200
+ export {
201
+ ApiError,
202
+ call,
203
+ onEvent,
204
+ isConnected,
205
+ onConnection,
206
+ connect,
207
+ loadSettings,
208
+ getSetting,
209
+ allSettings,
210
+ setSetting,
211
+ useAnchor,
212
+ anchorElement,
213
+ useEvent,
214
+ useSetting,
215
+ useMarks,
216
+ Icon,
217
+ addMark,
218
+ replyMark,
219
+ resolveMark
220
+ };