@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.mjs
CHANGED
|
@@ -242,7 +242,8 @@ function isSchemaAssistEnabled(type) {
|
|
|
242
242
|
return !type.options?.aiAssist?.exclude;
|
|
243
243
|
}
|
|
244
244
|
function isAssistSupported(type) {
|
|
245
|
-
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))
|
|
245
|
+
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 */
|
|
246
|
+
isType(type, "image") : !0;
|
|
246
247
|
}
|
|
247
248
|
function isDisabled(type) {
|
|
248
249
|
return !isSchemaAssistEnabled(type) || isUnsupportedType(type);
|
|
@@ -400,6 +401,12 @@ function getTypeIcon(schemaType) {
|
|
|
400
401
|
}
|
|
401
402
|
return isType(schemaType, "slug") ? LinkIcon : isType(schemaType, "image") ? ImageIcon : schemaType.jsonType === "array" && isPortableTextArray(schemaType) ? BlockContentIcon : schemaType.jsonType === "array" ? OlistIcon : schemaType.jsonType === "object" ? BlockquoteIcon : schemaType.jsonType === "string" ? StringIcon : DocumentIcon;
|
|
402
403
|
}
|
|
404
|
+
function asFieldRefsByTypePath(fieldRefs) {
|
|
405
|
+
return fieldRefs.reduce(
|
|
406
|
+
(acc, ref) => ({ ...acc, [ref.key]: ref }),
|
|
407
|
+
{}
|
|
408
|
+
);
|
|
409
|
+
}
|
|
403
410
|
function getFieldRefsWithDocument(schemaType) {
|
|
404
411
|
const fields = getFieldRefs(schemaType);
|
|
405
412
|
return [
|
|
@@ -1029,7 +1036,7 @@ function useAssistDocumentContextValue(documentId, documentType) {
|
|
|
1029
1036
|
} = useDocumentPane(), { draft, published, version } = editState || {}, assistableDocumentId = selectedReleaseId ? getVersionId(documentId, selectedReleaseId) : documentSchemaType.liveEdit ? documentId : getDraftId(documentId), documentIsNew = selectedReleaseId ? !version?._id : !draft?._id && !published?._id, documentIsAssistable = selectedReleaseId ? !!version : isDocAssistable(documentSchemaType, published, draft), { params } = useAiPaneRouter(), selectedPath = params[fieldPathParam], assistDocument = useStudioAssistDocument({
|
|
1030
1037
|
documentId: assistableDocumentId,
|
|
1031
1038
|
schemaType: documentSchemaType
|
|
1032
|
-
}), { syntheticTasks, addSyntheticTask, removeSyntheticTask } = useSyntheticTasks(assistableDocumentId);
|
|
1039
|
+
}), { syntheticTasks, addSyntheticTask, removeSyntheticTask } = useSyntheticTasks(assistableDocumentId), fieldRefs = getFieldRefs(documentSchemaType), fieldRefsByTypePath = asFieldRefsByTypePath(fieldRefs);
|
|
1033
1040
|
return useMemo(() => {
|
|
1034
1041
|
const base = {
|
|
1035
1042
|
assistableDocumentId,
|
|
@@ -1043,7 +1050,9 @@ function useAssistDocumentContextValue(documentId, documentType) {
|
|
|
1043
1050
|
selectedPath,
|
|
1044
1051
|
syntheticTasks,
|
|
1045
1052
|
addSyntheticTask,
|
|
1046
|
-
removeSyntheticTask
|
|
1053
|
+
removeSyntheticTask,
|
|
1054
|
+
fieldRefs,
|
|
1055
|
+
fieldRefsByTypePath
|
|
1047
1056
|
};
|
|
1048
1057
|
return assistDocument ? {
|
|
1049
1058
|
...base,
|
|
@@ -2959,7 +2968,8 @@ const assistFieldActions = {
|
|
|
2959
2968
|
documentOnChange,
|
|
2960
2969
|
documentSchemaType,
|
|
2961
2970
|
selectedPath,
|
|
2962
|
-
assistableDocumentId
|
|
2971
|
+
assistableDocumentId,
|
|
2972
|
+
fieldRefsByTypePath
|
|
2963
2973
|
} = useAssistDocumentContext(), { value: docValue, formState } = useDocumentPane(), docValueRef = useRef(docValue), formStateRef = useRef(formState);
|
|
2964
2974
|
formStateRef.current = formState;
|
|
2965
2975
|
const currentUser = useCurrentUser(), isHidden = !assistDocument, pathKey = usePathKey(props.path), typePath = useTypePath(docValue, pathKey), assistDocumentId2 = assistDocument?._id, { requestRunInstruction } = useRequestRunInstruction({
|
|
@@ -3047,14 +3057,22 @@ const assistFieldActions = {
|
|
|
3047
3057
|
path
|
|
3048
3058
|
};
|
|
3049
3059
|
}
|
|
3050
|
-
), []),
|
|
3060
|
+
), []), parentSchemaType = useMemo(() => {
|
|
3061
|
+
if (props.path.length) {
|
|
3062
|
+
if (props.path.length === 1)
|
|
3063
|
+
return documentSchemaType;
|
|
3064
|
+
} else return;
|
|
3065
|
+
const parentPath = props.path.slice(0, -1), typePath2 = getTypePath(docValueRef.current, pathToString(parentPath));
|
|
3066
|
+
return typePath2 ? fieldRefsByTypePath[typePath2]?.schemaType : void 0;
|
|
3067
|
+
}, [fieldRefsByTypePath, props.path, documentSchemaType]), customActions = useCustomFieldActions({
|
|
3051
3068
|
actionType: props.path.length ? "field" : "document",
|
|
3052
3069
|
documentIdForAction: assistableDocumentId,
|
|
3053
3070
|
schemaType,
|
|
3054
3071
|
documentSchemaType,
|
|
3055
3072
|
path: props.path,
|
|
3056
3073
|
getDocumentValue,
|
|
3057
|
-
getConditionalPaths
|
|
3074
|
+
getConditionalPaths,
|
|
3075
|
+
parentSchemaType
|
|
3058
3076
|
}), manageInstructionsItem = useMemo(
|
|
3059
3077
|
() => ({
|
|
3060
3078
|
type: "action",
|