@nuasite/cms 0.39.1 → 0.39.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/editor.js CHANGED
@@ -381,7 +381,7 @@ function WS(t, e) {
381
381
  function KS(t, e) {
382
382
  return typeof e == "function" ? e(t) : e;
383
383
  }
384
- const v3 = "0.39.1", k3 = v3, nt = {
384
+ const v3 = "0.39.2", k3 = v3, nt = {
385
385
  /** Highlight overlay for hovered elements */
386
386
  HIGHLIGHT: 2147483644,
387
387
  /** Hover outline for elements/components */
package/package.json CHANGED
@@ -14,7 +14,7 @@
14
14
  "directory": "packages/astro-cms"
15
15
  },
16
16
  "license": "Apache-2.0",
17
- "version": "0.39.1",
17
+ "version": "0.39.2",
18
18
  "module": "src/index.ts",
19
19
  "types": "src/index.ts",
20
20
  "type": "module",
@@ -382,7 +382,7 @@ async function processFile(
382
382
  // The sourcePath from HTML attributes may point to a shared Image component
383
383
  // rather than the file that actually uses the component with the src value
384
384
  if (entry.imageMetadata?.src) {
385
- const preferredLocation = entry.sourcePath
385
+ const preferredLocation = entry.sourcePath || entry.imageMetadata.srcOccurrence !== undefined
386
386
  ? {
387
387
  file: entry.sourcePath,
388
388
  line: entry.sourceLine,
@@ -598,7 +598,7 @@ export async function enhanceManifestInBackground(
598
598
  for (const entry of Object.values(enhanced)) {
599
599
  if (entry.sourceSnippet || entry.sourcePath) continue
600
600
  if (entry.imageMetadata?.src) {
601
- const preferredLocation = entry.sourcePath
601
+ const preferredLocation = entry.sourcePath || entry.imageMetadata.srcOccurrence !== undefined
602
602
  ? {
603
603
  file: entry.sourcePath,
604
604
  line: entry.sourceLine,
@@ -151,7 +151,7 @@ export async function findImageSourceLocation(
151
151
  imageSrc: string,
152
152
  imageSrcSet?: string,
153
153
  pageFiles?: readonly string[],
154
- preferredLocation?: { file: string; line?: number; srcOccurrence?: number },
154
+ preferredLocation?: { file?: string; line?: number; srcOccurrence?: number },
155
155
  ): Promise<SourceLocation | undefined> {
156
156
  // Use index if available (much faster)
157
157
  if (isSearchIndexInitialized()) {
@@ -1436,7 +1436,7 @@ function extractPathname(src: string): string {
1436
1436
  export function findInImageIndex(
1437
1437
  imageSrc: string,
1438
1438
  pageFiles?: readonly string[],
1439
- preferredLocation?: { file: string; line?: number; srcOccurrence?: number },
1439
+ preferredLocation?: { file?: string; line?: number; srcOccurrence?: number },
1440
1440
  ): SourceLocation | undefined {
1441
1441
  const index = getImageSearchIndex()
1442
1442
 
@@ -1446,7 +1446,7 @@ export function findInImageIndex(
1446
1446
  const candidates = decoded && decoded !== imageSrc ? [imageSrc, decoded] : [imageSrc]
1447
1447
  // Astro stamps absolute paths in `data-astro-source-file`; the index uses
1448
1448
  // project-relative paths. Normalize before comparing.
1449
- const preferredFile = preferredLocation ? toProjectRelativePath(preferredLocation.file) : undefined
1449
+ const preferredFile = preferredLocation?.file ? toProjectRelativePath(preferredLocation.file) : undefined
1450
1450
  const preferredLine = preferredLocation?.line
1451
1451
  const preferredOccurrence = preferredLocation?.srcOccurrence
1452
1452
 
@@ -1454,13 +1454,21 @@ export function findInImageIndex(
1454
1454
  let occurrenceCounter = 0
1455
1455
  let occurrenceMatch: SourceLocation | undefined
1456
1456
  let lineMatch: SourceLocation | undefined
1457
+ const pageSet = pageFiles?.length ? new Set(pageFiles) : undefined
1458
+ // Scope occurrence counting: if preferredFile is set, only that file.
1459
+ // Otherwise fall back to pageFiles. Otherwise count across the whole index.
1460
+ const occurrenceScope = (file: string): boolean => {
1461
+ if (preferredFile) return file === preferredFile
1462
+ if (pageSet) return pageSet.has(file)
1463
+ return true
1464
+ }
1457
1465
  for (const entry of index) {
1458
1466
  if (!candidates.includes(entry.src)) continue
1459
- if (preferredFile && entry.file === preferredFile) {
1467
+ if (occurrenceScope(entry.file)) {
1460
1468
  if (preferredOccurrence !== undefined && occurrenceCounter++ === preferredOccurrence) {
1461
1469
  occurrenceMatch ??= imageEntryToLocation(entry)
1462
1470
  }
1463
- if (preferredLine !== undefined && entry.line === preferredLine) {
1471
+ if (preferredLine !== undefined && entry.line === preferredLine && (!preferredFile || entry.file === preferredFile)) {
1464
1472
  lineMatch ??= imageEntryToLocation(entry)
1465
1473
  }
1466
1474
  }
@@ -751,7 +751,10 @@ export async function enhanceManifestWithSourceSnippets(
751
751
  }
752
752
 
753
753
  // ── Non-collection images: find via search index / AST ──
754
- const preferredLocation = entry.sourcePath
754
+ // Always pass preferredLocation when srcOccurrence is set, even if
755
+ // entry.sourcePath is missing — html-processor populates srcOccurrence
756
+ // independently of Astro's source attribution.
757
+ const preferredLocation = entry.sourcePath || entry.imageMetadata.srcOccurrence !== undefined
755
758
  ? {
756
759
  file: entry.sourcePath,
757
760
  line: entry.sourceLine,