* zin: refactor: rename node->type to node->fullType, node->shortType to node->type.

This commit is contained in:
sunhao
2024-02-26 17:09:45 +08:00
parent 448a86a606
commit 91da016692
9 changed files with 15 additions and 15 deletions
+1 -1
View File
@@ -85,7 +85,7 @@ class context extends \zin\utils\dataset
if($item instanceof node)
{
if($item->parent || $item->shortType() === 'wg') return false;
if($item->parent || $item->type() === 'wg') return false;
if(!isset($this->globalRenderList[$item->gid])) $this->globalRenderList[$item->gid] = $item;
return true;
+1 -1
View File
@@ -62,7 +62,7 @@ class dom
{
return array(
'gid' => $this->wg->gid,
'type' => $this->wg->type(),
'type' => $this->wg->fullType(),
'count' => count($this->children),
'renderInner' => $this->renderInner,
'renderType' => $this->renderType,
+1 -1
View File
@@ -35,7 +35,7 @@ class h extends node
return 'h::' . $this->tagName();
}
public function shortType(): string
public function type(): string
{
return $this->tagName();
}
+1 -1
View File
@@ -251,7 +251,7 @@ class hook
{
return array(
'gid' => $this->root->gid,
'type' => $this->root->type(),
'type' => $this->root->fullType(),
'count' => $this->count(),
'selectors' => $this->selectors,
'items' => $this->items
+6 -6
View File
@@ -75,14 +75,14 @@ class node implements \JsonSerializable
return $this->render();
}
public function type(): string
public function fullType(): string
{
return get_called_class();
}
public function shortType(): string
public function type(): string
{
$type = $this->type();
$type = $this->fullType();
if(str_contains($type, '\\'))
{
$type = substr($type, strrpos($type, '\\') + 1);
@@ -97,7 +97,7 @@ class node implements \JsonSerializable
public function displayID(): string
{
$displayID = $this->type() . '~' . $this->gid;
$displayID = $this->fullType() . '~' . $this->gid;
$id = $this->id();
if(!empty($id)) $displayID .= "#$id";
@@ -213,7 +213,7 @@ class node implements \JsonSerializable
if($name === 'children' && $child instanceof node)
{
$blockName = static::getNameFromBlockMap($child->type());
$blockName = static::getNameFromBlockMap($child->fullType());
if($blockName !== null) $name = $blockName;
}
@@ -294,7 +294,7 @@ class node implements \JsonSerializable
{
$json = new stdClass();
$json->gid = $this->gid;
$json->type = $this->shortType();
$json->type = $this->type();
$json->props = $this->props->toJSON();
$json->blocks = array();
+2 -2
View File
@@ -24,10 +24,10 @@ class text extends node
public function type(): string
{
return 'node::' . $this->shortType();
return 'node::' . $this->type();
}
public function shortType(): string
public function type(): string
{
return $this->prop('html') ? 'html' : 'text';
}
+1 -1
View File
@@ -22,7 +22,7 @@ class wg extends node
// if(empty($events)) return null;
// $id = $this->id();
// $code = array($this->shortType() === 'html' ? 'const ele = document;' : 'const ele = document.getElementById("' . (empty($id) ? $this->gid : $id) . '");if(!ele)return;const $ele = $(ele); const events = new Set(($ele.attr("data-zin-events") || "").split(" ").filter(Boolean));');
// $code = array($this->type() === 'html' ? 'const ele = document;' : 'const ele = document.getElementById("' . (empty($id) ? $this->gid : $id) . '");if(!ele)return;const $ele = $(ele); const events = new Set(($ele.attr("data-zin-events") || "").split(" ").filter(Boolean));');
// foreach($events as $event => $bindingList)
// {
// $code[] = "\$ele.on('$event.on.zin', function(e){";
+1 -1
View File
@@ -62,7 +62,7 @@ class zin
{
if(is_object($item))
{
if((isset($item->parent) && $item->parent) || ($item instanceof wg && ($item->shortType() === 'wg' || $item->shortType() === 'item')))
if((isset($item->parent) && $item->parent) || ($item instanceof wg && ($item->type() === 'wg' || $item->type() === 'item')))
continue;
}
$globalItems[] = $item;
+1 -1
View File
@@ -113,7 +113,7 @@ function groupWgInList(wg|array $items, string|array $types): array
{
if(!($item instanceof wg)) continue;
$type = $item->shortType();
$type = $item->type();
if(isset($typesMap[$type])) $typesMap[$type][] = $item;
else $restList[] = $item;
}