@exdst-sitecore-content-sdk/astro 0.0.5 → 0.0.7

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.
@@ -1,105 +1,105 @@
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 LinkFieldValue {
12
- [attributeName: string]: unknown;
13
- href?: string;
14
- class?: string;
15
- title?: string;
16
- target?: string;
17
- text?: string;
18
- anchor?: string;
19
- querystring?: string;
20
- linktype?: string;
21
- }
22
-
23
- export interface LinkField {
24
- value: LinkFieldValue;
25
- }
26
-
27
- export interface LinkProps extends EditableFieldProps {
28
- [htmlAttributes: string]: unknown;
29
- /** The link field data. */
30
- field: (LinkField | LinkFieldValue) & FieldMetadata;
31
- /**
32
- * Displays a link text ('description' in Sitecore) even when children exist
33
- */
34
- showLinkTextWithChildrenPresent?: boolean;
35
- }
36
-
37
- const {
38
- field,
39
- editable = true,
40
- showLinkTextWithChildrenPresent,
41
- emptyFieldEditingComponent,
42
- ...otherProps
43
- } = Astro.props as LinkProps;
44
-
45
- const children = await Astro.slots.render('default');
46
- const dynamicField: LinkField | LinkFieldValue = field;
47
-
48
- const isEmptyField = isFieldValueEmpty(dynamicField);
49
-
50
- let link,
51
- finalChildren,
52
- anchorAttrs: { [attr: string]: unknown } = {};
53
-
54
- if (!isEmptyField) {
55
- // handle link directly on field for forgetful devs
56
- link = (dynamicField as LinkFieldValue).href
57
- ? (field as LinkFieldValue)
58
- : (dynamicField as LinkField).value;
59
-
60
- if (link) {
61
- const anchor =
62
- link.linktype !== 'anchor' && link.anchor ? `#${link.anchor}` : '';
63
- const querystring = link.querystring ? `?${link.querystring}` : '';
64
-
65
- anchorAttrs = {
66
- href: `${link.href}${querystring}${anchor}`,
67
- class: link.class,
68
- title: link.title,
69
- target: link.target,
70
- };
71
-
72
- if (anchorAttrs.target === '_blank' && !anchorAttrs.rel) {
73
- // information disclosure attack prevention keeps target blank site from getting ref to window.opener
74
- anchorAttrs.rel = 'noopener noreferrer';
75
- }
76
-
77
- const linkText =
78
- showLinkTextWithChildrenPresent || !children
79
- ? link.text || link.href
80
- : null;
81
-
82
- finalChildren = children ? [linkText, ...children] : linkText;
83
- }
84
- }
85
-
86
- const attrs = { ...anchorAttrs, ...otherProps };
87
- ---
88
-
89
- {
90
- (
91
- <WithFieldMetadata field={field} editable={editable}>
92
- <WithEmptyFieldEditingComponent
93
- field={field}
94
- editable={editable}
95
- defaultEmptyFieldEditingComponent={
96
- DefaultEmptyFieldEditingComponentText
97
- }
98
- emptyFieldEditingComponent={emptyFieldEditingComponent}
99
- {...otherProps}
100
- >
101
- {!isEmptyField && link && <a {...attrs} set:html={finalChildren} />}
102
- </WithEmptyFieldEditingComponent>
103
- </WithFieldMetadata>
104
- )
105
- }
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 LinkFieldValue {
12
+ [attributeName: string]: unknown;
13
+ href?: string;
14
+ class?: string;
15
+ title?: string;
16
+ target?: string;
17
+ text?: string;
18
+ anchor?: string;
19
+ querystring?: string;
20
+ linktype?: string;
21
+ }
22
+
23
+ export interface LinkField {
24
+ value: LinkFieldValue;
25
+ }
26
+
27
+ export interface LinkProps extends EditableFieldProps {
28
+ [htmlAttributes: string]: unknown;
29
+ /** The link field data. */
30
+ field: (LinkField | LinkFieldValue) & FieldMetadata;
31
+ /**
32
+ * Displays a link text ('description' in Sitecore) even when children exist
33
+ */
34
+ showLinkTextWithChildrenPresent?: boolean;
35
+ }
36
+
37
+ const {
38
+ field,
39
+ editable = true,
40
+ showLinkTextWithChildrenPresent,
41
+ emptyFieldEditingComponent,
42
+ ...otherProps
43
+ } = Astro.props as LinkProps;
44
+
45
+ const children = await Astro.slots.render('default');
46
+ const dynamicField: LinkField | LinkFieldValue = field;
47
+
48
+ const isEmptyField = isFieldValueEmpty(dynamicField);
49
+
50
+ let link,
51
+ finalChildren,
52
+ anchorAttrs: { [attr: string]: unknown } = {};
53
+
54
+ if (!isEmptyField) {
55
+ // handle link directly on field for forgetful devs
56
+ link = (dynamicField as LinkFieldValue).href
57
+ ? (field as LinkFieldValue)
58
+ : (dynamicField as LinkField).value;
59
+
60
+ if (link) {
61
+ const anchor =
62
+ link.linktype !== 'anchor' && link.anchor ? `#${link.anchor}` : '';
63
+ const querystring = link.querystring ? `?${link.querystring}` : '';
64
+
65
+ anchorAttrs = {
66
+ href: `${link.href}${querystring}${anchor}`,
67
+ class: link.class,
68
+ title: link.title,
69
+ target: link.target,
70
+ };
71
+
72
+ if (anchorAttrs.target === '_blank' && !anchorAttrs.rel) {
73
+ // information disclosure attack prevention keeps target blank site from getting ref to window.opener
74
+ anchorAttrs.rel = 'noopener noreferrer';
75
+ }
76
+
77
+ const linkText =
78
+ showLinkTextWithChildrenPresent || !children
79
+ ? link.text || link.href
80
+ : null;
81
+
82
+ finalChildren = children ? [linkText, ...children] : linkText;
83
+ }
84
+ }
85
+
86
+ const attrs = { ...anchorAttrs, ...otherProps };
87
+ ---
88
+
89
+ {
90
+ (
91
+ <WithFieldMetadata field={field} editable={editable}>
92
+ <WithEmptyFieldEditingComponent
93
+ field={field}
94
+ editable={editable}
95
+ defaultEmptyFieldEditingComponent={
96
+ DefaultEmptyFieldEditingComponentText
97
+ }
98
+ emptyFieldEditingComponent={emptyFieldEditingComponent}
99
+ {...otherProps}
100
+ >
101
+ {!isEmptyField && link && <a {...attrs} set:html={finalChildren} />}
102
+ </WithEmptyFieldEditingComponent>
103
+ </WithFieldMetadata>
104
+ )
105
+ }
@@ -1,39 +1,39 @@
1
- ---
2
- interface MissingComponentProps {
3
- rendering?: {
4
- componentName?: string;
5
- };
6
- errorOverride?: string;
7
- }
8
-
9
- const props = Astro.props as MissingComponentProps;
10
-
11
- const componentName =
12
- props.rendering && props.rendering.componentName
13
- ? props.rendering.componentName
14
- : 'Unnamed Component';
15
-
16
- // error override would mean component is not unimplemented
17
- !props.errorOverride &&
18
- console.log(
19
- `Component props for unimplemented '${componentName}' component`,
20
- props
21
- );
22
-
23
- const errorMessage =
24
- props.errorOverride ||
25
- 'Content SDK component is missing Astro implementation. See the developer console for more information.';
26
- ---
27
-
28
- <div
29
- style={{
30
- background: 'darkorange',
31
- outline: '5px solid orange',
32
- padding: '10px',
33
- color: 'white',
34
- maxWidth: '500px',
35
- }}
36
- >
37
- <h2>{componentName}</h2>
38
- <p>{errorMessage}</p>
39
- </div>
1
+ ---
2
+ interface MissingComponentProps {
3
+ rendering?: {
4
+ componentName?: string;
5
+ };
6
+ errorOverride?: string;
7
+ }
8
+
9
+ const props = Astro.props as MissingComponentProps;
10
+
11
+ const componentName =
12
+ props.rendering && props.rendering.componentName
13
+ ? props.rendering.componentName
14
+ : 'Unnamed Component';
15
+
16
+ // error override would mean component is not unimplemented
17
+ !props.errorOverride &&
18
+ console.log(
19
+ `Component props for unimplemented '${componentName}' component`,
20
+ props
21
+ );
22
+
23
+ const errorMessage =
24
+ props.errorOverride ||
25
+ 'Content SDK component is missing Astro implementation. See the developer console for more information.';
26
+ ---
27
+
28
+ <div
29
+ style={{
30
+ background: 'darkorange',
31
+ outline: '5px solid orange',
32
+ padding: '10px',
33
+ color: 'white',
34
+ maxWidth: '500px',
35
+ }}
36
+ >
37
+ <h2>{componentName}</h2>
38
+ <p>{errorMessage}</p>
39
+ </div>
@@ -1,9 +1,9 @@
1
- ---
2
- /**
3
- * Renders the empty placeholder. The required CSS styles are applied to the placeholder in edit mode.
4
- */
5
- ---
6
-
7
- <div class="sc-jss-empty-placeholder">
8
- <slot />
9
- </div>
1
+ ---
2
+ /**
3
+ * Renders the empty placeholder. The required CSS styles are applied to the placeholder in edit mode.
4
+ */
5
+ ---
6
+
7
+ <div class="sc-jss-empty-placeholder">
8
+ <slot />
9
+ </div>
@@ -1,100 +1,100 @@
1
- ---
2
- import { ComponentRendering } from '@sitecore-content-sdk/core/layout';
3
- import ErrorBoundary from '../ErrorBoundary.astro';
4
- import PlaceholderMetadata from './PlaceholderMetadata.astro';
5
- import { useSitecore } from '../../context';
6
- import RenderWrapper from '../RenderWrapper.astro';
7
- import EmptyPlaceholder from './EmptyPlaceholder.astro';
8
- import { PlaceholderProps } from './models';
9
- import { getPlaceholderRenderings } from './placeholder-utils';
10
- import { getComponentsForRenderingData } from './PlaceholderUtils.astro';
11
-
12
- const props = Astro.props as PlaceholderProps;
13
-
14
- const { page } = useSitecore();
15
- const childProps: PlaceholderProps = { ...props, page };
16
-
17
- delete childProps.componentMap;
18
-
19
- const renderingData = childProps.rendering;
20
-
21
- const placeholderData = getPlaceholderRenderings(
22
- renderingData,
23
- childProps.name,
24
- childProps.page.mode.isEditing
25
- );
26
-
27
- const isEmpty = !placeholderData.length;
28
-
29
- const components = getComponentsForRenderingData(placeholderData, childProps);
30
- ---
31
-
32
- {
33
- (
34
- <RenderWrapper
35
- wrapper={
36
- isEmpty
37
- ? childProps.page.mode.isEditing && EmptyPlaceholder
38
- : childProps.render
39
- }
40
- >
41
- <ErrorBoundary>
42
- <RenderWrapper wrapper={isEmpty && childProps.renderEmpty}>
43
- {
44
- // Conditional rendering based on editing mode
45
- childProps.page.mode.isEditing ? (
46
- <PlaceholderMetadata
47
- placeholderName={childProps.name}
48
- rendering={childProps.rendering as ComponentRendering}
49
- >
50
- {components.map((component) => {
51
- const Component = component.component.component;
52
-
53
- return (
54
- <RenderWrapper wrapper={childProps.renderEach}>
55
- <PlaceholderMetadata
56
- rendering={component.rendering as ComponentRendering}
57
- >
58
- {!component.component.isEmpty && (
59
- <ErrorBoundary
60
- errorComponent={childProps.errorComponent}
61
- {...component.props}
62
- >
63
- <Component {...component.props} />
64
- </ErrorBoundary>
65
- )}
66
- {component.component.isEmpty && (
67
- <Component {...component.props} />
68
- )}
69
- </PlaceholderMetadata>
70
- </RenderWrapper>
71
- );
72
- })}
73
- </PlaceholderMetadata>
74
- ) : (
75
- <>
76
- {components.map((component) => {
77
- const Component = component.component.component;
78
- return (
79
- <RenderWrapper
80
- wrapper={
81
- isEmpty ? childProps.renderEmpty : childProps.renderEach
82
- }
83
- >
84
- <ErrorBoundary
85
- errorComponent={childProps.errorComponent}
86
- {...component.props}
87
- >
88
- <Component {...component.props} />
89
- </ErrorBoundary>
90
- </RenderWrapper>
91
- );
92
- })}
93
- </>
94
- )
95
- }
96
- </RenderWrapper>
97
- </ErrorBoundary>
98
- </RenderWrapper>
99
- )
100
- }
1
+ ---
2
+ import { ComponentRendering } from '@sitecore-content-sdk/core/layout';
3
+ import ErrorBoundary from '../ErrorBoundary.astro';
4
+ import PlaceholderMetadata from './PlaceholderMetadata.astro';
5
+ import { useSitecore } from '../../context';
6
+ import RenderWrapper from '../RenderWrapper.astro';
7
+ import EmptyPlaceholder from './EmptyPlaceholder.astro';
8
+ import { PlaceholderProps } from './models';
9
+ import { getPlaceholderRenderings } from './placeholder-utils';
10
+ import { getComponentsForRenderingData } from './PlaceholderUtils.astro';
11
+
12
+ const props = Astro.props as PlaceholderProps;
13
+
14
+ const { page } = useSitecore();
15
+ const childProps: PlaceholderProps = { ...props, page };
16
+
17
+ delete childProps.componentMap;
18
+
19
+ const renderingData = childProps.rendering;
20
+
21
+ const placeholderData = getPlaceholderRenderings(
22
+ renderingData,
23
+ childProps.name,
24
+ childProps.page.mode.isEditing
25
+ );
26
+
27
+ const isEmpty = !placeholderData.length;
28
+
29
+ const components = getComponentsForRenderingData(placeholderData, childProps);
30
+ ---
31
+
32
+ {
33
+ (
34
+ <RenderWrapper
35
+ wrapper={
36
+ isEmpty
37
+ ? childProps.page.mode.isEditing && EmptyPlaceholder
38
+ : childProps.render
39
+ }
40
+ >
41
+ <ErrorBoundary>
42
+ <RenderWrapper wrapper={isEmpty && childProps.renderEmpty}>
43
+ {
44
+ // Conditional rendering based on editing mode
45
+ childProps.page.mode.isEditing ? (
46
+ <PlaceholderMetadata
47
+ placeholderName={childProps.name}
48
+ rendering={childProps.rendering as ComponentRendering}
49
+ >
50
+ {components.map((component) => {
51
+ const Component = component.component.component;
52
+
53
+ return (
54
+ <RenderWrapper wrapper={childProps.renderEach}>
55
+ <PlaceholderMetadata
56
+ rendering={component.rendering as ComponentRendering}
57
+ >
58
+ {!component.component.isEmpty && (
59
+ <ErrorBoundary
60
+ errorComponent={childProps.errorComponent}
61
+ {...component.props}
62
+ >
63
+ <Component {...component.props} />
64
+ </ErrorBoundary>
65
+ )}
66
+ {component.component.isEmpty && (
67
+ <Component {...component.props} />
68
+ )}
69
+ </PlaceholderMetadata>
70
+ </RenderWrapper>
71
+ );
72
+ })}
73
+ </PlaceholderMetadata>
74
+ ) : (
75
+ <>
76
+ {components.map((component) => {
77
+ const Component = component.component.component;
78
+ return (
79
+ <RenderWrapper
80
+ wrapper={
81
+ isEmpty ? childProps.renderEmpty : childProps.renderEach
82
+ }
83
+ >
84
+ <ErrorBoundary
85
+ errorComponent={childProps.errorComponent}
86
+ {...component.props}
87
+ >
88
+ <Component {...component.props} />
89
+ </ErrorBoundary>
90
+ </RenderWrapper>
91
+ );
92
+ })}
93
+ </>
94
+ )
95
+ }
96
+ </RenderWrapper>
97
+ </ErrorBoundary>
98
+ </RenderWrapper>
99
+ )
100
+ }