svelte-multistyle-ui 0.0.9-alpha → 0.0.13-alpha
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 +1 -1
- package/cli/registry.js +2 -0
- package/dist/components/CodeEditor.svelte +130 -0
- package/dist/components/CodeEditor.svelte.d.ts +25 -0
- package/dist/components/TextEditor.svelte +187 -0
- package/dist/components/TextEditor.svelte.d.ts +27 -0
- package/dist/components/charts/chart-config.d.ts +2 -2
- package/dist/components/codeeditor-styles.css +292 -0
- package/dist/components/text-editor-core/dom-utils.d.ts +17 -0
- package/dist/components/text-editor-core/dom-utils.js +151 -0
- package/dist/components/text-editor-core/editor-core.d.ts +113 -0
- package/dist/components/text-editor-core/editor-core.js +808 -0
- package/dist/components/text-editor-core/history.d.ts +14 -0
- package/dist/components/text-editor-core/history.js +78 -0
- package/dist/components/text-editor-core/html-formatter.d.ts +4 -0
- package/dist/components/text-editor-core/html-formatter.js +80 -0
- package/dist/components/text-editor-core/index.d.ts +7 -0
- package/dist/components/text-editor-core/index.js +22 -0
- package/dist/components/text-editor-core/sanitizer.d.ts +3 -0
- package/dist/components/text-editor-core/sanitizer.js +161 -0
- package/dist/components/text-editor-core/selection-engine.d.ts +11 -0
- package/dist/components/text-editor-core/selection-engine.js +137 -0
- package/dist/components/text-editor-core/toolbar-config.d.ts +91 -0
- package/dist/components/text-editor-core/toolbar-config.js +138 -0
- package/dist/components/texteditor-styles.css +493 -0
- package/dist/config.svelte.d.ts +3 -3
- package/dist/index.d.ts +2 -0
- package/dist/index.js +2 -0
- package/dist/themes/presets.d.ts +21 -21
- package/package.json +1 -1
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Small DOM helpers used by the custom WYSIWYG editor core.
|
|
3
|
+
*/
|
|
4
|
+
export function createElement(tag: any, attrs?: {}, children?: any[]): any;
|
|
5
|
+
export function closest(node: any, selector: any): any;
|
|
6
|
+
export function matches(el: any, selector: any): any;
|
|
7
|
+
export function isInsideEditor(node: any, editorEl: any): any;
|
|
8
|
+
export function getActiveElement(editorEl: any): Node | null;
|
|
9
|
+
export function getParentBlock(node: any, editorEl: any): any;
|
|
10
|
+
export function isBlockElement(el: any): boolean;
|
|
11
|
+
export function walkNodes(root: any, callback: any): void;
|
|
12
|
+
export function emptyNode(node: any): void;
|
|
13
|
+
export function ensureParagraph(editorEl: any): any;
|
|
14
|
+
export function stripTags(html: any, allowed: any): string;
|
|
15
|
+
export function getTextLength(html: any): number;
|
|
16
|
+
export function getWordCount(html: any): number;
|
|
17
|
+
export function htmlToText(html: any): string;
|
|
@@ -0,0 +1,151 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Small DOM helpers used by the custom WYSIWYG editor core.
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
export function createElement(tag, attrs = {}, children = []) {
|
|
6
|
+
const el = document.createElement(tag);
|
|
7
|
+
for (const [key, value] of Object.entries(attrs)) {
|
|
8
|
+
if (key === "className") {
|
|
9
|
+
el.className = value;
|
|
10
|
+
} else if (key === "innerHTML") {
|
|
11
|
+
el.innerHTML = value;
|
|
12
|
+
} else if (key === "textContent") {
|
|
13
|
+
el.textContent = value;
|
|
14
|
+
} else if (key === "value") {
|
|
15
|
+
el.value = value;
|
|
16
|
+
} else if (key.startsWith("on") && typeof value === "function") {
|
|
17
|
+
const event = key.slice(2).toLowerCase();
|
|
18
|
+
el.addEventListener(event, value);
|
|
19
|
+
} else if (value !== null && value !== undefined) {
|
|
20
|
+
el.setAttribute(key, value);
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
for (const child of children) {
|
|
24
|
+
if (child == null) continue;
|
|
25
|
+
if (typeof child === "string" || typeof child === "number") {
|
|
26
|
+
el.appendChild(document.createTextNode(String(child)));
|
|
27
|
+
} else if (child instanceof Node) {
|
|
28
|
+
el.appendChild(child);
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
return el;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
export function closest(node, selector) {
|
|
35
|
+
if (!node) return null;
|
|
36
|
+
let current = node;
|
|
37
|
+
while (current) {
|
|
38
|
+
if (current.nodeType === Node.ELEMENT_NODE && current.matches(selector)) {
|
|
39
|
+
return current;
|
|
40
|
+
}
|
|
41
|
+
current = current.parentNode;
|
|
42
|
+
}
|
|
43
|
+
return null;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
export function matches(el, selector) {
|
|
47
|
+
if (!el || el.nodeType !== Node.ELEMENT_NODE) return false;
|
|
48
|
+
return el.matches?.(selector) ?? false;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
export function isInsideEditor(node, editorEl) {
|
|
52
|
+
if (!node) return false;
|
|
53
|
+
if (node.nodeType === Node.TEXT_NODE) node = node.parentNode;
|
|
54
|
+
return editorEl.contains(node);
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
export function getActiveElement(editorEl) {
|
|
58
|
+
const sel = window.getSelection();
|
|
59
|
+
if (!sel || sel.rangeCount === 0) return null;
|
|
60
|
+
const node = sel.anchorNode;
|
|
61
|
+
if (!isInsideEditor(node, editorEl)) return null;
|
|
62
|
+
return node;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
export function getParentBlock(node, editorEl) {
|
|
66
|
+
let current = node;
|
|
67
|
+
while (current && current !== editorEl) {
|
|
68
|
+
if (current.nodeType === Node.ELEMENT_NODE && isBlockElement(current)) {
|
|
69
|
+
return current;
|
|
70
|
+
}
|
|
71
|
+
current = current.parentNode;
|
|
72
|
+
}
|
|
73
|
+
return null;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
export function isBlockElement(el) {
|
|
77
|
+
if (!el || el.nodeType !== Node.ELEMENT_NODE) return false;
|
|
78
|
+
const blocks = [
|
|
79
|
+
"P", "DIV", "H1", "H2", "H3", "H4", "H5", "H6",
|
|
80
|
+
"BLOCKQUOTE", "PRE", "UL", "OL", "LI", "TABLE",
|
|
81
|
+
"THEAD", "TBODY", "TR", "TD", "TH", "HR",
|
|
82
|
+
];
|
|
83
|
+
return blocks.includes(el.tagName);
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
export function walkNodes(root, callback) {
|
|
87
|
+
const walker = document.createTreeWalker(
|
|
88
|
+
root,
|
|
89
|
+
NodeFilter.SHOW_ELEMENT | NodeFilter.SHOW_TEXT,
|
|
90
|
+
null,
|
|
91
|
+
false,
|
|
92
|
+
);
|
|
93
|
+
const nodes = [];
|
|
94
|
+
let node;
|
|
95
|
+
while ((node = walker.nextNode())) {
|
|
96
|
+
nodes.push(node);
|
|
97
|
+
}
|
|
98
|
+
for (const n of nodes) {
|
|
99
|
+
callback(n);
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
export function emptyNode(node) {
|
|
104
|
+
while (node.firstChild) {
|
|
105
|
+
node.removeChild(node.firstChild);
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
export function ensureParagraph(editorEl) {
|
|
110
|
+
if (!editorEl.innerHTML.trim()) {
|
|
111
|
+
editorEl.innerHTML = "<p><br></p>";
|
|
112
|
+
return editorEl.querySelector("p");
|
|
113
|
+
}
|
|
114
|
+
return null;
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
export function stripTags(html, allowed) {
|
|
118
|
+
const div = document.createElement("div");
|
|
119
|
+
div.innerHTML = html;
|
|
120
|
+
walkNodes(div, (node) => {
|
|
121
|
+
if (node.nodeType === Node.ELEMENT_NODE) {
|
|
122
|
+
const tag = node.tagName.toLowerCase();
|
|
123
|
+
if (!allowed.includes(tag)) {
|
|
124
|
+
const parent = node.parentNode;
|
|
125
|
+
while (node.firstChild) {
|
|
126
|
+
parent.insertBefore(node.firstChild, node);
|
|
127
|
+
}
|
|
128
|
+
parent.removeChild(node);
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
});
|
|
132
|
+
return div.innerHTML;
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
export function getTextLength(html) {
|
|
136
|
+
const div = document.createElement("div");
|
|
137
|
+
div.innerHTML = html;
|
|
138
|
+
return div.textContent.length;
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
export function getWordCount(html) {
|
|
142
|
+
const text = htmlToText(html);
|
|
143
|
+
const words = text.trim().split(/\s+/).filter(Boolean);
|
|
144
|
+
return words.length;
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
export function htmlToText(html) {
|
|
148
|
+
const div = document.createElement("div");
|
|
149
|
+
div.innerHTML = html;
|
|
150
|
+
return div.textContent || "";
|
|
151
|
+
}
|
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
export class TextEditorCore {
|
|
2
|
+
constructor(options?: {});
|
|
3
|
+
container: any;
|
|
4
|
+
onChange: any;
|
|
5
|
+
onSelectionChange: any;
|
|
6
|
+
onAction: any;
|
|
7
|
+
placeholder: any;
|
|
8
|
+
readOnly: any;
|
|
9
|
+
historyLimit: any;
|
|
10
|
+
toolbarConfig: any;
|
|
11
|
+
value: string;
|
|
12
|
+
history: {
|
|
13
|
+
record: (html: any) => void;
|
|
14
|
+
undo: (currentHtml: any) => any;
|
|
15
|
+
redo: () => any;
|
|
16
|
+
canUndo: () => boolean;
|
|
17
|
+
canRedo: () => boolean;
|
|
18
|
+
startComposition: () => void;
|
|
19
|
+
endComposition: (html: any) => void;
|
|
20
|
+
clear: () => void;
|
|
21
|
+
readonly length: number;
|
|
22
|
+
};
|
|
23
|
+
isComposing: boolean;
|
|
24
|
+
lastHtml: string;
|
|
25
|
+
focused: boolean;
|
|
26
|
+
_handlers: any[];
|
|
27
|
+
_dialogState: {
|
|
28
|
+
type: null;
|
|
29
|
+
data: null;
|
|
30
|
+
};
|
|
31
|
+
_codeView: boolean;
|
|
32
|
+
_codeEl: any;
|
|
33
|
+
_lastCodeValue: string;
|
|
34
|
+
_savedSelection: Range | null;
|
|
35
|
+
_buildDOM(): void;
|
|
36
|
+
toolbarEl: any;
|
|
37
|
+
bodyEl: any;
|
|
38
|
+
editorEl: any;
|
|
39
|
+
statusEl: any;
|
|
40
|
+
_attachEvents(): void;
|
|
41
|
+
_listen(target: any, event: any, handler: any): void;
|
|
42
|
+
destroy(): void;
|
|
43
|
+
_onInput(): void;
|
|
44
|
+
_onCompositionStart(): void;
|
|
45
|
+
_onCompositionEnd(): void;
|
|
46
|
+
_emitChange(): void;
|
|
47
|
+
_onFocus(): void;
|
|
48
|
+
_onBlur(): void;
|
|
49
|
+
_onSelectionChange(): void;
|
|
50
|
+
_onKeyDown(e: any): void;
|
|
51
|
+
_applyFormat(command: any): void;
|
|
52
|
+
_onPaste(e: any): void;
|
|
53
|
+
_onDrop(e: any): void;
|
|
54
|
+
_insertImageFromFile(file: any): void;
|
|
55
|
+
_renderToolbar(): void;
|
|
56
|
+
_createControl(action: any): any;
|
|
57
|
+
_handleCommand(action: any, value: any): void;
|
|
58
|
+
exec(command: any, value?: null): void;
|
|
59
|
+
_applyBlockFormat(tag: any): void;
|
|
60
|
+
_applyLineHeight(value: any): void;
|
|
61
|
+
_openLinkDialog(): void;
|
|
62
|
+
_openImageDialog(): void;
|
|
63
|
+
_openVideoDialog(): void;
|
|
64
|
+
_openTableDialog(): void;
|
|
65
|
+
_getSelectedLink(): Node | null;
|
|
66
|
+
insertLink({ text, href, title, target }: {
|
|
67
|
+
text: any;
|
|
68
|
+
href: any;
|
|
69
|
+
title: any;
|
|
70
|
+
target: any;
|
|
71
|
+
}): void;
|
|
72
|
+
removeLink(): void;
|
|
73
|
+
insertImage({ src, alt, width, align, caption }: {
|
|
74
|
+
src: any;
|
|
75
|
+
alt: any;
|
|
76
|
+
width: any;
|
|
77
|
+
align: any;
|
|
78
|
+
caption: any;
|
|
79
|
+
}): void;
|
|
80
|
+
insertVideo({ src, width, height }: {
|
|
81
|
+
src: any;
|
|
82
|
+
width?: string | undefined;
|
|
83
|
+
height?: string | undefined;
|
|
84
|
+
}): void;
|
|
85
|
+
insertTable({ rows, cols }: {
|
|
86
|
+
rows: any;
|
|
87
|
+
cols: any;
|
|
88
|
+
}): void;
|
|
89
|
+
getSelectedImage(): any;
|
|
90
|
+
alignImage(align: any): void;
|
|
91
|
+
removeImage(): void;
|
|
92
|
+
replaceImage(src: any): void;
|
|
93
|
+
setImageAlt(alt: any): void;
|
|
94
|
+
_recordBeforeMutation(): void;
|
|
95
|
+
undo(): void;
|
|
96
|
+
redo(): void;
|
|
97
|
+
toggleCodeView(): void;
|
|
98
|
+
_enterCodeView(): void;
|
|
99
|
+
_exitCodeView(): void;
|
|
100
|
+
_saveSelection(): Range | null;
|
|
101
|
+
_restoreSelection(range: any): void;
|
|
102
|
+
isCodeView(): boolean;
|
|
103
|
+
getHTML(): string;
|
|
104
|
+
setHTML(html: any): void;
|
|
105
|
+
_setHTMLInternal(html: any, record: any): void;
|
|
106
|
+
getText(): string;
|
|
107
|
+
clear(): void;
|
|
108
|
+
focus(): void;
|
|
109
|
+
setReadOnly(readOnly: any): void;
|
|
110
|
+
_updateToolbarState(state: any): void;
|
|
111
|
+
_updatePlaceholder(): void;
|
|
112
|
+
_updateStatus(state?: null): void;
|
|
113
|
+
}
|