Socket
Socket
Sign inDemoInstall

@sanity/react-hooks

Package Overview
Dependencies
4
Maintainers
17
Versions
388
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 0.147.10-document-actions.84 to 0.147.10-document-actions.97

lib/@types/parts.d.js

1

lib/index.d.ts

@@ -7,2 +7,1 @@ export { useDocumentOperation } from './useDocumentOperation';

export { useConnectionState } from './useConnectionState';
//# sourceMappingURL=index.d.ts.map

@@ -6,2 +6,1 @@ interface SyncState {

export {};
//# sourceMappingURL=useConnectionState.d.ts.map

@@ -44,3 +44,3 @@ "use strict";

return (0, _rxjs.merge)(connected$, disconnected$);
}))), DISCONNECTED);
}), (0, _operators.distinctUntilChanged)())), DISCONNECTED);
}
export declare function useDocumentOperation(publishedId: any, typeName: any): unknown;
//# sourceMappingURL=useDocumentOperation.d.ts.map

@@ -20,3 +20,3 @@ "use strict";

typeName
}, props$ => props$.pipe((0, _operators.switchMap)((_ref) => {
}, props$ => props$.pipe((0, _operators.distinctUntilChanged)((curr, next) => curr.publishedId === next.publishedId && curr.typeName === next.typeName), (0, _operators.switchMap)((_ref) => {
var publishedId = _ref.publishedId,

@@ -23,0 +23,0 @@ typeName = _ref.typeName;

export declare function useEditState(publishedId: any, typeName: any): unknown;
//# sourceMappingURL=useEditState.d.ts.map

@@ -6,2 +6,1 @@ interface SyncState {

export {};
//# sourceMappingURL=useSyncState.d.ts.map

@@ -1,8 +0,10 @@

declare type Marker = any;
interface Marker {
level: string;
type: string;
}
interface ValidationStatus {
isValidating: boolean;
errors: Marker[];
markers: Marker[];
}
export declare function useValidationStatus(publishedId: any, typeName: any): ValidationStatus;
export {};
//# sourceMappingURL=useValidationStatus.d.ts.map

@@ -14,44 +14,18 @@ "use strict";

var _validation = require("@sanity/validation");
var _rxjs = require("rxjs");
var _schema = _interopRequireDefault(require("part:@sanity/base/schema"));
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _nonIterableRest(); }
function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance"); }
function _iterableToArrayLimit(arr, i) { if (!(Symbol.iterator in Object(arr) || Object.prototype.toString.call(arr) === "[object Arguments]")) { return; } var _arr = []; var _n = true; var _d = false; var _e = undefined; try { for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"] != null) _i["return"](); } finally { if (_d) throw _e; } } return _arr; }
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
function getValidationMarkers(draft, published) {
var doc = draft || published;
if (!doc || !doc._type) {
return (0, _rxjs.of)([]);
}
return (0, _rxjs.from)((0, _validation.validateDocument)(doc, _schema.default));
}
var INITIAL_VALIDATION_STATUS = {
isValidating: true,
errors: []
var INITIAL = {
markers: [],
isValidating: false
};
function useValidationStatus(publishedId, typeName) {
return (0, _useObservable.useObservable)((0, _useObservable.toObservable)([publishedId, typeName], props$ => props$.pipe((0, _operators.switchMap)((_ref) => {
var _ref2 = _slicedToArray(_ref, 2),
publishedId = _ref2[0],
typeName = _ref2[1];
return _document.default.local.editStateOf(publishedId, typeName);
}), (0, _operators.switchMap)(editState => (0, _rxjs.concat)((0, _rxjs.of)(INITIAL_VALIDATION_STATUS), getValidationMarkers(editState.draft, editState.published).pipe((0, _operators.map)(markers => ({
errors: markers,
isValidating: false
}))))))), INITIAL_VALIDATION_STATUS);
return (0, _useObservable.useObservable)((0, _useObservable.toObservable)({
publishedId,
typeName
}, props$ => props$.pipe((0, _operators.switchMap)((_ref) => {
var publishedId = _ref.publishedId,
typeName = _ref.typeName;
return _document.default.local.validationFor(publishedId, typeName);
}))), INITIAL);
}

@@ -10,2 +10,1 @@ import * as React from 'react';

export declare function useObservableContext<T>(context: React.Context<T>): Observable<T>;
//# sourceMappingURL=use-observable.d.ts.map
{
"name": "@sanity/react-hooks",
"version": "0.147.10-document-actions.84+9f45f60db",
"version": "0.147.10-document-actions.97+70b578cd7",
"description": "Officially supported Sanity Studio API building blocks",

@@ -31,3 +31,3 @@ "main": "./lib/index.js",

"dependencies": {
"@sanity/base": "0.147.10-document-actions.84+9f45f60db",
"@sanity/base": "0.147.10-document-actions.97+70b578cd7",
"lodash": "^4.17.15",

@@ -54,3 +54,3 @@ "rxjs": "^6.5.3",

"homepage": "https://www.sanity.io/",
"gitHead": "9f45f60db32cb66dbb88d6a92d9fbc56e7415715"
"gitHead": "70b578cd7a1ba58e29c68ff8e081bb58b80bc757"
}
import documentStore from 'part:@sanity/base/datastore/document'
import {toObservable, useObservable} from './utils/use-observable'
import {filter, mapTo, switchMap} from 'rxjs/operators'
import {filter, mapTo, switchMap, distinctUntilChanged} from 'rxjs/operators'
import {merge, Observable} from 'rxjs'

@@ -30,3 +30,4 @@

}
)
),
distinctUntilChanged()
)

@@ -33,0 +34,0 @@ ),

import documentStore from 'part:@sanity/base/datastore/document'
import {toObservable, useObservable} from './utils/use-observable'
import {switchMap} from 'rxjs/operators'
import {distinctUntilChanged, switchMap} from 'rxjs/operators'

@@ -9,2 +9,5 @@ export function useDocumentOperation(publishedId, typeName) {

props$.pipe(
distinctUntilChanged(
(curr, next) => curr.publishedId === next.publishedId && curr.typeName === next.typeName
),
switchMap(({publishedId, typeName}) => documentStore.local.editOpsOf(publishedId, typeName))

@@ -11,0 +14,0 @@ )

import documentStore from 'part:@sanity/base/datastore/document'
import {toObservable, useObservable} from './utils/use-observable'
import {map, switchMap} from 'rxjs/operators'
import {validateDocument} from '@sanity/validation'
import {concat, from, Observable, of} from 'rxjs'
import schema from 'part:@sanity/base/schema'
import {switchMap} from 'rxjs/operators'
import {Observable} from 'rxjs'
type Marker = any
function getValidationMarkers(draft, published): Observable<Marker[]> {
const doc = draft || published
if (!doc || !doc._type) {
return of([])
}
return from(validateDocument(doc, schema) as Promise<Marker[]>)
interface Marker {
level: string
type: string
}

@@ -20,30 +13,19 @@

isValidating: boolean
errors: Marker[]
markers: Marker[]
}
const INITIAL_VALIDATION_STATUS = {isValidating: true, errors: []}
const INITIAL: ValidationStatus = {markers: [], isValidating: false}
export function useValidationStatus(publishedId, typeName): ValidationStatus {
return useObservable(
toObservable([publishedId, typeName], props$ =>
toObservable({publishedId, typeName}, props$ =>
props$.pipe(
switchMap(
([publishedId, typeName]): Observable<{draft: {}; published: {}}> =>
documentStore.local.editStateOf(publishedId, typeName)
),
switchMap(editState =>
concat(
of(INITIAL_VALIDATION_STATUS),
getValidationMarkers(editState.draft, editState.published).pipe(
map(markers => ({
errors: markers,
isValidating: false
}))
)
)
({publishedId, typeName}): Observable<ValidationStatus> =>
documentStore.local.validationFor(publishedId, typeName)
)
)
),
INITIAL_VALIDATION_STATUS
INITIAL
)
}

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc