@chenyomi/leafer-htmltext-editor 1.0.7 → 1.0.10
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.cjs +4 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.mts +64 -0
- package/dist/index.d.ts +51 -6
- package/dist/index.mjs +4 -0
- package/dist/index.mjs.map +1 -0
- package/package.json +16 -8
- package/dist/TextEditTool/index.d.ts +0 -17
- package/dist/TextEditTool/index.d.ts.map +0 -1
- package/dist/TextEditTool/index.js +0 -113
- package/dist/TextEditTool/utils.d.ts +0 -8
- package/dist/TextEditTool/utils.d.ts.map +0 -1
- package/dist/TextEditTool/utils.js +0 -256
- package/dist/TextEditor.d.ts +0 -30
- package/dist/TextEditor.d.ts.map +0 -1
- package/dist/TextEditor.js +0 -169
- package/dist/esm/TextEditTool/index.d.ts +0 -17
- package/dist/esm/TextEditTool/index.d.ts.map +0 -1
- package/dist/esm/TextEditTool/index.js +0 -110
- package/dist/esm/TextEditTool/utils.d.ts +0 -8
- package/dist/esm/TextEditTool/utils.d.ts.map +0 -1
- package/dist/esm/TextEditTool/utils.js +0 -248
- package/dist/esm/TextEditor.d.ts +0 -30
- package/dist/esm/TextEditor.d.ts.map +0 -1
- package/dist/esm/TextEditor.js +0 -166
- package/dist/esm/fonts/font.d.ts +0 -17
- package/dist/esm/fonts/font.d.ts.map +0 -1
- package/dist/esm/fonts/font.js +0 -68
- package/dist/esm/fonts/utils.d.ts +0 -9
- package/dist/esm/fonts/utils.d.ts.map +0 -1
- package/dist/esm/fonts/utils.js +0 -170
- package/dist/esm/index.d.ts +0 -19
- package/dist/esm/index.d.ts.map +0 -1
- package/dist/esm/utils.d.ts +0 -3
- package/dist/esm/utils.d.ts.map +0 -1
- package/dist/esm/utils.js +0 -266
- package/dist/fonts/font.d.ts +0 -17
- package/dist/fonts/font.d.ts.map +0 -1
- package/dist/fonts/font.js +0 -72
- package/dist/fonts/utils.d.ts +0 -9
- package/dist/fonts/utils.d.ts.map +0 -1
- package/dist/fonts/utils.js +0 -180
- package/dist/index.d.ts.map +0 -1
- package/dist/index.esm.js +0 -141
- package/dist/index.js +0 -179
- package/dist/utils.d.ts +0 -3
- package/dist/utils.d.ts.map +0 -1
- package/dist/utils.js +0 -271
- package/src/TextEditTool/index.ts +0 -132
- package/src/TextEditTool/utils.ts +0 -288
- package/src/TextEditor.ts +0 -213
- package/src/fonts/font.ts +0 -86
- package/src/fonts/utils.ts +0 -232
- package/src/htmltext-editor.css +0 -103
- package/src/index.ts +0 -163
- package/src/utils.ts +0 -294
package/dist/fonts/utils.js
DELETED
|
@@ -1,180 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.fetchFontAsBase64 = fetchFontAsBase64;
|
|
4
|
-
exports.addCustomFonts = addCustomFonts;
|
|
5
|
-
exports.getCustomFontsStyle = getCustomFontsStyle;
|
|
6
|
-
exports.addCustomFont = addCustomFont;
|
|
7
|
-
exports.batchLoadFont = batchLoadFont;
|
|
8
|
-
exports.addCustomFontBase64 = addCustomFontBase64;
|
|
9
|
-
exports.getBase64CustomFontsStyle = getBase64CustomFontsStyle;
|
|
10
|
-
exports.loadFont = loadFont;
|
|
11
|
-
const FONT_CSS_TAG = "data-fonts";
|
|
12
|
-
const FONT_CSS_TAG_BASE64 = "base64-fonts";
|
|
13
|
-
async function fetchFontAsBase64(url) {
|
|
14
|
-
const response = await fetch(url);
|
|
15
|
-
if (!response.ok) {
|
|
16
|
-
throw new Error(`Failed to fetch font from ${url}`);
|
|
17
|
-
}
|
|
18
|
-
const contentType = response.headers.get('Content-Type');
|
|
19
|
-
let mimeType;
|
|
20
|
-
if (contentType?.includes('font/woff2')) {
|
|
21
|
-
mimeType = 'font/woff2';
|
|
22
|
-
}
|
|
23
|
-
else if (contentType?.includes('font/woff')) {
|
|
24
|
-
mimeType = 'font/woff';
|
|
25
|
-
}
|
|
26
|
-
else if (contentType?.includes('font/ttf') || contentType?.includes('font/sfnt')) {
|
|
27
|
-
mimeType = 'font/ttf';
|
|
28
|
-
}
|
|
29
|
-
else if (contentType?.includes('application/octet-stream')) {
|
|
30
|
-
const extension = url.split('.').pop()?.toLowerCase();
|
|
31
|
-
if (extension === 'woff2') {
|
|
32
|
-
mimeType = 'font/woff2';
|
|
33
|
-
}
|
|
34
|
-
else if (extension === 'woff') {
|
|
35
|
-
mimeType = 'font/woff';
|
|
36
|
-
}
|
|
37
|
-
else if (extension === 'ttf') {
|
|
38
|
-
mimeType = 'font/ttf';
|
|
39
|
-
}
|
|
40
|
-
else {
|
|
41
|
-
throw new Error(`Unsupported font file type: ${extension}`);
|
|
42
|
-
}
|
|
43
|
-
}
|
|
44
|
-
else {
|
|
45
|
-
throw new Error(`Unsupported Content-Type: ${contentType}`);
|
|
46
|
-
}
|
|
47
|
-
const arrayBuffer = await response.arrayBuffer();
|
|
48
|
-
const base64String = arrayBufferToBase64(arrayBuffer);
|
|
49
|
-
return `data:${mimeType};charset=utf-8;base64,${base64String}`;
|
|
50
|
-
}
|
|
51
|
-
function arrayBufferToBase64(buffer) {
|
|
52
|
-
let binary = '';
|
|
53
|
-
const bytes = new Uint8Array(buffer);
|
|
54
|
-
const len = bytes.byteLength;
|
|
55
|
-
for (let i = 0; i < len; i++) {
|
|
56
|
-
binary += String.fromCharCode(bytes[i]);
|
|
57
|
-
}
|
|
58
|
-
return window.btoa(binary);
|
|
59
|
-
}
|
|
60
|
-
function addCustomFonts(fontList = []) {
|
|
61
|
-
let styleTag = document.createElement('style');
|
|
62
|
-
styleTag.setAttribute(FONT_CSS_TAG, 'true');
|
|
63
|
-
let fontRules = fontList.map((font) => `@font-face {
|
|
64
|
-
font-family: "${font.name}";
|
|
65
|
-
src: local("${font.name}"), url("${font.download}")
|
|
66
|
-
}`).join('\n');
|
|
67
|
-
styleTag.textContent = fontRules;
|
|
68
|
-
document.head.appendChild(styleTag);
|
|
69
|
-
}
|
|
70
|
-
function getCustomFontsStyle() {
|
|
71
|
-
const styleTag = document.querySelector('style[data-fonts]');
|
|
72
|
-
return styleTag?.textContent || '';
|
|
73
|
-
}
|
|
74
|
-
function addCustomFont(font) {
|
|
75
|
-
let styleTag = document.querySelector('style[data-fonts]');
|
|
76
|
-
if (!styleTag) {
|
|
77
|
-
styleTag = document.createElement('style');
|
|
78
|
-
styleTag.setAttribute(FONT_CSS_TAG, 'true');
|
|
79
|
-
document.head.appendChild(styleTag);
|
|
80
|
-
}
|
|
81
|
-
if (!styleTag.sheet)
|
|
82
|
-
return;
|
|
83
|
-
let existingFonts = [];
|
|
84
|
-
existingFonts = Array.from(styleTag.sheet.cssRules).map((rule) => {
|
|
85
|
-
const match = rule.cssText.match(/font-family: "([^"]+)"/);
|
|
86
|
-
return match ? match[1] : null;
|
|
87
|
-
}).filter((font) => font !== null);
|
|
88
|
-
if (!existingFonts.includes(font.name)) {
|
|
89
|
-
const newFontRule = `@font-face {
|
|
90
|
-
font-family: "${font.name}";
|
|
91
|
-
src: url("${font.download}");
|
|
92
|
-
}`;
|
|
93
|
-
try {
|
|
94
|
-
styleTag.sheet.insertRule(newFontRule, styleTag.sheet.cssRules.length);
|
|
95
|
-
}
|
|
96
|
-
catch (e) {
|
|
97
|
-
console.error('Failed to insert font rule:', e);
|
|
98
|
-
}
|
|
99
|
-
}
|
|
100
|
-
}
|
|
101
|
-
async function batchLoadFont(fontNameList = []) {
|
|
102
|
-
try {
|
|
103
|
-
for (const fontFamily of fontNameList) {
|
|
104
|
-
await document.fonts.load(`16px ${fontFamily}`);
|
|
105
|
-
}
|
|
106
|
-
}
|
|
107
|
-
catch (e) {
|
|
108
|
-
console.warn('Font loading failed:', e);
|
|
109
|
-
}
|
|
110
|
-
}
|
|
111
|
-
function getFontUrlFromCSS(selectors, fontFamilyName) {
|
|
112
|
-
const styleTags = document.querySelectorAll(selectors);
|
|
113
|
-
for (let i = 0; i < styleTags.length; i++) {
|
|
114
|
-
const styleTag = styleTags[i];
|
|
115
|
-
const cssText = styleTag.textContent || '';
|
|
116
|
-
const fontFaceRules = cssText.match(/@font-face\s*\{[^}]+\}/g);
|
|
117
|
-
if (fontFaceRules) {
|
|
118
|
-
for (const rule of fontFaceRules) {
|
|
119
|
-
const fontFamilyMatch = rule.match(/font-family:\s*(["'])(.*?)\1/);
|
|
120
|
-
if (fontFamilyMatch && fontFamilyMatch[2] === fontFamilyName) {
|
|
121
|
-
const srcMatch = rule.match(/src:\s*url\((["'])(.*?)\1\)/);
|
|
122
|
-
if (srcMatch) {
|
|
123
|
-
return srcMatch[2];
|
|
124
|
-
}
|
|
125
|
-
else {
|
|
126
|
-
const srcMatch2 = rule.match(/src:\s*(?:local\([^)]+\)\s*,\s*)?url\((["'])(.*?)\1\)/);
|
|
127
|
-
if (srcMatch2) {
|
|
128
|
-
return srcMatch2[2];
|
|
129
|
-
}
|
|
130
|
-
}
|
|
131
|
-
}
|
|
132
|
-
}
|
|
133
|
-
}
|
|
134
|
-
}
|
|
135
|
-
return null;
|
|
136
|
-
}
|
|
137
|
-
async function addCustomFontBase64(font) {
|
|
138
|
-
const fontUrl = getFontUrlFromCSS(`style[${FONT_CSS_TAG}]`, font);
|
|
139
|
-
if (!fontUrl) {
|
|
140
|
-
console.warn('Font URL not found for:', font);
|
|
141
|
-
return;
|
|
142
|
-
}
|
|
143
|
-
console.log('fontUrl=', fontUrl);
|
|
144
|
-
let styleTag = document.querySelector(`style[${FONT_CSS_TAG_BASE64}]`);
|
|
145
|
-
if (!styleTag) {
|
|
146
|
-
styleTag = document.createElement('style');
|
|
147
|
-
styleTag.setAttribute(FONT_CSS_TAG_BASE64, 'true');
|
|
148
|
-
document.head.appendChild(styleTag);
|
|
149
|
-
}
|
|
150
|
-
if (!styleTag.sheet) {
|
|
151
|
-
await new Promise(resolve => setTimeout(resolve, 10));
|
|
152
|
-
}
|
|
153
|
-
if (!styleTag.sheet)
|
|
154
|
-
return;
|
|
155
|
-
let existingFonts = Array.from(styleTag.sheet.cssRules).map((rule) => {
|
|
156
|
-
const match = rule.cssText.match(/font-family: "([^"]+)"/);
|
|
157
|
-
return match ? match[1] : null;
|
|
158
|
-
}).filter((font) => font !== null);
|
|
159
|
-
if (!existingFonts.includes(font)) {
|
|
160
|
-
const base64Url = await fetchFontAsBase64(fontUrl);
|
|
161
|
-
const newFontRule = `@font-face {
|
|
162
|
-
font-family: "${font}";
|
|
163
|
-
src: local("${font}"), url("${base64Url}");
|
|
164
|
-
}`;
|
|
165
|
-
try {
|
|
166
|
-
styleTag.sheet.insertRule(newFontRule, styleTag.sheet.cssRules.length);
|
|
167
|
-
styleTag.textContent += newFontRule;
|
|
168
|
-
}
|
|
169
|
-
catch (e) {
|
|
170
|
-
console.error('Failed to insert font rule:', e);
|
|
171
|
-
}
|
|
172
|
-
}
|
|
173
|
-
}
|
|
174
|
-
function getBase64CustomFontsStyle() {
|
|
175
|
-
const styleTag = document.querySelector(`style[${FONT_CSS_TAG_BASE64}]`);
|
|
176
|
-
return styleTag?.textContent || '';
|
|
177
|
-
}
|
|
178
|
-
async function loadFont(font) {
|
|
179
|
-
await addCustomFontBase64(font);
|
|
180
|
-
}
|
package/dist/index.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAgB,MAAM,OAAO,CAAC;AACrC,OAAO,2BAA2B,CAAC;AAEnC,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAC9C,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAC1C,cAAM,YAAY;IAChB,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAe;IACtC,OAAO,CAAC,KAAK,CAAsB;IAC5B,IAAI,EAAE,GAAG,GAAG,IAAI,CAAQ;IAE/B,OAAO;IAEP,MAAM,CAAC,WAAW;IAOZ,IAAI,CAAC,GAAG,EAAE,GAAG;IAwDnB,QAAQ;IAOR,SAAS;IAOT,OAAO,CAAC,aAAa;IA+Bd,aAAa,IAAI,OAAO;IAQxB,QAAQ,CACb,QAAQ,EAAE,CAAC,IAAI,EAAE,GAAG,KAAK,IAAI,EAC7B,KAAK,SAAI,EACT,OAAO,CAAC,EAAE,GAAG,GACZ,IAAI;CA4BR;AAED,eAAO,MAAM,YAAY,cAA6B,CAAC"}
|
package/dist/index.esm.js
DELETED
|
@@ -1,141 +0,0 @@
|
|
|
1
|
-
import Quill, { Delta } from "quill";
|
|
2
|
-
import "quill/dist/quill.core.css";
|
|
3
|
-
export { TextEditTool } from "./TextEditTool";
|
|
4
|
-
export { TextEditor } from "./TextEditor";
|
|
5
|
-
class QuillManager {
|
|
6
|
-
constructor() {
|
|
7
|
-
this.quill = null;
|
|
8
|
-
this.app_ = null;
|
|
9
|
-
}
|
|
10
|
-
static getInstance() {
|
|
11
|
-
if (!QuillManager.instance) {
|
|
12
|
-
QuillManager.instance = new QuillManager();
|
|
13
|
-
}
|
|
14
|
-
return QuillManager.instance;
|
|
15
|
-
}
|
|
16
|
-
async init(app) {
|
|
17
|
-
this.app_ = app;
|
|
18
|
-
if (this.quill)
|
|
19
|
-
return this.quill;
|
|
20
|
-
let el = document.getElementById("textInnerEditor");
|
|
21
|
-
if (!el) {
|
|
22
|
-
el = document.createElement("div");
|
|
23
|
-
el.id = "textInnerEditor";
|
|
24
|
-
el.style.position = "fixed";
|
|
25
|
-
el.style.transformOrigin = "left top";
|
|
26
|
-
el.style.overflowWrap = "break-word";
|
|
27
|
-
el.style.wordBreak = "break-all";
|
|
28
|
-
el.style.visibility = "hidden";
|
|
29
|
-
document.body.appendChild(el);
|
|
30
|
-
this.quill = new Quill("#textInnerEditor", {
|
|
31
|
-
theme: undefined,
|
|
32
|
-
modules: {
|
|
33
|
-
toolbar: false,
|
|
34
|
-
keyboard: {
|
|
35
|
-
bindings: {
|
|
36
|
-
enter: {
|
|
37
|
-
key: "Enter",
|
|
38
|
-
handler: (range) => {
|
|
39
|
-
const [line] = this.quill.getLine(range.index);
|
|
40
|
-
const BlockBlot = Quill.import("blots/block");
|
|
41
|
-
if (!BlockBlot?.bubbleFormats)
|
|
42
|
-
return true;
|
|
43
|
-
const lineFormats = BlockBlot.bubbleFormats(line);
|
|
44
|
-
const delta = new Delta()
|
|
45
|
-
.retain(range.index)
|
|
46
|
-
.delete(range.length)
|
|
47
|
-
.insert("\n", lineFormats);
|
|
48
|
-
this.quill.updateContents(delta, Quill.sources.USER);
|
|
49
|
-
this.quill.setSelection(range.index + 1, Quill.sources.SILENT);
|
|
50
|
-
return false;
|
|
51
|
-
},
|
|
52
|
-
},
|
|
53
|
-
},
|
|
54
|
-
},
|
|
55
|
-
},
|
|
56
|
-
});
|
|
57
|
-
this.app_.editor.quill = this.quill;
|
|
58
|
-
this.registerFonts();
|
|
59
|
-
return this.quill;
|
|
60
|
-
}
|
|
61
|
-
else {
|
|
62
|
-
this.quill = this.app_.editor.quill;
|
|
63
|
-
}
|
|
64
|
-
}
|
|
65
|
-
getQuill() {
|
|
66
|
-
if (!this.quill) {
|
|
67
|
-
throw new Error("Quill editor not initialized. Call init() first.");
|
|
68
|
-
}
|
|
69
|
-
return this.quill;
|
|
70
|
-
}
|
|
71
|
-
getCanvas() {
|
|
72
|
-
if (!this.app_) {
|
|
73
|
-
throw new Error("app_ editor not initialized. Call init() first.");
|
|
74
|
-
}
|
|
75
|
-
return this.app_;
|
|
76
|
-
}
|
|
77
|
-
registerFonts() {
|
|
78
|
-
const FontAttributor = Quill.import("attributors/class/font");
|
|
79
|
-
FontAttributor.whitelist = [
|
|
80
|
-
"Roboto",
|
|
81
|
-
"RobotoMono",
|
|
82
|
-
"Inter",
|
|
83
|
-
"OpenSans",
|
|
84
|
-
"Montserrat",
|
|
85
|
-
"RobotoCondensed",
|
|
86
|
-
"Arimo",
|
|
87
|
-
"NotoSans",
|
|
88
|
-
"NotoSansSymbols",
|
|
89
|
-
"Merriweather",
|
|
90
|
-
"PlayfairDisplay",
|
|
91
|
-
"NotoSerif",
|
|
92
|
-
"Lato",
|
|
93
|
-
"Spectral",
|
|
94
|
-
"DancingScript",
|
|
95
|
-
"NotoSansSimplifiedChinese",
|
|
96
|
-
"NotoSerifSimplifiedChinese",
|
|
97
|
-
"NotoSansTraditionalChinese",
|
|
98
|
-
"NotoSansHongKong",
|
|
99
|
-
"NotoSerifTraditionalChinese",
|
|
100
|
-
"NotoSerifHongKong",
|
|
101
|
-
"NotoSansJapanese",
|
|
102
|
-
"NotoSansKorean",
|
|
103
|
-
"Poppins",
|
|
104
|
-
];
|
|
105
|
-
Quill.register(FontAttributor, true);
|
|
106
|
-
}
|
|
107
|
-
isMultiSelect() {
|
|
108
|
-
if (!this.app_.editor)
|
|
109
|
-
return false;
|
|
110
|
-
if (this.app_.editor.multiple === true) {
|
|
111
|
-
return true;
|
|
112
|
-
}
|
|
113
|
-
else {
|
|
114
|
-
return false;
|
|
115
|
-
}
|
|
116
|
-
}
|
|
117
|
-
dateEdit(callback, level = 0, listNew) {
|
|
118
|
-
const { editor } = this.app_;
|
|
119
|
-
const list = listNew ? listNew : editor.leafList.list;
|
|
120
|
-
const applyCallback = (leaf) => {
|
|
121
|
-
if (level && (leaf.tag === "Box" || leaf.name === "Text")) {
|
|
122
|
-
callback(leaf.children?.[0] || leaf);
|
|
123
|
-
}
|
|
124
|
-
else {
|
|
125
|
-
callback(leaf);
|
|
126
|
-
}
|
|
127
|
-
};
|
|
128
|
-
if (!list.length)
|
|
129
|
-
return;
|
|
130
|
-
if (Array.isArray(list) && list.length > 1) {
|
|
131
|
-
this.app_.lockLayout();
|
|
132
|
-
list.forEach(applyCallback);
|
|
133
|
-
this.app_.unlockLayout();
|
|
134
|
-
editor.updateEditBox();
|
|
135
|
-
}
|
|
136
|
-
else {
|
|
137
|
-
applyCallback(list[0]);
|
|
138
|
-
}
|
|
139
|
-
}
|
|
140
|
-
}
|
|
141
|
-
export const quillManager = QuillManager.getInstance();
|
package/dist/index.js
DELETED
|
@@ -1,179 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
-
}) : function(o, v) {
|
|
16
|
-
o["default"] = v;
|
|
17
|
-
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
-
var ownKeys = function(o) {
|
|
20
|
-
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
-
var ar = [];
|
|
22
|
-
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
-
return ar;
|
|
24
|
-
};
|
|
25
|
-
return ownKeys(o);
|
|
26
|
-
};
|
|
27
|
-
return function (mod) {
|
|
28
|
-
if (mod && mod.__esModule) return mod;
|
|
29
|
-
var result = {};
|
|
30
|
-
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
-
__setModuleDefault(result, mod);
|
|
32
|
-
return result;
|
|
33
|
-
};
|
|
34
|
-
})();
|
|
35
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
-
exports.quillManager = exports.TextEditor = exports.TextEditTool = void 0;
|
|
37
|
-
const quill_1 = __importStar(require("quill"));
|
|
38
|
-
require("quill/dist/quill.core.css");
|
|
39
|
-
var TextEditTool_1 = require("./TextEditTool");
|
|
40
|
-
Object.defineProperty(exports, "TextEditTool", { enumerable: true, get: function () { return TextEditTool_1.TextEditTool; } });
|
|
41
|
-
var TextEditor_1 = require("./TextEditor");
|
|
42
|
-
Object.defineProperty(exports, "TextEditor", { enumerable: true, get: function () { return TextEditor_1.TextEditor; } });
|
|
43
|
-
class QuillManager {
|
|
44
|
-
constructor() {
|
|
45
|
-
this.quill = null;
|
|
46
|
-
this.app_ = null;
|
|
47
|
-
}
|
|
48
|
-
static getInstance() {
|
|
49
|
-
if (!QuillManager.instance) {
|
|
50
|
-
QuillManager.instance = new QuillManager();
|
|
51
|
-
}
|
|
52
|
-
return QuillManager.instance;
|
|
53
|
-
}
|
|
54
|
-
async init(app) {
|
|
55
|
-
this.app_ = app;
|
|
56
|
-
if (this.quill)
|
|
57
|
-
return this.quill;
|
|
58
|
-
let el = document.getElementById("textInnerEditor");
|
|
59
|
-
if (!el) {
|
|
60
|
-
el = document.createElement("div");
|
|
61
|
-
el.id = "textInnerEditor";
|
|
62
|
-
el.style.position = "fixed";
|
|
63
|
-
el.style.transformOrigin = "left top";
|
|
64
|
-
el.style.overflowWrap = "break-word";
|
|
65
|
-
el.style.wordBreak = "break-all";
|
|
66
|
-
el.style.visibility = "hidden";
|
|
67
|
-
document.body.appendChild(el);
|
|
68
|
-
this.quill = new quill_1.default("#textInnerEditor", {
|
|
69
|
-
theme: undefined,
|
|
70
|
-
modules: {
|
|
71
|
-
toolbar: false,
|
|
72
|
-
keyboard: {
|
|
73
|
-
bindings: {
|
|
74
|
-
enter: {
|
|
75
|
-
key: "Enter",
|
|
76
|
-
handler: (range) => {
|
|
77
|
-
const [line] = this.quill.getLine(range.index);
|
|
78
|
-
const BlockBlot = quill_1.default.import("blots/block");
|
|
79
|
-
if (!BlockBlot?.bubbleFormats)
|
|
80
|
-
return true;
|
|
81
|
-
const lineFormats = BlockBlot.bubbleFormats(line);
|
|
82
|
-
const delta = new quill_1.Delta()
|
|
83
|
-
.retain(range.index)
|
|
84
|
-
.delete(range.length)
|
|
85
|
-
.insert("\n", lineFormats);
|
|
86
|
-
this.quill.updateContents(delta, quill_1.default.sources.USER);
|
|
87
|
-
this.quill.setSelection(range.index + 1, quill_1.default.sources.SILENT);
|
|
88
|
-
return false;
|
|
89
|
-
},
|
|
90
|
-
},
|
|
91
|
-
},
|
|
92
|
-
},
|
|
93
|
-
},
|
|
94
|
-
});
|
|
95
|
-
this.app_.editor.quill = this.quill;
|
|
96
|
-
this.registerFonts();
|
|
97
|
-
return this.quill;
|
|
98
|
-
}
|
|
99
|
-
else {
|
|
100
|
-
this.quill = this.app_.editor.quill;
|
|
101
|
-
}
|
|
102
|
-
}
|
|
103
|
-
getQuill() {
|
|
104
|
-
if (!this.quill) {
|
|
105
|
-
throw new Error("Quill editor not initialized. Call init() first.");
|
|
106
|
-
}
|
|
107
|
-
return this.quill;
|
|
108
|
-
}
|
|
109
|
-
getCanvas() {
|
|
110
|
-
if (!this.app_) {
|
|
111
|
-
throw new Error("app_ editor not initialized. Call init() first.");
|
|
112
|
-
}
|
|
113
|
-
return this.app_;
|
|
114
|
-
}
|
|
115
|
-
registerFonts() {
|
|
116
|
-
const FontAttributor = quill_1.default.import("attributors/class/font");
|
|
117
|
-
FontAttributor.whitelist = [
|
|
118
|
-
"Roboto",
|
|
119
|
-
"RobotoMono",
|
|
120
|
-
"Inter",
|
|
121
|
-
"OpenSans",
|
|
122
|
-
"Montserrat",
|
|
123
|
-
"RobotoCondensed",
|
|
124
|
-
"Arimo",
|
|
125
|
-
"NotoSans",
|
|
126
|
-
"NotoSansSymbols",
|
|
127
|
-
"Merriweather",
|
|
128
|
-
"PlayfairDisplay",
|
|
129
|
-
"NotoSerif",
|
|
130
|
-
"Lato",
|
|
131
|
-
"Spectral",
|
|
132
|
-
"DancingScript",
|
|
133
|
-
"NotoSansSimplifiedChinese",
|
|
134
|
-
"NotoSerifSimplifiedChinese",
|
|
135
|
-
"NotoSansTraditionalChinese",
|
|
136
|
-
"NotoSansHongKong",
|
|
137
|
-
"NotoSerifTraditionalChinese",
|
|
138
|
-
"NotoSerifHongKong",
|
|
139
|
-
"NotoSansJapanese",
|
|
140
|
-
"NotoSansKorean",
|
|
141
|
-
"Poppins",
|
|
142
|
-
];
|
|
143
|
-
quill_1.default.register(FontAttributor, true);
|
|
144
|
-
}
|
|
145
|
-
isMultiSelect() {
|
|
146
|
-
if (!this.app_.editor)
|
|
147
|
-
return false;
|
|
148
|
-
if (this.app_.editor.multiple === true) {
|
|
149
|
-
return true;
|
|
150
|
-
}
|
|
151
|
-
else {
|
|
152
|
-
return false;
|
|
153
|
-
}
|
|
154
|
-
}
|
|
155
|
-
dateEdit(callback, level = 0, listNew) {
|
|
156
|
-
const { editor } = this.app_;
|
|
157
|
-
const list = listNew ? listNew : editor.leafList.list;
|
|
158
|
-
const applyCallback = (leaf) => {
|
|
159
|
-
if (level && (leaf.tag === "Box" || leaf.name === "Text")) {
|
|
160
|
-
callback(leaf.children?.[0] || leaf);
|
|
161
|
-
}
|
|
162
|
-
else {
|
|
163
|
-
callback(leaf);
|
|
164
|
-
}
|
|
165
|
-
};
|
|
166
|
-
if (!list.length)
|
|
167
|
-
return;
|
|
168
|
-
if (Array.isArray(list) && list.length > 1) {
|
|
169
|
-
this.app_.lockLayout();
|
|
170
|
-
list.forEach(applyCallback);
|
|
171
|
-
this.app_.unlockLayout();
|
|
172
|
-
editor.updateEditBox();
|
|
173
|
-
}
|
|
174
|
-
else {
|
|
175
|
-
applyCallback(list[0]);
|
|
176
|
-
}
|
|
177
|
-
}
|
|
178
|
-
}
|
|
179
|
-
exports.quillManager = QuillManager.getInstance();
|
package/dist/utils.d.ts
DELETED
package/dist/utils.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,cAAc,GAAU,IAAI,GAAG,EAAE,aAAa,GAAG,EAAE,UAAU,GAAG,kBAgG5E,CAAA;AAoED,eAAO,MAAM,WAAW,GAAI,KAAK,MAAM,EAAE,QAAQ,GAAG,EAAE,aAAa,GAAG,SA+HrE,CAAA"}
|