@asteroidcms/core-utils 0.1.2 → 0.1.4
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/README.md +59 -4
- package/dist/client.cjs +1684 -0
- package/dist/client.cjs.map +1 -0
- package/dist/client.d.cts +316 -0
- package/dist/client.d.ts +316 -0
- package/dist/client.js +1669 -0
- package/dist/client.js.map +1 -0
- package/dist/index.cjs +99 -740
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +42 -180
- package/dist/index.d.ts +42 -180
- package/dist/index.js +97 -731
- package/dist/index.js.map +1 -1
- package/package.json +7 -2
package/dist/index.d.cts
CHANGED
|
@@ -1,9 +1,4 @@
|
|
|
1
|
-
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
2
|
-
import * as react from 'react';
|
|
3
|
-
import { PropsWithChildren } from 'react';
|
|
4
|
-
import * as _apollo_client from '@apollo/client';
|
|
5
1
|
import { InMemoryCacheConfig, ApolloClientOptions, ApolloClient, DocumentNode } from '@apollo/client';
|
|
6
|
-
import { useMutation } from '@apollo/client/react';
|
|
7
2
|
|
|
8
3
|
type AsteroidCMSConfig = {
|
|
9
4
|
/** Base URL of the Asteroid CMS API (e.g. https://cms-api.example.com). */
|
|
@@ -30,25 +25,6 @@ type ResolvedAsteroidCMSConfig = Required<Pick<AsteroidCMSConfig, "cmsUrl" | "ap
|
|
|
30
25
|
onError?: AsteroidCMSConfig["onError"];
|
|
31
26
|
};
|
|
32
27
|
|
|
33
|
-
type AsteroidCMSProviderProps = PropsWithChildren<AsteroidCMSConfig>;
|
|
34
|
-
/**
|
|
35
|
-
* Root provider for `@asteroidcms/core-utils`.
|
|
36
|
-
*
|
|
37
|
-
* Wrap your app once at the top level:
|
|
38
|
-
*
|
|
39
|
-
* ```tsx
|
|
40
|
-
* <AsteroidCMSProvider cmsUrl="https://cms.example.com" apiKey="...">
|
|
41
|
-
* <App />
|
|
42
|
-
* </AsteroidCMSProvider>
|
|
43
|
-
* ```
|
|
44
|
-
*
|
|
45
|
-
* Everything below — `useCmsContent`, `useCmsMutate`, `useCmsImage`,
|
|
46
|
-
* `<RichTextContent>` — picks up `cmsUrl` and `apiKey` from this provider.
|
|
47
|
-
*/
|
|
48
|
-
declare function AsteroidCMSProvider({ children, ...config }: AsteroidCMSProviderProps): react_jsx_runtime.JSX.Element;
|
|
49
|
-
|
|
50
|
-
declare function useAsteroidCMSConfig(): ResolvedAsteroidCMSConfig;
|
|
51
|
-
|
|
52
28
|
declare module "@apollo/client" {
|
|
53
29
|
namespace ApolloClient.DeclareDefaultOptions {
|
|
54
30
|
interface WatchQuery {
|
|
@@ -65,146 +41,6 @@ declare module "@apollo/client" {
|
|
|
65
41
|
}
|
|
66
42
|
declare function createApolloClient(config: AsteroidCMSConfig): ApolloClient;
|
|
67
43
|
|
|
68
|
-
type FieldSelector$2 = string | {
|
|
69
|
-
field: string;
|
|
70
|
-
as?: string;
|
|
71
|
-
};
|
|
72
|
-
type ReferenceExpansion$2 = {
|
|
73
|
-
field: string;
|
|
74
|
-
as?: string;
|
|
75
|
-
single?: boolean;
|
|
76
|
-
select?: readonly (FieldSelector$2 | ReferenceExpansion$2)[];
|
|
77
|
-
};
|
|
78
|
-
type ContentStatus$1 = "DRAFT" | "PUBLISHED" | "ARCHIVED";
|
|
79
|
-
type CmsSearchCondition$1 = {
|
|
80
|
-
field: string;
|
|
81
|
-
value: string;
|
|
82
|
-
mode?: string;
|
|
83
|
-
};
|
|
84
|
-
type UseCmsContentOptions$1 = {
|
|
85
|
-
schema_slug: string;
|
|
86
|
-
entrySlug?: string;
|
|
87
|
-
select?: readonly (FieldSelector$2 | ReferenceExpansion$2)[];
|
|
88
|
-
fullData?: boolean;
|
|
89
|
-
limit?: number;
|
|
90
|
-
offset?: number;
|
|
91
|
-
status?: ContentStatus$1;
|
|
92
|
-
filter?: Record<string, string | number | boolean | null>;
|
|
93
|
-
search?: CmsSearchCondition$1[];
|
|
94
|
-
variables?: Record<string, any>;
|
|
95
|
-
};
|
|
96
|
-
/**
|
|
97
|
-
* React hook for querying content from Asteroid CMS via a flexible GraphQL API.
|
|
98
|
-
*
|
|
99
|
-
* Supports single-entry fetches (`entrySlug`) and paginated/filtered lists,
|
|
100
|
-
* with arbitrarily nested reference expansion and field aliasing.
|
|
101
|
-
*/
|
|
102
|
-
declare function useCmsContent<T = unknown>({ schema_slug, entrySlug, select, fullData, limit, offset, status, filter, search, variables, }: UseCmsContentOptions$1): {
|
|
103
|
-
client: _apollo_client.ApolloClient;
|
|
104
|
-
observable: _apollo_client.ObservableQuery<unknown, _apollo_client.OperationVariables>;
|
|
105
|
-
previousData?: unknown;
|
|
106
|
-
networkStatus: _apollo_client.NetworkStatus;
|
|
107
|
-
startPolling: (pollInterval: number) => void;
|
|
108
|
-
stopPolling: () => void;
|
|
109
|
-
subscribeToMore: _apollo_client.SubscribeToMoreFunction<unknown, _apollo_client.OperationVariables>;
|
|
110
|
-
updateQuery: (mapFn: _apollo_client.UpdateQueryMapFn<unknown, _apollo_client.OperationVariables>) => void;
|
|
111
|
-
refetch: (variables?: Partial<_apollo_client.OperationVariables> | undefined) => Promise<{
|
|
112
|
-
data: unknown;
|
|
113
|
-
error?: _apollo_client.ErrorLike;
|
|
114
|
-
}>;
|
|
115
|
-
variables: _apollo_client.OperationVariables;
|
|
116
|
-
fetchMore: <TFetchData = unknown, TFetchVars extends _apollo_client.OperationVariables = _apollo_client.OperationVariables>(fetchMoreOptions: _apollo_client.ObservableQuery.FetchMoreOptions<unknown, _apollo_client.OperationVariables, TFetchData, TFetchVars>) => Promise<{
|
|
117
|
-
data: TFetchData | undefined;
|
|
118
|
-
error?: _apollo_client.ErrorLike;
|
|
119
|
-
}>;
|
|
120
|
-
dataState: "empty";
|
|
121
|
-
loading: boolean;
|
|
122
|
-
error: _apollo_client.ErrorLike | undefined;
|
|
123
|
-
data: T | undefined;
|
|
124
|
-
} | {
|
|
125
|
-
client: _apollo_client.ApolloClient;
|
|
126
|
-
observable: _apollo_client.ObservableQuery<unknown, _apollo_client.OperationVariables>;
|
|
127
|
-
previousData?: unknown;
|
|
128
|
-
networkStatus: _apollo_client.NetworkStatus;
|
|
129
|
-
startPolling: (pollInterval: number) => void;
|
|
130
|
-
stopPolling: () => void;
|
|
131
|
-
subscribeToMore: _apollo_client.SubscribeToMoreFunction<unknown, _apollo_client.OperationVariables>;
|
|
132
|
-
updateQuery: (mapFn: _apollo_client.UpdateQueryMapFn<unknown, _apollo_client.OperationVariables>) => void;
|
|
133
|
-
refetch: (variables?: Partial<_apollo_client.OperationVariables> | undefined) => Promise<{
|
|
134
|
-
data: unknown;
|
|
135
|
-
error?: _apollo_client.ErrorLike;
|
|
136
|
-
}>;
|
|
137
|
-
variables: _apollo_client.OperationVariables;
|
|
138
|
-
fetchMore: <TFetchData = unknown, TFetchVars extends _apollo_client.OperationVariables = _apollo_client.OperationVariables>(fetchMoreOptions: _apollo_client.ObservableQuery.FetchMoreOptions<unknown, _apollo_client.OperationVariables, TFetchData, TFetchVars>) => Promise<{
|
|
139
|
-
data: TFetchData | undefined;
|
|
140
|
-
error?: _apollo_client.ErrorLike;
|
|
141
|
-
}>;
|
|
142
|
-
dataState: "complete";
|
|
143
|
-
loading: boolean;
|
|
144
|
-
error: _apollo_client.ErrorLike | undefined;
|
|
145
|
-
data: T | undefined;
|
|
146
|
-
} | {
|
|
147
|
-
client: _apollo_client.ApolloClient;
|
|
148
|
-
observable: _apollo_client.ObservableQuery<unknown, _apollo_client.OperationVariables>;
|
|
149
|
-
previousData?: unknown;
|
|
150
|
-
networkStatus: _apollo_client.NetworkStatus;
|
|
151
|
-
startPolling: (pollInterval: number) => void;
|
|
152
|
-
stopPolling: () => void;
|
|
153
|
-
subscribeToMore: _apollo_client.SubscribeToMoreFunction<unknown, _apollo_client.OperationVariables>;
|
|
154
|
-
updateQuery: (mapFn: _apollo_client.UpdateQueryMapFn<unknown, _apollo_client.OperationVariables>) => void;
|
|
155
|
-
refetch: (variables?: Partial<_apollo_client.OperationVariables> | undefined) => Promise<{
|
|
156
|
-
data: unknown;
|
|
157
|
-
error?: _apollo_client.ErrorLike;
|
|
158
|
-
}>;
|
|
159
|
-
variables: _apollo_client.OperationVariables;
|
|
160
|
-
fetchMore: <TFetchData = unknown, TFetchVars extends _apollo_client.OperationVariables = _apollo_client.OperationVariables>(fetchMoreOptions: _apollo_client.ObservableQuery.FetchMoreOptions<unknown, _apollo_client.OperationVariables, TFetchData, TFetchVars>) => Promise<{
|
|
161
|
-
data: TFetchData | undefined;
|
|
162
|
-
error?: _apollo_client.ErrorLike;
|
|
163
|
-
}>;
|
|
164
|
-
dataState: "streaming";
|
|
165
|
-
loading: boolean;
|
|
166
|
-
error: _apollo_client.ErrorLike | undefined;
|
|
167
|
-
data: T | undefined;
|
|
168
|
-
};
|
|
169
|
-
|
|
170
|
-
type FieldSelector$1 = string | {
|
|
171
|
-
field: string;
|
|
172
|
-
as?: string;
|
|
173
|
-
single?: boolean;
|
|
174
|
-
select?: readonly (FieldSelector$1 | ReferenceExpansion$1)[];
|
|
175
|
-
};
|
|
176
|
-
type ReferenceExpansion$1 = {
|
|
177
|
-
field: string;
|
|
178
|
-
as?: string;
|
|
179
|
-
single?: boolean;
|
|
180
|
-
select?: readonly (FieldSelector$1 | ReferenceExpansion$1)[];
|
|
181
|
-
};
|
|
182
|
-
type MutationType = "create" | "update" | "delete";
|
|
183
|
-
type UseCmsMutateOptions = {
|
|
184
|
-
schema_slug: string;
|
|
185
|
-
entrySlug?: string;
|
|
186
|
-
select?: readonly (FieldSelector$1 | ReferenceExpansion$1)[];
|
|
187
|
-
fullData?: boolean;
|
|
188
|
-
mutationType?: MutationType;
|
|
189
|
-
entryId?: string;
|
|
190
|
-
variables?: Record<string, any>;
|
|
191
|
-
};
|
|
192
|
-
/**
|
|
193
|
-
* React hook for mutating content in Asteroid CMS (`create` / `update` / `delete`).
|
|
194
|
-
* Uses the same selection syntax as `useCmsContent`.
|
|
195
|
-
*/
|
|
196
|
-
declare function useCmsMutate<TData = unknown>({ schema_slug, select, fullData, mutationType, entryId, variables: inputVariables, }: UseCmsMutateOptions): {
|
|
197
|
-
readonly data: TData | undefined;
|
|
198
|
-
readonly loading: boolean;
|
|
199
|
-
readonly called: boolean;
|
|
200
|
-
readonly client: _apollo_client.ApolloClient;
|
|
201
|
-
readonly reset: () => void;
|
|
202
|
-
readonly error: _apollo_client.ErrorLike | undefined;
|
|
203
|
-
readonly mutate: useMutation.MutationFunction<unknown, {
|
|
204
|
-
[x: string]: any;
|
|
205
|
-
}, _apollo_client.ApolloCache, "none">;
|
|
206
|
-
};
|
|
207
|
-
|
|
208
44
|
type FieldSelector = string | {
|
|
209
45
|
field: string;
|
|
210
46
|
as?: string;
|
|
@@ -250,8 +86,6 @@ declare function cmsImage(id: string | undefined, options: {
|
|
|
250
86
|
cmsUrl: string;
|
|
251
87
|
mediaPath?: string;
|
|
252
88
|
}): string;
|
|
253
|
-
/** Hook variant that pulls `cmsUrl`/`mediaPath` from the provider. */
|
|
254
|
-
declare function useCmsImage(): (id?: string) => string;
|
|
255
89
|
|
|
256
90
|
type ReadTimeUnit = "short" | "long";
|
|
257
91
|
interface GetContentReadTimeOptions {
|
|
@@ -307,6 +141,12 @@ interface ParseRichTextOptions {
|
|
|
307
141
|
classMap?: RichTextClassMap;
|
|
308
142
|
/** Tag allowlist override. Defaults to a safe semantic set. */
|
|
309
143
|
allowlist?: ReadonlyArray<string>;
|
|
144
|
+
/**
|
|
145
|
+
* When `true` (default), inject slugified `id` attributes on `<h1>`–`<h6>`
|
|
146
|
+
* tags that don't already have one. Lets ToC anchors resolve from the
|
|
147
|
+
* server-rendered markup without a client-side mutation step.
|
|
148
|
+
*/
|
|
149
|
+
autoHeadingIds?: boolean;
|
|
310
150
|
}
|
|
311
151
|
declare function parseRichText(html: string, options?: ParseRichTextOptions): string;
|
|
312
152
|
/**
|
|
@@ -316,19 +156,41 @@ declare function parseRichText(html: string, options?: ParseRichTextOptions): st
|
|
|
316
156
|
*/
|
|
317
157
|
declare function removeEmptyParagraphs(html: string): string;
|
|
318
158
|
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
159
|
+
/**
|
|
160
|
+
* Heading extraction helpers used to build tables of contents (ToC) from
|
|
161
|
+
* rich-text HTML. Server-safe — no React, no DOM dependency in the HTML
|
|
162
|
+
* variant. The DOM variant assigns missing `id`s in-place so anchor links
|
|
163
|
+
* resolve immediately.
|
|
164
|
+
*/
|
|
165
|
+
type HeadingLevel = 1 | 2 | 3 | 4 | 5 | 6;
|
|
166
|
+
interface ExtractedHeading {
|
|
167
|
+
id: string;
|
|
168
|
+
text: string;
|
|
169
|
+
level: HeadingLevel;
|
|
170
|
+
}
|
|
171
|
+
interface ExtractHeadingsOptions {
|
|
172
|
+
/** Levels to include. Defaults to `[2, 3]` — typical doc page outline. */
|
|
173
|
+
levels?: ReadonlyArray<HeadingLevel>;
|
|
174
|
+
/** Custom slug function. Defaults to a lowercase/kebab/diacritic-safe slug. */
|
|
175
|
+
slugify?: (text: string, index: number) => string;
|
|
325
176
|
}
|
|
326
|
-
declare function
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
177
|
+
declare function slugify(text: string): string;
|
|
178
|
+
/**
|
|
179
|
+
* Parse headings out of a raw HTML string. Returns headings in document
|
|
180
|
+
* order with stable, de-duplicated IDs.
|
|
181
|
+
*
|
|
182
|
+
* If a heading already has an `id` attribute, it's preserved verbatim
|
|
183
|
+
* (and reserved so later slugs don't collide with it).
|
|
184
|
+
*/
|
|
185
|
+
declare function extractHeadingsFromHtml(html: string, options?: ExtractHeadingsOptions): ExtractedHeading[];
|
|
186
|
+
/**
|
|
187
|
+
* Walk a rendered DOM subtree, collect headings, and assign missing `id`s
|
|
188
|
+
* in-place so anchor links resolve immediately. Also sets `scrollMarginTop`
|
|
189
|
+
* on each heading when `scrollMarginTop` is provided so navigation lands
|
|
190
|
+
* cleanly below a sticky header.
|
|
191
|
+
*/
|
|
192
|
+
declare function extractHeadingsFromElement(root: HTMLElement, options?: ExtractHeadingsOptions & {
|
|
193
|
+
scrollMarginTop?: number;
|
|
194
|
+
}): ExtractedHeading[];
|
|
333
195
|
|
|
334
|
-
export { type AsteroidCMSConfig,
|
|
196
|
+
export { type AsteroidCMSConfig, type CmsSearchCondition, type ContentStatus, type ExtractHeadingsOptions, type ExtractedHeading, type FieldSelector, type HeadingLevel, type ParseRichTextOptions, type ReferenceExpansion, type ResolvedAsteroidCMSConfig, type RichTextClassKey, type RichTextClassMap, type UseCmsContentOptions, buildCmsQuery, cmsImage, createApolloClient, extractHeadingsFromElement, extractHeadingsFromHtml, fetchCmsContent, getContentReadTime, parseRichText, removeEmptyParagraphs, slugify };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,9 +1,4 @@
|
|
|
1
|
-
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
2
|
-
import * as react from 'react';
|
|
3
|
-
import { PropsWithChildren } from 'react';
|
|
4
|
-
import * as _apollo_client from '@apollo/client';
|
|
5
1
|
import { InMemoryCacheConfig, ApolloClientOptions, ApolloClient, DocumentNode } from '@apollo/client';
|
|
6
|
-
import { useMutation } from '@apollo/client/react';
|
|
7
2
|
|
|
8
3
|
type AsteroidCMSConfig = {
|
|
9
4
|
/** Base URL of the Asteroid CMS API (e.g. https://cms-api.example.com). */
|
|
@@ -30,25 +25,6 @@ type ResolvedAsteroidCMSConfig = Required<Pick<AsteroidCMSConfig, "cmsUrl" | "ap
|
|
|
30
25
|
onError?: AsteroidCMSConfig["onError"];
|
|
31
26
|
};
|
|
32
27
|
|
|
33
|
-
type AsteroidCMSProviderProps = PropsWithChildren<AsteroidCMSConfig>;
|
|
34
|
-
/**
|
|
35
|
-
* Root provider for `@asteroidcms/core-utils`.
|
|
36
|
-
*
|
|
37
|
-
* Wrap your app once at the top level:
|
|
38
|
-
*
|
|
39
|
-
* ```tsx
|
|
40
|
-
* <AsteroidCMSProvider cmsUrl="https://cms.example.com" apiKey="...">
|
|
41
|
-
* <App />
|
|
42
|
-
* </AsteroidCMSProvider>
|
|
43
|
-
* ```
|
|
44
|
-
*
|
|
45
|
-
* Everything below — `useCmsContent`, `useCmsMutate`, `useCmsImage`,
|
|
46
|
-
* `<RichTextContent>` — picks up `cmsUrl` and `apiKey` from this provider.
|
|
47
|
-
*/
|
|
48
|
-
declare function AsteroidCMSProvider({ children, ...config }: AsteroidCMSProviderProps): react_jsx_runtime.JSX.Element;
|
|
49
|
-
|
|
50
|
-
declare function useAsteroidCMSConfig(): ResolvedAsteroidCMSConfig;
|
|
51
|
-
|
|
52
28
|
declare module "@apollo/client" {
|
|
53
29
|
namespace ApolloClient.DeclareDefaultOptions {
|
|
54
30
|
interface WatchQuery {
|
|
@@ -65,146 +41,6 @@ declare module "@apollo/client" {
|
|
|
65
41
|
}
|
|
66
42
|
declare function createApolloClient(config: AsteroidCMSConfig): ApolloClient;
|
|
67
43
|
|
|
68
|
-
type FieldSelector$2 = string | {
|
|
69
|
-
field: string;
|
|
70
|
-
as?: string;
|
|
71
|
-
};
|
|
72
|
-
type ReferenceExpansion$2 = {
|
|
73
|
-
field: string;
|
|
74
|
-
as?: string;
|
|
75
|
-
single?: boolean;
|
|
76
|
-
select?: readonly (FieldSelector$2 | ReferenceExpansion$2)[];
|
|
77
|
-
};
|
|
78
|
-
type ContentStatus$1 = "DRAFT" | "PUBLISHED" | "ARCHIVED";
|
|
79
|
-
type CmsSearchCondition$1 = {
|
|
80
|
-
field: string;
|
|
81
|
-
value: string;
|
|
82
|
-
mode?: string;
|
|
83
|
-
};
|
|
84
|
-
type UseCmsContentOptions$1 = {
|
|
85
|
-
schema_slug: string;
|
|
86
|
-
entrySlug?: string;
|
|
87
|
-
select?: readonly (FieldSelector$2 | ReferenceExpansion$2)[];
|
|
88
|
-
fullData?: boolean;
|
|
89
|
-
limit?: number;
|
|
90
|
-
offset?: number;
|
|
91
|
-
status?: ContentStatus$1;
|
|
92
|
-
filter?: Record<string, string | number | boolean | null>;
|
|
93
|
-
search?: CmsSearchCondition$1[];
|
|
94
|
-
variables?: Record<string, any>;
|
|
95
|
-
};
|
|
96
|
-
/**
|
|
97
|
-
* React hook for querying content from Asteroid CMS via a flexible GraphQL API.
|
|
98
|
-
*
|
|
99
|
-
* Supports single-entry fetches (`entrySlug`) and paginated/filtered lists,
|
|
100
|
-
* with arbitrarily nested reference expansion and field aliasing.
|
|
101
|
-
*/
|
|
102
|
-
declare function useCmsContent<T = unknown>({ schema_slug, entrySlug, select, fullData, limit, offset, status, filter, search, variables, }: UseCmsContentOptions$1): {
|
|
103
|
-
client: _apollo_client.ApolloClient;
|
|
104
|
-
observable: _apollo_client.ObservableQuery<unknown, _apollo_client.OperationVariables>;
|
|
105
|
-
previousData?: unknown;
|
|
106
|
-
networkStatus: _apollo_client.NetworkStatus;
|
|
107
|
-
startPolling: (pollInterval: number) => void;
|
|
108
|
-
stopPolling: () => void;
|
|
109
|
-
subscribeToMore: _apollo_client.SubscribeToMoreFunction<unknown, _apollo_client.OperationVariables>;
|
|
110
|
-
updateQuery: (mapFn: _apollo_client.UpdateQueryMapFn<unknown, _apollo_client.OperationVariables>) => void;
|
|
111
|
-
refetch: (variables?: Partial<_apollo_client.OperationVariables> | undefined) => Promise<{
|
|
112
|
-
data: unknown;
|
|
113
|
-
error?: _apollo_client.ErrorLike;
|
|
114
|
-
}>;
|
|
115
|
-
variables: _apollo_client.OperationVariables;
|
|
116
|
-
fetchMore: <TFetchData = unknown, TFetchVars extends _apollo_client.OperationVariables = _apollo_client.OperationVariables>(fetchMoreOptions: _apollo_client.ObservableQuery.FetchMoreOptions<unknown, _apollo_client.OperationVariables, TFetchData, TFetchVars>) => Promise<{
|
|
117
|
-
data: TFetchData | undefined;
|
|
118
|
-
error?: _apollo_client.ErrorLike;
|
|
119
|
-
}>;
|
|
120
|
-
dataState: "empty";
|
|
121
|
-
loading: boolean;
|
|
122
|
-
error: _apollo_client.ErrorLike | undefined;
|
|
123
|
-
data: T | undefined;
|
|
124
|
-
} | {
|
|
125
|
-
client: _apollo_client.ApolloClient;
|
|
126
|
-
observable: _apollo_client.ObservableQuery<unknown, _apollo_client.OperationVariables>;
|
|
127
|
-
previousData?: unknown;
|
|
128
|
-
networkStatus: _apollo_client.NetworkStatus;
|
|
129
|
-
startPolling: (pollInterval: number) => void;
|
|
130
|
-
stopPolling: () => void;
|
|
131
|
-
subscribeToMore: _apollo_client.SubscribeToMoreFunction<unknown, _apollo_client.OperationVariables>;
|
|
132
|
-
updateQuery: (mapFn: _apollo_client.UpdateQueryMapFn<unknown, _apollo_client.OperationVariables>) => void;
|
|
133
|
-
refetch: (variables?: Partial<_apollo_client.OperationVariables> | undefined) => Promise<{
|
|
134
|
-
data: unknown;
|
|
135
|
-
error?: _apollo_client.ErrorLike;
|
|
136
|
-
}>;
|
|
137
|
-
variables: _apollo_client.OperationVariables;
|
|
138
|
-
fetchMore: <TFetchData = unknown, TFetchVars extends _apollo_client.OperationVariables = _apollo_client.OperationVariables>(fetchMoreOptions: _apollo_client.ObservableQuery.FetchMoreOptions<unknown, _apollo_client.OperationVariables, TFetchData, TFetchVars>) => Promise<{
|
|
139
|
-
data: TFetchData | undefined;
|
|
140
|
-
error?: _apollo_client.ErrorLike;
|
|
141
|
-
}>;
|
|
142
|
-
dataState: "complete";
|
|
143
|
-
loading: boolean;
|
|
144
|
-
error: _apollo_client.ErrorLike | undefined;
|
|
145
|
-
data: T | undefined;
|
|
146
|
-
} | {
|
|
147
|
-
client: _apollo_client.ApolloClient;
|
|
148
|
-
observable: _apollo_client.ObservableQuery<unknown, _apollo_client.OperationVariables>;
|
|
149
|
-
previousData?: unknown;
|
|
150
|
-
networkStatus: _apollo_client.NetworkStatus;
|
|
151
|
-
startPolling: (pollInterval: number) => void;
|
|
152
|
-
stopPolling: () => void;
|
|
153
|
-
subscribeToMore: _apollo_client.SubscribeToMoreFunction<unknown, _apollo_client.OperationVariables>;
|
|
154
|
-
updateQuery: (mapFn: _apollo_client.UpdateQueryMapFn<unknown, _apollo_client.OperationVariables>) => void;
|
|
155
|
-
refetch: (variables?: Partial<_apollo_client.OperationVariables> | undefined) => Promise<{
|
|
156
|
-
data: unknown;
|
|
157
|
-
error?: _apollo_client.ErrorLike;
|
|
158
|
-
}>;
|
|
159
|
-
variables: _apollo_client.OperationVariables;
|
|
160
|
-
fetchMore: <TFetchData = unknown, TFetchVars extends _apollo_client.OperationVariables = _apollo_client.OperationVariables>(fetchMoreOptions: _apollo_client.ObservableQuery.FetchMoreOptions<unknown, _apollo_client.OperationVariables, TFetchData, TFetchVars>) => Promise<{
|
|
161
|
-
data: TFetchData | undefined;
|
|
162
|
-
error?: _apollo_client.ErrorLike;
|
|
163
|
-
}>;
|
|
164
|
-
dataState: "streaming";
|
|
165
|
-
loading: boolean;
|
|
166
|
-
error: _apollo_client.ErrorLike | undefined;
|
|
167
|
-
data: T | undefined;
|
|
168
|
-
};
|
|
169
|
-
|
|
170
|
-
type FieldSelector$1 = string | {
|
|
171
|
-
field: string;
|
|
172
|
-
as?: string;
|
|
173
|
-
single?: boolean;
|
|
174
|
-
select?: readonly (FieldSelector$1 | ReferenceExpansion$1)[];
|
|
175
|
-
};
|
|
176
|
-
type ReferenceExpansion$1 = {
|
|
177
|
-
field: string;
|
|
178
|
-
as?: string;
|
|
179
|
-
single?: boolean;
|
|
180
|
-
select?: readonly (FieldSelector$1 | ReferenceExpansion$1)[];
|
|
181
|
-
};
|
|
182
|
-
type MutationType = "create" | "update" | "delete";
|
|
183
|
-
type UseCmsMutateOptions = {
|
|
184
|
-
schema_slug: string;
|
|
185
|
-
entrySlug?: string;
|
|
186
|
-
select?: readonly (FieldSelector$1 | ReferenceExpansion$1)[];
|
|
187
|
-
fullData?: boolean;
|
|
188
|
-
mutationType?: MutationType;
|
|
189
|
-
entryId?: string;
|
|
190
|
-
variables?: Record<string, any>;
|
|
191
|
-
};
|
|
192
|
-
/**
|
|
193
|
-
* React hook for mutating content in Asteroid CMS (`create` / `update` / `delete`).
|
|
194
|
-
* Uses the same selection syntax as `useCmsContent`.
|
|
195
|
-
*/
|
|
196
|
-
declare function useCmsMutate<TData = unknown>({ schema_slug, select, fullData, mutationType, entryId, variables: inputVariables, }: UseCmsMutateOptions): {
|
|
197
|
-
readonly data: TData | undefined;
|
|
198
|
-
readonly loading: boolean;
|
|
199
|
-
readonly called: boolean;
|
|
200
|
-
readonly client: _apollo_client.ApolloClient;
|
|
201
|
-
readonly reset: () => void;
|
|
202
|
-
readonly error: _apollo_client.ErrorLike | undefined;
|
|
203
|
-
readonly mutate: useMutation.MutationFunction<unknown, {
|
|
204
|
-
[x: string]: any;
|
|
205
|
-
}, _apollo_client.ApolloCache, "none">;
|
|
206
|
-
};
|
|
207
|
-
|
|
208
44
|
type FieldSelector = string | {
|
|
209
45
|
field: string;
|
|
210
46
|
as?: string;
|
|
@@ -250,8 +86,6 @@ declare function cmsImage(id: string | undefined, options: {
|
|
|
250
86
|
cmsUrl: string;
|
|
251
87
|
mediaPath?: string;
|
|
252
88
|
}): string;
|
|
253
|
-
/** Hook variant that pulls `cmsUrl`/`mediaPath` from the provider. */
|
|
254
|
-
declare function useCmsImage(): (id?: string) => string;
|
|
255
89
|
|
|
256
90
|
type ReadTimeUnit = "short" | "long";
|
|
257
91
|
interface GetContentReadTimeOptions {
|
|
@@ -307,6 +141,12 @@ interface ParseRichTextOptions {
|
|
|
307
141
|
classMap?: RichTextClassMap;
|
|
308
142
|
/** Tag allowlist override. Defaults to a safe semantic set. */
|
|
309
143
|
allowlist?: ReadonlyArray<string>;
|
|
144
|
+
/**
|
|
145
|
+
* When `true` (default), inject slugified `id` attributes on `<h1>`–`<h6>`
|
|
146
|
+
* tags that don't already have one. Lets ToC anchors resolve from the
|
|
147
|
+
* server-rendered markup without a client-side mutation step.
|
|
148
|
+
*/
|
|
149
|
+
autoHeadingIds?: boolean;
|
|
310
150
|
}
|
|
311
151
|
declare function parseRichText(html: string, options?: ParseRichTextOptions): string;
|
|
312
152
|
/**
|
|
@@ -316,19 +156,41 @@ declare function parseRichText(html: string, options?: ParseRichTextOptions): st
|
|
|
316
156
|
*/
|
|
317
157
|
declare function removeEmptyParagraphs(html: string): string;
|
|
318
158
|
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
159
|
+
/**
|
|
160
|
+
* Heading extraction helpers used to build tables of contents (ToC) from
|
|
161
|
+
* rich-text HTML. Server-safe — no React, no DOM dependency in the HTML
|
|
162
|
+
* variant. The DOM variant assigns missing `id`s in-place so anchor links
|
|
163
|
+
* resolve immediately.
|
|
164
|
+
*/
|
|
165
|
+
type HeadingLevel = 1 | 2 | 3 | 4 | 5 | 6;
|
|
166
|
+
interface ExtractedHeading {
|
|
167
|
+
id: string;
|
|
168
|
+
text: string;
|
|
169
|
+
level: HeadingLevel;
|
|
170
|
+
}
|
|
171
|
+
interface ExtractHeadingsOptions {
|
|
172
|
+
/** Levels to include. Defaults to `[2, 3]` — typical doc page outline. */
|
|
173
|
+
levels?: ReadonlyArray<HeadingLevel>;
|
|
174
|
+
/** Custom slug function. Defaults to a lowercase/kebab/diacritic-safe slug. */
|
|
175
|
+
slugify?: (text: string, index: number) => string;
|
|
325
176
|
}
|
|
326
|
-
declare function
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
177
|
+
declare function slugify(text: string): string;
|
|
178
|
+
/**
|
|
179
|
+
* Parse headings out of a raw HTML string. Returns headings in document
|
|
180
|
+
* order with stable, de-duplicated IDs.
|
|
181
|
+
*
|
|
182
|
+
* If a heading already has an `id` attribute, it's preserved verbatim
|
|
183
|
+
* (and reserved so later slugs don't collide with it).
|
|
184
|
+
*/
|
|
185
|
+
declare function extractHeadingsFromHtml(html: string, options?: ExtractHeadingsOptions): ExtractedHeading[];
|
|
186
|
+
/**
|
|
187
|
+
* Walk a rendered DOM subtree, collect headings, and assign missing `id`s
|
|
188
|
+
* in-place so anchor links resolve immediately. Also sets `scrollMarginTop`
|
|
189
|
+
* on each heading when `scrollMarginTop` is provided so navigation lands
|
|
190
|
+
* cleanly below a sticky header.
|
|
191
|
+
*/
|
|
192
|
+
declare function extractHeadingsFromElement(root: HTMLElement, options?: ExtractHeadingsOptions & {
|
|
193
|
+
scrollMarginTop?: number;
|
|
194
|
+
}): ExtractedHeading[];
|
|
333
195
|
|
|
334
|
-
export { type AsteroidCMSConfig,
|
|
196
|
+
export { type AsteroidCMSConfig, type CmsSearchCondition, type ContentStatus, type ExtractHeadingsOptions, type ExtractedHeading, type FieldSelector, type HeadingLevel, type ParseRichTextOptions, type ReferenceExpansion, type ResolvedAsteroidCMSConfig, type RichTextClassKey, type RichTextClassMap, type UseCmsContentOptions, buildCmsQuery, cmsImage, createApolloClient, extractHeadingsFromElement, extractHeadingsFromHtml, fetchCmsContent, getContentReadTime, parseRichText, removeEmptyParagraphs, slugify };
|