@nuasite/cms 0.25.0 → 0.27.0
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 +23390 -23278
- package/package.json +1 -1
- package/src/build-processor.ts +0 -2
- package/src/collection-scanner.ts +4 -4
- package/src/dev-middleware.ts +25 -18
- package/src/editor/components/markdown-editor-overlay.tsx +37 -0
- package/src/editor/components/mdx-block-view.tsx +131 -24
- package/src/editor/milkdown-mdx-plugin.tsx +5 -0
- package/src/field-types.ts +27 -22
- package/src/index.ts +20 -9
- package/src/pages/component-preview.astro +56 -0
- package/src/source-finder/cache.ts +13 -1
- package/src/source-finder/collection-finder.ts +6 -12
- package/src/source-finder/index.ts +0 -1
- package/src/source-finder/search-index.ts +2 -2
- package/src/vite-plugin.ts +9 -0
|
@@ -4,7 +4,7 @@ import { isMap, isPair, isScalar, isSeq, LineCounter, parseDocument } from 'yaml
|
|
|
4
4
|
|
|
5
5
|
import { getProjectRoot } from '../config'
|
|
6
6
|
import type { CollectionDefinition } from '../types'
|
|
7
|
-
import { getMarkdownFileCache } from './cache'
|
|
7
|
+
import { getCollectionTextIndex, getMarkdownFileCache, setCollectionTextIndex } from './cache'
|
|
8
8
|
import { normalizeText } from './snippet-utils'
|
|
9
9
|
import type { CollectionInfo, MarkdownContent, SourceLocation } from './types'
|
|
10
10
|
|
|
@@ -12,8 +12,6 @@ import type { CollectionInfo, MarkdownContent, SourceLocation } from './types'
|
|
|
12
12
|
// Collection Text Index — pre-built reverse index for fast text→source lookups
|
|
13
13
|
// ============================================================================
|
|
14
14
|
|
|
15
|
-
/** Pre-built index: normalizedText → SourceLocation (with collection metadata) */
|
|
16
|
-
let collectionTextIndex: Map<string, SourceLocation[]> | null = null
|
|
17
15
|
let collectionTextIndexPromise: Promise<void> | null = null
|
|
18
16
|
|
|
19
17
|
/**
|
|
@@ -23,7 +21,7 @@ let collectionTextIndexPromise: Promise<void> | null = null
|
|
|
23
21
|
export async function buildCollectionTextIndex(
|
|
24
22
|
collections: Record<string, CollectionDefinition>,
|
|
25
23
|
): Promise<void> {
|
|
26
|
-
if (
|
|
24
|
+
if (getCollectionTextIndex()) return
|
|
27
25
|
if (collectionTextIndexPromise) return collectionTextIndexPromise
|
|
28
26
|
collectionTextIndexPromise = doBuildCollectionTextIndex(collections)
|
|
29
27
|
try {
|
|
@@ -76,7 +74,7 @@ async function doBuildCollectionTextIndex(
|
|
|
76
74
|
}))
|
|
77
75
|
}
|
|
78
76
|
|
|
79
|
-
|
|
77
|
+
setCollectionTextIndex(index)
|
|
80
78
|
}
|
|
81
79
|
|
|
82
80
|
/**
|
|
@@ -168,9 +166,10 @@ export function lookupCollectionText(
|
|
|
168
166
|
textContent: string,
|
|
169
167
|
referenceIndex?: Map<string, Array<{ collection: string; fieldName: string; isArray?: boolean }>>,
|
|
170
168
|
): SourceLocation | undefined {
|
|
171
|
-
|
|
169
|
+
const index = getCollectionTextIndex()
|
|
170
|
+
if (!index) return undefined
|
|
172
171
|
const normalized = normalizeText(textContent)
|
|
173
|
-
const locations =
|
|
172
|
+
const locations = index.get(normalized)
|
|
174
173
|
if (!locations || locations.length === 0) return undefined
|
|
175
174
|
|
|
176
175
|
// Prefer locations from referenced collections
|
|
@@ -184,11 +183,6 @@ export function lookupCollectionText(
|
|
|
184
183
|
return locations[0]
|
|
185
184
|
}
|
|
186
185
|
|
|
187
|
-
/** Clear the collection text index (called when collection files change) */
|
|
188
|
-
export function clearCollectionTextIndex(): void {
|
|
189
|
-
collectionTextIndex = null
|
|
190
|
-
}
|
|
191
|
-
|
|
192
186
|
// ============================================================================
|
|
193
187
|
// Markdown File Cache
|
|
194
188
|
// ============================================================================
|
|
@@ -17,9 +17,9 @@ import {
|
|
|
17
17
|
getTextSearchIndex,
|
|
18
18
|
isSearchIndexInitialized,
|
|
19
19
|
removeFileFromIndexes,
|
|
20
|
+
setCollectionTextIndex,
|
|
20
21
|
setSearchIndexInitialized,
|
|
21
22
|
} from './cache'
|
|
22
|
-
import { clearCollectionTextIndex } from './collection-finder'
|
|
23
23
|
import { extractImageSnippet, extractInnerHtmlFromSnippet, normalizeText } from './snippet-utils'
|
|
24
24
|
import type { CachedParsedFile, SearchIndexEntry, SourceLocation } from './types'
|
|
25
25
|
|
|
@@ -167,7 +167,7 @@ async function doReindexDirtyFiles(): Promise<void> {
|
|
|
167
167
|
// Also clear the markdown file cache and collection text index
|
|
168
168
|
// so collection content is re-read and re-indexed from disk
|
|
169
169
|
getMarkdownFileCache().clear()
|
|
170
|
-
|
|
170
|
+
setCollectionTextIndex(null)
|
|
171
171
|
|
|
172
172
|
for (const absPath of filesToReindex) {
|
|
173
173
|
const relFile = path.relative(projectRoot, absPath)
|
package/src/vite-plugin.ts
CHANGED
|
@@ -28,6 +28,9 @@ export function createVitePlugin(context: VitePluginContext): Plugin[] {
|
|
|
28
28
|
if (id === '/@cms/components' || id === 'virtual:cms-components') {
|
|
29
29
|
return '\0virtual:cms-components'
|
|
30
30
|
}
|
|
31
|
+
if (id === 'virtual:cms-component-preview') {
|
|
32
|
+
return '\0virtual:cms-component-preview'
|
|
33
|
+
}
|
|
31
34
|
},
|
|
32
35
|
load(id) {
|
|
33
36
|
if (id === '\0virtual:cms-manifest') {
|
|
@@ -36,6 +39,12 @@ export function createVitePlugin(context: VitePluginContext): Plugin[] {
|
|
|
36
39
|
if (id === '\0virtual:cms-components') {
|
|
37
40
|
return `export default ${JSON.stringify(componentDefinitions)};`
|
|
38
41
|
}
|
|
42
|
+
if (id === '\0virtual:cms-component-preview') {
|
|
43
|
+
const entries = Object.values(componentDefinitions).map(
|
|
44
|
+
(def) => ` ${JSON.stringify(def.file)}: () => import(${JSON.stringify('/' + def.file)})`,
|
|
45
|
+
)
|
|
46
|
+
return `export const components = {\n${entries.join(',\n')}\n};`
|
|
47
|
+
}
|
|
39
48
|
},
|
|
40
49
|
}
|
|
41
50
|
|