@pod-os/elements 0.31.1-rc.4c5bdf8.0 → 0.31.1-rc.85d0b38.0
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/cjs/pos-markdown-document.cjs.entry.js +610 -4
- package/dist/cjs/pos-markdown-document.cjs.entry.js.map +1 -1
- package/dist/components/pos-markdown-document2.js +610 -4
- package/dist/components/pos-markdown-document2.js.map +1 -1
- package/dist/elements/elements.esm.js +1 -1
- package/dist/elements/{p-38ced320.entry.js → p-e21e1369.entry.js} +2 -2
- package/dist/elements/p-e21e1369.entry.js.map +1 -0
- package/dist/esm/pos-markdown-document.entry.js +610 -4
- package/dist/esm/pos-markdown-document.entry.js.map +1 -1
- package/package.json +8 -8
- package/dist/elements/p-38ced320.entry.js.map +0 -1
|
@@ -16875,9 +16875,13 @@ var ExtensionManager = class {
|
|
|
16875
16875
|
if (!addNodeView) {
|
|
16876
16876
|
return [];
|
|
16877
16877
|
}
|
|
16878
|
+
const nodeViewResult = addNodeView();
|
|
16879
|
+
if (!nodeViewResult) {
|
|
16880
|
+
return [];
|
|
16881
|
+
}
|
|
16878
16882
|
const nodeview = (node, view, getPos, decorations, innerDecorations) => {
|
|
16879
16883
|
const HTMLAttributes = getRenderedAttributes(node, extensionAttributes);
|
|
16880
|
-
return
|
|
16884
|
+
return nodeViewResult({
|
|
16881
16885
|
// pass-through
|
|
16882
16886
|
node,
|
|
16883
16887
|
view,
|
|
@@ -17617,6 +17621,7 @@ var Editor = class extends EventEmitter {
|
|
|
17617
17621
|
constructor(options = {}) {
|
|
17618
17622
|
super();
|
|
17619
17623
|
this.css = null;
|
|
17624
|
+
this.className = "tiptap";
|
|
17620
17625
|
this.editorView = null;
|
|
17621
17626
|
this.isFocused = false;
|
|
17622
17627
|
/**
|
|
@@ -17729,7 +17734,7 @@ var Editor = class extends EventEmitter {
|
|
|
17729
17734
|
}
|
|
17730
17735
|
this.editorView = null;
|
|
17731
17736
|
this.isInitialized = false;
|
|
17732
|
-
if (this.css) {
|
|
17737
|
+
if (this.css && !document.querySelectorAll(`.${this.className}`).length) {
|
|
17733
17738
|
try {
|
|
17734
17739
|
if (typeof this.css.remove === "function") {
|
|
17735
17740
|
this.css.remove();
|
|
@@ -18009,7 +18014,7 @@ var Editor = class extends EventEmitter {
|
|
|
18009
18014
|
* Prepend class name to element.
|
|
18010
18015
|
*/
|
|
18011
18016
|
prependClass() {
|
|
18012
|
-
this.view.dom.className =
|
|
18017
|
+
this.view.dom.className = `${this.className} ${this.view.dom.className}`;
|
|
18013
18018
|
}
|
|
18014
18019
|
captureTransaction(fn) {
|
|
18015
18020
|
this.isCapturingTransaction = true;
|
|
@@ -18283,6 +18288,537 @@ function wrappingInputRule(config) {
|
|
|
18283
18288
|
undoable: config.undoable
|
|
18284
18289
|
});
|
|
18285
18290
|
}
|
|
18291
|
+
|
|
18292
|
+
// src/lib/ResizableNodeView.ts
|
|
18293
|
+
var isTouchEvent = (e) => {
|
|
18294
|
+
return "touches" in e;
|
|
18295
|
+
};
|
|
18296
|
+
var ResizableNodeView = class {
|
|
18297
|
+
/**
|
|
18298
|
+
* Creates a new ResizableNodeView instance.
|
|
18299
|
+
*
|
|
18300
|
+
* The constructor sets up the resize handles, applies initial sizing from
|
|
18301
|
+
* node attributes, and configures all resize behavior options.
|
|
18302
|
+
*
|
|
18303
|
+
* @param options - Configuration options for the resizable node view
|
|
18304
|
+
*/
|
|
18305
|
+
constructor(options) {
|
|
18306
|
+
/** Active resize handle directions */
|
|
18307
|
+
this.directions = ["bottom-left", "bottom-right", "top-left", "top-right"];
|
|
18308
|
+
/** Minimum allowed dimensions */
|
|
18309
|
+
this.minSize = {
|
|
18310
|
+
height: 8,
|
|
18311
|
+
width: 8
|
|
18312
|
+
};
|
|
18313
|
+
/** Whether to always preserve aspect ratio */
|
|
18314
|
+
this.preserveAspectRatio = false;
|
|
18315
|
+
/** CSS class names for elements */
|
|
18316
|
+
this.classNames = {
|
|
18317
|
+
container: "",
|
|
18318
|
+
wrapper: "",
|
|
18319
|
+
handle: "",
|
|
18320
|
+
resizing: ""
|
|
18321
|
+
};
|
|
18322
|
+
/** Initial width of the element (for aspect ratio calculation) */
|
|
18323
|
+
this.initialWidth = 0;
|
|
18324
|
+
/** Initial height of the element (for aspect ratio calculation) */
|
|
18325
|
+
this.initialHeight = 0;
|
|
18326
|
+
/** Calculated aspect ratio (width / height) */
|
|
18327
|
+
this.aspectRatio = 1;
|
|
18328
|
+
/** Whether a resize operation is currently active */
|
|
18329
|
+
this.isResizing = false;
|
|
18330
|
+
/** The handle currently being dragged */
|
|
18331
|
+
this.activeHandle = null;
|
|
18332
|
+
/** Starting mouse X position when resize began */
|
|
18333
|
+
this.startX = 0;
|
|
18334
|
+
/** Starting mouse Y position when resize began */
|
|
18335
|
+
this.startY = 0;
|
|
18336
|
+
/** Element width when resize began */
|
|
18337
|
+
this.startWidth = 0;
|
|
18338
|
+
/** Element height when resize began */
|
|
18339
|
+
this.startHeight = 0;
|
|
18340
|
+
/** Whether Shift key is currently pressed (for temporary aspect ratio lock) */
|
|
18341
|
+
this.isShiftKeyPressed = false;
|
|
18342
|
+
/**
|
|
18343
|
+
* Handles mouse movement during an active resize.
|
|
18344
|
+
*
|
|
18345
|
+
* Calculates the delta from the starting position, computes new dimensions
|
|
18346
|
+
* based on the active handle direction, applies constraints and aspect ratio,
|
|
18347
|
+
* then updates the element's style and calls the onResize callback.
|
|
18348
|
+
*
|
|
18349
|
+
* @param event - The mouse move event
|
|
18350
|
+
*/
|
|
18351
|
+
this.handleMouseMove = (event) => {
|
|
18352
|
+
if (!this.isResizing || !this.activeHandle) {
|
|
18353
|
+
return;
|
|
18354
|
+
}
|
|
18355
|
+
const deltaX = event.clientX - this.startX;
|
|
18356
|
+
const deltaY = event.clientY - this.startY;
|
|
18357
|
+
this.handleResize(deltaX, deltaY);
|
|
18358
|
+
};
|
|
18359
|
+
this.handleTouchMove = (event) => {
|
|
18360
|
+
if (!this.isResizing || !this.activeHandle) {
|
|
18361
|
+
return;
|
|
18362
|
+
}
|
|
18363
|
+
const touch = event.touches[0];
|
|
18364
|
+
if (!touch) {
|
|
18365
|
+
return;
|
|
18366
|
+
}
|
|
18367
|
+
const deltaX = touch.clientX - this.startX;
|
|
18368
|
+
const deltaY = touch.clientY - this.startY;
|
|
18369
|
+
this.handleResize(deltaX, deltaY);
|
|
18370
|
+
};
|
|
18371
|
+
/**
|
|
18372
|
+
* Completes the resize operation when the mouse button is released.
|
|
18373
|
+
*
|
|
18374
|
+
* Captures final dimensions, calls the onCommit callback to persist changes,
|
|
18375
|
+
* removes the resizing state and class, and cleans up document-level listeners.
|
|
18376
|
+
*/
|
|
18377
|
+
this.handleMouseUp = () => {
|
|
18378
|
+
if (!this.isResizing) {
|
|
18379
|
+
return;
|
|
18380
|
+
}
|
|
18381
|
+
const finalWidth = this.element.offsetWidth;
|
|
18382
|
+
const finalHeight = this.element.offsetHeight;
|
|
18383
|
+
this.onCommit(finalWidth, finalHeight);
|
|
18384
|
+
this.isResizing = false;
|
|
18385
|
+
this.activeHandle = null;
|
|
18386
|
+
this.container.dataset.resizeState = "false";
|
|
18387
|
+
if (this.classNames.resizing) {
|
|
18388
|
+
this.container.classList.remove(this.classNames.resizing);
|
|
18389
|
+
}
|
|
18390
|
+
document.removeEventListener("mousemove", this.handleMouseMove);
|
|
18391
|
+
document.removeEventListener("mouseup", this.handleMouseUp);
|
|
18392
|
+
document.removeEventListener("keydown", this.handleKeyDown);
|
|
18393
|
+
document.removeEventListener("keyup", this.handleKeyUp);
|
|
18394
|
+
};
|
|
18395
|
+
/**
|
|
18396
|
+
* Tracks Shift key state to enable temporary aspect ratio locking.
|
|
18397
|
+
*
|
|
18398
|
+
* When Shift is pressed during resize, aspect ratio is preserved even if
|
|
18399
|
+
* preserveAspectRatio is false.
|
|
18400
|
+
*
|
|
18401
|
+
* @param event - The keyboard event
|
|
18402
|
+
*/
|
|
18403
|
+
this.handleKeyDown = (event) => {
|
|
18404
|
+
if (event.key === "Shift") {
|
|
18405
|
+
this.isShiftKeyPressed = true;
|
|
18406
|
+
}
|
|
18407
|
+
};
|
|
18408
|
+
/**
|
|
18409
|
+
* Tracks Shift key release to disable temporary aspect ratio locking.
|
|
18410
|
+
*
|
|
18411
|
+
* @param event - The keyboard event
|
|
18412
|
+
*/
|
|
18413
|
+
this.handleKeyUp = (event) => {
|
|
18414
|
+
if (event.key === "Shift") {
|
|
18415
|
+
this.isShiftKeyPressed = false;
|
|
18416
|
+
}
|
|
18417
|
+
};
|
|
18418
|
+
var _a, _b, _c, _d, _e;
|
|
18419
|
+
this.node = options.node;
|
|
18420
|
+
this.element = options.element;
|
|
18421
|
+
this.contentElement = options.contentElement;
|
|
18422
|
+
this.getPos = options.getPos;
|
|
18423
|
+
this.onResize = options.onResize;
|
|
18424
|
+
this.onCommit = options.onCommit;
|
|
18425
|
+
this.onUpdate = options.onUpdate;
|
|
18426
|
+
if ((_a = options.options) == null ? void 0 : _a.min) {
|
|
18427
|
+
this.minSize = {
|
|
18428
|
+
...this.minSize,
|
|
18429
|
+
...options.options.min
|
|
18430
|
+
};
|
|
18431
|
+
}
|
|
18432
|
+
if ((_b = options.options) == null ? void 0 : _b.max) {
|
|
18433
|
+
this.maxSize = options.options.max;
|
|
18434
|
+
}
|
|
18435
|
+
if ((_c = options == null ? void 0 : options.options) == null ? void 0 : _c.directions) {
|
|
18436
|
+
this.directions = options.options.directions;
|
|
18437
|
+
}
|
|
18438
|
+
if ((_d = options.options) == null ? void 0 : _d.preserveAspectRatio) {
|
|
18439
|
+
this.preserveAspectRatio = options.options.preserveAspectRatio;
|
|
18440
|
+
}
|
|
18441
|
+
if ((_e = options.options) == null ? void 0 : _e.className) {
|
|
18442
|
+
this.classNames = {
|
|
18443
|
+
container: options.options.className.container || "",
|
|
18444
|
+
wrapper: options.options.className.wrapper || "",
|
|
18445
|
+
handle: options.options.className.handle || "",
|
|
18446
|
+
resizing: options.options.className.resizing || ""
|
|
18447
|
+
};
|
|
18448
|
+
}
|
|
18449
|
+
this.wrapper = this.createWrapper();
|
|
18450
|
+
this.container = this.createContainer();
|
|
18451
|
+
this.applyInitialSize();
|
|
18452
|
+
this.attachHandles();
|
|
18453
|
+
}
|
|
18454
|
+
/**
|
|
18455
|
+
* Returns the top-level DOM node that should be placed in the editor.
|
|
18456
|
+
*
|
|
18457
|
+
* This is required by the ProseMirror NodeView interface. The container
|
|
18458
|
+
* includes the wrapper, handles, and the actual content element.
|
|
18459
|
+
*
|
|
18460
|
+
* @returns The container element to be inserted into the editor
|
|
18461
|
+
*/
|
|
18462
|
+
get dom() {
|
|
18463
|
+
return this.container;
|
|
18464
|
+
}
|
|
18465
|
+
get contentDOM() {
|
|
18466
|
+
return this.contentElement;
|
|
18467
|
+
}
|
|
18468
|
+
/**
|
|
18469
|
+
* Called when the node's content or attributes change.
|
|
18470
|
+
*
|
|
18471
|
+
* Updates the internal node reference. If a custom `onUpdate` callback
|
|
18472
|
+
* was provided, it will be called to handle additional update logic.
|
|
18473
|
+
*
|
|
18474
|
+
* @param node - The new/updated node
|
|
18475
|
+
* @param decorations - Node decorations
|
|
18476
|
+
* @param innerDecorations - Inner decorations
|
|
18477
|
+
* @returns `false` if the node type has changed (requires full rebuild), otherwise the result of `onUpdate` or `true`
|
|
18478
|
+
*/
|
|
18479
|
+
update(node, decorations, innerDecorations) {
|
|
18480
|
+
if (node.type !== this.node.type) {
|
|
18481
|
+
return false;
|
|
18482
|
+
}
|
|
18483
|
+
this.node = node;
|
|
18484
|
+
if (this.onUpdate) {
|
|
18485
|
+
return this.onUpdate(node, decorations, innerDecorations);
|
|
18486
|
+
}
|
|
18487
|
+
return true;
|
|
18488
|
+
}
|
|
18489
|
+
/**
|
|
18490
|
+
* Cleanup method called when the node view is being removed.
|
|
18491
|
+
*
|
|
18492
|
+
* Removes all event listeners to prevent memory leaks. This is required
|
|
18493
|
+
* by the ProseMirror NodeView interface. If a resize is active when
|
|
18494
|
+
* destroy is called, it will be properly cancelled.
|
|
18495
|
+
*/
|
|
18496
|
+
destroy() {
|
|
18497
|
+
if (this.isResizing) {
|
|
18498
|
+
this.container.dataset.resizeState = "false";
|
|
18499
|
+
if (this.classNames.resizing) {
|
|
18500
|
+
this.container.classList.remove(this.classNames.resizing);
|
|
18501
|
+
}
|
|
18502
|
+
document.removeEventListener("mousemove", this.handleMouseMove);
|
|
18503
|
+
document.removeEventListener("mouseup", this.handleMouseUp);
|
|
18504
|
+
document.removeEventListener("keydown", this.handleKeyDown);
|
|
18505
|
+
document.removeEventListener("keyup", this.handleKeyUp);
|
|
18506
|
+
this.isResizing = false;
|
|
18507
|
+
this.activeHandle = null;
|
|
18508
|
+
}
|
|
18509
|
+
this.container.remove();
|
|
18510
|
+
}
|
|
18511
|
+
/**
|
|
18512
|
+
* Creates the outer container element.
|
|
18513
|
+
*
|
|
18514
|
+
* The container is the top-level element returned by the NodeView and
|
|
18515
|
+
* wraps the entire resizable node. It's set up with flexbox to handle
|
|
18516
|
+
* alignment and includes data attributes for styling and identification.
|
|
18517
|
+
*
|
|
18518
|
+
* @returns The container element
|
|
18519
|
+
*/
|
|
18520
|
+
createContainer() {
|
|
18521
|
+
const element = document.createElement("div");
|
|
18522
|
+
element.dataset.resizeContainer = "";
|
|
18523
|
+
element.dataset.node = this.node.type.name;
|
|
18524
|
+
element.style.display = "flex";
|
|
18525
|
+
element.style.justifyContent = "flex-start";
|
|
18526
|
+
element.style.alignItems = "flex-start";
|
|
18527
|
+
if (this.classNames.container) {
|
|
18528
|
+
element.className = this.classNames.container;
|
|
18529
|
+
}
|
|
18530
|
+
element.appendChild(this.wrapper);
|
|
18531
|
+
return element;
|
|
18532
|
+
}
|
|
18533
|
+
/**
|
|
18534
|
+
* Creates the wrapper element that contains the content and handles.
|
|
18535
|
+
*
|
|
18536
|
+
* The wrapper uses relative positioning so that resize handles can be
|
|
18537
|
+
* positioned absolutely within it. This is the direct parent of the
|
|
18538
|
+
* content element being made resizable.
|
|
18539
|
+
*
|
|
18540
|
+
* @returns The wrapper element
|
|
18541
|
+
*/
|
|
18542
|
+
createWrapper() {
|
|
18543
|
+
const element = document.createElement("div");
|
|
18544
|
+
element.style.position = "relative";
|
|
18545
|
+
element.style.display = "block";
|
|
18546
|
+
element.dataset.resizeWrapper = "";
|
|
18547
|
+
if (this.classNames.wrapper) {
|
|
18548
|
+
element.className = this.classNames.wrapper;
|
|
18549
|
+
}
|
|
18550
|
+
element.appendChild(this.element);
|
|
18551
|
+
return element;
|
|
18552
|
+
}
|
|
18553
|
+
/**
|
|
18554
|
+
* Creates a resize handle element for a specific direction.
|
|
18555
|
+
*
|
|
18556
|
+
* Each handle is absolutely positioned and includes a data attribute
|
|
18557
|
+
* identifying its direction for styling purposes.
|
|
18558
|
+
*
|
|
18559
|
+
* @param direction - The resize direction for this handle
|
|
18560
|
+
* @returns The handle element
|
|
18561
|
+
*/
|
|
18562
|
+
createHandle(direction) {
|
|
18563
|
+
const handle = document.createElement("div");
|
|
18564
|
+
handle.dataset.resizeHandle = direction;
|
|
18565
|
+
handle.style.position = "absolute";
|
|
18566
|
+
if (this.classNames.handle) {
|
|
18567
|
+
handle.className = this.classNames.handle;
|
|
18568
|
+
}
|
|
18569
|
+
return handle;
|
|
18570
|
+
}
|
|
18571
|
+
/**
|
|
18572
|
+
* Positions a handle element according to its direction.
|
|
18573
|
+
*
|
|
18574
|
+
* Corner handles (e.g., 'top-left') are positioned at the intersection
|
|
18575
|
+
* of two edges. Edge handles (e.g., 'top') span the full width or height.
|
|
18576
|
+
*
|
|
18577
|
+
* @param handle - The handle element to position
|
|
18578
|
+
* @param direction - The direction determining the position
|
|
18579
|
+
*/
|
|
18580
|
+
positionHandle(handle, direction) {
|
|
18581
|
+
const isTop = direction.includes("top");
|
|
18582
|
+
const isBottom = direction.includes("bottom");
|
|
18583
|
+
const isLeft = direction.includes("left");
|
|
18584
|
+
const isRight = direction.includes("right");
|
|
18585
|
+
if (isTop) {
|
|
18586
|
+
handle.style.top = "0";
|
|
18587
|
+
}
|
|
18588
|
+
if (isBottom) {
|
|
18589
|
+
handle.style.bottom = "0";
|
|
18590
|
+
}
|
|
18591
|
+
if (isLeft) {
|
|
18592
|
+
handle.style.left = "0";
|
|
18593
|
+
}
|
|
18594
|
+
if (isRight) {
|
|
18595
|
+
handle.style.right = "0";
|
|
18596
|
+
}
|
|
18597
|
+
if (direction === "top" || direction === "bottom") {
|
|
18598
|
+
handle.style.left = "0";
|
|
18599
|
+
handle.style.right = "0";
|
|
18600
|
+
}
|
|
18601
|
+
if (direction === "left" || direction === "right") {
|
|
18602
|
+
handle.style.top = "0";
|
|
18603
|
+
handle.style.bottom = "0";
|
|
18604
|
+
}
|
|
18605
|
+
}
|
|
18606
|
+
/**
|
|
18607
|
+
* Creates and attaches all resize handles to the wrapper.
|
|
18608
|
+
*
|
|
18609
|
+
* Iterates through the configured directions, creates a handle for each,
|
|
18610
|
+
* positions it, attaches the mousedown listener, and appends it to the DOM.
|
|
18611
|
+
*/
|
|
18612
|
+
attachHandles() {
|
|
18613
|
+
this.directions.forEach((direction) => {
|
|
18614
|
+
const handle = this.createHandle(direction);
|
|
18615
|
+
this.positionHandle(handle, direction);
|
|
18616
|
+
handle.addEventListener("mousedown", (event) => this.handleResizeStart(event, direction));
|
|
18617
|
+
handle.addEventListener("touchstart", (event) => this.handleResizeStart(event, direction));
|
|
18618
|
+
this.wrapper.appendChild(handle);
|
|
18619
|
+
});
|
|
18620
|
+
}
|
|
18621
|
+
/**
|
|
18622
|
+
* Applies initial sizing from node attributes to the element.
|
|
18623
|
+
*
|
|
18624
|
+
* If width/height attributes exist on the node, they're applied to the element.
|
|
18625
|
+
* Otherwise, the element's natural/current dimensions are measured. The aspect
|
|
18626
|
+
* ratio is calculated for later use in aspect-ratio-preserving resizes.
|
|
18627
|
+
*/
|
|
18628
|
+
applyInitialSize() {
|
|
18629
|
+
const width = this.node.attrs.width;
|
|
18630
|
+
const height = this.node.attrs.height;
|
|
18631
|
+
if (width) {
|
|
18632
|
+
this.element.style.width = `${width}px`;
|
|
18633
|
+
this.initialWidth = width;
|
|
18634
|
+
} else {
|
|
18635
|
+
this.initialWidth = this.element.offsetWidth;
|
|
18636
|
+
}
|
|
18637
|
+
if (height) {
|
|
18638
|
+
this.element.style.height = `${height}px`;
|
|
18639
|
+
this.initialHeight = height;
|
|
18640
|
+
} else {
|
|
18641
|
+
this.initialHeight = this.element.offsetHeight;
|
|
18642
|
+
}
|
|
18643
|
+
if (this.initialWidth > 0 && this.initialHeight > 0) {
|
|
18644
|
+
this.aspectRatio = this.initialWidth / this.initialHeight;
|
|
18645
|
+
}
|
|
18646
|
+
}
|
|
18647
|
+
/**
|
|
18648
|
+
* Initiates a resize operation when a handle is clicked.
|
|
18649
|
+
*
|
|
18650
|
+
* Captures the starting mouse position and element dimensions, sets up
|
|
18651
|
+
* the resize state, adds the resizing class and state attribute, and
|
|
18652
|
+
* attaches document-level listeners for mouse movement and keyboard input.
|
|
18653
|
+
*
|
|
18654
|
+
* @param event - The mouse down event
|
|
18655
|
+
* @param direction - The direction of the handle being dragged
|
|
18656
|
+
*/
|
|
18657
|
+
handleResizeStart(event, direction) {
|
|
18658
|
+
event.preventDefault();
|
|
18659
|
+
event.stopPropagation();
|
|
18660
|
+
this.isResizing = true;
|
|
18661
|
+
this.activeHandle = direction;
|
|
18662
|
+
if (isTouchEvent(event)) {
|
|
18663
|
+
this.startX = event.touches[0].clientX;
|
|
18664
|
+
this.startY = event.touches[0].clientY;
|
|
18665
|
+
} else {
|
|
18666
|
+
this.startX = event.clientX;
|
|
18667
|
+
this.startY = event.clientY;
|
|
18668
|
+
}
|
|
18669
|
+
this.startWidth = this.element.offsetWidth;
|
|
18670
|
+
this.startHeight = this.element.offsetHeight;
|
|
18671
|
+
if (this.startWidth > 0 && this.startHeight > 0) {
|
|
18672
|
+
this.aspectRatio = this.startWidth / this.startHeight;
|
|
18673
|
+
}
|
|
18674
|
+
this.getPos();
|
|
18675
|
+
this.container.dataset.resizeState = "true";
|
|
18676
|
+
if (this.classNames.resizing) {
|
|
18677
|
+
this.container.classList.add(this.classNames.resizing);
|
|
18678
|
+
}
|
|
18679
|
+
document.addEventListener("mousemove", this.handleMouseMove);
|
|
18680
|
+
document.addEventListener("touchmove", this.handleTouchMove);
|
|
18681
|
+
document.addEventListener("mouseup", this.handleMouseUp);
|
|
18682
|
+
document.addEventListener("keydown", this.handleKeyDown);
|
|
18683
|
+
document.addEventListener("keyup", this.handleKeyUp);
|
|
18684
|
+
}
|
|
18685
|
+
handleResize(deltaX, deltaY) {
|
|
18686
|
+
if (!this.activeHandle) {
|
|
18687
|
+
return;
|
|
18688
|
+
}
|
|
18689
|
+
const shouldPreserveAspectRatio = this.preserveAspectRatio || this.isShiftKeyPressed;
|
|
18690
|
+
const { width, height } = this.calculateNewDimensions(this.activeHandle, deltaX, deltaY);
|
|
18691
|
+
const constrained = this.applyConstraints(width, height, shouldPreserveAspectRatio);
|
|
18692
|
+
this.element.style.width = `${constrained.width}px`;
|
|
18693
|
+
this.element.style.height = `${constrained.height}px`;
|
|
18694
|
+
if (this.onResize) {
|
|
18695
|
+
this.onResize(constrained.width, constrained.height);
|
|
18696
|
+
}
|
|
18697
|
+
}
|
|
18698
|
+
/**
|
|
18699
|
+
* Calculates new dimensions based on mouse delta and resize direction.
|
|
18700
|
+
*
|
|
18701
|
+
* Takes the starting dimensions and applies the mouse movement delta
|
|
18702
|
+
* according to the handle direction. For corner handles, both dimensions
|
|
18703
|
+
* are affected. For edge handles, only one dimension changes. If aspect
|
|
18704
|
+
* ratio should be preserved, delegates to applyAspectRatio.
|
|
18705
|
+
*
|
|
18706
|
+
* @param direction - The active resize handle direction
|
|
18707
|
+
* @param deltaX - Horizontal mouse movement since resize start
|
|
18708
|
+
* @param deltaY - Vertical mouse movement since resize start
|
|
18709
|
+
* @returns The calculated width and height
|
|
18710
|
+
*/
|
|
18711
|
+
calculateNewDimensions(direction, deltaX, deltaY) {
|
|
18712
|
+
let newWidth = this.startWidth;
|
|
18713
|
+
let newHeight = this.startHeight;
|
|
18714
|
+
const isRight = direction.includes("right");
|
|
18715
|
+
const isLeft = direction.includes("left");
|
|
18716
|
+
const isBottom = direction.includes("bottom");
|
|
18717
|
+
const isTop = direction.includes("top");
|
|
18718
|
+
if (isRight) {
|
|
18719
|
+
newWidth = this.startWidth + deltaX;
|
|
18720
|
+
} else if (isLeft) {
|
|
18721
|
+
newWidth = this.startWidth - deltaX;
|
|
18722
|
+
}
|
|
18723
|
+
if (isBottom) {
|
|
18724
|
+
newHeight = this.startHeight + deltaY;
|
|
18725
|
+
} else if (isTop) {
|
|
18726
|
+
newHeight = this.startHeight - deltaY;
|
|
18727
|
+
}
|
|
18728
|
+
if (direction === "right" || direction === "left") {
|
|
18729
|
+
newWidth = this.startWidth + (isRight ? deltaX : -deltaX);
|
|
18730
|
+
}
|
|
18731
|
+
if (direction === "top" || direction === "bottom") {
|
|
18732
|
+
newHeight = this.startHeight + (isBottom ? deltaY : -deltaY);
|
|
18733
|
+
}
|
|
18734
|
+
const shouldPreserveAspectRatio = this.preserveAspectRatio || this.isShiftKeyPressed;
|
|
18735
|
+
if (shouldPreserveAspectRatio) {
|
|
18736
|
+
return this.applyAspectRatio(newWidth, newHeight, direction);
|
|
18737
|
+
}
|
|
18738
|
+
return { width: newWidth, height: newHeight };
|
|
18739
|
+
}
|
|
18740
|
+
/**
|
|
18741
|
+
* Applies min/max constraints to dimensions.
|
|
18742
|
+
*
|
|
18743
|
+
* When aspect ratio is NOT preserved, constraints are applied independently
|
|
18744
|
+
* to width and height. When aspect ratio IS preserved, constraints are
|
|
18745
|
+
* applied while maintaining the aspect ratio—if one dimension hits a limit,
|
|
18746
|
+
* the other is recalculated proportionally.
|
|
18747
|
+
*
|
|
18748
|
+
* This ensures that aspect ratio is never broken when constrained.
|
|
18749
|
+
*
|
|
18750
|
+
* @param width - The unconstrained width
|
|
18751
|
+
* @param height - The unconstrained height
|
|
18752
|
+
* @param preserveAspectRatio - Whether to maintain aspect ratio while constraining
|
|
18753
|
+
* @returns The constrained dimensions
|
|
18754
|
+
*/
|
|
18755
|
+
applyConstraints(width, height, preserveAspectRatio) {
|
|
18756
|
+
var _a, _b, _c, _d;
|
|
18757
|
+
if (!preserveAspectRatio) {
|
|
18758
|
+
let constrainedWidth2 = Math.max(this.minSize.width, width);
|
|
18759
|
+
let constrainedHeight2 = Math.max(this.minSize.height, height);
|
|
18760
|
+
if ((_a = this.maxSize) == null ? void 0 : _a.width) {
|
|
18761
|
+
constrainedWidth2 = Math.min(this.maxSize.width, constrainedWidth2);
|
|
18762
|
+
}
|
|
18763
|
+
if ((_b = this.maxSize) == null ? void 0 : _b.height) {
|
|
18764
|
+
constrainedHeight2 = Math.min(this.maxSize.height, constrainedHeight2);
|
|
18765
|
+
}
|
|
18766
|
+
return { width: constrainedWidth2, height: constrainedHeight2 };
|
|
18767
|
+
}
|
|
18768
|
+
let constrainedWidth = width;
|
|
18769
|
+
let constrainedHeight = height;
|
|
18770
|
+
if (constrainedWidth < this.minSize.width) {
|
|
18771
|
+
constrainedWidth = this.minSize.width;
|
|
18772
|
+
constrainedHeight = constrainedWidth / this.aspectRatio;
|
|
18773
|
+
}
|
|
18774
|
+
if (constrainedHeight < this.minSize.height) {
|
|
18775
|
+
constrainedHeight = this.minSize.height;
|
|
18776
|
+
constrainedWidth = constrainedHeight * this.aspectRatio;
|
|
18777
|
+
}
|
|
18778
|
+
if (((_c = this.maxSize) == null ? void 0 : _c.width) && constrainedWidth > this.maxSize.width) {
|
|
18779
|
+
constrainedWidth = this.maxSize.width;
|
|
18780
|
+
constrainedHeight = constrainedWidth / this.aspectRatio;
|
|
18781
|
+
}
|
|
18782
|
+
if (((_d = this.maxSize) == null ? void 0 : _d.height) && constrainedHeight > this.maxSize.height) {
|
|
18783
|
+
constrainedHeight = this.maxSize.height;
|
|
18784
|
+
constrainedWidth = constrainedHeight * this.aspectRatio;
|
|
18785
|
+
}
|
|
18786
|
+
return { width: constrainedWidth, height: constrainedHeight };
|
|
18787
|
+
}
|
|
18788
|
+
/**
|
|
18789
|
+
* Adjusts dimensions to maintain the original aspect ratio.
|
|
18790
|
+
*
|
|
18791
|
+
* For horizontal handles (left/right), uses width as the primary dimension
|
|
18792
|
+
* and calculates height from it. For vertical handles (top/bottom), uses
|
|
18793
|
+
* height as primary and calculates width. For corner handles, uses width
|
|
18794
|
+
* as the primary dimension.
|
|
18795
|
+
*
|
|
18796
|
+
* @param width - The new width
|
|
18797
|
+
* @param height - The new height
|
|
18798
|
+
* @param direction - The active resize direction
|
|
18799
|
+
* @returns Dimensions adjusted to preserve aspect ratio
|
|
18800
|
+
*/
|
|
18801
|
+
applyAspectRatio(width, height, direction) {
|
|
18802
|
+
const isHorizontal = direction === "left" || direction === "right";
|
|
18803
|
+
const isVertical = direction === "top" || direction === "bottom";
|
|
18804
|
+
if (isHorizontal) {
|
|
18805
|
+
return {
|
|
18806
|
+
width,
|
|
18807
|
+
height: width / this.aspectRatio
|
|
18808
|
+
};
|
|
18809
|
+
}
|
|
18810
|
+
if (isVertical) {
|
|
18811
|
+
return {
|
|
18812
|
+
width: height * this.aspectRatio,
|
|
18813
|
+
height
|
|
18814
|
+
};
|
|
18815
|
+
}
|
|
18816
|
+
return {
|
|
18817
|
+
width,
|
|
18818
|
+
height: width / this.aspectRatio
|
|
18819
|
+
};
|
|
18820
|
+
}
|
|
18821
|
+
};
|
|
18286
18822
|
function canInsertNode(state, nodeType) {
|
|
18287
18823
|
const { selection } = state;
|
|
18288
18824
|
const { $from } = selection;
|
|
@@ -20258,6 +20794,7 @@ var Document = Node3.create({
|
|
|
20258
20794
|
// src/hard-break.ts
|
|
20259
20795
|
var HardBreak = Node3.create({
|
|
20260
20796
|
name: "hardBreak",
|
|
20797
|
+
markdownTokenName: "br",
|
|
20261
20798
|
addOptions() {
|
|
20262
20799
|
return {
|
|
20263
20800
|
keepMarks: true,
|
|
@@ -20279,6 +20816,11 @@ var HardBreak = Node3.create({
|
|
|
20279
20816
|
},
|
|
20280
20817
|
renderMarkdown: (_node, h) => h.indent(`
|
|
20281
20818
|
`),
|
|
20819
|
+
parseMarkdown: () => {
|
|
20820
|
+
return {
|
|
20821
|
+
type: "hardBreak"
|
|
20822
|
+
};
|
|
20823
|
+
},
|
|
20282
20824
|
addCommands() {
|
|
20283
20825
|
return {
|
|
20284
20826
|
setHardBreak: () => ({ commands, chain, state, editor }) => {
|
|
@@ -25342,7 +25884,8 @@ var Image = Node3.create({
|
|
|
25342
25884
|
return {
|
|
25343
25885
|
inline: false,
|
|
25344
25886
|
allowBase64: false,
|
|
25345
|
-
HTMLAttributes: {}
|
|
25887
|
+
HTMLAttributes: {},
|
|
25888
|
+
resize: false
|
|
25346
25889
|
};
|
|
25347
25890
|
},
|
|
25348
25891
|
inline() {
|
|
@@ -25395,6 +25938,69 @@ var Image = Node3.create({
|
|
|
25395
25938
|
const title = (_f = (_e = node.attrs) == null ? void 0 : _e.title) != null ? _f : "";
|
|
25396
25939
|
return title ? `` : ``;
|
|
25397
25940
|
},
|
|
25941
|
+
addNodeView() {
|
|
25942
|
+
if (!this.options.resize || !this.options.resize.enabled || typeof document === "undefined" || !this.editor.isEditable) {
|
|
25943
|
+
return null;
|
|
25944
|
+
}
|
|
25945
|
+
const { directions, minWidth, minHeight, alwaysPreserveAspectRatio } = this.options.resize;
|
|
25946
|
+
return ({ node, getPos, HTMLAttributes }) => {
|
|
25947
|
+
const el = document.createElement("img");
|
|
25948
|
+
Object.entries(HTMLAttributes).forEach(([key, value]) => {
|
|
25949
|
+
if (value != null) {
|
|
25950
|
+
switch (key) {
|
|
25951
|
+
case "width":
|
|
25952
|
+
case "height":
|
|
25953
|
+
break;
|
|
25954
|
+
default:
|
|
25955
|
+
el.setAttribute(key, value);
|
|
25956
|
+
break;
|
|
25957
|
+
}
|
|
25958
|
+
}
|
|
25959
|
+
});
|
|
25960
|
+
el.src = HTMLAttributes.src;
|
|
25961
|
+
const nodeView = new ResizableNodeView({
|
|
25962
|
+
element: el,
|
|
25963
|
+
node,
|
|
25964
|
+
getPos,
|
|
25965
|
+
onResize: (width, height) => {
|
|
25966
|
+
el.style.width = `${width}px`;
|
|
25967
|
+
el.style.height = `${height}px`;
|
|
25968
|
+
},
|
|
25969
|
+
onCommit: (width, height) => {
|
|
25970
|
+
const pos = getPos();
|
|
25971
|
+
if (pos === void 0) {
|
|
25972
|
+
return;
|
|
25973
|
+
}
|
|
25974
|
+
this.editor.chain().setNodeSelection(pos).updateAttributes(this.name, {
|
|
25975
|
+
width,
|
|
25976
|
+
height
|
|
25977
|
+
}).run();
|
|
25978
|
+
},
|
|
25979
|
+
onUpdate: (updatedNode, _decorations, _innerDecorations) => {
|
|
25980
|
+
if (updatedNode.type !== node.type) {
|
|
25981
|
+
return false;
|
|
25982
|
+
}
|
|
25983
|
+
return true;
|
|
25984
|
+
},
|
|
25985
|
+
options: {
|
|
25986
|
+
directions,
|
|
25987
|
+
min: {
|
|
25988
|
+
width: minWidth,
|
|
25989
|
+
height: minHeight
|
|
25990
|
+
},
|
|
25991
|
+
preserveAspectRatio: alwaysPreserveAspectRatio === true
|
|
25992
|
+
}
|
|
25993
|
+
});
|
|
25994
|
+
const dom = nodeView.dom;
|
|
25995
|
+
dom.style.visibility = "hidden";
|
|
25996
|
+
dom.style.pointerEvents = "none";
|
|
25997
|
+
el.onload = () => {
|
|
25998
|
+
dom.style.visibility = "";
|
|
25999
|
+
dom.style.pointerEvents = "";
|
|
26000
|
+
};
|
|
26001
|
+
return nodeView;
|
|
26002
|
+
};
|
|
26003
|
+
},
|
|
25398
26004
|
addCommands() {
|
|
25399
26005
|
return {
|
|
25400
26006
|
setImage: (options) => ({ commands }) => {
|