@contentstack/studio-core 0.0.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/README.md +3 -0
- package/dist/index.d.ts +92 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +5 -0
- package/dist/index.js.map +1 -0
- package/dist/internal-components/Button.d.ts +2 -0
- package/dist/internal-components/Button.d.ts.map +1 -0
- package/dist/internal-components/Button.js +10 -0
- package/dist/internal-components/Button.js.map +1 -0
- package/dist/internal-components/styles.d.ts +5 -0
- package/dist/internal-components/styles.d.ts.map +1 -0
- package/dist/internal-components/styles.js +28 -0
- package/dist/internal-components/styles.js.map +1 -0
- package/dist/sdk/index.d.ts +59 -0
- package/dist/sdk/index.d.ts.map +1 -0
- package/dist/sdk/index.js +67 -0
- package/dist/sdk/index.js.map +1 -0
- package/dist/style-extractor/extract-styles.d.ts +16 -0
- package/dist/style-extractor/extract-styles.d.ts.map +1 -0
- package/dist/style-extractor/extract-styles.js +83 -0
- package/dist/style-extractor/extract-styles.js.map +1 -0
- package/dist/utils/handle-responsive-styles.util.d.ts +12 -0
- package/dist/utils/handle-responsive-styles.util.d.ts.map +1 -0
- package/dist/utils/handle-responsive-styles.util.js +61 -0
- package/dist/utils/handle-responsive-styles.util.js.map +1 -0
- package/package.json +52 -0
package/README.md
ADDED
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
2
|
+
import * as _contentstack_studio_client from '@contentstack/studio-client';
|
|
3
|
+
import { StudioSpec, UserConfig, LightConfig, StudioSdk, ComposableStudioLightSdk } from '@contentstack/studio-client';
|
|
4
|
+
import { NodeStyles } from '@contentstack/studio-internal';
|
|
5
|
+
|
|
6
|
+
declare const Button: (props: React.ButtonHTMLAttributes<HTMLButtonElement>) => react_jsx_runtime.JSX.Element;
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Extracts and concatenates CSS styles from a list of composition specifications.
|
|
10
|
+
*
|
|
11
|
+
* @param {(StudioSpec | null)[]} specs - Array of composition specifications to extract styles from
|
|
12
|
+
* @returns {string} Combined CSS styles string including root styles and composition-specific styles
|
|
13
|
+
*
|
|
14
|
+
* @description
|
|
15
|
+
* This function performs the following:
|
|
16
|
+
* 1. Extracts root CSS styles if not already extracted
|
|
17
|
+
* 2. Flushes any previously collected styles
|
|
18
|
+
* 3. Extracts styles from each valid composition specification
|
|
19
|
+
* 4. Combines root styles with composition-specific styles
|
|
20
|
+
*/
|
|
21
|
+
declare const extractStyles: (specs: (StudioSpec | null)[]) => string;
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* Processes node styles and generates responsive styles based on the provided style configuration.
|
|
25
|
+
* The default styles are not provied in the named style object, as it is assumed that it will be
|
|
26
|
+
* passed to the component via `className` and not as a separate prop.
|
|
27
|
+
*
|
|
28
|
+
* @param nodeStyles - An object containing styles for different sections of a node.
|
|
29
|
+
* @param styleConfiguration - Configuration options for registering component styles, including default styles and classes.
|
|
30
|
+
* @returns A tuple containing the default style class and an object mapping section names to their respective style classes.
|
|
31
|
+
*/
|
|
32
|
+
declare function handleNodeStyles(nodeStyles: NodeStyles, nodeUid: string): [string, Record<string, string>, Set<string>];
|
|
33
|
+
|
|
34
|
+
declare let sdk: StudioSdk | null;
|
|
35
|
+
declare let lightSdk: ComposableStudioLightSdk | null;
|
|
36
|
+
/**
|
|
37
|
+
* Main entry point for initializing the Studio SDK.
|
|
38
|
+
*
|
|
39
|
+
* Call `init` with your user configuration to set up the SDK.
|
|
40
|
+
* Most of the operations requires you to initialize the SDK first.
|
|
41
|
+
*
|
|
42
|
+
* It returns an object with methods that you can use to interact
|
|
43
|
+
* with Studio.
|
|
44
|
+
*
|
|
45
|
+
* @example
|
|
46
|
+
* ```ts
|
|
47
|
+
* import { studioSdk } from '@contentstack/studio-react';
|
|
48
|
+
* import contentstack from '@contentstack/delivery-sdk';
|
|
49
|
+
*
|
|
50
|
+
* const stack = contentstack.stack({
|
|
51
|
+
* apiKey: "YOUR_API_KEY",
|
|
52
|
+
* deliveryToken: "YOUR_DELIVERY_TOKEN",
|
|
53
|
+
* environment: "YOUR_ENVIRONMENT",
|
|
54
|
+
* live_preview: {
|
|
55
|
+
preview_token: "YOUR_PREVIEW_TOKEN",
|
|
56
|
+
enable: true,
|
|
57
|
+
},
|
|
58
|
+
})
|
|
59
|
+
*
|
|
60
|
+
* studioSdk.init({ stackSdk: stack });
|
|
61
|
+
* ```
|
|
62
|
+
* @example - Fetching the spec of a composition in SSR
|
|
63
|
+
* ```ts
|
|
64
|
+
* import { studioSdk, StudioComponent } from '@contentstack/studio-react';
|
|
65
|
+
*
|
|
66
|
+
* const sdk = studioSdk.init({ stackSdk: stack });
|
|
67
|
+
*
|
|
68
|
+
* function MyComponent() {
|
|
69
|
+
* const { specOptions } = sdk.fetchComposition({
|
|
70
|
+
* composableUid: 'your-composition-uid',
|
|
71
|
+
* searchQuery: window.location.search,
|
|
72
|
+
* });
|
|
73
|
+
*
|
|
74
|
+
* return <StudioComponent specOptions={specOptions} />;
|
|
75
|
+
* }
|
|
76
|
+
* ```
|
|
77
|
+
*
|
|
78
|
+
* @returns {StudioSdk['public']} The public SDK interface for interacting with Studio.
|
|
79
|
+
*/
|
|
80
|
+
declare const studioSdk: {
|
|
81
|
+
init(userConfig: UserConfig): {
|
|
82
|
+
fetchCompositionData: (queryOptions: _contentstack_studio_client.CompositionQueryForSSRInput, options?: _contentstack_studio_client.CompositionQueryOptions) => Promise<_contentstack_studio_client.StudioComponentSpecOptions>;
|
|
83
|
+
getConfig: () => Pick<_contentstack_studio_client.Config, "contentTypeUid" | "cslp" | "openInStudioButton">;
|
|
84
|
+
};
|
|
85
|
+
};
|
|
86
|
+
declare function lightInit(userConfig?: LightConfig): {
|
|
87
|
+
internal: {
|
|
88
|
+
getConfig: () => Pick<LightConfig, "contentTypeUid" | "cslp" | "openInStudioButton">;
|
|
89
|
+
};
|
|
90
|
+
} | null;
|
|
91
|
+
|
|
92
|
+
export { Button, extractStyles, handleNodeStyles, lightInit, lightSdk, sdk, studioSdk };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,8BAA8B,CAAC;AACtD,OAAO,EAAE,aAAa,EAAE,MAAM,kCAAkC,CAAC;AACjE,OAAO,EAAE,gBAAgB,EAAE,MAAM,uCAAuC,CAAC;AACzE,OAAO,EAAE,SAAS,EAAE,SAAS,EAAE,GAAG,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export { Button } from './internal-components/Button.js';
|
|
2
|
+
export { extractStyles } from './style-extractor/extract-styles.js';
|
|
3
|
+
export { handleNodeStyles } from './utils/handle-responsive-styles.util.js';
|
|
4
|
+
export { lightInit, lightSdk, sdk, studioSdk } from './sdk/index.js';
|
|
5
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Button.d.ts","sourceRoot":"","sources":["../../src/internal-components/Button.tsx"],"names":[],"mappings":"AAGA,eAAO,MAAM,MAAM,GACjB,OAAO,KAAK,CAAC,oBAAoB,CAAC,iBAAiB,CAAC,4CAKrD,CAAC"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { jsx } from 'react/jsx-runtime';
|
|
2
|
+
import { css } from 'goober';
|
|
3
|
+
import { styleFactory } from './styles.js';
|
|
4
|
+
|
|
5
|
+
const Button = (props) => {
|
|
6
|
+
return (jsx("button", { className: styleFactory(css).openInStudioButton, ...props }));
|
|
7
|
+
};
|
|
8
|
+
|
|
9
|
+
export { Button };
|
|
10
|
+
//# sourceMappingURL=Button.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Button.js","sources":["../../src/internal-components/Button.tsx"],"sourcesContent":[null],"names":["_jsx","gooberCss"],"mappings":";;;;AAGO,MAAM,MAAM,GAAG,CACpB,KAAoD,KAClD;AACF,IAAA,QACEA,GAAA,CAAA,QAAA,EAAA,EAAQ,SAAS,EAAE,YAAY,CAACC,GAAS,CAAC,CAAC,kBAAkB,EAAA,GAAM,KAAK,EAAA,CAAI;AAEhF;;;;"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"styles.d.ts","sourceRoot":"","sources":["../../src/internal-components/styles.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,IAAI,SAAS,EAAE,MAAM,QAAQ,CAAC;AAE1C,eAAO,MAAM,YAAY,GAAI,KAAK,OAAO,SAAS;;CAwBhD,CAAC"}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
const styleFactory = (css) => ({
|
|
2
|
+
openInStudioButton: css({
|
|
3
|
+
cursor: "pointer",
|
|
4
|
+
fontSize: ".875rem",
|
|
5
|
+
minHeight: "2rem",
|
|
6
|
+
maxHeight: "2rem",
|
|
7
|
+
padding: "0.3125rem 1rem",
|
|
8
|
+
backgroundColor: "#f9f8ff",
|
|
9
|
+
border: "1px solid #6c5ce7",
|
|
10
|
+
color: "#6c5ce7",
|
|
11
|
+
borderRadius: "4px",
|
|
12
|
+
fontFamily: "Inter",
|
|
13
|
+
textAlign: "center",
|
|
14
|
+
verticalAlign: "middle",
|
|
15
|
+
fontWeight: "600",
|
|
16
|
+
display: "flex",
|
|
17
|
+
alignItems: "center",
|
|
18
|
+
justifyContent: "center",
|
|
19
|
+
gap: ".5rem",
|
|
20
|
+
"&:focus": {
|
|
21
|
+
boxShadow: "0 0 0 2px #ada4f4",
|
|
22
|
+
outline: "none",
|
|
23
|
+
},
|
|
24
|
+
}),
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
export { styleFactory };
|
|
28
|
+
//# sourceMappingURL=styles.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"styles.js","sources":["../../src/internal-components/styles.ts"],"sourcesContent":[null],"names":[],"mappings":"MAEa,YAAY,GAAG,CAAC,GAAqB,MAAM;IACtD,kBAAkB,EAAE,GAAG,CAAC;AACtB,QAAA,MAAM,EAAE,SAAS;AACjB,QAAA,QAAQ,EAAE,SAAS;AACnB,QAAA,SAAS,EAAE,MAAM;AACjB,QAAA,SAAS,EAAE,MAAM;AACjB,QAAA,OAAO,EAAE,gBAAgB;AACzB,QAAA,eAAe,EAAE,SAAS;AAC1B,QAAA,MAAM,EAAE,mBAAmB;AAC3B,QAAA,KAAK,EAAE,SAAS;AAChB,QAAA,YAAY,EAAE,KAAK;AACnB,QAAA,UAAU,EAAE,OAAO;AACnB,QAAA,SAAS,EAAE,QAAQ;AACnB,QAAA,aAAa,EAAE,QAAQ;AACvB,QAAA,UAAU,EAAE,KAAK;AACjB,QAAA,OAAO,EAAE,MAAM;AACf,QAAA,UAAU,EAAE,QAAQ;AACpB,QAAA,cAAc,EAAE,QAAQ;AACxB,QAAA,GAAG,EAAE,OAAO;AACZ,QAAA,SAAS,EAAE;AACT,YAAA,SAAS,EAAE,mBAAmB;AAC9B,YAAA,OAAO,EAAE,MAAM;AAChB,SAAA;KACF,CAAC;AACH,CAAA;;;;"}
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import { UserConfig, StudioSdk, LightConfig, ComposableStudioLightSdk } from "@contentstack/studio-client";
|
|
2
|
+
export declare let sdk: StudioSdk | null;
|
|
3
|
+
export declare let lightSdk: ComposableStudioLightSdk | null;
|
|
4
|
+
/**
|
|
5
|
+
* Main entry point for initializing the Studio SDK.
|
|
6
|
+
*
|
|
7
|
+
* Call `init` with your user configuration to set up the SDK.
|
|
8
|
+
* Most of the operations requires you to initialize the SDK first.
|
|
9
|
+
*
|
|
10
|
+
* It returns an object with methods that you can use to interact
|
|
11
|
+
* with Studio.
|
|
12
|
+
*
|
|
13
|
+
* @example
|
|
14
|
+
* ```ts
|
|
15
|
+
* import { studioSdk } from '@contentstack/studio-react';
|
|
16
|
+
* import contentstack from '@contentstack/delivery-sdk';
|
|
17
|
+
*
|
|
18
|
+
* const stack = contentstack.stack({
|
|
19
|
+
* apiKey: "YOUR_API_KEY",
|
|
20
|
+
* deliveryToken: "YOUR_DELIVERY_TOKEN",
|
|
21
|
+
* environment: "YOUR_ENVIRONMENT",
|
|
22
|
+
* live_preview: {
|
|
23
|
+
preview_token: "YOUR_PREVIEW_TOKEN",
|
|
24
|
+
enable: true,
|
|
25
|
+
},
|
|
26
|
+
})
|
|
27
|
+
*
|
|
28
|
+
* studioSdk.init({ stackSdk: stack });
|
|
29
|
+
* ```
|
|
30
|
+
* @example - Fetching the spec of a composition in SSR
|
|
31
|
+
* ```ts
|
|
32
|
+
* import { studioSdk, StudioComponent } from '@contentstack/studio-react';
|
|
33
|
+
*
|
|
34
|
+
* const sdk = studioSdk.init({ stackSdk: stack });
|
|
35
|
+
*
|
|
36
|
+
* function MyComponent() {
|
|
37
|
+
* const { specOptions } = sdk.fetchComposition({
|
|
38
|
+
* composableUid: 'your-composition-uid',
|
|
39
|
+
* searchQuery: window.location.search,
|
|
40
|
+
* });
|
|
41
|
+
*
|
|
42
|
+
* return <StudioComponent specOptions={specOptions} />;
|
|
43
|
+
* }
|
|
44
|
+
* ```
|
|
45
|
+
*
|
|
46
|
+
* @returns {StudioSdk['public']} The public SDK interface for interacting with Studio.
|
|
47
|
+
*/
|
|
48
|
+
export declare const studioSdk: {
|
|
49
|
+
init(userConfig: UserConfig): {
|
|
50
|
+
fetchCompositionData: (queryOptions: import("@contentstack/studio-client").CompositionQueryForSSRInput, options?: import("@contentstack/studio-client").CompositionQueryOptions) => Promise<import("@contentstack/studio-client").StudioComponentSpecOptions>;
|
|
51
|
+
getConfig: () => Pick<import("@contentstack/studio-client").Config, "contentTypeUid" | "cslp" | "openInStudioButton">;
|
|
52
|
+
};
|
|
53
|
+
};
|
|
54
|
+
export declare function lightInit(userConfig?: LightConfig): {
|
|
55
|
+
internal: {
|
|
56
|
+
getConfig: () => Pick<LightConfig, "contentTypeUid" | "cslp" | "openInStudioButton">;
|
|
57
|
+
};
|
|
58
|
+
} | null;
|
|
59
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/sdk/index.ts"],"names":[],"mappings":"AAAA,OAAkC,EAChC,UAAU,EACV,SAAS,EACT,WAAW,EACX,wBAAwB,EACzB,MAAM,6BAA6B,CAAC;AAErC,eAAO,IAAI,GAAG,EAAE,SAAS,GAAG,IAAW,CAAC;AACxC,eAAO,IAAI,QAAQ,EAAE,wBAAwB,GAAG,IAAW,CAAC;AAE5D;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2CG;AACH,eAAO,MAAM,SAAS;qBACH,UAAU;uHAgBi8S,CAAC;;;CAP99S,CAAC;AAEF,wBAAgB,SAAS,CAAC,UAAU,CAAC,EAAE,WAAW;;;;SAIjD"}
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import ComposableStudioCommonSdk from '@contentstack/studio-client';
|
|
2
|
+
|
|
3
|
+
let sdk = null;
|
|
4
|
+
let lightSdk = null;
|
|
5
|
+
/**
|
|
6
|
+
* Main entry point for initializing the Studio SDK.
|
|
7
|
+
*
|
|
8
|
+
* Call `init` with your user configuration to set up the SDK.
|
|
9
|
+
* Most of the operations requires you to initialize the SDK first.
|
|
10
|
+
*
|
|
11
|
+
* It returns an object with methods that you can use to interact
|
|
12
|
+
* with Studio.
|
|
13
|
+
*
|
|
14
|
+
* @example
|
|
15
|
+
* ```ts
|
|
16
|
+
* import { studioSdk } from '@contentstack/studio-react';
|
|
17
|
+
* import contentstack from '@contentstack/delivery-sdk';
|
|
18
|
+
*
|
|
19
|
+
* const stack = contentstack.stack({
|
|
20
|
+
* apiKey: "YOUR_API_KEY",
|
|
21
|
+
* deliveryToken: "YOUR_DELIVERY_TOKEN",
|
|
22
|
+
* environment: "YOUR_ENVIRONMENT",
|
|
23
|
+
* live_preview: {
|
|
24
|
+
preview_token: "YOUR_PREVIEW_TOKEN",
|
|
25
|
+
enable: true,
|
|
26
|
+
},
|
|
27
|
+
})
|
|
28
|
+
*
|
|
29
|
+
* studioSdk.init({ stackSdk: stack });
|
|
30
|
+
* ```
|
|
31
|
+
* @example - Fetching the spec of a composition in SSR
|
|
32
|
+
* ```ts
|
|
33
|
+
* import { studioSdk, StudioComponent } from '@contentstack/studio-react';
|
|
34
|
+
*
|
|
35
|
+
* const sdk = studioSdk.init({ stackSdk: stack });
|
|
36
|
+
*
|
|
37
|
+
* function MyComponent() {
|
|
38
|
+
* const { specOptions } = sdk.fetchComposition({
|
|
39
|
+
* composableUid: 'your-composition-uid',
|
|
40
|
+
* searchQuery: window.location.search,
|
|
41
|
+
* });
|
|
42
|
+
*
|
|
43
|
+
* return <StudioComponent specOptions={specOptions} />;
|
|
44
|
+
* }
|
|
45
|
+
* ```
|
|
46
|
+
*
|
|
47
|
+
* @returns {StudioSdk['public']} The public SDK interface for interacting with Studio.
|
|
48
|
+
*/
|
|
49
|
+
const studioSdk = {
|
|
50
|
+
init(userConfig) {
|
|
51
|
+
if (sdk) {
|
|
52
|
+
console.warn("Studio SDK already initialized");
|
|
53
|
+
return sdk.public;
|
|
54
|
+
}
|
|
55
|
+
sdk = ComposableStudioCommonSdk.init(userConfig);
|
|
56
|
+
return sdk.public;
|
|
57
|
+
},
|
|
58
|
+
};
|
|
59
|
+
function lightInit(userConfig) {
|
|
60
|
+
if (!userConfig)
|
|
61
|
+
return null;
|
|
62
|
+
lightSdk = ComposableStudioCommonSdk.lightInit(userConfig);
|
|
63
|
+
return lightSdk;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
export { lightInit, lightSdk, sdk, studioSdk };
|
|
67
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sources":["../../src/sdk/index.ts"],"sourcesContent":[null],"names":[],"mappings":";;AAOO,IAAI,GAAG,GAAqB;AAC5B,IAAI,QAAQ,GAAoC;AAEvD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA2CG;AACI,MAAM,SAAS,GAAG;AACvB,IAAA,IAAI,CAAC,UAAsB,EAAA;QACzB,IAAI,GAAG,EAAE;AACP,YAAA,OAAO,CAAC,IAAI,CAAC,gCAAgC,CAAC;YAC9C,OAAO,GAAG,CAAC,MAAM;QACnB;AAEA,QAAA,GAAG,GAAG,yBAAyB,CAAC,IAAI,CAAC,UAAU,CAAC;QAChD,OAAO,GAAG,CAAC,MAAM;IACnB,CAAC;;AAGG,SAAU,SAAS,CAAC,UAAwB,EAAA;AAChD,IAAA,IAAI,CAAC,UAAU;AAAE,QAAA,OAAO,IAAI;AAC5B,IAAA,QAAQ,GAAG,yBAAyB,CAAC,SAAS,CAAC,UAAU,CAAC;AAC1D,IAAA,OAAO,QAAQ;AACjB;;;;"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { StudioSpec } from "@contentstack/studio-client";
|
|
2
|
+
/**
|
|
3
|
+
* Extracts and concatenates CSS styles from a list of composition specifications.
|
|
4
|
+
*
|
|
5
|
+
* @param {(StudioSpec | null)[]} specs - Array of composition specifications to extract styles from
|
|
6
|
+
* @returns {string} Combined CSS styles string including root styles and composition-specific styles
|
|
7
|
+
*
|
|
8
|
+
* @description
|
|
9
|
+
* This function performs the following:
|
|
10
|
+
* 1. Extracts root CSS styles if not already extracted
|
|
11
|
+
* 2. Flushes any previously collected styles
|
|
12
|
+
* 3. Extracts styles from each valid composition specification
|
|
13
|
+
* 4. Combines root styles with composition-specific styles
|
|
14
|
+
*/
|
|
15
|
+
export declare const extractStyles: (specs: (StudioSpec | null)[]) => string;
|
|
16
|
+
//# sourceMappingURL=extract-styles.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"extract-styles.d.ts","sourceRoot":"","sources":["../../src/style-extractor/extract-styles.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,6BAA6B,CAAC;AAoCzD;;;;;;;;;;;;GAYG;AACH,eAAO,MAAM,aAAa,GAAI,OAAO,CAAC,UAAU,GAAG,IAAI,CAAC,EAAE,KAAG,MAoC5D,CAAC"}
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
import { extractCss, css } from 'goober';
|
|
2
|
+
import { handleNodeStyles } from '../utils/handle-responsive-styles.util.js';
|
|
3
|
+
import { Button } from '../internal-components/Button.js';
|
|
4
|
+
|
|
5
|
+
let rootExtracted = "";
|
|
6
|
+
const extractStylesInternal = (node, collectedStyleSheet = "") => {
|
|
7
|
+
const nodeProps = node.props;
|
|
8
|
+
const { styles, uid } = node;
|
|
9
|
+
// loop through the slot nodes to further extract style
|
|
10
|
+
Object.entries(nodeProps).forEach(([field, prop]) => {
|
|
11
|
+
if (prop.type === "slot") {
|
|
12
|
+
const currentSlotNode = nodeProps[field];
|
|
13
|
+
const currentSlotUid = currentSlotNode.slot;
|
|
14
|
+
const slots = node.slots?.[currentSlotUid] ?? [];
|
|
15
|
+
slots.forEach((slotNode) => {
|
|
16
|
+
if (slotNode.metadata?.visible === false) {
|
|
17
|
+
return;
|
|
18
|
+
}
|
|
19
|
+
collectedStyleSheet =
|
|
20
|
+
extractStylesInternal(slotNode, collectedStyleSheet) || "";
|
|
21
|
+
});
|
|
22
|
+
}
|
|
23
|
+
});
|
|
24
|
+
handleNodeStyles(styles, uid);
|
|
25
|
+
const generatedStyles = extractCss();
|
|
26
|
+
return collectedStyleSheet + generatedStyles;
|
|
27
|
+
};
|
|
28
|
+
/**
|
|
29
|
+
* Extracts and concatenates CSS styles from a list of composition specifications.
|
|
30
|
+
*
|
|
31
|
+
* @param {(StudioSpec | null)[]} specs - Array of composition specifications to extract styles from
|
|
32
|
+
* @returns {string} Combined CSS styles string including root styles and composition-specific styles
|
|
33
|
+
*
|
|
34
|
+
* @description
|
|
35
|
+
* This function performs the following:
|
|
36
|
+
* 1. Extracts root CSS styles if not already extracted
|
|
37
|
+
* 2. Flushes any previously collected styles
|
|
38
|
+
* 3. Extracts styles from each valid composition specification
|
|
39
|
+
* 4. Combines root styles with composition-specific styles
|
|
40
|
+
*/
|
|
41
|
+
const extractStyles = (specs) => {
|
|
42
|
+
if (!specs || !specs.length)
|
|
43
|
+
return "";
|
|
44
|
+
if (!rootExtracted) {
|
|
45
|
+
rootExtracted = extractCss();
|
|
46
|
+
}
|
|
47
|
+
else {
|
|
48
|
+
// flush any styles collected in previous render
|
|
49
|
+
extractCss();
|
|
50
|
+
}
|
|
51
|
+
// extract styles for each composition
|
|
52
|
+
const styles = [];
|
|
53
|
+
specs.forEach((compositionSpec) => {
|
|
54
|
+
if (!compositionSpec)
|
|
55
|
+
return;
|
|
56
|
+
// Use the UI node directly as it's now the page node
|
|
57
|
+
const node = compositionSpec.ui;
|
|
58
|
+
const style = extractStylesInternal(node);
|
|
59
|
+
if (!style)
|
|
60
|
+
return;
|
|
61
|
+
styles.push(style);
|
|
62
|
+
});
|
|
63
|
+
// style for open in studio button
|
|
64
|
+
css({
|
|
65
|
+
position: "relative",
|
|
66
|
+
height: "100%",
|
|
67
|
+
".open-in-studio-btn": {
|
|
68
|
+
position: "absolute",
|
|
69
|
+
display: "none",
|
|
70
|
+
},
|
|
71
|
+
"&:hover": {
|
|
72
|
+
".open-in-studio-btn": {
|
|
73
|
+
display: "flex",
|
|
74
|
+
},
|
|
75
|
+
},
|
|
76
|
+
});
|
|
77
|
+
Button({});
|
|
78
|
+
styles.push(extractCss());
|
|
79
|
+
return rootExtracted + styles.join("");
|
|
80
|
+
};
|
|
81
|
+
|
|
82
|
+
export { extractStyles };
|
|
83
|
+
//# sourceMappingURL=extract-styles.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"extract-styles.js","sources":["../../src/style-extractor/extract-styles.ts"],"sourcesContent":[null],"names":[],"mappings":";;;;AAMA,IAAI,aAAa,GAAW,EAAE;AAC9B,MAAM,qBAAqB,GAAG,CAC5B,IAAU,EACV,mBAAA,GAA8B,EAAE,KAC9B;AACF,IAAA,MAAM,SAAS,GAAG,IAAI,CAAC,KAAK;AAC5B,IAAA,MAAM,EAAE,MAAM,EAAE,GAAG,EAAE,GAAG,IAAI;;AAG5B,IAAA,MAAM,CAAC,OAAO,CAAC,SAAS,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,KAAK,EAAE,IAAI,CAAC,KAAI;AAClD,QAAA,IAAI,IAAI,CAAC,IAAI,KAAK,MAAM,EAAE;AACxB,YAAA,MAAM,eAAe,GAAG,SAAS,CAAC,KAAK,CAAiC;AACxE,YAAA,MAAM,cAAc,GAAG,eAAe,CAAC,IAAI;YAC3C,MAAM,KAAK,GAAG,IAAI,CAAC,KAAK,GAAG,cAAc,CAAC,IAAI,EAAE;AAChD,YAAA,KAAK,CAAC,OAAO,CAAC,CAAC,QAAQ,KAAI;gBACzB,IAAI,QAAQ,CAAC,QAAQ,EAAE,OAAO,KAAK,KAAK,EAAE;oBACxC;gBACF;gBACA,mBAAmB;AACjB,oBAAA,qBAAqB,CAAC,QAAQ,EAAE,mBAAmB,CAAC,IAAI,EAAE;AAC9D,YAAA,CAAC,CAAC;QACJ;AACF,IAAA,CAAC,CAAC;AAEF,IAAA,gBAAgB,CAAC,MAAM,EAAE,GAAG,CAAC;AAE7B,IAAA,MAAM,eAAe,GAAG,UAAU,EAAE;IACpC,OAAO,mBAAmB,GAAG,eAAe;AAC9C,CAAC;AAED;;;;;;;;;;;;AAYG;AACI,MAAM,aAAa,GAAG,CAAC,KAA4B,KAAY;AACpE,IAAA,IAAI,CAAC,KAAK,IAAI,CAAC,KAAK,CAAC,MAAM;AAAE,QAAA,OAAO,EAAE;IACtC,IAAI,CAAC,aAAa,EAAE;QAClB,aAAa,GAAG,UAAU,EAAE;IAC9B;SAAO;;AAEL,QAAA,UAAU,EAAE;IACd;;IAGA,MAAM,MAAM,GAAa,EAAE;AAC3B,IAAA,KAAK,CAAC,OAAO,CAAC,CAAC,eAAe,KAAI;AAChC,QAAA,IAAI,CAAC,eAAe;YAAE;;AAEtB,QAAA,MAAM,IAAI,GAAG,eAAe,CAAC,EAAE;AAC/B,QAAA,MAAM,KAAK,GAAG,qBAAqB,CAAC,IAAI,CAAC;AACzC,QAAA,IAAI,CAAC,KAAK;YAAE;AACZ,QAAA,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC;AACpB,IAAA,CAAC,CAAC;;AAEF,IAAA,GAAG,CAAC;AACF,QAAA,QAAQ,EAAE,UAAU;AACpB,QAAA,MAAM,EAAE,MAAM;AACd,QAAA,qBAAqB,EAAE;AACrB,YAAA,QAAQ,EAAE,UAAU;AACpB,YAAA,OAAO,EAAE,MAAM;AAChB,SAAA;AACD,QAAA,SAAS,EAAE;AACT,YAAA,qBAAqB,EAAE;AACrB,gBAAA,OAAO,EAAE,MAAM;AAChB,aAAA;AACF,SAAA;AACF,KAAA,CAAC;IACF,MAAM,CAAC,EAAE,CAAC;AACV,IAAA,MAAM,CAAC,IAAI,CAAC,UAAU,EAAE,CAAC;IACzB,OAAO,aAAa,GAAG,MAAM,CAAC,IAAI,CAAC,EAAE,CAAC;AACxC;;;;"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { NodeStyles } from "@contentstack/studio-internal";
|
|
2
|
+
/**
|
|
3
|
+
* Processes node styles and generates responsive styles based on the provided style configuration.
|
|
4
|
+
* The default styles are not provied in the named style object, as it is assumed that it will be
|
|
5
|
+
* passed to the component via `className` and not as a separate prop.
|
|
6
|
+
*
|
|
7
|
+
* @param nodeStyles - An object containing styles for different sections of a node.
|
|
8
|
+
* @param styleConfiguration - Configuration options for registering component styles, including default styles and classes.
|
|
9
|
+
* @returns A tuple containing the default style class and an object mapping section names to their respective style classes.
|
|
10
|
+
*/
|
|
11
|
+
export declare function handleNodeStyles(nodeStyles: NodeStyles, nodeUid: string): [string, Record<string, string>, Set<string>];
|
|
12
|
+
//# sourceMappingURL=handle-responsive-styles.util.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"handle-responsive-styles.util.d.ts","sourceRoot":"","sources":["../../src/utils/handle-responsive-styles.util.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,+BAA+B,CAAC;AAIhE;;;;;;;;GAQG;AACH,wBAAgB,gBAAgB,CAC9B,UAAU,EAAE,UAAU,EACtB,OAAO,EAAE,MAAM,GACd,CAAC,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,EAAE,GAAG,CAAC,MAAM,CAAC,CAAC,CAyD/C"}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import { BreakpointManager, createClassNameUid } from '@contentstack/studio-client';
|
|
2
|
+
import classNames from 'classnames';
|
|
3
|
+
import { css } from 'goober';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Processes node styles and generates responsive styles based on the provided style configuration.
|
|
7
|
+
* The default styles are not provied in the named style object, as it is assumed that it will be
|
|
8
|
+
* passed to the component via `className` and not as a separate prop.
|
|
9
|
+
*
|
|
10
|
+
* @param nodeStyles - An object containing styles for different sections of a node.
|
|
11
|
+
* @param styleConfiguration - Configuration options for registering component styles, including default styles and classes.
|
|
12
|
+
* @returns A tuple containing the default style class and an object mapping section names to their respective style classes.
|
|
13
|
+
*/
|
|
14
|
+
function handleNodeStyles(nodeStyles, nodeUid) {
|
|
15
|
+
if (!nodeStyles || !Object.keys(nodeStyles).length) {
|
|
16
|
+
return ["", {}, new Set()];
|
|
17
|
+
}
|
|
18
|
+
const breakpointManager = BreakpointManager.getInstance();
|
|
19
|
+
const breakpoints = breakpointManager.getBreakpoints();
|
|
20
|
+
const fontFamilies = new Set(); // Collect fonts
|
|
21
|
+
const processedStyles = Object.entries(nodeStyles).map(([section, nodeStyle]) => {
|
|
22
|
+
const responsiveStyles = nodeStyle.responsiveStyles ?? {};
|
|
23
|
+
// we need this to get the default styles of the section
|
|
24
|
+
const classNameUid = createClassNameUid(nodeUid, section);
|
|
25
|
+
let styles = {};
|
|
26
|
+
breakpoints?.forEach((breakpoint) => {
|
|
27
|
+
const breakpointName = breakpoint.id;
|
|
28
|
+
const breakpointStyles = responsiveStyles[breakpointName];
|
|
29
|
+
const breakpointQuery = breakpoint.query;
|
|
30
|
+
if (breakpointStyles) {
|
|
31
|
+
styles =
|
|
32
|
+
breakpointName === "default"
|
|
33
|
+
? { ...styles, ...breakpointStyles }
|
|
34
|
+
: { ...styles, [`@media ${breakpointQuery}`]: breakpointStyles };
|
|
35
|
+
}
|
|
36
|
+
// load the google fonts
|
|
37
|
+
if (breakpointStyles?.fontFamily) {
|
|
38
|
+
const fontFamily = breakpointStyles.fontFamily.split(",")[0].trim();
|
|
39
|
+
/**
|
|
40
|
+
* NOTE: We are collecting the font families here to load them in the
|
|
41
|
+
* `useEffect` hook of the component. This is done to avoid loading the
|
|
42
|
+
* font on server side.
|
|
43
|
+
*/
|
|
44
|
+
fontFamilies.add(fontFamily);
|
|
45
|
+
}
|
|
46
|
+
});
|
|
47
|
+
const responsiveClass = css(styles);
|
|
48
|
+
return [
|
|
49
|
+
section,
|
|
50
|
+
classNames(responsiveClass, nodeStyle.classes ?? [], classNameUid),
|
|
51
|
+
];
|
|
52
|
+
});
|
|
53
|
+
const namedStyles = Object.fromEntries(processedStyles);
|
|
54
|
+
const DEFAULT_STYLE_KEY = "default";
|
|
55
|
+
const defaultStyle = namedStyles[DEFAULT_STYLE_KEY] ?? "";
|
|
56
|
+
delete namedStyles[DEFAULT_STYLE_KEY];
|
|
57
|
+
return [defaultStyle, namedStyles, fontFamilies];
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
export { handleNodeStyles };
|
|
61
|
+
//# sourceMappingURL=handle-responsive-styles.util.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"handle-responsive-styles.util.js","sources":["../../src/utils/handle-responsive-styles.util.ts"],"sourcesContent":[null],"names":[],"mappings":";;;;AAQA;;;;;;;;AAQG;AACG,SAAU,gBAAgB,CAC9B,UAAsB,EACtB,OAAe,EAAA;AAEf,IAAA,IAAI,CAAC,UAAU,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC,MAAM,EAAE;QAClD,OAAO,CAAC,EAAE,EAAE,EAAE,EAAE,IAAI,GAAG,EAAU,CAAC;IACpC;AACA,IAAA,MAAM,iBAAiB,GAAG,iBAAiB,CAAC,WAAW,EAAE;AACzD,IAAA,MAAM,WAAW,GAAG,iBAAiB,CAAC,cAAc,EAAE;AACtD,IAAA,MAAM,YAAY,GAAG,IAAI,GAAG,EAAU,CAAC;AAEvC,IAAA,MAAM,eAAe,GAAuB,MAAM,CAAC,OAAO,CAAC,UAAU,CAAC,CAAC,GAAG,CACxE,CAAC,CAAC,OAAO,EAAE,SAAS,CAAC,KAAI;AACvB,QAAA,MAAM,gBAAgB,GAAG,SAAS,CAAC,gBAAgB,IAAI,EAAE;;QAGzD,MAAM,YAAY,GAAG,kBAAkB,CAAC,OAAO,EAAE,OAAO,CAAC;QAEzD,IAAI,MAAM,GAAG,EAAE;AAEf,QAAA,WAAW,EAAE,OAAO,CAAC,CAAC,UAAU,KAAI;AAClC,YAAA,MAAM,cAAc,GAAG,UAAU,CAAC,EAAE;AACpC,YAAA,MAAM,gBAAgB,GAAG,gBAAgB,CAAC,cAAc,CAAC;AACzD,YAAA,MAAM,eAAe,GAAG,UAAU,CAAC,KAAK;YAExC,IAAI,gBAAgB,EAAE;gBACpB,MAAM;AACJ,oBAAA,cAAc,KAAK;AACjB,0BAAE,EAAE,GAAG,MAAM,EAAE,GAAG,gBAAgB;AAClC,0BAAE,EAAE,GAAG,MAAM,EAAE,CAAC,CAAA,OAAA,EAAU,eAAe,CAAA,CAAE,GAAG,gBAAgB,EAAE;YACtE;;AAGA,YAAA,IAAI,gBAAgB,EAAE,UAAU,EAAE;AAChC,gBAAA,MAAM,UAAU,GAAG,gBAAgB,CAAC,UAAU,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,EAAE;AACnE;;;;AAIG;AACH,gBAAA,YAAY,CAAC,GAAG,CAAC,UAAU,CAAC;YAC9B;AACF,QAAA,CAAC,CAAC;AAEF,QAAA,MAAM,eAAe,GAAG,GAAG,CAAC,MAAM,CAAC;QACnC,OAAO;YACL,OAAO;YACP,UAAU,CAAC,eAAe,EAAE,SAAS,CAAC,OAAO,IAAI,EAAE,EAAE,YAAY,CAAC;SACnE;AACH,IAAA,CAAC,CACF;IAED,MAAM,WAAW,GAAG,MAAM,CAAC,WAAW,CAAC,eAAe,CAAC;IAEvD,MAAM,iBAAiB,GAAG,SAAS;IAEnC,MAAM,YAAY,GAAG,WAAW,CAAC,iBAAiB,CAAC,IAAI,EAAE;AACzD,IAAA,OAAO,WAAW,CAAC,iBAAiB,CAAC;AAErC,IAAA,OAAO,CAAC,YAAY,EAAE,WAAW,EAAE,YAAY,CAAC;AAClD;;;;"}
|
package/package.json
ADDED
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@contentstack/studio-core",
|
|
3
|
+
"version": "0.0.1",
|
|
4
|
+
"description": "Provides utility to fetch spec for composable component",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "dist/index.js",
|
|
7
|
+
"types": "dist/index.d.ts",
|
|
8
|
+
"module": "dist/index.js",
|
|
9
|
+
"sideEffects": false,
|
|
10
|
+
"files": [
|
|
11
|
+
"dist/"
|
|
12
|
+
],
|
|
13
|
+
"scripts": {
|
|
14
|
+
"build": "rollup -c rollup.config.mjs",
|
|
15
|
+
"dev": "rollup -c rollup.config.mjs --watch",
|
|
16
|
+
"test": "vitest run",
|
|
17
|
+
"test:watch": "vitest watch",
|
|
18
|
+
"test:coverage": "vitest run --coverage"
|
|
19
|
+
},
|
|
20
|
+
"repository": {
|
|
21
|
+
"type": "git",
|
|
22
|
+
"url": "git+https://github.com/contentstack/composable-studio-sdk.git"
|
|
23
|
+
},
|
|
24
|
+
"author": "Contentstack",
|
|
25
|
+
"license": "MIT",
|
|
26
|
+
"bugs": {
|
|
27
|
+
"url": "https://github.com/contentstack/composable-studio-sdk/issues"
|
|
28
|
+
},
|
|
29
|
+
"homepage": "https://github.com/contentstack/composable-studio-sdk#readme",
|
|
30
|
+
"devDependencies": {
|
|
31
|
+
"@rollup/plugin-commonjs": "^28.0.6",
|
|
32
|
+
"@rollup/plugin-node-resolve": "^16.0.1",
|
|
33
|
+
"@rollup/plugin-terser": "^0.4.4",
|
|
34
|
+
"@rollup/plugin-typescript": "^12.1.4",
|
|
35
|
+
"@types/react": "^19.1.10",
|
|
36
|
+
"@types/react-dom": "^19.1.7",
|
|
37
|
+
"rollup-plugin-dts": "^6.2.1",
|
|
38
|
+
"rollup-plugin-node-externals": "^8.0.1",
|
|
39
|
+
"rollup-plugin-preserve-directives": "^0.4.0",
|
|
40
|
+
"tsup": "^8.5.0"
|
|
41
|
+
},
|
|
42
|
+
"dependencies": {
|
|
43
|
+
"@contentstack/studio-client": "file:../studio-client",
|
|
44
|
+
"@contentstack/studio-registry": "file:../studio-registry",
|
|
45
|
+
"classnames": "^2.5.1",
|
|
46
|
+
"goober": "^2.1.16"
|
|
47
|
+
},
|
|
48
|
+
"peerDependencies": {
|
|
49
|
+
"react": ">=16.0.0",
|
|
50
|
+
"react-dom": ">=16.0.0"
|
|
51
|
+
}
|
|
52
|
+
}
|