Skip to content

Commit

Permalink
copy current value
Browse files Browse the repository at this point in the history
  • Loading branch information
YousefED committed Oct 3, 2023
1 parent afa4b38 commit d11163c
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 4 deletions.
38 changes: 34 additions & 4 deletions packages/frame/src/runtime/executor/lib/autoForm/FormField.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ import DropdownMenu, {
DropdownItemRadio,
DropdownItemRadioGroup,
} from "@atlaskit/dropdown-menu";
import { Field } from "@atlaskit/form";
import { VscEllipsis } from "react-icons/vsc";
import { Field, HelperMessage } from "@atlaskit/form";
import { VscArrowCircleUp, VscEllipsis } from "react-icons/vsc";
import MonacoEdit from "./MonacoEdit";

export const FormField = observer(
Expand All @@ -28,6 +28,14 @@ export const FormField = observer(
const { inputObject, fieldKey } = props;
const currentValue = inputObject[fieldKey];

let currentStringified = "<complex object>";

try {
currentStringified = JSON.stringify(currentValue);
} catch (e) {
// noop
}

let currentParsedBinding: string | number | undefined;

if (props.value !== undefined) {
Expand Down Expand Up @@ -65,6 +73,10 @@ export const FormField = observer(
onChange={(e) => {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
const newVal = (e.target as any).value;
if (newVal === "") {
props.setValue(undefined);
return;
}
props.setValue(`export default ${JSON.stringify(newVal)};`);
}}
/>
Expand All @@ -79,8 +91,16 @@ export const FormField = observer(
value={currentParsedBinding || ""}
onChange={(e) => {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
const newVal = parseFloat((e.target as any).value);
props.setValue(`export default ${JSON.stringify(newVal)};`);
const newVal = (e.target as any).value;

if (newVal === "") {
props.setValue(undefined);
return;
}

props.setValue(
`export default ${JSON.stringify(parseFloat(newVal))};`,
);
}}
/>
);
Expand Down Expand Up @@ -144,6 +164,16 @@ export const FormField = observer(
</DropdownItemRadioGroup>
</DropdownMenu>
</div>
<HelperMessage>
<Button
onClick={() => {
props.setValue(`export default ${currentStringified}`);
}}
style={{ height: "auto" }}
appearance="subtle-link"
iconBefore={<VscArrowCircleUp size={18} />}></Button>
Current: {currentStringified}
</HelperMessage>
</Fragment>
)}
</Field>
Expand Down
4 changes: 4 additions & 0 deletions packages/frame/src/runtime/executor/lib/exports.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,10 @@ export default function getExposeGlobalVariables(
settings={editor.currentBlock.storage.settings || {}}
setSetting={(key: string, value: any) => {
runInAction(() => {
if (!editor.currentBlock.storage.settings) {
// TODO: might not be compatible with Yjs
editor.currentBlock.storage.settings = {};
}
editor.currentBlock.storage.settings[key] = value;
});
}}
Expand Down

0 comments on commit d11163c

Please sign in to comment.