@edv4h/usketch-session-voting 0.2.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/LICENSE +21 -0
- package/dist/client.d.ts +10 -0
- package/dist/client.d.ts.map +1 -0
- package/dist/client.js +221 -0
- package/dist/client.js.map +1 -0
- package/dist/server.d.ts +14 -0
- package/dist/server.d.ts.map +1 -0
- package/dist/server.js +74 -0
- package/dist/server.js.map +1 -0
- package/dist/types.d.ts +40 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +2 -0
- package/dist/types.js.map +1 -0
- package/package.json +52 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 EdV4H
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/dist/client.d.ts
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { ClientSessionType } from "@edv4h/usketch-plugin-session";
|
|
2
|
+
export type { VotingPrivateState, VotingPublicState } from "./types.js";
|
|
3
|
+
/**
|
|
4
|
+
* The `voting` session type's **client** half: renders the live poll card and
|
|
5
|
+
* the create form inside the framework's HUD panel. All logic is server-side
|
|
6
|
+
* (see `../server`); this only draws public state + the caller's own private
|
|
7
|
+
* receipt and sends intents via the framework-provided context.
|
|
8
|
+
*/
|
|
9
|
+
export declare const votingClientType: ClientSessionType;
|
|
10
|
+
//# sourceMappingURL=client.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../src/client.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACX,iBAAiB,EAGjB,MAAM,+BAA+B,CAAC;AAKvC,YAAY,EAAE,kBAAkB,EAAE,iBAAiB,EAAE,MAAM,YAAY,CAAC;AAMxE;;;;;GAKG;AACH,eAAO,MAAM,gBAAgB,EAAE,iBAK9B,CAAC"}
|
package/dist/client.js
ADDED
|
@@ -0,0 +1,221 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { useState } from "react";
|
|
3
|
+
// Align with the HUD's compact design tokens (theme-aware CSS variables).
|
|
4
|
+
const ACCENT = "var(--u-1)";
|
|
5
|
+
const tint = (v, pct) => `color-mix(in srgb, ${v} ${pct}%, transparent)`;
|
|
6
|
+
/**
|
|
7
|
+
* The `voting` session type's **client** half: renders the live poll card and
|
|
8
|
+
* the create form inside the framework's HUD panel. All logic is server-side
|
|
9
|
+
* (see `../server`); this only draws public state + the caller's own private
|
|
10
|
+
* receipt and sends intents via the framework-provided context.
|
|
11
|
+
*/
|
|
12
|
+
export const votingClientType = {
|
|
13
|
+
type: "voting",
|
|
14
|
+
label: "投票",
|
|
15
|
+
renderCreateForm: (ctx) => _jsx(CreateVoteForm, { ctx: ctx }),
|
|
16
|
+
renderCard: (ctx) => _jsx(VotingCard, { ctx: ctx }),
|
|
17
|
+
};
|
|
18
|
+
/** Short, readable form of a userId for the host indicator. */
|
|
19
|
+
function shortId(id) {
|
|
20
|
+
return id.length > 12 ? `${id.slice(0, 12)}…` : id;
|
|
21
|
+
}
|
|
22
|
+
function VotingCard({ ctx }) {
|
|
23
|
+
const { session, isHost, me } = ctx;
|
|
24
|
+
const pub = session.public;
|
|
25
|
+
const myPrivate = ctx.myPrivate;
|
|
26
|
+
const myVotes = myPrivate?.myVotes ?? [];
|
|
27
|
+
const total = pub.tally.reduce((a, b) => a + b, 0);
|
|
28
|
+
const closed = pub.status === "closed";
|
|
29
|
+
const online = session.participants.filter((p) => p.connected).length;
|
|
30
|
+
return (_jsxs("div", { style: cardStyle, children: [_jsxs("div", { style: cardHeadStyle, children: [_jsx("span", { style: questionStyle, children: pub.question }), _jsx("span", { style: closed ? badgeClosedStyle : badgeOpenStyle, children: closed ? "締切" : "受付中" })] }), _jsx("div", { style: optionsStyle, children: pub.options.map((label, i) => {
|
|
31
|
+
const count = pub.tally[i] ?? 0;
|
|
32
|
+
const pct = total > 0 ? Math.round((count / total) * 100) : 0;
|
|
33
|
+
const mine = myVotes.includes(i);
|
|
34
|
+
return (_jsxs("button", { type: "button", disabled: closed, onClick: () => ctx.act({ kind: "cast", optionIndex: i }), style: {
|
|
35
|
+
...optionBtnStyle,
|
|
36
|
+
borderColor: mine ? ACCENT : "var(--border-default)",
|
|
37
|
+
cursor: closed ? "default" : "pointer",
|
|
38
|
+
opacity: closed ? 0.7 : 1,
|
|
39
|
+
}, title: pub.multi ? "複数選択可(もう一度で取消)" : "1つ選択(再選択で変更)", children: [_jsx("span", { style: barFillStyle(pct, mine) }), _jsxs("span", { style: optionLabelStyle, children: [mine ? "● " : "", label] }), _jsx("span", { style: optionCountStyle, children: count })] }, `${session.id}:${i}`));
|
|
40
|
+
}) }), _jsx("div", { style: metaRowStyle, children: _jsxs("span", { children: [pub.secret ? "🔒秘密投票 · " : "", pub.multi ? "複数選択 · " : "", pub.totalVoters, "\u4EBA\u304C\u6295\u7968 \u00B7 ", online, "\u4EBA\u63A5\u7D9A\u4E2D"] }) }), isHost ? (closed ? (_jsx("button", { type: "button", style: hostEndBtnStyle, onClick: ctx.end, title: "\u5168\u54E1\u306E\u30D1\u30CD\u30EB\u304B\u3089\u524A\u9664", children: "\uD83D\uDDD1 \u7D42\u4E86\u3057\u3066\u524A\u9664" })) : (_jsx("button", { type: "button", style: hostCloseBtnStyle, onClick: ctx.close, title: "\u96C6\u8A08\u3092\u78BA\u5B9A\u3057\u3066\u7DE0\u3081\u5207\u308B", children: "\uD83D\uDED1 \u7DE0\u3081\u5207\u308B" }))) : (_jsxs("div", { style: notHostStyle, children: ["\u7DE0\u3081\u5207\u308C\u308B\u306E\u306F\u4E3B\u50AC\u8005\u306E\u307F\u3067\u3059\u3002", _jsx("br", {}), "\u4E3B\u50AC: ", _jsx("code", { children: shortId(session.hostUserId) }), " \uFF0F \u3042\u306A\u305F: ", _jsx("code", { children: shortId(me) })] }))] }));
|
|
41
|
+
}
|
|
42
|
+
function CreateVoteForm({ ctx }) {
|
|
43
|
+
const [question, setQuestion] = useState("");
|
|
44
|
+
const [options, setOptions] = useState(["", "", "", ""]);
|
|
45
|
+
const [secret, setSecret] = useState(false);
|
|
46
|
+
const [multi, setMulti] = useState(false);
|
|
47
|
+
const validOptions = options.map((o) => o.trim()).filter((o) => o.length > 0);
|
|
48
|
+
const canCreate = question.trim().length > 0 && validOptions.length >= 2;
|
|
49
|
+
return (_jsxs("div", { style: formStyle, children: [_jsx("input", { style: inputStyle, placeholder: "\u8CEA\u554F\uFF08\u4F8B: \u30E9\u30F3\u30C1\u3069\u3053\u884C\u304F\uFF1F\uFF09", value: question, onChange: (e) => setQuestion(e.target.value) }), options.map((opt, i) => (_jsx("input", { style: inputStyle, placeholder: `選択肢${i + 1}${i < 2 ? "(必須)" : "(任意)"}`, value: opt, onChange: (e) => {
|
|
50
|
+
const next = [...options];
|
|
51
|
+
next[i] = e.target.value;
|
|
52
|
+
setOptions(next);
|
|
53
|
+
} }, i))), _jsxs("label", { style: checkRowStyle, children: [_jsx("input", { type: "checkbox", checked: secret, onChange: (e) => setSecret(e.target.checked) }), "\u79D8\u5BC6\u6295\u7968\uFF08\u8AB0\u304C\u5165\u308C\u305F\u304B\u3092\u96A0\u3059\uFF09"] }), _jsxs("label", { style: checkRowStyle, children: [_jsx("input", { type: "checkbox", checked: multi, onChange: (e) => setMulti(e.target.checked) }), "\u8907\u6570\u9078\u629E\u3092\u8A31\u53EF"] }), _jsxs("div", { style: formActionsStyle, children: [_jsx("button", { type: "button", style: { ...createBtnStyle, opacity: canCreate ? 1 : 0.5 }, disabled: !canCreate, onClick: () => {
|
|
54
|
+
ctx.create({
|
|
55
|
+
type: "voting",
|
|
56
|
+
question: question.trim(),
|
|
57
|
+
options: validOptions,
|
|
58
|
+
secret,
|
|
59
|
+
multi,
|
|
60
|
+
});
|
|
61
|
+
ctx.dismiss();
|
|
62
|
+
}, children: "\u4F5C\u6210" }), _jsx("button", { type: "button", style: cancelBtnStyle, onClick: ctx.dismiss, children: "\u30AD\u30E3\u30F3\u30BB\u30EB" })] })] }));
|
|
63
|
+
}
|
|
64
|
+
// ── styles (HUD compact scale; theme-aware tokens) ──
|
|
65
|
+
const cardStyle = {
|
|
66
|
+
border: "1px solid var(--border-default)",
|
|
67
|
+
borderRadius: "var(--r-sm)",
|
|
68
|
+
padding: 8,
|
|
69
|
+
background: "var(--bg-input)",
|
|
70
|
+
display: "flex",
|
|
71
|
+
flexDirection: "column",
|
|
72
|
+
gap: 6,
|
|
73
|
+
};
|
|
74
|
+
const cardHeadStyle = {
|
|
75
|
+
display: "flex",
|
|
76
|
+
justifyContent: "space-between",
|
|
77
|
+
alignItems: "center",
|
|
78
|
+
gap: 6,
|
|
79
|
+
};
|
|
80
|
+
const questionStyle = {
|
|
81
|
+
fontSize: 11,
|
|
82
|
+
fontWeight: 600,
|
|
83
|
+
color: "var(--fg-primary)",
|
|
84
|
+
};
|
|
85
|
+
const badgeOpenStyle = {
|
|
86
|
+
fontSize: 9,
|
|
87
|
+
color: "var(--success)",
|
|
88
|
+
background: tint("var(--success)", 16),
|
|
89
|
+
borderRadius: "var(--r-pill)",
|
|
90
|
+
padding: "1px 6px",
|
|
91
|
+
whiteSpace: "nowrap",
|
|
92
|
+
};
|
|
93
|
+
const badgeClosedStyle = {
|
|
94
|
+
fontSize: 9,
|
|
95
|
+
color: "var(--fg-tertiary)",
|
|
96
|
+
background: "var(--bg-hover)",
|
|
97
|
+
borderRadius: "var(--r-pill)",
|
|
98
|
+
padding: "1px 6px",
|
|
99
|
+
whiteSpace: "nowrap",
|
|
100
|
+
};
|
|
101
|
+
const optionsStyle = { display: "flex", flexDirection: "column", gap: 3 };
|
|
102
|
+
const optionBtnStyle = {
|
|
103
|
+
position: "relative",
|
|
104
|
+
display: "flex",
|
|
105
|
+
alignItems: "center",
|
|
106
|
+
justifyContent: "space-between",
|
|
107
|
+
gap: 6,
|
|
108
|
+
padding: "3px 8px",
|
|
109
|
+
border: "1px solid var(--border-default)",
|
|
110
|
+
borderRadius: "var(--r-xs)",
|
|
111
|
+
background: "var(--bg-input)",
|
|
112
|
+
overflow: "hidden",
|
|
113
|
+
textAlign: "left",
|
|
114
|
+
font: "inherit",
|
|
115
|
+
fontSize: 10,
|
|
116
|
+
color: "var(--fg-primary)",
|
|
117
|
+
};
|
|
118
|
+
const barFillStyle = (pct, mine) => ({
|
|
119
|
+
position: "absolute",
|
|
120
|
+
left: 0,
|
|
121
|
+
top: 0,
|
|
122
|
+
bottom: 0,
|
|
123
|
+
width: `${pct}%`,
|
|
124
|
+
background: mine ? tint(ACCENT, 28) : "var(--bg-hover)",
|
|
125
|
+
transition: "width 0.3s",
|
|
126
|
+
pointerEvents: "none",
|
|
127
|
+
});
|
|
128
|
+
const optionLabelStyle = { position: "relative", zIndex: 1 };
|
|
129
|
+
const optionCountStyle = {
|
|
130
|
+
position: "relative",
|
|
131
|
+
zIndex: 1,
|
|
132
|
+
fontVariantNumeric: "tabular-nums",
|
|
133
|
+
color: "var(--fg-secondary)",
|
|
134
|
+
fontSize: 10,
|
|
135
|
+
};
|
|
136
|
+
const metaRowStyle = {
|
|
137
|
+
display: "flex",
|
|
138
|
+
justifyContent: "space-between",
|
|
139
|
+
alignItems: "center",
|
|
140
|
+
gap: 6,
|
|
141
|
+
fontSize: 9,
|
|
142
|
+
color: "var(--fg-tertiary)",
|
|
143
|
+
};
|
|
144
|
+
const hostBtnBase = {
|
|
145
|
+
width: "100%",
|
|
146
|
+
padding: "3px 8px",
|
|
147
|
+
borderRadius: "var(--r-xs)",
|
|
148
|
+
cursor: "pointer",
|
|
149
|
+
font: "inherit",
|
|
150
|
+
fontSize: 10,
|
|
151
|
+
fontWeight: 600,
|
|
152
|
+
};
|
|
153
|
+
const hostCloseBtnStyle = {
|
|
154
|
+
...hostBtnBase,
|
|
155
|
+
border: `1px solid ${ACCENT}`,
|
|
156
|
+
background: tint(ACCENT, 14),
|
|
157
|
+
color: ACCENT,
|
|
158
|
+
};
|
|
159
|
+
const hostEndBtnStyle = {
|
|
160
|
+
...hostBtnBase,
|
|
161
|
+
border: `1px solid ${tint("var(--danger)", 55)}`,
|
|
162
|
+
background: tint("var(--danger)", 14),
|
|
163
|
+
color: "var(--danger)",
|
|
164
|
+
};
|
|
165
|
+
const notHostStyle = {
|
|
166
|
+
fontSize: 9,
|
|
167
|
+
lineHeight: 1.5,
|
|
168
|
+
color: "var(--fg-tertiary)",
|
|
169
|
+
background: "var(--bg-hover)",
|
|
170
|
+
borderRadius: "var(--r-xs)",
|
|
171
|
+
padding: "4px 6px",
|
|
172
|
+
};
|
|
173
|
+
const formStyle = {
|
|
174
|
+
display: "flex",
|
|
175
|
+
flexDirection: "column",
|
|
176
|
+
gap: 4,
|
|
177
|
+
border: "1px solid var(--border-default)",
|
|
178
|
+
borderRadius: "var(--r-sm)",
|
|
179
|
+
padding: 8,
|
|
180
|
+
background: "var(--bg-input)",
|
|
181
|
+
};
|
|
182
|
+
const inputStyle = {
|
|
183
|
+
padding: "2px 6px",
|
|
184
|
+
border: "1px solid var(--border-default)",
|
|
185
|
+
borderRadius: "var(--r-xs)",
|
|
186
|
+
background: "var(--bg-input)",
|
|
187
|
+
color: "var(--fg-primary)",
|
|
188
|
+
font: "inherit",
|
|
189
|
+
fontSize: 10,
|
|
190
|
+
};
|
|
191
|
+
const checkRowStyle = {
|
|
192
|
+
display: "flex",
|
|
193
|
+
alignItems: "center",
|
|
194
|
+
gap: 5,
|
|
195
|
+
fontSize: 9,
|
|
196
|
+
color: "var(--fg-secondary)",
|
|
197
|
+
};
|
|
198
|
+
const formActionsStyle = { display: "flex", gap: 5, marginTop: 2 };
|
|
199
|
+
const createBtnStyle = {
|
|
200
|
+
flex: 1,
|
|
201
|
+
padding: "3px 8px",
|
|
202
|
+
border: "none",
|
|
203
|
+
borderRadius: "var(--r-xs)",
|
|
204
|
+
background: ACCENT,
|
|
205
|
+
color: "#fff",
|
|
206
|
+
cursor: "pointer",
|
|
207
|
+
font: "inherit",
|
|
208
|
+
fontSize: 10,
|
|
209
|
+
fontWeight: 600,
|
|
210
|
+
};
|
|
211
|
+
const cancelBtnStyle = {
|
|
212
|
+
padding: "3px 8px",
|
|
213
|
+
border: "1px solid var(--border-default)",
|
|
214
|
+
borderRadius: "var(--r-xs)",
|
|
215
|
+
background: "transparent",
|
|
216
|
+
color: "var(--fg-secondary)",
|
|
217
|
+
cursor: "pointer",
|
|
218
|
+
font: "inherit",
|
|
219
|
+
fontSize: 10,
|
|
220
|
+
};
|
|
221
|
+
//# sourceMappingURL=client.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"client.js","sourceRoot":"","sources":["../src/client.tsx"],"names":[],"mappings":";AAMA,OAAO,EAAE,QA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;IACd,YAAY,EAAE,aAAa;IAC3B,UAAU,EAAE,MAAM;IAClB,KAAK,EAAE,MAAM;IACb,MAAM,EAAE,SAAS;IACjB,IAAI,EAAE,SAAS;IACf,QAAQ,EAAE,EAAE;IACZ,UAAU,EAAE,GAAG;CACf,CAAC;AACF,MAAM,cAAc,GAAwB;IAC3C,OAAO,EAAE,SAAS;IAClB,MAAM,EAAE,iCAAiC;IACzC,YAAY,EAAE,aAAa;IAC3B,UAAU,EAAE,aAAa;IACzB,KAAK,EAAE,qBAAqB;IAC5B,MAAM,EAAE,SAAS;IACjB,IAAI,EAAE,SAAS;IACf,QAAQ,EAAE,EAAE;CACZ,CAAC"}
|
package/dist/server.d.ts
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { ServerSessionType } from "@edv4h/usketch-session-protocol";
|
|
2
|
+
import type { VoteCastAction, VotingConfig, VotingPublicState, VotingSecret } from "./types.js";
|
|
3
|
+
export type { VoteCastAction, VotingConfig, VotingPrivateState, VotingPublicState, VotingSecret, } from "./types.js";
|
|
4
|
+
/**
|
|
5
|
+
* Server-authoritative voting session type. Dedups per userId, keeps who-voted-
|
|
6
|
+
* what in server-only `secret` (so a secret ballot never leaks in `public`),
|
|
7
|
+
* replaces the pick on single-choice re-vote / toggles it on multi.
|
|
8
|
+
*
|
|
9
|
+
* Registered into the Durable Object's `SessionManager` by `apps/server` — the
|
|
10
|
+
* server bundle is where a type's rules must live for the model to stay
|
|
11
|
+
* authoritative.
|
|
12
|
+
*/
|
|
13
|
+
export declare const votingServerType: ServerSessionType<VotingPublicState, VotingSecret, VotingConfig, VoteCastAction>;
|
|
14
|
+
//# sourceMappingURL=server.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"server.d.ts","sourceRoot":"","sources":["../src/server.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,iCAAiC,CAAC;AACzE,OAAO,KAAK,EACX,cAAc,EACd,YAAY,EAEZ,iBAAiB,EACjB,YAAY,EACZ,MAAM,YAAY,CAAC;AAEpB,YAAY,EACX,cAAc,EACd,YAAY,EACZ,kBAAkB,EAClB,iBAAiB,EACjB,YAAY,GACZ,MAAM,YAAY,CAAC;AAcpB;;;;;;;;GAQG;AACH,eAAO,MAAM,gBAAgB,EAAE,iBAAiB,CAC/C,iBAAiB,EACjB,YAAY,EACZ,YAAY,EACZ,cAAc,CAkDd,CAAC"}
|
package/dist/server.js
ADDED
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
function recomputeTally(pub, secret) {
|
|
2
|
+
const tally = pub.options.map(() => 0);
|
|
3
|
+
let voters = 0;
|
|
4
|
+
for (const picks of Object.values(secret.votes)) {
|
|
5
|
+
if (picks.length === 0)
|
|
6
|
+
continue;
|
|
7
|
+
voters++;
|
|
8
|
+
for (const i of picks)
|
|
9
|
+
if (i >= 0 && i < tally.length)
|
|
10
|
+
tally[i]++;
|
|
11
|
+
}
|
|
12
|
+
pub.tally = tally;
|
|
13
|
+
pub.totalVoters = voters;
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Server-authoritative voting session type. Dedups per userId, keeps who-voted-
|
|
17
|
+
* what in server-only `secret` (so a secret ballot never leaks in `public`),
|
|
18
|
+
* replaces the pick on single-choice re-vote / toggles it on multi.
|
|
19
|
+
*
|
|
20
|
+
* Registered into the Durable Object's `SessionManager` by `apps/server` — the
|
|
21
|
+
* server bundle is where a type's rules must live for the model to stay
|
|
22
|
+
* authoritative.
|
|
23
|
+
*/
|
|
24
|
+
export const votingServerType = {
|
|
25
|
+
type: "voting",
|
|
26
|
+
init(config) {
|
|
27
|
+
const options = config.options.slice(0, 8); // cap
|
|
28
|
+
const pub = {
|
|
29
|
+
type: "voting",
|
|
30
|
+
question: config.question,
|
|
31
|
+
options,
|
|
32
|
+
tally: options.map(() => 0),
|
|
33
|
+
totalVoters: 0,
|
|
34
|
+
secret: !!config.secret,
|
|
35
|
+
multi: !!config.multi,
|
|
36
|
+
status: "open",
|
|
37
|
+
};
|
|
38
|
+
return { public: pub, secret: { votes: {} } };
|
|
39
|
+
},
|
|
40
|
+
reduce(state, action, actorUserId) {
|
|
41
|
+
const pub = state.public;
|
|
42
|
+
const secret = state.secret;
|
|
43
|
+
if (action.kind !== "cast")
|
|
44
|
+
return "unknown action";
|
|
45
|
+
if (pub.status === "closed")
|
|
46
|
+
return "vote is closed";
|
|
47
|
+
const i = action.optionIndex;
|
|
48
|
+
if (!Number.isInteger(i) || i < 0 || i >= pub.options.length)
|
|
49
|
+
return "invalid option";
|
|
50
|
+
const cur = secret.votes[actorUserId] ?? [];
|
|
51
|
+
let next;
|
|
52
|
+
if (pub.multi) {
|
|
53
|
+
// toggle the option
|
|
54
|
+
next = cur.includes(i) ? cur.filter((x) => x !== i) : [...cur, i];
|
|
55
|
+
}
|
|
56
|
+
else {
|
|
57
|
+
// single choice: re-voting replaces the previous pick
|
|
58
|
+
next = cur.length === 1 && cur[0] === i ? [] : [i];
|
|
59
|
+
}
|
|
60
|
+
if (next.length === 0)
|
|
61
|
+
delete secret.votes[actorUserId];
|
|
62
|
+
else
|
|
63
|
+
secret.votes[actorUserId] = next;
|
|
64
|
+
recomputeTally(pub, secret);
|
|
65
|
+
return undefined;
|
|
66
|
+
},
|
|
67
|
+
privateFor(state, userId) {
|
|
68
|
+
return { type: "voting", myVotes: state.secret.votes[userId] ?? [] };
|
|
69
|
+
},
|
|
70
|
+
close(state) {
|
|
71
|
+
state.public.status = "closed";
|
|
72
|
+
},
|
|
73
|
+
};
|
|
74
|
+
//# sourceMappingURL=server.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"server.js","sourceRoot":"","sources":["../src/server.ts"],"names":[],"mappings":"AAiBA,SAAS,cAAc,CAAC,GAAsB,EAAE,MAAoB;IACnE,MAAM,KAAK,GAAG,GAAG,CAAC,OAAO,CAAC,GAAG,CAAC,GAAG,EAAE,CAAC,CAAC,CAAC,CAAC;IAC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E,QAAQ,EAAE,OAAO,EAAE,KAAK,CAAC,MAAM,CAAC,KAAK,CAAC,MAAM,CAAC,IAAI,EAAE,EAAE,CAAC;IACtE,CAAC;IAED,KAAK,CAAC,KAAK;QACV,KAAK,CAAC,MAAM,CAAC,MAAM,GAAG,QAAQ,CAAC;IAChC,CAAC;CACD,CAAC"}
|
package/dist/types.d.ts
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import type { SessionConfig } from "@edv4h/usketch-session-protocol";
|
|
2
|
+
/** Voting public state — broadcast to everyone. */
|
|
3
|
+
export interface VotingPublicState {
|
|
4
|
+
type: "voting";
|
|
5
|
+
question: string;
|
|
6
|
+
options: string[];
|
|
7
|
+
/** Vote count per option (index-aligned with `options`). */
|
|
8
|
+
tally: number[];
|
|
9
|
+
/** Number of distinct users who have voted. */
|
|
10
|
+
totalVoters: number;
|
|
11
|
+
/** Secret ballot: the server never reveals who voted for what (only tallies). */
|
|
12
|
+
secret: boolean;
|
|
13
|
+
/** Whether a voter may pick multiple options. */
|
|
14
|
+
multi: boolean;
|
|
15
|
+
status: "open" | "closed";
|
|
16
|
+
}
|
|
17
|
+
/** Create config for a voting session. */
|
|
18
|
+
export interface VotingConfig extends SessionConfig {
|
|
19
|
+
type: "voting";
|
|
20
|
+
question: string;
|
|
21
|
+
options: string[];
|
|
22
|
+
secret?: boolean;
|
|
23
|
+
multi?: boolean;
|
|
24
|
+
}
|
|
25
|
+
/** The only voting action: cast (or, when multi, toggle) a vote for an option. */
|
|
26
|
+
export interface VoteCastAction {
|
|
27
|
+
kind: "cast";
|
|
28
|
+
optionIndex: number;
|
|
29
|
+
}
|
|
30
|
+
/** Private view sent only to the voting user (their own picks). */
|
|
31
|
+
export interface VotingPrivateState {
|
|
32
|
+
type: "voting";
|
|
33
|
+
/** Option indexes this user has voted for. */
|
|
34
|
+
myVotes: number[];
|
|
35
|
+
}
|
|
36
|
+
/** Secret (server-only) voting state: which option indexes each user picked. */
|
|
37
|
+
export interface VotingSecret {
|
|
38
|
+
votes: Record<string, number[]>;
|
|
39
|
+
}
|
|
40
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,iCAAiC,CAAC;AAErE,mDAAmD;AACnD,MAAM,WAAW,iBAAiB;IACjC,IAAI,EAAE,QAAQ,CAAC;IACf,QAAQ,EAAE,MAAM,CAAC;IACjB,OAAO,EAAE,MAAM,EAAE,CAAC;IAClB,4DAA4D;IAC5D,KAAK,EAAE,MAAM,EAAE,CAAC;IAChB,+CAA+C;IAC/C,WAAW,EAAE,MAAM,CAAC;IACpB,iFAAiF;IACjF,MAAM,EAAE,OAAO,CAAC;IAChB,iDAAiD;IACjD,KAAK,EAAE,OAAO,CAAC;IACf,MAAM,EAAE,MAAM,GAAG,QAAQ,CAAC;CAC1B;AAED,0CAA0C;AAC1C,MAAM,WAAW,YAAa,SAAQ,aAAa;IAClD,IAAI,EAAE,QAAQ,CAAC;IACf,QAAQ,EAAE,MAAM,CAAC;IACjB,OAAO,EAAE,MAAM,EAAE,CAAC;IAClB,MAAM,CAAC,EAAE,OAAO,CAAC;IACjB,KAAK,CAAC,EAAE,OAAO,CAAC;CAChB;AAED,kFAAkF;AAClF,MAAM,WAAW,cAAc;IAC9B,IAAI,EAAE,MAAM,CAAC;IACb,WAAW,EAAE,MAAM,CAAC;CACpB;AAED,mEAAmE;AACnE,MAAM,WAAW,kBAAkB;IAClC,IAAI,EAAE,QAAQ,CAAC;IACf,8CAA8C;IAC9C,OAAO,EAAE,MAAM,EAAE,CAAC;CAClB;AAED,gFAAgF;AAChF,MAAM,WAAW,YAAY;IAC5B,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,EAAE,CAAC,CAAC;CAChC"}
|
package/dist/types.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":""}
|
package/package.json
ADDED
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@edv4h/usketch-session-voting",
|
|
3
|
+
"version": "0.2.0",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"exports": {
|
|
6
|
+
"./server": {
|
|
7
|
+
"source": "./src/server.ts",
|
|
8
|
+
"types": "./dist/server.d.ts",
|
|
9
|
+
"import": "./dist/server.js"
|
|
10
|
+
},
|
|
11
|
+
"./client": {
|
|
12
|
+
"source": "./src/client.tsx",
|
|
13
|
+
"types": "./dist/client.d.ts",
|
|
14
|
+
"import": "./dist/client.js"
|
|
15
|
+
}
|
|
16
|
+
},
|
|
17
|
+
"dependencies": {
|
|
18
|
+
"@edv4h/usketch-plugin-session": "0.2.0",
|
|
19
|
+
"@edv4h/usketch-session-protocol": "0.2.0"
|
|
20
|
+
},
|
|
21
|
+
"peerDependencies": {
|
|
22
|
+
"react": ">=19"
|
|
23
|
+
},
|
|
24
|
+
"devDependencies": {
|
|
25
|
+
"@types/react": "19.2.18",
|
|
26
|
+
"typescript": "7.0.2",
|
|
27
|
+
"vitest": "4.1.10"
|
|
28
|
+
},
|
|
29
|
+
"publishConfig": {
|
|
30
|
+
"access": "public"
|
|
31
|
+
},
|
|
32
|
+
"files": [
|
|
33
|
+
"dist",
|
|
34
|
+
"README.md"
|
|
35
|
+
],
|
|
36
|
+
"license": "MIT",
|
|
37
|
+
"repository": {
|
|
38
|
+
"type": "git",
|
|
39
|
+
"url": "git+https://github.com/EdV4H/usketch.git",
|
|
40
|
+
"directory": "packages/usketch-session-voting"
|
|
41
|
+
},
|
|
42
|
+
"homepage": "https://github.com/EdV4H/usketch#readme",
|
|
43
|
+
"bugs": {
|
|
44
|
+
"url": "https://github.com/EdV4H/usketch/issues"
|
|
45
|
+
},
|
|
46
|
+
"scripts": {
|
|
47
|
+
"build": "tsc -p tsconfig.json",
|
|
48
|
+
"typecheck": "tsc --noEmit",
|
|
49
|
+
"test": "vitest run --passWithNoTests",
|
|
50
|
+
"clean": "rm -rf dist"
|
|
51
|
+
}
|
|
52
|
+
}
|