Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions .oxlintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
],
"categories": {},
"rules": {
"import/no-cycle": "warn",
"import/no-cycle": "error",
"import/no-duplicates": "error",
"import/no-extraneous-dependencies": "error",
"import/no-unresolved": "error",
Expand Down Expand Up @@ -98,6 +98,7 @@
"typescript/no-wrapper-object-types": "warn",
"typescript/prefer-as-const": "warn",
"typescript/triple-slash-reference": "warn",
"typescript/consistent-type-imports": "error",
"unicorn/no-await-in-promise-methods": "warn",
"unicorn/no-empty-file": "warn",
"unicorn/no-invalid-fetch-options": "warn",
Expand All @@ -110,7 +111,10 @@
"unicorn/no-useless-length-check": "warn",
"unicorn/no-useless-spread": "warn",
"unicorn/prefer-set-size": "warn",
"unicorn/prefer-string-starts-ends-with": "warn"
"unicorn/prefer-string-starts-ends-with": "warn",
"jest/valid-expect": "off",
"react/exhaustive-deps": "off",
"jsx_a11y/click-events-have-key-events": "off"
},
"settings": {
"jsx-a11y": {
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/features/caret/TriggerFinder.spec.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import {afterEach, beforeEach, describe, expect, it, vi} from 'vitest'
import {TriggerFinder} from './TriggerFinder'
import {Caret} from './Caret'
import {Markup} from '../parsing/ParserV2/types'
import type {Markup} from '../parsing/ParserV2/types'

// Mock DOM
const mockCreateTextNode = vi.fn(
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/features/caret/TriggerFinder.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import {Caret} from './Caret'
import {OverlayMatch} from '../../shared/types'
import type {OverlayMatch} from '../../shared/types'
import {escape} from '../../shared/escape'

/** Regex to match word characters from the start of a string */
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/features/events/EventBus.spec.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import {beforeEach, describe, expect, it, vi} from 'vitest'
import {EventBus} from '.'
import {EventKey} from '../../shared/types'
import type {EventKey} from '../../shared/types'

describe(`Utility: ${EventBus.name}`, () => {
let eventBus: EventBus
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/features/events/EventBus.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {EventKey, Listener} from '../../shared/types'
import type {EventKey, Listener} from '../../shared/types'

export class EventBus {
readonly #SystemEvents = new Map<EventKey<any>, Set<Listener>>()
Expand Down
4 changes: 2 additions & 2 deletions packages/core/src/features/events/constants.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import {Token} from '../parsing/ParserV2/types'
import {EventKey, OverlayMatch} from '../../shared/types'
import type {Token} from '../parsing/ParserV2/types'
import type {EventKey, OverlayMatch} from '../../shared/types'

export const SystemEvent = {
STORE_UPDATED: Symbol() as EventKey,
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/features/parsing/ParserV2/Parser.spec.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import {beforeEach, describe, expect, it} from 'vitest'
import {Parser} from './Parser'
import {MarkToken, Markup, Token} from './types'
import type {MarkToken, Markup, Token} from './types'
import {faker} from '@faker-js/faker'

describe('ParserV2', () => {
Expand Down
4 changes: 2 additions & 2 deletions packages/core/src/features/parsing/ParserV2/Parser.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import {Markup, Token, MarkToken} from './types'
import type {Markup, Token, MarkToken} from './types'
import {MarkupRegistry} from './core/MarkupRegistry'
import {PatternMatcher} from './core/PatternMatcher'
import {SegmentMatcher} from './core/SegmentMatcher'
import {createTextToken} from './utils/createTextToken'
import {TreeBuilder} from './core/TreeBuilder'
import {toString as tokensToString} from './utils/toString'
import {processTokensWithCallback} from './utils/denote'
import {processTokensWithCallback} from './utils/processTokens'

/**
* Parser - High-performance tree-based markup parser
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import {GAP_TYPE, GapType, PLACEHOLDER} from '../constants'
import {Markup} from '../types'
import {SegmentDefinition} from './SegmentMatcher'
import type {GapType} from '../constants'
import {GAP_TYPE, PLACEHOLDER} from '../constants'
import type {Markup} from '../types'
import type {SegmentDefinition} from './SegmentMatcher'

/**
* Descriptor for segment-based markup parsing
Expand Down Expand Up @@ -53,7 +54,7 @@ export function createMarkupDescriptor(markup: Markup, index: number): MarkupDes
gapTypes,
hasNested: counts.nested === 1,
hasTwoValues,
segmentGlobalIndices: new Array(segments.length), // Will be populated by MarkupRegistry
segmentGlobalIndices: Array.from({length: segments.length}), // Will be populated by MarkupRegistry
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import {Markup} from '../types'
import {MarkupDescriptor, createMarkupDescriptor} from '../core/MarkupDescriptor'
import {SegmentDefinition} from './SegmentMatcher'
import type {Markup} from '../types'
import type {MarkupDescriptor} from '../core/MarkupDescriptor'
import {createMarkupDescriptor} from '../core/MarkupDescriptor'
import type {SegmentDefinition} from './SegmentMatcher'

/**
* Registry for managing markup descriptors
Expand Down
8 changes: 4 additions & 4 deletions packages/core/src/features/parsing/ParserV2/core/Match.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import {GapType} from '../constants'
import {PositionRange} from '../types'
import {SegmentMatch} from './SegmentMatcher'
import {MarkupDescriptor} from './MarkupDescriptor'
import type {GapType} from '../constants'
import type {PositionRange} from '../types'
import type {SegmentMatch} from './SegmentMatcher'
import type {MarkupDescriptor} from './MarkupDescriptor'
import {getSegmentIndex} from '../utils/getSegmentIndex'

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
* - Gap position management for nested content extraction
*/

import {MarkupRegistry} from './MarkupRegistry'
import {SegmentMatch} from './SegmentMatcher'
import type {MarkupRegistry} from './MarkupRegistry'
import type {SegmentMatch} from './SegmentMatcher'
import {Match} from './Match'
import {getSegmentIndex} from '../utils/getSegmentIndex'
import type {MarkupDescriptor} from './MarkupDescriptor'
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import {describe, expect, it} from 'vitest'
import {SegmentDefinition, SegmentMatcher} from './SegmentMatcher'
import type {SegmentDefinition} from './SegmentMatcher'
import {SegmentMatcher} from './SegmentMatcher'
import {MarkupRegistry} from './MarkupRegistry'
import {Markup} from '../types'
import type {Markup} from '../types'

describe('SegmentMatcher', () => {
describe('static segments', () => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import {MarkToken, PositionRange, TextToken, Token} from '../types'
import {Match} from './Match'
import type {MarkToken, PositionRange, TextToken, Token} from '../types'
import type {Match} from './Match'
import {createTextToken} from '../utils/createTextToken'

/**
Expand Down
4 changes: 2 additions & 2 deletions packages/core/src/features/parsing/ParserV2/types.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import {PLACEHOLDER} from './constants'
import {MarkupDescriptor} from './core/MarkupDescriptor'
import type {PLACEHOLDER} from './constants'
import type {MarkupDescriptor} from './core/MarkupDescriptor'

export type Token = TextToken | MarkToken

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import {describe, expect, it} from 'vitest'
import {Markup} from '../types'
import type {Markup} from '../types'
import {annotate} from './annotate'

describe(`Utility: ${annotate.name}`, () => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import {PLACEHOLDER} from '../constants'
import {Markup} from '../types'
import type {Markup} from '../types'

/**
* Make annotation from the markup for ParserV2
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {TextToken} from '../types'
import type {TextToken} from '../types'

/**
* Creates a text token for a range in the input
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import {describe, expect, it} from 'vitest'
import {Markup} from '../types'
import type {Markup} from '../types'
import {denote} from './denote'

describe('Utility: denote', () => {
Expand Down
38 changes: 2 additions & 36 deletions packages/core/src/features/parsing/ParserV2/utils/denote.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import {Parser} from '../Parser'
import {MarkToken, Markup, Token} from '../types'
import type {MarkToken, Markup} from '../types'
import {processTokensWithCallback} from './processTokens'

/**
* Transform annotated text to another text by recursively processing all tokens
Expand All @@ -23,38 +24,3 @@ export function denote(value: string, callback: (mark: MarkToken) => string, mar

return processTokensWithCallback(tokens, callback)
}

/**
* Internal function to process tokens with a callback
* @param tokens - Tokens to process
* @param callback - Function to transform each MarkToken
* @returns Transformed text
*/
export function processTokensWithCallback(tokens: Token[], callback: (mark: MarkToken) => string): string {
let result = ''
for (const token of tokens) {
if (token.type === 'text') {
result += token.content
} else {
// For MarkToken with children, we need to decide:
// - If we want to transform the mark itself AND its children
// - Or transform children and include them in the mark's transformation

if (token.children.length > 0) {
// Recursively process children to get their transformed content
const processedChildren = processTokensWithCallback(token.children, callback)

// Create a modified token with processed children as the value
// This allows the callback to use the already-processed nested content
const modifiedToken: MarkToken = {
...token,
value: processedChildren,
}
result += callback(modifiedToken)
} else {
result += callback(token)
}
}
}
return result
}
36 changes: 36 additions & 0 deletions packages/core/src/features/parsing/ParserV2/utils/processTokens.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import type {MarkToken, Token} from '../types'

/**
* Internal function to process tokens with a callback
* @param tokens - Tokens to process
* @param callback - Function to transform each MarkToken
* @returns Transformed text
*/
export function processTokensWithCallback(tokens: Token[], callback: (mark: MarkToken) => string): string {
let result = ''
for (const token of tokens) {
if (token.type === 'text') {
result += token.content
} else {
// For MarkToken with children, we need to decide:
// - If we want to transform the mark itself AND its children
// - Or transform children and include them in the mark's transformation

if (token.children.length > 0) {
// Recursively process children to get their transformed content
const processedChildren = processTokensWithCallback(token.children, callback)

// Create a modified token with processed children as the value
// This allows the callback to use the already-processed nested content
const modifiedToken: MarkToken = {
...token,
value: processedChildren,
}
result += callback(modifiedToken)
} else {
result += callback(token)
}
}
}
return result
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import {describe, expect, it} from 'vitest'
import {Markup} from '../types'
import type {Markup} from '../types'
import {toString} from './toString'
import {Parser} from '../Parser'

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {Token} from '../types'
import type {Token} from '../types'
import {PLACEHOLDER} from '../constants'
import {annotate} from './annotate'

Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/features/parsing/parser.profile.bench.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import {afterAll, bench, describe} from 'vitest'
import {Parser} from './ParserV2/Parser'
import {Markup, Token} from './ParserV2/types'
import type {Markup, Token} from './ParserV2/types'
import * as fs from 'fs'
import * as path from 'path'

Expand Down
6 changes: 3 additions & 3 deletions packages/core/src/features/store/Store.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import {NodeProxy} from '../../shared/classes/NodeProxy'
import {Token} from '../parsing/ParserV2/types'
import {OverlayMatch, Recovery, CoreMarkputProps} from '../../shared/types'
import type {Token} from '../parsing/ParserV2/types'
import type {OverlayMatch, Recovery, CoreMarkputProps} from '../../shared/types'
import {EventBus, SystemEvent} from '../events'
import {KeyGenerator} from '../../shared/classes/KeyGenerator'
import {Parser} from '../parsing/ParserV2/Parser'
import type {Parser} from '../parsing/ParserV2/Parser'

export class Store<TProps extends CoreMarkputProps = CoreMarkputProps> {
// Utils domain
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {Store} from '../../store'
import type {Store} from '../../store'
import {toString} from '../../parsing'

export function deleteMark(place: 'prev' | 'self' | 'next', store: Store) {
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/shared/classes/NodeProxy.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {Store} from '../../features/store'
import type {Store} from '../../features/store'
import {Caret} from '../../features/caret'

export class NodeProxy {
Expand Down
4 changes: 2 additions & 2 deletions packages/core/src/shared/types.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {NodeProxy} from './classes/NodeProxy'
import type {NodeProxy} from './classes/NodeProxy'
import type {Markup} from '../features/parsing/ParserV2/types'

/**
Expand Down Expand Up @@ -83,7 +83,7 @@ export type OverlayMatch<TOption = CoreOption> = {

export type Listener<T = any> = (e: T) => void

// eslint-disable-next-line @typescript-eslint/no-unused-vars
// eslint-disable-next-line @typescript-eslint/no-unused-vars, oxlint-disable-next-line no-wrapper-object-types
export interface EventKey<T = any> extends Symbol {}

export type Recovery = {
Expand Down
2 changes: 1 addition & 1 deletion packages/markput/src/components/EditableSpan.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {ClipboardEvent} from 'react'
import type {ClipboardEvent} from 'react'
import {resolveSlot, resolveSlotProps} from '../utils/functions/resolveSlot'
import {useMark} from '../utils/hooks/useMark'
import {useStore} from '../utils/hooks/useStore'
Expand Down
4 changes: 2 additions & 2 deletions packages/markput/src/components/Featurer.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {ForwardedRef} from 'react'
import type {ForwardedRef} from 'react'
import {useCloseOverlayByEsc} from '../features/events/useCloseOverlayByEsc'
import {useCloseOverlayByOutsideClick} from '../features/events/useCloseOverlayByOutsideClick'
import {useKeyDown} from '../features/events/useKeyDown'
Expand All @@ -11,7 +11,7 @@ import {useCheckTrigger} from '../features/overlay/useCheckTrigger'
import {useTrigger} from '../features/overlay/useTrigger'
import {useValueParser} from '../features/parsing/useValueParser'
import {useMarkedInputHandler} from '../features/useMarkedInputHandler'
import {MarkedInputHandler} from '../types'
import type {MarkedInputHandler} from '../types'

export const Featurer = ({inRef}: {inRef: ForwardedRef<MarkedInputHandler>}) => {
useMarkedInputHandler(inRef)
Expand Down
7 changes: 4 additions & 3 deletions packages/markput/src/components/MarkedInput.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import {CSSProperties, ComponentType, ForwardedRef, forwardRef} from 'react'
import type {CSSProperties, ComponentType, ForwardedRef} from 'react'
import {forwardRef} from 'react'
import '@markput/core/styles.css'
import {MarkedInputHandler, Option, Slots, SlotProps, OverlayProps, MarkProps} from '../types'
import type {MarkedInputHandler, Option, Slots, SlotProps, OverlayProps, MarkProps} from '../types'
import {Container} from './Container'
import {Featurer} from './Featurer'
import {StoreProvider} from './StoreProvider'
import {Whisper} from './Whisper'
import {CoreMarkputProps, OverlayTrigger} from '@markput/core'
import type {CoreMarkputProps, OverlayTrigger} from '@markput/core'

/**
* Props for MarkedInput component with hierarchical type support.
Expand Down
3 changes: 2 additions & 1 deletion packages/markput/src/components/Piece.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import {ReactNode} from 'react'
import type {ReactNode} from 'react'
import {useStore} from '../utils/hooks/useStore'
import {useSlot} from '../utils/hooks/useSlot'
import {useToken} from '../utils/providers/TokenProvider'
// eslint-disable-next-line import/no-cycle -- Legitimate recursive component relationship: Token renders Piece, Piece renders Token for children
import {Token} from './Token'
import type {MarkProps} from '../types'

Expand Down
5 changes: 3 additions & 2 deletions packages/markput/src/components/StoreProvider.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import {ReactNode, useEffect, useState} from 'react'
import type {ReactNode} from 'react'
import {useEffect, useState} from 'react'
import {Store, DEFAULT_CLASS_NAME} from '@markput/core'
import {MarkedInputProps} from './MarkedInput'
import type {MarkedInputProps} from './MarkedInput'
import {StoreContext} from '../utils/providers/StoreContext'
import {mergeClassNames, mergeStyles} from '../utils/functions/resolveSlot'
import {DEFAULT_OPTIONS} from '../constants'
Expand Down
Loading