From d1001f6be4f39e1e45ce1ad92cbe83589efdc935 Mon Sep 17 00:00:00 2001 From: GogoVega <92022724+GogoVega@users.noreply.github.com> Date: Wed, 18 Dec 2024 18:31:39 +0100 Subject: [PATCH] Move types definition to global scope --- .../@node-red/editor-client/src/js/history.js | 384 ++++++++++-------- 1 file changed, 215 insertions(+), 169 deletions(-) diff --git a/packages/node_modules/@node-red/editor-client/src/js/history.js b/packages/node_modules/@node-red/editor-client/src/js/history.js index 5f719cc45..711500348 100644 --- a/packages/node_modules/@node-red/editor-client/src/js/history.js +++ b/packages/node_modules/@node-red/editor-client/src/js/history.js @@ -14,33 +14,224 @@ * limitations under the License. **/ +/** + * TODO: Import types from RED.nodes + * @typedef {object} Node + * @typedef {{ source: Node; sourcePort: number; target: Node; }} Link + * @typedef {Node & { env?: Array; }} Group + * @typedef {Node & {}} Junction + * @typedef {Node & { in: Array; out: Array; + * instances: Array; env?: Array; }} Subflow + * @typedef {Node & { type: "subflow"; direction: "in"|"out"; }} SubflowNode + * @typedef {Node & {}} Workspace + */ + +/** + * @typedef {object} AddEvent + * @property {"add"} t The history event type + * @property {(ev: HistoryEvent) => void} [callback] a function called after + * the undo/redo event + * @property {boolean} dirty Whether or not the workspace is dirty + * @property {Array} [groups] An array with added groups + * @property {Array} [junctions] An array with added junctions + * @property {Array} [links] An array with added links + * @property {Array} [nodes] An array with added node ids + * @property {Array} [removedLinks] An array with removed links + * @property {{ id: string, changed: boolean | undefined, + * instances: Array }} [subflow] + * @property {Array} [subflows] An array with added subflows (tabs) + * @property {Array} [workspaces] An array with added workspaces + * @memberof RED.history + * + * @typedef {object} AddToGroupEvent + * @property {"addToGroup"} t The history event type + * @property {(ev: HistoryEvent) => void} [callback] a function called after + * the undo/redo event + * @property {boolean} dirty Whether or not the workspace is dirty + * @property {Group} group The group in which remove nodes + * @property {Array | Node} [nodes] An array of nodes or one node + * to remove from the group + * @property {boolean} [reparent] Either to re-add to parent group + * @memberof RED.history + * + * @typedef {object} CreateGroupEvent + * @property {"createGroup"} t The history event type + * @property {(ev: HistoryEvent) => void} [callback] a function called after + * the undo/redo event + * @property {boolean} dirty Whether or not the workspace is dirty + * @property {Array} [groups] An array with groups to remove + * @memberof RED.history + * + * @typedef {object} CreateSubflowEvent + * @property {"createSubflow"} t The history event type + * @property {string} activeWorkspace The id of the active workspace + * @property {(ev: HistoryEvent) => void} [callback] a function called after + * the undo/redo event + * @property {boolean} dirty Whether or not the workspace is dirty + * @property {Array} [links] An array with added links (during + * conversion to Subflow - links inside the subflow) + * @property {Array} [nodes] An array with subflow node ids + * @property {Array} [removedLinks] An array with removed links + * (during conversion to Subflow - links from active workspace) + * @property {{ subflow: Subflow, offsetX: number | undefined, + * offsetY: number | undefined }} subflow The subflow created to delete + * @memberof RED.history + * + * @typedef {object} DeleteEvent + * @property {"delete"} t The history event type + * @property {(ev: HistoryEvent) => void} [callback] a function called after + * the undo/redo event + * @property {Record} [changes] An object with changes. + * The key is the id of a node and the value is an object with the changes + * to apply + * @property {Array} [createdLinks] An array with created links + * @property {boolean} dirty Whether or not the workspace is dirty + * @property {Array} [groups] An array with removed groups + * @property {Array} [junctions] An array with removed junctions + * @property {Array} [links] An array with removed links + * @property {Array} [nodes] An array with removed nodes + * @property {{ id: string | undefined, instances: Array | undefined, + * status: string | undefined }} [subflow] + * @property {Array} [subflowInputs] An array with removed + * subflow input + * @property {Array} [subflowOutputs] An array with removed + * subflow outputs + * @property {Array} [subflows] An array with removed subflows (tabs) + * @property {Array} [workspaces] An array with removed workspace + * @memberof RED.history + * + * @typedef {object} DeleteSubflowEvent + * @property {"deleteSubflow"} t The history event type + * @property {string} activeWorkspace The id of the active workspace + * @property {(ev: HistoryEvent) => void} [callback] a function called after + * the undo/redo event + * @property {Array} [createdLinks] An array with added links + * (during undo conversion to Subflow - links from active workspace) + * @property {boolean} dirty Whether or not the workspace is dirty + * @property {Array} [links] An array with removed links (during + * undo conversion to Subflow - links inside the subflow) + * @property {Array} [movedNodes] An array with nodes to move to the + * subflow to create + * @property {{ subflow: Subflow, offsetX: number | undefined, + * offsetY: number | undefined }} subflow The deleted subflow to create + * @property {Array} [subflows] An array with subflow nodes + * (redo conversion to subflow) + * @memberof RED.history + * + * @typedef {object} EditEvent + * @property {"edit"} t The history event type + * @property {(ev: HistoryEvent) => void} [callback] a function called after + * the undo/redo event + * @property {boolean} changed The changed node state before modifications + * @property {object} changes An object with previous node properties value + * @property {Array} [createdLinks] An array with links to create (redo) + * @property {boolean} dirty Whether or not the workspace is dirty + * @property {Array} [links] An array with removed links + * @property {Node} node The current node/subflow + * @property {object} [outputMap] + * @property {{ instances: Array | undefined, + * inputCount: number | undefined, outputCount: number | undefined, + * status: string | undefined }} [subflow] Subflow properties + * @memberof RED.history + * + * @typedef {object} MoveEvent + * @property {"move"} t The history event type + * @property {Group} [addToGroup] The group in which the nodes were added + * @property {(ev: HistoryEvent) => void} [callback] a function called after + * the undo/redo event + * @property {boolean} dirty Whether or not the workspace is dirty + * @property {Array} [links] + * @property {Array<{ n: Node, ox: number, oy: number, dx: number, + * dy: number }>} nodes An array with nodes moved + * @property {Array} [removedLinks] + * @property {Group} [removeFromGroup] The group in which the nodes were + * removed + * @memberof RED.history + * + * @typedef {object} MultiEvent + * @property {"multi"} t The history event type + * @property {(ev: HistoryEvent) => void} [callback] a function called after + * the undo/redo event + * @property {boolean} dirty Whether or not the workspace is dirty + * @property {Array} events An array with events + * @memberof RED.history + * + * @typedef {object} RemoveFromGroupEvent + * @property {"removeFromGroup"} t The history event type + * @property {(ev: HistoryEvent) => void} [callback] a function called after + * the undo/redo event + * @property {boolean} dirty Whether or not the workspace is dirty + * @property {Group} group The group in which add nodes + * @property {Array | Node} [nodes] An array of nodes or one node + * to add to the group + * @property {boolean} [reparent] Either to re-add to parent group + * @memberof RED.history + * + * @typedef {object} ReorderEvent + * @property {"reorder"} t The history event type + * @property {(ev: HistoryEvent) => void} [callback] a function called after + * the undo/redo event + * @property {boolean} dirty Whether or not the workspace is dirty + * @property {{ from: string, to: string, z: string }} [nodes] + * @property {object} [workspaces] + * @property {Array} workspaces[].from Ordered array of workspace ids + * @property {Array} workspaces[].to Ordered array of workspace ids + * @memberof RED.history + * + * @typedef {object} CompleteReplaceEvent + * @property {"replace"} t The history event type + * @property {(ev: HistoryEvent) => void} [callback] a function called after + * the undo/redo event + * @property {Record} changed An object with a node id + * as key and the node changed property as value + * @property {true} complete Either the {@link ReplaceEvent.config} + * property contains the complete flows + * @property {Array} config An array with the complete flows + * @property {boolean} dirty The dirty state before replacement + * @property {Record} moved An object with a node id + * as key and the node moved property as value + * @property {string} rev A revision version + * @memberof RED.history + * + * @typedef {object} IncompleteReplaceEvent + * @property {"replace"} t The history event type + * @property {(ev: HistoryEvent) => void} [callback] a function called after + * the undo/redo event + * @property {false} [complete] Either the {@link ReplaceEvent.config} + * property contains the complete flows + * @property {Array} config An array with config nodes and/or + * subflow definitions to replace. + * @property {boolean} dirty Whether or not the workspace is dirty + * @memberof RED.history + * + * @typedef {CompleteReplaceEvent|IncompleteReplaceEvent} ReplaceEvent + * @memberof RED.history + * + * @typedef {object} UngroupEvent + * @property {"ungroup"} t The history event type + * @property {(ev: HistoryEvent) => void} [callback] a function called after + * the undo/redo event + * @property {boolean} dirty Whether or not the workspace is dirty + * @property {Array} [groups] An array with groups to create + * @memberof RED.history + * + * @typedef {"add"|"delete"|"edit"|"move"|"multi"|"reorder"|"replace"| + * "createSubflow"|"deleteSubflow"|"addToGroup"|"createGroup"|"ungroup"| + * "removeFromGroup"} HistoryType + * + * @typedef { AddEvent | DeleteEvent | EditEvent | MoveEvent | MultiEvent | + * ReorderEvent | ReplaceEvent | CreateSubflowEvent | DeleteSubflowEvent | + * AddToGroupEvent | CreateGroupEvent | UngroupEvent | RemoveFromGroupEvent + * } HistoryEvent + * @memberof RED.history + */ + /** * An API for undo / redo history buffer * @namespace RED.history */ RED.history = (function () { - /** - * GLOBAL NOTE: Handle event and users ONLY for edit/change event - * TODO: Import types from RED.nodes - * - * @typedef {object} Node - * @typedef {{ source: Node; sourcePort: number; target: Node; }} Link - * @typedef {Node & { env?: Array; }} Group - * @typedef {Node & {}} Junction - * @typedef {Node & { in: Array; out: Array; - * instances: Array; env?: Array; }} Subflow - * @typedef {Node & { type: "subflow"; direction: "in"|"out"; }} SubflowNode - * @typedef {Node & {}} Workspace - * - * @typedef {"add"|"delete"|"edit"|"move"|"multi"|"reorder"|"replace"| - * "createSubflow"|"deleteSubflow"|"addToGroup"|"createGroup"|"ungroup"| - * "removeFromGroup"} HistoryType - * @typedef {{ t: HistoryType; dirty: boolean; callback?: (ev: HistoryEvent) => void; } - * & (AddEvent | DeleteEvent | EditEvent | MoveEvent | MultiEvent | ReorderEvent | - * ReplaceEvent | CreateSubflowEvent | DeleteSubflowEvent | AddToGroupEvent | - * CreateGroupEvent | UngroupEvent | RemoveFromGroupEvent) } HistoryEvent - * @memberof RED.history - */ + // GLOBAL NOTE: Handle event and users ONLY for edit/change event /** * @type {Array} @@ -72,19 +263,6 @@ RED.history = (function () { /** * Called on the `add` history event * - * @typedef {object} AddEvent - * @property {"add"} t The history event type - * @property {Array} [groups] An array with added groups - * @property {Array} [junctions] An array with added junctions - * @property {Array} [links] An array with added links - * @property {Array} [nodes] An array with added node ids - * @property {Array} [removedLinks] An array with removed links - * @property {{ id: string, changed: boolean | undefined, - * instances: Array }} [subflow] - * @property {Array} [subflows] An array with added subflows (tabs) - * @property {Array} [workspaces] An array with added workspaces - * @memberof RED.history - * * @param {AddEvent} ev The history event to undo * @param {object} [modifiedTabs] * @returns {DeleteEvent} The generated history event to redo @@ -220,26 +398,6 @@ RED.history = (function () { /** * Called on the `delete` history event * - * @typedef {object} DeleteEvent - * @property {"delete"} t The history event type - * @property {Record} [changes] An object with changes. - * The key is the id of a node and the value is an object with the changes - * to apply - * @property {Array} [createdLinks] An array with created links - * @property {Array} [groups] An array with removed groups - * @property {Array} [junctions] An array with removed junctions - * @property {Array} [links] An array with removed links - * @property {Array} [nodes] An array with removed nodes - * @property {{ id: string | undefined, instances: Array | undefined, - * status: string | undefined }} [subflow] - * @property {Array} [subflowInputs] An array with removed - * subflow input - * @property {Array} [subflowOutputs] An array with removed - * subflow outputs - * @property {Array} [subflows] An array with removed subflows (tabs) - * @property {Array} [workspaces] An array with removed workspace - * @memberof RED.history - * * @param {DeleteEvent} ev The history event to undo * @param {object} [modifiedTabs] * @returns {AddEvent} The generated history event to redo @@ -440,17 +598,6 @@ RED.history = (function () { /** * Called on the `move` history event * - * @typedef {object} MoveEvent - * @property {"move"} t The history event type - * @property {Group} [addToGroup] The group in which the nodes were added - * @property {Array} [links] - * @property {Array<{ n: Node, ox: number, oy: number, dx: number, - * dy: number }>} nodes An array with nodes moved - * @property {Array} [removedLinks] - * @property {Group} [removeFromGroup] The group in which the nodes were - * removed - * @memberof RED.history - * * @param {MoveEvent} ev The history event to undo * @returns {MoveEvent} The generated history event to redo */ @@ -508,18 +655,6 @@ RED.history = (function () { /** * Called on the `createSubflow` history event * - * @typedef {object} CreateSubflowEvent - * @property {"createSubflow"} t The history event type - * @property {string} activeWorkspace The id of the active workspace - * @property {Array} [links] An array with added links (during - * conversion to Subflow - links inside the subflow) - * @property {Array} [nodes] An array with subflow node ids - * @property {Array} [removedLinks] An array with removed links - * (during conversion to Subflow - links from active workspace) - * @property {{ subflow: Subflow, offsetX: number | undefined, - * offsetY: number | undefined }} subflow The subflow created to delete - * @memberof RED.history - * * @param {CreateSubflowEvent} ev The history event to undo * @returns {DeleteSubflowEvent} The generated history event to redo */ @@ -582,21 +717,6 @@ RED.history = (function () { /** * Called on the `deleteSubflow` history event * - * @typedef {object} DeleteSubflowEvent - * @property {"deleteSubflow"} t The history event type - * @property {string} activeWorkspace The id of the active workspace - * @property {Array} [createdLinks] An array with added links - * (during undo conversion to Subflow - links from active workspace) - * @property {Array} [links] An array with removed links (during - * undo conversion to Subflow - links inside the subflow) - * @property {Array} [movedNodes] An array with nodes to move to the - * subflow to create - * @property {{ subflow: Subflow, offsetX: number | undefined, - * offsetY: number | undefined }} subflow The deleted subflow to create - * @property {Array} [subflows] An array with subflow nodes - * (redo conversion to subflow) - * @memberof RED.history - * * @param {DeleteSubflowEvent} ev The history event to undo * @returns {CreateSubflowEvent} The generated history event to redo */ @@ -665,14 +785,6 @@ RED.history = (function () { /** * Called on the `reorder` history event * - * @typedef {object} ReorderEvent - * @property {"reorder"} t The history event type - * @property {{ from: string, to: string, z: string }} [nodes] - * @property {object} [workspaces] - * @property {Array} workspaces[].from Ordered array of workspace ids - * @property {Array} workspaces[].to Ordered array of workspace ids - * @memberof RED.history - * * @param {ReorderEvent} ev The history event to undo * @returns {ReorderEvent} The generated history event to redo */ @@ -706,11 +818,6 @@ RED.history = (function () { /** * Called on the `createGroup` history event * - * @typedef {object} CreateGroupEvent - * @property {"createGroup"} t The history event type - * @property {Array} [groups] An array with groups to remove - * @memberof RED.history - * * @param {CreateGroupEvent} ev The history event to undo * @returns {UngroupEvent} The generated history event to redo */ @@ -735,11 +842,6 @@ RED.history = (function () { /** * Called on the `ungroup` history event * - * @typedef {object} UngroupEvent - * @property {"ungroup"} t The history event type - * @property {Array} [groups] An array with groups to create - * @memberof RED.history - * * @param {UngroupEvent} ev The history event to undo * @returns {CreateGroupEvent} The generated history event to redo */ @@ -775,14 +877,6 @@ RED.history = (function () { /** * Called on the `addToGroup` history event * - * @typedef {object} AddToGroupEvent - * @property {"addToGroup"} t The history event type - * @property {Group} group The group in which remove nodes - * @property {Array | Node} [nodes] An array of nodes or one node - * to remove from the group - * @property {boolean} [reparent] Either to re-add to parent group - * @memberof RED.history - * * @param {AddToGroupEvent} ev The history event to undo * @returns {RemoveFromGroupEvent} The generated history event to redo */ @@ -806,14 +900,6 @@ RED.history = (function () { /** * Called on the `removeFromGroup` history event * - * @typedef {object} RemoveFromGroupEvent - * @property {"removeFromGroup"} t The history event type - * @property {Group} group The group in which add nodes - * @property {Array | Node} [nodes] An array of nodes or one node - * to add to the group - * @property {boolean} [reparent] Either to re-add to parent group - * @memberof RED.history - * * @param {RemoveFromGroupEvent} ev The history event to undo * @returns {AddToGroupEvent} The generated history event to redo */ @@ -837,19 +923,6 @@ RED.history = (function () { /** * Called on the `edit` history event * - * @typedef {object} EditEvent - * @property {"edit"} t The history event type - * @property {boolean} changed The changed node state before modifications - * @property {object} changes An object with previous node properties value - * @property {Array} [createdLinks] An array with links to create (redo) - * @property {Array} [links] An array with removed links - * @property {Node} node The current node/subflow - * @property {object} [outputMap] - * @property {{ instances: Array | undefined, - * inputCount: number | undefined, outputCount: number | undefined, - * status: string | undefined }} [subflow] Subflow properties - * @memberof RED.history - * * @param {EditEvent} ev The history event to undo * @returns {EditEvent} The generated history event to redo */ @@ -1096,30 +1169,6 @@ RED.history = (function () { /** * Called on the `replace` history event * - * @typedef {object} CompleteReplaceEvent - * @property {"replace"} t The history event type - * @property {Record} changed An object with a node id - * as key and the node changed property as value - * @property {true} complete Either the {@link ReplaceEvent.config} - * property contains the complete flows - * @property {Array} config An array with the complete flows - * @property {boolean} dirty The dirty state before replacement - * @property {Record} moved An object with a node id - * as key and the node moved property as value - * @property {string} rev A revision version - * @memberof RED.history - * - * @typedef {object} IncompleteReplaceEvent - * @property {"replace"} t The history event type - * @property {false} [complete] Either the {@link ReplaceEvent.config} - * property contains the complete flows - * @property {Array} config An array with config nodes and/or - * subflow definitions to replace. - * @memberof RED.history - * - * @typedef {CompleteReplaceEvent|IncompleteReplaceEvent} ReplaceEvent - * @memberof RED.history - * * @param {ReplaceEvent} ev The history event to undo * @returns {ReplaceEvent} The generated history event to redo */ @@ -1199,11 +1248,6 @@ RED.history = (function () { /** * Called on the `multi` history event * - * @typedef {object} MultiEvent - * @property {"multi"} t The history event type - * @property {Array} events An array with events - * @memberof RED.history - * * @param {MultiEvent} ev The history event to undo * @returns {MultiEvent} The generated history event to redo */ @@ -1403,3 +1447,5 @@ RED.history = (function () { } }; })(); + +module.exports = {}