@particle-academy/fancy-code 0.4.1 → 0.4.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.
package/README.md CHANGED
@@ -210,25 +210,19 @@ Add languages beyond the built-ins using `registerLanguage`:
210
210
 
211
211
  ```tsx
212
212
  import { registerLanguage } from "@particle-academy/fancy-code";
213
+ import type { Tokenizer } from "@particle-academy/fancy-code";
213
214
 
214
- registerLanguage({
215
- name: "Python",
216
- aliases: ["py", "python"],
217
- support: () => {
218
- // Return a LanguageSupport instance
219
- const { python } = require("@codemirror/lang-python");
220
- return python();
221
- },
222
- });
215
+ const tokenizeRuby: Tokenizer = (source) => {
216
+ const tokens = [];
217
+ // Your regex-based tokenizer logic here
218
+ // See src/engine/tokenizers/javascript.ts for a full example
219
+ return tokens;
220
+ };
223
221
 
224
- // Lazy-loaded
225
222
  registerLanguage({
226
- name: "Rust",
227
- aliases: ["rs", "rust"],
228
- support: async () => {
229
- const { rust } = await import("@codemirror/lang-rust");
230
- return rust();
231
- },
223
+ name: "Ruby",
224
+ aliases: ["rb", "ruby"],
225
+ tokenize: tokenizeRuby,
232
226
  });
233
227
  ```
234
228
 
@@ -323,7 +317,7 @@ src/
323
317
  │ ├── CodeEditorStatusBar.tsx # Cursor/language/tab display
324
318
  │ └── index.ts
325
319
  ├── hooks/
326
- │ ├── use-codemirror.ts # Core editor lifecycle
320
+ │ ├── use-editor-engine.ts # Core editor lifecycle
327
321
  │ └── use-dark-mode.ts # Reactive prefers-color-scheme
328
322
  ├── languages/
329
323
  │ ├── registry.ts # Global language registry
package/dist/index.cjs CHANGED
@@ -85,7 +85,7 @@ function CodeEditorPanel({ className }) {
85
85
  children: lineNumberElements
86
86
  }
87
87
  ),
88
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "relative min-w-0 flex-1", children: [
88
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: reactFancy.cn("relative flex-1", wordWrap && "min-w-0"), children: [
89
89
  /* @__PURE__ */ jsxRuntime.jsx(
90
90
  "pre",
91
91
  {
@@ -110,7 +110,10 @@ function CodeEditorPanel({ className }) {
110
110
  "textarea",
111
111
  {
112
112
  ref: textareaRef,
113
- className: "relative m-0 block w-full resize-none border-none bg-transparent p-2.5 text-[13px] leading-[1.5] text-transparent outline-none",
113
+ className: reactFancy.cn(
114
+ "relative m-0 block resize-none border-none bg-transparent p-2.5 text-[13px] leading-[1.5] text-transparent outline-none",
115
+ wordWrap ? "w-full" : "min-w-full"
116
+ ),
114
117
  style: {
115
118
  caretColor: themeColors.cursorColor,
116
119
  minHeight: _minHeight ? _minHeight - 40 : 80,
@@ -1295,6 +1298,7 @@ function useEditorEngine({
1295
1298
  language,
1296
1299
  theme,
1297
1300
  readOnly,
1301
+ wordWrap,
1298
1302
  tabSize,
1299
1303
  onCursorChange
1300
1304
  }) {
@@ -1333,7 +1337,13 @@ function useEditorEngine({
1333
1337
  if (!ta) return;
1334
1338
  ta.style.height = "auto";
1335
1339
  ta.style.height = ta.scrollHeight + "px";
1336
- }, []);
1340
+ if (!wordWrap) {
1341
+ ta.style.width = "0";
1342
+ ta.style.width = ta.scrollWidth + "px";
1343
+ } else {
1344
+ ta.style.width = "";
1345
+ }
1346
+ }, [wordWrap]);
1337
1347
  react.useEffect(() => {
1338
1348
  const ta = textareaRef.current;
1339
1349
  if (!ta) return;
@@ -1521,6 +1531,7 @@ function CodeEditorRoot({
1521
1531
  language: currentLanguage,
1522
1532
  theme: resolvedTheme,
1523
1533
  readOnly,
1534
+ wordWrap: isWordWrap,
1524
1535
  tabSize: tabSizeProp,
1525
1536
  onCursorChange: ({ line, col, selectionLength: sel }) => {
1526
1537
  setCursorPosition({ line, col });