@stefan.inc/feedback-engine 1.0.1 → 1.0.2

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 CHANGED
@@ -8,9 +8,9 @@ Alt+Meta+click anything in the browser, click any component on the frozen screen
8
8
 
9
9
  | The editor in the browser | The `feedback.png` it exports |
10
10
  | :---: | :---: |
11
- | <img src="https://raw.githubusercontent.com/smirea/feedback-engine/master/docs/web-editor.png" alt="The Feedback editor in Google Chrome over the React example: the page's screenshot on the left with four notes numbered 1, 2, 3, and 5 and an @4 tag on the New List button, and the panel on the right with the Groceries row, a ListRow, selected and its note, Show a progress bar here." width="320"> | <img src="https://raw.githubusercontent.com/smirea/feedback-engine/master/docs/web-export.png" alt="The feedback.png exported from the browser: the page with four numbered boxes and the New List button tagged @4. Each box links to a card with its note, the component or element, and its file:line, and the app's details sit at the top right. The note on Settings reads Move this next to @4_Button." width="520"> |
11
+ | <img src="https://raw.githubusercontent.com/smirea/feedback-engine/master/docs/web-editor.png" alt="The Feedback editor in Google Chrome over the React example: the page's screenshot on the left with four notes numbered 1 to 4 and an @5 tag on the New List button, and the panel on the right with the Groceries row, a ListRow, selected and its note, Show a progress bar here." width="320"> | <img src="https://raw.githubusercontent.com/smirea/feedback-engine/master/docs/web-export.png" alt="The feedback.png exported from the browser: the page with four numbered boxes and the New List button tagged @5. Each box links to a card with its note, the component or element, and its file:line, and the app's details sit at the top right. The note on Settings reads Move this next to @5_Button." width="520"> |
12
12
 
13
- Four notes on the React example in Google Chrome. The last one points at a second element. Type `@`, click the element, and the note reads `Move this next to @4_Button`. The export draws that element's box and highlights the token in the same color, so an agent knows which button you meant. Each card names its component or element and the `file:line` it comes from, such as `src/components/ListRow.tsx:4`.
13
+ Four notes on the React example in Google Chrome. The last one points at a second element. Type `@`, click the element, and the note reads `Move this next to @5_Button`. The export draws that element's box and highlights the token in the same color, so an agent knows which button you meant. Each card names its component or element and the `file:line` it comes from, such as `src/components/ListRow.tsx:4`.
14
14
 
15
15
  Prefer structured data? Share JSON for the whole component tree, each component's data, and the app context you attached, or both in one ZIP. A [webhook](#webhooks) adds a Share entry that posts both to a server of yours in one click, such as one that files a GitHub issue. [The report format](https://github.com/smirea/feedback-engine/blob/master/spec/report.md) is the same on every platform.
16
16
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@stefan.inc/feedback-engine",
3
- "version": "1.0.1",
3
+ "version": "1.0.2",
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",
@@ -12,12 +12,14 @@ export const tag = (reference: Reference) => `@${reference.number}`;
12
12
  /**
13
13
  * Everything a share exports besides the capture. Items and references share one count: a node takes the next number
14
14
  * and color the first time it is flagged or referenced, and keeps them for the capture, so no two boxes show the same
15
- * number. Removing an item leaves its number unused, since tokens in other texts may still name it.
15
+ * number. A new item that references other nodes holds its number before theirs. Removing an item leaves its number
16
+ * unused, since tokens in other texts may still name it.
16
17
  */
17
18
  export class Annotations {
18
19
  items: FeedbackItem[] = [];
19
20
  references: Reference[] = [];
20
- private marked: number[] = [];
21
+ /** Nodes in the order they took their numbers. `undefined` is the number held for the next new item. */
22
+ private marked: (number | undefined)[] = [];
21
23
 
22
24
  colorIndex(node: number) {
23
25
  const index = this.marked.indexOf(node);
@@ -36,10 +38,17 @@ export class Annotations {
36
38
  item.text = text;
37
39
  } else {
38
40
  this.items.push({ id: crypto.randomUUID(), target, text });
39
- this.mark(target);
41
+ const held = this.marked.indexOf(undefined);
42
+ if (held !== -1 && !this.marked.includes(target)) this.marked[held] = target;
43
+ else this.mark(target);
40
44
  }
41
45
  }
42
46
 
47
+ /** Holds the next number for the new item being written, so the nodes it references number after it. */
48
+ reserve() {
49
+ if (!this.marked.includes(undefined)) this.marked.push(undefined);
50
+ }
51
+
43
52
  remove(id: string) {
44
53
  this.items = this.items.filter(item => item.id !== id);
45
54
  }
@@ -100,6 +100,7 @@ export class Session {
100
100
  insertReference() {
101
101
  const node = this.referenceTarget;
102
102
  if (!node) return;
103
+ if (!this.editing) this.annotations.reserve();
103
104
  this.text = `${this.text.slice(0, -1)}${this.annotations.reference(node).token} `;
104
105
  }
105
106