@driftime/sanity-plugin-handbook 0.4.1 → 0.5.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 +4 -4
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +46 -80
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -132,8 +132,8 @@ declare const guideTypeName = "handbook.guide";
|
|
|
132
132
|
interface SanityHandbookGuideGroup {
|
|
133
133
|
/** Group title in the sidebar. */
|
|
134
134
|
title: string;
|
|
135
|
-
/** Guides in the group, in order. */
|
|
136
|
-
guides
|
|
135
|
+
/** Guides in the group, in order, or undefined when none have been added. */
|
|
136
|
+
guides?: SanityKeyedArray<SanityHandbookGuide>;
|
|
137
137
|
}
|
|
138
138
|
/**
|
|
139
139
|
* The Handbook document, listing the guide groups in sidebar order.
|
|
@@ -142,8 +142,8 @@ interface SanityHandbookGuideGroup {
|
|
|
142
142
|
*/
|
|
143
143
|
type SanityHandbook = Strict<SanityDocument> & {
|
|
144
144
|
_type: typeof handbookTypeName;
|
|
145
|
-
/** Guide groups, in order. */
|
|
146
|
-
groups
|
|
145
|
+
/** Guide groups, in order, or undefined when none have been added. */
|
|
146
|
+
groups?: SanityKeyedArray<SanityHandbookGuideGroup>;
|
|
147
147
|
};
|
|
148
148
|
/** Schema type name of the Handbook document. */
|
|
149
149
|
declare const handbookTypeName = "handbook.handbook";
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","names":["ComponentType","DocumentDefinition","PortableTextObject","SchemaTypeDefinition","_0","SanityHandbookMetadata","sideEffect","SanityHandbookDocumentRole","SanityHandbookBlockDefinition","SanityHandbookConfig","handbookPlugin","CurrentUser","StructureBuilder","handbookStructure","useIsHandbookEditor","KeyedSegment","PortableTextBlock","PortableTextObject","PortableTextSpan","PortableTextTextBlock","SanityDocument","Strict","T","K","SanityKeyedArray","SanityHandbookGuide","guideTypeName","SanityHandbookGuideGroup","SanityHandbook","handbookTypeName","SanityHandbookImage","imageTypeName","SanityHandbookVideo","videoTypeName","SanityHandbookCode","codeTypeName","SanityHandbookCalloutVariant","SanityHandbookCallout","calloutTypeName","SanityHandbookHorizontalRule","horizontalRuleTypeName","SanityHandbookLink"],"sources":["../src/plugin.ts","../src/lib/structure.ts","../src/hooks/use-is-handbook-editor.ts","../src/types.ts"],"mappings":";;;;YAoBY;;IAER,WAAWK;;YAIH;;IAER,WAAWA;;;;;;;;UASEA;;EAEf;;EAEA;;EAEA;;EAEA;;EAEA;;EAEA;;;;;;;UAQeE;;EAEf;;EAEA;;EAEA,WAAWN;;;;;;;UAQIO;;EAEf,QAAQL;;EAER,WAAWH;IAAgB,OAAOE;;;;;;;;UAQnBO;;EAEf;;EAEA;;EAEA,OAAOF;;EAEP,SAASC;;EAET;;EAEA;;;;;;;;;;qBAWWE,iCAAc,OAAAD;;;;;;;;;;wBCxFXI,kBACd,kBAAkBD,kBAClB;EAAW,aAAaD;GACxB,gDAAkB;;;;;;;;wBCVJG,oBAAoB;;KCDxBO,OAAO,QAAQ,WAAWC,oBAAoBC,2BAA2BA,YAAYA,IAAID,EAAEC;;KAG3FC,iBAAiB,MAAMT,eAAeO;;;;;;KAOtCG,sBAAsBJ,OAAOD;EACvC,cAAcM;;EAEd;;EAEA;;EAEA,SAASF,iBAAiBR;;;cAIfU;;;;;;UAOIC;;EAEf;;EAEA,
|
|
1
|
+
{"version":3,"file":"index.d.ts","names":["ComponentType","DocumentDefinition","PortableTextObject","SchemaTypeDefinition","_0","SanityHandbookMetadata","sideEffect","SanityHandbookDocumentRole","SanityHandbookBlockDefinition","SanityHandbookConfig","handbookPlugin","CurrentUser","StructureBuilder","handbookStructure","useIsHandbookEditor","KeyedSegment","PortableTextBlock","PortableTextObject","PortableTextSpan","PortableTextTextBlock","SanityDocument","Strict","T","K","SanityKeyedArray","SanityHandbookGuide","guideTypeName","SanityHandbookGuideGroup","SanityHandbook","handbookTypeName","SanityHandbookImage","imageTypeName","SanityHandbookVideo","videoTypeName","SanityHandbookCode","codeTypeName","SanityHandbookCalloutVariant","SanityHandbookCallout","calloutTypeName","SanityHandbookHorizontalRule","horizontalRuleTypeName","SanityHandbookLink"],"sources":["../src/plugin.ts","../src/lib/structure.ts","../src/hooks/use-is-handbook-editor.ts","../src/types.ts"],"mappings":";;;;YAoBY;;IAER,WAAWK;;YAIH;;IAER,WAAWA;;;;;;;;UASEA;;EAEf;;EAEA;;EAEA;;EAEA;;EAEA;;EAEA;;;;;;;UAQeE;;EAEf;;EAEA;;EAEA,WAAWN;;;;;;;UAQIO;;EAEf,QAAQL;;EAER,WAAWH;IAAgB,OAAOE;;;;;;;;UAQnBO;;EAEf;;EAEA;;EAEA,OAAOF;;EAEP,SAASC;;EAET;;EAEA;;;;;;;;;;qBAWWE,iCAAc,OAAAD;;;;;;;;;;wBCxFXI,kBACd,kBAAkBD,kBAClB;EAAW,aAAaD;GACxB,gDAAkB;;;;;;;;wBCVJG,oBAAoB;;KCDxBO,OAAO,QAAQ,WAAWC,oBAAoBC,2BAA2BA,YAAYA,IAAID,EAAEC;;KAG3FC,iBAAiB,MAAMT,eAAeO;;;;;;KAOtCG,sBAAsBJ,OAAOD;EACvC,cAAcM;;EAEd;;EAEA;;EAEA,SAASF,iBAAiBR;;;cAIfU;;;;;;UAOIC;;EAEf;;EAEA,SAASH,iBAAiBC;;;;;;;KAQhBG,iBAAiBP,OAAOD;EAClC,cAAcS;;EAEd,SAASL,iBAAiBG;;;cAIfE;;;;;;KAODC,sBAAsBT,OAAOJ;EACvC,cAAcc;;EAEd;IAAU;;;EAEV;;EAEA;;;cAIWA;;;;;;KAODC,sBAAsBX,OAAOJ;EACvC,cAAcgB;;EAEd;IAAU;;;EAEV;;;cAIWA;;;;;;KAODC,qBAAqBb,OAAOJ;EACtC,cAAckB;;EAEd;;EAEA;;;cAIWA;;;;;;KAODC;;;;;;KAOAC,wBAAwBhB,OAAOJ;EACzC,cAAcqB;;EAEd,SAASF;;EAET,MAAMZ,iBAAiBL,sBAAsBD;;;cAIlCoB;;;;;;KAODC,+BAA+BlB,OAAOJ;EAChD,cAAcuB;;;cAIHA;;;;;;KAODC,qBAAqBpB,OAAOJ;EACtC;;EAEA"}
|
package/dist/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { createContext, createElement, useContext, useEffect, useRef, useState } from "react";
|
|
2
|
-
import { CommandList, PreviewCard, SanityDefaultPreview, defineArrayMember, defineField, definePlugin, defineType,
|
|
2
|
+
import { CommandList, PreviewCard, SanityDefaultPreview, defineArrayMember, defineField, definePlugin, defineType, useCurrentUser, useDocumentStore, useSchema } from "sanity";
|
|
3
3
|
import { c } from "react/compiler-runtime";
|
|
4
4
|
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
5
5
|
import { Box, Button, Card, Flex, Heading, Layer, LayerProvider, Stack, Text, useClickOutsideEvent, useElementSize, useTheme_v2 } from "@sanity/ui";
|
|
@@ -177,71 +177,46 @@ const contentSpacing = {
|
|
|
177
177
|
list: 32,
|
|
178
178
|
nestedList: 12,
|
|
179
179
|
rule: 40
|
|
180
|
-
}, assetUrlFragment = "\"asset\": { \"url\": asset.asset->url }",
|
|
181
|
-
...,
|
|
182
|
-
content[] { ..., ${`
|
|
183
|
-
_type == "${imageTypeName}" => { ..., ${assetUrlFragment} },
|
|
184
|
-
_type == "${videoTypeName}" => { ..., ${assetUrlFragment} }
|
|
185
|
-
`} }
|
|
186
|
-
}`;
|
|
187
|
-
/**
|
|
188
|
-
* Defines a GROQ query typed with its result, so fetches infer the result type.
|
|
189
|
-
*
|
|
190
|
-
* @param query - The GROQ query.
|
|
191
|
-
* @returns The query, typed with its result.
|
|
192
|
-
*/
|
|
193
|
-
function defineTypedQuery(query) {
|
|
194
|
-
return query;
|
|
195
|
-
}
|
|
196
|
-
/**
|
|
197
|
-
* Runs a typed query, returning undefined instead of null when nothing matches.
|
|
198
|
-
*
|
|
199
|
-
* @param client - The Sanity client.
|
|
200
|
-
* @param query - The typed query.
|
|
201
|
-
* @returns The result, or undefined when nothing matches.
|
|
202
|
-
*/
|
|
203
|
-
async function fetchQuery(client, query) {
|
|
204
|
-
return await client.fetch(query) ?? void 0;
|
|
205
|
-
}
|
|
206
|
-
/** Handbook document with its guide references expanded. */
|
|
207
|
-
const handbookQuery = defineTypedQuery(`
|
|
180
|
+
}, assetUrlFragment = "\"asset\": { \"url\": asset.asset->url }", handbookQuery = `
|
|
208
181
|
*[_type == "${handbookTypeName}"][0] {
|
|
209
182
|
...,
|
|
210
183
|
groups[] {
|
|
211
184
|
...,
|
|
212
185
|
guides[] {
|
|
213
186
|
...,
|
|
214
|
-
${
|
|
187
|
+
${`...@-> {
|
|
188
|
+
...,
|
|
189
|
+
content[] { ..., ${`
|
|
190
|
+
_type == "${imageTypeName}" => { ..., ${assetUrlFragment} },
|
|
191
|
+
_type == "${videoTypeName}" => { ..., ${assetUrlFragment} }
|
|
192
|
+
`} }
|
|
193
|
+
}`}
|
|
215
194
|
}
|
|
216
195
|
}
|
|
217
196
|
}
|
|
218
|
-
|
|
197
|
+
`, handbookDocumentsQuery = `*[_type == "${handbookTypeName}" || _type == "${guideTypeName}"]`;
|
|
219
198
|
/**
|
|
220
|
-
*
|
|
199
|
+
* Reads the published Handbook document with its guides expanded, updating when any Handbook document is published.
|
|
221
200
|
*
|
|
222
|
-
* @returns The Handbook document,
|
|
201
|
+
* @returns The Handbook document, or undefined while it loads or when there isn't one.
|
|
223
202
|
*/
|
|
224
203
|
function useHandbookDocument() {
|
|
225
|
-
let $ = c(
|
|
226
|
-
$[0] ===
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
204
|
+
let $ = c(3), documentStore = useDocumentStore(), [handbook, setHandbook] = useState(), t0, t1;
|
|
205
|
+
return $[0] === documentStore ? (t0 = $[1], t1 = $[2]) : (t0 = () => {
|
|
206
|
+
let subscription = documentStore.listenQuery({
|
|
207
|
+
fetch: handbookQuery,
|
|
208
|
+
listen: handbookDocumentsQuery
|
|
209
|
+
}, {}, {
|
|
210
|
+
apiVersion: "2026-01-01",
|
|
211
|
+
perspective: "published",
|
|
212
|
+
throttleTime: 1e3
|
|
213
|
+
}).subscribe((result) => {
|
|
214
|
+
setHandbook(result ?? void 0);
|
|
235
215
|
});
|
|
236
216
|
return () => {
|
|
237
217
|
subscription.unsubscribe();
|
|
238
218
|
};
|
|
239
|
-
},
|
|
240
|
-
let t3;
|
|
241
|
-
return $[4] !== handbook || $[5] !== loading ? (t3 = {
|
|
242
|
-
handbook,
|
|
243
|
-
loading
|
|
244
|
-
}, $[4] = handbook, $[5] = loading, $[6] = t3) : t3 = $[6], t3;
|
|
219
|
+
}, t1 = [documentStore], $[0] = documentStore, $[1] = t0, $[2] = t1), useEffect(t0, t1), handbook;
|
|
245
220
|
}
|
|
246
221
|
const HandbookContext = createContext(void 0);
|
|
247
222
|
/**
|
|
@@ -262,24 +237,23 @@ function useHandbookContext() {
|
|
|
262
237
|
* @returns The provider.
|
|
263
238
|
*/
|
|
264
239
|
function HandbookProvider(t0) {
|
|
265
|
-
let $ = c(
|
|
266
|
-
$[0] !== activeTab || $[1] !== blocks || $[2] !== handbook || $[3] !==
|
|
240
|
+
let $ = c(11), { sidebarTitle, roles, blocks, undocumentedFieldMessage, children } = t0, [activeTab, setActiveTab] = useState(void 0), [sidebarExpanded, setSidebarExpanded] = useState(!0), handbook = useHandbookDocument(), t1;
|
|
241
|
+
$[0] !== activeTab || $[1] !== blocks || $[2] !== handbook || $[3] !== roles || $[4] !== sidebarExpanded || $[5] !== sidebarTitle || $[6] !== undocumentedFieldMessage ? (t1 = {
|
|
267
242
|
sidebarTitle,
|
|
268
243
|
roles,
|
|
269
244
|
blocks,
|
|
270
245
|
undocumentedFieldMessage,
|
|
271
246
|
activeTab,
|
|
272
247
|
sidebarExpanded,
|
|
273
|
-
loading,
|
|
274
248
|
handbook,
|
|
275
249
|
setActiveTab,
|
|
276
250
|
setSidebarExpanded
|
|
277
|
-
}, $[0] = activeTab, $[1] = blocks, $[2] = handbook, $[3] =
|
|
251
|
+
}, $[0] = activeTab, $[1] = blocks, $[2] = handbook, $[3] = roles, $[4] = sidebarExpanded, $[5] = sidebarTitle, $[6] = undocumentedFieldMessage, $[7] = t1) : t1 = $[7];
|
|
278
252
|
let t2;
|
|
279
|
-
return $[
|
|
253
|
+
return $[8] !== children || $[9] !== t1 ? (t2 = /* @__PURE__ */ jsx(HandbookContext, {
|
|
280
254
|
value: t1,
|
|
281
255
|
children
|
|
282
|
-
}), $[
|
|
256
|
+
}), $[8] = children, $[9] = t1, $[10] = t2) : t2 = $[10], t2;
|
|
283
257
|
}
|
|
284
258
|
function PaneHeader(t0) {
|
|
285
259
|
let $ = c(46), backButton, props, style, title;
|
|
@@ -756,7 +730,7 @@ function normalizeField(field, visited = /* @__PURE__ */ new Set()) {
|
|
|
756
730
|
type: typeName,
|
|
757
731
|
title: field.title ?? field.type.title,
|
|
758
732
|
description: field.description ?? field.type.description,
|
|
759
|
-
handbook: field.handbook
|
|
733
|
+
handbook: field.handbook ?? field.type.handbook
|
|
760
734
|
};
|
|
761
735
|
if (!visited.has(typeName)) {
|
|
762
736
|
let next = !opaqueTypes.has(typeName) && typeName !== "object" && typeName !== "array" ? /* @__PURE__ */ new Set([...visited, typeName]) : visited, fieldSource = hasFieldsArray(field) ? field : field.type, ofSource = hasOfArray(field) ? field : field.type;
|
|
@@ -1853,12 +1827,12 @@ function BookOpenTextIcon(props) {
|
|
|
1853
1827
|
* Builds a sidebar section for each guide group.
|
|
1854
1828
|
*
|
|
1855
1829
|
* @param handbook - The Handbook document.
|
|
1856
|
-
* @returns One section per group, with an entry per guide.
|
|
1830
|
+
* @returns One section per group, with an entry per published guide.
|
|
1857
1831
|
*/
|
|
1858
1832
|
function guidesSections(handbook) {
|
|
1859
|
-
return handbook.groups.map(({ title, guides }) => ({
|
|
1833
|
+
return (handbook.groups ?? []).map(({ title, guides }) => ({
|
|
1860
1834
|
title,
|
|
1861
|
-
entries: guides.map((guide) => ({
|
|
1835
|
+
entries: (guides ?? []).filter((guide) => isDefined(guide.title)).map((guide) => ({
|
|
1862
1836
|
id: guide._key,
|
|
1863
1837
|
title: guide.title,
|
|
1864
1838
|
description: guide.description,
|
|
@@ -1873,12 +1847,12 @@ function guidesSections(handbook) {
|
|
|
1873
1847
|
* @returns The built-in pages, the configured document roles, and the guide groups, as sections.
|
|
1874
1848
|
*/
|
|
1875
1849
|
function useSections() {
|
|
1876
|
-
let $ = c(
|
|
1877
|
-
return $[0] !== handbook || $[1] !==
|
|
1850
|
+
let $ = c(3), { roles, handbook } = useHandbookContext(), t0;
|
|
1851
|
+
return $[0] !== handbook || $[1] !== roles ? (t0 = [
|
|
1878
1852
|
...gettingStartedSections(),
|
|
1879
1853
|
...documentTypesSections(roles),
|
|
1880
|
-
...
|
|
1881
|
-
], $[0] = handbook, $[1] =
|
|
1854
|
+
...isDefined(handbook) ? guidesSections(handbook) : []
|
|
1855
|
+
], $[0] = handbook, $[1] = roles, $[2] = t0) : t0 = $[2], t0;
|
|
1882
1856
|
}
|
|
1883
1857
|
function Content(props) {
|
|
1884
1858
|
let $ = c(18), { activeTab } = useHandbookContext(), sections = useSections(), T0, t0, t1, t2, t3, t4;
|
|
@@ -2684,19 +2658,10 @@ function createGuideType(customBlocks = []) {
|
|
|
2684
2658
|
title: "Handbook Guide",
|
|
2685
2659
|
description: "Handbook page written in rich text.",
|
|
2686
2660
|
icon: createSanityIcon(BookOpenTextIcon),
|
|
2687
|
-
preview: {
|
|
2688
|
-
|
|
2689
|
-
|
|
2690
|
-
|
|
2691
|
-
},
|
|
2692
|
-
prepare(selection) {
|
|
2693
|
-
let { title, description } = selection;
|
|
2694
|
-
return {
|
|
2695
|
-
title: title ?? "Untitled",
|
|
2696
|
-
subtitle: description
|
|
2697
|
-
};
|
|
2698
|
-
}
|
|
2699
|
-
},
|
|
2661
|
+
preview: { select: {
|
|
2662
|
+
title: "title",
|
|
2663
|
+
subtitle: "description"
|
|
2664
|
+
} },
|
|
2700
2665
|
fields: [
|
|
2701
2666
|
defineField({
|
|
2702
2667
|
name: "title",
|
|
@@ -2775,16 +2740,17 @@ const handbookType = defineType({
|
|
|
2775
2740
|
title: "title",
|
|
2776
2741
|
guide0: "guides.0.title",
|
|
2777
2742
|
guide1: "guides.1.title",
|
|
2778
|
-
guide2: "guides.2.title"
|
|
2743
|
+
guide2: "guides.2.title",
|
|
2744
|
+
guide3: "guides.3.title"
|
|
2779
2745
|
},
|
|
2780
2746
|
prepare(selection) {
|
|
2781
|
-
let { title, guide0, guide1, guide2 } = selection, shown = [
|
|
2747
|
+
let { title, guide0, guide1, guide2, guide3 } = selection, shown = [
|
|
2782
2748
|
guide0,
|
|
2783
2749
|
guide1,
|
|
2784
2750
|
guide2
|
|
2785
|
-
].filter((guide) => isDefined(guide))
|
|
2751
|
+
].filter((guide) => isDefined(guide));
|
|
2786
2752
|
function formatSubtitle() {
|
|
2787
|
-
return isDefined(shown) ?
|
|
2753
|
+
return isDefined(shown) ? isDefined(guide3) ? `${shown.slice(0, 2).join(", ")}, and others` : new Intl.ListFormat("en-US").format(shown) : "No guides selected";
|
|
2788
2754
|
}
|
|
2789
2755
|
return {
|
|
2790
2756
|
title: title ?? "Group",
|