@zeyos/zx 2.1.0 → 2.2.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/CHANGELOG.md +39 -0
- package/README.md +15 -0
- package/dist/types/compat/base.d.ts +156 -0
- package/dist/types/compat/globals.d.ts +20 -0
- package/dist/types/compat/index.d.ts +128 -0
- package/dist/types/compat/map/basic.d.ts +175 -0
- package/dist/types/compat/map/data.d.ts +102 -0
- package/dist/types/compat/map/date-time.d.ts +80 -0
- package/dist/types/compat/map/factory.d.ts +9 -0
- package/dist/types/compat/map/form.d.ts +98 -0
- package/dist/types/compat/map/helpers.d.ts +12 -0
- package/dist/types/compat/map/http.d.ts +36 -0
- package/dist/types/compat/map/layout.d.ts +106 -0
- package/dist/types/compat/map/options.d.ts +80 -0
- package/dist/types/compat/map/select.d.ts +95 -0
- package/dist/types/compat/map/stubs.d.ts +32 -0
- package/dist/types/compat/map/utilities.d.ts +37 -0
- package/dist/types/compat-entry.d.ts +5 -0
- package/dist/types/components/badge/badge.d.ts +46 -0
- package/dist/types/components/breadcrumb/breadcrumb.d.ts +200 -0
- package/dist/types/components/button/button.d.ts +42 -0
- package/dist/types/components/check-button/check-button.d.ts +98 -0
- package/dist/types/components/checklist/checklist.d.ts +143 -0
- package/dist/types/components/checklist/field-adapter.d.ts +5 -0
- package/dist/types/components/context-menu/context-menu.d.ts +130 -0
- package/dist/types/components/copy/copy-button.d.ts +48 -0
- package/dist/types/components/copy/copy-input.d.ts +91 -0
- package/dist/types/components/data-filter/data-filter.d.ts +250 -0
- package/dist/types/components/data-filter/filter-core.d.ts +52 -0
- package/dist/types/components/date-picker/date-picker.d.ts +137 -0
- package/dist/types/components/date-picker/date-range-picker.d.ts +350 -0
- package/dist/types/components/date-picker/field-adapter.d.ts +6 -0
- package/dist/types/components/date-picker/month-picker.d.ts +75 -0
- package/dist/types/components/date-picker/range-field-adapter.d.ts +7 -0
- package/dist/types/components/date-picker/time-picker.d.ts +127 -0
- package/dist/types/components/datebox/date-range-box.d.ts +218 -0
- package/dist/types/components/datebox/datebox.d.ts +160 -0
- package/dist/types/components/datebox/field-adapter.d.ts +5 -0
- package/dist/types/components/dialog/dialog.d.ts +284 -0
- package/dist/types/components/dropdown/dropdown.d.ts +118 -0
- package/dist/types/components/empty-state/empty-state.d.ts +38 -0
- package/dist/types/components/field/field.d.ts +231 -0
- package/dist/types/components/field-upload/field-adapter.d.ts +5 -0
- package/dist/types/components/field-upload/field-upload.d.ts +213 -0
- package/dist/types/components/fieldset/fieldset.d.ts +125 -0
- package/dist/types/components/finder/finder.d.ts +252 -0
- package/dist/types/components/form/form.d.ts +194 -0
- package/dist/types/components/groupbox/groupbox.d.ts +89 -0
- package/dist/types/components/layout/layout.d.ts +132 -0
- package/dist/types/components/loading/inline-loading.d.ts +86 -0
- package/dist/types/components/loading/progress-bar.d.ts +168 -0
- package/dist/types/components/loading/spinner.d.ts +34 -0
- package/dist/types/components/master-panel/master-panel.d.ts +112 -0
- package/dist/types/components/menu-button/menu-button.d.ts +142 -0
- package/dist/types/components/message/message.d.ts +212 -0
- package/dist/types/components/modal/modal.d.ts +105 -0
- package/dist/types/components/multi-value-editor/field-adapter.d.ts +5 -0
- package/dist/types/components/multi-value-editor/multi-value-editor.d.ts +66 -0
- package/dist/types/components/navigation-bar/navigation-bar.d.ts +229 -0
- package/dist/types/components/number-field/field-adapter.d.ts +5 -0
- package/dist/types/components/number-field/number-field.d.ts +292 -0
- package/dist/types/components/pagination/pagination.d.ts +267 -0
- package/dist/types/components/panel/panel.d.ts +194 -0
- package/dist/types/components/permission/permission.d.ts +93 -0
- package/dist/types/components/rating/field-adapter.d.ts +5 -0
- package/dist/types/components/rating/rating.d.ts +213 -0
- package/dist/types/components/search/search.d.ts +98 -0
- package/dist/types/components/select/field-adapter.d.ts +5 -0
- package/dist/types/components/select/filter.d.ts +11 -0
- package/dist/types/components/select/select.d.ts +235 -0
- package/dist/types/components/skeleton/skeleton.d.ts +97 -0
- package/dist/types/components/slider/field-adapter.d.ts +5 -0
- package/dist/types/components/slider/slider.d.ts +216 -0
- package/dist/types/components/split-view/split-view.d.ts +335 -0
- package/dist/types/components/stepper/stepper.d.ts +314 -0
- package/dist/types/components/stepper/steps.d.ts +131 -0
- package/dist/types/components/tabbox/tabbox.d.ts +230 -0
- package/dist/types/components/table/sort.d.ts +49 -0
- package/dist/types/components/table/table.d.ts +872 -0
- package/dist/types/components/tag-picker/field-adapter.d.ts +5 -0
- package/dist/types/components/tag-picker/tag-picker.d.ts +375 -0
- package/dist/types/components/timebox/field-adapter.d.ts +5 -0
- package/dist/types/components/timebox/timebox.d.ts +121 -0
- package/dist/types/components/toggle/field-adapter.d.ts +5 -0
- package/dist/types/components/toggle/toggle.d.ts +94 -0
- package/dist/types/components/toolbar/toolbar.d.ts +230 -0
- package/dist/types/components/tooltip/tooltip.d.ts +183 -0
- package/dist/types/components/tree/hierarchy.d.ts +113 -0
- package/dist/types/components/tree/tree.d.ts +383 -0
- package/dist/types/components/truncate/truncate.d.ts +61 -0
- package/dist/types/components/value-list/field-adapter.d.ts +5 -0
- package/dist/types/components/value-list/value-list.d.ts +143 -0
- package/dist/types/core/breakpoint.d.ts +68 -0
- package/dist/types/core/component.d.ts +115 -0
- package/dist/types/core/date.d.ts +50 -0
- package/dist/types/core/dom.d.ts +86 -0
- package/dist/types/core/export.d.ts +70 -0
- package/dist/types/core/fontawesome.d.ts +107 -0
- package/dist/types/core/format.d.ts +107 -0
- package/dist/types/core/http.d.ts +122 -0
- package/dist/types/core/i18n.d.ts +35 -0
- package/dist/types/core/icons.d.ts +137 -0
- package/dist/types/core/keyboard.d.ts +72 -0
- package/dist/types/core/position.d.ts +45 -0
- package/dist/types/core/storage.d.ts +46 -0
- package/dist/types/core/util.d.ts +117 -0
- package/dist/types/elements/define.d.ts +73 -0
- package/dist/types/elements/reflect.d.ts +27 -0
- package/dist/types/index.d.ts +79 -0
- package/dist/types/zeyos/connect.d.ts +65 -0
- package/dist/types/zeyos/form.d.ts +140 -0
- package/dist/types/zeyos/icons.d.ts +104 -0
- package/dist/types/zeyos/index.d.ts +12 -0
- package/dist/types/zeyos/modules.d.ts +110 -0
- package/dist/types/zeyos/query.d.ts +157 -0
- package/dist/types/zeyos/schema.d.ts +79 -0
- package/dist/types/zeyos/select.d.ts +167 -0
- package/dist/types/zeyos/table.d.ts +205 -0
- package/dist/zx-compat.esm.js +362 -33
- package/dist/zx-compat.esm.min.js +1 -1
- package/dist/zx-compat.global.js +359 -67
- package/dist/zx-compat.global.min.js +3 -3
- package/dist/zx-zeyos.esm.js +342 -43
- package/dist/zx-zeyos.esm.min.js +1 -1
- package/dist/zx.css +68 -6
- package/dist/zx.esm.js +346 -67
- package/dist/zx.esm.min.js +3 -3
- package/dist/zx.global.js +346 -67
- package/dist/zx.global.min.js +3 -3
- package/dist/zx.min.css +1 -1
- package/docs/api.json +48 -2
- package/docs/llms.md +28 -0
- package/package.json +37 -9
- package/src/compat/base.js +291 -0
- package/src/compat/globals.js +165 -0
- package/src/compat/index.js +84 -0
- package/src/compat/map/basic.js +464 -0
- package/src/compat/map/data.js +232 -0
- package/src/compat/map/date-time.js +177 -0
- package/src/compat/map/factory.js +45 -0
- package/src/compat/map/form.js +330 -0
- package/src/compat/map/helpers.js +46 -0
- package/src/compat/map/http.js +117 -0
- package/src/compat/map/layout.js +256 -0
- package/src/compat/map/options.js +267 -0
- package/src/compat/map/select.js +198 -0
- package/src/compat/map/stubs.js +26 -0
- package/src/compat/map/utilities.js +113 -0
- package/src/compat-entry.js +11 -0
- package/src/components/badge/badge.css +147 -0
- package/src/components/badge/badge.js +92 -0
- package/src/components/breadcrumb/breadcrumb.css +105 -0
- package/src/components/breadcrumb/breadcrumb.js +331 -0
- package/src/components/button/button.css +104 -0
- package/src/components/button/button.js +76 -0
- package/src/components/check-button/check-button.css +66 -0
- package/src/components/check-button/check-button.js +167 -0
- package/src/components/checklist/checklist.css +65 -0
- package/src/components/checklist/checklist.js +282 -0
- package/src/components/checklist/field-adapter.js +46 -0
- package/src/components/context-menu/context-menu.css +54 -0
- package/src/components/context-menu/context-menu.js +334 -0
- package/src/components/copy/copy-button.css +27 -0
- package/src/components/copy/copy-button.js +78 -0
- package/src/components/copy/copy-input.css +59 -0
- package/src/components/copy/copy-input.js +123 -0
- package/src/components/data-filter/data-filter.css +53 -0
- package/src/components/data-filter/data-filter.js +400 -0
- package/src/components/data-filter/filter-core.js +128 -0
- package/src/components/date-picker/date-picker.css +181 -0
- package/src/components/date-picker/date-picker.js +500 -0
- package/src/components/date-picker/date-range-picker.css +264 -0
- package/src/components/date-picker/date-range-picker.js +990 -0
- package/src/components/date-picker/field-adapter.js +36 -0
- package/src/components/date-picker/month-picker.js +223 -0
- package/src/components/date-picker/range-field-adapter.js +31 -0
- package/src/components/date-picker/time-picker.css +191 -0
- package/src/components/date-picker/time-picker.js +406 -0
- package/src/components/datebox/date-range-box.css +128 -0
- package/src/components/datebox/date-range-box.js +492 -0
- package/src/components/datebox/datebox.css +108 -0
- package/src/components/datebox/datebox.js +358 -0
- package/src/components/datebox/field-adapter.js +34 -0
- package/src/components/dialog/dialog.css +74 -0
- package/src/components/dialog/dialog.js +450 -0
- package/src/components/dropdown/dropdown.css +24 -0
- package/src/components/dropdown/dropdown.js +288 -0
- package/src/components/empty-state/empty-state.css +80 -0
- package/src/components/empty-state/empty-state.js +92 -0
- package/src/components/field/field.css +127 -0
- package/src/components/field/field.js +605 -0
- package/src/components/field-upload/field-adapter.js +21 -0
- package/src/components/field-upload/field-upload.css +108 -0
- package/src/components/field-upload/field-upload.js +475 -0
- package/src/components/fieldset/fieldset.css +37 -0
- package/src/components/fieldset/fieldset.js +307 -0
- package/src/components/finder/finder.css +98 -0
- package/src/components/finder/finder.js +509 -0
- package/src/components/form/form.css +32 -0
- package/src/components/form/form.js +302 -0
- package/src/components/groupbox/groupbox.css +51 -0
- package/src/components/groupbox/groupbox.js +199 -0
- package/src/components/layout/layout.css +117 -0
- package/src/components/layout/layout.js +136 -0
- package/src/components/loading/inline-loading.css +34 -0
- package/src/components/loading/inline-loading.js +140 -0
- package/src/components/loading/progress-bar.css +115 -0
- package/src/components/loading/progress-bar.js +259 -0
- package/src/components/loading/spinner.css +58 -0
- package/src/components/loading/spinner.js +57 -0
- package/src/components/master-panel/master-panel.css +51 -0
- package/src/components/master-panel/master-panel.js +203 -0
- package/src/components/menu-button/menu-button.css +49 -0
- package/src/components/menu-button/menu-button.js +294 -0
- package/src/components/message/message.css +122 -0
- package/src/components/message/message.js +499 -0
- package/src/components/modal/modal.css +47 -0
- package/src/components/modal/modal.js +203 -0
- package/src/components/multi-value-editor/field-adapter.js +44 -0
- package/src/components/multi-value-editor/multi-value-editor.css +56 -0
- package/src/components/multi-value-editor/multi-value-editor.js +170 -0
- package/src/components/navigation-bar/navigation-bar.css +130 -0
- package/src/components/navigation-bar/navigation-bar.js +450 -0
- package/src/components/number-field/field-adapter.js +40 -0
- package/src/components/number-field/number-field.css +77 -0
- package/src/components/number-field/number-field.js +545 -0
- package/src/components/pagination/pagination.css +95 -0
- package/src/components/pagination/pagination.js +481 -0
- package/src/components/panel/panel.css +123 -0
- package/src/components/panel/panel.js +336 -0
- package/src/components/permission/permission.css +47 -0
- package/src/components/permission/permission.js +198 -0
- package/src/components/rating/field-adapter.js +34 -0
- package/src/components/rating/rating.css +97 -0
- package/src/components/rating/rating.js +395 -0
- package/src/components/search/search.css +70 -0
- package/src/components/search/search.js +193 -0
- package/src/components/select/field-adapter.js +24 -0
- package/src/components/select/filter.js +39 -0
- package/src/components/select/select.css +180 -0
- package/src/components/select/select.js +663 -0
- package/src/components/skeleton/skeleton.css +76 -0
- package/src/components/skeleton/skeleton.js +139 -0
- package/src/components/slider/field-adapter.js +36 -0
- package/src/components/slider/slider.css +181 -0
- package/src/components/slider/slider.js +399 -0
- package/src/components/split-view/split-view.css +139 -0
- package/src/components/split-view/split-view.js +806 -0
- package/src/components/stepper/stepper.css +234 -0
- package/src/components/stepper/stepper.js +459 -0
- package/src/components/stepper/steps.js +131 -0
- package/src/components/tabbox/tabbox.css +281 -0
- package/src/components/tabbox/tabbox.js +484 -0
- package/src/components/table/sort.js +85 -0
- package/src/components/table/table.css +364 -0
- package/src/components/table/table.js +1693 -0
- package/src/components/tag-picker/field-adapter.js +35 -0
- package/src/components/tag-picker/tag-picker.css +169 -0
- package/src/components/tag-picker/tag-picker.js +837 -0
- package/src/components/timebox/field-adapter.js +24 -0
- package/src/components/timebox/timebox.css +51 -0
- package/src/components/timebox/timebox.js +276 -0
- package/src/components/toggle/field-adapter.js +24 -0
- package/src/components/toggle/toggle.css +66 -0
- package/src/components/toggle/toggle.js +150 -0
- package/src/components/toolbar/toolbar.css +81 -0
- package/src/components/toolbar/toolbar.js +511 -0
- package/src/components/tooltip/tooltip.css +36 -0
- package/src/components/tooltip/tooltip.js +420 -0
- package/src/components/tree/hierarchy.js +151 -0
- package/src/components/tree/tree.css +99 -0
- package/src/components/tree/tree.js +784 -0
- package/src/components/truncate/truncate.css +20 -0
- package/src/components/truncate/truncate.js +92 -0
- package/src/components/value-list/field-adapter.js +24 -0
- package/src/components/value-list/value-list.css +108 -0
- package/src/components/value-list/value-list.js +336 -0
- package/src/core/breakpoint.js +150 -0
- package/src/core/component.js +292 -0
- package/src/core/date.js +216 -0
- package/src/core/dom.js +260 -0
- package/src/core/export.js +204 -0
- package/src/core/fontawesome.js +177 -0
- package/src/core/format.js +283 -0
- package/src/core/http.js +246 -0
- package/src/core/i18n.js +83 -0
- package/src/core/icons.js +283 -0
- package/src/core/keyboard.js +240 -0
- package/src/core/position.js +177 -0
- package/src/core/storage.js +175 -0
- package/src/core/util.js +336 -0
- package/src/elements/define.js +715 -0
- package/src/elements/reflect.js +79 -0
- package/src/index.js +131 -0
- package/src/zeyos/connect.js +142 -0
- package/src/zeyos/form.js +254 -0
- package/src/zeyos/icons.js +92 -0
- package/src/zeyos/index.js +21 -0
- package/src/zeyos/modules.js +269 -0
- package/src/zeyos/query.js +199 -0
- package/src/zeyos/schema.js +474 -0
- package/src/zeyos/select.js +175 -0
- package/src/zeyos/table.js +272 -0
- package/styles/base.css +124 -0
- package/styles/icons.css +34 -0
- package/styles/tokens/dark.css +84 -0
- package/styles/tokens/density.css +9 -0
- package/styles/tokens/global.css +80 -0
- package/styles/tokens/modules.css +109 -0
- package/styles/tokens/semantic.css +49 -0
- package/styles/zx.css +61 -0
|
@@ -0,0 +1,232 @@
|
|
|
1
|
+
import {
|
|
2
|
+
Checklist as ZxChecklist,
|
|
3
|
+
DataFilter as ZxDataFilter,
|
|
4
|
+
Http,
|
|
5
|
+
Permission as ZxPermission,
|
|
6
|
+
Table as ZxTable
|
|
7
|
+
} from '../../index.js';
|
|
8
|
+
import { GxWrapper } from '../base.js';
|
|
9
|
+
import { LEGACY_EVENT_ARGS, translateChecklistOptions, translateTableOptions } from './options.js';
|
|
10
|
+
|
|
11
|
+
/** Shared Checklist wrapper. */
|
|
12
|
+
class ChecklistBase extends GxWrapper {
|
|
13
|
+
static legacyName = 'gx.zeyos.Checklist';
|
|
14
|
+
|
|
15
|
+
/** @param {Element|string|null} display @param {Record<string, any>} [options={}] */
|
|
16
|
+
constructor(display, options = {}) {
|
|
17
|
+
super(options, { data: [], listValue: 'ID', listFormat: 'name', listActive: 'on' });
|
|
18
|
+
const translated = translateChecklistOptions(options);
|
|
19
|
+
translated.items = Array.isArray(options.data) ? options.data : (Array.isArray(options.items) ? options.items : []);
|
|
20
|
+
translated.load = options.url ? () => this._load(options.url, options.requestData) : null;
|
|
21
|
+
const component = new ZxChecklist(display, translated);
|
|
22
|
+
this._http = null;
|
|
23
|
+
this._attach(component, {
|
|
24
|
+
events: {
|
|
25
|
+
complete: { type: 'loaded', args: (detail) => [detail.items] },
|
|
26
|
+
change: { type: 'change', args: (detail) => [detail.values] }
|
|
27
|
+
},
|
|
28
|
+
ui: { frame: 'root', table: 'list', tbody: 'list', search: 'search' },
|
|
29
|
+
setters: { data: 'setData' }
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
/** @returns {unknown[]} */
|
|
34
|
+
getValues(key) {
|
|
35
|
+
const values = this._zx.getValues();
|
|
36
|
+
return key == null ? values : values.map((value) => value?.[key]).filter((value) => value != null);
|
|
37
|
+
}
|
|
38
|
+
/** @param {unknown[]} values @returns {unknown[]} */
|
|
39
|
+
setValues(values) { this._zx.setValues(values ?? []); return values; }
|
|
40
|
+
/** @returns {this} */
|
|
41
|
+
reset() { this._zx.uncheckAll(); return this; }
|
|
42
|
+
/** @param {string} query @returns {this} */
|
|
43
|
+
search(query) { this._zx.search(query); return this; }
|
|
44
|
+
/** @param {unknown[]} rows @returns {this} */
|
|
45
|
+
setData(rows) { this._zx.setItems(Array.isArray(rows) ? rows : []); return this; }
|
|
46
|
+
/** @param {string} [url] @param {Record<string, unknown>} [data] @returns {Promise<this>} */
|
|
47
|
+
async load(url = this.options.url, data = this.options.requestData) {
|
|
48
|
+
const rows = await this._load(url, data);
|
|
49
|
+
this._zx.setItems(rows);
|
|
50
|
+
this.fireEvent('complete', [rows]);
|
|
51
|
+
return this;
|
|
52
|
+
}
|
|
53
|
+
/** Bootstrap alias. @param {string} [url] @param {Record<string, unknown>} [data] @param {Function} [callback] @returns {Promise<this>} */
|
|
54
|
+
async loadFromURL(url, data, callback) { const result = await this.load(url, data); callback?.(this); return result; }
|
|
55
|
+
|
|
56
|
+
/** @param {string} url @param {Record<string, unknown>} data @returns {Promise<unknown[]>} */
|
|
57
|
+
async _load(url, data) {
|
|
58
|
+
this._http ??= new Http({ headers: this.options.requestHeader ?? {} });
|
|
59
|
+
try {
|
|
60
|
+
const method = String(this.options.method ?? 'GET').toUpperCase();
|
|
61
|
+
let result = await this._http.request(String(url ?? ''), method === 'GET'
|
|
62
|
+
? { method, query: data ?? {} }
|
|
63
|
+
: { method, data: data ?? {} });
|
|
64
|
+
if (typeof this.options.decodeResponse === 'function') result = this.options.decodeResponse(result);
|
|
65
|
+
return Array.isArray(result) ? result : [];
|
|
66
|
+
} catch (error) {
|
|
67
|
+
this.fireEvent('failure', [error]);
|
|
68
|
+
throw error;
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
/** Legacy ZeyOS checklist. */
|
|
74
|
+
export class Checklist extends ChecklistBase { static legacyName = 'gx.zeyos.Checklist'; }
|
|
75
|
+
/** Legacy bootstrap checklist. */
|
|
76
|
+
export class BootstrapChecklist extends ChecklistBase { static legacyName = 'gx.bootstrap.Checklist'; }
|
|
77
|
+
|
|
78
|
+
/** Legacy permission selector. */
|
|
79
|
+
export class Permission extends GxWrapper {
|
|
80
|
+
static legacyName = 'gx.zeyos.Permission';
|
|
81
|
+
|
|
82
|
+
/** @param {Element|string|null} display @param {Record<string, any>} [options={}] */
|
|
83
|
+
constructor(display, options = {}) {
|
|
84
|
+
super(options, { value: true, groups: [] });
|
|
85
|
+
const component = new ZxPermission(display, {
|
|
86
|
+
value: options.value ?? true,
|
|
87
|
+
groups: options.groups ?? options.data ?? [],
|
|
88
|
+
groupsValueKey: options.groupsValueKey ?? options.elementIndex ?? 'ID',
|
|
89
|
+
groupsLabelKey: options.groupsLabelKey ?? options.elementLabel ?? 'name'
|
|
90
|
+
});
|
|
91
|
+
this._attach(component, { events: { change: { type: 'change', args: (detail) => [detail.value] } }, setters: { value: 'set' } });
|
|
92
|
+
}
|
|
93
|
+
/** @returns {unknown} */ get() { return this._zx.get(); }
|
|
94
|
+
/** @param {unknown} value @param {boolean} [silent=false] @returns {this} */ set(value, silent = false) { this._zx.set(value, { silent }); return this; }
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
/** Shared full Table wrapper. */
|
|
98
|
+
class TableBase extends GxWrapper {
|
|
99
|
+
static legacyName = 'gx.zeyos.Table';
|
|
100
|
+
|
|
101
|
+
/** @param {Element|string|null} display @param {Record<string, any>} [options={}] */
|
|
102
|
+
constructor(display, options = {}) {
|
|
103
|
+
super(options, { cols: [], data: [] });
|
|
104
|
+
const source = { ...options };
|
|
105
|
+
if (typeof options.structure === 'function') source.structure = (row, index) => options.structure(row, index, this);
|
|
106
|
+
const translated = translateTableOptions(source, adaptCell);
|
|
107
|
+
const component = new ZxTable(display, translated);
|
|
108
|
+
this._cols = Array.isArray(options.cols) ? options.cols.map((column) => ({ ...column })) : [];
|
|
109
|
+
this._filter = translated.sort ? this._legacyColumn(translated.sort.id) : null;
|
|
110
|
+
if (this._filter) this._filter.mode = translated.sort.dir;
|
|
111
|
+
this._attach(component, {
|
|
112
|
+
events: {
|
|
113
|
+
click: { type: 'rowclick', args: (detail) => LEGACY_EVENT_ARGS.tableClick(detail) },
|
|
114
|
+
dblclick: { type: 'rowdblclick', args: (detail) => LEGACY_EVENT_ARGS.tableClick(detail) },
|
|
115
|
+
filter: { type: 'sort', args: (detail) => {
|
|
116
|
+
const column = this._legacyColumn(detail.id); column.mode = detail.dir; this._filter = column;
|
|
117
|
+
return [column, detail.dir];
|
|
118
|
+
} },
|
|
119
|
+
complete: { type: 'datachange', args: (detail) => [detail.rows] }
|
|
120
|
+
},
|
|
121
|
+
ui: { table: () => component._table, tbody: () => component._tbody, thead: () => component._thead, tableDiv: () => component._scroll },
|
|
122
|
+
setters: { data: 'setData', height: 'setHeight' }
|
|
123
|
+
});
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
/** @param {unknown[]} data @returns {this} */ setData(data) { this._zx.setData(Array.isArray(data) ? data : []); return this; }
|
|
127
|
+
/** @param {unknown[]|unknown} data @returns {this} */ addData(data) { this._zx.addData(Array.isArray(data) ? data : [data]); return this; }
|
|
128
|
+
/** @returns {this} */ empty() { this._zx.empty(); return this; }
|
|
129
|
+
/** @param {Record<string, any>|string} column @param {'asc'|'desc'} [mode] @param {boolean} [noEvent=false] @returns {this} */
|
|
130
|
+
setSort(column, mode, noEvent = false) {
|
|
131
|
+
const id = typeof column === 'object' ? String(column.id) : String(column);
|
|
132
|
+
this._zx.setSort(id, mode, { silent: Boolean(noEvent) });
|
|
133
|
+
this._filter = this._legacyColumn(id); this._filter.mode = this._zx._sort?.dir ?? mode ?? 'asc';
|
|
134
|
+
return this;
|
|
135
|
+
}
|
|
136
|
+
/** @returns {Record<string, any>|false} */ getFilter() { return this._filter ?? false; }
|
|
137
|
+
/** @returns {unknown[]} */ getData() { return this._zx.getData(); }
|
|
138
|
+
/** @param {unknown} height @returns {this} */ setHeight(height) { const value = typeof height === 'number' ? `${height}px` : String(height); this._zx._scroll.style.blockSize = value; return this; }
|
|
139
|
+
/** @param {string} id @returns {Record<string, any>} */ _legacyColumn(id) { return this._cols.find((column) => String(column.id) === String(id)) ?? { id }; }
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
/** Legacy ZeyOS table. */
|
|
143
|
+
export class Table extends TableBase { static legacyName = 'gx.zeyos.Table'; }
|
|
144
|
+
/** Legacy bootstrap table. */
|
|
145
|
+
export class BootstrapTable extends TableBase { static legacyName = 'gx.bootstrap.Table'; }
|
|
146
|
+
|
|
147
|
+
/** Legacy SimpleTable data facade. */
|
|
148
|
+
export class SimpleTable extends GxWrapper {
|
|
149
|
+
static legacyName = 'gx.ui.SimpleTable';
|
|
150
|
+
|
|
151
|
+
/** @param {Element|string|Record<string, any>|null} display @param {Record<string, any>} [options={}] */
|
|
152
|
+
constructor(display, options = {}) {
|
|
153
|
+
if (display && typeof display === 'object' && !display.nodeType && !Array.isArray(display)) {
|
|
154
|
+
options = display; display = null;
|
|
155
|
+
}
|
|
156
|
+
super(options, { cols: [], data: [] });
|
|
157
|
+
const source = { ...options, rowId: (row) => row };
|
|
158
|
+
if (typeof options.structure === 'function') source.structure = (row, index) => options.structure(row, index, this);
|
|
159
|
+
const component = new ZxTable(/** @type {Element|string|null} */ (display), translateTableOptions(source, adaptCell));
|
|
160
|
+
this._attach(component, {
|
|
161
|
+
events: { click: { type: 'rowclick', args: (detail) => [detail.row, detail.index] } },
|
|
162
|
+
ui: { table: () => component._table, tbody: () => component._tbody, thead: () => component._thead }
|
|
163
|
+
});
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
/** @param {unknown[]} data @returns {this} */ setData(data) { this._zx.setData(Array.isArray(data) ? data : []); return this; }
|
|
167
|
+
/** @param {unknown[]} data @returns {this} */ addData(data) { this._zx.addData(Array.isArray(data) ? data : [data]); return this; }
|
|
168
|
+
/** @param {unknown} row @param {number} [index] @returns {HTMLTableRowElement|null} */
|
|
169
|
+
createRow(row, index = this._zx.getData().length) {
|
|
170
|
+
const data = this._zx.getData(); data.splice(Math.max(0, index), 0, row); this._zx.setData(data);
|
|
171
|
+
return this.display('tbody')?.querySelectorAll?.('tr[data-row]')?.[index] ?? null;
|
|
172
|
+
}
|
|
173
|
+
/** @param {unknown} row @param {number} [index] @returns {HTMLTableRowElement|null} */ addRow(row, index) { return this.createRow(row, index); }
|
|
174
|
+
/** @param {unknown} row @param {number} index @returns {HTMLTableRowElement|null} */
|
|
175
|
+
updateRow(row, index) { const data = this._zx.getData(); if (index >= 0 && index < data.length) data[index] = row; this._zx.setData(data); return this.display('tbody')?.querySelectorAll?.('tr[data-row]')?.[index] ?? null; }
|
|
176
|
+
/** @param {number} index @returns {this} */ removeRow(index) { const data = this._zx.getData(); data.splice(index, 1); this._zx.setData(data); return this; }
|
|
177
|
+
/** @returns {unknown[]} */ getRows() { return this._zx.getData(); }
|
|
178
|
+
/** @returns {this} */ empty() { this._zx.empty(); return this; }
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
/** Legacy bootstrap client-side filter bar. */
|
|
182
|
+
export class DataFilter extends GxWrapper {
|
|
183
|
+
static legacyName = 'gx.bootstrap.DataFilter';
|
|
184
|
+
|
|
185
|
+
/** @param {Element|string|null} display @param {Record<string, any>} [options={}] */
|
|
186
|
+
constructor(display, options = {}) {
|
|
187
|
+
super(options);
|
|
188
|
+
const component = new ZxDataFilter(display, { data: [], filters: [], autoApply: true });
|
|
189
|
+
this.origin = [];
|
|
190
|
+
this.filtered = [];
|
|
191
|
+
this.filter = [];
|
|
192
|
+
this._attach(component, {
|
|
193
|
+
events: { filtered: { type: 'filter', args: (detail) => { this.filtered = detail.rows; return [detail.rows]; } } },
|
|
194
|
+
ui: { clear: () => component._controls, clearBtn: () => component._clearButton }
|
|
195
|
+
});
|
|
196
|
+
}
|
|
197
|
+
/** @param {string} identifier @param {string} label @param {string|string[]|Function} fields @param {unknown} [_width] @param {Function} [method] @returns {this} */
|
|
198
|
+
addSelectFilter(identifier, label, fields, _width, method) {
|
|
199
|
+
const definition = { type: 'select', id: String(identifier), label: String(label), fields: Array.isArray(fields) ? fields : [fields] };
|
|
200
|
+
this.filter.push({ identifier, fields: definition.fields, method: method ?? this.selectFilter, type: 'Select' });
|
|
201
|
+
this._zx.addFilter(definition); return this;
|
|
202
|
+
}
|
|
203
|
+
/** @param {string} identifier @param {string|string[]|Function} fields @param {string} label @param {unknown} [_width] @param {Function} [method] @returns {this} */
|
|
204
|
+
addFulltextFilter(identifier, fields, label, _width, method) {
|
|
205
|
+
const definition = { type: 'text', id: String(identifier), label: String(label ?? ''), placeholder: String(label ?? ''), fields: Array.isArray(fields) ? fields : [fields] };
|
|
206
|
+
this.filter.push({ identifier, fields: definition.fields, method: method ?? this.fulltextFilter, type: 'Fulltext' });
|
|
207
|
+
this._zx.addFilter(definition); return this;
|
|
208
|
+
}
|
|
209
|
+
/** @param {Element} element @returns {this} */ addCustomElement(element) { this.toElement().insertBefore(element, this._zx._controls); return this; }
|
|
210
|
+
/** @param {unknown[]} data @returns {this} */ initData(data) { this.origin = Array.isArray(data) ? data : []; this._zx.setData(this.origin); return this; }
|
|
211
|
+
/** @returns {unknown[]} */ doFilter() { this.filtered = this._zx.apply(); return this.filtered; }
|
|
212
|
+
/** @returns {this} */ clearFilter() { this._zx.clear(); return this; }
|
|
213
|
+
/** @param {string} identifier @returns {Record<string, any>|null} */ getFilter(identifier) { return this.filter.find((entry) => entry.identifier == identifier) ?? null; }
|
|
214
|
+
/** @param {unknown} filterValue @param {unknown} fieldValue @returns {boolean} */ fulltextFilter(filterValue, fieldValue) { return new RegExp(String(filterValue), 'i').test(String(fieldValue ?? '')); }
|
|
215
|
+
/** @param {unknown} filterValue @param {unknown} fieldValue @returns {boolean} */ selectFilter(filterValue, fieldValue) { return filterValue == fieldValue; }
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
/** @param {unknown} cell @returns {unknown} */
|
|
219
|
+
function adaptCell(cell) {
|
|
220
|
+
if (cell?.nodeType) return cell;
|
|
221
|
+
if (!cell || typeof cell !== 'object' || Array.isArray(cell)) return cell;
|
|
222
|
+
const element = document.createElement('span');
|
|
223
|
+
const label = cell.label;
|
|
224
|
+
if (label?.nodeType) element.append(label);
|
|
225
|
+
else if (label != null) element.append(document.createTextNode(String(label)));
|
|
226
|
+
if (cell.className) element.classList.add(...String(cell.className).split(/\s+/).filter(Boolean));
|
|
227
|
+
for (const [name, value] of Object.entries(cell)) {
|
|
228
|
+
if (['label', 'className', 'styles'].includes(name) || /^on/i.test(name) || value == null) continue;
|
|
229
|
+
if (['title', 'colspan', 'rowspan'].includes(name.toLowerCase())) element.setAttribute(name, String(value));
|
|
230
|
+
}
|
|
231
|
+
return element;
|
|
232
|
+
}
|
|
@@ -0,0 +1,177 @@
|
|
|
1
|
+
import {
|
|
2
|
+
Datebox as ZxDatebox,
|
|
3
|
+
DatePicker as ZxDatePicker,
|
|
4
|
+
MonthPicker as ZxMonthPicker,
|
|
5
|
+
Timebox as ZxTimebox,
|
|
6
|
+
TimePicker as ZxTimePicker,
|
|
7
|
+
formatDate
|
|
8
|
+
} from '../../index.js';
|
|
9
|
+
import { GxWrapper } from '../base.js';
|
|
10
|
+
import { translateDateboxFormat } from './options.js';
|
|
11
|
+
|
|
12
|
+
/** Legacy segmented date box presented through the Zx formatted date input. */
|
|
13
|
+
export class Datebox extends GxWrapper {
|
|
14
|
+
static legacyName = 'gx.zeyos.Datebox';
|
|
15
|
+
|
|
16
|
+
/** @param {Element|string|null} display @param {Record<string, any>} [options={}] */
|
|
17
|
+
constructor(display, options = {}) {
|
|
18
|
+
super(options, { timestamp: 0, unit: 'milliseconds', format: ['d', '.', 'M', '.', 'y', ' ', 'h', ':', 'i'] });
|
|
19
|
+
const initial = options.timestamp == null || Number(options.timestamp) === 0
|
|
20
|
+
? new Date() : legacyDate(options.timestamp, options.unit ?? 'milliseconds');
|
|
21
|
+
const format = translateDateboxFormat(options.format);
|
|
22
|
+
const component = new ZxDatebox(display, {
|
|
23
|
+
value: initial, format, time: /%[HMS]/.test(format), disabled: Boolean(options.disabled)
|
|
24
|
+
});
|
|
25
|
+
this._attach(component, {
|
|
26
|
+
events: { update: { type: 'change', args: () => [this.get()] } },
|
|
27
|
+
ui: { input: 'input', fieldset: 'control' },
|
|
28
|
+
setters: { timestamp: 'set', disabled: (value) => value ? this.disable() : this.enable() }
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
/** @param {Date|number|string|null} timestamp @param {'milliseconds'|'seconds'} [unit] @returns {this} */
|
|
32
|
+
set(timestamp, unit = this.options.unit ?? 'milliseconds') { this._zx.set(legacyDate(timestamp, unit)); return this; }
|
|
33
|
+
/** @param {'milliseconds'|'seconds'|'date'} [unit] @returns {Date|number|null} */
|
|
34
|
+
get(unit = this.options.unit ?? 'milliseconds') {
|
|
35
|
+
const date = this._zx.get('date');
|
|
36
|
+
if (!date) return null;
|
|
37
|
+
if (unit === 'date') return date;
|
|
38
|
+
return unit === 'seconds' ? date.getTime() / 1000 : date.getTime();
|
|
39
|
+
}
|
|
40
|
+
/** @returns {this} */ enable() { this._zx.enable(); return this; }
|
|
41
|
+
/** @returns {this} */ disable() { this._zx.disable(); return this; }
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/** Shared inline picker wrapper with legacy date formatting. */
|
|
45
|
+
class PickerBase extends GxWrapper {
|
|
46
|
+
static legacyName = 'gx.zeyos.DatePicker';
|
|
47
|
+
/*
|
|
48
|
+
* A constructor type rather than `typeof ZxDatePicker`: each subclass points this at a different
|
|
49
|
+
* picker, and inferring the base from its own default would make every subclass's static side
|
|
50
|
+
* incompatible with it.
|
|
51
|
+
*/
|
|
52
|
+
/** @type {new (target: Element|string|null, options?: any) => any} */
|
|
53
|
+
static Picker = ZxDatePicker;
|
|
54
|
+
|
|
55
|
+
/** @param {Element|string|null} display @param {Record<string, any>} [options={}] */
|
|
56
|
+
constructor(display, options = {}) {
|
|
57
|
+
super(options, { date: false, format: '%a %d.%m.%Y %H:%M', return_format: '%s' });
|
|
58
|
+
const initial = legacyDate(options.date || new Date(), options.unit ?? 'milliseconds');
|
|
59
|
+
const Picker = this.constructor.Picker;
|
|
60
|
+
const component = new Picker(display, pickerOptions(initial, options, Picker));
|
|
61
|
+
this._date = initial;
|
|
62
|
+
this._attach(component, {
|
|
63
|
+
events: { select: { type: 'change', args: (detail) => {
|
|
64
|
+
this._date = detail.date ? new Date(detail.date.getTime()) : this._dateFromTime(detail.time);
|
|
65
|
+
return [this._date];
|
|
66
|
+
} } },
|
|
67
|
+
ui: { input: 'root' },
|
|
68
|
+
setters: { date: 'set' }
|
|
69
|
+
});
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
/** @param {Date|number|string|null} value @returns {this} */
|
|
73
|
+
set(value) {
|
|
74
|
+
const date = legacyDate(value, 'milliseconds');
|
|
75
|
+
this._date = date;
|
|
76
|
+
if (this.constructor.Picker === ZxTimePicker) this._zx.set(date);
|
|
77
|
+
else this._zx.set(date);
|
|
78
|
+
return this;
|
|
79
|
+
}
|
|
80
|
+
/** @param {string} [format] @returns {Date|number|string|null} */
|
|
81
|
+
get(format = this.options.return_format) {
|
|
82
|
+
const date = this._readDate();
|
|
83
|
+
if (!date) return null;
|
|
84
|
+
if (format == null) return date;
|
|
85
|
+
if (format === '%s' || format === 'seconds') return Math.floor(date.getTime() / 1000);
|
|
86
|
+
if (format === 'date') return date;
|
|
87
|
+
return formatDate(date, String(format));
|
|
88
|
+
}
|
|
89
|
+
/** @returns {number|null} */ getSeconds() { const date = this._readDate(); return date ? date.getTime() / 1000 : null; }
|
|
90
|
+
/** @param {boolean} readOnly @returns {this} */ setReadOnly(readOnly) { this.toElement().setAttribute('aria-disabled', String(Boolean(readOnly))); return this; }
|
|
91
|
+
/** @param {string} format @param {boolean} [enableTimePicker] @returns {this} */ setFormat(format, enableTimePicker) { this.options.format = format; this.options.timePicker = enableTimePicker; return this; }
|
|
92
|
+
/** @returns {Date|null} */
|
|
93
|
+
_readDate() {
|
|
94
|
+
if (this.constructor.Picker === ZxTimePicker) {
|
|
95
|
+
const time = this._zx.get();
|
|
96
|
+
return time ? this._dateFromTime(time) : this._date;
|
|
97
|
+
}
|
|
98
|
+
return this._zx.get();
|
|
99
|
+
}
|
|
100
|
+
/** @param {{h?: number, m?: number, s?: number}|null} time @returns {Date} */
|
|
101
|
+
_dateFromTime(time) {
|
|
102
|
+
const date = this._date ? new Date(this._date.getTime()) : new Date();
|
|
103
|
+
if (time) date.setHours(Number(time.h) || 0, Number(time.m) || 0, Number(time.s) || 0, 0);
|
|
104
|
+
return date;
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
/** Legacy date picker. */
|
|
109
|
+
export class DatePicker extends PickerBase { static legacyName = 'gx.zeyos.DatePicker'; static Picker = ZxDatePicker; }
|
|
110
|
+
/** Legacy month picker. */
|
|
111
|
+
export class MonthPicker extends PickerBase { static legacyName = 'gx.zeyos.MonthPicker'; static Picker = ZxMonthPicker; }
|
|
112
|
+
/** Legacy time picker. */
|
|
113
|
+
export class TimePicker extends PickerBase { static legacyName = 'gx.zeyos.TimePicker'; static Picker = ZxTimePicker; }
|
|
114
|
+
|
|
115
|
+
/** Shared duration Timebox wrapper. */
|
|
116
|
+
class TimeboxBase extends GxWrapper {
|
|
117
|
+
static legacyName = 'gx.ui.Timebox';
|
|
118
|
+
|
|
119
|
+
/** @param {Element|string|null} display @param {Record<string, any>} [options={}] */
|
|
120
|
+
constructor(display, options = {}) {
|
|
121
|
+
super(options, { time: 0, unit: 'minutes', seconds: true, prefix: false, disabled: false });
|
|
122
|
+
const component = new ZxTimebox(display, {
|
|
123
|
+
value: Number(options.time) || 0, unit: normalizeTimeUnit(options.unit),
|
|
124
|
+
seconds: options.seconds !== false, signed: Boolean(options.prefix),
|
|
125
|
+
disabled: Boolean(options.disabled || options.readonly)
|
|
126
|
+
});
|
|
127
|
+
this._attach(component, {
|
|
128
|
+
events: { change: { type: 'change', args: (detail) => [detail.value] } },
|
|
129
|
+
ui: { prefix: 'sign' },
|
|
130
|
+
setters: { time: 'set', disabled: (value) => value ? this.disable() : this.enable() }
|
|
131
|
+
});
|
|
132
|
+
}
|
|
133
|
+
/** @param {number} time @param {'seconds'|'minutes'|'hours'} [unit] @returns {this} */ set(time, unit = this.options.unit) { this._zx.set(time ?? 0, normalizeTimeUnit(unit)); return this; }
|
|
134
|
+
/** @param {'seconds'|'minutes'|'hours'} [unit] @param {number} [precision=0] @returns {number} */
|
|
135
|
+
get(unit = this.options.unit, precision = 0) { const value = this._zx.get(normalizeTimeUnit(unit)); const scale = 10 ** (Number(precision) || 0); return Math.round(value * scale) / scale; }
|
|
136
|
+
/** @returns {this} */ update() { return this.set(this.get()); }
|
|
137
|
+
/** @returns {this} */ enable() { this.options.disabled = false; this._zx.enable(); this.fireEvent('disabled', [false]); return this; }
|
|
138
|
+
/** @returns {this} */ disable() { this.options.disabled = true; this._zx.disable(); this.fireEvent('disabled', [true]); return this; }
|
|
139
|
+
/** @returns {boolean} */ disabled() { return Boolean(this.options.disabled); }
|
|
140
|
+
/** @param {boolean} positive @returns {this} */ setPrefix(positive) { const value = Math.abs(this.get()); this.set(positive ? value : -value); return this; }
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
/** Legacy core Timebox. */
|
|
144
|
+
export class CoreTimebox extends TimeboxBase { static legacyName = 'gx.ui.Timebox'; }
|
|
145
|
+
/** Legacy ZeyOS Timebox. */
|
|
146
|
+
export class Timebox extends TimeboxBase { static legacyName = 'gx.zeyos.Timebox'; }
|
|
147
|
+
/** Legacy bootstrap Timebox. */
|
|
148
|
+
export class BootstrapTimebox extends TimeboxBase { static legacyName = 'gx.bootstrap.Timebox'; }
|
|
149
|
+
|
|
150
|
+
/** @param {unknown} value @param {unknown} unit @returns {Date|null} */
|
|
151
|
+
function legacyDate(value, unit) {
|
|
152
|
+
if (value == null) return null;
|
|
153
|
+
if (value instanceof Date) return new Date(value.getTime());
|
|
154
|
+
if (typeof value === 'number' || /^-?\d+(?:\.\d+)?$/.test(String(value))) {
|
|
155
|
+
const number = Number(value);
|
|
156
|
+
return new Date(unit === 'seconds' ? number * 1000 : number);
|
|
157
|
+
}
|
|
158
|
+
const date = new Date(String(value));
|
|
159
|
+
return Number.isNaN(date.getTime()) ? null : date;
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
/** @param {Date|null} value @param {Record<string, any>} options @param {Function} Picker @returns {Record<string, any>} */
|
|
163
|
+
function pickerOptions(value, options, Picker) {
|
|
164
|
+
if (Picker === ZxTimePicker) return { value, seconds: /%S/.test(options.format ?? '') };
|
|
165
|
+
return {
|
|
166
|
+
value,
|
|
167
|
+
min: legacyDate(options.min ?? null, 'milliseconds'),
|
|
168
|
+
max: legacyDate(options.max ?? null, 'milliseconds'),
|
|
169
|
+
time: Picker === ZxDatePicker && options.timePicker !== false,
|
|
170
|
+
showWeekNumbers: Boolean(options.weeknumbers)
|
|
171
|
+
};
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
/** @param {unknown} unit @returns {'seconds'|'minutes'|'hours'} */
|
|
175
|
+
function normalizeTimeUnit(unit) {
|
|
176
|
+
return ['seconds', 'minutes', 'hours'].includes(String(unit)) ? String(unit) : 'minutes';
|
|
177
|
+
}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { button, buttonGroup, icon, icons } from '../../index.js';
|
|
2
|
+
import { warnFunctionOnce } from './helpers.js';
|
|
3
|
+
|
|
4
|
+
/** Legacy glyph names accepted by `Factory.Icon()`. */
|
|
5
|
+
const ICON_NAMES = Object.freeze({
|
|
6
|
+
list: 'list', plus: 'plus', clock: 'clock', range: 'filter', reload: 'reload', clear: 'x',
|
|
7
|
+
settings: 'gear', eye: 'eye', trash: 'trash', fields: 'list', search: 'search', lock: 'lock',
|
|
8
|
+
checked: 'check', question: 'info'
|
|
9
|
+
});
|
|
10
|
+
|
|
11
|
+
/** Legacy ZeyOS DOM factory mapped to Zx button and icon primitives. */
|
|
12
|
+
export const Factory = Object.freeze({
|
|
13
|
+
/** @param {string} name @returns {SVGSVGElement} */
|
|
14
|
+
Icon(name) {
|
|
15
|
+
warnFactory();
|
|
16
|
+
const mapped = ICON_NAMES[name] ?? (icons[name] ? name : null);
|
|
17
|
+
if (!mapped) throw new RangeError(`Unsupported legacy icon: ${name}`);
|
|
18
|
+
return icon(mapped);
|
|
19
|
+
},
|
|
20
|
+
/** @param {string} text @param {string} [type=''] @param {string} [iconName] @param {Record<string, any>} [options={}] @returns {HTMLButtonElement} */
|
|
21
|
+
Button(text, type = '', iconName, options = {}) {
|
|
22
|
+
warnFactory();
|
|
23
|
+
const element = button({
|
|
24
|
+
label: String(text ?? ''), icon: iconName ? ICON_NAMES[iconName] ?? iconName : null,
|
|
25
|
+
kind: buttonKind(type), disabled: Boolean(options.disabled), title: options.title,
|
|
26
|
+
onclick: options.onclick ?? options.onClick
|
|
27
|
+
});
|
|
28
|
+
for (const name of ['id', 'name', 'value']) if (options[name] != null) element.setAttribute(name, String(options[name]));
|
|
29
|
+
return element;
|
|
30
|
+
},
|
|
31
|
+
/** @param {HTMLButtonElement[]} buttons @returns {HTMLDivElement} */
|
|
32
|
+
ButtonsGroup(buttons) { warnFactory(); return buttonGroup(Array.isArray(buttons) ? buttons : []); }
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
/** @returns {void} */
|
|
36
|
+
function warnFactory() { warnFunctionOnce(warnFactory, 'gx.zeyos.Factory', 'button/icon'); }
|
|
37
|
+
|
|
38
|
+
/** @param {unknown} type @returns {'default'|'primary'|'danger'|'ghost'} */
|
|
39
|
+
function buttonKind(type) {
|
|
40
|
+
const value = String(type ?? '').toLowerCase();
|
|
41
|
+
if (value === 'dark' || value === 'em') return 'primary';
|
|
42
|
+
if (value.includes('danger') || value.includes('error')) return 'danger';
|
|
43
|
+
if (value.includes('ghost') || value.includes('link')) return 'ghost';
|
|
44
|
+
return 'default';
|
|
45
|
+
}
|