@webmaster-droid/web 0.2.0 → 0.3.0
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.d.ts +12 -9
- package/dist/index.js +53 -1
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -3,15 +3,15 @@ import React, { ImgHTMLAttributes, HTMLAttributes, ReactNode } from 'react';
|
|
|
3
3
|
import { CmsDocument, SelectedElementKind, SelectedElementContext, PublishRequest, RollbackRequest } from '@webmaster-droid/contracts';
|
|
4
4
|
import { Session, SupabaseClient } from '@supabase/supabase-js';
|
|
5
5
|
|
|
6
|
-
type AnyCmsDocument$
|
|
6
|
+
type AnyCmsDocument$2 = CmsDocument<object, object, string>;
|
|
7
7
|
type EditableMode = "live" | "draft";
|
|
8
8
|
interface EditableContextValue {
|
|
9
|
-
document: AnyCmsDocument$
|
|
9
|
+
document: AnyCmsDocument$2;
|
|
10
10
|
mode: EditableMode;
|
|
11
11
|
enabled: boolean;
|
|
12
12
|
}
|
|
13
13
|
declare function EditableProvider(props: {
|
|
14
|
-
document: AnyCmsDocument$
|
|
14
|
+
document: AnyCmsDocument$2;
|
|
15
15
|
mode?: EditableMode;
|
|
16
16
|
enabled?: boolean;
|
|
17
17
|
children: ReactNode;
|
|
@@ -690,14 +690,14 @@ type WebmasterDroidOverlayProps = {
|
|
|
690
690
|
};
|
|
691
691
|
declare function WebmasterDroidOverlay({ injectCoreStyles }: WebmasterDroidOverlayProps): react_jsx_runtime.JSX.Element | null;
|
|
692
692
|
|
|
693
|
-
type AnyCmsDocument = CmsDocument<object, object, string>;
|
|
694
|
-
type WebmasterDroidCmsContextValue<TDocument extends AnyCmsDocument = AnyCmsDocument> = {
|
|
693
|
+
type AnyCmsDocument$1 = CmsDocument<object, object, string>;
|
|
694
|
+
type WebmasterDroidCmsContextValue<TDocument extends AnyCmsDocument$1 = AnyCmsDocument$1> = {
|
|
695
695
|
document: TDocument;
|
|
696
696
|
stage: "live" | "draft";
|
|
697
697
|
loading: boolean;
|
|
698
698
|
error: string | null;
|
|
699
699
|
};
|
|
700
|
-
type WebmasterDroidRuntimeProps<TDocument extends AnyCmsDocument = AnyCmsDocument> = {
|
|
700
|
+
type WebmasterDroidRuntimeProps<TDocument extends AnyCmsDocument$1 = AnyCmsDocument$1> = {
|
|
701
701
|
children: ReactNode;
|
|
702
702
|
fallbackDocument?: TDocument;
|
|
703
703
|
config?: WebmasterDroidConfig;
|
|
@@ -705,8 +705,11 @@ type WebmasterDroidRuntimeProps<TDocument extends AnyCmsDocument = AnyCmsDocumen
|
|
|
705
705
|
applyThemeTokens?: boolean;
|
|
706
706
|
injectCoreStyles?: boolean;
|
|
707
707
|
};
|
|
708
|
-
declare function WebmasterDroidRuntime<TDocument extends AnyCmsDocument = AnyCmsDocument>(props: WebmasterDroidRuntimeProps<TDocument>): react_jsx_runtime.JSX.Element;
|
|
709
|
-
declare function useWebmasterDroidCmsDocument<TDocument extends AnyCmsDocument = AnyCmsDocument>(): WebmasterDroidCmsContextValue<TDocument>;
|
|
708
|
+
declare function WebmasterDroidRuntime<TDocument extends AnyCmsDocument$1 = AnyCmsDocument$1>(props: WebmasterDroidRuntimeProps<TDocument>): react_jsx_runtime.JSX.Element;
|
|
709
|
+
declare function useWebmasterDroidCmsDocument<TDocument extends AnyCmsDocument$1 = AnyCmsDocument$1>(): WebmasterDroidCmsContextValue<TDocument>;
|
|
710
|
+
|
|
711
|
+
type AnyCmsDocument = CmsDocument<object, object, string>;
|
|
712
|
+
declare function normalizeCmsDocumentWithFallback<TDocument extends AnyCmsDocument>(document: unknown, fallbackDocument: TDocument): TDocument;
|
|
710
713
|
|
|
711
714
|
declare function getSupabaseBrowserClient(config: ResolvedWebmasterDroidConfig): SupabaseClient | null;
|
|
712
715
|
|
|
@@ -755,4 +758,4 @@ declare function streamChat(params: {
|
|
|
755
758
|
}) => void;
|
|
756
759
|
}): Promise<void>;
|
|
757
760
|
|
|
758
|
-
export { EditableImage, EditableLink, EditableProvider, EditableRichText, EditableText, type ModelOption, type ResolvedWebmasterDroidConfig, type WebmasterDroidCmsContextValue, type WebmasterDroidConfig, type WebmasterDroidContextValue, WebmasterDroidOverlay, type WebmasterDroidOverlayProps, WebmasterDroidProvider, WebmasterDroidRuntime, type WebmasterDroidRuntimeProps, buildApiUrl, deleteCheckpoint, editableMeta, fetchCmsContent, fetchHistory, fetchModels, getSupabaseBrowserClient, parseSelectedEditableFromTarget, publishDraft, resolveWebmasterDroidConfig, rollbackDraft, streamChat, useEditableDocument, useWebmasterDroid, useWebmasterDroidCmsDocument };
|
|
761
|
+
export { EditableImage, EditableLink, EditableProvider, EditableRichText, EditableText, type ModelOption, type ResolvedWebmasterDroidConfig, type WebmasterDroidCmsContextValue, type WebmasterDroidConfig, type WebmasterDroidContextValue, WebmasterDroidOverlay, type WebmasterDroidOverlayProps, WebmasterDroidProvider, WebmasterDroidRuntime, type WebmasterDroidRuntimeProps, buildApiUrl, deleteCheckpoint, editableMeta, fetchCmsContent, fetchHistory, fetchModels, getSupabaseBrowserClient, normalizeCmsDocumentWithFallback, parseSelectedEditableFromTarget, publishDraft, resolveWebmasterDroidConfig, rollbackDraft, streamChat, useEditableDocument, useWebmasterDroid, useWebmasterDroidCmsDocument };
|
package/dist/index.js
CHANGED
|
@@ -2097,6 +2097,54 @@ import {
|
|
|
2097
2097
|
import {
|
|
2098
2098
|
createDefaultCmsDocument
|
|
2099
2099
|
} from "@webmaster-droid/contracts";
|
|
2100
|
+
|
|
2101
|
+
// src/normalize-document.ts
|
|
2102
|
+
import {
|
|
2103
|
+
normalizeCmsDocument
|
|
2104
|
+
} from "@webmaster-droid/contracts";
|
|
2105
|
+
function isRecord(value) {
|
|
2106
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
2107
|
+
}
|
|
2108
|
+
function cloneValue(value) {
|
|
2109
|
+
if (Array.isArray(value)) {
|
|
2110
|
+
return value.map((item) => cloneValue(item));
|
|
2111
|
+
}
|
|
2112
|
+
if (isRecord(value)) {
|
|
2113
|
+
const out = {};
|
|
2114
|
+
for (const [key, item] of Object.entries(value)) {
|
|
2115
|
+
out[key] = cloneValue(item);
|
|
2116
|
+
}
|
|
2117
|
+
return out;
|
|
2118
|
+
}
|
|
2119
|
+
return value;
|
|
2120
|
+
}
|
|
2121
|
+
function mergeMissing(target, defaults) {
|
|
2122
|
+
if (Array.isArray(target) || Array.isArray(defaults)) {
|
|
2123
|
+
return target === void 0 ? cloneValue(defaults) : target;
|
|
2124
|
+
}
|
|
2125
|
+
if (!isRecord(defaults)) {
|
|
2126
|
+
return target === void 0 ? defaults : target;
|
|
2127
|
+
}
|
|
2128
|
+
if (!isRecord(target)) {
|
|
2129
|
+
return cloneValue(defaults);
|
|
2130
|
+
}
|
|
2131
|
+
const out = { ...target };
|
|
2132
|
+
for (const [key, value] of Object.entries(defaults)) {
|
|
2133
|
+
out[key] = mergeMissing(out[key], value);
|
|
2134
|
+
}
|
|
2135
|
+
return out;
|
|
2136
|
+
}
|
|
2137
|
+
function normalizeCmsDocumentWithFallback(document2, fallbackDocument) {
|
|
2138
|
+
const merged = mergeMissing(
|
|
2139
|
+
isRecord(document2) ? document2 : {},
|
|
2140
|
+
fallbackDocument
|
|
2141
|
+
);
|
|
2142
|
+
return normalizeCmsDocument(
|
|
2143
|
+
merged
|
|
2144
|
+
);
|
|
2145
|
+
}
|
|
2146
|
+
|
|
2147
|
+
// src/runtime.tsx
|
|
2100
2148
|
import { jsx as jsx5, jsxs as jsxs3 } from "react/jsx-runtime";
|
|
2101
2149
|
var CmsRuntimeContext = createContext3(null);
|
|
2102
2150
|
function createThemeCssVariables(tokens) {
|
|
@@ -2137,7 +2185,10 @@ function CmsRuntimeBridge(props) {
|
|
|
2137
2185
|
}
|
|
2138
2186
|
setState({
|
|
2139
2187
|
requestKey,
|
|
2140
|
-
document:
|
|
2188
|
+
document: normalizeCmsDocumentWithFallback(
|
|
2189
|
+
content2,
|
|
2190
|
+
defaultDocument
|
|
2191
|
+
),
|
|
2141
2192
|
error: null
|
|
2142
2193
|
});
|
|
2143
2194
|
}).catch((error2) => {
|
|
@@ -2207,6 +2258,7 @@ export {
|
|
|
2207
2258
|
fetchHistory,
|
|
2208
2259
|
fetchModels,
|
|
2209
2260
|
getSupabaseBrowserClient,
|
|
2261
|
+
normalizeCmsDocumentWithFallback,
|
|
2210
2262
|
parseSelectedEditableFromTarget,
|
|
2211
2263
|
publishDraft,
|
|
2212
2264
|
resolveWebmasterDroidConfig,
|