@web-atoms/web-controls 2.1.97 → 2.1.101

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 (33) hide show
  1. package/dist/auto-complete/AutoCompleteBox.d.ts.map +1 -1
  2. package/dist/auto-complete/AutoCompleteBox.js +0 -1
  3. package/dist/auto-complete/AutoCompleteBox.js.map +1 -1
  4. package/dist/basic/AtomRepeater.d.ts.map +1 -1
  5. package/dist/basic/AtomRepeater.js +9 -2
  6. package/dist/basic/AtomRepeater.js.map +1 -1
  7. package/dist/basic/Calendar.d.ts +29 -0
  8. package/dist/basic/Calendar.d.ts.map +1 -0
  9. package/dist/basic/Calendar.js +160 -0
  10. package/dist/basic/Calendar.js.map +1 -0
  11. package/dist/basic/ComboBox.d.ts +1 -0
  12. package/dist/basic/ComboBox.d.ts.map +1 -1
  13. package/dist/basic/ComboBox.js +9 -1
  14. package/dist/basic/ComboBox.js.map +1 -1
  15. package/dist/basic/Form.d.ts.map +1 -1
  16. package/dist/basic/Form.js +4 -2
  17. package/dist/basic/Form.js.map +1 -1
  18. package/dist/html-editor/commands/AddImage.js +1 -1
  19. package/dist/html-editor/commands/AddImage.js.map +1 -1
  20. package/dist/html-editor/commands/AddLink.js +1 -1
  21. package/dist/html-editor/commands/AddLink.js.map +1 -1
  22. package/dist/html-editor/commands/Source.js +1 -1
  23. package/dist/html-editor/commands/Source.js.map +1 -1
  24. package/dist/tsconfig.tsbuildinfo +1 -1
  25. package/package.json +2 -2
  26. package/src/auto-complete/AutoCompleteBox.tsx +363 -364
  27. package/src/basic/AtomRepeater.tsx +9 -2
  28. package/src/basic/Calendar.tsx +162 -0
  29. package/src/basic/ComboBox.tsx +10 -1
  30. package/src/basic/Form.tsx +4 -1
  31. package/src/html-editor/commands/AddImage.tsx +1 -1
  32. package/src/html-editor/commands/AddLink.tsx +1 -1
  33. package/src/html-editor/commands/Source.tsx +1 -1
@@ -71,7 +71,7 @@ export function askSuggestion<T>(
71
71
  itemRenderer={itemRenderer}
72
72
  visibilityFilter={Bind.oneWay(() => match(this.search))}
73
73
  eventItemClick={(e) => {
74
- this.viewModel.close(e.detail);
74
+ this.close(e.detail);
75
75
  }}
76
76
  items={items}/>
77
77
  </div>
@@ -267,8 +267,12 @@ export default class AtomRepeater extends AtomControl {
267
267
  if (this.initialValue !== undefined) {
268
268
  return this.initialValue;
269
269
  }
270
+ const sp = this.selectedItem;
271
+ if (sp === undefined) {
272
+ return sp;
273
+ }
270
274
  const vp = this.valuePath ?? SameObjectValue;
271
- return vp(this.selectedItem);
275
+ return vp(sp);
272
276
  }
273
277
 
274
278
  public set value(v) {
@@ -587,6 +591,9 @@ function onElementClick(e: Event) {
587
591
  if (si) {
588
592
  index = si.indexOf(item);
589
593
  if (index === -1) {
594
+ if (!this.allowMultipleSelection) {
595
+ si.clear();
596
+ }
590
597
  si.add(item);
591
598
  } else {
592
599
  si.removeAt(index);
@@ -0,0 +1,162 @@
1
+ import Bind from "@web-atoms/core/dist/core/Bind";
2
+ import { BindableProperty } from "@web-atoms/core/dist/core/BindableProperty";
3
+ import Colors from "@web-atoms/core/dist/core/Colors";
4
+ import WatchProperty from "@web-atoms/core/dist/core/WatchProperty";
5
+ import XNode from "@web-atoms/core/dist/core/XNode";
6
+ import StyleRule from "@web-atoms/core/dist/style/StyleRule";
7
+ import CSS from "@web-atoms/core/dist/web/styles/CSS";
8
+ import DateTime from "@web-atoms/date-time/dist/DateTime";
9
+ import AtomRepeater from "./AtomRepeater";
10
+ import ComboBox from "./ComboBox";
11
+
12
+ const getWeekDays = (locale, type: "short" | "long") => {
13
+ const baseDate = new Date(Date.UTC(2017, 0, 2)); // just a Monday
14
+ const weekDays = [];
15
+ for (let i = 0; i < 7; i++) {
16
+ weekDays.push(baseDate.toLocaleDateString(locale, { weekday: type }));
17
+ baseDate.setDate(baseDate.getDate() + 1);
18
+ }
19
+ return weekDays;
20
+ };
21
+
22
+ const getMonths = (locale, type: "short" | "long") => {
23
+ const baseDate = new Date(Date.UTC(2017, 0, 2)); // just a Monday
24
+ const weekDays = [];
25
+ for (let i = 0; i < 12; i++) {
26
+ weekDays.push(baseDate.toLocaleDateString(locale, { month: type }));
27
+ baseDate.setMonth(i + 1);
28
+ }
29
+ return weekDays;
30
+ };
31
+
32
+ export const weekdays = {
33
+
34
+ short: getWeekDays(navigator.language, "short"),
35
+ long: getWeekDays(navigator.language, "long"),
36
+ };
37
+
38
+ export const months = {
39
+ short: getMonths(navigator.language, "short"),
40
+ long: getMonths(navigator.language, "long")
41
+ };
42
+
43
+ const monthItems = months.long.map((x, i) => ({
44
+ label: x,
45
+ value: i
46
+ }));
47
+
48
+ const css = CSS(StyleRule()
49
+ .display("inline-grid")
50
+ .gridTemplateRows("auto auto 1fr")
51
+ .gridTemplateColumns("auto 1fr 1fr auto")
52
+ .child(StyleRule(".dates")
53
+ .gridColumnStart("1")
54
+ .gridColumnEnd("span 4")
55
+ .gridRowStart("3")
56
+ .display("inline-grid")
57
+ .gap(0)
58
+ .child(StyleRule("[data-item-index]")
59
+ .alignSelf("stretch")
60
+ .justifySelf("stretch")
61
+ .padding(7)
62
+ .cursor("pointer")
63
+ .textAlign("center")
64
+ .hoverBackgroundColor(Colors.lightGray.withAlphaPercent(0.5))
65
+ .and(StyleRule("[data-selected-item=true]")
66
+ .backgroundColor(Colors.blueViolet)
67
+ .color(Colors.white)
68
+ )
69
+ .and(StyleRule("[data-is-today=true]")
70
+ .backgroundColor(Colors.lightGreen)
71
+ )
72
+ .and(StyleRule("[data-is-weekend=true]")
73
+ .backgroundColor(Colors.lightGray.withAlphaPercent(0.3))
74
+ )
75
+ .and(StyleRule("[data-is-other-month=true]")
76
+ .opacity("0.5")
77
+ )
78
+ )
79
+ )
80
+ );
81
+
82
+ export interface ICalendarDate {
83
+ label: string;
84
+ type: string;
85
+ value: DateTime;
86
+ isToday: boolean;
87
+ isOtherMonth: boolean;
88
+ isWeekend: boolean;
89
+ row: number;
90
+ column: number;
91
+ }
92
+
93
+ export default class Calendar extends AtomRepeater {
94
+
95
+ @BindableProperty
96
+ public year: number;
97
+
98
+ @BindableProperty
99
+ public month: number;
100
+
101
+ public dateRenderer: (item: ICalendarDate) => XNode;
102
+
103
+ @WatchProperty
104
+ public get dates() {
105
+ const year = this.year;
106
+ const month = this.month ?? 0;
107
+ const today = DateTime.today;
108
+ let startDate = new DateTime(year, month, 1);
109
+ while (startDate.dayOfWeek !== 1) {
110
+ startDate = startDate.add(-1);
111
+ }
112
+ const a = [];
113
+ const y = startDate.year;
114
+ const m = startDate.month;
115
+ for (let index = 0; index < 42; index++) {
116
+ const cd = startDate.add(index);
117
+ a.push({
118
+ label: cd.day + "",
119
+ row: Math.floor(index / 7),
120
+ column: index % 7,
121
+ type: null,
122
+ value: cd,
123
+ isToday: cd.equals(today),
124
+ isOtherMonth: month !== cd.month,
125
+ isWeekend: (cd.dayOfWeek === 0 || cd.dayOfWeek === 6)
126
+ });
127
+ }
128
+ return a;
129
+ }
130
+
131
+ protected preCreate(): void {
132
+ const now = new Date();
133
+ this.selectedItems = [];
134
+ this.year = now.getFullYear();
135
+ this.month = now.getMonth();
136
+ this.render(<div
137
+ class={css}
138
+ items={Bind.oneWay(() => this.dates)}>
139
+ <i class="fa-solid fa-angle-left"/>
140
+ <ComboBox items={monthItems} value={Bind.twoWays(() => this.month)} />
141
+ <ComboBox/>
142
+ <i class="fa-solid fa-angle-right"/>
143
+ <div class="dates"/>
144
+ </div>);
145
+ this.itemsPresenter = this.element.lastElementChild;
146
+ this.dateRenderer = (item) => <div text={item.label}/>;
147
+ this.itemRenderer = (item: ICalendarDate) => {
148
+ const d = this.dateRenderer(item);
149
+ const a = d.attributes ??= {};
150
+ if (!a["data-click-event"]) {
151
+ a["data-click-event"] = "itemSelect";
152
+ }
153
+ a["data-is-today"] = item.isToday;
154
+ a["data-is-other-month"] = item.isOtherMonth;
155
+ a["data-is-weekend"] = item.isWeekend;
156
+ a.styleGridColumnStart = (item.column + 1);
157
+ a.styleGridRowStart = (item.row + 1);
158
+ return d;
159
+ };
160
+ }
161
+
162
+ }
@@ -11,13 +11,14 @@ export default class ComboBox extends AtomRepeater {
11
11
 
12
12
  constructor(app, e) {
13
13
  super(app, e ?? document.createElement("select"));
14
+ this.selectedItems = [];
14
15
  }
15
16
 
16
17
  public updateItems(container?: HTMLElement): void {
17
- super.updateItems(container);
18
18
  if (this.isChanging) {
19
19
  return;
20
20
  }
21
+ super.updateItems(container);
21
22
  const selectedItems = this.selectedItems;
22
23
  if (!selectedItems) {
23
24
  return;
@@ -31,6 +32,14 @@ export default class ComboBox extends AtomRepeater {
31
32
  this.isChanging = false;
32
33
  }
33
34
 
35
+ protected updateClasses(): void {
36
+ if (this.isChanging) {
37
+ return;
38
+ }
39
+ super.updateClasses();
40
+ this.updateItems();
41
+ }
42
+
34
43
  protected preCreate(): void {
35
44
  super.preCreate();
36
45
  this.labelPath = (item) => item?.label ?? item.toString();
@@ -6,9 +6,12 @@ import FormField from "./FormField";
6
6
  import IElement from "./IElement";
7
7
 
8
8
  const css = CSS(StyleRule()
9
- .verticalFlexLayout({})
9
+ .verticalFlexLayout({ alignItems: "stretch" })
10
10
  .displayNone(" .field-error:empty")
11
11
  .displayNone(":not([data-wa-show-errors=yes]) .field-error:not(:empty)")
12
+ .child(StyleRule("button")
13
+ .alignSelf("flex-start")
14
+ )
12
15
  , "*[data-wa-form=wa-form]");
13
16
 
14
17
  export interface ISubmitButton {
@@ -27,7 +27,7 @@ class ImageDialog extends PopupWindow {
27
27
  </FormField>
28
28
  <div class="command-bar">
29
29
  <button
30
- eventClick={() => this.viewModel.close(this.createImage())}
30
+ eventClick={() => this.close(this.createImage())}
31
31
  text="Add"/>
32
32
  </div>
33
33
  </div>);
@@ -61,7 +61,7 @@ class LinkDialog extends PopupWindow {
61
61
  <div class="command-bar">
62
62
  <button
63
63
  text="Add"
64
- eventClick={Bind.event(() => this.viewModel.close(this.toLink(this.link)))} />
64
+ eventClick={Bind.event(() => this.close(this.toLink(this.link)))} />
65
65
  </div>
66
66
  </div>);
67
67
  }
@@ -28,7 +28,7 @@ async function showDialog(s: AtomHtmlEditor, e: Event): Promise<string> {
28
28
  <textarea value={Bind.twoWaysImmediate(() => this.source)}/>
29
29
  <div class="command-bar">
30
30
  <button
31
- eventClick={Bind.event(() => this.viewModel.close(this.source))}
31
+ eventClick={Bind.event(() => this.close(this.source))}
32
32
  text="Save"/>
33
33
  </div>
34
34
  </div>);