@tailorkit/client-core 0.1.0-beta.22 → 0.1.0-beta.24

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/dist/{chunk-RNTQ3LLF.js → chunk-BLDTSDUG.js} +195 -123
  2. package/dist/{chunk-K3QITWU4.js → chunk-CWDPTXSZ.js} +22 -113
  3. package/dist/chunk-FUBKKH3Q.js +96 -0
  4. package/dist/chunk-LNGQREZV.js +79 -0
  5. package/dist/chunk-N4X53WS2.js +669 -0
  6. package/dist/chunk-QWOVC765.js +222 -0
  7. package/dist/client/config.d.ts +66 -0
  8. package/dist/client/index.d.ts +7 -0
  9. package/dist/client/primitive-css.d.ts +10 -0
  10. package/dist/client/slot-types.d.ts +61 -0
  11. package/dist/client/value-memo.d.ts +2 -0
  12. package/dist/client/views.d.ts +8 -0
  13. package/dist/client.js +24 -6
  14. package/dist/index.js +48 -16
  15. package/dist/store/fetch/apps.d.ts +1 -0
  16. package/dist/store/fetch/cache.d.ts +3 -1
  17. package/dist/store/fetch/meta.d.ts +1 -0
  18. package/dist/store/fetch/preview-manager.d.ts +1 -0
  19. package/dist/store/fetch/slot.d.ts +1 -0
  20. package/dist/store/index.d.ts +2 -0
  21. package/dist/store/local/index.d.ts +7 -2
  22. package/dist/store/local/node-store.d.ts +2 -0
  23. package/dist/store/local/remote-view.d.ts +31 -0
  24. package/dist/store/local/slot-runtime.d.ts +36 -0
  25. package/dist/store/local/view-context-diagnostics.d.ts +10 -0
  26. package/dist/store/local/view-context-types.d.ts +21 -0
  27. package/dist/store/local/{view-registry.d.ts → view-context.d.ts} +5 -2
  28. package/dist/store/query.d.ts +39 -0
  29. package/dist/store/snapshot-store.d.ts +5 -0
  30. package/dist/store/store.d.ts +4 -1
  31. package/dist/store-fetch.js +5 -4
  32. package/dist/store-local.js +11 -3
  33. package/package.json +6 -5
  34. package/dist/chunk-DPR3U4U2.js +0 -57
  35. package/dist/chunk-ED3BWTXG.js +0 -128
@@ -0,0 +1,79 @@
1
+ import {
2
+ createSlotStore,
3
+ serializeCacheKey
4
+ } from "./chunk-BLDTSDUG.js";
5
+
6
+ // src/client/value-memo.ts
7
+ function createValueMemo() {
8
+ let initialized = false;
9
+ let previousKey;
10
+ let previous;
11
+ return (value) => {
12
+ const key = JSON.stringify(value);
13
+ if (!initialized || previousKey !== key) {
14
+ initialized = true;
15
+ previousKey = key;
16
+ previous = value;
17
+ }
18
+ return previous;
19
+ };
20
+ }
21
+
22
+ // src/client/apps.ts
23
+ function matchesApp(app, scopes, appIds) {
24
+ return (scopes === void 0 || app.scope !== void 0 && scopes.includes(app.scope.name)) && (appIds === void 0 || appIds.includes(app.id));
25
+ }
26
+
27
+ // src/client/scope-query.ts
28
+ function appendScopeSelection(url, scopes) {
29
+ if (scopes === void 0) {
30
+ return;
31
+ }
32
+ if (scopes.length === 0) {
33
+ url.searchParams.append("scopes", "");
34
+ return;
35
+ }
36
+ for (const scope of scopes) {
37
+ url.searchParams.append("scopes", scope);
38
+ }
39
+ }
40
+ function normalizeScopeSelection(scopes) {
41
+ if (scopes === void 0) {
42
+ return { key: "*" };
43
+ }
44
+ const names = [...new Set(scopes)].sort();
45
+ return { key: JSON.stringify(names), scopes: names };
46
+ }
47
+
48
+ // src/client/views.ts
49
+ async function refetchViews(store, { slot, scopes, appIds }) {
50
+ const queryOptions = () => {
51
+ const schema = store.getMetaSnapshot().schema;
52
+ return {
53
+ apps: store.getAppsSnapshot().apps.filter((app) => matchesApp(app, scopes, appIds)),
54
+ slot,
55
+ activeView: schema === null || schema.slots[slot]?.multiple === true ? store.views.getSnapshot() : null
56
+ };
57
+ };
58
+ if (store.getAppsSnapshot().status === "ready" && store.getMetaSnapshot().schema?.slots[slot]?.multiple === true) {
59
+ await createSlotStore(store.client, queryOptions()).fetch({ force: true });
60
+ return;
61
+ }
62
+ await store.fetchApps({ force: true });
63
+ let previousKey;
64
+ while (store.getAppsSnapshot().status === "ready") {
65
+ const options = queryOptions();
66
+ const key = serializeCacheKey([options.apps, slot, options.activeView]);
67
+ if (key === previousKey) return;
68
+ previousKey = key;
69
+ await createSlotStore(store.client, options).fetch();
70
+ }
71
+ }
72
+
73
+ export {
74
+ createValueMemo,
75
+ matchesApp,
76
+ appendScopeSelection,
77
+ normalizeScopeSelection,
78
+ refetchViews
79
+ };