@quintype/components 3.3.1 → 3.3.2-brightcove.0

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/index.js CHANGED
@@ -12,7 +12,7 @@ var reactRedux = require('react-redux');
12
12
  var wretch = require('wretch');
13
13
  var omit = require('@babel/runtime/helpers/objectWithoutProperties');
14
14
  var propTypes = require('prop-types');
15
- var get = require('lodash/get');
15
+ var get$1 = require('lodash/get');
16
16
  var _defineProperty = require('@babel/runtime/helpers/defineProperty');
17
17
  var reactDfp = require('react-dfp');
18
18
  var _toConsumableArray = require('@babel/runtime/helpers/toConsumableArray');
@@ -23,7 +23,7 @@ var _extends = require('@babel/runtime/helpers/extends');
23
23
  var _assertThisInitialized = require('@babel/runtime/helpers/assertThisInitialized');
24
24
  var classNames = require('classnames');
25
25
  var getVideoID = require('get-video-id');
26
- var getYouTubeID = require('get-youtube-id');
26
+ var getYouTubeID$1 = require('get-youtube-id');
27
27
  var _asyncToGenerator = require('@babel/runtime/helpers/asyncToGenerator');
28
28
  var _regeneratorRuntime = require('@babel/runtime/regenerator');
29
29
  var ReactDOM = require('react-dom');
@@ -56,7 +56,7 @@ var _getPrototypeOf__default = /*#__PURE__*/_interopDefaultLegacy(_getPrototypeO
56
56
  var React__default = /*#__PURE__*/_interopDefaultLegacy(React);
57
57
  var wretch__default = /*#__PURE__*/_interopDefaultLegacy(wretch);
58
58
  var omit__default = /*#__PURE__*/_interopDefaultLegacy(omit);
59
- var get__default = /*#__PURE__*/_interopDefaultLegacy(get);
59
+ var get__default = /*#__PURE__*/_interopDefaultLegacy(get$1);
60
60
  var _defineProperty__default = /*#__PURE__*/_interopDefaultLegacy(_defineProperty);
61
61
  var _toConsumableArray__default = /*#__PURE__*/_interopDefaultLegacy(_toConsumableArray);
62
62
  var _slicedToArray__default = /*#__PURE__*/_interopDefaultLegacy(_slicedToArray);
@@ -65,7 +65,7 @@ var _extends__default = /*#__PURE__*/_interopDefaultLegacy(_extends);
65
65
  var _assertThisInitialized__default = /*#__PURE__*/_interopDefaultLegacy(_assertThisInitialized);
66
66
  var classNames__default = /*#__PURE__*/_interopDefaultLegacy(classNames);
67
67
  var getVideoID__default = /*#__PURE__*/_interopDefaultLegacy(getVideoID);
68
- var getYouTubeID__default = /*#__PURE__*/_interopDefaultLegacy(getYouTubeID);
68
+ var getYouTubeID__default = /*#__PURE__*/_interopDefaultLegacy(getYouTubeID$1);
69
69
  var _asyncToGenerator__default = /*#__PURE__*/_interopDefaultLegacy(_asyncToGenerator);
70
70
  var _regeneratorRuntime__default = /*#__PURE__*/_interopDefaultLegacy(_regeneratorRuntime);
71
71
  var ReactDOM__default = /*#__PURE__*/_interopDefaultLegacy(ReactDOM);
@@ -2357,6 +2357,130 @@ var WithLazy = /*#__PURE__*/function (_React$Component) {
2357
2357
  return WithLazy;
2358
2358
  }(React__default["default"].Component);
2359
2359
 
2360
+ var _this = undefined;
2361
+ var Brightcove = null;
2362
+ var loaderPromise$2 = null;
2363
+
2364
+ var loadLibrary$2 = function loadLibrary() {
2365
+ if (!loaderPromise$2) {
2366
+ loaderPromise$2 = Promise.resolve().then(function () { return /*#__PURE__*/_interopNamespace(require(
2367
+ /* webpackChunkName: "qtc-react-brightcove" */
2368
+ '@brightcove/react-player-loader')); }).then(function (Bc) {
2369
+ Brightcove = Bc["default"];
2370
+ })["catch"](function (err) {
2371
+ console.log('Failed to load @brightcove/react-player-loader', err);
2372
+ return Promise.reject();
2373
+ });
2374
+ }
2375
+
2376
+ return loaderPromise$2;
2377
+ };
2378
+
2379
+ var isLibraryLoaded$2 = Brightcove !== null;
2380
+
2381
+ var CustomElementBrightcove = function CustomElementBrightcove(props) {
2382
+ var _props$element = props.element,
2383
+ element = _props$element === void 0 ? {} : _props$element;
2384
+ props.card;
2385
+ props.story;
2386
+ props.disableAnalytics;
2387
+ var loadIframeOnClick = props.loadIframeOnClick;
2388
+
2389
+ var _useState = React.useState(false),
2390
+ _useState2 = _slicedToArray__default["default"](_useState, 2),
2391
+ showVideo = _useState2[0],
2392
+ handleVideoDisplay = _useState2[1];
2393
+
2394
+ useEffect(function () {
2395
+ if (!loadIframeOnClick) {
2396
+ loadLibrary$2();
2397
+ }
2398
+ }, [loadIframeOnClick]); // const triggerQlitics = action => {
2399
+ // if (disableAnalytics) return false
2400
+ // const qliticsData = {
2401
+ // ...getQliticsSchema(story, card, element),
2402
+ // ...{ 'story-element-action': action }
2403
+ // }
2404
+ // if (global.qlitics) {
2405
+ // global.qlitics('track', 'story-element-action', qliticsData)
2406
+ // } else {
2407
+ // global.qlitics =
2408
+ // global.qlitics ||
2409
+ // function () {
2410
+ // ;(qlitics.q = qlitics.q || []).push(arguments)
2411
+ // }
2412
+ // qlitics.qlitics.q.push('track', 'story-element-action', qliticsData)
2413
+ // }
2414
+ // }
2415
+ // onPlayCallback = (event) => {
2416
+ // this.triggerQlitics("play");
2417
+ // this.props.onPlay === "function" && this.props.onPlay(event);
2418
+ // };
2419
+ // onPauseCallback = (event) => {
2420
+ // this.triggerQlitics("pause");
2421
+ // this.props.onPause === "function" && this.props.onPause(event);
2422
+ // };
2423
+ // onEndCallback = (event) => {
2424
+ // this.triggerQlitics("end");
2425
+ // this.props.onEnd === "function" && this.props.onEnd(event);
2426
+ // };
2427
+ // onPlayerReady = (event) => {
2428
+ // event.target.setVolume(100);
2429
+ // event.target.playVideo();
2430
+ // };
2431
+
2432
+ var brightcoveIframe = function brightcoveIframe() {
2433
+ var updatedOpts = {
2434
+ aspectRatio: '16:9',
2435
+ autoplay: true,
2436
+ muted: true,
2437
+ responsive: true
2438
+ };
2439
+ return /*#__PURE__*/React__default["default"].createElement(Brightcove, {
2440
+ accountId: get(element, ['metadata', 'account-id']),
2441
+ videoId: get(element, ['metadata', 'video-id']),
2442
+ playerId: get(element, ['metadata', 'player-id']),
2443
+ opts: updatedOpts // onPlay={ this.onPlayCallback}
2444
+ // onPause: this.onPauseCallback,
2445
+ // onEnd: this.onEndCallback,
2446
+ // onReady: this.onPlayerReady,
2447
+
2448
+ });
2449
+ };
2450
+
2451
+ var renderVideo = function renderVideo() {
2452
+ loadLibrary$2();
2453
+ handleVideoDisplay(true);
2454
+ };
2455
+
2456
+ if (loadIframeOnClick) {
2457
+ return /*#__PURE__*/React__default["default"].createElement("div", {
2458
+ className: "thumbnail-wrapper"
2459
+ }, !showVideo && /*#__PURE__*/React__default["default"].createElement(React__default["default"].Fragment, null, /*#__PURE__*/React__default["default"].createElement("button", {
2460
+ className: "youtube-playBtn",
2461
+ onClick: renderVideo,
2462
+ "aria-label": "Play Video"
2463
+ }), /*#__PURE__*/React__default["default"].createElement("img", {
2464
+ className: "youtube-thumbnail",
2465
+ onClick: renderVideo,
2466
+ src: "https://i.ytimg.com/vi/".concat(getYouTubeID(_this.props.element.url), "/hqdefault.jpg"),
2467
+ alt: "video"
2468
+ })), showVideo && isLibraryLoaded$2 && /*#__PURE__*/React__default["default"].createElement("div", {
2469
+ className: "youtube-iframe-wrapper"
2470
+ }, brightcoveIframe()));
2471
+ } else if (!loadIframeOnClick && isLibraryLoaded$2) {
2472
+ return brightcoveIframe();
2473
+ } else return /*#__PURE__*/React__default["default"].createElement(React__default["default"].Fragment, null);
2474
+ };
2475
+
2476
+ var StoryElementBrightcove = function StoryElementBrightcove(props) {
2477
+ return /*#__PURE__*/React__default["default"].createElement(WithLazy, {
2478
+ margin: "0px"
2479
+ }, function () {
2480
+ return /*#__PURE__*/React__default["default"].createElement(CustomElementBrightcove, props);
2481
+ });
2482
+ };
2483
+
2360
2484
  function _createSuper$c(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct$c(); return function _createSuperInternal() { var Super = _getPrototypeOf__default["default"](Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf__default["default"](this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn__default["default"](this, result); }; }
2361
2485
 
2362
2486
  function _isNativeReflectConstruct$c() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
@@ -3240,7 +3364,8 @@ var DEFAULT_TEMPLATES = {
3240
3364
  polltype: StoryElementPolltype,
3241
3365
  table: StoryElementTable,
3242
3366
  "also-read": StoryElementAlsoRead,
3243
- file: StoryElementFile
3367
+ file: StoryElementFile,
3368
+ "brightcove-video": StoryElementBrightcove
3244
3369
  };
3245
3370
 
3246
3371
  var StoryElementBase = /*#__PURE__*/function (_React$Component2) {
@@ -22,6 +22,7 @@ import React from "react";
22
22
  import { getQliticsSchema } from "../utils";
23
23
  import { Link } from "./link";
24
24
  import { ResponsiveImage } from "./responsive-image";
25
+ import StoryElementBrightcove from "./story-elements/brightcove";
25
26
  import StoryElementDailyMotion from "./story-elements/dailymotion";
26
27
  import DailyMotionEmbedScript from "./story-elements/dailymotion-embed-script";
27
28
  import JSEmbed from "./story-elements/jsembed";
@@ -227,7 +228,8 @@ var DEFAULT_TEMPLATES = {
227
228
  polltype: StoryElementPolltype,
228
229
  table: StoryElementTable,
229
230
  "also-read": StoryElementAlsoRead,
230
- file: StoryElementFile
231
+ file: StoryElementFile,
232
+ "brightcove-video": StoryElementBrightcove
231
233
  };
232
234
 
233
235
  var StoryElementBase = /*#__PURE__*/function (_React$Component2) {
@@ -0,0 +1,133 @@
1
+ import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
2
+
3
+ var _this = this;
4
+
5
+ import { bool, func, object } from 'prop-types';
6
+ import React, { useState } from 'react';
7
+ import { WithLazy } from '../with-lazy';
8
+ var Brightcove = null;
9
+ var loaderPromise = null;
10
+
11
+ var loadLibrary = function loadLibrary() {
12
+ if (!loaderPromise) {
13
+ loaderPromise = import(
14
+ /* webpackChunkName: "qtc-react-brightcove" */
15
+ '@brightcove/react-player-loader').then(function (Bc) {
16
+ Brightcove = Bc["default"];
17
+ })["catch"](function (err) {
18
+ console.log('Failed to load @brightcove/react-player-loader', err);
19
+ return Promise.reject();
20
+ });
21
+ }
22
+
23
+ return loaderPromise;
24
+ };
25
+
26
+ var isLibraryLoaded = Brightcove !== null;
27
+
28
+ var CustomElementBrightcove = function CustomElementBrightcove(props) {
29
+ var _props$element = props.element,
30
+ element = _props$element === void 0 ? {} : _props$element,
31
+ _props$card = props.card,
32
+ card = _props$card === void 0 ? {} : _props$card,
33
+ _props$story = props.story,
34
+ story = _props$story === void 0 ? {} : _props$story,
35
+ disableAnalytics = props.disableAnalytics,
36
+ loadIframeOnClick = props.loadIframeOnClick;
37
+
38
+ var _useState = useState(false),
39
+ _useState2 = _slicedToArray(_useState, 2),
40
+ showVideo = _useState2[0],
41
+ handleVideoDisplay = _useState2[1];
42
+
43
+ useEffect(function () {
44
+ if (!loadIframeOnClick) {
45
+ loadLibrary();
46
+ }
47
+ }, [loadIframeOnClick]); // const triggerQlitics = action => {
48
+ // if (disableAnalytics) return false
49
+ // const qliticsData = {
50
+ // ...getQliticsSchema(story, card, element),
51
+ // ...{ 'story-element-action': action }
52
+ // }
53
+ // if (global.qlitics) {
54
+ // global.qlitics('track', 'story-element-action', qliticsData)
55
+ // } else {
56
+ // global.qlitics =
57
+ // global.qlitics ||
58
+ // function () {
59
+ // ;(qlitics.q = qlitics.q || []).push(arguments)
60
+ // }
61
+ // qlitics.qlitics.q.push('track', 'story-element-action', qliticsData)
62
+ // }
63
+ // }
64
+ // onPlayCallback = (event) => {
65
+ // this.triggerQlitics("play");
66
+ // this.props.onPlay === "function" && this.props.onPlay(event);
67
+ // };
68
+ // onPauseCallback = (event) => {
69
+ // this.triggerQlitics("pause");
70
+ // this.props.onPause === "function" && this.props.onPause(event);
71
+ // };
72
+ // onEndCallback = (event) => {
73
+ // this.triggerQlitics("end");
74
+ // this.props.onEnd === "function" && this.props.onEnd(event);
75
+ // };
76
+ // onPlayerReady = (event) => {
77
+ // event.target.setVolume(100);
78
+ // event.target.playVideo();
79
+ // };
80
+
81
+ var brightcoveIframe = function brightcoveIframe() {
82
+ var updatedOpts = {
83
+ aspectRatio: '16:9',
84
+ autoplay: true,
85
+ muted: true,
86
+ responsive: true
87
+ };
88
+ return /*#__PURE__*/React.createElement(Brightcove, {
89
+ accountId: get(element, ['metadata', 'account-id']),
90
+ videoId: get(element, ['metadata', 'video-id']),
91
+ playerId: get(element, ['metadata', 'player-id']),
92
+ opts: updatedOpts // onPlay={ this.onPlayCallback}
93
+ // onPause: this.onPauseCallback,
94
+ // onEnd: this.onEndCallback,
95
+ // onReady: this.onPlayerReady,
96
+
97
+ });
98
+ };
99
+
100
+ var renderVideo = function renderVideo() {
101
+ loadLibrary();
102
+ handleVideoDisplay(true);
103
+ };
104
+
105
+ if (loadIframeOnClick) {
106
+ return /*#__PURE__*/React.createElement("div", {
107
+ className: "thumbnail-wrapper"
108
+ }, !showVideo && /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement("button", {
109
+ className: "youtube-playBtn",
110
+ onClick: renderVideo,
111
+ "aria-label": "Play Video"
112
+ }), /*#__PURE__*/React.createElement("img", {
113
+ className: "youtube-thumbnail",
114
+ onClick: renderVideo,
115
+ src: "https://i.ytimg.com/vi/".concat(getYouTubeID(_this.props.element.url), "/hqdefault.jpg"),
116
+ alt: "video"
117
+ })), showVideo && isLibraryLoaded && /*#__PURE__*/React.createElement("div", {
118
+ className: "youtube-iframe-wrapper"
119
+ }, brightcoveIframe()));
120
+ } else if (!loadIframeOnClick && isLibraryLoaded) {
121
+ return brightcoveIframe();
122
+ } else return /*#__PURE__*/React.createElement(React.Fragment, null);
123
+ };
124
+
125
+ var StoryElementBrightcove = function StoryElementBrightcove(props) {
126
+ return /*#__PURE__*/React.createElement(WithLazy, {
127
+ margin: "0px"
128
+ }, function () {
129
+ return /*#__PURE__*/React.createElement(CustomElementBrightcove, props);
130
+ });
131
+ };
132
+
133
+ export default StoryElementBrightcove;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@quintype/components",
3
- "version": "3.3.1",
3
+ "version": "3.3.2-brightcove.0",
4
4
  "description": "Components to help build Quintype Node.js apps",
5
5
  "main": "dist/cjs/index.js",
6
6
  "module": "dist/es/index.js",
@@ -23,6 +23,7 @@
23
23
  "homepage": "https://github.com/quintype/quintype-node-components#readme",
24
24
  "dependencies": {
25
25
  "@babel/runtime": "^7.16.3",
26
+ "@brightcove/react-player-loader": "^1.4.2",
26
27
  "classnames": "^2.3.1",
27
28
  "empty-web-gif": "^1.0.1",
28
29
  "get-video-id": "^3.4.3",