miniapp-web-jsapi
Version:
JSAPI/View adapter for miniprogram running on the web
100 lines • 3.15 kB
JavaScript
import { rpc } from './rpc';
import { request } from './request';
import { alert } from './alert';
import { confirm } from './confirm';
import { pageScrollTo } from './page';
import { makePhoneCall } from './phone';
import { getLocation } from './location';
import { getServerTime } from './server-time';
import { getNetworkType } from './network';
import { createSelectorQuery } from './selector-query';
import { hideToast, showToast } from './toast';
import { navigateToMiniProgram, navigateTo, redirectTo } from './navigate';
import { navigateToBizScene } from './navigate/biz-scene';
import { hideLoading, showLoading } from './loading';
import { call, createUnsupportedJsApi, jsApiExtensions } from './call';
import { getClipboard, setClipboard } from './clipboard';
import { getSystemInfo, getSystemInfoSync } from './system';
import { getAppIdSync, getLaunchOptionsSync, getSiteInfo, setNavigationBar } from './misc';
import { clearStorage, clearStorageSync, getStorage, getStorageSync, removeStorage, removeStorageSync, setStorage, setStorageSync } from './storage';
import { startApp, exitApp } from './app';
import entries from "../../utils/entries";
var myImpl = {
// app
startApp: startApp,
exitApp: exitApp,
// modals
alert: alert,
confirm: confirm,
// misc
getLocation: getLocation,
makePhoneCall: makePhoneCall,
getServerTime: getServerTime,
getNetworkType: getNetworkType,
pageScrollTo: pageScrollTo,
createSelectorQuery: createSelectorQuery,
// navigate
navigateToBizScene: navigateToBizScene,
navigateToMiniProgram: navigateToMiniProgram,
navigateTo: navigateTo,
redirectTo: redirectTo,
// rpc / request
request: request,
call: call,
rpc: rpc,
// clipboard
setClipboard: setClipboard,
getClipboard: getClipboard,
// toast
showToast: showToast,
hideToast: hideToast,
// loading
showLoading: showLoading,
hideLoading: hideLoading,
// system
getSystemInfo: getSystemInfo,
getSystemInfoSync: getSystemInfoSync,
// storage
clearStorage: clearStorage,
clearStorageSync: clearStorageSync,
getStorage: getStorage,
getStorageSync: getStorageSync,
removeStorage: removeStorage,
removeStorageSync: removeStorageSync,
setStorage: setStorage,
setStorageSync: setStorageSync,
// misc
getSiteInfo: getSiteInfo,
getAppIdSync: getAppIdSync,
getLaunchOptionsSync: getLaunchOptionsSync,
setNavigationBar: setNavigationBar,
// no impl - with default unsupported mock impl
stopPullDownRefresh: createUnsupportedJsApi('stopPullDownRefresh')
};
function canIUse(apiName) {
var _window$my;
if (Object.keys(myImpl).indexOf(apiName) >= 0) {
return true;
}
if (((_window$my = window.my) === null || _window$my === void 0 ? void 0 : _window$my[apiName]) != null) {
return true;
}
return jsApiExtensions[apiName] != null;
}
(function () {
if (!window) {
return;
}
if (!window.my) {
window.my = myImpl;
} else {
var globalMy = window.my;
entries(myImpl).forEach(function (item) {
var key = item[0];
if (!globalMy[key]) {
globalMy[key] = item[1];
}
});
}
window.my.canIUse = canIUse;
})();