@tearleads/windowing 0.2.22 → 0.2.24
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +94 -0
- package/desktop/DesktopIcon.d.ts +28 -0
- package/desktop/DesktopIcon.js +38 -0
- package/desktop/DesktopIcon.js.map +1 -0
- package/desktop/DesktopIconMenu.d.ts +18 -0
- package/desktop/DesktopIconMenu.js +14 -0
- package/desktop/DesktopIconMenu.js.map +1 -0
- package/desktop/DesktopIcons.css +69 -0
- package/desktop/DesktopIcons.d.ts +26 -0
- package/desktop/DesktopIcons.js +43 -0
- package/desktop/DesktopIcons.js.map +1 -0
- package/desktop/desktopState.d.ts +43 -0
- package/desktop/desktopState.js +142 -0
- package/desktop/desktopState.js.map +1 -0
- package/desktop/desktopStateStorage.d.ts +21 -0
- package/desktop/desktopStateStorage.js +66 -0
- package/desktop/desktopStateStorage.js.map +1 -0
- package/desktop/useDesktopIconDrag.d.ts +24 -0
- package/desktop/useDesktopIconDrag.js +70 -0
- package/desktop/useDesktopIconDrag.js.map +1 -0
- package/desktop/useDesktopIconSelection.d.ts +12 -0
- package/desktop/useDesktopIconSelection.js +46 -0
- package/desktop/useDesktopIconSelection.js.map +1 -0
- package/desktop/useDesktopIconState.d.ts +17 -0
- package/desktop/useDesktopIconState.js +77 -0
- package/desktop/useDesktopIconState.js.map +1 -0
- package/desktop/useDesktopSurface.d.ts +10 -0
- package/desktop/useDesktopSurface.js +27 -0
- package/desktop/useDesktopSurface.js.map +1 -0
- package/display/DisplayProperties.css +106 -0
- package/display/DisplayProperties.d.ts +8 -0
- package/display/DisplayProperties.js +36 -0
- package/display/DisplayProperties.js.map +1 -0
- package/index.d.ts +9 -0
- package/index.js +10 -2
- package/index.js.map +1 -1
- package/launcher/LauncherNavigationProvider.js +1 -0
- package/launcher/LauncherNavigationProvider.js.map +1 -1
- package/launcher/launcherDefinition.d.ts +6 -0
- package/launcher/launcherDefinition.js.map +1 -1
- package/package.json +1 -1
- package/wallpaper/DesktopWallpaper.d.ts +15 -0
- package/wallpaper/DesktopWallpaper.js +22 -0
- package/wallpaper/DesktopWallpaper.js.map +1 -0
- package/wallpaper/Wallpaper.css +34 -0
- package/wallpaper/WallpaperProvider.d.ts +33 -0
- package/wallpaper/WallpaperProvider.js +37 -0
- package/wallpaper/WallpaperProvider.js.map +1 -0
- package/wallpaper/tessellations.d.ts +13 -0
- package/wallpaper/tessellations.js +151 -0
- package/wallpaper/tessellations.js.map +1 -0
- package/wallpaper/wallpapers.d.ts +52 -0
- package/wallpaper/wallpapers.js +28 -0
- package/wallpaper/wallpapers.js.map +1 -0
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
// Where the desktop keeps its state. The desktop reads and writes one JSON
|
|
2
|
+
// document through an adapter, so each host chooses the medium: an encrypted
|
|
3
|
+
// store, the origin private file system, or memory.
|
|
4
|
+
/** Keeps the state in memory, for the life of the adapter. */
|
|
5
|
+
export function createMemoryDesktopStateStorage(initial = null) {
|
|
6
|
+
let stored = initial;
|
|
7
|
+
return {
|
|
8
|
+
read: async () => stored,
|
|
9
|
+
write: async (serialized) => {
|
|
10
|
+
stored = serialized;
|
|
11
|
+
},
|
|
12
|
+
};
|
|
13
|
+
}
|
|
14
|
+
function opfsRoot() {
|
|
15
|
+
const storage = typeof navigator === "object" ? navigator.storage : undefined;
|
|
16
|
+
if (typeof storage?.getDirectory !== "function") {
|
|
17
|
+
return Promise.reject(new Error("The origin private file system is not available."));
|
|
18
|
+
}
|
|
19
|
+
return storage.getDirectory();
|
|
20
|
+
}
|
|
21
|
+
function isNotFound(error) {
|
|
22
|
+
return error instanceof DOMException && error.name === "NotFoundError";
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Keeps the state as a file in the origin private file system (OPFS). Reading
|
|
26
|
+
* a file or directory that does not exist yet yields null; any other failure,
|
|
27
|
+
* including a browser without OPFS, rejects.
|
|
28
|
+
*/
|
|
29
|
+
export function createOpfsDesktopStateStorage({ directory = [], fileName = "desktop-state.json", } = {}) {
|
|
30
|
+
async function openDirectory(create) {
|
|
31
|
+
let handle = await opfsRoot();
|
|
32
|
+
for (const name of directory) {
|
|
33
|
+
handle = await handle.getDirectoryHandle(name, { create });
|
|
34
|
+
}
|
|
35
|
+
return handle;
|
|
36
|
+
}
|
|
37
|
+
return {
|
|
38
|
+
read: async () => {
|
|
39
|
+
try {
|
|
40
|
+
const parent = await openDirectory(false);
|
|
41
|
+
const file = await (await parent.getFileHandle(fileName)).getFile();
|
|
42
|
+
return await file.text();
|
|
43
|
+
}
|
|
44
|
+
catch (error) {
|
|
45
|
+
if (isNotFound(error)) {
|
|
46
|
+
return null;
|
|
47
|
+
}
|
|
48
|
+
throw error;
|
|
49
|
+
}
|
|
50
|
+
},
|
|
51
|
+
write: async (serialized) => {
|
|
52
|
+
const parent = await openDirectory(true);
|
|
53
|
+
const handle = await parent.getFileHandle(fileName, { create: true });
|
|
54
|
+
const writable = await handle.createWritable();
|
|
55
|
+
try {
|
|
56
|
+
await writable.write(serialized);
|
|
57
|
+
}
|
|
58
|
+
catch (error) {
|
|
59
|
+
await writable.abort().catch(() => { });
|
|
60
|
+
throw error;
|
|
61
|
+
}
|
|
62
|
+
await writable.close();
|
|
63
|
+
},
|
|
64
|
+
};
|
|
65
|
+
}
|
|
66
|
+
//# sourceMappingURL=desktopStateStorage.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"desktopStateStorage.js","sourceRoot":"","sources":["../../../home/runner/work/tearleads/tearleads/packages/windowing/src/desktop/desktopStateStorage.ts"],"names":[],"mappings":"AAAA,2EAA2E;AAC3E,6EAA6E;AAC7E,oDAAoD;AAUpD,8DAA8D;AAC9D,MAAM,UAAU,+BAA+B,CAC7C,UAAyB,IAAI;IAE7B,IAAI,MAAM,GAAG,OAAO,CAAC;IACrB,OAAO;QACL,IAAI,EAAE,KAAK,IAAI,EAAE,CAAC,MAAM;QACxB,KAAK,EAAE,KAAK,EAAE,U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AAK,EAAE,CAAC;gBACf,IAAI,UAAU,CAAC,KAAK,CAAC,EAAE,CAAC;oBACtB,OAAO,IAAI,CAAC;gBACd,CAAC;gBACD,MAAM,KAAK,CAAC;YACd,CAAC;QACH,CAAC;QACD,KAAK,EAAE,KAAK,EAAE,UAAU,EAAE,EAAE;YAC1B,MAAM,MAAM,GAAG,MAAM,aAAa,CAAC,IAAI,CAAC,CAAC;YACzC,MAAM,MAAM,GAAG,MAAM,MAAM,CAAC,aAAa,CAAC,QAAQ,EAAE,EAAE,MAAM,EAAE,IAAI,EAAE,CAAC,CAAC;YACtE,MAAM,QAAQ,GAAG,MAAM,MAAM,CAAC,cAAc,EAAE,CAAC;YAC/C,IAAI,CAAC;gBACH,MAAM,QAAQ,CAAC,KAAK,CAAC,UAAU,CAAC,CAAC;YACnC,CAAC;YAAC,OAAO,KAAK,EAAE,CAAC;gBACf,MAAM,QAAQ,CAAC,KAAK,EAAE,CAAC,KAAK,CAAC,GAAG,EAAE,GAAE,CAAC,CAAC,CAAC;gBACvC,MAAM,KAAK,CAAC;YACd,CAAC;YACD,MAAM,QAAQ,CAAC,KAAK,EAAE,CAAC;QACzB,CAAC;KACF,CAAC;AACJ,CAAC","sourcesContent":["// Where the desktop keeps its state. The desktop reads and writes one JSON\n// document through an adapter, so each host chooses the medium: an encrypted\n// store, the origin private file system, or memory.\n\n/** Reads and writes the desktop's serialized state. */\nexport interface DesktopStateStorage {\n /** The stored text, or null when nothing is stored yet. */\n read: () => Promise<string | null>;\n /** Replaces the stored text. */\n write: (serialized: string) => Promise<void>;\n}\n\n/** Keeps the state in memory, for the life of the adapter. */\nexport function createMemoryDesktopStateStorage(\n initial: string | null = null,\n): DesktopStateStorage {\n let stored = initial;\n return {\n read: async () => stored,\n write: async (serialized) => {\n stored = serialized;\n },\n };\n}\n\nexport interface OpfsDesktopStateStorageOptions {\n /** Directories below the origin's root that hold the file, outermost first. */\n directory?: ReadonlyArray<string> | undefined;\n /** The file's name. Defaults to `desktop-state.json`. */\n fileName?: string | undefined;\n}\n\ninterface StorageWithDirectory {\n getDirectory: () => Promise<FileSystemDirectoryHandle>;\n}\n\nfunction opfsRoot(): Promise<FileSystemDirectoryHandle> {\n const storage: Partial<StorageWithDirectory> | undefined =\n typeof navigator === \"object\" ? navigator.storage : undefined;\n if (typeof storage?.getDirectory !== \"function\") {\n return Promise.reject(\n new Error(\"The origin private file system is not available.\"),\n );\n }\n return storage.getDirectory();\n}\n\nfunction isNotFound(error: unknown): boolean {\n return error instanceof DOMException && error.name === \"NotFoundError\";\n}\n\n/**\n * Keeps the state as a file in the origin private file system (OPFS). Reading\n * a file or directory that does not exist yet yields null; any other failure,\n * including a browser without OPFS, rejects.\n */\nexport function createOpfsDesktopStateStorage({\n directory = [],\n fileName = \"desktop-state.json\",\n}: OpfsDesktopStateStorageOptions = {}): DesktopStateStorage {\n async function openDirectory(create: boolean) {\n let handle = await opfsRoot();\n for (const name of directory) {\n handle = await handle.getDirectoryHandle(name, { create });\n }\n return handle;\n }\n\n return {\n read: async () => {\n try {\n const parent = await openDirectory(false);\n const file = await (await parent.getFileHandle(fileName)).getFile();\n return await file.text();\n } catch (error) {\n if (isNotFound(error)) {\n return null;\n }\n throw error;\n }\n },\n write: async (serialized) => {\n const parent = await openDirectory(true);\n const handle = await parent.getFileHandle(fileName, { create: true });\n const writable = await handle.createWritable();\n try {\n await writable.write(serialized);\n } catch (error) {\n await writable.abort().catch(() => {});\n throw error;\n }\n await writable.close();\n },\n };\n}\n"]}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { type PointerEvent } from "react";
|
|
2
|
+
import type { DesktopIconPosition, DesktopSurfaceSize } from "./desktopState.js";
|
|
3
|
+
/** Keeps a position on the surface, given the icon's rendered size. */
|
|
4
|
+
export type ClampDesktopIcon = (position: DesktopIconPosition, size: DesktopSurfaceSize) => DesktopIconPosition;
|
|
5
|
+
/**
|
|
6
|
+
* Moves an icon with any pointer: the primary press selects it and captures
|
|
7
|
+
* the pointer, the icon follows once the pointer passes the drag threshold,
|
|
8
|
+
* and the release commits where it landed. A cancelled gesture snaps back.
|
|
9
|
+
*/
|
|
10
|
+
export declare function useDesktopIconDrag({ clamp, onMove, onSelect, position, }: {
|
|
11
|
+
clamp: ClampDesktopIcon;
|
|
12
|
+
onMove: (position: DesktopIconPosition) => void;
|
|
13
|
+
onSelect: () => void;
|
|
14
|
+
position: DesktopIconPosition;
|
|
15
|
+
}): {
|
|
16
|
+
dragPosition: DesktopIconPosition | null;
|
|
17
|
+
handlers: {
|
|
18
|
+
onLostPointerCapture: () => void;
|
|
19
|
+
onPointerCancel: () => void;
|
|
20
|
+
onPointerDown: (event: PointerEvent<HTMLElement>) => void;
|
|
21
|
+
onPointerMove: (event: PointerEvent<HTMLElement>) => void;
|
|
22
|
+
onPointerUp: (event: PointerEvent<HTMLElement>) => void;
|
|
23
|
+
};
|
|
24
|
+
};
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import { useRef, useState } from "react";
|
|
2
|
+
// A press becomes a drag once the pointer travels this far, so a slightly
|
|
3
|
+
// shaky click or double-click does not move the icon.
|
|
4
|
+
const DRAG_THRESHOLD_PX = 4;
|
|
5
|
+
function sizeOf(element) {
|
|
6
|
+
return { height: element.offsetHeight, width: element.offsetWidth };
|
|
7
|
+
}
|
|
8
|
+
/**
|
|
9
|
+
* Moves an icon with any pointer: the primary press selects it and captures
|
|
10
|
+
* the pointer, the icon follows once the pointer passes the drag threshold,
|
|
11
|
+
* and the release commits where it landed. A cancelled gesture snaps back.
|
|
12
|
+
*/
|
|
13
|
+
export function useDesktopIconDrag({ clamp, onMove, onSelect, position, }) {
|
|
14
|
+
const dragRef = useRef(null);
|
|
15
|
+
const [dragPosition, setDragPosition] = useState(null);
|
|
16
|
+
const dragTo = (event, drag) => clamp({
|
|
17
|
+
x: Math.round(drag.origin.x + event.clientX - drag.startX),
|
|
18
|
+
y: Math.round(drag.origin.y + event.clientY - drag.startY),
|
|
19
|
+
}, sizeOf(event.currentTarget));
|
|
20
|
+
const activeDrag = (event) => {
|
|
21
|
+
const drag = dragRef.current;
|
|
22
|
+
return drag && drag.pointerId === event.pointerId ? drag : null;
|
|
23
|
+
};
|
|
24
|
+
const cancel = () => {
|
|
25
|
+
dragRef.current = null;
|
|
26
|
+
setDragPosition(null);
|
|
27
|
+
};
|
|
28
|
+
const handlers = {
|
|
29
|
+
onLostPointerCapture: cancel,
|
|
30
|
+
onPointerCancel: cancel,
|
|
31
|
+
onPointerDown: (event) => {
|
|
32
|
+
if (event.button !== 0) {
|
|
33
|
+
return;
|
|
34
|
+
}
|
|
35
|
+
onSelect();
|
|
36
|
+
dragRef.current = {
|
|
37
|
+
moved: false,
|
|
38
|
+
origin: position,
|
|
39
|
+
pointerId: event.pointerId,
|
|
40
|
+
startX: event.clientX,
|
|
41
|
+
startY: event.clientY,
|
|
42
|
+
};
|
|
43
|
+
event.currentTarget.setPointerCapture?.(event.pointerId);
|
|
44
|
+
},
|
|
45
|
+
onPointerMove: (event) => {
|
|
46
|
+
const drag = activeDrag(event);
|
|
47
|
+
if (!drag) {
|
|
48
|
+
return;
|
|
49
|
+
}
|
|
50
|
+
const distance = Math.hypot(event.clientX - drag.startX, event.clientY - drag.startY);
|
|
51
|
+
if (!drag.moved && distance < DRAG_THRESHOLD_PX) {
|
|
52
|
+
return;
|
|
53
|
+
}
|
|
54
|
+
drag.moved = true;
|
|
55
|
+
setDragPosition(dragTo(event, drag));
|
|
56
|
+
},
|
|
57
|
+
onPointerUp: (event) => {
|
|
58
|
+
const drag = activeDrag(event);
|
|
59
|
+
if (!drag) {
|
|
60
|
+
return;
|
|
61
|
+
}
|
|
62
|
+
cancel();
|
|
63
|
+
if (drag.moved) {
|
|
64
|
+
onMove(dragTo(event, drag));
|
|
65
|
+
}
|
|
66
|
+
},
|
|
67
|
+
};
|
|
68
|
+
return { dragPosition, handlers };
|
|
69
|
+
}
|
|
70
|
+
//# sourceMappingURL=useDesktopIconDrag.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useDesktopIconDrag.js","sourceRoot":"","sources":["../../../home/runner/work/tearleads/tearleads/packages/windowing/src/desktop/useDesktopIconDrag.ts"],"names":[],"mappings":"AAAA,OAAO,EAAqB,MAAM,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AAG5D,0EAA0E;AAC1E,sDAAsD;AACtD,MAAM,iBAAiB,GAAG,CAAC,CAAC;AAgB5B,SAAS,MAAM,CAAC,OAAoB;IAClC,OAAO,EAAE,MAAM,EAAE,OAAO,CAAC,YAAY,EAAE,KAAK,EAAE,OAAO,CAAC,WAAW,EAAE,CAAC;AACtE,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,kBAAkB,CAAC,EACjC,KAAK,EACL,MAAM,EACN,QAAQ,EACR,QAAQ,GAMT;IACC,MAAM,OAAO,GAAG,MAAM,CAAmB,IAAI,CAAC,CAAC;IAC/C,MAAM,CAAC,YAAY,EAAE,eAAe,CAAC,GAAG,QAAQ,CAC9C,IAAI,CACL,CAAC;IAEF,MAAM,MAAM,GAAG,CAAC,KAAgC,EAAE,IAAe,EAAE,EAAE,CACnE,KAAK,CACH;QACE,CAAC,EAAE,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,GAAG,KAAK,CAAC,OAAO,GAAG,IAAI,CAAC,MAAM,CAAC;QAC1D,CAAC,EAAE,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,GAAG,KAAK,CAAC,OAAO,GAAG,IAAI,CAAC,MAAM,CAAC;KAC3D,EACD,MAAM,CAAC,KAAK,CAAC,aAAa,CAAC,CAC5B,CAAC;IAEJ,MAAM,UAAU,GAAG,CAAC,KAAgC,EAAE,EAAE;QACtD,MAAM,IAAI,GAAG,OAAO,CAAC,OAAO,CAAC;QAC7B,OAAO,IAAI,IAAI,IAAI,CAAC,SAAS,KAAK,KAAK,CAAC,SAAS,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC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,CAAC,KAAgC,EAAE,EAAE;YAChD,MAAM,IAAI,GAAG,UAAU,CAAC,KAAK,CAAC,CAAC;YAC/B,IAAI,CAAC,IAAI,EAAE,CAAC;gBACV,OAAO;YACT,CAAC;YACD,MAAM,EAAE,CAAC;YACT,IAAI,IAAI,CAAC,KAAK,EAAE,CAAC;gBACf,MAAM,CAAC,MAAM,CAAC,KAAK,EAAE,IAAI,CAAC,CAAC,CAAC;YAC9B,CAAC;QACH,CAAC;KACF,CAAC;IAEF,OAAO,EAAE,YAAY,EAAE,QAAQ,EAAE,CAAC;AACpC,CAAC","sourcesContent":["import { type PointerEvent, useRef, useState } from \"react\";\nimport type { DesktopIconPosition, DesktopSurfaceSize } from \"./desktopState\";\n\n// A press becomes a drag once the pointer travels this far, so a slightly\n// shaky click or double-click does not move the icon.\nconst DRAG_THRESHOLD_PX = 4;\n\ninterface DragStart {\n moved: boolean;\n origin: DesktopIconPosition;\n pointerId: number;\n startX: number;\n startY: number;\n}\n\n/** Keeps a position on the surface, given the icon's rendered size. */\nexport type ClampDesktopIcon = (\n position: DesktopIconPosition,\n size: DesktopSurfaceSize,\n) => DesktopIconPosition;\n\nfunction sizeOf(element: HTMLElement): DesktopSurfaceSize {\n return { height: element.offsetHeight, width: element.offsetWidth };\n}\n\n/**\n * Moves an icon with any pointer: the primary press selects it and captures\n * the pointer, the icon follows once the pointer passes the drag threshold,\n * and the release commits where it landed. A cancelled gesture snaps back.\n */\nexport function useDesktopIconDrag({\n clamp,\n onMove,\n onSelect,\n position,\n}: {\n clamp: ClampDesktopIcon;\n onMove: (position: DesktopIconPosition) => void;\n onSelect: () => void;\n position: DesktopIconPosition;\n}) {\n const dragRef = useRef<DragStart | null>(null);\n const [dragPosition, setDragPosition] = useState<DesktopIconPosition | null>(\n null,\n );\n\n const dragTo = (event: PointerEvent<HTMLElement>, drag: DragStart) =>\n clamp(\n {\n x: Math.round(drag.origin.x + event.clientX - drag.startX),\n y: Math.round(drag.origin.y + event.clientY - drag.startY),\n },\n sizeOf(event.currentTarget),\n );\n\n const activeDrag = (event: PointerEvent<HTMLElement>) => {\n const drag = dragRef.current;\n return drag && drag.pointerId === event.pointerId ? drag : null;\n };\n\n const cancel = () => {\n dragRef.current = null;\n setDragPosition(null);\n };\n\n const handlers = {\n onLostPointerCapture: cancel,\n onPointerCancel: cancel,\n onPointerDown: (event: PointerEvent<HTMLElement>) => {\n if (event.button !== 0) {\n return;\n }\n onSelect();\n dragRef.current = {\n moved: false,\n origin: position,\n pointerId: event.pointerId,\n startX: event.clientX,\n startY: event.clientY,\n };\n event.currentTarget.setPointerCapture?.(event.pointerId);\n },\n onPointerMove: (event: PointerEvent<HTMLElement>) => {\n const drag = activeDrag(event);\n if (!drag) {\n return;\n }\n const distance = Math.hypot(\n event.clientX - drag.startX,\n event.clientY - drag.startY,\n );\n if (!drag.moved && distance < DRAG_THRESHOLD_PX) {\n return;\n }\n drag.moved = true;\n setDragPosition(dragTo(event, drag));\n },\n onPointerUp: (event: PointerEvent<HTMLElement>) => {\n const drag = activeDrag(event);\n if (!drag) {\n return;\n }\n cancel();\n if (drag.moved) {\n onMove(dragTo(event, drag));\n }\n },\n };\n\n return { dragPosition, handlers };\n}\n"]}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { DesktopIconStep } from "./DesktopIcon.js";
|
|
2
|
+
/**
|
|
3
|
+
* Which icon is selected. A press anywhere but an icon clears it, and steps
|
|
4
|
+
* move it (and focus) along the icons' order. One icon is tabbable: the
|
|
5
|
+
* selected one, or else the first.
|
|
6
|
+
*/
|
|
7
|
+
export declare function useDesktopIconSelection<AppId extends string>(layer: HTMLElement | null, appIds: ReadonlyArray<AppId>): {
|
|
8
|
+
selected: AppId | null;
|
|
9
|
+
setSelected: import("react").Dispatch<import("react").SetStateAction<AppId | null>>;
|
|
10
|
+
step: (from: AppId, direction: DesktopIconStep) => void;
|
|
11
|
+
tabbableId: AppId | undefined;
|
|
12
|
+
};
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { useCallback, useEffect, useState } from "react";
|
|
2
|
+
/**
|
|
3
|
+
* Which icon is selected. A press anywhere but an icon clears it, and steps
|
|
4
|
+
* move it (and focus) along the icons' order. One icon is tabbable: the
|
|
5
|
+
* selected one, or else the first.
|
|
6
|
+
*/
|
|
7
|
+
export function useDesktopIconSelection(layer, appIds) {
|
|
8
|
+
const [selected, setSelected] = useState(null);
|
|
9
|
+
useEffect(() => {
|
|
10
|
+
if (!layer || selected === null) {
|
|
11
|
+
return;
|
|
12
|
+
}
|
|
13
|
+
const handlePointerDown = (event) => {
|
|
14
|
+
const target = event.target;
|
|
15
|
+
if (target instanceof Element &&
|
|
16
|
+
layer.contains(target) &&
|
|
17
|
+
target.closest(".desktop-icon")) {
|
|
18
|
+
return;
|
|
19
|
+
}
|
|
20
|
+
setSelected(null);
|
|
21
|
+
};
|
|
22
|
+
document.addEventListener("pointerdown", handlePointerDown);
|
|
23
|
+
return () => document.removeEventListener("pointerdown", handlePointerDown);
|
|
24
|
+
}, [layer, selected]);
|
|
25
|
+
const step = useCallback((from, direction) => {
|
|
26
|
+
const index = appIds.indexOf(from);
|
|
27
|
+
const last = appIds.length - 1;
|
|
28
|
+
const target = {
|
|
29
|
+
first: 0,
|
|
30
|
+
last,
|
|
31
|
+
next: Math.min(index + 1, last),
|
|
32
|
+
previous: Math.max(index - 1, 0),
|
|
33
|
+
}[direction];
|
|
34
|
+
const appId = appIds[target];
|
|
35
|
+
if (appId === undefined) {
|
|
36
|
+
return;
|
|
37
|
+
}
|
|
38
|
+
setSelected(appId);
|
|
39
|
+
layer
|
|
40
|
+
?.querySelector(`[data-app-id="${CSS.escape(appId)}"]`)
|
|
41
|
+
?.focus();
|
|
42
|
+
}, [appIds, layer]);
|
|
43
|
+
const tabbableId = selected !== null && appIds.includes(selected) ? selected : appIds[0];
|
|
44
|
+
return { selected, setSelected, step, tabbableId };
|
|
45
|
+
}
|
|
46
|
+
//# sourceMappingURL=useDesktopIconSelection.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useDesktopIconSelection.js","sourceRoot":"","sources":["../../../home/runner/work/tearleads/tearleads/packages/windowing/src/desktop/useDesktopIconSelection.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,SAAS,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AAGzD;;;;GAIG;AACH,MAAM,UAAU,uBAAuB,CACrC,KAAyB,EACzB,MAA4B;IAE5B,MAAM,CAAC,QAAQ,EAAE,WAAW,CAAC,GAAG,QAAQ,CAAe,IAAI,CAAC,CAAC;IAE7D,SAAS,CAAC,GAAG,EAAE;QACb,IAAI,CAAC,KAAK,IAAI,QAAQ,KAAK,IAAI,EAAE,CAAC;YAChC,OAAO;QACT,CAAC;QACD,MAAM,iBAAiB,GAAG,CAAC,KAAmB,EAAE,EAAE;YAChD,MAAM,MAAM,GAAG,KAAK,CAAC,MAAM,CAAC;YAC5B,IACE,MAAM,YAAY,OAAO;gBACzB,KAAK,CAAC,QAAQ,CAAC,MAAM,CAAC;gBACtB,MAAM,CAAC,OAAO,CAAC,eAAe,CAAC,EAC/B,CAAC;gBACD,OAAO;YACT,CAAC;YACD,WAAW,CAAC,IAAI,CAAC,CAAC;QACpB,CAAC,CAAC;QACF,QAAQ,CAAC,gBAAgB,CAAC,aAAa,EAAE,iBAAiB,CAAC,CAAC;QAC5D,OAAO,GAAG,EAAE,CAAC,QAAQ,CAAC,mBAAmB,CAAC,aAAa,EAAE,iBAAiB,CAAC,CAAC;IAC9E,CAAC,EAAE,CAAC,KAAK,EAAE,QAAQ,CAAC,CAAC,CAAC;IAEtB,MAAM,IAAI,GAAG,WAAW,CACtB,CAAC,IAAW,EAAE,SAA0B,EAAE,EAAE;QAC1C,MAAM,KAAK,GAAG,MAAM,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC;QACnC,MAAM,IAAI,GAAG,MAAM,CAAC,MAAM,GAAG,CAAC,CAAC;QAC/B,MAAM,MAAM,GAAG;YACb,KAAK,EAAE,CAAC;YACR,IAAI;YACJ,IAAI,EAAE,IAAI,CAAC,GAAG,CAAC,KAAK,GAAG,CAAC,EAAE,IAAI,CAAC;YAC/B,QAAQ,EAAE,IAAI,CAAC,GAAG,CAAC,KAAK,GAAG,CAAC,EAAE,CAAC,CAAC;SACjC,CAAC,SAAS,CAAC,CAAC;QACb,MAAM,KAAK,GAAG,MAAM,CAAC,MAAM,CAAC,CAAC;QAC7B,IAAI,KAAK,KAAK,SAAS,EAAE,CAAC;YACxB,OAAO;QACT,CAAC;QACD,WAAW,CAAC,KAAK,CAAC,CAAC;QACnB,KAAK;YACH,EAAE,aAAa,CAAc,iBAAiB,GAAG,CAAC,MAAM,CAAC,KAAK,CAAC,IAAI,CAAC;YACpE,EAAE,KAAK,EAAE,CAAC;IACd,CAAC,EACD,CAAC,MAAM,EAAE,KAAK,CAAC,CAChB,CAAC;IAEF,MAAM,UAAU,GACd,QAAQ,KAAK,IAAI,IAAI,MAAM,CAAC,QAAQ,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC;IAExE,OAAO,EAAE,QAAQ,EAAE,WAAW,EAAE,IAAI,EAAE,UAAU,EAAE,CAAC;AACrD,CAAC","sourcesContent":["import { useCallback, useEffect, useState } from \"react\";\nimport type { DesktopIconStep } from \"./DesktopIcon\";\n\n/**\n * Which icon is selected. A press anywhere but an icon clears it, and steps\n * move it (and focus) along the icons' order. One icon is tabbable: the\n * selected one, or else the first.\n */\nexport function useDesktopIconSelection<AppId extends string>(\n layer: HTMLElement | null,\n appIds: ReadonlyArray<AppId>,\n) {\n const [selected, setSelected] = useState<AppId | null>(null);\n\n useEffect(() => {\n if (!layer || selected === null) {\n return;\n }\n const handlePointerDown = (event: PointerEvent) => {\n const target = event.target;\n if (\n target instanceof Element &&\n layer.contains(target) &&\n target.closest(\".desktop-icon\")\n ) {\n return;\n }\n setSelected(null);\n };\n document.addEventListener(\"pointerdown\", handlePointerDown);\n return () => document.removeEventListener(\"pointerdown\", handlePointerDown);\n }, [layer, selected]);\n\n const step = useCallback(\n (from: AppId, direction: DesktopIconStep) => {\n const index = appIds.indexOf(from);\n const last = appIds.length - 1;\n const target = {\n first: 0,\n last,\n next: Math.min(index + 1, last),\n previous: Math.max(index - 1, 0),\n }[direction];\n const appId = appIds[target];\n if (appId === undefined) {\n return;\n }\n setSelected(appId);\n layer\n ?.querySelector<HTMLElement>(`[data-app-id=\"${CSS.escape(appId)}\"]`)\n ?.focus();\n },\n [appIds, layer],\n );\n\n const tabbableId =\n selected !== null && appIds.includes(selected) ? selected : appIds[0];\n\n return { selected, setSelected, step, tabbableId };\n}\n"]}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { type DesktopIconPosition } from "./desktopState.js";
|
|
2
|
+
import type { DesktopStateStorage } from "./desktopStateStorage.js";
|
|
3
|
+
/**
|
|
4
|
+
* The desktop's icon positions, loaded from `storage` and written back after
|
|
5
|
+
* every move. A new adapter (another account's store, say) starts over from
|
|
6
|
+
* what it holds.
|
|
7
|
+
*
|
|
8
|
+
* Moves made before the load finishes win over the stored positions, and are
|
|
9
|
+
* written only once the load has merged them, so an early move never replaces
|
|
10
|
+
* the stored state with a partial one. When the read fails the positions stay
|
|
11
|
+
* in memory and nothing is written, so a passing failure cannot erase a saved
|
|
12
|
+
* layout.
|
|
13
|
+
*/
|
|
14
|
+
export declare function useDesktopIconState(storage: DesktopStateStorage): {
|
|
15
|
+
icons: Readonly<Record<string, DesktopIconPosition>>;
|
|
16
|
+
moveIcon: (appId: string, position: DesktopIconPosition) => void;
|
|
17
|
+
};
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import { useCallback, useEffect, useRef, useState } from "react";
|
|
2
|
+
import { parseDesktopState, serializeDesktopState, } from "./desktopState.js";
|
|
3
|
+
const NO_ICONS = {};
|
|
4
|
+
// Each adapter's last queued write. A desktop that remounts (a layout switch,
|
|
5
|
+
// say) while a write is pending reads only after it lands, so it never loads
|
|
6
|
+
// the layout from before the last move.
|
|
7
|
+
const pendingWrites = new WeakMap();
|
|
8
|
+
function queueWrite(storage, serialized) {
|
|
9
|
+
const write = (pendingWrites.get(storage) ?? Promise.resolve())
|
|
10
|
+
.then(() => storage.write(serialized))
|
|
11
|
+
.catch(() => { });
|
|
12
|
+
pendingWrites.set(storage, write);
|
|
13
|
+
}
|
|
14
|
+
function readAfterWrites(storage) {
|
|
15
|
+
return (pendingWrites.get(storage) ?? Promise.resolve()).then(() => storage.read());
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* The desktop's icon positions, loaded from `storage` and written back after
|
|
19
|
+
* every move. A new adapter (another account's store, say) starts over from
|
|
20
|
+
* what it holds.
|
|
21
|
+
*
|
|
22
|
+
* Moves made before the load finishes win over the stored positions, and are
|
|
23
|
+
* written only once the load has merged them, so an early move never replaces
|
|
24
|
+
* the stored state with a partial one. When the read fails the positions stay
|
|
25
|
+
* in memory and nothing is written, so a passing failure cannot erase a saved
|
|
26
|
+
* layout.
|
|
27
|
+
*/
|
|
28
|
+
export function useDesktopIconState(storage) {
|
|
29
|
+
const [icons, setIcons] = useState(NO_ICONS);
|
|
30
|
+
const iconsRef = useRef(NO_ICONS);
|
|
31
|
+
const movedRef = useRef(new Set());
|
|
32
|
+
const writableRef = useRef(false);
|
|
33
|
+
const publish = useCallback((next) => {
|
|
34
|
+
iconsRef.current = next;
|
|
35
|
+
setIcons(next);
|
|
36
|
+
}, []);
|
|
37
|
+
// Writes run one at a time, in order, so the last move is the one kept.
|
|
38
|
+
const save = useCallback((next) => queueWrite(storage, serializeDesktopState({ icons: next })), [storage]);
|
|
39
|
+
useEffect(() => {
|
|
40
|
+
let current = true;
|
|
41
|
+
movedRef.current = new Set();
|
|
42
|
+
writableRef.current = false;
|
|
43
|
+
publish(NO_ICONS);
|
|
44
|
+
readAfterWrites(storage).then((serialized) => {
|
|
45
|
+
if (!current) {
|
|
46
|
+
return;
|
|
47
|
+
}
|
|
48
|
+
const merged = {
|
|
49
|
+
...parseDesktopState(serialized).icons,
|
|
50
|
+
};
|
|
51
|
+
for (const appId of movedRef.current) {
|
|
52
|
+
const position = iconsRef.current[appId];
|
|
53
|
+
if (position) {
|
|
54
|
+
merged[appId] = position;
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
writableRef.current = true;
|
|
58
|
+
publish(merged);
|
|
59
|
+
if (movedRef.current.size > 0) {
|
|
60
|
+
save(merged);
|
|
61
|
+
}
|
|
62
|
+
}, () => { });
|
|
63
|
+
return () => {
|
|
64
|
+
current = false;
|
|
65
|
+
};
|
|
66
|
+
}, [publish, save, storage]);
|
|
67
|
+
const moveIcon = useCallback((appId, position) => {
|
|
68
|
+
movedRef.current.add(appId);
|
|
69
|
+
const next = { ...iconsRef.current, [appId]: position };
|
|
70
|
+
publish(next);
|
|
71
|
+
if (writableRef.current) {
|
|
72
|
+
save(next);
|
|
73
|
+
}
|
|
74
|
+
}, [publish, save]);
|
|
75
|
+
return { icons, moveIcon };
|
|
76
|
+
}
|
|
77
|
+
//# sourceMappingURL=useDesktopIconState.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useDesktopIconState.js","sourceRoot":"","sources":["../../../home/runner/work/tearleads/tearleads/packages/windowing/src/desktop/useDesktopIconState.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,SAAS,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AACjE,OAAO,EAGL,iBAAiB,EACjB,qBAAqB,GACtB,MAAM,gBAAgB,CAAC;AAKxB,MAAM,QAAQ,GAAkB,EAAE,CAAC;AAEnC,8EAA8E;AAC9E,6EAA6E;AAC7E,wCAAwC;AACxC,MAAM,aAAa,GAAG,IAAI,OAAO,EAAsC,CAAC;AAExE,SAAS,UAAU,CAAC,OAA4B,EAAE,UAAkB;IAClE,MAAM,KAAK,GAAG,CAAC,aAAa,CAAC,G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xD,OAAO,CAAC,IAAI,CAAC,CAAC;QACd,IAAI,WAAW,CAAC,OAAO,EAAE,CAAC;YACxB,IAAI,CAAC,IAAI,CAAC,CAAC;QACb,CAAC;IACH,CAAC,EACD,CAAC,OAAO,EAAE,IAAI,CAAC,CAChB,CAAC;IAEF,OAAO,EAAE,KAAK,EAAE,QAAQ,EAAE,CAAC;AAC7B,CAAC","sourcesContent":["import { useCallback, useEffect, useRef, useState } from \"react\";\nimport {\n type DesktopIconPosition,\n type DesktopState,\n parseDesktopState,\n serializeDesktopState,\n} from \"./desktopState\";\nimport type { DesktopStateStorage } from \"./desktopStateStorage\";\n\ntype IconPositions = DesktopState[\"icons\"];\n\nconst NO_ICONS: IconPositions = {};\n\n// Each adapter's last queued write. A desktop that remounts (a layout switch,\n// say) while a write is pending reads only after it lands, so it never loads\n// the layout from before the last move.\nconst pendingWrites = new WeakMap<DesktopStateStorage, Promise<void>>();\n\nfunction queueWrite(storage: DesktopStateStorage, serialized: string) {\n const write = (pendingWrites.get(storage) ?? Promise.resolve())\n .then(() => storage.write(serialized))\n .catch(() => {});\n pendingWrites.set(storage, write);\n}\n\nfunction readAfterWrites(storage: DesktopStateStorage) {\n return (pendingWrites.get(storage) ?? Promise.resolve()).then(() =>\n storage.read(),\n );\n}\n\n/**\n * The desktop's icon positions, loaded from `storage` and written back after\n * every move. A new adapter (another account's store, say) starts over from\n * what it holds.\n *\n * Moves made before the load finishes win over the stored positions, and are\n * written only once the load has merged them, so an early move never replaces\n * the stored state with a partial one. When the read fails the positions stay\n * in memory and nothing is written, so a passing failure cannot erase a saved\n * layout.\n */\nexport function useDesktopIconState(storage: DesktopStateStorage) {\n const [icons, setIcons] = useState<IconPositions>(NO_ICONS);\n const iconsRef = useRef<IconPositions>(NO_ICONS);\n const movedRef = useRef(new Set<string>());\n const writableRef = useRef(false);\n\n const publish = useCallback((next: IconPositions) => {\n iconsRef.current = next;\n setIcons(next);\n }, []);\n\n // Writes run one at a time, in order, so the last move is the one kept.\n const save = useCallback(\n (next: IconPositions) =>\n queueWrite(storage, serializeDesktopState({ icons: next })),\n [storage],\n );\n\n useEffect(() => {\n let current = true;\n movedRef.current = new Set();\n writableRef.current = false;\n publish(NO_ICONS);\n readAfterWrites(storage).then(\n (serialized) => {\n if (!current) {\n return;\n }\n const merged: Record<string, DesktopIconPosition> = {\n ...parseDesktopState(serialized).icons,\n };\n for (const appId of movedRef.current) {\n const position = iconsRef.current[appId];\n if (position) {\n merged[appId] = position;\n }\n }\n writableRef.current = true;\n publish(merged);\n if (movedRef.current.size > 0) {\n save(merged);\n }\n },\n () => {},\n );\n return () => {\n current = false;\n };\n }, [publish, save, storage]);\n\n const moveIcon = useCallback(\n (appId: string, position: DesktopIconPosition) => {\n movedRef.current.add(appId);\n const next = { ...iconsRef.current, [appId]: position };\n publish(next);\n if (writableRef.current) {\n save(next);\n }\n },\n [publish, save],\n );\n\n return { icons, moveIcon };\n}\n"]}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { type DesktopIconPosition, type DesktopSurfaceSize } from "./desktopState.js";
|
|
2
|
+
/**
|
|
3
|
+
* The surface the icons lie on, measured from the icon layer, which fills
|
|
4
|
+
* it, and a clamp that keeps an icon of a given size on it. Before the layer
|
|
5
|
+
* is laid out (a zero size) positions are only kept off negative coordinates.
|
|
6
|
+
*/
|
|
7
|
+
export declare function useDesktopSurface(layer: HTMLElement | null): {
|
|
8
|
+
clamp: (position: DesktopIconPosition, size: DesktopSurfaceSize) => DesktopIconPosition;
|
|
9
|
+
surface: DesktopSurfaceSize;
|
|
10
|
+
};
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { useCallback, useLayoutEffect, useState } from "react";
|
|
2
|
+
import { clampDesktopIconPosition, } from "./desktopState.js";
|
|
3
|
+
const UNMEASURED = { height: 0, width: 0 };
|
|
4
|
+
/**
|
|
5
|
+
* The surface the icons lie on, measured from the icon layer, which fills
|
|
6
|
+
* it, and a clamp that keeps an icon of a given size on it. Before the layer
|
|
7
|
+
* is laid out (a zero size) positions are only kept off negative coordinates.
|
|
8
|
+
*/
|
|
9
|
+
export function useDesktopSurface(layer) {
|
|
10
|
+
const [surface, setSurface] = useState(UNMEASURED);
|
|
11
|
+
useLayoutEffect(() => {
|
|
12
|
+
if (!layer) {
|
|
13
|
+
return;
|
|
14
|
+
}
|
|
15
|
+
const measure = () => setSurface((current) => current.width === layer.clientWidth &&
|
|
16
|
+
current.height === layer.clientHeight
|
|
17
|
+
? current
|
|
18
|
+
: { height: layer.clientHeight, width: layer.clientWidth });
|
|
19
|
+
measure();
|
|
20
|
+
const observer = new ResizeObserver(measure);
|
|
21
|
+
observer.observe(layer);
|
|
22
|
+
return () => observer.disconnect();
|
|
23
|
+
}, [layer]);
|
|
24
|
+
const clamp = useCallback((position, size) => clampDesktopIconPosition(position, size, surface), [surface]);
|
|
25
|
+
return { clamp, surface };
|
|
26
|
+
}
|
|
27
|
+
//# sourceMappingURL=useDesktopSurface.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useDesktopSurface.js","sourceRoot":"","sources":["../../../home/runner/work/tearleads/tearleads/packages/windowing/src/desktop/useDesktopSurface.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,eAAe,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AAC/D,OAAO,EACL,wBAAwB,GAGzB,MAAM,gBAAgB,CAAC;AAExB,MAAM,UAAU,GAAuB,EAAE,MAAM,EAAE,CAAC,EAAE,KAAK,EAAE,CAAC,EAAE,CAAC;AAE/D;;;;GAIG;AACH,MAAM,UAAU,iBAAiB,CAAC,KAAyB;IACzD,MAAM,CAAC,OAAO,EAAE,UAAU,CAAC,GAAG,QAAQ,CAAC,UAAU,CAAC,CAAC;IACnD,eAAe,CAAC,GAAG,EAAE;QACnB,IAAI,CAAC,KAAK,EAAE,CAAC;YACX,OAAO;QACT,CAAC;QACD,MAAM,OAAO,GAAG,GAAG,EAAE,CACnB,UAAU,CAAC,CAAC,OAAO,EAAE,EAAE,CACrB,OAAO,CAAC,KAAK,KAAK,KAAK,CAAC,WAAW;YACnC,OAAO,CAAC,MAAM,KAAK,KAAK,CAAC,YAAY;YACnC,CAAC,CAAC,OAAO;YACT,CAAC,CAAC,EAAE,MAAM,EAAE,KAAK,CAAC,YAAY,EAAE,KAAK,EAAE,KAAK,CAAC,WAAW,EAAE,CAC7D,CAAC;QACJ,OAAO,EAAE,CAAC;QACV,MAAM,QAAQ,GAAG,IAAI,cAAc,CAAC,OAAO,CAAC,CAAC;QAC7C,QAAQ,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC;QACxB,OAAO,GAAG,EAAE,CAAC,QAAQ,CAAC,UAAU,EAAE,CAAC;IACrC,CAAC,EAAE,CAAC,KAAK,CAAC,CAAC,CAAC;IAEZ,MAAM,KAAK,GAAG,WAAW,CACvB,CAAC,QAA6B,EAAE,IAAwB,EAAE,EAAE,CAC1D,wBAAwB,CAAC,QAAQ,EAAE,IAAI,EAAE,OAAO,CAAC,EACnD,CAAC,OAAO,CAAC,CACV,CAAC;IAEF,OAAO,EAAE,KAAK,EAAE,OAAO,EAAE,CAAC;AAC5B,CAAC","sourcesContent":["import { useCallback, useLayoutEffect, useState } from \"react\";\nimport {\n clampDesktopIconPosition,\n type DesktopIconPosition,\n type DesktopSurfaceSize,\n} from \"./desktopState\";\n\nconst UNMEASURED: DesktopSurfaceSize = { height: 0, width: 0 };\n\n/**\n * The surface the icons lie on, measured from the icon layer, which fills\n * it, and a clamp that keeps an icon of a given size on it. Before the layer\n * is laid out (a zero size) positions are only kept off negative coordinates.\n */\nexport function useDesktopSurface(layer: HTMLElement | null) {\n const [surface, setSurface] = useState(UNMEASURED);\n useLayoutEffect(() => {\n if (!layer) {\n return;\n }\n const measure = () =>\n setSurface((current) =>\n current.width === layer.clientWidth &&\n current.height === layer.clientHeight\n ? current\n : { height: layer.clientHeight, width: layer.clientWidth },\n );\n measure();\n const observer = new ResizeObserver(measure);\n observer.observe(layer);\n return () => observer.disconnect();\n }, [layer]);\n\n const clamp = useCallback(\n (position: DesktopIconPosition, size: DesktopSurfaceSize) =>\n clampDesktopIconPosition(position, size, surface),\n [surface],\n );\n\n return { clamp, surface };\n}\n"]}
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Display Properties: a column of fieldsets. Each option is a labeled radio
|
|
3
|
+
* drawn as a card; the radio itself stays in the tab order and the
|
|
4
|
+
* accessibility tree but is visually hidden, and the card shows its focus and
|
|
5
|
+
* checked state.
|
|
6
|
+
*/
|
|
7
|
+
.display-properties {
|
|
8
|
+
display: flex;
|
|
9
|
+
flex-direction: column;
|
|
10
|
+
gap: var(--space-md);
|
|
11
|
+
box-sizing: border-box;
|
|
12
|
+
padding: var(--space-md);
|
|
13
|
+
font-size: var(--font-size-sm);
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
.display-properties-section {
|
|
17
|
+
display: flex;
|
|
18
|
+
flex-direction: column;
|
|
19
|
+
gap: var(--space-sm);
|
|
20
|
+
min-width: 0;
|
|
21
|
+
margin: 0;
|
|
22
|
+
padding: 0;
|
|
23
|
+
border: 0;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
.display-properties-section > legend {
|
|
27
|
+
margin-bottom: var(--space-sm);
|
|
28
|
+
padding: 0;
|
|
29
|
+
font-weight: 600;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
.display-properties-wallpapers {
|
|
33
|
+
display: grid;
|
|
34
|
+
grid-template-columns: repeat(auto-fill, minmax(7rem, 1fr));
|
|
35
|
+
gap: var(--space-sm);
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
.display-properties-themes {
|
|
39
|
+
display: flex;
|
|
40
|
+
flex-wrap: wrap;
|
|
41
|
+
gap: var(--space-sm);
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
.display-properties-wallpaper,
|
|
45
|
+
.display-properties-theme {
|
|
46
|
+
position: relative;
|
|
47
|
+
display: flex;
|
|
48
|
+
align-items: center;
|
|
49
|
+
gap: var(--space-xs);
|
|
50
|
+
box-sizing: border-box;
|
|
51
|
+
padding: var(--space-xs);
|
|
52
|
+
border: var(--border-width) solid var(--color-hairline);
|
|
53
|
+
border-radius: var(--app-radius-control);
|
|
54
|
+
cursor: pointer;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
.display-properties-wallpaper {
|
|
58
|
+
flex-direction: column;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
.display-properties-theme {
|
|
62
|
+
padding: var(--space-xs) var(--space-sm);
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
.display-properties-wallpaper:hover,
|
|
66
|
+
.display-properties-theme:hover {
|
|
67
|
+
background: var(--app-hover-surface);
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
.display-properties-wallpaper:has(:checked),
|
|
71
|
+
.display-properties-theme:has(:checked) {
|
|
72
|
+
border-color: var(--color-dark);
|
|
73
|
+
box-shadow: inset 0 0 0 1px var(--color-dark);
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
.display-properties-wallpaper:has(:focus-visible),
|
|
77
|
+
.display-properties-theme:has(:focus-visible) {
|
|
78
|
+
outline: 2px solid var(--color-dark);
|
|
79
|
+
outline-offset: 2px;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
.display-properties-input {
|
|
83
|
+
position: absolute;
|
|
84
|
+
width: 1px;
|
|
85
|
+
height: 1px;
|
|
86
|
+
margin: 0;
|
|
87
|
+
overflow: hidden;
|
|
88
|
+
clip-path: inset(50%);
|
|
89
|
+
white-space: nowrap;
|
|
90
|
+
opacity: 0;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
.display-properties-swatch {
|
|
94
|
+
position: relative;
|
|
95
|
+
width: 100%;
|
|
96
|
+
height: 3.5rem;
|
|
97
|
+
overflow: hidden;
|
|
98
|
+
border-radius: calc(var(--app-radius-control) - 2px);
|
|
99
|
+
box-shadow: inset 0 0 0 1px var(--color-hairline);
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
.display-properties-label {
|
|
103
|
+
overflow: hidden;
|
|
104
|
+
text-overflow: ellipsis;
|
|
105
|
+
white-space: nowrap;
|
|
106
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The display settings, for a host's Display Properties mini-app: the
|
|
3
|
+
* desktop's background, from the nearest {@link WallpaperProvider}, and the
|
|
4
|
+
* color theme, from the nearest {@link ThemeProvider}. Each choice applies at
|
|
5
|
+
* once. A section whose provider is missing, or that offers one option, is
|
|
6
|
+
* left out. It has no toolbar actions, so its window shows no toolbar row.
|
|
7
|
+
*/
|
|
8
|
+
export declare function DisplayProperties(): import("react").JSX.Element;
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { useId } from "react";
|
|
3
|
+
import { useOptionalTheme } from "../theme/ThemeProvider.js";
|
|
4
|
+
import { useOptionalWallpaper } from "../wallpaper/WallpaperProvider.js";
|
|
5
|
+
import { wallpaperStyle } from "../wallpaper/wallpapers.js";
|
|
6
|
+
import { useSuppressWindowToolbar } from "../window/CurrentWindowContext.js";
|
|
7
|
+
import "../wallpaper/Wallpaper.css";
|
|
8
|
+
import "./DisplayProperties.css";
|
|
9
|
+
function BackgroundSection() {
|
|
10
|
+
const wallpaper = useOptionalWallpaper();
|
|
11
|
+
const name = useId();
|
|
12
|
+
if (!wallpaper) {
|
|
13
|
+
return null;
|
|
14
|
+
}
|
|
15
|
+
return (_jsxs("fieldset", { className: "display-properties-section", children: [_jsx("legend", { children: "Background" }), _jsx("div", { className: "display-properties-wallpapers", children: wallpaper.wallpapers.map((option) => (_jsxs("label", { className: "display-properties-wallpaper", children: [_jsx("input", { checked: option.id === wallpaper.activeWallpaper.id, className: "display-properties-input", name: name, onChange: () => wallpaper.setWallpaper(option.id), type: "radio", value: option.id }), _jsx("span", { "aria-hidden": "true", className: "display-properties-swatch wallpaper-pattern", "data-pattern": option.tile ? "" : undefined, style: wallpaperStyle(option) }), _jsx("span", { className: "display-properties-label", children: option.label })] }, option.id))) })] }));
|
|
16
|
+
}
|
|
17
|
+
function ThemeSection() {
|
|
18
|
+
const theme = useOptionalTheme();
|
|
19
|
+
const name = useId();
|
|
20
|
+
if (!theme || theme.themes.length < 2) {
|
|
21
|
+
return null;
|
|
22
|
+
}
|
|
23
|
+
return (_jsxs("fieldset", { className: "display-properties-section", children: [_jsx("legend", { children: "Theme" }), _jsx("div", { className: "display-properties-themes", children: theme.themes.map((option) => (_jsxs("label", { className: "display-properties-theme", children: [_jsx("input", { checked: option.id === theme.activeTheme.id, className: "display-properties-input", name: name, onChange: () => theme.setTheme(option.id), type: "radio", value: option.id }), _jsx("span", { className: "display-properties-label", children: option.label })] }, option.id))) })] }));
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* The display settings, for a host's Display Properties mini-app: the
|
|
27
|
+
* desktop's background, from the nearest {@link WallpaperProvider}, and the
|
|
28
|
+
* color theme, from the nearest {@link ThemeProvider}. Each choice applies at
|
|
29
|
+
* once. A section whose provider is missing, or that offers one option, is
|
|
30
|
+
* left out. It has no toolbar actions, so its window shows no toolbar row.
|
|
31
|
+
*/
|
|
32
|
+
export function DisplayProperties() {
|
|
33
|
+
useSuppressWindowToolbar(true);
|
|
34
|
+
return (_jsxs("div", { className: "display-properties", children: [_jsx(BackgroundSection, {}), _jsx(ThemeSection, {})] }));
|
|
35
|
+
}
|
|
36
|
+
//# sourceMappingURL=DisplayProperties.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"DisplayProperties.js","sourceRoot":"","sources":["../../../home/runner/work/tearleads/tearleads/packages/windowing/src/display/DisplayProperties.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,OAAO,CAAC;AAC9B,OAAO,EAAE,gBAAgB,EAAE,MAAM,wBAAwB,CAAC;A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AAC;IACjC,MAAM,IAAI,GAAG,KAAK,EAAE,CAAC;IACrB,IAAI,CAAC,KAAK,IAAI,KAAK,CAAC,MAAM,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;QACtC,OAAO,IAAI,CAAC;IACd,CAAC;IACD,OAAO,CACL,oBAAU,SAAS,EAAC,4BAA4B,aAC9C,qCAAsB,EACtB,cAAK,SAAS,EAAC,2BAA2B,YACvC,KAAK,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,CAC5B,iBAAO,SAAS,EAAC,0BAA0B,aACzC,gBACE,OAAO,EAAE,MAAM,CAAC,EAAE,KAAK,KAAK,CAAC,WAAW,CAAC,EAAE,EAC3C,SAAS,EAAC,0BAA0B,EACpC,IAAI,EAAE,IAAI,EACV,QAAQ,EAAE,GAAG,EAAE,CAAC,KAAK,CAAC,QAAQ,CAAC,MAAM,CAAC,EAAE,CAAC,EACzC,IAAI,EAAC,OAAO,EACZ,KAAK,EAAE,MAAM,CAAC,EAAE,GAChB,EACF,eAAM,SAAS,EAAC,0BAA0B,YAAE,MAAM,CAAC,KAAK,GAAQ,KATjB,MAAM,CAAC,EAAE,CAUlD,CACT,CAAC,GACE,IACG,CACZ,CAAC;AACJ,CAAC;AAED;;;;;;GAMG;AACH,MAAM,UAAU,iBAAiB;IAC/B,wBAAwB,CAAC,IAAI,CAAC,CAAC;IAC/B,OAAO,CACL,eAAK,SAAS,EAAC,oBAAoB,aACjC,KAAC,iBAAiB,KAAG,EACrB,KAAC,YAAY,KAAG,IACZ,CACP,CAAC;AACJ,CAAC","sourcesContent":["import { useId } from \"react\";\nimport { useOptionalTheme } from \"../theme/ThemeProvider\";\nimport { useOptionalWallpaper } from \"../wallpaper/WallpaperProvider\";\nimport { wallpaperStyle } from \"../wallpaper/wallpapers\";\nimport { useSuppressWindowToolbar } from \"../window/CurrentWindowContext\";\nimport \"../wallpaper/Wallpaper.css\";\nimport \"./DisplayProperties.css\";\n\nfunction BackgroundSection() {\n const wallpaper = useOptionalWallpaper();\n const name = useId();\n if (!wallpaper) {\n return null;\n }\n return (\n <fieldset className=\"display-properties-section\">\n <legend>Background</legend>\n <div className=\"display-properties-wallpapers\">\n {wallpaper.wallpapers.map((option) => (\n <label className=\"display-properties-wallpaper\" key={option.id}>\n <input\n checked={option.id === wallpaper.activeWallpaper.id}\n className=\"display-properties-input\"\n name={name}\n onChange={() => wallpaper.setWallpaper(option.id)}\n type=\"radio\"\n value={option.id}\n />\n <span\n aria-hidden=\"true\"\n className=\"display-properties-swatch wallpaper-pattern\"\n data-pattern={option.tile ? \"\" : undefined}\n style={wallpaperStyle(option)}\n />\n <span className=\"display-properties-label\">{option.label}</span>\n </label>\n ))}\n </div>\n </fieldset>\n );\n}\n\nfunction ThemeSection() {\n const theme = useOptionalTheme();\n const name = useId();\n if (!theme || theme.themes.length < 2) {\n return null;\n }\n return (\n <fieldset className=\"display-properties-section\">\n <legend>Theme</legend>\n <div className=\"display-properties-themes\">\n {theme.themes.map((option) => (\n <label className=\"display-properties-theme\" key={option.id}>\n <input\n checked={option.id === theme.activeTheme.id}\n className=\"display-properties-input\"\n name={name}\n onChange={() => theme.setTheme(option.id)}\n type=\"radio\"\n value={option.id}\n />\n <span className=\"display-properties-label\">{option.label}</span>\n </label>\n ))}\n </div>\n </fieldset>\n );\n}\n\n/**\n * The display settings, for a host's Display Properties mini-app: the\n * desktop's background, from the nearest {@link WallpaperProvider}, and the\n * color theme, from the nearest {@link ThemeProvider}. Each choice applies at\n * once. A section whose provider is missing, or that offers one option, is\n * left out. It has no toolbar actions, so its window shows no toolbar row.\n */\nexport function DisplayProperties() {\n useSuppressWindowToolbar(true);\n return (\n <div className=\"display-properties\">\n <BackgroundSection />\n <ThemeSection />\n </div>\n );\n}\n"]}
|
package/index.d.ts
CHANGED
|
@@ -1,4 +1,9 @@
|
|
|
1
1
|
export { createRequiredContext, type RequiredContext, } from "./createRequiredContext.js";
|
|
2
|
+
export type { DesktopIconMenuItem } from "./desktop/DesktopIconMenu.js";
|
|
3
|
+
export { DesktopIcons, type DesktopIconsProps, } from "./desktop/DesktopIcons.js";
|
|
4
|
+
export type { DesktopIconPosition, DesktopState, } from "./desktop/desktopState.js";
|
|
5
|
+
export { createMemoryDesktopStateStorage, createOpfsDesktopStateStorage, type DesktopStateStorage, type OpfsDesktopStateStorageOptions, } from "./desktop/desktopStateStorage.js";
|
|
6
|
+
export { DisplayProperties } from "./display/DisplayProperties.js";
|
|
2
7
|
export { type WindowingIcons, WindowingIconsProvider, } from "./icons/WindowingIcons.js";
|
|
3
8
|
export type { WindowingIcon, WindowingIconProps } from "./icons/windowingIcon.js";
|
|
4
9
|
export { ROUTED_TABLET_BREAKPOINT_PX, ROUTED_TABLET_QUERY, WINDOWED_LAYOUT_MIN_WIDTH_PX, } from "./launcher/breakpoints.js";
|
|
@@ -28,6 +33,10 @@ export { SidebarResizeHandle, useSidebarResize } from "./sidebar/SidebarResize.j
|
|
|
28
33
|
export { ThemeProvider, useOptionalTheme, useTheme, } from "./theme/ThemeProvider.js";
|
|
29
34
|
export { ThemeSwitch } from "./theme/ThemeSwitch.js";
|
|
30
35
|
export type { DefaultTheme, ThemeDefinition, ThemeScheme, } from "./theme/themes.js";
|
|
36
|
+
export { DesktopWallpaper, type DesktopWallpaperProps, } from "./wallpaper/DesktopWallpaper.js";
|
|
37
|
+
export { BLOCKS_WALLPAPER, CHEVRON_WALLPAPER, HARLEQUIN_WALLPAPER, HONEYCOMB_WALLPAPER, PLAIN_WALLPAPER, TRIANGLES_WALLPAPER, } from "./wallpaper/tessellations.js";
|
|
38
|
+
export { useOptionalWallpaper, useWallpaper, WallpaperProvider, } from "./wallpaper/WallpaperProvider.js";
|
|
39
|
+
export type { WallpaperDefinition, WallpaperTile, } from "./wallpaper/wallpapers.js";
|
|
31
40
|
export { CurrentWindowProvider, useCurrentWindow, useSuppressWindowToolbar, useWindowBackground, useWindowContentSize, } from "./window/CurrentWindowContext.js";
|
|
32
41
|
export { Window, type WindowContentBoundary } from "./window/Window.js";
|
|
33
42
|
export { WindowTitleBarActionButtons } from "./window/WindowChromeActions.js";
|
package/index.js
CHANGED
|
@@ -1,9 +1,14 @@
|
|
|
1
1
|
import "./tokens.css";
|
|
2
2
|
// The public windowing API: window state, window chrome and its registration
|
|
3
3
|
// hooks, the menu and sidebar primitives the chrome renders with, a taskbar's
|
|
4
|
-
// start menu and theme switch, the icons the chrome draws,
|
|
5
|
-
// mini-apps that shows them in windows or in the routed (iPad / phone) shell
|
|
4
|
+
// start menu and theme switch, the icons the chrome draws, a launcher of
|
|
5
|
+
// mini-apps that shows them in windows or in the routed (iPad / phone) shell,
|
|
6
|
+
// and desktop icons that open them, with a storage adapter for their layout,
|
|
7
|
+
// over a wallpaper chosen in Display Properties.
|
|
6
8
|
export { createRequiredContext, } from "./createRequiredContext.js";
|
|
9
|
+
export { DesktopIcons, } from "./desktop/DesktopIcons.js";
|
|
10
|
+
export { createMemoryDesktopStateStorage, createOpfsDesktopStateStorage, } from "./desktop/desktopStateStorage.js";
|
|
11
|
+
export { DisplayProperties } from "./display/DisplayProperties.js";
|
|
7
12
|
export { WindowingIconsProvider, } from "./icons/WindowingIcons.js";
|
|
8
13
|
export { ROUTED_TABLET_BREAKPOINT_PX, ROUTED_TABLET_QUERY, WINDOWED_LAYOUT_MIN_WIDTH_PX, } from "./launcher/breakpoints.js";
|
|
9
14
|
export { DEFAULT_MINI_APP_POSITION, LauncherNavigationProvider, useLauncherNavigationActions, useLauncherNavigationState, useMiniAppRouteSegments, useOptionalLauncherNavigationState, } from "./launcher/LauncherNavigationProvider.js";
|
|
@@ -30,6 +35,9 @@ export { RoutedPaneOverlayHostProvider, useRoutedPaneOverlayHost, } from "./rout
|
|
|
30
35
|
export { SidebarResizeHandle, useSidebarResize } from "./sidebar/SidebarResize.js";
|
|
31
36
|
export { ThemeProvider, useOptionalTheme, useTheme, } from "./theme/ThemeProvider.js";
|
|
32
37
|
export { ThemeSwitch } from "./theme/ThemeSwitch.js";
|
|
38
|
+
export { DesktopWallpaper, } from "./wallpaper/DesktopWallpaper.js";
|
|
39
|
+
export { BLOCKS_WALLPAPER, CHEVRON_WALLPAPER, HARLEQUIN_WALLPAPER, HONEYCOMB_WALLPAPER, PLAIN_WALLPAPER, TRIANGLES_WALLPAPER, } from "./wallpaper/tessellations.js";
|
|
40
|
+
export { useOptionalWallpaper, useWallpaper, WallpaperProvider, } from "./wallpaper/WallpaperProvider.js";
|
|
33
41
|
export { CurrentWindowProvider, useCurrentWindow, useSuppressWindowToolbar, useWindowBackground, useWindowContentSize, } from "./window/CurrentWindowContext.js";
|
|
34
42
|
export { Window } from "./window/Window.js";
|
|
35
43
|
export { WindowTitleBarActionButtons } from "./window/WindowChromeActions.js";
|