From f95e2777d50d7fb371060d01d402be852a9fdb05 Mon Sep 17 00:00:00 2001 From: Kristian Puccio Date: Thu, 23 Jul 2020 13:43:52 +1000 Subject: [PATCH] add missing build files --- lib/index.js | 1 + lib/react.d.ts | 8 ++++---- lib/react.js | 35 ++++++++++++++++++++++++++++++----- src/react.tsx | 21 +++++++++++++++++---- 4 files changed, 52 insertions(+), 13 deletions(-) diff --git a/lib/index.js b/lib/index.js index 928d379..bfe87bf 100644 --- a/lib/index.js +++ b/lib/index.js @@ -3,6 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); +exports.react = exports.client = void 0; var client_1 = __importDefault(require("./client")); exports.client = client_1.default; var react_1 = __importDefault(require("./react")); diff --git a/lib/react.d.ts b/lib/react.d.ts index ddd1b6d..1f619bb 100644 --- a/lib/react.d.ts +++ b/lib/react.d.ts @@ -106,7 +106,7 @@ declare class ElevioReact extends React.Component { static propTypes: { accountId: PropTypes.Validator; options: PropTypes.Requireable; - keywords: PropTypes.Requireable<(string | null)[]>; + keywords: PropTypes.Requireable<(string | null | undefined)[]>; language: PropTypes.Requireable; user: PropTypes.Requireable; settings: PropTypes.Requireable; @@ -127,7 +127,7 @@ declare class ElevioReact extends React.Component { constructor(props: Props); componentDidMount(): void; componentWillUnmount(): void; - componentWillReceiveProps(prevProps: Props): void; + componentDidUpdate(prevProps: Props): void; onLoad: (_elev: WindowElev) => void; onReady: () => void; onWidgetOpened: () => void; @@ -137,11 +137,11 @@ declare class ElevioReact extends React.Component { onPopupClosed: (articleId: string) => void; onSearchQuery: (results: { query: string; - results: { + results: Array<{ category_id: string; id: string; title: string; - }[]; + }>; }) => void; onSearchArticleClicked: (result: { articleId: string; diff --git a/lib/react.js b/lib/react.js index 1903f5f..d6098d6 100644 --- a/lib/react.js +++ b/lib/react.js @@ -12,22 +12,39 @@ var __extends = (this && this.__extends) || (function () { d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); }; })(); +var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { + if (k2 === undefined) k2 = k; + Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } }); +}) : (function(o, m, k, k2) { + if (k2 === undefined) k2 = k; + o[k2] = m[k]; +})); +var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { + Object.defineProperty(o, "default", { enumerable: true, value: v }); +}) : function(o, v) { + o["default"] = v; +}); var __importStar = (this && this.__importStar) || function (mod) { if (mod && mod.__esModule) return mod; var result = {}; - if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k]; - result["default"] = mod; + if (mod != null) for (var k in mod) if (k !== "default" && Object.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); + __setModuleDefault(result, mod); return result; }; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); +exports.Elevio = void 0; var React = __importStar(require("react")); var client_1 = __importDefault(require("./client")); exports.Elevio = client_1.default; var fast_deep_equal_1 = __importDefault(require("fast-deep-equal")); var prop_types_1 = __importDefault(require("prop-types")); +// This just keeps track of if the settings has been enabled via the server or settings +// that way when we render the component we know if we need to enable it or not +// NOTE: if the client does _elev.setStettings it won't be picked up by this. +var serverEnabled = undefined; // TODO: // * Convert all existing options into props. // # Modules + Popups ? @@ -40,6 +57,10 @@ var ElevioReact = /** @class */ (function (_super) { _this.props.onLoad && _this.props.onLoad(_elev); }; _this.onReady = function () { + if (typeof serverEnabled === 'undefined') { + // @ts-ignore + serverEnabled = _elev.getSetting('enabled'); + } _this.props.onReady && _this.props.onReady(); }; _this.onWidgetOpened = function () { @@ -90,7 +111,6 @@ var ElevioReact = /** @class */ (function (_super) { console.warn("Multiple instances of the elevio component being rendered, this will lead to unexpected results. Please only use one."); } var accountId = this.props.accountId; - // TODO: only on initial mount. var urlOverride = (this.props.developerOptions && this.props.developerOptions.urlOverride) || undefined; @@ -116,7 +136,9 @@ var ElevioReact = /** @class */ (function (_super) { if (_this.props.translations) { client_1.default.setTranslations(_this.props.translations); } - client_1.default.enable(); + if (serverEnabled) { + client_1.default.enable(); + } _this.onLoad(_elev); }); }; @@ -124,7 +146,7 @@ var ElevioReact = /** @class */ (function (_super) { client_1.default.disable(); mountedCount--; }; - ElevioReact.prototype.componentWillReceiveProps = function (prevProps) { + ElevioReact.prototype.componentDidUpdate = function (prevProps) { if (!fast_deep_equal_1.default(this.props.keywords, prevProps.keywords)) { client_1.default.setKeywords(this.props.keywords); } @@ -146,6 +168,9 @@ var ElevioReact = /** @class */ (function (_super) { } if (this.props.settings && !fast_deep_equal_1.default(this.props.settings, prevProps.settings)) { + if (this.props.settings.enabled) { + serverEnabled = this.props.settings.enabled; + } client_1.default.setSettings(this.props.settings); } if (this.props.pageUrl !== prevProps.pageUrl) { diff --git a/src/react.tsx b/src/react.tsx index f758578..efab86b 100644 --- a/src/react.tsx +++ b/src/react.tsx @@ -6,6 +6,11 @@ import PropTypes from 'prop-types'; export { Elevio }; +// This just keeps track of if the settings has been enabled via the server or settings +// that way when we render the component we know if we need to enable it or not +// NOTE: if the client does _elev.setStettings it won't be picked up by this. +let serverEnabled: boolean | undefined = undefined; + /** All the things you can pass to Elevio */ type Props = { /** Your account id, found here {@link https://app.elev.io/installation | Installation} */ @@ -173,7 +178,6 @@ class ElevioReact extends React.Component { const { accountId } = this.props; - // TODO: only on initial mount. const urlOverride = (this.props.developerOptions && this.props.developerOptions.urlOverride) || @@ -181,7 +185,7 @@ class ElevioReact extends React.Component { Elevio.load(accountId, { urlOverride, - }).then(_elev => { + }).then((_elev) => { // Wait until Elevio has loaded before setting settings. if (this.props.keywords) { @@ -208,7 +212,9 @@ class ElevioReact extends React.Component { Elevio.setTranslations(this.props.translations); } - Elevio.enable(); + if (serverEnabled) { + Elevio.enable(); + } this.onLoad(_elev); }); } @@ -218,7 +224,7 @@ class ElevioReact extends React.Component { mountedCount--; } - componentWillReceiveProps(prevProps: Props) { + componentDidUpdate(prevProps: Props) { if (!equal(this.props.keywords, prevProps.keywords)) { Elevio.setKeywords(this.props.keywords); } @@ -245,6 +251,9 @@ class ElevioReact extends React.Component { this.props.settings && !equal(this.props.settings, prevProps.settings) ) { + if (this.props.settings.enabled) { + serverEnabled = this.props.settings.enabled; + } Elevio.setSettings(this.props.settings); } @@ -262,6 +271,10 @@ class ElevioReact extends React.Component { }; onReady = () => { + if (typeof serverEnabled === 'undefined') { + // @ts-ignore + serverEnabled = _elev.getSetting('enabled'); + } this.props.onReady && this.props.onReady(); };