@exdst-sitecore-content-sdk/astro 0.0.5 → 0.0.6
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/LICENSE.txt +202 -202
- package/README.md +3 -3
- package/package.json +98 -98
- package/src/components/AstroImage.astro +114 -114
- package/src/components/Date.astro +76 -76
- package/src/components/DefaultEmptyFieldEditingComponentImage.astro +24 -24
- package/src/components/DefaultEmptyFieldEditingComponentText.astro +12 -12
- package/src/components/EditingScripts.astro +48 -48
- package/src/components/EmptyRendering.astro +2 -2
- package/src/components/ErrorBoundary.astro +77 -77
- package/src/components/FieldMetadata.astro +30 -30
- package/src/components/File.astro +46 -46
- package/src/components/HiddenRendering.astro +22 -22
- package/src/components/Image.astro +155 -155
- package/src/components/Link.astro +105 -105
- package/src/components/MissingComponent.astro +39 -39
- package/src/components/Placeholder/EmptyPlaceholder.astro +9 -9
- package/src/components/Placeholder/Placeholder.astro +100 -100
- package/src/components/Placeholder/PlaceholderMetadata.astro +102 -102
- package/src/components/Placeholder/PlaceholderUtils.astro +152 -152
- package/src/components/RenderWrapper.astro +31 -31
- package/src/components/RichText.astro +59 -59
- package/src/components/Text.astro +97 -97
- package/src/enhancers/WithEmptyFieldEditingComponent.astro +56 -56
- package/src/enhancers/WithFieldMetadata.astro +31 -31
|
@@ -1,59 +1,59 @@
|
|
|
1
|
-
---
|
|
2
|
-
import { EditableFieldProps } from './sharedTypes';
|
|
3
|
-
import {
|
|
4
|
-
FieldMetadata,
|
|
5
|
-
isFieldValueEmpty,
|
|
6
|
-
} from '@sitecore-content-sdk/core/layout';
|
|
7
|
-
import WithEmptyFieldEditingComponent from '../enhancers/WithEmptyFieldEditingComponent.astro';
|
|
8
|
-
import WithFieldMetadata from '../enhancers/WithFieldMetadata.astro';
|
|
9
|
-
import DefaultEmptyFieldEditingComponentText from './DefaultEmptyFieldEditingComponentText.astro';
|
|
10
|
-
|
|
11
|
-
export interface RichTextField extends FieldMetadata {
|
|
12
|
-
value?: string;
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
export interface RichTextProps extends EditableFieldProps {
|
|
16
|
-
[htmlAttributes: string]: unknown;
|
|
17
|
-
/** The text field data. */
|
|
18
|
-
field: RichTextField;
|
|
19
|
-
/**
|
|
20
|
-
* The HTML element that will wrap the contents of the field.
|
|
21
|
-
*/
|
|
22
|
-
tag?: string;
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
const {
|
|
26
|
-
field,
|
|
27
|
-
tag = 'div',
|
|
28
|
-
editable = true,
|
|
29
|
-
emptyFieldEditingComponent,
|
|
30
|
-
} = Astro.props as RichTextProps;
|
|
31
|
-
|
|
32
|
-
const isEmptyField = isFieldValueEmpty(field);
|
|
33
|
-
|
|
34
|
-
const Tag = tag;
|
|
35
|
-
|
|
36
|
-
const attrs = (function () {
|
|
37
|
-
const { field, ...attrs } = Astro.props;
|
|
38
|
-
const { tag, ...finalAttrs } = attrs;
|
|
39
|
-
return finalAttrs;
|
|
40
|
-
})();
|
|
41
|
-
---
|
|
42
|
-
|
|
43
|
-
{
|
|
44
|
-
(
|
|
45
|
-
<WithFieldMetadata field={field} editable={editable}>
|
|
46
|
-
<WithEmptyFieldEditingComponent
|
|
47
|
-
field={field}
|
|
48
|
-
editable={editable}
|
|
49
|
-
defaultEmptyFieldEditingComponent={
|
|
50
|
-
DefaultEmptyFieldEditingComponentText
|
|
51
|
-
}
|
|
52
|
-
emptyFieldEditingComponent={emptyFieldEditingComponent}
|
|
53
|
-
{...attrs}
|
|
54
|
-
>
|
|
55
|
-
{!isEmptyField && <Tag {...attrs} set:html={field.value} />}
|
|
56
|
-
</WithEmptyFieldEditingComponent>
|
|
57
|
-
</WithFieldMetadata>
|
|
58
|
-
)
|
|
59
|
-
}
|
|
1
|
+
---
|
|
2
|
+
import { EditableFieldProps } from './sharedTypes';
|
|
3
|
+
import {
|
|
4
|
+
FieldMetadata,
|
|
5
|
+
isFieldValueEmpty,
|
|
6
|
+
} from '@sitecore-content-sdk/core/layout';
|
|
7
|
+
import WithEmptyFieldEditingComponent from '../enhancers/WithEmptyFieldEditingComponent.astro';
|
|
8
|
+
import WithFieldMetadata from '../enhancers/WithFieldMetadata.astro';
|
|
9
|
+
import DefaultEmptyFieldEditingComponentText from './DefaultEmptyFieldEditingComponentText.astro';
|
|
10
|
+
|
|
11
|
+
export interface RichTextField extends FieldMetadata {
|
|
12
|
+
value?: string;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export interface RichTextProps extends EditableFieldProps {
|
|
16
|
+
[htmlAttributes: string]: unknown;
|
|
17
|
+
/** The text field data. */
|
|
18
|
+
field: RichTextField;
|
|
19
|
+
/**
|
|
20
|
+
* The HTML element that will wrap the contents of the field.
|
|
21
|
+
*/
|
|
22
|
+
tag?: string;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
const {
|
|
26
|
+
field,
|
|
27
|
+
tag = 'div',
|
|
28
|
+
editable = true,
|
|
29
|
+
emptyFieldEditingComponent,
|
|
30
|
+
} = Astro.props as RichTextProps;
|
|
31
|
+
|
|
32
|
+
const isEmptyField = isFieldValueEmpty(field);
|
|
33
|
+
|
|
34
|
+
const Tag = tag;
|
|
35
|
+
|
|
36
|
+
const attrs = (function () {
|
|
37
|
+
const { field, ...attrs } = Astro.props;
|
|
38
|
+
const { tag, ...finalAttrs } = attrs;
|
|
39
|
+
return finalAttrs;
|
|
40
|
+
})();
|
|
41
|
+
---
|
|
42
|
+
|
|
43
|
+
{
|
|
44
|
+
(
|
|
45
|
+
<WithFieldMetadata field={field} editable={editable}>
|
|
46
|
+
<WithEmptyFieldEditingComponent
|
|
47
|
+
field={field}
|
|
48
|
+
editable={editable}
|
|
49
|
+
defaultEmptyFieldEditingComponent={
|
|
50
|
+
DefaultEmptyFieldEditingComponentText
|
|
51
|
+
}
|
|
52
|
+
emptyFieldEditingComponent={emptyFieldEditingComponent}
|
|
53
|
+
{...attrs}
|
|
54
|
+
>
|
|
55
|
+
{!isEmptyField && <Tag {...attrs} set:html={field.value} />}
|
|
56
|
+
</WithEmptyFieldEditingComponent>
|
|
57
|
+
</WithFieldMetadata>
|
|
58
|
+
)
|
|
59
|
+
}
|
|
@@ -1,97 +1,97 @@
|
|
|
1
|
-
---
|
|
2
|
-
import {
|
|
3
|
-
FieldMetadata,
|
|
4
|
-
isFieldValueEmpty,
|
|
5
|
-
} from '@sitecore-content-sdk/core/layout';
|
|
6
|
-
import { EditableFieldProps } from './sharedTypes';
|
|
7
|
-
import WithFieldMetadata from '../enhancers/WithFieldMetadata.astro';
|
|
8
|
-
import WithEmptyFieldEditingComponent from '../enhancers/WithEmptyFieldEditingComponent.astro';
|
|
9
|
-
import DefaultEmptyFieldEditingComponentText from './DefaultEmptyFieldEditingComponentText.astro';
|
|
10
|
-
|
|
11
|
-
export interface TextField extends FieldMetadata {
|
|
12
|
-
value?: string | number;
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
export interface TextProps extends EditableFieldProps {
|
|
16
|
-
[htmlAttributes: string]: unknown;
|
|
17
|
-
/** The text field data. */
|
|
18
|
-
field: TextField;
|
|
19
|
-
/**
|
|
20
|
-
* The HTML element that will wrap the contents of the field.
|
|
21
|
-
*/
|
|
22
|
-
tag?: string;
|
|
23
|
-
/**
|
|
24
|
-
* If false, HTML-encoding of the field value is disabled and the value is rendered as-is.
|
|
25
|
-
*/
|
|
26
|
-
encode?: boolean;
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
const {
|
|
30
|
-
field,
|
|
31
|
-
tag,
|
|
32
|
-
editable = true,
|
|
33
|
-
encode = true,
|
|
34
|
-
emptyFieldEditingComponent,
|
|
35
|
-
...otherProps
|
|
36
|
-
} = Astro.props as TextProps;
|
|
37
|
-
|
|
38
|
-
const isEmptyField = isFieldValueEmpty(field);
|
|
39
|
-
|
|
40
|
-
// can't use editable value if we want to output unencoded
|
|
41
|
-
const isEditable = !encode ? false : editable;
|
|
42
|
-
|
|
43
|
-
let output: string | number | string[] = '';
|
|
44
|
-
if (!isEmptyField) {
|
|
45
|
-
output = field.value === undefined ? '' : field.value;
|
|
46
|
-
|
|
47
|
-
// when string value isn't formatted, we should format line breaks
|
|
48
|
-
const splitted = String(output).split('\n');
|
|
49
|
-
|
|
50
|
-
if (splitted.length) {
|
|
51
|
-
const formatted: string[] = [];
|
|
52
|
-
|
|
53
|
-
splitted.forEach((str, i) => {
|
|
54
|
-
const isLast = i === splitted.length - 1;
|
|
55
|
-
|
|
56
|
-
formatted.push(str);
|
|
57
|
-
|
|
58
|
-
if (!isLast) {
|
|
59
|
-
formatted.push('<br />');
|
|
60
|
-
}
|
|
61
|
-
});
|
|
62
|
-
|
|
63
|
-
output = formatted;
|
|
64
|
-
}
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
const Tag = tag || 'span';
|
|
68
|
-
|
|
69
|
-
const attrs: {
|
|
70
|
-
[htmlAttributes: string]: unknown;
|
|
71
|
-
} = {
|
|
72
|
-
...otherProps,
|
|
73
|
-
};
|
|
74
|
-
---
|
|
75
|
-
|
|
76
|
-
{
|
|
77
|
-
(
|
|
78
|
-
<WithFieldMetadata field={field} editable={isEditable}>
|
|
79
|
-
<WithEmptyFieldEditingComponent
|
|
80
|
-
field={field}
|
|
81
|
-
editable={isEditable}
|
|
82
|
-
defaultEmptyFieldEditingComponent={
|
|
83
|
-
DefaultEmptyFieldEditingComponentText
|
|
84
|
-
}
|
|
85
|
-
emptyFieldEditingComponent={emptyFieldEditingComponent}
|
|
86
|
-
{...attrs}
|
|
87
|
-
>
|
|
88
|
-
{!isEmptyField && (
|
|
89
|
-
<>
|
|
90
|
-
{(tag || !encode) && <Tag {...attrs} set:html={output} />}
|
|
91
|
-
{(!tag || encode) && <Fragment {...attrs} set:html={output} />}
|
|
92
|
-
</>
|
|
93
|
-
)}
|
|
94
|
-
</WithEmptyFieldEditingComponent>
|
|
95
|
-
</WithFieldMetadata>
|
|
96
|
-
)
|
|
97
|
-
}
|
|
1
|
+
---
|
|
2
|
+
import {
|
|
3
|
+
FieldMetadata,
|
|
4
|
+
isFieldValueEmpty,
|
|
5
|
+
} from '@sitecore-content-sdk/core/layout';
|
|
6
|
+
import { EditableFieldProps } from './sharedTypes';
|
|
7
|
+
import WithFieldMetadata from '../enhancers/WithFieldMetadata.astro';
|
|
8
|
+
import WithEmptyFieldEditingComponent from '../enhancers/WithEmptyFieldEditingComponent.astro';
|
|
9
|
+
import DefaultEmptyFieldEditingComponentText from './DefaultEmptyFieldEditingComponentText.astro';
|
|
10
|
+
|
|
11
|
+
export interface TextField extends FieldMetadata {
|
|
12
|
+
value?: string | number;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export interface TextProps extends EditableFieldProps {
|
|
16
|
+
[htmlAttributes: string]: unknown;
|
|
17
|
+
/** The text field data. */
|
|
18
|
+
field: TextField;
|
|
19
|
+
/**
|
|
20
|
+
* The HTML element that will wrap the contents of the field.
|
|
21
|
+
*/
|
|
22
|
+
tag?: string;
|
|
23
|
+
/**
|
|
24
|
+
* If false, HTML-encoding of the field value is disabled and the value is rendered as-is.
|
|
25
|
+
*/
|
|
26
|
+
encode?: boolean;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
const {
|
|
30
|
+
field,
|
|
31
|
+
tag,
|
|
32
|
+
editable = true,
|
|
33
|
+
encode = true,
|
|
34
|
+
emptyFieldEditingComponent,
|
|
35
|
+
...otherProps
|
|
36
|
+
} = Astro.props as TextProps;
|
|
37
|
+
|
|
38
|
+
const isEmptyField = isFieldValueEmpty(field);
|
|
39
|
+
|
|
40
|
+
// can't use editable value if we want to output unencoded
|
|
41
|
+
const isEditable = !encode ? false : editable;
|
|
42
|
+
|
|
43
|
+
let output: string | number | string[] = '';
|
|
44
|
+
if (!isEmptyField) {
|
|
45
|
+
output = field.value === undefined ? '' : field.value;
|
|
46
|
+
|
|
47
|
+
// when string value isn't formatted, we should format line breaks
|
|
48
|
+
const splitted = String(output).split('\n');
|
|
49
|
+
|
|
50
|
+
if (splitted.length) {
|
|
51
|
+
const formatted: string[] = [];
|
|
52
|
+
|
|
53
|
+
splitted.forEach((str, i) => {
|
|
54
|
+
const isLast = i === splitted.length - 1;
|
|
55
|
+
|
|
56
|
+
formatted.push(str);
|
|
57
|
+
|
|
58
|
+
if (!isLast) {
|
|
59
|
+
formatted.push('<br />');
|
|
60
|
+
}
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
output = formatted;
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
const Tag = tag || 'span';
|
|
68
|
+
|
|
69
|
+
const attrs: {
|
|
70
|
+
[htmlAttributes: string]: unknown;
|
|
71
|
+
} = {
|
|
72
|
+
...otherProps,
|
|
73
|
+
};
|
|
74
|
+
---
|
|
75
|
+
|
|
76
|
+
{
|
|
77
|
+
(
|
|
78
|
+
<WithFieldMetadata field={field} editable={isEditable}>
|
|
79
|
+
<WithEmptyFieldEditingComponent
|
|
80
|
+
field={field}
|
|
81
|
+
editable={isEditable}
|
|
82
|
+
defaultEmptyFieldEditingComponent={
|
|
83
|
+
DefaultEmptyFieldEditingComponentText
|
|
84
|
+
}
|
|
85
|
+
emptyFieldEditingComponent={emptyFieldEditingComponent}
|
|
86
|
+
{...attrs}
|
|
87
|
+
>
|
|
88
|
+
{!isEmptyField && (
|
|
89
|
+
<>
|
|
90
|
+
{(tag || !encode) && <Tag {...attrs} set:html={output} />}
|
|
91
|
+
{(!tag || encode) && <Fragment {...attrs} set:html={output} />}
|
|
92
|
+
</>
|
|
93
|
+
)}
|
|
94
|
+
</WithEmptyFieldEditingComponent>
|
|
95
|
+
</WithFieldMetadata>
|
|
96
|
+
)
|
|
97
|
+
}
|
|
@@ -1,56 +1,56 @@
|
|
|
1
|
-
---
|
|
2
|
-
/**
|
|
3
|
-
* Returns the passed field component or default component in case field value is empty and edit mode is 'metadata'
|
|
4
|
-
*/
|
|
5
|
-
|
|
6
|
-
import {
|
|
7
|
-
GenericFieldValue,
|
|
8
|
-
Field,
|
|
9
|
-
isFieldValueEmpty,
|
|
10
|
-
FieldMetadata,
|
|
11
|
-
} from '@sitecore-content-sdk/core/layout';
|
|
12
|
-
import { AstroContentSdkComponent } from '../sharedTypes/component-props';
|
|
13
|
-
|
|
14
|
-
interface FieldComponentProps {
|
|
15
|
-
// Partial<T> type is used here because _field.value_ could be required or optional for the different field types
|
|
16
|
-
field?: (Partial<Field> | GenericFieldValue) & FieldMetadata;
|
|
17
|
-
editable?: boolean;
|
|
18
|
-
emptyFieldEditingComponent?: AstroContentSdkComponent;
|
|
19
|
-
defaultEmptyFieldEditingComponent: AstroContentSdkComponent;
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
const getEmptyFieldEditingComponent = (
|
|
23
|
-
props: FieldComponentProps
|
|
24
|
-
): AstroContentSdkComponent | null => {
|
|
25
|
-
const { editable = true } = props;
|
|
26
|
-
if (props.field?.metadata && editable && isFieldValueEmpty(props.field)) {
|
|
27
|
-
return props.emptyFieldEditingComponent || props.defaultEmptyFieldEditingComponent;
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
return null;
|
|
31
|
-
};
|
|
32
|
-
|
|
33
|
-
const props = Astro.props as FieldComponentProps;
|
|
34
|
-
const { editable = true } = props;
|
|
35
|
-
|
|
36
|
-
const isEmptyEditableField = props.field?.metadata && editable && isFieldValueEmpty(props.field);
|
|
37
|
-
|
|
38
|
-
const EmptyComponent = getEmptyFieldEditingComponent(props);
|
|
39
|
-
|
|
40
|
-
let { defaultEmptyFieldEditingComponent, emptyFieldEditingComponent, ...resolvedProps } = props;
|
|
41
|
-
|
|
42
|
-
// If no custom empty field editing component is provided, we can omit unnecessary props
|
|
43
|
-
// to do not insert them to html
|
|
44
|
-
if (!props.emptyFieldEditingComponent) {
|
|
45
|
-
resolvedProps = {
|
|
46
|
-
...resolvedProps,
|
|
47
|
-
editable: undefined,
|
|
48
|
-
field: undefined,
|
|
49
|
-
};
|
|
50
|
-
}
|
|
51
|
-
---
|
|
52
|
-
|
|
53
|
-
<>
|
|
54
|
-
{isEmptyEditableField && EmptyComponent && <EmptyComponent {...resolvedProps} />}
|
|
55
|
-
{!isEmptyEditableField && <slot />}
|
|
56
|
-
</>
|
|
1
|
+
---
|
|
2
|
+
/**
|
|
3
|
+
* Returns the passed field component or default component in case field value is empty and edit mode is 'metadata'
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
import {
|
|
7
|
+
GenericFieldValue,
|
|
8
|
+
Field,
|
|
9
|
+
isFieldValueEmpty,
|
|
10
|
+
FieldMetadata,
|
|
11
|
+
} from '@sitecore-content-sdk/core/layout';
|
|
12
|
+
import { AstroContentSdkComponent } from '../sharedTypes/component-props';
|
|
13
|
+
|
|
14
|
+
interface FieldComponentProps {
|
|
15
|
+
// Partial<T> type is used here because _field.value_ could be required or optional for the different field types
|
|
16
|
+
field?: (Partial<Field> | GenericFieldValue) & FieldMetadata;
|
|
17
|
+
editable?: boolean;
|
|
18
|
+
emptyFieldEditingComponent?: AstroContentSdkComponent;
|
|
19
|
+
defaultEmptyFieldEditingComponent: AstroContentSdkComponent;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
const getEmptyFieldEditingComponent = (
|
|
23
|
+
props: FieldComponentProps
|
|
24
|
+
): AstroContentSdkComponent | null => {
|
|
25
|
+
const { editable = true } = props;
|
|
26
|
+
if (props.field?.metadata && editable && isFieldValueEmpty(props.field)) {
|
|
27
|
+
return props.emptyFieldEditingComponent || props.defaultEmptyFieldEditingComponent;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
return null;
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
const props = Astro.props as FieldComponentProps;
|
|
34
|
+
const { editable = true } = props;
|
|
35
|
+
|
|
36
|
+
const isEmptyEditableField = props.field?.metadata && editable && isFieldValueEmpty(props.field);
|
|
37
|
+
|
|
38
|
+
const EmptyComponent = getEmptyFieldEditingComponent(props);
|
|
39
|
+
|
|
40
|
+
let { defaultEmptyFieldEditingComponent, emptyFieldEditingComponent, ...resolvedProps } = props;
|
|
41
|
+
|
|
42
|
+
// If no custom empty field editing component is provided, we can omit unnecessary props
|
|
43
|
+
// to do not insert them to html
|
|
44
|
+
if (!props.emptyFieldEditingComponent) {
|
|
45
|
+
resolvedProps = {
|
|
46
|
+
...resolvedProps,
|
|
47
|
+
editable: undefined,
|
|
48
|
+
field: undefined,
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
---
|
|
52
|
+
|
|
53
|
+
<>
|
|
54
|
+
{isEmptyEditableField && EmptyComponent && <EmptyComponent {...resolvedProps} />}
|
|
55
|
+
{!isEmptyEditableField && <slot />}
|
|
56
|
+
</>
|
|
@@ -1,31 +1,31 @@
|
|
|
1
|
-
---
|
|
2
|
-
/**
|
|
3
|
-
* Wraps the field component with metadata markup intended to be used for chromes hydration in Pages
|
|
4
|
-
*/
|
|
5
|
-
|
|
6
|
-
import FieldMetadata from '../components/FieldMetadata.astro';
|
|
7
|
-
|
|
8
|
-
interface WithMetadataProps {
|
|
9
|
-
field?: {
|
|
10
|
-
metadata?: { [key: string]: unknown };
|
|
11
|
-
};
|
|
12
|
-
editable?: boolean;
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
const componentProps = Astro.props as WithMetadataProps;
|
|
16
|
-
|
|
17
|
-
const { editable = true } = componentProps;
|
|
18
|
-
const metadata = componentProps.field?.metadata;
|
|
19
|
-
const isEditable = metadata && editable;
|
|
20
|
-
---
|
|
21
|
-
|
|
22
|
-
<>
|
|
23
|
-
{!isEditable && <slot />}
|
|
24
|
-
{
|
|
25
|
-
isEditable && (
|
|
26
|
-
<FieldMetadata metadata={metadata}>
|
|
27
|
-
<slot />
|
|
28
|
-
</FieldMetadata>
|
|
29
|
-
)
|
|
30
|
-
}
|
|
31
|
-
</>
|
|
1
|
+
---
|
|
2
|
+
/**
|
|
3
|
+
* Wraps the field component with metadata markup intended to be used for chromes hydration in Pages
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
import FieldMetadata from '../components/FieldMetadata.astro';
|
|
7
|
+
|
|
8
|
+
interface WithMetadataProps {
|
|
9
|
+
field?: {
|
|
10
|
+
metadata?: { [key: string]: unknown };
|
|
11
|
+
};
|
|
12
|
+
editable?: boolean;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
const componentProps = Astro.props as WithMetadataProps;
|
|
16
|
+
|
|
17
|
+
const { editable = true } = componentProps;
|
|
18
|
+
const metadata = componentProps.field?.metadata;
|
|
19
|
+
const isEditable = metadata && editable;
|
|
20
|
+
---
|
|
21
|
+
|
|
22
|
+
<>
|
|
23
|
+
{!isEditable && <slot />}
|
|
24
|
+
{
|
|
25
|
+
isEditable && (
|
|
26
|
+
<FieldMetadata metadata={metadata}>
|
|
27
|
+
<slot />
|
|
28
|
+
</FieldMetadata>
|
|
29
|
+
)
|
|
30
|
+
}
|
|
31
|
+
</>
|