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

@blocksuite/block-std

Package Overview
Dependencies
Maintainers
0
Versions
878
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@blocksuite/block-std - npm Package Compare versions

Comparing version 0.0.0-canary-20241019001403 to 0.0.0-canary-20241021001443

8

CHANGELOG.md
# @blocksuite/block-std
## 0.0.0-canary-20241019001403
## 0.0.0-canary-20241021001443

@@ -9,5 +9,5 @@ ### Patch Changes

- Updated dependencies
- @blocksuite/global@0.0.0-canary-20241019001403
- @blocksuite/inline@0.0.0-canary-20241019001403
- @blocksuite/store@0.0.0-canary-20241019001403
- @blocksuite/global@0.0.0-canary-20241021001443
- @blocksuite/inline@0.0.0-canary-20241021001443
- @blocksuite/store@0.0.0-canary-20241021001443

@@ -14,0 +14,0 @@ ## 0.17.19

@@ -1,4 +0,4 @@

import { type InlineRangeProvider } from '@blocksuite/inline';
import type { InlineRangeProvider } from '@blocksuite/inline';
import type { BlockComponent } from '../view/element/block-component.js';
export declare const getInlineRangeProvider: (element: BlockComponent) => InlineRangeProvider | null;
//# sourceMappingURL=inline-range-provider.d.ts.map

@@ -1,5 +0,2 @@

import { BlockSuiteError, ErrorCode } from '@blocksuite/global/exceptions';
import { INLINE_ROOT_ATTR, } from '@blocksuite/inline';
import { signal } from '@preact/signals-core';
import { BLOCK_ID_ATTR } from '../view/index.js';
export const getInlineRangeProvider = element => {

@@ -12,26 +9,3 @@ const editorHost = element.host;

}
const isElementSelected = (range) => {
// Most cases, the range is collapsed, so we no need to use `intersectsNode`
// because its performance is not good enough.
if (range.collapsed) {
const startElement = range.startContainer instanceof Element
? range.startContainer
: range.startContainer.parentElement;
const inlineRoot = startElement?.closest(`[${INLINE_ROOT_ATTR}]`);
if (!inlineRoot)
return false;
const block = startElement?.closest(`[${BLOCK_ID_ATTR}]`);
if (!block || block !== element)
return false;
}
else {
if (!range.intersectsNode(element))
return false;
}
return true;
};
const calculateInlineRange = (range, textSelection) => {
if (!isElementSelected(range)) {
return null;
}
const { from, to } = textSelection;

@@ -51,8 +25,21 @@ if (from.blockId === element.blockId) {

if (!element.model.text) {
throw new BlockSuiteError(ErrorCode.SelectionError, 'element to set text selection has no text');
return null;
}
return {
index: 0,
length: element.model.text.length,
};
const elementRange = rangeManager.textSelectionToRange(selectionManager.create('text', {
from: {
index: 0,
blockId: element.blockId,
length: element.model.text.length,
},
to: null,
}));
if (elementRange &&
elementRange.compareBoundaryPoints(Range.START_TO_START, range) > -1 &&
elementRange.compareBoundaryPoints(Range.END_TO_END, range) < 1) {
return {
index: 0,
length: element.model.text.length,
};
}
return null;
};

@@ -59,0 +46,0 @@ const setInlineRange = (inlineRange) => {

{
"name": "@blocksuite/block-std",
"version": "0.0.0-canary-20241019001403",
"version": "0.0.0-canary-20241021001443",
"description": "Std for blocksuite blocks",

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

"dependencies": {
"@blocksuite/global": "0.0.0-canary-20241019001403",
"@blocksuite/inline": "0.0.0-canary-20241019001403",
"@blocksuite/store": "0.0.0-canary-20241019001403",
"@blocksuite/global": "0.0.0-canary-20241021001443",
"@blocksuite/inline": "0.0.0-canary-20241021001443",
"@blocksuite/store": "0.0.0-canary-20241021001443",
"@lit/context": "^1.1.2",

@@ -28,0 +28,0 @@ "@preact/signals-core": "^1.8.0",

@@ -1,7 +0,3 @@

import { BlockSuiteError, ErrorCode } from '@blocksuite/global/exceptions';
import {
INLINE_ROOT_ATTR,
type InlineRange,
type InlineRangeProvider,
} from '@blocksuite/inline';
import type { InlineRange, InlineRangeProvider } from '@blocksuite/inline';
import { signal } from '@preact/signals-core';

@@ -12,4 +8,2 @@

import { BLOCK_ID_ATTR } from '../view/index.js';
export const getInlineRangeProvider: (

@@ -26,21 +20,2 @@ element: BlockComponent

const isElementSelected = (range: Range): boolean => {
// Most cases, the range is collapsed, so we no need to use `intersectsNode`
// because its performance is not good enough.
if (range.collapsed) {
const startElement =
range.startContainer instanceof Element
? range.startContainer
: range.startContainer.parentElement;
const inlineRoot = startElement?.closest(`[${INLINE_ROOT_ATTR}]`);
if (!inlineRoot) return false;
const block = startElement?.closest(`[${BLOCK_ID_ATTR}]`);
if (!block || block !== element) return false;
} else {
if (!range.intersectsNode(element)) return false;
}
return true;
};
const calculateInlineRange = (

@@ -50,6 +25,2 @@ range: Range,

): InlineRange | null => {
if (!isElementSelected(range)) {
return null;
}
const { from, to } = textSelection;

@@ -72,12 +43,28 @@

if (!element.model.text) {
throw new BlockSuiteError(
ErrorCode.SelectionError,
'element to set text selection has no text'
);
return null;
}
return {
index: 0,
length: element.model.text.length,
};
const elementRange = rangeManager.textSelectionToRange(
selectionManager.create('text', {
from: {
index: 0,
blockId: element.blockId,
length: element.model.text.length,
},
to: null,
})
);
if (
elementRange &&
elementRange.compareBoundaryPoints(Range.START_TO_START, range) > -1 &&
elementRange.compareBoundaryPoints(Range.END_TO_END, range) < 1
) {
return {
index: 0,
length: element.model.text.length,
};
}
return null;
};

@@ -84,0 +71,0 @@

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