Update capacitor version
This commit is contained in:
parent
91155bce0a
commit
f3b3a86b32
610 changed files with 28718 additions and 7101 deletions
175
@capacitor/core/dist/index.cjs.js
vendored
175
@capacitor/core/dist/index.cjs.js
vendored
|
@ -3,69 +3,6 @@
|
|||
|
||||
Object.defineProperty(exports, '__esModule', { value: true });
|
||||
|
||||
const createCapacitorPlatforms = (win) => {
|
||||
const defaultPlatformMap = new Map();
|
||||
defaultPlatformMap.set('web', { name: 'web' });
|
||||
const capPlatforms = win.CapacitorPlatforms || {
|
||||
currentPlatform: { name: 'web' },
|
||||
platforms: defaultPlatformMap,
|
||||
};
|
||||
const addPlatform = (name, platform) => {
|
||||
capPlatforms.platforms.set(name, platform);
|
||||
};
|
||||
const setPlatform = (name) => {
|
||||
if (capPlatforms.platforms.has(name)) {
|
||||
capPlatforms.currentPlatform = capPlatforms.platforms.get(name);
|
||||
}
|
||||
};
|
||||
capPlatforms.addPlatform = addPlatform;
|
||||
capPlatforms.setPlatform = setPlatform;
|
||||
return capPlatforms;
|
||||
};
|
||||
const initPlatforms = (win) => (win.CapacitorPlatforms = createCapacitorPlatforms(win));
|
||||
/**
|
||||
* @deprecated Set `CapacitorCustomPlatform` on the window object prior to runtime executing in the web app instead
|
||||
*/
|
||||
const CapacitorPlatforms = /*#__PURE__*/ initPlatforms((typeof globalThis !== 'undefined'
|
||||
? globalThis
|
||||
: typeof self !== 'undefined'
|
||||
? self
|
||||
: typeof window !== 'undefined'
|
||||
? window
|
||||
: typeof global !== 'undefined'
|
||||
? global
|
||||
: {}));
|
||||
/**
|
||||
* @deprecated Set `CapacitorCustomPlatform` on the window object prior to runtime executing in the web app instead
|
||||
*/
|
||||
const addPlatform = CapacitorPlatforms.addPlatform;
|
||||
/**
|
||||
* @deprecated Set `CapacitorCustomPlatform` on the window object prior to runtime executing in the web app instead
|
||||
*/
|
||||
const setPlatform = CapacitorPlatforms.setPlatform;
|
||||
|
||||
const legacyRegisterWebPlugin = (cap, webPlugin) => {
|
||||
var _a;
|
||||
const config = webPlugin.config;
|
||||
const Plugins = cap.Plugins;
|
||||
if (!(config === null || config === void 0 ? void 0 : config.name)) {
|
||||
// TODO: add link to upgrade guide
|
||||
throw new Error(`Capacitor WebPlugin is using the deprecated "registerWebPlugin()" function, but without the config. Please use "registerPlugin()" instead to register this web plugin."`);
|
||||
}
|
||||
// TODO: add link to upgrade guide
|
||||
console.warn(`Capacitor plugin "${config.name}" is using the deprecated "registerWebPlugin()" function`);
|
||||
if (!Plugins[config.name] || ((_a = config === null || config === void 0 ? void 0 : config.platforms) === null || _a === void 0 ? void 0 : _a.includes(cap.getPlatform()))) {
|
||||
// Add the web plugin into the plugins registry if there already isn't
|
||||
// an existing one. If it doesn't already exist, that means
|
||||
// there's no existing native implementation for it.
|
||||
// - OR -
|
||||
// If we already have a plugin registered (meaning it was defined in the native layer),
|
||||
// then we should only overwrite it if the corresponding web plugin activates on
|
||||
// a certain platform. For example: Geolocation uses the WebPlugin on Android but not iOS
|
||||
Plugins[config.name] = webPlugin;
|
||||
}
|
||||
};
|
||||
|
||||
exports.ExceptionCode = void 0;
|
||||
(function (ExceptionCode) {
|
||||
/**
|
||||
|
@ -106,23 +43,14 @@ const getPlatformId = (win) => {
|
|||
};
|
||||
|
||||
const createCapacitor = (win) => {
|
||||
var _a, _b, _c, _d, _e;
|
||||
const capCustomPlatform = win.CapacitorCustomPlatform || null;
|
||||
const cap = win.Capacitor || {};
|
||||
const Plugins = (cap.Plugins = cap.Plugins || {});
|
||||
/**
|
||||
* @deprecated Use `capCustomPlatform` instead, default functions like registerPlugin will function with the new object.
|
||||
*/
|
||||
const capPlatforms = win.CapacitorPlatforms;
|
||||
const defaultGetPlatform = () => {
|
||||
return capCustomPlatform !== null
|
||||
? capCustomPlatform.name
|
||||
: getPlatformId(win);
|
||||
const getPlatform = () => {
|
||||
return capCustomPlatform !== null ? capCustomPlatform.name : getPlatformId(win);
|
||||
};
|
||||
const getPlatform = ((_a = capPlatforms === null || capPlatforms === void 0 ? void 0 : capPlatforms.currentPlatform) === null || _a === void 0 ? void 0 : _a.getPlatform) || defaultGetPlatform;
|
||||
const defaultIsNativePlatform = () => getPlatform() !== 'web';
|
||||
const isNativePlatform = ((_b = capPlatforms === null || capPlatforms === void 0 ? void 0 : capPlatforms.currentPlatform) === null || _b === void 0 ? void 0 : _b.isNativePlatform) || defaultIsNativePlatform;
|
||||
const defaultIsPluginAvailable = (pluginName) => {
|
||||
const isNativePlatform = () => getPlatform() !== 'web';
|
||||
const isPluginAvailable = (pluginName) => {
|
||||
const plugin = registeredPlugins.get(pluginName);
|
||||
if (plugin === null || plugin === void 0 ? void 0 : plugin.platforms.has(getPlatform())) {
|
||||
// JS implementation available for the current platform.
|
||||
|
@ -134,16 +62,10 @@ const createCapacitor = (win) => {
|
|||
}
|
||||
return false;
|
||||
};
|
||||
const isPluginAvailable = ((_c = capPlatforms === null || capPlatforms === void 0 ? void 0 : capPlatforms.currentPlatform) === null || _c === void 0 ? void 0 : _c.isPluginAvailable) ||
|
||||
defaultIsPluginAvailable;
|
||||
const defaultGetPluginHeader = (pluginName) => { var _a; return (_a = cap.PluginHeaders) === null || _a === void 0 ? void 0 : _a.find(h => h.name === pluginName); };
|
||||
const getPluginHeader = ((_d = capPlatforms === null || capPlatforms === void 0 ? void 0 : capPlatforms.currentPlatform) === null || _d === void 0 ? void 0 : _d.getPluginHeader) || defaultGetPluginHeader;
|
||||
const getPluginHeader = (pluginName) => { var _a; return (_a = cap.PluginHeaders) === null || _a === void 0 ? void 0 : _a.find((h) => h.name === pluginName); };
|
||||
const handleError = (err) => win.console.error(err);
|
||||
const pluginMethodNoop = (_target, prop, pluginName) => {
|
||||
return Promise.reject(`${pluginName} does not have an implementation of "${prop}".`);
|
||||
};
|
||||
const registeredPlugins = new Map();
|
||||
const defaultRegisterPlugin = (pluginName, jsImplementations = {}) => {
|
||||
const registerPlugin = (pluginName, jsImplementations = {}) => {
|
||||
const registeredPlugin = registeredPlugins.get(pluginName);
|
||||
if (registeredPlugin) {
|
||||
console.warn(`Capacitor plugin "${pluginName}" already registered. Cannot register plugins twice.`);
|
||||
|
@ -159,9 +81,7 @@ const createCapacitor = (win) => {
|
|||
? (jsImplementation = await jsImplementations[platform]())
|
||||
: (jsImplementation = jsImplementations[platform]);
|
||||
}
|
||||
else if (capCustomPlatform !== null &&
|
||||
!jsImplementation &&
|
||||
'web' in jsImplementations) {
|
||||
else if (capCustomPlatform !== null && !jsImplementation && 'web' in jsImplementations) {
|
||||
jsImplementation =
|
||||
typeof jsImplementations['web'] === 'function'
|
||||
? (jsImplementation = await jsImplementations['web']())
|
||||
|
@ -172,7 +92,7 @@ const createCapacitor = (win) => {
|
|||
const createPluginMethod = (impl, prop) => {
|
||||
var _a, _b;
|
||||
if (pluginHeader) {
|
||||
const methodHeader = pluginHeader === null || pluginHeader === void 0 ? void 0 : pluginHeader.methods.find(m => prop === m.name);
|
||||
const methodHeader = pluginHeader === null || pluginHeader === void 0 ? void 0 : pluginHeader.methods.find((m) => prop === m.name);
|
||||
if (methodHeader) {
|
||||
if (methodHeader.rtype === 'promise') {
|
||||
return (options) => cap.nativePromise(pluginName, prop.toString(), options);
|
||||
|
@ -195,7 +115,7 @@ const createCapacitor = (win) => {
|
|||
const createPluginMethodWrapper = (prop) => {
|
||||
let remove;
|
||||
const wrapper = (...args) => {
|
||||
const p = loadPluginImplementation().then(impl => {
|
||||
const p = loadPluginImplementation().then((impl) => {
|
||||
const fn = createPluginMethod(impl, prop);
|
||||
if (fn) {
|
||||
const p = fn(...args);
|
||||
|
@ -231,7 +151,7 @@ const createCapacitor = (win) => {
|
|||
callbackId,
|
||||
}, callback);
|
||||
};
|
||||
const p = new Promise(resolve => call.then(() => resolve({ remove })));
|
||||
const p = new Promise((resolve) => call.then(() => resolve({ remove })));
|
||||
p.remove = async () => {
|
||||
console.warn(`Using addListener() without 'await' is deprecated.`);
|
||||
await remove();
|
||||
|
@ -259,30 +179,22 @@ const createCapacitor = (win) => {
|
|||
registeredPlugins.set(pluginName, {
|
||||
name: pluginName,
|
||||
proxy,
|
||||
platforms: new Set([
|
||||
...Object.keys(jsImplementations),
|
||||
...(pluginHeader ? [platform] : []),
|
||||
]),
|
||||
platforms: new Set([...Object.keys(jsImplementations), ...(pluginHeader ? [platform] : [])]),
|
||||
});
|
||||
return proxy;
|
||||
};
|
||||
const registerPlugin = ((_e = capPlatforms === null || capPlatforms === void 0 ? void 0 : capPlatforms.currentPlatform) === null || _e === void 0 ? void 0 : _e.registerPlugin) || defaultRegisterPlugin;
|
||||
// Add in convertFileSrc for web, it will already be available in native context
|
||||
if (!cap.convertFileSrc) {
|
||||
cap.convertFileSrc = filePath => filePath;
|
||||
cap.convertFileSrc = (filePath) => filePath;
|
||||
}
|
||||
cap.getPlatform = getPlatform;
|
||||
cap.handleError = handleError;
|
||||
cap.isNativePlatform = isNativePlatform;
|
||||
cap.isPluginAvailable = isPluginAvailable;
|
||||
cap.pluginMethodNoop = pluginMethodNoop;
|
||||
cap.registerPlugin = registerPlugin;
|
||||
cap.Exception = CapacitorException;
|
||||
cap.DEBUG = !!cap.DEBUG;
|
||||
cap.isLoggingEnabled = !!cap.isLoggingEnabled;
|
||||
// Deprecated props
|
||||
cap.platform = cap.getPlatform();
|
||||
cap.isNative = cap.isNativePlatform();
|
||||
return cap;
|
||||
};
|
||||
const initCapacitorGlobal = (win) => (win.Capacitor = createCapacitor(win));
|
||||
|
@ -297,38 +209,15 @@ const Capacitor = /*#__PURE__*/ initCapacitorGlobal(typeof globalThis !== 'undef
|
|||
? global
|
||||
: {});
|
||||
const registerPlugin = Capacitor.registerPlugin;
|
||||
/**
|
||||
* @deprecated Provided for backwards compatibility for Capacitor v2 plugins.
|
||||
* Capacitor v3 plugins should import the plugin directly. This "Plugins"
|
||||
* export is deprecated in v3, and will be removed in v4.
|
||||
*/
|
||||
const Plugins = Capacitor.Plugins;
|
||||
/**
|
||||
* Provided for backwards compatibility. Use the registerPlugin() API
|
||||
* instead, and provide the web plugin as the "web" implmenetation.
|
||||
* For example
|
||||
*
|
||||
* export const Example = registerPlugin('Example', {
|
||||
* web: () => import('./web').then(m => new m.Example())
|
||||
* })
|
||||
*
|
||||
* @deprecated Deprecated in v3, will be removed from v4.
|
||||
*/
|
||||
const registerWebPlugin = (plugin) => legacyRegisterWebPlugin(Capacitor, plugin);
|
||||
|
||||
/**
|
||||
* Base class web plugins should extend.
|
||||
*/
|
||||
class WebPlugin {
|
||||
constructor(config) {
|
||||
constructor() {
|
||||
this.listeners = {};
|
||||
this.retainedEventArguments = {};
|
||||
this.windowListeners = {};
|
||||
if (config) {
|
||||
// TODO: add link to upgrade guide
|
||||
console.warn(`Capacitor WebPlugin "${config.name}" config object was deprecated in v3 and will be removed in v4.`);
|
||||
this.config = config;
|
||||
}
|
||||
}
|
||||
addListener(eventName, listenerFunc) {
|
||||
let firstListener = false;
|
||||
|
@ -371,17 +260,18 @@ class WebPlugin {
|
|||
}
|
||||
return;
|
||||
}
|
||||
listeners.forEach(listener => listener(data));
|
||||
listeners.forEach((listener) => listener(data));
|
||||
}
|
||||
hasListeners(eventName) {
|
||||
return !!this.listeners[eventName].length;
|
||||
var _a;
|
||||
return !!((_a = this.listeners[eventName]) === null || _a === void 0 ? void 0 : _a.length);
|
||||
}
|
||||
registerWindowListener(windowEventName, pluginEventName) {
|
||||
this.windowListeners[pluginEventName] = {
|
||||
registered: false,
|
||||
windowEventName,
|
||||
pluginEventName,
|
||||
handler: event => {
|
||||
handler: (event) => {
|
||||
this.notifyListeners(pluginEventName, event);
|
||||
},
|
||||
};
|
||||
|
@ -422,7 +312,7 @@ class WebPlugin {
|
|||
return;
|
||||
}
|
||||
delete this.retainedEventArguments[eventName];
|
||||
args.forEach(arg => {
|
||||
args.forEach((arg) => {
|
||||
this.notifyListeners(eventName, arg);
|
||||
});
|
||||
}
|
||||
|
@ -447,7 +337,7 @@ class CapacitorCookiesPluginWeb extends WebPlugin {
|
|||
async getCookies() {
|
||||
const cookies = document.cookie;
|
||||
const cookieMap = {};
|
||||
cookies.split(';').forEach(cookie => {
|
||||
cookies.split(';').forEach((cookie) => {
|
||||
if (cookie.length <= 0)
|
||||
return;
|
||||
// Replace first "=" with CAP_COOKIE to prevent splitting on additional "="
|
||||
|
@ -466,9 +356,7 @@ class CapacitorCookiesPluginWeb extends WebPlugin {
|
|||
// Clean & sanitize options
|
||||
const expires = `; expires=${(options.expires || '').replace('expires=', '')}`; // Default is "; expires="
|
||||
const path = (options.path || '/').replace('path=', ''); // Default is "path=/"
|
||||
const domain = options.url != null && options.url.length > 0
|
||||
? `domain=${options.url}`
|
||||
: '';
|
||||
const domain = options.url != null && options.url.length > 0 ? `domain=${options.url}` : '';
|
||||
document.cookie = `${encodedKey}=${encodedValue || ''}${expires}; path=${path}; ${domain};`;
|
||||
}
|
||||
catch (error) {
|
||||
|
@ -487,9 +375,7 @@ class CapacitorCookiesPluginWeb extends WebPlugin {
|
|||
try {
|
||||
const cookies = document.cookie.split(';') || [];
|
||||
for (const cookie of cookies) {
|
||||
document.cookie = cookie
|
||||
.replace(/^ +/, '')
|
||||
.replace(/=.*/, `=;expires=${new Date().toUTCString()};path=/`);
|
||||
document.cookie = cookie.replace(/^ +/, '').replace(/=.*/, `=;expires=${new Date().toUTCString()};path=/`);
|
||||
}
|
||||
}
|
||||
catch (error) {
|
||||
|
@ -518,9 +404,7 @@ const readBlobAsBase64 = async (blob) => new Promise((resolve, reject) => {
|
|||
reader.onload = () => {
|
||||
const base64String = reader.result;
|
||||
// remove prefix "data:application/pdf;base64,"
|
||||
resolve(base64String.indexOf(',') >= 0
|
||||
? base64String.split(',')[1]
|
||||
: base64String);
|
||||
resolve(base64String.indexOf(',') >= 0 ? base64String.split(',')[1] : base64String);
|
||||
};
|
||||
reader.onerror = (error) => reject(error);
|
||||
reader.readAsDataURL(blob);
|
||||
|
@ -531,7 +415,7 @@ const readBlobAsBase64 = async (blob) => new Promise((resolve, reject) => {
|
|||
*/
|
||||
const normalizeHttpHeaders = (headers = {}) => {
|
||||
const originalKeys = Object.keys(headers);
|
||||
const loweredKeys = Object.keys(headers).map(k => k.toLocaleLowerCase());
|
||||
const loweredKeys = Object.keys(headers).map((k) => k.toLocaleLowerCase());
|
||||
const normalized = loweredKeys.reduce((acc, key, index) => {
|
||||
acc[key] = headers[originalKeys[index]];
|
||||
return acc;
|
||||
|
@ -552,7 +436,7 @@ const buildUrlParams = (params, shouldEncode = true) => {
|
|||
let item;
|
||||
if (Array.isArray(value)) {
|
||||
item = '';
|
||||
value.forEach(str => {
|
||||
value.forEach((str) => {
|
||||
encodedValue = shouldEncode ? encodeURIComponent(str) : str;
|
||||
item += `${key}=${encodedValue}&`;
|
||||
});
|
||||
|
@ -590,8 +474,7 @@ const buildRequestInit = (options, extra = {}) => {
|
|||
}
|
||||
output.body = params.toString();
|
||||
}
|
||||
else if (type.includes('multipart/form-data') ||
|
||||
options.data instanceof FormData) {
|
||||
else if (type.includes('multipart/form-data') || options.data instanceof FormData) {
|
||||
const form = new FormData();
|
||||
if (options.data instanceof FormData) {
|
||||
options.data.forEach((value, key) => {
|
||||
|
@ -608,8 +491,7 @@ const buildRequestInit = (options, extra = {}) => {
|
|||
headers.delete('content-type'); // content-type will be set by `window.fetch` to includy boundary
|
||||
output.headers = headers;
|
||||
}
|
||||
else if (type.includes('application/json') ||
|
||||
typeof options.data === 'object') {
|
||||
else if (type.includes('application/json') || typeof options.data === 'object') {
|
||||
output.body = JSON.stringify(options.data);
|
||||
}
|
||||
return output;
|
||||
|
@ -705,13 +587,8 @@ exports.Capacitor = Capacitor;
|
|||
exports.CapacitorCookies = CapacitorCookies;
|
||||
exports.CapacitorException = CapacitorException;
|
||||
exports.CapacitorHttp = CapacitorHttp;
|
||||
exports.CapacitorPlatforms = CapacitorPlatforms;
|
||||
exports.Plugins = Plugins;
|
||||
exports.WebPlugin = WebPlugin;
|
||||
exports.WebView = WebView;
|
||||
exports.addPlatform = addPlatform;
|
||||
exports.buildRequestInit = buildRequestInit;
|
||||
exports.registerPlugin = registerPlugin;
|
||||
exports.registerWebPlugin = registerWebPlugin;
|
||||
exports.setPlatform = setPlatform;
|
||||
//# sourceMappingURL=index.cjs.js.map
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue