@cntrl-site/sdk-nextjs 0.2.1 → 0.2.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.
- package/.idea/inspectionProfiles/Project_Default.xml +15 -0
- package/lib/components/Item.js +4 -1
- package/lib/components/items/CustomItem.js +12 -0
- package/lib/components/items/VimeoEmbed.js +39 -5
- package/lib/index.js +5 -1
- package/lib/provider/CntrlContext.js +6 -0
- package/lib/provider/CntrlProvider.js +10 -0
- package/lib/provider/CntrlSdkContext.js +9 -0
- package/lib/provider/CustomItemRegistry.js +16 -0
- package/lib/provider/CustomItemTypes.js +2 -0
- package/lib/provider/defaultContext.js +7 -0
- package/lib/provider/useCntrlContext.js +10 -0
- package/package.json +2 -2
- package/src/components/Item.tsx +5 -2
- package/src/components/items/CustomItem.tsx +11 -0
- package/src/components/items/VimeoEmbed.tsx +55 -6
- package/src/index.ts +7 -0
- package/src/provider/CntrlContext.ts +5 -0
- package/src/provider/CntrlProvider.tsx +11 -0
- package/src/provider/CntrlSdkContext.ts +7 -0
- package/src/provider/CustomItemRegistry.ts +14 -0
- package/src/provider/CustomItemTypes.ts +3 -0
- package/src/provider/defaultContext.ts +6 -0
- package/src/provider/useCntrlContext.ts +8 -0
- package/.idea/codeStyles/codeStyleConfig.xml +0 -5
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
<component name="InspectionProjectProfileManager">
|
|
2
|
+
<profile version="1.0">
|
|
3
|
+
<option name="myName" value="Project Default" />
|
|
4
|
+
<inspection_tool class="HtmlUnknownAttribute" enabled="true" level="WARNING" enabled_by_default="true">
|
|
5
|
+
<option name="myValues">
|
|
6
|
+
<value>
|
|
7
|
+
<list size="1">
|
|
8
|
+
<item index="0" class="java.lang.String" itemvalue="jsx" />
|
|
9
|
+
</list>
|
|
10
|
+
</value>
|
|
11
|
+
</option>
|
|
12
|
+
<option name="myCustomValuesEnabled" value="true" />
|
|
13
|
+
</inspection_tool>
|
|
14
|
+
</profile>
|
|
15
|
+
</component>
|
package/lib/components/Item.js
CHANGED
|
@@ -8,12 +8,15 @@ const ImageItem_1 = require("./items/ImageItem");
|
|
|
8
8
|
const VideoItem_1 = require("./items/VideoItem");
|
|
9
9
|
const RichTextItem_1 = require("./items/RichTextItem");
|
|
10
10
|
const VimeoEmbed_1 = require("./items/VimeoEmbed");
|
|
11
|
+
const CustomItem_1 = require("./items/CustomItem");
|
|
11
12
|
const itemsMap = {
|
|
12
13
|
[sdk_1.ArticleItemType.Rectangle]: RectangleItem_1.RectangleItem,
|
|
13
14
|
[sdk_1.ArticleItemType.Image]: ImageItem_1.ImageItem,
|
|
14
15
|
[sdk_1.ArticleItemType.Video]: VideoItem_1.VideoItem,
|
|
15
16
|
[sdk_1.ArticleItemType.RichText]: RichTextItem_1.RichTextItem,
|
|
16
|
-
[sdk_1.ArticleItemType.
|
|
17
|
+
[sdk_1.ArticleItemType.YoutubeEmbed]: () => null,
|
|
18
|
+
[sdk_1.ArticleItemType.VimeoEmbed]: VimeoEmbed_1.VimeoEmbedItem,
|
|
19
|
+
[sdk_1.ArticleItemType.Custom]: CustomItem_1.CustomItem
|
|
17
20
|
};
|
|
18
21
|
const noop = () => null;
|
|
19
22
|
const Item = ({ item, layouts }) => {
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.CustomItem = void 0;
|
|
4
|
+
const useCntrlContext_1 = require("../../provider/useCntrlContext");
|
|
5
|
+
const CustomItem = ({ item }) => {
|
|
6
|
+
const sdk = (0, useCntrlContext_1.useCntrlContext)();
|
|
7
|
+
const component = sdk.customItems.get(item.commonParams.name);
|
|
8
|
+
if (!component)
|
|
9
|
+
return null;
|
|
10
|
+
return component({});
|
|
11
|
+
};
|
|
12
|
+
exports.CustomItem = CustomItem;
|
|
@@ -1,8 +1,42 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.VimeoEmbedItem = void 0;
|
|
4
4
|
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
5
|
-
const
|
|
6
|
-
|
|
7
|
-
(
|
|
8
|
-
|
|
5
|
+
const LinkWrapper_1 = require("../LinkWrapper");
|
|
6
|
+
const sdk_1 = require("@cntrl-site/sdk");
|
|
7
|
+
const VimeoEmbedItem = ({ item, layouts }) => {
|
|
8
|
+
const { autoplay, controls, loop, muted, pictureInPicture, url } = item.commonParams;
|
|
9
|
+
const getValidVimeoUrl = (url) => {
|
|
10
|
+
const validURL = new URL(url);
|
|
11
|
+
validURL.searchParams.append('autoplay', String(autoplay));
|
|
12
|
+
validURL.searchParams.append('controls', String(controls));
|
|
13
|
+
validURL.searchParams.append('muted', String(muted));
|
|
14
|
+
validURL.searchParams.append('loop', String(loop));
|
|
15
|
+
validURL.searchParams.append('pip', String(pictureInPicture));
|
|
16
|
+
validURL.searchParams.append('title', '0');
|
|
17
|
+
validURL.searchParams.append('byline', '0');
|
|
18
|
+
validURL.searchParams.append('portrait', '0');
|
|
19
|
+
return validURL.href;
|
|
20
|
+
};
|
|
21
|
+
const validUrl = getValidVimeoUrl(url);
|
|
22
|
+
return ((0, jsx_runtime_1.jsxs)(LinkWrapper_1.LinkWrapper, { url: item.link?.url, children: [(0, jsx_runtime_1.jsx)("div", { className: `embed-video-wrapper-${item.id}`, children: (0, jsx_runtime_1.jsx)("iframe", { className: "embedVideo", src: validUrl || '', allow: "autoplay; fullscreen; picture-in-picture;", allowFullScreen: true }) }), (0, jsx_runtime_1.jsx)("style", { jsx: true, children: `
|
|
23
|
+
${(0, sdk_1.getLayoutStyles)(layouts, [item.layoutParams], ([{ radius }]) => (`
|
|
24
|
+
.embed-video-wrapper-${item.id} {
|
|
25
|
+
position: absolute;
|
|
26
|
+
overflow: hidden;
|
|
27
|
+
width: 100%;
|
|
28
|
+
height: 100%;
|
|
29
|
+
top: 50%;
|
|
30
|
+
left: 50%;
|
|
31
|
+
transform: translate(-50%, -50%);
|
|
32
|
+
border-radius: ${radius * 100}vw;
|
|
33
|
+
}`))}
|
|
34
|
+
.embedVideo {
|
|
35
|
+
width: 100%;
|
|
36
|
+
height: 100%;
|
|
37
|
+
z-index: 1;
|
|
38
|
+
border: none;
|
|
39
|
+
}
|
|
40
|
+
` })] }));
|
|
41
|
+
};
|
|
42
|
+
exports.VimeoEmbedItem = VimeoEmbedItem;
|
package/lib/index.js
CHANGED
|
@@ -14,8 +14,11 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
14
14
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
15
|
};
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
exports.LayoutStyle = exports.VideoItem = exports.RichTextItem = exports.RectangleItem = exports.ImageItem = exports.Item = exports.Section = exports.Article = exports.Page = exports.RichTextConverter = void 0;
|
|
17
|
+
exports.CustomItems = exports.LayoutStyle = exports.VideoItem = exports.RichTextItem = exports.RectangleItem = exports.ImageItem = exports.Item = exports.Section = exports.Article = exports.Page = exports.RichTextConverter = exports.CntrlProvider = void 0;
|
|
18
|
+
const defaultContext_1 = require("./provider/defaultContext");
|
|
18
19
|
__exportStar(require("@cntrl-site/sdk"), exports);
|
|
20
|
+
var CntrlProvider_1 = require("./provider/CntrlProvider");
|
|
21
|
+
Object.defineProperty(exports, "CntrlProvider", { enumerable: true, get: function () { return CntrlProvider_1.CntrlProvider; } });
|
|
19
22
|
var RichTextConverter_1 = require("./utils/RichTextConverter");
|
|
20
23
|
Object.defineProperty(exports, "RichTextConverter", { enumerable: true, get: function () { return RichTextConverter_1.RichTextConverter; } });
|
|
21
24
|
var Page_1 = require("./components/Page");
|
|
@@ -36,3 +39,4 @@ var VideoItem_1 = require("./components/items/VideoItem");
|
|
|
36
39
|
Object.defineProperty(exports, "VideoItem", { enumerable: true, get: function () { return VideoItem_1.VideoItem; } });
|
|
37
40
|
var LayoutStyle_1 = require("./components/LayoutStyle");
|
|
38
41
|
Object.defineProperty(exports, "LayoutStyle", { enumerable: true, get: function () { return LayoutStyle_1.LayoutStyle; } });
|
|
42
|
+
exports.CustomItems = defaultContext_1.cntrlSdkContext.customItems;
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.CntrlContext = void 0;
|
|
4
|
+
const react_1 = require("react");
|
|
5
|
+
const defaultContext_1 = require("./defaultContext");
|
|
6
|
+
exports.CntrlContext = (0, react_1.createContext)(defaultContext_1.cntrlSdkContext);
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.CntrlProvider = void 0;
|
|
4
|
+
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
5
|
+
const CntrlContext_1 = require("./CntrlContext");
|
|
6
|
+
const defaultContext_1 = require("./defaultContext");
|
|
7
|
+
const CntrlProvider = ({ children }) => {
|
|
8
|
+
return ((0, jsx_runtime_1.jsx)(CntrlContext_1.CntrlContext.Provider, { value: defaultContext_1.cntrlSdkContext, children: children }));
|
|
9
|
+
};
|
|
10
|
+
exports.CntrlProvider = CntrlProvider;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.CustomItemRegistry = void 0;
|
|
4
|
+
class CustomItemRegistry {
|
|
5
|
+
constructor() {
|
|
6
|
+
this.definitions = new Map();
|
|
7
|
+
}
|
|
8
|
+
define(type, component) {
|
|
9
|
+
this.definitions.set(type, component);
|
|
10
|
+
return this;
|
|
11
|
+
}
|
|
12
|
+
get(type) {
|
|
13
|
+
return this.definitions.get(type);
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
exports.CustomItemRegistry = CustomItemRegistry;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.cntrlSdkContext = void 0;
|
|
4
|
+
const CntrlSdkContext_1 = require("./CntrlSdkContext");
|
|
5
|
+
const CustomItemRegistry_1 = require("./CustomItemRegistry");
|
|
6
|
+
const customItems = new CustomItemRegistry_1.CustomItemRegistry();
|
|
7
|
+
exports.cntrlSdkContext = new CntrlSdkContext_1.CntrlSdkContext(customItems);
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.useCntrlContext = void 0;
|
|
4
|
+
const react_1 = require("react");
|
|
5
|
+
const CntrlContext_1 = require("./CntrlContext");
|
|
6
|
+
function useCntrlContext() {
|
|
7
|
+
const context = (0, react_1.useContext)(CntrlContext_1.CntrlContext);
|
|
8
|
+
return context;
|
|
9
|
+
}
|
|
10
|
+
exports.useCntrlContext = useCntrlContext;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cntrl-site/sdk-nextjs",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.3",
|
|
4
4
|
"description": "SDK for Next.js",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"types": "src/index.js",
|
|
@@ -21,7 +21,7 @@
|
|
|
21
21
|
},
|
|
22
22
|
"homepage": "https://github.com/cntrl-site/sdk-nextjs#readme",
|
|
23
23
|
"dependencies": {
|
|
24
|
-
"@cntrl-site/sdk": "^0.2.
|
|
24
|
+
"@cntrl-site/sdk": "^0.2.11",
|
|
25
25
|
"html-react-parser": "^3.0.1",
|
|
26
26
|
"styled-jsx": "^5.0.2"
|
|
27
27
|
},
|
package/src/components/Item.tsx
CHANGED
|
@@ -10,7 +10,8 @@ import { RectangleItem } from './items/RectangleItem';
|
|
|
10
10
|
import { ImageItem } from './items/ImageItem';
|
|
11
11
|
import { VideoItem } from './items/VideoItem';
|
|
12
12
|
import { RichTextItem } from './items/RichTextItem';
|
|
13
|
-
import {
|
|
13
|
+
import { VimeoEmbedItem } from './items/VimeoEmbed';
|
|
14
|
+
import { CustomItem } from './items/CustomItem';
|
|
14
15
|
|
|
15
16
|
export interface ItemProps<I extends TArticleItemAny> {
|
|
16
17
|
layouts: TLayout[];
|
|
@@ -22,7 +23,9 @@ const itemsMap: Record<ArticleItemType, ComponentType<ItemProps<any>>> = {
|
|
|
22
23
|
[ArticleItemType.Image]: ImageItem,
|
|
23
24
|
[ArticleItemType.Video]: VideoItem,
|
|
24
25
|
[ArticleItemType.RichText]: RichTextItem,
|
|
25
|
-
[ArticleItemType.
|
|
26
|
+
[ArticleItemType.YoutubeEmbed]: () => null,
|
|
27
|
+
[ArticleItemType.VimeoEmbed]: VimeoEmbedItem,
|
|
28
|
+
[ArticleItemType.Custom]: CustomItem
|
|
26
29
|
};
|
|
27
30
|
|
|
28
31
|
const noop = () => null;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { TCustomItem } from '@cntrl-site/sdk';
|
|
2
|
+
import { FC } from 'react';
|
|
3
|
+
import { useCntrlContext } from '../../provider/useCntrlContext';
|
|
4
|
+
import { ItemProps } from '../Item';
|
|
5
|
+
|
|
6
|
+
export const CustomItem: FC<ItemProps<TCustomItem>> = ({ item }) => {
|
|
7
|
+
const sdk = useCntrlContext();
|
|
8
|
+
const component = sdk.customItems.get(item.commonParams.name);
|
|
9
|
+
if (!component) return null;
|
|
10
|
+
return component({});
|
|
11
|
+
};
|
|
@@ -1,9 +1,58 @@
|
|
|
1
1
|
import { FC } from 'react';
|
|
2
2
|
import { ItemProps } from '../Item';
|
|
3
|
-
import {
|
|
3
|
+
import { TVimeoEmbedItem } from '@cntrl-site/core';
|
|
4
|
+
import { LinkWrapper } from '../LinkWrapper';
|
|
5
|
+
import { getLayoutStyles } from '@cntrl-site/sdk';
|
|
4
6
|
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
)
|
|
7
|
+
|
|
8
|
+
export const VimeoEmbedItem: FC<ItemProps<TVimeoEmbedItem>> = ({ item, layouts }) => {
|
|
9
|
+
const { autoplay, controls, loop, muted, pictureInPicture, url } = item.commonParams;
|
|
10
|
+
const getValidVimeoUrl = (url: string): string => {
|
|
11
|
+
const validURL = new URL(url);
|
|
12
|
+
validURL.searchParams.append('autoplay', String(autoplay));
|
|
13
|
+
validURL.searchParams.append('controls', String(controls));
|
|
14
|
+
validURL.searchParams.append('muted', String(muted));
|
|
15
|
+
validURL.searchParams.append('loop', String(loop));
|
|
16
|
+
validURL.searchParams.append('pip', String(pictureInPicture));
|
|
17
|
+
validURL.searchParams.append('title', '0');
|
|
18
|
+
validURL.searchParams.append('byline', '0');
|
|
19
|
+
validURL.searchParams.append('portrait', '0');
|
|
20
|
+
|
|
21
|
+
return validURL.href;
|
|
22
|
+
}
|
|
23
|
+
const validUrl = getValidVimeoUrl(url);
|
|
24
|
+
|
|
25
|
+
return (
|
|
26
|
+
<LinkWrapper url={item.link?.url}>
|
|
27
|
+
<div className={`embed-video-wrapper-${item.id}`}>
|
|
28
|
+
<iframe
|
|
29
|
+
className="embedVideo"
|
|
30
|
+
src={validUrl || ''}
|
|
31
|
+
allow="autoplay; fullscreen; picture-in-picture;"
|
|
32
|
+
allowFullScreen
|
|
33
|
+
/>
|
|
34
|
+
</div>
|
|
35
|
+
<style jsx>{`
|
|
36
|
+
${getLayoutStyles(layouts, [item.layoutParams], ([{ radius }]) => (`
|
|
37
|
+
.embed-video-wrapper-${item.id} {
|
|
38
|
+
position: absolute;
|
|
39
|
+
overflow: hidden;
|
|
40
|
+
width: 100%;
|
|
41
|
+
height: 100%;
|
|
42
|
+
top: 50%;
|
|
43
|
+
left: 50%;
|
|
44
|
+
transform: translate(-50%, -50%);
|
|
45
|
+
border-radius: ${radius * 100}vw;
|
|
46
|
+
}`
|
|
47
|
+
))
|
|
48
|
+
}
|
|
49
|
+
.embedVideo {
|
|
50
|
+
width: 100%;
|
|
51
|
+
height: 100%;
|
|
52
|
+
z-index: 1;
|
|
53
|
+
border: none;
|
|
54
|
+
}
|
|
55
|
+
`}</style>
|
|
56
|
+
</LinkWrapper>
|
|
57
|
+
)
|
|
58
|
+
};
|
package/src/index.ts
CHANGED
|
@@ -1,4 +1,7 @@
|
|
|
1
|
+
import { cntrlSdkContext } from './provider/defaultContext';
|
|
2
|
+
|
|
1
3
|
export * from '@cntrl-site/sdk';
|
|
4
|
+
export { CntrlProvider } from './provider/CntrlProvider';
|
|
2
5
|
|
|
3
6
|
export { RichTextConverter } from './utils/RichTextConverter';
|
|
4
7
|
export { Page } from './components/Page';
|
|
@@ -10,3 +13,7 @@ export { RectangleItem } from './components/items/RectangleItem';
|
|
|
10
13
|
export { RichTextItem } from './components/items/RichTextItem';
|
|
11
14
|
export { VideoItem } from './components/items/VideoItem';
|
|
12
15
|
export { LayoutStyle } from './components/LayoutStyle';
|
|
16
|
+
|
|
17
|
+
// custom items
|
|
18
|
+
export { CustomItemComponent } from './provider/CustomItemTypes';
|
|
19
|
+
export const CustomItems = cntrlSdkContext.customItems;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { FC, PropsWithChildren } from 'react';
|
|
2
|
+
import { CntrlContext } from './CntrlContext';
|
|
3
|
+
import { cntrlSdkContext } from './defaultContext';
|
|
4
|
+
|
|
5
|
+
export const CntrlProvider: FC<PropsWithChildren<{}>> = ({ children }) => {
|
|
6
|
+
return (
|
|
7
|
+
<CntrlContext.Provider value={cntrlSdkContext}>
|
|
8
|
+
{children}
|
|
9
|
+
</CntrlContext.Provider>
|
|
10
|
+
);
|
|
11
|
+
};
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { CustomItemComponent } from './CustomItemTypes';
|
|
2
|
+
|
|
3
|
+
export class CustomItemRegistry {
|
|
4
|
+
private definitions: Map<string, CustomItemComponent<string>> = new Map();
|
|
5
|
+
|
|
6
|
+
define<T extends string>(type: T, component: CustomItemComponent<T>): this {
|
|
7
|
+
this.definitions.set(type, component);
|
|
8
|
+
return this;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
get(type: string): CustomItemComponent<string> | undefined {
|
|
12
|
+
return this.definitions.get(type);
|
|
13
|
+
}
|
|
14
|
+
}
|