@byline/admin 2.5.2 → 2.6.0

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 (260) hide show
  1. package/dist/fields/array/array-field.d.ts +14 -0
  2. package/dist/fields/array/array-field.js +177 -0
  3. package/dist/fields/array/array-field.module.js +11 -0
  4. package/dist/fields/array/array-field_module.css +32 -0
  5. package/dist/fields/blocks/blocks-field.d.ts +13 -0
  6. package/dist/fields/blocks/blocks-field.js +245 -0
  7. package/dist/fields/blocks/blocks-field.module.js +26 -0
  8. package/dist/fields/blocks/blocks-field_module.css +107 -0
  9. package/dist/fields/checkbox/checkbox-field.d.ts +16 -0
  10. package/dist/fields/checkbox/checkbox-field.js +28 -0
  11. package/dist/fields/checkbox/checkbox-field.module.js +6 -0
  12. package/dist/fields/checkbox/checkbox-field_module.css +4 -0
  13. package/dist/fields/column-formatter.d.ts +20 -0
  14. package/dist/fields/column-formatter.js +15 -0
  15. package/dist/fields/date-time-formatter.d.ts +16 -0
  16. package/dist/fields/date-time-formatter.js +8 -0
  17. package/dist/fields/datetime/datetime-field.d.ts +16 -0
  18. package/dist/fields/datetime/datetime-field.js +37 -0
  19. package/dist/fields/datetime/datetime-field.module.js +5 -0
  20. package/dist/fields/datetime/datetime-field_module.css +4 -0
  21. package/dist/fields/draggable-context-menu.d.ts +6 -0
  22. package/dist/fields/draggable-context-menu.js +85 -0
  23. package/dist/fields/draggable-context-menu.module.js +15 -0
  24. package/dist/fields/draggable-context-menu_module.css +91 -0
  25. package/dist/fields/field-helpers.d.ts +26 -0
  26. package/dist/fields/field-helpers.js +50 -0
  27. package/dist/fields/field-renderer.d.ts +37 -0
  28. package/dist/fields/field-renderer.js +206 -0
  29. package/dist/fields/field-renderer.module.js +8 -0
  30. package/dist/fields/field-renderer_module.css +11 -0
  31. package/dist/fields/field-services-context.d.ts +16 -0
  32. package/dist/fields/field-services-context.js +13 -0
  33. package/dist/fields/field-services-types.d.ts +63 -0
  34. package/dist/fields/field-services-types.js +1 -0
  35. package/dist/fields/file/file-field.d.ts +19 -0
  36. package/dist/fields/file/file-field.js +225 -0
  37. package/dist/fields/file/file-field.module.js +18 -0
  38. package/dist/fields/file/file-field_module.css +131 -0
  39. package/dist/fields/file/file-upload-field.d.ts +21 -0
  40. package/dist/fields/file/file-upload-field.js +130 -0
  41. package/dist/fields/file/file-upload-field.module.js +15 -0
  42. package/dist/fields/file/file-upload-field_module.css +74 -0
  43. package/dist/fields/group/group-field.d.ts +15 -0
  44. package/dist/fields/group/group-field.js +59 -0
  45. package/dist/fields/group/group-field.module.js +9 -0
  46. package/dist/fields/group/group-field_module.css +27 -0
  47. package/dist/fields/image/image-field.d.ts +19 -0
  48. package/dist/fields/image/image-field.js +241 -0
  49. package/dist/fields/image/image-field.module.js +22 -0
  50. package/dist/fields/image/image-field_module.css +121 -0
  51. package/dist/fields/image/image-upload-field.d.ts +21 -0
  52. package/dist/fields/image/image-upload-field.js +190 -0
  53. package/dist/fields/image/image-upload-field.module.js +19 -0
  54. package/dist/fields/image/image-upload-field_module.css +92 -0
  55. package/dist/fields/local-date-time.d.ts +27 -0
  56. package/dist/fields/local-date-time.js +49 -0
  57. package/dist/fields/locale-badge.d.ts +18 -0
  58. package/dist/fields/locale-badge.js +10 -0
  59. package/dist/fields/locale-badge.module.js +5 -0
  60. package/dist/fields/locale-badge_module.css +27 -0
  61. package/dist/fields/numerical/numerical-field.d.ts +18 -0
  62. package/dist/fields/numerical/numerical-field.js +74 -0
  63. package/dist/fields/relation/relation-display.d.ts +40 -0
  64. package/dist/fields/relation/relation-display.js +58 -0
  65. package/dist/fields/relation/relation-display.module.js +9 -0
  66. package/dist/fields/relation/relation-display_module.css +21 -0
  67. package/dist/fields/relation/relation-field.d.ts +18 -0
  68. package/dist/fields/relation/relation-field.js +138 -0
  69. package/dist/fields/relation/relation-field.module.js +13 -0
  70. package/dist/fields/relation/relation-field_module.css +62 -0
  71. package/dist/fields/relation/relation-picker.d.ts +49 -0
  72. package/dist/fields/relation/relation-picker.js +236 -0
  73. package/dist/fields/relation/relation-picker.module.js +26 -0
  74. package/dist/fields/relation/relation-picker_module.css +124 -0
  75. package/dist/fields/relation/relation-summary.d.ts +31 -0
  76. package/dist/fields/relation/relation-summary.js +50 -0
  77. package/dist/fields/relation/relation-summary.module.js +11 -0
  78. package/dist/fields/relation/relation-summary_module.css +37 -0
  79. package/dist/fields/select/select-field.d.ts +16 -0
  80. package/dist/fields/select/select-field.js +50 -0
  81. package/dist/fields/select/select-field.module.js +5 -0
  82. package/dist/fields/select/select-field_module.css +4 -0
  83. package/dist/fields/sortable-item.d.ts +15 -0
  84. package/dist/fields/sortable-item.js +81 -0
  85. package/dist/fields/sortable-item.module.js +22 -0
  86. package/dist/fields/sortable-item_module.css +124 -0
  87. package/dist/fields/text/text-field.d.ts +20 -0
  88. package/dist/fields/text/text-field.js +104 -0
  89. package/dist/fields/text/text-field.module.js +6 -0
  90. package/dist/fields/text/text-field_module.css +5 -0
  91. package/dist/fields/text-area/text-area-field.d.ts +20 -0
  92. package/dist/fields/text-area/text-area-field.js +105 -0
  93. package/dist/fields/text-area/text-area-field.module.js +6 -0
  94. package/dist/fields/text-area/text-area-field_module.css +5 -0
  95. package/dist/fields/use-field-change-handler.d.ts +23 -0
  96. package/dist/fields/use-field-change-handler.js +52 -0
  97. package/dist/forms/document-actions.d.ts +48 -0
  98. package/dist/forms/document-actions.js +475 -0
  99. package/dist/forms/document-actions.module.js +34 -0
  100. package/dist/forms/document-actions_module.css +118 -0
  101. package/dist/forms/form-context.d.ts +89 -0
  102. package/dist/forms/form-context.js +466 -0
  103. package/dist/forms/form-renderer.d.ts +98 -0
  104. package/dist/forms/form-renderer.js +597 -0
  105. package/dist/forms/form-renderer.module.js +46 -0
  106. package/dist/forms/form-renderer_module.css +245 -0
  107. package/dist/forms/navigation-guard.d.ts +54 -0
  108. package/dist/forms/navigation-guard.js +22 -0
  109. package/dist/forms/path-widget.d.ts +36 -0
  110. package/dist/forms/path-widget.js +116 -0
  111. package/dist/forms/path-widget.module.js +8 -0
  112. package/dist/forms/path-widget_module.css +29 -0
  113. package/dist/forms/upload-executor.d.ts +57 -0
  114. package/dist/forms/upload-executor.js +94 -0
  115. package/dist/lib/translate-validation-error.d.ts +36 -0
  116. package/dist/lib/translate-validation-error.js +11 -0
  117. package/dist/modules/admin-account/commands.d.ts +2 -1
  118. package/dist/modules/admin-account/commands.js +13 -2
  119. package/dist/modules/admin-account/components/change-password.js +45 -36
  120. package/dist/modules/admin-account/components/container.js +185 -134
  121. package/dist/modules/admin-account/components/preferences.d.ts +8 -0
  122. package/dist/modules/admin-account/components/preferences.js +152 -0
  123. package/dist/modules/admin-account/components/preferences.module.js +11 -0
  124. package/dist/modules/admin-account/components/preferences_module.css +41 -0
  125. package/dist/modules/admin-account/components/update.js +50 -31
  126. package/dist/modules/admin-account/index.d.ts +3 -3
  127. package/dist/modules/admin-account/index.js +2 -2
  128. package/dist/modules/admin-account/schemas.d.ts +4 -0
  129. package/dist/modules/admin-account/schemas.js +4 -1
  130. package/dist/modules/admin-account/service.d.ts +1 -0
  131. package/dist/modules/admin-account/service.js +8 -0
  132. package/dist/modules/admin-permissions/components/inspector.js +31 -41
  133. package/dist/modules/admin-roles/components/create.js +43 -26
  134. package/dist/modules/admin-roles/components/permissions.js +26 -35
  135. package/dist/modules/admin-roles/components/update.js +26 -16
  136. package/dist/modules/admin-users/components/create.js +60 -40
  137. package/dist/modules/admin-users/components/roles.js +9 -15
  138. package/dist/modules/admin-users/components/set-password.js +30 -31
  139. package/dist/modules/admin-users/components/update.js +58 -39
  140. package/dist/modules/admin-users/dto.js +1 -0
  141. package/dist/modules/admin-users/repository.d.ts +17 -0
  142. package/dist/modules/admin-users/schemas.d.ts +4 -0
  143. package/dist/modules/admin-users/schemas.js +6 -2
  144. package/dist/modules/auth/components/sign-in-form.js +10 -8
  145. package/dist/presentation/group.d.ts +27 -0
  146. package/dist/presentation/group.js +14 -0
  147. package/dist/presentation/group.module.js +6 -0
  148. package/dist/presentation/group_module.css +19 -0
  149. package/dist/presentation/row.d.ts +25 -0
  150. package/dist/presentation/row.js +8 -0
  151. package/dist/presentation/row.module.js +5 -0
  152. package/dist/presentation/row_module.css +18 -0
  153. package/dist/presentation/tabs.d.ts +25 -0
  154. package/dist/presentation/tabs.js +39 -0
  155. package/dist/presentation/tabs.module.js +10 -0
  156. package/dist/presentation/tabs_module.css +68 -0
  157. package/dist/react.d.ts +66 -0
  158. package/dist/react.js +36 -0
  159. package/dist/services/admin-services-types.d.ts +16 -0
  160. package/dist/widgets/diff-viewer/diff-modal.d.ts +22 -0
  161. package/dist/widgets/diff-viewer/diff-modal.js +149 -0
  162. package/dist/widgets/diff-viewer/diff-modal.module.js +14 -0
  163. package/dist/widgets/diff-viewer/diff-modal_module.css +56 -0
  164. package/dist/widgets/status-badge/status-badge.d.ts +25 -0
  165. package/dist/widgets/status-badge/status-badge.js +37 -0
  166. package/dist/widgets/status-badge/status-badge.module.js +7 -0
  167. package/dist/widgets/status-badge/status-badge_module.css +20 -0
  168. package/package.json +14 -4
  169. package/src/fields/array/array-field.module.css +48 -0
  170. package/src/fields/array/array-field.tsx +267 -0
  171. package/src/fields/blocks/blocks-field.module.css +148 -0
  172. package/src/fields/blocks/blocks-field.tsx +323 -0
  173. package/src/fields/checkbox/checkbox-field.module.css +4 -0
  174. package/src/fields/checkbox/checkbox-field.tsx +54 -0
  175. package/src/fields/column-formatter.tsx +31 -0
  176. package/src/fields/date-time-formatter.tsx +22 -0
  177. package/src/fields/datetime/datetime-field.module.css +13 -0
  178. package/src/fields/datetime/datetime-field.tsx +54 -0
  179. package/src/fields/draggable-context-menu.module.css +127 -0
  180. package/src/fields/draggable-context-menu.tsx +87 -0
  181. package/src/fields/field-helpers.ts +69 -0
  182. package/src/fields/field-renderer.module.css +22 -0
  183. package/src/fields/field-renderer.tsx +288 -0
  184. package/src/fields/field-services-context.tsx +35 -0
  185. package/src/fields/field-services-types.ts +68 -0
  186. package/src/fields/file/file-field.module.css +153 -0
  187. package/src/fields/file/file-field.tsx +286 -0
  188. package/src/fields/file/file-upload-field.module.css +101 -0
  189. package/src/fields/file/file-upload-field.tsx +187 -0
  190. package/src/fields/group/group-field.module.css +43 -0
  191. package/src/fields/group/group-field.tsx +84 -0
  192. package/src/fields/image/image-field.module.css +155 -0
  193. package/src/fields/image/image-field.tsx +306 -0
  194. package/src/fields/image/image-upload-field.module.css +123 -0
  195. package/src/fields/image/image-upload-field.tsx +276 -0
  196. package/src/fields/local-date-time.tsx +88 -0
  197. package/src/fields/locale-badge.module.css +37 -0
  198. package/src/fields/locale-badge.tsx +32 -0
  199. package/src/fields/numerical/numerical-field.tsx +114 -0
  200. package/src/fields/relation/relation-display.module.css +36 -0
  201. package/src/fields/relation/relation-display.tsx +130 -0
  202. package/src/fields/relation/relation-field.module.css +83 -0
  203. package/src/fields/relation/relation-field.tsx +211 -0
  204. package/src/fields/relation/relation-picker.module.css +168 -0
  205. package/src/fields/relation/relation-picker.tsx +326 -0
  206. package/src/fields/relation/relation-summary.module.css +55 -0
  207. package/src/fields/relation/relation-summary.tsx +123 -0
  208. package/src/fields/select/select-field.module.css +13 -0
  209. package/src/fields/select/select-field.tsx +61 -0
  210. package/src/fields/sortable-item.module.css +167 -0
  211. package/src/fields/sortable-item.tsx +106 -0
  212. package/src/fields/text/text-field.module.css +13 -0
  213. package/src/fields/text/text-field.tsx +146 -0
  214. package/src/fields/text-area/text-area-field.module.css +13 -0
  215. package/src/fields/text-area/text-area-field.tsx +147 -0
  216. package/src/fields/use-field-change-handler.ts +112 -0
  217. package/src/forms/document-actions.module.css +160 -0
  218. package/src/forms/document-actions.tsx +482 -0
  219. package/src/forms/form-context.tsx +704 -0
  220. package/src/forms/form-renderer.module.css +321 -0
  221. package/src/forms/form-renderer.tsx +891 -0
  222. package/src/forms/navigation-guard.tsx +98 -0
  223. package/src/forms/path-widget.module.css +41 -0
  224. package/src/forms/path-widget.test.tsx +217 -0
  225. package/src/forms/path-widget.tsx +183 -0
  226. package/src/forms/upload-executor.ts +192 -0
  227. package/src/lib/translate-validation-error.ts +56 -0
  228. package/src/modules/admin-account/commands.ts +13 -0
  229. package/src/modules/admin-account/components/change-password.tsx +46 -31
  230. package/src/modules/admin-account/components/container.tsx +83 -38
  231. package/src/modules/admin-account/components/preferences.module.css +60 -0
  232. package/src/modules/admin-account/components/preferences.tsx +203 -0
  233. package/src/modules/admin-account/components/update.tsx +53 -27
  234. package/src/modules/admin-account/index.ts +3 -0
  235. package/src/modules/admin-account/schemas.ts +13 -0
  236. package/src/modules/admin-account/service.ts +12 -0
  237. package/src/modules/admin-permissions/components/inspector.tsx +22 -14
  238. package/src/modules/admin-roles/components/create.tsx +51 -23
  239. package/src/modules/admin-roles/components/permissions.tsx +25 -21
  240. package/src/modules/admin-roles/components/update.tsx +37 -19
  241. package/src/modules/admin-users/components/create.tsx +63 -34
  242. package/src/modules/admin-users/components/roles.tsx +9 -8
  243. package/src/modules/admin-users/components/set-password.tsx +34 -28
  244. package/src/modules/admin-users/components/update.tsx +58 -36
  245. package/src/modules/admin-users/dto.ts +1 -0
  246. package/src/modules/admin-users/repository.ts +17 -0
  247. package/src/modules/admin-users/schemas.ts +12 -0
  248. package/src/modules/auth/components/sign-in-form.tsx +14 -8
  249. package/src/presentation/group.module.css +41 -0
  250. package/src/presentation/group.tsx +40 -0
  251. package/src/presentation/row.module.css +32 -0
  252. package/src/presentation/row.tsx +33 -0
  253. package/src/presentation/tabs.module.css +107 -0
  254. package/src/presentation/tabs.tsx +84 -0
  255. package/src/react.ts +84 -0
  256. package/src/services/admin-services-types.ts +18 -0
  257. package/src/widgets/diff-viewer/diff-modal.module.css +79 -0
  258. package/src/widgets/diff-viewer/diff-modal.tsx +186 -0
  259. package/src/widgets/status-badge/status-badge.module.css +31 -0
  260. package/src/widgets/status-badge/status-badge.tsx +71 -0
@@ -0,0 +1,323 @@
1
+ /**
2
+ * This Source Code is subject to the terms of the Mozilla Public
3
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
4
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
5
+ *
6
+ * Copyright (c) Infonomic Company Limited
7
+ */
8
+
9
+ import { useEffect, useMemo, useState } from 'react'
10
+
11
+ import type {
12
+ BlocksField as BlocksFieldType,
13
+ Field,
14
+ GroupField as GroupFieldType,
15
+ } from '@byline/core'
16
+ import { useTranslation } from '@byline/i18n/react'
17
+ import {
18
+ Card,
19
+ CloseIcon,
20
+ DraggableSortable,
21
+ IconButton,
22
+ Modal,
23
+ moveItem,
24
+ PlusIcon,
25
+ } from '@byline/ui/react'
26
+ import cx from 'classnames'
27
+
28
+ import { defaultScalarForField } from '../../fields/field-helpers'
29
+ import { GroupField } from '../../fields/group/group-field'
30
+ import { SortableItem } from '../../fields/sortable-item'
31
+ import { useFormContext } from '../../forms/form-context'
32
+ import styles from './blocks-field.module.css'
33
+
34
+ // ---------------------------------------------------------------------------
35
+ // BlocksField — renders `type: 'blocks'` fields. Children are heterogeneous
36
+ // group fields selected via a modal picker. Supports D&D.
37
+ // ---------------------------------------------------------------------------
38
+
39
+ export const BlocksField = ({
40
+ field,
41
+ defaultValue,
42
+ path,
43
+ }: {
44
+ field: BlocksFieldType
45
+ defaultValue: any
46
+ path: string
47
+ }) => {
48
+ const { appendPatch, getFieldValue, getFieldValues, setFieldStore } = useFormContext()
49
+ const { t } = useTranslation('byline-admin')
50
+ const [items, setItems] = useState<{ id: string; data: any }[]>([])
51
+ const [showAddBlockModal, setShowAddBlockModal] = useState(false)
52
+ const [pendingInsertIndex, setPendingInsertIndex] = useState<number | null>(null)
53
+
54
+ const availableBlocks = useMemo(() => field.blocks ?? [], [field.blocks])
55
+ const [selectedBlockName, setSelectedBlockName] = useState<string>(
56
+ () => availableBlocks[0]?.blockType ?? ''
57
+ )
58
+
59
+ useEffect(() => {
60
+ if (
61
+ selectedBlockName == null ||
62
+ !availableBlocks.some((b) => b.blockType === selectedBlockName)
63
+ ) {
64
+ setSelectedBlockName(availableBlocks[0]?.blockType ?? '')
65
+ }
66
+ }, [availableBlocks, selectedBlockName])
67
+
68
+ useEffect(() => {
69
+ if (Array.isArray(defaultValue)) {
70
+ setItems(
71
+ defaultValue.map((item: any) => ({
72
+ id:
73
+ item && typeof item === 'object' && '_id' in item
74
+ ? String((item as { _id: string })._id)
75
+ : crypto.randomUUID(),
76
+ data: item,
77
+ }))
78
+ )
79
+ } else {
80
+ setItems([])
81
+ }
82
+ }, [defaultValue])
83
+
84
+ const handleDragEnd = ({
85
+ moveFromIndex,
86
+ moveToIndex,
87
+ }: {
88
+ moveFromIndex: number
89
+ moveToIndex: number
90
+ }) => {
91
+ setItems((prev) => moveItem(prev, moveFromIndex, moveToIndex))
92
+ const currentArray = (getFieldValue(path) ?? defaultValue) as any[]
93
+
94
+ if (Array.isArray(currentArray)) {
95
+ const clampedFrom = Math.max(0, Math.min(moveFromIndex, currentArray.length - 1))
96
+ const clampedTo = Math.max(0, Math.min(moveToIndex, currentArray.length - 1))
97
+ if (clampedFrom === clampedTo) return
98
+
99
+ const item = currentArray[clampedFrom]
100
+ const itemId =
101
+ item && typeof item === 'object' && '_id' in item
102
+ ? String((item as { _id: string })._id)
103
+ : String(clampedFrom)
104
+
105
+ appendPatch({
106
+ kind: 'array.move',
107
+ path: path,
108
+ itemId,
109
+ toIndex: clampedTo,
110
+ })
111
+ }
112
+ }
113
+
114
+ const handleAddItem = async (forcedVariantName?: string, atIndex?: number) => {
115
+ setShowAddBlockModal(false)
116
+ setPendingInsertIndex(null)
117
+
118
+ const variant =
119
+ (forcedVariantName != null
120
+ ? availableBlocks.find((v) => v.blockType === forcedVariantName)
121
+ : undefined) ?? availableBlocks[0]
122
+
123
+ if (!variant) return
124
+
125
+ const compositeFields = (variant.fields ?? []) as Field[]
126
+
127
+ const newId = crypto.randomUUID()
128
+ const newItem: Record<string, any> = {
129
+ _id: newId,
130
+ _type: variant.blockType,
131
+ }
132
+ for (const f of compositeFields) {
133
+ newItem[f.name] = await defaultScalarForField(f, getFieldValues)
134
+ }
135
+
136
+ const currentArray = (getFieldValue(path) ?? defaultValue) as any[]
137
+ const insertAt = atIndex != null ? atIndex : currentArray ? currentArray.length : 0
138
+
139
+ const newItemWrapper = { id: newId, data: newItem }
140
+ setItems((prev) => {
141
+ const next = [...prev]
142
+ next.splice(insertAt, 0, newItemWrapper)
143
+ return next
144
+ })
145
+
146
+ appendPatch({
147
+ kind: 'array.insert',
148
+ path: path,
149
+ index: insertAt,
150
+ item: newItem,
151
+ })
152
+
153
+ const newArrayValue = currentArray ? [...currentArray] : []
154
+ newArrayValue.splice(insertAt, 0, newItem)
155
+ setFieldStore(path, newArrayValue)
156
+ }
157
+
158
+ const handleRemoveItem = (index: number) => {
159
+ const currentArray = (getFieldValue(path) ?? defaultValue) as any[]
160
+ if (!Array.isArray(currentArray) || index < 0 || index >= currentArray.length) return
161
+
162
+ const item = currentArray[index]
163
+ const itemId =
164
+ item && typeof item === 'object' && '_id' in item
165
+ ? String((item as { _id: string })._id)
166
+ : String(index)
167
+
168
+ setItems((prev) => prev.filter((_, i) => i !== index))
169
+
170
+ appendPatch({
171
+ kind: 'array.remove',
172
+ path: path,
173
+ itemId,
174
+ })
175
+
176
+ const newArrayValue = [...currentArray]
177
+ newArrayValue.splice(index, 1)
178
+ setFieldStore(path, newArrayValue)
179
+ }
180
+
181
+ const handleInsertBelow = (index: number, forcedVariantName?: string) => {
182
+ if (availableBlocks.length > 1 && forcedVariantName == null) {
183
+ setPendingInsertIndex(index + 1)
184
+ setShowAddBlockModal(true)
185
+ } else {
186
+ void handleAddItem(forcedVariantName, index + 1)
187
+ }
188
+ }
189
+
190
+ const renderItem = (itemWrapper: { id: string; data: any }, index: number) => {
191
+ const item = itemWrapper.data
192
+ const arrayElementPath = `${path}[${index}]`
193
+
194
+ if (!item || typeof item !== 'object' || typeof item._type !== 'string') return null
195
+
196
+ const subField = field.blocks?.find((b) => b.blockType === item._type)
197
+ if (subField == null) return null
198
+
199
+ // Extract field data (everything except _id and _type)
200
+ const { _id, _type, ...fieldData } = item
201
+ const label = subField.label ?? _type
202
+
203
+ // Render the block's children directly with arrayElementPath as the
204
+ // path (not basePath). FieldRenderer would append the group name
205
+ // (e.g. "richTextBlock") producing paths like
206
+ // "content[0].richTextBlock.constrainedWidth", but the flat block
207
+ // shape stores fields directly on the item so the correct path is
208
+ // "content[0].constrainedWidth".
209
+ const body = (
210
+ <GroupField
211
+ key={subField.blockType}
212
+ field={
213
+ {
214
+ type: 'group',
215
+ name: subField.blockType,
216
+ fields: subField.fields,
217
+ label: undefined,
218
+ } as GroupFieldType
219
+ }
220
+ defaultValue={fieldData}
221
+ path={arrayElementPath}
222
+ />
223
+ )
224
+
225
+ return (
226
+ <SortableItem
227
+ key={itemWrapper.id}
228
+ id={itemWrapper.id}
229
+ label={label ?? subField.blockType}
230
+ onAddBelow={() => handleInsertBelow(index)}
231
+ onRemove={() => handleRemoveItem(index)}
232
+ >
233
+ {body}
234
+ </SortableItem>
235
+ )
236
+ }
237
+
238
+ return (
239
+ <div className={`byline-field-blocks ${field.name}`}>
240
+ {field.label && (
241
+ <h3 className={cx('byline-field-blocks-title', styles.title)}>{field.label}</h3>
242
+ )}
243
+ <DraggableSortable
244
+ ids={items.map((i) => i.id)}
245
+ onDragEnd={handleDragEnd}
246
+ className={cx('byline-field-blocks-stack', styles.stack)}
247
+ >
248
+ {items.map((item, index) => renderItem(item, index))}
249
+ <div className={cx('byline-field-blocks-add-row', styles['add-row'])}>
250
+ <IconButton
251
+ onClick={() => {
252
+ setPendingInsertIndex(null)
253
+ setShowAddBlockModal(true)
254
+ }}
255
+ disabled={!selectedBlockName}
256
+ aria-label={t('fields.blocks.addBlockAriaLabel')}
257
+ >
258
+ <PlusIcon />
259
+ </IconButton>
260
+ </div>
261
+ </DraggableSortable>
262
+ <Modal
263
+ isOpen={showAddBlockModal}
264
+ closeOnOverlayClick={true}
265
+ onDismiss={() => {
266
+ setShowAddBlockModal(false)
267
+ setPendingInsertIndex(null)
268
+ }}
269
+ >
270
+ <Modal.Container style={{ maxWidth: '600px' }}>
271
+ <Modal.Header className={cx('byline-field-blocks-modal-head', styles['modal-head'])}>
272
+ <h3 className={cx('byline-field-blocks-modal-title', styles['modal-title'])}>
273
+ {t('fields.blocks.modalTitle')}
274
+ </h3>
275
+ <IconButton
276
+ arial-label={t('common.actions.close')}
277
+ size="xs"
278
+ onClick={() => {
279
+ setShowAddBlockModal(false)
280
+ setPendingInsertIndex(null)
281
+ }}
282
+ >
283
+ <CloseIcon width="16px" height="16px" svgClassName="white-icon" />
284
+ </IconButton>
285
+ </Modal.Header>
286
+ <Modal.Content className={cx('byline-field-blocks-card-cursor', styles['modal-content'])}>
287
+ <div className={cx('byline-field-blocks-grid', styles.grid)}>
288
+ {availableBlocks.map((b, index) => (
289
+ <Card
290
+ key={b.blockType}
291
+ hover
292
+ onClick={() => void handleAddItem(b.blockType, pendingInsertIndex ?? undefined)}
293
+ className={cx('byline-field-blocks-card', styles.card)}
294
+ >
295
+ <Card.Header>
296
+ <div className={cx('byline-field-blocks-card-head', styles['card-head'])}>
297
+ <Card.Title
298
+ className={cx('byline-field-blocks-card-title', styles['card-title'])}
299
+ >
300
+ {b.label ?? b.blockType}
301
+ </Card.Title>
302
+ <span className={cx('byline-field-blocks-card-index', styles['card-index'])}>
303
+ {index + 1}
304
+ </span>
305
+ </div>
306
+ <code className={cx('byline-field-blocks-card-code', styles['card-code'])}>
307
+ {b.blockType}
308
+ </code>
309
+ </Card.Header>
310
+ <Card.Content>
311
+ <p className={cx('byline-field-blocks-card-body', styles['card-body'])}>
312
+ {b.helpText ?? b.label ?? b.blockType}
313
+ </p>
314
+ </Card.Content>
315
+ </Card>
316
+ ))}
317
+ </div>
318
+ </Modal.Content>
319
+ </Modal.Container>
320
+ </Modal>
321
+ </div>
322
+ )
323
+ }
@@ -0,0 +1,4 @@
1
+ :global(.byline-field-checkbox),
2
+ .field-checkbox {
3
+ margin: 0;
4
+ }
@@ -0,0 +1,54 @@
1
+ /**
2
+ * This Source Code is subject to the terms of the Mozilla Public
3
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
4
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
5
+ *
6
+ * Copyright (c) Infonomic Company Limited
7
+ */
8
+
9
+ import type { CheckboxField as FieldType } from '@byline/core'
10
+ import { Checkbox } from '@byline/ui/react'
11
+
12
+ import { useFieldError, useFieldValue } from '../../forms/form-context'
13
+ import styles from './checkbox-field.module.css'
14
+
15
+ export const CheckboxField = ({
16
+ field,
17
+ value,
18
+ defaultValue,
19
+ onChange,
20
+ id,
21
+ path,
22
+ }: {
23
+ field: FieldType
24
+ value?: boolean
25
+ defaultValue?: boolean
26
+ onChange?: (value: boolean) => void
27
+ id?: string
28
+ path?: string
29
+ }) => {
30
+ const fieldPath = path ?? field.name
31
+ const fieldError = useFieldError(fieldPath)
32
+ const fieldValue = useFieldValue<boolean | undefined>(fieldPath)
33
+ const checked = value ?? fieldValue ?? defaultValue ?? false
34
+
35
+ return (
36
+ <div className={`byline-field-checkbox ${field.name} ${styles['field-checkbox']}`}>
37
+ <Checkbox
38
+ id={id ?? fieldPath}
39
+ name={field.name}
40
+ label={field.label}
41
+ checked={checked}
42
+ size="sm"
43
+ helpText={field.helpText}
44
+ // TODO: Handle indeterminate state
45
+ onCheckedChange={(value: boolean | 'indeterminate') => {
46
+ const next = value === 'indeterminate' ? false : Boolean(value)
47
+ onChange?.(next)
48
+ }}
49
+ error={fieldError != null}
50
+ errorText={fieldError}
51
+ />
52
+ </div>
53
+ )
54
+ }
@@ -0,0 +1,31 @@
1
+ /**
2
+ * This Source Code is subject to the terms of the Mozilla Public
3
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
4
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
5
+ *
6
+ * Copyright (c) Infonomic Company Limited
7
+ */
8
+
9
+ import type { ColumnFormatter, FormatterProps } from '@byline/core'
10
+
11
+ /**
12
+ * Type guard: returns true when the formatter is a `{ component }` wrapper
13
+ * rather than a plain function.
14
+ */
15
+ export function isComponentFormatter<T>(
16
+ fmt: ColumnFormatter<T>
17
+ ): fmt is { component: (props: FormatterProps<T>) => any } {
18
+ return typeof fmt === 'object' && fmt !== null && 'component' in fmt
19
+ }
20
+
21
+ /**
22
+ * Render a cell value through its column formatter (if any).
23
+ * Handles both plain-function and `{ component }` formatters.
24
+ */
25
+ export function renderFormatted(value: any, document: any, formatter: ColumnFormatter) {
26
+ if (isComponentFormatter(formatter)) {
27
+ const Component = formatter.component
28
+ return <Component value={value} record={document} />
29
+ }
30
+ return formatter(value, document)
31
+ }
@@ -0,0 +1,22 @@
1
+ /**
2
+ * This Source Code is subject to the terms of the Mozilla Public
3
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
4
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
5
+ *
6
+ * Copyright (c) Infonomic Company Limited
7
+ */
8
+
9
+ import type { FormatterProps } from '@byline/core'
10
+
11
+ import { LocalDateTime } from './local-date-time'
12
+
13
+ /**
14
+ * SSR-safe date-time column formatter for list views.
15
+ *
16
+ * Uses the `LocalDateTime` component which renders a placeholder on the server
17
+ * and formats to the user's locale/timezone after hydration, avoiding
18
+ * server/client mismatches.
19
+ */
20
+ export function DateTimeFormatter({ value }: FormatterProps) {
21
+ return <LocalDateTime value={value} />
22
+ }
@@ -0,0 +1,13 @@
1
+ /**
2
+ * DateTimeField — date/time picker form widget.
3
+ *
4
+ * Override handles:
5
+ * .byline-field-datetime — the wrapper div
6
+ * .byline-field-datetime-dirty — added to the inner picker when the
7
+ * field has unsaved local changes
8
+ */
9
+
10
+ .dirty,
11
+ :global(.byline-field-datetime-dirty) {
12
+ border-color: var(--blue-300);
13
+ }
@@ -0,0 +1,54 @@
1
+ /**
2
+ * This Source Code is subject to the terms of the Mozilla Public
3
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
4
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
5
+ *
6
+ * Copyright (c) Infonomic Company Limited
7
+ */
8
+
9
+ import type { DateTimeField as FieldType } from '@byline/core'
10
+ import { DatePicker, ErrorText } from '@byline/ui/react'
11
+ import cx from 'classnames'
12
+
13
+ import { useFieldError, useFieldValue, useIsDirty } from '../../forms/form-context'
14
+ import styles from './datetime-field.module.css'
15
+
16
+ export const DateTimeField = ({
17
+ field,
18
+ value,
19
+ defaultValue,
20
+ onChange,
21
+ id,
22
+ path,
23
+ }: {
24
+ field: FieldType
25
+ value?: Date | null
26
+ defaultValue?: Date | null
27
+ onChange?: (value: Date | null) => void
28
+ id?: string
29
+ path?: string
30
+ }) => {
31
+ const fieldPath = path ?? field.name
32
+ const fieldError = useFieldError(fieldPath)
33
+ const isDirty = useIsDirty(fieldPath)
34
+ const fieldValue = useFieldValue<Date | null | undefined>(fieldPath)
35
+ const incomingValue = value ?? fieldValue ?? defaultValue ?? null
36
+
37
+ return (
38
+ <div className={`byline-field-datetime ${field.name}`}>
39
+ <DatePicker
40
+ id={id ?? fieldPath}
41
+ name={field.name}
42
+ label={field.label}
43
+ required={!field.optional}
44
+ initialValue={incomingValue}
45
+ mode={field.mode || 'datetime'}
46
+ yearsInFuture={field.yearsInFuture || 1}
47
+ yearsInPast={field.yearsInPast || 10}
48
+ onDateChange={(date) => onChange?.(date)}
49
+ className={cx(isDirty && ['byline-field-datetime-dirty', styles.dirty])}
50
+ />
51
+ {fieldError && <ErrorText id={`${field.name}-error`} text={fieldError} />}
52
+ </div>
53
+ )
54
+ }
@@ -0,0 +1,127 @@
1
+ /**
2
+ * DraggableContextMenu — small `…` dropdown attached to draggable list rows.
3
+ *
4
+ * Override handles:
5
+ * .byline-draggable-menu — dropdown content panel
6
+ * .byline-draggable-menu-item — individual menu item
7
+ * .byline-draggable-menu-row — flex row inside an item
8
+ * .byline-draggable-menu-icon-slot — fixed-width icon column
9
+ * .byline-draggable-menu-label — label text column
10
+ * .byline-draggable-menu-label-danger — destructive-action label
11
+ * .byline-draggable-menu-separator — separator between items
12
+ */
13
+
14
+ .menu,
15
+ :global(.byline-draggable-menu) {
16
+ z-index: 40;
17
+ width: 8.5rem;
18
+ padding: 0.25rem 0.375rem;
19
+ background-color: white;
20
+ border: var(--border-width-thin) var(--border-style-solid) var(--gray-200);
21
+ border-radius: var(--border-radius-sm);
22
+ box-shadow:
23
+ 0 4px 6px -1px rgb(0 0 0 / 0.1),
24
+ 0 2px 4px -2px rgb(0 0 0 / 0.1);
25
+ }
26
+
27
+ .item,
28
+ :global(.byline-draggable-menu-item) {
29
+ display: flex;
30
+ align-items: center;
31
+ gap: 0.25rem;
32
+ width: 100%;
33
+ padding: 5px 2px;
34
+ border-radius: var(--border-radius-sm);
35
+ color: var(--gray-600);
36
+ cursor: default;
37
+ user-select: none;
38
+ outline: none;
39
+ }
40
+
41
+ @media (min-width: 48rem) {
42
+ .item,
43
+ :global(.byline-draggable-menu-item) {
44
+ font-size: var(--font-size-sm);
45
+ }
46
+ }
47
+
48
+ .item:hover,
49
+ .item:focus,
50
+ :global(.byline-draggable-menu-item):hover,
51
+ :global(.byline-draggable-menu-item):focus {
52
+ background-color: oklch(from var(--canvas-50) l c h / 0.3);
53
+ }
54
+
55
+ .row,
56
+ :global(.byline-draggable-menu-row) {
57
+ display: flex;
58
+ align-items: center;
59
+ gap: 0.25rem;
60
+ width: 100%;
61
+ }
62
+
63
+ .icon-slot,
64
+ :global(.byline-draggable-menu-icon-slot) {
65
+ display: inline-block;
66
+ width: 22px;
67
+ }
68
+
69
+ .label,
70
+ :global(.byline-draggable-menu-label) {
71
+ display: inline-block;
72
+ flex: 1;
73
+ width: 100%;
74
+ align-self: flex-start;
75
+ text-align: left;
76
+ color: black;
77
+ }
78
+
79
+ .label-danger,
80
+ :global(.byline-draggable-menu-label-danger) {
81
+ color: var(--red-600);
82
+ }
83
+
84
+ .delete-icon,
85
+ :global(.byline-draggable-menu-delete-icon) {
86
+ stroke: var(--red-600);
87
+ }
88
+
89
+ .separator,
90
+ :global(.byline-draggable-menu-separator) {
91
+ width: 90%;
92
+ margin: 0.25rem auto;
93
+ border: none;
94
+ border-top: var(--border-width-thin) var(--border-style-solid) var(--gray-200);
95
+ }
96
+
97
+ /* ─── Dark theme variants ───────────────────────────────────── */
98
+
99
+ :is([data-theme="dark"], :global(.dark)) {
100
+ .menu,
101
+ :global(.byline-draggable-menu) {
102
+ background-color: var(--canvas-800);
103
+ border-color: var(--canvas-700);
104
+ }
105
+
106
+ .item,
107
+ :global(.byline-draggable-menu-item) {
108
+ color: var(--gray-300);
109
+ }
110
+
111
+ .item:hover,
112
+ .item:focus,
113
+ :global(.byline-draggable-menu-item):hover,
114
+ :global(.byline-draggable-menu-item):focus {
115
+ background-color: var(--canvas-900);
116
+ }
117
+
118
+ .label,
119
+ :global(.byline-draggable-menu-label) {
120
+ color: var(--gray-300);
121
+ }
122
+
123
+ .separator,
124
+ :global(.byline-draggable-menu-separator) {
125
+ border-top-color: var(--gray-900);
126
+ }
127
+ }