@40rty/ams-ui 0.2.2 → 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,269 @@
1
+ /* ============================================================================
2
+ <SpacefrontIsland /> — the AMS island for a host-owned page.
3
+ Published as `@40rty/ams-ui/island.css`. Plain CSS, no Tailwind, UNLAYERED:
4
+ a host's own unlayered globals beat anything in a cascade layer, so a layer
5
+ would lose to `form button { width: 100% }`.
6
+
7
+ HOST-PROOF. Every element is reset by `.fourty-si :is(…)` (0,1,1), which
8
+ beats a host's element globals (`input`, `form button`), and every rule
9
+ below is `.fourty-si .fourty-si__x` (0,2,0), which beats the reset and any
10
+ host rule short of two classes. The tests pin both numbers.
11
+
12
+ Themed ONLY through these custom properties (defaults in parentheses):
13
+ --fourty-island-surface (#fff) slab fill
14
+ --fourty-island-fg (#111) everything on the slab
15
+ --fourty-island-radius (16px) slab corner
16
+ --fourty-island-edge (1px hairline of fg)
17
+ --fourty-island-shadow (three-step lift)
18
+ --fourty-island-collapsed-surface (fg) pill fill
19
+ --fourty-island-collapsed-fg (surface) pill text
20
+ --fourty-island-accent (fg) chip / stamp hover fill
21
+ --fourty-island-accent-fg (surface) text on the accent
22
+ --fourty-island-error (#b42318)
23
+ --fourty-island-font-family (inherit)
24
+ --fourty-island-offset-bottom (16px) clears a host bottom bar
25
+ --fourty-island-inset-left / -right (0) the column, container="viewport"
26
+ --fourty-island-max-width (640px)
27
+ --fourty-island-z-index (40)
28
+ ============================================================================ */
29
+
30
+ .fourty-si {
31
+ --_surface: var(--fourty-island-surface, #fff);
32
+ --_fg: var(--fourty-island-fg, #111);
33
+ --_accent: var(--fourty-island-accent, var(--_fg));
34
+ --_accent-fg: var(--fourty-island-accent-fg, var(--_surface));
35
+ --_ease: cubic-bezier(0.22, 1, 0.36, 1);
36
+ position: fixed;
37
+ left: var(--fourty-island-inset-left, 0);
38
+ right: var(--fourty-island-inset-right, 0);
39
+ bottom: calc(var(--fourty-island-offset-bottom, 16px) + env(safe-area-inset-bottom, 0px));
40
+ z-index: var(--fourty-island-z-index, 40);
41
+ display: flex;
42
+ justify-content: center;
43
+ box-sizing: border-box;
44
+ padding: 0 16px;
45
+ pointer-events: none;
46
+ font-family: var(--fourty-island-font-family, inherit);
47
+ font-size: 14px;
48
+ line-height: 1.4;
49
+ color: var(--_fg);
50
+ text-align: left;
51
+ }
52
+ .fourty-si[data-container='column'] {
53
+ position: sticky;
54
+ left: auto;
55
+ right: auto;
56
+ width: 100%;
57
+ }
58
+
59
+ /* The reset — the host's element globals stop here. */
60
+ .fourty-si :is(div, p, form, button, input, svg) {
61
+ all: unset;
62
+ box-sizing: border-box;
63
+ }
64
+ .fourty-si :focus-visible {
65
+ outline: 2px solid var(--_accent);
66
+ outline-offset: 2px;
67
+ }
68
+
69
+ .fourty-si .fourty-si__stack {
70
+ display: grid;
71
+ gap: 8px;
72
+ width: 100%;
73
+ max-width: var(--fourty-island-max-width, 640px);
74
+ pointer-events: auto;
75
+ animation: fourty-si-in 220ms var(--_ease);
76
+ }
77
+
78
+ .fourty-si .fourty-si__chips {
79
+ display: flex;
80
+ flex-wrap: wrap;
81
+ justify-content: center;
82
+ gap: 8px;
83
+ }
84
+ .fourty-si .fourty-si__chip {
85
+ padding: 4px 14px;
86
+ border: 1px solid color-mix(in srgb, var(--_fg) 24%, transparent);
87
+ border-radius: 999px;
88
+ background: var(--_surface);
89
+ cursor: pointer;
90
+ transition: background-color 150ms ease, color 150ms ease, border-color 150ms ease;
91
+ }
92
+
93
+ .fourty-si .fourty-si__slab {
94
+ display: flex;
95
+ flex-direction: column;
96
+ overflow: hidden;
97
+ border-radius: var(--fourty-island-radius, 16px);
98
+ background: var(--_surface);
99
+ box-shadow:
100
+ var(--fourty-island-edge, 0 0 0 1px color-mix(in srgb, var(--_fg) 14%, transparent)),
101
+ var(--fourty-island-shadow, 0 1px 2px color-mix(in srgb, var(--_fg) 14%, transparent),
102
+ 0 6px 16px -4px color-mix(in srgb, var(--_fg) 26%, transparent),
103
+ 0 20px 44px -12px color-mix(in srgb, var(--_fg) 36%, transparent));
104
+ }
105
+
106
+ /* The grip — the rulebook's shallow up-chevron, turned over while the thread is open. */
107
+ .fourty-si .fourty-si__grip {
108
+ display: flex;
109
+ justify-content: center;
110
+ padding: 8px 0;
111
+ cursor: pointer;
112
+ }
113
+ .fourty-si .fourty-si__chevron {
114
+ display: block;
115
+ width: 32px;
116
+ height: 5px;
117
+ overflow: visible;
118
+ color: color-mix(in srgb, var(--_fg) 42%, var(--_surface));
119
+ transition: transform 220ms var(--_ease);
120
+ }
121
+ .fourty-si .fourty-si__grip[aria-expanded='true'] .fourty-si__chevron {
122
+ transform: rotate(180deg);
123
+ }
124
+
125
+ .fourty-si .fourty-si__status {
126
+ display: block;
127
+ padding: 0 16px;
128
+ }
129
+ .fourty-si .fourty-si__latest {
130
+ display: -webkit-box;
131
+ -webkit-box-orient: vertical;
132
+ -webkit-line-clamp: 2;
133
+ overflow: hidden;
134
+ color: color-mix(in srgb, var(--_fg) 72%, transparent);
135
+ cursor: pointer;
136
+ }
137
+ .fourty-si .fourty-si__muted {
138
+ display: block;
139
+ color: color-mix(in srgb, var(--_fg) 60%, transparent);
140
+ }
141
+ .fourty-si .fourty-si__error {
142
+ display: block;
143
+ color: var(--fourty-island-error, #b42318);
144
+ }
145
+ .fourty-si .fourty-si__thread {
146
+ display: grid;
147
+ gap: 12px;
148
+ max-height: 16rem;
149
+ overflow-y: auto;
150
+ padding-bottom: 8px;
151
+ overscroll-behavior: contain;
152
+ }
153
+ .fourty-si .fourty-si__turn {
154
+ display: grid;
155
+ gap: 4px;
156
+ }
157
+ .fourty-si .fourty-si__turn p {
158
+ display: block;
159
+ }
160
+ .fourty-si .fourty-si__turn .fourty-si__asked {
161
+ color: color-mix(in srgb, var(--_fg) 55%, transparent);
162
+ }
163
+
164
+ /* Working — a light sweeping across the line while the turn is in flight. */
165
+ .fourty-si .fourty-si__working {
166
+ display: block;
167
+ color: transparent;
168
+ background: linear-gradient(100deg,
169
+ color-mix(in srgb, var(--_fg) 45%, transparent) 40%,
170
+ var(--_fg) 50%,
171
+ color-mix(in srgb, var(--_fg) 45%, transparent) 60%) 0 0 / 250% 100%;
172
+ -webkit-background-clip: text;
173
+ background-clip: text;
174
+ animation: fourty-si-shimmer 1.6s linear infinite;
175
+ }
176
+
177
+ .fourty-si .fourty-si__face {
178
+ display: flex;
179
+ align-items: center;
180
+ gap: 8px;
181
+ padding: 8px 12px 12px;
182
+ }
183
+ .fourty-si .fourty-si__field {
184
+ flex: 1 1 auto;
185
+ min-width: 0;
186
+ margin: 0;
187
+ border: 0;
188
+ background: transparent;
189
+ padding: 8px 4px;
190
+ font-size: 16px; /* under 16px iOS zooms the page on focus */
191
+ cursor: text;
192
+ }
193
+ .fourty-si .fourty-si__field::placeholder {
194
+ color: color-mix(in srgb, var(--_fg) 52%, transparent);
195
+ opacity: 1;
196
+ }
197
+
198
+ /* The send stamp — round, the slab's colours inverted. */
199
+ .fourty-si .fourty-si__stamp {
200
+ display: grid;
201
+ place-items: center;
202
+ flex: 0 0 34px;
203
+ width: 34px;
204
+ height: 34px;
205
+ margin: 0;
206
+ border: 0;
207
+ border-radius: 999px;
208
+ background: var(--_fg);
209
+ color: var(--_surface);
210
+ cursor: pointer;
211
+ transition: background-color 150ms ease, color 150ms ease, opacity 150ms ease;
212
+ }
213
+ .fourty-si .fourty-si__stamp svg {
214
+ display: block;
215
+ width: 16px;
216
+ height: 16px;
217
+ }
218
+ .fourty-si .fourty-si__stamp:disabled {
219
+ opacity: 0.4;
220
+ cursor: default;
221
+ }
222
+
223
+ /* The pill — 112 × 40, fully round (ISLAND_COLLAPSED_W/H). */
224
+ .fourty-si .fourty-si__pill {
225
+ display: grid;
226
+ place-items: center;
227
+ width: 112px;
228
+ height: 40px;
229
+ border-radius: 20px;
230
+ background: var(--fourty-island-collapsed-surface, var(--_fg));
231
+ color: var(--fourty-island-collapsed-fg, var(--_surface));
232
+ font-weight: 600;
233
+ box-shadow: 0 6px 16px -4px color-mix(in srgb, var(--_fg) 30%, transparent);
234
+ pointer-events: auto;
235
+ cursor: pointer;
236
+ animation: fourty-si-in 220ms var(--_ease);
237
+ }
238
+
239
+ @media (hover: hover) {
240
+ .fourty-si .fourty-si__chip:hover,
241
+ .fourty-si .fourty-si__stamp:not(:disabled):hover {
242
+ background: var(--_accent);
243
+ color: var(--_accent-fg);
244
+ border-color: var(--_accent);
245
+ }
246
+ }
247
+
248
+ @keyframes fourty-si-in {
249
+ from { opacity: 0; transform: translateY(8px) scale(0.98); }
250
+ }
251
+ @keyframes fourty-si-shimmer {
252
+ to { background-position: -150% 0; }
253
+ }
254
+
255
+ @media (prefers-reduced-motion: reduce) {
256
+ .fourty-si .fourty-si__stack,
257
+ .fourty-si .fourty-si__pill,
258
+ .fourty-si .fourty-si__working {
259
+ animation: none;
260
+ }
261
+ .fourty-si .fourty-si__working {
262
+ color: color-mix(in srgb, var(--_fg) 55%, transparent);
263
+ }
264
+ .fourty-si .fourty-si__chevron,
265
+ .fourty-si .fourty-si__chip,
266
+ .fourty-si .fourty-si__stamp {
267
+ transition: none;
268
+ }
269
+ }
package/dist/island.js ADDED
@@ -0,0 +1,127 @@
1
+ 'use client';
2
+
3
+ // src/shell/SpacefrontIsland.tsx
4
+ import * as React from "react";
5
+ import { renderInline, useComposerChipSelect, useComposerDraft, useFourtySession, useThreadRows } from "@40rty/ams-sdk";
6
+ import { jsx, jsxs } from "react/jsx-runtime";
7
+ var FOLD_STEP = 24;
8
+ var FOLD_AFTER = 120;
9
+ function SpacefrontIsland({
10
+ placeholder = "Ask anything\u2026",
11
+ emptyText = "Tell us what you\u2019re looking for.",
12
+ workingText = "Pulling that together\u2026",
13
+ pillLabel = "Ask",
14
+ container = "viewport",
15
+ stopKeyPropagation = true
16
+ }) {
17
+ const session = useFourtySession();
18
+ const [draft, setDraft] = useComposerDraft();
19
+ const { rows, isEmpty } = useThreadRows();
20
+ const selectChip = useComposerChipSelect();
21
+ const chips = session.suggestions === null ? [] : session.suggestions.actions.filter((chip) => chip.label.trim() !== "");
22
+ const latest = rows.length > 0 ? rows[rows.length - 1] : void 0;
23
+ const working = session.isRunning || session.isSubmitting;
24
+ const [threadOpen, setThreadOpen] = React.useState(false);
25
+ const [folded, setFolded] = React.useState(false);
26
+ const rootRef = React.useRef(null);
27
+ React.useEffect(() => {
28
+ let last = window.scrollY;
29
+ const onScroll = () => {
30
+ const y = window.scrollY;
31
+ if (Math.abs(y - last) < FOLD_STEP) return;
32
+ const root = rootRef.current;
33
+ const typing = root !== null && root.contains(document.activeElement);
34
+ setFolded(!typing && y > last && y > FOLD_AFTER);
35
+ last = y;
36
+ };
37
+ window.addEventListener("scroll", onScroll, { passive: true });
38
+ return () => window.removeEventListener("scroll", onScroll);
39
+ }, []);
40
+ const send = () => {
41
+ if (draft.trim() === "" || working) return;
42
+ session.sendMessage(draft);
43
+ setDraft("");
44
+ setThreadOpen(false);
45
+ };
46
+ const isolate = (event) => {
47
+ if (!stopKeyPropagation) return;
48
+ event.stopPropagation();
49
+ event.nativeEvent.stopImmediatePropagation();
50
+ };
51
+ const status = (() => {
52
+ if (session.error !== null) return /* @__PURE__ */ jsx("p", { className: "fourty-si__error", role: "alert", children: session.error });
53
+ if (working && (latest === void 0 || latest.prose === "")) {
54
+ return /* @__PURE__ */ jsx("p", { className: "fourty-si__working", children: workingText });
55
+ }
56
+ if (threadOpen) {
57
+ return /* @__PURE__ */ jsx("div", { className: "fourty-si__thread", children: rows.length === 0 ? /* @__PURE__ */ jsx("p", { className: "fourty-si__muted", children: emptyText }) : rows.map((row) => /* @__PURE__ */ jsxs("div", { className: "fourty-si__turn", children: [
58
+ /* @__PURE__ */ jsx("p", { className: "fourty-si__asked", children: row.visitorText }),
59
+ /* @__PURE__ */ jsx("p", { children: renderInline(row.prose, row.key) })
60
+ ] }, row.key)) });
61
+ }
62
+ if (latest === void 0) return isEmpty ? /* @__PURE__ */ jsx("p", { className: "fourty-si__muted", children: emptyText }) : null;
63
+ return /* @__PURE__ */ jsx("button", { type: "button", className: "fourty-si__latest", "aria-expanded": false, onClick: () => setThreadOpen(true), children: renderInline(latest.prose, latest.key) });
64
+ })();
65
+ return /* @__PURE__ */ jsx(
66
+ "div",
67
+ {
68
+ ref: rootRef,
69
+ className: "fourty-si",
70
+ "data-container": container,
71
+ "data-folded": folded,
72
+ "data-working": working,
73
+ onKeyDown: (event) => {
74
+ isolate(event);
75
+ if (event.key === "Escape" && threadOpen) setThreadOpen(false);
76
+ },
77
+ onKeyUp: isolate,
78
+ children: folded ? /* @__PURE__ */ jsx("button", { type: "button", className: "fourty-si__pill", "aria-label": `${pillLabel} \u2014 open the assistant`, onClick: () => setFolded(false), children: pillLabel }) : /* @__PURE__ */ jsxs("div", { className: "fourty-si__stack", children: [
79
+ chips.length > 0 && /* @__PURE__ */ jsx("div", { className: "fourty-si__chips", role: "group", "aria-label": "Suggestions", children: chips.map((chip) => /* @__PURE__ */ jsx("button", { type: "button", className: "fourty-si__chip", onClick: () => selectChip(chip), children: chip.label }, chip.id)) }),
80
+ /* @__PURE__ */ jsxs("div", { className: "fourty-si__slab", children: [
81
+ /* @__PURE__ */ jsx(
82
+ "button",
83
+ {
84
+ type: "button",
85
+ className: "fourty-si__grip",
86
+ "aria-label": threadOpen ? "Close the conversation" : "Open the conversation",
87
+ "aria-expanded": threadOpen,
88
+ onClick: () => setThreadOpen(!threadOpen),
89
+ children: /* @__PURE__ */ jsx("svg", { className: "fourty-si__chevron", viewBox: "0 0 32 5", "aria-hidden": "true", children: /* @__PURE__ */ jsx("polyline", { points: "1,4 16,1 31,4", fill: "none", stroke: "currentColor", strokeWidth: "2", strokeLinecap: "round", strokeLinejoin: "round" }) })
90
+ }
91
+ ),
92
+ /* @__PURE__ */ jsx("div", { className: "fourty-si__status", "aria-live": "polite", children: status }),
93
+ /* @__PURE__ */ jsxs(
94
+ "form",
95
+ {
96
+ className: "fourty-si__face",
97
+ onSubmit: (event) => {
98
+ event.preventDefault();
99
+ send();
100
+ },
101
+ children: [
102
+ /* @__PURE__ */ jsx(
103
+ "input",
104
+ {
105
+ type: "text",
106
+ className: "fourty-si__field",
107
+ "aria-label": placeholder,
108
+ placeholder,
109
+ enterKeyHint: "send",
110
+ autoComplete: "off",
111
+ value: draft,
112
+ onChange: (event) => setDraft(event.target.value),
113
+ onFocus: () => setThreadOpen(false)
114
+ }
115
+ ),
116
+ /* @__PURE__ */ jsx("button", { type: "submit", className: "fourty-si__stamp", "aria-label": "Send", disabled: working || draft.trim() === "", children: /* @__PURE__ */ jsx("svg", { viewBox: "0 0 16 16", "aria-hidden": "true", children: /* @__PURE__ */ jsx("path", { d: "M8 13V3M3.5 7.5 8 3l4.5 4.5", fill: "none", stroke: "currentColor", strokeWidth: "2", strokeLinecap: "round", strokeLinejoin: "round" }) }) })
117
+ ]
118
+ }
119
+ )
120
+ ] })
121
+ ] })
122
+ }
123
+ );
124
+ }
125
+ export {
126
+ SpacefrontIsland
127
+ };
@@ -0,0 +1 @@
1
+ export { SpacefrontIsland, type SpacefrontIslandProps } from '../shell/SpacefrontIsland';
@@ -0,0 +1,32 @@
1
+ import * as React from 'react';
2
+ export interface SpacefrontIslandProps {
3
+ /** The field's placeholder — also its accessible name. */
4
+ placeholder?: string;
5
+ /** What the answer line says before the visitor has asked anything. */
6
+ emptyText?: string;
7
+ /** The answer line while a turn is in flight, before its prose streams. */
8
+ workingText?: string;
9
+ /** The folded pill's text. */
10
+ pillLabel?: string;
11
+ /**
12
+ * `'viewport'` (default): fixed to the bottom of the window, between
13
+ * `--fourty-island-inset-left/right`. `'column'`: sticky to the bottom of
14
+ * the column it is rendered in — place it last in that column.
15
+ */
16
+ container?: 'viewport' | 'column';
17
+ /**
18
+ * Keep keystrokes in the field from reaching the host's own key handlers
19
+ * (single-key shortcuts, Escape-closes-drawer). Default true.
20
+ */
21
+ stopKeyPropagation?: boolean;
22
+ }
23
+ /**
24
+ * The AMS island — the composer every 40rty spacefront is recognised by, for a
25
+ * host that brings its own page: grip, latest answer (expands to the thread),
26
+ * field, round send stamp, suggestion chips, a pill while the visitor scrolls
27
+ * down. Its shape is fixed; its look is the host's, set through the
28
+ * `--fourty-island-*` custom properties in `@40rty/ams-ui/island.css` (which
29
+ * the host imports — this module has no CSS side effect). Reads only the
30
+ * public sdk hooks, so it works inside any `<Spacefront>`.
31
+ */
32
+ export declare function SpacefrontIsland({ placeholder, emptyText, workingText, pillLabel, container, stopKeyPropagation, }: SpacefrontIslandProps): React.ReactElement;
package/package.json CHANGED
@@ -38,7 +38,12 @@
38
38
  "types": "./dist/types/shell/index.d.ts",
39
39
  "default": "./dist/shell.js"
40
40
  },
41
+ "./island": {
42
+ "types": "./dist/types/island/index.d.ts",
43
+ "default": "./dist/island.js"
44
+ },
41
45
  "./motion.css": "./dist/css/preset/motion.css",
46
+ "./island.css": "./dist/css/shell/spacefront-island.css",
42
47
  "./preset/tailwind-theme.css": "./dist/css/preset/tailwind-theme.css"
43
48
  },
44
49
  "sideEffects": [
@@ -57,12 +62,12 @@
57
62
  "zod": "^3.23.0"
58
63
  },
59
64
  "peerDependencies": {
60
- "@40rty/ams-sdk": "0.2.2",
65
+ "@40rty/ams-sdk": "0.3.0",
61
66
  "lucide-react": ">=0.400.0",
62
67
  "react": ">=18.0.0",
63
68
  "react-dom": ">=18.0.0"
64
69
  },
65
- "version": "0.2.2",
70
+ "version": "0.3.0",
66
71
  "homepage": "https://docs.40rty.ai",
67
72
  "license": "UNLICENSED",
68
73
  "engines": {