@sanity/document-internationalization 0.1.4 → 0.1.7

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 CHANGED
@@ -1,5 +1,14 @@
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
+
9
+ ## v0.1.5
10
+ * Don't override `child` resolver as it is not required anymore. This way it will correctly fallback on the Studio's structure definition
11
+
3
12
  ## v0.1.4
4
13
  * Fixed an issue with filtering `all:part:@sanity/desk-tool/language-select-component`
5
14
 
@@ -1,16 +1,2 @@
1
- /// <reference types="react" />
2
- import { IResolverProps } from '../types';
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 { IResolverProps } from '../types';
2
- export declare const DuplicateWithi18nAction: (props: IResolverProps) => {
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 * as React from 'react';
2
- import { IResolverProps } from '../types';
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;
@@ -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) => any;
8
+ declare const _default: (props: IResolverProps) => DocumentActionComponent[];
8
9
  export default _default;
@@ -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
 
@@ -2053,6 +2053,7 @@ var PublishWithi18nAction = function PublishWithi18nAction(_ref) {
2053
2053
  onComplete = _ref.onComplete;
2054
2054
  var toast = ui.useToast();
2055
2055
  var baseDocumentId = getBaseIdFromId(id);
2056
+ var updatingIntlFieldsPromiseRef = React__namespace.useRef(null);
2056
2057
 
2057
2058
  var _React$useState = React__namespace.useState(null),
2058
2059
  _React$useState2 = _slicedToArray__default["default"](_React$useState, 2),
@@ -2159,11 +2160,15 @@ var PublishWithi18nAction = function PublishWithi18nAction(_ref) {
2159
2160
  }, [publishState, draft]);
2160
2161
  React__namespace.useEffect(function () {
2161
2162
  if (publishState === 'published') {
2162
- doUpdateIntlFields().then(function () {
2163
- if (onComplete) onComplete();
2164
- });
2163
+ if (!updatingIntlFieldsPromiseRef.current) {
2164
+ updatingIntlFieldsPromiseRef.current = doUpdateIntlFields().then(function () {
2165
+ return onComplete && onComplete();
2166
+ })["finally"](function () {
2167
+ return updatingIntlFieldsPromiseRef.current = null;
2168
+ });
2169
+ }
2165
2170
  }
2166
- }, [publishState]);
2171
+ }, [publishState, onComplete, doUpdateIntlFields]);
2167
2172
  return {
2168
2173
  disabled: disabled,
2169
2174
  label: label,
@@ -2304,6 +2309,7 @@ var DeleteWithi18nAction = function DeleteWithi18nAction(_ref) {
2304
2309
  color: 'danger',
2305
2310
  icon: TrashIcon__default["default"],
2306
2311
  disabled: isDeleting || Boolean(deleteOp.disabled) || syncState.isSyncing || baseDocumentSyncState.isSyncing,
2312
+ shortcut: 'CTRL+ALT+D',
2307
2313
  title: deleteOp.disabled && DISABLED_REASON_TITLE$1[deleteOp.disabled] || '',
2308
2314
  label: isDeleting ? UiMessages.deleteAll.deleting : UiMessages.deleteAll.buttonTitle,
2309
2315
  dialog: isConfirmDialogOpen && {
@@ -2325,13 +2331,17 @@ function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { va
2325
2331
  var DISABLED_REASON_TITLE = {
2326
2332
  NOTHING_TO_DUPLICATE: "This document doesn't yet exist so there's nothing to duplicate"
2327
2333
  };
2328
- var DuplicateWithi18nAction = function DuplicateWithi18nAction(props) {
2334
+ var DuplicateWithi18nAction = function DuplicateWithi18nAction(_ref) {
2335
+ var id = _ref.id,
2336
+ type = _ref.type,
2337
+ draft = _ref.draft,
2338
+ published = _ref.published;
2329
2339
  var toast = ui.useToast();
2330
2340
  var client = getSanityClient();
2331
- var baseDocumentId = getBaseIdFromId(props.id);
2341
+ var baseDocumentId = getBaseIdFromId(id);
2332
2342
 
2333
- var _ref = reactHooks.useDocumentOperation(props.id, props.type),
2334
- duplicateOp = _ref.duplicate;
2343
+ var _ref2 = reactHooks.useDocumentOperation(id, type),
2344
+ duplicateOp = _ref2.duplicate;
2335
2345
 
2336
2346
  var _React$useState = React__default["default"].useState(false),
2337
2347
  _React$useState2 = _slicedToArray__default["default"](_React$useState, 2),
@@ -2339,8 +2349,7 @@ var DuplicateWithi18nAction = function DuplicateWithi18nAction(props) {
2339
2349
  setDuplicating = _React$useState2[1];
2340
2350
 
2341
2351
  var onDuplicate = React__default["default"].useCallback( /*#__PURE__*/_asyncToGenerator__default["default"]( /*#__PURE__*/_regeneratorRuntime__default["default"].mark(function _callee() {
2342
- var _props$draft, dupeId, translations, transaction;
2343
-
2352
+ var dupeId, translations, transaction;
2344
2353
  return _regeneratorRuntime__default["default"].wrap(function _callee$(_context) {
2345
2354
  while (1) {
2346
2355
  switch (_context.prev = _context.next) {
@@ -2354,9 +2363,9 @@ var DuplicateWithi18nAction = function DuplicateWithi18nAction(props) {
2354
2363
  case 5:
2355
2364
  translations = _context.sent;
2356
2365
  transaction = client.transaction();
2357
- transaction.create(_objectSpread(_objectSpread({}, (_props$draft = props.draft) !== null && _props$draft !== void 0 ? _props$draft : props.published), {}, {
2366
+ transaction.create(_objectSpread(_objectSpread({}, draft !== null && draft !== void 0 ? draft : published), {}, {
2358
2367
  _id: dupeId,
2359
- _type: props.type
2368
+ _type: type
2360
2369
  }));
2361
2370
  translations.forEach(function (t) {
2362
2371
  var isDraft = t._id.startsWith('drafts.');
@@ -2388,7 +2397,7 @@ var DuplicateWithi18nAction = function DuplicateWithi18nAction(props) {
2388
2397
  }
2389
2398
  }
2390
2399
  }, _callee, null, [[1, 13]]);
2391
- })), [baseDocumentId, props.onComplete, props.type, props.draft, props.published]);
2400
+ })), [client, toast, baseDocumentId, type, draft, published]);
2392
2401
  return {
2393
2402
  icon: ContentCopyIcon__default["default"],
2394
2403
  disabled: Boolean(duplicateOp.disabled) || isDuplicating,
@@ -2401,13 +2410,29 @@ var DuplicateWithi18nAction = function DuplicateWithi18nAction(props) {
2401
2410
  var index = (function (props) {
2402
2411
  var schema = getSchema(props.type);
2403
2412
  var isI18n = schema && schema.i18n;
2404
- var actions = defaultResolve__default["default"](props).map(function (Action) {
2405
- return Action === defaultResolve.PublishAction && isI18n ? PublishWithi18nAction : Action;
2406
- });
2413
+ var isBase = props.id == getBaseIdFromId(props.id);
2414
+ var actions = defaultResolve__default["default"](props);
2415
+
2416
+ if (isI18n) {
2417
+ actions = actions.map(function (Action) {
2418
+ var isPublishAction = Action === defaultResolve.PublishAction;
2419
+ var isDeleteAction = Action === defaultResolve.DeleteAction; // replace default publish actions with i18n publish actions
2420
+
2421
+ if (isPublishAction) {
2422
+ return PublishWithi18nAction;
2423
+ } // replace base delete action with delete with i18n action
2407
2424
 
2408
- if (isI18n && props.id == getBaseIdFromId(props.id)) {
2409
- actions.push(DuplicateWithi18nAction);
2410
- actions.push(DeleteWithi18nAction);
2425
+
2426
+ if (isDeleteAction && isBase) {
2427
+ return DeleteWithi18nAction;
2428
+ }
2429
+
2430
+ return Action;
2431
+ }); // push duplicate action
2432
+
2433
+ if (isBase) {
2434
+ actions.push(DuplicateWithi18nAction);
2435
+ }
2411
2436
  }
2412
2437
 
2413
2438
  return actions;