@sitecore-content-sdk/react 1.1.0-canary.40 → 1.1.0-canary.42
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/cjs/components/DefaultEmptyFieldEditingComponents.js +4 -4
- package/dist/cjs/enhancers/withEmptyFieldEditingComponent.js +12 -5
- package/dist/esm/components/DefaultEmptyFieldEditingComponents.js +4 -4
- package/dist/esm/enhancers/withEmptyFieldEditingComponent.js +12 -5
- package/package.json +3 -3
- package/types/components/Date.d.ts +1 -1
- package/types/components/DefaultEmptyFieldEditingComponents.d.ts +8 -2
- package/types/components/Image.d.ts +1 -1
- package/types/components/Link.d.ts +1 -1
- package/types/components/RichText.d.ts +1 -1
- package/types/components/Text.d.ts +1 -1
- package/types/components/sharedTypes/props.d.ts +2 -2
- package/types/enhancers/withEmptyFieldEditingComponent.d.ts +3 -3
|
@@ -5,11 +5,11 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.DefaultEmptyFieldEditingComponentImage = exports.DefaultEmptyFieldEditingComponentText = void 0;
|
|
7
7
|
const react_1 = __importDefault(require("react"));
|
|
8
|
-
const DefaultEmptyFieldEditingComponentText = () => {
|
|
9
|
-
return react_1.default.createElement(
|
|
8
|
+
const DefaultEmptyFieldEditingComponentText = (props) => {
|
|
9
|
+
return react_1.default.createElement(props.tag || 'span', props, '[No text in field]');
|
|
10
10
|
};
|
|
11
11
|
exports.DefaultEmptyFieldEditingComponentText = DefaultEmptyFieldEditingComponentText;
|
|
12
|
-
const DefaultEmptyFieldEditingComponentImage = () => {
|
|
12
|
+
const DefaultEmptyFieldEditingComponentImage = (props) => {
|
|
13
13
|
const inlineStyles = {
|
|
14
14
|
minWidth: '48px',
|
|
15
15
|
minHeight: '48px',
|
|
@@ -17,6 +17,6 @@ const DefaultEmptyFieldEditingComponentImage = () => {
|
|
|
17
17
|
maxHeight: '400px',
|
|
18
18
|
cursor: 'pointer',
|
|
19
19
|
};
|
|
20
|
-
return (react_1.default.createElement("img", { alt: "", src: 'data:image/svg+xml,%3Csvg version="1.1" id="Layer_1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px" viewBox="0 0 240 240" style="enable-background:new 0 0 240 240;" xml:space="preserve"%3E%3Cstyle type="text/css"%3E .st0%7Bfill:none;%7D .st1%7Bfill:%23969696;%7D .st2%7Bfill:%23FFFFFF;%7D .st3%7Bfill:%23FFFFFF;stroke:%23FFFFFF;stroke-width:0.75;stroke-miterlimit:10;%7D%0A%3C/style%3E%3Cg%3E%3Crect class="st0" width="240" height="240"/%3E%3Cg%3E%3Cg%3E%3Crect x="20" y="20" class="st1" width="200" height="200"/%3E%3C/g%3E%3Cg%3E%3Ccircle class="st2" cx="174" cy="67" r="14"/%3E%3Cpath class="st2" d="M174,54c7.17,0,13,5.83,13,13s-5.83,13-13,13s-13-5.83-13-13S166.83,54,174,54 M174,52 c-8.28,0-15,6.72-15,15s6.72,15,15,15s15-6.72,15-15S182.28,52,174,52L174,52z"/%3E%3C/g%3E%3Cpolyline class="st3" points="29.5,179.25 81.32,122.25 95.41,137.75 137.23,91.75 209.5,179.75 "/%3E%3C/g%3E%3C/g%3E%3C/svg%3E', className:
|
|
20
|
+
return (react_1.default.createElement("img", Object.assign({}, props, { alt: "", src: 'data:image/svg+xml,%3Csvg version="1.1" id="Layer_1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px" viewBox="0 0 240 240" style="enable-background:new 0 0 240 240;" xml:space="preserve"%3E%3Cstyle type="text/css"%3E .st0%7Bfill:none;%7D .st1%7Bfill:%23969696;%7D .st2%7Bfill:%23FFFFFF;%7D .st3%7Bfill:%23FFFFFF;stroke:%23FFFFFF;stroke-width:0.75;stroke-miterlimit:10;%7D%0A%3C/style%3E%3Cg%3E%3Crect class="st0" width="240" height="240"/%3E%3Cg%3E%3Cg%3E%3Crect x="20" y="20" class="st1" width="200" height="200"/%3E%3C/g%3E%3Cg%3E%3Ccircle class="st2" cx="174" cy="67" r="14"/%3E%3Cpath class="st2" d="M174,54c7.17,0,13,5.83,13,13s-5.83,13-13,13s-13-5.83-13-13S166.83,54,174,54 M174,52 c-8.28,0-15,6.72-15,15s6.72,15,15,15s15-6.72,15-15S182.28,52,174,52L174,52z"/%3E%3C/g%3E%3Cpolyline class="st3" points="29.5,179.25 81.32,122.25 95.41,137.75 137.23,91.75 209.5,179.75 "/%3E%3C/g%3E%3C/g%3E%3C/svg%3E', className: `scEmptyImage ${props.className || ''}`, style: inlineStyles })));
|
|
21
21
|
};
|
|
22
22
|
exports.DefaultEmptyFieldEditingComponentImage = DefaultEmptyFieldEditingComponentImage;
|
|
@@ -46,18 +46,25 @@ function withEmptyFieldEditingComponent(FieldComponent, options) {
|
|
|
46
46
|
var _a;
|
|
47
47
|
const { editable = true } = props;
|
|
48
48
|
if (((_a = props.field) === null || _a === void 0 ? void 0 : _a.metadata) && editable && (0, layout_1.isFieldValueEmpty)(props.field)) {
|
|
49
|
-
|
|
49
|
+
const Component = props.emptyFieldEditingComponent || options.defaultEmptyFieldEditingComponent;
|
|
50
|
+
let resolvedProps = props;
|
|
51
|
+
// If no custom empty field editing component is provided, we can omit unnecessary props
|
|
52
|
+
// to do not insert them to html
|
|
53
|
+
if (!props.emptyFieldEditingComponent) {
|
|
54
|
+
resolvedProps = Object.assign(Object.assign({}, props), { editable: undefined, field: undefined });
|
|
55
|
+
}
|
|
56
|
+
return react_1.default.createElement(Component, Object.assign({}, resolvedProps));
|
|
50
57
|
}
|
|
51
58
|
return null;
|
|
52
59
|
};
|
|
53
60
|
if (options.isForwardRef) {
|
|
54
61
|
return (0, react_1.forwardRef)((props, ref) => {
|
|
55
|
-
const
|
|
56
|
-
return (
|
|
62
|
+
const emptyFieldEditingComponent = getEmptyFieldEditingComponent(props);
|
|
63
|
+
return (emptyFieldEditingComponent || (react_1.default.createElement(FieldComponent, Object.assign({}, props, { ref: ref }))));
|
|
57
64
|
});
|
|
58
65
|
}
|
|
59
66
|
return (props) => {
|
|
60
|
-
const
|
|
61
|
-
return
|
|
67
|
+
const emptyFieldEditingComponent = getEmptyFieldEditingComponent(props);
|
|
68
|
+
return emptyFieldEditingComponent || react_1.default.createElement(FieldComponent, Object.assign({}, props));
|
|
62
69
|
};
|
|
63
70
|
}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
|
-
export const DefaultEmptyFieldEditingComponentText = () => {
|
|
3
|
-
return React.createElement(
|
|
2
|
+
export const DefaultEmptyFieldEditingComponentText = (props) => {
|
|
3
|
+
return React.createElement(props.tag || 'span', props, '[No text in field]');
|
|
4
4
|
};
|
|
5
|
-
export const DefaultEmptyFieldEditingComponentImage = () => {
|
|
5
|
+
export const DefaultEmptyFieldEditingComponentImage = (props) => {
|
|
6
6
|
const inlineStyles = {
|
|
7
7
|
minWidth: '48px',
|
|
8
8
|
minHeight: '48px',
|
|
@@ -10,5 +10,5 @@ export const DefaultEmptyFieldEditingComponentImage = () => {
|
|
|
10
10
|
maxHeight: '400px',
|
|
11
11
|
cursor: 'pointer',
|
|
12
12
|
};
|
|
13
|
-
return (React.createElement("img", { alt: "", src: 'data:image/svg+xml,%3Csvg version="1.1" id="Layer_1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px" viewBox="0 0 240 240" style="enable-background:new 0 0 240 240;" xml:space="preserve"%3E%3Cstyle type="text/css"%3E .st0%7Bfill:none;%7D .st1%7Bfill:%23969696;%7D .st2%7Bfill:%23FFFFFF;%7D .st3%7Bfill:%23FFFFFF;stroke:%23FFFFFF;stroke-width:0.75;stroke-miterlimit:10;%7D%0A%3C/style%3E%3Cg%3E%3Crect class="st0" width="240" height="240"/%3E%3Cg%3E%3Cg%3E%3Crect x="20" y="20" class="st1" width="200" height="200"/%3E%3C/g%3E%3Cg%3E%3Ccircle class="st2" cx="174" cy="67" r="14"/%3E%3Cpath class="st2" d="M174,54c7.17,0,13,5.83,13,13s-5.83,13-13,13s-13-5.83-13-13S166.83,54,174,54 M174,52 c-8.28,0-15,6.72-15,15s6.72,15,15,15s15-6.72,15-15S182.28,52,174,52L174,52z"/%3E%3C/g%3E%3Cpolyline class="st3" points="29.5,179.25 81.32,122.25 95.41,137.75 137.23,91.75 209.5,179.75 "/%3E%3C/g%3E%3C/g%3E%3C/svg%3E', className:
|
|
13
|
+
return (React.createElement("img", Object.assign({}, props, { alt: "", src: 'data:image/svg+xml,%3Csvg version="1.1" id="Layer_1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px" viewBox="0 0 240 240" style="enable-background:new 0 0 240 240;" xml:space="preserve"%3E%3Cstyle type="text/css"%3E .st0%7Bfill:none;%7D .st1%7Bfill:%23969696;%7D .st2%7Bfill:%23FFFFFF;%7D .st3%7Bfill:%23FFFFFF;stroke:%23FFFFFF;stroke-width:0.75;stroke-miterlimit:10;%7D%0A%3C/style%3E%3Cg%3E%3Crect class="st0" width="240" height="240"/%3E%3Cg%3E%3Cg%3E%3Crect x="20" y="20" class="st1" width="200" height="200"/%3E%3C/g%3E%3Cg%3E%3Ccircle class="st2" cx="174" cy="67" r="14"/%3E%3Cpath class="st2" d="M174,54c7.17,0,13,5.83,13,13s-5.83,13-13,13s-13-5.83-13-13S166.83,54,174,54 M174,52 c-8.28,0-15,6.72-15,15s6.72,15,15,15s15-6.72,15-15S182.28,52,174,52L174,52z"/%3E%3C/g%3E%3Cpolyline class="st3" points="29.5,179.25 81.32,122.25 95.41,137.75 137.23,91.75 209.5,179.75 "/%3E%3C/g%3E%3C/g%3E%3C/svg%3E', className: `scEmptyImage ${props.className || ''}`, style: inlineStyles })));
|
|
14
14
|
};
|
|
@@ -10,18 +10,25 @@ export function withEmptyFieldEditingComponent(FieldComponent, options) {
|
|
|
10
10
|
var _a;
|
|
11
11
|
const { editable = true } = props;
|
|
12
12
|
if (((_a = props.field) === null || _a === void 0 ? void 0 : _a.metadata) && editable && isFieldValueEmpty(props.field)) {
|
|
13
|
-
|
|
13
|
+
const Component = props.emptyFieldEditingComponent || options.defaultEmptyFieldEditingComponent;
|
|
14
|
+
let resolvedProps = props;
|
|
15
|
+
// If no custom empty field editing component is provided, we can omit unnecessary props
|
|
16
|
+
// to do not insert them to html
|
|
17
|
+
if (!props.emptyFieldEditingComponent) {
|
|
18
|
+
resolvedProps = Object.assign(Object.assign({}, props), { editable: undefined, field: undefined });
|
|
19
|
+
}
|
|
20
|
+
return React.createElement(Component, Object.assign({}, resolvedProps));
|
|
14
21
|
}
|
|
15
22
|
return null;
|
|
16
23
|
};
|
|
17
24
|
if (options.isForwardRef) {
|
|
18
25
|
return forwardRef((props, ref) => {
|
|
19
|
-
const
|
|
20
|
-
return (
|
|
26
|
+
const emptyFieldEditingComponent = getEmptyFieldEditingComponent(props);
|
|
27
|
+
return (emptyFieldEditingComponent || (React.createElement(FieldComponent, Object.assign({}, props, { ref: ref }))));
|
|
21
28
|
});
|
|
22
29
|
}
|
|
23
30
|
return (props) => {
|
|
24
|
-
const
|
|
25
|
-
return
|
|
31
|
+
const emptyFieldEditingComponent = getEmptyFieldEditingComponent(props);
|
|
32
|
+
return emptyFieldEditingComponent || React.createElement(FieldComponent, Object.assign({}, props));
|
|
26
33
|
};
|
|
27
34
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sitecore-content-sdk/react",
|
|
3
|
-
"version": "1.1.0-canary.
|
|
3
|
+
"version": "1.1.0-canary.42",
|
|
4
4
|
"main": "dist/cjs/index.js",
|
|
5
5
|
"module": "dist/esm/index.js",
|
|
6
6
|
"sideEffects": false,
|
|
@@ -72,12 +72,12 @@
|
|
|
72
72
|
"react-dom": "^19.1.0"
|
|
73
73
|
},
|
|
74
74
|
"dependencies": {
|
|
75
|
-
"@sitecore-content-sdk/core": "1.1.0-canary.
|
|
75
|
+
"@sitecore-content-sdk/core": "1.1.0-canary.42",
|
|
76
76
|
"fast-deep-equal": "^3.1.3"
|
|
77
77
|
},
|
|
78
78
|
"description": "",
|
|
79
79
|
"types": "types/index.d.ts",
|
|
80
|
-
"gitHead": "
|
|
80
|
+
"gitHead": "fb95f0f3aab093cb6af38ea85919873b4cf10032",
|
|
81
81
|
"files": [
|
|
82
82
|
"dist",
|
|
83
83
|
"types"
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
import { EditableFieldProps } from './sharedTypes';
|
|
3
3
|
import { FieldMetadata } from '@sitecore-content-sdk/core/layout';
|
|
4
|
-
export interface DateFieldProps extends EditableFieldProps {
|
|
4
|
+
export interface DateFieldProps extends EditableFieldProps<DateFieldProps> {
|
|
5
5
|
/** The date field data. */
|
|
6
6
|
[htmlAttributes: string]: unknown;
|
|
7
7
|
field: FieldMetadata & {
|
|
@@ -1,3 +1,9 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
|
-
export declare const DefaultEmptyFieldEditingComponentText: React.FC
|
|
3
|
-
|
|
2
|
+
export declare const DefaultEmptyFieldEditingComponentText: React.FC<{
|
|
3
|
+
[key: string]: unknown;
|
|
4
|
+
tag?: string;
|
|
5
|
+
}>;
|
|
6
|
+
export declare const DefaultEmptyFieldEditingComponentImage: React.FC<{
|
|
7
|
+
[key: string]: unknown;
|
|
8
|
+
className?: string;
|
|
9
|
+
}>;
|
|
@@ -25,7 +25,7 @@ export interface ImageSizeParameters {
|
|
|
25
25
|
/** Image scale. Defaults to 1.0 */
|
|
26
26
|
sc?: number;
|
|
27
27
|
}
|
|
28
|
-
export interface ImageProps extends EditableFieldProps {
|
|
28
|
+
export interface ImageProps extends EditableFieldProps<ImageProps> {
|
|
29
29
|
[attributeName: string]: unknown;
|
|
30
30
|
/** Image field data (consistent with other field types) */
|
|
31
31
|
field?: (ImageField | ImageFieldValue) & FieldMetadata;
|
|
@@ -16,7 +16,7 @@ export interface LinkFieldValue {
|
|
|
16
16
|
export interface LinkField {
|
|
17
17
|
value: LinkFieldValue;
|
|
18
18
|
}
|
|
19
|
-
export type LinkProps = EditableFieldProps & React.AnchorHTMLAttributes<HTMLAnchorElement> & RefAttributes<HTMLAnchorElement> & {
|
|
19
|
+
export type LinkProps = EditableFieldProps<LinkProps> & React.AnchorHTMLAttributes<HTMLAnchorElement> & RefAttributes<HTMLAnchorElement> & {
|
|
20
20
|
/** The link field data. */
|
|
21
21
|
field: (LinkField | LinkFieldValue) & FieldMetadata;
|
|
22
22
|
/**
|
|
@@ -4,7 +4,7 @@ import { FieldMetadata } from '@sitecore-content-sdk/core/layout';
|
|
|
4
4
|
export interface RichTextField extends FieldMetadata {
|
|
5
5
|
value?: string;
|
|
6
6
|
}
|
|
7
|
-
export interface RichTextProps extends EditableFieldProps {
|
|
7
|
+
export interface RichTextProps extends EditableFieldProps<RichTextProps> {
|
|
8
8
|
[htmlAttributes: string]: unknown;
|
|
9
9
|
/** The rich text field data. */
|
|
10
10
|
field?: RichTextField;
|
|
@@ -4,7 +4,7 @@ import { FieldMetadata } from '@sitecore-content-sdk/core/layout';
|
|
|
4
4
|
export interface TextField extends FieldMetadata {
|
|
5
5
|
value?: string | number;
|
|
6
6
|
}
|
|
7
|
-
export interface TextProps extends EditableFieldProps {
|
|
7
|
+
export interface TextProps extends EditableFieldProps<TextProps> {
|
|
8
8
|
[htmlAttributes: string]: unknown;
|
|
9
9
|
/** The text field data. */
|
|
10
10
|
field?: TextField;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Shared editing field props
|
|
3
3
|
*/
|
|
4
|
-
export interface EditableFieldProps {
|
|
4
|
+
export interface EditableFieldProps<EmptyFieldEditingComponentProps = unknown> {
|
|
5
5
|
/**
|
|
6
6
|
* Can be used to explicitly disable inline editing.
|
|
7
7
|
* @default true
|
|
@@ -10,5 +10,5 @@ export interface EditableFieldProps {
|
|
|
10
10
|
/**
|
|
11
11
|
* Custom element to render in Pages in edit mode if field value is empty
|
|
12
12
|
*/
|
|
13
|
-
emptyFieldEditingComponent?: React.ComponentClass<
|
|
13
|
+
emptyFieldEditingComponent?: React.ComponentClass<EmptyFieldEditingComponentProps> | React.FC<EmptyFieldEditingComponentProps>;
|
|
14
14
|
}
|
|
@@ -13,15 +13,15 @@ export interface WithEmptyFieldEditingComponentOptions {
|
|
|
13
13
|
*/
|
|
14
14
|
isForwardRef?: boolean;
|
|
15
15
|
}
|
|
16
|
-
interface WithEmptyFieldEditingComponentProps {
|
|
16
|
+
interface WithEmptyFieldEditingComponentProps<Props> {
|
|
17
17
|
field?: (Partial<Field> | GenericFieldValue) & FieldMetadata;
|
|
18
18
|
editable?: boolean;
|
|
19
|
-
emptyFieldEditingComponent?: React.ComponentClass | React.FC
|
|
19
|
+
emptyFieldEditingComponent?: React.ComponentClass<Props> | React.FC<Props>;
|
|
20
20
|
}
|
|
21
21
|
/**
|
|
22
22
|
* Returns the passed field component or default component in case field value is empty and edit mode is 'metadata'
|
|
23
23
|
* @param {ComponentType<FieldComponentProps>} FieldComponent the field component
|
|
24
24
|
* @param {WithEmptyFieldEditingComponentProps} options the options of the HOC;
|
|
25
25
|
*/
|
|
26
|
-
export declare function withEmptyFieldEditingComponent<FieldComponentProps extends WithEmptyFieldEditingComponentProps
|
|
26
|
+
export declare function withEmptyFieldEditingComponent<FieldComponentProps extends WithEmptyFieldEditingComponentProps<FieldComponentProps>, RefElementType = HTMLElement>(FieldComponent: ComponentType<FieldComponentProps>, options: WithEmptyFieldEditingComponentOptions): React.ForwardRefExoticComponent<React.PropsWithoutRef<FieldComponentProps> & React.RefAttributes<RefElementType>> | ((props: FieldComponentProps) => React.JSX.Element);
|
|
27
27
|
export {};
|