@contember/create 2.0.0-alpha.9 → 2.0.0-beta.2

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.
Files changed (146) hide show
  1. package/dist/development/run.cjs +0 -2
  2. package/dist/development/run.cjs.map +1 -1
  3. package/dist/development/run.js +0 -2
  4. package/dist/development/run.js.map +1 -1
  5. package/dist/development/src/commands/WorkspaceCreateCommand.cjs.map +1 -1
  6. package/dist/development/src/commands/WorkspaceCreateCommand.js.map +1 -1
  7. package/dist/development/src/lib/FileSystem.cjs.map +1 -1
  8. package/dist/development/src/lib/FileSystem.js.map +1 -1
  9. package/dist/development/src/lib/TemplateInstaller.cjs +1 -8
  10. package/dist/development/src/lib/TemplateInstaller.cjs.map +1 -1
  11. package/dist/development/src/lib/TemplateInstaller.js +2 -9
  12. package/dist/development/src/lib/TemplateInstaller.js.map +1 -1
  13. package/dist/development/src/lib/version.cjs.map +1 -1
  14. package/dist/development/src/paths.cjs +3 -1
  15. package/dist/development/src/paths.cjs.map +1 -1
  16. package/dist/development/src/paths.js +4 -2
  17. package/dist/development/src/paths.js.map +1 -1
  18. package/dist/production/run.cjs +0 -2
  19. package/dist/production/run.cjs.map +1 -1
  20. package/dist/production/run.js +0 -2
  21. package/dist/production/run.js.map +1 -1
  22. package/dist/production/src/commands/WorkspaceCreateCommand.cjs.map +1 -1
  23. package/dist/production/src/commands/WorkspaceCreateCommand.js.map +1 -1
  24. package/dist/production/src/lib/FileSystem.cjs.map +1 -1
  25. package/dist/production/src/lib/FileSystem.js.map +1 -1
  26. package/dist/production/src/lib/TemplateInstaller.cjs +1 -8
  27. package/dist/production/src/lib/TemplateInstaller.cjs.map +1 -1
  28. package/dist/production/src/lib/TemplateInstaller.js +2 -9
  29. package/dist/production/src/lib/TemplateInstaller.js.map +1 -1
  30. package/dist/production/src/lib/version.cjs.map +1 -1
  31. package/dist/production/src/paths.cjs +3 -1
  32. package/dist/production/src/paths.cjs.map +1 -1
  33. package/dist/production/src/paths.js +4 -2
  34. package/dist/production/src/paths.js.map +1 -1
  35. package/dist/types/lib/TemplateInstaller.d.ts +1 -3
  36. package/dist/types/lib/TemplateInstaller.d.ts.map +1 -1
  37. package/dist/types/paths.d.ts.map +1 -1
  38. package/dist/types/tsconfig.tsbuildinfo +1 -1
  39. package/package.json +7 -31
  40. package/resources/templates/template-workspace/.github/scripts/setup-actions-variables.sh +36 -0
  41. package/resources/templates/template-workspace/.github/workflows/deploy.yaml +23 -0
  42. package/resources/templates/template-workspace/admin/lib/binding/binding.tsx +12 -2
  43. package/resources/templates/template-workspace/admin/lib/binding/delete.tsx +34 -23
  44. package/resources/templates/template-workspace/admin/lib/binding/hooks.tsx +5 -6
  45. package/resources/templates/template-workspace/admin/lib/binding/identity.tsx +34 -3
  46. package/resources/templates/template-workspace/admin/lib/binding/navigation-guard-dialog.tsx +39 -0
  47. package/resources/templates/template-workspace/admin/lib/binding/persist.tsx +10 -60
  48. package/resources/templates/template-workspace/admin/lib/block-repeater/block-repeater.tsx +109 -39
  49. package/resources/templates/template-workspace/admin/lib/buttons/link-back-button.tsx +1 -1
  50. package/resources/templates/template-workspace/admin/lib/datagrid/cells.tsx +90 -10
  51. package/resources/templates/template-workspace/admin/lib/datagrid/column-header.tsx +12 -4
  52. package/resources/templates/template-workspace/admin/lib/datagrid/column-leaf.tsx +21 -0
  53. package/resources/templates/template-workspace/admin/lib/datagrid/columns.tsx +367 -36
  54. package/resources/templates/template-workspace/admin/lib/datagrid/elements.tsx +6 -0
  55. package/resources/templates/template-workspace/admin/lib/datagrid/export.tsx +9 -0
  56. package/resources/templates/template-workspace/admin/lib/datagrid/filters/boolean.tsx +22 -5
  57. package/resources/templates/template-workspace/admin/lib/datagrid/filters/common.tsx +3 -0
  58. package/resources/templates/template-workspace/admin/lib/datagrid/filters/date.tsx +25 -2
  59. package/resources/templates/template-workspace/admin/lib/datagrid/filters/defined.tsx +103 -0
  60. package/resources/templates/template-workspace/admin/lib/datagrid/filters/enum.tsx +83 -27
  61. package/resources/templates/template-workspace/admin/lib/datagrid/filters/index.ts +1 -1
  62. package/resources/templates/template-workspace/admin/lib/datagrid/filters/mobile.tsx +0 -1
  63. package/resources/templates/template-workspace/admin/lib/datagrid/filters/number.tsx +21 -5
  64. package/resources/templates/template-workspace/admin/lib/datagrid/filters/relation.tsx +170 -43
  65. package/resources/templates/template-workspace/admin/lib/datagrid/filters/text.tsx +48 -5
  66. package/resources/templates/template-workspace/admin/lib/datagrid/grid.tsx +97 -25
  67. package/resources/templates/template-workspace/admin/lib/datagrid/index.ts +30 -4
  68. package/resources/templates/template-workspace/admin/lib/datagrid/labels.tsx +31 -0
  69. package/resources/templates/template-workspace/admin/lib/datagrid/layout-switcher.tsx +3 -0
  70. package/resources/templates/template-workspace/admin/lib/datagrid/loader.tsx +44 -2
  71. package/resources/templates/template-workspace/admin/lib/datagrid/pagination.tsx +8 -0
  72. package/resources/templates/template-workspace/admin/lib/datagrid/table.tsx +15 -1
  73. package/resources/templates/template-workspace/admin/lib/datagrid/tiles.tsx +13 -0
  74. package/resources/templates/template-workspace/admin/lib/datagrid/toolbar.tsx +27 -2
  75. package/resources/templates/template-workspace/admin/lib/dict.ts +54 -5
  76. package/resources/templates/template-workspace/admin/lib/dimensions/dimensions.tsx +1 -1
  77. package/resources/templates/template-workspace/admin/lib/editor/common/editor-canvas.tsx +2 -2
  78. package/resources/templates/template-workspace/admin/lib/editor/index.ts +1 -0
  79. package/resources/templates/template-workspace/admin/lib/editor/rich-text-view.tsx +17 -0
  80. package/resources/templates/template-workspace/admin/lib/field/formatted-field.tsx +10 -0
  81. package/resources/templates/template-workspace/admin/lib/field/index.ts +1 -0
  82. package/resources/templates/template-workspace/admin/lib/form/container.tsx +43 -45
  83. package/resources/templates/template-workspace/admin/lib/form/index.ts +1 -0
  84. package/resources/templates/template-workspace/admin/lib/form/inputs.tsx +56 -23
  85. package/resources/templates/template-workspace/admin/lib/form/select.tsx +61 -30
  86. package/resources/templates/template-workspace/admin/lib/form/ui.tsx +11 -2
  87. package/resources/templates/template-workspace/admin/lib/form/upload-repeaters.tsx +188 -0
  88. package/resources/templates/template-workspace/admin/lib/form/upload.tsx +57 -242
  89. package/resources/templates/template-workspace/admin/lib/formatting/formatting.ts +23 -0
  90. package/resources/templates/template-workspace/admin/lib/labels/enum-labels.ts +9 -0
  91. package/resources/templates/template-workspace/admin/lib/labels/field-labels.ts +7 -0
  92. package/resources/templates/template-workspace/admin/lib/labels/index.ts +2 -0
  93. package/resources/templates/template-workspace/admin/lib/layout/layout.tsx +3 -3
  94. package/resources/templates/template-workspace/admin/lib/repeater/repeater.tsx +97 -64
  95. package/resources/templates/template-workspace/admin/lib/select/filter.tsx +3 -2
  96. package/resources/templates/template-workspace/admin/lib/select/index.ts +0 -1
  97. package/resources/templates/template-workspace/admin/lib/select/list.tsx +78 -26
  98. package/resources/templates/template-workspace/admin/lib/select/multi-select.tsx +12 -19
  99. package/resources/templates/template-workspace/admin/lib/select/select.tsx +40 -23
  100. package/resources/templates/template-workspace/admin/lib/select/sortable-select.tsx +23 -18
  101. package/resources/templates/template-workspace/admin/lib/select/ui.tsx +3 -0
  102. package/resources/templates/template-workspace/admin/lib/tenant/forms/invite.tsx +5 -3
  103. package/resources/templates/template-workspace/admin/lib/tenant/forms/memberships-control.tsx +28 -16
  104. package/resources/templates/template-workspace/admin/lib/tenant/forms/password-reset.tsx +9 -6
  105. package/resources/templates/template-workspace/admin/lib/tenant/forms/passwordless-signin-init.tsx +31 -0
  106. package/resources/templates/template-workspace/admin/lib/tenant/forms/passwordless-signin.tsx +59 -0
  107. package/resources/templates/template-workspace/admin/lib/tenant/forms/update-project-member.tsx +5 -3
  108. package/resources/templates/template-workspace/admin/lib/tenant/hooks/useInvite.ts +1 -1
  109. package/resources/templates/template-workspace/admin/lib/tenant/listing/member-list.tsx +6 -5
  110. package/resources/templates/template-workspace/admin/lib/tenant/listing/person-list.tsx +2 -1
  111. package/resources/templates/template-workspace/admin/lib/ui/alert-dialog.tsx +2 -1
  112. package/resources/templates/template-workspace/admin/lib/ui/collapsible.tsx +9 -0
  113. package/resources/templates/template-workspace/admin/lib/ui/dialog.tsx +2 -1
  114. package/resources/templates/template-workspace/admin/lib/ui/dropdown.tsx +2 -1
  115. package/resources/templates/template-workspace/admin/lib/ui/input.tsx +14 -10
  116. package/resources/templates/template-workspace/admin/lib/ui/menu.tsx +2 -3
  117. package/resources/templates/template-workspace/admin/lib/ui/popover.tsx +2 -1
  118. package/resources/templates/template-workspace/admin/lib/ui/property-list.tsx +33 -0
  119. package/resources/templates/template-workspace/admin/lib/ui/select.tsx +80 -0
  120. package/resources/templates/template-workspace/admin/lib/ui/sheet.tsx +3 -2
  121. package/resources/templates/template-workspace/admin/lib/ui/textarea.tsx +9 -1
  122. package/resources/templates/template-workspace/admin/lib/upload/view.tsx +160 -165
  123. package/resources/templates/template-workspace/admin/lib/utils/createComponentOpenHooks.tsx +38 -0
  124. package/resources/templates/template-workspace/admin/lib/utils/uic.tsx +3 -3
  125. package/resources/templates/template-workspace/admin/package.json +21 -20
  126. package/resources/templates/template-workspace/package.json +3 -3
  127. package/src/lib/TemplateInstaller.ts +2 -9
  128. package/src/paths.ts +4 -3
  129. package/src/run.ts +0 -2
  130. package/tsconfig.settings.json +0 -4
  131. package/dist/development/src/lib/PackageDownloader.cjs +0 -33
  132. package/dist/development/src/lib/PackageDownloader.cjs.map +0 -1
  133. package/dist/development/src/lib/PackageDownloader.js +0 -33
  134. package/dist/development/src/lib/PackageDownloader.js.map +0 -1
  135. package/dist/production/src/lib/PackageDownloader.cjs +0 -33
  136. package/dist/production/src/lib/PackageDownloader.cjs.map +0 -1
  137. package/dist/production/src/lib/PackageDownloader.js +0 -33
  138. package/dist/production/src/lib/PackageDownloader.js.map +0 -1
  139. package/dist/types/lib/PackageDownloader.d.ts +0 -7
  140. package/dist/types/lib/PackageDownloader.d.ts.map +0 -1
  141. package/resources/templates/template-workspace/admin/.env.production +0 -3
  142. package/resources/templates/template-workspace/admin/lib/select/pagination.tsx +0 -48
  143. package/src/lib/PackageDownloader.ts +0 -33
  144. package/types/download-tarball/index.d.ts +0 -7
  145. package/types/get-package-json-from-registry/index.d.ts +0 -3
  146. package/types/registry-info/index.d.ts +0 -7
@@ -1,5 +1,5 @@
1
1
  import * as React from 'react'
2
- import { forwardRef, ReactNode, useCallback } from 'react'
2
+ import { forwardRef, ReactNode, useCallback, useMemo } from 'react'
3
3
  import { Tooltip, TooltipContent, TooltipProvider, TooltipTrigger } from '../../ui/tooltip'
4
4
  import {
5
5
  DataViewHasManyFilter,
@@ -9,55 +9,97 @@ import {
9
9
  DataViewNullFilterTrigger,
10
10
  DataViewRelationFilterList,
11
11
  DataViewRelationFilterOptions,
12
- DataViewRelationFilterTrigger, DataViewUnionFilterFields,
12
+ DataViewRelationFilterTrigger,
13
+ DataViewUnionFilterFields,
13
14
  useDataViewFilterName,
14
15
  useDataViewRelationFilterFactory,
15
16
  UseDataViewRelationFilterResult,
16
17
  } from '@contember/react-dataview'
17
18
  import { Component, EntityId, StaticRender, useEntity } from '@contember/interface'
18
19
  import { Popover, PopoverTrigger } from '../../ui/popover'
19
- import { DataGridActiveFilterUI, DataGridExcludeActionButtonUI, DataGridFilterActionButtonUI, DataGridFilterSelectItemUI, DataGridFilterSelectTriggerUI, DataGridSingleFilterUI } from '../ui'
20
+ import {
21
+ DataGridActiveFilterUI,
22
+ DataGridExcludeActionButtonUI,
23
+ DataGridFilterActionButtonUI,
24
+ DataGridFilterSelectItemUI,
25
+ DataGridFilterSelectTriggerUI,
26
+ DataGridSingleFilterUI,
27
+ } from '../ui'
20
28
  import { DataGridNullFilter } from './common'
21
29
  import { SelectDefaultFilter, SelectListInner, SelectPopoverContent } from '../../select'
22
30
  import { dict } from '../../dict'
23
31
  import { DataGridFilterMobileHiding } from './mobile'
32
+ import { DataViewHasManyLabel, DataViewHasOneLabel } from '../labels'
33
+ import { createRequiredContext } from '@contember/react-utils'
24
34
 
25
-
26
- type DataGridRelationFilterInnerProps = {
27
- children: ReactNode
28
- label: ReactNode
29
- }
30
-
35
+ /**
36
+ * Props for {@link DataGridHasOneFilter}.
37
+ */
31
38
  export type DataGridHasOneFilterProps =
32
39
  & DataViewHasOneFilterProps
33
- & DataGridRelationFilterInnerProps
34
-
40
+ & {
41
+ children: ReactNode
42
+ label: ReactNode
43
+ }
44
+ /**
45
+ * Has one filter for DataGrid with default UI.
46
+ *
47
+ * ## Props {@link DataGridHasOneFilterProps}
48
+ * field, label, children, ?name, ?options
49
+ *
50
+ * ## Example
51
+ * ```tsx
52
+ * <DataGridHasOneFilter field={'author'} label="Author">
53
+ * <Field field="name" />
54
+ * </DataGridHasOneFilter>
55
+ * ```
56
+ */
35
57
  export const DataGridHasOneFilter = Component(({ label, children, ...props }: DataGridHasOneFilterProps) => (
36
58
  <DataViewHasOneFilter {...props}>
37
59
  <DataGridFilterMobileHiding>
38
- <DataGridRelationFilterInner label={label}>
60
+ <DataGridRelationFilterInner label={label ?? <DataViewHasOneLabel field={props.field} />}>
39
61
  {children}
40
62
  </DataGridRelationFilterInner>
41
63
  </DataGridFilterMobileHiding>
42
64
  </DataViewHasOneFilter>
43
65
  ))
44
66
 
45
-
67
+ /**
68
+ * Props for {@link DataGridHasManyFilter}.
69
+ */
46
70
  export type DataGridHasManyFilterProps =
47
71
  & DataViewHasManyFilterProps
48
- & DataGridRelationFilterInnerProps
49
-
72
+ & {
73
+ children: ReactNode
74
+ label: ReactNode
75
+ }
76
+ /**
77
+ * Has many filter for DataGrid with default UI.
78
+ *
79
+ * ## Props {@link DataGridHasManyFilterProps}
80
+ * field, label, children, ?name, ?options
81
+ *
82
+ * ## Example
83
+ * ```tsx
84
+ * <DataGridHasManyFilter field={'tags'} label="Tags">
85
+ * <Field field="name" />
86
+ * </DataGridHasManyFilter>
87
+ * ```
88
+ */
50
89
  export const DataGridHasManyFilter = Component(({ label, children, ...props }: DataGridHasManyFilterProps) => (
51
90
  <DataViewHasManyFilter {...props} >
52
91
  <DataGridFilterMobileHiding>
53
- <DataGridRelationFilterInner label={label}>
92
+ <DataGridRelationFilterInner label={label ?? <DataViewHasManyLabel field={props.field} />}>
54
93
  {children}
55
94
  </DataGridRelationFilterInner>
56
95
  </DataGridFilterMobileHiding>
57
96
  </DataViewHasManyFilter>
58
97
  ))
59
98
 
60
- const DataGridRelationFilterInner = Component(({ children, label }: DataGridRelationFilterInnerProps) => {
99
+ const DataGridRelationFilterInner = Component(({ children, label }: {
100
+ children: ReactNode
101
+ label: ReactNode
102
+ }) => {
61
103
  return (
62
104
  <DataGridSingleFilterUI>
63
105
  <DataGridRelationFilterSelect label={label}>
@@ -70,7 +112,39 @@ const DataGridRelationFilterInner = Component(({ children, label }: DataGridRela
70
112
  )
71
113
  }, () => null)
72
114
 
73
- export const DataGridHasOneTooltip = Component(({ children, actions, ...props }: DataViewHasOneFilterProps & { children: ReactNode; actions?: ReactNode }) => (<>
115
+ /**
116
+ * Props for {@link DataGridHasOneTooltip}.
117
+ */
118
+ export type DataGridHasOneTooltipProps =
119
+ & DataViewHasOneFilterProps
120
+ & {
121
+ children: ReactNode
122
+ /**
123
+ * Custom actions to render in the tooltip.
124
+ */
125
+ actions?: ReactNode
126
+ }
127
+
128
+ /**
129
+ * Component for rendering a value with a tooltip that allows to include/exclude the value from the filter.
130
+ * Used in DataGridHasOneColumn, but can be used in custom columns as well.
131
+ *
132
+ * ## Props {@link DataGridHasOneTooltipProps}
133
+ * field, children, ?name, ?options, ?actions
134
+ *
135
+ * ## Example
136
+ * ```tsx
137
+ * <HasOne field="category">
138
+ * <DataGridHasOneTooltip field={'category'}>
139
+ * <button className="text-lg font-semibold text-gray-600">
140
+ * <Field field="category.name" />
141
+ * </button>
142
+ * </button>
143
+ * </DataGridHasOneTooltip>
144
+ * </HasOne>
145
+ * ```
146
+ */
147
+ export const DataGridHasOneTooltip = Component<DataGridHasOneTooltipProps>(({ children, actions, ...props }) => (<>
74
148
  <DataViewHasOneFilter {...props}>
75
149
  <DataGridRelationFieldTooltipInner actions={actions}>
76
150
  {children}
@@ -81,7 +155,38 @@ export const DataGridHasOneTooltip = Component(({ children, actions, ...props }:
81
155
  </StaticRender>
82
156
  </>))
83
157
 
84
- export const DataGridHasManyTooltip = Component<DataViewHasManyFilterProps & { children: ReactNode; actions?: ReactNode }>(({ children, actions, ...props }, env) => {
158
+ /**
159
+ * Props for {@link DataGridHasManyTooltip}.
160
+ */
161
+ export type DataGridHasManyTooltipProps =
162
+ & DataViewHasManyFilterProps
163
+ & {
164
+ children: ReactNode
165
+ /**
166
+ * Custom actions to render in the tooltip.
167
+ */
168
+ actions?: ReactNode
169
+ }
170
+
171
+ /**
172
+ * Component for rendering a value with a tooltip that allows to include/exclude the value from the filter.
173
+ * Used in DataGridHasManyColumn, but can be used in custom columns as well.
174
+ *
175
+ * ## Props {@link DataGridHasManyTooltipProps}
176
+ * field, children, ?name, ?options, ?actions
177
+ *
178
+ * ## Example
179
+ * ```tsx
180
+ * <HasMany field="tags">
181
+ * <DataGridHasManyTooltip field={'tags'}>
182
+ * <button className="text-sm border rounded px-2 py-1">
183
+ * <Field field="name" />
184
+ * </button>
185
+ * </DataGridHasManyTooltip>
186
+ * </HasMany>
187
+ * ```
188
+ */
189
+ export const DataGridHasManyTooltip = Component<DataGridHasManyTooltipProps>(({ children, actions, ...props }) => {
85
190
  return (<>
86
191
  <DataViewHasManyFilter {...props}>
87
192
  <DataGridRelationFieldTooltipInner actions={actions}>
@@ -115,6 +220,9 @@ const DataGridRelationFieldTooltipInner = Component(({ children, actions }: { ch
115
220
  </TooltipProvider>
116
221
  ))
117
222
 
223
+ /**
224
+ * @internal
225
+ */
118
226
  export const DataGridRelationFilteredItemsList = ({ children }: {
119
227
  children: ReactNode
120
228
  }) => (
@@ -134,28 +242,34 @@ export const DataGridRelationFilteredItemsList = ({ children }: {
134
242
  </>
135
243
  )
136
244
 
137
- const DataGridRelationFilterSelectItem = forwardRef<HTMLButtonElement, {
245
+ const [, useFilterFactory, FilterFactoryContextProvider] = createRequiredContext<(value: EntityId) => UseDataViewRelationFilterResult>('FilterFactoryContext')
246
+
247
+ type DataGridRelationFilterSelectItemProps = {
138
248
  children: ReactNode
139
- filterFactory: (value: EntityId) => UseDataViewRelationFilterResult
140
- }>(({ children, filterFactory, ...props }, ref) => {
141
- const entity = useEntity()
142
- const [current, setFilter] = filterFactory(entity.id)
249
+ }
250
+ const DataGridRelationFilterSelectItem = forwardRef<HTMLButtonElement, DataGridRelationFilterSelectItemProps>(({
251
+ children,
252
+ ...props
253
+ }, ref) => {
254
+ const entity = useEntity()
255
+ const filterFactory = useFilterFactory()
256
+ const [current, setFilter] = filterFactory(entity.id)
143
257
 
144
- const include = useCallback(() => setFilter('toggleInclude'), [setFilter])
145
- const exclude = useCallback(() => setFilter('toggleExclude'), [setFilter])
258
+ const include = useCallback(() => setFilter('toggleInclude'), [setFilter])
259
+ const exclude = useCallback(() => setFilter('toggleExclude'), [setFilter])
146
260
 
147
- const isIncluded = current === 'include'
148
- const isExcluded = current == 'exclude'
261
+ const isIncluded = current === 'include'
262
+ const isExcluded = current === 'exclude'
149
263
 
150
- return (
151
- <DataGridFilterSelectItemUI ref={ref} onExclude={exclude} onInclude={include} isExcluded={isExcluded} isIncluded={isIncluded} {...props}>
152
- {children}
153
- </DataGridFilterSelectItemUI>
154
- )
155
- })
264
+ return (
265
+ <DataGridFilterSelectItemUI ref={ref} onExclude={exclude} onInclude={include} isExcluded={isExcluded} isIncluded={isIncluded} {...props}>
266
+ {children}
267
+ </DataGridFilterSelectItemUI>
268
+ )
269
+ })
156
270
 
157
271
 
158
- export const DataGridRelationFilterSelect = ({ children, queryField, label }: {
272
+ const DataGridRelationFilterSelect = ({ children, queryField, label }: {
159
273
  queryField?: DataViewUnionFilterFields
160
274
  children: ReactNode
161
275
  label?: ReactNode
@@ -176,24 +290,37 @@ export const DataGridRelationFilterSelect = ({ children, queryField, label }: {
176
290
  )
177
291
  }
178
292
 
179
-
293
+ /**
294
+ * @internal
295
+ */
180
296
  export const DataGridRelationFilterControls = ({ children, queryField }: {
181
297
  queryField?: DataViewUnionFilterFields
182
298
  children: ReactNode
183
299
  }) => {
300
+ const inner = useMemo(() => <DataGridRelationFilterControlsInner>{children}</DataGridRelationFilterControlsInner>, [children])
184
301
  const filterFactory = useDataViewRelationFilterFactory(useDataViewFilterName())
185
302
  return (
186
- <>
303
+ <FilterFactoryContextProvider value={filterFactory}>
187
304
  <DataViewRelationFilterOptions queryField={queryField}>
188
- <SelectListInner filterToolbar={<SelectDefaultFilter />}>
189
- <DataGridRelationFilterSelectItem filterFactory={filterFactory}>
190
- {children}
191
- </DataGridRelationFilterSelectItem>
192
- </SelectListInner>
305
+ {inner}
193
306
  </DataViewRelationFilterOptions>
194
307
  <div>
195
308
  <DataGridNullFilter />
196
309
  </div>
197
- </>
310
+ </FilterFactoryContextProvider>
198
311
  )
199
312
  }
313
+
314
+ type DataGridRelationFilterControlsInnerProps = {
315
+ children: ReactNode
316
+ }
317
+ const DataGridRelationFilterControlsInner = Component<DataGridRelationFilterControlsInnerProps>(({ children }) => {
318
+
319
+ return <>
320
+ <SelectListInner filterToolbar={<SelectDefaultFilter />}>
321
+ <DataGridRelationFilterSelectItem>
322
+ {children}
323
+ </DataGridRelationFilterSelectItem>
324
+ </SelectListInner>
325
+ </>
326
+ })
@@ -24,28 +24,56 @@ import { DataGridNullFilter } from './common'
24
24
  import { dict } from '../../dict'
25
25
  import { Component } from '@contember/interface'
26
26
  import { DataGridFilterMobileHiding } from './mobile'
27
+ import { DataViewFieldLabel } from '../labels'
27
28
 
28
-
29
+ /**
30
+ * Props for {@link DataGridTextFilter}.
31
+ */
29
32
  export type DataGridTextFilterProps =
30
33
  & Omit<DataViewTextFilterProps, 'children'>
31
34
  & {
32
35
  label?: React.ReactNode
33
36
  }
34
37
 
38
+ /**
39
+ * Text filter for DataGrid with default UI.
40
+ *
41
+ * ## Props {@link DataGridTextFilterProps}
42
+ * field, label, ?name
43
+ *
44
+ * ## Example
45
+ * ```tsx
46
+ * <DataGridTextFilter field={'name'} label="Name" />
47
+ * ```
48
+ */
35
49
  export const DataGridTextFilter = Component(({ label, ...props }: DataGridTextFilterProps) => (
36
50
  <DataViewTextFilter {...props}>
37
51
  <DataGridFilterMobileHiding>
38
- <DataGridTextFilterInner label={label} />
52
+ <DataGridTextFilterInner label={label ?? <DataViewFieldLabel field={props.field} />} />
39
53
  </DataGridFilterMobileHiding>
40
54
  </DataViewTextFilter>
41
55
  ))
42
56
 
57
+ /**
58
+ * Props for {@link DataGridUnionTextFilter}.
59
+ */
43
60
  export type DataGridUnionTextFilterProps =
44
61
  & Omit<DataViewUnionTextFilterProps, 'children'>
45
62
  & {
46
63
  label?: React.ReactNode
47
64
  }
48
65
 
66
+ /**
67
+ * Text filter which filters multiple fields at once for DataGrid with default UI.
68
+ *
69
+ * ## Props {@link DataGridUnionTextFilterProps}
70
+ * fields, label, ?name
71
+ *
72
+ * ## Example
73
+ * ```tsx
74
+ * <DataGridUnionTextFilter fields={['name', 'description']} label="Name or description" />
75
+ * ```
76
+ */
49
77
  export const DataGridUnionTextFilter = Component(({ label, ...props }: DataGridUnionTextFilterProps) => (
50
78
  <DataViewUnionTextFilter {...props}>
51
79
  <DataGridFilterMobileHiding>
@@ -53,10 +81,22 @@ export const DataGridUnionTextFilter = Component(({ label, ...props }: DataGridU
53
81
  </DataGridFilterMobileHiding>
54
82
  </DataViewUnionTextFilter>
55
83
  ))
56
-
57
- export const DataGridQueryFilter = Component(({ label }: {
84
+ /**
85
+ * Props for {@link DataGridQueryFilter}.
86
+ */
87
+ export type DataGridQueryFilterProps = {
58
88
  label?: React.ReactNode
59
- }) => (
89
+ }
90
+
91
+ /**
92
+ * Universal text filter for DataGrid with default UI. By default, it filters all text fields.
93
+ *
94
+ * ## Example
95
+ * ```tsx
96
+ * <DataGridQueryFilter label="Search" />
97
+ * ```
98
+ */
99
+ export const DataGridQueryFilter = Component(({ label }: DataGridQueryFilterProps) => (
60
100
  <DataViewHasFilterType name={DataViewQueryFilterName}>
61
101
  <DataViewFilterScope name={DataViewQueryFilterName}>
62
102
  <DataGridFilterMobileHiding>
@@ -66,6 +106,9 @@ export const DataGridQueryFilter = Component(({ label }: {
66
106
  </DataViewHasFilterType>
67
107
  ))
68
108
 
109
+ /**
110
+ * @internal
111
+ */
69
112
  export const DataGridTextFilterInner = ({ label }: {
70
113
  label?: React.ReactNode
71
114
  }) => {
@@ -1,17 +1,22 @@
1
- import { DataView, DataViewLoaderState, DataViewProps } from '@contember/react-dataview'
1
+ import { DataView, DataViewProps } from '@contember/react-dataview'
2
2
  import * as React from 'react'
3
- import { Fragment, ReactNode } from 'react'
4
- import { DataGridInitialLoader, DataGridOverlayLoader } from './loader'
3
+ import { ReactNode } from 'react'
5
4
  import { Component } from '@contember/interface'
5
+ import { DataGridToolbar } from './toolbar'
6
+ import { DataGridLoader } from './loader'
7
+ import { DataGridTable } from './table'
8
+ import { DataGridPagination } from './pagination'
6
9
 
7
-
10
+ /**
11
+ * Props for {@link DataGrid}.
12
+ */
8
13
  export type DataGridProps =
9
- & Omit<DataViewProps, 'children' | 'filterTypes'>
14
+ & Omit<DataViewProps, 'children'>
10
15
  & {
11
16
  children: ReactNode
12
17
  }
13
18
 
14
- export const dataGridDefaultStorages: Partial<DataGridProps> = {
19
+ const dataGridDefaultStorages: Partial<DataGridProps> = {
15
20
  filteringStateStorage: 'session',
16
21
  sortingStateStorage: 'session',
17
22
  currentPageStateStorage: 'session',
@@ -19,35 +24,102 @@ export const dataGridDefaultStorages: Partial<DataGridProps> = {
19
24
  pagingSettingsStorage: 'local',
20
25
  }
21
26
 
27
+ /**
28
+ * Base DataGrid component. The UI is up to you.
29
+ *
30
+ * ## Props {@link DataGridProps}
31
+ * Primary: children, entities
32
+ * Optional: queryField, filterTypes, dataViewKey, onSelectHighlighted
33
+ * Initial values: initialFilters, initialSorting, initialSelection, initialItemsPerPage
34
+ * Storage settings: filteringStateStorage, sortingStateStorage, currentPageStateStorage, selectionStateStorage, pagingSettingsStorage
35
+ *
36
+ * ## Example
37
+ * ```tsx
38
+ * <DataGrid
39
+ * entities="GridArticle"
40
+ * initialSorting={{
41
+ * publishedAt: 'asc',
42
+ * }}
43
+ * >
44
+ * <DataGridToolbar>
45
+ * <DataGridQueryFilter />
46
+ * <DataGridEnumFilter field={'state'} />
47
+ * <DataGridHasOneFilter field={'author'} label="Author">
48
+ * <Field field="name" />
49
+ * </DataGridHasOneFilter>
50
+ * </DataGridToolbar>
51
+ * <DataGridLoader>
52
+ * <DataGridTable>
53
+ * <DataGridActionColumn><Button>Show detail</Button></DataGridActionColumn>
54
+ * <DataGridTextColumn header="Title" field="title" />
55
+ * <DataGridEnumColumn field="state" />
56
+ * <DataGridDateColumn header="Published at" field="publishedAt" />
57
+ * <DataGridHasOneColumn header="Author" field="author">
58
+ * <Field field="name" />
59
+ * </DataGridHasOneColumn>
60
+ * </DataGridTable>
61
+ * <DataGridTiles>
62
+ * <MyCustomTile />
63
+ * </DataGridTiles>
64
+ * <DataViewLayout name="rows" label='Rows'>
65
+ * <DataViewEachRow>
66
+ * <MyCustomRow />
67
+ * </DataViewEachRow>
68
+ * </DataViewLayout>
69
+ * </DataGridLoader>
70
+ * <DataGridPagination />
71
+ * </DataGrid>
72
+ * ```
73
+ */
22
74
  export const DataGrid = Component(({ children, ...props }: DataGridProps) => {
23
75
  return (
24
76
  <DataView
25
77
  {...dataGridDefaultStorages}
26
78
  {...props}
27
79
  >
28
- {children}
80
+ <div>
81
+ {children}
82
+ </div>
29
83
  </DataView>
30
84
  )
31
85
  })
32
86
 
33
- export interface DataViewBodyProps {
34
- children: ReactNode
35
- }
87
+ /**
88
+ * Props for {@link DefaultDataGrid}.
89
+ */
90
+ export type DefaultDataGridProps =
91
+ & Omit<DataViewProps, 'children'>
92
+ & {
93
+ children: ReactNode
94
+ toolbar?: ReactNode
95
+ }
36
96
 
37
- export const DataGridLoader = ({ children }: DataViewBodyProps) => (
38
- <>
39
- <DataViewLoaderState refreshing loaded>
40
- <div className="relative">
41
- <DataViewLoaderState refreshing>
42
- <DataGridOverlayLoader />
43
- </DataViewLoaderState>
44
- {children}
45
- </div>
46
- </DataViewLoaderState>
47
- <DataViewLoaderState initial>
48
- <DataGridInitialLoader />
49
- </DataViewLoaderState>
50
- </>
51
- )
97
+ /**
98
+ * Default DataGrid with toolbar, loader, table and pagination.
99
+ *
100
+ * ## Example
101
+ * ```tsx
102
+ * <DefaultDataGrid entities="GridArticle">
103
+ * <DataGridActionColumn><Button>Show detail</Button></DataGridActionColumn>
104
+ * <DataGridTextColumn header="Title" field="title" />
105
+ * <DataGridEnumColumn header="State" field="state" options={GridArticleStateLabels} />
106
+ * </DefaultDataGrid>
107
+ * ```
108
+ */
109
+ export const DefaultDataGrid = Component(({ children, toolbar, ...props }: DefaultDataGridProps) => {
110
+ return (
111
+ <DataGrid {...props}>
112
+ <DataGridToolbar>
113
+ {toolbar}
114
+ </DataGridToolbar>
52
115
 
116
+ <DataGridLoader>
117
+ <DataGridTable>
118
+ {children}
119
+ </DataGridTable>
120
+ </DataGridLoader>
53
121
 
122
+ <DataGridPagination />
123
+ </DataGrid>
124
+ )
125
+ })
@@ -1,16 +1,42 @@
1
- export * from './filters'
1
+ export {
2
+ type DataGridBooleanFilterProps,
3
+ DataGridBooleanFilter,
4
+ type DataGridDateFilterProps,
5
+ DataGridDateFilter,
6
+ type DataGridPredefinedDateRange,
7
+ createDataGridDateRange,
8
+ type DataGridIsDefinedFilterProps,
9
+ DataGridIsDefinedFilter,
10
+ type DataGridEnumFilterProps,
11
+ DataGridEnumFilter,
12
+ type DataGridEnumFieldTooltipProps,
13
+ DataGridEnumFieldTooltip,
14
+ type DataGridNumberFilterProps,
15
+ DataGridNumberFilter,
16
+ type DataGridTextFilterProps,
17
+ DataGridTextFilter,
18
+ type DataGridUnionTextFilterProps,
19
+ DataGridUnionTextFilter,
20
+ type DataGridQueryFilterProps,
21
+ DataGridQueryFilter,
22
+ type DataGridHasManyFilterProps,
23
+ DataGridHasManyFilter,
24
+ type DataGridHasManyTooltipProps,
25
+ DataGridHasManyTooltip,
26
+ type DataGridHasOneFilterProps,
27
+ DataGridHasOneFilter,
28
+ type DataGridHasOneTooltipProps,
29
+ DataGridHasOneTooltip,
30
+ } from './filters'
2
31
 
3
32
  export * from './cells'
4
- export * from './column-header'
5
33
  export * from './columns'
6
- export * from './elements'
7
34
  export * from './empty'
8
35
  export * from './export'
9
36
  export * from './grid'
10
37
  export * from './layout-switcher'
11
38
  export * from './loader'
12
39
  export * from './pagination'
13
- export * from './ui'
14
40
  export * from './tiles'
15
41
  export * from './toolbar'
16
42
  export * from './table'
@@ -0,0 +1,31 @@
1
+ import { SugaredRelativeEntityList, SugaredRelativeSingleEntity, SugaredRelativeSingleField } from '@contember/interface'
2
+ import { useDataViewTargetFieldSchema, useDataViewTargetHasManySchema, useDataViewTargetHasOneSchema } from '@contember/react-dataview'
3
+ import { useFieldLabelFormatter } from '../labels'
4
+
5
+ /**
6
+ * Utility component that renders a label for a field.
7
+ */
8
+ export const DataViewFieldLabel = ({ field }: { field: SugaredRelativeSingleField['field'] }) => {
9
+ const { field: targetField, entity } = useDataViewTargetFieldSchema(field)
10
+ const formatter = useFieldLabelFormatter()
11
+ return <>{formatter(entity.name, targetField.name)}</>
12
+ }
13
+
14
+ /**
15
+ * Utility component that renders a label for a has-one relation.
16
+ */
17
+ export const DataViewHasOneLabel = ({ field }: { field: SugaredRelativeSingleEntity['field'] }) => {
18
+ const { field: targetField, entity } = useDataViewTargetHasOneSchema(field)
19
+ const formatter = useFieldLabelFormatter()
20
+ return <>{formatter(entity.name, targetField.name)}</>
21
+ }
22
+
23
+ /**
24
+ * Utility component that renders a label for a has-many relation.
25
+ */
26
+ export const DataViewHasManyLabel = ({ field }: { field: SugaredRelativeEntityList['field'] }) => {
27
+ const { field: targetField, entity } = useDataViewTargetHasManySchema(field)
28
+ const formatter = useFieldLabelFormatter()
29
+ return <>{formatter(entity.name, targetField.name)}</>
30
+ }
31
+
@@ -12,6 +12,9 @@ const LayoutSwitchButton = uic(Button, {
12
12
  },
13
13
  })
14
14
 
15
+ /**
16
+ * Layout switcher UI for data grid. Displays buttons for each layout.
17
+ */
15
18
  export const DataGridLayoutSwitcher = () => {
16
19
  const layouts = useDataViewSelectionState().layouts
17
20