@crossworks/share-ui 0.230.43

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 (44) hide show
  1. package/LICENSE.md +135 -0
  2. package/package.json +68 -0
  3. package/src/app-bridge-protocol.ts +115 -0
  4. package/src/app-presenter.tsx +25 -0
  5. package/src/app-sandbox.tsx +552 -0
  6. package/src/appearance.ts +192 -0
  7. package/src/avatar.test.ts +229 -0
  8. package/src/avatar.ts +731 -0
  9. package/src/backgrounds.test.ts +119 -0
  10. package/src/backgrounds.ts +118 -0
  11. package/src/draw-presenter.tsx +39 -0
  12. package/src/event-presenter.tsx +62 -0
  13. package/src/file-presenter.tsx +76 -0
  14. package/src/formula-calculator.tsx +209 -0
  15. package/src/formula-presenter.test.ts +128 -0
  16. package/src/formula-presenter.tsx +301 -0
  17. package/src/help-topics.ts +104 -0
  18. package/src/lib/ink-audit.test.ts +314 -0
  19. package/src/lib/theme-css-blocks.ts +26 -0
  20. package/src/lib/theme-generator.test.ts +179 -0
  21. package/src/lib/theme-registry.gen.ts +352 -0
  22. package/src/lib/themes.test.ts +308 -0
  23. package/src/lib/themes.ts +75 -0
  24. package/src/lib/utils.ts +6 -0
  25. package/src/nav-items.ts +225 -0
  26. package/src/note-presenter.tsx +14 -0
  27. package/src/page-outline.tsx +127 -0
  28. package/src/table-presenter.tsx +226 -0
  29. package/src/task-presenter.tsx +60 -0
  30. package/src/ui/button.tsx +50 -0
  31. package/src/ui/input.tsx +18 -0
  32. package/src/ui/label.tsx +20 -0
  33. package/src/view-payload.ts +82 -0
  34. package/styles/app.css +1098 -0
  35. package/styles/themes.css +6198 -0
  36. package/themes/generate.d.mts +11 -0
  37. package/themes/generate.mjs +618 -0
  38. package/themes/model.d.mts +24 -0
  39. package/themes/model.mjs +213 -0
  40. package/themes/preview.html +145 -0
  41. package/themes/seeds.d.mts +16 -0
  42. package/themes/seeds.mjs +3694 -0
  43. package/tsconfig.json +15 -0
  44. package/tsconfig.tsbuildinfo +1 -0
package/LICENSE.md ADDED
@@ -0,0 +1,135 @@
1
+ # License
2
+
3
+ Mantle is **dual-licensed** by Cross Works Engineering (Pty) Ltd:
4
+
5
+ 1. **Public license — Functional Source License 1.1 (MIT Future), reproduced in
6
+ full below.** Free to use, self-host, modify, and run for any purpose that is
7
+ not a Competing Use (see the _Permitted Purpose_ clause). Two years after each
8
+ version is first published, that version automatically converts to the MIT
9
+ license.
10
+ 2. **Commercial license — see [`LICENSE-COMMERCIAL.md`](./LICENSE-COMMERCIAL.md).**
11
+ A paid agreement that lifts the FSL's _Competing Use_ restriction for partners
12
+ who want to embed Mantle in a commercial product or offer it as a service
13
+ during the two-year window. Contact **licensing@crossworks.engineering**.
14
+
15
+ For a plain-language explanation of how the two licenses fit together and what the
16
+ key terms mean, see [`LICENSING.md`](./LICENSING.md). Third-party open-source
17
+ components bundled with Mantle are attributed in
18
+ [`THIRD-PARTY-NOTICES.md`](./THIRD-PARTY-NOTICES.md).
19
+
20
+ The "Change Date" for each release is **two years after that release is first made
21
+ available** under this license; on the Change Date that release becomes available
22
+ under the MIT license (the _Grant of Future License_ below).
23
+
24
+ ---
25
+
26
+ # Functional Source License, Version 1.1, MIT Future License
27
+
28
+ ## Abbreviation
29
+
30
+ FSL-1.1-MIT
31
+
32
+ ## Notice
33
+
34
+ Copyright 2026 Cross Works Engineering (Pty) Ltd
35
+
36
+ ## Terms and Conditions
37
+
38
+ ### Licensor ("We")
39
+
40
+ The party offering the Software under these Terms and Conditions.
41
+
42
+ ### The Software
43
+
44
+ The "Software" is each version of the software that we make available under
45
+ these Terms and Conditions, as indicated by our inclusion of these Terms and
46
+ Conditions with the Software.
47
+
48
+ ### License Grant
49
+
50
+ Subject to your compliance with this License Grant and the Patents,
51
+ Redistribution and Trademark clauses below, we hereby grant you the right to
52
+ use, copy, modify, create derivative works, publicly perform, publicly display
53
+ and redistribute the Software for any Permitted Purpose identified below.
54
+
55
+ ### Permitted Purpose
56
+
57
+ A Permitted Purpose is any purpose other than a Competing Use. A Competing Use
58
+ means making the Software available to others in a commercial product or
59
+ service that:
60
+
61
+ 1. substitutes for the Software;
62
+
63
+ 2. substitutes for any other product or service we offer using the Software
64
+ that exists as of the date we make the Software available; or
65
+
66
+ 3. offers the same or substantially similar functionality as the Software.
67
+
68
+ Permitted Purposes specifically include using the Software:
69
+
70
+ 1. for your internal use and access;
71
+
72
+ 2. for non-commercial education;
73
+
74
+ 3. for non-commercial research; and
75
+
76
+ 4. in connection with professional services that you provide to a licensee
77
+ using the Software in accordance with these Terms and Conditions.
78
+
79
+ ### Patents
80
+
81
+ To the extent your use for a Permitted Purpose would necessarily infringe our
82
+ patents, the license grant above includes a license under our patents. If you
83
+ make a claim against any party that the Software infringes or contributes to
84
+ the infringement of any patent, then your patent license to the Software ends
85
+ immediately.
86
+
87
+ ### Redistribution
88
+
89
+ The Terms and Conditions apply to all copies, modifications and derivatives of
90
+ the Software.
91
+
92
+ If you redistribute any copies, modifications or derivatives of the Software,
93
+ you must include a copy of or a link to these Terms and Conditions and not
94
+ remove any copyright notices provided in or with the Software.
95
+
96
+ ### Disclaimer
97
+
98
+ THE SOFTWARE IS PROVIDED "AS IS" AND WITHOUT WARRANTIES OF ANY KIND, EXPRESS OR
99
+ IMPLIED, INCLUDING WITHOUT LIMITATION WARRANTIES OF FITNESS FOR A PARTICULAR
100
+ PURPOSE, MERCHANTABILITY, TITLE OR NON-INFRINGEMENT.
101
+
102
+ IN NO EVENT WILL WE HAVE ANY LIABILITY TO YOU ARISING OUT OF OR RELATED TO THE
103
+ SOFTWARE, INCLUDING INDIRECT, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES,
104
+ EVEN IF WE HAVE BEEN INFORMED OF THEIR POSSIBILITY IN ADVANCE.
105
+
106
+ ### Trademarks
107
+
108
+ Except for displaying the License Details and identifying us as the origin of
109
+ the Software, you have no right under these Terms and Conditions to use our
110
+ trademarks, trade names, service marks or product names.
111
+
112
+ ## Grant of Future License
113
+
114
+ We hereby irrevocably grant you an additional license to use the Software under
115
+ the MIT license that is effective on the second anniversary of the date we make
116
+ the Software available. On or after that date, you may use the Software under
117
+ the MIT license, in which case the following will apply:
118
+
119
+ Permission is hereby granted, free of charge, to any person obtaining a copy of
120
+ this software and associated documentation files (the "Software"), to deal in
121
+ the Software without restriction, including without limitation the rights to
122
+ use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
123
+ of the Software, and to permit persons to whom the Software is furnished to do
124
+ so, subject to the following conditions:
125
+
126
+ The above copyright notice and this permission notice shall be included in all
127
+ copies or substantial portions of the Software.
128
+
129
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
130
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
131
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
132
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
133
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
134
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
135
+ SOFTWARE.
package/package.json ADDED
@@ -0,0 +1,68 @@
1
+ {
2
+ "name": "@crossworks/share-ui",
3
+ "version": "0.230.43",
4
+ "description": "The server-rendered share surface — the /s/<token> presenters, view-payload contract, mini-app sandbox, and the few primitives they need. Lives in MANTLE (the server renders these), published for jackdaw to consume; may depend only on @mantle/{client-types,content-core} (the jackdaw-repo-split boundary).",
5
+ "exports": {
6
+ "./app-presenter": "./src/app-presenter.tsx",
7
+ "./draw-presenter": "./src/draw-presenter.tsx",
8
+ "./event-presenter": "./src/event-presenter.tsx",
9
+ "./file-presenter": "./src/file-presenter.tsx",
10
+ "./formula-calculator": "./src/formula-calculator.tsx",
11
+ "./formula-presenter": "./src/formula-presenter.tsx",
12
+ "./note-presenter": "./src/note-presenter.tsx",
13
+ "./table-presenter": "./src/table-presenter.tsx",
14
+ "./task-presenter": "./src/task-presenter.tsx",
15
+ "./view-payload": "./src/view-payload.ts",
16
+ "./app-sandbox": "./src/app-sandbox.tsx",
17
+ "./app-bridge-protocol": "./src/app-bridge-protocol.ts",
18
+ "./ui/button": "./src/ui/button.tsx",
19
+ "./ui/input": "./src/ui/input.tsx",
20
+ "./ui/label": "./src/ui/label.tsx",
21
+ "./lib/utils": "./src/lib/utils.ts",
22
+ "./page-outline": "./src/page-outline.tsx",
23
+ "./nav-items": "./src/nav-items.ts",
24
+ "./help-topics": "./src/help-topics.ts",
25
+ "./appearance": "./src/appearance.ts",
26
+ "./backgrounds": "./src/backgrounds.ts",
27
+ "./avatar": "./src/avatar.ts",
28
+ "./lib/themes": "./src/lib/themes.ts",
29
+ "./styles/themes.css": "./styles/themes.css",
30
+ "./styles/app.css": "./styles/app.css"
31
+ },
32
+ "dependencies": {
33
+ "@radix-ui/react-label": "^2.1.12",
34
+ "@radix-ui/react-slot": "^1.3.0",
35
+ "class-variance-authority": "^0.7.1",
36
+ "clsx": "^2.1.1",
37
+ "katex": "^0.18.1",
38
+ "lucide-react": "^1.25.0",
39
+ "react-markdown": "^10.1.0",
40
+ "remark-gfm": "^4.0.1",
41
+ "tailwind-merge": "^3.5.0",
42
+ "@dicebear/core": "^10.4.0",
43
+ "@dicebear/styles": "^10.3.0",
44
+ "@mantle/content-core": "npm:@crossworks/content-core@0.230.43",
45
+ "@mantle/client-types": "npm:@crossworks/client-types@0.230.43"
46
+ },
47
+ "peerDependencies": {
48
+ "react": "^19.2.7",
49
+ "react-dom": "^19.2.7"
50
+ },
51
+ "devDependencies": {
52
+ "@types/katex": "^0.16.8",
53
+ "@types/react": "^19.2.17",
54
+ "@types/react-dom": "^19.2.3",
55
+ "@types/node": "^22.20.1"
56
+ },
57
+ "license": "SEE LICENSE IN LICENSE.md",
58
+ "repository": {
59
+ "type": "git",
60
+ "url": "https://github.com/crossworks-engineering/mantle"
61
+ },
62
+ "scripts": {
63
+ "typecheck": "tsc --noEmit",
64
+ "themes:build": "node themes/generate.mjs",
65
+ "themes:check": "node themes/generate.mjs --check",
66
+ "themes:report": "node themes/generate.mjs --report"
67
+ }
68
+ }
@@ -0,0 +1,115 @@
1
+ /**
2
+ * The postMessage contract between a running mini app (inside its sandboxed
3
+ * iframe) and the host page. Zero-dependency + client-safe so both the host
4
+ * `AppSandbox` component and the API routes can import it.
5
+ *
6
+ * The iframe-side counterpart is bundled into every app by `@mantle/app-build`
7
+ * (see its `@host` kit module); the two MUST agree on these shapes. Keep this
8
+ * the single source of truth and mirror any change there.
9
+ *
10
+ * Trust model: the iframe has an opaque origin (sandbox without
11
+ * allow-same-origin), so it holds no credentials and cannot call host APIs
12
+ * directly. Its ONLY channel is postMessage to the parent, which re-derives the
13
+ * owner from the session and enforces the per-app allowlist server-side.
14
+ */
15
+
16
+ export const BRIDGE_VERSION = 1 as const;
17
+
18
+ /** Requests the app sends UP to the host (await a matching BridgeRes by `id`). */
19
+ export type BridgeReq =
20
+ | { v: 1; id: string; kind: 'tool.call'; slug: string; input: unknown }
21
+ | { v: 1; id: string; kind: 'db.query'; sql: string; params?: unknown[] }
22
+ | { v: 1; id: string; kind: 'db.exec'; sql: string; params?: unknown[] }
23
+ // Team-hub surface only: the shell answers from the /api/team/hub payload it
24
+ // already holds (data-down). Rejected with ok:false anywhere else (owner
25
+ // editor, ordinary shares) so hub apps degrade to a local preview.
26
+ | { v: 1; id: string; kind: 'hub.get' };
27
+
28
+ /** Where a hub app can ask the /team shell to navigate (intent-up: the SHELL
29
+ * owns chat and the briefing reader; the app can open them, never embed them). */
30
+ export type HubNavTarget = 'chat' | { briefing: string } | { app: string };
31
+
32
+ /** Fire-and-forget lifecycle events the app emits (no response expected). */
33
+ export type BridgeEvt =
34
+ | { v: 1; kind: 'ready' }
35
+ | { v: 1; kind: 'resize'; height: number }
36
+ | { v: 1; kind: 'error'; message: string; stack?: string }
37
+ // Inspect mode (host-injected overlay → host): the user locked/cleared a
38
+ // selection (regionId = a data-app-region value, or null when cleared), or
39
+ // exited inspect via Esc (`inspect` with on:false).
40
+ | { v: 1; kind: 'select'; regionId: string | null; label?: string }
41
+ | { v: 1; kind: 'inspect'; on: boolean }
42
+ // Team-hub surface only; ignored anywhere else.
43
+ | { v: 1; kind: 'hub.nav'; target: HubNavTarget };
44
+
45
+ /** Responses the host sends DOWN, correlated to a BridgeReq by `id`. */
46
+ export type BridgeRes =
47
+ { v: 1; id: string; ok: true; output: unknown } | { v: 1; id: string; ok: false; error: string };
48
+
49
+ /** Control messages the host pushes DOWN unprompted: agent region annotations,
50
+ * and inspect-mode control (toggle select mode; set/clear the locked selection
51
+ * from the host side, e.g. when the user clears the focus chip). */
52
+ export type BridgeCtl =
53
+ | { v: 1; kind: 'annotate'; regions: { id: string; note?: string; severity?: 'info' | 'warn' }[] }
54
+ | { v: 1; kind: 'inspect'; on: boolean }
55
+ | { v: 1; kind: 'select'; regionId: string | null }
56
+ // Live theme: the host's <html> class + data-color-theme, mirrored onto the
57
+ // iframe's <html> so a dark/light or colour-theme switch restyles a RUNNING
58
+ // app (every theme's tokens are already in the linked stylesheet).
59
+ | { v: 1; kind: 'theme'; cls: string; colorTheme: string | null };
60
+
61
+ export type FromApp = BridgeReq | BridgeEvt;
62
+ export type FromHost = BridgeRes | BridgeCtl;
63
+
64
+ export function isFromApp(m: unknown): m is FromApp {
65
+ return !!m && typeof m === 'object' && (m as { v?: unknown }).v === BRIDGE_VERSION;
66
+ }
67
+
68
+ /** The `hub.get` answer on the /team surface — everything the built-in hub
69
+ * renders, handed to a designated hub app so it can render the same things its
70
+ * own way. Mirrors the /api/team/hub response; every field is member-safe by
71
+ * construction (sections are the owner's team-mode page shares, stats are
72
+ * whitelisted coarse counts). `memberName` is display-grade — a hub app must
73
+ * never build permission logic on it. */
74
+ export type HubData = {
75
+ /** Brain's site-name pref; null ⇒ the app should fall back to its own label. */
76
+ siteName: string | null;
77
+ /** Signed-in member's display name (null when the contact has none). */
78
+ memberName: string | null;
79
+ version: string;
80
+ sections: {
81
+ token: string;
82
+ title: string;
83
+ icon: string | null;
84
+ summary: string | null;
85
+ updatedAt: string;
86
+ /** Token of the nearest team-shared ANCESTOR page, or null when top-level.
87
+ * A hub app nests children under their parent; the built-in hub renders
88
+ * only top-level (null) as cards. Every section is an openable share. */
89
+ parentToken: string | null;
90
+ }[];
91
+ /** Whitelisted coarse per-type node counts (zeros included — the app decides
92
+ * what to hide). Same shape as the /api/team/hub `counts` field. */
93
+ counts: Record<string, number>;
94
+ /** The owner's OTHER team-shared apps (green published build), as launcher
95
+ * cards — the designated hub app is excluded. Open one with
96
+ * `host.hub.openApp(token)`; the shell renders it in the in-hub reader
97
+ * (same /s/<token> iframe + "back to hub" as a briefing). */
98
+ apps: {
99
+ token: string;
100
+ title: string;
101
+ description: string | null;
102
+ updatedAt: string;
103
+ }[];
104
+ };
105
+
106
+ /** Narrow an unknown `hub.nav` target to a valid one — the shell must not
107
+ * navigate on a malformed message from a (possibly buggy) app bundle. */
108
+ export function isHubNavTarget(t: unknown): t is HubNavTarget {
109
+ if (t === 'chat') return true;
110
+ if (!t || typeof t !== 'object') return false;
111
+ const briefing = (t as { briefing?: unknown }).briefing;
112
+ if (typeof briefing === 'string' && briefing.length > 0) return true;
113
+ const app = (t as { app?: unknown }).app;
114
+ return typeof app === 'string' && app.length > 0;
115
+ }
@@ -0,0 +1,25 @@
1
+ 'use client';
2
+
3
+ /**
4
+ * Public presenter for a SHARED mini-app. The app gets the WHOLE viewport
5
+ * (h-dvh, no chrome) in share mode (shareToken) so the bundle + tool/db
6
+ * brokers resolve under /s/<token>/* — no owner session. How the app fills
7
+ * (or doesn't fill) that space is the app's own business; it owns its
8
+ * internal layout and scrolling.
9
+ */
10
+ import { AppSandbox } from './app-sandbox';
11
+ import type { ShareViewPayload } from './view-payload';
12
+
13
+ export function AppPresenter({
14
+ view,
15
+ token,
16
+ }: {
17
+ view: Extract<ShareViewPayload, { kind: 'app' }>;
18
+ token: string;
19
+ }) {
20
+ return (
21
+ <div className="h-dvh w-full">
22
+ <AppSandbox appId={view.appId} shareToken={token} frame="viewport" />
23
+ </div>
24
+ );
25
+ }