@vertz/ui 0.2.11 → 0.2.13

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 (35) hide show
  1. package/README.md +70 -6
  2. package/dist/shared/{chunk-n91rwj2r.js → chunk-2sth83bd.js} +4 -2
  3. package/dist/shared/{chunk-9e92w0wt.js → chunk-83g4h38e.js} +13 -0
  4. package/dist/shared/{chunk-hrd0mft1.js → chunk-8hsz5y4a.js} +102 -37
  5. package/dist/shared/{chunk-q6cpe5k7.js → chunk-c30eg6wn.js} +1 -1
  6. package/dist/shared/{chunk-qacth5ah.js → chunk-c9xxsrat.js} +7 -2
  7. package/dist/shared/{chunk-v3yyf79g.js → chunk-dksg08fq.js} +1 -1
  8. package/dist/shared/{chunk-g4rch80a.js → chunk-h89w580h.js} +7 -0
  9. package/dist/shared/chunk-hw67ckr3.js +1212 -0
  10. package/dist/shared/{chunk-ryb49346.js → chunk-j6qyxfdc.js} +7 -7
  11. package/dist/shared/{chunk-ka5ked7n.js → chunk-mj7b4t40.js} +107 -41
  12. package/dist/shared/{chunk-0xcmwgdb.js → chunk-nn9v1zmk.js} +6 -6
  13. package/dist/src/auth/public.d.ts +303 -0
  14. package/dist/src/auth/public.js +773 -0
  15. package/dist/src/css/public.js +22 -0
  16. package/dist/{form → src/form}/public.js +2 -2
  17. package/dist/{index.d.ts → src/index.d.ts} +220 -15
  18. package/dist/{index.js → src/index.js} +96 -232
  19. package/dist/{internals.d.ts → src/internals.d.ts} +266 -4
  20. package/dist/{internals.js → src/internals.js} +35 -26
  21. package/dist/{jsx-runtime → src/jsx-runtime}/index.d.ts +1 -1
  22. package/dist/{jsx-runtime → src/jsx-runtime}/index.js +1 -1
  23. package/dist/{query → src/query}/public.d.ts +3 -1
  24. package/dist/src/query/public.js +15 -0
  25. package/dist/{router → src/router}/public.d.ts +25 -4
  26. package/dist/{router → src/router}/public.js +9 -9
  27. package/dist/{test → src/test}/index.d.ts +12 -2
  28. package/dist/{test → src/test}/index.js +4 -4
  29. package/package.json +31 -25
  30. package/reactivity.json +67 -0
  31. package/dist/css/public.js +0 -22
  32. package/dist/query/public.js +0 -15
  33. package/dist/shared/chunk-rjjjvmcf.js +0 -528
  34. /package/dist/{css → src/css}/public.d.ts +0 -0
  35. /package/dist/{form → src/form}/public.d.ts +0 -0
@@ -20,7 +20,7 @@ import {
20
20
  slideOutToTop,
21
21
  zoomIn,
22
22
  zoomOut
23
- } from "./shared/chunk-n91rwj2r.js";
23
+ } from "../shared/chunk-2sth83bd.js";
24
24
  import {
25
25
  Outlet,
26
26
  OutletContext,
@@ -31,25 +31,34 @@ import {
31
31
  useParams,
32
32
  useRouter,
33
33
  useSearchParams
34
- } from "./shared/chunk-0xcmwgdb.js";
35
- import"./shared/chunk-v3yyf79g.js";
34
+ } from "../shared/chunk-nn9v1zmk.js";
35
+ import"../shared/chunk-dksg08fq.js";
36
36
  import {
37
37
  createRouter
38
- } from "./shared/chunk-ka5ked7n.js";
38
+ } from "../shared/chunk-mj7b4t40.js";
39
39
  import {
40
40
  defineRoutes
41
- } from "./shared/chunk-9e92w0wt.js";
41
+ } from "../shared/chunk-83g4h38e.js";
42
42
  import {
43
43
  createFieldState,
44
44
  form,
45
45
  formDataToObject,
46
46
  validate
47
- } from "./shared/chunk-q6cpe5k7.js";
47
+ } from "../shared/chunk-c30eg6wn.js";
48
48
  import {
49
+ EntityStore,
50
+ QueryEnvelopeStore,
51
+ getEntityStore,
52
+ getMutationEventBus,
53
+ getQueryEnvelopeStore,
54
+ getRelationSchema,
55
+ invalidate,
49
56
  query,
50
- queryMatch
51
- } from "./shared/chunk-rjjjvmcf.js";
52
- import"./shared/chunk-jrtrk5z4.js";
57
+ queryMatch,
58
+ registerRelationSchema,
59
+ resetRelationSchemas_TEST_ONLY
60
+ } from "../shared/chunk-hw67ckr3.js";
61
+ import"../shared/chunk-jrtrk5z4.js";
53
62
  import {
54
63
  ThemeProvider,
55
64
  children,
@@ -63,7 +72,7 @@ import {
63
72
  resolveChildren,
64
73
  s,
65
74
  variants
66
- } from "./shared/chunk-qacth5ah.js";
75
+ } from "../shared/chunk-c9xxsrat.js";
67
76
  import {
68
77
  __append,
69
78
  __element,
@@ -72,14 +81,15 @@ import {
72
81
  __staticText,
73
82
  endHydration,
74
83
  startHydration
75
- } from "./shared/chunk-ryb49346.js";
84
+ } from "../shared/chunk-j6qyxfdc.js";
85
+ import"../shared/chunk-prj7nm08.js";
76
86
  import {
77
87
  RENDER_NODE_BRAND,
78
88
  createDOMAdapter,
79
89
  getAdapter,
80
90
  isRenderNode,
81
91
  setAdapter
82
- } from "./shared/chunk-g4rch80a.js";
92
+ } from "../shared/chunk-h89w580h.js";
83
93
  import {
84
94
  DisposalScopeError,
85
95
  _tryOnCleanup,
@@ -88,6 +98,7 @@ import {
88
98
  createContext,
89
99
  domEffect,
90
100
  getContextScope,
101
+ getSSRContext,
91
102
  popScope,
92
103
  pushScope,
93
104
  runCleanups,
@@ -95,8 +106,7 @@ import {
95
106
  signal,
96
107
  untrack,
97
108
  useContext
98
- } from "./shared/chunk-hrd0mft1.js";
99
- import"./shared/chunk-prj7nm08.js";
109
+ } from "../shared/chunk-8hsz5y4a.js";
100
110
  // src/component/error-boundary-context.ts
101
111
  var handlerStack = [];
102
112
  function pushErrorHandler(handler) {
@@ -156,11 +166,8 @@ function ErrorBoundary(props) {
156
166
  }
157
167
  // src/component/lifecycle.ts
158
168
  function onMount(callback) {
159
- if (typeof globalThis !== "undefined") {
160
- const check = globalThis.__VERTZ_IS_SSR__;
161
- if (typeof check === "function" && check())
162
- return;
163
- }
169
+ if (getSSRContext())
170
+ return;
164
171
  const scope = pushScope();
165
172
  try {
166
173
  const cleanup = untrack(callback);
@@ -253,14 +260,20 @@ function listTransition(startMarker, endMarker, items, keyFn, renderFn) {
253
260
  keyGeneration.set(key, gen);
254
261
  exitingNodes.add(node);
255
262
  exitingKeyMap.set(key, node);
256
- node.setAttribute("data-presence", "exit");
257
- onAnimationsComplete(node, () => {
258
- if (keyGeneration.get(key) === gen) {
259
- node.parentNode?.removeChild(node);
260
- exitingNodes.delete(node);
261
- exitingKeyMap.delete(key);
262
- }
263
- });
263
+ if (node instanceof Element) {
264
+ node.setAttribute("data-presence", "exit");
265
+ onAnimationsComplete(node, () => {
266
+ if (keyGeneration.get(key) === gen) {
267
+ node.parentNode?.removeChild(node);
268
+ exitingNodes.delete(node);
269
+ exitingKeyMap.delete(key);
270
+ }
271
+ });
272
+ } else {
273
+ node.parentNode?.removeChild(node);
274
+ exitingNodes.delete(node);
275
+ exitingKeyMap.delete(key);
276
+ }
264
277
  }
265
278
  }
266
279
  const desiredNodes = [];
@@ -285,7 +298,8 @@ function listTransition(startMarker, endMarker, items, keyFn, renderFn) {
285
298
  nodeMap.set(key, node);
286
299
  scopeMap.set(key, scope);
287
300
  itemSignalMap.set(key, itemSig);
288
- node.setAttribute("data-presence", "enter");
301
+ if (node instanceof Element)
302
+ node.setAttribute("data-presence", "enter");
289
303
  enterNodes.push({ node, key });
290
304
  } else {
291
305
  const itemSig = itemSignalMap.get(key);
@@ -310,6 +324,8 @@ function listTransition(startMarker, endMarker, items, keyFn, renderFn) {
310
324
  }
311
325
  }
312
326
  for (const { node: enterNode, key } of enterNodes) {
327
+ if (!(enterNode instanceof Element))
328
+ continue;
313
329
  onAnimationsComplete(enterNode, () => {
314
330
  if (nodeMap.get(key) === enterNode) {
315
331
  enterNode.removeAttribute("data-presence");
@@ -466,7 +482,7 @@ function Suspense(props) {
466
482
  }
467
483
  }
468
484
  // src/dialog/dialog-stack.ts
469
- var DialogStackContext = createContext();
485
+ var DialogStackContext = createContext(undefined, "@vertz/ui::DialogStackContext");
470
486
  function useDialogStack() {
471
487
  const stack = useContext(DialogStackContext);
472
488
  if (!stack) {
@@ -605,14 +621,19 @@ function createDialogStack(container) {
605
621
  }
606
622
  }
607
623
  // src/mount.ts
608
- function mount(app, selector, options) {
609
- if (typeof selector !== "string" && !(selector instanceof HTMLElement)) {
610
- throw new Error(`mount(): selector must be a string or HTMLElement, got ${typeof selector}`);
611
- }
612
- const root = typeof selector === "string" ? document.querySelector(selector) : selector;
624
+ var MOUNTED_KEY = Symbol.for("vertz:mounted-roots");
625
+ var _global = globalThis;
626
+ if (!_global[MOUNTED_KEY])
627
+ _global[MOUNTED_KEY] = new WeakMap;
628
+ var mountedRoots = _global[MOUNTED_KEY];
629
+ function mount(app, options) {
630
+ const root = document.getElementById("app");
613
631
  if (!root) {
614
- throw new Error(`mount(): root element "${selector}" not found`);
632
+ throw new Error('mount(): root element "#app" not found');
615
633
  }
634
+ const existingHandle = mountedRoots.get(root);
635
+ if (existingHandle)
636
+ return existingHandle;
616
637
  if (options?.theme) {
617
638
  const { css: css2 } = compileTheme(options.theme);
618
639
  injectCSS(css2);
@@ -630,13 +651,16 @@ function mount(app, selector, options) {
630
651
  endHydration();
631
652
  popScope();
632
653
  options?.onMount?.(root);
633
- return {
654
+ const handle2 = {
634
655
  unmount: () => {
656
+ mountedRoots.delete(root);
635
657
  runCleanups(scope2);
636
658
  root.textContent = "";
637
659
  },
638
660
  root
639
661
  };
662
+ mountedRoots.set(root, handle2);
663
+ return handle2;
640
664
  } catch (e) {
641
665
  endHydration();
642
666
  popScope();
@@ -652,216 +676,48 @@ function mount(app, selector, options) {
652
676
  root.appendChild(appElement);
653
677
  popScope();
654
678
  options?.onMount?.(root);
655
- return {
679
+ const handle = {
656
680
  unmount: () => {
681
+ mountedRoots.delete(root);
657
682
  runCleanups(scope);
658
683
  root.textContent = "";
659
684
  },
660
685
  root
661
686
  };
687
+ mountedRoots.set(root, handle);
688
+ return handle;
662
689
  }
663
- // src/store/merge.ts
664
- function shallowMerge(existing, incoming) {
665
- const result = { ...existing };
666
- for (const key of Object.keys(incoming)) {
667
- const value = incoming[key];
668
- if (value !== undefined) {
669
- result[key] = value;
670
- }
671
- }
672
- return result;
673
- }
674
- function shallowEqual(a, b) {
675
- const keysA = Object.keys(a);
676
- const keysB = Object.keys(b);
677
- if (keysA.length !== keysB.length) {
678
- return false;
679
- }
680
- for (const key of keysA) {
681
- if (a[key] !== b[key]) {
682
- return false;
683
- }
684
- }
685
- return true;
686
- }
687
-
688
- // src/store/query-result-index.ts
689
- class QueryResultIndex {
690
- _indices = new Map;
691
- set(queryKey, ids) {
692
- this._indices.set(queryKey, ids);
693
- }
694
- get(queryKey) {
695
- return this._indices.get(queryKey);
696
- }
697
- removeEntity(entityId) {
698
- for (const [queryKey, ids] of this._indices.entries()) {
699
- const filtered = ids.filter((id) => id !== entityId);
700
- if (filtered.length !== ids.length) {
701
- this._indices.set(queryKey, filtered);
690
+ // src/store/optimistic-handler.ts
691
+ function createOptimisticHandler(store, options) {
692
+ const bus = options?.mutationEventBus ?? getMutationEventBus();
693
+ return {
694
+ apply(meta, mutationId) {
695
+ const { entityType, kind, id, body } = meta;
696
+ if (kind === "update" && id && body) {
697
+ store.applyLayer(entityType, id, mutationId, body);
698
+ return () => store.rollbackLayer(entityType, id, mutationId);
702
699
  }
703
- }
704
- }
705
- clear(queryKey) {
706
- this._indices.delete(queryKey);
707
- }
708
- keys() {
709
- return Array.from(this._indices.keys());
710
- }
711
- }
712
-
713
- // src/store/entity-store.ts
714
- class EntityStore {
715
- _entities = new Map;
716
- _typeListeners = new Map;
717
- _queryIndices = new QueryResultIndex;
718
- constructor(options) {
719
- if (options?.initialData) {
720
- this.hydrate(options.initialData);
721
- }
722
- }
723
- get(type, id) {
724
- const typeMap = this._entities.get(type);
725
- if (typeMap?.has(id)) {
726
- return typeMap.get(id);
727
- }
728
- const sig = signal(undefined);
729
- this._getOrCreateTypeMap(type).set(id, sig);
730
- return sig;
731
- }
732
- getMany(type, ids) {
733
- return computed(() => ids.map((id) => this.get(type, id).value));
734
- }
735
- merge(type, data) {
736
- const items = Array.isArray(data) ? data : [data];
737
- if (items.length === 0) {
738
- return;
739
- }
740
- batch(() => {
741
- for (const item of items) {
742
- const typeMap = this._entities.get(type);
743
- const existing = typeMap?.get(item.id);
744
- if (existing) {
745
- const current = existing.peek();
746
- const merged = shallowMerge(current || {}, item);
747
- if (!shallowEqual(current || {}, merged)) {
748
- untrack(() => {
749
- existing.value = merged;
750
- });
751
- }
752
- } else {
753
- const newSignal = signal(item);
754
- this._getOrCreateTypeMap(type).set(item.id, newSignal);
755
- this._notifyTypeChange(type);
756
- }
700
+ if (kind === "delete" && id) {
701
+ const entitySnapshot = store.get(entityType, id).peek();
702
+ const indexSnapshot = store.queryIndices.snapshotEntity(id);
703
+ store.removeOptimistic(entityType, id, mutationId);
704
+ return () => store.restoreOptimistic(entityType, id, mutationId, entitySnapshot, indexSnapshot);
757
705
  }
758
- });
759
- }
760
- remove(type, id) {
761
- const typeMap = this._entities.get(type);
762
- if (!typeMap?.has(id)) {
763
706
  return;
764
- }
765
- const existing = typeMap.get(id);
766
- if (existing) {
767
- existing.value = undefined;
768
- }
769
- typeMap.delete(id);
770
- this._queryIndices.removeEntity(id);
771
- this._notifyTypeChange(type);
772
- }
773
- onTypeChange(type, callback) {
774
- const listeners = this._getOrCreateListeners(type);
775
- listeners.add(callback);
776
- return () => {
777
- listeners.delete(callback);
778
- };
779
- }
780
- has(type, id) {
781
- const typeMap = this._entities.get(type);
782
- if (!typeMap?.has(id)) {
783
- return false;
784
- }
785
- const signal2 = typeMap.get(id);
786
- return signal2?.peek() !== undefined;
787
- }
788
- size(type) {
789
- const typeMap = this._entities.get(type);
790
- if (!typeMap) {
791
- return 0;
792
- }
793
- let count = 0;
794
- for (const signal2 of typeMap.values()) {
795
- if (signal2.peek() !== undefined) {
796
- count++;
797
- }
798
- }
799
- return count;
800
- }
801
- dehydrate() {
802
- const entities = {};
803
- for (const [type, typeMap] of this._entities.entries()) {
804
- const typeEntities = {};
805
- for (const [id, signal2] of typeMap.entries()) {
806
- const value = signal2.peek();
807
- if (value !== undefined) {
808
- typeEntities[id] = value;
809
- }
707
+ },
708
+ commit(meta, mutationId, data) {
709
+ const { entityType, kind, id } = meta;
710
+ if (kind === "update" && id) {
711
+ store.commitLayer(entityType, id, mutationId, data);
810
712
  }
811
- if (Object.keys(typeEntities).length > 0) {
812
- entities[type] = typeEntities;
713
+ if (kind === "create" && data && typeof data === "object" && "id" in data) {
714
+ store.merge(entityType, data);
813
715
  }
814
- }
815
- const queries = {};
816
- for (const queryKey of this._queryIndices.keys()) {
817
- const ids = this._queryIndices.get(queryKey);
818
- if (ids) {
819
- queries[queryKey] = { ids };
716
+ if (!meta.skipInvalidation) {
717
+ bus.emit(entityType);
820
718
  }
821
719
  }
822
- return {
823
- entities,
824
- ...Object.keys(queries).length > 0 ? { queries } : {}
825
- };
826
- }
827
- hydrate(data) {
828
- for (const [type, typeEntities] of Object.entries(data.entities)) {
829
- const entities = Object.values(typeEntities).map((entity) => ({
830
- ...entity,
831
- id: entity.id
832
- }));
833
- this.merge(type, entities);
834
- }
835
- if (data.queries) {
836
- for (const [queryKey, queryData] of Object.entries(data.queries)) {
837
- this._queryIndices.set(queryKey, queryData.ids);
838
- }
839
- }
840
- }
841
- _getOrCreateTypeMap(type) {
842
- let typeMap = this._entities.get(type);
843
- if (!typeMap) {
844
- typeMap = new Map;
845
- this._entities.set(type, typeMap);
846
- }
847
- return typeMap;
848
- }
849
- _getOrCreateListeners(type) {
850
- let listeners = this._typeListeners.get(type);
851
- if (!listeners) {
852
- listeners = new Set;
853
- this._typeListeners.set(type, listeners);
854
- }
855
- return listeners;
856
- }
857
- _notifyTypeChange(type) {
858
- const listeners = this._typeListeners.get(type);
859
- if (listeners) {
860
- for (const callback of listeners) {
861
- callback();
862
- }
863
- }
864
- }
720
+ };
865
721
  }
866
722
  // src/store/test-utils.ts
867
723
  function createTestStore(data) {
@@ -897,7 +753,9 @@ export {
897
753
  setAdapter,
898
754
  s,
899
755
  resolveChildren,
756
+ resetRelationSchemas_TEST_ONLY,
900
757
  resetInjectedStyles,
758
+ registerRelationSchema,
901
759
  ref,
902
760
  queryMatch,
903
761
  query,
@@ -908,10 +766,14 @@ export {
908
766
  keyframes,
909
767
  isRenderNode,
910
768
  isQueryDescriptor,
769
+ invalidate,
911
770
  injectCSS,
912
771
  hydrate,
913
772
  globalCss,
773
+ getRelationSchema,
774
+ getQueryEnvelopeStore,
914
775
  getInjectedCSS,
776
+ getEntityStore,
915
777
  getAdapter,
916
778
  formDataToObject,
917
779
  form,
@@ -922,6 +784,7 @@ export {
922
784
  css,
923
785
  createTestStore,
924
786
  createRouter,
787
+ createOptimisticHandler,
925
788
  createLink,
926
789
  createFieldState,
927
790
  createDialogStack,
@@ -943,6 +806,7 @@ export {
943
806
  RouterView,
944
807
  RouterContext,
945
808
  RENDER_NODE_BRAND,
809
+ QueryEnvelopeStore,
946
810
  Presence,
947
811
  OutletContext,
948
812
  Outlet,