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.
Files changed (43) hide show
  1. package/docs/DataBinding.md +19 -0
  2. package/docs/DateTimeComponent.md +1 -0
  3. package/docs/GridComponent.md +8 -5
  4. package/docs/InputComponent.md +1 -1
  5. package/docs/README.md +1 -0
  6. package/examples/showcase/checks-and-expanders.ts +2 -17
  7. package/examples/showcase/data-binding.ts +138 -0
  8. package/examples/showcase/dates.ts +6 -16
  9. package/examples/showcase/fields.ts +14 -26
  10. package/examples/showcase/generate-sources.cjs +104 -0
  11. package/examples/showcase/grids.ts +246 -17
  12. package/examples/showcase/index.html +12 -2
  13. package/examples/showcase/selects.ts +6 -8
  14. package/examples/showcase/showcase-sources.ts +95 -0
  15. package/examples/showcase/showcase.css +23 -2
  16. package/examples/showcase/showcase.ts +28 -5
  17. package/lib/components/auto-suggest/AutoSuggestComponent.d.ts +4 -4
  18. package/lib/components/auto-suggest/AutoSuggestComponent.js +1 -1
  19. package/lib/components/checkbox/CheckBoxComponent.d.ts +2 -3
  20. package/lib/components/checkbox/CheckBoxComponent.js +7 -20
  21. package/lib/components/date/DateComponent.d.ts +4 -4
  22. package/lib/components/date/DateComponent.js +11 -27
  23. package/lib/components/date-time/DateTimeComponent.d.ts +4 -4
  24. package/lib/components/date-time/DateTimeComponent.js +21 -32
  25. package/lib/components/input/InputComponent.d.ts +1 -4
  26. package/lib/components/input/InputComponent.js +14 -32
  27. package/lib/components/number/NumberComponent.d.ts +1 -4
  28. package/lib/components/number/NumberComponent.js +11 -29
  29. package/lib/components/select/SelectComponent.d.ts +1 -3
  30. package/lib/components/select/SelectComponent.js +8 -22
  31. package/lib/components/time/TimeComponent.d.ts +4 -3
  32. package/lib/components/time/TimeComponent.js +11 -24
  33. package/lib/grid/filterDialogs/excelFilter.js +12 -10
  34. package/lib/grid/plugins/slick.headermenu.css +98 -101
  35. package/lib/grid/slick-default-theme.css +10 -2
  36. package/lib/grid/slick.grid.css +112 -1
  37. package/lib/grid.css +852 -3392
  38. package/lib/index.css +260 -124
  39. package/lib/index.css.map +1 -1
  40. package/lib/index.js.map +1 -1
  41. package/lib/interaction/data-binding.d.ts +27 -0
  42. package/lib/interaction/data-binding.js +72 -0
  43. package/package.json +3 -1
@@ -0,0 +1,27 @@
1
+ import { IDataConverter } from "./dataconverter";
2
+ export type BindingMode = "toModel" | "fromModel" | "both";
3
+ export interface IDataBindingOptions<T, TValue> {
4
+ bindTo?: T;
5
+ property?: keyof T;
6
+ bindMode?: BindingMode;
7
+ converter?: IDataConverter<any, TValue>;
8
+ value?: TValue;
9
+ }
10
+ /** Shared model synchronization; controls remain responsible for their own UI values. */
11
+ export declare class DataBinding<T, TValue> {
12
+ private readonly options;
13
+ private readonly hasBinding;
14
+ private readonly mode;
15
+ private readonly hasInitialValue;
16
+ private readonly initialValue;
17
+ private observed;
18
+ private initialized;
19
+ private written;
20
+ constructor(options: IDataBindingOptions<T, TValue>);
21
+ initialValueOr(fallback: TValue): TValue;
22
+ initialize(): void;
23
+ sync(apply: (value: TValue) => void): void;
24
+ write(value: TValue): void;
25
+ private modelValue;
26
+ private toUI;
27
+ }
@@ -0,0 +1,72 @@
1
+ // Snapshot mutable values so in-place date and array changes are observable.
2
+ function snapshot(value) {
3
+ if (value instanceof Date) {
4
+ return new Date(value.getTime());
5
+ }
6
+ if (Array.isArray(value)) {
7
+ return value.map(snapshot);
8
+ }
9
+ return value;
10
+ }
11
+ function equal(a, b) {
12
+ if (a instanceof Date && b instanceof Date) {
13
+ return Object.is(a.getTime(), b.getTime());
14
+ }
15
+ if (Array.isArray(a) && Array.isArray(b)) {
16
+ return a.length === b.length && a.every((value, index) => equal(value, b[index]));
17
+ }
18
+ return Object.is(a, b);
19
+ }
20
+ /** Shared model synchronization; controls remain responsible for their own UI values. */
21
+ export class DataBinding {
22
+ constructor(options) {
23
+ var _a;
24
+ this.initialized = false;
25
+ this.written = false;
26
+ this.options = { ...options };
27
+ this.hasBinding = options.bindTo != null && options.property != null;
28
+ this.mode = (_a = options.bindMode) !== null && _a !== void 0 ? _a : "toModel";
29
+ this.hasInitialValue = Object.prototype.hasOwnProperty.call(options, "value") && options.value !== undefined;
30
+ this.initialValue = options.value;
31
+ }
32
+ initialValueOr(fallback) {
33
+ if (!this.hasBinding || this.mode === "toModel") {
34
+ return fallback;
35
+ }
36
+ const value = this.modelValue();
37
+ this.observed = snapshot(value);
38
+ return this.toUI(value);
39
+ }
40
+ initialize() {
41
+ if (this.initialized) {
42
+ return;
43
+ }
44
+ this.initialized = true;
45
+ if (this.mode === "toModel" && this.hasInitialValue && !this.written) {
46
+ this.write(this.initialValue);
47
+ }
48
+ }
49
+ sync(apply) {
50
+ if (!this.hasBinding || this.mode === "toModel") {
51
+ return;
52
+ }
53
+ const value = this.modelValue();
54
+ if (!equal(value, this.observed)) {
55
+ this.observed = snapshot(value);
56
+ apply(this.toUI(value));
57
+ }
58
+ }
59
+ write(value) {
60
+ var _a;
61
+ if (!this.hasBinding || this.mode === "fromModel") {
62
+ return;
63
+ }
64
+ this.options.bindTo[this.options.property] = ((_a = this.options.converter) === null || _a === void 0 ? void 0 : _a.toData) ? this.options.converter.toData(value) : value;
65
+ this.written = true;
66
+ if (this.mode === "both") {
67
+ this.observed = snapshot(this.modelValue());
68
+ }
69
+ }
70
+ modelValue() { return this.options.bindTo[this.options.property]; }
71
+ toUI(value) { var _a; return ((_a = this.options.converter) === null || _a === void 0 ? void 0 : _a.toUI) ? this.options.converter.toUI(value) : value; }
72
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "jsl-ui",
3
- "version": "10.1.0",
3
+ "version": "10.2.0",
4
4
  "main": "lib/index.js",
5
5
  "description": "javascript UI library",
6
6
  "files": [
@@ -14,7 +14,9 @@
14
14
  "buildcss": "parcel build .\\grid.ts --no-scope-hoist && powershell Move-Item -LiteralPath \"lib\\index.css\" -Destination \"lib\\grid.css\" -Force && parcel build .\\index.ts --no-scope-hoist",
15
15
  "build": "npm run buildcss && npm run copycss && npm run copyscss && tsc",
16
16
  "test": "parcel examples/components/jsl-render.html",
17
+ "preshowcase": "node examples/showcase/generate-sources.cjs",
17
18
  "showcase": "parcel examples/showcase --port 1235",
19
+ "prebuild:showcase": "node examples/showcase/generate-sources.cjs",
18
20
  "build:showcase": "parcel build examples/showcase --target showcase"
19
21
  },
20
22
  "author": "Philipp P.",