Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

main -> latest #239

Merged
merged 2 commits into from
Dec 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# Changelog

## 0.14.2

### Patch Changes

- [#237](https://github.com/KonnorRogers/rhino-editor/pull/237) [`1c395c5`](https://github.com/KonnorRogers/rhino-editor/commit/1c395c55a1ac867f7c8ac8387acf570ff5bac925) Thanks [@KonnorRogers](https://github.com/KonnorRogers)! - Fix pendingAttachments not clearing attachments that get cancelled

## 0.14.1

### Patch Changes
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "rhino-editor",
"version": "0.14.1",
"version": "0.14.2",
"description": "A custom element wrapped rich text editor",
"type": "module",
"main": "exports/index.js",
Expand Down
35 changes: 30 additions & 5 deletions src/exports/elements/tip-tap-editor-base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ import { SelectionChangeEvent } from "../events/selection-change-event.js";
import { RhinoPasteEvent } from "../events/rhino-paste-event.js";
import { DOMSerializer, Slice } from "@tiptap/pm/model";
import type { EditorView } from "@tiptap/pm/view";
import { AttachmentRemoveEvent } from "../events/attachment-remove-event.js";

export type Serializer = "" | "html" | "json";

Expand Down Expand Up @@ -393,12 +394,12 @@ export class TipTapEditorBase extends BaseElement {
constructor() {
super();

this.registerDependencies();
this.addEventListener(AddAttachmentEvent.eventName, this.handleAttachment);

this.__addPendingAttachment = this.__addPendingAttachment.bind(this);
this.__removePendingAttachment = this.__removePendingAttachment.bind(this);

this.registerDependencies();
this.addEventListener(AddAttachmentEvent.eventName, this.handleAttachment);

this.addEventListener(
AttachmentUploadStartEvent.eventName,
this.__addPendingAttachment,
Expand All @@ -407,19 +408,43 @@ export class TipTapEditorBase extends BaseElement {
AttachmentUploadCompleteEvent.eventName,
this.__removePendingAttachment,
);
this.addEventListener(
AttachmentRemoveEvent.eventName,
this.__removePendingAttachment,
);

this.addEventListener("drop", this.handleNativeDrop);
this.addEventListener("rhino-paste", this.handlePaste);
this.addEventListener("rhino-file-accept", this.handleFileAccept);
}

/**
* @private
*/
__addPendingAttachment(e: { attachmentUpload: AttachmentUpload }) {
this.pendingAttachments.push(e.attachmentUpload);
}

__removePendingAttachment(e: { attachmentUpload: AttachmentUpload }) {
/**
* @private
*/
__removePendingAttachment(
e:
| { attachment: AttachmentManager }
| { attachmentUpload: AttachmentUpload },
) {
const index = this.pendingAttachments.findIndex((attachment) => {
return attachment === e.attachmentUpload;
// This is what you get from an attachment upload finishing.
if ("attachmentUpload" in e) {
return attachment === e.attachmentUpload;
}

// This is what you get from a generic "remove" event when an attachment is removed from the editor, this may not always be an upload.
if ("attachment" in e) {
return attachment.attachment.attachmentId === e.attachment.attachmentId;
}

return false;
});

if (index > -1) {
Expand Down
Loading