@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.mjs
CHANGED
|
@@ -8,8 +8,8 @@ import { NodeTypes, stringifyExpression, createSimpleExpression, processExpressi
|
|
|
8
8
|
import * as compilerDom from "@vue/compiler-dom";
|
|
9
9
|
import { parse as parse$2, NodeTypes as NodeTypes$1 } from "@vue/compiler-dom";
|
|
10
10
|
import { parse as parse$1, compileScript } from "@vue/compiler-sfc";
|
|
11
|
-
import { Project, QuoteKind, NewLineKind, IndentationText,
|
|
12
|
-
import { isIdentifier, isObjectPattern, isRestElement, isObjectProperty, isArrayExpression, isStringLiteral, isTemplateLiteral, isArrowFunctionExpression, isExpressionStatement, isAssignmentPattern, isMemberExpression, isOptionalMemberExpression, isCallExpression, isOptionalCallExpression, isAssignmentExpression,
|
|
11
|
+
import { Project, QuoteKind, NewLineKind, IndentationText, CodeBlockWriter, StructureKind, VariableDeclarationKind } from "ts-morph";
|
|
12
|
+
import { isIdentifier, isObjectPattern, isRestElement, isObjectProperty, isArrayExpression, isStringLiteral, isTemplateLiteral, isArrowFunctionExpression, isExpressionStatement, isAssignmentPattern, isMemberExpression, isOptionalMemberExpression, isCallExpression, isOptionalCallExpression, isAssignmentExpression, isObjectExpression, isFile, isBlockStatement, isLogicalExpression, isConditionalExpression, isSequenceExpression, isProgram, isArrayPattern, VISITOR_KEYS, isBooleanLiteral, isNumericLiteral, isNullLiteral, isImportDeclaration, isImportSpecifier, isExportDefaultDeclaration, isExpression, isVariableDeclaration, isFunctionDeclaration, isFunctionExpression, isReturnStatement, isTSAsExpression, isTSTypeAssertion, isTSNonNullExpression, isForInStatement, isIfStatement } from "@babel/types";
|
|
13
13
|
import { createHash, randomUUID } from "node:crypto";
|
|
14
14
|
import { POM_ROUTER_GLOBAL_NAME } from "./router.mjs";
|
|
15
15
|
import { performance } from "node:perf_hooks";
|
|
@@ -254,6 +254,58 @@ function applyNuxtDiscoveryToInjectionOptions(options, discovery) {
|
|
|
254
254
|
wrapperSearchRoots: discovery.wrapperSearchRoots
|
|
255
255
|
};
|
|
256
256
|
}
|
|
257
|
+
class TypeScriptRenderCache {
|
|
258
|
+
entries = /* @__PURE__ */ new Map();
|
|
259
|
+
render(filePath, input, build) {
|
|
260
|
+
const previous = this.entries.get(filePath);
|
|
261
|
+
if (previous?.input === input) return previous.content;
|
|
262
|
+
const content = build();
|
|
263
|
+
this.entries.set(filePath, { input, content });
|
|
264
|
+
return content;
|
|
265
|
+
}
|
|
266
|
+
retain(filePaths) {
|
|
267
|
+
for (const filePath of this.entries.keys()) {
|
|
268
|
+
if (!filePaths.has(filePath)) this.entries.delete(filePath);
|
|
269
|
+
}
|
|
270
|
+
}
|
|
271
|
+
}
|
|
272
|
+
function createClassDeclaration(declaration, members) {
|
|
273
|
+
const result = { ...declaration, kind: StructureKind.Class };
|
|
274
|
+
for (const member of members) {
|
|
275
|
+
switch (member.kind) {
|
|
276
|
+
case StructureKind.Constructor:
|
|
277
|
+
(result.ctors ??= []).push(member);
|
|
278
|
+
break;
|
|
279
|
+
case StructureKind.GetAccessor:
|
|
280
|
+
(result.getAccessors ??= []).push(member);
|
|
281
|
+
break;
|
|
282
|
+
case StructureKind.Method:
|
|
283
|
+
(result.methods ??= []).push(member);
|
|
284
|
+
break;
|
|
285
|
+
case StructureKind.Property:
|
|
286
|
+
(result.properties ??= []).push(member);
|
|
287
|
+
break;
|
|
288
|
+
default:
|
|
289
|
+
throw new Error(`Unsupported class member kind: ${String(member.kind)}`);
|
|
290
|
+
}
|
|
291
|
+
}
|
|
292
|
+
return result;
|
|
293
|
+
}
|
|
294
|
+
function renderStructuredSourceFile(filePath, structure, options = {}) {
|
|
295
|
+
const build = () => {
|
|
296
|
+
const project = createTypeScriptProject();
|
|
297
|
+
const sourceFile = project.createSourceFile(filePath, structure);
|
|
298
|
+
return ensureTrailingNewline(`${options.prefixText ?? ""}${sourceFile.getFullText()}`);
|
|
299
|
+
};
|
|
300
|
+
if (!options.cache) return build();
|
|
301
|
+
const input = JSON.stringify([options.prefixText, structure], (_key, value) => {
|
|
302
|
+
if (typeof value !== "function") return value;
|
|
303
|
+
const writer = createTypeScriptWriter();
|
|
304
|
+
value(writer);
|
|
305
|
+
return writer.toString();
|
|
306
|
+
});
|
|
307
|
+
return options.cache.render(filePath, input, build);
|
|
308
|
+
}
|
|
257
309
|
function createTypeScriptProject() {
|
|
258
310
|
return new Project({
|
|
259
311
|
useInMemoryFileSystem: true,
|
|
@@ -318,9 +370,6 @@ function addNamedImport(sourceFile, options) {
|
|
|
318
370
|
namedImports: options.namedImports
|
|
319
371
|
});
|
|
320
372
|
}
|
|
321
|
-
function addExportAll(sourceFile, moduleSpecifier) {
|
|
322
|
-
return sourceFile.addExportDeclaration({ moduleSpecifier });
|
|
323
|
-
}
|
|
324
373
|
function createClassMethod(method) {
|
|
325
374
|
return {
|
|
326
375
|
kind: StructureKind.Method,
|
|
@@ -1417,23 +1466,11 @@ function getSlotScopeVariablesUsedAsBareCallbackHandlers(templateNode) {
|
|
|
1417
1466
|
const vFor = node.props.find(
|
|
1418
1467
|
(prop) => prop.type === NodeTypes.DIRECTIVE && prop.name === "for"
|
|
1419
1468
|
);
|
|
1420
|
-
if (vFor?.
|
|
1421
|
-
const
|
|
1422
|
-
|
|
1423
|
-
|
|
1424
|
-
|
|
1425
|
-
if (aliasSource) {
|
|
1426
|
-
try {
|
|
1427
|
-
const aliasAst = parseExpression(aliasSource, { plugins: ["typescript"] });
|
|
1428
|
-
if (isSequenceExpression(aliasAst)) {
|
|
1429
|
-
for (const part of aliasAst.expressions) {
|
|
1430
|
-
names.push(...collectBindingPatternNames(part));
|
|
1431
|
-
}
|
|
1432
|
-
} else {
|
|
1433
|
-
names.push(...collectBindingPatternNames(aliasAst));
|
|
1434
|
-
}
|
|
1435
|
-
} catch {
|
|
1436
|
-
}
|
|
1469
|
+
if (vFor?.forParseResult) {
|
|
1470
|
+
const { value, key, index } = vFor.forParseResult;
|
|
1471
|
+
for (const alias of [value, key, index]) {
|
|
1472
|
+
if (alias) {
|
|
1473
|
+
names.push(...collectBindingPatternNames(tryGetTemplateSlotScopeBindingNode(alias)));
|
|
1437
1474
|
}
|
|
1438
1475
|
}
|
|
1439
1476
|
}
|
|
@@ -1603,10 +1640,6 @@ function tryGetTemplateSlotScopeBindingNode(expression) {
|
|
|
1603
1640
|
if (!rawSource) {
|
|
1604
1641
|
return null;
|
|
1605
1642
|
}
|
|
1606
|
-
try {
|
|
1607
|
-
return parseExpression(rawSource, { plugins: ["typescript"] });
|
|
1608
|
-
} catch {
|
|
1609
|
-
}
|
|
1610
1643
|
try {
|
|
1611
1644
|
const parsed = parse(`(${rawSource}) => {}`, {
|
|
1612
1645
|
sourceType: "module",
|
|
@@ -3967,29 +4000,30 @@ function generateTestIdsModule(componentHierarchyMap, elementMetadata) {
|
|
|
3967
4000
|
});
|
|
3968
4001
|
});
|
|
3969
4002
|
}
|
|
3970
|
-
function generatePomManifestModule(componentHierarchyMap, elementMetadata, fileName = "virtual-pom-manifest.ts") {
|
|
4003
|
+
function generatePomManifestModule(componentHierarchyMap, elementMetadata, fileName = "virtual-pom-manifest.ts", renderCache) {
|
|
3971
4004
|
const pomManifest = buildPomManifest(componentHierarchyMap, elementMetadata);
|
|
3972
|
-
return
|
|
3973
|
-
|
|
3974
|
-
|
|
4005
|
+
return renderStructuredSourceFile(fileName, {
|
|
4006
|
+
statements: [{
|
|
4007
|
+
kind: StructureKind.VariableStatement,
|
|
4008
|
+
leadingTrivia: "// Rich POM discoverability manifest.\n",
|
|
3975
4009
|
declarationKind: VariableDeclarationKind.Const,
|
|
3976
4010
|
isExported: true,
|
|
3977
4011
|
declarations: [{
|
|
3978
4012
|
name: "pomManifest",
|
|
3979
4013
|
initializer: writeConstJson(pomManifest)
|
|
3980
4014
|
}]
|
|
3981
|
-
}
|
|
3982
|
-
|
|
4015
|
+
}, {
|
|
4016
|
+
kind: StructureKind.TypeAlias,
|
|
3983
4017
|
isExported: true,
|
|
3984
4018
|
name: "PomManifest",
|
|
3985
4019
|
type: "typeof pomManifest"
|
|
3986
|
-
}
|
|
3987
|
-
|
|
4020
|
+
}, {
|
|
4021
|
+
kind: StructureKind.TypeAlias,
|
|
3988
4022
|
isExported: true,
|
|
3989
4023
|
name: "PomManifestComponentName",
|
|
3990
4024
|
type: "keyof PomManifest"
|
|
3991
|
-
}
|
|
3992
|
-
});
|
|
4025
|
+
}]
|
|
4026
|
+
}, { cache: renderCache });
|
|
3993
4027
|
}
|
|
3994
4028
|
const manifestName = ".vue-pom-generator-outputs.json";
|
|
3995
4029
|
function hash(content) {
|
|
@@ -4038,6 +4072,7 @@ function assertNoSymlinkParents(filePath, outDir, projectRoot) {
|
|
|
4038
4072
|
}
|
|
4039
4073
|
}
|
|
4040
4074
|
function writeFile(filePath, content) {
|
|
4075
|
+
if (fs.existsSync(filePath) && fs.readFileSync(filePath, "utf8") === content) return;
|
|
4041
4076
|
fs.mkdirSync(path.dirname(filePath), { recursive: true });
|
|
4042
4077
|
const temporaryPath = `${filePath}.${randomUUID()}.tmp`;
|
|
4043
4078
|
try {
|
|
@@ -5868,7 +5903,8 @@ async function generateFiles(componentHierarchyMap, vueFilesPathMap, basePageCla
|
|
|
5868
5903
|
componentDirs,
|
|
5869
5904
|
layoutDirs,
|
|
5870
5905
|
routeMetaByComponent: routeMetaByComponentOverride,
|
|
5871
|
-
elementMetadata = /* @__PURE__ */ new Map()
|
|
5906
|
+
elementMetadata = /* @__PURE__ */ new Map(),
|
|
5907
|
+
renderCache
|
|
5872
5908
|
} = options;
|
|
5873
5909
|
const emitLanguages = emitLanguagesOverride?.length ? emitLanguagesOverride : ["ts"];
|
|
5874
5910
|
const root = projectRoot ?? process.cwd();
|
|
@@ -5886,6 +5922,7 @@ async function generateFiles(componentHierarchyMap, vueFilesPathMap, basePageCla
|
|
|
5886
5922
|
const generatedFiles = [];
|
|
5887
5923
|
if (emitLanguages.includes("ts")) {
|
|
5888
5924
|
const files = typescriptOutputStructure === "split" ? await generateSplitTypeScriptFiles(emittableComponentHierarchyMap, vueFilesPathMap, basePageClassPath, outDir, {
|
|
5925
|
+
renderCache,
|
|
5889
5926
|
customPomAttachments,
|
|
5890
5927
|
projectRoot,
|
|
5891
5928
|
customPomDir,
|
|
@@ -5896,6 +5933,7 @@ async function generateFiles(componentHierarchyMap, vueFilesPathMap, basePageCla
|
|
|
5896
5933
|
routeMetaByComponent,
|
|
5897
5934
|
vueRouterFluentChaining
|
|
5898
5935
|
}) : await generateAggregatedFiles(emittableComponentHierarchyMap, vueFilesPathMap, basePageClassPath, outDir, {
|
|
5936
|
+
renderCache,
|
|
5899
5937
|
customPomAttachments,
|
|
5900
5938
|
projectRoot,
|
|
5901
5939
|
customPomDir,
|
|
@@ -5908,6 +5946,7 @@ async function generateFiles(componentHierarchyMap, vueFilesPathMap, basePageCla
|
|
|
5908
5946
|
});
|
|
5909
5947
|
generatedFiles.push(...files);
|
|
5910
5948
|
const fixtureRegistryFiles = maybeGenerateFixtureRegistry(emittableComponentHierarchyMap, {
|
|
5949
|
+
renderCache,
|
|
5911
5950
|
generateFixtures,
|
|
5912
5951
|
pomOutDir: outDir,
|
|
5913
5952
|
projectRoot,
|
|
@@ -5928,12 +5967,13 @@ async function generateFiles(componentHierarchyMap, vueFilesPathMap, basePageCla
|
|
|
5928
5967
|
const vueTestUtilsFiles = generateVueTestUtilsFiles(
|
|
5929
5968
|
emittableComponentHierarchyMap,
|
|
5930
5969
|
vueTestUtilsOutDir,
|
|
5931
|
-
{ testIdAttribute }
|
|
5970
|
+
{ testIdAttribute, renderCache }
|
|
5932
5971
|
);
|
|
5933
5972
|
generatedFiles.push(...vueTestUtilsFiles);
|
|
5934
5973
|
}
|
|
5935
5974
|
const gitattributesFiles = buildGeneratedGitAttributesFiles(generatedFiles.map((file) => file.filePath));
|
|
5936
5975
|
writeGeneratedOutputs(outDir, generatedFiles, gitattributesFiles, path.resolve(root));
|
|
5976
|
+
renderCache?.retain(new Set(generatedFiles.map((file) => file.filePath)));
|
|
5937
5977
|
}
|
|
5938
5978
|
const VUE_TEST_UTILS_OMITTED_PARAMETERS = /* @__PURE__ */ new Set(["annotationText", "timeOut", "timeout", "wait"]);
|
|
5939
5979
|
function getVueTestUtilsParameters(parameters, patterns, options = {}) {
|
|
@@ -6061,7 +6101,7 @@ function getVueTestUtilsComponentMembers(componentInstances, projectedComponentI
|
|
|
6061
6101
|
}));
|
|
6062
6102
|
return members;
|
|
6063
6103
|
}
|
|
6064
|
-
function generateVueTestUtilsContent(componentName, dependencies, componentHierarchyMap, outputDir, runtimePath, generatedFilePathByComponent, testIdAttribute) {
|
|
6104
|
+
function generateVueTestUtilsContent(componentName, dependencies, componentHierarchyMap, outputDir, runtimePath, generatedFilePathByComponent, testIdAttribute, renderCache) {
|
|
6065
6105
|
const prepared = prepareViewObjectModelClass(componentName, dependencies, componentHierarchyMap, {
|
|
6066
6106
|
testIdAttribute
|
|
6067
6107
|
});
|
|
@@ -6081,33 +6121,29 @@ function generateVueTestUtilsContent(componentName, dependencies, componentHiera
|
|
|
6081
6121
|
...getUniquePrimaryPomSpecs(dependencies).flatMap(({ pom }) => getVueTestUtilsPrimaryMembers(pom)),
|
|
6082
6122
|
...(dependencies.pomExtraMethods ?? []).flatMap(getVueTestUtilsExtraMembers)
|
|
6083
6123
|
];
|
|
6084
|
-
return
|
|
6085
|
-
|
|
6124
|
+
return renderStructuredSourceFile(path.join(outputDir, `${componentName}.vtu.g.ts`), {
|
|
6125
|
+
statements: [{
|
|
6126
|
+
kind: StructureKind.ImportDeclaration,
|
|
6086
6127
|
moduleSpecifier: runtimeImport,
|
|
6087
6128
|
namedImports: ["VueTestUtilsPom"]
|
|
6088
|
-
}
|
|
6089
|
-
|
|
6129
|
+
}, {
|
|
6130
|
+
kind: StructureKind.ImportDeclaration,
|
|
6090
6131
|
moduleSpecifier: runtimeImport,
|
|
6091
6132
|
namedImports: ["VueTestUtilsPomRoot"],
|
|
6092
6133
|
isTypeOnly: true
|
|
6093
|
-
})
|
|
6094
|
-
|
|
6095
|
-
|
|
6096
|
-
|
|
6097
|
-
|
|
6098
|
-
});
|
|
6099
|
-
}
|
|
6100
|
-
const declaration = sourceFile.addClass({
|
|
6134
|
+
}, ...componentImports.map((componentImport) => ({
|
|
6135
|
+
kind: StructureKind.ImportDeclaration,
|
|
6136
|
+
moduleSpecifier: componentImport.moduleSpecifier,
|
|
6137
|
+
namedImports: [componentImport.className]
|
|
6138
|
+
})), createClassDeclaration({
|
|
6101
6139
|
name: prepared.className,
|
|
6102
6140
|
isExported: true,
|
|
6103
6141
|
extends: "VueTestUtilsPom",
|
|
6104
6142
|
docs: [`Vue Test Utils object for ${componentName} (source: ${sourceRel}).`]
|
|
6105
|
-
})
|
|
6106
|
-
for (const member of members) {
|
|
6107
|
-
addClassMember(declaration, member);
|
|
6108
|
-
}
|
|
6143
|
+
}, members)]
|
|
6109
6144
|
}, {
|
|
6110
|
-
prefixText: buildFilePrefix({ eslintDisableSortImports: true })
|
|
6145
|
+
prefixText: buildFilePrefix({ eslintDisableSortImports: true }),
|
|
6146
|
+
cache: renderCache
|
|
6111
6147
|
});
|
|
6112
6148
|
}
|
|
6113
6149
|
function generateVueTestUtilsFiles(componentHierarchyMap, outDir, options = {}) {
|
|
@@ -6129,7 +6165,8 @@ function generateVueTestUtilsFiles(componentHierarchyMap, outDir, options = {})
|
|
|
6129
6165
|
path.dirname(filePath),
|
|
6130
6166
|
runtimePath,
|
|
6131
6167
|
generatedFilePathByComponent,
|
|
6132
|
-
testIdAttribute
|
|
6168
|
+
testIdAttribute,
|
|
6169
|
+
options.renderCache
|
|
6133
6170
|
)
|
|
6134
6171
|
};
|
|
6135
6172
|
});
|
|
@@ -6141,12 +6178,13 @@ function generateVueTestUtilsFiles(componentHierarchyMap, outDir, options = {})
|
|
|
6141
6178
|
if (!runtimeFile) {
|
|
6142
6179
|
throw new Error("[vue-pom-generator] Failed to generate the Vue Test Utils runtime.");
|
|
6143
6180
|
}
|
|
6144
|
-
const indexContent =
|
|
6145
|
-
|
|
6146
|
-
|
|
6147
|
-
|
|
6148
|
-
}
|
|
6181
|
+
const indexContent = renderStructuredSourceFile(path.join(base, "index.ts"), {
|
|
6182
|
+
statements: [
|
|
6183
|
+
stripExtension(toPosixRelativePath(base, runtimePath)),
|
|
6184
|
+
...Array.from(generatedFilePathByComponent.values(), (filePath) => `./${stripExtension(path.basename(filePath))}`)
|
|
6185
|
+
].map((moduleSpecifier) => ({ kind: StructureKind.ExportDeclaration, moduleSpecifier }))
|
|
6149
6186
|
}, {
|
|
6187
|
+
cache: options.renderCache,
|
|
6150
6188
|
prefixText: buildFilePrefix({
|
|
6151
6189
|
eslintDisableSortImports: true,
|
|
6152
6190
|
commentLines: [
|
|
@@ -6200,6 +6238,7 @@ async function generateSplitTypeScriptFiles(componentHierarchyMap, vueFilesPathM
|
|
|
6200
6238
|
continue;
|
|
6201
6239
|
}
|
|
6202
6240
|
const content = generateViewObjectModelContent(name, deps, componentHierarchyMap, vueFilesPathMap, runtimeBasePagePath, {
|
|
6241
|
+
renderCache: options.renderCache,
|
|
6203
6242
|
outputDir: path.dirname(filePath),
|
|
6204
6243
|
customPomAttachments: options.customPomAttachments ?? [],
|
|
6205
6244
|
projectRoot,
|
|
@@ -6227,6 +6266,8 @@ async function generateSplitTypeScriptFiles(componentHierarchyMap, vueFilesPathM
|
|
|
6227
6266
|
const childImports = getChildImportSpecifiers(outputDir, composed?.childClassNames ?? [], generatedTsFilePathByComponent);
|
|
6228
6267
|
const members = composed?.members ?? getDefaultStubMembers();
|
|
6229
6268
|
const content = renderSplitStubPomContent({
|
|
6269
|
+
filePath,
|
|
6270
|
+
renderCache: options.renderCache,
|
|
6230
6271
|
className: targetClassName,
|
|
6231
6272
|
basePageImportSpecifier,
|
|
6232
6273
|
childImports,
|
|
@@ -6236,14 +6277,13 @@ async function generateSplitTypeScriptFiles(componentHierarchyMap, vueFilesPathM
|
|
|
6236
6277
|
}
|
|
6237
6278
|
const runtimeAssetSpecs = getRuntimeGeneratedAssetSpecs(base, basePageClassPath);
|
|
6238
6279
|
const runtimeFiles = buildRuntimeGeneratedFilesFromSpecs(runtimeAssetSpecs);
|
|
6239
|
-
const indexContent =
|
|
6240
|
-
|
|
6241
|
-
|
|
6242
|
-
|
|
6243
|
-
|
|
6244
|
-
addExportAll(sourceFile, `./${stripExtension(path.basename(filePath))}`);
|
|
6245
|
-
}
|
|
6280
|
+
const indexContent = renderStructuredSourceFile(path.join(base, "index.ts"), {
|
|
6281
|
+
statements: [
|
|
6282
|
+
...runtimeAssetSpecs.map((spec) => stripExtension(toPosixRelativePath(base, spec.outputPath))),
|
|
6283
|
+
...Array.from(generatedTsFilePathByComponent.entries()).sort((a, b) => a[0].localeCompare(b[0])).map(([, filePath]) => `./${stripExtension(path.basename(filePath))}`)
|
|
6284
|
+
].map((moduleSpecifier) => ({ kind: StructureKind.ExportDeclaration, moduleSpecifier }))
|
|
6246
6285
|
}, {
|
|
6286
|
+
cache: options.renderCache,
|
|
6247
6287
|
prefixText: buildFilePrefix({
|
|
6248
6288
|
eslintDisableSortImports: true,
|
|
6249
6289
|
commentLines: [
|
|
@@ -6919,7 +6959,8 @@ function maybeGenerateFixtureRegistry(componentHierarchyMap, options) {
|
|
|
6919
6959
|
const manifestContent = generatePomManifestModule(
|
|
6920
6960
|
componentHierarchyMap,
|
|
6921
6961
|
options.elementMetadata,
|
|
6922
|
-
manifestFileName
|
|
6962
|
+
path.resolve(fixtureOutDirAbs, manifestFileName),
|
|
6963
|
+
options.renderCache
|
|
6923
6964
|
);
|
|
6924
6965
|
const [diagnosticsRuntimeFile] = buildRuntimeGeneratedFilesFromSpecs([{
|
|
6925
6966
|
absolutePath: resolvePluginAsset("../class-generation/diagnostics.ts"),
|
|
@@ -7267,40 +7308,33 @@ function generateViewObjectModelContent(componentName, dependencies, componentHi
|
|
|
7267
7308
|
generatedImports.sort((a, b) => a.className.localeCompare(b.className));
|
|
7268
7309
|
const prefixText = `${buildFilePrefix({ eslintDisableSortImports: true })}${doc}
|
|
7269
7310
|
`;
|
|
7270
|
-
return
|
|
7271
|
-
|
|
7311
|
+
return renderStructuredSourceFile(path.join(outputDir, `${componentName}.g.ts`), {
|
|
7312
|
+
statements: [{
|
|
7313
|
+
kind: StructureKind.ImportDeclaration,
|
|
7272
7314
|
moduleSpecifier: "@playwright/test",
|
|
7273
7315
|
isTypeOnly: true,
|
|
7274
7316
|
namedImports: [
|
|
7275
7317
|
{ name: "Locator", alias: "PwLocator" },
|
|
7276
7318
|
{ name: "Page", alias: "PwPage" }
|
|
7277
7319
|
]
|
|
7278
|
-
}
|
|
7279
|
-
|
|
7320
|
+
}, {
|
|
7321
|
+
kind: StructureKind.ImportDeclaration,
|
|
7280
7322
|
moduleSpecifier: basePageImportSpecifier,
|
|
7281
7323
|
namedImports: ["BasePage", "Fluent"]
|
|
7282
|
-
})
|
|
7283
|
-
|
|
7284
|
-
|
|
7285
|
-
|
|
7286
|
-
|
|
7287
|
-
|
|
7288
|
-
|
|
7289
|
-
|
|
7290
|
-
|
|
7291
|
-
moduleSpecifier: generatedImport.moduleSpecifier,
|
|
7292
|
-
namedImports: [generatedImport.className]
|
|
7293
|
-
});
|
|
7294
|
-
}
|
|
7295
|
-
const classDeclaration = sourceFile.addClass({
|
|
7324
|
+
}, ...customImports.map((customImport) => ({
|
|
7325
|
+
kind: StructureKind.ImportDeclaration,
|
|
7326
|
+
moduleSpecifier: customImport.moduleSpecifier,
|
|
7327
|
+
namedImports: [{ name: customImport.name, alias: customImport.alias }]
|
|
7328
|
+
})), ...generatedImports.map((generatedImport) => ({
|
|
7329
|
+
kind: StructureKind.ImportDeclaration,
|
|
7330
|
+
moduleSpecifier: generatedImport.moduleSpecifier,
|
|
7331
|
+
namedImports: [generatedImport.className]
|
|
7332
|
+
})), createClassDeclaration({
|
|
7296
7333
|
name: prepared.className,
|
|
7297
7334
|
isExported: true,
|
|
7298
7335
|
extends: "BasePage"
|
|
7299
|
-
})
|
|
7300
|
-
|
|
7301
|
-
addClassMember(classDeclaration, member);
|
|
7302
|
-
}
|
|
7303
|
-
}, { prefixText });
|
|
7336
|
+
}, prepared.members)]
|
|
7337
|
+
}, { prefixText, cache: options.renderCache });
|
|
7304
7338
|
}
|
|
7305
7339
|
function getViewPassthroughMethods(viewName, viewDependencies, componentInstances, componentHierarchyMap, blockedMethodNames = /* @__PURE__ */ new Set()) {
|
|
7306
7340
|
const existingOnView = viewDependencies.generatedMethods ?? /* @__PURE__ */ new Map();
|
|
@@ -7521,35 +7555,32 @@ function renderSplitStubPomContent(options) {
|
|
|
7521
7555
|
"Changes should be made in the generator/template, not in the generated output."
|
|
7522
7556
|
]
|
|
7523
7557
|
});
|
|
7524
|
-
return
|
|
7525
|
-
|
|
7558
|
+
return renderStructuredSourceFile(options.filePath, {
|
|
7559
|
+
// Stub ctors take Playwright's full `Page` (aliased `PwPage`), matching non-stub generated
|
|
7560
|
+
// POMs — stubs are constructed with `new Stub(this.page)` where `this.page` is `Page`.
|
|
7561
|
+
statements: [{
|
|
7562
|
+
kind: StructureKind.ImportDeclaration,
|
|
7526
7563
|
moduleSpecifier: "@playwright/test",
|
|
7527
7564
|
isTypeOnly: true,
|
|
7528
7565
|
namedImports: [{ name: "Page", alias: "PwPage" }]
|
|
7529
|
-
}
|
|
7530
|
-
|
|
7566
|
+
}, {
|
|
7567
|
+
kind: StructureKind.ImportDeclaration,
|
|
7531
7568
|
moduleSpecifier: options.basePageImportSpecifier,
|
|
7532
7569
|
namedImports: ["BasePage"]
|
|
7533
|
-
})
|
|
7534
|
-
|
|
7535
|
-
|
|
7536
|
-
|
|
7537
|
-
|
|
7538
|
-
});
|
|
7539
|
-
}
|
|
7540
|
-
sourceFile.addStatements(buildCommentBlock([
|
|
7541
|
-
"Stub POM generated because it is referenced as a navigation target but",
|
|
7542
|
-
"did not have any generated test ids in this build."
|
|
7543
|
-
]).trimEnd());
|
|
7544
|
-
const classDeclaration = sourceFile.addClass({
|
|
7570
|
+
}, ...options.childImports.map((childImport) => ({
|
|
7571
|
+
kind: StructureKind.ImportDeclaration,
|
|
7572
|
+
moduleSpecifier: childImport.importPath,
|
|
7573
|
+
namedImports: [childImport.className]
|
|
7574
|
+
})), createClassDeclaration({
|
|
7545
7575
|
name: options.className,
|
|
7546
7576
|
isExported: true,
|
|
7547
|
-
extends: "BasePage"
|
|
7548
|
-
|
|
7549
|
-
|
|
7550
|
-
|
|
7551
|
-
|
|
7552
|
-
|
|
7577
|
+
extends: "BasePage",
|
|
7578
|
+
leadingTrivia: buildCommentBlock([
|
|
7579
|
+
"Stub POM generated because it is referenced as a navigation target but",
|
|
7580
|
+
"did not have any generated test ids in this build."
|
|
7581
|
+
])
|
|
7582
|
+
}, options.members)]
|
|
7583
|
+
}, { prefixText, cache: options.renderCache });
|
|
7553
7584
|
}
|
|
7554
7585
|
function getChildImportSpecifiers(outputDir, childClassNames, generatedTsFilePathByComponent) {
|
|
7555
7586
|
return childClassNames.map((childClassName) => {
|
|
@@ -7563,37 +7594,6 @@ function getChildImportSpecifiers(outputDir, childClassNames, generatedTsFilePat
|
|
|
7563
7594
|
};
|
|
7564
7595
|
}).filter((entry) => !!entry).sort((a, b) => a.className.localeCompare(b.className));
|
|
7565
7596
|
}
|
|
7566
|
-
function isConstructorMember(member) {
|
|
7567
|
-
return member.kind === StructureKind.Constructor;
|
|
7568
|
-
}
|
|
7569
|
-
function isGetterMember(member) {
|
|
7570
|
-
return member.kind === StructureKind.GetAccessor;
|
|
7571
|
-
}
|
|
7572
|
-
function isMethodMember(member) {
|
|
7573
|
-
return member.kind === StructureKind.Method;
|
|
7574
|
-
}
|
|
7575
|
-
function isPropertyMember(member) {
|
|
7576
|
-
return member.kind === StructureKind.Property;
|
|
7577
|
-
}
|
|
7578
|
-
function addClassMember(classDeclaration, member) {
|
|
7579
|
-
if (isConstructorMember(member)) {
|
|
7580
|
-
classDeclaration.addConstructor(member);
|
|
7581
|
-
return;
|
|
7582
|
-
}
|
|
7583
|
-
if (isGetterMember(member)) {
|
|
7584
|
-
classDeclaration.addGetAccessor(member);
|
|
7585
|
-
return;
|
|
7586
|
-
}
|
|
7587
|
-
if (isMethodMember(member)) {
|
|
7588
|
-
classDeclaration.addMethod(member);
|
|
7589
|
-
return;
|
|
7590
|
-
}
|
|
7591
|
-
if (isPropertyMember(member)) {
|
|
7592
|
-
classDeclaration.addProperty(member);
|
|
7593
|
-
return;
|
|
7594
|
-
}
|
|
7595
|
-
throw new Error(`Unsupported class member structure: ${String(member)}`);
|
|
7596
|
-
}
|
|
7597
7597
|
function getRuntimeGeneratedAssetSpecs(baseDir, basePageClassPath) {
|
|
7598
7598
|
const runtimeDirAbs = path.join(baseDir, "_pom-runtime");
|
|
7599
7599
|
const runtimeClassGenAbs = path.join(runtimeDirAbs, "class-generation");
|
|
@@ -7871,37 +7871,30 @@ async function generateAggregatedFiles(componentHierarchyMap, vueFilesPathMap, b
|
|
|
7871
7871
|
"Changes should be made in the generator/template, not in the generated output."
|
|
7872
7872
|
]
|
|
7873
7873
|
});
|
|
7874
|
-
return
|
|
7875
|
-
|
|
7876
|
-
|
|
7877
|
-
|
|
7878
|
-
for (const entry of [...classes, ...stubs]) {
|
|
7879
|
-
if (entry.isStub) {
|
|
7880
|
-
sourceFile.addStatements(buildCommentBlock([
|
|
7881
|
-
"Stub POM generated because it is referenced as a navigation target but",
|
|
7882
|
-
"did not have any generated test ids in this build."
|
|
7883
|
-
]).trimEnd());
|
|
7884
|
-
} else {
|
|
7885
|
-
sourceFile.addStatements(entry.doc);
|
|
7886
|
-
}
|
|
7887
|
-
const classDeclaration = sourceFile.addClass({
|
|
7874
|
+
return renderStructuredSourceFile(path.join(outputDir, "page-object-models.g.ts"), {
|
|
7875
|
+
statements: [
|
|
7876
|
+
...imports,
|
|
7877
|
+
...[...classes, ...stubs].map((entry) => createClassDeclaration({
|
|
7888
7878
|
name: entry.className,
|
|
7889
7879
|
isExported: true,
|
|
7890
|
-
extends: "BasePage"
|
|
7891
|
-
|
|
7892
|
-
|
|
7893
|
-
|
|
7894
|
-
|
|
7895
|
-
|
|
7896
|
-
|
|
7880
|
+
extends: "BasePage",
|
|
7881
|
+
leadingTrivia: entry.isStub ? buildCommentBlock([
|
|
7882
|
+
"Stub POM generated because it is referenced as a navigation target but",
|
|
7883
|
+
"did not have any generated test ids in this build."
|
|
7884
|
+
]) : `${entry.doc}
|
|
7885
|
+
`
|
|
7886
|
+
}, entry.members))
|
|
7887
|
+
]
|
|
7888
|
+
}, { prefixText, cache: options.renderCache });
|
|
7897
7889
|
};
|
|
7898
7890
|
const base = ensureDir(outDir);
|
|
7899
7891
|
const outputFile = path.join(base, "page-object-models.g.ts");
|
|
7900
7892
|
const content = makeAggregatedContent(path.dirname(outputFile), [...views, ...components]);
|
|
7901
7893
|
const indexFile = path.join(base, "index.ts");
|
|
7902
|
-
const indexContent =
|
|
7903
|
-
|
|
7894
|
+
const indexContent = renderStructuredSourceFile(indexFile, {
|
|
7895
|
+
statements: [{ kind: StructureKind.ExportDeclaration, moduleSpecifier: "./page-object-models.g" }]
|
|
7904
7896
|
}, {
|
|
7897
|
+
cache: options.renderCache,
|
|
7905
7898
|
prefixText: buildFilePrefix({
|
|
7906
7899
|
eslintDisableSortImports: true,
|
|
7907
7900
|
commentLines: [
|
|
@@ -10718,6 +10711,7 @@ function createDevProcessorPlugin(options) {
|
|
|
10718
10711
|
scheduleVueFileRegen(ctx.file, "hmr");
|
|
10719
10712
|
},
|
|
10720
10713
|
async configureServer(server) {
|
|
10714
|
+
const renderCache = new TypeScriptRenderCache();
|
|
10721
10715
|
const getViewsDirAbs = () => resolveProjectPath(getViewsDir());
|
|
10722
10716
|
const getPageDirsAbs = () => getPageDirs().map((dir) => resolveProjectPath(dir));
|
|
10723
10717
|
const routerInitPromise = (async () => {
|
|
@@ -10925,6 +10919,7 @@ function createDevProcessorPlugin(options) {
|
|
|
10925
10919
|
const generateAggregatedFromSnapshot = async (logLabel) => {
|
|
10926
10920
|
const t0 = performance.now();
|
|
10927
10921
|
await generateFiles(snapshotHierarchy, snapshotVuePathMap, normalizedBasePagePath, {
|
|
10922
|
+
renderCache,
|
|
10928
10923
|
outDir,
|
|
10929
10924
|
emitLanguages,
|
|
10930
10925
|
typescriptOutputStructure,
|
|
@@ -11958,6 +11953,20 @@ const ANNOTATOR_STYLES = `
|
|
|
11958
11953
|
max-width: min(320px, calc(100vw - 24px));
|
|
11959
11954
|
}
|
|
11960
11955
|
|
|
11956
|
+
.vpg-annotator-panel--preview {
|
|
11957
|
+
min-width: min(720px, calc(100vw - 24px));
|
|
11958
|
+
max-width: min(940px, calc(100vw - 24px));
|
|
11959
|
+
}
|
|
11960
|
+
|
|
11961
|
+
.vpg-annotator-panel--preview .vpg-annotator-textarea {
|
|
11962
|
+
height: min(52vh, 440px);
|
|
11963
|
+
resize: vertical;
|
|
11964
|
+
font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
|
|
11965
|
+
white-space: pre;
|
|
11966
|
+
overflow: auto;
|
|
11967
|
+
}
|
|
11968
|
+
|
|
11969
|
+
|
|
11961
11970
|
.vpg-annotator-arrow {
|
|
11962
11971
|
position: absolute;
|
|
11963
11972
|
z-index: 0;
|
|
@@ -12072,18 +12081,6 @@ const ANNOTATOR_STYLES = `
|
|
|
12072
12081
|
margin-top: 12px;
|
|
12073
12082
|
}
|
|
12074
12083
|
|
|
12075
|
-
.vpg-annotator-shortcuts {
|
|
12076
|
-
display: grid;
|
|
12077
|
-
gap: 8px;
|
|
12078
|
-
}
|
|
12079
|
-
|
|
12080
|
-
.vpg-annotator-shortcut-row {
|
|
12081
|
-
display: flex;
|
|
12082
|
-
align-items: center;
|
|
12083
|
-
justify-content: space-between;
|
|
12084
|
-
gap: 12px;
|
|
12085
|
-
}
|
|
12086
|
-
|
|
12087
12084
|
.vpg-annotator-label {
|
|
12088
12085
|
font-size: 12px;
|
|
12089
12086
|
font-weight: 600;
|
|
@@ -12099,20 +12096,6 @@ const ANNOTATOR_STYLES = `
|
|
|
12099
12096
|
padding: 8px 10px;
|
|
12100
12097
|
}
|
|
12101
12098
|
|
|
12102
|
-
.vpg-annotator-kbd {
|
|
12103
|
-
min-width: 32px;
|
|
12104
|
-
padding: 4px 8px;
|
|
12105
|
-
border: 1px solid var(--vpg-annotator-border);
|
|
12106
|
-
border-radius: var(--vpg-annotator-radius);
|
|
12107
|
-
background: rgba(15, 23, 42, 0.72);
|
|
12108
|
-
color: var(--vpg-annotator-text);
|
|
12109
|
-
font: inherit;
|
|
12110
|
-
font-size: 11px;
|
|
12111
|
-
font-weight: 700;
|
|
12112
|
-
line-height: 1;
|
|
12113
|
-
text-align: center;
|
|
12114
|
-
}
|
|
12115
|
-
|
|
12116
12099
|
.vpg-annotator-highlight {
|
|
12117
12100
|
position: fixed;
|
|
12118
12101
|
z-index: 2147483646;
|
|
@@ -12144,6 +12127,7 @@ const ANNOTATOR_STYLES = `
|
|
|
12144
12127
|
inset: 0;
|
|
12145
12128
|
z-index: 2147483645;
|
|
12146
12129
|
background: transparent;
|
|
12130
|
+
cursor: crosshair;
|
|
12147
12131
|
}
|
|
12148
12132
|
|
|
12149
12133
|
.vpg-annotator-marker {
|
|
@@ -12176,6 +12160,34 @@ const ANNOTATOR_STYLES = `
|
|
|
12176
12160
|
font-size: 12px;
|
|
12177
12161
|
font-weight: 600;
|
|
12178
12162
|
}
|
|
12163
|
+
|
|
12164
|
+
.vpg-annotator-heading-row {
|
|
12165
|
+
display: flex;
|
|
12166
|
+
align-items: center;
|
|
12167
|
+
justify-content: space-between;
|
|
12168
|
+
gap: 8px;
|
|
12169
|
+
}
|
|
12170
|
+
|
|
12171
|
+
.vpg-annotator-heading-row .vpg-annotator-heading {
|
|
12172
|
+
margin-bottom: 4px;
|
|
12173
|
+
}
|
|
12174
|
+
|
|
12175
|
+
.vpg-annotator-panel-close {
|
|
12176
|
+
margin-left: auto;
|
|
12177
|
+
background: transparent;
|
|
12178
|
+
border: none;
|
|
12179
|
+
color: var(--vpg-annotator-text-soft);
|
|
12180
|
+
font-size: 16px;
|
|
12181
|
+
line-height: 1;
|
|
12182
|
+
padding: 2px 6px;
|
|
12183
|
+
cursor: pointer;
|
|
12184
|
+
border-radius: var(--vpg-annotator-radius);
|
|
12185
|
+
}
|
|
12186
|
+
|
|
12187
|
+
.vpg-annotator-panel-close:hover {
|
|
12188
|
+
color: var(--vpg-annotator-text);
|
|
12189
|
+
background: var(--vpg-annotator-bg-soft);
|
|
12190
|
+
}
|
|
12179
12191
|
`;
|
|
12180
12192
|
const ignoredComponentNamePattern = /^(?:items\[\d+\]\.template|template|anonymous|slot|transition|transition-group)$/i;
|
|
12181
12193
|
function getDirectVueInstances(element) {
|
|
@@ -12334,35 +12346,15 @@ const TOOLBAR_POSITION_STORAGE_KEY = "vpg-annotator-toolbar-position";
|
|
|
12334
12346
|
const RUNTIME_GUARD = "__VUE_POM_GENERATOR_ANNOTATOR_RUNTIME__";
|
|
12335
12347
|
const TOOLBAR_ICON_MARKUP = {
|
|
12336
12348
|
drag: '<svg viewBox="0 0 16 16"><path d="M5 3h1v1H5zM10 3h1v1h-1zM5 7h1v1H5zM10 7h1v1h-1zM5 11h1v1H5zM10 11h1v1h-1z" fill="currentColor" stroke="none" /></svg>',
|
|
12337
|
-
inspect: '<svg viewBox="0 0 16 16"><path d="M8
|
|
12349
|
+
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>',
|
|
12338
12350
|
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>',
|
|
12339
12351
|
copy: '<svg viewBox="0 0 16 16"><path d="M6 2.5h6.5v9H6z"/><path d="M3.5 5.5H5v6.5h5.5v1.5h-7z"/></svg>',
|
|
12340
12352
|
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>',
|
|
12341
12353
|
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>'
|
|
12342
12354
|
};
|
|
12343
|
-
const SHORTCUT_LABELS = {
|
|
12344
|
-
select: "S",
|
|
12345
|
-
preview: "P",
|
|
12346
|
-
copy: "C",
|
|
12347
|
-
clear: "X",
|
|
12348
|
-
settings: ",",
|
|
12349
|
-
cancel: "Esc"
|
|
12350
|
-
};
|
|
12351
|
-
function formatShortcutTitle(label, shortcut) {
|
|
12352
|
-
return shortcut ? `${label} (${shortcut})` : label;
|
|
12353
|
-
}
|
|
12354
12355
|
function isInsideAnnotatorTree(node) {
|
|
12355
12356
|
return node instanceof Element && !!node.closest(`[${ANNOTATOR_ROOT_ATTR}]`);
|
|
12356
12357
|
}
|
|
12357
|
-
function isEditableTarget(node) {
|
|
12358
|
-
if (!(node instanceof Element)) {
|
|
12359
|
-
return false;
|
|
12360
|
-
}
|
|
12361
|
-
if (node instanceof HTMLInputElement || node instanceof HTMLTextAreaElement || node instanceof HTMLSelectElement) {
|
|
12362
|
-
return true;
|
|
12363
|
-
}
|
|
12364
|
-
return node.closest('[contenteditable=""], [contenteditable="true"]') !== null;
|
|
12365
|
-
}
|
|
12366
12358
|
function getElementSummary(element) {
|
|
12367
12359
|
const testId = element.getAttribute("data-testid");
|
|
12368
12360
|
if (testId) {
|
|
@@ -12427,10 +12419,7 @@ function createButtonBase(label, onClick, options = {}) {
|
|
|
12427
12419
|
button.className = `vpg-annotator-btn${options.primary ? " vpg-annotator-btn--primary" : ""}`;
|
|
12428
12420
|
button.setAttribute(ANNOTATOR_ROOT_ATTR, "");
|
|
12429
12421
|
button.setAttribute("aria-label", label);
|
|
12430
|
-
button.title =
|
|
12431
|
-
if (options.shortcut) {
|
|
12432
|
-
button.setAttribute("aria-keyshortcuts", options.shortcut);
|
|
12433
|
-
}
|
|
12422
|
+
button.title = label;
|
|
12434
12423
|
if (options.pressed) {
|
|
12435
12424
|
button.setAttribute("aria-pressed", "true");
|
|
12436
12425
|
}
|
|
@@ -12570,23 +12559,18 @@ class AnnotatorRuntime {
|
|
|
12570
12559
|
count.textContent = `${this.annotations.length} annotation${this.annotations.length === 1 ? "" : "s"}`;
|
|
12571
12560
|
const selectButton = createIconButton(this.inspectMode ? "Stop selecting" : "Select element", "inspect", () => {
|
|
12572
12561
|
this.setInspectMode(!this.inspectMode);
|
|
12573
|
-
}, { primary: this.inspectMode, pressed: this.inspectMode
|
|
12562
|
+
}, { primary: this.inspectMode, pressed: this.inspectMode });
|
|
12574
12563
|
const previewButton = createIconButton("Preview annotations", "preview", () => this.openPreview(), {
|
|
12575
|
-
disabled: this.annotations.length === 0
|
|
12576
|
-
shortcut: SHORTCUT_LABELS.preview
|
|
12564
|
+
disabled: this.annotations.length === 0
|
|
12577
12565
|
});
|
|
12578
12566
|
this.previewButton = previewButton;
|
|
12579
12567
|
const copyButton = createIconButton("Copy annotations", "copy", () => this.copyAnnotations(), {
|
|
12580
|
-
disabled: this.annotations.length === 0
|
|
12581
|
-
shortcut: SHORTCUT_LABELS.copy
|
|
12568
|
+
disabled: this.annotations.length === 0
|
|
12582
12569
|
});
|
|
12583
12570
|
const clearButton = createIconButton("Clear annotations", "clear", () => this.clearAnnotations(), {
|
|
12584
|
-
disabled: this.annotations.length === 0
|
|
12585
|
-
shortcut: SHORTCUT_LABELS.clear
|
|
12586
|
-
});
|
|
12587
|
-
const settingsButton = createIconButton("Annotator settings", "settings", () => this.openSettings(), {
|
|
12588
|
-
shortcut: SHORTCUT_LABELS.settings
|
|
12571
|
+
disabled: this.annotations.length === 0
|
|
12589
12572
|
});
|
|
12573
|
+
const settingsButton = createIconButton("Annotator settings", "settings", () => this.openSettings());
|
|
12590
12574
|
this.settingsButton = settingsButton;
|
|
12591
12575
|
this.toolbarEl.append(handle, selectButton, previewButton, copyButton, clearButton, settingsButton, count);
|
|
12592
12576
|
this.applyToolbarPosition();
|
|
@@ -12617,7 +12601,6 @@ class AnnotatorRuntime {
|
|
|
12617
12601
|
this.renderMarkers();
|
|
12618
12602
|
this.applyToolbarPosition();
|
|
12619
12603
|
});
|
|
12620
|
-
window.addEventListener("keydown", (event) => this.onWindowKeyDown(event), true);
|
|
12621
12604
|
}
|
|
12622
12605
|
loadSettings() {
|
|
12623
12606
|
try {
|
|
@@ -12744,60 +12727,6 @@ class AnnotatorRuntime {
|
|
|
12744
12727
|
window.addEventListener("pointercancel", onPointerUp);
|
|
12745
12728
|
});
|
|
12746
12729
|
}
|
|
12747
|
-
onWindowKeyDown(event) {
|
|
12748
|
-
if (event.defaultPrevented || event.metaKey || event.ctrlKey || event.altKey) {
|
|
12749
|
-
return;
|
|
12750
|
-
}
|
|
12751
|
-
if (event.key === "Escape") {
|
|
12752
|
-
if (!this.inspectMode && !this.currentPanelEl) {
|
|
12753
|
-
return;
|
|
12754
|
-
}
|
|
12755
|
-
event.preventDefault();
|
|
12756
|
-
if (this.inspectMode) {
|
|
12757
|
-
this.setInspectMode(false);
|
|
12758
|
-
} else {
|
|
12759
|
-
this.closePanel();
|
|
12760
|
-
}
|
|
12761
|
-
return;
|
|
12762
|
-
}
|
|
12763
|
-
if (isEditableTarget(event.target)) {
|
|
12764
|
-
return;
|
|
12765
|
-
}
|
|
12766
|
-
const key = event.key.toLowerCase();
|
|
12767
|
-
if (key === SHORTCUT_LABELS.select.toLowerCase()) {
|
|
12768
|
-
event.preventDefault();
|
|
12769
|
-
this.setInspectMode(!this.inspectMode);
|
|
12770
|
-
return;
|
|
12771
|
-
}
|
|
12772
|
-
if (key === SHORTCUT_LABELS.preview.toLowerCase()) {
|
|
12773
|
-
if (!this.annotations.length) {
|
|
12774
|
-
return;
|
|
12775
|
-
}
|
|
12776
|
-
event.preventDefault();
|
|
12777
|
-
this.openPreview();
|
|
12778
|
-
return;
|
|
12779
|
-
}
|
|
12780
|
-
if (key === SHORTCUT_LABELS.copy.toLowerCase()) {
|
|
12781
|
-
if (!this.annotations.length) {
|
|
12782
|
-
return;
|
|
12783
|
-
}
|
|
12784
|
-
event.preventDefault();
|
|
12785
|
-
void this.copyAnnotations();
|
|
12786
|
-
return;
|
|
12787
|
-
}
|
|
12788
|
-
if (key === SHORTCUT_LABELS.clear.toLowerCase()) {
|
|
12789
|
-
if (!this.annotations.length) {
|
|
12790
|
-
return;
|
|
12791
|
-
}
|
|
12792
|
-
event.preventDefault();
|
|
12793
|
-
this.clearAnnotations();
|
|
12794
|
-
return;
|
|
12795
|
-
}
|
|
12796
|
-
if (event.key === SHORTCUT_LABELS.settings) {
|
|
12797
|
-
event.preventDefault();
|
|
12798
|
-
this.openSettings();
|
|
12799
|
-
}
|
|
12800
|
-
}
|
|
12801
12730
|
setInspectMode(next) {
|
|
12802
12731
|
this.inspectMode = next;
|
|
12803
12732
|
this.shieldEl.hidden = !next;
|
|
@@ -12982,11 +12911,21 @@ class AnnotatorRuntime {
|
|
|
12982
12911
|
this.editingAnnotationId = annotation.id;
|
|
12983
12912
|
this.openInputForDraft(reference);
|
|
12984
12913
|
}
|
|
12914
|
+
createPanelCloseButton(ariaLabel) {
|
|
12915
|
+
const closeButton = document.createElement("button");
|
|
12916
|
+
closeButton.type = "button";
|
|
12917
|
+
closeButton.className = "vpg-annotator-panel-close";
|
|
12918
|
+
closeButton.setAttribute(ANNOTATOR_ROOT_ATTR, "");
|
|
12919
|
+
closeButton.setAttribute("aria-label", ariaLabel);
|
|
12920
|
+
closeButton.textContent = "×";
|
|
12921
|
+
closeButton.addEventListener("click", () => this.closePanel());
|
|
12922
|
+
return closeButton;
|
|
12923
|
+
}
|
|
12985
12924
|
openPreview() {
|
|
12986
12925
|
if (!this.previewButton || this.annotations.length === 0) {
|
|
12987
12926
|
return;
|
|
12988
12927
|
}
|
|
12989
|
-
const { panel, body, arrowEl } = this.createPanelBase("vpg-annotator-panel");
|
|
12928
|
+
const { panel, body, arrowEl } = this.createPanelBase("vpg-annotator-panel vpg-annotator-panel--preview");
|
|
12990
12929
|
const title = document.createElement("div");
|
|
12991
12930
|
title.className = "vpg-annotator-heading";
|
|
12992
12931
|
title.textContent = "Annotation preview";
|
|
@@ -12997,7 +12936,10 @@ class AnnotatorRuntime {
|
|
|
12997
12936
|
textarea.className = "vpg-annotator-textarea";
|
|
12998
12937
|
textarea.readOnly = true;
|
|
12999
12938
|
textarea.value = formatAnnotations(this.annotations, this.settings.outputDetail, window.location.href);
|
|
13000
|
-
|
|
12939
|
+
const headerRow = document.createElement("div");
|
|
12940
|
+
headerRow.className = "vpg-annotator-heading-row";
|
|
12941
|
+
headerRow.append(title, this.createPanelCloseButton("Close preview"));
|
|
12942
|
+
body.append(headerRow, subtitle, textarea);
|
|
13001
12943
|
this.showPanel(panel, () => this.attachFloating(this.previewButton, panel, arrowEl, "top-start", ["top-start", "left-start", "top-end", "left-end"]));
|
|
13002
12944
|
}
|
|
13003
12945
|
openSettings() {
|
|
@@ -13036,35 +12978,7 @@ class AnnotatorRuntime {
|
|
|
13036
12978
|
this.saveSettings();
|
|
13037
12979
|
});
|
|
13038
12980
|
showComponentField.append(showComponentCopy, showComponentCheckbox);
|
|
13039
|
-
|
|
13040
|
-
shortcutsField.className = "vpg-annotator-field";
|
|
13041
|
-
const shortcutsLabel = document.createElement("div");
|
|
13042
|
-
shortcutsLabel.className = "vpg-annotator-label";
|
|
13043
|
-
shortcutsLabel.textContent = "Keyboard shortcuts";
|
|
13044
|
-
const shortcutsList = document.createElement("div");
|
|
13045
|
-
shortcutsList.className = "vpg-annotator-shortcuts";
|
|
13046
|
-
for (const [shortcut, description] of [
|
|
13047
|
-
[SHORTCUT_LABELS.select, "Toggle selection mode"],
|
|
13048
|
-
[SHORTCUT_LABELS.preview, "Open preview"],
|
|
13049
|
-
[SHORTCUT_LABELS.copy, "Copy annotations"],
|
|
13050
|
-
[SHORTCUT_LABELS.clear, "Clear annotations"],
|
|
13051
|
-
[SHORTCUT_LABELS.settings, "Open settings"],
|
|
13052
|
-
[SHORTCUT_LABELS.cancel, "Close panel / cancel selection"]
|
|
13053
|
-
]) {
|
|
13054
|
-
const row = document.createElement("div");
|
|
13055
|
-
row.className = "vpg-annotator-shortcut-row";
|
|
13056
|
-
const text = document.createElement("span");
|
|
13057
|
-
text.className = "vpg-annotator-subtle";
|
|
13058
|
-
text.textContent = description;
|
|
13059
|
-
const kbd = document.createElement("kbd");
|
|
13060
|
-
kbd.className = "vpg-annotator-kbd";
|
|
13061
|
-
kbd.setAttribute(ANNOTATOR_ROOT_ATTR, "");
|
|
13062
|
-
kbd.textContent = shortcut;
|
|
13063
|
-
row.append(text, kbd);
|
|
13064
|
-
shortcutsList.appendChild(row);
|
|
13065
|
-
}
|
|
13066
|
-
shortcutsField.append(shortcutsLabel, shortcutsList);
|
|
13067
|
-
body.append(title, detailField, showComponentField, shortcutsField);
|
|
12981
|
+
body.append(title, detailField, showComponentField);
|
|
13068
12982
|
this.showPanel(panel, () => this.attachFloating(this.settingsButton, panel, arrowEl, "top-start", ["top-start", "left-start", "top-end", "left-end"]));
|
|
13069
12983
|
}
|
|
13070
12984
|
disposeCurrentPanel() {
|