@domicile-desktop/component-library 0.0.0-alpha-6bfeb689abcc → 0.0.0-alpha-dccbffbc7543

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/package.json CHANGED
@@ -2,8 +2,8 @@
2
2
  "dependencies": {
3
3
  "@base-ui/react": "^1.8.0",
4
4
  "@cprussin/option-result": "^2.0.1",
5
- "@domicile-desktop/sdk": "0.0.0-alpha-6bfeb689abcc",
6
- "@domicile-desktop/system-apps": "0.0.0-alpha-6bfeb689abcc",
5
+ "@domicile-desktop/sdk": "0.0.0-alpha-dccbffbc7543",
6
+ "@domicile-desktop/system-apps": "0.0.0-alpha-dccbffbc7543",
7
7
  "@phosphor-icons/react": "^2.1.10"
8
8
  },
9
9
  "description": "React components and the Panda CSS design system that Domicile's shells are built from.",
@@ -106,5 +106,5 @@
106
106
  "test:unit": "bun test"
107
107
  },
108
108
  "type": "module",
109
- "version": "0.0.0-alpha-6bfeb689abcc"
109
+ "version": "0.0.0-alpha-dccbffbc7543"
110
110
  }
@@ -9,7 +9,7 @@ import { AppWindowIcon } from "@phosphor-icons/react/dist/ssr/AppWindow";
9
9
  import { GlobeIcon } from "@phosphor-icons/react/dist/ssr/Globe";
10
10
  import { MonitorIcon } from "@phosphor-icons/react/dist/ssr/Monitor";
11
11
  import type { PointerEvent, ReactNode } from "react";
12
- import { useState } from "react";
12
+ import { useEffect, useState } from "react";
13
13
  import { css } from "../../styled-system/css";
14
14
  import { flex } from "../../styled-system/patterns";
15
15
  import { Button } from "../Button/Button";
@@ -57,7 +57,8 @@ type Choice = { icon: ReactNode; name: string; pick: Pick };
57
57
  * Picks what to save of a frozen desk: all of it, a screen, a window, or an
58
58
  * area dragged over it. A window the shell shows is its whole frame on the
59
59
  * desk; one it does not show, such as a hidden tab, is saved from its own
60
- * last frame. Dismissing it cancels.
60
+ * last frame. Ctrl+C copies the pick to the clipboard instead of saving it.
61
+ * Dismissing it cancels.
61
62
  */
62
63
  export const ScreenshotDialog = ({
63
64
  answer,
@@ -101,6 +102,18 @@ export const ScreenshotDialog = ({
101
102
  if (pick === undefined) {
102
103
  throw new Error(`no screenshot choice ${String(picked)}`);
103
104
  }
105
+ useEffect(() => {
106
+ const copy = (event: KeyboardEvent) => {
107
+ if (isCopy(event)) {
108
+ event.preventDefault();
109
+ answer(answerOf(pick, true));
110
+ }
111
+ };
112
+ document.addEventListener("keydown", copy);
113
+ return () => {
114
+ document.removeEventListener("keydown", copy);
115
+ };
116
+ }, [answer, pick]);
104
117
  const button = (choice: Choice, index: number) => (
105
118
  <Button
106
119
  aria-pressed={index === picked}
@@ -137,7 +150,7 @@ export const ScreenshotDialog = ({
137
150
  </Button>
138
151
  <Button
139
152
  onClick={() => {
140
- answer(answerOf(pick));
153
+ answer(answerOf(pick, false));
141
154
  }}
142
155
  >
143
156
  Save
@@ -277,16 +290,24 @@ const placed = (
277
290
  const titled = (title: string): string =>
278
291
  title === "" ? "Untitled window" : title;
279
292
 
280
- /** The answer that saves `pick`. */
281
- const answerOf = (pick: Pick): PortalAnswer => {
293
+ /** The answer that saves `pick`, and copies it too when `copy` is set. */
294
+ const answerOf = (pick: Pick, copy: boolean): PortalAnswer => {
282
295
  switch (pick.kind) {
283
296
  case PickKind.Area:
284
- return Answer.Screenshot(pick.area);
297
+ return Answer.Screenshot(pick.area, copy);
285
298
  case PickKind.Window:
286
- return Answer.ScreenshotWindow(pick.id);
299
+ return Answer.ScreenshotWindow(pick.id, copy);
287
300
  }
288
301
  };
289
302
 
303
+ /** Whether `event` is Ctrl+C, with no other modifier. */
304
+ const isCopy = (event: KeyboardEvent): boolean =>
305
+ event.ctrlKey &&
306
+ !event.altKey &&
307
+ !event.metaKey &&
308
+ !event.shiftKey &&
309
+ event.key.toLowerCase() === "c";
310
+
290
311
  /**
291
312
  * What saving window `id` keeps: its frame on the desk while the shell shows
292
313
  * it there, else its own last frame.