dsh-offwork 0.0.0-stage → 1.0.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/README.md +210 -2
- package/client.js +690 -0
- package/client.source.js +534 -0
- package/clock.js +103 -0
- package/cordis.patch.yml +4 -0
- package/icon.svg +1 -0
- package/index.js +198 -0
- package/locale/en.json +1 -0
- package/locale/zh.json +1 -0
- package/package.json +60 -4
- package/tests/clock.test.mjs +193 -0
- package/tests/host.test.mjs +172 -0
- package/tests/ui.test.mjs +75 -0
- package/tools/build.mjs +13 -0
- package/ui-utils.js +51 -0
package/client.source.js
ADDED
|
@@ -0,0 +1,534 @@
|
|
|
1
|
+
// Authored Client entry. Run node tools/build.mjs to inline the tested pure modules.
|
|
2
|
+
window.__ModuleLoader__.load({
|
|
3
|
+
id: 'dsh-offwork',
|
|
4
|
+
factory(require) {
|
|
5
|
+
const React = require('react');
|
|
6
|
+
const h = React.createElement;
|
|
7
|
+
/* PURE_MODULES */
|
|
8
|
+
const messages = {
|
|
9
|
+
zh: {
|
|
10
|
+
title:'下班计时器', working:'距离下班', before:'距离开工', lunch:'午休中', done:'本班已完成', rest:'今天休息',
|
|
11
|
+
earned:'本班已赚 · 税前', daily:'日薪', hourly:'有效时薪', progress:'计薪进度',
|
|
12
|
+
settings:'设置', collapse:'收起为小条', expand:'展开', hide:'隐藏工资', show:'显示工资',
|
|
13
|
+
save:'保存', cancel:'取消', monthlySalary:'税前月薪(元)', dailySalary:'税前日薪(元)',
|
|
14
|
+
workdaysPerMonth:'月计薪天数', start:'上班时间', end:'下班时间', breakStart:'休息开始', breakEnd:'休息结束',
|
|
15
|
+
timezone:'时区', weekdays:'班次开始日', payMode:'计薪方式', monthly:'月薪', dailyMode:'日薪',
|
|
16
|
+
loading:'正在读取设置…', retry:'重新读取', noSession:'请先打开或创建一个会话。', error:'操作失败,请重试。',
|
|
17
|
+
saved:'设置已保存', days:'日一二三四五六', privacy:'配置存本机;读写结果进入所选会话记录。',
|
|
18
|
+
drag:'按住可拖动;方向键微调,Home 复位', setup:'先设好你的作息', setupHint:'示例数值不是你的收入,保存后才开始计时。',
|
|
19
|
+
breakEnabled:'扣除无薪休息', noBreak:'不扣休息', nextDay:'次日', preview:'折算',
|
|
20
|
+
salaryGroup:'薪资', scheduleGroup:'作息', appearanceGroup:'外观', advanced:'高级设置', sessionHint:'仅用于记录配置读写操作,不是账本,不影响工资计算。', session:'操作记录会话', masked:'工资已隐藏', reset:'复位位置', synced:'已读取最新配置',
|
|
21
|
+
refresh:'读取最新配置', busy:'保存中…', storage:'浏览器禁止本地存储;位置与透明度本次有效。',
|
|
22
|
+
shiftDate:'班次', opacity:'背景透明度', opacityHint:'只影响背景,不影响文字。',
|
|
23
|
+
},
|
|
24
|
+
en: {
|
|
25
|
+
title:'Offwork Clock', working:'Until clock-out', before:'Until work starts', lunch:'On break', done:'Shift complete', rest:'Day off',
|
|
26
|
+
earned:'Earned this shift · gross', daily:'Shift pay', hourly:'Paid-hour rate', progress:'Paid progress',
|
|
27
|
+
settings:'Settings', collapse:'Minimize to strip', expand:'Expand', hide:'Hide salary', show:'Show salary',
|
|
28
|
+
save:'Save', cancel:'Cancel', monthlySalary:'Monthly gross (CNY)', dailySalary:'Daily gross (CNY)',
|
|
29
|
+
workdaysPerMonth:'Paid days / month', start:'Shift starts', end:'Shift ends', breakStart:'Break starts', breakEnd:'Break ends',
|
|
30
|
+
timezone:'Time zone', weekdays:'Shift starting days', payMode:'Pay basis', monthly:'Monthly', dailyMode:'Daily',
|
|
31
|
+
loading:'Loading settings…', retry:'Reload', noSession:'Open or create a session first.', error:'Operation failed. Please retry.',
|
|
32
|
+
saved:'Settings saved', days:'SMTWTFS', privacy:'Settings stay local; results enter the selected session log.',
|
|
33
|
+
drag:'Drag to move; arrow keys to adjust; Home resets', setup:'Set up your schedule', setupHint:'These are example values, not your income. Save to start.',
|
|
34
|
+
breakEnabled:'Deduct unpaid break', noBreak:'no break', nextDay:'next day', preview:'Preview',
|
|
35
|
+
salaryGroup:'Salary', scheduleGroup:'Schedule', appearanceGroup:'Appearance', advanced:'Advanced', sessionHint:'Logs configuration operations only; not a ledger and does not affect pay calculations.', session:'Action log session', masked:'Salary hidden', reset:'Reset position', synced:'Latest settings loaded',
|
|
36
|
+
refresh:'Reload latest settings', busy:'Saving…', storage:'Local storage is blocked; position and opacity last only for this visit.',
|
|
37
|
+
shiftDate:'Shift', opacity:'Surface opacity', opacityHint:'Affects the background only.',
|
|
38
|
+
},
|
|
39
|
+
};
|
|
40
|
+
const STYLE = `
|
|
41
|
+
.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}
|
|
42
|
+
.owc-v2:active{cursor:grabbing}
|
|
43
|
+
.owc-v2.owc-compact{touch-action:none;border-radius:18px}
|
|
44
|
+
.owc-v2:not(.owc-compact){width:296px}
|
|
45
|
+
.owc-v2 :is(button,input,select,label,a){cursor:pointer;user-select:auto;-webkit-user-select:auto}
|
|
46
|
+
.owc-v2 :is(input,select){user-select:text;-webkit-user-select:text}
|
|
47
|
+
.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}
|
|
48
|
+
.owc-content{position:relative;border-radius:inherit;max-height:calc(100dvh - 24px);overflow:auto;overscroll-behavior:contain;scrollbar-width:thin}
|
|
49
|
+
.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}
|
|
50
|
+
.owc-v2 button:hover{background:color-mix(in srgb,var(--dsw-alias-label-primary) 7%,transparent)}
|
|
51
|
+
.owc-v2 button:focus-visible,.owc-v2 :is(input,select):focus-visible{outline:2px solid var(--dsw-alias-brand-primary);outline-offset:1px}
|
|
52
|
+
.owc-v2 button:disabled{opacity:.45;cursor:not-allowed;background:transparent}
|
|
53
|
+
.owc-icon{color:var(--dsw-alias-label-secondary);min-width:28px}
|
|
54
|
+
.owc-text{font-size:11px;color:var(--dsw-alias-label-secondary);padding:4px 6px;min-height:24px;white-space:nowrap}
|
|
55
|
+
.owc-text:hover{color:var(--dsw-alias-label-primary)}
|
|
56
|
+
.owc-pill{display:flex;flex-direction:column;gap:8px;padding:12px 10px 9px 14px;min-width:168px}
|
|
57
|
+
.owc-pill-top>svg{color:var(--owc-accent);flex:none}
|
|
58
|
+
.owc-pill-top>.owc-icon{color:var(--dsw-alias-label-secondary)}
|
|
59
|
+
.owc-pill-top{display:flex;align-items:center;gap:7px;min-width:0}
|
|
60
|
+
.owc-grip{display:flex;align-items:baseline;gap:7px;touch-action:none;min-width:0}
|
|
61
|
+
.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)}
|
|
62
|
+
.owc-pill-actions{display:flex;align-items:center;gap:2px}
|
|
63
|
+
.owc-pill-status{font-size:10px;color:var(--dsw-alias-label-secondary);white-space:nowrap;letter-spacing:.02em}
|
|
64
|
+
.owc-pill-time{font-size:24px;font-weight:500;letter-spacing:-.5px;font-variant-numeric:tabular-nums;white-space:nowrap;line-height:1.25}
|
|
65
|
+
.owc-pill-money{font-size:13px;color:var(--dsw-alias-label-secondary);font-variant-numeric:tabular-nums;white-space:nowrap;min-width:46px}
|
|
66
|
+
.owc-dot{width:6px;height:6px;border-radius:50%;background:var(--dsw-alias-state-idle-primary);flex:none}
|
|
67
|
+
.owc-v2[data-status=working] .owc-dot{background:var(--dsw-alias-state-success-primary)}
|
|
68
|
+
.owc-v2[data-status=lunch] .owc-dot{background:var(--dsw-alias-state-warn-primary)}
|
|
69
|
+
.owc-v2[data-status=done] .owc-dot{background:var(--dsw-alias-brand-primary)}
|
|
70
|
+
.owc-v2[data-status=before] .owc-dot,.owc-v2[data-status=rest] .owc-dot{opacity:.6}
|
|
71
|
+
.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)}
|
|
72
|
+
.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}
|
|
73
|
+
.owc-main{padding:4px 17px 12px}
|
|
74
|
+
.owc-status{display:flex;align-items:center;gap:7px;font-size:11px;color:var(--dsw-alias-label-secondary);margin-bottom:1px}
|
|
75
|
+
.owc-time{font-size:34px;font-weight:350;line-height:1.28;letter-spacing:-1.2px;font-variant-numeric:tabular-nums}
|
|
76
|
+
.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}
|
|
77
|
+
.owc-progress>div{height:100%;border-radius:3px;background:var(--owc-accent);transition:width .6s linear}
|
|
78
|
+
.owc-earn-row{display:flex;align-items:center;justify-content:space-between;gap:8px}
|
|
79
|
+
.owc-money{font-size:26px;font-weight:400;letter-spacing:-.6px;font-variant-numeric:tabular-nums;margin-top:1px}
|
|
80
|
+
.owc-muted{font-size:10.5px;color:var(--dsw-alias-label-secondary)}
|
|
81
|
+
.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)}
|
|
82
|
+
.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)}
|
|
83
|
+
.owc-stats span{display:block;font-size:10px;color:var(--dsw-alias-label-secondary)}
|
|
84
|
+
.owc-stats strong{display:block;margin-top:1px;font-size:13px;font-weight:500;font-variant-numeric:tabular-nums}
|
|
85
|
+
.owc-meta{margin-top:12px}
|
|
86
|
+
.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}
|
|
87
|
+
.owc-row-actions{display:flex;gap:4px;margin-top:8px;margin-left:-6px}
|
|
88
|
+
.owc-form{padding:2px 17px 15px}
|
|
89
|
+
.owc-v2.owc-editing{width:340px}
|
|
90
|
+
.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)}
|
|
91
|
+
.owc-setting-group legend{padding:0 6px;font-size:12px;font-weight:600;color:var(--dsw-alias-label-primary)}
|
|
92
|
+
.owc-form :is(input[type=time],input[type=number],select){min-height:36px;border-radius:10px}
|
|
93
|
+
.owc-advanced{margin:0 0 12px;padding:10px 12px;border-radius:12px;background:color-mix(in srgb,var(--dsw-alias-label-secondary) 5%,transparent)}
|
|
94
|
+
.owc-advanced summary{cursor:pointer;font-size:12px;font-weight:500}
|
|
95
|
+
.owc-advanced[open] summary{margin-bottom:10px}
|
|
96
|
+
.owc-grip:focus-visible,.owc-advanced summary:focus-visible{outline:2px solid var(--owc-accent);outline-offset:3px}
|
|
97
|
+
.owc-field{display:block;margin-bottom:10px}
|
|
98
|
+
.owc-field>span{display:block;font-size:10.5px;color:var(--dsw-alias-label-secondary);margin-bottom:4px}
|
|
99
|
+
.owc-row2{display:grid;grid-template-columns:1fr 1fr;gap:10px}
|
|
100
|
+
.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}
|
|
101
|
+
.owc-v2 select option{background:var(--dsw-alias-bg-overlay);color:var(--dsw-alias-label-primary)}
|
|
102
|
+
.owc-seg{display:flex;gap:3px;padding:3px;border-radius:11px;background:color-mix(in srgb,var(--dsw-alias-label-primary) 6%,transparent)}
|
|
103
|
+
.owc-seg button{flex:1;font-size:11.5px;min-height:26px;border-radius:8px}
|
|
104
|
+
.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)}
|
|
105
|
+
.owc-days{display:flex;gap:3px}
|
|
106
|
+
.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)}
|
|
107
|
+
.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)}
|
|
108
|
+
.owc-check{display:flex;flex-direction:row;align-items:center;gap:7px;font-size:11.5px;margin:0 0 10px}
|
|
109
|
+
.owc-check input{appearance:auto;-webkit-appearance:auto;width:auto;accent-color:var(--dsw-alias-brand-primary)}
|
|
110
|
+
.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)}
|
|
111
|
+
.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}
|
|
112
|
+
.owc-hint{font-size:10.5px;line-height:1.6;color:var(--dsw-alias-label-secondary);margin:0 0 10px}
|
|
113
|
+
.owc-range{width:100%;accent-color:var(--dsw-alias-brand-primary);margin:1px 0 2px}
|
|
114
|
+
.owc-save{display:flex;align-items:center;justify-content:flex-end;gap:6px;margin-top:12px}
|
|
115
|
+
.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}
|
|
116
|
+
.owc-v2 button.owc-primary:hover{background:color-mix(in srgb,var(--owc-accent) 88%,#000)}
|
|
117
|
+
.owc-v2 button.owc-primary:disabled{opacity:.5;color:#fff;background:var(--owc-accent)}
|
|
118
|
+
.owc-error,.owc-note{padding:0 17px 9px;margin:0;font-size:10.5px;line-height:1.6}
|
|
119
|
+
.owc-error{color:var(--dsw-alias-state-error-primary)}
|
|
120
|
+
.owc-note{color:var(--dsw-alias-label-secondary)}
|
|
121
|
+
@supports not ((backdrop-filter:blur(1px)) or (-webkit-backdrop-filter:blur(1px))){.owc-glass{opacity:1}}
|
|
122
|
+
@media(prefers-reduced-transparency:reduce),(prefers-contrast:more){.owc-glass{opacity:1;-webkit-backdrop-filter:none;backdrop-filter:none}}
|
|
123
|
+
@media(prefers-reduced-motion:reduce){.owc-v2 button,.owc-glass,.owc-progress>div{transition:none}}
|
|
124
|
+
@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}}
|
|
125
|
+
`;
|
|
126
|
+
const ICONS = {
|
|
127
|
+
eye: [['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'}], ['circle', {cx:8, cy:8, r:2.05}]],
|
|
128
|
+
eyeOff: [['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'}], ['circle', {cx:8, cy:8, r:2.05}], ['path', {d:'M3 3l10 10'}]],
|
|
129
|
+
sliders: [['path', {d:'M2.2 4.6h3.4M9.2 4.6h4.6M2.2 11.4h5.4M11.4 11.4h2.4'}], ['circle', {cx:7.3, cy:4.6, r:1.55}], ['circle', {cx:9.4, cy:11.4, r:1.55}]],
|
|
130
|
+
alarm: [['circle', {cx:8, cy:9, r:4.5}], ['path', {d:'M8 6.5V9l1.7 1M2 4l2-2M12 2l2 2M5 13l-1 2M11 13l1 2'}]],
|
|
131
|
+
chevronUp: [['path', {d:'M3.7 9.8L8 5.5l4.3 4.3'}]],
|
|
132
|
+
chevronDown: [['path', {d:'M3.7 6.2L8 10.5l4.3-4.3'}]],
|
|
133
|
+
close: [['path', {d:'M4.3 4.3l7.4 7.4M11.7 4.3l-7.4 7.4'}]],
|
|
134
|
+
refresh: [['path', {d:'M13.1 8a5.1 5.1 0 1 1-1.5-3.6'}], ['path', {d:'M13.1 3v3.2H9.9'}]],
|
|
135
|
+
};
|
|
136
|
+
const iconSvg = (name, size = 15) => h('svg', {
|
|
137
|
+
width: size, height: size, viewBox: '0 0 16 16', fill: 'none', stroke: 'currentColor',
|
|
138
|
+
strokeWidth: 1.55, strokeLinecap: 'round', strokeLinejoin: 'round', 'aria-hidden': 'true', focusable: 'false',
|
|
139
|
+
}, ICONS[name].map(([tag, attrs], index) => h(tag, {key: index, ...attrs})));
|
|
140
|
+
|
|
141
|
+
return {
|
|
142
|
+
inject: ['slots', 'locale', 'remote', 'remote.commands'],
|
|
143
|
+
apply(ctx) {
|
|
144
|
+
for (const [lang, dict] of Object.entries(messages)) ctx.effect(() => ctx.locale.register('offwork-clock', lang, dict));
|
|
145
|
+
const viewKey = 'dsh.offwork-clock.view.v4';
|
|
146
|
+
const legacyKey = 'dsh.offwork-clock.view.v3';
|
|
147
|
+
|
|
148
|
+
function Clock(props) {
|
|
149
|
+
const locale = React.useSyncExternalStore(fn => ctx.locale.subscribe(fn), () => ctx.locale.getSnapshot());
|
|
150
|
+
const t = ctx.locale.bind('offwork-clock');
|
|
151
|
+
const sessions = props.useSessions(s => s);
|
|
152
|
+
const sessionIds = Array.isArray(sessions?.ids) ? sessions.ids : [];
|
|
153
|
+
const [sessionChoice, setSessionChoice] = React.useState('');
|
|
154
|
+
const sessionId = sessionIds.includes(sessionChoice) ? sessionChoice : sessionIds[0];
|
|
155
|
+
const [data, setData] = React.useState(null);
|
|
156
|
+
const [draft, setDraft] = React.useState(null);
|
|
157
|
+
const [editing, setEditing] = React.useState(false);
|
|
158
|
+
const [busy, setBusy] = React.useState(false);
|
|
159
|
+
const [error, setError] = React.useState('');
|
|
160
|
+
const [notice, setNotice] = React.useState('');
|
|
161
|
+
const [storageError, setStorageError] = React.useState(false);
|
|
162
|
+
const [now, setNow] = React.useState(Date.now());
|
|
163
|
+
const [view, setView] = React.useState(normalizeView(null));
|
|
164
|
+
const [ready, setReady] = React.useState(false);
|
|
165
|
+
const box = React.useRef(null);
|
|
166
|
+
const dragState = React.useRef(null);
|
|
167
|
+
const lastPosition = React.useRef(null);
|
|
168
|
+
const generation = React.useRef(0);
|
|
169
|
+
const requestBusy = React.useRef(false);
|
|
170
|
+
const focusReturn = React.useRef(null);
|
|
171
|
+
|
|
172
|
+
const settings = data?.settings;
|
|
173
|
+
const workingDraft = draft || settings;
|
|
174
|
+
const state = settings ? safeCalculate(settings) : null;
|
|
175
|
+
const preview = workingDraft ? safeCalculate(workingDraft) : null;
|
|
176
|
+
const safeState = state && !state.error ? state : null;
|
|
177
|
+
const collapsed = !!safeState && !editing && view.mini && !error && !state?.error;
|
|
178
|
+
const seconds = safeState ? (safeState.status === 'before' ? safeState.startRemaining : safeState.remaining) : NaN;
|
|
179
|
+
const duration = formatDuration(seconds);
|
|
180
|
+
const formatMoney = React.useMemo(() => new Intl.NumberFormat(locale.active, {
|
|
181
|
+
style: 'currency', currency: 'CNY', minimumFractionDigits: 2, maximumFractionDigits: 2,
|
|
182
|
+
}), [locale.active]);
|
|
183
|
+
const money = value => view.masked ? '••••' : formatMoney.format(value);
|
|
184
|
+
const moneyText = safeState ? money(safeState.earned) : '—';
|
|
185
|
+
const cardStyle = Object.assign({ '--owc-alpha': String(view.opacity) },
|
|
186
|
+
view.position ? { left: view.position.x, top: view.position.y, right: 'auto' } : {});
|
|
187
|
+
|
|
188
|
+
function safeCalculate(value) {
|
|
189
|
+
try { return calculate(value, now); }
|
|
190
|
+
catch (e) { return { error: e instanceof Error ? e.message : t('error') }; }
|
|
191
|
+
}
|
|
192
|
+
function errorText(e) { return e instanceof Error ? e.message : t('error'); }
|
|
193
|
+
function setPreference(patch) { setView(current => ({ ...current, ...patch })); }
|
|
194
|
+
|
|
195
|
+
const clamp = React.useCallback(position => clampPosition(position,
|
|
196
|
+
{ width: window.innerWidth, height: window.innerHeight },
|
|
197
|
+
{ width: box.current?.offsetWidth || 300, height: box.current?.offsetHeight || 200 }), []);
|
|
198
|
+
|
|
199
|
+
React.useEffect(() => {
|
|
200
|
+
try {
|
|
201
|
+
const saved = localStorage.getItem(viewKey);
|
|
202
|
+
const legacy = !saved ? JSON.parse(localStorage.getItem(legacyKey) || 'null') : null;
|
|
203
|
+
setView(normalizeView(saved ? JSON.parse(saved) : { position: legacy?.position ?? null, masked: legacy?.masked ?? true }));
|
|
204
|
+
} catch { setStorageError(true); }
|
|
205
|
+
setReady(true);
|
|
206
|
+
const sync = e => {
|
|
207
|
+
if (e.key !== viewKey) return;
|
|
208
|
+
try { setView(normalizeView(JSON.parse(e.newValue || 'null'))); } catch {}
|
|
209
|
+
};
|
|
210
|
+
window.addEventListener('storage', sync);
|
|
211
|
+
return () => window.removeEventListener('storage', sync);
|
|
212
|
+
}, []);
|
|
213
|
+
|
|
214
|
+
React.useEffect(() => {
|
|
215
|
+
if (!ready) return;
|
|
216
|
+
try { localStorage.setItem(viewKey, JSON.stringify(normalizeView(view))); }
|
|
217
|
+
catch { setStorageError(true); }
|
|
218
|
+
}, [ready, view]);
|
|
219
|
+
|
|
220
|
+
React.useEffect(() => {
|
|
221
|
+
if (sessionId) reload();
|
|
222
|
+
else setError(t('noSession'));
|
|
223
|
+
return () => { generation.current++; };
|
|
224
|
+
}, [sessionId]);
|
|
225
|
+
|
|
226
|
+
React.useEffect(() => {
|
|
227
|
+
let timer;
|
|
228
|
+
const tick = () => { setNow(Date.now()); timer = setTimeout(tick, 1000 - Date.now() % 1000); };
|
|
229
|
+
const visibility = () => { clearTimeout(timer); setNow(Date.now()); if (!document.hidden) tick(); };
|
|
230
|
+
if (!document.hidden) tick();
|
|
231
|
+
document.addEventListener('visibilitychange', visibility);
|
|
232
|
+
return () => { clearTimeout(timer); document.removeEventListener('visibilitychange', visibility); };
|
|
233
|
+
}, []);
|
|
234
|
+
|
|
235
|
+
React.useEffect(() => {
|
|
236
|
+
const resize = () => setView(current => current.position ? { ...current, position: clamp(current.position) } : current);
|
|
237
|
+
const ro = typeof ResizeObserver === 'function' ? new ResizeObserver(resize) : null;
|
|
238
|
+
if (box.current) ro?.observe(box.current);
|
|
239
|
+
window.addEventListener('resize', resize);
|
|
240
|
+
return () => { ro?.disconnect(); window.removeEventListener('resize', resize); };
|
|
241
|
+
}, [clamp]);
|
|
242
|
+
|
|
243
|
+
React.useEffect(() => {
|
|
244
|
+
if (!editing) { focusReturn.current?.focus?.(); return; }
|
|
245
|
+
box.current?.querySelector('form input,form select')?.focus?.();
|
|
246
|
+
}, [editing]);
|
|
247
|
+
|
|
248
|
+
React.useEffect(() => () => { generation.current++; dragState.current = null; }, []);
|
|
249
|
+
|
|
250
|
+
async function request(action, patch) {
|
|
251
|
+
if (!sessionId) throw new Error(t('noSession'));
|
|
252
|
+
const rpc = await ctx.remote.commands.execute(sessionId, '/offwork-clock ' + action + (patch ? ' ' + JSON.stringify(patch) : ''), []);
|
|
253
|
+
return decodeCommand(rpc);
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
async function reload(explicit = false) {
|
|
257
|
+
if (requestBusy.current) return;
|
|
258
|
+
const token = ++generation.current;
|
|
259
|
+
setBusy(true); setError('');
|
|
260
|
+
try {
|
|
261
|
+
const next = await request('get');
|
|
262
|
+
if (token !== generation.current) return;
|
|
263
|
+
setData(next);
|
|
264
|
+
if (!next.configured) { setDraft({ ...next.settings }); setEditing(true); }
|
|
265
|
+
if (explicit) setNotice(t('synced'));
|
|
266
|
+
} catch (e) { if (token === generation.current) setError(errorText(e)); }
|
|
267
|
+
finally { if (token === generation.current) setBusy(false); }
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
async function save(event) {
|
|
271
|
+
event.preventDefault();
|
|
272
|
+
if (requestBusy.current) return;
|
|
273
|
+
requestBusy.current = true; setBusy(true); setError('');
|
|
274
|
+
const token = ++generation.current;
|
|
275
|
+
try {
|
|
276
|
+
const next = await request('set', changedSettings(settings, draft));
|
|
277
|
+
if (token === generation.current) {
|
|
278
|
+
setData(next); setEditing(false); setDraft(null); setNotice(t('saved'));
|
|
279
|
+
}
|
|
280
|
+
} catch (e) { if (token === generation.current) setError(errorText(e)); }
|
|
281
|
+
finally { requestBusy.current = false; if (token === generation.current) setBusy(false); }
|
|
282
|
+
}
|
|
283
|
+
|
|
284
|
+
function commitPosition(position) {
|
|
285
|
+
const next = clamp(position);
|
|
286
|
+
setPreference({ position: next });
|
|
287
|
+
lastPosition.current = next;
|
|
288
|
+
}
|
|
289
|
+
function dragDown(e) {
|
|
290
|
+
if (e.button !== 0) return;
|
|
291
|
+
if (e.target.closest?.('button,input,select,label,a,textarea,summary,[contenteditable]')) return;
|
|
292
|
+
const rect = box.current.getBoundingClientRect();
|
|
293
|
+
dragState.current = { dx: e.clientX - rect.left, dy: e.clientY - rect.top, x0: e.clientX, y0: e.clientY, moved: false };
|
|
294
|
+
try { e.currentTarget.setPointerCapture?.(e.pointerId); } catch {}
|
|
295
|
+
}
|
|
296
|
+
function dragMove(e) {
|
|
297
|
+
const d = dragState.current;
|
|
298
|
+
if (!d) return;
|
|
299
|
+
if (!d.moved && Math.abs(e.clientX - d.x0) + Math.abs(e.clientY - d.y0) < 4) return;
|
|
300
|
+
d.moved = true;
|
|
301
|
+
const next = clamp({ x: e.clientX - d.dx, y: e.clientY - d.dy });
|
|
302
|
+
lastPosition.current = next;
|
|
303
|
+
if (box.current) {
|
|
304
|
+
box.current.style.left = next.x + 'px';
|
|
305
|
+
box.current.style.top = next.y + 'px';
|
|
306
|
+
box.current.style.right = 'auto';
|
|
307
|
+
}
|
|
308
|
+
}
|
|
309
|
+
function dragEnd(e) {
|
|
310
|
+
const d = dragState.current;
|
|
311
|
+
if (!d) return;
|
|
312
|
+
dragState.current = null;
|
|
313
|
+
if (d.moved && lastPosition.current) commitPosition(lastPosition.current);
|
|
314
|
+
try { if (e.currentTarget.hasPointerCapture?.(e.pointerId)) e.currentTarget.releasePointerCapture(e.pointerId); } catch {}
|
|
315
|
+
}
|
|
316
|
+
function gripKeys(e) {
|
|
317
|
+
if (e.key === 'Home') { e.preventDefault(); setPreference({ position: null }); return; }
|
|
318
|
+
if (!['ArrowLeft', 'ArrowRight', 'ArrowUp', 'ArrowDown'].includes(e.key)) return;
|
|
319
|
+
e.preventDefault();
|
|
320
|
+
const rect = box.current.getBoundingClientRect();
|
|
321
|
+
commitPosition({
|
|
322
|
+
x: rect.left + (e.key === 'ArrowRight' ? 10 : e.key === 'ArrowLeft' ? -10 : 0),
|
|
323
|
+
y: rect.top + (e.key === 'ArrowDown' ? 10 : e.key === 'ArrowUp' ? -10 : 0),
|
|
324
|
+
});
|
|
325
|
+
}
|
|
326
|
+
|
|
327
|
+
function openEditor(e) {
|
|
328
|
+
focusReturn.current = e.currentTarget;
|
|
329
|
+
setDraft({ ...settings });
|
|
330
|
+
setEditing(true);
|
|
331
|
+
setError(''); setNotice('');
|
|
332
|
+
}
|
|
333
|
+
function closeEditor() {
|
|
334
|
+
if (!data?.configured) return;
|
|
335
|
+
setEditing(false); setDraft(null); setError('');
|
|
336
|
+
}
|
|
337
|
+
function update(key, value) { setDraft(current => ({ ...current, [key]: value })); }
|
|
338
|
+
function toggleBreak(e) {
|
|
339
|
+
const point = text => +text.slice(0, 2) * 60 + +text.slice(3);
|
|
340
|
+
const label = minutes => String(Math.floor(minutes / 60)).padStart(2, '0') + ':' + String(minutes % 60).padStart(2, '0');
|
|
341
|
+
setDraft(current => {
|
|
342
|
+
if (!e.target.checked) return { ...current, breakStart: current.start, breakEnd: current.start };
|
|
343
|
+
const start = point(current.start);
|
|
344
|
+
const span = (point(current.end) - start + 1440) % 1440;
|
|
345
|
+
return { ...current, breakStart: current.start, breakEnd: label((start + Math.max(1, Math.min(60, Math.floor(span / 2)))) % 1440) };
|
|
346
|
+
});
|
|
347
|
+
}
|
|
348
|
+
|
|
349
|
+
const label = (text, control) => h('label', { className: 'owc-field' }, h('span', null, text), control);
|
|
350
|
+
const numberInput = key => h('input', {
|
|
351
|
+
name: key, type: 'number', step: 'any', min: key === 'workdaysPerMonth' ? '0.01' : '0',
|
|
352
|
+
value: workingDraft?.[key] ?? '', disabled: busy,
|
|
353
|
+
onChange: e => update(key, e.target.value === '' ? '' : e.target.valueAsNumber),
|
|
354
|
+
});
|
|
355
|
+
const timeInput = key => h('input', {
|
|
356
|
+
name: key, type: 'time', required: true, value: workingDraft?.[key] ?? '', disabled: busy,
|
|
357
|
+
onChange: e => update(key, e.target.value),
|
|
358
|
+
});
|
|
359
|
+
const sessionSelect = () => h('select', {
|
|
360
|
+
value: sessionId || '', disabled: busy,
|
|
361
|
+
onChange: e => setSessionChoice(e.target.value),
|
|
362
|
+
}, sessionIds.length
|
|
363
|
+
? sessionIds.map(id => h('option', { key: id, value: id }, sessions?.byId?.[id]?.title || String(id).slice(0, 12)))
|
|
364
|
+
: h('option', { value: '' }, t('noSession')));
|
|
365
|
+
const salaryToggle = () => h('button', {
|
|
366
|
+
type: 'button', className: 'owc-text', 'aria-pressed': view.masked,
|
|
367
|
+
title: t(view.masked ? 'show' : 'hide'),
|
|
368
|
+
onClick: () => setPreference({ masked: !view.masked }),
|
|
369
|
+
}, iconSvg(view.masked ? 'eyeOff' : 'eye', 13), t(view.masked ? 'show' : 'hide'));
|
|
370
|
+
|
|
371
|
+
const strip = () => h('div', { className: 'owc-pill' },
|
|
372
|
+
h('div', { className: 'owc-pill-top' },
|
|
373
|
+
iconSvg('alarm', 16),
|
|
374
|
+
h('span', { className: 'owc-grip', tabIndex: 0, title: t('drag'), onKeyDown: gripKeys },
|
|
375
|
+
safeState.status !== 'done' && h('span', { className: 'owc-pill-status' }, t(safeState.status)),
|
|
376
|
+
h('span', { className: 'owc-pill-time' }, duration)),
|
|
377
|
+
h('button', {
|
|
378
|
+
type: 'button', className: 'owc-icon', style: { marginLeft: 'auto' },
|
|
379
|
+
title: t('expand'), 'aria-label': t('expand'),
|
|
380
|
+
onClick: () => setPreference({ mini: false }),
|
|
381
|
+
}, iconSvg('chevronUp', 14))),
|
|
382
|
+
h('div', { className: 'owc-pill-bottom' },
|
|
383
|
+
h('span', { className: 'owc-pill-money', 'aria-label': view.masked ? t('masked') : moneyText }, moneyText),
|
|
384
|
+
h('div', { className: 'owc-pill-actions' },
|
|
385
|
+
h('button', {
|
|
386
|
+
type: 'button', className: 'owc-icon',
|
|
387
|
+
title: t(view.masked ? 'show' : 'hide'), 'aria-label': t(view.masked ? 'show' : 'hide'),
|
|
388
|
+
onClick: () => setPreference({ masked: !view.masked }),
|
|
389
|
+
}, iconSvg(view.masked ? 'eyeOff' : 'eye', 14)))));
|
|
390
|
+
|
|
391
|
+
const panelHead = () => h('div', { className: 'owc-head' },
|
|
392
|
+
h('span', {
|
|
393
|
+
className: 'owc-title', tabIndex: 0, title: t('drag'), onKeyDown: gripKeys,
|
|
394
|
+
}, editing ? t(data?.configured ? 'settings' : 'setup') : t('title')),
|
|
395
|
+
editing
|
|
396
|
+
? (data?.configured && h('button', {
|
|
397
|
+
type: 'button', className: 'owc-icon', title: t('cancel'), 'aria-label': t('cancel'),
|
|
398
|
+
onClick: closeEditor, disabled: busy,
|
|
399
|
+
}, iconSvg('close')))
|
|
400
|
+
: h(React.Fragment, null,
|
|
401
|
+
h('button', {
|
|
402
|
+
type: 'button', className: 'owc-icon', title: t('settings'), 'aria-label': t('settings'),
|
|
403
|
+
onClick: openEditor, disabled: busy,
|
|
404
|
+
}, iconSvg('sliders')),
|
|
405
|
+
h('button', {
|
|
406
|
+
type: 'button', className: 'owc-icon', title: t('collapse'), 'aria-label': t('collapse'),
|
|
407
|
+
onClick: () => setPreference({ mini: true }),
|
|
408
|
+
}, iconSvg('chevronDown'))));
|
|
409
|
+
|
|
410
|
+
const panelBody = () => {
|
|
411
|
+
if (!safeState) return h('div', { className: 'owc-main' },
|
|
412
|
+
h('div', { className: 'owc-status' }, h('span', { className: 'owc-dot' }), t('loading')),
|
|
413
|
+
!sessionId && h('p', { className: 'owc-hint' }, t('noSession')),
|
|
414
|
+
h('div', { className: 'owc-row-actions' },
|
|
415
|
+
h('button', { type: 'button', className: 'owc-text', onClick: () => reload(true), disabled: busy || !sessionId },
|
|
416
|
+
iconSvg('refresh', 12), t('retry'))));
|
|
417
|
+
const status = safeState.status === 'done' ? '' : t(safeState.status);
|
|
418
|
+
return h('div', { className: 'owc-main' },
|
|
419
|
+
status && h('div', { className: 'owc-status' }, h('span', { className: 'owc-dot' }), status),
|
|
420
|
+
h('div', { className: 'owc-time', 'aria-label': status + ' ' + duration }, duration),
|
|
421
|
+
h('div', {
|
|
422
|
+
className: 'owc-progress', role: 'progressbar', 'aria-label': t('progress'),
|
|
423
|
+
'aria-valuenow': Math.floor(safeState.progress * 100), 'aria-valuemin': 0, 'aria-valuemax': 100,
|
|
424
|
+
}, h('div', { style: { width: safeState.progress * 100 + '%' } })),
|
|
425
|
+
h('div', { className: 'owc-earn-row' },
|
|
426
|
+
h('span', { className: 'owc-muted' }, t('earned')), salaryToggle()),
|
|
427
|
+
h('div', { className: 'owc-money', 'aria-label': view.masked ? t('masked') : moneyText }, moneyText),
|
|
428
|
+
h('div', { className: 'owc-stats' },
|
|
429
|
+
h('div', null, h('span', null, t('daily')), h('strong', null, money(safeState.daily))),
|
|
430
|
+
h('div', null, h('span', null, t('hourly')), h('strong', null, money(safeState.hourly)))),
|
|
431
|
+
h('div', { className: 'owc-meta' },
|
|
432
|
+
h('span', null, settings.start + ' — ' + settings.end + (settings.end < settings.start ? ' +1' : '') +
|
|
433
|
+
' · ' + (settings.breakStart === settings.breakEnd ? t('noBreak') : settings.breakStart + '–' + settings.breakEnd)),
|
|
434
|
+
h('span', null, t('shiftDate') + ' ' + safeState.shiftDate + ' · ' + settings.timezone)),
|
|
435
|
+
h('div', { className: 'owc-row-actions' },
|
|
436
|
+
h('button', { type: 'button', className: 'owc-text', onClick: () => reload(true), disabled: busy },
|
|
437
|
+
iconSvg('refresh', 12), t('refresh')),
|
|
438
|
+
h('button', { type: 'button', className: 'owc-text', onClick: () => setPreference({ position: null }) }, t('reset'))));
|
|
439
|
+
};
|
|
440
|
+
|
|
441
|
+
const editor = () => {
|
|
442
|
+
if (!workingDraft) return null;
|
|
443
|
+
const payDaily = workingDraft.payMode === 'daily';
|
|
444
|
+
const salaryKey = payDaily ? 'dailySalary' : 'monthlySalary';
|
|
445
|
+
const salaryControl = view.masked
|
|
446
|
+
? h('div', { className: 'owc-private' }, h('span', null, '••••'),
|
|
447
|
+
h('button', { type: 'button', className: 'owc-text', onClick: () => setPreference({ masked: false }) }, t('show')))
|
|
448
|
+
: numberInput(salaryKey);
|
|
449
|
+
const breakOn = workingDraft.breakStart !== workingDraft.breakEnd;
|
|
450
|
+
const commonZones = ['Asia/Shanghai', 'Asia/Hong_Kong', 'Asia/Taipei', 'Asia/Singapore', 'Asia/Tokyo', 'Asia/Seoul', 'Asia/Kolkata', 'Europe/London', 'Europe/Paris', 'America/New_York', 'America/Los_Angeles', 'Australia/Sydney', 'UTC'];
|
|
451
|
+
let allZones = [];
|
|
452
|
+
try { allZones = Intl.supportedValuesOf('timeZone'); } catch {}
|
|
453
|
+
const zones = [...new Set([workingDraft.timezone, ...commonZones, ...allZones].filter(Boolean))];
|
|
454
|
+
return h('form', {
|
|
455
|
+
className: 'owc-form', onSubmit: save,
|
|
456
|
+
onKeyDown: e => { if (e.key === 'Escape') { e.preventDefault(); closeEditor(); } },
|
|
457
|
+
},
|
|
458
|
+
!data?.configured && h('p', { className: 'owc-hint' }, t('setupHint')),
|
|
459
|
+
h('fieldset', { className: 'owc-setting-group' }, h('legend', null, t('salaryGroup')),
|
|
460
|
+
label(t('payMode'), h('div', { className: 'owc-seg' },
|
|
461
|
+
h('button', { type: 'button', disabled: busy, 'aria-pressed': !payDaily, onClick: () => update('payMode', 'monthly') }, t('monthly')),
|
|
462
|
+
h('button', { type: 'button', disabled: busy, 'aria-pressed': payDaily, onClick: () => update('payMode', 'daily') }, t('dailyMode')))),
|
|
463
|
+
h('div', { className: 'owc-row2' },
|
|
464
|
+
label(t(salaryKey), salaryControl),
|
|
465
|
+
!payDaily && label(t('workdaysPerMonth'), numberInput('workdaysPerMonth')))),
|
|
466
|
+
h('fieldset', { className: 'owc-setting-group' }, h('legend', null, t('scheduleGroup')),
|
|
467
|
+
h('div', { className: 'owc-row2' }, label(t('start'), timeInput('start')), label(t('end'), timeInput('end'))),
|
|
468
|
+
workingDraft.end < workingDraft.start && h('p', { className: 'owc-hint' }, t('end') + ' · ' + t('nextDay')),
|
|
469
|
+
h('label', { className: 'owc-check' },
|
|
470
|
+
h('input', { type: 'checkbox', checked: breakOn, disabled: busy, onChange: toggleBreak }), t('breakEnabled')),
|
|
471
|
+
breakOn && h('div', { className: 'owc-row2' }, label(t('breakStart'), timeInput('breakStart')), label(t('breakEnd'), timeInput('breakEnd'))),
|
|
472
|
+
label(t('weekdays'), h('div', { className: 'owc-days' }, [0, 1, 2, 3, 4, 5, 6].map(day => h('button', {
|
|
473
|
+
key: day, type: 'button', disabled: busy, 'aria-pressed': workingDraft.weekdays.includes(day),
|
|
474
|
+
'aria-label': t('weekdays') + ' ' + t('days')[day],
|
|
475
|
+
onClick: () => update('weekdays', workingDraft.weekdays.includes(day)
|
|
476
|
+
? workingDraft.weekdays.filter(d => d !== day)
|
|
477
|
+
: [...workingDraft.weekdays, day].sort((a, b) => a - b)),
|
|
478
|
+
}, t('days')[day])))),
|
|
479
|
+
label(t('timezone'), h('select', {
|
|
480
|
+
name: 'timezone', value: workingDraft.timezone ?? '', disabled: busy,
|
|
481
|
+
onChange: e => update('timezone', e.target.value),
|
|
482
|
+
}, zones.map(zone => h('option', { key: zone, value: zone }, zone))))),
|
|
483
|
+
h('fieldset', { className: 'owc-setting-group' }, h('legend', null, t('appearanceGroup')),
|
|
484
|
+
label(t('opacity'), h(React.Fragment, null,
|
|
485
|
+
h('input', {
|
|
486
|
+
className: 'owc-range', type: 'range', min: '30', max: '100', step: '5',
|
|
487
|
+
value: String(Math.round(view.opacity * 100)), disabled: busy, 'aria-label': t('opacity'),
|
|
488
|
+
onChange: e => setPreference({ opacity: e.target.valueAsNumber / 100 }),
|
|
489
|
+
}),
|
|
490
|
+
h('span', { className: 'owc-hint', style: { margin: 0 } }, Math.round(view.opacity * 100) + '% · ' + t('opacityHint'))))),
|
|
491
|
+
preview && !preview.error && h('div', { className: 'owc-preview' },
|
|
492
|
+
t('preview') + ' · ' + t('daily') + ' ' + money(preview.daily) + ' · ' + t('hourly') + ' ' + money(preview.hourly)),
|
|
493
|
+
preview?.error && h('p', { className: 'owc-error', role: 'alert', style: { padding: 0 } }, preview.error),
|
|
494
|
+
h('details', { className: 'owc-advanced' },
|
|
495
|
+
h('summary', null, t('advanced')),
|
|
496
|
+
h('p', { className: 'owc-hint' }, t('sessionHint')),
|
|
497
|
+
label(t('session'), sessionSelect())),
|
|
498
|
+
h('p', { className: 'owc-hint' }, t('privacy')),
|
|
499
|
+
h('div', { className: 'owc-save' },
|
|
500
|
+
data?.configured && h('button', { type: 'button', className: 'owc-text', onClick: closeEditor, disabled: busy }, t('cancel')),
|
|
501
|
+
h('button', { type: 'submit', className: 'owc-primary', disabled: busy || !!preview?.error }, t(busy ? 'busy' : 'save'))));
|
|
502
|
+
};
|
|
503
|
+
|
|
504
|
+
const notices = () => h(React.Fragment, null,
|
|
505
|
+
error && h('p', { className: 'owc-error', role: 'alert' }, error),
|
|
506
|
+
state?.error && h('p', { className: 'owc-error', role: 'alert' }, state.error),
|
|
507
|
+
notice && h('p', { className: 'owc-note', role: 'status' }, notice),
|
|
508
|
+
storageError && h('p', { className: 'owc-note' }, t('storage')));
|
|
509
|
+
|
|
510
|
+
return h('section', {
|
|
511
|
+
ref: box,
|
|
512
|
+
className: 'owc-v2' + (collapsed ? ' owc-compact' : '') + (editing ? ' owc-editing' : ''),
|
|
513
|
+
'aria-label': t('title'), 'data-version': '1.0.0', 'data-status': safeState?.status || 'setup',
|
|
514
|
+
style: cardStyle,
|
|
515
|
+
onPointerDown: dragDown, onPointerMove: dragMove, onPointerUp: dragEnd,
|
|
516
|
+
onPointerCancel: dragEnd, onLostPointerCapture: dragEnd,
|
|
517
|
+
},
|
|
518
|
+
h('style', null, STYLE),
|
|
519
|
+
h('div', { className: 'owc-glass', 'aria-hidden': 'true' }),
|
|
520
|
+
h('div', { className: 'owc-content' },
|
|
521
|
+
collapsed ? strip() : h(React.Fragment, null,
|
|
522
|
+
panelHead(),
|
|
523
|
+
editing ? editor() : panelBody(),
|
|
524
|
+
notices())));
|
|
525
|
+
}
|
|
526
|
+
|
|
527
|
+
ctx.slots.inject('shell.overlay', () => ctx.slots.register({
|
|
528
|
+
name: 'shell.overlay', id: 'offwork-clock', order: 900,
|
|
529
|
+
label: () => ctx.locale.bind('offwork-clock')('title'),
|
|
530
|
+
}, Clock));
|
|
531
|
+
},
|
|
532
|
+
};
|
|
533
|
+
},
|
|
534
|
+
});
|