@peers-app/peers-ui 0.33.13 → 0.33.15
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/dist/components/markdown-editor/editor.d.ts +10 -4
- package/dist/components/markdown-editor/editor.js +7 -5
- package/dist/components/markdown-editor/markdown-plugin.d.ts +24 -6
- package/dist/components/markdown-editor/markdown-plugin.js +33 -16
- package/dist/index.d.ts +1 -0
- package/dist/index.js +2 -0
- package/dist/mentions/mention-chip.d.ts +1 -1
- package/dist/mentions/mention-chip.js +2 -1
- package/dist/tabs-layout/tab-color.d.ts +19 -0
- package/dist/tabs-layout/tab-color.js +38 -0
- package/dist/tabs-layout/tabs-layout.js +11 -3
- package/dist/theme.css +37 -0
- package/dist/ui-contracts/host-ui-contract.d.ts +28 -0
- package/dist/ui-contracts/host-ui-contract.js +45 -0
- package/dist/ui-contracts/implement-piece.d.ts +24 -0
- package/dist/ui-contracts/implement-piece.js +44 -0
- package/dist/ui-contracts/index.d.ts +6 -0
- package/dist/ui-contracts/index.js +17 -0
- package/dist/ui-contracts/mock-piece.d.ts +36 -0
- package/dist/ui-contracts/mock-piece.js +56 -0
- package/dist/ui-contracts/piece-host.d.ts +99 -0
- package/dist/ui-contracts/piece-host.js +266 -0
- package/dist/ui-contracts/piece-resolution.d.ts +55 -0
- package/dist/ui-contracts/piece-resolution.js +186 -0
- package/dist/ui-contracts/piece.d.ts +77 -0
- package/dist/ui-contracts/piece.js +358 -0
- package/dist/ui-contracts/popover-surface.d.ts +21 -0
- package/dist/ui-contracts/popover-surface.js +169 -0
- package/dist/ui-contracts/types.d.ts +113 -0
- package/dist/ui-contracts/types.js +2 -0
- package/dist/ui-router/ui-loader.js +9 -3
- package/package.json +3 -3
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
import type { IPieceImplementation, IUIContractDeclaration, PieceEmitInputsOf, PieceEmitPayloadsOf, PiecePropsOf, UIContractPieceNamesOf } from "@peers-app/peers-sdk";
|
|
2
|
+
import type React from "react";
|
|
3
|
+
/**
|
|
4
|
+
* One piece of a UI contract, as a screen embeds it: from a {@link IHostUIContractClient}'s
|
|
5
|
+
* `pieces`. It names the UI contract version, the piece, and the group and provider the client
|
|
6
|
+
* was made for. Pass it to `<Piece of={…}>` or {@link usePiece}.
|
|
7
|
+
*/
|
|
8
|
+
export interface IPieceHandle<T = unknown, N extends string = string> {
|
|
9
|
+
/** Marks a piece handle. */
|
|
10
|
+
readonly kind: "piece-handle";
|
|
11
|
+
/** The UI contract's id. */
|
|
12
|
+
readonly contractId: string;
|
|
13
|
+
/** The UI contract version the embedder consumes. */
|
|
14
|
+
readonly version: number;
|
|
15
|
+
/** The piece's name. */
|
|
16
|
+
readonly name: N;
|
|
17
|
+
/** The group whose provider draws the piece; the active group when absent. */
|
|
18
|
+
readonly dataContextId?: string | (() => Promise<string>);
|
|
19
|
+
/** A provider to use instead of the group's active one, as a hub names each of its providers. */
|
|
20
|
+
readonly providerPackageId?: string;
|
|
21
|
+
/** Type-only: the UI contract. Always undefined at runtime. */
|
|
22
|
+
readonly types?: {
|
|
23
|
+
contract: T;
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
/** Where a piece can be embedded from: a client's group and, for a hub, one provider. */
|
|
27
|
+
export interface IHostUIContractOptions {
|
|
28
|
+
/**
|
|
29
|
+
* The group whose provider draws the piece: its id, or a function that gives it. Absent, the
|
|
30
|
+
* active group. Pass the id of the group the piece's data belongs to, since the group switcher
|
|
31
|
+
* is going away, and make the client once per group. A function, or none, is read again each
|
|
32
|
+
* time the screen renders, so the piece follows it.
|
|
33
|
+
*/
|
|
34
|
+
dataContextId?: string | (() => Promise<string>);
|
|
35
|
+
/** A provider to use instead of the group's active one. */
|
|
36
|
+
providerPackageId?: string;
|
|
37
|
+
}
|
|
38
|
+
/** A client for a UI contract: a handle for each of its pieces, by name. */
|
|
39
|
+
export interface IHostUIContractClient<T = unknown> {
|
|
40
|
+
/** The UI contract's id. */
|
|
41
|
+
readonly contractId: string;
|
|
42
|
+
/** The UI contract version. */
|
|
43
|
+
readonly version: number;
|
|
44
|
+
/** A handle for each piece, by name. */
|
|
45
|
+
readonly pieces: [UIContractPieceNamesOf<T>] extends [never] ? Record<string, IPieceHandle<T, string>> : {
|
|
46
|
+
readonly [N in UIContractPieceNamesOf<T>]: IPieceHandle<T, N>;
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
/** Why a piece can't show. */
|
|
50
|
+
export type PieceUnavailableReason = "missing" | "older" | "not-running" | "failed";
|
|
51
|
+
/** A piece that can't show: why, a sentence for people, and for `failed`, a way to try again. */
|
|
52
|
+
export interface IPieceUnavailable {
|
|
53
|
+
/**
|
|
54
|
+
* - `missing`: nothing in the group provides the UI contract;
|
|
55
|
+
* - `older`: the group's provider has the UI contract, but not this version;
|
|
56
|
+
* - `not-running`: the provider is installed but doesn't run here (waiting for a contract it
|
|
57
|
+
* requires, not approved on this device, turned off, or unsupported on this host);
|
|
58
|
+
* - `failed`: its UI didn't load, registered no component for the piece, or threw; or it's
|
|
59
|
+
* drawn inside itself, or more than four pieces deep.
|
|
60
|
+
*/
|
|
61
|
+
reason: PieceUnavailableReason;
|
|
62
|
+
/** What's wrong, in a sentence. */
|
|
63
|
+
message: string;
|
|
64
|
+
/** For `failed`: load and draw it again. */
|
|
65
|
+
retry?: () => void;
|
|
66
|
+
}
|
|
67
|
+
/** What a piece's link or mention opens, sent with the built-in `open` emit. */
|
|
68
|
+
export interface IPieceOpenTarget {
|
|
69
|
+
/** The record's kind, such as `task`. */
|
|
70
|
+
kind: string;
|
|
71
|
+
/** The record's id. */
|
|
72
|
+
id: string;
|
|
73
|
+
/** The group it's in, when the piece knows. */
|
|
74
|
+
groupId?: string;
|
|
75
|
+
}
|
|
76
|
+
/** The emit functions a piece's component gets: one per declared emit, plus `open`. */
|
|
77
|
+
export type PieceEmitters<T, N extends UIContractPieceNamesOf<T>> = {
|
|
78
|
+
readonly [E in keyof PieceEmitInputsOf<T, N>]: (payload: PieceEmitInputsOf<T, N>[E]) => void;
|
|
79
|
+
} & {
|
|
80
|
+
/** Ask the embedder to open a record; the host opens it when the embedder doesn't. */
|
|
81
|
+
readonly open: (target: IPieceOpenTarget) => void;
|
|
82
|
+
};
|
|
83
|
+
/** What a piece's component gets. */
|
|
84
|
+
export interface PieceComponentProps<T extends IUIContractDeclaration<any, any, any>, N extends UIContractPieceNamesOf<T> = UIContractPieceNamesOf<T>> {
|
|
85
|
+
/** What the embedder passed: plain data, checked against the declared props. */
|
|
86
|
+
props: PiecePropsOf<T, N>;
|
|
87
|
+
/** Send a declared emit to the embedder, or `open` a record. */
|
|
88
|
+
emit: PieceEmitters<T, N>;
|
|
89
|
+
/** For a popover: close it. A view can call it too; its embedder decides what it means. */
|
|
90
|
+
close: () => void;
|
|
91
|
+
/** The group the piece was embedded for. */
|
|
92
|
+
groupId: string;
|
|
93
|
+
}
|
|
94
|
+
/** The handlers an embedder passes `<Piece on={…}>`, one per emit it cares about. */
|
|
95
|
+
export type PieceHandlers<T, N extends string> = N extends UIContractPieceNamesOf<T> ? {
|
|
96
|
+
readonly [E in keyof PieceEmitPayloadsOf<T, N>]?: (payload: PieceEmitPayloadsOf<T, N>[E]) => void;
|
|
97
|
+
} & {
|
|
98
|
+
/**
|
|
99
|
+
* A link or mention in the piece was clicked. Return `false` to let the host open it as
|
|
100
|
+
* usual, which is also what happens without this handler.
|
|
101
|
+
*/
|
|
102
|
+
readonly open?: (target: IPieceOpenTarget) => unknown;
|
|
103
|
+
} : Record<string, ((payload: never) => unknown) | undefined>;
|
|
104
|
+
/** The props type a piece takes, for a handle. */
|
|
105
|
+
export type PieceHandleProps<H> = H extends IPieceHandle<infer T, infer N> ? N extends UIContractPieceNamesOf<T> ? PiecePropsOf<T, N> : Record<string, unknown> : never;
|
|
106
|
+
/** A registered piece's component, as a UI bundle exports it. */
|
|
107
|
+
export type PieceComponent = React.ComponentType<{
|
|
108
|
+
props: Record<string, unknown>;
|
|
109
|
+
emit: Record<string, (payload?: unknown) => void>;
|
|
110
|
+
close: () => void;
|
|
111
|
+
groupId: string;
|
|
112
|
+
}>;
|
|
113
|
+
export type { IPieceImplementation };
|
|
@@ -45,6 +45,7 @@ const hooks_1 = require("../hooks");
|
|
|
45
45
|
const package_waiting_1 = require("../screens/packages/package-waiting");
|
|
46
46
|
const packages_ipc_1 = require("../screens/packages/packages-ipc");
|
|
47
47
|
require("../ui-defaults");
|
|
48
|
+
const piece_host_1 = require("../ui-contracts/piece-host");
|
|
48
49
|
const bundle_files_1 = require("./bundle-files");
|
|
49
50
|
const find_route_1 = require("./find-route");
|
|
50
51
|
const routes_loader_1 = require("./routes-loader");
|
|
@@ -157,7 +158,9 @@ async function readUIBundle(pkg, servingPackageVersionId) {
|
|
|
157
158
|
if (bundleCode && selected.dataContext.groupId) {
|
|
158
159
|
(0, peers_sdk_1.assertPackageBundleIntegrity)(selected.pv, "ui", bundleCode);
|
|
159
160
|
}
|
|
160
|
-
return bundleCode
|
|
161
|
+
return bundleCode
|
|
162
|
+
? { code: bundleCode, packageVersionId: selected.pv.packageVersionId, uiBundleFileId }
|
|
163
|
+
: undefined;
|
|
161
164
|
}
|
|
162
165
|
/**
|
|
163
166
|
* Run a package's UI bundle once per version, registering its UIs. A load for another version, or
|
|
@@ -179,16 +182,19 @@ function loadUIBundle(pkg, opts) {
|
|
|
179
182
|
const load = { serving, promise: Promise.resolve(), done: false };
|
|
180
183
|
load.promise = (async () => {
|
|
181
184
|
try {
|
|
182
|
-
const
|
|
185
|
+
const read = await (opts.read ?? readUIBundle(pkg, opts.servingPackageVersionId));
|
|
186
|
+
const bundleCode = read?.code;
|
|
183
187
|
// A newer load (another version, or a reload) took this one's place: settle with it.
|
|
184
188
|
const latest = uiLoads[pkg.packageId];
|
|
185
189
|
if (latest !== load)
|
|
186
190
|
return latest.promise;
|
|
187
|
-
if (bundleCode) {
|
|
191
|
+
if (read && bundleCode) {
|
|
188
192
|
const exportUIs = (peerUIs) => {
|
|
189
193
|
peerUIs?.uis?.forEach((ui) => {
|
|
190
194
|
peersUIs[ui.peersUIId] = ui;
|
|
191
195
|
});
|
|
196
|
+
// Its UI contracts' pieces too, so a piece of this version doesn't run it again.
|
|
197
|
+
(0, piece_host_1.recordLoadedPieces)(read.packageVersionId, read.uiBundleFileId, peerUIs);
|
|
192
198
|
};
|
|
193
199
|
const bundleFunction = new Function("exportUIs", bundleCode);
|
|
194
200
|
await bundleFunction(exportUIs);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@peers-app/peers-ui",
|
|
3
|
-
"version": "0.33.
|
|
3
|
+
"version": "0.33.15",
|
|
4
4
|
"repository": {
|
|
5
5
|
"type": "git",
|
|
6
6
|
"url": "git+https://github.com/peers-app/peers-ui.git"
|
|
@@ -36,7 +36,7 @@
|
|
|
36
36
|
"lint:fix": "biome check --write ."
|
|
37
37
|
},
|
|
38
38
|
"peerDependencies": {
|
|
39
|
-
"@peers-app/peers-sdk": "^0.33.
|
|
39
|
+
"@peers-app/peers-sdk": "^0.33.15",
|
|
40
40
|
"bootstrap": "^5.3.3",
|
|
41
41
|
"react": "^18.0.0",
|
|
42
42
|
"react-dom": "^18.0.0"
|
|
@@ -47,7 +47,7 @@
|
|
|
47
47
|
"@babel/preset-react": "^7.24.1",
|
|
48
48
|
"@babel/preset-typescript": "^7.27.1",
|
|
49
49
|
"@biomejs/biome": "2.3.11",
|
|
50
|
-
"@peers-app/peers-sdk": "0.33.
|
|
50
|
+
"@peers-app/peers-sdk": "0.33.15",
|
|
51
51
|
"@testing-library/dom": "^10.4.0",
|
|
52
52
|
"@testing-library/jest-dom": "^6.6.3",
|
|
53
53
|
"@testing-library/react": "^16.3.0",
|