@contember/create 2.0.0-alpha.8 → 2.0.0-beta.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/development/run.cjs +0 -2
- package/dist/development/run.cjs.map +1 -1
- package/dist/development/run.js +0 -2
- package/dist/development/run.js.map +1 -1
- package/dist/development/src/commands/WorkspaceCreateCommand.cjs.map +1 -1
- package/dist/development/src/commands/WorkspaceCreateCommand.js.map +1 -1
- package/dist/development/src/lib/FileSystem.cjs.map +1 -1
- package/dist/development/src/lib/FileSystem.js.map +1 -1
- package/dist/development/src/lib/TemplateInstaller.cjs +1 -8
- package/dist/development/src/lib/TemplateInstaller.cjs.map +1 -1
- package/dist/development/src/lib/TemplateInstaller.js +2 -9
- package/dist/development/src/lib/TemplateInstaller.js.map +1 -1
- package/dist/development/src/lib/version.cjs.map +1 -1
- package/dist/development/src/paths.cjs +3 -1
- package/dist/development/src/paths.cjs.map +1 -1
- package/dist/development/src/paths.js +4 -2
- package/dist/development/src/paths.js.map +1 -1
- package/dist/production/run.cjs +0 -2
- package/dist/production/run.cjs.map +1 -1
- package/dist/production/run.js +0 -2
- package/dist/production/run.js.map +1 -1
- package/dist/production/src/commands/WorkspaceCreateCommand.cjs.map +1 -1
- package/dist/production/src/commands/WorkspaceCreateCommand.js.map +1 -1
- package/dist/production/src/lib/FileSystem.cjs.map +1 -1
- package/dist/production/src/lib/FileSystem.js.map +1 -1
- package/dist/production/src/lib/TemplateInstaller.cjs +1 -8
- package/dist/production/src/lib/TemplateInstaller.cjs.map +1 -1
- package/dist/production/src/lib/TemplateInstaller.js +2 -9
- package/dist/production/src/lib/TemplateInstaller.js.map +1 -1
- package/dist/production/src/lib/version.cjs.map +1 -1
- package/dist/production/src/paths.cjs +3 -1
- package/dist/production/src/paths.cjs.map +1 -1
- package/dist/production/src/paths.js +4 -2
- package/dist/production/src/paths.js.map +1 -1
- package/dist/types/lib/TemplateInstaller.d.ts +1 -3
- package/dist/types/lib/TemplateInstaller.d.ts.map +1 -1
- package/dist/types/paths.d.ts.map +1 -1
- package/dist/types/tsconfig.tsbuildinfo +1 -1
- package/package.json +7 -31
- package/resources/templates/template-workspace/.github/scripts/setup-actions-variables.sh +36 -0
- package/resources/templates/template-workspace/.github/workflows/deploy.yaml +23 -0
- package/resources/templates/template-workspace/admin/lib/binding/binding.tsx +12 -2
- package/resources/templates/template-workspace/admin/lib/binding/delete.tsx +34 -23
- package/resources/templates/template-workspace/admin/lib/binding/hooks.tsx +5 -6
- package/resources/templates/template-workspace/admin/lib/binding/identity.tsx +34 -3
- package/resources/templates/template-workspace/admin/lib/binding/navigation-guard-dialog.tsx +39 -0
- package/resources/templates/template-workspace/admin/lib/binding/persist.tsx +10 -60
- package/resources/templates/template-workspace/admin/lib/block-repeater/block-repeater.tsx +109 -39
- package/resources/templates/template-workspace/admin/lib/buttons/link-back-button.tsx +1 -1
- package/resources/templates/template-workspace/admin/lib/datagrid/cells.tsx +90 -10
- package/resources/templates/template-workspace/admin/lib/datagrid/column-header.tsx +12 -4
- package/resources/templates/template-workspace/admin/lib/datagrid/column-leaf.tsx +21 -0
- package/resources/templates/template-workspace/admin/lib/datagrid/columns.tsx +367 -36
- package/resources/templates/template-workspace/admin/lib/datagrid/elements.tsx +6 -0
- package/resources/templates/template-workspace/admin/lib/datagrid/export.tsx +9 -0
- package/resources/templates/template-workspace/admin/lib/datagrid/filters/boolean.tsx +22 -5
- package/resources/templates/template-workspace/admin/lib/datagrid/filters/common.tsx +3 -0
- package/resources/templates/template-workspace/admin/lib/datagrid/filters/date.tsx +25 -2
- package/resources/templates/template-workspace/admin/lib/datagrid/filters/defined.tsx +103 -0
- package/resources/templates/template-workspace/admin/lib/datagrid/filters/enum.tsx +83 -27
- package/resources/templates/template-workspace/admin/lib/datagrid/filters/index.ts +1 -1
- package/resources/templates/template-workspace/admin/lib/datagrid/filters/mobile.tsx +0 -1
- package/resources/templates/template-workspace/admin/lib/datagrid/filters/number.tsx +21 -5
- package/resources/templates/template-workspace/admin/lib/datagrid/filters/relation.tsx +170 -43
- package/resources/templates/template-workspace/admin/lib/datagrid/filters/text.tsx +48 -5
- package/resources/templates/template-workspace/admin/lib/datagrid/grid.tsx +97 -25
- package/resources/templates/template-workspace/admin/lib/datagrid/index.ts +30 -4
- package/resources/templates/template-workspace/admin/lib/datagrid/labels.tsx +31 -0
- package/resources/templates/template-workspace/admin/lib/datagrid/layout-switcher.tsx +3 -0
- package/resources/templates/template-workspace/admin/lib/datagrid/loader.tsx +44 -2
- package/resources/templates/template-workspace/admin/lib/datagrid/pagination.tsx +8 -0
- package/resources/templates/template-workspace/admin/lib/datagrid/table.tsx +15 -1
- package/resources/templates/template-workspace/admin/lib/datagrid/tiles.tsx +13 -0
- package/resources/templates/template-workspace/admin/lib/datagrid/toolbar.tsx +27 -2
- package/resources/templates/template-workspace/admin/lib/dict.ts +54 -5
- package/resources/templates/template-workspace/admin/lib/dimensions/dimensions.tsx +1 -1
- package/resources/templates/template-workspace/admin/lib/editor/common/editor-canvas.tsx +2 -2
- package/resources/templates/template-workspace/admin/lib/editor/index.ts +1 -0
- package/resources/templates/template-workspace/admin/lib/editor/rich-text-view.tsx +17 -0
- package/resources/templates/template-workspace/admin/lib/field/formatted-field.tsx +10 -0
- package/resources/templates/template-workspace/admin/lib/field/index.ts +1 -0
- package/resources/templates/template-workspace/admin/lib/form/container.tsx +43 -45
- package/resources/templates/template-workspace/admin/lib/form/index.ts +1 -0
- package/resources/templates/template-workspace/admin/lib/form/inputs.tsx +56 -23
- package/resources/templates/template-workspace/admin/lib/form/select.tsx +61 -30
- package/resources/templates/template-workspace/admin/lib/form/ui.tsx +11 -2
- package/resources/templates/template-workspace/admin/lib/form/upload-repeaters.tsx +188 -0
- package/resources/templates/template-workspace/admin/lib/form/upload.tsx +57 -242
- package/resources/templates/template-workspace/admin/lib/formatting/formatting.ts +23 -0
- package/resources/templates/template-workspace/admin/lib/labels/enum-labels.ts +9 -0
- package/resources/templates/template-workspace/admin/lib/labels/field-labels.ts +7 -0
- package/resources/templates/template-workspace/admin/lib/labels/index.ts +2 -0
- package/resources/templates/template-workspace/admin/lib/layout/layout.tsx +3 -3
- package/resources/templates/template-workspace/admin/lib/repeater/repeater.tsx +97 -64
- package/resources/templates/template-workspace/admin/lib/select/filter.tsx +3 -2
- package/resources/templates/template-workspace/admin/lib/select/index.ts +0 -1
- package/resources/templates/template-workspace/admin/lib/select/list.tsx +78 -26
- package/resources/templates/template-workspace/admin/lib/select/multi-select.tsx +12 -19
- package/resources/templates/template-workspace/admin/lib/select/select.tsx +40 -23
- package/resources/templates/template-workspace/admin/lib/select/sortable-select.tsx +23 -18
- package/resources/templates/template-workspace/admin/lib/select/ui.tsx +3 -0
- package/resources/templates/template-workspace/admin/lib/tenant/forms/invite.tsx +5 -3
- package/resources/templates/template-workspace/admin/lib/tenant/forms/memberships-control.tsx +28 -16
- package/resources/templates/template-workspace/admin/lib/tenant/forms/password-reset.tsx +9 -6
- package/resources/templates/template-workspace/admin/lib/tenant/forms/passwordless-signin-init.tsx +31 -0
- package/resources/templates/template-workspace/admin/lib/tenant/forms/passwordless-signin.tsx +59 -0
- package/resources/templates/template-workspace/admin/lib/tenant/forms/update-project-member.tsx +5 -3
- package/resources/templates/template-workspace/admin/lib/tenant/hooks/useInvite.ts +1 -1
- package/resources/templates/template-workspace/admin/lib/tenant/listing/member-list.tsx +6 -5
- package/resources/templates/template-workspace/admin/lib/tenant/listing/person-list.tsx +2 -1
- package/resources/templates/template-workspace/admin/lib/ui/alert-dialog.tsx +2 -1
- package/resources/templates/template-workspace/admin/lib/ui/collapsible.tsx +9 -0
- package/resources/templates/template-workspace/admin/lib/ui/dialog.tsx +2 -1
- package/resources/templates/template-workspace/admin/lib/ui/dropdown.tsx +2 -1
- package/resources/templates/template-workspace/admin/lib/ui/input.tsx +14 -10
- package/resources/templates/template-workspace/admin/lib/ui/menu.tsx +2 -3
- package/resources/templates/template-workspace/admin/lib/ui/popover.tsx +2 -1
- package/resources/templates/template-workspace/admin/lib/ui/property-list.tsx +33 -0
- package/resources/templates/template-workspace/admin/lib/ui/select.tsx +80 -0
- package/resources/templates/template-workspace/admin/lib/ui/sheet.tsx +3 -2
- package/resources/templates/template-workspace/admin/lib/ui/textarea.tsx +9 -1
- package/resources/templates/template-workspace/admin/lib/upload/view.tsx +160 -165
- package/resources/templates/template-workspace/admin/lib/utils/createComponentOpenHooks.tsx +38 -0
- package/resources/templates/template-workspace/admin/lib/utils/uic.tsx +3 -3
- package/resources/templates/template-workspace/admin/package.json +21 -20
- package/resources/templates/template-workspace/package.json +3 -3
- package/src/lib/TemplateInstaller.ts +2 -9
- package/src/paths.ts +4 -3
- package/src/run.ts +0 -2
- package/tsconfig.settings.json +0 -4
- package/dist/development/src/lib/PackageDownloader.cjs +0 -33
- package/dist/development/src/lib/PackageDownloader.cjs.map +0 -1
- package/dist/development/src/lib/PackageDownloader.js +0 -33
- package/dist/development/src/lib/PackageDownloader.js.map +0 -1
- package/dist/production/src/lib/PackageDownloader.cjs +0 -33
- package/dist/production/src/lib/PackageDownloader.cjs.map +0 -1
- package/dist/production/src/lib/PackageDownloader.js +0 -33
- package/dist/production/src/lib/PackageDownloader.js.map +0 -1
- package/dist/types/lib/PackageDownloader.d.ts +0 -7
- package/dist/types/lib/PackageDownloader.d.ts.map +0 -1
- package/resources/templates/template-workspace/admin/.env.production +0 -3
- package/resources/templates/template-workspace/admin/lib/select/pagination.tsx +0 -48
- package/src/lib/PackageDownloader.ts +0 -33
- package/types/download-tarball/index.d.ts +0 -7
- package/types/get-package-json-from-registry/index.d.ts +0 -3
- package/types/registry-info/index.d.ts +0 -7
|
@@ -1,19 +1,50 @@
|
|
|
1
|
-
import { IdentityState } from '@contember/react-identity'
|
|
1
|
+
import { IdentityState, LogoutTrigger } from '@contember/react-identity'
|
|
2
2
|
import { Loader } from '../ui/loader'
|
|
3
3
|
import { dict } from '../dict'
|
|
4
|
+
import { Button } from '../ui/button'
|
|
5
|
+
import { Card, CardContent } from '../ui/card'
|
|
6
|
+
import { CircleAlert } from 'lucide-react'
|
|
7
|
+
import { useEffect } from 'react'
|
|
4
8
|
|
|
5
9
|
export const IdentityLoader = ({ children }: {
|
|
6
10
|
children: React.ReactNode
|
|
7
11
|
}) => {
|
|
8
12
|
return <>
|
|
9
|
-
<IdentityState state={['loading'
|
|
13
|
+
<IdentityState state={['loading']}>
|
|
10
14
|
<Loader />
|
|
11
15
|
</IdentityState>
|
|
16
|
+
<IdentityState state={['none', 'cleared']}>
|
|
17
|
+
<Redirect />
|
|
18
|
+
</IdentityState>
|
|
12
19
|
<IdentityState state={'failed'}>
|
|
13
|
-
|
|
20
|
+
<div className="flex justify-center items-center h-screen bg-gray-100">
|
|
21
|
+
<Card className="w-72">
|
|
22
|
+
<CardContent className="flex flex-col items-center gap-2">
|
|
23
|
+
<CircleAlert className="h-12 w-12 text-destructive" />
|
|
24
|
+
<p className="text-center text-lg text-gray-600">
|
|
25
|
+
{dict.identityLoader.fail}
|
|
26
|
+
</p>
|
|
27
|
+
<div className="flex gap-2">
|
|
28
|
+
<Button onClick={() => window.location.reload()} variant="secondary">Try reload</Button>
|
|
29
|
+
<LogoutTrigger>
|
|
30
|
+
<Button>Login again</Button>
|
|
31
|
+
</LogoutTrigger>
|
|
32
|
+
</div>
|
|
33
|
+
</CardContent>
|
|
34
|
+
</Card>
|
|
35
|
+
|
|
36
|
+
</div>
|
|
14
37
|
</IdentityState>
|
|
15
38
|
<IdentityState state={'success'}>
|
|
16
39
|
{children}
|
|
17
40
|
</IdentityState>
|
|
18
41
|
</>
|
|
19
42
|
}
|
|
43
|
+
|
|
44
|
+
const Redirect = () => {
|
|
45
|
+
useEffect(() => {
|
|
46
|
+
const backlink = window.location.pathname + window.location.search
|
|
47
|
+
window.location.href = `/?backlink=${encodeURIComponent(backlink)}` // redirect to login with backlink
|
|
48
|
+
})
|
|
49
|
+
return null
|
|
50
|
+
}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { useCallback, useState } from 'react'
|
|
2
|
+
import { AlertDialog, AlertDialogCancel, AlertDialogContent, AlertDialogTitle } from '../ui/alert-dialog'
|
|
3
|
+
import { BlockNavigationOnDirtyStateResult, useBlockNavigationOnDirtyState } from '@contember/interface'
|
|
4
|
+
import { usePersistFeedbackHandlers } from './hooks'
|
|
5
|
+
import { Button } from '../ui/button'
|
|
6
|
+
import { SaveIcon } from 'lucide-react'
|
|
7
|
+
|
|
8
|
+
export const NavigationGuardDialog = () => {
|
|
9
|
+
const [resolver, setResolver] = useState<((value: BlockNavigationOnDirtyStateResult) => void) | null>(null)
|
|
10
|
+
|
|
11
|
+
const handler = useCallback(() => new Promise<BlockNavigationOnDirtyStateResult>(resolve => {
|
|
12
|
+
setResolver(() => (value: BlockNavigationOnDirtyStateResult) => {
|
|
13
|
+
setResolver(null)
|
|
14
|
+
resolve(value)
|
|
15
|
+
})
|
|
16
|
+
}), [])
|
|
17
|
+
|
|
18
|
+
useBlockNavigationOnDirtyState(handler, usePersistFeedbackHandlers())
|
|
19
|
+
|
|
20
|
+
return (
|
|
21
|
+
<AlertDialog open={resolver !== null} onOpenChange={it => it ? null : resolver?.('cancel')}>
|
|
22
|
+
<AlertDialogContent>
|
|
23
|
+
<AlertDialogTitle>Unsaved changes</AlertDialogTitle>
|
|
24
|
+
Do you want to save your changes before leaving?
|
|
25
|
+
<div className="flex gap-2 justify-end">
|
|
26
|
+
<Button onClick={() => resolver?.('save')}>
|
|
27
|
+
<SaveIcon className="w-4 h-4 mr-2" />
|
|
28
|
+
Save
|
|
29
|
+
</Button>
|
|
30
|
+
<Button onClick={() => resolver?.('discard')} variant="outline"
|
|
31
|
+
className="border-destructive/50 text-destructive hover:bg-red-100 hover:text-destructive">
|
|
32
|
+
Don't save
|
|
33
|
+
</Button>
|
|
34
|
+
<AlertDialogCancel onClick={() => resolver?.('cancel')} className="border-gray-500">Cancel</AlertDialogCancel>
|
|
35
|
+
</div>
|
|
36
|
+
</AlertDialogContent>
|
|
37
|
+
</AlertDialog>
|
|
38
|
+
)
|
|
39
|
+
}
|
|
@@ -1,70 +1,20 @@
|
|
|
1
|
-
import { PersistTrigger
|
|
1
|
+
import { PersistTrigger } from '@contember/interface'
|
|
2
|
+
import { ReactNode } from 'react'
|
|
3
|
+
import { dict } from '../dict'
|
|
2
4
|
import { Button } from '../ui/button'
|
|
3
5
|
import { Loader } from '../ui/loader'
|
|
4
|
-
import {
|
|
5
|
-
import { Slot } from '@radix-ui/react-slot'
|
|
6
|
-
import { usePersist } from '@contember/interface'
|
|
7
|
-
import { dict } from '../dict'
|
|
8
|
-
import { usePersistErrorHandler, usePersistFeedbackHandlers, usePersistWithFeedback } from './hooks'
|
|
9
|
-
|
|
10
|
-
export const FeedbackTrigger = (props: { children: ReactElement }) => {
|
|
11
|
-
return <Slot {...props} {...usePersistFeedbackHandlers()} />
|
|
12
|
-
}
|
|
6
|
+
import { usePersistSuccessHandler } from './hooks'
|
|
13
7
|
|
|
14
8
|
export const PersistButton = ({ label }: {
|
|
15
9
|
label?: ReactNode
|
|
16
10
|
}) => {
|
|
17
11
|
return (
|
|
18
|
-
<
|
|
19
|
-
<
|
|
20
|
-
<
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
</PersistTrigger>
|
|
25
|
-
</FeedbackTrigger>
|
|
12
|
+
<PersistTrigger onPersistSuccess={usePersistSuccessHandler()}>
|
|
13
|
+
<Button className="group">
|
|
14
|
+
<Loader size="sm" position="absolute" className="hidden group-data-[loading]:block" />
|
|
15
|
+
{label ?? dict.persist.persistButton}
|
|
16
|
+
</Button>
|
|
17
|
+
</PersistTrigger>
|
|
26
18
|
)
|
|
27
19
|
}
|
|
28
20
|
|
|
29
|
-
|
|
30
|
-
export const PersistOnCmdS = () => {
|
|
31
|
-
const persist = usePersistWithFeedback()
|
|
32
|
-
useEffect(() => {
|
|
33
|
-
const listener = (event: KeyboardEvent) => {
|
|
34
|
-
if (event.ctrlKey && event.key === 's') {
|
|
35
|
-
event.preventDefault()
|
|
36
|
-
persist()
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
document.body.addEventListener('keydown', listener)
|
|
40
|
-
return () => document.body.removeEventListener('keydown', listener)
|
|
41
|
-
}, [persist])
|
|
42
|
-
|
|
43
|
-
return null
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
export const PersistOnFieldChange = ({ field }: {
|
|
48
|
-
field: SugaredRelativeSingleField['field']
|
|
49
|
-
}) => {
|
|
50
|
-
const triggerPersist = usePersist()
|
|
51
|
-
const onError = usePersistErrorHandler()
|
|
52
|
-
const getField = useField(field).getAccessor
|
|
53
|
-
useEffect(() => {
|
|
54
|
-
let persisting = false
|
|
55
|
-
return getField().addEventListener({ type: 'update' }, async field => {
|
|
56
|
-
if (persisting || field.value === field.valueOnServer) {
|
|
57
|
-
return
|
|
58
|
-
}
|
|
59
|
-
persisting = true
|
|
60
|
-
try {
|
|
61
|
-
await Promise.resolve()
|
|
62
|
-
await triggerPersist().catch(onError)
|
|
63
|
-
} finally {
|
|
64
|
-
persisting = false
|
|
65
|
-
}
|
|
66
|
-
})
|
|
67
|
-
}, [getField, onError, triggerPersist])
|
|
68
|
-
|
|
69
|
-
return null
|
|
70
|
-
}
|
|
@@ -1,43 +1,96 @@
|
|
|
1
|
-
import { Component, DeleteEntityTrigger, PersistTrigger, StaticRender, useEntity } from '@contember/interface'
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
1
|
+
import { Component, DeleteEntityTrigger, PersistTrigger, StaticRender, SuccessfulPersistResult, useEntity } from '@contember/interface'
|
|
2
|
+
import {
|
|
3
|
+
BlockRepeater,
|
|
4
|
+
BlockRepeaterAddItemTrigger,
|
|
5
|
+
BlockRepeaterProps,
|
|
6
|
+
useBlockRepeaterConfig,
|
|
7
|
+
useBlockRepeaterCurrentBlock,
|
|
8
|
+
} from '@contember/react-block-repeater'
|
|
9
9
|
import { RepeaterAddItemIndex, RepeaterEmpty } from '@contember/react-repeater'
|
|
10
|
-
import {
|
|
11
|
-
|
|
10
|
+
import {
|
|
11
|
+
RepeaterSortable,
|
|
12
|
+
RepeaterSortableDragOverlay,
|
|
13
|
+
RepeaterSortableEachItem,
|
|
14
|
+
RepeaterSortableItemActivator,
|
|
15
|
+
RepeaterSortableItemNode,
|
|
16
|
+
} from '@contember/react-repeater-dnd-kit'
|
|
12
17
|
import { createRequiredContext } from '@contember/react-utils'
|
|
13
|
-
import {
|
|
18
|
+
import { GripVerticalIcon, PlusCircleIcon, TrashIcon } from 'lucide-react'
|
|
19
|
+
import { useCallback, useId, useState } from 'react'
|
|
20
|
+
import { usePersistSuccessHandler } from '../binding'
|
|
21
|
+
import { dict } from '../dict'
|
|
22
|
+
import { RepeaterDropIndicator, RepeaterRemoveItemButton } from '../repeater'
|
|
23
|
+
import { Button } from '../ui/button'
|
|
24
|
+
import { DropdownMenu, DropdownMenuContent, DropdownMenuItem, DropdownMenuTrigger } from '../ui/dropdown'
|
|
14
25
|
import { Label } from '../ui/label'
|
|
26
|
+
import { Sheet, SheetClose, SheetContent, SheetFooter, SheetHeader, SheetTitle } from '../ui/sheet'
|
|
15
27
|
import { Switch } from '../ui/switch'
|
|
16
|
-
import {
|
|
28
|
+
import { uic } from '../utils'
|
|
17
29
|
|
|
18
|
-
|
|
30
|
+
const BlockRepeaterItemsWrapperUI = uic('div', {
|
|
19
31
|
baseClass: 'rounded border border-gray-300 px-4 py-8 flex flex-col',
|
|
20
32
|
})
|
|
21
|
-
|
|
33
|
+
const BlockRepeaterItemUI = uic('div', {
|
|
22
34
|
baseClass: 'relative border-t transition-all group',
|
|
23
35
|
})
|
|
24
|
-
|
|
36
|
+
const BlockRepeaterDragOverlayUI = uic('div', {
|
|
25
37
|
baseClass: 'rounded border border-gray-300 p-4 relative bg-opacity-60 bg-gray-100 backdrop-blur-sm',
|
|
26
38
|
})
|
|
27
|
-
|
|
39
|
+
const BlockRepeaterHandleUI = uic('button', {
|
|
28
40
|
baseClass: 'absolute top-1/2 -left-6 h-6 w-6 flex justify-end align-center opacity-10 hover:opacity-100 transition-opacity -translate-y-1/2',
|
|
29
41
|
beforeChildren: <GripVerticalIcon size={16} />,
|
|
30
42
|
})
|
|
31
43
|
|
|
32
|
-
|
|
44
|
+
const BlockRepeaterItemActions = uic('div', {
|
|
33
45
|
baseClass: 'absolute top-1 right-2 flex gap-2 opacity-0 group-hover:opacity-100 transition-opacity',
|
|
34
46
|
})
|
|
35
47
|
|
|
48
|
+
const BlockRepeaterContentWrapperUI = uic('div', {
|
|
49
|
+
baseClass: 'flex flex-col gap-2',
|
|
50
|
+
})
|
|
51
|
+
|
|
36
52
|
export type DefaultBlockRepeaterProps =
|
|
37
53
|
& BlockRepeaterProps
|
|
38
54
|
|
|
39
55
|
const [BlockRepeaterEditModeContext, useBlockRepeaterEditMode] = createRequiredContext<boolean>('BlockRepeaterEditMode')
|
|
40
56
|
|
|
57
|
+
/**
|
|
58
|
+
* The `DefaultBlockRepeater` component is a versatile and customizable block repeater shipped with a UI.
|
|
59
|
+
* It allows for the creation and management of repeatable content blocks within a form.
|
|
60
|
+
* Supports two modes of operation:
|
|
61
|
+
* - **Inline Edit Mode**: By providing only `children`, the blocks can be edited inline.
|
|
62
|
+
* - **Dual-Mode**: By providing both `form` and `children`, the component supports a dual-mode where blocks can be edited in a separate form view.
|
|
63
|
+
*
|
|
64
|
+
* ## Props {@link DefaultBlockRepeaterProps}
|
|
65
|
+
* - field or entities, sortableBy, discriminationField, children
|
|
66
|
+
*
|
|
67
|
+
* ## Example
|
|
68
|
+
* ```tsx
|
|
69
|
+
* <DefaultBlockRepeater field="blocks" sortableBy="order" discriminationField="type">
|
|
70
|
+
* <Block
|
|
71
|
+
* name="text"
|
|
72
|
+
* label={<><TextIcon /> Text</>}
|
|
73
|
+
* form={<>
|
|
74
|
+
* <InputField field="title" label="Title" />
|
|
75
|
+
* <TextareaField field="content" label="Content" />
|
|
76
|
+
* </>}
|
|
77
|
+
* children={<>
|
|
78
|
+
* <div className="flex">
|
|
79
|
+
* <div className="w-64 space-y-2">
|
|
80
|
+
* <h2 className="text-xl font-bold">
|
|
81
|
+
* <Field field="title" />
|
|
82
|
+
* </h2>
|
|
83
|
+
* <p>
|
|
84
|
+
* <Field field="content" />
|
|
85
|
+
* </p>
|
|
86
|
+
* </div>
|
|
87
|
+
* </div>
|
|
88
|
+
* </>
|
|
89
|
+
* }
|
|
90
|
+
* />
|
|
91
|
+
* </DefaultBlockRepeater>
|
|
92
|
+
* ```
|
|
93
|
+
*/
|
|
41
94
|
export const DefaultBlockRepeater = Component<DefaultBlockRepeaterProps>(({ children, ...props }) => {
|
|
42
95
|
const [editMode, setEditMode] = useState(false)
|
|
43
96
|
return (
|
|
@@ -46,11 +99,13 @@ export const DefaultBlockRepeater = Component<DefaultBlockRepeaterProps>(({ chil
|
|
|
46
99
|
{children}
|
|
47
100
|
</StaticRender>
|
|
48
101
|
<BlockRepeaterEditModeContext.Provider value={editMode}>
|
|
49
|
-
<
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
<
|
|
53
|
-
|
|
102
|
+
<BlockRepeaterContentWrapperUI>
|
|
103
|
+
<ToggleEditMode setEditMode={setEditMode} editMode={editMode} />
|
|
104
|
+
<BlockRepeaterSortable sortableBy={props.sortableBy} />
|
|
105
|
+
<div className="mt-4">
|
|
106
|
+
<BlockRepeaterAddButtons />
|
|
107
|
+
</div>
|
|
108
|
+
</BlockRepeaterContentWrapperUI>
|
|
54
109
|
</BlockRepeaterEditModeContext.Provider>
|
|
55
110
|
</BlockRepeater>
|
|
56
111
|
)
|
|
@@ -67,13 +122,15 @@ const ToggleEditMode = ({ setEditMode, editMode }: { setEditMode: (value: boolea
|
|
|
67
122
|
}
|
|
68
123
|
return (
|
|
69
124
|
<div className="flex items-center space-x-2 justify-end mb-2">
|
|
70
|
-
<Switch id={id} checked={editMode} onCheckedChange={setEditMode
|
|
125
|
+
<Switch id={id} checked={editMode} onCheckedChange={setEditMode} />
|
|
71
126
|
<Label htmlFor={id}>Edit mode</Label>
|
|
72
127
|
</div>
|
|
73
128
|
)
|
|
74
129
|
}
|
|
75
130
|
|
|
76
|
-
|
|
131
|
+
const BlockRepeaterSortable = Component<{
|
|
132
|
+
sortableBy: DefaultBlockRepeaterProps['sortableBy']
|
|
133
|
+
}>(({ sortableBy }) => {
|
|
77
134
|
return (
|
|
78
135
|
<RepeaterSortable>
|
|
79
136
|
<BlockRepeaterItemsWrapperUI>
|
|
@@ -109,13 +166,18 @@ export const BlockRepeaterSortable = Component<{ sortableBy: DefaultBlockRepeate
|
|
|
109
166
|
)
|
|
110
167
|
})
|
|
111
168
|
|
|
112
|
-
|
|
169
|
+
const BlockRepeaterAddButtons = ({ index }: { index?: RepeaterAddItemIndex }) => {
|
|
113
170
|
const { blocks } = useBlockRepeaterConfig()
|
|
114
171
|
return (
|
|
115
172
|
<div className="grid grid-cols-[repeat(auto-fill,minmax(110px,1fr))] gap-2">
|
|
116
173
|
{Object.values(blocks).map(it => (
|
|
117
174
|
<BlockRepeaterAddItemTrigger key={it.name} type={it.name} index={index}>
|
|
118
|
-
<Button
|
|
175
|
+
<Button
|
|
176
|
+
size="lg"
|
|
177
|
+
variant="outline"
|
|
178
|
+
className="aspect-square flex-col h-auto gap-2 p-2"
|
|
179
|
+
onClick={e => e.stopPropagation()}
|
|
180
|
+
>
|
|
119
181
|
{it.label || it.name}
|
|
120
182
|
</Button>
|
|
121
183
|
</BlockRepeaterAddItemTrigger>
|
|
@@ -125,7 +187,7 @@ export const BlockRepeaterAddButtons = ({ index }: { index?: RepeaterAddItemInde
|
|
|
125
187
|
}
|
|
126
188
|
|
|
127
189
|
|
|
128
|
-
|
|
190
|
+
const BlockRepeaterContent = () => {
|
|
129
191
|
const entity = useEntity()
|
|
130
192
|
const block = useBlockRepeaterCurrentBlock()
|
|
131
193
|
const children = block?.children
|
|
@@ -152,7 +214,6 @@ export const BlockRepeaterContent = () => {
|
|
|
152
214
|
}
|
|
153
215
|
|
|
154
216
|
|
|
155
|
-
|
|
156
217
|
const BlockRepeaterAddItemBefore = ({ sortableBy }: { sortableBy: DefaultBlockRepeaterProps['sortableBy'] }) => {
|
|
157
218
|
const entity = useEntity()
|
|
158
219
|
const order = sortableBy ? entity.getField<number>(sortableBy).value : null
|
|
@@ -184,21 +245,34 @@ const BlockRepeaterEditSheetInner = ({ open, setOpen }: { open: boolean; setOpen
|
|
|
184
245
|
const block = useBlockRepeaterCurrentBlock()
|
|
185
246
|
const form = block?.form
|
|
186
247
|
const editMode = useBlockRepeaterEditMode()
|
|
248
|
+
const persistSuccess = usePersistSuccessHandler()
|
|
249
|
+
const onSuccess = useCallback((result: SuccessfulPersistResult) => {
|
|
250
|
+
persistSuccess(result)
|
|
251
|
+
setOpen(false)
|
|
252
|
+
}, [persistSuccess, setOpen])
|
|
187
253
|
|
|
188
254
|
if (!form || editMode) {
|
|
189
255
|
return null
|
|
190
256
|
}
|
|
191
257
|
return (
|
|
192
258
|
<Sheet open={open} onOpenChange={setOpen} modal={false}>
|
|
193
|
-
<SheetContent
|
|
194
|
-
e
|
|
195
|
-
|
|
259
|
+
<SheetContent
|
|
260
|
+
onFocusOutside={e => {
|
|
261
|
+
e.preventDefault()
|
|
262
|
+
}}
|
|
263
|
+
>
|
|
196
264
|
<SheetHeader>
|
|
197
265
|
<SheetTitle className="flex gap-2">
|
|
198
266
|
{block.label}
|
|
199
267
|
<DeleteEntityTrigger>
|
|
200
268
|
<SheetClose asChild>
|
|
201
|
-
<Button
|
|
269
|
+
<Button
|
|
270
|
+
variant="destructive"
|
|
271
|
+
className="ml-auto"
|
|
272
|
+
size="sm"
|
|
273
|
+
>
|
|
274
|
+
<TrashIcon className="w-3 h-3" />
|
|
275
|
+
</Button>
|
|
202
276
|
</SheetClose>
|
|
203
277
|
</DeleteEntityTrigger>
|
|
204
278
|
</SheetTitle>
|
|
@@ -210,13 +284,9 @@ const BlockRepeaterEditSheetInner = ({ open, setOpen }: { open: boolean; setOpen
|
|
|
210
284
|
<SheetClose asChild>
|
|
211
285
|
<Button variant="link">Close</Button>
|
|
212
286
|
</SheetClose>
|
|
213
|
-
<
|
|
214
|
-
<
|
|
215
|
-
|
|
216
|
-
<Button variant="link">Close & save</Button>
|
|
217
|
-
</SheetClose>
|
|
218
|
-
</PersistTrigger>
|
|
219
|
-
</FeedbackTrigger>
|
|
287
|
+
<PersistTrigger onPersistSuccess={onSuccess}>
|
|
288
|
+
<Button variant="link">Close & save</Button>
|
|
289
|
+
</PersistTrigger>
|
|
220
290
|
</SheetFooter>
|
|
221
291
|
</SheetContent>
|
|
222
292
|
</Sheet>
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { ReactNode } from 'react'
|
|
2
2
|
import { AnchorButton } from '../ui/button'
|
|
3
3
|
import { ArrowLeftIcon } from 'lucide-react'
|
|
4
|
-
import { Link, RoutingLinkTarget } from '@contember/
|
|
4
|
+
import { Link, type RoutingLinkTarget } from '@contember/interface'
|
|
5
5
|
import { Slots } from '../layout'
|
|
6
6
|
|
|
7
7
|
export const LinkBackButton = ({ children, to }: {
|
|
@@ -2,15 +2,48 @@ import * as React from 'react'
|
|
|
2
2
|
import { ReactNode } from 'react'
|
|
3
3
|
import { DataGridEnumFieldTooltip, DataGridHasManyTooltip, DataGridHasOneTooltip } from './filters'
|
|
4
4
|
import { DataGridTooltipLabel } from './ui'
|
|
5
|
-
import {
|
|
5
|
+
import {
|
|
6
|
+
Component,
|
|
7
|
+
Field,
|
|
8
|
+
FieldView,
|
|
9
|
+
HasMany,
|
|
10
|
+
HasOne,
|
|
11
|
+
SugaredRelativeEntityList,
|
|
12
|
+
SugaredRelativeSingleEntity,
|
|
13
|
+
SugaredRelativeSingleField,
|
|
14
|
+
} from '@contember/interface'
|
|
15
|
+
import { useEnumOptionsFormatter } from '../labels'
|
|
6
16
|
|
|
17
|
+
/**
|
|
18
|
+
* Props for {@link DataGridHasOneCell}.
|
|
19
|
+
*/
|
|
7
20
|
export type DataGridHasOneCellProps = {
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* Has-one field to be displayed.
|
|
24
|
+
*/
|
|
8
25
|
field: SugaredRelativeSingleEntity['field']
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* Filter identifier. If not provided, the filter is resolved from the field name.
|
|
29
|
+
*/
|
|
9
30
|
filterName?: string
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* Cell content in the context of the has-one relation.
|
|
34
|
+
*/
|
|
10
35
|
children: ReactNode
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* Custom actions to be displayed in the tooltip.
|
|
39
|
+
*/
|
|
11
40
|
tooltipActions?: ReactNode
|
|
12
41
|
}
|
|
13
42
|
|
|
43
|
+
/**
|
|
44
|
+
* Renders a cell with a has-one relation.
|
|
45
|
+
* Contains a tooltip with filter actions.
|
|
46
|
+
*/
|
|
14
47
|
export const DataGridHasOneCell = Component(({ field, filterName, children, tooltipActions }: DataGridHasOneCellProps) => {
|
|
15
48
|
return (
|
|
16
49
|
<HasOne field={field}>
|
|
@@ -23,13 +56,35 @@ export const DataGridHasOneCell = Component(({ field, filterName, children, tool
|
|
|
23
56
|
)
|
|
24
57
|
})
|
|
25
58
|
|
|
59
|
+
/**
|
|
60
|
+
* Props for {@link DataGridHasManyCell}.
|
|
61
|
+
*/
|
|
26
62
|
export type DataGridHasManyCellProps = {
|
|
63
|
+
/**
|
|
64
|
+
* Has-many field to be displayed.
|
|
65
|
+
*/
|
|
27
66
|
field: SugaredRelativeEntityList['field']
|
|
67
|
+
|
|
68
|
+
/**
|
|
69
|
+
* Filter identifier. If not provided, the filter is resolved from the field name.
|
|
70
|
+
*/
|
|
28
71
|
filterName?: string
|
|
72
|
+
|
|
73
|
+
/**
|
|
74
|
+
* Cell content in the context of the has-many relation.
|
|
75
|
+
*/
|
|
29
76
|
children: ReactNode
|
|
77
|
+
|
|
78
|
+
/**
|
|
79
|
+
* Custom actions to be displayed in the tooltip.
|
|
80
|
+
*/
|
|
30
81
|
tooltipActions?: ReactNode
|
|
31
82
|
}
|
|
32
83
|
|
|
84
|
+
/**
|
|
85
|
+
* Renders a cell with a has-many relation.
|
|
86
|
+
* Contains a tooltip with filter actions.
|
|
87
|
+
*/
|
|
33
88
|
export const DataGridHasManyCell = Component(({ field, filterName, children, tooltipActions }: DataGridHasManyCellProps) => {
|
|
34
89
|
return (
|
|
35
90
|
<div className={'flex flex-wrap gap-2'}>
|
|
@@ -44,21 +99,46 @@ export const DataGridHasManyCell = Component(({ field, filterName, children, too
|
|
|
44
99
|
)
|
|
45
100
|
})
|
|
46
101
|
|
|
102
|
+
/**
|
|
103
|
+
* Props for {@link DataGridEnumCell}.
|
|
104
|
+
*/
|
|
47
105
|
export type DataGridEnumCellProps = {
|
|
106
|
+
/**
|
|
107
|
+
* Field to be displayed.
|
|
108
|
+
*/
|
|
48
109
|
field: SugaredRelativeSingleField['field']
|
|
110
|
+
|
|
111
|
+
/**
|
|
112
|
+
* Filter identifier. If not provided, the filter is resolved from the field name.
|
|
113
|
+
*/
|
|
49
114
|
filterName?: string
|
|
50
|
-
|
|
115
|
+
|
|
116
|
+
/**
|
|
117
|
+
* Enum options to be displayed in the tooltip. If not provided, the options are resolved from the enum.
|
|
118
|
+
*/
|
|
119
|
+
options?: Record<string, ReactNode>
|
|
120
|
+
/**
|
|
121
|
+
* Custom actions to be displayed in the tooltip.
|
|
122
|
+
*/
|
|
51
123
|
tooltipActions?: ReactNode
|
|
52
124
|
}
|
|
53
125
|
|
|
126
|
+
/**
|
|
127
|
+
* Renders a cell with an enum value.
|
|
128
|
+
* Contains a tooltip with filter actions.
|
|
129
|
+
*/
|
|
54
130
|
export const DataGridEnumCell = Component(({ field, options, filterName, tooltipActions }: DataGridEnumCellProps) => {
|
|
131
|
+
const enumOptionsProvider = useEnumOptionsFormatter()
|
|
55
132
|
return (
|
|
56
|
-
<
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
133
|
+
<FieldView<string> field={field} render={it => {
|
|
134
|
+
const resolvedOptions = options ?? enumOptionsProvider(it.schema.enumName!)
|
|
135
|
+
return it.value ? (
|
|
136
|
+
<DataGridEnumFieldTooltip value={it.value} field={field} name={filterName} actions={tooltipActions}>
|
|
137
|
+
<DataGridTooltipLabel>
|
|
138
|
+
{resolvedOptions[it.value]}
|
|
139
|
+
</DataGridTooltipLabel>
|
|
140
|
+
</DataGridEnumFieldTooltip>
|
|
141
|
+
) : null
|
|
142
|
+
}} />
|
|
63
143
|
)
|
|
64
|
-
})
|
|
144
|
+
}, ({ field }) => <Field field={field} />, 'DataGridEnumCell')
|
|
@@ -7,14 +7,22 @@ import { dict } from '../dict'
|
|
|
7
7
|
import { Component } from '@contember/interface'
|
|
8
8
|
import { Popover, PopoverContent, PopoverTrigger } from '../ui/popover'
|
|
9
9
|
|
|
10
|
-
|
|
11
|
-
|
|
10
|
+
/**
|
|
11
|
+
* Props for {@link DataGridColumnHeader}.
|
|
12
|
+
*/
|
|
13
|
+
export type DataGridColumnHeaderProps = {
|
|
12
14
|
sortingField?: string
|
|
13
15
|
hidingName?: string
|
|
14
16
|
filterName?: string
|
|
15
17
|
filter?: ReactNode
|
|
16
18
|
children: ReactNode
|
|
17
|
-
}
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* Column header for data grid.
|
|
23
|
+
* Contains filtering, sorting and hiding controls.
|
|
24
|
+
*/
|
|
25
|
+
export const DataGridColumnHeader = Component(({ sortingField, hidingName, children, filter, filterName }: DataGridColumnHeaderProps) => {
|
|
18
26
|
let hasFilter = false
|
|
19
27
|
if (filterName) {
|
|
20
28
|
const [, , { isEmpty }] = useDataViewFilter(filterName)
|
|
@@ -22,7 +30,7 @@ export const DataGridColumnHeader = Component(({ sortingField, hidingName, child
|
|
|
22
30
|
}
|
|
23
31
|
|
|
24
32
|
if (!sortingField && !hidingName && !filter) {
|
|
25
|
-
return <div>{children}</div>
|
|
33
|
+
return <div className="text-xs">{children}</div>
|
|
26
34
|
}
|
|
27
35
|
|
|
28
36
|
return (
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { Component } from '@contember/interface'
|
|
2
|
+
import * as React from 'react'
|
|
3
|
+
import { ReactNode } from 'react'
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* @internal
|
|
7
|
+
*/
|
|
8
|
+
export interface DataGridColumnLeafProps {
|
|
9
|
+
header?: ReactNode
|
|
10
|
+
cell: ReactNode
|
|
11
|
+
name?: string
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* @internal
|
|
16
|
+
*/
|
|
17
|
+
export const DataGridColumnLeaf = Component<DataGridColumnLeafProps>(() => {
|
|
18
|
+
throw new Error('DataGridColumnLeaf is not supposed to be rendered')
|
|
19
|
+
}, ({ header, cell }) => {
|
|
20
|
+
return <>{header}{cell}</>
|
|
21
|
+
})
|