dsh-quick-phrases 0.0.0-stage → 0.3.3

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/client.js ADDED
@@ -0,0 +1,1039 @@
1
+ /**
2
+ * dsh-quick-phrases — client half.
3
+ *
4
+ * Two surfaces, one phrase list:
5
+ * - A row of chips next to the composer (under it by default; the manager can
6
+ * move it above the card or into the tool row). Clicking a chip sends that
7
+ * phrase's 发送内容 (text) right away when the composer is empty, and
8
+ * inserts it at the caret otherwise; the manager can switch it to
9
+ * fill-only.
10
+ * - `settings.section`: the management page (add / edit / delete / reorder,
11
+ * and the display position), where 显示名称 (label) and 发送内容 (text) are
12
+ * edited as separate fields.
13
+ *
14
+ * The list and the placement live in localStorage, so they are per browser
15
+ * profile and survive restarts without a Host-side service. Keep this file
16
+ * dependency-free: it is served verbatim to the Web page, there is no build step.
17
+ */
18
+ window.__ModuleLoader__.load({
19
+ id: 'dsh-quick-phrases',
20
+ factory(require) {
21
+ 'use strict'
22
+
23
+ var React = require('react')
24
+ var h = React.createElement
25
+
26
+ var NS = 'dsh-quick-phrases'
27
+ var STORAGE_KEY = 'dsh.quick-phrases.v1'
28
+ var PLACEMENT_KEY = 'dsh.quick-phrases.placement.v1'
29
+ var CLICK_KEY = 'dsh.quick-phrases.click.v1'
30
+ var SECTION_ID = 'quick-phrases'
31
+ var DOCK_ORDER = 5
32
+ var SECTION_ORDER = 26
33
+
34
+ /**
35
+ * Where the phrase row lives. Each value is one composer slot; the manager
36
+ * writes the choice here and every registered row re-evaluates it, so the
37
+ * row moves between slots without an extra round of registration.
38
+ */
39
+ var PLACEMENTS = [
40
+ { slot: 'conversation.composer.dock', value: 'composer-dock', tag: 'dock', order: DOCK_ORDER, compact: false, key: 'manager.placementDock' },
41
+ // `dock` rows live in the composer stack, whose children stretch to the
42
+ // whole column; the card itself is narrower. `inset: true` copies the
43
+ // host's own dock geometry (QueueDock/TodoPanel) so the row lines up with
44
+ // the card instead of hanging off the column's left edge.
45
+ { slot: 'conversation.input.dock', value: 'input-dock', tag: 'top', order: -10, compact: false, inset: true, key: 'manager.placementTop' },
46
+ { slot: 'conversation.input.right', value: 'tool-right', tag: 'tool', order: -5, compact: true, key: 'manager.placementTool' },
47
+ ]
48
+ var DEFAULT_PLACEMENT = PLACEMENTS[0].value
49
+
50
+ /**
51
+ * What a chip click does. `send` sends the phrase straight away when the
52
+ * composer is empty (the shortcut case); `fill` only writes it into the
53
+ * draft. Either way a draft that already has content is never thrown away.
54
+ */
55
+ var CLICK_MODES = ['send', 'fill']
56
+ var DEFAULT_CLICK = 'send'
57
+
58
+ var DICTS = {
59
+ zh: {
60
+ 'section.title': '快捷短语',
61
+ 'section.description': '在输入框附近放一排短语按钮。按钮上显示的是「显示名称」,发送内容单独编辑,两者可以完全不同。下面的两项决定它出现在哪里、点一下会发生什么。',
62
+ 'dock.manage': '管理',
63
+ 'dock.openFailed': '请在「设置 — 快捷短语」中管理',
64
+ 'dock.tooltip': '写入输入框',
65
+ 'manager.add': '新增短语',
66
+ 'manager.phrases': '短语',
67
+ 'manager.count': '{n} 条',
68
+ 'manager.preview': '按钮预览',
69
+ 'manager.untitled': '未命名',
70
+ 'manager.chars': '{n} 字',
71
+ 'manager.drag': '拖动排序',
72
+ 'manager.deleteConfirm': '删除这条短语',
73
+ 'manager.deleteShort': '确认',
74
+ 'manager.reset': '恢复默认',
75
+ 'manager.resetConfirm': '再点一次确认',
76
+ 'manager.delete': '删除',
77
+ 'manager.moveUp': '上移',
78
+ 'manager.moveDown': '下移',
79
+ 'manager.placement': '显示位置',
80
+ 'manager.placementDock': '输入框下方',
81
+ 'manager.placementTop': '输入框上方',
82
+ 'manager.placementTool': '工具行右侧',
83
+ 'manager.placementHint': '切换后短语行会立刻移动到新位置。工具行右侧空间有限,超出的短语可以横向滚动。',
84
+ 'manager.clickMode': '点按短语时',
85
+ 'manager.clickSend': '直接发送',
86
+ 'manager.clickInsert': '填入输入框',
87
+ 'manager.clickHint': '「直接发送」在输入框为空时一次点按就发出这条短语;输入框里已有文字或附件时会改为插到光标处,不会覆盖你正在写的内容。',
88
+ 'manager.label': '显示名称',
89
+ 'manager.text': '发送内容',
90
+ 'manager.labelPlaceholder': '按钮上显示的文字,例如:提交',
91
+ 'manager.textPlaceholder': '点按按钮后写入输入框的内容,例如:提交改动并推送到远端',
92
+ 'manager.newPhrase': '新短语',
93
+ 'manager.empty': '列表是空的,先新增一条短语。',
94
+ 'manager.savedHint': '改动会自动保存并立即生效,无需重启。',
95
+ 'manager.tip': '拖动手柄或 ↑↓ 都能调整顺序,改动会自动保存。',
96
+ 'default.continue.label': '继续',
97
+ 'default.continue.text': '继续',
98
+ 'default.commit.label': '提交',
99
+ 'default.commit.text': '提交改动并推送到远端',
100
+ 'default.push.label': '推送',
101
+ 'default.push.text': '把本地提交推送到远端',
102
+ 'default.release.label': '发版',
103
+ 'default.release.text': '发布新版本',
104
+ },
105
+ en: {
106
+ 'section.title': 'Quick phrases',
107
+ 'section.description': 'A row of phrase chips next to the composer. A chip shows its display name while the text it inserts is edited separately. The two options below decide where it lives and what a click does.',
108
+ 'dock.manage': 'Manage',
109
+ 'dock.openFailed': 'Manage them in Settings — Quick phrases',
110
+ 'dock.tooltip': 'Insert into the composer',
111
+ 'manager.add': 'Add phrase',
112
+ 'manager.phrases': 'Phrases',
113
+ 'manager.count': '{n}',
114
+ 'manager.preview': 'Chip preview',
115
+ 'manager.untitled': 'Untitled',
116
+ 'manager.chars': '{n} chars',
117
+ 'manager.drag': 'Drag to reorder',
118
+ 'manager.deleteConfirm': 'Delete this phrase',
119
+ 'manager.deleteShort': 'Confirm',
120
+ 'manager.reset': 'Restore defaults',
121
+ 'manager.resetConfirm': 'Click again to confirm',
122
+ 'manager.delete': 'Delete',
123
+ 'manager.moveUp': 'Move up',
124
+ 'manager.moveDown': 'Move down',
125
+ 'manager.placement': 'Position',
126
+ 'manager.placementDock': 'Below the composer',
127
+ 'manager.placementTop': 'Above the composer',
128
+ 'manager.placementTool': 'Composer tool row',
129
+ 'manager.placementHint': 'The row moves as soon as you switch. The tool row is narrow, so long lists scroll sideways.',
130
+ 'manager.clickMode': 'On click',
131
+ 'manager.clickSend': 'Send right away',
132
+ 'manager.clickInsert': 'Fill the composer',
133
+ 'manager.clickHint': '“Send right away” fires the phrase with one click while the composer is empty; when it already holds text or attachments the phrase is inserted at the caret instead, so nothing you were writing is lost.',
134
+ 'manager.label': 'Display name',
135
+ 'manager.text': 'Sent text',
136
+ 'manager.labelPlaceholder': 'Chip caption, e.g. Commit',
137
+ 'manager.textPlaceholder': 'What the chip inserts, e.g. Commit the changes and push to the remote',
138
+ 'manager.newPhrase': 'New phrase',
139
+ 'manager.empty': 'The list is empty. Add one phrase to start.',
140
+ 'manager.savedHint': 'Changes save automatically and apply immediately.',
141
+ 'manager.tip': 'Drag the handle or use ↑↓ to reorder; edits are saved automatically.',
142
+ 'default.continue.label': 'Continue',
143
+ 'default.continue.text': 'Continue',
144
+ 'default.commit.label': 'Commit',
145
+ 'default.commit.text': 'Commit the changes and push to the remote',
146
+ 'default.push.label': 'Push',
147
+ 'default.push.text': 'Push local commits to the remote',
148
+ 'default.release.label': 'Release',
149
+ 'default.release.text': 'Release a new version',
150
+ },
151
+ }
152
+
153
+ var DEFAULT_SPECS = [
154
+ { id: 'continue', label: 'default.continue.label', text: 'default.continue.text' },
155
+ { id: 'commit', label: 'default.commit.label', text: 'default.commit.text' },
156
+ { id: 'push', label: 'default.push.label', text: 'default.push.text' },
157
+ { id: 'release', label: 'default.release.label', text: 'default.release.text' },
158
+ ]
159
+
160
+ /* ------------------------------------------------------------------ *
161
+ * Phrase store: module-level state shared by the dock and the manager.
162
+ * ------------------------------------------------------------------ */
163
+
164
+ var state = null
165
+ var placement = null
166
+ var clickMode = null
167
+ var listeners = new Set()
168
+
169
+ function uniqueId() {
170
+ return 'p' + Date.now().toString(36) + Math.random().toString(36).slice(2, 7)
171
+ }
172
+
173
+ function normalize(item, index) {
174
+ if (item === null || typeof item !== 'object') return null
175
+ var label = typeof item.label === 'string' ? item.label : ''
176
+ var text = typeof item.text === 'string' ? item.text : ''
177
+ if (label === '' && text === '') return null
178
+ var id = typeof item.id === 'string' && item.id !== '' ? item.id : 'p' + index
179
+ return { id: id, label: label, text: text }
180
+ }
181
+
182
+ function readStorage() {
183
+ try {
184
+ var raw = window.localStorage.getItem(STORAGE_KEY)
185
+ if (raw === null) return null
186
+ var parsed = JSON.parse(raw)
187
+ if (!Array.isArray(parsed)) return null
188
+ var out = []
189
+ parsed.forEach(function (item, index) {
190
+ var next = normalize(item, index)
191
+ if (next !== null) out.push(next)
192
+ })
193
+ return out
194
+ } catch (error) {
195
+ console.warn('[quick-phrases] could not read stored phrases', error)
196
+ return null
197
+ }
198
+ }
199
+
200
+ function persist() {
201
+ try {
202
+ window.localStorage.setItem(STORAGE_KEY, JSON.stringify(state))
203
+ } catch (error) {
204
+ console.warn('[quick-phrases] could not persist phrases', error)
205
+ }
206
+ }
207
+
208
+ function emit() {
209
+ listeners.forEach(function (listener) {
210
+ try {
211
+ listener()
212
+ } catch (error) {
213
+ console.warn('[quick-phrases] listener failed', error)
214
+ }
215
+ })
216
+ }
217
+
218
+ function seededPhrases(t) {
219
+ return DEFAULT_SPECS.map(function (spec) {
220
+ return { id: spec.id, label: t(spec.label), text: t(spec.text) }
221
+ })
222
+ }
223
+
224
+ /** Seeds on first use: stored list wins, otherwise localized defaults. */
225
+ function ensureSeeded(t) {
226
+ if (state !== null) return state
227
+ var stored = readStorage()
228
+ state = stored === null ? seededPhrases(t) : stored
229
+ if (stored === null) persist()
230
+ return state
231
+ }
232
+
233
+ function replacePhrases(next) {
234
+ state = next
235
+ persist()
236
+ emit()
237
+ }
238
+
239
+ function updatePhrase(index, patch) {
240
+ if (state === null) return
241
+ var next = state.slice()
242
+ var current = next[index]
243
+ if (current === undefined) return
244
+ next[index] = {
245
+ id: current.id,
246
+ label: typeof patch.label === 'string' ? patch.label : current.label,
247
+ text: typeof patch.text === 'string' ? patch.text : current.text,
248
+ }
249
+ replacePhrases(next)
250
+ }
251
+
252
+ function insertPhrase() {
253
+ if (state === null) return null
254
+ var id = uniqueId()
255
+ replacePhrases(state.concat([{ id: id, label: '', text: '' }]))
256
+ return id
257
+ }
258
+
259
+ function removePhrase(index) {
260
+ if (state === null || state[index] === undefined) return
261
+ replacePhrases(state.filter(function (_item, at) { return at !== index }))
262
+ }
263
+
264
+ function movePhrase(index, delta) {
265
+ if (state === null) return
266
+ var target = index + delta
267
+ if (target < 0 || target >= state.length) return
268
+ var next = state.slice()
269
+ var moved = next[index]
270
+ next[index] = next[target]
271
+ next[target] = moved
272
+ replacePhrases(next)
273
+ }
274
+
275
+ /** Drag-and-drop reorder: pull one entry out and drop it at `to`. */
276
+ function movePhraseTo(from, to) {
277
+ if (state === null) return
278
+ if (from < 0 || to < 0 || from >= state.length || to >= state.length || from === to) return
279
+ var next = state.slice()
280
+ var moved = next.splice(from, 1)[0]
281
+ next.splice(to, 0, moved)
282
+ replacePhrases(next)
283
+ }
284
+
285
+ function resetPhrases(t) {
286
+ replacePhrases(seededPhrases(t))
287
+ }
288
+
289
+ function subscribe(listener) {
290
+ listeners.add(listener)
291
+ return function () {
292
+ listeners.delete(listener)
293
+ }
294
+ }
295
+
296
+ /** Subscribes this component to the shared list and returns the current one. */
297
+ function usePhrases(t) {
298
+ var tick = React.useState(0)
299
+ var setTick = tick[1]
300
+ React.useEffect(function () {
301
+ var unsubscribe = subscribe(function () {
302
+ setTick(function (value) { return value + 1 })
303
+ })
304
+ function onStorage(event) {
305
+ if (event.key !== STORAGE_KEY) return
306
+ var stored = readStorage()
307
+ if (stored !== null) state = stored
308
+ setTick(function (value) { return value + 1 })
309
+ }
310
+ window.addEventListener('storage', onStorage)
311
+ return function () {
312
+ unsubscribe()
313
+ window.removeEventListener('storage', onStorage)
314
+ }
315
+ }, [])
316
+ return ensureSeeded(t)
317
+ }
318
+
319
+ /* ------------------------------------------------------------------ *
320
+ * Placement store: which composer slot the row lives in.
321
+ * ------------------------------------------------------------------ */
322
+
323
+ function isPlacement(value) {
324
+ for (var i = 0; i < PLACEMENTS.length; i += 1) {
325
+ if (PLACEMENTS[i].value === value) return true
326
+ }
327
+ return false
328
+ }
329
+
330
+ function readPlacement() {
331
+ try {
332
+ var raw = window.localStorage.getItem(PLACEMENT_KEY)
333
+ if (raw !== null && isPlacement(raw)) return raw
334
+ } catch (error) {
335
+ console.warn('[quick-phrases] could not read the stored placement', error)
336
+ }
337
+ return DEFAULT_PLACEMENT
338
+ }
339
+
340
+ function ensurePlacement() {
341
+ if (placement !== null) return placement
342
+ placement = readPlacement()
343
+ return placement
344
+ }
345
+
346
+ function setPlacement(next) {
347
+ if (!isPlacement(next) || next === ensurePlacement()) return
348
+ placement = next
349
+ try {
350
+ window.localStorage.setItem(PLACEMENT_KEY, next)
351
+ } catch (error) {
352
+ console.warn('[quick-phrases] could not persist the placement', error)
353
+ }
354
+ emit()
355
+ }
356
+
357
+ /** Subscribes a component to the shared placement and returns the current one. */
358
+ function usePlacement() {
359
+ var tick = React.useState(0)
360
+ var setTick = tick[1]
361
+ React.useEffect(function () {
362
+ var unsubscribe = subscribe(function () {
363
+ setTick(function (value) { return value + 1 })
364
+ })
365
+ function onStorage(event) {
366
+ if (event.key !== PLACEMENT_KEY) return
367
+ placement = readPlacement()
368
+ setTick(function (value) { return value + 1 })
369
+ }
370
+ window.addEventListener('storage', onStorage)
371
+ return function () {
372
+ unsubscribe()
373
+ window.removeEventListener('storage', onStorage)
374
+ }
375
+ }, [])
376
+ return ensurePlacement()
377
+ }
378
+
379
+ /* ------------------------------------------------------------------ *
380
+ * Click store: send the phrase at once, or only fill it in.
381
+ * ------------------------------------------------------------------ */
382
+
383
+ function isClickMode(value) {
384
+ return CLICK_MODES.indexOf(value) >= 0
385
+ }
386
+
387
+ function readClickMode() {
388
+ try {
389
+ var raw = window.localStorage.getItem(CLICK_KEY)
390
+ if (raw !== null && isClickMode(raw)) return raw
391
+ } catch (error) {
392
+ console.warn('[quick-phrases] could not read the stored click mode', error)
393
+ }
394
+ return DEFAULT_CLICK
395
+ }
396
+
397
+ function ensureClickMode() {
398
+ if (clickMode !== null) return clickMode
399
+ clickMode = readClickMode()
400
+ return clickMode
401
+ }
402
+
403
+ function setClickMode(next) {
404
+ if (!isClickMode(next) || next === ensureClickMode()) return
405
+ clickMode = next
406
+ try {
407
+ window.localStorage.setItem(CLICK_KEY, next)
408
+ } catch (error) {
409
+ console.warn('[quick-phrases] could not persist the click mode', error)
410
+ }
411
+ emit()
412
+ }
413
+
414
+ /** Subscribes a component to the shared click mode and returns the current one. */
415
+ function useClickMode() {
416
+ var tick = React.useState(0)
417
+ var setTick = tick[1]
418
+ React.useEffect(function () {
419
+ var unsubscribe = subscribe(function () {
420
+ setTick(function (value) { return value + 1 })
421
+ })
422
+ function onStorage(event) {
423
+ if (event.key !== CLICK_KEY) return
424
+ clickMode = readClickMode()
425
+ setTick(function (value) { return value + 1 })
426
+ }
427
+ window.addEventListener('storage', onStorage)
428
+ return function () {
429
+ unsubscribe()
430
+ window.removeEventListener('storage', onStorage)
431
+ }
432
+ }, [])
433
+ return ensureClickMode()
434
+ }
435
+
436
+ /* ------------------------------------------------------------------ *
437
+ * Styles: local to each component, removed on unmount.
438
+ * ------------------------------------------------------------------ */
439
+
440
+ var DOCK_CSS =
441
+ '.dqp-dock{display:flex;align-items:center;flex-wrap:wrap;gap:6px;min-width:0;font-size:12px;line-height:18px;font-family:inherit}' +
442
+ '.dqp-dock-tool{flex-wrap:nowrap;overflow-x:auto;overflow-y:hidden;max-width:min(50vw,460px);scrollbar-width:none;padding-bottom:1px}' +
443
+ '.dqp-dock-tool::-webkit-scrollbar{display:none}' +
444
+ '.dqp-chip{box-sizing:border-box;display:inline-flex;align-items:center;flex:0 0 auto;height:24px;max-width:200px;padding:0 10px;' +
445
+ 'border:.5px solid var(--dsw-alias-border-l2,#494949);border-radius:999px;background:var(--dsw-alias-bg-layer-1,rgba(255,255,255,.04));' +
446
+ 'color:var(--dsw-alias-label-secondary,#b9b9b9);font:inherit;font-size:12px;line-height:1;cursor:pointer;white-space:nowrap;' +
447
+ 'overflow:hidden;text-overflow:ellipsis;transition:background-color .12s ease,color .12s ease,border-color .12s ease}' +
448
+ '.dqp-dock-tool .dqp-chip{height:22px;padding:0 8px;font-size:11px;max-width:130px}' +
449
+ // Same geometry as the host dock cards above the composer (QueueDock /
450
+ // TodoPanel): the stack stretches children to the whole column while the
451
+ // input card is narrower and centred, so match the card's width, centre,
452
+ // and cancel the stack gap the way an attached dock does.
453
+ '.dqp-dock-inset{box-sizing:border-box;width:calc(100% - var(--dsh-composer-side-clearance,16px) - var(--dsh-composer-side-clearance,16px) - var(--dsh-composer-dock-inset,8px) - var(--dsh-composer-dock-inset,8px));' +
454
+ 'max-width:calc(var(--dsh-composer-card-max-width,952px) - var(--dsh-composer-dock-inset,8px) - var(--dsh-composer-dock-inset,8px));' +
455
+ 'margin:0 auto;padding:0 var(--dsh-composer-dock-inset,8px)}' +
456
+ '.dqp-chip:hover{background:var(--dsw-alias-interactive-bg-hover,rgba(255,255,255,.08));color:var(--dsw-alias-label-primary,#eee);' +
457
+ 'border-color:var(--dsw-alias-border-l3,#5a5a5a)}' +
458
+ '.dqp-chip:active{background:var(--dsw-alias-interactive-bg-hover-solid,rgba(255,255,255,.12))}' +
459
+ '.dqp-chip:focus-visible{outline:var(--dsw-focus-ring-width,2px) solid var(--dsw-focus-ring-color,var(--dsw-alias-brand-primary,#4c6fff));outline-offset:2px}' +
460
+ '.dqp-chip-manage{color:var(--dsw-alias-label-tertiary,#9a9a9a);border-style:dashed;background:transparent}' +
461
+ '.dqp-hint{color:var(--dsw-alias-state-warn-primary,#e0a33a);white-space:nowrap}'
462
+
463
+ var MANAGER_CSS =
464
+ '.dqp-page{box-sizing:border-box;height:100%;min-height:0;overflow-y:auto;display:flex;justify-content:center;' +
465
+ 'padding:24px clamp(20px,4vw,44px) 48px;font-family:inherit;color:var(--dsw-alias-label-primary,#eee)}' +
466
+ '.dqp-inner{width:100%;max-width:760px;display:flex;flex-direction:column;gap:18px}' +
467
+ '.dqp-head{display:flex;align-items:flex-start;gap:12px}' +
468
+ '.dqp-head-text{flex:1 1 auto;min-width:0;display:flex;flex-direction:column;gap:4px}' +
469
+ '.dqp-title{margin:0;font-size:16px;line-height:24px;font-weight:600}' +
470
+ '.dqp-desc{margin:0;font-size:12px;line-height:18px;color:var(--dsw-alias-label-secondary,#b9b9b9)}' +
471
+ '.dqp-badge{flex:0 0 auto;display:inline-flex;align-items:center;height:20px;padding:0 8px;border-radius:999px;' +
472
+ 'background:var(--dsw-alias-bg-layer-2,rgba(255,255,255,.05));color:var(--dsw-alias-label-tertiary,#9a9a9a);font-size:11px;line-height:1}' +
473
+ '.dqp-options{display:flex;flex-direction:column;border:.5px solid var(--dsw-alias-border-l2,#494949);' +
474
+ 'border-radius:var(--dsw-radius-md,10px);background:var(--dsw-alias-settings-card-fill,transparent);overflow:hidden}' +
475
+ '.dqp-option{display:flex;align-items:center;gap:16px;padding:10px 12px;border-top:.5px solid var(--dsw-alias-border-l1,#3a3a3a)}' +
476
+ '.dqp-option:first-child{border-top:0}' +
477
+ '.dqp-option-text{flex:1 1 auto;min-width:0;display:flex;flex-direction:column;gap:1px}' +
478
+ '.dqp-option-label{font-size:12px;line-height:18px;color:var(--dsw-alias-label-primary,#eee)}' +
479
+ '.dqp-option-hint{font-size:11px;line-height:16px;color:var(--dsw-alias-label-caption,#7d7d7d)}' +
480
+ '.dqp-select-wrap{position:relative;flex:0 0 auto;display:inline-flex}' +
481
+ '.dqp-select-wrap::after{content:"";position:absolute;right:10px;top:50%;width:6px;height:6px;margin-top:-4px;' +
482
+ 'border-right:1.4px solid var(--dsw-alias-label-tertiary,#9a9a9a);border-bottom:1.4px solid var(--dsw-alias-label-tertiary,#9a9a9a);' +
483
+ 'transform:rotate(45deg);pointer-events:none}' +
484
+ '.dqp-select{box-sizing:border-box;height:28px;min-width:136px;padding:0 28px 0 10px;border:.5px solid var(--dsw-alias-border-l2,#494949);' +
485
+ 'border-radius:var(--dsw-radius-sm,8px);background:var(--dsw-alias-bg-layer-2,rgba(255,255,255,.05));' +
486
+ 'color:var(--dsw-alias-label-primary,#eee);font:inherit;font-size:12px;line-height:1;appearance:none;-webkit-appearance:none;cursor:pointer}' +
487
+ '.dqp-select:hover{background:var(--dsw-alias-interactive-bg-hover,rgba(255,255,255,.08))}' +
488
+ '.dqp-select:focus-visible{outline:var(--dsw-focus-ring-width,2px) solid var(--dsw-focus-ring-color,var(--dsw-alias-brand-primary,#4c6fff));outline-offset:1px}' +
489
+ '.dqp-section{display:flex;flex-direction:column;gap:10px}' +
490
+ '.dqp-section-head{display:flex;align-items:center;flex-wrap:wrap;gap:8px}' +
491
+ '.dqp-section-title{flex:1 1 auto;margin:0;font-size:13px;line-height:20px;font-weight:600}' +
492
+ '.dqp-btn{box-sizing:border-box;display:inline-flex;align-items:center;justify-content:center;gap:4px;height:28px;padding:0 12px;' +
493
+ 'border:.5px solid var(--dsw-alias-border-l2,#494949);border-radius:var(--dsw-radius-sm,8px);' +
494
+ 'background:var(--dsw-alias-bg-layer-1,rgba(255,255,255,.04));color:var(--dsw-alias-label-primary,#eee);' +
495
+ 'font:inherit;font-size:12px;line-height:1;cursor:pointer;' +
496
+ 'transition:background-color .12s ease,border-color .12s ease,color .12s ease}' +
497
+ '.dqp-btn:not(.dqp-btn-primary):hover:not(:disabled){background:var(--dsw-alias-interactive-bg-hover,rgba(255,255,255,.08))}' +
498
+ '.dqp-btn:focus-visible{outline:var(--dsw-focus-ring-width,2px) solid var(--dsw-focus-ring-color,var(--dsw-alias-brand-primary,#4c6fff));outline-offset:2px}' +
499
+ '.dqp-btn-primary{border-color:transparent;background:var(--dsw-alias-button-primary-fill,#4c6fff);' +
500
+ 'color:var(--dsw-alias-label-primary-foreground,#fff)}' +
501
+ '.dqp-btn-primary:hover:not(:disabled){background:var(--dsw-alias-button-primary-hover,#3f5fe0)}' +
502
+ '.dqp-btn-warn{color:var(--dsw-alias-state-warn-primary,#e0a33a);border-color:var(--dsw-alias-state-warn-primary,#e0a33a)}' +
503
+ '.dqp-list{display:flex;flex-direction:column;gap:8px}' +
504
+ '.dqp-row{display:flex;align-items:flex-start;gap:8px;padding:10px 12px 10px 6px;border:.5px solid var(--dsw-alias-border-l2,#494949);' +
505
+ 'border-radius:var(--dsw-radius-md,10px);background:var(--dsw-alias-settings-card-fill,transparent);' +
506
+ 'transition:border-color .12s ease,box-shadow .12s ease,opacity .12s ease}' +
507
+ '.dqp-row:hover{border-color:var(--dsw-alias-border-l3,#5a5a5a)}' +
508
+ '.dqp-row-dragging{opacity:.45}' +
509
+ '.dqp-row-over{border-color:var(--dsw-alias-brand-primary,#4c6fff);box-shadow:0 0 0 1px var(--dsw-alias-brand-primary,#4c6fff)}' +
510
+ '.dqp-grip{flex:0 0 auto;display:inline-flex;align-items:center;justify-content:center;width:20px;height:28px;padding:0;' +
511
+ 'border:0;border-radius:6px;background:transparent;color:var(--dsw-alias-label-caption,#7d7d7d);font:inherit;font-size:13px;' +
512
+ 'line-height:1;letter-spacing:-1px;cursor:grab;user-select:none}' +
513
+ '.dqp-grip:hover{color:var(--dsw-alias-label-secondary,#b9b9b9);background:var(--dsw-alias-interactive-bg-hover,rgba(255,255,255,.06))}' +
514
+ '.dqp-grip:active{cursor:grabbing}' +
515
+ '.dqp-grip:focus-visible{outline:var(--dsw-focus-ring-width,2px) solid var(--dsw-focus-ring-color,var(--dsw-alias-brand-primary,#4c6fff));outline-offset:1px}' +
516
+ '.dqp-body{flex:1 1 auto;min-width:0;display:flex;flex-direction:column;gap:6px}' +
517
+ '.dqp-row-head{display:flex;align-items:center;gap:6px}' +
518
+ '.dqp-label-input{box-sizing:border-box;flex:1 1 auto;min-width:0;height:26px;padding:0 8px;border:.5px solid transparent;' +
519
+ 'border-radius:var(--dsw-radius-sm,8px);background:transparent;color:var(--dsw-alias-label-primary,#eee);' +
520
+ 'font:inherit;font-size:13px;font-weight:500;line-height:18px}' +
521
+ '.dqp-label-input:hover{background:var(--dsw-alias-interactive-bg-hover,rgba(255,255,255,.05))}' +
522
+ '.dqp-label-input:focus{outline:none;background:var(--dsw-alias-bg-layer-2,rgba(255,255,255,.04));' +
523
+ 'border-color:var(--dsw-alias-brand-primary,#4c6fff)}' +
524
+ '.dqp-label-input::placeholder{color:var(--dsw-alias-label-caption,#7d7d7d);font-weight:400}' +
525
+ '.dqp-row-actions{display:flex;align-items:center;gap:2px;flex:0 0 auto}' +
526
+ '.dqp-icon{box-sizing:border-box;display:inline-flex;align-items:center;justify-content:center;width:24px;height:24px;padding:0;' +
527
+ 'border:0;border-radius:6px;background:transparent;color:var(--dsw-alias-label-tertiary,#9a9a9a);' +
528
+ 'font:inherit;font-size:12px;line-height:1;cursor:pointer;transition:background-color .12s ease,color .12s ease}' +
529
+ '.dqp-icon:hover:not(:disabled){background:var(--dsw-alias-interactive-bg-hover,rgba(255,255,255,.08));color:var(--dsw-alias-label-primary,#eee)}' +
530
+ '.dqp-icon:focus-visible{outline:var(--dsw-focus-ring-width,2px) solid var(--dsw-focus-ring-color,var(--dsw-alias-brand-primary,#4c6fff));outline-offset:1px}' +
531
+ '.dqp-icon:disabled{opacity:.35;cursor:default}' +
532
+ '.dqp-icon-danger:hover:not(:disabled){background:var(--dsw-alias-state-error-primary,#e35d5d);color:var(--dsw-alias-label-on-color,#fff)}' +
533
+ '.dqp-icon-confirm{width:auto;padding:0 6px;font-size:11px;color:var(--dsw-alias-state-error-primary,#e35d5d);' +
534
+ 'background:transparent;box-shadow:inset 0 0 0 .5px var(--dsw-alias-state-error-primary,#e35d5d)}' +
535
+ '.dqp-textarea{box-sizing:border-box;width:100%;min-height:48px;padding:6px 8px;border:.5px solid var(--dsw-alias-border-l2,#494949);' +
536
+ 'border-radius:var(--dsw-radius-sm,8px);background:var(--dsw-alias-bg-layer-2,rgba(255,255,255,.03));' +
537
+ 'color:var(--dsw-alias-label-primary,#eee);font:inherit;font-size:12px;line-height:18px;resize:vertical}' +
538
+ '.dqp-textarea:hover{border-color:var(--dsw-alias-border-l3,#5a5a5a)}' +
539
+ '.dqp-textarea:focus{outline:none;border-color:var(--dsw-alias-brand-primary,#4c6fff)}' +
540
+ '.dqp-textarea::placeholder{color:var(--dsw-alias-label-caption,#7d7d7d)}' +
541
+ '.dqp-row-meta{display:flex;align-items:center;gap:8px;min-width:0;font-size:11px;line-height:16px;' +
542
+ 'color:var(--dsw-alias-label-caption,#7d7d7d)}' +
543
+ '.dqp-preview{display:inline-flex;align-items:center;height:20px;max-width:240px;padding:0 8px;' +
544
+ 'border:.5px solid var(--dsw-alias-border-l2,#494949);border-radius:999px;' +
545
+ 'background:var(--dsw-alias-bg-layer-1,rgba(255,255,255,.04));color:var(--dsw-alias-label-secondary,#b9b9b9);' +
546
+ 'overflow:hidden;text-overflow:ellipsis;white-space:nowrap}' +
547
+ '.dqp-preview-empty{opacity:.55}' +
548
+ '.dqp-meta-grow{flex:1 1 auto}' +
549
+ '.dqp-empty{padding:28px 12px;text-align:center;font-size:12px;line-height:18px;color:var(--dsw-alias-label-tertiary,#9a9a9a)}' +
550
+ '.dqp-foot{margin:0;font-size:12px;line-height:18px;color:var(--dsw-alias-label-caption,#7d7d7d)}'
551
+ '.dqp-fields{flex:1;min-width:0;display:flex;flex-direction:column;gap:8px}' +
552
+ '.dqp-field{display:flex;align-items:flex-start;gap:8px;min-width:0}' +
553
+ '.dqp-field-name{flex:0 0 64px;padding-top:6px;font-size:12px;line-height:18px;color:var(--dsw-alias-label-tertiary,#9a9a9a)}' +
554
+ '.dqp-input{box-sizing:border-box;flex:1;min-width:0;width:100%;padding:6px 10px;border:.5px solid var(--dsw-alias-border-l2,#494949);' +
555
+ 'border-radius:var(--dsw-radius-sm,8px);background:var(--dsw-alias-bg-layer-2,rgba(255,255,255,.03));' +
556
+ 'color:var(--dsw-alias-label-primary,#eee);font:inherit;font-size:12px;line-height:18px;resize:vertical}' +
557
+ '.dqp-input::placeholder{color:var(--dsw-alias-label-caption,#7d7d7d)}' +
558
+ '.dqp-input:focus{outline:none;border-color:var(--dsw-alias-brand-primary,#4c6fff)}' +
559
+ '.dqp-textarea{min-height:52px}' +
560
+ '.dqp-empty{padding:28px 12px;text-align:center;font-size:12px;line-height:18px;color:var(--dsw-alias-label-tertiary,#9a9a9a)}' +
561
+ '.dqp-foot{font-size:12px;line-height:18px;color:var(--dsw-alias-label-caption,#7d7d7d)}' +
562
+ '.dqp-badge{display:inline-flex;align-items:center;height:20px;padding:0 8px;border-radius:999px;' +
563
+ 'background:var(--dsw-alias-bg-layer-2,rgba(255,255,255,.05));color:var(--dsw-alias-label-tertiary,#9a9a9a);font-size:11px;line-height:1}'
564
+
565
+ /* ------------------------------------------------------------------ *
566
+ * Dock chips
567
+ * ------------------------------------------------------------------ */
568
+
569
+ /** Fallback translator: the slot synthesizes `t` from the locale seat, but a
570
+ * host that drops it must not blank our entry. */
571
+ function resolveT(props) {
572
+ if (typeof props.t === 'function') return props.t
573
+ var zh = typeof navigator !== 'undefined' && /^zh/i.test(navigator.language || '')
574
+ var dict = zh ? DICTS.zh : DICTS.en
575
+ return function (key) {
576
+ return dict[key] !== undefined ? dict[key] : key
577
+ }
578
+ }
579
+
580
+ function phraseCaption(phrase) {
581
+ if (phrase.label !== '') return phrase.label
582
+ var firstLine = phrase.text.split('\n')[0]
583
+ return firstLine.length > 24 ? firstLine.slice(0, 24) + '…' : firstLine
584
+ }
585
+
586
+ /** Narrow selectors so the row only re-renders when these two change. */
587
+ function draftOf(state) {
588
+ return state === null || state === undefined || typeof state.draft !== 'string' ? '' : state.draft
589
+ }
590
+
591
+ function attachmentCountOf(state) {
592
+ if (state === null || state === undefined || state.attachmentIds === null || state.attachmentIds === undefined) return 0
593
+ return state.attachmentIds.length
594
+ }
595
+
596
+ /**
597
+ * One chip row bound to one composer slot. All rows stay registered; the
598
+ * placement store decides which one renders, so a switch is a re-render
599
+ * instead of a re-registration.
600
+ */
601
+ function makeChips(spec) {
602
+ return function Chips(props) {
603
+ var t = resolveT(props)
604
+ var inputActions = props.inputActions
605
+ var openManager = props.openManager
606
+ var phrases = usePhrases(t)
607
+ var current = usePlacement()
608
+ var mode = useClickMode()
609
+ // `useInput` is part of the session slot kit; both calls sit here so the
610
+ // hook order never depends on the phrase list or on the placement.
611
+ var draft = typeof props.useInput === 'function' ? props.useInput(draftOf) : ''
612
+ var attachments = typeof props.useInput === 'function' ? props.useInput(attachmentCountOf) : 0
613
+ var showHint = React.useState(false)
614
+ var setShowHint = showHint[1]
615
+ var hintTimer = React.useRef(null)
616
+ var usable = phrases.filter(function (phrase) { return phrase.text.trim() !== '' })
617
+
618
+ React.useEffect(function () {
619
+ return function () {
620
+ if (hintTimer.current !== null) window.clearTimeout(hintTimer.current)
621
+ }
622
+ }, [])
623
+
624
+ if (current !== spec.value) return null
625
+
626
+ function insertIntoCaret(phrase) {
627
+ if (typeof inputActions.captureInsertion === 'function' && typeof inputActions.insertText === 'function') {
628
+ try {
629
+ return inputActions.insertText(phrase.text, inputActions.captureInsertion()) === true
630
+ } catch (error) {
631
+ console.warn('[quick-phrases] could not insert the phrase at the caret', error)
632
+ }
633
+ }
634
+ return false
635
+ }
636
+
637
+ function activate(phrase) {
638
+ if (inputActions === null || typeof inputActions !== 'object') {
639
+ console.warn('[quick-phrases] the slot did not provide inputActions')
640
+ return
641
+ }
642
+ var sendNow = mode === 'send' && draft.trim() === '' && attachments === 0
643
+ try {
644
+ if (sendNow) {
645
+ inputActions.setDraft(phrase.text)
646
+ if (typeof inputActions.submit === 'function') {
647
+ try {
648
+ inputActions.submit()
649
+ } catch (error) {
650
+ // The draft is already written; reporting beats sending twice.
651
+ console.warn('[quick-phrases] could not send the phrase', error)
652
+ }
653
+ }
654
+ return
655
+ }
656
+ if (!insertIntoCaret(phrase)) inputActions.setDraft(phrase.text)
657
+ } catch (error) {
658
+ console.warn('[quick-phrases] could not use the phrase', error)
659
+ }
660
+ }
661
+
662
+ function handleManage() {
663
+ var opened = false
664
+ try {
665
+ opened = openManager()
666
+ } catch (error) {
667
+ console.warn('[quick-phrases] could not open the manager', error)
668
+ }
669
+ if (!opened) {
670
+ setShowHint(true)
671
+ if (hintTimer.current !== null) window.clearTimeout(hintTimer.current)
672
+ hintTimer.current = window.setTimeout(function () { setShowHint(false) }, 3600)
673
+ }
674
+ }
675
+
676
+ var rowClass = 'dqp-dock'
677
+ if (spec.compact) rowClass += ' dqp-dock-tool'
678
+ if (spec.inset) rowClass += ' dqp-dock-inset'
679
+
680
+ var children = [
681
+ h('style', { key: 'style' }, DOCK_CSS),
682
+ h('div', { key: 'row', className: rowClass },
683
+ usable.map(function (phrase, index) {
684
+ return h('button', {
685
+ key: phrase.id + ':' + index,
686
+ type: 'button',
687
+ className: 'dqp-chip',
688
+ title: phrase.text,
689
+ 'aria-label': phraseCaption(phrase) + ' — ' + t('dock.tooltip'),
690
+ onClick: function () { activate(phrase) },
691
+ }, phraseCaption(phrase))
692
+ }),
693
+ h('button', {
694
+ key: 'manage',
695
+ type: 'button',
696
+ className: 'dqp-chip dqp-chip-manage',
697
+ onClick: handleManage,
698
+ }, t('dock.manage')),
699
+ ),
700
+ ]
701
+ if (showHint[0]) {
702
+ children.push(h('div', { key: 'hint', className: 'dqp-hint' }, t('dock.openFailed')))
703
+ }
704
+ return children
705
+ }
706
+ }
707
+
708
+ /* ------------------------------------------------------------------ *
709
+ * Settings page (the management surface)
710
+ * ------------------------------------------------------------------ */
711
+
712
+ function ManagerPage(props) {
713
+ var t = resolveT(props)
714
+ var phrases = usePhrases(t)
715
+ var placementNow = usePlacement()
716
+ var clickNow = useClickMode()
717
+
718
+ var resetState = React.useState(false)
719
+ var isResetting = resetState[0]
720
+ var setIsResetting = resetState[1]
721
+ var deleteState = React.useState(null)
722
+ var pendingDelete = deleteState[0]
723
+ var setPendingDelete = deleteState[1]
724
+ var dragState = React.useState(null)
725
+ var dragFrom = dragState[0]
726
+ var setDragFrom = dragState[1]
727
+ // The drop handler must see the drag source even before React re-renders.
728
+ var dragRef = React.useRef(null)
729
+ var dropState = React.useState(null)
730
+ var dragOver = dropState[0]
731
+ var setDragOver = dropState[1]
732
+ var focusState = React.useState(null)
733
+ var focusId = focusState[0]
734
+ var setFocusId = focusState[1]
735
+
736
+ // A pending delete forgets itself so a stray click cannot remove a phrase later.
737
+ React.useEffect(function () {
738
+ if (pendingDelete === null) return undefined
739
+ var timer = window.setTimeout(function () { setPendingDelete(null) }, 4000)
740
+ return function () { window.clearTimeout(timer) }
741
+ }, [pendingDelete])
742
+
743
+ React.useEffect(function () {
744
+ if (focusId !== null) setFocusId(null)
745
+ }, [focusId])
746
+
747
+ function handleReset() {
748
+ if (!isResetting) {
749
+ setIsResetting(true)
750
+ return
751
+ }
752
+ setIsResetting(false)
753
+ resetPhrases(t)
754
+ }
755
+
756
+ function handleAdd() {
757
+ var id = insertPhrase()
758
+ if (id !== null) setFocusId(id)
759
+ }
760
+
761
+ function handleDrop(index) {
762
+ var from = dragRef.current
763
+ if (from !== null) movePhraseTo(from, index)
764
+ endDrag()
765
+ }
766
+
767
+ function endDrag() {
768
+ dragRef.current = null
769
+ setDragFrom(null)
770
+ setDragOver(null)
771
+ }
772
+
773
+ var rows = phrases.map(function (phrase, index) {
774
+ var deleting = pendingDelete === phrase.id
775
+ var isDragging = dragFrom === index
776
+ var isDropTarget = dragOver === index && dragFrom !== null && dragFrom !== index
777
+ // Rough height hint: one row per line, plus one per ~72 characters.
778
+ var textRows = phrase.text === ''
779
+ ? 2
780
+ : Math.min(8, Math.max(2, phrase.text.split('\n').length + Math.floor(phrase.text.length / 72)))
781
+
782
+ return h('div', {
783
+ key: phrase.id,
784
+ className: 'dqp-row' + (isDragging ? ' dqp-row-dragging' : '') + (isDropTarget ? ' dqp-row-over' : ''),
785
+ onDragOver: function (event) {
786
+ event.preventDefault()
787
+ if (dragFrom !== null) setDragOver(index)
788
+ },
789
+ onDragLeave: function () {
790
+ if (dragOver === index) setDragOver(null)
791
+ },
792
+ onDrop: function (event) {
793
+ event.preventDefault()
794
+ handleDrop(index)
795
+ },
796
+ },
797
+ h('button', {
798
+ type: 'button',
799
+ className: 'dqp-grip',
800
+ draggable: true,
801
+ title: t('manager.drag'),
802
+ 'aria-label': t('manager.drag'),
803
+ onDragStart: function (event) {
804
+ dragRef.current = index
805
+ setDragFrom(index)
806
+ if (event && event.dataTransfer) {
807
+ event.dataTransfer.effectAllowed = 'move'
808
+ // Firefox only starts a drag when the payload is set.
809
+ try { event.dataTransfer.setData('text/plain', phrase.id) } catch (error) { /* ignore */ }
810
+ }
811
+ },
812
+ onDragEnd: endDrag,
813
+ }, '\u283f'),
814
+
815
+ h('div', { className: 'dqp-body' },
816
+ h('div', { className: 'dqp-row-head' },
817
+ h('input', {
818
+ type: 'text',
819
+ className: 'dqp-label-input',
820
+ value: phrase.label,
821
+ placeholder: t('manager.labelPlaceholder'),
822
+ 'aria-label': t('manager.label'),
823
+ spellCheck: false,
824
+ autoFocus: focusId === phrase.id,
825
+ onChange: function (event) { updatePhrase(index, { label: event.target.value }) },
826
+ }),
827
+ h('div', { className: 'dqp-row-actions' },
828
+ h('button', {
829
+ type: 'button',
830
+ className: 'dqp-icon',
831
+ title: t('manager.moveUp'),
832
+ 'aria-label': t('manager.moveUp'),
833
+ disabled: index === 0,
834
+ onClick: function () { movePhrase(index, -1) },
835
+ }, '\u2191'),
836
+ h('button', {
837
+ type: 'button',
838
+ className: 'dqp-icon',
839
+ title: t('manager.moveDown'),
840
+ 'aria-label': t('manager.moveDown'),
841
+ disabled: index === phrases.length - 1,
842
+ onClick: function () { movePhrase(index, 1) },
843
+ }, '\u2193'),
844
+ h('button', {
845
+ type: 'button',
846
+ className: 'dqp-icon dqp-icon-danger' + (deleting ? ' dqp-icon-confirm' : ''),
847
+ title: deleting ? t('manager.deleteConfirm') : t('manager.delete'),
848
+ 'aria-label': deleting ? t('manager.deleteConfirm') : t('manager.delete'),
849
+ onClick: function () {
850
+ if (!deleting) {
851
+ setPendingDelete(phrase.id)
852
+ return
853
+ }
854
+ setPendingDelete(null)
855
+ removePhrase(index)
856
+ },
857
+ }, deleting ? t('manager.deleteShort') : '\u2715'),
858
+ ),
859
+ ),
860
+
861
+ h('textarea', {
862
+ className: 'dqp-textarea',
863
+ value: phrase.text,
864
+ rows: textRows,
865
+ placeholder: t('manager.textPlaceholder'),
866
+ 'aria-label': t('manager.text'),
867
+ spellCheck: false,
868
+ onChange: function (event) { updatePhrase(index, { text: event.target.value }) },
869
+ }),
870
+
871
+ h('div', { className: 'dqp-row-meta' },
872
+ h('span', null, t('manager.preview')),
873
+ h('span', {
874
+ className: 'dqp-preview' + (phraseCaption(phrase) === '' ? ' dqp-preview-empty' : ''),
875
+ title: phrase.text,
876
+ }, phraseCaption(phrase) || t('manager.untitled')),
877
+ h('span', { className: 'dqp-meta-grow' }),
878
+ h('span', null, t('manager.chars').replace('{n}', String(phrase.text.length))),
879
+ ),
880
+ ),
881
+ )
882
+ })
883
+
884
+ var placementOption = h('div', { className: 'dqp-option' },
885
+ h('div', { className: 'dqp-option-text' },
886
+ h('label', { className: 'dqp-option-label', htmlFor: 'dqp-placement' }, t('manager.placement')),
887
+ h('span', { className: 'dqp-option-hint' }, t('manager.placementHint')),
888
+ ),
889
+ h('div', { className: 'dqp-select-wrap' },
890
+ h('select', {
891
+ id: 'dqp-placement',
892
+ className: 'dqp-select',
893
+ value: placementNow,
894
+ onChange: function (event) { setPlacement(event.target.value) },
895
+ },
896
+ PLACEMENTS.map(function (item) {
897
+ return h('option', { key: item.value, value: item.value }, t(item.key))
898
+ }),
899
+ ),
900
+ ),
901
+ )
902
+
903
+ var clickOption = h('div', { className: 'dqp-option' },
904
+ h('div', { className: 'dqp-option-text' },
905
+ h('label', { className: 'dqp-option-label', htmlFor: 'dqp-click' }, t('manager.clickMode')),
906
+ h('span', { className: 'dqp-option-hint' }, t('manager.clickHint')),
907
+ ),
908
+ h('div', { className: 'dqp-select-wrap' },
909
+ h('select', {
910
+ id: 'dqp-click',
911
+ className: 'dqp-select',
912
+ value: clickNow,
913
+ onChange: function (event) { setClickMode(event.target.value) },
914
+ },
915
+ CLICK_MODES.map(function (value) {
916
+ return h('option', { key: value, value: value }, t(value === 'send' ? 'manager.clickSend' : 'manager.clickInsert'))
917
+ }),
918
+ ),
919
+ ),
920
+ )
921
+
922
+ return h('div', { className: 'dqp-page' },
923
+ h('style', null, MANAGER_CSS),
924
+ h('div', { className: 'dqp-inner' },
925
+ h('div', { className: 'dqp-head' },
926
+ h('div', { className: 'dqp-head-text' },
927
+ h('h2', { className: 'dqp-title' }, t('section.title')),
928
+ h('p', { className: 'dqp-desc' }, t('section.description')),
929
+ ),
930
+ h('span', { className: 'dqp-badge' }, t('manager.count').replace('{n}', String(phrases.length))),
931
+ ),
932
+ h('div', { className: 'dqp-options' }, placementOption, clickOption),
933
+ h('div', { className: 'dqp-section' },
934
+ h('div', { className: 'dqp-section-head' },
935
+ h('h3', { className: 'dqp-section-title' }, t('manager.phrases')),
936
+ h('button', {
937
+ type: 'button',
938
+ className: 'dqp-btn' + (isResetting ? ' dqp-btn-warn' : ''),
939
+ onClick: handleReset,
940
+ }, isResetting ? t('manager.resetConfirm') : t('manager.reset')),
941
+ h('button', {
942
+ type: 'button',
943
+ className: 'dqp-btn dqp-btn-primary',
944
+ onClick: handleAdd,
945
+ }, '+ ' + t('manager.add')),
946
+ ),
947
+ rows.length > 0
948
+ ? h('div', { className: 'dqp-list' }, rows)
949
+ : h('div', { className: 'dqp-list' },
950
+ h('div', { className: 'dqp-empty' }, t('manager.empty')),
951
+ ),
952
+ ),
953
+ h('p', { className: 'dqp-foot' }, t('manager.savedHint') + ' ' + t('manager.tip')),
954
+ ),
955
+ )
956
+ }
957
+
958
+ /* ------------------------------------------------------------------ *
959
+ * Settings navigation glyph (optional; the page works without it)
960
+ * ------------------------------------------------------------------ */
961
+
962
+ function SectionIcon(props) {
963
+ var size = typeof props.size === 'number' ? props.size : 18
964
+ var color = props.active
965
+ ? 'var(--dsw-alias-brand-primary,#4c6fff)'
966
+ : 'var(--dsw-alias-label-secondary,#b9b9b9)'
967
+ return h('svg', {
968
+ width: size,
969
+ height: size,
970
+ viewBox: '0 0 24 24',
971
+ fill: 'none',
972
+ 'aria-hidden': true,
973
+ style: { display: 'block' },
974
+ },
975
+ h('rect', { x: 3, y: 5, width: 18, height: 15, rx: 4, stroke: color, strokeWidth: 1.6 }),
976
+ h('path', { d: 'M7 11h7M7 15h4', stroke: color, strokeWidth: 1.6, strokeLinecap: 'round' }),
977
+ h('path', { d: 'M16.5 14.5v4M14.5 16.5h4', stroke: color, strokeWidth: 1.6, strokeLinecap: 'round' }),
978
+ )
979
+ }
980
+
981
+ /* ------------------------------------------------------------------ *
982
+ * Plugin body
983
+ * ------------------------------------------------------------------ */
984
+
985
+ return {
986
+ inject: ['slots', 'locale'],
987
+ apply: function apply(ctx) {
988
+ ctx.effect(function () {
989
+ return ctx.locale.register(NS, DICTS)
990
+ })
991
+
992
+ function openManager() {
993
+ var rows = typeof ctx.slots.entries === 'function' ? ctx.slots.entries('sidebar.settings') : []
994
+ for (var i = 0; i < rows.length; i += 1) {
995
+ var row = rows[i]
996
+ if (row === null || row === undefined || row.store === null || row.store === undefined) continue
997
+ if (typeof row.store.create !== 'function') continue
998
+ var handle = row.store.create()
999
+ if (handle !== null && handle !== undefined && handle.actions !== null && handle.actions !== undefined &&
1000
+ typeof handle.actions.openSection === 'function') {
1001
+ handle.actions.openSection(SECTION_ID)
1002
+ return true
1003
+ }
1004
+ }
1005
+ return false
1006
+ }
1007
+
1008
+ PLACEMENTS.forEach(function (spec) {
1009
+ ctx.slots.inject(spec.slot, function () {
1010
+ return ctx.slots.register({
1011
+ name: spec.slot,
1012
+ id: SECTION_ID + '-' + spec.tag,
1013
+ order: spec.order,
1014
+ locale: NS,
1015
+ inject: function () { return { openManager: openManager } },
1016
+ }, makeChips(spec))
1017
+ })
1018
+ })
1019
+
1020
+ ctx.slots.inject('settings.section', function () {
1021
+ return ctx.slots.register({
1022
+ name: 'settings.section',
1023
+ id: SECTION_ID,
1024
+ order: SECTION_ORDER,
1025
+ locale: NS,
1026
+ label: function () { return ctx.locale.bind(NS)('section.title') },
1027
+ }, ManagerPage)
1028
+ })
1029
+
1030
+ ctx.slots.inject('settings.section.icon', function () {
1031
+ return ctx.slots.register({
1032
+ name: 'settings.section.icon',
1033
+ id: SECTION_ID,
1034
+ }, SectionIcon)
1035
+ })
1036
+ },
1037
+ }
1038
+ },
1039
+ })