verstak 0.23.125 → 0.24.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,236 +1,58 @@
1
- import { Verstak, ElKind, Align, CursorCommandDriver, BaseDriver } from "../core/api.js";
1
+ import { RxTree } from "reactronic";
2
+ import { Constants, CursorCommandDriver, ElKind } from "./El.js";
2
3
  import { HtmlDriver } from "./HtmlDriver.js";
3
- export function Section(spec, base) {
4
- return Verstak.specify(Drivers.section, spec, base);
4
+ export function Section(declaration, preset) {
5
+ return RxTree.declare(Drivers.section, declaration, preset);
5
6
  }
6
- export function Table(spec, base) {
7
- return Verstak.specify(Drivers.table, spec, base);
7
+ export function Table(declaration, preset) {
8
+ return RxTree.declare(Drivers.table, declaration, preset);
8
9
  }
9
10
  export function row(builder, shiftCursorDown) {
10
11
  startNewRow(shiftCursorDown);
11
12
  builder === null || builder === void 0 ? void 0 : builder();
12
13
  }
13
14
  export function startNewRow(shiftCursorDown) {
14
- Verstak.specify(Drivers.row);
15
+ RxTree.declare(Drivers.partition);
15
16
  }
16
17
  export function cursor(areaParams) {
17
- Verstak.specify(Drivers.cursor, {
18
+ RxTree.declare(Drivers.cursor, {
18
19
  update(b) {
19
20
  b.area = areaParams;
20
21
  },
21
22
  });
22
23
  }
23
- export function Note(content, spec) {
24
- return Verstak.specify(Drivers.note, spec, {
24
+ export function Note(content, declaration) {
25
+ return RxTree.declare(Drivers.note, declaration, {
25
26
  update(b) {
26
27
  b.native.innerText = content;
27
28
  }
28
29
  });
29
30
  }
30
- export function HtmlNote(content, spec) {
31
- return Verstak.specify(Drivers.note, spec, {
31
+ export function HtmlNote(content, declaration) {
32
+ return RxTree.declare(Drivers.note, declaration, {
32
33
  update(b) {
33
34
  b.native.innerHTML = content;
34
35
  }
35
36
  });
36
37
  }
37
- export function Group(spec, base) {
38
- return Verstak.specify(Drivers.group, spec, base);
38
+ export function Group(declaration, preset) {
39
+ return RxTree.declare(Drivers.group, declaration, preset);
39
40
  }
40
- export function Fragment(spec, base) {
41
- return Verstak.specify(BaseDriver.fragment, spec, base);
41
+ export function Fragment(declaration, preset) {
42
+ return RxTree.declare(HtmlDriver.group, declaration, preset);
42
43
  }
43
44
  export class VerstakHtmlDriver extends HtmlDriver {
44
- applyKind(element, value) {
45
- const kind = Constants.layouts[value];
46
- kind && element.native.setAttribute(Constants.attribute, kind);
47
- VerstakDriversByLayout[value](element);
48
- super.applyKind(element, value);
49
- }
50
- applyCoords(element, value) {
51
- const s = element.native.style;
52
- if (value) {
53
- const x1 = value.x1 || 1;
54
- const y1 = value.y1 || 1;
55
- const x2 = value.x2 || x1;
56
- const y2 = value.y2 || y1;
57
- s.gridArea = `${y1} / ${x1} / span ${y2 - y1 + 1} / span ${x2 - x1 + 1}`;
58
- }
59
- else
60
- s.gridArea = "";
61
- super.applyCoords(element, value);
62
- }
63
- applyWidthGrowth(element, value) {
64
- const s = element.native.style;
65
- if (value > 0) {
66
- s.flexGrow = `${value}`;
67
- s.flexBasis = "0";
68
- }
69
- else {
70
- s.flexGrow = "";
71
- s.flexBasis = "";
72
- }
73
- }
74
- applyMinWidth(element, value) {
75
- element.native.style.minWidth = `${value}`;
76
- }
77
- applyMaxWidth(element, value) {
78
- element.native.style.maxWidth = `${value}`;
79
- }
80
- applyHeightGrowth(element, value) {
81
- const bNode = element.node;
82
- const driver = bNode.driver;
83
- if (driver.isSeparator) {
84
- const s = element.native.style;
85
- if (value > 0)
86
- s.flexGrow = `${value}`;
87
- else
88
- s.flexGrow = "";
89
- }
90
- else {
91
- const hostDriver = bNode.host.driver;
92
- if (hostDriver.isSeparator) {
93
- driver.applyElementAlignment(element, Align.ToBounds);
94
- hostDriver.applyHeightGrowth(bNode.host.slot.instance, value);
95
- }
96
- }
97
- }
98
- applyMinHeight(element, value) {
99
- element.native.style.minHeight = `${value}`;
100
- }
101
- applyMaxHeight(element, value) {
102
- element.native.style.maxHeight = `${value}`;
103
- }
104
- applyContentAlignment(element, value) {
105
- const s = element.native.style;
106
- if ((value & Align.Default) === 0) {
107
- const v = AlignToCss[(value >> 2) & 0b11];
108
- const h = AlignToCss[value & 0b11];
109
- const t = TextAlignCss[value & 0b11];
110
- s.justifyContent = v;
111
- s.alignItems = h;
112
- s.textAlign = t;
113
- }
114
- else
115
- s.justifyContent = s.alignContent = s.textAlign = "";
116
- }
117
- applyElementAlignment(element, value) {
118
- const s = element.native.style;
119
- if ((value & Align.Default) === 0) {
120
- const v = AlignToCss[(value >> 2) & 0b11];
121
- const h = AlignToCss[value & 0b11];
122
- s.alignSelf = v;
123
- s.justifySelf = h;
124
- }
125
- else
126
- s.alignSelf = s.justifySelf = "";
127
- }
128
- applyContentWrapping(element, value) {
129
- const s = element.native.style;
130
- if (value) {
131
- s.flexFlow = "wrap";
132
- s.overflow = "";
133
- s.textOverflow = "";
134
- s.whiteSpace = "";
135
- }
136
- else {
137
- s.flexFlow = "";
138
- s.overflow = "hidden";
139
- s.textOverflow = "ellipsis";
140
- s.whiteSpace = "nowrap";
141
- }
142
- }
143
- applyOverlayVisible(element, value) {
144
- const e = element.native;
145
- const s = e.style;
146
- const host = HtmlDriver.findEffectiveHtmlElementHost(element).native;
147
- if (value === true) {
148
- const doc = document.body;
149
- const rect = host.getBoundingClientRect();
150
- if (doc.offsetWidth - rect.left > rect.right)
151
- s.left = "0", s.right = "";
152
- else
153
- s.left = "", s.right = "0";
154
- if (doc.clientHeight - rect.top > rect.bottom)
155
- s.top = "100%", s.bottom = "";
156
- else
157
- s.top = "", s.bottom = "100%";
158
- s.display = "";
159
- s.position = "absolute";
160
- s.minWidth = "100%";
161
- s.boxSizing = "border-box";
162
- host.style.position = "relative";
163
- }
164
- else {
165
- host.style.position = "";
166
- if (value === false)
167
- s.display = "none";
168
- else
169
- s.position = s.display = s.left = s.right = s.top = s.bottom = "";
170
- }
171
- }
172
- applyStyle(element, secondary, styleName, enabled) {
173
- const native = element.native;
174
- enabled !== null && enabled !== void 0 ? enabled : (enabled = true);
175
- if (secondary)
176
- native.classList.toggle(styleName, enabled);
177
- else
178
- native.className = enabled ? styleName : "";
179
- }
180
45
  update(element) {
181
- if (element.kind <= ElKind.Table)
46
+ if (element.kind === ElKind.Section)
182
47
  startNewRow();
183
48
  return super.update(element);
184
49
  }
185
50
  }
186
- const Constants = {
187
- el: "el",
188
- row: "row",
189
- layouts: ["section", "table", "note", "group", "", ""],
190
- attribute: "kind",
191
- };
192
51
  const Drivers = {
193
- section: new VerstakHtmlDriver(Constants.el, false, el => el.kind = ElKind.Section),
194
- table: new VerstakHtmlDriver(Constants.el, false, el => el.kind = ElKind.Table),
195
- note: new VerstakHtmlDriver(Constants.el, false, el => el.kind = ElKind.Note),
196
- group: new VerstakHtmlDriver(Constants.el, false, el => el.kind = ElKind.Group),
197
- row: new VerstakHtmlDriver(Constants.row, true, el => el.kind = ElKind.Row),
52
+ section: new VerstakHtmlDriver(Constants.element, false, el => el.kind = ElKind.Section),
53
+ table: new VerstakHtmlDriver(Constants.element, false, el => el.kind = ElKind.Table),
54
+ note: new VerstakHtmlDriver(Constants.element, false, el => el.kind = ElKind.Note),
55
+ group: new VerstakHtmlDriver(Constants.element, false, el => el.kind = ElKind.Group),
56
+ partition: new VerstakHtmlDriver(Constants.partition, true, el => el.kind = ElKind.Part),
198
57
  cursor: new CursorCommandDriver(),
199
58
  };
200
- const VerstakDriversByLayout = [
201
- el => {
202
- const s = el.native.style;
203
- s.display = "flex";
204
- s.flexDirection = "column";
205
- s.alignSelf = el.node.owner.slot.instance.isTable ? "stretch" : "center";
206
- s.textAlign = "initial";
207
- s.flexShrink = "1";
208
- s.minWidth = "0";
209
- },
210
- el => {
211
- const s = el.native.style;
212
- s.alignSelf = el.node.owner.slot.instance.isTable ? "stretch" : "center";
213
- s.display = "grid";
214
- s.flexBasis = "0";
215
- s.gridAutoRows = "minmax(min-content, 1fr)";
216
- s.gridAutoColumns = "minmax(min-content, 1fr)";
217
- s.textAlign = "initial";
218
- },
219
- el => {
220
- const s = el.native.style;
221
- s.alignSelf = el.node.owner.slot.instance.isTable ? "stretch" : "center";
222
- s.display = "inline-grid";
223
- s.flexShrink = "1";
224
- },
225
- el => {
226
- const s = el.native.style;
227
- s.display = "contents";
228
- },
229
- el => {
230
- const s = el.native.style;
231
- s.display = el.node.owner.slot.instance.isTable ? "none" : "flex";
232
- s.flexDirection = "row";
233
- },
234
- ];
235
- const AlignToCss = ["stretch", "start", "center", "end"];
236
- const TextAlignCss = ["justify", "left", "center", "right"];
@@ -1,20 +1,23 @@
1
- import { MergedItem } from "reactronic";
2
- import { El, BaseDriver } from "../core/api.js";
3
- export declare abstract class BaseHtmlDriver<T extends Element, C = unknown> extends BaseDriver<T, C> {
4
- create(element: El<T, unknown, C, void>): void;
5
- initialize(element: El<T, unknown, C, void>): void;
6
- finalize(element: El<T, unknown, C>, isLeader: boolean): boolean;
7
- mount(element: El<T, unknown, C>): void;
8
- relocate(element: El<T, unknown, C>): void;
9
- update(element: El<T, unknown, C>): void | Promise<void>;
1
+ import { SimpleDelegate } from "reactronic";
2
+ import { El, ElDriver } from "./El.js";
3
+ export declare class VerstakDriver<T extends Element, M = unknown, C = unknown> extends ElDriver<T, M, C> {
4
+ initialize(element: El<T, M, C>): void;
5
+ finalize(element: El<T, M, C>, isLeader: boolean): boolean;
6
+ mount(element: El<T, M, C>): void;
7
+ relocate(element: El<T, M, C>): void;
8
+ update(element: El<T, M, C>): void | Promise<void>;
10
9
  static get blinkingEffectMarker(): string | undefined;
11
10
  static set blinkingEffectMarker(value: string | undefined);
12
- static findEffectiveHtmlElementHost(element: El<any>): El<HTMLElement | SVGElement>;
13
- static findPrevSiblingHtmlElement(ties: MergedItem<El<any>>): MergedItem<El<HTMLElement | SVGElement>> | undefined;
14
11
  }
15
- export declare class HtmlDriver<T extends HTMLElement, C = unknown> extends BaseHtmlDriver<T, C> {
16
- create(element: El<T, unknown, C, void>): void;
12
+ export declare class StaticDriver<T extends HTMLElement> extends VerstakDriver<T> {
13
+ readonly native: T;
14
+ constructor(native: T, name: string, isRow: boolean, predefine?: SimpleDelegate<El<T>>);
15
+ assign(element: El<T>): void;
17
16
  }
18
- export declare class SvgDriver<T extends SVGElement, C = unknown> extends BaseHtmlDriver<T, C> {
19
- create(element: El<T, unknown, C, void>): void;
17
+ export declare class HtmlDriver<T extends HTMLElement, M = any, C = any> extends VerstakDriver<T, M, C> {
18
+ static readonly group: HtmlDriver<any, any, any>;
19
+ assign(element: El<T, any, C, void>): void;
20
+ }
21
+ export declare class SvgDriver<T extends SVGElement, M = any, C = any> extends VerstakDriver<T, M, C> {
22
+ assign(element: El<T, any, C, void>): void;
20
23
  }
@@ -1,12 +1,9 @@
1
- import { Rx } from "reactronic";
2
- import { Verstak, BaseDriver } from "../core/api.js";
3
- export class BaseHtmlDriver extends BaseDriver {
4
- create(element) {
5
- super.create(element);
6
- }
1
+ import { RxSystem, RxTree } from "reactronic";
2
+ import { Constants, ElDriver, ElImpl, ElKind } from "./El.js";
3
+ export class VerstakDriver extends ElDriver {
7
4
  initialize(element) {
8
- if (Rx.isLogging && !element.node.driver.isSeparator)
9
- element.native.setAttribute("key", element.node.key);
5
+ if (RxSystem.isLogging && !element.node.driver.isPartitionSeparator)
6
+ element.native.setAttribute(Constants.keyAttrName, element.node.key);
10
7
  super.initialize(element);
11
8
  }
12
9
  finalize(element, isLeader) {
@@ -25,16 +22,17 @@ export class BaseHtmlDriver extends BaseDriver {
25
22
  if (native) {
26
23
  const node = element.node;
27
24
  const sequential = node.owner.children.isStrict;
28
- const automaticNativeHost = BaseHtmlDriver.findEffectiveHtmlElementHost(element).native;
25
+ const automaticHost = RxTree.findMatchingHost(node, n => n.element.native instanceof HTMLElement || n.element.native instanceof SVGElement);
26
+ const automaticNativeHost = automaticHost === null || automaticHost === void 0 ? void 0 : automaticHost.element.native;
29
27
  if (automaticNativeHost) {
30
- if (sequential && !node.driver.isSeparator) {
31
- const after = BaseHtmlDriver.findPrevSiblingHtmlElement(element.node.slot);
32
- if (after === undefined || after.instance.node.driver.isSeparator) {
28
+ if (sequential && !node.driver.isPartitionSeparator) {
29
+ const after = RxTree.findMatchingPrevSibling(element.node, n => n.element.native instanceof HTMLElement || n.element.native instanceof SVGElement);
30
+ if (after === undefined || after.driver.isPartitionSeparator) {
33
31
  if (automaticNativeHost !== native.parentNode || !native.previousSibling)
34
32
  automaticNativeHost.prepend(native);
35
33
  }
36
34
  else {
37
- const nativeAfter = after.instance.native;
35
+ const nativeAfter = after.element.native;
38
36
  if (nativeAfter instanceof Element) {
39
37
  if (nativeAfter.nextSibling !== native)
40
38
  automaticNativeHost.insertBefore(native, nativeAfter.nextSibling);
@@ -50,8 +48,13 @@ export class BaseHtmlDriver extends BaseDriver {
50
48
  }
51
49
  update(element) {
52
50
  const result = super.update(element);
51
+ if (element.area === undefined) {
52
+ const oel = element.node.owner.element;
53
+ if (oel instanceof ElImpl && oel.isTable)
54
+ element.area = undefined;
55
+ }
53
56
  if (gBlinkingEffectMarker)
54
- blink(element.native, Verstak.currentUpdatePriority, element.node.stamp);
57
+ blink(element.native, RxTree.currentUpdatePriority, element.node.stamp);
55
58
  return result;
56
59
  }
57
60
  static get blinkingEffectMarker() {
@@ -60,30 +63,27 @@ export class BaseHtmlDriver extends BaseDriver {
60
63
  static set blinkingEffectMarker(value) {
61
64
  gBlinkingEffectMarker = value;
62
65
  }
63
- static findEffectiveHtmlElementHost(element) {
64
- let p = element.node.host;
65
- while (p.slot.instance.native instanceof HTMLElement === false &&
66
- p.slot.instance.native instanceof SVGElement === false && p !== element.node)
67
- p = p.host;
68
- return p.slot.instance;
66
+ }
67
+ export class StaticDriver extends VerstakDriver {
68
+ constructor(native, name, isRow, predefine) {
69
+ super(name, isRow, predefine);
70
+ this.native = native;
69
71
  }
70
- static findPrevSiblingHtmlElement(ties) {
71
- let p = ties.prev;
72
- while (p && !(p.instance.native instanceof HTMLElement) && !(p.instance.native instanceof SVGElement))
73
- p = p.prev;
74
- return p;
72
+ assign(element) {
73
+ element.native = this.native;
75
74
  }
76
75
  }
77
- export class HtmlDriver extends BaseHtmlDriver {
78
- create(element) {
76
+ export class HtmlDriver extends VerstakDriver {
77
+ assign(element) {
79
78
  element.native = document.createElement(element.node.driver.name);
80
- super.create(element);
79
+ super.assign(element);
81
80
  }
82
81
  }
83
- export class SvgDriver extends BaseHtmlDriver {
84
- create(element) {
82
+ HtmlDriver.group = new HtmlDriver("group", false, el => el.kind = ElKind.Group);
83
+ export class SvgDriver extends VerstakDriver {
84
+ assign(element) {
85
85
  element.native = document.createElementNS("http://www.w3.org/2000/svg", element.node.driver.name);
86
- super.create(element);
86
+ super.assign(element);
87
87
  }
88
88
  }
89
89
  function blink(element, priority, revision) {