@cntrl-site/sdk-nextjs 1.1.5-alpha.2 → 1.1.5

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,18 @@
1
+ import antfu from '@antfu/eslint-config';
2
+
3
+ export default antfu(
4
+ {
5
+ ignores: [],
6
+ },
7
+ {
8
+ rules: {
9
+ 'import/order': 'off',
10
+ 'style/semi': 'off',
11
+ 'antfu/if-newline': 'off',
12
+ 'style/comma-dangle': 'off',
13
+ 'style/member-delimiter-style': 'off',
14
+ 'semi': ['error', 'always'],
15
+ 'no-alert': 'off',
16
+ },
17
+ },
18
+ );
@@ -14,16 +14,16 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
14
14
  Object.defineProperty(exports, "__esModule", { value: true });
15
15
  exports.VimeoEmbedItem = void 0;
16
16
  const jsx_runtime_1 = require("react/jsx-runtime");
17
- const react_1 = require("react");
17
+ const sdk_1 = require("@cntrl-site/sdk");
18
18
  const player_1 = __importDefault(require("@vimeo/player"));
19
+ const react_1 = require("react");
19
20
  const style_1 = __importDefault(require("styled-jsx/style"));
20
- const LinkWrapper_1 = require("../LinkWrapper");
21
- const useEmbedVideoItem_1 = require("./useEmbedVideoItem");
22
- const useItemAngle_1 = require("../useItemAngle");
23
- const sdk_1 = require("@cntrl-site/sdk");
24
- const useCntrlContext_1 = require("../../provider/useCntrlContext");
25
21
  const useRegisterResize_1 = require("../../common/useRegisterResize");
22
+ const useCntrlContext_1 = require("../../provider/useCntrlContext");
26
23
  const getStyleFromItemStateAndParams_1 = require("../../utils/getStyleFromItemStateAndParams");
24
+ const LinkWrapper_1 = require("../LinkWrapper");
25
+ const useItemAngle_1 = require("../useItemAngle");
26
+ const useEmbedVideoItem_1 = require("./useEmbedVideoItem");
27
27
  const VimeoEmbedItem = ({ item, sectionId, onResize, interactionCtrl, onVisibilityChange }) => {
28
28
  var _a, _b, _c, _d, _e, _f, _g, _h, _j;
29
29
  const id = (0, react_1.useId)();
@@ -48,7 +48,7 @@ const VimeoEmbedItem = ({ item, sectionId, onResize, interactionCtrl, onVisibili
48
48
  const validURL = new URL(url);
49
49
  validURL.searchParams.append('controls', String(controls));
50
50
  validURL.searchParams.append('autoplay', String(play === 'auto'));
51
- validURL.searchParams.append('muted', String(play !== 'on-click' ? true : muted));
51
+ validURL.searchParams.append('muted', String(muted));
52
52
  validURL.searchParams.append('loop', String(loop));
53
53
  validURL.searchParams.append('pip', String(pictureInPicture));
54
54
  validURL.searchParams.append('title', '0');
@@ -69,6 +69,9 @@ const VimeoEmbedItem = ({ item, sectionId, onResize, interactionCtrl, onVisibili
69
69
  setIsCoverVisible(true);
70
70
  }
71
71
  });
72
+ vimeoPlayer.on('ended', () => {
73
+ setIsCoverVisible(true);
74
+ });
72
75
  }, [vimeoPlayer, imgRef]);
73
76
  const handleClick = () => __awaiter(void 0, void 0, void 0, function* () {
74
77
  if (!vimeoPlayer)
@@ -109,13 +112,13 @@ const VimeoEmbedItem = ({ item, sectionId, onResize, interactionCtrl, onVisibili
109
112
  width: '100%',
110
113
  top: '0',
111
114
  left: '0'
112
- }, alt: "Cover img" })), (!item.commonParams.controls && play === 'on-click') && ((0, jsx_runtime_1.jsx)("div", { onClick: handleClick, style: {
115
+ }, alt: "Cover img" })), (!item.commonParams.controls && (play === 'on-click' || play === 'auto')) && ((0, jsx_runtime_1.jsx)("div", { onClick: handleClick, style: {
113
116
  position: 'absolute',
114
117
  height: '100%',
115
118
  width: '100%',
116
119
  top: '0',
117
120
  left: '0'
118
- } })), (0, jsx_runtime_1.jsx)("iframe", { ref: setIframeRef, className: `embed-video`, src: validUrl || '', allow: "autoplay; fullscreen; picture-in-picture;", allowFullScreen: true, style: Object.assign(Object.assign({}, (radius !== undefined ? { borderRadius: `${radius * 100}vw` } : {})), { transition: (_j = frameStateParams === null || frameStateParams === void 0 ? void 0 : frameStateParams.transition) !== null && _j !== void 0 ? _j : 'none' }) })] }), (0, jsx_runtime_1.jsx)(style_1.default, { id: id, children: `
121
+ } })), (0, jsx_runtime_1.jsx)("iframe", { ref: setIframeRef, className: "embed-video", src: validUrl || '', allow: "autoplay; fullscreen; picture-in-picture;", allowFullScreen: true, style: Object.assign(Object.assign({}, (radius !== undefined ? { borderRadius: `${radius * 100}vw` } : {})), { transition: (_j = frameStateParams === null || frameStateParams === void 0 ? void 0 : frameStateParams.transition) !== null && _j !== void 0 ? _j : 'none' }) })] }), (0, jsx_runtime_1.jsx)(style_1.default, { id: id, children: `
119
122
  .embed-video-wrapper-${item.id} {
120
123
  position: absolute;
121
124
  width: 100%;
@@ -14,12 +14,10 @@ Object.defineProperty(exports, "__esModule", { value: true });
14
14
  exports.InteractionsRegistry = void 0;
15
15
  const sdk_1 = require("@cntrl-site/sdk");
16
16
  const Item_1 = require("../components/Item");
17
- const AudioPlayer_1 = require("./AudioPlayer");
18
17
  class InteractionsRegistry {
19
18
  constructor(article, layoutId) {
20
19
  this.layoutId = layoutId;
21
20
  this.ctrls = new Map();
22
- this.audioPlayer = new AudioPlayer_1.AudioPlayer();
23
21
  const { interactions } = article;
24
22
  this.items = this.unpackItems(article);
25
23
  const activeStatesIds = interactions.reduce((map, inter) => {
@@ -141,9 +139,6 @@ class InteractionsRegistry {
141
139
  for (const trigger of interaction.triggers) {
142
140
  itemsToNotify.add(trigger.itemId);
143
141
  }
144
- if (triggerType === 'click') {
145
- this.playClickSound();
146
- }
147
142
  this.notifyItemCtrlsChange(Array.from(itemsToNotify));
148
143
  this.notifyTransitionStartForItems(transitioningItems, activeStateId);
149
144
  }
@@ -240,8 +235,5 @@ class InteractionsRegistry {
240
235
  }
241
236
  return stages;
242
237
  }
243
- playClickSound() {
244
- this.audioPlayer.play();
245
- }
246
238
  }
247
239
  exports.InteractionsRegistry = InteractionsRegistry;
package/package.json CHANGED
@@ -1,7 +1,17 @@
1
1
  {
2
2
  "name": "@cntrl-site/sdk-nextjs",
3
- "version": "1.1.5-alpha.2",
3
+ "version": "1.1.5",
4
4
  "description": "SDK for Next.js",
5
+ "author": "arsen@momdesign.nyc",
6
+ "license": "MIT",
7
+ "homepage": "https://github.com/cntrl-site/sdk-nextjs#readme",
8
+ "repository": {
9
+ "type": "git",
10
+ "url": "git+https://github.com/cntrl-site/sdk-nextjs.git"
11
+ },
12
+ "bugs": {
13
+ "url": "https://github.com/cntrl-site/sdk-nextjs/issues"
14
+ },
5
15
  "main": "lib/index.js",
6
16
  "types": "src/index.ts",
7
17
  "scripts": {
@@ -10,35 +20,24 @@
10
20
  "build": "tsc --project tsconfig.build.json",
11
21
  "prepublishOnly": "NODE_ENV=production npm run build"
12
22
  },
13
- "repository": {
14
- "type": "git",
15
- "url": "git+https://github.com/cntrl-site/sdk-nextjs.git"
16
- },
17
- "author": "arsen@momdesign.nyc",
18
- "license": "MIT",
19
- "bugs": {
20
- "url": "https://github.com/cntrl-site/sdk-nextjs/issues"
23
+ "peerDependencies": {
24
+ "@types/lodash.isequal": "^4.5.6",
25
+ "lodash.isequal": "^4.5.0",
26
+ "next": "^14.2.3",
27
+ "react": "^18.3.1",
28
+ "react-dom": "^18.3.1"
21
29
  },
22
- "homepage": "https://github.com/cntrl-site/sdk-nextjs#readme",
23
30
  "dependencies": {
31
+ "@antfu/eslint-config": "^3.8.0",
24
32
  "@cntrl-site/color": "^1.0.0",
25
33
  "@cntrl-site/effects": "^1.2.0",
26
34
  "@cntrl-site/sdk": "^1.13.0",
27
- "@types/howler": "^2.2.12",
28
35
  "@types/vimeo__player": "^2.18.0",
29
36
  "@vimeo/player": "^2.20.1",
30
- "howler": "^2.2.4",
31
37
  "html-react-parser": "^3.0.1",
32
38
  "resize-observer-polyfill": "^1.5.1",
33
39
  "styled-jsx": "^5.0.2"
34
40
  },
35
- "peerDependencies": {
36
- "@types/lodash.isequal": "^4.5.6",
37
- "lodash.isequal": "^4.5.0",
38
- "next": "^14.2.3",
39
- "react": "^18.3.1",
40
- "react-dom": "^18.3.1"
41
- },
42
41
  "devDependencies": {
43
42
  "@testing-library/jest-dom": "^6.4.8",
44
43
  "@testing-library/react": "^16.0.0",
@@ -1,14 +1,16 @@
1
- import { FC, useEffect, useId, useMemo, useState } from 'react';
1
+ import type { VimeoEmbedItem as TVimeoEmbedItem } from '@cntrl-site/sdk';
2
+ import type { FC } from 'react';
3
+ import type { ItemProps } from '../Item';
4
+ import { getLayoutStyles } from '@cntrl-site/sdk';
2
5
  import Player from '@vimeo/player';
6
+ import { useEffect, useId, useMemo, useState } from 'react';
3
7
  import JSXStyle from 'styled-jsx/style';
4
- import { ItemProps } from '../Item';
5
- import { LinkWrapper } from '../LinkWrapper';
6
- import { useEmbedVideoItem } from './useEmbedVideoItem';
7
- import { useItemAngle } from '../useItemAngle';
8
- import { getLayoutStyles, VimeoEmbedItem as TVimeoEmbedItem } from '@cntrl-site/sdk';
8
+ import { useRegisterResize } from '../../common/useRegisterResize';
9
9
  import { useCntrlContext } from '../../provider/useCntrlContext';
10
- import { useRegisterResize } from "../../common/useRegisterResize";
11
10
  import { getStyleFromItemStateAndParams } from '../../utils/getStyleFromItemStateAndParams';
11
+ import { LinkWrapper } from '../LinkWrapper';
12
+ import { useItemAngle } from '../useItemAngle';
13
+ import { useEmbedVideoItem } from './useEmbedVideoItem';
12
14
 
13
15
  export const VimeoEmbedItem: FC<ItemProps<TVimeoEmbedItem>> = ({ item, sectionId, onResize, interactionCtrl, onVisibilityChange }) => {
14
16
  const id = useId();
@@ -37,7 +39,7 @@ export const VimeoEmbedItem: FC<ItemProps<TVimeoEmbedItem>> = ({ item, sectionId
37
39
  const validURL = new URL(url);
38
40
  validURL.searchParams.append('controls', String(controls));
39
41
  validURL.searchParams.append('autoplay', String(play === 'auto'));
40
- validURL.searchParams.append('muted', String(play !== 'on-click' ? true : muted));
42
+ validURL.searchParams.append('muted', String(muted));
41
43
  validURL.searchParams.append('loop', String(loop));
42
44
  validURL.searchParams.append('pip', String(pictureInPicture));
43
45
  validURL.searchParams.append('title', '0');
@@ -46,7 +48,7 @@ export const VimeoEmbedItem: FC<ItemProps<TVimeoEmbedItem>> = ({ item, sectionId
46
48
  validURL.searchParams.append('autopause', 'false');
47
49
 
48
50
  return validURL.href;
49
- }
51
+ };
50
52
  const validUrl = getValidVimeoUrl(url);
51
53
 
52
54
  useEffect(() => {
@@ -59,6 +61,9 @@ export const VimeoEmbedItem: FC<ItemProps<TVimeoEmbedItem>> = ({ item, sectionId
59
61
  setIsCoverVisible(true);
60
62
  }
61
63
  });
64
+ vimeoPlayer.on('ended', () => {
65
+ setIsCoverVisible(true);
66
+ });
62
67
  }, [vimeoPlayer, imgRef]);
63
68
 
64
69
  const handleClick = async () => {
@@ -67,7 +72,8 @@ export const VimeoEmbedItem: FC<ItemProps<TVimeoEmbedItem>> = ({ item, sectionId
67
72
  if (isPaused) {
68
73
  vimeoPlayer.play();
69
74
  setIsCoverVisible(false);
70
- } else {
75
+ }
76
+ else {
71
77
  vimeoPlayer.pause();
72
78
  }
73
79
  };
@@ -98,7 +104,7 @@ export const VimeoEmbedItem: FC<ItemProps<TVimeoEmbedItem>> = ({ item, sectionId
98
104
  if (!vimeoPlayer || play !== 'on-hover') return;
99
105
  vimeoPlayer.play();
100
106
  }}
101
- onMouseLeave={() =>{
107
+ onMouseLeave={() => {
102
108
  if (!vimeoPlayer || play !== 'on-hover') return;
103
109
  vimeoPlayer.pause();
104
110
  }}
@@ -122,7 +128,7 @@ export const VimeoEmbedItem: FC<ItemProps<TVimeoEmbedItem>> = ({ item, sectionId
122
128
  />
123
129
  )}
124
130
  {/* ↓ This is necessary to track clicks on an iframe. */}
125
- {(!item.commonParams.controls && play === 'on-click') && (
131
+ {(!item.commonParams.controls && (play === 'on-click' || play === 'auto')) && (
126
132
  <div
127
133
  onClick={handleClick}
128
134
  style={{
@@ -136,17 +142,18 @@ export const VimeoEmbedItem: FC<ItemProps<TVimeoEmbedItem>> = ({ item, sectionId
136
142
  )}
137
143
  <iframe
138
144
  ref={setIframeRef}
139
- className={`embed-video`}
145
+ className="embed-video"
140
146
  src={validUrl || ''}
141
147
  allow="autoplay; fullscreen; picture-in-picture;"
142
148
  allowFullScreen
143
149
  style={{
144
- ...(radius !== undefined ? { borderRadius: `${radius * 100}vw` } : {}),
150
+ ...(radius !== undefined ? { borderRadius: `${radius * 100}vw` } : {}),
145
151
  transition: frameStateParams?.transition ?? 'none'
146
152
  }}
147
153
  />
148
154
  </div>
149
- <JSXStyle id={id}>{`
155
+ <JSXStyle id={id}>
156
+ {`
150
157
  .embed-video-wrapper-${item.id} {
151
158
  position: absolute;
152
159
  width: 100%;
@@ -160,7 +167,7 @@ export const VimeoEmbedItem: FC<ItemProps<TVimeoEmbedItem>> = ({ item, sectionId
160
167
  overflow: hidden;
161
168
  }
162
169
  ${getLayoutStyles(layouts, layoutValues, ([area, layoutParams]) => {
163
- return (`
170
+ return (`
164
171
  .embed-video-wrapper-${item.id} {
165
172
  opacity: ${layoutParams.opacity};
166
173
  transform: rotate(${area.angle}deg);
@@ -170,8 +177,9 @@ export const VimeoEmbedItem: FC<ItemProps<TVimeoEmbedItem>> = ({ item, sectionId
170
177
  border-radius: ${layoutParams.radius * 100}vw;
171
178
  }
172
179
  `);
173
- })}
174
- `}</JSXStyle>
180
+ })}
181
+ `}
182
+ </JSXStyle>
175
183
  </LinkWrapper>
176
184
  );
177
185
  };
@@ -7,7 +7,6 @@ import {
7
7
  ItemAny,
8
8
  } from '@cntrl-site/sdk';
9
9
  import { isItemType } from '../components/Item';
10
- import { AudioPlayer } from './AudioPlayer';
11
10
 
12
11
  export class InteractionsRegistry implements InteractionsRegistryPort {
13
12
  private ctrls: Map<ItemId, ItemInteractionCtrl> = new Map();
@@ -17,7 +16,7 @@ export class InteractionsRegistry implements InteractionsRegistryPort {
17
16
  private interactionStateMap: InteractionStateMap;
18
17
  private itemsStages: ItemStages;
19
18
  private activeStateIdInteractionIdMap: Record<StateId, InteractionId>;
20
- private audioPlayer = new AudioPlayer();
19
+
21
20
  constructor(article: Article, private layoutId: string) {
22
21
  const { interactions } = article;
23
22
  this.items = this.unpackItems(article);
@@ -138,9 +137,6 @@ export class InteractionsRegistry implements InteractionsRegistryPort {
138
137
  for (const trigger of interaction.triggers) {
139
138
  itemsToNotify.add(trigger.itemId);
140
139
  }
141
- if (triggerType === 'click') {
142
- this.playClickSound();
143
- }
144
140
  this.notifyItemCtrlsChange(Array.from(itemsToNotify));
145
141
  this.notifyTransitionStartForItems(transitioningItems, activeStateId);
146
142
  }
@@ -238,10 +234,6 @@ export class InteractionsRegistry implements InteractionsRegistryPort {
238
234
  }
239
235
  return stages;
240
236
  }
241
-
242
- private playClickSound() {
243
- this.audioPlayer.play();
244
- }
245
237
  }
246
238
 
247
239
  type ItemStages = (TransitioningStage | ActiveStage)[];
@@ -1,5 +0,0 @@
1
- <component name="ProjectCodeStyleConfiguration">
2
- <state>
3
- <option name="PREFERRED_PROJECT_CODE_STYLE" value="Default" />
4
- </state>
5
- </component>
@@ -1,15 +0,0 @@
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/.idea/modules.xml DELETED
@@ -1,8 +0,0 @@
1
- <?xml version="1.0" encoding="UTF-8"?>
2
- <project version="4">
3
- <component name="ProjectModuleManager">
4
- <modules>
5
- <module fileurl="file://$PROJECT_DIR$/.idea/sdk-nextjs.iml" filepath="$PROJECT_DIR$/.idea/sdk-nextjs.iml" />
6
- </modules>
7
- </component>
8
- </project>
@@ -1,12 +0,0 @@
1
- <?xml version="1.0" encoding="UTF-8"?>
2
- <module type="WEB_MODULE" version="4">
3
- <component name="NewModuleRootManager">
4
- <content url="file://$MODULE_DIR$">
5
- <excludeFolder url="file://$MODULE_DIR$/temp" />
6
- <excludeFolder url="file://$MODULE_DIR$/.tmp" />
7
- <excludeFolder url="file://$MODULE_DIR$/tmp" />
8
- </content>
9
- <orderEntry type="inheritedJdk" />
10
- <orderEntry type="sourceFolder" forTests="false" />
11
- </component>
12
- </module>
package/.idea/vcs.xml DELETED
@@ -1,6 +0,0 @@
1
- <?xml version="1.0" encoding="UTF-8"?>
2
- <project version="4">
3
- <component name="VcsDirectoryMappings">
4
- <mapping directory="$PROJECT_DIR$" vcs="Git" />
5
- </component>
6
- </project>
@@ -1,16 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.AudioPlayer = void 0;
4
- const howler_1 = require("howler");
5
- class AudioPlayer {
6
- constructor() {
7
- this.audio = new howler_1.Howl({
8
- src: ['https://cdn.cntrl.site/client-app-files/hover.b226066e.mp3'],
9
- volume: 1,
10
- });
11
- }
12
- play() {
13
- this.audio.play();
14
- }
15
- }
16
- exports.AudioPlayer = AudioPlayer;
@@ -1,16 +0,0 @@
1
- import { Howl } from 'howler';
2
-
3
- export class AudioPlayer {
4
- private audio: Howl;
5
-
6
- constructor() {
7
- this.audio = new Howl({
8
- src: ['https://cdn.cntrl.site/client-app-files/hover.b226066e.mp3'],
9
- volume: 1,
10
- });
11
- }
12
-
13
- play() {
14
- this.audio.play();
15
- }
16
- }