@stefan.inc/feedback-engine 1.2.4 → 1.4.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/README.md +7 -1
- package/package.json +1 -1
- package/src/core/index.ts +1 -0
- package/src/core/savedWebhooks.ts +118 -0
- package/src/dom/savedWebhooks.ts +18 -0
- package/src/dom/share.ts +15 -8
- package/src/dom/webhook.ts +51 -6
- package/src/editor/Editor.svelte +107 -71
- package/src/editor/ProcrastimateSheet.svelte +39 -140
- package/src/editor/Sheet.svelte +120 -0
- package/src/editor/WebhookDialog.svelte +247 -0
- package/src/editor/WebhookSheet.svelte +8 -12
- package/src/editor/destinations.ts +29 -8
- package/src/editor/engine.ts +7 -1
- package/src/react/public.d.ts +7 -1
- package/src/editor/ItemsSheet.svelte +0 -233
|
@@ -14,6 +14,7 @@
|
|
|
14
14
|
type ProcrastimateConfig,
|
|
15
15
|
} from '../dom/procrastimate.ts';
|
|
16
16
|
import ProblemCard from './ProblemCard.svelte';
|
|
17
|
+
import Sheet from './Sheet.svelte';
|
|
17
18
|
|
|
18
19
|
let {
|
|
19
20
|
screen,
|
|
@@ -114,145 +115,53 @@
|
|
|
114
115
|
</button>
|
|
115
116
|
{/snippet}
|
|
116
117
|
|
|
117
|
-
<
|
|
118
|
-
|
|
119
|
-
class="
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
<
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
{
|
|
146
|
-
|
|
118
|
+
<Sheet label="Add to ProcrastiMate" onsubmit={() => void post()}>
|
|
119
|
+
{#snippet header()}
|
|
120
|
+
<button type="button" class="link" disabled={posting} onclick={onclose}>Cancel</button>
|
|
121
|
+
<h2>Add to ProcrastiMate</h2>
|
|
122
|
+
<button type="submit" class="link strong" disabled={posting || !name.trim()}>{posting ? 'Adding…' : 'Add'}</button>
|
|
123
|
+
{/snippet}
|
|
124
|
+
|
|
125
|
+
<div class="status" bind:this={status}>
|
|
126
|
+
{#if step}<p class="step" role="status">{step}…</p>{/if}
|
|
127
|
+
{#if postProblem}<ProblemCard problem={postProblem} />{/if}
|
|
128
|
+
{#if loadProblem}<ProblemCard problem={loadProblem} />{/if}
|
|
129
|
+
</div>
|
|
130
|
+
<label>
|
|
131
|
+
<span class="caption">Name</span>
|
|
132
|
+
<input bind:value={name} aria-label="Task name" disabled={posting} />
|
|
133
|
+
</label>
|
|
134
|
+
<span class="caption">Project{loading ? ' · loading…' : ''}</span>
|
|
135
|
+
<div class="list" role="listbox" aria-label="Project">
|
|
136
|
+
{@render row('Inbox', !place.projectId, false, () => (place = {}))}
|
|
137
|
+
{#each projects as project (project.id)}
|
|
138
|
+
{@const open = project.id === place.projectId && project.sections.length > 0}
|
|
139
|
+
{@render row(
|
|
140
|
+
project.name,
|
|
141
|
+
project.id === place.projectId && !open,
|
|
142
|
+
false,
|
|
143
|
+
() => (place = { projectId: project.id }),
|
|
144
|
+
)}
|
|
145
|
+
{#if open}
|
|
146
|
+
{@render row('No section', !place.sectionId, true, () => (place = { projectId: project.id }))}
|
|
147
|
+
{#each project.sections as section (section.id)}
|
|
147
148
|
{@render row(
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
() => (place = { projectId: project.id }),
|
|
149
|
+
section.name,
|
|
150
|
+
place.sectionId === section.id,
|
|
151
|
+
true,
|
|
152
|
+
() => (place = { projectId: project.id, sectionId: section.id }),
|
|
152
153
|
)}
|
|
153
|
-
{#if open}
|
|
154
|
-
{@render row('No section', !place.sectionId, true, () => (place = { projectId: project.id }))}
|
|
155
|
-
{#each project.sections as section (section.id)}
|
|
156
|
-
{@render row(
|
|
157
|
-
section.name,
|
|
158
|
-
place.sectionId === section.id,
|
|
159
|
-
true,
|
|
160
|
-
() => (place = { projectId: project.id, sectionId: section.id }),
|
|
161
|
-
)}
|
|
162
|
-
{/each}
|
|
163
|
-
{/if}
|
|
164
154
|
{/each}
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
</
|
|
168
|
-
</
|
|
155
|
+
{/if}
|
|
156
|
+
{/each}
|
|
157
|
+
</div>
|
|
158
|
+
</Sheet>
|
|
169
159
|
|
|
170
160
|
<style>
|
|
171
|
-
.scrim {
|
|
172
|
-
position: absolute;
|
|
173
|
-
inset: 0;
|
|
174
|
-
z-index: 5;
|
|
175
|
-
display: grid;
|
|
176
|
-
place-items: end center;
|
|
177
|
-
background: rgb(0 0 0 / 0.5);
|
|
178
|
-
}
|
|
179
|
-
|
|
180
|
-
.sheet {
|
|
181
|
-
display: flex;
|
|
182
|
-
flex-direction: column;
|
|
183
|
-
width: min(100%, 480px);
|
|
184
|
-
max-height: 85%;
|
|
185
|
-
border-radius: 16px 16px 0 0;
|
|
186
|
-
box-sizing: border-box;
|
|
187
|
-
background: #1f1f1f;
|
|
188
|
-
}
|
|
189
|
-
|
|
190
|
-
header {
|
|
191
|
-
display: flex;
|
|
192
|
-
align-items: center;
|
|
193
|
-
gap: 8px;
|
|
194
|
-
padding: 14px 16px 8px;
|
|
195
|
-
}
|
|
196
|
-
|
|
197
|
-
h2 {
|
|
198
|
-
flex: 1;
|
|
199
|
-
margin: 0;
|
|
200
|
-
font-size: 16px;
|
|
201
|
-
text-align: center;
|
|
202
|
-
}
|
|
203
|
-
|
|
204
|
-
button,
|
|
205
|
-
input {
|
|
206
|
-
color: inherit;
|
|
207
|
-
font: inherit;
|
|
208
|
-
}
|
|
209
|
-
|
|
210
|
-
button {
|
|
211
|
-
border: 0;
|
|
212
|
-
background: none;
|
|
213
|
-
cursor: pointer;
|
|
214
|
-
}
|
|
215
|
-
|
|
216
|
-
button:disabled {
|
|
217
|
-
cursor: default;
|
|
218
|
-
opacity: 0.5;
|
|
219
|
-
}
|
|
220
|
-
|
|
221
|
-
.link {
|
|
222
|
-
color: #0a84ff;
|
|
223
|
-
}
|
|
224
|
-
|
|
225
161
|
.strong {
|
|
226
162
|
font-weight: 600;
|
|
227
163
|
}
|
|
228
164
|
|
|
229
|
-
.scroll {
|
|
230
|
-
display: grid;
|
|
231
|
-
gap: 8px;
|
|
232
|
-
padding: 8px 16px 16px;
|
|
233
|
-
overflow: auto;
|
|
234
|
-
}
|
|
235
|
-
|
|
236
|
-
.caption {
|
|
237
|
-
color: #aeaeb2;
|
|
238
|
-
font-size: 12px;
|
|
239
|
-
font-weight: 600;
|
|
240
|
-
text-transform: uppercase;
|
|
241
|
-
}
|
|
242
|
-
|
|
243
|
-
label {
|
|
244
|
-
display: grid;
|
|
245
|
-
gap: 6px;
|
|
246
|
-
margin-bottom: 8px;
|
|
247
|
-
}
|
|
248
|
-
|
|
249
|
-
input {
|
|
250
|
-
border: 0;
|
|
251
|
-
border-radius: 10px;
|
|
252
|
-
padding: 10px 12px;
|
|
253
|
-
background: #2e2e30;
|
|
254
|
-
}
|
|
255
|
-
|
|
256
165
|
.list {
|
|
257
166
|
display: grid;
|
|
258
167
|
border-radius: 10px;
|
|
@@ -291,14 +200,4 @@
|
|
|
291
200
|
margin: 0;
|
|
292
201
|
color: #aeaeb2;
|
|
293
202
|
}
|
|
294
|
-
|
|
295
|
-
@media (min-width: 900px) {
|
|
296
|
-
.scrim {
|
|
297
|
-
place-items: center;
|
|
298
|
-
}
|
|
299
|
-
|
|
300
|
-
.sheet {
|
|
301
|
-
border-radius: 16px;
|
|
302
|
-
}
|
|
303
|
-
}
|
|
304
203
|
</style>
|
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
<svelte:options css="injected" />
|
|
2
|
+
|
|
3
|
+
<script lang="ts">
|
|
4
|
+
import type { Snippet } from 'svelte';
|
|
5
|
+
|
|
6
|
+
let {
|
|
7
|
+
label,
|
|
8
|
+
onsubmit,
|
|
9
|
+
header,
|
|
10
|
+
children,
|
|
11
|
+
}: { label: string; onsubmit: () => void; header: Snippet; children: Snippet } = $props();
|
|
12
|
+
</script>
|
|
13
|
+
|
|
14
|
+
<div class="scrim" role="presentation">
|
|
15
|
+
<form
|
|
16
|
+
class="sheet"
|
|
17
|
+
aria-label={label}
|
|
18
|
+
novalidate
|
|
19
|
+
onsubmit={event => {
|
|
20
|
+
event.preventDefault();
|
|
21
|
+
onsubmit();
|
|
22
|
+
}}
|
|
23
|
+
>
|
|
24
|
+
<header>{@render header()}</header>
|
|
25
|
+
<div class="scroll">{@render children()}</div>
|
|
26
|
+
</form>
|
|
27
|
+
</div>
|
|
28
|
+
|
|
29
|
+
<!-- The shared styles reach into content another component scopes, and `:where` keeps them below that component's own. -->
|
|
30
|
+
<style>
|
|
31
|
+
.scrim {
|
|
32
|
+
position: absolute;
|
|
33
|
+
inset: 0;
|
|
34
|
+
z-index: 5;
|
|
35
|
+
display: grid;
|
|
36
|
+
place-items: end center;
|
|
37
|
+
background: rgb(0 0 0 / 0.5);
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
.sheet {
|
|
41
|
+
display: flex;
|
|
42
|
+
flex-direction: column;
|
|
43
|
+
width: min(100%, 480px);
|
|
44
|
+
max-height: 85%;
|
|
45
|
+
border-radius: 16px 16px 0 0;
|
|
46
|
+
box-sizing: border-box;
|
|
47
|
+
background: #1f1f1f;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
header {
|
|
51
|
+
display: flex;
|
|
52
|
+
align-items: center;
|
|
53
|
+
gap: 8px;
|
|
54
|
+
padding: 14px 16px 8px;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
header :global(h2) {
|
|
58
|
+
flex: 1;
|
|
59
|
+
margin: 0;
|
|
60
|
+
font-size: 16px;
|
|
61
|
+
text-align: center;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
.scroll {
|
|
65
|
+
display: grid;
|
|
66
|
+
gap: 8px;
|
|
67
|
+
padding: 8px 16px 16px;
|
|
68
|
+
overflow: auto;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
:where(.sheet) :global(:is(button, input)) {
|
|
72
|
+
color: inherit;
|
|
73
|
+
font: inherit;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
:where(.sheet) :global(button) {
|
|
77
|
+
border: 0;
|
|
78
|
+
background: none;
|
|
79
|
+
cursor: pointer;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
:where(.sheet) :global(button:disabled) {
|
|
83
|
+
cursor: default;
|
|
84
|
+
opacity: 0.5;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
:where(.sheet) :global(.link) {
|
|
88
|
+
color: #0a84ff;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
:where(.sheet) :global(.caption) {
|
|
92
|
+
color: #aeaeb2;
|
|
93
|
+
font-size: 12px;
|
|
94
|
+
font-weight: 600;
|
|
95
|
+
text-transform: uppercase;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
:where(.sheet) :global(label:has(> .caption)) {
|
|
99
|
+
display: grid;
|
|
100
|
+
gap: 6px;
|
|
101
|
+
margin-bottom: 8px;
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
:where(.sheet) :global(:is(input:not([type]), input[type='url'])) {
|
|
105
|
+
border: 0;
|
|
106
|
+
border-radius: 10px;
|
|
107
|
+
padding: 10px 12px;
|
|
108
|
+
background: #2e2e30;
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
@media (min-width: 900px) {
|
|
112
|
+
.scrim {
|
|
113
|
+
place-items: center;
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
.sheet {
|
|
117
|
+
border-radius: 16px;
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
</style>
|
|
@@ -0,0 +1,247 @@
|
|
|
1
|
+
<svelte:options css="injected" />
|
|
2
|
+
|
|
3
|
+
<script lang="ts">
|
|
4
|
+
import {
|
|
5
|
+
draftOf,
|
|
6
|
+
readDraft,
|
|
7
|
+
type Compression,
|
|
8
|
+
type DraftErrors,
|
|
9
|
+
type SavedWebhook,
|
|
10
|
+
type WebhookDraft,
|
|
11
|
+
} from '../core/index.ts';
|
|
12
|
+
import { postId } from '../dom/webhook.ts';
|
|
13
|
+
import Sheet from './Sheet.svelte';
|
|
14
|
+
|
|
15
|
+
let {
|
|
16
|
+
webhook,
|
|
17
|
+
taken,
|
|
18
|
+
onsubmit,
|
|
19
|
+
ondelete,
|
|
20
|
+
onclose,
|
|
21
|
+
}: {
|
|
22
|
+
/** The webhook to edit, or none for a new one. */
|
|
23
|
+
webhook?: SavedWebhook;
|
|
24
|
+
/** The names of the Share menu's other entries. */
|
|
25
|
+
taken: string[];
|
|
26
|
+
/** Saves a new webhook, or saves an edited one and sends the feedback to it. Returns why it could not save. */
|
|
27
|
+
onsubmit: (webhook: SavedWebhook) => string | undefined;
|
|
28
|
+
ondelete: () => string | undefined;
|
|
29
|
+
onclose: () => void;
|
|
30
|
+
} = $props();
|
|
31
|
+
|
|
32
|
+
// The editor makes a new dialog each time it opens one, so the first value is the only one.
|
|
33
|
+
// svelte-ignore state_referenced_locally
|
|
34
|
+
let draft = $state<WebhookDraft>(draftOf(webhook));
|
|
35
|
+
let errors = $state<DraftErrors>({});
|
|
36
|
+
let failure = $state<string>();
|
|
37
|
+
// svelte-ignore state_referenced_locally
|
|
38
|
+
const id = webhook?.id ?? postId();
|
|
39
|
+
const compressions: Compression[] = ['low', 'medium', 'high'];
|
|
40
|
+
const list = new Intl.ListFormat('en', { type: 'conjunction' });
|
|
41
|
+
|
|
42
|
+
function submit() {
|
|
43
|
+
const read = readDraft(draft, { id, taken });
|
|
44
|
+
errors = 'errors' in read ? read.errors : {};
|
|
45
|
+
if ('webhook' in read) failure = onsubmit(read.webhook);
|
|
46
|
+
}
|
|
47
|
+
</script>
|
|
48
|
+
|
|
49
|
+
{#snippet field(key: keyof DraftErrors, caption: string, placeholder: string, type?: 'url')}
|
|
50
|
+
<label>
|
|
51
|
+
<span class="caption">{caption}</span>
|
|
52
|
+
<input
|
|
53
|
+
bind:value={draft[key]}
|
|
54
|
+
{type}
|
|
55
|
+
{placeholder}
|
|
56
|
+
autocapitalize={key === 'name' ? undefined : 'off'}
|
|
57
|
+
autocomplete="off"
|
|
58
|
+
spellcheck={key === 'name'}
|
|
59
|
+
aria-invalid={!!errors[key]}
|
|
60
|
+
aria-describedby={errors[key] ? `webhook-${key}-error` : undefined}
|
|
61
|
+
/>
|
|
62
|
+
{#if errors[key]}<span class="error" id="webhook-{key}-error">{errors[key]}</span>{/if}
|
|
63
|
+
</label>
|
|
64
|
+
{/snippet}
|
|
65
|
+
|
|
66
|
+
{#snippet segments(name: string, options: [string, string][], value: string, pick: (value: string) => void)}
|
|
67
|
+
<div class="choice" role="radiogroup" aria-label={name}>
|
|
68
|
+
<span>{name}</span>
|
|
69
|
+
<div class="segments">
|
|
70
|
+
{#each options as [option, label] (option)}
|
|
71
|
+
<label class:picked={value === option}>
|
|
72
|
+
<input type="radio" {name} value={option} checked={value === option} onchange={() => pick(option)} />{label}
|
|
73
|
+
</label>
|
|
74
|
+
{/each}
|
|
75
|
+
</div>
|
|
76
|
+
</div>
|
|
77
|
+
{/snippet}
|
|
78
|
+
|
|
79
|
+
<Sheet label={webhook ? 'Edit Webhook' : 'New Webhook'} onsubmit={submit}>
|
|
80
|
+
{#snippet header()}
|
|
81
|
+
{#if webhook}
|
|
82
|
+
<button type="button" class="icon danger" aria-label="Delete Webhook" onclick={() => (failure = ondelete())}>
|
|
83
|
+
<svg viewBox="0 0 24 24" aria-hidden="true"><path d="M4 7h16M10 11v6M14 11v6M6 7l1 13h10l1-13M9 7V4h6v3" /></svg
|
|
84
|
+
>
|
|
85
|
+
</button>
|
|
86
|
+
{:else}
|
|
87
|
+
<span class="icon"></span>
|
|
88
|
+
{/if}
|
|
89
|
+
<h2>{webhook ? webhook.name : 'New Webhook'}</h2>
|
|
90
|
+
<button type="button" class="icon" aria-label="Close" onclick={onclose}>
|
|
91
|
+
<svg viewBox="0 0 24 24" aria-hidden="true"><path d="M6 6l12 12M18 6L6 18" /></svg>
|
|
92
|
+
</button>
|
|
93
|
+
{/snippet}
|
|
94
|
+
|
|
95
|
+
{#if failure}<p class="error" role="alert">{failure}</p>{/if}
|
|
96
|
+
{@render field('name', 'Name', 'Agent')}
|
|
97
|
+
{@render field('url', 'URL', 'https://hooks.example.com/feedback', 'url')}
|
|
98
|
+
{@render field('header', 'Header (optional)', 'Authorization: Bearer key')}
|
|
99
|
+
|
|
100
|
+
<div class="list">
|
|
101
|
+
<label class="toggle">
|
|
102
|
+
<span>Attach JSON</span>
|
|
103
|
+
<input type="checkbox" bind:checked={draft.feedback} />
|
|
104
|
+
</label>
|
|
105
|
+
<label class="toggle">
|
|
106
|
+
<span>Attach image</span>
|
|
107
|
+
<input type="checkbox" bind:checked={draft.image} />
|
|
108
|
+
</label>
|
|
109
|
+
{#if draft.image}
|
|
110
|
+
{@render segments(
|
|
111
|
+
'Image format',
|
|
112
|
+
[
|
|
113
|
+
['png', 'PNG'],
|
|
114
|
+
['jpeg', 'JPEG'],
|
|
115
|
+
],
|
|
116
|
+
draft.format,
|
|
117
|
+
value => (draft.format = value as WebhookDraft['format']),
|
|
118
|
+
)}
|
|
119
|
+
{#if draft.format === 'jpeg'}
|
|
120
|
+
{@render segments(
|
|
121
|
+
'Compression',
|
|
122
|
+
compressions.map(level => [level, level[0]!.toUpperCase() + level.slice(1)]),
|
|
123
|
+
draft.compression,
|
|
124
|
+
value => (draft.compression = value as Compression),
|
|
125
|
+
)}
|
|
126
|
+
{/if}
|
|
127
|
+
{/if}
|
|
128
|
+
</div>
|
|
129
|
+
<p class="note">
|
|
130
|
+
Each post sends {list.format(
|
|
131
|
+
['the title', draft.feedback && 'the feedback JSON', draft.image && 'the image', 'the device JSON'].filter(
|
|
132
|
+
part => typeof part === 'string',
|
|
133
|
+
),
|
|
134
|
+
)}. This browser keeps the webhook, header included, for this site.
|
|
135
|
+
</p>
|
|
136
|
+
<div class="actions">
|
|
137
|
+
<button type="submit" class="primary">{webhook ? 'Send' : 'Save'}</button>
|
|
138
|
+
</div>
|
|
139
|
+
</Sheet>
|
|
140
|
+
|
|
141
|
+
<style>
|
|
142
|
+
.icon {
|
|
143
|
+
display: grid;
|
|
144
|
+
place-items: center;
|
|
145
|
+
width: 32px;
|
|
146
|
+
height: 32px;
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
.icon svg {
|
|
150
|
+
width: 20px;
|
|
151
|
+
height: 20px;
|
|
152
|
+
fill: none;
|
|
153
|
+
stroke: currentColor;
|
|
154
|
+
stroke-width: 2;
|
|
155
|
+
stroke-linecap: round;
|
|
156
|
+
stroke-linejoin: round;
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
.danger {
|
|
160
|
+
color: #ff453a;
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
input[aria-invalid='true'] {
|
|
164
|
+
outline: 1px solid #ff453a;
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
.error {
|
|
168
|
+
margin: 0;
|
|
169
|
+
color: #ff6961;
|
|
170
|
+
font-size: 13px;
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
.list {
|
|
174
|
+
display: grid;
|
|
175
|
+
border-radius: 10px;
|
|
176
|
+
background: #2c2c2e;
|
|
177
|
+
overflow: hidden;
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
.toggle,
|
|
181
|
+
.choice {
|
|
182
|
+
display: flex;
|
|
183
|
+
align-items: center;
|
|
184
|
+
justify-content: space-between;
|
|
185
|
+
gap: 12px;
|
|
186
|
+
border-bottom: 1px solid rgb(255 255 255 / 0.08);
|
|
187
|
+
padding: 11px 12px;
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
.list > :last-child {
|
|
191
|
+
border-bottom: 0;
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
.toggle input {
|
|
195
|
+
width: 20px;
|
|
196
|
+
height: 20px;
|
|
197
|
+
margin: 0;
|
|
198
|
+
accent-color: #0a84ff;
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
.segments {
|
|
202
|
+
display: flex;
|
|
203
|
+
border-radius: 8px;
|
|
204
|
+
padding: 2px;
|
|
205
|
+
background: #1c1c1e;
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
.segments label {
|
|
209
|
+
border-radius: 6px;
|
|
210
|
+
padding: 4px 10px;
|
|
211
|
+
font-size: 14px;
|
|
212
|
+
cursor: pointer;
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
.segments label.picked {
|
|
216
|
+
background: #636366;
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
.segments label:has(:focus-visible) {
|
|
220
|
+
outline: 2px solid #0a84ff;
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
.segments input {
|
|
224
|
+
position: absolute;
|
|
225
|
+
opacity: 0;
|
|
226
|
+
pointer-events: none;
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
.note {
|
|
230
|
+
margin: 0;
|
|
231
|
+
color: #aeaeb2;
|
|
232
|
+
font-size: 13px;
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
.actions {
|
|
236
|
+
display: flex;
|
|
237
|
+
justify-content: flex-end;
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
.primary {
|
|
241
|
+
min-width: 96px;
|
|
242
|
+
border-radius: 12px;
|
|
243
|
+
padding: 10px 20px;
|
|
244
|
+
background: #0a84ff;
|
|
245
|
+
font-weight: 600;
|
|
246
|
+
}
|
|
247
|
+
</style>
|
|
@@ -3,20 +3,19 @@
|
|
|
3
3
|
<script lang="ts">
|
|
4
4
|
import { Problem, taskTitle, type Fact, type FeedbackItem, type Session, type Toast } from '../core/index.ts';
|
|
5
5
|
import type { Screen } from '../dom/capture.ts';
|
|
6
|
-
import {
|
|
7
|
-
import { postId, postWebhook, type Webhook } from '../dom/webhook.ts';
|
|
6
|
+
import { postFiles, postId, postWebhook, type Delivery } from '../dom/webhook.ts';
|
|
8
7
|
import ProblemCard from './ProblemCard.svelte';
|
|
9
8
|
|
|
10
9
|
let {
|
|
11
10
|
screen,
|
|
12
11
|
session,
|
|
13
|
-
|
|
12
|
+
delivery,
|
|
14
13
|
onclose,
|
|
15
14
|
onposted,
|
|
16
15
|
}: {
|
|
17
16
|
screen: Screen;
|
|
18
17
|
session: Session;
|
|
19
|
-
|
|
18
|
+
delivery: Delivery;
|
|
20
19
|
onclose: () => void;
|
|
21
20
|
onposted: (items: FeedbackItem[], toast: Toast) => void;
|
|
22
21
|
} = $props();
|
|
@@ -27,7 +26,7 @@
|
|
|
27
26
|
// svelte-ignore state_referenced_locally
|
|
28
27
|
const title = taskTitle(session.capture, items).placeholder;
|
|
29
28
|
// svelte-ignore state_referenced_locally
|
|
30
|
-
const
|
|
29
|
+
const { webhook, contents } = delivery;
|
|
31
30
|
const id = postId();
|
|
32
31
|
let step = $state('Drawing the image');
|
|
33
32
|
let problem = $state<Problem>();
|
|
@@ -36,15 +35,12 @@
|
|
|
36
35
|
problem = undefined;
|
|
37
36
|
step = 'Drawing the image';
|
|
38
37
|
const started = performance.now();
|
|
39
|
-
const facts: Fact[] = [
|
|
40
|
-
{ label: 'Post', value: id },
|
|
41
|
-
{ label: 'Report', value: `${new TextEncoder().encode(report).length} bytes` },
|
|
42
|
-
];
|
|
38
|
+
const facts: Fact[] = [{ label: 'Post', value: id }];
|
|
43
39
|
try {
|
|
44
|
-
const
|
|
45
|
-
facts.push({ label:
|
|
40
|
+
const files = await postFiles(contents, screen, session.annotations);
|
|
41
|
+
for (const { file } of files) facts.push({ label: file.name, value: `${file.size} bytes` });
|
|
46
42
|
step = `Sending to ${webhook.name}`;
|
|
47
|
-
const link = await postWebhook(webhook, { id, title,
|
|
43
|
+
const link = await postWebhook(webhook, { id, title, files });
|
|
48
44
|
onposted(items, { text: `Sent to ${webhook.name}`, link });
|
|
49
45
|
} catch (error) {
|
|
50
46
|
const elapsed = { label: 'Elapsed', value: `${((performance.now() - started) / 1000).toFixed(1)} s` };
|
|
@@ -1,18 +1,24 @@
|
|
|
1
|
+
import type { SavedWebhook } from '../core/savedWebhooks.ts';
|
|
1
2
|
import type { ProcrastimateConfig } from '../dom/procrastimate.ts';
|
|
2
3
|
import { procrastimateIcon } from '../dom/procrastimate-icon.ts';
|
|
3
|
-
import { githubIcon, type Webhook } from '../dom/webhook.ts';
|
|
4
|
+
import { githubIcon, type Delivery, type Webhook } from '../dom/webhook.ts';
|
|
4
5
|
|
|
5
6
|
/** A server the feedback can be posted to, as the Share menu lists it after the exports. */
|
|
6
7
|
export type Destination = { name: string; image?: string } & (
|
|
7
8
|
| { kind: 'procrastimate' }
|
|
8
|
-
| { kind: 'webhook';
|
|
9
|
+
| { kind: 'webhook'; delivery: Delivery }
|
|
10
|
+
| { kind: 'saved'; saved: SavedWebhook }
|
|
9
11
|
);
|
|
10
12
|
|
|
11
|
-
/**
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
export function destinations(options: {
|
|
13
|
+
/**
|
|
14
|
+
* ProcrastiMate first, then the webhooks with GitHub's icon, then the app's other webhooks in its order, then the ones
|
|
15
|
+
* saved in the editor in the order they were added.
|
|
16
|
+
*/
|
|
17
|
+
export function destinations(options: {
|
|
18
|
+
procrastimate?: ProcrastimateConfig;
|
|
19
|
+
webhooks?: Webhook[];
|
|
20
|
+
saved?: SavedWebhook[];
|
|
21
|
+
}): Destination[] {
|
|
16
22
|
const webhooks = [...(options.webhooks ?? [])].sort(
|
|
17
23
|
(a, b) => Number(b.image === githubIcon) - Number(a.image === githubIcon),
|
|
18
24
|
);
|
|
@@ -20,6 +26,21 @@ export function destinations(options: { procrastimate?: ProcrastimateConfig; web
|
|
|
20
26
|
...(options.procrastimate
|
|
21
27
|
? [{ kind: 'procrastimate' as const, name: 'ProcrastiMate', image: procrastimateIcon }]
|
|
22
28
|
: []),
|
|
23
|
-
...webhooks.map(webhook => ({
|
|
29
|
+
...webhooks.map(webhook => ({
|
|
30
|
+
kind: 'webhook' as const,
|
|
31
|
+
name: webhook.name,
|
|
32
|
+
image: webhook.image,
|
|
33
|
+
delivery: { webhook, contents: { kind: 'report' as const } },
|
|
34
|
+
})),
|
|
35
|
+
...(options.saved ?? []).map(saved => ({ kind: 'saved' as const, name: saved.name, saved })),
|
|
24
36
|
];
|
|
25
37
|
}
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* The destinations that also get a button beside Share: the ones `pinned` names, in its order, or the first two
|
|
41
|
+
* without it. A name with no destination is skipped, since a webhook can join the list after setup.
|
|
42
|
+
*/
|
|
43
|
+
export function pinnedDestinations(all: Destination[], pinned: string[] | undefined): Destination[] {
|
|
44
|
+
if (!pinned) return all.slice(0, 2);
|
|
45
|
+
return pinned.flatMap(name => all.filter(destination => destination.name === name));
|
|
46
|
+
}
|
package/src/editor/engine.ts
CHANGED
|
@@ -33,9 +33,15 @@ export type FeedbackOptions = {
|
|
|
33
33
|
/**
|
|
34
34
|
* Adds one entry to the Share menu per webhook. Choosing it posts the image export and the JSON export to the
|
|
35
35
|
* webhook's `url`, with nothing more to fill in. The menu lists ProcrastiMate, then the webhooks with `githubIcon`,
|
|
36
|
-
* then the others
|
|
36
|
+
* then the others.
|
|
37
37
|
*/
|
|
38
38
|
webhooks?: Webhook[];
|
|
39
|
+
/**
|
|
40
|
+
* The Share menu entries that also get a button beside Share, by name, in this order: `'ProcrastiMate'` or a
|
|
41
|
+
* webhook's `name`. A name the menu does not list is skipped. Without it, the first two of ProcrastiMate and the
|
|
42
|
+
* webhooks get one. `[]` gives none.
|
|
43
|
+
*/
|
|
44
|
+
pinned?: string[];
|
|
39
45
|
};
|
|
40
46
|
|
|
41
47
|
export const defaultShortcut = 'Alt+Meta+Click';
|