Skip to content

Commit

Permalink
Merge pull request alibaba#866 from alibaba/feat/generator-preview
Browse files Browse the repository at this point in the history
feat(generator): preview props
  • Loading branch information
siyi98 authored Aug 7, 2022
2 parents 6af45bc + 0582087 commit c926f92
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 7 deletions.
1 change: 1 addition & 0 deletions docs/generator/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ export default Demo;
| transformer | schema 双向转换 | `object` | `{ from, to, fromSetting, toSetting }` |
| extraButtons | 操作栏按钮 | `array` | `extraButton[]` |
| controlButtons | 选中项操作按钮 | `array` | `controlButton[]` |
| preview | 预览态控制 | `boolean` | - |
| settings | 左右侧栏配置 | `array` | [`defaultSettings`](https://github.com/alibaba/form-render/blob/master/tools/schema-generator/src/settings/index.js) |
| commonSettings | 通用配置 | `object` | [`defaultCommonSettings`](https://github.com/alibaba/form-render/blob/master/tools/schema-generator/src/settings/index.js) |
| globalSettings | 全局配置 | `object` | [`defaultGlobalSettings`](https://github.com/alibaba/form-render/blob/master/tools/schema-generator/src/settings/index.js) |
Expand Down
3 changes: 2 additions & 1 deletion tools/schema-generator/src/Provider.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ function Provider(props, ref) {
transformer: _transformer,
extraButtons,
controlButtons,
preview: _preview,
hideId,
getId = defaultGetId,
settings,
Expand Down Expand Up @@ -108,7 +109,7 @@ function Provider(props, ref) {
const _widgets = { ...defaultWidgets, ...widgets, list };

const rootState = {
preview,
preview: _preview ?? preview,
mapping: _mapping,
widgets: _widgets,
selected,
Expand Down
6 changes: 2 additions & 4 deletions tools/schema-generator/src/components/Canvas/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,18 +18,17 @@ const Canvas = ({ onSelect }) => {
userProps,
displaySchema,
displaySchemaString,
preview,
selected,
flatten,
onChange,
onSchemaChange,
} = useStore();
const [local, setState] = useSet({
preview: false,
showModal: false,
showModal2: false,
schemaForImport: '',
});
const { preview } = local;

const { transformer, extraButtons = [] } = userProps;

Expand Down Expand Up @@ -101,8 +100,7 @@ const Canvas = ({ onSelect }) => {
<Button
className="mr2 mb1"
onClick={() => {
setState({ preview: !preview });
setGlobal({ selected: '#' });
setGlobal({ selected: '#', preview: !preview });
}}
>
{getDefaultBtnText(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,12 @@ import { useGlobal, useStore } from '../../utils/hooks';
export default function GlobalSettings({ widgets }) {
const form = useForm();
const [innerUpdate, setInnerUpdate] = useState(false);
const { widgets: globalWidgets, frProps, userProps = {}, mapping } = useStore();
const {
widgets: globalWidgets,
frProps,
userProps = {},
mapping,
} = useStore();
const setGlobal = useGlobal();
const globalSettings = userProps.globalSettings || defaultGlobalSettings;

Expand Down
4 changes: 3 additions & 1 deletion tools/schema-generator/src/components/Settings/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,9 @@ export default function Settings({ widgets }) {
}
}, [selected]);

const globalSettingHide = userProps.globalSettings === null || (userProps.globalSettings && !Object.keys(userProps.globalSettings).length);
const globalSettingHide =
userProps.globalSettings === null ||
(userProps.globalSettings && !Object.keys(userProps.globalSettings).length);

return showRight ? (
<div className="right-layout relative pl2">
Expand Down
2 changes: 2 additions & 0 deletions tools/schema-generator/src/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,8 @@ export interface FRGeneratorProps {
extraButtons?: (ExtraButton | boolean | string)[];
/** 选中项操作按钮 */
controlButtons?: (ControlButton | boolean | Function)[];
/** 预览态控制 */
preview?: boolean;
/** 左右侧栏配置 */
settings?: Setting[];
/** 通用配置 */
Expand Down

0 comments on commit c926f92

Please sign in to comment.