@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,222 @@
|
|
|
1
|
+
import {
|
|
2
|
+
createEndpointClient
|
|
3
|
+
} from "./chunk-FUBKKH3Q.js";
|
|
4
|
+
import {
|
|
5
|
+
createFetchCache
|
|
6
|
+
} from "./chunk-BLDTSDUG.js";
|
|
7
|
+
|
|
8
|
+
// src/client/fetch-client.ts
|
|
9
|
+
function createTailorKitFetchClient(options) {
|
|
10
|
+
const endpoints = createEndpointClient(options);
|
|
11
|
+
const cache = createFetchCache(options.cache);
|
|
12
|
+
const baseUrl = endpoints.baseUrl;
|
|
13
|
+
const prefix = ["tailorkit", baseUrl.toString()];
|
|
14
|
+
return {
|
|
15
|
+
baseUrl,
|
|
16
|
+
endpoints,
|
|
17
|
+
cache,
|
|
18
|
+
cacheOptions: options.cache,
|
|
19
|
+
apps: (settings = {}) => cache.getStore([...prefix, "apps"], endpoints.apps, { ...options.cache?.apps, ...settings }),
|
|
20
|
+
meta: (settings = {}) => cache.getStore([...prefix, "meta"], endpoints.meta, { ...options.cache?.meta, ...settings }),
|
|
21
|
+
clear() {
|
|
22
|
+
cache.clear();
|
|
23
|
+
endpoints.clearSessions();
|
|
24
|
+
}
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
// src/client/config.ts
|
|
29
|
+
var componentTagPrefix = "tailorkit-";
|
|
30
|
+
var toComponentTagName = (name) => `${componentTagPrefix}${name.replaceAll(/([a-z0-9])([A-Z])/gu, "$1-$2").replaceAll(/[\s_]+/gu, "-").toLowerCase()}`;
|
|
31
|
+
function createTailorKitClientConfig(options) {
|
|
32
|
+
return {
|
|
33
|
+
baseUrl: options.baseUrl,
|
|
34
|
+
fetchClient: createTailorKitFetchClient(options),
|
|
35
|
+
components: options.components ?? {},
|
|
36
|
+
theme: options.theme ?? {}
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
function createComponentRegistry(renderers, wrap) {
|
|
40
|
+
const components = {};
|
|
41
|
+
for (const [name, renderer] of Object.entries(renderers)) {
|
|
42
|
+
if (renderer) {
|
|
43
|
+
const component = wrap(renderer);
|
|
44
|
+
components[name] = component;
|
|
45
|
+
components[toComponentTagName(name)] = component;
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
return components;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
// src/client/primitive-css.ts
|
|
52
|
+
import { resolveTheme } from "@tailorkit/core/primitives/theme";
|
|
53
|
+
var tokenGroups = [
|
|
54
|
+
"space",
|
|
55
|
+
"radius",
|
|
56
|
+
"background",
|
|
57
|
+
"border",
|
|
58
|
+
"borderColor",
|
|
59
|
+
"textColor"
|
|
60
|
+
];
|
|
61
|
+
var cssEscape = (value) => {
|
|
62
|
+
const css = globalThis.CSS;
|
|
63
|
+
if (typeof css?.escape === "function") {
|
|
64
|
+
return css.escape(value);
|
|
65
|
+
}
|
|
66
|
+
return value.replaceAll(/[^A-Za-z0-9_-]/gu, "\\$&");
|
|
67
|
+
};
|
|
68
|
+
var toCssValue = (group, value) => {
|
|
69
|
+
if (typeof value === "number") {
|
|
70
|
+
return `${value}px`;
|
|
71
|
+
}
|
|
72
|
+
if (group === "size" || group === "raw") {
|
|
73
|
+
return value;
|
|
74
|
+
}
|
|
75
|
+
return `var(--tailorkit-${group}-${cssEscape(value)})`;
|
|
76
|
+
};
|
|
77
|
+
var toResponsiveEntries = (value) => {
|
|
78
|
+
if (value === void 0) {
|
|
79
|
+
return [];
|
|
80
|
+
}
|
|
81
|
+
if (!(value && typeof value === "object") || Array.isArray(value)) {
|
|
82
|
+
return [["base", value]];
|
|
83
|
+
}
|
|
84
|
+
return Object.entries(value).filter(
|
|
85
|
+
(entry) => entry[1] !== void 0
|
|
86
|
+
);
|
|
87
|
+
};
|
|
88
|
+
var declarationsForProp = (prop, value) => {
|
|
89
|
+
if (prop === "columns") {
|
|
90
|
+
return [`grid-template-columns: repeat(${String(value)}, minmax(0, 1fr));`];
|
|
91
|
+
}
|
|
92
|
+
const tokenDeclarations = {
|
|
93
|
+
background: ["background", "background"],
|
|
94
|
+
border: ["border", "border"],
|
|
95
|
+
borderColor: ["borderColor", "border-color"],
|
|
96
|
+
textColor: ["textColor", "color"]
|
|
97
|
+
};
|
|
98
|
+
const tokenDeclaration = tokenDeclarations[prop];
|
|
99
|
+
if (tokenDeclaration) {
|
|
100
|
+
const [group, property] = tokenDeclaration;
|
|
101
|
+
if (prop === "border") {
|
|
102
|
+
return [`border-style: ${toCssValue(group, value)};`, "border-width: 1px;"];
|
|
103
|
+
}
|
|
104
|
+
return [`${property}: ${toCssValue(group, value)};`];
|
|
105
|
+
}
|
|
106
|
+
if (prop === "gap" || prop === "margin" || prop === "padding") {
|
|
107
|
+
return [`${prop}: ${toCssValue("space", value)};`];
|
|
108
|
+
}
|
|
109
|
+
if (prop === "height" || prop === "width") {
|
|
110
|
+
return [`${prop}: ${toCssValue("size", value)};`];
|
|
111
|
+
}
|
|
112
|
+
if (prop === "radius") {
|
|
113
|
+
return [`border-radius: ${toCssValue("radius", value)};`];
|
|
114
|
+
}
|
|
115
|
+
if (prop === "align") {
|
|
116
|
+
return [`align-items: ${toFlexAlignment(value)};`];
|
|
117
|
+
}
|
|
118
|
+
if (prop === "justify") {
|
|
119
|
+
return [`justify-content: ${toFlexJustification(value)};`];
|
|
120
|
+
}
|
|
121
|
+
if (prop === "direction") {
|
|
122
|
+
return [`flex-direction: ${toCssValue("raw", value)};`];
|
|
123
|
+
}
|
|
124
|
+
if (prop === "overflow") {
|
|
125
|
+
return [`overflow: ${toCssValue("raw", value)};`];
|
|
126
|
+
}
|
|
127
|
+
if (prop === "grow") {
|
|
128
|
+
return [`flex-grow: ${String(value)};`];
|
|
129
|
+
}
|
|
130
|
+
if (prop === "shrink") {
|
|
131
|
+
return [`flex-shrink: ${String(value)};`];
|
|
132
|
+
}
|
|
133
|
+
if (prop === "minHeight") {
|
|
134
|
+
return [`min-height: ${toCssValue("size", value)};`];
|
|
135
|
+
}
|
|
136
|
+
if (prop === "minWidth") {
|
|
137
|
+
return [`min-width: ${toCssValue("size", value)};`];
|
|
138
|
+
}
|
|
139
|
+
if (prop === "basis") {
|
|
140
|
+
return [`flex-basis: ${toCssValue("size", value)};`];
|
|
141
|
+
}
|
|
142
|
+
if (prop === "wrap") {
|
|
143
|
+
return [`flex-wrap: ${toCssValue("raw", value)};`];
|
|
144
|
+
}
|
|
145
|
+
return [];
|
|
146
|
+
};
|
|
147
|
+
var toFlexAlignment = (value) => {
|
|
148
|
+
if (value === "start") {
|
|
149
|
+
return "flex-start";
|
|
150
|
+
}
|
|
151
|
+
if (value === "end") {
|
|
152
|
+
return "flex-end";
|
|
153
|
+
}
|
|
154
|
+
return String(value);
|
|
155
|
+
};
|
|
156
|
+
var toFlexJustification = (value) => {
|
|
157
|
+
if (value === "start") {
|
|
158
|
+
return "flex-start";
|
|
159
|
+
}
|
|
160
|
+
if (value === "end") {
|
|
161
|
+
return "flex-end";
|
|
162
|
+
}
|
|
163
|
+
if (value === "between") {
|
|
164
|
+
return "space-between";
|
|
165
|
+
}
|
|
166
|
+
return String(value);
|
|
167
|
+
};
|
|
168
|
+
var buildPrimitiveCss = ({
|
|
169
|
+
display,
|
|
170
|
+
nodeId,
|
|
171
|
+
props,
|
|
172
|
+
viewId,
|
|
173
|
+
theme
|
|
174
|
+
}) => {
|
|
175
|
+
const selector = `[data-tailorkit-view="${cssEscape(viewId)}"] [data-tailorkit-node="${cssEscape(
|
|
176
|
+
nodeId
|
|
177
|
+
)}"]`;
|
|
178
|
+
const base = [`display: ${display};`];
|
|
179
|
+
const byBreakpoint = /* @__PURE__ */ new Map();
|
|
180
|
+
for (const [prop, rawValue] of Object.entries(props)) {
|
|
181
|
+
for (const [breakpoint, value] of toResponsiveEntries(rawValue)) {
|
|
182
|
+
const declarations = declarationsForProp(prop, value);
|
|
183
|
+
if (declarations.length === 0) {
|
|
184
|
+
continue;
|
|
185
|
+
}
|
|
186
|
+
const target = breakpoint === "base" ? base : byBreakpoint.get(breakpoint) ?? [];
|
|
187
|
+
target.push(...declarations);
|
|
188
|
+
if (breakpoint !== "base") {
|
|
189
|
+
byBreakpoint.set(breakpoint, target);
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
const rules = [`${selector} { ${base.join(" ")} }`];
|
|
194
|
+
for (const [breakpoint, declarations] of byBreakpoint) {
|
|
195
|
+
const minWidth = theme.breakpoints?.[breakpoint];
|
|
196
|
+
if (!minWidth) {
|
|
197
|
+
continue;
|
|
198
|
+
}
|
|
199
|
+
rules.push(`@media (min-width: ${minWidth}) { ${selector} { ${declarations.join(" ")} } }`);
|
|
200
|
+
}
|
|
201
|
+
return rules.join("\n");
|
|
202
|
+
};
|
|
203
|
+
var buildThemeCss = (viewId, theme) => {
|
|
204
|
+
const selector = `[data-tailorkit-view="${cssEscape(viewId)}"]`;
|
|
205
|
+
const declarations = [];
|
|
206
|
+
const resolvedTheme = resolveTheme(theme);
|
|
207
|
+
for (const group of tokenGroups) {
|
|
208
|
+
for (const [name, value] of Object.entries(resolvedTheme.tokens?.[group] ?? {})) {
|
|
209
|
+
declarations.push(`--tailorkit-${group}-${cssEscape(name)}: ${value};`);
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
return `${selector} { ${declarations.join(" ")} }`;
|
|
213
|
+
};
|
|
214
|
+
|
|
215
|
+
export {
|
|
216
|
+
createTailorKitFetchClient,
|
|
217
|
+
toComponentTagName,
|
|
218
|
+
createTailorKitClientConfig,
|
|
219
|
+
createComponentRegistry,
|
|
220
|
+
buildPrimitiveCss,
|
|
221
|
+
buildThemeCss
|
|
222
|
+
};
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import type { TailorKitTheme, CallbackMap, ComponentDefinition, ComponentProps, Schema, ViewDefinition, SlotDefinitions } from "@tailorkit/core/schema";
|
|
2
|
+
import type { TailorKitFetchClient, TailorKitCacheOptions } from "./fetch-client";
|
|
3
|
+
export type AnyComponentDefinition = ComponentDefinition<Schema | undefined, CallbackMap, boolean | undefined>;
|
|
4
|
+
export type ComponentRenderer<TComponent extends AnyComponentDefinition, TNode> = (args: {
|
|
5
|
+
props: ComponentProps<TComponent>;
|
|
6
|
+
children?: TComponent extends {
|
|
7
|
+
children: true;
|
|
8
|
+
} ? TNode : never;
|
|
9
|
+
}) => TNode;
|
|
10
|
+
export type ComponentRenderers<TComponents extends Record<string, AnyComponentDefinition>, TNode> = {
|
|
11
|
+
[TName in keyof TComponents]?: ComponentRenderer<TComponents[TName], TNode>;
|
|
12
|
+
};
|
|
13
|
+
export type CompleteComponentRenderers<TComponents extends Record<string, AnyComponentDefinition>, TNode> = {
|
|
14
|
+
[TName in keyof TComponents]-?: ComponentRenderer<TComponents[TName], TNode>;
|
|
15
|
+
};
|
|
16
|
+
export declare const toComponentTagName: (name: string) => string;
|
|
17
|
+
export interface TailorKitClientConfig {
|
|
18
|
+
readonly baseUrl: string | URL;
|
|
19
|
+
readonly fetchClient?: TailorKitFetchClient;
|
|
20
|
+
readonly components: Record<string, unknown>;
|
|
21
|
+
readonly theme: TailorKitTheme;
|
|
22
|
+
}
|
|
23
|
+
export type SlotMultiple<TSlot> = TSlot extends {
|
|
24
|
+
multiple: infer TMultiple extends boolean;
|
|
25
|
+
} ? TMultiple : TSlot extends {
|
|
26
|
+
multiple?: infer TMultiple extends boolean;
|
|
27
|
+
} ? TMultiple | false : false;
|
|
28
|
+
export interface TailorKitServerShape {
|
|
29
|
+
$internal: {
|
|
30
|
+
schema: {
|
|
31
|
+
components: Record<string, unknown>;
|
|
32
|
+
views: Record<string, unknown>;
|
|
33
|
+
};
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
type ServerComponentMap<TTailor extends TailorKitServerShape> = TTailor["$internal"]["schema"]["components"];
|
|
37
|
+
export type ServerComponents<TTailor extends TailorKitServerShape> = {
|
|
38
|
+
[TName in keyof ServerComponentMap<TTailor>]: ServerComponentMap<TTailor>[TName] extends AnyComponentDefinition ? ServerComponentMap<TTailor>[TName] : never;
|
|
39
|
+
};
|
|
40
|
+
type ServerViewMap<TTailor extends TailorKitServerShape> = TTailor["$internal"]["schema"]["views"];
|
|
41
|
+
export type ServerScopeNames<TTailor extends TailorKitServerShape> = TTailor extends {
|
|
42
|
+
handler: (request: Request, options: infer TOptions) => unknown;
|
|
43
|
+
} ? TOptions extends {
|
|
44
|
+
authenticate: infer TAuthenticate;
|
|
45
|
+
} ? TAuthenticate extends (...args: infer _TArgs) => infer TResult ? Extract<Awaited<TResult>, {
|
|
46
|
+
scopes: unknown;
|
|
47
|
+
}> extends {
|
|
48
|
+
scopes: infer TScopes;
|
|
49
|
+
} ? keyof TScopes & string : never : never : never : never;
|
|
50
|
+
export type ServerViews<TTailor extends TailorKitServerShape> = {
|
|
51
|
+
[TName in keyof ServerViewMap<TTailor>]: ServerViewMap<TTailor>[TName] extends ViewDefinition ? ServerViewMap<TTailor>[TName] : never;
|
|
52
|
+
};
|
|
53
|
+
export type ServerSlots<TTailor> = TTailor extends {
|
|
54
|
+
readonly $slots?: infer V extends SlotDefinitions;
|
|
55
|
+
} ? V : SlotDefinitions;
|
|
56
|
+
/** Build framework-independent client configuration after an adapter wraps its renderers. */
|
|
57
|
+
export declare function createTailorKitClientConfig(options: {
|
|
58
|
+
baseUrl: string | URL;
|
|
59
|
+
components?: Record<string, unknown>;
|
|
60
|
+
theme?: TailorKitTheme;
|
|
61
|
+
cache?: TailorKitCacheOptions;
|
|
62
|
+
fetch?: typeof fetch;
|
|
63
|
+
}): TailorKitClientConfig;
|
|
64
|
+
/** Register schema names and their remote element aliases with the same wrapped renderer. */
|
|
65
|
+
export declare function createComponentRegistry<T extends Record<string, unknown>, TRenderer>(renderers: T, wrap: (renderer: NonNullable<T[keyof T]>) => TRenderer): Record<string, TRenderer>;
|
|
66
|
+
export {};
|
package/dist/client/index.d.ts
CHANGED
|
@@ -6,3 +6,10 @@ export { toBaseUrl } from "./url";
|
|
|
6
6
|
export { matchesApp } from "./apps";
|
|
7
7
|
export { normalizeScopeSelection, appendScopeSelection } from "./scope-query";
|
|
8
8
|
export { resolveSlotView, selectSlotView } from "./slot-view";
|
|
9
|
+
export { refetchViews } from "./views";
|
|
10
|
+
export type { ViewsQueryOptions } from "./views";
|
|
11
|
+
export * from "./config";
|
|
12
|
+
export * from "./slot-types";
|
|
13
|
+
export { buildPrimitiveCss, buildThemeCss } from "./primitive-css";
|
|
14
|
+
export type { PrimitiveProps } from "./primitive-css";
|
|
15
|
+
export { createValueMemo } from "./value-memo";
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { TailorKitTheme } from "@tailorkit/core/schema";
|
|
2
|
+
export type PrimitiveProps = Record<string, unknown>;
|
|
3
|
+
export declare const buildPrimitiveCss: ({ display, nodeId, props, viewId, theme, }: {
|
|
4
|
+
display: "block" | "flex" | "grid" | "inline";
|
|
5
|
+
nodeId: string;
|
|
6
|
+
props: PrimitiveProps;
|
|
7
|
+
viewId: string;
|
|
8
|
+
theme: TailorKitTheme;
|
|
9
|
+
}) => string;
|
|
10
|
+
export declare const buildThemeCss: (viewId: string, theme: TailorKitTheme) => string;
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import type { ViewInstance } from "@tailorkit/app/client";
|
|
2
|
+
import type { SlotDefinitions, ViewDefinition } from "@tailorkit/core/schema";
|
|
3
|
+
import type { ActiveView, ViewStatus } from "@tailorkit/core/views";
|
|
4
|
+
import type { TailorKitApp } from "../types";
|
|
5
|
+
import type { ViewContext, ViewName } from "../store/local/view-context-types";
|
|
6
|
+
type DefaultViews = Record<`/${string}`, ViewDefinition>;
|
|
7
|
+
type ContextPaths<TViews extends Record<string, ViewDefinition>, TView extends ViewName<TViews>> = {
|
|
8
|
+
[P in ViewName<TViews>]: P extends "/" | TView ? P : TView extends `${P}/${string}` ? P : never;
|
|
9
|
+
}[ViewName<TViews>];
|
|
10
|
+
type ContextFields<TView> = undefined extends ViewContext<TView> ? Partial<Exclude<ViewContext<TView>, undefined>> : ViewContext<TView>;
|
|
11
|
+
export type SlotContext<TViews extends Record<string, ViewDefinition>, TView extends ViewName<TViews>> = {
|
|
12
|
+
[P in ContextPaths<TViews, TView>]: (context: ContextFields<TViews[P]>) => void;
|
|
13
|
+
}[ContextPaths<TViews, TView>] extends (context: infer TContext) => void ? TContext : never;
|
|
14
|
+
export interface RuntimeSlotProps {
|
|
15
|
+
app: TailorKitApp;
|
|
16
|
+
/** The host slot to render in. */
|
|
17
|
+
name: string;
|
|
18
|
+
/** Select an instance of the matching view. */
|
|
19
|
+
instanceKey?: string;
|
|
20
|
+
}
|
|
21
|
+
type InstanceProps<TSlot, TKey extends string, TValue> = boolean extends (TSlot extends {
|
|
22
|
+
multiple?: infer T;
|
|
23
|
+
} ? T : false) ? {
|
|
24
|
+
[K in TKey]?: TValue;
|
|
25
|
+
} : TSlot extends {
|
|
26
|
+
multiple: true;
|
|
27
|
+
} ? {
|
|
28
|
+
[K in TKey]: TValue;
|
|
29
|
+
} : {
|
|
30
|
+
[K in TKey]?: never;
|
|
31
|
+
};
|
|
32
|
+
export type SlotProps<TSlots extends SlotDefinitions = SlotDefinitions> = {
|
|
33
|
+
[TSlot in keyof TSlots & string]: {
|
|
34
|
+
app: TailorKitApp;
|
|
35
|
+
name: TSlot;
|
|
36
|
+
} & InstanceProps<TSlots[TSlot], "instanceKey", string>;
|
|
37
|
+
}[keyof TSlots & string];
|
|
38
|
+
export type ControlledSlotProps<TViews extends Record<string, ViewDefinition> = DefaultViews, TSlots extends SlotDefinitions = SlotDefinitions> = {
|
|
39
|
+
[TSlot in keyof TSlots & string]: {
|
|
40
|
+
[TView in Extract<ViewName<TViews>, TSlots[TSlot]["views"][number]>]: {
|
|
41
|
+
app: TailorKitApp;
|
|
42
|
+
name: TSlot;
|
|
43
|
+
view: TView;
|
|
44
|
+
} & (({
|
|
45
|
+
context: SlotContext<TViews, TView>;
|
|
46
|
+
status: "ready";
|
|
47
|
+
} & InstanceProps<TSlots[TSlot], "instance", ViewInstance>) | {
|
|
48
|
+
context?: never;
|
|
49
|
+
status: "loading" | "error";
|
|
50
|
+
instance?: never;
|
|
51
|
+
});
|
|
52
|
+
}[Extract<ViewName<TViews>, TSlots[TSlot]["views"][number]>];
|
|
53
|
+
}[keyof TSlots & string];
|
|
54
|
+
export type SlotState = ActiveView | {
|
|
55
|
+
view: string;
|
|
56
|
+
controlled: true;
|
|
57
|
+
context?: unknown;
|
|
58
|
+
status: ViewStatus;
|
|
59
|
+
instance?: ViewInstance;
|
|
60
|
+
};
|
|
61
|
+
export {};
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { TailorKitStore } from "../store/store";
|
|
2
|
+
export interface ViewsQueryOptions<TScopeNames extends string = string, TSlot extends string = string> {
|
|
3
|
+
slot: TSlot;
|
|
4
|
+
scopes?: readonly TScopeNames[];
|
|
5
|
+
appIds?: readonly string[];
|
|
6
|
+
}
|
|
7
|
+
/** Refresh discovery or instances and join queries created by the resulting state. */
|
|
8
|
+
export declare function refetchViews(store: TailorKitStore, { slot, scopes, appIds }: ViewsQueryOptions): Promise<void>;
|
package/dist/client.js
CHANGED
|
@@ -1,22 +1,40 @@
|
|
|
1
1
|
import {
|
|
2
|
-
|
|
2
|
+
buildPrimitiveCss,
|
|
3
|
+
buildThemeCss,
|
|
4
|
+
createComponentRegistry,
|
|
5
|
+
createTailorKitClientConfig,
|
|
3
6
|
createTailorKitFetchClient,
|
|
7
|
+
toComponentTagName
|
|
8
|
+
} from "./chunk-QWOVC765.js";
|
|
9
|
+
import {
|
|
10
|
+
createEndpointClient
|
|
11
|
+
} from "./chunk-FUBKKH3Q.js";
|
|
12
|
+
import {
|
|
13
|
+
appendScopeSelection,
|
|
14
|
+
createValueMemo,
|
|
4
15
|
matchesApp,
|
|
5
|
-
normalizeScopeSelection
|
|
6
|
-
|
|
16
|
+
normalizeScopeSelection,
|
|
17
|
+
refetchViews
|
|
18
|
+
} from "./chunk-LNGQREZV.js";
|
|
7
19
|
import {
|
|
8
|
-
createEndpointClient,
|
|
9
20
|
resolveSlotView,
|
|
10
21
|
selectSlotView,
|
|
11
22
|
toBaseUrl
|
|
12
|
-
} from "./chunk-
|
|
23
|
+
} from "./chunk-BLDTSDUG.js";
|
|
13
24
|
export {
|
|
14
25
|
appendScopeSelection,
|
|
26
|
+
buildPrimitiveCss,
|
|
27
|
+
buildThemeCss,
|
|
28
|
+
createComponentRegistry,
|
|
15
29
|
createEndpointClient,
|
|
30
|
+
createTailorKitClientConfig,
|
|
16
31
|
createTailorKitFetchClient,
|
|
32
|
+
createValueMemo,
|
|
17
33
|
matchesApp,
|
|
18
34
|
normalizeScopeSelection,
|
|
35
|
+
refetchViews,
|
|
19
36
|
resolveSlotView,
|
|
20
37
|
selectSlotView,
|
|
21
|
-
toBaseUrl
|
|
38
|
+
toBaseUrl,
|
|
39
|
+
toComponentTagName
|
|
22
40
|
};
|
package/dist/index.js
CHANGED
|
@@ -1,27 +1,45 @@
|
|
|
1
1
|
import {
|
|
2
|
-
|
|
2
|
+
buildPrimitiveCss,
|
|
3
|
+
buildThemeCss,
|
|
4
|
+
createComponentRegistry,
|
|
5
|
+
createTailorKitClientConfig,
|
|
3
6
|
createTailorKitFetchClient,
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
} from "./chunk-DPR3U4U2.js";
|
|
7
|
+
toComponentTagName
|
|
8
|
+
} from "./chunk-QWOVC765.js";
|
|
7
9
|
import {
|
|
8
10
|
createAppsStore,
|
|
9
11
|
createMetadataStore,
|
|
10
|
-
createPreviewManager
|
|
11
|
-
|
|
12
|
-
|
|
12
|
+
createPreviewManager
|
|
13
|
+
} from "./chunk-CWDPTXSZ.js";
|
|
14
|
+
import {
|
|
15
|
+
createEndpointClient
|
|
16
|
+
} from "./chunk-FUBKKH3Q.js";
|
|
17
|
+
import {
|
|
18
|
+
NodeStore,
|
|
19
|
+
appsQueryKey,
|
|
20
|
+
createAppViewsQuery,
|
|
21
|
+
createAppsQuery,
|
|
22
|
+
createRemoteElementProps,
|
|
23
|
+
createRemoteViewStore,
|
|
24
|
+
createSlotRuntime,
|
|
25
|
+
createViewContextStore,
|
|
26
|
+
createViewsQuery
|
|
27
|
+
} from "./chunk-N4X53WS2.js";
|
|
28
|
+
import {
|
|
29
|
+
appendScopeSelection,
|
|
30
|
+
createValueMemo,
|
|
31
|
+
matchesApp,
|
|
32
|
+
normalizeScopeSelection,
|
|
33
|
+
refetchViews
|
|
34
|
+
} from "./chunk-LNGQREZV.js";
|
|
13
35
|
import {
|
|
14
|
-
createEndpointClient,
|
|
15
36
|
createFetchCache,
|
|
37
|
+
createSlotStore,
|
|
16
38
|
resolveSlotView,
|
|
17
39
|
selectSlotView,
|
|
18
40
|
serializeCacheKey,
|
|
19
41
|
toBaseUrl
|
|
20
|
-
} from "./chunk-
|
|
21
|
-
import {
|
|
22
|
-
NodeStore,
|
|
23
|
-
createViewRegistry
|
|
24
|
-
} from "./chunk-ED3BWTXG.js";
|
|
42
|
+
} from "./chunk-BLDTSDUG.js";
|
|
25
43
|
|
|
26
44
|
// src/store/store.ts
|
|
27
45
|
function createTailorKitStore(baseUrl, initialApps, client = createTailorKitFetchClient({ baseUrl })) {
|
|
@@ -34,7 +52,7 @@ function createTailorKitStore(baseUrl, initialApps, client = createTailorKitFetc
|
|
|
34
52
|
baseUrl: client.baseUrl,
|
|
35
53
|
client,
|
|
36
54
|
fetch: { apps, meta },
|
|
37
|
-
views:
|
|
55
|
+
views: createViewContextStore(client),
|
|
38
56
|
setProvidedApps: apps.setProvidedApps,
|
|
39
57
|
fetchApps: apps.fetch,
|
|
40
58
|
fetchMeta: meta.fetch,
|
|
@@ -55,19 +73,33 @@ function createTailorKitStore(baseUrl, initialApps, client = createTailorKitFetc
|
|
|
55
73
|
export {
|
|
56
74
|
NodeStore,
|
|
57
75
|
appendScopeSelection,
|
|
76
|
+
appsQueryKey,
|
|
77
|
+
buildPrimitiveCss,
|
|
78
|
+
buildThemeCss,
|
|
79
|
+
createAppViewsQuery,
|
|
80
|
+
createAppsQuery,
|
|
58
81
|
createAppsStore,
|
|
82
|
+
createComponentRegistry,
|
|
59
83
|
createEndpointClient,
|
|
60
84
|
createFetchCache,
|
|
61
85
|
createMetadataStore,
|
|
62
86
|
createPreviewManager,
|
|
87
|
+
createRemoteElementProps,
|
|
88
|
+
createRemoteViewStore,
|
|
89
|
+
createSlotRuntime,
|
|
63
90
|
createSlotStore,
|
|
91
|
+
createTailorKitClientConfig,
|
|
64
92
|
createTailorKitFetchClient,
|
|
65
93
|
createTailorKitStore,
|
|
66
|
-
|
|
94
|
+
createValueMemo,
|
|
95
|
+
createViewContextStore,
|
|
96
|
+
createViewsQuery,
|
|
67
97
|
matchesApp,
|
|
68
98
|
normalizeScopeSelection,
|
|
99
|
+
refetchViews,
|
|
69
100
|
resolveSlotView,
|
|
70
101
|
selectSlotView,
|
|
71
102
|
serializeCacheKey,
|
|
72
|
-
toBaseUrl
|
|
103
|
+
toBaseUrl,
|
|
104
|
+
toComponentTagName
|
|
73
105
|
};
|
|
@@ -15,4 +15,5 @@ export declare function createAppsStore(client: TailorKitFetchClient, initialApp
|
|
|
15
15
|
setProvidedApps(apps: TailorKitApp[] | undefined): void;
|
|
16
16
|
updateViews(appId: string, appViews: NonNullable<TailorKitApp["views"]>): void;
|
|
17
17
|
invalidate: () => Promise<void>;
|
|
18
|
+
state: import("nanostores").ReadableAtom<TailorKitAppsSnapshot>;
|
|
18
19
|
};
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { ReadableAtom } from "nanostores";
|
|
1
2
|
export interface FetchCacheOptions {
|
|
2
3
|
/** Milliseconds before a successful response needs refreshing. Infinity keeps it fresh. */
|
|
3
4
|
staleTime?: number;
|
|
@@ -14,8 +15,9 @@ export interface FetchSnapshot<T> {
|
|
|
14
15
|
export interface FetchOptions extends Pick<FetchCacheOptions, "staleTime"> {
|
|
15
16
|
force?: boolean;
|
|
16
17
|
}
|
|
17
|
-
/**
|
|
18
|
+
/** A cached request and readable state shared across framework adapters. */
|
|
18
19
|
export interface FetchStore<T> {
|
|
20
|
+
state: ReadableAtom<FetchSnapshot<T>>;
|
|
19
21
|
getSnapshot: () => FetchSnapshot<T>;
|
|
20
22
|
subscribe: (listener: () => void) => () => void;
|
|
21
23
|
fetch: (options?: FetchOptions) => Promise<void>;
|
|
@@ -13,4 +13,5 @@ export declare function createMetadataStore(client: TailorKitFetchClient): {
|
|
|
13
13
|
subscribe: (listener: () => void) => () => void;
|
|
14
14
|
fetch: (options?: import("./cache").FetchOptions) => Promise<void>;
|
|
15
15
|
invalidate: () => Promise<void>;
|
|
16
|
+
state: import("nanostores").ReadableAtom<TailorKitMetaSnapshot>;
|
|
16
17
|
};
|
|
@@ -8,4 +8,5 @@ export declare function createPreviewManager(baseUrl: URL, onEnded: () => void,
|
|
|
8
8
|
updateApp: (app: TailorKitApp) => void;
|
|
9
9
|
subscribe: (app: TailorKitApp, listener: () => void) => (() => void);
|
|
10
10
|
dispose: () => void;
|
|
11
|
+
getStore(getApp: () => TailorKitApp): import("nanostores").ReadableAtom<PreviewSnapshot>;
|
|
11
12
|
};
|
|
@@ -28,5 +28,6 @@ export declare function createSlotStore(client: TailorKitFetchClient, options: S
|
|
|
28
28
|
subscribe: (listener: () => void) => () => void;
|
|
29
29
|
fetch: (fetchOptions?: FetchOptions) => Promise<void>;
|
|
30
30
|
invalidate: () => Promise<void>;
|
|
31
|
+
state: import("nanostores").ReadableAtom<SlotSnapshot>;
|
|
31
32
|
};
|
|
32
33
|
export {};
|
package/dist/store/index.d.ts
CHANGED
|
@@ -2,3 +2,5 @@ export { createTailorKitStore } from "./store";
|
|
|
2
2
|
export type { TailorKitStore } from "./store";
|
|
3
3
|
export * from "./fetch/index";
|
|
4
4
|
export * from "./local/index";
|
|
5
|
+
export { createAppsQuery, createViewsQuery, createAppViewsQuery, appsQueryKey } from "./query";
|
|
6
|
+
export type { AppsQueryOptions, QueryResult, ViewsQueryResult } from "./query";
|
|
@@ -1,4 +1,9 @@
|
|
|
1
1
|
export { NodeStore } from "./node-store";
|
|
2
2
|
export type { NodeSnapshot } from "./node-store";
|
|
3
|
-
export {
|
|
4
|
-
export type {
|
|
3
|
+
export { createRemoteViewStore, createRemoteElementProps } from "./remote-view";
|
|
4
|
+
export type { RemoteViewStore, RemoteViewStoreOptions, RemoteViewMountOptions, RemoteViewSnapshot, } from "./remote-view";
|
|
5
|
+
export { createViewContextStore } from "./view-context";
|
|
6
|
+
export type { ViewEntry } from "./view-context";
|
|
7
|
+
export type { ViewContext, ViewContextRegistration, ViewContextState, ViewName, ViewOptions, ViewState, } from "./view-context-types";
|
|
8
|
+
export { createSlotRuntime } from "./slot-runtime";
|
|
9
|
+
export type { SlotRuntimeOptions, SlotRuntimeSnapshot } from "./slot-runtime";
|
|
@@ -6,11 +6,13 @@ export interface NodeSnapshot {
|
|
|
6
6
|
}
|
|
7
7
|
export declare class NodeStore {
|
|
8
8
|
readonly state: import("nanostores").PreinitializedWritableAtom<NodeSnapshot> & object;
|
|
9
|
+
readonly root: import("nanostores").ReadableAtom<string | null>;
|
|
9
10
|
private signatures;
|
|
10
11
|
clear(): void;
|
|
11
12
|
setSnapshot(tree: RemoteNode): void;
|
|
12
13
|
getRootId(): string | null;
|
|
13
14
|
getNode(id: string): RemoteNode | null;
|
|
15
|
+
selectNode(id: string): import("nanostores").ReadableAtom<RemoteNode | null>;
|
|
14
16
|
subscribe(id: string, listener: Listener): () => void;
|
|
15
17
|
subscribeRoot(listener: Listener): () => void;
|
|
16
18
|
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { createIframeUiHost } from "@tailorkit/sandbox/host";
|
|
2
|
+
import type { IframeUiHostOptions } from "@tailorkit/sandbox/host";
|
|
3
|
+
import type { HostToIframePayload, RemoteElementNode } from "@tailorkit/sandbox/protocol";
|
|
4
|
+
import { NodeStore } from "./node-store";
|
|
5
|
+
export interface RemoteViewSnapshot {
|
|
6
|
+
error: Error | null;
|
|
7
|
+
generation: number;
|
|
8
|
+
status: "starting" | "ready" | "error";
|
|
9
|
+
}
|
|
10
|
+
export interface RemoteViewStoreOptions {
|
|
11
|
+
components?: Record<string, unknown>;
|
|
12
|
+
props?: Record<string, unknown>;
|
|
13
|
+
}
|
|
14
|
+
export interface RemoteViewMountOptions extends Omit<IframeUiHostOptions, "onError" | "props"> {
|
|
15
|
+
appUrl: string | URL;
|
|
16
|
+
}
|
|
17
|
+
/** One remote app's state and host lifecycle, independent of its rendering framework. */
|
|
18
|
+
export declare function createRemoteViewStore(options?: RemoteViewStoreOptions, createHost?: typeof createIframeUiHost): {
|
|
19
|
+
nodes: NodeStore;
|
|
20
|
+
components: import("nanostores").PreinitializedWritableAtom<Record<string, unknown>> & object;
|
|
21
|
+
state: import("nanostores").PreinitializedWritableAtom<RemoteViewSnapshot> & object;
|
|
22
|
+
selectComponent: (name: string) => import("nanostores").ReadableAtom<unknown>;
|
|
23
|
+
setComponents: (registry: Record<string, unknown>) => void;
|
|
24
|
+
setProps(next: Record<string, unknown> | undefined): void;
|
|
25
|
+
dispatch(payload: HostToIframePayload): void;
|
|
26
|
+
mount({ appUrl, ...hostOptions }: RemoteViewMountOptions): () => void;
|
|
27
|
+
destroy(): void;
|
|
28
|
+
};
|
|
29
|
+
export type RemoteViewStore = ReturnType<typeof createRemoteViewStore>;
|
|
30
|
+
/** Bind remote callbacks to their protocol payload without framework event arguments leaking. */
|
|
31
|
+
export declare function createRemoteElementProps(node: RemoteElementNode, dispatch: RemoteViewStore["dispatch"]): Record<string, unknown>;
|