@immense/vue-pom-generator 1.0.115 → 1.0.117
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 +39 -0
- package/RELEASE_NOTES.md +14 -33
- package/dist/index.cjs +56 -19
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +3 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.mjs +57 -20
- package/dist/index.mjs.map +1 -1
- package/dist/plugin/runtime/annotator/client.d.ts +27 -1
- package/dist/plugin/runtime/annotator/client.d.ts.map +1 -1
- package/dist/plugin/runtime/annotator/format.d.ts +4 -0
- package/dist/plugin/runtime/annotator/format.d.ts.map +1 -1
- package/dist/tests/annotator-submit.test.d.ts +2 -0
- package/dist/tests/annotator-submit.test.d.ts.map +1 -0
- package/dist/transform.d.ts.map +1 -1
- package/dist/wrapper-contract.d.ts +12 -6
- package/dist/wrapper-contract.d.ts.map +1 -1
- package/package.json +1 -1
- package/plugin/runtime/annotator/client.ts +98 -10
- package/plugin/runtime/annotator/format.ts +4 -0
|
@@ -1,10 +1,31 @@
|
|
|
1
|
-
import { type OutputDetail } from "./format";
|
|
1
|
+
import { type FormattedAnnotation, type OutputDetail } from "./format";
|
|
2
2
|
import { type VueDetectorOptions } from "./vue-detector";
|
|
3
3
|
export interface AnnotatorClientOptions extends VueDetectorOptions {
|
|
4
4
|
outputDetail: OutputDetail;
|
|
5
5
|
copyToClipboard: boolean;
|
|
6
6
|
showComponentTree: boolean;
|
|
7
7
|
}
|
|
8
|
+
declare const RUNTIME_GUARD = "__VUE_POM_GENERATOR_ANNOTATOR_RUNTIME__";
|
|
9
|
+
/**
|
|
10
|
+
* Where an app registers a submit handler at runtime. Annotator options are serialized into the
|
|
11
|
+
* injected client, so a function can't be passed through the Vite config.
|
|
12
|
+
*/
|
|
13
|
+
declare const SUBMIT_HOOK = "__VUE_POM_GENERATOR_ANNOTATOR_SUBMIT__";
|
|
14
|
+
/**
|
|
15
|
+
* Receives every queued annotation at once, so feedback that only makes sense together is sent
|
|
16
|
+
* together. Return true only after the submission is accepted: it clears exactly the submitted
|
|
17
|
+
* records that are still unchanged. Any other return (false, undefined) or a throw retains the
|
|
18
|
+
* queue with visible feedback.
|
|
19
|
+
*/
|
|
20
|
+
export type AnnotatorSubmitHandler = (annotations: FormattedAnnotation[], context: {
|
|
21
|
+
pageUrl: string;
|
|
22
|
+
}) => boolean | Promise<boolean>;
|
|
23
|
+
declare global {
|
|
24
|
+
interface Window {
|
|
25
|
+
[RUNTIME_GUARD]?: AnnotatorRuntime;
|
|
26
|
+
[SUBMIT_HOOK]?: AnnotatorSubmitHandler;
|
|
27
|
+
}
|
|
28
|
+
}
|
|
8
29
|
/**
|
|
9
30
|
* The primary side of a Floating UI placement token (e.g. `"top"` from
|
|
10
31
|
* `"top-start"`). Used to derive the static side opposite the arrow. This
|
|
@@ -36,6 +57,7 @@ declare class AnnotatorRuntime {
|
|
|
36
57
|
private currentPanelEl;
|
|
37
58
|
private toastTimer;
|
|
38
59
|
private toolbarPosition;
|
|
60
|
+
private submitting;
|
|
39
61
|
constructor(options: AnnotatorClientOptions);
|
|
40
62
|
mount(): void;
|
|
41
63
|
private ensureStyles;
|
|
@@ -70,10 +92,14 @@ declare class AnnotatorRuntime {
|
|
|
70
92
|
private closePanel;
|
|
71
93
|
private clearAnnotations;
|
|
72
94
|
private copyAnnotations;
|
|
95
|
+
/** Re-renders the toolbar, for example after an app registers or removes a submit handler. */
|
|
96
|
+
refresh(): void;
|
|
97
|
+
private submitAnnotations;
|
|
73
98
|
private showToast;
|
|
74
99
|
}
|
|
75
100
|
export declare function mountAnnotatorClient(options: AnnotatorClientOptions): AnnotatorRuntime;
|
|
76
101
|
export declare const __internal: {
|
|
102
|
+
annotationsStorageKey: string;
|
|
77
103
|
placementPrimarySide: typeof placementPrimarySide;
|
|
78
104
|
};
|
|
79
105
|
export {};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../../../../plugin/runtime/annotator/client.ts"],"names":[],"mappings":"AAEA,OAAO,
|
|
1
|
+
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../../../../plugin/runtime/annotator/client.ts"],"names":[],"mappings":"AAEA,OAAO,EAAoD,KAAK,mBAAmB,EAAE,KAAK,YAAY,EAAE,MAAM,UAAU,CAAC;AAGzH,OAAO,EAA2B,KAAK,kBAAkB,EAAE,MAAM,gBAAgB,CAAC;AAElF,MAAM,WAAW,sBAAuB,SAAQ,kBAAkB;IAChE,YAAY,EAAE,YAAY,CAAC;IAC3B,eAAe,EAAE,OAAO,CAAC;IACzB,iBAAiB,EAAE,OAAO,CAAC;CAC5B;AAiBD,QAAA,MAAM,aAAa,4CAA4C,CAAC;AAChE;;;GAGG;AACH,QAAA,MAAM,WAAW,2CAA2C,CAAC;AAE7D;;;;;GAKG;AACH,MAAM,MAAM,sBAAsB,GAAG,CACnC,WAAW,EAAE,mBAAmB,EAAE,EAClC,OAAO,EAAE;IAAE,OAAO,EAAE,MAAM,CAAA;CAAE,KACzB,OAAO,GAAG,OAAO,CAAC,OAAO,CAAC,CAAC;AAEhC,OAAO,CAAC,MAAM,CAAC;IACb,UAAU,MAAM;QACd,CAAC,aAAa,CAAC,CAAC,EAAE,gBAAgB,CAAC;QACnC,CAAC,WAAW,CAAC,CAAC,EAAE,sBAAsB,CAAC;KACxC;CACF;AAoGD;;;;;;;;GAQG;AACH,iBAAS,oBAAoB,CAAC,SAAS,EAAE,MAAM,GAAG,MAAM,CAIvD;AAmGD,cAAM,gBAAgB;IACpB,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAyB;IACjD,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAoB;IAC7C,OAAO,CAAC,WAAW,CAA0B;IAC7C,OAAO,CAAC,cAAc,CAAwB;IAC9C,OAAO,CAAC,WAAW,CAAS;IAC5B,OAAO,CAAC,iBAAiB,CAAiC;IAC1D,OAAO,CAAC,mBAAmB,CAAu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AAC,mBAAmB;IAO3B,OAAO,CAAC,SAAS;IAqBjB,OAAO,CAAC,UAAU;IAMlB,OAAO,CAAC,gBAAgB;YAUV,eAAe;IAgB7B,8FAA8F;IAC9F,OAAO;YAIO,iBAAiB;IA2C/B,OAAO,CAAC,SAAS;CAmBlB;AAED,wBAAgB,oBAAoB,CAAC,OAAO,EAAE,sBAAsB,oBASnE;AAGD,eAAO,MAAM,UAAU;;;CAGtB,CAAC"}
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
export type OutputDetail = "standard" | "forensic";
|
|
2
2
|
export interface FormattedAnnotation {
|
|
3
|
+
/** Stable runtime id of the queued annotation; same id on retries, changed content keeps the id. */
|
|
4
|
+
id?: string;
|
|
3
5
|
comment: string;
|
|
4
6
|
targetLabel: string;
|
|
5
7
|
source?: string;
|
|
@@ -7,6 +9,8 @@ export interface FormattedAnnotation {
|
|
|
7
9
|
uiText?: string;
|
|
8
10
|
locator?: string;
|
|
9
11
|
domHint?: string;
|
|
12
|
+
/** Page URL where the annotation was captured (recorded at creation time, survives SPA route changes). */
|
|
13
|
+
pageUrl?: string;
|
|
10
14
|
}
|
|
11
15
|
export declare function formatAnnotations(annotations: FormattedAnnotation[], detail: OutputDetail, pageUrl: string): string;
|
|
12
16
|
export declare function formatSingleAnnotationPreview(annotation: FormattedAnnotation, detail: OutputDetail, pageUrl: string): string;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"format.d.ts","sourceRoot":"","sources":["../../../../plugin/runtime/annotator/format.ts"],"names":[],"mappings":"AAEA,MAAM,MAAM,YAAY,GAAG,UAAU,GAAG,UAAU,CAAC;AAEnD,MAAM,WAAW,mBAAmB;IAClC,OAAO,EAAE,MAAM,CAAC;IAChB,WAAW,EAAE,MAAM,CAAC;IACpB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB;AAED,wBAAgB,iBAAiB,CAC/B,WAAW,EAAE,mBAAmB,EAAE,EAClC,MAAM,EAAE,YAAY,EACpB,OAAO,EAAE,MAAM,GACd,MAAM,CA8CR;AAED,wBAAgB,6BAA6B,CAC3C,UAAU,EAAE,mBAAmB,EAC/B,MAAM,EAAE,YAAY,EACpB,OAAO,EAAE,MAAM,GACd,MAAM,CAOR"}
|
|
1
|
+
{"version":3,"file":"format.d.ts","sourceRoot":"","sources":["../../../../plugin/runtime/annotator/format.ts"],"names":[],"mappings":"AAEA,MAAM,MAAM,YAAY,GAAG,UAAU,GAAG,UAAU,CAAC;AAEnD,MAAM,WAAW,mBAAmB;IAClC,oGAAoG;IACpG,EAAE,CAAC,EAAE,MAAM,CAAC;IACZ,OAAO,EAAE,MAAM,CAAC;IAChB,WAAW,EAAE,MAAM,CAAC;IACpB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,0GAA0G;IAC1G,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB;AAED,wBAAgB,iBAAiB,CAC/B,WAAW,EAAE,mBAAmB,EAAE,EAClC,MAAM,EAAE,YAAY,EACpB,OAAO,EAAE,MAAM,GACd,MAAM,CA8CR;AAED,wBAAgB,6BAA6B,CAC3C,UAAU,EAAE,mBAAmB,EAC/B,MAAM,EAAE,YAAY,EACpB,OAAO,EAAE,MAAM,GACd,MAAM,CAOR"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"annotator-submit.test.d.ts","sourceRoot":"","sources":["../../tests/annotator-submit.test.ts"],"names":[],"mappings":""}
|
package/dist/transform.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"transform.d.ts","sourceRoot":"","sources":["../transform.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,WAAW,EACX,aAAa,EAUd,MAAM,oBAAoB,CAAC;AAC5B,OAAO,KAAK,EAAE,cAAc,EAA4B,YAAY,EAAmB,MAAM,SAAS,CAAC;AASvG,OAAO,EACL,oBAAoB,
|
|
1
|
+
{"version":3,"file":"transform.d.ts","sourceRoot":"","sources":["../transform.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,WAAW,EACX,aAAa,EAUd,MAAM,oBAAoB,CAAC;AAC5B,OAAO,KAAK,EAAE,cAAc,EAA4B,YAAY,EAAmB,MAAM,SAAS,CAAC;AASvG,OAAO,EACL,oBAAoB,EAGpB,2BAA2B,EAC3B,0BAA0B,EAC1B,oBAAoB,EAEpB,cAAc,EACf,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EAgCL,sBAAsB,EACtB,iBAAiB,EACjB,UAAU,EAUuC,MAAM,SAAS,CAAC;AAkJnE,iBAAS,wBAAwB,CAAC,OAAO,EAAE,WAAW,GAAG,UAAU,GAAG,IAAI,CAEzE;AA0BD;;;;;GAKG;AAEH,iBAAS,yBAAyB,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI,GAAG,MAAM,GAAG,IAAI,CAOtE;AAGD,iBAAS,gBAAgB,CAAC,SAAS,EAAE,WAAW,GAAG,MAAM,GAAG,IAAI,CAyB/D;AAED,iBAAS,sBAAsB,CAAC,OAAO,EAAE,WAAW,EAAE,YAAY,EAAE,YAAY,GAAG,MAAM,GAAG,IAAI,CAoC/F;AAED,iBAAS,qBAAqB,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAcpD;AAED,iBAAS,2BAA2B,CAAC,OAAO,EAAE,WAAW,GAAG;IAAE,IAAI,EAAE,IAAI,GAAG,SAAS,GAAG,MAAM,CAAC;IAAC,MAAM,EAAE,MAAM,CAAA;CAAE,GAAG,IAAI,CAiCrH;AAED,iBAAS,mDAAmD,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BACO,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,uBACjB,MAAM,EAAE;;;;;;;CAa/B,CAAC"}
|
|
@@ -7,12 +7,10 @@ export interface WrapperContract {
|
|
|
7
7
|
targetRoles: Array<NativeRole | null>;
|
|
8
8
|
/** Template-relative start offsets of elements that receive the configured test-id. */
|
|
9
9
|
forwardedTestIdTargetOffsets: ReadonlySet<number>;
|
|
10
|
-
/**
|
|
11
|
-
|
|
12
|
-
/**
|
|
13
|
-
|
|
14
|
-
/** SFC-source-relative equivalents for explicit forwarding targets. */
|
|
15
|
-
explicitlyForwardedTestIdTargetSfcOffsets: ReadonlySet<number>;
|
|
10
|
+
/** Script names that hold the component's fallthrough attributes (`$attrs`, `const attrs = useAttrs()`). */
|
|
11
|
+
attrsObjectNames: ReadonlySet<string>;
|
|
12
|
+
/** Script functions that return the component's fallthrough attributes. */
|
|
13
|
+
attrsFunctionNames: ReadonlySet<string>;
|
|
16
14
|
}
|
|
17
15
|
export interface AnalyzeWrapperContractFromSfcOptions {
|
|
18
16
|
filePath: string;
|
|
@@ -31,6 +29,14 @@ export declare function normalizeWrapperSearchRoots(wrapperSearchRoots: string[]
|
|
|
31
29
|
export declare function buildVueSfcPathIndex(searchRoots: string[]): Map<string, string[]>;
|
|
32
30
|
export declare function resolveSfcPathForTag(tag: string, vueFilesPathMap?: Map<string, string>, wrapperSearchRoots?: string[]): string | null;
|
|
33
31
|
export declare function getElementControlRole(element: ElementNode): NativeRole | null;
|
|
32
|
+
/**
|
|
33
|
+
* Whether `element` receives the caller's test id through an explicit binding such as
|
|
34
|
+
* `v-bind="$attrs"`, given the component's `$attrs` aliases (a `WrapperContract` carries them).
|
|
35
|
+
* It inspects the element itself rather than its source offset, so it still holds when another
|
|
36
|
+
* Vite plugin has rewritten the template before compilation (for example vite-plugin-vue-inspector
|
|
37
|
+
* adding `data-v-inspector` attributes).
|
|
38
|
+
*/
|
|
39
|
+
export declare function elementExplicitlyForwardsTestId(element: ElementNode, testIdAttribute: string, scriptMetadata: Pick<WrapperContract, "attrsObjectNames" | "attrsFunctionNames">): boolean;
|
|
34
40
|
export declare function analyzeWrapperContractFromSfc(options: AnalyzeWrapperContractFromSfcOptions): WrapperContract;
|
|
35
41
|
export declare function resolveWrapperContractForTag(options: ResolveWrapperContractForTagOptions): WrapperContract | null;
|
|
36
42
|
export declare function resetWrapperContractCaches(): void;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"wrapper-contract.d.ts","sourceRoot":"","sources":["../wrapper-contract.ts"],"names":[],"mappings":"AAYA,OAAO,KAAK,EAGV,WAAW,EAGZ,MAAM,oBAAoB,CAAC;AAC5B,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AAwC1C,MAAM,WAAW,eAAe;IAC9B,mGAAmG;IACnG,IAAI,EAAE,UAAU,GAAG,IAAI,CAAC;IACxB,sFAAsF;IACtF,WAAW,EAAE,KAAK,CAAC,UAAU,GAAG,IAAI,CAAC,CAAC;IACtC,uFAAuF;IACvF,4BAA4B,EAAE,WAAW,CAAC,MAAM,CAAC,CAAC;IAClD,
|
|
1
|
+
{"version":3,"file":"wrapper-contract.d.ts","sourceRoot":"","sources":["../wrapper-contract.ts"],"names":[],"mappings":"AAYA,OAAO,KAAK,EAGV,WAAW,EAGZ,MAAM,oBAAoB,CAAC;AAC5B,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AAwC1C,MAAM,WAAW,eAAe;IAC9B,mGAAmG;IACnG,IAAI,EAAE,UAAU,GAAG,IAAI,CAAC;IACxB,sFAAsF;IACtF,WAAW,EAAE,KAAK,CAAC,UAAU,GAAG,IAAI,CAAC,CAAC;IACtC,uFAAuF;IACvF,4BAA4B,EAAE,WAAW,CAAC,MAAM,CAAC,CAAC;IAClD,4GAA4G;IAC5G,gBAAgB,EAAE,WAAW,CAAC,MAAM,CAAC,CAAC;IACtC,2EAA2E;IAC3E,kBAAkB,EAAE,WAAW,CAAC,MAAM,CA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AG,IAAI,CAyCjH;AAED,wBAAgB,0BAA0B,IAAI,IAAI,CAGjD"}
|
package/package.json
CHANGED
|
@@ -27,10 +27,29 @@ const SETTINGS_STORAGE_KEY = "vpg-annotator-settings";
|
|
|
27
27
|
const ANNOTATIONS_STORAGE_KEY = "vpg-annotator-annotations";
|
|
28
28
|
const TOOLBAR_POSITION_STORAGE_KEY = "vpg-annotator-toolbar-position";
|
|
29
29
|
const RUNTIME_GUARD = "__VUE_POM_GENERATOR_ANNOTATOR_RUNTIME__";
|
|
30
|
+
/**
|
|
31
|
+
* Where an app registers a submit handler at runtime. Annotator options are serialized into the
|
|
32
|
+
* injected client, so a function can't be passed through the Vite config.
|
|
33
|
+
*/
|
|
34
|
+
const SUBMIT_HOOK = "__VUE_POM_GENERATOR_ANNOTATOR_SUBMIT__";
|
|
30
35
|
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
36
|
+
/**
|
|
37
|
+
* Receives every queued annotation at once, so feedback that only makes sense together is sent
|
|
38
|
+
* together. Return true only after the submission is accepted: it clears exactly the submitted
|
|
39
|
+
* records that are still unchanged. Any other return (false, undefined) or a throw retains the
|
|
40
|
+
* queue with visible feedback.
|
|
41
|
+
*/
|
|
42
|
+
export type AnnotatorSubmitHandler = (
|
|
43
|
+
annotations: FormattedAnnotation[],
|
|
44
|
+
context: { pageUrl: string },
|
|
45
|
+
) => boolean | Promise<boolean>;
|
|
46
|
+
|
|
47
|
+
declare global {
|
|
48
|
+
interface Window {
|
|
49
|
+
[RUNTIME_GUARD]?: AnnotatorRuntime;
|
|
50
|
+
[SUBMIT_HOOK]?: AnnotatorSubmitHandler;
|
|
51
|
+
}
|
|
52
|
+
}
|
|
34
53
|
|
|
35
54
|
interface ToolbarPosition {
|
|
36
55
|
left: number;
|
|
@@ -43,13 +62,14 @@ interface ButtonOptions {
|
|
|
43
62
|
disabled?: boolean;
|
|
44
63
|
}
|
|
45
64
|
|
|
46
|
-
type ToolbarIconName = "drag" | "inspect" | "preview" | "copy" | "clear" | "settings";
|
|
65
|
+
type ToolbarIconName = "drag" | "inspect" | "preview" | "copy" | "submit" | "clear" | "settings";
|
|
47
66
|
|
|
48
67
|
const TOOLBAR_ICON_MARKUP: Record<ToolbarIconName, string> = {
|
|
49
68
|
drag: '<svg viewBox="0 0 16 16"><path d="M5 3h1v1H5zM10 3h1v1h-1zM5 7h1v1H5zM10 7h1v1h-1zM5 11h1v1H5zM10 11h1v1h-1z" fill="currentColor" stroke="none" /></svg>',
|
|
50
69
|
inspect: '<svg viewBox="0 0 16 16"><circle cx="8" cy="8" r="4.5"/><path d="M8 1v2.5M8 12.5v2.5M1 8h2.5M12.5 8h2.5"/><circle cx="8" cy="8" r="0.9" fill="currentColor" stroke="none"/></svg>',
|
|
51
70
|
preview: '<svg viewBox="0 0 16 16"><path d="M1.5 8s2.4-4 6.5-4 6.5 4 6.5 4-2.4 4-6.5 4-6.5-4-6.5-4Z"/><circle cx="8" cy="8" r="1.8"/></svg>',
|
|
52
71
|
copy: '<svg viewBox="0 0 16 16"><path d="M6 2.5h6.5v9H6z"/><path d="M3.5 5.5H5v6.5h5.5v1.5h-7z"/></svg>',
|
|
72
|
+
submit: '<svg viewBox="0 0 16 16"><path d="M14 2 2 7.5l5 1.5 1.5 5z"/><path d="M14 2 7 9"/></svg>',
|
|
53
73
|
clear: '<svg viewBox="0 0 16 16"><path d="M2.5 4.5h11"/><path d="M6 2.5h4"/><path d="M5 4.5v8"/><path d="M8 4.5v8"/><path d="M11 4.5v8"/><path d="M4 4.5h8l-.6 9H4.6z"/></svg>',
|
|
54
74
|
settings: '<svg viewBox="0 0 16 16"><path d="M8 2.2l1 .6 1.2-.2.8 1 .9.7-.3 1.2.5 1-.5 1 .3 1.2-.9.7-.8 1-1.2-.2-1 .6-1-.6-1.2.2-.8-1-.9-.7.3-1.2-.5-1 .5-1-.3-1.2.9-.7.8-1 1.2.2z"/><circle cx="8" cy="8" r="2.2"/></svg>',
|
|
55
75
|
};
|
|
@@ -230,6 +250,17 @@ async function copyTextToClipboard(text: string) {
|
|
|
230
250
|
}
|
|
231
251
|
}
|
|
232
252
|
|
|
253
|
+
function annotationMatchesSubmitted(submitted: FormattedAnnotation, current: FormattedAnnotation): boolean {
|
|
254
|
+
return submitted.comment === current.comment
|
|
255
|
+
&& submitted.targetLabel === current.targetLabel
|
|
256
|
+
&& submitted.source === current.source
|
|
257
|
+
&& submitted.component === current.component
|
|
258
|
+
&& submitted.uiText === current.uiText
|
|
259
|
+
&& submitted.locator === current.locator
|
|
260
|
+
&& submitted.domHint === current.domHint
|
|
261
|
+
&& submitted.pageUrl === current.pageUrl;
|
|
262
|
+
}
|
|
263
|
+
|
|
233
264
|
class AnnotatorRuntime {
|
|
234
265
|
private readonly options: AnnotatorClientOptions;
|
|
235
266
|
private readonly settings: AnnotatorSettings;
|
|
@@ -251,6 +282,7 @@ class AnnotatorRuntime {
|
|
|
251
282
|
private currentPanelEl: HTMLElement | null = null;
|
|
252
283
|
private toastTimer: number | null = null;
|
|
253
284
|
private toolbarPosition: ToolbarPosition | null = null;
|
|
285
|
+
private submitting = false;
|
|
254
286
|
|
|
255
287
|
constructor(options: AnnotatorClientOptions) {
|
|
256
288
|
this.options = options;
|
|
@@ -332,6 +364,13 @@ class AnnotatorRuntime {
|
|
|
332
364
|
disabled: this.annotations.length === 0,
|
|
333
365
|
});
|
|
334
366
|
|
|
367
|
+
// Only when the app has registered a handler; otherwise Copy is the way out.
|
|
368
|
+
const submitButton = typeof window[SUBMIT_HOOK] === "function"
|
|
369
|
+
? createIconButton("Submit annotations", "submit", () => void this.submitAnnotations(), {
|
|
370
|
+
disabled: this.submitting || this.annotations.length === 0,
|
|
371
|
+
})
|
|
372
|
+
: null;
|
|
373
|
+
|
|
335
374
|
const clearButton = createIconButton("Clear annotations", "clear", () => this.clearAnnotations(), {
|
|
336
375
|
disabled: this.annotations.length === 0,
|
|
337
376
|
});
|
|
@@ -339,7 +378,7 @@ class AnnotatorRuntime {
|
|
|
339
378
|
const settingsButton = createIconButton("Annotator settings", "settings", () => this.openSettings());
|
|
340
379
|
this.settingsButton = settingsButton;
|
|
341
380
|
|
|
342
|
-
this.toolbarEl.append(handle, selectButton, previewButton, copyButton, clearButton, settingsButton, count);
|
|
381
|
+
this.toolbarEl.append(handle, selectButton, previewButton, copyButton, ...(submitButton ? [submitButton] : []), clearButton, settingsButton, count);
|
|
343
382
|
this.applyToolbarPosition();
|
|
344
383
|
}
|
|
345
384
|
|
|
@@ -602,6 +641,7 @@ class AnnotatorRuntime {
|
|
|
602
641
|
uiText: getNearbyText(element),
|
|
603
642
|
locator: getNearbyLocator(element),
|
|
604
643
|
domHint: getElementPath(element),
|
|
644
|
+
pageUrl: window.location.href,
|
|
605
645
|
pageX: rect.left + rect.width / 2,
|
|
606
646
|
pageY: rect.top + window.scrollY,
|
|
607
647
|
};
|
|
@@ -868,6 +908,54 @@ class AnnotatorRuntime {
|
|
|
868
908
|
}
|
|
869
909
|
}
|
|
870
910
|
|
|
911
|
+
/** Re-renders the toolbar, for example after an app registers or removes a submit handler. */
|
|
912
|
+
refresh() {
|
|
913
|
+
this.renderToolbar();
|
|
914
|
+
}
|
|
915
|
+
|
|
916
|
+
private async submitAnnotations() {
|
|
917
|
+
if (this.submitting || !this.annotations.length) {
|
|
918
|
+
return;
|
|
919
|
+
}
|
|
920
|
+
const handler = window[SUBMIT_HOOK];
|
|
921
|
+
if (typeof handler !== "function") {
|
|
922
|
+
return;
|
|
923
|
+
}
|
|
924
|
+
|
|
925
|
+
this.submitting = true;
|
|
926
|
+
this.renderToolbar();
|
|
927
|
+
// Snapshot the queue so annotations added while the handler runs are not cleared with it, and
|
|
928
|
+
// keep a copy of the exact submitted content: retry sends the same records, and a record is
|
|
929
|
+
// only cleared if its id AND content still match the snapshot.
|
|
930
|
+
const batch = [...this.annotations];
|
|
931
|
+
const submitted = new Map(batch.map(annotation => [annotation.id, { ...annotation }]));
|
|
932
|
+
try {
|
|
933
|
+
const accepted = await handler(batch, { pageUrl: window.location.href });
|
|
934
|
+
// Strict: only an explicit true is a successful submit. Anything else — false, undefined
|
|
935
|
+
// from an untyped caller, or a throw — retains the queue with visible feedback.
|
|
936
|
+
if (accepted !== true) {
|
|
937
|
+
this.showToast("Submit failed");
|
|
938
|
+
return;
|
|
939
|
+
}
|
|
940
|
+
// Keep new drafts and drafts edited (or mutated) after the snapshot; id + content decide.
|
|
941
|
+
this.annotations = this.annotations.filter((annotation) => {
|
|
942
|
+
const snapshot = submitted.get(annotation.id);
|
|
943
|
+
return snapshot === undefined || !annotationMatchesSubmitted(snapshot, annotation);
|
|
944
|
+
});
|
|
945
|
+
this.saveAnnotations();
|
|
946
|
+
this.closePanel();
|
|
947
|
+
this.showToast("Submitted");
|
|
948
|
+
}
|
|
949
|
+
catch (error) {
|
|
950
|
+
console.error("[vue-pom-generator] Annotator submit handler failed", error);
|
|
951
|
+
this.showToast("Submit failed");
|
|
952
|
+
}
|
|
953
|
+
finally {
|
|
954
|
+
this.submitting = false;
|
|
955
|
+
this.renderToolbar();
|
|
956
|
+
}
|
|
957
|
+
}
|
|
958
|
+
|
|
871
959
|
private showToast(message: string) {
|
|
872
960
|
this.toastEl?.remove();
|
|
873
961
|
if (this.toastTimer !== null) {
|
|
@@ -890,18 +978,18 @@ class AnnotatorRuntime {
|
|
|
890
978
|
}
|
|
891
979
|
|
|
892
980
|
export function mountAnnotatorClient(options: AnnotatorClientOptions) {
|
|
893
|
-
|
|
894
|
-
|
|
895
|
-
return runtimeWindow[RUNTIME_GUARD]!;
|
|
981
|
+
if (window[RUNTIME_GUARD]) {
|
|
982
|
+
return window[RUNTIME_GUARD]!;
|
|
896
983
|
}
|
|
897
984
|
|
|
898
985
|
const runtime = new AnnotatorRuntime(options);
|
|
899
986
|
runtime.mount();
|
|
900
|
-
|
|
987
|
+
window[RUNTIME_GUARD] = runtime;
|
|
901
988
|
return runtime;
|
|
902
989
|
}
|
|
903
990
|
|
|
904
|
-
//
|
|
991
|
+
// Test-only values and pure helpers (no DOM access).
|
|
905
992
|
export const __internal = {
|
|
993
|
+
annotationsStorageKey: ANNOTATIONS_STORAGE_KEY,
|
|
906
994
|
placementPrimarySide,
|
|
907
995
|
};
|
|
@@ -3,6 +3,8 @@ import { normalizeInlineText } from "./text-utils";
|
|
|
3
3
|
export type OutputDetail = "standard" | "forensic";
|
|
4
4
|
|
|
5
5
|
export interface FormattedAnnotation {
|
|
6
|
+
/** Stable runtime id of the queued annotation; same id on retries, changed content keeps the id. */
|
|
7
|
+
id?: string;
|
|
6
8
|
comment: string;
|
|
7
9
|
targetLabel: string;
|
|
8
10
|
source?: string;
|
|
@@ -10,6 +12,8 @@ export interface FormattedAnnotation {
|
|
|
10
12
|
uiText?: string;
|
|
11
13
|
locator?: string;
|
|
12
14
|
domHint?: string;
|
|
15
|
+
/** Page URL where the annotation was captured (recorded at creation time, survives SPA route changes). */
|
|
16
|
+
pageUrl?: string;
|
|
13
17
|
}
|
|
14
18
|
|
|
15
19
|
export function formatAnnotations(
|