@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
|
@@ -0,0 +1,14 @@
|
|
|
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
|
+
import type { ArrayField as ArrayFieldType } from '@byline/core';
|
|
9
|
+
export declare const ArrayField: ({ field, defaultValue, path, disableSorting, }: {
|
|
10
|
+
field: ArrayFieldType;
|
|
11
|
+
defaultValue: any;
|
|
12
|
+
path: string;
|
|
13
|
+
disableSorting?: boolean;
|
|
14
|
+
}) => import("react").JSX.Element;
|
|
@@ -0,0 +1,177 @@
|
|
|
1
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { useEffect, useState } from "react";
|
|
3
|
+
import { useTranslation } from "@byline/i18n/react";
|
|
4
|
+
import { DraggableSortable, IconButton, PlusIcon, moveItem } from "@byline/ui/react";
|
|
5
|
+
import classnames from "classnames";
|
|
6
|
+
import { defaultScalarForField } from "../field-helpers.js";
|
|
7
|
+
import { FieldRenderer } from "../field-renderer.js";
|
|
8
|
+
import { SortableItem } from "../sortable-item.js";
|
|
9
|
+
import { useFormContext } from "../../forms/form-context.js";
|
|
10
|
+
import array_field_module from "./array-field.module.js";
|
|
11
|
+
const ArrayField = ({ field, defaultValue, path, disableSorting = false })=>{
|
|
12
|
+
const { appendPatch, getFieldValue, getFieldValues, setFieldStore } = useFormContext();
|
|
13
|
+
const { t } = useTranslation('byline-admin');
|
|
14
|
+
const [items, setItems] = useState([]);
|
|
15
|
+
useEffect(()=>{
|
|
16
|
+
Array.isArray(defaultValue) ? setItems(defaultValue.map((item)=>({
|
|
17
|
+
id: item && 'object' == typeof item && 'id' in item ? String(item.id) : item && 'object' == typeof item && '_id' in item ? String(item._id) : crypto.randomUUID(),
|
|
18
|
+
data: item
|
|
19
|
+
}))) : setItems([]);
|
|
20
|
+
}, [
|
|
21
|
+
defaultValue
|
|
22
|
+
]);
|
|
23
|
+
const handleDragEnd = ({ moveFromIndex, moveToIndex })=>{
|
|
24
|
+
setItems((prev)=>moveItem(prev, moveFromIndex, moveToIndex));
|
|
25
|
+
const currentArray = getFieldValue(path) ?? defaultValue;
|
|
26
|
+
if (Array.isArray(currentArray)) {
|
|
27
|
+
const clampedFrom = Math.max(0, Math.min(moveFromIndex, currentArray.length - 1));
|
|
28
|
+
const clampedTo = Math.max(0, Math.min(moveToIndex, currentArray.length - 1));
|
|
29
|
+
if (clampedFrom === clampedTo) return;
|
|
30
|
+
const item = currentArray[clampedFrom];
|
|
31
|
+
const itemId = item && 'object' == typeof item && 'id' in item ? String(item.id) : String(clampedFrom);
|
|
32
|
+
appendPatch({
|
|
33
|
+
kind: 'array.move',
|
|
34
|
+
path: path,
|
|
35
|
+
itemId,
|
|
36
|
+
toIndex: clampedTo
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
};
|
|
40
|
+
const handleAddItem = async (atIndex)=>{
|
|
41
|
+
const childFields = field.fields ?? [];
|
|
42
|
+
if (0 === childFields.length) return;
|
|
43
|
+
const newId = crypto.randomUUID();
|
|
44
|
+
const newItem = {};
|
|
45
|
+
for (const childField of childFields)if ('group' === childField.type && childField.fields && childField.fields.length > 0) {
|
|
46
|
+
const groupObj = {};
|
|
47
|
+
for (const innerField of childField.fields)groupObj[innerField.name] = await defaultScalarForField(innerField, getFieldValues);
|
|
48
|
+
newItem[childField.name] = groupObj;
|
|
49
|
+
} else newItem[childField.name] = await defaultScalarForField(childField, getFieldValues);
|
|
50
|
+
const currentArray = getFieldValue(path) ?? defaultValue;
|
|
51
|
+
const insertAt = null != atIndex ? atIndex : currentArray ? currentArray.length : 0;
|
|
52
|
+
const newItemWrapper = {
|
|
53
|
+
id: newId,
|
|
54
|
+
data: newItem
|
|
55
|
+
};
|
|
56
|
+
setItems((prev)=>{
|
|
57
|
+
const next = [
|
|
58
|
+
...prev
|
|
59
|
+
];
|
|
60
|
+
next.splice(insertAt, 0, newItemWrapper);
|
|
61
|
+
return next;
|
|
62
|
+
});
|
|
63
|
+
appendPatch({
|
|
64
|
+
kind: 'array.insert',
|
|
65
|
+
path: path,
|
|
66
|
+
index: insertAt,
|
|
67
|
+
item: newItem
|
|
68
|
+
});
|
|
69
|
+
const newArrayValue = currentArray ? [
|
|
70
|
+
...currentArray
|
|
71
|
+
] : [];
|
|
72
|
+
newArrayValue.splice(insertAt, 0, newItem);
|
|
73
|
+
setFieldStore(path, newArrayValue);
|
|
74
|
+
};
|
|
75
|
+
const handleRemoveItem = (index)=>{
|
|
76
|
+
const currentArray = getFieldValue(path) ?? defaultValue;
|
|
77
|
+
if (!Array.isArray(currentArray) || index < 0 || index >= currentArray.length) return;
|
|
78
|
+
const item = currentArray[index];
|
|
79
|
+
const itemId = item && 'object' == typeof item && 'id' in item ? String(item.id) : String(index);
|
|
80
|
+
setItems((prev)=>prev.filter((_, i)=>i !== index));
|
|
81
|
+
appendPatch({
|
|
82
|
+
kind: 'array.remove',
|
|
83
|
+
path: path,
|
|
84
|
+
itemId
|
|
85
|
+
});
|
|
86
|
+
const newArrayValue = [
|
|
87
|
+
...currentArray
|
|
88
|
+
];
|
|
89
|
+
newArrayValue.splice(index, 1);
|
|
90
|
+
setFieldStore(path, newArrayValue);
|
|
91
|
+
};
|
|
92
|
+
const handleInsertBelow = (index)=>{
|
|
93
|
+
handleAddItem(index + 1);
|
|
94
|
+
};
|
|
95
|
+
const renderItem = (itemWrapper, index)=>{
|
|
96
|
+
const item = itemWrapper.data;
|
|
97
|
+
const arrayElementPath = `${path}[${index}]`;
|
|
98
|
+
if (!item || 'object' != typeof item) return null;
|
|
99
|
+
const childFields = field.fields ?? [];
|
|
100
|
+
if (0 === childFields.length) return null;
|
|
101
|
+
const innerBody = childFields.map((childField)=>{
|
|
102
|
+
const initial = item[childField.name];
|
|
103
|
+
if ('group' === childField.type && childField.fields && childField.fields.length > 0) {
|
|
104
|
+
const groupData = initial && 'object' == typeof initial ? initial : {};
|
|
105
|
+
return /*#__PURE__*/ jsxs("div", {
|
|
106
|
+
className: classnames('byline-field-array-group-fields', array_field_module["group-fields"]),
|
|
107
|
+
children: [
|
|
108
|
+
childField.label && /*#__PURE__*/ jsx("h4", {
|
|
109
|
+
className: classnames('byline-field-array-group-header', array_field_module["group-header"]),
|
|
110
|
+
children: childField.label
|
|
111
|
+
}),
|
|
112
|
+
childField.fields.map((innerField)=>/*#__PURE__*/ jsx(FieldRenderer, {
|
|
113
|
+
field: innerField,
|
|
114
|
+
defaultValue: groupData[innerField.name],
|
|
115
|
+
basePath: `${arrayElementPath}.${childField.name}`,
|
|
116
|
+
disableSorting: true
|
|
117
|
+
}, innerField.name))
|
|
118
|
+
]
|
|
119
|
+
}, childField.name);
|
|
120
|
+
}
|
|
121
|
+
return /*#__PURE__*/ jsx(FieldRenderer, {
|
|
122
|
+
field: childField,
|
|
123
|
+
defaultValue: initial,
|
|
124
|
+
basePath: arrayElementPath,
|
|
125
|
+
disableSorting: true
|
|
126
|
+
}, childField.name);
|
|
127
|
+
});
|
|
128
|
+
const label = field.label ?? field.name;
|
|
129
|
+
if (disableSorting) return /*#__PURE__*/ jsx("div", {
|
|
130
|
+
className: classnames('byline-field-array-card', array_field_module.card),
|
|
131
|
+
children: /*#__PURE__*/ jsx("div", {
|
|
132
|
+
className: classnames('byline-field-array-group-fields', array_field_module["group-fields"]),
|
|
133
|
+
children: innerBody
|
|
134
|
+
})
|
|
135
|
+
}, itemWrapper.id);
|
|
136
|
+
return /*#__PURE__*/ jsx(SortableItem, {
|
|
137
|
+
id: itemWrapper.id,
|
|
138
|
+
label: label,
|
|
139
|
+
onAddBelow: ()=>handleInsertBelow(index),
|
|
140
|
+
onRemove: ()=>handleRemoveItem(index),
|
|
141
|
+
children: /*#__PURE__*/ jsx("div", {
|
|
142
|
+
className: classnames('byline-field-array-group-fields', array_field_module["group-fields"]),
|
|
143
|
+
children: innerBody
|
|
144
|
+
})
|
|
145
|
+
}, itemWrapper.id);
|
|
146
|
+
};
|
|
147
|
+
return /*#__PURE__*/ jsxs("div", {
|
|
148
|
+
className: `byline-field-array ${field.name}`,
|
|
149
|
+
children: [
|
|
150
|
+
!disableSorting && field.label && /*#__PURE__*/ jsx("h3", {
|
|
151
|
+
className: classnames('byline-field-array-title', array_field_module.title),
|
|
152
|
+
children: field.label
|
|
153
|
+
}),
|
|
154
|
+
disableSorting ? /*#__PURE__*/ jsx("div", {
|
|
155
|
+
className: classnames('byline-field-array-stack', array_field_module.stack),
|
|
156
|
+
children: items.map((item, index)=>renderItem(item, index))
|
|
157
|
+
}) : /*#__PURE__*/ jsxs(DraggableSortable, {
|
|
158
|
+
ids: items.map((i)=>i.id),
|
|
159
|
+
onDragEnd: handleDragEnd,
|
|
160
|
+
className: classnames('byline-field-array-stack', array_field_module.stack),
|
|
161
|
+
children: [
|
|
162
|
+
items.map((item, index)=>renderItem(item, index)),
|
|
163
|
+
/*#__PURE__*/ jsx("span", {
|
|
164
|
+
children: /*#__PURE__*/ jsx(IconButton, {
|
|
165
|
+
onClick: ()=>{
|
|
166
|
+
handleAddItem();
|
|
167
|
+
},
|
|
168
|
+
"aria-label": t('fields.array.addItemAriaLabel'),
|
|
169
|
+
children: /*#__PURE__*/ jsx(PlusIcon, {})
|
|
170
|
+
})
|
|
171
|
+
})
|
|
172
|
+
]
|
|
173
|
+
})
|
|
174
|
+
]
|
|
175
|
+
});
|
|
176
|
+
};
|
|
177
|
+
export { ArrayField };
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import "./array-field_module.css";
|
|
2
|
+
const array_field_module = {
|
|
3
|
+
title: "title-HMJs1n",
|
|
4
|
+
stack: "stack-emBcXW",
|
|
5
|
+
card: "card-j_6w_O",
|
|
6
|
+
"group-header": "group-header-KJxpIV",
|
|
7
|
+
groupHeader: "group-header-KJxpIV",
|
|
8
|
+
"group-fields": "group-fields-Bmi_hA",
|
|
9
|
+
groupFields: "group-fields-Bmi_hA"
|
|
10
|
+
};
|
|
11
|
+
export default array_field_module;
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
:is(.title-HMJs1n, .byline-field-array-title) {
|
|
2
|
+
font-size: 1rem;
|
|
3
|
+
font-weight: var(--font-weight-medium);
|
|
4
|
+
margin-bottom: .25rem;
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
:is(.stack-emBcXW, .byline-field-array-stack) {
|
|
8
|
+
gap: var(--spacing-16);
|
|
9
|
+
flex-direction: column;
|
|
10
|
+
display: flex;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
:is(.card-j_6w_O, .byline-field-array-card) {
|
|
14
|
+
gap: var(--spacing-16);
|
|
15
|
+
padding: var(--spacing-16);
|
|
16
|
+
border: var(--border-width-thin) dashed var(--gray-600);
|
|
17
|
+
border-radius: var(--border-radius-md);
|
|
18
|
+
flex-direction: column;
|
|
19
|
+
display: flex;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
:is(.group-header-KJxpIV, .byline-field-array-group-header) {
|
|
23
|
+
font-size: .9rem;
|
|
24
|
+
font-weight: var(--font-weight-medium);
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
:is(.group-fields-Bmi_hA, .byline-field-array-group-fields) {
|
|
28
|
+
gap: var(--spacing-16);
|
|
29
|
+
flex-direction: column;
|
|
30
|
+
display: flex;
|
|
31
|
+
}
|
|
32
|
+
|
|
@@ -0,0 +1,13 @@
|
|
|
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
|
+
import type { BlocksField as BlocksFieldType } from '@byline/core';
|
|
9
|
+
export declare const BlocksField: ({ field, defaultValue, path, }: {
|
|
10
|
+
field: BlocksFieldType;
|
|
11
|
+
defaultValue: any;
|
|
12
|
+
path: string;
|
|
13
|
+
}) => import("react").JSX.Element;
|
|
@@ -0,0 +1,245 @@
|
|
|
1
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { useEffect, useMemo, useState } from "react";
|
|
3
|
+
import { useTranslation } from "@byline/i18n/react";
|
|
4
|
+
import { Card, CloseIcon, DraggableSortable, IconButton, Modal, PlusIcon, moveItem } from "@byline/ui/react";
|
|
5
|
+
import classnames from "classnames";
|
|
6
|
+
import { defaultScalarForField } from "../field-helpers.js";
|
|
7
|
+
import { GroupField } from "../group/group-field.js";
|
|
8
|
+
import { SortableItem } from "../sortable-item.js";
|
|
9
|
+
import { useFormContext } from "../../forms/form-context.js";
|
|
10
|
+
import blocks_field_module from "./blocks-field.module.js";
|
|
11
|
+
const BlocksField = ({ field, defaultValue, path })=>{
|
|
12
|
+
const { appendPatch, getFieldValue, getFieldValues, setFieldStore } = useFormContext();
|
|
13
|
+
const { t } = useTranslation('byline-admin');
|
|
14
|
+
const [items, setItems] = useState([]);
|
|
15
|
+
const [showAddBlockModal, setShowAddBlockModal] = useState(false);
|
|
16
|
+
const [pendingInsertIndex, setPendingInsertIndex] = useState(null);
|
|
17
|
+
const availableBlocks = useMemo(()=>field.blocks ?? [], [
|
|
18
|
+
field.blocks
|
|
19
|
+
]);
|
|
20
|
+
const [selectedBlockName, setSelectedBlockName] = useState(()=>availableBlocks[0]?.blockType ?? '');
|
|
21
|
+
useEffect(()=>{
|
|
22
|
+
if (null == selectedBlockName || !availableBlocks.some((b)=>b.blockType === selectedBlockName)) setSelectedBlockName(availableBlocks[0]?.blockType ?? '');
|
|
23
|
+
}, [
|
|
24
|
+
availableBlocks,
|
|
25
|
+
selectedBlockName
|
|
26
|
+
]);
|
|
27
|
+
useEffect(()=>{
|
|
28
|
+
Array.isArray(defaultValue) ? setItems(defaultValue.map((item)=>({
|
|
29
|
+
id: item && 'object' == typeof item && '_id' in item ? String(item._id) : crypto.randomUUID(),
|
|
30
|
+
data: item
|
|
31
|
+
}))) : setItems([]);
|
|
32
|
+
}, [
|
|
33
|
+
defaultValue
|
|
34
|
+
]);
|
|
35
|
+
const handleDragEnd = ({ moveFromIndex, moveToIndex })=>{
|
|
36
|
+
setItems((prev)=>moveItem(prev, moveFromIndex, moveToIndex));
|
|
37
|
+
const currentArray = getFieldValue(path) ?? defaultValue;
|
|
38
|
+
if (Array.isArray(currentArray)) {
|
|
39
|
+
const clampedFrom = Math.max(0, Math.min(moveFromIndex, currentArray.length - 1));
|
|
40
|
+
const clampedTo = Math.max(0, Math.min(moveToIndex, currentArray.length - 1));
|
|
41
|
+
if (clampedFrom === clampedTo) return;
|
|
42
|
+
const item = currentArray[clampedFrom];
|
|
43
|
+
const itemId = item && 'object' == typeof item && '_id' in item ? String(item._id) : String(clampedFrom);
|
|
44
|
+
appendPatch({
|
|
45
|
+
kind: 'array.move',
|
|
46
|
+
path: path,
|
|
47
|
+
itemId,
|
|
48
|
+
toIndex: clampedTo
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
};
|
|
52
|
+
const handleAddItem = async (forcedVariantName, atIndex)=>{
|
|
53
|
+
setShowAddBlockModal(false);
|
|
54
|
+
setPendingInsertIndex(null);
|
|
55
|
+
const variant = (null != forcedVariantName ? availableBlocks.find((v)=>v.blockType === forcedVariantName) : void 0) ?? availableBlocks[0];
|
|
56
|
+
if (!variant) return;
|
|
57
|
+
const compositeFields = variant.fields ?? [];
|
|
58
|
+
const newId = crypto.randomUUID();
|
|
59
|
+
const newItem = {
|
|
60
|
+
_id: newId,
|
|
61
|
+
_type: variant.blockType
|
|
62
|
+
};
|
|
63
|
+
for (const f of compositeFields)newItem[f.name] = await defaultScalarForField(f, getFieldValues);
|
|
64
|
+
const currentArray = getFieldValue(path) ?? defaultValue;
|
|
65
|
+
const insertAt = null != atIndex ? atIndex : currentArray ? currentArray.length : 0;
|
|
66
|
+
const newItemWrapper = {
|
|
67
|
+
id: newId,
|
|
68
|
+
data: newItem
|
|
69
|
+
};
|
|
70
|
+
setItems((prev)=>{
|
|
71
|
+
const next = [
|
|
72
|
+
...prev
|
|
73
|
+
];
|
|
74
|
+
next.splice(insertAt, 0, newItemWrapper);
|
|
75
|
+
return next;
|
|
76
|
+
});
|
|
77
|
+
appendPatch({
|
|
78
|
+
kind: 'array.insert',
|
|
79
|
+
path: path,
|
|
80
|
+
index: insertAt,
|
|
81
|
+
item: newItem
|
|
82
|
+
});
|
|
83
|
+
const newArrayValue = currentArray ? [
|
|
84
|
+
...currentArray
|
|
85
|
+
] : [];
|
|
86
|
+
newArrayValue.splice(insertAt, 0, newItem);
|
|
87
|
+
setFieldStore(path, newArrayValue);
|
|
88
|
+
};
|
|
89
|
+
const handleRemoveItem = (index)=>{
|
|
90
|
+
const currentArray = getFieldValue(path) ?? defaultValue;
|
|
91
|
+
if (!Array.isArray(currentArray) || index < 0 || index >= currentArray.length) return;
|
|
92
|
+
const item = currentArray[index];
|
|
93
|
+
const itemId = item && 'object' == typeof item && '_id' in item ? String(item._id) : String(index);
|
|
94
|
+
setItems((prev)=>prev.filter((_, i)=>i !== index));
|
|
95
|
+
appendPatch({
|
|
96
|
+
kind: 'array.remove',
|
|
97
|
+
path: path,
|
|
98
|
+
itemId
|
|
99
|
+
});
|
|
100
|
+
const newArrayValue = [
|
|
101
|
+
...currentArray
|
|
102
|
+
];
|
|
103
|
+
newArrayValue.splice(index, 1);
|
|
104
|
+
setFieldStore(path, newArrayValue);
|
|
105
|
+
};
|
|
106
|
+
const handleInsertBelow = (index, forcedVariantName)=>{
|
|
107
|
+
if (availableBlocks.length > 1 && null == forcedVariantName) {
|
|
108
|
+
setPendingInsertIndex(index + 1);
|
|
109
|
+
setShowAddBlockModal(true);
|
|
110
|
+
} else handleAddItem(forcedVariantName, index + 1);
|
|
111
|
+
};
|
|
112
|
+
const renderItem = (itemWrapper, index)=>{
|
|
113
|
+
const item = itemWrapper.data;
|
|
114
|
+
const arrayElementPath = `${path}[${index}]`;
|
|
115
|
+
if (!item || 'object' != typeof item || 'string' != typeof item._type) return null;
|
|
116
|
+
const subField = field.blocks?.find((b)=>b.blockType === item._type);
|
|
117
|
+
if (null == subField) return null;
|
|
118
|
+
const { _id, _type, ...fieldData } = item;
|
|
119
|
+
const label = subField.label ?? _type;
|
|
120
|
+
const body = /*#__PURE__*/ jsx(GroupField, {
|
|
121
|
+
field: {
|
|
122
|
+
type: 'group',
|
|
123
|
+
name: subField.blockType,
|
|
124
|
+
fields: subField.fields,
|
|
125
|
+
label: void 0
|
|
126
|
+
},
|
|
127
|
+
defaultValue: fieldData,
|
|
128
|
+
path: arrayElementPath
|
|
129
|
+
}, subField.blockType);
|
|
130
|
+
return /*#__PURE__*/ jsx(SortableItem, {
|
|
131
|
+
id: itemWrapper.id,
|
|
132
|
+
label: label ?? subField.blockType,
|
|
133
|
+
onAddBelow: ()=>handleInsertBelow(index),
|
|
134
|
+
onRemove: ()=>handleRemoveItem(index),
|
|
135
|
+
children: body
|
|
136
|
+
}, itemWrapper.id);
|
|
137
|
+
};
|
|
138
|
+
return /*#__PURE__*/ jsxs("div", {
|
|
139
|
+
className: `byline-field-blocks ${field.name}`,
|
|
140
|
+
children: [
|
|
141
|
+
field.label && /*#__PURE__*/ jsx("h3", {
|
|
142
|
+
className: classnames('byline-field-blocks-title', blocks_field_module.title),
|
|
143
|
+
children: field.label
|
|
144
|
+
}),
|
|
145
|
+
/*#__PURE__*/ jsxs(DraggableSortable, {
|
|
146
|
+
ids: items.map((i)=>i.id),
|
|
147
|
+
onDragEnd: handleDragEnd,
|
|
148
|
+
className: classnames('byline-field-blocks-stack', blocks_field_module.stack),
|
|
149
|
+
children: [
|
|
150
|
+
items.map((item, index)=>renderItem(item, index)),
|
|
151
|
+
/*#__PURE__*/ jsx("div", {
|
|
152
|
+
className: classnames('byline-field-blocks-add-row', blocks_field_module["add-row"]),
|
|
153
|
+
children: /*#__PURE__*/ jsx(IconButton, {
|
|
154
|
+
onClick: ()=>{
|
|
155
|
+
setPendingInsertIndex(null);
|
|
156
|
+
setShowAddBlockModal(true);
|
|
157
|
+
},
|
|
158
|
+
disabled: !selectedBlockName,
|
|
159
|
+
"aria-label": t('fields.blocks.addBlockAriaLabel'),
|
|
160
|
+
children: /*#__PURE__*/ jsx(PlusIcon, {})
|
|
161
|
+
})
|
|
162
|
+
})
|
|
163
|
+
]
|
|
164
|
+
}),
|
|
165
|
+
/*#__PURE__*/ jsx(Modal, {
|
|
166
|
+
isOpen: showAddBlockModal,
|
|
167
|
+
closeOnOverlayClick: true,
|
|
168
|
+
onDismiss: ()=>{
|
|
169
|
+
setShowAddBlockModal(false);
|
|
170
|
+
setPendingInsertIndex(null);
|
|
171
|
+
},
|
|
172
|
+
children: /*#__PURE__*/ jsxs(Modal.Container, {
|
|
173
|
+
style: {
|
|
174
|
+
maxWidth: '600px'
|
|
175
|
+
},
|
|
176
|
+
children: [
|
|
177
|
+
/*#__PURE__*/ jsxs(Modal.Header, {
|
|
178
|
+
className: classnames('byline-field-blocks-modal-head', blocks_field_module["modal-head"]),
|
|
179
|
+
children: [
|
|
180
|
+
/*#__PURE__*/ jsx("h3", {
|
|
181
|
+
className: classnames('byline-field-blocks-modal-title', blocks_field_module["modal-title"]),
|
|
182
|
+
children: t('fields.blocks.modalTitle')
|
|
183
|
+
}),
|
|
184
|
+
/*#__PURE__*/ jsx(IconButton, {
|
|
185
|
+
"arial-label": t('common.actions.close'),
|
|
186
|
+
size: "xs",
|
|
187
|
+
onClick: ()=>{
|
|
188
|
+
setShowAddBlockModal(false);
|
|
189
|
+
setPendingInsertIndex(null);
|
|
190
|
+
},
|
|
191
|
+
children: /*#__PURE__*/ jsx(CloseIcon, {
|
|
192
|
+
width: "16px",
|
|
193
|
+
height: "16px",
|
|
194
|
+
svgClassName: "white-icon"
|
|
195
|
+
})
|
|
196
|
+
})
|
|
197
|
+
]
|
|
198
|
+
}),
|
|
199
|
+
/*#__PURE__*/ jsx(Modal.Content, {
|
|
200
|
+
className: classnames('byline-field-blocks-card-cursor', blocks_field_module["modal-content"]),
|
|
201
|
+
children: /*#__PURE__*/ jsx("div", {
|
|
202
|
+
className: classnames('byline-field-blocks-grid', blocks_field_module.grid),
|
|
203
|
+
children: availableBlocks.map((b, index)=>/*#__PURE__*/ jsxs(Card, {
|
|
204
|
+
hover: true,
|
|
205
|
+
onClick: ()=>void handleAddItem(b.blockType, pendingInsertIndex ?? void 0),
|
|
206
|
+
className: classnames('byline-field-blocks-card', blocks_field_module.card),
|
|
207
|
+
children: [
|
|
208
|
+
/*#__PURE__*/ jsxs(Card.Header, {
|
|
209
|
+
children: [
|
|
210
|
+
/*#__PURE__*/ jsxs("div", {
|
|
211
|
+
className: classnames('byline-field-blocks-card-head', blocks_field_module["card-head"]),
|
|
212
|
+
children: [
|
|
213
|
+
/*#__PURE__*/ jsx(Card.Title, {
|
|
214
|
+
className: classnames('byline-field-blocks-card-title', blocks_field_module["card-title"]),
|
|
215
|
+
children: b.label ?? b.blockType
|
|
216
|
+
}),
|
|
217
|
+
/*#__PURE__*/ jsx("span", {
|
|
218
|
+
className: classnames('byline-field-blocks-card-index', blocks_field_module["card-index"]),
|
|
219
|
+
children: index + 1
|
|
220
|
+
})
|
|
221
|
+
]
|
|
222
|
+
}),
|
|
223
|
+
/*#__PURE__*/ jsx("code", {
|
|
224
|
+
className: classnames('byline-field-blocks-card-code', blocks_field_module["card-code"]),
|
|
225
|
+
children: b.blockType
|
|
226
|
+
})
|
|
227
|
+
]
|
|
228
|
+
}),
|
|
229
|
+
/*#__PURE__*/ jsx(Card.Content, {
|
|
230
|
+
children: /*#__PURE__*/ jsx("p", {
|
|
231
|
+
className: classnames('byline-field-blocks-card-body', blocks_field_module["card-body"]),
|
|
232
|
+
children: b.helpText ?? b.label ?? b.blockType
|
|
233
|
+
})
|
|
234
|
+
})
|
|
235
|
+
]
|
|
236
|
+
}, b.blockType))
|
|
237
|
+
})
|
|
238
|
+
})
|
|
239
|
+
]
|
|
240
|
+
})
|
|
241
|
+
})
|
|
242
|
+
]
|
|
243
|
+
});
|
|
244
|
+
};
|
|
245
|
+
export { BlocksField };
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import "./blocks-field_module.css";
|
|
2
|
+
const blocks_field_module = {
|
|
3
|
+
title: "title-lxXfG6",
|
|
4
|
+
stack: "stack-Xxa89J",
|
|
5
|
+
"add-row": "add-row-gEqjM_",
|
|
6
|
+
addRow: "add-row-gEqjM_",
|
|
7
|
+
"modal-head": "modal-head-BTxR9C",
|
|
8
|
+
modalHead: "modal-head-BTxR9C",
|
|
9
|
+
"modal-title": "modal-title-jwOfU_",
|
|
10
|
+
modalTitle: "modal-title-jwOfU_",
|
|
11
|
+
"modal-content": "modal-content-S12b_T",
|
|
12
|
+
modalContent: "modal-content-S12b_T",
|
|
13
|
+
grid: "grid-gALL6j",
|
|
14
|
+
card: "card-O4b_4k",
|
|
15
|
+
"card-head": "card-head-yrL68H",
|
|
16
|
+
cardHead: "card-head-yrL68H",
|
|
17
|
+
"card-title": "card-title-yBgy__",
|
|
18
|
+
cardTitle: "card-title-yBgy__",
|
|
19
|
+
"card-index": "card-index-XD_vf6",
|
|
20
|
+
cardIndex: "card-index-XD_vf6",
|
|
21
|
+
"card-code": "card-code-pEAcf6",
|
|
22
|
+
cardCode: "card-code-pEAcf6",
|
|
23
|
+
"card-body": "card-body-RhabRg",
|
|
24
|
+
cardBody: "card-body-RhabRg"
|
|
25
|
+
};
|
|
26
|
+
export default blocks_field_module;
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
:is(.title-lxXfG6, .byline-field-blocks-title) {
|
|
2
|
+
font-size: 1rem;
|
|
3
|
+
font-weight: var(--font-weight-medium);
|
|
4
|
+
margin-bottom: .25rem;
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
:is(.stack-Xxa89J, .byline-field-blocks-stack) {
|
|
8
|
+
gap: var(--spacing-16);
|
|
9
|
+
flex-direction: column;
|
|
10
|
+
display: flex;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
:is(.add-row-gEqjM_, .byline-field-blocks-add-row) {
|
|
14
|
+
align-items: center;
|
|
15
|
+
gap: var(--spacing-8);
|
|
16
|
+
display: flex;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
:is(.modal-head-BTxR9C, .byline-field-blocks-modal-head) {
|
|
20
|
+
margin-bottom: var(--spacing-8);
|
|
21
|
+
padding-top: 1rem;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
:is(.modal-title-jwOfU_, .byline-field-blocks-modal-title) {
|
|
25
|
+
margin: 0 0 var(--spacing-8) 0;
|
|
26
|
+
font-size: var(--font-size-2xl);
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
:is(.modal-content-S12b_T, .byline-field-blocks-card-cursor) {
|
|
30
|
+
cursor: pointer;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
:is(.grid-gALL6j, .byline-field-blocks-grid) {
|
|
34
|
+
gap: var(--spacing-16);
|
|
35
|
+
grid-template-columns: 1fr;
|
|
36
|
+
display: grid;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
@media (min-width: 40rem) {
|
|
40
|
+
:is(.grid-gALL6j, .byline-field-blocks-grid) {
|
|
41
|
+
grid-template-columns: repeat(2, 1fr);
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
@media (min-width: 48rem) {
|
|
46
|
+
:is(.grid-gALL6j, .byline-field-blocks-grid) {
|
|
47
|
+
grid-template-columns: repeat(3, 1fr);
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
:is(.card-O4b_4k, .byline-field-blocks-card) {
|
|
52
|
+
margin-bottom: var(--spacing-8);
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
:is(.card-head-yrL68H, .byline-field-blocks-card-head) {
|
|
56
|
+
justify-content: space-between;
|
|
57
|
+
align-items: flex-start;
|
|
58
|
+
gap: var(--spacing-8);
|
|
59
|
+
display: flex;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
:is(.card-title-yBgy__, .byline-field-blocks-card-title) {
|
|
63
|
+
font-size: 1.3rem;
|
|
64
|
+
line-height: var(--line-height-tight);
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
:is(.card-index-XD_vf6, .byline-field-blocks-card-index) {
|
|
68
|
+
border: var(--border-width-thin) var(--border-style-solid) var(--gray-100);
|
|
69
|
+
border-radius: var(--border-radius-full);
|
|
70
|
+
width: 1.25rem;
|
|
71
|
+
height: 1.25rem;
|
|
72
|
+
color: var(--gray-400);
|
|
73
|
+
font-size: 10px;
|
|
74
|
+
font-weight: var(--font-weight-semibold);
|
|
75
|
+
font-variant-numeric: tabular-nums;
|
|
76
|
+
flex-shrink: 0;
|
|
77
|
+
justify-content: center;
|
|
78
|
+
align-items: center;
|
|
79
|
+
margin-top: .125rem;
|
|
80
|
+
display: inline-flex;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
:is(.card-code-pEAcf6, .byline-field-blocks-card-code) {
|
|
84
|
+
color: var(--gray-400);
|
|
85
|
+
margin-top: 0;
|
|
86
|
+
font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
|
|
87
|
+
font-size: 12px;
|
|
88
|
+
display: block;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
:is(.card-body-RhabRg, .byline-field-blocks-card-body) {
|
|
92
|
+
color: var(--gray-500);
|
|
93
|
+
font-size: var(--font-size-sm);
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
:is(:is([data-theme="dark"], .dark) .card-index-XD_vf6, :is([data-theme="dark"], .dark) .byline-field-blocks-card-index) {
|
|
97
|
+
border-color: var(--gray-700);
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
:is(:is([data-theme="dark"], .dark) .card-code-pEAcf6, :is([data-theme="dark"], .dark) .byline-field-blocks-card-code) {
|
|
101
|
+
color: var(--gray-500);
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
:is(:is([data-theme="dark"], .dark) .card-body-RhabRg, :is([data-theme="dark"], .dark) .byline-field-blocks-card-body) {
|
|
105
|
+
color: var(--gray-200);
|
|
106
|
+
}
|
|
107
|
+
|
|
@@ -0,0 +1,16 @@
|
|
|
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
|
+
import type { CheckboxField as FieldType } from '@byline/core';
|
|
9
|
+
export declare const CheckboxField: ({ field, value, defaultValue, onChange, id, path, }: {
|
|
10
|
+
field: FieldType;
|
|
11
|
+
value?: boolean;
|
|
12
|
+
defaultValue?: boolean;
|
|
13
|
+
onChange?: (value: boolean) => void;
|
|
14
|
+
id?: string;
|
|
15
|
+
path?: string;
|
|
16
|
+
}) => import("react").JSX.Element;
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { jsx } from "react/jsx-runtime";
|
|
2
|
+
import { Checkbox } from "@byline/ui/react";
|
|
3
|
+
import { useFieldError, useFieldValue } from "../../forms/form-context.js";
|
|
4
|
+
import checkbox_field_module from "./checkbox-field.module.js";
|
|
5
|
+
const CheckboxField = ({ field, value, defaultValue, onChange, id, path })=>{
|
|
6
|
+
const fieldPath = path ?? field.name;
|
|
7
|
+
const fieldError = useFieldError(fieldPath);
|
|
8
|
+
const fieldValue = useFieldValue(fieldPath);
|
|
9
|
+
const checked = value ?? fieldValue ?? defaultValue ?? false;
|
|
10
|
+
return /*#__PURE__*/ jsx("div", {
|
|
11
|
+
className: `byline-field-checkbox ${field.name} ${checkbox_field_module["field-checkbox"]}`,
|
|
12
|
+
children: /*#__PURE__*/ jsx(Checkbox, {
|
|
13
|
+
id: id ?? fieldPath,
|
|
14
|
+
name: field.name,
|
|
15
|
+
label: field.label,
|
|
16
|
+
checked: checked,
|
|
17
|
+
size: "sm",
|
|
18
|
+
helpText: field.helpText,
|
|
19
|
+
onCheckedChange: (value)=>{
|
|
20
|
+
const next = 'indeterminate' === value ? false : Boolean(value);
|
|
21
|
+
onChange?.(next);
|
|
22
|
+
},
|
|
23
|
+
error: null != fieldError,
|
|
24
|
+
errorText: fieldError
|
|
25
|
+
})
|
|
26
|
+
});
|
|
27
|
+
};
|
|
28
|
+
export { CheckboxField };
|