@contember/create 2.0.0-beta.3 → 2.0.0-beta.5
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/package.json +2 -2
- package/resources/templates/template-workspace/admin/lib/binding/binding.tsx +8 -5
- package/resources/templates/template-workspace/admin/lib/errors/error-boundary.tsx +31 -0
- package/resources/templates/template-workspace/admin/lib/repeater/repeater.tsx +15 -14
- package/resources/templates/template-workspace/admin/lib/ui/sidebar.tsx +3 -3
package/package.json
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@contember/create",
|
|
3
|
-
"version": "2.0.0-beta.
|
|
3
|
+
"version": "2.0.0-beta.5",
|
|
4
4
|
"license": "Apache-2.0",
|
|
5
5
|
"bin": "dist/production/run.js",
|
|
6
6
|
"dependencies": {
|
|
7
|
-
"@contember/cli-common": "2.0.0-beta.
|
|
7
|
+
"@contember/cli-common": "2.0.0-beta.5",
|
|
8
8
|
"chalk": "^5.3.0",
|
|
9
9
|
"fs-extra": "^11.2.0",
|
|
10
10
|
"js-yaml": "^4.1.0"
|
|
@@ -3,16 +3,19 @@ import { AccessorTreeState, DataBindingProvider, useDataBindingEvent } from '@co
|
|
|
3
3
|
import { Loader } from '../ui/loader'
|
|
4
4
|
import { NavigationGuardDialog } from './navigation-guard-dialog'
|
|
5
5
|
import { usePersistErrorHandler } from './hooks'
|
|
6
|
+
import { ErrorBoundary } from '../errors/error-boundary'
|
|
6
7
|
|
|
7
8
|
export const Binding = ({ children }: {
|
|
8
9
|
children: ReactNode
|
|
9
10
|
}) => {
|
|
10
11
|
return (
|
|
11
|
-
<
|
|
12
|
-
<
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
12
|
+
<ErrorBoundary>
|
|
13
|
+
<DataBindingProvider stateComponent={BindingStateRenderer}>
|
|
14
|
+
<NavigationGuardDialog />
|
|
15
|
+
<PersistErrorHandler />
|
|
16
|
+
{children}
|
|
17
|
+
</DataBindingProvider>
|
|
18
|
+
</ErrorBoundary>
|
|
16
19
|
)
|
|
17
20
|
}
|
|
18
21
|
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import React from 'react'
|
|
2
|
+
|
|
3
|
+
export type ErrorBoundaryProps = {
|
|
4
|
+
fallback?: React.ReactNode
|
|
5
|
+
children: React.ReactNode
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
export class ErrorBoundary extends React.Component<ErrorBoundaryProps, {
|
|
9
|
+
hasError: boolean
|
|
10
|
+
}> {
|
|
11
|
+
constructor(props: ErrorBoundaryProps) {
|
|
12
|
+
super(props)
|
|
13
|
+
this.state = { hasError: false }
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
static getDerivedStateFromError(error: unknown) {
|
|
17
|
+
return { hasError: true }
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
override componentDidCatch(error: unknown, info: { componentStack: string }) {
|
|
21
|
+
console.error(error, info.componentStack)
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
override render() {
|
|
25
|
+
if (this.state.hasError) {
|
|
26
|
+
return this.props.fallback ?? <div>Something went wrong</div>
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
return this.props.children
|
|
30
|
+
}
|
|
31
|
+
}
|
|
@@ -43,7 +43,7 @@ const RepeaterEmptyUI = uic('div', {
|
|
|
43
43
|
export const RepeaterDropIndicator = ({ position }: { position: 'before' | 'after' }) => (
|
|
44
44
|
<div className={'relative'}>
|
|
45
45
|
<RepeaterSortableDropIndicator position={position}>
|
|
46
|
-
<DropIndicator placement={position === 'before' ? 'top' : 'bottom'}/>
|
|
46
|
+
<DropIndicator placement={position === 'before' ? 'top' : 'bottom'} />
|
|
47
47
|
</RepeaterSortableDropIndicator>
|
|
48
48
|
</div>
|
|
49
49
|
)
|
|
@@ -53,7 +53,7 @@ export const RepeaterAddItemButton = ({ children, index }: { children?: React.Re
|
|
|
53
53
|
<div>
|
|
54
54
|
<Button variant={'link'} size={'sm'} className={'gap-1 px-0'}>
|
|
55
55
|
{children || <>
|
|
56
|
-
<PlusCircleIcon size={16}/>
|
|
56
|
+
<PlusCircleIcon size={16} />
|
|
57
57
|
<span>{dict.repeater.addItem}</span>
|
|
58
58
|
</>}
|
|
59
59
|
</Button>
|
|
@@ -68,7 +68,7 @@ export const RepeaterRemoveItemButton = ({ children }: { children?: React.ReactN
|
|
|
68
68
|
<RepeaterRemoveItemTrigger>
|
|
69
69
|
<Button variant={'link'} size={'sm'} className={'gap-1 px-0 group/button'}>
|
|
70
70
|
{children || <>
|
|
71
|
-
<Trash2Icon className={'group-hover/button:text-red-600'} size={16}/>
|
|
71
|
+
<Trash2Icon className={'group-hover/button:text-red-600'} size={16} />
|
|
72
72
|
</>}
|
|
73
73
|
</Button>
|
|
74
74
|
</RepeaterRemoveItemTrigger>
|
|
@@ -88,6 +88,7 @@ export type DefaultRepeaterProps =
|
|
|
88
88
|
* Position of the add button.
|
|
89
89
|
*/
|
|
90
90
|
addButtonPosition?: 'none' | 'after' | 'before' | 'around'
|
|
91
|
+
addButtonLabel?: ReactNode
|
|
91
92
|
}
|
|
92
93
|
& RepeaterProps
|
|
93
94
|
|
|
@@ -111,14 +112,14 @@ export const DefaultRepeater = Component<DefaultRepeaterProps>(props => {
|
|
|
111
112
|
if ('field' in props) {
|
|
112
113
|
return (
|
|
113
114
|
<RecursionTerminator field={{ field: props.field, kind: 'hasMany' }}>
|
|
114
|
-
<DefaultRepeaterInner {...props}/>
|
|
115
|
+
<DefaultRepeaterInner {...props} />
|
|
115
116
|
</RecursionTerminator>
|
|
116
117
|
)
|
|
117
118
|
}
|
|
118
|
-
return <DefaultRepeaterInner {...props}/>
|
|
119
|
+
return <DefaultRepeaterInner {...props} />
|
|
119
120
|
})
|
|
120
121
|
|
|
121
|
-
const DefaultRepeaterInner = Component<DefaultRepeaterProps>(({ title, children, addButtonPosition = 'after', ...props }) => {
|
|
122
|
+
const DefaultRepeaterInner = Component<DefaultRepeaterProps>(({ title, children, addButtonPosition = 'after', addButtonLabel, ...props }) => {
|
|
122
123
|
const isSortable = props.sortableBy !== undefined
|
|
123
124
|
|
|
124
125
|
if (!isSortable) {
|
|
@@ -126,7 +127,7 @@ const DefaultRepeaterInner = Component<DefaultRepeaterProps>(({ title, children,
|
|
|
126
127
|
<Repeater {...props}>
|
|
127
128
|
<RepeaterWrapperUI>
|
|
128
129
|
{title && <h3 className={'font-medium'}>{title}</h3>}
|
|
129
|
-
{(addButtonPosition === 'before' || addButtonPosition === 'around') && <RepeaterAddItemButton index="first"
|
|
130
|
+
{(addButtonPosition === 'before' || addButtonPosition === 'around') && <RepeaterAddItemButton index="first">{addButtonLabel}</RepeaterAddItemButton>}
|
|
130
131
|
<RepeaterEmpty>
|
|
131
132
|
<RepeaterEmptyUI>
|
|
132
133
|
{dict.repeater.empty}
|
|
@@ -137,7 +138,7 @@ const DefaultRepeaterInner = Component<DefaultRepeaterProps>(({ title, children,
|
|
|
137
138
|
{children}
|
|
138
139
|
</RepeaterItemUI>
|
|
139
140
|
</RepeaterEachItem>
|
|
140
|
-
{(addButtonPosition === 'after' || addButtonPosition === 'around') && <RepeaterAddItemButton
|
|
141
|
+
{(addButtonPosition === 'after' || addButtonPosition === 'around') && <RepeaterAddItemButton>{addButtonLabel}</RepeaterAddItemButton>}
|
|
141
142
|
</RepeaterWrapperUI>
|
|
142
143
|
</Repeater>
|
|
143
144
|
)
|
|
@@ -146,7 +147,7 @@ const DefaultRepeaterInner = Component<DefaultRepeaterProps>(({ title, children,
|
|
|
146
147
|
<Repeater {...props}>
|
|
147
148
|
<RepeaterWrapperUI>
|
|
148
149
|
{title && <h3 className={'font-medium'}>{title}</h3>}
|
|
149
|
-
{(addButtonPosition === 'before' || addButtonPosition === 'around') && <RepeaterAddItemButton index="first"
|
|
150
|
+
{(addButtonPosition === 'before' || addButtonPosition === 'around') && <RepeaterAddItemButton index="first">{addButtonLabel}</RepeaterAddItemButton>}
|
|
150
151
|
<RepeaterSortable>
|
|
151
152
|
<RepeaterEmpty>
|
|
152
153
|
<RepeaterEmptyUI>
|
|
@@ -155,16 +156,16 @@ const DefaultRepeaterInner = Component<DefaultRepeaterProps>(({ title, children,
|
|
|
155
156
|
</RepeaterEmpty>
|
|
156
157
|
<RepeaterSortableEachItem>
|
|
157
158
|
<div>
|
|
158
|
-
<RepeaterDropIndicator position={'before'}/>
|
|
159
|
+
<RepeaterDropIndicator position={'before'} />
|
|
159
160
|
<RepeaterSortableItemNode>
|
|
160
161
|
<RepeaterItemUI>
|
|
161
162
|
<RepeaterSortableItemActivator>
|
|
162
|
-
<RepeaterHandleUI/>
|
|
163
|
+
<RepeaterHandleUI />
|
|
163
164
|
</RepeaterSortableItemActivator>
|
|
164
165
|
{children}
|
|
165
166
|
</RepeaterItemUI>
|
|
166
167
|
</RepeaterSortableItemNode>
|
|
167
|
-
<RepeaterDropIndicator position={'after'}/>
|
|
168
|
+
<RepeaterDropIndicator position={'after'} />
|
|
168
169
|
</div>
|
|
169
170
|
</RepeaterSortableEachItem>
|
|
170
171
|
<RepeaterSortableDragOverlay>
|
|
@@ -174,10 +175,10 @@ const DefaultRepeaterInner = Component<DefaultRepeaterProps>(({ title, children,
|
|
|
174
175
|
</RepeaterSortableDragOverlay>
|
|
175
176
|
</RepeaterSortable>
|
|
176
177
|
|
|
177
|
-
{(addButtonPosition === 'after' || addButtonPosition === 'around') && <RepeaterAddItemButton
|
|
178
|
+
{(addButtonPosition === 'after' || addButtonPosition === 'around') && <RepeaterAddItemButton>{addButtonLabel}</RepeaterAddItemButton>}
|
|
178
179
|
</RepeaterWrapperUI>
|
|
179
180
|
</Repeater>
|
|
180
181
|
)
|
|
181
182
|
}, props => {
|
|
182
|
-
return <Repeater {...props}/>
|
|
183
|
+
return <Repeater {...props} />
|
|
183
184
|
})
|
|
@@ -430,13 +430,13 @@ export const sidebarMenuButtonVariants = cva(
|
|
|
430
430
|
},
|
|
431
431
|
)
|
|
432
432
|
|
|
433
|
-
type SidebarMenuButtonProps = ComponentProps<'
|
|
433
|
+
type SidebarMenuButtonProps = ComponentProps<'a'> & {
|
|
434
434
|
asChild?: boolean
|
|
435
435
|
isActive?: boolean
|
|
436
436
|
tooltip?: ReactNode
|
|
437
437
|
} & VariantProps<typeof sidebarMenuButtonVariants>
|
|
438
438
|
|
|
439
|
-
export const SidebarMenuButton = forwardRef<
|
|
439
|
+
export const SidebarMenuButton = forwardRef<HTMLAnchorElement, SidebarMenuButtonProps>(
|
|
440
440
|
(
|
|
441
441
|
{
|
|
442
442
|
asChild = false,
|
|
@@ -449,7 +449,7 @@ export const SidebarMenuButton = forwardRef<HTMLButtonElement, SidebarMenuButton
|
|
|
449
449
|
},
|
|
450
450
|
ref,
|
|
451
451
|
) => {
|
|
452
|
-
const Comp = asChild ? Slot : '
|
|
452
|
+
const Comp = asChild ? Slot : 'a'
|
|
453
453
|
const { isMobile, state } = useSidebar()
|
|
454
454
|
|
|
455
455
|
const button = (
|