@dxyl/utils 1.2.1 → 1.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.es.js +8893 -7705
- package/dist/index.umd.js +33 -23
- package/lib/opentype/index.d.ts +372 -0
- package/lib/opentype/index.js +14459 -0
- package/lib/opentype/index.umd.js +14477 -0
- package/package.json +6 -1
- package/types/PluginService.d.ts +61 -0
- package/types/antv-util/matrix/index.d.ts +1 -1
- package/types/antv-util/path/parser/params-parser.d.ts +2 -2
- package/types/data/reactivity.d.ts +2 -1
- package/types/events/eventTarget.d.ts +1 -1
- package/types/fast/fast-deep-equal.d.ts +1 -0
- package/types/fast/fast-diff.d.ts +21 -0
- package/types/fast/fast-json-patch/core.d.ts +111 -0
- package/types/fast/fast-json-patch/duplex.d.ts +23 -0
- package/types/fast/fast-json-patch/helpers.d.ts +41 -0
- package/types/index.d.ts +5 -1
- package/types/laxer.d.ts +25 -1
- package/types/lodash/_freeGlobal.d.ts +1 -1
- package/types/lodash/_stackSet.d.ts +1 -1
- package/types/priority_queue.d.ts +2 -2
- package/types/radash/array.d.ts +3 -3
- package/types/text/quill-delta/AttributeMap.d.ts +10 -0
- package/types/text/quill-delta/Delta.d.ts +45 -0
- package/types/text/quill-delta/Op.d.ts +11 -0
- package/types/text/quill-delta/OpIterator.d.ts +13 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dxyl/utils",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.3.0",
|
|
4
4
|
"description": "Collected many useful mathematical tools",
|
|
5
5
|
"publishConfig": {
|
|
6
6
|
"access": "public"
|
|
@@ -19,6 +19,11 @@
|
|
|
19
19
|
"import":"./dist/index.es.js",
|
|
20
20
|
"default":"./dist/index.umd.js"
|
|
21
21
|
},
|
|
22
|
+
"./opentype":{
|
|
23
|
+
"types":"./lib/opentype/index.d.ts",
|
|
24
|
+
"import":"./lib/opentype/index.js",
|
|
25
|
+
"default":"./lib/opentype/index.umd.js"
|
|
26
|
+
},
|
|
22
27
|
"./lib/*":"./lib/*"
|
|
23
28
|
},
|
|
24
29
|
"files": [
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
export type PluginObject = {};
|
|
2
|
+
export type PluginServiceOPtions = {
|
|
3
|
+
plugins?: IPlugin[];
|
|
4
|
+
presets?: IPreset[];
|
|
5
|
+
};
|
|
6
|
+
export type PluginContext = {
|
|
7
|
+
pluginName: string;
|
|
8
|
+
register(hook: IHook): void;
|
|
9
|
+
registerMethod(name: string, fn?: IMethod): void;
|
|
10
|
+
};
|
|
11
|
+
export type IPlugin = {
|
|
12
|
+
name: string;
|
|
13
|
+
config?: any;
|
|
14
|
+
apply: (api: PluginContext, config?: any) => void;
|
|
15
|
+
};
|
|
16
|
+
export type IPreset = Omit<IPlugin, 'apply'> & {
|
|
17
|
+
apply: (api: PluginContext, config?: any) => ({
|
|
18
|
+
presets?: IPreset[];
|
|
19
|
+
plugins?: IPlugin[];
|
|
20
|
+
});
|
|
21
|
+
};
|
|
22
|
+
export type IHook = {
|
|
23
|
+
name: string;
|
|
24
|
+
order?: number;
|
|
25
|
+
fn: Function;
|
|
26
|
+
};
|
|
27
|
+
export declare enum HookType {
|
|
28
|
+
create = "create",
|
|
29
|
+
add = "add",
|
|
30
|
+
modify = "modify",
|
|
31
|
+
event = "event"
|
|
32
|
+
}
|
|
33
|
+
export type HookOpts = {
|
|
34
|
+
name: string;
|
|
35
|
+
type?: HookType;
|
|
36
|
+
initalValue?: any;
|
|
37
|
+
args?: any;
|
|
38
|
+
sync?: boolean;
|
|
39
|
+
};
|
|
40
|
+
export type IMethod = (...args: any[]) => void;
|
|
41
|
+
export declare class PluginService {
|
|
42
|
+
config?: PluginServiceOPtions;
|
|
43
|
+
private hooks;
|
|
44
|
+
private methods;
|
|
45
|
+
private plugins;
|
|
46
|
+
private extraPresets;
|
|
47
|
+
private extraPlugins;
|
|
48
|
+
constructor(config?: PluginServiceOPtions);
|
|
49
|
+
initPresetsAndPlugins(config: PluginServiceOPtions): void;
|
|
50
|
+
private resolvePresets;
|
|
51
|
+
private resolvePlugins;
|
|
52
|
+
private applyMethods;
|
|
53
|
+
private initPluginContext;
|
|
54
|
+
private initPreset;
|
|
55
|
+
private initPlugin;
|
|
56
|
+
registerPlugin(plugin: IPlugin | IPreset): void;
|
|
57
|
+
register(hook: IHook): void;
|
|
58
|
+
registerMethod(name: string, fn?: IMethod): void;
|
|
59
|
+
applyPlugins<T = any>(opts: HookOpts): Promise<T | void>;
|
|
60
|
+
destroy(): void;
|
|
61
|
+
}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
export type IfAny<T, Y, N> = 0 extends 1 & T ? Y : N;
|
|
2
|
+
|
|
2
3
|
export declare enum TrackOpTypes {
|
|
3
4
|
GET = "get",
|
|
4
5
|
HAS = "has",
|
|
@@ -751,5 +752,5 @@ export declare function getCurrentWatcher(): ReactiveEffect<any> | undefined;
|
|
|
751
752
|
*/
|
|
752
753
|
export declare function onWatcherCleanup(cleanupFn: () => void, failSilently?: boolean, owner?: ReactiveEffect | undefined): void;
|
|
753
754
|
export declare function watch(source: WatchSource | WatchSource[] | WatchEffect | object, cb?: WatchCallback | null, options?: WatchOptions): WatchHandle;
|
|
754
|
-
export declare function traverse(value: unknown, depth?: number, seen?:
|
|
755
|
+
export declare function traverse(value: unknown, depth?: number, seen?: Map<unknown, number>): unknown;
|
|
755
756
|
|
|
@@ -17,7 +17,7 @@ export declare const BUBBLING_PHASE: 3;
|
|
|
17
17
|
export declare class Event<T = any, E extends Extract<keyof Record<string, any>, string> = ''> {
|
|
18
18
|
static create<T = any, E extends Extract<keyof Record<string, any>, string> = ''>(type: E, bubbles?: boolean, cancelable?: boolean): Event<T, E>;
|
|
19
19
|
type: E;
|
|
20
|
-
parentNode:
|
|
20
|
+
parentNode: any;
|
|
21
21
|
target: EventTarget | null;
|
|
22
22
|
currentTarget: EventTarget | null;
|
|
23
23
|
data: T | null;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export default function equal(a: any, b: any): boolean;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
declare function diff(
|
|
2
|
+
text1: string,
|
|
3
|
+
text2: string,
|
|
4
|
+
cursorPos?: number | diff.CursorInfo,
|
|
5
|
+
cleanup?: boolean
|
|
6
|
+
): diff.Diff[];
|
|
7
|
+
|
|
8
|
+
declare namespace diff {
|
|
9
|
+
type Diff = [-1 | 0 | 1, string];
|
|
10
|
+
|
|
11
|
+
const DELETE: -1;
|
|
12
|
+
const INSERT: 1;
|
|
13
|
+
const EQUAL: 0;
|
|
14
|
+
|
|
15
|
+
interface CursorInfo {
|
|
16
|
+
oldRange: { index: number; length: number };
|
|
17
|
+
newRange: { index: number; length: number };
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export default diff;
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
import { PatchError, _deepClone } from './helpers.js';
|
|
2
|
+
export declare const JsonPatchError: typeof PatchError;
|
|
3
|
+
export declare const deepClone: typeof _deepClone;
|
|
4
|
+
export type Operation = AddOperation<any> | RemoveOperation | ReplaceOperation<any> | MoveOperation | CopyOperation | TestOperation<any> | GetOperation<any>;
|
|
5
|
+
export interface Validator<T> {
|
|
6
|
+
(operation: Operation, index: number, document: T, existingPathFragment: string): void;
|
|
7
|
+
}
|
|
8
|
+
export interface OperationResult<T> {
|
|
9
|
+
removed?: any;
|
|
10
|
+
test?: boolean;
|
|
11
|
+
newDocument: T;
|
|
12
|
+
}
|
|
13
|
+
export interface BaseOperation {
|
|
14
|
+
path: string;
|
|
15
|
+
}
|
|
16
|
+
export interface AddOperation<T> extends BaseOperation {
|
|
17
|
+
op: 'add';
|
|
18
|
+
value: T;
|
|
19
|
+
}
|
|
20
|
+
export interface RemoveOperation extends BaseOperation {
|
|
21
|
+
op: 'remove';
|
|
22
|
+
}
|
|
23
|
+
export interface ReplaceOperation<T> extends BaseOperation {
|
|
24
|
+
op: 'replace';
|
|
25
|
+
value: T;
|
|
26
|
+
}
|
|
27
|
+
export interface MoveOperation extends BaseOperation {
|
|
28
|
+
op: 'move';
|
|
29
|
+
from: string;
|
|
30
|
+
}
|
|
31
|
+
export interface CopyOperation extends BaseOperation {
|
|
32
|
+
op: 'copy';
|
|
33
|
+
from: string;
|
|
34
|
+
}
|
|
35
|
+
export interface TestOperation<T> extends BaseOperation {
|
|
36
|
+
op: 'test';
|
|
37
|
+
value: T;
|
|
38
|
+
}
|
|
39
|
+
export interface GetOperation<T> extends BaseOperation {
|
|
40
|
+
op: '_get';
|
|
41
|
+
value: T;
|
|
42
|
+
}
|
|
43
|
+
export interface PatchResult<T> extends Array<OperationResult<T>> {
|
|
44
|
+
newDocument: T;
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Retrieves a value from a JSON document by a JSON pointer.
|
|
48
|
+
* Returns the value.
|
|
49
|
+
*
|
|
50
|
+
* @param document The document to get the value from
|
|
51
|
+
* @param pointer an escaped JSON pointer
|
|
52
|
+
* @return The retrieved value
|
|
53
|
+
*/
|
|
54
|
+
export declare function getValueByPointer(document: any, pointer: string): any;
|
|
55
|
+
/**
|
|
56
|
+
* Apply a single JSON Patch Operation on a JSON document.
|
|
57
|
+
* Returns the {newDocument, result} of the operation.
|
|
58
|
+
* It modifies the `document` and `operation` objects - it gets the values by reference.
|
|
59
|
+
* If you would like to avoid touching your values, clone them:
|
|
60
|
+
* `jsonpatch.applyOperation(document, jsonpatch._deepClone(operation))`.
|
|
61
|
+
*
|
|
62
|
+
* @param document The document to patch
|
|
63
|
+
* @param operation The operation to apply
|
|
64
|
+
* @param validateOperation `false` is without validation, `true` to use default jsonpatch's validation, or you can pass a `validateOperation` callback to be used for validation.
|
|
65
|
+
* @param mutateDocument Whether to mutate the original document or clone it before applying
|
|
66
|
+
* @param banPrototypeModifications Whether to ban modifications to `__proto__`, defaults to `true`.
|
|
67
|
+
* @return `{newDocument, result}` after the operation
|
|
68
|
+
*/
|
|
69
|
+
export declare function applyOperation<T>(document: T, operation: Operation, validateOperation?: boolean | Validator<T>, mutateDocument?: boolean, banPrototypeModifications?: boolean, index?: number): OperationResult<T>;
|
|
70
|
+
/**
|
|
71
|
+
* Apply a full JSON Patch array on a JSON document.
|
|
72
|
+
* Returns the {newDocument, result} of the patch.
|
|
73
|
+
* It modifies the `document` object and `patch` - it gets the values by reference.
|
|
74
|
+
* If you would like to avoid touching your values, clone them:
|
|
75
|
+
* `jsonpatch.applyPatch(document, jsonpatch._deepClone(patch))`.
|
|
76
|
+
*
|
|
77
|
+
* @param document The document to patch
|
|
78
|
+
* @param patch The patch to apply
|
|
79
|
+
* @param validateOperation `false` is without validation, `true` to use default jsonpatch's validation, or you can pass a `validateOperation` callback to be used for validation.
|
|
80
|
+
* @param mutateDocument Whether to mutate the original document or clone it before applying
|
|
81
|
+
* @param banPrototypeModifications Whether to ban modifications to `__proto__`, defaults to `true`.
|
|
82
|
+
* @return An array of `{newDocument, result}` after the patch
|
|
83
|
+
*/
|
|
84
|
+
export declare function applyPatch<T>(document: T, patch: ReadonlyArray<Operation>, validateOperation?: boolean | Validator<T>, mutateDocument?: boolean, banPrototypeModifications?: boolean): PatchResult<T>;
|
|
85
|
+
/**
|
|
86
|
+
* Apply a single JSON Patch Operation on a JSON document.
|
|
87
|
+
* Returns the updated document.
|
|
88
|
+
* Suitable as a reducer.
|
|
89
|
+
*
|
|
90
|
+
* @param document The document to patch
|
|
91
|
+
* @param operation The operation to apply
|
|
92
|
+
* @return The updated document
|
|
93
|
+
*/
|
|
94
|
+
export declare function applyReducer<T>(document: T, operation: Operation, index: number): T;
|
|
95
|
+
/**
|
|
96
|
+
* Validates a single operation. Called from `jsonpatch.validate`. Throws `JsonPatchError` in case of an error.
|
|
97
|
+
* @param {object} operation - operation object (patch)
|
|
98
|
+
* @param {number} index - index of operation in the sequence
|
|
99
|
+
* @param {object} [document] - object where the operation is supposed to be applied
|
|
100
|
+
* @param {string} [existingPathFragment] - comes along with `document`
|
|
101
|
+
*/
|
|
102
|
+
export declare function validator(operation: Operation, index: number, document?: any, existingPathFragment?: string): void;
|
|
103
|
+
/**
|
|
104
|
+
* Validates a sequence of operations. If `document` parameter is provided, the sequence is additionally validated against the object document.
|
|
105
|
+
* If error is encountered, returns a JsonPatchError object
|
|
106
|
+
* @param sequence
|
|
107
|
+
* @param document
|
|
108
|
+
* @returns {JsonPatchError|undefined}
|
|
109
|
+
*/
|
|
110
|
+
export declare function validate<T>(sequence: ReadonlyArray<Operation>, document?: T, externalValidator?: Validator<T>): PatchError;
|
|
111
|
+
export declare function _areEquals(a: any, b: any): boolean;
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { Operation } from './core.js';
|
|
2
|
+
export interface Observer<T> {
|
|
3
|
+
object: T;
|
|
4
|
+
patches: Operation[];
|
|
5
|
+
unobserve: () => void;
|
|
6
|
+
callback: (patches: Operation[]) => void;
|
|
7
|
+
}
|
|
8
|
+
/**
|
|
9
|
+
* Detach an observer from an object
|
|
10
|
+
*/
|
|
11
|
+
export declare function unobserve<T>(root: T, observer: Observer<T>): void;
|
|
12
|
+
/**
|
|
13
|
+
* Observes changes made to an object, which can then be retrieved using generate
|
|
14
|
+
*/
|
|
15
|
+
export declare function observe<T>(obj: Object | Array<T>, callback?: (patches: Operation[]) => void): Observer<T>;
|
|
16
|
+
/**
|
|
17
|
+
* Generate an array of patches from an observer
|
|
18
|
+
*/
|
|
19
|
+
export declare function generate<T>(observer: Observer<Object>, invertible?: boolean): Operation[];
|
|
20
|
+
/**
|
|
21
|
+
* Create an array of patches from the differences in two objects
|
|
22
|
+
*/
|
|
23
|
+
export declare function compare(tree1: Object | Array<any>, tree2: Object | Array<any>, invertible?: boolean): Operation[];
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
/*!
|
|
2
|
+
* https://github.com/Starcounter-Jack/JSON-Patch
|
|
3
|
+
* (c) 2017-2022 Joachim Wester
|
|
4
|
+
* MIT licensed
|
|
5
|
+
*/
|
|
6
|
+
export declare function hasOwnProperty(obj: any, key: string): boolean;
|
|
7
|
+
export declare function _objectKeys(obj: any): any[];
|
|
8
|
+
/**
|
|
9
|
+
* Deeply clone the object.
|
|
10
|
+
* https://jsperf.com/deep-copy-vs-json-stringify-json-parse/25 (recursiveDeepCopy)
|
|
11
|
+
* @param {any} obj value to clone
|
|
12
|
+
* @return {any} cloned obj
|
|
13
|
+
*/
|
|
14
|
+
export declare function _deepClone(obj: any): any;
|
|
15
|
+
export declare function isInteger(str: string): boolean;
|
|
16
|
+
/**
|
|
17
|
+
* Escapes a json pointer path
|
|
18
|
+
* @param path The raw pointer
|
|
19
|
+
* @return the Escaped path
|
|
20
|
+
*/
|
|
21
|
+
export declare function escapePathComponent(path: string): string;
|
|
22
|
+
/**
|
|
23
|
+
* Unescapes a json pointer path
|
|
24
|
+
* @param path The escaped pointer
|
|
25
|
+
* @return The unescaped path
|
|
26
|
+
*/
|
|
27
|
+
export declare function unescapePathComponent(path: string): string;
|
|
28
|
+
export declare function _getPathRecursive(root: any, obj: any): string;
|
|
29
|
+
export declare function getPath(root: Object, obj: Object): string;
|
|
30
|
+
/**
|
|
31
|
+
* Recursively checks whether an object has any undefined values inside.
|
|
32
|
+
*/
|
|
33
|
+
export declare function hasUndefined(obj: any): boolean;
|
|
34
|
+
export type JsonPatchErrorName = 'SEQUENCE_NOT_AN_ARRAY' | 'OPERATION_NOT_AN_OBJECT' | 'OPERATION_OP_INVALID' | 'OPERATION_PATH_INVALID' | 'OPERATION_FROM_REQUIRED' | 'OPERATION_VALUE_REQUIRED' | 'OPERATION_VALUE_CANNOT_CONTAIN_UNDEFINED' | 'OPERATION_PATH_CANNOT_ADD' | 'OPERATION_PATH_UNRESOLVABLE' | 'OPERATION_FROM_UNRESOLVABLE' | 'OPERATION_PATH_ILLEGAL_ARRAY_INDEX' | 'OPERATION_VALUE_OUT_OF_BOUNDS' | 'TEST_OPERATION_FAILED';
|
|
35
|
+
export declare class PatchError extends Error {
|
|
36
|
+
name: JsonPatchErrorName;
|
|
37
|
+
index?: number;
|
|
38
|
+
operation?: any;
|
|
39
|
+
tree?: any;
|
|
40
|
+
constructor(message: string, name: JsonPatchErrorName, index?: number, operation?: any, tree?: any);
|
|
41
|
+
}
|
package/types/index.d.ts
CHANGED
|
@@ -24,6 +24,10 @@ export { Options } from './Options';
|
|
|
24
24
|
export { default as compose } from './compose';
|
|
25
25
|
export type { OptionsProperties, OptionConfig } from './Options';
|
|
26
26
|
export { default as deepmerge } from './deepmerge';
|
|
27
|
-
export { default as fastDeepEqual } from './fast-deep-equal';
|
|
28
27
|
export * from './Color';
|
|
29
28
|
export * as colord from './color/colord/src';
|
|
29
|
+
export * from './PluginService';
|
|
30
|
+
export { default as fastDeepEqual } from './fast/fast-deep-equal';
|
|
31
|
+
export { default as fastDiff } from './fast/fast-diff';
|
|
32
|
+
export * as fastJsonPatch from './fast/fast-json-patch/core';
|
|
33
|
+
export * as QuillDelta from './text/quill-delta/Delta';
|
package/types/laxer.d.ts
CHANGED
|
@@ -19,4 +19,28 @@
|
|
|
19
19
|
*
|
|
20
20
|
* sourceCode -> Lexer analysis or Tokenizer(token[]) -> ast parse (tree<astNode>) -> (code generate) | (ast interpreter)
|
|
21
21
|
*/
|
|
22
|
-
|
|
22
|
+
declare const token: (type: string, value: any, start: number) => {
|
|
23
|
+
type: string;
|
|
24
|
+
value: any;
|
|
25
|
+
start: number;
|
|
26
|
+
};
|
|
27
|
+
type Token = ReturnType<typeof token>;
|
|
28
|
+
/**
|
|
29
|
+
* 词法分析
|
|
30
|
+
* @param {string} source 源码
|
|
31
|
+
* @returns {Token[]}
|
|
32
|
+
*/
|
|
33
|
+
declare const lexer: (source: string) => {
|
|
34
|
+
type: string;
|
|
35
|
+
value: any;
|
|
36
|
+
start: number;
|
|
37
|
+
}[];
|
|
38
|
+
declare const parse: (tokens: Token[]) => {
|
|
39
|
+
type: string;
|
|
40
|
+
body: any[];
|
|
41
|
+
start?: number;
|
|
42
|
+
end?: number;
|
|
43
|
+
};
|
|
44
|
+
declare const codeGen: (ast: any) => string;
|
|
45
|
+
declare const interpreter: (program: any) => any;
|
|
46
|
+
export { parse, codeGen, lexer, interpreter, token };
|
|
@@ -14,7 +14,7 @@ export declare class PriorityQueue<T> {
|
|
|
14
14
|
* 判断队列是否为空
|
|
15
15
|
*/
|
|
16
16
|
isEmpty(): boolean;
|
|
17
|
-
top(): T
|
|
17
|
+
top(): T;
|
|
18
18
|
/**
|
|
19
19
|
* 查看队首元素
|
|
20
20
|
*/
|
|
@@ -25,7 +25,7 @@ export declare class PriorityQueue<T> {
|
|
|
25
25
|
*/
|
|
26
26
|
enqueue(value: T): void;
|
|
27
27
|
push(value: T): void;
|
|
28
|
-
pop(): T
|
|
28
|
+
pop(): T;
|
|
29
29
|
/**
|
|
30
30
|
* 出队
|
|
31
31
|
* @returns 队首元素或null(空队列时)
|
package/types/radash/array.d.ts
CHANGED
|
@@ -30,7 +30,7 @@ export declare function zipToObject<K extends string | number | symbol, V>(keys:
|
|
|
30
30
|
*
|
|
31
31
|
* Ex. const greatest = () => boil(numbers, (a, b) => a > b)
|
|
32
32
|
*/
|
|
33
|
-
export declare const boil: <T>(array: readonly T[], compareFunc: (a: T, b: T) => T) => T
|
|
33
|
+
export declare const boil: <T>(array: readonly T[], compareFunc: (a: T, b: T) => T) => T;
|
|
34
34
|
/**
|
|
35
35
|
* Sum all numbers in an array. Optionally provide a function
|
|
36
36
|
* to convert objects in the array to number values.
|
|
@@ -40,11 +40,11 @@ export declare function sum<T extends object>(array: readonly T[], fn: (item: T)
|
|
|
40
40
|
/**
|
|
41
41
|
* Get the first item in an array or a default value
|
|
42
42
|
*/
|
|
43
|
-
export declare const first: <T>(array: readonly T[], defaultValue?: T | null | undefined) => T
|
|
43
|
+
export declare const first: <T>(array: readonly T[], defaultValue?: T | null | undefined) => T;
|
|
44
44
|
/**
|
|
45
45
|
* Get the last item in an array or a default value
|
|
46
46
|
*/
|
|
47
|
-
export declare const last: <T>(array: readonly T[], defaultValue?: T | null | undefined) => T
|
|
47
|
+
export declare const last: <T>(array: readonly T[], defaultValue?: T | null | undefined) => T;
|
|
48
48
|
/**
|
|
49
49
|
* Sort an array without modifying it and return
|
|
50
50
|
* the newly sorted value
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
interface AttributeMap {
|
|
2
|
+
[key: string]: unknown;
|
|
3
|
+
}
|
|
4
|
+
declare namespace AttributeMap {
|
|
5
|
+
function compose(a?: AttributeMap, b?: AttributeMap, keepNull?: boolean): AttributeMap | undefined;
|
|
6
|
+
function diff(a?: AttributeMap, b?: AttributeMap): AttributeMap | undefined;
|
|
7
|
+
function invert(attr?: AttributeMap, base?: AttributeMap): AttributeMap;
|
|
8
|
+
function transform(a: AttributeMap | undefined, b: AttributeMap | undefined, priority?: boolean): AttributeMap | undefined;
|
|
9
|
+
}
|
|
10
|
+
export default AttributeMap;
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { default as diff } from '../../fast/fast-diff';
|
|
2
|
+
import { default as AttributeMap } from './AttributeMap';
|
|
3
|
+
import { default as Op } from './Op';
|
|
4
|
+
import { default as OpIterator } from './OpIterator';
|
|
5
|
+
interface EmbedHandler<T> {
|
|
6
|
+
compose(a: T, b: T, keepNull: boolean): T;
|
|
7
|
+
invert(a: T, b: T): T;
|
|
8
|
+
transform(a: T, b: T, priority: boolean): T;
|
|
9
|
+
}
|
|
10
|
+
declare class Delta {
|
|
11
|
+
static Op: typeof Op;
|
|
12
|
+
static OpIterator: typeof OpIterator;
|
|
13
|
+
static AttributeMap: typeof AttributeMap;
|
|
14
|
+
private static handlers;
|
|
15
|
+
static registerEmbed<T>(embedType: string, handler: EmbedHandler<T>): void;
|
|
16
|
+
static unregisterEmbed(embedType: string): void;
|
|
17
|
+
private static getHandler;
|
|
18
|
+
ops: Op[];
|
|
19
|
+
constructor(ops?: Op[] | {
|
|
20
|
+
ops: Op[];
|
|
21
|
+
});
|
|
22
|
+
insert(arg: string | Record<string, unknown>, attributes?: AttributeMap | null): this;
|
|
23
|
+
delete(length: number): this;
|
|
24
|
+
retain(length: number | Record<string, unknown>, attributes?: AttributeMap | null): this;
|
|
25
|
+
push(newOp: Op): this;
|
|
26
|
+
chop(): this;
|
|
27
|
+
filter(predicate: (op: Op, index: number) => boolean): Op[];
|
|
28
|
+
forEach(predicate: (op: Op, index: number) => void): void;
|
|
29
|
+
map<T>(predicate: (op: Op, index: number) => T): T[];
|
|
30
|
+
partition(predicate: (op: Op) => boolean): [Op[], Op[]];
|
|
31
|
+
reduce<T>(predicate: (accum: T, curr: Op, index: number) => T, initialValue: T): T;
|
|
32
|
+
changeLength(): number;
|
|
33
|
+
length(): number;
|
|
34
|
+
slice(start?: number, end?: number): Delta;
|
|
35
|
+
compose(other: Delta): Delta;
|
|
36
|
+
concat(other: Delta): Delta;
|
|
37
|
+
diff(other: Delta, cursor?: number | diff.CursorInfo): Delta;
|
|
38
|
+
eachLine(predicate: (line: Delta, attributes: AttributeMap, index: number) => boolean | void, newline?: string): void;
|
|
39
|
+
invert(base: Delta): Delta;
|
|
40
|
+
transform(index: number, priority?: boolean): number;
|
|
41
|
+
transform(other: Delta, priority?: boolean): Delta;
|
|
42
|
+
transformPosition(index: number, priority?: boolean): number;
|
|
43
|
+
}
|
|
44
|
+
export default Delta;
|
|
45
|
+
export { Op, OpIterator, AttributeMap, Delta };
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { default as AttributeMap } from './AttributeMap';
|
|
2
|
+
interface Op {
|
|
3
|
+
insert?: string | Record<string, unknown>;
|
|
4
|
+
delete?: number;
|
|
5
|
+
retain?: number | Record<string, unknown>;
|
|
6
|
+
attributes?: AttributeMap;
|
|
7
|
+
}
|
|
8
|
+
declare namespace Op {
|
|
9
|
+
function length(op: Op): number;
|
|
10
|
+
}
|
|
11
|
+
export default Op;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { default as Op } from './Op';
|
|
2
|
+
export default class Iterator {
|
|
3
|
+
ops: Op[];
|
|
4
|
+
index: number;
|
|
5
|
+
offset: number;
|
|
6
|
+
constructor(ops: Op[]);
|
|
7
|
+
hasNext(): boolean;
|
|
8
|
+
next(length?: number): Op;
|
|
9
|
+
peek(): Op;
|
|
10
|
+
peekLength(): number;
|
|
11
|
+
peekType(): string;
|
|
12
|
+
rest(): Op[];
|
|
13
|
+
}
|