Move types definition to global scope

This commit is contained in:
GogoVega 2024-12-18 18:31:39 +01:00
parent db82b10e25
commit d1001f6be4
No known key found for this signature in database
GPG Key ID: E1E048B63AC5AC2B

View File

@ -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<object>; }} Group
* @typedef {Node & {}} Junction
* @typedef {Node & { in: Array<object>; out: Array<object>;
* instances: Array<Node>; env?: Array<object>; }} 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<Group>} [groups] An array with added groups
* @property {Array<Junction>} [junctions] An array with added junctions
* @property {Array<Link>} [links] An array with added links
* @property {Array<string>} [nodes] An array with added node ids
* @property {Array<Link>} [removedLinks] An array with removed links
* @property {{ id: string, changed: boolean | undefined,
* instances: Array<Node> }} [subflow]
* @property {Array<Subflow>} [subflows] An array with added subflows (tabs)
* @property {Array<Workspace>} [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> | 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<Group>} [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<Link>} [links] An array with added links (during
* conversion to Subflow - links inside the subflow)
* @property {Array<string>} [nodes] An array with subflow node ids
* @property {Array<Link>} [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<string, object>} [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<Link>} [createdLinks] An array with created links
* @property {boolean} dirty Whether or not the workspace is dirty
* @property {Array<Group>} [groups] An array with removed groups
* @property {Array<Junction>} [junctions] An array with removed junctions
* @property {Array<Link>} [links] An array with removed links
* @property {Array<Node>} [nodes] An array with removed nodes
* @property {{ id: string | undefined, instances: Array<Node> | undefined,
* status: string | undefined }} [subflow]
* @property {Array<SubflowNode>} [subflowInputs] An array with removed
* subflow input
* @property {Array<SubflowNode>} [subflowOutputs] An array with removed
* subflow outputs
* @property {Array<Subflow>} [subflows] An array with removed subflows (tabs)
* @property {Array<Workspace>} [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<Link>} [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<Link>} [links] An array with removed links (during
* undo conversion to Subflow - links inside the subflow)
* @property {Array<Node>} [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<Subflow>} [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<Link>} [createdLinks] An array with links to create (redo)
* @property {boolean} dirty Whether or not the workspace is dirty
* @property {Array<Link>} [links] An array with removed links
* @property {Node} node The current node/subflow
* @property {object} [outputMap]
* @property {{ instances: Array<Node> | 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<Link>} [links]
* @property {Array<{ n: Node, ox: number, oy: number, dx: number,
* dy: number }>} nodes An array with nodes moved
* @property {Array<Link>} [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<HistoryEvent>} 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> | 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<string>} workspaces[].from Ordered array of workspace ids
* @property {Array<string>} 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<string, boolean>} 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<Node>} config An array with the complete flows
* @property {boolean} dirty The dirty state before replacement
* @property {Record<string, boolean>} 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<Node>} 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<Group>} [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<object>; }} Group
* @typedef {Node & {}} Junction
* @typedef {Node & { in: Array<object>; out: Array<object>;
* instances: Array<Node>; env?: Array<object>; }} 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<HistoryEvent>}
@ -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<Group>} [groups] An array with added groups
* @property {Array<Junction>} [junctions] An array with added junctions
* @property {Array<Link>} [links] An array with added links
* @property {Array<string>} [nodes] An array with added node ids
* @property {Array<Link>} [removedLinks] An array with removed links
* @property {{ id: string, changed: boolean | undefined,
* instances: Array<Node> }} [subflow]
* @property {Array<Subflow>} [subflows] An array with added subflows (tabs)
* @property {Array<Workspace>} [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<string, object>} [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<Link>} [createdLinks] An array with created links
* @property {Array<Group>} [groups] An array with removed groups
* @property {Array<Junction>} [junctions] An array with removed junctions
* @property {Array<Link>} [links] An array with removed links
* @property {Array<Node>} [nodes] An array with removed nodes
* @property {{ id: string | undefined, instances: Array<Node> | undefined,
* status: string | undefined }} [subflow]
* @property {Array<SubflowNode>} [subflowInputs] An array with removed
* subflow input
* @property {Array<SubflowNode>} [subflowOutputs] An array with removed
* subflow outputs
* @property {Array<Subflow>} [subflows] An array with removed subflows (tabs)
* @property {Array<Workspace>} [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<Link>} [links]
* @property {Array<{ n: Node, ox: number, oy: number, dx: number,
* dy: number }>} nodes An array with nodes moved
* @property {Array<Link>} [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<Link>} [links] An array with added links (during
* conversion to Subflow - links inside the subflow)
* @property {Array<string>} [nodes] An array with subflow node ids
* @property {Array<Link>} [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<Link>} [createdLinks] An array with added links
* (during undo conversion to Subflow - links from active workspace)
* @property {Array<Link>} [links] An array with removed links (during
* undo conversion to Subflow - links inside the subflow)
* @property {Array<Node>} [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<Subflow>} [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<string>} workspaces[].from Ordered array of workspace ids
* @property {Array<string>} 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<Group>} [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<Group>} [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> | 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> | 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<Link>} [createdLinks] An array with links to create (redo)
* @property {Array<Link>} [links] An array with removed links
* @property {Node} node The current node/subflow
* @property {object} [outputMap]
* @property {{ instances: Array<Node> | 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<string, boolean>} 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<Node>} config An array with the complete flows
* @property {boolean} dirty The dirty state before replacement
* @property {Record<string, boolean>} 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<Node>} 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<HistoryEvent>} 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 = {}