@cere/cere-design-system 0.0.30 → 0.0.31

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/dist/index.d.mts CHANGED
@@ -2747,6 +2747,8 @@ interface CodeEditorWorkspaceProps extends Pick<UseCodeEditorWorkspaceOptions, '
2747
2747
  statusBarItems?: CodeEditorStatusBarItem[];
2748
2748
  /** Expose the workspace instance to the parent via ref-like callback */
2749
2749
  onWorkspaceReady?: (workspace: UseCodeEditorWorkspaceReturn) => void;
2750
+ /** Called when the user presses Ctrl+S / Cmd+S. Receives all dirty files. */
2751
+ onSave?: (dirtyFiles: CodeEditorFile[]) => void;
2750
2752
  }
2751
2753
  /**
2752
2754
  * Convenience composed workspace that combines `CodeEditorFileTree`,
package/dist/index.d.ts CHANGED
@@ -2747,6 +2747,8 @@ interface CodeEditorWorkspaceProps extends Pick<UseCodeEditorWorkspaceOptions, '
2747
2747
  statusBarItems?: CodeEditorStatusBarItem[];
2748
2748
  /** Expose the workspace instance to the parent via ref-like callback */
2749
2749
  onWorkspaceReady?: (workspace: UseCodeEditorWorkspaceReturn) => void;
2750
+ /** Called when the user presses Ctrl+S / Cmd+S. Receives all dirty files. */
2751
+ onSave?: (dirtyFiles: CodeEditorFile[]) => void;
2750
2752
  }
2751
2753
  /**
2752
2754
  * Convenience composed workspace that combines `CodeEditorFileTree`,
package/dist/index.js CHANGED
@@ -9865,7 +9865,8 @@ var CodeEditorWorkspace = ({
9865
9865
  gitInfo,
9866
9866
  showStatusBar = true,
9867
9867
  statusBarItems,
9868
- onWorkspaceReady
9868
+ onWorkspaceReady,
9869
+ onSave
9869
9870
  }) => {
9870
9871
  const workspace = useCodeEditorWorkspace({
9871
9872
  files,
@@ -9876,6 +9877,27 @@ var CodeEditorWorkspace = ({
9876
9877
  import_react40.default.useEffect(() => {
9877
9878
  onWorkspaceReady?.(workspace);
9878
9879
  }, []);
9880
+ import_react40.default.useEffect(() => {
9881
+ if (!onSave) return;
9882
+ const handleKeyDown = (e) => {
9883
+ if ((e.ctrlKey || e.metaKey) && e.key === "s") {
9884
+ e.preventDefault();
9885
+ const dirtyFiles = workspace.openTabs.filter((t) => t.isDirty).map((t) => {
9886
+ const file = files.find((f) => f.path === t.path);
9887
+ if (!file) return null;
9888
+ return {
9889
+ ...file,
9890
+ value: workspace.getFileContent(file.path) ?? file.value
9891
+ };
9892
+ }).filter((f) => f !== null);
9893
+ if (dirtyFiles.length > 0) {
9894
+ onSave(dirtyFiles);
9895
+ }
9896
+ }
9897
+ };
9898
+ window.addEventListener("keydown", handleKeyDown);
9899
+ return () => window.removeEventListener("keydown", handleKeyDown);
9900
+ }, [onSave, workspace, files]);
9879
9901
  const hasFileTree = showFileTree && fileTree && fileTree.length > 0;
9880
9902
  const tabsProps = {
9881
9903
  tabs: workspace.openTabs,