@noirhare/dsh-ui-notification 0.0.2

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.
@@ -0,0 +1,3 @@
1
+ import React from "react";
2
+ export declare function SidebarNotify(): React.JSX.Element | null;
3
+ export default SidebarNotify;
@@ -0,0 +1,3 @@
1
+ import type { ClientContext } from "@deepseek-ai/dsh-client-runtime/client";
2
+ export declare const inject: string[];
3
+ export declare function apply(ctx: ClientContext): Promise<void>;
@@ -0,0 +1,98 @@
1
+ window.__ModuleLoader__.load({ id: "@noirhare/dsh-ui-notification", factory: (require) => {
2
+ var module = { exports: {} };
3
+ var __create = Object.create;
4
+ var __defProp = Object.defineProperty;
5
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
6
+ var __getOwnPropNames = Object.getOwnPropertyNames;
7
+ var __getProtoOf = Object.getPrototypeOf;
8
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
9
+ var __export = (target, all) => {
10
+ for (var name in all)
11
+ __defProp(target, name, { get: all[name], enumerable: true });
12
+ };
13
+ var __copyProps = (to, from, except, desc) => {
14
+ if (from && typeof from === "object" || typeof from === "function") {
15
+ for (let key of __getOwnPropNames(from))
16
+ if (!__hasOwnProp.call(to, key) && key !== except)
17
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
18
+ }
19
+ return to;
20
+ };
21
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
22
+ // If the importer is in node compatibility mode or this is not an ESM
23
+ // file that has been converted to a CommonJS file using a Babel-
24
+ // compatible transform (i.e. "__esModule" has not been set), then set
25
+ // "default" to the CommonJS "module.exports" for node compatibility.
26
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
27
+ mod
28
+ ));
29
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
30
+
31
+ // src/client/index.ts
32
+ var index_exports = {};
33
+ __export(index_exports, {
34
+ apply: () => apply,
35
+ inject: () => inject
36
+ });
37
+ module.exports = __toCommonJS(index_exports);
38
+
39
+ // src/client/SidebarNotify.tsx
40
+ var import_react = __toESM(require("react"), 1);
41
+ var import_dsh_client_ui_primitives = require("@deepseek-ai/dsh-client-ui-primitives");
42
+ function SidebarNotify() {
43
+ const [permission, setPermission] = (0, import_react.useState)(Notification.permission);
44
+ function buttonClick(event) {
45
+ event.preventDefault();
46
+ Notification.requestPermission((permission2) => setPermission(permission2));
47
+ }
48
+ return (0, import_react.useMemo)(() => permission === "default" ? /* @__PURE__ */ import_react.default.createElement(import_dsh_client_ui_primitives.Button, { variant: "toolbar", onClick: buttonClick }, "\u542F\u52A8\u901A\u77E5") : null, [permission]);
49
+ }
50
+ var SidebarNotify_default = SidebarNotify;
51
+
52
+ // src/client/index.ts
53
+ var ID = "@noirhare/dsh-ui-notification";
54
+ var inject = ["slots", "sessions"];
55
+ async function apply(ctx) {
56
+ if (Notification.permission === "default") {
57
+ ctx.slots.inject(
58
+ "sidebar.footer.action",
59
+ () => ctx.slots.register({
60
+ name: "sidebar.footer.action",
61
+ id: `${ID}:request-permission`
62
+ }, SidebarNotify_default)
63
+ );
64
+ }
65
+ ctx.effect(() => {
66
+ let previous = ctx.sessions.list.getSnapshot().byId;
67
+ return ctx.sessions.list.subscribe(() => {
68
+ const snapshot = ctx.sessions.list.getSnapshot();
69
+ try {
70
+ if (Notification.permission !== "granted") return;
71
+ for (const id of snapshot.ids) {
72
+ const p = previous[id];
73
+ if (!p) continue;
74
+ const c = snapshot.byId[id];
75
+ if (p.running && !c.running) {
76
+ const n = new Notification(c.displayTitle, { body: "\u8FD0\u884C\u7ED3\u675F" });
77
+ n.addEventListener("click", (e) => {
78
+ e.preventDefault();
79
+ ctx.sessions.open(id);
80
+ window.focus();
81
+ });
82
+ }
83
+ if (p.pendingInteraction !== c.pendingInteraction && c.pendingInteraction) {
84
+ const n = new Notification(c.displayTitle, { body: `${c.pendingInteraction} \u7B49\u5F85\u54CD\u5E94` });
85
+ n.addEventListener("click", (e) => {
86
+ e.preventDefault();
87
+ ctx.sessions.open(id);
88
+ window.focus();
89
+ });
90
+ }
91
+ }
92
+ } finally {
93
+ previous = snapshot.byId;
94
+ }
95
+ });
96
+ }, `${ID}:session-update`);
97
+ }
98
+ return module.exports; } });
@@ -0,0 +1 @@
1
+ export declare function apply(): void;
@@ -0,0 +1,2 @@
1
+ export function apply() {
2
+ }
package/package.json ADDED
@@ -0,0 +1,43 @@
1
+ {
2
+ "name": "@noirhare/dsh-ui-notification",
3
+ "version": "0.0.2",
4
+ "license": "MIT",
5
+ "author": {
6
+ "name": "NoirHare",
7
+ "url": "https://github.com/NoirHare"
8
+ },
9
+ "repository": {
10
+ "type": "git",
11
+ "url": "git+https://github.com/NoirHare/dsh-bundle.git",
12
+ "directory": "packages/ui-notification"
13
+ },
14
+ "files": [
15
+ "lib"
16
+ ],
17
+ "publishConfig": {
18
+ "access": "public"
19
+ },
20
+ "type": "module",
21
+ "exports": {
22
+ ".": "./lib/host/index.js",
23
+ "./client": "./lib/client/index.js",
24
+ "./package.json": "./package.json"
25
+ },
26
+ "peerDependencies": {
27
+ "@deepseek-ai/dsh-client-runtime": "^0.1.1-rc.2",
28
+ "@deepseek-ai/dsh-client-ui-primitives": "^0.1.1-rc.2",
29
+ "@deepseek-ai/dsh-client-ui-slots": "^0.1.1-rc.2",
30
+ "@deepseek-ai/dsh-client-ui-sidebar": "^0.1.1-rc.2"
31
+ },
32
+ "dsh": {
33
+ "client": {
34
+ "inject": [],
35
+ "platform": "web"
36
+ }
37
+ },
38
+ "dependencies": {},
39
+ "scripts": {
40
+ "build": "tsc -b && node build.ts",
41
+ "prepublish": "pnpm build"
42
+ }
43
+ }