@imjp/writenex-astro 0.1.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/README.md +539 -0
- package/dist/chunk-5PM6EQE5.js +151 -0
- package/dist/chunk-5PM6EQE5.js.map +1 -0
- package/dist/chunk-7XU5X6CW.js +1331 -0
- package/dist/chunk-7XU5X6CW.js.map +1 -0
- package/dist/chunk-AAOQHQPU.js +574 -0
- package/dist/chunk-AAOQHQPU.js.map +1 -0
- package/dist/chunk-CF2XXJFF.js +1410 -0
- package/dist/chunk-CF2XXJFF.js.map +1 -0
- package/dist/chunk-CRPZUUDU.js +52 -0
- package/dist/chunk-CRPZUUDU.js.map +1 -0
- package/dist/chunk-CYLDJ3HZ.js +310 -0
- package/dist/chunk-CYLDJ3HZ.js.map +1 -0
- package/dist/chunk-KIKIPIFA.js +1 -0
- package/dist/chunk-KIKIPIFA.js.map +1 -0
- package/dist/chunk-XNTQTTJU.js +145 -0
- package/dist/chunk-XNTQTTJU.js.map +1 -0
- package/dist/client/index.css +2 -0
- package/dist/client/index.css.map +1 -0
- package/dist/client/index.js +375 -0
- package/dist/client/index.js.map +1 -0
- package/dist/client/styles.css +584 -0
- package/dist/client/variables.css +304 -0
- package/dist/config/index.d.ts +54 -0
- package/dist/config/index.js +38 -0
- package/dist/config/index.js.map +1 -0
- package/dist/config-BmEdBDo_.d.ts +220 -0
- package/dist/content-BWR52vD-.d.ts +64 -0
- package/dist/discovery/index.d.ts +310 -0
- package/dist/discovery/index.js +38 -0
- package/dist/discovery/index.js.map +1 -0
- package/dist/errors-C0iYiDTv.d.ts +107 -0
- package/dist/filesystem/index.d.ts +1292 -0
- package/dist/filesystem/index.js +203 -0
- package/dist/filesystem/index.js.map +1 -0
- package/dist/image-FP7w5ZIs.d.ts +47 -0
- package/dist/index.d.ts +64 -0
- package/dist/index.js +151 -0
- package/dist/index.js.map +1 -0
- package/dist/loader-55LWCXHA.js +12 -0
- package/dist/loader-55LWCXHA.js.map +1 -0
- package/dist/loader-CrdnaAWR.d.ts +327 -0
- package/dist/server/index.d.ts +357 -0
- package/dist/server/index.js +37 -0
- package/dist/server/index.js.map +1 -0
- package/package.json +94 -0
- package/src/client/App.tsx +900 -0
- package/src/client/components/ConfigPanel/ConfigPanel.css +553 -0
- package/src/client/components/ConfigPanel/ConfigPanel.tsx +396 -0
- package/src/client/components/ConfigPanel/index.ts +6 -0
- package/src/client/components/CreateContentModal/CreateContentModal.css +327 -0
- package/src/client/components/CreateContentModal/CreateContentModal.tsx +216 -0
- package/src/client/components/CreateContentModal/index.ts +7 -0
- package/src/client/components/Editor/Editor.css +885 -0
- package/src/client/components/Editor/Editor.tsx +484 -0
- package/src/client/components/Editor/ImageDialog.css +344 -0
- package/src/client/components/Editor/ImageDialog.tsx +367 -0
- package/src/client/components/Editor/LinkDialog.css +326 -0
- package/src/client/components/Editor/LinkDialog.tsx +332 -0
- package/src/client/components/Editor/index.ts +6 -0
- package/src/client/components/FrontmatterForm/FrontmatterForm.css +468 -0
- package/src/client/components/FrontmatterForm/FrontmatterForm.tsx +914 -0
- package/src/client/components/FrontmatterForm/index.ts +7 -0
- package/src/client/components/Header/Header.css +300 -0
- package/src/client/components/Header/Header.tsx +300 -0
- package/src/client/components/Header/index.ts +7 -0
- package/src/client/components/KeyboardShortcuts/KeyboardShortcuts.css +239 -0
- package/src/client/components/KeyboardShortcuts/KeyboardShortcuts.tsx +151 -0
- package/src/client/components/KeyboardShortcuts/index.ts +6 -0
- package/src/client/components/LazyEditor.tsx +75 -0
- package/src/client/components/LiveRegion/LiveRegion.css +19 -0
- package/src/client/components/LiveRegion/LiveRegion.tsx +60 -0
- package/src/client/components/LiveRegion/index.ts +7 -0
- package/src/client/components/SearchReplace/SearchReplacePanel.css +300 -0
- package/src/client/components/SearchReplace/SearchReplacePanel.tsx +332 -0
- package/src/client/components/SearchReplace/index.ts +7 -0
- package/src/client/components/SelectCollectionModal/SelectCollectionModal.css +308 -0
- package/src/client/components/SelectCollectionModal/SelectCollectionModal.tsx +223 -0
- package/src/client/components/SelectCollectionModal/index.ts +7 -0
- package/src/client/components/Sidebar/Sidebar.css +570 -0
- package/src/client/components/Sidebar/Sidebar.tsx +617 -0
- package/src/client/components/Sidebar/index.ts +7 -0
- package/src/client/components/SkipLink/SkipLink.css +51 -0
- package/src/client/components/SkipLink/SkipLink.tsx +67 -0
- package/src/client/components/SkipLink/index.ts +7 -0
- package/src/client/components/UnsavedChangesModal/UnsavedChangesModal.css +233 -0
- package/src/client/components/UnsavedChangesModal/UnsavedChangesModal.tsx +160 -0
- package/src/client/components/UnsavedChangesModal/index.ts +1 -0
- package/src/client/components/VersionHistory/DiffViewer.css +430 -0
- package/src/client/components/VersionHistory/DiffViewer.tsx +383 -0
- package/src/client/components/VersionHistory/VersionActions.css +318 -0
- package/src/client/components/VersionHistory/VersionActions.tsx +277 -0
- package/src/client/components/VersionHistory/VersionHistoryPanel.css +369 -0
- package/src/client/components/VersionHistory/VersionHistoryPanel.tsx +469 -0
- package/src/client/components/VersionHistory/index.ts +9 -0
- package/src/client/context/ApiContext.tsx +154 -0
- package/src/client/context/ThemeContext.tsx +172 -0
- package/src/client/hooks/useAnnounce.ts +201 -0
- package/src/client/hooks/useApi.ts +374 -0
- package/src/client/hooks/useArrowNavigation.ts +286 -0
- package/src/client/hooks/useAutosave.ts +241 -0
- package/src/client/hooks/useFocusTrap.ts +178 -0
- package/src/client/hooks/useKeyboardShortcuts.ts +203 -0
- package/src/client/hooks/useSearch.ts +206 -0
- package/src/client/hooks/useVersionHistory.ts +451 -0
- package/src/client/index.tsx +70 -0
- package/src/client/styles.css +584 -0
- package/src/client/utils/focus.ts +57 -0
- package/src/client/utils/openInEditor.ts +130 -0
- package/src/client/variables.css +304 -0
- package/src/config/defaults.ts +109 -0
- package/src/config/index.ts +32 -0
- package/src/config/loader.ts +174 -0
- package/src/config/schema.ts +161 -0
- package/src/core/constants.ts +39 -0
- package/src/core/errors.ts +739 -0
- package/src/core/index.ts +11 -0
- package/src/discovery/collections.ts +216 -0
- package/src/discovery/index.ts +33 -0
- package/src/discovery/patterns.ts +702 -0
- package/src/discovery/schema.ts +453 -0
- package/src/filesystem/images.ts +798 -0
- package/src/filesystem/index.ts +107 -0
- package/src/filesystem/reader.ts +452 -0
- package/src/filesystem/version-config.ts +390 -0
- package/src/filesystem/versions.ts +1339 -0
- package/src/filesystem/watcher.ts +226 -0
- package/src/filesystem/writer.ts +540 -0
- package/src/index.ts +61 -0
- package/src/integration.ts +228 -0
- package/src/server/assets.ts +254 -0
- package/src/server/cache.ts +355 -0
- package/src/server/index.ts +33 -0
- package/src/server/middleware.ts +209 -0
- package/src/server/routes.ts +1428 -0
- package/src/types/api.ts +61 -0
- package/src/types/config.ts +134 -0
- package/src/types/content.ts +64 -0
- package/src/types/image.ts +48 -0
- package/src/types/index.ts +58 -0
- package/src/types/version.ts +117 -0
|
@@ -0,0 +1,203 @@
|
|
|
1
|
+
import {
|
|
2
|
+
ContentWatcher,
|
|
3
|
+
FileModificationTracker,
|
|
4
|
+
createContentWatcher
|
|
5
|
+
} from "../chunk-XNTQTTJU.js";
|
|
6
|
+
import {
|
|
7
|
+
DEFAULT_IMAGE_CONFIG,
|
|
8
|
+
calculateRelativePath,
|
|
9
|
+
clearVersions,
|
|
10
|
+
createContent,
|
|
11
|
+
createEmptyManifest,
|
|
12
|
+
deleteContent,
|
|
13
|
+
deleteVersion,
|
|
14
|
+
detectContentStructure,
|
|
15
|
+
discoverContentImages,
|
|
16
|
+
ensureGitignore,
|
|
17
|
+
ensureStorageDirectory,
|
|
18
|
+
generatePreview,
|
|
19
|
+
generateSlug,
|
|
20
|
+
generateUniqueSlug,
|
|
21
|
+
generateVersionId,
|
|
22
|
+
getContentImageFolder,
|
|
23
|
+
getManifestPath,
|
|
24
|
+
getOrRecoverManifest,
|
|
25
|
+
getVersion,
|
|
26
|
+
getVersionFilePath,
|
|
27
|
+
getVersionStoragePath,
|
|
28
|
+
getVersions,
|
|
29
|
+
isValidImageFile,
|
|
30
|
+
parseMultipartFormData,
|
|
31
|
+
parseVersionId,
|
|
32
|
+
pruneVersions,
|
|
33
|
+
readManifest,
|
|
34
|
+
recoverManifest,
|
|
35
|
+
restoreVersion,
|
|
36
|
+
saveVersion,
|
|
37
|
+
scanDirectoryForImages,
|
|
38
|
+
updateContent,
|
|
39
|
+
uploadImage,
|
|
40
|
+
writeManifest
|
|
41
|
+
} from "../chunk-CF2XXJFF.js";
|
|
42
|
+
import {
|
|
43
|
+
checkCollection,
|
|
44
|
+
extractSlug,
|
|
45
|
+
generateExcerpt,
|
|
46
|
+
getCollectionCount,
|
|
47
|
+
getCollectionSummaries,
|
|
48
|
+
getContentFilePath,
|
|
49
|
+
getFileStats,
|
|
50
|
+
isContentFile,
|
|
51
|
+
readCollection,
|
|
52
|
+
readContentFile,
|
|
53
|
+
toContentSummary
|
|
54
|
+
} from "../chunk-AAOQHQPU.js";
|
|
55
|
+
import {
|
|
56
|
+
DEFAULT_VERSION_HISTORY_CONFIG
|
|
57
|
+
} from "../chunk-CRPZUUDU.js";
|
|
58
|
+
|
|
59
|
+
// src/filesystem/version-config.ts
|
|
60
|
+
function resolveVersionConfig(config) {
|
|
61
|
+
if (!config) {
|
|
62
|
+
return { ...DEFAULT_VERSION_HISTORY_CONFIG };
|
|
63
|
+
}
|
|
64
|
+
return {
|
|
65
|
+
enabled: config.enabled ?? DEFAULT_VERSION_HISTORY_CONFIG.enabled,
|
|
66
|
+
maxVersions: config.maxVersions ?? DEFAULT_VERSION_HISTORY_CONFIG.maxVersions,
|
|
67
|
+
storagePath: config.storagePath ?? DEFAULT_VERSION_HISTORY_CONFIG.storagePath
|
|
68
|
+
};
|
|
69
|
+
}
|
|
70
|
+
function isVersionHistoryEnabled(config) {
|
|
71
|
+
const resolved = resolveVersionConfig(config);
|
|
72
|
+
return resolved.enabled;
|
|
73
|
+
}
|
|
74
|
+
async function saveVersionWithConfig(projectRoot, collection, contentId, content, config, options) {
|
|
75
|
+
const resolvedConfig = resolveVersionConfig(config);
|
|
76
|
+
if (!resolvedConfig.enabled) {
|
|
77
|
+
return { success: true };
|
|
78
|
+
}
|
|
79
|
+
return saveVersion(
|
|
80
|
+
projectRoot,
|
|
81
|
+
collection,
|
|
82
|
+
contentId,
|
|
83
|
+
content,
|
|
84
|
+
resolvedConfig,
|
|
85
|
+
options
|
|
86
|
+
);
|
|
87
|
+
}
|
|
88
|
+
async function getVersionsWithConfig(projectRoot, collection, contentId, config) {
|
|
89
|
+
const resolvedConfig = resolveVersionConfig(config);
|
|
90
|
+
if (!resolvedConfig.enabled) {
|
|
91
|
+
return [];
|
|
92
|
+
}
|
|
93
|
+
return getVersions(projectRoot, collection, contentId, resolvedConfig);
|
|
94
|
+
}
|
|
95
|
+
async function getVersionWithConfig(projectRoot, collection, contentId, versionId, config) {
|
|
96
|
+
const resolvedConfig = resolveVersionConfig(config);
|
|
97
|
+
if (!resolvedConfig.enabled) {
|
|
98
|
+
return null;
|
|
99
|
+
}
|
|
100
|
+
return getVersion(
|
|
101
|
+
projectRoot,
|
|
102
|
+
collection,
|
|
103
|
+
contentId,
|
|
104
|
+
versionId,
|
|
105
|
+
resolvedConfig
|
|
106
|
+
);
|
|
107
|
+
}
|
|
108
|
+
async function deleteVersionWithConfig(projectRoot, collection, contentId, versionId, config) {
|
|
109
|
+
const resolvedConfig = resolveVersionConfig(config);
|
|
110
|
+
return deleteVersion(
|
|
111
|
+
projectRoot,
|
|
112
|
+
collection,
|
|
113
|
+
contentId,
|
|
114
|
+
versionId,
|
|
115
|
+
resolvedConfig
|
|
116
|
+
);
|
|
117
|
+
}
|
|
118
|
+
async function clearVersionsWithConfig(projectRoot, collection, contentId, config) {
|
|
119
|
+
const resolvedConfig = resolveVersionConfig(config);
|
|
120
|
+
return clearVersions(projectRoot, collection, contentId, resolvedConfig);
|
|
121
|
+
}
|
|
122
|
+
async function pruneVersionsWithConfig(projectRoot, collection, contentId, config) {
|
|
123
|
+
const resolvedConfig = resolveVersionConfig(config);
|
|
124
|
+
return pruneVersions(projectRoot, collection, contentId, resolvedConfig);
|
|
125
|
+
}
|
|
126
|
+
async function restoreVersionWithConfig(projectRoot, collection, contentId, versionId, contentFilePath, config, options) {
|
|
127
|
+
const resolvedConfig = resolveVersionConfig(config);
|
|
128
|
+
if (!resolvedConfig.enabled) {
|
|
129
|
+
return {
|
|
130
|
+
success: false,
|
|
131
|
+
error: "Version history is disabled"
|
|
132
|
+
};
|
|
133
|
+
}
|
|
134
|
+
return restoreVersion(
|
|
135
|
+
projectRoot,
|
|
136
|
+
collection,
|
|
137
|
+
contentId,
|
|
138
|
+
versionId,
|
|
139
|
+
contentFilePath,
|
|
140
|
+
resolvedConfig,
|
|
141
|
+
options
|
|
142
|
+
);
|
|
143
|
+
}
|
|
144
|
+
export {
|
|
145
|
+
ContentWatcher,
|
|
146
|
+
DEFAULT_IMAGE_CONFIG,
|
|
147
|
+
FileModificationTracker,
|
|
148
|
+
calculateRelativePath,
|
|
149
|
+
checkCollection,
|
|
150
|
+
clearVersions,
|
|
151
|
+
clearVersionsWithConfig,
|
|
152
|
+
createContent,
|
|
153
|
+
createContentWatcher,
|
|
154
|
+
createEmptyManifest,
|
|
155
|
+
deleteContent,
|
|
156
|
+
deleteVersion,
|
|
157
|
+
deleteVersionWithConfig,
|
|
158
|
+
detectContentStructure,
|
|
159
|
+
discoverContentImages,
|
|
160
|
+
ensureGitignore,
|
|
161
|
+
ensureStorageDirectory,
|
|
162
|
+
extractSlug,
|
|
163
|
+
generateExcerpt,
|
|
164
|
+
generatePreview,
|
|
165
|
+
generateSlug,
|
|
166
|
+
generateUniqueSlug,
|
|
167
|
+
generateVersionId,
|
|
168
|
+
getCollectionCount,
|
|
169
|
+
getCollectionSummaries,
|
|
170
|
+
getContentFilePath,
|
|
171
|
+
getContentImageFolder,
|
|
172
|
+
getFileStats,
|
|
173
|
+
getManifestPath,
|
|
174
|
+
getOrRecoverManifest,
|
|
175
|
+
getVersion,
|
|
176
|
+
getVersionFilePath,
|
|
177
|
+
getVersionStoragePath,
|
|
178
|
+
getVersionWithConfig,
|
|
179
|
+
getVersions,
|
|
180
|
+
getVersionsWithConfig,
|
|
181
|
+
isContentFile,
|
|
182
|
+
isValidImageFile,
|
|
183
|
+
isVersionHistoryEnabled,
|
|
184
|
+
parseMultipartFormData,
|
|
185
|
+
parseVersionId,
|
|
186
|
+
pruneVersions,
|
|
187
|
+
pruneVersionsWithConfig,
|
|
188
|
+
readCollection,
|
|
189
|
+
readContentFile,
|
|
190
|
+
readManifest,
|
|
191
|
+
recoverManifest,
|
|
192
|
+
resolveVersionConfig,
|
|
193
|
+
restoreVersion,
|
|
194
|
+
restoreVersionWithConfig,
|
|
195
|
+
saveVersion,
|
|
196
|
+
saveVersionWithConfig,
|
|
197
|
+
scanDirectoryForImages,
|
|
198
|
+
toContentSummary,
|
|
199
|
+
updateContent,
|
|
200
|
+
uploadImage,
|
|
201
|
+
writeManifest
|
|
202
|
+
};
|
|
203
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/filesystem/version-config.ts"],"sourcesContent":["/**\n * @fileoverview Config-aware wrappers for version history operations\n *\n * This module provides wrapper functions that automatically apply configuration\n * defaults and check the enabled flag before performing version operations.\n * These wrappers simplify usage by accepting partial configuration and handling\n * all the configuration resolution internally.\n *\n * @module @writenex/astro/filesystem/version-config\n * @see {@link saveVersion} - Core save function\n * @see {@link getVersions} - Core list function\n */\n\nimport type {\n VersionHistoryConfig,\n VersionEntry,\n Version,\n VersionResult,\n SaveVersionOptions,\n RestoreVersionOptions,\n RestoreResult,\n} from \"@/types\";\nimport { DEFAULT_VERSION_HISTORY_CONFIG } from \"@/config/defaults\";\nimport {\n saveVersion as coreSaveVersion,\n getVersions as coreGetVersions,\n getVersion as coreGetVersion,\n deleteVersion as coreDeleteVersion,\n clearVersions as coreClearVersions,\n pruneVersions as corePruneVersions,\n restoreVersion as coreRestoreVersion,\n} from \"./versions\";\n\n// =============================================================================\n// Configuration Resolution\n// =============================================================================\n\n/**\n * Resolve version history configuration with defaults applied.\n *\n * Takes a partial configuration and merges it with defaults to produce\n * a complete configuration object.\n *\n * @param config - Partial version history configuration\n * @returns Complete configuration with all defaults applied\n *\n * @example\n * ```typescript\n * const resolved = resolveVersionConfig({ maxVersions: 50 });\n * // Returns: { enabled: true, maxVersions: 50, storagePath: '.writenex/versions' }\n * ```\n */\nexport function resolveVersionConfig(\n config?: VersionHistoryConfig\n): Required<VersionHistoryConfig> {\n if (!config) {\n return { ...DEFAULT_VERSION_HISTORY_CONFIG };\n }\n\n return {\n enabled: config.enabled ?? DEFAULT_VERSION_HISTORY_CONFIG.enabled,\n maxVersions:\n config.maxVersions ?? DEFAULT_VERSION_HISTORY_CONFIG.maxVersions,\n storagePath:\n config.storagePath ?? DEFAULT_VERSION_HISTORY_CONFIG.storagePath,\n };\n}\n\n/**\n * Check if version history is enabled in the configuration.\n *\n * @param config - Version history configuration (partial or full)\n * @returns True if version history is enabled\n *\n * @example\n * ```typescript\n * if (isVersionHistoryEnabled({ enabled: false })) {\n * // This won't execute\n * }\n * ```\n */\nexport function isVersionHistoryEnabled(\n config?: VersionHistoryConfig\n): boolean {\n const resolved = resolveVersionConfig(config);\n return resolved.enabled;\n}\n\n// =============================================================================\n// Config-Aware Version Operations\n// =============================================================================\n\n/**\n * Save a version with automatic configuration resolution.\n *\n * This wrapper automatically applies configuration defaults and checks\n * the enabled flag before delegating to the core saveVersion function.\n *\n * @param projectRoot - Absolute path to project root\n * @param collection - Collection name\n * @param contentId - Content item ID (slug)\n * @param content - Full markdown content to save\n * @param config - Partial version history configuration\n * @param options - Save options\n * @returns Result of the save operation\n *\n * @example\n * ```typescript\n * // With partial config - defaults are applied automatically\n * const result = await saveVersionWithConfig(\n * '/project',\n * 'blog',\n * 'my-post',\n * '---\\ntitle: My Post\\n---\\n\\nContent...',\n * { maxVersions: 50 } // enabled and storagePath use defaults\n * );\n * ```\n */\nexport async function saveVersionWithConfig(\n projectRoot: string,\n collection: string,\n contentId: string,\n content: string,\n config?: VersionHistoryConfig,\n options?: SaveVersionOptions\n): Promise<VersionResult> {\n const resolvedConfig = resolveVersionConfig(config);\n\n // Early return if disabled\n if (!resolvedConfig.enabled) {\n return { success: true };\n }\n\n return coreSaveVersion(\n projectRoot,\n collection,\n contentId,\n content,\n resolvedConfig,\n options\n );\n}\n\n/**\n * Get all versions with automatic configuration resolution.\n *\n * This wrapper automatically applies configuration defaults and checks\n * the enabled flag before delegating to the core getVersions function.\n *\n * @param projectRoot - Absolute path to project root\n * @param collection - Collection name\n * @param contentId - Content item ID (slug)\n * @param config - Partial version history configuration\n * @returns Array of version entries (empty if disabled)\n *\n * @example\n * ```typescript\n * const versions = await getVersionsWithConfig(\n * '/project',\n * 'blog',\n * 'my-post',\n * { storagePath: 'custom/versions' }\n * );\n * ```\n */\nexport async function getVersionsWithConfig(\n projectRoot: string,\n collection: string,\n contentId: string,\n config?: VersionHistoryConfig\n): Promise<VersionEntry[]> {\n const resolvedConfig = resolveVersionConfig(config);\n\n // Early return if disabled\n if (!resolvedConfig.enabled) {\n return [];\n }\n\n return coreGetVersions(projectRoot, collection, contentId, resolvedConfig);\n}\n\n/**\n * Get a specific version with automatic configuration resolution.\n *\n * This wrapper automatically applies configuration defaults and checks\n * the enabled flag before delegating to the core getVersion function.\n *\n * @param projectRoot - Absolute path to project root\n * @param collection - Collection name\n * @param contentId - Content item ID (slug)\n * @param versionId - Version ID to retrieve\n * @param config - Partial version history configuration\n * @returns Full version data or null if not found/disabled\n *\n * @example\n * ```typescript\n * const version = await getVersionWithConfig(\n * '/project',\n * 'blog',\n * 'my-post',\n * '2024-12-11T10-30-00-000Z'\n * );\n * ```\n */\nexport async function getVersionWithConfig(\n projectRoot: string,\n collection: string,\n contentId: string,\n versionId: string,\n config?: VersionHistoryConfig\n): Promise<Version | null> {\n const resolvedConfig = resolveVersionConfig(config);\n\n // Early return if disabled\n if (!resolvedConfig.enabled) {\n return null;\n }\n\n return coreGetVersion(\n projectRoot,\n collection,\n contentId,\n versionId,\n resolvedConfig\n );\n}\n\n/**\n * Delete a version with automatic configuration resolution.\n *\n * This wrapper automatically applies configuration defaults before\n * delegating to the core deleteVersion function.\n *\n * @param projectRoot - Absolute path to project root\n * @param collection - Collection name\n * @param contentId - Content item ID (slug)\n * @param versionId - Version ID to delete\n * @param config - Partial version history configuration\n * @returns Result of the delete operation\n *\n * @example\n * ```typescript\n * const result = await deleteVersionWithConfig(\n * '/project',\n * 'blog',\n * 'my-post',\n * '2024-12-11T10-30-00-000Z'\n * );\n * ```\n */\nexport async function deleteVersionWithConfig(\n projectRoot: string,\n collection: string,\n contentId: string,\n versionId: string,\n config?: VersionHistoryConfig\n): Promise<VersionResult> {\n const resolvedConfig = resolveVersionConfig(config);\n\n return coreDeleteVersion(\n projectRoot,\n collection,\n contentId,\n versionId,\n resolvedConfig\n );\n}\n\n/**\n * Clear all versions with automatic configuration resolution.\n *\n * This wrapper automatically applies configuration defaults before\n * delegating to the core clearVersions function.\n *\n * @param projectRoot - Absolute path to project root\n * @param collection - Collection name\n * @param contentId - Content item ID (slug)\n * @param config - Partial version history configuration\n * @returns Result of the clear operation\n *\n * @example\n * ```typescript\n * const result = await clearVersionsWithConfig(\n * '/project',\n * 'blog',\n * 'my-post'\n * );\n * ```\n */\nexport async function clearVersionsWithConfig(\n projectRoot: string,\n collection: string,\n contentId: string,\n config?: VersionHistoryConfig\n): Promise<VersionResult> {\n const resolvedConfig = resolveVersionConfig(config);\n\n return coreClearVersions(projectRoot, collection, contentId, resolvedConfig);\n}\n\n/**\n * Prune old versions with automatic configuration resolution.\n *\n * This wrapper automatically applies configuration defaults before\n * delegating to the core pruneVersions function. Uses the configured\n * maxVersions value for determining how many versions to keep.\n *\n * @param projectRoot - Absolute path to project root\n * @param collection - Collection name\n * @param contentId - Content item ID (slug)\n * @param config - Partial version history configuration\n * @returns Result of the prune operation\n *\n * @example\n * ```typescript\n * // Uses custom maxVersions\n * const result = await pruneVersionsWithConfig(\n * '/project',\n * 'blog',\n * 'my-post',\n * { maxVersions: 10 }\n * );\n * ```\n */\nexport async function pruneVersionsWithConfig(\n projectRoot: string,\n collection: string,\n contentId: string,\n config?: VersionHistoryConfig\n): Promise<VersionResult> {\n const resolvedConfig = resolveVersionConfig(config);\n\n return corePruneVersions(projectRoot, collection, contentId, resolvedConfig);\n}\n\n/**\n * Restore a version with automatic configuration resolution.\n *\n * This wrapper automatically applies configuration defaults and checks\n * the enabled flag before delegating to the core restoreVersion function.\n *\n * @param projectRoot - Absolute path to project root\n * @param collection - Collection name\n * @param contentId - Content item ID (slug)\n * @param versionId - Version ID to restore\n * @param contentFilePath - Absolute path to the current content file\n * @param config - Partial version history configuration\n * @param options - Restore options\n * @returns Result of the restore operation\n *\n * @example\n * ```typescript\n * const result = await restoreVersionWithConfig(\n * '/project',\n * 'blog',\n * 'my-post',\n * '2024-12-11T10-30-00-000Z',\n * '/project/src/content/blog/my-post.md'\n * );\n * ```\n */\nexport async function restoreVersionWithConfig(\n projectRoot: string,\n collection: string,\n contentId: string,\n versionId: string,\n contentFilePath: string,\n config?: VersionHistoryConfig,\n options?: RestoreVersionOptions\n): Promise<RestoreResult> {\n const resolvedConfig = resolveVersionConfig(config);\n\n // Early return if disabled\n if (!resolvedConfig.enabled) {\n return {\n success: false,\n error: \"Version history is disabled\",\n };\n }\n\n return coreRestoreVersion(\n projectRoot,\n collection,\n contentId,\n versionId,\n contentFilePath,\n resolvedConfig,\n options\n );\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAoDO,SAAS,qBACd,QACgC;AAChC,MAAI,CAAC,QAAQ;AACX,WAAO,EAAE,GAAG,+BAA+B;AAAA,EAC7C;AAEA,SAAO;AAAA,IACL,SAAS,OAAO,WAAW,+BAA+B;AAAA,IAC1D,aACE,OAAO,eAAe,+BAA+B;AAAA,IACvD,aACE,OAAO,eAAe,+BAA+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ACwB;AACxB,QAAM,iBAAiB,qBAAqB,MAAM;AAGlD,MAAI,CAAC,eAAe,SAAS;AAC3B,WAAO;AAAA,MACL,SAAS;AAAA,MACT,OAAO;AAAA,IACT;AAAA,EACF;AAEA,SAAO;AAAA,IACL;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EACF;AACF;","names":[]}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview Image-related type definitions for @writenex/astro
|
|
3
|
+
*
|
|
4
|
+
* This file contains all TypeScript type definitions related to image discovery
|
|
5
|
+
* and image metadata.
|
|
6
|
+
*
|
|
7
|
+
* @module @writenex/astro/types/image
|
|
8
|
+
*/
|
|
9
|
+
/**
|
|
10
|
+
* Discovered image metadata
|
|
11
|
+
*
|
|
12
|
+
* Represents an image file found during content folder scanning.
|
|
13
|
+
*/
|
|
14
|
+
interface DiscoveredImage {
|
|
15
|
+
/** Original filename (e.g., "hero.jpg") */
|
|
16
|
+
filename: string;
|
|
17
|
+
/** Relative path for markdown (e.g., "./images/hero.jpg") */
|
|
18
|
+
relativePath: string;
|
|
19
|
+
/** Absolute filesystem path */
|
|
20
|
+
absolutePath: string;
|
|
21
|
+
/** File size in bytes */
|
|
22
|
+
size: number;
|
|
23
|
+
/** File extension (lowercase, with dot, e.g., ".jpg") */
|
|
24
|
+
extension: string;
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Options for image discovery
|
|
28
|
+
*/
|
|
29
|
+
interface ImageDiscoveryOptions {
|
|
30
|
+
/** Maximum recursion depth (default: 5) */
|
|
31
|
+
maxDepth?: number;
|
|
32
|
+
/** Additional extensions to include beyond defaults */
|
|
33
|
+
additionalExtensions?: string[];
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Result of image discovery operation
|
|
37
|
+
*/
|
|
38
|
+
interface ImageDiscoveryResult {
|
|
39
|
+
/** Whether discovery was successful */
|
|
40
|
+
success: boolean;
|
|
41
|
+
/** Discovered images */
|
|
42
|
+
images: DiscoveredImage[];
|
|
43
|
+
/** Error message if failed */
|
|
44
|
+
error?: string;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
export type { DiscoveredImage as D, ImageDiscoveryOptions as I, ImageDiscoveryResult as a };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import { AstroIntegration } from 'astro';
|
|
2
|
+
import { W as WritenexOptions } from './config-BmEdBDo_.js';
|
|
3
|
+
export { C as CollectionConfig, b as CollectionSchema, D as DiscoveryConfig, E as EditorConfig, F as FieldType, I as ImageConfig, c as ImageStrategy, S as SchemaField, V as VersionHistoryConfig, a as WritenexConfig } from './config-BmEdBDo_.js';
|
|
4
|
+
export { d as defineConfig, l as loadConfig, v as validateConfig } from './loader-CrdnaAWR.js';
|
|
5
|
+
export { C as ContentItem, a as ContentSummary, D as DiscoveredCollection } from './content-BWR52vD-.js';
|
|
6
|
+
export { W as WritenexError, a as WritenexErrorCode, i as isWritenexError } from './errors-C0iYiDTv.js';
|
|
7
|
+
import 'zod';
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* @fileoverview Astro integration for Writenex visual editor
|
|
11
|
+
*
|
|
12
|
+
* This module provides the main Astro integration that injects the Writenex
|
|
13
|
+
* editor UI and API routes into an Astro project.
|
|
14
|
+
*
|
|
15
|
+
* ## Features:
|
|
16
|
+
* - Injects editor UI at /_writenex
|
|
17
|
+
* - Provides API routes for content CRUD operations
|
|
18
|
+
* - Auto-discovers content collections
|
|
19
|
+
* - Production guard to prevent accidental exposure
|
|
20
|
+
*
|
|
21
|
+
* ## Usage:
|
|
22
|
+
* ```typescript
|
|
23
|
+
* // astro.config.mjs
|
|
24
|
+
* import { defineConfig } from 'astro/config';
|
|
25
|
+
* import writenex from '@writenex/astro';
|
|
26
|
+
*
|
|
27
|
+
* export default defineConfig({
|
|
28
|
+
* integrations: [writenex()],
|
|
29
|
+
* });
|
|
30
|
+
* ```
|
|
31
|
+
*
|
|
32
|
+
* @module @writenex/astro/integration
|
|
33
|
+
*/
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* Creates the Writenex Astro integration.
|
|
37
|
+
*
|
|
38
|
+
* This integration injects the Writenex visual editor into your Astro project,
|
|
39
|
+
* providing a WYSIWYG interface for editing content collections.
|
|
40
|
+
*
|
|
41
|
+
* @param options - Integration options
|
|
42
|
+
* @param options.allowProduction - Allow running in production (default: false)
|
|
43
|
+
* @returns Astro integration object
|
|
44
|
+
*
|
|
45
|
+
* @example
|
|
46
|
+
* ```typescript
|
|
47
|
+
* // Basic usage
|
|
48
|
+
* export default defineConfig({
|
|
49
|
+
* integrations: [writenex()],
|
|
50
|
+
* });
|
|
51
|
+
*
|
|
52
|
+
* // With options
|
|
53
|
+
* export default defineConfig({
|
|
54
|
+
* integrations: [
|
|
55
|
+
* writenex({
|
|
56
|
+
* allowProduction: true, // Enable in production (use with caution)
|
|
57
|
+
* }),
|
|
58
|
+
* ],
|
|
59
|
+
* });
|
|
60
|
+
* ```
|
|
61
|
+
*/
|
|
62
|
+
declare function writenex(options?: WritenexOptions): AstroIntegration;
|
|
63
|
+
|
|
64
|
+
export { WritenexOptions, writenex as default, writenex };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,151 @@
|
|
|
1
|
+
import "./chunk-KIKIPIFA.js";
|
|
2
|
+
import {
|
|
3
|
+
ContentWatcher
|
|
4
|
+
} from "./chunk-XNTQTTJU.js";
|
|
5
|
+
import {
|
|
6
|
+
createMiddleware,
|
|
7
|
+
getCache
|
|
8
|
+
} from "./chunk-7XU5X6CW.js";
|
|
9
|
+
import "./chunk-CYLDJ3HZ.js";
|
|
10
|
+
import {
|
|
11
|
+
WritenexError,
|
|
12
|
+
WritenexErrorCode,
|
|
13
|
+
isWritenexError
|
|
14
|
+
} from "./chunk-CF2XXJFF.js";
|
|
15
|
+
import "./chunk-AAOQHQPU.js";
|
|
16
|
+
import {
|
|
17
|
+
defineConfig,
|
|
18
|
+
loadConfig,
|
|
19
|
+
validateConfig
|
|
20
|
+
} from "./chunk-5PM6EQE5.js";
|
|
21
|
+
import "./chunk-CRPZUUDU.js";
|
|
22
|
+
|
|
23
|
+
// src/integration.ts
|
|
24
|
+
var DEFAULT_BASE_PATH = "/_writenex";
|
|
25
|
+
var PACKAGE_NAME = "@writenex/astro";
|
|
26
|
+
function writenex(options) {
|
|
27
|
+
const { allowProduction = false } = options ?? {};
|
|
28
|
+
const basePath = DEFAULT_BASE_PATH;
|
|
29
|
+
let isActive = true;
|
|
30
|
+
let resolvedConfig = null;
|
|
31
|
+
let projectRoot = "";
|
|
32
|
+
let astroTrailingSlash = "ignore";
|
|
33
|
+
let watcher = null;
|
|
34
|
+
let hasLoggedEditorUrl = false;
|
|
35
|
+
return {
|
|
36
|
+
name: PACKAGE_NAME,
|
|
37
|
+
hooks: {
|
|
38
|
+
/**
|
|
39
|
+
* Configuration setup hook
|
|
40
|
+
*
|
|
41
|
+
* This hook runs during Astro's config resolution phase.
|
|
42
|
+
* We use it to:
|
|
43
|
+
* 1. Check if we should run (production guard)
|
|
44
|
+
* 2. Load Writenex configuration
|
|
45
|
+
* 3. Register any necessary Vite plugins
|
|
46
|
+
*/
|
|
47
|
+
"astro:config:setup": async ({ command, logger, config }) => {
|
|
48
|
+
if (command === "build" && !allowProduction) {
|
|
49
|
+
logger.warn(
|
|
50
|
+
"Disabled in production build. Use allowProduction: true to override."
|
|
51
|
+
);
|
|
52
|
+
isActive = false;
|
|
53
|
+
return;
|
|
54
|
+
}
|
|
55
|
+
projectRoot = config.root.pathname;
|
|
56
|
+
astroTrailingSlash = config.trailingSlash ?? "ignore";
|
|
57
|
+
const { config: loadedConfig, warnings } = await loadConfig(projectRoot);
|
|
58
|
+
resolvedConfig = loadedConfig;
|
|
59
|
+
for (const warning of warnings) {
|
|
60
|
+
logger.warn(warning);
|
|
61
|
+
}
|
|
62
|
+
},
|
|
63
|
+
/**
|
|
64
|
+
* Server setup hook
|
|
65
|
+
*
|
|
66
|
+
* This hook runs when the Astro dev server starts.
|
|
67
|
+
* We use it to:
|
|
68
|
+
* 1. Inject middleware for API routes
|
|
69
|
+
* 2. Serve the editor UI
|
|
70
|
+
* 3. Start file watcher for cache invalidation
|
|
71
|
+
*/
|
|
72
|
+
"astro:server:setup": ({ server }) => {
|
|
73
|
+
if (!isActive || !resolvedConfig) {
|
|
74
|
+
return;
|
|
75
|
+
}
|
|
76
|
+
const middleware = createMiddleware({
|
|
77
|
+
basePath,
|
|
78
|
+
projectRoot,
|
|
79
|
+
config: resolvedConfig,
|
|
80
|
+
trailingSlash: astroTrailingSlash
|
|
81
|
+
});
|
|
82
|
+
server.middlewares.use(middleware);
|
|
83
|
+
const cache = getCache({ hasWatcher: true });
|
|
84
|
+
watcher = new ContentWatcher(projectRoot, "src/content", {
|
|
85
|
+
onChange: (event) => {
|
|
86
|
+
cache.handleFileChange(event.type, event.collection);
|
|
87
|
+
}
|
|
88
|
+
});
|
|
89
|
+
watcher.start();
|
|
90
|
+
},
|
|
91
|
+
/**
|
|
92
|
+
* Server start hook
|
|
93
|
+
*
|
|
94
|
+
* This hook runs after the dev server has started and is listening.
|
|
95
|
+
* We use it to log the full editor URL with the actual server address.
|
|
96
|
+
*/
|
|
97
|
+
"astro:server:start": ({ address, logger }) => {
|
|
98
|
+
if (!isActive || hasLoggedEditorUrl) {
|
|
99
|
+
return;
|
|
100
|
+
}
|
|
101
|
+
const protocol = "http";
|
|
102
|
+
const rawHost = address.address;
|
|
103
|
+
const isLoopback = rawHost === "" || rawHost === "::" || rawHost === "127.0.0.1" || rawHost === "::1";
|
|
104
|
+
const host = isLoopback ? "localhost" : rawHost;
|
|
105
|
+
const port = address.port;
|
|
106
|
+
const editorUrl = `${protocol}://${host}:${port}${basePath}`;
|
|
107
|
+
logger.info(`Writenex editor running at: ${editorUrl}`);
|
|
108
|
+
hasLoggedEditorUrl = true;
|
|
109
|
+
},
|
|
110
|
+
/**
|
|
111
|
+
* Server done hook
|
|
112
|
+
*
|
|
113
|
+
* This hook runs when the server is shutting down.
|
|
114
|
+
* We use it to clean up the file watcher.
|
|
115
|
+
*/
|
|
116
|
+
"astro:server:done": async () => {
|
|
117
|
+
if (watcher) {
|
|
118
|
+
await watcher.stop();
|
|
119
|
+
watcher = null;
|
|
120
|
+
}
|
|
121
|
+
},
|
|
122
|
+
/**
|
|
123
|
+
* Build done hook
|
|
124
|
+
*
|
|
125
|
+
* This hook runs after the build completes.
|
|
126
|
+
* Currently just logs a warning if production mode is enabled.
|
|
127
|
+
*/
|
|
128
|
+
"astro:build:done": ({ logger }) => {
|
|
129
|
+
if (allowProduction) {
|
|
130
|
+
logger.warn(
|
|
131
|
+
"Production mode enabled. Ensure your deployment is secured."
|
|
132
|
+
);
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
};
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
// src/core/constants.ts
|
|
140
|
+
var MAX_IMAGE_SIZE = 10 * 1024 * 1024;
|
|
141
|
+
export {
|
|
142
|
+
WritenexError,
|
|
143
|
+
WritenexErrorCode,
|
|
144
|
+
writenex as default,
|
|
145
|
+
defineConfig,
|
|
146
|
+
isWritenexError,
|
|
147
|
+
loadConfig,
|
|
148
|
+
validateConfig,
|
|
149
|
+
writenex
|
|
150
|
+
};
|
|
151
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/integration.ts","../src/core/constants.ts"],"sourcesContent":["/**\n * @fileoverview Astro integration for Writenex visual editor\n *\n * This module provides the main Astro integration that injects the Writenex\n * editor UI and API routes into an Astro project.\n *\n * ## Features:\n * - Injects editor UI at /_writenex\n * - Provides API routes for content CRUD operations\n * - Auto-discovers content collections\n * - Production guard to prevent accidental exposure\n *\n * ## Usage:\n * ```typescript\n * // astro.config.mjs\n * import { defineConfig } from 'astro/config';\n * import writenex from '@writenex/astro';\n *\n * export default defineConfig({\n * integrations: [writenex()],\n * });\n * ```\n *\n * @module @writenex/astro/integration\n */\n\nimport type { AstroIntegration } from \"astro\";\nimport type { WritenexOptions, WritenexConfig } from \"@/types\";\nimport { loadConfig } from \"@/config/loader\";\nimport { createMiddleware } from \"@/server/middleware\";\nimport { ContentWatcher } from \"@/filesystem/watcher\";\nimport { getCache } from \"@/server/cache\";\n\n/**\n * Default base path for the Writenex editor UI\n */\nconst DEFAULT_BASE_PATH = \"/_writenex\";\n\n/**\n * Package name for logging\n */\nconst PACKAGE_NAME = \"@writenex/astro\";\n\n/**\n * Creates the Writenex Astro integration.\n *\n * This integration injects the Writenex visual editor into your Astro project,\n * providing a WYSIWYG interface for editing content collections.\n *\n * @param options - Integration options\n * @param options.allowProduction - Allow running in production (default: false)\n * @returns Astro integration object\n *\n * @example\n * ```typescript\n * // Basic usage\n * export default defineConfig({\n * integrations: [writenex()],\n * });\n *\n * // With options\n * export default defineConfig({\n * integrations: [\n * writenex({\n * allowProduction: true, // Enable in production (use with caution)\n * }),\n * ],\n * });\n * ```\n */\nexport default function writenex(options?: WritenexOptions): AstroIntegration {\n const { allowProduction = false } = options ?? {};\n\n // Use fixed base path for consistency and branding\n const basePath = DEFAULT_BASE_PATH;\n\n // Track if we should be active\n let isActive = true;\n\n // Store loaded configuration\n let resolvedConfig: Required<WritenexConfig> | null = null;\n\n // Store project root\n let projectRoot = \"\";\n\n // Store Astro's trailingSlash setting\n let astroTrailingSlash: \"always\" | \"never\" | \"ignore\" = \"ignore\";\n\n // File watcher instance\n let watcher: ContentWatcher | null = null;\n\n // Track if editor URL has been logged (to avoid duplicate logs)\n let hasLoggedEditorUrl = false;\n\n return {\n name: PACKAGE_NAME,\n hooks: {\n /**\n * Configuration setup hook\n *\n * This hook runs during Astro's config resolution phase.\n * We use it to:\n * 1. Check if we should run (production guard)\n * 2. Load Writenex configuration\n * 3. Register any necessary Vite plugins\n */\n \"astro:config:setup\": async ({ command, logger, config }) => {\n // Production guard: disable in production unless explicitly allowed\n if (command === \"build\" && !allowProduction) {\n logger.warn(\n \"Disabled in production build. Use allowProduction: true to override.\"\n );\n isActive = false;\n return;\n }\n\n // Store project root\n projectRoot = config.root.pathname;\n\n // Capture Astro's trailingSlash setting for preview URLs\n astroTrailingSlash = config.trailingSlash ?? \"ignore\";\n\n // Load Writenex configuration\n const { config: loadedConfig, warnings } =\n await loadConfig(projectRoot);\n resolvedConfig = loadedConfig;\n\n // Log any configuration warnings\n for (const warning of warnings) {\n logger.warn(warning);\n }\n },\n\n /**\n * Server setup hook\n *\n * This hook runs when the Astro dev server starts.\n * We use it to:\n * 1. Inject middleware for API routes\n * 2. Serve the editor UI\n * 3. Start file watcher for cache invalidation\n */\n \"astro:server:setup\": ({ server }) => {\n // Skip if disabled (production guard triggered)\n if (!isActive || !resolvedConfig) {\n return;\n }\n\n // Create and register the middleware\n const middleware = createMiddleware({\n basePath,\n projectRoot,\n config: resolvedConfig,\n trailingSlash: astroTrailingSlash,\n });\n\n server.middlewares.use(middleware);\n\n // Setup cache with file watcher integration\n const cache = getCache({ hasWatcher: true });\n\n // Start file watcher for cache invalidation\n watcher = new ContentWatcher(projectRoot, \"src/content\", {\n onChange: (event) => {\n cache.handleFileChange(event.type, event.collection);\n },\n });\n\n watcher.start();\n },\n\n /**\n * Server start hook\n *\n * This hook runs after the dev server has started and is listening.\n * We use it to log the full editor URL with the actual server address.\n */\n \"astro:server:start\": ({ address, logger }) => {\n if (!isActive || hasLoggedEditorUrl) {\n return;\n }\n\n // Build the full URL from the server address\n // Normalize loopback addresses to \"localhost\" for better readability\n const protocol = \"http\";\n const rawHost = address.address;\n const isLoopback =\n rawHost === \"\" ||\n rawHost === \"::\" ||\n rawHost === \"127.0.0.1\" ||\n rawHost === \"::1\";\n const host = isLoopback ? \"localhost\" : rawHost;\n const port = address.port;\n const editorUrl = `${protocol}://${host}:${port}${basePath}`;\n\n logger.info(`Writenex editor running at: ${editorUrl}`);\n hasLoggedEditorUrl = true;\n },\n\n /**\n * Server done hook\n *\n * This hook runs when the server is shutting down.\n * We use it to clean up the file watcher.\n */\n \"astro:server:done\": async () => {\n if (watcher) {\n await watcher.stop();\n watcher = null;\n }\n },\n\n /**\n * Build done hook\n *\n * This hook runs after the build completes.\n * Currently just logs a warning if production mode is enabled.\n */\n \"astro:build:done\": ({ logger }) => {\n if (allowProduction) {\n logger.warn(\n \"Production mode enabled. Ensure your deployment is secured.\"\n );\n }\n },\n },\n };\n}\n","/**\n * @fileoverview Shared constants for @writenex/astro\n *\n * This module provides centralized constants used across the integration,\n * including version information, default paths, and configuration limits.\n *\n * @module @writenex/astro/core/constants\n */\n\n/**\n * Current version of the @writenex/astro package\n */\nexport const WRITENEX_VERSION = \"1.0.0\";\n\n/**\n * Default base path for the Writenex editor UI\n */\nexport const DEFAULT_BASE_PATH = \"/_writenex\";\n\n/**\n * Default API path for Writenex API endpoints\n */\nexport const DEFAULT_API_PATH = \"/_writenex/api\";\n\n/**\n * Supported image MIME types for upload\n */\nexport const SUPPORTED_IMAGE_TYPES = [\n \"image/jpeg\",\n \"image/png\",\n \"image/gif\",\n \"image/webp\",\n \"image/svg+xml\",\n] as const;\n\n/**\n * Maximum allowed image file size in bytes (10MB)\n */\nexport const MAX_IMAGE_SIZE = 10 * 1024 * 1024;\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;AAoCA,IAAM,oBAAoB;AAK1B,IAAM,eAAe;AA6BN,SAAR,SAA0B,SAA6C;AAC5E,QAAM,EAAE,kBAAkB,MAAM,IAAI,WAAW,CAAC;AAGhD,QAAM,WAAW;AAGjB,MAAI,WAAW;AAGf,MAAI,iBAAkD;AAGtD,MAAI,cAAc;AAGlB,MAAI,qBAAoD;AAGxD,MAAI,UAAiC;AAGrC,MAAI,qBAAqB;AAEzB,SAAO;AAAA,IACL,MAAM;AAAA,IACN,OAAO;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,MAUL,sBAAsB,OAAO,EAAE,SAAS,QAA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