@sanity/assist 4.3.2 → 4.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +3 -0
- package/dist/index.d.mts +12 -1
- package/dist/index.d.ts +12 -1
- package/dist/index.esm.js +22 -5
- package/dist/index.esm.js.map +1 -1
- package/dist/index.js +22 -5
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +22 -5
- 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/types.ts +1 -1
package/dist/index.mjs
CHANGED
|
@@ -400,6 +400,12 @@ function getTypeIcon(schemaType) {
|
|
|
400
400
|
}
|
|
401
401
|
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
402
|
}
|
|
403
|
+
function asFieldRefsByTypePath(fieldRefs) {
|
|
404
|
+
return fieldRefs.reduce(
|
|
405
|
+
(acc, ref) => ({ ...acc, [ref.key]: ref }),
|
|
406
|
+
{}
|
|
407
|
+
);
|
|
408
|
+
}
|
|
403
409
|
function getFieldRefsWithDocument(schemaType) {
|
|
404
410
|
const fields = getFieldRefs(schemaType);
|
|
405
411
|
return [
|
|
@@ -1029,7 +1035,7 @@ function useAssistDocumentContextValue(documentId, documentType) {
|
|
|
1029
1035
|
} = 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
1036
|
documentId: assistableDocumentId,
|
|
1031
1037
|
schemaType: documentSchemaType
|
|
1032
|
-
}), { syntheticTasks, addSyntheticTask, removeSyntheticTask } = useSyntheticTasks(assistableDocumentId);
|
|
1038
|
+
}), { syntheticTasks, addSyntheticTask, removeSyntheticTask } = useSyntheticTasks(assistableDocumentId), fieldRefs = getFieldRefs(documentSchemaType), fieldRefsByTypePath = asFieldRefsByTypePath(fieldRefs);
|
|
1033
1039
|
return useMemo(() => {
|
|
1034
1040
|
const base = {
|
|
1035
1041
|
assistableDocumentId,
|
|
@@ -1043,7 +1049,9 @@ function useAssistDocumentContextValue(documentId, documentType) {
|
|
|
1043
1049
|
selectedPath,
|
|
1044
1050
|
syntheticTasks,
|
|
1045
1051
|
addSyntheticTask,
|
|
1046
|
-
removeSyntheticTask
|
|
1052
|
+
removeSyntheticTask,
|
|
1053
|
+
fieldRefs,
|
|
1054
|
+
fieldRefsByTypePath
|
|
1047
1055
|
};
|
|
1048
1056
|
return assistDocument ? {
|
|
1049
1057
|
...base,
|
|
@@ -2959,7 +2967,8 @@ const assistFieldActions = {
|
|
|
2959
2967
|
documentOnChange,
|
|
2960
2968
|
documentSchemaType,
|
|
2961
2969
|
selectedPath,
|
|
2962
|
-
assistableDocumentId
|
|
2970
|
+
assistableDocumentId,
|
|
2971
|
+
fieldRefsByTypePath
|
|
2963
2972
|
} = useAssistDocumentContext(), { value: docValue, formState } = useDocumentPane(), docValueRef = useRef(docValue), formStateRef = useRef(formState);
|
|
2964
2973
|
formStateRef.current = formState;
|
|
2965
2974
|
const currentUser = useCurrentUser(), isHidden = !assistDocument, pathKey = usePathKey(props.path), typePath = useTypePath(docValue, pathKey), assistDocumentId2 = assistDocument?._id, { requestRunInstruction } = useRequestRunInstruction({
|
|
@@ -3047,14 +3056,22 @@ const assistFieldActions = {
|
|
|
3047
3056
|
path
|
|
3048
3057
|
};
|
|
3049
3058
|
}
|
|
3050
|
-
), []),
|
|
3059
|
+
), []), parentSchemaType = useMemo(() => {
|
|
3060
|
+
if (props.path.length) {
|
|
3061
|
+
if (props.path.length === 1)
|
|
3062
|
+
return documentSchemaType;
|
|
3063
|
+
} else return;
|
|
3064
|
+
const parentPath = props.path.slice(0, -1), typePath2 = getTypePath(docValueRef.current, pathToString(parentPath));
|
|
3065
|
+
return typePath2 ? fieldRefsByTypePath[typePath2]?.schemaType : void 0;
|
|
3066
|
+
}, [fieldRefsByTypePath, props.path, documentSchemaType]), customActions = useCustomFieldActions({
|
|
3051
3067
|
actionType: props.path.length ? "field" : "document",
|
|
3052
3068
|
documentIdForAction: assistableDocumentId,
|
|
3053
3069
|
schemaType,
|
|
3054
3070
|
documentSchemaType,
|
|
3055
3071
|
path: props.path,
|
|
3056
3072
|
getDocumentValue,
|
|
3057
|
-
getConditionalPaths
|
|
3073
|
+
getConditionalPaths,
|
|
3074
|
+
parentSchemaType
|
|
3058
3075
|
}), manageInstructionsItem = useMemo(
|
|
3059
3076
|
() => ({
|
|
3060
3077
|
type: "action",
|