-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore(designable): add save service to playground
- Loading branch information
Showing
10 changed files
with
152 additions
and
74 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export * from './schema' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import { Engine } from '@designable/core' | ||
import { transformToSchema, transformToTreeNode } from '@designable/formily' | ||
import { message } from 'antd' | ||
|
||
export const saveSchema = (designer: Engine) => { | ||
localStorage.setItem( | ||
'formily-schema', | ||
JSON.stringify( | ||
transformToSchema(designer.getCurrentTree(), { | ||
designableFieldName: 'DesignableField', | ||
designableFormName: 'Root', | ||
}) | ||
) | ||
) | ||
message.success('Save Success') | ||
} | ||
|
||
export const loadInitialSchema = (designer: Engine) => { | ||
try { | ||
designer.setCurrentTree( | ||
transformToTreeNode(JSON.parse(localStorage.getItem('formily-schema')), { | ||
designableFieldName: 'DesignableField', | ||
designableFormName: 'Root', | ||
}) | ||
) | ||
} catch {} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,32 +1,48 @@ | ||
import React from 'react' | ||
import React, { useEffect } from 'react' | ||
import { Space, Button, Radio } from 'antd' | ||
import { GithubOutlined } from '@ant-design/icons' | ||
import { TextWidget } from '@designable/react' | ||
import { useDesigner, TextWidget } from '@designable/react' | ||
import { GlobalRegistry } from '@designable/core' | ||
import { observer } from '@formily/react' | ||
import { loadInitialSchema, saveSchema } from '../service' | ||
|
||
export const ActionsWidget = observer(() => ( | ||
<Space style={{ marginRight: 10 }}> | ||
<Radio.Group | ||
value={GlobalRegistry.getDesignerLanguage()} | ||
optionType="button" | ||
options={[ | ||
{ label: 'English', value: 'en-us' }, | ||
{ label: '简体中文', value: 'zh-cn' }, | ||
]} | ||
onChange={(e) => { | ||
GlobalRegistry.setDesignerLanguage(e.target.value) | ||
}} | ||
/> | ||
<Button href="https://github.com/alibaba/formily" target="_blank"> | ||
<GithubOutlined /> | ||
Github | ||
</Button> | ||
<Button> | ||
<TextWidget>Save</TextWidget> | ||
</Button> | ||
<Button type="primary"> | ||
<TextWidget>Publish</TextWidget> | ||
</Button> | ||
</Space> | ||
)) | ||
export const ActionsWidget = observer(() => { | ||
const designer = useDesigner() | ||
useEffect(() => { | ||
loadInitialSchema(designer) | ||
}, []) | ||
return ( | ||
<Space style={{ marginRight: 10 }}> | ||
<Radio.Group | ||
value={GlobalRegistry.getDesignerLanguage()} | ||
optionType="button" | ||
options={[ | ||
{ label: 'English', value: 'en-us' }, | ||
{ label: '简体中文', value: 'zh-cn' }, | ||
]} | ||
onChange={(e) => { | ||
GlobalRegistry.setDesignerLanguage(e.target.value) | ||
}} | ||
/> | ||
<Button href="https://github.com/alibaba/formily" target="_blank"> | ||
<GithubOutlined /> | ||
Github | ||
</Button> | ||
<Button | ||
onClick={() => { | ||
saveSchema(designer) | ||
}} | ||
> | ||
<TextWidget>Save</TextWidget> | ||
</Button> | ||
<Button | ||
type="primary" | ||
onClick={() => { | ||
saveSchema(designer) | ||
}} | ||
> | ||
<TextWidget>Publish</TextWidget> | ||
</Button> | ||
</Space> | ||
) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters