@bendyline/docblocks-react 1.1.0 → 1.1.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.
Files changed (64) hide show
  1. package/README.md +23 -14
  2. package/dist/AppMenu/AppMenu.d.ts +11 -1
  3. package/dist/AppMenu/AppMenu.d.ts.map +1 -1
  4. package/dist/AppMenu/AppMenu.js +2 -2
  5. package/dist/AppMenu/AppMenu.js.map +1 -1
  6. package/dist/DocBlocksShell/DocBlocksShell.d.ts +23 -3
  7. package/dist/DocBlocksShell/DocBlocksShell.d.ts.map +1 -1
  8. package/dist/DocBlocksShell/DocBlocksShell.js +621 -94
  9. package/dist/DocBlocksShell/DocBlocksShell.js.map +1 -1
  10. package/dist/Export/ExportDialog.d.ts.map +1 -1
  11. package/dist/Export/ExportDialog.js +123 -7
  12. package/dist/Export/ExportDialog.js.map +1 -1
  13. package/dist/Export/ExportToolbarControls.d.ts.map +1 -1
  14. package/dist/Export/ExportToolbarControls.js +108 -17
  15. package/dist/Export/ExportToolbarControls.js.map +1 -1
  16. package/dist/Export/export-options.d.ts +35 -0
  17. package/dist/Export/export-options.d.ts.map +1 -1
  18. package/dist/Export/export-options.js +6 -1
  19. package/dist/Export/export-options.js.map +1 -1
  20. package/dist/Export/run-export.d.ts.map +1 -1
  21. package/dist/Export/run-export.js +185 -97
  22. package/dist/Export/run-export.js.map +1 -1
  23. package/dist/Export/transform-summaries.d.ts +7 -0
  24. package/dist/Export/transform-summaries.d.ts.map +1 -0
  25. package/dist/Export/transform-summaries.js +6 -0
  26. package/dist/Export/transform-summaries.js.map +1 -0
  27. package/dist/FileExplorer/FileExplorer.d.ts.map +1 -1
  28. package/dist/FileExplorer/FileExplorer.js +17 -2
  29. package/dist/FileExplorer/FileExplorer.js.map +1 -1
  30. package/dist/WorkspacePicker/WorkspaceSettingsButton.d.ts +2 -1
  31. package/dist/WorkspacePicker/WorkspaceSettingsButton.d.ts.map +1 -1
  32. package/dist/WorkspacePicker/WorkspaceSettingsButton.js +2 -2
  33. package/dist/WorkspacePicker/WorkspaceSettingsButton.js.map +1 -1
  34. package/dist/WorkspacePicker/WorkspaceSettingsDialog.d.ts +20 -0
  35. package/dist/WorkspacePicker/WorkspaceSettingsDialog.d.ts.map +1 -0
  36. package/dist/WorkspacePicker/WorkspaceSettingsDialog.js +36 -0
  37. package/dist/WorkspacePicker/WorkspaceSettingsDialog.js.map +1 -0
  38. package/dist/hooks/useAutoSave.d.ts +8 -2
  39. package/dist/hooks/useAutoSave.d.ts.map +1 -1
  40. package/dist/hooks/useAutoSave.js +65 -30
  41. package/dist/hooks/useAutoSave.js.map +1 -1
  42. package/dist/monaco-slim.d.ts +19 -0
  43. package/dist/monaco-slim.d.ts.map +1 -0
  44. package/dist/monaco-slim.js +19 -0
  45. package/dist/monaco-slim.js.map +1 -0
  46. package/dist/preferences/versioning.d.ts +27 -0
  47. package/dist/preferences/versioning.d.ts.map +1 -0
  48. package/dist/preferences/versioning.js +62 -0
  49. package/dist/preferences/versioning.js.map +1 -0
  50. package/package.json +14 -10
  51. package/src/AppMenu/AppMenu.tsx +64 -1
  52. package/src/DocBlocksShell/DocBlocksShell.tsx +839 -116
  53. package/src/Export/ExportDialog.tsx +236 -26
  54. package/src/Export/ExportToolbarControls.tsx +151 -21
  55. package/src/Export/export-options.ts +43 -1
  56. package/src/Export/run-export.ts +208 -97
  57. package/src/Export/transform-summaries.ts +14 -0
  58. package/src/FileExplorer/FileExplorer.tsx +31 -9
  59. package/src/WorkspacePicker/WorkspaceSettingsButton.tsx +9 -0
  60. package/src/WorkspacePicker/WorkspaceSettingsDialog.tsx +121 -0
  61. package/src/hooks/useAutoSave.ts +87 -29
  62. package/src/monaco-slim.ts +20 -0
  63. package/src/preferences/versioning.ts +69 -0
  64. package/src/styles/docblocks.css +995 -53
@@ -2,57 +2,115 @@
2
2
  * useAutoSave — debounced auto-save hook.
3
3
  *
4
4
  * Writes content to the FileSystemProvider after a delay
5
- * whenever the content changes.
5
+ * whenever the content changes. Returns a `flush` function so callers
6
+ * (e.g. an explicit Ctrl/Cmd+S handler) can force an immediate write
7
+ * and await its completion.
6
8
  */
7
9
 
8
10
  import { useEffect, useRef, useCallback } from 'react';
9
11
  import type { FileSystemProvider } from '@bendyline/docblocks/filesystem';
10
12
 
13
+ export interface UseAutoSaveResult {
14
+ /** Cancel any pending debounce and write the current content immediately. */
15
+ flush: () => Promise<void>;
16
+ }
17
+
11
18
  export function useAutoSave(
12
19
  provider: FileSystemProvider | null,
13
20
  filePath: string | null,
14
21
  content: string,
15
22
  delayMs = 500,
16
- ): void {
23
+ onSaved?: (filePath: string, content: string) => void,
24
+ ): UseAutoSaveResult {
17
25
  const timerRef = useRef<ReturnType<typeof setTimeout> | null>(null);
18
- const lastSavedRef = useRef<string>(content);
19
-
20
- const save = useCallback(async () => {
21
- if (!provider || !filePath) return;
22
- if (content === lastSavedRef.current) return;
23
- lastSavedRef.current = content;
24
- await provider.writeFile(filePath, content);
25
- }, [provider, filePath, content]);
26
-
27
- useEffect(() => {
28
- if (!provider || !filePath) return;
26
+ const contentRef = useRef(content);
27
+ const onSavedRef = useRef(onSaved);
28
+ const targetRef = useRef<{
29
+ provider: FileSystemProvider;
30
+ filePath: string;
31
+ lastSaved: string;
32
+ } | null>(null);
29
33
 
34
+ const clearTimer = useCallback(() => {
30
35
  if (timerRef.current) {
31
36
  clearTimeout(timerRef.current);
37
+ timerRef.current = null;
32
38
  }
39
+ }, []);
33
40
 
34
- timerRef.current = setTimeout(() => {
35
- save();
36
- }, delayMs);
41
+ const flushTarget = useCallback(
42
+ async (
43
+ target: {
44
+ provider: FileSystemProvider;
45
+ filePath: string;
46
+ lastSaved: string;
47
+ },
48
+ nextContent: string,
49
+ ) => {
50
+ if (nextContent === target.lastSaved) return;
51
+ const previous = target.lastSaved;
52
+ target.lastSaved = nextContent;
53
+ try {
54
+ await target.provider.writeFile(target.filePath, nextContent);
55
+ onSavedRef.current?.(target.filePath, nextContent);
56
+ } catch (err) {
57
+ target.lastSaved = previous;
58
+ throw err;
59
+ }
60
+ },
61
+ [],
62
+ );
63
+
64
+ useEffect(() => {
65
+ onSavedRef.current = onSaved;
66
+ }, [onSaved]);
67
+
68
+ useEffect(() => {
69
+ contentRef.current = content;
70
+ }, [content]);
71
+
72
+ useEffect(() => {
73
+ clearTimer();
74
+ targetRef.current = provider && filePath ? { provider, filePath, lastSaved: content } : null;
75
+ contentRef.current = content;
37
76
 
38
77
  return () => {
39
- if (timerRef.current) {
40
- clearTimeout(timerRef.current);
78
+ clearTimer();
79
+ const target = targetRef.current;
80
+ if (target) {
81
+ void flushTarget(target, contentRef.current).catch(() => undefined);
41
82
  }
83
+ targetRef.current = null;
42
84
  };
43
- }, [content, delayMs, save, provider, filePath]);
85
+ // `content` is intentionally captured only when the save target changes.
86
+ // Content edits are handled by the debounced effect below.
87
+ // eslint-disable-next-line react-hooks/exhaustive-deps
88
+ }, [provider, filePath, clearTimer, flushTarget]);
44
89
 
45
- // Flush on unmount
46
90
  useEffect(() => {
91
+ const target = targetRef.current;
92
+ if (!target) return;
93
+ clearTimer();
94
+
95
+ if (content !== target.lastSaved) {
96
+ timerRef.current = setTimeout(() => {
97
+ const currentTarget = targetRef.current;
98
+ if (!currentTarget) return;
99
+ void flushTarget(currentTarget, contentRef.current).catch(() => undefined);
100
+ }, delayMs);
101
+ }
102
+
47
103
  return () => {
48
- if (timerRef.current) {
49
- clearTimeout(timerRef.current);
50
- }
51
- // Sync save on unmount is best-effort
52
- if (provider && filePath && content !== lastSavedRef.current) {
53
- provider.writeFile(filePath, content);
54
- }
104
+ clearTimer();
55
105
  };
56
- // eslint-disable-next-line react-hooks/exhaustive-deps
57
- }, []);
106
+ }, [content, delayMs, clearTimer, flushTarget]);
107
+
108
+ const flush = useCallback(async () => {
109
+ clearTimer();
110
+ const target = targetRef.current;
111
+ if (!target) return;
112
+ await flushTarget(target, contentRef.current);
113
+ }, [clearTimer, flushTarget]);
114
+
115
+ return { flush };
58
116
  }
@@ -0,0 +1,20 @@
1
+ /**
2
+ * Slim Monaco editor bundle for DocBlocks browser surfaces.
3
+ *
4
+ * Squisq's raw editor lazy-loads `monaco-editor/esm/vs/editor/editor.main.js`
5
+ * so syntax highlighting works in raw mode. Alias both that subpath and the
6
+ * bare `monaco-editor` specifier to this file to keep the lazy chunk focused
7
+ * on markdown plus the languages users most often place in fenced blocks.
8
+ */
9
+
10
+ export * from 'monaco-editor/esm/vs/editor/editor.api';
11
+
12
+ import 'monaco-editor/esm/vs/basic-languages/markdown/markdown.contribution';
13
+ import 'monaco-editor/esm/vs/basic-languages/javascript/javascript.contribution';
14
+ import 'monaco-editor/esm/vs/basic-languages/typescript/typescript.contribution';
15
+ import 'monaco-editor/esm/vs/basic-languages/html/html.contribution';
16
+ import 'monaco-editor/esm/vs/basic-languages/css/css.contribution';
17
+ import 'monaco-editor/esm/vs/basic-languages/yaml/yaml.contribution';
18
+ import 'monaco-editor/esm/vs/basic-languages/python/python.contribution';
19
+ import 'monaco-editor/esm/vs/basic-languages/shell/shell.contribution';
20
+ import 'monaco-editor/esm/vs/basic-languages/xml/xml.contribution';
@@ -0,0 +1,69 @@
1
+ /**
2
+ * Versioning preferences — global default + per-workspace resolution.
3
+ *
4
+ * The global preference controls whether DocBlocks writes version
5
+ * snapshots (under `<basename>_files/.versions/`) when editing. The
6
+ * default is `'browser-only'` so local-folder workspaces stay clean by
7
+ * default and only IndexedDB workspaces accumulate version history.
8
+ *
9
+ * Each workspace can override the global default with its own setting
10
+ * stored on the WorkspaceDescriptor. `'inherit'` (or absent) defers to
11
+ * the global preference; `'on'` / `'off'` force the behavior regardless.
12
+ */
13
+
14
+ import type { WorkspaceDescriptor } from '@bendyline/docblocks/workspace';
15
+
16
+ export type VersioningPreference = 'on' | 'browser-only' | 'off';
17
+
18
+ const STORAGE_KEY = 'docblocks:versioningPreference';
19
+ const DEFAULT_PREFERENCE: VersioningPreference = 'browser-only';
20
+
21
+ export function loadVersioningPreference(): VersioningPreference {
22
+ try {
23
+ const raw = localStorage.getItem(STORAGE_KEY);
24
+ if (raw === 'on' || raw === 'browser-only' || raw === 'off') return raw;
25
+ } catch {
26
+ // ignore
27
+ }
28
+ return DEFAULT_PREFERENCE;
29
+ }
30
+
31
+ export function saveVersioningPreference(value: VersioningPreference): void {
32
+ try {
33
+ localStorage.setItem(STORAGE_KEY, value);
34
+ } catch {
35
+ // ignore quota errors
36
+ }
37
+ }
38
+
39
+ /** Whether a workspace type is "local" (writes to a real folder on disk). */
40
+ export function isLocalWorkspaceType(type: WorkspaceDescriptor['type']): boolean {
41
+ return type === 'native' || type === 'electron-native';
42
+ }
43
+
44
+ /**
45
+ * Compute the effective versioning state for a workspace, honoring the
46
+ * per-workspace override first and falling back to the global preference.
47
+ *
48
+ * Returns `false` whenever no workspace is provided so callers can use
49
+ * this directly during initial render before a workspace loads.
50
+ */
51
+ export function resolveVersioningEnabled(
52
+ workspace: WorkspaceDescriptor | null,
53
+ globalPref: VersioningPreference,
54
+ ): boolean {
55
+ if (!workspace) return false;
56
+
57
+ const override = workspace.versioningOverride;
58
+ if (override === 'on') return true;
59
+ if (override === 'off') return false;
60
+
61
+ switch (globalPref) {
62
+ case 'on':
63
+ return true;
64
+ case 'off':
65
+ return false;
66
+ case 'browser-only':
67
+ return !isLocalWorkspaceType(workspace.type);
68
+ }
69
+ }