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

@contentful/live-preview

Package Overview
Dependencies
Maintainers
5
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 4.3.2 to 4.4.0

dist/constants.cjs

301

dist/index.js

@@ -1,15 +0,286 @@

import { C as o, I as t, L as n, c as E, e as a, V as i, u as I, a as r, f as d, o as p, b as R } from "./index-BRM1evsg.js";
export {
o as ContentfulLivePreview,
t as InspectorModeEventMethods,
n as LIVE_PREVIEW_EDITOR_SOURCE,
E as LIVE_PREVIEW_SDK_SOURCE,
a as LivePreviewPostMessageMethods,
i as VERSION,
I as encodeCPAResponse,
r as encodeGraphQLResponse,
d as openAssetInEditorUtility,
p as openEntryInEditorUtility,
R as splitEncoding
};
//# sourceMappingURL=index.js.map
function _define_property(obj, key, value) {
if (key in obj) {
Object.defineProperty(obj, key, {
value: value,
enumerable: true,
configurable: true,
writable: true
});
} else {
obj[key] = value;
}
return obj;
}
function _object_spread(target) {
for(var i = 1; i < arguments.length; i++){
var source = arguments[i] != null ? arguments[i] : {};
var ownKeys = Object.keys(source);
if (typeof Object.getOwnPropertySymbols === "function") {
ownKeys = ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function(sym) {
return Object.getOwnPropertyDescriptor(source, sym).enumerable;
}));
}
ownKeys.forEach(function(key) {
_define_property(target, key, source[key]);
});
}
return target;
}
function ownKeys(object, enumerableOnly) {
var keys = Object.keys(object);
if (Object.getOwnPropertySymbols) {
var symbols = Object.getOwnPropertySymbols(object);
if (enumerableOnly) {
symbols = symbols.filter(function(sym) {
return Object.getOwnPropertyDescriptor(object, sym).enumerable;
});
}
keys.push.apply(keys, symbols);
}
return keys;
}
function _object_spread_props(target, source) {
source = source != null ? source : {};
if (Object.getOwnPropertyDescriptors) {
Object.defineProperties(target, Object.getOwnPropertyDescriptors(source));
} else {
ownKeys(Object(source)).forEach(function(key) {
Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key));
});
}
return target;
}
import { encodeGraphQLResponse, encodeCPAResponse, splitEncoding } from '@contentful/content-source-maps';
import { version } from '../package.json';
import { debug, isInsideIframe, pollUrlChanges, sendMessageToEditor, setDebugMode } from './helpers/index.js';
import { isValidMessage } from './helpers/validateMessage.js';
import { InspectorMode } from './inspectorMode/index.js';
import { InspectorModeDataAttributes } from './inspectorMode/types.js';
import { getAllTaggedElements, getAllTaggedEntries } from './inspectorMode/utils.js';
import { LiveUpdates } from './liveUpdates.js';
import { LivePreviewPostMessageMethods, openAssetInEditorUtility, openEntryInEditorUtility } from './messages.js';
import { SaveEvent } from './saveEvent.js';
export const VERSION = version;
const DEFAULT_ALLOWED_ORIGINS = [
'https://app.contentful.com',
'https://app.eu.contentful.com',
'http://localhost:3001'
];
export class ContentfulLivePreview {
static init(config) {
if (typeof config !== 'object' || !(config === null || config === void 0 ? void 0 : config.locale)) {
throw new Error("Init function have to be called with a locale configuration (for example: `ContentfulLivePreview.init({ locale: 'en-US'})`)");
}
const { debugMode, enableInspectorMode, enableLiveUpdates, locale, environment, space, targetOrigin } = config;
if (typeof window !== 'undefined') {
if (!isInsideIframe()) {
this.liveUpdatesEnabled = false;
return Promise.resolve(null);
}
if (debugMode) {
setDebugMode(debugMode);
}
if (typeof enableInspectorMode === 'boolean') {
this.inspectorModeEnabled = enableInspectorMode;
}
if (typeof enableLiveUpdates === 'boolean') {
this.liveUpdatesEnabled = enableLiveUpdates;
}
this.locale = locale;
this.space = space;
this.environment = environment;
this.initTargetOrigin(targetOrigin);
if (this.initialized) {
debug.log('You have already initialized the Live Preview SDK.');
return Promise.resolve(ContentfulLivePreview.inspectorMode);
}
if (this.inspectorModeEnabled) {
var _config_experimental;
this.inspectorMode = new InspectorMode({
locale,
space,
environment,
targetOrigin: this.targetOrigin,
ignoreManuallyTaggedElements: (_config_experimental = config.experimental) === null || _config_experimental === void 0 ? void 0 : _config_experimental.ignoreManuallyTaggedElements
});
}
if (this.liveUpdatesEnabled) {
this.liveUpdates = new LiveUpdates({
locale,
targetOrigin: this.targetOrigin
});
this.saveEvent = new SaveEvent({
locale,
options: {
locale: this.locale,
space: this.space,
environment: this.environment,
targetOrigin: this.targetOrigin
}
});
}
window.addEventListener('message', (event)=>{
if (!isValidMessage(event)) {
return;
}
debug.log('Received message', event.data);
if (event.data.method === LivePreviewPostMessageMethods.DEBUG_MODE_ENABLED) {
setDebugMode(true);
return;
}
if (this.inspectorModeEnabled) {
var _this_inspectorMode;
(_this_inspectorMode = this.inspectorMode) === null || _this_inspectorMode === void 0 ? void 0 : _this_inspectorMode.receiveMessage(event.data);
}
if (this.liveUpdatesEnabled) {
var _this_liveUpdates, _this_saveEvent;
(_this_liveUpdates = this.liveUpdates) === null || _this_liveUpdates === void 0 ? void 0 : _this_liveUpdates.receiveMessage(event.data);
(_this_saveEvent = this.saveEvent) === null || _this_saveEvent === void 0 ? void 0 : _this_saveEvent.receiveMessage(event.data);
}
});
pollUrlChanges(()=>{
sendMessageToEditor(LivePreviewPostMessageMethods.URL_CHANGED, {
action: LivePreviewPostMessageMethods.URL_CHANGED,
taggedElementCount: document.querySelectorAll(`[${InspectorModeDataAttributes.ENTRY_ID}]`).length
}, this.targetOrigin);
});
const { taggedElements, manuallyTaggedCount, automaticallyTaggedCount } = this.inspectorModeEnabled ? getAllTaggedElements({
options: {
locale: this.locale,
space: this.space,
environment: this.environment
}
}) : {
taggedElements: [],
manuallyTaggedCount: 0,
automaticallyTaggedCount: 0
};
const taggedElementCount = taggedElements.length;
sendMessageToEditor(LivePreviewPostMessageMethods.CONNECTED, {
action: LivePreviewPostMessageMethods.CONNECTED,
connected: true,
tags: taggedElementCount,
taggedElementCount,
locale: this.locale,
isInspectorEnabled: this.inspectorModeEnabled,
isLiveUpdatesEnabled: this.liveUpdatesEnabled,
manuallyTaggedElementCount: manuallyTaggedCount,
automaticallyTaggedElementCount: automaticallyTaggedCount
}, this.targetOrigin);
this.initialized = true;
return Promise.resolve(ContentfulLivePreview.inspectorMode);
}
}
static initTargetOrigin(targetOrigin) {
if (targetOrigin) {
this.targetOrigin = Array.isArray(targetOrigin) ? targetOrigin : [
targetOrigin
];
} else {
const ancestorOrigins = window.location.ancestorOrigins;
const currentDefaultOrigin = ancestorOrigins ? DEFAULT_ALLOWED_ORIGINS.find((origin)=>ancestorOrigins.contains(origin)) : DEFAULT_ALLOWED_ORIGINS.find((origin)=>document.referrer.includes(origin));
if (!currentDefaultOrigin) {
throw new Error(`The current origin is not supported. Please provide a targetOrigin in the live preview configuration.`);
}
this.targetOrigin = [
currentDefaultOrigin
];
}
}
static subscribe(configOrEvent, config) {
if (!this.liveUpdatesEnabled) {
return ()=>{};
}
const event = typeof configOrEvent === 'string' ? configOrEvent : 'edit';
const subscribeConfig = typeof configOrEvent === 'object' ? configOrEvent : config;
if (event === 'save') {
if (!this.saveEvent) {
throw new Error('Save event is not initialized, please call `ContentfulLivePreview.init()` first.');
}
return this.saveEvent.subscribe(subscribeConfig.callback);
}
if (!this.liveUpdates) {
throw new Error('Live updates are not initialized, please call `ContentfulLivePreview.init()` first.');
}
return this.liveUpdates.subscribe(subscribeConfig);
}
static getProps(props) {
const { fieldId, locale, environment, space } = props;
if (!this.inspectorModeEnabled) {
return null;
}
if (fieldId) {
const sharedProps = _object_spread_props(_object_spread({}, locale ? {
[InspectorModeDataAttributes.LOCALE]: locale
} : {}, environment ? {
[InspectorModeDataAttributes.ENVIRONMENT]: environment
} : {}, space ? {
[InspectorModeDataAttributes.SPACE]: space
} : {}), {
[InspectorModeDataAttributes.FIELD_ID]: fieldId
});
if (locale) {
sharedProps[InspectorModeDataAttributes.LOCALE] = locale;
}
if (props.assetId !== undefined) {
return _object_spread_props(_object_spread({}, sharedProps), {
[InspectorModeDataAttributes.ASSET_ID]: props.assetId
});
}
if (props.entryId !== undefined) {
return _object_spread_props(_object_spread({}, sharedProps), {
[InspectorModeDataAttributes.ENTRY_ID]: props.entryId
});
}
}
debug.warn('Missing property for inspector mode', _object_spread({}, props));
return null;
}
static toggleInspectorMode() {
this.inspectorModeEnabled = !this.inspectorModeEnabled;
return this.inspectorModeEnabled;
}
static toggleLiveUpdatesMode() {
this.liveUpdatesEnabled = !this.liveUpdatesEnabled;
return this.liveUpdatesEnabled;
}
static openEntryInEditor(props) {
const defaultProps = {
locale: this.locale,
environment: this.environment,
space: this.space
};
if (props.assetId !== undefined && props.fieldId) {
openAssetInEditorUtility(_object_spread({}, defaultProps, props), this.targetOrigin);
return;
}
if (props.entryId !== undefined && props.fieldId) {
openEntryInEditorUtility(_object_spread({}, defaultProps, props), this.targetOrigin);
return;
}
debug.error('Please provide field id and entry id to openEntryInEditor.');
}
static getEntryList() {
return getAllTaggedEntries({
options: {
locale: this.locale,
space: this.space,
environment: this.environment
}
});
}
}
_define_property(ContentfulLivePreview, "initialized", false);
_define_property(ContentfulLivePreview, "inspectorMode", null);
_define_property(ContentfulLivePreview, "liveUpdates", null);
_define_property(ContentfulLivePreview, "saveEvent", null);
_define_property(ContentfulLivePreview, "inspectorModeEnabled", true);
_define_property(ContentfulLivePreview, "liveUpdatesEnabled", true);
_define_property(ContentfulLivePreview, "locale", void 0);
_define_property(ContentfulLivePreview, "space", void 0);
_define_property(ContentfulLivePreview, "environment", void 0);
_define_property(ContentfulLivePreview, "sendMessage", void 0);
_define_property(ContentfulLivePreview, "targetOrigin", void 0);
export { LIVE_PREVIEW_EDITOR_SOURCE, LIVE_PREVIEW_SDK_SOURCE } from './constants.js';
export * from './messages.js';
export { encodeGraphQLResponse, encodeCPAResponse, splitEncoding };

840

dist/react.js

@@ -1,716 +0,156 @@

import xe, { createContext as yr, useRef as N, useMemo as ee, useEffect as br, useState as hr, useContext as ke, useCallback as gr } from "react";
import { i as Er, C as re, d as Rr } from "./index-BRM1evsg.js";
var Q = { exports: {} }, W = {};
/**
* @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 Oe;
function mr() {
if (Oe) return W;
Oe = 1;
var u = xe, s = Symbol.for("react.element"), h = Symbol.for("react.fragment"), E = Object.prototype.hasOwnProperty, m = u.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ReactCurrentOwner, _ = { key: !0, ref: !0, __self: !0, __source: !0 };
function C(p, l, T) {
var y, P = {}, S = null, Y = null;
T !== void 0 && (S = "" + T), l.key !== void 0 && (S = "" + l.key), l.ref !== void 0 && (Y = l.ref);
for (y in l) E.call(l, y) && !_.hasOwnProperty(y) && (P[y] = l[y]);
if (p && p.defaultProps) for (y in l = p.defaultProps, l) P[y] === void 0 && (P[y] = l[y]);
return { $$typeof: s, type: p, key: S, ref: Y, props: P, _owner: m.current };
}
return W.Fragment = h, W.jsx = C, W.jsxs = C, W;
'use client';
function _define_property(obj, key, value) {
if (key in obj) {
Object.defineProperty(obj, key, {
value: value,
enumerable: true,
configurable: true,
writable: true
});
} else {
obj[key] = value;
}
return obj;
}
var $ = {};
/**
* @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 je;
function _r() {
return je || (je = 1, process.env.NODE_ENV !== "production" && function() {
var u = xe, s = Symbol.for("react.element"), h = Symbol.for("react.portal"), E = Symbol.for("react.fragment"), m = Symbol.for("react.strict_mode"), _ = Symbol.for("react.profiler"), C = Symbol.for("react.provider"), p = Symbol.for("react.context"), l = Symbol.for("react.forward_ref"), T = Symbol.for("react.suspense"), y = Symbol.for("react.suspense_list"), P = Symbol.for("react.memo"), S = Symbol.for("react.lazy"), Y = Symbol.for("react.offscreen"), ne = Symbol.iterator, De = "@@iterator";
function Ae(e) {
if (e === null || typeof e != "object")
return null;
var r = ne && e[ne] || e[De];
return typeof r == "function" ? r : null;
}
var x = u.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED;
function d(e) {
{
for (var r = arguments.length, t = new Array(r > 1 ? r - 1 : 0), n = 1; n < r; n++)
t[n - 1] = arguments[n];
Fe("error", e, t);
}
}
function Fe(e, r, t) {
{
var n = x.ReactDebugCurrentFrame, i = n.getStackAddendum();
i !== "" && (r += "%s", t = t.concat([i]));
var f = t.map(function(o) {
return String(o);
function _object_spread(target) {
for(var i = 1; i < arguments.length; i++){
var source = arguments[i] != null ? arguments[i] : {};
var ownKeys = Object.keys(source);
if (typeof Object.getOwnPropertySymbols === "function") {
ownKeys = ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function(sym) {
return Object.getOwnPropertyDescriptor(source, sym).enumerable;
}));
}
ownKeys.forEach(function(key) {
_define_property(target, key, source[key]);
});
f.unshift("Warning: " + r), Function.prototype.apply.call(console[e], console, f);
}
}
var Ie = !1, We = !1, $e = !1, Ye = !1, Le = !1, ae;
ae = Symbol.for("react.module.reference");
function Me(e) {
return !!(typeof e == "string" || typeof e == "function" || e === E || e === _ || Le || e === m || e === T || e === y || Ye || e === Y || Ie || We || $e || typeof e == "object" && e !== null && (e.$$typeof === S || e.$$typeof === P || e.$$typeof === C || e.$$typeof === p || e.$$typeof === l || // 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 === ae || e.getModuleId !== void 0));
return target;
}
import { createContext, useCallback, useContext, useEffect, useMemo, useRef, useState } from 'react';
import isEqual from 'lodash.isequal';
import { debounce } from './helpers/index.js';
import { ContentfulLivePreview } from './index.js';
export function useDeepCompareMemoize(value) {
const ref = useRef(value);
const signalRef = useRef(0);
if (!isEqual(value, ref.current)) {
ref.current = value;
signalRef.current += 1;
}
function Ue(e, r, t) {
var n = e.displayName;
if (n)
return n;
var i = r.displayName || r.name || "";
return i !== "" ? t + "(" + i + ")" : t;
return useMemo(()=>ref.current, [
signalRef.current
]);
}
export function useDeepCompareEffectNoCheck(callback, dependencies) {
return useEffect(callback, useDeepCompareMemoize(dependencies));
}
const ContentfulLivePreviewContext = createContext(null);
export function ContentfulLivePreviewProvider({ children, locale, space, environment, debugMode = false, enableInspectorMode = true, enableLiveUpdates = true, targetOrigin, experimental }) {
if (!locale) {
throw new Error('ContentfulLivePreviewProvider have to be called with a locale property (for example: `<ContentfulLivePreviewProvider locale="en-US">{children}</ContentfulLivePreviewProvider>`');
}
function oe(e) {
return e.displayName || "Context";
}
function w(e) {
if (e == null)
return null;
if (typeof e.tag == "number" && d("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 E:
return "Fragment";
case h:
return "Portal";
case _:
return "Profiler";
case m:
return "StrictMode";
case T:
return "Suspense";
case y:
return "SuspenseList";
}
if (typeof e == "object")
switch (e.$$typeof) {
case p:
var r = e;
return oe(r) + ".Consumer";
case C:
var t = e;
return oe(t._context) + ".Provider";
case l:
return Ue(e, e.render, "ForwardRef");
case P:
var n = e.displayName || null;
return n !== null ? n : w(e.type) || "Memo";
case S: {
var i = e, f = i._payload, o = i._init;
try {
return w(o(f));
} catch {
return null;
}
}
ContentfulLivePreview.init({
locale,
space,
environment,
debugMode,
enableInspectorMode,
enableLiveUpdates,
targetOrigin,
experimental
});
const props = useMemo(()=>({
locale,
space,
environment,
debugMode,
enableInspectorMode,
enableLiveUpdates,
targetOrigin
}), [
locale,
space,
environment,
debugMode,
enableInspectorMode,
enableLiveUpdates,
targetOrigin
]);
return React.createElement(ContentfulLivePreviewContext.Provider, {
value: props
}, children);
}
export function useContentfulLiveUpdates(data, optionsOrLocale, skip = false) {
const [state, setState] = useState({
data,
version: 1
});
const previous = useRef(data);
const update = useRef(debounce(setState));
const config = useContext(ContentfulLivePreviewContext);
const options = typeof optionsOrLocale === 'object' ? optionsOrLocale : {
locale: optionsOrLocale,
skip
};
const shouldSubscribe = useMemo(()=>{
if (config && !config.enableLiveUpdates) {
return false;
}
return null;
}
var O = Object.assign, A = 0, ie, ue, se, fe, le, ce, ve;
function de() {
}
de.__reactDisabledLog = !0;
function Ve() {
{
if (A === 0) {
ie = console.log, ue = console.info, se = console.warn, fe = console.error, le = console.group, ce = console.groupCollapsed, ve = console.groupEnd;
var e = {
configurable: !0,
enumerable: !0,
value: de,
writable: !0
};
Object.defineProperties(console, {
info: e,
log: e,
warn: e,
error: e,
group: e,
groupCollapsed: e,
groupEnd: e
});
if (options.skip) {
return false;
}
A++;
}
}
function Ne() {
{
if (A--, A === 0) {
var e = {
configurable: !0,
enumerable: !0,
writable: !0
};
Object.defineProperties(console, {
log: O({}, e, {
value: ie
}),
info: O({}, e, {
value: ue
}),
warn: O({}, e, {
value: se
}),
error: O({}, e, {
value: fe
}),
group: O({}, e, {
value: le
}),
groupCollapsed: O({}, e, {
value: ce
}),
groupEnd: O({}, e, {
value: ve
})
});
if (Array.isArray(data) && data.length) {
return true;
}
A < 0 && d("disabledDepth fell below zero. This is a bug in React. Please file an issue.");
}
}
var q = x.ReactCurrentDispatcher, B;
function L(e, r, t) {
{
if (B === void 0)
try {
throw Error();
} catch (i) {
var n = i.stack.trim().match(/\n( *(at )?)/);
B = n && n[1] || "";
}
return `
` + B + e;
}
}
var J = !1, M;
{
var qe = typeof WeakMap == "function" ? WeakMap : Map;
M = new qe();
}
function pe(e, r) {
if (!e || J)
return "";
{
var t = M.get(e);
if (t !== void 0)
return t;
}
var n;
J = !0;
var i = Error.prepareStackTrace;
Error.prepareStackTrace = void 0;
var f;
f = q.current, q.current = null, Ve();
try {
if (r) {
var o = function() {
throw Error();
};
if (Object.defineProperty(o.prototype, "props", {
set: function() {
throw Error();
}
}), typeof Reflect == "object" && Reflect.construct) {
try {
Reflect.construct(o, []);
} catch (g) {
n = g;
}
Reflect.construct(e, [], o);
} else {
try {
o.call();
} catch (g) {
n = g;
}
e.call(o.prototype);
}
} else {
try {
throw Error();
} catch (g) {
n = g;
}
e();
if (data && typeof data === 'object' && Object.keys(data).length) {
return true;
}
} catch (g) {
if (g && n && typeof g.stack == "string") {
for (var a = g.stack.split(`
`), b = n.stack.split(`
`), c = a.length - 1, v = b.length - 1; c >= 1 && v >= 0 && a[c] !== b[v]; )
v--;
for (; c >= 1 && v >= 0; c--, v--)
if (a[c] !== b[v]) {
if (c !== 1 || v !== 1)
do
if (c--, v--, v < 0 || a[c] !== b[v]) {
var R = `
` + a[c].replace(" at new ", " at ");
return e.displayName && R.includes("<anonymous>") && (R = R.replace("<anonymous>", e.displayName)), typeof e == "function" && M.set(e, R), R;
}
while (c >= 1 && v >= 0);
break;
}
return false;
}, [
config,
options.skip,
data
]);
useDeepCompareEffectNoCheck(()=>{
if (previous.current !== data) {
setState({
data,
version: 1
});
previous.current = data;
}
} finally {
J = !1, q.current = f, Ne(), Error.prepareStackTrace = i;
}
var D = e ? e.displayName || e.name : "", j = D ? L(D) : "";
return typeof e == "function" && M.set(e, j), j;
}
function Be(e, r, t) {
return pe(e, !1);
}
function Je(e) {
var r = e.prototype;
return !!(r && r.isReactComponent);
}
function U(e, r, t) {
if (e == null)
return "";
if (typeof e == "function")
return pe(e, Je(e));
if (typeof e == "string")
return L(e);
switch (e) {
case T:
return L("Suspense");
case y:
return L("SuspenseList");
}
if (typeof e == "object")
switch (e.$$typeof) {
case l:
return Be(e.render);
case P:
return U(e.type, r, t);
case S: {
var n = e, i = n._payload, f = n._init;
try {
return U(f(i), r, t);
} catch {
}
}
if (!shouldSubscribe) {
return;
}
return "";
}
var F = Object.prototype.hasOwnProperty, ye = {}, be = x.ReactDebugCurrentFrame;
function V(e) {
if (e) {
var r = e._owner, t = U(e.type, e._source, r ? r.type : null);
be.setExtraStackFrame(t);
} else
be.setExtraStackFrame(null);
}
function Ke(e, r, t, n, i) {
{
var f = Function.call.bind(F);
for (var o in e)
if (f(e, o)) {
var a = void 0;
try {
if (typeof e[o] != "function") {
var b = Error((n || "React class") + ": " + t + " type `" + o + "` is invalid; it must be a function, usually from the `prop-types` package, but received `" + typeof e[o] + "`.This often happens because of typos such as `PropTypes.function` instead of `PropTypes.func`.");
throw b.name = "Invariant Violation", b;
}
a = e[o](r, o, n, t, null, "SECRET_DO_NOT_PASS_THIS_OR_YOU_WILL_BE_FIRED");
} catch (c) {
a = c;
return ContentfulLivePreview.subscribe('edit', {
data: data,
locale: options.locale,
query: options.query,
callback: (updatedData)=>{
update.current((prevState)=>({
data: updatedData,
version: prevState.version + 1
}));
}
a && !(a instanceof Error) && (V(i), d("%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).", n || "React class", t, o, typeof a), V(null)), a instanceof Error && !(a.message in ye) && (ye[a.message] = !0, V(i), d("Failed %s type: %s", t, a.message), V(null));
}
}
}
var ze = Array.isArray;
function K(e) {
return ze(e);
}
function Ge(e) {
{
var r = typeof Symbol == "function" && Symbol.toStringTag, t = r && e[Symbol.toStringTag] || e.constructor.name || "Object";
return t;
}
}
function Xe(e) {
try {
return he(e), !1;
} catch {
return !0;
}
}
function he(e) {
return "" + e;
}
function ge(e) {
if (Xe(e))
return d("The provided key is an unsupported type %s. This value must be coerced to a string before before using it here.", Ge(e)), he(e);
}
var I = x.ReactCurrentOwner, He = {
key: !0,
ref: !0,
__self: !0,
__source: !0
}, Ee, Re, z;
z = {};
function Ze(e) {
if (F.call(e, "ref")) {
var r = Object.getOwnPropertyDescriptor(e, "ref").get;
if (r && r.isReactWarning)
return !1;
}
return e.ref !== void 0;
}
function Qe(e) {
if (F.call(e, "key")) {
var r = Object.getOwnPropertyDescriptor(e, "key").get;
if (r && r.isReactWarning)
return !1;
}
return e.key !== void 0;
}
function er(e, r) {
if (typeof e.ref == "string" && I.current && r && I.current.stateNode !== r) {
var t = w(I.current.type);
z[t] || (d('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', w(I.current.type), e.ref), z[t] = !0);
}
}
function rr(e, r) {
{
var t = function() {
Ee || (Ee = !0, d("%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 tr(e, r) {
{
var t = function() {
Re || (Re = !0, d("%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 nr = function(e, r, t, n, i, f, o) {
var a = {
// This tag allows us to uniquely identify this as a React Element
$$typeof: s,
// Built-in properties that belong on the element
type: e,
key: r,
ref: t,
props: o,
// Record the component responsible for creating this element.
_owner: f
};
return a._store = {}, Object.defineProperty(a._store, "validated", {
configurable: !1,
enumerable: !1,
writable: !0,
value: !1
}), Object.defineProperty(a, "_self", {
configurable: !1,
enumerable: !1,
writable: !1,
value: n
}), Object.defineProperty(a, "_source", {
configurable: !1,
enumerable: !1,
writable: !1,
value: i
}), Object.freeze && (Object.freeze(a.props), Object.freeze(a)), a;
};
function ar(e, r, t, n, i) {
{
var f, o = {}, a = null, b = null;
t !== void 0 && (ge(t), a = "" + t), Qe(r) && (ge(r.key), a = "" + r.key), Ze(r) && (b = r.ref, er(r, i));
for (f in r)
F.call(r, f) && !He.hasOwnProperty(f) && (o[f] = r[f]);
if (e && e.defaultProps) {
var c = e.defaultProps;
for (f in c)
o[f] === void 0 && (o[f] = c[f]);
}
if (a || b) {
var v = typeof e == "function" ? e.displayName || e.name || "Unknown" : e;
a && rr(o, v), b && tr(o, v);
}
return nr(e, a, b, i, n, I.current, o);
}
}
var G = x.ReactCurrentOwner, me = x.ReactDebugCurrentFrame;
function k(e) {
if (e) {
var r = e._owner, t = U(e.type, e._source, r ? r.type : null);
me.setExtraStackFrame(t);
} else
me.setExtraStackFrame(null);
}
var X;
X = !1;
function H(e) {
return typeof e == "object" && e !== null && e.$$typeof === s;
}
function _e() {
{
if (G.current) {
var e = w(G.current.type);
if (e)
return `
Check the render method of \`` + e + "`.";
}
return "";
}
}
function or(e) {
{
if (e !== void 0) {
var r = e.fileName.replace(/^.*[\\\/]/, ""), t = e.lineNumber;
return `
Check your code at ` + r + ":" + t + ".";
}
return "";
}
}
var Ce = {};
function ir(e) {
{
var r = _e();
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 Te(e, r) {
{
if (!e._store || e._store.validated || e.key != null)
return;
e._store.validated = !0;
var t = ir(r);
if (Ce[t])
return;
Ce[t] = !0;
var n = "";
e && e._owner && e._owner !== G.current && (n = " It was passed a child from " + w(e._owner.type) + "."), k(e), d('Each child in a list should have a unique "key" prop.%s%s See https://reactjs.org/link/warning-keys for more information.', t, n), k(null);
}
}
function Pe(e, r) {
{
if (typeof e != "object")
return;
if (K(e))
for (var t = 0; t < e.length; t++) {
var n = e[t];
H(n) && Te(n, r);
}
else if (H(e))
e._store && (e._store.validated = !0);
else if (e) {
var i = Ae(e);
if (typeof i == "function" && i !== e.entries)
for (var f = i.call(e), o; !(o = f.next()).done; )
H(o.value) && Te(o.value, r);
}
}
}
function ur(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 === l || // Note: Memo only checks outer props here.
// Inner props are checked in the reconciler.
r.$$typeof === P))
t = r.propTypes;
else
return;
if (t) {
var n = w(r);
Ke(t, e.props, "prop", n, e);
} else if (r.PropTypes !== void 0 && !X) {
X = !0;
var i = w(r);
d("Component %s declared `PropTypes` instead of `propTypes`. Did you misspell the property assignment?", i || "Unknown");
}
typeof r.getDefaultProps == "function" && !r.getDefaultProps.isReactClassApproved && d("getDefaultProps is only used on classic React.createClass definitions. Use a static property named `defaultProps` instead.");
}
}
function sr(e) {
{
for (var r = Object.keys(e.props), t = 0; t < r.length; t++) {
var n = r[t];
if (n !== "children" && n !== "key") {
k(e), d("Invalid prop `%s` supplied to `React.Fragment`. React.Fragment can only have `key` and `children` props.", n), k(null);
break;
}
}
e.ref !== null && (k(e), d("Invalid attribute `ref` supplied to `React.Fragment`."), k(null));
}
}
var we = {};
function Se(e, r, t, n, i, f) {
{
var o = Me(e);
if (!o) {
var a = "";
(e === void 0 || typeof e == "object" && e !== null && Object.keys(e).length === 0) && (a += " 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 b = or(i);
b ? a += b : a += _e();
var c;
e === null ? c = "null" : K(e) ? c = "array" : e !== void 0 && e.$$typeof === s ? (c = "<" + (w(e.type) || "Unknown") + " />", a = " Did you accidentally export a JSX literal instead of a component?") : c = typeof e, d("React.jsx: type is invalid -- expected a string (for built-in components) or a class/function (for composite components) but got: %s.%s", c, a);
}
var v = ar(e, r, t, i, f);
if (v == null)
return v;
if (o) {
var R = r.children;
if (R !== void 0)
if (n)
if (K(R)) {
for (var D = 0; D < R.length; D++)
Pe(R[D], e);
Object.freeze && Object.freeze(R);
} else
d("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
Pe(R, e);
}
if (F.call(r, "key")) {
var j = w(e), g = Object.keys(r).filter(function(pr) {
return pr !== "key";
}), Z = g.length > 0 ? "{key: someKey, " + g.join(": ..., ") + ": ...}" : "{key: someKey}";
if (!we[j + Z]) {
var dr = g.length > 0 ? "{" + g.join(": ..., ") + ": ...}" : "{}";
d(`A props object containing a "key" prop is being spread into JSX:
let props = %s;
<%s {...props} />
React keys must be passed directly to JSX without using spread:
let props = %s;
<%s key={someKey} {...props} />`, Z, j, dr, j), we[j + Z] = !0;
}
}
return e === E ? sr(v) : ur(v), v;
}
}
function fr(e, r, t) {
return Se(e, r, t, !0);
}
function lr(e, r, t) {
return Se(e, r, t, !1);
}
var cr = lr, vr = fr;
$.Fragment = E, $.jsx = cr, $.jsxs = vr;
}()), $;
}, [
data,
shouldSubscribe,
options.locale,
options.query
]);
return state.data;
}
process.env.NODE_ENV === "production" ? Q.exports = mr() : Q.exports = _r();
var Cr = Q.exports;
function Tr(u) {
const s = N(u), h = N(0);
return Er(u, s.current) || (s.current = u, h.current += 1), ee(() => s.current, [h.current]);
}
function Pr(u, s) {
return br(u, Tr(s));
}
const te = yr(null);
function Or({
children: u,
locale: s,
space: h,
environment: E,
debugMode: m = !1,
enableInspectorMode: _ = !0,
enableLiveUpdates: C = !0,
targetOrigin: p,
experimental: l
}) {
if (!s)
throw new Error(
'ContentfulLivePreviewProvider have to be called with a locale property (for example: `<ContentfulLivePreviewProvider locale="en-US">{children}</ContentfulLivePreviewProvider>`'
);
re.init({
locale: s,
space: h,
environment: E,
debugMode: m,
enableInspectorMode: _,
enableLiveUpdates: C,
targetOrigin: p,
experimental: l
});
const T = ee(
() => ({
locale: s,
space: h,
environment: E,
debugMode: m,
enableInspectorMode: _,
enableLiveUpdates: C,
targetOrigin: p
}),
[s, h, E, m, _, C, p]
);
return /* @__PURE__ */ Cr.jsx(te.Provider, { value: T, children: u });
}
function jr(u, s, h = !1) {
const [E, m] = hr({ data: u, version: 1 }), _ = N(u), C = N(Rr(m)), p = ke(te), l = typeof s == "object" ? s : { locale: s, skip: h }, T = ee(() => p && !p.enableLiveUpdates || l.skip ? !1 : !!(Array.isArray(u) && u.length || u && typeof u == "object" && Object.keys(u).length), [p, l.skip, u]);
return Pr(() => {
if (_.current !== u && (m({ data: u, version: 1 }), _.current = u), !!T)
return re.subscribe("edit", {
data: u,
locale: l.locale,
query: l.query,
callback: (y) => {
C.current((P) => ({ data: y, version: P.version + 1 }));
export function useContentfulInspectorMode(sharedProps) {
const config = useContext(ContentfulLivePreviewContext);
return useCallback((props)=>{
if (config === null || config === void 0 ? void 0 : config.enableInspectorMode) {
return ContentfulLivePreview.getProps(_object_spread({}, sharedProps, props));
}
});
}, [u, T, l.locale, l.query]), E.data;
return null;
}, [
config === null || config === void 0 ? void 0 : config.enableInspectorMode,
sharedProps
]);
}
function xr(u) {
const s = ke(te);
return gr(
(h) => s != null && s.enableInspectorMode ? re.getProps({ ...u, ...h }) : null,
[s == null ? void 0 : s.enableInspectorMode, u]
);
}
export {
Or as ContentfulLivePreviewProvider,
xr as useContentfulInspectorMode,
jr as useContentfulLiveUpdates,
Pr as useDeepCompareEffectNoCheck,
Tr as useDeepCompareMemoize
};
//# sourceMappingURL=react.js.map
{
"name": "@contentful/live-preview",
"version": "4.3.2",
"version": "4.4.0",
"author": "Contentful GmbH",

@@ -12,6 +12,2 @@ "license": "MIT",

"type": "module",
"files": [
"dist",
"react"
],
"exports": {

@@ -21,2 +17,3 @@ ".": {

"require": "./dist/index.cjs",
"default": "./dist/index.cjs",
"types": "./dist/index.d.ts"

@@ -28,4 +25,9 @@ },

"types": "./dist/react.d.ts"
}
},
"./package.json": "./package.json"
},
"files": [
"dist",
"react"
],
"repository": {

@@ -39,4 +41,11 @@ "type": "git",

"scripts": {
"start": "vite build --watch",
"build": "vite build",
"start": "yarn concurrently \"yarn:watch:*\"",
"watch:cjs": "yarn build:cjs -w",
"watch:esm": "yarn build:esm -w",
"watch:types": "yarn build:types --watch",
"prebuild": "rm -rf dist",
"build": "yarn build:types && yarn build:cjs && yarn build:esm",
"build:types": "tsc --outDir dist --emitDeclarationOnly",
"build:cjs": "swc src --config-file ../../.swcrc -d dist -C module.type=commonjs --strip-leading-paths --out-file-extension cjs",
"build:esm": "swc src --config-file ../../.swcrc -d dist --strip-leading-paths",
"benchmark": "vitest bench",

@@ -52,3 +61,3 @@ "lint": "eslint ./src --ext .js,.jsx,.ts,.tsx",

"dependencies": {
"@contentful/content-source-maps": "^0.8.0",
"@contentful/content-source-maps": "^0.9.0",
"@contentful/rich-text-types": "^16.2.0",

@@ -67,3 +76,2 @@ "flatted": "^3.2.9",

"@types/react-dom": "^18.0.10",
"@vitejs/plugin-react-swc": "3.7.0",
"contentful": "^10.3.4",

@@ -81,3 +89,3 @@ "contentful-management": "^11.0.1",

},
"gitHead": "5fd12f2b1bd46e6c6ddf25f45bb2c4921adbe812"
"gitHead": "bf5d31037d272ca75aebbc8bed36ba05b8073832"
}

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