Compare commits

...
7 changed files with 135 additions and 26 deletions

No files matched your search

Generated
+1
View File
@@ -2846,6 +2846,7 @@ dependencies = [
"bitflags 2.13.2",
"blake3",
"color",
"convert_case 0.12.0",
"core-types",
"derivative",
"document-container",
+2 -1
View File
@@ -26,6 +26,7 @@ document-format = { workspace = true, features = ["migrations", "network"] }
migration-formats = { workspace = true }
migration-compiled = { workspace = true }
migration-nodes = { workspace = true }
migration-core = { workspace = true, features = ["typed"] }
document-graph-storage = { workspace = true, features = ["conversion"] }
document-container = { workspace = true }
peer-transport = { workspace = true }
@@ -49,6 +50,7 @@ kurbo = { workspace = true }
futures = { workspace = true }
glam = { workspace = true }
derivative = { workspace = true }
convert_case = { workspace = true }
tsify = { workspace = true }
dyn-any = { workspace = true }
num_enum = { workspace = true }
@@ -80,4 +82,3 @@ env_logger = { workspace = true }
futures = { workspace = true }
node-macro = { workspace = true }
core-types = { workspace = true }
migration-core = { workspace = true, features = ["typed"] }
@@ -8,9 +8,11 @@ use crate::messages::layout::utility_types::widget_prelude::*;
use crate::messages::portfolio::document::utility_types::network_interface::{
InputMetadata, NodeNetworkInterface, NodeNetworkTemplate, NodeTemplate, NodeTemplateImplementation, NodeTypePersistentMetadata, Vec2InputSettings, WidgetOverride,
};
use crate::messages::portfolio::document_migration::legacy_aliases;
use crate::messages::portfolio::ingest::utility_types::TypeFilter;
use crate::messages::prelude::{DocumentId, FontsMessage, FontsMessageHandler, Message, ResourceMessageHandler, Responses};
use crate::node_graph_executor::NodeGraphExecutor;
use convert_case::{Boundary, Case, Casing};
use glam::DVec2;
use graph_craft::ProtoNodeIdentifier;
use graph_craft::document::value::*;
@@ -21,6 +23,7 @@ use graphene_std::raster::{CellularDistanceFunction, CellularReturnType, Color,
use graphene_std::transform::Footprint;
use graphene_std::vector::Vector;
use graphene_std::*;
use migration_core::{DeclarationKind, NodeMigration};
use std::collections::{HashMap, VecDeque};
pub struct NodeInspectorContext<'a> {
@@ -1620,6 +1623,8 @@ impl InputTypeConstraint {
/// The node catalog's entries, ordered by category and then by name.
pub fn collect_node_types() -> Vec<FrontendNodeType> {
let migrations = migration_core::registered_migrations();
let mut node_types: Vec<FrontendNodeType> = DOCUMENT_NODE_TYPES
.iter()
// A Passthrough is placed as a redirect dot on a wire, so it isn't offered as a node
@@ -1633,6 +1638,7 @@ pub fn collect_node_types() -> Vec<FrontendNodeType> {
FrontendNodeType {
identifier: identifier.serialized(),
input_types: InputTypeConstraint::constraints_for_all_inputs(&definition.node_template, &name),
search_aliases: former_names(identifier, &name, &migrations),
name,
category: definition.category.to_string(),
}
@@ -1647,6 +1653,51 @@ pub fn collect_node_types() -> Vec<FrontendNodeType> {
node_types
}
/// The display names of every declaration that migrates, directly or through others, to the node of `identifier`, and of its legacy aliases.
fn former_names(identifier: &DefinitionIdentifier, current_name: &str, migrations: &[&'static dyn NodeMigration]) -> Vec<String> {
let (current, legacy_aliases): (_, Vec<&str>) = match identifier {
DefinitionIdentifier::ProtoNode(proto_node_identifier) => ((proto_node_identifier.as_str(), DeclarationKind::Proto), legacy_aliases(proto_node_identifier).collect()),
DefinitionIdentifier::Network(name) => ((name.as_str(), DeclarationKind::Network), Vec::new()),
};
let mut visited = vec![current];
let mut pending = vec![current];
while let Some((identifier, kind)) = pending.pop() {
for migration in migrations {
let (source, target) = (migration.source(), migration.target());
let predecessor = (source.identifier, source.kind);
if target.identifier == identifier && target.kind == kind && !visited.contains(&predecessor) {
visited.push(predecessor);
pending.push(predecessor);
}
}
}
let mut names: Vec<String> = visited
.into_iter()
.skip(1)
.chain(legacy_aliases.into_iter().map(|alias| (alias, DeclarationKind::Proto)))
.map(|(identifier, kind)| declaration_display_name(identifier, kind))
.filter(|name| !name.eq_ignore_ascii_case(current_name))
.collect();
names.sort();
names.dedup();
names
}
/// A network definition's identifier is its display name, and a proto node's is approximated from its type name, like `MathFxNode` becoming "Math Fx".
fn declaration_display_name(identifier: &str, kind: DeclarationKind) -> String {
match kind {
DeclarationKind::Network => identifier.to_string(),
DeclarationKind::Proto => {
let type_name = identifier.rsplit("::").next().unwrap_or(identifier);
let name = type_name.strip_suffix("Node").unwrap_or(type_name);
name.set_boundaries(&[Boundary::LowerUpper, Boundary::DigitUpper, Boundary::Acronym]).to_case(Case::Title)
}
}
}
pub fn collect_node_descriptions() -> Vec<(String, String)> {
DOCUMENT_NODE_TYPES
.iter()
@@ -120,6 +120,9 @@ pub struct FrontendNodeType {
pub category: String,
#[serde(rename = "inputTypes")]
pub input_types: Vec<InputTypeConstraint>,
/// Names the node went by before migrations replaced it, which the catalog search also matches.
#[serde(rename = "searchAliases")]
pub search_aliases: Vec<String>,
}
#[cfg_attr(feature = "wasm", derive(tsify::Tsify))]
@@ -55,6 +55,14 @@ fn into_group_aliases() -> impl Iterator<Item = &'static &'static str> {
.flat_map(|replacement| replacement.aliases)
}
/// The identifiers and display names that legacy documents use for `node`.
pub fn legacy_aliases(node: &ProtoNodeIdentifier) -> impl Iterator<Item = &'static str> + '_ {
NODE_REPLACEMENTS
.iter()
.filter(move |replacement| replacement.node == *node)
.flat_map(|replacement| replacement.aliases.iter().copied())
}
/// Clears a migrated node's stored display name if it was only the replaced node's default name, so it shows its new node's name instead.
fn reset_default_display_name(document: &mut DocumentMessageHandler, node_id: &NodeId, network_path: &[NodeId], old_default_name: &str) {
if document.network_interface.display_name(node_id, network_path) == old_default_name {
@@ -353,8 +361,8 @@ const NODE_REPLACEMENTS: &[NodeReplacement<'static>] = &[
node: graphene_std::math_nodes::logical_and::IDENTIFIER,
aliases: &[
"graphene_core::ops::LogicalAndNode",
"graphene_core::ops::LogicNotNode",
"graphene_core::logic::LogicNotNode",
"graphene_core::ops::LogicAndNode",
"graphene_core::logic::LogicAndNode",
"graphene_math_nodes::LogicalAndNode",
],
},
@@ -362,8 +370,8 @@ const NODE_REPLACEMENTS: &[NodeReplacement<'static>] = &[
node: graphene_std::math_nodes::logical_not::IDENTIFIER,
aliases: &[
"graphene_core::ops::LogicalNotNode",
"graphene_core::ops::LogicOrNode",
"graphene_core::logic::LogicOrNode",
"graphene_core::ops::LogicNotNode",
"graphene_core::logic::LogicNotNode",
"graphene_math_nodes::LogicalNotNode",
],
},
@@ -371,8 +379,8 @@ const NODE_REPLACEMENTS: &[NodeReplacement<'static>] = &[
node: graphene_std::math_nodes::logical_or::IDENTIFIER,
aliases: &[
"graphene_core::ops::LogicalOrNode",
"graphene_core::ops::LogicAndNode",
"graphene_core::logic::LogicAndNode",
"graphene_core::ops::LogicOrNode",
"graphene_core::logic::LogicOrNode",
"graphene_math_nodes::LogicalOrNode",
],
},
@@ -1933,8 +1941,7 @@ fn migrate_node(node_id: &NodeId, node: &DocumentNode, network_path: &[NodeId],
&& inner.nodes.values().any(|n| {
matches!(&n.implementation, DocumentNodeImplementation::ProtoNode(identifier) if *identifier == graphene_std::math_nodes::floor::IDENTIFIER)
&& n.inputs.iter().any(|input| matches!(input, NodeInput::Import { import_index: 1, .. }))
})
&& let Some(node_definition) = resolve_network_node_type("Blend")
}) && let Some(node_definition) = resolve_network_node_type("Blend")
{
document.network_interface.replace_implementation(node_id, network_path, &mut node_definition.default_node_template());
}
@@ -1946,8 +1953,7 @@ fn migrate_node(node_id: &NodeId, node: &DocumentNode, network_path: &[NodeId],
n.inputs
.iter()
.any(|input| matches!(input, NodeInput::Import { import_type, import_index: 2 } if *import_type == item!(f64)))
})
&& let Some(node_definition) = resolve_network_node_type("Regex Find")
}) && let Some(node_definition) = resolve_network_node_type("Regex Find")
{
document.network_interface.replace_implementation(node_id, network_path, &mut node_definition.default_node_template());
}
@@ -21,8 +21,36 @@
$: nodeCategories = buildNodeCategories(searchTerm);
type TextSegment = {
text: string;
highlighted: boolean;
};
type NodeCatalogEntry = {
nodeType: FrontendNodeType;
matchedAliasSegments: TextSegment[] | undefined;
};
// Splits `text` into runs that are highlighted where one of the lowercase `terms` occurs
function highlightTerms(text: string, terms: string[]): TextSegment[] {
const lowercaseText = text.toLowerCase();
const highlighted = new Array<boolean>(text.length).fill(false);
terms.forEach((term) => {
const start = lowercaseText.indexOf(term);
if (term.length > 0 && start !== -1) highlighted.fill(true, start, start + term.length);
});
const segments: TextSegment[] = [];
highlighted.forEach((isHighlighted, index) => {
const last = segments.at(-1);
if (last?.highlighted === isHighlighted) last.text += text[index];
else segments.push({ text: text[index], highlighted: isHighlighted });
});
return segments;
}
type NodeCategoryDetails = {
nodes: FrontendNodeType[];
nodes: NodeCatalogEntry[];
open: boolean;
};
@@ -43,23 +71,24 @@
nodeTypes.forEach((node) => {
let matchesTypeSearch = true;
let matchesRemainingTerms = true;
if (isTypeSearch && typeSearchTerm) {
matchesTypeSearch = node.inputTypes?.some((constraint) => constraint === "All" || constraint.Limited.some((inputType) => inputType.toLowerCase().includes(typeSearchTerm))) || false;
}
if (remainingSearchTerms.length > 0) {
matchesRemainingTerms = remainingSearchTerms.every((term) => {
const nameMatch = node.name.toLowerCase().includes(term);
const categoryMatch = node.category.toLowerCase().includes(term);
const termsUnmatchedByName = remainingSearchTerms.filter((term) => {
const nameMatch = node.name.toLowerCase().includes(term);
const categoryMatch = node.category.toLowerCase().includes(term);
// Quick and dirty hack to alias "Layer" to "Merge" in the search
const layerAliasMatch = node.name === "Merge" && "layer".includes(term);
// Quick and dirty hack to alias "Layer" to "Merge" in the search
const layerAliasMatch = node.name === "Merge" && "layer".includes(term);
return nameMatch || categoryMatch || layerAliasMatch;
});
}
return !nameMatch && !categoryMatch && !layerAliasMatch;
});
const matchedAlias = termsUnmatchedByName.length > 0 ? node.searchAliases.find((alias) => termsUnmatchedByName.every((term) => alias.toLowerCase().includes(term))) : undefined;
const matchesRemainingTerms = termsUnmatchedByName.length === 0 || matchedAlias !== undefined;
const matchedAliasSegments = matchedAlias !== undefined ? highlightTerms(matchedAlias, termsUnmatchedByName) : undefined;
// Node matches if it passes both type search and remaining terms filters
const includesSearchTerm = matchesTypeSearch && matchesRemainingTerms;
@@ -76,11 +105,11 @@
if (category) {
category.open = category.open || open;
category.nodes.push(node);
category.nodes.push({ nodeType: node, matchedAliasSegments });
} else {
categories.set(node.category, {
open,
nodes: [node],
nodes: [{ nodeType: node, matchedAliasSegments }],
});
}
});
@@ -102,14 +131,20 @@
<summary>
<TextLabel>{nodeCategory[0]}</TextLabel>
</summary>
{#each nodeCategory[1].nodes as nodeType}
{#each nodeCategory[1].nodes as { nodeType, matchedAliasSegments }}
<TextButton
{disabled}
label={nodeType.name}
tooltipLabel={nodeType.name}
tooltipDescription={nodeType.identifier ? $nodeGraph.nodeDescriptions.get(nodeType.identifier) : undefined}
action={() => dispatch("selectNodeType", nodeType.identifier)}
/>
>
{#if matchedAliasSegments}
<span class="matched-alias"
>{#each matchedAliasSegments as segment}<span class:highlighted={segment.highlighted}>{segment.text}</span>{/each}</span
>
{/if}
</TextButton>
{/each}
</details>
{:else}
@@ -172,6 +207,17 @@
&:last-child .text-button {
margin-bottom: 0;
}
.matched-alias {
margin-left: 8px;
overflow: hidden;
text-overflow: ellipsis;
color: var(--color-8-uppergray);
.highlighted {
color: var(--button-text-color);
}
}
}
}
}
@@ -88,6 +88,7 @@
{#if label}
<TextLabel>{label}</TextLabel>
{/if}
<slot />
</button>
{#if menuListChildrenExists}
<MenuList