Compare commits
5 Commits
fix/script
...
fix/update
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
58cde29fff | ||
|
|
a06fb06610 | ||
|
|
1f5a9731bb | ||
|
|
ef4f95ca3e | ||
|
|
fb9814ec76 |
@@ -24,13 +24,19 @@ import { saveAllFiles } from "../state/actions/saveFile";
|
|||||||
import { Tab, Tabs } from "./Tabs";
|
import { Tab, Tabs } from "./Tabs";
|
||||||
import { renameFile } from "../state/actions/createNewFile";
|
import { renameFile } from "../state/actions/createNewFile";
|
||||||
|
|
||||||
const validateWritability = (editor: monaco.editor.IStandaloneCodeEditor) => {
|
const checkWritable = (filename?: string): boolean => {
|
||||||
const currPath = editor.getModel()?.uri.path;
|
if (apiHeaderFiles.find(file => file === filename)) {
|
||||||
if (apiHeaderFiles.find(h => currPath?.endsWith(h))) {
|
return false;
|
||||||
editor.updateOptions({ readOnly: true });
|
|
||||||
} else {
|
|
||||||
editor.updateOptions({ readOnly: false });
|
|
||||||
}
|
}
|
||||||
|
return true;
|
||||||
|
};
|
||||||
|
|
||||||
|
const validateWritability = (
|
||||||
|
editor: monaco.editor.IStandaloneCodeEditor
|
||||||
|
) => {
|
||||||
|
const filename = editor.getModel()?.uri.path.split("/").pop();
|
||||||
|
const isWritable = checkWritable(filename);
|
||||||
|
editor.updateOptions({ readOnly: !isWritable });
|
||||||
};
|
};
|
||||||
|
|
||||||
let decorations: { [key: string]: string[] } = {};
|
let decorations: { [key: string]: string[] } = {};
|
||||||
@@ -138,7 +144,7 @@ const HooksEditor = () => {
|
|||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
{snap.files.map((file, index) => {
|
{snap.files.map((file, index) => {
|
||||||
return <Tab key={file.name} header={file.name} />;
|
return <Tab key={file.name} header={file.name} renameDisabled={!checkWritable(file.name)} />;
|
||||||
})}
|
})}
|
||||||
</Tabs>
|
</Tabs>
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -31,6 +31,7 @@ type Nullable<T> = T | null | undefined | false;
|
|||||||
interface TabProps {
|
interface TabProps {
|
||||||
header: string;
|
header: string;
|
||||||
children?: ReactNode;
|
children?: ReactNode;
|
||||||
|
renameDisabled?: boolean
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO customize messages shown
|
// TODO customize messages shown
|
||||||
@@ -98,16 +99,15 @@ export const Tabs = ({
|
|||||||
}, [tabname, setTabnameError]);
|
}, [tabname, setTabnameError]);
|
||||||
|
|
||||||
const validateTabname = useCallback(
|
const validateTabname = useCallback(
|
||||||
(tabname: string): { error?: string, result?: string } => {
|
(tabname: string): { error?: string; result?: string } => {
|
||||||
if (!tabname) {
|
if (!tabname) {
|
||||||
return { error: `Please enter ${label.toLocaleLowerCase()} name.` };
|
return { error: `Please enter ${label.toLocaleLowerCase()} name.` };
|
||||||
}
|
}
|
||||||
let ext =
|
let ext = (tabname.includes(".") && tabname.split(".").pop()) || "";
|
||||||
(tabname.includes(".") && tabname.split(".").pop()) || "";
|
|
||||||
|
|
||||||
if (!ext && defaultExtension) {
|
if (!ext && defaultExtension) {
|
||||||
ext = defaultExtension
|
ext = defaultExtension;
|
||||||
tabname = `${tabname}.${defaultExtension}`
|
tabname = `${tabname}.${defaultExtension}`;
|
||||||
}
|
}
|
||||||
if (tabs.find(tab => tab.header === tabname)) {
|
if (tabs.find(tab => tab.header === tabname)) {
|
||||||
return { error: `${capitalize(label)} name already exists.` };
|
return { error: `${capitalize(label)} name already exists.` };
|
||||||
@@ -153,16 +153,23 @@ export const Tabs = ({
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const { result: _tabname = tabname } = res
|
const { result: nwName = tabname } = res;
|
||||||
|
|
||||||
setRenamingTab(null);
|
setRenamingTab(null);
|
||||||
setTabname("");
|
setTabname("");
|
||||||
|
|
||||||
const oldName = tabs[renamingTab]?.header;
|
const oldName = tabs[renamingTab]?.header;
|
||||||
onRenameTab?.(renamingTab, _tabname, oldName);
|
onRenameTab?.(renamingTab, nwName, oldName);
|
||||||
|
|
||||||
handleActiveChange(renamingTab);
|
handleActiveChange(renamingTab, nwName);
|
||||||
}, [handleActiveChange, onRenameTab, renamingTab, tabname, tabs, validateTabname]);
|
}, [
|
||||||
|
handleActiveChange,
|
||||||
|
onRenameTab,
|
||||||
|
renamingTab,
|
||||||
|
tabname,
|
||||||
|
tabs,
|
||||||
|
validateTabname,
|
||||||
|
]);
|
||||||
|
|
||||||
const handleCreateTab = useCallback(() => {
|
const handleCreateTab = useCallback(() => {
|
||||||
const res = validateTabname(tabname);
|
const res = validateTabname(tabname);
|
||||||
@@ -170,7 +177,7 @@ export const Tabs = ({
|
|||||||
setTabnameError(`Error: ${res.error}`);
|
setTabnameError(`Error: ${res.error}`);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
const { result: _tabname = tabname } = res
|
const { result: _tabname = tabname } = res;
|
||||||
|
|
||||||
setIsNewtabDialogOpen(false);
|
setIsNewtabDialogOpen(false);
|
||||||
setTabname("");
|
setTabname("");
|
||||||
@@ -178,17 +185,22 @@ export const Tabs = ({
|
|||||||
onCreateNewTab?.(_tabname);
|
onCreateNewTab?.(_tabname);
|
||||||
|
|
||||||
handleActiveChange(tabs.length, _tabname);
|
handleActiveChange(tabs.length, _tabname);
|
||||||
}, [validateTabname, tabname, onCreateNewTab, handleActiveChange, tabs.length]);
|
}, [
|
||||||
|
validateTabname,
|
||||||
|
tabname,
|
||||||
|
onCreateNewTab,
|
||||||
|
handleActiveChange,
|
||||||
|
tabs.length,
|
||||||
|
]);
|
||||||
|
|
||||||
const handleCloseTab = useCallback(
|
const handleCloseTab = useCallback(
|
||||||
(idx: number) => {
|
(idx: number) => {
|
||||||
if (idx <= active && active !== 0) {
|
|
||||||
setActive(active - 1);
|
|
||||||
}
|
|
||||||
|
|
||||||
onCloseTab?.(idx, tabs[idx].header);
|
onCloseTab?.(idx, tabs[idx].header);
|
||||||
|
|
||||||
handleActiveChange(idx, tabs[idx].header);
|
if (idx <= active && active !== 0) {
|
||||||
|
const nwActive = active - 1
|
||||||
|
handleActiveChange(nwActive, tabs[nwActive].header);
|
||||||
|
}
|
||||||
},
|
},
|
||||||
[active, handleActiveChange, onCloseTab, tabs]
|
[active, handleActiveChange, onCloseTab, tabs]
|
||||||
);
|
);
|
||||||
@@ -200,13 +212,16 @@ export const Tabs = ({
|
|||||||
key: "close",
|
key: "close",
|
||||||
onSelect: () => handleCloseTab(idx),
|
onSelect: () => handleCloseTab(idx),
|
||||||
};
|
};
|
||||||
const renameOption = (idx: number): Nullable<ContentMenuOption> =>
|
const renameOption = (idx: number, tab: TabProps): Nullable<ContentMenuOption> => {
|
||||||
onRenameTab && {
|
return (
|
||||||
type: "text",
|
onRenameTab && !tab.renameDisabled && {
|
||||||
label: "Rename",
|
type: "text",
|
||||||
key: "rename",
|
label: "Rename",
|
||||||
onSelect: () => setRenamingTab(idx),
|
key: "rename",
|
||||||
};
|
onSelect: () => setRenamingTab(idx),
|
||||||
|
}
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
@@ -225,7 +240,7 @@ export const Tabs = ({
|
|||||||
<ContextMenu
|
<ContextMenu
|
||||||
key={tab.header}
|
key={tab.header}
|
||||||
options={
|
options={
|
||||||
[closeOption(idx), renameOption(idx)].filter(
|
[closeOption(idx), renameOption(idx, tab)].filter(
|
||||||
Boolean
|
Boolean
|
||||||
) as ContentMenuOption[]
|
) as ContentMenuOption[]
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -36,7 +36,7 @@
|
|||||||
"lodash.xor": "^4.5.0",
|
"lodash.xor": "^4.5.0",
|
||||||
"monaco-editor": "^0.33.0",
|
"monaco-editor": "^0.33.0",
|
||||||
"next": "^12.0.4",
|
"next": "^12.0.4",
|
||||||
"next-auth": "^4.10.1",
|
"next-auth": "^4.10.3",
|
||||||
"next-plausible": "^3.2.0",
|
"next-plausible": "^3.2.0",
|
||||||
"next-themes": "^0.1.1",
|
"next-themes": "^0.1.1",
|
||||||
"normalize-url": "^7.0.2",
|
"normalize-url": "^7.0.2",
|
||||||
@@ -80,4 +80,4 @@
|
|||||||
"resolutions": {
|
"resolutions": {
|
||||||
"ripple-binary-codec": "=1.4.2"
|
"ripple-binary-codec": "=1.4.2"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2953,10 +2953,10 @@ natural-compare@^1.4.0:
|
|||||||
resolved "https://registry.npmjs.org/natural-compare/-/natural-compare-1.4.0.tgz"
|
resolved "https://registry.npmjs.org/natural-compare/-/natural-compare-1.4.0.tgz"
|
||||||
integrity sha1-Sr6/7tdUHywnrPspvbvRXI1bpPc=
|
integrity sha1-Sr6/7tdUHywnrPspvbvRXI1bpPc=
|
||||||
|
|
||||||
next-auth@^4.10.1:
|
next-auth@^4.10.3:
|
||||||
version "4.10.1"
|
version "4.10.3"
|
||||||
resolved "https://registry.yarnpkg.com/next-auth/-/next-auth-4.10.1.tgz#33b29265d12287bb2f6d267c8d415a407c27f0e9"
|
resolved "https://registry.yarnpkg.com/next-auth/-/next-auth-4.10.3.tgz#0a952dd5004fd2ac2ba414c990922cf9b33951a3"
|
||||||
integrity sha512-F00vtwBdyMIIJ8IORHOAOHjVGTDEhhm9+HpB2BQ8r40WtGxqToWWLN7Z+2ZW/z2RFlo3zhcuAtUCPUzVJxtZwQ==
|
integrity sha512-7zc4aXYc/EEln7Pkcsn21V1IevaTZsMLJwapfbnKA4+JY0+jFzWbt5p/ljugesGIrN4VOZhpZIw50EaFZyghJQ==
|
||||||
dependencies:
|
dependencies:
|
||||||
"@babel/runtime" "^7.16.3"
|
"@babel/runtime" "^7.16.3"
|
||||||
"@panva/hkdf" "^1.0.1"
|
"@panva/hkdf" "^1.0.1"
|
||||||
|
|||||||
Reference in New Issue
Block a user