@seorii/tiptap 0.4.2 → 0.4.3
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/plugin/resize/index.js +29 -6
- package/package.json +1 -1
|
@@ -242,10 +242,24 @@ function buildResizeAttrs(kind, node, height, imageRatio, aspectRatio = normaliz
|
|
|
242
242
|
// Keep image responsive by storing width only; fixed height causes ratio distortion on narrow layouts.
|
|
243
243
|
return { ...attrs, width: roundedWidth, height: null };
|
|
244
244
|
}
|
|
245
|
-
if (kind === 'iframe'
|
|
246
|
-
|
|
245
|
+
if (kind === 'iframe') {
|
|
246
|
+
if (aspectRatio) {
|
|
247
|
+
// A fixed height prevents CSS aspect-ratio from taking effect.
|
|
248
|
+
return { ...attrs, width: attrs.width || '100%', height: null, aspectRatio };
|
|
249
|
+
}
|
|
250
|
+
return { ...attrs, width: attrs.width || '100%', height: roundedHeight, aspectRatio: null };
|
|
251
|
+
}
|
|
252
|
+
if (kind === 'embed') {
|
|
253
|
+
if (aspectRatio) {
|
|
254
|
+
// Keep PDF/embed responsive with CSS aspect-ratio when a preset is selected.
|
|
255
|
+
return { ...attrs, width: attrs.width || '100%', height: null, aspectRatio };
|
|
256
|
+
}
|
|
257
|
+
return { ...attrs, width: attrs.width || '100%', height: roundedHeight, aspectRatio: null };
|
|
247
258
|
}
|
|
248
|
-
return { ...attrs, height: roundedHeight, aspectRatio };
|
|
259
|
+
return { ...attrs, height: roundedHeight, aspectRatio: null };
|
|
260
|
+
}
|
|
261
|
+
function canUseAspectRatioPreset(kind) {
|
|
262
|
+
return kind === 'iframe' || kind === 'embed';
|
|
249
263
|
}
|
|
250
264
|
function createResizeHandleDecoration(nodePos, widgetPos, resizeMeta, node) {
|
|
251
265
|
return Decoration.widget(widgetPos, () => {
|
|
@@ -258,7 +272,7 @@ function createResizeHandleDecoration(nodePos, widgetPos, resizeMeta, node) {
|
|
|
258
272
|
button.dataset.resizeKind = resizeMeta.kind;
|
|
259
273
|
button.setAttribute('aria-label', 'Resize media height (click for aspect ratio)');
|
|
260
274
|
anchor.append(button);
|
|
261
|
-
if (resizeMeta.kind
|
|
275
|
+
if (canUseAspectRatioPreset(resizeMeta.kind)) {
|
|
262
276
|
const selectedAspectRatio = normalizeAspectRatioAttr(node.attrs.aspectRatio);
|
|
263
277
|
const toolbar = document.createElement('div');
|
|
264
278
|
toolbar.className = 'tiptap-media-aspect-ratio-toolbar';
|
|
@@ -342,8 +356,17 @@ export default Extension.create({
|
|
|
342
356
|
},
|
|
343
357
|
height: {
|
|
344
358
|
default: '600',
|
|
345
|
-
parseHTML: (element) =>
|
|
359
|
+
parseHTML: (element) => {
|
|
360
|
+
const aspectRatio = normalizeAspectRatioAttr(element.getAttribute('data-resize-aspect-ratio'));
|
|
361
|
+
if (aspectRatio)
|
|
362
|
+
return null;
|
|
363
|
+
return (normalizeNumericAttr(element.getAttribute('height') || element.style.height) ||
|
|
364
|
+
'600');
|
|
365
|
+
},
|
|
346
366
|
renderHTML: (attributes) => {
|
|
367
|
+
const aspectRatio = normalizeAspectRatioAttr(attributes.aspectRatio);
|
|
368
|
+
if (aspectRatio)
|
|
369
|
+
return {};
|
|
347
370
|
const height = normalizeNumericAttr(attributes.height) || '600';
|
|
348
371
|
return { height };
|
|
349
372
|
}
|
|
@@ -478,7 +501,7 @@ export default Extension.create({
|
|
|
478
501
|
if (!node)
|
|
479
502
|
return true;
|
|
480
503
|
const resizeMeta = resolveResizeMeta(node);
|
|
481
|
-
if (!resizeMeta || resizeMeta.kind
|
|
504
|
+
if (!resizeMeta || !canUseAspectRatioPreset(resizeMeta.kind))
|
|
482
505
|
return true;
|
|
483
506
|
const target = resolveTargetElement(view, pos, resizeMeta, node);
|
|
484
507
|
if (!target)
|