@simpleplatform/ui-kit 0.0.0-stage → 0.1.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 (41) hide show
  1. package/LICENSE +201 -0
  2. package/README.md +488 -2
  3. package/custom-elements.json +24 -0
  4. package/dist/contracts/index.d.ts +2 -0
  5. package/dist/contracts/index.d.ts.map +1 -0
  6. package/dist/contracts/index.js +1 -0
  7. package/dist/contracts/status-badge.d.ts +4 -0
  8. package/dist/contracts/status-badge.d.ts.map +1 -0
  9. package/dist/contracts/status-badge.js +8 -0
  10. package/dist/elements/index.d.ts +2 -0
  11. package/dist/elements/index.d.ts.map +1 -0
  12. package/dist/elements/index.js +1 -0
  13. package/dist/elements/status-badge.d.ts +19 -0
  14. package/dist/elements/status-badge.d.ts.map +1 -0
  15. package/dist/elements/status-badge.js +123 -0
  16. package/dist/index.d.ts +3 -0
  17. package/dist/index.d.ts.map +1 -0
  18. package/dist/index.js +2 -0
  19. package/dist/react/index.d.ts +4 -0
  20. package/dist/react/index.d.ts.map +1 -0
  21. package/dist/react/index.js +3 -0
  22. package/dist/react/mount-boundary.d.ts +13 -0
  23. package/dist/react/mount-boundary.d.ts.map +1 -0
  24. package/dist/react/mount-boundary.js +70 -0
  25. package/dist/react/record-activity.d.ts +11 -0
  26. package/dist/react/record-activity.d.ts.map +1 -0
  27. package/dist/react/record-activity.js +144 -0
  28. package/dist/react/record-bridge.d.ts +34 -0
  29. package/dist/react/record-bridge.d.ts.map +1 -0
  30. package/dist/react/record-bridge.js +8 -0
  31. package/dist/react/record-form.d.ts +11 -0
  32. package/dist/react/record-form.d.ts.map +1 -0
  33. package/dist/react/record-form.js +112 -0
  34. package/dist/react/status-badge.d.ts +15 -0
  35. package/dist/react/status-badge.d.ts.map +1 -0
  36. package/dist/react/status-badge.js +6 -0
  37. package/dist/runtime.d.ts +22 -0
  38. package/dist/runtime.d.ts.map +1 -0
  39. package/dist/runtime.js +46 -0
  40. package/package.json +59 -3
  41. package/theme.css +56 -0
@@ -0,0 +1,112 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { useEffect, useRef, useState } from 'react';
3
+ import { loadRuntime, RuntimeLoadError } from '../runtime.js';
4
+ import { waitForElementMount } from './mount-boundary.js';
5
+ import { getManagedRecordBridge } from './record-bridge.js';
6
+ const FORM_READY_EVENT = 'simple-record-form-ready';
7
+ const FORM_ERROR_EVENT = 'simple-record-form-error';
8
+ /**
9
+ * Renders the host-owned RecordForm without exposing its field registry or
10
+ * form model as customer extension points.
11
+ */
12
+ export function RecordForm({ record }) {
13
+ return _jsx(RecordFormInstance, { record: record }, record.id);
14
+ }
15
+ function RecordFormInstance({ record }) {
16
+ const containerRef = useRef(null);
17
+ const [state, setState] = useState({ kind: 'loading' });
18
+ const [attempt, setAttempt] = useState(0);
19
+ const bridge = getManagedRecordBridge(record);
20
+ const [formModel, setFormModel] = useState(() => bridge?.form);
21
+ const formModelRef = useRef(formModel);
22
+ formModelRef.current = formModel;
23
+ const hasFormModel = formModel !== undefined;
24
+ useEffect(() => {
25
+ if (!bridge)
26
+ return;
27
+ setFormModel(bridge.form);
28
+ return bridge.subscribeFormModel(setFormModel);
29
+ }, [bridge]);
30
+ useEffect(() => {
31
+ const element = containerRef.current?.querySelector('simple-record-form');
32
+ if (element)
33
+ element.formModel = formModel;
34
+ }, [formModel]);
35
+ useEffect(() => {
36
+ if (!bridge) {
37
+ setState({
38
+ error: new Error('The managed record form is unavailable for this Record Space.'),
39
+ kind: 'error',
40
+ });
41
+ return;
42
+ }
43
+ if (!hasFormModel || !containerRef.current)
44
+ return;
45
+ let disposed = false;
46
+ let failed = false;
47
+ let element;
48
+ let disposeMount;
49
+ const mountController = new AbortController();
50
+ const mount = async () => {
51
+ try {
52
+ if (bridge.runtime)
53
+ await loadRuntime(bridge.runtime);
54
+ if (!customElements.get('simple-record-form')) {
55
+ throw new Error('The Simple UI Runtime did not register RecordForm.');
56
+ }
57
+ if (disposed || !containerRef.current)
58
+ return;
59
+ element = document.createElement('simple-record-form');
60
+ element.blurField = bridge.blurField;
61
+ element.focusField = bridge.focusField;
62
+ element.formModel = formModelRef.current;
63
+ element.graphql = bridge.graphql;
64
+ element.capabilities = bridge.capabilities;
65
+ element.navigate = bridge.capabilities?.navigate;
66
+ element.registerSubmitPreparation = bridge.registerSubmitPreparation;
67
+ element.record = record;
68
+ element.subscribe = bridge.subscribe;
69
+ const ready = waitForElementMount({
70
+ element,
71
+ errorEventName: FORM_ERROR_EVENT,
72
+ fallbackErrorMessage: 'The RecordForm could not be rendered.',
73
+ onPostMountError: (error) => {
74
+ failed = true;
75
+ if (!disposed)
76
+ setState({ error, kind: 'error' });
77
+ },
78
+ readyEventName: FORM_READY_EVENT,
79
+ signal: mountController.signal,
80
+ timeoutMessage: 'The RecordForm did not become ready in time.',
81
+ });
82
+ containerRef.current.replaceChildren(element);
83
+ disposeMount = await ready;
84
+ if (!disposed && !failed)
85
+ setState({ kind: 'ready' });
86
+ }
87
+ catch (error) {
88
+ if (!disposed) {
89
+ const failure = error instanceof RuntimeLoadError || error instanceof Error
90
+ ? error
91
+ : new Error('The Simple UI Runtime could not be loaded.');
92
+ setState({ error: failure, kind: 'error' });
93
+ }
94
+ }
95
+ };
96
+ void mount();
97
+ return () => {
98
+ disposed = true;
99
+ mountController.abort();
100
+ disposeMount?.();
101
+ if (containerRef.current && element && containerRef.current.contains(element))
102
+ containerRef.current.replaceChildren();
103
+ };
104
+ }, [attempt, bridge, hasFormModel, record]);
105
+ if (state.kind === 'error') {
106
+ return (_jsxs("div", { role: "alert", children: [_jsx("p", { children: state.error.message }), _jsx("button", { onClick: () => {
107
+ setState({ kind: 'loading' });
108
+ setAttempt(current => current + 1);
109
+ }, type: "button", children: "Try again" })] }));
110
+ }
111
+ return (_jsx("div", { "aria-busy": state.kind === 'loading' ? 'true' : undefined, "data-simple-managed-record-form": "", ref: containerRef }));
112
+ }
@@ -0,0 +1,15 @@
1
+ import type { SimpleStatusBadgeTone } from '../contracts/status-badge.js';
2
+ import '../elements/status-badge.js';
3
+ export interface StatusBadgeProps {
4
+ /** Extra context announced with the visible label when a screen reader reads the badge. */
5
+ description?: string;
6
+ label: string;
7
+ tone: SimpleStatusBadgeTone;
8
+ }
9
+ /** React bridge for the canonical <simple-status-badge> Element. */
10
+ export declare function StatusBadge({ description, label, tone }: StatusBadgeProps): import("react").ReactElement<{
11
+ description: string | undefined;
12
+ label: string;
13
+ tone: "neutral" | "info" | "success" | "warning" | "danger";
14
+ }, string | import("react").JSXElementConstructor<any>>;
15
+ //# sourceMappingURL=status-badge.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"status-badge.d.ts","sourceRoot":"","sources":["../../src/react/status-badge.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,8BAA8B,CAAA;AAIzE,OAAO,6BAA6B,CAAA;AAEpC,MAAM,WAAW,gBAAgB;IAC/B,2FAA2F;IAC3F,WAAW,CAAC,EAAE,MAAM,CAAA;IACpB,KAAK,EAAE,MAAM,CAAA;IACb,IAAI,EAAE,qBAAqB,CAAA;CAC5B;AAED,oEAAoE;AACpE,wBAAgB,WAAW,CAAC,EAAE,WAAW,EAAE,KAAK,EAAE,IAAI,EAAE,EAAE,gBAAgB;;;;wDAEzE"}
@@ -0,0 +1,6 @@
1
+ import { createElement } from 'react';
2
+ import '../elements/status-badge.js';
3
+ /** React bridge for the canonical <simple-status-badge> Element. */
4
+ export function StatusBadge({ description, label, tone }) {
5
+ return createElement('simple-status-badge', { description, label, tone }, label);
6
+ }
@@ -0,0 +1,22 @@
1
+ export interface RuntimeDescriptor {
2
+ url: string;
3
+ version: string;
4
+ }
5
+ export interface RuntimeInfo {
6
+ version: string;
7
+ }
8
+ export interface RuntimeModule {
9
+ version?: unknown;
10
+ }
11
+ export declare class RuntimeLoadError extends Error {
12
+ readonly expected: string;
13
+ readonly received?: string;
14
+ constructor(message: string, expected: string, received?: string);
15
+ }
16
+ /**
17
+ * Loads one exact Simple UI Runtime artifact and shares the in-flight result.
18
+ * The runtime module registers its elements as a side effect and exports its
19
+ * version for an integrity check at the API boundary.
20
+ */
21
+ export declare function loadRuntime({ url, version }: RuntimeDescriptor): Promise<RuntimeInfo>;
22
+ //# sourceMappingURL=runtime.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"runtime.d.ts","sourceRoot":"","sources":["../src/runtime.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,iBAAiB;IAChC,GAAG,EAAE,MAAM,CAAA;IACX,OAAO,EAAE,MAAM,CAAA;CAChB;AAED,MAAM,WAAW,WAAW;IAC1B,OAAO,EAAE,MAAM,CAAA;CAChB;AAED,MAAM,WAAW,aAAa;IAC5B,OAAO,CAAC,EAAE,OAAO,CAAA;CAClB;AAED,qBAAa,gBAAiB,SAAQ,KAAK;IACzC,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAA;IACzB,QAAQ,CAAC,QAAQ,CAAC,EAAE,MAAM,CAAA;gBAEd,OAAO,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,EAAE,QAAQ,CAAC,EAAE,MAAM;CAMjE;AAKD;;;;GAIG;AACH,wBAAgB,WAAW,CAAC,EAAE,GAAG,EAAE,OAAO,EAAE,EAAE,iBAAiB,GAAG,OAAO,CAAC,WAAW,CAAC,CA2BrF"}
@@ -0,0 +1,46 @@
1
+ export class RuntimeLoadError extends Error {
2
+ expected;
3
+ received;
4
+ constructor(message, expected, received) {
5
+ super(message);
6
+ this.name = 'RuntimeLoadError';
7
+ this.expected = expected;
8
+ this.received = received;
9
+ }
10
+ }
11
+ const loads = new Map();
12
+ const LOAD_TIMEOUT_MS = 15_000;
13
+ /**
14
+ * Loads one exact Simple UI Runtime artifact and shares the in-flight result.
15
+ * The runtime module registers its elements as a side effect and exports its
16
+ * version for an integrity check at the API boundary.
17
+ */
18
+ export function loadRuntime({ url, version }) {
19
+ const key = `${version}:${url}`;
20
+ const existing = loads.get(key);
21
+ if (existing)
22
+ return existing;
23
+ let timeout;
24
+ const load = Promise.race([
25
+ import(/* @vite-ignore */ url).then(module => readRuntimeInfo(module, version)),
26
+ new Promise((_resolve, reject) => {
27
+ timeout = setTimeout(() => reject(new RuntimeLoadError('The Simple UI Runtime did not load in time.', version)), LOAD_TIMEOUT_MS);
28
+ }),
29
+ ])
30
+ .finally(() => {
31
+ if (timeout !== undefined)
32
+ clearTimeout(timeout);
33
+ })
34
+ .catch((error) => {
35
+ loads.delete(key);
36
+ throw error;
37
+ });
38
+ loads.set(key, load);
39
+ return load;
40
+ }
41
+ function readRuntimeInfo(module, expected) {
42
+ if (typeof module.version !== 'string' || module.version !== expected) {
43
+ throw new RuntimeLoadError(`Simple UI Runtime version mismatch. Expected ${expected}.`, expected, typeof module.version === 'string' ? module.version : undefined);
44
+ }
45
+ return { version: module.version };
46
+ }
package/package.json CHANGED
@@ -1,6 +1,62 @@
1
1
  {
2
2
  "name": "@simpleplatform/ui-kit",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
3
+ "type": "module",
4
+ "version": "0.1.0",
5
+ "description": "Supported UI contracts and framework bridges for Simple Spaces",
6
+ "license": "Apache-2.0",
7
+ "sideEffects": [
8
+ "./dist/elements/index.js",
9
+ "./dist/elements/status-badge.js",
10
+ "./theme.css"
11
+ ],
12
+ "exports": {
13
+ ".": {
14
+ "types": "./dist/index.d.ts",
15
+ "import": "./dist/index.js"
16
+ },
17
+ "./contracts": {
18
+ "types": "./dist/contracts/index.d.ts",
19
+ "import": "./dist/contracts/index.js"
20
+ },
21
+ "./elements": {
22
+ "types": "./dist/elements/index.d.ts",
23
+ "import": "./dist/elements/index.js"
24
+ },
25
+ "./react": {
26
+ "types": "./dist/react/index.d.ts",
27
+ "import": "./dist/react/index.js"
28
+ },
29
+ "./theme.css": "./theme.css",
30
+ "./package.json": "./package.json"
31
+ },
32
+ "types": "./dist/index.d.ts",
33
+ "files": [
34
+ "README.md",
35
+ "custom-elements.json",
36
+ "dist",
37
+ "theme.css"
38
+ ],
39
+ "peerDependencies": {
40
+ "@simpleplatform/sdk": "^3.0.0 || 0.0.0",
41
+ "react": ">=18.3.0 <20"
42
+ },
43
+ "dependencies": {
44
+ "@fontsource-variable/geist": "5.2.9",
45
+ "@fontsource-variable/geist-mono": "5.2.8"
46
+ },
47
+ "devDependencies": {
48
+ "@types/react": "18.3.28",
49
+ "@types/react-dom": "18.3.7",
50
+ "happy-dom": "20.8.9",
51
+ "react": "18.3.1",
52
+ "react-dom": "18.3.1",
53
+ "typescript": "5.9.3",
54
+ "@simpleplatform/sdk": "0.0.0"
55
+ },
56
+ "customElements": "custom-elements.json",
57
+ "scripts": {
58
+ "build": "node --eval \"require('node:fs').rmSync('dist', { force: true, recursive: true })\" && tsc -p tsconfig.json",
59
+ "typecheck": "tsc --noEmit -p tsconfig.json",
60
+ "test": "pnpm build && node --test test/*.test.mjs"
61
+ }
6
62
  }
package/theme.css ADDED
@@ -0,0 +1,56 @@
1
+ @import '@fontsource-variable/geist';
2
+ @import '@fontsource-variable/geist-mono';
3
+
4
+ /*
5
+ * Space typography is bundled with the Space itself so it also works in the
6
+ * cross-origin iframe. These defaults align Spaces with the Simple shell;
7
+ * customers can override them in their own stylesheet.
8
+ */
9
+ :root {
10
+ --font-sans: 'Geist Variable', ui-sans-serif, system-ui, sans-serif;
11
+ --font-mono: 'Geist Mono Variable', ui-monospace, SFMono-Regular, Menlo, monospace;
12
+
13
+ /* StatusBadge defaults follow the platform palette and remain Space-overridable. */
14
+ --simple-status-badge-font-family: var(--font-sans, ui-sans-serif, system-ui, sans-serif);
15
+ --simple-status-badge-font-size: 0.75rem;
16
+ --simple-status-badge-font-weight: 500;
17
+ --simple-status-badge-line-height: 1rem;
18
+ --simple-status-badge-min-height: 1.5rem;
19
+ --simple-status-badge-padding-inline: 0.5rem;
20
+ --simple-status-badge-radius: 9999px;
21
+
22
+ --simple-status-badge-neutral-background: hsl(var(--secondary, 210 40% 98%));
23
+ --simple-status-badge-neutral-border: hsl(var(--border, 213 27% 84%));
24
+ --simple-status-badge-neutral-foreground: hsl(var(--secondary-foreground, 215 19% 35%));
25
+
26
+ --simple-status-badge-info-background: hsl(214 95% 93%);
27
+ --simple-status-badge-info-border: hsl(214 95% 75%);
28
+ --simple-status-badge-info-foreground: hsl(221 83% 35%);
29
+
30
+ --simple-status-badge-success-background: hsl(142 76% 90%);
31
+ --simple-status-badge-success-border: hsl(142 76% 65%);
32
+ --simple-status-badge-success-foreground: hsl(142 72% 25%);
33
+
34
+ --simple-status-badge-warning-background: hsl(38 92% 90%);
35
+ --simple-status-badge-warning-border: hsl(38 92% 65%);
36
+ --simple-status-badge-warning-foreground: hsl(28 80% 25%);
37
+
38
+ --simple-status-badge-danger-background: hsl(0 84% 95%);
39
+ --simple-status-badge-danger-border: hsl(0 84% 75%);
40
+ --simple-status-badge-danger-foreground: hsl(0 72% 35%);
41
+ }
42
+
43
+ .dark {
44
+ --simple-status-badge-info-background: hsl(214 60% 25%);
45
+ --simple-status-badge-info-border: hsl(214 70% 45%);
46
+ --simple-status-badge-info-foreground: hsl(214 95% 90%);
47
+ --simple-status-badge-success-background: hsl(142 45% 22%);
48
+ --simple-status-badge-success-border: hsl(142 50% 38%);
49
+ --simple-status-badge-success-foreground: hsl(142 65% 85%);
50
+ --simple-status-badge-warning-background: hsl(38 55% 24%);
51
+ --simple-status-badge-warning-border: hsl(38 65% 42%);
52
+ --simple-status-badge-warning-foreground: hsl(38 90% 85%);
53
+ --simple-status-badge-danger-background: hsl(0 45% 24%);
54
+ --simple-status-badge-danger-border: hsl(0 55% 42%);
55
+ --simple-status-badge-danger-foreground: hsl(0 85% 88%);
56
+ }