@zag-js/text-selection
Advanced tools
Comparing version 0.0.1 to 0.8.0
@@ -1,10 +0,11 @@ | ||
declare function disableTextSelection({ target, doc }?: { | ||
target?: HTMLElement; | ||
type DisableTextSelectionOptions<T = MaybeElement> = { | ||
target?: T; | ||
doc?: Document; | ||
}): () => void; | ||
declare function restoreTextSelection({ target, doc }?: { | ||
target?: HTMLElement; | ||
doc?: Document; | ||
}): void; | ||
defer?: boolean; | ||
}; | ||
declare function restoreTextSelection(options?: DisableTextSelectionOptions): void; | ||
type MaybeElement = HTMLElement | null | undefined; | ||
type NodeOrFn = MaybeElement | (() => MaybeElement); | ||
declare function disableTextSelection(options?: DisableTextSelectionOptions<NodeOrFn>): () => void; | ||
export { disableTextSelection, restoreTextSelection }; | ||
export { DisableTextSelectionOptions, disableTextSelection, restoreTextSelection }; |
@@ -27,20 +27,11 @@ "use strict"; | ||
module.exports = __toCommonJS(src_exports); | ||
var import_dom_query = require("@zag-js/dom-query"); | ||
var state = "default"; | ||
var userSelect = ""; | ||
var elementMap = /* @__PURE__ */ new WeakMap(); | ||
var isIos = () => { | ||
const userAgent = navigator.userAgent.toLowerCase(); | ||
return /iphone|ipad|ipod/.test(userAgent); | ||
}; | ||
var nextTick = (fn) => { | ||
requestAnimationFrame(() => { | ||
requestAnimationFrame(() => { | ||
fn(); | ||
}); | ||
}); | ||
}; | ||
function disableTextSelection({ target, doc } = {}) { | ||
const _document = doc ?? document; | ||
const rootEl = _document.documentElement; | ||
if (isIos()) { | ||
function disableTextSelectionImpl(options = {}) { | ||
const { target, doc } = options; | ||
const docNode = doc ?? document; | ||
const rootEl = docNode.documentElement; | ||
if ((0, import_dom_query.isIos)()) { | ||
if (state === "default") { | ||
@@ -55,8 +46,9 @@ userSelect = rootEl.style.webkitUserSelect; | ||
} | ||
return () => restoreTextSelection({ target, doc: _document }); | ||
return () => restoreTextSelection({ target, doc: docNode }); | ||
} | ||
function restoreTextSelection({ target, doc } = {}) { | ||
const _document = doc ?? document; | ||
const rootEl = _document.documentElement; | ||
if (isIos()) { | ||
function restoreTextSelection(options = {}) { | ||
const { target, doc } = options; | ||
const docNode = doc ?? document; | ||
const rootEl = docNode.documentElement; | ||
if ((0, import_dom_query.isIos)()) { | ||
if (state !== "disabled") | ||
@@ -66,3 +58,3 @@ return; | ||
setTimeout(() => { | ||
nextTick(() => { | ||
(0, import_dom_query.nextTick)(() => { | ||
if (state === "restoring") { | ||
@@ -90,2 +82,16 @@ if (rootEl.style.webkitUserSelect === "none") { | ||
} | ||
function disableTextSelection(options = {}) { | ||
const { defer, target, ...restOptions } = options; | ||
const func = defer ? import_dom_query.raf : (v) => v(); | ||
const cleanups = []; | ||
cleanups.push( | ||
func(() => { | ||
const node = typeof target === "function" ? target() : target; | ||
cleanups.push(disableTextSelectionImpl({ ...restOptions, target: node })); | ||
}) | ||
); | ||
return () => { | ||
cleanups.forEach((fn) => fn?.()); | ||
}; | ||
} | ||
// Annotate the CommonJS export names for ESM import in node: | ||
@@ -92,0 +98,0 @@ 0 && (module.exports = { |
{ | ||
"name": "@zag-js/text-selection", | ||
"version": "0.0.1", | ||
"version": "0.8.0", | ||
"description": "", | ||
@@ -29,2 +29,5 @@ "keywords": [ | ||
}, | ||
"dependencies": { | ||
"@zag-js/dom-query": "0.1.4" | ||
}, | ||
"module": "dist/index.mjs", | ||
@@ -31,0 +34,0 @@ "types": "dist/index.d.ts", |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
8594
177
1
+ Added@zag-js/dom-query@0.1.4
+ Added@zag-js/dom-query@0.1.4(transitive)