forked from nggepe/bracket-editor-js
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
186 lines (185 loc) · 8.62 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
const bracketEditor = require('./src/bracket-editor')
module.exports = {
convert: ({ data, bracket = [
{
open: "\\*\\*",
close: "\\*\\*",
opentag: "<b>",
closetag: "</b>"
},
{
open: "\\*",
close: "\\*",
opentag: "<i>",
closetag: "</i>"
},
{
open: "```",
close: "```",
opentag: "<pre style='background: rgba(255,255,255,0.4);'><code>",
closetag: "</code></pre>",
},
{
open: "`",
close: "`",
opentag: "<code>",
closetag: "</code>"
},
{
open: "--",
close: "--",
opentag: "<center>",
closetag: "</center>"
}
],
imageSupport = {
btnclass: "btn-b-editor",
btnstyle: "",
innerHTML: `<svg fill="#f2f2f2" id="bold" enable-background="new 0 0 24 24" height="12" viewBox="0 0 24 24" width="12" xmlns="http://www.w3.org/2000/svg"><g><g><path d="m6.25 19.5c-1.601 0-3.025-1.025-3.542-2.551l-.035-.115c-.122-.404-.173-.744-.173-1.084v-6.818l-2.426 8.098c-.312 1.191.399 2.426 1.592 2.755l15.463 4.141c.193.05.386.074.576.074.996 0 1.906-.661 2.161-1.635l.901-2.865z"/></g><path d="m9 9c1.103 0 2-.897 2-2s-.897-2-2-2-2 .897-2 2 .897 2 2 2z"/></g><path d="m21.5 2h-15c-1.378 0-2.5 1.122-2.5 2.5v11c0 1.378 1.122 2.5 2.5 2.5h15c1.378 0 2.5-1.122 2.5-2.5v-11c0-1.378-1.122-2.5-2.5-2.5zm-15 2h15c.276 0 .5.224.5.5v7.099l-3.159-3.686c-.335-.393-.82-.603-1.341-.615-.518.003-1.004.233-1.336.631l-3.714 4.458-1.21-1.207c-.684-.684-1.797-.684-2.48 0l-2.76 2.759v-9.439c0-.276.224-.5.5-.5z"/></svg>`
},
tag = {
hashTag: { active: true, class: "gp-editor-tag", style: "", ontap: () => { } },
atTag: { active: true, class: "gp-editor-tag", style: "", ontap: () => { } },
},
callback = function (cb) { } }) => {
return require('./src/bracket-editor-converter').convert({
bracket: typeof bracket === 'undefined' ? [
{
open: "\\*\\*",
close: "\\*\\*",
opentag: "<b>",
closetag: "</b>"
},
{
open: "\\*",
close: "\\*",
opentag: "<i>",
closetag: "</i>"
},
{
open: "```",
close: "```",
opentag: "<pre style='background: rgba(255,255,255,0.4);'><code>",
closetag: "</code></pre>",
},
{
open: "`",
close: "`",
opentag: "<code>",
closetag: "</code>"
},
{
open: "--",
close: "--",
opentag: "<center>",
closetag: "</center>"
}
] : bracket,
data: data,
tag: typeof tag === 'undefined' ? {
hashTag: { active: true, class: "gp-editor-tag", style: "", ontap: () => { } },
atTag: { active: true, class: "gp-editor-tag", style: "", ontap: () => { } },
} : tag,
callback: typeof callback === "undefined" ? function () { } : callback,
imageSupport: typeof imageSupport === "undefined" ? {
btnclass: "btn-b-editor",
btnstyle: "",
innerHTML: `<svg fill="#f2f2f2" id="bold" enable-background="new 0 0 24 24" height="12" viewBox="0 0 24 24" width="12" xmlns="http://www.w3.org/2000/svg"><g><g><path d="m6.25 19.5c-1.601 0-3.025-1.025-3.542-2.551l-.035-.115c-.122-.404-.173-.744-.173-1.084v-6.818l-2.426 8.098c-.312 1.191.399 2.426 1.592 2.755l15.463 4.141c.193.05.386.074.576.074.996 0 1.906-.661 2.161-1.635l.901-2.865z"/></g><path d="m9 9c1.103 0 2-.897 2-2s-.897-2-2-2-2 .897-2 2 .897 2 2 2z"/></g><path d="m21.5 2h-15c-1.378 0-2.5 1.122-2.5 2.5v11c0 1.378 1.122 2.5 2.5 2.5h15c1.378 0 2.5-1.122 2.5-2.5v-11c0-1.378-1.122-2.5-2.5-2.5zm-15 2h15c.276 0 .5.224.5.5v7.099l-3.159-3.686c-.335-.393-.82-.603-1.341-.615-.518.003-1.004.233-1.336.631l-3.714 4.458-1.21-1.207c-.684-.684-1.797-.684-2.48 0l-2.76 2.759v-9.439c0-.276.224-.5.5-.5z"/></svg>`
} : imageSupport
})
},
bracketEditor: ({
elEditor = "gp-textarea",
elOutput = "gp-text-output",
bracket = [
{
open: "\\*\\*",
close: "\\*\\*",
opentag: "<b>",
closetag: "</b>"
},
{
open: "\\*",
close: "\\*",
opentag: "<i>",
closetag: "</i>"
},
{
open: "```",
close: "```",
opentag: "<pre style='background: rgba(255,255,255,0.4);'><code>",
closetag: "</code></pre>",
},
{
open: "`",
close: "`",
opentag: "<code>",
closetag: "</code>"
},
{
open: "--",
close: "--",
opentag: "<center>",
closetag: "</center>"
}
],
button = [
{
innerhtml: "<b>B</b>",
class: "btn-b-editor",
},
{
innerhtml: "I",
class: "btn-b-editor",
},
{
innerhtml: "{<>}",
class: "btn-b-editor",
},
{
innerhtml: "<>",
class: "btn-b-editor",
},
{
innerhtml: `<svg version="1.1" fill="#F2F2F2" width="12px" height="12px" id="Capa_1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px" viewBox="0 0 426.667 426.667" style="enable-background:new 0 0 426.667 426.667;" xml:space="preserve"> <g> <rect x="85.333" y="320" width="256" height="42.667"/> </g> <g> <rect x="64" y="149.333" width="298.667" height="42.667"/> </g> <g> <rect y="64" width="426.667" height="42.667"/> </g> <g> <rect x="21.333" y="234.667" width="384" height="42.667"/> </g></svg>`,
class: "btn-b-editor",
},
],
textareaClass = "gp-text-editor",
textareaStyle = "width: calc(99%); margin-right: 20px;",
callbackValue = function (defaults, generated) { },
imageSupport = {
showButton: true,
btnclass: "btn-b-editor",
btnstyle: "",
innerHTML: `<svg fill="#f2f2f2" id="bold" enable-background="new 0 0 24 24" height="12" viewBox="0 0 24 24" width="12" xmlns="http://www.w3.org/2000/svg"><g><g><path d="m6.25 19.5c-1.601 0-3.025-1.025-3.542-2.551l-.035-.115c-.122-.404-.173-.744-.173-1.084v-6.818l-2.426 8.098c-.312 1.191.399 2.426 1.592 2.755l15.463 4.141c.193.05.386.074.576.074.996 0 1.906-.661 2.161-1.635l.901-2.865z"/></g><path d="m9 9c1.103 0 2-.897 2-2s-.897-2-2-2-2 .897-2 2 .897 2 2 2z"/></g><path d="m21.5 2h-15c-1.378 0-2.5 1.122-2.5 2.5v11c0 1.378 1.122 2.5 2.5 2.5h15c1.378 0 2.5-1.122 2.5-2.5v-11c0-1.378-1.122-2.5-2.5-2.5zm-15 2h15c.276 0 .5.224.5.5v7.099l-3.159-3.686c-.335-.393-.82-.603-1.341-.615-.518.003-1.004.233-1.336.631l-3.714 4.458-1.21-1.207c-.684-.684-1.797-.684-2.48 0l-2.76 2.759v-9.439c0-.276.224-.5.5-.5z"/></svg>`,
fileHandler: (file) => console.log(file)
},
tag = {
hashTag: { active: true, class: "gp-editor-tag", style: "", ontap: () => { } },
atTag: { active: true, class: "gp-editor-tag", style: "", ontap: () => { } },
}
}) => {
bracketEditor({
elEditor: elEditor,
elOutput: elOutput,
bracket: bracket,
button: button,
textareaClass: textareaClass,
textareaStyle: textareaStyle,
callbackValue: callbackValue,
imageSupport: {
showButton: typeof imageSupport.showButton === "undefined" ? true : imageSupport.showButton,
btnclass: typeof imageSupport.btnclass === "undefined" ? "btn-b-editor" : imageSupport.btnclass,
btnstyle: typeof imageSupport.btnstyle === "undefined" ? "" : imageSupport.btnstyle,
innerHTML: typeof imageSupport.innerHTML === "undefined" ? `<svg fill="#f2f2f2" id="bold" enable-background="new 0 0 24 24" height="12" viewBox="0 0 24 24" width="12" xmlns="http://www.w3.org/2000/svg"><g><g><path d="m6.25 19.5c-1.601 0-3.025-1.025-3.542-2.551l-.035-.115c-.122-.404-.173-.744-.173-1.084v-6.818l-2.426 8.098c-.312 1.191.399 2.426 1.592 2.755l15.463 4.141c.193.05.386.074.576.074.996 0 1.906-.661 2.161-1.635l.901-2.865z"/></g><path d="m9 9c1.103 0 2-.897 2-2s-.897-2-2-2-2 .897-2 2 .897 2 2 2z"/></g><path d="m21.5 2h-15c-1.378 0-2.5 1.122-2.5 2.5v11c0 1.378 1.122 2.5 2.5 2.5h15c1.378 0 2.5-1.122 2.5-2.5v-11c0-1.378-1.122-2.5-2.5-2.5zm-15 2h15c.276 0 .5.224.5.5v7.099l-3.159-3.686c-.335-.393-.82-.603-1.341-.615-.518.003-1.004.233-1.336.631l-3.714 4.458-1.21-1.207c-.684-.684-1.797-.684-2.48 0l-2.76 2.759v-9.439c0-.276.224-.5.5-.5z"/></svg>` : imageSupport.innerHTML,
fileHandler: typeof imageSupport.fileHandler === "undefined" ? file => console.log(file, "ini default") : imageSupport.fileHandler
},
tag: {
hashTag: typeof tag.hashTag === 'undefined' ? { class: "gp-editor-tag", style: "", ontap: () => { } } : tag.hashTag,
atTag: typeof tag.atTag === 'undefined' ? { class: "gp-editor-tag", style: "", ontap: () => { } } : tag.atTag,
}
})
},
seturl: (url) => { require('./src/bracket-editor-image-send')(url) }
};