plugin updates
This commit is contained in:
@@ -1,14 +0,0 @@
|
||||
import $ from 'jquery';
|
||||
import Raven, { configureRaven } from '../lib/Raven';
|
||||
|
||||
export function initApp(initFn: Function) {
|
||||
configureRaven();
|
||||
Raven.context(initFn);
|
||||
}
|
||||
|
||||
export function initAppOnReady(initFn: (...args: any[]) => void) {
|
||||
function main() {
|
||||
$(initFn);
|
||||
}
|
||||
initApp(main);
|
||||
}
|
||||
@@ -1,44 +0,0 @@
|
||||
import {
|
||||
deviceId,
|
||||
hubspotBaseUrl,
|
||||
locale,
|
||||
portalId,
|
||||
} from '../constants/leadinConfig';
|
||||
import { initApp } from './appUtils';
|
||||
|
||||
type CallbackFn = (...args: any[]) => void;
|
||||
|
||||
export function initBackgroundApp(initFn: CallbackFn | CallbackFn[]) {
|
||||
function main() {
|
||||
if (Array.isArray(initFn)) {
|
||||
initFn.forEach(callback => callback());
|
||||
} else {
|
||||
initFn();
|
||||
}
|
||||
}
|
||||
initApp(main);
|
||||
}
|
||||
|
||||
export const getOrCreateBackgroundApp = (refreshToken: string) => {
|
||||
if ((window as any).LeadinBackgroundApp) {
|
||||
return (window as any).LeadinBackgroundApp;
|
||||
}
|
||||
const { IntegratedAppEmbedder, IntegratedAppOptions }: any = window;
|
||||
const options = new IntegratedAppOptions()
|
||||
.setLocale(locale)
|
||||
.setDeviceId(deviceId)
|
||||
.setRefreshToken(refreshToken);
|
||||
|
||||
const embedder = new IntegratedAppEmbedder(
|
||||
'integrated-plugin-proxy',
|
||||
portalId,
|
||||
hubspotBaseUrl,
|
||||
() => {}
|
||||
).setOptions(options);
|
||||
|
||||
embedder.attachTo(document.body, false);
|
||||
embedder.postStartAppMessage(); // lets the app know all all data has been passed to it
|
||||
|
||||
(window as any).LeadinBackgroundApp = embedder;
|
||||
return (window as any).LeadinBackgroundApp;
|
||||
};
|
||||
@@ -1,27 +0,0 @@
|
||||
type ContentEmbedInfoResponse = {
|
||||
success: boolean;
|
||||
data?: {
|
||||
// Empty if user doesn't have permissions or plugin already activated
|
||||
activateAjaxUrl?: string;
|
||||
message: string;
|
||||
};
|
||||
};
|
||||
|
||||
export function startInstall(nonce: string) {
|
||||
const formData = new FormData();
|
||||
const ajaxUrl = (window as any).ajaxurl;
|
||||
formData.append('_wpnonce', nonce);
|
||||
formData.append('action', 'content_embed_install');
|
||||
return fetch(ajaxUrl, {
|
||||
method: 'POST',
|
||||
body: formData,
|
||||
keepalive: true,
|
||||
}).then<ContentEmbedInfoResponse>(res => res.json());
|
||||
}
|
||||
|
||||
export function startActivation(requestUrl: string) {
|
||||
return fetch(requestUrl, {
|
||||
method: 'POST',
|
||||
keepalive: true,
|
||||
}).then<ContentEmbedInfoResponse>(res => res.json());
|
||||
}
|
||||
@@ -1,36 +0,0 @@
|
||||
import { useEffect, useState } from 'react';
|
||||
|
||||
const IFRAME_DISPLAY_TIMEOUT = 5000;
|
||||
|
||||
export function useIframeNotRendered(app: string) {
|
||||
const [iframeNotRendered, setIframeNotRendered] = useState(false);
|
||||
useEffect(() => {
|
||||
const timer = setTimeout(() => {
|
||||
const iframe = document.getElementById(app);
|
||||
if (!iframe) {
|
||||
setIframeNotRendered(true);
|
||||
}
|
||||
}, IFRAME_DISPLAY_TIMEOUT);
|
||||
|
||||
return () => {
|
||||
if (timer) {
|
||||
clearTimeout(timer);
|
||||
}
|
||||
};
|
||||
}, []);
|
||||
|
||||
return iframeNotRendered;
|
||||
}
|
||||
|
||||
export const resizeWindow = () => {
|
||||
const adminMenuWrap = document.getElementById('adminmenuwrap');
|
||||
const sideMenuHeight = adminMenuWrap ? adminMenuWrap.offsetHeight : 0;
|
||||
const adminBar = document.getElementById('wpadminbar');
|
||||
const adminBarHeight = (adminBar && adminBar.offsetHeight) || 0;
|
||||
const offset = 4;
|
||||
if (window.innerHeight < sideMenuHeight) {
|
||||
return sideMenuHeight - offset;
|
||||
} else {
|
||||
return window.innerHeight - adminBarHeight - offset;
|
||||
}
|
||||
};
|
||||
@@ -1,14 +0,0 @@
|
||||
export function addQueryObjectToUrl(
|
||||
urlObject: URL,
|
||||
queryParams: { [key: string]: any }
|
||||
) {
|
||||
Object.keys(queryParams).forEach(key => {
|
||||
urlObject.searchParams.append(key, queryParams[key]);
|
||||
});
|
||||
}
|
||||
|
||||
export function removeQueryParamFromLocation(key: string) {
|
||||
const location = new URL(window.location.href);
|
||||
location.searchParams.delete(key);
|
||||
window.history.replaceState(null, '', location.href);
|
||||
}
|
||||
@@ -1,30 +0,0 @@
|
||||
import { withSelect, withDispatch, select } from '@wordpress/data';
|
||||
|
||||
// from answer here: https://github.com/WordPress/gutenberg/issues/44477#issuecomment-1263026599
|
||||
export const isFullSiteEditor = () => {
|
||||
return select && !!select('core/edit-site');
|
||||
};
|
||||
|
||||
const applyWithSelect = withSelect((select: Function, props: any): any => {
|
||||
return {
|
||||
metaValue: select('core/editor').getEditedPostAttribute('meta')[
|
||||
props.metaKey
|
||||
],
|
||||
};
|
||||
});
|
||||
|
||||
const applyWithDispatch = withDispatch(
|
||||
(dispatch: Function, props: any): any => {
|
||||
return {
|
||||
setMetaValue(value: string) {
|
||||
dispatch('core/editor').editPost({ meta: { [props.metaKey]: value } });
|
||||
},
|
||||
};
|
||||
}
|
||||
);
|
||||
|
||||
function apply<T>(el: T): T {
|
||||
return applyWithSelect(applyWithDispatch(el));
|
||||
}
|
||||
|
||||
export default apply;
|
||||
Reference in New Issue
Block a user