Skip to content

Commit 9b5148a

Browse files
committed
Add new subComponents and fix bug
1 parent fb64474 commit 9b5148a

19 files changed

Lines changed: 317 additions & 193 deletions

Component.php

Lines changed: 10 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,7 @@
88
use JsonSerializable;
99
use LogicException;
1010

11-
use function json_encode;
1211
use function lcfirst;
13-
use function preg_replace_callback;
14-
use function stripcslashes;
1512

1613
class Component implements JsonSerializable
1714
{
@@ -26,7 +23,7 @@ class Component implements JsonSerializable
2623
/**
2724
* @var array
2825
*/
29-
protected array $properties;
26+
protected array $properties = [];
3027
/**
3128
* @var string
3229
*/
@@ -37,17 +34,19 @@ class Component implements JsonSerializable
3734
protected bool $asSelector;
3835

3936
/**
40-
* @param string|null $id
41-
* @param bool $asSelector
37+
* @var string
4238
*/
43-
public function __construct(string|null $id, bool $asSelector = true)
39+
protected string $endSymbols;
40+
41+
public function __construct(string|null $id, bool $asSelector = true, string $endSymbols = ';' . PHP_EOL)
4442
{
4543
if (!defined(static::class . '::COMPONENT_NAME')) {
4644
throw new LogicException("Class " . static::class . " must have const COMPONENT_NAME.");
4745
}
4846

4947
$this->id = $id;
5048
$this->asSelector = $asSelector;
49+
$this->endSymbols = $endSymbols;
5150
}
5251

5352
/**
@@ -107,7 +106,7 @@ protected function addMethod(string $methodName, $methodValue): static
107106
if ($methodValue === null) {
108107
$method = "('{$methodName}')";
109108
} else {
110-
$args = $this->encode($methodValue);
109+
$args = Encode::json($methodValue);
111110
$method = "('{$methodName}', {$args})";
112111
}
113112

@@ -140,20 +139,20 @@ public function __toString()
140139
{
141140
$appends = $this->appends;
142141

143-
$data = $this->method ?? '(' . $this->encode($this) . ')';
142+
$data = $this->method ?? '(' . Encode::json($this) . ')';
144143

145144
$selector = '';
146145
$end = '';
147146

148147
if ($this->id !== null) {
149-
$end = ';';
148+
$end = $this->endSymbols;
150149
$selector = '$(' . $this->id . ').';
151150

152151
if ($this->asSelector) {
153152
$selector = '$("#' . $this->id . '").';
154153
}
155154
} elseif (!$this->asSelector) {
156-
$end = ';';
155+
$end = $this->endSymbols;
157156
$selector = '$.';
158157
}
159158

@@ -174,23 +173,4 @@ public function jsonSerialize(): ?array
174173
{
175174
return $this->properties ?: null;
176175
}
177-
178-
/**
179-
* @param $toJson
180-
* @return string
181-
* @throws Exception
182-
*/
183-
protected function encode($toJson): string
184-
{
185-
$data = json_encode($toJson, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE);
186-
187-
if ($data === false) {
188-
throw new Exception('Invalid data');
189-
}
190-
191-
// replace markup by JS
192-
return preg_replace_callback('/"::JS::(.*?)::JS::"/', function ($matches) {
193-
return stripcslashes($matches[1]);
194-
}, $data) ?: '';
195-
}
196176
}

Components/DataGrid.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,5 @@ class DataGrid extends Component
88
{
99
public const string COMPONENT_NAME = 'datagrid';
1010
use \Easyui\Traits\DataGrid;
11+
use \Easyui\Traits\Panel;
1112
}

Components/Datagrid/Column.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
/**
1111
* @method $this title(string $title) [The column title text.]
1212
* @method $this field(string $field) [The column field name.]
13-
* @method $this width(int $width) [The width of column. If not defined, the width will auto expand to fit its contents. No width definition will reduce performance.]
13+
* @method $this width(string $width) [The width of column. If not defined, the width will auto expand to fit its contents. No width definition will reduce performance.]
1414
* @method $this rowspan(int $rowspan) [Indicate how many rows a cell should take up.]
1515
* @method $this colspan(int $colspan) [Indicate how many columns a cell should take up.]
1616
* @method $this align(DatagridColumnAlign $align) [Indicate how to align the column data. 'left', 'right', 'center' can be used.]

Components/Drawer.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
* @method $this mExpand() [Expand the drawer.]
2020
* @method $this mCollapse() [Collapse the drawer.]
2121
*/
22-
class Drawer extends Component
22+
class Drawer extends Dialog
2323
{
2424
public const string COMPONENT_NAME = 'drawer';
2525
}

Components/Form.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
*
2626
* Method
2727
* @method $this mSubmit(string|Js $options) [Do the submit action, the options parameter is an object which contains following properties:<br>url: the action URL<br>onSubmit: callback function before submit<br>success: callback function after submit successfully]
28-
* @method $this mLoad(array $data) [Load records to fill the form. The data parameter can be a string or a object type, when string acts as a remote URL, otherwise acts as a local record.]
28+
* @method $this mLoad(array|string $data) [Load records to fill the form. The data parameter can be a string or a object type, when string acts as a remote URL, otherwise acts as a local record.]
2929
* @method $this mClear() [Clear the form data.]
3030
* @method $this mReset() [Reset the form data.]
3131
* @method $this mValidate() [Do the form fields validation, return true when all fields is valid. The method is used with the validatebox plugin.]

Components/Layout.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,14 @@
33
namespace Easyui\Components;
44

55
use Easyui\Component;
6+
use Easyui\Components\Region\Panel as RegionPanel;
67
use Easyui\Enums\LayoutRegion;
78
use Easyui\Enums\LayoutPanelRegion;
89
use Easyui\Js;
910

1011
/**
1112
* Property/Params
1213
* @method $this pFit(bool $fit) [Set to true to set the layout size fit its parent container. When creating layout on 'body' tag, it will be auto maximized to the full size of whole page.]
13-
* @method $this p() []
1414
*
1515
* Event
1616
* @method $this eOnCollapse(Js $onCollapse) [Fires when collapse a region panel.]
@@ -23,7 +23,7 @@
2323
* @method $this mPanel(LayoutPanelRegion $region) [Return the specified panel, the 'region' parameter possible values:'north', 'south', 'east', 'west', 'center'.]
2424
* @method $this mCollapse(LayoutRegion $region) [Collapse the specified panel, the 'region' parameter possible values:'north', 'south', 'east', 'west'.]
2525
* @method $this mExpand(LayoutRegion $region) [Expand the specified panel, the 'region' parameter possible values:'north', 'south', 'east', 'west'.]
26-
* @method $this mAdd($options) [Add a specified panel, the options parameter is a config object, see tab panel properties for more details.]
26+
* @method $this mAdd(RegionPanel $options) [Add a specified panel, the options parameter is a config object, see tab panel properties for more details.]
2727
* @method $this mRemove(LayoutRegion $region) [Remove the specified panel, the 'region' parameter possible values:'north', 'south', 'east', 'west'.]
2828
* @method $this mSplit($region) [Split the region panel.]
2929
* @method $this mUnsplit($region) [Unsplit the region panel.]

Components/Messager/Confirm.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66
use Easyui\Options;
77

88
/**
9-
* @method $this title(string $title) [The title text to be showed on header panel.]
10-
* @method $this msg(string $msg) [The message text to be showed.]
9+
* @method $this title(string|Js $title) [The title text to be showed on header panel.]
10+
* @method $this msg(string|Js $msg) [The message text to be showed.]
1111
* @method $this fn(Js $fn) [fn(b): The callback function, when user click Ok button, pass a true value to function, otherwise pass a false to it.]
1212
*/
1313
class Confirm extends Options

Components/Panel.php

Lines changed: 1 addition & 92 deletions
Original file line numberDiff line numberDiff line change
@@ -3,100 +3,9 @@
33
namespace Easyui\Components;
44

55
use Easyui\Component;
6-
use Easyui\Enums\PanelCloseAnimation;
7-
use Easyui\Enums\PanelHalign;
8-
use Easyui\Enums\PanelOpenAnimation;
9-
use Easyui\Enums\PanelTitleDirection;
10-
use Easyui\Js;
116

12-
/**
13-
* Property/Params
14-
* @method $this pId(string $id) [The id attribute of this panel.]
15-
* @method $this pTitle(string $title) [The title text to display in panel header.]
16-
* @method $this pIconCls(string $iconCls) [A CSS class to display a 16x16 icon in panel.]
17-
* @method $this pWidth(int $width) [Set the panel width.]
18-
* @method $this pHeight(int $height) [Set the panel height.]
19-
* @method $this pLeft(int $left) [Set the panel left position.]
20-
* @method $this pTop(int $top) [Set the panel top position.]
21-
* @method $this pCls(string $cls) [Add a CSS class to the panel.]
22-
* @method $this pHeaderCls(string $headerCls) [Add a CSS class to the panel header.]
23-
* @method $this pBodyCls(string $bodyCls) [Add a CSS class to the panel body.]
24-
* @method $this pStyle(array $style) [Add a custom specification style to the panel.]
25-
* @method $this pFit(bool $fit) [When true to set the panel size fit its parent container.]
26-
* @method $this pBorder(bool $border) [Defines if to show panel border.]
27-
* @method $this pDoSize(bool $doSize) [If set to true, the panel will be resize and do layout when created.]
28-
* @method $this pNoheader(bool $noheader) [If set to true, the panel header will not be created.]
29-
* @method $this pContent(string $content) [The panel body content.]
30-
* @method $this pHalign(PanelHalign $halign) [The panel header alignment. Possible values are: 'top', 'left', 'right'.]
31-
* @method $this pTitleDirection(PanelTitleDirection $titleDirection) [The header title direction. Possible values are: 'up', 'down'. This property is valid only when the 'halign' property is set to 'left' or 'right'.]
32-
* @method $this pCollapsible(bool $collapsible) [Defines if to show collapsible button.]
33-
* @method $this pMinimizable(bool $minimizable) [Defines if to show minimizable button.]
34-
* @method $this pMaximizable(bool $maximizable) [Defines if to show maximizable button.]
35-
* @method $this pClosable(bool $closable) [Defines if to show closable button.]
36-
* @method $this pTools(string|array $tools) [Custom tools, possible values:<br>1) an array, each element contains iconCls and handler properties.<br>2) a selector that indicating the tools]
37-
* @method $this pHeader(string $header) [The panel header.]
38-
* @method $this pFooter(string $footer) [The panel footer.]
39-
* @method $this pOpenAnimation(PanelOpenAnimation $openAnimation) [The opening animation. Available values are: 'slide', 'fade', 'show'.]
40-
* @method $this pOpenDuration(int $openDuration) [The opening duration.]
41-
* @method $this pCloseAnimation(PanelCloseAnimation $closeAnimation) [The closing animation. Available values are: 'slide', 'fade', 'hide'.]
42-
* @method $this pCloseDuration(int $closeDuration) [The closing duration.]
43-
* @method $this pCollapsed(bool $collapsed) [Defines if the panel is collapsed at initialization.]
44-
* @method $this pMinimized(bool $minimized) [Defines if the panel is minimized at initialization.]
45-
* @method $this pMaximized(bool $maximized) [Defines if the panel is maximized at initialization.]
46-
* @method $this pClosed(bool $closed) [Defines if the panel is closed at initialization.]
47-
* @method $this pHref(string $href) [A URL to load remote data and then display in the panel. Notice that the content will not be loaded until the panel is open and expand.]
48-
* @method $this pCache(bool $cache) [True to cache the panel content that loaded from href.]
49-
* @method $this pLoadingMessage(string $loadingMessage) [When loading remote data show a message in the panel.]
50-
* @method $this pExtractor(Js $extractor) [Defines how to extract the content from ajax response, return extracted data.]
51-
* @method $this pMethod(string $method) [The http method to load content page.]
52-
* @method $this pQueryParams(array $queryParams) [The additional parameters that will be sent when loading a content page.]
53-
* @method $this pLoader(Js $loader) [Defines how to load content page from remote server. This function takes following parameters:<br>param: the parameter object to pass to remote server.<br>success(data): the callback function that will be called when retrieve data successfully.<br>error(): the callback function that will be called when failed to retrieve data.]
54-
*
55-
* @method $this pSelected(bool $selected) [ONLY FOR accordion. Set to true to expand the panel.]
56-
* @method $this pDisabled(bool $disabled) [ONLY FOR TABS. When set to true, the tab panel will be disabled.]
57-
*
58-
* Event
59-
* @method $this eOnBeforeLoad(Js $onBeforeLoad) [Fires before loading a content page, return false to ignore this action.]
60-
* @method $this eOnLoad(Js $onLoad) [Fires when remote data is loaded.]
61-
* @method $this eOnLoadError(Js $onLoadError) [Fires when some errors occur to load content page.]
62-
* @method $this eOnBeforeOpen(Js $onBeforeOpen) [Fires before panel is opened, return false to stop the open.]
63-
* @method $this eOnOpen(Js $onOpen) [Fires after panel is opened.]
64-
* @method $this eOnBeforeClose(Js $onBeforeClose) [Fires before panel is closed, return false to cancel the close. The panel declared below cannot be closed.]
65-
* @method $this eOnClose(Js $onClose) [Fires after panel is closed.]
66-
* @method $this eOnBeforeDestroy(Js $onBeforeDestroy) [Fires before panel is destroyed, return false to cancel the destroy.]
67-
* @method $this eOnDestroy(Js $onDestroy) [Fires after panel is destroyed.]
68-
* @method $this eOnBeforeCollapse(Js $onBeforeCollapse) [Fires before panel is collapsed, return false to stop the collapse.]
69-
* @method $this eOnCollapse(Js $onCollapse) [Fires after panel is collapsed.]
70-
* @method $this eOnBeforeExpand(Js $onBeforeExpand) [Fires before panel is expanded, return false to stop the expand.]
71-
* @method $this eOnExpand(Js $onExpand) [Fires after panel is expanded.]
72-
* @method $this eOnResize(Js $onResize) [Fires after panel is resized.<br>width: the new outer width<br>height: the new outer height]
73-
* @method $this eOnMove(Js $onMove) [Fires after panel is moved.<br>left: the new left position<br>top: the new top position]
74-
* @method $this eOnMaximize(Js $onMaximize) [Fires after the window has been maximized.]
75-
* @method $this eOnRestore(Js $onRestore) [Fires after the window has been restored to its original size.]
76-
* @method $this eOnMinimize(Js $onMinimize) [Fires after the window has been minimized.]
77-
*
78-
* Method
79-
* @method $this mOptions() [Return options property.]
80-
* @method $this mPanel() [Return the outer panel object.]
81-
* @method $this mHeader() [Return the panel header object.]
82-
* @method $this mFooter() [Return the panel footer object.]
83-
* @method $this mBody() [Return the panel body object.]
84-
* @method $this mSetTitle($title) [Set the title text of header.]
85-
* @method $this mOpen($forceOpen) [When forceOpen parameter set to true, the panel is opened bypass the onBeforeOpen callback.]
86-
* @method $this mClose($close) [When forceClose parameter set to true, the panel is closed bypass the onBeforeClose callback.]
87-
* @method $this mDestroy($forceDestroy) [When forceDestroy parameter set to true, the panel is destroyed bypass the onBeforeDestroy callback.]
88-
* @method $this mClear() [Clear the panel content.]
89-
* @method $this mRefresh($href) [Refresh the panel to load remote data. If the 'href' parameter is assigned, it will override the old 'href' property.]
90-
* @method $this mResize($options) [Set panel size and do layout. The options object contains following properties:<br>width: the new panel width<br>height: the new panel height<br>left: the new panel left position<br>top: the new panel top position]
91-
* @method $this mDoLayout() [Set the sizes of child components within the panel.]
92-
* @method $this mMove($options) [Move the panel to a new position. The options object contains following properties:<br>left: the new panel left position<br>top: the new panel top position]
93-
* @method $this mMaximize() [Fits the panel winthin its container.]
94-
* @method $this mMinimize() [Minimizing the panel.]
95-
* @method $this mRestore() [Restores the maximized panel back to its original size and position.]
96-
* @method $this mCollapse($animate) [Collapses the panel body. The 'animate' parameter value indicates if to use animation effect.]
97-
* @method $this mExpand($animate) [Expand the panel body. The 'animate' parameter value indicates if to use animation effect.]
98-
*/
997
class Panel extends Component
1008
{
1019
public const string COMPONENT_NAME = 'panel';
10+
use \Easyui\Traits\Panel;
10211
}

Components/PropertyGrid.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
* @method $this mExpandGroup($groupIndex) [Expand specified group. If the 'groupIndex' parameter is not assigned, expand all group.]
1818
* @method $this mCollapseGroup($groupIndex) [Collapse specified group. If the 'groupIndex' parameter is not assigned, collapse all group.]
1919
*/
20-
class PropertyGrid extends Datagrid
20+
class PropertyGrid extends DataGrid
2121
{
2222
public const string COMPONENT_NAME = 'propertygrid';
2323
}

Components/Region/Panel.php

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
<?php
2+
3+
namespace Easyui\Components\Region;
4+
5+
use Easyui\Enums\LayoutPanelExpandMode;
6+
use Easyui\Enums\LayoutPanelRegion;
7+
use Easyui\Js;
8+
use Easyui\Options;
9+
10+
/**
11+
* @method $this title(string $title) [The layout panel title text.]
12+
* @method $this region(LayoutPanelRegion $region) [Defines the layout panel position, the value is one of following: north, south, east, west, center.]
13+
* @method $this border(bool $border) [True to show layout panel border.]
14+
* @method $this split(bool $split) [True to show a split bar which user can change the panel size.]
15+
* @method $this iconCls(string $iconCls) [An icon CSS class to show a icon on panel header.]
16+
* @method $this href(string $href) [An URL to load data from remote server.]
17+
* @method $this collapsible(bool $collapsible) [Defines if to show collapsible button.]
18+
* @method $this minWidth(int $minWidth) [The minimum panel width.]
19+
* @method $this minHeight(int $minHeight) [The minimum panel height.]
20+
* @method $this maxWidth(int $maxWidth) [The maximum panel width.]
21+
* @method $this maxHeight(int $maxHeight) [The maximum panel height.]
22+
* @method $this expandMode(LayoutPanelExpandMode|null $expandMode) [The expanding mode when click on the collapsed panel. Possible values are 'float', 'dock' and null.<br> * float: the region panel will expand and float on the top.<br> dock: the region panel will expand and dock on the layout.<br>null: nothing happens.]
23+
* @method $this collapsedSize(int $collapsedSize) [The collapsed panel size.]
24+
* @method $this hideExpandTool(bool $hideExpandTool) [True to hide the expand tool on the collapsed panel.]
25+
* @method $this hideCollapsedContent(bool $hideCollapsedContent) [True to hide the title bar on the collapsed panel.]
26+
* @method $this collapsedContent(Js $collapsedContent) [The title content to display on the collapsed panel, possible values:<br>1) the title string.<br>2) a function that returns the title content.]
27+
* @method $this width($width) [The title content to display on the collapsed panel, possible values:<br>1) the title string.<br>2) a function that returns the title content.]
28+
*/
29+
class Panel extends Options
30+
{
31+
}

0 commit comments

Comments
 (0)