Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@blocksuite/global

Package Overview
Dependencies
Maintainers
5
Versions
1141
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@blocksuite/global - npm Package Compare versions

Comparing version 0.4.0-20230203234453-6122cfe to 0.4.0-20230204233304-6e37e29

33

dist/utils/web.js
export const isWeb = typeof window !== 'undefined';
export const isFirefox = isWeb && navigator.userAgent.toLowerCase().indexOf('firefox') > -1;
const withHidePopup = (fn) => {
const map = new Map();
const formatBar = document.querySelector('format-quick-bar');
if (formatBar) {
map.set(formatBar, formatBar.style.visibility);
formatBar.style.visibility = 'hidden';
}
try {
return fn();
}
finally {
// recover
map.forEach((visibility, node) => {
node.style.visibility = visibility;
});
}
};
export function caretRangeFromPoint(clientX, clientY) {
if (isFirefox) {
const caret = document.caretPositionFromPoint(clientX, clientY);
// TODO handle caret is covered by popup
const range = document.createRange();

@@ -10,4 +28,17 @@ range.setStart(caret.offsetNode, caret.offset);

}
return document.caretRangeFromPoint(clientX, clientY);
const range = document.caretRangeFromPoint(clientX, clientY);
if (!range) {
return null;
}
// This is a workaround
// Sometimes the point be covered by the format bar,
// so the range will return the body element,
// which is not what we want.
if (range.startContainer === document.body &&
range.endContainer === document.body) {
const retryRange = withHidePopup(() => document.caretRangeFromPoint(clientX, clientY));
return retryRange;
}
return range;
}
//# sourceMappingURL=web.js.map

2

package.json
{
"name": "@blocksuite/global",
"version": "0.4.0-20230203234453-6122cfe",
"version": "0.4.0-20230204233304-6e37e29",
"types": "./index.d.ts",

@@ -5,0 +5,0 @@ "type": "module",

@@ -17,2 +17,19 @@ export const isWeb = typeof window !== 'undefined';

const withHidePopup = <T>(fn: () => T): T => {
const map = new Map<HTMLElement, string>();
const formatBar = document.querySelector<HTMLElement>('format-quick-bar');
if (formatBar) {
map.set(formatBar, formatBar.style.visibility);
formatBar.style.visibility = 'hidden';
}
try {
return fn();
} finally {
// recover
map.forEach((visibility, node) => {
node.style.visibility = visibility;
});
}
};
export function caretRangeFromPoint(

@@ -24,2 +41,3 @@ clientX: number,

const caret = document.caretPositionFromPoint(clientX, clientY);
// TODO handle caret is covered by popup
const range = document.createRange();

@@ -29,3 +47,20 @@ range.setStart(caret.offsetNode, caret.offset);

}
return document.caretRangeFromPoint(clientX, clientY);
const range = document.caretRangeFromPoint(clientX, clientY);
if (!range) {
return null;
}
// This is a workaround
// Sometimes the point be covered by the format bar,
// so the range will return the body element,
// which is not what we want.
if (
range.startContainer === document.body &&
range.endContainer === document.body
) {
const retryRange = withHidePopup(() =>
document.caretRangeFromPoint(clientX, clientY)
);
return retryRange;
}
return range;
}

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc