@simpleplatform/sdk 3.1.0 → 4.0.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.
- package/README.md +11 -28
- package/dist/space/browser-transport.d.ts +3 -3
- package/dist/space/browser-transport.js +81 -6
- package/dist/space/core.d.ts +4 -5
- package/dist/space/core.js +16 -4
- package/dist/space/index.d.ts +3 -3
- package/dist/space/index.js +7 -8
- package/dist/space/record-form.d.ts +15 -1
- package/dist/space/record-form.js +74 -10
- package/dist/space/record.js +23 -17
- package/dist/space/tabs.d.ts +0 -3
- package/dist/space/tabs.js +0 -6
- package/dist/space/ui.d.ts +1 -17
- package/dist/space/ui.js +2 -38
- package/package.json +1 -1
- package/dist/space/status.d.ts +0 -2
- package/dist/space/status.js +0 -7
package/README.md
CHANGED
|
@@ -183,8 +183,8 @@ cannot be opened again as a secondary session (`already_current`).
|
|
|
183
183
|
|
|
184
184
|
### Managed record UI and header actions (pre-release)
|
|
185
185
|
|
|
186
|
-
The companion UI Kit
|
|
187
|
-
|
|
186
|
+
The companion UI Kit provides pre-release managed React `RecordForm` and
|
|
187
|
+
`RecordActivity` components for record handles:
|
|
188
188
|
|
|
189
189
|
```tsx
|
|
190
190
|
<RecordForm record={record} />
|
|
@@ -195,6 +195,12 @@ registries, document/reference/secret internals, or Record Behavior timing as
|
|
|
195
195
|
public APIs. When a Space needs fully custom presentation, keep using the
|
|
196
196
|
record handle's `snapshot()`, `update()`, and `submit()` commands.
|
|
197
197
|
|
|
198
|
+
For collections, the UI Kit also provides database-backed `ListView`,
|
|
199
|
+
`DataGrid`, and `Board`. Their private bridge requires the planned SDK
|
|
200
|
+
`^3.2.0` release, which is not yet published. Inbox remains platform-only;
|
|
201
|
+
standalone filter-builder components are private. See the
|
|
202
|
+
[UI Kit collection contracts](../space-ui/README.md#managed-database-backed-views).
|
|
203
|
+
|
|
198
204
|
Record Spaces can replace the platform main actions in the header while
|
|
199
205
|
mounted:
|
|
200
206
|
|
|
@@ -221,24 +227,6 @@ state without choosing UI; call `simple.ui.toast.show()` when the Space should
|
|
|
221
227
|
also show a platform toast. `RecordForm` continues to display detailed field
|
|
222
228
|
and form messages inline.
|
|
223
229
|
|
|
224
|
-
A Record Space can also show one status beside the record title:
|
|
225
|
-
|
|
226
|
-
```ts
|
|
227
|
-
simple.ui.header.status.set({
|
|
228
|
-
description: 'A reviewer needs to check this record.',
|
|
229
|
-
label: 'Needs review',
|
|
230
|
-
tone: 'warning',
|
|
231
|
-
})
|
|
232
|
-
|
|
233
|
-
simple.ui.header.status.set(null) // Clear the status
|
|
234
|
-
```
|
|
235
|
-
|
|
236
|
-
The label is non-blank and limited to 80 characters. Tones are `neutral`,
|
|
237
|
-
`info`, `success`, `warning`, and `danger`; the optional description is for
|
|
238
|
-
screen readers. Hosts that do not negotiate `headerStatus` reject this call
|
|
239
|
-
with an `unavailable` error. Header status is negotiated separately, so an
|
|
240
|
-
older host can continue to support header actions without supporting status.
|
|
241
|
-
|
|
242
230
|
### Show a platform toast
|
|
243
231
|
|
|
244
232
|
Any Space can show feedback with Simple's existing toast presenter and theme:
|
|
@@ -271,7 +259,7 @@ const { selectedTabId } = await simple.ui.tabs.set({
|
|
|
271
259
|
},
|
|
272
260
|
tabs: [
|
|
273
261
|
{ icon: 'layout-dashboard', id: 'overview', title: 'Overview' },
|
|
274
|
-
{ badge: 3,
|
|
262
|
+
{ badge: 3, icon: 'message-square', id: 'messages', title: 'Messages' },
|
|
275
263
|
{ badge: 'New', icon: 'file-text', id: 'documents', title: 'Documents' },
|
|
276
264
|
],
|
|
277
265
|
})
|
|
@@ -286,13 +274,8 @@ empty list clears the current declaration and resolves with
|
|
|
286
274
|
Each tab requires an `id` (1–64 characters matching `^[a-z0-9][a-z0-9_-]{0,63}$`)
|
|
287
275
|
and a non-blank `title` (up to 80 characters), with optional `default: true`,
|
|
288
276
|
optional kebab-case Lucide `icon`, and optional `badge` (non-blank text up to 20
|
|
289
|
-
characters or a finite non-negative integer).
|
|
290
|
-
|
|
291
|
-
keeps its neutral appearance. At most one tab may set `default: true`; if none
|
|
292
|
-
is specified, the first tab defaults to active.
|
|
293
|
-
|
|
294
|
-
Older hosts that do not recognize `badgeTone` ignore it and display the count
|
|
295
|
-
with the neutral appearance.
|
|
277
|
+
characters or a finite non-negative integer). At most one tab may set `default: true`;
|
|
278
|
+
if none is specified, the first tab defaults to active.
|
|
296
279
|
|
|
297
280
|
The host negotiates `protocols.tabs: [1]` and owns selection and URL state.
|
|
298
281
|
Registration uses `ui.tabs.set`, which assigns a `registrationRequestId` and
|
|
@@ -3,7 +3,7 @@ import type { SpaceNavigationTransport } from './navigation.js';
|
|
|
3
3
|
import type { SpaceTransport } from './protocol.js';
|
|
4
4
|
import type { RecordFormCapabilities } from './record-form.js';
|
|
5
5
|
import type { SpaceThemeSnapshot } from './theme.js';
|
|
6
|
-
import type {
|
|
6
|
+
import type { SpaceHeaderTransport, SpaceTabsTransport, SpaceToastTransport } from './ui.js';
|
|
7
7
|
export interface MessagePortLike {
|
|
8
8
|
close?: () => void;
|
|
9
9
|
onmessage: null | ((event: {
|
|
@@ -12,8 +12,8 @@ export interface MessagePortLike {
|
|
|
12
12
|
postMessage: (message: unknown, transfer?: ArrayBuffer[]) => void;
|
|
13
13
|
start?: () => void;
|
|
14
14
|
}
|
|
15
|
-
export interface BrowserSpaceTransport extends SpaceDataTransport,
|
|
15
|
+
export interface BrowserSpaceTransport extends SpaceDataTransport, SpaceHeaderTransport, SpaceNavigationTransport, SpaceTabsTransport, SpaceToastTransport, SpaceTransport {
|
|
16
16
|
capabilities: RecordFormCapabilities;
|
|
17
17
|
subscribeFormModel: (listener: (form: unknown) => void) => () => void;
|
|
18
18
|
}
|
|
19
|
-
export declare function createMessagePortTransport(port: MessagePortLike, targetOrigin: string, onThemeChanged?: (theme: SpaceThemeSnapshot) => void): BrowserSpaceTransport;
|
|
19
|
+
export declare function createMessagePortTransport(port: MessagePortLike, targetOrigin: string, onThemeChanged?: (theme: SpaceThemeSnapshot) => void, formLifecycleEnabled?: boolean): BrowserSpaceTransport;
|
|
@@ -1,9 +1,11 @@
|
|
|
1
|
-
import { SpaceDataError, SpaceProtocolError, } from './protocol.js';
|
|
1
|
+
import { isObjectRecord, SpaceDataError, SpaceProtocolError, } from './protocol.js';
|
|
2
2
|
import { createFormModelSubscriptionManager, createRecordFormCapabilities, } from './record-form.js';
|
|
3
3
|
import { parseThemeSnapshot } from './theme.js';
|
|
4
|
-
export function createMessagePortTransport(port, targetOrigin, onThemeChanged) {
|
|
4
|
+
export function createMessagePortTransport(port, targetOrigin, onThemeChanged, formLifecycleEnabled = false) {
|
|
5
5
|
const headerCallbacks = new Map();
|
|
6
6
|
const formModelManager = createFormModelSubscriptionManager();
|
|
7
|
+
const formLifecycles = new Map();
|
|
8
|
+
const activeFormRequests = new Set();
|
|
7
9
|
const pendingData = new Map();
|
|
8
10
|
const pending = new Map();
|
|
9
11
|
const pendingCapabilities = new Map();
|
|
@@ -12,6 +14,8 @@ export function createMessagePortTransport(port, targetOrigin, onThemeChanged) {
|
|
|
12
14
|
if (typeof port.addEventListener === 'function') {
|
|
13
15
|
port.addEventListener('close', () => {
|
|
14
16
|
isPortClosed = true;
|
|
17
|
+
formLifecycles.clear();
|
|
18
|
+
activeFormRequests.clear();
|
|
15
19
|
});
|
|
16
20
|
}
|
|
17
21
|
port.onmessage = (event) => {
|
|
@@ -23,6 +27,49 @@ export function createMessagePortTransport(port, targetOrigin, onThemeChanged) {
|
|
|
23
27
|
formModelManager.handleUpdate(envelope.form);
|
|
24
28
|
return;
|
|
25
29
|
}
|
|
30
|
+
if (envelope.type === 'SPACE_RECORD_FORM_REQUEST' && formLifecycleEnabled) {
|
|
31
|
+
const request = message;
|
|
32
|
+
if (typeof request.id !== 'string' || !request.id || typeof request.sessionId !== 'string' || !request.sessionId)
|
|
33
|
+
return;
|
|
34
|
+
const { id, sessionId } = request;
|
|
35
|
+
Promise.resolve().then(async () => {
|
|
36
|
+
const handlers = formLifecycles.get(sessionId);
|
|
37
|
+
if (!handlers?.size)
|
|
38
|
+
throw new Error('The managed record session is unavailable.');
|
|
39
|
+
const check = () => {
|
|
40
|
+
const states = [...handlers].map(handler => handler.check());
|
|
41
|
+
return { busy: activeFormRequests.has(sessionId) || states.some(state => state.busy), dirty: states.some(state => state.dirty) };
|
|
42
|
+
};
|
|
43
|
+
if (request.operation === 'check')
|
|
44
|
+
return check();
|
|
45
|
+
if (request.operation !== 'prepare' && request.operation !== 'discard')
|
|
46
|
+
throw new Error('The managed record form operation is unsupported.');
|
|
47
|
+
if (activeFormRequests.has(sessionId) || [...handlers].some(handler => handler.check().busy))
|
|
48
|
+
throw new Error('The record is still being prepared or saved.');
|
|
49
|
+
if (request.operation === 'discard' && !isObjectRecord(request.values))
|
|
50
|
+
throw new Error('Discard requires the original record values.');
|
|
51
|
+
activeFormRequests.add(sessionId);
|
|
52
|
+
try {
|
|
53
|
+
for (const handler of handlers) {
|
|
54
|
+
if (request.operation === 'prepare')
|
|
55
|
+
await handler.prepare();
|
|
56
|
+
else
|
|
57
|
+
await handler.discard(request.values);
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
finally {
|
|
61
|
+
activeFormRequests.delete(sessionId);
|
|
62
|
+
}
|
|
63
|
+
return check();
|
|
64
|
+
}).then((state) => {
|
|
65
|
+
if (!isPortClosed)
|
|
66
|
+
port.postMessage({ ...state, id, ok: true, sessionId, type: 'SPACE_RECORD_FORM_RESULT' });
|
|
67
|
+
}).catch((error) => {
|
|
68
|
+
if (!isPortClosed)
|
|
69
|
+
port.postMessage({ error: error instanceof Error ? error.message : 'The managed record form request failed.', id, ok: false, sessionId, type: 'SPACE_RECORD_FORM_RESULT' });
|
|
70
|
+
});
|
|
71
|
+
return;
|
|
72
|
+
}
|
|
26
73
|
if (envelope.type === 'THEME_CHANGED') {
|
|
27
74
|
if (onThemeChanged) {
|
|
28
75
|
const snapshot = parseThemeSnapshot(envelope.theme);
|
|
@@ -136,7 +183,38 @@ export function createMessagePortTransport(port, targetOrigin, onThemeChanged) {
|
|
|
136
183
|
});
|
|
137
184
|
};
|
|
138
185
|
return {
|
|
139
|
-
capabilities:
|
|
186
|
+
capabilities: {
|
|
187
|
+
...createRecordFormCapabilities(requestCapability, msg => port.postMessage(msg), targetOrigin),
|
|
188
|
+
...(formLifecycleEnabled
|
|
189
|
+
? {
|
|
190
|
+
notifyFormDraft: (sessionId) => {
|
|
191
|
+
if (isPortClosed)
|
|
192
|
+
return;
|
|
193
|
+
let dirty = true;
|
|
194
|
+
try {
|
|
195
|
+
dirty = [...formLifecycles.get(sessionId) ?? []].some(handler => handler.check().dirty);
|
|
196
|
+
}
|
|
197
|
+
catch {
|
|
198
|
+
// A broken draft getter must not let navigation discard edits.
|
|
199
|
+
}
|
|
200
|
+
port.postMessage({ dirty, sessionId, type: 'SPACE_RECORD_FORM_DRAFT' });
|
|
201
|
+
},
|
|
202
|
+
registerFormLifecycle: (sessionId, lifecycle) => {
|
|
203
|
+
let handlers = formLifecycles.get(sessionId);
|
|
204
|
+
if (!handlers) {
|
|
205
|
+
handlers = new Set();
|
|
206
|
+
formLifecycles.set(sessionId, handlers);
|
|
207
|
+
}
|
|
208
|
+
handlers.add(lifecycle);
|
|
209
|
+
return () => {
|
|
210
|
+
handlers.delete(lifecycle);
|
|
211
|
+
if (!handlers.size)
|
|
212
|
+
formLifecycles.delete(sessionId);
|
|
213
|
+
};
|
|
214
|
+
},
|
|
215
|
+
}
|
|
216
|
+
: {}),
|
|
217
|
+
},
|
|
140
218
|
execute: (document, variables) => {
|
|
141
219
|
return new Promise((resolve, reject) => {
|
|
142
220
|
const id = createDataRequestId();
|
|
@@ -186,9 +264,6 @@ export function createMessagePortTransport(port, targetOrigin, onThemeChanged) {
|
|
|
186
264
|
type: 'SPACE_HEADER_ACTIONS_SET',
|
|
187
265
|
});
|
|
188
266
|
},
|
|
189
|
-
setStatus: (status) => {
|
|
190
|
-
port.postMessage({ status, type: 'SPACE_HEADER_STATUS_SET' });
|
|
191
|
-
},
|
|
192
267
|
showToast: (options) => {
|
|
193
268
|
port.postMessage({ options, type: 'SPACE_TOAST_SHOW' });
|
|
194
269
|
},
|
package/dist/space/core.d.ts
CHANGED
|
@@ -6,7 +6,7 @@ import type { SpaceTransport } from './protocol.js';
|
|
|
6
6
|
import type { RecordFormCapabilities, RecordFormModelTransport, UiRuntimeDescriptor } from './record-form.js';
|
|
7
7
|
import type { SimpleRecordsClient } from './record.js';
|
|
8
8
|
import type { SimpleTasksClient } from './tasks.js';
|
|
9
|
-
import type { SimpleHeaderClient, SimpleTabsClient, SimpleToastClient,
|
|
9
|
+
import type { SimpleHeaderClient, SimpleTabsClient, SimpleToastClient, SpaceHeaderTransport, SpaceTabsTransport, SpaceToastTransport } from './ui.js';
|
|
10
10
|
export type { ActionFailedDetails, ActionRunOptions, SimpleActionsClient, } from './actions.js';
|
|
11
11
|
export type { DocumentStageInput, DocumentStageResult, SimpleDocumentsClient, StagedDocumentHandle, } from './documents.js';
|
|
12
12
|
export type { NavigationOpenOptions, NavigationTarget, SimpleNavigationClient, SpaceNavigationTransport, } from './navigation.js';
|
|
@@ -17,8 +17,8 @@ export type { ManagedRecordFormField, ManagedRecordFormModel, RecordFormCapabili
|
|
|
17
17
|
export { RECORDS_PROTOCOL_VERSION } from './record.js';
|
|
18
18
|
export type { CurrentRecordRequest, CurrentRecordResult, OpenRecordOptions, RecordErrorSnapshot, RecordFieldSnapshot, RecordFormError, RecordHandle, RecordOpenRequest, RecordOpenResult, RecordReference, RecordSnapshot, RecordSubmitResult, RecordUpdateResult, SimpleRecordsClient, } from './record.js';
|
|
19
19
|
export type { JsonObject, JsonValue, SimpleTasksClient, TaskCreateInput, TaskCreateResult, TaskReplyInput, TaskReplyResult, TaskStatus, } from './tasks.js';
|
|
20
|
-
export { DEFAULT_TABS_TIMEOUT_MS, HEADER_ACTIONS_PROTOCOL_VERSION,
|
|
21
|
-
export type { HeaderAction, HeaderActionType, SetTabsOptions, SimpleHeaderActionsClient, SimpleHeaderClient,
|
|
20
|
+
export { DEFAULT_TABS_TIMEOUT_MS, HEADER_ACTIONS_PROTOCOL_VERSION, LUCIDE_ICON_NAME, TAB_ID, TABS_PROTOCOL_VERSION, TOAST_PROTOCOL_VERSION, validateTabs } from './ui.js';
|
|
21
|
+
export type { HeaderAction, HeaderActionType, SetTabsOptions, SimpleHeaderActionsClient, SimpleHeaderClient, SimpleTabsClient, SimpleToastClient, SpaceTab, SpaceTabsSelectionEvent, SpaceTabsTransport, SpaceToastOptions, SpaceToastVariant, TabsSelectPayload, TabsSelectRequest, TabsSelectResult, TabsSetPayload, TabsSetRequest, TabsSetResult, WireTab, } from './ui.js';
|
|
22
22
|
export type SpaceContext = {
|
|
23
23
|
applicationId: string;
|
|
24
24
|
kind: 'record';
|
|
@@ -69,7 +69,6 @@ export interface SimpleClientOptions {
|
|
|
69
69
|
formModelTransport?: RecordFormModelTransport;
|
|
70
70
|
hostOrigin?: string;
|
|
71
71
|
headerTransport?: SpaceHeaderTransport;
|
|
72
|
-
headerStatusTransport?: SpaceHeaderStatusTransport;
|
|
73
72
|
navigationTransport?: SpaceNavigationTransport;
|
|
74
73
|
nextRequestId?: () => string;
|
|
75
74
|
/** Present only when the host negotiated the records protocol. */
|
|
@@ -81,5 +80,5 @@ export interface SimpleClientOptions {
|
|
|
81
80
|
transport?: SpaceTransport;
|
|
82
81
|
}
|
|
83
82
|
/** Composes Space capabilities around the host transports supplied by `connect`. */
|
|
84
|
-
export declare function createSimpleClient({ actionTransport, capabilities, context, dataTransport, documentTransport, formModelTransport,
|
|
83
|
+
export declare function createSimpleClient({ actionTransport, capabilities, context, dataTransport, documentTransport, formModelTransport, headerTransport, hostOrigin, navigationTransport, nextRequestId, recordsTransport, runtime, tabsTransport, taskTransport, toastTransport, transport, }: SimpleClientOptions): SimpleClient;
|
|
85
84
|
export declare function isSpaceContext(value: unknown): value is SpaceContext;
|
package/dist/space/core.js
CHANGED
|
@@ -8,9 +8,10 @@ import { createHeaderClient, createTabsClient, createToastClient, validateSpaceT
|
|
|
8
8
|
export { PROTOCOL_VERSION, SpaceDataError, SpaceProtocolError } from './protocol.js';
|
|
9
9
|
export { MANAGED_RECORD_FORM_PROTOCOL_VERSION } from './record-form.js';
|
|
10
10
|
export { RECORDS_PROTOCOL_VERSION } from './record.js';
|
|
11
|
-
export { DEFAULT_TABS_TIMEOUT_MS, HEADER_ACTIONS_PROTOCOL_VERSION,
|
|
11
|
+
export { DEFAULT_TABS_TIMEOUT_MS, HEADER_ACTIONS_PROTOCOL_VERSION, LUCIDE_ICON_NAME, TAB_ID, TABS_PROTOCOL_VERSION, TOAST_PROTOCOL_VERSION, validateTabs } from './ui.js';
|
|
12
|
+
const MANAGED_UI_SYMBOL = Symbol.for('@simpleplatform/sdk/space/managed-ui/v1');
|
|
12
13
|
/** Composes Space capabilities around the host transports supplied by `connect`. */
|
|
13
|
-
export function createSimpleClient({ actionTransport, capabilities, context = { kind: 'standalone' }, dataTransport, documentTransport, formModelTransport,
|
|
14
|
+
export function createSimpleClient({ actionTransport, capabilities, context = { kind: 'standalone' }, dataTransport, documentTransport, formModelTransport, headerTransport, hostOrigin, navigationTransport, nextRequestId = createRequestId, recordsTransport, runtime, tabsTransport, taskTransport, toastTransport, transport, }) {
|
|
14
15
|
const immutableContext = deepFreeze(structuredClone(context));
|
|
15
16
|
const recordFormCapabilities = capabilities && toastTransport
|
|
16
17
|
? {
|
|
@@ -51,7 +52,7 @@ export function createSimpleClient({ actionTransport, capabilities, context = {
|
|
|
51
52
|
recordsTransport,
|
|
52
53
|
runtime,
|
|
53
54
|
});
|
|
54
|
-
|
|
55
|
+
const client = {
|
|
55
56
|
actions: createActionsClient(actionTransport, nextRequestId),
|
|
56
57
|
context: immutableContext,
|
|
57
58
|
data: {
|
|
@@ -63,11 +64,22 @@ export function createSimpleClient({ actionTransport, capabilities, context = {
|
|
|
63
64
|
records,
|
|
64
65
|
tasks: createTasksClient(taskTransport, nextRequestId),
|
|
65
66
|
ui: {
|
|
66
|
-
header: createHeaderClient(immutableContext.kind === 'record', headerTransport
|
|
67
|
+
header: createHeaderClient(immutableContext.kind === 'record', headerTransport),
|
|
67
68
|
tabs: createTabsClient(immutableContext.kind === 'record', tabsTransport, nextRequestId),
|
|
68
69
|
toast: createToastClient(toastTransport),
|
|
69
70
|
},
|
|
70
71
|
};
|
|
72
|
+
const uiBridge = Object.freeze({
|
|
73
|
+
graphql: (document, variables) => executeData(dataTransport, document, variables),
|
|
74
|
+
runtime: runtime ? Object.freeze({ url: runtime.url, version: runtime.version }) : undefined,
|
|
75
|
+
});
|
|
76
|
+
Object.defineProperty(client, MANAGED_UI_SYMBOL, {
|
|
77
|
+
configurable: false,
|
|
78
|
+
enumerable: false,
|
|
79
|
+
value: uiBridge,
|
|
80
|
+
writable: false,
|
|
81
|
+
});
|
|
82
|
+
return client;
|
|
71
83
|
}
|
|
72
84
|
/** An action's context names the user by an optional ID; a supplied ID is non-blank. */
|
|
73
85
|
function isContextUser(value) {
|
package/dist/space/index.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { SimpleClient } from './core.js';
|
|
2
|
-
import { HEADER_ACTIONS_PROTOCOL_VERSION,
|
|
3
|
-
export { HEADER_ACTIONS_PROTOCOL_VERSION,
|
|
4
|
-
export type { ActionFailedDetails, ActionRunOptions, DocumentStageInput, DocumentStageResult, GraphQLVariables, HeaderAction, HeaderActionType, JsonObject, JsonValue, NavigationOpenOptions, NavigationTarget, OpenRecordOptions, RecordErrorSnapshot, RecordFieldSnapshot, RecordFormError, RecordHandle, RecordOpenRequest, RecordOpenResult, RecordReference, RecordSnapshot, RecordSubmitResult, RecordUpdateResult, SetTabsOptions, SimpleActionsClient, SimpleClient, SimpleDataClient, SimpleDocumentsClient, SimpleHeaderActionsClient, SimpleHeaderClient,
|
|
2
|
+
import { HEADER_ACTIONS_PROTOCOL_VERSION, PROTOCOL_VERSION, RECORDS_PROTOCOL_VERSION, SpaceDataError, SpaceProtocolError, TABS_PROTOCOL_VERSION, TOAST_PROTOCOL_VERSION } from './core.js';
|
|
3
|
+
export { HEADER_ACTIONS_PROTOCOL_VERSION, PROTOCOL_VERSION, RECORDS_PROTOCOL_VERSION, SpaceDataError, SpaceProtocolError, TABS_PROTOCOL_VERSION, TOAST_PROTOCOL_VERSION };
|
|
4
|
+
export type { ActionFailedDetails, ActionRunOptions, DocumentStageInput, DocumentStageResult, GraphQLVariables, HeaderAction, HeaderActionType, JsonObject, JsonValue, NavigationOpenOptions, NavigationTarget, OpenRecordOptions, RecordErrorSnapshot, RecordFieldSnapshot, RecordFormError, RecordHandle, RecordOpenRequest, RecordOpenResult, RecordReference, RecordSnapshot, RecordSubmitResult, RecordUpdateResult, SetTabsOptions, SimpleActionsClient, SimpleClient, SimpleDataClient, SimpleDocumentsClient, SimpleHeaderActionsClient, SimpleHeaderClient, SimpleNavigationClient, SimpleRecordsClient, SimpleTabsClient, SimpleTasksClient, SimpleToastClient, SpaceContext, SpaceDataErrorPayload, SpaceNavigationTransport, SpaceProtocolErrorPayload, SpaceTab, SpaceTabsSelectionEvent, SpaceTabsTransport, SpaceToastOptions, SpaceToastVariant, StagedDocumentHandle, TaskCreateInput, TaskCreateResult, TaskReplyInput, TaskReplyResult, TaskStatus, } from './core.js';
|
|
5
5
|
export interface ConnectOptions {
|
|
6
6
|
targetOrigin: string;
|
|
7
7
|
}
|
package/dist/space/index.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { createMessagePortTransport } from './browser-transport.js';
|
|
2
|
-
import { createSimpleClient, HEADER_ACTIONS_PROTOCOL_VERSION,
|
|
2
|
+
import { createSimpleClient, HEADER_ACTIONS_PROTOCOL_VERSION, isSpaceContext, MANAGED_RECORD_FORM_PROTOCOL_VERSION, PROTOCOL_VERSION, RECORDS_PROTOCOL_VERSION, SpaceDataError, SpaceProtocolError, TABS_PROTOCOL_VERSION, TOAST_PROTOCOL_VERSION, } from './core.js';
|
|
3
3
|
import { isObjectRecord } from './protocol.js';
|
|
4
4
|
import { applyThemeSnapshot, parseThemeSnapshot, THEME_PROTOCOL_VERSION } from './theme.js';
|
|
5
|
-
export { HEADER_ACTIONS_PROTOCOL_VERSION,
|
|
5
|
+
export { HEADER_ACTIONS_PROTOCOL_VERSION, PROTOCOL_VERSION, RECORDS_PROTOCOL_VERSION, SpaceDataError, SpaceProtocolError, TABS_PROTOCOL_VERSION, TOAST_PROTOCOL_VERSION };
|
|
6
6
|
const connections = new WeakMap();
|
|
7
7
|
/** Connects this Space to its host using the explicitly supplied host origin. */
|
|
8
8
|
export function connect({ targetOrigin }) {
|
|
@@ -65,8 +65,8 @@ export function connect({ targetOrigin }) {
|
|
|
65
65
|
applyThemeSnapshot(window.document, appliedThemeTokens, snapshot, fontState);
|
|
66
66
|
}
|
|
67
67
|
: undefined;
|
|
68
|
-
const transport = createMessagePortTransport(port, targetOrigin, onThemeChanged);
|
|
69
68
|
const protocols = event.data.protocols;
|
|
69
|
+
const transport = createMessagePortTransport(port, targetOrigin, onThemeChanged, protocols?.form === MANAGED_RECORD_FORM_PROTOCOL_VERSION);
|
|
70
70
|
const hasRecord = protocols?.record === PROTOCOL_VERSION;
|
|
71
71
|
const hasRecords = protocols?.records === RECORDS_PROTOCOL_VERSION;
|
|
72
72
|
resolve(createSimpleClient({
|
|
@@ -75,8 +75,7 @@ export function connect({ targetOrigin }) {
|
|
|
75
75
|
context: event.data.context,
|
|
76
76
|
dataTransport: transport,
|
|
77
77
|
documentTransport: protocols?.document === PROTOCOL_VERSION ? transport : undefined,
|
|
78
|
-
formModelTransport: protocols?.form === MANAGED_RECORD_FORM_PROTOCOL_VERSION ? transport : undefined,
|
|
79
|
-
headerStatusTransport: hasRecord && protocols?.headerStatus === HEADER_STATUS_PROTOCOL_VERSION ? transport : undefined,
|
|
78
|
+
formModelTransport: protocols?.form === MANAGED_RECORD_FORM_PROTOCOL_VERSION || protocols?.form === 2 ? transport : undefined,
|
|
80
79
|
headerTransport: hasRecord && protocols?.header === HEADER_ACTIONS_PROTOCOL_VERSION ? transport : undefined,
|
|
81
80
|
hostOrigin: targetOrigin,
|
|
82
81
|
navigationTransport: transport,
|
|
@@ -93,9 +92,8 @@ export function connect({ targetOrigin }) {
|
|
|
93
92
|
protocols: {
|
|
94
93
|
action: [PROTOCOL_VERSION],
|
|
95
94
|
document: [PROTOCOL_VERSION],
|
|
96
|
-
form: [MANAGED_RECORD_FORM_PROTOCOL_VERSION],
|
|
95
|
+
form: [MANAGED_RECORD_FORM_PROTOCOL_VERSION, 2],
|
|
97
96
|
header: [HEADER_ACTIONS_PROTOCOL_VERSION],
|
|
98
|
-
headerStatus: [HEADER_STATUS_PROTOCOL_VERSION],
|
|
99
97
|
record: [PROTOCOL_VERSION],
|
|
100
98
|
records: [RECORDS_PROTOCOL_VERSION],
|
|
101
99
|
tabs: [TABS_PROTOCOL_VERSION],
|
|
@@ -134,7 +132,8 @@ function isUiRuntimeDescriptor(value) {
|
|
|
134
132
|
if (typeof url !== 'string' || !url || typeof version !== 'string' || !version)
|
|
135
133
|
return false;
|
|
136
134
|
try {
|
|
137
|
-
const
|
|
135
|
+
const runtimeUrl = new URL(url);
|
|
136
|
+
const protocol = runtimeUrl.protocol;
|
|
138
137
|
return protocol === 'http:' || protocol === 'https:';
|
|
139
138
|
}
|
|
140
139
|
catch {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { RecordHandle, RecordSnapshot, RecordUiBridge } from './record.js';
|
|
2
2
|
import type { SpaceToastOptions } from './ui.js';
|
|
3
|
-
export declare const MANAGED_RECORD_FORM_PROTOCOL_VERSION:
|
|
3
|
+
export declare const MANAGED_RECORD_FORM_PROTOCOL_VERSION: 3;
|
|
4
4
|
export interface UiRuntimeDescriptor {
|
|
5
5
|
readonly url: string;
|
|
6
6
|
readonly version: string;
|
|
@@ -26,7 +26,17 @@ export interface ManagedRecordFormModel {
|
|
|
26
26
|
}
|
|
27
27
|
export type ManagedRecordFormSnapshotListener = (snapshot: RecordSnapshot) => void;
|
|
28
28
|
export type RecordFormSubmitPreparation = () => Promise<Readonly<Record<string, unknown>> | undefined>;
|
|
29
|
+
export interface RecordFormHostLifecycle {
|
|
30
|
+
check: () => {
|
|
31
|
+
busy: boolean;
|
|
32
|
+
dirty: boolean;
|
|
33
|
+
};
|
|
34
|
+
discard: (values: Readonly<Record<string, unknown>>) => Promise<void>;
|
|
35
|
+
prepare: () => Promise<void>;
|
|
36
|
+
}
|
|
29
37
|
export interface RecordFormCapabilities {
|
|
38
|
+
notifyFormDraft?: (sessionId: string) => void;
|
|
39
|
+
registerFormLifecycle?: (sessionId: string, lifecycle: RecordFormHostLifecycle) => () => void;
|
|
30
40
|
createDocumentHandle: (request: {
|
|
31
41
|
bytes: ArrayBuffer;
|
|
32
42
|
lifecycle?: 'pending' | 'record' | 'staged';
|
|
@@ -62,6 +72,9 @@ export interface RecordFormBridge extends RecordUiBridge {
|
|
|
62
72
|
blurField: (fieldName: string) => Promise<void>;
|
|
63
73
|
focusField: (fieldName: string) => Promise<void>;
|
|
64
74
|
form: unknown;
|
|
75
|
+
onDraftChange: () => void;
|
|
76
|
+
registerDiscard: (discard: (values: Readonly<Record<string, unknown>>) => Promise<void>) => () => void;
|
|
77
|
+
registerDraftState: (getDirty: () => boolean) => () => void;
|
|
65
78
|
registerSubmitPreparation: (preparation: RecordFormSubmitPreparation) => () => void;
|
|
66
79
|
subscribeFormModel: (listener: (form: unknown) => void) => () => void;
|
|
67
80
|
subscribe: (listener: ManagedRecordFormSnapshotListener) => () => void;
|
|
@@ -70,6 +83,7 @@ export interface RecordFormModelTransport {
|
|
|
70
83
|
subscribeFormModel: (listener: (form: unknown) => void) => () => void;
|
|
71
84
|
}
|
|
72
85
|
export interface RecordFormLifecycle {
|
|
86
|
+
beginSubmit: () => () => void;
|
|
73
87
|
notifySnapshot: (snapshot: RecordSnapshot) => void;
|
|
74
88
|
prepareSubmit: () => Promise<Record<string, unknown>>;
|
|
75
89
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { deepFreeze, invalidResponse, isObjectRecord } from './protocol.js';
|
|
2
|
-
export const MANAGED_RECORD_FORM_PROTOCOL_VERSION =
|
|
2
|
+
export const MANAGED_RECORD_FORM_PROTOCOL_VERSION = 3;
|
|
3
3
|
const MANAGED_RECORD_UI_SYMBOL = Symbol.for('@simpleplatform/sdk/space/managed-record-ui/v1');
|
|
4
4
|
export function isManagedRecordFormModel(value) {
|
|
5
5
|
if (!isObjectRecord(value) || !Array.isArray(value.fields))
|
|
@@ -49,7 +49,56 @@ export function initRecordFormLifecycle(record, options) {
|
|
|
49
49
|
const metadataListeners = new Set();
|
|
50
50
|
const snapshotListeners = new Set();
|
|
51
51
|
const submitPreparations = new Set();
|
|
52
|
+
const draftStates = new Set();
|
|
53
|
+
const discardHandlers = new Set();
|
|
54
|
+
let submissions = 0;
|
|
55
|
+
let formOperationPending = false;
|
|
52
56
|
let currentMetadata = currentForm ? recordUiMetadata(currentForm) : undefined;
|
|
57
|
+
const onDraftChange = () => capabilities?.notifyFormDraft?.(record.id);
|
|
58
|
+
const check = () => ({ busy: submissions > 0 || formOperationPending, dirty: [...draftStates].some(getDirty => getDirty()) });
|
|
59
|
+
const prepareSubmit = async () => {
|
|
60
|
+
const values = {};
|
|
61
|
+
for (const preparation of submitPreparations) {
|
|
62
|
+
const preparedValues = await preparation();
|
|
63
|
+
if (preparedValues)
|
|
64
|
+
Object.assign(values, preparedValues);
|
|
65
|
+
}
|
|
66
|
+
return values;
|
|
67
|
+
};
|
|
68
|
+
capabilities?.registerFormLifecycle?.(record.id, {
|
|
69
|
+
check,
|
|
70
|
+
discard: async (values) => {
|
|
71
|
+
if (check().busy)
|
|
72
|
+
throw new Error('The record is still being prepared or saved.');
|
|
73
|
+
formOperationPending = true;
|
|
74
|
+
try {
|
|
75
|
+
for (const discard of discardHandlers)
|
|
76
|
+
await discard(values);
|
|
77
|
+
}
|
|
78
|
+
finally {
|
|
79
|
+
formOperationPending = false;
|
|
80
|
+
onDraftChange();
|
|
81
|
+
}
|
|
82
|
+
},
|
|
83
|
+
prepare: async () => {
|
|
84
|
+
if (check().busy)
|
|
85
|
+
throw new Error('The record is still being prepared or saved.');
|
|
86
|
+
formOperationPending = true;
|
|
87
|
+
onDraftChange();
|
|
88
|
+
try {
|
|
89
|
+
const values = await prepareSubmit();
|
|
90
|
+
if (Object.keys(values).length > 0) {
|
|
91
|
+
const result = await record.update(values);
|
|
92
|
+
if (!result.ok)
|
|
93
|
+
throw new Error('Record validation rejected the prepared fields.');
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
finally {
|
|
97
|
+
formOperationPending = false;
|
|
98
|
+
onDraftChange();
|
|
99
|
+
}
|
|
100
|
+
},
|
|
101
|
+
});
|
|
53
102
|
const publishFormModel = (updatedForm) => {
|
|
54
103
|
if (!isManagedRecordFormModel(updatedForm))
|
|
55
104
|
return;
|
|
@@ -112,6 +161,19 @@ export function initRecordFormLifecycle(record, options) {
|
|
|
112
161
|
get metadata() {
|
|
113
162
|
return currentMetadata;
|
|
114
163
|
},
|
|
164
|
+
onDraftChange,
|
|
165
|
+
registerDiscard: (discard) => {
|
|
166
|
+
discardHandlers.add(discard);
|
|
167
|
+
return () => discardHandlers.delete(discard);
|
|
168
|
+
},
|
|
169
|
+
registerDraftState: (getDirty) => {
|
|
170
|
+
draftStates.add(getDirty);
|
|
171
|
+
onDraftChange();
|
|
172
|
+
return () => {
|
|
173
|
+
draftStates.delete(getDirty);
|
|
174
|
+
onDraftChange();
|
|
175
|
+
};
|
|
176
|
+
},
|
|
115
177
|
registerSubmitPreparation: (preparation) => {
|
|
116
178
|
submitPreparations.add(preparation);
|
|
117
179
|
return () => submitPreparations.delete(preparation);
|
|
@@ -140,19 +202,21 @@ export function initRecordFormLifecycle(record, options) {
|
|
|
140
202
|
};
|
|
141
203
|
Object.defineProperty(record, MANAGED_RECORD_UI_SYMBOL, { value: bridge });
|
|
142
204
|
return {
|
|
205
|
+
beginSubmit: () => {
|
|
206
|
+
if (formOperationPending)
|
|
207
|
+
throw new Error('The record is still being prepared or discarded.');
|
|
208
|
+
submissions++;
|
|
209
|
+
onDraftChange();
|
|
210
|
+
return () => {
|
|
211
|
+
submissions--;
|
|
212
|
+
onDraftChange();
|
|
213
|
+
};
|
|
214
|
+
},
|
|
143
215
|
notifySnapshot: (snapshot) => {
|
|
144
216
|
for (const listener of snapshotListeners)
|
|
145
217
|
listener(snapshot);
|
|
146
218
|
},
|
|
147
|
-
prepareSubmit
|
|
148
|
-
const values = {};
|
|
149
|
-
for (const preparation of submitPreparations) {
|
|
150
|
-
const preparedValues = await preparation();
|
|
151
|
-
if (preparedValues)
|
|
152
|
-
Object.assign(values, preparedValues);
|
|
153
|
-
}
|
|
154
|
-
return values;
|
|
155
|
-
},
|
|
219
|
+
prepareSubmit,
|
|
156
220
|
};
|
|
157
221
|
}
|
|
158
222
|
function recordUiMetadata(form) {
|
package/dist/space/record.js
CHANGED
|
@@ -157,23 +157,29 @@ export class ProtocolRecordHandle {
|
|
|
157
157
|
return { ok: result.ok, snapshot };
|
|
158
158
|
}
|
|
159
159
|
async submit() {
|
|
160
|
-
const
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
160
|
+
const endSubmission = __classPrivateFieldGet(this, _ProtocolRecordHandle_formLifecycle, "f")?.beginSubmit();
|
|
161
|
+
try {
|
|
162
|
+
const values = await __classPrivateFieldGet(this, _ProtocolRecordHandle_formLifecycle, "f")?.prepareSubmit() ?? {};
|
|
163
|
+
const request = {
|
|
164
|
+
operation: 'record.submit',
|
|
165
|
+
payload: {
|
|
166
|
+
sessionId: this.id,
|
|
167
|
+
...(Object.keys(values).length > 0 ? { values } : {}),
|
|
168
|
+
},
|
|
169
|
+
protocol: PROTOCOL_VERSION,
|
|
170
|
+
requestId: __classPrivateFieldGet(this, _ProtocolRecordHandle_nextRequestId, "f").call(this),
|
|
171
|
+
};
|
|
172
|
+
const response = await __classPrivateFieldGet(this, _ProtocolRecordHandle_transport, "f").request(request);
|
|
173
|
+
const result = readResponse(response, request);
|
|
174
|
+
if (!isRecordSubmitResult(result))
|
|
175
|
+
throw invalidResponse('The record-submit response is malformed.');
|
|
176
|
+
const snapshot = immutableSnapshot(result.snapshot);
|
|
177
|
+
this.setSnapshot(snapshot);
|
|
178
|
+
return { ok: result.ok, snapshot };
|
|
179
|
+
}
|
|
180
|
+
finally {
|
|
181
|
+
endSubmission?.();
|
|
182
|
+
}
|
|
177
183
|
}
|
|
178
184
|
}
|
|
179
185
|
_ProtocolRecordHandle_nextRequestId = new WeakMap(), _ProtocolRecordHandle_transport = new WeakMap(), _ProtocolRecordHandle_formLifecycle = new WeakMap(), _ProtocolRecordHandle_snapshot = new WeakMap();
|
package/dist/space/tabs.d.ts
CHANGED
|
@@ -1,12 +1,10 @@
|
|
|
1
1
|
import type { ProtocolRequest, SpaceTransport } from './protocol.js';
|
|
2
|
-
import type { SpaceStatusTone } from './status.js';
|
|
3
2
|
export declare const TABS_PROTOCOL_VERSION: 1;
|
|
4
3
|
export declare const DEFAULT_TABS_TIMEOUT_MS = 10000;
|
|
5
4
|
export declare const LUCIDE_ICON_NAME: RegExp;
|
|
6
5
|
export declare const TAB_ID: RegExp;
|
|
7
6
|
export interface SpaceTab {
|
|
8
7
|
badge?: number | string;
|
|
9
|
-
badgeTone?: SpaceStatusTone;
|
|
10
8
|
default?: boolean;
|
|
11
9
|
icon?: string;
|
|
12
10
|
id: string;
|
|
@@ -32,7 +30,6 @@ export interface SpaceTabsTransport extends SpaceTransport {
|
|
|
32
30
|
}
|
|
33
31
|
export interface WireTab {
|
|
34
32
|
badge?: number | string;
|
|
35
|
-
badgeTone?: SpaceStatusTone;
|
|
36
33
|
default?: true;
|
|
37
34
|
icon?: string;
|
|
38
35
|
id: string;
|
package/dist/space/tabs.js
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { invalidRequest, invalidResponse, isNonBlankString, isNonNegativeInteger, isObjectRecord, PROTOCOL_VERSION, readResponse, requestWithin, SpaceProtocolError, } from './protocol.js';
|
|
2
|
-
import { SPACE_STATUS_TONES } from './status.js';
|
|
3
2
|
export const TABS_PROTOCOL_VERSION = 1;
|
|
4
3
|
export const DEFAULT_TABS_TIMEOUT_MS = 10000;
|
|
5
4
|
export const LUCIDE_ICON_NAME = /^[a-z0-9]+(-[a-z0-9]+)*$/;
|
|
@@ -50,10 +49,6 @@ export function validateTabs(options) {
|
|
|
50
49
|
throw invalidRequest(`Tab "${tab.id}" badge must be a non-empty string or a non-negative integer.`);
|
|
51
50
|
}
|
|
52
51
|
}
|
|
53
|
-
if (tab.badgeTone !== undefined
|
|
54
|
-
&& (typeof tab.badgeTone !== 'string' || !SPACE_STATUS_TONES.includes(tab.badgeTone))) {
|
|
55
|
-
throw invalidRequest(`Tab "${tab.id}" badgeTone must be one of: ${SPACE_STATUS_TONES.join(', ')}.`);
|
|
56
|
-
}
|
|
57
52
|
}
|
|
58
53
|
if (defaultCount > 1)
|
|
59
54
|
throw invalidRequest('Only one tab may be marked as default.');
|
|
@@ -61,7 +56,6 @@ export function validateTabs(options) {
|
|
|
61
56
|
const isDefault = Boolean(tab.default || (defaultCount === 0 && index === 0));
|
|
62
57
|
return {
|
|
63
58
|
...(tab.badge !== undefined ? { badge: tab.badge } : {}),
|
|
64
|
-
...(tab.badgeTone !== undefined ? { badgeTone: tab.badgeTone } : {}),
|
|
65
59
|
...(isDefault ? { default: true } : {}),
|
|
66
60
|
...(tab.icon !== undefined ? { icon: tab.icon } : {}),
|
|
67
61
|
id: tab.id,
|
package/dist/space/ui.d.ts
CHANGED
|
@@ -1,8 +1,5 @@
|
|
|
1
|
-
import type { SpaceStatusTone } from './status.js';
|
|
2
1
|
export declare const HEADER_ACTIONS_PROTOCOL_VERSION: 1;
|
|
3
|
-
export declare const HEADER_STATUS_PROTOCOL_VERSION: 1;
|
|
4
2
|
export declare const TOAST_PROTOCOL_VERSION: 1;
|
|
5
|
-
export type { SpaceStatusTone } from './status.js';
|
|
6
3
|
export { createTabsClient, DEFAULT_TABS_TIMEOUT_MS, LUCIDE_ICON_NAME, TAB_ID, TABS_PROTOCOL_VERSION, validateTabs, } from './tabs.js';
|
|
7
4
|
export type { SetTabsOptions, SimpleTabsClient, SpaceTab, SpaceTabsSelectionEvent, SpaceTabsTransport, TabsSelectPayload, TabsSelectRequest, TabsSelectResult, TabsSetPayload, TabsSetRequest, TabsSetResult, WireTab, } from './tabs.js';
|
|
8
5
|
export type HeaderActionType = 'destructive' | 'outline' | 'primary' | 'secondary';
|
|
@@ -24,24 +21,12 @@ export interface HeaderAction {
|
|
|
24
21
|
export interface SimpleHeaderActionsClient {
|
|
25
22
|
set: (actions: readonly HeaderAction[]) => void;
|
|
26
23
|
}
|
|
27
|
-
export interface SpaceHeaderStatus {
|
|
28
|
-
description?: string;
|
|
29
|
-
label: string;
|
|
30
|
-
tone: SpaceStatusTone;
|
|
31
|
-
}
|
|
32
|
-
export interface SimpleHeaderStatusClient {
|
|
33
|
-
set: (status: SpaceHeaderStatus | null) => void;
|
|
34
|
-
}
|
|
35
24
|
export interface SimpleHeaderClient {
|
|
36
25
|
actions: SimpleHeaderActionsClient;
|
|
37
|
-
status: SimpleHeaderStatusClient;
|
|
38
26
|
}
|
|
39
27
|
export interface SpaceHeaderTransport {
|
|
40
28
|
setActions: (actions: readonly HeaderAction[]) => void;
|
|
41
29
|
}
|
|
42
|
-
export interface SpaceHeaderStatusTransport {
|
|
43
|
-
setStatus: (status: SpaceHeaderStatus | null) => void;
|
|
44
|
-
}
|
|
45
30
|
export type SpaceToastVariant = 'default' | 'destructive';
|
|
46
31
|
export type SpaceToastOptions = {
|
|
47
32
|
variant?: SpaceToastVariant;
|
|
@@ -62,6 +47,5 @@ export declare function validateHeaderActions(actions: readonly HeaderAction[]):
|
|
|
62
47
|
export declare const MAX_TOAST_TITLE_LENGTH = 160;
|
|
63
48
|
export declare const MAX_TOAST_DESCRIPTION_LENGTH = 1000;
|
|
64
49
|
export declare function validateSpaceToastOptions(options: SpaceToastOptions): SpaceToastOptions;
|
|
65
|
-
export declare function createHeaderClient(isRecordSpace: boolean, headerTransport?: SpaceHeaderTransport
|
|
66
|
-
export declare function validateHeaderStatus(status: SpaceHeaderStatus | null): SpaceHeaderStatus | null;
|
|
50
|
+
export declare function createHeaderClient(isRecordSpace: boolean, headerTransport?: SpaceHeaderTransport): SimpleHeaderClient;
|
|
67
51
|
export declare function createToastClient(toastTransport?: SpaceToastTransport): SimpleToastClient;
|
package/dist/space/ui.js
CHANGED
|
@@ -1,7 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { SPACE_STATUS_TONES } from './status.js';
|
|
1
|
+
import { SpaceProtocolError } from './protocol.js';
|
|
3
2
|
export const HEADER_ACTIONS_PROTOCOL_VERSION = 1;
|
|
4
|
-
export const HEADER_STATUS_PROTOCOL_VERSION = 1;
|
|
5
3
|
export const TOAST_PROTOCOL_VERSION = 1;
|
|
6
4
|
export { createTabsClient, DEFAULT_TABS_TIMEOUT_MS, LUCIDE_ICON_NAME, TAB_ID, TABS_PROTOCOL_VERSION, validateTabs, } from './tabs.js';
|
|
7
5
|
export function validateHeaderActions(actions) {
|
|
@@ -53,7 +51,7 @@ export function validateSpaceToastOptions(options) {
|
|
|
53
51
|
...(candidate.variant === undefined ? {} : { variant: candidate.variant }),
|
|
54
52
|
};
|
|
55
53
|
}
|
|
56
|
-
export function createHeaderClient(isRecordSpace, headerTransport
|
|
54
|
+
export function createHeaderClient(isRecordSpace, headerTransport) {
|
|
57
55
|
return {
|
|
58
56
|
actions: {
|
|
59
57
|
set(actions) {
|
|
@@ -72,40 +70,6 @@ export function createHeaderClient(isRecordSpace, headerTransport, headerStatusT
|
|
|
72
70
|
headerTransport.setActions(validateHeaderActions(actions));
|
|
73
71
|
},
|
|
74
72
|
},
|
|
75
|
-
status: {
|
|
76
|
-
set(status) {
|
|
77
|
-
if (!isRecordSpace) {
|
|
78
|
-
throw new SpaceProtocolError({
|
|
79
|
-
code: 'unavailable',
|
|
80
|
-
message: 'Header status is available only when this Space is configured as a record view.',
|
|
81
|
-
});
|
|
82
|
-
}
|
|
83
|
-
if (!headerStatusTransport) {
|
|
84
|
-
throw new SpaceProtocolError({
|
|
85
|
-
code: 'unavailable',
|
|
86
|
-
message: 'The header-status bridge is unavailable for this record Space.',
|
|
87
|
-
});
|
|
88
|
-
}
|
|
89
|
-
headerStatusTransport.setStatus(validateHeaderStatus(status));
|
|
90
|
-
},
|
|
91
|
-
},
|
|
92
|
-
};
|
|
93
|
-
}
|
|
94
|
-
export function validateHeaderStatus(status) {
|
|
95
|
-
if (status === null)
|
|
96
|
-
return null;
|
|
97
|
-
if (!isObjectRecord(status))
|
|
98
|
-
throw invalidRequest('Header status must be an object or null.');
|
|
99
|
-
if (typeof status.label !== 'string' || !status.label.trim() || status.label.length > 80)
|
|
100
|
-
throw invalidRequest('Header status label must be a non-empty string of at most 80 characters.');
|
|
101
|
-
if (typeof status.tone !== 'string' || !SPACE_STATUS_TONES.includes(status.tone))
|
|
102
|
-
throw invalidRequest(`Header status tone must be one of: ${SPACE_STATUS_TONES.join(', ')}.`);
|
|
103
|
-
if (status.description !== undefined && typeof status.description !== 'string')
|
|
104
|
-
throw invalidRequest('Header status description must be a string.');
|
|
105
|
-
return {
|
|
106
|
-
...(status.description === undefined ? {} : { description: status.description }),
|
|
107
|
-
label: status.label,
|
|
108
|
-
tone: status.tone,
|
|
109
73
|
};
|
|
110
74
|
}
|
|
111
75
|
export function createToastClient(toastTransport) {
|
package/package.json
CHANGED
package/dist/space/status.d.ts
DELETED