jsl-ui 10.1.0 → 10.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/docs/DataBinding.md +19 -0
- package/docs/DateTimeComponent.md +1 -0
- package/docs/GridComponent.md +8 -5
- package/docs/InputComponent.md +1 -1
- package/docs/README.md +1 -0
- package/examples/showcase/checks-and-expanders.ts +2 -17
- package/examples/showcase/data-binding.ts +138 -0
- package/examples/showcase/dates.ts +6 -16
- package/examples/showcase/fields.ts +14 -26
- package/examples/showcase/generate-sources.cjs +104 -0
- package/examples/showcase/grids.ts +246 -17
- package/examples/showcase/index.html +12 -2
- package/examples/showcase/selects.ts +6 -8
- package/examples/showcase/showcase-sources.ts +95 -0
- package/examples/showcase/showcase.css +23 -2
- package/examples/showcase/showcase.ts +28 -5
- package/lib/components/auto-suggest/AutoSuggestComponent.d.ts +4 -4
- package/lib/components/auto-suggest/AutoSuggestComponent.js +1 -1
- package/lib/components/checkbox/CheckBoxComponent.d.ts +2 -3
- package/lib/components/checkbox/CheckBoxComponent.js +7 -20
- package/lib/components/date/DateComponent.d.ts +4 -4
- package/lib/components/date/DateComponent.js +11 -27
- package/lib/components/date-time/DateTimeComponent.d.ts +4 -4
- package/lib/components/date-time/DateTimeComponent.js +21 -32
- package/lib/components/input/InputComponent.d.ts +1 -4
- package/lib/components/input/InputComponent.js +14 -32
- package/lib/components/number/NumberComponent.d.ts +1 -4
- package/lib/components/number/NumberComponent.js +11 -29
- package/lib/components/select/SelectComponent.d.ts +1 -3
- package/lib/components/select/SelectComponent.js +8 -22
- package/lib/components/time/TimeComponent.d.ts +4 -3
- package/lib/components/time/TimeComponent.js +11 -24
- package/lib/grid/filterDialogs/excelFilter.js +12 -10
- package/lib/grid/plugins/slick.headermenu.css +98 -101
- package/lib/grid/slick-default-theme.css +10 -2
- package/lib/grid/slick.grid.css +112 -1
- package/lib/grid.css +852 -3392
- package/lib/index.css +260 -124
- package/lib/index.css.map +1 -1
- package/lib/index.js.map +1 -1
- package/lib/interaction/data-binding.d.ts +27 -0
- package/lib/interaction/data-binding.js +72 -0
- package/package.json +3 -1
|
@@ -11,12 +11,12 @@
|
|
|
11
11
|
/* Keep the showcase layout predictable without resetting sizing on library DOM.
|
|
12
12
|
Grid cells and component internals should exercise their own box model. */
|
|
13
13
|
:where(
|
|
14
|
-
.skip-link, .sidebar, .brand, .brand-caption, .brand-mark, .nav-label, .nav-item,
|
|
14
|
+
.skip-link, .sidebar, .brand, .brand-caption, .brand-mark, .nav-label, .nav-item, .nav-group, .nav-submenu, .nav-subitem,
|
|
15
15
|
.nav-number, .nav-icon, .sidebar-note, .status-dot, main, .page-meta, .page-tools,
|
|
16
16
|
.theme-picker, .version, .hero, .eyebrow, .hero-preview, .preview-caption,
|
|
17
17
|
.preview-note, .hero-description, .overview-bar, .overview-label, .overview-stat,
|
|
18
18
|
.sample-grid, .sample-card, .card-heading, .sample-number, .card-description,
|
|
19
|
-
.sample-row, .sample-status, .sample-code, .inline-note, .showcase-icon,
|
|
19
|
+
.sample-row, .sample-status, .sample-code, .inline-note, .showcase-icon, .binding-field,
|
|
20
20
|
.format-bold, .format-italic, .format-underline, .sample-divider, .size-row,
|
|
21
21
|
.size-sample, .size-caption, .context-panel, .context-body, .context-eyebrow,
|
|
22
22
|
.context-copy, .context-footer, .count-badge, .usage, .page-footer,
|
|
@@ -56,6 +56,11 @@ a { color: inherit; }
|
|
|
56
56
|
.nav-item { display: flex; align-items: center; gap: 10px; padding: 9px 12px; margin-bottom: 4px; border-radius: 6px; color: var(--jsl-color-text-secondary); text-decoration: none; font-size: 13px; font-weight: 600; }
|
|
57
57
|
.nav-item:hover { background: var(--jsl-color-surface-hover); }
|
|
58
58
|
.nav-item[aria-current] { background: var(--jsl-color-surface-selected); color: var(--jsl-color-text); }
|
|
59
|
+
.nav-group:has(.nav-subitem[aria-current]) > .nav-item { background: var(--jsl-color-surface-selected); color: var(--jsl-color-text); }
|
|
60
|
+
.nav-submenu { margin: -2px 0 8px 38px; padding-left: 10px; border-left: 1px solid var(--jsl-color-border-subtle); display: flex; flex-direction: column; gap: 2px; }
|
|
61
|
+
.nav-subitem { display: block; padding: 5px 8px; border-radius: 5px; color: var(--jsl-color-text-muted); text-decoration: none; font-size: 11px; line-height: 1.4; }
|
|
62
|
+
.nav-subitem:hover { background: var(--jsl-color-surface-hover); color: var(--jsl-color-text); }
|
|
63
|
+
.nav-subitem[aria-current] { color: var(--jsl-color-text); font-weight: 600; background: var(--jsl-color-surface-selected); }
|
|
59
64
|
.nav-number { margin-left: auto; font-size: 10px; font-weight: 400; color: var(--jsl-color-text-muted); }
|
|
60
65
|
.nav-icon { font-size: 17px; }
|
|
61
66
|
.sidebar nav { min-height: 0; overflow-y: auto; scrollbar-width: thin; }
|
|
@@ -258,9 +263,25 @@ h2 { font-size: 14px; font-weight: 600; margin: 0; letter-spacing: -0.15px; }
|
|
|
258
263
|
.layout-demo-panel p { color: var(--jsl-color-text-secondary); font-size: 13px; line-height: 1.6; }
|
|
259
264
|
.tree-demo-content { display: flex; align-items: center; gap: 8px; }
|
|
260
265
|
.grid-samples { display: flex; flex-direction: column; gap: 24px; margin: 24px 0; }
|
|
266
|
+
.grid-category { scroll-margin-top: 12px; }
|
|
267
|
+
.grid-category-title { margin: 0 0 12px; padding-bottom: 8px; border-bottom: 1px solid var(--jsl-color-border-subtle); color: var(--jsl-color-text-secondary); font-size: 12px; font-weight: 600; }
|
|
268
|
+
.grid-category-samples { display: flex; flex-direction: column; gap: 16px; }
|
|
261
269
|
.grid-sample-card { min-width: 0; }
|
|
262
270
|
.grid-sample-card h3 { margin: 0; font-size: 14px; font-weight: 600; }
|
|
263
271
|
.grid-sample-host { min-width: 0; }
|
|
272
|
+
.grid-selection-mode { display: flex; align-items: center; gap: 10px; margin: 0 0 14px; font-size: 12px; color: var(--jsl-color-text-secondary); }
|
|
273
|
+
.grid-selection-mode select { padding: 5px 8px; border: 1px solid var(--jsl-color-border); border-radius: 5px; color: var(--jsl-color-text); background: var(--jsl-color-surface); font: inherit; }
|
|
274
|
+
.grid-selection-summary { margin: 14px 0 0; overflow-wrap: anywhere; }
|
|
275
|
+
.showcase-source { margin-top: 18px; }
|
|
276
|
+
.showcase-source summary { cursor: pointer; color: var(--jsl-color-text-secondary); font-size: 12px; font-weight: 600; }
|
|
277
|
+
.showcase-source-code { max-width: 100%; overflow: auto; white-space: pre; overflow-wrap: normal; margin-top: 10px; }
|
|
278
|
+
.grid-header-starred { color: #d4a000; }
|
|
264
279
|
.page-tools { flex-wrap: wrap; }
|
|
265
280
|
.format-preview { color: var(--jsl-color-text-muted); font-size: 11px; letter-spacing: 0; white-space: nowrap; }
|
|
266
281
|
#grid-reorder .grid-row-handle { cursor: grab; text-align: center; color: var(--jsl-color-text-muted); }
|
|
282
|
+
.binding-sample-grid > .sample-card:last-child { grid-column: auto; }
|
|
283
|
+
.binding-field { display: flex; flex-direction: column; align-items: flex-start; gap: 8px; margin: 14px 0; }
|
|
284
|
+
.binding-field > label { color: var(--jsl-color-text-secondary); font-size: 12px; font-weight: 500; }
|
|
285
|
+
.binding-field > .jsl-input, .binding-field > .jsl-number, .binding-field > .select-comp { width: 100%; }
|
|
286
|
+
.binding-preview { width: 24rem; max-width: 100%; }
|
|
287
|
+
.binding-preview .binding-field { width: 100%; margin: 0; }
|
|
@@ -11,6 +11,8 @@ import { notificationShowcase, loadingShowcase, navigationShowcase } from "./fee
|
|
|
11
11
|
import { progressShowcase, stackShowcase, treeShowcase, overlayShowcase, ribbonShowcase } from "./layout-and-navigation";
|
|
12
12
|
import { sliderShowcase, dateShowcase, dateRangeShowcase, dateTimeShowcase } from "./dates";
|
|
13
13
|
import { dropdownMenuShowcase } from "./dropdown-menus";
|
|
14
|
+
import { dataBindingShowcase } from "./data-binding";
|
|
15
|
+
import { showcaseSources } from "./showcase-sources";
|
|
14
16
|
import { IJSLComponent, IJSLVNode, JSLRender } from "jsl-render";
|
|
15
17
|
import { ButtonComponent, IButtonOptions } from "../../components/button/ButtonComponent";
|
|
16
18
|
|
|
@@ -180,8 +182,7 @@ const usage: IJSLVNode = {
|
|
|
180
182
|
]
|
|
181
183
|
};
|
|
182
184
|
|
|
183
|
-
|
|
184
|
-
new JSLRender(document.getElementById("showcase"), true).render({
|
|
185
|
+
const showcaseContent: IJSLVNode = {
|
|
185
186
|
tag: "div", children: [{
|
|
186
187
|
tag: "section", attr: { id: "buttons", "aria-labelledby": "buttons-title" }, children: [
|
|
187
188
|
group([
|
|
@@ -191,10 +192,32 @@ new JSLRender(document.getElementById("showcase"), true).render({
|
|
|
191
192
|
group([node("span", "Overview", "overview-label"), node("span", "3 variants", "overview-stat"), node("span", "3 sizes", "overview-stat"), node("span", "Keyboard accessible", "overview-stat")], "overview-bar"),
|
|
192
193
|
group(cards, "sample-grid"), usage
|
|
193
194
|
]
|
|
194
|
-
}, dialogShowcase, tabsShowcase, sliderShowcase, dateShowcase, dateRangeShowcase, dateTimeShowcase, selectShowcase, checkboxShowcase, expanderShowcase, inputShowcase, numberShowcase, formFieldShowcase, notificationShowcase, loadingShowcase, navigationShowcase, progressShowcase, stackShowcase, treeShowcase, overlayShowcase, ribbonShowcase, gridShowcase, dropdownMenuShowcase]
|
|
195
|
-
}
|
|
195
|
+
}, dialogShowcase, tabsShowcase, sliderShowcase, dateShowcase, dateRangeShowcase, dateTimeShowcase, selectShowcase, checkboxShowcase, expanderShowcase, inputShowcase, numberShowcase, formFieldShowcase, notificationShowcase, loadingShowcase, navigationShowcase, progressShowcase, stackShowcase, treeShowcase, overlayShowcase, ribbonShowcase, gridShowcase, dropdownMenuShowcase, dataBindingShowcase]
|
|
196
|
+
};
|
|
197
|
+
|
|
198
|
+
function addCodeViews(content: Content, sectionId?: string): void {
|
|
199
|
+
if (!("tag" in content)) return;
|
|
200
|
+
const id = content.tag === "section" && content.attr?.id ? content.attr.id : sectionId;
|
|
201
|
+
const classes = typeof content.attr?.class === "string" ? content.attr.class.split(/\s+/) : [];
|
|
202
|
+
if (classes.includes("sample-card")) {
|
|
203
|
+
const source = showcaseSources[content.attr.id || id];
|
|
204
|
+
const alreadyHasCode = content.children?.some(child => "tag" in child && child.attr?.class === "showcase-source");
|
|
205
|
+
if (source && !alreadyHasCode) {
|
|
206
|
+
content.children = content.children || [];
|
|
207
|
+
content.children.push({ tag: "details", attr: { class: "showcase-source" }, children: [
|
|
208
|
+
node("summary", "Show code"),
|
|
209
|
+
{ tag: "pre", attr: { class: "sample-code showcase-source-code" }, children: [{ tag: "code", content: source }] }
|
|
210
|
+
] });
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
content.children?.forEach(child => addCodeViews(child, id));
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
addCodeViews(showcaseContent);
|
|
217
|
+
JSLRender.PrintRenderTime = false;
|
|
218
|
+
new JSLRender(document.getElementById("showcase"), true).render(showcaseContent);
|
|
196
219
|
|
|
197
|
-
const navigation = Array.from(document.querySelectorAll<HTMLAnchorElement>(".nav-item"));
|
|
220
|
+
const navigation = Array.from(document.querySelectorAll<HTMLAnchorElement>(".nav-item, .nav-subitem"));
|
|
198
221
|
let navigationScheduled = false;
|
|
199
222
|
function updateNavigation() {
|
|
200
223
|
navigationScheduled = false;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { IJSLVNode } from "jsl-render";
|
|
2
2
|
import { IAutoSuggestOptions, IAutoSuggest } from "../../ui/auto.suggest";
|
|
3
|
-
import { InputComponent } from "../input/InputComponent";
|
|
4
|
-
export interface IAutoSuggestComponentOptions extends IAutoSuggestOptions {
|
|
3
|
+
import { InputComponent, IInputOptions } from "../input/InputComponent";
|
|
4
|
+
export interface IAutoSuggestComponentOptions<T = any> extends IAutoSuggestOptions, Pick<IInputOptions<T>, "bindTo" | "property" | "bindMode" | "converter" | "bindOnInput" | "onInput"> {
|
|
5
5
|
id?: string;
|
|
6
6
|
value?: string;
|
|
7
7
|
class?: string;
|
|
@@ -13,11 +13,11 @@ export interface IAutoSuggestComponentOptions extends IAutoSuggestOptions {
|
|
|
13
13
|
ariaLabel?: string;
|
|
14
14
|
maxLength?: number;
|
|
15
15
|
}
|
|
16
|
-
export declare class AutoSuggestComponent extends InputComponent {
|
|
16
|
+
export declare class AutoSuggestComponent<T = any> extends InputComponent<T> {
|
|
17
17
|
private ref;
|
|
18
18
|
private input;
|
|
19
19
|
private suggestOptions;
|
|
20
|
-
constructor(options: IAutoSuggestComponentOptions);
|
|
20
|
+
constructor(options: IAutoSuggestComponentOptions<T>);
|
|
21
21
|
getRef(): IAutoSuggest;
|
|
22
22
|
onCreate(node: IJSLVNode): void;
|
|
23
23
|
onRemove(): void;
|
|
@@ -14,7 +14,7 @@ export class AutoSuggestComponent extends InputComponent {
|
|
|
14
14
|
}
|
|
15
15
|
this.ref = AutoSuggest(this.input, {
|
|
16
16
|
...this.suggestOptions,
|
|
17
|
-
onChange: value => { var _a, _b, _c;
|
|
17
|
+
onChange: value => { var _a, _b, _c; (_b = (_a = this.suggestOptions).onChange) === null || _b === void 0 ? void 0 : _b.call(_a, value); (_c = this.renderer) === null || _c === void 0 ? void 0 : _c.refresh(); },
|
|
18
18
|
onSelect: (event, term, element) => {
|
|
19
19
|
var _a, _b, _c;
|
|
20
20
|
this.setValue(term);
|
|
@@ -21,6 +21,7 @@ export interface ICheckBoxOptions<T = any> {
|
|
|
21
21
|
export declare class CheckBoxComponent<T = any> implements IJSLComponent {
|
|
22
22
|
private options;
|
|
23
23
|
private currentDom;
|
|
24
|
+
private binding;
|
|
24
25
|
get onChange(): EventHandler<boolean>;
|
|
25
26
|
constructor(options: ICheckBoxOptions<T>);
|
|
26
27
|
render(): IJSLVNode;
|
|
@@ -29,10 +30,8 @@ export declare class CheckBoxComponent<T = any> implements IJSLComponent {
|
|
|
29
30
|
setValue(value: boolean): void;
|
|
30
31
|
get indeterminate(): boolean;
|
|
31
32
|
set indeterminate(value: boolean);
|
|
33
|
+
onInit(): void;
|
|
32
34
|
onCreate(node: IJSLVNode): void;
|
|
33
35
|
onRemove(): void;
|
|
34
|
-
private hasBinding;
|
|
35
|
-
private readModel;
|
|
36
|
-
private writeModel;
|
|
37
36
|
private raiseEvent;
|
|
38
37
|
}
|
|
@@ -1,21 +1,19 @@
|
|
|
1
1
|
import "./CheckBoxStyle.scss";
|
|
2
2
|
import { EventHandler } from "../../interaction/eventhandler";
|
|
3
|
+
import { DataBinding } from "../../interaction/data-binding";
|
|
3
4
|
import { helper } from "../../core/helper";
|
|
4
5
|
export class CheckBoxComponent {
|
|
5
6
|
get onChange() { return this.options.onChange; }
|
|
6
7
|
constructor(options) {
|
|
7
8
|
this.options = { enabled: true, class: "", bindMode: "toModel", ...options };
|
|
8
9
|
this.options.id = this.options.id || helper.newDomGuid();
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
}
|
|
10
|
+
this.binding = new DataBinding(options);
|
|
11
|
+
this.options.value = !!this.binding.initialValueOr(this.options.value);
|
|
12
12
|
this.options.onChange = EventHandler.Create(this.options.onChange);
|
|
13
13
|
}
|
|
14
14
|
render() {
|
|
15
15
|
var _a;
|
|
16
|
-
|
|
17
|
-
this.options.value = this.readModel();
|
|
18
|
-
}
|
|
16
|
+
this.binding.sync(value => { this.options.value = !!value; });
|
|
19
17
|
if (this.currentDom) {
|
|
20
18
|
this.currentDom.checked = !!this.options.value;
|
|
21
19
|
this.currentDom.indeterminate = !!this.options.indeterminate;
|
|
@@ -52,7 +50,7 @@ export class CheckBoxComponent {
|
|
|
52
50
|
if (this.currentDom) {
|
|
53
51
|
this.currentDom.checked = !!value;
|
|
54
52
|
}
|
|
55
|
-
this.
|
|
53
|
+
this.binding.write(value);
|
|
56
54
|
}
|
|
57
55
|
get indeterminate() { var _a, _b; return (_b = (_a = this.currentDom) === null || _a === void 0 ? void 0 : _a.indeterminate) !== null && _b !== void 0 ? _b : !!this.options.indeterminate; }
|
|
58
56
|
set indeterminate(value) {
|
|
@@ -61,23 +59,12 @@ export class CheckBoxComponent {
|
|
|
61
59
|
this.currentDom.indeterminate = !!value;
|
|
62
60
|
}
|
|
63
61
|
}
|
|
62
|
+
onInit() { this.binding.initialize(); }
|
|
64
63
|
onCreate(node) {
|
|
65
64
|
this.currentDom = node.dom.querySelector("input");
|
|
66
65
|
this.currentDom.indeterminate = !!this.options.indeterminate;
|
|
67
66
|
}
|
|
68
67
|
onRemove() { this.currentDom = null; }
|
|
69
|
-
hasBinding() { return this.options.bindTo != null && this.options.property != null; }
|
|
70
|
-
readModel() {
|
|
71
|
-
var _a;
|
|
72
|
-
const value = this.options.bindTo[this.options.property];
|
|
73
|
-
return !!(((_a = this.options.converter) === null || _a === void 0 ? void 0 : _a.toUI) ? this.options.converter.toUI(value) : value);
|
|
74
|
-
}
|
|
75
|
-
writeModel(value) {
|
|
76
|
-
var _a;
|
|
77
|
-
if (this.hasBinding() && this.options.bindMode !== "fromModel") {
|
|
78
|
-
this.options.bindTo[this.options.property] = ((_a = this.options.converter) === null || _a === void 0 ? void 0 : _a.toData) ? this.options.converter.toData(value) : value;
|
|
79
|
-
}
|
|
80
|
-
}
|
|
81
68
|
raiseEvent(event, node) {
|
|
82
69
|
if (!this.options.enabled) {
|
|
83
70
|
return false;
|
|
@@ -85,7 +72,7 @@ export class CheckBoxComponent {
|
|
|
85
72
|
this.currentDom = node.dom;
|
|
86
73
|
this.options.value = this.currentDom.checked;
|
|
87
74
|
this.options.indeterminate = this.currentDom.indeterminate;
|
|
88
|
-
this.
|
|
75
|
+
this.binding.write(this.options.value);
|
|
89
76
|
this.onChange.notify(this.options.value);
|
|
90
77
|
}
|
|
91
78
|
}
|
|
@@ -21,22 +21,22 @@ export declare class DateComponent<T = any> implements IJSLComponent {
|
|
|
21
21
|
private options;
|
|
22
22
|
private ref;
|
|
23
23
|
private currentDom;
|
|
24
|
-
private
|
|
24
|
+
private binding;
|
|
25
25
|
constructor(options: IDateComponentOptions<T>);
|
|
26
26
|
get onChange(): EventHandler<Date>;
|
|
27
27
|
render(): IJSLVNode;
|
|
28
28
|
getValue(): string;
|
|
29
29
|
getValueAsDate(): Date;
|
|
30
30
|
isValid(): boolean;
|
|
31
|
-
/** Updates the input and
|
|
31
|
+
/** Updates the input, calendar and writable binding without raising onChange. */
|
|
32
32
|
setValue(value: Date): void;
|
|
33
|
+
private applyValue;
|
|
33
34
|
getRef(): IDatePicker;
|
|
35
|
+
onInit(): void;
|
|
34
36
|
onCreate(node: IJSLVNode): void;
|
|
35
37
|
onUpdate(node: IJSLVNode): void;
|
|
36
38
|
onRemove(): void;
|
|
37
39
|
private format;
|
|
38
|
-
private hasBinding;
|
|
39
|
-
private readModel;
|
|
40
40
|
private raiseEvent;
|
|
41
41
|
private parseBoundary;
|
|
42
42
|
}
|
|
@@ -3,14 +3,12 @@ import { DatePicker } from "../../ui/date.picker";
|
|
|
3
3
|
import { date } from "../../core/date";
|
|
4
4
|
import { helper } from "../../core/helper";
|
|
5
5
|
import { EventHandler } from "../../interaction/eventhandler";
|
|
6
|
+
import { DataBinding } from "../../interaction/data-binding";
|
|
6
7
|
export class DateComponent {
|
|
7
8
|
constructor(options) {
|
|
8
|
-
var _a;
|
|
9
9
|
this.options = { enabled: true, id: helper.newDomGuid(), bindMode: "toModel", ...options };
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
}
|
|
13
|
-
this.modelValue = (_a = this.options.value) === null || _a === void 0 ? void 0 : _a.getTime();
|
|
10
|
+
this.binding = new DataBinding(options);
|
|
11
|
+
this.options.value = this.binding.initialValueOr(this.options.value);
|
|
14
12
|
this.options.onChange = EventHandler.Create(this.options.onChange);
|
|
15
13
|
}
|
|
16
14
|
get onChange() {
|
|
@@ -18,13 +16,7 @@ export class DateComponent {
|
|
|
18
16
|
}
|
|
19
17
|
render() {
|
|
20
18
|
var _a;
|
|
21
|
-
|
|
22
|
-
const value = this.readModel();
|
|
23
|
-
if ((value === null || value === void 0 ? void 0 : value.getTime()) !== this.modelValue) {
|
|
24
|
-
this.setValue(value);
|
|
25
|
-
this.modelValue = value === null || value === void 0 ? void 0 : value.getTime();
|
|
26
|
-
}
|
|
27
|
-
}
|
|
19
|
+
this.binding.sync(value => this.applyValue(value));
|
|
28
20
|
return {
|
|
29
21
|
tag: "input",
|
|
30
22
|
attr: {
|
|
@@ -69,8 +61,12 @@ export class DateComponent {
|
|
|
69
61
|
return !(min && stamp < min.getTime()) && !(max && stamp > max.getTime()) &&
|
|
70
62
|
(!this.options.inRange || this.options.inRange(value));
|
|
71
63
|
}
|
|
72
|
-
/** Updates the input and
|
|
64
|
+
/** Updates the input, calendar and writable binding without raising onChange. */
|
|
73
65
|
setValue(value) {
|
|
66
|
+
this.applyValue(value);
|
|
67
|
+
this.binding.write(value);
|
|
68
|
+
}
|
|
69
|
+
applyValue(value) {
|
|
74
70
|
var _a;
|
|
75
71
|
this.options.value = value ? new Date(value.getTime()) : null;
|
|
76
72
|
if (this.currentDom) {
|
|
@@ -81,6 +77,7 @@ export class DateComponent {
|
|
|
81
77
|
(_a = this.ref) === null || _a === void 0 ? void 0 : _a.setState({ selectedDate: this.options.value }, true);
|
|
82
78
|
}
|
|
83
79
|
getRef() { return this.ref; }
|
|
80
|
+
onInit() { this.binding.initialize(); }
|
|
84
81
|
onCreate(node) {
|
|
85
82
|
this.currentDom = node.dom;
|
|
86
83
|
this.ref = DatePicker(this.currentDom, this.options);
|
|
@@ -91,16 +88,7 @@ export class DateComponent {
|
|
|
91
88
|
var _a;
|
|
92
89
|
return value ? ((_a = this.options.format) !== null && _a !== void 0 ? _a : date.format)(value) : "";
|
|
93
90
|
}
|
|
94
|
-
hasBinding() {
|
|
95
|
-
return this.options.bindTo != null && this.options.property != null;
|
|
96
|
-
}
|
|
97
|
-
readModel() {
|
|
98
|
-
var _a;
|
|
99
|
-
const value = this.options.bindTo[this.options.property];
|
|
100
|
-
return ((_a = this.options.converter) === null || _a === void 0 ? void 0 : _a.toUI) ? this.options.converter.toUI(value) : value;
|
|
101
|
-
}
|
|
102
91
|
raiseEvent(e, node) {
|
|
103
|
-
var _a;
|
|
104
92
|
if (!this.options.enabled) {
|
|
105
93
|
return;
|
|
106
94
|
}
|
|
@@ -114,11 +102,7 @@ export class DateComponent {
|
|
|
114
102
|
}
|
|
115
103
|
this.currentDom.removeAttribute("aria-invalid");
|
|
116
104
|
this.options.value = value;
|
|
117
|
-
|
|
118
|
-
this.options.bindTo[this.options.property] =
|
|
119
|
-
((_a = this.options.converter) === null || _a === void 0 ? void 0 : _a.toData) ? this.options.converter.toData(value) : value;
|
|
120
|
-
this.modelValue = value === null || value === void 0 ? void 0 : value.getTime();
|
|
121
|
-
}
|
|
105
|
+
this.binding.write(value);
|
|
122
106
|
this.onChange.notify(value);
|
|
123
107
|
}
|
|
124
108
|
parseBoundary(value) {
|
|
@@ -10,14 +10,14 @@ export declare class DateTimeComponent<T = any> implements IJSLComponent {
|
|
|
10
10
|
private options;
|
|
11
11
|
private dateComp;
|
|
12
12
|
private timeComp;
|
|
13
|
-
private
|
|
13
|
+
private binding;
|
|
14
14
|
constructor(options: IDateTimeComponentOptions<T>);
|
|
15
15
|
render(): IJSLVNode;
|
|
16
16
|
getValue(): string;
|
|
17
17
|
getValueAsDate(): Date;
|
|
18
|
-
/** Updates both fields without raising onChange. */
|
|
18
|
+
/** Updates both fields and the writable binding without raising onChange. */
|
|
19
19
|
setValue(value: Date): void;
|
|
20
|
-
private
|
|
21
|
-
|
|
20
|
+
private applyValue;
|
|
21
|
+
onInit(): void;
|
|
22
22
|
private raiseChange;
|
|
23
23
|
}
|
|
@@ -3,36 +3,31 @@ import { EventHandler } from "../../interaction/eventhandler";
|
|
|
3
3
|
import { helper } from "../../core/helper";
|
|
4
4
|
import { DateComponent } from "../date/DateComponent";
|
|
5
5
|
import { TimeComponent } from "../time/TimeComponent";
|
|
6
|
+
import { DataBinding } from "../../interaction/data-binding";
|
|
6
7
|
export class DateTimeComponent {
|
|
7
8
|
constructor(options) {
|
|
8
|
-
var _a, _b, _c
|
|
9
|
+
var _a, _b, _c;
|
|
9
10
|
this.options = { bindMode: "toModel", ...options };
|
|
10
11
|
this.options.onChange = EventHandler.Create(this.options.onChange);
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
const id = (
|
|
12
|
+
this.binding = new DataBinding(options);
|
|
13
|
+
const value = this.binding.initialValueOr(options.value);
|
|
14
|
+
const id = (_a = options.id) !== null && _a !== void 0 ? _a : helper.newDomGuid();
|
|
14
15
|
const childOptions = {
|
|
15
16
|
...options, value, bindTo: null, property: null, converter: null,
|
|
16
17
|
bindMode: "toModel", class: undefined, style: undefined,
|
|
17
18
|
onChange: () => this.raiseChange()
|
|
18
19
|
};
|
|
19
20
|
this.dateComp = new DateComponent({
|
|
20
|
-
...childOptions, id, ariaLabel: (
|
|
21
|
+
...childOptions, id, ariaLabel: (_b = options.dateAriaLabel) !== null && _b !== void 0 ? _b : "Date"
|
|
21
22
|
});
|
|
22
23
|
this.timeComp = new TimeComponent({
|
|
23
24
|
...childOptions, id: id + "-time", placeholder: options.inputMode === "HourMinuteSecond" ? "HH:MM:SS" : "HH:MM",
|
|
24
|
-
ariaLabel: (
|
|
25
|
+
ariaLabel: (_c = options.timeAriaLabel) !== null && _c !== void 0 ? _c : "Time"
|
|
25
26
|
});
|
|
26
27
|
}
|
|
27
28
|
render() {
|
|
28
29
|
var _a, _b;
|
|
29
|
-
|
|
30
|
-
const value = this.readModel();
|
|
31
|
-
if ((value === null || value === void 0 ? void 0 : value.getTime()) !== this.modelValue) {
|
|
32
|
-
this.setValue(value);
|
|
33
|
-
this.modelValue = value === null || value === void 0 ? void 0 : value.getTime();
|
|
34
|
-
}
|
|
35
|
-
}
|
|
30
|
+
this.binding.sync(value => this.applyValue(value));
|
|
36
31
|
return {
|
|
37
32
|
tag: "div", attr: {
|
|
38
33
|
class: "date-time-comp " + ((_a = this.options.class) !== null && _a !== void 0 ? _a : ""),
|
|
@@ -49,32 +44,26 @@ export class DateTimeComponent {
|
|
|
49
44
|
const date = this.dateComp.getValueAsDate();
|
|
50
45
|
return date && this.dateComp.isValid() ? this.timeComp.getValueAsDate(date) : null;
|
|
51
46
|
}
|
|
52
|
-
/** Updates both fields without raising onChange. */
|
|
47
|
+
/** Updates both fields and the writable binding without raising onChange. */
|
|
53
48
|
setValue(value) {
|
|
49
|
+
this.applyValue(value);
|
|
50
|
+
this.binding.write(value);
|
|
51
|
+
}
|
|
52
|
+
applyValue(value) {
|
|
54
53
|
this.dateComp.setValue(value);
|
|
55
54
|
this.timeComp.setValue(value);
|
|
56
55
|
}
|
|
57
|
-
|
|
58
|
-
return this.options.bindTo != null && this.options.property != null;
|
|
59
|
-
}
|
|
60
|
-
readModel() {
|
|
61
|
-
var _a;
|
|
62
|
-
const value = this.options.bindTo[this.options.property];
|
|
63
|
-
return ((_a = this.options.converter) === null || _a === void 0 ? void 0 : _a.toUI) ? this.options.converter.toUI(value) : value;
|
|
64
|
-
}
|
|
56
|
+
onInit() { this.binding.initialize(); }
|
|
65
57
|
raiseChange() {
|
|
66
|
-
|
|
67
|
-
const
|
|
68
|
-
//
|
|
69
|
-
if (!this.dateComp.isValid() ||
|
|
70
|
-
(
|
|
58
|
+
const dateText = this.dateComp.getValue().trim();
|
|
59
|
+
const timeText = this.timeComp.getValue().trim();
|
|
60
|
+
// A partial or invalid pair is a draft; clearing both fields publishes null.
|
|
61
|
+
if (!!dateText !== !!timeText || !this.dateComp.isValid() ||
|
|
62
|
+
(timeText && !this.timeComp.getValueAsDate(null))) {
|
|
71
63
|
return;
|
|
72
64
|
}
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
((_a = this.options.converter) === null || _a === void 0 ? void 0 : _a.toData) ? this.options.converter.toData(value) : value;
|
|
76
|
-
this.modelValue = value === null || value === void 0 ? void 0 : value.getTime();
|
|
77
|
-
}
|
|
65
|
+
const value = dateText ? this.getValueAsDate() : null;
|
|
66
|
+
this.binding.write(value);
|
|
78
67
|
this.options.onChange.notify(value);
|
|
79
68
|
}
|
|
80
69
|
}
|
|
@@ -27,7 +27,7 @@ export interface IInputOptions<T = any> {
|
|
|
27
27
|
export declare class InputComponent<T = any> implements IJSLComponent {
|
|
28
28
|
private options;
|
|
29
29
|
private currentDom;
|
|
30
|
-
private
|
|
30
|
+
private binding;
|
|
31
31
|
private initialTextValue;
|
|
32
32
|
protected renderer: JSLRender;
|
|
33
33
|
get onChange(): EventHandler<string>;
|
|
@@ -42,9 +42,6 @@ export declare class InputComponent<T = any> implements IJSLComponent {
|
|
|
42
42
|
onCreate(node: IJSLVNode): void;
|
|
43
43
|
onUpdate(node: IJSLVNode): void;
|
|
44
44
|
onRemove(): void;
|
|
45
|
-
private hasBinding;
|
|
46
|
-
private readModel;
|
|
47
|
-
private writeModel;
|
|
48
45
|
private raiseChangeEvent;
|
|
49
46
|
private raiseInputEvent;
|
|
50
47
|
}
|
|
@@ -1,16 +1,15 @@
|
|
|
1
1
|
import "../../ui/input.css";
|
|
2
2
|
import { EventHandler } from "../../interaction/eventhandler";
|
|
3
|
+
import { DataBinding } from "../../interaction/data-binding";
|
|
3
4
|
export class InputComponent {
|
|
4
5
|
get onChange() { return this.options.onChange; }
|
|
5
6
|
get onInput() { return this.options.onInput; }
|
|
6
7
|
constructor(options) {
|
|
7
8
|
var _a;
|
|
8
9
|
this.options = { type: "text", enabled: true, bindMode: "toModel", ...options };
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
this.modelValue = (_a = this.options.value) !== null && _a !== void 0 ? _a : "";
|
|
13
|
-
this.initialTextValue = this.modelValue;
|
|
10
|
+
this.binding = new DataBinding(options);
|
|
11
|
+
this.options.value = (_a = this.binding.initialValueOr(this.options.value)) !== null && _a !== void 0 ? _a : "";
|
|
12
|
+
this.initialTextValue = this.options.value;
|
|
14
13
|
this.options.onChange = EventHandler.Create(this.options.onChange);
|
|
15
14
|
this.options.onInput = EventHandler.Create(this.options.onInput);
|
|
16
15
|
if (this.options.type === "input") {
|
|
@@ -19,16 +18,12 @@ export class InputComponent {
|
|
|
19
18
|
}
|
|
20
19
|
render() {
|
|
21
20
|
var _a, _b, _c;
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
if (value !== this.
|
|
25
|
-
this.
|
|
26
|
-
this.modelValue = value;
|
|
27
|
-
if (this.currentDom && this.currentDom.value !== value) {
|
|
28
|
-
this.currentDom.value = value;
|
|
29
|
-
}
|
|
21
|
+
this.binding.sync(value => {
|
|
22
|
+
this.options.value = value !== null && value !== void 0 ? value : "";
|
|
23
|
+
if (this.currentDom && this.currentDom.value !== this.options.value) {
|
|
24
|
+
this.currentDom.value = this.options.value;
|
|
30
25
|
}
|
|
31
|
-
}
|
|
26
|
+
});
|
|
32
27
|
const textarea = this.options.type === "textarea";
|
|
33
28
|
return {
|
|
34
29
|
tag: textarea ? "textarea" : "input",
|
|
@@ -55,33 +50,20 @@ export class InputComponent {
|
|
|
55
50
|
if (this.currentDom && this.currentDom.value !== this.options.value) {
|
|
56
51
|
this.currentDom.value = this.options.value;
|
|
57
52
|
}
|
|
58
|
-
this.
|
|
53
|
+
this.binding.write(value);
|
|
59
54
|
}
|
|
60
55
|
focus() { var _a; (_a = this.currentDom) === null || _a === void 0 ? void 0 : _a.focus(); }
|
|
61
|
-
onInit(renderer) { this.renderer = renderer; }
|
|
56
|
+
onInit(renderer) { this.renderer = renderer; this.binding.initialize(); }
|
|
62
57
|
onCreate(node) { this.currentDom = node.dom; }
|
|
63
58
|
onUpdate(node) { this.currentDom = node.dom; }
|
|
64
59
|
onRemove() { this.currentDom = null; }
|
|
65
|
-
hasBinding() { return this.options.bindTo != null && this.options.property != null; }
|
|
66
|
-
readModel() {
|
|
67
|
-
var _a, _b;
|
|
68
|
-
const value = this.options.bindTo[this.options.property];
|
|
69
|
-
return ((_b = (((_a = this.options.converter) === null || _a === void 0 ? void 0 : _a.toUI) ? this.options.converter.toUI(value) : value)) !== null && _b !== void 0 ? _b : "");
|
|
70
|
-
}
|
|
71
|
-
writeModel(value) {
|
|
72
|
-
var _a;
|
|
73
|
-
if (this.hasBinding() && this.options.bindMode !== "fromModel") {
|
|
74
|
-
this.options.bindTo[this.options.property] = ((_a = this.options.converter) === null || _a === void 0 ? void 0 : _a.toData) ? this.options.converter.toData(value) : value;
|
|
75
|
-
this.modelValue = value;
|
|
76
|
-
}
|
|
77
|
-
}
|
|
78
60
|
raiseChangeEvent(event, node) {
|
|
79
61
|
if (!this.options.enabled) {
|
|
80
62
|
return false;
|
|
81
63
|
}
|
|
82
64
|
const value = node.dom.value;
|
|
83
65
|
this.options.value = value;
|
|
84
|
-
this.
|
|
66
|
+
this.binding.write(value);
|
|
85
67
|
this.onChange.notify(value);
|
|
86
68
|
}
|
|
87
69
|
raiseInputEvent(event, node) {
|
|
@@ -91,9 +73,9 @@ export class InputComponent {
|
|
|
91
73
|
}
|
|
92
74
|
const value = node.dom.value;
|
|
93
75
|
this.options.value = value;
|
|
94
|
-
const bindOnInput = (_a = this.options.bindOnInput) !== null && _a !== void 0 ? _a : (this.options.bindMode !== "
|
|
76
|
+
const bindOnInput = (_a = this.options.bindOnInput) !== null && _a !== void 0 ? _a : (this.options.bindMode !== "fromModel" && this.onInput.count() > 0);
|
|
95
77
|
if (bindOnInput) {
|
|
96
|
-
this.
|
|
78
|
+
this.binding.write(value);
|
|
97
79
|
}
|
|
98
80
|
this.onInput.notify(value);
|
|
99
81
|
return this.onInput.count() ? undefined : false;
|
|
@@ -20,7 +20,7 @@ export declare class NumberComponent<T = any> implements IJSLComponent {
|
|
|
20
20
|
private currentDom;
|
|
21
21
|
private id;
|
|
22
22
|
private options;
|
|
23
|
-
private
|
|
23
|
+
private binding;
|
|
24
24
|
private renderer;
|
|
25
25
|
constructor(options: INumberComponentOptions<T>);
|
|
26
26
|
get onChange(): EventHandler<number>;
|
|
@@ -34,7 +34,4 @@ export declare class NumberComponent<T = any> implements IJSLComponent {
|
|
|
34
34
|
onInit(renderer: JSLRender): void;
|
|
35
35
|
onCreate(node: IJSLVNode): void;
|
|
36
36
|
onRemove(): void;
|
|
37
|
-
private hasBinding;
|
|
38
|
-
private readModel;
|
|
39
|
-
private writeModel;
|
|
40
37
|
}
|