* zin: refactor to compatible with php 5.4.
# Conflicts: # module/instance/ui/view.html.php # module/repo/ui/monaco.html.php
This commit is contained in:
@@ -50,8 +50,8 @@ class props extends \zin\utils\dataset
|
||||
*/
|
||||
public function __construct(array $props = array())
|
||||
{
|
||||
$this->style = style::new();
|
||||
$this->class = classlist::new();
|
||||
$this->style = new style();
|
||||
$this->class = new classlist();
|
||||
|
||||
parent::__construct($props);
|
||||
}
|
||||
|
||||
@@ -18,13 +18,13 @@ class set
|
||||
{
|
||||
public static function __callStatic($prop, $args)
|
||||
{
|
||||
if($prop === 'class' || strtolower($prop) === 'classname')
|
||||
{
|
||||
return directive('prop', array('class' => $args));
|
||||
}
|
||||
|
||||
$value = array_shift($args);
|
||||
if(is_object($value)) $value = (array)$value;
|
||||
return directive('prop', array($prop => $value));
|
||||
}
|
||||
|
||||
public static function class(/* ...$args */)
|
||||
{
|
||||
return directive('prop', array('class' => func_get_args()));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -25,28 +25,6 @@ class classlist
|
||||
*/
|
||||
private array $list = array();
|
||||
|
||||
/**
|
||||
* Create an classlist instance
|
||||
*
|
||||
* @param string|array|null $names - A string or a class name list
|
||||
* @return classlist
|
||||
*/
|
||||
public static function new(string|array|null $names = array()): classlist
|
||||
{
|
||||
return new classlist($names);
|
||||
}
|
||||
|
||||
/**
|
||||
* Stringify class list
|
||||
*
|
||||
* @param string|array $names - A string or a class name list
|
||||
* @return string
|
||||
*/
|
||||
public static function str(string|array $names): string
|
||||
{
|
||||
return classlist::new($names)->toStr();
|
||||
}
|
||||
|
||||
/**
|
||||
* Create classname instance
|
||||
*
|
||||
@@ -76,7 +54,7 @@ class classlist
|
||||
* Example:
|
||||
*
|
||||
* // Set class names
|
||||
* $classlist = classlist::new();
|
||||
* $classlist = new classlist();
|
||||
* $classlist->set('btn primary rounded');
|
||||
*
|
||||
* // Set multiple classnames by string list
|
||||
@@ -133,7 +111,7 @@ class classlist
|
||||
*
|
||||
* Example:
|
||||
*
|
||||
* $classlist = classlist::new();
|
||||
* $classlist = new classlist();
|
||||
* $classlist->add('btn primary rounded');
|
||||
*
|
||||
* // Add multiple classnames by string list
|
||||
@@ -153,7 +131,7 @@ class classlist
|
||||
*
|
||||
* Example:
|
||||
*
|
||||
* $classlist = classlist::new('btn primary rounded');
|
||||
* $classlist = new classlist('btn primary rounded');
|
||||
* $classlist->remove('btn primary');
|
||||
*
|
||||
* // Add multiple classnames by string list
|
||||
@@ -183,7 +161,7 @@ class classlist
|
||||
*
|
||||
* Example:
|
||||
*
|
||||
* $classlist = classlist::new('btn');
|
||||
* $classlist = new classlist('btn');
|
||||
* $classlist->toggle('btn'); // class list is ""
|
||||
*
|
||||
* // Toggle class name by flag
|
||||
@@ -209,7 +187,7 @@ class classlist
|
||||
*
|
||||
* Example:
|
||||
*
|
||||
* $classlist = classlist::new('btn primary rounded');
|
||||
* $classlist = new classlist('btn primary rounded');
|
||||
* echo $classlist->has('btn'); // Output true
|
||||
*
|
||||
* // Check multiple names
|
||||
|
||||
@@ -182,7 +182,7 @@ class dataset
|
||||
* @access public
|
||||
* @return object
|
||||
*/
|
||||
public function clone()
|
||||
public function copy()
|
||||
{
|
||||
$className = get_called_class();
|
||||
return new $className($this->data);
|
||||
|
||||
@@ -1,126 +0,0 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
/**
|
||||
* The hx class file of zin of ZenTaoPMS.
|
||||
*
|
||||
* @copyright Copyright 2023 青岛易软天创网络科技有限公司(QingDao Nature Easy Soft Network Technology Co,LTD, www.cnezsoft.com)
|
||||
* @author Hao Sun <sunhao@easycorp.ltd>
|
||||
* @package zin
|
||||
* @version $Id
|
||||
* @link https://www.zentao.net
|
||||
*/
|
||||
|
||||
namespace zin\utils;
|
||||
|
||||
require_once __DIR__ . DS . 'dataset.class.php';
|
||||
|
||||
/**
|
||||
* Manage hx for html element and widgets
|
||||
*
|
||||
* Example:
|
||||
*
|
||||
* // Create a hx object an convert to str string
|
||||
* $hx = hx::new()->boost();
|
||||
*
|
||||
* echo $hx(); // Output 'hx-boost="true"'
|
||||
*
|
||||
* @see https://htmx.org/
|
||||
* @todo @sunhao: Validate hx properties on modifying
|
||||
*/
|
||||
class hx extends dataset
|
||||
{
|
||||
/**
|
||||
* Method for sub class to modify value on setting it
|
||||
*
|
||||
* @access public
|
||||
* @param array|string $prop - Property name or properties list
|
||||
* @param mixed $value - Property value
|
||||
* @param bool $removeEmpty - Whether to remove empty value
|
||||
* @return hx
|
||||
*/
|
||||
protected function setVal($prop, $value, $removeEmpty = false)
|
||||
{
|
||||
if(str_starts_with($prop, 'hx-')) $prop = substr($prop, 3);
|
||||
return parent::setVal($prop, $value);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set ajax request
|
||||
*
|
||||
* @access public
|
||||
* @param string $url - The request url
|
||||
* @param string $trigger - The trigget
|
||||
* @param string $target - A css selector to specific a element to load remote content
|
||||
* @param string $method - The request method, default value is "get"
|
||||
* @return hx
|
||||
* @see https://htmx.org/docs/#ajax
|
||||
*/
|
||||
public function ajax($url, $trigger = '', $target = '', $method = 'get')
|
||||
{
|
||||
if(is_array($url)) return $this->set($url);
|
||||
|
||||
return $this->set(array('url' => $url, 'trigger' => $trigger, 'target' => $target, 'method' => $method));
|
||||
}
|
||||
|
||||
/**
|
||||
* Set ajax post request
|
||||
*
|
||||
* @access public
|
||||
* @param string $url - The request url
|
||||
* @param string $trigger - The trigget
|
||||
* @param string $target - A css selector to specific a element to load remote content
|
||||
* @return hx
|
||||
* @see https://htmx.org/docs/#ajax
|
||||
*/
|
||||
public function post($url, $trigger = '', $target = '')
|
||||
{
|
||||
return $this->ajax($url, $trigger, $target, 'post');
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert hx properties to str string
|
||||
*
|
||||
* @access public
|
||||
* @return string
|
||||
*/
|
||||
public function toStr()
|
||||
{
|
||||
$pairs = array();
|
||||
|
||||
foreach($this->data as $name => $value)
|
||||
{
|
||||
/* Skip any null value */
|
||||
if($value === null) continue;
|
||||
|
||||
/* Convert non-string to json */
|
||||
if(!is_string($value)) $value = json_encode($value);
|
||||
|
||||
$pairs[] = 'hx-' . $name . '="' . htmlspecialchars($value) . '"';
|
||||
}
|
||||
|
||||
return implode(' ', $pairs);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create an instance
|
||||
*
|
||||
* @param string $hx - CSS hx list
|
||||
* @return hx
|
||||
*/
|
||||
static public function new($hx)
|
||||
{
|
||||
return new hx($hx);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create properties string from hx list
|
||||
*
|
||||
* @access public
|
||||
* @param string $hx - CSS hx list
|
||||
* @return string
|
||||
*/
|
||||
static public function str($props)
|
||||
{
|
||||
return (new hx($props))->toStr();
|
||||
}
|
||||
}
|
||||
@@ -43,29 +43,6 @@ require_once __DIR__ . DS . 'dataset.class.php';
|
||||
*/
|
||||
class style extends dataset
|
||||
{
|
||||
/**
|
||||
* Create an instance
|
||||
*
|
||||
* @param array $style - CSS style list
|
||||
* @return style
|
||||
*/
|
||||
public static function new(array $style = array()): style
|
||||
{
|
||||
return new style($style);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create css from style list
|
||||
*
|
||||
* @access public
|
||||
* @param array $style - CSS style list
|
||||
* @return string
|
||||
*/
|
||||
public static function str(array $style): string
|
||||
{
|
||||
return (new style($style))->toStr();
|
||||
}
|
||||
|
||||
/**
|
||||
* Format CSS variable name with prefix "--"
|
||||
*
|
||||
|
||||
@@ -47,7 +47,7 @@ class checkbox extends wg
|
||||
),
|
||||
h::label
|
||||
(
|
||||
set::for($id),
|
||||
set('for', $id),
|
||||
setClass($labelClass),
|
||||
$text,
|
||||
),
|
||||
@@ -68,7 +68,7 @@ class checkbox extends wg
|
||||
set::type($type),
|
||||
set($this->props->skip('text,primary,typeClass')),
|
||||
),
|
||||
is_string($text) ? span($text, set::class('text')) : $text,
|
||||
is_string($text) ? span($text, set::className('text')) : $text,
|
||||
$this->children()
|
||||
);
|
||||
}
|
||||
|
||||
@@ -50,7 +50,7 @@ class control extends wg
|
||||
{
|
||||
return div
|
||||
(
|
||||
set::class('form-control-static'),
|
||||
set::className('form-control-static'),
|
||||
set($this->props->skip(array('type', 'name', 'value', 'required', 'disabled', 'placeholder', 'items', 'required'))),
|
||||
set('data-name', $this->prop('name')),
|
||||
$this->prop('value')
|
||||
|
||||
@@ -129,7 +129,7 @@ class featureBar extends wg
|
||||
if(!empty($nav) && $nav[0] instanceof nav) return $nav;
|
||||
return new nav
|
||||
(
|
||||
set::class('nav-feature'),
|
||||
set::className('nav-feature'),
|
||||
set::items($this->getItems()),
|
||||
divorce($this->children())
|
||||
);
|
||||
|
||||
@@ -66,7 +66,7 @@ class formBase extends wg
|
||||
|
||||
return toolbar
|
||||
(
|
||||
set::class('form-actions', $this->prop('actionsClass')),
|
||||
set::className('form-actions', $this->prop('actionsClass')),
|
||||
set::items($actions)
|
||||
);
|
||||
}
|
||||
@@ -80,8 +80,8 @@ class formBase extends wg
|
||||
{
|
||||
list($url, $target, $method, $id) = $this->prop(array('url', 'target', 'method', 'id'));
|
||||
return array(
|
||||
set::class('form load-indicator'),
|
||||
$target === 'ajax' ? set::class('form-ajax') : null,
|
||||
set::className('form load-indicator'),
|
||||
$target === 'ajax' ? set::className('form-ajax') : null,
|
||||
set(array(
|
||||
'id' => $id,
|
||||
'action' => empty($url) ? $_SERVER['REQUEST_URI'] : $url,
|
||||
|
||||
@@ -96,13 +96,13 @@ class formBatchItem extends wg
|
||||
set($this->getRestProps()),
|
||||
span
|
||||
(
|
||||
set::class('form-label form-batch-label', $labelClass, $strong ? 'font-bold' : null, $required ? 'required' : null),
|
||||
set::className('form-label form-batch-label', $labelClass, $strong ? 'font-bold' : null, $required ? 'required' : null),
|
||||
set($labelProps),
|
||||
$label
|
||||
),
|
||||
empty($tip) ? null : new btn
|
||||
(
|
||||
set::class('form-batch-tip state text-gray', $tipClass),
|
||||
set::className('form-batch-tip state text-gray', $tipClass),
|
||||
set::size('sm'),
|
||||
set::type('ghost'),
|
||||
toggle('tooltip', array('title' => $tip)),
|
||||
|
||||
@@ -49,13 +49,13 @@ class formGroup extends wg
|
||||
|
||||
return div
|
||||
(
|
||||
set::class('form-group', $required ? 'required' : null, ($label === false || $label === null) ? 'no-label' : null, empty($width) ? null : 'grow-0'),
|
||||
set::className('form-group', $required ? 'required' : null, ($label === false || $label === null) ? 'no-label' : null, empty($width) ? null : 'grow-0'),
|
||||
zui::width($width),
|
||||
set($this->getRestProps()),
|
||||
setCssVar('form-grid-label-width', $labelWidth),
|
||||
empty($label) ? null : new formLabel
|
||||
(
|
||||
set::class($labelClass, $strong ? 'font-bold' : null),
|
||||
set::className($labelClass, $strong ? 'font-bold' : null),
|
||||
set::required($required),
|
||||
set($labelProps),
|
||||
$label
|
||||
@@ -65,7 +65,7 @@ class formGroup extends wg
|
||||
$this->children(),
|
||||
empty($tip) ? null : div
|
||||
(
|
||||
set::class($tipClass),
|
||||
set::className($tipClass),
|
||||
set($tipProps),
|
||||
$tip
|
||||
)
|
||||
|
||||
@@ -163,7 +163,7 @@ class formPanel extends panel
|
||||
|
||||
return new form
|
||||
(
|
||||
set::class($this->prop('formClass')),
|
||||
set::className($this->prop('formClass')),
|
||||
set($this->props->pick(array_keys(form::definedPropsList()))),
|
||||
$this->children(),
|
||||
$hiddenFields ? jsVar('hiddenFields', $hiddenFields) : null,
|
||||
|
||||
@@ -29,7 +29,7 @@ class formRow extends wg
|
||||
|
||||
return div
|
||||
(
|
||||
set::class('form-row', empty($width) ? null : 'grow-0', $hidden ? 'hidden' : ''),
|
||||
set::className('form-row', empty($width) ? null : 'grow-0', $hidden ? 'hidden' : ''),
|
||||
zui::width($width),
|
||||
is_array($items) ? array_map(array($this, 'onBuildItem'), $items) : null,
|
||||
set($this->getRestProps()),
|
||||
|
||||
@@ -91,7 +91,7 @@ class main extends wg
|
||||
(
|
||||
set::id('mainContent'),
|
||||
$leftSides,
|
||||
set::class(empty($leftSides) && empty($rightSides) ? '' : 'row', empty($leftSides) ? '' : 'has-sidebar-left', empty($rightSides) ? '' : 'has-sidebar-right'),
|
||||
set::className(empty($leftSides) && empty($rightSides) ? '' : 'row', empty($leftSides) ? '' : 'has-sidebar-left', empty($rightSides) ? '' : 'has-sidebar-right'),
|
||||
$this->children(),
|
||||
$rightSides
|
||||
);
|
||||
@@ -125,7 +125,7 @@ class main extends wg
|
||||
$this->buildMainNavbar(),
|
||||
div
|
||||
(
|
||||
set::class('container'),
|
||||
set::className('container'),
|
||||
$this->buildMenu(),
|
||||
$this->buildContent()
|
||||
)
|
||||
|
||||
@@ -60,7 +60,7 @@ class mindmap extends wg
|
||||
(
|
||||
h::iframe
|
||||
(
|
||||
set::class('mindmap-iframe'),
|
||||
set::className('mindmap-iframe'),
|
||||
set::src($mindmapPath),
|
||||
set::allowfullscreen(true),
|
||||
set::allowtransparency(true),
|
||||
|
||||
@@ -45,7 +45,7 @@ class modalHeader extends wg
|
||||
$title ? div
|
||||
(
|
||||
$title,
|
||||
set::class($this->prop('titleClass')),
|
||||
set::className($this->prop('titleClass')),
|
||||
) : null,
|
||||
($entityText || $entityID) ? entityLabel
|
||||
(
|
||||
@@ -62,7 +62,7 @@ class modalHeader extends wg
|
||||
|
||||
return h::div
|
||||
(
|
||||
set::class('modal-header panel-form rounded-md canvas mx-auto'),
|
||||
set::className('modal-header panel-form rounded-md canvas mx-auto'),
|
||||
set::style(array('margin-bottom' => '0px')),
|
||||
$header
|
||||
);
|
||||
|
||||
@@ -95,7 +95,7 @@ class pageBase extends wg
|
||||
(
|
||||
before(html('<!DOCTYPE html>')),
|
||||
set($attrs),
|
||||
set::class("theme-$themeName"),
|
||||
set::className("theme-$themeName"),
|
||||
set::lang($currentLang),
|
||||
h::head
|
||||
(
|
||||
@@ -108,7 +108,7 @@ class pageBase extends wg
|
||||
h::body
|
||||
(
|
||||
set($bodyProps),
|
||||
set::class($bodyClass),
|
||||
set::className($bodyClass),
|
||||
empty($imports) ? null : h::import($imports),
|
||||
h::css($css, setClass('zin-page-css')),
|
||||
$body,
|
||||
|
||||
@@ -29,7 +29,7 @@ class searchToggle extends wg
|
||||
if(is_null($open) && !empty($_GET['browseType'])) $open = $_GET['browseType'] === 'bySearch';
|
||||
return btn
|
||||
(
|
||||
set::class('ghost search-form-toggle'),
|
||||
set::className('ghost search-form-toggle'),
|
||||
set::icon('search'),
|
||||
set::text($lang->searchAB),
|
||||
set('data-module', $this->prop('module')),
|
||||
|
||||
@@ -29,7 +29,7 @@ class sidebar extends wg
|
||||
$this->children(),
|
||||
$showToggle ? div
|
||||
(
|
||||
set::class("sidebar-toggle sidebar-$side-toggle"),
|
||||
set::className("sidebar-toggle sidebar-$side-toggle"),
|
||||
icon("angle-$side"),
|
||||
on::click("zui.toggleSidebar({side: '$side'})")
|
||||
) : null
|
||||
|
||||
@@ -77,25 +77,25 @@ class stepsEditor extends wg
|
||||
setClass('steps-editor-row'),
|
||||
cell
|
||||
(
|
||||
set::class('steps-editor-col steps-editor-col-step'),
|
||||
set::className('steps-editor-col steps-editor-col-step'),
|
||||
$stepText
|
||||
),
|
||||
cell
|
||||
(
|
||||
set::class('steps-editor-col steps-editor-col-add'),
|
||||
set::className('steps-editor-col steps-editor-col-add'),
|
||||
div($sameLevelText),
|
||||
div($subLevelText),
|
||||
),
|
||||
cell
|
||||
(
|
||||
set::class('steps-editor-col steps-editor-col-expect'),
|
||||
set::className('steps-editor-col steps-editor-col-expect'),
|
||||
$expectText
|
||||
)
|
||||
)
|
||||
),
|
||||
div
|
||||
(
|
||||
set::class('steps-editor-body')
|
||||
set::className('steps-editor-body')
|
||||
),
|
||||
zui::stepsEditor
|
||||
(
|
||||
|
||||
@@ -54,7 +54,7 @@ class tableChart extends wg
|
||||
$chartOption[] = array('name' => $data->name, 'value' => $type == 'pie' ? $data->value : array('value' => $data->value, 'itemStyle' => array('color' => $color)));
|
||||
$tableTR[] = h::tr
|
||||
(
|
||||
h::td(label(set::class('label-dot mr-2'), set::style(array('background-color' => $color, '--tw-ring-color' => $color))), $data->name),
|
||||
h::td(label(set::className('label-dot mr-2'), set::style(array('background-color' => $color, '--tw-ring-color' => $color))), $data->name),
|
||||
h::td($data->value),
|
||||
h::td(($data->percent * 100) . '%')
|
||||
);
|
||||
@@ -66,11 +66,11 @@ class tableChart extends wg
|
||||
$overflow = $this->prop('overflow', true);
|
||||
return div
|
||||
(
|
||||
set::class('flex border py-2'),
|
||||
set::className('flex border py-2'),
|
||||
cell
|
||||
(
|
||||
setClass('border-r chart flex-auto'),
|
||||
div(set::class('center text-base font-bold py-2'), $title),
|
||||
div(set::className('center text-base font-bold py-2'), $title),
|
||||
echarts
|
||||
(
|
||||
set::color($colorList),
|
||||
@@ -105,7 +105,7 @@ class tableChart extends wg
|
||||
$overflow ? setStyle('max-height', ($chartHeight + 50) .'px') : null,
|
||||
h::table
|
||||
(
|
||||
set::class('table'),
|
||||
set::className('table'),
|
||||
$this->genTableHeaders(),
|
||||
$tableTR
|
||||
)
|
||||
|
||||
@@ -120,7 +120,7 @@ class tabs extends wg
|
||||
$titleViews[] = $this->buildTitleView($tabPane);
|
||||
|
||||
$divider = $tabPane->block('divider');
|
||||
if($divider) $titleViews[] = div(set::class('divider'));
|
||||
if($divider) $titleViews[] = div(set::className('divider'));
|
||||
|
||||
$contentViews[] = $tabPane;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user