@cairntale/chimeling-react 0.0.0 → 1.0.0-alpha.0
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/CHANGELOG.md +7 -0
- package/dist/components/chimeling.d.ts +12 -0
- package/dist/components/chimeling.js +13 -0
- package/dist/components/chimeling.js.map +1 -0
- package/dist/components/index.d.ts +7 -0
- package/dist/components/index.js +7 -0
- package/dist/components/logo.js +19 -0
- package/dist/components/logo.js.map +1 -0
- package/dist/components/popover.d.ts +7 -0
- package/dist/components/popover.js +36 -0
- package/dist/components/popover.js.map +1 -0
- package/dist/components/provider.d.ts +11 -0
- package/dist/components/provider.js +24 -0
- package/dist/components/provider.js.map +1 -0
- package/dist/components/root.d.ts +20 -0
- package/dist/components/root.js +66 -0
- package/dist/components/root.js.map +1 -0
- package/dist/components/trigger.d.ts +7 -0
- package/dist/components/trigger.js +23 -0
- package/dist/components/trigger.js.map +1 -0
- package/dist/hooks/index.js +4 -0
- package/dist/hooks/use-client.d.ts +6 -0
- package/dist/hooks/use-client.js +10 -0
- package/dist/hooks/use-client.js.map +1 -0
- package/dist/hooks/use-resolved-user-presence.d.ts +27 -0
- package/dist/hooks/use-resolved-user-presence.js +22 -0
- package/dist/hooks/use-resolved-user-presence.js.map +1 -0
- package/dist/index.d.ts +10 -0
- package/dist/index.js +11 -0
- package/dist/lib/config.js +11 -0
- package/dist/lib/config.js.map +1 -0
- package/dist/lib/context.js +14 -0
- package/dist/lib/context.js.map +1 -0
- package/dist/lib/format-activity-duration.js +26 -0
- package/dist/lib/format-activity-duration.js.map +1 -0
- package/dist/lib/icon-url.js +9 -0
- package/dist/lib/icon-url.js.map +1 -0
- package/dist/lib/presence-key.js +14 -0
- package/dist/lib/presence-key.js.map +1 -0
- package/dist/lib/showable-presence.d.ts +12 -0
- package/dist/lib/showable-presence.js +12 -0
- package/dist/lib/showable-presence.js.map +1 -0
- package/dist/lib/widget-context.d.ts +6 -0
- package/dist/lib/widget-context.js +14 -0
- package/dist/lib/widget-context.js.map +1 -0
- package/dist/react/package.js +6 -0
- package/dist/react/package.js.map +1 -0
- package/dist/sdk/src/client/client/client.gen.js +174 -0
- package/dist/sdk/src/client/client/client.gen.js.map +1 -0
- package/dist/sdk/src/client/client/index.js +5 -0
- package/dist/sdk/src/client/client/utils.gen.js +177 -0
- package/dist/sdk/src/client/client/utils.gen.js.map +1 -0
- package/dist/sdk/src/client/core/auth.gen.js +12 -0
- package/dist/sdk/src/client/core/auth.gen.js.map +1 -0
- package/dist/sdk/src/client/core/bodySerializer.gen.js +6 -0
- package/dist/sdk/src/client/core/bodySerializer.gen.js.map +1 -0
- package/dist/sdk/src/client/core/params.gen.js +9 -0
- package/dist/sdk/src/client/core/params.gen.js.map +1 -0
- package/dist/sdk/src/client/core/pathSerializer.gen.js +82 -0
- package/dist/sdk/src/client/core/pathSerializer.gen.js.map +1 -0
- package/dist/sdk/src/client/core/serverSentEvents.gen.js +96 -0
- package/dist/sdk/src/client/core/serverSentEvents.gen.js.map +1 -0
- package/dist/sdk/src/client/core/utils.gen.js +78 -0
- package/dist/sdk/src/client/core/utils.gen.js.map +1 -0
- package/dist/types.d.ts +6 -0
- package/package.json +34 -9
- package/src/components/chimeling.ts +9 -0
- package/src/components/index.ts +8 -0
- package/src/components/logo.tsx +18 -0
- package/src/components/popover.tsx +44 -0
- package/src/components/provider.tsx +26 -0
- package/src/components/root.tsx +91 -0
- package/src/components/trigger.tsx +33 -0
- package/src/hooks/index.ts +4 -0
- package/src/hooks/use-client.ts +8 -0
- package/src/hooks/use-resolved-user-presence.ts +27 -0
- package/src/index.ts +4 -0
- package/src/lib/config.ts +9 -0
- package/src/lib/context.ts +24 -0
- package/src/lib/format-activity-duration.ts +21 -0
- package/src/lib/icon-url.ts +5 -0
- package/src/lib/presence-key.ts +5 -0
- package/src/lib/showable-presence.ts +22 -0
- package/src/lib/widget-context.ts +33 -0
- package/src/types.ts +3 -0
- package/tsconfig.json +14 -0
- package/tsdown.config.ts +13 -0
- package/turbo.json +10 -0
- package/index.js +0 -1
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { ChimelingRoot } from "./root.js";
|
|
2
|
+
import { ChimelingTrigger } from "./trigger.js";
|
|
3
|
+
import { ChimelingPopover } from "./popover.js";
|
|
4
|
+
//#region src/components/chimeling.d.ts
|
|
5
|
+
declare const Chimeling: {
|
|
6
|
+
Root: typeof ChimelingRoot;
|
|
7
|
+
Trigger: typeof ChimelingTrigger;
|
|
8
|
+
Popover: typeof ChimelingPopover;
|
|
9
|
+
};
|
|
10
|
+
//#endregion
|
|
11
|
+
export { Chimeling };
|
|
12
|
+
//# sourceMappingURL=chimeling.d.ts.map
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { ChimelingRoot } from "./root.js";
|
|
2
|
+
import { ChimelingTrigger } from "./trigger.js";
|
|
3
|
+
import { ChimelingPopover } from "./popover.js";
|
|
4
|
+
//#region src/components/chimeling.ts
|
|
5
|
+
const Chimeling = {
|
|
6
|
+
Root: ChimelingRoot,
|
|
7
|
+
Trigger: ChimelingTrigger,
|
|
8
|
+
Popover: ChimelingPopover
|
|
9
|
+
};
|
|
10
|
+
//#endregion
|
|
11
|
+
export { Chimeling };
|
|
12
|
+
|
|
13
|
+
//# sourceMappingURL=chimeling.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"chimeling.js","names":[],"sources":["../../src/components/chimeling.ts"],"sourcesContent":["import { ChimelingRoot } from './root'\nimport { ChimelingTrigger } from './trigger'\nimport { ChimelingPopover } from './popover'\n\nexport const Chimeling = {\n Root: ChimelingRoot,\n Trigger: ChimelingTrigger,\n Popover: ChimelingPopover,\n}\n"],"mappings":";;;;AAIA,MAAa,YAAY;CACvB,MAAM;CACN,SAAS;CACT,SAAS;AACX"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { ChimelingProvider } from "./provider.js";
|
|
2
|
+
import { PresenceActivity, ShowablePresence } from "../lib/showable-presence.js";
|
|
3
|
+
import { ChimelingRoot, ChimelingRootProps } from "./root.js";
|
|
4
|
+
import { ChimelingTrigger, ChimelingTriggerProps } from "./trigger.js";
|
|
5
|
+
import { ChimelingPopover, ChimelingPopoverProps } from "./popover.js";
|
|
6
|
+
import { Chimeling } from "./chimeling.js";
|
|
7
|
+
export { Chimeling, ChimelingPopover, type ChimelingPopoverProps, ChimelingProvider, ChimelingRoot, type ChimelingRootProps, ChimelingTrigger, type ChimelingTriggerProps, type PresenceActivity, type ShowablePresence };
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { ChimelingProvider } from "./provider.js";
|
|
3
|
+
import { ChimelingRoot } from "./root.js";
|
|
4
|
+
import { ChimelingTrigger } from "./trigger.js";
|
|
5
|
+
import { ChimelingPopover } from "./popover.js";
|
|
6
|
+
import { Chimeling } from "./chimeling.js";
|
|
7
|
+
export { Chimeling, ChimelingPopover, ChimelingProvider, ChimelingRoot, ChimelingTrigger };
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { jsx } from "react/jsx-runtime";
|
|
2
|
+
//#region src/components/logo.tsx
|
|
3
|
+
function Logo() {
|
|
4
|
+
return /* @__PURE__ */ jsx("svg", {
|
|
5
|
+
width: "1em",
|
|
6
|
+
height: "1em",
|
|
7
|
+
viewBox: "0 0 804 804",
|
|
8
|
+
fill: "none",
|
|
9
|
+
xmlns: "http://www.w3.org/2000/svg",
|
|
10
|
+
children: /* @__PURE__ */ jsx("path", {
|
|
11
|
+
d: "M402 0C600.823 0 762 161.177 762 360C762 525.32 650.565 664.61 498.711 706.86C489.497 709.423 484.89 710.705 482.445 713.923C480 717.141 480 721.695 480 730.802V774.682C480 790.69 480 798.695 474.745 802.266C469.489 805.837 462.047 802.89 447.163 796.996L340.163 754.62C332.821 751.712 329.149 750.259 327.075 747.205C325 744.152 325 740.204 325 732.306V731.08C325 721.947 325 717.381 322.545 714.159C320.09 710.937 315.467 709.664 306.221 707.119C153.891 665.181 42 525.658 42 360C42 161.177 203.177 0 402 0ZM402 243C245.151 243 118 345.975 118 473C118 569.681 191.658 652.427 296.005 686.445C308.733 690.594 315.097 692.669 320.049 689.075C325 685.482 325 678.444 325 664.368V475.318C325 459.31 325 451.305 330.255 447.734C335.511 444.163 342.953 447.11 357.837 453.004L464.837 495.38C472.179 498.288 475.851 499.741 477.925 502.795C480 505.848 480 509.796 480 517.694V664.044C480 678.16 480 685.217 484.968 688.81C489.936 692.403 496.311 690.3 509.059 686.095C612.843 651.863 686 569.351 686 473C686 345.975 558.849 243 402 243Z",
|
|
12
|
+
fill: "currentColor"
|
|
13
|
+
})
|
|
14
|
+
});
|
|
15
|
+
}
|
|
16
|
+
//#endregion
|
|
17
|
+
export { Logo as default };
|
|
18
|
+
|
|
19
|
+
//# sourceMappingURL=logo.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"logo.js","names":[],"sources":["../../src/components/logo.tsx"],"sourcesContent":["function Logo() {\n return (\n <svg\n width=\"1em\"\n height=\"1em\"\n viewBox=\"0 0 804 804\"\n fill=\"none\"\n xmlns=\"http://www.w3.org/2000/svg\"\n >\n <path\n d=\"M402 0C600.823 0 762 161.177 762 360C762 525.32 650.565 664.61 498.711 706.86C489.497 709.423 484.89 710.705 482.445 713.923C480 717.141 480 721.695 480 730.802V774.682C480 790.69 480 798.695 474.745 802.266C469.489 805.837 462.047 802.89 447.163 796.996L340.163 754.62C332.821 751.712 329.149 750.259 327.075 747.205C325 744.152 325 740.204 325 732.306V731.08C325 721.947 325 717.381 322.545 714.159C320.09 710.937 315.467 709.664 306.221 707.119C153.891 665.181 42 525.658 42 360C42 161.177 203.177 0 402 0ZM402 243C245.151 243 118 345.975 118 473C118 569.681 191.658 652.427 296.005 686.445C308.733 690.594 315.097 692.669 320.049 689.075C325 685.482 325 678.444 325 664.368V475.318C325 459.31 325 451.305 330.255 447.734C335.511 444.163 342.953 447.11 357.837 453.004L464.837 495.38C472.179 498.288 475.851 499.741 477.925 502.795C480 505.848 480 509.796 480 517.694V664.044C480 678.16 480 685.217 484.968 688.81C489.936 692.403 496.311 690.3 509.059 686.095C612.843 651.863 686 569.351 686 473C686 345.975 558.849 243 402 243Z\"\n fill=\"currentColor\"\n />\n </svg>\n )\n}\n\nexport default Logo\n"],"mappings":";;AAAA,SAAS,OAAO;CACd,OACE,oBAAC,OAAD;EACE,OAAM;EACN,QAAO;EACP,SAAQ;EACR,MAAK;EACL,OAAM;EAEN,UAAA,oBAAC,QAAD;GACE,GAAE;GACF,MAAK;EACN,CAAA;CACE,CAAA;AAET"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { PopoverPopupProps } from "@base-ui/react/popover";
|
|
2
|
+
//#region src/components/popover.d.ts
|
|
3
|
+
type ChimelingPopoverProps = Pick<PopoverPopupProps, 'className' | 'style'>;
|
|
4
|
+
declare function ChimelingPopover({ className, style }: ChimelingPopoverProps): import("react").JSX.Element | null;
|
|
5
|
+
//#endregion
|
|
6
|
+
export { ChimelingPopover, ChimelingPopoverProps };
|
|
7
|
+
//# sourceMappingURL=popover.d.ts.map
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { useWidgetContext } from "../lib/widget-context.js";
|
|
3
|
+
import { formatActivityDuration } from "../lib/format-activity-duration.js";
|
|
4
|
+
import { iconImageUrl } from "../lib/icon-url.js";
|
|
5
|
+
import Logo from "./logo.js";
|
|
6
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
7
|
+
import { Popover } from "@base-ui/react/popover";
|
|
8
|
+
//#region src/components/popover.tsx
|
|
9
|
+
function ChimelingPopover({ className, style }) {
|
|
10
|
+
const { showable, now, poweredBy, placement, baseUrl } = useWidgetContext();
|
|
11
|
+
if (!showable) return null;
|
|
12
|
+
const { gerund, appName, iconHash, startedAt } = showable.activity;
|
|
13
|
+
return /* @__PURE__ */ jsx(Popover.Portal, { children: /* @__PURE__ */ jsx(Popover.Positioner, {
|
|
14
|
+
side: placement.side,
|
|
15
|
+
align: placement.align,
|
|
16
|
+
sideOffset: placement.sideOffset,
|
|
17
|
+
children: /* @__PURE__ */ jsxs(Popover.Popup, {
|
|
18
|
+
className,
|
|
19
|
+
style,
|
|
20
|
+
children: [
|
|
21
|
+
/* @__PURE__ */ jsx(Popover.Description, { children: gerund }),
|
|
22
|
+
/* @__PURE__ */ jsx(Popover.Title, { children: appName }),
|
|
23
|
+
/* @__PURE__ */ jsx("span", { children: formatActivityDuration(startedAt, now) }),
|
|
24
|
+
iconHash ? /* @__PURE__ */ jsx("img", {
|
|
25
|
+
src: iconImageUrl(baseUrl, iconHash),
|
|
26
|
+
alt: ""
|
|
27
|
+
}) : null,
|
|
28
|
+
poweredBy ? /* @__PURE__ */ jsxs("div", { children: ["Powered by ", /* @__PURE__ */ jsx(Logo, {})] }) : null
|
|
29
|
+
]
|
|
30
|
+
})
|
|
31
|
+
}) });
|
|
32
|
+
}
|
|
33
|
+
//#endregion
|
|
34
|
+
export { ChimelingPopover };
|
|
35
|
+
|
|
36
|
+
//# sourceMappingURL=popover.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"popover.js","names":[],"sources":["../../src/components/popover.tsx"],"sourcesContent":["'use client'\n\nimport { Popover } from '@base-ui/react/popover'\nimport type { PopoverPopupProps } from '@base-ui/react/popover'\nimport { formatActivityDuration } from '../lib/format-activity-duration'\nimport { iconImageUrl } from '../lib/icon-url'\nimport { useWidgetContext } from '../lib/widget-context'\nimport Logo from './logo'\n\n// TODO: decide whether to expose the rest of Base UI Popup props.\nexport type ChimelingPopoverProps = Pick<PopoverPopupProps, 'className' | 'style'>\n\nexport function ChimelingPopover({ className, style }: ChimelingPopoverProps) {\n const { showable, now, poweredBy, placement, baseUrl } = useWidgetContext()\n\n if (!showable) {\n return null\n }\n\n const { gerund, appName, iconHash, startedAt } = showable.activity\n\n return (\n <Popover.Portal>\n {/* TODO: decide whether to expose the rest of Base UI Positioner props. */}\n <Popover.Positioner\n side={placement.side}\n align={placement.align}\n sideOffset={placement.sideOffset}\n >\n <Popover.Popup className={className} style={style}>\n <Popover.Description>{gerund}</Popover.Description>\n <Popover.Title>{appName}</Popover.Title>\n <span>{formatActivityDuration(startedAt, now)}</span>\n {iconHash ? <img src={iconImageUrl(baseUrl, iconHash)} alt=\"\" /> : null}\n {poweredBy ? (\n <div>\n Powered by <Logo />\n </div>\n ) : null}\n </Popover.Popup>\n </Popover.Positioner>\n </Popover.Portal>\n )\n}\n"],"mappings":";;;;;;;;AAYA,SAAgB,iBAAiB,EAAE,WAAW,SAAgC;CAC5E,MAAM,EAAE,UAAU,KAAK,WAAW,WAAW,YAAY,iBAAiB;CAE1E,IAAI,CAAC,UACH,OAAO;CAGT,MAAM,EAAE,QAAQ,SAAS,UAAU,cAAc,SAAS;CAE1D,OACE,oBAAC,QAAQ,QAAT,EAAA,UAEE,oBAAC,QAAQ,YAAT;EACE,MAAM,UAAU;EAChB,OAAO,UAAU;EACjB,YAAY,UAAU;EAEtB,UAAA,qBAAC,QAAQ,OAAT;GAA0B;GAAkB;GAA5C,UAAA;IACE,oBAAC,QAAQ,aAAT,EAAA,UAAsB,OAA4B,CAAA;IAClD,oBAAC,QAAQ,OAAT,EAAA,UAAgB,QAAuB,CAAA;IACvC,oBAAC,QAAD,EAAA,UAAO,uBAAuB,WAAW,GAAG,EAAQ,CAAA;IACnD,WAAW,oBAAC,OAAD;KAAK,KAAK,aAAa,SAAS,QAAQ;KAAG,KAAI;IAAI,CAAA,IAAI;IAClE,YACC,qBAAC,OAAD,EAAA,UAAA,CAAK,eACQ,oBAAC,MAAD,CAAO,CAAA,CACf,EAAA,CAAA,IACH;GACS;;CACG,CAAA,EACN,CAAA;AAEpB"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { ReactNode } from "react";
|
|
2
|
+
//#region src/components/provider.d.ts
|
|
3
|
+
type ChimelingProviderProps = {
|
|
4
|
+
baseUrl?: string;
|
|
5
|
+
refreshInterval?: number;
|
|
6
|
+
children: ReactNode;
|
|
7
|
+
};
|
|
8
|
+
declare function ChimelingProvider({ baseUrl, refreshInterval, children }: ChimelingProviderProps): import("react").JSX.Element;
|
|
9
|
+
//#endregion
|
|
10
|
+
export { ChimelingProvider };
|
|
11
|
+
//# sourceMappingURL=provider.d.ts.map
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { createConfig } from "../sdk/src/client/client/utils.gen.js";
|
|
3
|
+
import { createClient } from "../sdk/src/client/client/client.gen.js";
|
|
4
|
+
import "../sdk/src/client/client/index.js";
|
|
5
|
+
import { DEFAULT_PRESENCE_REFRESH_INTERVAL } from "../lib/config.js";
|
|
6
|
+
import { ChimelingContext } from "../lib/context.js";
|
|
7
|
+
import { useMemo } from "react";
|
|
8
|
+
import { jsx } from "react/jsx-runtime";
|
|
9
|
+
//#region src/components/provider.tsx
|
|
10
|
+
function ChimelingProvider({ baseUrl, refreshInterval = DEFAULT_PRESENCE_REFRESH_INTERVAL, children }) {
|
|
11
|
+
const client = useMemo(() => createClient(createConfig({ baseUrl: baseUrl ?? "https://chimeling.app" })), [baseUrl]);
|
|
12
|
+
const value = useMemo(() => ({
|
|
13
|
+
client,
|
|
14
|
+
refreshInterval
|
|
15
|
+
}), [client, refreshInterval]);
|
|
16
|
+
return /* @__PURE__ */ jsx(ChimelingContext.Provider, {
|
|
17
|
+
value,
|
|
18
|
+
children
|
|
19
|
+
});
|
|
20
|
+
}
|
|
21
|
+
//#endregion
|
|
22
|
+
export { ChimelingProvider };
|
|
23
|
+
|
|
24
|
+
//# sourceMappingURL=provider.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"provider.js","names":[],"sources":["../../src/components/provider.tsx"],"sourcesContent":["'use client'\n\nimport { useMemo, type ReactNode } from 'react'\nimport { createClient, createConfig } from '../../../sdk/src/client/client'\nimport { DEFAULT_PRESENCE_REFRESH_INTERVAL } from '../lib/config'\nimport { ChimelingContext } from '../lib/context'\n\ntype ChimelingProviderProps = {\n baseUrl?: string\n refreshInterval?: number\n children: ReactNode\n}\n\nexport function ChimelingProvider({\n baseUrl,\n refreshInterval = DEFAULT_PRESENCE_REFRESH_INTERVAL,\n children,\n}: ChimelingProviderProps) {\n const client = useMemo(\n () => createClient(createConfig({ baseUrl: baseUrl ?? 'https://chimeling.app' })),\n [baseUrl],\n )\n const value = useMemo(() => ({ client, refreshInterval }), [client, refreshInterval])\n\n return <ChimelingContext.Provider value={value}>{children}</ChimelingContext.Provider>\n}\n"],"mappings":";;;;;;;;;AAaA,SAAgB,kBAAkB,EAChC,SACA,kBAAkB,mCAClB,YACyB;CACzB,MAAM,SAAS,cACP,aAAa,aAAa,EAAE,SAAS,WAAW,wBAAwB,CAAC,CAAC,GAChF,CAAC,OAAO,CACV;CACA,MAAM,QAAQ,eAAe;EAAE;EAAQ;CAAgB,IAAI,CAAC,QAAQ,eAAe,CAAC;CAEpF,OAAO,oBAAC,iBAAiB,UAAlB;EAAkC;EAAQ;CAAoC,CAAA;AACvF"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { GetResolvedUserPresenceResponse } from "../sdk/dist/types.gen.js";
|
|
2
|
+
import { ShowablePresence } from "../lib/showable-presence.js";
|
|
3
|
+
import { WidgetPlacement } from "../lib/widget-context.js";
|
|
4
|
+
import { ReactNode } from "react";
|
|
5
|
+
//#region src/components/root.d.ts
|
|
6
|
+
type ChimelingRootProps = WidgetPlacement & {
|
|
7
|
+
userId: string;
|
|
8
|
+
children: ReactNode;
|
|
9
|
+
poweredBy?: boolean;
|
|
10
|
+
openOnHover?: boolean;
|
|
11
|
+
hoverOpenDelay?: number;
|
|
12
|
+
hoverCloseDelay?: number;
|
|
13
|
+
onReady?: (presence: ShowablePresence) => void;
|
|
14
|
+
presence?: GetResolvedUserPresenceResponse;
|
|
15
|
+
refreshInterval?: number;
|
|
16
|
+
};
|
|
17
|
+
declare function ChimelingRoot({ userId, children, poweredBy, openOnHover, hoverOpenDelay, hoverCloseDelay, onReady, presence: presenceOverride, refreshInterval, side, align, sideOffset }: ChimelingRootProps): import("react").JSX.Element;
|
|
18
|
+
//#endregion
|
|
19
|
+
export { ChimelingRoot, ChimelingRootProps };
|
|
20
|
+
//# sourceMappingURL=root.d.ts.map
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { useChimelingContext } from "../lib/context.js";
|
|
3
|
+
import { useResolvedUserPresence } from "../hooks/use-resolved-user-presence.js";
|
|
4
|
+
import { getShowablePresence } from "../lib/showable-presence.js";
|
|
5
|
+
import { WidgetContext } from "../lib/widget-context.js";
|
|
6
|
+
import { useEffect, useMemo, useRef, useState } from "react";
|
|
7
|
+
import { jsx } from "react/jsx-runtime";
|
|
8
|
+
import { Popover } from "@base-ui/react/popover";
|
|
9
|
+
//#region src/components/root.tsx
|
|
10
|
+
const DEFAULT_HOVER_OPEN_DELAY = 300;
|
|
11
|
+
const DEFAULT_HOVER_CLOSE_DELAY = 0;
|
|
12
|
+
function ChimelingRoot({ userId, children, poweredBy = true, openOnHover = false, hoverOpenDelay = DEFAULT_HOVER_OPEN_DELAY, hoverCloseDelay = DEFAULT_HOVER_CLOSE_DELAY, onReady, presence: presenceOverride, refreshInterval, side, align, sideOffset }) {
|
|
13
|
+
const { client } = useChimelingContext();
|
|
14
|
+
const fetched = useResolvedUserPresence(presenceOverride === void 0 ? userId : "", { refreshInterval });
|
|
15
|
+
const presence = presenceOverride ?? fetched.data;
|
|
16
|
+
const showable = useMemo(() => getShowablePresence(presence), [presence]);
|
|
17
|
+
const [now, setNow] = useState(() => /* @__PURE__ */ new Date());
|
|
18
|
+
const readyRef = useRef(false);
|
|
19
|
+
useEffect(() => {
|
|
20
|
+
if (!showable) return;
|
|
21
|
+
const id = setInterval(() => setNow(/* @__PURE__ */ new Date()), 1e3);
|
|
22
|
+
return () => clearInterval(id);
|
|
23
|
+
}, [showable]);
|
|
24
|
+
useEffect(() => {
|
|
25
|
+
if (readyRef.current || !showable) return;
|
|
26
|
+
readyRef.current = true;
|
|
27
|
+
onReady?.(showable);
|
|
28
|
+
}, [showable, onReady]);
|
|
29
|
+
const baseUrl = client.getConfig().baseUrl ?? "";
|
|
30
|
+
const placement = useMemo(() => ({
|
|
31
|
+
side,
|
|
32
|
+
align,
|
|
33
|
+
sideOffset
|
|
34
|
+
}), [
|
|
35
|
+
side,
|
|
36
|
+
align,
|
|
37
|
+
sideOffset
|
|
38
|
+
]);
|
|
39
|
+
const value = useMemo(() => ({
|
|
40
|
+
showable,
|
|
41
|
+
now,
|
|
42
|
+
poweredBy,
|
|
43
|
+
openOnHover,
|
|
44
|
+
hoverOpenDelay,
|
|
45
|
+
hoverCloseDelay,
|
|
46
|
+
placement,
|
|
47
|
+
baseUrl
|
|
48
|
+
}), [
|
|
49
|
+
showable,
|
|
50
|
+
now,
|
|
51
|
+
poweredBy,
|
|
52
|
+
openOnHover,
|
|
53
|
+
hoverOpenDelay,
|
|
54
|
+
hoverCloseDelay,
|
|
55
|
+
placement,
|
|
56
|
+
baseUrl
|
|
57
|
+
]);
|
|
58
|
+
return /* @__PURE__ */ jsx(WidgetContext.Provider, {
|
|
59
|
+
value,
|
|
60
|
+
children: showable ? /* @__PURE__ */ jsx(Popover.Root, { children }) : children
|
|
61
|
+
});
|
|
62
|
+
}
|
|
63
|
+
//#endregion
|
|
64
|
+
export { ChimelingRoot };
|
|
65
|
+
|
|
66
|
+
//# sourceMappingURL=root.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"root.js","names":[],"sources":["../../src/components/root.tsx"],"sourcesContent":["'use client'\n\nimport { useEffect, useMemo, useRef, useState, type ReactNode } from 'react'\nimport { Popover } from '@base-ui/react/popover'\nimport type { GetResolvedUserPresenceResponse } from '@cairntale/chimeling-js'\nimport { useResolvedUserPresence } from '../hooks/use-resolved-user-presence'\nimport { useChimelingContext } from '../lib/context'\nimport { getShowablePresence, type ShowablePresence } from '../lib/showable-presence'\nimport { WidgetContext, type WidgetPlacement } from '../lib/widget-context'\n\nconst DEFAULT_HOVER_OPEN_DELAY = 300\nconst DEFAULT_HOVER_CLOSE_DELAY = 0\n\nexport type ChimelingRootProps = WidgetPlacement & {\n userId: string\n children: ReactNode\n poweredBy?: boolean\n openOnHover?: boolean\n hoverOpenDelay?: number\n hoverCloseDelay?: number\n onReady?: (presence: ShowablePresence) => void\n presence?: GetResolvedUserPresenceResponse\n refreshInterval?: number\n}\n\nexport function ChimelingRoot({\n userId,\n children,\n poweredBy = true,\n openOnHover = false,\n hoverOpenDelay = DEFAULT_HOVER_OPEN_DELAY,\n hoverCloseDelay = DEFAULT_HOVER_CLOSE_DELAY,\n onReady,\n presence: presenceOverride,\n refreshInterval,\n side,\n align,\n sideOffset,\n}: ChimelingRootProps) {\n const { client } = useChimelingContext()\n const fetched = useResolvedUserPresence(presenceOverride === undefined ? userId : '', {\n refreshInterval,\n })\n const presence = presenceOverride ?? fetched.data\n const showable = useMemo(() => getShowablePresence(presence), [presence])\n\n const [now, setNow] = useState(() => new Date())\n const readyRef = useRef(false)\n\n useEffect(() => {\n if (!showable) {\n return\n }\n\n const id = setInterval(() => setNow(new Date()), 1000)\n return () => clearInterval(id)\n }, [showable])\n\n useEffect(() => {\n if (readyRef.current || !showable) {\n return\n }\n\n readyRef.current = true\n onReady?.(showable)\n }, [showable, onReady])\n\n const baseUrl = client.getConfig().baseUrl ?? ''\n const placement = useMemo(() => ({ side, align, sideOffset }), [side, align, sideOffset])\n\n const value = useMemo(\n () => ({\n showable,\n now,\n poweredBy,\n openOnHover,\n hoverOpenDelay,\n hoverCloseDelay,\n placement,\n baseUrl,\n }),\n [showable, now, poweredBy, openOnHover, hoverOpenDelay, hoverCloseDelay, placement, baseUrl],\n )\n\n return (\n <WidgetContext.Provider value={value}>\n {/* TODO: decide whether to expose Base UI Root props (open, onOpenChange, …). */}\n {showable ? <Popover.Root>{children}</Popover.Root> : children}\n </WidgetContext.Provider>\n )\n}\n"],"mappings":";;;;;;;;;AAUA,MAAM,2BAA2B;AACjC,MAAM,4BAA4B;AAclC,SAAgB,cAAc,EAC5B,QACA,UACA,YAAY,MACZ,cAAc,OACd,iBAAiB,0BACjB,kBAAkB,2BAClB,SACA,UAAU,kBACV,iBACA,MACA,OACA,cACqB;CACrB,MAAM,EAAE,WAAW,oBAAoB;CACvC,MAAM,UAAU,wBAAwB,qBAAqB,KAAA,IAAY,SAAS,IAAI,EACpF,gBACF,CAAC;CACD,MAAM,WAAW,oBAAoB,QAAQ;CAC7C,MAAM,WAAW,cAAc,oBAAoB,QAAQ,GAAG,CAAC,QAAQ,CAAC;CAExE,MAAM,CAAC,KAAK,UAAU,+BAAe,IAAI,KAAK,CAAC;CAC/C,MAAM,WAAW,OAAO,KAAK;CAE7B,gBAAgB;EACd,IAAI,CAAC,UACH;EAGF,MAAM,KAAK,kBAAkB,uBAAO,IAAI,KAAK,CAAC,GAAG,GAAI;EACrD,aAAa,cAAc,EAAE;CAC/B,GAAG,CAAC,QAAQ,CAAC;CAEb,gBAAgB;EACd,IAAI,SAAS,WAAW,CAAC,UACvB;EAGF,SAAS,UAAU;EACnB,UAAU,QAAQ;CACpB,GAAG,CAAC,UAAU,OAAO,CAAC;CAEtB,MAAM,UAAU,OAAO,UAAU,CAAC,CAAC,WAAW;CAC9C,MAAM,YAAY,eAAe;EAAE;EAAM;EAAO;CAAW,IAAI;EAAC;EAAM;EAAO;CAAU,CAAC;CAExF,MAAM,QAAQ,eACL;EACL;EACA;EACA;EACA;EACA;EACA;EACA;EACA;CACF,IACA;EAAC;EAAU;EAAK;EAAW;EAAa;EAAgB;EAAiB;EAAW;CAAO,CAC7F;CAEA,OACE,oBAAC,cAAc,UAAf;EAA+B;EAE5B,UAAA,WAAW,oBAAC,QAAQ,MAAT,EAAe,SAAuB,CAAA,IAAI;CAChC,CAAA;AAE5B"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { PopoverTriggerProps } from "@base-ui/react/popover";
|
|
2
|
+
//#region src/components/trigger.d.ts
|
|
3
|
+
type ChimelingTriggerProps = Pick<PopoverTriggerProps, 'className' | 'style' | 'nativeButton' | 'id'>;
|
|
4
|
+
declare function ChimelingTrigger({ className, style, nativeButton, id }: ChimelingTriggerProps): import("react").JSX.Element | null;
|
|
5
|
+
//#endregion
|
|
6
|
+
export { ChimelingTrigger, ChimelingTriggerProps };
|
|
7
|
+
//# sourceMappingURL=trigger.d.ts.map
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { useWidgetContext } from "../lib/widget-context.js";
|
|
3
|
+
import { jsx } from "react/jsx-runtime";
|
|
4
|
+
import { Popover } from "@base-ui/react/popover";
|
|
5
|
+
//#region src/components/trigger.tsx
|
|
6
|
+
function ChimelingTrigger({ className, style, nativeButton, id }) {
|
|
7
|
+
const { showable, openOnHover, hoverOpenDelay, hoverCloseDelay } = useWidgetContext();
|
|
8
|
+
if (!showable) return null;
|
|
9
|
+
return /* @__PURE__ */ jsx(Popover.Trigger, {
|
|
10
|
+
className,
|
|
11
|
+
style,
|
|
12
|
+
nativeButton,
|
|
13
|
+
id,
|
|
14
|
+
openOnHover,
|
|
15
|
+
delay: hoverOpenDelay,
|
|
16
|
+
closeDelay: hoverCloseDelay,
|
|
17
|
+
children: showable.activity.gerund
|
|
18
|
+
});
|
|
19
|
+
}
|
|
20
|
+
//#endregion
|
|
21
|
+
export { ChimelingTrigger };
|
|
22
|
+
|
|
23
|
+
//# sourceMappingURL=trigger.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"trigger.js","names":[],"sources":["../../src/components/trigger.tsx"],"sourcesContent":["'use client'\n\nimport { Popover } from '@base-ui/react/popover'\nimport type { PopoverTriggerProps } from '@base-ui/react/popover'\nimport { useWidgetContext } from '../lib/widget-context'\n\n// TODO: decide whether to expose the rest of Base UI Trigger props.\nexport type ChimelingTriggerProps = Pick<\n PopoverTriggerProps,\n 'className' | 'style' | 'nativeButton' | 'id'\n>\n\nexport function ChimelingTrigger({ className, style, nativeButton, id }: ChimelingTriggerProps) {\n const { showable, openOnHover, hoverOpenDelay, hoverCloseDelay } = useWidgetContext()\n\n if (!showable) {\n return null\n }\n\n return (\n <Popover.Trigger\n className={className}\n style={style}\n nativeButton={nativeButton}\n id={id}\n openOnHover={openOnHover}\n delay={hoverOpenDelay}\n closeDelay={hoverCloseDelay}\n >\n {showable.activity.gerund}\n </Popover.Trigger>\n )\n}\n"],"mappings":";;;;;AAYA,SAAgB,iBAAiB,EAAE,WAAW,OAAO,cAAc,MAA6B;CAC9F,MAAM,EAAE,UAAU,aAAa,gBAAgB,oBAAoB,iBAAiB;CAEpF,IAAI,CAAC,UACH,OAAO;CAGT,OACE,oBAAC,QAAQ,SAAT;EACa;EACJ;EACO;EACV;EACS;EACb,OAAO;EACP,YAAY;EAEX,UAAA,SAAS,SAAS;CACJ,CAAA;AAErB"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { useChimelingContext } from "../lib/context.js";
|
|
3
|
+
//#region src/hooks/use-client.ts
|
|
4
|
+
function useChimelingClient() {
|
|
5
|
+
return useChimelingContext().client;
|
|
6
|
+
}
|
|
7
|
+
//#endregion
|
|
8
|
+
export { useChimelingClient };
|
|
9
|
+
|
|
10
|
+
//# sourceMappingURL=use-client.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"use-client.js","names":[],"sources":["../../src/hooks/use-client.ts"],"sourcesContent":["'use client'\n\nimport { useChimelingContext } from '../lib/context'\nimport type { ChimelingClient } from '../types'\n\nexport function useChimelingClient(): ChimelingClient {\n return useChimelingContext().client\n}\n"],"mappings":";;;AAKA,SAAgB,qBAAsC;CACpD,OAAO,oBAAoB,CAAC,CAAC;AAC/B"}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
//#region src/hooks/use-resolved-user-presence.d.ts
|
|
2
|
+
declare function useResolvedUserPresence(userId: string, options?: {
|
|
3
|
+
refreshInterval?: number;
|
|
4
|
+
}): import("swr").SWRResponse<{
|
|
5
|
+
status: "offline";
|
|
6
|
+
} | {
|
|
7
|
+
status: "online";
|
|
8
|
+
activity: {
|
|
9
|
+
gerund: string;
|
|
10
|
+
appName: string;
|
|
11
|
+
iconHash: string | null;
|
|
12
|
+
startedAt: Date;
|
|
13
|
+
} | null;
|
|
14
|
+
} | {
|
|
15
|
+
status: "idle";
|
|
16
|
+
activity: {
|
|
17
|
+
gerund: string;
|
|
18
|
+
appName: string;
|
|
19
|
+
iconHash: string | null;
|
|
20
|
+
startedAt: Date;
|
|
21
|
+
} | null;
|
|
22
|
+
}, any, {
|
|
23
|
+
refreshInterval: number;
|
|
24
|
+
}>;
|
|
25
|
+
//#endregion
|
|
26
|
+
export { useResolvedUserPresence };
|
|
27
|
+
//# sourceMappingURL=use-resolved-user-presence.d.ts.map
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { useChimelingContext } from "../lib/context.js";
|
|
3
|
+
import { getResolvedUserPresence } from "../sdk/dist/sdk.gen.js";
|
|
4
|
+
import "../sdk/dist/index.js";
|
|
5
|
+
import { resolvedUserPresenceKey } from "../lib/presence-key.js";
|
|
6
|
+
import useSWR from "swr";
|
|
7
|
+
//#region src/hooks/use-resolved-user-presence.ts
|
|
8
|
+
function useResolvedUserPresence(userId, options) {
|
|
9
|
+
const { client, refreshInterval } = useChimelingContext();
|
|
10
|
+
const baseUrl = client.getConfig().baseUrl ?? "";
|
|
11
|
+
return useSWR(userId ? resolvedUserPresenceKey(userId, baseUrl) : null, async ([, , , id]) => {
|
|
12
|
+
const { data } = await getResolvedUserPresence({ userId: id }, {
|
|
13
|
+
client,
|
|
14
|
+
throwOnError: true
|
|
15
|
+
});
|
|
16
|
+
return data;
|
|
17
|
+
}, { refreshInterval: options?.refreshInterval ?? refreshInterval });
|
|
18
|
+
}
|
|
19
|
+
//#endregion
|
|
20
|
+
export { useResolvedUserPresence };
|
|
21
|
+
|
|
22
|
+
//# sourceMappingURL=use-resolved-user-presence.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"use-resolved-user-presence.js","names":[],"sources":["../../src/hooks/use-resolved-user-presence.ts"],"sourcesContent":["'use client'\n\nimport useSWR from 'swr'\nimport { getResolvedUserPresence } from '@cairntale/chimeling-js'\nimport { useChimelingContext } from '../lib/context'\nimport { resolvedUserPresenceKey } from '../lib/presence-key'\n\nexport function useResolvedUserPresence(\n userId: string,\n options?: {\n refreshInterval?: number\n },\n) {\n const { client, refreshInterval } = useChimelingContext()\n const baseUrl = client.getConfig().baseUrl ?? ''\n\n return useSWR(\n userId ? resolvedUserPresenceKey(userId, baseUrl) : null,\n async ([, , , id]) => {\n const { data } = await getResolvedUserPresence({ userId: id }, { client, throwOnError: true })\n return data\n },\n {\n refreshInterval: options?.refreshInterval ?? refreshInterval,\n },\n )\n}\n"],"mappings":";;;;;;;AAOA,SAAgB,wBACd,QACA,SAGA;CACA,MAAM,EAAE,QAAQ,oBAAoB,oBAAoB;CACxD,MAAM,UAAU,OAAO,UAAU,CAAC,CAAC,WAAW;CAE9C,OAAO,OACL,SAAS,wBAAwB,QAAQ,OAAO,IAAI,MACpD,OAAO,OAAO,QAAQ;EACpB,MAAM,EAAE,SAAS,MAAM,wBAAwB,EAAE,QAAQ,GAAG,GAAG;GAAE;GAAQ,cAAc;EAAK,CAAC;EAC7F,OAAO;CACT,GACA,EACE,iBAAiB,SAAS,mBAAmB,gBAC/C,CACF;AACF"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { ChimelingProvider } from "./components/provider.js";
|
|
2
|
+
import { PresenceActivity, ShowablePresence } from "./lib/showable-presence.js";
|
|
3
|
+
import { ChimelingRoot, ChimelingRootProps } from "./components/root.js";
|
|
4
|
+
import { ChimelingTrigger, ChimelingTriggerProps } from "./components/trigger.js";
|
|
5
|
+
import { ChimelingPopover, ChimelingPopoverProps } from "./components/popover.js";
|
|
6
|
+
import { Chimeling } from "./components/chimeling.js";
|
|
7
|
+
import "./components/index.js";
|
|
8
|
+
import { useChimelingClient } from "./hooks/use-client.js";
|
|
9
|
+
import { useResolvedUserPresence } from "./hooks/use-resolved-user-presence.js";
|
|
10
|
+
export { Chimeling, ChimelingPopover, type ChimelingPopoverProps, ChimelingProvider, ChimelingRoot, type ChimelingRootProps, ChimelingTrigger, type ChimelingTriggerProps, type PresenceActivity, type ShowablePresence, useChimelingClient, useResolvedUserPresence };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { ChimelingProvider } from "./components/provider.js";
|
|
3
|
+
import { useResolvedUserPresence } from "./hooks/use-resolved-user-presence.js";
|
|
4
|
+
import { ChimelingRoot } from "./components/root.js";
|
|
5
|
+
import { ChimelingTrigger } from "./components/trigger.js";
|
|
6
|
+
import { ChimelingPopover } from "./components/popover.js";
|
|
7
|
+
import { Chimeling } from "./components/chimeling.js";
|
|
8
|
+
import "./components/index.js";
|
|
9
|
+
import { useChimelingClient } from "./hooks/use-client.js";
|
|
10
|
+
import "./hooks/index.js";
|
|
11
|
+
export { Chimeling, ChimelingPopover, ChimelingProvider, ChimelingRoot, ChimelingTrigger, useChimelingClient, useResolvedUserPresence };
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { name } from "../react/package.js";
|
|
2
|
+
//#region src/lib/config.ts
|
|
3
|
+
const PACKAGE_NAME = name;
|
|
4
|
+
const DEFAULT_PRESENCE_REFRESH_INTERVAL = 5e3;
|
|
5
|
+
function packageErrorMessage(message) {
|
|
6
|
+
return `${PACKAGE_NAME}: ${message}`;
|
|
7
|
+
}
|
|
8
|
+
//#endregion
|
|
9
|
+
export { DEFAULT_PRESENCE_REFRESH_INTERVAL, PACKAGE_NAME, packageErrorMessage };
|
|
10
|
+
|
|
11
|
+
//# sourceMappingURL=config.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"config.js","names":["packageJson.name"],"sources":["../../src/lib/config.ts"],"sourcesContent":["import packageJson from '../../package.json' with { type: 'json' }\n\nexport const PACKAGE_NAME = packageJson.name\n\nexport const DEFAULT_PRESENCE_REFRESH_INTERVAL = 5_000\n\nexport function packageErrorMessage(message: string): string {\n return `${PACKAGE_NAME}: ${message}`\n}\n"],"mappings":";;AAEA,MAAa,eAAeA;AAE5B,MAAa,oCAAoC;AAEjD,SAAgB,oBAAoB,SAAyB;CAC3D,OAAO,GAAG,aAAa,IAAI;AAC7B"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { packageErrorMessage } from "./config.js";
|
|
3
|
+
import { createContext, useContext } from "react";
|
|
4
|
+
//#region src/lib/context.ts
|
|
5
|
+
const ChimelingContext = createContext(null);
|
|
6
|
+
function useChimelingContext() {
|
|
7
|
+
const context = useContext(ChimelingContext);
|
|
8
|
+
if (!context) throw new Error(packageErrorMessage("This hook or component can only be used within the <ChimelingProvider /> component."));
|
|
9
|
+
return context;
|
|
10
|
+
}
|
|
11
|
+
//#endregion
|
|
12
|
+
export { ChimelingContext, useChimelingContext };
|
|
13
|
+
|
|
14
|
+
//# sourceMappingURL=context.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"context.js","names":[],"sources":["../../src/lib/context.ts"],"sourcesContent":["'use client'\n\nimport { createContext, useContext } from 'react'\nimport type { ChimelingClient } from '../types'\nimport { packageErrorMessage } from './config'\n\ntype ChimelingContextValue = {\n client: ChimelingClient\n refreshInterval: number\n}\n\nexport const ChimelingContext = createContext<ChimelingContextValue | null>(null)\n\nexport function useChimelingContext(): ChimelingContextValue {\n const context = useContext(ChimelingContext)\n if (!context) {\n throw new Error(\n packageErrorMessage(\n 'This hook or component can only be used within the <ChimelingProvider /> component.',\n ),\n )\n }\n return context\n}\n"],"mappings":";;;;AAWA,MAAa,mBAAmB,cAA4C,IAAI;AAEhF,SAAgB,sBAA6C;CAC3D,MAAM,UAAU,WAAW,gBAAgB;CAC3C,IAAI,CAAC,SACH,MAAM,IAAI,MACR,oBACE,qFACF,CACF;CAEF,OAAO;AACT"}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { formatDuration, intervalToDuration } from "date-fns";
|
|
2
|
+
//#region src/lib/format-activity-duration.ts
|
|
3
|
+
const UNITS = [
|
|
4
|
+
"years",
|
|
5
|
+
"months",
|
|
6
|
+
"weeks",
|
|
7
|
+
"days",
|
|
8
|
+
"hours",
|
|
9
|
+
"minutes"
|
|
10
|
+
];
|
|
11
|
+
const JUST_NOW_MS = 6e4;
|
|
12
|
+
function formatActivityDuration(startedAt, now) {
|
|
13
|
+
const start = startedAt instanceof Date ? startedAt : new Date(startedAt);
|
|
14
|
+
if (now.getTime() - start.getTime() < JUST_NOW_MS) return "just now";
|
|
15
|
+
const duration = intervalToDuration({
|
|
16
|
+
start,
|
|
17
|
+
end: now
|
|
18
|
+
});
|
|
19
|
+
const unit = UNITS.find((name) => (duration[name] ?? 0) > 0);
|
|
20
|
+
if (!unit) return "just now";
|
|
21
|
+
return `for ${formatDuration({ [unit]: duration[unit] }, { format: [unit] })}`;
|
|
22
|
+
}
|
|
23
|
+
//#endregion
|
|
24
|
+
export { formatActivityDuration };
|
|
25
|
+
|
|
26
|
+
//# sourceMappingURL=format-activity-duration.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"format-activity-duration.js","names":[],"sources":["../../src/lib/format-activity-duration.ts"],"sourcesContent":["import { formatDuration, intervalToDuration } from 'date-fns'\n\nconst UNITS = ['years', 'months', 'weeks', 'days', 'hours', 'minutes'] as const\n\nconst JUST_NOW_MS = 60_000\n\nexport function formatActivityDuration(startedAt: Date, now: Date): string {\n const start = startedAt instanceof Date ? startedAt : new Date(startedAt)\n const elapsedMs = now.getTime() - start.getTime()\n if (elapsedMs < JUST_NOW_MS) {\n return 'just now'\n }\n\n const duration = intervalToDuration({ start, end: now })\n const unit = UNITS.find(name => (duration[name] ?? 0) > 0)\n if (!unit) {\n return 'just now'\n }\n\n return `for ${formatDuration({ [unit]: duration[unit] }, { format: [unit] })}`\n}\n"],"mappings":";;AAEA,MAAM,QAAQ;CAAC;CAAS;CAAU;CAAS;CAAQ;CAAS;AAAS;AAErE,MAAM,cAAc;AAEpB,SAAgB,uBAAuB,WAAiB,KAAmB;CACzE,MAAM,QAAQ,qBAAqB,OAAO,YAAY,IAAI,KAAK,SAAS;CAExE,IADkB,IAAI,QAAQ,IAAI,MAAM,QAAQ,IAChC,aACd,OAAO;CAGT,MAAM,WAAW,mBAAmB;EAAE;EAAO,KAAK;CAAI,CAAC;CACvD,MAAM,OAAO,MAAM,MAAK,UAAS,SAAS,SAAS,KAAK,CAAC;CACzD,IAAI,CAAC,MACH,OAAO;CAGT,OAAO,OAAO,eAAe,GAAG,OAAO,SAAS,MAAM,GAAG,EAAE,QAAQ,CAAC,IAAI,EAAE,CAAC;AAC7E"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"icon-url.js","names":[],"sources":["../../src/lib/icon-url.ts"],"sourcesContent":["import { joinURL } from 'ufo'\n\nexport function iconImageUrl(baseUrl: string, hash: string): string {\n return joinURL(baseUrl, 'api/v1/icons', hash, 'image')\n}\n"],"mappings":";;AAEA,SAAgB,aAAa,SAAiB,MAAsB;CAClE,OAAO,QAAQ,SAAS,gBAAgB,MAAM,OAAO;AACvD"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { PACKAGE_NAME } from "./config.js";
|
|
2
|
+
//#region src/lib/presence-key.ts
|
|
3
|
+
function resolvedUserPresenceKey(userId, baseUrl) {
|
|
4
|
+
return [
|
|
5
|
+
PACKAGE_NAME,
|
|
6
|
+
"resolved-user-presence",
|
|
7
|
+
baseUrl,
|
|
8
|
+
userId
|
|
9
|
+
];
|
|
10
|
+
}
|
|
11
|
+
//#endregion
|
|
12
|
+
export { resolvedUserPresenceKey };
|
|
13
|
+
|
|
14
|
+
//# sourceMappingURL=presence-key.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"presence-key.js","names":[],"sources":["../../src/lib/presence-key.ts"],"sourcesContent":["import { PACKAGE_NAME } from './config'\n\nexport function resolvedUserPresenceKey(userId: string, baseUrl: string) {\n return [PACKAGE_NAME, 'resolved-user-presence', baseUrl, userId] as const\n}\n"],"mappings":";;AAEA,SAAgB,wBAAwB,QAAgB,SAAiB;CACvE,OAAO;EAAC;EAAc;EAA0B;EAAS;CAAM;AACjE"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { GetResolvedUserPresenceResponse } from "../sdk/dist/types.gen.js";
|
|
2
|
+
//#region src/lib/showable-presence.d.ts
|
|
3
|
+
type PresenceWithActivity = Extract<GetResolvedUserPresenceResponse, {
|
|
4
|
+
status: 'online' | 'idle';
|
|
5
|
+
}>;
|
|
6
|
+
type PresenceActivity = NonNullable<PresenceWithActivity['activity']>;
|
|
7
|
+
type ShowablePresence = Omit<PresenceWithActivity, 'activity'> & {
|
|
8
|
+
activity: PresenceActivity;
|
|
9
|
+
};
|
|
10
|
+
//#endregion
|
|
11
|
+
export { PresenceActivity, ShowablePresence };
|
|
12
|
+
//# sourceMappingURL=showable-presence.d.ts.map
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
//#region src/lib/showable-presence.ts
|
|
2
|
+
function getShowablePresence(presence) {
|
|
3
|
+
if (!presence || presence.status === "offline" || presence.activity == null) return null;
|
|
4
|
+
return {
|
|
5
|
+
status: presence.status,
|
|
6
|
+
activity: presence.activity
|
|
7
|
+
};
|
|
8
|
+
}
|
|
9
|
+
//#endregion
|
|
10
|
+
export { getShowablePresence };
|
|
11
|
+
|
|
12
|
+
//# sourceMappingURL=showable-presence.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"showable-presence.js","names":[],"sources":["../../src/lib/showable-presence.ts"],"sourcesContent":["import type { GetResolvedUserPresenceResponse } from '@cairntale/chimeling-js'\n\ntype PresenceWithActivity = Extract<GetResolvedUserPresenceResponse, { status: 'online' | 'idle' }>\n\nexport type PresenceActivity = NonNullable<PresenceWithActivity['activity']>\n\nexport type ShowablePresence = Omit<PresenceWithActivity, 'activity'> & {\n activity: PresenceActivity\n}\n\nexport function getShowablePresence(\n presence: GetResolvedUserPresenceResponse | undefined,\n): ShowablePresence | null {\n if (!presence || presence.status === 'offline' || presence.activity == null) {\n return null\n }\n\n return {\n status: presence.status,\n activity: presence.activity,\n }\n}\n"],"mappings":";AAUA,SAAgB,oBACd,UACyB;CACzB,IAAI,CAAC,YAAY,SAAS,WAAW,aAAa,SAAS,YAAY,MACrE,OAAO;CAGT,OAAO;EACL,QAAQ,SAAS;EACjB,UAAU,SAAS;CACrB;AACF"}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { PopoverPositionerProps } from "@base-ui/react/popover";
|
|
2
|
+
//#region src/lib/widget-context.d.ts
|
|
3
|
+
type WidgetPlacement = Pick<PopoverPositionerProps, 'side' | 'align' | 'sideOffset'>;
|
|
4
|
+
//#endregion
|
|
5
|
+
export { WidgetPlacement };
|
|
6
|
+
//# sourceMappingURL=widget-context.d.ts.map
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { packageErrorMessage } from "./config.js";
|
|
3
|
+
import { createContext, useContext } from "react";
|
|
4
|
+
//#region src/lib/widget-context.ts
|
|
5
|
+
const WidgetContext = createContext(null);
|
|
6
|
+
function useWidgetContext() {
|
|
7
|
+
const context = useContext(WidgetContext);
|
|
8
|
+
if (!context) throw new Error(packageErrorMessage("This component can only be used within the <Chimeling.Root /> component."));
|
|
9
|
+
return context;
|
|
10
|
+
}
|
|
11
|
+
//#endregion
|
|
12
|
+
export { WidgetContext, useWidgetContext };
|
|
13
|
+
|
|
14
|
+
//# sourceMappingURL=widget-context.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"widget-context.js","names":[],"sources":["../../src/lib/widget-context.ts"],"sourcesContent":["'use client'\n\nimport { createContext, useContext } from 'react'\nimport type { PopoverPositionerProps } from '@base-ui/react/popover'\nimport { packageErrorMessage } from './config'\nimport type { ShowablePresence } from './showable-presence'\n\nexport type WidgetPlacement = Pick<PopoverPositionerProps, 'side' | 'align' | 'sideOffset'>\n\nexport type WidgetContextValue = {\n showable: ShowablePresence | null\n now: Date\n poweredBy: boolean\n openOnHover: boolean\n hoverOpenDelay: number\n hoverCloseDelay: number\n placement: WidgetPlacement\n baseUrl: string\n}\n\nexport const WidgetContext = createContext<WidgetContextValue | null>(null)\n\nexport function useWidgetContext(): WidgetContextValue {\n const context = useContext(WidgetContext)\n if (!context) {\n throw new Error(\n packageErrorMessage(\n 'This component can only be used within the <Chimeling.Root /> component.',\n ),\n )\n }\n return context\n}\n"],"mappings":";;;;AAoBA,MAAa,gBAAgB,cAAyC,IAAI;AAE1E,SAAgB,mBAAuC;CACrD,MAAM,UAAU,WAAW,aAAa;CACxC,IAAI,CAAC,SACH,MAAM,IAAI,MACR,oBACE,0EACF,CACF;CAEF,OAAO;AACT"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"package.js","names":[],"sources":["../../package.json"],"sourcesContent":[""],"mappings":""}
|