dsh-offwork 0.0.0-stage → 1.0.1
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 +17 -0
- package/LICENSE +21 -0
- package/README.md +229 -2
- package/client.js +1392 -0
- package/client.source.js +1178 -0
- package/clock.js +150 -0
- package/cordis.patch.yml +4 -0
- package/icon.svg +1 -0
- package/index.js +274 -0
- package/locale/en.json +6 -0
- package/locale/zh.json +6 -0
- package/package.json +73 -4
- package/tests/clock.test.mjs +236 -0
- package/tests/host.test.mjs +221 -0
- package/tests/ui.test.mjs +132 -0
- package/tools/build.mjs +28 -0
- package/tools/check-package.mjs +96 -0
- package/ui-utils.js +62 -0
package/client.js
ADDED
|
@@ -0,0 +1,1392 @@
|
|
|
1
|
+
// Generated by tools/build.mjs; edit client.source.js, clock.js or ui-utils.js.
|
|
2
|
+
// Authored Client entry. Run node tools/build.mjs to inline the tested pure modules.
|
|
3
|
+
window.__ModuleLoader__.load({
|
|
4
|
+
id: 'dsh-offwork',
|
|
5
|
+
factory(require) {
|
|
6
|
+
const React = require('react');
|
|
7
|
+
const h = React.createElement;
|
|
8
|
+
// Pure calculation. Weekdays belong to the shift's START date, not the clock date.
|
|
9
|
+
// Keep helpers inside calculate: the client build embeds this exact function.
|
|
10
|
+
function calculate(settings, timestamp = Date.now()) {
|
|
11
|
+
const now = Number(timestamp);
|
|
12
|
+
if (!Number.isFinite(now)) throw new RangeError('Invalid timestamp');
|
|
13
|
+
const DAY = 86400000;
|
|
14
|
+
const formatter = new Intl.DateTimeFormat('en-CA', {
|
|
15
|
+
timeZone: settings.timezone,
|
|
16
|
+
year: 'numeric',
|
|
17
|
+
month: '2-digit',
|
|
18
|
+
day: '2-digit',
|
|
19
|
+
hour: '2-digit',
|
|
20
|
+
minute: '2-digit',
|
|
21
|
+
second: '2-digit',
|
|
22
|
+
hourCycle: 'h23',
|
|
23
|
+
});
|
|
24
|
+
const civil = (time) => {
|
|
25
|
+
const p = Object.fromEntries(formatter.formatToParts(time).map((p) => [p.type, p.value]));
|
|
26
|
+
return Date.UTC(+p.year, +p.month - 1, +p.day, +p.hour, +p.minute, +p.second);
|
|
27
|
+
};
|
|
28
|
+
// Convert a timezone-local civil time to an absolute instant. At DST overlaps use
|
|
29
|
+
// the earlier occurrence; at gaps move forward by the gap (Temporal-compatible).
|
|
30
|
+
const instant = (local) => {
|
|
31
|
+
const offsets = [
|
|
32
|
+
...new Set([-DAY, 0, DAY].map((delta) => civil(local + delta) - (local + delta))),
|
|
33
|
+
];
|
|
34
|
+
const candidates = offsets.map((offset) => local - offset);
|
|
35
|
+
const exact = candidates.filter((time) => civil(time) === local);
|
|
36
|
+
if (exact.length) return Math.min(...exact);
|
|
37
|
+
const after = candidates.filter((time) => civil(time) >= local);
|
|
38
|
+
return Math.min(...(after.length ? after : candidates));
|
|
39
|
+
};
|
|
40
|
+
const minute = (text) => {
|
|
41
|
+
if (typeof text !== 'string' || !/^(?:[01]\d|2[0-3]):[0-5]\d$/.test(text)) {
|
|
42
|
+
throw new RangeError('Shift times must be HH:mm');
|
|
43
|
+
}
|
|
44
|
+
const [h, m] = text.split(':').map(Number);
|
|
45
|
+
return h * 60 + m;
|
|
46
|
+
};
|
|
47
|
+
const start = minute(settings.start),
|
|
48
|
+
end = minute(settings.end);
|
|
49
|
+
if (start === end) throw new RangeError('Shift must not be empty');
|
|
50
|
+
const overnight = end < start;
|
|
51
|
+
const duration = (end - start + 1440) % 1440;
|
|
52
|
+
let breakOffset = 0,
|
|
53
|
+
breakDuration = 0;
|
|
54
|
+
if (settings.breakStart != null || settings.breakEnd != null) {
|
|
55
|
+
const bs = minute(settings.breakStart),
|
|
56
|
+
be = minute(settings.breakEnd);
|
|
57
|
+
if (bs !== be) {
|
|
58
|
+
breakOffset = (bs - start + 1440) % 1440;
|
|
59
|
+
breakDuration = (be - bs + 1440) % 1440;
|
|
60
|
+
if (breakOffset + breakDuration > duration || breakDuration >= duration) {
|
|
61
|
+
throw new RangeError('Break must be inside the shift and leave paid work');
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
const localNow = civil(now);
|
|
66
|
+
const today = Math.floor(localNow / DAY) * DAY;
|
|
67
|
+
const minuteNow = (localNow - today) / 60000;
|
|
68
|
+
const workday = (day) => settings.weekdays.includes(new Date(day).getUTCDay());
|
|
69
|
+
let shiftDay = today;
|
|
70
|
+
if (overnight && minuteNow < start) {
|
|
71
|
+
// Retain yesterday's finished work shift until the next shift starts. If
|
|
72
|
+
// yesterday was off, a working today is 'before' (e.g. Monday daytime).
|
|
73
|
+
if (minuteNow < end || workday(today - DAY)) shiftDay -= DAY;
|
|
74
|
+
}
|
|
75
|
+
const isWorkday = workday(shiftDay);
|
|
76
|
+
const shiftStart = instant(shiftDay + start * 60000);
|
|
77
|
+
const shiftEnd = instant(shiftDay + (start + duration) * 60000);
|
|
78
|
+
const breakStart = breakDuration ? instant(shiftDay + (start + breakOffset) * 60000) : null;
|
|
79
|
+
const breakEnd = breakDuration
|
|
80
|
+
? instant(shiftDay + (start + breakOffset + breakDuration) * 60000)
|
|
81
|
+
: null;
|
|
82
|
+
const breakMs = breakDuration ? breakEnd - breakStart : 0;
|
|
83
|
+
const totalMs = shiftEnd - shiftStart - breakMs;
|
|
84
|
+
if (totalMs <= 0 || breakMs < 0) throw new RangeError('Shift has no paid duration');
|
|
85
|
+
const clampedNow = Math.max(shiftStart, Math.min(now, shiftEnd));
|
|
86
|
+
const elapsedMs = isWorkday
|
|
87
|
+
? Math.max(
|
|
88
|
+
0,
|
|
89
|
+
Math.min(
|
|
90
|
+
totalMs,
|
|
91
|
+
clampedNow -
|
|
92
|
+
shiftStart -
|
|
93
|
+
(breakDuration ? Math.max(0, Math.min(clampedNow, breakEnd) - breakStart) : 0),
|
|
94
|
+
),
|
|
95
|
+
)
|
|
96
|
+
: 0;
|
|
97
|
+
const status = !isWorkday
|
|
98
|
+
? 'rest'
|
|
99
|
+
: now < shiftStart
|
|
100
|
+
? 'before'
|
|
101
|
+
: now >= shiftEnd
|
|
102
|
+
? 'done'
|
|
103
|
+
: breakDuration && now >= breakStart && now < breakEnd
|
|
104
|
+
? 'lunch'
|
|
105
|
+
: 'working';
|
|
106
|
+
// Decimal inputs become exact rational numbers before truncation. Never use
|
|
107
|
+
// floor((salary / days * progress) * 100): binary rounding loses whole cents.
|
|
108
|
+
const rational = (number) => {
|
|
109
|
+
if (typeof number !== 'number' || !Number.isFinite(number) || number < 0)
|
|
110
|
+
throw new RangeError('Invalid salary');
|
|
111
|
+
const [mantissa, exponent = '0'] = String(number).toLowerCase().split('e');
|
|
112
|
+
const [integer, fraction = ''] = mantissa.split('.');
|
|
113
|
+
const scale = fraction.length - Number(exponent);
|
|
114
|
+
return scale >= 0
|
|
115
|
+
? [BigInt(integer + fraction), 10n ** BigInt(scale)]
|
|
116
|
+
: [BigInt(integer + fraction) * 10n ** BigInt(-scale), 1n];
|
|
117
|
+
};
|
|
118
|
+
const payMode = settings.payMode === 'daily' ? 'daily' : 'monthly';
|
|
119
|
+
let [numerator, denominator] = rational(
|
|
120
|
+
payMode === 'daily' ? settings.dailySalary : settings.monthlySalary,
|
|
121
|
+
);
|
|
122
|
+
if (payMode === 'monthly') {
|
|
123
|
+
const [daysN, daysD] = rational(settings.workdaysPerMonth);
|
|
124
|
+
if (daysN === 0n) throw new RangeError('Workdays per month must be positive');
|
|
125
|
+
numerator *= daysD;
|
|
126
|
+
denominator *= daysN;
|
|
127
|
+
}
|
|
128
|
+
const dailyCents = Number((numerator * 100n) / denominator);
|
|
129
|
+
const earnedCents = Math.min(
|
|
130
|
+
dailyCents,
|
|
131
|
+
Number((numerator * 100n * BigInt(Math.floor(elapsedMs))) / (denominator * BigInt(totalMs))),
|
|
132
|
+
);
|
|
133
|
+
const hourlyCents = Number((numerator * 100n * 3600000n) / (denominator * BigInt(totalMs)));
|
|
134
|
+
const dateString = (day) => new Date(day).toISOString().slice(0, 10);
|
|
135
|
+
return {
|
|
136
|
+
status,
|
|
137
|
+
remaining: isWorkday ? Math.max(0, Math.ceil((shiftEnd - now) / 1000)) : 0,
|
|
138
|
+
startRemaining: status === 'before' ? Math.max(0, Math.ceil((shiftStart - now) / 1000)) : 0,
|
|
139
|
+
progress: elapsedMs / totalMs,
|
|
140
|
+
earned: earnedCents / 100,
|
|
141
|
+
daily: dailyCents / 100,
|
|
142
|
+
hourly: hourlyCents / 100,
|
|
143
|
+
date: dateString(today),
|
|
144
|
+
shiftDate: dateString(shiftDay),
|
|
145
|
+
earnedCents,
|
|
146
|
+
dailyCents,
|
|
147
|
+
payMode,
|
|
148
|
+
isWorkday,
|
|
149
|
+
overnight,
|
|
150
|
+
shiftStart,
|
|
151
|
+
shiftEnd,
|
|
152
|
+
breakStart,
|
|
153
|
+
breakEnd,
|
|
154
|
+
elapsed: elapsedMs / 1000,
|
|
155
|
+
total: totalMs / 1000,
|
|
156
|
+
};
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
// Small pure helpers shared by the browser artifact and its tests.
|
|
160
|
+
function formatDuration(seconds) {
|
|
161
|
+
if (!Number.isFinite(seconds) || seconds < 0) return '--:--:--';
|
|
162
|
+
const n = Math.ceil(seconds);
|
|
163
|
+
return [Math.floor(n / 3600), Math.floor((n % 3600) / 60), n % 60]
|
|
164
|
+
.map((part) => String(part).padStart(2, '0'))
|
|
165
|
+
.join(':');
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
function clampPosition(position, viewport, size) {
|
|
169
|
+
const width = Math.max(0, viewport.width),
|
|
170
|
+
height = Math.max(0, viewport.height);
|
|
171
|
+
const edge = Math.min(12, width / 2, height / 2);
|
|
172
|
+
const maxX = Math.max(edge, width - size.width - edge);
|
|
173
|
+
const maxY = Math.max(edge, height - size.height - edge);
|
|
174
|
+
return {
|
|
175
|
+
x: Math.max(edge, Math.min(Number.isFinite(position?.x) ? position.x : maxX, maxX)),
|
|
176
|
+
y: Math.max(edge, Math.min(Number.isFinite(position?.y) ? position.y : 88, maxY)),
|
|
177
|
+
};
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
function clampOpacity(value, fallback = 0.82) {
|
|
181
|
+
const number = Number(value);
|
|
182
|
+
if (!Number.isFinite(number)) return fallback;
|
|
183
|
+
return Math.min(1, Math.max(0.3, number));
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
function normalizeView(value) {
|
|
187
|
+
return {
|
|
188
|
+
mini: value?.mini !== false,
|
|
189
|
+
masked: value?.masked !== false,
|
|
190
|
+
opacity: clampOpacity(value?.opacity),
|
|
191
|
+
position:
|
|
192
|
+
Number.isFinite(value?.position?.x) && Number.isFinite(value?.position?.y)
|
|
193
|
+
? { x: value.position.x, y: value.position.y }
|
|
194
|
+
: null,
|
|
195
|
+
};
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
function decodeCommand(rpc) {
|
|
199
|
+
if (!rpc || rpc.ok !== true) throw new Error(rpc?.error?.message || 'RPC unavailable');
|
|
200
|
+
const result = rpc.value?.result;
|
|
201
|
+
if (!result || typeof result.text !== 'string') throw new Error('Command unavailable');
|
|
202
|
+
let data;
|
|
203
|
+
try {
|
|
204
|
+
data = JSON.parse(result.text);
|
|
205
|
+
} catch {
|
|
206
|
+
throw new Error('Invalid command response');
|
|
207
|
+
}
|
|
208
|
+
if (result.kind !== 'success' || data?.ok !== true)
|
|
209
|
+
throw new Error(data?.error || 'Request failed');
|
|
210
|
+
if (!data.settings || typeof data.settings !== 'object') throw new Error('Missing settings');
|
|
211
|
+
return data;
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
function changedSettings(original, draft) {
|
|
215
|
+
return Object.fromEntries(
|
|
216
|
+
Object.entries(draft).filter(
|
|
217
|
+
([key, value]) => JSON.stringify(value) !== JSON.stringify(original[key]),
|
|
218
|
+
),
|
|
219
|
+
);
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
const messages = {
|
|
223
|
+
zh: {
|
|
224
|
+
title: '下班计时器',
|
|
225
|
+
working: '距离下班',
|
|
226
|
+
before: '距离开工',
|
|
227
|
+
lunch: '午休中',
|
|
228
|
+
done: '本班已完成',
|
|
229
|
+
rest: '今天休息',
|
|
230
|
+
earned: '本班已赚 · 税前',
|
|
231
|
+
daily: '日薪',
|
|
232
|
+
hourly: '有效时薪',
|
|
233
|
+
progress: '计薪进度',
|
|
234
|
+
settings: '设置',
|
|
235
|
+
collapse: '收起为小条',
|
|
236
|
+
expand: '展开',
|
|
237
|
+
hide: '隐藏工资',
|
|
238
|
+
show: '显示工资',
|
|
239
|
+
save: '保存',
|
|
240
|
+
cancel: '取消',
|
|
241
|
+
monthlySalary: '税前月薪(元)',
|
|
242
|
+
dailySalary: '税前日薪(元)',
|
|
243
|
+
workdaysPerMonth: '月计薪天数',
|
|
244
|
+
start: '上班时间',
|
|
245
|
+
end: '下班时间',
|
|
246
|
+
breakStart: '休息开始',
|
|
247
|
+
breakEnd: '休息结束',
|
|
248
|
+
timezone: '时区',
|
|
249
|
+
weekdays: '班次开始日',
|
|
250
|
+
payMode: '计薪方式',
|
|
251
|
+
monthly: '月薪',
|
|
252
|
+
dailyMode: '日薪',
|
|
253
|
+
loading: '正在读取设置…',
|
|
254
|
+
retry: '重新读取',
|
|
255
|
+
noSession: '请先打开或创建一个会话。',
|
|
256
|
+
error: '操作失败,请重试。',
|
|
257
|
+
saved: '设置已保存',
|
|
258
|
+
days: '日一二三四五六',
|
|
259
|
+
privacy: '配置保存在 Harness 所在机器;读写结果进入所选会话记录。',
|
|
260
|
+
drag: '按住可拖动;方向键微调,Home 复位',
|
|
261
|
+
setup: '先设好你的作息',
|
|
262
|
+
setupHint: '示例数值不是你的收入,保存后才开始计时。',
|
|
263
|
+
breakEnabled: '扣除无薪休息',
|
|
264
|
+
noBreak: '不扣休息',
|
|
265
|
+
nextDay: '次日',
|
|
266
|
+
preview: '折算',
|
|
267
|
+
salaryGroup: '薪资',
|
|
268
|
+
scheduleGroup: '作息',
|
|
269
|
+
appearanceGroup: '外观',
|
|
270
|
+
advanced: '高级设置',
|
|
271
|
+
sessionHint: '仅用于记录配置读写操作,不是账本,不影响工资计算。',
|
|
272
|
+
session: '操作记录会话',
|
|
273
|
+
masked: '工资已隐藏',
|
|
274
|
+
reset: '复位位置',
|
|
275
|
+
synced: '已读取最新配置',
|
|
276
|
+
refresh: '读取最新配置',
|
|
277
|
+
busy: '保存中…',
|
|
278
|
+
storage: '浏览器禁止本地存储;位置与透明度本次有效。',
|
|
279
|
+
shiftDate: '班次',
|
|
280
|
+
opacity: '背景透明度',
|
|
281
|
+
opacityHint: '只影响背景,不影响文字。',
|
|
282
|
+
},
|
|
283
|
+
en: {
|
|
284
|
+
title: 'Offwork Clock',
|
|
285
|
+
working: 'Until clock-out',
|
|
286
|
+
before: 'Until work starts',
|
|
287
|
+
lunch: 'On break',
|
|
288
|
+
done: 'Shift complete',
|
|
289
|
+
rest: 'Day off',
|
|
290
|
+
earned: 'Earned this shift · gross',
|
|
291
|
+
daily: 'Shift pay',
|
|
292
|
+
hourly: 'Paid-hour rate',
|
|
293
|
+
progress: 'Paid progress',
|
|
294
|
+
settings: 'Settings',
|
|
295
|
+
collapse: 'Minimize to strip',
|
|
296
|
+
expand: 'Expand',
|
|
297
|
+
hide: 'Hide salary',
|
|
298
|
+
show: 'Show salary',
|
|
299
|
+
save: 'Save',
|
|
300
|
+
cancel: 'Cancel',
|
|
301
|
+
monthlySalary: 'Monthly gross (CNY)',
|
|
302
|
+
dailySalary: 'Daily gross (CNY)',
|
|
303
|
+
workdaysPerMonth: 'Paid days / month',
|
|
304
|
+
start: 'Shift starts',
|
|
305
|
+
end: 'Shift ends',
|
|
306
|
+
breakStart: 'Break starts',
|
|
307
|
+
breakEnd: 'Break ends',
|
|
308
|
+
timezone: 'Time zone',
|
|
309
|
+
weekdays: 'Shift starting days',
|
|
310
|
+
payMode: 'Pay basis',
|
|
311
|
+
monthly: 'Monthly',
|
|
312
|
+
dailyMode: 'Daily',
|
|
313
|
+
loading: 'Loading settings…',
|
|
314
|
+
retry: 'Reload',
|
|
315
|
+
noSession: 'Open or create a session first.',
|
|
316
|
+
error: 'Operation failed. Please retry.',
|
|
317
|
+
saved: 'Settings saved',
|
|
318
|
+
days: 'SMTWTFS',
|
|
319
|
+
privacy: 'Settings are saved on the Harness host; results enter the selected session log.',
|
|
320
|
+
drag: 'Drag to move; arrow keys to adjust; Home resets',
|
|
321
|
+
setup: 'Set up your schedule',
|
|
322
|
+
setupHint: 'These are example values, not your income. Save to start.',
|
|
323
|
+
breakEnabled: 'Deduct unpaid break',
|
|
324
|
+
noBreak: 'no break',
|
|
325
|
+
nextDay: 'next day',
|
|
326
|
+
preview: 'Preview',
|
|
327
|
+
salaryGroup: 'Salary',
|
|
328
|
+
scheduleGroup: 'Schedule',
|
|
329
|
+
appearanceGroup: 'Appearance',
|
|
330
|
+
advanced: 'Advanced',
|
|
331
|
+
sessionHint:
|
|
332
|
+
'Logs configuration operations only; not a ledger and does not affect pay calculations.',
|
|
333
|
+
session: 'Action log session',
|
|
334
|
+
masked: 'Salary hidden',
|
|
335
|
+
reset: 'Reset position',
|
|
336
|
+
synced: 'Latest settings loaded',
|
|
337
|
+
refresh: 'Reload latest settings',
|
|
338
|
+
busy: 'Saving…',
|
|
339
|
+
storage: 'Local storage is blocked; position and opacity last only for this visit.',
|
|
340
|
+
shiftDate: 'Shift',
|
|
341
|
+
opacity: 'Surface opacity',
|
|
342
|
+
opacityHint: 'Affects the background only.',
|
|
343
|
+
},
|
|
344
|
+
};
|
|
345
|
+
const STYLE = `
|
|
346
|
+
.owc-v2{--owc-accent:color-mix(in srgb,var(--dsw-alias-brand-primary) 65%,#2563eb);pointer-events:auto;position:fixed;top:96px;right:24px;z-index:40;max-width:calc(100vw - 24px);max-height:calc(100dvh - 24px);border-radius:20px;color:var(--dsw-alias-label-primary);font:13px/1.45 -apple-system,BlinkMacSystemFont,'Segoe UI','PingFang SC',sans-serif;cursor:grab;touch-action:manipulation;user-select:none;-webkit-user-select:none}
|
|
347
|
+
.owc-v2:active{cursor:grabbing}
|
|
348
|
+
.owc-v2.owc-compact{touch-action:none;border-radius:18px}
|
|
349
|
+
.owc-v2:not(.owc-compact){width:296px}
|
|
350
|
+
.owc-v2 :is(button,input,select,label,a){cursor:pointer;user-select:auto;-webkit-user-select:auto}
|
|
351
|
+
.owc-v2 :is(input,select){user-select:text;-webkit-user-select:text}
|
|
352
|
+
.owc-glass{position:absolute;inset:0;border-radius:inherit;pointer-events:none;opacity:var(--owc-alpha,.82);background:color-mix(in srgb,var(--dsw-alias-bg-overlay) 97%,var(--owc-accent));-webkit-backdrop-filter:blur(18px);backdrop-filter:blur(18px);border:1px solid color-mix(in srgb,var(--dsw-alias-label-secondary) 18%,transparent);box-shadow:inset 0 1px 0 color-mix(in srgb,var(--dsw-alias-bg-base) 70%,transparent),0 8px 20px color-mix(in srgb,var(--dsw-alias-label-primary) 7%,transparent),0 14px 34px color-mix(in srgb,var(--owc-accent) 5%,transparent);transition:opacity .18s ease}
|
|
353
|
+
.owc-content{position:relative;border-radius:inherit;max-height:calc(100dvh - 24px);overflow:auto;overscroll-behavior:contain;scrollbar-width:thin}
|
|
354
|
+
.owc-v2 button{appearance:none;-webkit-appearance:none;border:0;margin:0;background:transparent;color:inherit;font:inherit;display:inline-flex;align-items:center;justify-content:center;gap:5px;padding:6px;min-height:28px;border-radius:10px;transition:background .15s ease,color .15s ease}
|
|
355
|
+
.owc-v2 button:hover{background:color-mix(in srgb,var(--dsw-alias-label-primary) 7%,transparent)}
|
|
356
|
+
.owc-v2 button:focus-visible,.owc-v2 :is(input,select):focus-visible{outline:2px solid var(--dsw-alias-brand-primary);outline-offset:1px}
|
|
357
|
+
.owc-v2 button:disabled{opacity:.45;cursor:not-allowed;background:transparent}
|
|
358
|
+
.owc-icon{color:var(--dsw-alias-label-secondary);min-width:28px}
|
|
359
|
+
.owc-text{font-size:11px;color:var(--dsw-alias-label-secondary);padding:4px 6px;min-height:24px;white-space:nowrap}
|
|
360
|
+
.owc-text:hover{color:var(--dsw-alias-label-primary)}
|
|
361
|
+
.owc-pill{display:flex;flex-direction:column;gap:8px;padding:12px 10px 9px 14px;min-width:168px}
|
|
362
|
+
.owc-pill-top>svg{color:var(--owc-accent);flex:none}
|
|
363
|
+
.owc-pill-top>.owc-icon{color:var(--dsw-alias-label-secondary)}
|
|
364
|
+
.owc-pill-top{display:flex;align-items:center;gap:7px;min-width:0}
|
|
365
|
+
.owc-grip{display:flex;align-items:baseline;gap:7px;touch-action:none;min-width:0}
|
|
366
|
+
.owc-pill-bottom{display:flex;align-items:center;justify-content:space-between;gap:8px;padding-top:6px;border-top:1px solid color-mix(in srgb,var(--dsw-alias-label-secondary) 12%,transparent)}
|
|
367
|
+
.owc-pill-actions{display:flex;align-items:center;gap:2px}
|
|
368
|
+
.owc-pill-status{font-size:10px;color:var(--dsw-alias-label-secondary);white-space:nowrap;letter-spacing:.02em}
|
|
369
|
+
.owc-pill-time{font-size:24px;font-weight:500;letter-spacing:-.5px;font-variant-numeric:tabular-nums;white-space:nowrap;line-height:1.25}
|
|
370
|
+
.owc-pill-money{font-size:13px;color:var(--dsw-alias-label-secondary);font-variant-numeric:tabular-nums;white-space:nowrap;min-width:46px}
|
|
371
|
+
.owc-dot{width:6px;height:6px;border-radius:50%;background:var(--dsw-alias-state-idle-primary);flex:none}
|
|
372
|
+
.owc-v2[data-status=working] .owc-dot{background:var(--dsw-alias-state-success-primary)}
|
|
373
|
+
.owc-v2[data-status=lunch] .owc-dot{background:var(--dsw-alias-state-warn-primary)}
|
|
374
|
+
.owc-v2[data-status=done] .owc-dot{background:var(--dsw-alias-brand-primary)}
|
|
375
|
+
.owc-v2[data-status=before] .owc-dot,.owc-v2[data-status=rest] .owc-dot{opacity:.6}
|
|
376
|
+
.owc-head{display:flex;align-items:center;gap:4px;padding:12px 12px 10px 18px;margin-bottom:12px;border-bottom:1px solid color-mix(in srgb,var(--dsw-alias-label-secondary) 12%,transparent)}
|
|
377
|
+
.owc-title{flex:1;min-width:0;font-size:11px;font-weight:600;letter-spacing:.02em;color:var(--dsw-alias-label-secondary);white-space:nowrap;overflow:hidden;text-overflow:ellipsis}
|
|
378
|
+
.owc-main{padding:4px 17px 12px}
|
|
379
|
+
.owc-status{display:flex;align-items:center;gap:7px;font-size:11px;color:var(--dsw-alias-label-secondary);margin-bottom:1px}
|
|
380
|
+
.owc-time{font-size:34px;font-weight:350;line-height:1.28;letter-spacing:-1.2px;font-variant-numeric:tabular-nums}
|
|
381
|
+
.owc-progress{height:3px;border-radius:3px;overflow:hidden;background:color-mix(in srgb,var(--dsw-alias-label-primary) 9%,transparent);margin:10px 0 16px}
|
|
382
|
+
.owc-progress>div{height:100%;border-radius:3px;background:var(--owc-accent);transition:width .6s linear}
|
|
383
|
+
.owc-earn-row{display:flex;align-items:center;justify-content:space-between;gap:8px}
|
|
384
|
+
.owc-money{font-size:26px;font-weight:400;letter-spacing:-.6px;font-variant-numeric:tabular-nums;margin-top:1px}
|
|
385
|
+
.owc-muted{font-size:10.5px;color:var(--dsw-alias-label-secondary)}
|
|
386
|
+
.owc-stats{display:grid;grid-template-columns:1fr 1fr;gap:12px;margin-top:14px;padding-top:12px;border-top:1px solid color-mix(in srgb,var(--dsw-alias-label-primary) 8%,transparent)}
|
|
387
|
+
.owc-stats>div{padding:10px;border-radius:12px;background:color-mix(in srgb,var(--dsw-alias-label-secondary) 5%,transparent);border:1px solid color-mix(in srgb,var(--dsw-alias-label-secondary) 8%,transparent)}
|
|
388
|
+
.owc-stats span{display:block;font-size:10px;color:var(--dsw-alias-label-secondary)}
|
|
389
|
+
.owc-stats strong{display:block;margin-top:1px;font-size:13px;font-weight:500;font-variant-numeric:tabular-nums}
|
|
390
|
+
.owc-meta{margin-top:12px}
|
|
391
|
+
.owc-meta span{display:block;font-size:10.5px;line-height:1.7;color:var(--dsw-alias-label-secondary);white-space:nowrap;overflow:hidden;text-overflow:ellipsis}
|
|
392
|
+
.owc-row-actions{display:flex;gap:4px;margin-top:8px;margin-left:-6px}
|
|
393
|
+
.owc-form{padding:2px 17px 15px}
|
|
394
|
+
.owc-v2.owc-editing{width:340px}
|
|
395
|
+
.owc-setting-group{min-width:0;margin:0 0 16px;padding:12px 12px 2px;border:1px solid color-mix(in srgb,var(--dsw-alias-label-secondary) 15%,transparent);border-radius:14px;background:color-mix(in srgb,var(--dsw-alias-bg-base) 24%,transparent)}
|
|
396
|
+
.owc-setting-group legend{padding:0 6px;font-size:12px;font-weight:600;color:var(--dsw-alias-label-primary)}
|
|
397
|
+
.owc-form :is(input[type=time],input[type=number],select){min-height:36px;border-radius:10px}
|
|
398
|
+
.owc-advanced{margin:0 0 12px;padding:10px 12px;border-radius:12px;background:color-mix(in srgb,var(--dsw-alias-label-secondary) 5%,transparent)}
|
|
399
|
+
.owc-advanced summary{cursor:pointer;font-size:12px;font-weight:500}
|
|
400
|
+
.owc-advanced[open] summary{margin-bottom:10px}
|
|
401
|
+
.owc-grip:focus-visible,.owc-advanced summary:focus-visible{outline:2px solid var(--owc-accent);outline-offset:3px}
|
|
402
|
+
.owc-field{display:block;margin-bottom:10px}
|
|
403
|
+
.owc-field>span{display:block;font-size:10.5px;color:var(--dsw-alias-label-secondary);margin-bottom:4px}
|
|
404
|
+
.owc-row2{display:grid;grid-template-columns:1fr 1fr;gap:10px}
|
|
405
|
+
.owc-v2 :is(input[type=text],input[type=time],input[type=number],select){width:100%;box-sizing:border-box;font:inherit;font-size:12px;padding:6px 8px;border-radius:9px;border:1px solid color-mix(in srgb,var(--dsw-alias-label-primary) 13%,transparent);background:color-mix(in srgb,var(--dsw-alias-bg-base) 55%,transparent);color:inherit;min-height:30px}
|
|
406
|
+
.owc-v2 select option{background:var(--dsw-alias-bg-overlay);color:var(--dsw-alias-label-primary)}
|
|
407
|
+
.owc-seg{display:flex;gap:3px;padding:3px;border-radius:11px;background:color-mix(in srgb,var(--dsw-alias-label-primary) 6%,transparent)}
|
|
408
|
+
.owc-seg button{flex:1;font-size:11.5px;min-height:26px;border-radius:8px}
|
|
409
|
+
.owc-seg button[aria-pressed=true]{background:color-mix(in srgb,var(--dsw-alias-bg-overlay) 92%,var(--dsw-alias-bg-base));box-shadow:0 1px 3px color-mix(in srgb,var(--dsw-alias-label-primary) 10%,transparent)}
|
|
410
|
+
.owc-days{display:flex;gap:3px}
|
|
411
|
+
.owc-days button{flex:1;min-height:26px;font-size:11px;border-radius:8px;background:color-mix(in srgb,var(--dsw-alias-label-primary) 5%,transparent)}
|
|
412
|
+
.owc-days button[aria-pressed=true]{background:color-mix(in srgb,var(--owc-accent) 12%,transparent);color:var(--owc-accent);box-shadow:inset 0 0 0 1px color-mix(in srgb,var(--owc-accent) 22%,transparent)}
|
|
413
|
+
.owc-check{display:flex;flex-direction:row;align-items:center;gap:7px;font-size:11.5px;margin:0 0 10px}
|
|
414
|
+
.owc-check input{appearance:auto;-webkit-appearance:auto;width:auto;accent-color:var(--dsw-alias-brand-primary)}
|
|
415
|
+
.owc-private{display:flex;align-items:center;justify-content:space-between;gap:6px;min-height:30px;padding:4px 6px 4px 10px;border-radius:9px;border:1px dashed color-mix(in srgb,var(--dsw-alias-label-primary) 16%,transparent);font-size:12px;color:var(--dsw-alias-label-secondary)}
|
|
416
|
+
.owc-preview{font-size:11px;color:var(--dsw-alias-label-secondary);padding:8px 10px;border-radius:10px;background:color-mix(in srgb,var(--dsw-alias-label-primary) 5%,transparent);margin:0 0 10px;font-variant-numeric:tabular-nums}
|
|
417
|
+
.owc-hint{font-size:10.5px;line-height:1.6;color:var(--dsw-alias-label-secondary);margin:0 0 10px}
|
|
418
|
+
.owc-range{width:100%;accent-color:var(--dsw-alias-brand-primary);margin:1px 0 2px}
|
|
419
|
+
.owc-save{display:flex;align-items:center;justify-content:flex-end;gap:6px;margin-top:12px}
|
|
420
|
+
.owc-v2 button.owc-primary{background:var(--owc-accent);color:#fff;padding:0 16px;min-height:36px;font-size:12px;font-weight:600;border-radius:12px}
|
|
421
|
+
.owc-v2 button.owc-primary:hover{background:color-mix(in srgb,var(--owc-accent) 88%,#000)}
|
|
422
|
+
.owc-v2 button.owc-primary:disabled{opacity:.5;color:#fff;background:var(--owc-accent)}
|
|
423
|
+
.owc-error,.owc-note{padding:0 17px 9px;margin:0;font-size:10.5px;line-height:1.6}
|
|
424
|
+
.owc-error{color:var(--dsw-alias-state-error-primary)}
|
|
425
|
+
.owc-note{color:var(--dsw-alias-label-secondary)}
|
|
426
|
+
@supports not ((backdrop-filter:blur(1px)) or (-webkit-backdrop-filter:blur(1px))){.owc-glass{opacity:1}}
|
|
427
|
+
@media(prefers-reduced-transparency:reduce),(prefers-contrast:more){.owc-glass{opacity:1;-webkit-backdrop-filter:none;backdrop-filter:none}}
|
|
428
|
+
@media(prefers-reduced-motion:reduce){.owc-v2 button,.owc-glass,.owc-progress>div{transition:none}}
|
|
429
|
+
@media(max-width:420px){.owc-pill{min-width:136px;padding:8px 8px 7px 12px}.owc-pill-status{display:none}.owc-pill-time{font-size:22px}.owc-main,.owc-form{padding-left:14px;padding-right:14px}.owc-time{font-size:31px}}
|
|
430
|
+
`;
|
|
431
|
+
const ICONS = {
|
|
432
|
+
eye: [
|
|
433
|
+
['path', { d: 'M1.7 8S4.3 3.9 8 3.9 14.3 8 14.3 8 11.7 12.1 8 12.1 1.7 8 1.7 8Z' }],
|
|
434
|
+
['circle', { cx: 8, cy: 8, r: 2.05 }],
|
|
435
|
+
],
|
|
436
|
+
eyeOff: [
|
|
437
|
+
['path', { d: 'M1.7 8S4.3 3.9 8 3.9 14.3 8 14.3 8 11.7 12.1 8 12.1 1.7 8 1.7 8Z' }],
|
|
438
|
+
['circle', { cx: 8, cy: 8, r: 2.05 }],
|
|
439
|
+
['path', { d: 'M3 3l10 10' }],
|
|
440
|
+
],
|
|
441
|
+
sliders: [
|
|
442
|
+
['path', { d: 'M2.2 4.6h3.4M9.2 4.6h4.6M2.2 11.4h5.4M11.4 11.4h2.4' }],
|
|
443
|
+
['circle', { cx: 7.3, cy: 4.6, r: 1.55 }],
|
|
444
|
+
['circle', { cx: 9.4, cy: 11.4, r: 1.55 }],
|
|
445
|
+
],
|
|
446
|
+
alarm: [
|
|
447
|
+
['circle', { cx: 8, cy: 9, r: 4.5 }],
|
|
448
|
+
['path', { d: 'M8 6.5V9l1.7 1M2 4l2-2M12 2l2 2M5 13l-1 2M11 13l1 2' }],
|
|
449
|
+
],
|
|
450
|
+
chevronUp: [['path', { d: 'M3.7 9.8L8 5.5l4.3 4.3' }]],
|
|
451
|
+
chevronDown: [['path', { d: 'M3.7 6.2L8 10.5l4.3-4.3' }]],
|
|
452
|
+
close: [['path', { d: 'M4.3 4.3l7.4 7.4M11.7 4.3l-7.4 7.4' }]],
|
|
453
|
+
refresh: [
|
|
454
|
+
['path', { d: 'M13.1 8a5.1 5.1 0 1 1-1.5-3.6' }],
|
|
455
|
+
['path', { d: 'M13.1 3v3.2H9.9' }],
|
|
456
|
+
],
|
|
457
|
+
};
|
|
458
|
+
const iconSvg = (name, size = 15) =>
|
|
459
|
+
h(
|
|
460
|
+
'svg',
|
|
461
|
+
{
|
|
462
|
+
width: size,
|
|
463
|
+
height: size,
|
|
464
|
+
viewBox: '0 0 16 16',
|
|
465
|
+
fill: 'none',
|
|
466
|
+
stroke: 'currentColor',
|
|
467
|
+
strokeWidth: 1.55,
|
|
468
|
+
strokeLinecap: 'round',
|
|
469
|
+
strokeLinejoin: 'round',
|
|
470
|
+
'aria-hidden': 'true',
|
|
471
|
+
focusable: 'false',
|
|
472
|
+
},
|
|
473
|
+
ICONS[name].map(([tag, attrs], index) => h(tag, { key: index, ...attrs })),
|
|
474
|
+
);
|
|
475
|
+
|
|
476
|
+
return {
|
|
477
|
+
inject: ['slots', 'locale', 'remote', 'remote.commands'],
|
|
478
|
+
apply(ctx) {
|
|
479
|
+
for (const [lang, dict] of Object.entries(messages))
|
|
480
|
+
ctx.effect(() => ctx.locale.register('offwork-clock', lang, dict));
|
|
481
|
+
const viewKey = 'dsh.offwork-clock.view.v4';
|
|
482
|
+
const legacyKey = 'dsh.offwork-clock.view.v3';
|
|
483
|
+
|
|
484
|
+
function Clock(props) {
|
|
485
|
+
const locale = React.useSyncExternalStore(
|
|
486
|
+
(fn) => ctx.locale.subscribe(fn),
|
|
487
|
+
() => ctx.locale.getSnapshot(),
|
|
488
|
+
);
|
|
489
|
+
const t = ctx.locale.bind('offwork-clock');
|
|
490
|
+
const sessions = props.useSessions((s) => s);
|
|
491
|
+
const sessionIds = Array.isArray(sessions?.ids) ? sessions.ids : [];
|
|
492
|
+
const [sessionChoice, setSessionChoice] = React.useState('');
|
|
493
|
+
const sessionId = sessionIds.includes(sessionChoice) ? sessionChoice : sessionIds[0];
|
|
494
|
+
const [data, setData] = React.useState(null);
|
|
495
|
+
const [draft, setDraft] = React.useState(null);
|
|
496
|
+
const [editing, setEditing] = React.useState(false);
|
|
497
|
+
const [busy, setBusy] = React.useState(false);
|
|
498
|
+
const [error, setError] = React.useState('');
|
|
499
|
+
const [notice, setNotice] = React.useState('');
|
|
500
|
+
const [storageError, setStorageError] = React.useState(false);
|
|
501
|
+
const [now, setNow] = React.useState(Date.now());
|
|
502
|
+
const [view, setView] = React.useState(normalizeView(null));
|
|
503
|
+
const [ready, setReady] = React.useState(false);
|
|
504
|
+
const box = React.useRef(null);
|
|
505
|
+
const dragState = React.useRef(null);
|
|
506
|
+
const lastPosition = React.useRef(null);
|
|
507
|
+
const generation = React.useRef(0);
|
|
508
|
+
const requestBusy = React.useRef(false);
|
|
509
|
+
const focusReturn = React.useRef(null);
|
|
510
|
+
|
|
511
|
+
const settings = data?.settings;
|
|
512
|
+
const workingDraft = draft || settings;
|
|
513
|
+
const state = settings ? safeCalculate(settings) : null;
|
|
514
|
+
const preview = workingDraft ? safeCalculate(workingDraft) : null;
|
|
515
|
+
const safeState = state && !state.error ? state : null;
|
|
516
|
+
const collapsed = !!safeState && !editing && view.mini && !error && !state?.error;
|
|
517
|
+
const seconds = safeState
|
|
518
|
+
? safeState.status === 'before'
|
|
519
|
+
? safeState.startRemaining
|
|
520
|
+
: safeState.remaining
|
|
521
|
+
: NaN;
|
|
522
|
+
const duration = formatDuration(seconds);
|
|
523
|
+
const formatMoney = React.useMemo(
|
|
524
|
+
() =>
|
|
525
|
+
new Intl.NumberFormat(locale.active, {
|
|
526
|
+
style: 'currency',
|
|
527
|
+
currency: 'CNY',
|
|
528
|
+
minimumFractionDigits: 2,
|
|
529
|
+
maximumFractionDigits: 2,
|
|
530
|
+
}),
|
|
531
|
+
[locale.active],
|
|
532
|
+
);
|
|
533
|
+
const money = (value) => (view.masked ? '••••' : formatMoney.format(value));
|
|
534
|
+
const moneyText = safeState ? money(safeState.earned) : '—';
|
|
535
|
+
const cardStyle = Object.assign(
|
|
536
|
+
{ '--owc-alpha': String(view.opacity) },
|
|
537
|
+
view.position ? { left: view.position.x, top: view.position.y, right: 'auto' } : {},
|
|
538
|
+
);
|
|
539
|
+
|
|
540
|
+
function safeCalculate(value) {
|
|
541
|
+
try {
|
|
542
|
+
return calculate(value, now);
|
|
543
|
+
} catch (e) {
|
|
544
|
+
return { error: e instanceof Error ? e.message : t('error') };
|
|
545
|
+
}
|
|
546
|
+
}
|
|
547
|
+
function errorText(e) {
|
|
548
|
+
return e instanceof Error ? e.message : t('error');
|
|
549
|
+
}
|
|
550
|
+
function setPreference(patch) {
|
|
551
|
+
setView((current) => ({ ...current, ...patch }));
|
|
552
|
+
}
|
|
553
|
+
|
|
554
|
+
const clamp = React.useCallback(
|
|
555
|
+
(position) =>
|
|
556
|
+
clampPosition(
|
|
557
|
+
position,
|
|
558
|
+
{ width: window.innerWidth, height: window.innerHeight },
|
|
559
|
+
{
|
|
560
|
+
width: box.current?.offsetWidth || 300,
|
|
561
|
+
height: box.current?.offsetHeight || 200,
|
|
562
|
+
},
|
|
563
|
+
),
|
|
564
|
+
[],
|
|
565
|
+
);
|
|
566
|
+
|
|
567
|
+
React.useEffect(() => {
|
|
568
|
+
try {
|
|
569
|
+
const saved = localStorage.getItem(viewKey);
|
|
570
|
+
const legacy = !saved ? JSON.parse(localStorage.getItem(legacyKey) || 'null') : null;
|
|
571
|
+
setView(
|
|
572
|
+
normalizeView(
|
|
573
|
+
saved
|
|
574
|
+
? JSON.parse(saved)
|
|
575
|
+
: { position: legacy?.position ?? null, masked: legacy?.masked ?? true },
|
|
576
|
+
),
|
|
577
|
+
);
|
|
578
|
+
} catch {
|
|
579
|
+
setStorageError(true);
|
|
580
|
+
}
|
|
581
|
+
setReady(true);
|
|
582
|
+
const sync = (e) => {
|
|
583
|
+
if (e.key !== viewKey) return;
|
|
584
|
+
try {
|
|
585
|
+
setView(normalizeView(JSON.parse(e.newValue || 'null')));
|
|
586
|
+
} catch {}
|
|
587
|
+
};
|
|
588
|
+
window.addEventListener('storage', sync);
|
|
589
|
+
return () => window.removeEventListener('storage', sync);
|
|
590
|
+
}, []);
|
|
591
|
+
|
|
592
|
+
React.useEffect(() => {
|
|
593
|
+
if (!ready) return;
|
|
594
|
+
try {
|
|
595
|
+
localStorage.setItem(viewKey, JSON.stringify(normalizeView(view)));
|
|
596
|
+
} catch {
|
|
597
|
+
setStorageError(true);
|
|
598
|
+
}
|
|
599
|
+
}, [ready, view]);
|
|
600
|
+
|
|
601
|
+
React.useEffect(() => {
|
|
602
|
+
if (sessionId) reload();
|
|
603
|
+
else setError(t('noSession'));
|
|
604
|
+
return () => {
|
|
605
|
+
generation.current++;
|
|
606
|
+
};
|
|
607
|
+
}, [sessionId]);
|
|
608
|
+
|
|
609
|
+
React.useEffect(() => {
|
|
610
|
+
let timer;
|
|
611
|
+
const tick = () => {
|
|
612
|
+
setNow(Date.now());
|
|
613
|
+
timer = setTimeout(tick, 1000 - (Date.now() % 1000));
|
|
614
|
+
};
|
|
615
|
+
const visibility = () => {
|
|
616
|
+
clearTimeout(timer);
|
|
617
|
+
setNow(Date.now());
|
|
618
|
+
if (!document.hidden) tick();
|
|
619
|
+
};
|
|
620
|
+
if (!document.hidden) tick();
|
|
621
|
+
document.addEventListener('visibilitychange', visibility);
|
|
622
|
+
return () => {
|
|
623
|
+
clearTimeout(timer);
|
|
624
|
+
document.removeEventListener('visibilitychange', visibility);
|
|
625
|
+
};
|
|
626
|
+
}, []);
|
|
627
|
+
|
|
628
|
+
React.useEffect(() => {
|
|
629
|
+
const resize = () =>
|
|
630
|
+
setView((current) =>
|
|
631
|
+
current.position ? { ...current, position: clamp(current.position) } : current,
|
|
632
|
+
);
|
|
633
|
+
const ro = typeof ResizeObserver === 'function' ? new ResizeObserver(resize) : null;
|
|
634
|
+
if (box.current) ro?.observe(box.current);
|
|
635
|
+
window.addEventListener('resize', resize);
|
|
636
|
+
return () => {
|
|
637
|
+
ro?.disconnect();
|
|
638
|
+
window.removeEventListener('resize', resize);
|
|
639
|
+
};
|
|
640
|
+
}, [clamp]);
|
|
641
|
+
|
|
642
|
+
React.useEffect(() => {
|
|
643
|
+
if (!editing) {
|
|
644
|
+
focusReturn.current?.focus?.();
|
|
645
|
+
return;
|
|
646
|
+
}
|
|
647
|
+
box.current?.querySelector('form input,form select')?.focus?.();
|
|
648
|
+
}, [editing]);
|
|
649
|
+
|
|
650
|
+
React.useEffect(
|
|
651
|
+
() => () => {
|
|
652
|
+
generation.current++;
|
|
653
|
+
dragState.current = null;
|
|
654
|
+
},
|
|
655
|
+
[],
|
|
656
|
+
);
|
|
657
|
+
|
|
658
|
+
async function request(action, patch) {
|
|
659
|
+
if (!sessionId) throw new Error(t('noSession'));
|
|
660
|
+
const rpc = await ctx.remote.commands.execute(
|
|
661
|
+
sessionId,
|
|
662
|
+
'/offwork-clock ' + action + (patch ? ' ' + JSON.stringify(patch) : ''),
|
|
663
|
+
[],
|
|
664
|
+
);
|
|
665
|
+
return decodeCommand(rpc);
|
|
666
|
+
}
|
|
667
|
+
|
|
668
|
+
async function reload(explicit = false) {
|
|
669
|
+
if (requestBusy.current) return;
|
|
670
|
+
const token = ++generation.current;
|
|
671
|
+
setBusy(true);
|
|
672
|
+
setError('');
|
|
673
|
+
try {
|
|
674
|
+
const next = await request('get');
|
|
675
|
+
if (token !== generation.current) return;
|
|
676
|
+
setData(next);
|
|
677
|
+
if (!next.configured) {
|
|
678
|
+
setDraft({ ...next.settings });
|
|
679
|
+
setEditing(true);
|
|
680
|
+
}
|
|
681
|
+
if (explicit) setNotice(t('synced'));
|
|
682
|
+
} catch (e) {
|
|
683
|
+
if (token === generation.current) setError(errorText(e));
|
|
684
|
+
} finally {
|
|
685
|
+
if (token === generation.current) setBusy(false);
|
|
686
|
+
}
|
|
687
|
+
}
|
|
688
|
+
|
|
689
|
+
async function save(event) {
|
|
690
|
+
event.preventDefault();
|
|
691
|
+
if (requestBusy.current) return;
|
|
692
|
+
requestBusy.current = true;
|
|
693
|
+
setBusy(true);
|
|
694
|
+
setError('');
|
|
695
|
+
const token = ++generation.current;
|
|
696
|
+
try {
|
|
697
|
+
const next = await request('set', changedSettings(settings, draft));
|
|
698
|
+
if (token === generation.current) {
|
|
699
|
+
setData(next);
|
|
700
|
+
setEditing(false);
|
|
701
|
+
setDraft(null);
|
|
702
|
+
setNotice(t('saved'));
|
|
703
|
+
}
|
|
704
|
+
} catch (e) {
|
|
705
|
+
if (token === generation.current) setError(errorText(e));
|
|
706
|
+
} finally {
|
|
707
|
+
requestBusy.current = false;
|
|
708
|
+
if (token === generation.current) setBusy(false);
|
|
709
|
+
}
|
|
710
|
+
}
|
|
711
|
+
|
|
712
|
+
function commitPosition(position) {
|
|
713
|
+
const next = clamp(position);
|
|
714
|
+
setPreference({ position: next });
|
|
715
|
+
lastPosition.current = next;
|
|
716
|
+
}
|
|
717
|
+
function dragDown(e) {
|
|
718
|
+
if (e.button !== 0) return;
|
|
719
|
+
if (
|
|
720
|
+
e.target.closest?.('button,input,select,label,a,textarea,summary,[contenteditable]')
|
|
721
|
+
)
|
|
722
|
+
return;
|
|
723
|
+
const rect = box.current.getBoundingClientRect();
|
|
724
|
+
dragState.current = {
|
|
725
|
+
dx: e.clientX - rect.left,
|
|
726
|
+
dy: e.clientY - rect.top,
|
|
727
|
+
x0: e.clientX,
|
|
728
|
+
y0: e.clientY,
|
|
729
|
+
moved: false,
|
|
730
|
+
};
|
|
731
|
+
try {
|
|
732
|
+
e.currentTarget.setPointerCapture?.(e.pointerId);
|
|
733
|
+
} catch {}
|
|
734
|
+
}
|
|
735
|
+
function dragMove(e) {
|
|
736
|
+
const d = dragState.current;
|
|
737
|
+
if (!d) return;
|
|
738
|
+
if (!d.moved && Math.abs(e.clientX - d.x0) + Math.abs(e.clientY - d.y0) < 4) return;
|
|
739
|
+
d.moved = true;
|
|
740
|
+
const next = clamp({ x: e.clientX - d.dx, y: e.clientY - d.dy });
|
|
741
|
+
lastPosition.current = next;
|
|
742
|
+
if (box.current) {
|
|
743
|
+
box.current.style.left = next.x + 'px';
|
|
744
|
+
box.current.style.top = next.y + 'px';
|
|
745
|
+
box.current.style.right = 'auto';
|
|
746
|
+
}
|
|
747
|
+
}
|
|
748
|
+
function dragEnd(e) {
|
|
749
|
+
const d = dragState.current;
|
|
750
|
+
if (!d) return;
|
|
751
|
+
dragState.current = null;
|
|
752
|
+
if (d.moved && lastPosition.current) commitPosition(lastPosition.current);
|
|
753
|
+
try {
|
|
754
|
+
if (e.currentTarget.hasPointerCapture?.(e.pointerId))
|
|
755
|
+
e.currentTarget.releasePointerCapture(e.pointerId);
|
|
756
|
+
} catch {}
|
|
757
|
+
}
|
|
758
|
+
function gripKeys(e) {
|
|
759
|
+
if (e.key === 'Home') {
|
|
760
|
+
e.preventDefault();
|
|
761
|
+
setPreference({ position: null });
|
|
762
|
+
return;
|
|
763
|
+
}
|
|
764
|
+
if (!['ArrowLeft', 'ArrowRight', 'ArrowUp', 'ArrowDown'].includes(e.key)) return;
|
|
765
|
+
e.preventDefault();
|
|
766
|
+
const rect = box.current.getBoundingClientRect();
|
|
767
|
+
commitPosition({
|
|
768
|
+
x: rect.left + (e.key === 'ArrowRight' ? 10 : e.key === 'ArrowLeft' ? -10 : 0),
|
|
769
|
+
y: rect.top + (e.key === 'ArrowDown' ? 10 : e.key === 'ArrowUp' ? -10 : 0),
|
|
770
|
+
});
|
|
771
|
+
}
|
|
772
|
+
|
|
773
|
+
function openEditor(e) {
|
|
774
|
+
focusReturn.current = e.currentTarget;
|
|
775
|
+
setDraft({ ...settings });
|
|
776
|
+
setEditing(true);
|
|
777
|
+
setError('');
|
|
778
|
+
setNotice('');
|
|
779
|
+
}
|
|
780
|
+
function closeEditor() {
|
|
781
|
+
if (!data?.configured) return;
|
|
782
|
+
setEditing(false);
|
|
783
|
+
setDraft(null);
|
|
784
|
+
setError('');
|
|
785
|
+
}
|
|
786
|
+
function update(key, value) {
|
|
787
|
+
setDraft((current) => ({ ...current, [key]: value }));
|
|
788
|
+
}
|
|
789
|
+
function toggleBreak(e) {
|
|
790
|
+
const point = (text) => +text.slice(0, 2) * 60 + +text.slice(3);
|
|
791
|
+
const label = (minutes) =>
|
|
792
|
+
String(Math.floor(minutes / 60)).padStart(2, '0') +
|
|
793
|
+
':' +
|
|
794
|
+
String(minutes % 60).padStart(2, '0');
|
|
795
|
+
setDraft((current) => {
|
|
796
|
+
if (!e.target.checked)
|
|
797
|
+
return { ...current, breakStart: current.start, breakEnd: current.start };
|
|
798
|
+
const start = point(current.start);
|
|
799
|
+
const span = (point(current.end) - start + 1440) % 1440;
|
|
800
|
+
return {
|
|
801
|
+
...current,
|
|
802
|
+
breakStart: current.start,
|
|
803
|
+
breakEnd: label((start + Math.max(1, Math.min(60, Math.floor(span / 2)))) % 1440),
|
|
804
|
+
};
|
|
805
|
+
});
|
|
806
|
+
}
|
|
807
|
+
|
|
808
|
+
const label = (text, control) =>
|
|
809
|
+
h('label', { className: 'owc-field' }, h('span', null, text), control);
|
|
810
|
+
const numberInput = (key) =>
|
|
811
|
+
h('input', {
|
|
812
|
+
name: key,
|
|
813
|
+
type: 'number',
|
|
814
|
+
step: 'any',
|
|
815
|
+
min: key === 'workdaysPerMonth' ? '0.01' : '0',
|
|
816
|
+
value: workingDraft?.[key] ?? '',
|
|
817
|
+
disabled: busy,
|
|
818
|
+
onChange: (e) => update(key, e.target.value === '' ? '' : e.target.valueAsNumber),
|
|
819
|
+
});
|
|
820
|
+
const timeInput = (key) =>
|
|
821
|
+
h('input', {
|
|
822
|
+
name: key,
|
|
823
|
+
type: 'time',
|
|
824
|
+
required: true,
|
|
825
|
+
value: workingDraft?.[key] ?? '',
|
|
826
|
+
disabled: busy,
|
|
827
|
+
onChange: (e) => update(key, e.target.value),
|
|
828
|
+
});
|
|
829
|
+
const sessionSelect = () =>
|
|
830
|
+
h(
|
|
831
|
+
'select',
|
|
832
|
+
{
|
|
833
|
+
value: sessionId || '',
|
|
834
|
+
disabled: busy,
|
|
835
|
+
onChange: (e) => setSessionChoice(e.target.value),
|
|
836
|
+
},
|
|
837
|
+
sessionIds.length
|
|
838
|
+
? sessionIds.map((id) =>
|
|
839
|
+
h(
|
|
840
|
+
'option',
|
|
841
|
+
{ key: id, value: id },
|
|
842
|
+
sessions?.byId?.[id]?.title || String(id).slice(0, 12),
|
|
843
|
+
),
|
|
844
|
+
)
|
|
845
|
+
: h('option', { value: '' }, t('noSession')),
|
|
846
|
+
);
|
|
847
|
+
const salaryToggle = () =>
|
|
848
|
+
h(
|
|
849
|
+
'button',
|
|
850
|
+
{
|
|
851
|
+
type: 'button',
|
|
852
|
+
className: 'owc-text',
|
|
853
|
+
'aria-pressed': view.masked,
|
|
854
|
+
title: t(view.masked ? 'show' : 'hide'),
|
|
855
|
+
onClick: () => setPreference({ masked: !view.masked }),
|
|
856
|
+
},
|
|
857
|
+
iconSvg(view.masked ? 'eyeOff' : 'eye', 13),
|
|
858
|
+
t(view.masked ? 'show' : 'hide'),
|
|
859
|
+
);
|
|
860
|
+
|
|
861
|
+
const strip = () =>
|
|
862
|
+
h(
|
|
863
|
+
'div',
|
|
864
|
+
{ className: 'owc-pill' },
|
|
865
|
+
h(
|
|
866
|
+
'div',
|
|
867
|
+
{ className: 'owc-pill-top' },
|
|
868
|
+
iconSvg('alarm', 16),
|
|
869
|
+
h(
|
|
870
|
+
'span',
|
|
871
|
+
{ className: 'owc-grip', tabIndex: 0, title: t('drag'), onKeyDown: gripKeys },
|
|
872
|
+
safeState.status !== 'done' &&
|
|
873
|
+
h('span', { className: 'owc-pill-status' }, t(safeState.status)),
|
|
874
|
+
h('span', { className: 'owc-pill-time' }, duration),
|
|
875
|
+
),
|
|
876
|
+
h(
|
|
877
|
+
'button',
|
|
878
|
+
{
|
|
879
|
+
type: 'button',
|
|
880
|
+
className: 'owc-icon',
|
|
881
|
+
style: { marginLeft: 'auto' },
|
|
882
|
+
title: t('expand'),
|
|
883
|
+
'aria-label': t('expand'),
|
|
884
|
+
onClick: () => setPreference({ mini: false }),
|
|
885
|
+
},
|
|
886
|
+
iconSvg('chevronUp', 14),
|
|
887
|
+
),
|
|
888
|
+
),
|
|
889
|
+
h(
|
|
890
|
+
'div',
|
|
891
|
+
{ className: 'owc-pill-bottom' },
|
|
892
|
+
h(
|
|
893
|
+
'span',
|
|
894
|
+
{
|
|
895
|
+
className: 'owc-pill-money',
|
|
896
|
+
'aria-label': view.masked ? t('masked') : moneyText,
|
|
897
|
+
},
|
|
898
|
+
moneyText,
|
|
899
|
+
),
|
|
900
|
+
h(
|
|
901
|
+
'div',
|
|
902
|
+
{ className: 'owc-pill-actions' },
|
|
903
|
+
h(
|
|
904
|
+
'button',
|
|
905
|
+
{
|
|
906
|
+
type: 'button',
|
|
907
|
+
className: 'owc-icon',
|
|
908
|
+
title: t(view.masked ? 'show' : 'hide'),
|
|
909
|
+
'aria-label': t(view.masked ? 'show' : 'hide'),
|
|
910
|
+
onClick: () => setPreference({ masked: !view.masked }),
|
|
911
|
+
},
|
|
912
|
+
iconSvg(view.masked ? 'eyeOff' : 'eye', 14),
|
|
913
|
+
),
|
|
914
|
+
),
|
|
915
|
+
),
|
|
916
|
+
);
|
|
917
|
+
|
|
918
|
+
const panelHead = () =>
|
|
919
|
+
h(
|
|
920
|
+
'div',
|
|
921
|
+
{ className: 'owc-head' },
|
|
922
|
+
h(
|
|
923
|
+
'span',
|
|
924
|
+
{
|
|
925
|
+
className: 'owc-title',
|
|
926
|
+
tabIndex: 0,
|
|
927
|
+
title: t('drag'),
|
|
928
|
+
onKeyDown: gripKeys,
|
|
929
|
+
},
|
|
930
|
+
editing ? t(data?.configured ? 'settings' : 'setup') : t('title'),
|
|
931
|
+
),
|
|
932
|
+
editing
|
|
933
|
+
? data?.configured &&
|
|
934
|
+
h(
|
|
935
|
+
'button',
|
|
936
|
+
{
|
|
937
|
+
type: 'button',
|
|
938
|
+
className: 'owc-icon',
|
|
939
|
+
title: t('cancel'),
|
|
940
|
+
'aria-label': t('cancel'),
|
|
941
|
+
onClick: closeEditor,
|
|
942
|
+
disabled: busy,
|
|
943
|
+
},
|
|
944
|
+
iconSvg('close'),
|
|
945
|
+
)
|
|
946
|
+
: h(
|
|
947
|
+
React.Fragment,
|
|
948
|
+
null,
|
|
949
|
+
h(
|
|
950
|
+
'button',
|
|
951
|
+
{
|
|
952
|
+
type: 'button',
|
|
953
|
+
className: 'owc-icon',
|
|
954
|
+
title: t('settings'),
|
|
955
|
+
'aria-label': t('settings'),
|
|
956
|
+
onClick: openEditor,
|
|
957
|
+
disabled: busy,
|
|
958
|
+
},
|
|
959
|
+
iconSvg('sliders'),
|
|
960
|
+
),
|
|
961
|
+
h(
|
|
962
|
+
'button',
|
|
963
|
+
{
|
|
964
|
+
type: 'button',
|
|
965
|
+
className: 'owc-icon',
|
|
966
|
+
title: t('collapse'),
|
|
967
|
+
'aria-label': t('collapse'),
|
|
968
|
+
onClick: () => setPreference({ mini: true }),
|
|
969
|
+
},
|
|
970
|
+
iconSvg('chevronDown'),
|
|
971
|
+
),
|
|
972
|
+
),
|
|
973
|
+
);
|
|
974
|
+
|
|
975
|
+
const panelBody = () => {
|
|
976
|
+
if (!safeState)
|
|
977
|
+
return h(
|
|
978
|
+
'div',
|
|
979
|
+
{ className: 'owc-main' },
|
|
980
|
+
h(
|
|
981
|
+
'div',
|
|
982
|
+
{ className: 'owc-status' },
|
|
983
|
+
h('span', { className: 'owc-dot' }),
|
|
984
|
+
t('loading'),
|
|
985
|
+
),
|
|
986
|
+
!sessionId && h('p', { className: 'owc-hint' }, t('noSession')),
|
|
987
|
+
h(
|
|
988
|
+
'div',
|
|
989
|
+
{ className: 'owc-row-actions' },
|
|
990
|
+
h(
|
|
991
|
+
'button',
|
|
992
|
+
{
|
|
993
|
+
type: 'button',
|
|
994
|
+
className: 'owc-text',
|
|
995
|
+
onClick: () => reload(true),
|
|
996
|
+
disabled: busy || !sessionId,
|
|
997
|
+
},
|
|
998
|
+
iconSvg('refresh', 12),
|
|
999
|
+
t('retry'),
|
|
1000
|
+
),
|
|
1001
|
+
),
|
|
1002
|
+
);
|
|
1003
|
+
const status = safeState.status === 'done' ? '' : t(safeState.status);
|
|
1004
|
+
return h(
|
|
1005
|
+
'div',
|
|
1006
|
+
{ className: 'owc-main' },
|
|
1007
|
+
status &&
|
|
1008
|
+
h('div', { className: 'owc-status' }, h('span', { className: 'owc-dot' }), status),
|
|
1009
|
+
h('div', { className: 'owc-time', 'aria-label': status + ' ' + duration }, duration),
|
|
1010
|
+
h(
|
|
1011
|
+
'div',
|
|
1012
|
+
{
|
|
1013
|
+
className: 'owc-progress',
|
|
1014
|
+
role: 'progressbar',
|
|
1015
|
+
'aria-label': t('progress'),
|
|
1016
|
+
'aria-valuenow': Math.floor(safeState.progress * 100),
|
|
1017
|
+
'aria-valuemin': 0,
|
|
1018
|
+
'aria-valuemax': 100,
|
|
1019
|
+
},
|
|
1020
|
+
h('div', { style: { width: safeState.progress * 100 + '%' } }),
|
|
1021
|
+
),
|
|
1022
|
+
h(
|
|
1023
|
+
'div',
|
|
1024
|
+
{ className: 'owc-earn-row' },
|
|
1025
|
+
h('span', { className: 'owc-muted' }, t('earned')),
|
|
1026
|
+
salaryToggle(),
|
|
1027
|
+
),
|
|
1028
|
+
h(
|
|
1029
|
+
'div',
|
|
1030
|
+
{ className: 'owc-money', 'aria-label': view.masked ? t('masked') : moneyText },
|
|
1031
|
+
moneyText,
|
|
1032
|
+
),
|
|
1033
|
+
h(
|
|
1034
|
+
'div',
|
|
1035
|
+
{ className: 'owc-stats' },
|
|
1036
|
+
h(
|
|
1037
|
+
'div',
|
|
1038
|
+
null,
|
|
1039
|
+
h('span', null, t('daily')),
|
|
1040
|
+
h('strong', null, money(safeState.daily)),
|
|
1041
|
+
),
|
|
1042
|
+
h(
|
|
1043
|
+
'div',
|
|
1044
|
+
null,
|
|
1045
|
+
h('span', null, t('hourly')),
|
|
1046
|
+
h('strong', null, money(safeState.hourly)),
|
|
1047
|
+
),
|
|
1048
|
+
),
|
|
1049
|
+
h(
|
|
1050
|
+
'div',
|
|
1051
|
+
{ className: 'owc-meta' },
|
|
1052
|
+
h(
|
|
1053
|
+
'span',
|
|
1054
|
+
null,
|
|
1055
|
+
settings.start +
|
|
1056
|
+
' — ' +
|
|
1057
|
+
settings.end +
|
|
1058
|
+
(settings.end < settings.start ? ' +1' : '') +
|
|
1059
|
+
' · ' +
|
|
1060
|
+
(settings.breakStart === settings.breakEnd
|
|
1061
|
+
? t('noBreak')
|
|
1062
|
+
: settings.breakStart + '–' + settings.breakEnd),
|
|
1063
|
+
),
|
|
1064
|
+
h(
|
|
1065
|
+
'span',
|
|
1066
|
+
null,
|
|
1067
|
+
t('shiftDate') + ' ' + safeState.shiftDate + ' · ' + settings.timezone,
|
|
1068
|
+
),
|
|
1069
|
+
),
|
|
1070
|
+
h(
|
|
1071
|
+
'div',
|
|
1072
|
+
{ className: 'owc-row-actions' },
|
|
1073
|
+
h(
|
|
1074
|
+
'button',
|
|
1075
|
+
{
|
|
1076
|
+
type: 'button',
|
|
1077
|
+
className: 'owc-text',
|
|
1078
|
+
onClick: () => reload(true),
|
|
1079
|
+
disabled: busy,
|
|
1080
|
+
},
|
|
1081
|
+
iconSvg('refresh', 12),
|
|
1082
|
+
t('refresh'),
|
|
1083
|
+
),
|
|
1084
|
+
h(
|
|
1085
|
+
'button',
|
|
1086
|
+
{
|
|
1087
|
+
type: 'button',
|
|
1088
|
+
className: 'owc-text',
|
|
1089
|
+
onClick: () => setPreference({ position: null }),
|
|
1090
|
+
},
|
|
1091
|
+
t('reset'),
|
|
1092
|
+
),
|
|
1093
|
+
),
|
|
1094
|
+
);
|
|
1095
|
+
};
|
|
1096
|
+
|
|
1097
|
+
const editor = () => {
|
|
1098
|
+
if (!workingDraft) return null;
|
|
1099
|
+
const payDaily = workingDraft.payMode === 'daily';
|
|
1100
|
+
const salaryKey = payDaily ? 'dailySalary' : 'monthlySalary';
|
|
1101
|
+
const salaryControl = view.masked
|
|
1102
|
+
? h(
|
|
1103
|
+
'div',
|
|
1104
|
+
{ className: 'owc-private' },
|
|
1105
|
+
h('span', null, '••••'),
|
|
1106
|
+
h(
|
|
1107
|
+
'button',
|
|
1108
|
+
{
|
|
1109
|
+
type: 'button',
|
|
1110
|
+
className: 'owc-text',
|
|
1111
|
+
'aria-label': t('show'),
|
|
1112
|
+
onClick: () => setPreference({ masked: false }),
|
|
1113
|
+
},
|
|
1114
|
+
t('show'),
|
|
1115
|
+
),
|
|
1116
|
+
)
|
|
1117
|
+
: numberInput(salaryKey);
|
|
1118
|
+
const breakOn = workingDraft.breakStart !== workingDraft.breakEnd;
|
|
1119
|
+
const commonZones = [
|
|
1120
|
+
'Asia/Shanghai',
|
|
1121
|
+
'Asia/Hong_Kong',
|
|
1122
|
+
'Asia/Taipei',
|
|
1123
|
+
'Asia/Singapore',
|
|
1124
|
+
'Asia/Tokyo',
|
|
1125
|
+
'Asia/Seoul',
|
|
1126
|
+
'Asia/Kolkata',
|
|
1127
|
+
'Europe/London',
|
|
1128
|
+
'Europe/Paris',
|
|
1129
|
+
'America/New_York',
|
|
1130
|
+
'America/Los_Angeles',
|
|
1131
|
+
'Australia/Sydney',
|
|
1132
|
+
'UTC',
|
|
1133
|
+
];
|
|
1134
|
+
let allZones = [];
|
|
1135
|
+
try {
|
|
1136
|
+
allZones = Intl.supportedValuesOf('timeZone');
|
|
1137
|
+
} catch {}
|
|
1138
|
+
const zones = [
|
|
1139
|
+
...new Set([workingDraft.timezone, ...commonZones, ...allZones].filter(Boolean)),
|
|
1140
|
+
];
|
|
1141
|
+
return h(
|
|
1142
|
+
'form',
|
|
1143
|
+
{
|
|
1144
|
+
className: 'owc-form',
|
|
1145
|
+
onSubmit: save,
|
|
1146
|
+
onKeyDown: (e) => {
|
|
1147
|
+
if (e.key === 'Escape') {
|
|
1148
|
+
e.preventDefault();
|
|
1149
|
+
closeEditor();
|
|
1150
|
+
}
|
|
1151
|
+
},
|
|
1152
|
+
},
|
|
1153
|
+
!data?.configured && h('p', { className: 'owc-hint' }, t('setupHint')),
|
|
1154
|
+
h(
|
|
1155
|
+
'fieldset',
|
|
1156
|
+
{ className: 'owc-setting-group' },
|
|
1157
|
+
h('legend', null, t('salaryGroup')),
|
|
1158
|
+
label(
|
|
1159
|
+
t('payMode'),
|
|
1160
|
+
h(
|
|
1161
|
+
'div',
|
|
1162
|
+
{ className: 'owc-seg' },
|
|
1163
|
+
h(
|
|
1164
|
+
'button',
|
|
1165
|
+
{
|
|
1166
|
+
type: 'button',
|
|
1167
|
+
disabled: busy,
|
|
1168
|
+
'aria-pressed': !payDaily,
|
|
1169
|
+
'aria-label': t('monthly'),
|
|
1170
|
+
onClick: () => update('payMode', 'monthly'),
|
|
1171
|
+
},
|
|
1172
|
+
t('monthly'),
|
|
1173
|
+
),
|
|
1174
|
+
h(
|
|
1175
|
+
'button',
|
|
1176
|
+
{
|
|
1177
|
+
type: 'button',
|
|
1178
|
+
disabled: busy,
|
|
1179
|
+
'aria-pressed': payDaily,
|
|
1180
|
+
'aria-label': t('dailyMode'),
|
|
1181
|
+
onClick: () => update('payMode', 'daily'),
|
|
1182
|
+
},
|
|
1183
|
+
t('dailyMode'),
|
|
1184
|
+
),
|
|
1185
|
+
),
|
|
1186
|
+
),
|
|
1187
|
+
h(
|
|
1188
|
+
'div',
|
|
1189
|
+
{ className: 'owc-row2' },
|
|
1190
|
+
label(t(salaryKey), salaryControl),
|
|
1191
|
+
!payDaily && label(t('workdaysPerMonth'), numberInput('workdaysPerMonth')),
|
|
1192
|
+
),
|
|
1193
|
+
),
|
|
1194
|
+
h(
|
|
1195
|
+
'fieldset',
|
|
1196
|
+
{ className: 'owc-setting-group' },
|
|
1197
|
+
h('legend', null, t('scheduleGroup')),
|
|
1198
|
+
h(
|
|
1199
|
+
'div',
|
|
1200
|
+
{ className: 'owc-row2' },
|
|
1201
|
+
label(t('start'), timeInput('start')),
|
|
1202
|
+
label(t('end'), timeInput('end')),
|
|
1203
|
+
),
|
|
1204
|
+
workingDraft.end < workingDraft.start &&
|
|
1205
|
+
h('p', { className: 'owc-hint' }, t('end') + ' · ' + t('nextDay')),
|
|
1206
|
+
h(
|
|
1207
|
+
'label',
|
|
1208
|
+
{ className: 'owc-check' },
|
|
1209
|
+
h('input', {
|
|
1210
|
+
type: 'checkbox',
|
|
1211
|
+
checked: breakOn,
|
|
1212
|
+
disabled: busy,
|
|
1213
|
+
onChange: toggleBreak,
|
|
1214
|
+
}),
|
|
1215
|
+
t('breakEnabled'),
|
|
1216
|
+
),
|
|
1217
|
+
breakOn &&
|
|
1218
|
+
h(
|
|
1219
|
+
'div',
|
|
1220
|
+
{ className: 'owc-row2' },
|
|
1221
|
+
label(t('breakStart'), timeInput('breakStart')),
|
|
1222
|
+
label(t('breakEnd'), timeInput('breakEnd')),
|
|
1223
|
+
),
|
|
1224
|
+
label(
|
|
1225
|
+
t('weekdays'),
|
|
1226
|
+
h(
|
|
1227
|
+
'div',
|
|
1228
|
+
{ className: 'owc-days' },
|
|
1229
|
+
[0, 1, 2, 3, 4, 5, 6].map((day) =>
|
|
1230
|
+
h(
|
|
1231
|
+
'button',
|
|
1232
|
+
{
|
|
1233
|
+
key: day,
|
|
1234
|
+
type: 'button',
|
|
1235
|
+
disabled: busy,
|
|
1236
|
+
'aria-pressed': workingDraft.weekdays.includes(day),
|
|
1237
|
+
'aria-label': t('weekdays') + ' ' + t('days')[day],
|
|
1238
|
+
onClick: () =>
|
|
1239
|
+
update(
|
|
1240
|
+
'weekdays',
|
|
1241
|
+
workingDraft.weekdays.includes(day)
|
|
1242
|
+
? workingDraft.weekdays.filter((d) => d !== day)
|
|
1243
|
+
: [...workingDraft.weekdays, day].sort((a, b) => a - b),
|
|
1244
|
+
),
|
|
1245
|
+
},
|
|
1246
|
+
t('days')[day],
|
|
1247
|
+
),
|
|
1248
|
+
),
|
|
1249
|
+
),
|
|
1250
|
+
),
|
|
1251
|
+
label(
|
|
1252
|
+
t('timezone'),
|
|
1253
|
+
h(
|
|
1254
|
+
'select',
|
|
1255
|
+
{
|
|
1256
|
+
name: 'timezone',
|
|
1257
|
+
value: workingDraft.timezone ?? '',
|
|
1258
|
+
disabled: busy,
|
|
1259
|
+
onChange: (e) => update('timezone', e.target.value),
|
|
1260
|
+
},
|
|
1261
|
+
zones.map((zone) => h('option', { key: zone, value: zone }, zone)),
|
|
1262
|
+
),
|
|
1263
|
+
),
|
|
1264
|
+
),
|
|
1265
|
+
h(
|
|
1266
|
+
'fieldset',
|
|
1267
|
+
{ className: 'owc-setting-group' },
|
|
1268
|
+
h('legend', null, t('appearanceGroup')),
|
|
1269
|
+
label(
|
|
1270
|
+
t('opacity'),
|
|
1271
|
+
h(
|
|
1272
|
+
React.Fragment,
|
|
1273
|
+
null,
|
|
1274
|
+
h('input', {
|
|
1275
|
+
className: 'owc-range',
|
|
1276
|
+
type: 'range',
|
|
1277
|
+
min: '30',
|
|
1278
|
+
max: '100',
|
|
1279
|
+
step: '1',
|
|
1280
|
+
value: String(Math.round(view.opacity * 100)),
|
|
1281
|
+
disabled: busy,
|
|
1282
|
+
'aria-label': t('opacity'),
|
|
1283
|
+
onChange: (e) => setPreference({ opacity: e.target.valueAsNumber / 100 }),
|
|
1284
|
+
}),
|
|
1285
|
+
h(
|
|
1286
|
+
'span',
|
|
1287
|
+
{ className: 'owc-hint', style: { margin: 0 } },
|
|
1288
|
+
Math.round(view.opacity * 100) + '% · ' + t('opacityHint'),
|
|
1289
|
+
),
|
|
1290
|
+
),
|
|
1291
|
+
),
|
|
1292
|
+
),
|
|
1293
|
+
preview &&
|
|
1294
|
+
!preview.error &&
|
|
1295
|
+
h(
|
|
1296
|
+
'div',
|
|
1297
|
+
{ className: 'owc-preview' },
|
|
1298
|
+
t('preview') +
|
|
1299
|
+
' · ' +
|
|
1300
|
+
t('daily') +
|
|
1301
|
+
' ' +
|
|
1302
|
+
money(preview.daily) +
|
|
1303
|
+
' · ' +
|
|
1304
|
+
t('hourly') +
|
|
1305
|
+
' ' +
|
|
1306
|
+
money(preview.hourly),
|
|
1307
|
+
),
|
|
1308
|
+
preview?.error &&
|
|
1309
|
+
h(
|
|
1310
|
+
'p',
|
|
1311
|
+
{ className: 'owc-error', role: 'alert', style: { padding: 0 } },
|
|
1312
|
+
preview.error,
|
|
1313
|
+
),
|
|
1314
|
+
h(
|
|
1315
|
+
'details',
|
|
1316
|
+
{ className: 'owc-advanced' },
|
|
1317
|
+
h('summary', null, t('advanced')),
|
|
1318
|
+
h('p', { className: 'owc-hint' }, t('sessionHint')),
|
|
1319
|
+
label(t('session'), sessionSelect()),
|
|
1320
|
+
),
|
|
1321
|
+
h('p', { className: 'owc-hint' }, t('privacy')),
|
|
1322
|
+
h(
|
|
1323
|
+
'div',
|
|
1324
|
+
{ className: 'owc-save' },
|
|
1325
|
+
data?.configured &&
|
|
1326
|
+
h(
|
|
1327
|
+
'button',
|
|
1328
|
+
{ type: 'button', className: 'owc-text', onClick: closeEditor, disabled: busy },
|
|
1329
|
+
t('cancel'),
|
|
1330
|
+
),
|
|
1331
|
+
h(
|
|
1332
|
+
'button',
|
|
1333
|
+
{ type: 'submit', className: 'owc-primary', disabled: busy || !!preview?.error },
|
|
1334
|
+
t(busy ? 'busy' : 'save'),
|
|
1335
|
+
),
|
|
1336
|
+
),
|
|
1337
|
+
);
|
|
1338
|
+
};
|
|
1339
|
+
|
|
1340
|
+
const notices = () =>
|
|
1341
|
+
h(
|
|
1342
|
+
React.Fragment,
|
|
1343
|
+
null,
|
|
1344
|
+
error && h('p', { className: 'owc-error', role: 'alert' }, error),
|
|
1345
|
+
state?.error && h('p', { className: 'owc-error', role: 'alert' }, state.error),
|
|
1346
|
+
notice && h('p', { className: 'owc-note', role: 'status' }, notice),
|
|
1347
|
+
storageError && h('p', { className: 'owc-note' }, t('storage')),
|
|
1348
|
+
);
|
|
1349
|
+
|
|
1350
|
+
return h(
|
|
1351
|
+
'section',
|
|
1352
|
+
{
|
|
1353
|
+
ref: box,
|
|
1354
|
+
className:
|
|
1355
|
+
'owc-v2' + (collapsed ? ' owc-compact' : '') + (editing ? ' owc-editing' : ''),
|
|
1356
|
+
'aria-label': t('title'),
|
|
1357
|
+
'data-version': '1.0.1',
|
|
1358
|
+
'data-status': safeState?.status || 'setup',
|
|
1359
|
+
style: cardStyle,
|
|
1360
|
+
onPointerDown: dragDown,
|
|
1361
|
+
onPointerMove: dragMove,
|
|
1362
|
+
onPointerUp: dragEnd,
|
|
1363
|
+
onPointerCancel: dragEnd,
|
|
1364
|
+
onLostPointerCapture: dragEnd,
|
|
1365
|
+
},
|
|
1366
|
+
h('style', null, STYLE),
|
|
1367
|
+
h('div', { className: 'owc-glass', 'aria-hidden': 'true' }),
|
|
1368
|
+
h(
|
|
1369
|
+
'div',
|
|
1370
|
+
{ className: 'owc-content' },
|
|
1371
|
+
collapsed
|
|
1372
|
+
? strip()
|
|
1373
|
+
: h(React.Fragment, null, panelHead(), editing ? editor() : panelBody(), notices()),
|
|
1374
|
+
),
|
|
1375
|
+
);
|
|
1376
|
+
}
|
|
1377
|
+
|
|
1378
|
+
ctx.slots.inject('shell.overlay', () =>
|
|
1379
|
+
ctx.slots.register(
|
|
1380
|
+
{
|
|
1381
|
+
name: 'shell.overlay',
|
|
1382
|
+
id: 'offwork-clock',
|
|
1383
|
+
order: 900,
|
|
1384
|
+
label: () => ctx.locale.bind('offwork-clock')('title'),
|
|
1385
|
+
},
|
|
1386
|
+
Clock,
|
|
1387
|
+
),
|
|
1388
|
+
);
|
|
1389
|
+
},
|
|
1390
|
+
};
|
|
1391
|
+
},
|
|
1392
|
+
});
|