-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #35 from Nounspace/hy_port_to_fidget_wrappers
feat: port Layout PR to use frame wrappers
- Loading branch information
Showing
19 changed files
with
505 additions
and
354 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
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,59 @@ | ||
export interface FidgetSettings {} | ||
|
||
export type FidgetConfig<S extends FidgetSettings = FidgetSettings> = { | ||
editable: boolean; | ||
settings: S; | ||
}; | ||
|
||
export type FidgetFieldConfig = { | ||
readonly fieldName: string; | ||
readonly validator?: (value) => boolean; | ||
// This should be changed to a set of allowed input selectors | ||
readonly inputSelector: React.FC; | ||
readonly default?: any; | ||
readonly required: boolean; | ||
}; | ||
|
||
export type FidgetEditConfig = { | ||
fields: FidgetFieldConfig[]; | ||
size: { | ||
minHeight: NumericRange<1,36>; | ||
maxHeight: NumericRange<1,36>; | ||
minWidth: NumericRange<1,36>; | ||
maxWidth: NumericRange<1,36>; | ||
} | ||
}; | ||
|
||
export interface FidgetDetails<S extends FidgetSettings = FidgetSettings> { | ||
editConfig: FidgetEditConfig; | ||
instanceConfig: FidgetConfig<S>; | ||
id: string; | ||
} | ||
|
||
export interface LayoutFidgetConfig {} | ||
|
||
export interface LayoutFidgetDetails { | ||
layoutFidget: string; | ||
layoutConfig: LayoutFidgetConfig; | ||
} | ||
|
||
export interface FidgetModule<P = unknown> { | ||
fidget: React.FC<P>; | ||
editConfig: FidgetEditConfig; | ||
} | ||
|
||
interface LayoutFigetProps { | ||
layoutConfig: LayoutFidgetConfig; | ||
fidgets: { | ||
[key: string]: ReactNode; | ||
}; | ||
isEditable: boolean; | ||
} | ||
|
||
const LayoutFidgetDefaultProps = { | ||
fidgets: object, | ||
layoutConfig: object, | ||
isEditable: false, | ||
} | ||
|
||
export interface LayoutFiget<P extends LayoutFigetProps = LayoutFidgetDefaultProps> extends React.FC<P> {} |
This file was deleted.
Oops, something went wrong.
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,3 @@ | ||
export default function randDivId(): string { | ||
return Math.random().toString(36).replace(/[^a-z]+/g, '').substring(2, 10); | ||
} |
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,79 @@ | ||
import { FidgetConfig, FidgetSettings, LayoutFidgetDetails } from '@/common/fidgets'; | ||
import React from 'react'; | ||
import { CompleteFidgets, LayoutFidgets } from '@/fidgets'; | ||
import { mapValues } from 'lodash'; | ||
import { FidgetWrapper } from '@/common/fidgets/FidgetWrapper'; | ||
|
||
export type SpaceConfig = { | ||
fidgetConfigs: { | ||
[key: string]: { | ||
instanceConfig: FidgetConfig<FidgetSettings>; | ||
fidgetName: string; | ||
id: string; | ||
}; | ||
} | ||
layoutID: string; | ||
layoutDetails: LayoutFidgetDetails; | ||
} | ||
|
||
type SpaceArgs = { | ||
config: SpaceConfig; | ||
isEditable: boolean; | ||
saveConfig: (config: SpaceConfig) => Promise<boolean>; | ||
} | ||
|
||
export default function Space({ config, isEditable, saveConfig }: SpaceArgs){ | ||
const LayoutFidget = LayoutFidgets[config.layoutDetails.layoutFidget]; | ||
const fidgets = mapValues(config.fidgetConfigs, (details, key) => FidgetWrapper({ | ||
fidget: CompleteFidgets[details.fidgetName].fidget, | ||
config: { | ||
id: details.id, | ||
instanceConfig: { | ||
editable: isEditable, | ||
settings: details.instanceConfig.settings, | ||
}, | ||
editConfig: CompleteFidgets[details.fidgetName].editConfig, | ||
}, | ||
saveConfig: async (newInstanceConfig: FidgetConfig<FidgetSettings>) => { | ||
return await saveConfig({ | ||
layoutID: config.layoutID, | ||
layoutDetails: config.layoutDetails, | ||
fidgetConfigs: { | ||
...config.fidgetConfigs, | ||
[key]: { | ||
instanceConfig: newInstanceConfig, | ||
id: details.id, | ||
fidgetName: details.fidgetName, | ||
}, | ||
}, | ||
}) | ||
}, | ||
})); | ||
|
||
function saveLayout(layout) { | ||
return saveConfig({ | ||
layoutID: config.layoutID, | ||
fidgetConfigs: config.fidgetConfigs, | ||
layoutDetails: { | ||
...config.layoutDetails, | ||
layoutConfig: { | ||
...config.layoutDetails.layoutConfig, | ||
layout: layout, | ||
}, | ||
}, | ||
}); | ||
} | ||
|
||
console.log(fidgets); | ||
|
||
return ( | ||
<LayoutFidget | ||
layoutConfig={{ | ||
...config.layoutDetails.layoutConfig, | ||
onLayoutChange: saveLayout, | ||
}} | ||
fidgets={fidgets} | ||
isEditable={isEditable} | ||
/> | ||
); | ||
} |
Oops, something went wrong.