@sanity/document-internationalization 0.1.5 → 0.3.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/CHANGELOG.md +6 -0
- package/lib/actions/DeleteWithi18nAction.d.ts +2 -16
- package/lib/actions/DuplicateWithi18nAction.d.ts +2 -8
- package/lib/actions/PublishWithi18nAction.d.ts +2 -9
- package/lib/actions/index.d.ts +2 -1
- package/lib/actions/index.js +66 -44
- package/lib/actions/index.js.map +1 -1
- package/lib/badges/index.js.map +1 -1
- package/lib/constants/index.js.map +1 -1
- package/lib/language-select/hooks/index.d.ts +0 -1
- package/lib/language-select/hooks/useListeningQuery.d.ts +12 -0
- package/lib/language-select/index.js +308 -319
- package/lib/language-select/index.js.map +1 -1
- package/lib/structure/index.js +12 -6
- package/lib/structure/index.js.map +1 -1
- package/lib/utils/index.js.map +1 -1
- package/lib/validators/index.js.map +1 -1
- package/package.json +10 -8
- package/lib/language-select/hooks/useManyEditStates.d.ts +0 -1
- package/lib/language-select/hooks/useManyObservables.d.ts +0 -2
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,11 @@
|
|
|
1
1
|
# CHANGELOG
|
|
2
2
|
|
|
3
|
+
## v0.1.7
|
|
4
|
+
* For base I18n documents the default "Delete" action will now be replaced with the Delete (incl. translations)" action. The default "Delete" action does not make sense for base documents in any scenario as it results in broken references.
|
|
5
|
+
|
|
6
|
+
## v0.1.6
|
|
7
|
+
* Fixed translation maintenance functionality
|
|
8
|
+
|
|
3
9
|
## v0.1.5
|
|
4
10
|
* Don't override `child` resolver as it is not required anymore. This way it will correctly fallback on the Studio's structure definition
|
|
5
11
|
|
|
@@ -1,16 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
export declare const DeleteWithi18nAction: ({ id, type, onComplete }: IResolverProps) => {
|
|
4
|
-
onHandle: () => void;
|
|
5
|
-
color: string;
|
|
6
|
-
icon: any;
|
|
7
|
-
disabled: boolean;
|
|
8
|
-
title: any;
|
|
9
|
-
label: string;
|
|
10
|
-
dialog: false | {
|
|
11
|
-
type: string;
|
|
12
|
-
onClose: (() => void) | undefined;
|
|
13
|
-
title: string;
|
|
14
|
-
content: JSX.Element | null;
|
|
15
|
-
};
|
|
16
|
-
};
|
|
1
|
+
import type { DocumentActionComponent } from '@sanity/base';
|
|
2
|
+
export declare const DeleteWithi18nAction: DocumentActionComponent;
|
|
@@ -1,8 +1,2 @@
|
|
|
1
|
-
import {
|
|
2
|
-
export declare const DuplicateWithi18nAction:
|
|
3
|
-
icon: any;
|
|
4
|
-
disabled: boolean;
|
|
5
|
-
title: any;
|
|
6
|
-
label: string;
|
|
7
|
-
onHandle: () => Promise<void>;
|
|
8
|
-
};
|
|
1
|
+
import type { DocumentActionComponent } from '@sanity/base';
|
|
2
|
+
export declare const DuplicateWithi18nAction: DocumentActionComponent;
|
|
@@ -1,9 +1,2 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
3
|
-
export declare const PublishWithi18nAction: ({ type, id, onComplete }: IResolverProps) => {
|
|
4
|
-
disabled: boolean;
|
|
5
|
-
label: string;
|
|
6
|
-
icon: React.ForwardRefExoticComponent<Pick<React.SVGProps<SVGSVGElement>, "string" | "fr" | "id" | "lang" | "name" | "path" | "type" | "ideographic" | "alphabetic" | "hanging" | "mathematical" | "className" | "color" | "height" | "max" | "media" | "method" | "min" | "style" | "target" | "width" | "role" | "tabIndex" | "crossOrigin" | "accentHeight" | "accumulate" | "additive" | "alignmentBaseline" | "allowReorder" | "amplitude" | "arabicForm" | "ascent" | "attributeName" | "attributeType" | "autoReverse" | "azimuth" | "baseFrequency" | "baselineShift" | "baseProfile" | "bbox" | "begin" | "bias" | "by" | "calcMode" | "capHeight" | "clip" | "clipPath" | "clipPathUnits" | "clipRule" | "colorInterpolation" | "colorInterpolationFilters" | "colorProfile" | "colorRendering" | "contentScriptType" | "contentStyleType" | "cursor" | "cx" | "cy" | "d" | "decelerate" | "descent" | "diffuseConstant" | "direction" | "display" | "divisor" | "dominantBaseline" | "dur" | "dx" | "dy" | "edgeMode" | "elevation" | "enableBackground" | "end" | "exponent" | "externalResourcesRequired" | "fill" | "fillOpacity" | "fillRule" | "filter" | "filterRes" | "filterUnits" | "floodColor" | "floodOpacity" | "focusable" | "fontFamily" | "fontSize" | "fontSizeAdjust" | "fontStretch" | "fontStyle" | "fontVariant" | "fontWeight" | "format" | "from" | "fx" | "fy" | "g1" | "g2" | "glyphName" | "glyphOrientationHorizontal" | "glyphOrientationVertical" | "glyphRef" | "gradientTransform" | "gradientUnits" | "horizAdvX" | "horizOriginX" | "href" | "imageRendering" | "in2" | "in" | "intercept" | "k1" | "k2" | "k3" | "k4" | "k" | "kernelMatrix" | "kernelUnitLength" | "kerning" | "keyPoints" | "keySplines" | "keyTimes" | "lengthAdjust" | "letterSpacing" | "lightingColor" | "limitingConeAngle" | "local" | "markerEnd" | "markerHeight" | "markerMid" | "markerStart" | "markerUnits" | "markerWidth" | "mask" | "maskContentUnits" | "maskUnits" | "mode" | "numOctaves" | "offset" | "opacity" | "operator" | "order" | "orient" | "orientation" | "origin" | "overflow" | "overlinePosition" | "overlineThickness" | "paintOrder" | "panose1" | "pathLength" | "patternContentUnits" | "patternTransform" | "patternUnits" | "pointerEvents" | "points" | "pointsAtX" | "pointsAtY" | "pointsAtZ" | "preserveAlpha" | "preserveAspectRatio" | "primitiveUnits" | "r" | "radius" | "refX" | "refY" | "renderingIntent" | "repeatCount" | "repeatDur" | "requiredExtensions" | "requiredFeatures" | "restart" | "result" | "rotate" | "rx" | "ry" | "scale" | "seed" | "shapeRendering" | "slope" | "spacing" | "specularConstant" | "specularExponent" | "speed" | "spreadMethod" | "startOffset" | "stdDeviation" | "stemh" | "stemv" | "stitchTiles" | "stopColor" | "stopOpacity" | "strikethroughPosition" | "strikethroughThickness" | "stroke" | "strokeDasharray" | "strokeDashoffset" | "strokeLinecap" | "strokeLinejoin" | "strokeMiterlimit" | "strokeOpacity" | "strokeWidth" | "surfaceScale" | "systemLanguage" | "tableValues" | "targetX" | "targetY" | "textAnchor" | "textDecoration" | "textLength" | "textRendering" | "to" | "transform" | "u1" | "u2" | "underlinePosition" | "underlineThickness" | "unicode" | "unicodeBidi" | "unicodeRange" | "unitsPerEm" | "vAlphabetic" | "values" | "vectorEffect" | "version" | "vertAdvY" | "vertOriginX" | "vertOriginY" | "vHanging" | "vIdeographic" | "viewBox" | "viewTarget" | "visibility" | "vMathematical" | "widths" | "wordSpacing" | "writingMode" | "x1" | "x2" | "x" | "xChannelSelector" | "xHeight" | "xlinkActuate" | "xlinkArcrole" | "xlinkHref" | "xlinkRole" | "xlinkShow" | "xlinkTitle" | "xlinkType" | "xmlBase" | "xmlLang" | "xmlns" | "xmlnsXlink" | "xmlSpace" | "y1" | "y2" | "y" | "yChannelSelector" | "z" | "zoomAndPan" | "aria-activedescendant" | "aria-atomic" | "aria-autocomplete" | "aria-busy" | "aria-checked" | "aria-colcount" | "aria-colindex" | "aria-colspan" | "aria-controls" | "aria-current" | "aria-describedby" | "aria-details" | "aria-disabled" | "aria-dropeffect" | "aria-errormessage" | "aria-expanded" | "aria-flowto" | "aria-grabbed" | "aria-haspopup" | "aria-hidden" | "aria-invalid" | "aria-keyshortcuts" | "aria-label" | "aria-labelledby" | "aria-level" | "aria-live" | "aria-modal" | "aria-multiline" | "aria-multiselectable" | "aria-orientation" | "aria-owns" | "aria-placeholder" | "aria-posinset" | "aria-pressed" | "aria-readonly" | "aria-relevant" | "aria-required" | "aria-roledescription" | "aria-rowcount" | "aria-rowindex" | "aria-rowspan" | "aria-selected" | "aria-setsize" | "aria-sort" | "aria-valuemax" | "aria-valuemin" | "aria-valuenow" | "aria-valuetext" | "children" | "dangerouslySetInnerHTML" | "onCopy" | "onCopyCapture" | "onCut" | "onCutCapture" | "onPaste" | "onPasteCapture" | "onCompositionEnd" | "onCompositionEndCapture" | "onCompositionStart" | "onCompositionStartCapture" | "onCompositionUpdate" | "onCompositionUpdateCapture" | "onFocus" | "onFocusCapture" | "onBlur" | "onBlurCapture" | "onChange" | "onChangeCapture" | "onBeforeInput" | "onBeforeInputCapture" | "onInput" | "onInputCapture" | "onReset" | "onResetCapture" | "onSubmit" | "onSubmitCapture" | "onInvalid" | "onInvalidCapture" | "onLoad" | "onLoadCapture" | "onError" | "onErrorCapture" | "onKeyDown" | "onKeyDownCapture" | "onKeyPress" | "onKeyPressCapture" | "onKeyUp" | "onKeyUpCapture" | "onAbort" | "onAbortCapture" | "onCanPlay" | "onCanPlayCapture" | "onCanPlayThrough" | "onCanPlayThroughCapture" | "onDurationChange" | "onDurationChangeCapture" | "onEmptied" | "onEmptiedCapture" | "onEncrypted" | "onEncryptedCapture" | "onEnded" | "onEndedCapture" | "onLoadedData" | "onLoadedDataCapture" | "onLoadedMetadata" | "onLoadedMetadataCapture" | "onLoadStart" | "onLoadStartCapture" | "onPause" | "onPauseCapture" | "onPlay" | "onPlayCapture" | "onPlaying" | "onPlayingCapture" | "onProgress" | "onProgressCapture" | "onRateChange" | "onRateChangeCapture" | "onSeeked" | "onSeekedCapture" | "onSeeking" | "onSeekingCapture" | "onStalled" | "onStalledCapture" | "onSuspend" | "onSuspendCapture" | "onTimeUpdate" | "onTimeUpdateCapture" | "onVolumeChange" | "onVolumeChangeCapture" | "onWaiting" | "onWaitingCapture" | "onAuxClick" | "onAuxClickCapture" | "onClick" | "onClickCapture" | "onContextMenu" | "onContextMenuCapture" | "onDoubleClick" | "onDoubleClickCapture" | "onDrag" | "onDragCapture" | "onDragEnd" | "onDragEndCapture" | "onDragEnter" | "onDragEnterCapture" | "onDragExit" | "onDragExitCapture" | "onDragLeave" | "onDragLeaveCapture" | "onDragOver" | "onDragOverCapture" | "onDragStart" | "onDragStartCapture" | "onDrop" | "onDropCapture" | "onMouseDown" | "onMouseDownCapture" | "onMouseEnter" | "onMouseLeave" | "onMouseMove" | "onMouseMoveCapture" | "onMouseOut" | "onMouseOutCapture" | "onMouseOver" | "onMouseOverCapture" | "onMouseUp" | "onMouseUpCapture" | "onSelect" | "onSelectCapture" | "onTouchCancel" | "onTouchCancelCapture" | "onTouchEnd" | "onTouchEndCapture" | "onTouchMove" | "onTouchMoveCapture" | "onTouchStart" | "onTouchStartCapture" | "onPointerDown" | "onPointerDownCapture" | "onPointerMove" | "onPointerMoveCapture" | "onPointerUp" | "onPointerUpCapture" | "onPointerCancel" | "onPointerCancelCapture" | "onPointerEnter" | "onPointerEnterCapture" | "onPointerLeave" | "onPointerLeaveCapture" | "onPointerOver" | "onPointerOverCapture" | "onPointerOut" | "onPointerOutCapture" | "onGotPointerCapture" | "onGotPointerCaptureCapture" | "onLostPointerCapture" | "onLostPointerCaptureCapture" | "onScroll" | "onScrollCapture" | "onWheel" | "onWheelCapture" | "onAnimationStart" | "onAnimationStartCapture" | "onAnimationEnd" | "onAnimationEndCapture" | "onAnimationIteration" | "onAnimationIterationCapture" | "onTransitionEnd" | "onTransitionEndCapture" | "key"> & React.RefAttributes<SVGSVGElement>>;
|
|
7
|
-
shortcut: string | null;
|
|
8
|
-
onHandle: () => void;
|
|
9
|
-
};
|
|
1
|
+
import type { DocumentActionComponent } from '@sanity/base';
|
|
2
|
+
export declare const PublishWithi18nAction: DocumentActionComponent;
|
package/lib/actions/index.d.ts
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import 'regenerator-runtime';
|
|
2
|
+
import type { DocumentActionComponent } from '@sanity/base';
|
|
2
3
|
import { IResolverProps } from '../types';
|
|
3
4
|
import { PublishWithi18nAction } from './PublishWithi18nAction';
|
|
4
5
|
import { DeleteWithi18nAction } from './DeleteWithi18nAction';
|
|
5
6
|
import { DuplicateWithi18nAction } from './DuplicateWithi18nAction';
|
|
6
7
|
export { PublishWithi18nAction, DeleteWithi18nAction, DuplicateWithi18nAction };
|
|
7
|
-
declare const _default: (props: IResolverProps) =>
|
|
8
|
+
declare const _default: (props: IResolverProps) => DocumentActionComponent[];
|
|
8
9
|
export default _default;
|
package/lib/actions/index.js
CHANGED
|
@@ -3,20 +3,20 @@
|
|
|
3
3
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
4
|
|
|
5
5
|
var defaultResolve = require('part:@sanity/base/document-actions');
|
|
6
|
-
var _asyncToGenerator = require('@babel/runtime/helpers/asyncToGenerator');
|
|
7
|
-
var _slicedToArray = require('@babel/runtime/helpers/slicedToArray');
|
|
8
|
-
var _regeneratorRuntime = require('@babel/runtime/regenerator');
|
|
9
|
-
var React = require('react');
|
|
10
|
-
var reactHooks = require('@sanity/react-hooks');
|
|
11
|
-
var ui = require('@sanity/ui');
|
|
12
|
-
var icons = require('@sanity/icons');
|
|
13
6
|
var config = require('config:@sanity/document-internationalization');
|
|
14
7
|
var schemas = require('part:@sanity/base/schema');
|
|
15
8
|
var client = require('part:@sanity/base/client');
|
|
9
|
+
var _asyncToGenerator = require('@babel/runtime/helpers/asyncToGenerator');
|
|
10
|
+
var _regeneratorRuntime = require('@babel/runtime/regenerator');
|
|
16
11
|
var languagesLoaderFn = require('part:@sanity/document-internationalization/languages/loader?');
|
|
17
12
|
var _defineProperty = require('@babel/runtime/helpers/defineProperty');
|
|
18
13
|
var _ = require('lodash');
|
|
19
14
|
require('@sanity/types');
|
|
15
|
+
var _slicedToArray = require('@babel/runtime/helpers/slicedToArray');
|
|
16
|
+
var React = require('react');
|
|
17
|
+
var reactHooks = require('@sanity/react-hooks');
|
|
18
|
+
var ui = require('@sanity/ui');
|
|
19
|
+
var icons = require('@sanity/icons');
|
|
20
20
|
var TrashIcon = require('part:@sanity/base/trash-icon');
|
|
21
21
|
var ConfirmDeleteDialog = require('@sanity/desk-tool/lib/components/confirmDeleteDialog/ConfirmDeleteDialog');
|
|
22
22
|
var ContentCopyIcon = require('part:@sanity/base/content-copy-icon');
|
|
@@ -43,17 +43,17 @@ function _interopNamespace(e) {
|
|
|
43
43
|
}
|
|
44
44
|
|
|
45
45
|
var defaultResolve__default = /*#__PURE__*/_interopDefaultLegacy(defaultResolve);
|
|
46
|
-
var _asyncToGenerator__default = /*#__PURE__*/_interopDefaultLegacy(_asyncToGenerator);
|
|
47
|
-
var _slicedToArray__default = /*#__PURE__*/_interopDefaultLegacy(_slicedToArray);
|
|
48
|
-
var _regeneratorRuntime__default = /*#__PURE__*/_interopDefaultLegacy(_regeneratorRuntime);
|
|
49
|
-
var React__namespace = /*#__PURE__*/_interopNamespace(React);
|
|
50
|
-
var React__default = /*#__PURE__*/_interopDefaultLegacy(React);
|
|
51
46
|
var config__default = /*#__PURE__*/_interopDefaultLegacy(config);
|
|
52
47
|
var schemas__default = /*#__PURE__*/_interopDefaultLegacy(schemas);
|
|
53
48
|
var client__default = /*#__PURE__*/_interopDefaultLegacy(client);
|
|
49
|
+
var _asyncToGenerator__default = /*#__PURE__*/_interopDefaultLegacy(_asyncToGenerator);
|
|
50
|
+
var _regeneratorRuntime__default = /*#__PURE__*/_interopDefaultLegacy(_regeneratorRuntime);
|
|
54
51
|
var languagesLoaderFn__default = /*#__PURE__*/_interopDefaultLegacy(languagesLoaderFn);
|
|
55
52
|
var _defineProperty__default = /*#__PURE__*/_interopDefaultLegacy(_defineProperty);
|
|
56
53
|
var ___default = /*#__PURE__*/_interopDefaultLegacy(_);
|
|
54
|
+
var _slicedToArray__default = /*#__PURE__*/_interopDefaultLegacy(_slicedToArray);
|
|
55
|
+
var React__namespace = /*#__PURE__*/_interopNamespace(React);
|
|
56
|
+
var React__default = /*#__PURE__*/_interopDefaultLegacy(React);
|
|
57
57
|
var TrashIcon__default = /*#__PURE__*/_interopDefaultLegacy(TrashIcon);
|
|
58
58
|
var ContentCopyIcon__default = /*#__PURE__*/_interopDefaultLegacy(ContentCopyIcon);
|
|
59
59
|
|
|
@@ -2006,15 +2006,10 @@ function useDelayedFlag() {
|
|
|
2006
2006
|
var delayedOn = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;
|
|
2007
2007
|
var delayedOff = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : true;
|
|
2008
2008
|
|
|
2009
|
-
var _useState = React.useState(
|
|
2010
|
-
_useState2 = _slicedToArray__default["default"](_useState, 2)
|
|
2011
|
-
_useState2[0]
|
|
2012
|
-
_useState2[1];
|
|
2013
|
-
|
|
2014
|
-
var _useState3 = React.useState(value),
|
|
2015
|
-
_useState4 = _slicedToArray__default["default"](_useState3, 2),
|
|
2016
|
-
flag = _useState4[0],
|
|
2017
|
-
setFlag = _useState4[1];
|
|
2009
|
+
var _useState = React.useState(value),
|
|
2010
|
+
_useState2 = _slicedToArray__default["default"](_useState, 2),
|
|
2011
|
+
flag = _useState2[0],
|
|
2012
|
+
setFlag = _useState2[1];
|
|
2018
2013
|
|
|
2019
2014
|
React.useEffect(function () {
|
|
2020
2015
|
if (flag !== value) {
|
|
@@ -2026,9 +2021,9 @@ function useDelayedFlag() {
|
|
|
2026
2021
|
return function () {
|
|
2027
2022
|
return clearTimeout(timeoutId);
|
|
2028
2023
|
};
|
|
2029
|
-
} else {
|
|
2030
|
-
setFlag(true);
|
|
2031
2024
|
}
|
|
2025
|
+
|
|
2026
|
+
setFlag(true);
|
|
2032
2027
|
} else if (!value) {
|
|
2033
2028
|
if (delayedOff) {
|
|
2034
2029
|
var _timeoutId = setTimeout(function () {
|
|
@@ -2038,11 +2033,13 @@ function useDelayedFlag() {
|
|
|
2038
2033
|
return function () {
|
|
2039
2034
|
return clearTimeout(_timeoutId);
|
|
2040
2035
|
};
|
|
2041
|
-
} else {
|
|
2042
|
-
setFlag(false);
|
|
2043
2036
|
}
|
|
2037
|
+
|
|
2038
|
+
setFlag(false);
|
|
2044
2039
|
}
|
|
2045
2040
|
}
|
|
2041
|
+
|
|
2042
|
+
return undefined;
|
|
2046
2043
|
}, [value, timeout, delayedOn, delayedOff]);
|
|
2047
2044
|
return flag;
|
|
2048
2045
|
}
|
|
@@ -2053,6 +2050,7 @@ var PublishWithi18nAction = function PublishWithi18nAction(_ref) {
|
|
|
2053
2050
|
onComplete = _ref.onComplete;
|
|
2054
2051
|
var toast = ui.useToast();
|
|
2055
2052
|
var baseDocumentId = getBaseIdFromId(id);
|
|
2053
|
+
var updatingIntlFieldsPromiseRef = React__namespace.useRef(null);
|
|
2056
2054
|
|
|
2057
2055
|
var _React$useState = React__namespace.useState(null),
|
|
2058
2056
|
_React$useState2 = _slicedToArray__default["default"](_React$useState, 2),
|
|
@@ -2159,11 +2157,15 @@ var PublishWithi18nAction = function PublishWithi18nAction(_ref) {
|
|
|
2159
2157
|
}, [publishState, draft]);
|
|
2160
2158
|
React__namespace.useEffect(function () {
|
|
2161
2159
|
if (publishState === 'published') {
|
|
2162
|
-
|
|
2163
|
-
|
|
2164
|
-
|
|
2160
|
+
if (!updatingIntlFieldsPromiseRef.current) {
|
|
2161
|
+
updatingIntlFieldsPromiseRef.current = doUpdateIntlFields().then(function () {
|
|
2162
|
+
return onComplete && onComplete();
|
|
2163
|
+
})["finally"](function () {
|
|
2164
|
+
return updatingIntlFieldsPromiseRef.current = null;
|
|
2165
|
+
});
|
|
2166
|
+
}
|
|
2165
2167
|
}
|
|
2166
|
-
}, [publishState]);
|
|
2168
|
+
}, [publishState, onComplete, doUpdateIntlFields]);
|
|
2167
2169
|
return {
|
|
2168
2170
|
disabled: disabled,
|
|
2169
2171
|
label: label,
|
|
@@ -2304,6 +2306,7 @@ var DeleteWithi18nAction = function DeleteWithi18nAction(_ref) {
|
|
|
2304
2306
|
color: 'danger',
|
|
2305
2307
|
icon: TrashIcon__default["default"],
|
|
2306
2308
|
disabled: isDeleting || Boolean(deleteOp.disabled) || syncState.isSyncing || baseDocumentSyncState.isSyncing,
|
|
2309
|
+
shortcut: 'CTRL+ALT+D',
|
|
2307
2310
|
title: deleteOp.disabled && DISABLED_REASON_TITLE$1[deleteOp.disabled] || '',
|
|
2308
2311
|
label: isDeleting ? UiMessages.deleteAll.deleting : UiMessages.deleteAll.buttonTitle,
|
|
2309
2312
|
dialog: isConfirmDialogOpen && {
|
|
@@ -2325,13 +2328,17 @@ function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { va
|
|
|
2325
2328
|
var DISABLED_REASON_TITLE = {
|
|
2326
2329
|
NOTHING_TO_DUPLICATE: "This document doesn't yet exist so there's nothing to duplicate"
|
|
2327
2330
|
};
|
|
2328
|
-
var DuplicateWithi18nAction = function DuplicateWithi18nAction(
|
|
2331
|
+
var DuplicateWithi18nAction = function DuplicateWithi18nAction(_ref) {
|
|
2332
|
+
var id = _ref.id,
|
|
2333
|
+
type = _ref.type,
|
|
2334
|
+
draft = _ref.draft,
|
|
2335
|
+
published = _ref.published;
|
|
2329
2336
|
var toast = ui.useToast();
|
|
2330
2337
|
var client = getSanityClient();
|
|
2331
|
-
var baseDocumentId = getBaseIdFromId(
|
|
2338
|
+
var baseDocumentId = getBaseIdFromId(id);
|
|
2332
2339
|
|
|
2333
|
-
var
|
|
2334
|
-
duplicateOp =
|
|
2340
|
+
var _ref2 = reactHooks.useDocumentOperation(id, type),
|
|
2341
|
+
duplicateOp = _ref2.duplicate;
|
|
2335
2342
|
|
|
2336
2343
|
var _React$useState = React__default["default"].useState(false),
|
|
2337
2344
|
_React$useState2 = _slicedToArray__default["default"](_React$useState, 2),
|
|
@@ -2339,8 +2346,7 @@ var DuplicateWithi18nAction = function DuplicateWithi18nAction(props) {
|
|
|
2339
2346
|
setDuplicating = _React$useState2[1];
|
|
2340
2347
|
|
|
2341
2348
|
var onDuplicate = React__default["default"].useCallback( /*#__PURE__*/_asyncToGenerator__default["default"]( /*#__PURE__*/_regeneratorRuntime__default["default"].mark(function _callee() {
|
|
2342
|
-
var
|
|
2343
|
-
|
|
2349
|
+
var dupeId, translations, transaction;
|
|
2344
2350
|
return _regeneratorRuntime__default["default"].wrap(function _callee$(_context) {
|
|
2345
2351
|
while (1) {
|
|
2346
2352
|
switch (_context.prev = _context.next) {
|
|
@@ -2354,9 +2360,9 @@ var DuplicateWithi18nAction = function DuplicateWithi18nAction(props) {
|
|
|
2354
2360
|
case 5:
|
|
2355
2361
|
translations = _context.sent;
|
|
2356
2362
|
transaction = client.transaction();
|
|
2357
|
-
transaction.create(_objectSpread(_objectSpread({},
|
|
2363
|
+
transaction.create(_objectSpread(_objectSpread({}, draft !== null && draft !== void 0 ? draft : published), {}, {
|
|
2358
2364
|
_id: dupeId,
|
|
2359
|
-
_type:
|
|
2365
|
+
_type: type
|
|
2360
2366
|
}));
|
|
2361
2367
|
translations.forEach(function (t) {
|
|
2362
2368
|
var isDraft = t._id.startsWith('drafts.');
|
|
@@ -2388,7 +2394,7 @@ var DuplicateWithi18nAction = function DuplicateWithi18nAction(props) {
|
|
|
2388
2394
|
}
|
|
2389
2395
|
}
|
|
2390
2396
|
}, _callee, null, [[1, 13]]);
|
|
2391
|
-
})), [
|
|
2397
|
+
})), [client, toast, baseDocumentId, type, draft, published]);
|
|
2392
2398
|
return {
|
|
2393
2399
|
icon: ContentCopyIcon__default["default"],
|
|
2394
2400
|
disabled: Boolean(duplicateOp.disabled) || isDuplicating,
|
|
@@ -2401,13 +2407,29 @@ var DuplicateWithi18nAction = function DuplicateWithi18nAction(props) {
|
|
|
2401
2407
|
var index = (function (props) {
|
|
2402
2408
|
var schema = getSchema(props.type);
|
|
2403
2409
|
var isI18n = schema && schema.i18n;
|
|
2404
|
-
var
|
|
2405
|
-
|
|
2406
|
-
|
|
2410
|
+
var isBase = props.id == getBaseIdFromId(props.id);
|
|
2411
|
+
var actions = defaultResolve__default["default"](props);
|
|
2412
|
+
|
|
2413
|
+
if (isI18n) {
|
|
2414
|
+
actions = actions.map(function (Action) {
|
|
2415
|
+
var isPublishAction = Action === defaultResolve.PublishAction;
|
|
2416
|
+
var isDeleteAction = Action === defaultResolve.DeleteAction; // replace default publish actions with i18n publish actions
|
|
2417
|
+
|
|
2418
|
+
if (isPublishAction) {
|
|
2419
|
+
return PublishWithi18nAction;
|
|
2420
|
+
} // replace base delete action with delete with i18n action
|
|
2407
2421
|
|
|
2408
|
-
|
|
2409
|
-
|
|
2410
|
-
|
|
2422
|
+
|
|
2423
|
+
if (isDeleteAction && isBase) {
|
|
2424
|
+
return DeleteWithi18nAction;
|
|
2425
|
+
}
|
|
2426
|
+
|
|
2427
|
+
return Action;
|
|
2428
|
+
}); // push duplicate action
|
|
2429
|
+
|
|
2430
|
+
if (isBase) {
|
|
2431
|
+
actions.push(DuplicateWithi18nAction);
|
|
2432
|
+
}
|
|
2411
2433
|
}
|
|
2412
2434
|
|
|
2413
2435
|
return actions;
|