@byline/admin 2.5.2 → 2.6.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/fields/array/array-field.d.ts +14 -0
- package/dist/fields/array/array-field.js +177 -0
- package/dist/fields/array/array-field.module.js +11 -0
- package/dist/fields/array/array-field_module.css +32 -0
- package/dist/fields/blocks/blocks-field.d.ts +13 -0
- package/dist/fields/blocks/blocks-field.js +245 -0
- package/dist/fields/blocks/blocks-field.module.js +26 -0
- package/dist/fields/blocks/blocks-field_module.css +107 -0
- package/dist/fields/checkbox/checkbox-field.d.ts +16 -0
- package/dist/fields/checkbox/checkbox-field.js +28 -0
- package/dist/fields/checkbox/checkbox-field.module.js +6 -0
- package/dist/fields/checkbox/checkbox-field_module.css +4 -0
- package/dist/fields/column-formatter.d.ts +20 -0
- package/dist/fields/column-formatter.js +15 -0
- package/dist/fields/date-time-formatter.d.ts +16 -0
- package/dist/fields/date-time-formatter.js +8 -0
- package/dist/fields/datetime/datetime-field.d.ts +16 -0
- package/dist/fields/datetime/datetime-field.js +37 -0
- package/dist/fields/datetime/datetime-field.module.js +5 -0
- package/dist/fields/datetime/datetime-field_module.css +4 -0
- package/dist/fields/draggable-context-menu.d.ts +6 -0
- package/dist/fields/draggable-context-menu.js +85 -0
- package/dist/fields/draggable-context-menu.module.js +15 -0
- package/dist/fields/draggable-context-menu_module.css +91 -0
- package/dist/fields/field-helpers.d.ts +26 -0
- package/dist/fields/field-helpers.js +50 -0
- package/dist/fields/field-renderer.d.ts +37 -0
- package/dist/fields/field-renderer.js +206 -0
- package/dist/fields/field-renderer.module.js +8 -0
- package/dist/fields/field-renderer_module.css +11 -0
- package/dist/fields/field-services-context.d.ts +16 -0
- package/dist/fields/field-services-context.js +13 -0
- package/dist/fields/field-services-types.d.ts +63 -0
- package/dist/fields/field-services-types.js +1 -0
- package/dist/fields/file/file-field.d.ts +19 -0
- package/dist/fields/file/file-field.js +225 -0
- package/dist/fields/file/file-field.module.js +18 -0
- package/dist/fields/file/file-field_module.css +131 -0
- package/dist/fields/file/file-upload-field.d.ts +21 -0
- package/dist/fields/file/file-upload-field.js +130 -0
- package/dist/fields/file/file-upload-field.module.js +15 -0
- package/dist/fields/file/file-upload-field_module.css +74 -0
- package/dist/fields/group/group-field.d.ts +15 -0
- package/dist/fields/group/group-field.js +59 -0
- package/dist/fields/group/group-field.module.js +9 -0
- package/dist/fields/group/group-field_module.css +27 -0
- package/dist/fields/image/image-field.d.ts +19 -0
- package/dist/fields/image/image-field.js +241 -0
- package/dist/fields/image/image-field.module.js +22 -0
- package/dist/fields/image/image-field_module.css +121 -0
- package/dist/fields/image/image-upload-field.d.ts +21 -0
- package/dist/fields/image/image-upload-field.js +190 -0
- package/dist/fields/image/image-upload-field.module.js +19 -0
- package/dist/fields/image/image-upload-field_module.css +92 -0
- package/dist/fields/local-date-time.d.ts +27 -0
- package/dist/fields/local-date-time.js +49 -0
- package/dist/fields/locale-badge.d.ts +18 -0
- package/dist/fields/locale-badge.js +10 -0
- package/dist/fields/locale-badge.module.js +5 -0
- package/dist/fields/locale-badge_module.css +27 -0
- package/dist/fields/numerical/numerical-field.d.ts +18 -0
- package/dist/fields/numerical/numerical-field.js +74 -0
- package/dist/fields/relation/relation-display.d.ts +40 -0
- package/dist/fields/relation/relation-display.js +61 -0
- package/dist/fields/relation/relation-display.module.js +9 -0
- package/dist/fields/relation/relation-display_module.css +21 -0
- package/dist/fields/relation/relation-field.d.ts +18 -0
- package/dist/fields/relation/relation-field.js +138 -0
- package/dist/fields/relation/relation-field.module.js +13 -0
- package/dist/fields/relation/relation-field_module.css +62 -0
- package/dist/fields/relation/relation-picker.d.ts +59 -0
- package/dist/fields/relation/relation-picker.js +237 -0
- package/dist/fields/relation/relation-picker.module.js +26 -0
- package/dist/fields/relation/relation-picker_module.css +124 -0
- package/dist/fields/relation/relation-summary.d.ts +31 -0
- package/dist/fields/relation/relation-summary.js +50 -0
- package/dist/fields/relation/relation-summary.module.js +11 -0
- package/dist/fields/relation/relation-summary_module.css +37 -0
- package/dist/fields/select/select-field.d.ts +16 -0
- package/dist/fields/select/select-field.js +50 -0
- package/dist/fields/select/select-field.module.js +5 -0
- package/dist/fields/select/select-field_module.css +4 -0
- package/dist/fields/sortable-item.d.ts +15 -0
- package/dist/fields/sortable-item.js +81 -0
- package/dist/fields/sortable-item.module.js +22 -0
- package/dist/fields/sortable-item_module.css +124 -0
- package/dist/fields/text/text-field.d.ts +20 -0
- package/dist/fields/text/text-field.js +104 -0
- package/dist/fields/text/text-field.module.js +6 -0
- package/dist/fields/text/text-field_module.css +5 -0
- package/dist/fields/text-area/text-area-field.d.ts +20 -0
- package/dist/fields/text-area/text-area-field.js +105 -0
- package/dist/fields/text-area/text-area-field.module.js +6 -0
- package/dist/fields/text-area/text-area-field_module.css +5 -0
- package/dist/fields/use-field-change-handler.d.ts +23 -0
- package/dist/fields/use-field-change-handler.js +52 -0
- package/dist/forms/document-actions.d.ts +48 -0
- package/dist/forms/document-actions.js +475 -0
- package/dist/forms/document-actions.module.js +34 -0
- package/dist/forms/document-actions_module.css +118 -0
- package/dist/forms/form-context.d.ts +89 -0
- package/dist/forms/form-context.js +466 -0
- package/dist/forms/form-renderer.d.ts +98 -0
- package/dist/forms/form-renderer.js +597 -0
- package/dist/forms/form-renderer.module.js +46 -0
- package/dist/forms/form-renderer_module.css +245 -0
- package/dist/forms/navigation-guard.d.ts +54 -0
- package/dist/forms/navigation-guard.js +22 -0
- package/dist/forms/path-widget.d.ts +36 -0
- package/dist/forms/path-widget.js +116 -0
- package/dist/forms/path-widget.module.js +8 -0
- package/dist/forms/path-widget_module.css +29 -0
- package/dist/forms/upload-executor.d.ts +57 -0
- package/dist/forms/upload-executor.js +94 -0
- package/dist/lib/translate-validation-error.d.ts +36 -0
- package/dist/lib/translate-validation-error.js +11 -0
- package/dist/modules/admin-account/commands.d.ts +2 -1
- package/dist/modules/admin-account/commands.js +13 -2
- package/dist/modules/admin-account/components/change-password.js +45 -36
- package/dist/modules/admin-account/components/container.js +185 -134
- package/dist/modules/admin-account/components/preferences.d.ts +8 -0
- package/dist/modules/admin-account/components/preferences.js +152 -0
- package/dist/modules/admin-account/components/preferences.module.js +11 -0
- package/dist/modules/admin-account/components/preferences_module.css +41 -0
- package/dist/modules/admin-account/components/update.js +50 -31
- package/dist/modules/admin-account/index.d.ts +3 -3
- package/dist/modules/admin-account/index.js +2 -2
- package/dist/modules/admin-account/schemas.d.ts +4 -0
- package/dist/modules/admin-account/schemas.js +4 -1
- package/dist/modules/admin-account/service.d.ts +1 -0
- package/dist/modules/admin-account/service.js +8 -0
- package/dist/modules/admin-permissions/components/inspector.js +31 -41
- package/dist/modules/admin-roles/components/create.js +43 -26
- package/dist/modules/admin-roles/components/permissions.js +26 -35
- package/dist/modules/admin-roles/components/update.js +26 -16
- package/dist/modules/admin-users/components/create.js +60 -40
- package/dist/modules/admin-users/components/roles.js +9 -15
- package/dist/modules/admin-users/components/set-password.js +30 -31
- package/dist/modules/admin-users/components/update.js +58 -39
- package/dist/modules/admin-users/dto.js +1 -0
- package/dist/modules/admin-users/repository.d.ts +17 -0
- package/dist/modules/admin-users/schemas.d.ts +4 -0
- package/dist/modules/admin-users/schemas.js +6 -2
- package/dist/modules/auth/components/sign-in-form.js +10 -8
- package/dist/presentation/group.d.ts +27 -0
- package/dist/presentation/group.js +14 -0
- package/dist/presentation/group.module.js +6 -0
- package/dist/presentation/group_module.css +19 -0
- package/dist/presentation/row.d.ts +25 -0
- package/dist/presentation/row.js +8 -0
- package/dist/presentation/row.module.js +5 -0
- package/dist/presentation/row_module.css +18 -0
- package/dist/presentation/tabs.d.ts +25 -0
- package/dist/presentation/tabs.js +39 -0
- package/dist/presentation/tabs.module.js +10 -0
- package/dist/presentation/tabs_module.css +68 -0
- package/dist/react.d.ts +66 -0
- package/dist/react.js +36 -0
- package/dist/services/admin-services-types.d.ts +16 -0
- package/dist/widgets/diff-viewer/diff-modal.d.ts +22 -0
- package/dist/widgets/diff-viewer/diff-modal.js +149 -0
- package/dist/widgets/diff-viewer/diff-modal.module.js +14 -0
- package/dist/widgets/diff-viewer/diff-modal_module.css +56 -0
- package/dist/widgets/status-badge/status-badge.d.ts +25 -0
- package/dist/widgets/status-badge/status-badge.js +37 -0
- package/dist/widgets/status-badge/status-badge.module.js +7 -0
- package/dist/widgets/status-badge/status-badge_module.css +20 -0
- package/package.json +14 -4
- package/src/fields/array/array-field.module.css +48 -0
- package/src/fields/array/array-field.tsx +267 -0
- package/src/fields/blocks/blocks-field.module.css +148 -0
- package/src/fields/blocks/blocks-field.tsx +323 -0
- package/src/fields/checkbox/checkbox-field.module.css +4 -0
- package/src/fields/checkbox/checkbox-field.tsx +54 -0
- package/src/fields/column-formatter.tsx +31 -0
- package/src/fields/date-time-formatter.tsx +22 -0
- package/src/fields/datetime/datetime-field.module.css +13 -0
- package/src/fields/datetime/datetime-field.tsx +54 -0
- package/src/fields/draggable-context-menu.module.css +127 -0
- package/src/fields/draggable-context-menu.tsx +87 -0
- package/src/fields/field-helpers.ts +69 -0
- package/src/fields/field-renderer.module.css +22 -0
- package/src/fields/field-renderer.tsx +288 -0
- package/src/fields/field-services-context.tsx +35 -0
- package/src/fields/field-services-types.ts +68 -0
- package/src/fields/file/file-field.module.css +153 -0
- package/src/fields/file/file-field.tsx +286 -0
- package/src/fields/file/file-upload-field.module.css +101 -0
- package/src/fields/file/file-upload-field.tsx +187 -0
- package/src/fields/group/group-field.module.css +43 -0
- package/src/fields/group/group-field.tsx +84 -0
- package/src/fields/image/image-field.module.css +155 -0
- package/src/fields/image/image-field.tsx +306 -0
- package/src/fields/image/image-upload-field.module.css +123 -0
- package/src/fields/image/image-upload-field.tsx +276 -0
- package/src/fields/local-date-time.tsx +88 -0
- package/src/fields/locale-badge.module.css +37 -0
- package/src/fields/locale-badge.tsx +32 -0
- package/src/fields/numerical/numerical-field.tsx +114 -0
- package/src/fields/relation/relation-display.module.css +36 -0
- package/src/fields/relation/relation-display.tsx +138 -0
- package/src/fields/relation/relation-field.module.css +83 -0
- package/src/fields/relation/relation-field.tsx +211 -0
- package/src/fields/relation/relation-picker.module.css +168 -0
- package/src/fields/relation/relation-picker.tsx +343 -0
- package/src/fields/relation/relation-summary.module.css +55 -0
- package/src/fields/relation/relation-summary.tsx +123 -0
- package/src/fields/select/select-field.module.css +13 -0
- package/src/fields/select/select-field.tsx +61 -0
- package/src/fields/sortable-item.module.css +167 -0
- package/src/fields/sortable-item.tsx +106 -0
- package/src/fields/text/text-field.module.css +13 -0
- package/src/fields/text/text-field.tsx +146 -0
- package/src/fields/text-area/text-area-field.module.css +13 -0
- package/src/fields/text-area/text-area-field.tsx +147 -0
- package/src/fields/use-field-change-handler.ts +112 -0
- package/src/forms/document-actions.module.css +160 -0
- package/src/forms/document-actions.tsx +482 -0
- package/src/forms/form-context.tsx +704 -0
- package/src/forms/form-renderer.module.css +321 -0
- package/src/forms/form-renderer.tsx +891 -0
- package/src/forms/navigation-guard.tsx +98 -0
- package/src/forms/path-widget.module.css +41 -0
- package/src/forms/path-widget.test.tsx +217 -0
- package/src/forms/path-widget.tsx +183 -0
- package/src/forms/upload-executor.ts +192 -0
- package/src/lib/translate-validation-error.ts +56 -0
- package/src/modules/admin-account/commands.ts +13 -0
- package/src/modules/admin-account/components/change-password.tsx +46 -31
- package/src/modules/admin-account/components/container.tsx +83 -38
- package/src/modules/admin-account/components/preferences.module.css +60 -0
- package/src/modules/admin-account/components/preferences.tsx +203 -0
- package/src/modules/admin-account/components/update.tsx +53 -27
- package/src/modules/admin-account/index.ts +3 -0
- package/src/modules/admin-account/schemas.ts +13 -0
- package/src/modules/admin-account/service.ts +12 -0
- package/src/modules/admin-permissions/components/inspector.tsx +22 -14
- package/src/modules/admin-roles/components/create.tsx +51 -23
- package/src/modules/admin-roles/components/permissions.tsx +25 -21
- package/src/modules/admin-roles/components/update.tsx +37 -19
- package/src/modules/admin-users/components/create.tsx +63 -34
- package/src/modules/admin-users/components/roles.tsx +9 -8
- package/src/modules/admin-users/components/set-password.tsx +34 -28
- package/src/modules/admin-users/components/update.tsx +58 -36
- package/src/modules/admin-users/dto.ts +1 -0
- package/src/modules/admin-users/repository.ts +17 -0
- package/src/modules/admin-users/schemas.ts +12 -0
- package/src/modules/auth/components/sign-in-form.tsx +14 -8
- package/src/presentation/group.module.css +41 -0
- package/src/presentation/group.tsx +40 -0
- package/src/presentation/row.module.css +32 -0
- package/src/presentation/row.tsx +33 -0
- package/src/presentation/tabs.module.css +107 -0
- package/src/presentation/tabs.tsx +84 -0
- package/src/react.ts +84 -0
- package/src/services/admin-services-types.ts +18 -0
- package/src/widgets/diff-viewer/diff-modal.module.css +79 -0
- package/src/widgets/diff-viewer/diff-modal.tsx +186 -0
- package/src/widgets/status-badge/status-badge.module.css +31 -0
- package/src/widgets/status-badge/status-badge.tsx +71 -0
package/package.json
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
"name": "@byline/admin",
|
|
3
3
|
"private": false,
|
|
4
4
|
"license": "MPL-2.0",
|
|
5
|
-
"version": "2.
|
|
5
|
+
"version": "2.6.1",
|
|
6
6
|
"engines": {
|
|
7
7
|
"node": ">=20.9.0"
|
|
8
8
|
},
|
|
@@ -37,6 +37,11 @@
|
|
|
37
37
|
"import": "./dist/index.js",
|
|
38
38
|
"require": "./dist/index.js"
|
|
39
39
|
},
|
|
40
|
+
"./react": {
|
|
41
|
+
"types": "./dist/react.d.ts",
|
|
42
|
+
"import": "./dist/react.js",
|
|
43
|
+
"require": "./dist/react.js"
|
|
44
|
+
},
|
|
40
45
|
"./auth": {
|
|
41
46
|
"types": "./dist/modules/auth/index.d.ts",
|
|
42
47
|
"import": "./dist/modules/auth/index.js",
|
|
@@ -137,11 +142,15 @@
|
|
|
137
142
|
"@tanstack/react-form-start": "^1.32.0",
|
|
138
143
|
"classnames": "^2.5.1",
|
|
139
144
|
"jose": "^6.2.3",
|
|
145
|
+
"lodash-es": "^4.18.1",
|
|
146
|
+
"react-diff-viewer-continued": "^4.2.2",
|
|
140
147
|
"uuid": "^14.0.0",
|
|
141
148
|
"zod": "^4.4.3",
|
|
142
|
-
"
|
|
143
|
-
"@byline/core": "2.
|
|
144
|
-
"@byline/
|
|
149
|
+
"zod-form-data": "^3.0.1",
|
|
150
|
+
"@byline/core": "2.6.1",
|
|
151
|
+
"@byline/auth": "2.6.1",
|
|
152
|
+
"@byline/ui": "2.6.1",
|
|
153
|
+
"@byline/i18n": "2.6.1"
|
|
145
154
|
},
|
|
146
155
|
"peerDependencies": {
|
|
147
156
|
"react": "^19.0.0",
|
|
@@ -151,6 +160,7 @@
|
|
|
151
160
|
"@biomejs/biome": "2.4.15",
|
|
152
161
|
"@rsbuild/plugin-react": "^2.0.0",
|
|
153
162
|
"@rslib/core": "^0.21.5",
|
|
163
|
+
"@types/lodash-es": "^4.17.12",
|
|
154
164
|
"@types/node": "^25.9.1",
|
|
155
165
|
"@types/react": "19.2.15",
|
|
156
166
|
"@types/react-dom": "19.2.3",
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ArrayField — homogeneous array of child fields with optional D&D.
|
|
3
|
+
*
|
|
4
|
+
* Override handles:
|
|
5
|
+
* .byline-field-array — outer wrapper
|
|
6
|
+
* .byline-field-array-title — array label heading
|
|
7
|
+
* .byline-field-array-stack — vertical layout for items + add row
|
|
8
|
+
* .byline-field-array-card — disable-sorting fallback card per item
|
|
9
|
+
* .byline-field-array-group-header — sub-group title above grouped fields
|
|
10
|
+
* .byline-field-array-group-fields — vertical stack of fields inside an item
|
|
11
|
+
*/
|
|
12
|
+
|
|
13
|
+
.title,
|
|
14
|
+
:global(.byline-field-array-title) {
|
|
15
|
+
margin-bottom: 0.25rem;
|
|
16
|
+
font-size: 1rem;
|
|
17
|
+
font-weight: var(--font-weight-medium);
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
.stack,
|
|
21
|
+
:global(.byline-field-array-stack) {
|
|
22
|
+
display: flex;
|
|
23
|
+
flex-direction: column;
|
|
24
|
+
gap: var(--spacing-16);
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
.card,
|
|
28
|
+
:global(.byline-field-array-card) {
|
|
29
|
+
display: flex;
|
|
30
|
+
flex-direction: column;
|
|
31
|
+
gap: var(--spacing-16);
|
|
32
|
+
padding: var(--spacing-16);
|
|
33
|
+
border: var(--border-width-thin) dashed var(--gray-600);
|
|
34
|
+
border-radius: var(--border-radius-md);
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
.group-header,
|
|
38
|
+
:global(.byline-field-array-group-header) {
|
|
39
|
+
font-size: 0.9rem;
|
|
40
|
+
font-weight: var(--font-weight-medium);
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
.group-fields,
|
|
44
|
+
:global(.byline-field-array-group-fields) {
|
|
45
|
+
display: flex;
|
|
46
|
+
flex-direction: column;
|
|
47
|
+
gap: var(--spacing-16);
|
|
48
|
+
}
|
|
@@ -0,0 +1,267 @@
|
|
|
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, useState } from 'react'
|
|
10
|
+
|
|
11
|
+
import type { ArrayField as ArrayFieldType, Field } from '@byline/core'
|
|
12
|
+
import { useTranslation } from '@byline/i18n/react'
|
|
13
|
+
import { DraggableSortable, IconButton, moveItem, PlusIcon } from '@byline/ui/react'
|
|
14
|
+
import cx from 'classnames'
|
|
15
|
+
|
|
16
|
+
import { defaultScalarForField } from '../../fields/field-helpers'
|
|
17
|
+
import { FieldRenderer } from '../../fields/field-renderer'
|
|
18
|
+
import { SortableItem } from '../../fields/sortable-item'
|
|
19
|
+
import { useFormContext } from '../../forms/form-context'
|
|
20
|
+
import styles from './array-field.module.css'
|
|
21
|
+
|
|
22
|
+
// ---------------------------------------------------------------------------
|
|
23
|
+
// ArrayField — renders `type: 'array'` fields. Children are homogeneous:
|
|
24
|
+
// either single value fields or a single group definition. Supports D&D.
|
|
25
|
+
// ---------------------------------------------------------------------------
|
|
26
|
+
|
|
27
|
+
export const ArrayField = ({
|
|
28
|
+
field,
|
|
29
|
+
defaultValue,
|
|
30
|
+
path,
|
|
31
|
+
disableSorting = false,
|
|
32
|
+
}: {
|
|
33
|
+
field: ArrayFieldType
|
|
34
|
+
defaultValue: any
|
|
35
|
+
path: string
|
|
36
|
+
disableSorting?: boolean
|
|
37
|
+
}) => {
|
|
38
|
+
const { appendPatch, getFieldValue, getFieldValues, setFieldStore } = useFormContext()
|
|
39
|
+
const { t } = useTranslation('byline-admin')
|
|
40
|
+
const [items, setItems] = useState<{ id: string; data: any }[]>([])
|
|
41
|
+
|
|
42
|
+
useEffect(() => {
|
|
43
|
+
if (Array.isArray(defaultValue)) {
|
|
44
|
+
setItems(
|
|
45
|
+
defaultValue.map((item: any) => ({
|
|
46
|
+
id:
|
|
47
|
+
item && typeof item === 'object' && 'id' in item
|
|
48
|
+
? String((item as { id: string }).id)
|
|
49
|
+
: item && typeof item === 'object' && '_id' in item
|
|
50
|
+
? String((item as { _id: string })._id)
|
|
51
|
+
: crypto.randomUUID(),
|
|
52
|
+
data: item,
|
|
53
|
+
}))
|
|
54
|
+
)
|
|
55
|
+
} else {
|
|
56
|
+
setItems([])
|
|
57
|
+
}
|
|
58
|
+
}, [defaultValue])
|
|
59
|
+
|
|
60
|
+
const handleDragEnd = ({
|
|
61
|
+
moveFromIndex,
|
|
62
|
+
moveToIndex,
|
|
63
|
+
}: {
|
|
64
|
+
moveFromIndex: number
|
|
65
|
+
moveToIndex: number
|
|
66
|
+
}) => {
|
|
67
|
+
setItems((prev) => moveItem(prev, moveFromIndex, moveToIndex))
|
|
68
|
+
const currentArray = (getFieldValue(path) ?? defaultValue) as any[]
|
|
69
|
+
|
|
70
|
+
if (Array.isArray(currentArray)) {
|
|
71
|
+
const clampedFrom = Math.max(0, Math.min(moveFromIndex, currentArray.length - 1))
|
|
72
|
+
const clampedTo = Math.max(0, Math.min(moveToIndex, currentArray.length - 1))
|
|
73
|
+
if (clampedFrom === clampedTo) return
|
|
74
|
+
|
|
75
|
+
const item = currentArray[clampedFrom]
|
|
76
|
+
const itemId =
|
|
77
|
+
item && typeof item === 'object' && 'id' in item
|
|
78
|
+
? String((item as { id: string }).id)
|
|
79
|
+
: String(clampedFrom)
|
|
80
|
+
|
|
81
|
+
appendPatch({
|
|
82
|
+
kind: 'array.move',
|
|
83
|
+
path: path,
|
|
84
|
+
itemId,
|
|
85
|
+
toIndex: clampedTo,
|
|
86
|
+
})
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
const handleAddItem = async (atIndex?: number) => {
|
|
91
|
+
const childFields = field.fields ?? []
|
|
92
|
+
if (childFields.length === 0) return
|
|
93
|
+
|
|
94
|
+
const newId = crypto.randomUUID()
|
|
95
|
+
|
|
96
|
+
// Build a new item with default values for ALL child fields
|
|
97
|
+
const newItem: Record<string, any> = {}
|
|
98
|
+
for (const childField of childFields) {
|
|
99
|
+
if (childField.type === 'group' && childField.fields && childField.fields.length > 0) {
|
|
100
|
+
// Group child — build a nested object with defaults for each inner field
|
|
101
|
+
const groupObj: Record<string, any> = {}
|
|
102
|
+
for (const innerField of childField.fields as Field[]) {
|
|
103
|
+
groupObj[innerField.name] = await defaultScalarForField(innerField, getFieldValues)
|
|
104
|
+
}
|
|
105
|
+
newItem[childField.name] = groupObj
|
|
106
|
+
} else {
|
|
107
|
+
newItem[childField.name] = await defaultScalarForField(childField, getFieldValues)
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
const currentArray = (getFieldValue(path) ?? defaultValue) as any[]
|
|
112
|
+
const insertAt = atIndex != null ? atIndex : currentArray ? currentArray.length : 0
|
|
113
|
+
|
|
114
|
+
const newItemWrapper = { id: newId, data: newItem }
|
|
115
|
+
setItems((prev) => {
|
|
116
|
+
const next = [...prev]
|
|
117
|
+
next.splice(insertAt, 0, newItemWrapper)
|
|
118
|
+
return next
|
|
119
|
+
})
|
|
120
|
+
|
|
121
|
+
appendPatch({
|
|
122
|
+
kind: 'array.insert',
|
|
123
|
+
path: path,
|
|
124
|
+
index: insertAt,
|
|
125
|
+
item: newItem,
|
|
126
|
+
})
|
|
127
|
+
|
|
128
|
+
const newArrayValue = currentArray ? [...currentArray] : []
|
|
129
|
+
newArrayValue.splice(insertAt, 0, newItem)
|
|
130
|
+
setFieldStore(path, newArrayValue)
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
const handleRemoveItem = (index: number) => {
|
|
134
|
+
const currentArray = (getFieldValue(path) ?? defaultValue) as any[]
|
|
135
|
+
if (!Array.isArray(currentArray) || index < 0 || index >= currentArray.length) return
|
|
136
|
+
|
|
137
|
+
const item = currentArray[index]
|
|
138
|
+
const itemId =
|
|
139
|
+
item && typeof item === 'object' && 'id' in item
|
|
140
|
+
? String((item as { id: string }).id)
|
|
141
|
+
: String(index)
|
|
142
|
+
|
|
143
|
+
setItems((prev) => prev.filter((_, i) => i !== index))
|
|
144
|
+
|
|
145
|
+
appendPatch({
|
|
146
|
+
kind: 'array.remove',
|
|
147
|
+
path: path,
|
|
148
|
+
itemId,
|
|
149
|
+
})
|
|
150
|
+
|
|
151
|
+
const newArrayValue = [...currentArray]
|
|
152
|
+
newArrayValue.splice(index, 1)
|
|
153
|
+
setFieldStore(path, newArrayValue)
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
const handleInsertBelow = (index: number) => {
|
|
157
|
+
void handleAddItem(index + 1)
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
const renderItem = (itemWrapper: { id: string; data: any }, index: number) => {
|
|
161
|
+
const item = itemWrapper.data
|
|
162
|
+
const arrayElementPath = `${path}[${index}]`
|
|
163
|
+
|
|
164
|
+
if (!item || typeof item !== 'object') return null
|
|
165
|
+
|
|
166
|
+
const childFields = field.fields ?? []
|
|
167
|
+
if (childFields.length === 0) return null
|
|
168
|
+
|
|
169
|
+
// Render ALL child fields defined in the array's field schema
|
|
170
|
+
const innerBody = childFields.map((childField) => {
|
|
171
|
+
const initial = item[childField.name]
|
|
172
|
+
|
|
173
|
+
if (childField.type === 'group' && childField.fields && childField.fields.length > 0) {
|
|
174
|
+
// Group child — render its inner fields with the group's sub-object
|
|
175
|
+
const groupData = initial && typeof initial === 'object' ? initial : {}
|
|
176
|
+
return (
|
|
177
|
+
<div
|
|
178
|
+
key={childField.name}
|
|
179
|
+
className={cx('byline-field-array-group-fields', styles['group-fields'])}
|
|
180
|
+
>
|
|
181
|
+
{childField.label && (
|
|
182
|
+
<h4 className={cx('byline-field-array-group-header', styles['group-header'])}>
|
|
183
|
+
{childField.label}
|
|
184
|
+
</h4>
|
|
185
|
+
)}
|
|
186
|
+
{(childField.fields as Field[]).map((innerField) => (
|
|
187
|
+
<FieldRenderer
|
|
188
|
+
key={innerField.name}
|
|
189
|
+
field={innerField}
|
|
190
|
+
defaultValue={groupData[innerField.name]}
|
|
191
|
+
basePath={`${arrayElementPath}.${childField.name}`}
|
|
192
|
+
disableSorting={true}
|
|
193
|
+
/>
|
|
194
|
+
))}
|
|
195
|
+
</div>
|
|
196
|
+
)
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
return (
|
|
200
|
+
<FieldRenderer
|
|
201
|
+
key={childField.name}
|
|
202
|
+
field={childField}
|
|
203
|
+
defaultValue={initial}
|
|
204
|
+
basePath={arrayElementPath}
|
|
205
|
+
disableSorting={true}
|
|
206
|
+
/>
|
|
207
|
+
)
|
|
208
|
+
})
|
|
209
|
+
|
|
210
|
+
const label = field.label ?? field.name
|
|
211
|
+
|
|
212
|
+
if (disableSorting) {
|
|
213
|
+
return (
|
|
214
|
+
<div key={itemWrapper.id} className={cx('byline-field-array-card', styles.card)}>
|
|
215
|
+
<div className={cx('byline-field-array-group-fields', styles['group-fields'])}>
|
|
216
|
+
{innerBody}
|
|
217
|
+
</div>
|
|
218
|
+
</div>
|
|
219
|
+
)
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
return (
|
|
223
|
+
<SortableItem
|
|
224
|
+
key={itemWrapper.id}
|
|
225
|
+
id={itemWrapper.id}
|
|
226
|
+
label={label}
|
|
227
|
+
onAddBelow={() => handleInsertBelow(index)}
|
|
228
|
+
onRemove={() => handleRemoveItem(index)}
|
|
229
|
+
>
|
|
230
|
+
<div className={cx('byline-field-array-group-fields', styles['group-fields'])}>
|
|
231
|
+
{innerBody}
|
|
232
|
+
</div>
|
|
233
|
+
</SortableItem>
|
|
234
|
+
)
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
return (
|
|
238
|
+
<div className={`byline-field-array ${field.name}`}>
|
|
239
|
+
{!disableSorting && field.label && (
|
|
240
|
+
<h3 className={cx('byline-field-array-title', styles.title)}>{field.label}</h3>
|
|
241
|
+
)}
|
|
242
|
+
{disableSorting ? (
|
|
243
|
+
<div className={cx('byline-field-array-stack', styles.stack)}>
|
|
244
|
+
{items.map((item, index) => renderItem(item, index))}
|
|
245
|
+
</div>
|
|
246
|
+
) : (
|
|
247
|
+
<DraggableSortable
|
|
248
|
+
ids={items.map((i) => i.id)}
|
|
249
|
+
onDragEnd={handleDragEnd}
|
|
250
|
+
className={cx('byline-field-array-stack', styles.stack)}
|
|
251
|
+
>
|
|
252
|
+
{items.map((item, index) => renderItem(item, index))}
|
|
253
|
+
<span>
|
|
254
|
+
<IconButton
|
|
255
|
+
onClick={() => {
|
|
256
|
+
void handleAddItem()
|
|
257
|
+
}}
|
|
258
|
+
aria-label={t('fields.array.addItemAriaLabel')}
|
|
259
|
+
>
|
|
260
|
+
<PlusIcon />
|
|
261
|
+
</IconButton>
|
|
262
|
+
</span>
|
|
263
|
+
</DraggableSortable>
|
|
264
|
+
)}
|
|
265
|
+
</div>
|
|
266
|
+
)
|
|
267
|
+
}
|
|
@@ -0,0 +1,148 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* BlocksField — heterogeneous array picked from a modal of block variants.
|
|
3
|
+
*
|
|
4
|
+
* Override handles:
|
|
5
|
+
* .byline-field-blocks — outer wrapper
|
|
6
|
+
* .byline-field-blocks-title — block-list label heading
|
|
7
|
+
* .byline-field-blocks-stack — vertical stack of blocks + add row
|
|
8
|
+
* .byline-field-blocks-add-row — add-button row at the bottom
|
|
9
|
+
* .byline-field-blocks-modal-head — picker modal header
|
|
10
|
+
* .byline-field-blocks-modal-title — picker modal title
|
|
11
|
+
* .byline-field-blocks-grid — grid of variant cards
|
|
12
|
+
* .byline-field-blocks-card — variant card wrapper
|
|
13
|
+
* .byline-field-blocks-card-head — card title row
|
|
14
|
+
* .byline-field-blocks-card-title — card title text
|
|
15
|
+
* .byline-field-blocks-card-index — small numeric index pill
|
|
16
|
+
* .byline-field-blocks-card-code — variant blockType code line
|
|
17
|
+
* .byline-field-blocks-card-body — variant description text
|
|
18
|
+
* .byline-field-blocks-card-cursor — cursor: pointer hint on the modal content
|
|
19
|
+
*/
|
|
20
|
+
|
|
21
|
+
.title,
|
|
22
|
+
:global(.byline-field-blocks-title) {
|
|
23
|
+
margin-bottom: 0.25rem;
|
|
24
|
+
font-size: 1rem;
|
|
25
|
+
font-weight: var(--font-weight-medium);
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
.stack,
|
|
29
|
+
:global(.byline-field-blocks-stack) {
|
|
30
|
+
display: flex;
|
|
31
|
+
flex-direction: column;
|
|
32
|
+
gap: var(--spacing-16);
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
.add-row,
|
|
36
|
+
:global(.byline-field-blocks-add-row) {
|
|
37
|
+
display: flex;
|
|
38
|
+
align-items: center;
|
|
39
|
+
gap: var(--spacing-8);
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
.modal-head,
|
|
43
|
+
:global(.byline-field-blocks-modal-head) {
|
|
44
|
+
padding-top: 1rem;
|
|
45
|
+
margin-bottom: var(--spacing-8);
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
.modal-title,
|
|
49
|
+
:global(.byline-field-blocks-modal-title) {
|
|
50
|
+
margin: 0 0 var(--spacing-8) 0;
|
|
51
|
+
font-size: var(--font-size-2xl);
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
.modal-content,
|
|
55
|
+
:global(.byline-field-blocks-card-cursor) {
|
|
56
|
+
cursor: pointer;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
.grid,
|
|
60
|
+
:global(.byline-field-blocks-grid) {
|
|
61
|
+
display: grid;
|
|
62
|
+
grid-template-columns: 1fr;
|
|
63
|
+
gap: var(--spacing-16);
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
@media (min-width: 40rem) {
|
|
67
|
+
.grid,
|
|
68
|
+
:global(.byline-field-blocks-grid) {
|
|
69
|
+
grid-template-columns: repeat(2, 1fr);
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
@media (min-width: 48rem) {
|
|
74
|
+
.grid,
|
|
75
|
+
:global(.byline-field-blocks-grid) {
|
|
76
|
+
grid-template-columns: repeat(3, 1fr);
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
.card,
|
|
81
|
+
:global(.byline-field-blocks-card) {
|
|
82
|
+
margin-bottom: var(--spacing-8);
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
.card-head,
|
|
86
|
+
:global(.byline-field-blocks-card-head) {
|
|
87
|
+
display: flex;
|
|
88
|
+
align-items: flex-start;
|
|
89
|
+
justify-content: space-between;
|
|
90
|
+
gap: var(--spacing-8);
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
.card-title,
|
|
94
|
+
:global(.byline-field-blocks-card-title) {
|
|
95
|
+
font-size: 1.3rem;
|
|
96
|
+
line-height: var(--line-height-tight);
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
.card-index,
|
|
100
|
+
:global(.byline-field-blocks-card-index) {
|
|
101
|
+
flex-shrink: 0;
|
|
102
|
+
display: inline-flex;
|
|
103
|
+
align-items: center;
|
|
104
|
+
justify-content: center;
|
|
105
|
+
width: 1.25rem;
|
|
106
|
+
height: 1.25rem;
|
|
107
|
+
margin-top: 0.125rem;
|
|
108
|
+
border: var(--border-width-thin) var(--border-style-solid) var(--gray-100);
|
|
109
|
+
border-radius: var(--border-radius-full);
|
|
110
|
+
color: var(--gray-400);
|
|
111
|
+
font-size: 10px;
|
|
112
|
+
font-weight: var(--font-weight-semibold);
|
|
113
|
+
font-variant-numeric: tabular-nums;
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
.card-code,
|
|
117
|
+
:global(.byline-field-blocks-card-code) {
|
|
118
|
+
display: block;
|
|
119
|
+
margin-top: 0;
|
|
120
|
+
color: var(--gray-400);
|
|
121
|
+
font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
|
|
122
|
+
font-size: 12px;
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
.card-body,
|
|
126
|
+
:global(.byline-field-blocks-card-body) {
|
|
127
|
+
color: var(--gray-500);
|
|
128
|
+
font-size: var(--font-size-sm);
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
/* ─── Dark theme variants ───────────────────────────────────── */
|
|
132
|
+
|
|
133
|
+
:is([data-theme="dark"], :global(.dark)) {
|
|
134
|
+
.card-index,
|
|
135
|
+
:global(.byline-field-blocks-card-index) {
|
|
136
|
+
border-color: var(--gray-700);
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
.card-code,
|
|
140
|
+
:global(.byline-field-blocks-card-code) {
|
|
141
|
+
color: var(--gray-500);
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
.card-body,
|
|
145
|
+
:global(.byline-field-blocks-card-body) {
|
|
146
|
+
color: var(--gray-200);
|
|
147
|
+
}
|
|
148
|
+
}
|