one
Version:
One is a React framework for web, iOS, and Android apps.
135 lines (132 loc) • 4.48 kB
JavaScript
;
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
for (var name in all) __defProp(target, name, {
get: all[name],
enumerable: true
});
};
var __copyProps = (to, from, except, desc) => {
if (from && typeof from === "object" || typeof from === "function") {
for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
get: () => from[key],
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
});
}
return to;
};
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
var index_native_exports = {};
__export(index_native_exports, { Clipboard: () => Clipboard });
module.exports = __toCommonJS(index_native_exports);
var import_react_native_nitro_modules = require("react-native-nitro-modules");
var import_nativeError = require("../nativeError.native.js");
var import_validate = require("./validate.native.js");
var hybrid;
function native() {
hybrid !== null && hybrid !== void 0 ? hybrid : hybrid = import_react_native_nitro_modules.NitroModules.createHybridObject("OneClipboard");
return hybrid;
}
function getString(options) {
(0, import_validate.assertGetStringOptions)(options, "getString");
var nativeOptions = {};
if ((options === null || options === void 0 ? void 0 : options.preferredFormat) !== void 0) {
nativeOptions.preferredFormat = options.preferredFormat;
}
return native().getString(nativeOptions).catch(import_nativeError.rethrowNativeError);
}
function setString(text, options) {
(0, import_validate.assertSetStringText)(text);
(0, import_validate.assertSetStringOptions)(options, "setString");
var nativeOptions = {};
if ((options === null || options === void 0 ? void 0 : options.inputFormat) !== void 0) {
nativeOptions.inputFormat = options.inputFormat;
}
return native().setString(text, nativeOptions).catch(import_nativeError.rethrowNativeError);
}
function hasString() {
return native().hasString().catch(import_nativeError.rethrowNativeError);
}
function getImage(options) {
(0, import_validate.assertGetImageOptions)(options);
var nativeOptions = { format: options.format };
if (options.jpegQuality !== void 0) {
nativeOptions.jpegQuality = options.jpegQuality;
}
return native().getImage(nativeOptions).catch(import_nativeError.rethrowNativeError).then(function(result) {
return result ? {
data: result.data,
size: {
width: result.width,
height: result.height
}
} : null;
});
}
function setImage(base64Image) {
(0, import_validate.assertSetImage)(base64Image);
return native().setImage(base64Image).catch(import_nativeError.rethrowNativeError);
}
function hasImage() {
return native().hasImage().catch(import_nativeError.rethrowNativeError);
}
function getUrl() {
return native().getUrl().catch(import_nativeError.rethrowNativeError).then(function(url) {
return url !== null && url !== void 0 ? url : null;
});
}
function setUrl(url) {
(0, import_validate.assertSetUrl)(url);
return native().setUrl(url).catch(import_nativeError.rethrowNativeError);
}
function hasUrl() {
return native().hasUrl().catch(import_nativeError.rethrowNativeError);
}
var listeners = /* @__PURE__ */ new Set();
function toContentType(value) {
if (value === "plain-text" || value === "image" || value === "url" || value === "html") {
return value;
}
return null;
}
function addListener(listener) {
(0, import_validate.assertListener)(listener);
if (listeners.size === 0) {
native().setClipboardListener(function(contentTypes) {
var event = { contentTypes: contentTypes.flatMap(function(type) {
var mapped = toContentType(type);
return mapped ? [mapped] : [];
}) };
listeners.forEach(function(entry) {
return entry.callback(event);
});
});
}
var subscription = { callback: listener };
listeners.add(subscription);
var removed = false;
return { remove: function remove() {
if (removed) return;
removed = true;
listeners.delete(subscription);
if (listeners.size === 0) {
hybrid === null || hybrid === void 0 ? void 0 : hybrid.clearClipboardListener();
}
} };
}
var Clipboard = Object.freeze({
getString,
setString,
hasString,
getImage,
setImage,
hasImage,
getUrl,
setUrl,
hasUrl,
addListener
});
//# sourceMappingURL=index.native.js.map