react-datocms
Advanced tools
Comparing version 1.6.1-2 to 1.6.1-3
@@ -1,17 +0,357 @@ | ||
"use strict"; | ||
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { | ||
if (k2 === undefined) k2 = k; | ||
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } }); | ||
}) : (function(o, m, k, k2) { | ||
if (k2 === undefined) k2 = k; | ||
o[k2] = m[k]; | ||
})); | ||
var __exportStar = (this && this.__exportStar) || function(m, exports) { | ||
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p); | ||
'use strict'; | ||
Object.defineProperty(exports, '__esModule', { value: true }); | ||
var React = require('react'); | ||
require('intersection-observer'); | ||
var reactIntersectionObserver = require('react-intersection-observer'); | ||
var datocmsListen = require('datocms-listen'); | ||
var useDeepCompareEffect = require('use-deep-compare-effect'); | ||
var datocmsStructuredTextGenericHtmlRenderer = require('datocms-structured-text-generic-html-renderer'); | ||
var datocmsStructuredTextUtils = require('datocms-structured-text-utils'); | ||
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; } | ||
var React__default = /*#__PURE__*/_interopDefaultLegacy(React); | ||
/*! ***************************************************************************** | ||
Copyright (c) Microsoft Corporation. | ||
Permission to use, copy, modify, and/or distribute this software for any | ||
purpose with or without fee is hereby granted. | ||
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH | ||
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY | ||
AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, | ||
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM | ||
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR | ||
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR | ||
PERFORMANCE OF THIS SOFTWARE. | ||
***************************************************************************** */ | ||
var __assign = function() { | ||
__assign = Object.assign || function __assign(t) { | ||
for (var s, i = 1, n = arguments.length; i < n; i++) { | ||
s = arguments[i]; | ||
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p]; | ||
} | ||
return t; | ||
}; | ||
return __assign.apply(this, arguments); | ||
}; | ||
exports.__esModule = true; | ||
__exportStar(require("./Image/index"), exports); | ||
__exportStar(require("./Seo/index"), exports); | ||
__exportStar(require("./useQuerySubscription/index"), exports); | ||
__exportStar(require("./StructuredText/index"), exports); | ||
//# sourceMappingURL=index.js.map | ||
function __rest(s, e) { | ||
var t = {}; | ||
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0) | ||
t[p] = s[p]; | ||
if (s != null && typeof Object.getOwnPropertySymbols === "function") | ||
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) { | ||
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i])) | ||
t[p[i]] = s[p[i]]; | ||
} | ||
return t; | ||
} | ||
function __awaiter(thisArg, _arguments, P, generator) { | ||
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } | ||
return new (P || (P = Promise))(function (resolve, reject) { | ||
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } | ||
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } | ||
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } | ||
step((generator = generator.apply(thisArg, _arguments || [])).next()); | ||
}); | ||
} | ||
function __generator(thisArg, body) { | ||
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g; | ||
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g; | ||
function verb(n) { return function (v) { return step([n, v]); }; } | ||
function step(op) { | ||
if (f) throw new TypeError("Generator is already executing."); | ||
while (_) try { | ||
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t; | ||
if (y = 0, t) op = [op[0] & 2, t.value]; | ||
switch (op[0]) { | ||
case 0: case 1: t = op; break; | ||
case 4: _.label++; return { value: op[1], done: false }; | ||
case 5: _.label++; y = op[1]; op = [0]; continue; | ||
case 7: op = _.ops.pop(); _.trys.pop(); continue; | ||
default: | ||
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; } | ||
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; } | ||
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; } | ||
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; } | ||
if (t[2]) _.ops.pop(); | ||
_.trys.pop(); continue; | ||
} | ||
op = body.call(thisArg, _); | ||
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; } | ||
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true }; | ||
} | ||
} | ||
var isSsr = typeof window === "undefined"; | ||
var universalBtoa = isSsr | ||
? function (str) { return Buffer.from(str.toString(), "binary").toString("base64"); } | ||
: window.btoa; | ||
var isIntersectionObserverAvailable = isSsr | ||
? false | ||
: !!window.IntersectionObserver; | ||
var imageAddStrategy = function (_a) { | ||
var lazyLoad = _a.lazyLoad, inView = _a.inView, loaded = _a.loaded; | ||
if (!lazyLoad) { | ||
return true; | ||
} | ||
if (isSsr) { | ||
return false; | ||
} | ||
if (isIntersectionObserverAvailable) { | ||
return inView || loaded; | ||
} | ||
return true; | ||
}; | ||
var imageShowStrategy = function (_a) { | ||
var lazyLoad = _a.lazyLoad, loaded = _a.loaded; | ||
if (!lazyLoad) { | ||
return true; | ||
} | ||
if (isSsr) { | ||
return false; | ||
} | ||
if (isIntersectionObserverAvailable) { | ||
return loaded; | ||
} | ||
return true; | ||
}; | ||
var Image = function (_a) { | ||
var className = _a.className, fadeInDuration = _a.fadeInDuration, intersectionTreshold = _a.intersectionTreshold, intersectionThreshold = _a.intersectionThreshold, intersectionMargin = _a.intersectionMargin, pictureClassName = _a.pictureClassName, _b = _a.lazyLoad, lazyLoad = _b === void 0 ? true : _b, style = _a.style, pictureStyle = _a.pictureStyle, explicitWidth = _a.explicitWidth, data = _a.data; | ||
var _c = React.useState(false), loaded = _c[0], setLoaded = _c[1]; | ||
var handleLoad = React.useCallback(function () { | ||
setLoaded(true); | ||
}, []); | ||
var _d = reactIntersectionObserver.useInView({ | ||
threshold: intersectionThreshold || intersectionTreshold || 0, | ||
rootMargin: intersectionMargin || "0px 0px 0px 0px", | ||
triggerOnce: true, | ||
}), ref = _d.ref, inView = _d.inView; | ||
var absolutePositioning = { | ||
position: "absolute", | ||
left: 0, | ||
top: 0, | ||
width: "100%", | ||
height: "100%", | ||
}; | ||
var addImage = imageAddStrategy({ | ||
lazyLoad: lazyLoad, | ||
inView: inView, | ||
loaded: loaded, | ||
}); | ||
var showImage = imageShowStrategy({ | ||
lazyLoad: lazyLoad, | ||
inView: inView, | ||
loaded: loaded, | ||
}); | ||
var webpSource = data.webpSrcSet && (React__default['default'].createElement("source", { srcSet: data.webpSrcSet, sizes: data.sizes, type: "image/webp" })); | ||
var regularSource = data.srcSet && (React__default['default'].createElement("source", { srcSet: data.srcSet, sizes: data.sizes })); | ||
var transition = typeof fadeInDuration === "undefined" || fadeInDuration > 0 | ||
? "opacity " + (fadeInDuration || 500) + "ms " + (fadeInDuration || 500) + "ms" | ||
: undefined; | ||
var placeholder = (React__default['default'].createElement("div", { style: __assign({ backgroundImage: data.base64 ? "url(" + data.base64 + ")" : undefined, backgroundColor: data.bgColor, backgroundSize: "cover", opacity: showImage ? 0 : 1, transition: transition }, absolutePositioning) })); | ||
var width = data.width, aspectRatio = data.aspectRatio; | ||
var height = data.height || width / aspectRatio; | ||
var svg = "<svg xmlns=\"http://www.w3.org/2000/svg\" width=\"" + width + "\" height=\"" + height + "\"></svg>"; | ||
var sizer = (React__default['default'].createElement("img", { className: pictureClassName, style: __assign({ display: "block", width: explicitWidth ? width + "px" : "100%" }, pictureStyle), src: "data:image/svg+xml;base64," + universalBtoa(svg), role: "presentation" })); | ||
return (React__default['default'].createElement("div", { ref: ref, className: className, style: __assign(__assign({ display: explicitWidth ? "inline-block" : "block", overflow: "hidden" }, style), { position: "relative" }) }, | ||
sizer, | ||
placeholder, | ||
addImage && (React__default['default'].createElement("picture", null, | ||
webpSource, | ||
regularSource, | ||
data.src && (React__default['default'].createElement("img", { src: data.src, alt: data.alt, title: data.title, onLoad: handleLoad, className: pictureClassName, style: __assign(__assign(__assign({}, absolutePositioning), pictureStyle), { opacity: showImage ? 1 : 0, transition: transition }) })))), | ||
React__default['default'].createElement("noscript", null, | ||
React__default['default'].createElement("picture", null, | ||
webpSource, | ||
regularSource, | ||
data.src && (React__default['default'].createElement("img", { src: data.src, alt: data.alt, title: data.title, className: pictureClassName, style: __assign(__assign({}, absolutePositioning), pictureStyle), loading: "lazy" })))))); | ||
}; | ||
var renderMetaTags = function (data) { | ||
return data.map(function (_a) { | ||
var tag = _a.tag, attributes = _a.attributes, content = _a.content; | ||
var key = [tag]; | ||
if (attributes && "property" in attributes) { | ||
key.push(attributes.property); | ||
} | ||
if (attributes && "name" in attributes) { | ||
key.push(attributes.name); | ||
} | ||
if (attributes && "rel" in attributes) { | ||
key.push(attributes.rel); | ||
} | ||
if (attributes && "sizes" in attributes) { | ||
key.push(attributes.sizes); | ||
} | ||
var Tag = tag; | ||
return (React__default['default'].createElement(Tag, __assign({ key: key.join("-") }, attributes), content)); | ||
}); | ||
}; | ||
var serializeAttributes = function (attributes) { | ||
if (!attributes) { | ||
return ""; | ||
} | ||
var serializedAttrs = []; | ||
for (var key in attributes) { | ||
if (Object.prototype.hasOwnProperty.call(attributes, key)) { | ||
serializedAttrs.push(key + "=\"" + attributes[key] + "\""); | ||
} | ||
} | ||
return " " + serializedAttrs.join(" "); | ||
}; | ||
var renderMetaTagsToString = function (data) { | ||
return data | ||
.map(function (_a) { | ||
var tag = _a.tag, attributes = _a.attributes, content = _a.content; | ||
if (content) { | ||
return "<" + tag + serializeAttributes(attributes) + ">" + content + "</" + tag + ">"; | ||
} | ||
return "<" + tag + serializeAttributes(attributes) + " />"; | ||
}) | ||
.join("\n"); | ||
}; | ||
function useQuerySubscription(options) { | ||
var enabled = options.enabled, initialData = options.initialData, other = __rest(options, ["enabled", "initialData"]); | ||
var _a = React.useState(null), error = _a[0], setError = _a[1]; | ||
var _b = React.useState(null), data = _b[0], setData = _b[1]; | ||
var _c = React.useState(enabled ? "connecting" : "closed"), status = _c[0], setStatus = _c[1]; | ||
var subscribeToQueryOptions = other; | ||
useDeepCompareEffect.useDeepCompareEffectNoCheck(function () { | ||
if (enabled === false) { | ||
setStatus("closed"); | ||
return function () { | ||
// we don't have to perform any uninstall | ||
}; | ||
} | ||
var unsubscribe; | ||
function subscribe() { | ||
return __awaiter(this, void 0, void 0, function () { | ||
return __generator(this, function (_a) { | ||
switch (_a.label) { | ||
case 0: return [4 /*yield*/, datocmsListen.subscribeToQuery(__assign(__assign({}, subscribeToQueryOptions), { onStatusChange: function (status) { | ||
setStatus(status); | ||
}, onUpdate: function (updateData) { | ||
setError(null); | ||
setData(updateData.response.data); | ||
}, onChannelError: function (errorData) { | ||
setData(null); | ||
setError(errorData); | ||
} }))]; | ||
case 1: | ||
unsubscribe = _a.sent(); | ||
return [2 /*return*/]; | ||
} | ||
}); | ||
}); | ||
} | ||
subscribe(); | ||
return function () { | ||
if (unsubscribe) { | ||
unsubscribe(); | ||
} | ||
}; | ||
}, Object.values(subscribeToQueryOptions)); | ||
return { error: error, status: status, data: data || initialData }; | ||
} | ||
var defaultAdapter = { | ||
renderNode: React__default['default'].createElement, | ||
renderFragment: function (children, key) { return React__default['default'].createElement(React__default['default'].Fragment, { key: key }, children); }, | ||
renderText: function (text, key) { return text; }, | ||
}; | ||
function appendKeyToValidElement(element, key) { | ||
if (React.isValidElement(element) && element.key === null) { | ||
return React.cloneElement(element, { key: key }); | ||
} | ||
return element; | ||
} | ||
function StructuredText(_a) { | ||
var data = _a.data, renderInlineRecord = _a.renderInlineRecord, renderLinkToRecord = _a.renderLinkToRecord, renderBlock = _a.renderBlock, renderText = _a.renderText, renderNode = _a.renderNode, renderFragment = _a.renderFragment, customRules = _a.customRules, metaTransformer = _a.metaTransformer; | ||
var result = datocmsStructuredTextGenericHtmlRenderer.render({ | ||
renderText: renderText || defaultAdapter.renderText, | ||
renderNode: renderNode || defaultAdapter.renderNode, | ||
renderFragment: renderFragment || defaultAdapter.renderFragment, | ||
}, data, [ | ||
datocmsStructuredTextGenericHtmlRenderer.renderRule(datocmsStructuredTextUtils.isInlineItem, function (_a) { | ||
var node = _a.node, key = _a.key; | ||
if (!renderInlineRecord) { | ||
throw new datocmsStructuredTextUtils.RenderError("The Structured Text document contains an 'inlineItem' node, but no 'renderInlineRecord' prop is specified!", node); | ||
} | ||
if (!datocmsStructuredTextUtils.isStructuredText(data) || !data.links) { | ||
throw new datocmsStructuredTextUtils.RenderError("The document contains an 'itemLink' node, but the passed data prop is not a Structured Text GraphQL response, or data.links is not present!", node); | ||
} | ||
var item = data.links.find(function (item) { return item.id === node.item; }); | ||
if (!item) { | ||
throw new datocmsStructuredTextUtils.RenderError("The Structured Text document contains an 'inlineItem' node, but cannot find a record with ID " + node.item + " inside data.links!", node); | ||
} | ||
return appendKeyToValidElement(renderInlineRecord({ record: item }), key); | ||
}), | ||
datocmsStructuredTextGenericHtmlRenderer.renderRule(datocmsStructuredTextUtils.isItemLink, function (_a) { | ||
var node = _a.node, key = _a.key, children = _a.children; | ||
if (!renderLinkToRecord) { | ||
throw new datocmsStructuredTextUtils.RenderError("The Structured Text document contains an 'itemLink' node, but no 'renderLinkToRecord' prop is specified!", node); | ||
} | ||
if (!datocmsStructuredTextUtils.isStructuredText(data) || !data.links) { | ||
throw new datocmsStructuredTextUtils.RenderError("The document contains an 'itemLink' node, but the passed data prop is not a Structured Text GraphQL response, or data.links is not present!", node); | ||
} | ||
var item = data.links.find(function (item) { return item.id === node.item; }); | ||
if (!item) { | ||
throw new datocmsStructuredTextUtils.RenderError("The Structured Text document contains an 'itemLink' node, but cannot find a record with ID " + node.item + " inside data.links!", node); | ||
} | ||
return appendKeyToValidElement(renderLinkToRecord({ | ||
record: item, | ||
children: children, | ||
transformedMeta: node.meta | ||
? (metaTransformer || datocmsStructuredTextGenericHtmlRenderer.defaultMetaTransformer)({ | ||
node: node, | ||
meta: node.meta, | ||
}) | ||
: null, | ||
}), key); | ||
}), | ||
datocmsStructuredTextGenericHtmlRenderer.renderRule(datocmsStructuredTextUtils.isBlock, function (_a) { | ||
var node = _a.node, key = _a.key; | ||
if (!renderBlock) { | ||
throw new datocmsStructuredTextUtils.RenderError("The Structured Text document contains a 'block' node, but no 'renderBlock' prop is specified!", node); | ||
} | ||
if (!datocmsStructuredTextUtils.isStructuredText(data) || !data.blocks) { | ||
throw new datocmsStructuredTextUtils.RenderError("The document contains an 'block' node, but the passed data prop is not a Structured Text GraphQL response, or data.blocks is not present!", node); | ||
} | ||
var item = data.blocks.find(function (item) { return item.id === node.item; }); | ||
if (!item) { | ||
throw new datocmsStructuredTextUtils.RenderError("The Structured Text document contains a 'block' node, but cannot find a record with ID " + node.item + " inside data.blocks!", node); | ||
} | ||
return appendKeyToValidElement(renderBlock({ record: item }), key); | ||
}), | ||
].concat(customRules || []), metaTransformer); | ||
return result; | ||
} | ||
Object.defineProperty(exports, 'renderRule', { | ||
enumerable: true, | ||
get: function () { | ||
return datocmsStructuredTextGenericHtmlRenderer.renderRule; | ||
} | ||
}); | ||
Object.defineProperty(exports, 'RenderError', { | ||
enumerable: true, | ||
get: function () { | ||
return datocmsStructuredTextUtils.RenderError; | ||
} | ||
}); | ||
exports.Image = Image; | ||
exports.StructuredText = StructuredText; | ||
exports.appendKeyToValidElement = appendKeyToValidElement; | ||
exports.defaultAdapter = defaultAdapter; | ||
exports.renderMetaTags = renderMetaTags; | ||
exports.renderMetaTagsToString = renderMetaTagsToString; | ||
exports.useQuerySubscription = useQuerySubscription; |
export {}; |
@@ -0,0 +0,0 @@ import React from "react"; |
@@ -0,0 +0,0 @@ export * from './Image/index'; |
@@ -1,5 +0,333 @@ | ||
export * from './Image/index'; | ||
export * from './Seo/index'; | ||
export * from './useQuerySubscription/index'; | ||
export * from './StructuredText/index'; | ||
//# sourceMappingURL=index.js.map | ||
import React, { useState, useCallback, isValidElement, cloneElement } from 'react'; | ||
import 'intersection-observer'; | ||
import { useInView } from 'react-intersection-observer'; | ||
import { subscribeToQuery } from 'datocms-listen'; | ||
import { useDeepCompareEffectNoCheck } from 'use-deep-compare-effect'; | ||
import { render, renderRule, defaultMetaTransformer } from 'datocms-structured-text-generic-html-renderer'; | ||
export { renderRule } from 'datocms-structured-text-generic-html-renderer'; | ||
import { isInlineItem, RenderError, isStructuredText, isItemLink, isBlock } from 'datocms-structured-text-utils'; | ||
export { RenderError } from 'datocms-structured-text-utils'; | ||
/*! ***************************************************************************** | ||
Copyright (c) Microsoft Corporation. | ||
Permission to use, copy, modify, and/or distribute this software for any | ||
purpose with or without fee is hereby granted. | ||
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH | ||
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY | ||
AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, | ||
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM | ||
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR | ||
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR | ||
PERFORMANCE OF THIS SOFTWARE. | ||
***************************************************************************** */ | ||
var __assign = function() { | ||
__assign = Object.assign || function __assign(t) { | ||
for (var s, i = 1, n = arguments.length; i < n; i++) { | ||
s = arguments[i]; | ||
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p]; | ||
} | ||
return t; | ||
}; | ||
return __assign.apply(this, arguments); | ||
}; | ||
function __rest(s, e) { | ||
var t = {}; | ||
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0) | ||
t[p] = s[p]; | ||
if (s != null && typeof Object.getOwnPropertySymbols === "function") | ||
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) { | ||
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i])) | ||
t[p[i]] = s[p[i]]; | ||
} | ||
return t; | ||
} | ||
function __awaiter(thisArg, _arguments, P, generator) { | ||
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } | ||
return new (P || (P = Promise))(function (resolve, reject) { | ||
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } | ||
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } | ||
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } | ||
step((generator = generator.apply(thisArg, _arguments || [])).next()); | ||
}); | ||
} | ||
function __generator(thisArg, body) { | ||
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g; | ||
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g; | ||
function verb(n) { return function (v) { return step([n, v]); }; } | ||
function step(op) { | ||
if (f) throw new TypeError("Generator is already executing."); | ||
while (_) try { | ||
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t; | ||
if (y = 0, t) op = [op[0] & 2, t.value]; | ||
switch (op[0]) { | ||
case 0: case 1: t = op; break; | ||
case 4: _.label++; return { value: op[1], done: false }; | ||
case 5: _.label++; y = op[1]; op = [0]; continue; | ||
case 7: op = _.ops.pop(); _.trys.pop(); continue; | ||
default: | ||
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; } | ||
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; } | ||
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; } | ||
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; } | ||
if (t[2]) _.ops.pop(); | ||
_.trys.pop(); continue; | ||
} | ||
op = body.call(thisArg, _); | ||
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; } | ||
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true }; | ||
} | ||
} | ||
var isSsr = typeof window === "undefined"; | ||
var universalBtoa = isSsr | ||
? function (str) { return Buffer.from(str.toString(), "binary").toString("base64"); } | ||
: window.btoa; | ||
var isIntersectionObserverAvailable = isSsr | ||
? false | ||
: !!window.IntersectionObserver; | ||
var imageAddStrategy = function (_a) { | ||
var lazyLoad = _a.lazyLoad, inView = _a.inView, loaded = _a.loaded; | ||
if (!lazyLoad) { | ||
return true; | ||
} | ||
if (isSsr) { | ||
return false; | ||
} | ||
if (isIntersectionObserverAvailable) { | ||
return inView || loaded; | ||
} | ||
return true; | ||
}; | ||
var imageShowStrategy = function (_a) { | ||
var lazyLoad = _a.lazyLoad, loaded = _a.loaded; | ||
if (!lazyLoad) { | ||
return true; | ||
} | ||
if (isSsr) { | ||
return false; | ||
} | ||
if (isIntersectionObserverAvailable) { | ||
return loaded; | ||
} | ||
return true; | ||
}; | ||
var Image = function (_a) { | ||
var className = _a.className, fadeInDuration = _a.fadeInDuration, intersectionTreshold = _a.intersectionTreshold, intersectionThreshold = _a.intersectionThreshold, intersectionMargin = _a.intersectionMargin, pictureClassName = _a.pictureClassName, _b = _a.lazyLoad, lazyLoad = _b === void 0 ? true : _b, style = _a.style, pictureStyle = _a.pictureStyle, explicitWidth = _a.explicitWidth, data = _a.data; | ||
var _c = useState(false), loaded = _c[0], setLoaded = _c[1]; | ||
var handleLoad = useCallback(function () { | ||
setLoaded(true); | ||
}, []); | ||
var _d = useInView({ | ||
threshold: intersectionThreshold || intersectionTreshold || 0, | ||
rootMargin: intersectionMargin || "0px 0px 0px 0px", | ||
triggerOnce: true, | ||
}), ref = _d.ref, inView = _d.inView; | ||
var absolutePositioning = { | ||
position: "absolute", | ||
left: 0, | ||
top: 0, | ||
width: "100%", | ||
height: "100%", | ||
}; | ||
var addImage = imageAddStrategy({ | ||
lazyLoad: lazyLoad, | ||
inView: inView, | ||
loaded: loaded, | ||
}); | ||
var showImage = imageShowStrategy({ | ||
lazyLoad: lazyLoad, | ||
inView: inView, | ||
loaded: loaded, | ||
}); | ||
var webpSource = data.webpSrcSet && (React.createElement("source", { srcSet: data.webpSrcSet, sizes: data.sizes, type: "image/webp" })); | ||
var regularSource = data.srcSet && (React.createElement("source", { srcSet: data.srcSet, sizes: data.sizes })); | ||
var transition = typeof fadeInDuration === "undefined" || fadeInDuration > 0 | ||
? "opacity " + (fadeInDuration || 500) + "ms " + (fadeInDuration || 500) + "ms" | ||
: undefined; | ||
var placeholder = (React.createElement("div", { style: __assign({ backgroundImage: data.base64 ? "url(" + data.base64 + ")" : undefined, backgroundColor: data.bgColor, backgroundSize: "cover", opacity: showImage ? 0 : 1, transition: transition }, absolutePositioning) })); | ||
var width = data.width, aspectRatio = data.aspectRatio; | ||
var height = data.height || width / aspectRatio; | ||
var svg = "<svg xmlns=\"http://www.w3.org/2000/svg\" width=\"" + width + "\" height=\"" + height + "\"></svg>"; | ||
var sizer = (React.createElement("img", { className: pictureClassName, style: __assign({ display: "block", width: explicitWidth ? width + "px" : "100%" }, pictureStyle), src: "data:image/svg+xml;base64," + universalBtoa(svg), role: "presentation" })); | ||
return (React.createElement("div", { ref: ref, className: className, style: __assign(__assign({ display: explicitWidth ? "inline-block" : "block", overflow: "hidden" }, style), { position: "relative" }) }, | ||
sizer, | ||
placeholder, | ||
addImage && (React.createElement("picture", null, | ||
webpSource, | ||
regularSource, | ||
data.src && (React.createElement("img", { src: data.src, alt: data.alt, title: data.title, onLoad: handleLoad, className: pictureClassName, style: __assign(__assign(__assign({}, absolutePositioning), pictureStyle), { opacity: showImage ? 1 : 0, transition: transition }) })))), | ||
React.createElement("noscript", null, | ||
React.createElement("picture", null, | ||
webpSource, | ||
regularSource, | ||
data.src && (React.createElement("img", { src: data.src, alt: data.alt, title: data.title, className: pictureClassName, style: __assign(__assign({}, absolutePositioning), pictureStyle), loading: "lazy" })))))); | ||
}; | ||
var renderMetaTags = function (data) { | ||
return data.map(function (_a) { | ||
var tag = _a.tag, attributes = _a.attributes, content = _a.content; | ||
var key = [tag]; | ||
if (attributes && "property" in attributes) { | ||
key.push(attributes.property); | ||
} | ||
if (attributes && "name" in attributes) { | ||
key.push(attributes.name); | ||
} | ||
if (attributes && "rel" in attributes) { | ||
key.push(attributes.rel); | ||
} | ||
if (attributes && "sizes" in attributes) { | ||
key.push(attributes.sizes); | ||
} | ||
var Tag = tag; | ||
return (React.createElement(Tag, __assign({ key: key.join("-") }, attributes), content)); | ||
}); | ||
}; | ||
var serializeAttributes = function (attributes) { | ||
if (!attributes) { | ||
return ""; | ||
} | ||
var serializedAttrs = []; | ||
for (var key in attributes) { | ||
if (Object.prototype.hasOwnProperty.call(attributes, key)) { | ||
serializedAttrs.push(key + "=\"" + attributes[key] + "\""); | ||
} | ||
} | ||
return " " + serializedAttrs.join(" "); | ||
}; | ||
var renderMetaTagsToString = function (data) { | ||
return data | ||
.map(function (_a) { | ||
var tag = _a.tag, attributes = _a.attributes, content = _a.content; | ||
if (content) { | ||
return "<" + tag + serializeAttributes(attributes) + ">" + content + "</" + tag + ">"; | ||
} | ||
return "<" + tag + serializeAttributes(attributes) + " />"; | ||
}) | ||
.join("\n"); | ||
}; | ||
function useQuerySubscription(options) { | ||
var enabled = options.enabled, initialData = options.initialData, other = __rest(options, ["enabled", "initialData"]); | ||
var _a = useState(null), error = _a[0], setError = _a[1]; | ||
var _b = useState(null), data = _b[0], setData = _b[1]; | ||
var _c = useState(enabled ? "connecting" : "closed"), status = _c[0], setStatus = _c[1]; | ||
var subscribeToQueryOptions = other; | ||
useDeepCompareEffectNoCheck(function () { | ||
if (enabled === false) { | ||
setStatus("closed"); | ||
return function () { | ||
// we don't have to perform any uninstall | ||
}; | ||
} | ||
var unsubscribe; | ||
function subscribe() { | ||
return __awaiter(this, void 0, void 0, function () { | ||
return __generator(this, function (_a) { | ||
switch (_a.label) { | ||
case 0: return [4 /*yield*/, subscribeToQuery(__assign(__assign({}, subscribeToQueryOptions), { onStatusChange: function (status) { | ||
setStatus(status); | ||
}, onUpdate: function (updateData) { | ||
setError(null); | ||
setData(updateData.response.data); | ||
}, onChannelError: function (errorData) { | ||
setData(null); | ||
setError(errorData); | ||
} }))]; | ||
case 1: | ||
unsubscribe = _a.sent(); | ||
return [2 /*return*/]; | ||
} | ||
}); | ||
}); | ||
} | ||
subscribe(); | ||
return function () { | ||
if (unsubscribe) { | ||
unsubscribe(); | ||
} | ||
}; | ||
}, Object.values(subscribeToQueryOptions)); | ||
return { error: error, status: status, data: data || initialData }; | ||
} | ||
var defaultAdapter = { | ||
renderNode: React.createElement, | ||
renderFragment: function (children, key) { return React.createElement(React.Fragment, { key: key }, children); }, | ||
renderText: function (text, key) { return text; }, | ||
}; | ||
function appendKeyToValidElement(element, key) { | ||
if (isValidElement(element) && element.key === null) { | ||
return cloneElement(element, { key: key }); | ||
} | ||
return element; | ||
} | ||
function StructuredText(_a) { | ||
var data = _a.data, renderInlineRecord = _a.renderInlineRecord, renderLinkToRecord = _a.renderLinkToRecord, renderBlock = _a.renderBlock, renderText = _a.renderText, renderNode = _a.renderNode, renderFragment = _a.renderFragment, customRules = _a.customRules, metaTransformer = _a.metaTransformer; | ||
var result = render({ | ||
renderText: renderText || defaultAdapter.renderText, | ||
renderNode: renderNode || defaultAdapter.renderNode, | ||
renderFragment: renderFragment || defaultAdapter.renderFragment, | ||
}, data, [ | ||
renderRule(isInlineItem, function (_a) { | ||
var node = _a.node, key = _a.key; | ||
if (!renderInlineRecord) { | ||
throw new RenderError("The Structured Text document contains an 'inlineItem' node, but no 'renderInlineRecord' prop is specified!", node); | ||
} | ||
if (!isStructuredText(data) || !data.links) { | ||
throw new RenderError("The document contains an 'itemLink' node, but the passed data prop is not a Structured Text GraphQL response, or data.links is not present!", node); | ||
} | ||
var item = data.links.find(function (item) { return item.id === node.item; }); | ||
if (!item) { | ||
throw new RenderError("The Structured Text document contains an 'inlineItem' node, but cannot find a record with ID " + node.item + " inside data.links!", node); | ||
} | ||
return appendKeyToValidElement(renderInlineRecord({ record: item }), key); | ||
}), | ||
renderRule(isItemLink, function (_a) { | ||
var node = _a.node, key = _a.key, children = _a.children; | ||
if (!renderLinkToRecord) { | ||
throw new RenderError("The Structured Text document contains an 'itemLink' node, but no 'renderLinkToRecord' prop is specified!", node); | ||
} | ||
if (!isStructuredText(data) || !data.links) { | ||
throw new RenderError("The document contains an 'itemLink' node, but the passed data prop is not a Structured Text GraphQL response, or data.links is not present!", node); | ||
} | ||
var item = data.links.find(function (item) { return item.id === node.item; }); | ||
if (!item) { | ||
throw new RenderError("The Structured Text document contains an 'itemLink' node, but cannot find a record with ID " + node.item + " inside data.links!", node); | ||
} | ||
return appendKeyToValidElement(renderLinkToRecord({ | ||
record: item, | ||
children: children, | ||
transformedMeta: node.meta | ||
? (metaTransformer || defaultMetaTransformer)({ | ||
node: node, | ||
meta: node.meta, | ||
}) | ||
: null, | ||
}), key); | ||
}), | ||
renderRule(isBlock, function (_a) { | ||
var node = _a.node, key = _a.key; | ||
if (!renderBlock) { | ||
throw new RenderError("The Structured Text document contains a 'block' node, but no 'renderBlock' prop is specified!", node); | ||
} | ||
if (!isStructuredText(data) || !data.blocks) { | ||
throw new RenderError("The document contains an 'block' node, but the passed data prop is not a Structured Text GraphQL response, or data.blocks is not present!", node); | ||
} | ||
var item = data.blocks.find(function (item) { return item.id === node.item; }); | ||
if (!item) { | ||
throw new RenderError("The Structured Text document contains a 'block' node, but cannot find a record with ID " + node.item + " inside data.blocks!", node); | ||
} | ||
return appendKeyToValidElement(renderBlock({ record: item }), key); | ||
}), | ||
].concat(customRules || []), metaTransformer); | ||
return result; | ||
} | ||
export { Image, StructuredText, appendKeyToValidElement, defaultAdapter, renderMetaTags, renderMetaTagsToString, useQuerySubscription }; |
export {}; |
@@ -0,0 +0,0 @@ /// <reference types="react" /> |
export {}; |
@@ -0,0 +0,0 @@ import { renderRule, TransformedMeta, TransformMetaFn } from "datocms-structured-text-generic-html-renderer"; |
@@ -0,0 +0,0 @@ import { ChannelErrorData, ConnectionStatus, Options } from "datocms-listen"; |
{ | ||
"name": "react-datocms", | ||
"version": "1.6.1-2", | ||
"version": "1.6.1-3", | ||
"types": "dist/index.d.ts", | ||
@@ -19,2 +19,4 @@ "main": "dist/cjs/index.js", | ||
"devDependencies": { | ||
"@rollup/plugin-commonjs": "^18.0.0", | ||
"@rollup/plugin-node-resolve": "^11.2.1", | ||
"@types/enzyme": "^3.10.8", | ||
@@ -37,2 +39,4 @@ "@types/enzyme-to-json": "^1.5.4", | ||
"rimraf": "^3.0.2", | ||
"rollup": "^2.45.2", | ||
"rollup-plugin-typescript2": "^0.30.0", | ||
"ts-jest": "^26.5.4", | ||
@@ -42,3 +46,3 @@ "typescript": "^4.2.4" | ||
"scripts": { | ||
"build": "rimraf dist && tsc && tsc --project ./tsconfig.esnext.json", | ||
"build": "rimraf dist && rollup -c rollup.config.ts", | ||
"watch": "rimraf dist && tsc --watch", | ||
@@ -45,0 +49,0 @@ "prepare": "npm run test && npm run build", |
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
75630
23
15
807
1