sanity-plugin-markdown 9.0.2 → 9.0.3

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.
@@ -12,13 +12,6 @@ declare global {
12
12
  readonly observable: symbol;
13
13
  }
14
14
  }
15
- /**
16
- * A function type interface that describes a function that accepts one parameter `T`
17
- * and returns another parameter `R`.
18
- *
19
- * Usually used to describe {@link OperatorFunction} - it always takes a single
20
- * parameter (the source Observable) and returns another Observable.
21
- */
22
15
  /**
23
16
  * Used to tag types that is set to `any` as a temporary measure, but should be replaced with proper typings in the future
24
17
  * @internal
@@ -37,7 +30,7 @@ declare interface SanityAssetDocument extends SanityDocument {
37
30
  originalFilename?: string;
38
31
  }
39
32
  /** @internal */
40
- declare type SanityDocument<T extends Record<string, Any> = Record<string, Any>> = { [P in keyof T]: T[P] } & {
33
+ declare type SanityDocument<T extends Record<string, Any> = Record<string, Any>> = { [P in keyof T]: T[P]; } & {
41
34
  _id: string;
42
35
  _rev: string;
43
36
  _type: string;
@@ -0,0 +1 @@
1
+ {"version":3,"file":"commonExports.d.ts","names":[],"sources":["../../../../node_modules/.pnpm/rxjs@7.8.2/node_modules/rxjs/dist/types/internal/types.d.ts","../../../../node_modules/.pnpm/@sanity+client@7.23.0/node_modules/@sanity/client/dist/index.d.ts","../../src/schema.ts","../../src/components/MarkdownInput.tsx","../../src/plugin.tsx"],"x_google_ignoreList":[0,1],"mappings":";;;;;;;;;QAOQ;YACM;aACG;;;;;;;aC0YG;;kBA68IK,4BAA4B;EACnD;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;;;aA8xBkB,eAAe,UAAU,eAAe,OAAO,eAAe,WAC/E,WAAW,IAAI,EAAE;EAElB;EACA;EACA;EACA;EACA;;;;EAIA;;;kBAWuB,iCAAiC;EACxD;IACE;IACA;IACA;IACA;IACA;IACA;IACA;MACE;MACA;MACA;MACA;;IAEF;MACE;MACA,YAAY;MACZ,cAAc;MACd,WAAW;MACX,aAAa;MACb,eAAe;MACf,QAAQ;MACR,UAAU;;IAEZ;MACE;OACC,cAAc;;IAEjB;MACE;OACC,cAAc;;;;;kBAMI;EACvB;EACA;EACA;EACA;;cChsLW;UAEI;;;;;;;;;;;;;;;;;;EAkBf,YAAY,YAAY;;;;;UAMT,2BAA2B,KAAK;EAC/C,aAAa;EACb,UAAU;;;YAKO;IACf,UAAU;;;cAID;;;IAAA,KAAA;UC0CI,2BAA2B;;;;;;;EAO1C,gBAAgB,KAAK;;cAGV,iBAAiB;iBAiBd,cAAc,OAAO,qBAAqB,MAAM,IAAI;UC5GnD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAmCf,SAAS,OAAO,qBAAqB,MAAM;;cAGhC,gBAAgB,OAAO"}
@@ -0,0 +1 @@
1
+ {"version":3,"file":"commonExports.js","names":["Box","Text","Options","EasyMdeOptions","lazy","Suspense","useCallback","useEffect","useImperativeHandle","useMemo","useRef","useState","SimpleMDEReactProps","PatchEvent","set","StringInputProps","unset","useClient","styled","MarkdownOptions","SimpleMdeReact","MarkdownInputStyles","theme","sanity","color","card","enabled","fg","border","selectable","primary","hovered","bg","MarkdownInputProps","reactMdeProps","Omit","defaultMdeTools","MarkdownInput","props","$","_c","value","t0","onChange","elementProps","t1","t2","schemaType","focused","undefined","onBlur","onFocus","ref","elementRef","t3","mdeCustomOptions","options","t4","Symbol","for","apiVersion","client","t5","imageUrl","shouldAutoFocus","setShouldAutoFocus","t6","current","t7","file","onSuccess","onError","assets","upload","then","doc","url","catch","e","console","error","message","imageUpload","t8","spellChecker","sideBySideFullscreen","uploadImage","imageUploadFunction","toolbar","status","autofocus","mdeOptions","t10","t9","node","raf","requestAnimationFrame","contains","document","activeElement","cancelAnimationFrame","raf_0","t11","newValue","from","handleChange","t12","fallback","SanityImageAssetDocument","defineType","StringDefinition","MarkdownInput","markdownTypeName","MarkdownOptions","imageUrl","imageAsset","MarkdownDefinition","Omit","type","options","IntrinsicDefinitions","markdown","markdownSchemaType","name","title","components","input","definePlugin","Plugin","StringInputProps","markdownSchemaType","MarkdownConfig","input","props","React","ReactElement","markdownSchema","config","name","schema","types","components"],"sources":["../../src/components/MarkdownInput.tsx","../../src/schema.ts","../../src/plugin.tsx"],"sourcesContent":["// TODO: when upgrading to @sanity/ui@4 start using the new tokens\n// oxlint-disable typescript/no-deprecated\n\nimport {Box, Text} from '@sanity/ui'\n// `import type` (not an inline type specifier) so the bundle keeps no side-effect\n// `import 'easymde'`, which would break SSR/Node (easymde touches `document` on load)\nimport type {Options as EasyMdeOptions} from 'easymde'\nimport {\n lazy,\n Suspense,\n useCallback,\n useEffect,\n useImperativeHandle,\n useMemo,\n useRef,\n useState,\n} from 'react'\n// dont import non-types here, it will break SSR on next\nimport type {SimpleMDEReactProps} from 'react-simplemde-editor'\nimport {PatchEvent, set, type StringInputProps, unset, useClient} from 'sanity'\nimport {styled} from 'styled-components'\n\nimport type {MarkdownOptions} from '../schema'\n\nconst SimpleMdeReact = lazy(() => import('react-simplemde-editor'))\n\nconst MarkdownInputStyles = styled(Box)`\n & .CodeMirror.CodeMirror {\n color: ${({theme}) => theme.sanity.color.card.enabled.fg};\n border-color: ${({theme}) => theme.sanity.color.card.enabled.border};\n background-color: inherit;\n }\n\n & .cm-s-easymde .CodeMirror-cursor {\n border-color: ${({theme}) => theme.sanity.color.card.enabled.fg};\n }\n\n & .editor-toolbar,\n .editor-preview-side {\n border-color: ${({theme}) => theme.sanity.color.card.enabled.border};\n }\n\n & .CodeMirror-focused .CodeMirror-selected.CodeMirror-selected.CodeMirror-selected {\n background-color: ${({theme}) => theme.sanity.color.selectable?.primary?.hovered?.bg};\n }\n\n & .CodeMirror-selected.CodeMirror-selected.CodeMirror-selected {\n background-color: ${({theme}) => theme.sanity.color.card.enabled.bg};\n }\n\n & .editor-toolbar > * {\n color: ${({theme}) => theme.sanity.color.card.enabled.fg};\n }\n\n & .editor-toolbar > .active,\n .editor-toolbar > button:hover,\n .editor-preview pre,\n .cm-s-easymde .cm-comment {\n background-color: ${({theme}) => theme.sanity.color.card.enabled.bg};\n }\n\n & .editor-preview {\n background-color: ${({theme}) => theme.sanity.color.card.enabled.bg};\n\n & h1,\n h2,\n h3,\n h4,\n h5,\n h6 {\n font-size: revert;\n }\n\n & ul,\n li {\n list-style: revert;\n padding: revert;\n }\n\n & a {\n text-decoration: revert;\n }\n }\n`\n\nexport interface MarkdownInputProps extends StringInputProps {\n /**\n * These are passed along directly to\n *\n * Note: MarkdownInput sets certain reactMdeProps.options by default.\n * These will be merged with any custom options.\n */\n reactMdeProps?: Omit<SimpleMDEReactProps, 'value' | 'onChange'>\n}\n\nexport const defaultMdeTools: EasyMdeOptions['toolbar'] = [\n 'heading',\n 'bold',\n 'italic',\n '|',\n 'quote',\n 'unordered-list',\n 'ordered-list',\n '|',\n 'link',\n 'image',\n 'code',\n '|',\n 'preview',\n 'side-by-side',\n]\n\nexport function MarkdownInput(props: MarkdownInputProps): React.JSX.Element {\n const {\n value = '',\n onChange,\n elementProps: {onBlur, onFocus, ref: elementRef},\n reactMdeProps: {options: mdeCustomOptions, ...reactMdeProps} = {},\n schemaType,\n focused,\n } = props\n const client = useClient({apiVersion: '2022-01-01'})\n // oxlint-disable-next-line no-unsafe-type-assertion\n const {imageUrl} = (schemaType.options as MarkdownOptions | undefined) ?? {}\n const [shouldAutoFocus, setShouldAutoFocus] = useState(false)\n const ref = useRef<HTMLDivElement>(null)\n\n // Forward ref to parent form state\n useImperativeHandle(elementRef, () => ref.current)\n\n const imageUpload = useCallback(\n (file: File, onSuccess: (url: string) => void, onError: (error: string) => void) => {\n client.assets\n .upload('image', file)\n .then((doc) => onSuccess(imageUrl ? imageUrl(doc) : `${doc.url}?w=450`))\n .catch((e) => {\n console.error(e)\n onError(e.message)\n })\n },\n [client, imageUrl],\n )\n\n const mdeOptions: EasyMdeOptions = useMemo(() => {\n return {\n spellChecker: false,\n sideBySideFullscreen: false,\n uploadImage: true,\n imageUploadFunction: imageUpload,\n toolbar: defaultMdeTools,\n status: false,\n ...mdeCustomOptions,\n autofocus: shouldAutoFocus,\n }\n }, [imageUpload, mdeCustomOptions, shouldAutoFocus])\n\n useEffect(() => {\n const node = ref.current\n if (!node) return undefined\n\n if (focused && !shouldAutoFocus) {\n // Do not set autofocus if the field already has focus\n const raf = requestAnimationFrame(() =>\n setShouldAutoFocus(!node.contains(document.activeElement)),\n )\n return () => cancelAnimationFrame(raf)\n }\n\n if (!focused && shouldAutoFocus) {\n // If `focused` is false, and the current active focus is no longer within the editor, reset autofocus state\n const raf = requestAnimationFrame(() =>\n setShouldAutoFocus(node.contains(document.activeElement)),\n )\n return () => cancelAnimationFrame(raf)\n }\n\n return undefined\n }, [focused, shouldAutoFocus])\n\n const handleChange = useCallback(\n (newValue: string) => {\n onChange(PatchEvent.from(newValue ? set(newValue) : unset()))\n },\n [onChange],\n )\n\n return (\n <MarkdownInputStyles>\n <Suspense fallback={fallback}>\n <SimpleMdeReact\n {...reactMdeProps}\n ref={ref}\n value={value}\n onChange={handleChange}\n onBlur={onBlur}\n onFocus={onFocus}\n options={mdeOptions}\n spellCheck={false}\n />\n </Suspense>\n </MarkdownInputStyles>\n )\n}\n\nconst fallback = (\n <Box padding={3}>\n <Text>Loading editor...</Text>\n </Box>\n)\n","import type {SanityImageAssetDocument} from '@sanity/client'\nimport {defineType, type StringDefinition} from 'sanity'\n\nimport {MarkdownInput} from './components/MarkdownInput'\n\nexport const markdownTypeName = 'markdown'\n\nexport interface MarkdownOptions {\n /**\n * Used to create image url for any uploaded image.\n * The function will be invoked whenever an image is pasted or dragged into the\n * markdown editor, after upload completes.\n *\n * The default implementation uses\n * ```js\n * imageAsset => `${imageAsset.url}?w=450`\n * ```\n * ## Example\n * ```js\n * {\n * imageUrl: imageAsset => `${imageAsset.url}?w=400&h=400`\n * }\n * ```\n * @param imageAsset\n */\n imageUrl?: (imageAsset: SanityImageAssetDocument) => string\n}\n\n/**\n * @public\n */\nexport interface MarkdownDefinition extends Omit<StringDefinition, 'type' | 'fields' | 'options'> {\n type: typeof markdownTypeName\n options?: MarkdownOptions\n}\n\ndeclare module 'sanity' {\n // makes type: 'markdown' narrow correctly when using defineType/defineField/defineArrayMember\n export interface IntrinsicDefinitions {\n markdown: MarkdownDefinition\n }\n}\n\nexport const markdownSchemaType = defineType({\n type: 'string',\n name: markdownTypeName,\n title: 'Markdown',\n components: {input: MarkdownInput},\n})\n","import {definePlugin, type Plugin, type StringInputProps} from 'sanity'\n\nimport {markdownSchemaType} from './schema'\n\nexport interface MarkdownConfig {\n /**\n * When provided, will replace the default input component.\n *\n * Use this to customize MarkdownInput by wrapping it in a custom component,\n * and provide any custom props for https://github.com/RIP21/react-simplemde-editor#react-simplemde-easymde-markdown-editor\n * via the `reactMdeProps` prop.\n *\n * ### Example\n *\n * ```tsx\n * // CustomMarkdownInput.tsx\n * import { MarkdownInput, MarkdownInputProps } from 'sanity-plugin-markdown'\n *\n * export function CustomMarkdownInput(props) {\n * const reactMdeProps: MarkdownInputProps['reactMdeProps'] =\n * useMemo(() => {\n * return {\n * options: {\n * toolbar: ['bold', 'italic'],\n * // more options available, see:\n * // https://github.com/Ionaru/easy-markdown-editor#options-list\n * },\n * // more props available, see:\n * // https://github.com/RIP21/react-simplemde-editor#react-simplemde-easymde-markdown-editor\n * }\n * }, [])\n *\n * return <MarkdownInput {...props} reactMdeProps={reactMdeProps} />\n * }\n *\n * // studio.config.ts\n * markdownSchema({input: CustomMarkdownInput})\n * ```\n */\n input?: (props: StringInputProps) => React.ReactElement\n}\n\nexport const markdownSchema: Plugin<MarkdownConfig | void> = definePlugin(\n (config: MarkdownConfig | void) => {\n return {\n name: 'markdown-editor',\n schema: {\n types: [\n config && config.input\n ? {...markdownSchemaType, components: {input: config.input}}\n : markdownSchemaType,\n ],\n },\n }\n },\n)\n"],"mappings":";;;;;;AAwBA,MAAMoB,iBAAiBhB,WAAW,OAAO,yBAAyB,GAE5DiB,sBAAsBH,OAAOlB,GAAG,CAAC,CAAA,WAAA;;;qCAEzB,EAACsB,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EAAA,UACE,oBAAC,UAAD;EAAoBC;YAClB,oBAAC,gBAAD;GAAe,GACTzE;GACCkB;GACEX;GACGgE,UAAAA;GACFvD;GACCC;GACAwC,SAAAA;GACG,YAAA;EAAK,CAAA;CATZ,CAAA,EADS,CAAA,GAaEpD,EAAA,MAAAkE,cAAAlE,EAAA,MAAAoD,YAAApD,EAAA,MAAAW,QAAAX,EAAA,MAAAY,SAAAZ,EAAA,MAAAL,eAAAK,EAAA,MAAAE,OAAAF,EAAA,MAAAmE,OAAAA,MAAAnE,EAAA,KAbtBmE;AAasB;AAI1B,MAAMC,WACJ,oBAAC,KAAD;CAAK,SAAS;WACZ,oBAAC,MAAD,EAAA,UAAM,oBAAuB,CAAA;AAC1B,CAAA,GCpKMe,qBAAqBb,WAAW;CAC3CS,MAAM;CACNK,MAAMX;CACNY,OAAO;CACPC,YAAY,EAACC,OAAOf,cAAa;AACnC,CAAC,GCNYyB,iBAAgDT,cAC1DU,YACQ;CACLC,MAAM;CACNC,QAAQ,EACNC,OAAO,CACLH,UAAUA,OAAOL,QACb;EAAC,GAAGF;EAAoBW,YAAY,EAACT,OAAOK,OAAOL,MAAK;CAAC,IACzDF,kBAAkB,EAE1B;AACF,EAEJ"}
package/dist/index.d.ts CHANGED
@@ -1,2 +1,3 @@
1
- import { a as defaultMdeTools, i as MarkdownInputProps, n as markdownSchema, o as MarkdownDefinition, r as MarkdownInput, s as markdownSchemaType, t as MarkdownConfig } from "./commonExports.js";
1
+ import { a as defaultMdeTools, i as MarkdownInputProps, n as markdownSchema, o as MarkdownDefinition, r as MarkdownInput, s as markdownSchemaType, t as MarkdownConfig } from "./_chunks-dts/commonExports.js";
2
+ import "easymde/dist/easymde.min.css";
2
3
  export { type MarkdownConfig, type MarkdownDefinition, MarkdownInput, type MarkdownInputProps, defaultMdeTools, markdownSchema, markdownSchemaType };
package/dist/index.js CHANGED
@@ -1,3 +1,3 @@
1
- import { i as defaultMdeTools, n as markdownSchemaType, r as MarkdownInput, t as markdownSchema } from "./commonExports.js";
1
+ import { i as defaultMdeTools, n as markdownSchemaType, r as MarkdownInput, t as markdownSchema } from "./_chunks-es/commonExports.js";
2
2
  import "easymde/dist/easymde.min.css";
3
3
  export { MarkdownInput, defaultMdeTools, markdownSchema, markdownSchemaType };
package/dist/next.d.ts CHANGED
@@ -1,2 +1,2 @@
1
- import { a as defaultMdeTools, i as MarkdownInputProps, n as markdownSchema, o as MarkdownDefinition, r as MarkdownInput, s as markdownSchemaType, t as MarkdownConfig } from "./commonExports.js";
1
+ import { a as defaultMdeTools, i as MarkdownInputProps, n as markdownSchema, o as MarkdownDefinition, r as MarkdownInput, s as markdownSchemaType, t as MarkdownConfig } from "./_chunks-dts/commonExports.js";
2
2
  export { type MarkdownConfig, type MarkdownDefinition, MarkdownInput, type MarkdownInputProps, defaultMdeTools, markdownSchema, markdownSchemaType };
package/dist/next.js CHANGED
@@ -1,2 +1,2 @@
1
- import { i as defaultMdeTools, n as markdownSchemaType, r as MarkdownInput, t as markdownSchema } from "./commonExports.js";
1
+ import { i as defaultMdeTools, n as markdownSchemaType, r as MarkdownInput, t as markdownSchema } from "./_chunks-es/commonExports.js";
2
2
  export { MarkdownInput, defaultMdeTools, markdownSchema, markdownSchemaType };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "sanity-plugin-markdown",
3
- "version": "9.0.2",
3
+ "version": "9.0.3",
4
4
  "description": "Markdown fields in Sanity Studio. Supports Github flavored Markdown and image uploads.",
5
5
  "keywords": [
6
6
  "github flavored markdown",
@@ -31,21 +31,21 @@
31
31
  "./package.json": "./package.json"
32
32
  },
33
33
  "dependencies": {
34
- "@sanity/ui": "^3.3.0",
34
+ "@sanity/ui": "^3.3.5",
35
35
  "react-simplemde-editor": "^5.2.0"
36
36
  },
37
37
  "devDependencies": {
38
38
  "@sanity/client": "^7.23.0",
39
39
  "@sanity/tsconfig": "^2.2.0",
40
- "@sanity/tsdown-config": "^0.11.0",
41
- "@types/node": "^24.13.2",
40
+ "@sanity/tsdown-config": "^0.13.1",
41
+ "@types/node": "^24.13.3",
42
42
  "@types/react": "^19.2.17",
43
43
  "babel-plugin-react-compiler": "^1.0.0",
44
44
  "easymde": "^2.21.0",
45
45
  "react": "^19.2.7",
46
46
  "sanity": "^6.3.0",
47
47
  "styled-components": "^6.4.3",
48
- "tsdown": "^0.22.3"
48
+ "tsdown": "^0.22.5"
49
49
  },
50
50
  "peerDependencies": {
51
51
  "easymde": "^2.18",
@@ -1 +0,0 @@
1
- {"version":3,"file":"commonExports.d.ts","names":["global","SymbolConstructor","observable","T","R","source","UnaryFunction","Observable","OperatorFunction","value","timestamp","interval","unsubscribe","Subscription","Unsubscribable","closed","Subscribable","PromiseLike","InteropObservable","subscribe","Partial","Observer","observer","AsyncIterable","ArrayLike","Iterable","ReadableStreamLike","Symbol","kind","error","NextNotification","ErrorNotification","CompleteNotification","next","err","complete","NextObserver","ErrorObserver","CompletionObserver","TimestampProvider","schedule","SchedulerAction","this","state","work","delay","now","O","ObservableInput","X","Array","ObservedValueUnionFromArray","K","ObservedValueOf","Y","arg","rest","args","U","A","V","Falsy","read","done","releaseLock","getReader","ReadableStreamDefaultReaderLike","connect","CreateAction","ReplaceDraftAction","EditAction","DeleteAction","DiscardAction","PublishAction","UnpublishAction","VersionAction","ReleaseAction","type","description","items","ActionErrorItem","error","value","index","async","TParamConfig","docIdRequired","ConstantAgentActionParam","FieldAgentActionParam","DocumentAgentActionParam","GroqAgentActionParam","Record","AgentActionParam","AgentActionPathSegment","_key","AgentActionSchema","localeSettings","locale","timeZone","temperature","schemaId","forcePublishedWrite","conditionalPaths","defaultReadOnly","defaultHidden","paths","path","AgentActionPath","readOnly","hidden","private","constructor","SanityClient","client","HttpRequest","httpRequest","generate","DocumentShape","Any","GenerateInstruction","request","Promise","_id","IdentifiedSanityDocumentStub","transform","TransformDocument","translate","TranslateDocument","prompt","PromptRequest","patch","PatchDocument","noWrite","maxPathDepth","exclude","types","AgentActionTypeConfig","include","BaseMutationOptions","returnFirst","returnDocuments","width","height","start","end","fps","format","AnimatedImageFormat","Exclude","message","statusCode","actionType","releaseId","upload","assetType","UploadBody","body","UploadClientConfig","options","SanityAssetDocument","SanityImageAssetDocument","key","name","title","url","providers","AuthProvider","RequestOptions","transactionId","skipCrossDatasetReferenceValidation","dryRun","visibility","autoGenerateArrayKeys","selection","PatchSelection","operations","PatchOperations","set","AttributeSet","attrs","setIfMissing","diffMatchPatch","unset","inc","dec","insert","at","selector","append","prepend","splice","deleteCount","ifRevisionId","rev","serialize","PatchMutationOperation","toJSON","reset","_assign","op","props","merge","_set","Mutation","trxId","create","R","SanityDocumentStub","doc","createIfNotExists","createOrReplace","delete","documentId","id","_add","mut","Error","data","projectId","dataset","useCdn","token","resource","ClientConfigResource","perspective","ClientPerspective","apiHost","apiVersion","proxy","requestTagPrefix","headers","ignoreBrowserTokenWarning","ignoreWarnings","RegExp","Array","withCredentials","allowReconfigure","timeout","maxRetries","retryDelay","attemptNumber","useProjectHostname","requester","Requester","resultSourceMap","fetch","cache","ResponseQueryOptions","next","stega","StegaConfig","lineage","_requestHandler","RequestHandler","response","ErrorProps","responseBody","traceId","details","res","HttpContext","context","DeprecatedPreviewDrafts","StackablePerspective","GroqString","Fallback","SanityQueries","EventName","EventSourceInstance","Observable","initEventSource","events","ServerSentEvent","mappings","ContentSourceMapMappings","documents","ContentSourceMapDocuments","ContentSourceMapPaths","ContentSourceMapDocumentBase","_projectId","_dataset","_type","ContentSourceMapDocument","ContentSourceMapRemoteDocument","document","ContentSourceMapValueMapping","ContentSourceMapMapping","ContentSourceMapDocumentValueSource","ContentSourceMapLiteralSource","ContentSourceMapUnknownSource","source","ContentSourceMapSource","addOriginUrl","URL","credentials","publishedId","attributes","ifExists","ClientConfig","config","metadata","Partial","ReleaseDocument","baseId","versionId","ifBaseRevisionId","email","profileImage","role","provider","aclMode","DatasetAclMode","embeddings","enabled","projection","datasetName","DatasetCreateOptions","DatasetResponse","edit","DatasetEditOptions","deleted","list","DatasetsResponse","getEmbeddingsSettings","EmbeddingsSettings","editEmbeddingsSettings","EmbeddingsSettingsBody","settings","createdAt","createdByUserId","addonFor","datasetProfile","features","tags","includeDrafts","purge","draftId","reason","ErrorOptions","DocIdParam","Omit","PartialExcept","status","Name","InstanceType","globalThis","EventSource","sourcePath","ContentSourceMapParsedPath","sourceDocument","ContentSourceMapDocuments_2","resultPath","filterDefault","FilterDefault","filterResponse","QueryParseError","tag","T","GenerateExistingDocumentRequest","GenerateTargetDocumentRequest","GenerateRequestBase","AgentActionAsync","targetDocument","GenerateSyncInstruction","GenerateAsyncInstruction","AgentActionRequestBase","instruction","instructionParams","AgentActionParams","target","GenerateTarget","AgentActionSync","AgentActionTarget","operation","GenerateOperation","GenerateTargetInclude","initialValues","GenerateTargetDocument","AgentActionTargetInclude","query","params","ClientPerspective_2","method","statusMessage","ReturnType","ResponseEvent","ProgressEvent_2","P","imageUrl","isDefaultApi","cdnUrl","InitializedStegaConfig","StegaConfigRequiredKeys","Required","Pick","before","after","replace","HttpError","ObservableSanityClient","this","ListenParams","MutationEvent","Opts","ListenOptions","ResumableListenOptions","ListenEventFromOptions","ReconnectEvent","WelcomeBackEvent","ResetEvent","WelcomeEvent","OpenEvent","ResumableListenEventNames","ListenEventName","MapListenEventNamesToListenEvents","ListenEvent","includeResult","includeMutations","includePreviousRevision","includeAllVersions","effectFormat","enableResume","includeMembers","includeFeatures","organizationId","onlyExplicitMembership","_tag","waitFor","LiveEvent","LiveEventRestart","LiveEventReconnect","LiveEventMessage","LiveEventWelcome","LiveEventGoAway","SyncTag","console","Events","E","SanityReference","transformations","MediaLibraryVideoPlaybackTransformations","expiration","getPlaybackInfo","MediaLibraryAssetInstanceIdentifier","assetIdentifier","MediaLibraryPlaybackInfoOptions","VideoPlaybackInfo","thumbnail","ThumbnailTransformOptions","animated","AnimatedTransformOptions","storyboard","StoryboardTransformOptions","documentIds","results","MutationOperation","MutationSelection","MutationErrorItem","eventId","identity","mutations","previousRev","resultRev","result","SanityDocument","previous","effects","apply","revert","timestamp","transition","transactionTotalEvents","transactionCurrentEvent","MutationSelectionQueryParams","HttpRequestEvent","BasePatch","clone","ObservablePatch","commit","FirstDocumentMutationOptions","AllDocumentsMutationOptions","FirstDocumentIdMutationOptions","SingleMutationResult","AllDocumentIdsMutationOptions","MultipleMutationResult","ListOptions","SanityProject","OmittedProjectFields","getById","get","signal","AbortSignal","BaseActionOptions","SingleActionResult","release","publish","archive","unarchive","schedule","publishAt","unschedule","fetchDocuments","RawQueryResponse","assets","ObservableAssetsClient","datasets","ObservableDatasetsClient","live","LiveClient","mediaLibrary","video","ObservableMediaLibraryVideoClient","projects","ObservableProjectsClient","users","ObservableUsersClient","agent","action","ObservableAgentsActionClient","releases","ObservableReleasesClient","listen","_listen","InitializedClientConfig","newConfig","withConfig","Q","QueryWithoutParams","G","ClientReturn","QueryParams","FilteredResponseQueryOptions","UnfilteredResponseQueryOptions","UnfilteredResponseWithoutQuery","RawQuerylessQueryResponse","getDocument","getDocuments","ids","documentsExists","Set","createVersion","args","MultipleActionResult","discardVersion","replaceVersion","unpublishVersion","mutate","ObservableTransaction","transaction","Action","RawRequestOptions","getUrl","uri","canUseCdn","getDataUrl","BaseTransaction","TransactionFirstDocumentMutationOptions","TransactionAllDocumentsMutationOptions","TransactionFirstDocumentIdMutationOptions","TransactionAllDocumentIdsMutationOptions","ObservablePatchBuilder","patchOps","CurrentSanityUser","SanityUser","K","Patch","PatchDocumentSync","PatchDocumentAsync","PatchExistingDocumentRequest","PatchTargetDocumentRequest","PatchRequestBase","InsertPatch","ifRevisionID","PatchTarget","PatchOperation","AnyNonNullable","stage","percent","total","loaded","lengthComputable","PromptTextResponse","PromptJsonResponse","PromptRequestBase","ifDraftRevisionId","ifPublishedRevisionId","RequestInit","returnQuery","lastLiveEventId","cacheMode","ms","ContentSourceMap","syncTags","json","useGlobalApi","maxRedirects","CreateReleaseAction","EditReleaseAction","PublishReleaseAction","ArchiveReleaseAction","UnarchiveReleaseAction","ScheduleReleaseAction","UnscheduleReleaseAction","DeleteReleaseAction","ImportReleaseAction","_createdAt","_updatedAt","_rev","state","ReleaseState","finalDocumentStates","publishedAt","intendedPublishAt","releaseType","ReleaseType","cardinality","ReleaseCardinality","defaultRequester","size","assetId","mimeType","sha1hash","extension","uploadId","originalFilename","AssetsClient","DatasetsClient","MediaLibraryVideoClient","ProjectsClient","UsersClient","AgentActionsClient","ReleasesClient","observable","Transaction","dataRequest","endpoint","_originalId","hasAlpha","isOpaque","lqip","blurHash","thumbHash","dimensions","aspectRatio","palette","darkMuted","SanityImagePalette","darkVibrant","dominant","lightMuted","lightVibrant","muted","vibrant","image","exif","background","foreground","population","displayName","studioHost","isBlocked","isDisabled","isDisabledByUser","pendingInvites","maxRetentionDays","members","SanityProjectMember","cliInitializedAt","color","externalStudioHost","isRobot","isCurrentUser","_ref","familyName","givenName","middleName","updatedAt","studioUrl","StudioUrl","ResolveStudioUrl","filter","logger","Logger","omitCrossDatasetReferenceData","Extract","StillImageFormat","time","fit","FitMode","PatchBuilder","TransformDocumentSync","TransformDocumentAsync","TransformRequestBase","ImageDescriptionOperation","TransformTargetDocument","TransformTarget","TransformTargetInclude","TransformOperation","TranslateDocumentSync","TranslateDocumentAsync","TranslateRequestBase","fromLanguage","TranslateLanguage","toLanguage","styleGuide","styleGuideParams","protectedPhrases","languageFieldPath","TranslateTarget","TranslateTargetInclude","File","Blob","Buffer","NodeJS","ReadableStream","preserveFilename","filename","contentType","extract","AssetMetadataType","label","creditLine","CreateVersionAction","DiscardVersionAction","ReplaceVersionAction","UnpublishVersionAction","VideoPlaybackInfoItem","VideoRenditionInfo","VideoPlaybackInfoItemSigned","VideoRenditionInfoSigned","S","VideoSubtitleInfo","VideoSubtitleInfoSigned","stream","duration","renditions","subtitles","VideoPlaybackInfoItemPublic","VideoRenditionInfoPublic","resolution","expiresAt","VideoSubtitleInfoPublic","trackId","languageCode","closedCaptions","listenerName"],"sources":["../../../node_modules/.pnpm/rxjs@7.8.2/node_modules/rxjs/dist/types/internal/types.d.ts","../../../node_modules/.pnpm/@sanity+client@7.23.0/node_modules/@sanity/client/dist/index.d.ts","../src/schema.ts","../src/components/MarkdownInput.tsx","../src/plugin.tsx"],"x_google_ignoreList":[0,1],"mappings":";;;;;;AAE8C;;;QAKtCA,MAAAA;EAAAA,UACMC,iBAAAA;IAAAA,SACGC,UAAAA;EAAAA;AAAAA;;AAAU;;AC0Y3B;;;;;;;;aAAoB,GAAA;;kBA68IK,mBAAA,SAA4B,cAAc;EACjEkK,GAAAA;EACA1D,IAAAA;EACAggB,IAAAA;EACAC,OAAAA;EACAC,QAAAA;EACAC,QAAAA;EACAC,SAAAA;EACAC,QAAAA;EACAC,gBAAAA;AAAAA;;aA8xBkB,cAAA,WAAyB,MAAA,SAAe,GAAA,IAAO,MAAA,SAAe,GAAA,mBACpE,CAAA,GAAI,CAAA,CAAE,CAAA;EAElBtf,GAAAA;EACAqe,IAAAA;EACAtU,KAAAA;EACAoU,UAAAA;EACAC,UAAAA;;;;EAIA8B,WAAAA;AAAAA;;kBAWuB,wBAAA,SAAiC,mBAAA;EACxDhV,QAAAA;IACEnB,KAAAA;IACAoW,QAAAA;IACAC,QAAAA;IACAC,IAAAA;IACAC,QAAAA;IACAC,SAAAA;IACAC,UAAAA;MACEzW,KAAAA;MACA0W,WAAAA;MACArf,MAAAA;MACAD,KAAAA;IAAAA;IAEFuf,OAAAA;MACE3W,KAAAA;MACA4W,SAAAA,GAAY,kBAAA;MACZE,WAAAA,GAAc,kBAAA;MACdC,QAAAA,GAAW,kBAAA;MACXC,UAAAA,GAAa,kBAAA;MACbC,YAAAA,GAAe,kBAAA;MACfC,KAAAA,GAAQ,kBAAA;MACRC,OAAAA,GAAU,kBAAA;IAAA;IAEZC,KAAAA;MACEpX,KAAAA;MAAAA,CACCxH,GAAAA,WAAc,GAAA;IAAA;IAEjB6e,IAAAA;MACErX,KAAAA;MAAAA,CACCxH,GAAAA,WAAc,GAAA;IAAA;EAAA;AAAA;;kBAMI,kBAAA;EACvB8e,UAAAA;EACAC,UAAAA;EACAC,UAAAA;EACA9e,KAAAA;AAAAA;AAAAA,cChsLW,gBAAA;AAAA,UAEI,eAAA;EFL6B;;;;;;;;;AAOnB;;AC0Y3B;;;;AAAuB;AA68IvB;ECv0JE,QAAA,IAAY,UAAA,EAAY,wBAAwB;AAAA;;;;UAMjC,kBAAA,SAA2B,IAAA,CAAK,gBAAA;EAC/C,IAAA,SAAa,gBAAA;EACb,OAAA,GAAU,eAAA;AAAA;AAAA;EAAA,UAKO,oBAAA;IACf,QAAA,EAAU,kBAAkB;EAAA;AAAA;AAAA,cAInB,kBAAA;;;IAKX,IAAA,CAAA,gBAAA;AAAA,UCqCe,kBAAA,SAA2B,gBAAA;EHnFE;;;;;;EG0F5C,aAAA,GAAgB,IAAA,CAAK,mBAAA;AAAA;AAAA,cAGV,eAAA,EAAiB,OAAc;AAAA,iBAiB5B,aAAA,CAAc,KAAA,EAAO,kBAAA,GAAqB,KAAA,CAAM,GAAA,CAAI,OAAO;AAAA,UC5G1D,cAAA;;;AJF6B;;;;;;;;;AAOnB;;AC0Y3B;;;;AAAuB;AA68IvB;;;;;;;;;;;;;;;AASkB;EGl0JhB,KAAA,IAAS,KAAA,EAAO,gBAAA,KAAqB,KAAA,CAAM,YAAY;AAAA;AAAA,cAG5C,cAAA,EAAgB,MAAM,CAAC,cAAA"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"commonExports.js","names":["Box","Text","Options","EasyMdeOptions","lazy","Suspense","useCallback","useEffect","useImperativeHandle","useMemo","useRef","useState","SimpleMDEReactProps","PatchEvent","set","StringInputProps","unset","useClient","styled","MarkdownOptions","SimpleMdeReact","MarkdownInputStyles","theme","sanity","color","card","enabled","fg","border","selectable","primary","hovered","bg","MarkdownInputProps","reactMdeProps","Omit","defaultMdeTools","MarkdownInput","props","$","_c","value","t0","onChange","elementProps","t1","t2","schemaType","focused","undefined","onBlur","onFocus","ref","elementRef","t3","mdeCustomOptions","options","t4","Symbol","for","apiVersion","client","t5","imageUrl","shouldAutoFocus","setShouldAutoFocus","t6","current","t7","file","onSuccess","onError","assets","upload","then","doc","url","catch","e","console","error","message","imageUpload","t8","spellChecker","sideBySideFullscreen","uploadImage","imageUploadFunction","toolbar","status","autofocus","mdeOptions","t10","t9","node","raf","requestAnimationFrame","contains","document","activeElement","cancelAnimationFrame","raf_0","t11","newValue","from","handleChange","t12","fallback","SanityImageAssetDocument","defineType","StringDefinition","MarkdownInput","markdownTypeName","MarkdownOptions","imageUrl","imageAsset","MarkdownDefinition","Omit","type","options","IntrinsicDefinitions","markdown","markdownSchemaType","name","title","components","input","definePlugin","Plugin","StringInputProps","markdownSchemaType","MarkdownConfig","input","props","React","ReactElement","markdownSchema","config","name","schema","types","components"],"sources":["../src/components/MarkdownInput.tsx","../src/schema.ts","../src/plugin.tsx"],"sourcesContent":["// TODO: when upgrading to @sanity/ui@4 start using the new tokens\n// oxlint-disable typescript/no-deprecated\n\nimport {Box, Text} from '@sanity/ui'\n// `import type` (not an inline type specifier) so the bundle keeps no side-effect\n// `import 'easymde'`, which would break SSR/Node (easymde touches `document` on load)\nimport type {Options as EasyMdeOptions} from 'easymde'\nimport {\n lazy,\n Suspense,\n useCallback,\n useEffect,\n useImperativeHandle,\n useMemo,\n useRef,\n useState,\n} from 'react'\n// dont import non-types here, it will break SSR on next\nimport type {SimpleMDEReactProps} from 'react-simplemde-editor'\nimport {PatchEvent, set, type StringInputProps, unset, useClient} from 'sanity'\nimport {styled} from 'styled-components'\n\nimport type {MarkdownOptions} from '../schema'\n\nconst SimpleMdeReact = lazy(() => import('react-simplemde-editor'))\n\nconst MarkdownInputStyles = styled(Box)`\n & .CodeMirror.CodeMirror {\n color: ${({theme}) => theme.sanity.color.card.enabled.fg};\n border-color: ${({theme}) => theme.sanity.color.card.enabled.border};\n background-color: inherit;\n }\n\n & .cm-s-easymde .CodeMirror-cursor {\n border-color: ${({theme}) => theme.sanity.color.card.enabled.fg};\n }\n\n & .editor-toolbar,\n .editor-preview-side {\n border-color: ${({theme}) => theme.sanity.color.card.enabled.border};\n }\n\n & .CodeMirror-focused .CodeMirror-selected.CodeMirror-selected.CodeMirror-selected {\n background-color: ${({theme}) => theme.sanity.color.selectable?.primary?.hovered?.bg};\n }\n\n & .CodeMirror-selected.CodeMirror-selected.CodeMirror-selected {\n background-color: ${({theme}) => theme.sanity.color.card.enabled.bg};\n }\n\n & .editor-toolbar > * {\n color: ${({theme}) => theme.sanity.color.card.enabled.fg};\n }\n\n & .editor-toolbar > .active,\n .editor-toolbar > button:hover,\n .editor-preview pre,\n .cm-s-easymde .cm-comment {\n background-color: ${({theme}) => theme.sanity.color.card.enabled.bg};\n }\n\n & .editor-preview {\n background-color: ${({theme}) => theme.sanity.color.card.enabled.bg};\n\n & h1,\n h2,\n h3,\n h4,\n h5,\n h6 {\n font-size: revert;\n }\n\n & ul,\n li {\n list-style: revert;\n padding: revert;\n }\n\n & a {\n text-decoration: revert;\n }\n }\n`\n\nexport interface MarkdownInputProps extends StringInputProps {\n /**\n * These are passed along directly to\n *\n * Note: MarkdownInput sets certain reactMdeProps.options by default.\n * These will be merged with any custom options.\n */\n reactMdeProps?: Omit<SimpleMDEReactProps, 'value' | 'onChange'>\n}\n\nexport const defaultMdeTools: EasyMdeOptions['toolbar'] = [\n 'heading',\n 'bold',\n 'italic',\n '|',\n 'quote',\n 'unordered-list',\n 'ordered-list',\n '|',\n 'link',\n 'image',\n 'code',\n '|',\n 'preview',\n 'side-by-side',\n]\n\nexport function MarkdownInput(props: MarkdownInputProps): React.JSX.Element {\n const {\n value = '',\n onChange,\n elementProps: {onBlur, onFocus, ref: elementRef},\n reactMdeProps: {options: mdeCustomOptions, ...reactMdeProps} = {},\n schemaType,\n focused,\n } = props\n const client = useClient({apiVersion: '2022-01-01'})\n // oxlint-disable-next-line no-unsafe-type-assertion\n const {imageUrl} = (schemaType.options as MarkdownOptions | undefined) ?? {}\n const [shouldAutoFocus, setShouldAutoFocus] = useState(false)\n const ref = useRef<HTMLDivElement>(null)\n\n // Forward ref to parent form state\n useImperativeHandle(elementRef, () => ref.current)\n\n const imageUpload = useCallback(\n (file: File, onSuccess: (url: string) => void, onError: (error: string) => void) => {\n client.assets\n .upload('image', file)\n .then((doc) => onSuccess(imageUrl ? imageUrl(doc) : `${doc.url}?w=450`))\n .catch((e) => {\n console.error(e)\n onError(e.message)\n })\n },\n [client, imageUrl],\n )\n\n const mdeOptions: EasyMdeOptions = useMemo(() => {\n return {\n spellChecker: false,\n sideBySideFullscreen: false,\n uploadImage: true,\n imageUploadFunction: imageUpload,\n toolbar: defaultMdeTools,\n status: false,\n ...mdeCustomOptions,\n autofocus: shouldAutoFocus,\n }\n }, [imageUpload, mdeCustomOptions, shouldAutoFocus])\n\n useEffect(() => {\n const node = ref.current\n if (!node) return undefined\n\n if (focused && !shouldAutoFocus) {\n // Do not set autofocus if the field already has focus\n const raf = requestAnimationFrame(() =>\n setShouldAutoFocus(!node.contains(document.activeElement)),\n )\n return () => cancelAnimationFrame(raf)\n }\n\n if (!focused && shouldAutoFocus) {\n // If `focused` is false, and the current active focus is no longer within the editor, reset autofocus state\n const raf = requestAnimationFrame(() =>\n setShouldAutoFocus(node.contains(document.activeElement)),\n )\n return () => cancelAnimationFrame(raf)\n }\n\n return undefined\n }, [focused, shouldAutoFocus])\n\n const handleChange = useCallback(\n (newValue: string) => {\n onChange(PatchEvent.from(newValue ? set(newValue) : unset()))\n },\n [onChange],\n )\n\n return (\n <MarkdownInputStyles>\n <Suspense fallback={fallback}>\n <SimpleMdeReact\n {...reactMdeProps}\n ref={ref}\n value={value}\n onChange={handleChange}\n onBlur={onBlur}\n onFocus={onFocus}\n options={mdeOptions}\n spellCheck={false}\n />\n </Suspense>\n </MarkdownInputStyles>\n )\n}\n\nconst fallback = (\n <Box padding={3}>\n <Text>Loading editor...</Text>\n </Box>\n)\n","import type {SanityImageAssetDocument} from '@sanity/client'\nimport {defineType, type StringDefinition} from 'sanity'\n\nimport {MarkdownInput} from './components/MarkdownInput'\n\nexport const markdownTypeName = 'markdown'\n\nexport interface MarkdownOptions {\n /**\n * Used to create image url for any uploaded image.\n * The function will be invoked whenever an image is pasted or dragged into the\n * markdown editor, after upload completes.\n *\n * The default implementation uses\n * ```js\n * imageAsset => `${imageAsset.url}?w=450`\n * ```\n * ## Example\n * ```js\n * {\n * imageUrl: imageAsset => `${imageAsset.url}?w=400&h=400`\n * }\n * ```\n * @param imageAsset\n */\n imageUrl?: (imageAsset: SanityImageAssetDocument) => string\n}\n\n/**\n * @public\n */\nexport interface MarkdownDefinition extends Omit<StringDefinition, 'type' | 'fields' | 'options'> {\n type: typeof markdownTypeName\n options?: MarkdownOptions\n}\n\ndeclare module 'sanity' {\n // makes type: 'markdown' narrow correctly when using defineType/defineField/defineArrayMember\n export interface IntrinsicDefinitions {\n markdown: MarkdownDefinition\n }\n}\n\nexport const markdownSchemaType = defineType({\n type: 'string',\n name: markdownTypeName,\n title: 'Markdown',\n components: {input: MarkdownInput},\n})\n","import {definePlugin, type Plugin, type StringInputProps} from 'sanity'\n\nimport {markdownSchemaType} from './schema'\n\nexport interface MarkdownConfig {\n /**\n * When provided, will replace the default input component.\n *\n * Use this to customize MarkdownInput by wrapping it in a custom component,\n * and provide any custom props for https://github.com/RIP21/react-simplemde-editor#react-simplemde-easymde-markdown-editor\n * via the `reactMdeProps` prop.\n *\n * ### Example\n *\n * ```tsx\n * // CustomMarkdownInput.tsx\n * import { MarkdownInput, MarkdownInputProps } from 'sanity-plugin-markdown'\n *\n * export function CustomMarkdownInput(props) {\n * const reactMdeProps: MarkdownInputProps['reactMdeProps'] =\n * useMemo(() => {\n * return {\n * options: {\n * toolbar: ['bold', 'italic'],\n * // more options available, see:\n * // https://github.com/Ionaru/easy-markdown-editor#options-list\n * },\n * // more props available, see:\n * // https://github.com/RIP21/react-simplemde-editor#react-simplemde-easymde-markdown-editor\n * }\n * }, [])\n *\n * return <MarkdownInput {...props} reactMdeProps={reactMdeProps} />\n * }\n *\n * // studio.config.ts\n * markdownSchema({input: CustomMarkdownInput})\n * ```\n */\n input?: (props: StringInputProps) => React.ReactElement\n}\n\nexport const markdownSchema: Plugin<MarkdownConfig | void> = definePlugin(\n (config: MarkdownConfig | void) => {\n return {\n name: 'markdown-editor',\n schema: {\n types: [\n config && config.input\n ? {...markdownSchemaType, components: {input: config.input}}\n : markdownSchemaType,\n ],\n },\n }\n },\n)\n"],"mappings":";;;;;;AAwBA,MAAMoB,iBAAiBhB,WAAW,OAAO,yBAAyB,GAE5DiB,sBAAsBH,OAAOlB,GAAG,CAAC,CAAA,WAAA;;;qCAEzB,EAACsB,YAAWA,MAAMC,OAAOC,MAAMC,KAAKC,QAAQC,GAAE,iBACvC,EAACL,YAAWA,MAAMC,OAAOC,MAAMC,KAAKC,QAAQE,OAAM,8EAKlD,EAACN,YAAWA,MAAMC,OAAOC,MAAMC,KAAKC,QAAQC,GAAE,yDAK9C,EAACL,YAAWA,MAAMC,OAAOC,MAAMC,KAAKC,QAAQE,OAAM,yGAI9C,EAACN,YAAWA,MAAMC,OAAOC,MAAMK,YAAYC,SAASC,SAASC,GAAE,qFAI/D,EAACV,YAAWA,MAAMC,OAAOC,MAAMC,KAAKC,QAAQM,GAAE,iCAIzD,EAACV,YAAWA,MAAMC,OAAOC,MAAMC,KAAKC,QAAQC,GAAE,+HAOnC,EAACL,YAAWA,MAAMC,OAAOC,MAAMC,KAAKC,QAAQM,GAAE,wCAI9C,EAACV,YAAWA,MAAMC,OAAOC,MAAMC,KAAKC,QAAQM,GAAE,iHAiC1DI,kBAA6C;CACxD;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;AAAc;AAGhB,SAAOC,cAAAC,OAAA;CAAA,IAAAC,IAAAC,EAAA,EAAA,GACL,EAAAC,OAAAC,IAAAC,UAAAC,cAAAC,IAAAX,eAAAY,IAAAC,YAAAC,YAOIV,OANFG,QAAAC,OAAAO,KAAAA,IAAA,KAAAP,IAEc,EAAAQ,QA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