verstak 0.22.511 → 0.22.512

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,29 +1,25 @@
1
- import { Monitor, LoggingOptions, Item, CollectionReader } from "reactronic";
1
+ import { LoggingOptions, Item, CollectionReader, MemberOptions } from "reactronic";
2
2
  import { CellRange } from "./CellRange";
3
3
  import { Cursor, Align, Cells } from "./Cursor";
4
4
  export declare type Callback<T = unknown> = (native: T) => void;
5
- export declare type Render<T = unknown, M = unknown, R = void> = (native: T, block: VBlock<T, M, R>, base: () => R) => R;
6
- export declare type AsyncRender<T = unknown, M = unknown> = (native: T, block: VBlock<T, M, Promise<void>>) => Promise<void>;
5
+ export declare type Render<T = unknown, M = unknown, R = void> = (block: VBlock<T, M, R>, base: () => R) => R;
6
+ export declare type AsyncRender<T = unknown, M = unknown> = (block: VBlock<T, M, Promise<void>>) => Promise<void>;
7
7
  export declare const enum Priority {
8
8
  SyncP0 = 0,
9
9
  AsyncP1 = 1,
10
10
  AsyncP2 = 2
11
11
  }
12
12
  export declare type Type<T> = new (...args: any[]) => T;
13
- export interface BlockArgs<T = unknown, M = unknown, R = void> {
13
+ export declare type BlockBody<T = unknown, M = unknown, R = void> = Render<T, M, R> | BlockVmt<T, M, R>;
14
+ export interface BlockVmt<T = unknown, M = unknown, R = void> {
14
15
  reacting?: boolean;
15
16
  triggers?: unknown;
16
- priority?: Priority;
17
- monitor?: Monitor;
18
- throttling?: number;
19
- logging?: Partial<LoggingOptions>;
20
- shuffle?: boolean;
21
17
  initialize?: Render<T, M, R>;
22
18
  override?: Render<T, M, R>;
23
19
  render?: Render<T, M, R>;
24
20
  finalize?: Render<T, M, R>;
25
21
  }
26
- export declare function asComponent<T, M, R>(outer: BlockArgs<T, M, R> | undefined, base: BlockArgs<T, M, R>): BlockArgs<T, M, R>;
22
+ export declare function asComponent<T, M, R>(outer: BlockBody<T, M, R> | undefined, base: BlockBody<T, M, R>): BlockVmt<T, M, R>;
27
23
  export declare function setContext<T extends Object>(type: Type<T>, context: T): void;
28
24
  export declare function use<T extends Object>(type: Type<T>): T;
29
25
  export declare abstract class VBlock<T = unknown, M = unknown, R = void> {
@@ -33,7 +29,7 @@ export declare abstract class VBlock<T = unknown, M = unknown, R = void> {
33
29
  static frameDuration: number;
34
30
  abstract readonly name: string;
35
31
  abstract readonly driver: AbstractDriver<T>;
36
- abstract readonly args: Readonly<BlockArgs<T, M, R>>;
32
+ abstract readonly body: Readonly<BlockVmt<T, M, R>>;
37
33
  abstract model: M;
38
34
  abstract cells: Cells;
39
35
  abstract widthGrowth: number;
@@ -46,18 +42,21 @@ export declare abstract class VBlock<T = unknown, M = unknown, R = void> {
46
42
  abstract alignFrame: Align;
47
43
  abstract wrapContent: boolean;
48
44
  abstract dangling: boolean;
45
+ abstract shuffleChildren: boolean;
46
+ abstract renderingPriority?: Priority;
49
47
  abstract readonly level: number;
50
48
  abstract readonly host: VBlock;
51
49
  abstract readonly children: CollectionReader<VBlock>;
52
50
  abstract readonly item: Item<VBlock> | undefined;
53
51
  abstract readonly stamp: number;
54
- abstract readonly native: T | undefined;
52
+ abstract readonly native: T;
55
53
  get isInitialRendering(): boolean;
54
+ abstract configureReactronic(options: Partial<MemberOptions>): MemberOptions;
56
55
  static root(render: () => void): void;
57
56
  static get current(): VBlock;
58
57
  static renderNestedTreesThenDo(action: (error: unknown) => void): void;
59
58
  static runForAllBlocks<T>(action: (e: T) => void): void;
60
- static claim<T = undefined, M = unknown, R = void>(name: string, driver: AbstractDriver<T> | undefined, args: BlockArgs<T, M, R>): VBlock<T, M, R>;
59
+ static claim<T = undefined, M = unknown, R = void>(name: string, driver: AbstractDriver<T> | undefined, body: BlockBody<T, M, R>): VBlock<T, M, R>;
61
60
  static getDefaultLoggingOptions(): LoggingOptions | undefined;
62
61
  static setDefaultLoggingOptions(logging?: LoggingOptions): void;
63
62
  }
@@ -79,7 +78,7 @@ export declare class AbstractDriver<T> {
79
78
  get isGrid(): boolean;
80
79
  get isRow(): boolean;
81
80
  constructor(name: string, layout: LayoutKind, createCursor?: () => Cursor);
82
- initialize(block: VBlock<T>, native: T | undefined): void;
81
+ initialize(block: VBlock<T>, native: T): void;
83
82
  finalize(block: VBlock<T>, isLeader: boolean): boolean;
84
83
  deploy(block: VBlock<T>, sequential: boolean): void;
85
84
  applyCellRange(block: VBlock<T, any, any>, cellRange: CellRange | undefined): void;
@@ -98,5 +97,5 @@ export declare class AbstractDriver<T> {
98
97
  export declare class StaticDriver<T> extends AbstractDriver<T> {
99
98
  readonly element: T;
100
99
  constructor(element: T, name: string, layout: LayoutKind, createCursor?: () => Cursor);
101
- initialize(block: VBlock<T>, element: T | undefined): void;
100
+ initialize(block: VBlock<T>, element: T): void;
102
101
  }
@@ -26,12 +26,16 @@ export var Priority;
26
26
  Priority[Priority["AsyncP2"] = 2] = "AsyncP2";
27
27
  })(Priority || (Priority = {}));
28
28
  export function asComponent(outer, base) {
29
+ if (outer instanceof Function)
30
+ outer = { render: outer };
31
+ if (base instanceof Function)
32
+ base = { render: base };
29
33
  const result = Object.assign(Object.assign(Object.assign({}, base), outer), { initialize: via(outer === null || outer === void 0 ? void 0 : outer.initialize, base.initialize), render: via(outer === null || outer === void 0 ? void 0 : outer.render, base.render), finalize: via(outer === null || outer === void 0 ? void 0 : outer.finalize, base.finalize) });
30
34
  return result;
31
35
  }
32
36
  function via(outer, base) {
33
37
  const inherited = base !== null && base !== void 0 ? base : NOP;
34
- return outer ? (e, b) => outer(e, b, () => inherited(e, b)) : inherited;
38
+ return outer ? b => outer(b, () => inherited(b)) : inherited;
35
39
  }
36
40
  export function setContext(type, context) {
37
41
  return VBlockImpl.setContext(type, context);
@@ -44,7 +48,7 @@ export class VBlock {
44
48
  return this.stamp === 2;
45
49
  }
46
50
  static root(render) {
47
- gSysRoot.instance.args.render = render;
51
+ gSysRoot.instance.body.render = render;
48
52
  prepareAndRunRender(gSysRoot, false, false);
49
53
  }
50
54
  static get current() {
@@ -56,8 +60,10 @@ export class VBlock {
56
60
  static runForAllBlocks(action) {
57
61
  forEachChildRecursively(gSysRoot, action);
58
62
  }
59
- static claim(name, driver, args) {
63
+ static claim(name, driver, body) {
60
64
  var _a, _b;
65
+ if (body instanceof Function)
66
+ body = { render: body };
61
67
  let result;
62
68
  const owner = gCurrent.instance;
63
69
  const children = owner.children;
@@ -74,16 +80,16 @@ export class VBlock {
74
80
  result = ex.instance;
75
81
  if (result.driver !== driver && driver !== undefined)
76
82
  throw new Error(`changing block driver is not yet supported: "${result.driver.name}" -> "${driver === null || driver === void 0 ? void 0 : driver.name}"`);
77
- const exTriggers = (_b = result.args) === null || _b === void 0 ? void 0 : _b.triggers;
78
- if (triggersAreEqual(args.triggers, exTriggers))
79
- args.triggers = exTriggers;
80
- result.args = args;
83
+ const exTriggers = (_b = result.body) === null || _b === void 0 ? void 0 : _b.triggers;
84
+ if (triggersAreEqual(body.triggers, exTriggers))
85
+ body.triggers = exTriggers;
86
+ result.body = body;
81
87
  }
82
88
  else {
83
- result = new VBlockImpl(name, driver, owner, args);
89
+ result = new VBlockImpl(name, driver, owner, body);
84
90
  result.item = children.add(result);
85
91
  VBlockImpl.grandCount++;
86
- if (args.reacting)
92
+ if (body.reacting)
87
93
  VBlockImpl.disposableCount++;
88
94
  }
89
95
  return result;
@@ -123,14 +129,13 @@ export class AbstractDriver {
123
129
  var _a, _b;
124
130
  const b = block;
125
131
  b.native = native;
126
- (_b = (_a = block.args).initialize) === null || _b === void 0 ? void 0 : _b.call(_a, native, block, NOP);
132
+ (_b = (_a = block.body).initialize) === null || _b === void 0 ? void 0 : _b.call(_a, block, NOP);
127
133
  }
128
134
  finalize(block, isLeader) {
129
135
  var _a, _b;
130
136
  const b = block;
131
- const native = block.native;
132
- (_b = (_a = block.args).finalize) === null || _b === void 0 ? void 0 : _b.call(_a, native, block, NOP);
133
- b.native = undefined;
137
+ (_b = (_a = block.body).finalize) === null || _b === void 0 ? void 0 : _b.call(_a, block, NOP);
138
+ b.native = null;
134
139
  return isLeader;
135
140
  }
136
141
  deploy(block, sequential) {
@@ -160,9 +165,9 @@ export class AbstractDriver {
160
165
  render(block) {
161
166
  var _a;
162
167
  let result;
163
- const override = (_a = block.args) === null || _a === void 0 ? void 0 : _a.override;
168
+ const override = (_a = block.body) === null || _a === void 0 ? void 0 : _a.override;
164
169
  if (override)
165
- result = override(block.native, block, NOP);
170
+ result = override(block, NOP);
166
171
  else
167
172
  result = invokeRenderFunction(block);
168
173
  return result;
@@ -171,8 +176,8 @@ export class AbstractDriver {
171
176
  AbstractDriver.group = new AbstractDriver("group", LayoutKind.Group);
172
177
  function invokeRenderFunction(block) {
173
178
  var _a;
174
- const r = (_a = block.args.render) !== null && _a !== void 0 ? _a : NOP;
175
- return r(block.native, block, NOP);
179
+ const r = (_a = block.body.render) !== null && _a !== void 0 ? _a : NOP;
180
+ return r(block, NOP);
176
181
  }
177
182
  export class StaticDriver extends AbstractDriver {
178
183
  constructor(element, name, layout, createCursor) {
@@ -198,11 +203,11 @@ __decorate([
198
203
  __metadata("design:type", Object)
199
204
  ], VBlockContext.prototype, "type", void 0);
200
205
  class VBlockImpl extends VBlock {
201
- constructor(name, driver, owner, args) {
206
+ constructor(name, driver, owner, body) {
202
207
  super();
203
208
  this.name = name;
204
209
  this.driver = driver;
205
- this.args = args;
210
+ this.body = body;
206
211
  this.model = undefined;
207
212
  this.assignedCells = undefined;
208
213
  this.appliedCellRange = Cursor.UndefinedCellRange;
@@ -216,6 +221,8 @@ class VBlockImpl extends VBlock {
216
221
  this.appliedAlignFrame = Align.Default;
217
222
  this.appliedWrapContent = false;
218
223
  this.appliedDangling = false;
224
+ this.shuffleChildren = false;
225
+ this.renderingPriority = Priority.SyncP0;
219
226
  this.level = owner.level + 1;
220
227
  this.host = owner;
221
228
  this.children = new Collection(driver.isSequential, getBlockName);
@@ -311,6 +318,11 @@ class VBlockImpl extends VBlock {
311
318
  this.appliedDangling = value;
312
319
  }
313
320
  }
321
+ configureReactronic(options) {
322
+ if (this.stamp !== 1 || !this.body.reacting)
323
+ throw new Error("reactronic can be configured only for reacting blocks and only inside initialize");
324
+ return Rx.getController(this.rerender).configure(options);
325
+ }
314
326
  static use(type) {
315
327
  var _a, _b;
316
328
  let b = gCurrent.instance;
@@ -384,13 +396,12 @@ function runRenderNestedTreesThenDo(error, action) {
384
396
  break;
385
397
  const block = item.instance;
386
398
  const driver = block.driver;
387
- const opt = block.args;
388
399
  const host = driver.isRow ? owner : partHost;
400
+ const p = (_a = block.renderingPriority) !== null && _a !== void 0 ? _a : Priority.SyncP0;
389
401
  redeploy = markToRedeployIfNecessary(redeploy, host, item, children, sequential);
390
- const priority = (_a = opt === null || opt === void 0 ? void 0 : opt.priority) !== null && _a !== void 0 ? _a : Priority.SyncP0;
391
- if (priority === Priority.SyncP0)
402
+ if (p === Priority.SyncP0)
392
403
  prepareAndRunRender(item, children.isMoved(item), sequential);
393
- else if (priority === Priority.AsyncP1)
404
+ else if (p === Priority.AsyncP1)
394
405
  p1 = push(item, p1);
395
406
  else
396
407
  p2 = push(item, p2);
@@ -430,7 +441,6 @@ function startIncrementalRendering(owner, allChildren, priority1, priority2) {
430
441
  });
431
442
  }
432
443
  function renderIncrementally(owner, stamp, allChildren, items, priority) {
433
- var _a;
434
444
  return __awaiter(this, void 0, void 0, function* () {
435
445
  yield Transaction.requestNextFrame();
436
446
  const block = owner.instance;
@@ -439,7 +449,7 @@ function renderIncrementally(owner, stamp, allChildren, items, priority) {
439
449
  VBlock.currentRenderingPriority = priority;
440
450
  try {
441
451
  const sequential = block.children.strict;
442
- if ((_a = block.args) === null || _a === void 0 ? void 0 : _a.shuffle)
452
+ if (block.shuffleChildren)
443
453
  shuffle(items);
444
454
  const frameDurationLimit = priority === Priority.AsyncP2 ? VBlock.shortFrameDuration : Infinity;
445
455
  let frameDuration = Math.min(frameDurationLimit, Math.max(VBlock.frameDuration / 4, VBlock.shortFrameDuration));
@@ -467,8 +477,8 @@ function prepareAndRunRender(item, redeploy, sequential) {
467
477
  const block = item.instance;
468
478
  if (block.stamp >= 0) {
469
479
  prepareRender(item, redeploy, sequential);
470
- if ((_a = block.args) === null || _a === void 0 ? void 0 : _a.reacting)
471
- nonreactive(block.rerender, (_b = block.args) === null || _b === void 0 ? void 0 : _b.triggers);
480
+ if ((_a = block.body) === null || _a === void 0 ? void 0 : _a.reacting)
481
+ nonreactive(block.rerender, (_b = block.body) === null || _b === void 0 ? void 0 : _b.triggers);
472
482
  else
473
483
  runRender(item);
474
484
  }
@@ -480,16 +490,12 @@ function prepareRender(item, redeploy, sequential) {
480
490
  block.stamp = 1;
481
491
  runUnder(item, () => {
482
492
  var _a;
483
- if ((_a = block.args) === null || _a === void 0 ? void 0 : _a.reacting) {
493
+ if ((_a = block.body) === null || _a === void 0 ? void 0 : _a.reacting) {
484
494
  Transaction.outside(() => {
485
- var _a, _b, _c;
486
495
  if (Rx.isLogging)
487
496
  Rx.setLoggingHint(block, block.name);
488
497
  Rx.getController(block.rerender).configure({
489
498
  order: block.level,
490
- monitor: (_a = block.args) === null || _a === void 0 ? void 0 : _a.monitor,
491
- throttling: (_b = block.args) === null || _b === void 0 ? void 0 : _b.throttling,
492
- logging: (_c = block.args) === null || _c === void 0 ? void 0 : _c.logging,
493
499
  });
494
500
  });
495
501
  }
@@ -536,7 +542,7 @@ function runFinalize(item, isLeader) {
536
542
  if (block.stamp >= 0) {
537
543
  block.stamp = ~block.stamp;
538
544
  const childrenAreLeaders = block.driver.finalize(block, isLeader);
539
- if ((_a = block.args) === null || _a === void 0 ? void 0 : _a.reacting) {
545
+ if ((_a = block.body) === null || _a === void 0 ? void 0 : _a.reacting) {
540
546
  item.aux = undefined;
541
547
  const last = gLastToDispose;
542
548
  if (last)
@@ -569,8 +575,8 @@ function runDisposalLoop() {
569
575
  }
570
576
  function forEachChildRecursively(item, action) {
571
577
  const block = item.instance;
572
- const native = block.native;
573
- native && action(native);
578
+ const e = block.native;
579
+ e && action(e);
574
580
  for (const item of block.children.items())
575
581
  forEachChildRecursively(item, action);
576
582
  }
@@ -1,12 +1,12 @@
1
- import { VBlock, BlockArgs, Align, CellRange } from "../core/api";
1
+ import { VBlock, BlockBody, Align, CellRange } from "../core/api";
2
2
  import { HtmlDriver } from "./HtmlDriver";
3
- export declare function Block<M = unknown, R = void>(name: string, args: BlockArgs<HTMLElement, M, R>): VBlock<HTMLElement, M, R>;
4
- export declare function PlainText(content: string, name?: string, args?: BlockArgs<HTMLElement, void, void>): VBlock<HTMLElement, void, void>;
5
- export declare function HtmlText(content: string, name?: string, args?: BlockArgs<HTMLElement, void, void>): VBlock<HTMLElement, void, void>;
6
- export declare function Grid<M = unknown, R = void>(name: string, args: BlockArgs<HTMLElement, M, R>): VBlock<HTMLElement, M, R>;
3
+ export declare function Block<M = unknown, R = void>(name: string, args: BlockBody<HTMLElement, M, R>): VBlock<HTMLElement, M, R>;
4
+ export declare function PlainText(content: string, name?: string, args?: BlockBody<HTMLElement, void, void>): VBlock<HTMLElement, void, void>;
5
+ export declare function HtmlText(content: string, name?: string, args?: BlockBody<HTMLElement, void, void>): VBlock<HTMLElement, void, void>;
6
+ export declare function Grid<M = unknown, R = void>(name: string, body: BlockBody<HTMLElement, M, R>): VBlock<HTMLElement, M, R>;
7
7
  export declare function Line<T = void>(claim: (x: void) => T): VBlock<HTMLElement>;
8
- export declare function lineFeed(args?: BlockArgs<HTMLElement, void, void>, noCoalescing?: boolean): VBlock<HTMLElement>;
9
- export declare function Group<M = unknown, R = void>(name: string, args: BlockArgs<HTMLElement, M, R>): VBlock<HTMLElement, M, R>;
8
+ export declare function lineFeed(body?: BlockBody<HTMLElement, void, void>, noCoalescing?: boolean): VBlock<HTMLElement>;
9
+ export declare function Group<M = unknown, R = void>(name: string, body: BlockBody<HTMLElement, M, R>): VBlock<HTMLElement, M, R>;
10
10
  export declare class VerstakDriver<T extends HTMLElement> extends HtmlDriver<T> {
11
11
  applyCellRange(block: VBlock<T>, cellRange: CellRange | undefined): void;
12
12
  applyWidthGrowth(block: VBlock<T>, widthGrowth: number): void;
@@ -5,32 +5,32 @@ export function Block(name, args) {
5
5
  }
6
6
  export function PlainText(content, name, args) {
7
7
  return VBlock.claim(name !== null && name !== void 0 ? name : "", VerstakTags.text, asComponent(args, {
8
- render(e) {
9
- e.innerText = content;
8
+ render(b) {
9
+ b.native.innerText = content;
10
10
  },
11
11
  }));
12
12
  }
13
13
  export function HtmlText(content, name, args) {
14
14
  return VBlock.claim(name !== null && name !== void 0 ? name : "", VerstakTags.text, asComponent(args, {
15
- render(e) {
16
- e.innerHTML = content;
15
+ render(b) {
16
+ b.native.innerHTML = content;
17
17
  },
18
18
  }));
19
19
  }
20
- export function Grid(name, args) {
21
- return VBlock.claim(name, VerstakTags.grid, args);
20
+ export function Grid(name, body) {
21
+ return VBlock.claim(name, VerstakTags.grid, body);
22
22
  }
23
23
  export function Line(claim) {
24
- const result = VBlock.claim("", VerstakTags.row, EMPTY_RENDER);
24
+ const result = VBlock.claim("", VerstakTags.row, EMPTY_BLOCK_BODY);
25
25
  claim();
26
- VBlock.claim("", VerstakTags.row, EMPTY_RENDER);
26
+ VBlock.claim("", VerstakTags.row, EMPTY_BLOCK_BODY);
27
27
  return result;
28
28
  }
29
- export function lineFeed(args, noCoalescing) {
30
- return VBlock.claim("", VerstakTags.row, args !== null && args !== void 0 ? args : EMPTY_RENDER);
29
+ export function lineFeed(body, noCoalescing) {
30
+ return VBlock.claim("", VerstakTags.row, body !== null && body !== void 0 ? body : EMPTY_BLOCK_BODY);
31
31
  }
32
- export function Group(name, args) {
33
- return VBlock.claim(name, VerstakTags.group, args);
32
+ export function Group(name, body) {
33
+ return VBlock.claim(name, VerstakTags.group, body);
34
34
  }
35
35
  export class VerstakDriver extends HtmlDriver {
36
36
  applyCellRange(block, cellRange) {
@@ -120,7 +120,7 @@ export class VerstakDriver extends HtmlDriver {
120
120
  }
121
121
  render(block) {
122
122
  if (block.driver.layout < LayoutKind.Row)
123
- VBlock.claim("", VerstakTags.row, EMPTY_RENDER);
123
+ VBlock.claim("", VerstakTags.row, EMPTY_BLOCK_BODY);
124
124
  return super.render(block);
125
125
  }
126
126
  }
@@ -131,6 +131,6 @@ const VerstakTags = {
131
131
  row: new VerstakDriver("v-row", LayoutKind.Row),
132
132
  group: new VerstakDriver("v-group", LayoutKind.Group),
133
133
  };
134
- const EMPTY_RENDER = { render() { } };
134
+ const EMPTY_BLOCK_BODY = { render() { } };
135
135
  const AlignToCss = ["stretch", "start", "center", "end"];
136
136
  const TextAlignCss = ["justify", "left", "center", "right"];