@driftime/sanity-plugin-handbook 0.2.1 → 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.
Files changed (69) hide show
  1. package/README.md +130 -77
  2. package/dist/index.d.ts +203 -110
  3. package/dist/index.d.ts.map +1 -0
  4. package/dist/index.js +2790 -2064
  5. package/dist/index.js.map +1 -1
  6. package/package.json +36 -34
  7. package/dist/index.cjs +0 -2094
  8. package/dist/index.cjs.map +0 -1
  9. package/dist/index.d.cts +0 -143
  10. package/src/blocks/callout/block.tsx +0 -56
  11. package/src/blocks/callout/content.tsx +0 -41
  12. package/src/blocks/callout/preview.tsx +0 -15
  13. package/src/blocks/code/block.tsx +0 -18
  14. package/src/blocks/code/content.tsx +0 -18
  15. package/src/blocks/code/preview.tsx +0 -17
  16. package/src/blocks/horizontal-rule/block.tsx +0 -5
  17. package/src/blocks/horizontal-rule/content.tsx +0 -8
  18. package/src/blocks/horizontal-rule/preview.tsx +0 -5
  19. package/src/blocks/image/block.tsx +0 -23
  20. package/src/blocks/image/content.tsx +0 -31
  21. package/src/blocks/image/preview.tsx +0 -23
  22. package/src/blocks/video/block.tsx +0 -21
  23. package/src/blocks/video/content.tsx +0 -37
  24. package/src/blocks/video/preview.tsx +0 -21
  25. package/src/components/content-panel.tsx +0 -58
  26. package/src/components/decorators.tsx +0 -53
  27. package/src/components/document-types.tsx +0 -49
  28. package/src/components/field.tsx +0 -530
  29. package/src/components/guide-content.tsx +0 -117
  30. package/src/components/guides.tsx +0 -36
  31. package/src/components/pane-header.tsx +0 -26
  32. package/src/components/sidebar-group.tsx +0 -30
  33. package/src/components/sidebar-tab.tsx +0 -78
  34. package/src/contexts/handbook-context.tsx +0 -84
  35. package/src/getting-started/document-types.tsx +0 -104
  36. package/src/getting-started/how-to-use.tsx +0 -95
  37. package/src/getting-started/overview.tsx +0 -65
  38. package/src/hooks/use-container-width.ts +0 -41
  39. package/src/hooks/use-handbook-configuration.ts +0 -74
  40. package/src/hooks/use-is-handbook-editor.ts +0 -18
  41. package/src/icons/book-open-text.tsx +0 -22
  42. package/src/icons/book-text.tsx +0 -19
  43. package/src/icons/code.tsx +0 -18
  44. package/src/icons/image.tsx +0 -19
  45. package/src/icons/info.tsx +0 -19
  46. package/src/icons/layout-grid.tsx +0 -20
  47. package/src/icons/lightbulb.tsx +0 -19
  48. package/src/icons/list-plus.tsx +0 -21
  49. package/src/icons/message-circle-question-mark.tsx +0 -19
  50. package/src/icons/minus.tsx +0 -17
  51. package/src/icons/triangle-alert.tsx +0 -19
  52. package/src/icons/video.tsx +0 -18
  53. package/src/index.ts +0 -145
  54. package/src/layouts/content.tsx +0 -13
  55. package/src/layouts/sidebar.tsx +0 -15
  56. package/src/layouts/tool.tsx +0 -205
  57. package/src/lib/handbook-structure.ts +0 -47
  58. package/src/lib/icons.ts +0 -16
  59. package/src/lib/utils.ts +0 -69
  60. package/src/schemas/annotations/link.ts +0 -19
  61. package/src/schemas/blocks/callout.ts +0 -69
  62. package/src/schemas/blocks/code.ts +0 -46
  63. package/src/schemas/blocks/horizontal-rule.ts +0 -31
  64. package/src/schemas/blocks/image.ts +0 -40
  65. package/src/schemas/blocks/video.ts +0 -34
  66. package/src/schemas/guide-content.ts +0 -58
  67. package/src/schemas/types/guide.ts +0 -48
  68. package/src/schemas/types/handbook.ts +0 -86
  69. package/src/types.ts +0 -101
package/dist/index.d.ts CHANGED
@@ -1,52 +1,21 @@
1
- import type { ComponentType } from "react";
2
- import type { CurrentUser } from "sanity";
3
- import type { DocumentDefinition } from "sanity";
4
- import { ListItemBuilder } from "sanity/structure";
5
- import { PluginOptions } from "sanity";
6
- import type { PortableTextBlock } from "sanity";
7
- import type { PortableTextObject } from "sanity";
8
- import type { SanityDocument } from "sanity";
9
- import type { SchemaTypeDefinition } from "sanity";
10
- import type { StructureBuilder } from "sanity/structure";
11
-
12
- /** @public */
13
- export declare interface HandbookBlockDefinition {
14
- /** Sanity schema type definition for the custom block. */
15
- schema: SchemaTypeDefinition;
16
- /** React component for rendering the block in the Handbook viewer. */
17
- component: ComponentType<{
18
- value: PortableTextObject;
19
- }>;
20
- }
21
-
22
- /** @public */
23
- export declare interface HandbookConfig {
24
- /** Title shown in the Studio tool navigation. */
25
- title?: string;
26
- /** Heading displayed at the top of the sidebar. */
27
- sidebarTitle?: string;
28
- /** Document type groups defining the hierarchy. */
29
- groups?: HandbookStructureGroup[];
30
- /** Custom Portable Text block definitions for guide content. */
31
- blocks?: HandbookBlockDefinition[];
32
- /** Email addresses permitted to edit handbook documents. */
33
- editors?: string[];
34
- /** Fallback message shown when a field has no description. */
35
- undocumentedFieldMessage?: string;
36
- }
37
-
38
- /** @public */
39
- export declare interface HandbookGuideGroup {
40
- /** Unique key assigned by Sanity for this array item. */
41
- _key: string;
42
- /** Display title for this group in the sidebar. */
43
- title: string;
44
- /** Ordered array of guide references. */
45
- guides: SanityHandbookGuide[];
1
+ import { CurrentUser, DocumentDefinition, KeyedSegment, PortableTextBlock, PortableTextObject, PortableTextSpan, PortableTextTextBlock, SanityDocument, SchemaTypeDefinition } from "sanity";
2
+ import { ComponentType } from "react";
3
+ import "@sanity/ui";
4
+ import { StructureBuilder } from "sanity/structure";
5
+ declare module "@sanity/types" {
6
+ interface FieldDefinitionBase {
7
+ handbook?: SanityHandbookMetadata;
8
+ }
9
+ interface DocumentDefinition {
10
+ handbook?: SanityHandbookMetadata;
11
+ }
46
12
  }
47
-
48
- /** @public */
49
- export declare interface HandbookMetadata {
13
+ /**
14
+ * Documentation a schema author attaches to a field or document, shown wherever the Handbook renders it.
15
+ *
16
+ * @public
17
+ */
18
+ interface SanityHandbookMetadata {
50
19
  /** Display title override for the field or document. */
51
20
  title?: string;
52
21
  /** Description shown beneath the field or document heading. */
@@ -60,84 +29,208 @@ export declare interface HandbookMetadata {
60
29
  /** Warning displayed as a popover hint. */
61
30
  caution?: string;
62
31
  }
63
-
64
32
  /**
65
- * Creates a Handbook tool for Sanity Studio, providing auto-generated documentation
66
- * for document types and Portable Text guides within the Studio interface.
33
+ * A named part a set of document types plays in the content model, shown as one sidebar section.
67
34
  *
68
35
  * @public
69
- * @param config - Optional plugin configuration.
70
- * @returns Sanity plugin definition.
71
36
  */
72
- export declare function handbookPlugin(config?: HandbookConfig): PluginOptions;
73
-
74
- /**
75
- * Creates Structure tool items for handbook documents.
76
- * Returns an empty array if the current user is not in the editors list
77
- * configured via handbookPlugin.
78
- *
79
- * @public
80
- * @param structureBuilder - The Sanity Structure builder instance.
81
- * @param context - The Structure context containing the current user.
82
- * @returns An array of list items for the handbook singleton and guides list.
83
- */
84
- export declare function handbookStructure(
85
- structureBuilder: StructureBuilder,
86
- context: {
87
- currentUser: CurrentUser | null;
88
- },
89
- ): ListItemBuilder[];
90
-
91
- /** @public */
92
- export declare interface HandbookStructureGroup {
93
- /** Display title for the document type group. */
37
+ interface SanityHandbookDocumentRole {
38
+ /** Display title for the document role. */
94
39
  title: string;
95
- /** Brief description of the group's purpose. */
40
+ /** Brief description of the role's purpose. */
96
41
  description?: string;
97
- /** Document definitions belonging to this group. */
42
+ /** Document definitions filling this role. */
98
43
  documents: DocumentDefinition[];
99
44
  }
100
-
101
- /** @public */
102
- export declare interface SanityHandbook extends SanityDocument {
103
- /** Document type identifier. */
104
- _type: "handbook.handbook";
105
- /** Ordered array of groups, each containing a title and guide references. */
106
- groups: HandbookGuideGroup[];
45
+ /**
46
+ * A Portable Text block a consumer adds to guide content, pairing its schema with how it renders.
47
+ *
48
+ * @public
49
+ */
50
+ interface SanityHandbookBlockDefinition {
51
+ /** Sanity schema type definition for the custom block. */
52
+ schema: SchemaTypeDefinition;
53
+ /** React component for rendering the block in the Handbook viewer. */
54
+ component: ComponentType<{
55
+ value: PortableTextObject;
56
+ }>;
57
+ }
58
+ /**
59
+ * Everything the plugin accepts, of which only the document roles are required.
60
+ *
61
+ * @public
62
+ */
63
+ interface SanityHandbookConfig {
64
+ /** Title shown in the Studio tool navigation. */
65
+ title?: string;
66
+ /** Heading displayed at the top of the sidebar. */
67
+ sidebarTitle?: string;
68
+ /** Document roles, each shown as a labelled section in the sidebar. */
69
+ roles: SanityHandbookDocumentRole[];
70
+ /** Custom Portable Text block definitions for guide content. */
71
+ blocks?: SanityHandbookBlockDefinition[];
72
+ /** Email addresses permitted to edit Handbook documents. */
73
+ editors?: string[];
74
+ /** Fallback message shown when a field has no description. */
75
+ undocumentedFieldMessage?: string;
107
76
  }
108
-
109
- /** @public */
110
- export declare interface SanityHandbookGuide extends SanityDocument {
111
- /** Document type identifier. */
112
- _type: "handbook.guide";
113
- /** Unique key assigned by Sanity for this array item. */
114
- _key: string;
77
+ /**
78
+ * Creates a Handbook tool for Sanity Studio, generating documentation from document type schemas
79
+ * alongside the Portable Text guides authored in the dataset.
80
+ *
81
+ * @param config - Plugin configuration.
82
+ * @returns Sanity plugin definition.
83
+ * @public
84
+ */
85
+ declare const handbookPlugin: import("sanity").Plugin<SanityHandbookConfig>;
86
+ /**
87
+ * Creates the Structure tool items for Handbook documents, yielding nothing when the current user is
88
+ * not permitted to edit them.
89
+ *
90
+ * @param structureBuilder - The Sanity Structure builder instance.
91
+ * @param context - The Structure context carrying the current user.
92
+ * @param editors - Email addresses permitted to edit, defaulting to the configured list.
93
+ * @returns The list items for the Handbook singleton and the guides list.
94
+ * @public
95
+ */
96
+ declare function handbookStructure(structureBuilder: StructureBuilder, context: {
97
+ currentUser: CurrentUser | null;
98
+ }, editors?: string[]): import("sanity/structure").ListItemBuilder[];
99
+ /**
100
+ * Checks whether the current user is permitted to edit Handbook content, treating an absent list as
101
+ * unrestricted access.
102
+ *
103
+ * @param editors - Email addresses permitted to edit, defaulting to the configured list.
104
+ * @returns Whether the current user can edit Handbook documents.
105
+ * @public
106
+ */
107
+ declare function useIsHandbookEditor(editors?: string[]): boolean;
108
+ /** Drops a type's catch-all index signature, so a mistyped field name is an error rather than an unknown value. */
109
+ type Strict<T> = { [K in keyof T as string extends K ? never : number extends K ? never : K]: T[K]; };
110
+ /** Array of objects each carrying the key Sanity assigns to array items, keeping members identifiable. */
111
+ type SanityKeyedArray<T> = (KeyedSegment & T)[];
112
+ /**
113
+ * A single Handbook page, authored as rich text and rendered in the tool.
114
+ *
115
+ * @public
116
+ */
117
+ type SanityHandbookGuide = Strict<SanityDocument> & {
118
+ _type: typeof guideTypeName;
115
119
  /** Display title for this guide. */
116
120
  title: string;
117
121
  /** Brief description shown beneath the guide heading. */
118
122
  description?: string;
119
123
  /** Portable Text content of the guide. */
120
- content: PortableTextBlock[];
121
- }
122
-
124
+ content: SanityKeyedArray<PortableTextBlock>;
125
+ };
126
+ /** Document type name of an individual guide. */
127
+ declare const guideTypeName = "handbook.guide";
123
128
  /**
124
- * Checks whether the current user is permitted to edit handbook content.
125
- * Returns true if no editors list is provided (unrestricted) or if the
126
- * current user's email is in the list.
129
+ * A titled run of guides in the sidebar, holding them in the order they appear.
127
130
  *
128
131
  * @public
129
- * @param editors - Optional list of permitted email addresses.
130
- * @returns Whether the current user can edit handbook documents.
131
132
  */
132
- export declare function useIsHandbookEditor(editors?: string[]): boolean;
133
-
134
- export {};
135
-
136
- declare module "@sanity/types" {
137
- interface FieldDefinitionBase {
138
- handbook?: HandbookMetadata;
139
- }
140
- interface DocumentDefinition {
141
- handbook?: HandbookMetadata;
142
- }
133
+ interface SanityHandbookGuideGroup {
134
+ /** Display title for this group in the sidebar. */
135
+ title: string;
136
+ /** Ordered array of guide references. */
137
+ guides: SanityKeyedArray<SanityHandbookGuide>;
143
138
  }
139
+ /**
140
+ * The singleton naming every guide group and the order the sidebar lists them in.
141
+ *
142
+ * @public
143
+ */
144
+ type SanityHandbook = Strict<SanityDocument> & {
145
+ _type: typeof handbookTypeName;
146
+ /** Ordered array of groups, each containing a title and guide references. */
147
+ groups: SanityKeyedArray<SanityHandbookGuideGroup>;
148
+ };
149
+ /** Document type name of the Handbook singleton. */
150
+ declare const handbookTypeName = "handbook.handbook";
151
+ /** The intent a callout is drawn with, choosing its icon and tone. */
152
+ type CalloutVariant = "tip" | "info" | "warning";
153
+ /**
154
+ * A highlighted message set apart from the surrounding guide text.
155
+ *
156
+ * @public
157
+ */
158
+ type SanityHandbookCallout = Strict<PortableTextObject> & {
159
+ _type: typeof calloutTypeName;
160
+ /** Visual style and intent of the callout. */
161
+ variant: CalloutVariant;
162
+ /** Portable Text content displayed inside the callout, which offers no inline objects. */
163
+ body: SanityKeyedArray<PortableTextTextBlock<PortableTextSpan>>;
164
+ };
165
+ /** Type name of the callout block. */
166
+ declare const calloutTypeName = "handbook.callout";
167
+ /**
168
+ * A block of source code, rendered with syntax highlighting for its language.
169
+ *
170
+ * @public
171
+ */
172
+ type SanityHandbookCode = Strict<PortableTextObject> & {
173
+ _type: typeof codeTypeName;
174
+ /** Source code to display. */
175
+ code?: string;
176
+ /** Programming language used for syntax highlighting. */
177
+ language?: string;
178
+ };
179
+ /** Type name of the code block. */
180
+ declare const codeTypeName = "handbook.code";
181
+ /**
182
+ * A divider between sections of a guide, carrying no authored content of its own.
183
+ *
184
+ * @public
185
+ */
186
+ type SanityHandbookHorizontalRule = Strict<PortableTextObject> & {
187
+ _type: typeof horizontalRuleTypeName;
188
+ };
189
+ /** Type name of the horizontal rule block. */
190
+ declare const horizontalRuleTypeName = "handbook.horizontalRule";
191
+ /**
192
+ * An image placed in a guide, with the caption and alternative text shown alongside it.
193
+ *
194
+ * @public
195
+ */
196
+ type SanityHandbookImage = Strict<PortableTextObject> & {
197
+ _type: typeof imageTypeName;
198
+ /** Uploaded image asset, narrowed by the query to the URL the viewer renders. */
199
+ asset?: {
200
+ url?: string;
201
+ };
202
+ /** Text displayed beneath the image. */
203
+ caption?: string;
204
+ /** Alternative text for screen readers. */
205
+ alt?: string;
206
+ };
207
+ /** Type name of the image block. */
208
+ declare const imageTypeName = "handbook.image";
209
+ /**
210
+ * A video placed in a guide, with the caption shown beneath it.
211
+ *
212
+ * @public
213
+ */
214
+ type SanityHandbookVideo = Strict<PortableTextObject> & {
215
+ _type: typeof videoTypeName;
216
+ /** Uploaded video asset, narrowed by the query to the URL the viewer renders. */
217
+ asset?: {
218
+ url?: string;
219
+ };
220
+ /** Text displayed beneath the video. */
221
+ caption?: string;
222
+ };
223
+ /** Type name of the video block. */
224
+ declare const videoTypeName = "handbook.video";
225
+ /**
226
+ * A web address applied to a run of guide text.
227
+ *
228
+ * @public
229
+ */
230
+ type SanityHandbookLink = Strict<PortableTextObject> & {
231
+ _type: "link";
232
+ /** Web address the link points to. */
233
+ href?: string;
234
+ };
235
+ export { type SanityHandbook, type SanityHandbookBlockDefinition, type SanityHandbookCallout, type SanityHandbookCode, type SanityHandbookConfig, type SanityHandbookDocumentRole, type SanityHandbookGuide, type SanityHandbookGuideGroup, type SanityHandbookHorizontalRule, type SanityHandbookImage, type SanityHandbookLink, type SanityHandbookMetadata, type SanityHandbookVideo, handbookPlugin, handbookStructure, useIsHandbookEditor };
236
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","names":[],"sources":["../src/plugin.ts","../src/lib/structure.ts","../src/hooks/use-is-handbook-editor.ts","../src/types.ts","../src/schemas/types/guide.ts","../src/schemas/types/handbook.ts","../src/blocks/callout/content.tsx","../src/schemas/blocks/callout.ts","../src/schemas/blocks/code.ts","../src/schemas/blocks/horizontal-rule.ts","../src/schemas/blocks/image.ts","../src/schemas/blocks/video.ts","../src/schemas/annotations/link.ts"],"mappings":";;;;;YAoBY;IACR,WAAW;;YAIH;IACR,WAAW;;;;;;;;UASE;;EAEf;;EAEA;;EAEA;;EAEA;;EAEA;;EAEA;;;;;;;UAQe;;EAEf;;EAEA;;EAEA,WAAW;;;;;;;UAQI;;EAEf,QAAQ;;EAER,WAAW;IAAgB,OAAO;;;;;;;;UAQnB;;EAEf;;EAEA;;EAEA,OAAO;;EAEP,SAAS;;EAET;;EAEA;;;;;;;;;;cAWW,iCAAc,OAAA;;;;;;;;;;;iBCpFX,kBACd,kBAAkB,kBAClB;EAAW,aAAa;GACxB,gDAAkB;;;;;;;;;iBCXJ,oBAAoB;;KCNxB,OAAO,QAAQ,WAAW,oBAAoB,2BAA2B,YAAY,IAAI,EAAE;;KAG3F,iBAAiB,MAAM,eAAe;;;;;;KCMtC,sBAAsB,OAAO;EACvC,cAAc;;EAEd;;EAEA;;EAEA,SAAS,iBAAiB;;;cAIf;;;;;;UCVI;;EAEf;;EAEA,QAAQ,iBAAiB;;;;;;;KAQf,iBAAiB,OAAO;EAClC,cAAc;;EAEd,QAAQ,iBAAiB;;;cAId;;KCzBD;;;;;;KCOA,wBAAwB,OAAO;EACzC,cAAc;;EAEd,SAAS;;EAET,MAAM,iBAAiB,sBAAsB;;;cAIlC;;;;;;KCbD,qBAAqB,OAAO;EACtC,cAAc;;EAEd;;EAEA;;;cAIW;;;;;;KCTD,+BAA+B,OAAO;EAChD,cAAc;;;cAIH;;;;;;KCLD,sBAAsB,OAAO;EACvC,cAAc;;EAEd;IAAU;;;EAEV;;EAEA;;;cAIW;;;;;;KCXD,sBAAsB,OAAO;EACvC,cAAc;;EAEd;IAAU;;;EAEV;;;cAIW;;;;;;KCZD,qBAAqB,OAAO;EACtC;;EAEA"}