Skip to content

Commit

Permalink
allow to references sub components of other domkit with root.sub name
Browse files Browse the repository at this point in the history
  • Loading branch information
ncannasse committed Jan 30, 2025
1 parent 88bc299 commit ba468ab
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
9 changes: 8 additions & 1 deletion hide/comp/DomkitEditor.hx
Original file line number Diff line number Diff line change
Expand Up @@ -349,14 +349,21 @@ class DomkitChecker extends ScriptEditor.ScriptChecker {
}

function resolveComp( name : String ) : TypedComponent {

var rootComp = name;
var index = name.indexOf(".");
if( index >= 0 ) {
rootComp = name.substr(0, index);
name = name.substr(index+1);
}
var c = components.get(name);
if( c != null )
return c;
// dynamic load from comps directories
var dirs : Array<String> = config.get("domkit.components");
if( dirs == null ) dirs = ["ui/comp"];
for( d in dirs ) {
var path = d+"/"+name+".domkit";
var path = d+"/"+rootComp.split("-").join("_")+".domkit";
var content = try sys.io.File.getContent(ide.getPath(path)) catch( e : Dynamic ) continue;
var data = hrt.impl.DomkitViewer.DomkitFile.parse(content);
var node = null, params = new Map();
Expand Down
11 changes: 11 additions & 0 deletions hrt/impl/DomkitViewer.hx
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,16 @@ class DomkitViewer {
}
}

static function clearImportNames( m : domkit.MarkupParser.Markup ) {
switch( m.kind ) {
case Node(n) if( n != null && n.indexOf(".") >= 0 ): m.kind = Node(n.split(".").pop()); // remove root.name
default:
}
if( m.children != null )
for( c in m.children )
clearImportNames(c);
}

public static function loadSource( path : String, pos : Position, fields : Array<Field> ) {
var name = path.split("/").pop().split("_").join("-");
var dotPos = name.lastIndexOf(".");
Expand Down Expand Up @@ -104,6 +114,7 @@ class DomkitViewer {
}
if( hasDynParam )
removeDynParamsRec(m, dynParams);
clearImportNames(m);

fields.push({
name : "__CSS",
Expand Down

0 comments on commit ba468ab

Please sign in to comment.