@particle-academy/fancy-code 0.1.2 → 0.2.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 +2 -2
- package/dist/index.cjs +878 -403
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +63 -26
- package/dist/index.d.ts +63 -26
- package/dist/index.js +877 -402
- package/dist/index.js.map +1 -1
- package/dist/styles.css +18 -18
- package/dist/styles.css.map +1 -1
- package/package.json +3 -13
package/dist/index.d.ts
CHANGED
|
@@ -1,8 +1,50 @@
|
|
|
1
1
|
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
2
|
+
import { RefObject, ReactNode } from 'react';
|
|
3
|
+
|
|
4
|
+
interface ThemeColors {
|
|
5
|
+
background: string;
|
|
6
|
+
foreground: string;
|
|
7
|
+
gutterBackground: string;
|
|
8
|
+
gutterForeground: string;
|
|
9
|
+
gutterBorder: string;
|
|
10
|
+
activeLineBackground: string;
|
|
11
|
+
selectionBackground: string;
|
|
12
|
+
cursorColor: string;
|
|
13
|
+
keyword: string;
|
|
14
|
+
string: string;
|
|
15
|
+
comment: string;
|
|
16
|
+
number: string;
|
|
17
|
+
operator: string;
|
|
18
|
+
function: string;
|
|
19
|
+
type: string;
|
|
20
|
+
tag: string;
|
|
21
|
+
attribute: string;
|
|
22
|
+
attributeValue: string;
|
|
23
|
+
punctuation: string;
|
|
24
|
+
variable: string;
|
|
25
|
+
}
|
|
26
|
+
interface ThemeDefinition {
|
|
27
|
+
/** Unique theme name */
|
|
28
|
+
name: string;
|
|
29
|
+
/** Whether this is a dark or light theme */
|
|
30
|
+
variant: "light" | "dark";
|
|
31
|
+
/** Color definitions */
|
|
32
|
+
colors: ThemeColors;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
interface UseEditorEngineReturn {
|
|
36
|
+
textareaRef: RefObject<HTMLTextAreaElement | null>;
|
|
37
|
+
highlightedHtml: string;
|
|
38
|
+
lineCount: number;
|
|
39
|
+
activeLine: number;
|
|
40
|
+
themeColors: ThemeColors;
|
|
41
|
+
handleKeyDown: (e: React.KeyboardEvent<HTMLTextAreaElement>) => void;
|
|
42
|
+
handleInput: () => void;
|
|
43
|
+
handleScroll: () => void;
|
|
44
|
+
handleSelect: () => void;
|
|
45
|
+
scrollTop: number;
|
|
46
|
+
scrollLeft: number;
|
|
47
|
+
}
|
|
6
48
|
|
|
7
49
|
interface CodeEditorProps {
|
|
8
50
|
children: ReactNode;
|
|
@@ -33,12 +75,8 @@ interface CodeEditorProps {
|
|
|
33
75
|
minHeight?: number;
|
|
34
76
|
/** Maximum height in px (scrolls beyond this) */
|
|
35
77
|
maxHeight?: number;
|
|
36
|
-
/** Additional CodeMirror extensions */
|
|
37
|
-
extensions?: Extension[];
|
|
38
78
|
}
|
|
39
79
|
interface CodeEditorContextValue {
|
|
40
|
-
/** The CodeMirror EditorView (null during SSR or before mount) */
|
|
41
|
-
view: EditorView | null;
|
|
42
80
|
/** Get the current document text */
|
|
43
81
|
getValue: () => string;
|
|
44
82
|
/** Get the currently selected text */
|
|
@@ -76,8 +114,10 @@ interface CodeEditorContextValue {
|
|
|
76
114
|
};
|
|
77
115
|
/** Length of the current selection (0 if none) */
|
|
78
116
|
selectionLength: number;
|
|
79
|
-
/**
|
|
80
|
-
|
|
117
|
+
/** Placeholder text */
|
|
118
|
+
placeholder?: string;
|
|
119
|
+
/** @internal */
|
|
120
|
+
_engineReturn: UseEditorEngineReturn | null;
|
|
81
121
|
/** @internal */
|
|
82
122
|
_minHeight?: number;
|
|
83
123
|
/** @internal */
|
|
@@ -95,7 +135,7 @@ interface CodeEditorStatusBarProps {
|
|
|
95
135
|
className?: string;
|
|
96
136
|
}
|
|
97
137
|
|
|
98
|
-
declare function CodeEditorPanel({ className }: CodeEditorPanelProps): react_jsx_runtime.JSX.Element;
|
|
138
|
+
declare function CodeEditorPanel({ className }: CodeEditorPanelProps): react_jsx_runtime.JSX.Element | null;
|
|
99
139
|
declare namespace CodeEditorPanel {
|
|
100
140
|
var displayName: string;
|
|
101
141
|
}
|
|
@@ -115,7 +155,7 @@ declare namespace CodeEditorStatusBar {
|
|
|
115
155
|
var displayName: string;
|
|
116
156
|
}
|
|
117
157
|
|
|
118
|
-
declare function CodeEditorRoot({ children, className, value: valueProp, defaultValue, onChange, language: languageProp, onLanguageChange, theme, readOnly, lineNumbers: lineNumbersProp, wordWrap: wordWrapProp, tabSize: tabSizeProp, placeholder, minHeight, maxHeight,
|
|
158
|
+
declare function CodeEditorRoot({ children, className, value: valueProp, defaultValue, onChange, language: languageProp, onLanguageChange, theme, readOnly, lineNumbers: lineNumbersProp, wordWrap: wordWrapProp, tabSize: tabSizeProp, placeholder, minHeight, maxHeight, }: CodeEditorProps): react_jsx_runtime.JSX.Element;
|
|
119
159
|
declare namespace CodeEditorRoot {
|
|
120
160
|
var displayName: string;
|
|
121
161
|
}
|
|
@@ -129,32 +169,29 @@ declare const CodeEditor: typeof CodeEditorRoot & {
|
|
|
129
169
|
|
|
130
170
|
declare function useCodeEditor(): CodeEditorContextValue;
|
|
131
171
|
|
|
172
|
+
type TokenType = "keyword" | "string" | "comment" | "number" | "operator" | "tag" | "attribute" | "attributeValue" | "punctuation" | "function" | "type" | "variable" | "plain";
|
|
173
|
+
interface Token {
|
|
174
|
+
type: TokenType;
|
|
175
|
+
start: number;
|
|
176
|
+
end: number;
|
|
177
|
+
}
|
|
178
|
+
type Tokenizer = (source: string) => Token[];
|
|
179
|
+
|
|
132
180
|
interface LanguageDefinition {
|
|
133
181
|
/** Display name shown in UI (e.g., "JavaScript") */
|
|
134
182
|
name: string;
|
|
135
183
|
/** Alternative keys (e.g., ["js", "javascript"]) */
|
|
136
184
|
aliases?: string[];
|
|
137
|
-
/**
|
|
138
|
-
|
|
185
|
+
/** Tokenizer function for syntax highlighting */
|
|
186
|
+
tokenize: Tokenizer;
|
|
139
187
|
}
|
|
140
188
|
|
|
141
189
|
declare function registerLanguage(def: LanguageDefinition): void;
|
|
142
190
|
declare function getLanguage(name: string): LanguageDefinition | undefined;
|
|
143
191
|
declare function getRegisteredLanguages(): string[];
|
|
144
192
|
|
|
145
|
-
interface ThemeDefinition {
|
|
146
|
-
/** Unique theme name */
|
|
147
|
-
name: string;
|
|
148
|
-
/** Whether this is a dark or light theme */
|
|
149
|
-
variant: "light" | "dark";
|
|
150
|
-
/** CodeMirror editor theme (gutter, cursor, selection, etc.) */
|
|
151
|
-
editorTheme: Extension;
|
|
152
|
-
/** Syntax highlighting color scheme */
|
|
153
|
-
highlightStyle: HighlightStyle;
|
|
154
|
-
}
|
|
155
|
-
|
|
156
193
|
declare function registerTheme(theme: ThemeDefinition): void;
|
|
157
194
|
declare function getTheme(name: string): ThemeDefinition | undefined;
|
|
158
195
|
declare function getRegisteredThemes(): string[];
|
|
159
196
|
|
|
160
|
-
export { CodeEditor, type CodeEditorContextValue, type CodeEditorPanelProps, type CodeEditorProps, type CodeEditorStatusBarProps, type CodeEditorToolbarProps, type LanguageDefinition, type ThemeDefinition, getLanguage, getRegisteredLanguages, getRegisteredThemes, getTheme, registerLanguage, registerTheme, useCodeEditor };
|
|
197
|
+
export { CodeEditor, type CodeEditorContextValue, type CodeEditorPanelProps, type CodeEditorProps, type CodeEditorStatusBarProps, type CodeEditorToolbarProps, type LanguageDefinition, type ThemeColors, type ThemeDefinition, type Token, type TokenType, type Tokenizer, getLanguage, getRegisteredLanguages, getRegisteredThemes, getTheme, registerLanguage, registerTheme, useCodeEditor };
|