@immense/vue-pom-generator 1.0.107 → 1.0.109
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/RELEASE_NOTES.md +28 -67
- package/class-generation/index.ts +99 -150
- package/dist/class-generation/index.d.ts +3 -0
- package/dist/class-generation/index.d.ts.map +1 -1
- package/dist/index.cjs +228 -314
- package/dist/index.cjs.map +1 -1
- package/dist/index.mjs +230 -316
- package/dist/index.mjs.map +1 -1
- package/dist/manifest-generator.d.ts +2 -1
- package/dist/manifest-generator.d.ts.map +1 -1
- package/dist/plugin/generated-outputs.d.ts.map +1 -1
- package/dist/plugin/internal/dev-plugin.d.ts.map +1 -1
- package/dist/plugin/runtime/annotator/client.d.ts +1 -1
- package/dist/plugin/runtime/annotator/client.d.ts.map +1 -1
- package/dist/plugin/runtime/annotator/styles.d.ts +1 -1
- package/dist/plugin/runtime/annotator/styles.d.ts.map +1 -1
- package/dist/tests/annotator-keyboard.test.d.ts +2 -0
- package/dist/tests/annotator-keyboard.test.d.ts.map +1 -0
- package/dist/tests/annotator-preview.test.d.ts +2 -0
- package/dist/tests/annotator-preview.test.d.ts.map +1 -0
- package/dist/tests/incremental-generation.test.d.ts +2 -0
- package/dist/tests/incremental-generation.test.d.ts.map +1 -0
- package/dist/typescript-codegen.d.ts +14 -1
- package/dist/typescript-codegen.d.ts.map +1 -1
- package/dist/utils.d.ts.map +1 -1
- package/package.json +1 -1
- package/plugin/runtime/annotator/client.ts +23 -137
- package/plugin/runtime/annotator/styles.ts +43 -26
package/dist/index.cjs
CHANGED
|
@@ -295,6 +295,58 @@ function applyNuxtDiscoveryToInjectionOptions(options, discovery) {
|
|
|
295
295
|
wrapperSearchRoots: discovery.wrapperSearchRoots
|
|
296
296
|
};
|
|
297
297
|
}
|
|
298
|
+
class TypeScriptRenderCache {
|
|
299
|
+
entries = /* @__PURE__ */ new Map();
|
|
300
|
+
render(filePath, input, build) {
|
|
301
|
+
const previous = this.entries.get(filePath);
|
|
302
|
+
if (previous?.input === input) return previous.content;
|
|
303
|
+
const content = build();
|
|
304
|
+
this.entries.set(filePath, { input, content });
|
|
305
|
+
return content;
|
|
306
|
+
}
|
|
307
|
+
retain(filePaths) {
|
|
308
|
+
for (const filePath of this.entries.keys()) {
|
|
309
|
+
if (!filePaths.has(filePath)) this.entries.delete(filePath);
|
|
310
|
+
}
|
|
311
|
+
}
|
|
312
|
+
}
|
|
313
|
+
function createClassDeclaration(declaration, members) {
|
|
314
|
+
const result = { ...declaration, kind: tsMorph.StructureKind.Class };
|
|
315
|
+
for (const member of members) {
|
|
316
|
+
switch (member.kind) {
|
|
317
|
+
case tsMorph.StructureKind.Constructor:
|
|
318
|
+
(result.ctors ??= []).push(member);
|
|
319
|
+
break;
|
|
320
|
+
case tsMorph.StructureKind.GetAccessor:
|
|
321
|
+
(result.getAccessors ??= []).push(member);
|
|
322
|
+
break;
|
|
323
|
+
case tsMorph.StructureKind.Method:
|
|
324
|
+
(result.methods ??= []).push(member);
|
|
325
|
+
break;
|
|
326
|
+
case tsMorph.StructureKind.Property:
|
|
327
|
+
(result.properties ??= []).push(member);
|
|
328
|
+
break;
|
|
329
|
+
default:
|
|
330
|
+
throw new Error(`Unsupported class member kind: ${String(member.kind)}`);
|
|
331
|
+
}
|
|
332
|
+
}
|
|
333
|
+
return result;
|
|
334
|
+
}
|
|
335
|
+
function renderStructuredSourceFile(filePath, structure, options = {}) {
|
|
336
|
+
const build = () => {
|
|
337
|
+
const project = createTypeScriptProject();
|
|
338
|
+
const sourceFile = project.createSourceFile(filePath, structure);
|
|
339
|
+
return ensureTrailingNewline(`${options.prefixText ?? ""}${sourceFile.getFullText()}`);
|
|
340
|
+
};
|
|
341
|
+
if (!options.cache) return build();
|
|
342
|
+
const input = JSON.stringify([options.prefixText, structure], (_key, value) => {
|
|
343
|
+
if (typeof value !== "function") return value;
|
|
344
|
+
const writer = createTypeScriptWriter();
|
|
345
|
+
value(writer);
|
|
346
|
+
return writer.toString();
|
|
347
|
+
});
|
|
348
|
+
return options.cache.render(filePath, input, build);
|
|
349
|
+
}
|
|
298
350
|
function createTypeScriptProject() {
|
|
299
351
|
return new tsMorph.Project({
|
|
300
352
|
useInMemoryFileSystem: true,
|
|
@@ -359,9 +411,6 @@ function addNamedImport(sourceFile, options) {
|
|
|
359
411
|
namedImports: options.namedImports
|
|
360
412
|
});
|
|
361
413
|
}
|
|
362
|
-
function addExportAll(sourceFile, moduleSpecifier) {
|
|
363
|
-
return sourceFile.addExportDeclaration({ moduleSpecifier });
|
|
364
|
-
}
|
|
365
414
|
function createClassMethod(method) {
|
|
366
415
|
return {
|
|
367
416
|
kind: tsMorph.StructureKind.Method,
|
|
@@ -1458,23 +1507,11 @@ function getSlotScopeVariablesUsedAsBareCallbackHandlers(templateNode) {
|
|
|
1458
1507
|
const vFor = node.props.find(
|
|
1459
1508
|
(prop) => prop.type === compilerCore.NodeTypes.DIRECTIVE && prop.name === "for"
|
|
1460
1509
|
);
|
|
1461
|
-
if (vFor?.
|
|
1462
|
-
const
|
|
1463
|
-
|
|
1464
|
-
|
|
1465
|
-
|
|
1466
|
-
if (aliasSource) {
|
|
1467
|
-
try {
|
|
1468
|
-
const aliasAst = parser.parseExpression(aliasSource, { plugins: ["typescript"] });
|
|
1469
|
-
if (types.isSequenceExpression(aliasAst)) {
|
|
1470
|
-
for (const part of aliasAst.expressions) {
|
|
1471
|
-
names.push(...collectBindingPatternNames(part));
|
|
1472
|
-
}
|
|
1473
|
-
} else {
|
|
1474
|
-
names.push(...collectBindingPatternNames(aliasAst));
|
|
1475
|
-
}
|
|
1476
|
-
} catch {
|
|
1477
|
-
}
|
|
1510
|
+
if (vFor?.forParseResult) {
|
|
1511
|
+
const { value, key, index } = vFor.forParseResult;
|
|
1512
|
+
for (const alias of [value, key, index]) {
|
|
1513
|
+
if (alias) {
|
|
1514
|
+
names.push(...collectBindingPatternNames(tryGetTemplateSlotScopeBindingNode(alias)));
|
|
1478
1515
|
}
|
|
1479
1516
|
}
|
|
1480
1517
|
}
|
|
@@ -1644,10 +1681,6 @@ function tryGetTemplateSlotScopeBindingNode(expression) {
|
|
|
1644
1681
|
if (!rawSource) {
|
|
1645
1682
|
return null;
|
|
1646
1683
|
}
|
|
1647
|
-
try {
|
|
1648
|
-
return parser.parseExpression(rawSource, { plugins: ["typescript"] });
|
|
1649
|
-
} catch {
|
|
1650
|
-
}
|
|
1651
1684
|
try {
|
|
1652
1685
|
const parsed = parser.parse(`(${rawSource}) => {}`, {
|
|
1653
1686
|
sourceType: "module",
|
|
@@ -4008,29 +4041,30 @@ function generateTestIdsModule(componentHierarchyMap, elementMetadata) {
|
|
|
4008
4041
|
});
|
|
4009
4042
|
});
|
|
4010
4043
|
}
|
|
4011
|
-
function generatePomManifestModule(componentHierarchyMap, elementMetadata, fileName = "virtual-pom-manifest.ts") {
|
|
4044
|
+
function generatePomManifestModule(componentHierarchyMap, elementMetadata, fileName = "virtual-pom-manifest.ts", renderCache) {
|
|
4012
4045
|
const pomManifest = buildPomManifest(componentHierarchyMap, elementMetadata);
|
|
4013
|
-
return
|
|
4014
|
-
|
|
4015
|
-
|
|
4046
|
+
return renderStructuredSourceFile(fileName, {
|
|
4047
|
+
statements: [{
|
|
4048
|
+
kind: tsMorph.StructureKind.VariableStatement,
|
|
4049
|
+
leadingTrivia: "// Rich POM discoverability manifest.\n",
|
|
4016
4050
|
declarationKind: tsMorph.VariableDeclarationKind.Const,
|
|
4017
4051
|
isExported: true,
|
|
4018
4052
|
declarations: [{
|
|
4019
4053
|
name: "pomManifest",
|
|
4020
4054
|
initializer: writeConstJson(pomManifest)
|
|
4021
4055
|
}]
|
|
4022
|
-
}
|
|
4023
|
-
|
|
4056
|
+
}, {
|
|
4057
|
+
kind: tsMorph.StructureKind.TypeAlias,
|
|
4024
4058
|
isExported: true,
|
|
4025
4059
|
name: "PomManifest",
|
|
4026
4060
|
type: "typeof pomManifest"
|
|
4027
|
-
}
|
|
4028
|
-
|
|
4061
|
+
}, {
|
|
4062
|
+
kind: tsMorph.StructureKind.TypeAlias,
|
|
4029
4063
|
isExported: true,
|
|
4030
4064
|
name: "PomManifestComponentName",
|
|
4031
4065
|
type: "keyof PomManifest"
|
|
4032
|
-
}
|
|
4033
|
-
});
|
|
4066
|
+
}]
|
|
4067
|
+
}, { cache: renderCache });
|
|
4034
4068
|
}
|
|
4035
4069
|
const manifestName = ".vue-pom-generator-outputs.json";
|
|
4036
4070
|
function hash(content) {
|
|
@@ -4079,6 +4113,7 @@ function assertNoSymlinkParents(filePath, outDir, projectRoot) {
|
|
|
4079
4113
|
}
|
|
4080
4114
|
}
|
|
4081
4115
|
function writeFile(filePath, content) {
|
|
4116
|
+
if (fs.existsSync(filePath) && fs.readFileSync(filePath, "utf8") === content) return;
|
|
4082
4117
|
fs.mkdirSync(path.dirname(filePath), { recursive: true });
|
|
4083
4118
|
const temporaryPath = `${filePath}.${node_crypto.randomUUID()}.tmp`;
|
|
4084
4119
|
try {
|
|
@@ -5909,7 +5944,8 @@ async function generateFiles(componentHierarchyMap, vueFilesPathMap, basePageCla
|
|
|
5909
5944
|
componentDirs,
|
|
5910
5945
|
layoutDirs,
|
|
5911
5946
|
routeMetaByComponent: routeMetaByComponentOverride,
|
|
5912
|
-
elementMetadata = /* @__PURE__ */ new Map()
|
|
5947
|
+
elementMetadata = /* @__PURE__ */ new Map(),
|
|
5948
|
+
renderCache
|
|
5913
5949
|
} = options;
|
|
5914
5950
|
const emitLanguages = emitLanguagesOverride?.length ? emitLanguagesOverride : ["ts"];
|
|
5915
5951
|
const root = projectRoot ?? process.cwd();
|
|
@@ -5927,6 +5963,7 @@ async function generateFiles(componentHierarchyMap, vueFilesPathMap, basePageCla
|
|
|
5927
5963
|
const generatedFiles = [];
|
|
5928
5964
|
if (emitLanguages.includes("ts")) {
|
|
5929
5965
|
const files = typescriptOutputStructure === "split" ? await generateSplitTypeScriptFiles(emittableComponentHierarchyMap, vueFilesPathMap, basePageClassPath, outDir, {
|
|
5966
|
+
renderCache,
|
|
5930
5967
|
customPomAttachments,
|
|
5931
5968
|
projectRoot,
|
|
5932
5969
|
customPomDir,
|
|
@@ -5937,6 +5974,7 @@ async function generateFiles(componentHierarchyMap, vueFilesPathMap, basePageCla
|
|
|
5937
5974
|
routeMetaByComponent,
|
|
5938
5975
|
vueRouterFluentChaining
|
|
5939
5976
|
}) : await generateAggregatedFiles(emittableComponentHierarchyMap, vueFilesPathMap, basePageClassPath, outDir, {
|
|
5977
|
+
renderCache,
|
|
5940
5978
|
customPomAttachments,
|
|
5941
5979
|
projectRoot,
|
|
5942
5980
|
customPomDir,
|
|
@@ -5949,6 +5987,7 @@ async function generateFiles(componentHierarchyMap, vueFilesPathMap, basePageCla
|
|
|
5949
5987
|
});
|
|
5950
5988
|
generatedFiles.push(...files);
|
|
5951
5989
|
const fixtureRegistryFiles = maybeGenerateFixtureRegistry(emittableComponentHierarchyMap, {
|
|
5990
|
+
renderCache,
|
|
5952
5991
|
generateFixtures,
|
|
5953
5992
|
pomOutDir: outDir,
|
|
5954
5993
|
projectRoot,
|
|
@@ -5969,12 +6008,13 @@ async function generateFiles(componentHierarchyMap, vueFilesPathMap, basePageCla
|
|
|
5969
6008
|
const vueTestUtilsFiles = generateVueTestUtilsFiles(
|
|
5970
6009
|
emittableComponentHierarchyMap,
|
|
5971
6010
|
vueTestUtilsOutDir,
|
|
5972
|
-
{ testIdAttribute }
|
|
6011
|
+
{ testIdAttribute, renderCache }
|
|
5973
6012
|
);
|
|
5974
6013
|
generatedFiles.push(...vueTestUtilsFiles);
|
|
5975
6014
|
}
|
|
5976
6015
|
const gitattributesFiles = buildGeneratedGitAttributesFiles(generatedFiles.map((file) => file.filePath));
|
|
5977
6016
|
writeGeneratedOutputs(outDir, generatedFiles, gitattributesFiles, path.resolve(root));
|
|
6017
|
+
renderCache?.retain(new Set(generatedFiles.map((file) => file.filePath)));
|
|
5978
6018
|
}
|
|
5979
6019
|
const VUE_TEST_UTILS_OMITTED_PARAMETERS = /* @__PURE__ */ new Set(["annotationText", "timeOut", "timeout", "wait"]);
|
|
5980
6020
|
function getVueTestUtilsParameters(parameters, patterns, options = {}) {
|
|
@@ -6102,7 +6142,7 @@ function getVueTestUtilsComponentMembers(componentInstances, projectedComponentI
|
|
|
6102
6142
|
}));
|
|
6103
6143
|
return members;
|
|
6104
6144
|
}
|
|
6105
|
-
function generateVueTestUtilsContent(componentName, dependencies, componentHierarchyMap, outputDir, runtimePath, generatedFilePathByComponent, testIdAttribute) {
|
|
6145
|
+
function generateVueTestUtilsContent(componentName, dependencies, componentHierarchyMap, outputDir, runtimePath, generatedFilePathByComponent, testIdAttribute, renderCache) {
|
|
6106
6146
|
const prepared = prepareViewObjectModelClass(componentName, dependencies, componentHierarchyMap, {
|
|
6107
6147
|
testIdAttribute
|
|
6108
6148
|
});
|
|
@@ -6122,33 +6162,29 @@ function generateVueTestUtilsContent(componentName, dependencies, componentHiera
|
|
|
6122
6162
|
...getUniquePrimaryPomSpecs(dependencies).flatMap(({ pom }) => getVueTestUtilsPrimaryMembers(pom)),
|
|
6123
6163
|
...(dependencies.pomExtraMethods ?? []).flatMap(getVueTestUtilsExtraMembers)
|
|
6124
6164
|
];
|
|
6125
|
-
return
|
|
6126
|
-
|
|
6165
|
+
return renderStructuredSourceFile(path.join(outputDir, `${componentName}.vtu.g.ts`), {
|
|
6166
|
+
statements: [{
|
|
6167
|
+
kind: tsMorph.StructureKind.ImportDeclaration,
|
|
6127
6168
|
moduleSpecifier: runtimeImport,
|
|
6128
6169
|
namedImports: ["VueTestUtilsPom"]
|
|
6129
|
-
}
|
|
6130
|
-
|
|
6170
|
+
}, {
|
|
6171
|
+
kind: tsMorph.StructureKind.ImportDeclaration,
|
|
6131
6172
|
moduleSpecifier: runtimeImport,
|
|
6132
6173
|
namedImports: ["VueTestUtilsPomRoot"],
|
|
6133
6174
|
isTypeOnly: true
|
|
6134
|
-
})
|
|
6135
|
-
|
|
6136
|
-
|
|
6137
|
-
|
|
6138
|
-
|
|
6139
|
-
});
|
|
6140
|
-
}
|
|
6141
|
-
const declaration = sourceFile.addClass({
|
|
6175
|
+
}, ...componentImports.map((componentImport) => ({
|
|
6176
|
+
kind: tsMorph.StructureKind.ImportDeclaration,
|
|
6177
|
+
moduleSpecifier: componentImport.moduleSpecifier,
|
|
6178
|
+
namedImports: [componentImport.className]
|
|
6179
|
+
})), createClassDeclaration({
|
|
6142
6180
|
name: prepared.className,
|
|
6143
6181
|
isExported: true,
|
|
6144
6182
|
extends: "VueTestUtilsPom",
|
|
6145
6183
|
docs: [`Vue Test Utils object for ${componentName} (source: ${sourceRel}).`]
|
|
6146
|
-
})
|
|
6147
|
-
for (const member of members) {
|
|
6148
|
-
addClassMember(declaration, member);
|
|
6149
|
-
}
|
|
6184
|
+
}, members)]
|
|
6150
6185
|
}, {
|
|
6151
|
-
prefixText: buildFilePrefix({ eslintDisableSortImports: true })
|
|
6186
|
+
prefixText: buildFilePrefix({ eslintDisableSortImports: true }),
|
|
6187
|
+
cache: renderCache
|
|
6152
6188
|
});
|
|
6153
6189
|
}
|
|
6154
6190
|
function generateVueTestUtilsFiles(componentHierarchyMap, outDir, options = {}) {
|
|
@@ -6170,7 +6206,8 @@ function generateVueTestUtilsFiles(componentHierarchyMap, outDir, options = {})
|
|
|
6170
6206
|
path.dirname(filePath),
|
|
6171
6207
|
runtimePath,
|
|
6172
6208
|
generatedFilePathByComponent,
|
|
6173
|
-
testIdAttribute
|
|
6209
|
+
testIdAttribute,
|
|
6210
|
+
options.renderCache
|
|
6174
6211
|
)
|
|
6175
6212
|
};
|
|
6176
6213
|
});
|
|
@@ -6182,12 +6219,13 @@ function generateVueTestUtilsFiles(componentHierarchyMap, outDir, options = {})
|
|
|
6182
6219
|
if (!runtimeFile) {
|
|
6183
6220
|
throw new Error("[vue-pom-generator] Failed to generate the Vue Test Utils runtime.");
|
|
6184
6221
|
}
|
|
6185
|
-
const indexContent =
|
|
6186
|
-
|
|
6187
|
-
|
|
6188
|
-
|
|
6189
|
-
}
|
|
6222
|
+
const indexContent = renderStructuredSourceFile(path.join(base, "index.ts"), {
|
|
6223
|
+
statements: [
|
|
6224
|
+
stripExtension(toPosixRelativePath(base, runtimePath)),
|
|
6225
|
+
...Array.from(generatedFilePathByComponent.values(), (filePath) => `./${stripExtension(path.basename(filePath))}`)
|
|
6226
|
+
].map((moduleSpecifier) => ({ kind: tsMorph.StructureKind.ExportDeclaration, moduleSpecifier }))
|
|
6190
6227
|
}, {
|
|
6228
|
+
cache: options.renderCache,
|
|
6191
6229
|
prefixText: buildFilePrefix({
|
|
6192
6230
|
eslintDisableSortImports: true,
|
|
6193
6231
|
commentLines: [
|
|
@@ -6241,6 +6279,7 @@ async function generateSplitTypeScriptFiles(componentHierarchyMap, vueFilesPathM
|
|
|
6241
6279
|
continue;
|
|
6242
6280
|
}
|
|
6243
6281
|
const content = generateViewObjectModelContent(name, deps, componentHierarchyMap, vueFilesPathMap, runtimeBasePagePath, {
|
|
6282
|
+
renderCache: options.renderCache,
|
|
6244
6283
|
outputDir: path.dirname(filePath),
|
|
6245
6284
|
customPomAttachments: options.customPomAttachments ?? [],
|
|
6246
6285
|
projectRoot,
|
|
@@ -6268,6 +6307,8 @@ async function generateSplitTypeScriptFiles(componentHierarchyMap, vueFilesPathM
|
|
|
6268
6307
|
const childImports = getChildImportSpecifiers(outputDir, composed?.childClassNames ?? [], generatedTsFilePathByComponent);
|
|
6269
6308
|
const members = composed?.members ?? getDefaultStubMembers();
|
|
6270
6309
|
const content = renderSplitStubPomContent({
|
|
6310
|
+
filePath,
|
|
6311
|
+
renderCache: options.renderCache,
|
|
6271
6312
|
className: targetClassName,
|
|
6272
6313
|
basePageImportSpecifier,
|
|
6273
6314
|
childImports,
|
|
@@ -6277,14 +6318,13 @@ async function generateSplitTypeScriptFiles(componentHierarchyMap, vueFilesPathM
|
|
|
6277
6318
|
}
|
|
6278
6319
|
const runtimeAssetSpecs = getRuntimeGeneratedAssetSpecs(base, basePageClassPath);
|
|
6279
6320
|
const runtimeFiles = buildRuntimeGeneratedFilesFromSpecs(runtimeAssetSpecs);
|
|
6280
|
-
const indexContent =
|
|
6281
|
-
|
|
6282
|
-
|
|
6283
|
-
|
|
6284
|
-
|
|
6285
|
-
addExportAll(sourceFile, `./${stripExtension(path.basename(filePath))}`);
|
|
6286
|
-
}
|
|
6321
|
+
const indexContent = renderStructuredSourceFile(path.join(base, "index.ts"), {
|
|
6322
|
+
statements: [
|
|
6323
|
+
...runtimeAssetSpecs.map((spec) => stripExtension(toPosixRelativePath(base, spec.outputPath))),
|
|
6324
|
+
...Array.from(generatedTsFilePathByComponent.entries()).sort((a, b) => a[0].localeCompare(b[0])).map(([, filePath]) => `./${stripExtension(path.basename(filePath))}`)
|
|
6325
|
+
].map((moduleSpecifier) => ({ kind: tsMorph.StructureKind.ExportDeclaration, moduleSpecifier }))
|
|
6287
6326
|
}, {
|
|
6327
|
+
cache: options.renderCache,
|
|
6288
6328
|
prefixText: buildFilePrefix({
|
|
6289
6329
|
eslintDisableSortImports: true,
|
|
6290
6330
|
commentLines: [
|
|
@@ -6960,7 +7000,8 @@ function maybeGenerateFixtureRegistry(componentHierarchyMap, options) {
|
|
|
6960
7000
|
const manifestContent = generatePomManifestModule(
|
|
6961
7001
|
componentHierarchyMap,
|
|
6962
7002
|
options.elementMetadata,
|
|
6963
|
-
manifestFileName
|
|
7003
|
+
path.resolve(fixtureOutDirAbs, manifestFileName),
|
|
7004
|
+
options.renderCache
|
|
6964
7005
|
);
|
|
6965
7006
|
const [diagnosticsRuntimeFile] = buildRuntimeGeneratedFilesFromSpecs([{
|
|
6966
7007
|
absolutePath: resolvePluginAsset("../class-generation/diagnostics.ts"),
|
|
@@ -7308,40 +7349,33 @@ function generateViewObjectModelContent(componentName, dependencies, componentHi
|
|
|
7308
7349
|
generatedImports.sort((a, b) => a.className.localeCompare(b.className));
|
|
7309
7350
|
const prefixText = `${buildFilePrefix({ eslintDisableSortImports: true })}${doc}
|
|
7310
7351
|
`;
|
|
7311
|
-
return
|
|
7312
|
-
|
|
7352
|
+
return renderStructuredSourceFile(path.join(outputDir, `${componentName}.g.ts`), {
|
|
7353
|
+
statements: [{
|
|
7354
|
+
kind: tsMorph.StructureKind.ImportDeclaration,
|
|
7313
7355
|
moduleSpecifier: "@playwright/test",
|
|
7314
7356
|
isTypeOnly: true,
|
|
7315
7357
|
namedImports: [
|
|
7316
7358
|
{ name: "Locator", alias: "PwLocator" },
|
|
7317
7359
|
{ name: "Page", alias: "PwPage" }
|
|
7318
7360
|
]
|
|
7319
|
-
}
|
|
7320
|
-
|
|
7361
|
+
}, {
|
|
7362
|
+
kind: tsMorph.StructureKind.ImportDeclaration,
|
|
7321
7363
|
moduleSpecifier: basePageImportSpecifier,
|
|
7322
7364
|
namedImports: ["BasePage", "Fluent"]
|
|
7323
|
-
})
|
|
7324
|
-
|
|
7325
|
-
|
|
7326
|
-
|
|
7327
|
-
|
|
7328
|
-
|
|
7329
|
-
|
|
7330
|
-
|
|
7331
|
-
|
|
7332
|
-
moduleSpecifier: generatedImport.moduleSpecifier,
|
|
7333
|
-
namedImports: [generatedImport.className]
|
|
7334
|
-
});
|
|
7335
|
-
}
|
|
7336
|
-
const classDeclaration = sourceFile.addClass({
|
|
7365
|
+
}, ...customImports.map((customImport) => ({
|
|
7366
|
+
kind: tsMorph.StructureKind.ImportDeclaration,
|
|
7367
|
+
moduleSpecifier: customImport.moduleSpecifier,
|
|
7368
|
+
namedImports: [{ name: customImport.name, alias: customImport.alias }]
|
|
7369
|
+
})), ...generatedImports.map((generatedImport) => ({
|
|
7370
|
+
kind: tsMorph.StructureKind.ImportDeclaration,
|
|
7371
|
+
moduleSpecifier: generatedImport.moduleSpecifier,
|
|
7372
|
+
namedImports: [generatedImport.className]
|
|
7373
|
+
})), createClassDeclaration({
|
|
7337
7374
|
name: prepared.className,
|
|
7338
7375
|
isExported: true,
|
|
7339
7376
|
extends: "BasePage"
|
|
7340
|
-
})
|
|
7341
|
-
|
|
7342
|
-
addClassMember(classDeclaration, member);
|
|
7343
|
-
}
|
|
7344
|
-
}, { prefixText });
|
|
7377
|
+
}, prepared.members)]
|
|
7378
|
+
}, { prefixText, cache: options.renderCache });
|
|
7345
7379
|
}
|
|
7346
7380
|
function getViewPassthroughMethods(viewName, viewDependencies, componentInstances, componentHierarchyMap, blockedMethodNames = /* @__PURE__ */ new Set()) {
|
|
7347
7381
|
const existingOnView = viewDependencies.generatedMethods ?? /* @__PURE__ */ new Map();
|
|
@@ -7562,35 +7596,32 @@ function renderSplitStubPomContent(options) {
|
|
|
7562
7596
|
"Changes should be made in the generator/template, not in the generated output."
|
|
7563
7597
|
]
|
|
7564
7598
|
});
|
|
7565
|
-
return
|
|
7566
|
-
|
|
7599
|
+
return renderStructuredSourceFile(options.filePath, {
|
|
7600
|
+
// Stub ctors take Playwright's full `Page` (aliased `PwPage`), matching non-stub generated
|
|
7601
|
+
// POMs — stubs are constructed with `new Stub(this.page)` where `this.page` is `Page`.
|
|
7602
|
+
statements: [{
|
|
7603
|
+
kind: tsMorph.StructureKind.ImportDeclaration,
|
|
7567
7604
|
moduleSpecifier: "@playwright/test",
|
|
7568
7605
|
isTypeOnly: true,
|
|
7569
7606
|
namedImports: [{ name: "Page", alias: "PwPage" }]
|
|
7570
|
-
}
|
|
7571
|
-
|
|
7607
|
+
}, {
|
|
7608
|
+
kind: tsMorph.StructureKind.ImportDeclaration,
|
|
7572
7609
|
moduleSpecifier: options.basePageImportSpecifier,
|
|
7573
7610
|
namedImports: ["BasePage"]
|
|
7574
|
-
})
|
|
7575
|
-
|
|
7576
|
-
|
|
7577
|
-
|
|
7578
|
-
|
|
7579
|
-
});
|
|
7580
|
-
}
|
|
7581
|
-
sourceFile.addStatements(buildCommentBlock([
|
|
7582
|
-
"Stub POM generated because it is referenced as a navigation target but",
|
|
7583
|
-
"did not have any generated test ids in this build."
|
|
7584
|
-
]).trimEnd());
|
|
7585
|
-
const classDeclaration = sourceFile.addClass({
|
|
7611
|
+
}, ...options.childImports.map((childImport) => ({
|
|
7612
|
+
kind: tsMorph.StructureKind.ImportDeclaration,
|
|
7613
|
+
moduleSpecifier: childImport.importPath,
|
|
7614
|
+
namedImports: [childImport.className]
|
|
7615
|
+
})), createClassDeclaration({
|
|
7586
7616
|
name: options.className,
|
|
7587
7617
|
isExported: true,
|
|
7588
|
-
extends: "BasePage"
|
|
7589
|
-
|
|
7590
|
-
|
|
7591
|
-
|
|
7592
|
-
|
|
7593
|
-
|
|
7618
|
+
extends: "BasePage",
|
|
7619
|
+
leadingTrivia: buildCommentBlock([
|
|
7620
|
+
"Stub POM generated because it is referenced as a navigation target but",
|
|
7621
|
+
"did not have any generated test ids in this build."
|
|
7622
|
+
])
|
|
7623
|
+
}, options.members)]
|
|
7624
|
+
}, { prefixText, cache: options.renderCache });
|
|
7594
7625
|
}
|
|
7595
7626
|
function getChildImportSpecifiers(outputDir, childClassNames, generatedTsFilePathByComponent) {
|
|
7596
7627
|
return childClassNames.map((childClassName) => {
|
|
@@ -7604,37 +7635,6 @@ function getChildImportSpecifiers(outputDir, childClassNames, generatedTsFilePat
|
|
|
7604
7635
|
};
|
|
7605
7636
|
}).filter((entry) => !!entry).sort((a, b) => a.className.localeCompare(b.className));
|
|
7606
7637
|
}
|
|
7607
|
-
function isConstructorMember(member) {
|
|
7608
|
-
return member.kind === tsMorph.StructureKind.Constructor;
|
|
7609
|
-
}
|
|
7610
|
-
function isGetterMember(member) {
|
|
7611
|
-
return member.kind === tsMorph.StructureKind.GetAccessor;
|
|
7612
|
-
}
|
|
7613
|
-
function isMethodMember(member) {
|
|
7614
|
-
return member.kind === tsMorph.StructureKind.Method;
|
|
7615
|
-
}
|
|
7616
|
-
function isPropertyMember(member) {
|
|
7617
|
-
return member.kind === tsMorph.StructureKind.Property;
|
|
7618
|
-
}
|
|
7619
|
-
function addClassMember(classDeclaration, member) {
|
|
7620
|
-
if (isConstructorMember(member)) {
|
|
7621
|
-
classDeclaration.addConstructor(member);
|
|
7622
|
-
return;
|
|
7623
|
-
}
|
|
7624
|
-
if (isGetterMember(member)) {
|
|
7625
|
-
classDeclaration.addGetAccessor(member);
|
|
7626
|
-
return;
|
|
7627
|
-
}
|
|
7628
|
-
if (isMethodMember(member)) {
|
|
7629
|
-
classDeclaration.addMethod(member);
|
|
7630
|
-
return;
|
|
7631
|
-
}
|
|
7632
|
-
if (isPropertyMember(member)) {
|
|
7633
|
-
classDeclaration.addProperty(member);
|
|
7634
|
-
return;
|
|
7635
|
-
}
|
|
7636
|
-
throw new Error(`Unsupported class member structure: ${String(member)}`);
|
|
7637
|
-
}
|
|
7638
7638
|
function getRuntimeGeneratedAssetSpecs(baseDir, basePageClassPath) {
|
|
7639
7639
|
const runtimeDirAbs = path.join(baseDir, "_pom-runtime");
|
|
7640
7640
|
const runtimeClassGenAbs = path.join(runtimeDirAbs, "class-generation");
|
|
@@ -7912,37 +7912,30 @@ async function generateAggregatedFiles(componentHierarchyMap, vueFilesPathMap, b
|
|
|
7912
7912
|
"Changes should be made in the generator/template, not in the generated output."
|
|
7913
7913
|
]
|
|
7914
7914
|
});
|
|
7915
|
-
return
|
|
7916
|
-
|
|
7917
|
-
|
|
7918
|
-
|
|
7919
|
-
for (const entry of [...classes, ...stubs]) {
|
|
7920
|
-
if (entry.isStub) {
|
|
7921
|
-
sourceFile.addStatements(buildCommentBlock([
|
|
7922
|
-
"Stub POM generated because it is referenced as a navigation target but",
|
|
7923
|
-
"did not have any generated test ids in this build."
|
|
7924
|
-
]).trimEnd());
|
|
7925
|
-
} else {
|
|
7926
|
-
sourceFile.addStatements(entry.doc);
|
|
7927
|
-
}
|
|
7928
|
-
const classDeclaration = sourceFile.addClass({
|
|
7915
|
+
return renderStructuredSourceFile(path.join(outputDir, "page-object-models.g.ts"), {
|
|
7916
|
+
statements: [
|
|
7917
|
+
...imports,
|
|
7918
|
+
...[...classes, ...stubs].map((entry) => createClassDeclaration({
|
|
7929
7919
|
name: entry.className,
|
|
7930
7920
|
isExported: true,
|
|
7931
|
-
extends: "BasePage"
|
|
7932
|
-
|
|
7933
|
-
|
|
7934
|
-
|
|
7935
|
-
|
|
7936
|
-
|
|
7937
|
-
|
|
7921
|
+
extends: "BasePage",
|
|
7922
|
+
leadingTrivia: entry.isStub ? buildCommentBlock([
|
|
7923
|
+
"Stub POM generated because it is referenced as a navigation target but",
|
|
7924
|
+
"did not have any generated test ids in this build."
|
|
7925
|
+
]) : `${entry.doc}
|
|
7926
|
+
`
|
|
7927
|
+
}, entry.members))
|
|
7928
|
+
]
|
|
7929
|
+
}, { prefixText, cache: options.renderCache });
|
|
7938
7930
|
};
|
|
7939
7931
|
const base = ensureDir(outDir);
|
|
7940
7932
|
const outputFile = path.join(base, "page-object-models.g.ts");
|
|
7941
7933
|
const content = makeAggregatedContent(path.dirname(outputFile), [...views, ...components]);
|
|
7942
7934
|
const indexFile = path.join(base, "index.ts");
|
|
7943
|
-
const indexContent =
|
|
7944
|
-
|
|
7935
|
+
const indexContent = renderStructuredSourceFile(indexFile, {
|
|
7936
|
+
statements: [{ kind: tsMorph.StructureKind.ExportDeclaration, moduleSpecifier: "./page-object-models.g" }]
|
|
7945
7937
|
}, {
|
|
7938
|
+
cache: options.renderCache,
|
|
7946
7939
|
prefixText: buildFilePrefix({
|
|
7947
7940
|
eslintDisableSortImports: true,
|
|
7948
7941
|
commentLines: [
|
|
@@ -10759,6 +10752,7 @@ function createDevProcessorPlugin(options) {
|
|
|
10759
10752
|
scheduleVueFileRegen(ctx.file, "hmr");
|
|
10760
10753
|
},
|
|
10761
10754
|
async configureServer(server) {
|
|
10755
|
+
const renderCache = new TypeScriptRenderCache();
|
|
10762
10756
|
const getViewsDirAbs = () => resolveProjectPath(getViewsDir());
|
|
10763
10757
|
const getPageDirsAbs = () => getPageDirs().map((dir) => resolveProjectPath(dir));
|
|
10764
10758
|
const routerInitPromise = (async () => {
|
|
@@ -10966,6 +10960,7 @@ function createDevProcessorPlugin(options) {
|
|
|
10966
10960
|
const generateAggregatedFromSnapshot = async (logLabel) => {
|
|
10967
10961
|
const t0 = node_perf_hooks.performance.now();
|
|
10968
10962
|
await generateFiles(snapshotHierarchy, snapshotVuePathMap, normalizedBasePagePath, {
|
|
10963
|
+
renderCache,
|
|
10969
10964
|
outDir,
|
|
10970
10965
|
emitLanguages,
|
|
10971
10966
|
typescriptOutputStructure,
|
|
@@ -11999,6 +11994,20 @@ const ANNOTATOR_STYLES = `
|
|
|
11999
11994
|
max-width: min(320px, calc(100vw - 24px));
|
|
12000
11995
|
}
|
|
12001
11996
|
|
|
11997
|
+
.vpg-annotator-panel--preview {
|
|
11998
|
+
min-width: min(720px, calc(100vw - 24px));
|
|
11999
|
+
max-width: min(940px, calc(100vw - 24px));
|
|
12000
|
+
}
|
|
12001
|
+
|
|
12002
|
+
.vpg-annotator-panel--preview .vpg-annotator-textarea {
|
|
12003
|
+
height: min(52vh, 440px);
|
|
12004
|
+
resize: vertical;
|
|
12005
|
+
font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
|
|
12006
|
+
white-space: pre;
|
|
12007
|
+
overflow: auto;
|
|
12008
|
+
}
|
|
12009
|
+
|
|
12010
|
+
|
|
12002
12011
|
.vpg-annotator-arrow {
|
|
12003
12012
|
position: absolute;
|
|
12004
12013
|
z-index: 0;
|
|
@@ -12113,18 +12122,6 @@ const ANNOTATOR_STYLES = `
|
|
|
12113
12122
|
margin-top: 12px;
|
|
12114
12123
|
}
|
|
12115
12124
|
|
|
12116
|
-
.vpg-annotator-shortcuts {
|
|
12117
|
-
display: grid;
|
|
12118
|
-
gap: 8px;
|
|
12119
|
-
}
|
|
12120
|
-
|
|
12121
|
-
.vpg-annotator-shortcut-row {
|
|
12122
|
-
display: flex;
|
|
12123
|
-
align-items: center;
|
|
12124
|
-
justify-content: space-between;
|
|
12125
|
-
gap: 12px;
|
|
12126
|
-
}
|
|
12127
|
-
|
|
12128
12125
|
.vpg-annotator-label {
|
|
12129
12126
|
font-size: 12px;
|
|
12130
12127
|
font-weight: 600;
|
|
@@ -12140,20 +12137,6 @@ const ANNOTATOR_STYLES = `
|
|
|
12140
12137
|
padding: 8px 10px;
|
|
12141
12138
|
}
|
|
12142
12139
|
|
|
12143
|
-
.vpg-annotator-kbd {
|
|
12144
|
-
min-width: 32px;
|
|
12145
|
-
padding: 4px 8px;
|
|
12146
|
-
border: 1px solid var(--vpg-annotator-border);
|
|
12147
|
-
border-radius: var(--vpg-annotator-radius);
|
|
12148
|
-
background: rgba(15, 23, 42, 0.72);
|
|
12149
|
-
color: var(--vpg-annotator-text);
|
|
12150
|
-
font: inherit;
|
|
12151
|
-
font-size: 11px;
|
|
12152
|
-
font-weight: 700;
|
|
12153
|
-
line-height: 1;
|
|
12154
|
-
text-align: center;
|
|
12155
|
-
}
|
|
12156
|
-
|
|
12157
12140
|
.vpg-annotator-highlight {
|
|
12158
12141
|
position: fixed;
|
|
12159
12142
|
z-index: 2147483646;
|
|
@@ -12185,6 +12168,7 @@ const ANNOTATOR_STYLES = `
|
|
|
12185
12168
|
inset: 0;
|
|
12186
12169
|
z-index: 2147483645;
|
|
12187
12170
|
background: transparent;
|
|
12171
|
+
cursor: crosshair;
|
|
12188
12172
|
}
|
|
12189
12173
|
|
|
12190
12174
|
.vpg-annotator-marker {
|
|
@@ -12217,6 +12201,34 @@ const ANNOTATOR_STYLES = `
|
|
|
12217
12201
|
font-size: 12px;
|
|
12218
12202
|
font-weight: 600;
|
|
12219
12203
|
}
|
|
12204
|
+
|
|
12205
|
+
.vpg-annotator-heading-row {
|
|
12206
|
+
display: flex;
|
|
12207
|
+
align-items: center;
|
|
12208
|
+
justify-content: space-between;
|
|
12209
|
+
gap: 8px;
|
|
12210
|
+
}
|
|
12211
|
+
|
|
12212
|
+
.vpg-annotator-heading-row .vpg-annotator-heading {
|
|
12213
|
+
margin-bottom: 4px;
|
|
12214
|
+
}
|
|
12215
|
+
|
|
12216
|
+
.vpg-annotator-panel-close {
|
|
12217
|
+
margin-left: auto;
|
|
12218
|
+
background: transparent;
|
|
12219
|
+
border: none;
|
|
12220
|
+
color: var(--vpg-annotator-text-soft);
|
|
12221
|
+
font-size: 16px;
|
|
12222
|
+
line-height: 1;
|
|
12223
|
+
padding: 2px 6px;
|
|
12224
|
+
cursor: pointer;
|
|
12225
|
+
border-radius: var(--vpg-annotator-radius);
|
|
12226
|
+
}
|
|
12227
|
+
|
|
12228
|
+
.vpg-annotator-panel-close:hover {
|
|
12229
|
+
color: var(--vpg-annotator-text);
|
|
12230
|
+
background: var(--vpg-annotator-bg-soft);
|
|
12231
|
+
}
|
|
12220
12232
|
`;
|
|
12221
12233
|
const ignoredComponentNamePattern = /^(?:items\[\d+\]\.template|template|anonymous|slot|transition|transition-group)$/i;
|
|
12222
12234
|
function getDirectVueInstances(element) {
|
|
@@ -12375,35 +12387,15 @@ const TOOLBAR_POSITION_STORAGE_KEY = "vpg-annotator-toolbar-position";
|
|
|
12375
12387
|
const RUNTIME_GUARD = "__VUE_POM_GENERATOR_ANNOTATOR_RUNTIME__";
|
|
12376
12388
|
const TOOLBAR_ICON_MARKUP = {
|
|
12377
12389
|
drag: '<svg viewBox="0 0 16 16"><path d="M5 3h1v1H5zM10 3h1v1h-1zM5 7h1v1H5zM10 7h1v1h-1zM5 11h1v1H5zM10 11h1v1h-1z" fill="currentColor" stroke="none" /></svg>',
|
|
12378
|
-
inspect: '<svg viewBox="0 0 16 16"><path d="M8
|
|
12390
|
+
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>',
|
|
12379
12391
|
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>',
|
|
12380
12392
|
copy: '<svg viewBox="0 0 16 16"><path d="M6 2.5h6.5v9H6z"/><path d="M3.5 5.5H5v6.5h5.5v1.5h-7z"/></svg>',
|
|
12381
12393
|
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>',
|
|
12382
12394
|
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>'
|
|
12383
12395
|
};
|
|
12384
|
-
const SHORTCUT_LABELS = {
|
|
12385
|
-
select: "S",
|
|
12386
|
-
preview: "P",
|
|
12387
|
-
copy: "C",
|
|
12388
|
-
clear: "X",
|
|
12389
|
-
settings: ",",
|
|
12390
|
-
cancel: "Esc"
|
|
12391
|
-
};
|
|
12392
|
-
function formatShortcutTitle(label, shortcut) {
|
|
12393
|
-
return shortcut ? `${label} (${shortcut})` : label;
|
|
12394
|
-
}
|
|
12395
12396
|
function isInsideAnnotatorTree(node) {
|
|
12396
12397
|
return node instanceof Element && !!node.closest(`[${ANNOTATOR_ROOT_ATTR}]`);
|
|
12397
12398
|
}
|
|
12398
|
-
function isEditableTarget(node) {
|
|
12399
|
-
if (!(node instanceof Element)) {
|
|
12400
|
-
return false;
|
|
12401
|
-
}
|
|
12402
|
-
if (node instanceof HTMLInputElement || node instanceof HTMLTextAreaElement || node instanceof HTMLSelectElement) {
|
|
12403
|
-
return true;
|
|
12404
|
-
}
|
|
12405
|
-
return node.closest('[contenteditable=""], [contenteditable="true"]') !== null;
|
|
12406
|
-
}
|
|
12407
12399
|
function getElementSummary(element) {
|
|
12408
12400
|
const testId = element.getAttribute("data-testid");
|
|
12409
12401
|
if (testId) {
|
|
@@ -12468,10 +12460,7 @@ function createButtonBase(label, onClick, options = {}) {
|
|
|
12468
12460
|
button.className = `vpg-annotator-btn${options.primary ? " vpg-annotator-btn--primary" : ""}`;
|
|
12469
12461
|
button.setAttribute(ANNOTATOR_ROOT_ATTR, "");
|
|
12470
12462
|
button.setAttribute("aria-label", label);
|
|
12471
|
-
button.title =
|
|
12472
|
-
if (options.shortcut) {
|
|
12473
|
-
button.setAttribute("aria-keyshortcuts", options.shortcut);
|
|
12474
|
-
}
|
|
12463
|
+
button.title = label;
|
|
12475
12464
|
if (options.pressed) {
|
|
12476
12465
|
button.setAttribute("aria-pressed", "true");
|
|
12477
12466
|
}
|
|
@@ -12611,23 +12600,18 @@ class AnnotatorRuntime {
|
|
|
12611
12600
|
count.textContent = `${this.annotations.length} annotation${this.annotations.length === 1 ? "" : "s"}`;
|
|
12612
12601
|
const selectButton = createIconButton(this.inspectMode ? "Stop selecting" : "Select element", "inspect", () => {
|
|
12613
12602
|
this.setInspectMode(!this.inspectMode);
|
|
12614
|
-
}, { primary: this.inspectMode, pressed: this.inspectMode
|
|
12603
|
+
}, { primary: this.inspectMode, pressed: this.inspectMode });
|
|
12615
12604
|
const previewButton = createIconButton("Preview annotations", "preview", () => this.openPreview(), {
|
|
12616
|
-
disabled: this.annotations.length === 0
|
|
12617
|
-
shortcut: SHORTCUT_LABELS.preview
|
|
12605
|
+
disabled: this.annotations.length === 0
|
|
12618
12606
|
});
|
|
12619
12607
|
this.previewButton = previewButton;
|
|
12620
12608
|
const copyButton = createIconButton("Copy annotations", "copy", () => this.copyAnnotations(), {
|
|
12621
|
-
disabled: this.annotations.length === 0
|
|
12622
|
-
shortcut: SHORTCUT_LABELS.copy
|
|
12609
|
+
disabled: this.annotations.length === 0
|
|
12623
12610
|
});
|
|
12624
12611
|
const clearButton = createIconButton("Clear annotations", "clear", () => this.clearAnnotations(), {
|
|
12625
|
-
disabled: this.annotations.length === 0
|
|
12626
|
-
shortcut: SHORTCUT_LABELS.clear
|
|
12627
|
-
});
|
|
12628
|
-
const settingsButton = createIconButton("Annotator settings", "settings", () => this.openSettings(), {
|
|
12629
|
-
shortcut: SHORTCUT_LABELS.settings
|
|
12612
|
+
disabled: this.annotations.length === 0
|
|
12630
12613
|
});
|
|
12614
|
+
const settingsButton = createIconButton("Annotator settings", "settings", () => this.openSettings());
|
|
12631
12615
|
this.settingsButton = settingsButton;
|
|
12632
12616
|
this.toolbarEl.append(handle, selectButton, previewButton, copyButton, clearButton, settingsButton, count);
|
|
12633
12617
|
this.applyToolbarPosition();
|
|
@@ -12658,7 +12642,6 @@ class AnnotatorRuntime {
|
|
|
12658
12642
|
this.renderMarkers();
|
|
12659
12643
|
this.applyToolbarPosition();
|
|
12660
12644
|
});
|
|
12661
|
-
window.addEventListener("keydown", (event) => this.onWindowKeyDown(event), true);
|
|
12662
12645
|
}
|
|
12663
12646
|
loadSettings() {
|
|
12664
12647
|
try {
|
|
@@ -12785,60 +12768,6 @@ class AnnotatorRuntime {
|
|
|
12785
12768
|
window.addEventListener("pointercancel", onPointerUp);
|
|
12786
12769
|
});
|
|
12787
12770
|
}
|
|
12788
|
-
onWindowKeyDown(event) {
|
|
12789
|
-
if (event.defaultPrevented || event.metaKey || event.ctrlKey || event.altKey) {
|
|
12790
|
-
return;
|
|
12791
|
-
}
|
|
12792
|
-
if (event.key === "Escape") {
|
|
12793
|
-
if (!this.inspectMode && !this.currentPanelEl) {
|
|
12794
|
-
return;
|
|
12795
|
-
}
|
|
12796
|
-
event.preventDefault();
|
|
12797
|
-
if (this.inspectMode) {
|
|
12798
|
-
this.setInspectMode(false);
|
|
12799
|
-
} else {
|
|
12800
|
-
this.closePanel();
|
|
12801
|
-
}
|
|
12802
|
-
return;
|
|
12803
|
-
}
|
|
12804
|
-
if (isEditableTarget(event.target)) {
|
|
12805
|
-
return;
|
|
12806
|
-
}
|
|
12807
|
-
const key = event.key.toLowerCase();
|
|
12808
|
-
if (key === SHORTCUT_LABELS.select.toLowerCase()) {
|
|
12809
|
-
event.preventDefault();
|
|
12810
|
-
this.setInspectMode(!this.inspectMode);
|
|
12811
|
-
return;
|
|
12812
|
-
}
|
|
12813
|
-
if (key === SHORTCUT_LABELS.preview.toLowerCase()) {
|
|
12814
|
-
if (!this.annotations.length) {
|
|
12815
|
-
return;
|
|
12816
|
-
}
|
|
12817
|
-
event.preventDefault();
|
|
12818
|
-
this.openPreview();
|
|
12819
|
-
return;
|
|
12820
|
-
}
|
|
12821
|
-
if (key === SHORTCUT_LABELS.copy.toLowerCase()) {
|
|
12822
|
-
if (!this.annotations.length) {
|
|
12823
|
-
return;
|
|
12824
|
-
}
|
|
12825
|
-
event.preventDefault();
|
|
12826
|
-
void this.copyAnnotations();
|
|
12827
|
-
return;
|
|
12828
|
-
}
|
|
12829
|
-
if (key === SHORTCUT_LABELS.clear.toLowerCase()) {
|
|
12830
|
-
if (!this.annotations.length) {
|
|
12831
|
-
return;
|
|
12832
|
-
}
|
|
12833
|
-
event.preventDefault();
|
|
12834
|
-
this.clearAnnotations();
|
|
12835
|
-
return;
|
|
12836
|
-
}
|
|
12837
|
-
if (event.key === SHORTCUT_LABELS.settings) {
|
|
12838
|
-
event.preventDefault();
|
|
12839
|
-
this.openSettings();
|
|
12840
|
-
}
|
|
12841
|
-
}
|
|
12842
12771
|
setInspectMode(next) {
|
|
12843
12772
|
this.inspectMode = next;
|
|
12844
12773
|
this.shieldEl.hidden = !next;
|
|
@@ -13023,11 +12952,21 @@ class AnnotatorRuntime {
|
|
|
13023
12952
|
this.editingAnnotationId = annotation.id;
|
|
13024
12953
|
this.openInputForDraft(reference);
|
|
13025
12954
|
}
|
|
12955
|
+
createPanelCloseButton(ariaLabel) {
|
|
12956
|
+
const closeButton = document.createElement("button");
|
|
12957
|
+
closeButton.type = "button";
|
|
12958
|
+
closeButton.className = "vpg-annotator-panel-close";
|
|
12959
|
+
closeButton.setAttribute(ANNOTATOR_ROOT_ATTR, "");
|
|
12960
|
+
closeButton.setAttribute("aria-label", ariaLabel);
|
|
12961
|
+
closeButton.textContent = "×";
|
|
12962
|
+
closeButton.addEventListener("click", () => this.closePanel());
|
|
12963
|
+
return closeButton;
|
|
12964
|
+
}
|
|
13026
12965
|
openPreview() {
|
|
13027
12966
|
if (!this.previewButton || this.annotations.length === 0) {
|
|
13028
12967
|
return;
|
|
13029
12968
|
}
|
|
13030
|
-
const { panel, body, arrowEl } = this.createPanelBase("vpg-annotator-panel");
|
|
12969
|
+
const { panel, body, arrowEl } = this.createPanelBase("vpg-annotator-panel vpg-annotator-panel--preview");
|
|
13031
12970
|
const title = document.createElement("div");
|
|
13032
12971
|
title.className = "vpg-annotator-heading";
|
|
13033
12972
|
title.textContent = "Annotation preview";
|
|
@@ -13038,7 +12977,10 @@ class AnnotatorRuntime {
|
|
|
13038
12977
|
textarea.className = "vpg-annotator-textarea";
|
|
13039
12978
|
textarea.readOnly = true;
|
|
13040
12979
|
textarea.value = formatAnnotations(this.annotations, this.settings.outputDetail, window.location.href);
|
|
13041
|
-
|
|
12980
|
+
const headerRow = document.createElement("div");
|
|
12981
|
+
headerRow.className = "vpg-annotator-heading-row";
|
|
12982
|
+
headerRow.append(title, this.createPanelCloseButton("Close preview"));
|
|
12983
|
+
body.append(headerRow, subtitle, textarea);
|
|
13042
12984
|
this.showPanel(panel, () => this.attachFloating(this.previewButton, panel, arrowEl, "top-start", ["top-start", "left-start", "top-end", "left-end"]));
|
|
13043
12985
|
}
|
|
13044
12986
|
openSettings() {
|
|
@@ -13077,35 +13019,7 @@ class AnnotatorRuntime {
|
|
|
13077
13019
|
this.saveSettings();
|
|
13078
13020
|
});
|
|
13079
13021
|
showComponentField.append(showComponentCopy, showComponentCheckbox);
|
|
13080
|
-
|
|
13081
|
-
shortcutsField.className = "vpg-annotator-field";
|
|
13082
|
-
const shortcutsLabel = document.createElement("div");
|
|
13083
|
-
shortcutsLabel.className = "vpg-annotator-label";
|
|
13084
|
-
shortcutsLabel.textContent = "Keyboard shortcuts";
|
|
13085
|
-
const shortcutsList = document.createElement("div");
|
|
13086
|
-
shortcutsList.className = "vpg-annotator-shortcuts";
|
|
13087
|
-
for (const [shortcut, description] of [
|
|
13088
|
-
[SHORTCUT_LABELS.select, "Toggle selection mode"],
|
|
13089
|
-
[SHORTCUT_LABELS.preview, "Open preview"],
|
|
13090
|
-
[SHORTCUT_LABELS.copy, "Copy annotations"],
|
|
13091
|
-
[SHORTCUT_LABELS.clear, "Clear annotations"],
|
|
13092
|
-
[SHORTCUT_LABELS.settings, "Open settings"],
|
|
13093
|
-
[SHORTCUT_LABELS.cancel, "Close panel / cancel selection"]
|
|
13094
|
-
]) {
|
|
13095
|
-
const row = document.createElement("div");
|
|
13096
|
-
row.className = "vpg-annotator-shortcut-row";
|
|
13097
|
-
const text = document.createElement("span");
|
|
13098
|
-
text.className = "vpg-annotator-subtle";
|
|
13099
|
-
text.textContent = description;
|
|
13100
|
-
const kbd = document.createElement("kbd");
|
|
13101
|
-
kbd.className = "vpg-annotator-kbd";
|
|
13102
|
-
kbd.setAttribute(ANNOTATOR_ROOT_ATTR, "");
|
|
13103
|
-
kbd.textContent = shortcut;
|
|
13104
|
-
row.append(text, kbd);
|
|
13105
|
-
shortcutsList.appendChild(row);
|
|
13106
|
-
}
|
|
13107
|
-
shortcutsField.append(shortcutsLabel, shortcutsList);
|
|
13108
|
-
body.append(title, detailField, showComponentField, shortcutsField);
|
|
13022
|
+
body.append(title, detailField, showComponentField);
|
|
13109
13023
|
this.showPanel(panel, () => this.attachFloating(this.settingsButton, panel, arrowEl, "top-start", ["top-start", "left-start", "top-end", "left-end"]));
|
|
13110
13024
|
}
|
|
13111
13025
|
disposeCurrentPanel() {
|