Re-declare public API's enums
This commit is contained in:
parent
edac74e1a7
commit
eadc58eeaa
2 changed files with 27 additions and 17 deletions
2
reconcile-js/package-lock.json
generated
2
reconcile-js/package-lock.json
generated
|
|
@ -24,7 +24,7 @@
|
||||||
},
|
},
|
||||||
"../pkg": {
|
"../pkg": {
|
||||||
"name": "reconcile-text",
|
"name": "reconcile-text",
|
||||||
"version": "0.4.9",
|
"version": "0.4.10",
|
||||||
"dev": true,
|
"dev": true,
|
||||||
"license": "MIT"
|
"license": "MIT"
|
||||||
},
|
},
|
||||||
|
|
|
||||||
|
|
@ -3,17 +3,36 @@ import {
|
||||||
reconcile as wasmReconcile,
|
reconcile as wasmReconcile,
|
||||||
TextWithCursors as wasmTextWithCursors,
|
TextWithCursors as wasmTextWithCursors,
|
||||||
SpanWithHistory as wasmSpanWithHistory,
|
SpanWithHistory as wasmSpanWithHistory,
|
||||||
BuiltinTokenizer,
|
|
||||||
reconcileWithHistory as wasmReconcileWithHistory,
|
reconcileWithHistory as wasmReconcileWithHistory,
|
||||||
isBinary as wasmIsBinary,
|
isBinary as wasmIsBinary,
|
||||||
History,
|
|
||||||
initSync,
|
initSync,
|
||||||
} from 'reconcile-text';
|
} from 'reconcile-text';
|
||||||
|
|
||||||
import wasmBytes from 'reconcile-text/reconcile_text_bg.wasm';
|
import wasmBytes from 'reconcile-text/reconcile_text_bg.wasm';
|
||||||
|
|
||||||
// Re-export types from the WASM module as these are part of our API
|
// Define the enum values as const arrays to avoid duplication
|
||||||
export { History, BuiltinTokenizer };
|
const BUILTIN_TOKENIZERS = ['Character', 'Line', 'Word'] as const;
|
||||||
|
const HISTORY_VALUES = [
|
||||||
|
'Unchanged',
|
||||||
|
'AddedFromLeft',
|
||||||
|
'AddedFromRight',
|
||||||
|
'RemovedFromLeft',
|
||||||
|
'RemovedFromRight',
|
||||||
|
] as const;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Tokenisation strategies for text merging.
|
||||||
|
*
|
||||||
|
* These correspond to the built-in tokenizers available in the underlying WASM module.
|
||||||
|
*/
|
||||||
|
export type BuiltinTokenizer = (typeof BUILTIN_TOKENIZERS)[number];
|
||||||
|
|
||||||
|
/**
|
||||||
|
* History classification for text spans in merge results.
|
||||||
|
*
|
||||||
|
* Indicates the origin of each text span in the merged document.
|
||||||
|
*/
|
||||||
|
export type History = (typeof HISTORY_VALUES)[number];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Represents a text document with associated cursor positions.
|
* Represents a text document with associated cursor positions.
|
||||||
|
|
@ -84,16 +103,7 @@ export interface SpanWithHistory {
|
||||||
history: History;
|
history: History;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
const UNSUPPORTED_TOKENIZER_ERROR = `Unsupported tokenizer. Only ${BUILTIN_TOKENIZERS.join(
|
||||||
* Tokenisation strategies for text merging.
|
|
||||||
*
|
|
||||||
* - "Word": Splits text on word boundaries (recommended for prose and most text)
|
|
||||||
* - "Character": Splits text into individual characters (fine-grained control)
|
|
||||||
* - "Line": Splits text into lines (similar to git merge or diff3)
|
|
||||||
*/
|
|
||||||
const TOKENIZERS = ['Line', 'Word', 'Character'];
|
|
||||||
|
|
||||||
const UNSUPPORTED_TOKENIZER_ERROR = `Unsupported tokenizer. Only ${TOKENIZERS.join(
|
|
||||||
', '
|
', '
|
||||||
)} are supported.`;
|
)} are supported.`;
|
||||||
|
|
||||||
|
|
@ -131,7 +141,7 @@ export function reconcile(
|
||||||
): TextWithCursors {
|
): TextWithCursors {
|
||||||
init();
|
init();
|
||||||
|
|
||||||
if (!TOKENIZERS.includes(tokenizer)) {
|
if (!BUILTIN_TOKENIZERS.includes(tokenizer)) {
|
||||||
throw new Error(UNSUPPORTED_TOKENIZER_ERROR);
|
throw new Error(UNSUPPORTED_TOKENIZER_ERROR);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -185,7 +195,7 @@ export function reconcileWithHistory(
|
||||||
): TextWithCursorsAndHistory {
|
): TextWithCursorsAndHistory {
|
||||||
init();
|
init();
|
||||||
|
|
||||||
if (!TOKENIZERS.includes(tokenizer)) {
|
if (!BUILTIN_TOKENIZERS.includes(tokenizer)) {
|
||||||
throw new Error(UNSUPPORTED_TOKENIZER_ERROR);
|
throw new Error(UNSUPPORTED_TOKENIZER_ERROR);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue