Skip to content

Commit

Permalink
add missing build files
Browse files Browse the repository at this point in the history
  • Loading branch information
kristian-puccio committed Jul 23, 2020
1 parent 78a71c7 commit f95e277
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 13 deletions.
1 change: 1 addition & 0 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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"));
Expand Down
8 changes: 4 additions & 4 deletions lib/react.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ declare class ElevioReact extends React.Component<Props> {
static propTypes: {
accountId: PropTypes.Validator<string>;
options: PropTypes.Requireable<object>;
keywords: PropTypes.Requireable<(string | null)[]>;
keywords: PropTypes.Requireable<(string | null | undefined)[]>;
language: PropTypes.Requireable<string>;
user: PropTypes.Requireable<object>;
settings: PropTypes.Requireable<object>;
Expand All @@ -127,7 +127,7 @@ declare class ElevioReact extends React.Component<Props> {
constructor(props: Props);
componentDidMount(): void;
componentWillUnmount(): void;
componentWillReceiveProps(prevProps: Props): void;
componentDidUpdate(prevProps: Props): void;
onLoad: (_elev: WindowElev) => void;
onReady: () => void;
onWidgetOpened: () => void;
Expand All @@ -137,11 +137,11 @@ declare class ElevioReact extends React.Component<Props> {
onPopupClosed: (articleId: string) => void;
onSearchQuery: (results: {
query: string;
results: {
results: Array<{
category_id: string;
id: string;
title: string;
}[];
}>;
}) => void;
onSearchArticleClicked: (result: {
articleId: string;
Expand Down
35 changes: 30 additions & 5 deletions lib/react.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 ?
Expand All @@ -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 () {
Expand Down Expand Up @@ -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;
Expand All @@ -116,15 +136,17 @@ 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);
});
};
ElevioReact.prototype.componentWillUnmount = function () {
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);
}
Expand All @@ -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) {
Expand Down
21 changes: 17 additions & 4 deletions src/react.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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} */
Expand Down Expand Up @@ -173,15 +178,14 @@ class ElevioReact extends React.Component<Props> {

const { accountId } = this.props;

// TODO: only on initial mount.
const urlOverride =
(this.props.developerOptions &&
this.props.developerOptions.urlOverride) ||
undefined;

Elevio.load(accountId, {
urlOverride,
}).then(_elev => {
}).then((_elev) => {
// Wait until Elevio has loaded before setting settings.

if (this.props.keywords) {
Expand All @@ -208,7 +212,9 @@ class ElevioReact extends React.Component<Props> {
Elevio.setTranslations(this.props.translations);
}

Elevio.enable();
if (serverEnabled) {
Elevio.enable();
}
this.onLoad(_elev);
});
}
Expand All @@ -218,7 +224,7 @@ class ElevioReact extends React.Component<Props> {
mountedCount--;
}

componentWillReceiveProps(prevProps: Props) {
componentDidUpdate(prevProps: Props) {
if (!equal(this.props.keywords, prevProps.keywords)) {
Elevio.setKeywords(this.props.keywords);
}
Expand All @@ -245,6 +251,9 @@ class ElevioReact extends React.Component<Props> {
this.props.settings &&
!equal(this.props.settings, prevProps.settings)
) {
if (this.props.settings.enabled) {
serverEnabled = this.props.settings.enabled;
}
Elevio.setSettings(this.props.settings);
}

Expand All @@ -262,6 +271,10 @@ class ElevioReact extends React.Component<Props> {
};

onReady = () => {
if (typeof serverEnabled === 'undefined') {
// @ts-ignore
serverEnabled = _elev.getSetting('enabled');
}
this.props.onReady && this.props.onReady();
};

Expand Down

0 comments on commit f95e277

Please sign in to comment.