@pyreon/code 0.5.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 (80) hide show
  1. package/LICENSE +21 -0
  2. package/lib/analysis/index.js.html +5406 -0
  3. package/lib/dist-B5vB-rif.js +3904 -0
  4. package/lib/dist-B5vB-rif.js.map +1 -0
  5. package/lib/dist-BAfzu5eu.js +1428 -0
  6. package/lib/dist-BAfzu5eu.js.map +1 -0
  7. package/lib/dist-BLlV_D16.js +1166 -0
  8. package/lib/dist-BLlV_D16.js.map +1 -0
  9. package/lib/dist-BNmKLTu8.js +373 -0
  10. package/lib/dist-BNmKLTu8.js.map +1 -0
  11. package/lib/dist-BZtTlC1J.js +692 -0
  12. package/lib/dist-BZtTlC1J.js.map +1 -0
  13. package/lib/dist-CTDqGIAf.js +856 -0
  14. package/lib/dist-CTDqGIAf.js.map +1 -0
  15. package/lib/dist-CTPisNZp.js +83 -0
  16. package/lib/dist-CTPisNZp.js.map +1 -0
  17. package/lib/dist-Ce2tvOxv.js +379 -0
  18. package/lib/dist-Ce2tvOxv.js.map +1 -0
  19. package/lib/dist-CttF0OTv.js +465 -0
  20. package/lib/dist-CttF0OTv.js.map +1 -0
  21. package/lib/dist-DS2tluW9.js +818 -0
  22. package/lib/dist-DS2tluW9.js.map +1 -0
  23. package/lib/dist-DUNx9ldu.js +460 -0
  24. package/lib/dist-DUNx9ldu.js.map +1 -0
  25. package/lib/dist-Dej_yf3k.js +473 -0
  26. package/lib/dist-Dej_yf3k.js.map +1 -0
  27. package/lib/dist-DshStUxU.js +283 -0
  28. package/lib/dist-DshStUxU.js.map +1 -0
  29. package/lib/dist-qTrOe7xY.js +461 -0
  30. package/lib/dist-qTrOe7xY.js.map +1 -0
  31. package/lib/dist-v09vikKr.js +2421 -0
  32. package/lib/dist-v09vikKr.js.map +1 -0
  33. package/lib/index.js +915 -0
  34. package/lib/index.js.map +1 -0
  35. package/lib/types/dist.d.ts +798 -0
  36. package/lib/types/dist.d.ts.map +1 -0
  37. package/lib/types/dist10.d.ts +67 -0
  38. package/lib/types/dist10.d.ts.map +1 -0
  39. package/lib/types/dist11.d.ts +126 -0
  40. package/lib/types/dist11.d.ts.map +1 -0
  41. package/lib/types/dist12.d.ts +21 -0
  42. package/lib/types/dist12.d.ts.map +1 -0
  43. package/lib/types/dist13.d.ts +404 -0
  44. package/lib/types/dist13.d.ts.map +1 -0
  45. package/lib/types/dist14.d.ts +292 -0
  46. package/lib/types/dist14.d.ts.map +1 -0
  47. package/lib/types/dist15.d.ts +132 -0
  48. package/lib/types/dist15.d.ts.map +1 -0
  49. package/lib/types/dist2.d.ts +15 -0
  50. package/lib/types/dist2.d.ts.map +1 -0
  51. package/lib/types/dist3.d.ts +106 -0
  52. package/lib/types/dist3.d.ts.map +1 -0
  53. package/lib/types/dist4.d.ts +67 -0
  54. package/lib/types/dist4.d.ts.map +1 -0
  55. package/lib/types/dist5.d.ts +95 -0
  56. package/lib/types/dist5.d.ts.map +1 -0
  57. package/lib/types/dist6.d.ts +330 -0
  58. package/lib/types/dist6.d.ts.map +1 -0
  59. package/lib/types/dist7.d.ts +15 -0
  60. package/lib/types/dist7.d.ts.map +1 -0
  61. package/lib/types/dist8.d.ts +15 -0
  62. package/lib/types/dist8.d.ts.map +1 -0
  63. package/lib/types/dist9.d.ts +635 -0
  64. package/lib/types/dist9.d.ts.map +1 -0
  65. package/lib/types/index.d.ts +852 -0
  66. package/lib/types/index.d.ts.map +1 -0
  67. package/lib/types/index2.d.ts +347 -0
  68. package/lib/types/index2.d.ts.map +1 -0
  69. package/package.json +79 -0
  70. package/src/components/code-editor.tsx +42 -0
  71. package/src/components/diff-editor.tsx +97 -0
  72. package/src/components/tabbed-editor.tsx +86 -0
  73. package/src/editor.ts +652 -0
  74. package/src/index.ts +52 -0
  75. package/src/languages.ts +77 -0
  76. package/src/minimap.ts +160 -0
  77. package/src/tabbed-editor.ts +231 -0
  78. package/src/tests/code.test.ts +505 -0
  79. package/src/themes.ts +87 -0
  80. package/src/types.ts +253 -0
package/src/types.ts ADDED
@@ -0,0 +1,253 @@
1
+ import type { Extension } from '@codemirror/state'
2
+ import type { EditorView } from '@codemirror/view'
3
+ import type { Computed, Signal } from '@pyreon/reactivity'
4
+
5
+ // ─── Editor config ───────────────────────────────────────────────────────────
6
+
7
+ export type EditorLanguage =
8
+ | 'javascript'
9
+ | 'typescript'
10
+ | 'jsx'
11
+ | 'tsx'
12
+ | 'html'
13
+ | 'css'
14
+ | 'json'
15
+ | 'markdown'
16
+ | 'python'
17
+ | 'rust'
18
+ | 'sql'
19
+ | 'xml'
20
+ | 'yaml'
21
+ | 'cpp'
22
+ | 'java'
23
+ | 'go'
24
+ | 'php'
25
+ | 'ruby'
26
+ | 'shell'
27
+ | 'plain'
28
+
29
+ export type EditorTheme = 'light' | 'dark' | Extension
30
+
31
+ export interface EditorConfig {
32
+ /** Initial value */
33
+ value?: string
34
+ /** Language for syntax highlighting — lazy-loaded */
35
+ language?: EditorLanguage
36
+ /** Theme — 'light', 'dark', or a custom CodeMirror theme extension */
37
+ theme?: EditorTheme
38
+ /** Show line numbers — default: true */
39
+ lineNumbers?: boolean
40
+ /** Read-only mode — default: false */
41
+ readOnly?: boolean
42
+ /** Enable code folding — default: true */
43
+ foldGutter?: boolean
44
+ /** Enable bracket matching — default: true */
45
+ bracketMatching?: boolean
46
+ /** Enable autocomplete — default: true */
47
+ autocomplete?: boolean
48
+ /** Enable search (Cmd+F) — default: true */
49
+ search?: boolean
50
+ /** Enable lint/diagnostics — default: false */
51
+ lint?: boolean
52
+ /** Enable indent guides — default: true */
53
+ highlightIndentGuides?: boolean
54
+ /** Vim keybinding mode — default: false */
55
+ vim?: boolean
56
+ /** Emacs keybinding mode — default: false */
57
+ emacs?: boolean
58
+ /** Tab size — default: 2 */
59
+ tabSize?: number
60
+ /** Enable indent guides — default: true */
61
+ indentGuides?: boolean
62
+ /** Enable line wrapping — default: false */
63
+ lineWrapping?: boolean
64
+ /** Placeholder text when empty */
65
+ placeholder?: string
66
+ /** Enable minimap — default: false */
67
+ minimap?: boolean
68
+ /** Additional CodeMirror extensions */
69
+ extensions?: Extension[]
70
+ /** Called when value changes */
71
+ onChange?: (value: string) => void
72
+ }
73
+
74
+ // ─── Editor instance ─────────────────────────────────────────────────────────
75
+
76
+ export interface EditorInstance {
77
+ /** Current editor value — reactive signal */
78
+ value: Signal<string>
79
+ /** Current language — reactive signal */
80
+ language: Signal<EditorLanguage>
81
+ /** Current theme — reactive signal */
82
+ theme: Signal<EditorTheme>
83
+ /** Read-only state — reactive signal */
84
+ readOnly: Signal<boolean>
85
+ /** Cursor position — reactive */
86
+ cursor: Computed<{ line: number; col: number }>
87
+ /** Current selection — reactive */
88
+ selection: Computed<{ from: number; to: number; text: string }>
89
+ /** Line count — reactive */
90
+ lineCount: Computed<number>
91
+ /** Whether the editor has focus — reactive */
92
+ focused: Signal<boolean>
93
+ /** The underlying CodeMirror EditorView — null until mounted */
94
+ view: Signal<EditorView | null>
95
+ /** Focus the editor */
96
+ focus: () => void
97
+ /** Insert text at cursor */
98
+ insert: (text: string) => void
99
+ /** Replace selection */
100
+ replaceSelection: (text: string) => void
101
+ /** Select a range */
102
+ select: (from: number, to: number) => void
103
+ /** Select all */
104
+ selectAll: () => void
105
+ /** Go to a specific line */
106
+ goToLine: (line: number) => void
107
+ /** Undo */
108
+ undo: () => void
109
+ /** Redo */
110
+ redo: () => void
111
+ /** Fold all */
112
+ foldAll: () => void
113
+ /** Unfold all */
114
+ unfoldAll: () => void
115
+ /** Set diagnostics (lint errors/warnings) */
116
+ setDiagnostics: (diagnostics: Diagnostic[]) => void
117
+ /** Clear all diagnostics */
118
+ clearDiagnostics: () => void
119
+ /** Highlight a specific line (e.g., error line, current execution) */
120
+ highlightLine: (line: number, className: string) => void
121
+ /** Clear all line highlights */
122
+ clearLineHighlights: () => void
123
+ /** Set gutter markers (breakpoints, error icons) */
124
+ setGutterMarker: (line: number, marker: GutterMarker) => void
125
+ /** Clear all gutter markers */
126
+ clearGutterMarkers: () => void
127
+ /** Add a custom keybinding */
128
+ addKeybinding: (key: string, handler: () => boolean | undefined) => void
129
+ /** Get the text of a specific line */
130
+ getLine: (line: number) => string
131
+ /** Get word at cursor position */
132
+ getWordAtCursor: () => string
133
+ /** Scroll to a specific position */
134
+ scrollTo: (pos: number) => void
135
+ /** The editor configuration */
136
+ config: EditorConfig
137
+ /** Dispose — clean up view and listeners */
138
+ dispose: () => void
139
+ }
140
+
141
+ // ─── Diagnostic ──────────────────────────────────────────────────────────────
142
+
143
+ export interface Diagnostic {
144
+ /** Start position (character offset) */
145
+ from: number
146
+ /** End position (character offset) */
147
+ to: number
148
+ /** Severity */
149
+ severity: 'error' | 'warning' | 'info' | 'hint'
150
+ /** Message */
151
+ message: string
152
+ /** Optional source (e.g., "typescript", "eslint") */
153
+ source?: string
154
+ }
155
+
156
+ // ─── Gutter marker ───────────────────────────────────────────────────────────
157
+
158
+ export interface GutterMarker {
159
+ /** CSS class for the marker element */
160
+ class?: string
161
+ /** Text content (e.g., emoji or icon) */
162
+ text?: string
163
+ /** Tooltip on hover */
164
+ title?: string
165
+ }
166
+
167
+ // ─── Component props ─────────────────────────────────────────────────────────
168
+
169
+ export interface CodeEditorProps {
170
+ instance: EditorInstance
171
+ style?: string
172
+ class?: string
173
+ }
174
+
175
+ export interface DiffEditorProps {
176
+ /** Original (left) content */
177
+ original: string | Signal<string>
178
+ /** Modified (right) content */
179
+ modified: string | Signal<string>
180
+ /** Language for both panels */
181
+ language?: EditorLanguage
182
+ /** Theme */
183
+ theme?: EditorTheme
184
+ /** Show inline diff instead of side-by-side — default: false */
185
+ inline?: boolean
186
+ /** Read-only — default: true */
187
+ readOnly?: boolean
188
+ style?: string
189
+ class?: string
190
+ }
191
+
192
+ // ─── Tabs ────────────────────────────────────────────────────────────────────
193
+
194
+ export interface Tab {
195
+ /** Unique tab identifier — defaults to name */
196
+ id?: string
197
+ /** File name displayed in the tab */
198
+ name: string
199
+ /** Language for syntax highlighting */
200
+ language?: EditorLanguage
201
+ /** File content */
202
+ value: string
203
+ /** Whether the tab has unsaved changes */
204
+ modified?: boolean
205
+ /** Whether the tab can be closed — default: true */
206
+ closable?: boolean
207
+ }
208
+
209
+ export interface TabbedEditorConfig {
210
+ /** Initial tabs */
211
+ tabs?: Tab[]
212
+ /** Theme — 'light', 'dark', or custom */
213
+ theme?: EditorTheme
214
+ /** Editor config applied to all tabs */
215
+ editorConfig?: Omit<EditorConfig, 'value' | 'language' | 'theme'>
216
+ }
217
+
218
+ export interface TabbedEditorInstance {
219
+ /** The underlying editor instance */
220
+ editor: EditorInstance
221
+ /** All open tabs — reactive */
222
+ tabs: Signal<Tab[]>
223
+ /** Active tab — reactive */
224
+ activeTab: Computed<Tab | null>
225
+ /** Active tab ID — reactive */
226
+ activeTabId: Signal<string>
227
+ /** Open a new tab (or switch to it if already open) */
228
+ openTab: (tab: Tab) => void
229
+ /** Close a tab by ID */
230
+ closeTab: (id: string) => void
231
+ /** Switch to a tab by ID */
232
+ switchTab: (id: string) => void
233
+ /** Rename a tab */
234
+ renameTab: (id: string, name: string) => void
235
+ /** Mark a tab as modified/saved */
236
+ setModified: (id: string, modified: boolean) => void
237
+ /** Reorder tabs */
238
+ moveTab: (fromIndex: number, toIndex: number) => void
239
+ /** Get tab by ID */
240
+ getTab: (id: string) => Tab | undefined
241
+ /** Close all tabs */
242
+ closeAll: () => void
243
+ /** Close all tabs except the given one */
244
+ closeOthers: (id: string) => void
245
+ /** Dispose */
246
+ dispose: () => void
247
+ }
248
+
249
+ export interface TabbedEditorProps {
250
+ instance: TabbedEditorInstance
251
+ style?: string
252
+ class?: string
253
+ }