ezfw-core 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/components/EzBaseComponent.ts +648 -0
- package/components/EzComponent.ts +89 -0
- package/components/EzInput.module.scss +183 -0
- package/components/EzInput.ts +104 -0
- package/components/EzLabel.ts +22 -0
- package/components/EzOutlet.ts +181 -0
- package/components/HtmlWrapper.ts +305 -0
- package/components/avatar/EzAvatar.module.scss +200 -0
- package/components/avatar/EzAvatar.ts +130 -0
- package/components/badge/EzBadge.module.scss +202 -0
- package/components/badge/EzBadge.ts +77 -0
- package/components/button/EzButton.module.scss +402 -0
- package/components/button/EzButton.ts +175 -0
- package/components/button/EzButtonGroup.ts +48 -0
- package/components/card/EzCard.module.scss +71 -0
- package/components/card/EzCard.ts +120 -0
- package/components/chart/EzBarChart.ts +47 -0
- package/components/chart/EzChart.module.scss +14 -0
- package/components/chart/EzChart.ts +279 -0
- package/components/chart/EzDoughnutChart.ts +47 -0
- package/components/chart/EzLineChart.ts +53 -0
- package/components/checkbox/EzCheckbox.module.scss +145 -0
- package/components/checkbox/EzCheckbox.ts +115 -0
- package/components/dataview/EzDataView.module.scss +115 -0
- package/components/dataview/EzDataView.ts +355 -0
- package/components/dataview/modes/EzDataViewCards.ts +322 -0
- package/components/dataview/modes/EzDataViewGrid.ts +76 -0
- package/components/datepicker/EzDatePicker.module.scss +348 -0
- package/components/datepicker/EzDatePicker.ts +519 -0
- package/components/dialog/EzDialog.module.scss +180 -0
- package/components/dropdown/EzDropdown.module.scss +107 -0
- package/components/dropdown/EzDropdown.ts +235 -0
- package/components/feed/EzActivityFeed.module.scss +90 -0
- package/components/feed/EzActivityFeed.ts +78 -0
- package/components/form/EzForm.ts +364 -0
- package/components/form/EzValidators.test.js +421 -0
- package/components/form/EzValidators.ts +202 -0
- package/components/grid/EzGrid.scss +88 -0
- package/components/grid/EzGrid.ts +1085 -0
- package/components/grid/EzGridContainer.ts +104 -0
- package/components/grid/body/EzGridBody.scss +283 -0
- package/components/grid/body/EzGridBody.ts +549 -0
- package/components/grid/body/EzGridCell.ts +211 -0
- package/components/grid/body/EzGridRow.ts +196 -0
- package/components/grid/filter/EzGridFilters.scss +78 -0
- package/components/grid/filter/EzGridFilters.ts +285 -0
- package/components/grid/footer/EzGridFooter.scss +136 -0
- package/components/grid/footer/EzGridFooter.ts +448 -0
- package/components/grid/header/EzGridHeader.scss +199 -0
- package/components/grid/header/EzGridHeader.ts +430 -0
- package/components/grid/query/EzGridQuery.ts +81 -0
- package/components/grid/state/EzGridColumns.ts +155 -0
- package/components/grid/state/EzGridController.ts +470 -0
- package/components/grid/state/EzGridLifecycle.ts +136 -0
- package/components/grid/state/EzGridNormalizers.test.js +273 -0
- package/components/grid/state/EzGridNormalizers.ts +162 -0
- package/components/grid/state/EzGridParts.ts +233 -0
- package/components/grid/state/EzGridPersistence.ts +140 -0
- package/components/grid/state/EzGridRemote.test.js +573 -0
- package/components/grid/state/EzGridRemote.ts +335 -0
- package/components/grid/state/EzGridSelection.ts +231 -0
- package/components/grid/state/EzGridSort.ts +286 -0
- package/components/grid/title/EzGridActionBar.ts +98 -0
- package/components/grid/title/EzGridTitle.ts +114 -0
- package/components/grid/title/EzGridTitleBar.scss +65 -0
- package/components/grid/title/EzGridTitleBar.ts +87 -0
- package/components/grid/types.ts +607 -0
- package/components/panel/EzPanel.module.scss +133 -0
- package/components/panel/EzPanel.ts +147 -0
- package/components/radio/EzRadio.module.scss +190 -0
- package/components/radio/EzRadio.ts +149 -0
- package/components/select/EzSelect.module.scss +153 -0
- package/components/select/EzSelect.ts +238 -0
- package/components/skeleton/EzSkeleton.module.scss +95 -0
- package/components/skeleton/EzSkeleton.ts +70 -0
- package/components/store/EzStore.ts +344 -0
- package/components/switch/EzSwitch.module.scss +164 -0
- package/components/switch/EzSwitch.ts +117 -0
- package/components/tabs/EzTabPanel.module.scss +181 -0
- package/components/tabs/EzTabPanel.ts +402 -0
- package/components/textarea/EzTextarea.module.scss +131 -0
- package/components/textarea/EzTextarea.ts +161 -0
- package/components/timepicker/EzTimePicker.module.scss +282 -0
- package/components/timepicker/EzTimePicker.ts +540 -0
- package/components/toast/EzToast.module.scss +291 -0
- package/components/tooltip/EzTooltip.module.scss +124 -0
- package/components/tooltip/EzTooltip.ts +153 -0
- package/core/EzComponentTypes.ts +693 -0
- package/core/EzError.ts +63 -0
- package/core/EzModel.ts +268 -0
- package/core/EzTypes.ts +328 -0
- package/core/eventBus.ts +284 -0
- package/core/ez.ts +617 -0
- package/core/loader.ts +725 -0
- package/core/renderer.ts +1010 -0
- package/core/router.ts +490 -0
- package/core/services.ts +124 -0
- package/core/state.ts +142 -0
- package/core/utils.ts +81 -0
- package/package.json +51 -0
- package/services/RouteUI.js +17 -0
- package/services/crypto.js +64 -0
- package/services/dialog.js +222 -0
- package/services/fetchApi.js +63 -0
- package/services/firebase.js +30 -0
- package/services/toast.js +214 -0
- package/template/doc/EzDocs.js +15 -0
- package/template/doc/EzDocs.module.scss +627 -0
- package/template/doc/EzDocsController.js +164 -0
- package/template/doc/data/activityfeed/EzActivityFeedDoc.js +42 -0
- package/template/doc/data/avatar/EzAvatarDoc.js +71 -0
- package/template/doc/data/badge/EzBadgeDoc.js +92 -0
- package/template/doc/data/button/EzButtonDoc.js +77 -0
- package/template/doc/data/buttongroup/EzButtonGroupDoc.js +102 -0
- package/template/doc/data/card/EzCardDoc.js +39 -0
- package/template/doc/data/chart/EzChartDoc.js +60 -0
- package/template/doc/data/checkbox/EzCheckboxDoc.js +67 -0
- package/template/doc/data/component/EzComponentDoc.js +34 -0
- package/template/doc/data/cssmodules/CSSModulesDoc.js +70 -0
- package/template/doc/data/datepicker/EzDatePickerDoc.js +126 -0
- package/template/doc/data/dialog/EzDialogDoc.js +217 -0
- package/template/doc/data/dropdown/EzDropdownDoc.js +178 -0
- package/template/doc/data/form/EzFormDoc.js +90 -0
- package/template/doc/data/grid/EzGridDoc.js +99 -0
- package/template/doc/data/input/EzInputDoc.js +92 -0
- package/template/doc/data/label/EzLabelDoc.js +40 -0
- package/template/doc/data/model/EzModelDoc.js +53 -0
- package/template/doc/data/outlet/EzOutletDoc.js +63 -0
- package/template/doc/data/panel/EzPanelDoc.js +214 -0
- package/template/doc/data/radio/EzRadioDoc.js +174 -0
- package/template/doc/data/router/EzRouterDoc.js +75 -0
- package/template/doc/data/select/EzSelectDoc.js +37 -0
- package/template/doc/data/skeleton/EzSkeletonDoc.js +149 -0
- package/template/doc/data/switch/EzSwitchDoc.js +82 -0
- package/template/doc/data/tabpanel/EzTabPanelDoc.js +44 -0
- package/template/doc/data/textarea/EzTextareaDoc.js +131 -0
- package/template/doc/data/timepicker/EzTimePickerDoc.js +107 -0
- package/template/doc/data/tooltip/EzTooltipDoc.js +193 -0
- package/template/doc/data/validators/EzValidatorsDoc.js +37 -0
- package/template/doc/sidebar/EzDocsSidebar.js +32 -0
- package/template/doc/sidebar/category/EzDocsCategory.js +33 -0
- package/template/doc/sidebar/item/EzDocsComponentItem.js +24 -0
- package/template/doc/viewer/EzDocsViewer.js +18 -0
- package/template/doc/viewer/codepanel/EzDocsCodePanel.js +51 -0
- package/template/doc/viewer/content/EzDocsContent.js +315 -0
- package/template/doc/viewer/header/EzDocsViewerHeader.js +46 -0
- package/template/doc/viewer/showcase/EzDocsShowcase.js +59 -0
- package/template/doc/viewer/showcase/EzDocsShowcaseSection.js +25 -0
- package/template/doc/viewer/showcase/EzDocsVariantItem.js +29 -0
- package/template/doc/welcome/EzDocsWelcome.js +48 -0
- package/themes/ez-theme.scss +179 -0
- package/themes/nature-fresh.scss +169 -0
- package/types/global.d.ts +21 -0
- package/utils/cssModules.js +81 -0
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
.dataview {
|
|
2
|
+
display: flex;
|
|
3
|
+
flex-direction: column;
|
|
4
|
+
flex: 1;
|
|
5
|
+
min-height: 0;
|
|
6
|
+
background: var(--ez-surface);
|
|
7
|
+
border-radius: var(--ez-radius, 8px);
|
|
8
|
+
border: 1px solid var(--ez-border);
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
.toolbar {
|
|
12
|
+
display: flex;
|
|
13
|
+
align-items: center;
|
|
14
|
+
padding: 12px 16px;
|
|
15
|
+
border-bottom: 1px solid var(--ez-border);
|
|
16
|
+
gap: 12px;
|
|
17
|
+
background: var(--ez-surface);
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
.toolbarTools {
|
|
21
|
+
display: flex;
|
|
22
|
+
gap: 8px;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
.modeSwitch {
|
|
26
|
+
display: flex;
|
|
27
|
+
gap: 2px;
|
|
28
|
+
background: var(--ez-surface-secondary);
|
|
29
|
+
border-radius: 6px;
|
|
30
|
+
padding: 2px;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
.modeSwitchBtn {
|
|
34
|
+
padding: 6px 10px;
|
|
35
|
+
border: none;
|
|
36
|
+
background: transparent;
|
|
37
|
+
border-radius: 4px;
|
|
38
|
+
cursor: pointer;
|
|
39
|
+
color: var(--ez-text-secondary);
|
|
40
|
+
transition: all 0.15s ease;
|
|
41
|
+
|
|
42
|
+
&:hover {
|
|
43
|
+
color: var(--ez-text-primary);
|
|
44
|
+
background: var(--ez-surface);
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
&.active {
|
|
48
|
+
background: var(--ez-surface);
|
|
49
|
+
color: var(--ez-primary);
|
|
50
|
+
box-shadow: 0 1px 2px rgba(0, 0, 0, 0.05);
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
.content {
|
|
55
|
+
display: flex;
|
|
56
|
+
flex: 1;
|
|
57
|
+
min-height: 0;
|
|
58
|
+
overflow: hidden;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
.cardsContainer {
|
|
62
|
+
flex: 1;
|
|
63
|
+
overflow-y: auto;
|
|
64
|
+
padding: 16px;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
.cardsGrid {
|
|
68
|
+
display: grid;
|
|
69
|
+
gap: 16px;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
.cardsEmpty {
|
|
73
|
+
grid-column: 1 / -1;
|
|
74
|
+
text-align: center;
|
|
75
|
+
padding: 60px 20px;
|
|
76
|
+
color: var(--ez-text-tertiary);
|
|
77
|
+
|
|
78
|
+
.emptyIcon {
|
|
79
|
+
font-size: 48px;
|
|
80
|
+
margin-bottom: 16px;
|
|
81
|
+
opacity: 0.5;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
.emptyText {
|
|
85
|
+
font-size: 15px;
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
.footer {
|
|
90
|
+
display: flex;
|
|
91
|
+
align-items: center;
|
|
92
|
+
padding: 12px 16px;
|
|
93
|
+
border-top: 1px solid var(--ez-border);
|
|
94
|
+
background: var(--ez-surface);
|
|
95
|
+
gap: 16px;
|
|
96
|
+
font-size: 13px;
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
.footerNav {
|
|
100
|
+
display: flex;
|
|
101
|
+
gap: 4px;
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
.footerInfo {
|
|
105
|
+
color: var(--ez-text-secondary);
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
.loading {
|
|
109
|
+
display: flex;
|
|
110
|
+
align-items: center;
|
|
111
|
+
justify-content: center;
|
|
112
|
+
flex: 1;
|
|
113
|
+
min-height: 200px;
|
|
114
|
+
color: var(--ez-text-tertiary);
|
|
115
|
+
}
|
|
@@ -0,0 +1,355 @@
|
|
|
1
|
+
import { EzBaseComponent, EzBaseComponentConfig } from '../EzBaseComponent.js';
|
|
2
|
+
import { createEzStore } from '../store/EzStore.js';
|
|
3
|
+
import buttonStyles from '../button/EzButton.module.scss';
|
|
4
|
+
|
|
5
|
+
declare const ez: {
|
|
6
|
+
_createChildElements(items: unknown[], controller: string | null, state: unknown): Promise<Node[]>;
|
|
7
|
+
getControllerSync(name: string): EzController | null;
|
|
8
|
+
define(name: string, component: unknown): void;
|
|
9
|
+
};
|
|
10
|
+
|
|
11
|
+
interface EzController {
|
|
12
|
+
[key: string]: unknown;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
interface EzStore {
|
|
16
|
+
load(): Promise<void>;
|
|
17
|
+
state: {
|
|
18
|
+
data: unknown[];
|
|
19
|
+
loading: boolean;
|
|
20
|
+
page: number;
|
|
21
|
+
pageSize: number;
|
|
22
|
+
total: number;
|
|
23
|
+
};
|
|
24
|
+
on(event: string, callback: (...args: unknown[]) => void): () => void;
|
|
25
|
+
getTotalPages(): number;
|
|
26
|
+
isFirstPage(): boolean;
|
|
27
|
+
isLastPage(): boolean;
|
|
28
|
+
goToFirstPage(): void;
|
|
29
|
+
goToPrevPage(): void;
|
|
30
|
+
goToNextPage(): void;
|
|
31
|
+
goToLastPage(): void;
|
|
32
|
+
setPageSize(size: number): void;
|
|
33
|
+
reload(): Promise<void>;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
interface ToolConfig {
|
|
37
|
+
onClick?: string | ((dataView: EzDataView) => void);
|
|
38
|
+
[key: string]: unknown;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
interface GridConfig {
|
|
42
|
+
columns?: unknown[];
|
|
43
|
+
[key: string]: unknown;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
interface CardsConfig {
|
|
47
|
+
columns?: number | 'auto';
|
|
48
|
+
minWidth?: number;
|
|
49
|
+
gap?: number;
|
|
50
|
+
itemRender?: (item: unknown, index: number, meta: { isFirst: boolean; isLast: boolean; isEven: boolean }) => unknown;
|
|
51
|
+
[key: string]: unknown;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
interface StoreConfig {
|
|
55
|
+
remote?: unknown;
|
|
56
|
+
model?: string;
|
|
57
|
+
autoLoad?: boolean;
|
|
58
|
+
[key: string]: unknown;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
type DataViewMode = 'grid' | 'cards';
|
|
62
|
+
|
|
63
|
+
export interface EzDataViewConfig extends EzBaseComponentConfig {
|
|
64
|
+
modes?: DataViewMode[];
|
|
65
|
+
defaultMode?: DataViewMode;
|
|
66
|
+
store?: EzStore | StoreConfig;
|
|
67
|
+
remote?: unknown;
|
|
68
|
+
model?: string;
|
|
69
|
+
pageSize?: number;
|
|
70
|
+
autoLoad?: boolean;
|
|
71
|
+
grid?: GridConfig;
|
|
72
|
+
cards?: CardsConfig;
|
|
73
|
+
tools?: ToolConfig[];
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
interface EzGridInstance {
|
|
77
|
+
[key: string]: unknown;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
export class EzDataView extends EzBaseComponent {
|
|
81
|
+
declare config: EzDataViewConfig;
|
|
82
|
+
declare el: HTMLElement;
|
|
83
|
+
|
|
84
|
+
private _currentMode: DataViewMode;
|
|
85
|
+
private _store: EzStore | null;
|
|
86
|
+
private _modeBtns: Record<string, HTMLElement> = {};
|
|
87
|
+
private _contentEl: HTMLElement | null = null;
|
|
88
|
+
private _gridInstance: EzGridInstance | null = null;
|
|
89
|
+
private _cardsInstance: unknown = null;
|
|
90
|
+
|
|
91
|
+
constructor(config: EzDataViewConfig = {}) {
|
|
92
|
+
super(config);
|
|
93
|
+
|
|
94
|
+
this.config = config;
|
|
95
|
+
this.config.cls = [
|
|
96
|
+
...(Array.isArray(config.cls) ? config.cls : [config.cls]),
|
|
97
|
+
'ez-dataview'
|
|
98
|
+
].filter(Boolean) as string[];
|
|
99
|
+
|
|
100
|
+
this.config.flex = config.flex ?? 1;
|
|
101
|
+
|
|
102
|
+
this._currentMode = config.defaultMode || 'grid';
|
|
103
|
+
this._store = this._resolveStore(config);
|
|
104
|
+
|
|
105
|
+
this._buildParts();
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
private _resolveStore(config: EzDataViewConfig): EzStore | null {
|
|
109
|
+
if (config.store && typeof config.store === 'object' && typeof (config.store as EzStore).load === 'function') {
|
|
110
|
+
return config.store as EzStore;
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
if (config.store && typeof config.store === 'object') {
|
|
114
|
+
return createEzStore({
|
|
115
|
+
...(config.store as StoreConfig),
|
|
116
|
+
autoLoad: false
|
|
117
|
+
} as unknown as Parameters<typeof createEzStore>[0]) as unknown as EzStore;
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
if (config.remote) {
|
|
121
|
+
return createEzStore({
|
|
122
|
+
remote: config.remote,
|
|
123
|
+
model: config.model,
|
|
124
|
+
pageSize: config.pageSize || 25,
|
|
125
|
+
autoLoad: false
|
|
126
|
+
} as unknown as Parameters<typeof createEzStore>[0]) as unknown as EzStore;
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
return null;
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
private _buildParts(): void {
|
|
133
|
+
(this.config as { items: unknown[] }).items = [
|
|
134
|
+
this._buildToolbar(),
|
|
135
|
+
this._buildContent()
|
|
136
|
+
];
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
private _buildToolbar(): unknown {
|
|
140
|
+
const modes = this.config.modes || ['grid', 'cards'];
|
|
141
|
+
const tools = this.config.tools || [];
|
|
142
|
+
|
|
143
|
+
return {
|
|
144
|
+
eztype: 'EzComponent',
|
|
145
|
+
cls: 'ez-dataview-toolbar',
|
|
146
|
+
layout: 'hbox',
|
|
147
|
+
style: {
|
|
148
|
+
padding: '12px 16px',
|
|
149
|
+
borderBottom: '1px solid var(--ez-border)',
|
|
150
|
+
alignItems: 'center',
|
|
151
|
+
gap: '12px'
|
|
152
|
+
},
|
|
153
|
+
items: [
|
|
154
|
+
...(tools.length > 0 ? [{
|
|
155
|
+
eztype: 'EzComponent',
|
|
156
|
+
layout: 'hbox',
|
|
157
|
+
style: { gap: '8px' },
|
|
158
|
+
items: tools.map(tool => ({
|
|
159
|
+
...tool,
|
|
160
|
+
onClick: () => this._handleToolClick(tool)
|
|
161
|
+
}))
|
|
162
|
+
}] : []),
|
|
163
|
+
{ eztype: 'EzComponent', flex: 1 },
|
|
164
|
+
...(modes.length > 1 ? [this._buildModeSwitch(modes)] : [])
|
|
165
|
+
]
|
|
166
|
+
};
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
private _buildModeSwitch(modes: DataViewMode[]): unknown {
|
|
170
|
+
return {
|
|
171
|
+
eztype: 'EzComponent',
|
|
172
|
+
layout: 'hbox',
|
|
173
|
+
style: {
|
|
174
|
+
gap: '2px',
|
|
175
|
+
background: 'var(--ez-surface-secondary)',
|
|
176
|
+
borderRadius: '6px',
|
|
177
|
+
padding: '2px'
|
|
178
|
+
},
|
|
179
|
+
items: modes.map(mode => ({
|
|
180
|
+
eztype: 'EzButton',
|
|
181
|
+
variant: this._currentMode === mode ? 'primary' : 'ghost',
|
|
182
|
+
size: 'sm',
|
|
183
|
+
icon: mode === 'grid' ? 'fa-solid fa-table-cells' : 'fa-solid fa-grip',
|
|
184
|
+
_ezAfterRender: (el: HTMLElement) => {
|
|
185
|
+
this._modeBtns ??= {};
|
|
186
|
+
this._modeBtns[mode] = el;
|
|
187
|
+
},
|
|
188
|
+
onClick: () => this._setMode(mode)
|
|
189
|
+
}))
|
|
190
|
+
};
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
private _buildContent(): unknown {
|
|
194
|
+
const viewConfig = this._buildCurrentModeView();
|
|
195
|
+
(viewConfig as { _ezAfterRender: (el: HTMLElement) => void })._ezAfterRender = (el: HTMLElement) => {
|
|
196
|
+
this._contentEl = el;
|
|
197
|
+
};
|
|
198
|
+
return viewConfig;
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
private _buildCurrentModeView(): unknown {
|
|
202
|
+
if (this._currentMode === 'grid') {
|
|
203
|
+
return this._buildGridView();
|
|
204
|
+
} else {
|
|
205
|
+
return this._buildCardsView();
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
private _buildGridView(): unknown {
|
|
210
|
+
const gridConfig = this.config.grid || {};
|
|
211
|
+
|
|
212
|
+
if (this._store) {
|
|
213
|
+
return {
|
|
214
|
+
eztype: 'EzGrid',
|
|
215
|
+
flex: 1,
|
|
216
|
+
...gridConfig,
|
|
217
|
+
store: this._store,
|
|
218
|
+
autoLoad: this.config.autoLoad !== false,
|
|
219
|
+
title: null,
|
|
220
|
+
_ezAfterRender: (_el: HTMLElement, instance: EzGridInstance) => {
|
|
221
|
+
this._gridInstance = instance;
|
|
222
|
+
}
|
|
223
|
+
};
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
return {
|
|
227
|
+
eztype: 'EzGrid',
|
|
228
|
+
flex: 1,
|
|
229
|
+
...gridConfig,
|
|
230
|
+
model: this.config.model,
|
|
231
|
+
remote: this.config.remote,
|
|
232
|
+
autoLoad: this.config.autoLoad !== false,
|
|
233
|
+
pageSize: this.config.pageSize || 25,
|
|
234
|
+
title: null,
|
|
235
|
+
_ezAfterRender: (_el: HTMLElement, instance: EzGridInstance) => {
|
|
236
|
+
this._gridInstance = instance;
|
|
237
|
+
}
|
|
238
|
+
};
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
private _buildCardsView(): unknown {
|
|
242
|
+
const cardsConfig = this.config.cards || {};
|
|
243
|
+
|
|
244
|
+
return {
|
|
245
|
+
eztype: 'EzDataViewCards',
|
|
246
|
+
store: this._store,
|
|
247
|
+
cardsConfig,
|
|
248
|
+
_ezAfterRender: (_el: HTMLElement, instance: unknown) => {
|
|
249
|
+
this._cardsInstance = instance;
|
|
250
|
+
}
|
|
251
|
+
};
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
private _handleToolClick(tool: ToolConfig): void {
|
|
255
|
+
if (typeof tool.onClick === 'function') {
|
|
256
|
+
tool.onClick(this);
|
|
257
|
+
} else if (typeof tool.onClick === 'string') {
|
|
258
|
+
const ctrl = ez.getControllerSync(this.config.controller as string);
|
|
259
|
+
const method = ctrl?.[tool.onClick] as ((dataView: EzDataView) => void) | undefined;
|
|
260
|
+
method?.(this);
|
|
261
|
+
}
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
private async _setMode(mode: DataViewMode): Promise<void> {
|
|
265
|
+
if (this._currentMode === mode) return;
|
|
266
|
+
|
|
267
|
+
this._currentMode = mode;
|
|
268
|
+
this._updateModeButtons();
|
|
269
|
+
|
|
270
|
+
if (this._contentEl && this._contentEl.parentNode) {
|
|
271
|
+
const parent = this._contentEl.parentNode;
|
|
272
|
+
const oldContent = this._contentEl;
|
|
273
|
+
|
|
274
|
+
const viewConfig = this._buildCurrentModeView() as { _ezAfterRender?: (el: HTMLElement) => void };
|
|
275
|
+
viewConfig._ezAfterRender = (el: HTMLElement) => {
|
|
276
|
+
this._contentEl = el;
|
|
277
|
+
};
|
|
278
|
+
|
|
279
|
+
const children = await ez._createChildElements([viewConfig], null, null);
|
|
280
|
+
|
|
281
|
+
if (children[0] instanceof Node) {
|
|
282
|
+
parent.replaceChild(children[0], oldContent);
|
|
283
|
+
this._contentEl = children[0] as HTMLElement;
|
|
284
|
+
}
|
|
285
|
+
}
|
|
286
|
+
}
|
|
287
|
+
|
|
288
|
+
private _updateModeButtons(): void {
|
|
289
|
+
if (!this._modeBtns) return;
|
|
290
|
+
|
|
291
|
+
const primaryCls = buttonStyles.primary;
|
|
292
|
+
const ghostCls = buttonStyles.ghost;
|
|
293
|
+
|
|
294
|
+
for (const [mode, el] of Object.entries(this._modeBtns)) {
|
|
295
|
+
const isActive = mode === this._currentMode;
|
|
296
|
+
el.classList.toggle(primaryCls, isActive);
|
|
297
|
+
el.classList.toggle(ghostCls, !isActive);
|
|
298
|
+
}
|
|
299
|
+
}
|
|
300
|
+
|
|
301
|
+
getMode(): DataViewMode {
|
|
302
|
+
return this._currentMode;
|
|
303
|
+
}
|
|
304
|
+
|
|
305
|
+
getStore(): EzStore | null {
|
|
306
|
+
return this._store;
|
|
307
|
+
}
|
|
308
|
+
|
|
309
|
+
getGridInstance(): EzGridInstance | null {
|
|
310
|
+
return this._gridInstance;
|
|
311
|
+
}
|
|
312
|
+
|
|
313
|
+
async render(): Promise<HTMLElement> {
|
|
314
|
+
const el = document.createElement('div');
|
|
315
|
+
|
|
316
|
+
el.style.display = 'flex';
|
|
317
|
+
el.style.flexDirection = 'column';
|
|
318
|
+
el.style.minHeight = '0';
|
|
319
|
+
|
|
320
|
+
if (this.config.flex) {
|
|
321
|
+
el.style.flex = String(this.config.flex);
|
|
322
|
+
}
|
|
323
|
+
|
|
324
|
+
if (this.config.style) {
|
|
325
|
+
Object.assign(el.style, this.config.style);
|
|
326
|
+
}
|
|
327
|
+
|
|
328
|
+
this.applyCls(el);
|
|
329
|
+
|
|
330
|
+
const items = (this.config as { items?: unknown[] }).items;
|
|
331
|
+
if (items) {
|
|
332
|
+
const children = await ez._createChildElements(
|
|
333
|
+
items,
|
|
334
|
+
this.config.controller || null,
|
|
335
|
+
null
|
|
336
|
+
);
|
|
337
|
+
|
|
338
|
+
for (const child of children) {
|
|
339
|
+
if (child instanceof Node) {
|
|
340
|
+
el.appendChild(child);
|
|
341
|
+
}
|
|
342
|
+
}
|
|
343
|
+
}
|
|
344
|
+
|
|
345
|
+
this.el = el;
|
|
346
|
+
|
|
347
|
+
if (this._store && this.config.autoLoad !== false) {
|
|
348
|
+
this._store.load();
|
|
349
|
+
}
|
|
350
|
+
|
|
351
|
+
return el;
|
|
352
|
+
}
|
|
353
|
+
}
|
|
354
|
+
|
|
355
|
+
ez.define('EzDataView', EzDataView);
|