@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.
Files changed (141) hide show
  1. package/README.md +539 -0
  2. package/dist/chunk-5PM6EQE5.js +151 -0
  3. package/dist/chunk-5PM6EQE5.js.map +1 -0
  4. package/dist/chunk-7XU5X6CW.js +1331 -0
  5. package/dist/chunk-7XU5X6CW.js.map +1 -0
  6. package/dist/chunk-AAOQHQPU.js +574 -0
  7. package/dist/chunk-AAOQHQPU.js.map +1 -0
  8. package/dist/chunk-CF2XXJFF.js +1410 -0
  9. package/dist/chunk-CF2XXJFF.js.map +1 -0
  10. package/dist/chunk-CRPZUUDU.js +52 -0
  11. package/dist/chunk-CRPZUUDU.js.map +1 -0
  12. package/dist/chunk-CYLDJ3HZ.js +310 -0
  13. package/dist/chunk-CYLDJ3HZ.js.map +1 -0
  14. package/dist/chunk-KIKIPIFA.js +1 -0
  15. package/dist/chunk-KIKIPIFA.js.map +1 -0
  16. package/dist/chunk-XNTQTTJU.js +145 -0
  17. package/dist/chunk-XNTQTTJU.js.map +1 -0
  18. package/dist/client/index.css +2 -0
  19. package/dist/client/index.css.map +1 -0
  20. package/dist/client/index.js +375 -0
  21. package/dist/client/index.js.map +1 -0
  22. package/dist/client/styles.css +584 -0
  23. package/dist/client/variables.css +304 -0
  24. package/dist/config/index.d.ts +54 -0
  25. package/dist/config/index.js +38 -0
  26. package/dist/config/index.js.map +1 -0
  27. package/dist/config-BmEdBDo_.d.ts +220 -0
  28. package/dist/content-BWR52vD-.d.ts +64 -0
  29. package/dist/discovery/index.d.ts +310 -0
  30. package/dist/discovery/index.js +38 -0
  31. package/dist/discovery/index.js.map +1 -0
  32. package/dist/errors-C0iYiDTv.d.ts +107 -0
  33. package/dist/filesystem/index.d.ts +1292 -0
  34. package/dist/filesystem/index.js +203 -0
  35. package/dist/filesystem/index.js.map +1 -0
  36. package/dist/image-FP7w5ZIs.d.ts +47 -0
  37. package/dist/index.d.ts +64 -0
  38. package/dist/index.js +151 -0
  39. package/dist/index.js.map +1 -0
  40. package/dist/loader-55LWCXHA.js +12 -0
  41. package/dist/loader-55LWCXHA.js.map +1 -0
  42. package/dist/loader-CrdnaAWR.d.ts +327 -0
  43. package/dist/server/index.d.ts +357 -0
  44. package/dist/server/index.js +37 -0
  45. package/dist/server/index.js.map +1 -0
  46. package/package.json +94 -0
  47. package/src/client/App.tsx +900 -0
  48. package/src/client/components/ConfigPanel/ConfigPanel.css +553 -0
  49. package/src/client/components/ConfigPanel/ConfigPanel.tsx +396 -0
  50. package/src/client/components/ConfigPanel/index.ts +6 -0
  51. package/src/client/components/CreateContentModal/CreateContentModal.css +327 -0
  52. package/src/client/components/CreateContentModal/CreateContentModal.tsx +216 -0
  53. package/src/client/components/CreateContentModal/index.ts +7 -0
  54. package/src/client/components/Editor/Editor.css +885 -0
  55. package/src/client/components/Editor/Editor.tsx +484 -0
  56. package/src/client/components/Editor/ImageDialog.css +344 -0
  57. package/src/client/components/Editor/ImageDialog.tsx +367 -0
  58. package/src/client/components/Editor/LinkDialog.css +326 -0
  59. package/src/client/components/Editor/LinkDialog.tsx +332 -0
  60. package/src/client/components/Editor/index.ts +6 -0
  61. package/src/client/components/FrontmatterForm/FrontmatterForm.css +468 -0
  62. package/src/client/components/FrontmatterForm/FrontmatterForm.tsx +914 -0
  63. package/src/client/components/FrontmatterForm/index.ts +7 -0
  64. package/src/client/components/Header/Header.css +300 -0
  65. package/src/client/components/Header/Header.tsx +300 -0
  66. package/src/client/components/Header/index.ts +7 -0
  67. package/src/client/components/KeyboardShortcuts/KeyboardShortcuts.css +239 -0
  68. package/src/client/components/KeyboardShortcuts/KeyboardShortcuts.tsx +151 -0
  69. package/src/client/components/KeyboardShortcuts/index.ts +6 -0
  70. package/src/client/components/LazyEditor.tsx +75 -0
  71. package/src/client/components/LiveRegion/LiveRegion.css +19 -0
  72. package/src/client/components/LiveRegion/LiveRegion.tsx +60 -0
  73. package/src/client/components/LiveRegion/index.ts +7 -0
  74. package/src/client/components/SearchReplace/SearchReplacePanel.css +300 -0
  75. package/src/client/components/SearchReplace/SearchReplacePanel.tsx +332 -0
  76. package/src/client/components/SearchReplace/index.ts +7 -0
  77. package/src/client/components/SelectCollectionModal/SelectCollectionModal.css +308 -0
  78. package/src/client/components/SelectCollectionModal/SelectCollectionModal.tsx +223 -0
  79. package/src/client/components/SelectCollectionModal/index.ts +7 -0
  80. package/src/client/components/Sidebar/Sidebar.css +570 -0
  81. package/src/client/components/Sidebar/Sidebar.tsx +617 -0
  82. package/src/client/components/Sidebar/index.ts +7 -0
  83. package/src/client/components/SkipLink/SkipLink.css +51 -0
  84. package/src/client/components/SkipLink/SkipLink.tsx +67 -0
  85. package/src/client/components/SkipLink/index.ts +7 -0
  86. package/src/client/components/UnsavedChangesModal/UnsavedChangesModal.css +233 -0
  87. package/src/client/components/UnsavedChangesModal/UnsavedChangesModal.tsx +160 -0
  88. package/src/client/components/UnsavedChangesModal/index.ts +1 -0
  89. package/src/client/components/VersionHistory/DiffViewer.css +430 -0
  90. package/src/client/components/VersionHistory/DiffViewer.tsx +383 -0
  91. package/src/client/components/VersionHistory/VersionActions.css +318 -0
  92. package/src/client/components/VersionHistory/VersionActions.tsx +277 -0
  93. package/src/client/components/VersionHistory/VersionHistoryPanel.css +369 -0
  94. package/src/client/components/VersionHistory/VersionHistoryPanel.tsx +469 -0
  95. package/src/client/components/VersionHistory/index.ts +9 -0
  96. package/src/client/context/ApiContext.tsx +154 -0
  97. package/src/client/context/ThemeContext.tsx +172 -0
  98. package/src/client/hooks/useAnnounce.ts +201 -0
  99. package/src/client/hooks/useApi.ts +374 -0
  100. package/src/client/hooks/useArrowNavigation.ts +286 -0
  101. package/src/client/hooks/useAutosave.ts +241 -0
  102. package/src/client/hooks/useFocusTrap.ts +178 -0
  103. package/src/client/hooks/useKeyboardShortcuts.ts +203 -0
  104. package/src/client/hooks/useSearch.ts +206 -0
  105. package/src/client/hooks/useVersionHistory.ts +451 -0
  106. package/src/client/index.tsx +70 -0
  107. package/src/client/styles.css +584 -0
  108. package/src/client/utils/focus.ts +57 -0
  109. package/src/client/utils/openInEditor.ts +130 -0
  110. package/src/client/variables.css +304 -0
  111. package/src/config/defaults.ts +109 -0
  112. package/src/config/index.ts +32 -0
  113. package/src/config/loader.ts +174 -0
  114. package/src/config/schema.ts +161 -0
  115. package/src/core/constants.ts +39 -0
  116. package/src/core/errors.ts +739 -0
  117. package/src/core/index.ts +11 -0
  118. package/src/discovery/collections.ts +216 -0
  119. package/src/discovery/index.ts +33 -0
  120. package/src/discovery/patterns.ts +702 -0
  121. package/src/discovery/schema.ts +453 -0
  122. package/src/filesystem/images.ts +798 -0
  123. package/src/filesystem/index.ts +107 -0
  124. package/src/filesystem/reader.ts +452 -0
  125. package/src/filesystem/version-config.ts +390 -0
  126. package/src/filesystem/versions.ts +1339 -0
  127. package/src/filesystem/watcher.ts +226 -0
  128. package/src/filesystem/writer.ts +540 -0
  129. package/src/index.ts +61 -0
  130. package/src/integration.ts +228 -0
  131. package/src/server/assets.ts +254 -0
  132. package/src/server/cache.ts +355 -0
  133. package/src/server/index.ts +33 -0
  134. package/src/server/middleware.ts +209 -0
  135. package/src/server/routes.ts +1428 -0
  136. package/src/types/api.ts +61 -0
  137. package/src/types/config.ts +134 -0
  138. package/src/types/content.ts +64 -0
  139. package/src/types/image.ts +48 -0
  140. package/src/types/index.ts +58 -0
  141. package/src/types/version.ts +117 -0
@@ -0,0 +1,390 @@
1
+ /**
2
+ * @fileoverview Config-aware wrappers for version history operations
3
+ *
4
+ * This module provides wrapper functions that automatically apply configuration
5
+ * defaults and check the enabled flag before performing version operations.
6
+ * These wrappers simplify usage by accepting partial configuration and handling
7
+ * all the configuration resolution internally.
8
+ *
9
+ * @module @writenex/astro/filesystem/version-config
10
+ * @see {@link saveVersion} - Core save function
11
+ * @see {@link getVersions} - Core list function
12
+ */
13
+
14
+ import type {
15
+ VersionHistoryConfig,
16
+ VersionEntry,
17
+ Version,
18
+ VersionResult,
19
+ SaveVersionOptions,
20
+ RestoreVersionOptions,
21
+ RestoreResult,
22
+ } from "@/types";
23
+ import { DEFAULT_VERSION_HISTORY_CONFIG } from "@/config/defaults";
24
+ import {
25
+ saveVersion as coreSaveVersion,
26
+ getVersions as coreGetVersions,
27
+ getVersion as coreGetVersion,
28
+ deleteVersion as coreDeleteVersion,
29
+ clearVersions as coreClearVersions,
30
+ pruneVersions as corePruneVersions,
31
+ restoreVersion as coreRestoreVersion,
32
+ } from "./versions";
33
+
34
+ // =============================================================================
35
+ // Configuration Resolution
36
+ // =============================================================================
37
+
38
+ /**
39
+ * Resolve version history configuration with defaults applied.
40
+ *
41
+ * Takes a partial configuration and merges it with defaults to produce
42
+ * a complete configuration object.
43
+ *
44
+ * @param config - Partial version history configuration
45
+ * @returns Complete configuration with all defaults applied
46
+ *
47
+ * @example
48
+ * ```typescript
49
+ * const resolved = resolveVersionConfig({ maxVersions: 50 });
50
+ * // Returns: { enabled: true, maxVersions: 50, storagePath: '.writenex/versions' }
51
+ * ```
52
+ */
53
+ export function resolveVersionConfig(
54
+ config?: VersionHistoryConfig
55
+ ): Required<VersionHistoryConfig> {
56
+ if (!config) {
57
+ return { ...DEFAULT_VERSION_HISTORY_CONFIG };
58
+ }
59
+
60
+ return {
61
+ enabled: config.enabled ?? DEFAULT_VERSION_HISTORY_CONFIG.enabled,
62
+ maxVersions:
63
+ config.maxVersions ?? DEFAULT_VERSION_HISTORY_CONFIG.maxVersions,
64
+ storagePath:
65
+ config.storagePath ?? DEFAULT_VERSION_HISTORY_CONFIG.storagePath,
66
+ };
67
+ }
68
+
69
+ /**
70
+ * Check if version history is enabled in the configuration.
71
+ *
72
+ * @param config - Version history configuration (partial or full)
73
+ * @returns True if version history is enabled
74
+ *
75
+ * @example
76
+ * ```typescript
77
+ * if (isVersionHistoryEnabled({ enabled: false })) {
78
+ * // This won't execute
79
+ * }
80
+ * ```
81
+ */
82
+ export function isVersionHistoryEnabled(
83
+ config?: VersionHistoryConfig
84
+ ): boolean {
85
+ const resolved = resolveVersionConfig(config);
86
+ return resolved.enabled;
87
+ }
88
+
89
+ // =============================================================================
90
+ // Config-Aware Version Operations
91
+ // =============================================================================
92
+
93
+ /**
94
+ * Save a version with automatic configuration resolution.
95
+ *
96
+ * This wrapper automatically applies configuration defaults and checks
97
+ * the enabled flag before delegating to the core saveVersion function.
98
+ *
99
+ * @param projectRoot - Absolute path to project root
100
+ * @param collection - Collection name
101
+ * @param contentId - Content item ID (slug)
102
+ * @param content - Full markdown content to save
103
+ * @param config - Partial version history configuration
104
+ * @param options - Save options
105
+ * @returns Result of the save operation
106
+ *
107
+ * @example
108
+ * ```typescript
109
+ * // With partial config - defaults are applied automatically
110
+ * const result = await saveVersionWithConfig(
111
+ * '/project',
112
+ * 'blog',
113
+ * 'my-post',
114
+ * '---\ntitle: My Post\n---\n\nContent...',
115
+ * { maxVersions: 50 } // enabled and storagePath use defaults
116
+ * );
117
+ * ```
118
+ */
119
+ export async function saveVersionWithConfig(
120
+ projectRoot: string,
121
+ collection: string,
122
+ contentId: string,
123
+ content: string,
124
+ config?: VersionHistoryConfig,
125
+ options?: SaveVersionOptions
126
+ ): Promise<VersionResult> {
127
+ const resolvedConfig = resolveVersionConfig(config);
128
+
129
+ // Early return if disabled
130
+ if (!resolvedConfig.enabled) {
131
+ return { success: true };
132
+ }
133
+
134
+ return coreSaveVersion(
135
+ projectRoot,
136
+ collection,
137
+ contentId,
138
+ content,
139
+ resolvedConfig,
140
+ options
141
+ );
142
+ }
143
+
144
+ /**
145
+ * Get all versions with automatic configuration resolution.
146
+ *
147
+ * This wrapper automatically applies configuration defaults and checks
148
+ * the enabled flag before delegating to the core getVersions function.
149
+ *
150
+ * @param projectRoot - Absolute path to project root
151
+ * @param collection - Collection name
152
+ * @param contentId - Content item ID (slug)
153
+ * @param config - Partial version history configuration
154
+ * @returns Array of version entries (empty if disabled)
155
+ *
156
+ * @example
157
+ * ```typescript
158
+ * const versions = await getVersionsWithConfig(
159
+ * '/project',
160
+ * 'blog',
161
+ * 'my-post',
162
+ * { storagePath: 'custom/versions' }
163
+ * );
164
+ * ```
165
+ */
166
+ export async function getVersionsWithConfig(
167
+ projectRoot: string,
168
+ collection: string,
169
+ contentId: string,
170
+ config?: VersionHistoryConfig
171
+ ): Promise<VersionEntry[]> {
172
+ const resolvedConfig = resolveVersionConfig(config);
173
+
174
+ // Early return if disabled
175
+ if (!resolvedConfig.enabled) {
176
+ return [];
177
+ }
178
+
179
+ return coreGetVersions(projectRoot, collection, contentId, resolvedConfig);
180
+ }
181
+
182
+ /**
183
+ * Get a specific version with automatic configuration resolution.
184
+ *
185
+ * This wrapper automatically applies configuration defaults and checks
186
+ * the enabled flag before delegating to the core getVersion function.
187
+ *
188
+ * @param projectRoot - Absolute path to project root
189
+ * @param collection - Collection name
190
+ * @param contentId - Content item ID (slug)
191
+ * @param versionId - Version ID to retrieve
192
+ * @param config - Partial version history configuration
193
+ * @returns Full version data or null if not found/disabled
194
+ *
195
+ * @example
196
+ * ```typescript
197
+ * const version = await getVersionWithConfig(
198
+ * '/project',
199
+ * 'blog',
200
+ * 'my-post',
201
+ * '2024-12-11T10-30-00-000Z'
202
+ * );
203
+ * ```
204
+ */
205
+ export async function getVersionWithConfig(
206
+ projectRoot: string,
207
+ collection: string,
208
+ contentId: string,
209
+ versionId: string,
210
+ config?: VersionHistoryConfig
211
+ ): Promise<Version | null> {
212
+ const resolvedConfig = resolveVersionConfig(config);
213
+
214
+ // Early return if disabled
215
+ if (!resolvedConfig.enabled) {
216
+ return null;
217
+ }
218
+
219
+ return coreGetVersion(
220
+ projectRoot,
221
+ collection,
222
+ contentId,
223
+ versionId,
224
+ resolvedConfig
225
+ );
226
+ }
227
+
228
+ /**
229
+ * Delete a version with automatic configuration resolution.
230
+ *
231
+ * This wrapper automatically applies configuration defaults before
232
+ * delegating to the core deleteVersion function.
233
+ *
234
+ * @param projectRoot - Absolute path to project root
235
+ * @param collection - Collection name
236
+ * @param contentId - Content item ID (slug)
237
+ * @param versionId - Version ID to delete
238
+ * @param config - Partial version history configuration
239
+ * @returns Result of the delete operation
240
+ *
241
+ * @example
242
+ * ```typescript
243
+ * const result = await deleteVersionWithConfig(
244
+ * '/project',
245
+ * 'blog',
246
+ * 'my-post',
247
+ * '2024-12-11T10-30-00-000Z'
248
+ * );
249
+ * ```
250
+ */
251
+ export async function deleteVersionWithConfig(
252
+ projectRoot: string,
253
+ collection: string,
254
+ contentId: string,
255
+ versionId: string,
256
+ config?: VersionHistoryConfig
257
+ ): Promise<VersionResult> {
258
+ const resolvedConfig = resolveVersionConfig(config);
259
+
260
+ return coreDeleteVersion(
261
+ projectRoot,
262
+ collection,
263
+ contentId,
264
+ versionId,
265
+ resolvedConfig
266
+ );
267
+ }
268
+
269
+ /**
270
+ * Clear all versions with automatic configuration resolution.
271
+ *
272
+ * This wrapper automatically applies configuration defaults before
273
+ * delegating to the core clearVersions function.
274
+ *
275
+ * @param projectRoot - Absolute path to project root
276
+ * @param collection - Collection name
277
+ * @param contentId - Content item ID (slug)
278
+ * @param config - Partial version history configuration
279
+ * @returns Result of the clear operation
280
+ *
281
+ * @example
282
+ * ```typescript
283
+ * const result = await clearVersionsWithConfig(
284
+ * '/project',
285
+ * 'blog',
286
+ * 'my-post'
287
+ * );
288
+ * ```
289
+ */
290
+ export async function clearVersionsWithConfig(
291
+ projectRoot: string,
292
+ collection: string,
293
+ contentId: string,
294
+ config?: VersionHistoryConfig
295
+ ): Promise<VersionResult> {
296
+ const resolvedConfig = resolveVersionConfig(config);
297
+
298
+ return coreClearVersions(projectRoot, collection, contentId, resolvedConfig);
299
+ }
300
+
301
+ /**
302
+ * Prune old versions with automatic configuration resolution.
303
+ *
304
+ * This wrapper automatically applies configuration defaults before
305
+ * delegating to the core pruneVersions function. Uses the configured
306
+ * maxVersions value for determining how many versions to keep.
307
+ *
308
+ * @param projectRoot - Absolute path to project root
309
+ * @param collection - Collection name
310
+ * @param contentId - Content item ID (slug)
311
+ * @param config - Partial version history configuration
312
+ * @returns Result of the prune operation
313
+ *
314
+ * @example
315
+ * ```typescript
316
+ * // Uses custom maxVersions
317
+ * const result = await pruneVersionsWithConfig(
318
+ * '/project',
319
+ * 'blog',
320
+ * 'my-post',
321
+ * { maxVersions: 10 }
322
+ * );
323
+ * ```
324
+ */
325
+ export async function pruneVersionsWithConfig(
326
+ projectRoot: string,
327
+ collection: string,
328
+ contentId: string,
329
+ config?: VersionHistoryConfig
330
+ ): Promise<VersionResult> {
331
+ const resolvedConfig = resolveVersionConfig(config);
332
+
333
+ return corePruneVersions(projectRoot, collection, contentId, resolvedConfig);
334
+ }
335
+
336
+ /**
337
+ * Restore a version with automatic configuration resolution.
338
+ *
339
+ * This wrapper automatically applies configuration defaults and checks
340
+ * the enabled flag before delegating to the core restoreVersion function.
341
+ *
342
+ * @param projectRoot - Absolute path to project root
343
+ * @param collection - Collection name
344
+ * @param contentId - Content item ID (slug)
345
+ * @param versionId - Version ID to restore
346
+ * @param contentFilePath - Absolute path to the current content file
347
+ * @param config - Partial version history configuration
348
+ * @param options - Restore options
349
+ * @returns Result of the restore operation
350
+ *
351
+ * @example
352
+ * ```typescript
353
+ * const result = await restoreVersionWithConfig(
354
+ * '/project',
355
+ * 'blog',
356
+ * 'my-post',
357
+ * '2024-12-11T10-30-00-000Z',
358
+ * '/project/src/content/blog/my-post.md'
359
+ * );
360
+ * ```
361
+ */
362
+ export async function restoreVersionWithConfig(
363
+ projectRoot: string,
364
+ collection: string,
365
+ contentId: string,
366
+ versionId: string,
367
+ contentFilePath: string,
368
+ config?: VersionHistoryConfig,
369
+ options?: RestoreVersionOptions
370
+ ): Promise<RestoreResult> {
371
+ const resolvedConfig = resolveVersionConfig(config);
372
+
373
+ // Early return if disabled
374
+ if (!resolvedConfig.enabled) {
375
+ return {
376
+ success: false,
377
+ error: "Version history is disabled",
378
+ };
379
+ }
380
+
381
+ return coreRestoreVersion(
382
+ projectRoot,
383
+ collection,
384
+ contentId,
385
+ versionId,
386
+ contentFilePath,
387
+ resolvedConfig,
388
+ options
389
+ );
390
+ }