@searsuite/sear-foundation-common
Small dependency-free values and contracts shared across SearSuite packages.
- enumBuildInStateName
-
Enumeration of built-in state names in the Sear framework.
These state names are reserved and used internally by the Sear document editing system to manage the core data structures and visual representations.
State Types:
- CORE_STATE: The fundamental state managing document structure and content
- COLUMN_SHAPE_STATE: State tracking column dimensions and visual properties
- ROW_SHAPE_STATE: State tracking row dimensions and visual properties
These are typically used as keys in the state management system to ensure that core states don't conflict with user-defined or plugin-defined states.
enum member COLUMN_SHAPE_STATE: "COLUMN_SHAPE_STATE"State managing column dimensions and visual shape properties
enum member CORE_STATE: "CORE_STATE"Core state managing the fundamental document structure and content
enum member ROW_SHAPE_STATE: "ROW_SHAPE_STATE"State managing row dimensions and visual shape properties
- enumSearDocumentType
-
Enumeration of supported document types in the Sear suite.
The Sear suite is a comprehensive document editing and collaboration platform that supports multiple document formats, each with specific features and use cases.
Supported Types:
- UNKNOWN: Undefined or unrecognized document type
- SEAR_DOC: General-purpose text document (word processor)
- SEAR_SHEET: Spreadsheet with cells, formulas, and data analysis
- SEAR_TABLE: Structured table for tabular data presentation
- SEAR_SLIDE: Presentation slides for visual content delivery
- SEAR_MIND: Mind mapping document for brainstorming and organizing ideas
- SEAR_FLOW: Flowchart and diagram editor for process visualization
enum member SEAR_DOC: 1General document type (text processor)
enum member SEAR_FLOW: 6Flowchart and diagram document type
enum member SEAR_MIND: 5Mind map document type for hierarchical visualization
enum member SEAR_SHEET: 2Spreadsheet document type with cell-based data
enum member SEAR_SLIDE: 4Slide presentation document type
enum member SEAR_TABLE: 3Table document type for structured tabular data
enum member UNKNOWN: 0Unknown or unspecified document type
- classQuadTree
-
class QuadTree<T>High-level QuadTree interface for spatial data management.
This class provides a user-friendly API for working with quadtrees. It maintains a root node and delegates all operations to it.
Typical use cases:
- 2D game collision detection (broad phase)
- Spatial database indexing
- Rectangle packing and overlap queries
- Geographic information systems (GIS) spatial queries
constructor QuadTree<T>(rootNode: IQuadTreeNode<T>): QuadTree<T>Creates a new QuadTree instance with a specified root node.
rootNodeThe root node defining the initial boundary and capacity. Typically created as: new QuadTreeNode({ x: 0, y: 0, width: 800, height: 600 }, 4)
property root: IQuadTreeNode<T>The root node of the quadtree.
method insert(point: Point, value: T): booleanInserts a new point and associated value into the quadtree.
Returnstrue if insertion succeeded, false if point is outside the tree's boundary.
pointThe 2D coordinates where the value should be stored.
valueThe data to associate with this point.
method query(range: { height: number; width: number; x: number; y: number }): NodeData<T>[]Queries all values within a rectangular range.
ReturnsArray of all data entries found within the range.
rangeThe query rectangle (x, y, width, height).
method remove(point: Point): booleanRemoves a point and its associated value from the quadtree.
Returnstrue if point was found and removed, false if not found.
pointThe exact coordinates of the point to remove.
- classQuadTreeNode
-
class QuadTreeNode<T> extends IQuadTreeNode<T>Implementation of a QuadTree node for efficient 2D spatial partitioning.
A QuadTree divides a 2D space into four quadrants recursively, enabling fast spatial queries. This implementation is particularly useful for:
- Range queries on 2D data
- Collision detection in graphics/gaming
- Spatial indexing in databases
- Performance optimization for large datasets
The tree automatically subdivides nodes when they exceed capacity, creating a balanced spatial structure. Each node can hold up to 'capacity' points before subdividing into four child nodes (northeast, northwest, southeast, southwest).
constructor QuadTreeNode<T>(boundary: { height: number; width: number; x: number; y: number }, capacity: number): QuadTreeNode<T>Creates a new QuadTree node with specified boundary and capacity.
boundaryThe rectangular area this node covers.
capacityMaximum points before node subdivides (typically 4).
property boundary: { height: number; width: number; x: number; y: number }The rectangular boundary of this node in 2D space.
property capacity: numberMaximum number of points this node can hold before subdividing.
property divided: booleanFlag indicating whether this node has been subdivided into children.
property northeast: IQuadTreeNode<T> | nullNortheast child node (upper-right quadrant).
property northwest: IQuadTreeNode<T> | nullNorthwest child node (upper-left quadrant).
property points: NodeData<T>[]Array of data points stored in this node (before subdivision).
property southeast: IQuadTreeNode<T> | nullSoutheast child node (lower-right quadrant).
property southwest: IQuadTreeNode<T> | nullSouthwest child node (lower-left quadrant).
method contains(boundary: { height: number; width: number; x: number; y: number }, point: Point): booleanChecks if a point is contained within a rectangular boundary. Uses inclusive lower bound and exclusive upper bound for consistency.
Returnstrue if the point is within the boundary (x1 <= x < x2, y1 <= y < y2).
boundaryThe rectangle to check against.
pointThe point to test.
method insert(data: NodeData<T>): booleanInserts a data entry into the quadtree. The insertion process:
- Checks if the point is within this node's boundary
- If node has capacity, adds point directly
- If node is full, subdivides and recursively inserts into children
This ensures the tree grows in a balanced manner, with points distributed across quadrants as the tree expands.
Returnstrue if insertion succeeded, false if point is outside boundary.
dataThe point and value to insert.
method intersects(a: { height: number; width: number; x: number; y: number }, b: { height: number; width: number; x: number; y: number }): booleanChecks if two rectangles intersect (have any overlapping area). Uses the separating axis theorem for AABB (Axis-Aligned Bounding Box) collision.
Two rectangles do NOT intersect if:
- Rectangle A is completely to the right of B
- Rectangle A is completely to the left of B
- Rectangle A is completely below B
- Rectangle A is completely above B
Returnstrue if the rectangles intersect, false otherwise.
aFirst rectangle.
bSecond rectangle.
method query(range: { height: number; width: number; x: number; y: number }, found?: NodeData<T>[]): NodeData<T>[]Finds all data entries within a given rectangular range. This is the primary query operation for spatial lookups.
The query process:
- Checks if the query range intersects with this node's boundary
- If no intersection, skips this node and its children
- If intersection, checks all points in this node
- Recursively queries child nodes if subdivided
This approach provides O(log N) average performance for sparse data.
ReturnsArray of all data entries found within the range.
rangeThe rectangular area to query.
foundAccumulator array (for recursion, default empty array).
method remove(point: Point): booleanRemoves a data entry at the specified point coordinates.
The removal process:
- Checks if point is within this node's boundary
- Searches and removes the point from this node's points array
- If not found, recursively searches child nodes
Note: This operation does not trigger node merging after removal, so the tree structure may become unbalanced over time with many removals.
Returnstrue if point was found and removed, false if not found.
pointThe exact coordinates of the point to remove.
method subdivide(): voidSubdivides this node into four equal child nodes (quadrants). Called when the node reaches capacity and needs to distribute points to child nodes for better spatial organization.
The subdivision creates four equal rectangles:
- Northeast (NE): upper-right
- Northwest (NW): upper-left
- Southeast (SE): lower-right
- Southwest (SW): lower-left
- classSearKey
-
SearKey class for generating unique identifiers within the Sear framework.
This class is primarily used for plugin identification and namespace management in the Sear document editing system. Each instance receives a uniquely generated key that prevents naming collisions even when multiple plugins with the same base name are loaded.
Use cases:
- Plugin identification: Each plugin instance gets a unique key for internal references
- State management: Creating unique state keys for different plugin instances
- Event system: Identifying event listeners and handlers from different sources
- Namespace isolation: Preventing key collisions in shared state objects
Exampleconst key1 = new SearKey('plugin'); // Returns key='plugin#39; const key2 = new SearKey('plugin'); // Returns key='plugin$1' const key3 = new SearKey('plugin'); // Returns key='plugin$2' const key4 = new SearKey('state'); // Returns key='state#39;constructor SearKey(key?: string): SearKeyCreates a new SearKey instance with a unique identifier.
keyThe base name for this key (default: 'plugin'). Should be descriptive and represent the purpose of this key.
property key: stringThe unique key string generated for this instance. Format: '{baseName}#39; for the first instance, '{baseName}${count}' for subsequent ones.
- functionprintNameAndVersion
-
printNameAndVersion(name: string, version: string): voidExports the console logging utility for displaying plugin name and version.
Exampleimport { printNameAndVersion } from '@searsuite/sear-foundation-common';\n * // Display plugin info on initialization printNameAndVersion('SearEditor', '1.2.3'); // Console output: \" SearEditor v1.2.3 \" with stylingnameThe name of the plugin or component (e.g., 'sear-editor', 'sear-table')
versionThe version string of the plugin (e.g., '1.0.0', '2.1.5-beta')
- variableCommandExecutionPhase
-
CommandExecutionPhase: { Completed: "completed"; Failed: "failed"; Started: "started" }Stable lifecycle phases emitted by Sheet, Doc, and Workbook command buses.
No matching API entries.