@tailorkit/client-core 0.1.0-beta.23 → 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.
- package/dist/{chunk-RNTQ3LLF.js → chunk-BLDTSDUG.js} +195 -123
- package/dist/{chunk-K3QITWU4.js → chunk-CWDPTXSZ.js} +22 -113
- package/dist/chunk-FUBKKH3Q.js +96 -0
- package/dist/chunk-LNGQREZV.js +79 -0
- package/dist/chunk-N4X53WS2.js +669 -0
- package/dist/chunk-QWOVC765.js +222 -0
- package/dist/client/config.d.ts +66 -0
- package/dist/client/index.d.ts +7 -0
- package/dist/client/primitive-css.d.ts +10 -0
- package/dist/client/slot-types.d.ts +61 -0
- package/dist/client/value-memo.d.ts +2 -0
- package/dist/client/views.d.ts +8 -0
- package/dist/client.js +24 -6
- package/dist/index.js +48 -16
- package/dist/store/fetch/apps.d.ts +1 -0
- package/dist/store/fetch/cache.d.ts +3 -1
- package/dist/store/fetch/meta.d.ts +1 -0
- package/dist/store/fetch/preview-manager.d.ts +1 -0
- package/dist/store/fetch/slot.d.ts +1 -0
- package/dist/store/index.d.ts +2 -0
- package/dist/store/local/index.d.ts +7 -2
- package/dist/store/local/node-store.d.ts +2 -0
- package/dist/store/local/remote-view.d.ts +31 -0
- package/dist/store/local/slot-runtime.d.ts +36 -0
- package/dist/store/local/view-context-diagnostics.d.ts +10 -0
- package/dist/store/local/view-context-types.d.ts +21 -0
- package/dist/store/local/{view-registry.d.ts → view-context.d.ts} +5 -2
- package/dist/store/query.d.ts +39 -0
- package/dist/store/snapshot-store.d.ts +5 -0
- package/dist/store/store.d.ts +4 -1
- package/dist/store-fetch.js +5 -4
- package/dist/store-local.js +11 -3
- package/package.json +6 -5
- package/dist/chunk-DPR3U4U2.js +0 -57
- package/dist/chunk-ED3BWTXG.js +0 -128
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import type { Session, ViewInstance } from "@tailorkit/app/client";
|
|
2
|
+
import type { ViewStatus } from "@tailorkit/core/views";
|
|
3
|
+
import type { RuntimeSlotProps } from "../../client/slot-types";
|
|
4
|
+
import type { TailorKitStore } from "../store";
|
|
5
|
+
export type SlotRuntimeOptions = RuntimeSlotProps & ({
|
|
6
|
+
mode: "managed";
|
|
7
|
+
} | {
|
|
8
|
+
mode: "controlled";
|
|
9
|
+
view: string;
|
|
10
|
+
context?: unknown;
|
|
11
|
+
status: ViewStatus;
|
|
12
|
+
instance?: ViewInstance;
|
|
13
|
+
});
|
|
14
|
+
export type SlotRuntimeSnapshot = {
|
|
15
|
+
status: "hidden";
|
|
16
|
+
} | {
|
|
17
|
+
status: "loading";
|
|
18
|
+
message: string;
|
|
19
|
+
} | {
|
|
20
|
+
status: "error";
|
|
21
|
+
error: Error;
|
|
22
|
+
} | {
|
|
23
|
+
status: "render";
|
|
24
|
+
appUrl: string;
|
|
25
|
+
sourceText?: string;
|
|
26
|
+
hostKey: string | number;
|
|
27
|
+
props: Record<string, unknown>;
|
|
28
|
+
getBackendSession: (options: {
|
|
29
|
+
refresh: boolean;
|
|
30
|
+
}) => Promise<Session>;
|
|
31
|
+
};
|
|
32
|
+
/** Resolve a managed or controlled slot; adapters only render its snapshot. */
|
|
33
|
+
export declare function createSlotRuntime(store: TailorKitStore, initial: SlotRuntimeOptions): {
|
|
34
|
+
state: import("nanostores").ReadableAtom<SlotRuntimeSnapshot>;
|
|
35
|
+
setInput(options: SlotRuntimeOptions): void;
|
|
36
|
+
};
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { TailorKitSchemaSpecType } from "@tailorkit/core/spec";
|
|
2
|
+
import type { ViewEntry } from "./view-context";
|
|
3
|
+
type Definition = TailorKitSchemaSpecType["views"][string];
|
|
4
|
+
interface Diagnostic {
|
|
5
|
+
message: string;
|
|
6
|
+
details?: unknown;
|
|
7
|
+
}
|
|
8
|
+
/** Cache validators by schema identity; metadata refreshes can replace schemas. */
|
|
9
|
+
export declare function createViewContextDiagnostics(): (entry: ViewEntry, definition: Definition | undefined) => Diagnostic | null;
|
|
10
|
+
export {};
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import type { ViewDefinition } from "@tailorkit/core/schema";
|
|
2
|
+
type DefaultViews = Record<`/${string}`, ViewDefinition>;
|
|
3
|
+
export type ViewName<TViews extends Record<string, ViewDefinition>> = keyof TViews & string;
|
|
4
|
+
export type ViewContext<TView> = TView extends ViewDefinition ? NonNullable<TView["~standard"]["types"]>["output"] : Record<string, never>;
|
|
5
|
+
export interface ViewContextState<TContext = unknown> {
|
|
6
|
+
/** The complete context for this view, or undefined while it is unavailable. */
|
|
7
|
+
context: TContext | undefined;
|
|
8
|
+
/** Defaults to false. Loading views do not publish context. */
|
|
9
|
+
loading?: boolean;
|
|
10
|
+
/** Takes precedence over loading. Error views do not publish context. */
|
|
11
|
+
error?: Error | null;
|
|
12
|
+
}
|
|
13
|
+
export type ViewState<TViews extends Record<string, ViewDefinition> = DefaultViews, TView extends ViewName<TViews> = ViewName<TViews>> = ViewContextState<ViewContext<TViews[TView]>>;
|
|
14
|
+
export type ViewOptions<TViews extends Record<string, ViewDefinition> = DefaultViews, TView extends ViewName<TViews> = ViewName<TViews>> = TView extends ViewName<TViews> ? ViewState<TViews, TView> & {
|
|
15
|
+
view: TView;
|
|
16
|
+
} : never;
|
|
17
|
+
export interface ViewContextRegistration<TContext = unknown> extends ViewContextState<TContext> {
|
|
18
|
+
id: symbol;
|
|
19
|
+
view: string;
|
|
20
|
+
}
|
|
21
|
+
export {};
|
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
import type { ActiveView, ViewStatus } from "@tailorkit/core/views";
|
|
2
|
+
import type { TailorKitFetchClient } from "../../client/fetch-client";
|
|
3
|
+
import type { ViewContextRegistration } from "./view-context-types";
|
|
2
4
|
export interface ViewEntry {
|
|
3
5
|
id: symbol;
|
|
4
6
|
view: string;
|
|
@@ -6,10 +8,11 @@ export interface ViewEntry {
|
|
|
6
8
|
status: ViewStatus;
|
|
7
9
|
order: number;
|
|
8
10
|
}
|
|
9
|
-
|
|
11
|
+
/** Own view state and diagnostics independently of any framework adapter. */
|
|
12
|
+
export declare function createViewContextStore(client: TailorKitFetchClient): {
|
|
10
13
|
state: import("nanostores").PreinitializedWritableAtom<ActiveView | null> & object;
|
|
11
14
|
getSnapshot: () => ActiveView | null;
|
|
12
15
|
subscribe: (listener: () => void) => (() => void);
|
|
13
|
-
register(
|
|
16
|
+
register(input: ViewContextRegistration): void;
|
|
14
17
|
unregister(id: symbol): void;
|
|
15
18
|
};
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import type { ReadableAtom } from "nanostores";
|
|
2
|
+
import type { TailorKitApp } from "../types";
|
|
3
|
+
import type { TailorKitStore } from "./store";
|
|
4
|
+
import type { FetchSnapshot } from "./fetch/cache";
|
|
5
|
+
import type { SlotItem } from "./fetch/slot";
|
|
6
|
+
import type { ViewsQueryOptions } from "../client/views";
|
|
7
|
+
export interface AppsQueryOptions<TScopeNames extends string = string> {
|
|
8
|
+
scopes?: readonly TScopeNames[];
|
|
9
|
+
appIds?: readonly string[];
|
|
10
|
+
}
|
|
11
|
+
export interface QueryResult<T> {
|
|
12
|
+
data: T | undefined;
|
|
13
|
+
error: Error | null;
|
|
14
|
+
status: FetchSnapshot<unknown>["status"];
|
|
15
|
+
isFetching: boolean;
|
|
16
|
+
isError: boolean;
|
|
17
|
+
isLoading: boolean;
|
|
18
|
+
isPending: boolean;
|
|
19
|
+
isSuccess: boolean;
|
|
20
|
+
refetch: () => Promise<void>;
|
|
21
|
+
}
|
|
22
|
+
export type ViewsQueryResult<TMultiple extends boolean = boolean> = QueryResult<SlotItem<TMultiple>[]>;
|
|
23
|
+
export declare function appsQueryKey(options: AppsQueryOptions): string;
|
|
24
|
+
/** Discover and filter apps, with the same result shape in every framework. */
|
|
25
|
+
export declare function createAppsQuery(store: TailorKitStore, options?: AppsQueryOptions): {
|
|
26
|
+
state: ReadableAtom<QueryResult<TailorKitApp[]>>;
|
|
27
|
+
refetch: () => Promise<void>;
|
|
28
|
+
fetch: (options?: import("./fetch").FetchOptions) => Promise<void>;
|
|
29
|
+
};
|
|
30
|
+
/** Resolve a slot reactively as discovery, metadata, and registered context change. */
|
|
31
|
+
export declare function createViewsQuery(store: TailorKitStore, options: ViewsQueryOptions): {
|
|
32
|
+
state: ReadableAtom<ViewsQueryResult<boolean>>;
|
|
33
|
+
refetch: () => Promise<void>;
|
|
34
|
+
};
|
|
35
|
+
/** Resolve an explicitly supplied app without initiating discovery. */
|
|
36
|
+
export declare function createAppViewsQuery(store: TailorKitStore, app: TailorKitApp, slot: string): {
|
|
37
|
+
state: ReadableAtom<ViewsQueryResult<boolean>>;
|
|
38
|
+
refetch: () => Promise<void>;
|
|
39
|
+
};
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import type { ReadableAtom } from "nanostores";
|
|
2
|
+
/** Expose cache snapshots as a Nano Store with immediate observer cleanup. */
|
|
3
|
+
export declare function createSnapshotStore<T>(getSnapshot: () => T, subscribe: (listener: () => void) => () => void): ReadableAtom<T>;
|
|
4
|
+
/** Follow a selected store and detach the previous reader immediately. */
|
|
5
|
+
export declare function switchStore<T>(selection: ReadableAtom<ReadableAtom<T>>): ReadableAtom<T>;
|
package/dist/store/store.d.ts
CHANGED
|
@@ -37,19 +37,21 @@ export declare function createTailorKitStore(baseUrl: string | URL, initialApps?
|
|
|
37
37
|
setProvidedApps(apps: TailorKitApp[] | undefined): void;
|
|
38
38
|
updateViews(appId: string, appViews: NonNullable<TailorKitApp["views"]>): void;
|
|
39
39
|
invalidate: () => Promise<void>;
|
|
40
|
+
state: import("nanostores").ReadableAtom<import("./fetch").TailorKitAppsSnapshot>;
|
|
40
41
|
};
|
|
41
42
|
meta: {
|
|
42
43
|
getSnapshot(): import("./fetch").TailorKitMetaSnapshot;
|
|
43
44
|
subscribe: (listener: () => void) => () => void;
|
|
44
45
|
fetch: (options?: import("./fetch").FetchOptions) => Promise<void>;
|
|
45
46
|
invalidate: () => Promise<void>;
|
|
47
|
+
state: import("nanostores").ReadableAtom<import("./fetch").TailorKitMetaSnapshot>;
|
|
46
48
|
};
|
|
47
49
|
};
|
|
48
50
|
views: {
|
|
49
51
|
state: import("nanostores").PreinitializedWritableAtom<import("@tailorkit/core/views").ActiveView | null> & object;
|
|
50
52
|
getSnapshot: () => import("@tailorkit/core/views").ActiveView | null;
|
|
51
53
|
subscribe: (listener: () => void) => (() => void);
|
|
52
|
-
register(
|
|
54
|
+
register(input: import("./local").ViewContextRegistration): void;
|
|
53
55
|
unregister(id: symbol): void;
|
|
54
56
|
};
|
|
55
57
|
setProvidedApps: (apps: TailorKitApp[] | undefined) => void;
|
|
@@ -64,5 +66,6 @@ export declare function createTailorKitStore(baseUrl: string | URL, initialApps?
|
|
|
64
66
|
updateApp: (app: TailorKitApp) => void;
|
|
65
67
|
subscribe: (app: TailorKitApp, listener: () => void) => (() => void);
|
|
66
68
|
dispose: () => void;
|
|
69
|
+
getStore(getApp: () => TailorKitApp): import("nanostores").ReadableAtom<import("./fetch").PreviewSnapshot>;
|
|
67
70
|
};
|
|
68
71
|
};
|
package/dist/store-fetch.js
CHANGED
|
@@ -1,13 +1,14 @@
|
|
|
1
1
|
import {
|
|
2
2
|
createAppsStore,
|
|
3
3
|
createMetadataStore,
|
|
4
|
-
createPreviewManager
|
|
5
|
-
|
|
6
|
-
|
|
4
|
+
createPreviewManager
|
|
5
|
+
} from "./chunk-CWDPTXSZ.js";
|
|
6
|
+
import "./chunk-FUBKKH3Q.js";
|
|
7
7
|
import {
|
|
8
8
|
createFetchCache,
|
|
9
|
+
createSlotStore,
|
|
9
10
|
serializeCacheKey
|
|
10
|
-
} from "./chunk-
|
|
11
|
+
} from "./chunk-BLDTSDUG.js";
|
|
11
12
|
export {
|
|
12
13
|
createAppsStore,
|
|
13
14
|
createFetchCache,
|
package/dist/store-local.js
CHANGED
|
@@ -1,8 +1,16 @@
|
|
|
1
1
|
import {
|
|
2
2
|
NodeStore,
|
|
3
|
-
|
|
4
|
-
|
|
3
|
+
createRemoteElementProps,
|
|
4
|
+
createRemoteViewStore,
|
|
5
|
+
createSlotRuntime,
|
|
6
|
+
createViewContextStore
|
|
7
|
+
} from "./chunk-N4X53WS2.js";
|
|
8
|
+
import "./chunk-LNGQREZV.js";
|
|
9
|
+
import "./chunk-BLDTSDUG.js";
|
|
5
10
|
export {
|
|
6
11
|
NodeStore,
|
|
7
|
-
|
|
12
|
+
createRemoteElementProps,
|
|
13
|
+
createRemoteViewStore,
|
|
14
|
+
createSlotRuntime,
|
|
15
|
+
createViewContextStore
|
|
8
16
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tailorkit/client-core",
|
|
3
|
-
"version": "0.1.0-beta.
|
|
3
|
+
"version": "0.1.0-beta.24",
|
|
4
4
|
"license": "Apache-2.0",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -34,10 +34,11 @@
|
|
|
34
34
|
"access": "public"
|
|
35
35
|
},
|
|
36
36
|
"dependencies": {
|
|
37
|
-
"@
|
|
38
|
-
"@tailorkit/
|
|
39
|
-
"@tailorkit/
|
|
40
|
-
"@tailorkit/
|
|
37
|
+
"@nanostores/async": "0.1.0",
|
|
38
|
+
"@tailorkit/app": "0.1.0-beta.24",
|
|
39
|
+
"@tailorkit/client-platform": "0.1.0-beta.24",
|
|
40
|
+
"@tailorkit/core": "0.1.0-beta.24",
|
|
41
|
+
"@tailorkit/sandbox": "0.1.0-beta.24",
|
|
41
42
|
"nanostores": "1.5.4"
|
|
42
43
|
},
|
|
43
44
|
"devDependencies": {
|
package/dist/chunk-DPR3U4U2.js
DELETED
|
@@ -1,57 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
createEndpointClient,
|
|
3
|
-
createFetchCache
|
|
4
|
-
} from "./chunk-RNTQ3LLF.js";
|
|
5
|
-
|
|
6
|
-
// src/client/fetch-client.ts
|
|
7
|
-
function createTailorKitFetchClient(options) {
|
|
8
|
-
const endpoints = createEndpointClient(options);
|
|
9
|
-
const cache = createFetchCache(options.cache);
|
|
10
|
-
const baseUrl = endpoints.baseUrl;
|
|
11
|
-
const prefix = ["tailorkit", baseUrl.toString()];
|
|
12
|
-
return {
|
|
13
|
-
baseUrl,
|
|
14
|
-
endpoints,
|
|
15
|
-
cache,
|
|
16
|
-
cacheOptions: options.cache,
|
|
17
|
-
apps: (settings = {}) => cache.getStore([...prefix, "apps"], endpoints.apps, { ...options.cache?.apps, ...settings }),
|
|
18
|
-
meta: (settings = {}) => cache.getStore([...prefix, "meta"], endpoints.meta, { ...options.cache?.meta, ...settings }),
|
|
19
|
-
clear() {
|
|
20
|
-
cache.clear();
|
|
21
|
-
endpoints.clearSessions();
|
|
22
|
-
}
|
|
23
|
-
};
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
// src/client/apps.ts
|
|
27
|
-
function matchesApp(app, scopes, appIds) {
|
|
28
|
-
return (scopes === void 0 || app.scope !== void 0 && scopes.includes(app.scope.name)) && (appIds === void 0 || appIds.includes(app.id));
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
// src/client/scope-query.ts
|
|
32
|
-
function appendScopeSelection(url, scopes) {
|
|
33
|
-
if (scopes === void 0) {
|
|
34
|
-
return;
|
|
35
|
-
}
|
|
36
|
-
if (scopes.length === 0) {
|
|
37
|
-
url.searchParams.append("scopes", "");
|
|
38
|
-
return;
|
|
39
|
-
}
|
|
40
|
-
for (const scope of scopes) {
|
|
41
|
-
url.searchParams.append("scopes", scope);
|
|
42
|
-
}
|
|
43
|
-
}
|
|
44
|
-
function normalizeScopeSelection(scopes) {
|
|
45
|
-
if (scopes === void 0) {
|
|
46
|
-
return { key: "*" };
|
|
47
|
-
}
|
|
48
|
-
const names = [...new Set(scopes)].sort();
|
|
49
|
-
return { key: JSON.stringify(names), scopes: names };
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
export {
|
|
53
|
-
createTailorKitFetchClient,
|
|
54
|
-
matchesApp,
|
|
55
|
-
appendScopeSelection,
|
|
56
|
-
normalizeScopeSelection
|
|
57
|
-
};
|
package/dist/chunk-ED3BWTXG.js
DELETED
|
@@ -1,128 +0,0 @@
|
|
|
1
|
-
// src/store/local/node-store.ts
|
|
2
|
-
import { atom, computed } from "nanostores";
|
|
3
|
-
var childIds = (children) => children.map((c) => c.id).join(",");
|
|
4
|
-
var nodeSignature = (node) => {
|
|
5
|
-
if (node.kind === "text") {
|
|
6
|
-
return `text:${node.text}`;
|
|
7
|
-
}
|
|
8
|
-
if (node.kind === "fragment") {
|
|
9
|
-
return `frag:${childIds(node.children)}`;
|
|
10
|
-
}
|
|
11
|
-
const propsStr = JSON.stringify(node.props);
|
|
12
|
-
const callbacksStr = (node.callbacks ?? []).map((binding) => `${binding.callback}:${binding.event}:${binding.inputCount}`).join(",");
|
|
13
|
-
return `elem:${node.type}|${childIds(node.children)}|${propsStr}|${callbacksStr}`;
|
|
14
|
-
};
|
|
15
|
-
var flattenTree = (node, out) => {
|
|
16
|
-
out.set(node.id, node);
|
|
17
|
-
if (node.kind === "text") {
|
|
18
|
-
return;
|
|
19
|
-
}
|
|
20
|
-
for (const child of node.children) {
|
|
21
|
-
flattenTree(child, out);
|
|
22
|
-
}
|
|
23
|
-
};
|
|
24
|
-
var NodeStore = class {
|
|
25
|
-
state = atom({ nodes: /* @__PURE__ */ new Map(), rootId: null });
|
|
26
|
-
signatures = /* @__PURE__ */ new Map();
|
|
27
|
-
clear() {
|
|
28
|
-
this.signatures.clear();
|
|
29
|
-
this.state.set({ nodes: /* @__PURE__ */ new Map(), rootId: null });
|
|
30
|
-
}
|
|
31
|
-
setSnapshot(tree) {
|
|
32
|
-
const previous = this.state.get();
|
|
33
|
-
const next = /* @__PURE__ */ new Map();
|
|
34
|
-
flattenTree(tree, next);
|
|
35
|
-
let changed = previous.rootId !== tree.id || previous.nodes.size !== next.size;
|
|
36
|
-
for (const [id, node] of next) {
|
|
37
|
-
const signature = nodeSignature(node);
|
|
38
|
-
const previousNode = previous.nodes.get(id);
|
|
39
|
-
if (previousNode && this.signatures.get(id) === signature) {
|
|
40
|
-
next.set(id, previousNode);
|
|
41
|
-
} else {
|
|
42
|
-
changed = true;
|
|
43
|
-
this.signatures.set(id, signature);
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
for (const id of this.signatures.keys()) {
|
|
47
|
-
if (!next.has(id)) {
|
|
48
|
-
this.signatures.delete(id);
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
|
-
if (changed) {
|
|
52
|
-
this.state.set({ nodes: next, rootId: tree.id });
|
|
53
|
-
}
|
|
54
|
-
}
|
|
55
|
-
getRootId() {
|
|
56
|
-
return this.state.get().rootId;
|
|
57
|
-
}
|
|
58
|
-
getNode(id) {
|
|
59
|
-
return this.state.get().nodes.get(id) ?? null;
|
|
60
|
-
}
|
|
61
|
-
subscribe(id, listener) {
|
|
62
|
-
const node = computed(this.state, (snapshot) => snapshot.nodes.get(id) ?? null);
|
|
63
|
-
return node.listen(listener);
|
|
64
|
-
}
|
|
65
|
-
subscribeRoot(listener) {
|
|
66
|
-
const root = computed(this.state, (snapshot) => snapshot.rootId);
|
|
67
|
-
return root.listen(listener);
|
|
68
|
-
}
|
|
69
|
-
};
|
|
70
|
-
|
|
71
|
-
// src/store/local/view-registry.ts
|
|
72
|
-
import { atom as atom2 } from "nanostores";
|
|
73
|
-
import { getViewDepth, isViewAncestor } from "@tailorkit/core/views";
|
|
74
|
-
function createViewRegistry() {
|
|
75
|
-
const entries = /* @__PURE__ */ new Map();
|
|
76
|
-
const state = atom2(null);
|
|
77
|
-
let nextOrder = 0;
|
|
78
|
-
let scheduled = false;
|
|
79
|
-
const publish = () => {
|
|
80
|
-
if (scheduled) {
|
|
81
|
-
return;
|
|
82
|
-
}
|
|
83
|
-
scheduled = true;
|
|
84
|
-
queueMicrotask(() => {
|
|
85
|
-
scheduled = false;
|
|
86
|
-
const ordered = [...entries.values()].toSorted(
|
|
87
|
-
(a, b) => getViewDepth(b.view) - getViewDepth(a.view) || b.order - a.order
|
|
88
|
-
);
|
|
89
|
-
const selected = ordered[0];
|
|
90
|
-
if (selected) {
|
|
91
|
-
const peers = ordered.filter(
|
|
92
|
-
(entry) => getViewDepth(entry.view) === getViewDepth(selected.view)
|
|
93
|
-
);
|
|
94
|
-
if (peers.length > 1) {
|
|
95
|
-
console.warn(
|
|
96
|
-
`TailorKit found multiple active views at the same hierarchy depth: ${peers.toReversed().map((entry) => `"${entry.view}"`).join(
|
|
97
|
-
", "
|
|
98
|
-
)}. TailorKit selected "${selected.view}" by mount order. Only one route at a hierarchy depth should register a view.`
|
|
99
|
-
);
|
|
100
|
-
}
|
|
101
|
-
state.set({
|
|
102
|
-
view: selected.view,
|
|
103
|
-
layers: ordered.filter((entry) => isViewAncestor(entry.view, selected.view)).toReversed().map((entry) => ({ path: entry.view, context: entry.context, status: entry.status }))
|
|
104
|
-
});
|
|
105
|
-
} else {
|
|
106
|
-
state.set(null);
|
|
107
|
-
}
|
|
108
|
-
});
|
|
109
|
-
};
|
|
110
|
-
return {
|
|
111
|
-
state,
|
|
112
|
-
getSnapshot: () => state.get(),
|
|
113
|
-
subscribe: (listener) => state.listen(listener),
|
|
114
|
-
register(entry) {
|
|
115
|
-
entries.set(entry.id, { ...entry, order: entries.get(entry.id)?.order ?? nextOrder++ });
|
|
116
|
-
publish();
|
|
117
|
-
},
|
|
118
|
-
unregister(id) {
|
|
119
|
-
entries.delete(id);
|
|
120
|
-
publish();
|
|
121
|
-
}
|
|
122
|
-
};
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
export {
|
|
126
|
-
createViewRegistry,
|
|
127
|
-
NodeStore
|
|
128
|
-
};
|