@catalystsoftware/ui 1.0.15 → 1.0.16

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.
@@ -1,5 +1,5 @@
1
1
  import { ClientOnly, } from "~/utils/client-only";
2
- import React, { useCallback, useEffect, useRef, useState } from "react";
2
+ import React, { useCallback, useEffect, useRef, useState } from "react";
3
3
  import { X, } from "lucide-react";
4
4
  import { LoadingPage, SpinnerV4, DEFAULT_PREF, loadEditorSettings, autoSaveSettings, handleEditorDidMount as baseHandleEditorDidMount, renderEditor as baseRenderEditor, useToasted, MonacoToolbar, } from "~/components/catalyst-ui";
5
5
  import { useDS, DSTrigger } from "~/components/catalyst-ui";
@@ -18,7 +18,7 @@ export function MonacoEditor({ setCode, code, }) {
18
18
  const [theme, setTheme] = useState(DEFAULT_PREF.theme);
19
19
  const [isFullscreen, setIsFullscreen] = useState(DEFAULT_PREF.isFullscreen);
20
20
  const [es, setEs] = useState(() => loadEditorSettings());
21
- const [isSaving, setIsSaving] = useState(false);
21
+ const [isSaving, setIsSaving] = useState(false);
22
22
  const [lastSaved, setLastSaved] = useState(null);
23
23
  const [isClient, setIsClient] = useState(false);
24
24
  const [editorRenameTab, setEditorRenameTab] = useState(false);
@@ -330,76 +330,75 @@ export function MonacoEditor({ setCode, code, }) {
330
330
  };
331
331
 
332
332
  const TabComponent = ({ tab, isActive, onClose, onSelect }) => {
333
- const [isEditing, setIsEditing] = useState(false);
334
- const [editName, setEditName] = useState(tab.name);
335
- const inputRef = useRef<HTMLInputElement>(null);
336
-
337
- useEffect(() => {
338
- if (editorRenameTab && isActive) {
339
- setIsEditing(true);
340
- setEditName(tab.name);
341
- }
342
- }, [editorRenameTab, isActive]);
343
-
344
- useEffect(() => {
345
- if (isEditing && inputRef.current) {
346
- inputRef.current.focus();
347
- inputRef.current.select();
348
- }
349
- }, [isEditing]);
333
+ const [isEditing, setIsEditing] = useState(false);
334
+ const [editName, setEditName] = useState(tab.name);
335
+ const inputRef = useRef<HTMLInputElement>(null);
336
+
337
+ useEffect(() => {
338
+ if (editorRenameTab && isActive) {
339
+ setIsEditing(true);
340
+ setEditName(tab.name);
341
+ }
342
+ }, [editorRenameTab, isActive]);
350
343
 
351
- const handleRename = () => {
352
- if (editName.trim() && editName !== tab.name) {
353
- renameTab(tab.id, editName.trim());
354
- }
355
- setIsEditing(false);
356
- setEditorRenameTab(false);
357
- };
344
+ useEffect(() => {
345
+ if (isEditing && inputRef.current) {
346
+ inputRef.current.focus();
347
+ inputRef.current.select();
348
+ }
349
+ }, [isEditing]);
358
350
 
359
- const handleKeyDown = (e: React.KeyboardEvent) => {
360
- if (e.key === 'Enter') {
361
- handleRename();
362
- } else if (e.key === 'Escape') {
363
- setEditName(tab.name);
351
+ const handleRename = () => {
352
+ if (editName.trim() && editName !== tab.name) {
353
+ renameTab(tab.id, editName.trim());
354
+ }
364
355
  setIsEditing(false);
365
356
  setEditorRenameTab(false);
366
- }
367
- };
357
+ };
368
358
 
369
- return (
370
- <div
371
- className={`flex items-center px-3 py-2 border-r border-border cursor-pointer transition-colors ${
372
- isActive ? "bg-background text-foreground border-b-2 border-primary" : "bg-muted text-muted-foreground hover:bg-background hover:text-foreground"
373
- }`}
374
- onClick={() => !isEditing && onSelect(tab.id)}
375
- >
376
- {isEditing ? (
377
- <input
378
- ref={inputRef}
379
- type="text"
380
- value={editName}
381
- onChange={(e) => setEditName(e.target.value)}
382
- onBlur={handleRename}
383
- onKeyDown={handleKeyDown}
384
- onClick={(e) => e.stopPropagation()}
385
- className="text-sm bg-transparent border-none outline-none focus:ring-0 w-32 px-0"
386
- />
387
- ) : (
388
- <span className="text-sm truncate max-w-32">{tab.name}</span>
389
- )}
390
- {tab.isDirty && <span className="ml-1 text-destructive">●</span>}
391
- <button
392
- onClick={(e) => {
393
- e.stopPropagation();
394
- onClose(tab.id);
395
- }}
396
- className="ml-2 p-1 rounded hover:bg-destructive/20 hover:text-destructive"
359
+ const handleKeyDown = (e: React.KeyboardEvent) => {
360
+ if (e.key === 'Enter') {
361
+ handleRename();
362
+ } else if (e.key === 'Escape') {
363
+ setEditName(tab.name);
364
+ setIsEditing(false);
365
+ setEditorRenameTab(false);
366
+ }
367
+ };
368
+
369
+ return (
370
+ <div
371
+ className={`flex items-center px-3 py-2 border-r border-border cursor-pointer transition-colors ${isActive ? "bg-background text-foreground border-b-2 border-primary" : "bg-muted text-muted-foreground hover:bg-background hover:text-foreground"
372
+ }`}
373
+ onClick={() => !isEditing && onSelect(tab.id)}
397
374
  >
398
- <X className="h-3 w-3" />
399
- </button>
400
- </div>
401
- );
402
- };
375
+ {isEditing ? (
376
+ <input
377
+ ref={inputRef}
378
+ type="text"
379
+ value={editName}
380
+ onChange={(e) => setEditName(e.target.value)}
381
+ onBlur={handleRename}
382
+ onKeyDown={handleKeyDown}
383
+ onClick={(e) => e.stopPropagation()}
384
+ className="text-sm bg-transparent border-none outline-none focus:ring-0 w-32 px-0"
385
+ />
386
+ ) : (
387
+ <span className="text-sm truncate max-w-32">{tab.name}</span>
388
+ )}
389
+ {tab.isDirty && <span className="ml-1 text-destructive">●</span>}
390
+ <button
391
+ onClick={(e) => {
392
+ e.stopPropagation();
393
+ onClose(tab.id);
394
+ }}
395
+ className="ml-2 p-1 rounded hover:bg-destructive/20 hover:text-destructive"
396
+ >
397
+ <X className="h-3 w-3" />
398
+ </button>
399
+ </div>
400
+ );
401
+ };
403
402
  const onOpen = async (e: React.ChangeEvent<HTMLInputElement>) => {
404
403
  try {
405
404
  const file = e.target.files?.[0];
@@ -486,6 +485,7 @@ export function MonacoEditor({ setCode, code, }) {
486
485
  </div>
487
486
  )}
488
487
  </div>
488
+
489
489
  </div>
490
490
  );
491
491
  }