@stefan.inc/feedback-engine 1.7.2 → 1.8.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 +2 -0
- package/package.json +1 -1
- package/src/dom/procrastimate.ts +38 -1
- package/src/editor/ProcrastimateSheet.svelte +70 -34
- package/src/editor/setup.ts +5 -1
- package/src/react/public.d.ts +5 -0
- package/src/vite/index.d.ts +5 -0
- package/src/vite/index.js +5 -1
package/README.md
CHANGED
|
@@ -241,6 +241,8 @@ export default defineConfig({
|
|
|
241
241
|
The token is the switch. With `PROCRASTIMATE_TOKEN` set, **ProcrastiMate** shows in the Share menu, with the same picker and task as on iOS. Without it, the entry is not there, and nothing else changes. `setupFeedbackEngine()` needs no option for either case.
|
|
242
242
|
|
|
243
243
|
- The token is a ProcrastiMate personal token, from Settings › Personal token. An AI account's token lists the projects but cannot upload the image, so the post fails with `Not for AI accounts`. `feedbackProcrastimate({ url })` names another ProcrastiMate server.
|
|
244
|
+
- `feedbackProcrastimate({ projects: ['Feedback Engine', 'Website'] })` lists the only projects the picker offers, by name (ignoring case) or id, in that order, so feedback cannot land anywhere else. The Inbox is not offered then, and the picker opens on the last of them posted to, or the first. A listed name ProcrastiMate does not have shows as an error above the list.
|
|
245
|
+
- Each project in the picker has a ↗ link to its page in ProcrastiMate, which opens in a new tab for someone signed in to its space.
|
|
244
246
|
- `feedbackProcrastimate({ project })` names the project the picker opens on, by name (ignoring case) or id, so an app's feedback lands in its own project. Without it, the picker opens on the last project posted to. A name ProcrastiMate does not have shows as an error above the list.
|
|
245
247
|
- The proxy runs in `vite dev` and `vite preview`. A build reads the token too. Build a site you deploy without it, because a static host has no proxy.
|
|
246
248
|
- For a proxy of your own, pass its address to the page instead: `setupFeedbackEngine({ procrastimate: { url: '/my-proxy' } })`.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@stefan.inc/feedback-engine",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.8.0",
|
|
4
4
|
"description": "In-app feedback for Svelte and React: point at a component, write what should change, and export its name, file:line, and data for an agent.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"accessibility",
|
package/src/dom/procrastimate.ts
CHANGED
|
@@ -9,6 +9,11 @@ export type ProcrastimateConfig = {
|
|
|
9
9
|
app?: string;
|
|
10
10
|
/** The project the picker opens on, by name (ignoring case) or id, in place of the last one posted to. */
|
|
11
11
|
project?: string;
|
|
12
|
+
/**
|
|
13
|
+
* The only projects the picker offers, by name (ignoring case) or id, in this order. The Inbox is not offered with
|
|
14
|
+
* it. Without it, the picker lists the Inbox and every project.
|
|
15
|
+
*/
|
|
16
|
+
projects?: string[];
|
|
12
17
|
};
|
|
13
18
|
|
|
14
19
|
export type Section = { id: string; name: string };
|
|
@@ -51,8 +56,40 @@ export const namedProject = (projects: Project[], name: string) =>
|
|
|
51
56
|
projects.find(project => project.id === name) ??
|
|
52
57
|
projects.find(project => project.name.toLowerCase() === name.toLowerCase());
|
|
53
58
|
|
|
59
|
+
/**
|
|
60
|
+
* The projects the picker lists: every one, or only those `names` lists, in its order. `missing` has the names
|
|
61
|
+
* ProcrastiMate does not have.
|
|
62
|
+
*/
|
|
63
|
+
export function listedProjects(all: Project[], names: string[] | undefined) {
|
|
64
|
+
if (!names) return { projects: all, missing: [] as string[] };
|
|
65
|
+
const projects: Project[] = [];
|
|
66
|
+
const missing: string[] = [];
|
|
67
|
+
for (const name of names) {
|
|
68
|
+
const project = namedProject(all, name);
|
|
69
|
+
if (!project) missing.push(name);
|
|
70
|
+
else if (!projects.includes(project)) projects.push(project);
|
|
71
|
+
}
|
|
72
|
+
return { projects, missing };
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
/**
|
|
76
|
+
* The project the picker opens on, among the listed ones: the one the app names, else the last one posted to, else
|
|
77
|
+
* the first when the app lists its projects, as the Inbox is not offered then. `undefined` is the Inbox.
|
|
78
|
+
*/
|
|
79
|
+
export function startingProject(listed: Project[], config: ProcrastimateConfig, last: string | undefined) {
|
|
80
|
+
if (config.project) return namedProject(listed, config.project)?.id;
|
|
81
|
+
if (listed.some(project => project.id === last)) return last;
|
|
82
|
+
return config.projects ? listed[0]?.id : undefined;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
const appURL = (config: ProcrastimateConfig) => (config.app ?? defaultApp).replace(/\/$/, '');
|
|
86
|
+
|
|
87
|
+
/** The project's page in the ProcrastiMate web app, which opens for someone signed in to its space. */
|
|
88
|
+
export const projectLink = (config: ProcrastimateConfig, id: string) =>
|
|
89
|
+
`${appURL(config)}/projects/${encodeURIComponent(id)}`;
|
|
90
|
+
|
|
54
91
|
export const taskLink = (config: ProcrastimateConfig, id: string) =>
|
|
55
|
-
`${(config
|
|
92
|
+
`${appURL(config)}/inbox?task=${encodeURIComponent(id)}`;
|
|
56
93
|
|
|
57
94
|
async function send(
|
|
58
95
|
config: ProcrastimateConfig,
|
|
@@ -7,9 +7,11 @@
|
|
|
7
7
|
import {
|
|
8
8
|
cachedProjects,
|
|
9
9
|
lastProject,
|
|
10
|
+
listedProjects,
|
|
10
11
|
loadProjects,
|
|
11
|
-
namedProject,
|
|
12
12
|
postTask,
|
|
13
|
+
projectLink,
|
|
14
|
+
startingProject,
|
|
13
15
|
taskLink,
|
|
14
16
|
type Place,
|
|
15
17
|
type ProcrastimateConfig,
|
|
@@ -34,11 +36,12 @@
|
|
|
34
36
|
// svelte-ignore state_referenced_locally
|
|
35
37
|
const names = taskTitle(session.capture, session.items);
|
|
36
38
|
let name = $state(names.placeholder);
|
|
37
|
-
let
|
|
39
|
+
let all = $state(cachedProjects());
|
|
40
|
+
const projects = $derived(listedProjects(all, config.projects).projects);
|
|
38
41
|
// svelte-ignore state_referenced_locally
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
});
|
|
42
|
+
const inbox = !config.projects;
|
|
43
|
+
// svelte-ignore state_referenced_locally
|
|
44
|
+
let place = $state<Place>({ projectId: startingProject(projects, config, lastProject()) });
|
|
42
45
|
let loading = $state(true);
|
|
43
46
|
/** Whether the user chose a place, which a project list that finishes loading must not undo. */
|
|
44
47
|
let chosen = false;
|
|
@@ -47,8 +50,8 @@
|
|
|
47
50
|
/** What the post is doing, while it runs. */
|
|
48
51
|
let step = $state<string>();
|
|
49
52
|
const posting = $derived(step !== undefined);
|
|
50
|
-
/**
|
|
51
|
-
const unresolved = $derived(loading && !!config.project
|
|
53
|
+
/** Without a project, a post would land in the Inbox, which a project the app named or listed rules out. */
|
|
54
|
+
const unresolved = $derived(!place.projectId && (!inbox || (loading && !!config.project)));
|
|
52
55
|
let status = $state<HTMLElement>();
|
|
53
56
|
// svelte-ignore state_referenced_locally
|
|
54
57
|
const environment: Fact[] = session.capture.environment.map(entry => ({ label: entry.name, value: entry.value }));
|
|
@@ -56,15 +59,23 @@
|
|
|
56
59
|
$effect(() => {
|
|
57
60
|
loadProjects(config)
|
|
58
61
|
.then(loaded => {
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
const project = loaded.find(candidate => candidate.id === place.projectId);
|
|
66
|
-
if (!project) place = {};
|
|
62
|
+
all = loaded;
|
|
63
|
+
const listed = listedProjects(loaded, config.projects);
|
|
64
|
+
if (!chosen) place = { projectId: startingProject(listed.projects, config, lastProject()) };
|
|
65
|
+
const project = listed.projects.find(candidate => candidate.id === place.projectId);
|
|
66
|
+
if (!project)
|
|
67
|
+
place = { projectId: startingProject(listed.projects, { ...config, project: undefined }, undefined) };
|
|
67
68
|
else if (!project.sections.some(section => section.id === place.sectionId)) place = { projectId: project.id };
|
|
69
|
+
const missing = [...listed.missing];
|
|
70
|
+
if (config.project && !startingProject(listed.projects, config, undefined)) missing.push(config.project);
|
|
71
|
+
if (missing.length) {
|
|
72
|
+
const names = [...new Set(missing)].map(name => `"${name}"`).join(', ');
|
|
73
|
+
throw new Error(
|
|
74
|
+
config.projects
|
|
75
|
+
? `ProcrastiMate has no project named ${names} among the projects Feedback was set up with`
|
|
76
|
+
: `ProcrastiMate has no project named ${names}`,
|
|
77
|
+
);
|
|
78
|
+
}
|
|
68
79
|
})
|
|
69
80
|
.catch(
|
|
70
81
|
(error: unknown) =>
|
|
@@ -113,22 +124,32 @@
|
|
|
113
124
|
});
|
|
114
125
|
</script>
|
|
115
126
|
|
|
116
|
-
{#snippet row(label: string, picked: boolean, indented: boolean, pick: () => void)}
|
|
117
|
-
<
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
127
|
+
{#snippet row(label: string, picked: boolean, indented: boolean, pick: () => void, link?: string)}
|
|
128
|
+
<div class="row" class:indented>
|
|
129
|
+
<button
|
|
130
|
+
type="button"
|
|
131
|
+
role="option"
|
|
132
|
+
aria-selected={picked}
|
|
133
|
+
disabled={posting}
|
|
134
|
+
onclick={() => {
|
|
135
|
+
chosen = true;
|
|
136
|
+
pick();
|
|
137
|
+
}}
|
|
138
|
+
>
|
|
139
|
+
<span>{label}</span>
|
|
140
|
+
{#if picked}<span class="check" aria-hidden="true">✓</span>{/if}
|
|
141
|
+
</button>
|
|
142
|
+
{#if link}
|
|
143
|
+
<a
|
|
144
|
+
class="open"
|
|
145
|
+
href={link}
|
|
146
|
+
target="_blank"
|
|
147
|
+
rel="noopener"
|
|
148
|
+
aria-label="Open {label} in ProcrastiMate"
|
|
149
|
+
title="Open in ProcrastiMate">↗</a
|
|
150
|
+
>
|
|
151
|
+
{/if}
|
|
152
|
+
</div>
|
|
132
153
|
{/snippet}
|
|
133
154
|
|
|
134
155
|
<Sheet label="Add to ProcrastiMate" onsubmit={() => void post()}>
|
|
@@ -151,7 +172,7 @@
|
|
|
151
172
|
</label>
|
|
152
173
|
<span class="caption">Project{loading ? ' · loading…' : ''}</span>
|
|
153
174
|
<div class="list" role="listbox" aria-label="Project">
|
|
154
|
-
{@render row('Inbox', !place.projectId, false, () => (place = {}))}
|
|
175
|
+
{#if inbox}{@render row('Inbox', !place.projectId, false, () => (place = {}))}{/if}
|
|
155
176
|
{#each projects as project (project.id)}
|
|
156
177
|
{@const open = project.id === place.projectId && project.sections.length > 0}
|
|
157
178
|
{@render row(
|
|
@@ -159,6 +180,7 @@
|
|
|
159
180
|
project.id === place.projectId && !open,
|
|
160
181
|
false,
|
|
161
182
|
() => (place = { projectId: project.id }),
|
|
183
|
+
projectLink(config, project.id),
|
|
162
184
|
)}
|
|
163
185
|
{#if open}
|
|
164
186
|
{@render row('No section', !place.sectionId, true, () => (place = { projectId: project.id }))}
|
|
@@ -189,17 +211,31 @@
|
|
|
189
211
|
|
|
190
212
|
.row {
|
|
191
213
|
display: flex;
|
|
214
|
+
border-bottom: 1px solid rgb(255 255 255 / 0.08);
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
.row > button {
|
|
218
|
+
display: flex;
|
|
219
|
+
flex: 1;
|
|
192
220
|
justify-content: space-between;
|
|
193
221
|
gap: 8px;
|
|
194
|
-
border-bottom: 1px solid rgb(255 255 255 / 0.08);
|
|
195
222
|
padding: 11px 12px;
|
|
196
223
|
text-align: left;
|
|
197
224
|
}
|
|
198
225
|
|
|
199
|
-
.row.indented {
|
|
226
|
+
.row.indented > button {
|
|
200
227
|
padding-left: 40px;
|
|
201
228
|
}
|
|
202
229
|
|
|
230
|
+
.open {
|
|
231
|
+
display: grid;
|
|
232
|
+
place-items: center;
|
|
233
|
+
width: 44px;
|
|
234
|
+
border-left: 1px solid rgb(255 255 255 / 0.08);
|
|
235
|
+
color: #0a84ff;
|
|
236
|
+
text-decoration: none;
|
|
237
|
+
}
|
|
238
|
+
|
|
203
239
|
.check {
|
|
204
240
|
color: #0a84ff;
|
|
205
241
|
font-weight: 700;
|
package/src/editor/setup.ts
CHANGED
|
@@ -60,9 +60,13 @@ export function setupFeedbackEngine(options: FeedbackOptions = {}): FeedbackEngi
|
|
|
60
60
|
type Meta = { env?: Record<string, string | undefined> };
|
|
61
61
|
const proxy = (import.meta as Meta).env && (import.meta as Meta).env!.FEEDBACK_PROCRASTIMATE;
|
|
62
62
|
const project = (import.meta as Meta).env && (import.meta as Meta).env!.FEEDBACK_PROCRASTIMATE_PROJECT;
|
|
63
|
+
const projects = (import.meta as Meta).env && (import.meta as Meta).env!.FEEDBACK_PROCRASTIMATE_PROJECTS;
|
|
64
|
+
const listed = projects ? (JSON.parse(projects) as string[]) : [];
|
|
63
65
|
const engine = new Engine({
|
|
64
66
|
...options,
|
|
65
|
-
procrastimate:
|
|
67
|
+
procrastimate:
|
|
68
|
+
options.procrastimate ??
|
|
69
|
+
(proxy ? { url: proxy, project: project || undefined, projects: listed.length ? listed : undefined } : undefined),
|
|
66
70
|
});
|
|
67
71
|
const host = document.createElement('div');
|
|
68
72
|
host.setAttribute(hostAttribute, '');
|
package/src/react/public.d.ts
CHANGED
|
@@ -36,6 +36,11 @@ export type FeedbackOptions = {
|
|
|
36
36
|
app?: string;
|
|
37
37
|
/** The project the picker opens on, by name (ignoring case) or id, in place of the last one posted to. */
|
|
38
38
|
project?: string;
|
|
39
|
+
/**
|
|
40
|
+
* The only projects the picker offers, by name (ignoring case) or id, in this order. The Inbox is not offered
|
|
41
|
+
* with it. Without it, the picker lists the Inbox and every project.
|
|
42
|
+
*/
|
|
43
|
+
projects?: string[];
|
|
39
44
|
};
|
|
40
45
|
/**
|
|
41
46
|
* Adds one entry to the Share menu per webhook. Choosing it posts the image export and the JSON export to the
|
package/src/vite/index.d.ts
CHANGED
|
@@ -25,6 +25,11 @@ export function feedbackProcrastimate(options?: {
|
|
|
25
25
|
path?: string;
|
|
26
26
|
/** The project the picker opens on, by name (ignoring case) or id, in place of the last one posted to. */
|
|
27
27
|
project?: string;
|
|
28
|
+
/**
|
|
29
|
+
* The only projects the picker offers, by name (ignoring case) or id, in this order, each with a link to its page
|
|
30
|
+
* in ProcrastiMate. The Inbox is not offered with it. Without it, the picker lists the Inbox and every project.
|
|
31
|
+
*/
|
|
32
|
+
projects?: string[];
|
|
28
33
|
}): Plugin;
|
|
29
34
|
|
|
30
35
|
/**
|
package/src/vite/index.js
CHANGED
|
@@ -8,6 +8,7 @@ const entry = '@stefan.inc/feedback-engine/svelte';
|
|
|
8
8
|
/** What `setupFeedbackEngine()` reads for the proxy's path. `editor/setup.ts` spells the same name. */
|
|
9
9
|
const procrastimateDefine = 'import.meta.env.FEEDBACK_PROCRASTIMATE';
|
|
10
10
|
const procrastimateProjectDefine = 'import.meta.env.FEEDBACK_PROCRASTIMATE_PROJECT';
|
|
11
|
+
const procrastimateProjectsDefine = 'import.meta.env.FEEDBACK_PROCRASTIMATE_PROJECTS';
|
|
11
12
|
|
|
12
13
|
/**
|
|
13
14
|
* The name a tag gets without one: the file's, as `.feedback(self)` uses the type's on iOS. A SvelteKit route file is
|
|
@@ -156,9 +157,11 @@ export function feedbackEngine(options = {}) {
|
|
|
156
157
|
* ProcrastiMate. Without one the page is told nothing, so the entry is not there. A page that names the path itself
|
|
157
158
|
* then gets a 501 that says why.
|
|
158
159
|
*
|
|
159
|
-
* @param {{ url?: string, token?: string, path?: string, project?: string }} [options]
|
|
160
|
+
* @param {{ url?: string, token?: string, path?: string, project?: string, projects?: string[] }} [options]
|
|
160
161
|
*/
|
|
161
162
|
export function feedbackProcrastimate(options = {}) {
|
|
163
|
+
if (options.projects && !options.projects.length)
|
|
164
|
+
throw new Error('feedbackProcrastimate({ projects }) lists no projects. Leave it out to offer every project.');
|
|
162
165
|
const path = options.path ?? '/__feedback/procrastimate';
|
|
163
166
|
const target = (options.url ?? 'https://procrastimate.stf.lol').replace(/\/$/, '');
|
|
164
167
|
/** @type {import('vite').Connect.NextHandleFunction} */
|
|
@@ -198,6 +201,7 @@ export function feedbackProcrastimate(options = {}) {
|
|
|
198
201
|
define: {
|
|
199
202
|
[procrastimateDefine]: JSON.stringify(options.token ? path : ''),
|
|
200
203
|
[procrastimateProjectDefine]: JSON.stringify(options.project ?? ''),
|
|
204
|
+
[procrastimateProjectsDefine]: JSON.stringify(JSON.stringify(options.projects ?? [])),
|
|
201
205
|
},
|
|
202
206
|
};
|
|
203
207
|
},
|