@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
|
@@ -51,11 +51,17 @@ export interface IMarkdownEditorProps {
|
|
|
51
51
|
* group as the document's, and mentions resolve wherever they were last found.
|
|
52
52
|
*/
|
|
53
53
|
groupId?: string;
|
|
54
|
+
/**
|
|
55
|
+
* Whether a line starting with `#` is a heading. True if omitted, for documents such as task
|
|
56
|
+
* bodies and notes. Pass false for short inline text such as messages, where `#` stays text.
|
|
57
|
+
*/
|
|
58
|
+
headings?: boolean;
|
|
54
59
|
}
|
|
55
60
|
/**
|
|
56
|
-
* A rich-text editor whose value is markdown:
|
|
57
|
-
* finds people and records in every group, `@` people, a
|
|
58
|
-
* as `#`, that source's records, and a pasted id becomes
|
|
59
|
-
* chip with the record's live title). Edits are written
|
|
61
|
+
* A rich-text editor whose value is markdown: headings (unless `headings` is false), lists and
|
|
62
|
+
* checklists, links, and mentions (`<` finds people and records in every group, `@` people, a
|
|
63
|
+
* trigger a mention source declares, such as `#`, that source's records, and a pasted id becomes
|
|
64
|
+
* its record's chip; a mention shows as a chip with the record's live title). Edits are written
|
|
65
|
+
* back to `value`.
|
|
60
66
|
*/
|
|
61
67
|
export declare function MarkdownEditor(props: IMarkdownEditorProps): import("react/jsx-runtime").JSX.Element;
|
|
@@ -87,10 +87,11 @@ const editorConfig = {
|
|
|
87
87
|
theme: theme_1.default,
|
|
88
88
|
};
|
|
89
89
|
/**
|
|
90
|
-
* A rich-text editor whose value is markdown:
|
|
91
|
-
* finds people and records in every group, `@` people, a
|
|
92
|
-
* as `#`, that source's records, and a pasted id becomes
|
|
93
|
-
* chip with the record's live title). Edits are written
|
|
90
|
+
* A rich-text editor whose value is markdown: headings (unless `headings` is false), lists and
|
|
91
|
+
* checklists, links, and mentions (`<` finds people and records in every group, `@` people, a
|
|
92
|
+
* trigger a mention source declares, such as `#`, that source's records, and a pasted id becomes
|
|
93
|
+
* its record's chip; a mention shows as a chip with the record's live title). Edits are written
|
|
94
|
+
* back to `value`.
|
|
94
95
|
*/
|
|
95
96
|
function MarkdownEditor(props) {
|
|
96
97
|
const { effects } = props;
|
|
@@ -118,7 +119,8 @@ function MarkdownEditor(props) {
|
|
|
118
119
|
}
|
|
119
120
|
};
|
|
120
121
|
}
|
|
121
|
-
|
|
122
|
+
const transformers = props.headings === false ? markdown_plugin_1.inlineMarkdownTransformers : markdown_plugin_1.documentMarkdownTransformers;
|
|
123
|
+
return ((0, jsx_runtime_1.jsx)(mention_chip_1.MentionGroupContext.Provider, { value: props.groupId, children: (0, jsx_runtime_1.jsx)(LexicalComposer_1.LexicalComposer, { initialConfig: { ...editorConfig }, children: (0, jsx_runtime_1.jsxs)("div", { className: "editor-container", children: [props.hideToolbar ? null : (0, jsx_runtime_1.jsx)(toolbar_1.ToolbarPlugin, { topRightControls: props.topRightControls }), (0, jsx_runtime_1.jsxs)("div", { className: "editor-inner", ref: editorRef, style: { maxHeight: props.maxHeight, overflowY: "auto" }, children: [(0, jsx_runtime_1.jsx)(LexicalRichTextPlugin_1.RichTextPlugin, { contentEditable: (0, jsx_runtime_1.jsx)(LexicalContentEditable_1.ContentEditable, { className: "editor-input p-2" }), placeholder: null, ErrorBoundary: LexicalErrorBoundary_1.LexicalErrorBoundary }), (0, jsx_runtime_1.jsx)(LexicalHistoryPlugin_1.HistoryPlugin, {}), props.autoFocus && (0, jsx_runtime_1.jsx)(LexicalAutoFocusPlugin_1.AutoFocusPlugin, { defaultSelection: "rootEnd" }), (0, jsx_runtime_1.jsx)(LexicalListPlugin_1.ListPlugin, {}), props.mentions !== false && ((0, jsx_runtime_1.jsx)(mentions_plugin_1.MentionsPlugin, { mentionsOpen: mentionsOpen, groupId: props.groupId })), (0, jsx_runtime_1.jsx)(autolink_plugin_1.LexicalAutoLinkPlugin, {}), (0, jsx_runtime_1.jsx)(markdown_plugin_1.MarkdownPlugin, { markdownObs: props.value, transformers: transformers }), (0, jsx_runtime_1.jsx)(LexicalMarkdownShortcutPlugin_1.MarkdownShortcutPlugin, { transformers: transformers }), (0, jsx_runtime_1.jsx)(LexicalCheckListPlugin_1.CheckListPlugin, {}), (0, jsx_runtime_1.jsx)(LexicalTabIndentationPlugin_1.TabIndentationPlugin, {}), (0, jsx_runtime_1.jsx)(move_line_plugin_1.MoveLineWithAltArrowsPlugin, { mentionsOpen: mentionsOpen }), (0, jsx_runtime_1.jsx)(select_line_boundary_plugin_1.SelectToLineBoundaryPlugin, {}), (0, jsx_runtime_1.jsx)(OnKeyDownPlugin, { effects: props.effects, mentionsOpen: mentionsOpen }), effects ? (0, jsx_runtime_1.jsx)(selection_effects_plugin_1.SelectionEffectsPlugin, { effects: effects }) : null] })] }) }) }));
|
|
122
124
|
}
|
|
123
125
|
const OnKeyDownPlugin = (props) => {
|
|
124
126
|
const [editor] = (0, LexicalComposerContext_1.useLexicalComposerContext)();
|
|
@@ -1,15 +1,33 @@
|
|
|
1
|
+
import { type Transformer } from "@lexical/markdown";
|
|
1
2
|
import { type Observable } from "@peers-app/peers-sdk";
|
|
2
3
|
/**
|
|
3
|
-
*
|
|
4
|
-
* otherwise take `peers://` links) and checklists
|
|
4
|
+
* Markdown for documents (task bodies, notes): mentions (ahead of Lexical's link transformer,
|
|
5
|
+
* which would otherwise take `peers://` links) and checklists (ahead of Lexical's lists, or
|
|
6
|
+
* `- [ ]` would read as a plain list item), then Lexical's own, headings included.
|
|
5
7
|
*/
|
|
6
|
-
export declare const
|
|
7
|
-
|
|
8
|
+
export declare const documentMarkdownTransformers: Transformer[];
|
|
9
|
+
/**
|
|
10
|
+
* The transformers without the heading one. It's recognized by its node's type, `"heading"`, not
|
|
11
|
+
* the class's name: the app ships Lexical's minified build, which renames classes, so the name
|
|
12
|
+
* check this replaced never matched and headings stayed on.
|
|
13
|
+
*
|
|
14
|
+
* @param transformers - The transformers to filter.
|
|
15
|
+
*/
|
|
16
|
+
export declare function withoutHeadings(transformers: readonly Transformer[]): Transformer[];
|
|
17
|
+
/**
|
|
18
|
+
* Markdown for short inline text such as messages, where a line starting with `#` stays text: the
|
|
19
|
+
* document transformers without headings.
|
|
20
|
+
*/
|
|
21
|
+
export declare const inlineMarkdownTransformers: Transformer[];
|
|
22
|
+
/** {@link MarkdownPlugin}'s props. */
|
|
23
|
+
export interface IMarkdownPluginProps {
|
|
24
|
+
/** The markdown the editor shows, written back as the user edits. */
|
|
8
25
|
markdownObs: Observable<string>;
|
|
26
|
+
/** How markdown is read and written. {@link documentMarkdownTransformers} if omitted. */
|
|
27
|
+
transformers?: Transformer[];
|
|
9
28
|
}
|
|
10
29
|
/**
|
|
11
30
|
* Keeps the editor and a markdown observable in step: the observable's value is loaded into the
|
|
12
31
|
* editor (without moving the caret or taking focus), and edits are written back as markdown.
|
|
13
32
|
*/
|
|
14
|
-
export declare function MarkdownPlugin(props:
|
|
15
|
-
export {};
|
|
33
|
+
export declare function MarkdownPlugin(props: IMarkdownPluginProps): null;
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.inlineMarkdownTransformers = exports.documentMarkdownTransformers = void 0;
|
|
4
|
+
exports.withoutHeadings = withoutHeadings;
|
|
4
5
|
exports.MarkdownPlugin = MarkdownPlugin;
|
|
5
6
|
const list_1 = require("@lexical/list");
|
|
6
7
|
const markdown_1 = require("@lexical/markdown");
|
|
@@ -10,6 +11,7 @@ const react_1 = require("react");
|
|
|
10
11
|
const mention_node_1 = require("./mention-node");
|
|
11
12
|
// Amount of spaces that define indentation level
|
|
12
13
|
const LIST_INDENT_SIZE = 4;
|
|
14
|
+
/** A list item's indent level, from the tabs and spaces before its marker. */
|
|
13
15
|
function getIndent(whitespaces) {
|
|
14
16
|
const tabs = whitespaces.match(/\t/g);
|
|
15
17
|
const spaces = whitespaces.match(/ /g);
|
|
@@ -61,6 +63,7 @@ const listReplace = (listType) => {
|
|
|
61
63
|
}
|
|
62
64
|
};
|
|
63
65
|
};
|
|
66
|
+
/** A list (and the lists nested in it) as markdown, with `- [ ]`/`- [x]` for checklist items. */
|
|
64
67
|
const listExport = (listNode, exportChildren, depth) => {
|
|
65
68
|
const output = [];
|
|
66
69
|
const children = listNode.getChildren();
|
|
@@ -87,6 +90,7 @@ const listExport = (listNode, exportChildren, depth) => {
|
|
|
87
90
|
}
|
|
88
91
|
return output.join("\n");
|
|
89
92
|
};
|
|
93
|
+
/** `- [ ]` and `- [x]` lines as checklist items, both ways. */
|
|
90
94
|
const CHECK_LIST_TRANSFORMER = {
|
|
91
95
|
dependencies: [list_1.ListNode, list_1.ListItemNode],
|
|
92
96
|
export: (node, exportChildren) => {
|
|
@@ -131,22 +135,34 @@ const OLD_MENTION_TRANSFORMER = {
|
|
|
131
135
|
},
|
|
132
136
|
};
|
|
133
137
|
/**
|
|
134
|
-
*
|
|
135
|
-
* otherwise take `peers://` links) and checklists
|
|
138
|
+
* Markdown for documents (task bodies, notes): mentions (ahead of Lexical's link transformer,
|
|
139
|
+
* which would otherwise take `peers://` links) and checklists (ahead of Lexical's lists, or
|
|
140
|
+
* `- [ ]` would read as a plain list item), then Lexical's own, headings included.
|
|
136
141
|
*/
|
|
137
|
-
exports.
|
|
142
|
+
exports.documentMarkdownTransformers = [
|
|
138
143
|
MENTION_TRANSFORMER,
|
|
139
144
|
OLD_MENTION_TRANSFORMER,
|
|
140
|
-
CHECK_LIST_TRANSFORMER,
|
|
141
|
-
...markdown_1.TRANSFORMERS
|
|
142
|
-
const t = transformer;
|
|
143
|
-
// disable headings for this markdown since these are inline messages
|
|
144
|
-
if (t.dependencies?.[0]?.name === "HeadingNode") {
|
|
145
|
-
return false;
|
|
146
|
-
}
|
|
147
|
-
return true;
|
|
148
|
-
}),
|
|
145
|
+
CHECK_LIST_TRANSFORMER,
|
|
146
|
+
...markdown_1.TRANSFORMERS,
|
|
149
147
|
];
|
|
148
|
+
/**
|
|
149
|
+
* The transformers without the heading one. It's recognized by its node's type, `"heading"`, not
|
|
150
|
+
* the class's name: the app ships Lexical's minified build, which renames classes, so the name
|
|
151
|
+
* check this replaced never matched and headings stayed on.
|
|
152
|
+
*
|
|
153
|
+
* @param transformers - The transformers to filter.
|
|
154
|
+
*/
|
|
155
|
+
function withoutHeadings(transformers) {
|
|
156
|
+
return transformers.filter((transformer) => {
|
|
157
|
+
const nodes = "dependencies" in transformer ? transformer.dependencies : [];
|
|
158
|
+
return !nodes.some((node) => node.getType() === "heading");
|
|
159
|
+
});
|
|
160
|
+
}
|
|
161
|
+
/**
|
|
162
|
+
* Markdown for short inline text such as messages, where a line starting with `#` stays text: the
|
|
163
|
+
* document transformers without headings.
|
|
164
|
+
*/
|
|
165
|
+
exports.inlineMarkdownTransformers = withoutHeadings(exports.documentMarkdownTransformers);
|
|
150
166
|
/**
|
|
151
167
|
* Keeps the editor and a markdown observable in step: the observable's value is loaded into the
|
|
152
168
|
* editor (without moving the caret or taking focus), and edits are written back as markdown.
|
|
@@ -154,6 +170,7 @@ exports.customMarkdownTransformers = [
|
|
|
154
170
|
function MarkdownPlugin(props) {
|
|
155
171
|
const [editor] = (0, LexicalComposerContext_1.useLexicalComposerContext)();
|
|
156
172
|
const { markdownObs } = props;
|
|
173
|
+
const transformers = props.transformers ?? exports.documentMarkdownTransformers;
|
|
157
174
|
(0, react_1.useEffect)(() => {
|
|
158
175
|
let markdown = "";
|
|
159
176
|
function setMarkdown() {
|
|
@@ -163,7 +180,7 @@ function MarkdownPlugin(props) {
|
|
|
163
180
|
}
|
|
164
181
|
markdown = newMarkdown;
|
|
165
182
|
editor.update(() => {
|
|
166
|
-
(0, markdown_1.$convertFromMarkdownString)(markdown,
|
|
183
|
+
(0, markdown_1.$convertFromMarkdownString)(markdown, transformers, undefined, true, false);
|
|
167
184
|
});
|
|
168
185
|
}
|
|
169
186
|
setMarkdown();
|
|
@@ -172,7 +189,7 @@ function MarkdownPlugin(props) {
|
|
|
172
189
|
});
|
|
173
190
|
const sub2Dispose = editor.registerUpdateListener(({ editorState }) => {
|
|
174
191
|
editorState.read(() => {
|
|
175
|
-
const newMarkdown = (0, markdown_1.$convertToMarkdownString)(
|
|
192
|
+
const newMarkdown = (0, markdown_1.$convertToMarkdownString)(transformers, undefined, true);
|
|
176
193
|
if (newMarkdown !== markdown) {
|
|
177
194
|
markdown = newMarkdown;
|
|
178
195
|
markdownObs(markdown);
|
|
@@ -183,6 +200,6 @@ function MarkdownPlugin(props) {
|
|
|
183
200
|
sub.dispose();
|
|
184
201
|
sub2Dispose();
|
|
185
202
|
};
|
|
186
|
-
}, [editor, markdownObs]);
|
|
203
|
+
}, [editor, markdownObs, transformers]);
|
|
187
204
|
return null;
|
|
188
205
|
}
|
package/dist/index.d.ts
CHANGED
|
@@ -26,3 +26,4 @@ export { DEFAULT_ROOT_LAYOUT_ID, getRootLayout, getRootLayouts, } from "./root-l
|
|
|
26
26
|
export { selectedRootLayoutId, setRootLayout } from "./root-layout/root-layout-state";
|
|
27
27
|
export * from "./tabs-layout/tabs-layout";
|
|
28
28
|
export { activeTabId, activeTabs, closeCurrentTab, goToTabPath, TabState, updateActiveTabTitle, } from "./tabs-layout/tabs-state";
|
|
29
|
+
export * from "./ui-contracts";
|
package/dist/index.js
CHANGED
|
@@ -71,3 +71,5 @@ Object.defineProperty(exports, "activeTabs", { enumerable: true, get: function (
|
|
|
71
71
|
Object.defineProperty(exports, "closeCurrentTab", { enumerable: true, get: function () { return tabs_state_1.closeCurrentTab; } });
|
|
72
72
|
Object.defineProperty(exports, "goToTabPath", { enumerable: true, get: function () { return tabs_state_1.goToTabPath; } });
|
|
73
73
|
Object.defineProperty(exports, "updateActiveTabTitle", { enumerable: true, get: function () { return tabs_state_1.updateActiveTabTitle; } });
|
|
74
|
+
// UI contracts: embed another package's UI pieces by contract (docs/Packages/ui-contracts.md).
|
|
75
|
+
__exportStar(require("./ui-contracts"), exports);
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type
|
|
1
|
+
import { type IMentionLink, type IMentionPlace } from "@peers-app/peers-sdk";
|
|
2
2
|
/**
|
|
3
3
|
* The group of the document a mention is in. Mentions resolve there first, and the picker marks
|
|
4
4
|
* results from other groups. Unset, the record is looked for wherever it was last found.
|
|
@@ -4,6 +4,7 @@ exports.MentionGroupContext = void 0;
|
|
|
4
4
|
exports.useMentionPlace = useMentionPlace;
|
|
5
5
|
exports.MentionChip = MentionChip;
|
|
6
6
|
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
7
|
+
const peers_sdk_1 = require("@peers-app/peers-sdk");
|
|
7
8
|
const react_1 = require("react");
|
|
8
9
|
const use_observable_1 = require("../hooks/use-observable");
|
|
9
10
|
const mentions_client_1 = require("./mentions-client");
|
|
@@ -72,5 +73,5 @@ function MentionChip(props) {
|
|
|
72
73
|
e.preventDefault();
|
|
73
74
|
open();
|
|
74
75
|
}
|
|
75
|
-
}, children: [(place?.kind ?? kind) === "user" ? ("@") : ((0, jsx_runtime_1.jsx)("i", { className: `${place?.iconClassName ?? "bi bi-link-45deg"} peers-mention-icon
|
|
76
|
+
}, children: [(place?.kind ?? kind) === "user" ? ("@") : ((0, jsx_runtime_1.jsx)("i", { className: `${place?.iconClassName ?? "bi bi-link-45deg"} peers-mention-icon`, ...((0, peers_sdk_1.isAppColor)(place?.color) ? { "data-color": place.color } : {}) })), title] }));
|
|
76
77
|
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { type AppColor } from "@peers-app/peers-sdk";
|
|
2
|
+
import { type TabState } from "./tabs-state";
|
|
3
|
+
/**
|
|
4
|
+
* The color of a tab's app on the Apps screen, for its icon in the tab strip: the color its app
|
|
5
|
+
* nav names, else the one Peers picks for it ({@link resolveAppColor}). The Apps tab, built-in
|
|
6
|
+
* apps and a route no package owns have none, and keep the strip's own grey.
|
|
7
|
+
*
|
|
8
|
+
* @param tab - The tab.
|
|
9
|
+
* @returns The app's palette color, or undefined for none.
|
|
10
|
+
*/
|
|
11
|
+
export declare function tabAppColor(tab: TabState): AppColor | undefined;
|
|
12
|
+
/**
|
|
13
|
+
* The classes that draw a tab's icon in its app's color ({@link tabAppColor}), kept current as
|
|
14
|
+
* packages load: a tab restored at startup finds its app once the packages are read.
|
|
15
|
+
*
|
|
16
|
+
* @param tab - The tab, or undefined for none.
|
|
17
|
+
* @returns `peers-tab-icon peers-app-color-<color>`, or an empty string for no color.
|
|
18
|
+
*/
|
|
19
|
+
export declare function useTabIconColorClass(tab: TabState | undefined): string;
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.tabAppColor = tabAppColor;
|
|
4
|
+
exports.useTabIconColorClass = useTabIconColorClass;
|
|
5
|
+
const peers_sdk_1 = require("@peers-app/peers-sdk");
|
|
6
|
+
const use_observable_1 = require("../hooks/use-observable");
|
|
7
|
+
const system_apps_1 = require("../system-apps");
|
|
8
|
+
const routes_loader_1 = require("../ui-router/routes-loader");
|
|
9
|
+
const tabs_state_1 = require("./tabs-state");
|
|
10
|
+
/**
|
|
11
|
+
* The color of a tab's app on the Apps screen, for its icon in the tab strip: the color its app
|
|
12
|
+
* nav names, else the one Peers picks for it ({@link resolveAppColor}). The Apps tab, built-in
|
|
13
|
+
* apps and a route no package owns have none, and keep the strip's own grey.
|
|
14
|
+
*
|
|
15
|
+
* @param tab - The tab.
|
|
16
|
+
* @returns The app's palette color, or undefined for none.
|
|
17
|
+
*/
|
|
18
|
+
function tabAppColor(tab) {
|
|
19
|
+
if (!tab.packageId || tab.packageId === "launcher" || tab.packageId === system_apps_1.systemPackage.packageId) {
|
|
20
|
+
return undefined;
|
|
21
|
+
}
|
|
22
|
+
const app = (0, tabs_state_1.determineAppFromPath)(tab.path);
|
|
23
|
+
if (!app || app.package.packageId === system_apps_1.systemPackage.packageId)
|
|
24
|
+
return undefined;
|
|
25
|
+
return (0, peers_sdk_1.resolveAppColor)(app.package.packageId, app.navItem);
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* The classes that draw a tab's icon in its app's color ({@link tabAppColor}), kept current as
|
|
29
|
+
* packages load: a tab restored at startup finds its app once the packages are read.
|
|
30
|
+
*
|
|
31
|
+
* @param tab - The tab, or undefined for none.
|
|
32
|
+
* @returns `peers-tab-icon peers-app-color-<color>`, or an empty string for no color.
|
|
33
|
+
*/
|
|
34
|
+
function useTabIconColorClass(tab) {
|
|
35
|
+
(0, use_observable_1.useObservable)(routes_loader_1.allPackages);
|
|
36
|
+
const color = tab ? tabAppColor(tab) : undefined;
|
|
37
|
+
return color ? `peers-tab-icon peers-app-color-${color}` : "";
|
|
38
|
+
}
|
|
@@ -53,6 +53,7 @@ const identity_routes_1 = require("../screens/identity/identity-routes");
|
|
|
53
53
|
const color_mode_dropdown_1 = require("../screens/settings/color-mode-dropdown");
|
|
54
54
|
const ui_loader_1 = require("../ui-router/ui-loader");
|
|
55
55
|
const network_status_indicator_1 = require("./network-status-indicator");
|
|
56
|
+
const tab_color_1 = require("./tab-color");
|
|
56
57
|
const tabs_state_1 = require("./tabs-state");
|
|
57
58
|
/**
|
|
58
59
|
* Wraps a single tab's content so a crash in one tab doesn't take down the whole app.
|
|
@@ -191,6 +192,7 @@ function MobileTabsHeader({ tabs, activeTab, onSwitch, onClose, colorMode, }) {
|
|
|
191
192
|
const notificationSummary = (0, notifications_client_1.useNotificationSummary)();
|
|
192
193
|
const notificationsLabel = (0, notifications_panel_1.notificationBadgeLabel)(notificationSummary);
|
|
193
194
|
const currentTab = tabs.find((t) => t.tabId === activeTab);
|
|
195
|
+
const currentIconColor = (0, tab_color_1.useTabIconColorClass)(currentTab);
|
|
194
196
|
const nonLauncherTabs = tabs.filter((t) => t.packageId !== "launcher");
|
|
195
197
|
const closeMenu = react_1.default.useCallback(() => {
|
|
196
198
|
setShowMenuDropdown(false);
|
|
@@ -211,7 +213,7 @@ function MobileTabsHeader({ tabs, activeTab, onSwitch, onClose, colorMode, }) {
|
|
|
211
213
|
transform: "translateX(-50%)",
|
|
212
214
|
pointerEvents: "none",
|
|
213
215
|
maxWidth: "calc(100% - 140px)",
|
|
214
|
-
}, children: [currentTab?.iconClassName && currentTab.packageId !== "launcher" && ((0, jsx_runtime_1.jsx)("i", { className: `${currentTab.iconClassName} me-2` })), (0, jsx_runtime_1.jsx)("span", { className: "fw-medium text-truncate small", children: currentTab?.title || "Apps" })] }), (0, jsx_runtime_1.jsxs)("div", { className: "d-flex align-items-center gap-1", children: [(0, jsx_runtime_1.jsx)(network_status_indicator_1.TabsStripIndicators, { compact: true, notifications: false }), (0, jsx_runtime_1.jsxs)("div", { className: "dropdown", children: [(0, jsx_runtime_1.jsx)("button", { type: "button", className: `btn btn-sm ${colorMode === "light" ? "btn-outline-dark" : "btn-outline-light"}`, onClick: () => (showMenuDropdown ? closeMenu() : setShowMenuDropdown(true)), style: { minWidth: "36px" }, "aria-label": [
|
|
216
|
+
}, children: [currentTab?.iconClassName && currentTab.packageId !== "launcher" && ((0, jsx_runtime_1.jsx)("i", { className: `${currentTab.iconClassName} me-2 ${currentIconColor}` })), (0, jsx_runtime_1.jsx)("span", { className: "fw-medium text-truncate small", children: currentTab?.title || "Apps" })] }), (0, jsx_runtime_1.jsxs)("div", { className: "d-flex align-items-center gap-1", children: [(0, jsx_runtime_1.jsx)(network_status_indicator_1.TabsStripIndicators, { compact: true, notifications: false }), (0, jsx_runtime_1.jsxs)("div", { className: "dropdown", children: [(0, jsx_runtime_1.jsx)("button", { type: "button", className: `btn btn-sm ${colorMode === "light" ? "btn-outline-dark" : "btn-outline-light"}`, onClick: () => (showMenuDropdown ? closeMenu() : setShowMenuDropdown(true)), style: { minWidth: "36px" }, "aria-label": [
|
|
215
217
|
"Menu",
|
|
216
218
|
nonLauncherTabs.length > 0 &&
|
|
217
219
|
`${nonLauncherTabs.length} tab${nonLauncherTabs.length === 1 ? "" : "s"}`,
|
|
@@ -241,13 +243,19 @@ function MobileTabsHeader({ tabs, activeTab, onSwitch, onClose, colorMode, }) {
|
|
|
241
243
|
.map((tab) => ((0, jsx_runtime_1.jsxs)("div", { className: `dropdown-item d-flex align-items-center justify-content-between ${activeTab === tab.tabId ? "active" : ""}`, style: { cursor: "pointer", padding: "14px 18px", fontSize: "17px" }, onClick: () => {
|
|
242
244
|
onSwitch(tab.tabId);
|
|
243
245
|
closeMenu();
|
|
244
|
-
}, children: [(0, jsx_runtime_1.jsxs)("div", { className: "d-flex align-items-center", children: [tab.iconClassName && (
|
|
246
|
+
}, children: [(0, jsx_runtime_1.jsxs)("div", { className: "d-flex align-items-center", children: [tab.iconClassName && (0, jsx_runtime_1.jsx)(MenuTabIcon, { tab: tab }), (0, jsx_runtime_1.jsx)("span", { children: tab.title })] }), (0, jsx_runtime_1.jsx)("button", { type: "button", className: "btn btn-sm p-0 ms-3", style: { width: "32px", height: "32px", fontSize: "20px" }, onClick: (e) => {
|
|
245
247
|
e.stopPropagation();
|
|
246
248
|
onClose(tab.tabId);
|
|
247
249
|
}, children: (0, jsx_runtime_1.jsx)("i", { className: "bi-x" }) })] }, tab.tabId)))] })) }))] })] }), showMenuDropdown && ((0, jsx_runtime_1.jsx)("div", { className: "position-fixed w-100 h-100", style: { top: 0, left: 0, zIndex: 999 }, onClick: closeMenu }))] }));
|
|
248
250
|
}
|
|
251
|
+
/** A tab's icon in the phone's tab menu, in its app's color. */
|
|
252
|
+
function MenuTabIcon({ tab }) {
|
|
253
|
+
const color = (0, tab_color_1.useTabIconColorClass)(tab);
|
|
254
|
+
return (0, jsx_runtime_1.jsx)("i", { className: `${tab.iconClassName} me-3 ${color}`, style: { fontSize: "20px" } });
|
|
255
|
+
}
|
|
249
256
|
function TabHeader({ tab, isActive, onSwitch, onClose, colorMode }) {
|
|
250
257
|
const isLight = colorMode === "light";
|
|
258
|
+
const iconColor = (0, tab_color_1.useTabIconColorClass)(tab);
|
|
251
259
|
const activeClass = isLight ? "" : isActive ? "bg-secondary" : "bg-dark";
|
|
252
260
|
return ((0, jsx_runtime_1.jsxs)("div", { className: `peers-tab ${isActive ? "peers-tab-active" : ""} d-flex align-items-center px-2 py-1 user-select-none ${activeClass}`, style: {
|
|
253
261
|
cursor: "pointer",
|
|
@@ -273,7 +281,7 @@ function TabHeader({ tab, isActive, onSwitch, onClose, colorMode }) {
|
|
|
273
281
|
if (!isActive && !isLight) {
|
|
274
282
|
e.currentTarget.style.backgroundColor = "#343a40";
|
|
275
283
|
}
|
|
276
|
-
}, onClick: () => onSwitch(tab.tabId), children: [tab.iconClassName && (0, jsx_runtime_1.jsx)("i", { className: `${tab.iconClassName} me-2` }), (0, jsx_runtime_1.jsx)("span", { className: "text-truncate", style: { maxWidth: "120px", fontSize: "12px" }, children: tab.title }), tab.tabId !== "launcher" && ((0, jsx_runtime_1.jsx)("button", { type: "button", className: "btn p-0 ms-1 opacity-75 hover-opacity-100", style: {
|
|
284
|
+
}, onClick: () => onSwitch(tab.tabId), children: [tab.iconClassName && (0, jsx_runtime_1.jsx)("i", { className: `${tab.iconClassName} me-2 ${iconColor}` }), (0, jsx_runtime_1.jsx)("span", { className: "text-truncate", style: { maxWidth: "120px", fontSize: "12px" }, children: tab.title }), tab.tabId !== "launcher" && ((0, jsx_runtime_1.jsx)("button", { type: "button", className: "btn p-0 ms-1 opacity-75 hover-opacity-100", style: {
|
|
277
285
|
width: "14px",
|
|
278
286
|
height: "14px",
|
|
279
287
|
fontSize: "11px",
|
package/dist/theme.css
CHANGED
|
@@ -159,6 +159,38 @@
|
|
|
159
159
|
margin-right: 3px;
|
|
160
160
|
}
|
|
161
161
|
|
|
162
|
+
/* A mention source's palette color (a label's, say), from its `color` setting. */
|
|
163
|
+
.peers-mention-icon[data-color="blue"] {
|
|
164
|
+
color: var(--peers-app-blue-bg);
|
|
165
|
+
}
|
|
166
|
+
.peers-mention-icon[data-color="teal"] {
|
|
167
|
+
color: var(--peers-app-teal-bg);
|
|
168
|
+
}
|
|
169
|
+
.peers-mention-icon[data-color="red"] {
|
|
170
|
+
color: var(--peers-app-red-bg);
|
|
171
|
+
}
|
|
172
|
+
.peers-mention-icon[data-color="amber"] {
|
|
173
|
+
color: var(--peers-app-amber-bg);
|
|
174
|
+
}
|
|
175
|
+
.peers-mention-icon[data-color="purple"] {
|
|
176
|
+
color: var(--peers-app-purple-bg);
|
|
177
|
+
}
|
|
178
|
+
.peers-mention-icon[data-color="orange"] {
|
|
179
|
+
color: var(--peers-app-orange-bg);
|
|
180
|
+
}
|
|
181
|
+
.peers-mention-icon[data-color="green"] {
|
|
182
|
+
color: var(--peers-app-green-bg);
|
|
183
|
+
}
|
|
184
|
+
.peers-mention-icon[data-color="pink"] {
|
|
185
|
+
color: var(--peers-app-pink-bg);
|
|
186
|
+
}
|
|
187
|
+
.peers-mention-icon[data-color="violet"] {
|
|
188
|
+
color: var(--peers-app-violet-bg);
|
|
189
|
+
}
|
|
190
|
+
.peers-mention-icon[data-color="slate"] {
|
|
191
|
+
color: var(--peers-app-slate-bg);
|
|
192
|
+
}
|
|
193
|
+
|
|
162
194
|
.peers-mention-done {
|
|
163
195
|
opacity: 0.7;
|
|
164
196
|
text-decoration: line-through;
|
|
@@ -444,6 +476,11 @@
|
|
|
444
476
|
--peers-tile-border: var(--peers-app-system-border);
|
|
445
477
|
}
|
|
446
478
|
|
|
479
|
+
/* A tab's icon in the tab strip: its app's color from the Apps screen (tab-color.ts). */
|
|
480
|
+
.peers-tab-icon {
|
|
481
|
+
color: var(--peers-tile-bg);
|
|
482
|
+
}
|
|
483
|
+
|
|
447
484
|
/* An app's icon: a rounded square in its color. Size it with --peers-tile-size. */
|
|
448
485
|
.peers-app-icon {
|
|
449
486
|
--peers-tile-size: 66px;
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import type { IUIContractDeclaration } from "@peers-app/peers-sdk";
|
|
2
|
+
import type { IHostUIContractClient, IHostUIContractOptions, IPieceHandle } from "./types";
|
|
3
|
+
/**
|
|
4
|
+
* A client for a UI contract, to embed its pieces: `<Piece of={client.pieces.picker} …>`. It's
|
|
5
|
+
* made like an API contract client, and its group and provider apply to every piece.
|
|
6
|
+
*
|
|
7
|
+
* ```tsx
|
|
8
|
+
* import type { LabelPickerUI } from "../contracts/label-picker.v1"; // types only
|
|
9
|
+
* const labelPicker = hostUIContract<typeof LabelPickerUI>(labelPickerUIId, 1, { dataContextId: task.groupId });
|
|
10
|
+
* <Piece of={labelPicker.pieces.picker} props={{ itemId: task.taskId }} anchor={plus} open={open} onClose={close} />
|
|
11
|
+
* ```
|
|
12
|
+
*
|
|
13
|
+
* The package must consume the UI contract (`pkg.consumes(LabelPickerUI, { optional: true })`).
|
|
14
|
+
* Making a client loads nothing; a piece's provider UI loads when it first shows.
|
|
15
|
+
*
|
|
16
|
+
* @param contractId - The UI contract's id, or its declaration.
|
|
17
|
+
* @param version - The version the screen consumes (omit when passing a declaration).
|
|
18
|
+
* @param options - The group (default: the active one) and, for a hub, one provider.
|
|
19
|
+
*/
|
|
20
|
+
export declare function hostUIContract<T extends IUIContractDeclaration<any, any, any>>(contract: T, options?: IHostUIContractOptions): IHostUIContractClient<T>;
|
|
21
|
+
export declare function hostUIContract<T = unknown>(contractId: string, version: number, options?: IHostUIContractOptions): IHostUIContractClient<T>;
|
|
22
|
+
/**
|
|
23
|
+
* A stable string for a handle, for effects and caches: its UI contract version, piece, provider
|
|
24
|
+
* and named group.
|
|
25
|
+
*
|
|
26
|
+
* @param handle - A piece handle.
|
|
27
|
+
*/
|
|
28
|
+
export declare function pieceHandleKey(handle: IPieceHandle): string;
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.hostUIContract = hostUIContract;
|
|
4
|
+
exports.pieceHandleKey = pieceHandleKey;
|
|
5
|
+
function hostUIContract(contractOrId, versionOrOptions, maybeOptions) {
|
|
6
|
+
const declared = typeof contractOrId === "object" ? contractOrId : undefined;
|
|
7
|
+
const contractId = declared ? declared.contractId : contractOrId;
|
|
8
|
+
const version = declared ? declared.version : versionOrOptions;
|
|
9
|
+
const options = (declared ? versionOrOptions : maybeOptions);
|
|
10
|
+
if (typeof contractId !== "string" || !Number.isInteger(version) || version < 1) {
|
|
11
|
+
throw new Error("hostUIContract takes a UI contract's id and version, or its declaration");
|
|
12
|
+
}
|
|
13
|
+
const handles = new Map();
|
|
14
|
+
const handle = (name) => {
|
|
15
|
+
let found = handles.get(name);
|
|
16
|
+
if (!found) {
|
|
17
|
+
found = Object.freeze({
|
|
18
|
+
kind: "piece-handle",
|
|
19
|
+
contractId,
|
|
20
|
+
version,
|
|
21
|
+
name,
|
|
22
|
+
...(options?.dataContextId === undefined ? {} : { dataContextId: options.dataContextId }),
|
|
23
|
+
...(options?.providerPackageId ? { providerPackageId: options.providerPackageId } : {}),
|
|
24
|
+
});
|
|
25
|
+
handles.set(name, found);
|
|
26
|
+
}
|
|
27
|
+
return found;
|
|
28
|
+
};
|
|
29
|
+
// Piece names come from the declaration's type, so any name gets a handle; a piece the
|
|
30
|
+
// provider doesn't declare shows the `failed` fallback.
|
|
31
|
+
const pieces = new Proxy({}, {
|
|
32
|
+
get: (_target, name) => (typeof name === "string" ? handle(name) : undefined),
|
|
33
|
+
});
|
|
34
|
+
return Object.freeze({ contractId, version, pieces });
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* A stable string for a handle, for effects and caches: its UI contract version, piece, provider
|
|
38
|
+
* and named group.
|
|
39
|
+
*
|
|
40
|
+
* @param handle - A piece handle.
|
|
41
|
+
*/
|
|
42
|
+
function pieceHandleKey(handle) {
|
|
43
|
+
const group = typeof handle.dataContextId === "string" ? handle.dataContextId : "";
|
|
44
|
+
return `${handle.contractId}@${handle.version}/${handle.name}|${handle.providerPackageId ?? ""}|${group}`;
|
|
45
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import type { IPieceImplementation, IUIContractDeclaration, UIContractPieceNamesOf } from "@peers-app/peers-sdk";
|
|
2
|
+
import type React from "react";
|
|
3
|
+
import type { PieceComponentProps } from "./types";
|
|
4
|
+
/**
|
|
5
|
+
* Implement one piece of a UI contract the package provides, for its UI bundle. Pass the result
|
|
6
|
+
* in `exportUIs({ uis, pieces: [...] })` in `src/uis.ts`; the package's own screens can render
|
|
7
|
+
* the same component directly, so there's one copy.
|
|
8
|
+
*
|
|
9
|
+
* ```tsx
|
|
10
|
+
* import type { LabelPickerUI } from "../ui-contracts"; // types only
|
|
11
|
+
* function LabelPicker({ props, emit, close, groupId }: PieceComponentProps<typeof LabelPickerUI, "picker">) { … }
|
|
12
|
+
* export const PickerPiece = implementPiece<typeof LabelPickerUI, "picker">(labelPickerUIId, 1, "picker", LabelPicker);
|
|
13
|
+
* ```
|
|
14
|
+
*
|
|
15
|
+
* Import the UI contract's declaration as a type only, so its code stays out of the UI bundle.
|
|
16
|
+
*
|
|
17
|
+
* @param contractId - The UI contract's id.
|
|
18
|
+
* @param version - The UI contract version this implements (the one the package provides).
|
|
19
|
+
* @param name - The piece's name.
|
|
20
|
+
* @param component - The component: it gets the embedder's props, `emit`, `close`, and the group.
|
|
21
|
+
*/
|
|
22
|
+
export declare function implementPiece<T extends IUIContractDeclaration<any, any, any>, N extends UIContractPieceNamesOf<T> = UIContractPieceNamesOf<T>>(contractId: string, version: number, name: N, component: React.ComponentType<PieceComponentProps<T, N>>): IPieceImplementation;
|
|
23
|
+
/** The key a piece's component is registered under: its UI contract version and its name. */
|
|
24
|
+
export declare function pieceKey(contractId: string, version: number, name: string): string;
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.implementPiece = implementPiece;
|
|
4
|
+
exports.pieceKey = pieceKey;
|
|
5
|
+
/**
|
|
6
|
+
* Implement one piece of a UI contract the package provides, for its UI bundle. Pass the result
|
|
7
|
+
* in `exportUIs({ uis, pieces: [...] })` in `src/uis.ts`; the package's own screens can render
|
|
8
|
+
* the same component directly, so there's one copy.
|
|
9
|
+
*
|
|
10
|
+
* ```tsx
|
|
11
|
+
* import type { LabelPickerUI } from "../ui-contracts"; // types only
|
|
12
|
+
* function LabelPicker({ props, emit, close, groupId }: PieceComponentProps<typeof LabelPickerUI, "picker">) { … }
|
|
13
|
+
* export const PickerPiece = implementPiece<typeof LabelPickerUI, "picker">(labelPickerUIId, 1, "picker", LabelPicker);
|
|
14
|
+
* ```
|
|
15
|
+
*
|
|
16
|
+
* Import the UI contract's declaration as a type only, so its code stays out of the UI bundle.
|
|
17
|
+
*
|
|
18
|
+
* @param contractId - The UI contract's id.
|
|
19
|
+
* @param version - The UI contract version this implements (the one the package provides).
|
|
20
|
+
* @param name - The piece's name.
|
|
21
|
+
* @param component - The component: it gets the embedder's props, `emit`, `close`, and the group.
|
|
22
|
+
*/
|
|
23
|
+
function implementPiece(contractId, version, name, component) {
|
|
24
|
+
if (typeof contractId !== "string" || !Number.isInteger(version) || version < 1) {
|
|
25
|
+
throw new Error("implementPiece takes a UI contract's id and a positive integer version");
|
|
26
|
+
}
|
|
27
|
+
if (typeof name !== "string" || !name) {
|
|
28
|
+
throw new Error("implementPiece takes the piece's name");
|
|
29
|
+
}
|
|
30
|
+
if (typeof component !== "function" && typeof component !== "object") {
|
|
31
|
+
throw new Error(`implementPiece: piece "${name}" needs a component`);
|
|
32
|
+
}
|
|
33
|
+
return Object.freeze({
|
|
34
|
+
kind: "piece-implementation",
|
|
35
|
+
contractId,
|
|
36
|
+
version,
|
|
37
|
+
name,
|
|
38
|
+
component: component,
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
/** The key a piece's component is registered under: its UI contract version and its name. */
|
|
42
|
+
function pieceKey(contractId, version, name) {
|
|
43
|
+
return `${contractId}@${version}/${name}`;
|
|
44
|
+
}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export { hostUIContract } from "./host-ui-contract";
|
|
2
|
+
export { implementPiece } from "./implement-piece";
|
|
3
|
+
export { type IMockPiece, mockPiece } from "./mock-piece";
|
|
4
|
+
export { type IPieceProps, type IPieceSize, Piece, type PieceState, usePiece, usePieceSize, } from "./piece";
|
|
5
|
+
export type { PopoverAnchor } from "./popover-surface";
|
|
6
|
+
export type { IHostUIContractClient, IHostUIContractOptions, IPieceHandle, IPieceOpenTarget, IPieceUnavailable, PieceComponentProps, PieceEmitters, PieceHandlers, PieceUnavailableReason, } from "./types";
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.usePieceSize = exports.usePiece = exports.Piece = exports.mockPiece = exports.implementPiece = exports.hostUIContract = void 0;
|
|
4
|
+
// UI contracts: a package's screens embed another package's UI pieces by contract, not by
|
|
5
|
+
// component id. The provider implements its pieces in its UI bundle (`implementPiece`); a
|
|
6
|
+
// consumer embeds them (`hostUIContract`, `<Piece>`) and gets a fallback when they can't show.
|
|
7
|
+
// See docs/Packages/ui-contracts.md.
|
|
8
|
+
var host_ui_contract_1 = require("./host-ui-contract");
|
|
9
|
+
Object.defineProperty(exports, "hostUIContract", { enumerable: true, get: function () { return host_ui_contract_1.hostUIContract; } });
|
|
10
|
+
var implement_piece_1 = require("./implement-piece");
|
|
11
|
+
Object.defineProperty(exports, "implementPiece", { enumerable: true, get: function () { return implement_piece_1.implementPiece; } });
|
|
12
|
+
var mock_piece_1 = require("./mock-piece");
|
|
13
|
+
Object.defineProperty(exports, "mockPiece", { enumerable: true, get: function () { return mock_piece_1.mockPiece; } });
|
|
14
|
+
var piece_1 = require("./piece");
|
|
15
|
+
Object.defineProperty(exports, "Piece", { enumerable: true, get: function () { return piece_1.Piece; } });
|
|
16
|
+
Object.defineProperty(exports, "usePiece", { enumerable: true, get: function () { return piece_1.usePiece; } });
|
|
17
|
+
Object.defineProperty(exports, "usePieceSize", { enumerable: true, get: function () { return piece_1.usePieceSize; } });
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import type { ContractPieceKind, IField } from "@peers-app/peers-sdk";
|
|
2
|
+
import type { IPieceHandle, PieceComponent } from "./types";
|
|
3
|
+
/** What a test can do with a stand-in piece from {@link mockPiece}. */
|
|
4
|
+
export interface IMockPiece {
|
|
5
|
+
/** The props it was last drawn with, or undefined before it drew. */
|
|
6
|
+
readonly props: Record<string, unknown> | undefined;
|
|
7
|
+
/** How many times it has drawn. */
|
|
8
|
+
readonly renders: number;
|
|
9
|
+
/** Send one of its emits to the embedder, as the real piece would. */
|
|
10
|
+
emit(name: string, payload?: unknown): void;
|
|
11
|
+
/** Ask the embedder to close it (a popover's `close`). */
|
|
12
|
+
close(): void;
|
|
13
|
+
/** Remove the stand-in. */
|
|
14
|
+
restore(): void;
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Stand in for a piece in a consumer's tests: `<Piece of={handle}>` draws a small placeholder
|
|
18
|
+
* (`data-testid="mock-piece-<name>"`) instead of loading a provider, and the test sends the
|
|
19
|
+
* piece's emits and reads the props it got. Declare the emits the test sends, and the props to
|
|
20
|
+
* check, as the real UI contract declares them.
|
|
21
|
+
*
|
|
22
|
+
* ```tsx
|
|
23
|
+
* const picker = mockPiece(labelPicker.pieces.picker, { kind: "popover", emits: ["chosen"] });
|
|
24
|
+
* render(<TaskRow task={task} />);
|
|
25
|
+
* picker.emit("chosen", { labelId: "l1" });
|
|
26
|
+
* ```
|
|
27
|
+
*
|
|
28
|
+
* @param handle - The piece, from the consumer's UI contract client.
|
|
29
|
+
* @param options - Its kind, props fields, emit names, and an optional component to draw.
|
|
30
|
+
*/
|
|
31
|
+
export declare function mockPiece(handle: IPieceHandle, options?: {
|
|
32
|
+
kind?: ContractPieceKind;
|
|
33
|
+
propsFields?: IField[];
|
|
34
|
+
emits?: string[];
|
|
35
|
+
component?: PieceComponent;
|
|
36
|
+
}): IMockPiece;
|