tiptap-extension-izzy-resizable-image 0.1.10 → 0.1.12

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.
Files changed (2) hide show
  1. package/npm/index.js +22 -8
  2. package/package.json +1 -1
package/npm/index.js CHANGED
@@ -148,7 +148,8 @@ class ResizableImageView {
148
148
  if (!hidden.size50) this.menu.appendChild(this.btnSize50)
149
149
  if (!hidden.size100) this.menu.appendChild(this.btnSize100)
150
150
 
151
- this.updateMenuPosition(node.attrs.alignMenuPosition != null ? node.attrs.alignMenuPosition : (this.options && this.options.alignMenuPosition != null ? this.options.alignMenuPosition : 'below'))
151
+ const menuVerticalPos = node.attrs.alignMenuPosition != null ? node.attrs.alignMenuPosition : (this.options && this.options.alignMenuPosition != null ? this.options.alignMenuPosition : 'below')
152
+ this.updateMenuPosition(menuVerticalPos, node.attrs.align)
152
153
 
153
154
  this.dom.addEventListener('dragstart', (e) => {
154
155
  const dragImg = document.createElement('canvas')
@@ -237,9 +238,9 @@ class ResizableImageView {
237
238
  this.view.dispatch(tr)
238
239
  }
239
240
 
240
- updateMenuPosition(pos) {
241
+ updateMenuPosition(verticalPos, align) {
241
242
  this.menu.classList.remove('menu-above', 'menu-below')
242
- if (pos === 'above') {
243
+ if (verticalPos === 'above') {
243
244
  this.menu.classList.add('menu-above')
244
245
  this.menu.style.top = '-32px'
245
246
  this.menu.style.bottom = ''
@@ -248,6 +249,20 @@ class ResizableImageView {
248
249
  this.menu.style.bottom = '-32px'
249
250
  this.menu.style.top = ''
250
251
  }
252
+
253
+ // Horizontal positioning based on image alignment
254
+ this.menu.style.left = ''
255
+ this.menu.style.right = ''
256
+ this.menu.style.transform = ''
257
+ if (align === 'left') {
258
+ this.menu.style.left = '0px'
259
+ } else if (align === 'right') {
260
+ this.menu.style.right = '0px'
261
+ } else {
262
+ // center or default
263
+ this.menu.style.left = '50%'
264
+ this.menu.style.transform = 'translateX(-50%)'
265
+ }
251
266
  }
252
267
 
253
268
  applyAlignAttr(align) {
@@ -276,11 +291,9 @@ class ResizableImageView {
276
291
  }
277
292
 
278
293
  applyResizePercent(percent) {
279
- const naturalW = this.img.naturalWidth || Math.round(this.img.getBoundingClientRect().width)
280
- const targetW = Math.max(20, Math.round(naturalW * percent))
281
- const targetH = this.aspect ? Math.round(targetW / this.aspect) : Math.round(this.img.getBoundingClientRect().height)
294
+ const percentValue = Math.round(Math.max(0.05, Math.min(1, percent)) * 100) + '%'
282
295
  const pos = this.getPos()
283
- const tr = this.view.state.tr.setNodeMarkup(pos, null, { ...this.node.attrs, width: targetW, height: targetH })
296
+ const tr = this.view.state.tr.setNodeMarkup(pos, null, { ...this.node.attrs, width: percentValue, height: 'auto' })
284
297
  this.view.dispatch(tr)
285
298
  }
286
299
 
@@ -350,7 +363,8 @@ class ResizableImageView {
350
363
  applyDimensionStyle(this.img, 'width', node.attrs.width)
351
364
  applyDimensionStyle(this.img, 'height', node.attrs.height)
352
365
  this.applyAlignment(node.attrs.align)
353
- this.updateMenuPosition(node.attrs.alignMenuPosition != null ? node.attrs.alignMenuPosition : (this.options && this.options.alignMenuPosition != null ? this.options.alignMenuPosition : 'below'))
366
+ const menuVerticalPos = node.attrs.alignMenuPosition != null ? node.attrs.alignMenuPosition : (this.options && this.options.alignMenuPosition != null ? this.options.alignMenuPosition : 'below')
367
+ this.updateMenuPosition(menuVerticalPos, node.attrs.align)
354
368
  this.btnLeft.innerHTML = (node.attrs.iconLeft != null ? node.attrs.iconLeft : (this.options && this.options.alignMenuIcons ? this.options.alignMenuIcons.left : '⟸'))
355
369
  this.btnCenter.innerHTML = (node.attrs.iconCenter != null ? node.attrs.iconCenter : (this.options && this.options.alignMenuIcons ? this.options.alignMenuIcons.center : '⇔'))
356
370
  this.btnRight.innerHTML = (node.attrs.iconRight != null ? node.attrs.iconRight : (this.options && this.options.alignMenuIcons ? this.options.alignMenuIcons.right : '⟹'))
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "tiptap-extension-izzy-resizable-image",
3
- "version": "0.1.10",
3
+ "version": "0.1.12",
4
4
  "description": "Resizable image NodeView for TipTap v2 with alignment menu and defaults",
5
5
  "license": "MIT",
6
6
  "type": "module",