@sanity/agent-directives 0.0.4 → 0.0.6
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 +113 -60
- package/dist/index.d.ts +2 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -2
- package/dist/index.js.map +1 -1
- package/dist/{formatters.d.ts → lib/formatters.d.ts} +1 -1
- package/dist/lib/formatters.d.ts.map +1 -0
- package/dist/{formatters.js → lib/formatters.js} +1 -1
- package/dist/lib/formatters.js.map +1 -0
- package/dist/{react.d.ts → lib/react.d.ts} +10 -48
- package/dist/lib/react.d.ts.map +1 -0
- package/dist/{react.js → lib/react.js} +22 -96
- package/dist/lib/react.js.map +1 -0
- package/dist/lib/string.d.ts +73 -0
- package/dist/lib/string.d.ts.map +1 -0
- package/dist/lib/string.js +141 -0
- package/dist/lib/string.js.map +1 -0
- package/dist/schemas.d.ts +127 -0
- package/dist/schemas.d.ts.map +1 -0
- package/dist/schemas.js +35 -0
- package/dist/schemas.js.map +1 -0
- package/package.json +8 -9
- package/dist/formatters.d.ts.map +0 -1
- package/dist/formatters.js.map +0 -1
- package/dist/react.d.ts.map +0 -1
- package/dist/react.js.map +0 -1
- package/dist/string.d.ts +0 -34
- package/dist/string.d.ts.map +0 -1
- package/dist/string.js +0 -65
- package/dist/string.js.map +0 -1
package/README.md
CHANGED
|
@@ -8,102 +8,155 @@ Shared directive system for Sanity Agent.
|
|
|
8
8
|
pnpm add @sanity/agent-directives
|
|
9
9
|
```
|
|
10
10
|
|
|
11
|
-
## React Usage
|
|
11
|
+
## React Usage
|
|
12
12
|
|
|
13
13
|
```tsx
|
|
14
|
-
//
|
|
14
|
+
// kit.ts
|
|
15
15
|
import { createDirectiveKit } from "@sanity/agent-directives/react";
|
|
16
|
-
import { useThreadApplication } from "../hooks/useThreadResource";
|
|
17
16
|
|
|
18
|
-
export const { defineDirective } = createDirectiveKit({
|
|
19
|
-
useApplication: useThreadApplication,
|
|
17
|
+
export const { defineDirective } = createDirectiveKit<Application>({
|
|
18
|
+
useApplication: (source) => useThreadApplication(source),
|
|
20
19
|
});
|
|
21
|
-
```
|
|
22
20
|
|
|
23
|
-
```tsx
|
|
24
21
|
// directives/Document.tsx
|
|
25
|
-
|
|
22
|
+
export const DocumentDirective = defineDirective(
|
|
23
|
+
"document",
|
|
24
|
+
({ id, application }) => {
|
|
25
|
+
return <DocumentCard id={id} application={application} />;
|
|
26
|
+
},
|
|
27
|
+
);
|
|
26
28
|
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
})
|
|
31
|
-
|
|
29
|
+
// directives/Changes.tsx - no application needed
|
|
30
|
+
export const ChangesDirective = defineDirective(
|
|
31
|
+
"changes",
|
|
32
|
+
({ createdCount, updatedCount }) => (
|
|
33
|
+
<ChangesCard created={createdCount} updated={updatedCount} />
|
|
34
|
+
),
|
|
35
|
+
{ requiresContext: false },
|
|
36
|
+
);
|
|
32
37
|
|
|
33
|
-
|
|
38
|
+
// AgentMessage.tsx
|
|
39
|
+
import { remarkAgentDirectives } from "@sanity/agent-directives/react";
|
|
40
|
+
import ReactMarkdown from "react-markdown";
|
|
41
|
+
|
|
42
|
+
const components = {
|
|
43
|
+
Document: DocumentDirective,
|
|
44
|
+
Changes: ChangesDirective,
|
|
45
|
+
// directive names are converted to PascalCase
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
function AgentMessage({ content }: { content: string }) {
|
|
49
|
+
return (
|
|
50
|
+
<ReactMarkdown
|
|
51
|
+
remarkPlugins={[remarkAgentDirectives]}
|
|
52
|
+
components={components}
|
|
53
|
+
>
|
|
54
|
+
{content}
|
|
55
|
+
</ReactMarkdown>
|
|
56
|
+
);
|
|
57
|
+
}
|
|
58
|
+
```
|
|
34
59
|
|
|
35
|
-
##
|
|
60
|
+
## Server-side Usage
|
|
36
61
|
|
|
37
62
|
```ts
|
|
38
|
-
//
|
|
39
|
-
import {
|
|
63
|
+
// kit.ts
|
|
64
|
+
import {
|
|
65
|
+
createDirectiveKit,
|
|
66
|
+
createRemarkRenderer,
|
|
67
|
+
} from "@sanity/agent-directives/string";
|
|
40
68
|
|
|
41
|
-
interface
|
|
69
|
+
interface MyContext {
|
|
42
70
|
accessToken: string;
|
|
43
71
|
applications: Application[];
|
|
44
72
|
}
|
|
45
73
|
|
|
46
|
-
interface
|
|
74
|
+
interface MyOutput {
|
|
47
75
|
text?: string;
|
|
48
|
-
blocks?:
|
|
76
|
+
blocks?: Block[];
|
|
49
77
|
}
|
|
50
78
|
|
|
51
79
|
export const { defineDirective, renderDirective } = createDirectiveKit<
|
|
52
|
-
|
|
53
|
-
|
|
80
|
+
MyContext,
|
|
81
|
+
MyOutput
|
|
54
82
|
>();
|
|
55
|
-
```
|
|
56
83
|
|
|
57
|
-
|
|
84
|
+
export const remarkRenderDirectives = createRemarkRenderer<MyContext, Block>(
|
|
85
|
+
renderDirective,
|
|
86
|
+
);
|
|
87
|
+
|
|
58
88
|
// directives/document.ts
|
|
59
|
-
|
|
89
|
+
defineDirective("document", async ({ props, context }) => {
|
|
90
|
+
const doc = await fetchDocument(props.id, context.accessToken);
|
|
91
|
+
return { blocks: [linkButton(doc.title, url)] };
|
|
92
|
+
});
|
|
60
93
|
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
);
|
|
68
|
-
```
|
|
94
|
+
// directives/changes.ts - simple text output
|
|
95
|
+
defineDirective("changes", ({ props }) => {
|
|
96
|
+
return {
|
|
97
|
+
text: `Created: ${props.createdCount}, Updated: ${props.updatedCount}`,
|
|
98
|
+
};
|
|
99
|
+
});
|
|
69
100
|
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
101
|
+
// markdown.ts
|
|
102
|
+
import remarkDirective from "remark-directive";
|
|
103
|
+
|
|
104
|
+
async function toMarkdown(content: string, context: MyContext) {
|
|
105
|
+
const collector = { blocks: [] };
|
|
73
106
|
|
|
74
|
-
const
|
|
107
|
+
const processor = unified()
|
|
108
|
+
.use(remarkParse)
|
|
109
|
+
.use(remarkDirective)
|
|
110
|
+
.use(remarkRenderDirectives, context, collector)
|
|
111
|
+
.use(remarkStringify);
|
|
112
|
+
|
|
113
|
+
const file = await processor.process(content);
|
|
114
|
+
return { text: String(file), blocks: collector.blocks };
|
|
115
|
+
}
|
|
75
116
|
```
|
|
76
117
|
|
|
77
|
-
## Formatters
|
|
118
|
+
## Formatters
|
|
119
|
+
|
|
120
|
+
For generating directive strings (agent backend):
|
|
78
121
|
|
|
79
122
|
```ts
|
|
80
|
-
import {
|
|
81
|
-
createDocumentDirective,
|
|
82
|
-
createChangesDirective,
|
|
83
|
-
} from "@sanity/agent-directives/formatters";
|
|
123
|
+
import { createDocumentDirective } from "@sanity/agent-directives/formatters";
|
|
84
124
|
|
|
85
125
|
createDocumentDirective({ id: "doc-123", type: "article" });
|
|
86
126
|
// => '::document{id="doc-123" type="article"}'
|
|
87
|
-
|
|
88
|
-
createChangesDirective({ createdCount: 3, updatedCount: 5 });
|
|
89
|
-
// => '::changes{createdCount="3" updatedCount="5"}'
|
|
90
127
|
```
|
|
91
128
|
|
|
92
|
-
##
|
|
129
|
+
## Adding a New Directive
|
|
130
|
+
|
|
131
|
+
Edit `src/schemas.ts`:
|
|
93
132
|
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
| `changes` | `createdCount`, `updatedCount` |
|
|
133
|
+
```ts
|
|
134
|
+
// 1. Add schema
|
|
135
|
+
export const MyDirectiveSchema = z.object({
|
|
136
|
+
id: z.string(),
|
|
137
|
+
title: z.string().optional(),
|
|
138
|
+
});
|
|
101
139
|
|
|
102
|
-
|
|
140
|
+
// 2. Add to DirectiveSchemas
|
|
141
|
+
export const DirectiveSchemas = {
|
|
142
|
+
// ...existing
|
|
143
|
+
my: MyDirectiveSchema,
|
|
144
|
+
} as const;
|
|
145
|
+
|
|
146
|
+
// 3. Add to DIRECTIVE_NAMES
|
|
147
|
+
export const DIRECTIVE_NAMES = {
|
|
148
|
+
// ...existing
|
|
149
|
+
my: "my",
|
|
150
|
+
} as const;
|
|
151
|
+
|
|
152
|
+
// 4. Add type
|
|
153
|
+
export type MyDirectiveProps = z.infer<typeof MyDirectiveSchema>;
|
|
154
|
+
|
|
155
|
+
// 5. Add to DirectivePropsMap
|
|
156
|
+
export interface DirectivePropsMap {
|
|
157
|
+
// ...existing
|
|
158
|
+
my: MyDirectiveProps;
|
|
159
|
+
}
|
|
160
|
+
```
|
|
103
161
|
|
|
104
|
-
|
|
105
|
-
| ------------------------------------- | ------------------------------------ |
|
|
106
|
-
| `@sanity/agent-directives` | Schemas and formatters |
|
|
107
|
-
| `@sanity/agent-directives/react` | `createDirectiveKit` for React |
|
|
108
|
-
| `@sanity/agent-directives/string` | `createDirectiveKit` for server-side |
|
|
109
|
-
| `@sanity/agent-directives/formatters` | Directive string formatters |
|
|
162
|
+
Then define the render function in your client using `defineDirective('my', ...)`.
|
package/dist/index.d.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
export {
|
|
2
|
-
export {
|
|
1
|
+
export { createChangesDirective, createDocumentDirective, createReleaseDirective, createResourceDirective, createSetDirective, formatDirective, } from './lib/formatters.js';
|
|
2
|
+
export { type ChangesDirectiveProps, ChangesDirectiveSchema, type DefineDirectiveOptions, DIRECTIVE_NAMES, type DirectiveName, type DirectivePropsMap, DirectiveSchemas, type DocumentDirectiveProps, DocumentDirectiveSchema, type ReleaseDirectiveProps, ReleaseDirectiveSchema, type ResourceDirectiveProps, ResourceDirectiveSchema, type SetDirectiveProps, SetDirectiveSchema, } from './schemas.js';
|
|
3
3
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,sBAAsB,EACtB,uBAAuB,EACvB,sBAAsB,EACtB,uBAAuB,EACvB,kBAAkB,EAClB,eAAe,GAChB,MAAM,qBAAqB,CAAA;AAC5B,OAAO,EACL,KAAK,qBAAqB,EAC1B,sBAAsB,EACtB,KAAK,sBAAsB,EAC3B,eAAe,EACf,KAAK,aAAa,EAClB,KAAK,iBAAiB,EACtB,gBAAgB,EAChB,KAAK,sBAAsB,EAC3B,uBAAuB,EACvB,KAAK,qBAAqB,EAC1B,sBAAsB,EACtB,KAAK,sBAAsB,EAC3B,uBAAuB,EACvB,KAAK,iBAAiB,EACtB,kBAAkB,GACnB,MAAM,cAAc,CAAA"}
|
package/dist/index.js
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
export {
|
|
2
|
-
export {
|
|
1
|
+
export { createChangesDirective, createDocumentDirective, createReleaseDirective, createResourceDirective, createSetDirective, formatDirective, } from './lib/formatters.js';
|
|
2
|
+
export { ChangesDirectiveSchema, DIRECTIVE_NAMES, DirectiveSchemas, DocumentDirectiveSchema, ReleaseDirectiveSchema, ResourceDirectiveSchema, SetDirectiveSchema, } from './schemas.js';
|
|
3
3
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,sBAAsB,EACtB,uBAAuB,EACvB,sBAAsB,EACtB,uBAAuB,EACvB,kBAAkB,EAClB,eAAe,GAChB,MAAM,qBAAqB,CAAA;AAC5B,OAAO,EAEL,sBAAsB,EAEtB,eAAe,EAGf,gBAAgB,EAEhB,uBAAuB,EAEvB,sBAAsB,EAEtB,uBAAuB,EAEvB,kBAAkB,GACnB,MAAM,cAAc,CAAA"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { type ChangesDirectiveProps, type DirectiveName, type DocumentDirectiveProps, type ReleaseDirectiveProps, type ResourceDirectiveProps, type SetDirectiveProps } from '
|
|
1
|
+
import { type ChangesDirectiveProps, type DirectiveName, type DocumentDirectiveProps, type ReleaseDirectiveProps, type ResourceDirectiveProps, type SetDirectiveProps } from '../schemas.js';
|
|
2
2
|
export declare function formatDirective(name: DirectiveName, props: Record<string, unknown>): string;
|
|
3
3
|
export declare function createDocumentDirective(props: DocumentDirectiveProps): string;
|
|
4
4
|
export declare function createReleaseDirective(props: ReleaseDirectiveProps): string;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"formatters.d.ts","sourceRoot":"","sources":["../../src/lib/formatters.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,qBAAqB,EAE1B,KAAK,aAAa,EAClB,KAAK,sBAAsB,EAC3B,KAAK,qBAAqB,EAC1B,KAAK,sBAAsB,EAC3B,KAAK,iBAAiB,EACvB,MAAM,eAAe,CAAA;AAStB,wBAAgB,eAAe,CAAC,IAAI,EAAE,aAAa,EAAE,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,MAAM,CAG3F;AAED,wBAAgB,uBAAuB,CAAC,KAAK,EAAE,sBAAsB,GAAG,MAAM,CAE7E;AAED,wBAAgB,sBAAsB,CAAC,KAAK,EAAE,qBAAqB,GAAG,MAAM,CAE3E;AAED,wBAAgB,uBAAuB,CAAC,KAAK,EAAE,sBAAsB,GAAG,MAAM,CAE7E;AAED,wBAAgB,kBAAkB,CAAC,KAAK,EAAE,iBAAiB,GAAG,MAAM,CAEnE;AAED,wBAAgB,sBAAsB,CAAC,KAAK,EAAE,qBAAqB,GAAG,MAAM,CAE3E"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"formatters.js","sourceRoot":"","sources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A;AACxD,CAAC"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { type ComponentType, type ReactNode } from 'react';
|
|
1
|
+
import type { ComponentType, ReactNode } from 'react';
|
|
3
2
|
import type { Processor } from 'unified';
|
|
4
3
|
import type { Node } from 'unist';
|
|
4
|
+
import { type DefineDirectiveOptions, type DirectiveName, type DirectivePropsMap } from '../schemas.js';
|
|
5
5
|
type DirectiveProps<T extends DirectiveName> = DirectivePropsMap[T];
|
|
6
6
|
export interface NodeProps {
|
|
7
7
|
node?: {
|
|
@@ -11,37 +11,24 @@ export interface NodeProps {
|
|
|
11
11
|
export type DirectiveRenderProps<TName extends DirectiveName, TApplication = undefined, TRequiresApplication extends boolean = true> = DirectiveProps<TName> & (TRequiresApplication extends true ? TApplication extends undefined ? {} : {
|
|
12
12
|
application: TApplication;
|
|
13
13
|
} : {});
|
|
14
|
-
export
|
|
15
|
-
/**
|
|
16
|
-
* Whether this directive requires application context.
|
|
17
|
-
* If true (default), the directive will not render if application is unavailable.
|
|
18
|
-
* If false, the directive renders without application injection.
|
|
19
|
-
*/
|
|
20
|
-
requiresApplication?: boolean;
|
|
21
|
-
}
|
|
14
|
+
export type { DefineDirectiveOptions };
|
|
22
15
|
export type DirectiveComponentProps<TName extends DirectiveName> = DirectiveProps<TName> & {
|
|
23
16
|
source?: string;
|
|
24
17
|
} & NodeProps;
|
|
25
|
-
export declare function remarkAgentDirectives(this: Processor): (tree: Node) => void;
|
|
26
|
-
interface DirectivesStackProps {
|
|
27
|
-
children?: ReactNode;
|
|
28
|
-
}
|
|
29
18
|
/**
|
|
30
|
-
*
|
|
31
|
-
*
|
|
19
|
+
* Remark plugin for agent directive support.
|
|
20
|
+
* Parses and transforms directive syntax into React components.
|
|
32
21
|
*
|
|
33
22
|
* @example
|
|
34
23
|
* ```tsx
|
|
35
|
-
* import {
|
|
24
|
+
* import { remarkAgentDirectives } from '@sanity/agent-directives/react'
|
|
36
25
|
*
|
|
37
|
-
*
|
|
38
|
-
*
|
|
39
|
-
*
|
|
40
|
-
* // Or override with your own
|
|
41
|
-
* components={{ DirectivesStack: MyCustomStack }}
|
|
26
|
+
* <ReactMarkdown remarkPlugins={[remarkAgentDirectives]}>
|
|
27
|
+
* {content}
|
|
28
|
+
* </ReactMarkdown>
|
|
42
29
|
* ```
|
|
43
30
|
*/
|
|
44
|
-
export declare function
|
|
31
|
+
export declare function remarkAgentDirectives(this: Processor): (tree: Node) => void;
|
|
45
32
|
export interface DirectiveKitOptions<TApplication> {
|
|
46
33
|
useApplication?: (source: string | undefined) => TApplication | undefined;
|
|
47
34
|
}
|
|
@@ -51,9 +38,6 @@ export interface DirectiveKitOptions<TApplication> {
|
|
|
51
38
|
* @example
|
|
52
39
|
* ```tsx
|
|
53
40
|
* // kit.ts
|
|
54
|
-
* import { createDirectiveKit } from '@sanity/agent-directives/react'
|
|
55
|
-
* import type { Application } from '@sanity/agent-types'
|
|
56
|
-
*
|
|
57
41
|
* export const { defineDirective } = createDirectiveKit<Application>({
|
|
58
42
|
* useApplication: (source) => useThreadApplication(source),
|
|
59
43
|
* })
|
|
@@ -67,26 +51,4 @@ export interface DirectiveKitOptions<TApplication> {
|
|
|
67
51
|
export declare function createDirectiveKit<TApplication = undefined>(options?: DirectiveKitOptions<TApplication>): {
|
|
68
52
|
defineDirective: <TName extends DirectiveName, TRequiresApplication extends boolean = true>(name: TName, render: (props: DirectiveRenderProps<TName, TApplication, TRequiresApplication>) => ReactNode, directiveOptions?: DefineDirectiveOptions) => ComponentType<DirectiveComponentProps<TName>>;
|
|
69
53
|
};
|
|
70
|
-
/**
|
|
71
|
-
* Default components map including DirectivesStack.
|
|
72
|
-
* Spread this into your components and override as needed.
|
|
73
|
-
*
|
|
74
|
-
* @example
|
|
75
|
-
* ```tsx
|
|
76
|
-
* import { defaultComponents } from '@sanity/agent-directives/react'
|
|
77
|
-
*
|
|
78
|
-
* <ReactMarkdown
|
|
79
|
-
* components={{
|
|
80
|
-
* ...defaultComponents,
|
|
81
|
-
* Document: DocumentDirective,
|
|
82
|
-
* }}
|
|
83
|
-
* >
|
|
84
|
-
* {content}
|
|
85
|
-
* </ReactMarkdown>
|
|
86
|
-
* ```
|
|
87
|
-
*/
|
|
88
|
-
export declare const defaultComponents: {
|
|
89
|
-
readonly DirectivesStack: typeof DirectivesStack;
|
|
90
|
-
};
|
|
91
|
-
export {};
|
|
92
54
|
//# sourceMappingURL=react.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"react.d.ts","sourceRoot":"","sources":["../../src/lib/react.tsx"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,aAAa,EAAE,SAAS,EAAE,MAAM,OAAO,CAAA;AACrD,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,SAAS,CAAA;AACxC,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,OAAO,CAAA;AAEjC,OAAO,EACL,KAAK,sBAAsB,EAC3B,KAAK,aAAa,EAClB,KAAK,iBAAiB,EAEvB,MAAM,eAAe,CAAA;AAMtB,KAAK,cAAc,CAAC,CAAC,SAAS,aAAa,IAAI,iBAAiB,CAAC,CAAC,CAAC,CAAA;AAEnE,MAAM,WAAW,SAAS;IACxB,IAAI,CAAC,EAAE;QAAE,UAAU,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;KAAE,CAAA;CAChD;AAED,MAAM,MAAM,oBAAoB,CAC9B,KAAK,SAAS,aAAa,EAC3B,YAAY,GAAG,SAAS,EACxB,oBAAoB,SAAS,OAAO,GAAG,IAAI,IACzC,cAAc,CAAC,KAAK,CAAC,GACvB,CAAC,oBAAoB,SAAS,IAAI,GAC9B,YAAY,SAAS,SAAS,GAC5B,EAAE,GACF;IAAE,WAAW,EAAE,YAAY,CAAA;CAAE,GAC/B,EAAE,CAAC,CAAA;AAET,YAAY,EAAE,sBAAsB,EAAE,CAAA;AAEtC,MAAM,MAAM,uBAAuB,CAAC,KAAK,SAAS,aAAa,IAAI,cAAc,CAAC,KAAK,CAAC,GAAG;IACzF,MAAM,CAAC,EAAE,MAAM,CAAA;CAChB,GAAG,SAAS,CAAA;AAiKb;;;;;;;;;;;;GAYG;AACH,wBAAgB,qBAAqB,CAAC,IAAI,EAAE,SAAS,UA9HrC,IAAI,UA0InB;AAMD,MAAM,WAAW,mBAAmB,CAAC,YAAY;IAC/C,cAAc,CAAC,EAAE,CAAC,MAAM,EAAE,MAAM,GAAG,SAAS,KAAK,YAAY,GAAG,SAAS,CAAA;CAC1E;AAED;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,kBAAkB,CAAC,YAAY,GAAG,SAAS,EACzD,OAAO,GAAE,mBAAmB,CAAC,YAAY,CAAM;sBAK7C,KAAK,SAAS,aAAa,EAC3B,oBAAoB,SAAS,OAAO,eAE9B,KAAK,UACH,CAAC,KAAK,EAAE,oBAAoB,CAAC,KAAK,EAAE,YAAY,EAAE,oBAAoB,CAAC,KAAK,SAAS,qBAC3E,sBAAsB,KACvC,aAAa,CAAC,uBAAuB,CAAC,KAAK,CAAC,CAAC;EAgCjD"}
|
|
@@ -1,9 +1,8 @@
|
|
|
1
|
-
import { DirectiveSchemas } from '@sanity/agent-types';
|
|
2
1
|
import { pascalCase } from 'es-toolkit';
|
|
3
2
|
import { directiveFromMarkdown, directiveToMarkdown } from 'mdast-util-directive';
|
|
4
3
|
import { directive } from 'micromark-extension-directive';
|
|
5
|
-
import { Children, createElement, useState, } from 'react';
|
|
6
4
|
import { visit } from 'unist-util-visit';
|
|
5
|
+
import { DirectiveSchemas, } from '../schemas.js';
|
|
7
6
|
const DIRECTIVE_TYPES = ['textDirective', 'leafDirective', 'containerDirective'];
|
|
8
7
|
const isDirectiveNode = (node) => 'name' in node &&
|
|
9
8
|
typeof node.name === 'string' &&
|
|
@@ -21,7 +20,6 @@ const isListItemWithOnlyDirective = (node) => {
|
|
|
21
20
|
/**
|
|
22
21
|
* Remark plugin that transforms directive syntax into React components.
|
|
23
22
|
*
|
|
24
|
-
* Features:
|
|
25
23
|
* - Validates directive names (letters and hyphens only)
|
|
26
24
|
* - Extracts directives from list items
|
|
27
25
|
* - Groups consecutive leaf directives into DirectivesStack wrappers
|
|
@@ -124,73 +122,31 @@ function remarkDirectivesTransform() {
|
|
|
124
122
|
});
|
|
125
123
|
};
|
|
126
124
|
}
|
|
127
|
-
export function remarkAgentDirectives() {
|
|
128
|
-
// Set up micromark extensions for parsing directive syntax (from remark-directive)
|
|
129
|
-
const data = this.data();
|
|
130
|
-
const micromarkExtensions = data.micromarkExtensions || (data.micromarkExtensions = []);
|
|
131
|
-
const fromMarkdownExtensions = data.fromMarkdownExtensions || (data.fromMarkdownExtensions = []);
|
|
132
|
-
const toMarkdownExtensions = data.toMarkdownExtensions || (data.toMarkdownExtensions = []);
|
|
133
|
-
micromarkExtensions.push(directive());
|
|
134
|
-
fromMarkdownExtensions.push(directiveFromMarkdown());
|
|
135
|
-
toMarkdownExtensions.push(directiveToMarkdown());
|
|
136
|
-
// Return our transformer for processing the parsed directives
|
|
137
|
-
return remarkDirectivesTransform();
|
|
138
|
-
}
|
|
139
|
-
const stackStyles = {
|
|
140
|
-
display: 'flex',
|
|
141
|
-
flexDirection: 'column',
|
|
142
|
-
gap: '1px',
|
|
143
|
-
borderRadius: '8px',
|
|
144
|
-
overflow: 'hidden',
|
|
145
|
-
boxShadow: '0 1px 3px rgba(0, 0, 0, 0.1)',
|
|
146
|
-
margin: '8px 0',
|
|
147
|
-
};
|
|
148
|
-
const collapsedStackStyles = {
|
|
149
|
-
...stackStyles,
|
|
150
|
-
maxHeight: '280px',
|
|
151
|
-
overflowY: 'auto',
|
|
152
|
-
};
|
|
153
|
-
const expandButtonStyles = {
|
|
154
|
-
display: 'flex',
|
|
155
|
-
justifyContent: 'flex-end',
|
|
156
|
-
padding: '4px 0',
|
|
157
|
-
};
|
|
158
|
-
const buttonStyles = {
|
|
159
|
-
background: 'none',
|
|
160
|
-
border: 'none',
|
|
161
|
-
padding: '4px 8px',
|
|
162
|
-
cursor: 'pointer',
|
|
163
|
-
fontSize: '12px',
|
|
164
|
-
color: 'inherit',
|
|
165
|
-
opacity: 0.7,
|
|
166
|
-
};
|
|
167
125
|
/**
|
|
168
|
-
*
|
|
169
|
-
*
|
|
126
|
+
* Remark plugin for agent directive support.
|
|
127
|
+
* Parses and transforms directive syntax into React components.
|
|
170
128
|
*
|
|
171
129
|
* @example
|
|
172
130
|
* ```tsx
|
|
173
|
-
* import {
|
|
174
|
-
*
|
|
175
|
-
* // Use default
|
|
176
|
-
* components={{ DirectivesStack }}
|
|
131
|
+
* import { remarkAgentDirectives } from '@sanity/agent-directives/react'
|
|
177
132
|
*
|
|
178
|
-
*
|
|
179
|
-
*
|
|
133
|
+
* <ReactMarkdown remarkPlugins={[remarkAgentDirectives]}>
|
|
134
|
+
* {content}
|
|
135
|
+
* </ReactMarkdown>
|
|
180
136
|
* ```
|
|
181
137
|
*/
|
|
182
|
-
export function
|
|
183
|
-
const
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
if (!
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
138
|
+
export function remarkAgentDirectives() {
|
|
139
|
+
const data = this.data();
|
|
140
|
+
if (!data.micromarkExtensions)
|
|
141
|
+
data.micromarkExtensions = [];
|
|
142
|
+
if (!data.fromMarkdownExtensions)
|
|
143
|
+
data.fromMarkdownExtensions = [];
|
|
144
|
+
if (!data.toMarkdownExtensions)
|
|
145
|
+
data.toMarkdownExtensions = [];
|
|
146
|
+
data.micromarkExtensions.push(directive());
|
|
147
|
+
data.fromMarkdownExtensions.push(directiveFromMarkdown());
|
|
148
|
+
data.toMarkdownExtensions.push(directiveToMarkdown());
|
|
149
|
+
return remarkDirectivesTransform();
|
|
194
150
|
}
|
|
195
151
|
/**
|
|
196
152
|
* Creates a directive kit with application injection.
|
|
@@ -198,9 +154,6 @@ export function DirectivesStack({ children }) {
|
|
|
198
154
|
* @example
|
|
199
155
|
* ```tsx
|
|
200
156
|
* // kit.ts
|
|
201
|
-
* import { createDirectiveKit } from '@sanity/agent-directives/react'
|
|
202
|
-
* import type { Application } from '@sanity/agent-types'
|
|
203
|
-
*
|
|
204
157
|
* export const { defineDirective } = createDirectiveKit<Application>({
|
|
205
158
|
* useApplication: (source) => useThreadApplication(source),
|
|
206
159
|
* })
|
|
@@ -214,16 +167,13 @@ export function DirectivesStack({ children }) {
|
|
|
214
167
|
export function createDirectiveKit(options = {}) {
|
|
215
168
|
const { useApplication } = options;
|
|
216
169
|
function defineDirective(name, render, directiveOptions = {}) {
|
|
217
|
-
const
|
|
170
|
+
const requiresContext = directiveOptions.requiresContext ?? directiveOptions.requiresApplication ?? true;
|
|
218
171
|
function Directive(props) {
|
|
219
172
|
const { node, source, ...rest } = props;
|
|
220
|
-
// If useApplication is provided and this directive requires it, inject application
|
|
221
173
|
const application = useApplication?.(source);
|
|
222
|
-
if (
|
|
174
|
+
if (requiresContext && useApplication && !application)
|
|
223
175
|
return null;
|
|
224
|
-
// Merge node properties with component props (component props take precedence)
|
|
225
176
|
const merged = { ...(node?.properties ?? {}), ...rest };
|
|
226
|
-
// Validate against schema
|
|
227
177
|
const schema = DirectiveSchemas[name];
|
|
228
178
|
const result = schema.safeParse(merged);
|
|
229
179
|
if (!result.success) {
|
|
@@ -232,7 +182,7 @@ export function createDirectiveKit(options = {}) {
|
|
|
232
182
|
}
|
|
233
183
|
const renderProps = {
|
|
234
184
|
...result.data,
|
|
235
|
-
...(
|
|
185
|
+
...(requiresContext && useApplication ? { application } : {}),
|
|
236
186
|
};
|
|
237
187
|
return render(renderProps);
|
|
238
188
|
}
|
|
@@ -241,28 +191,4 @@ export function createDirectiveKit(options = {}) {
|
|
|
241
191
|
}
|
|
242
192
|
return { defineDirective };
|
|
243
193
|
}
|
|
244
|
-
// ============================================================================
|
|
245
|
-
// Convenience: Default Components
|
|
246
|
-
// ============================================================================
|
|
247
|
-
/**
|
|
248
|
-
* Default components map including DirectivesStack.
|
|
249
|
-
* Spread this into your components and override as needed.
|
|
250
|
-
*
|
|
251
|
-
* @example
|
|
252
|
-
* ```tsx
|
|
253
|
-
* import { defaultComponents } from '@sanity/agent-directives/react'
|
|
254
|
-
*
|
|
255
|
-
* <ReactMarkdown
|
|
256
|
-
* components={{
|
|
257
|
-
* ...defaultComponents,
|
|
258
|
-
* Document: DocumentDirective,
|
|
259
|
-
* }}
|
|
260
|
-
* >
|
|
261
|
-
* {content}
|
|
262
|
-
* </ReactMarkdown>
|
|
263
|
-
* ```
|
|
264
|
-
*/
|
|
265
|
-
export const defaultComponents = {
|
|
266
|
-
DirectivesStack,
|
|
267
|
-
};
|
|
268
194
|
//# sourceMappingURL=react.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"react.js","sourceRoot":"","sources":["../../src/lib/react.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,YAAY,CAAA;AACvC,OAAO,EAAE,qBAAqB,EAAE,mBAAmB,EAAE,MAAM,sBAAsB,CAAA;AACjF,OAAO,EAAE,SAAS,EAAE,MAAM,+BAA+B,CAAA;AAIzD,OAAO,EAAE,KAAK,EAAE,MAAM,kBAAkB,CAAA;AACxC,OAAO,EAIL,gBAAgB,GACjB,MAAM,eAAe,CAAA;AA+CtB,MAAM,eAAe,GAAoB,CAAC,eAAe,EAAE,eAAe,EAAE,oBAAoB,CAAC,CAAA;AAEjG,MAAM,eAAe,GAAG,CAAC,IAAU,EAAyB,EAAE,CAC5D,MAAM,IAAI,IAAI;IACd,OAAQ,IAAsB,CAAC,IAAI,KAAK,QAAQ;IAChD,cAAc,CAAC,IAAI,CAAE,IAAsB,CAAC,IAAI,CAAC;IACjD,eAAe,CAAC,QAAQ,CAAC,IAAI,CAAC,IAAqB,CAAC,CAAA;AAEtD,MAAM,2BAA2B,GAAG,CAAC,IAAU,EAAW,EAAE;IAC1D,IAAI,IAAI,CAAC,IAAI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C,eAAe,IAAI,gBAAgB,CAAC,mBAAmB,IAAI,IAAI,CAAA;QAElF,SAAS,SAAS,CAAC,KAAqC;YACtD,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,GAAG,IAAI,EAAE,GAAG,KAAK,CAAA;YAEvC,MAAM,WAAW,GAAG,cAAc,EAAE,CAAC,MAAM,CAAC,CAAA;YAC5C,IAAI,eAAe,IAAI,cAAc,IAAI,CAAC,WAAW;gBAAE,OAAO,IAAI,CAAA;YAElE,MAAM,MAAM,GAAG,EAAE,GAAG,CAAC,IAAI,EAAE,UAAU,IAAI,EAAE,CAAC,EAAE,GAAG,IAAI,EAAE,CAAA;YAEvD,MAAM,MAAM,GAAG,gBAAgB,CAAC,IAAI,CAAC,CAAA;YACrC,MAAM,MAAM,GAAG,MAAM,CAAC,SAAS,CAAC,MAAM,CAAC,CAAA;YACvC,IAAI,CAAC,MAAM,CAAC,OAAO,EAAE,CAAC;gBACpB,OAAO,CAAC,KAAK,CAAC,cAAc,IAAI,qBAAqB,EAAE,MAAM,CAAC,KAAK,CAAC,MAAM,EAAE,CAAC,CAAA;gBAC7E,OAAO,IAAI,CAAA;YACb,CAAC;YAED,MAAM,WAAW,GAAG;gBAClB,GAAI,MAAM,CAAC,IAA8B;gBACzC,GAAG,CAAC,eAAe,IAAI,cAAc,CAAC,CAAC,CAAC,EAAE,WAAW,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;aACK,CAAA;YAEpE,OAAO,MAAM,CAAC,WAAW,CAAC,CAAA;QAC5B,CAAC;QAED,SAAS,CAAC,WAAW,GAAG,aAAa,IAAI,GAAG,CAAA;QAC5C,OAAO,SAAS,CAAA;IAClB,CAAC;IAED,OAAO,EAAE,eAAe,EAAE,CAAA;AAC5B,CAAC"}
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import type { Root } from 'mdast';
|
|
2
|
+
import { type DefineDirectiveOptions, type DirectiveName, type DirectivePropsMap } from '../schemas.js';
|
|
3
|
+
export type { DirectiveName };
|
|
4
|
+
type DirectiveProps<T extends DirectiveName> = DirectivePropsMap[T];
|
|
5
|
+
export interface DirectiveNode {
|
|
6
|
+
type: 'textDirective' | 'leafDirective' | 'containerDirective';
|
|
7
|
+
name: string;
|
|
8
|
+
attributes?: Record<string, string | null | undefined>;
|
|
9
|
+
children?: unknown[];
|
|
10
|
+
}
|
|
11
|
+
export interface DirectiveRenderProps<TName extends DirectiveName, TContext> {
|
|
12
|
+
props: DirectiveProps<TName>;
|
|
13
|
+
context: TContext;
|
|
14
|
+
children: string;
|
|
15
|
+
isInline: boolean;
|
|
16
|
+
}
|
|
17
|
+
export type DirectiveRenderFn<TName extends DirectiveName, TContext, TOutput> = (args: DirectiveRenderProps<TName, TContext>) => TOutput | null | Promise<TOutput | null>;
|
|
18
|
+
export type { DefineDirectiveOptions };
|
|
19
|
+
export interface RegisteredDirective<TContext, TOutput> {
|
|
20
|
+
name: DirectiveName;
|
|
21
|
+
render: DirectiveRenderFn<DirectiveName, TContext, TOutput>;
|
|
22
|
+
options: DefineDirectiveOptions;
|
|
23
|
+
}
|
|
24
|
+
type DirectiveRegistry<TContext, TOutput> = Record<string, RegisteredDirective<TContext, TOutput>>;
|
|
25
|
+
/**
|
|
26
|
+
* Creates a directive kit for server-side rendering.
|
|
27
|
+
*
|
|
28
|
+
* @example
|
|
29
|
+
* ```ts
|
|
30
|
+
* // kit.ts
|
|
31
|
+
* export const { defineDirective, renderDirective } = createDirectiveKit<
|
|
32
|
+
* SlackContext,
|
|
33
|
+
* SlackOutput
|
|
34
|
+
* >()
|
|
35
|
+
*
|
|
36
|
+
* // document.ts
|
|
37
|
+
* defineDirective('document', async ({ props, context }) => {
|
|
38
|
+
* const doc = await fetchDocument(props.id, context.accessToken)
|
|
39
|
+
* return { blocks: [linkButton(doc.title, url)] }
|
|
40
|
+
* })
|
|
41
|
+
* ```
|
|
42
|
+
*/
|
|
43
|
+
export declare function createDirectiveKit<TContext, TOutput>(): {
|
|
44
|
+
defineDirective: <TName extends DirectiveName>(name: TName, render: DirectiveRenderFn<TName, TContext, TOutput>, options?: DefineDirectiveOptions) => RegisteredDirective<TContext, TOutput>;
|
|
45
|
+
renderDirective: (node: DirectiveNode, context: TContext) => Promise<TOutput | null>;
|
|
46
|
+
registry: DirectiveRegistry<TContext, TOutput>;
|
|
47
|
+
};
|
|
48
|
+
export interface DirectiveRenderResult<TBlock = unknown> {
|
|
49
|
+
text?: string;
|
|
50
|
+
blocks?: TBlock[];
|
|
51
|
+
}
|
|
52
|
+
export type DirectiveOutput<TBlock = unknown> = string | DirectiveRenderResult<TBlock> | null;
|
|
53
|
+
export declare function normalizeOutput<TBlock>(output: DirectiveOutput<TBlock>): DirectiveRenderResult<TBlock> | null;
|
|
54
|
+
export interface BlockCollector<TBlock = unknown> {
|
|
55
|
+
blocks: TBlock[];
|
|
56
|
+
}
|
|
57
|
+
type RenderFn<TContext, TOutput> = (node: DirectiveNode, context: TContext) => Promise<TOutput | null>;
|
|
58
|
+
/**
|
|
59
|
+
* Creates a remark plugin that renders directives and collects output blocks.
|
|
60
|
+
*
|
|
61
|
+
* @example
|
|
62
|
+
* ```ts
|
|
63
|
+
* const remarkRenderDirectives = createRemarkRenderer<SlackContext, SlackBlock>(renderDirective)
|
|
64
|
+
*
|
|
65
|
+
* unified()
|
|
66
|
+
* .use(remarkParse)
|
|
67
|
+
* .use(remarkDirective)
|
|
68
|
+
* .use(remarkRenderDirectives, context, collector)
|
|
69
|
+
* .use(remarkStringify)
|
|
70
|
+
* ```
|
|
71
|
+
*/
|
|
72
|
+
export declare function createRemarkRenderer<TContext, TBlock>(renderDirective: RenderFn<TContext, DirectiveRenderResult<TBlock> | null>): (context: TContext, collector: BlockCollector<TBlock>) => (tree: Root) => Promise<void>;
|
|
73
|
+
//# sourceMappingURL=string.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"string.d.ts","sourceRoot":"","sources":["../../src/lib/string.ts"],"names":[],"mappings":"AAAA,OAAO,KA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@ -0,0 +1,141 @@
|
|
|
1
|
+
import { visit } from 'unist-util-visit';
|
|
2
|
+
import { DirectiveSchemas, } from '../schemas.js';
|
|
3
|
+
function extractChildren(node) {
|
|
4
|
+
if (!node.children || !Array.isArray(node.children)) {
|
|
5
|
+
return '';
|
|
6
|
+
}
|
|
7
|
+
function extractText(n) {
|
|
8
|
+
if (!n || typeof n !== 'object')
|
|
9
|
+
return '';
|
|
10
|
+
if ('type' in n && n.type === 'text' && 'value' in n && typeof n.value === 'string') {
|
|
11
|
+
return n.value;
|
|
12
|
+
}
|
|
13
|
+
if ('children' in n && Array.isArray(n.children)) {
|
|
14
|
+
return n.children.map(extractText).join('');
|
|
15
|
+
}
|
|
16
|
+
return '';
|
|
17
|
+
}
|
|
18
|
+
return node.children.map(extractText).join('');
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Creates a directive kit for server-side rendering.
|
|
22
|
+
*
|
|
23
|
+
* @example
|
|
24
|
+
* ```ts
|
|
25
|
+
* // kit.ts
|
|
26
|
+
* export const { defineDirective, renderDirective } = createDirectiveKit<
|
|
27
|
+
* SlackContext,
|
|
28
|
+
* SlackOutput
|
|
29
|
+
* >()
|
|
30
|
+
*
|
|
31
|
+
* // document.ts
|
|
32
|
+
* defineDirective('document', async ({ props, context }) => {
|
|
33
|
+
* const doc = await fetchDocument(props.id, context.accessToken)
|
|
34
|
+
* return { blocks: [linkButton(doc.title, url)] }
|
|
35
|
+
* })
|
|
36
|
+
* ```
|
|
37
|
+
*/
|
|
38
|
+
export function createDirectiveKit() {
|
|
39
|
+
const registry = {};
|
|
40
|
+
function defineDirective(name, render, options = {}) {
|
|
41
|
+
const directive = {
|
|
42
|
+
name,
|
|
43
|
+
render: render,
|
|
44
|
+
options,
|
|
45
|
+
};
|
|
46
|
+
registry[name] = directive;
|
|
47
|
+
return directive;
|
|
48
|
+
}
|
|
49
|
+
async function renderDirective(node, context) {
|
|
50
|
+
const directive = registry[node.name];
|
|
51
|
+
if (!directive)
|
|
52
|
+
return null;
|
|
53
|
+
const schema = DirectiveSchemas[node.name];
|
|
54
|
+
if (!schema)
|
|
55
|
+
return null;
|
|
56
|
+
const result = schema.safeParse(node.attributes ?? {});
|
|
57
|
+
if (!result.success) {
|
|
58
|
+
console.error(`Directive "${node.name}" validation error:`, result.error.format());
|
|
59
|
+
return null;
|
|
60
|
+
}
|
|
61
|
+
return directive.render({
|
|
62
|
+
props: result.data,
|
|
63
|
+
context,
|
|
64
|
+
children: extractChildren(node),
|
|
65
|
+
isInline: node.type === 'textDirective',
|
|
66
|
+
});
|
|
67
|
+
}
|
|
68
|
+
return { defineDirective, renderDirective, registry };
|
|
69
|
+
}
|
|
70
|
+
export function normalizeOutput(output) {
|
|
71
|
+
if (output === null)
|
|
72
|
+
return null;
|
|
73
|
+
if (typeof output === 'string')
|
|
74
|
+
return { text: output };
|
|
75
|
+
return output;
|
|
76
|
+
}
|
|
77
|
+
// ============================================================================
|
|
78
|
+
// Remark Plugin
|
|
79
|
+
// ============================================================================
|
|
80
|
+
const DIRECTIVE_TYPES = ['textDirective', 'leafDirective', 'containerDirective'];
|
|
81
|
+
function isDirectiveNode(node) {
|
|
82
|
+
return (typeof node === 'object' &&
|
|
83
|
+
node !== null &&
|
|
84
|
+
'type' in node &&
|
|
85
|
+
typeof node.type === 'string' &&
|
|
86
|
+
DIRECTIVE_TYPES.includes(node.type) &&
|
|
87
|
+
'name' in node &&
|
|
88
|
+
typeof node.name === 'string');
|
|
89
|
+
}
|
|
90
|
+
/**
|
|
91
|
+
* Creates a remark plugin that renders directives and collects output blocks.
|
|
92
|
+
*
|
|
93
|
+
* @example
|
|
94
|
+
* ```ts
|
|
95
|
+
* const remarkRenderDirectives = createRemarkRenderer<SlackContext, SlackBlock>(renderDirective)
|
|
96
|
+
*
|
|
97
|
+
* unified()
|
|
98
|
+
* .use(remarkParse)
|
|
99
|
+
* .use(remarkDirective)
|
|
100
|
+
* .use(remarkRenderDirectives, context, collector)
|
|
101
|
+
* .use(remarkStringify)
|
|
102
|
+
* ```
|
|
103
|
+
*/
|
|
104
|
+
export function createRemarkRenderer(renderDirective) {
|
|
105
|
+
return function remarkRenderDirectives(context, collector) {
|
|
106
|
+
return async (tree) => {
|
|
107
|
+
const locations = [];
|
|
108
|
+
visit(tree, DIRECTIVE_TYPES, (node, index, parent) => {
|
|
109
|
+
if (!isDirectiveNode(node))
|
|
110
|
+
return;
|
|
111
|
+
if (!parent || typeof index !== 'number')
|
|
112
|
+
return;
|
|
113
|
+
locations.push({ node, index, parent });
|
|
114
|
+
});
|
|
115
|
+
const replacements = await Promise.all(locations.map(async (loc) => ({
|
|
116
|
+
...loc,
|
|
117
|
+
output: normalizeOutput(await renderDirective(loc.node, context)),
|
|
118
|
+
})));
|
|
119
|
+
for (let i = replacements.length - 1; i >= 0; i--) {
|
|
120
|
+
const { node, index, parent, output } = replacements[i];
|
|
121
|
+
if (output?.blocks) {
|
|
122
|
+
collector.blocks.unshift(...output.blocks);
|
|
123
|
+
}
|
|
124
|
+
if (output?.text) {
|
|
125
|
+
parent.children.splice(index, 1, {
|
|
126
|
+
type: 'paragraph',
|
|
127
|
+
children: [{ type: 'text', value: output.text }],
|
|
128
|
+
});
|
|
129
|
+
continue;
|
|
130
|
+
}
|
|
131
|
+
if (node.type === 'containerDirective' && node.children && node.children.length > 0) {
|
|
132
|
+
const containerNode = node;
|
|
133
|
+
parent.children.splice(index, 1, ...containerNode.children);
|
|
134
|
+
continue;
|
|
135
|
+
}
|
|
136
|
+
parent.children.splice(index, 1);
|
|
137
|
+
}
|
|
138
|
+
};
|
|
139
|
+
};
|
|
140
|
+
}
|
|
141
|
+
//# sourceMappingURL=string.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"string.js","sourceRoot":"","sources":["../../src/lib/string.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,KAAK,EAAE,MAAM,kBAAkB,CAAA;AACxC,OAAO,EAIL,gBAAgB,GACjB,MAAM,eAAe,CAAA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AAM,EAAE,CAAC;oBACnB,SAAS,CAAC,MAAM,CAAC,OAAO,CAAC,GAAG,MAAM,CAAC,MAAM,CAAC,CAAA;gBAC5C,CAAC;gBAED,IAAI,MAAM,EAAE,IAAI,EAAE,CAAC;oBACjB,MAAM,CAAC,QAAQ,CAAC,MAAM,CAAC,KAAK,EAAE,CAAC,EAAE;wBAC/B,IAAI,EAAE,WAAW;wBACjB,QAAQ,EAAE,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,CAAC,IAAI,EAAE,CAAC;qBAClC,CAAC,CAAA;oBACjB,SAAQ;gBACV,CAAC;gBAED,IAAI,IAAI,CAAC,IAAI,KAAK,oBAAoB,IAAI,IAAI,CAAC,QAAQ,IAAI,IAAI,CAAC,QAAQ,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;oBACpF,MAAM,aAAa,GAAG,IAAqC,CAAA;oBAC3D,MAAM,CAAC,QAAQ,CAAC,MAAM,CAAC,KAAK,EAAE,CAAC,EAAE,GAAI,aAAa,CAAC,QAA0B,CAAC,CAAA;oBAC9E,SAAQ;gBACV,CAAC;gBAED,MAAM,CAAC,QAAQ,CAAC,MAAM,CAAC,KAAK,EAAE,CAAC,CAAC,CAAA;YAClC,CAAC;QACH,CAAC,CAAA;IACH,CAAC,CAAA;AACH,CAAC"}
|
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
export declare const DocumentDirectiveSchema: z.ZodObject<{
|
|
3
|
+
id: z.ZodString;
|
|
4
|
+
type: z.ZodOptional<z.ZodString>;
|
|
5
|
+
source: z.ZodOptional<z.ZodString>;
|
|
6
|
+
}, "strip", z.ZodTypeAny, {
|
|
7
|
+
id: string;
|
|
8
|
+
type?: string | undefined;
|
|
9
|
+
source?: string | undefined;
|
|
10
|
+
}, {
|
|
11
|
+
id: string;
|
|
12
|
+
type?: string | undefined;
|
|
13
|
+
source?: string | undefined;
|
|
14
|
+
}>;
|
|
15
|
+
export declare const ReleaseDirectiveSchema: z.ZodObject<{
|
|
16
|
+
id: z.ZodString;
|
|
17
|
+
source: z.ZodOptional<z.ZodString>;
|
|
18
|
+
}, "strip", z.ZodTypeAny, {
|
|
19
|
+
id: string;
|
|
20
|
+
source?: string | undefined;
|
|
21
|
+
}, {
|
|
22
|
+
id: string;
|
|
23
|
+
source?: string | undefined;
|
|
24
|
+
}>;
|
|
25
|
+
export declare const ResourceDirectiveSchema: z.ZodObject<{
|
|
26
|
+
source: z.ZodString;
|
|
27
|
+
}, "strip", z.ZodTypeAny, {
|
|
28
|
+
source: string;
|
|
29
|
+
}, {
|
|
30
|
+
source: string;
|
|
31
|
+
}>;
|
|
32
|
+
export declare const SetDirectiveSchema: z.ZodObject<{
|
|
33
|
+
id: z.ZodString;
|
|
34
|
+
}, "strip", z.ZodTypeAny, {
|
|
35
|
+
id: string;
|
|
36
|
+
}, {
|
|
37
|
+
id: string;
|
|
38
|
+
}>;
|
|
39
|
+
export declare const ChangesDirectiveSchema: z.ZodObject<{
|
|
40
|
+
createdCount: z.ZodNumber;
|
|
41
|
+
updatedCount: z.ZodNumber;
|
|
42
|
+
}, "strip", z.ZodTypeAny, {
|
|
43
|
+
createdCount: number;
|
|
44
|
+
updatedCount: number;
|
|
45
|
+
}, {
|
|
46
|
+
createdCount: number;
|
|
47
|
+
updatedCount: number;
|
|
48
|
+
}>;
|
|
49
|
+
export declare const DirectiveSchemas: {
|
|
50
|
+
readonly document: z.ZodObject<{
|
|
51
|
+
id: z.ZodString;
|
|
52
|
+
type: z.ZodOptional<z.ZodString>;
|
|
53
|
+
source: z.ZodOptional<z.ZodString>;
|
|
54
|
+
}, "strip", z.ZodTypeAny, {
|
|
55
|
+
id: string;
|
|
56
|
+
type?: string | undefined;
|
|
57
|
+
source?: string | undefined;
|
|
58
|
+
}, {
|
|
59
|
+
id: string;
|
|
60
|
+
type?: string | undefined;
|
|
61
|
+
source?: string | undefined;
|
|
62
|
+
}>;
|
|
63
|
+
readonly release: z.ZodObject<{
|
|
64
|
+
id: z.ZodString;
|
|
65
|
+
source: z.ZodOptional<z.ZodString>;
|
|
66
|
+
}, "strip", z.ZodTypeAny, {
|
|
67
|
+
id: string;
|
|
68
|
+
source?: string | undefined;
|
|
69
|
+
}, {
|
|
70
|
+
id: string;
|
|
71
|
+
source?: string | undefined;
|
|
72
|
+
}>;
|
|
73
|
+
readonly resource: z.ZodObject<{
|
|
74
|
+
source: z.ZodString;
|
|
75
|
+
}, "strip", z.ZodTypeAny, {
|
|
76
|
+
source: string;
|
|
77
|
+
}, {
|
|
78
|
+
source: string;
|
|
79
|
+
}>;
|
|
80
|
+
readonly set: z.ZodObject<{
|
|
81
|
+
id: z.ZodString;
|
|
82
|
+
}, "strip", z.ZodTypeAny, {
|
|
83
|
+
id: string;
|
|
84
|
+
}, {
|
|
85
|
+
id: string;
|
|
86
|
+
}>;
|
|
87
|
+
readonly changes: z.ZodObject<{
|
|
88
|
+
createdCount: z.ZodNumber;
|
|
89
|
+
updatedCount: z.ZodNumber;
|
|
90
|
+
}, "strip", z.ZodTypeAny, {
|
|
91
|
+
createdCount: number;
|
|
92
|
+
updatedCount: number;
|
|
93
|
+
}, {
|
|
94
|
+
createdCount: number;
|
|
95
|
+
updatedCount: number;
|
|
96
|
+
}>;
|
|
97
|
+
};
|
|
98
|
+
export declare const DIRECTIVE_NAMES: {
|
|
99
|
+
readonly document: "document";
|
|
100
|
+
readonly release: "release";
|
|
101
|
+
readonly resource: "resource";
|
|
102
|
+
readonly set: "set";
|
|
103
|
+
readonly changes: "changes";
|
|
104
|
+
};
|
|
105
|
+
export type DirectiveName = (typeof DIRECTIVE_NAMES)[keyof typeof DIRECTIVE_NAMES];
|
|
106
|
+
export type DocumentDirectiveProps = z.infer<typeof DocumentDirectiveSchema>;
|
|
107
|
+
export type ReleaseDirectiveProps = z.infer<typeof ReleaseDirectiveSchema>;
|
|
108
|
+
export type ResourceDirectiveProps = z.infer<typeof ResourceDirectiveSchema>;
|
|
109
|
+
export type SetDirectiveProps = z.infer<typeof SetDirectiveSchema>;
|
|
110
|
+
export type ChangesDirectiveProps = z.infer<typeof ChangesDirectiveSchema>;
|
|
111
|
+
export interface DirectivePropsMap {
|
|
112
|
+
document: DocumentDirectiveProps;
|
|
113
|
+
release: ReleaseDirectiveProps;
|
|
114
|
+
resource: ResourceDirectiveProps;
|
|
115
|
+
set: SetDirectiveProps;
|
|
116
|
+
changes: ChangesDirectiveProps;
|
|
117
|
+
}
|
|
118
|
+
export interface DefineDirectiveOptions {
|
|
119
|
+
/**
|
|
120
|
+
* Whether this directive requires context/application to render.
|
|
121
|
+
* If true (default), the directive won't render without context.
|
|
122
|
+
*/
|
|
123
|
+
requiresContext?: boolean;
|
|
124
|
+
/** @deprecated Use `requiresContext` instead */
|
|
125
|
+
requiresApplication?: boolean;
|
|
126
|
+
}
|
|
127
|
+
//# sourceMappingURL=schemas.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"schemas.d.ts","sourceRoot":"","sources":["../src/schemas.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAA;AAEvB,eAAO,MAAM,uBAAuB;;;;;;;;;;;;EAIlC,CAAA;AAEF,eAAO,MAAM,sBAAsB;;;;;;;;;EAGjC,CAAA;AAEF,eAAO,MAAM,uBAAuB;;;;;;EAElC,CAAA;AAEF,eAAO,MAAM,kBAAkB;;;;;;EAE7B,CAAA;AAEF,eAAO,MAAM,sBAAsB;;;;;;;;;EAGjC,CAAA;AAEF,eAAO,MAAM,gBAAgB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAMnB,CAAA;AAEV,eAAO,MAAM,eAAe;;;;;;CAMlB,CAAA;AAEV,MAAM,MAAM,aAAa,GAAG,CAAC,OAAO,eAAe,CAAC,CAAC,MAAM,OAAO,eAAe,CAAC,CAAA;AAElF,MAAM,MAAM,sBAAsB,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,uBAAuB,CAAC,CAAA;AAC5E,MAAM,MAAM,qBAAqB,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,sBAAsB,CAAC,CAAA;AAC1E,MAAM,MAAM,sBAAsB,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,uBAAuB,CAAC,CAAA;AAC5E,MAAM,MAAM,iBAAiB,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,kBAAkB,CAAC,CAAA;AAClE,MAAM,MAAM,qBAAqB,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,sBAAsB,CAAC,CAAA;AAE1E,MAAM,WAAW,iBAAiB;IAChC,QAAQ,EAAE,sBAAsB,CAAA;IAChC,OAAO,EAAE,qBAAqB,CAAA;IAC9B,QAAQ,EAAE,sBAAsB,CAAA;IAChC,GAAG,EAAE,iBAAiB,CAAA;IACtB,OAAO,EAAE,qBAAqB,CAAA;CAC/B;AAED,MAAM,WAAW,sBAAsB;IACrC;;;OAGG;IACH,eAAe,CAAC,EAAE,OAAO,CAAA;IACzB,gDAAgD;IAChD,mBAAmB,CAAC,EAAE,OAAO,CAAA;CAC9B"}
|
package/dist/schemas.js
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
export const DocumentDirectiveSchema = z.object({
|
|
3
|
+
id: z.string(),
|
|
4
|
+
type: z.string().optional(),
|
|
5
|
+
source: z.string().optional(),
|
|
6
|
+
});
|
|
7
|
+
export const ReleaseDirectiveSchema = z.object({
|
|
8
|
+
id: z.string(),
|
|
9
|
+
source: z.string().optional(),
|
|
10
|
+
});
|
|
11
|
+
export const ResourceDirectiveSchema = z.object({
|
|
12
|
+
source: z.string(),
|
|
13
|
+
});
|
|
14
|
+
export const SetDirectiveSchema = z.object({
|
|
15
|
+
id: z.string(),
|
|
16
|
+
});
|
|
17
|
+
export const ChangesDirectiveSchema = z.object({
|
|
18
|
+
createdCount: z.coerce.number().min(0),
|
|
19
|
+
updatedCount: z.coerce.number().min(0),
|
|
20
|
+
});
|
|
21
|
+
export const DirectiveSchemas = {
|
|
22
|
+
document: DocumentDirectiveSchema,
|
|
23
|
+
release: ReleaseDirectiveSchema,
|
|
24
|
+
resource: ResourceDirectiveSchema,
|
|
25
|
+
set: SetDirectiveSchema,
|
|
26
|
+
changes: ChangesDirectiveSchema,
|
|
27
|
+
};
|
|
28
|
+
export const DIRECTIVE_NAMES = {
|
|
29
|
+
document: 'document',
|
|
30
|
+
release: 'release',
|
|
31
|
+
resource: 'resource',
|
|
32
|
+
set: 'set',
|
|
33
|
+
changes: 'changes',
|
|
34
|
+
};
|
|
35
|
+
//# sourceMappingURL=schemas.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"schemas.js","sourceRoot":"","sources":["../src/schemas.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAA;AAEvB,MAAM,CAAC,MAAM,uBAAuB,GAAG,CAAC,CAAC,MAAM,CAAC;IAC9C,EAAE,EAAE,CAAC,CAAC,MAAM,EAAE;IACd,IAAI,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE;IAC3B,MAAM,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE;CAC9B,CAAC,CAAA;AAEF,MAAM,CAAC,MAAM,sBAAsB,GAAG,CAAC,CAAC,MAAM,CAAC;IAC7C,EAAE,EAAE,CAAC,CAAC,MAAM,EAAE;IACd,MAAM,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE;CAC9B,CAAC,CAAA;AAEF,MAAM,CAAC,MAAM,uBAAuB,GAAG,CAAC,CAAC,MAAM,CAAC;IAC9C,MAAM,EAAE,CAAC,CAAC,MAAM,EAAE;CACnB,CAAC,CAAA;AAEF,MAAM,CAAC,MAAM,kBAAkB,GAAG,CAAC,CAAC,MAAM,CAAC;IACzC,EAAE,EAAE,CAAC,CAAC,MAAM,EAAE;CACf,CAAC,CAAA;AAEF,MAAM,CAAC,MAAM,sBAAsB,GAAG,CAAC,CAAC,MAAM,CAAC;IAC7C,YAAY,EAAE,CAAC,CAAC,MAAM,CAAC,MAAM,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC;IACtC,YAAY,EAAE,CAAC,CAAC,MAAM,CAAC,MAAM,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC;CACvC,CAAC,CAAA;AAEF,MAAM,CAAC,MAAM,gBAAgB,GAAG;IAC9B,QAAQ,EAAE,uBAAuB;IACjC,OAAO,EAAE,sBAAsB;IAC/B,QAAQ,EAAE,uBAAuB;IACjC,GAAG,EAAE,kBAAkB;IACvB,OAAO,EAAE,sBAAsB;CACvB,CAAA;AAEV,MAAM,CAAC,MAAM,eAAe,GAAG;IAC7B,QAAQ,EAAE,UAAU;IACpB,OAAO,EAAE,SAAS;IAClB,QAAQ,EAAE,UAAU;IACpB,GAAG,EAAE,KAAK;IACV,OAAO,EAAE,SAAS;CACV,CAAA"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sanity/agent-directives",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.6",
|
|
4
4
|
"description": "Shared directive system for Sanity Agent",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"sanity",
|
|
@@ -20,16 +20,16 @@
|
|
|
20
20
|
"types": "./dist/index.d.ts"
|
|
21
21
|
},
|
|
22
22
|
"./formatters": {
|
|
23
|
-
"import": "./dist/formatters.js",
|
|
24
|
-
"types": "./dist/formatters.d.ts"
|
|
23
|
+
"import": "./dist/lib/formatters.js",
|
|
24
|
+
"types": "./dist/lib/formatters.d.ts"
|
|
25
25
|
},
|
|
26
26
|
"./react": {
|
|
27
|
-
"import": "./dist/react.js",
|
|
28
|
-
"types": "./dist/react.d.ts"
|
|
27
|
+
"import": "./dist/lib/react.js",
|
|
28
|
+
"types": "./dist/lib/react.d.ts"
|
|
29
29
|
},
|
|
30
30
|
"./string": {
|
|
31
|
-
"import": "./dist/string.js",
|
|
32
|
-
"types": "./dist/string.d.ts"
|
|
31
|
+
"import": "./dist/lib/string.js",
|
|
32
|
+
"types": "./dist/lib/string.d.ts"
|
|
33
33
|
}
|
|
34
34
|
},
|
|
35
35
|
"main": "./dist/index.js",
|
|
@@ -52,7 +52,7 @@
|
|
|
52
52
|
"zod": "^3.25.76"
|
|
53
53
|
},
|
|
54
54
|
"devDependencies": {
|
|
55
|
-
"@
|
|
55
|
+
"@types/mdast": "^4.0.4",
|
|
56
56
|
"@testing-library/jest-dom": "^6.6.3",
|
|
57
57
|
"@testing-library/react": "^16.0.0",
|
|
58
58
|
"@types/react": "^19.0.0",
|
|
@@ -66,7 +66,6 @@
|
|
|
66
66
|
"vitest": "^3.0.9"
|
|
67
67
|
},
|
|
68
68
|
"peerDependencies": {
|
|
69
|
-
"@sanity/agent-types": "*",
|
|
70
69
|
"react": "^18.0.0 || ^19.0.0"
|
|
71
70
|
},
|
|
72
71
|
"peerDependenciesMeta": {
|
package/dist/formatters.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"formatters.d.ts","sourceRoot":"","sources":["../src/formatters.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,qBAAqB,EAE1B,KAAK,aAAa,EAClB,KAAK,sBAAsB,EAC3B,KAAK,qBAAqB,EAC1B,KAAK,sBAAsB,EAC3B,KAAK,iBAAiB,EACvB,MAAM,qBAAqB,CAAA;AAS5B,wBAAgB,eAAe,CAAC,IAAI,EAAE,aAAa,EAAE,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,MAAM,CAG3F;AAED,wBAAgB,uBAAuB,CAAC,KAAK,EAAE,sBAAsB,GAAG,MAAM,CAE7E;AAED,wBAAgB,sBAAsB,CAAC,KAAK,EAAE,qBAAqB,GAAG,MAAM,CAE3E;AAED,wBAAgB,uBAAuB,CAAC,KAAK,EAA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YAEtE,+EAA+E;YAC/E,MAAM,MAAM,GAAG,EAAE,GAAG,CAAC,IAAI,EAAE,UAAU,IAAI,EAAE,CAAC,EAAE,GAAG,IAAI,EAAE,CAAA;YAEvD,0BAA0B;YAC1B,MAAM,MAAM,GAAG,gBAAgB,CAAC,IAAI,CAAC,CAAA;YACrC,MAAM,MAAM,GAAG,MAAM,CAAC,SAAS,CAAC,MAAM,CAAC,CAAA;YACvC,IAAI,CAAC,MAAM,CAAC,OAAO,EAAE,CAAC;gBACpB,OAAO,CAAC,KAAK,CAAC,cAAc,IAAI,qBAAqB,EAAE,MAAM,CAAC,KAAK,CAAC,MAAM,EAAE,CAAC,CAAA;gBAC7E,OAAO,IAAI,CAAA;YACb,CAAC;YAED,MAAM,WAAW,GAAG;gBAClB,GAAI,MAAM,CAAC,IAA8B;gBACzC,GAAG,CAAC,mBAAmB,IAAI,cAAc,CAAC,CAAC,CAAC,EAAE,WAAW,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;aACC,CAAA;YAEpE,OAAO,MAAM,CAAC,WAAW,CAAC,CAAA;QAC5B,CAAC;QAED,SAAS,CAAC,WAAW,GAAG,aAAa,IAAI,GAAG,CAAA;QAC5C,OAAO,SAAS,CAAA;IAClB,CAAC;IAED,OAAO,EAAE,eAAe,EAAE,CAAA;AAC5B,CAAC;AAED,+EAA+E;AAC/E,kCAAkC;AAClC,+EAA+E;AAE/E;;;;;;;;;;;;;;;;;GAiBG;AACH,MAAM,CAAC,MAAM,iBAAiB,GAAG;IAC/B,eAAe;CACP,CAAA"}
|
package/dist/string.d.ts
DELETED
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
import { type DirectiveName, type DirectivePropsMap } from '@sanity/agent-types';
|
|
2
|
-
type DirectiveProps<T extends DirectiveName> = DirectivePropsMap[T];
|
|
3
|
-
export interface DirectiveNode {
|
|
4
|
-
type: 'textDirective' | 'leafDirective' | 'containerDirective';
|
|
5
|
-
name: string;
|
|
6
|
-
attributes?: Record<string, string | null | undefined>;
|
|
7
|
-
children?: unknown[];
|
|
8
|
-
}
|
|
9
|
-
export interface DirectiveBaseProps {
|
|
10
|
-
children: string;
|
|
11
|
-
isInline: boolean;
|
|
12
|
-
}
|
|
13
|
-
export type DirectiveRenderFn<TName extends DirectiveName, TContext, TOutput> = (props: DirectiveProps<TName> & DirectiveBaseProps & {
|
|
14
|
-
_context: TContext;
|
|
15
|
-
}) => TOutput | null | Promise<TOutput | null>;
|
|
16
|
-
export interface StringDirective<TName extends DirectiveName, TContext, TOutput> {
|
|
17
|
-
name: TName;
|
|
18
|
-
render: DirectiveRenderFn<TName, TContext, TOutput>;
|
|
19
|
-
}
|
|
20
|
-
export type StringDirectiveRegistry<TContext, TOutput> = Record<string, StringDirective<DirectiveName, TContext, TOutput>>;
|
|
21
|
-
export declare function createDirectiveKit<TContext = unknown, TOutput = unknown>(): {
|
|
22
|
-
defineDirective: <TName extends DirectiveName>(name: TName, render: DirectiveRenderFn<TName, TContext, TOutput>) => StringDirective<TName, TContext, TOutput>;
|
|
23
|
-
renderDirective: (node: DirectiveNode, context: TContext) => Promise<TOutput | null>;
|
|
24
|
-
registry: StringDirectiveRegistry<TContext, TOutput>;
|
|
25
|
-
};
|
|
26
|
-
export interface DirectiveRenderResult<TBlock = unknown> {
|
|
27
|
-
text?: string;
|
|
28
|
-
blocks?: TBlock[];
|
|
29
|
-
}
|
|
30
|
-
export type DirectiveOutput<TBlock = unknown> = string | DirectiveRenderResult<TBlock> | null;
|
|
31
|
-
export declare function hasBlocks<TBlock>(output: DirectiveOutput<TBlock>): output is DirectiveRenderResult<TBlock>;
|
|
32
|
-
export declare function normalizeOutput<TBlock>(output: DirectiveOutput<TBlock>): DirectiveRenderResult<TBlock> | null;
|
|
33
|
-
export {};
|
|
34
|
-
//# sourceMappingURL=string.d.ts.map
|
package/dist/string.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"string.d.ts","sourceRoot":"","sources":["../src/string.ts"],"names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,KAAK,EAAE,QAAQ,EAAE,OAAO,CAAC,KAClD,eAAe,CAAC,KAAK,EAAE,QAAQ,EAAE,OAAO,CAAC;4BAMP,aAAa,WAAW,QAAQ,KAAG,OAAO,CAAC,OAAO,GAAG,IAAI,CAAC;;EAgChG;AAED,MAAM,WAAW,qBAAqB,CAAC,MAAM,GAAG,OAAO;IACrD,IAAI,CAAC,EAAE,MAAM,CAAA;IACb,MAAM,CAAC,EAAE,MAAM,EAAE,CAAA;CAClB;AAED,MAAM,MAAM,eAAe,CAAC,MAAM,GAAG,OAAO,IAAI,MAAM,GAAG,qBAAqB,CAAC,MAAM,CAAC,GAAG,IAAI,CAAA;AAE7F,wBAAgB,SAAS,CAAC,MAAM,EAC9B,MAAM,EAAE,eAAe,CAAC,MAAM,CAAC,GAC9B,MAAM,IAAI,qBAAqB,CAAC,MAAM,CAAC,CAEzC;AAED,wBAAgB,eAAe,CAAC,MAAM,EACpC,MAAM,EAAE,eAAe,CAAC,MAAM,CAAC,GAC9B,qBAAqB,CAAC,MAAM,CAAC,GAAG,IAAI,CAQtC"}
|
package/dist/string.js
DELETED
|
@@ -1,65 +0,0 @@
|
|
|
1
|
-
import { DirectiveSchemas } from '@sanity/agent-types';
|
|
2
|
-
function extractChildren(node) {
|
|
3
|
-
if (!node.children || !Array.isArray(node.children)) {
|
|
4
|
-
return '';
|
|
5
|
-
}
|
|
6
|
-
function extractText(n) {
|
|
7
|
-
if (!n || typeof n !== 'object')
|
|
8
|
-
return '';
|
|
9
|
-
if ('type' in n && n.type === 'text' && 'value' in n && typeof n.value === 'string') {
|
|
10
|
-
return n.value;
|
|
11
|
-
}
|
|
12
|
-
if ('children' in n && Array.isArray(n.children)) {
|
|
13
|
-
return n.children.map(extractText).join('');
|
|
14
|
-
}
|
|
15
|
-
return '';
|
|
16
|
-
}
|
|
17
|
-
return node.children.map(extractText).join('');
|
|
18
|
-
}
|
|
19
|
-
export function createDirectiveKit() {
|
|
20
|
-
const registry = {};
|
|
21
|
-
function defineDirective(name, render) {
|
|
22
|
-
const directive = { name, render };
|
|
23
|
-
registry[name] = directive;
|
|
24
|
-
return directive;
|
|
25
|
-
}
|
|
26
|
-
async function renderDirective(node, context) {
|
|
27
|
-
const directive = registry[node.name];
|
|
28
|
-
if (!directive)
|
|
29
|
-
return null;
|
|
30
|
-
const schema = DirectiveSchemas[node.name];
|
|
31
|
-
if (!schema)
|
|
32
|
-
return null;
|
|
33
|
-
const rawProps = {
|
|
34
|
-
...node.attributes,
|
|
35
|
-
children: extractChildren(node),
|
|
36
|
-
isInline: node.type === 'textDirective',
|
|
37
|
-
};
|
|
38
|
-
const result = schema.safeParse(rawProps);
|
|
39
|
-
if (!result.success) {
|
|
40
|
-
console.error(`Directive "${node.name}" validation error:`, result.error.format());
|
|
41
|
-
return null;
|
|
42
|
-
}
|
|
43
|
-
const props = {
|
|
44
|
-
...result.data,
|
|
45
|
-
children: rawProps.children,
|
|
46
|
-
isInline: rawProps.isInline,
|
|
47
|
-
_context: context,
|
|
48
|
-
};
|
|
49
|
-
return directive.render(props);
|
|
50
|
-
}
|
|
51
|
-
return { defineDirective, renderDirective, registry };
|
|
52
|
-
}
|
|
53
|
-
export function hasBlocks(output) {
|
|
54
|
-
return output !== null && typeof output === 'object' && 'blocks' in output;
|
|
55
|
-
}
|
|
56
|
-
export function normalizeOutput(output) {
|
|
57
|
-
if (output === null) {
|
|
58
|
-
return null;
|
|
59
|
-
}
|
|
60
|
-
if (typeof output === 'string') {
|
|
61
|
-
return { text: output };
|
|
62
|
-
}
|
|
63
|
-
return output;
|
|
64
|
-
}
|
|
65
|
-
//# sourceMappingURL=string.js.map
|
package/dist/string.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"string.js","sourceRoot":"","sources":["../src/string.ts"],"names":[],"mappings":"AAAA,OAAO,EAA8C,gBAAgB,EAAE,MAAM,qBAAqB,CAAA;AA8BlG,SAAS,eAAe,CAAC,IAAmB;IAC1C,IAAI,CAAC,IA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