Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@contentful/live-preview

Package Overview
Dependencies
Maintainers
165
Versions
218
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@contentful/live-preview - npm Package Compare versions

Comparing version 1.15.0 to 1.16.0

dist/index-0c0421f8.js

7

dist/index.d.ts
import { InspectorMode } from './inspectorMode';
import { LiveUpdates } from './liveUpdates';
import { Argument, LivePreviewProps, SubscribeCallback, TagAttributes } from './types';
interface ContentfulLivePreviewInitConfig {
import { Argument, InspectorModeTags, LivePreviewProps, SubscribeCallback } from './types';
export interface ContentfulLivePreviewInitConfig {
debugMode?: boolean;

@@ -17,6 +17,5 @@ enableInspectorMode?: boolean;

static subscribe(data: Argument, locale: string, callback: SubscribeCallback): VoidFunction;
static getProps({ fieldId, entryId, locale, }: LivePreviewProps): Record<TagAttributes, string | null | undefined> | null;
static getProps({ fieldId, entryId, locale }: LivePreviewProps): InspectorModeTags;
static toggleInspectorMode(): boolean;
static toggleLiveUpdatesMode(): boolean;
}
export {};

@@ -1,2 +0,2 @@

import { C as r } from "./index-b47152ed.js";
import { C as r } from "./index-0c0421f8.js";
export {

@@ -3,0 +3,0 @@ r as ContentfulLivePreview

@@ -1,3 +0,10 @@

import { Argument } from './types';
import { type PropsWithChildren, type ReactElement } from 'react';
import { ContentfulLivePreviewInitConfig } from '.';
import { Argument, InspectorModeTags, LivePreviewProps } from './types';
/**
* ContentfulLivePreviewProvider to initialize the the SDK and provide the config for the live updates
* Essential to wrap it around the whole react tree, where you want to use live updates and inspector mode.
*/
export declare function ContentfulLivePreviewProvider({ children, debugMode, enableInspectorMode, enableLiveUpdates, }: PropsWithChildren<ContentfulLivePreviewInitConfig>): ReactElement;
/**
* Receives updates directly from the Contentful Editor inside the LivePreview

@@ -9,1 +16,9 @@ * Attention: For this to work, the provided data should contain a `sys.id` information

export declare function useContentfulLiveUpdates<T extends Argument | null | undefined>(data: T, locale: string, skip?: boolean): T;
type GetInspectorModeProps<T> = (props: {
[K in Exclude<keyof LivePreviewProps, keyof T>]: LivePreviewProps[K];
}) => InspectorModeTags;
/**
* Generates the function to build the required properties for the inspector mode (field tagging)
*/
export declare function useContentfulInspectorMode<T = undefined | Pick<LivePreviewProps, 'entryId'> | Pick<LivePreviewProps, 'entryId' | 'locale'>>(sharedProps?: T): GetInspectorModeProps<T>;
export {};

@@ -1,89 +0,736 @@

import * as f from "react";
import { useState as v, useRef as c } from "react";
import { d as o, C as g } from "./index-b47152ed.js";
var l = Object.prototype.hasOwnProperty;
function p(e, t, n) {
for (n of e.keys())
if (u(n, t))
return n;
import * as V from "react";
import ke, { createContext as pr, useState as gr, useRef as Oe, useContext as De, useMemo as hr, useCallback as yr } from "react";
import { C as Q, d as mr } from "./index-0c0421f8.js";
var Z = { exports: {} }, F = {};
/**
* @license React
* react-jsx-runtime.production.min.js
*
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
var Pe;
function Er() {
if (Pe)
return F;
Pe = 1;
var n = ke, a = Symbol.for("react.element"), s = Symbol.for("react.fragment"), o = Object.prototype.hasOwnProperty, v = n.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ReactCurrentOwner, w = { key: !0, ref: !0, __self: !0, __source: !0 };
function O(R, g, T) {
var h, _ = {}, P = null, W = null;
T !== void 0 && (P = "" + T), g.key !== void 0 && (P = "" + g.key), g.ref !== void 0 && (W = g.ref);
for (h in g)
o.call(g, h) && !w.hasOwnProperty(h) && (_[h] = g[h]);
if (R && R.defaultProps)
for (h in g = R.defaultProps, g)
_[h] === void 0 && (_[h] = g[h]);
return { $$typeof: a, type: R, key: P, ref: W, props: _, _owner: v.current };
}
return F.Fragment = s, F.jsx = O, F.jsxs = O, F;
}
function u(e, t) {
var n, r, i;
if (e === t)
var I = {};
/**
* @license React
* react-jsx-runtime.development.js
*
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
var Se;
function Rr() {
return Se || (Se = 1, process.env.NODE_ENV !== "production" && function() {
var n = ke, a = Symbol.for("react.element"), s = Symbol.for("react.portal"), o = Symbol.for("react.fragment"), v = Symbol.for("react.strict_mode"), w = Symbol.for("react.profiler"), O = Symbol.for("react.provider"), R = Symbol.for("react.context"), g = Symbol.for("react.forward_ref"), T = Symbol.for("react.suspense"), h = Symbol.for("react.suspense_list"), _ = Symbol.for("react.memo"), P = Symbol.for("react.lazy"), W = Symbol.for("react.offscreen"), re = Symbol.iterator, Ae = "@@iterator";
function Fe(e) {
if (e === null || typeof e != "object")
return null;
var r = re && e[re] || e[Ae];
return typeof r == "function" ? r : null;
}
var j = n.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED;
function y(e) {
{
for (var r = arguments.length, t = new Array(r > 1 ? r - 1 : 0), i = 1; i < r; i++)
t[i - 1] = arguments[i];
Ie("error", e, t);
}
}
function Ie(e, r, t) {
{
var i = j.ReactDebugCurrentFrame, l = i.getStackAddendum();
l !== "" && (r += "%s", t = t.concat([l]));
var c = t.map(function(f) {
return String(f);
});
c.unshift("Warning: " + r), Function.prototype.apply.call(console[e], console, c);
}
}
var Le = !1, We = !1, Ye = !1, $e = !1, Me = !1, te;
te = Symbol.for("react.module.reference");
function Ne(e) {
return !!(typeof e == "string" || typeof e == "function" || e === o || e === w || Me || e === v || e === T || e === h || $e || e === W || Le || We || Ye || typeof e == "object" && e !== null && (e.$$typeof === P || e.$$typeof === _ || e.$$typeof === O || e.$$typeof === R || e.$$typeof === g || // This needs to include all possible module reference object
// types supported by any Flight configuration anywhere since
// we don't know which Flight build this will end up being used
// with.
e.$$typeof === te || e.getModuleId !== void 0));
}
function Ue(e, r, t) {
var i = e.displayName;
if (i)
return i;
var l = r.displayName || r.name || "";
return l !== "" ? t + "(" + l + ")" : t;
}
function ne(e) {
return e.displayName || "Context";
}
function b(e) {
if (e == null)
return null;
if (typeof e.tag == "number" && y("Received an unexpected object in getComponentNameFromType(). This is likely a bug in React. Please file an issue."), typeof e == "function")
return e.displayName || e.name || null;
if (typeof e == "string")
return e;
switch (e) {
case o:
return "Fragment";
case s:
return "Portal";
case w:
return "Profiler";
case v:
return "StrictMode";
case T:
return "Suspense";
case h:
return "SuspenseList";
}
if (typeof e == "object")
switch (e.$$typeof) {
case R:
var r = e;
return ne(r) + ".Consumer";
case O:
var t = e;
return ne(t._context) + ".Provider";
case g:
return Ue(e, e.render, "ForwardRef");
case _:
var i = e.displayName || null;
return i !== null ? i : b(e.type) || "Memo";
case P: {
var l = e, c = l._payload, f = l._init;
try {
return b(f(c));
} catch {
return null;
}
}
}
return null;
}
var S = Object.assign, D = 0, ae, ie, ue, oe, se, fe, le;
function ce() {
}
ce.__reactDisabledLog = !0;
function Ve() {
{
if (D === 0) {
ae = console.log, ie = console.info, ue = console.warn, oe = console.error, se = console.group, fe = console.groupCollapsed, le = console.groupEnd;
var e = {
configurable: !0,
enumerable: !0,
value: ce,
writable: !0
};
Object.defineProperties(console, {
info: e,
log: e,
warn: e,
error: e,
group: e,
groupCollapsed: e,
groupEnd: e
});
}
D++;
}
}
function Be() {
{
if (D--, D === 0) {
var e = {
configurable: !0,
enumerable: !0,
writable: !0
};
Object.defineProperties(console, {
log: S({}, e, {
value: ae
}),
info: S({}, e, {
value: ie
}),
warn: S({}, e, {
value: ue
}),
error: S({}, e, {
value: oe
}),
group: S({}, e, {
value: se
}),
groupCollapsed: S({}, e, {
value: fe
}),
groupEnd: S({}, e, {
value: le
})
});
}
D < 0 && y("disabledDepth fell below zero. This is a bug in React. Please file an issue.");
}
}
var B = j.ReactCurrentDispatcher, z;
function Y(e, r, t) {
{
if (z === void 0)
try {
throw Error();
} catch (l) {
var i = l.stack.trim().match(/\n( *(at )?)/);
z = i && i[1] || "";
}
return `
` + z + e;
}
}
var q = !1, $;
{
var ze = typeof WeakMap == "function" ? WeakMap : Map;
$ = new ze();
}
function ve(e, r) {
if (!e || q)
return "";
{
var t = $.get(e);
if (t !== void 0)
return t;
}
var i;
q = !0;
var l = Error.prepareStackTrace;
Error.prepareStackTrace = void 0;
var c;
c = B.current, B.current = null, Ve();
try {
if (r) {
var f = function() {
throw Error();
};
if (Object.defineProperty(f.prototype, "props", {
set: function() {
throw Error();
}
}), typeof Reflect == "object" && Reflect.construct) {
try {
Reflect.construct(f, []);
} catch (C) {
i = C;
}
Reflect.construct(e, [], f);
} else {
try {
f.call();
} catch (C) {
i = C;
}
e.call(f.prototype);
}
} else {
try {
throw Error();
} catch (C) {
i = C;
}
e();
}
} catch (C) {
if (C && i && typeof C.stack == "string") {
for (var u = C.stack.split(`
`), m = i.stack.split(`
`), d = u.length - 1, p = m.length - 1; d >= 1 && p >= 0 && u[d] !== m[p]; )
p--;
for (; d >= 1 && p >= 0; d--, p--)
if (u[d] !== m[p]) {
if (d !== 1 || p !== 1)
do
if (d--, p--, p < 0 || u[d] !== m[p]) {
var E = `
` + u[d].replace(" at new ", " at ");
return e.displayName && E.includes("<anonymous>") && (E = E.replace("<anonymous>", e.displayName)), typeof e == "function" && $.set(e, E), E;
}
while (d >= 1 && p >= 0);
break;
}
}
} finally {
q = !1, B.current = c, Be(), Error.prepareStackTrace = l;
}
var k = e ? e.displayName || e.name : "", we = k ? Y(k) : "";
return typeof e == "function" && $.set(e, we), we;
}
function qe(e, r, t) {
return ve(e, !1);
}
function Je(e) {
var r = e.prototype;
return !!(r && r.isReactComponent);
}
function M(e, r, t) {
if (e == null)
return "";
if (typeof e == "function")
return ve(e, Je(e));
if (typeof e == "string")
return Y(e);
switch (e) {
case T:
return Y("Suspense");
case h:
return Y("SuspenseList");
}
if (typeof e == "object")
switch (e.$$typeof) {
case g:
return qe(e.render);
case _:
return M(e.type, r, t);
case P: {
var i = e, l = i._payload, c = i._init;
try {
return M(c(l), r, t);
} catch {
}
}
}
return "";
}
var N = Object.prototype.hasOwnProperty, de = {}, pe = j.ReactDebugCurrentFrame;
function U(e) {
if (e) {
var r = e._owner, t = M(e.type, e._source, r ? r.type : null);
pe.setExtraStackFrame(t);
} else
pe.setExtraStackFrame(null);
}
function Ge(e, r, t, i, l) {
{
var c = Function.call.bind(N);
for (var f in e)
if (c(e, f)) {
var u = void 0;
try {
if (typeof e[f] != "function") {
var m = Error((i || "React class") + ": " + t + " type `" + f + "` is invalid; it must be a function, usually from the `prop-types` package, but received `" + typeof e[f] + "`.This often happens because of typos such as `PropTypes.function` instead of `PropTypes.func`.");
throw m.name = "Invariant Violation", m;
}
u = e[f](r, f, i, t, null, "SECRET_DO_NOT_PASS_THIS_OR_YOU_WILL_BE_FIRED");
} catch (d) {
u = d;
}
u && !(u instanceof Error) && (U(l), y("%s: type specification of %s `%s` is invalid; the type checker function must return `null` or an `Error` but returned a %s. You may have forgotten to pass an argument to the type checker creator (arrayOf, instanceOf, objectOf, oneOf, oneOfType, and shape all require an argument).", i || "React class", t, f, typeof u), U(null)), u instanceof Error && !(u.message in de) && (de[u.message] = !0, U(l), y("Failed %s type: %s", t, u.message), U(null));
}
}
}
var Ke = Array.isArray;
function J(e) {
return Ke(e);
}
function He(e) {
{
var r = typeof Symbol == "function" && Symbol.toStringTag, t = r && e[Symbol.toStringTag] || e.constructor.name || "Object";
return t;
}
}
function Xe(e) {
try {
return ge(e), !1;
} catch {
return !0;
}
}
function ge(e) {
return "" + e;
}
function he(e) {
if (Xe(e))
return y("The provided key is an unsupported type %s. This value must be coerced to a string before before using it here.", He(e)), ge(e);
}
var A = j.ReactCurrentOwner, Ze = {
key: !0,
ref: !0,
__self: !0,
__source: !0
}, ye, me, G;
G = {};
function Qe(e) {
if (N.call(e, "ref")) {
var r = Object.getOwnPropertyDescriptor(e, "ref").get;
if (r && r.isReactWarning)
return !1;
}
return e.ref !== void 0;
}
function er(e) {
if (N.call(e, "key")) {
var r = Object.getOwnPropertyDescriptor(e, "key").get;
if (r && r.isReactWarning)
return !1;
}
return e.key !== void 0;
}
function rr(e, r) {
if (typeof e.ref == "string" && A.current && r && A.current.stateNode !== r) {
var t = b(A.current.type);
G[t] || (y('Component "%s" contains the string ref "%s". Support for string refs will be removed in a future major release. This case cannot be automatically converted to an arrow function. We ask you to manually fix this case by using useRef() or createRef() instead. Learn more about using refs safely here: https://reactjs.org/link/strict-mode-string-ref', b(A.current.type), e.ref), G[t] = !0);
}
}
function tr(e, r) {
{
var t = function() {
ye || (ye = !0, y("%s: `key` is not a prop. Trying to access it will result in `undefined` being returned. If you need to access the same value within the child component, you should pass it as a different prop. (https://reactjs.org/link/special-props)", r));
};
t.isReactWarning = !0, Object.defineProperty(e, "key", {
get: t,
configurable: !0
});
}
}
function nr(e, r) {
{
var t = function() {
me || (me = !0, y("%s: `ref` is not a prop. Trying to access it will result in `undefined` being returned. If you need to access the same value within the child component, you should pass it as a different prop. (https://reactjs.org/link/special-props)", r));
};
t.isReactWarning = !0, Object.defineProperty(e, "ref", {
get: t,
configurable: !0
});
}
}
var ar = function(e, r, t, i, l, c, f) {
var u = {
// This tag allows us to uniquely identify this as a React Element
$$typeof: a,
// Built-in properties that belong on the element
type: e,
key: r,
ref: t,
props: f,
// Record the component responsible for creating this element.
_owner: c
};
return u._store = {}, Object.defineProperty(u._store, "validated", {
configurable: !1,
enumerable: !1,
writable: !0,
value: !1
}), Object.defineProperty(u, "_self", {
configurable: !1,
enumerable: !1,
writable: !1,
value: i
}), Object.defineProperty(u, "_source", {
configurable: !1,
enumerable: !1,
writable: !1,
value: l
}), Object.freeze && (Object.freeze(u.props), Object.freeze(u)), u;
};
function ir(e, r, t, i, l) {
{
var c, f = {}, u = null, m = null;
t !== void 0 && (he(t), u = "" + t), er(r) && (he(r.key), u = "" + r.key), Qe(r) && (m = r.ref, rr(r, l));
for (c in r)
N.call(r, c) && !Ze.hasOwnProperty(c) && (f[c] = r[c]);
if (e && e.defaultProps) {
var d = e.defaultProps;
for (c in d)
f[c] === void 0 && (f[c] = d[c]);
}
if (u || m) {
var p = typeof e == "function" ? e.displayName || e.name || "Unknown" : e;
u && tr(f, p), m && nr(f, p);
}
return ar(e, u, m, l, i, A.current, f);
}
}
var K = j.ReactCurrentOwner, Ee = j.ReactDebugCurrentFrame;
function x(e) {
if (e) {
var r = e._owner, t = M(e.type, e._source, r ? r.type : null);
Ee.setExtraStackFrame(t);
} else
Ee.setExtraStackFrame(null);
}
var H;
H = !1;
function X(e) {
return typeof e == "object" && e !== null && e.$$typeof === a;
}
function Re() {
{
if (K.current) {
var e = b(K.current.type);
if (e)
return `
Check the render method of \`` + e + "`.";
}
return "";
}
}
function ur(e) {
{
if (e !== void 0) {
var r = e.fileName.replace(/^.*[\\\/]/, ""), t = e.lineNumber;
return `
Check your code at ` + r + ":" + t + ".";
}
return "";
}
}
var _e = {};
function or(e) {
{
var r = Re();
if (!r) {
var t = typeof e == "string" ? e : e.displayName || e.name;
t && (r = `
Check the top-level render call using <` + t + ">.");
}
return r;
}
}
function be(e, r) {
{
if (!e._store || e._store.validated || e.key != null)
return;
e._store.validated = !0;
var t = or(r);
if (_e[t])
return;
_e[t] = !0;
var i = "";
e && e._owner && e._owner !== K.current && (i = " It was passed a child from " + b(e._owner.type) + "."), x(e), y('Each child in a list should have a unique "key" prop.%s%s See https://reactjs.org/link/warning-keys for more information.', t, i), x(null);
}
}
function Ce(e, r) {
{
if (typeof e != "object")
return;
if (J(e))
for (var t = 0; t < e.length; t++) {
var i = e[t];
X(i) && be(i, r);
}
else if (X(e))
e._store && (e._store.validated = !0);
else if (e) {
var l = Fe(e);
if (typeof l == "function" && l !== e.entries)
for (var c = l.call(e), f; !(f = c.next()).done; )
X(f.value) && be(f.value, r);
}
}
}
function sr(e) {
{
var r = e.type;
if (r == null || typeof r == "string")
return;
var t;
if (typeof r == "function")
t = r.propTypes;
else if (typeof r == "object" && (r.$$typeof === g || // Note: Memo only checks outer props here.
// Inner props are checked in the reconciler.
r.$$typeof === _))
t = r.propTypes;
else
return;
if (t) {
var i = b(r);
Ge(t, e.props, "prop", i, e);
} else if (r.PropTypes !== void 0 && !H) {
H = !0;
var l = b(r);
y("Component %s declared `PropTypes` instead of `propTypes`. Did you misspell the property assignment?", l || "Unknown");
}
typeof r.getDefaultProps == "function" && !r.getDefaultProps.isReactClassApproved && y("getDefaultProps is only used on classic React.createClass definitions. Use a static property named `defaultProps` instead.");
}
}
function fr(e) {
{
for (var r = Object.keys(e.props), t = 0; t < r.length; t++) {
var i = r[t];
if (i !== "children" && i !== "key") {
x(e), y("Invalid prop `%s` supplied to `React.Fragment`. React.Fragment can only have `key` and `children` props.", i), x(null);
break;
}
}
e.ref !== null && (x(e), y("Invalid attribute `ref` supplied to `React.Fragment`."), x(null));
}
}
function Te(e, r, t, i, l, c) {
{
var f = Ne(e);
if (!f) {
var u = "";
(e === void 0 || typeof e == "object" && e !== null && Object.keys(e).length === 0) && (u += " You likely forgot to export your component from the file it's defined in, or you might have mixed up default and named imports.");
var m = ur(l);
m ? u += m : u += Re();
var d;
e === null ? d = "null" : J(e) ? d = "array" : e !== void 0 && e.$$typeof === a ? (d = "<" + (b(e.type) || "Unknown") + " />", u = " Did you accidentally export a JSX literal instead of a component?") : d = typeof e, y("React.jsx: type is invalid -- expected a string (for built-in components) or a class/function (for composite components) but got: %s.%s", d, u);
}
var p = ir(e, r, t, l, c);
if (p == null)
return p;
if (f) {
var E = r.children;
if (E !== void 0)
if (i)
if (J(E)) {
for (var k = 0; k < E.length; k++)
Ce(E[k], e);
Object.freeze && Object.freeze(E);
} else
y("React.jsx: Static children should always be an array. You are likely explicitly calling React.jsxs or React.jsxDEV. Use the Babel transform instead.");
else
Ce(E, e);
}
return e === o ? fr(p) : sr(p), p;
}
}
function lr(e, r, t) {
return Te(e, r, t, !0);
}
function cr(e, r, t) {
return Te(e, r, t, !1);
}
var vr = cr, dr = lr;
I.Fragment = o, I.jsx = vr, I.jsxs = dr;
}()), I;
}
process.env.NODE_ENV === "production" ? Z.exports = Er() : Z.exports = Rr();
var _r = Z.exports, je = Object.prototype.hasOwnProperty;
function xe(n, a, s) {
for (s of n.keys())
if (L(s, a))
return s;
}
function L(n, a) {
var s, o, v;
if (n === a)
return !0;
if (e && t && (n = e.constructor) === t.constructor) {
if (n === Date)
return e.getTime() === t.getTime();
if (n === RegExp)
return e.toString() === t.toString();
if (n === Array) {
if ((r = e.length) === t.length)
for (; r-- && u(e[r], t[r]); )
if (n && a && (s = n.constructor) === a.constructor) {
if (s === Date)
return n.getTime() === a.getTime();
if (s === RegExp)
return n.toString() === a.toString();
if (s === Array) {
if ((o = n.length) === a.length)
for (; o-- && L(n[o], a[o]); )
;
return r === -1;
return o === -1;
}
if (n === Set) {
if (e.size !== t.size)
if (s === Set) {
if (n.size !== a.size)
return !1;
for (r of e)
if (i = r, i && typeof i == "object" && (i = p(t, i), !i) || !t.has(i))
for (o of n)
if (v = o, v && typeof v == "object" && (v = xe(a, v), !v) || !a.has(v))
return !1;
return !0;
}
if (n === Map) {
if (e.size !== t.size)
if (s === Map) {
if (n.size !== a.size)
return !1;
for (r of e)
if (i = r[0], i && typeof i == "object" && (i = p(t, i), !i) || !u(r[1], t.get(i)))
for (o of n)
if (v = o[0], v && typeof v == "object" && (v = xe(a, v), !v) || !L(o[1], a.get(v)))
return !1;
return !0;
}
if (n === ArrayBuffer)
e = new Uint8Array(e), t = new Uint8Array(t);
else if (n === DataView) {
if ((r = e.byteLength) === t.byteLength)
for (; r-- && e.getInt8(r) === t.getInt8(r); )
if (s === ArrayBuffer)
n = new Uint8Array(n), a = new Uint8Array(a);
else if (s === DataView) {
if ((o = n.byteLength) === a.byteLength)
for (; o-- && n.getInt8(o) === a.getInt8(o); )
;
return r === -1;
return o === -1;
}
if (ArrayBuffer.isView(e)) {
if ((r = e.byteLength) === t.byteLength)
for (; r-- && e[r] === t[r]; )
if (ArrayBuffer.isView(n)) {
if ((o = n.byteLength) === a.byteLength)
for (; o-- && n[o] === a[o]; )
;
return r === -1;
return o === -1;
}
if (!n || typeof e == "object") {
r = 0;
for (n in e)
if (l.call(e, n) && ++r && !l.call(t, n) || !(n in t) || !u(e[n], t[n]))
if (!s || typeof n == "object") {
o = 0;
for (s in n)
if (je.call(n, s) && ++o && !je.call(a, s) || !(s in a) || !L(n[s], a[s]))
return !1;
return Object.keys(t).length === r;
return Object.keys(a).length === o;
}
}
return e !== e && t !== t;
return n !== n && a !== a;
}
function w(e) {
var t = f.useRef(e), n = f.useRef(0);
return u(e, t.current) || (t.current = e, n.current += 1), f.useMemo(function() {
return t.current;
}, [n.current]);
function br(n) {
var a = V.useRef(n), s = V.useRef(0);
return L(n, a.current) || (a.current = n, s.current += 1), V.useMemo(function() {
return a.current;
}, [s.current]);
}
function j(e, t) {
return f.useEffect(e, w(t));
function Cr(n, a) {
return V.useEffect(n, br(a));
}
function A(e, t) {
return !g.liveUpdatesEnabled || e ? !1 : !!(Array.isArray(t) && t.length || t && typeof t == "object" && Object.keys(t).length);
const ee = pr(null);
function Or({
children: n,
debugMode: a = !1,
enableInspectorMode: s = !0,
enableLiveUpdates: o = !0
}) {
return Q.init({ debugMode: a, enableInspectorMode: s, enableLiveUpdates: o }), /* @__PURE__ */ _r.jsx(
ee.Provider,
{
value: { debugMode: a, enableInspectorMode: s, enableLiveUpdates: o },
children: n
}
);
}
function R(e, t, n = !1) {
const [r, i] = v({ data: e, version: 1 }), s = c(e), y = c(o(i));
return j(() => {
if (s.current !== e && (i({ data: e, version: 1 }), s.current = e), !!A(n, e))
return g.subscribe(e, t, (h) => {
y.current((m) => ({ data: h, version: m.version++ }));
function Pr(n, a, s = !1) {
const [o, v] = gr({ data: n, version: 1 }), w = Oe(n), O = Oe(mr(v)), R = De(ee), g = hr(() => R && !R.enableLiveUpdates || s ? !1 : !!(Array.isArray(n) && n.length || n && typeof n == "object" && Object.keys(n).length), [R, s, n]);
return Cr(() => {
if (w.current !== n && (v({ data: n, version: 1 }), w.current = n), !!g)
return Q.subscribe(n, a, (T) => {
O.current((h) => ({ data: T, version: h.version++ }));
});
}, [e]), r.data;
}, [n, g]), o.data;
}
function Sr(n) {
const a = De(ee);
return yr(
(s) => a != null && a.enableInspectorMode ? Q.getProps({ ...n, ...s }) : null,
[a == null ? void 0 : a.enableInspectorMode, n]
);
}
export {
R as useContentfulLiveUpdates
Or as ContentfulLivePreviewProvider,
Sr as useContentfulInspectorMode,
Pr as useContentfulLiveUpdates
};
//# sourceMappingURL=react.js.map

@@ -5,5 +5,5 @@ import type { AssetProps, EntryProps, ContentTypeProps } from 'contentful-management';

export type LivePreviewProps = {
fieldId: string | null | undefined;
entryId: string | null | undefined;
locale: string | null | undefined;
fieldId: string;
entryId: string;
locale: string;
};

@@ -15,2 +15,3 @@ export declare const enum TagAttributes {

}
export type InspectorModeTags = Record<TagAttributes, string> | null;
export interface SysProps {

@@ -17,0 +18,0 @@ id: string;

{
"name": "@contentful/live-preview",
"version": "1.15.0",
"version": "1.16.0",
"author": "Contentful GmbH",

@@ -5,0 +5,0 @@ "license": "MIT",

@@ -104,11 +104,28 @@ # @contentful/live-preview

2. Initialize the SDK and add the stylesheet for field tagging inside `_app.tsx` or `_app.js`.
2. Initialize the SDK with the `ContentfulLivePreviewProvider` and add the stylesheet for field tagging inside `_app.tsx` or `_app.js`.
The `ContentfulLivePreviewProvider` accepts the same arguments as the [init function](#init-configuration).
```tsx
import '@contentful/live-preview/style.css';
import { ContentfulLivePreview } from '@contentful/live-preview';
import { ContentfulLivePreview } from '@contentful/live-preview/react';
ContentfulLivePreview.init();
const CustomApp = ({ Component, pageProps }) => (
<ContentfulLivePreviewProvider>
<Component {...pageProps}>
</ContentfulLivePreviewProvider>
)
```
This provides the posibility to only enable live updates and the inspector mode inside the preview mode:
```tsx
import '@contentful/live-preview/style.css';
import { ContentfulLivePreview } from '@contentful/live-preview/react';
const CustomApp = ({ Component, pageProps }) => (
<ContentfulLivePreviewProvider enableInspectorMode={pageProps.previewActive} enableLiveUpdates={pageProps.previewActive}>
<Component {...pageProps}>
</ContentfulLivePreviewProvider>
)
```
3. Add field tagging and live updates to your component

@@ -118,2 +135,3 @@

export default function BlogPost: ({ blogPost }) {
const inspectorProps = useContentfulInspectorMode()
// Live updates for this component

@@ -131,3 +149,3 @@ const data = useContentfulLiveUpdates(

as="p"
{...ContentfulLivePreview.getProps({
{...inspectorProps({
entryId: data.sys.id,

@@ -146,2 +164,18 @@ fieldId: 'text',

**Tip:** If you want to tag multiple fields of an entry, you can also provide initial arguments to the hook:
```tsx
export default function BlogPost: ({ blogPost }) {
const inspectorProps = useContentfulInspectorMode({ entryId: data.sys.id, locale })
return (
<Section>
<Heading as="h1" {...inspectorProps({ fieldId: 'heading' })}>{data.heading}</Heading>
<Text as="p" {...inspectorProps({ fieldId: 'text' })}>
{data.text}
</Text>
</Section>
)
```
4. Enable preview mode

@@ -177,5 +211,9 @@

import '@contentful/live-preview/style.css';
import { ContentfulLivePreview } from '@contentful/live-preview';
ContentfulLivePreview.init();
import React from "react";
import { ContentfulLivePreview } from '@contentful/live-preview/react';
export const wrapRootElement = ({ element }) => (
<ContentfulLivePreviewProvider>{element}</ContentfulLivePreviewProvider>
)
```

@@ -219,2 +257,3 @@

export default function Hero({ contentful_id, ...props }) {
const inspectorProps = useContentfulInspectorMode()
// Live updates for this component

@@ -235,3 +274,3 @@ const data = useContentfulLiveUpdates(

as="p"
{...ContentfulLivePreview.getProps({
{...inspectorProps({
entryId: contentful_id,

@@ -238,0 +277,0 @@ fieldId: 'text',

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
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc