tiptap-extension-izzy-resizable-image 0.1.4 → 0.1.6
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 +13 -1
- package/npm/index.js +35 -3
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -123,6 +123,8 @@ These can be set per-node, overriding options.
|
|
|
123
123
|
- `title: string | null`
|
|
124
124
|
- `width: number | null` — width in px.
|
|
125
125
|
- `height: number | null` — height in px.
|
|
126
|
+
- `id: string | null` — applied to the `<img>` element.
|
|
127
|
+
- `class: string | null` — applied to the `<img>` element.
|
|
126
128
|
- `align: 'left' | 'center' | 'right' | null` — alignment.
|
|
127
129
|
- `showAlignMenu: boolean | null` — show/hide menu per node.
|
|
128
130
|
- `alignMenuPosition: 'above' | 'below' | null`
|
|
@@ -136,7 +138,7 @@ Reference: `resizable-image.js:358-372`
|
|
|
136
138
|
|
|
137
139
|
## Commands
|
|
138
140
|
|
|
139
|
-
- `insertResizableImage({ src, alt, title, width, height })`
|
|
141
|
+
- `insertResizableImage({ src, alt, title, width, height, id, class })`
|
|
140
142
|
- Inserts the resizable image node. Missing attrs fall back to options (e.g., `height`).
|
|
141
143
|
- Reference: `resizable-image.js:398-416`
|
|
142
144
|
|
|
@@ -181,3 +183,13 @@ Reference: `resizable-image.js:358-372`
|
|
|
181
183
|
|
|
182
184
|
- The extension is inline and draggable; selection toggles menu/handles.
|
|
183
185
|
- Deselecting removes the overlay/menu from the DOM to keep markup clean.
|
|
186
|
+
### Example with `id` and `class`
|
|
187
|
+
|
|
188
|
+
```js
|
|
189
|
+
editor.commands.insertResizableImage({
|
|
190
|
+
src: 'https://picsum.photos/300/200',
|
|
191
|
+
width: 300,
|
|
192
|
+
id: 'hero-image',
|
|
193
|
+
class: 'rounded shadow'
|
|
194
|
+
});
|
|
195
|
+
```
|
package/npm/index.js
CHANGED
|
@@ -39,9 +39,11 @@ class ResizableImageView {
|
|
|
39
39
|
this.img.src = node.attrs.src
|
|
40
40
|
this.img.alt = node.attrs.alt || ''
|
|
41
41
|
this.img.style.display = 'block'
|
|
42
|
-
this.img.style.userSelect = 'none'
|
|
43
|
-
this.img.style.pointerEvents = 'none'
|
|
44
|
-
if (node.attrs.
|
|
42
|
+
this.img.style.userSelect = 'none'
|
|
43
|
+
this.img.style.pointerEvents = 'none'
|
|
44
|
+
if (node.attrs.id) this.img.id = node.attrs.id
|
|
45
|
+
if (node.attrs.class) this.img.className = node.attrs.class
|
|
46
|
+
if (node.attrs.width) this.img.style.width = node.attrs.width + 'px'
|
|
45
47
|
if (node.attrs.height) {
|
|
46
48
|
this.img.style.height = node.attrs.height + 'px'
|
|
47
49
|
} else if (this.options && this.options.height) {
|
|
@@ -354,6 +356,8 @@ export const TiptapIzzyExtensionResizableImage = Node.create({
|
|
|
354
356
|
title: { default: null },
|
|
355
357
|
width: { default: null },
|
|
356
358
|
height: { default: null },
|
|
359
|
+
id: { default: null },
|
|
360
|
+
class: { default: null },
|
|
357
361
|
align: { default: 'left' },
|
|
358
362
|
showAlignMenu: { default: null },
|
|
359
363
|
alignMenuPosition: { default: null },
|
|
@@ -361,6 +365,7 @@ export const TiptapIzzyExtensionResizableImage = Node.create({
|
|
|
361
365
|
iconCenter: { default: null },
|
|
362
366
|
iconRight: { default: null },
|
|
363
367
|
iconClear: { default: null },
|
|
368
|
+
iconView: { default: null },
|
|
364
369
|
}
|
|
365
370
|
},
|
|
366
371
|
|
|
@@ -467,6 +472,33 @@ export const TiptapIzzyExtensionResizableImage = Node.create({
|
|
|
467
472
|
},
|
|
468
473
|
},
|
|
469
474
|
},
|
|
475
|
+
appendTransaction: (transactions, oldState, newState) => {
|
|
476
|
+
const imgType = newState.schema.nodes.image
|
|
477
|
+
const resizeType = newState.schema.nodes[this.name]
|
|
478
|
+
if (!imgType || !resizeType) return null
|
|
479
|
+
let tr = newState.tr
|
|
480
|
+
let changed = false
|
|
481
|
+
newState.doc.descendants((node, pos) => {
|
|
482
|
+
if (node.type === imgType) {
|
|
483
|
+
tr = tr.setNodeMarkup(pos, resizeType, {
|
|
484
|
+
src: node.attrs.src,
|
|
485
|
+
alt: node.attrs.alt,
|
|
486
|
+
title: node.attrs.title,
|
|
487
|
+
width: node.attrs.width,
|
|
488
|
+
height: node.attrs.height ?? this.options.height,
|
|
489
|
+
showAlignMenu: this.options.showAlignMenu,
|
|
490
|
+
alignMenuPosition: this.options.alignMenuPosition,
|
|
491
|
+
iconLeft: this.options.alignMenuIcons?.left,
|
|
492
|
+
iconCenter: this.options.alignMenuIcons?.center,
|
|
493
|
+
iconRight: this.options.alignMenuIcons?.right,
|
|
494
|
+
iconClear: this.options.alignMenuIcons?.clear,
|
|
495
|
+
iconView: this.options.alignMenuIcons?.preview,
|
|
496
|
+
})
|
|
497
|
+
changed = true
|
|
498
|
+
}
|
|
499
|
+
})
|
|
500
|
+
return changed ? tr : null
|
|
501
|
+
},
|
|
470
502
|
}),
|
|
471
503
|
]
|
|
472
504
|
},
|