@peers-app/peers-ui 0.34.6 → 0.34.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (56) hide show
  1. package/dist/command-palette/command-palette-ui.js +14 -14
  2. package/dist/command-palette/command-palette.d.ts +10 -3
  3. package/dist/command-palette/command-palette.js +60 -6
  4. package/dist/command-palette/frame-commands.d.ts +37 -0
  5. package/dist/command-palette/frame-commands.js +43 -0
  6. package/dist/components/markdown-editor/editor.d.ts +5 -4
  7. package/dist/components/markdown-editor/editor.js +10 -145
  8. package/dist/components/markdown-editor/lexical-editor.d.ts +3 -0
  9. package/dist/components/markdown-editor/lexical-editor.js +153 -0
  10. package/dist/components/markdown-render.d.ts +8 -0
  11. package/dist/components/markdown-render.js +143 -0
  12. package/dist/components/markdown-with-mentions.d.ts +1 -1
  13. package/dist/components/markdown-with-mentions.js +7 -129
  14. package/dist/components/trust-level-dropdown.d.ts +6 -1
  15. package/dist/components/trust-level-dropdown.js +43 -14
  16. package/dist/globals.d.ts +13 -2
  17. package/dist/globals.js +24 -2
  18. package/dist/index.d.ts +2 -1
  19. package/dist/index.js +9 -1
  20. package/dist/isolated-screens/config.js +1 -5
  21. package/dist/isolated-screens/focus-relay.d.ts +24 -0
  22. package/dist/isolated-screens/focus-relay.js +104 -0
  23. package/dist/isolated-screens/frame-document.d.ts +7 -0
  24. package/dist/isolated-screens/frame-document.js +11 -1
  25. package/dist/isolated-screens/frame-permissions.d.ts +11 -0
  26. package/dist/isolated-screens/frame-permissions.js +33 -0
  27. package/dist/isolated-screens/frame-protocol.d.ts +90 -0
  28. package/dist/isolated-screens/frame-protocol.js +49 -0
  29. package/dist/isolated-screens/frame-runtime.js +115 -16
  30. package/dist/isolated-screens/frame-viewport.d.ts +9 -0
  31. package/dist/isolated-screens/frame-viewport.js +36 -0
  32. package/dist/isolated-screens/global-widgets.d.ts +74 -0
  33. package/dist/isolated-screens/global-widgets.js +270 -0
  34. package/dist/isolated-screens/isolated-screen.d.ts +57 -1
  35. package/dist/isolated-screens/isolated-screen.js +266 -15
  36. package/dist/isolated-screens/piece-frames.js +57 -5
  37. package/dist/isolated-screens/piece-reach.d.ts +24 -0
  38. package/dist/isolated-screens/piece-reach.js +40 -13
  39. package/dist/isolated-screens/widget-box.d.ts +48 -0
  40. package/dist/isolated-screens/widget-box.js +193 -0
  41. package/dist/lazy-module.d.ts +17 -0
  42. package/dist/lazy-module.js +26 -0
  43. package/dist/operator-console/console-session.js +1 -9
  44. package/dist/operator-console/operator-console-state.js +5 -1
  45. package/dist/root-layout/root-layout-host.js +3 -1
  46. package/dist/screens/groups/group-members.js +7 -17
  47. package/dist/screens/invites/accept-invite.js +15 -4
  48. package/dist/screens/packages/package-info.js +2 -1
  49. package/dist/screens/packages/package-widgets-panel.d.ts +15 -0
  50. package/dist/screens/packages/package-widgets-panel.js +64 -0
  51. package/dist/tabs-layout/tabs-state.d.ts +5 -2
  52. package/dist/tabs-layout/tabs-state.js +41 -17
  53. package/dist/ui-contracts/piece-height.d.ts +8 -2
  54. package/dist/ui-contracts/piece-height.js +6 -1
  55. package/dist/ui-contracts/piece.js +1 -1
  56. package/package.json +4 -3
@@ -0,0 +1,143 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
35
+ var __importDefault = (this && this.__importDefault) || function (mod) {
36
+ return (mod && mod.__esModule) ? mod : { "default": mod };
37
+ };
38
+ Object.defineProperty(exports, "__esModule", { value: true });
39
+ exports.MarkdownRender = void 0;
40
+ exports.mentionUrlTransform = mentionUrlTransform;
41
+ const jsx_runtime_1 = require("react/jsx-runtime");
42
+ // Markdown rendered with react-markdown and remark-gfm. It loads the first time markdown is
43
+ // drawn (`MarkdownWithMentions` in markdown-with-mentions.tsx) or `mentionUrlTransform` is
44
+ // called, not when peers-ui loads: see `lazyModule`.
45
+ const peers_sdk_1 = require("@peers-app/peers-sdk");
46
+ const react_1 = __importDefault(require("react"));
47
+ const react_markdown_1 = __importStar(require("react-markdown"));
48
+ const remark_gfm_1 = __importDefault(require("remark-gfm"));
49
+ const host_shell_consumer_1 = require("../host-shell/host-shell-consumer");
50
+ const mention_chip_1 = require("../mentions/mention-chip");
51
+ /** The text in some rendered markdown children. */
52
+ function textOf(children) {
53
+ return react_1.default.Children.toArray(children)
54
+ .map((child) => {
55
+ if (typeof child === "string" || typeof child === "number")
56
+ return String(child);
57
+ if (react_1.default.isValidElement(child)) {
58
+ return textOf(child.props.children);
59
+ }
60
+ return "";
61
+ })
62
+ .join("");
63
+ }
64
+ /** A link: a mention becomes a chip, and a web link opens in the system browser. */
65
+ const LinkRenderer = (props) => {
66
+ const { href } = props;
67
+ const mention = href ? (0, peers_sdk_1.parseMentionUrl)(href) : undefined;
68
+ if (mention)
69
+ return (0, jsx_runtime_1.jsx)(mention_chip_1.MentionChip, { ...mention, label: textOf(props.children) });
70
+ return ((0, jsx_runtime_1.jsx)("a", { href: href, onClick: (e) => {
71
+ if (href?.startsWith("http")) {
72
+ e.preventDefault();
73
+ void (0, host_shell_consumer_1.openOnHost)(href);
74
+ }
75
+ }, children: props.children }));
76
+ };
77
+ /**
78
+ * An image. `![label](peers://…)` is a mention typed right after a `!` ("Thanks![Plan](…)"),
79
+ * which the editor shows as `!` and a chip, so it renders the same here.
80
+ */
81
+ const ImageRenderer = ({ node: _node, src, alt, ...props }) => {
82
+ const mention = typeof src === "string" ? (0, peers_sdk_1.parseMentionUrl)(src) : undefined;
83
+ if (mention) {
84
+ return ((0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: ["!", (0, jsx_runtime_1.jsx)(mention_chip_1.MentionChip, { ...mention, label: alt ?? "" })] }));
85
+ }
86
+ return (0, jsx_runtime_1.jsx)("img", { src: src, alt: alt, ...props });
87
+ };
88
+ /** Text with the older `<$kind:Name:id>` mentions turned into chips (a name alone without an id). */
89
+ const processTextWithMentions = (text) => {
90
+ const parts = [];
91
+ const regex = new RegExp((0, peers_sdk_1.mentionRegex)().source, "g");
92
+ let lastIndex = 0;
93
+ for (const match of text.matchAll(regex)) {
94
+ const at = match.index ?? 0;
95
+ if (at > lastIndex)
96
+ parts.push(text.slice(lastIndex, at));
97
+ const [, , kind, name, id] = match;
98
+ const label = name.replace(/_/g, " ");
99
+ const ref = id ? (0, peers_sdk_1.parseMentionUrl)(`peers://${kind.toLowerCase()}/${id}`) : undefined;
100
+ parts.push(ref ? (0, jsx_runtime_1.jsx)(mention_chip_1.MentionChip, { ...ref, label: label }, at) : label);
101
+ lastIndex = at + match[0].length;
102
+ }
103
+ if (lastIndex < text.length)
104
+ parts.push(text.slice(lastIndex));
105
+ return parts;
106
+ };
107
+ const createElementWithMentions = (Element) => {
108
+ return ({ node: _node, ...props }) => {
109
+ return ((0, jsx_runtime_1.jsx)(Element, { ...props, children: react_1.default.Children.map(props.children, (child) => {
110
+ if (typeof child === "string") {
111
+ return processTextWithMentions(child);
112
+ }
113
+ return child;
114
+ }) }));
115
+ };
116
+ };
117
+ const components = {
118
+ p: createElementWithMentions("p"),
119
+ h1: createElementWithMentions("h1"),
120
+ h2: createElementWithMentions("h2"),
121
+ h3: createElementWithMentions("h3"),
122
+ h4: createElementWithMentions("h4"),
123
+ h5: createElementWithMentions("h5"),
124
+ h6: createElementWithMentions("h6"),
125
+ li: createElementWithMentions("li"),
126
+ a: LinkRenderer,
127
+ img: ImageRenderer,
128
+ strong: createElementWithMentions("strong"),
129
+ em: createElementWithMentions("em"),
130
+ blockquote: createElementWithMentions("blockquote"),
131
+ code: createElementWithMentions("code"),
132
+ td: createElementWithMentions("td"),
133
+ th: createElementWithMentions("th"),
134
+ };
135
+ /** {@link mentionUrlTransform}'s implementation. */
136
+ function mentionUrlTransform(url) {
137
+ return (0, peers_sdk_1.parseMentionUrl)(url) ? url : (0, react_markdown_1.defaultUrlTransform)(url);
138
+ }
139
+ /** {@link MarkdownWithMentions}'s implementation. */
140
+ const MarkdownRender = ({ content, groupId, }) => ((0, jsx_runtime_1.jsx)(mention_chip_1.MentionGroupContext.Provider, { value: groupId, children: (0, jsx_runtime_1.jsx)("div", { className: "markdown", children: (0, jsx_runtime_1.jsx)(react_markdown_1.default, { remarkPlugins: [remark_gfm_1.default], urlTransform: mentionUrlTransform,
141
+ // @ts-expect-error react-markdown's component props are narrower than these wrappers
142
+ components: components, children: content }) }) }));
143
+ exports.MarkdownRender = MarkdownRender;
@@ -1,4 +1,4 @@
1
- import React from "react";
1
+ import type React from "react";
2
2
  /**
3
3
  * Keep `peers://` mention links; every other URL gets react-markdown's default treatment, which
4
4
  * blanks `javascript:` and other unsafe schemes in text other members wrote.
@@ -1,140 +1,20 @@
1
1
  "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
- Object.defineProperty(o, "default", { enumerable: true, value: v });
15
- }) : function(o, v) {
16
- o["default"] = v;
17
- });
18
- var __importStar = (this && this.__importStar) || (function () {
19
- var ownKeys = function(o) {
20
- ownKeys = Object.getOwnPropertyNames || function (o) {
21
- var ar = [];
22
- for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
- return ar;
24
- };
25
- return ownKeys(o);
26
- };
27
- return function (mod) {
28
- if (mod && mod.__esModule) return mod;
29
- var result = {};
30
- if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
- __setModuleDefault(result, mod);
32
- return result;
33
- };
34
- })();
35
- var __importDefault = (this && this.__importDefault) || function (mod) {
36
- return (mod && mod.__esModule) ? mod : { "default": mod };
37
- };
38
2
  Object.defineProperty(exports, "__esModule", { value: true });
39
3
  exports.MarkdownWithMentions = void 0;
40
4
  exports.mentionUrlTransform = mentionUrlTransform;
41
- const jsx_runtime_1 = require("react/jsx-runtime");
42
- const peers_sdk_1 = require("@peers-app/peers-sdk");
43
- const react_1 = __importDefault(require("react"));
44
- const react_markdown_1 = __importStar(require("react-markdown"));
45
- const remark_gfm_1 = __importDefault(require("remark-gfm"));
46
- const host_shell_consumer_1 = require("../host-shell/host-shell-consumer");
47
- const mention_chip_1 = require("../mentions/mention-chip");
48
- /** The text in some rendered markdown children. */
49
- function textOf(children) {
50
- return react_1.default.Children.toArray(children)
51
- .map((child) => {
52
- if (typeof child === "string" || typeof child === "number")
53
- return String(child);
54
- if (react_1.default.isValidElement(child)) {
55
- return textOf(child.props.children);
56
- }
57
- return "";
58
- })
59
- .join("");
60
- }
61
- /** A link: a mention becomes a chip, and a web link opens in the system browser. */
62
- const LinkRenderer = (props) => {
63
- const { href } = props;
64
- const mention = href ? (0, peers_sdk_1.parseMentionUrl)(href) : undefined;
65
- if (mention)
66
- return (0, jsx_runtime_1.jsx)(mention_chip_1.MentionChip, { ...mention, label: textOf(props.children) });
67
- return ((0, jsx_runtime_1.jsx)("a", { href: href, onClick: (e) => {
68
- if (href?.startsWith("http")) {
69
- e.preventDefault();
70
- void (0, host_shell_consumer_1.openOnHost)(href);
71
- }
72
- }, children: props.children }));
73
- };
5
+ const react_1 = require("react");
6
+ const lazy_module_1 = require("../lazy-module");
74
7
  /**
75
- * An image. `![label](peers://…)` is a mention typed right after a `!` ("Thanks![Plan](…)"),
76
- * which the editor shows as `!` and a chip, so it renders the same here.
8
+ * react-markdown, remark-gfm and the renderers, loaded the first time markdown is drawn (or
9
+ * `mentionUrlTransform` is called).
77
10
  */
78
- const ImageRenderer = ({ node: _node, src, alt, ...props }) => {
79
- const mention = typeof src === "string" ? (0, peers_sdk_1.parseMentionUrl)(src) : undefined;
80
- if (mention) {
81
- return ((0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: ["!", (0, jsx_runtime_1.jsx)(mention_chip_1.MentionChip, { ...mention, label: alt ?? "" })] }));
82
- }
83
- return (0, jsx_runtime_1.jsx)("img", { src: src, alt: alt, ...props });
84
- };
85
- /** Text with the older `<$kind:Name:id>` mentions turned into chips (a name alone without an id). */
86
- const processTextWithMentions = (text) => {
87
- const parts = [];
88
- const regex = new RegExp((0, peers_sdk_1.mentionRegex)().source, "g");
89
- let lastIndex = 0;
90
- for (const match of text.matchAll(regex)) {
91
- const at = match.index ?? 0;
92
- if (at > lastIndex)
93
- parts.push(text.slice(lastIndex, at));
94
- const [, , kind, name, id] = match;
95
- const label = name.replace(/_/g, " ");
96
- const ref = id ? (0, peers_sdk_1.parseMentionUrl)(`peers://${kind.toLowerCase()}/${id}`) : undefined;
97
- parts.push(ref ? (0, jsx_runtime_1.jsx)(mention_chip_1.MentionChip, { ...ref, label: label }, at) : label);
98
- lastIndex = at + match[0].length;
99
- }
100
- if (lastIndex < text.length)
101
- parts.push(text.slice(lastIndex));
102
- return parts;
103
- };
104
- const createElementWithMentions = (Element) => {
105
- return ({ node: _node, ...props }) => {
106
- return ((0, jsx_runtime_1.jsx)(Element, { ...props, children: react_1.default.Children.map(props.children, (child) => {
107
- if (typeof child === "string") {
108
- return processTextWithMentions(child);
109
- }
110
- return child;
111
- }) }));
112
- };
113
- };
114
- const components = {
115
- p: createElementWithMentions("p"),
116
- h1: createElementWithMentions("h1"),
117
- h2: createElementWithMentions("h2"),
118
- h3: createElementWithMentions("h3"),
119
- h4: createElementWithMentions("h4"),
120
- h5: createElementWithMentions("h5"),
121
- h6: createElementWithMentions("h6"),
122
- li: createElementWithMentions("li"),
123
- a: LinkRenderer,
124
- img: ImageRenderer,
125
- strong: createElementWithMentions("strong"),
126
- em: createElementWithMentions("em"),
127
- blockquote: createElementWithMentions("blockquote"),
128
- code: createElementWithMentions("code"),
129
- td: createElementWithMentions("td"),
130
- th: createElementWithMentions("th"),
131
- };
11
+ const markdownRender = (0, lazy_module_1.lazyModule)(() => require("./markdown-render"));
132
12
  /**
133
13
  * Keep `peers://` mention links; every other URL gets react-markdown's default treatment, which
134
14
  * blanks `javascript:` and other unsafe schemes in text other members wrote.
135
15
  */
136
16
  function mentionUrlTransform(url) {
137
- return (0, peers_sdk_1.parseMentionUrl)(url) ? url : (0, react_markdown_1.defaultUrlTransform)(url);
17
+ return markdownRender().mentionUrlTransform(url);
138
18
  }
139
19
  /**
140
20
  * Render markdown (GitHub-flavored) with mentions (`[label](peers://<kind>/<id>)`, and the
@@ -144,7 +24,5 @@ function mentionUrlTransform(url) {
144
24
  * @param props.content - The markdown.
145
25
  * @param props.groupId - The group the text belongs to: mentions resolve there first.
146
26
  */
147
- const MarkdownWithMentions = ({ content, groupId, }) => ((0, jsx_runtime_1.jsx)(mention_chip_1.MentionGroupContext.Provider, { value: groupId, children: (0, jsx_runtime_1.jsx)("div", { className: "markdown", children: (0, jsx_runtime_1.jsx)(react_markdown_1.default, { remarkPlugins: [remark_gfm_1.default], urlTransform: mentionUrlTransform,
148
- // @ts-expect-error react-markdown's component props are narrower than these wrappers
149
- components: components, children: content }) }) }));
27
+ const MarkdownWithMentions = (props) => (0, react_1.createElement)(markdownRender().MarkdownRender, props);
150
28
  exports.MarkdownWithMentions = MarkdownWithMentions;
@@ -5,6 +5,11 @@ interface TrustLevelDropdownProps {
5
5
  onChange?: (newLevel: TrustLevel) => void;
6
6
  type?: "user" | "device";
7
7
  }
8
- /** Select a context-scoped user or device trust level, including the full-access Self grant. */
8
+ /**
9
+ * Select a context-scoped user or device trust level, including the full-access Self grant.
10
+ * Without a level set it shows the default (`getUserTrust`), marked as such, and once one is set
11
+ * it offers Use the default, which clears it. The signed-in user, in their Personal, is always
12
+ * Self, so for them it only shows Self.
13
+ */
9
14
  export declare const TrustLevelDropdown: ({ userId, dataContext, onChange, type, }: TrustLevelDropdownProps) => import("react/jsx-runtime").JSX.Element;
10
15
  export {};
@@ -5,10 +5,27 @@ const jsx_runtime_1 = require("react/jsx-runtime");
5
5
  const peers_sdk_1 = require("@peers-app/peers-sdk");
6
6
  const react_1 = require("react");
7
7
  const loading_indicator_1 = require("./loading-indicator");
8
- /** Select a context-scoped user or device trust level, including the full-access Self grant. */
8
+ /** The context the dropdown reads and writes: the one given, else the user's Personal. */
9
+ async function contextFor(dataContext) {
10
+ return dataContext || (await (0, peers_sdk_1.getUserContext)()).userDataContext;
11
+ }
12
+ /** The user's trust there, the default included. */
13
+ async function readTrust(userId, dataContext) {
14
+ return (0, peers_sdk_1.getUserTrust)(await contextFor(dataContext), userId);
15
+ }
16
+ /**
17
+ * Select a context-scoped user or device trust level, including the full-access Self grant.
18
+ * Without a level set it shows the default (`getUserTrust`), marked as such, and once one is set
19
+ * it offers Use the default, which clears it. The signed-in user, in their Personal, is always
20
+ * Self, so for them it only shows Self.
21
+ */
9
22
  const TrustLevelDropdown = ({ userId, dataContext, onChange, type = "user", }) => {
10
- const [trustLevel, setTrustLevelState] = (0, react_1.useState)(peers_sdk_1.TrustLevel.Unknown);
23
+ const [trust, setTrust] = (0, react_1.useState)({
24
+ level: peers_sdk_1.TrustLevel.Unknown,
25
+ explicit: false,
26
+ });
11
27
  const [loading, setLoading] = (0, react_1.useState)(true);
28
+ const trustLevel = trust.level;
12
29
  const allTrustLevelConfigs = [
13
30
  {
14
31
  value: peers_sdk_1.TrustLevel.Self,
@@ -44,24 +61,32 @@ const TrustLevelDropdown = ({ userId, dataContext, onChange, type = "user", }) =
44
61
  // Filter configs based on type
45
62
  const trustLevelConfigs = allTrustLevelConfigs.filter((config) => !config.showFor || config.showFor === type);
46
63
  (0, react_1.useEffect)(() => {
47
- async function loadTrustLevel() {
48
- const userContext = await (0, peers_sdk_1.getUserContext)();
49
- const contextToUse = dataContext || userContext.userDataContext;
50
- const level = await (0, peers_sdk_1.getUserTrustLevel)(contextToUse, userId);
51
- setTrustLevelState(level);
64
+ let current = true;
65
+ void readTrust(userId, dataContext).then((read) => {
66
+ if (!current)
67
+ return;
68
+ setTrust(read);
52
69
  setLoading(false);
53
- }
54
- loadTrustLevel();
70
+ });
71
+ return () => {
72
+ current = false;
73
+ };
55
74
  }, [userId, dataContext]);
56
75
  async function handleTrustLevelChange(newLevel) {
57
- const userContext = await (0, peers_sdk_1.getUserContext)();
58
- const contextToUse = dataContext || userContext.userDataContext;
59
- await (0, peers_sdk_1.setUserTrustLevel)(userId, newLevel, contextToUse);
60
- setTrustLevelState(newLevel);
76
+ await (0, peers_sdk_1.setUserTrustLevel)(userId, newLevel, await contextFor(dataContext));
77
+ setTrust({ level: newLevel, explicit: true });
61
78
  if (onChange) {
62
79
  onChange(newLevel);
63
80
  }
64
81
  }
82
+ /** Clear the level set here, so the default applies again. */
83
+ async function restoreDefault() {
84
+ const context = await contextFor(dataContext);
85
+ await (0, peers_sdk_1.UserTrustLevels)(context).delete(userId);
86
+ const restored = await (0, peers_sdk_1.getUserTrust)(context, userId);
87
+ setTrust(restored);
88
+ onChange?.(restored.level);
89
+ }
65
90
  // Find current config
66
91
  const sortedConfigs = trustLevelConfigs.sort((a, b) => a.value - b.value);
67
92
  let currentConfig = { color: "secondary", icon: "bi-shield", text: "Unknown" };
@@ -76,6 +101,10 @@ const TrustLevelDropdown = ({ userId, dataContext, onChange, type = "user", }) =
76
101
  if (loading) {
77
102
  return (0, jsx_runtime_1.jsx)(loading_indicator_1.LoadingIndicator, {});
78
103
  }
79
- return ((0, jsx_runtime_1.jsxs)("div", { className: "dropdown", children: [(0, jsx_runtime_1.jsxs)("button", { className: `btn btn-sm btn-${currentConfig.color} dropdown-toggle d-flex align-items-center gap-1`, type: "button", "data-bs-toggle": "dropdown", "data-bs-auto-close": "true", "data-bs-popper-config": '{"strategy":"fixed"}', "aria-expanded": "false", children: [(0, jsx_runtime_1.jsx)("i", { className: currentConfig.icon }), currentConfig.text] }), (0, jsx_runtime_1.jsx)("ul", { className: "dropdown-menu", children: trustLevelConfigs.map((config) => ((0, jsx_runtime_1.jsx)("li", { children: (0, jsx_runtime_1.jsx)("button", { className: "dropdown-item p-2", onClick: () => handleTrustLevelChange(config.value), children: (0, jsx_runtime_1.jsxs)("span", { className: `badge bg-${config.color} d-flex align-items-center gap-2 w-100 py-2 px-3 fs-6 ${trustLevel === config.value ? "border border-dark border-2" : ""}`, children: [(0, jsx_runtime_1.jsx)("i", { className: config.icon }), config.text] }) }) }, config.value))) })] }));
104
+ // The signed-in user in their Personal: Self whatever is chosen, so there's nothing to choose.
105
+ if (trustLevel === peers_sdk_1.TrustLevel.Self && !trust.explicit) {
106
+ return ((0, jsx_runtime_1.jsxs)("span", { className: `btn btn-sm btn-${currentConfig.color} disabled d-inline-flex align-items-center gap-1`, "aria-disabled": "true", children: [(0, jsx_runtime_1.jsx)("i", { className: currentConfig.icon }), currentConfig.text] }));
107
+ }
108
+ return ((0, jsx_runtime_1.jsxs)("div", { className: "dropdown", children: [(0, jsx_runtime_1.jsxs)("button", { className: `btn btn-sm btn-${currentConfig.color} dropdown-toggle d-flex align-items-center gap-1`, type: "button", "data-bs-toggle": "dropdown", "data-bs-auto-close": "true", "data-bs-popper-config": '{"strategy":"fixed"}', "aria-expanded": "false", children: [(0, jsx_runtime_1.jsx)("i", { className: currentConfig.icon }), currentConfig.text, !trust.explicit && " (default)"] }), trust.knownFrom && ((0, jsx_runtime_1.jsxs)("small", { className: "text-muted d-block mt-1", children: ["Known from ", trust.knownFrom.toLocaleDateString()] })), (0, jsx_runtime_1.jsxs)("ul", { className: "dropdown-menu", children: [trustLevelConfigs.map((config) => ((0, jsx_runtime_1.jsx)("li", { children: (0, jsx_runtime_1.jsx)("button", { className: "dropdown-item p-2", onClick: () => handleTrustLevelChange(config.value), children: (0, jsx_runtime_1.jsxs)("span", { className: `badge bg-${config.color} d-flex align-items-center gap-2 w-100 py-2 px-3 fs-6 ${trustLevel === config.value ? "border border-dark border-2" : ""}`, children: [(0, jsx_runtime_1.jsx)("i", { className: config.icon }), config.text] }) }) }, config.value))), trust.explicit && ((0, jsx_runtime_1.jsx)("li", { children: (0, jsx_runtime_1.jsx)("button", { className: "dropdown-item p-2", onClick: () => void restoreDefault(), children: "Use the default" }) }))] })] }));
80
109
  };
81
110
  exports.TrustLevelDropdown = TrustLevelDropdown;
package/dist/globals.d.ts CHANGED
@@ -9,10 +9,21 @@ export declare const mainContentPath: import("@peers-app/peers-sdk").Observable<
9
9
  export declare function queryParam(name: string, value?: string): string;
10
10
  /** Signed profile for the active user after {@link loadGlobals}. */
11
11
  export declare let me: IUser;
12
- /** Current browser viewport width. */
12
+ /**
13
+ * The Peers window's width. In a global widget's frame, which is only as big as what the widget
14
+ * draws, it's still the window's, so a widget lays itself out and clamps a drag to the window.
15
+ */
13
16
  export declare const windowWidth: import("@peers-app/peers-sdk").Observable<number>;
14
- /** Current browser viewport height. */
17
+ /** The Peers window's height; in a global widget's frame, the window's too. */
15
18
  export declare const windowHeight: import("@peers-app/peers-sdk").Observable<number>;
19
+ /**
20
+ * In a global widget's frame: the Peers window's size, which the host sends, stands for this
21
+ * frame's own from now on. Only the frame runtime calls it.
22
+ *
23
+ * @param width - The window's width.
24
+ * @param height - The window's height.
25
+ */
26
+ export declare function followHostViewport(width: number, height: number): void;
16
27
  /** True when the viewport uses wide-screen navigation. */
17
28
  export declare const isDesktop: import("@peers-app/peers-sdk").Observable<boolean>;
18
29
  /** Enabled groups available to the active user. */
package/dist/globals.js CHANGED
@@ -2,6 +2,7 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.groups = exports.isDesktop = exports.windowHeight = exports.windowWidth = exports.me = exports.mainContentPath = exports._mainContentPath = exports.packageReloaded = void 0;
4
4
  exports.queryParam = queryParam;
5
+ exports.followHostViewport = followHostViewport;
5
6
  exports.initializeHashNavigation = initializeHashNavigation;
6
7
  exports.loadGlobals = loadGlobals;
7
8
  const peers_sdk_1 = require("@peers-app/peers-sdk");
@@ -63,14 +64,35 @@ function queryParam(name, value) {
63
64
  }
64
65
  /** Signed profile for the active user after {@link loadGlobals}. */
65
66
  exports.me = null;
66
- /** Current browser viewport width. */
67
+ /**
68
+ * The Peers window's width. In a global widget's frame, which is only as big as what the widget
69
+ * draws, it's still the window's, so a widget lays itself out and clamps a drag to the window.
70
+ */
67
71
  exports.windowWidth = (0, peers_sdk_1.observable)(window.innerWidth); //.extend({ rateLimit: 500 });
68
- /** Current browser viewport height. */
72
+ /** The Peers window's height; in a global widget's frame, the window's too. */
69
73
  exports.windowHeight = (0, peers_sdk_1.observable)(window.innerHeight); //.extend({ rateLimit: 500 });
74
+ /** Set in a global widget's frame: the window's size comes from the host, not this frame's. */
75
+ let viewportFromHost = false;
70
76
  window.addEventListener("resize", (_ev) => {
77
+ if (viewportFromHost)
78
+ return;
71
79
  (0, exports.windowWidth)(window.innerWidth);
72
80
  (0, exports.windowHeight)(window.innerHeight);
73
81
  });
82
+ /**
83
+ * In a global widget's frame: the Peers window's size, which the host sends, stands for this
84
+ * frame's own from now on. Only the frame runtime calls it.
85
+ *
86
+ * @param width - The window's width.
87
+ * @param height - The window's height.
88
+ */
89
+ function followHostViewport(width, height) {
90
+ viewportFromHost = true;
91
+ if ((0, exports.windowWidth)() !== width)
92
+ (0, exports.windowWidth)(width);
93
+ if ((0, exports.windowHeight)() !== height)
94
+ (0, exports.windowHeight)(height);
95
+ }
74
96
  /** True when the viewport uses wide-screen navigation. */
75
97
  exports.isDesktop = (0, peers_sdk_1.computed)(() => {
76
98
  // return windowWidth() > 1200;
package/dist/index.d.ts CHANGED
@@ -1,3 +1,4 @@
1
+ export { type Command, executeCommand, registerCommand, unregisterCommand, } from "./command-palette/command-palette";
1
2
  export * from "./components/color-picker";
2
3
  export * from "./components/data-grid";
3
4
  export * from "./components/icon";
@@ -12,7 +13,7 @@ export * from "./components/responsive-section-nav";
12
13
  export * from "./components/sortable-list";
13
14
  export * from "./components/tabs";
14
15
  export { Typeahead, type TypeaheadItem } from "./components/typeahead";
15
- export { isDesktop, mainContentPath } from "./globals";
16
+ export { isDesktop, mainContentPath, windowHeight, windowWidth } from "./globals";
16
17
  export * from "./graph/ring-layout";
17
18
  export * from "./groups";
18
19
  export * from "./hooks";
package/dist/index.js CHANGED
@@ -14,7 +14,13 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
14
  for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
15
  };
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
- exports.inspectUI = exports.FRAME_SELECTOR_PREFIX = exports.actOnUI = exports.updateActiveTabTitle = exports.goToTabPath = exports.closeCurrentTab = exports.activeTabs = exports.activeTabId = exports.setRootLayout = exports.selectedRootLayoutId = exports.getRootLayouts = exports.getRootLayout = exports.DEFAULT_ROOT_LAYOUT_ID = exports.TabsLayoutApp = exports.RootLayoutHost = exports.LayoutPicker = exports.unregisterGlobalOverlay = exports.registerGlobalOverlay = exports.globalOverlays = exports.notificationHostControls = exports.openMention = exports.useMentionPlace = exports.MentionGroupContext = exports.MentionChip = exports.openLink = exports.mainContentPath = exports.isDesktop = exports.Typeahead = exports.MarkdownEditor = exports.configureIconSearchIndexes = void 0;
17
+ exports.inspectUI = exports.FRAME_SELECTOR_PREFIX = exports.actOnUI = exports.updateActiveTabTitle = exports.goToTabPath = exports.closeCurrentTab = exports.activeTabs = exports.activeTabId = exports.setRootLayout = exports.selectedRootLayoutId = exports.getRootLayouts = exports.getRootLayout = exports.DEFAULT_ROOT_LAYOUT_ID = exports.TabsLayoutApp = exports.RootLayoutHost = exports.LayoutPicker = exports.unregisterGlobalOverlay = exports.registerGlobalOverlay = exports.globalOverlays = exports.notificationHostControls = exports.openMention = exports.useMentionPlace = exports.MentionGroupContext = exports.MentionChip = exports.openLink = exports.windowWidth = exports.windowHeight = exports.mainContentPath = exports.isDesktop = exports.Typeahead = exports.MarkdownEditor = exports.configureIconSearchIndexes = exports.unregisterCommand = exports.registerCommand = exports.executeCommand = void 0;
18
+ // Commands in the command palette, with optional shortcuts. From a package's frame they go to the
19
+ // host's palette, under the package's name.
20
+ var command_palette_1 = require("./command-palette/command-palette");
21
+ Object.defineProperty(exports, "executeCommand", { enumerable: true, get: function () { return command_palette_1.executeCommand; } });
22
+ Object.defineProperty(exports, "registerCommand", { enumerable: true, get: function () { return command_palette_1.registerCommand; } });
23
+ Object.defineProperty(exports, "unregisterCommand", { enumerable: true, get: function () { return command_palette_1.unregisterCommand; } });
18
24
  __exportStar(require("./components/color-picker"), exports);
19
25
  __exportStar(require("./components/data-grid"), exports);
20
26
  __exportStar(require("./components/icon"), exports);
@@ -34,6 +40,8 @@ Object.defineProperty(exports, "Typeahead", { enumerable: true, get: function ()
34
40
  var globals_1 = require("./globals");
35
41
  Object.defineProperty(exports, "isDesktop", { enumerable: true, get: function () { return globals_1.isDesktop; } });
36
42
  Object.defineProperty(exports, "mainContentPath", { enumerable: true, get: function () { return globals_1.mainContentPath; } });
43
+ Object.defineProperty(exports, "windowHeight", { enumerable: true, get: function () { return globals_1.windowHeight; } });
44
+ Object.defineProperty(exports, "windowWidth", { enumerable: true, get: function () { return globals_1.windowWidth; } });
37
45
  // Groups: names, colors and icons from System Groups, and the dialog that edits a group's look.
38
46
  __exportStar(require("./graph/ring-layout"), exports);
39
47
  __exportStar(require("./groups"), exports);
@@ -12,13 +12,9 @@ let runtimeSource;
12
12
  * can't do for it yet. The list only shrinks: each entry goes when its reason does.
13
13
  */
14
14
  exports.SHARED_WINDOW_PACKAGES = new Map([
15
- [
16
- "00mh0wlipjixk2gqmurbwee0o",
17
- "Tasks: its timer overlay shows over every app (global widgets, task 00mwiaq9279nj7u3a8cchwjin)",
18
- ],
19
15
  [
20
16
  "00mwi9ux5ate4rpcr26wdedph",
21
- "Operator: its overlay shows over every app and listens to keys in any app (global widgets), and it uses the microphone",
17
+ "Operator: Talk uses the microphone, which a frame's opaque origin can't open (Chromium and WebKit refuse it even with allow=microphone), and its settings write a secret variable (the OpenAI key), which frames can't. Its declared widget draws in the window.",
22
18
  ],
23
19
  [
24
20
  "00mp0gayf4f9hotacqsobyv6w",
@@ -0,0 +1,24 @@
1
+ /** Which end of a piece focus enters at: its first control (Tab) or its last (Shift+Tab). */
2
+ export type FocusEdge = "first" | "last";
3
+ /** Which way focus leaves a piece: to the control after its slot, or the one before it. */
4
+ export type FocusDirection = "next" | "previous";
5
+ /** The elements Tab stops at in a document, in document order (positive tabindex aside). */
6
+ export declare function tabbables(doc: Document): HTMLElement[];
7
+ /**
8
+ * Focus a document's first or last control.
9
+ *
10
+ * @returns Whether it had one.
11
+ */
12
+ export declare function focusEdge(doc: Document, edge: FocusEdge): boolean;
13
+ /**
14
+ * Whether Tab (or Shift+Tab) on the focused element leaves the document's controls: from its last
15
+ * control, its first, or from nothing focusable.
16
+ */
17
+ export declare function tabLeaves(doc: Document, backwards: boolean): boolean;
18
+ /** The edge focus enters a slot at, from the element focus came from. */
19
+ export declare function edgeEnteredFrom(slot: Element, from: Element | null): FocusEdge;
20
+ /**
21
+ * Focus the control after (or before) a slot in its document, leaving the slot itself out. With
22
+ * none there, focus leaves the slot.
23
+ */
24
+ export declare function focusBeside(slot: HTMLElement, direction: FocusDirection): void;