|
56 | 56 | return __assign.apply(this, arguments); |
57 | 57 | }; |
58 | 58 |
|
59 | | - __$styleInject("#editor-resizer {\n position: absolute;\n border: 1px dashed #fff;\n background-color: rgba(0, 0, 0, 0.5);\n}\n#editor-resizer .handler {\n position: absolute;\n right: -5px;\n bottom: -5px;\n width: 10px;\n height: 10px;\n border: 1px solid #333;\n background-color: rgba(255, 255, 255, 0.8);\n cursor: nwse-resize;\n user-select: none;\n}\n#editor-resizer .toolbar {\n position: absolute;\n top: -5em;\n left: 50%;\n padding: 0.5em;\n border: 1px solid #fff;\n border-radius: 3px;\n background-color: #fff;\n box-shadow: 0 0 3px rgba(0, 0, 0, 0.5);\n transform: translateX(-50%);\n}\n#editor-resizer .toolbar .group {\n display: flex;\n border: 1px solid #aaa;\n border-radius: 6px;\n overflow: hidden;\n white-space: nowrap;\n text-align: center;\n}\n#editor-resizer .toolbar .group:not(:first-child) {\n margin-top: 0.5em;\n}\n#editor-resizer .toolbar .group .btn {\n flex: 1 0 0;\n text-align: center;\n width: 25%;\n padding: 0 0.5rem;\n display: inline-block;\n color: rgba(0, 0, 0, 0.65);\n vertical-align: top;\n line-height: 2;\n user-select: none;\n}\n#editor-resizer .toolbar .group .btn.btn-group {\n padding: 0;\n display: inline-flex;\n line-height: 2em;\n}\n#editor-resizer .toolbar .group .btn.btn-group .inner-btn {\n flex: 1 0 0;\n font-size: 2em;\n width: 50%;\n cursor: pointer;\n}\n#editor-resizer .toolbar .group .btn.btn-group .inner-btn:first-child {\n border-right: 1px solid #ddd;\n}\n#editor-resizer .toolbar .group .btn.btn-group .inner-btn:active {\n transform: scale(0.8);\n}\n#editor-resizer .toolbar .group .btn:not(:last-child) {\n border-right: 1px solid #bbb;\n}\n#editor-resizer .toolbar .group .btn:not(.btn-group):active {\n background-color: rgba(0, 0, 0, 0.1);\n}\n"); |
| 59 | + __$styleInject("#editor-resizer {\n position: absolute;\n border: 1px dashed #fff;\n background-color: rgba(0, 0, 0, 0.5);\n}\n#editor-resizer .handler {\n position: absolute;\n right: -5px;\n bottom: -5px;\n width: 10px;\n height: 10px;\n border: 1px solid #333;\n background-color: rgba(255, 255, 255, 0.8);\n cursor: nwse-resize;\n user-select: none;\n}\n#editor-resizer .toolbar {\n position: absolute;\n top: -3em;\n left: 50%;\n padding: 0.5em;\n border: 1px solid #fff;\n border-radius: 3px;\n background-color: #fff;\n box-shadow: 0 0 3px rgba(0, 0, 0, 0.5);\n transform: translateX(-50%);\n}\n#editor-resizer .toolbar .group {\n display: flex;\n border: 1px solid #aaa;\n border-radius: 6px;\n overflow: hidden;\n white-space: nowrap;\n text-align: center;\n}\n#editor-resizer .toolbar .group:not(:first-child) {\n margin-top: 0.5em;\n}\n#editor-resizer .toolbar .group .btn {\n flex: 1 0 0;\n text-align: center;\n width: 25%;\n padding: 0 0.5rem;\n display: inline-block;\n color: rgba(0, 0, 0, 0.65);\n vertical-align: top;\n line-height: 2;\n user-select: none;\n}\n#editor-resizer .toolbar .group .btn.btn-group {\n padding: 0;\n display: inline-flex;\n line-height: 2em;\n}\n#editor-resizer .toolbar .group .btn.btn-group .inner-btn {\n flex: 1 0 0;\n font-size: 2em;\n width: 50%;\n cursor: pointer;\n}\n#editor-resizer .toolbar .group .btn.btn-group .inner-btn:first-child {\n border-right: 1px solid #ddd;\n}\n#editor-resizer .toolbar .group .btn.btn-group .inner-btn:active {\n transform: scale(0.8);\n}\n#editor-resizer .toolbar .group .btn:not(:last-child) {\n border-right: 1px solid #bbb;\n}\n#editor-resizer .toolbar .group .btn:not(.btn-group):active {\n background-color: rgba(0, 0, 0, 0.1);\n}\n#editor-resizer .last-item {\n margin-right: 5px;\n}\n#editor-resizer .showSize {\n position: absolute;\n top: 50%;\n left: 50%;\n padding: 0.1em;\n border: 1px solid rgba(255, 255, 255, 0.8);\n border-radius: 2px;\n background-color: rgba(255, 255, 255, 0.8);\n box-shadow: 0 0 3px rgba(0, 0, 0, 0.5);\n transform: translateX(-50%);\n}\n"); |
60 | 60 |
|
61 | 61 | var I18n = /** @class */ (function () { |
62 | 62 | function I18n(config) { |
|
102 | 102 | } |
103 | 103 | return ResizeElement; |
104 | 104 | }(HTMLElement)); |
105 | | - var templateWithoutToolbar = "\n<div class=\"handler\" title=\"{0}\"></div>\n"; |
106 | | - var template = "\n<div class=\"handler\" title=\"{0}\"></div>\n<div class=\"toolbar\">\n <div class=\"group\">\n <a class=\"btn\" data-width=\"100%\">100%</a>\n <a class=\"btn\" data-width=\"50%\">50%</a>\n <a class=\"btn btn-group\">\n <span data-width=\"-5\" class=\"inner-btn\">\uFE63</span>\n <span data-width=\"5\" class=\"inner-btn\">\uFE62</span>\n </a>\n <a data-width=\"auto\" class=\"btn\">{4}</a>\n </div>\n <div class=\"group\">\n <a class=\"btn\" data-float=\"left\">{1}</a>\n <a class=\"btn\" data-float=\"center\">{2}</a>\n <a class=\"btn\" data-float=\"right\">{3}</a>\n <a data-float=\"none\" class=\"btn\">{4}</a>\n </div>\n</div>\n"; |
107 | | - var hiddenToobar = false; |
108 | | - var noUseStyle = false; |
| 105 | + var templateUsed; |
| 106 | + var pluginOptions; |
109 | 107 | var ResizePlugin = /** @class */ (function () { |
110 | 108 | function ResizePlugin(resizeTarget, container, options) { |
111 | 109 | this.resizer = null; |
112 | 110 | this.startResizePosition = null; |
113 | 111 | this.i18n = new I18n((options === null || options === void 0 ? void 0 : options.locale) || defaultLocale); |
114 | | - // options?.toolbar ? showToolbar = true: showToolbar = false |
115 | | - hiddenToobar = (options === null || options === void 0 ? void 0 : options.hiddenToobar) || false; |
116 | | - noUseStyle = (options === null || options === void 0 ? void 0 : options.noUseStyle) || false; |
| 112 | + templateUsed = this.createToobar(options); |
117 | 113 | this.resizeTarget = resizeTarget; |
118 | 114 | if (!resizeTarget.originSize) { |
119 | 115 | resizeTarget.originSize = { |
120 | 116 | width: resizeTarget.clientWidth, |
121 | | - height: resizeTarget.clientHeight |
| 117 | + height: resizeTarget.clientHeight, |
122 | 118 | }; |
123 | 119 | } |
| 120 | + pluginOptions = options; |
124 | 121 | this.container = container; |
125 | 122 | this.initResizer(); |
126 | 123 | this.positionResizerToTarget(resizeTarget); |
|
135 | 132 | if (!resizer) { |
136 | 133 | resizer = document.createElement("div"); |
137 | 134 | resizer.setAttribute("id", "editor-resizer"); |
138 | | - resizer.innerHTML = format(hiddenToobar ? templateWithoutToolbar : template, this.i18n.findLabel("altTip"), this.i18n.findLabel("floatLeft"), this.i18n.findLabel("center"), this.i18n.findLabel("floatRight"), this.i18n.findLabel("restore")); |
| 135 | + resizer.innerHTML = format(templateUsed, this.i18n.findLabel("altTip"), this.i18n.findLabel("floatLeft"), this.i18n.findLabel("center"), this.i18n.findLabel("floatRight"), this.i18n.findLabel("restore")); |
139 | 136 | this.container.appendChild(resizer); |
140 | 137 | } |
141 | 138 | this.resizer = resizer; |
142 | 139 | }; |
| 140 | + ResizePlugin.prototype.createToobar = function (options) { |
| 141 | + var _a, _b; |
| 142 | + var templateBasicToolbar = "<div class=\"handler\" title=\"{0}\"></div>"; |
| 143 | + var size = "<div class=\"showSize\" name=\"ql-size\" title=\"{0}\">{size}</div>"; |
| 144 | + var sizeTools = "<div class=\"group\">\n <a class=\"btn\" data-width=\"100%\">100%</a>\n <a class=\"btn\" data-width=\"50%\">50%</a>\n <a class=\"btn btn-group\">\n <span data-width=\"-5\" class=\"inner-btn\">\uFE63</span>\n <span data-width=\"5\" class=\"inner-btn\">\uFE62</span>\n </a>\n <a data-width=\"auto\" class=\"btn last-item\">{4}</a>\n </div>"; |
| 145 | + var alingTools = "<div class=\"group\">\n <a class=\"btn\" data-float=\"left\">{1}</a>\n <a class=\"btn\" data-float=\"center\">{2}</a>\n <a class=\"btn\" data-float=\"right\">{3}</a>\n <a data-float=\"none\" class=\"btn last-item\">{4}</a>\n </div>"; |
| 146 | + var toolBarTemplate = "<div class=\"toolbar\">\n " + (((_a = options === null || options === void 0 ? void 0 : options.toolbar) === null || _a === void 0 ? void 0 : _a.sizeTools) !== false ? sizeTools : "") + "\n " + (((_b = options === null || options === void 0 ? void 0 : options.toolbar) === null || _b === void 0 ? void 0 : _b.alingTools) !== false ? alingTools : "") + "\n </div>"; |
| 147 | + return "" + templateBasicToolbar + ((options === null || options === void 0 ? void 0 : options.showSize) === true ? size : "") + ((options === null || options === void 0 ? void 0 : options.showToolbar) !== false ? toolBarTemplate : ""); |
| 148 | + }; |
143 | 149 | ResizePlugin.prototype.positionResizerToTarget = function (el) { |
144 | 150 | if (this.resizer !== null) { |
145 | 151 | this.resizer.style.setProperty("left", el.offsetLeft + "px"); |
146 | 152 | this.resizer.style.setProperty("top", el.offsetTop + "px"); |
147 | 153 | this.resizer.style.setProperty("width", el.clientWidth + "px"); |
148 | 154 | this.resizer.style.setProperty("height", el.clientHeight + "px"); |
| 155 | + // this.resizer.getElementsByTagName("ql-size").item(0)?.innerHTML = `450px, 500px` |
| 156 | + (pluginOptions === null || pluginOptions === void 0 ? void 0 : pluginOptions.showSize) && |
| 157 | + (document.getElementsByName("ql-size").item(0).innerHTML = (el.getAttribute("width") ? el.getAttribute("width") : el.clientWidth) + ", " + (el.getAttribute("height") |
| 158 | + ? el.getAttribute("height") |
| 159 | + : el.clientHeight)); |
| 160 | + // this.resizer.innerHTML = formatSize (templateUsed, "450px, 500px") |
149 | 161 | } |
150 | 162 | }; |
151 | 163 | ResizePlugin.prototype.bindEvents = function () { |
|
165 | 177 | var style = this.resizeTarget.style; |
166 | 178 | if (width) { |
167 | 179 | if (this.resizeTarget.tagName.toLowerCase() !== "iframe") { |
168 | | - style.removeProperty("height"); |
| 180 | + // style.removeProperty("height"); |
| 181 | + this.resizeTarget.removeAttribute("height"); |
169 | 182 | } |
170 | 183 | if (width === "auto") { |
171 | | - style.removeProperty("width"); |
| 184 | + // style.removeProperty("width"); |
| 185 | + this.resizeTarget.removeAttribute("width"); |
172 | 186 | } |
173 | 187 | else if (width.includes("%")) { |
174 | | - style.setProperty("width", width); |
| 188 | + this.resizeTarget.setAttribute("width", width); |
| 189 | + // style.setProperty("width", width); |
175 | 190 | } |
176 | 191 | else { |
177 | | - var styleWidth = style.getPropertyValue("width"); |
| 192 | + var styleWidth = this.resizeTarget.getAttribute("width") || ""; |
| 193 | + // let styleWidth = style.getPropertyValue("width"); |
178 | 194 | width = parseInt(width); |
179 | 195 | if (styleWidth.includes("%")) { |
180 | 196 | styleWidth = |
|
184 | 200 | styleWidth = |
185 | 201 | Math.max(this.resizeTarget.clientWidth + width, 10) + "px"; |
186 | 202 | } |
187 | | - style.setProperty("width", styleWidth); |
| 203 | + this.resizeTarget.setAttribute("width", styleWidth); |
| 204 | + // style.setProperty("width", styleWidth); |
188 | 205 | } |
189 | 206 | } |
190 | 207 | else { |
|
209 | 226 | left: e.clientX, |
210 | 227 | top: e.clientY, |
211 | 228 | width: this.resizeTarget.clientWidth, |
212 | | - height: this.resizeTarget.clientHeight |
| 229 | + height: this.resizeTarget.clientHeight, |
213 | 230 | }; |
214 | 231 | } |
215 | 232 | }; |
|
230 | 247 | var rate = originSize.height / originSize.width; |
231 | 248 | height = rate * width; |
232 | 249 | } |
233 | | - if (noUseStyle) { |
234 | | - this.resizeTarget.setAttribute("width", Math.max(width, 30) + ""); |
235 | | - this.resizeTarget.setAttribute("height", Math.max(height, 30) + ""); |
236 | | - } |
237 | | - else { |
238 | | - this.resizeTarget.style.setProperty("width", Math.max(width, 30) + "px"); |
239 | | - this.resizeTarget.style.setProperty("height", Math.max(height, 30) + "px"); |
240 | | - } |
| 250 | + this.resizeTarget.setAttribute("width", Math.max(width, 30) + ""); |
| 251 | + this.resizeTarget.setAttribute("height", Math.max(height, 30) + ""); |
241 | 252 | this.positionResizerToTarget(this.resizeTarget); |
242 | 253 | }; |
243 | 254 | ResizePlugin.prototype.destory = function () { |
|
0 commit comments