@sanity/assist 4.3.2 → 4.4.1
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 +3 -0
- package/dist/index.d.mts +12 -1
- package/dist/index.d.ts +12 -1
- package/dist/index.esm.js +24 -6
- package/dist/index.esm.js.map +1 -1
- package/dist/index.js +24 -6
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +24 -6
- package/dist/index.mjs.map +1 -1
- package/package.json +3 -3
- package/src/assistDocument/AssistDocumentContext.tsx +4 -0
- package/src/assistDocument/hooks/useAssistDocumentContextValue.tsx +7 -1
- package/src/assistInspector/helpers.ts +8 -0
- package/src/assistLayout/RunInstructionProvider.tsx +1 -0
- package/src/fieldActions/assistFieldActions.tsx +15 -1
- package/src/fieldActions/customFieldActions.tsx +12 -0
- package/src/helpers/assistSupported.ts +5 -1
- package/src/schemas/serialize/serializeSchema.test.ts +18 -4
- package/src/types.ts +1 -1
package/dist/index.js
CHANGED
|
@@ -235,7 +235,8 @@ function isSchemaAssistEnabled(type) {
|
|
|
235
235
|
return !type.options?.aiAssist?.exclude;
|
|
236
236
|
}
|
|
237
237
|
function isAssistSupported(type) {
|
|
238
|
-
return !isSchemaAssistEnabled(type) || isDisabled(type) ? !1 : type.jsonType === "array" ? !type.of.every((t) => isDisabled(t)) : type.jsonType === "object" ? !type.fields.every((field) => isDisabled(field.type))
|
|
238
|
+
return !isSchemaAssistEnabled(type) || isDisabled(type) ? !1 : type.jsonType === "array" ? !type.of.every((t) => isDisabled(t)) : type.jsonType === "object" ? !type.fields.every((field) => isDisabled(field.type)) || /* to allow attaching custom actions on fieldless images */
|
|
239
|
+
isType(type, "image") : !0;
|
|
239
240
|
}
|
|
240
241
|
function isDisabled(type) {
|
|
241
242
|
return !isSchemaAssistEnabled(type) || isUnsupportedType(type);
|
|
@@ -393,6 +394,12 @@ function getTypeIcon(schemaType) {
|
|
|
393
394
|
}
|
|
394
395
|
return isType(schemaType, "slug") ? icons.LinkIcon : isType(schemaType, "image") ? icons.ImageIcon : schemaType.jsonType === "array" && isPortableTextArray(schemaType) ? icons.BlockContentIcon : schemaType.jsonType === "array" ? icons.OlistIcon : schemaType.jsonType === "object" ? icons.BlockquoteIcon : schemaType.jsonType === "string" ? icons.StringIcon : icons.DocumentIcon;
|
|
395
396
|
}
|
|
397
|
+
function asFieldRefsByTypePath(fieldRefs) {
|
|
398
|
+
return fieldRefs.reduce(
|
|
399
|
+
(acc, ref) => ({ ...acc, [ref.key]: ref }),
|
|
400
|
+
{}
|
|
401
|
+
);
|
|
402
|
+
}
|
|
396
403
|
function getFieldRefsWithDocument(schemaType) {
|
|
397
404
|
const fields = getFieldRefs(schemaType);
|
|
398
405
|
return [
|
|
@@ -1022,7 +1029,7 @@ function useAssistDocumentContextValue(documentId, documentType) {
|
|
|
1022
1029
|
} = structure.useDocumentPane(), { draft, published, version } = editState || {}, assistableDocumentId = selectedReleaseId ? sanity.getVersionId(documentId, selectedReleaseId) : documentSchemaType.liveEdit ? documentId : sanity.getDraftId(documentId), documentIsNew = selectedReleaseId ? !version?._id : !draft?._id && !published?._id, documentIsAssistable = selectedReleaseId ? !!version : isDocAssistable(documentSchemaType, published, draft), { params } = useAiPaneRouter(), selectedPath = params[fieldPathParam], assistDocument = useStudioAssistDocument({
|
|
1023
1030
|
documentId: assistableDocumentId,
|
|
1024
1031
|
schemaType: documentSchemaType
|
|
1025
|
-
}), { syntheticTasks, addSyntheticTask, removeSyntheticTask } = useSyntheticTasks(assistableDocumentId);
|
|
1032
|
+
}), { syntheticTasks, addSyntheticTask, removeSyntheticTask } = useSyntheticTasks(assistableDocumentId), fieldRefs = getFieldRefs(documentSchemaType), fieldRefsByTypePath = asFieldRefsByTypePath(fieldRefs);
|
|
1026
1033
|
return react.useMemo(() => {
|
|
1027
1034
|
const base = {
|
|
1028
1035
|
assistableDocumentId,
|
|
@@ -1036,7 +1043,9 @@ function useAssistDocumentContextValue(documentId, documentType) {
|
|
|
1036
1043
|
selectedPath,
|
|
1037
1044
|
syntheticTasks,
|
|
1038
1045
|
addSyntheticTask,
|
|
1039
|
-
removeSyntheticTask
|
|
1046
|
+
removeSyntheticTask,
|
|
1047
|
+
fieldRefs,
|
|
1048
|
+
fieldRefsByTypePath
|
|
1040
1049
|
};
|
|
1041
1050
|
return assistDocument ? {
|
|
1042
1051
|
...base,
|
|
@@ -2952,7 +2961,8 @@ const assistFieldActions = {
|
|
|
2952
2961
|
documentOnChange,
|
|
2953
2962
|
documentSchemaType,
|
|
2954
2963
|
selectedPath,
|
|
2955
|
-
assistableDocumentId
|
|
2964
|
+
assistableDocumentId,
|
|
2965
|
+
fieldRefsByTypePath
|
|
2956
2966
|
} = useAssistDocumentContext(), { value: docValue, formState } = structure.useDocumentPane(), docValueRef = react.useRef(docValue), formStateRef = react.useRef(formState);
|
|
2957
2967
|
formStateRef.current = formState;
|
|
2958
2968
|
const currentUser = sanity.useCurrentUser(), isHidden = !assistDocument, pathKey = usePathKey(props.path), typePath = useTypePath(docValue, pathKey), assistDocumentId2 = assistDocument?._id, { requestRunInstruction } = useRequestRunInstruction({
|
|
@@ -3040,14 +3050,22 @@ const assistFieldActions = {
|
|
|
3040
3050
|
path
|
|
3041
3051
|
};
|
|
3042
3052
|
}
|
|
3043
|
-
), []),
|
|
3053
|
+
), []), parentSchemaType = react.useMemo(() => {
|
|
3054
|
+
if (props.path.length) {
|
|
3055
|
+
if (props.path.length === 1)
|
|
3056
|
+
return documentSchemaType;
|
|
3057
|
+
} else return;
|
|
3058
|
+
const parentPath = props.path.slice(0, -1), typePath2 = getTypePath(docValueRef.current, sanity.pathToString(parentPath));
|
|
3059
|
+
return typePath2 ? fieldRefsByTypePath[typePath2]?.schemaType : void 0;
|
|
3060
|
+
}, [fieldRefsByTypePath, props.path, documentSchemaType]), customActions = useCustomFieldActions({
|
|
3044
3061
|
actionType: props.path.length ? "field" : "document",
|
|
3045
3062
|
documentIdForAction: assistableDocumentId,
|
|
3046
3063
|
schemaType,
|
|
3047
3064
|
documentSchemaType,
|
|
3048
3065
|
path: props.path,
|
|
3049
3066
|
getDocumentValue,
|
|
3050
|
-
getConditionalPaths
|
|
3067
|
+
getConditionalPaths,
|
|
3068
|
+
parentSchemaType
|
|
3051
3069
|
}), manageInstructionsItem = react.useMemo(
|
|
3052
3070
|
() => ({
|
|
3053
3071
|
type: "action",
|