@contember/create 1.4.0-rc.3 → 1.4.0-rc.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.
Files changed (223) hide show
  1. package/dist/src/commands/WorkspaceCreateCommand.d.ts +4 -3
  2. package/dist/src/commands/WorkspaceCreateCommand.d.ts.map +1 -1
  3. package/dist/src/commands/WorkspaceCreateCommand.js +10 -4
  4. package/dist/src/commands/WorkspaceCreateCommand.js.map +1 -1
  5. package/dist/src/lib/FileSystem.d.ts +14 -0
  6. package/dist/src/lib/FileSystem.d.ts.map +1 -0
  7. package/dist/src/lib/FileSystem.js +54 -0
  8. package/dist/src/lib/FileSystem.js.map +1 -0
  9. package/dist/src/lib/PackageDownloader.d.ts +7 -0
  10. package/dist/src/lib/PackageDownloader.d.ts.map +1 -0
  11. package/dist/src/lib/PackageDownloader.js +32 -0
  12. package/dist/src/lib/PackageDownloader.js.map +1 -0
  13. package/dist/src/lib/TemplateInstaller.d.ts +13 -0
  14. package/dist/src/lib/TemplateInstaller.d.ts.map +1 -0
  15. package/dist/src/lib/TemplateInstaller.js +75 -0
  16. package/dist/src/lib/TemplateInstaller.js.map +1 -0
  17. package/dist/src/lib/pathUtils.d.ts +3 -0
  18. package/dist/src/lib/pathUtils.d.ts.map +1 -0
  19. package/dist/src/lib/pathUtils.js +7 -0
  20. package/dist/src/lib/pathUtils.js.map +1 -0
  21. package/dist/src/run.js +7 -3
  22. package/dist/src/run.js.map +1 -1
  23. package/dist/src/tsconfig.tsbuildinfo +1 -1
  24. package/package.json +9 -3
  25. package/resources/templates/template-workspace/.gitignore.dist +3 -0
  26. package/resources/templates/template-workspace/admin/.env.development +3 -0
  27. package/resources/templates/template-workspace/admin/.env.production +3 -0
  28. package/resources/templates/template-workspace/admin/app/components/layout.tsx +32 -0
  29. package/resources/templates/template-workspace/admin/app/components/logo.tsx +16 -0
  30. package/resources/templates/template-workspace/admin/app/components/navigation.tsx +1 -0
  31. package/resources/templates/template-workspace/admin/app/config.ts +27 -0
  32. package/resources/templates/template-workspace/admin/app/index.html +15 -0
  33. package/resources/templates/template-workspace/admin/app/index.tsx +40 -0
  34. package/resources/templates/template-workspace/admin/app/pages/index.tsx +5 -0
  35. package/resources/templates/template-workspace/admin/index.css +53 -0
  36. package/resources/templates/template-workspace/admin/index.html +13 -0
  37. package/resources/templates/template-workspace/admin/index.tsx +268 -0
  38. package/resources/templates/template-workspace/admin/lib/binding/binding.tsx +45 -0
  39. package/resources/templates/template-workspace/admin/lib/binding/delete.tsx +43 -0
  40. package/resources/templates/template-workspace/admin/lib/binding/hooks.tsx +71 -0
  41. package/resources/templates/template-workspace/admin/lib/binding/identity.tsx +19 -0
  42. package/resources/templates/template-workspace/admin/lib/binding/index.ts +5 -0
  43. package/resources/templates/template-workspace/admin/lib/binding/persist.tsx +70 -0
  44. package/resources/templates/template-workspace/admin/lib/block-repeater/block-repeater.tsx +224 -0
  45. package/resources/templates/template-workspace/admin/lib/block-repeater/index.ts +1 -0
  46. package/resources/templates/template-workspace/admin/lib/board/board.tsx +240 -0
  47. package/resources/templates/template-workspace/admin/lib/board/index.ts +1 -0
  48. package/resources/templates/template-workspace/admin/lib/buttons/back-button.tsx +20 -0
  49. package/resources/templates/template-workspace/admin/lib/buttons/index.ts +2 -0
  50. package/resources/templates/template-workspace/admin/lib/buttons/link-back-button.tsx +21 -0
  51. package/resources/templates/template-workspace/admin/lib/datagrid/cells.tsx +64 -0
  52. package/resources/templates/template-workspace/admin/lib/datagrid/column-header.tsx +65 -0
  53. package/resources/templates/template-workspace/admin/lib/datagrid/columns.tsx +166 -0
  54. package/resources/templates/template-workspace/admin/lib/datagrid/elements.tsx +42 -0
  55. package/resources/templates/template-workspace/admin/lib/datagrid/empty.tsx +8 -0
  56. package/resources/templates/template-workspace/admin/lib/datagrid/export.tsx +17 -0
  57. package/resources/templates/template-workspace/admin/lib/datagrid/filters/boolean.tsx +76 -0
  58. package/resources/templates/template-workspace/admin/lib/datagrid/filters/common.tsx +29 -0
  59. package/resources/templates/template-workspace/admin/lib/datagrid/filters/date.tsx +153 -0
  60. package/resources/templates/template-workspace/admin/lib/datagrid/filters/enum.tsx +115 -0
  61. package/resources/templates/template-workspace/admin/lib/datagrid/filters/index.ts +7 -0
  62. package/resources/templates/template-workspace/admin/lib/datagrid/filters/mobile.tsx +19 -0
  63. package/resources/templates/template-workspace/admin/lib/datagrid/filters/number.tsx +100 -0
  64. package/resources/templates/template-workspace/admin/lib/datagrid/filters/relation.tsx +180 -0
  65. package/resources/templates/template-workspace/admin/lib/datagrid/filters/text.tsx +121 -0
  66. package/resources/templates/template-workspace/admin/lib/datagrid/grid.tsx +61 -0
  67. package/resources/templates/template-workspace/admin/lib/datagrid/index.ts +16 -0
  68. package/resources/templates/template-workspace/admin/lib/datagrid/layout-switcher.tsx +32 -0
  69. package/resources/templates/template-workspace/admin/lib/datagrid/loader.tsx +10 -0
  70. package/resources/templates/template-workspace/admin/lib/datagrid/pagination.tsx +103 -0
  71. package/resources/templates/template-workspace/admin/lib/datagrid/table.tsx +69 -0
  72. package/resources/templates/template-workspace/admin/lib/datagrid/tiles.tsx +24 -0
  73. package/resources/templates/template-workspace/admin/lib/datagrid/toolbar.tsx +66 -0
  74. package/resources/templates/template-workspace/admin/lib/datagrid/ui.tsx +153 -0
  75. package/resources/templates/template-workspace/admin/lib/dev/index.ts +2 -0
  76. package/resources/templates/template-workspace/admin/lib/dev/login-panel.tsx +56 -0
  77. package/resources/templates/template-workspace/admin/lib/dev/todo.tsx +14 -0
  78. package/resources/templates/template-workspace/admin/lib/dict.ts +324 -0
  79. package/resources/templates/template-workspace/admin/lib/dimensions/dimensions.tsx +135 -0
  80. package/resources/templates/template-workspace/admin/lib/dimensions/index.ts +1 -0
  81. package/resources/templates/template-workspace/admin/lib/editor/block-editor.tsx +111 -0
  82. package/resources/templates/template-workspace/admin/lib/editor/common/baseEditorPlugins.tsx +66 -0
  83. package/resources/templates/template-workspace/admin/lib/editor/common/buttons.tsx +83 -0
  84. package/resources/templates/template-workspace/admin/lib/editor/common/editor-block-toolbar.tsx +17 -0
  85. package/resources/templates/template-workspace/admin/lib/editor/common/editor-canvas.tsx +30 -0
  86. package/resources/templates/template-workspace/admin/lib/editor/common/editor-editable-canvas.tsx +50 -0
  87. package/resources/templates/template-workspace/admin/lib/editor/common/editor-inline-toolbar.tsx +63 -0
  88. package/resources/templates/template-workspace/admin/lib/editor/common/elements/AnchorRenderer.tsx +36 -0
  89. package/resources/templates/template-workspace/admin/lib/editor/common/elements/BlockElement.tsx +48 -0
  90. package/resources/templates/template-workspace/admin/lib/editor/common/elements/HeadingRenderer.tsx +48 -0
  91. package/resources/templates/template-workspace/admin/lib/editor/common/elements/HorizontalRuleRenderer.tsx +28 -0
  92. package/resources/templates/template-workspace/admin/lib/editor/common/elements/ListItemRenderer.tsx +13 -0
  93. package/resources/templates/template-workspace/admin/lib/editor/common/elements/OrderedListRenderer.tsx +13 -0
  94. package/resources/templates/template-workspace/admin/lib/editor/common/elements/ParagraphRenderer.tsx +15 -0
  95. package/resources/templates/template-workspace/admin/lib/editor/common/elements/ScrollTargetRenderer.tsx +30 -0
  96. package/resources/templates/template-workspace/admin/lib/editor/common/elements/TableCellElementRenderer.tsx +20 -0
  97. package/resources/templates/template-workspace/admin/lib/editor/common/elements/TableElementRenderer.tsx +96 -0
  98. package/resources/templates/template-workspace/admin/lib/editor/common/elements/TableRowElementRenderer.tsx +15 -0
  99. package/resources/templates/template-workspace/admin/lib/editor/common/elements/UnorderedListRenderer.tsx +13 -0
  100. package/resources/templates/template-workspace/admin/lib/editor/common/index.ts +6 -0
  101. package/resources/templates/template-workspace/admin/lib/editor/editor-block.tsx +96 -0
  102. package/resources/templates/template-workspace/admin/lib/editor/index.ts +5 -0
  103. package/resources/templates/template-workspace/admin/lib/editor/plugins.tsx +36 -0
  104. package/resources/templates/template-workspace/admin/lib/editor/rich-text.tsx +54 -0
  105. package/resources/templates/template-workspace/admin/lib/editor/sortable-block.tsx +51 -0
  106. package/resources/templates/template-workspace/admin/lib/errors/index.ts +1 -0
  107. package/resources/templates/template-workspace/admin/lib/errors/use-error-formatter.ts +26 -0
  108. package/resources/templates/template-workspace/admin/lib/form/container.tsx +63 -0
  109. package/resources/templates/template-workspace/admin/lib/form/index.ts +5 -0
  110. package/resources/templates/template-workspace/admin/lib/form/inputs.tsx +99 -0
  111. package/resources/templates/template-workspace/admin/lib/form/select.tsx +123 -0
  112. package/resources/templates/template-workspace/admin/lib/form/ui.tsx +29 -0
  113. package/resources/templates/template-workspace/admin/lib/form/upload.tsx +243 -0
  114. package/resources/templates/template-workspace/admin/lib/formatting/formatting.ts +62 -0
  115. package/resources/templates/template-workspace/admin/lib/formatting/index.ts +1 -0
  116. package/resources/templates/template-workspace/admin/lib/images/formatImageResizeUrl.ts +23 -0
  117. package/resources/templates/template-workspace/admin/lib/images/index.ts +1 -0
  118. package/resources/templates/template-workspace/admin/lib/layout/index.ts +2 -0
  119. package/resources/templates/template-workspace/admin/lib/layout/layout.tsx +167 -0
  120. package/resources/templates/template-workspace/admin/lib/layout/slots.tsx +24 -0
  121. package/resources/templates/template-workspace/admin/lib/outdated-application-dialog/index.ts +1 -0
  122. package/resources/templates/template-workspace/admin/lib/outdated-application-dialog/outdated-application-dialog.tsx +41 -0
  123. package/resources/templates/template-workspace/admin/lib/repeater/index.ts +1 -0
  124. package/resources/templates/template-workspace/admin/lib/repeater/repeater.tsx +142 -0
  125. package/resources/templates/template-workspace/admin/lib/select/create-new.tsx +34 -0
  126. package/resources/templates/template-workspace/admin/lib/select/filter.tsx +13 -0
  127. package/resources/templates/template-workspace/admin/lib/select/highlight.tsx +16 -0
  128. package/resources/templates/template-workspace/admin/lib/select/index.ts +7 -0
  129. package/resources/templates/template-workspace/admin/lib/select/list.tsx +49 -0
  130. package/resources/templates/template-workspace/admin/lib/select/multi-select.tsx +95 -0
  131. package/resources/templates/template-workspace/admin/lib/select/pagination.tsx +48 -0
  132. package/resources/templates/template-workspace/admin/lib/select/select.tsx +87 -0
  133. package/resources/templates/template-workspace/admin/lib/select/sortable-select.tsx +129 -0
  134. package/resources/templates/template-workspace/admin/lib/select/ui.tsx +80 -0
  135. package/resources/templates/template-workspace/admin/lib/tenant/forms/change-my-password.tsx +40 -0
  136. package/resources/templates/template-workspace/admin/lib/tenant/forms/common.tsx +94 -0
  137. package/resources/templates/template-workspace/admin/lib/tenant/forms/create-api-key.tsx +39 -0
  138. package/resources/templates/template-workspace/admin/lib/tenant/forms/index.ts +8 -0
  139. package/resources/templates/template-workspace/admin/lib/tenant/forms/invite.tsx +46 -0
  140. package/resources/templates/template-workspace/admin/lib/tenant/forms/login.tsx +52 -0
  141. package/resources/templates/template-workspace/admin/lib/tenant/forms/memberships-control.tsx +128 -0
  142. package/resources/templates/template-workspace/admin/lib/tenant/forms/password-reset-request.tsx +31 -0
  143. package/resources/templates/template-workspace/admin/lib/tenant/forms/password-reset.tsx +44 -0
  144. package/resources/templates/template-workspace/admin/lib/tenant/forms/update-project-member.tsx +32 -0
  145. package/resources/templates/template-workspace/admin/lib/tenant/hooks/useInvite.ts +28 -0
  146. package/resources/templates/template-workspace/admin/lib/tenant/hooks/useInviteUser.tsx +45 -0
  147. package/resources/templates/template-workspace/admin/lib/tenant/index.ts +3 -0
  148. package/resources/templates/template-workspace/admin/lib/tenant/listing/api-key-list.tsx +25 -0
  149. package/resources/templates/template-workspace/admin/lib/tenant/listing/index.ts +4 -0
  150. package/resources/templates/template-workspace/admin/lib/tenant/listing/member-delete-dialog.tsx +38 -0
  151. package/resources/templates/template-workspace/admin/lib/tenant/listing/member-list.tsx +147 -0
  152. package/resources/templates/template-workspace/admin/lib/tenant/listing/person-list.tsx +25 -0
  153. package/resources/templates/template-workspace/admin/lib/tenant/otp/index.ts +1 -0
  154. package/resources/templates/template-workspace/admin/lib/tenant/otp/otp-setup.tsx +146 -0
  155. package/resources/templates/template-workspace/admin/lib/toast/index.ts +2 -0
  156. package/resources/templates/template-workspace/admin/lib/toast/toast.tsx +112 -0
  157. package/resources/templates/template-workspace/admin/lib/toast/toaster.tsx +104 -0
  158. package/resources/templates/template-workspace/admin/lib/ui/alert-dialog.tsx +59 -0
  159. package/resources/templates/template-workspace/admin/lib/ui/button.tsx +29 -0
  160. package/resources/templates/template-workspace/admin/lib/ui/card.tsx +25 -0
  161. package/resources/templates/template-workspace/admin/lib/ui/dialog.tsx +51 -0
  162. package/resources/templates/template-workspace/admin/lib/ui/divider.tsx +11 -0
  163. package/resources/templates/template-workspace/admin/lib/ui/dropdown.tsx +108 -0
  164. package/resources/templates/template-workspace/admin/lib/ui/input.tsx +62 -0
  165. package/resources/templates/template-workspace/admin/lib/ui/label.tsx +7 -0
  166. package/resources/templates/template-workspace/admin/lib/ui/loader.tsx +30 -0
  167. package/resources/templates/template-workspace/admin/lib/ui/menu.tsx +103 -0
  168. package/resources/templates/template-workspace/admin/lib/ui/overlay.tsx +33 -0
  169. package/resources/templates/template-workspace/admin/lib/ui/popover.tsx +31 -0
  170. package/resources/templates/template-workspace/admin/lib/ui/progress.tsx +25 -0
  171. package/resources/templates/template-workspace/admin/lib/ui/scroll-area.tsx +45 -0
  172. package/resources/templates/template-workspace/admin/lib/ui/sheet.tsx +67 -0
  173. package/resources/templates/template-workspace/admin/lib/ui/sortable.tsx +13 -0
  174. package/resources/templates/template-workspace/admin/lib/ui/switch.tsx +10 -0
  175. package/resources/templates/template-workspace/admin/lib/ui/table.tsx +46 -0
  176. package/resources/templates/template-workspace/admin/lib/ui/textarea.tsx +18 -0
  177. package/resources/templates/template-workspace/admin/lib/ui/toggle-group.tsx +44 -0
  178. package/resources/templates/template-workspace/admin/lib/ui/toggle.tsx +29 -0
  179. package/resources/templates/template-workspace/admin/lib/ui/tooltip.tsx +24 -0
  180. package/resources/templates/template-workspace/admin/lib/upload/dropzone.tsx +21 -0
  181. package/resources/templates/template-workspace/admin/lib/upload/index.ts +3 -0
  182. package/resources/templates/template-workspace/admin/lib/upload/repeater.tsx +12 -0
  183. package/resources/templates/template-workspace/admin/lib/upload/ui.tsx +57 -0
  184. package/resources/templates/template-workspace/admin/lib/upload/upload-progress.tsx +130 -0
  185. package/resources/templates/template-workspace/admin/lib/upload/view.tsx +219 -0
  186. package/resources/templates/template-workspace/admin/lib/utils/cn.ts +4 -0
  187. package/resources/templates/template-workspace/admin/lib/utils/dict-format.tsx +3 -0
  188. package/resources/templates/template-workspace/admin/lib/utils/format-image-resize-url.ts +17 -0
  189. package/resources/templates/template-workspace/admin/lib/utils/formatting.ts +60 -0
  190. package/resources/templates/template-workspace/admin/lib/utils/index.ts +2 -0
  191. package/resources/templates/template-workspace/admin/lib/utils/uic.tsx +79 -0
  192. package/resources/templates/template-workspace/admin/package.json +63 -0
  193. package/resources/templates/template-workspace/admin/postcss.config.js +6 -0
  194. package/resources/templates/template-workspace/admin/public/favicon.png +0 -0
  195. package/resources/templates/template-workspace/admin/tailwind.config.js +73 -0
  196. package/resources/templates/template-workspace/admin/tsconfig.json +23 -0
  197. package/resources/templates/template-workspace/admin/vite-env.d.ts +7 -0
  198. package/resources/templates/template-workspace/admin/vite.config.ts +39 -0
  199. package/resources/templates/template-workspace/api/index.ts +7 -0
  200. package/resources/templates/template-workspace/api/migrations/.gitkeep +1 -0
  201. package/resources/templates/template-workspace/api/model/index.ts +1 -0
  202. package/resources/templates/template-workspace/api/package.json +16 -0
  203. package/resources/templates/template-workspace/api/tsconfig.json +10 -0
  204. package/resources/templates/template-workspace/biome.json +45 -0
  205. package/resources/templates/template-workspace/client/package.json +16 -0
  206. package/resources/templates/template-workspace/client/src/index.ts +1 -0
  207. package/resources/templates/template-workspace/client/tsconfig.json +9 -0
  208. package/resources/templates/template-workspace/contember.template.yaml +7 -0
  209. package/resources/templates/template-workspace/docker-compose.yaml +124 -0
  210. package/resources/templates/template-workspace/package.json +32 -0
  211. package/resources/templates/template-workspace/scripts/generate-client.sh +8 -0
  212. package/resources/templates/template-workspace/tsconfig.json +9 -0
  213. package/resources/templates/template-workspace/tsconfig.settings.json +15 -0
  214. package/src/commands/WorkspaceCreateCommand.ts +15 -6
  215. package/src/lib/FileSystem.ts +24 -0
  216. package/src/lib/PackageDownloader.ts +33 -0
  217. package/src/lib/TemplateInstaller.ts +102 -0
  218. package/src/lib/pathUtils.ts +4 -0
  219. package/src/run.ts +14 -5
  220. package/tsconfig.settings.json +5 -1
  221. package/types/download-tarball/index.d.ts +7 -0
  222. package/types/get-package-json-from-registry/index.d.ts +3 -0
  223. package/types/registry-info/index.d.ts +7 -0
@@ -0,0 +1,96 @@
1
+ import { Button } from '../ui/button'
2
+ import { PencilIcon, TrashIcon } from 'lucide-react'
3
+ import { Popover, PopoverContent, PopoverTrigger } from '../ui/popover'
4
+ import { Component } from '@contember/interface'
5
+ import { ReactNode, useCallback } from 'react'
6
+ import { Block, BlockContent, BlockRendererProps, useEditorBlockElement } from '@contember/react-slate-editor'
7
+ import { BlockElement } from './common/elements/BlockElement'
8
+ import { ReactEditor, useSlateStatic } from 'slate-react'
9
+ import { Node, Transforms } from 'slate'
10
+
11
+ export interface EditorBlockProps {
12
+ name: string
13
+ label: ReactNode
14
+ children: ReactNode
15
+ alternate?: ReactNode
16
+ }
17
+
18
+ export const EditorBlock = Component<EditorBlockProps>(() => {
19
+ return null
20
+ }, blockProps => {
21
+ return (
22
+ <Block
23
+ name={blockProps.name}
24
+ render={renderBlockProps => (
25
+ <EditorBlockUi blockProps={blockProps} renderBlockProps={renderBlockProps} />
26
+ )}
27
+ >
28
+ {blockProps.children}
29
+ {blockProps.alternate}
30
+ </Block>
31
+ )
32
+ })
33
+
34
+ export const EditorBlockContent = Component(() => {
35
+ const el = useEditorBlockElement().element
36
+ const hasText = Node.string(el).length > 0
37
+ return (
38
+ <div className="py-2 relative">
39
+ {!hasText && (
40
+ <div className="absolute inset-0 flex items-center text-gray-400 pointer-events-none" contentEditable={false}>
41
+ Type here...
42
+ </div>
43
+ )}
44
+ <BlockContent />
45
+ </div>
46
+ )
47
+ }, () => <BlockContent />)
48
+
49
+ const EditorBlockUi = ({ blockProps, renderBlockProps }: {
50
+ blockProps: EditorBlockProps,
51
+ renderBlockProps: BlockRendererProps }) => {
52
+ const {
53
+ children,
54
+ alternate,
55
+ label,
56
+ } = blockProps
57
+ const {
58
+ element,
59
+ attributes,
60
+ children: elChildren,
61
+ isVoid,
62
+ } = renderBlockProps
63
+ const editor = useSlateStatic()
64
+
65
+ const onRemove = useCallback(() => {
66
+ const path = ReactEditor.findPath(editor, element)
67
+ Transforms.removeNodes(editor, {
68
+ at: path,
69
+ })
70
+ }, [editor, element])
71
+
72
+ return (
73
+ <BlockElement element={element} attributes={attributes} withBoundaries>
74
+ <div className="group -ml-3 p-3 border border-transparent rounded-md hover:shadow-md hover:border-gray-200 transition-all">
75
+ <div contentEditable={false}>
76
+ <div className="flex">
77
+ <div className="text-gray-400 text-xs font-semibold">
78
+ {label}
79
+ </div>
80
+ <div className="ml-auto opacity-0 group-hover:opacity-20 hover:!opacity-100 transition-opacity">
81
+ <Button variant="destructive" onClick={onRemove} size="sm"><TrashIcon className="w-3 h-3" /></Button>
82
+ {alternate && (<Popover>
83
+ <PopoverTrigger asChild><Button size="sm"><PencilIcon className="w-3 h-3" /></Button></PopoverTrigger>
84
+ <PopoverContent>{alternate}</PopoverContent>
85
+ </Popover>)}
86
+ </div>
87
+ </div>
88
+ </div>
89
+ <div contentEditable={isVoid ? false : undefined}>
90
+ {children}
91
+ {isVoid ? elChildren : undefined}
92
+ </div>
93
+ </div>
94
+ </BlockElement>
95
+ )
96
+ }
@@ -0,0 +1,5 @@
1
+ export * from './common'
2
+ export * from './block-editor'
3
+ export * from './editor-block'
4
+ export * from './plugins'
5
+ export * from './rich-text'
@@ -0,0 +1,36 @@
1
+ import { withSortable } from '@contember/react-slate-editor'
2
+ import { SortableBlock } from './sortable-block'
3
+ import { baseEditorPlugins } from './common/baseEditorPlugins'
4
+
5
+ const plugins = baseEditorPlugins
6
+
7
+ export const richTextFieldPlugins = [
8
+ plugins.anchor,
9
+ plugins.bold,
10
+ plugins.code,
11
+ plugins.highlight,
12
+ plugins.italic,
13
+ plugins.newline,
14
+ plugins.strikeThrough,
15
+ plugins.underline,
16
+ ]
17
+
18
+ export const blockEditorPlugins = [
19
+ plugins.anchor,
20
+ plugins.paragraph,
21
+ plugins.heading,
22
+ plugins.list,
23
+ plugins.horizontalRule,
24
+ plugins.scrollTarget,
25
+ plugins.table,
26
+ plugins.bold,
27
+ plugins.code,
28
+ plugins.highlight,
29
+ plugins.italic,
30
+ plugins.newline,
31
+ plugins.strikeThrough,
32
+ plugins.underline,
33
+ withSortable({
34
+ render: SortableBlock,
35
+ }),
36
+ ]
@@ -0,0 +1,54 @@
1
+ import { Editable, useSlateStatic } from 'slate-react'
2
+ import { EditorCanvas } from './common/editor-canvas'
3
+ import { RichTextEditor } from '@contember/react-slate-editor'
4
+ import { Component, SugaredRelativeSingleField, useMutationState } from '@contember/interface'
5
+ import * as React from 'react'
6
+ import { ReactNode } from 'react'
7
+ import { FormContainer, FormContainerProps } from '../form'
8
+ import { FormFieldScope } from '@contember/react-form'
9
+ import { richTextFieldPlugins } from './plugins'
10
+
11
+ export type RichTextFieldProps = {
12
+ field: SugaredRelativeSingleField['field']
13
+ children: ReactNode
14
+ }
15
+ & Omit<FormContainerProps, 'children'>
16
+
17
+ export const RichTextField = Component<RichTextFieldProps>(({ field, description, label, children }) => {
18
+ return (
19
+ <FormFieldScope field={field}>
20
+ <FormContainer description={description} label={label}>
21
+ <RichTextEditor field={field} plugins={richTextFieldPlugins}>
22
+ <RichTextAreaInner>
23
+ {children}
24
+ </RichTextAreaInner>
25
+ </RichTextEditor>
26
+ </FormContainer>
27
+ </FormFieldScope>
28
+ )
29
+ })
30
+
31
+ const RichTextAreaInner = ({ placeholder, children }: { placeholder?: string, children: ReactNode }) => {
32
+ const editor = useSlateStatic()
33
+ const isMutating = useMutationState()
34
+
35
+ return (
36
+ <EditorCanvas
37
+ underlyingComponent={Editable}
38
+ componentProps={{
39
+ readOnly: isMutating,
40
+ renderElement: editor.renderElement,
41
+ renderLeaf: editor.renderLeaf,
42
+ onKeyDown: editor.onKeyDown,
43
+ onFocusCapture: editor.onFocus,
44
+ onBlurCapture: editor.onBlur,
45
+ onDOMBeforeInput: editor.onDOMBeforeInput,
46
+ placeholder,
47
+ }}
48
+ >
49
+ {children}
50
+ </EditorCanvas>
51
+ )
52
+ }
53
+
54
+
@@ -0,0 +1,51 @@
1
+ import React, { ReactNode, useEffect } from 'react'
2
+ import { Element } from 'slate'
3
+ import { useSortable } from '@dnd-kit/sortable'
4
+ import { uic } from '../utils'
5
+ import { GripVerticalIcon } from 'lucide-react'
6
+ import { DropIndicator } from '../ui/sortable'
7
+ import { Portal } from '@radix-ui/react-portal'
8
+ import { DragOverlay } from '@dnd-kit/core'
9
+
10
+ export const BlockEditorHandle = uic('button', {
11
+ baseClass: 'absolute top-1/2 -left-3 h-6 w-6 flex justify-end items-center opacity-10 hover:opacity-100 transition-opacity -translate-y-1/2',
12
+ beforeChildren: <GripVerticalIcon size={16} />,
13
+ })
14
+
15
+ export const SortableBlock = ({ children, element }: { children: ReactNode, element: Element }) => {
16
+ const sortable = useSortable({
17
+ id: element.key as string,
18
+ })
19
+ const isOver = sortable.isOver
20
+ const activeSortable = sortable.active?.data.current?.sortable
21
+ const isAfter = (sortable.data?.sortable.index ?? 0) > activeSortable?.index
22
+ const isActive = sortable.active?.id === element.key
23
+ const contentRef = React.useRef<HTMLDivElement>(null)
24
+
25
+ return (<>
26
+ <div className="relative">
27
+ <div className={'relative'}>
28
+ {isOver && !isAfter ? <DropIndicator placement={'top'} /> : null}
29
+ </div>
30
+ <div className={'p-6 ' + (isActive ? 'opacity-60' : '')} ref={sortable.setNodeRef}>
31
+ <BlockEditorHandle ref={sortable.setActivatorNodeRef} {...sortable.listeners} />
32
+ <div ref={contentRef}>
33
+ {children}
34
+ </div>
35
+ </div>
36
+ <div className={'relative'}>
37
+ {isOver && isAfter ? <DropIndicator placement={'bottom'} /> : null}
38
+ </div>
39
+ </div>
40
+ {isActive && contentRef.current && <Portal>
41
+ <DragOverlay>
42
+ <div className="opacity-80 flex">
43
+ <div className="p-4 bg-white bg-opacity-80 backdrop-blur-sm"
44
+ // deliberately using innerHTML to avoid firing React events
45
+ dangerouslySetInnerHTML={{ __html: contentRef.current.innerHTML }}/>
46
+ </div>
47
+ </DragOverlay>
48
+ </Portal>}
49
+ </>)
50
+ }
51
+
@@ -0,0 +1 @@
1
+ export * from './use-error-formatter'
@@ -0,0 +1,26 @@
1
+ import { ReactNode, useCallback } from 'react'
2
+ import { dict } from '../dict'
3
+ import { ErrorAccessor } from '@contember/interface'
4
+
5
+ export const useErrorFormatter = () => {
6
+ return useCallback((errors: ErrorAccessor.Error[]): ReactNode[] => {
7
+ return errors.map((it, i) => {
8
+ if (it.type === 'validation') {
9
+ switch (it.code) {
10
+ // case 'fieldRequired':
11
+ // return 'This field is required'
12
+ default:
13
+ return it.message
14
+ }
15
+ } else if (it.type === 'execution') {
16
+ if (it.code === 'UniqueConstraintViolation') {
17
+ return dict.errors.unique
18
+ } else {
19
+ return dict.errors.unknown
20
+ }
21
+ } else {
22
+ return dict.errors.unknown
23
+ }
24
+ })
25
+ }, [])
26
+ }
@@ -0,0 +1,63 @@
1
+ import * as React from 'react'
2
+ import { ReactNode } from 'react'
3
+ import { FormContainerUI, FormDescriptionUI, FormErrorUI, FormLabelUI, FormLabelWrapperUI } from './ui'
4
+ import { useErrorFormatter } from '../errors'
5
+ import { Component } from '@contember/interface'
6
+ import { FormError, FormLabel } from '@contember/react-form'
7
+
8
+ export interface FormContainerProps {
9
+ label?: ReactNode
10
+ description?: ReactNode
11
+ children: ReactNode
12
+ errors?: ReactNode
13
+ }
14
+
15
+
16
+ export const StandaloneFormContainer = ({ children, description, label, errors }: FormContainerProps) => (
17
+ <FormContainerUI>
18
+ <FormLabelWrapperUI>
19
+ {label &&
20
+ <FormLabelUI>
21
+ {label}
22
+ </FormLabelUI>
23
+ }
24
+ </FormLabelWrapperUI>
25
+ <div>
26
+ {children}
27
+ </div>
28
+ <div>
29
+ {description && <FormDescriptionUI>
30
+ {description}
31
+ </FormDescriptionUI>}
32
+ {errors}
33
+ </div>
34
+ </FormContainerUI>
35
+ )
36
+
37
+ export const FormContainer = Component(({ children, description, label }: FormContainerProps) => (
38
+ <FormContainerUI>
39
+ <FormLabelWrapperUI>
40
+ {label && <FormLabel>
41
+ <FormLabelUI>
42
+ {label}
43
+ </FormLabelUI>
44
+ </FormLabel>}
45
+ </FormLabelWrapperUI>
46
+ <div>
47
+ {children}
48
+ </div>
49
+ <div>
50
+ {description && <FormDescriptionUI>
51
+ {description}
52
+ </FormDescriptionUI>}
53
+
54
+ <FormError formatter={useErrorFormatter()}>
55
+ <FormErrorUI />
56
+ </FormError>
57
+ </div>
58
+ </FormContainerUI>
59
+ ), ({ children, label, description }) => <>
60
+ {label}
61
+ {children}
62
+ {description}
63
+ </>)
@@ -0,0 +1,5 @@
1
+ export * from './container'
2
+ export * from './inputs'
3
+ export * from './select'
4
+ export * from './ui'
5
+ export * from './upload'
@@ -0,0 +1,99 @@
1
+ import * as React from 'react'
2
+ import { ComponentProps, ReactNode } from 'react'
3
+ import { CheckboxInput, Input, RadioInput } from '../ui/input'
4
+ import { cn } from '../utils'
5
+ import { TextareaAutosize } from '../ui/textarea'
6
+ import { FormLabelUI } from './ui'
7
+ import { FormCheckbox, FormCheckboxProps, FormFieldScope, FormInput, FormInputProps, FormLabel, FormRadioInput, FormRadioItemProps } from '@contember/react-form'
8
+ import { FormContainer, FormContainerProps } from './container'
9
+ import { Component } from '@contember/interface'
10
+
11
+
12
+ export type InputFieldProps =
13
+ & Omit<FormInputProps, 'children'>
14
+ & Omit<FormContainerProps, 'children'>
15
+ & {
16
+ required?: boolean
17
+ inputProps?: ComponentProps<typeof Input>
18
+ }
19
+
20
+ export const InputField = Component(({ field, label, description, inputProps, isNonbearing, defaultValue, required }: InputFieldProps) => (
21
+ <FormFieldScope field={field}>
22
+ <FormContainer description={description} label={label}>
23
+ <FormInput field={field} isNonbearing={isNonbearing} defaultValue={defaultValue}>
24
+ <Input required={required} {...(inputProps ?? {})} className={cn('max-w-md', inputProps?.className)} />
25
+ </FormInput>
26
+ </FormContainer>
27
+ </FormFieldScope>
28
+ ))
29
+
30
+ export type TextareaFieldProps =
31
+ & Omit<FormInputProps, 'children'>
32
+ & Omit<FormContainerProps, 'children'>
33
+ & {
34
+ inputProps?: ComponentProps<typeof TextareaAutosize>
35
+ }
36
+
37
+ export const TextareaField = Component(({ field, label, description, inputProps, isNonbearing, defaultValue }: TextareaFieldProps) => (
38
+ <FormFieldScope field={field}>
39
+ <FormContainer description={description} label={label}>
40
+ <FormInput field={field} isNonbearing={isNonbearing} defaultValue={defaultValue}>
41
+ <TextareaAutosize {...(inputProps ?? {})} className={cn('max-w-md', inputProps?.className)} />
42
+ </FormInput>
43
+ </FormContainer>
44
+ </FormFieldScope>
45
+ ))
46
+
47
+
48
+ export type CheckboxFieldProps =
49
+ & Omit<FormCheckboxProps, 'children'>
50
+ & Omit<FormContainerProps, 'children'>
51
+ & {
52
+ inputProps?: Omit<React.InputHTMLAttributes<HTMLInputElement>, 'defaultValue'>
53
+ }
54
+
55
+ export const CheckboxField = Component(({ field, label, description, inputProps, isNonbearing, defaultValue }: CheckboxFieldProps) => (
56
+ <FormFieldScope field={field}>
57
+ <FormContainer description={description} label={undefined}>
58
+ <div className="flex gap-2 items-center">
59
+ <FormCheckbox field={field} isNonbearing={isNonbearing} defaultValue={defaultValue}>
60
+ <CheckboxInput {...inputProps} />
61
+ </FormCheckbox>
62
+ {label && <FormLabel>
63
+ <FormLabelUI>
64
+ {label}
65
+ </FormLabelUI>
66
+ </FormLabel>}
67
+ </div>
68
+ </FormContainer>
69
+ </FormFieldScope>
70
+ ))
71
+
72
+
73
+ export type RadioEnumFieldProps =
74
+ & Omit<FormRadioItemProps, 'children' | 'value'>
75
+ & Omit<FormContainerProps, 'children'>
76
+ & {
77
+ options: Record<string, ReactNode>
78
+ orientation?: 'horizontal' | 'vertical'
79
+ inputProps?: Omit<React.InputHTMLAttributes<HTMLInputElement>, 'defaultValue'>
80
+ }
81
+
82
+ export const RadioEnumField = Component<RadioEnumFieldProps>(({ field, label, description, options, inputProps, orientation, defaultValue, isNonbearing }) => {
83
+ return (
84
+ <FormFieldScope field={field}>
85
+ <FormContainer description={description} label={label}>
86
+ <div className={'flex flex-wrap gap-3 data-[orientation=vertical]:flex-col'} data-orientation={orientation ?? 'vertical'}>
87
+ {Object.entries(options).map(([value, label]) => (
88
+ <FormLabelUI className="flex gap-2 items-center font-normal" key={value}>
89
+ <FormRadioInput field={field} value={value} defaultValue={defaultValue} isNonbearing={isNonbearing}>
90
+ <RadioInput {...inputProps} />
91
+ </FormRadioInput>
92
+ {label}
93
+ </FormLabelUI>
94
+ ))}
95
+ </div>
96
+ </FormContainer>
97
+ </FormFieldScope>
98
+ )
99
+ })
@@ -0,0 +1,123 @@
1
+ import {
2
+ MultiSelectInput,
3
+ MultiSelectInputProps,
4
+ SelectDefaultPlaceholderUI,
5
+ SelectInput,
6
+ SelectInputActionsUI,
7
+ SelectInputProps,
8
+ SelectInputUI,
9
+ SelectInputWrapperUI,
10
+ SelectListItemUI,
11
+ SelectPopoverContent,
12
+ SortableMultiSelectInput,
13
+ SortableMultiSelectInputProps,
14
+ } from '../select'
15
+ import * as React from 'react'
16
+ import { FormContainer, FormContainerProps } from './container'
17
+ import { FormFieldScope, FormHasManyRelationScope, FormHasOneRelationScope, useFormFieldId } from '@contember/react-form'
18
+ import { Component, Field, SugaredRelativeSingleField, useField } from '@contember/interface'
19
+ import { Popover, PopoverTrigger } from '../ui/popover'
20
+ import { ChevronDownIcon, ChevronUpIcon } from 'lucide-react'
21
+
22
+
23
+ export type SelectFieldProps =
24
+ & SelectInputProps
25
+ & Omit<FormContainerProps, 'children'>
26
+
27
+ export const SelectField = Component<SelectFieldProps>(({ field, label, description, children, options, queryField, placeholder, createNewForm, errors, initialSorting }) => {
28
+ return (
29
+ <FormHasOneRelationScope field={field}>
30
+ <FormContainer description={description} label={label} errors={errors}>
31
+ <SelectInput field={field} queryField={queryField} options={options} placeholder={placeholder} createNewForm={createNewForm} initialSorting={initialSorting}>
32
+ {children}
33
+ </SelectInput>
34
+ </FormContainer>
35
+ </FormHasOneRelationScope>
36
+ )
37
+ })
38
+
39
+ export type MultiSelectFieldProps =
40
+ & MultiSelectInputProps
41
+ & Omit<FormContainerProps, 'children'>
42
+
43
+ export const MultiSelectField = Component<MultiSelectFieldProps>(({ field, label, description, children, options, queryField, placeholder, createNewForm, errors, initialSorting }) => {
44
+ return (
45
+ <FormHasManyRelationScope field={field}>
46
+ <FormContainer description={description} label={label} errors={errors}>
47
+ <MultiSelectInput field={field} queryField={queryField} options={options} placeholder={placeholder} createNewForm={createNewForm} initialSorting={initialSorting}>
48
+ {children}
49
+ </MultiSelectInput>
50
+ </FormContainer>
51
+ </FormHasManyRelationScope>
52
+ )
53
+ })
54
+
55
+ export type SortableMultiSelectFieldProps =
56
+ & SortableMultiSelectInputProps
57
+ & Omit<FormContainerProps, 'children'>
58
+
59
+ export const SortableMultiSelectField = Component<SortableMultiSelectFieldProps>(({ field, label, description, children, options, queryField, placeholder, sortableBy, connectAt, createNewForm, errors, initialSorting }) => {
60
+ return (
61
+ <FormHasManyRelationScope field={field}>
62
+ <FormContainer description={description} label={label} errors={errors}>
63
+ <SortableMultiSelectInput field={field} queryField={queryField} options={options} placeholder={placeholder} sortableBy={sortableBy} connectAt={connectAt} createNewForm={createNewForm} initialSorting={initialSorting}>
64
+ {children}
65
+ </SortableMultiSelectInput>
66
+ </FormContainer>
67
+ </FormHasManyRelationScope>
68
+ )
69
+ })
70
+
71
+ export type SelectEnumFieldProps =
72
+ & Omit<FormContainerProps, 'children'>
73
+ & {
74
+ field: SugaredRelativeSingleField['field']
75
+ options: Record<string, React.ReactNode>
76
+ placeholder?: React.ReactNode
77
+ defaultValue?: string
78
+ }
79
+
80
+ export const SelectEnumField = Component<SelectEnumFieldProps>(
81
+ ({ field, label, description, options, placeholder }) => {
82
+ return (
83
+ <FormFieldScope field={field}>
84
+ <FormContainer description={description} label={label}>
85
+ <SelectEnumFieldInner field={field} options={options} placeholder={placeholder} />
86
+ </FormContainer>
87
+ </FormFieldScope>
88
+ )
89
+ },
90
+ ({ field, defaultValue }) => <Field field={field} defaultValue={defaultValue} />,
91
+ 'SelectEnumField',
92
+ )
93
+
94
+ const SelectEnumFieldInner = ({ field, options, placeholder }: SelectEnumFieldProps) => {
95
+ const [open, setOpen] = React.useState(false)
96
+ const fieldAccessor = useField<string>(field)
97
+ const id = useFormFieldId()
98
+ return (
99
+ <Popover open={open} onOpenChange={setOpen}>
100
+ <SelectInputWrapperUI>
101
+ <PopoverTrigger asChild>
102
+ <SelectInputUI id={id ? `${id}-input` : undefined}>
103
+ {fieldAccessor.value ? options[fieldAccessor.value] : placeholder ?? <SelectDefaultPlaceholderUI />}
104
+ <SelectInputActionsUI>
105
+ {open ? <ChevronUpIcon /> : <ChevronDownIcon />}
106
+ </SelectInputActionsUI>
107
+ </SelectInputUI>
108
+ </PopoverTrigger>
109
+ </SelectInputWrapperUI>
110
+ <SelectPopoverContent>
111
+ {Object.entries(options).map(([value, label]) => (
112
+ <SelectListItemUI key={value} onClick={() => {
113
+ fieldAccessor.updateValue(value)
114
+ setOpen(false)
115
+ }}>
116
+ {label}
117
+ </SelectListItemUI>
118
+ ))}
119
+ </SelectPopoverContent>
120
+ </Popover>
121
+
122
+ )
123
+ }
@@ -0,0 +1,29 @@
1
+ import { uic } from '../utils/uic'
2
+ import { Label } from '../ui/label'
3
+
4
+ export const FormLayout = uic('div', {
5
+ baseClass: 'flex flex-col gap-2 w-full mx-4',
6
+ displayName: 'FormLayout',
7
+ })
8
+
9
+ export const FormDescriptionUI = uic('p', {
10
+ baseClass: 'text-[0.8rem] text-muted-foreground',
11
+ displayName: 'FormDescription',
12
+ })
13
+
14
+ export const FormErrorUI = uic('p', {
15
+ baseClass: 'text-[0.8rem] font-medium text-destructive',
16
+ displayName: 'FormError',
17
+ })
18
+ export const FormLabelWrapperUI = uic('div', {
19
+ baseClass: 'flex',
20
+ displayName: 'FormLabelWrapper',
21
+ })
22
+ export const FormLabelUI = uic(Label, {
23
+ baseClass: 'text-left',
24
+ displayName: 'FormLabel',
25
+ })
26
+ export const FormContainerUI = uic('div', {
27
+ baseClass: 'flex flex-col gap-2 w-full',
28
+ displayName: 'FormContainer',
29
+ })