@driftime/sanity-plugin-handbook 0.1.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/LICENSE +21 -0
- package/README.md +299 -0
- package/dist/index.cjs +1866 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +143 -0
- package/dist/index.d.ts +143 -0
- package/dist/index.js +1870 -0
- package/dist/index.js.map +1 -0
- package/package.json +92 -0
- package/src/blocks/callout/block.tsx +56 -0
- package/src/blocks/callout/content.tsx +39 -0
- package/src/blocks/callout/preview.tsx +15 -0
- package/src/blocks/code/block.tsx +18 -0
- package/src/blocks/code/content.tsx +18 -0
- package/src/blocks/code/preview.tsx +17 -0
- package/src/blocks/horizontal-rule/block.tsx +5 -0
- package/src/blocks/horizontal-rule/content.tsx +8 -0
- package/src/blocks/horizontal-rule/preview.tsx +5 -0
- package/src/blocks/image/block.tsx +23 -0
- package/src/blocks/image/content.tsx +31 -0
- package/src/blocks/image/preview.tsx +23 -0
- package/src/blocks/video/block.tsx +21 -0
- package/src/blocks/video/content.tsx +37 -0
- package/src/blocks/video/preview.tsx +21 -0
- package/src/components/content-panel.tsx +58 -0
- package/src/components/decorators.tsx +53 -0
- package/src/components/document-types.tsx +49 -0
- package/src/components/field.tsx +528 -0
- package/src/components/guide-content.tsx +117 -0
- package/src/components/guides.tsx +37 -0
- package/src/components/pane-header.tsx +26 -0
- package/src/components/sidebar-group.tsx +30 -0
- package/src/components/sidebar-tab.tsx +78 -0
- package/src/contexts/handbook-context.tsx +84 -0
- package/src/getting-started/document-types.tsx +104 -0
- package/src/getting-started/how-to-use.tsx +93 -0
- package/src/getting-started/overview.tsx +64 -0
- package/src/hooks/use-container-width.ts +41 -0
- package/src/hooks/use-handbook-configuration.ts +74 -0
- package/src/hooks/use-is-handbook-editor.ts +18 -0
- package/src/index.ts +145 -0
- package/src/layouts/content.tsx +13 -0
- package/src/layouts/sidebar.tsx +15 -0
- package/src/layouts/tool.tsx +205 -0
- package/src/lib/handbook-structure.ts +46 -0
- package/src/lib/icons.ts +18 -0
- package/src/lib/utils.ts +69 -0
- package/src/schemas/annotations/link.ts +19 -0
- package/src/schemas/blocks/callout.ts +69 -0
- package/src/schemas/blocks/code.ts +46 -0
- package/src/schemas/blocks/horizontal-rule.ts +31 -0
- package/src/schemas/blocks/image.ts +40 -0
- package/src/schemas/blocks/video.ts +34 -0
- package/src/schemas/guide-content.ts +58 -0
- package/src/schemas/types/guide.ts +48 -0
- package/src/schemas/types/handbook.ts +85 -0
- package/src/types.ts +101 -0
package/dist/index.d.cts
ADDED
|
@@ -0,0 +1,143 @@
|
|
|
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[];
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
/** @public */
|
|
49
|
+
export declare interface HandbookMetadata {
|
|
50
|
+
/** Display title override for the field or document. */
|
|
51
|
+
title?: string;
|
|
52
|
+
/** Description shown beneath the field or document heading. */
|
|
53
|
+
description?: string;
|
|
54
|
+
/** Illustrative example value for the field. */
|
|
55
|
+
example?: string;
|
|
56
|
+
/** Helpful tip displayed as a popover hint. */
|
|
57
|
+
tip?: string;
|
|
58
|
+
/** Informational note displayed as a popover hint. */
|
|
59
|
+
info?: string;
|
|
60
|
+
/** Warning displayed as a popover hint. */
|
|
61
|
+
caution?: string;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* Creates a Handbook tool for Sanity Studio, providing auto-generated documentation
|
|
66
|
+
* for document types and Portable Text guides within the Studio interface.
|
|
67
|
+
*
|
|
68
|
+
* @public
|
|
69
|
+
* @param config - Optional plugin configuration.
|
|
70
|
+
* @returns Sanity plugin definition.
|
|
71
|
+
*/
|
|
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. */
|
|
94
|
+
title: string;
|
|
95
|
+
/** Brief description of the group's purpose. */
|
|
96
|
+
description?: string;
|
|
97
|
+
/** Document definitions belonging to this group. */
|
|
98
|
+
documents: DocumentDefinition[];
|
|
99
|
+
}
|
|
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[];
|
|
107
|
+
}
|
|
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;
|
|
115
|
+
/** Display title for this guide. */
|
|
116
|
+
title: string;
|
|
117
|
+
/** Brief description shown beneath the guide heading. */
|
|
118
|
+
description?: string;
|
|
119
|
+
/** Portable Text content of the guide. */
|
|
120
|
+
content: PortableTextBlock[];
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
/**
|
|
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.
|
|
127
|
+
*
|
|
128
|
+
* @public
|
|
129
|
+
* @param editors - Optional list of permitted email addresses.
|
|
130
|
+
* @returns Whether the current user can edit handbook documents.
|
|
131
|
+
*/
|
|
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
|
+
}
|
|
143
|
+
}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,143 @@
|
|
|
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[];
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
/** @public */
|
|
49
|
+
export declare interface HandbookMetadata {
|
|
50
|
+
/** Display title override for the field or document. */
|
|
51
|
+
title?: string;
|
|
52
|
+
/** Description shown beneath the field or document heading. */
|
|
53
|
+
description?: string;
|
|
54
|
+
/** Illustrative example value for the field. */
|
|
55
|
+
example?: string;
|
|
56
|
+
/** Helpful tip displayed as a popover hint. */
|
|
57
|
+
tip?: string;
|
|
58
|
+
/** Informational note displayed as a popover hint. */
|
|
59
|
+
info?: string;
|
|
60
|
+
/** Warning displayed as a popover hint. */
|
|
61
|
+
caution?: string;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* Creates a Handbook tool for Sanity Studio, providing auto-generated documentation
|
|
66
|
+
* for document types and Portable Text guides within the Studio interface.
|
|
67
|
+
*
|
|
68
|
+
* @public
|
|
69
|
+
* @param config - Optional plugin configuration.
|
|
70
|
+
* @returns Sanity plugin definition.
|
|
71
|
+
*/
|
|
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. */
|
|
94
|
+
title: string;
|
|
95
|
+
/** Brief description of the group's purpose. */
|
|
96
|
+
description?: string;
|
|
97
|
+
/** Document definitions belonging to this group. */
|
|
98
|
+
documents: DocumentDefinition[];
|
|
99
|
+
}
|
|
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[];
|
|
107
|
+
}
|
|
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;
|
|
115
|
+
/** Display title for this guide. */
|
|
116
|
+
title: string;
|
|
117
|
+
/** Brief description shown beneath the guide heading. */
|
|
118
|
+
description?: string;
|
|
119
|
+
/** Portable Text content of the guide. */
|
|
120
|
+
content: PortableTextBlock[];
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
/**
|
|
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.
|
|
127
|
+
*
|
|
128
|
+
* @public
|
|
129
|
+
* @param editors - Optional list of permitted email addresses.
|
|
130
|
+
* @returns Whether the current user can edit handbook documents.
|
|
131
|
+
*/
|
|
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
|
+
}
|
|
143
|
+
}
|