@sitecore-jss/sitecore-jss-react 22.3.0 → 22.3.1-canary.2
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/EditingScripts.js +2 -1
- package/dist/cjs/components/FEaaSComponent.js +0 -1
- package/dist/cjs/components/FieldMetadata.js +3 -2
- package/dist/cjs/components/PlaceholderCommon.js +6 -22
- package/dist/cjs/components/PlaceholderMetadata.js +9 -13
- package/dist/cjs/enhancers/withSitecoreContext.js +1 -5
- package/dist/cjs/utils.js +1 -1
- package/dist/esm/components/EditingScripts.js +2 -1
- package/dist/esm/components/FEaaSComponent.js +0 -1
- package/dist/esm/components/FieldMetadata.js +3 -2
- package/dist/esm/components/PlaceholderCommon.js +4 -18
- package/dist/esm/components/PlaceholderMetadata.js +5 -9
- package/dist/esm/enhancers/withSitecoreContext.js +1 -5
- package/dist/esm/utils.js +1 -1
- package/package.json +8 -8
- package/types/components/PlaceholderCommon.d.ts +2 -14
- package/types/components/PlaceholderMetadata.d.ts +0 -1
- package/types/enhancers/withEmptyFieldEditingComponent.d.ts +1 -1
- package/types/enhancers/withSitecoreContext.d.ts +1 -5
- package/types/utils.d.ts +1 -1
|
@@ -15,8 +15,9 @@ const editing_1 = require("@sitecore-jss/sitecore-jss/editing");
|
|
|
15
15
|
const EditingScripts = () => {
|
|
16
16
|
const { sitecoreContext: { pageState, editMode, clientData, clientScripts }, } = (0, withSitecoreContext_1.useSitecoreContext)();
|
|
17
17
|
// Don't render anything if not in editing/preview mode
|
|
18
|
-
if (pageState === layout_1.LayoutServicePageState.Normal)
|
|
18
|
+
if (pageState === layout_1.LayoutServicePageState.Normal || pageState === layout_1.LayoutServicePageState.Preview) {
|
|
19
19
|
return react_1.default.createElement(react_1.default.Fragment, null);
|
|
20
|
+
}
|
|
20
21
|
if (editMode === layout_1.EditMode.Metadata) {
|
|
21
22
|
const jssClientData = Object.assign(Object.assign({}, clientData), (0, editing_1.getJssPagesClientData)());
|
|
22
23
|
return (react_1.default.createElement(react_1.default.Fragment, null, clientScripts === null || clientScripts === void 0 ? void 0 :
|
|
@@ -118,7 +118,6 @@ function fetchComponentTemplate(src, params, revisionFallback) {
|
|
|
118
118
|
/**
|
|
119
119
|
* Fetches component data based on the provided data options.
|
|
120
120
|
* This function asynchronously fetches data using the FEAAS.DataSettings.fetch method.
|
|
121
|
-
*
|
|
122
121
|
* @param {FEAAS.DataOptions} dataOptions - Options to customize data fetching.
|
|
123
122
|
* @returns {Promise<FEAAS.DataScopes>} A promise that resolves with the fetched data,
|
|
124
123
|
* or rejects with an error if data fetching encounters an issue.
|
|
@@ -6,6 +6,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
6
6
|
exports.FieldMetadata = void 0;
|
|
7
7
|
const react_1 = __importDefault(require("react"));
|
|
8
8
|
const prop_types_1 = __importDefault(require("prop-types"));
|
|
9
|
+
const editing_1 = require("@sitecore-jss/sitecore-jss/editing");
|
|
9
10
|
/**
|
|
10
11
|
* The component which renders field metadata markup
|
|
11
12
|
* @param {FieldMetadataProps} props the props of the component
|
|
@@ -18,8 +19,8 @@ const FieldMetadata = (props) => {
|
|
|
18
19
|
chrometype: 'field',
|
|
19
20
|
className: 'scpm',
|
|
20
21
|
};
|
|
21
|
-
const codeOpenAttributes = Object.assign(Object.assign({}, attributes), { kind:
|
|
22
|
-
const codeCloseAttributes = Object.assign(Object.assign({}, attributes), { kind:
|
|
22
|
+
const codeOpenAttributes = Object.assign(Object.assign({}, attributes), { kind: editing_1.MetadataKind.Open });
|
|
23
|
+
const codeCloseAttributes = Object.assign(Object.assign({}, attributes), { kind: editing_1.MetadataKind.Close });
|
|
23
24
|
return (react_1.default.createElement(react_1.default.Fragment, null,
|
|
24
25
|
react_1.default.createElement("code", Object.assign({}, codeOpenAttributes), data),
|
|
25
26
|
props.children,
|
|
@@ -14,7 +14,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
14
14
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
15
15
|
};
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
exports.PlaceholderCommon =
|
|
17
|
+
exports.PlaceholderCommon = void 0;
|
|
18
18
|
const react_1 = __importDefault(require("react"));
|
|
19
19
|
const prop_types_1 = __importDefault(require("prop-types"));
|
|
20
20
|
const MissingComponent_1 = require("./MissingComponent");
|
|
@@ -28,22 +28,6 @@ const BYOCComponent_1 = require("./BYOCComponent");
|
|
|
28
28
|
const BYOCWrapper_1 = require("./BYOCWrapper");
|
|
29
29
|
const PlaceholderMetadata_1 = require("./PlaceholderMetadata");
|
|
30
30
|
const ErrorBoundary_1 = __importDefault(require("./ErrorBoundary"));
|
|
31
|
-
/**
|
|
32
|
-
* Returns a regular expression pattern for a dynamic placeholder name.
|
|
33
|
-
* @param {string} placeholder Placeholder name with a dynamic segment (e.g. 'main-{*}')
|
|
34
|
-
* @returns Regular expression pattern for the dynamic segment
|
|
35
|
-
*/
|
|
36
|
-
const getDynamicPlaceholderPattern = (placeholder) => {
|
|
37
|
-
return new RegExp(`^${placeholder.replace(/\{\*\}+/i, '\\d+')}$`);
|
|
38
|
-
};
|
|
39
|
-
exports.getDynamicPlaceholderPattern = getDynamicPlaceholderPattern;
|
|
40
|
-
/**
|
|
41
|
-
* Checks if the placeholder name is dynamic.
|
|
42
|
-
* @param {string} placeholder Placeholder name
|
|
43
|
-
* @returns True if the placeholder name is dynamic
|
|
44
|
-
*/
|
|
45
|
-
const isDynamicPlaceholder = (placeholder) => placeholder.indexOf('{*}') !== -1;
|
|
46
|
-
exports.isDynamicPlaceholder = isDynamicPlaceholder;
|
|
47
31
|
class PlaceholderCommon extends react_1.default.Component {
|
|
48
32
|
constructor(props) {
|
|
49
33
|
super(props);
|
|
@@ -57,14 +41,14 @@ class PlaceholderCommon extends react_1.default.Component {
|
|
|
57
41
|
let result;
|
|
58
42
|
let phName = name.slice();
|
|
59
43
|
/**
|
|
60
|
-
*
|
|
61
|
-
*
|
|
62
|
-
*
|
|
44
|
+
* Process (SXA) dynamic placeholders
|
|
45
|
+
* Find and replace the matching dynamic placeholder e.g 'nameOfContainer-{*}' with the requested e.g. 'nameOfContainer-1'.
|
|
46
|
+
* For Metadata EditMode, we need to keep the raw placeholder name in place.
|
|
63
47
|
*/
|
|
64
48
|
if (rendering === null || rendering === void 0 ? void 0 : rendering.placeholders) {
|
|
65
49
|
Object.keys(rendering.placeholders).forEach((placeholder) => {
|
|
66
|
-
const patternPlaceholder = (0,
|
|
67
|
-
? (0,
|
|
50
|
+
const patternPlaceholder = (0, layout_1.isDynamicPlaceholder)(placeholder)
|
|
51
|
+
? (0, layout_1.getDynamicPlaceholderPattern)(placeholder)
|
|
68
52
|
: null;
|
|
69
53
|
if (patternPlaceholder && patternPlaceholder.test(phName)) {
|
|
70
54
|
if (editMode === layout_1.EditMode.Metadata) {
|
|
@@ -5,16 +5,12 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.PlaceholderMetadata = void 0;
|
|
7
7
|
const react_1 = __importDefault(require("react"));
|
|
8
|
-
const
|
|
9
|
-
|
|
10
|
-
* default value of uid for root placeholder when uid is not present.
|
|
11
|
-
*/
|
|
12
|
-
const DEFAULT_PLACEHOLDER_UID = '00000000-0000-0000-0000-000000000000';
|
|
8
|
+
const layout_1 = require("@sitecore-jss/sitecore-jss/layout");
|
|
9
|
+
const editing_1 = require("@sitecore-jss/sitecore-jss/editing");
|
|
13
10
|
/**
|
|
14
11
|
* A React component to generate metadata blocks for a placeholder or rendering.
|
|
15
12
|
* It utilizes dynamic attributes based on whether the component acts as a placeholder
|
|
16
13
|
* or as a rendering to properly render the surrounding code blocks.
|
|
17
|
-
*
|
|
18
14
|
* @param {object} props The properties passed to the component.
|
|
19
15
|
* @param {ComponentRendering} props.rendering The rendering data.
|
|
20
16
|
* @param {string} [props.placeholderName] The name of the placeholder.
|
|
@@ -30,22 +26,22 @@ const PlaceholderMetadata = ({ rendering, placeholderName, children, }) => {
|
|
|
30
26
|
className: 'scpm',
|
|
31
27
|
kind: kind,
|
|
32
28
|
};
|
|
33
|
-
if (kind ===
|
|
29
|
+
if (kind === editing_1.MetadataKind.Open) {
|
|
34
30
|
if (chrometype === 'placeholder' && placeholderName) {
|
|
35
31
|
let phId = '';
|
|
36
32
|
for (const placeholder of Object.keys(rendering.placeholders)) {
|
|
37
33
|
if (placeholderName === placeholder) {
|
|
38
34
|
phId = id
|
|
39
35
|
? `${placeholderName}_${id}`
|
|
40
|
-
: `${placeholderName}_${DEFAULT_PLACEHOLDER_UID}`;
|
|
36
|
+
: `${placeholderName}_${editing_1.DEFAULT_PLACEHOLDER_UID}`;
|
|
41
37
|
break;
|
|
42
38
|
}
|
|
43
39
|
// Check if the placeholder is a dynamic placeholder
|
|
44
|
-
if ((0,
|
|
45
|
-
const pattern = (0,
|
|
40
|
+
if ((0, layout_1.isDynamicPlaceholder)(placeholder)) {
|
|
41
|
+
const pattern = (0, layout_1.getDynamicPlaceholderPattern)(placeholder);
|
|
46
42
|
// Check if the placeholder matches the dynamic placeholder pattern
|
|
47
43
|
if (pattern.test(placeholderName)) {
|
|
48
|
-
phId = id ? `${placeholder}_${id}` : `${placeholder}_${DEFAULT_PLACEHOLDER_UID}`;
|
|
44
|
+
phId = id ? `${placeholder}_${id}` : `${placeholder}_${editing_1.DEFAULT_PLACEHOLDER_UID}`;
|
|
49
45
|
break;
|
|
50
46
|
}
|
|
51
47
|
}
|
|
@@ -59,9 +55,9 @@ const PlaceholderMetadata = ({ rendering, placeholderName, children, }) => {
|
|
|
59
55
|
return attributes;
|
|
60
56
|
};
|
|
61
57
|
const renderComponent = (uid, placeholderName) => (react_1.default.createElement(react_1.default.Fragment, null,
|
|
62
|
-
react_1.default.createElement("code", Object.assign({}, getCodeBlockAttributes(
|
|
58
|
+
react_1.default.createElement("code", Object.assign({}, getCodeBlockAttributes(editing_1.MetadataKind.Open, uid, placeholderName))),
|
|
63
59
|
children,
|
|
64
|
-
react_1.default.createElement("code", Object.assign({}, getCodeBlockAttributes(
|
|
60
|
+
react_1.default.createElement("code", Object.assign({}, getCodeBlockAttributes(editing_1.MetadataKind.Close, uid, placeholderName)))));
|
|
65
61
|
return react_1.default.createElement(react_1.default.Fragment, null, renderComponent(rendering.uid, placeholderName));
|
|
66
62
|
};
|
|
67
63
|
exports.PlaceholderMetadata = PlaceholderMetadata;
|
|
@@ -23,24 +23,20 @@ exports.withSitecoreContext = withSitecoreContext;
|
|
|
23
23
|
* - pageEditing - Provided by Layout Service, a boolean indicating whether the route is being accessed via the Experience Editor.
|
|
24
24
|
* - pageState - Like pageEditing, but a string: normal, preview or edit.
|
|
25
25
|
* - site - Provided by Layout Service, an object containing the name of the current Sitecore site context.
|
|
26
|
-
*
|
|
27
26
|
* @see https://jss.sitecore.com/docs/techniques/extending-layout-service/layoutservice-extending-context
|
|
28
|
-
*
|
|
29
27
|
* @param {WithSitecoreContextOptions} [options] hook options
|
|
30
|
-
*
|
|
31
28
|
* @example
|
|
32
29
|
* const EditMode = () => {
|
|
33
30
|
* const { sitecoreContext } = useSitecoreContext();
|
|
34
31
|
* return <span>Edit Mode is {sitecoreContext.pageEditing ? 'active' : 'inactive'}</span>
|
|
35
32
|
* }
|
|
36
|
-
*
|
|
37
33
|
* @example
|
|
38
34
|
* const EditMode = () => {
|
|
39
35
|
* const { sitecoreContext, updateSitecoreContext } = useSitecoreContext({ updatable: true });
|
|
40
36
|
* const onClick = () => updateSitecoreContext({ pageEditing: true });
|
|
41
37
|
* return <span onClick={onClick}>Edit Mode is {sitecoreContext.pageEditing ? 'active' : 'inactive'}</span>
|
|
42
38
|
* }
|
|
43
|
-
* @returns {
|
|
39
|
+
* @returns {object} { sitecoreContext, updateSitecoreContext }
|
|
44
40
|
*/
|
|
45
41
|
function useSitecoreContext(options) {
|
|
46
42
|
const reactContext = react_1.default.useContext(SitecoreContext_1.SitecoreContextReactContext);
|
package/dist/cjs/utils.js
CHANGED
|
@@ -82,7 +82,7 @@ const addClassName = (otherAttrs) => {
|
|
|
82
82
|
exports.addClassName = addClassName;
|
|
83
83
|
/**
|
|
84
84
|
* Converts the given tag attributes object to a string
|
|
85
|
-
* @param {
|
|
85
|
+
* @param {{[key: string]: unknown}} attributes the attributes object
|
|
86
86
|
* @returns {string} string representation of the attributes
|
|
87
87
|
*/
|
|
88
88
|
const getAttributesString = (attributes) => {
|
|
@@ -9,8 +9,9 @@ import { getJssPagesClientData } from '@sitecore-jss/sitecore-jss/editing';
|
|
|
9
9
|
export const EditingScripts = () => {
|
|
10
10
|
const { sitecoreContext: { pageState, editMode, clientData, clientScripts }, } = useSitecoreContext();
|
|
11
11
|
// Don't render anything if not in editing/preview mode
|
|
12
|
-
if (pageState === LayoutServicePageState.Normal)
|
|
12
|
+
if (pageState === LayoutServicePageState.Normal || pageState === LayoutServicePageState.Preview) {
|
|
13
13
|
return React.createElement(React.Fragment, null);
|
|
14
|
+
}
|
|
14
15
|
if (editMode === EditMode.Metadata) {
|
|
15
16
|
const jssClientData = Object.assign(Object.assign({}, clientData), getJssPagesClientData());
|
|
16
17
|
return (React.createElement(React.Fragment, null, clientScripts === null || clientScripts === void 0 ? void 0 :
|
|
@@ -87,7 +87,6 @@ function fetchComponentTemplate(src, params, revisionFallback) {
|
|
|
87
87
|
/**
|
|
88
88
|
* Fetches component data based on the provided data options.
|
|
89
89
|
* This function asynchronously fetches data using the FEAAS.DataSettings.fetch method.
|
|
90
|
-
*
|
|
91
90
|
* @param {FEAAS.DataOptions} dataOptions - Options to customize data fetching.
|
|
92
91
|
* @returns {Promise<FEAAS.DataScopes>} A promise that resolves with the fetched data,
|
|
93
92
|
* or rejects with an error if data fetching encounters an issue.
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
import PropTypes from 'prop-types';
|
|
3
|
+
import { MetadataKind } from '@sitecore-jss/sitecore-jss/editing';
|
|
3
4
|
/**
|
|
4
5
|
* The component which renders field metadata markup
|
|
5
6
|
* @param {FieldMetadataProps} props the props of the component
|
|
@@ -12,8 +13,8 @@ export const FieldMetadata = (props) => {
|
|
|
12
13
|
chrometype: 'field',
|
|
13
14
|
className: 'scpm',
|
|
14
15
|
};
|
|
15
|
-
const codeOpenAttributes = Object.assign(Object.assign({}, attributes), { kind:
|
|
16
|
-
const codeCloseAttributes = Object.assign(Object.assign({}, attributes), { kind:
|
|
16
|
+
const codeOpenAttributes = Object.assign(Object.assign({}, attributes), { kind: MetadataKind.Open });
|
|
17
|
+
const codeCloseAttributes = Object.assign(Object.assign({}, attributes), { kind: MetadataKind.Close });
|
|
17
18
|
return (React.createElement(React.Fragment, null,
|
|
18
19
|
React.createElement("code", Object.assign({}, codeOpenAttributes), data),
|
|
19
20
|
props.children,
|
|
@@ -12,7 +12,7 @@ var __rest = (this && this.__rest) || function (s, e) {
|
|
|
12
12
|
import React from 'react';
|
|
13
13
|
import PropTypes from 'prop-types';
|
|
14
14
|
import { MissingComponent } from './MissingComponent';
|
|
15
|
-
import { EditMode, } from '@sitecore-jss/sitecore-jss/layout';
|
|
15
|
+
import { EditMode, isDynamicPlaceholder, getDynamicPlaceholderPattern, } from '@sitecore-jss/sitecore-jss/layout';
|
|
16
16
|
import { constants } from '@sitecore-jss/sitecore-jss';
|
|
17
17
|
import { convertAttributesToReactProps } from '../utils';
|
|
18
18
|
import { HiddenRendering } from './HiddenRendering';
|
|
@@ -22,20 +22,6 @@ import { BYOCComponent, BYOC_COMPONENT_RENDERING_NAME } from './BYOCComponent';
|
|
|
22
22
|
import { BYOCWrapper, BYOC_WRAPPER_RENDERING_NAME } from './BYOCWrapper';
|
|
23
23
|
import { PlaceholderMetadata } from './PlaceholderMetadata';
|
|
24
24
|
import ErrorBoundary from './ErrorBoundary';
|
|
25
|
-
/**
|
|
26
|
-
* Returns a regular expression pattern for a dynamic placeholder name.
|
|
27
|
-
* @param {string} placeholder Placeholder name with a dynamic segment (e.g. 'main-{*}')
|
|
28
|
-
* @returns Regular expression pattern for the dynamic segment
|
|
29
|
-
*/
|
|
30
|
-
export const getDynamicPlaceholderPattern = (placeholder) => {
|
|
31
|
-
return new RegExp(`^${placeholder.replace(/\{\*\}+/i, '\\d+')}$`);
|
|
32
|
-
};
|
|
33
|
-
/**
|
|
34
|
-
* Checks if the placeholder name is dynamic.
|
|
35
|
-
* @param {string} placeholder Placeholder name
|
|
36
|
-
* @returns True if the placeholder name is dynamic
|
|
37
|
-
*/
|
|
38
|
-
export const isDynamicPlaceholder = (placeholder) => placeholder.indexOf('{*}') !== -1;
|
|
39
25
|
export class PlaceholderCommon extends React.Component {
|
|
40
26
|
constructor(props) {
|
|
41
27
|
super(props);
|
|
@@ -49,9 +35,9 @@ export class PlaceholderCommon extends React.Component {
|
|
|
49
35
|
let result;
|
|
50
36
|
let phName = name.slice();
|
|
51
37
|
/**
|
|
52
|
-
*
|
|
53
|
-
*
|
|
54
|
-
*
|
|
38
|
+
* Process (SXA) dynamic placeholders
|
|
39
|
+
* Find and replace the matching dynamic placeholder e.g 'nameOfContainer-{*}' with the requested e.g. 'nameOfContainer-1'.
|
|
40
|
+
* For Metadata EditMode, we need to keep the raw placeholder name in place.
|
|
55
41
|
*/
|
|
56
42
|
if (rendering === null || rendering === void 0 ? void 0 : rendering.placeholders) {
|
|
57
43
|
Object.keys(rendering.placeholders).forEach((placeholder) => {
|
|
@@ -1,14 +1,10 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
|
-
import { getDynamicPlaceholderPattern, isDynamicPlaceholder } from '
|
|
3
|
-
|
|
4
|
-
* default value of uid for root placeholder when uid is not present.
|
|
5
|
-
*/
|
|
6
|
-
const DEFAULT_PLACEHOLDER_UID = '00000000-0000-0000-0000-000000000000';
|
|
2
|
+
import { getDynamicPlaceholderPattern, isDynamicPlaceholder, } from '@sitecore-jss/sitecore-jss/layout';
|
|
3
|
+
import { MetadataKind, DEFAULT_PLACEHOLDER_UID } from '@sitecore-jss/sitecore-jss/editing';
|
|
7
4
|
/**
|
|
8
5
|
* A React component to generate metadata blocks for a placeholder or rendering.
|
|
9
6
|
* It utilizes dynamic attributes based on whether the component acts as a placeholder
|
|
10
7
|
* or as a rendering to properly render the surrounding code blocks.
|
|
11
|
-
*
|
|
12
8
|
* @param {object} props The properties passed to the component.
|
|
13
9
|
* @param {ComponentRendering} props.rendering The rendering data.
|
|
14
10
|
* @param {string} [props.placeholderName] The name of the placeholder.
|
|
@@ -24,7 +20,7 @@ export const PlaceholderMetadata = ({ rendering, placeholderName, children, }) =
|
|
|
24
20
|
className: 'scpm',
|
|
25
21
|
kind: kind,
|
|
26
22
|
};
|
|
27
|
-
if (kind ===
|
|
23
|
+
if (kind === MetadataKind.Open) {
|
|
28
24
|
if (chrometype === 'placeholder' && placeholderName) {
|
|
29
25
|
let phId = '';
|
|
30
26
|
for (const placeholder of Object.keys(rendering.placeholders)) {
|
|
@@ -53,8 +49,8 @@ export const PlaceholderMetadata = ({ rendering, placeholderName, children, }) =
|
|
|
53
49
|
return attributes;
|
|
54
50
|
};
|
|
55
51
|
const renderComponent = (uid, placeholderName) => (React.createElement(React.Fragment, null,
|
|
56
|
-
React.createElement("code", Object.assign({}, getCodeBlockAttributes(
|
|
52
|
+
React.createElement("code", Object.assign({}, getCodeBlockAttributes(MetadataKind.Open, uid, placeholderName))),
|
|
57
53
|
children,
|
|
58
|
-
React.createElement("code", Object.assign({}, getCodeBlockAttributes(
|
|
54
|
+
React.createElement("code", Object.assign({}, getCodeBlockAttributes(MetadataKind.Close, uid, placeholderName)))));
|
|
59
55
|
return React.createElement(React.Fragment, null, renderComponent(rendering.uid, placeholderName));
|
|
60
56
|
};
|
|
@@ -16,24 +16,20 @@ export function withSitecoreContext(options) {
|
|
|
16
16
|
* - pageEditing - Provided by Layout Service, a boolean indicating whether the route is being accessed via the Experience Editor.
|
|
17
17
|
* - pageState - Like pageEditing, but a string: normal, preview or edit.
|
|
18
18
|
* - site - Provided by Layout Service, an object containing the name of the current Sitecore site context.
|
|
19
|
-
*
|
|
20
19
|
* @see https://jss.sitecore.com/docs/techniques/extending-layout-service/layoutservice-extending-context
|
|
21
|
-
*
|
|
22
20
|
* @param {WithSitecoreContextOptions} [options] hook options
|
|
23
|
-
*
|
|
24
21
|
* @example
|
|
25
22
|
* const EditMode = () => {
|
|
26
23
|
* const { sitecoreContext } = useSitecoreContext();
|
|
27
24
|
* return <span>Edit Mode is {sitecoreContext.pageEditing ? 'active' : 'inactive'}</span>
|
|
28
25
|
* }
|
|
29
|
-
*
|
|
30
26
|
* @example
|
|
31
27
|
* const EditMode = () => {
|
|
32
28
|
* const { sitecoreContext, updateSitecoreContext } = useSitecoreContext({ updatable: true });
|
|
33
29
|
* const onClick = () => updateSitecoreContext({ pageEditing: true });
|
|
34
30
|
* return <span onClick={onClick}>Edit Mode is {sitecoreContext.pageEditing ? 'active' : 'inactive'}</span>
|
|
35
31
|
* }
|
|
36
|
-
* @returns {
|
|
32
|
+
* @returns {object} { sitecoreContext, updateSitecoreContext }
|
|
37
33
|
*/
|
|
38
34
|
export function useSitecoreContext(options) {
|
|
39
35
|
const reactContext = React.useContext(SitecoreContextReactContext);
|
package/dist/esm/utils.js
CHANGED
|
@@ -75,7 +75,7 @@ export const addClassName = (otherAttrs) => {
|
|
|
75
75
|
};
|
|
76
76
|
/**
|
|
77
77
|
* Converts the given tag attributes object to a string
|
|
78
|
-
* @param {
|
|
78
|
+
* @param {{[key: string]: unknown}} attributes the attributes object
|
|
79
79
|
* @returns {string} string representation of the attributes
|
|
80
80
|
*/
|
|
81
81
|
export const getAttributesString = (attributes) => {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sitecore-jss/sitecore-jss-react",
|
|
3
|
-
"version": "22.3.
|
|
3
|
+
"version": "22.3.1-canary.2",
|
|
4
4
|
"main": "dist/cjs/index.js",
|
|
5
5
|
"module": "dist/esm/index.js",
|
|
6
6
|
"sideEffects": false,
|
|
@@ -11,10 +11,10 @@
|
|
|
11
11
|
"test": "mocha --require ts-node/register/transpile-only --require ./src/tests/shim.ts ./src/tests/jsdom-setup.ts ./src/tests/enzyme-setup.ts \"./src/**/*.test.ts\" \"./src/**/*.test.tsx\" --exit",
|
|
12
12
|
"prepublishOnly": "npm run build",
|
|
13
13
|
"coverage": "nyc npm test",
|
|
14
|
-
"generate-docs": "npx typedoc --plugin typedoc-plugin-markdown --readme none --out ../../ref-docs/sitecore-jss-react src/index.ts --githubPages false"
|
|
14
|
+
"generate-docs": "npx typedoc --plugin typedoc-plugin-markdown --outputFileStrategy Members --parametersFormat table --readme none --out ../../ref-docs/sitecore-jss-react src/index.ts --githubPages false"
|
|
15
15
|
},
|
|
16
16
|
"engines": {
|
|
17
|
-
"node": ">=
|
|
17
|
+
"node": ">=22"
|
|
18
18
|
},
|
|
19
19
|
"author": {
|
|
20
20
|
"name": "Sitecore Corporation",
|
|
@@ -33,7 +33,7 @@
|
|
|
33
33
|
"@types/mocha": "^10.0.1",
|
|
34
34
|
"@types/node": "20.14.2",
|
|
35
35
|
"@types/prop-types": "^15.7.5",
|
|
36
|
-
"@types/react": "^18.2.
|
|
36
|
+
"@types/react": "^18.2.45",
|
|
37
37
|
"@types/react-dom": "^18.0.10",
|
|
38
38
|
"@types/sinon": "^10.0.13",
|
|
39
39
|
"@types/sinon-chai": "^3.2.9",
|
|
@@ -43,9 +43,9 @@
|
|
|
43
43
|
"cheerio": "1.0.0-rc.12",
|
|
44
44
|
"del-cli": "^5.0.0",
|
|
45
45
|
"enzyme": "^3.11.0",
|
|
46
|
-
"eslint": "^8.
|
|
46
|
+
"eslint": "^8.56.0",
|
|
47
47
|
"eslint-plugin-react": "^7.31.11",
|
|
48
|
-
"jsdom": "^
|
|
48
|
+
"jsdom": "^25.0.1",
|
|
49
49
|
"mocha": "^10.2.0",
|
|
50
50
|
"nyc": "^15.1.0",
|
|
51
51
|
"react": "^18.2.0",
|
|
@@ -61,14 +61,14 @@
|
|
|
61
61
|
"react-dom": "^18.2.0"
|
|
62
62
|
},
|
|
63
63
|
"dependencies": {
|
|
64
|
-
"@sitecore-jss/sitecore-jss": "22.3.
|
|
64
|
+
"@sitecore-jss/sitecore-jss": "^22.3.1-canary.2",
|
|
65
65
|
"fast-deep-equal": "^3.1.3",
|
|
66
66
|
"prop-types": "^15.8.1",
|
|
67
67
|
"style-attr": "^1.3.0"
|
|
68
68
|
},
|
|
69
69
|
"description": "",
|
|
70
70
|
"types": "types/index.d.ts",
|
|
71
|
-
"gitHead": "
|
|
71
|
+
"gitHead": "5b35bbbe22b6ea21a1829950e371d54422ebf8fd",
|
|
72
72
|
"files": [
|
|
73
73
|
"dist",
|
|
74
74
|
"types"
|
|
@@ -12,18 +12,6 @@ export type ComponentProps = {
|
|
|
12
12
|
[key: string]: unknown;
|
|
13
13
|
rendering: ComponentRendering;
|
|
14
14
|
};
|
|
15
|
-
/**
|
|
16
|
-
* Returns a regular expression pattern for a dynamic placeholder name.
|
|
17
|
-
* @param {string} placeholder Placeholder name with a dynamic segment (e.g. 'main-{*}')
|
|
18
|
-
* @returns Regular expression pattern for the dynamic segment
|
|
19
|
-
*/
|
|
20
|
-
export declare const getDynamicPlaceholderPattern: (placeholder: string) => RegExp;
|
|
21
|
-
/**
|
|
22
|
-
* Checks if the placeholder name is dynamic.
|
|
23
|
-
* @param {string} placeholder Placeholder name
|
|
24
|
-
* @returns True if the placeholder name is dynamic
|
|
25
|
-
*/
|
|
26
|
-
export declare const isDynamicPlaceholder: (placeholder: string) => boolean;
|
|
27
15
|
export interface PlaceholderProps {
|
|
28
16
|
[key: string]: unknown;
|
|
29
17
|
/** Name of the placeholder to render. */
|
|
@@ -81,7 +69,7 @@ export interface PlaceholderProps {
|
|
|
81
69
|
}
|
|
82
70
|
export declare class PlaceholderCommon<T extends PlaceholderProps> extends React.Component<T> {
|
|
83
71
|
static propTypes: {
|
|
84
|
-
rendering: PropTypes.Validator<NonNullable<NonNullable<ComponentRendering | RouteData<Record<string, Field<import("@sitecore-jss/sitecore-jss/layout").GenericFieldValue> | Item | Item[]>>>>>;
|
|
72
|
+
rendering: PropTypes.Validator<NonNullable<NonNullable<ComponentRendering<import("@sitecore-jss/sitecore-jss/layout").ComponentFields> | RouteData<Record<string, Field<import("@sitecore-jss/sitecore-jss/layout").GenericFieldValue> | Item | Item[]>>>>>;
|
|
85
73
|
fields: PropTypes.Requireable<{
|
|
86
74
|
[x: string]: NonNullable<NonNullable<Field<import("@sitecore-jss/sitecore-jss/layout").GenericFieldValue> | Item[]>>;
|
|
87
75
|
}>;
|
|
@@ -99,7 +87,7 @@ export declare class PlaceholderCommon<T extends PlaceholderProps> extends React
|
|
|
99
87
|
error?: Error;
|
|
100
88
|
}>;
|
|
101
89
|
constructor(props: T);
|
|
102
|
-
static getPlaceholderDataFromRenderingData(rendering: ComponentRendering | RouteData, name: string, editMode?: EditMode): (ComponentRendering | HtmlElementRendering)[];
|
|
90
|
+
static getPlaceholderDataFromRenderingData(rendering: ComponentRendering | RouteData, name: string, editMode?: EditMode): (ComponentRendering<import("@sitecore-jss/sitecore-jss/layout").ComponentFields> | HtmlElementRendering)[];
|
|
103
91
|
componentDidMount(): void;
|
|
104
92
|
componentDidUpdate(): void;
|
|
105
93
|
componentDidCatch(error: Error): void;
|
|
@@ -20,7 +20,6 @@ export type CodeBlockAttributes = {
|
|
|
20
20
|
* A React component to generate metadata blocks for a placeholder or rendering.
|
|
21
21
|
* It utilizes dynamic attributes based on whether the component acts as a placeholder
|
|
22
22
|
* or as a rendering to properly render the surrounding code blocks.
|
|
23
|
-
*
|
|
24
23
|
* @param {object} props The properties passed to the component.
|
|
25
24
|
* @param {ComponentRendering} props.rendering The rendering data.
|
|
26
25
|
* @param {string} [props.placeholderName] The name of the placeholder.
|
|
@@ -3,7 +3,7 @@ import React, { ComponentType } from 'react';
|
|
|
3
3
|
import { GenericFieldValue, Field, FieldMetadata } from '@sitecore-jss/sitecore-jss/layout';
|
|
4
4
|
/**
|
|
5
5
|
* The HOC options
|
|
6
|
-
|
|
6
|
+
*/
|
|
7
7
|
export interface WithEmptyFieldEditingComponentOptions {
|
|
8
8
|
/**
|
|
9
9
|
* the default empty field component
|
|
@@ -20,24 +20,20 @@ export declare function withSitecoreContext(options?: WithSitecoreContextOptions
|
|
|
20
20
|
* - pageEditing - Provided by Layout Service, a boolean indicating whether the route is being accessed via the Experience Editor.
|
|
21
21
|
* - pageState - Like pageEditing, but a string: normal, preview or edit.
|
|
22
22
|
* - site - Provided by Layout Service, an object containing the name of the current Sitecore site context.
|
|
23
|
-
*
|
|
24
23
|
* @see https://jss.sitecore.com/docs/techniques/extending-layout-service/layoutservice-extending-context
|
|
25
|
-
*
|
|
26
24
|
* @param {WithSitecoreContextOptions} [options] hook options
|
|
27
|
-
*
|
|
28
25
|
* @example
|
|
29
26
|
* const EditMode = () => {
|
|
30
27
|
* const { sitecoreContext } = useSitecoreContext();
|
|
31
28
|
* return <span>Edit Mode is {sitecoreContext.pageEditing ? 'active' : 'inactive'}</span>
|
|
32
29
|
* }
|
|
33
|
-
*
|
|
34
30
|
* @example
|
|
35
31
|
* const EditMode = () => {
|
|
36
32
|
* const { sitecoreContext, updateSitecoreContext } = useSitecoreContext({ updatable: true });
|
|
37
33
|
* const onClick = () => updateSitecoreContext({ pageEditing: true });
|
|
38
34
|
* return <span onClick={onClick}>Edit Mode is {sitecoreContext.pageEditing ? 'active' : 'inactive'}</span>
|
|
39
35
|
* }
|
|
40
|
-
* @returns {
|
|
36
|
+
* @returns {object} { sitecoreContext, updateSitecoreContext }
|
|
41
37
|
*/
|
|
42
38
|
export declare function useSitecoreContext(options?: WithSitecoreContextOptions): {
|
|
43
39
|
sitecoreContext: SitecoreContextValue;
|
package/types/utils.d.ts
CHANGED
|
@@ -26,7 +26,7 @@ export declare const addClassName: (otherAttrs: {
|
|
|
26
26
|
}) => void;
|
|
27
27
|
/**
|
|
28
28
|
* Converts the given tag attributes object to a string
|
|
29
|
-
* @param {
|
|
29
|
+
* @param {{[key: string]: unknown}} attributes the attributes object
|
|
30
30
|
* @returns {string} string representation of the attributes
|
|
31
31
|
*/
|
|
32
32
|
export declare const getAttributesString: (attributes: {
|