verstak 0.23.106 → 0.23.107

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.
@@ -1,53 +1,59 @@
1
- import { VBlock, LayoutKind, Align, GridCursor } from "../core/api";
1
+ import { VBlock, Layout, Align } from "../core/api";
2
2
  import { HtmlDriver } from "./HtmlDriver";
3
- export function Ribbon(body, base) {
4
- return VBlock.claim(VerstakTags.block, body, base);
3
+ export function VSection(builder, base) {
4
+ return VBlock.claim(Drivers.section, builder, base);
5
5
  }
6
- export function Table(body, base) {
7
- return VBlock.claim(VerstakTags.grid, body, base);
6
+ export function VTable(builder, base) {
7
+ return VBlock.claim(Drivers.table, builder, base);
8
8
  }
9
- export function line(body) {
10
- lineFeed();
11
- body();
9
+ export function row(builder, key) {
10
+ fromNewRow(key);
11
+ builder === null || builder === void 0 ? void 0 : builder();
12
12
  }
13
- export function lineFeed(noCoalescing, key) {
14
- return VBlock.claim(VerstakTags.line, { key });
13
+ export function fromNewRow(key) {
14
+ VBlock.claim(Drivers.row, { key });
15
15
  }
16
- export function Note(content, body) {
17
- return VBlock.claim(VerstakTags.text, body, {
16
+ export function VNote(content, builder) {
17
+ return VBlock.claim(Drivers.note, builder, {
18
18
  render(b) {
19
19
  b.native.innerText = content;
20
20
  }
21
21
  });
22
22
  }
23
- export function HtmlNote(content, body) {
24
- return VBlock.claim(VerstakTags.text, body, {
23
+ export function VHtmlNote(content, builder) {
24
+ return VBlock.claim(Drivers.note, builder, {
25
25
  render(b) {
26
26
  b.native.innerHTML = content;
27
27
  }
28
28
  });
29
29
  }
30
- export function Group(body, base) {
31
- return VBlock.claim(VerstakTags.group, body, base);
30
+ export function VGroup(builder, base) {
31
+ return VBlock.claim(Drivers.group, builder, base);
32
32
  }
33
- export class VerstakDriver extends HtmlDriver {
34
- applyCellRange(block, cellRange) {
33
+ export class VerstakHtmlDriver extends HtmlDriver {
34
+ applyChildrenLayout(block, value) {
35
+ const kind = Constants.layouts[value];
36
+ kind && block.native.setAttribute(Constants.attribute, kind);
37
+ VerstakDriversByLayout[value](block);
38
+ super.applyChildrenLayout(block, value);
39
+ }
40
+ applyCellRange(block, value) {
35
41
  const css = block.native.style;
36
- if (cellRange) {
37
- const x1 = cellRange.x1 || 1;
38
- const y1 = cellRange.y1 || 1;
39
- const x2 = cellRange.x2 || x1;
40
- const y2 = cellRange.y2 || y1;
42
+ if (value) {
43
+ const x1 = value.x1 || 1;
44
+ const y1 = value.y1 || 1;
45
+ const x2 = value.x2 || x1;
46
+ const y2 = value.y2 || y1;
41
47
  css.gridArea = `${y1} / ${x1} / span ${y2 - y1 + 1} / span ${x2 - x1 + 1}`;
42
48
  }
43
49
  else
44
50
  css.gridArea = "";
45
- super.applyCellRange(block, cellRange);
51
+ super.applyCellRange(block, value);
46
52
  }
47
- applyWidthGrowth(block, widthGrowth) {
53
+ applyWidthGrowth(block, value) {
48
54
  const css = block.native.style;
49
- if (widthGrowth > 0) {
50
- css.flexGrow = `${widthGrowth}`;
55
+ if (value > 0) {
56
+ css.flexGrow = `${value}`;
51
57
  css.flexBasis = "0";
52
58
  }
53
59
  else {
@@ -55,37 +61,37 @@ export class VerstakDriver extends HtmlDriver {
55
61
  css.flexBasis = "";
56
62
  }
57
63
  }
58
- applyMinWidth(block, minWidth) {
59
- block.native.style.minWidth = `${minWidth}`;
64
+ applyMinWidth(block, value) {
65
+ block.native.style.minWidth = `${value}`;
60
66
  }
61
- applyMaxWidth(block, maxWidth) {
62
- block.native.style.maxWidth = `${maxWidth}`;
67
+ applyMaxWidth(block, value) {
68
+ block.native.style.maxWidth = `${value}`;
63
69
  }
64
- applyHeightGrowth(block, heightGrowth) {
65
- if (block.driver.isLine) {
70
+ applyHeightGrowth(block, value) {
71
+ if (block.driver.isRow) {
66
72
  const css = block.native.style;
67
- if (heightGrowth > 0)
68
- css.flexGrow = `${heightGrowth}`;
73
+ if (value > 0)
74
+ css.flexGrow = `${value}`;
69
75
  else
70
76
  css.flexGrow = "";
71
77
  }
72
- else if (block.host.driver.isLine) {
73
- block.driver.applyFrameAlignment(block, Align.Stretch);
74
- block.host.driver.applyHeightGrowth(block.host, heightGrowth);
78
+ else if (block.host.driver.isRow) {
79
+ block.driver.applyBlockAlignment(block, Align.Stretch);
80
+ block.host.driver.applyHeightGrowth(block.host, value);
75
81
  }
76
82
  }
77
- applyMinHeight(block, minHeight) {
78
- block.native.style.minHeight = `${minHeight}`;
83
+ applyMinHeight(block, value) {
84
+ block.native.style.minHeight = `${value}`;
79
85
  }
80
- applyMaxHeight(block, maxHeight) {
81
- block.native.style.maxHeight = `${maxHeight}`;
86
+ applyMaxHeight(block, value) {
87
+ block.native.style.maxHeight = `${value}`;
82
88
  }
83
- applyContentAlignment(block, contentAlign) {
89
+ applyContentAlignment(block, value) {
84
90
  const css = block.native.style;
85
- if ((contentAlign & Align.Default) === 0) {
86
- const v = AlignToCss[(contentAlign >> 2) & 0b11];
87
- const h = AlignToCss[contentAlign & 0b11];
88
- const t = TextAlignCss[contentAlign & 0b11];
91
+ if ((value & Align.Default) === 0) {
92
+ const v = AlignToCss[(value >> 2) & 0b11];
93
+ const h = AlignToCss[value & 0b11];
94
+ const t = TextAlignCss[value & 0b11];
89
95
  css.justifyContent = v;
90
96
  css.alignItems = h;
91
97
  css.textAlign = t;
@@ -93,43 +99,62 @@ export class VerstakDriver extends HtmlDriver {
93
99
  else
94
100
  css.justifyContent = css.alignContent = css.textAlign = "";
95
101
  }
96
- applyFrameAlignment(block, frameAlign) {
102
+ applyBlockAlignment(block, value) {
97
103
  const css = block.native.style;
98
- if ((frameAlign & Align.Default) === 0) {
99
- const v = AlignToCss[(frameAlign >> 2) & 0b11];
100
- const h = AlignToCss[frameAlign & 0b11];
104
+ if ((value & Align.Default) === 0) {
105
+ const v = AlignToCss[(value >> 2) & 0b11];
106
+ const h = AlignToCss[value & 0b11];
101
107
  css.alignSelf = v;
102
108
  css.justifySelf = h;
103
109
  }
104
110
  else
105
111
  css.alignSelf = css.justifySelf = "";
106
112
  }
107
- applyContentWrapping(block, contentWrapping) {
108
- if (contentWrapping)
109
- block.native.setAttribute("wrapping", "true");
110
- else
111
- block.native.removeAttribute("wrapping");
113
+ applyContentWrapping(block, value) {
114
+ const css = block.native.style;
115
+ if (value) {
116
+ css.flexFlow = "wrap";
117
+ css.overflow = "";
118
+ css.textOverflow = "";
119
+ css.whiteSpace = "";
120
+ }
121
+ else {
122
+ css.flexFlow = "";
123
+ css.overflow = "hidden";
124
+ css.textOverflow = "ellipsis";
125
+ css.whiteSpace = "nowrap";
126
+ }
112
127
  }
113
- applyOverlayVisible(block, overlayVisible) {
128
+ applyOverlayVisible(block, value) {
114
129
  const e = block.native;
130
+ const css = e.style;
115
131
  const parent = HtmlDriver.findNearestParentHtmlBlock(block).native;
116
- if (overlayVisible === true) {
132
+ if (value === true) {
117
133
  const doc = document.body;
118
134
  const rect = parent.getBoundingClientRect();
119
- const h = doc.offsetWidth - rect.left > rect.right ? "rightward" : "leftward";
120
- const v = doc.clientHeight - rect.top > rect.bottom ? "downward" : "upward";
121
- e.setAttribute("overlay", `${h}-${v}`);
122
- parent.setAttribute("stacking", "true");
135
+ if (doc.offsetWidth - rect.left > rect.right)
136
+ css.left = "0", css.right = "";
137
+ else
138
+ css.left = "", css.right = "0";
139
+ if (doc.clientHeight - rect.top > rect.bottom)
140
+ css.top = "100%", css.bottom = "";
141
+ else
142
+ css.top = "", css.bottom = "100%";
143
+ css.display = "";
144
+ css.position = "absolute";
145
+ css.minWidth = "100%";
146
+ css.boxSizing = "border-box";
147
+ parent.style.position = "relative";
123
148
  }
124
149
  else {
125
- parent.removeAttribute("stacking");
126
- if (overlayVisible === false)
127
- e.setAttribute("overlay", "hidden");
150
+ parent.style.position = "";
151
+ if (value === false)
152
+ css.display = "none";
128
153
  else
129
- e.removeAttribute("overlay");
154
+ css.position = css.display = css.left = css.right = css.top = css.bottom = "";
130
155
  }
131
156
  }
132
- applyStyling(block, secondary, styleName, enabled) {
157
+ applyStyle(block, secondary, styleName, enabled) {
133
158
  const e = block.native;
134
159
  enabled !== null && enabled !== void 0 ? enabled : (enabled = true);
135
160
  if (secondary)
@@ -138,17 +163,63 @@ export class VerstakDriver extends HtmlDriver {
138
163
  e.className = enabled ? styleName : "";
139
164
  }
140
165
  render(block) {
141
- if (block.driver.layout < LayoutKind.Line)
142
- lineFeed();
166
+ if (block.childrenLayout < Layout.Row)
167
+ fromNewRow();
143
168
  return super.render(block);
144
169
  }
145
170
  }
146
- const VerstakTags = {
147
- block: new VerstakDriver("v-block", LayoutKind.Block),
148
- text: new VerstakDriver("v-text", LayoutKind.Text),
149
- grid: new VerstakDriver("v-grid", LayoutKind.Grid, () => new GridCursor()),
150
- line: new VerstakDriver("v-line", LayoutKind.Line),
151
- group: new VerstakDriver("v-group", LayoutKind.Fragment),
171
+ const Constants = {
172
+ block: "block",
173
+ row: "row",
174
+ layouts: ["section", "table", "", "group", "note"],
175
+ attribute: "kind",
176
+ };
177
+ const Drivers = {
178
+ section: new VerstakHtmlDriver(Constants.block, false, b => b.childrenLayout = Layout.Section),
179
+ table: new VerstakHtmlDriver(Constants.block, false, b => b.childrenLayout = Layout.Table),
180
+ row: new VerstakHtmlDriver(Constants.row, true, b => b.childrenLayout = Layout.Row),
181
+ group: new VerstakHtmlDriver(Constants.block, false, b => b.childrenLayout = Layout.Group),
182
+ note: new VerstakHtmlDriver(Constants.block, false, b => b.childrenLayout = Layout.Note),
152
183
  };
184
+ const VerstakDriversByLayout = [
185
+ b => {
186
+ const css = b.native.style;
187
+ css.alignSelf = "center";
188
+ css.display = "flex";
189
+ css.flexDirection = "column";
190
+ css.justifyContent = "center";
191
+ css.textAlign = "initial";
192
+ css.flexShrink = "1";
193
+ css.minWidth = "0";
194
+ },
195
+ b => {
196
+ const css = b.native.style;
197
+ css.alignSelf = "center";
198
+ css.display = "grid";
199
+ css.flexBasis = "0";
200
+ css.gridAutoRows = "minmax(min-content, 1fr)";
201
+ css.gridAutoColumns = "minmax(min-content, 1fr)";
202
+ css.textAlign = "initial";
203
+ },
204
+ b => {
205
+ const css = b.native.style;
206
+ css.display = "flex";
207
+ css.flexDirection = "row";
208
+ },
209
+ b => {
210
+ const css = b.native.style;
211
+ css.alignSelf = "center";
212
+ css.display = "contents";
213
+ },
214
+ b => {
215
+ const css = b.native.style;
216
+ css.alignSelf = "center";
217
+ css.display = "inline-block";
218
+ css.flexShrink = "1";
219
+ css.overflow = "";
220
+ css.textOverflow = "";
221
+ css.whiteSpace = "";
222
+ },
223
+ ];
153
224
  const AlignToCss = ["stretch", "start", "center", "end"];
154
225
  const TextAlignCss = ["justify", "left", "center", "right"];