From 91da016692ca6871ce480b5f0f1e08b3e34d8e32 Mon Sep 17 00:00:00 2001 From: sunhao Date: Thu, 22 Feb 2024 12:08:43 +0800 Subject: [PATCH] * zin: refactor: rename node->type to node->fullType, node->shortType to node->type. --- lib/zin/core/context.class.php | 2 +- lib/zin/core/dom.class.php | 2 +- lib/zin/core/h.class.php | 2 +- lib/zin/core/hook.class.php | 2 +- lib/zin/core/node.class.php | 12 ++++++------ lib/zin/core/text.class.php | 4 ++-- lib/zin/core/wg.class.php | 2 +- lib/zin/core/zin.class.php | 2 +- lib/zin/core/zin.func.php | 2 +- 9 files changed, 15 insertions(+), 15 deletions(-) diff --git a/lib/zin/core/context.class.php b/lib/zin/core/context.class.php index 8aa4e80c61..78bfbfa266 100644 --- a/lib/zin/core/context.class.php +++ b/lib/zin/core/context.class.php @@ -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; diff --git a/lib/zin/core/dom.class.php b/lib/zin/core/dom.class.php index 1f5cd78886..9874a222ff 100644 --- a/lib/zin/core/dom.class.php +++ b/lib/zin/core/dom.class.php @@ -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, diff --git a/lib/zin/core/h.class.php b/lib/zin/core/h.class.php index 05b26d2338..9aa93f0470 100644 --- a/lib/zin/core/h.class.php +++ b/lib/zin/core/h.class.php @@ -35,7 +35,7 @@ class h extends node return 'h::' . $this->tagName(); } - public function shortType(): string + public function type(): string { return $this->tagName(); } diff --git a/lib/zin/core/hook.class.php b/lib/zin/core/hook.class.php index acb63db135..422c4fff09 100644 --- a/lib/zin/core/hook.class.php +++ b/lib/zin/core/hook.class.php @@ -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 diff --git a/lib/zin/core/node.class.php b/lib/zin/core/node.class.php index 05890c8947..c7d0bc6adc 100644 --- a/lib/zin/core/node.class.php +++ b/lib/zin/core/node.class.php @@ -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(); diff --git a/lib/zin/core/text.class.php b/lib/zin/core/text.class.php index b03358622b..779e53f114 100644 --- a/lib/zin/core/text.class.php +++ b/lib/zin/core/text.class.php @@ -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'; } diff --git a/lib/zin/core/wg.class.php b/lib/zin/core/wg.class.php index 0106576d27..130fb5274f 100644 --- a/lib/zin/core/wg.class.php +++ b/lib/zin/core/wg.class.php @@ -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){"; diff --git a/lib/zin/core/zin.class.php b/lib/zin/core/zin.class.php index 1329eaa2e1..12a341369c 100644 --- a/lib/zin/core/zin.class.php +++ b/lib/zin/core/zin.class.php @@ -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; diff --git a/lib/zin/core/zin.func.php b/lib/zin/core/zin.func.php index 69231d0e86..4da6f6ee42 100644 --- a/lib/zin/core/zin.func.php +++ b/lib/zin/core/zin.func.php @@ -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; }