veles 0.0.6 → 0.0.7

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.
package/dist/index.cjs CHANGED
@@ -21,7 +21,6 @@ var src_exports = {};
21
21
  __export(src_exports, {
22
22
  Fragment: () => Fragment,
23
23
  attachComponent: () => attachComponent,
24
- combineState: () => combineState,
25
24
  createElement: () => createElement,
26
25
  createRef: () => createRef,
27
26
  createState: () => createState,
@@ -30,7 +29,7 @@ __export(src_exports, {
30
29
  });
31
30
  module.exports = __toCommonJS(src_exports);
32
31
 
33
- // src/utils.ts
32
+ // src/_utils.ts
34
33
  function getComponentVelesNode(component) {
35
34
  const componentsTree = [];
36
35
  if ("velesStringElement" in component) {
@@ -347,6 +346,307 @@ function createState(initialValue, subscribeCallback) {
347
346
  let trackingSelectorElements = [];
348
347
  let trackingAttributes = [];
349
348
  let trackingIterators = [];
349
+ const _triggerUpdates = () => {
350
+ const newTrackingSelectorElements = [];
351
+ trackingSelectorElements.forEach((selectorTrackingElement) => {
352
+ const { selectedValue, selector, cb, node, comparator } = selectorTrackingElement;
353
+ const newSelectedValue = selector ? selector(value) : value;
354
+ if (comparator(selectedValue, newSelectedValue)) {
355
+ newTrackingSelectorElements.push(selectorTrackingElement);
356
+ return;
357
+ }
358
+ const returnednewNode = cb ? cb(newSelectedValue) : String(newSelectedValue);
359
+ const newNode = !returnednewNode || typeof returnednewNode === "string" ? createTextElement(returnednewNode) : returnednewNode;
360
+ const { velesElementNode: oldVelesElementNode } = getComponentVelesNode(node);
361
+ const { velesElementNode: newVelesElementNode } = getComponentVelesNode(newNode);
362
+ const parentVelesElement = oldVelesElementNode.parentVelesElement;
363
+ const newTrackingSelectorElement = {
364
+ selector,
365
+ selectedValue: newSelectedValue,
366
+ cb,
367
+ node: newNode,
368
+ comparator
369
+ };
370
+ if (parentVelesElement) {
371
+ newVelesElementNode.parentVelesElement = parentVelesElement;
372
+ if ("velesNode" in newVelesElementNode && newVelesElementNode.phantom) {
373
+ const insertAllPhantomChildren = (adjacentNode) => {
374
+ newVelesElementNode.childComponents.forEach(
375
+ (childComponentofPhantom) => {
376
+ if ("velesNode" in childComponentofPhantom) {
377
+ adjacentNode.html.before(childComponentofPhantom.html);
378
+ childComponentofPhantom.parentVelesElement = adjacentNode.parentVelesElement;
379
+ } else {
380
+ const { velesElementNode } = getComponentVelesNode(
381
+ childComponentofPhantom
382
+ );
383
+ if (!velesElementNode) {
384
+ console.error("can't find HTML tree in a component chain");
385
+ } else {
386
+ adjacentNode.html.before(velesElementNode.html);
387
+ velesElementNode.parentVelesElement = adjacentNode.parentVelesElement;
388
+ }
389
+ }
390
+ }
391
+ );
392
+ };
393
+ if ("velesNode" in oldVelesElementNode && oldVelesElementNode.phantom) {
394
+ let isInserted = false;
395
+ oldVelesElementNode.childComponents.forEach(
396
+ (childComponentofPhantom) => {
397
+ if ("velesNode" in childComponentofPhantom) {
398
+ if (!isInserted) {
399
+ insertAllPhantomChildren(childComponentofPhantom);
400
+ isInserted = true;
401
+ }
402
+ childComponentofPhantom.html.remove();
403
+ } else {
404
+ const { velesElementNode } = getComponentVelesNode(
405
+ childComponentofPhantom
406
+ );
407
+ if (!velesElementNode) {
408
+ console.error("can't find HTML tree in a component chain");
409
+ } else {
410
+ if (!isInserted) {
411
+ insertAllPhantomChildren(velesElementNode);
412
+ isInserted = true;
413
+ }
414
+ velesElementNode.html.remove();
415
+ }
416
+ }
417
+ }
418
+ );
419
+ } else {
420
+ insertAllPhantomChildren(oldVelesElementNode);
421
+ oldVelesElementNode.html.remove();
422
+ }
423
+ } else {
424
+ if ("velesNode" in oldVelesElementNode && oldVelesElementNode.phantom) {
425
+ let isInserted = false;
426
+ oldVelesElementNode.childComponents.forEach(
427
+ (childComponentofPhantom) => {
428
+ if ("velesNode" in childComponentofPhantom) {
429
+ if (!isInserted) {
430
+ childComponentofPhantom.html.before(
431
+ newVelesElementNode.html
432
+ );
433
+ isInserted = true;
434
+ }
435
+ childComponentofPhantom.html.remove();
436
+ } else {
437
+ const { velesElementNode } = getComponentVelesNode(
438
+ childComponentofPhantom
439
+ );
440
+ if (!velesElementNode) {
441
+ console.error("can't find HTML tree in a component chain");
442
+ } else {
443
+ if (!isInserted) {
444
+ velesElementNode.html.before(newVelesElementNode.html);
445
+ isInserted = true;
446
+ }
447
+ velesElementNode.html.remove();
448
+ }
449
+ }
450
+ }
451
+ );
452
+ } else {
453
+ parentVelesElement.html.replaceChild(
454
+ newVelesElementNode.html,
455
+ oldVelesElementNode.html
456
+ );
457
+ }
458
+ }
459
+ parentVelesElement.childComponents = parentVelesElement.childComponents.map(
460
+ (childComponent) => childComponent === node ? newNode : node
461
+ );
462
+ node._privateMethods._callUnmountHandlers();
463
+ callMountHandlers(newNode);
464
+ newNode._privateMethods._addUnmountHandler(() => {
465
+ trackingSelectorElements = trackingSelectorElements.filter(
466
+ (el) => el !== newTrackingSelectorElement
467
+ );
468
+ });
469
+ } else {
470
+ console.log("parent node was not found");
471
+ }
472
+ newTrackingSelectorElements.push(newTrackingSelectorElement);
473
+ });
474
+ trackingSelectorElements = unique(
475
+ trackingSelectorElements.concat(newTrackingSelectorElements)
476
+ );
477
+ trackingAttributes.forEach(({ cb, htmlElement, attributeName }) => {
478
+ const newAttributeValue = cb ? cb(value) : value;
479
+ htmlElement.setAttribute(attributeName, newAttributeValue);
480
+ });
481
+ trackingEffects.forEach((trackingEffect) => {
482
+ const { cb, selectedValue, selector, comparator } = trackingEffect;
483
+ const newSelectedValue = selector ? selector(value) : value;
484
+ if (comparator ? comparator(selectedValue, newSelectedValue) : selectedValue === newSelectedValue) {
485
+ return;
486
+ }
487
+ cb(newSelectedValue);
488
+ trackingEffect.selectedValue = newSelectedValue;
489
+ });
490
+ trackingIterators.forEach((trackingIterator) => {
491
+ const {
492
+ cb,
493
+ key,
494
+ renderedElements,
495
+ elementsByKey,
496
+ wrapperComponent,
497
+ selector
498
+ } = trackingIterator;
499
+ if (!wrapperComponent) {
500
+ console.error("there is no wrapper component for the iterator");
501
+ return;
502
+ }
503
+ const { velesElementNode: wrapperVelesElementNode } = getComponentVelesNode(wrapperComponent);
504
+ const parentVelesElement = wrapperVelesElementNode.parentVelesElement;
505
+ if (!parentVelesElement) {
506
+ console.error("there is no parent Veles node for the iterator wrapper");
507
+ return;
508
+ }
509
+ const elements = selector ? selector(value) : value;
510
+ if (Array.isArray(elements)) {
511
+ const newRenderedElements = [];
512
+ const newElementsByKey = {};
513
+ const renderedExistingElements = {};
514
+ elements.forEach((element, index) => {
515
+ let calculatedKey = "";
516
+ if (typeof key === "string" && typeof element === "object" && element !== null && key in element) {
517
+ calculatedKey = element[key];
518
+ } else if (typeof key === "function") {
519
+ calculatedKey = key({ element, index });
520
+ } else {
521
+ }
522
+ if (!calculatedKey) {
523
+ return;
524
+ }
525
+ const existingElement = elementsByKey[calculatedKey];
526
+ if (existingElement) {
527
+ renderedExistingElements[calculatedKey] = true;
528
+ const currentValue = existingElement.elementState.getValue();
529
+ if (currentValue !== element) {
530
+ existingElement.elementState.setValue(element);
531
+ }
532
+ const currentIndex = existingElement.indexState.getValue();
533
+ if (currentIndex !== index) {
534
+ existingElement.indexState.setValue(index);
535
+ }
536
+ newRenderedElements.push([
537
+ existingElement.node,
538
+ calculatedKey,
539
+ existingElement.elementState
540
+ ]);
541
+ newElementsByKey[calculatedKey] = {
542
+ elementState: existingElement.elementState,
543
+ indexState: existingElement.indexState,
544
+ indexValue: index,
545
+ node: existingElement.node
546
+ };
547
+ } else {
548
+ const elementState = createState(element);
549
+ const indexState = createState(index);
550
+ const node = cb({ elementState, indexState });
551
+ newRenderedElements.push([node, calculatedKey, elementState]);
552
+ newElementsByKey[calculatedKey] = {
553
+ elementState,
554
+ indexState,
555
+ indexValue: index,
556
+ node
557
+ };
558
+ }
559
+ });
560
+ const positioningOffset = {};
561
+ let newElementsCount = 0;
562
+ let offset = 0;
563
+ let currentElement = null;
564
+ newRenderedElements.forEach((newRenderedElement, index) => {
565
+ var _a, _b, _c;
566
+ if (positioningOffset[index]) {
567
+ offset = offset + positioningOffset[index];
568
+ }
569
+ const [newNode, calculatedKey, newState] = newRenderedElement;
570
+ const existingElement = elementsByKey[calculatedKey];
571
+ if (existingElement) {
572
+ const { velesElementNode: existingElementNode } = getComponentVelesNode(existingElement.node);
573
+ if (existingElement.indexValue + offset === index) {
574
+ currentElement = existingElementNode.html;
575
+ return;
576
+ }
577
+ if (existingElement.indexValue + offset > index) {
578
+ if (currentElement) {
579
+ currentElement.after(existingElementNode.html);
580
+ positioningOffset[existingElement.indexValue + 1] = -1;
581
+ } else {
582
+ const firstRenderedElement = (_a = renderedElements[0]) == null ? void 0 : _a[0];
583
+ if (firstRenderedElement) {
584
+ const { velesElementNode: firstRenderedVelesNode } = getComponentVelesNode(firstRenderedElement);
585
+ firstRenderedVelesNode.html.before(existingElementNode.html);
586
+ } else {
587
+ }
588
+ }
589
+ currentElement = existingElementNode.html;
590
+ offset = offset + 1;
591
+ } else {
592
+ if (currentElement) {
593
+ currentElement.after(existingElementNode.html);
594
+ positioningOffset[existingElement.indexValue + 1] = 1;
595
+ } else {
596
+ const firstRenderedElement = (_b = renderedElements[0]) == null ? void 0 : _b[0];
597
+ if (firstRenderedElement) {
598
+ const { velesElementNode: firstRenderedVelesNode } = getComponentVelesNode(firstRenderedElement);
599
+ firstRenderedVelesNode.html.before(existingElementNode.html);
600
+ } else {
601
+ }
602
+ }
603
+ currentElement = existingElementNode.html;
604
+ offset = offset - 1;
605
+ }
606
+ } else {
607
+ const { velesElementNode: newNodeVelesElement } = getComponentVelesNode(newNode);
608
+ newNodeVelesElement.parentVelesElement = parentVelesElement;
609
+ if (currentElement) {
610
+ currentElement.after(newNodeVelesElement.html);
611
+ } else {
612
+ const firstRenderedElement = (_c = renderedElements[0]) == null ? void 0 : _c[0];
613
+ if (firstRenderedElement) {
614
+ const { velesElementNode: firstRenderedVelesNode } = getComponentVelesNode(firstRenderedElement);
615
+ firstRenderedVelesNode.html.before(newNodeVelesElement.html);
616
+ } else {
617
+ parentVelesElement.html.prepend(newNodeVelesElement.html);
618
+ }
619
+ }
620
+ offset = offset + 1;
621
+ currentElement = newNodeVelesElement.html;
622
+ newElementsCount = newElementsCount + 1;
623
+ callMountHandlers(newNode);
624
+ }
625
+ });
626
+ if (renderedElements.length === newRenderedElements.length + newElementsCount) {
627
+ } else {
628
+ renderedElements.forEach(([oldNode, calculatedKey]) => {
629
+ if (renderedExistingElements[calculatedKey] === true) {
630
+ return;
631
+ } else {
632
+ const { velesElementNode: oldRenderedVelesNode } = getComponentVelesNode(oldNode);
633
+ oldRenderedVelesNode.html.remove();
634
+ oldNode._privateMethods._callUnmountHandlers();
635
+ if ("velesNode" in wrapperVelesElementNode) {
636
+ wrapperVelesElementNode.childComponents = wrapperVelesElementNode.childComponents.filter(
637
+ (childComponent) => childComponent !== oldNode
638
+ );
639
+ } else {
640
+ throw new Error("Wrapper iterator element is a string");
641
+ }
642
+ }
643
+ });
644
+ }
645
+ trackingIterator.renderedElements = newRenderedElements;
646
+ trackingIterator.elementsByKey = newElementsByKey;
647
+ }
648
+ });
649
+ };
350
650
  const result = {
351
651
  // supposed to be used at the component level
352
652
  trackValue: (cb, options = {}) => {
@@ -414,13 +714,15 @@ function createState(initialValue, subscribeCallback) {
414
714
  } else {
415
715
  }
416
716
  const elementState = createState(element);
717
+ const indexState = createState(index);
417
718
  if (!calculatedKey) {
418
719
  return;
419
720
  }
420
- let node = cb({ elementState, index });
721
+ let node = cb({ elementState, indexState });
421
722
  elementsByKey[calculatedKey] = {
422
723
  node,
423
- index,
724
+ indexState,
725
+ indexValue: index,
424
726
  elementState
425
727
  };
426
728
  children.push([node, calculatedKey, elementState]);
@@ -481,227 +783,8 @@ function createState(initialValue, subscribeCallback) {
481
783
  if (newValue !== value) {
482
784
  previousValue = value;
483
785
  value = newValue;
484
- result._triggerUpdates();
786
+ _triggerUpdates();
485
787
  }
486
- },
487
- // TODO: remove it from this object completely
488
- // and access it from closure
489
- _triggerUpdates: () => {
490
- const newTrackingSelectorElements = [];
491
- trackingSelectorElements.forEach((selectorTrackingElement) => {
492
- const { selectedValue, selector, cb, node, comparator } = selectorTrackingElement;
493
- const newSelectedValue = selector ? selector(value) : value;
494
- if (comparator(selectedValue, newSelectedValue)) {
495
- newTrackingSelectorElements.push(selectorTrackingElement);
496
- return;
497
- }
498
- const returnednewNode = cb ? cb(newSelectedValue) : String(newSelectedValue);
499
- const newNode = !returnednewNode || typeof returnednewNode === "string" ? createTextElement(returnednewNode) : returnednewNode;
500
- const { velesElementNode: oldVelesElementNode } = getComponentVelesNode(node);
501
- const { velesElementNode: newVelesElementNode } = getComponentVelesNode(newNode);
502
- const parentVelesElement = oldVelesElementNode.parentVelesElement;
503
- const newTrackingSelectorElement = {
504
- selector,
505
- selectedValue: newSelectedValue,
506
- cb,
507
- node: newNode,
508
- comparator
509
- };
510
- if (parentVelesElement) {
511
- newVelesElementNode.parentVelesElement = parentVelesElement;
512
- parentVelesElement.html.replaceChild(
513
- newVelesElementNode.html,
514
- oldVelesElementNode.html
515
- );
516
- parentVelesElement.childComponents = parentVelesElement.childComponents.map(
517
- (childComponent) => childComponent === node ? newNode : node
518
- );
519
- node._privateMethods._callUnmountHandlers();
520
- callMountHandlers(newNode);
521
- newNode._privateMethods._addUnmountHandler(() => {
522
- trackingSelectorElements = trackingSelectorElements.filter(
523
- (el) => el !== newTrackingSelectorElement
524
- );
525
- });
526
- } else {
527
- console.log("parent node was not found");
528
- }
529
- newTrackingSelectorElements.push(newTrackingSelectorElement);
530
- });
531
- trackingSelectorElements = unique(
532
- trackingSelectorElements.concat(newTrackingSelectorElements)
533
- );
534
- trackingAttributes.forEach(({ cb, htmlElement, attributeName }) => {
535
- const newAttributeValue = cb ? cb(value) : value;
536
- htmlElement.setAttribute(attributeName, newAttributeValue);
537
- });
538
- trackingEffects.forEach((trackingEffect) => {
539
- const { cb, selectedValue, selector, comparator } = trackingEffect;
540
- const newSelectedValue = selector ? selector(value) : value;
541
- if (comparator ? comparator(selectedValue, newSelectedValue) : selectedValue === newSelectedValue) {
542
- return;
543
- }
544
- cb(newSelectedValue);
545
- trackingEffect.selectedValue = newSelectedValue;
546
- });
547
- trackingIterators.forEach((trackingIterator) => {
548
- const {
549
- cb,
550
- key,
551
- renderedElements,
552
- elementsByKey,
553
- wrapperComponent,
554
- selector
555
- } = trackingIterator;
556
- if (!wrapperComponent) {
557
- console.error("there is no wrapper component for the iterator");
558
- return;
559
- }
560
- const { velesElementNode: wrapperVelesElementNode } = getComponentVelesNode(wrapperComponent);
561
- const parentVelesElement = wrapperVelesElementNode.parentVelesElement;
562
- if (!parentVelesElement) {
563
- console.error(
564
- "there is no parent Veles node for the iterator wrapper"
565
- );
566
- return;
567
- }
568
- const elements = selector ? selector(value) : value;
569
- if (Array.isArray(elements)) {
570
- const newRenderedElements = [];
571
- const newElementsByKey = {};
572
- const renderedExistingElements = {};
573
- elements.forEach((element, index) => {
574
- let calculatedKey = "";
575
- if (typeof key === "string" && typeof element === "object" && element !== null && key in element) {
576
- calculatedKey = element[key];
577
- } else if (typeof key === "function") {
578
- calculatedKey = key({ element, index });
579
- } else {
580
- }
581
- if (!calculatedKey) {
582
- return;
583
- }
584
- const existingElement = elementsByKey[calculatedKey];
585
- if (existingElement) {
586
- renderedExistingElements[calculatedKey] = true;
587
- const currentValue = existingElement.elementState.getValue();
588
- if (currentValue !== element) {
589
- existingElement.elementState.setValue(() => element);
590
- }
591
- newRenderedElements.push([
592
- existingElement.node,
593
- calculatedKey,
594
- existingElement.elementState
595
- ]);
596
- newElementsByKey[calculatedKey] = {
597
- elementState: existingElement.elementState,
598
- index,
599
- node: existingElement.node
600
- };
601
- } else {
602
- const elementState = createState(element);
603
- const node = cb({ elementState, index });
604
- newRenderedElements.push([node, calculatedKey, elementState]);
605
- newElementsByKey[calculatedKey] = {
606
- elementState,
607
- index,
608
- node
609
- };
610
- }
611
- });
612
- const positioningOffset = {};
613
- let newElementsCount = 0;
614
- let offset = 0;
615
- let currentElement = null;
616
- newRenderedElements.forEach((newRenderedElement, index) => {
617
- var _a, _b, _c;
618
- if (positioningOffset[index]) {
619
- offset = offset + positioningOffset[index];
620
- }
621
- const [newNode, calculatedKey, newState] = newRenderedElement;
622
- const existingElement = elementsByKey[calculatedKey];
623
- if (existingElement) {
624
- const { velesElementNode: existingElementNode } = getComponentVelesNode(existingElement.node);
625
- if (existingElement.index + offset === index) {
626
- currentElement = existingElementNode.html;
627
- return;
628
- }
629
- if (existingElement.index + offset > index) {
630
- if (currentElement) {
631
- currentElement.after(existingElementNode.html);
632
- positioningOffset[existingElement.index + 1] = -1;
633
- } else {
634
- const firstRenderedElement = (_a = renderedElements[0]) == null ? void 0 : _a[0];
635
- if (firstRenderedElement) {
636
- const { velesElementNode: firstRenderedVelesNode } = getComponentVelesNode(firstRenderedElement);
637
- firstRenderedVelesNode.html.before(
638
- existingElementNode.html
639
- );
640
- } else {
641
- }
642
- }
643
- currentElement = existingElementNode.html;
644
- offset = offset + 1;
645
- } else {
646
- if (currentElement) {
647
- currentElement.after(existingElementNode.html);
648
- positioningOffset[existingElement.index + 1] = 1;
649
- } else {
650
- const firstRenderedElement = (_b = renderedElements[0]) == null ? void 0 : _b[0];
651
- if (firstRenderedElement) {
652
- const { velesElementNode: firstRenderedVelesNode } = getComponentVelesNode(firstRenderedElement);
653
- firstRenderedVelesNode.html.before(
654
- existingElementNode.html
655
- );
656
- } else {
657
- }
658
- }
659
- currentElement = existingElementNode.html;
660
- offset = offset - 1;
661
- }
662
- } else {
663
- const { velesElementNode: newNodeVelesElement } = getComponentVelesNode(newNode);
664
- newNodeVelesElement.parentVelesElement = parentVelesElement;
665
- if (currentElement) {
666
- currentElement.after(newNodeVelesElement.html);
667
- } else {
668
- const firstRenderedElement = (_c = renderedElements[0]) == null ? void 0 : _c[0];
669
- if (firstRenderedElement) {
670
- const { velesElementNode: firstRenderedVelesNode } = getComponentVelesNode(firstRenderedElement);
671
- firstRenderedVelesNode.html.before(newNodeVelesElement.html);
672
- } else {
673
- parentVelesElement.html.prepend(newNodeVelesElement.html);
674
- }
675
- }
676
- offset = offset + 1;
677
- currentElement = newNodeVelesElement.html;
678
- newElementsCount = newElementsCount + 1;
679
- callMountHandlers(newNode);
680
- }
681
- });
682
- if (renderedElements.length === newRenderedElements.length + newElementsCount) {
683
- } else {
684
- renderedElements.forEach(([oldNode, calculatedKey]) => {
685
- if (renderedExistingElements[calculatedKey] === true) {
686
- return;
687
- } else {
688
- const { velesElementNode: oldRenderedVelesNode } = getComponentVelesNode(oldNode);
689
- oldRenderedVelesNode.html.remove();
690
- oldNode._privateMethods._callUnmountHandlers();
691
- if ("velesNode" in wrapperVelesElementNode) {
692
- wrapperVelesElementNode.childComponents = wrapperVelesElementNode.childComponents.filter(
693
- (childComponent) => childComponent !== oldNode
694
- );
695
- } else {
696
- throw new Error("Wrapper iterator element is a string");
697
- }
698
- }
699
- });
700
- }
701
- trackingIterator.renderedElements = newRenderedElements;
702
- trackingIterator.elementsByKey = newElementsByKey;
703
- }
704
- });
705
788
  }
706
789
  };
707
790
  if (subscribeCallback) {
@@ -713,19 +796,6 @@ function createState(initialValue, subscribeCallback) {
713
796
  return result;
714
797
  }
715
798
 
716
- // src/hooks/combine-state.ts
717
- function combineState(...states) {
718
- const initialValue = states.map((state) => state.getValue());
719
- const combinedState = createState(initialValue);
720
- states.forEach((state) => {
721
- state.trackValue(() => {
722
- const updatedValue = states.map((state2) => state2.getValue());
723
- combinedState.setValue(updatedValue);
724
- });
725
- });
726
- return combinedState;
727
- }
728
-
729
799
  // src/create-ref.ts
730
800
  function createRef(initialRefValue = null) {
731
801
  return {
@@ -745,7 +815,6 @@ function Fragment({ children }) {
745
815
  0 && (module.exports = {
746
816
  Fragment,
747
817
  attachComponent,
748
- combineState,
749
818
  createElement,
750
819
  createRef,
751
820
  createState,
package/dist/index.d.cts CHANGED
@@ -1,53 +1,12 @@
1
- import { V as VelesElement, a as VelesComponent, b as VelesStringElement, A as AttributeHelper } from './fragment-CHmQ0MhU.cjs';
2
- export { F as Fragment, c as createElement } from './fragment-CHmQ0MhU.cjs';
1
+ import { V as VelesElement, a as VelesComponent } from './types.d-DgVBp6oa.cjs';
2
+ export { F as Fragment, c as createElement } from './fragment-CU26z590.cjs';
3
+ export { S as State, c as createState } from './create-state-D1JASFVs.cjs';
3
4
 
4
5
  declare function attachComponent({ htmlElement, component, }: {
5
6
  htmlElement: HTMLElement;
6
7
  component: VelesElement | VelesComponent;
7
8
  }): () => void;
8
9
 
9
- type State<ValueType> = {
10
- trackValue(cb: (value: ValueType) => void | Function, options?: {
11
- callOnMount?: boolean;
12
- skipFirstCall?: boolean;
13
- comparator?: (value1: ValueType, value2: ValueType) => boolean;
14
- }): void;
15
- trackValueSelector<SelectorValueType>(selector: (value: ValueType) => SelectorValueType, cb: (value: SelectorValueType) => void | Function, options?: {
16
- callOnMount?: boolean;
17
- skipFirstCall?: boolean;
18
- comparator?: (value1: SelectorValueType, value2: SelectorValueType) => boolean;
19
- }): void;
20
- useValue(cb?: (value: ValueType) => VelesElement | VelesComponent | string | undefined | null, comparator?: (value1: ValueType, value2: ValueType) => boolean): VelesElement | VelesComponent | VelesStringElement;
21
- useValueSelector<SelectorValueType>(selector: (value: ValueType) => SelectorValueType, cb?: (value: SelectorValueType) => VelesElement | VelesComponent | string | undefined | null, comparator?: (value1: SelectorValueType, value2: SelectorValueType) => boolean): VelesElement | VelesComponent | VelesStringElement;
22
- useAttribute(cb?: (value: ValueType) => any): AttributeHelper<any>;
23
- useValueIterator<Element>(options: {
24
- key: string | ((options: {
25
- element: Element;
26
- index: number;
27
- }) => string);
28
- selector?: (value: ValueType) => Element[];
29
- }, cb: (props: {
30
- elementState: State<Element>;
31
- index: number;
32
- }) => VelesElement | VelesComponent): VelesComponent | VelesElement | null;
33
- getValue(): ValueType;
34
- getPreviousValue(): undefined | ValueType;
35
- setValue(newValueCB: ((currentValue: ValueType) => ValueType) | ValueType): void;
36
- _triggerUpdates(): void;
37
- };
38
- declare function createState<T>(initialValue: T, subscribeCallback?: (setValue: ReturnType<typeof createState<T>>["setValue"]) => Function): State<T>;
39
-
40
- type createdState<StateType> = ReturnType<typeof createState<StateType>>;
41
- declare function combineState<A, B>(state1: createdState<A>, state2: createdState<B>): createdState<[A, B]>;
42
- declare function combineState<A, B, C>(state1: createdState<A>, state2: createdState<B>, state3: createdState<C>): createdState<[A, B, C]>;
43
- declare function combineState<A, B, C, D>(state1: createdState<A>, state2: createdState<B>, state3: createdState<C>, state4: createdState<D>): createdState<[A, B, C, D]>;
44
- declare function combineState<A, B, C, D, E>(state1: createdState<A>, state2: createdState<B>, state3: createdState<C>, state4: createdState<D>, state5: createdState<E>): createdState<[A, B, C, D, E]>;
45
- declare function combineState<A, B, C, D, E, F>(state1: createdState<A>, state2: createdState<B>, state3: createdState<C>, state4: createdState<D>, state5: createdState<E>, state6: createdState<F>): createdState<[A, B, C, D, E, F]>;
46
- declare function combineState<A, B, C, D, E, F, G>(state1: createdState<A>, state2: createdState<B>, state3: createdState<C>, state4: createdState<D>, state5: createdState<E>, state6: createdState<F>, state7: createdState<G>): createdState<[A, B, C, D, E, F, G]>;
47
- declare function combineState<A, B, C, D, E, F, G, H>(state1: createdState<A>, state2: createdState<B>, state3: createdState<C>, state4: createdState<D>, state5: createdState<E>, state6: createdState<F>, state7: createdState<G>, state8: createdState<H>): createdState<[A, B, C, D, E, F, G, H]>;
48
- declare function combineState<A, B, C, D, E, F, G, H, I>(state1: createdState<A>, state2: createdState<B>, state3: createdState<C>, state4: createdState<D>, state5: createdState<E>, state6: createdState<F>, state7: createdState<G>, state8: createdState<H>, state9: createdState<I>): createdState<[A, B, C, D, E, F, G, H, I]>;
49
- declare function combineState<A, B, C, D, E, F, G, H, I, J>(state1: createdState<A>, state2: createdState<B>, state3: createdState<C>, state4: createdState<D>, state5: createdState<E>, state6: createdState<F>, state7: createdState<G>, state8: createdState<H>, state9: createdState<I>, state10: createdState<J>): createdState<[A, B, C, D, E, F, G, H, I, J]>;
50
-
51
10
  declare function onMount(cb: () => void | Function): void;
52
11
  declare function onUnmount(cb: Function): void;
53
12
 
@@ -56,4 +15,4 @@ declare function createRef<T>(initialRefValue?: T | null): {
56
15
  current: T | null;
57
16
  };
58
17
 
59
- export { type State, attachComponent, combineState, createRef, createState, onMount, onUnmount };
18
+ export { attachComponent, createRef, onMount, onUnmount };