@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,104 @@
|
|
|
1
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { useCallback } from "react";
|
|
3
|
+
import { Input, Label } from "@byline/ui/react";
|
|
4
|
+
import classnames from "classnames";
|
|
5
|
+
import { useFieldError, useFieldValue } from "../../forms/form-context.js";
|
|
6
|
+
import { LocaleBadge } from "../locale-badge.js";
|
|
7
|
+
import text_field_module from "./text-field.module.js";
|
|
8
|
+
const TextField = ({ field, value, defaultValue, onChange, id, path, locale, components })=>{
|
|
9
|
+
const fieldPath = path ?? field.name;
|
|
10
|
+
const fieldError = useFieldError(fieldPath);
|
|
11
|
+
const fieldValue = useFieldValue(fieldPath);
|
|
12
|
+
const incomingValue = value ?? fieldValue ?? defaultValue ?? '';
|
|
13
|
+
const htmlId = id ?? fieldPath;
|
|
14
|
+
const handleChange = useCallback((value)=>{
|
|
15
|
+
if (onChange) onChange(value);
|
|
16
|
+
}, [
|
|
17
|
+
onChange
|
|
18
|
+
]);
|
|
19
|
+
const slots = components;
|
|
20
|
+
const CustomLabel = slots?.Label;
|
|
21
|
+
const CustomHelpText = slots?.HelpText;
|
|
22
|
+
const CustomField = slots?.Field;
|
|
23
|
+
const BeforeField = slots?.beforeField;
|
|
24
|
+
const AfterField = slots?.afterField;
|
|
25
|
+
const slotBaseProps = {
|
|
26
|
+
field: field,
|
|
27
|
+
path: fieldPath,
|
|
28
|
+
value: incomingValue,
|
|
29
|
+
error: fieldError,
|
|
30
|
+
id: htmlId
|
|
31
|
+
};
|
|
32
|
+
const showBadge = !!locale && !!field.label;
|
|
33
|
+
const hasCustomLabel = !!CustomLabel;
|
|
34
|
+
const suppressInputLabel = showBadge || hasCustomLabel;
|
|
35
|
+
const suppressInputHelpText = !!CustomHelpText;
|
|
36
|
+
const labelRowClass = classnames('byline-field-text-label-row', text_field_module["label-row"]);
|
|
37
|
+
const renderLabel = ()=>{
|
|
38
|
+
if (hasCustomLabel) return /*#__PURE__*/ jsxs("div", {
|
|
39
|
+
className: labelRowClass,
|
|
40
|
+
children: [
|
|
41
|
+
/*#__PURE__*/ jsx(CustomLabel, {
|
|
42
|
+
...slotBaseProps,
|
|
43
|
+
label: field.label,
|
|
44
|
+
required: !field.optional
|
|
45
|
+
}),
|
|
46
|
+
showBadge && /*#__PURE__*/ jsx(LocaleBadge, {
|
|
47
|
+
locale: locale
|
|
48
|
+
})
|
|
49
|
+
]
|
|
50
|
+
});
|
|
51
|
+
if (showBadge) return /*#__PURE__*/ jsxs("div", {
|
|
52
|
+
className: labelRowClass,
|
|
53
|
+
children: [
|
|
54
|
+
/*#__PURE__*/ jsx(Label, {
|
|
55
|
+
id: `${htmlId}-label`,
|
|
56
|
+
htmlFor: htmlId,
|
|
57
|
+
label: field.label,
|
|
58
|
+
required: !field.optional
|
|
59
|
+
}),
|
|
60
|
+
/*#__PURE__*/ jsx(LocaleBadge, {
|
|
61
|
+
locale: locale
|
|
62
|
+
})
|
|
63
|
+
]
|
|
64
|
+
});
|
|
65
|
+
return null;
|
|
66
|
+
};
|
|
67
|
+
const renderInput = ()=>{
|
|
68
|
+
if (CustomField) return /*#__PURE__*/ jsx(CustomField, {
|
|
69
|
+
...slotBaseProps,
|
|
70
|
+
onChange: handleChange,
|
|
71
|
+
defaultValue: defaultValue,
|
|
72
|
+
placeholder: field.placeholder
|
|
73
|
+
});
|
|
74
|
+
return /*#__PURE__*/ jsx(Input, {
|
|
75
|
+
id: htmlId,
|
|
76
|
+
name: field.name,
|
|
77
|
+
label: suppressInputLabel ? void 0 : field.label,
|
|
78
|
+
required: !field.optional,
|
|
79
|
+
helpText: suppressInputHelpText ? void 0 : field.helpText,
|
|
80
|
+
value: incomingValue,
|
|
81
|
+
onChange: (e)=>handleChange(e.target.value),
|
|
82
|
+
error: null != fieldError,
|
|
83
|
+
errorText: fieldError
|
|
84
|
+
});
|
|
85
|
+
};
|
|
86
|
+
return /*#__PURE__*/ jsxs("div", {
|
|
87
|
+
className: `byline-field-text ${field.name}`,
|
|
88
|
+
children: [
|
|
89
|
+
renderLabel(),
|
|
90
|
+
BeforeField && /*#__PURE__*/ jsx(BeforeField, {
|
|
91
|
+
...slotBaseProps
|
|
92
|
+
}),
|
|
93
|
+
renderInput(),
|
|
94
|
+
AfterField && /*#__PURE__*/ jsx(AfterField, {
|
|
95
|
+
...slotBaseProps
|
|
96
|
+
}),
|
|
97
|
+
CustomHelpText && /*#__PURE__*/ jsx(CustomHelpText, {
|
|
98
|
+
...slotBaseProps,
|
|
99
|
+
helpText: field.helpText
|
|
100
|
+
})
|
|
101
|
+
]
|
|
102
|
+
});
|
|
103
|
+
};
|
|
104
|
+
export { TextField };
|
|
@@ -0,0 +1,20 @@
|
|
|
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 { FieldComponentSlots, TextAreaField as FieldType } from '@byline/core';
|
|
9
|
+
export declare const TextAreaField: ({ field, value, defaultValue, onChange, id, path, locale, components, }: {
|
|
10
|
+
field: FieldType;
|
|
11
|
+
value?: string;
|
|
12
|
+
defaultValue?: string;
|
|
13
|
+
onChange?: (value: string) => void;
|
|
14
|
+
id?: string;
|
|
15
|
+
path?: string;
|
|
16
|
+
/** When provided, renders a LocaleBadge next to the field label. */
|
|
17
|
+
locale?: string;
|
|
18
|
+
/** Optional UI component slot overrides from the admin config. */
|
|
19
|
+
components?: FieldComponentSlots;
|
|
20
|
+
}) => import("react").JSX.Element;
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { useCallback } from "react";
|
|
3
|
+
import { Label, TextArea } from "@byline/ui/react";
|
|
4
|
+
import classnames from "classnames";
|
|
5
|
+
import { useFieldError, useFieldValue } from "../../forms/form-context.js";
|
|
6
|
+
import { LocaleBadge } from "../locale-badge.js";
|
|
7
|
+
import text_area_field_module from "./text-area-field.module.js";
|
|
8
|
+
const TextAreaField = ({ field, value, defaultValue, onChange, id, path, locale, components })=>{
|
|
9
|
+
const fieldPath = path ?? field.name;
|
|
10
|
+
const fieldError = useFieldError(fieldPath);
|
|
11
|
+
const fieldValue = useFieldValue(fieldPath);
|
|
12
|
+
const incomingValue = value ?? fieldValue ?? defaultValue ?? '';
|
|
13
|
+
const htmlId = id ?? fieldPath;
|
|
14
|
+
const handleChange = useCallback((value)=>{
|
|
15
|
+
if (onChange) onChange(value);
|
|
16
|
+
}, [
|
|
17
|
+
onChange
|
|
18
|
+
]);
|
|
19
|
+
const slots = components;
|
|
20
|
+
const CustomLabel = slots?.Label;
|
|
21
|
+
const CustomHelpText = slots?.HelpText;
|
|
22
|
+
const CustomField = slots?.Field;
|
|
23
|
+
const BeforeField = slots?.beforeField;
|
|
24
|
+
const AfterField = slots?.afterField;
|
|
25
|
+
const slotBaseProps = {
|
|
26
|
+
field: field,
|
|
27
|
+
path: fieldPath,
|
|
28
|
+
value: incomingValue,
|
|
29
|
+
error: fieldError,
|
|
30
|
+
id: htmlId
|
|
31
|
+
};
|
|
32
|
+
const showBadge = !!locale && !!field.label;
|
|
33
|
+
const hasCustomLabel = !!CustomLabel;
|
|
34
|
+
const suppressInputLabel = showBadge || hasCustomLabel;
|
|
35
|
+
const suppressInputHelpText = !!CustomHelpText;
|
|
36
|
+
const labelRowClass = classnames('byline-field-text-area-label-row', text_area_field_module["label-row"]);
|
|
37
|
+
const renderLabel = ()=>{
|
|
38
|
+
if (hasCustomLabel) return /*#__PURE__*/ jsxs("div", {
|
|
39
|
+
className: labelRowClass,
|
|
40
|
+
children: [
|
|
41
|
+
/*#__PURE__*/ jsx(CustomLabel, {
|
|
42
|
+
...slotBaseProps,
|
|
43
|
+
label: field.label,
|
|
44
|
+
required: !field.optional
|
|
45
|
+
}),
|
|
46
|
+
showBadge && /*#__PURE__*/ jsx(LocaleBadge, {
|
|
47
|
+
locale: locale
|
|
48
|
+
})
|
|
49
|
+
]
|
|
50
|
+
});
|
|
51
|
+
if (showBadge) return /*#__PURE__*/ jsxs("div", {
|
|
52
|
+
className: labelRowClass,
|
|
53
|
+
children: [
|
|
54
|
+
/*#__PURE__*/ jsx(Label, {
|
|
55
|
+
id: `${htmlId}-label`,
|
|
56
|
+
htmlFor: htmlId,
|
|
57
|
+
label: field.label,
|
|
58
|
+
required: !field.optional
|
|
59
|
+
}),
|
|
60
|
+
/*#__PURE__*/ jsx(LocaleBadge, {
|
|
61
|
+
locale: locale
|
|
62
|
+
})
|
|
63
|
+
]
|
|
64
|
+
});
|
|
65
|
+
return null;
|
|
66
|
+
};
|
|
67
|
+
const renderInput = ()=>{
|
|
68
|
+
if (CustomField) return /*#__PURE__*/ jsx(CustomField, {
|
|
69
|
+
...slotBaseProps,
|
|
70
|
+
onChange: handleChange,
|
|
71
|
+
defaultValue: defaultValue,
|
|
72
|
+
placeholder: field.placeholder
|
|
73
|
+
});
|
|
74
|
+
return /*#__PURE__*/ jsx(TextArea, {
|
|
75
|
+
id: htmlId,
|
|
76
|
+
name: field.name,
|
|
77
|
+
label: suppressInputLabel ? void 0 : field.label,
|
|
78
|
+
required: !field.optional,
|
|
79
|
+
helpText: suppressInputHelpText ? void 0 : field.helpText,
|
|
80
|
+
value: incomingValue,
|
|
81
|
+
onChange: (e)=>handleChange(e.target.value),
|
|
82
|
+
error: null != fieldError,
|
|
83
|
+
errorText: fieldError,
|
|
84
|
+
rows: 4
|
|
85
|
+
});
|
|
86
|
+
};
|
|
87
|
+
return /*#__PURE__*/ jsxs("div", {
|
|
88
|
+
className: `byline-field-text-area ${field.name}`,
|
|
89
|
+
children: [
|
|
90
|
+
renderLabel(),
|
|
91
|
+
BeforeField && /*#__PURE__*/ jsx(BeforeField, {
|
|
92
|
+
...slotBaseProps
|
|
93
|
+
}),
|
|
94
|
+
renderInput(),
|
|
95
|
+
AfterField && /*#__PURE__*/ jsx(AfterField, {
|
|
96
|
+
...slotBaseProps
|
|
97
|
+
}),
|
|
98
|
+
CustomHelpText && /*#__PURE__*/ jsx(CustomHelpText, {
|
|
99
|
+
...slotBaseProps,
|
|
100
|
+
helpText: field.helpText
|
|
101
|
+
})
|
|
102
|
+
]
|
|
103
|
+
});
|
|
104
|
+
};
|
|
105
|
+
export { TextAreaField };
|
|
@@ -0,0 +1,23 @@
|
|
|
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 { Field } from '@byline/core';
|
|
9
|
+
/**
|
|
10
|
+
* Returns a change handler for the given field that runs through the
|
|
11
|
+
* field-hook pipeline before committing the value:
|
|
12
|
+
*
|
|
13
|
+
* 1. `clearFieldError(path)`
|
|
14
|
+
* 2. `field.hooks.beforeValidate(ctx)` — advisory: may set an error on
|
|
15
|
+
* the field but the value is **always** committed (user can keep typing)
|
|
16
|
+
* 3. `field.hooks.beforeChange(ctx)` — may return `{ value }` to replace
|
|
17
|
+
* or `{ error }` to block the change entirely
|
|
18
|
+
* 4. `setFieldValue(path, finalValue)`
|
|
19
|
+
*
|
|
20
|
+
* When the field has no hooks the function is a zero-overhead pass-through
|
|
21
|
+
* to `setFieldValue` (no promises, no extra allocations).
|
|
22
|
+
*/
|
|
23
|
+
export declare function useFieldChangeHandler(field: Field, path: string): (value: any) => void;
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { useCallback } from "react";
|
|
2
|
+
import { normalizeHooks } from "@byline/core";
|
|
3
|
+
import { useFormContext } from "../forms/form-context.js";
|
|
4
|
+
function useFieldChangeHandler(field, path) {
|
|
5
|
+
const { setFieldValue, getFieldValue, getFieldValues, setFieldError, clearFieldError } = useFormContext();
|
|
6
|
+
return useCallback((value)=>{
|
|
7
|
+
const hooks = field.hooks;
|
|
8
|
+
const validateFns = normalizeHooks(hooks?.beforeValidate);
|
|
9
|
+
const changeFns = normalizeHooks(hooks?.beforeChange);
|
|
10
|
+
if (0 === validateFns.length && 0 === changeFns.length) return void setFieldValue(path, value);
|
|
11
|
+
const previousValue = getFieldValue(path);
|
|
12
|
+
const ctx = {
|
|
13
|
+
value,
|
|
14
|
+
previousValue,
|
|
15
|
+
data: getFieldValues(),
|
|
16
|
+
path,
|
|
17
|
+
field,
|
|
18
|
+
operation: 'change'
|
|
19
|
+
};
|
|
20
|
+
clearFieldError(path);
|
|
21
|
+
if (0 === changeFns.length) setFieldValue(path, value);
|
|
22
|
+
(async ()=>{
|
|
23
|
+
try {
|
|
24
|
+
let advisoryError;
|
|
25
|
+
for (const fn of validateFns){
|
|
26
|
+
const result = await fn(ctx);
|
|
27
|
+
if (result?.error) advisoryError = result.error;
|
|
28
|
+
if (result?.value !== void 0) ctx.value = result.value;
|
|
29
|
+
}
|
|
30
|
+
for (const fn of changeFns){
|
|
31
|
+
const result = await fn(ctx);
|
|
32
|
+
if (result?.error) return void setFieldError(path, result.error);
|
|
33
|
+
if (result?.value !== void 0) ctx.value = result.value;
|
|
34
|
+
}
|
|
35
|
+
setFieldValue(path, ctx.value);
|
|
36
|
+
if (advisoryError) setFieldError(path, advisoryError);
|
|
37
|
+
} catch (err) {
|
|
38
|
+
const message = err instanceof Error ? err.message : 'Unexpected hook error';
|
|
39
|
+
setFieldError(path, message);
|
|
40
|
+
}
|
|
41
|
+
})();
|
|
42
|
+
}, [
|
|
43
|
+
field,
|
|
44
|
+
path,
|
|
45
|
+
setFieldValue,
|
|
46
|
+
getFieldValue,
|
|
47
|
+
getFieldValues,
|
|
48
|
+
setFieldError,
|
|
49
|
+
clearFieldError
|
|
50
|
+
]);
|
|
51
|
+
}
|
|
52
|
+
export { useFieldChangeHandler };
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import type { PublishedVersionInfo } from './form-renderer';
|
|
2
|
+
/**
|
|
3
|
+
* Shape of a content-locale option as consumed by the Copy-to-Locale
|
|
4
|
+
* modal. Matches the host adapter's `ContentLocaleOption`; declared
|
|
5
|
+
* locally so this package does not take a dependency on host code.
|
|
6
|
+
*/
|
|
7
|
+
export interface DocumentActionsLocaleOption {
|
|
8
|
+
code: string;
|
|
9
|
+
label: string;
|
|
10
|
+
}
|
|
11
|
+
export declare function DocumentActions({ publishedVersion, onUnpublish, onDelete, onDuplicate, sourceTitle, onCopyToLocale, sourceLocale, contentLocales, }: {
|
|
12
|
+
publishedVersion?: PublishedVersionInfo | null;
|
|
13
|
+
onUnpublish?: () => Promise<void>;
|
|
14
|
+
onDelete?: () => Promise<void>;
|
|
15
|
+
/**
|
|
16
|
+
* Called when the editor confirms the duplicate modal. The parent runs
|
|
17
|
+
* the server fn, surfaces a toast, and navigates to the new document.
|
|
18
|
+
*/
|
|
19
|
+
onDuplicate?: () => Promise<void>;
|
|
20
|
+
/**
|
|
21
|
+
* The current (saved) value of the source document's `useAsTitle`
|
|
22
|
+
* field, used to render the suffix preview inside the duplicate modal.
|
|
23
|
+
* Sourced from the form's `initialData`, not live form state, so the
|
|
24
|
+
* preview reflects what will actually be duplicated.
|
|
25
|
+
*/
|
|
26
|
+
sourceTitle?: string | null;
|
|
27
|
+
/**
|
|
28
|
+
* Called when the editor confirms the Copy-to-Locale modal. The
|
|
29
|
+
* parent runs the server fn, surfaces a toast, and navigates to the
|
|
30
|
+
* target locale view. Menu item is hidden when omitted, or when fewer
|
|
31
|
+
* than two content locales are configured.
|
|
32
|
+
*/
|
|
33
|
+
onCopyToLocale?: (args: {
|
|
34
|
+
targetLocale: string;
|
|
35
|
+
overwrite: boolean;
|
|
36
|
+
}) => Promise<void>;
|
|
37
|
+
/**
|
|
38
|
+
* The locale the form is currently displaying. Used as the read-only
|
|
39
|
+
* "From" label in the Copy-to-Locale modal and excluded from the
|
|
40
|
+
* target Select.
|
|
41
|
+
*/
|
|
42
|
+
sourceLocale?: string;
|
|
43
|
+
/**
|
|
44
|
+
* All configured content locales (code + display label). The
|
|
45
|
+
* Copy-to-Locale Select lists every locale except `sourceLocale`.
|
|
46
|
+
*/
|
|
47
|
+
contentLocales?: ReadonlyArray<DocumentActionsLocaleOption>;
|
|
48
|
+
}): import("react").JSX.Element;
|