Skip to content

Commit

Permalink
chore: Add deprecation notice for edit event v1
Browse files Browse the repository at this point in the history
  • Loading branch information
clepski committed Jan 23, 2025
1 parent 852c7ab commit 83d2532
Showing 1 changed file with 45 additions and 4 deletions.
49 changes: 45 additions & 4 deletions packages/core/foundation/deprecated/edit-event.ts
Original file line number Diff line number Diff line change
@@ -1,62 +1,103 @@
/**
* @deprecated Use the new edit event V2 API instead.
*/
export type Initiator = 'user' | 'system' | 'undo' | 'redo' | string;

/** Intent to `parent.insertBefore(node, reference)` */
/**
* @deprecated Use the new edit event V2 API instead.
*/
export type Insert = {
parent: Node;
node: Node;
reference: Node | null;
};

/**
* @deprecated Use the new edit event V2 API instead.
*/
export type NamespacedAttributeValue = {
value: string | null;
namespaceURI: string | null;
};
/**
* @deprecated Use the new edit event V2 API instead.
*/
export type AttributeValue = string | null | NamespacedAttributeValue;
/** Intent to set or remove (if null) attributes on element */
/**
* @deprecated Use the new edit event V2 API instead.
*/
export type Update = {
element: Element;
attributes: Partial<Record<string, AttributeValue>>;
};

/** Intent to remove a node from its ownerDocument */
/**
* @deprecated Use the new edit event V2 API instead.
*/
export type Remove = {
node: Node;
};

/** Represents the user's intent to change an XMLDocument */
/**
* @deprecated Use the new edit event V2 API instead.
*/
export type Edit = Insert | Update | Remove | Edit[];

/**
* @deprecated Use the new edit event V2 API instead.
*/
export function isComplex(edit: Edit): edit is Edit[] {
return edit instanceof Array;
}

/**
* @deprecated Use the new edit event V2 API instead.
*/
export function isInsert(edit: Edit): edit is Insert {
return (edit as Insert).parent !== undefined;
}

/**
* @deprecated Use the new edit event V2 API instead.
*/
export function isNamespaced(
value: AttributeValue
): value is NamespacedAttributeValue {
return value !== null && typeof value !== 'string';
}

/**
* @deprecated Use the new edit event V2 API instead.
*/
export function isUpdate(edit: Edit): edit is Update {
return (edit as Update).element !== undefined;
}

/**
* @deprecated Use the new edit event V2 API instead.
*/
export function isRemove(edit: Edit): edit is Remove {
return (
(edit as Insert).parent === undefined && (edit as Remove).node !== undefined
);
}

/**
* @deprecated Use the new edit event V2 API instead.
*/
export interface EditEventDetail<E extends Edit = Edit> {
edit: E;
initiator: Initiator;
}

/**
* @deprecated Use the new edit event V2 API instead.
*/
export type EditEvent = CustomEvent<EditEventDetail>;

/**
* @deprecated Use the new edit event V2 API instead.
*/
export function newEditEvent<E extends Edit>(
edit: E,
initiator: Initiator = 'user'
Expand Down

0 comments on commit 83d2532

Please sign in to comment.