@cntrl-site/sdk-nextjs 0.30.1 → 0.30.3

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.
@@ -0,0 +1,5 @@
1
+ <component name="ProjectCodeStyleConfiguration">
2
+ <state>
3
+ <option name="PREFERRED_PROJECT_CODE_STYLE" value="Default" />
4
+ </state>
5
+ </component>
Binary file
Binary file
Binary file
Binary file
@@ -36,20 +36,41 @@ const CodeEmbedItem = ({ item, sectionId, onResize }) => {
36
36
  (0, useRegisterResize_1.useRegisterResize)(ref, onResize);
37
37
  const pos = stylesMap[anchor];
38
38
  const layoutValues = [item.area, item.layoutParams, item.state.hover];
39
- return ((0, jsx_runtime_1.jsxs)(LinkWrapper_1.LinkWrapper, { url: (_a = item.link) === null || _a === void 0 ? void 0 : _a.url, target: (_b = item.link) === null || _b === void 0 ? void 0 : _b.target, children: [(0, jsx_runtime_1.jsx)("div", { className: `embed-wrapper-${item.id}`, style: Object.assign({ opacity: `${opacity}`, transform: `rotate(${angle}deg)`, filter: `blur(${blur * 100}vw)` }, pos), ref: setRef, children: (0, jsx_runtime_1.jsx)("div", { className: "embed", dangerouslySetInnerHTML: { __html: html } }) }), (0, jsx_runtime_1.jsx)(style_1.default, { id: id, children: `
40
- .embed -wrapper-${item.id} {
39
+ (0, react_1.useEffect)(() => {
40
+ if (!ref)
41
+ return;
42
+ const scripts = ref.querySelectorAll('script');
43
+ for (const script of scripts) {
44
+ const newScript = document.createElement('script');
45
+ for (const attr of script.getAttributeNames()) {
46
+ newScript.setAttribute(attr, script.getAttribute(attr));
47
+ }
48
+ newScript.textContent = script.textContent;
49
+ script.parentNode.removeChild(script);
50
+ ref.appendChild(newScript);
51
+ }
52
+ }, [item.commonParams.html]);
53
+ (0, react_1.useEffect)(() => {
54
+ if (!ref)
55
+ return;
56
+ const iframe = ref.querySelector(`[data-embed="${item.id}"]`);
57
+ if (!iframe)
58
+ return;
59
+ iframe.srcdoc = item.commonParams.html;
60
+ }, [item.commonParams.html, item.commonParams.iframe, ref]);
61
+ return ((0, jsx_runtime_1.jsxs)(LinkWrapper_1.LinkWrapper, { url: (_a = item.link) === null || _a === void 0 ? void 0 : _a.url, target: (_b = item.link) === null || _b === void 0 ? void 0 : _b.target, children: [(0, jsx_runtime_1.jsx)("div", { className: `embed-wrapper-${item.id}`, style: { opacity: `${opacity}`, transform: `rotate(${angle}deg)`, filter: `blur(${blur * 100}vw)` }, ref: setRef, children: item.commonParams.iframe ? ((0, jsx_runtime_1.jsx)("iframe", { "data-embed": item.id, className: `embed-${item.id}`, style: Object.assign(Object.assign({}, pos), { border: 'unset' }) })) : ((0, jsx_runtime_1.jsx)("div", { className: `embed-${item.id}`, style: Object.assign({}, pos), dangerouslySetInnerHTML: { __html: html } })) }), (0, jsx_runtime_1.jsx)(style_1.default, { id: id, children: `
62
+ .embed-wrapper-${item.id} {
41
63
  position: absolute;
42
64
  width: 100%;
43
65
  height: 100%;
44
66
  }
45
- .embed {
46
- width: 100%;
47
- height: 100%;
67
+ .embed-${item.id} {
68
+ transform: ${item.commonParams.scale ? 'scale(var(--layout-deviation))' : 'none'};
69
+ transform-origin: top left;
48
70
  z-index: 1;
49
71
  border: none;
50
- overflow: hidden;
51
72
  }
52
- ${(0, sdk_1.getLayoutStyles)(layouts, layoutValues, ([area, layoutParams, hoverParams]) => {
73
+ ${(0, sdk_1.getLayoutStyles)(layouts, layoutValues, ([area, layoutParams, hoverParams], exemplary) => {
53
74
  return (`
54
75
  .embed-wrapper-${item.id} {
55
76
  opacity: ${layoutParams.opacity};
@@ -57,6 +78,10 @@ const CodeEmbedItem = ({ item, sectionId, onResize }) => {
57
78
  filter: ${layoutParams.blur !== 0 ? `blur(${layoutParams.blur * 100}vw)` : 'unset'};
58
79
  transition: ${(0, HoverStyles_1.getTransitions)(['angle', 'blur', 'opacity'], hoverParams)};
59
80
  }
81
+ .embed-${item.id} {
82
+ width: ${item.commonParams.scale ? `${area.width * exemplary}px` : '100%'};
83
+ height: ${item.commonParams.scale ? `${area.height * exemplary}px` : '100%'};
84
+ }
60
85
  .embed-wrapper-${item.id}:hover {
61
86
  ${(0, HoverStyles_1.getHoverStyles)(['angle', 'blur', 'opacity'], hoverParams)}
62
87
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cntrl-site/sdk-nextjs",
3
- "version": "0.30.1",
3
+ "version": "0.30.3",
4
4
  "description": "SDK for Next.js",
5
5
  "main": "lib/index.js",
6
6
  "types": "src/index.ts",
@@ -23,7 +23,7 @@
23
23
  "dependencies": {
24
24
  "@cntrl-site/color": "^1.0.0",
25
25
  "@cntrl-site/effects": "^1.2.0",
26
- "@cntrl-site/sdk": "^1.12.0",
26
+ "@cntrl-site/sdk": "^1.12.2",
27
27
  "@types/vimeo__player": "^2.18.0",
28
28
  "@vimeo/player": "^2.20.1",
29
29
  "html-react-parser": "^3.0.1",
@@ -1,5 +1,5 @@
1
1
  import { ArticleItemType, getLayoutStyles, CodeEmbedItem as TCodeEmbedItem, AreaAnchor } from '@cntrl-site/sdk';
2
- import { FC, useId, useState } from 'react';
2
+ import { FC, useEffect, useId, useState } from 'react';
3
3
  import { useCntrlContext } from '../../provider/useCntrlContext';
4
4
  import { ItemProps } from '../Item';
5
5
  import { getHoverStyles, getTransitions } from '../../utils/HoverStyles/HoverStyles';
@@ -32,29 +32,64 @@ export const CodeEmbedItem: FC<ItemProps<TCodeEmbedItem>> = ({ item, sectionId,
32
32
  const pos = stylesMap[anchor];
33
33
  const layoutValues: Record<string, any>[] = [item.area, item.layoutParams, item.state.hover];
34
34
 
35
+ useEffect(() => {
36
+ if (!ref) return;
37
+ const scripts = ref.querySelectorAll('script');
38
+ for (const script of scripts) {
39
+ const newScript = document.createElement('script');
40
+ for (const attr of script.getAttributeNames()) {
41
+ newScript.setAttribute(attr, script.getAttribute(attr)!);
42
+ }
43
+ newScript.textContent = script.textContent;
44
+ script.parentNode!.removeChild(script);
45
+ ref.appendChild(newScript);
46
+ }
47
+ }, [item.commonParams.html])
48
+
49
+ useEffect(() => {
50
+ if (!ref) return;
51
+ const iframe: HTMLIFrameElement | null = ref.querySelector(`[data-embed="${item.id}"]`);
52
+ if (!iframe) return;
53
+ iframe.srcdoc = item.commonParams.html;
54
+ }, [item.commonParams.html, item.commonParams.iframe, ref]);
55
+
35
56
  return (
36
57
  <LinkWrapper url={item.link?.url} target={item.link?.target}>
37
58
  <div
38
59
  className={`embed-wrapper-${item.id}`}
39
- style={{ opacity: `${opacity}`, transform: `rotate(${angle}deg)`, filter: `blur(${blur * 100}vw)`, ...pos}}
60
+ style={{ opacity: `${opacity}`, transform: `rotate(${angle}deg)`, filter: `blur(${blur * 100}vw)` }}
40
61
  ref={setRef}
41
62
  >
42
- <div className="embed" dangerouslySetInnerHTML={{ __html: html }}></div>
63
+ {item.commonParams.iframe ? (
64
+ <iframe
65
+ data-embed={item.id}
66
+ className={`embed-${item.id}`}
67
+ style={{
68
+ ...pos,
69
+ border: 'unset'
70
+ }}
71
+ />
72
+ ) : (
73
+ <div
74
+ className={`embed-${item.id}`}
75
+ style={{ ...pos }}
76
+ dangerouslySetInnerHTML={{ __html: html }}
77
+ />
78
+ )}
43
79
  </div>
44
80
  <JSXStyle id={id}>{`
45
- .embed -wrapper-${item.id} {
81
+ .embed-wrapper-${item.id} {
46
82
  position: absolute;
47
83
  width: 100%;
48
84
  height: 100%;
49
85
  }
50
- .embed {
51
- width: 100%;
52
- height: 100%;
86
+ .embed-${item.id} {
87
+ transform: ${item.commonParams.scale ? 'scale(var(--layout-deviation))' : 'none'};
88
+ transform-origin: top left;
53
89
  z-index: 1;
54
90
  border: none;
55
- overflow: hidden;
56
91
  }
57
- ${getLayoutStyles(layouts, layoutValues, ([area, layoutParams, hoverParams]) => {
92
+ ${getLayoutStyles(layouts, layoutValues, ([area, layoutParams, hoverParams], exemplary) => {
58
93
  return (`
59
94
  .embed-wrapper-${item.id} {
60
95
  opacity: ${layoutParams.opacity};
@@ -62,6 +97,10 @@ export const CodeEmbedItem: FC<ItemProps<TCodeEmbedItem>> = ({ item, sectionId,
62
97
  filter: ${layoutParams.blur !== 0 ? `blur(${layoutParams.blur * 100}vw)` : 'unset'};
63
98
  transition: ${getTransitions<ArticleItemType.CodeEmbed>(['angle', 'blur', 'opacity'], hoverParams)};
64
99
  }
100
+ .embed-${item.id} {
101
+ width: ${item.commonParams.scale ? `${area.width * exemplary}px` : '100%'};
102
+ height: ${item.commonParams.scale ? `${area.height * exemplary}px` : '100%'};
103
+ }
65
104
  .embed-wrapper-${item.id}:hover {
66
105
  ${getHoverStyles<ArticleItemType.CodeEmbed>(['angle', 'blur', 'opacity'], hoverParams)}
67
106
  }
Binary file
Binary file