@editora/toast 1.0.2 → 2.0.1
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/README.md +904 -8
- package/dist/core/AnimationUtils.d.ts +36 -0
- package/dist/core/ToastLifecycle.d.ts +25 -0
- package/dist/core/ToastManager.d.ts +36 -0
- package/dist/core/ToastQueue.d.ts +19 -0
- package/dist/core/ToastRenderer.d.ts +20 -0
- package/dist/core/ToastStore.d.ts +31 -0
- package/dist/core/types.d.ts +168 -0
- package/dist/index.cjs.js +2 -0
- package/dist/index.cjs.js.map +1 -0
- package/dist/index.d.ts +39 -10
- package/dist/index.esm.js +1075 -0
- package/dist/index.esm.js.map +1 -0
- package/dist/index.umd.js +2 -0
- package/dist/index.umd.js.map +1 -0
- package/dist/toast.css +783 -18
- package/package.json +50 -13
- package/LICENSE +0 -21
- package/dist/index.js +0 -70
- package/dist/packages/core/src/Editor.d.ts +0 -15
- package/dist/packages/core/src/Editor.js +0 -37
- package/dist/packages/core/src/EditorState.d.ts +0 -13
- package/dist/packages/core/src/EditorState.js +0 -14
- package/dist/packages/core/src/Selection.d.ts +0 -126
- package/dist/packages/core/src/Selection.js +0 -232
- package/dist/packages/core/src/commands/CommandManager.d.ts +0 -56
- package/dist/packages/core/src/commands/CommandManager.js +0 -166
- package/dist/packages/core/src/index.d.ts +0 -7
- package/dist/packages/core/src/index.js +0 -4
- package/dist/packages/core/src/model/Fragment.d.ts +0 -80
- package/dist/packages/core/src/model/Fragment.js +0 -172
- package/dist/packages/core/src/model/Mark.d.ts +0 -108
- package/dist/packages/core/src/model/Mark.js +0 -138
- package/dist/packages/core/src/model/Node.d.ts +0 -172
- package/dist/packages/core/src/model/Node.js +0 -458
- package/dist/packages/core/src/model/types.d.ts +0 -29
- package/dist/packages/core/src/model/types.js +0 -1
- package/dist/packages/core/src/plugins/Plugin.d.ts +0 -37
- package/dist/packages/core/src/plugins/Plugin.js +0 -31
- package/dist/packages/core/src/plugins/PluginManager.d.ts +0 -75
- package/dist/packages/core/src/plugins/PluginManager.js +0 -185
- package/dist/packages/core/src/schema/Node.d.ts +0 -26
- package/dist/packages/core/src/schema/Node.js +0 -12
- package/dist/packages/core/src/schema/Schema.d.ts +0 -52
- package/dist/packages/core/src/schema/Schema.js +0 -296
- package/dist/packages/core/src/security/Sanitizer.d.ts +0 -81
- package/dist/packages/core/src/security/Sanitizer.js +0 -200
- package/dist/packages/editora-toast/src/index.d.ts +0 -18
- package/dist/packages/editora-toast/src/index.js +0 -70
- package/src/index.ts +0 -83
- package/src/toast.css +0 -42
package/package.json
CHANGED
|
@@ -1,27 +1,64 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@editora/toast",
|
|
3
|
-
"version": "
|
|
4
|
-
"
|
|
5
|
-
"
|
|
3
|
+
"version": "2.0.1",
|
|
4
|
+
"description": "Advanced toast notification system with enterprise features, backward compatibility, and rich customization options",
|
|
5
|
+
"main": "dist/index.cjs.js",
|
|
6
|
+
"module": "dist/index.esm.js",
|
|
7
|
+
"browser": "dist/index.umd.js",
|
|
8
|
+
"unpkg": "dist/index.umd.js",
|
|
9
|
+
"jsdelivr": "dist/index.umd.js",
|
|
6
10
|
"types": "dist/index.d.ts",
|
|
7
11
|
"exports": {
|
|
8
12
|
".": {
|
|
9
|
-
"
|
|
10
|
-
"
|
|
11
|
-
"
|
|
12
|
-
|
|
13
|
+
"types": "./dist/index.d.ts",
|
|
14
|
+
"import": "./dist/index.esm.js",
|
|
15
|
+
"require": "./dist/index.cjs.js",
|
|
16
|
+
"browser": "./dist/index.umd.js"
|
|
17
|
+
},
|
|
18
|
+
"./toast.css": "./dist/toast.css"
|
|
13
19
|
},
|
|
14
20
|
"files": [
|
|
15
|
-
"dist"
|
|
16
|
-
|
|
21
|
+
"dist"
|
|
22
|
+
],
|
|
23
|
+
"keywords": [
|
|
24
|
+
"toast",
|
|
25
|
+
"notification",
|
|
26
|
+
"ui",
|
|
27
|
+
"ux",
|
|
28
|
+
"typescript",
|
|
29
|
+
"framework-agnostic",
|
|
30
|
+
"accessibility",
|
|
31
|
+
"promise",
|
|
32
|
+
"queue",
|
|
33
|
+
"plugin",
|
|
34
|
+
"editor",
|
|
35
|
+
"rich-text-editor"
|
|
17
36
|
],
|
|
18
37
|
"author": "Ajay Kumar <ajaykr089@gmail.com>",
|
|
19
38
|
"license": "MIT",
|
|
39
|
+
"repository": {
|
|
40
|
+
"type": "git",
|
|
41
|
+
"url": "git+https://github.com/ajaykr089/Editora.git",
|
|
42
|
+
"directory": "packages/editora-toast"
|
|
43
|
+
},
|
|
44
|
+
"bugs": {
|
|
45
|
+
"url": "https://github.com/ajaykr089/Editora/issues"
|
|
46
|
+
},
|
|
47
|
+
"homepage": "https://github.com/ajaykr089/Editora/tree/main/packages/editora-toast#readme",
|
|
48
|
+
"style": "dist/toast.css",
|
|
49
|
+
"publishConfig": {
|
|
50
|
+
"access": "public"
|
|
51
|
+
},
|
|
20
52
|
"scripts": {
|
|
21
|
-
"build": "
|
|
53
|
+
"build": "vite build && vite build --config vite.umd.config.ts && tsc --emitDeclarationOnly --outDir dist",
|
|
54
|
+
"postbuild": "cp src/toast.css dist/",
|
|
55
|
+
"dev": "vite build --watch",
|
|
56
|
+
"clean": "rm -rf dist",
|
|
57
|
+
"prepublishOnly": "npm run clean && npm run build"
|
|
22
58
|
},
|
|
23
59
|
"devDependencies": {
|
|
24
|
-
"typescript": "^5.0.0"
|
|
60
|
+
"typescript": "^5.0.0",
|
|
61
|
+
"vite": "^7.3.1"
|
|
25
62
|
},
|
|
26
|
-
"gitHead": "
|
|
27
|
-
}
|
|
63
|
+
"gitHead": "694494db58b809f0dcf24501696284faa1ab68a5"
|
|
64
|
+
}
|
package/LICENSE
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
MIT License
|
|
2
|
-
|
|
3
|
-
Copyright (c) 2026 Ajay Kumar
|
|
4
|
-
|
|
5
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
-
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
-
in the Software without restriction, including without limitation the rights
|
|
8
|
-
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
-
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
-
furnished to do so, subject to the following conditions:
|
|
11
|
-
|
|
12
|
-
The above copyright notice and this permission notice shall be included in all
|
|
13
|
-
copies or substantial portions of the Software.
|
|
14
|
-
|
|
15
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
-
SOFTWARE.
|
package/dist/index.js
DELETED
|
@@ -1,70 +0,0 @@
|
|
|
1
|
-
const DEFAULT_DURATION = 4000;
|
|
2
|
-
let container = null;
|
|
3
|
-
function ensureContainer() {
|
|
4
|
-
if (container)
|
|
5
|
-
return container;
|
|
6
|
-
container = document.createElement('div');
|
|
7
|
-
container.className = 'editora-toast-container';
|
|
8
|
-
document.body.appendChild(container);
|
|
9
|
-
// try to inject css if not loaded
|
|
10
|
-
const existing = Array.from(document.styleSheets).find(s => { var _a, _b; return (_b = (_a = s.ownerNode) === null || _a === void 0 ? void 0 : _a.href) === null || _b === void 0 ? void 0 : _b.includes('toast.css'); });
|
|
11
|
-
if (!existing) {
|
|
12
|
-
const link = document.createElement('link');
|
|
13
|
-
link.rel = 'stylesheet';
|
|
14
|
-
link.href = '/packages/editora-toast/dist/toast.css';
|
|
15
|
-
document.head.appendChild(link);
|
|
16
|
-
}
|
|
17
|
-
return container;
|
|
18
|
-
}
|
|
19
|
-
function createToastEl(message, level) {
|
|
20
|
-
const el = document.createElement('div');
|
|
21
|
-
el.className = `editora-toast ${level}`;
|
|
22
|
-
el.textContent = message;
|
|
23
|
-
const close = document.createElement('span');
|
|
24
|
-
close.className = 'close';
|
|
25
|
-
close.textContent = '×';
|
|
26
|
-
close.style.float = 'right';
|
|
27
|
-
close.style.marginLeft = '8px';
|
|
28
|
-
close.onclick = () => {
|
|
29
|
-
// immediate hide for manual close (will mirror show.hide behavior)
|
|
30
|
-
el.classList.remove('show');
|
|
31
|
-
setTimeout(() => {
|
|
32
|
-
try {
|
|
33
|
-
el.remove();
|
|
34
|
-
}
|
|
35
|
-
catch (e) { }
|
|
36
|
-
}, 220);
|
|
37
|
-
};
|
|
38
|
-
el.appendChild(close);
|
|
39
|
-
return el;
|
|
40
|
-
}
|
|
41
|
-
function show(options) {
|
|
42
|
-
if (typeof document === 'undefined')
|
|
43
|
-
return;
|
|
44
|
-
const { message, duration = DEFAULT_DURATION, level = 'info' } = options;
|
|
45
|
-
const cont = ensureContainer();
|
|
46
|
-
const el = createToastEl(message, level);
|
|
47
|
-
cont.appendChild(el);
|
|
48
|
-
// force layout then show
|
|
49
|
-
requestAnimationFrame(() => el.classList.add('show'));
|
|
50
|
-
const timeout = setTimeout(() => hide(el), duration);
|
|
51
|
-
function hide(target) {
|
|
52
|
-
clearTimeout(timeout);
|
|
53
|
-
target.classList.remove('show');
|
|
54
|
-
setTimeout(() => {
|
|
55
|
-
try {
|
|
56
|
-
target.remove();
|
|
57
|
-
}
|
|
58
|
-
catch (e) { }
|
|
59
|
-
}, 220);
|
|
60
|
-
}
|
|
61
|
-
return {
|
|
62
|
-
dismiss: () => hide(el)
|
|
63
|
-
};
|
|
64
|
-
}
|
|
65
|
-
export const toast = {
|
|
66
|
-
info: (msg, duration) => show({ message: msg, level: 'info', duration }),
|
|
67
|
-
success: (msg, duration) => show({ message: msg, level: 'success', duration }),
|
|
68
|
-
error: (msg, duration) => show({ message: msg, level: 'error', duration })
|
|
69
|
-
};
|
|
70
|
-
export default toast;
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import { EditorState } from './EditorState';
|
|
2
|
-
import { PluginManager } from './plugins/Plugin';
|
|
3
|
-
import { Node } from './schema/Node';
|
|
4
|
-
export declare class Editor {
|
|
5
|
-
state: EditorState;
|
|
6
|
-
pluginManager: PluginManager;
|
|
7
|
-
commands: Record<string, (state: EditorState) => EditorState | null>;
|
|
8
|
-
listeners: Array<(state: EditorState) => void>;
|
|
9
|
-
constructor(pluginManager: PluginManager);
|
|
10
|
-
setState(state: EditorState): void;
|
|
11
|
-
onChange(fn: (state: EditorState) => void): () => void;
|
|
12
|
-
execCommand(name: string): boolean;
|
|
13
|
-
setContent(doc: Node): void;
|
|
14
|
-
getContent(): Node;
|
|
15
|
-
}
|
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
import { EditorState } from './EditorState';
|
|
2
|
-
export class Editor {
|
|
3
|
-
constructor(pluginManager) {
|
|
4
|
-
this.listeners = [];
|
|
5
|
-
this.pluginManager = pluginManager;
|
|
6
|
-
const schema = pluginManager.buildSchema();
|
|
7
|
-
this.state = EditorState.create(schema);
|
|
8
|
-
this.commands = pluginManager.getCommands();
|
|
9
|
-
}
|
|
10
|
-
setState(state) {
|
|
11
|
-
this.state = state;
|
|
12
|
-
this.listeners.forEach(fn => fn(state));
|
|
13
|
-
}
|
|
14
|
-
onChange(fn) {
|
|
15
|
-
this.listeners.push(fn);
|
|
16
|
-
return () => {
|
|
17
|
-
this.listeners = this.listeners.filter(l => l !== fn);
|
|
18
|
-
};
|
|
19
|
-
}
|
|
20
|
-
execCommand(name) {
|
|
21
|
-
const command = this.commands[name];
|
|
22
|
-
if (!command)
|
|
23
|
-
return false;
|
|
24
|
-
const newState = command(this.state);
|
|
25
|
-
if (newState) {
|
|
26
|
-
this.setState(newState);
|
|
27
|
-
return true;
|
|
28
|
-
}
|
|
29
|
-
return false;
|
|
30
|
-
}
|
|
31
|
-
setContent(doc) {
|
|
32
|
-
this.setState(this.state.apply(doc));
|
|
33
|
-
}
|
|
34
|
-
getContent() {
|
|
35
|
-
return this.state.doc;
|
|
36
|
-
}
|
|
37
|
-
}
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import { Node, Schema } from './schema/Node';
|
|
2
|
-
export interface EditorSelection {
|
|
3
|
-
anchor: number;
|
|
4
|
-
head: number;
|
|
5
|
-
}
|
|
6
|
-
export declare class EditorState {
|
|
7
|
-
doc: Node;
|
|
8
|
-
selection: EditorSelection;
|
|
9
|
-
schema: Schema;
|
|
10
|
-
constructor(doc: Node, selection: EditorSelection, schema: Schema);
|
|
11
|
-
static create(schema: Schema, content?: Node): EditorState;
|
|
12
|
-
apply(doc: Node, selection?: EditorSelection): EditorState;
|
|
13
|
-
}
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
export class EditorState {
|
|
2
|
-
constructor(doc, selection, schema) {
|
|
3
|
-
this.doc = doc;
|
|
4
|
-
this.selection = selection;
|
|
5
|
-
this.schema = schema;
|
|
6
|
-
}
|
|
7
|
-
static create(schema, content) {
|
|
8
|
-
const doc = content || schema.node('doc', {}, [schema.node('paragraph')]);
|
|
9
|
-
return new EditorState(doc, { anchor: 0, head: 0 }, schema);
|
|
10
|
-
}
|
|
11
|
-
apply(doc, selection) {
|
|
12
|
-
return new EditorState(doc, selection || this.selection, this.schema);
|
|
13
|
-
}
|
|
14
|
-
}
|
|
@@ -1,126 +0,0 @@
|
|
|
1
|
-
import { Node } from './model/Node';
|
|
2
|
-
import { Fragment } from './model/Fragment';
|
|
3
|
-
/**
|
|
4
|
-
* Base selection interface representing a range or position in the document.
|
|
5
|
-
*/
|
|
6
|
-
export declare abstract class Selection {
|
|
7
|
-
abstract readonly $from: ResolvedPos;
|
|
8
|
-
abstract readonly $to: ResolvedPos;
|
|
9
|
-
abstract readonly from: number;
|
|
10
|
-
abstract readonly to: number;
|
|
11
|
-
abstract readonly empty: boolean;
|
|
12
|
-
/**
|
|
13
|
-
* Create a selection at the start of the document.
|
|
14
|
-
*/
|
|
15
|
-
static atStart(doc: Node): Selection;
|
|
16
|
-
/**
|
|
17
|
-
* Create a selection at the end of the document.
|
|
18
|
-
*/
|
|
19
|
-
static atEnd(doc: Node): Selection;
|
|
20
|
-
/**
|
|
21
|
-
* Create a selection from positions.
|
|
22
|
-
*/
|
|
23
|
-
static create(doc: Node, from: number, to?: number): Selection;
|
|
24
|
-
/**
|
|
25
|
-
* Check if this selection equals another selection.
|
|
26
|
-
*/
|
|
27
|
-
abstract equals(other: Selection): boolean;
|
|
28
|
-
/**
|
|
29
|
-
* Map this selection through a document change.
|
|
30
|
-
*/
|
|
31
|
-
abstract map(doc: Node, mapping: any): Selection;
|
|
32
|
-
/**
|
|
33
|
-
* Convert to JSON representation.
|
|
34
|
-
*/
|
|
35
|
-
abstract toJSON(): any;
|
|
36
|
-
/**
|
|
37
|
-
* Get the content of this selection.
|
|
38
|
-
*/
|
|
39
|
-
get content(): Slice;
|
|
40
|
-
}
|
|
41
|
-
/**
|
|
42
|
-
* Text selection representing a cursor position or range in text.
|
|
43
|
-
*/
|
|
44
|
-
export declare class TextSelection extends Selection {
|
|
45
|
-
readonly $from: ResolvedPos;
|
|
46
|
-
readonly $to: ResolvedPos;
|
|
47
|
-
readonly from: number;
|
|
48
|
-
readonly to: number;
|
|
49
|
-
constructor($from: ResolvedPos, $to?: ResolvedPos);
|
|
50
|
-
get empty(): boolean;
|
|
51
|
-
static create(doc: Node, pos: number): TextSelection;
|
|
52
|
-
equals(other: Selection): boolean;
|
|
53
|
-
map(doc: Node, mapping: any): Selection;
|
|
54
|
-
toJSON(): any;
|
|
55
|
-
}
|
|
56
|
-
/**
|
|
57
|
-
* Node selection representing the selection of a single node.
|
|
58
|
-
*/
|
|
59
|
-
export declare class NodeSelection extends Selection {
|
|
60
|
-
readonly $from: ResolvedPos;
|
|
61
|
-
readonly $to: ResolvedPos;
|
|
62
|
-
readonly from: number;
|
|
63
|
-
readonly to: number;
|
|
64
|
-
readonly node: Node;
|
|
65
|
-
constructor($from: ResolvedPos);
|
|
66
|
-
get empty(): boolean;
|
|
67
|
-
static create(doc: Node, pos: number): NodeSelection;
|
|
68
|
-
equals(other: Selection): boolean;
|
|
69
|
-
map(doc: Node, mapping: any): Selection;
|
|
70
|
-
toJSON(): any;
|
|
71
|
-
}
|
|
72
|
-
/**
|
|
73
|
-
* Resolved position in the document with context information.
|
|
74
|
-
*/
|
|
75
|
-
export declare class ResolvedPos {
|
|
76
|
-
readonly pos: number;
|
|
77
|
-
readonly doc: Node;
|
|
78
|
-
readonly depth: number;
|
|
79
|
-
readonly parentOffset: number;
|
|
80
|
-
constructor(pos: number, doc: Node, depth: number, parentOffset: number);
|
|
81
|
-
/**
|
|
82
|
-
* Resolve a position in the document to a ResolvedPos.
|
|
83
|
-
*/
|
|
84
|
-
static resolve(doc: Node, pos: number): ResolvedPos;
|
|
85
|
-
/**
|
|
86
|
-
* Get the node at this position.
|
|
87
|
-
*/
|
|
88
|
-
get node(): Node;
|
|
89
|
-
/**
|
|
90
|
-
* Get the node after this position.
|
|
91
|
-
*/
|
|
92
|
-
get nodeAfter(): Node | null;
|
|
93
|
-
/**
|
|
94
|
-
* Get the node before this position.
|
|
95
|
-
*/
|
|
96
|
-
get nodeBefore(): Node | null;
|
|
97
|
-
/**
|
|
98
|
-
* Get the parent node at the given depth.
|
|
99
|
-
*/
|
|
100
|
-
parent(depth?: number): Node;
|
|
101
|
-
/**
|
|
102
|
-
* Get the resolved position of the parent.
|
|
103
|
-
*/
|
|
104
|
-
private parentPos;
|
|
105
|
-
/**
|
|
106
|
-
* Get the path from root to this position.
|
|
107
|
-
*/
|
|
108
|
-
private path;
|
|
109
|
-
/**
|
|
110
|
-
* Check if this position is at the start of its parent.
|
|
111
|
-
*/
|
|
112
|
-
get isAtStart(): boolean;
|
|
113
|
-
/**
|
|
114
|
-
* Check if this position is at the end of its parent.
|
|
115
|
-
*/
|
|
116
|
-
get isAtEnd(): boolean;
|
|
117
|
-
}
|
|
118
|
-
/**
|
|
119
|
-
* A slice of document content.
|
|
120
|
-
*/
|
|
121
|
-
export declare class Slice {
|
|
122
|
-
readonly content: Fragment;
|
|
123
|
-
readonly openStart: number;
|
|
124
|
-
readonly openEnd: number;
|
|
125
|
-
constructor(content: Fragment, openStart: number, openEnd: number);
|
|
126
|
-
}
|
|
@@ -1,232 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Base selection interface representing a range or position in the document.
|
|
3
|
-
*/
|
|
4
|
-
export class Selection {
|
|
5
|
-
/**
|
|
6
|
-
* Create a selection at the start of the document.
|
|
7
|
-
*/
|
|
8
|
-
static atStart(doc) {
|
|
9
|
-
return TextSelection.create(doc, 0);
|
|
10
|
-
}
|
|
11
|
-
/**
|
|
12
|
-
* Create a selection at the end of the document.
|
|
13
|
-
*/
|
|
14
|
-
static atEnd(doc) {
|
|
15
|
-
return TextSelection.create(doc, doc.content.size);
|
|
16
|
-
}
|
|
17
|
-
/**
|
|
18
|
-
* Create a selection from positions.
|
|
19
|
-
*/
|
|
20
|
-
static create(doc, from, to) {
|
|
21
|
-
if (to === undefined || from === to) {
|
|
22
|
-
return TextSelection.create(doc, from);
|
|
23
|
-
}
|
|
24
|
-
return new TextSelection(ResolvedPos.resolve(doc, from), ResolvedPos.resolve(doc, to));
|
|
25
|
-
}
|
|
26
|
-
/**
|
|
27
|
-
* Get the content of this selection.
|
|
28
|
-
*/
|
|
29
|
-
get content() {
|
|
30
|
-
return new Slice(this.$from.doc.slice(this.from, this.to), 0, 0);
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
/**
|
|
34
|
-
* Text selection representing a cursor position or range in text.
|
|
35
|
-
*/
|
|
36
|
-
export class TextSelection extends Selection {
|
|
37
|
-
constructor($from, $to) {
|
|
38
|
-
super();
|
|
39
|
-
this.$from = $from;
|
|
40
|
-
this.$to = $to || $from;
|
|
41
|
-
this.from = $from.pos;
|
|
42
|
-
this.to = this.$to.pos;
|
|
43
|
-
}
|
|
44
|
-
get empty() {
|
|
45
|
-
return this.from === this.to;
|
|
46
|
-
}
|
|
47
|
-
static create(doc, pos) {
|
|
48
|
-
return new TextSelection(ResolvedPos.resolve(doc, pos));
|
|
49
|
-
}
|
|
50
|
-
equals(other) {
|
|
51
|
-
return other instanceof TextSelection &&
|
|
52
|
-
this.$from.pos === other.$from.pos &&
|
|
53
|
-
this.$to.pos === other.$to.pos;
|
|
54
|
-
}
|
|
55
|
-
map(doc, mapping) {
|
|
56
|
-
// Basic mapping implementation - will be enhanced
|
|
57
|
-
const newFrom = mapping.map(this.from);
|
|
58
|
-
const newTo = mapping.map(this.to);
|
|
59
|
-
return TextSelection.create(doc, Math.min(newFrom, newTo));
|
|
60
|
-
}
|
|
61
|
-
toJSON() {
|
|
62
|
-
return {
|
|
63
|
-
type: 'text',
|
|
64
|
-
from: this.from,
|
|
65
|
-
to: this.to
|
|
66
|
-
};
|
|
67
|
-
}
|
|
68
|
-
}
|
|
69
|
-
/**
|
|
70
|
-
* Node selection representing the selection of a single node.
|
|
71
|
-
*/
|
|
72
|
-
export class NodeSelection extends Selection {
|
|
73
|
-
constructor($from) {
|
|
74
|
-
super();
|
|
75
|
-
this.$from = $from;
|
|
76
|
-
this.$to = ResolvedPos.resolve($from.doc, $from.pos + $from.nodeAfter.nodeSize);
|
|
77
|
-
this.from = $from.pos;
|
|
78
|
-
this.to = this.$to.pos;
|
|
79
|
-
this.node = $from.nodeAfter;
|
|
80
|
-
}
|
|
81
|
-
get empty() {
|
|
82
|
-
return false;
|
|
83
|
-
}
|
|
84
|
-
static create(doc, pos) {
|
|
85
|
-
const $pos = ResolvedPos.resolve(doc, pos);
|
|
86
|
-
if (!$pos.nodeAfter) {
|
|
87
|
-
throw new Error('No node at position ' + pos);
|
|
88
|
-
}
|
|
89
|
-
return new NodeSelection($pos);
|
|
90
|
-
}
|
|
91
|
-
equals(other) {
|
|
92
|
-
return other instanceof NodeSelection &&
|
|
93
|
-
this.$from.pos === other.$from.pos;
|
|
94
|
-
}
|
|
95
|
-
map(doc, mapping) {
|
|
96
|
-
const newPos = mapping.map(this.from);
|
|
97
|
-
try {
|
|
98
|
-
return NodeSelection.create(doc, newPos);
|
|
99
|
-
}
|
|
100
|
-
catch (_a) {
|
|
101
|
-
return TextSelection.create(doc, newPos);
|
|
102
|
-
}
|
|
103
|
-
}
|
|
104
|
-
toJSON() {
|
|
105
|
-
return {
|
|
106
|
-
type: 'node',
|
|
107
|
-
from: this.from,
|
|
108
|
-
to: this.to
|
|
109
|
-
};
|
|
110
|
-
}
|
|
111
|
-
}
|
|
112
|
-
/**
|
|
113
|
-
* Resolved position in the document with context information.
|
|
114
|
-
*/
|
|
115
|
-
export class ResolvedPos {
|
|
116
|
-
constructor(pos, doc, depth, parentOffset) {
|
|
117
|
-
this.pos = pos;
|
|
118
|
-
this.doc = doc;
|
|
119
|
-
this.depth = depth;
|
|
120
|
-
this.parentOffset = parentOffset;
|
|
121
|
-
}
|
|
122
|
-
/**
|
|
123
|
-
* Resolve a position in the document to a ResolvedPos.
|
|
124
|
-
*/
|
|
125
|
-
static resolve(doc, pos) {
|
|
126
|
-
if (pos < 0)
|
|
127
|
-
pos = 0;
|
|
128
|
-
if (pos > doc.content.size)
|
|
129
|
-
pos = doc.content.size;
|
|
130
|
-
let depth = 0;
|
|
131
|
-
let parentOffset = pos;
|
|
132
|
-
let node = doc;
|
|
133
|
-
while (depth < 100 && parentOffset > 0) {
|
|
134
|
-
const child = node.content.findChildAt(parentOffset - 1);
|
|
135
|
-
if (!child)
|
|
136
|
-
break;
|
|
137
|
-
if (parentOffset <= child.offset + child.node.nodeSize) {
|
|
138
|
-
depth++;
|
|
139
|
-
parentOffset -= child.offset;
|
|
140
|
-
node = child.node;
|
|
141
|
-
}
|
|
142
|
-
else {
|
|
143
|
-
break;
|
|
144
|
-
}
|
|
145
|
-
}
|
|
146
|
-
return new ResolvedPos(pos, doc, depth, parentOffset);
|
|
147
|
-
}
|
|
148
|
-
/**
|
|
149
|
-
* Get the node at this position.
|
|
150
|
-
*/
|
|
151
|
-
get node() {
|
|
152
|
-
return this.doc.nodeAt(this.pos);
|
|
153
|
-
}
|
|
154
|
-
/**
|
|
155
|
-
* Get the node after this position.
|
|
156
|
-
*/
|
|
157
|
-
get nodeAfter() {
|
|
158
|
-
return this.doc.nodeAt(this.pos);
|
|
159
|
-
}
|
|
160
|
-
/**
|
|
161
|
-
* Get the node before this position.
|
|
162
|
-
*/
|
|
163
|
-
get nodeBefore() {
|
|
164
|
-
return this.pos > 0 ? this.doc.nodeAt(this.pos - 1) : null;
|
|
165
|
-
}
|
|
166
|
-
/**
|
|
167
|
-
* Get the parent node at the given depth.
|
|
168
|
-
*/
|
|
169
|
-
parent(depth) {
|
|
170
|
-
const targetDepth = depth !== null && depth !== void 0 ? depth : this.depth - 1;
|
|
171
|
-
if (targetDepth < 0)
|
|
172
|
-
return this.doc;
|
|
173
|
-
let pos = this;
|
|
174
|
-
for (let i = this.depth; i > targetDepth; i--) {
|
|
175
|
-
pos = pos.parentPos();
|
|
176
|
-
}
|
|
177
|
-
return pos.node;
|
|
178
|
-
}
|
|
179
|
-
/**
|
|
180
|
-
* Get the resolved position of the parent.
|
|
181
|
-
*/
|
|
182
|
-
parentPos() {
|
|
183
|
-
let pos = 0;
|
|
184
|
-
let node = this.doc;
|
|
185
|
-
const path = this.path();
|
|
186
|
-
for (let i = 0; i < path.length - 1; i++) {
|
|
187
|
-
pos += path[i].offset + 1;
|
|
188
|
-
node = path[i].node;
|
|
189
|
-
}
|
|
190
|
-
return ResolvedPos.resolve(this.doc, pos);
|
|
191
|
-
}
|
|
192
|
-
/**
|
|
193
|
-
* Get the path from root to this position.
|
|
194
|
-
*/
|
|
195
|
-
path() {
|
|
196
|
-
const path = [];
|
|
197
|
-
let pos = 0;
|
|
198
|
-
let node = this.doc;
|
|
199
|
-
while (pos < this.pos) {
|
|
200
|
-
const child = node.content.findChildAt(pos);
|
|
201
|
-
if (!child)
|
|
202
|
-
break;
|
|
203
|
-
path.push({ node: child.node, offset: child.offset });
|
|
204
|
-
pos += child.offset;
|
|
205
|
-
node = child.node;
|
|
206
|
-
}
|
|
207
|
-
return path;
|
|
208
|
-
}
|
|
209
|
-
/**
|
|
210
|
-
* Check if this position is at the start of its parent.
|
|
211
|
-
*/
|
|
212
|
-
get isAtStart() {
|
|
213
|
-
return this.parentOffset === 0;
|
|
214
|
-
}
|
|
215
|
-
/**
|
|
216
|
-
* Check if this position is at the end of its parent.
|
|
217
|
-
*/
|
|
218
|
-
get isAtEnd() {
|
|
219
|
-
return this.parentOffset === this.parent().content.size;
|
|
220
|
-
}
|
|
221
|
-
}
|
|
222
|
-
/**
|
|
223
|
-
* A slice of document content.
|
|
224
|
-
*/
|
|
225
|
-
export class Slice {
|
|
226
|
-
constructor(content, openStart, openEnd) {
|
|
227
|
-
this.content = content;
|
|
228
|
-
this.openStart = openStart;
|
|
229
|
-
this.openEnd = openEnd;
|
|
230
|
-
}
|
|
231
|
-
}
|
|
232
|
-
// Placeholder - will be implemented in model/Fragment.ts
|
|
@@ -1,56 +0,0 @@
|
|
|
1
|
-
import { EditorState, Transaction } from '../EditorState';
|
|
2
|
-
/**
|
|
3
|
-
* Command function type.
|
|
4
|
-
*/
|
|
5
|
-
export type Command = (state: EditorState, dispatch?: (tr: Transaction) => void, view?: any, ...args: any[]) => boolean;
|
|
6
|
-
/**
|
|
7
|
-
* Command manager for registering and executing commands.
|
|
8
|
-
*/
|
|
9
|
-
export declare class CommandManager {
|
|
10
|
-
private commands;
|
|
11
|
-
private aliases;
|
|
12
|
-
/**
|
|
13
|
-
* Register a command.
|
|
14
|
-
*/
|
|
15
|
-
register(name: string, command: Command): void;
|
|
16
|
-
/**
|
|
17
|
-
* Register multiple commands.
|
|
18
|
-
*/
|
|
19
|
-
registerAll(commands: Record<string, Command>): void;
|
|
20
|
-
/**
|
|
21
|
-
* Create an alias for a command.
|
|
22
|
-
*/
|
|
23
|
-
alias(alias: string, commandName: string): void;
|
|
24
|
-
/**
|
|
25
|
-
* Execute a command by name.
|
|
26
|
-
*/
|
|
27
|
-
execute(name: string, state: EditorState, dispatch?: (tr: Transaction) => void, view?: any, ...args: any[]): boolean;
|
|
28
|
-
/**
|
|
29
|
-
* Check if a command can be executed.
|
|
30
|
-
*/
|
|
31
|
-
can(name: string, state: EditorState, view?: any, ...args: any[]): boolean;
|
|
32
|
-
/**
|
|
33
|
-
* Check if a command exists.
|
|
34
|
-
*/
|
|
35
|
-
has(name: string): boolean;
|
|
36
|
-
/**
|
|
37
|
-
* Get all registered commands.
|
|
38
|
-
*/
|
|
39
|
-
getCommands(): Record<string, Command>;
|
|
40
|
-
/**
|
|
41
|
-
* Get all registered command names.
|
|
42
|
-
*/
|
|
43
|
-
getCommandNames(): string[];
|
|
44
|
-
/**
|
|
45
|
-
* Unregister a command.
|
|
46
|
-
*/
|
|
47
|
-
unregister(name: string): void;
|
|
48
|
-
/**
|
|
49
|
-
* Clear all commands.
|
|
50
|
-
*/
|
|
51
|
-
clear(): void;
|
|
52
|
-
}
|
|
53
|
-
/**
|
|
54
|
-
* Create a command manager instance with built-in commands.
|
|
55
|
-
*/
|
|
56
|
-
export declare function createCommandManager(): CommandManager;
|