@zeyos/zx 2.3.0 → 4.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/CHANGELOG.md +138 -0
- package/DESIGN-SYSTEM.md +96 -0
- package/README.md +29 -39
- package/dist/types/components/account-menu/account-menu.d.ts +144 -0
- package/dist/types/components/app-sidebar/app-sidebar.d.ts +243 -0
- package/dist/types/components/avatar/avatar.d.ts +100 -0
- package/dist/types/components/card/card.d.ts +128 -0
- package/dist/types/components/chart/chart.d.ts +322 -0
- package/dist/types/components/date-picker/month-picker.d.ts +6 -0
- package/dist/types/components/dialog/dialog.d.ts +9 -0
- package/dist/types/components/dock/dock.d.ts +495 -0
- package/dist/types/components/dropdown/dropdown.d.ts +2 -2
- package/dist/types/components/field/field.d.ts +14 -0
- package/dist/types/components/field-upload/field-upload.d.ts +37 -4
- package/dist/types/components/form/form.d.ts +25 -3
- package/dist/types/components/grid/grid.d.ts +172 -0
- package/dist/types/components/launcher/launcher.d.ts +359 -0
- package/dist/types/components/layout/layout.d.ts +4 -4
- package/dist/types/components/menu-button/menu-button.d.ts +10 -2
- package/dist/types/components/modal/modal.d.ts +25 -0
- package/dist/types/components/multi-value-editor/multi-value-editor.d.ts +7 -1
- package/dist/types/components/questionnaire/items.d.ts +327 -0
- package/dist/types/components/questionnaire/questionnaire.d.ts +449 -0
- package/dist/types/components/select/select.d.ts +51 -0
- package/dist/types/components/sheet/sheet-stack.d.ts +167 -0
- package/dist/types/components/sheet/sheet.d.ts +294 -0
- package/dist/types/components/split-view/split-view.d.ts +2 -21
- package/dist/types/components/table/table.d.ts +223 -15
- package/dist/types/components/tooltip/tooltip.d.ts +2 -2
- package/dist/types/components/value-list/value-list.d.ts +24 -3
- package/dist/types/core/dom.d.ts +122 -0
- package/dist/types/core/drag-axis.d.ts +111 -0
- package/dist/types/core/position.d.ts +4 -2
- package/dist/types/index.d.ts +13 -2
- package/dist/types/internal/app-rail.d.ts +265 -0
- package/dist/types/zeyos/icons.d.ts +5 -0
- package/dist/types/zeyos/index.d.ts +2 -1
- package/dist/types/zeyos/launcher.d.ts +147 -0
- package/dist/types/zeyos/select.d.ts +39 -0
- package/dist/zx-zeyos.esm.js +1870 -133
- package/dist/zx-zeyos.esm.min.js +1 -1
- package/dist/zx.css +2006 -267
- package/dist/zx.esm.js +8987 -2757
- package/dist/zx.esm.min.js +3 -3
- package/dist/zx.global.js +8987 -2757
- package/dist/zx.global.min.js +3 -3
- package/dist/zx.min.css +1 -1
- package/docs/api.json +4396 -2344
- package/docs/llms.md +463 -86
- package/docs/llms.txt +32 -19
- package/package.json +10 -17
- package/src/components/account-menu/account-menu.css +70 -0
- package/src/components/account-menu/account-menu.js +208 -0
- package/src/components/app-rail/app-rail.css +107 -0
- package/src/components/app-sidebar/app-sidebar.css +80 -0
- package/src/components/app-sidebar/app-sidebar.js +588 -0
- package/src/components/avatar/avatar.css +61 -0
- package/src/components/avatar/avatar.js +222 -0
- package/src/components/button/button.css +0 -1
- package/src/components/card/card.css +149 -0
- package/src/components/card/card.js +285 -0
- package/src/components/chart/chart.css +61 -0
- package/src/components/chart/chart.js +523 -0
- package/src/components/date-picker/month-picker.js +9 -0
- package/src/components/dialog/dialog.js +11 -4
- package/src/components/dock/dock.css +228 -0
- package/src/components/dock/dock.js +977 -0
- package/src/components/dropdown/dropdown.js +1 -1
- package/src/components/field/field.js +2 -0
- package/src/components/field-upload/field-upload.js +9 -4
- package/src/components/form/form.js +6 -3
- package/src/components/grid/grid.css +6 -0
- package/src/components/grid/grid.js +220 -0
- package/src/components/launcher/launcher.css +210 -0
- package/src/components/launcher/launcher.js +765 -0
- package/src/components/layout/layout.js +2 -2
- package/src/components/menu-button/menu-button.js +27 -2
- package/src/components/modal/modal.css +5 -1
- package/src/components/modal/modal.js +37 -2
- package/src/components/multi-value-editor/multi-value-editor.js +2 -1
- package/src/components/questionnaire/items.js +370 -0
- package/src/components/questionnaire/questionnaire.css +387 -0
- package/src/components/questionnaire/questionnaire.js +1033 -0
- package/src/components/select/field-adapter.js +9 -4
- package/src/components/select/select.css +144 -11
- package/src/components/select/select.js +259 -27
- package/src/components/sheet/sheet-stack.js +304 -0
- package/src/components/sheet/sheet.css +351 -0
- package/src/components/sheet/sheet.js +551 -0
- package/src/components/split-view/split-view.js +76 -161
- package/src/components/table/table.css +43 -0
- package/src/components/table/table.js +531 -52
- package/src/components/tooltip/tooltip.js +5 -2
- package/src/components/value-list/value-list.js +6 -3
- package/src/core/dom.js +322 -0
- package/src/core/drag-axis.js +203 -0
- package/src/core/position.js +68 -22
- package/src/index.js +20 -2
- package/src/internal/app-rail.js +718 -0
- package/src/zeyos/icons.js +8 -3
- package/src/zeyos/index.js +7 -1
- package/src/zeyos/launcher.js +338 -0
- package/src/zeyos/modules.js +1 -0
- package/src/zeyos/select.js +115 -1
- package/styles/tokens/dark.css +2 -3
- package/styles/tokens/global.css +6 -6
- package/styles/tokens/modules.css +1 -0
- package/styles/tokens/semantic.css +5 -3
- package/styles/tokens/themes.css +1 -1
- package/styles/zx.css +11 -1
- package/MIGRATION.md +0 -598
- package/dist/types/compat/base.d.ts +0 -156
- package/dist/types/compat/globals.d.ts +0 -20
- package/dist/types/compat/index.d.ts +0 -128
- package/dist/types/compat/map/basic.d.ts +0 -175
- package/dist/types/compat/map/data.d.ts +0 -102
- package/dist/types/compat/map/date-time.d.ts +0 -80
- package/dist/types/compat/map/factory.d.ts +0 -9
- package/dist/types/compat/map/form.d.ts +0 -98
- package/dist/types/compat/map/helpers.d.ts +0 -12
- package/dist/types/compat/map/http.d.ts +0 -36
- package/dist/types/compat/map/layout.d.ts +0 -106
- package/dist/types/compat/map/options.d.ts +0 -80
- package/dist/types/compat/map/select.d.ts +0 -95
- package/dist/types/compat/map/stubs.d.ts +0 -32
- package/dist/types/compat/map/utilities.d.ts +0 -37
- package/dist/types/compat-entry.d.ts +0 -5
- package/dist/types/components/permission/permission.d.ts +0 -96
- package/dist/zx-compat.esm.js +0 -17484
- package/dist/zx-compat.esm.min.js +0 -1
- package/dist/zx-compat.global.js +0 -23635
- package/dist/zx-compat.global.min.js +0 -3
- package/src/compat/base.js +0 -291
- package/src/compat/globals.js +0 -165
- package/src/compat/index.js +0 -84
- package/src/compat/map/basic.js +0 -464
- package/src/compat/map/data.js +0 -232
- package/src/compat/map/date-time.js +0 -177
- package/src/compat/map/factory.js +0 -45
- package/src/compat/map/form.js +0 -330
- package/src/compat/map/helpers.js +0 -46
- package/src/compat/map/http.js +0 -117
- package/src/compat/map/layout.js +0 -256
- package/src/compat/map/options.js +0 -267
- package/src/compat/map/select.js +0 -198
- package/src/compat/map/stubs.js +0 -26
- package/src/compat/map/utilities.js +0 -113
- package/src/compat-entry.js +0 -11
- package/src/components/permission/permission.css +0 -47
- package/src/components/permission/permission.js +0 -201
package/src/compat/base.js
DELETED
|
@@ -1,291 +0,0 @@
|
|
|
1
|
-
import { installElementStorage } from './globals.js';
|
|
2
|
-
|
|
3
|
-
/** @typedef {(detail: Record<string, any>, event: Event) => unknown[]} LegacyArgumentMapper */
|
|
4
|
-
/**
|
|
5
|
-
* @typedef {Object} LegacyEventMapping
|
|
6
|
-
* @property {string} type Zx event name.
|
|
7
|
-
* @property {LegacyArgumentMapper} [args] Legacy positional argument adapter.
|
|
8
|
-
* @property {(detail: Record<string, any>, event: Event) => boolean} [filter] Optional event filter.
|
|
9
|
-
*/
|
|
10
|
-
/** @typedef {Record<string, string|LegacyEventMapping>} LegacyEventMap */
|
|
11
|
-
/**
|
|
12
|
-
* @typedef {Object} WrapperConfiguration
|
|
13
|
-
* @property {LegacyEventMap} [events]
|
|
14
|
-
* @property {Record<string, string|Element|(() => Element|null)>} [ui]
|
|
15
|
-
* @property {Record<string, string|((value: unknown) => void)>} [setters]
|
|
16
|
-
*/
|
|
17
|
-
|
|
18
|
-
/**
|
|
19
|
-
* MooTools-flavoured façade shared by compatibility component wrappers.
|
|
20
|
-
* @fires GxWrapper#legacy-event
|
|
21
|
-
*/
|
|
22
|
-
export class GxWrapper {
|
|
23
|
-
/** Fully qualified legacy class name shown in migration warnings. */
|
|
24
|
-
static legacyName = 'gx.ui.Container';
|
|
25
|
-
|
|
26
|
-
/**
|
|
27
|
-
* Initializes legacy options and callback-style `onEvent` options.
|
|
28
|
-
* Subclasses call `_attach()` after constructing their Zx implementation.
|
|
29
|
-
* @param {Record<string, any>} [options={}] Legacy options.
|
|
30
|
-
* @param {Record<string, any>} [defaults={}] Legacy defaults.
|
|
31
|
-
*/
|
|
32
|
-
constructor(options = {}, defaults = {}) {
|
|
33
|
-
warnClassOnce(this.constructor);
|
|
34
|
-
this.gx = this.constructor.legacyName;
|
|
35
|
-
this.options = { ...defaults, ...(options && typeof options === 'object' ? options : {}) };
|
|
36
|
-
this._events = new Map();
|
|
37
|
-
this._mappedListeners = [];
|
|
38
|
-
this._domAbort = new AbortController();
|
|
39
|
-
this._zx = null;
|
|
40
|
-
this._ui = {};
|
|
41
|
-
this._display = this._ui;
|
|
42
|
-
this._uiMap = {};
|
|
43
|
-
this._optionSetters = {};
|
|
44
|
-
this._destroyed = false;
|
|
45
|
-
for (const [key, value] of Object.entries(this.options)) {
|
|
46
|
-
if (/^on[A-Z]/.test(key) && typeof value === 'function') this.addEvent(key, value);
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
/**
|
|
51
|
-
* Subscribes a legacy callback.
|
|
52
|
-
* @param {string} type Legacy event name, with or without an `on` prefix.
|
|
53
|
-
* @param {Function} fn Callback receiving legacy positional arguments.
|
|
54
|
-
* @returns {this}
|
|
55
|
-
*/
|
|
56
|
-
addEvent(type, fn) {
|
|
57
|
-
if (typeof fn !== 'function') return this;
|
|
58
|
-
const name = normalizeEventName(type);
|
|
59
|
-
const handlers = this._events.get(name) ?? new Set();
|
|
60
|
-
handlers.add(fn);
|
|
61
|
-
this._events.set(name, handlers);
|
|
62
|
-
return this;
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
/**
|
|
66
|
-
* Removes one callback, or all callbacks of a type when omitted.
|
|
67
|
-
* @param {string} type Legacy event name.
|
|
68
|
-
* @param {Function} [fn] Callback to remove.
|
|
69
|
-
* @returns {this}
|
|
70
|
-
*/
|
|
71
|
-
removeEvent(type, fn) {
|
|
72
|
-
const name = normalizeEventName(type);
|
|
73
|
-
if (fn === undefined) this._events.delete(name);
|
|
74
|
-
else {
|
|
75
|
-
const handlers = this._events.get(name);
|
|
76
|
-
handlers?.delete(fn);
|
|
77
|
-
if (handlers?.size === 0) this._events.delete(name);
|
|
78
|
-
}
|
|
79
|
-
return this;
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
/**
|
|
83
|
-
* Fires a legacy event synchronously.
|
|
84
|
-
* @param {string} type Legacy event name.
|
|
85
|
-
* @param {unknown|unknown[]} [args=[]] Positional argument array or one argument.
|
|
86
|
-
* @returns {this}
|
|
87
|
-
* @fires GxWrapper#legacy-event
|
|
88
|
-
*/
|
|
89
|
-
fireEvent(type, args = []) {
|
|
90
|
-
const values = Array.isArray(args) ? args : [args];
|
|
91
|
-
const handlers = [...(this._events.get(normalizeEventName(type)) ?? [])];
|
|
92
|
-
for (const handler of handlers) handler.apply(this, values);
|
|
93
|
-
return this;
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
/**
|
|
97
|
-
* Applies multiple post-construction legacy options.
|
|
98
|
-
* @param {Record<string, unknown>} options Option values.
|
|
99
|
-
* @returns {this}
|
|
100
|
-
*/
|
|
101
|
-
setOptions(options) {
|
|
102
|
-
if (!options || typeof options !== 'object') return this;
|
|
103
|
-
for (const [name, value] of Object.entries(options)) this.setOption(name, value);
|
|
104
|
-
return this;
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
/**
|
|
108
|
-
* Applies one post-construction option through a declared setter.
|
|
109
|
-
* Unsupported dynamic options are retained on `options` and warn once per class/key.
|
|
110
|
-
* @param {string} option Legacy option name.
|
|
111
|
-
* @param {unknown} value New value.
|
|
112
|
-
* @returns {this}
|
|
113
|
-
*/
|
|
114
|
-
setOption(option, value) {
|
|
115
|
-
const name = String(option);
|
|
116
|
-
this.options[name] = value;
|
|
117
|
-
if (/^on[A-Z]/.test(name) && typeof value === 'function') {
|
|
118
|
-
this.addEvent(name, value);
|
|
119
|
-
return this;
|
|
120
|
-
}
|
|
121
|
-
const setter = this._optionSetters[name];
|
|
122
|
-
if (typeof setter === 'function') setter.call(this, value);
|
|
123
|
-
else if (typeof setter === 'string' && typeof this[setter] === 'function') this[setter](value);
|
|
124
|
-
else warnOptionOnce(this.constructor, name);
|
|
125
|
-
return this;
|
|
126
|
-
}
|
|
127
|
-
|
|
128
|
-
/**
|
|
129
|
-
* Returns the wrapped component root.
|
|
130
|
-
* @returns {Element|null}
|
|
131
|
-
*/
|
|
132
|
-
toElement() {
|
|
133
|
-
return this._zx?.toElement?.() ?? this._zx?.el ?? null;
|
|
134
|
-
}
|
|
135
|
-
|
|
136
|
-
/**
|
|
137
|
-
* Resolves a legacy `_ui` key, falling back to the component root.
|
|
138
|
-
* @param {string} [key='root'] Legacy display key.
|
|
139
|
-
* @returns {Element|null}
|
|
140
|
-
*/
|
|
141
|
-
display(key = 'root') {
|
|
142
|
-
const name = key || 'root';
|
|
143
|
-
if (name === 'root') return this.toElement();
|
|
144
|
-
const mapped = this._uiMap[name];
|
|
145
|
-
if (typeof mapped === 'function') return mapped.call(this) ?? this.toElement();
|
|
146
|
-
if (typeof mapped === 'string') return this._zx?.refs?.[mapped] ?? this.toElement();
|
|
147
|
-
if (mapped?.nodeType === 1) return mapped;
|
|
148
|
-
return this._ui[name] ?? this.toElement();
|
|
149
|
-
}
|
|
150
|
-
|
|
151
|
-
/**
|
|
152
|
-
* Returns the supported legacy coordinate subset.
|
|
153
|
-
* @returns {{width: number, height: number, top: number, left: number}}
|
|
154
|
-
*/
|
|
155
|
-
getCoordinates() {
|
|
156
|
-
const rectangle = this.toElement()?.getBoundingClientRect?.();
|
|
157
|
-
return rectangle ? {
|
|
158
|
-
width: rectangle.width,
|
|
159
|
-
height: rectangle.height,
|
|
160
|
-
top: rectangle.top,
|
|
161
|
-
left: rectangle.left
|
|
162
|
-
} : { width: 0, height: 0, top: 0, left: 0 };
|
|
163
|
-
}
|
|
164
|
-
|
|
165
|
-
/**
|
|
166
|
-
* Updates one root style property.
|
|
167
|
-
* @param {string} property CSS property.
|
|
168
|
-
* @param {unknown} value CSS value.
|
|
169
|
-
* @returns {this}
|
|
170
|
-
*/
|
|
171
|
-
setStyle(property, value) {
|
|
172
|
-
const element = /** @type {HTMLElement|null} */ (this.toElement());
|
|
173
|
-
if (!element) return this;
|
|
174
|
-
if (String(property).startsWith('--') || String(property).includes('-')) {
|
|
175
|
-
element.style.setProperty(String(property), String(value));
|
|
176
|
-
} else {
|
|
177
|
-
element.style[property] = value;
|
|
178
|
-
}
|
|
179
|
-
return this;
|
|
180
|
-
}
|
|
181
|
-
|
|
182
|
-
/**
|
|
183
|
-
* Updates supported root coordinates.
|
|
184
|
-
* @param {Record<string, unknown>} coordinates Coordinate styles.
|
|
185
|
-
* @returns {this}
|
|
186
|
-
*/
|
|
187
|
-
setCoordinates(coordinates = {}) {
|
|
188
|
-
for (const key of ['width', 'height', 'top', 'right', 'bottom', 'left']) {
|
|
189
|
-
if (coordinates[key] == null) continue;
|
|
190
|
-
const value = typeof coordinates[key] === 'number' ? `${coordinates[key]}px` : coordinates[key];
|
|
191
|
-
this.setStyle(key, value);
|
|
192
|
-
}
|
|
193
|
-
return this;
|
|
194
|
-
}
|
|
195
|
-
|
|
196
|
-
/**
|
|
197
|
-
* Destroys the wrapped component and legacy event subscriptions.
|
|
198
|
-
* @returns {void}
|
|
199
|
-
*/
|
|
200
|
-
destroy() {
|
|
201
|
-
if (this._destroyed) return;
|
|
202
|
-
this._destroyed = true;
|
|
203
|
-
this._domAbort.abort();
|
|
204
|
-
const root = this.toElement();
|
|
205
|
-
if (root?.retrieve?.('com') === this) root.eliminate('com');
|
|
206
|
-
for (const [type, listener] of this._mappedListeners) this._zx?.off?.(type, listener);
|
|
207
|
-
this._mappedListeners.length = 0;
|
|
208
|
-
this._events.clear();
|
|
209
|
-
this._zx?.destroy?.();
|
|
210
|
-
}
|
|
211
|
-
|
|
212
|
-
/**
|
|
213
|
-
* Attaches a constructed Zx component and its translation metadata.
|
|
214
|
-
* @param {any} component Wrapped Zx component.
|
|
215
|
-
* @param {WrapperConfiguration} [configuration={}] Event, display, and setter maps.
|
|
216
|
-
* @returns {this}
|
|
217
|
-
*/
|
|
218
|
-
_attach(component, configuration = {}) {
|
|
219
|
-
this._zx = component;
|
|
220
|
-
this._uiMap = { ...(configuration.ui ?? {}) };
|
|
221
|
-
this._optionSetters = { ...(configuration.setters ?? {}) };
|
|
222
|
-
const root = this.toElement();
|
|
223
|
-
if (root) {
|
|
224
|
-
installElementStorage(globalThis);
|
|
225
|
-
root.store?.('com', this);
|
|
226
|
-
this._ui.root = root;
|
|
227
|
-
for (const key of Object.keys(this._uiMap)) this._ui[key] = this.display(key);
|
|
228
|
-
}
|
|
229
|
-
for (const [legacyType, declaration] of Object.entries(configuration.events ?? {})) {
|
|
230
|
-
const mapping = typeof declaration === 'string' ? { type: declaration } : declaration;
|
|
231
|
-
const listener = (event) => {
|
|
232
|
-
const detail = event.detail ?? {};
|
|
233
|
-
if (mapping.filter && !mapping.filter.call(this, detail, event)) return;
|
|
234
|
-
const args = mapping.args ? mapping.args.call(this, detail, event) : [];
|
|
235
|
-
this.fireEvent(legacyType, args);
|
|
236
|
-
};
|
|
237
|
-
component.on?.(mapping.type, listener);
|
|
238
|
-
this._mappedListeners.push([mapping.type, listener]);
|
|
239
|
-
}
|
|
240
|
-
return this;
|
|
241
|
-
}
|
|
242
|
-
|
|
243
|
-
/**
|
|
244
|
-
* Adds a DOM listener owned by this wrapper.
|
|
245
|
-
* @param {EventTarget} target Event target.
|
|
246
|
-
* @param {string} type Event type.
|
|
247
|
-
* @param {EventListenerOrEventListenerObject} listener Listener.
|
|
248
|
-
* @param {AddEventListenerOptions} [options={}] Listener options.
|
|
249
|
-
* @returns {this}
|
|
250
|
-
*/
|
|
251
|
-
_listen(target, type, listener, options = {}) {
|
|
252
|
-
target.addEventListener(type, listener, { ...options, signal: this._domAbort.signal });
|
|
253
|
-
return this;
|
|
254
|
-
}
|
|
255
|
-
|
|
256
|
-
/** @param {Element|null} element @param {boolean} active @returns {void} */
|
|
257
|
-
_mirrorAct(element, active) {
|
|
258
|
-
element?.classList.toggle('act', Boolean(active));
|
|
259
|
-
}
|
|
260
|
-
}
|
|
261
|
-
|
|
262
|
-
/** Generic legacy event dispatched by a mapped Zx event. @event GxWrapper#legacy-event */
|
|
263
|
-
|
|
264
|
-
/** @param {typeof GxWrapper} constructor @returns {void} */
|
|
265
|
-
function warnClassOnce(constructor) {
|
|
266
|
-
if (Object.hasOwn(constructor, '_compatWarned') && constructor._compatWarned) return;
|
|
267
|
-
Object.defineProperty(constructor, '_compatWarned', { configurable: true, value: true, writable: true });
|
|
268
|
-
console.warn(`${constructor.legacyName} is running on the Zx compat layer — migrate to ${replacementName(constructor.legacyName)}`);
|
|
269
|
-
}
|
|
270
|
-
|
|
271
|
-
/** @param {typeof GxWrapper} constructor @param {string} option @returns {void} */
|
|
272
|
-
function warnOptionOnce(constructor, option) {
|
|
273
|
-
if (!Object.hasOwn(constructor, '_compatOptionWarnings')) {
|
|
274
|
-
Object.defineProperty(constructor, '_compatOptionWarnings', { configurable: true, value: new Set() });
|
|
275
|
-
}
|
|
276
|
-
if (constructor._compatOptionWarnings.has(option)) return;
|
|
277
|
-
constructor._compatOptionWarnings.add(option);
|
|
278
|
-
console.warn(`${constructor.legacyName}.setOption("${option}") cannot update the wrapped Zx component dynamically`);
|
|
279
|
-
}
|
|
280
|
-
|
|
281
|
-
/** @param {string} name @returns {string} */
|
|
282
|
-
function replacementName(name) {
|
|
283
|
-
const className = name.split('.').at(-1);
|
|
284
|
-
return `zx.${className}`;
|
|
285
|
-
}
|
|
286
|
-
|
|
287
|
-
/** @param {string} type @returns {string} */
|
|
288
|
-
function normalizeEventName(type) {
|
|
289
|
-
const value = String(type ?? '');
|
|
290
|
-
return (/^on[A-Z]/.test(value) ? value.slice(2) : value).toLowerCase();
|
|
291
|
-
}
|
package/src/compat/globals.js
DELETED
|
@@ -1,165 +0,0 @@
|
|
|
1
|
-
import { h, htmlEscape } from '../core/dom.js';
|
|
2
|
-
import { translate } from '../core/i18n.js';
|
|
3
|
-
|
|
4
|
-
/** @type {WeakMap<object, Map<unknown, unknown>>} */
|
|
5
|
-
const elementStorage = new WeakMap();
|
|
6
|
-
|
|
7
|
-
/**
|
|
8
|
-
* Installs the small WeakMap-backed MooTools Element storage surface.
|
|
9
|
-
* Existing implementations are never overwritten.
|
|
10
|
-
* @param {typeof globalThis} [host=globalThis] Realm whose Element prototype is extended.
|
|
11
|
-
* @returns {void}
|
|
12
|
-
*/
|
|
13
|
-
export function installElementStorage(host = globalThis) {
|
|
14
|
-
const prototype = host?.Element?.prototype;
|
|
15
|
-
if (!prototype) return;
|
|
16
|
-
if (typeof prototype.store !== 'function') {
|
|
17
|
-
Object.defineProperty(prototype, 'store', {
|
|
18
|
-
configurable: true,
|
|
19
|
-
writable: true,
|
|
20
|
-
value: function store(key, value) {
|
|
21
|
-
let values = elementStorage.get(this);
|
|
22
|
-
if (!values) {
|
|
23
|
-
values = new Map();
|
|
24
|
-
elementStorage.set(this, values);
|
|
25
|
-
}
|
|
26
|
-
values.set(key, value);
|
|
27
|
-
return this;
|
|
28
|
-
}
|
|
29
|
-
});
|
|
30
|
-
}
|
|
31
|
-
if (typeof prototype.retrieve !== 'function') {
|
|
32
|
-
Object.defineProperty(prototype, 'retrieve', {
|
|
33
|
-
configurable: true,
|
|
34
|
-
writable: true,
|
|
35
|
-
value: function retrieve(key, fallback = null) {
|
|
36
|
-
let values = elementStorage.get(this);
|
|
37
|
-
if (values?.has(key)) return values.get(key);
|
|
38
|
-
if (arguments.length > 1) {
|
|
39
|
-
if (!values) {
|
|
40
|
-
values = new Map();
|
|
41
|
-
elementStorage.set(this, values);
|
|
42
|
-
}
|
|
43
|
-
values.set(key, fallback);
|
|
44
|
-
}
|
|
45
|
-
return fallback;
|
|
46
|
-
}
|
|
47
|
-
});
|
|
48
|
-
}
|
|
49
|
-
if (typeof prototype.eliminate !== 'function') {
|
|
50
|
-
Object.defineProperty(prototype, 'eliminate', {
|
|
51
|
-
configurable: true,
|
|
52
|
-
writable: true,
|
|
53
|
-
value: function eliminate(key) {
|
|
54
|
-
elementStorage.get(this)?.delete(key);
|
|
55
|
-
return this;
|
|
56
|
-
}
|
|
57
|
-
});
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
/**
|
|
62
|
-
* Parses the legacy gx object-literal DOM dialect.
|
|
63
|
-
* `html` is intentionally treated as trusted legacy markup via `h.raw()`.
|
|
64
|
-
* @param {unknown} source Legacy tree value.
|
|
65
|
-
* @returns {Node|false} Parsed node, or false for unsupported input.
|
|
66
|
-
*/
|
|
67
|
-
export function parse(source) {
|
|
68
|
-
if (source && typeof source === 'object' && typeof source.toElement === 'function') {
|
|
69
|
-
return source.toElement() ?? false;
|
|
70
|
-
}
|
|
71
|
-
if (source && typeof source === 'object' && typeof source.nodeType === 'number') return source;
|
|
72
|
-
if (typeof source === 'string' || typeof source === 'number') return document.createTextNode(String(source));
|
|
73
|
-
if (!source || typeof source !== 'object' || Array.isArray(source)) return false;
|
|
74
|
-
|
|
75
|
-
const descriptor = source;
|
|
76
|
-
const props = {};
|
|
77
|
-
const events = [];
|
|
78
|
-
const reserved = new Set(['tag', 'html', 'styles', 'classes', 'child', 'children', '_adopt', 'events']);
|
|
79
|
-
for (const [key, value] of Object.entries(descriptor)) {
|
|
80
|
-
if (reserved.has(key)) continue;
|
|
81
|
-
if (/^on[A-Z]/.test(key) && typeof value === 'function') {
|
|
82
|
-
events.push([key.slice(2).toLowerCase(), value]);
|
|
83
|
-
} else if (key === 'class') {
|
|
84
|
-
props.class = value;
|
|
85
|
-
} else if (key === 'text') {
|
|
86
|
-
props.textContent = value == null ? '' : String(value);
|
|
87
|
-
} else {
|
|
88
|
-
props[key] = value;
|
|
89
|
-
}
|
|
90
|
-
}
|
|
91
|
-
if (descriptor.styles && typeof descriptor.styles === 'object') props.style = descriptor.styles;
|
|
92
|
-
if (descriptor.classes != null) {
|
|
93
|
-
const classes = Array.isArray(descriptor.classes) ? descriptor.classes : [descriptor.classes];
|
|
94
|
-
props.class = [props.class, ...classes].flat().filter(Boolean);
|
|
95
|
-
}
|
|
96
|
-
const element = h(String(descriptor.tag ?? 'div'), props);
|
|
97
|
-
for (const [type, listener] of events) element.addEventListener(type, listener);
|
|
98
|
-
if (descriptor.events && typeof descriptor.events === 'object') {
|
|
99
|
-
for (const [type, listener] of Object.entries(descriptor.events)) {
|
|
100
|
-
if (typeof listener === 'function') element.addEventListener(type, listener);
|
|
101
|
-
}
|
|
102
|
-
}
|
|
103
|
-
if (descriptor.html != null) element.append(h.raw(String(descriptor.html)));
|
|
104
|
-
appendParsed(element, descriptor._adopt);
|
|
105
|
-
appendParsed(element, descriptor.child);
|
|
106
|
-
if (Array.isArray(descriptor.children)) {
|
|
107
|
-
for (const child of descriptor.children) appendParsed(element, child);
|
|
108
|
-
} else if (descriptor.children && typeof descriptor.children === 'object') {
|
|
109
|
-
const names = [];
|
|
110
|
-
for (const [name, childSource] of Object.entries(descriptor.children)) {
|
|
111
|
-
const child = parse(childSource);
|
|
112
|
-
if (!child) continue;
|
|
113
|
-
element.append(child);
|
|
114
|
-
element[`_${name}`] = child.retrieve?.('com') ?? child;
|
|
115
|
-
names.push(name);
|
|
116
|
-
}
|
|
117
|
-
element.store?.('children', names);
|
|
118
|
-
}
|
|
119
|
-
return element;
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
/**
|
|
123
|
-
* Explicitly installs legacy globals and prototype conveniences.
|
|
124
|
-
* @param {typeof globalThis} [host=globalThis] Realm to modify.
|
|
125
|
-
* @returns {typeof globalThis} The supplied realm.
|
|
126
|
-
*/
|
|
127
|
-
export function installGlobals(host = globalThis) {
|
|
128
|
-
installElementStorage(host);
|
|
129
|
-
host.__ = parse;
|
|
130
|
-
const stringPrototype = host.String?.prototype;
|
|
131
|
-
if (stringPrototype && typeof stringPrototype.htmlSpecialChars !== 'function') {
|
|
132
|
-
Object.defineProperty(stringPrototype, 'htmlSpecialChars', {
|
|
133
|
-
configurable: true,
|
|
134
|
-
writable: true,
|
|
135
|
-
value: function htmlSpecialChars() { return htmlEscape(String(this)); }
|
|
136
|
-
});
|
|
137
|
-
}
|
|
138
|
-
const arrayPrototype = host.Array?.prototype;
|
|
139
|
-
if (arrayPrototype && typeof arrayPrototype.findBy !== 'function') {
|
|
140
|
-
Object.defineProperty(arrayPrototype, 'findBy', {
|
|
141
|
-
configurable: true,
|
|
142
|
-
writable: true,
|
|
143
|
-
value: function findBy(matcher, value) {
|
|
144
|
-
const predicate = typeof matcher === 'string' ? (item) => item?.[matcher] === value : matcher;
|
|
145
|
-
if (typeof predicate !== 'function') return null;
|
|
146
|
-
for (let index = this.length - 1; index >= 0; index -= 1) {
|
|
147
|
-
if (predicate(this[index]) === true) return this[index];
|
|
148
|
-
}
|
|
149
|
-
return null;
|
|
150
|
-
}
|
|
151
|
-
});
|
|
152
|
-
}
|
|
153
|
-
if (host._ === undefined) host._ = (key, args) => translate(String(key), args);
|
|
154
|
-
return host;
|
|
155
|
-
}
|
|
156
|
-
|
|
157
|
-
/** @param {Node} parent @param {unknown} source @returns {void} */
|
|
158
|
-
function appendParsed(parent, source) {
|
|
159
|
-
if (source == null) return;
|
|
160
|
-
const list = Array.isArray(source) ? source : [source];
|
|
161
|
-
for (const item of list) {
|
|
162
|
-
const child = parse(item);
|
|
163
|
-
if (child) parent.append(child);
|
|
164
|
-
}
|
|
165
|
-
}
|
package/src/compat/index.js
DELETED
|
@@ -1,84 +0,0 @@
|
|
|
1
|
-
import { GxWrapper } from './base.js';
|
|
2
|
-
import { installElementStorage, installGlobals, parse } from './globals.js';
|
|
3
|
-
import {
|
|
4
|
-
BootstrapMessage, BootstrapPopup, CheckButton, Dialog, Dropdown, MenuButton, Msgbox, Popup,
|
|
5
|
-
PopupAlert, PopupConfirm, PopupConfirmCanceled, Toggle
|
|
6
|
-
} from './map/basic.js';
|
|
7
|
-
import {
|
|
8
|
-
BootstrapChecklist, BootstrapTable, Checklist, DataFilter, Permission, SimpleTable, Table
|
|
9
|
-
} from './map/data.js';
|
|
10
|
-
import {
|
|
11
|
-
BootstrapTimebox, CoreTimebox, Datebox, DatePicker, MonthPicker, Timebox, TimePicker
|
|
12
|
-
} from './map/date-time.js';
|
|
13
|
-
import { Factory } from './map/factory.js';
|
|
14
|
-
import { Field, Fieldset, FieldUpload, Form, MultiValueEditor, ValueList } from './map/form.js';
|
|
15
|
-
import { Client, Request } from './map/http.js';
|
|
16
|
-
import {
|
|
17
|
-
BootstrapTabbox, Groupbox, MasterPanel, NavigationBar, Panel, Search, Tabbox
|
|
18
|
-
} from './map/layout.js';
|
|
19
|
-
import {
|
|
20
|
-
BootstrapSelect, BootstrapSelectDyn, BootstrapSelectFilter, BootstrapSelectPrio,
|
|
21
|
-
Select, SelectDyn, SelectDynREST, SelectFilter, SelectPrio
|
|
22
|
-
} from './map/select.js';
|
|
23
|
-
import { Container, Settings, Blend, Collapse, HGroup, Hud, Templates, Toggling } from './map/stubs.js';
|
|
24
|
-
import { util } from './map/utilities.js';
|
|
25
|
-
|
|
26
|
-
/** Compatibility utilities and explicit global/prototype installers. */
|
|
27
|
-
const compat = Object.freeze({ installGlobals, installElementStorage, parse, GxWrapper });
|
|
28
|
-
|
|
29
|
-
/** Window-independent legacy gx namespace. */
|
|
30
|
-
export const gx = {
|
|
31
|
-
core: { Settings },
|
|
32
|
-
ui: {
|
|
33
|
-
Container, SimpleTable, Timebox: CoreTimebox,
|
|
34
|
-
Collapse, Blend, Hud, Toggling, HGroup, Templates
|
|
35
|
-
},
|
|
36
|
-
util,
|
|
37
|
-
zeyos: {
|
|
38
|
-
Toggle, Msgbox, Popup, Dialog, Dropdown,
|
|
39
|
-
Select, SelectFilter, SelectDyn, SelectPrio,
|
|
40
|
-
Checklist, Permission, Table, Tabbox,
|
|
41
|
-
Panel, MasterPanel, Groupbox, Search,
|
|
42
|
-
Datebox, DatePicker, TimePicker, MonthPicker, Timebox,
|
|
43
|
-
Client, Request, Factory
|
|
44
|
-
},
|
|
45
|
-
bootstrap: {
|
|
46
|
-
Message: BootstrapMessage,
|
|
47
|
-
Popup: BootstrapPopup,
|
|
48
|
-
PopupAlert,
|
|
49
|
-
PopupConfirm,
|
|
50
|
-
PopupConfirmCanceled,
|
|
51
|
-
MenuButton,
|
|
52
|
-
CheckButton,
|
|
53
|
-
Select: BootstrapSelect,
|
|
54
|
-
SelectFilter: BootstrapSelectFilter,
|
|
55
|
-
SelectDyn: BootstrapSelectDyn,
|
|
56
|
-
SelectDynREST,
|
|
57
|
-
SelectPrio: BootstrapSelectPrio,
|
|
58
|
-
Checklist: BootstrapChecklist,
|
|
59
|
-
Table: BootstrapTable,
|
|
60
|
-
Tabbox: BootstrapTabbox,
|
|
61
|
-
NavigationBar,
|
|
62
|
-
Timebox: BootstrapTimebox,
|
|
63
|
-
Form,
|
|
64
|
-
Fieldset,
|
|
65
|
-
Field,
|
|
66
|
-
ValueList,
|
|
67
|
-
MultiValueEditor,
|
|
68
|
-
FieldUpload,
|
|
69
|
-
DataFilter
|
|
70
|
-
},
|
|
71
|
-
compat
|
|
72
|
-
};
|
|
73
|
-
|
|
74
|
-
/** Assigns the compatibility namespace to a browser-like host without installing optional globals. @param {typeof globalThis} [host=globalThis] @returns {typeof gx} */
|
|
75
|
-
export function install(host = globalThis) {
|
|
76
|
-
installElementStorage(host);
|
|
77
|
-
host.gx = gx;
|
|
78
|
-
return gx;
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
gx.install = install;
|
|
82
|
-
|
|
83
|
-
export { GxWrapper, installElementStorage, installGlobals, parse };
|
|
84
|
-
export default gx;
|