@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.js
CHANGED
|
@@ -393,6 +393,12 @@ function getTypeIcon(schemaType) {
|
|
|
393
393
|
}
|
|
394
394
|
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
395
|
}
|
|
396
|
+
function asFieldRefsByTypePath(fieldRefs) {
|
|
397
|
+
return fieldRefs.reduce(
|
|
398
|
+
(acc, ref) => ({ ...acc, [ref.key]: ref }),
|
|
399
|
+
{}
|
|
400
|
+
);
|
|
401
|
+
}
|
|
396
402
|
function getFieldRefsWithDocument(schemaType) {
|
|
397
403
|
const fields = getFieldRefs(schemaType);
|
|
398
404
|
return [
|
|
@@ -1022,7 +1028,7 @@ function useAssistDocumentContextValue(documentId, documentType) {
|
|
|
1022
1028
|
} = 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
1029
|
documentId: assistableDocumentId,
|
|
1024
1030
|
schemaType: documentSchemaType
|
|
1025
|
-
}), { syntheticTasks, addSyntheticTask, removeSyntheticTask } = useSyntheticTasks(assistableDocumentId);
|
|
1031
|
+
}), { syntheticTasks, addSyntheticTask, removeSyntheticTask } = useSyntheticTasks(assistableDocumentId), fieldRefs = getFieldRefs(documentSchemaType), fieldRefsByTypePath = asFieldRefsByTypePath(fieldRefs);
|
|
1026
1032
|
return react.useMemo(() => {
|
|
1027
1033
|
const base = {
|
|
1028
1034
|
assistableDocumentId,
|
|
@@ -1036,7 +1042,9 @@ function useAssistDocumentContextValue(documentId, documentType) {
|
|
|
1036
1042
|
selectedPath,
|
|
1037
1043
|
syntheticTasks,
|
|
1038
1044
|
addSyntheticTask,
|
|
1039
|
-
removeSyntheticTask
|
|
1045
|
+
removeSyntheticTask,
|
|
1046
|
+
fieldRefs,
|
|
1047
|
+
fieldRefsByTypePath
|
|
1040
1048
|
};
|
|
1041
1049
|
return assistDocument ? {
|
|
1042
1050
|
...base,
|
|
@@ -2952,7 +2960,8 @@ const assistFieldActions = {
|
|
|
2952
2960
|
documentOnChange,
|
|
2953
2961
|
documentSchemaType,
|
|
2954
2962
|
selectedPath,
|
|
2955
|
-
assistableDocumentId
|
|
2963
|
+
assistableDocumentId,
|
|
2964
|
+
fieldRefsByTypePath
|
|
2956
2965
|
} = useAssistDocumentContext(), { value: docValue, formState } = structure.useDocumentPane(), docValueRef = react.useRef(docValue), formStateRef = react.useRef(formState);
|
|
2957
2966
|
formStateRef.current = formState;
|
|
2958
2967
|
const currentUser = sanity.useCurrentUser(), isHidden = !assistDocument, pathKey = usePathKey(props.path), typePath = useTypePath(docValue, pathKey), assistDocumentId2 = assistDocument?._id, { requestRunInstruction } = useRequestRunInstruction({
|
|
@@ -3040,14 +3049,22 @@ const assistFieldActions = {
|
|
|
3040
3049
|
path
|
|
3041
3050
|
};
|
|
3042
3051
|
}
|
|
3043
|
-
), []),
|
|
3052
|
+
), []), parentSchemaType = react.useMemo(() => {
|
|
3053
|
+
if (props.path.length) {
|
|
3054
|
+
if (props.path.length === 1)
|
|
3055
|
+
return documentSchemaType;
|
|
3056
|
+
} else return;
|
|
3057
|
+
const parentPath = props.path.slice(0, -1), typePath2 = getTypePath(docValueRef.current, sanity.pathToString(parentPath));
|
|
3058
|
+
return typePath2 ? fieldRefsByTypePath[typePath2]?.schemaType : void 0;
|
|
3059
|
+
}, [fieldRefsByTypePath, props.path, documentSchemaType]), customActions = useCustomFieldActions({
|
|
3044
3060
|
actionType: props.path.length ? "field" : "document",
|
|
3045
3061
|
documentIdForAction: assistableDocumentId,
|
|
3046
3062
|
schemaType,
|
|
3047
3063
|
documentSchemaType,
|
|
3048
3064
|
path: props.path,
|
|
3049
3065
|
getDocumentValue,
|
|
3050
|
-
getConditionalPaths
|
|
3066
|
+
getConditionalPaths,
|
|
3067
|
+
parentSchemaType
|
|
3051
3068
|
}), manageInstructionsItem = react.useMemo(
|
|
3052
3069
|
() => ({
|
|
3053
3070
|
type: "action",
|