Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
124 changed files
with
3,898 additions
and
350 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
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
23 changes: 23 additions & 0 deletions
23
packages/admin/src/components/bindingFacade/upload/fileHandler/createEntityConnector.ts
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,23 @@ | ||
import { BindingError, EntityAccessor, Environment, QueryLanguage } from '@contember/react-binding' | ||
import { EntityConnectorFactory } from '../internalComponents/hooks/useConnectSelectedEntities' | ||
|
||
export const createEntityConnectorFactory = (env: Environment, ...baseEntity: (string | undefined)[]): EntityConnectorFactory => { | ||
if (!baseEntity[baseEntity.length - 1]) { | ||
throw new BindingError('Cannot use "fileSelectionComponent" when "baseField" prop is not set. For more information, please consult the documentation.') | ||
} | ||
const path = baseEntity.filter( | ||
(it): it is string => it !== undefined) | ||
.map(it => QueryLanguage.desugarRelativeSingleEntity(it, env)) | ||
.flatMap(it => it.hasOneRelationPath) | ||
|
||
return selected => { | ||
const connector = (parent: EntityAccessor) => { | ||
const parentEntity = parent.getRelativeSingleEntity({ | ||
hasOneRelationPath: path.slice(0, -1), | ||
}) | ||
parentEntity.connectEntityAtField(path[path.length - 1].field, selected) | ||
} | ||
connector.entity = selected | ||
return connector | ||
} | ||
} |
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
53 changes: 53 additions & 0 deletions
53
packages/interface/src/components/binding/DisconnectEntityTrigger.tsx
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,53 @@ | ||
import { ComponentType, ReactNode, useCallback } from 'react' | ||
import { Slot } from '@radix-ui/react-slot' | ||
import { BindingError, EntityListAccessor, ErrorPersistResult, SuccessfulPersistResult, SugaredRelativeSingleEntity, useEntity, useMutationState, usePersist } from '@contember/react-binding' | ||
|
||
|
||
const SlotButton = Slot as ComponentType<React.ButtonHTMLAttributes<HTMLButtonElement>> | ||
|
||
export interface DisconnectEntityTriggerProps { | ||
immediatePersist?: true | ||
children: ReactNode | ||
onPersistSuccess?: (result: SuccessfulPersistResult) => void | ||
onPersistError?: (result: ErrorPersistResult) => void | ||
field?: SugaredRelativeSingleEntity['field'] | ||
} | ||
|
||
export const DisconnectEntityTrigger = ({ immediatePersist, onPersistError, onPersistSuccess, field, ...props }: DisconnectEntityTriggerProps) => { | ||
const entity = useEntity() | ||
const triggerPersist = usePersist() | ||
const isMutating = useMutationState() | ||
const onClick = useCallback(() => { | ||
if (field) { | ||
entity.disconnectEntityAtField({ field }) | ||
} else { | ||
const parent = entity.getParent() | ||
if (!parent) { | ||
throw new BindingError('Cannot disconnect root entity') | ||
} | ||
if (parent instanceof EntityListAccessor) { | ||
parent.disconnectEntity(entity) | ||
} else { | ||
const subTreeNode = entity.environment.getSubTreeNode() | ||
if (subTreeNode.type !== 'entity') { | ||
throw new BindingError('Cannot disconnect root entity') | ||
} | ||
parent.disconnectEntityAtField({ field: subTreeNode.field.name }) | ||
} | ||
} | ||
|
||
if (immediatePersist) { | ||
triggerPersist() | ||
.then(onPersistSuccess) | ||
.catch(onPersistError) | ||
} | ||
}, [field, immediatePersist, entity, triggerPersist, onPersistSuccess, onPersistError]) | ||
|
||
return ( | ||
<SlotButton | ||
onClick={onClick} | ||
disabled={isMutating ? true : undefined} | ||
{...props} | ||
/> | ||
) | ||
} |
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,5 +1,6 @@ | ||
export * from './ClearFieldTrigger' | ||
export * from './DeleteEntityTrigger' | ||
export * from './DisconnectEntityTrigger' | ||
export * from './PersistTrigger' | ||
export * from './EntityBeforePersist' | ||
export * from './RedirectOnPersist' |
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 |
---|---|---|
@@ -1,3 +1,7 @@ | ||
export default (<> | ||
Hello! | ||
</>) | ||
import * as React from 'react' | ||
|
||
export default () => { | ||
debugger | ||
const foo = React.useMemo(() => 1, []) | ||
return <>Hello!</> | ||
} |
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,80 @@ | ||
import { EntitySubTree } from '@contember/react-binding' | ||
import * as React from 'react' | ||
import { Binding, PersistButton } from '../../lib/components/binding' | ||
import { Slots } from '../../lib/components/slots' | ||
import { ImageField } from '../../lib/components/form' | ||
|
||
|
||
export const image = () => <> | ||
|
||
<Binding> | ||
<Slots.Actions><PersistButton /></Slots.Actions> | ||
<EntitySubTree entity="UploadRoot(unique = unique)" setOnCreate="(unique = unique)"> | ||
<ImageField | ||
baseField="image" | ||
urlField="url" | ||
widthField="width" | ||
heightField="height" | ||
fileNameField="meta.fileName" | ||
fileSizeField="meta.fileSize" | ||
fileTypeField="meta.fileType" | ||
lastModifiedField="meta.lastModified" | ||
label="Image file" | ||
description="Some description of the image file." | ||
/> | ||
</EntitySubTree> | ||
</Binding> | ||
</> | ||
|
||
|
||
export const imageList = () => <> | ||
|
||
{/*<MultiUploader field={'multipleBasicImageList'}*/} | ||
{/* sortableBy={'order'}*/} | ||
{/* fileHandler={new SingleKindFileHandler(getStockImageFileKind({*/} | ||
{/* baseField: 'image',*/} | ||
{/* urlField: 'url',*/} | ||
{/* uploader: s3FileUploader,*/} | ||
{/* }))}>*/} | ||
{/* {Dropzone}*/} | ||
{/* <UploaderSortable>*/} | ||
|
||
{/* <div style={{ display: 'flex' }}>*/} | ||
{/* <UploaderSortableEachItem>*/} | ||
{/* <div style={{ width: '25%' }}>*/} | ||
{/* <div style={{ position: 'relative' }}>*/} | ||
{/* <UploaderSortableDropIndicator position={'before'}>*/} | ||
{/* {dropIndicatorEl}*/} | ||
{/* </UploaderSortableDropIndicator>*/} | ||
{/* </div>*/} | ||
{/* <UploaderSortableItemNode>*/} | ||
{/* <Box>*/} | ||
{/* <UploaderSortableItemActivator>*/} | ||
{/* <div>move</div>*/} | ||
{/* </UploaderSortableItemActivator>*/} | ||
|
||
{/* <UploaderFileEntity>*/} | ||
{/* <Field field={'url'} />*/} | ||
{/* /!*{FilePreview}*!/*/} | ||
{/* </UploaderFileEntity>*/} | ||
{/* /!*{UploadingState}*!/*/} | ||
{/* </Box>*/} | ||
{/* </UploaderSortableItemNode>*/} | ||
{/* <div style={{ position: 'relative' }}>*/} | ||
{/* <UploaderSortableDropIndicator position={'after'}>*/} | ||
{/* {dropIndicatorEl}*/} | ||
{/* </UploaderSortableDropIndicator>*/} | ||
{/* </div>*/} | ||
{/* </div>*/} | ||
{/* </UploaderSortableEachItem>*/} | ||
{/* </div>*/} | ||
{/* <UploaderSortableDragOverlay>*/} | ||
{/* <Box>*/} | ||
{/* <UploaderFileEntity>*/} | ||
{/* Dragging file <Field field={'url'} />*/} | ||
{/* </UploaderFileEntity>*/} | ||
{/* </Box>*/} | ||
{/* </UploaderSortableDragOverlay>*/} | ||
{/* </UploaderSortable>*/} | ||
{/*</MultiUploader>*/} | ||
</> |
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
Oops, something went wrong.