From 448a86a606dfe208e619b1cdaee833ff5883746e Mon Sep 17 00:00:00 2001 From: sunhao Date: Wed, 21 Feb 2024 22:54:56 +0800 Subject: [PATCH] * zin: improve zin lib. --- extension/lite/project/ext/ui/edit.html.php | 2 +- framework/base/control.class.php | 20 +- lib/zin/core/context.class.php | 141 +- lib/zin/core/context.func.php | 61 + lib/zin/core/data.func.php | 55 - lib/zin/core/directive.class.php | 39 +- lib/zin/core/dom.class.php | 3 +- lib/zin/core/h.class.php | 272 +-- lib/zin/core/h.func.php | 54 +- lib/zin/core/helper.func.php | 41 + lib/zin/core/item.class.php | 2 +- lib/zin/core/js.class.php | 77 +- lib/zin/core/jscallback.class.php | 2 +- lib/zin/core/node.class.php | 643 ++++++ lib/zin/core/on.class.php | 16 +- lib/zin/core/props.class.php | 13 - lib/zin/core/rawcontent.class.php | 23 - lib/zin/core/render.func.php | 13 +- lib/zin/core/set.class.php | 128 +- lib/zin/core/text.class.php | 52 + lib/zin/core/to.class.php | 2 +- lib/zin/core/wg.class.php | 821 +------- lib/zin/core/wg.func.php | 290 --- lib/zin/core/zin.func.php | 140 ++ lib/zin/func.php | 2031 ++----------------- lib/zin/wg/aclbox/v1.php | 4 +- lib/zin/wg/actionitem/v1.php | 2 +- lib/zin/wg/avatar/v1.php | 2 +- lib/zin/wg/batchactions/v1.php | 4 +- lib/zin/wg/btn/v1.php | 2 +- lib/zin/wg/btngroup/v1.php | 2 +- lib/zin/wg/cell/v1.php | 2 +- lib/zin/wg/center/v1.php | 2 +- lib/zin/wg/checkbox/v1.php | 2 +- lib/zin/wg/checkboxgroup/v1.php | 8 +- lib/zin/wg/checkbtn/v1.php | 2 +- lib/zin/wg/checkbtngroup/v1.php | 4 +- lib/zin/wg/checkcolorgroup/v1.php | 4 +- lib/zin/wg/checklist/v1.php | 2 +- lib/zin/wg/col/v1.php | 2 +- lib/zin/wg/collapsebtn/v1.php | 2 +- lib/zin/wg/colorinput/v1.php | 2 +- lib/zin/wg/colorpicker/v1.php | 2 +- lib/zin/wg/commentdialog/v1.php | 2 +- lib/zin/wg/commentform/v1.php | 2 +- lib/zin/wg/contactlist/v1.php | 4 +- lib/zin/wg/control/v1.php | 2 +- lib/zin/wg/dashboard/v1.php | 2 +- lib/zin/wg/datepicker/v1.php | 2 +- lib/zin/wg/daterangepicker/v1.php | 2 +- lib/zin/wg/datetimepicker/v1.php | 2 +- lib/zin/wg/detailbody/v1.php | 6 +- lib/zin/wg/detailheader/v1.php | 2 +- lib/zin/wg/detailside/v1.php | 4 +- lib/zin/wg/divider/v1.php | 2 +- lib/zin/wg/docmenu/v1.php | 4 +- lib/zin/wg/dropmenu/v1.php | 2 +- lib/zin/wg/dtable/v1.php | 4 +- lib/zin/wg/dynamic/v1.php | 4 +- lib/zin/wg/editor/v1.php | 6 +- lib/zin/wg/entitylabel/v1.php | 4 +- lib/zin/wg/featurebar/v1.php | 2 +- lib/zin/wg/filelist/v1.php | 6 +- lib/zin/wg/fileselector/v1.php | 2 +- lib/zin/wg/filter/v1.php | 2 +- lib/zin/wg/floatprenextbtn/v1.php | 6 +- lib/zin/wg/floattoolbar/v1.php | 2 +- lib/zin/wg/formbase/v1.php | 2 +- lib/zin/wg/formgroup/v1.php | 2 +- lib/zin/wg/formitemdropdown/v1.php | 4 +- lib/zin/wg/formlabel/v1.php | 2 +- lib/zin/wg/formpanel/v1.php | 2 +- lib/zin/wg/formrow/v1.php | 2 +- lib/zin/wg/formrowgroup/v1.php | 4 +- lib/zin/wg/formsettingbtn/v1.php | 6 +- lib/zin/wg/fragment/v1.php | 2 +- lib/zin/wg/gantt/v1.php | 2 +- lib/zin/wg/globalsearch/v1.php | 4 +- lib/zin/wg/header/v1.php | 2 +- lib/zin/wg/heading/v1.php | 2 +- lib/zin/wg/hr/v1.php | 2 +- lib/zin/wg/icon/v1.php | 2 +- lib/zin/wg/imageselector/v1.php | 2 +- lib/zin/wg/input/v1.php | 2 +- lib/zin/wg/inputcontrol/v1.php | 2 +- lib/zin/wg/inputgroup/v1.php | 2 +- lib/zin/wg/inputgroupaddon/v1.php | 2 +- lib/zin/wg/label/v1.php | 4 +- lib/zin/wg/main/v1.php | 2 +- lib/zin/wg/mainnavbar/v1.php | 4 +- lib/zin/wg/menu/v1.php | 2 +- lib/zin/wg/modal/v1.php | 2 +- lib/zin/wg/modaldialog/v1.php | 4 +- lib/zin/wg/modalheader/v1.php | 2 +- lib/zin/wg/modalnextstep/v1.php | 4 +- lib/zin/wg/modulemenu/v1.php | 2 +- lib/zin/wg/modulepicker/v1.php | 4 +- lib/zin/wg/monaco/v1.php | 4 +- lib/zin/wg/nav/v1.php | 2 +- lib/zin/wg/navbar/v1.php | 2 +- lib/zin/wg/navigator/v1.php | 4 +- lib/zin/wg/overviewblock/v1.php | 2 +- lib/zin/wg/pagebase/v1.php | 15 +- lib/zin/wg/panel/v1.php | 2 +- lib/zin/wg/password/v1.php | 2 +- lib/zin/wg/pastedialog/v1.php | 6 +- lib/zin/wg/prilabel/v1.php | 2 +- lib/zin/wg/productmenu/v1.php | 2 +- lib/zin/wg/productsbox/v1.php | 6 +- lib/zin/wg/programmenu/v1.php | 2 +- lib/zin/wg/progressbar/v1.php | 2 +- lib/zin/wg/progresscircle/v1.php | 2 +- lib/zin/wg/resultfilter/v1.php | 2 +- lib/zin/wg/risklabel/v1.php | 4 +- lib/zin/wg/roadmap/v1.php | 2 +- lib/zin/wg/row/v1.php | 2 +- lib/zin/wg/searchform/v1.php | 2 +- lib/zin/wg/searchtoggle/v1.php | 2 +- lib/zin/wg/section/v1.php | 2 +- lib/zin/wg/sectioncard/v1.php | 2 +- lib/zin/wg/sectionlist/v1.php | 2 +- lib/zin/wg/select/v1.php | 2 +- lib/zin/wg/severitylabel/v1.php | 2 +- lib/zin/wg/sidebar/v1.php | 2 +- lib/zin/wg/statisticblock/v1.php | 2 +- lib/zin/wg/stepseditor/v1.php | 6 +- lib/zin/wg/tablechart/v1.php | 2 +- lib/zin/wg/tabledata/v1.php | 4 +- lib/zin/wg/tabpane/v1.php | 2 +- lib/zin/wg/tabs/v1.php | 4 +- lib/zin/wg/textarea/v1.php | 2 +- lib/zin/wg/toolbar/v1.php | 2 +- lib/zin/wg/treeeditor/v1.php | 2 +- lib/zin/wg/twinsstory/v1.php | 6 +- lib/zin/wg/useravatar/v1.php | 2 +- lib/zin/wg/users/v1.php | 2 +- lib/zin/wg/visionswitcher/v1.php | 2 +- lib/zin/zentao/zentao.func.php | 2 +- lib/zin/zui/zui.class.php | 5 +- 139 files changed, 1772 insertions(+), 3501 deletions(-) delete mode 100644 lib/zin/core/data.func.php create mode 100644 lib/zin/core/helper.func.php create mode 100644 lib/zin/core/node.class.php delete mode 100644 lib/zin/core/rawcontent.class.php create mode 100644 lib/zin/core/text.class.php delete mode 100644 lib/zin/core/wg.func.php create mode 100644 lib/zin/core/zin.func.php diff --git a/extension/lite/project/ext/ui/edit.html.php b/extension/lite/project/ext/ui/edit.html.php index c6288c084b..39db498b78 100644 --- a/extension/lite/project/ext/ui/edit.html.php +++ b/extension/lite/project/ext/ui/edit.html.php @@ -155,6 +155,6 @@ formPanel ) ); -useData('title', $title); +setPageData('title', $title); render(); diff --git a/framework/base/control.class.php b/framework/base/control.class.php index 74b0bf33db..7454749d2c 100644 --- a/framework/base/control.class.php +++ b/framework/base/control.class.php @@ -1002,28 +1002,26 @@ class baseControl chdir(dirname($viewFile)); /** - * Set zin context data + * Init zin context data. + * 设置 zin 渲染上下文数据。 */ - \zin\zin::$globalRenderList = array(); - \zin\zin::$enabledGlobalRender = true; - \zin\zin::$rendered = false; - \zin\zin::$rawContentCalled = false; + $context = \zin\context(); + $context->data = (array)$this->view; + $context->data['zinDebug'] = array(); - \zin\zin::$data = (array)$this->view; - \zin\zin::$data['zinDebug'] = array(); if($this->config->debug && $this->config->debug >= 2 && $this->config->installed) { - \zin\zin::$data['zinDebug']['trace'] = $this->app->loadClass('trace')->getTrace(); + $context->data['zinDebug']['trace'] = $this->app->loadClass('trace')->getTrace(); } /** * 使用extract和ob方法渲染$viewFile里面的代码。 * Use extract and ob functions to eval the codes in $viewFile. */ - extract(\zin\zin::$data); + extract($context->data); /* 将 hooks 文件添加到当前 context 中。 */ - if(!empty($hookFiles)) \zin\context::current()->addHookFiles($hookFiles); + if(!empty($hookFiles)) $context->addHookFiles($hookFiles); /* 加载 common.field.php 和 method.field.php。 */ $commonFieldFile = dirname($viewFile) . DS . 'common.field.php'; @@ -1034,7 +1032,7 @@ class baseControl ob_start(); include $viewFile; - if(!\zin\zin::$rendered) \zin\render(); + if(!$context->rendered) \zin\render(); $content = ob_get_clean(); ob_start(); diff --git a/lib/zin/core/context.class.php b/lib/zin/core/context.class.php index c10bc02939..8aa4e80c61 100644 --- a/lib/zin/core/context.class.php +++ b/lib/zin/core/context.class.php @@ -16,13 +16,110 @@ use function zin\utils\flat; require_once dirname(__DIR__) . DS . 'utils' . DS . 'dataset.class.php'; require_once dirname(__DIR__) . DS . 'utils' . DS . 'flat.func.php'; +require_once dirname(__DIR__) . DS . 'utils' . DS . 'deep.func.php'; class context extends \zin\utils\dataset { + public string $name; + + public array $globalRenderList = array(); + + public int $globalRenderLevel = 0; + + public array $data = array(); + + public bool $rendered = false; + + public bool $rawContentCalled = false; + + public function __construct(string $name) + { + parent::__construct(); + $this->name = $name; + } + + public function __debugInfo(): array + { + return array_merge(array + ( + 'name' => $this->name, + 'globalRenderListLen' => count($this->globalRenderList), + 'globalRenderList' => $this->globalRenderList, + 'globalRenderLevel' => $this->globalRenderLevel, + 'rendered' => $this->rendered, + 'rawContentCalled' => $this->rawContentCalled, + ), $this->storedData); + } + + public function getData(string $namePath, mixed $defaultValue = null): mixed + { + return \zin\utils\deepGet($this->data, $namePath, $defaultValue); + } + + public function setData(string $namePath, mixed $value) + { + \zin\utils\deepSet($this->data, $namePath, $value); + } + + public function enableGlobalRender() + { + $this->globalRenderLevel--; + } + + public function disableGlobalRender() + { + $this->globalRenderLevel++; + } + + public function enabledGlobalRender() + { + return $this->globalRenderLevel < 1; + } + + public function renderInGlobal(node|iDirective $item): bool + { + if($this->globalRenderLevel > 0) + { + return false; + } + + if($item instanceof node) + { + if($item->parent || $item->shortType() === 'wg') return false; + + if(!isset($this->globalRenderList[$item->gid])) $this->globalRenderList[$item->gid] = $item; + return true; + } + + if(in_array($item, $this->globalRenderList)) return false; + + $this->globalRenderList[] = $item; + return true; + } + + public function getGlobalRenderList(bool $clear = true): array + { + $globalItems = array(); + + foreach($this->globalRenderList as $item) + { + if(is_object($item) && ((isset($item->parent) && $item->parent) || (isset($item->notRenderInGlobal) && $item->notRenderInGlobal))) + { + continue; + } + $globalItems[] = $item; + } + + /* Clear globalRenderList. */ + if($clear) $this->globalRenderList = array(); + + return $globalItems; + } + public function addHookFiles(string|array ...$files) { $files = flat($files); - return $this->mergeToList('hookFiles', $files); + return $this->mergeToList('hookFiles', array_filter(array_values($files))); } public function getHookFiles(): array @@ -30,12 +127,12 @@ class context extends \zin\utils\dataset return $this->getList('hookFiles'); } - public function addImport(string ...$files) + public function addImports(string ...$files) { return $this->mergeToList('import', $files); } - public function getImportList(): array + public function getImports(): array { return $this->getList('import'); } @@ -57,7 +154,7 @@ class context extends \zin\utils\dataset public function addJSVar(string $name, mixed $value) { - return $this->addToList('jsVar', h::createJsVarCode($name, $value)); + // return $this->addToList('jsVar', h::createJsVarCode($name, $value)); } public function addWgWithEvents($wg) @@ -107,7 +204,7 @@ class context extends \zin\utils\dataset return $js; } - public static $map = array(); + public static array $stack = array(); public static function js(/* string ...$code */) { @@ -121,7 +218,6 @@ class context extends \zin\utils\dataset call_user_func_array(array($context, 'addJSCall'), func_get_args()); } - public static function jsVar($name, $value) { $context = static::current(); @@ -137,7 +233,7 @@ class context extends \zin\utils\dataset public static function import(/* string ...$files */) { $context = static::current(); - call_user_func_array(array($context, 'addImport'), func_get_args()); + call_user_func_array(array($context, 'addImports'), func_get_args()); } /** @@ -148,35 +244,38 @@ class context extends \zin\utils\dataset */ public static function current(): context { - if(empty(static::$map)) static::$map['current'] = new context(); - return static::$map['current']; + if(empty(static::$stack)) + { + $context = new context('default'); + static::$stack['default'] = $context; + return $context; + } + return end(static::$stack); } /** - * Create widget context. + * Create context. * * @access public - * @param string $gid The widget gid. + * @param string $name Context name. * @return context */ - public static function create(string $gid): context + public static function create(string $name): context { - if(isset(static::$map[$gid])) return static::$map[$gid]; - $context = new context(); - static::$map[$gid] = $context; + if(isset(static::$stack[$name])) return static::$stack[$name]; + $context = new context($name); + static::$stack[$name] = $context; return $context; } /** - * Destroy widget context. + * Pop last context. * * @access public - * @param string $gid The widget gid. - * @return void + * @return ?context */ - public static function destroy(string $gid = null): void + public static function pop(): ?context { - if($gid === null) unset(static::$map['current']); - elseif(isset(static::$map[$gid])) unset(static::$map[$gid]); + return array_pop(static::$stack); } } diff --git a/lib/zin/core/context.func.php b/lib/zin/core/context.func.php index cc24fbbdaf..6ed8121022 100644 --- a/lib/zin/core/context.func.php +++ b/lib/zin/core/context.func.php @@ -14,6 +14,32 @@ namespace zin; require_once __DIR__ . DS . 'context.class.php'; +function context(?string $name = null): context +{ + if($name) return context::create($name); + return context::current(); +} + +function popContext() +{ + return context::pop(); +} + +function enableGlobalRender() +{ + context::current()->enableGlobalRender(); +} + +function disableGlobalRender() +{ + context::current()->disableGlobalRender(); +} + +function renderInGlobal(node|iDirective $item): bool +{ + return context::current()->renderInGlobal($item); +} + function pageJS() { call_user_func_array('\zin\context::js', func_get_args()); @@ -38,3 +64,38 @@ function import() { call_user_func_array('\zin\context::import', func_get_args()); } + +function setPageData($name, $value) +{ + $context = context::current(); + if(is_array($value) && empty($name)) + { + foreach ($value as $key => $val) $context->setData($key, $val); + return; + } + $context->setData($name, $value); +} + +function getPageData($name) +{ + $context = context::current(); + if(is_array($name)) + { + $values = array(); + foreach($name as $propName) + { + $values[] = $context->getData($propName); + } + return $values; + } + + return $context->getData($name); +} + +function data() +{ + $args = func_get_args(); + + if(count($args) >= 2) return setPageData($args[0], $args[1]); + return getPageData($args[0]); +} diff --git a/lib/zin/core/data.func.php b/lib/zin/core/data.func.php deleted file mode 100644 index fb8cf0d02a..0000000000 --- a/lib/zin/core/data.func.php +++ /dev/null @@ -1,55 +0,0 @@ - - * @package zin - * @version $Id - * @link https://www.zentao.net - */ - -namespace zin; - -function setPageData($name, $value) -{ - if(is_array($value) && empty($name)) - { - foreach ($value as $key => $val) zin::setData($key, $val); - return; - } - zin::setData($name, $value); -} - -function getPageData($name) -{ - if(is_array($name)) - { - $values = array(); - foreach($name as $propName) - { - $values[] = zin::getData($propName); - } - return $values; - } - - return zin::getData($name); -} - -function data() -{ - $args = func_get_args(); - - if(count($args) >= 2) return setPageData($args[0], $args[1]); - return getPageData($args[0]); -} - -/** - * Set page data - * @deprecated Use data($name, $value) insteadOf useData($name, $value) - */ -function useData($name, $value) -{ - return setPageData($name, $value); -} diff --git a/lib/zin/core/directive.class.php b/lib/zin/core/directive.class.php index e8ce7e96bb..de539a63cf 100644 --- a/lib/zin/core/directive.class.php +++ b/lib/zin/core/directive.class.php @@ -13,8 +13,16 @@ declare(strict_types=1); namespace zin; require_once __DIR__ . DS . 'zin.class.php'; +require_once __DIR__ . DS . 'context.func.php'; -class directive +use zin\node; + +interface iDirective +{ + public function apply(node $node, string $blockName): void; +} + +class directive implements iDirective { public string $type; @@ -37,7 +45,10 @@ class directive $this->data = $data; $this->options = $options; - zin::renderInGlobal($this); + if(!$options || !isset($options['notRenderInGlobal']) || !$options['notRenderInGlobal']) + { + renderInGlobal($this); + } } public function __debugInfo(): array @@ -49,50 +60,52 @@ class directive ); } - public function applyToWg(wg &$wg, string $blockName): void + public function apply(node $node, string $blockName): void { - $this->parent = $wg; + $this->parent = $node; $data = $this->data; $type = $this->type; if($type === 'prop') { - $wg->setProp($data); + $node->setProp($data); return; } if($type === 'class' || $type === 'style') { - $wg->setProp($type, $data); + $node->setProp($type, $data); return; } if($type === 'cssVar') { - $wg->setProp('--', $data); + $node->setProp('--', $data); return; } if($type === 'html') { - $wg->addToBlock($blockName, $this); + $html = new stdClass(); + $html->html = implode("\n", $data); + $node->addToBlock($blockName, $html); return; } if($type === 'text') { - $wg->addToBlock($blockName, htmlspecialchars($data, ENT_QUOTES | ENT_SUBSTITUTE | ENT_HTML401, null, false)); + $node->addToBlock($blockName, $data); return; } if($type === 'block') { foreach($data as $blockName => $blockChildren) { - $wg->add($blockChildren, $blockName); + $node->add($blockChildren, $blockName); } } } - public static function is(mixed $item, ?string $type = null): bool + public static function is(mixed $item): bool { - return $item instanceof directive && ($type === null || $item->type === $type); + return ($item instanceof directive) || $item instanceof iDirective || (is_object($item) && method_exists($item, 'apply')); } } @@ -103,5 +116,5 @@ function directive($type, $data, $options = null): directive function isDirective(mixed $item, ?string $type = null): bool { - return directive::is($item, $type); + return directive::is($item); } diff --git a/lib/zin/core/dom.class.php b/lib/zin/core/dom.class.php index 08b7639b02..1f5cd78886 100644 --- a/lib/zin/core/dom.class.php +++ b/lib/zin/core/dom.class.php @@ -130,8 +130,7 @@ class dom * @access public * @return array */ - public function build() - { + public function build(): mixed { if($this->wg->removed) return array(); if($this->buildList !== null && $this->buildListInner === $this->renderInner) return $this->buildList; diff --git a/lib/zin/core/h.class.php b/lib/zin/core/h.class.php index d49d4ffce1..05b26d2338 100644 --- a/lib/zin/core/h.class.php +++ b/lib/zin/core/h.class.php @@ -12,153 +12,141 @@ declare(strict_types=1); namespace zin; -require_once dirname(__DIR__) . DS . 'utils' . DS . 'flat.func.php'; -require_once dirname(__DIR__) . DS . 'utils' . DS . 'json.func.php'; -require_once __DIR__ . DS . 'wg.class.php'; -require_once __DIR__ . DS . 'wg.func.php'; +require_once __DIR__ . DS . 'node.class.php'; +require_once __DIR__ . DS . 'text.class.php'; +require_once __DIR__ . DS . 'directive.class.php'; -class h extends wg +class h extends node { - protected static array $defineProps = array( - 'tagName: string', - 'selfClose?: bool' + public static array $defineProps = array + ( + 'tagName' => 'string', + 'selfClose' => '?bool' ); + public function tagName(): string + { + $tagName = $this->prop('tagName'); + return $tagName === null ? '' : $tagName; + } + + public function type(): string + { + return 'h::' . $this->tagName(); + } + + public function shortType(): string + { + return $this->tagName(); + } + + public function isSelfClose(): bool + { + $selfClose = $this->prop('selfClose'); + if($selfClose !== null) return boolval($selfClose); + + return in_array($this->tagName(), static::$selfCloseTags); + } + protected function onSetProp(array|string $prop, mixed $value) { if($prop === 'className') $prop = 'class'; return parent::onSetProp($prop, $value); } - public function getTagName(): string + public function build(): mixed { - return $this->props->get('tagName'); - } - - public function isDomElement(): bool - { - return true; - } - - public function isSelfClose() - { - $selfClose = $this->props->get('selfClose'); - if($selfClose !== null) return $selfClose; - - return in_array($this->getTagName(), static::$selfCloseTags); - } - - public function build(): array - { - if($this->isSelfClose()) return array($this->buildSelfCloseTag()); + if($this->isSelfClose()) return $this->buildSelfCloseTag(); return array($this->buildTagBegin(), parent::build(), $this->buildTagEnd()); } - public function toJSON(): array - { - $data = parent::toJSON(); - $data['type'] = 'h:' . $this->getTagName(); - return $data; - } - - public function type(): string - { - return $this->getTagName(); - } - - public function shortType(): string - { - return $this->getTagName(); - } - protected function getPropsStr(): string { $propStr = $this->props->toStr(array_keys(static::definedPropsList())); - if($this->props->hasEvent() && empty($this->id()) && $this->getTagName() !== 'html') $propStr = "$propStr id='$this->gid'"; + if($this->props->hasEvent() && empty($this->id()) && $this->tagName() !== 'html') $propStr = "$propStr id='$this->gid'"; return empty($propStr) ? '' : " $propStr"; } protected function buildSelfCloseTag(): string { - $tagName = $this->getTagName(); + $tagName = $this->tagName(); $propStr = $this->getPropsStr(); return "<$tagName$propStr />"; } protected function buildTagBegin(): string { - $tagName = $this->getTagName(); + $tagName = $this->tagName(); $propStr = $this->getPropsStr(); return "<$tagName$propStr>"; } protected function buildTagEnd(): string { - $tagName = $this->getTagName(); + $tagName = $this->tagName(); return ""; } - public static function create(): h + public static function create(string $tagName, mixed ...$args): h { - $args = func_get_args(); - $tagName = array_shift($args); - return new h(is_string($tagName) ? set('tagName', $tagName) : $tagName, $args); + $h = new h(...$args); + $h->setProp('tagName', $tagName); + return $h; } public static function __callStatic(string $tagName, array $args): h { - return new h(set('tagName', $tagName), $args); + return static::create($tagName, ...$args); } public static function a(): h { $a = static::create('a', func_get_args()); - if($a->prop('target') === '_blank' && !$a->hasProp('rel')) $a->prop('rel', 'noopener noreferrer'); + if($a->prop('target') === '_blank' && !$a->hasProp('rel')) + { + $a->setProp('rel', 'noopener noreferrer'); + } return $a; } - public static function button() + public static function button(mixed ...$args): h { - return static::create('button', set('type', 'button'), func_get_args()); + $button = static::create('button', ...$args); + $button->setDefaultProps('type', 'button'); + return $button; } - public static function input() + public static function input(mixed ...$args): h { - return static::create('input', set('type', 'text'), func_get_args()); + $input = static::create('input', ...$args); + $input->setDefaultProps('type', 'text'); + return $input; } - public static function formHidden(/* $name, $value, ...$args */) + public static function formHidden(string $name, string $value, mixed ...$args): h { - $args = func_get_args(); - $name = array_shift($args); - $value = array_shift($args); - return static::create('input', set('type', 'hidden'), set::name($name), set::value($value), $args); + $input = static::create('input', ...$args); + $input->setDefaultProps(array('type' => 'hidden', 'name' => $name, 'value' => $value)); + return $input; } - public static function checkbox() + public static function checkbox(mixed ...$args): h { - return static::create('input', set('type', 'checkbox'), func_get_args()); + $input = static::create('input', ...$args); + $input->setDefaultProps('type', 'checkbox'); + return $input; } - public static function radio() + public static function radio(mixed ...$args): h { - return static::create('input', set('type', 'radio'), func_get_args()); + $input = static::create('input', ...$args); + $input->setDefaultProps('type', 'radio'); + return $input; } - public static function date() + public static function textarea(mixed ...$args) { - return static::create('input', set('type', 'date'), func_get_args()); - } - - public static function file() - { - return static::create('input', set('type', 'file'), func_get_args()); - } - - public static function textarea(/* ...$args */) - { - $args = func_get_args(); list($code, $args) = h::splitRawCode($args); return static::create('textarea', $code, $args); } @@ -168,33 +156,29 @@ class h extends wg * * @access public * @param string $comment - * @return directive + * @return node */ - public static function comment(string $comment): directive + public static function comment(string $comment): text { return html(""); } - public static function importJs(/* $src, ...$args */) + public static function importJs(string $src, mixed ...$args): h { - $args = func_get_args(); - $src = array_shift($args); - return static::create('script', set('src', $src), $args); + $script = static::create('script', ...$args); + $script->setDefaultProps('src', 'src'); + return $script; } - public static function importCss(/* $src, ...$args */) + public static function importCss(string $href, mixed ...$args): h { - $args = func_get_args(); - $src = array_shift($args); - return static::create('link', set('rel', 'stylesheet'), set('href', $src), $args); + $link = static::create('link', ...$args); + $link->setDefaultProps(array('rel' => 'stylesheet', 'href' => $href)); + return $link; } - public static function import(/* $file, $type = null, ...$args */) + public static function import(string|array $file, ?string $type = null, mixed ...$args): ?h { - $args = array_merge(func_get_args(), array(null, null)); - $file = array_shift($args); - $type = array_shift($args); - if(is_array($file)) { $children = array(); @@ -210,37 +194,35 @@ class h extends wg return null; } - public static function css(/* ...$args */) + public static function css(mixed ...$args): ?h { - list($code, $args) = h::splitRawCode(func_get_args()); + list($code, $args) = h::splitRawCode($args); if(empty($code)) return null; - return static::create('style', html(implode("\n", $code)), $args); + return static::create('style', html(...$code), $args); } - public static function globalJS(/* ...$args */) + public static function globalJS(mixed ...$args): ?h { - list($code, $args) = h::splitRawCode(func_get_args()); + list($code, $args) = h::splitRawCode($args); if(empty($code)) return null; - return static::create('script', html(implode("\n", $code)), $args); + return static::create('script', html(...$code), $args); } - public static function js(/* ...$args */) + public static function js(mixed ...$args): ?h { - - list($code, $args) = h::splitRawCode(func_get_args()); + list($code, $args) = h::splitRawCode($args); if(empty($code)) return null; - return static::create('script', html(h::createJsScopeCode($code)), $args); + $code = ';(function(){' . implode("\n", $code) . '}());'; + return static::create('script', html($code, $args)); } - public static function jsVar(/* $name, $value, ...$args */) + public static function jsVar(string $name, mixed $value, mixed ...$args): ?h { - $args = func_get_args(); - $name = array_shift($args); - $value = array_shift($args); - return static::js(static::createJsVarCode($name, $value), $args); + + return static::js(js()->var($name, $value), $args); } - public static function jsCall(/* $funcName, ...$args */) + public static function jsCall(string $funcName, mixed ...$args): h { $args = func_get_args(); $funcName = array_shift($args); @@ -250,69 +232,11 @@ class h extends wg foreach($args as $arg) { if(isDirective($arg)) $directives[] = $arg; - else $funcArgs[] = $arg; - } - $code = static::createJsCallCode($funcName, $funcArgs); - return static::js($code, $directives); - } - - public static function createJsCallCode($func, $args) - { - foreach($args as $index => $arg) - { - $args[$index] = h::encodeJsonWithRawJs($arg, JSON_UNESCAPED_UNICODE); + else $funcArgs[] = $arg; } - if($func[0] === '~') - { - $func = substr($func, 1); - return "$(() => $func(" . implode(',', $args) . "));"; - } - return $func . '(' . implode(',', $args) . ');'; - } - - public static function createJsVarCode($name, $value) - { - $vars = is_string($name) ? array($name => $value) : $name; - $jsCode = ''; - foreach($vars as $var => $val) - { - if(empty($var)) continue; - - $val = h::encodeJsonWithRawJs($val); - - if(str_starts_with($var, 'window.')) $jsCode .= "$var=" . $val . ';'; - elseif(str_starts_with($var, '+')) $jsCode .= 'let ' . substr($var, 1) . '=' . $val . ';'; - else $jsCode .= "const $var=" . $val . ';'; - } - return $jsCode; - } - - public static function createJsScopeCode(string|array $codes): string - { - if(is_array($codes)) $codes = implode("\n", $codes); - return ";(function(){\n$codes\n}());"; - } - - public static function jsRaw(): string - { - $js = implode('RAWJS_LINE', func_get_args()); - $js = str_replace(array("\n", '"'), array('RAWJS_LINE', 'RAWJS_QUOTE'), $js); - return "RAWJS<$js>RAWJS"; - } - - public static function decodeJSRaw(string $str): string - { - if(!str_contains($str, 'RAWJS')) return $str; - return str_replace(array('RAWJS_LINE', 'RAWJS_QUOTE', '"RAWJS<', '>RAWJS"'), array("\n", '"', '', ''), $str); - } - - public static function encodeJsonWithRawJs($data) - { - $json = \zin\utils\jsonEncode($data, JSON_UNESCAPED_UNICODE); - if(empty($json) && (is_array($data) || is_object($data))) return '[]'; - - return static::decodeJSRaw($json); + $js = js()->call($funcName, ...$funcArgs); + return static::js($js->toJS(), $directives); } protected static function splitRawCode($children) @@ -323,9 +247,9 @@ class h extends wg foreach($children as $child) { if(is_string($child)) $code[] = $child; - else $args[] = $child; + else $args[] = $child; } - return [$code, $args]; + return array($code, $args); } public static $selfCloseTags = array('area', 'base', 'br', 'col', 'command', 'embed', 'hr', 'img', 'input', 'keygen', 'link', 'meta', 'param', 'source', 'track', 'wbr'); diff --git a/lib/zin/core/h.func.php b/lib/zin/core/h.func.php index ef751faf45..303803ee10 100644 --- a/lib/zin/core/h.func.php +++ b/lib/zin/core/h.func.php @@ -13,35 +13,27 @@ declare(strict_types=1); namespace zin; require_once __DIR__ . DS . 'h.class.php'; -require_once __DIR__ . DS . 'item.class.php'; -require_once __DIR__ . DS . 'wg.func.php'; -require_once __DIR__ . DS . 'set.class.php'; -require_once __DIR__ . DS . 'to.class.php'; -require_once __DIR__ . DS . 'data.func.php'; -require_once __DIR__ . DS . 'on.class.php'; -function h(): h {return call_user_func_array('\zin\h::create', func_get_args());} - -function div(): h {return call_user_func_array('\zin\h::div', func_get_args());} -function span(): h {return call_user_func_array('\zin\h::span', func_get_args());} -function code(): h {return call_user_func_array('\zin\h::code', func_get_args());} -function canvas(): h {return call_user_func_array('\zin\h::canvas', func_get_args());} -function br(): h {return call_user_func_array('\zin\h::br', func_get_args());} -function a(): h {return call_user_func_array('\zin\h::a', func_get_args());} -function p(): h {return call_user_func_array('\zin\h::p', func_get_args());} -function img(): h {return call_user_func_array('\zin\h::img', func_get_args());} -function button(): h {return call_user_func_array('\zin\h::button', func_get_args());} -function h1(): h {return call_user_func_array('\zin\h::h1', func_get_args());} -function h2(): h {return call_user_func_array('\zin\h::h2', func_get_args());} -function h3(): h {return call_user_func_array('\zin\h::h3', func_get_args());} -function h4(): h {return call_user_func_array('\zin\h::h4', func_get_args());} -function h5(): h {return call_user_func_array('\zin\h::h5', func_get_args());} -function h6(): h {return call_user_func_array('\zin\h::h6', func_get_args());} -function ul(): h {return call_user_func_array('\zin\h::ul', func_get_args());} -function li(): h {return call_user_func_array('\zin\h::li', func_get_args());} -function template(): h {return call_user_func_array('\zin\h::template', func_get_args());} -function formHidden(): h {return call_user_func_array('\zin\h::formHidden', func_get_args());} -function fieldset(): h {return call_user_func_array('\zin\h::fieldset', func_get_args());} -function legend(): h {return call_user_func_array('\zin\h::legend', func_get_args());} - -function jsRaw(): string {return call_user_func_array('\zin\h::jsRaw', func_get_args());} +function h(mixed ...$args): h {return h::create(...$args);} +function div(mixed ...$args): h {return h::div(...$args);} +function span(mixed ...$args): h {return h::span(...$args);} +function code(mixed ...$args): h {return h::code(...$args);} +function canvas(mixed ...$args): h {return h::canvas(...$args);} +function br(mixed ...$args): h {return h::br(...$args);} +function a(mixed ...$args): h {return h::a(...$args);} +function p(mixed ...$args): h {return h::p(...$args);} +function img(mixed ...$args): h {return h::img(...$args);} +function button(mixed ...$args): h {return h::button(...$args);} +function h1(mixed ...$args): h {return h::h1(...$args);} +function h2(mixed ...$args): h {return h::h2(...$args);} +function h3(mixed ...$args): h {return h::h3(...$args);} +function h4(mixed ...$args): h {return h::h4(...$args);} +function h5(mixed ...$args): h {return h::h5(...$args);} +function h6(mixed ...$args): h {return h::h6(...$args);} +function ul(mixed ...$args): h {return h::ul(...$args);} +function li(mixed ...$args): h {return h::li(...$args);} +function template(mixed ...$args): h {return h::template(...$args);} +function formHidden(mixed ...$args): h {return h::formHidden(...$args);} +function fieldset(mixed ...$args): h {return h::fieldset(...$args);} +function legend(mixed ...$args): h {return h::legend(...$args);} +function rawContent(): text {return h::comment('{{RAW_CONTENT}}');} diff --git a/lib/zin/core/helper.func.php b/lib/zin/core/helper.func.php new file mode 100644 index 0000000000..6b88965338 --- /dev/null +++ b/lib/zin/core/helper.func.php @@ -0,0 +1,41 @@ + + * @package zin + * @version $Id + * @link https://www.zentao.net + */ + +namespace zin; + +/** + * Check if the debug mode is on. + * + * @param int $level - The min debug level. + * @return bool + */ +function isDebug(int $level = 1): bool +{ + global $config; + $debug = isset($config->debug) ? $config->debug : 0; + if(is_bool($debug)) $debug = $debug ? 1 : 0; + + return $debug >= $level; +} + +/** + * Trigger an error. + * + * @param string $message - The error message. + * @param int $level - The error level. + * @param string $scope - The error scope. + * @return void + */ +function triggerError(string $message, int $level = E_USER_ERROR, string $scope = 'ZIN') +{ + trigger_error("[$scope] $message", $level); +} diff --git a/lib/zin/core/item.class.php b/lib/zin/core/item.class.php index 4689019c5a..ffe0fc68ae 100644 --- a/lib/zin/core/item.class.php +++ b/lib/zin/core/item.class.php @@ -13,7 +13,7 @@ declare(strict_types=1); namespace zin; require_once __DIR__ . DS . 'wg.class.php'; -require_once __DIR__ . DS . 'wg.func.php'; +require_once __DIR__ . DS . 'zin.func.php'; class item extends wg { diff --git a/lib/zin/core/js.class.php b/lib/zin/core/js.class.php index cc876f004f..edbbcaf1ed 100644 --- a/lib/zin/core/js.class.php +++ b/lib/zin/core/js.class.php @@ -12,11 +12,14 @@ declare(strict_types=1); namespace zin; -require_once __DIR__ . DS . 'wg.func.php'; +require_once __DIR__ . DS . 'node.class.php'; +require_once __DIR__ . DS . 'directive.class.php'; +require_once __DIR__ . DS . 'zin.func.php'; use zin\jsContext; use zin\jsCallback; use zin\jQuery; +use zin\node; /** * Class for generating js code. @@ -24,8 +27,10 @@ use zin\jQuery; * * @access public */ -class js extends directive implements \JsonSerializable +class js implements \JsonSerializable, iDirective { + public bool $notRenderInGlobal = true; + /** * The js code lines. * JS 代码行。 @@ -43,7 +48,6 @@ class js extends directive implements \JsonSerializable */ public function __construct(null|string|js|array ...$codes) { - parent::__construct('js'); $this->appendLines(...$codes); } @@ -104,9 +108,10 @@ class js extends directive implements \JsonSerializable $argCodes = array(); foreach($args as $arg) { - $argCodes[] = ($arg instanceof js) ? $arg->toJS() : static::json($arg); + $argCodes[] = ($arg instanceof js) ? $arg->toJS() : static::value($arg); } - return $this->appendLine($func, '(', implode(',', $argCodes), ')'); + + return $this->appendLine($func . '(' . implode(',', $argCodes) . ')'); } /** @@ -133,7 +138,7 @@ class js extends directive implements \JsonSerializable */ public function let(string $name, mixed $value): self { - return $this->appendLine('let', $name, '=', static::json($value)); + return $this->appendLine('let', $name, '=', static::value($value)); } /** @@ -147,7 +152,7 @@ class js extends directive implements \JsonSerializable */ public function const(string $name, mixed $value): self { - return $this->appendLine('const', $name, '=', static::json($value)); + return $this->appendLine('const', $name, '=', static::value($value)); } /** @@ -162,7 +167,21 @@ class js extends directive implements \JsonSerializable public function globalVar(string $name, mixed $value): self { if(!str_starts_with($name, 'window.')) $name = 'window.' . $name; - return $this->appendLine($name, '=', static::json($value)); + return $this->appendLine($name, '=', static::value($value)); + } + + public function var(string|array $nameOrVars, mixed $value = null): self + { + if(is_array($nameOrVars)) + { + foreach($nameOrVars as $name => $val) $this->var($name, $val); + return $this; + } + + $name = $nameOrVars; + if(str_starts_with($name, '+')) return $this->let(substr($name, 1), $value); + if(str_starts_with($name, 'window.')) return $this->globalVar($name, $value); + return $this->const($name, $value); } /** @@ -295,7 +314,6 @@ class js extends directive implements \JsonSerializable } if($line instanceof js) { - $line->parent = $this; $line = $line->toJS(); } $this->appendLine($line); @@ -348,16 +366,16 @@ class js extends directive implements \JsonSerializable } /** - * Apply JS code to zin widget. + * Apply JS code to zin node. * 将 JS 代码应用到指定的 zin 部件中。 * * @access public - * @param wg $wg zin widget object. - * @param string $blockName zin widget block name. + * @param node $node zin node object. + * @param string $blockName zin node block name. */ - public function applyToWg(wg &$wg, string $blockName): void + public function apply(node $node, string $blockName): void { - $wg->addToBlock($blockName, h::js($this->toJS())); + $node->addToBlock($blockName, h::js($this->toJS())); } /** @@ -371,7 +389,20 @@ class js extends directive implements \JsonSerializable { $js = trim($this->toJS()); if(str_ends_with(';', $js)) $js = substr($js, 0, -1); - return h::jsRaw($js); + return js::raw($js); + } + + public static function raw(string ...$codes) + { + $js = implode('', $codes); + $js = str_replace(array("\n", '"'), array('', ''), $js); + return "RAWJS<$js>RAWJS"; + } + + public static function decodeRaw(string $str): string + { + if(!str_contains($str, 'RAWJS')) return $str; + return str_replace(array('', '', '"RAWJS<', '>RAWJS"'), array("\n", '"', '', ''), $str); } /** @@ -389,16 +420,19 @@ class js extends directive implements \JsonSerializable } /** - * Encode php value to JSON. - * 将 PHP 值编码为 JSON。 + * Encode php value to JS code. + * 将 PHP 值编码为 JS 代码。 * * @access public * @param mixed $data PHP value. * @return string */ - public static function json($data): string + public static function value(mixed $data): string { - return h::encodeJsonWithRawJs($data); + $js = \zin\utils\jsonEncode($data, JSON_UNESCAPED_UNICODE); + if(empty($js) && (is_array($data) || is_object($data))) return '[]'; + + return static::decodeRaw($js); } /** @@ -488,3 +522,8 @@ function js(null|string|js|array ...$codes): js { return new js(...$codes); } + +function jsRaw(string ...$codes): string +{ + return js::raw(...$codes); +} diff --git a/lib/zin/core/jscallback.class.php b/lib/zin/core/jscallback.class.php index 97cd23e745..f974f9378f 100644 --- a/lib/zin/core/jscallback.class.php +++ b/lib/zin/core/jscallback.class.php @@ -12,7 +12,7 @@ declare(strict_types=1); namespace zin; -require_once __DIR__ . DS . 'wg.func.php'; +require_once __DIR__ . DS . 'zin.func.php'; require_once __DIR__ . DS . 'jshelper.class.php'; /** diff --git a/lib/zin/core/node.class.php b/lib/zin/core/node.class.php new file mode 100644 index 0000000000..05890c8947 --- /dev/null +++ b/lib/zin/core/node.class.php @@ -0,0 +1,643 @@ + + * @package zin + * @version $Id + * @link https://www.zentao.net + */ + +namespace zin; + +require_once __DIR__ . DS . 'helper.func.php'; +require_once __DIR__ . DS . 'props.class.php'; + +/** + * The base node class. + */ +class node implements \JsonSerializable +{ + /** + * Define properties + * + * @access public + * @var array + */ + protected static array $defineProps = array(); + + /** + * Default properties + * + * @access public + * @var array + */ + protected static array $defaultProps = array(); + + protected static array $defineBlocks = array(); + + public string $gid; + + public ?node $parent = null; + + public props $props; + + public array $blocks = array(); + + public bool $removed = false; + + public ?array $buildList = null; + + public function __construct(mixed ...$args) + { + $this->gid = 'zin_' . uniqid(); + $this->props = new props(); + + disableGlobalRender(); + + $this->setDefaultProps(static::getDefaultProps()); + $this->add($args); + $this->created(); + + enableGlobalRender(); + renderInGlobal($this); + } + + public function __debugInfo(): array + { + return (array)$this->toJSON(); + } + + public function __toString(): string + { + return $this->render(); + } + + public function type(): string + { + return get_called_class(); + } + + public function shortType(): string + { + $type = $this->type(); + if(str_contains($type, '\\')) + { + $type = substr($type, strrpos($type, '\\') + 1); + } + return $type; + } + + public function id(): ?string + { + return $this->props->get('id'); + } + + public function displayID(): string + { + $displayID = $this->type() . '~' . $this->gid; + + $id = $this->id(); + if(!empty($id)) $displayID .= "#$id"; + + return $displayID; + } + + public function prop(array|string $name, mixed $defaultValue = null): mixed + { + if(is_array($name)) + { + $values = array(); + foreach($name as $index => $propName) + { + $values[] = $this->onGetProp($propName, is_array($defaultValue) ? (isset($defaultValue[$propName]) ? $defaultValue[$propName] : $defaultValue[$index]) : $defaultValue); + } + return $values; + } + + return $this->onGetProp($name, $defaultValue); + } + + /** + * Set property, an array can be passed to set multiple properties + * + * @access public + * @param props|array|string $prop - Property name or properties list + * @param mixed $value - Property value + */ + public function setProp(props|array|string $prop, mixed $value = null) + { + if($prop instanceof props) $prop = $prop->toJSON(); + + if(is_array($prop)) + { + foreach($prop as $name => $value) $this->setProp($name, $value); + return $this; + } + + if(!is_string($prop) || empty($prop)) return $this; + + if($prop[0] === '#') + { + $this->add($value, substr($prop, 1)); + return $this; + } + + $this->onSetProp($prop, $value); + return $this; + } + + public function hasProp(): bool + { + $names = func_get_args(); + if(empty($names)) return false; + foreach($names as $name) + { + if(!$this->props->has($name)) return false; + } + return true; + } + + public function setDefaultProps(string|array $props, mixed $value = null) + { + if(is_string($props)) $props = array($props => $value); + if(!is_array($props) || empty($props)) return; + + foreach($props as $name => $value) + { + if($this->props->isset($name)) continue; + $this->setProp($name, $value); + } + } + + public function getRestProps(): array + { + return $this->props->skip(array_keys(static::definedPropsList())); + } + + public function getDefinedProps(): array + { + return $this->props->pick(array_keys(static::definedPropsList())); + } + + public function add($item, string $blockName = 'children') + { + if($item === null || is_bool($item)) return; + + if(is_array($item)) + { + foreach($item as $child) $this->add($child, $blockName); + return; + } + + if(isDirective($item)) $this->directive($item, $blockName); + else $this->addToBlock($blockName, $item); + } + + public function addToBlock(string $name, mixed $child) + { + if($child === null || is_bool($child)) return; + + if(is_array($child)) + { + foreach($child as $blockChild) + { + $this->addToBlock($name, $blockChild); + } + return; + } + + if($child instanceof node) $child->parent = $this; + + if($name === 'children' && $child instanceof node) + { + $blockName = static::getNameFromBlockMap($child->type()); + if($blockName !== null) $name = $blockName; + } + + $result = $name === 'children' ? $this->onAddChild($child) : $this->onAddBlock($child, $name); + if($result === false) return; + if($result !== null && $result !== true) $child = $result; + + if(isset($this->blocks[$name])) $this->blocks[$name][] = $child; + else $this->blocks[$name] = array($child); + } + + public function directive(iDirective $directive, string $blockName = 'children') + { + $directive->parent = $this; + $directive->apply($this, $blockName); + } + + public function addChild(mixed $child) + { + return $this->addToBlock('children', $child); + } + + public function render(): string + { + if($this->removed) return ''; + + return renderToHtml(...$this->prebuild()); + } + + public function prebuild(): array + { + if($this->removed) return array(); + + if($this->buildList === null) + { + $list = $this->build(); + $list = is_array($list) ? $list : array($list); + $list = array_merge($this->buildBefore(), $list, $this->buildAfter()); + + $this->buildList = $list; + } + + return $this->buildList; + } + + public function children(): array + { + return $this->block('children'); + } + + public function block(string $name): array + { + $list = array(); + if(isset($this->blocks[$name])) + { + $items = $this->blocks[$name]; + foreach($items as $item) + { + if(is_array($item)) $list = array_merge($list, $item); + else $list[] = $item; + } + } + return $list; + } + + public function hasBlock(string $name): bool + { + return isset($this->blocks[$name]); + } + + /** + * Convert to JSON object. + * + * @access public + * @return object + */ + public function toJSON(): object + { + $json = new stdClass(); + $json->gid = $this->gid; + $json->type = $this->shortType(); + $json->props = $this->props->toJSON(); + + $json->blocks = array(); + foreach($this->blocks as $key => $block) + { + if($key === 'children') + { + $json->$key = $block; + unset($json->blocks[$key]); + } + else + { + $json->blocks[$key] = $block; + } + } + + if(!$json->blocks) unset($json->blocks); + + $id = $this->id(); + if($id !== null) $json->id = $id; + + $parent = $this->parent; + if($parent !== null) $json->parent = $parent->displayID(); + + if($this->removed) $json->removed = true; + + return $json; + } + + /** + * Serialized to JSON string. + * + * @access public + * @return string + */ + public function jsonSerialize(): string + { + return json_encode($this->toJSON()); + } + + /** + * Trigger error in debug mode. + * + * @access public + * @param string $message + * @param int $level + * @return void + */ + public function triggerError(string $message, int $level = E_USER_ERROR) + { + triggerError("{$this->displayID()}: $message", $level); + } + + protected function build() + { + return $this->children(); + } + + protected function buildBefore(): array + { + return $this->block('before'); + } + + protected function buildAfter(): array + { + return $this->block('after'); + } + + protected function created() + { + } + + protected function onAddChild(mixed $child) + { + return $child; + } + + protected function onAddBlock(mixed $child, string $name) + { + return $child; + } + + protected function onSetProp(array|string $prop, mixed $value) + { + if($prop === 'id' && $value === '$GID') $value = $this->gid; + $this->props->set($prop, $value); + } + + protected function onGetProp(string $prop, mixed $defaultValue): mixed + { + return $this->props->get($prop, $defaultValue); + } + + /** + * Check errors in debug mode. + * + * @access protected + * @return void + */ + protected function checkErrors() + { + if(!isDebug()) return; + + $definedProps = static::definedPropsList(); + foreach($definedProps as $name => $definition) + { + if($this->hasProp($name)) continue; + if(isset($definition['default']) && $definition['default'] !== null) continue; + if(isset($definition['optional']) && $definition['optional']) continue; + + $this->triggerError("The value of property \"$name: {$definition['type']}\" is required."); + } + + $wgErrors = $this->onCheckErrors(); + if(empty($wgErrors)) return; + + foreach($wgErrors as $error) + { + if(is_array($error)) $this->triggerError(...$error); + else $this->triggerError($error); + } + } + + /** + * The lifecycle method for checking errors in debug mode. + * + * @access protected + * @return array|null + */ + protected function onCheckErrors(): ?array + { + return null; + } + + protected static array $definedPropsMap = array(); + + protected static array $blockMap = array(); + + public static function getBlockMap(): array + { + $type = get_called_class(); + if(!isset(node::$blockMap[$type])) + { + $blockMap = array(); + if(is_array(static::$defineBlocks)) + { + foreach(static::$defineBlocks as $blockName => $setting) + { + if(!isset($setting['map'])) continue; + $map = $setting['map']; + if(is_string($map)) $map = explode(',', $map); + foreach($map as $name) $blockMap[$name] = $blockName; + } + } + node::$blockMap[$type] = $blockMap; + } + return node::$blockMap[$type]; + } + + public static function getNameFromBlockMap(string $type): ?string + { + $blockMap = static::getBlockMap(); + if(str_starts_with($type, 'zin\\')) $type = substr($type, 4); + return isset($blockMap[$type]) ? $blockMap[$type] : null; + } + + public static function definedPropsList(?string $type = null): array + { + if($type === null) $type = get_called_class(); + + if(!isset(node::$definedPropsMap[$type]) && $type === get_called_class()) + { + node::$definedPropsMap[$type] = static::parsePropsDefinition(static::$defineProps); + } + return node::$definedPropsMap[$type]; + } + + public static function getDefaultProps(?string $type = null): array + { + $defaultProps = array(); + foreach(static::definedPropsList($type) as $name => $definition) + { + if(!isset($definition['default'])) continue; + $defaultProps[$name] = $definition['default']; + } + return $defaultProps; + } + + /** + * Parse props definition + * @param $definition + * @example + * + * $definition = array('name', 'desc:string', 'title?:string|array', 'icon?:string="star"'); + * $definition = array('name' => 'mixed', 'desc' => '?string', 'title' => array('type' => 'string|array', 'optional' => true), 'icon' => array('type' => 'string', 'default' => 'star', 'optional' => true)))) + */ + protected static function parsePropsDefinition(array $definition): array + { + $parentClass = get_parent_class(get_called_class()); + $parentProps = array(); + $defaultProps = static::$defaultProps; + + if($parentClass) + { + $parentProps = call_user_func("$parentClass::definedPropsList", $parentClass); + if($defaultProps === $parentClass::$defaultProps) + { + $defaultProps = array(); + } + } + + return parsePropsMap($definition, $parentProps, $defaultProps); + } +} + +function renderToHtml(mixed ...$items): string +{ + $html = ''; + + foreach($items as $item) + { + if(is_array($item)) + { + $html .= renderToHtml(...$item); + continue; + } + if($item instanceof node || (is_object($item) && method_exists($item, 'render'))) + { + $html .= $item->render(); + continue; + } + if(is_object($item) && isset($item->html)) + { + $html .= $item->html; + continue; + } + if(!is_string($item)) $item = strval($item); + $html .= htmlspecialchars(strval($item), ENT_QUOTES | ENT_SUBSTITUTE | ENT_HTML401, null, false); + } + + return $html; +} + +/** + * Parse the props definition. + * + * @param array $definition - The props definition. + * @param array $parentProps - The parent props. + * @param array $defaultValues - The default values. + * @return array + */ +function parsePropsMap(array $definition, array $parentProps = array(), array $defaultValues = array()) +{ + $props = $parentProps; + + foreach($definition as $name => $value) + { + $prop = parseProp($value, is_string($name) ? $name : null); + $name = $prop['name']; + + if($prop['default'] === null) + { + if(isset($defaultValues[$prop['name']])) $prop['default'] = $defaultValues[$prop['name']]; + else if(isset($parentProps[$prop['name']])) $prop['default'] = $parentProps[$prop['name']]['default']; + } + + $props[$name] = $prop; + } + + return $props; +} + +/** + * Parse the prop definition. + * + * @param string|array $definition - The prop definition. + * @param string|null $name - The prop name. + * @param mixed $default - The default value. + * @return array + */ +function parseProp(string|array $definition, ?string $name = null, mixed $default = null) +{ + $optional = false; + $type = 'mixed'; + + if(is_string($definition)) $definition = trim($definition); + + /* Parse definition like `'name?: type1|type2="default"'` . */ + if(!$name && is_string($definition)) + { + if(str_contains($definition, ':')) + { + list($name, $definition) = explode(':', $definition, 2); + } + else + { + $name = $definition; + $definition = ''; + } + $name = trim($name); + if(str_ends_with($name, '?')) + { + $name = substr($name, 0, strlen($name) - 1); + $optional = true; + } + } + + /* Parse definition like `'name' => '?type1|type2="default"'` . */ + if(is_array($definition)) + { + if(isset($definition['type'])) $type = $definition['type']; + if(isset($definition['default'])) $default = $definition['default']; + if(isset($definition['optional'])) $optional = $definition['optional']; + } + else if(is_string($definition)) + { + if(str_contains($definition, '=')) + { + list($type, $default) = explode('=', $definition, 2); + } + else + { + $type = $definition; + } + if(is_string($default)) $default = json_decode(trim($default)); + } + + $type = trim($type); + if(str_starts_with($type, '?')) + { + $type = substr($type, 1); + $optional = true; + } + + $typeList = explode('|', $type); + if(in_array('null', $typeList) || in_array('mixed', $typeList)) + { + $optional = true; + } + elseif($optional) + { + array_unshift($typeList, 'null'); + } + + return array('name' => $name, 'type' => implode('|', $typeList), 'default' => $default, 'optional' => $default !== null || $optional); +} diff --git a/lib/zin/core/on.class.php b/lib/zin/core/on.class.php index b3d511300f..813d8002ba 100644 --- a/lib/zin/core/on.class.php +++ b/lib/zin/core/on.class.php @@ -12,10 +12,10 @@ declare(strict_types=1); namespace zin; -require_once __DIR__ . DS . 'wg.func.php'; +require_once __DIR__ . DS . 'zin.func.php'; require_once __DIR__ . DS . 'jscallback.class.php'; -use zin\wg; +use zin\node; /** * Events binding class. @@ -170,16 +170,16 @@ class on extends jsCallback } /** - * Apply to widget. + * Apply to node. * 应用到部件。 * * @access public - * @param wg $wg The widget instance. + * @param node $node The node instance. * @param string $blockName The block name. * @return void * @override */ - public function applyToWg(wg &$wg, string $blockName): void + public function apply(node $node, string $blockName): void { if($this->compatible) { @@ -187,12 +187,12 @@ class on extends jsCallback $options['selector'] = $this->selector; $options['handler'] = parent::buildBody(''); - $wg->setProp("@{$this->event}", (object)$options); + $node->setProp("@{$this->event}", (object)$options); return; } - $zuiInitCode = $wg->prop('zui-init', ''); - $wg->setProp('zui-init', $zuiInitCode . "\n" . $this->toJS()); + $zuiInitCode = $node->prop('zui-init', ''); + $node->setProp('zui-init', $zuiInitCode . "\n" . $this->toJS()); } /** diff --git a/lib/zin/core/props.class.php b/lib/zin/core/props.class.php index 411a760b9d..4c03689d79 100644 --- a/lib/zin/core/props.class.php +++ b/lib/zin/core/props.class.php @@ -70,8 +70,6 @@ class props extends \zin\utils\dataset elseif(str_starts_with($prop, '~')) $this->style->set(substr($prop, 1), $value); elseif($prop === '--') $this->style->cssVar($value); elseif(str_starts_with($prop, '--')) $this->style->cssVar(substr($prop, 2), $value); - elseif($prop === '!') $this->hx($value); - elseif(str_starts_with($prop, '!')) $this->hx(substr($prop, 1), $value); elseif(str_starts_with($prop, ':')) $this->set('data-' . substr($prop, 1), $value); elseif($prop === '@') $this->bindEvent($value); elseif(str_starts_with($prop, '@')) $this->bindEvent(substr($prop, 1), $value); @@ -149,17 +147,6 @@ class props extends \zin\utils\dataset return false; } - public function hx(array|string $name, ?string $value = null) - { - if(is_array($name)) - { - foreach($name as $key => $val) $this->set("hx-$key", $val); - return; - } - - $this->set("hx-$name", $value); - } - /** * Convert props to html string * diff --git a/lib/zin/core/rawcontent.class.php b/lib/zin/core/rawcontent.class.php deleted file mode 100644 index 023a73f211..0000000000 --- a/lib/zin/core/rawcontent.class.php +++ /dev/null @@ -1,23 +0,0 @@ - - * @package zin - * @version $Id - * @link https://www.zentao.net - */ - -namespace zin; - -require_once __DIR__ . DS . 'wg.class.php'; - -class rawContent extends wg -{ - protected function build(): directive - { - return h::comment('{{RAW_CONTENT}}'); - } -} diff --git a/lib/zin/core/render.func.php b/lib/zin/core/render.func.php index 50ef3d25ad..c8d19571c5 100644 --- a/lib/zin/core/render.func.php +++ b/lib/zin/core/render.func.php @@ -27,7 +27,8 @@ require_once __DIR__ . DS . 'hook.class.php'; function render(string $wgName = '', array $options = array()) { /* 获取全局渲染部件实例和指令。 Get global render widgets and directives. */ - $globalItems = zin::getGlobalRenderList(); + $context = context(); + $globalItems = $context->getGlobalRenderList(); /* 决定部件名称,如果是 Ajax 请求则进行特殊处理。 Decide widget name, if is ajax request, then do special process. */ if(empty($wgName)) @@ -51,17 +52,17 @@ function render(string $wgName = '', array $options = array()) /* 创建部件实例。 Create widget instance. */ $wg = createWg($wgName, $globalItems); + /* 如果不是渲染一个完整页面,则使用 fragment 进行渲染。 If not render in full page, then render all items in a fragment. */ + if(!$isFullPage && $wgName !== 'fragment') $wg = fragment($wg); + /* 设置全局根部件。 Set global root widget. */ hook::$globalRoot = $wg; /* 添加 hooks 内容。Add hooks contents. */ $wg->add(includeHooks()); - /* 如果不是渲染一个完整页面,则使用 fragment 进行渲染。 If not render in full page, then render all items in a fragment. */ - if(!$isFullPage && $wgName !== 'fragment') $wg = fragment($wg); - /* 渲染并输出 HTML。 Render and display html. */ - $wg->display($options); + // $wg->display($options); - zin::$rendered = true; + $context->rendered = true; } diff --git a/lib/zin/core/set.class.php b/lib/zin/core/set.class.php index d9a680e9bf..05d98cdff3 100644 --- a/lib/zin/core/set.class.php +++ b/lib/zin/core/set.class.php @@ -12,12 +12,34 @@ declare(strict_types=1); namespace zin; +require_once __DIR__ . DS . 'setting.class.php'; require_once __DIR__ . DS . 'directive.class.php'; +require_once __DIR__ . DS . 'context.func.php'; -class set +class set extends setting implements iDirective { - public static function __callStatic($prop, $args) + /** + * Create an instance, the initialed data can be passed. + * + * @access public + * @param array|object|string $data Properties list array. + * @param mixed $value Property value. + */ + public function __construct(array|string $data = null, mixed $value = null) { + parent::__construct($data, $value); + + renderInGlobal($this); + } + + public function apply(node $node, string $blockName): void + { + $node->setProp($this->toArray()); + } + + public static function __callStatic($prop, $args): set + { + $set = new set(); if($prop === 'class' || strtolower($prop) === 'classname') { global $config; @@ -25,13 +47,13 @@ class set { trigger_error("[ZIN] Use set::className() instead of set::class() to compatible with php 5.4.", E_USER_WARNING); } - return directive('prop', array('class' => $args)); + return $set->setClass('class', $args); } /* Compatible with zui prop className. */ if($prop === '_className') { - return directive('prop', array('className' => $args)); + return $set->setClass('className', $args); } /* Support to set url with createLink params. */ @@ -44,6 +66,102 @@ class set $value = count($args) > 1 ? $args : array_shift($args); } - return directive('prop', array($prop => $value)); + return $set->set($prop, $value); } } + +/** + * Set widget properties. + * + * @param string|array|props|null $name + * @param mixed $value + * @return set + */ +function set(string|array|props|null $name = null, mixed $value = null): set +{ + $set = new set(); + if($name === null) return $set; + + $props = null; + if($name instanceof props) $props = $name->toArray(); + else if(is_array($name)) $props = $name; + else if(is_object($name)) $props = (array)$name; + else if(is_string($name)) $props = array($name => $value); + $set->set($props); + return $set; +} + + +/** + * Set widget CSS class attribute. + * + * @param mixed ...$class + * @return set + */ +function setClass(mixed ...$class): set +{ + return set()->setClass('class', ...$class); +} + +/** + * Set widget style attribute. + * + * @return set + */ +function setStyle(array|string $name, ?string $value = null): set +{ + return set()->addToMap('style', is_array($name) ? $name : array($name => $value)); +} + +/** + * Set widget CSS variable. + * + * @return set + */ +function setCssVar(array|string $name, ?string $value = null): set +{ + return set()->addToMap('--', is_array($name) ? $name : array($name => $value)); +} + +/** + * Set widget ID attribute. + * + * @return ?set + */ +function setID(?string $id = null): set +{ + return set('id', $id); +} + +/** + * Set widget element tag name. + * + * @return set + */ +function setTag(string $id): set +{ + return set('tagName', $id); +} + +/** + * Set widget data-* attribute. + * + * @param string|array $name + * @param mixed $value + * @return set + */ +function setData(null|string|array $name, mixed $value = null): set +{ + if($name === null) return set(); + $map = is_array($name) ? $name : array($name => $value); + $attrs = array(); + foreach($map as $key => $value) + { + if(is_numeric($key)) $key = (string)$key; + $name = 'data-' . strtolower(preg_replace('/(? + * @package zin + * @version $Id + * @link https://www.zentao.net + */ + +namespace zin; + +require_once __DIR__ . DS . 'node.class.php'; +require_once __DIR__ . DS . 'directive.class.php'; + +class text extends node +{ + public static array $defineProps = array + ( + 'html' => '?bool', + ); + + public function type(): string + { + return 'node::' . $this->shortType(); + } + + public function shortType(): string + { + return $this->prop('html') ? 'html' : 'text'; + } + + public function render(): string + { + if($this->prop('html')) return implode('', $this->children()); + return parent::render(); + } +} + +function text(string ...$texts): text +{ + return new text(...$texts); +} + +function html(string ...$codes): text +{ + $text = new text(...$codes); + $text->setProp('html', true); + return $text; +} diff --git a/lib/zin/core/to.class.php b/lib/zin/core/to.class.php index f53c6b8446..98c114b07a 100644 --- a/lib/zin/core/to.class.php +++ b/lib/zin/core/to.class.php @@ -12,7 +12,7 @@ declare(strict_types=1); namespace zin; -require_once __DIR__ . DS . 'wg.func.php'; +require_once __DIR__ . DS . 'zin.func.php'; class to { diff --git a/lib/zin/core/wg.class.php b/lib/zin/core/wg.class.php index 11a8a9aa4f..0106576d27 100644 --- a/lib/zin/core/wg.class.php +++ b/lib/zin/core/wg.class.php @@ -12,645 +12,55 @@ declare(strict_types=1); namespace zin; -require_once __DIR__ . DS . 'props.class.php'; -require_once __DIR__ . DS . 'directive.class.php'; -require_once __DIR__ . DS . 'setting.class.php'; -require_once __DIR__ . DS . 'zin.class.php'; -require_once __DIR__ . DS . 'context.class.php'; -require_once __DIR__ . DS . 'selector.func.php'; -require_once __DIR__ . DS . 'dom.class.php'; +require_once __DIR__ . DS . 'node.class.php'; -class wg +class wg extends node { - /** - * Define props for the element - * - * @var array - */ - protected static array $defineProps = array(); + // public function buildEvents(): ?string + // { + // $events = $this->props->events(); + // if(empty($events)) return null; - protected static array $defaultProps = array(); + // $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));'); + // foreach($events as $event => $bindingList) + // { + // $code[] = "\$ele.on('$event.on.zin', function(e){"; + // foreach($bindingList as $binding) + // { + // if(is_string($binding)) $binding = (object)array('handler' => $binding); + // $selector = isset($binding->selector) ? $binding->selector : null; + // $handler = isset($binding->handler) ? trim($binding->handler) : ''; + // $stop = isset($binding->stop) ? $binding->stop : null; + // $prevent = isset($binding->prevent) ? $binding->prevent : null; + // $self = isset($binding->self) ? $binding->self : null; - protected static array $defineBlocks = array(); + // $code[] = '(function(){'; + // if($selector) $code[] = "const target = e.target.closest('$selector');if(!target) return;"; + // else $code[] = "const target = ele;"; + // if($self) $code[] = "if(ele !== e.target) return;"; + // if($stop) $code[] = "e.stopPropagation();"; + // if($prevent) $code[] = "e.preventDefault();"; - protected static array $wgToBlockMap = array(); + // if(preg_match('/^[$A-Z_][0-9A-Z_$\[\]."\']*$/i', $handler)) $code[] = "($handler).call(target,e);"; + // else $code[] = $handler; - protected static array $definedPropsMap = array(); + // $code[] = '})();'; + // } + // $code[] = "});events.add('$event');"; + // } + // $code[] = '$ele.attr("data-zin-events", Array.from(events).join(" "));'; + // return h::createJsScopeCode($code); + // } - protected static array $pageResources = array(); - - /** - * The props of the element - * - * @access public - * @var props - */ - public props $props; - - public array $blocks = array(); - - public ?wg $parent = null; - - public string $gid; - - public bool $displayed = false; - - public bool $removed = false; - - protected array $renderOptions = array(); - - public function __construct(/* string|element|object|array|null ...$args */) + public static function getPageCSS(): ?string { - $this->props = new props(); - - $this->gid = 'zin_' . uniqid(); - $this->setDefaultProps(static::getDefaultProps()); - $this->add(func_get_args()); - $this->created(); - - zin::renderInGlobal($this); - static::checkPageResources(); - - $this->checkErrors(); + return null; // No css } - public function __debugInfo(): array + public static function getPageJS(): ?string { - return $this->toJSON(); - } - - public function isDomElement(): bool - { - return false; - } - - /** - * Check if the element is match any of the selectors - * @param string|array|object $selectors - */ - public function isMatch(string|array|object $selectors): bool - { - $list = parseWgSelectors($selectors); - foreach($list as $selector) - { - if(isset($selector->command)) continue; - if(!empty($selector->id) && $this->id() !== $selector->id) continue; - if(!empty($selector->tag) && $this->shortType() !== $selector->tag) continue; - if(!empty($selector->class) && !$this->props->class->has($selector->class)) continue; - return true; - } - return false; - } - - /** - * Build dom object - * @return dom - */ - public function buildDom(): dom - { - $before = $this->buildBefore(); - $children = $this->build(); - $after = $this->buildAfter(); - $options = $this->renderOptions; - $selectors = (!empty($options) && isset($options['selector'])) ? $options['selector'] : null; - - return new dom - ( - $this, - [$before, $children, $after], - $selectors, - (!empty($options) && isset($options['type'])) ? $options['type'] : 'html', // TODO: () may not work in lower php - (!empty($options) && isset($options['data'])) ? $options['data'] : null, - ); - } - - /** - * Mark widget been removed. - * - * @param string $selector - * @access public - * @return void - */ - public function remove(string $selector = '') - { - if(!empty($selector)) - { - $list = $this->find($selector); - foreach($list as $item) $item->remove(); - return; - } - $this->removed = true; - } - - /** - * Find widgets by selector. - * - * @param string|array|object $selector - * @param string $blockName - * @param bool $nested - * @return array - * @access public - */ - public function find(string|array|object $selector, string $blockName = '', bool $nested = true): array - { - $selectors = parseWgSelectors($selector); - $result = array(); - $blocks = empty($blockName) ? $this->blocks : array($blockName => isset($this->blocks[$blockName]) ? $this->blocks[$blockName] : array()); - foreach($blocks as $items) - { - foreach($items as $item) - { - if(!($item instanceof wg)) continue; - - if($item->isMatch($selectors)) $result[] = $item; - elseif($nested) $result = array_merge($result, $item->find($selectors, '', $nested)); - } - } - return $result; - } - - /** - * Find children widgets by selector. - * - * @param string $selector - * @return array - * @access public - */ - public function findChildren(string $selector): array - { - return $this->find($selector, 'children', false); - } - - /** - * Find first widget by selector. - * - * @param string $selector - * @return wg|null - * @access public - */ - public function first(string $selector = ''): wg | null - { - return reset($this->find($selector)); - } - - /** - * Find last widget by selector. - * - * @param string $selector - * @return wg|null - * @access public - */ - public function last(string $selector = ''): wg | null - { - return end($this->find($selector)); - } - - /** - * Render widget to html - * @return string - */ - public function render(): string - { - if($this->removed) return ''; - - $dom = $this->buildDom(); - $result = $dom->render(); - - return is_string($result) ? $result : json_encode($result); - } - - public function display(array $options = array()): wg - { - zin::disableGlobalRender(); - $this->renderOptions = $options; - - $dom = $this->buildDom(); - $result = $dom->render(); - $context = context::current(); - $css = $context->getCSS(); - $js = $context->getJS(); - - global $app, $config; - $zinDebug = null; - if($config->debug && (!isAjaxRequest() || isAjaxRequest('zin'))) - { - $zinDebug = data('zinDebug'); - if(is_array($zinDebug)) - { - $zinDebug['basePath'] = $app->getBasePath(); - if(isset($app->zinErrors)) $zinDebug['errors'] = $app->zinErrors; - } - } - - $rawContent = ob_get_contents(); - if(!is_string($rawContent)) $rawContent = ''; - ob_end_clean(); - - if(is_object($result)) - { - if($zinDebug && isset($result['zinDebug'])) $result['zinDebug'] = $zinDebug; - $result = json_encode($result); - } - elseif(is_array($result)) - { - foreach($result as $index => $item) - { - if($item['name'] === 'zinDebug' && $zinDebug) - { - $result[$index]['data'] = $zinDebug; - continue; - } - if(!isset($item['type']) || $item['type'] !== 'html') continue; - - $data = $item['data']; - $data = str_replace('/*{{ZIN_PAGE_CSS}}*/', $css, $data); - $data = str_replace('/*{{ZIN_PAGE_JS}}*/', $js, $data); - $data = str_replace('', $rawContent, $data); - $result[$index]['data'] = $data; - } - $result = json_encode($result, JSON_PARTIAL_OUTPUT_ON_ERROR); - } - else - { - if($zinDebug) $js .= h::createJsVarCode('window.zinDebug', $zinDebug); - $result = str_replace('/*{{ZIN_PAGE_CSS}}*/', $css, $result); - $result = str_replace('/*{{ZIN_PAGE_JS}}*/', $js, $result); - $result = str_replace('', $rawContent, $result); - } - - ob_start(); - echo $result; - - $this->displayed = true; - context::destroy(); - return $this; - } - - protected function created() {} - - protected function buildBefore(): array - { - return $this->block('before'); - } - - protected function buildAfter(): array - { - return $this->block('after'); - } - - protected function build() - { - if($this->removed) return array(); - - return $this->children(); - } - - public function buildEvents(): ?string - { - $events = $this->props->events(); - 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));'); - foreach($events as $event => $bindingList) - { - $code[] = "\$ele.on('$event.on.zin', function(e){"; - foreach($bindingList as $binding) - { - if(is_string($binding)) $binding = (object)array('handler' => $binding); - $selector = isset($binding->selector) ? $binding->selector : null; - $handler = isset($binding->handler) ? trim($binding->handler) : ''; - $stop = isset($binding->stop) ? $binding->stop : null; - $prevent = isset($binding->prevent) ? $binding->prevent : null; - $self = isset($binding->self) ? $binding->self : null; - - $code[] = '(function(){'; - if($selector) $code[] = "const target = e.target.closest('$selector');if(!target) return;"; - else $code[] = "const target = ele;"; - if($self) $code[] = "if(ele !== e.target) return;"; - if($stop) $code[] = "e.stopPropagation();"; - if($prevent) $code[] = "e.preventDefault();"; - - if(preg_match('/^[$A-Z_][0-9A-Z_$\[\]."\']*$/i', $handler)) $code[] = "($handler).call(target,e);"; - else $code[] = $handler; - - $code[] = '})();'; - } - $code[] = "});events.add('$event');"; - } - $code[] = '$ele.attr("data-zin-events", Array.from(events).join(" "));'; - return h::createJsScopeCode($code); - } - - - protected function onAddBlock(array|string|wg|directive $child, string $name) - { - return $child; - } - - protected function onAddChild(array|string|wg|directive $child) - { - return $child; - } - - protected function onSetProp(array|string $prop, mixed $value) - { - if($prop === 'id' && $value === '$GID') $value = $this->gid; - if($prop[0] === '@') - { - $this->setDefaultProps(array('id' => $this->gid)); - context::current()->addWgWithEvents($this); - } - $this->props->set($prop, $value); - } - - protected function onGetProp(string $prop, mixed $defaultValue): mixed - { - return $this->props->get($prop, $defaultValue); - } - - public function add($item, string $blockName = 'children') - { - if($item === null || is_bool($item)) return $this; - - if(is_array($item)) - { - foreach($item as $child) $this->add($child, $blockName); - return $this; - } - - zin::disableGlobalRender(); - - if($item instanceof setting) $item = $item->toDirective(); - - if($item instanceof wg) $this->addToBlock($blockName, $item); - elseif(is_string($item)) $this->addToBlock($blockName, htmlspecialchars($item, ENT_QUOTES | ENT_SUBSTITUTE | ENT_HTML401, null, false)); - elseif(isDirective($item)) $this->directive($item, $blockName); - else $this->addToBlock($blockName, htmlspecialchars(strval($item), ENT_QUOTES | ENT_SUBSTITUTE | ENT_HTML401, null, false)); - - zin::enableGlobalRender(); - - return $this; - } - - public function addToBlock(array|string $name, array|string|null|wg|directive $child = null) - { - if(is_array($name)) - { - foreach($name as $blockName => $blockChildren) - { - $this->addToBlock($blockName, $blockChildren); - } - return; - } - if(is_array($child)) - { - foreach($child as $blockChild) - { - $this->addToBlock($name, $blockChild); - } - return; - } - - if($child instanceof wg && empty($child->parent)) $child->parent = &$this; - - if($name === 'children' && $child instanceof wg) - { - $blockName = static::getBlockNameForWg($child); - if($blockName !== null) $name = $blockName; - } - - $result = $name === 'children' ? $this->onAddChild($child) : $this->onAddBlock($child, $name); - - if($result === false) return; - if($result !== null && $result !== true) $child = $result; - - if(isset($this->blocks[$name])) $this->blocks[$name][] = $child; - else $this->blocks[$name] = array($child); - } - - public function children(): array - { - return $this->block('children'); - } - - public function block(string $name): array - { - $list = array(); - if(isset($this->blocks[$name])) - { - $items = $this->blocks[$name]; - foreach($items as $item) - { - $isWg = $item instanceof wg && $item->shortType() === 'wg'; - $item = $isWg ? $item->children() : $item; - if(is_array($item)) $list = array_merge($list, $item); - else $list[] = $item; - } - } - return $list; - } - - public function hasBlock(string $name): bool - { - return isset($this->blocks[$name]); - } - - /** - * Apply directive - */ - public function directive(directive &$directive, string $blockName) - { - $directive->parent = &$this; - $directive->applyToWg($this, $blockName); - } - - public function prop(array|string $name, mixed $defaultValue = null): mixed - { - if(is_array($name)) - { - $values = array(); - foreach($name as $index => $propName) - { - $values[] = $this->onGetProp($propName, is_array($defaultValue) ? (isset($defaultValue[$propName]) ? $defaultValue[$propName] : $defaultValue[$index]) : $defaultValue); - } - return $values; - } - - return $this->onGetProp($name, $defaultValue); - } - - /** - * Set property, an array can be passed to set multiple properties - * - * @access public - * @param props|array|string $prop - Property name or properties list - * @param mixed $value - Property value - */ - public function setProp(props|array|string $prop, mixed $value = null) - { - if($prop instanceof props) $prop = $prop->toJSON(); - - if(is_array($prop)) - { - foreach($prop as $name => $value) $this->setProp($name, $value); - return $this; - } - - if(!is_string($prop) || empty($prop)) return $this; - - if($prop[0] === '#') - { - $this->add($value, substr($prop, 1)); - return $this; - } - - $this->onSetProp($prop, $value); - return $this; - } - - public function hasProp(): bool - { - $names = func_get_args(); - if(empty($names)) return false; - foreach($names as $name) - { - if(!$this->props->has($name)) return false; - } - return true; - } - - public function setDefaultProps(array $props) - { - if(!is_array($props) || empty($props)) return; - - foreach($props as $name => $value) - { - if($this->props->has($name)) continue; - $this->setProp($name, $value); - } - } - - public function getRestProps(): array - { - return $this->props->skip(array_keys(static::definedPropsList())); - } - - public function getDefinedProps(): array - { - return $this->props->pick(array_keys(static::definedPropsList())); - } - - public function type(): string - { - return get_called_class(); - } - - public function shortType(): string - { - $type = $this->type(); - $pos = strrpos($type, '\\'); - return $pos === false ? $type : substr($type, $pos + 1); - } - - public function id(): ?string - { - return $this->prop('id'); - } - - public function toJSON(): array - { - $data = array(); - $data['gid'] = $this->gid; - $data['id'] = $this->id(); - $data['removed'] = $this->removed; - $data['props'] = $this->props->toJSON(); - - $data['type'] = $this->type(); - if(str_starts_with($data['type'], 'zin\\')) $data['type'] = substr($data['type'], 4); - - $data['blocks'] = array(); - foreach($this->blocks as $key => $value) - { - foreach($value as $index => $child) - { - if($child instanceof wg || (is_object($child) && method_exists($child, 'toJSON'))) - { - $value[$index] = $child->toJSON(); - } - elseif(isDirective($child, 'html')) - { - $value[$index] = $child->data; - } - } - if($key === 'children') - { - unset($data['blocks'][$key]); - $data['children'] = $value; - } - else - { - $data['blocks'][$key] = $value; - } - } - - if(empty($data['blocks'])) unset($data['blocks']); - - if(!empty($this->parent)) $data['parent'] = $this->parent->gid; - - return $data; - } - - /** - * Check errors in debug mode. - * - * @access protected - * @return void - */ - protected function checkErrors() - { - global $config; - if(!isset($config->debug) || !$config->debug) return; - - $definedProps = static::definedPropsList(); - foreach($definedProps as $name => $definition) - { - if($this->hasProp($name)) continue; - if(isset($definition['default']) && $definition['default'] !== null) continue; - if(isset($definition['optional']) && $definition['optional']) continue; - - trigger_error("[ZIN] The property \"$name: {$definition['type']}\" of widget \"{$this->type()}#$this->gid\" is required.", E_USER_ERROR); - } - - $wgErrors = $this->onCheckErrors(); - if(empty($wgErrors)) return; - - foreach($wgErrors as $error) - { - if(is_array($error)) trigger_error("[ZIN] $error[0]", count($error) > 1 ? $error[1] : E_USER_WARNING); - else trigger_error("[ZIN] $error", E_USER_ERROR); - } - } - - /** - * The lifecycle method for checking errors in debug mode. - * - * @access protected - * @return array|null - */ - protected function onCheckErrors(): array|null - { - return null; - } - - public static function getPageCSS(): string|false - { - return false; // No css - } - - public static function getPageJS(): string|false - { - return false; // No js + return null; // No js } protected static function checkPageResources() @@ -667,148 +77,15 @@ class wg if(!empty($pageJS)) context::js($pageJS); } - public static function wgBlockMap(): array - { - $wgName = get_called_class(); - if(!isset(wg::$wgToBlockMap[$wgName])) - { - $wgBlockMap = array(); - if(!empty(static::$defineBlocks)) - { - foreach(static::$defineBlocks as $blockName => $setting) - { - if(!isset($setting['map'])) continue; - $map = $setting['map']; - if(is_string($map)) $map = explode(',', $map); - foreach($map as $name) $wgBlockMap[$name] = $blockName; - } - } - wg::$wgToBlockMap[$wgName] = $wgBlockMap; - } - return wg::$wgToBlockMap[$wgName]; - } - - public static function getBlockNameForWg(wg|string $wg): ?string - { - $wgType = ($wg instanceof wg) ? $wg->type() : $wg; - $wgBlockMap = static::wgBlockMap(); - if(str_starts_with($wgType, 'zin\\')) $wgType = substr($wgType, 4); - return isset($wgBlockMap[$wgType]) ? $wgBlockMap[$wgType] : null; - } - - protected static function definedPropsList(?string $wgName = null): array - { - if($wgName === null) $wgName = get_called_class(); - - if(!isset(wg::$definedPropsMap[$wgName]) && $wgName === get_called_class()) - { - wg::$definedPropsMap[$wgName] = static::parsePropsDefinition(static::$defineProps); - } - return wg::$definedPropsMap[$wgName]; - } - - protected static function getDefaultProps(?string $wgName = null): array - { - $defaultProps = array(); - foreach(static::definedPropsList($wgName) as $name => $definition) - { - if(!isset($definition['default'])) continue; - $defaultProps[$name] = $definition['default']; - } - return $defaultProps; - } - - /** - * Parse props definition - * @param $definition - * @example - * - * $definition = array('name', 'desc:string', 'title?:string|element', 'icon?:string="star"'); - * $definition = array('name' => 'mixed', 'desc' => 'string', 'title' => array('type' => 'string|element', 'optional' => true), 'icon' => array('type' => 'string', 'default' => 'star', 'optional' => true)))) - */ - private static function parsePropsDefinition(array $definition): array - { - $parentClass = get_parent_class(get_called_class()); - /** - * @var array - */ - $props = $parentClass ? call_user_func("$parentClass::definedPropsList") : array(); - - if($parentClass !== false && $definition === $parentClass::$defineProps) - { - if(!empty(static::$defaultProps) && static::$defaultProps !== $parentClass::$defaultProps) - { - foreach($props as $name => $value) - { - if(isset(static::$defaultProps[$name])) - { - $value['default'] = static::$defaultProps[$name]; - $props[$name] = $value; - } - } - } - return $props; - } - - foreach($definition as $name => $value) - { - $optional = false; - $type = 'mixed'; - $default = (isset($props[$name]) && isset($props[$name]['default'])) ? $props[$name]['default'] : null; - - if(is_int($name) && is_string($value)) - { - $value = trim($value); - if(!str_contains($value, ':')) - { - $name = $value; - $value = ''; - } - else - { - list($name, $value) = explode(':', $value, 2); - } - $name = trim($name); - if($name[strlen($name) - 1] === '?') - { - $name = substr($name, 0, strlen($name) - 1); - $optional = true; - } - } - - if(is_array($value)) - { - $type = isset($value['type']) ? $value['type'] : $type; - $default = isset($value['default']) ? $value['default'] : $default; - $optional = isset($value['optional'])? $value['optional']: $optional; - } - else if(is_string($value)) - { - if(!str_contains($value, '=')) - { - $type = $value; - $default = null; - } - else - { - list($type, $default) = explode('=', $value, 2); - } - $type = trim($type); - - if(is_string($default)) $default = json_decode(trim($default)); - } - - $props[$name] = array('type' => empty($type) ? 'mixed' : $type, 'default' => $default, 'optional' => $default !== null || $optional); - } - - if(static::$defaultProps && (!$parentClass || static::$defaultProps !== $parentClass::$defaultProps)) - { - foreach(static::$defaultProps as $name => $value) - { - if(!isset($props[$name])) continue; - $props[$name]['default'] = $value; - } - } - return $props; - } + protected static array $pageResources = array(); +} + +/** + * Create an new widget. + * + * @return wg + */ +function wg(mixed ...$args): wg +{ + return new wg(...$args); } diff --git a/lib/zin/core/wg.func.php b/lib/zin/core/wg.func.php deleted file mode 100644 index 96f1d2cc5d..0000000000 --- a/lib/zin/core/wg.func.php +++ /dev/null @@ -1,290 +0,0 @@ - - * @package zin - * @link http://www.zentao.net - */ -namespace zin; - -require_once dirname(__DIR__) . DS . 'utils' . DS . 'flat.func.php'; -require_once __DIR__ . DS . 'loader.func.php'; -require_once __DIR__ . DS . 'props.class.php'; -require_once __DIR__ . DS . 'directive.class.php'; -require_once __DIR__ . DS . 'setting.class.php'; -require_once __DIR__ . DS . 'rawcontent.class.php'; -require_once __DIR__ . DS . 'wg.class.php'; -require_once __DIR__ . DS . 'context.func.php'; -require_once __DIR__ . DS . 'on.class.php'; -require_once __DIR__ . DS . 'jquery.class.php'; - -/** - * Create an new widget. - * - * @return wg - */ -function wg(): wg -{ - return new wg(func_get_args()); -} - -/** - * Set widget properties. - * - * @param string|array|props|null $name - * @param mixed $value - * @return directive|null - */ -function set(string|array|props|null $name, mixed $value = null): ?directive -{ - if($name === null) return null; - - $props = null; - if($name instanceof props) $props = $name; - else if(is_array($name)) $props = $name; - else if(is_object($name)) $props = (array)$name; - else if(is_string($name)) $props = array($name => $value); - return $props ? directive('prop', $props) : null; -} - -/** - * Set widget CSS class attribute. - * - * @param array|string|null ...$classList - * @return directive - */ -function setClass(/* array|string|null ...$classList */): directive -{ - return directive('class', func_get_args()); -} - -/** - * Set widget style attribute. - * - * @return directive - */ -function setStyle(array|string $name, ?string $value = null): directive -{ - return directive('style', is_array($name) ? $name : array($name => $value)); -} - -/** - * Set widget CSS variable. - * - * @return directive - */ -function setCssVar(array|string $name, ?string $value = null): directive -{ - return directive('cssVar', is_array($name) ? $name : array($name => $value)); -} - -/** - * Set widget ID attribute. - * - * @return ?directive - */ -function setID(?string $id = null): directive -{ - return set('id', $id); -} - -/** - * Set widget element tag name. - * - * @return directive - */ -function setTag(string $id): directive -{ - return set('tagName', $id); -} - -/** - * Set widget data-* attribute. - * - * @param string|array $name - * @param mixed $value - * @return directive - */ -function setData(null|string|array $name, mixed $value = null): ?directive -{ - if($name === null) return null; - $map = is_array($name) ? $name : array($name => $value); - $attrs = array(); - foreach($map as $key => $value) - { - if(is_numeric($key)) $key = (string)$key; - $name = 'data-' . strtolower(preg_replace('/(? 1 ? $args : $args[0]); - return directive('block', array($name => $wg)); -} - -/** - * Create content for block "before". - * - * @param string $wgs - * @return directive - */ -function before(/* mixed ...$wgs */): directive -{ - return to('before', func_get_args()); -} - -/** - * Create content for block "after". - * - * @param string $wgs - * @return directive - */ -function after(): directive -{ - return to('after', func_get_args()); -} - -/** - * Create widget contents inherited from the given widget. - * - * @param wg|array $item - * @return array - */ -function inherit(wg|array $item): array -{ - if(!($item instanceof wg)) $item = new wg($item); - return array(set($item->props), directive('block', $item->blocks), $item->children()); -} - -/** - * Divorce widget from parent. - * - * @param wg|array $item - * @return array - */ -function divorce(wg|array $item): wg|array -{ - if($item instanceof wg) - { - $item->parent = null; - } - else if(is_array($item)) - { - foreach($item as $i) divorce($i); - } - return $item; -} - -/** - * Check if the given widget list has the given widget type. - * - * @param wg|array $items - * @param string $type - * @return bool - */ -function hasWgInList(wg|array $items, string $type): bool -{ - if(!is_array($items)) $items = array($items); - foreach($items as $item) - { - if($item instanceof wg && $item->type() == $type) return true; - } - return false; -} - -/** - * Group widgets by type. - * - * @param wg|array $items - * @param string $types - * @return array - */ -function groupWgInList(wg|array $items, string|array $types): array -{ - if(is_string($types)) $types = explode(',', $types); - $typesMap = array(); - $restList = array(); - - foreach($types as $type) $typesMap[$type] = array(); - - foreach($items as $item) - { - if(!($item instanceof wg)) continue; - - $type = $item->shortType(); - if(isset($typesMap[$type])) $typesMap[$type][] = $item; - else $restList[] = $item; - } - - $groups = array(); - foreach($types as $index => $type) $groups[] = $typesMap[$type]; - $groups[] = $restList; - return $groups; -} - -/** - * Create raw content placeholder. - * - * @return rawContent - */ -function rawContent(): rawContent -{ - zin::$rawContentCalled = true; - - return new rawContent(); -} - -/** - * Include hooks files. - */ -function includeHooks() -{ - $hookFiles = context::current()->getHookFiles(); - ob_start(); - foreach($hookFiles as $hookFile) - { - if(!empty($hookFile) && file_exists($hookFile)) include $hookFile; - } - $hookCode = ob_get_clean(); - return html($hookCode); -} diff --git a/lib/zin/core/zin.func.php b/lib/zin/core/zin.func.php new file mode 100644 index 0000000000..69231d0e86 --- /dev/null +++ b/lib/zin/core/zin.func.php @@ -0,0 +1,140 @@ + + * @package zin + * @link http://www.zentao.net + */ +namespace zin; + +require_once dirname(__DIR__) . DS . 'utils' . DS . 'flat.func.php'; +require_once __DIR__ . DS . 'loader.func.php'; +require_once __DIR__ . DS . 'node.class.php'; +require_once __DIR__ . DS . 'text.class.php'; +require_once __DIR__ . DS . 'props.class.php'; +require_once __DIR__ . DS . 'directive.class.php'; +require_once __DIR__ . DS . 'setting.class.php'; +require_once __DIR__ . DS . 'set.class.php'; +require_once __DIR__ . DS . 'wg.class.php'; +require_once __DIR__ . DS . 'h.class.php'; +require_once __DIR__ . DS . 'h.func.php'; +require_once __DIR__ . DS . 'item.class.php'; +require_once __DIR__ . DS . 'to.class.php'; +require_once __DIR__ . DS . 'context.func.php'; +require_once __DIR__ . DS . 'on.class.php'; +require_once __DIR__ . DS . 'jquery.class.php'; + +/** + * Create block content. + * + * @param string $name + * @param mixed ...$args + * @return directive + */ +function to(string $blockName, mixed ...$args): directive +{ + $node = new node(...$args); + return directive('block', array($blockName => $node)); +} + +/** + * Create content for block "before". + * + * @param string $args + * @return directive + */ +function before(mixed ...$args): directive +{ + return to('before', ...$args); +} + +/** + * Create content for block "after". + * + * @param string $args + * @return directive + */ +function after(mixed ...$args): directive +{ + return to('after', ...$args); +} + +/** + * Create widget contents inherited from the given widget. + * + * @param node|array $item + * @return array + */ +function inherit(node|array $item): array +{ + if(!($item instanceof node)) $item = new node($item); + return array(set($item->props), directive('block', $item->blocks), $item->children()); +} + +/** + * Divorce widget from parent. + * + * @param node|array $item + * @return array + */ +function divorce(node|array $item): node|array +{ + if($item instanceof node) + { + $item->parent = null; + } + else if(is_array($item)) + { + foreach($item as $i) divorce($i); + } + return $item; +} + +/** + * Group widgets by type. + * + * @param wg|array $items + * @param string $types + * @return array + */ +function groupWgInList(wg|array $items, string|array $types): array +{ + if(is_string($types)) $types = explode(',', $types); + $typesMap = array(); + $restList = array(); + + foreach($types as $type) $typesMap[$type] = array(); + + foreach($items as $item) + { + if(!($item instanceof wg)) continue; + + $type = $item->shortType(); + if(isset($typesMap[$type])) $typesMap[$type][] = $item; + else $restList[] = $item; + } + + $groups = array(); + foreach($types as $index => $type) $groups[] = $typesMap[$type]; + $groups[] = $restList; + return $groups; +} + +/** + * Include hooks files. + */ +function includeHooks() +{ + $hookFiles = context::current()->getHookFiles(); + ob_start(); + foreach($hookFiles as $hookFile) + { + if(!empty($hookFile) && file_exists($hookFile)) include $hookFile; + } + $hookCode = ob_get_clean(); + return html($hookCode); +} diff --git a/lib/zin/func.php b/lib/zin/func.php index 8834d82ff1..8837492ba6 100644 --- a/lib/zin/func.php +++ b/lib/zin/func.php @@ -12,1897 +12,152 @@ declare(strict_types=1); namespace zin; -require_once __DIR__ . DS . 'core' . DS . 'h.func.php'; +require_once __DIR__ . DS . 'core' . DS . 'zin.func.php'; require_once __DIR__ . DS . 'core' . DS . 'render.func.php'; require_once __DIR__ . DS . 'zui' . DS . 'zui.func.php'; require_once __DIR__ . DS . 'zentao' . DS . 'zentao.func.php'; require_once __DIR__ . DS . 'zentao' . DS . 'field.func.php'; require_once __DIR__ . DS . 'zentao' . DS . 'bind.class.php'; -/* Form */ - -/** - * Html input. - * - * string name - * ?string type='text' - * ?string id - * ?string class='form-control' - * ?string value - * ?bool required - * ?string placeholder - * ?bool autofocus - * ?bool autocomplete=false - * ?bool disabled - */ -function input(): input -{ - return createWg('input', func_get_args()); -} - -/** - * Html textarea. - * - * string name - * int rows - * int cols - * ?string id - * ?string class='form-control' - * ?bool required - * ?string placeholder - */ -function textarea(): textarea -{ - return createWg('textarea', func_get_args()); -} - -/** - * Radio widget. - * - * string id - * ?string text - * ?bool checked - * ?string name - * ?bool primary=true - * ?bool disabled - * ?string value - * ?string typeClass - * ?string rootClass - */ -function radio(): radio -{ - return createWg('radio', func_get_args()); -} - -/** - * Switcher widget. - * - * string id - * string value - * ?string text - * ?bool checked - * ?string name - * ?bool primary=true - * ?bool disabled - * ?string typeClass - * ?string rootClass - */ -function switcher(): switcher -{ - return createWg('switcher', func_get_args()); -} - -/** - * Checkbox widget. - * - * string id - * ?string text - * ?bool checked - * ?string name - * ?bool primary=true - * ?bool disabled - * ?string value - * ?string typeClass - * ?string rootClass - * ?string labelClass - */ -function checkbox(): checkbox -{ - return createWg('checkbox', func_get_args()); -} - -/** - * Checkbox group widget. - * - * array title - * array items - */ -function checkboxGroup(): checkboxGroup -{ - return createWg('checkboxGroup', func_get_args()); -} - -/** - * Base form widget. - * - * ?string id='$GID' - * ?string method='post' - * ?string url - * ?array actions - * ?string actionsClass - * ?string target - * ?string submitBtnText - * ?string cancelBtnText - */ -function formBase(): formBase -{ - return createWg('formBase', func_get_args()); -} - -/** - * Form widget. - * - * ?string id='$GID' - * ?string method='post' - * ?string url - * ?array actions - * ?string actionsClass - * ?string target - * ?string submitBtnText - * ?string cancelBtnText - * ?bool grid - * ?int labelWidth - */ -function form(): form -{ - return createWg('form', func_get_args()); -} - -/** - * Form panel widget. - * - * ?string method - * ?string url - * ?array actions - * ?string target - * ?array items - * ?bool grid - * ?int labelWidth - */ -function formPanel(): formPanel -{ - return createWg('formPanel', func_get_args()); -} - -/** - * Form grid panel widget. - */ -function formGridPanel(): formGridPanel -{ - return createWg('formGridPanel', func_get_args()); -} - -/** - * Zentao form batch wg. - * - * ?string id='$GID' - * ?string method='post' - * ?string url - * ?array actions - * ?string actionsClass - * ?string target - * ?array items - * ?int minRows=1 - * ?int maxRows=100 - * ?array data - * ?string mode='add' - */ -function formBatch(): formBatch -{ - return createWg('formBatch', func_get_args()); -} - -/** - * Zentao form batch item wg. - * - * ?string name - * ?string|bool label - * ?string labelClass - * ?string labelProps - * ?bool|string required="auto" - * ?array|string control - * ?string width - * ?string|array value - * ?bool disabled - * ?array items - * ?string placeholder - * ?bool hidden=false - */ -function formBatchItem(): formBatchItem -{ - return createWg('formBatchItem', func_get_args()); -} - -/** - * Form panel widget. - * - * ?string method - * ?string url - * ?array actions - * ?string target - * ?array items - * ?bool grid - * ?int labelWidth - * ?int minRows=1 - * ?int maxRows=100 - * ?array data - * ?string mode='add' - */ -function formBatchPanel(): formBatchPanel -{ - return createWg('formBatchPanel', func_get_args()); -} - -/** - * Batch actions: add, delete. - */ -function batchActions(): batchActions -{ - return createWg('batchActions', func_get_args()); -} - -/** - * Control widget. - * Dynamically create html input. - * - * string type - it can be text, password, email, number, date, time, datetime, month, url, search, tel, color, picker, select, checkbox, radio, checkboxList, radioList, checkboxListInline, radioListInline, file, textarea. - * string name - * ?string id - * ?string value - * ?bool required - * ?string placeholder - * ?bool disabled - * ?string form - * ?array items - */ -function control(): control -{ - return createWg('control', func_get_args()); -} - -/** - * Html select. - * - * string name - * ?string id - * ?string class="form-control" - * ?string value - * ?bool required - * ?bool disabled - * ?bool multiple - * ?array items - * ?int size - */ -function select(): select -{ - return createWg('select', func_get_args()); -} - -/** - * Html label which use id form. - * - * ?string text - * ?bool required - * ?string for - */ -function formLabel(): formLabel -{ - return createWg('formLabel', func_get_args()); -} - -/** - * Form group widget. - * - * ?string name - * ?string labelClass - * ?string tip - * ?array tipProps - * ?string width - * ?bool strong - * ?bool disabled - * ?array items - * ?string placeholder - * bool|string|null required='auto' - * string|array|null tipClass - * string|bool|null label - * string|array|null value - * array|string|null control - */ -function formGroup(): formGroup -{ - return createWg('formGroup', func_get_args()); -} - -/** - * Form row widget. - * - * ?string width - * ?array items - * ?bool hidden - */ -function formRow(): formRow -{ - return createWg('formRow', func_get_args()); -} - -/** - * Form row group widget. - * - * ?string width - * ?array items - * ?bool hidden - */ -function formRowGroup(): formRowGroup -{ - return createWg('formRowGroup', func_get_args()); -} - -/** - * Html input with prefix or suffix. - * - * mixed prefix - * mixed suffix - * string|int prefixWidth - * string|int suffixWidth - */ -function inputControl(): inputControl -{ - return createWg('inputControl', func_get_args()); -} - -/** - * Input group widget. - * - * ?array items - * ?bool seg - */ -function inputGroup(): inputGroup -{ - return createWg('inputGroup', func_get_args()); -} - -/** - * Input group addon widget. - */ -function inputGroupAddon(): inputGroupAddon -{ - return createWg('inputGroupAddon', func_get_args()); -} - -/** - * Checkbox list widget. - * - * ?string name - * ?bool primary=true - * ?array items - * ?bool inline - * string|array|null value - */ -function checkList(): checkList -{ - return createWg('checkList', func_get_args()); -} - -/** - * Radio list widget. - * - * ?string name - * ?bool primary=true - * ?array items - * ?bool inline - * string|array|null value - */ -function radioList(): radioList -{ - return createWg('radioList', func_get_args()); -} - -/** - * Check button widget. - */ -function checkBtn(): checkBtn -{ - return createWg('checkBtn', func_get_args()); -} - -/** - * Check button group widget. - */ -function checkBtnGroup(): checkBtnGroup -{ - return createWg('checkBtnGroup', func_get_args()); -} - -/** - * Check color group widget. - */ -function checkColorGroup(): checkColorGroup -{ - return createWg('checkColorGroup', func_get_args()); -} - -/** - * Color picker widget which extends input. - * - * ?string heading - * ?string icon - * ?bool closeBtn=true - * ?string syncText - * ?string syncColor - * ?string syncBackground - * ?string syncBorder - */ -function colorPicker(): colorPicker -{ - return createWg('colorPicker', func_get_args()); -} - -/** - * Date picker widget which extends input. - * - * string name - * ?string id - * ?string class - * ?string value - * ?bool required - * ?string placeholder - * ?bool autofocus - * ?bool disabled - * ?bool autocomplete=false - */ -function datePicker(): datePicker -{ - return createWg('datePicker', func_get_args()); -} - -/** - * Datetime picker widget which extends input. - * - * string name - * ?string id - * ?string class - * ?string value - * ?bool required - * ?string placeholder - * ?bool autofocus - * ?bool disabled - * ?bool autocomplete=false - */ -function datetimePicker(): datetimePicker -{ - return createWg('datetimePicker', func_get_args()); -} - -/** - * Time picker widget which extends input. - * - * string name - * ?string id - * ?string class - * ?string value - * ?bool required - * ?string placeholder - * ?bool autofocus - * ?bool disabled - * ?bool autocomplete=false - */ -function timePicker(): timePicker -{ - return createWg('timePicker', func_get_args()); -} - -/** - * Html file input which extends input. - * - * string name - * ?string id - * ?string class - * ?string value - * ?bool required - * ?string placeholder - * ?bool autofocus - * ?bool disabled - * ?bool autocomplete=false - */ -function fileInput(): fileInput -{ - return createWg('fileInput', func_get_args()); -} - -/** - * Page form widget which extends page. - * - * ?array formPanel - * ?string title - * ?array bodyProps - * ?bool zui=true - * ?bool display=true - * array|string|null bodyClass - * string|array|null metas=array('', '', '', '') - * - * ====== blocks ====== - * head = array() - * header = array('map' => 'header') - * main = array('map' => 'main') - * footer = array() - * ==================== - */ -function pageForm(): pageForm -{ - return createWg('pageForm', func_get_args()); -} - -/** - * Icon widget. - * - * string name - * string|int|null size - */ -function icon(): icon -{ - return createWg('icon', func_get_args()); -} - -/** - * Button widget. - * - * ?string icon - * ?string text - * ?bool square - * ?bool disabled - * ?bool active - * ?string url - * ?string target - * ?string trailingIcon - * ?string hint - * ?string type - * ?string btnType - * string|int|null size - * string|bool|null caret - */ -function btn(): btn -{ - return createWg('btn', func_get_args()); -} - -/** - * Page base widget. - * - * ?string title - * ?array bodyProps - * ?bool zui=false - * ?bool display=true - * array|string|null bodyClass - * string|array|null metas=array('', '', '', '') - */ -function pageBase(): pageBase -{ - return createWg('pageBase', func_get_args()); -} - -/** - * Page widget. - * - * ?string title - * ?array bodyProps - * ?array|string bodyClass - * ?bool zui=true - * ?bool display=true - * string|array|null metas=array('', '', '', '') - * - * ====== blocks ====== - * head = array() - * header = array('map' => 'header') - * main = array('map' => 'main') - * footer = array() - * ==================== - */ -function page(): page -{ - return createWg('page', func_get_args()); -} - -/** - * Fragment widget. - * Let you group elements without a wrapper node. - */ -function fragment(): fragment -{ - return createWg('fragment', func_get_args()); -} - -/** - * Button group widget. - * - * ?array items - * ?bool disabled - * ?string size - */ -function btnGroup(): btnGroup -{ - return createWg('btnGroup', func_get_args()); -} - -/** - * Zentao main menu widget. - * - * ?array statuses - * ?array btnGroup - * ?array others - */ -function mainMenu(): mainMenu -{ - return createWg('mainMenu', func_get_args()); -} - -/** - * Row widget. - * - * ?string justify - * ?string align - */ -function row(): row -{ - return createWg('row', func_get_args()); -} - -/** - * Col widget. - * - * ?string justify - * ?string align - */ -function col(): col -{ - return createWg('col', func_get_args()); -} - -/** - * Center widget. - */ -function center(): center -{ - return createWg('center', func_get_args()); -} - -/** - * Cell widget. - * Flex item. - * - * int order - * int grow - * string shrink - * string|int width 'auto'|'flex-start'|'flex-end'|'center'|'baseline'|'stretch' - * string align - * string flex - */ -function cell(): cell -{ - return createWg('cell', func_get_args()); -} - -/** - * Divider widget. - */ -function divider(): divider -{ - return createWg('divider', func_get_args()); -} - -/** - * Action item widget. - * - * ?string name='action' - * ?string type='item' - * ?string outerTag='li' - * ?string tagName='a' - * ?string icon - * ?string text - * ?string url - * ?string target - * ?bool active - * ?bool disabled - * ?string trailingIcon - * ?array outerProps - * ?string outerClass - * ?props array - * string|array|object|null badge - */ -function actionItem(): actionItem -{ - return createWg('actionItem', func_get_args()); -} - -/** - * Nav widget. - * - * ?array items - */ -function nav(): nav -{ - return createWg('nav', func_get_args()); -} - -/** - * Label widget. - * - * ?string text - */ -function label(): label -{ - return createWg('label', func_get_args()); -} - -/** - * DTable widget. - * - * ?string className - * ?string id - * ?bool customCols - * ?array cols - * ?string module - */ -function dtable(): dtable -{ - return createWg('dtable', func_get_args()); -} - -/** - * Menu widget. - * - * ?array items - */ -function menu(): menu -{ - return createWg('menu', func_get_args()); -} - -/** - * Dropdown widget. - * - * ?array items - * ?string placement - * ?string strategy - * ?int offset - * ?bool flip - * ?string arrow - * ?string trigger - * ?array menu - * ?string target - * ?string id - * ?string menuClass - * ?bool hasIcons - * ?bool staticMenu - */ -function dropdown(): dropdown -{ - return createWg('dropdown', func_get_args()); -} - -/** - * Header widget. - * - * ====== blocks ====== - * heading = array('map' => 'toolbar') - * navbar = array('map' => 'nav') - * toolbar = array('map' => 'btn') - * ==================== - */ -function header(): header -{ - return createWg('header', func_get_args()); -} - -/** - * Heading widget. - * - * array items - * ?bool showAppName=true - */ -function heading(): heading -{ - return createWg('heading', func_get_args()); -} - -/** - * Navbar widget. - * - * ?array items - */ -function navbar(): navbar -{ - return createWg('navbar', func_get_args()); -} - -/** - * Dropmenu widget. - * - * ?string id // ID,当页面有多个 dropmenu 时确保有唯一的 ID。 - * ?string tab // 应用名。 - * ?string module // 模块名。 - * ?string method // 方法名。 - * ?string objectID // 当前选中项的 ID。 - * ?string extra // 额外参数。 - * ?string url // 异步获取下拉菜单选项数据的 URL。 - * ?string text // 选择按钮上显示的文本。 - * ?bool|int cache // 是否启用缓存。 - * ?array data // 手动指定数据。 - * ?string menuID // 指定下拉菜单的ID。 - */ -function dropmenu(): dropmenu -{ - return createWg('dropmenu', func_get_args()); -} - -/** - * Main widget. - * - * ====== blocks ====== - * menu = array('map' => 'featureBar,nav,toolbar') - * sidebar = array('map' => 'sidebar') - * ==================== - */ -function main(): main -{ - return createWg('main', func_get_args()); -} - -/** - * Zentao sidebar widget. - * - * ?string side='left' - * ?bool showToggle=true - */ -function sidebar(): sidebar -{ - return createWg('sidebar', func_get_args()); -} - -/** - * Zentao feature bar widget. - * - * ?array items - * ?string current - * ?string link - * ?string linkParams - * ?string module - * ?string method - * - * ====== blocks ====== - * nav = array('map' => 'nav') - * leading = array() - * trailing = array() - * ==================== - */ -function featureBar(): featureBar -{ - return createWg('featureBar', func_get_args()); -} - -/** - * Avatar widget. - * - * ?string className - * ?array style - * ?int size=32 - * ?bool circle=true - * ?string|int rounded - * ?string background - * ?string foreColor - * ?string text - * ?string code - * ?int maxTextLength=2 - * ?int hueDistance=43 - * ?int saturation=0.4 - * ?int lightness=0.6 - * ?string src - */ -function avatar(): avatar -{ - return createWg('avatar', func_get_args()); -} - -/** - * Zentao user avatar widget. - * - * string className? - * array style? - * int size=32 - * bool circle=true - * string|int rounded - * string background - * string foreColor - * string text - * string code? - * int maxTextLength=2 - * int hueDistance=43 - * int saturation=0.4 - * int lightness=0.6 - * string src? - * string avatar? - * string account? - * string realname? - * array|object user? - */ -function userAvatar(): userAvatar -{ - return createWg('userAvatar', func_get_args()); -} - -/** - * Pager widget. - */ -function pager(): pager -{ - return createWg('pager', func_get_args()); -} - -/** - * Modal widget. - * - * ?string id="$GID" - * ?array modalProps=array() - */ -function modal(): modal -{ - return createWg('modal', func_get_args()); -} - -/** - * Modal trigger widget. - * - * ?string target - * ?bool keyboard - * ?bool moveable - * ?bool animation - * ?int transTime - * ?bool responsive - * ?string type - * ?string loadingText - * ?int loadTimeout - * ?string failedTip - * ?string timeoutTip - * ?string title - * ?string content - * ?object custom - * ?string url - * ?object request - * ?string dataType - * bool|string|null backdrop - * string|int|object|null size - * string|int|object|function|null position - * - * ====== blocks ====== - * trigger = array('map' => 'btn,a') - * modal = array('map' => 'modal') - * ==================== - */ -function modalTrigger(): modalTrigger -{ - return createWg('modalTrigger', func_get_args()); -} - -/** - * Modal header widget. - * - * ?string title - * ?string entityText - * ?int entityID - */ -function modalHeader(): modalHeader -{ - return createWg('modalHeader', func_get_args()); -} - -/** - * Modal dialog widget. - * - * ?string title - * ?int itemID - * ?string headerClass - * ?array headerProps - * ?array actions - * ?array footerActions - * ?string footerClass - * ?array footerProps - * bool|array|null closeBtn=true - */ -function modalDialog(): modalDialog -{ - return createWg('modalDialog', func_get_args()); -} - -/** - * Tabs widget. - * - * ?string direction='h' - * ?bool collapse=false - */ -function tabs(): tabs -{ - return createWg('tabs', func_get_args()); -} - -/** - * Tab pane widget. - * - * ?bool active - * string key - * string title - * - * ====== blocks ====== - * prefix = array() - * suffix = array() - * ==================== - */ -function tabPane(): tabPane -{ - return createWg('tabPane', func_get_args()); -} - -/** - * Panel widget. - * - * ?string class='rounded shadow ring-0 canvas' - * ?string size - * ?string title - * ?string titleClass - * ?array titleProps - * ?string headingClass - * ?array headingProps - * ?array headingActions - * ?string bodyClass - * ?array bodyProps - * ?array footerActions - * ?string footerClass - * ?array footerProps - */ -function panel(): panel -{ - return createWg('panel', func_get_args()); -} - -function pasteDialog(): pasteDialog -{ - return createWg('pasteDialog', func_get_args()); -} - -/** - * Tooltip widget. - */ -function tooltip(): tooltip -{ - return createWg('tooltip', func_get_args()); -} - -/** - * Toolbar widget. - * - * ?array items - * ?string btnClass - * ?array btnProps - */ -function toolbar(): toolbar -{ - return createWg('toolbar', func_get_args()); -} - -/** - * Zentao search toggle widget. - * - * ?bool open - */ -function searchToggle(): searchToggle -{ - return createWg('searchToggle', func_get_args()); -} - -/** - * Zentao search form widget. - */ -function searchForm(): searchForm -{ - return createWg('searchForm', func_get_args()); -} - -/** - * Zentao program menu widget. - * - * ?array programs - * ?string activeClass - * ?string activeIcon - * ?string activeKey - * ?string closeLink - */ -function programMenu(): programMenu -{ - return createWg('programMenu', func_get_args()); -} - -/** - * Zentao product menu widget. - * - * ?string title - * ?array items - * ?string activeKey - * ?string link - */ -function productMenu(): productMenu -{ - return createWg('productMenu', func_get_args()); -} - -/** - * Zentao module menu widget. - * - * array modules - * int activeKey - * string closeLink - */ -function moduleMenu(): moduleMenu -{ - return createWg('moduleMenu', func_get_args()); -} - -/** - * Zentao doc module menu widget. - * - * array modules - * int activeKey - * string closeLink - */ -function docMenu(): docMenu -{ - return createWg('docMenu', func_get_args()); -} - -/** - * Zentao tree widget. - * - * ?array items - */ -function tree(): Tree -{ - return createWg('tree', func_get_args()); -} - -/** - * Zentao tree editor widget. - * - * ?array items - */ -function treeEditor(): TreeEditor -{ - return createWg('treeEditor', func_get_args()); -} - -/** - * Zentao file list widget. - * - * ?array files - * ?int objectID - * ?string objectType - */ -function fileList(): fileList -{ - return createWg('fileList', func_get_args()); -} - -/** - * Zentao history records widget. - * - * ?array actions - * ?array users - * ?string methodName - * ?bool commentBtn - */ -function history(): history -{ - return createWg('history', func_get_args()); -} - -/** - * Zentao float toolbar widget. - * - * ?array prefix btns props array. - * ?array main btns props array. - * ?array suffix btns props array. - * ?object object - * - * ====== blocks ====== - * dropdowns = array() - * ==================== - */ -function floatToolbar(): floatToolbar -{ - return createWg('floatToolbar', func_get_args()); -} - -/** - * Zentao customize form item dropdown. - * - * ?string method - * ?string url - * ?array actions - * ?string target - * ?array items - * ?array value - */ -function formItemDropdown(): formItemDropdown -{ - return createWg('formItemDropdown', func_get_args()); -} - -/** - * Zentao editor wg. - * - * ?bool createInput=false - * ?string uploadUrl='' - * ?string placeholder='' - * ?bool fullscreenable=false - * ?bool resizable=false - * ?bool exposeEditor=true - * ?string size='sm' - * ?bool hideMenubar=false - * ?bool bubbleMenu=false - */ -function editor(): editor -{ - return createWg('editor', func_get_args()); -} - -/** - * Zentao comment button wg. - * - * ?string dataTarget - * ?string dataUrl - * ?string dataType - * ?string icon - * ?string text - * ?bool square - * ?bool disabled - * ?bool active - * ?string url - * ?string target - * ?string trailingIcon - * ?string hint - * ?string type - * ?string btnType - * string|int|null size - * string|bool|null caret - */ -function commentBtn(): commentBtn -{ - return createWg('commentBtn', func_get_args()); -} - -/** - * - * Zentao comment dialog wg. - * - * ?string title, - * ?string url - * ?string name='comment' - * ?string method='POST' - */ -function commentDialog(): commentDialog -{ - return createWg('commentDialog', func_get_args()); -} - -/** - * Zentao comment form wg. - * - * ?string url - * ?string name='comment' - * ?string method='POST' - */ -function commentForm(): commentForm -{ - return createWg('commentForm', func_get_args()); -} - -/** - * Zentao priority number wg. - * - * int pri - */ -function priLabel(): priLabel -{ - return createWg('priLabel', func_get_args()); -} - -/** - * Zentao risk label wg. - * - * ?string text - * ?string level 'h'|'m'|'l' - */ -function riskLabel(): riskLabel -{ - return createWg('riskLabel', func_get_args()); -} - -/** - * Zentao severity label wg. - * - * ?string text - * ?int|string level 1|2|3|4 - */ -function severityLabel(): severityLabel -{ - return createWg('severityLabel', func_get_args()); -} - -/** - * Zentao dashboard widget. - * - * ?bool responsive 是否启用响应式。 - * array blocks 区块列表。 - * ?int grid 栅格数。 - * ?int gap 间距。 - * ?int leftStop 区块水平停靠间隔。 - * ?int cellHeight 网格高度。 - * ?stringunction|array blockFetch 区块数据获取 url 或选项。 - * ?array blockDefaultSize 区块默认大小。 - * array blockSizeMap 区块大小映射。 - * ?array blockMenu 区块菜单。 - * ?function onLayoutChange 布局变更事件。 - */ -function dashboard(): dashboard -{ - return createWg('dashboard', func_get_args()); -} - -/** - * Dashboard panel widget. - */ -function blockPanel(): blockPanel -{ - return createWg('blockPanel', func_get_args()); -} - -/** - * Zentao detail page section widget. - * - * string title - * string|array|null content - * ?bool useHtml=false - * - * ====== blocks ====== - * subTitle => array() - * actions => array() - * ==================== - */ -function section(): section -{ - return createWg('section', func_get_args()); -} - -/** - * Zentao detail page section card widget. - * - * ====== blocks ====== - * title => array('map' => 'entityLabel') - * ==================== - */ -function sectionCard(): sectionCard -{ - return createWg('sectionCard', func_get_args()); -} - -/** - * Zentao detail page section list widget. - */ -function sectionList(): sectionList -{ - return createWg('sectionList', func_get_args()); -} - -/** - * Zentao entity label widget. - * - * string|int|null entityID - * string|int|null level - * string text - * - * ====== blocks ====== - * suffix = array() - * ==================== - */ -function entityLabel(): entityLabel -{ - return createWg('entityLabel',func_get_args()); -} - -/** - * Zentao table data widget. - */ -function tableData(): tableData -{ - return createWg('tableData',func_get_args()); -} - -/** - * Zentao detail page header widget. - * - * ====== blocks ====== - * prefix => array() - * title => array() - * suffix => array() - * ==================== - */ -function detailHeader(): detailHeader -{ - return createWg('detailHeader', func_get_args()); -} - -/** - * Zentao detail page side widget. - */ -function detailSide(): detailSide -{ - return createWg('detailSide', func_get_args()); -} - -/** - * Zentao detail page body widget. - */ -function detailBody(): detailBody -{ - return createWg('detailBody', func_get_args()); -} - -/** - * ECharts widget. - */ -function echarts(): echarts -{ - return createWg('echarts', func_get_args()); -} - -/** - * Popovers widget. - * - * ?string placement='bottom' - * ?string strategy='fixed' - * ?bool flip=true - * ?array|bool shift=array('padding' => 5) - * ?bool arrow=false - * ?int offset=1 - * - * ====== blocks ====== - * trigger = array() - * target = array() - * ==================== - */ -function popovers(): popovers -{ - return createWg('popovers', func_get_args()); -} - -/** - * Back btn widget. - * - * ?string back - */ -function backBtn(): backBtn -{ - return createWg('backBtn', func_get_args()); -} - -/** - * Collapse btn widget. - * - * string target - * string parent - */ -function collapseBtn(): collapseBtn -{ - return createWg('collapseBtn', func_get_args()); -} - -/** - * Main navbar widget. - * - * ?array items - */ -function mainNavbar(): mainNavbar -{ - return createWg('mainNavbar', func_get_args()); -} - -/** - * Zentao float Pre and Next Button widget. - * - * ?string preLink link of pre-button. - * ?string nextLink link of next-button. - */ -function floatPreNextBtn(): floatPreNextBtn -{ - return createWg('floatPreNextBtn', func_get_args()); -} - -/** - * The zui file selector widget. - */ -function fileSelector(): fileSelector -{ - return createWg('fileSelector', func_get_args()); -} - -/** - * The zui file selector widget. - */ -function imageSelector(): imageSelector -{ - return createWg('imageSelector', func_get_args()); -} - -/** - * Upload widget. - * - * string name - * ?string icon - * ?bool showIcon=true - * ?bool showSize=true - * ?bool multiple=true - * ?string listPosition="bottom" - * ?string uploadText - * ?string uploadIcon - * ?bool renameBtn=true - * ?string renameIcon - * ?string renameText - * ?string renameClass - * ?bool deleteBtn=true - * ?string deleteText - * ?string deleteIcon - * ?string deleteClass - * ?string confirmText - * ?string cancelText - * ?bool useIconBtn=true - * ?string tip - * ?string btnClass - * ?callable onAdd - * ?callable onDelete - * ?callable onRename - * ?callable onSizeChange - * ?bool draggable - * ?int limitCount - * ?string accept - * ?object[] defaultFileList - * false|string|null limitSize=false - * ?string duplicatedHint - * ?string exceededSizeHint - * ?string exceededCountHint - * @deprecated use "fileSelector" instead. - */ -function upload(): upload -{ - return createWg('upload', func_get_args()); -} - -/** - * Upload images widget. - * - * string name - * ?bool showSize=true - * ?bool multiple=true - * ?string uploadText - * ?string uploadIcon - * ?bool renameBtn=true - * ?string renameIcon - * ?string renameText - * ?string renameClass - * ?bool deleteBtn=true - * ?string deleteIcon - * ?string deleteText - * ?string deleteClass - * ?string tip - * ?string btnClass - * ?callable onAdd - * ?callable onDelete - * ?callable onRename - * ?callable onSizeChange - * ?int limitCount - * ?string accept - * ?object[] defaultFileList - * false|string|null limitSize=false - * ?string duplicatedHint - * ?string exceededSizeHint - * ?string exceededCountHint - * ?string totalCountText - * @deprecated use "imageSelector" instead. - */ -function uploadImgs(): uploadImgs -{ - return createWg('uploadImgs', func_get_args()); -} - -/** - * Burn widget. - * - * ?string|array data - * ?bool referenceLine - */ -function burn(): burn -{ - return createWg('burn', func_get_args()); -} - -/** - * Monaco widget. - * - * string id - * ?string action - * ?string options - * ?string diffContent - * ?string onMouseDown - */ -function monaco(): monaco -{ - return createWg('monaco', func_get_args()); -} - -/** - * Dynamic widget. - * - * ?array dynamics - * ?array users - * ?string className - */ -function dynamic(): dynamic -{ - return createWg('dynamic', func_get_args()); -} - -/** - * Form setting button. - * - * ?array customFields - * ?string urlParams - */ -function formSettingBtn(): formSettingBtn -{ - return createWg('formSettingBtn', func_get_args()); -} - -/** - * Overview block widget. - * - * string id - * string title - */ -function overviewBlock(): overviewBlock -{ - return createWg('overviewBlock', func_get_args()); -} - -/** - * Statistic block widget. - * - */ -function statisticBlock(): statisticBlock -{ - return createWg('statisticBlock', func_get_args()); -} - -/** - * Picker widget. - */ -function picker(): picker -{ - return createWg('picker', func_get_args()); -} - -/** - * Pri picker widget. - * - * ?string placeholder - * ?string[]|object[]|object|array items - */ -function priPicker(): priPicker -{ - return createWg('priPicker', func_get_args()); -} - -/** - * Severity picker widget. - * - * ?string placeholder - * ?string[]|object[]|object|array items - */ -function severityPicker(): severityPicker -{ - return createWg('severityPicker', func_get_args()); -} - -function hr(): hr -{ - return createWg('hr', func_get_args()); -} - -/** - * Global search widget. - * - * string commonSearchText - * string commonSearchUrl - * array searchItems - */ -function globalSearch(): globalSearch -{ - return createWg('globalSearch', func_get_args()); -} - -/** - * Steps editor widget. - */ -function stepsEditor(): stepsEditor -{ - return createWg('stepsEditor', func_get_args()); -} - -/** - * table and chart widget. - */ -function tableChart(): tableChart -{ - return createWg('tableChart', func_get_args()); -} - -/** - * Password widget. - */ -function password(): password -{ - return createWg('password', func_get_args()); -} - -/** - * Mindmap widget. - */ -function mindmap(): mindmap -{ - return createWg('mindmap', func_get_args()); -} - -/** - * Treemap widget. - */ -function treemap(): treemap -{ - return createWg('treemap', func_get_args()); -} - -/** - * Image cutter widget. - */ -function imgCutter(): imgCutter -{ - return createWg('imgCutter', func_get_args()); -} - -/** - * Next step modal widget. - * - * string tip - * array items - */ -function modalNextStep(): modalNextStep -{ - return createWg('modalNextStep', func_get_args()); -} - -/** - * Navigator widget. - */ -function navigator(): navigator -{ - return createWg('navigator', func_get_args()); -} - -/** - * Gantt widget. - */ -function gantt(): gantt -{ - return createWg('gantt', func_get_args()); -} - -/** - * road map widget. - */ -function roadMap(): roadMap -{ - return createWg('roadmap', func_get_args()); -} - -/** - * Progress bar widget. - */ -function progressBar(): progressBar -{ - return createWg('progressBar', func_get_args()); -} - -/** - * Progress circle widget. - */ -function progressCircle(): progressCircle -{ - return createWg('progressCircle', func_get_args()); -} - -/** - * Filter widget. - */ -function filter(): filter -{ - return createWg('filter', func_get_args()); -} - -/** - * Result filter widget. - */ -function resultFilter(): resultFilter -{ - return createWg('resultFilter', func_get_args()); -} - -/** - * Contact list widget. - */ -function contactList(): contactList -{ - return createWg('contactList', func_get_args()); -} - -/** - * Users widget. - */ -function users(): users -{ - return createWg('users', func_get_args()); -} - -/** - * Mailto widget. - */ -function mailto(): mailto -{ - return createWg('mailto', func_get_args()); -} - -/** - * whitelist widget. - */ -function whitelist(): whitelist -{ - return createWg('whitelist', func_get_args()); -} - -/** - * modulePicker widget. - */ -function modulePicker(): modulePicker -{ - return createWg('modulePicker', func_get_args()); -} - -/** - * visionSwitcher widget. - */ -function visionSwitcher(): visionSwitcher -{ - return createWg('visionSwitcher', func_get_args()); -} +function input(): input {return createWg('input', func_get_args());} +function textarea(): textarea {return createWg('textarea', func_get_args());} +function radio(): radio {return createWg('radio', func_get_args());} +function switcher(): switcher {return createWg('switcher', func_get_args());} +function checkbox(): checkbox {return createWg('checkbox', func_get_args());} +function checkboxGroup(): checkboxGroup {return createWg('checkboxGroup', func_get_args());} +function formBase(): formBase {return createWg('formBase', func_get_args());} +function form(): form {return createWg('form', func_get_args());} +function formPanel(): formPanel {return createWg('formPanel', func_get_args());} +function formGridPanel(): formGridPanel {return createWg('formGridPanel', func_get_args());} +function formBatch(): formBatch {return createWg('formBatch', func_get_args());} +function formBatchItem(): formBatchItem {return createWg('formBatchItem', func_get_args());} +function formBatchPanel(): formBatchPanel {return createWg('formBatchPanel', func_get_args());} +function batchActions(): batchActions {return createWg('batchActions', func_get_args());} +function control(): control {return createWg('control', func_get_args());} +function select(): select {return createWg('select', func_get_args());} +function formLabel(): formLabel {return createWg('formLabel', func_get_args());} +function formGroup(): formGroup {return createWg('formGroup', func_get_args());} +function formRow(): formRow {return createWg('formRow', func_get_args());} +function formRowGroup(): formRowGroup {return createWg('formRowGroup', func_get_args());} +function inputControl(): inputControl {return createWg('inputControl', func_get_args());} +function inputGroup(): inputGroup {return createWg('inputGroup', func_get_args());} +function inputGroupAddon(): inputGroupAddon {return createWg('inputGroupAddon', func_get_args());} +function checkList(): checkList {return createWg('checkList', func_get_args());} +function radioList(): radioList {return createWg('radioList', func_get_args());} +function checkBtn(): checkBtn {return createWg('checkBtn', func_get_args());} +function checkBtnGroup(): checkBtnGroup {return createWg('checkBtnGroup', func_get_args());} +function checkColorGroup(): checkColorGroup {return createWg('checkColorGroup', func_get_args());} +function colorPicker(): colorPicker {return createWg('colorPicker', func_get_args());} +function datePicker(): datePicker {return createWg('datePicker', func_get_args());} +function datetimePicker(): datetimePicker {return createWg('datetimePicker', func_get_args());} +function timePicker(): timePicker {return createWg('timePicker', func_get_args());} +function fileInput(): fileInput {return createWg('fileInput', func_get_args());} +function pageForm(): pageForm {return createWg('pageForm', func_get_args());} +function icon(): icon {return createWg('icon', func_get_args());} +function btn(): btn {return createWg('btn', func_get_args());} +function pageBase(): pageBase {return createWg('pageBase', func_get_args());} +function page(): page {return createWg('page', func_get_args());} +function fragment(): fragment {return createWg('fragment', func_get_args());} +function btnGroup(): btnGroup {return createWg('btnGroup', func_get_args());} +function mainMenu(): mainMenu {return createWg('mainMenu', func_get_args());} +function row(): row {return createWg('row', func_get_args());} +function col(): col {return createWg('col', func_get_args());} +function center(): center {return createWg('center', func_get_args());} +function cell(): cell {return createWg('cell', func_get_args());} +function divider(): divider {return createWg('divider', func_get_args());} +function actionItem(): actionItem {return createWg('actionItem', func_get_args());} +function nav(): nav {return createWg('nav', func_get_args());} +function label(): label {return createWg('label', func_get_args());} +function dtable(): dtable {return createWg('dtable', func_get_args());} +function menu(): menu {return createWg('menu', func_get_args());} +function dropdown(): dropdown {return createWg('dropdown', func_get_args());} +function header(): header {return createWg('header', func_get_args());} +function heading(): heading {return createWg('heading', func_get_args());} +function navbar(): navbar {return createWg('navbar', func_get_args());} +function dropmenu(): dropmenu {return createWg('dropmenu', func_get_args());} +function main(): main {return createWg('main', func_get_args());} +function sidebar(): sidebar {return createWg('sidebar', func_get_args());} +function featureBar(): featureBar {return createWg('featureBar', func_get_args());} +function avatar(): avatar {return createWg('avatar', func_get_args());} +function userAvatar(): userAvatar {return createWg('userAvatar', func_get_args());} +function pager(): pager {return createWg('pager', func_get_args());} +function modal(): modal {return createWg('modal', func_get_args());} +function modalTrigger(): modalTrigger {return createWg('modalTrigger', func_get_args());} +function modalHeader(): modalHeader {return createWg('modalHeader', func_get_args());} +function modalDialog(): modalDialog {return createWg('modalDialog', func_get_args());} +function tabs(): tabs {return createWg('tabs', func_get_args());} +function tabPane(): tabPane {return createWg('tabPane', func_get_args());} +function panel(): panel {return createWg('panel', func_get_args());} +function pasteDialog(): pasteDialog {return createWg('pasteDialog', func_get_args());} +function tooltip(): tooltip {return createWg('tooltip', func_get_args());} +function toolbar(): toolbar {return createWg('toolbar', func_get_args());} +function searchToggle(): searchToggle {return createWg('searchToggle', func_get_args());} +function searchForm(): searchForm {return createWg('searchForm', func_get_args());} +function programMenu(): programMenu {return createWg('programMenu', func_get_args());} +function productMenu(): productMenu {return createWg('productMenu', func_get_args());} +function moduleMenu(): moduleMenu {return createWg('moduleMenu', func_get_args());} +function docMenu(): docMenu {return createWg('docMenu', func_get_args());} +function tree(): Tree {return createWg('tree', func_get_args());} +function treeEditor(): TreeEditor {return createWg('treeEditor', func_get_args());} +function fileList(): fileList {return createWg('fileList', func_get_args());} +function history(): history {return createWg('history', func_get_args());} +function floatToolbar(): floatToolbar {return createWg('floatToolbar', func_get_args());} +function formItemDropdown(): formItemDropdown {return createWg('formItemDropdown', func_get_args());} +function editor(): editor {return createWg('editor', func_get_args());} +function commentBtn(): commentBtn {return createWg('commentBtn', func_get_args());} +function commentDialog(): commentDialog {return createWg('commentDialog', func_get_args());} +function commentForm(): commentForm {return createWg('commentForm', func_get_args());} +function priLabel(): priLabel {return createWg('priLabel', func_get_args());} +function riskLabel(): riskLabel {return createWg('riskLabel', func_get_args());} +function severityLabel(): severityLabel {return createWg('severityLabel', func_get_args());} +function dashboard(): dashboard {return createWg('dashboard', func_get_args());} +function blockPanel(): blockPanel {return createWg('blockPanel', func_get_args());} +function section(): section {return createWg('section', func_get_args());} +function sectionCard(): sectionCard {return createWg('sectionCard', func_get_args());} +function sectionList(): sectionList {return createWg('sectionList', func_get_args());} +function entityLabel(): entityLabel {return createWg('entityLabel',func_get_args());} +function tableData(): tableData {return createWg('tableData',func_get_args());} +function detailHeader(): detailHeader {return createWg('detailHeader', func_get_args());} +function detailSide(): detailSide {return createWg('detailSide', func_get_args());} +function detailBody(): detailBody {return createWg('detailBody', func_get_args());} +function echarts(): echarts {return createWg('echarts', func_get_args());} +function popovers(): popovers {return createWg('popovers', func_get_args());} +function backBtn(): backBtn {return createWg('backBtn', func_get_args());} +function collapseBtn(): collapseBtn {return createWg('collapseBtn', func_get_args());} +function mainNavbar(): mainNavbar {return createWg('mainNavbar', func_get_args());} +function floatPreNextBtn(): floatPreNextBtn {return createWg('floatPreNextBtn', func_get_args());} +function fileSelector(): fileSelector {return createWg('fileSelector', func_get_args());} +function imageSelector(): imageSelector {return createWg('imageSelector', func_get_args());} +function upload(): upload {return createWg('upload', func_get_args());} +function uploadImgs(): uploadImgs {return createWg('uploadImgs', func_get_args());} +function burn(): burn {return createWg('burn', func_get_args());} +function monaco(): monaco {return createWg('monaco', func_get_args());} +function dynamic(): dynamic {return createWg('dynamic', func_get_args());} +function formSettingBtn(): formSettingBtn {return createWg('formSettingBtn', func_get_args());} +function overviewBlock(): overviewBlock {return createWg('overviewBlock', func_get_args());} +function statisticBlock(): statisticBlock {return createWg('statisticBlock', func_get_args());} +function picker(): picker {return createWg('picker', func_get_args());} +function priPicker(): priPicker {return createWg('priPicker', func_get_args());} +function severityPicker(): severityPicker {return createWg('severityPicker', func_get_args());} +function hr(): hr {return createWg('hr', func_get_args());} +function globalSearch(): globalSearch {return createWg('globalSearch', func_get_args());} +function stepsEditor(): stepsEditor {return createWg('stepsEditor', func_get_args());} +function tableChart(): tableChart {return createWg('tableChart', func_get_args());} +function password(): password {return createWg('password', func_get_args());} +function mindmap(): mindmap {return createWg('mindmap', func_get_args());} +function treemap(): treemap {return createWg('treemap', func_get_args());} +function imgCutter(): imgCutter {return createWg('imgCutter', func_get_args());} +function modalNextStep(): modalNextStep {return createWg('modalNextStep', func_get_args());} +function navigator(): navigator {return createWg('navigator', func_get_args());} +function gantt(): gantt {return createWg('gantt', func_get_args());} +function roadMap(): roadMap {return createWg('roadmap', func_get_args());} +function progressBar(): progressBar {return createWg('progressBar', func_get_args());} +function progressCircle(): progressCircle {return createWg('progressCircle', func_get_args());} +function filter(): filter {return createWg('filter', func_get_args());} +function resultFilter(): resultFilter {return createWg('resultFilter', func_get_args());} +function contactList(): contactList {return createWg('contactList', func_get_args());} +function users(): users {return createWg('users', func_get_args());} +function mailto(): mailto {return createWg('mailto', func_get_args());} +function whitelist(): whitelist {return createWg('whitelist', func_get_args());} +function modulePicker(): modulePicker {return createWg('modulePicker', func_get_args());} +function visionSwitcher(): visionSwitcher {return createWg('visionSwitcher', func_get_args());} diff --git a/lib/zin/wg/aclbox/v1.php b/lib/zin/wg/aclbox/v1.php index 32e21d7143..d896d80173 100644 --- a/lib/zin/wg/aclbox/v1.php +++ b/lib/zin/wg/aclbox/v1.php @@ -18,12 +18,12 @@ class aclBox extends wg 'userValue?: string=""', // 用户组默认选中值。 ); - public static function getPageCSS(): string|false + public static function getPageCSS(): ?string { return file_get_contents(__DIR__ . DS . 'css' . DS . 'v1.css'); } - protected function build(): wg + protected function build() { list($aclItems, $aclValue, $whitelistLabel, $groupLabel, $userLabel, $groupName, $userName, $groupItems, $groupValue, $userValue) = $this->prop(array('aclItems', 'aclValue', 'whitelistLabel', 'groupLabel', 'userLabel', 'groupName', 'userName', 'groupItems', 'groupValue', 'userValue')); diff --git a/lib/zin/wg/actionitem/v1.php b/lib/zin/wg/actionitem/v1.php index 7d091d409a..92bee8a6b6 100644 --- a/lib/zin/wg/actionitem/v1.php +++ b/lib/zin/wg/actionitem/v1.php @@ -126,7 +126,7 @@ class actionItem extends wg ); } - protected function build(): wg + protected function build() { list($name, $type, $outerTag, $outerProps, $outerClass) = $this->prop(array('name', 'type', 'outerTag', 'outerProps', 'outerClass')); diff --git a/lib/zin/wg/avatar/v1.php b/lib/zin/wg/avatar/v1.php index 4a2a1a746d..ace7e263e7 100644 --- a/lib/zin/wg/avatar/v1.php +++ b/lib/zin/wg/avatar/v1.php @@ -38,7 +38,7 @@ class avatar extends wg return $child; } - protected function build(): wg + protected function build() { /* Attach classes. */ $this->finalClass[] = $this->prop('className'); diff --git a/lib/zin/wg/batchactions/v1.php b/lib/zin/wg/batchactions/v1.php index f694ea21fb..2884fe6cc4 100644 --- a/lib/zin/wg/batchactions/v1.php +++ b/lib/zin/wg/batchactions/v1.php @@ -8,12 +8,12 @@ class batchActions extends wg 'actionClass?: string=""', ); - public static function getPageJS(): string|false + public static function getPageJS(): ?string { return file_get_contents(__DIR__ . DS . 'js' . DS . 'v1.js'); } - protected function build(): wg + protected function build() { return formGroup ( diff --git a/lib/zin/wg/btn/v1.php b/lib/zin/wg/btn/v1.php index a8b33bd05d..3cb0b7bb64 100644 --- a/lib/zin/wg/btn/v1.php +++ b/lib/zin/wg/btn/v1.php @@ -90,7 +90,7 @@ class btn extends wg return $classList; } - protected function build(): wg + protected function build() { $props = $this->getProps(); $children = $this->getChildren(); diff --git a/lib/zin/wg/btngroup/v1.php b/lib/zin/wg/btngroup/v1.php index a627d24b76..941f04292f 100644 --- a/lib/zin/wg/btngroup/v1.php +++ b/lib/zin/wg/btngroup/v1.php @@ -28,7 +28,7 @@ class btnGroup extends wg return $className; } - protected function build(): wg + protected function build() { $items = $this->prop('items'); $className = $this->getclassName(); diff --git a/lib/zin/wg/cell/v1.php b/lib/zin/wg/cell/v1.php index 3914ea6ee1..bb1657d5c7 100644 --- a/lib/zin/wg/cell/v1.php +++ b/lib/zin/wg/cell/v1.php @@ -13,7 +13,7 @@ class cell extends wg 'align?: string' // align-self 属性,例如 'auto'、'flex-start'、'flex-end'、'center'、'baseline'、'stretch'。 ); - protected function build(): wg + protected function build() { $basis = null; $class = array('cell'); diff --git a/lib/zin/wg/center/v1.php b/lib/zin/wg/center/v1.php index fae71036c2..53cf871786 100644 --- a/lib/zin/wg/center/v1.php +++ b/lib/zin/wg/center/v1.php @@ -4,7 +4,7 @@ namespace zin; class center extends wg { - protected function build(): wg + protected function build() { return div ( diff --git a/lib/zin/wg/checkbox/v1.php b/lib/zin/wg/checkbox/v1.php index 1ed12842e7..a9fdc137f3 100644 --- a/lib/zin/wg/checkbox/v1.php +++ b/lib/zin/wg/checkbox/v1.php @@ -55,7 +55,7 @@ class checkbox extends wg ); } - protected function build(): wg + protected function build() { if($this->prop('primary')) return $this->buildPrimary(); list($text, $type, $typeClass) = $this->prop(array('text', 'type', 'typeClass')); diff --git a/lib/zin/wg/checkboxgroup/v1.php b/lib/zin/wg/checkboxgroup/v1.php index 1d209b0c95..98c2f8c047 100644 --- a/lib/zin/wg/checkboxgroup/v1.php +++ b/lib/zin/wg/checkboxgroup/v1.php @@ -14,12 +14,12 @@ class checkboxGroup extends wg 'disabled' => false ); - public static function getPageCSS(): string|false + public static function getPageCSS(): ?string { return file_get_contents(__DIR__ . DS . 'css' . DS . 'v1.css'); } - public static function getPageJS(): string|false + public static function getPageJS(): ?string { return file_get_contents(__DIR__ . DS . 'js' . DS . 'v1.js'); } @@ -30,7 +30,7 @@ class checkboxGroup extends wg return checkbox(set($title), setClass('checkbox-title')); } - private function buildCheckboxList(): wg + private function buildCheckboxList(): node { $items = $this->prop('items'); $title = array_merge(self::$checkboxProps, $this->prop('title')); @@ -52,7 +52,7 @@ class checkboxGroup extends wg return $list; } - public function build(): wg + public function build() { return div ( diff --git a/lib/zin/wg/checkbtn/v1.php b/lib/zin/wg/checkbtn/v1.php index a50749ba32..46b7016f7d 100644 --- a/lib/zin/wg/checkbtn/v1.php +++ b/lib/zin/wg/checkbtn/v1.php @@ -6,7 +6,7 @@ require_once dirname(__DIR__) . DS . 'checkbox' . DS . 'v1.php'; class checkBtn extends checkbox { - public static function getPageCSS(): string|false + public static function getPageCSS(): ?string { return << input + label {color: var(--color-gray-500)} diff --git a/lib/zin/wg/checkbtngroup/v1.php b/lib/zin/wg/checkbtngroup/v1.php index 9a6279dd76..3a9faecd0c 100644 --- a/lib/zin/wg/checkbtngroup/v1.php +++ b/lib/zin/wg/checkbtngroup/v1.php @@ -13,7 +13,7 @@ class checkBtnGroup extends checkList 'type' => 'radio' ); - public static function getPageCSS(): string|false + public static function getPageCSS(): ?string { return <<add(setClass('check-btn-group')); diff --git a/lib/zin/wg/checkcolorgroup/v1.php b/lib/zin/wg/checkcolorgroup/v1.php index 53c866e480..da99a174ed 100644 --- a/lib/zin/wg/checkcolorgroup/v1.php +++ b/lib/zin/wg/checkcolorgroup/v1.php @@ -6,7 +6,7 @@ require_once dirname(__DIR__) . DS . 'checkbtngroup' . DS . 'v1.php'; class checkColorGroup extends checkBtnGroup { - public static function getPageCSS(): string|false + public static function getPageCSS(): ?string { return <<prop(array('items', 'inline', 'disabled', 'className')); diff --git a/lib/zin/wg/col/v1.php b/lib/zin/wg/col/v1.php index cfa83ee973..d7fd49e6a7 100644 --- a/lib/zin/wg/col/v1.php +++ b/lib/zin/wg/col/v1.php @@ -9,7 +9,7 @@ class col extends wg 'align?:string' ); - protected function build(): wg + protected function build() { $classList = 'col'; list($justify, $align) = $this->prop(array('justify', 'align')); diff --git a/lib/zin/wg/collapsebtn/v1.php b/lib/zin/wg/collapsebtn/v1.php index 9d5b3665cb..e4829431c5 100644 --- a/lib/zin/wg/collapsebtn/v1.php +++ b/lib/zin/wg/collapsebtn/v1.php @@ -11,7 +11,7 @@ class collapseBtn extends wg 'parent: string' // 目标元素与按钮共同的父级元素选择器,使用 closest 辅助目标元素的确定。 ); - protected function build(): wg + protected function build() { $target = $this->prop('target'); $parent = $this->prop('parent'); diff --git a/lib/zin/wg/colorinput/v1.php b/lib/zin/wg/colorinput/v1.php index ff9de94f24..40cb8b5c77 100644 --- a/lib/zin/wg/colorinput/v1.php +++ b/lib/zin/wg/colorinput/v1.php @@ -44,7 +44,7 @@ class colorInput extends inputControl * * @access protected */ - protected function build(): wg + protected function build() { list($id, $name, $value, $inputClass, $colorName, $colorValue, $syncColor) = $this->prop(array('id', 'name', 'value', 'inputClass', 'colorName', 'colorValue', 'syncColor')); diff --git a/lib/zin/wg/colorpicker/v1.php b/lib/zin/wg/colorpicker/v1.php index 16bd704334..811a91ff22 100644 --- a/lib/zin/wg/colorpicker/v1.php +++ b/lib/zin/wg/colorpicker/v1.php @@ -57,7 +57,7 @@ class colorPicker extends wg * * @access protected */ - protected function build(): wg + protected function build() { list($props, $restProps) = $this->props->split(array_keys(static::definedPropsList())); if(isset($props['id'])) diff --git a/lib/zin/wg/commentdialog/v1.php b/lib/zin/wg/commentdialog/v1.php index 5da51b4ac6..3ed92cf2ef 100644 --- a/lib/zin/wg/commentdialog/v1.php +++ b/lib/zin/wg/commentdialog/v1.php @@ -13,7 +13,7 @@ class commentDialog extends wg 'load?: bool|string' ); - protected function build(): wg + protected function build() { global $lang; $id = $this->prop('id'); diff --git a/lib/zin/wg/commentform/v1.php b/lib/zin/wg/commentform/v1.php index cbfbb9355a..d8c5532db7 100644 --- a/lib/zin/wg/commentform/v1.php +++ b/lib/zin/wg/commentform/v1.php @@ -12,7 +12,7 @@ class commentForm extends wg 'method?:string="POST"' ); - protected function build(): wg + protected function build() { global $lang; $url = $this->prop('url'); diff --git a/lib/zin/wg/contactlist/v1.php b/lib/zin/wg/contactlist/v1.php index 5ab8297238..537c5eff43 100644 --- a/lib/zin/wg/contactlist/v1.php +++ b/lib/zin/wg/contactlist/v1.php @@ -20,7 +20,7 @@ class contactList extends wg 'placeholder?: string', // picker 占位符。 ); - public static function getPageJS(): string|false + public static function getPageJS(): ?string { return file_get_contents(__DIR__ . DS . 'js' . DS . 'v1.js'); } @@ -45,7 +45,7 @@ class contactList extends wg } } - protected function build(): wg|array + protected function build() { global $app, $lang; $app->loadLang('user'); diff --git a/lib/zin/wg/control/v1.php b/lib/zin/wg/control/v1.php index 1783b5bebc..ba6ccddbd6 100644 --- a/lib/zin/wg/control/v1.php +++ b/lib/zin/wg/control/v1.php @@ -218,7 +218,7 @@ class control extends wg return new dropdown($this->prop('text'), set($this->props->skip('control,text,name,widget'))); } - protected function build(): wg + protected function build() { $builder = $this->prop('builder'); if(is_callable($builder)) return $builder($this->props->skip('builder'), $this->children()); diff --git a/lib/zin/wg/dashboard/v1.php b/lib/zin/wg/dashboard/v1.php index 67a726409b..c8a5648450 100644 --- a/lib/zin/wg/dashboard/v1.php +++ b/lib/zin/wg/dashboard/v1.php @@ -55,7 +55,7 @@ class dashboard extends wg /** * Build widget. */ - protected function build(): wg + protected function build() { return zui::dashboard ( diff --git a/lib/zin/wg/datepicker/v1.php b/lib/zin/wg/datepicker/v1.php index 33e223437c..95ee7c528a 100644 --- a/lib/zin/wg/datepicker/v1.php +++ b/lib/zin/wg/datepicker/v1.php @@ -65,7 +65,7 @@ class datePicker extends wg * @access protected * @return wg */ - protected function build(): wg + protected function build() { list($props, $restProps) = $this->props->split(array_keys(static::definedPropsList())); if(isset($props['id'])) diff --git a/lib/zin/wg/daterangepicker/v1.php b/lib/zin/wg/daterangepicker/v1.php index 6053e84d75..4dfb47453a 100644 --- a/lib/zin/wg/daterangepicker/v1.php +++ b/lib/zin/wg/daterangepicker/v1.php @@ -112,7 +112,7 @@ class dateRangePicker extends wg * @access protected * @return wg */ - protected function build(): wg + protected function build() { $begin = new datePicker(set($this->buildBeginProps())); $end = new datePicker(set($this->buildEndProps())); diff --git a/lib/zin/wg/datetimepicker/v1.php b/lib/zin/wg/datetimepicker/v1.php index 6078c5553b..1e8653d8f3 100644 --- a/lib/zin/wg/datetimepicker/v1.php +++ b/lib/zin/wg/datetimepicker/v1.php @@ -54,7 +54,7 @@ class datetimePicker extends wg * @access protected * @return wg */ - protected function build(): wg + protected function build() { list($props, $restProps) = $this->props->split(array_keys(static::definedPropsList())); if(isset($props['id'])) diff --git a/lib/zin/wg/detailbody/v1.php b/lib/zin/wg/detailbody/v1.php index f5b7ddd56f..e2450c026e 100644 --- a/lib/zin/wg/detailbody/v1.php +++ b/lib/zin/wg/detailbody/v1.php @@ -15,17 +15,17 @@ class detailBody extends wg 'floating' => array('map' => 'floatToolbar') ); - public static function getPageCSS(): string|false + public static function getPageCSS(): ?string { return file_get_contents(__DIR__ . DS . 'css' . DS . 'v1.css'); } - public static function getPageJS(): string|false + public static function getPageJS(): ?string { return file_get_contents(__DIR__ . DS . 'js' . DS . 'v1.js'); } - protected function build(): wg + protected function build() { $main = $this->block('main'); $side = $this->block('side'); diff --git a/lib/zin/wg/detailheader/v1.php b/lib/zin/wg/detailheader/v1.php index dffe6d0a34..35b2cd37a5 100644 --- a/lib/zin/wg/detailheader/v1.php +++ b/lib/zin/wg/detailheader/v1.php @@ -28,7 +28,7 @@ class detailHeader extends wg ); } - protected function build(): wg + protected function build() { $prefix = $this->block('prefix'); $title = $this->block('title'); diff --git a/lib/zin/wg/detailside/v1.php b/lib/zin/wg/detailside/v1.php index 2886a09d8a..e13395eea4 100644 --- a/lib/zin/wg/detailside/v1.php +++ b/lib/zin/wg/detailside/v1.php @@ -4,7 +4,7 @@ namespace zin; class detailSide extends wg { - public static function getPageCSS(): string|false + public static function getPageCSS(): ?string { return <<prop('users', (array)data('users')); $dynamics = $this->prop('dynamics', (array)data('dynamics')); diff --git a/lib/zin/wg/editor/v1.php b/lib/zin/wg/editor/v1.php index 021e506b34..3033540923 100644 --- a/lib/zin/wg/editor/v1.php +++ b/lib/zin/wg/editor/v1.php @@ -33,12 +33,12 @@ class editor extends wg .tippy-content zen-editor-menu-item .label {all: unset;} CSS; - public static function getPageCSS(): string|false + public static function getPageCSS(): ?string { return file_get_contents(__DIR__ . DS . 'css' . DS . 'v1.css'); } - public static function getPageJS(): string|false + public static function getPageJS(): ?string { $content = file_get_contents(__DIR__ . DS . 'js' . DS . 'v1.js'); $content .= '$.getLib(\'zen-editor/zen-editor.esm.js\', {type: "module"}, () => {document.body.dataset.loadedEditor = true;});'; @@ -75,7 +75,7 @@ class editor extends wg ); } - protected function build(): wg + protected function build() { global $lang; diff --git a/lib/zin/wg/entitylabel/v1.php b/lib/zin/wg/entitylabel/v1.php index 89a0e26d0d..08236ebf50 100644 --- a/lib/zin/wg/entitylabel/v1.php +++ b/lib/zin/wg/entitylabel/v1.php @@ -23,7 +23,7 @@ class entityLabel extends wg 'suffix' => array() ); - public static function getPageCSS(): string|false + public static function getPageCSS(): ?string { return file_get_contents(__DIR__ . DS . 'css' . DS . 'v1.css'); } @@ -86,7 +86,7 @@ class entityLabel extends wg ); } - protected function build(): wg + protected function build() { $reverse = $this->prop('reverse'); $prefix = $this->block('prefix'); diff --git a/lib/zin/wg/featurebar/v1.php b/lib/zin/wg/featurebar/v1.php index 9b82d2f95c..cdc08095d2 100644 --- a/lib/zin/wg/featurebar/v1.php +++ b/lib/zin/wg/featurebar/v1.php @@ -143,7 +143,7 @@ class featureBar extends wg ); } - protected function build(): wg + protected function build() { return div ( diff --git a/lib/zin/wg/filelist/v1.php b/lib/zin/wg/filelist/v1.php index 299bca3fc3..1d6be30fea 100644 --- a/lib/zin/wg/filelist/v1.php +++ b/lib/zin/wg/filelist/v1.php @@ -16,12 +16,12 @@ class fileList extends wg 'padding?:bool=true' ); - public static function getPageCSS(): string|false + public static function getPageCSS(): ?string { return file_get_contents(__DIR__ . DS . 'css' . DS . 'v1.css'); } - public static function getPageJS(): string|false + public static function getPageJS(): ?string { return file_get_contents(__DIR__ . DS . 'js' . DS . 'v1.js'); } @@ -47,7 +47,7 @@ class fileList extends wg return $fileListView; } - protected function build(): wg + protected function build() { global $lang; diff --git a/lib/zin/wg/fileselector/v1.php b/lib/zin/wg/fileselector/v1.php index cb1b0da36b..c80aed1e65 100644 --- a/lib/zin/wg/fileselector/v1.php +++ b/lib/zin/wg/fileselector/v1.php @@ -76,7 +76,7 @@ class fileSelector extends wg * @access protected * @return wg */ - protected function build(): wg + protected function build() { return zui::fileSelector(inherit($this)); } diff --git a/lib/zin/wg/filter/v1.php b/lib/zin/wg/filter/v1.php index a85c94cc1e..6a2e429f94 100644 --- a/lib/zin/wg/filter/v1.php +++ b/lib/zin/wg/filter/v1.php @@ -82,7 +82,7 @@ class filter extends wg return $this->buildInput(); } - protected function build(): wg|array + protected function build() { $type = $this->prop('type'); $class = $this->prop('class', 'w-1/4'); diff --git a/lib/zin/wg/floatprenextbtn/v1.php b/lib/zin/wg/floatprenextbtn/v1.php index 693ccc0af6..c040e95199 100644 --- a/lib/zin/wg/floatprenextbtn/v1.php +++ b/lib/zin/wg/floatprenextbtn/v1.php @@ -9,16 +9,16 @@ class floatPreNextBtn extends wg 'nextLink?:string' ); - public static function getPageCSS(): string|false + public static function getPageCSS(): ?string { return file_get_contents(__DIR__ . DS . 'css' . DS . 'v1.css'); } - public static function getPageJS(): string|false + public static function getPageJS(): ?string { return file_get_contents(__DIR__ . DS . 'js' . DS . 'v1.js'); } - protected function build(): wg|array + protected function build() { global $app; $preLink = $this->prop('preLink'); diff --git a/lib/zin/wg/floattoolbar/v1.php b/lib/zin/wg/floattoolbar/v1.php index 9ec34452fa..ed58fcb791 100644 --- a/lib/zin/wg/floattoolbar/v1.php +++ b/lib/zin/wg/floattoolbar/v1.php @@ -74,7 +74,7 @@ class floatToolbar extends wg return array_merge($btns, $block); } - protected function build(): wg + protected function build() { $prefixBtns = $this->buildBtns($this->prop('prefix')); $mainBtns = $this->buildBtns($this->prop('main')); diff --git a/lib/zin/wg/formbase/v1.php b/lib/zin/wg/formbase/v1.php index 16be88ec1f..a60be1ca6a 100644 --- a/lib/zin/wg/formbase/v1.php +++ b/lib/zin/wg/formbase/v1.php @@ -107,7 +107,7 @@ class formBase extends wg return $after; } - protected function build(): wg + protected function build() { return h::form ( diff --git a/lib/zin/wg/formgroup/v1.php b/lib/zin/wg/formgroup/v1.php index 7419770c63..5b594833de 100644 --- a/lib/zin/wg/formgroup/v1.php +++ b/lib/zin/wg/formgroup/v1.php @@ -136,7 +136,7 @@ class formGroup extends wg ); } - protected function build(): wg|array + protected function build() { list($name, $labelWidth, $required, $width, $id, $hidden, $foldable, $pinned, $children, $wrapBefore, $wrapAfter, $data) = $this->prop(array('name', 'labelWidth', 'required', 'width', 'id', 'hidden', 'foldable', 'pinned', 'children', 'wrapBefore', 'wrapAfter', 'data')); diff --git a/lib/zin/wg/formitemdropdown/v1.php b/lib/zin/wg/formitemdropdown/v1.php index 021eef8152..a18ef95579 100644 --- a/lib/zin/wg/formitemdropdown/v1.php +++ b/lib/zin/wg/formitemdropdown/v1.php @@ -14,7 +14,7 @@ class formItemDropdown extends wg 'target?: string' ); - public static function getPageCSS(): string|false + public static function getPageCSS(): ?string { return file_get_contents(__DIR__ . DS . 'css' . DS . 'v1.css'); } @@ -63,7 +63,7 @@ class formItemDropdown extends wg ); } - protected function build(): wg + protected function build() { return div ( diff --git a/lib/zin/wg/formlabel/v1.php b/lib/zin/wg/formlabel/v1.php index f909704c71..235fdf45f8 100644 --- a/lib/zin/wg/formlabel/v1.php +++ b/lib/zin/wg/formlabel/v1.php @@ -18,7 +18,7 @@ class formLabel extends wg 'checkbox?: bool|array' ); - protected function build(): wg + protected function build() { list($text, $required, $for, $hint, $hintClass, $hintProps, $hintIcon, $actions, $actionsClass, $actionsProps, $checkbox) = $this->prop(array('text', 'required', 'for', 'hint', 'hintClass', 'hintProps', 'hintIcon', 'actions', 'actionsClass', 'actionsProps', 'checkbox')); diff --git a/lib/zin/wg/formpanel/v1.php b/lib/zin/wg/formpanel/v1.php index 4bf4da40ee..3454c62963 100644 --- a/lib/zin/wg/formpanel/v1.php +++ b/lib/zin/wg/formpanel/v1.php @@ -65,7 +65,7 @@ class formPanel extends panel 'customFields?: array=[]' // @deprecated 自定义表单项。 ); - public static function getPageJS(): string|false + public static function getPageJS(): ?string { return file_get_contents(__DIR__ . DS . 'js' . DS . 'v1.js'); } diff --git a/lib/zin/wg/formrow/v1.php b/lib/zin/wg/formrow/v1.php index 7943eabf2a..0c39d119df 100644 --- a/lib/zin/wg/formrow/v1.php +++ b/lib/zin/wg/formrow/v1.php @@ -23,7 +23,7 @@ class formRow extends wg return new formGroup(inherit($item)); } - protected function build(): wg + protected function build() { list($width, $items, $hidden) = $this->prop(['width', 'items', 'hidden']); diff --git a/lib/zin/wg/formrowgroup/v1.php b/lib/zin/wg/formrowgroup/v1.php index e87a3b7b72..0d23f9cf75 100644 --- a/lib/zin/wg/formrowgroup/v1.php +++ b/lib/zin/wg/formrowgroup/v1.php @@ -17,12 +17,12 @@ class formRowGroup extends formRow 'suffix' => array() ); - public static function getPageCSS(): string|false + public static function getPageCSS(): ?string { return file_get_contents(__DIR__ . DS . 'css' . DS . 'v1.css'); } - protected function build(): wg + protected function build() { return formRow ( diff --git a/lib/zin/wg/formsettingbtn/v1.php b/lib/zin/wg/formsettingbtn/v1.php index af793f8dec..e212f7dffc 100644 --- a/lib/zin/wg/formsettingbtn/v1.php +++ b/lib/zin/wg/formsettingbtn/v1.php @@ -19,12 +19,12 @@ class formSettingBtn extends wg 'urlParams' => '' ); - public static function getPageCSS(): string|false + public static function getPageCSS(): ?string { return file_get_contents(__DIR__ . DS . 'css' . DS . 'v1.css'); } - public static function getPageJS(): string|false + public static function getPageJS(): ?string { return file_get_contents(__DIR__ . DS . 'js' . DS . 'v1.js'); } @@ -49,7 +49,7 @@ class formSettingBtn extends wg return $items; } - protected function build(): wg + protected function build() { $customFields = $this->prop('customFields', array()); diff --git a/lib/zin/wg/fragment/v1.php b/lib/zin/wg/fragment/v1.php index ebdfb09f54..c76fbac065 100644 --- a/lib/zin/wg/fragment/v1.php +++ b/lib/zin/wg/fragment/v1.php @@ -13,7 +13,7 @@ class fragment extends wg { $css = array(data('pageCSS'), '/*{{ZIN_PAGE_CSS}}*/'); $js = array('/*{{ZIN_PAGE_JS}}*/', data('pageJS')); - $rawContent = $this->prop('rawContent', !zin::$rawContentCalled); + $rawContent = $this->prop('rawContent', !context()->rawContentCalled); return array ( diff --git a/lib/zin/wg/gantt/v1.php b/lib/zin/wg/gantt/v1.php index 7a980cfc82..92ab7d7cb8 100644 --- a/lib/zin/wg/gantt/v1.php +++ b/lib/zin/wg/gantt/v1.php @@ -9,7 +9,7 @@ class gantt extends wg return file_get_contents(dirname(__DIR__, 4) . '/www/js/dhtmlxgantt/min.css'); } - protected function build(): wg + protected function build() { global $app; $jsFile = $app->getWebRoot() . 'js/dhtmlxgantt/min.js'; diff --git a/lib/zin/wg/globalsearch/v1.php b/lib/zin/wg/globalsearch/v1.php index 166fcff44c..0f35e2ac2d 100644 --- a/lib/zin/wg/globalsearch/v1.php +++ b/lib/zin/wg/globalsearch/v1.php @@ -4,12 +4,12 @@ namespace zin; class globalSearch extends wg { - public static function getPageJS(): string|false + public static function getPageJS(): ?string { return file_get_contents(__DIR__ . DS . 'js' . DS . 'v1.js'); } - protected function build(): wg + protected function build() { global $config, $lang; diff --git a/lib/zin/wg/header/v1.php b/lib/zin/wg/header/v1.php index 913ea97847..baccf53d4f 100644 --- a/lib/zin/wg/header/v1.php +++ b/lib/zin/wg/header/v1.php @@ -64,7 +64,7 @@ class header extends wg * * @access protected */ - protected function build(): wg + protected function build() { return h::header ( diff --git a/lib/zin/wg/heading/v1.php b/lib/zin/wg/heading/v1.php index 5b9b8bbac3..2064b1e2ce 100644 --- a/lib/zin/wg/heading/v1.php +++ b/lib/zin/wg/heading/v1.php @@ -95,7 +95,7 @@ class heading extends wg * * @access protected */ - protected function build(): wg + protected function build() { return div ( diff --git a/lib/zin/wg/hr/v1.php b/lib/zin/wg/hr/v1.php index 9dbf422fc5..7d6aa3d3f7 100644 --- a/lib/zin/wg/hr/v1.php +++ b/lib/zin/wg/hr/v1.php @@ -4,7 +4,7 @@ namespace zin; class hr extends wg { - protected function build(): wg + protected function build() { return h::hr(setClass('my-5')); } diff --git a/lib/zin/wg/icon/v1.php b/lib/zin/wg/icon/v1.php index 7247b0f9c0..2b7ba01a44 100644 --- a/lib/zin/wg/icon/v1.php +++ b/lib/zin/wg/icon/v1.php @@ -18,7 +18,7 @@ class icon extends wg } } - protected function build(): wg + protected function build() { list($name, $size) = $this->prop(array('name', 'size')); return h::i diff --git a/lib/zin/wg/imageselector/v1.php b/lib/zin/wg/imageselector/v1.php index 9aa6472c4d..5b4432bee6 100644 --- a/lib/zin/wg/imageselector/v1.php +++ b/lib/zin/wg/imageselector/v1.php @@ -17,7 +17,7 @@ class imageSelector extends fileSelector * @access protected * @return wg */ - protected function build(): wg + protected function build() { return zui::imageSelector(inherit($this)); } diff --git a/lib/zin/wg/input/v1.php b/lib/zin/wg/input/v1.php index b0c79c1dd4..a222c79d2c 100644 --- a/lib/zin/wg/input/v1.php +++ b/lib/zin/wg/input/v1.php @@ -23,7 +23,7 @@ class input extends wg 'class' => 'form-control' ); - protected function build(): wg + protected function build() { $props = $this->props->skip('required'); $required = $this->prop('required'); diff --git a/lib/zin/wg/inputcontrol/v1.php b/lib/zin/wg/inputcontrol/v1.php index bc249196e4..dae99ec71f 100644 --- a/lib/zin/wg/inputcontrol/v1.php +++ b/lib/zin/wg/inputcontrol/v1.php @@ -19,7 +19,7 @@ class inputControl extends wg 'suffix' => array() ); - protected function build(): wg + protected function build() { list($prefix, $suffix, $prefixWidth, $suffixWidth, $class) = $this->prop(array('prefix', 'suffix', 'prefixWidth', 'suffixWidth', 'class')); diff --git a/lib/zin/wg/inputgroup/v1.php b/lib/zin/wg/inputgroup/v1.php index ec491b4f93..477907d1c5 100644 --- a/lib/zin/wg/inputgroup/v1.php +++ b/lib/zin/wg/inputgroup/v1.php @@ -50,7 +50,7 @@ class inputGroup extends wg return new input(set::type($control), set($item->props->skip('control'))); } - protected function build(): wg + protected function build() { list($items, $seg) = $this->prop(['items', 'seg']); $children = $this->children(); diff --git a/lib/zin/wg/inputgroupaddon/v1.php b/lib/zin/wg/inputgroupaddon/v1.php index 4da97ef37c..4d207dddbb 100644 --- a/lib/zin/wg/inputgroupaddon/v1.php +++ b/lib/zin/wg/inputgroupaddon/v1.php @@ -20,7 +20,7 @@ namespace zin; */ class inputGroupAddon extends wg { - protected function build(): wg + protected function build() { return h::span(setClass('input-group-addon'), set($this->props), $this->children()); } diff --git a/lib/zin/wg/label/v1.php b/lib/zin/wg/label/v1.php index 74c69e15aa..24b031f735 100644 --- a/lib/zin/wg/label/v1.php +++ b/lib/zin/wg/label/v1.php @@ -8,7 +8,7 @@ class label extends wg 'text?:string' ); - public static function getPageCSS(): string|false + public static function getPageCSS(): ?string { return file_get_contents(__DIR__ . DS . 'css' . DS . 'v1.css'); } @@ -22,7 +22,7 @@ class label extends wg } } - public function build(): wg + public function build() { return span ( diff --git a/lib/zin/wg/main/v1.php b/lib/zin/wg/main/v1.php index a18c5c5a2e..5007632724 100644 --- a/lib/zin/wg/main/v1.php +++ b/lib/zin/wg/main/v1.php @@ -134,7 +134,7 @@ class main extends wg * @access protected * @return wg */ - protected function build(): wg + protected function build() { return div ( diff --git a/lib/zin/wg/mainnavbar/v1.php b/lib/zin/wg/mainnavbar/v1.php index dd7cc14204..efc3bf588f 100644 --- a/lib/zin/wg/mainnavbar/v1.php +++ b/lib/zin/wg/mainnavbar/v1.php @@ -40,7 +40,7 @@ class mainNavbar extends nav * @access public * @return string|false */ - public static function getPageCSS(): string|false + public static function getPageCSS(): ?string { return file_get_contents(__DIR__ . DS . 'css' . DS . 'v1.css'); } @@ -99,7 +99,7 @@ class mainNavbar extends nav * @access protected * @return wg */ - protected function build(): wg + protected function build() { global $app, $config; diff --git a/lib/zin/wg/menu/v1.php b/lib/zin/wg/menu/v1.php index aa3f76d5a4..e62d8a5fd5 100644 --- a/lib/zin/wg/menu/v1.php +++ b/lib/zin/wg/menu/v1.php @@ -24,7 +24,7 @@ class menu extends wg /** * @return builder */ - protected function build(): wg + protected function build() { $items = $this->prop('items'); return h::menu diff --git a/lib/zin/wg/modal/v1.php b/lib/zin/wg/modal/v1.php index 0a57027bdb..60f1791020 100644 --- a/lib/zin/wg/modal/v1.php +++ b/lib/zin/wg/modal/v1.php @@ -15,7 +15,7 @@ class modal extends modalDialog 'modalProps' => array() ); - protected function build(): wg + protected function build() { list($id, $modalProps) = $this->prop(array('id', 'modalProps')); diff --git a/lib/zin/wg/modaldialog/v1.php b/lib/zin/wg/modaldialog/v1.php index a28ed49d88..ff61f3a7ce 100644 --- a/lib/zin/wg/modaldialog/v1.php +++ b/lib/zin/wg/modaldialog/v1.php @@ -88,7 +88,7 @@ class modalDialog extends wg protected function buildBody() { - $rawContent = $this->prop('rawContent', !zin::$rawContentCalled); + $rawContent = $this->prop('rawContent', !context()->rawContentCalled); return div ( setClass('modal-body scrollbar-hover', $this->prop('bodyClass')), @@ -125,7 +125,7 @@ class modalDialog extends wg return "$objectType:$objectID"; } - protected function build(): wg + protected function build() { return div ( diff --git a/lib/zin/wg/modalheader/v1.php b/lib/zin/wg/modalheader/v1.php index 3dba8a6eed..eb8bf6eab2 100644 --- a/lib/zin/wg/modalheader/v1.php +++ b/lib/zin/wg/modalheader/v1.php @@ -34,7 +34,7 @@ class modalHeader extends wg $this->setDefaultProps(array('title' => $title, 'entityText' => $entityText, 'entityID' => $entityID)); } - protected function build(): wg|array + protected function build() { list($title, $entityText, $entityID, $inModal) = $this->prop(array('title', 'entityText', 'entityID', 'inModal')); if(empty($inModal)) $inModal = false; diff --git a/lib/zin/wg/modalnextstep/v1.php b/lib/zin/wg/modalnextstep/v1.php index 8716b7bf97..39fddb6894 100644 --- a/lib/zin/wg/modalnextstep/v1.php +++ b/lib/zin/wg/modalnextstep/v1.php @@ -9,12 +9,12 @@ class modalNextStep extends wg 'items: array' ); - public static function getPageCSS(): string|false + public static function getPageCSS(): ?string { return file_get_contents(__DIR__ . DS . 'css' . DS . 'v1.css'); } - protected function build(): wg + protected function build() { $tip = $this->prop('tip'); $items = $this->prop('items'); diff --git a/lib/zin/wg/modulemenu/v1.php b/lib/zin/wg/modulemenu/v1.php index aaf41e4740..1e5619e638 100644 --- a/lib/zin/wg/modulemenu/v1.php +++ b/lib/zin/wg/modulemenu/v1.php @@ -24,7 +24,7 @@ class moduleMenu extends wg 'onCheck?: function' ); - public static function getPageCSS(): string|false + public static function getPageCSS(): ?string { return file_get_contents(__DIR__ . DS . 'css' . DS . 'v1.css'); } diff --git a/lib/zin/wg/modulepicker/v1.php b/lib/zin/wg/modulepicker/v1.php index b7f22b8e10..b8b9c1782d 100644 --- a/lib/zin/wg/modulepicker/v1.php +++ b/lib/zin/wg/modulepicker/v1.php @@ -22,12 +22,12 @@ class modulePicker extends wg 'manageLink?: string' // 维护模块链接 ); - public static function getPageJS(): string|false + public static function getPageJS(): ?string { return file_get_contents(__DIR__ . DS . 'js' . DS . 'v1.js'); } - protected function build(): wg|array + protected function build() { global $app, $lang; $app->loadLang('tree'); diff --git a/lib/zin/wg/monaco/v1.php b/lib/zin/wg/monaco/v1.php index c8c4e087e6..50bf23f933 100644 --- a/lib/zin/wg/monaco/v1.php +++ b/lib/zin/wg/monaco/v1.php @@ -20,12 +20,12 @@ class monaco extends wg 'onMouseDown' => '', 'onMouseMouse' => '' ); - public static function getPageJS(): string|false + public static function getPageJS(): ?string { return file_get_contents(__DIR__ . DS . 'js' . DS . 'v1.js'); } - protected function build(): wg + protected function build() { global $app; $vsPath = $app->getWebRoot() . 'js/monaco-editor/min/vs'; diff --git a/lib/zin/wg/nav/v1.php b/lib/zin/wg/nav/v1.php index 2d2de9df78..24d75460b5 100644 --- a/lib/zin/wg/nav/v1.php +++ b/lib/zin/wg/nav/v1.php @@ -23,7 +23,7 @@ class nav extends wg ); } - protected function build(): wg + protected function build() { list($items, $type, $stacked, $justified) = $this->prop(array('items', 'type', 'stacked', 'justified')); return h::menu diff --git a/lib/zin/wg/navbar/v1.php b/lib/zin/wg/navbar/v1.php index 90644935b1..86b99c9867 100644 --- a/lib/zin/wg/navbar/v1.php +++ b/lib/zin/wg/navbar/v1.php @@ -291,7 +291,7 @@ class navbar extends wg * * @access protected */ - protected function build(): wg + protected function build() { return h::nav ( diff --git a/lib/zin/wg/navigator/v1.php b/lib/zin/wg/navigator/v1.php index 5548fed105..e1481cd35f 100644 --- a/lib/zin/wg/navigator/v1.php +++ b/lib/zin/wg/navigator/v1.php @@ -8,7 +8,7 @@ class navigator extends wg 'items?: array' ); - public static function getPageCSS(): string|false + public static function getPageCSS(): ?string { return file_get_contents(__DIR__ . DS . 'css' . DS . 'v1.css'); } @@ -35,7 +35,7 @@ class navigator extends wg return $steps; } - protected function build(): wg + protected function build() { return ul ( diff --git a/lib/zin/wg/overviewblock/v1.php b/lib/zin/wg/overviewblock/v1.php index 18101dd80c..2619859ba9 100644 --- a/lib/zin/wg/overviewblock/v1.php +++ b/lib/zin/wg/overviewblock/v1.php @@ -131,7 +131,7 @@ class overviewBlock extends wg return $body; } - protected function build(): wg + protected function build() { list($id, $title, $block, $groups) = $this->prop(array('id', 'title', 'block', 'groups')); diff --git a/lib/zin/wg/pagebase/v1.php b/lib/zin/wg/pagebase/v1.php index 29a74806a3..bae26e1394 100644 --- a/lib/zin/wg/pagebase/v1.php +++ b/lib/zin/wg/pagebase/v1.php @@ -20,9 +20,9 @@ class pageBase extends wg protected static array $defaultProps = array ( - 'zui' => false, + 'zui' => false, 'display' => true, - 'metas' => array('', '', '', '') + 'metas' => array('', '', '', '') ); protected static array $defineBlocks = array('head' => array()); @@ -42,7 +42,7 @@ class pageBase extends wg return $this->children(); } - protected function build(): wg + protected function build() { global $lang, $config, $app; @@ -50,16 +50,17 @@ class pageBase extends wg $head = $this->buildHead(); $body = $this->buildBody(); + $context = context(); $jsConfig = \js::getJSConfigVars(); $bodyProps = $this->prop('bodyProps'); $bodyClass = $this->prop('bodyClass'); $metas = $this->prop('metas'); - $rawContent = $this->prop('rawContent', !zin::$rawContentCalled); + $rawContent = $this->prop('rawContent', !$context->rawContentCalled); $title = $this->props->get('title', data('title')) . " - $lang->zentaoPMS"; $attrs = $this->getRestProps(); $css = array(data('pageCSS'), '/*{{ZIN_PAGE_CSS}}*/'); $js = array('/*{{ZIN_PAGE_JS}}*/', data('pageJS')); - $imports = context::current()->getImportList(); + $imports = $context->getImports(); $webRoot = $app->getWebRoot(); $themeName = $app->cookie->theme; $zuiPath = $config->zin->zuiPath; @@ -94,12 +95,12 @@ class pageBase extends wg $zinDebugData['definedProps'] = wg::$definedPropsMap; $zinDebugData['wgBlockMap'] = wg::$wgToBlockMap; } - $js[] = h::createJsVarCode('window.zin', $zinDebugData); + $js[] = 'window.zin = ' . js::value($zinDebugData) . ';'; $js[] = 'console.log("[ZIN] ", window.zin);'; } else { - $js[] = h::createJsVarCode('window.zin', array()); + $js[] = 'window.zin = {};'; } if($zui) array_unshift($js, 'zui.defineFn();'); diff --git a/lib/zin/wg/panel/v1.php b/lib/zin/wg/panel/v1.php index 44b5c4e8d8..cbc5a9c700 100644 --- a/lib/zin/wg/panel/v1.php +++ b/lib/zin/wg/panel/v1.php @@ -118,7 +118,7 @@ class panel extends wg return array(setID($id), setClass('panel', $class, empty($size) ? null : "size-$size", $shadow ? 'shadow' : null)); } - protected function build(): wg + protected function build() { return div ( diff --git a/lib/zin/wg/password/v1.php b/lib/zin/wg/password/v1.php index ee4b9bc272..0436d18e72 100644 --- a/lib/zin/wg/password/v1.php +++ b/lib/zin/wg/password/v1.php @@ -13,7 +13,7 @@ class password extends wg 'strengthClass?: string="passwordStrength"' ); - public static function getPageJS(): string|false + public static function getPageJS(): ?string { return file_get_contents(__DIR__ . DS . 'js' . DS . 'v1.js'); } diff --git a/lib/zin/wg/pastedialog/v1.php b/lib/zin/wg/pastedialog/v1.php index 80bdc3ea44..78264ceb4f 100644 --- a/lib/zin/wg/pastedialog/v1.php +++ b/lib/zin/wg/pastedialog/v1.php @@ -10,17 +10,17 @@ class pasteDialog extends wg 'name?: string="importLines"' // 多行文本控件名称,默认为“importLines” ); - public static function getPageCSS(): string|false + public static function getPageCSS(): ?string { return file_get_contents(__DIR__ . DS . 'css' . DS . 'v1.css'); } - public static function getPageJS(): string|false + public static function getPageJS(): ?string { return file_get_contents(__DIR__ . DS . 'js' . DS . 'v1.js'); } - protected function build(): wg + protected function build() { global $lang; $field = $this->prop('field'); diff --git a/lib/zin/wg/prilabel/v1.php b/lib/zin/wg/prilabel/v1.php index 7d317235e3..4567b08cad 100644 --- a/lib/zin/wg/prilabel/v1.php +++ b/lib/zin/wg/prilabel/v1.php @@ -27,7 +27,7 @@ class priLabel extends wg return $child; } - protected function build(): wg + protected function build() { $pri = $this->prop('pri', 0); $text = $this->prop('text'); diff --git a/lib/zin/wg/productmenu/v1.php b/lib/zin/wg/productmenu/v1.php index 5040e63fda..d8582c5e6c 100644 --- a/lib/zin/wg/productmenu/v1.php +++ b/lib/zin/wg/productmenu/v1.php @@ -12,7 +12,7 @@ class productMenu extends wg 'leading?:bool=true' ); - public static function getPageCSS(): string|false + public static function getPageCSS(): ?string { return file_get_contents(__DIR__ . DS . 'css' . DS . 'v1.css'); } diff --git a/lib/zin/wg/productsbox/v1.php b/lib/zin/wg/productsbox/v1.php index f1354eeb74..3c797c667d 100644 --- a/lib/zin/wg/productsbox/v1.php +++ b/lib/zin/wg/productsbox/v1.php @@ -27,17 +27,17 @@ class productsBox extends wg 'required?: bool=false' // 是否是必填。 ); - public static function getPageCSS(): string|false + public static function getPageCSS(): ?string { return file_get_contents(__DIR__ . DS . 'css' . DS . 'v1.css'); } - public static function getPageJS(): string|false + public static function getPageJS(): ?string { return file_get_contents(__DIR__ . DS . 'js' . DS . 'v1.js'); } - protected function build(): wg + protected function build() { list($project, $productItems, $linkedProducts, $errorSameProducts) = $this->prop(array('project', 'productItems', 'linkedProducts', 'errorSameProducts')); diff --git a/lib/zin/wg/programmenu/v1.php b/lib/zin/wg/programmenu/v1.php index 9db1d63f13..d23642b20f 100644 --- a/lib/zin/wg/programmenu/v1.php +++ b/lib/zin/wg/programmenu/v1.php @@ -17,7 +17,7 @@ class programMenu extends wg 'leadingAngle?: bool' ); - public static function getPageCSS(): string|false + public static function getPageCSS(): ?string { return file_get_contents(__DIR__ . DS . 'css' . DS . 'v1.css'); } diff --git a/lib/zin/wg/progressbar/v1.php b/lib/zin/wg/progressbar/v1.php index 1777e648cd..fd5817c056 100644 --- a/lib/zin/wg/progressbar/v1.php +++ b/lib/zin/wg/progressbar/v1.php @@ -41,7 +41,7 @@ class progressBar extends wg * @access protected * @return wg */ - protected function build(): wg + protected function build() { list($percent, $color, $background, $height, $width, $striped, $active) = $this->prop(array('percent', 'color', 'background', 'height', 'width', 'striped', 'active')); $style = array diff --git a/lib/zin/wg/progresscircle/v1.php b/lib/zin/wg/progresscircle/v1.php index 9cc2e818be..9097a9130a 100644 --- a/lib/zin/wg/progresscircle/v1.php +++ b/lib/zin/wg/progresscircle/v1.php @@ -48,7 +48,7 @@ class progressCircle extends wg * @access protected * @return wg */ - protected function build(): wg + protected function build() { $children = $this->children(); $class = $this->prop('class'); diff --git a/lib/zin/wg/resultfilter/v1.php b/lib/zin/wg/resultfilter/v1.php index 60612e1de0..52ab781c70 100644 --- a/lib/zin/wg/resultfilter/v1.php +++ b/lib/zin/wg/resultfilter/v1.php @@ -68,7 +68,7 @@ class resultFilter extends filter ); } - protected function build(): wg|array + protected function build() { $type = $this->prop('type'); $class = $this->prop('class'); diff --git a/lib/zin/wg/risklabel/v1.php b/lib/zin/wg/risklabel/v1.php index c50921d812..c96c615921 100644 --- a/lib/zin/wg/risklabel/v1.php +++ b/lib/zin/wg/risklabel/v1.php @@ -9,7 +9,7 @@ class riskLabel extends wg 'level?: string' // 风险等级:高('high' 或 'h')、中('middle' 或 'm')、低('low' 或 'l') ); - public static function getPageCSS(): string|false + public static function getPageCSS(): ?string { return file_get_contents(__DIR__ . DS . 'css' . DS . 'v1.css'); } @@ -31,7 +31,7 @@ class riskLabel extends wg return 'risk-low'; } - protected function build(): wg + protected function build() { $text = $this->prop('text'); return span diff --git a/lib/zin/wg/roadmap/v1.php b/lib/zin/wg/roadmap/v1.php index 74c5fd3579..dfd35ae921 100644 --- a/lib/zin/wg/roadmap/v1.php +++ b/lib/zin/wg/roadmap/v1.php @@ -100,7 +100,7 @@ class roadMap extends wg ); } - protected function build(): wg + protected function build() { $releases = $this->prop('releases'); $releasePaths = array(); diff --git a/lib/zin/wg/row/v1.php b/lib/zin/wg/row/v1.php index d460c85ada..b0fe92affb 100644 --- a/lib/zin/wg/row/v1.php +++ b/lib/zin/wg/row/v1.php @@ -9,7 +9,7 @@ class row extends wg 'align?: string' ); - protected function build(): wg + protected function build() { $classList = 'row'; list($justify, $align) = $this->prop(array('justify', 'align')); diff --git a/lib/zin/wg/searchform/v1.php b/lib/zin/wg/searchform/v1.php index 47acaeb4e3..c647611e45 100644 --- a/lib/zin/wg/searchform/v1.php +++ b/lib/zin/wg/searchform/v1.php @@ -43,7 +43,7 @@ class searchForm extends wg * @access protected * @return wg */ - protected function build(): wg + protected function build() { global $config; if(isset($config->zin->mode) && $config->zin->mode == 'compatible') diff --git a/lib/zin/wg/searchtoggle/v1.php b/lib/zin/wg/searchtoggle/v1.php index 64db0705f6..d5ecd66c87 100644 --- a/lib/zin/wg/searchtoggle/v1.php +++ b/lib/zin/wg/searchtoggle/v1.php @@ -17,7 +17,7 @@ class searchToggle extends wg if($this->hasProp('formName')) trigger_error('[ZIN] The property "formName" is not supported in the "searchToggle()"', E_USER_WARNING); } - protected function build(): wg + protected function build() { global $lang, $app, $config; list($target, $module, $open, $url, $searchUrl) = $this->prop(array('target', 'module', 'open', 'url', 'searchUrl')); diff --git a/lib/zin/wg/section/v1.php b/lib/zin/wg/section/v1.php index 5d639b72a9..8621f4483a 100644 --- a/lib/zin/wg/section/v1.php +++ b/lib/zin/wg/section/v1.php @@ -80,7 +80,7 @@ class section extends wg return $this->content($content); } - protected function build(): wg + protected function build() { return div ( diff --git a/lib/zin/wg/sectioncard/v1.php b/lib/zin/wg/sectioncard/v1.php index f926cd41da..9b064aa068 100644 --- a/lib/zin/wg/sectioncard/v1.php +++ b/lib/zin/wg/sectioncard/v1.php @@ -27,7 +27,7 @@ class sectionCard extends wg ); } - protected function build(): wg + protected function build() { $title = $this->block('title'); diff --git a/lib/zin/wg/sectionlist/v1.php b/lib/zin/wg/sectionlist/v1.php index e61a990b44..d790537525 100644 --- a/lib/zin/wg/sectionlist/v1.php +++ b/lib/zin/wg/sectionlist/v1.php @@ -11,7 +11,7 @@ class sectionList extends wg return new section(inherit($item)); } - protected function build(): wg + protected function build() { return div ( diff --git a/lib/zin/wg/select/v1.php b/lib/zin/wg/select/v1.php index a5b994b788..c6d260c8f9 100644 --- a/lib/zin/wg/select/v1.php +++ b/lib/zin/wg/select/v1.php @@ -99,7 +99,7 @@ class select extends wg * @access protected * @return wg */ - protected function build(): wg + protected function build() { list($items, $multiple, $required) = $this->prop(array('items', 'multiple', 'required')); diff --git a/lib/zin/wg/severitylabel/v1.php b/lib/zin/wg/severitylabel/v1.php index 22926f7aa9..adef4cbece 100644 --- a/lib/zin/wg/severitylabel/v1.php +++ b/lib/zin/wg/severitylabel/v1.php @@ -28,7 +28,7 @@ class severityLabel extends wg return $child; } - protected function build(): wg + protected function build() { $level = $this->prop('level', 0); $text = $this->prop('text'); diff --git a/lib/zin/wg/sidebar/v1.php b/lib/zin/wg/sidebar/v1.php index d908cdd8fc..344178388b 100644 --- a/lib/zin/wg/sidebar/v1.php +++ b/lib/zin/wg/sidebar/v1.php @@ -27,7 +27,7 @@ class sidebar extends wg } } - protected function build(): wg + protected function build() { list($side, $showToggle, $width, $preserve, $parent, $maxWidth, $minWidth, $dragToResize, $onToggle, $toggleBtn) = $this->prop(array('side', 'showToggle', 'width', 'preserve', 'parent', 'maxWidth', 'minWidth', 'dragToResize', 'onToggle', 'toggleBtn')); if($preserve === null) diff --git a/lib/zin/wg/statisticblock/v1.php b/lib/zin/wg/statisticblock/v1.php index c0b50820e9..130f601263 100644 --- a/lib/zin/wg/statisticblock/v1.php +++ b/lib/zin/wg/statisticblock/v1.php @@ -38,7 +38,7 @@ class statisticBlock extends blockPanel * @return string|false * @access protected */ - public static function getPageCSS(): string|false + public static function getPageCSS(): ?string { return file_get_contents(__DIR__ . DS . 'css' . DS . 'v1.css'); } diff --git a/lib/zin/wg/stepseditor/v1.php b/lib/zin/wg/stepseditor/v1.php index 2cbe23170f..88064f5ea0 100644 --- a/lib/zin/wg/stepseditor/v1.php +++ b/lib/zin/wg/stepseditor/v1.php @@ -40,12 +40,12 @@ class stepsEditor extends wg 'dragNestedTip?: string' // 拖拽超出提示。 ); - public static function getPageJS(): string|false + public static function getPageJS(): ?string { return file_get_contents(__DIR__ . DS . 'js' . DS . 'v1.js'); } - public static function getPageCSS(): string|false + public static function getPageCSS(): ?string { return file_get_contents(__DIR__ . DS . 'css' . DS . 'v1.css'); } @@ -56,7 +56,7 @@ class stepsEditor extends wg * @access protected * @return wg */ - protected function build(): wg + protected function build() { $stepText = $this->prop('stepText', data('lang.testcase.stepDesc')); $expectText = $this->prop('expectText', data('lang.testcase.stepExpect')); diff --git a/lib/zin/wg/tablechart/v1.php b/lib/zin/wg/tablechart/v1.php index 513934a61f..4aa9d637e5 100644 --- a/lib/zin/wg/tablechart/v1.php +++ b/lib/zin/wg/tablechart/v1.php @@ -39,7 +39,7 @@ class tableChart extends wg ); } - protected function build(): wg + protected function build() { $type = $this->prop('type'); $item = $this->prop('item'); diff --git a/lib/zin/wg/tabledata/v1.php b/lib/zin/wg/tabledata/v1.php index 35e14097df..bc1fb37739 100644 --- a/lib/zin/wg/tabledata/v1.php +++ b/lib/zin/wg/tabledata/v1.php @@ -16,7 +16,7 @@ class tableData extends wg 'required?: bool=false' ); - public static function getPageCSS(): string|false + public static function getPageCSS(): ?string { return file_get_contents(__DIR__ . DS . 'css' . DS . 'v1.css'); } @@ -105,7 +105,7 @@ class tableData extends wg ); } - protected function build(): wg + protected function build() { $useTable = $this->prop('useTable'); $tableClass = $this->prop('class'); diff --git a/lib/zin/wg/tabpane/v1.php b/lib/zin/wg/tabpane/v1.php index ec5eda4f78..098b2e0da2 100644 --- a/lib/zin/wg/tabpane/v1.php +++ b/lib/zin/wg/tabpane/v1.php @@ -27,7 +27,7 @@ class tabPane extends wg } } - protected function build(): wg + protected function build() { $key = $this->prop('key'); $active = $this->prop('active'); diff --git a/lib/zin/wg/tabs/v1.php b/lib/zin/wg/tabs/v1.php index dd93fdec0f..8dc1055439 100644 --- a/lib/zin/wg/tabs/v1.php +++ b/lib/zin/wg/tabs/v1.php @@ -20,7 +20,7 @@ class tabs extends wg 'headerClass?:string=""' ); - public static function getPageCSS(): string|false + public static function getPageCSS(): ?string { return file_get_contents(__DIR__ . DS . 'css' . DS . 'v1.css'); } @@ -109,7 +109,7 @@ class tabs extends wg ); } - protected function build(): wg + protected function build() { $isVertical = $this->prop('direction') === 'v'; diff --git a/lib/zin/wg/textarea/v1.php b/lib/zin/wg/textarea/v1.php index 15787c9254..b950cfed68 100644 --- a/lib/zin/wg/textarea/v1.php +++ b/lib/zin/wg/textarea/v1.php @@ -31,7 +31,7 @@ class textarea extends wg return $child; } - protected function build(): wg + protected function build() { return h::textarea ( diff --git a/lib/zin/wg/toolbar/v1.php b/lib/zin/wg/toolbar/v1.php index 39c401f77d..5e77c6789e 100644 --- a/lib/zin/wg/toolbar/v1.php +++ b/lib/zin/wg/toolbar/v1.php @@ -39,7 +39,7 @@ class toolbar extends wg ); } - protected function build(): wg + protected function build() { $items = $this->prop('items'); return div diff --git a/lib/zin/wg/treeeditor/v1.php b/lib/zin/wg/treeeditor/v1.php index e43cb5a74b..c9671f8ba0 100644 --- a/lib/zin/wg/treeeditor/v1.php +++ b/lib/zin/wg/treeeditor/v1.php @@ -19,7 +19,7 @@ class treeEditor extends wg 'canSplit?: bool=true' ); - protected function build(): wg + protected function build() { $this->setProp('items', $this->buildTree($this->prop('items'))); $treeProps = $this->props->pick(array('items', 'activeClass', 'activeIcon', 'activeKey', 'onClickItem', 'defaultNestedShow', 'changeActiveKey', 'isDropdownMenu', 'collapsedIcon', 'expandedIcon', 'normalIcon', 'itemActions', 'hover', 'onClick', 'sortable', 'onSort')); diff --git a/lib/zin/wg/twinsstory/v1.php b/lib/zin/wg/twinsstory/v1.php index f97d446dec..68cb6b5547 100644 --- a/lib/zin/wg/twinsstory/v1.php +++ b/lib/zin/wg/twinsstory/v1.php @@ -20,17 +20,17 @@ class twinsStory extends wg 'defaultPlan?: int=0', // 默认计划。 ); - public static function getPageCSS(): string|false + public static function getPageCSS(): ?string { return file_get_contents(__DIR__ . DS . 'css' . DS . 'v1.css'); } - public static function getPageJS(): string|false + public static function getPageJS(): ?string { return file_get_contents(__DIR__ . DS . 'js' . DS . 'v1.js'); } - protected function build(): wg + protected function build() { global $lang, $config; list($productType, $branchItems, $defaultBranch, $moduleItems, $defaultModule, $planItems, $defaultPlan) = $this->prop(array('productType', 'branchItems', 'defaultBranch', 'moduleItems', 'defaultModule', 'planItems', 'defaultPlan')); diff --git a/lib/zin/wg/useravatar/v1.php b/lib/zin/wg/useravatar/v1.php index 91dd5ecbf4..c1e5e0fa45 100644 --- a/lib/zin/wg/useravatar/v1.php +++ b/lib/zin/wg/useravatar/v1.php @@ -37,7 +37,7 @@ class userAvatar extends wg return parent::onAddChild($child); } - protected function build(): wg + protected function build() { list($user, $avatar, $account, $realname) = $this->prop(array('user', 'avatar', 'account', 'realname')); if(is_array($user)) diff --git a/lib/zin/wg/users/v1.php b/lib/zin/wg/users/v1.php index cd731c4188..180b46e0ea 100644 --- a/lib/zin/wg/users/v1.php +++ b/lib/zin/wg/users/v1.php @@ -44,7 +44,7 @@ class users extends wg } } - protected function build(): wg|array + protected function build() { return inputGroup ( diff --git a/lib/zin/wg/visionswitcher/v1.php b/lib/zin/wg/visionswitcher/v1.php index 2ba1d0ec03..6387264a09 100644 --- a/lib/zin/wg/visionswitcher/v1.php +++ b/lib/zin/wg/visionswitcher/v1.php @@ -7,7 +7,7 @@ require_once dirname(__DIR__) . DS . 'btn' . DS . 'v1.php'; class visionSwitcher extends wg { - public static function getPageCSS(): string|false + public static function getPageCSS(): ?string { return << .icon, #versionMenu .item-icon {display: flex; width: 18px; height: 18px; border-radius: var(--radius-md); align-items: center; justify-content: center; background: rgba(var(--color-inverse-rgb), .1); opacity: .7;} diff --git a/lib/zin/zentao/zentao.func.php b/lib/zin/zentao/zentao.func.php index 5895e6ca78..313acf53a3 100644 --- a/lib/zin/zentao/zentao.func.php +++ b/lib/zin/zentao/zentao.func.php @@ -141,6 +141,6 @@ function bind(string $name, bool|string|array $callback, array|string $options = function renderJson(mixed $data, int $flags = 0) { ob_end_flush(); - zin::$rendered = true; + context()->rendered = true; echo json_encode($data, $flags); } diff --git a/lib/zin/zui/zui.class.php b/lib/zin/zui/zui.class.php index 825c76c3eb..c366e8303c 100644 --- a/lib/zin/zui/zui.class.php +++ b/lib/zin/zui/zui.class.php @@ -13,8 +13,7 @@ declare(strict_types=1); namespace zin; require_once dirname(__DIR__) . DS . 'core' . DS . 'wg.class.php'; -require_once dirname(__DIR__) . DS . 'core' . DS . 'wg.func.php'; -require_once dirname(__DIR__) . DS . 'core' . DS . 'wg.func.php'; +require_once dirname(__DIR__) . DS . 'core' . DS . 'zin.func.php'; require_once __DIR__ . DS . 'toggle.func.php'; require_once __DIR__ . DS . 'toggle.class.php'; @@ -34,7 +33,7 @@ class zui extends wg '_initWithShareData?: bool', ); - protected function build(): wg|array + protected function build(): mixed { list($name, $target, $tagName, $targetProps, $size, $id, $class, $map, $call, $initWithShareData, $userOptions) = $this->prop(array('_name', '_to', '_tag', '_props', '_size', '_id', '_class', '_map', '_call', '_initWithShareData', '_options')); list($width, $height) = $size;