@domicile-desktop/manganese-bar-module-google-messages 0.0.0-alpha-2f651ffb23f7
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 +33 -0
- package/package.json +56 -0
- package/src/Messages.tsx +198 -0
- package/src/bar-item.tsx +36 -0
- package/src/desk-messages.ts +36 -0
- package/src/from-messages.ts +10 -0
- package/src/page-bars.ts +38 -0
- package/styled-system/css/conditions.mjs +36 -0
- package/styled-system/css/css.d.ts +22 -0
- package/styled-system/css/css.mjs +45 -0
- package/styled-system/css/cva.d.ts +6 -0
- package/styled-system/css/cva.mjs +87 -0
- package/styled-system/css/cx.d.ts +5 -0
- package/styled-system/css/cx.mjs +15 -0
- package/styled-system/css/index.d.ts +5 -0
- package/styled-system/css/index.mjs +4 -0
- package/styled-system/css/sva.d.ts +4 -0
- package/styled-system/css/sva.mjs +46 -0
- package/styled-system/helpers.mjs +328 -0
- package/styled-system/jsx/aspect-ratio.d.ts +10 -0
- package/styled-system/jsx/aspect-ratio.mjs +14 -0
- package/styled-system/jsx/bleed.d.ts +10 -0
- package/styled-system/jsx/bleed.mjs +14 -0
- package/styled-system/jsx/box.d.ts +10 -0
- package/styled-system/jsx/box.mjs +14 -0
- package/styled-system/jsx/center.d.ts +10 -0
- package/styled-system/jsx/center.mjs +14 -0
- package/styled-system/jsx/circle.d.ts +10 -0
- package/styled-system/jsx/circle.mjs +14 -0
- package/styled-system/jsx/container.d.ts +10 -0
- package/styled-system/jsx/container.mjs +14 -0
- package/styled-system/jsx/cq.d.ts +10 -0
- package/styled-system/jsx/cq.mjs +14 -0
- package/styled-system/jsx/create-style-context.d.ts +54 -0
- package/styled-system/jsx/create-style-context.mjs +121 -0
- package/styled-system/jsx/divider.d.ts +10 -0
- package/styled-system/jsx/divider.mjs +14 -0
- package/styled-system/jsx/factory-helper.mjs +22 -0
- package/styled-system/jsx/factory.d.ts +3 -0
- package/styled-system/jsx/factory.mjs +89 -0
- package/styled-system/jsx/flex.d.ts +10 -0
- package/styled-system/jsx/flex.mjs +14 -0
- package/styled-system/jsx/float.d.ts +10 -0
- package/styled-system/jsx/float.mjs +14 -0
- package/styled-system/jsx/grid-item.d.ts +10 -0
- package/styled-system/jsx/grid-item.mjs +14 -0
- package/styled-system/jsx/grid.d.ts +10 -0
- package/styled-system/jsx/grid.mjs +14 -0
- package/styled-system/jsx/hstack.d.ts +10 -0
- package/styled-system/jsx/hstack.mjs +14 -0
- package/styled-system/jsx/index.d.ts +25 -0
- package/styled-system/jsx/index.mjs +23 -0
- package/styled-system/jsx/is-valid-prop.d.ts +11 -0
- package/styled-system/jsx/is-valid-prop.mjs +17 -0
- package/styled-system/jsx/link-overlay.d.ts +10 -0
- package/styled-system/jsx/link-overlay.mjs +14 -0
- package/styled-system/jsx/spacer.d.ts +10 -0
- package/styled-system/jsx/spacer.mjs +14 -0
- package/styled-system/jsx/square.d.ts +10 -0
- package/styled-system/jsx/square.mjs +14 -0
- package/styled-system/jsx/stack.d.ts +10 -0
- package/styled-system/jsx/stack.mjs +14 -0
- package/styled-system/jsx/visually-hidden.d.ts +10 -0
- package/styled-system/jsx/visually-hidden.mjs +14 -0
- package/styled-system/jsx/vstack.d.ts +10 -0
- package/styled-system/jsx/vstack.mjs +14 -0
- package/styled-system/jsx/wrap.d.ts +10 -0
- package/styled-system/jsx/wrap.mjs +14 -0
- package/styled-system/patterns/aspect-ratio.d.ts +20 -0
- package/styled-system/patterns/aspect-ratio.mjs +38 -0
- package/styled-system/patterns/bleed.d.ts +21 -0
- package/styled-system/patterns/bleed.mjs +24 -0
- package/styled-system/patterns/box.d.ts +20 -0
- package/styled-system/patterns/box.mjs +15 -0
- package/styled-system/patterns/center.d.ts +20 -0
- package/styled-system/patterns/center.mjs +21 -0
- package/styled-system/patterns/circle.d.ts +20 -0
- package/styled-system/patterns/circle.mjs +25 -0
- package/styled-system/patterns/container.d.ts +20 -0
- package/styled-system/patterns/container.mjs +21 -0
- package/styled-system/patterns/cq.d.ts +21 -0
- package/styled-system/patterns/cq.mjs +21 -0
- package/styled-system/patterns/divider.d.ts +22 -0
- package/styled-system/patterns/divider.mjs +25 -0
- package/styled-system/patterns/flex.d.ts +26 -0
- package/styled-system/patterns/flex.mjs +26 -0
- package/styled-system/patterns/float.d.ts +23 -0
- package/styled-system/patterns/float.mjs +52 -0
- package/styled-system/patterns/grid-item.d.ts +25 -0
- package/styled-system/patterns/grid-item.mjs +25 -0
- package/styled-system/patterns/grid.d.ts +24 -0
- package/styled-system/patterns/grid.mjs +27 -0
- package/styled-system/patterns/hstack.d.ts +21 -0
- package/styled-system/patterns/hstack.mjs +24 -0
- package/styled-system/patterns/index.d.ts +21 -0
- package/styled-system/patterns/index.mjs +20 -0
- package/styled-system/patterns/link-overlay.d.ts +20 -0
- package/styled-system/patterns/link-overlay.mjs +24 -0
- package/styled-system/patterns/spacer.d.ts +20 -0
- package/styled-system/patterns/spacer.mjs +25 -0
- package/styled-system/patterns/square.d.ts +20 -0
- package/styled-system/patterns/square.mjs +24 -0
- package/styled-system/patterns/stack.d.ts +23 -0
- package/styled-system/patterns/stack.mjs +24 -0
- package/styled-system/patterns/visually-hidden.d.ts +20 -0
- package/styled-system/patterns/visually-hidden.mjs +18 -0
- package/styled-system/patterns/vstack.d.ts +21 -0
- package/styled-system/patterns/vstack.mjs +24 -0
- package/styled-system/patterns/wrap.d.ts +24 -0
- package/styled-system/patterns/wrap.mjs +25 -0
- package/styled-system/recipes/control.d.ts +31 -0
- package/styled-system/recipes/control.mjs +35 -0
- package/styled-system/recipes/create-recipe.mjs +82 -0
- package/styled-system/recipes/index.d.ts +2 -0
- package/styled-system/recipes/index.mjs +1 -0
- package/styled-system/tokens/index.d.ts +9 -0
- package/styled-system/tokens/index.mjs +49656 -0
- package/styled-system/tokens/tokens.d.ts +72 -0
- package/styled-system/types/composition.d.ts +227 -0
- package/styled-system/types/conditions.d.ts +322 -0
- package/styled-system/types/csstype.d.ts +22570 -0
- package/styled-system/types/global.d.ts +20 -0
- package/styled-system/types/index.d.ts +8 -0
- package/styled-system/types/jsx.d.ts +69 -0
- package/styled-system/types/parts.d.ts +8 -0
- package/styled-system/types/pattern.d.ts +78 -0
- package/styled-system/types/prop-type.d.ts +268 -0
- package/styled-system/types/recipe.d.ts +181 -0
- package/styled-system/types/selectors.d.ts +59 -0
- package/styled-system/types/static-css.d.ts +56 -0
- package/styled-system/types/style-props.d.ts +8089 -0
- package/styled-system/types/system-types.d.ts +151 -0
package/README.md
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
# @domicile-desktop/manganese-bar-module-google-messages
|
|
2
|
+
|
|
3
|
+
A manganese bar item: Google Messages in a panel, with a count of its new
|
|
4
|
+
messages.
|
|
5
|
+
|
|
6
|
+
## Use
|
|
7
|
+
|
|
8
|
+
Put `<GoogleMessages />` in a column of
|
|
9
|
+
[`runManganese`](../shell-manganese/README.md)'s `bar`. No default bar has it.
|
|
10
|
+
|
|
11
|
+
```tsx
|
|
12
|
+
import { DEFAULT_BAR, runManganese } from "@domicile-desktop/manganese";
|
|
13
|
+
import { GoogleMessages } from "@domicile-desktop/manganese-bar-module-google-messages";
|
|
14
|
+
|
|
15
|
+
export const Shell = runManganese({
|
|
16
|
+
bar: {
|
|
17
|
+
...DEFAULT_BAR,
|
|
18
|
+
right: [<GoogleMessages key="messages" />, ...DEFAULT_BAR.right],
|
|
19
|
+
},
|
|
20
|
+
});
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
Open the panel once to pair it with the phone: scan the QR code, or sign in
|
|
24
|
+
with Google. Then allow Messages' notifications when it asks.
|
|
25
|
+
|
|
26
|
+
What it shows, and how it keeps the page:
|
|
27
|
+
[TOP-BAR.md](../shell-manganese/docs/TOP-BAR.md#google-messages).
|
|
28
|
+
|
|
29
|
+
## Test
|
|
30
|
+
|
|
31
|
+
```sh
|
|
32
|
+
bun run turbo test --filter @domicile-desktop/manganese-bar-module-google-messages
|
|
33
|
+
```
|
package/package.json
ADDED
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
{
|
|
2
|
+
"dependencies": {
|
|
3
|
+
"@domicile-desktop/component-library": "0.0.0-alpha-2f651ffb23f7",
|
|
4
|
+
"@domicile-desktop/manganese-bar": "0.0.0-alpha-2f651ffb23f7",
|
|
5
|
+
"@domicile-desktop/manganese-host": "0.0.0-alpha-2f651ffb23f7",
|
|
6
|
+
"@domicile-desktop/manganese-page-requests": "0.0.0-alpha-2f651ffb23f7",
|
|
7
|
+
"@domicile-desktop/sdk": "0.0.0-alpha-2f651ffb23f7",
|
|
8
|
+
"@pandacss/dev": "^1.12.1",
|
|
9
|
+
"@phosphor-icons/react": "^2.1.10",
|
|
10
|
+
"react": "^19.2.8"
|
|
11
|
+
},
|
|
12
|
+
"description": "A manganese bar item: Google Messages in a panel, with a count of its new messages.",
|
|
13
|
+
"devDependencies": {
|
|
14
|
+
"@cprussin/tsconfig": "^5.0.0",
|
|
15
|
+
"@domicile-desktop/test-support": "0.0.1",
|
|
16
|
+
"@pandacss/preset-panda": "^1.12.1",
|
|
17
|
+
"@testing-library/react": "^16.3.3",
|
|
18
|
+
"@testing-library/user-event": "^14.6.7",
|
|
19
|
+
"@types/bun": "^1.4.2",
|
|
20
|
+
"@types/react": "^19.2.18",
|
|
21
|
+
"@types/react-dom": "^19.2.7",
|
|
22
|
+
"postcss": "^8.5.28",
|
|
23
|
+
"typescript": "^7.0.2"
|
|
24
|
+
},
|
|
25
|
+
"engines": {
|
|
26
|
+
"bun": ">=1.4.2",
|
|
27
|
+
"node": ">=24"
|
|
28
|
+
},
|
|
29
|
+
"exports": {
|
|
30
|
+
".": "./src/bar-item.tsx"
|
|
31
|
+
},
|
|
32
|
+
"files": [
|
|
33
|
+
"src/**",
|
|
34
|
+
"styled-system/**",
|
|
35
|
+
"!src/**/*.test.ts",
|
|
36
|
+
"!src/**/*.test.tsx"
|
|
37
|
+
],
|
|
38
|
+
"license": "MIT",
|
|
39
|
+
"name": "@domicile-desktop/manganese-bar-module-google-messages",
|
|
40
|
+
"private": false,
|
|
41
|
+
"publishConfig": {
|
|
42
|
+
"access": "public"
|
|
43
|
+
},
|
|
44
|
+
"repository": {
|
|
45
|
+
"directory": "packages/manganese-bar-module-google-messages",
|
|
46
|
+
"type": "git",
|
|
47
|
+
"url": "git+https://github.com/cprussin/domicile.git"
|
|
48
|
+
},
|
|
49
|
+
"scripts": {
|
|
50
|
+
"prepare": "panda codegen --silent",
|
|
51
|
+
"test:types": "tsc --noEmit",
|
|
52
|
+
"test:unit": "bun test"
|
|
53
|
+
},
|
|
54
|
+
"type": "module",
|
|
55
|
+
"version": "0.0.0-alpha-2f651ffb23f7"
|
|
56
|
+
}
|
package/src/Messages.tsx
ADDED
|
@@ -0,0 +1,198 @@
|
|
|
1
|
+
/// <reference types="@domicile-desktop/manganese-host/domicile-elements" />
|
|
2
|
+
|
|
3
|
+
import type { createHandle } from "@domicile-desktop/component-library/Popover";
|
|
4
|
+
import { Popover } from "@domicile-desktop/component-library/Popover";
|
|
5
|
+
import { useKeepsKeyboard } from "@domicile-desktop/manganese-bar/panel-keyboard";
|
|
6
|
+
import { PermissionAsk } from "@domicile-desktop/manganese-page-requests/PermissionAsk";
|
|
7
|
+
import { usePermissionRequest } from "@domicile-desktop/manganese-page-requests/usePermissionRequest";
|
|
8
|
+
import { WEBVIEW_FOCUS_REQUEST_EVENT } from "@domicile-desktop/sdk/webview-element";
|
|
9
|
+
import { ChatCircleTextIcon } from "@phosphor-icons/react/dist/ssr/ChatCircleText";
|
|
10
|
+
import { useEffect, useState } from "react";
|
|
11
|
+
import { css } from "../styled-system/css";
|
|
12
|
+
import { hstack } from "../styled-system/patterns";
|
|
13
|
+
|
|
14
|
+
const MESSAGES_URL = "https://messages.google.com/web/";
|
|
15
|
+
|
|
16
|
+
// Storage of its own, kept across restarts, so the pairing lasts and a
|
|
17
|
+
// Messages tab in a browser window is a separate session.
|
|
18
|
+
const PARTITION = "persist:google-messages";
|
|
19
|
+
|
|
20
|
+
type Handle = ReturnType<typeof createHandle>;
|
|
21
|
+
|
|
22
|
+
type Props = {
|
|
23
|
+
/** Whether this bar draws the page. Exactly one bar does. */
|
|
24
|
+
drawsPage: boolean;
|
|
25
|
+
/** Opens the panel from any bar. */
|
|
26
|
+
handle: Handle;
|
|
27
|
+
/** The panel opened. */
|
|
28
|
+
onOpen: () => void;
|
|
29
|
+
/** The bar's monitor. */
|
|
30
|
+
screen: string;
|
|
31
|
+
/** How many of Messages' notifications are uncleared. */
|
|
32
|
+
unread: number;
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* The item: a button with the count of new messages, which opens Messages in
|
|
37
|
+
* a panel. The bar that draws the page holds the panel; the others' buttons
|
|
38
|
+
* open it under themselves.
|
|
39
|
+
*/
|
|
40
|
+
export const Messages = ({
|
|
41
|
+
drawsPage,
|
|
42
|
+
handle,
|
|
43
|
+
onOpen,
|
|
44
|
+
screen,
|
|
45
|
+
unread,
|
|
46
|
+
}: Props) => {
|
|
47
|
+
const id = triggerId(screen);
|
|
48
|
+
const trigger = (
|
|
49
|
+
<Popover.Trigger handle={handle} id={id} render={count(unread)} />
|
|
50
|
+
);
|
|
51
|
+
return drawsPage ? (
|
|
52
|
+
<>
|
|
53
|
+
{trigger}
|
|
54
|
+
<Panel handle={handle} onOpen={onOpen} triggerId={id} />
|
|
55
|
+
</>
|
|
56
|
+
) : (
|
|
57
|
+
trigger
|
|
58
|
+
);
|
|
59
|
+
};
|
|
60
|
+
|
|
61
|
+
type PanelProps = {
|
|
62
|
+
handle: Handle;
|
|
63
|
+
onOpen: () => void;
|
|
64
|
+
/** The id of this bar's button, to open under on the page's request. */
|
|
65
|
+
triggerId: string;
|
|
66
|
+
};
|
|
67
|
+
|
|
68
|
+
/**
|
|
69
|
+
* The panel, kept mounted so the page keeps running while it is closed. It
|
|
70
|
+
* keeps the keyboard while open, for typing into the page.
|
|
71
|
+
*/
|
|
72
|
+
const Panel = ({ handle, onOpen, triggerId }: PanelProps) => {
|
|
73
|
+
const [open, setOpen] = useState(false);
|
|
74
|
+
useKeepsKeyboard(open);
|
|
75
|
+
return (
|
|
76
|
+
<Popover
|
|
77
|
+
align="end"
|
|
78
|
+
flush
|
|
79
|
+
handle={handle}
|
|
80
|
+
keepMounted
|
|
81
|
+
onOpenChange={(opened) => {
|
|
82
|
+
setOpen(opened);
|
|
83
|
+
if (opened) {
|
|
84
|
+
onOpen();
|
|
85
|
+
}
|
|
86
|
+
}}
|
|
87
|
+
>
|
|
88
|
+
<Page
|
|
89
|
+
onShow={() => {
|
|
90
|
+
handle.open(triggerId);
|
|
91
|
+
}}
|
|
92
|
+
/>
|
|
93
|
+
</Popover>
|
|
94
|
+
);
|
|
95
|
+
};
|
|
96
|
+
|
|
97
|
+
/**
|
|
98
|
+
* Messages' page, with its permission requests asked above it. `onShow` is
|
|
99
|
+
* the page asking to be shown, as on a press of its notification.
|
|
100
|
+
*/
|
|
101
|
+
const Page = ({ onShow }: { onShow: () => void }) => {
|
|
102
|
+
// `null` because React passes it to a callback ref on unmount.
|
|
103
|
+
const [view, setView] = useState<HTMLWebViewElement | null>(null);
|
|
104
|
+
const request = usePermissionRequest(view);
|
|
105
|
+
|
|
106
|
+
useEffect(() => {
|
|
107
|
+
if (view === null) {
|
|
108
|
+
return undefined;
|
|
109
|
+
} else {
|
|
110
|
+
view.addEventListener(WEBVIEW_FOCUS_REQUEST_EVENT, onShow);
|
|
111
|
+
return () => {
|
|
112
|
+
view.removeEventListener(WEBVIEW_FOCUS_REQUEST_EVENT, onShow);
|
|
113
|
+
};
|
|
114
|
+
}
|
|
115
|
+
}, [onShow, view]);
|
|
116
|
+
|
|
117
|
+
return (
|
|
118
|
+
<>
|
|
119
|
+
{request !== undefined && (
|
|
120
|
+
<div className={askStyles}>
|
|
121
|
+
<PermissionAsk
|
|
122
|
+
asker={new URL(request.origin).host}
|
|
123
|
+
request={request}
|
|
124
|
+
/>
|
|
125
|
+
</div>
|
|
126
|
+
)}
|
|
127
|
+
<webview
|
|
128
|
+
className={viewStyles}
|
|
129
|
+
partition={PARTITION}
|
|
130
|
+
ref={setView}
|
|
131
|
+
src={MESSAGES_URL}
|
|
132
|
+
/>
|
|
133
|
+
</>
|
|
134
|
+
);
|
|
135
|
+
};
|
|
136
|
+
|
|
137
|
+
/** The bar's button, lit with the count while there are new messages. */
|
|
138
|
+
const count = (unread: number) => (
|
|
139
|
+
<button
|
|
140
|
+
aria-label={
|
|
141
|
+
unread === 0 ? "Messages" : `Messages: ${unread.toString()} new`
|
|
142
|
+
}
|
|
143
|
+
className={itemStyles}
|
|
144
|
+
data-unread={unread > 0}
|
|
145
|
+
type="button"
|
|
146
|
+
>
|
|
147
|
+
<ChatCircleTextIcon aria-hidden size={15} weight="bold" />
|
|
148
|
+
{unread > 0 && <span className={figureStyles}>{unread}</span>}
|
|
149
|
+
</button>
|
|
150
|
+
);
|
|
151
|
+
|
|
152
|
+
/** The id of `screen`'s button, for opening the panel under it. */
|
|
153
|
+
const triggerId = (screen: string) => `google-messages-${screen}`;
|
|
154
|
+
|
|
155
|
+
// Matches the Gmail item, lit as it is for unread mail.
|
|
156
|
+
const itemStyles = hstack({
|
|
157
|
+
_hover: {
|
|
158
|
+
backgroundColor: "color-mix(in oklab, white 16%, transparent)",
|
|
159
|
+
},
|
|
160
|
+
"&[data-unread=true]": {
|
|
161
|
+
backgroundColor: "color-mix(in oklab, white 24%, transparent)",
|
|
162
|
+
},
|
|
163
|
+
backgroundColor: "transparent",
|
|
164
|
+
blockSize: 7,
|
|
165
|
+
borderRadius: "full",
|
|
166
|
+
borderStyle: "none",
|
|
167
|
+
color: "inherit",
|
|
168
|
+
cursor: "pointer",
|
|
169
|
+
flexShrink: 0,
|
|
170
|
+
font: "inherit",
|
|
171
|
+
gap: 1,
|
|
172
|
+
justifyContent: "center",
|
|
173
|
+
paddingBlock: 0,
|
|
174
|
+
// The ends' radius, so the icon and count stay clear of the curve.
|
|
175
|
+
paddingInline: 3,
|
|
176
|
+
transition: "background-color {durations.fast} {easings.default}",
|
|
177
|
+
});
|
|
178
|
+
|
|
179
|
+
// 10px to match the bar's other figures; no font-size token fits. Fixed-width
|
|
180
|
+
// digits, so the bar does not shift as the count changes.
|
|
181
|
+
const figureStyles = css({
|
|
182
|
+
fontSize: "0.625rem",
|
|
183
|
+
fontVariantNumeric: "tabular-nums",
|
|
184
|
+
fontWeight: "semibold",
|
|
185
|
+
whiteSpace: "nowrap",
|
|
186
|
+
});
|
|
187
|
+
|
|
188
|
+
// The panel is flush, so the request gets its own inset.
|
|
189
|
+
const askStyles = css({ padding: 2 });
|
|
190
|
+
|
|
191
|
+
// Wide enough for Messages' list and conversation side by side, within the
|
|
192
|
+
// screen. `display: block` avoids a line-box gap under it in the panel.
|
|
193
|
+
const viewStyles = css({
|
|
194
|
+
blockSize: "min({spacing.160}, 80vh)",
|
|
195
|
+
borderStyle: "none",
|
|
196
|
+
display: "block",
|
|
197
|
+
inlineSize: "min({spacing.240}, 90vw)",
|
|
198
|
+
});
|
package/src/bar-item.tsx
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { useBar } from "@domicile-desktop/manganese-bar/bar-context";
|
|
2
|
+
import { useDomicile } from "@domicile-desktop/manganese-host/domicile-context";
|
|
3
|
+
import { useSharedWatch } from "@domicile-desktop/manganese-host/useSharedWatch";
|
|
4
|
+
import { useEffect, useSyncExternalStore } from "react";
|
|
5
|
+
|
|
6
|
+
import { deskMessages } from "./desk-messages";
|
|
7
|
+
import { Messages } from "./Messages";
|
|
8
|
+
|
|
9
|
+
const NONE: readonly number[] = [];
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Google Messages in a panel, with a count of its new messages. Not in the
|
|
13
|
+
* default bar.
|
|
14
|
+
*
|
|
15
|
+
* The page stays loaded while the panel is closed, so its notifications keep
|
|
16
|
+
* coming. One bar draws it; every bar's item opens it.
|
|
17
|
+
*/
|
|
18
|
+
export const GoogleMessages = () => {
|
|
19
|
+
const domicile = useDomicile();
|
|
20
|
+
const { screen } = useBar();
|
|
21
|
+
const desk = deskMessages(domicile);
|
|
22
|
+
useEffect(() => desk.bars.show(screen), [desk, screen]);
|
|
23
|
+
const drawer = useSyncExternalStore(desk.bars.subscribe, desk.bars.drawer);
|
|
24
|
+
const unread = useSharedWatch(desk.notifications) ?? NONE;
|
|
25
|
+
return (
|
|
26
|
+
<Messages
|
|
27
|
+
drawsPage={drawer === screen}
|
|
28
|
+
handle={desk.handle}
|
|
29
|
+
onOpen={() => {
|
|
30
|
+
domicile.dismissNotifications(unread);
|
|
31
|
+
}}
|
|
32
|
+
screen={screen}
|
|
33
|
+
unread={unread.length}
|
|
34
|
+
/>
|
|
35
|
+
);
|
|
36
|
+
};
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { createHandle } from "@domicile-desktop/component-library/Popover";
|
|
2
|
+
import { perHost } from "@domicile-desktop/manganese-host/per-host";
|
|
3
|
+
import type { SharedWatch } from "@domicile-desktop/manganese-host/shared-watch";
|
|
4
|
+
import { sharedWatch } from "@domicile-desktop/manganese-host/shared-watch";
|
|
5
|
+
import { watchHost } from "@domicile-desktop/manganese-host/watch-host";
|
|
6
|
+
|
|
7
|
+
import { messagesFrom } from "./from-messages";
|
|
8
|
+
import type { PageBars } from "./page-bars";
|
|
9
|
+
import { pageBars } from "./page-bars";
|
|
10
|
+
|
|
11
|
+
/** What every bar's item shares. */
|
|
12
|
+
export type DeskMessages = {
|
|
13
|
+
bars: PageBars;
|
|
14
|
+
/** Opens the one panel from any bar's item. */
|
|
15
|
+
handle: ReturnType<typeof createHandle>;
|
|
16
|
+
/** The ids of Messages' uncleared notifications. */
|
|
17
|
+
notifications: SharedWatch<readonly number[]>;
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
/** The item's shared state, once per desktop. */
|
|
21
|
+
export const deskMessages = perHost(
|
|
22
|
+
(domicile): DeskMessages => ({
|
|
23
|
+
bars: pageBars(),
|
|
24
|
+
handle: createHandle(),
|
|
25
|
+
notifications: sharedWatch((onIds: (ids: readonly number[]) => void) =>
|
|
26
|
+
watchHost(
|
|
27
|
+
domicile,
|
|
28
|
+
"notificationschanged",
|
|
29
|
+
(host) => host.notifications ?? undefined,
|
|
30
|
+
(items) => {
|
|
31
|
+
onIds(messagesFrom(items));
|
|
32
|
+
},
|
|
33
|
+
),
|
|
34
|
+
),
|
|
35
|
+
}),
|
|
36
|
+
);
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { DomicileNotification } from "@domicile-desktop/sdk/domicile-host";
|
|
2
|
+
|
|
3
|
+
/** The site Messages' notifications come from, as the engine names it. */
|
|
4
|
+
export const MESSAGES_SITE = "messages.google.com";
|
|
5
|
+
|
|
6
|
+
/** The ids of Messages' notifications among `items`. */
|
|
7
|
+
export const messagesFrom = (
|
|
8
|
+
items: readonly DomicileNotification[],
|
|
9
|
+
): readonly number[] =>
|
|
10
|
+
items.filter(({ appName }) => appName === MESSAGES_SITE).map(({ id }) => id);
|
package/src/page-bars.ts
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Which bars show the item, so exactly one draws the page. A second page would
|
|
3
|
+
* be a second Messages session, which Messages refuses.
|
|
4
|
+
*/
|
|
5
|
+
export type PageBars = {
|
|
6
|
+
/** Adds `screen`'s bar until the returned function is called. */
|
|
7
|
+
show: (screen: string) => () => void;
|
|
8
|
+
/** The bar that draws the page: the first still showing the item. */
|
|
9
|
+
drawer: () => string | undefined;
|
|
10
|
+
/** Calls `onChange` when `drawer` changes, until the returned function. */
|
|
11
|
+
subscribe: (onChange: () => void) => () => void;
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
export const pageBars = (): PageBars => {
|
|
15
|
+
const state: { shown: readonly string[] } = { shown: [] };
|
|
16
|
+
const listeners = new Set<() => void>();
|
|
17
|
+
const changed = (shown: readonly string[]) => {
|
|
18
|
+
state.shown = shown;
|
|
19
|
+
for (const onChange of listeners) {
|
|
20
|
+
onChange();
|
|
21
|
+
}
|
|
22
|
+
};
|
|
23
|
+
return {
|
|
24
|
+
drawer: () => state.shown[0],
|
|
25
|
+
show: (screen) => {
|
|
26
|
+
changed([...state.shown, screen]);
|
|
27
|
+
return () => {
|
|
28
|
+
changed(state.shown.filter((shown) => shown !== screen));
|
|
29
|
+
};
|
|
30
|
+
},
|
|
31
|
+
subscribe: (onChange) => {
|
|
32
|
+
listeners.add(onChange);
|
|
33
|
+
return () => {
|
|
34
|
+
listeners.delete(onChange);
|
|
35
|
+
};
|
|
36
|
+
},
|
|
37
|
+
};
|
|
38
|
+
};
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { withoutSpace } from '../helpers.mjs';
|
|
2
|
+
|
|
3
|
+
const conditionsStr = "_hover,_focus,_focusWithin,_focusVisible,_disabled,_active,_visited,_target,_readOnly,_readWrite,_empty,_checked,_enabled,_expanded,_highlighted,_complete,_incomplete,_dragging,_before,_after,_firstLetter,_firstLine,_marker,_selection,_file,_backdrop,_first,_last,_only,_even,_odd,_firstOfType,_lastOfType,_onlyOfType,_peerFocus,_peerHover,_peerActive,_peerFocusWithin,_peerFocusVisible,_peerDisabled,_peerChecked,_peerInvalid,_peerExpanded,_peerPlaceholderShown,_groupFocus,_groupHover,_groupActive,_groupFocusWithin,_groupFocusVisible,_groupDisabled,_groupChecked,_groupExpanded,_groupInvalid,_indeterminate,_required,_valid,_invalid,_autofill,_inRange,_outOfRange,_placeholder,_placeholderShown,_pressed,_selected,_grabbed,_underValue,_overValue,_atValue,_default,_optional,_open,_closed,_fullscreen,_loading,_hidden,_current,_currentPage,_currentStep,_today,_unavailable,_rangeStart,_rangeEnd,_now,_topmost,_motionReduce,_motionSafe,_print,_landscape,_portrait,_dark,_light,_osDark,_osLight,_highContrast,_lessContrast,_moreContrast,_ltr,_rtl,_scrollbar,_scrollbarThumb,_scrollbarTrack,_horizontal,_vertical,_icon,_starting,_noscript,_invertedColors,_activeEnabled,_contrastHigh,_hoverEnabled,_pointerCoarse,_touchOverlay,_touchSheet,sm,smOnly,smDown,md,mdOnly,mdDown,lg,lgOnly,lgDown,xl,xlOnly,xlDown,2xl,2xlOnly,2xlDown,smToMd,smToLg,smToXl,smTo2xl,mdToLg,mdToXl,mdTo2xl,lgToXl,lgTo2xl,xlTo2xl,@/xs,@/sm,@/md,@/lg,@/xl,@/2xl,@/3xl,@/4xl,@/5xl,@/6xl,@/7xl,@/8xl,base"
|
|
4
|
+
const conditions = new Set(conditionsStr.split(','))
|
|
5
|
+
|
|
6
|
+
const conditionRegex = /^@|&|&$/
|
|
7
|
+
|
|
8
|
+
export function isCondition(value){
|
|
9
|
+
return conditions.has(value) || conditionRegex.test(value)
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
const underscoreRegex = /^_/
|
|
13
|
+
const conditionsSelectorRegex = /&|@/
|
|
14
|
+
|
|
15
|
+
export function finalizeConditions(paths){
|
|
16
|
+
return paths.map((path) => {
|
|
17
|
+
if (conditions.has(path)){
|
|
18
|
+
return path.replace(underscoreRegex, '')
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
if (conditionsSelectorRegex.test(path)){
|
|
22
|
+
return `[${withoutSpace(path.trim())}]`
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
return path
|
|
26
|
+
})}
|
|
27
|
+
|
|
28
|
+
export function sortConditions(paths){
|
|
29
|
+
return paths.sort((a, b) => {
|
|
30
|
+
const aa = isCondition(a)
|
|
31
|
+
const bb = isCondition(b)
|
|
32
|
+
if (aa && !bb) return 1
|
|
33
|
+
if (!aa && bb) return -1
|
|
34
|
+
return 0
|
|
35
|
+
})
|
|
36
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/* eslint-disable */
|
|
2
|
+
import type { SystemStyleObject } from '../types/index';
|
|
3
|
+
|
|
4
|
+
type Styles = SystemStyleObject | undefined | null | false
|
|
5
|
+
|
|
6
|
+
interface CssRawFunction {
|
|
7
|
+
(styles: Styles): SystemStyleObject
|
|
8
|
+
(styles: Styles[]): SystemStyleObject
|
|
9
|
+
(...styles: Array<Styles | Styles[]>): SystemStyleObject
|
|
10
|
+
(styles: Styles): SystemStyleObject
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
interface CssFunction {
|
|
14
|
+
(styles: Styles): string
|
|
15
|
+
(styles: Styles[]): string
|
|
16
|
+
(...styles: Array<Styles | Styles[]>): string
|
|
17
|
+
(styles: Styles): string
|
|
18
|
+
|
|
19
|
+
raw: CssRawFunction
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export declare const css: CssFunction;
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { createCss, createMergeCss, hypenateProperty, withoutSpace } from '../helpers.mjs';
|
|
2
|
+
import { sortConditions, finalizeConditions } from './conditions.mjs';
|
|
3
|
+
|
|
4
|
+
const utilities = "aspectRatio:asp,boxDecorationBreak:bx-db,zIndex:z,boxSizing:bx-s,objectPosition:obj-p,objectFit:obj-f,overscrollBehavior:ovs-b,overscrollBehaviorX:ovs-bx,overscrollBehaviorY:ovs-by,position:pos/1,top:top,left:left,inset:inset,insetInline:inset-x/insetX,insetBlock:inset-y/insetY,insetBlockEnd:inset-be,insetBlockStart:inset-bs,insetInlineEnd:inset-e/insetEnd/end,insetInlineStart:inset-s/insetStart/start,right:right,bottom:bottom,float:float,visibility:vis,display:d,hideFrom:hide,hideBelow:show,flexBasis:flex-b,flex:flex,flexDirection:flex-d/flexDir,flexGrow:flex-g,flexShrink:flex-sh,gridTemplateColumns:grid-tc,gridTemplateRows:grid-tr,gridColumn:grid-c,gridRow:grid-r,gridColumnStart:grid-cs,gridColumnEnd:grid-ce,gridAutoFlow:grid-af,gridAutoColumns:grid-ac,gridAutoRows:grid-ar,gap:gap,gridGap:grid-g,gridRowGap:grid-rg,gridColumnGap:grid-cg,rowGap:rg,columnGap:cg,justifyContent:jc,alignContent:ac,alignItems:ai,alignSelf:as,padding:p/1,paddingLeft:pl/1,paddingRight:pr/1,paddingTop:pt/1,paddingBottom:pb/1,paddingBlock:py/1/paddingY,paddingBlockEnd:pbe,paddingBlockStart:pbs,paddingInline:px/paddingX/1,paddingInlineEnd:pe/1/paddingEnd,paddingInlineStart:ps/1/paddingStart,marginLeft:ml/1,marginRight:mr/1,marginTop:mt/1,marginBottom:mb/1,margin:m/1,marginBlock:my/1/marginY,marginBlockEnd:mbe,marginBlockStart:mbs,marginInline:mx/1/marginX,marginInlineEnd:me/1/marginEnd,marginInlineStart:ms/1/marginStart,spaceX:sx,spaceY:sy,outlineWidth:ring-w/ringWidth,outlineColor:ring-c/ringColor,outline:ring/1,outlineOffset:ring-o/ringOffset,focusRing:focus-ring,focusVisibleRing:focus-v-ring,focusRingColor:focus-ring-c,focusRingOffset:focus-ring-o,focusRingWidth:focus-ring-w,focusRingStyle:focus-ring-s,divideX:dvd-x,divideY:dvd-y,divideColor:dvd-c,divideStyle:dvd-s,width:w/1,inlineSize:w-is,minWidth:min-w/minW,minInlineSize:min-w-is,maxWidth:max-w/maxW,maxInlineSize:max-w-is,height:h/1,blockSize:h-bs,minHeight:min-h/minH,minBlockSize:min-h-bs,maxHeight:max-h/maxH,maxBlockSize:max-b,boxSize:size,color:c,fontFamily:ff,fontSize:fs,fontSizeAdjust:fs-a,fontPalette:fp,fontKerning:fk,fontFeatureSettings:ff-s,fontWeight:fw,fontSmoothing:fsmt,fontVariant:fv,fontVariantAlternates:fv-alt,fontVariantCaps:fv-caps,fontVariationSettings:fv-s,fontVariantNumeric:fv-num,letterSpacing:ls,lineHeight:lh,textAlign:ta,textDecoration:td,textDecorationColor:td-c,textEmphasisColor:te-c,textDecorationStyle:td-s,textDecorationThickness:td-t,textUnderlineOffset:tu-o,textTransform:tt,textIndent:ti,textShadow:tsh,textShadowColor:tsh-c/textShadowColor,WebkitTextFillColor:wktf-c,textOverflow:tov,verticalAlign:va,wordBreak:wb,textWrap:tw,truncate:trunc,lineClamp:lc,listStyleType:li-t,listStylePosition:li-pos,listStyleImage:li-img,listStyle:li-s,backgroundPosition:bg-p/bgPosition,backgroundPositionX:bg-p-x/bgPositionX,backgroundPositionY:bg-p-y/bgPositionY,backgroundAttachment:bg-a/bgAttachment,backgroundClip:bg-cp/bgClip,background:bg/1,backgroundColor:bg-c/bgColor,backgroundOrigin:bg-o/bgOrigin,backgroundImage:bg-i/bgImage,backgroundRepeat:bg-r/bgRepeat,backgroundBlendMode:bg-bm/bgBlendMode,backgroundSize:bg-s/bgSize,backgroundGradient:bg-grad/bgGradient,backgroundLinear:bg-linear/bgLinear,backgroundRadial:bg-radial/bgRadial,backgroundConic:bg-conic/bgConic,textGradient:txt-grad,gradientFromPosition:grad-from-pos,gradientToPosition:grad-to-pos,gradientFrom:grad-from,gradientTo:grad-to,gradientVia:grad-via,gradientViaPosition:grad-via-pos,borderRadius:bdr/rounded,borderTopLeftRadius:bdr-tl/roundedTopLeft,borderTopRightRadius:bdr-tr/roundedTopRight,borderBottomRightRadius:bdr-br/roundedBottomRight,borderBottomLeftRadius:bdr-bl/roundedBottomLeft,borderTopRadius:bdr-t/roundedTop,borderRightRadius:bdr-r/roundedRight,borderBottomRadius:bdr-b/roundedBottom,borderLeftRadius:bdr-l/roundedLeft,borderStartStartRadius:bdr-ss/roundedStartStart,borderStartEndRadius:bdr-se/roundedStartEnd,borderStartRadius:bdr-s/roundedStart,borderEndStartRadius:bdr-es/roundedEndStart,borderEndEndRadius:bdr-ee/roundedEndEnd,borderEndRadius:bdr-e/roundedEnd,border:bd,borderWidth:bd-w,borderTopWidth:bd-t-w,borderLeftWidth:bd-l-w,borderRightWidth:bd-r-w,borderBottomWidth:bd-b-w,borderBlockStartWidth:bd-bs-w,borderBlockEndWidth:bd-be-w,borderColor:bd-c,borderInline:bd-x/borderX,borderInlineWidth:bd-x-w/borderXWidth,borderInlineColor:bd-x-c/borderXColor,borderBlock:bd-y/borderY,borderBlockWidth:bd-y-w/borderYWidth,borderBlockColor:bd-y-c/borderYColor,borderLeft:bd-l,borderLeftColor:bd-l-c,borderInlineStart:bd-s/borderStart,borderInlineStartWidth:bd-s-w/borderStartWidth,borderInlineStartColor:bd-s-c/borderStartColor,borderRight:bd-r,borderRightColor:bd-r-c,borderInlineEnd:bd-e/borderEnd,borderInlineEndWidth:bd-e-w/borderEndWidth,borderInlineEndColor:bd-e-c/borderEndColor,borderTop:bd-t,borderTopColor:bd-t-c,borderBottom:bd-b,borderBottomColor:bd-b-c,borderBlockEnd:bd-be,borderBlockEndColor:bd-be-c,borderBlockStart:bd-bs,borderBlockStartColor:bd-bs-c,opacity:op,boxShadow:bx-sh/shadow,boxShadowColor:bx-sh-c/shadowColor,mixBlendMode:mix-bm,filter:filter,brightness:brightness,contrast:contrast,grayscale:grayscale,hueRotate:hue-rotate,invert:invert,saturate:saturate,sepia:sepia,dropShadow:drop-shadow,blur:blur,backdropFilter:bkdp,backdropBlur:bkdp-blur,backdropBrightness:bkdp-brightness,backdropContrast:bkdp-contrast,backdropGrayscale:bkdp-grayscale,backdropHueRotate:bkdp-hue-rotate,backdropInvert:bkdp-invert,backdropOpacity:bkdp-opacity,backdropSaturate:bkdp-saturate,backdropSepia:bkdp-sepia,borderCollapse:bd-cl,borderSpacing:bd-sp,borderSpacingX:bd-sx,borderSpacingY:bd-sy,tableLayout:tbl,transitionTimingFunction:trs-tmf,transitionDelay:trs-dly,transitionDuration:trs-dur,transitionProperty:trs-prop,transition:trs,animation:anim,animationName:anim-n,animationTimingFunction:anim-tmf,animationDuration:anim-dur,animationDelay:anim-dly,animationPlayState:anim-ps,animationComposition:anim-comp,animationFillMode:anim-fm,animationDirection:anim-dir,animationIterationCount:anim-ic,animationRange:anim-r,animationState:anim-s,animationRangeStart:anim-rs,animationRangeEnd:anim-re,animationTimeline:anim-tl,transformOrigin:trf-o,transformBox:trf-b,transformStyle:trf-s,transform:trf,rotate:rotate,rotateX:rotate-x,rotateY:rotate-y,rotateZ:rotate-z,scale:scale,scaleX:scale-x,scaleY:scale-y,translate:translate,translateX:translate-x/x,translateY:translate-y/y,translateZ:translate-z/z,accentColor:ac-c,caretColor:ca-c,scrollBehavior:scr-bhv,scrollbar:scr-bar,scrollbarColor:scr-bar-c,scrollbarGutter:scr-bar-g,scrollbarWidth:scr-bar-w,scrollMargin:scr-m,scrollMarginLeft:scr-ml,scrollMarginRight:scr-mr,scrollMarginTop:scr-mt,scrollMarginBottom:scr-mb,scrollMarginBlock:scr-my/scrollMarginY,scrollMarginBlockEnd:scr-mbe,scrollMarginBlockStart:scr-mbt,scrollMarginInline:scr-mx/scrollMarginX,scrollMarginInlineEnd:scr-me,scrollMarginInlineStart:scr-ms,scrollPadding:scr-p,scrollPaddingBlock:scr-py/scrollPaddingY,scrollPaddingBlockStart:scr-pbs,scrollPaddingBlockEnd:scr-pbe,scrollPaddingInline:scr-px/scrollPaddingX,scrollPaddingInlineEnd:scr-pe,scrollPaddingInlineStart:scr-ps,scrollPaddingLeft:scr-pl,scrollPaddingRight:scr-pr,scrollPaddingTop:scr-pt,scrollPaddingBottom:scr-pb,scrollSnapAlign:scr-sa,scrollSnapStop:scrs-s,scrollSnapType:scrs-t,scrollSnapStrictness:scrs-strt,scrollSnapMargin:scrs-m,scrollSnapMarginTop:scrs-mt,scrollSnapMarginBottom:scrs-mb,scrollSnapMarginLeft:scrs-ml,scrollSnapMarginRight:scrs-mr,scrollSnapCoordinate:scrs-c,scrollSnapDestination:scrs-d,scrollSnapPointsX:scrs-px,scrollSnapPointsY:scrs-py,scrollSnapTypeX:scrs-tx,scrollSnapTypeY:scrs-ty,scrollTimeline:scrtl,scrollTimelineAxis:scrtl-a,scrollTimelineName:scrtl-n,touchAction:tch-a,userSelect:us,overflow:ov,overflowWrap:ov-wrap,overflowX:ov-x,overflowY:ov-y,overflowAnchor:ov-a,overflowBlock:ov-b,overflowInline:ov-i,overflowClipBox:ovcp-bx,overflowClipMargin:ovcp-m,overscrollBehaviorBlock:ovs-bb,overscrollBehaviorInline:ovs-bi,fill:fill,stroke:stk,strokeWidth:stk-w,strokeDasharray:stk-dsh,strokeDashoffset:stk-do,strokeLinecap:stk-lc,strokeLinejoin:stk-lj,strokeMiterlimit:stk-ml,strokeOpacity:stk-op,srOnly:sr,debug:debug,appearance:ap,backfaceVisibility:bfv,clipPath:cp-path,hyphens:hy,mask:msk,maskImage:msk-i,maskSize:msk-s,textSizeAdjust:txt-adj,container:cq,containerName:cq-n,containerType:cq-t,cursor:cursor,textStyle:textStyle"
|
|
5
|
+
|
|
6
|
+
const classNameByProp = new Map()
|
|
7
|
+
const shorthands = new Map()
|
|
8
|
+
utilities.split(',').forEach((utility) => {
|
|
9
|
+
const [prop, meta] = utility.split(':')
|
|
10
|
+
const [className, ...shorthandList] = meta.split('/')
|
|
11
|
+
classNameByProp.set(prop, className)
|
|
12
|
+
if (shorthandList.length) {
|
|
13
|
+
shorthandList.forEach((shorthand) => {
|
|
14
|
+
shorthands.set(shorthand === '1' ? className : shorthand, prop)
|
|
15
|
+
})
|
|
16
|
+
}
|
|
17
|
+
})
|
|
18
|
+
|
|
19
|
+
const resolveShorthand = (prop) => shorthands.get(prop) || prop
|
|
20
|
+
|
|
21
|
+
const context = {
|
|
22
|
+
hash: true,
|
|
23
|
+
conditions: {
|
|
24
|
+
shift: sortConditions,
|
|
25
|
+
finalize: finalizeConditions,
|
|
26
|
+
breakpoints: { keys: ["base","sm","md","lg","xl","2xl"] }
|
|
27
|
+
},
|
|
28
|
+
utility: {
|
|
29
|
+
|
|
30
|
+
transform: (prop, value) => {
|
|
31
|
+
const key = resolveShorthand(prop)
|
|
32
|
+
const propKey = classNameByProp.get(key) || hypenateProperty(key)
|
|
33
|
+
return { className: `${propKey}_${withoutSpace(value)}` }
|
|
34
|
+
},
|
|
35
|
+
hasShorthand: true,
|
|
36
|
+
toHash: (path, hashFn) => hashFn(path.join(":")),
|
|
37
|
+
resolveShorthand: resolveShorthand,
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
const cssFn = createCss(context)
|
|
42
|
+
export const css = (...styles) => cssFn(mergeCss(...styles))
|
|
43
|
+
css.raw = (...styles) => mergeCss(...styles)
|
|
44
|
+
|
|
45
|
+
export const { mergeCss, assignCss } = createMergeCss(context)
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
import { compact, mergeProps, memo, splitProps, uniq } from '../helpers.mjs';
|
|
2
|
+
import { css, mergeCss } from './css.mjs';
|
|
3
|
+
|
|
4
|
+
const defaults = (conf) => ({
|
|
5
|
+
base: {},
|
|
6
|
+
variants: {},
|
|
7
|
+
defaultVariants: {},
|
|
8
|
+
compoundVariants: [],
|
|
9
|
+
...conf,
|
|
10
|
+
})
|
|
11
|
+
|
|
12
|
+
export function cva(config) {
|
|
13
|
+
const { base, variants, defaultVariants, compoundVariants } = defaults(config)
|
|
14
|
+
const getVariantProps = (variants) => ({ ...defaultVariants, ...compact(variants) })
|
|
15
|
+
|
|
16
|
+
function resolve(props = {}) {
|
|
17
|
+
const computedVariants = getVariantProps(props)
|
|
18
|
+
let variantCss = { ...base }
|
|
19
|
+
for (const [key, value] of Object.entries(computedVariants)) {
|
|
20
|
+
if (variants[key]?.[value]) {
|
|
21
|
+
variantCss = mergeCss(variantCss, variants[key][value])
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
const compoundVariantCss = getCompoundVariantCss(compoundVariants, computedVariants)
|
|
25
|
+
return mergeCss(variantCss, compoundVariantCss)
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
function merge(__cva) {
|
|
29
|
+
const override = defaults(__cva.config)
|
|
30
|
+
const variantKeys = uniq(__cva.variantKeys, Object.keys(variants))
|
|
31
|
+
return cva({
|
|
32
|
+
base: mergeCss(base, override.base),
|
|
33
|
+
variants: Object.fromEntries(
|
|
34
|
+
variantKeys.map((key) => [key, mergeCss(variants[key], override.variants[key])]),
|
|
35
|
+
),
|
|
36
|
+
defaultVariants: mergeProps(defaultVariants, override.defaultVariants),
|
|
37
|
+
compoundVariants: [...compoundVariants, ...override.compoundVariants],
|
|
38
|
+
})
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
function cvaFn(props) {
|
|
42
|
+
return css(resolve(props))
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
const variantKeys = Object.keys(variants)
|
|
46
|
+
|
|
47
|
+
function splitVariantProps(props) {
|
|
48
|
+
return splitProps(props, variantKeys)
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
const variantMap = Object.fromEntries(Object.entries(variants).map(([key, value]) => [key, Object.keys(value)]))
|
|
52
|
+
|
|
53
|
+
return Object.assign(memo(cvaFn), {
|
|
54
|
+
__cva__: true,
|
|
55
|
+
variantMap,
|
|
56
|
+
variantKeys,
|
|
57
|
+
raw: resolve,
|
|
58
|
+
config,
|
|
59
|
+
merge,
|
|
60
|
+
splitVariantProps,
|
|
61
|
+
getVariantProps
|
|
62
|
+
})
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
export function getCompoundVariantCss(compoundVariants, variantMap) {
|
|
66
|
+
let result = {}
|
|
67
|
+
compoundVariants.forEach((compoundVariant) => {
|
|
68
|
+
const isMatching = Object.entries(compoundVariant).every(([key, value]) => {
|
|
69
|
+
if (key === 'css') return true
|
|
70
|
+
|
|
71
|
+
const values = Array.isArray(value) ? value : [value]
|
|
72
|
+
return values.some((value) => variantMap[key] === value)
|
|
73
|
+
})
|
|
74
|
+
|
|
75
|
+
if (isMatching) {
|
|
76
|
+
result = mergeCss(result, compoundVariant.css)
|
|
77
|
+
}
|
|
78
|
+
})
|
|
79
|
+
|
|
80
|
+
return result
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
export function assertCompoundVariant(name, compoundVariants, variants, prop) {
|
|
84
|
+
if (compoundVariants.length > 0 && typeof variants?.[prop] === 'object') {
|
|
85
|
+
throw new Error(`[recipe:${name}:${prop}] Conditions are not supported when using compound variants.`)
|
|
86
|
+
}
|
|
87
|
+
}
|