@mjhls/mjh-framework 1.0.44 → 1.0.45

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -25,7 +25,6 @@ var Button = _interopDefault(require('react-bootstrap/Button'));
25
25
  var router = require('next/router');
26
26
  var PropTypes = _interopDefault(require('prop-types'));
27
27
  var reactBootstrap = require('react-bootstrap');
28
- var BlockContent = _interopDefault(require('@sanity/block-content-to-react'));
29
28
 
30
29
  /*! *****************************************************************************
31
30
  Copyright (c) Microsoft Corporation. All rights reserved.
@@ -5632,39 +5631,24 @@ var AD728x90 = function AD728x90(_ref) {
5632
5631
  adUnit = _ref.adUnit,
5633
5632
  slotId = _ref.slotId,
5634
5633
  _ref$targeting = _ref.targeting,
5635
- targeting = _ref$targeting === undefined ? { desktop: {}, mobile: { post: 'mobile1' } } : _ref$targeting;
5636
-
5637
- console.log('targeting:', targeting);
5634
+ targeting = _ref$targeting === undefined ? {} : _ref$targeting;
5638
5635
 
5639
5636
  return React__default.createElement(
5640
5637
  lib_1,
5641
- { dfpNetworkId: networkID, targetingArguments: targeting.desktop, sizeMapping: [{ viewport: [1024, 768], sizes: [[728, 90]] }, { viewport: [640, 480], sizes: [[320, 50], [300, 50]] }], lazyLoad: { fetchMarginPercent: 500, renderMarginPercent: 200, mobileScaling: 2.0 } },
5642
- React__default.createElement(
5643
- main_2,
5644
- null,
5645
- React__default.createElement(
5646
- 'div',
5647
- { className: 'AD728x90' },
5648
- React__default.createElement(lib_2, {
5649
- slotId: slotId,
5650
- sizes: [[728, 90]],
5651
- adUnit: adUnit
5652
- })
5653
- )
5654
- ),
5638
+ {
5639
+ dfpNetworkId: networkID,
5640
+ targetingArguments: targeting.desktop,
5641
+ sizeMapping: [{ viewport: [768, 1], sizes: [[728, 90]] }, { viewport: [1, 1], sizes: [[320, 50], [300, 50]] }],
5642
+ lazyLoad: { fetchMarginPercent: 500, renderMarginPercent: 200, mobileScaling: 2.0 } },
5655
5643
  React__default.createElement(
5656
- main_8,
5657
- null,
5658
- React__default.createElement(
5659
- 'div',
5660
- { className: 'AD728x90' },
5661
- React__default.createElement(lib_2, {
5662
- slotId: slotId,
5663
- sizes: [[300, 50], [320, 50]],
5664
- adUnit: adUnit,
5665
- targetingArguments: targeting.mobile
5666
- })
5667
- )
5644
+ 'div',
5645
+ { className: 'AD728x90' },
5646
+ React__default.createElement(lib_2, {
5647
+ slotId: slotId,
5648
+ sizes: [[728, 90], [320, 50], [300, 50]],
5649
+ adUnit: adUnit,
5650
+ sizeMapping: [{ viewport: [768, 1], sizes: [[728, 90]] }, { viewport: [1, 1], sizes: [[320, 50], [300, 50]] }]
5651
+ })
5668
5652
  )
5669
5653
  );
5670
5654
  };
@@ -8468,6 +8452,1447 @@ var YouTubePlayer$1 = function YouTubePlayer(_ref) {
8468
8452
  return React__default.createElement(YouTube, { videoId: id, opts: { width: '100%' } });
8469
8453
  };
8470
8454
 
8455
+ /*
8456
+ object-assign
8457
+ (c) Sindre Sorhus
8458
+ @license MIT
8459
+ */
8460
+ /* eslint-disable no-unused-vars */
8461
+ var getOwnPropertySymbols = Object.getOwnPropertySymbols;
8462
+ var hasOwnProperty$5 = Object.prototype.hasOwnProperty;
8463
+ var propIsEnumerable = Object.prototype.propertyIsEnumerable;
8464
+
8465
+ function toObject(val) {
8466
+ if (val === null || val === undefined) {
8467
+ throw new TypeError('Object.assign cannot be called with null or undefined');
8468
+ }
8469
+
8470
+ return Object(val);
8471
+ }
8472
+
8473
+ function shouldUseNative() {
8474
+ try {
8475
+ if (!Object.assign) {
8476
+ return false;
8477
+ }
8478
+
8479
+ // Detect buggy property enumeration order in older V8 versions.
8480
+
8481
+ // https://bugs.chromium.org/p/v8/issues/detail?id=4118
8482
+ var test1 = new String('abc'); // eslint-disable-line no-new-wrappers
8483
+ test1[5] = 'de';
8484
+ if (Object.getOwnPropertyNames(test1)[0] === '5') {
8485
+ return false;
8486
+ }
8487
+
8488
+ // https://bugs.chromium.org/p/v8/issues/detail?id=3056
8489
+ var test2 = {};
8490
+ for (var i = 0; i < 10; i++) {
8491
+ test2['_' + String.fromCharCode(i)] = i;
8492
+ }
8493
+ var order2 = Object.getOwnPropertyNames(test2).map(function (n) {
8494
+ return test2[n];
8495
+ });
8496
+ if (order2.join('') !== '0123456789') {
8497
+ return false;
8498
+ }
8499
+
8500
+ // https://bugs.chromium.org/p/v8/issues/detail?id=3056
8501
+ var test3 = {};
8502
+ 'abcdefghijklmnopqrst'.split('').forEach(function (letter) {
8503
+ test3[letter] = letter;
8504
+ });
8505
+ if (Object.keys(Object.assign({}, test3)).join('') !==
8506
+ 'abcdefghijklmnopqrst') {
8507
+ return false;
8508
+ }
8509
+
8510
+ return true;
8511
+ } catch (err) {
8512
+ // We don't expect any of the above to throw, but better to be safe.
8513
+ return false;
8514
+ }
8515
+ }
8516
+
8517
+ var objectAssign = shouldUseNative() ? Object.assign : function (target, source) {
8518
+ var from;
8519
+ var to = toObject(target);
8520
+ var symbols;
8521
+
8522
+ for (var s = 1; s < arguments.length; s++) {
8523
+ from = Object(arguments[s]);
8524
+
8525
+ for (var key in from) {
8526
+ if (hasOwnProperty$5.call(from, key)) {
8527
+ to[key] = from[key];
8528
+ }
8529
+ }
8530
+
8531
+ if (getOwnPropertySymbols) {
8532
+ symbols = getOwnPropertySymbols(from);
8533
+ for (var i = 0; i < symbols.length; i++) {
8534
+ if (propIsEnumerable.call(from, symbols[i])) {
8535
+ to[symbols[i]] = from[symbols[i]];
8536
+ }
8537
+ }
8538
+ }
8539
+ }
8540
+
8541
+ return to;
8542
+ };
8543
+
8544
+ var baseUrl = 'https://docs.sanity.io/help/';
8545
+
8546
+ var generateHelpUrl = function generateHelpUrl(slug) {
8547
+ return baseUrl + slug
8548
+ };
8549
+
8550
+ var parseAssetId_1 = createCommonjsModule(function (module, exports) {
8551
+ Object.defineProperty(exports, "__esModule", { value: true });
8552
+ var example = 'image-Tb9Ew8CXIwaY6R1kjMvI0uRR-2000x3000-jpg';
8553
+ function parseAssetId(ref) {
8554
+ var _a = ref.split('-'), id = _a[1], dimensionString = _a[2], format = _a[3];
8555
+ if (!id || !dimensionString || !format) {
8556
+ throw new Error("Malformed asset _ref '" + ref + "'. Expected an id like \"" + example + "\".");
8557
+ }
8558
+ var _b = dimensionString.split('x'), imgWidthStr = _b[0], imgHeightStr = _b[1];
8559
+ var width = +imgWidthStr;
8560
+ var height = +imgHeightStr;
8561
+ var isValidAssetId = isFinite(width) && isFinite(height);
8562
+ if (!isValidAssetId) {
8563
+ throw new Error("Malformed asset _ref '" + ref + "'. Expected an id like \"" + example + "\".");
8564
+ }
8565
+ return { id: id, width: width, height: height, format: format };
8566
+ }
8567
+ exports.default = parseAssetId;
8568
+
8569
+ });
8570
+
8571
+ unwrapExports(parseAssetId_1);
8572
+
8573
+ var parseSource_1 = createCommonjsModule(function (module, exports) {
8574
+ var __assign = (commonjsGlobal && commonjsGlobal.__assign) || function () {
8575
+ __assign = Object.assign || function(t) {
8576
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
8577
+ s = arguments[i];
8578
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
8579
+ t[p] = s[p];
8580
+ }
8581
+ return t;
8582
+ };
8583
+ return __assign.apply(this, arguments);
8584
+ };
8585
+ Object.defineProperty(exports, "__esModule", { value: true });
8586
+ var isRef = function (src) {
8587
+ var source = src;
8588
+ return source ? typeof source._ref === 'string' : false;
8589
+ };
8590
+ var isAsset = function (src) {
8591
+ var source = src;
8592
+ return source ? typeof source._id === 'string' : false;
8593
+ };
8594
+ var isAssetStub = function (src) {
8595
+ var source = src;
8596
+ return source && source.asset ? typeof source.asset.url === 'string' : false;
8597
+ };
8598
+ // Convert an asset-id, asset or image to an image record suitable for processing
8599
+ // eslint-disable-next-line complexity
8600
+ function parseSource(source) {
8601
+ if (!source) {
8602
+ return null;
8603
+ }
8604
+ var image;
8605
+ if (typeof source === 'string' && isUrl(source)) {
8606
+ // Someone passed an existing image url?
8607
+ image = {
8608
+ asset: { _ref: urlToId(source) }
8609
+ };
8610
+ }
8611
+ else if (typeof source === 'string') {
8612
+ // Just an asset id
8613
+ image = {
8614
+ asset: { _ref: source }
8615
+ };
8616
+ }
8617
+ else if (isRef(source)) {
8618
+ // We just got passed an asset directly
8619
+ image = {
8620
+ asset: source
8621
+ };
8622
+ }
8623
+ else if (isAsset(source)) {
8624
+ // If we were passed an image asset document
8625
+ image = {
8626
+ asset: {
8627
+ _ref: source._id || ''
8628
+ }
8629
+ };
8630
+ }
8631
+ else if (isAssetStub(source)) {
8632
+ // If we were passed a partial asset (`url`, but no `_id`)
8633
+ image = {
8634
+ asset: {
8635
+ _ref: urlToId(source.asset.url)
8636
+ }
8637
+ };
8638
+ }
8639
+ else if (typeof source.asset === 'object') {
8640
+ // Probably an actual image with materialized asset
8641
+ image = source;
8642
+ }
8643
+ else {
8644
+ // We got something that does not look like an image, or it is an image
8645
+ // that currently isn't sporting an asset.
8646
+ return null;
8647
+ }
8648
+ var img = source;
8649
+ if (img.crop) {
8650
+ image.crop = img.crop;
8651
+ }
8652
+ if (img.hotspot) {
8653
+ image.hotspot = img.hotspot;
8654
+ }
8655
+ return applyDefaults(image);
8656
+ }
8657
+ exports.default = parseSource;
8658
+ function isUrl(url) {
8659
+ return /^https?:\/\//.test("" + url);
8660
+ }
8661
+ function urlToId(url) {
8662
+ var parts = url.split('/').slice(-1);
8663
+ return ("image-" + parts[0]).replace(/\.([a-z]+)$/, '-$1');
8664
+ }
8665
+ // Mock crop and hotspot if image lacks it
8666
+ function applyDefaults(image) {
8667
+ if (image.crop && image.hotspot) {
8668
+ return image;
8669
+ }
8670
+ // We need to pad in default values for crop or hotspot
8671
+ var result = __assign({}, image);
8672
+ if (!result.crop) {
8673
+ result.crop = {
8674
+ left: 0,
8675
+ top: 0,
8676
+ bottom: 0,
8677
+ right: 0
8678
+ };
8679
+ }
8680
+ if (!result.hotspot) {
8681
+ result.hotspot = {
8682
+ x: 0.5,
8683
+ y: 0.5,
8684
+ height: 1.0,
8685
+ width: 1.0
8686
+ };
8687
+ }
8688
+ return result;
8689
+ }
8690
+
8691
+ });
8692
+
8693
+ unwrapExports(parseSource_1);
8694
+
8695
+ var urlForImage_1 = createCommonjsModule(function (module, exports) {
8696
+ var __assign = (commonjsGlobal && commonjsGlobal.__assign) || function () {
8697
+ __assign = Object.assign || function(t) {
8698
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
8699
+ s = arguments[i];
8700
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
8701
+ t[p] = s[p];
8702
+ }
8703
+ return t;
8704
+ };
8705
+ return __assign.apply(this, arguments);
8706
+ };
8707
+ var __importDefault = (commonjsGlobal && commonjsGlobal.__importDefault) || function (mod) {
8708
+ return (mod && mod.__esModule) ? mod : { "default": mod };
8709
+ };
8710
+ Object.defineProperty(exports, "__esModule", { value: true });
8711
+ var parseAssetId_1$$1 = __importDefault(parseAssetId_1);
8712
+ var parseSource_1$$1 = __importDefault(parseSource_1);
8713
+ exports.parseSource = parseSource_1$$1.default;
8714
+ exports.SPEC_NAME_TO_URL_NAME_MAPPINGS = [
8715
+ ['width', 'w'],
8716
+ ['height', 'h'],
8717
+ ['format', 'fm'],
8718
+ ['download', 'dl'],
8719
+ ['blur', 'blur'],
8720
+ ['sharpen', 'sharp'],
8721
+ ['invert', 'invert'],
8722
+ ['orientation', 'or'],
8723
+ ['minHeight', 'min-h'],
8724
+ ['maxHeight', 'max-h'],
8725
+ ['minWidth', 'min-w'],
8726
+ ['maxWidth', 'max-w'],
8727
+ ['quality', 'q'],
8728
+ ['fit', 'fit'],
8729
+ ['crop', 'crop'],
8730
+ ['auto', 'auto'],
8731
+ ['dpr', 'dpr']
8732
+ ];
8733
+ function urlForImage(options) {
8734
+ var spec = __assign({}, (options || {}));
8735
+ var source = spec.source;
8736
+ delete spec.source;
8737
+ var image = parseSource_1$$1.default(source);
8738
+ if (!image) {
8739
+ return null;
8740
+ }
8741
+ var id = image.asset._ref || image.asset._id || '';
8742
+ var asset = parseAssetId_1$$1.default(id);
8743
+ // Compute crop rect in terms of pixel coordinates in the raw source image
8744
+ var cropLeft = Math.round(image.crop.left * asset.width);
8745
+ var cropTop = Math.round(image.crop.top * asset.height);
8746
+ var crop = {
8747
+ left: cropLeft,
8748
+ top: cropTop,
8749
+ width: Math.round(asset.width - image.crop.right * asset.width - cropLeft),
8750
+ height: Math.round(asset.height - image.crop.bottom * asset.height - cropTop)
8751
+ };
8752
+ // Compute hot spot rect in terms of pixel coordinates
8753
+ var hotSpotVerticalRadius = (image.hotspot.height * asset.height) / 2;
8754
+ var hotSpotHorizontalRadius = (image.hotspot.width * asset.width) / 2;
8755
+ var hotSpotCenterX = image.hotspot.x * asset.width;
8756
+ var hotSpotCenterY = image.hotspot.y * asset.height;
8757
+ var hotspot = {
8758
+ left: hotSpotCenterX - hotSpotHorizontalRadius,
8759
+ top: hotSpotCenterY - hotSpotVerticalRadius,
8760
+ right: hotSpotCenterX + hotSpotHorizontalRadius,
8761
+ bottom: hotSpotCenterY + hotSpotVerticalRadius
8762
+ };
8763
+ // If irrelevant, or if we are requested to: don't perform crop/fit based on
8764
+ // the crop/hotspot.
8765
+ if (!(spec.rect || spec.focalPoint || spec.ignoreImageParams || spec.crop)) {
8766
+ spec = __assign({}, spec, fit({ crop: crop, hotspot: hotspot }, spec));
8767
+ }
8768
+ return specToImageUrl(__assign({}, spec, { asset: asset }));
8769
+ }
8770
+ exports.default = urlForImage;
8771
+ // eslint-disable-next-line complexity
8772
+ function specToImageUrl(spec) {
8773
+ var cdnUrl = spec.baseUrl || 'https://cdn.sanity.io';
8774
+ var filename = spec.asset.id + "-" + spec.asset.width + "x" + spec.asset.height + "." + spec.asset.format;
8775
+ var baseUrl = cdnUrl + "/images/" + spec.projectId + "/" + spec.dataset + "/" + filename;
8776
+ var params = [];
8777
+ if (spec.rect) {
8778
+ // Only bother url with a crop if it actually crops anything
8779
+ var _a = spec.rect, left = _a.left, top_1 = _a.top, width = _a.width, height = _a.height;
8780
+ var isEffectiveCrop = left !== 0 || top_1 !== 0 || height !== spec.asset.height || width !== spec.asset.width;
8781
+ if (isEffectiveCrop) {
8782
+ params.push("rect=" + left + "," + top_1 + "," + width + "," + height);
8783
+ }
8784
+ }
8785
+ if (spec.bg) {
8786
+ params.push("bg=" + spec.bg);
8787
+ }
8788
+ if (spec.focalPoint) {
8789
+ params.push("fp-x=" + spec.focalPoint.x);
8790
+ params.push("fp-x=" + spec.focalPoint.y);
8791
+ }
8792
+ var flip = [spec.flipHorizontal && 'h', spec.flipVertical && 'v'].filter(Boolean).join('');
8793
+ if (flip) {
8794
+ params.push("flip=" + flip);
8795
+ }
8796
+ // Map from spec name to url param name, and allow using the actual param name as an alternative
8797
+ exports.SPEC_NAME_TO_URL_NAME_MAPPINGS.forEach(function (mapping) {
8798
+ var specName = mapping[0], param = mapping[1];
8799
+ if (typeof spec[specName] !== 'undefined') {
8800
+ params.push(param + "=" + encodeURIComponent(spec[specName]));
8801
+ }
8802
+ else if (typeof spec[param] !== 'undefined') {
8803
+ params.push(param + "=" + encodeURIComponent(spec[param]));
8804
+ }
8805
+ });
8806
+ if (params.length === 0) {
8807
+ return baseUrl;
8808
+ }
8809
+ return baseUrl + "?" + params.join('&');
8810
+ }
8811
+ function fit(source, spec) {
8812
+ var cropRect;
8813
+ var imgWidth = spec.width;
8814
+ var imgHeight = spec.height;
8815
+ // If we are not constraining the aspect ratio, we'll just use the whole crop
8816
+ if (!(imgWidth && imgHeight)) {
8817
+ return { width: imgWidth, height: imgHeight, rect: source.crop };
8818
+ }
8819
+ var crop = source.crop;
8820
+ var hotspot = source.hotspot;
8821
+ // If we are here, that means aspect ratio is locked and fitting will be a bit harder
8822
+ var desiredAspectRatio = imgWidth / imgHeight;
8823
+ var cropAspectRatio = crop.width / crop.height;
8824
+ if (cropAspectRatio > desiredAspectRatio) {
8825
+ // The crop is wider than the desired aspect ratio. That means we are cutting from the sides
8826
+ var height = crop.height;
8827
+ var width = height * desiredAspectRatio;
8828
+ var top_2 = crop.top;
8829
+ // Center output horizontally over hotspot
8830
+ var hotspotXCenter = (hotspot.right - hotspot.left) / 2 + hotspot.left;
8831
+ var left = hotspotXCenter - width / 2;
8832
+ // Keep output within crop
8833
+ if (left < crop.left) {
8834
+ left = crop.left;
8835
+ }
8836
+ else if (left + width > crop.left + crop.width) {
8837
+ left = crop.left + crop.width - width;
8838
+ }
8839
+ cropRect = {
8840
+ left: Math.round(left),
8841
+ top: Math.round(top_2),
8842
+ width: Math.round(width),
8843
+ height: Math.round(height)
8844
+ };
8845
+ }
8846
+ else {
8847
+ // The crop is taller than the desired ratio, we are cutting from top and bottom
8848
+ var width = crop.width;
8849
+ var height = width / desiredAspectRatio;
8850
+ var left = crop.left;
8851
+ // Center output vertically over hotspot
8852
+ var hotspotYCenter = (hotspot.bottom - hotspot.top) / 2 + hotspot.top;
8853
+ var top_3 = hotspotYCenter - height / 2;
8854
+ // Keep output rect within crop
8855
+ if (top_3 < crop.top) {
8856
+ top_3 = crop.top;
8857
+ }
8858
+ else if (top_3 + height > crop.top + crop.height) {
8859
+ top_3 = crop.top + crop.height - height;
8860
+ }
8861
+ cropRect = {
8862
+ left: Math.max(0, Math.floor(left)),
8863
+ top: Math.max(0, Math.floor(top_3)),
8864
+ width: Math.round(width),
8865
+ height: Math.round(height)
8866
+ };
8867
+ }
8868
+ return {
8869
+ width: imgWidth,
8870
+ height: imgHeight,
8871
+ rect: cropRect
8872
+ };
8873
+ }
8874
+
8875
+ });
8876
+
8877
+ unwrapExports(urlForImage_1);
8878
+ var urlForImage_2 = urlForImage_1.parseSource;
8879
+ var urlForImage_3 = urlForImage_1.SPEC_NAME_TO_URL_NAME_MAPPINGS;
8880
+
8881
+ var builder = createCommonjsModule(function (module, exports) {
8882
+ var __assign = (commonjsGlobal && commonjsGlobal.__assign) || function () {
8883
+ __assign = Object.assign || function(t) {
8884
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
8885
+ s = arguments[i];
8886
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
8887
+ t[p] = s[p];
8888
+ }
8889
+ return t;
8890
+ };
8891
+ return __assign.apply(this, arguments);
8892
+ };
8893
+ var __importStar = (commonjsGlobal && commonjsGlobal.__importStar) || function (mod) {
8894
+ if (mod && mod.__esModule) return mod;
8895
+ var result = {};
8896
+ if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k];
8897
+ result["default"] = mod;
8898
+ return result;
8899
+ };
8900
+ Object.defineProperty(exports, "__esModule", { value: true });
8901
+ var urlForImage_1$$1 = __importStar(urlForImage_1);
8902
+ var validFits = ['clip', 'crop', 'fill', 'fillmax', 'max', 'scale', 'min'];
8903
+ var validCrops = ['top', 'bottom', 'left', 'right', 'center', 'focalpoint', 'entropy'];
8904
+ var validAutoModes = ['format'];
8905
+ function isSanityClient(client) {
8906
+ return client ? typeof client.clientConfig === 'object' : false;
8907
+ }
8908
+ function rewriteSpecName(key) {
8909
+ var specs = urlForImage_1$$1.SPEC_NAME_TO_URL_NAME_MAPPINGS;
8910
+ for (var _i = 0, specs_1 = specs; _i < specs_1.length; _i++) {
8911
+ var entry = specs_1[_i];
8912
+ var specName = entry[0], param = entry[1];
8913
+ if (key === specName || key === param) {
8914
+ return specName;
8915
+ }
8916
+ }
8917
+ return key;
8918
+ }
8919
+ function urlBuilder(options) {
8920
+ // Did we get a SanityClient?
8921
+ var client = options;
8922
+ if (isSanityClient(client)) {
8923
+ // Inherit config from client
8924
+ var _a = client.clientConfig, apiHost = _a.apiHost, projectId = _a.projectId, dataset = _a.dataset;
8925
+ return new ImageUrlBuilder(null, {
8926
+ baseUrl: apiHost.replace(/^https:\/\/api\./, 'https://cdn.'),
8927
+ projectId: projectId,
8928
+ dataset: dataset
8929
+ });
8930
+ }
8931
+ // Or just accept the options as given
8932
+ return new ImageUrlBuilder(null, options);
8933
+ }
8934
+ exports.default = urlBuilder;
8935
+ var ImageUrlBuilder = /** @class */ (function () {
8936
+ function ImageUrlBuilder(parent, options) {
8937
+ this.options = parent
8938
+ ? __assign({}, (parent.options || {}), (options || {})) : __assign({}, (options || {})); // Copy options
8939
+ }
8940
+ ImageUrlBuilder.prototype.withOptions = function (options) {
8941
+ var baseUrl = options.baseUrl || '';
8942
+ var newOptions = { baseUrl: baseUrl };
8943
+ for (var key in options) {
8944
+ if (options.hasOwnProperty(key)) {
8945
+ var specKey = rewriteSpecName(key);
8946
+ newOptions[specKey] = options[key];
8947
+ }
8948
+ }
8949
+ return new ImageUrlBuilder(this, __assign({ baseUrl: baseUrl }, newOptions));
8950
+ };
8951
+ // The image to be represented. Accepts a Sanity 'image'-document, 'asset'-document or
8952
+ // _id of asset. To get the benefit of automatic hot-spot/crop integration with the content
8953
+ // studio, the 'image'-document must be provided.
8954
+ ImageUrlBuilder.prototype.image = function (source) {
8955
+ return this.withOptions({ source: source });
8956
+ };
8957
+ // Specify the dataset
8958
+ ImageUrlBuilder.prototype.dataset = function (dataset) {
8959
+ return this.withOptions({ dataset: dataset });
8960
+ };
8961
+ // Specify the projectId
8962
+ ImageUrlBuilder.prototype.projectId = function (projectId) {
8963
+ return this.withOptions({ projectId: projectId });
8964
+ };
8965
+ // Specify background color
8966
+ ImageUrlBuilder.prototype.bg = function (bg) {
8967
+ return this.withOptions({ bg: bg });
8968
+ };
8969
+ // Set DPR scaling factor
8970
+ ImageUrlBuilder.prototype.dpr = function (dpr) {
8971
+ return this.withOptions({ dpr: dpr });
8972
+ };
8973
+ // Specify the width of the image in pixels
8974
+ ImageUrlBuilder.prototype.width = function (width) {
8975
+ return this.withOptions({ width: width });
8976
+ };
8977
+ // Specify the height of the image in pixels
8978
+ ImageUrlBuilder.prototype.height = function (height) {
8979
+ return this.withOptions({ height: height });
8980
+ };
8981
+ // Specify focal point in fraction of image dimensions. Each component 0.0-1.0
8982
+ ImageUrlBuilder.prototype.focalPoint = function (x, y) {
8983
+ return this.withOptions({ focalPoint: { x: x, y: y } });
8984
+ };
8985
+ ImageUrlBuilder.prototype.maxWidth = function (maxWidth) {
8986
+ return this.withOptions({ maxWidth: maxWidth });
8987
+ };
8988
+ ImageUrlBuilder.prototype.minWidth = function (minWidth) {
8989
+ return this.withOptions({ minWidth: minWidth });
8990
+ };
8991
+ ImageUrlBuilder.prototype.maxHeight = function (maxHeight) {
8992
+ return this.withOptions({ maxHeight: maxHeight });
8993
+ };
8994
+ ImageUrlBuilder.prototype.minHeight = function (minHeight) {
8995
+ return this.withOptions({ minHeight: minHeight });
8996
+ };
8997
+ // Specify width and height in pixels
8998
+ ImageUrlBuilder.prototype.size = function (width, height) {
8999
+ return this.withOptions({ width: width, height: height });
9000
+ };
9001
+ // Specify blur between 0 and 100
9002
+ ImageUrlBuilder.prototype.blur = function (blur) {
9003
+ return this.withOptions({ blur: blur });
9004
+ };
9005
+ ImageUrlBuilder.prototype.sharpen = function (sharpen) {
9006
+ return this.withOptions({ sharpen: sharpen });
9007
+ };
9008
+ // Specify the desired rectangle of the image
9009
+ ImageUrlBuilder.prototype.rect = function (left, top, width, height) {
9010
+ return this.withOptions({ rect: { left: left, top: top, width: width, height: height } });
9011
+ };
9012
+ // Specify the image format of the image. 'jpg', 'pjpg', 'png', 'webp'
9013
+ ImageUrlBuilder.prototype.format = function (format) {
9014
+ return this.withOptions({ format: format });
9015
+ };
9016
+ ImageUrlBuilder.prototype.invert = function (invert) {
9017
+ return this.withOptions({ invert: invert });
9018
+ };
9019
+ // Rotation in degrees 0, 90, 180, 270
9020
+ ImageUrlBuilder.prototype.orientation = function (orientation) {
9021
+ return this.withOptions({ orientation: orientation });
9022
+ };
9023
+ // Compression quality 0-100
9024
+ ImageUrlBuilder.prototype.quality = function (quality) {
9025
+ return this.withOptions({ quality: quality });
9026
+ };
9027
+ // Make it a download link. Parameter is default filename.
9028
+ ImageUrlBuilder.prototype.forceDownload = function (download) {
9029
+ return this.withOptions({ download: download });
9030
+ };
9031
+ // Flip image horizontally
9032
+ ImageUrlBuilder.prototype.flipHorizontal = function () {
9033
+ return this.withOptions({ flipHorizontal: true });
9034
+ };
9035
+ // Flip image verically
9036
+ ImageUrlBuilder.prototype.flipVertical = function () {
9037
+ return this.withOptions({ flipVertical: true });
9038
+ };
9039
+ // Ignore crop/hotspot from image record, even when present
9040
+ ImageUrlBuilder.prototype.ignoreImageParams = function () {
9041
+ return this.withOptions({ ignoreImageParams: true });
9042
+ };
9043
+ ImageUrlBuilder.prototype.fit = function (value) {
9044
+ if (validFits.indexOf(value) === -1) {
9045
+ throw new Error("Invalid fit mode \"" + value + "\"");
9046
+ }
9047
+ return this.withOptions({ fit: value });
9048
+ };
9049
+ ImageUrlBuilder.prototype.crop = function (value) {
9050
+ if (validCrops.indexOf(value) === -1) {
9051
+ throw new Error("Invalid crop mode \"" + value + "\"");
9052
+ }
9053
+ return this.withOptions({ crop: value });
9054
+ };
9055
+ ImageUrlBuilder.prototype.auto = function (value) {
9056
+ if (validAutoModes.indexOf(value) === -1) {
9057
+ throw new Error("Invalid auto mode \"" + value + "\"");
9058
+ }
9059
+ return this.withOptions({ auto: value });
9060
+ };
9061
+ // Gets the url based on the submitted parameters
9062
+ ImageUrlBuilder.prototype.url = function () {
9063
+ return urlForImage_1$$1.default(this.options);
9064
+ };
9065
+ // Synonym for url()
9066
+ ImageUrlBuilder.prototype.toString = function () {
9067
+ return this.url();
9068
+ };
9069
+ return ImageUrlBuilder;
9070
+ }());
9071
+
9072
+ });
9073
+
9074
+ unwrapExports(builder);
9075
+
9076
+ var node$1 = createCommonjsModule(function (module) {
9077
+ var __importDefault = (commonjsGlobal && commonjsGlobal.__importDefault) || function (mod) {
9078
+ return (mod && mod.__esModule) ? mod : { "default": mod };
9079
+ };
9080
+ var builder_1 = __importDefault(builder);
9081
+ module.exports = builder_1.default;
9082
+
9083
+ });
9084
+
9085
+ unwrapExports(node$1);
9086
+
9087
+ var enc = encodeURIComponent;
9088
+ var materializeError = "You must either:\n - Pass `projectId` and `dataset` to the block renderer\n - Materialize images to include the `url` field.\n\nFor more information, see ".concat(generateHelpUrl('block-content-image-materializing'));
9089
+
9090
+ var getQueryString = function getQueryString(options) {
9091
+ var query = options.imageOptions;
9092
+ var keys = Object.keys(query);
9093
+
9094
+ if (!keys.length) {
9095
+ return '';
9096
+ }
9097
+
9098
+ var params = keys.map(function (key) {
9099
+ return "".concat(enc(key), "=").concat(enc(query[key]));
9100
+ });
9101
+ return "?".concat(params.join('&'));
9102
+ };
9103
+
9104
+ var buildUrl = function buildUrl(props) {
9105
+ var node = props.node,
9106
+ options = props.options;
9107
+ var projectId = options.projectId,
9108
+ dataset = options.dataset;
9109
+ var asset = node.asset;
9110
+
9111
+ if (!asset) {
9112
+ throw new Error('Image does not have required `asset` property');
9113
+ }
9114
+
9115
+ if (asset.url) {
9116
+ return asset.url + getQueryString(options);
9117
+ }
9118
+
9119
+ if (!projectId || !dataset) {
9120
+ throw new Error(materializeError);
9121
+ }
9122
+
9123
+ var ref = asset._ref;
9124
+
9125
+ if (!ref) {
9126
+ throw new Error('Invalid image reference in block, no `_ref` found on `asset`');
9127
+ }
9128
+
9129
+ return node$1(objectAssign({
9130
+ projectId: projectId,
9131
+ dataset: dataset
9132
+ }, options.imageOptions || {})).image(node).toString();
9133
+ };
9134
+
9135
+ var getImageUrl = buildUrl;
9136
+
9137
+ var serializers = function (h, serializerOpts) {
9138
+ var serializeOptions = serializerOpts || {
9139
+ useDashedStyles: false // Low-level block serializer
9140
+
9141
+ };
9142
+
9143
+ function BlockSerializer(props) {
9144
+ var node = props.node,
9145
+ serializers = props.serializers,
9146
+ options = props.options,
9147
+ isInline = props.isInline,
9148
+ children = props.children;
9149
+ var blockType = node._type;
9150
+ var serializer = serializers.types[blockType];
9151
+
9152
+ if (!serializer) {
9153
+ throw new Error("Unknown block type \"".concat(blockType, "\", please specify a serializer for it in the `serializers.types` prop"));
9154
+ }
9155
+
9156
+ return h(serializer, {
9157
+ node: node,
9158
+ options: options,
9159
+ isInline: isInline
9160
+ }, children);
9161
+ } // Low-level span serializer
9162
+
9163
+
9164
+ function SpanSerializer(props) {
9165
+ var _props$node = props.node,
9166
+ mark = _props$node.mark,
9167
+ children = _props$node.children;
9168
+ var isPlain = typeof mark === 'string';
9169
+ var markType = isPlain ? mark : mark._type;
9170
+ var serializer = props.serializers.marks[markType];
9171
+
9172
+ if (!serializer) {
9173
+ // @todo Revert back to throwing errors?
9174
+ // eslint-disable-next-line no-console
9175
+ console.warn("Unknown mark type \"".concat(markType, "\", please specify a serializer for it in the `serializers.marks` prop"));
9176
+ return h(props.serializers.markFallback, null, children);
9177
+ }
9178
+
9179
+ return h(serializer, props.node, children);
9180
+ } // Low-level list serializer
9181
+
9182
+
9183
+ function ListSerializer(props) {
9184
+ var tag = props.type === 'bullet' ? 'ul' : 'ol';
9185
+ return h(tag, null, props.children);
9186
+ } // Low-level list item serializer
9187
+
9188
+
9189
+ function ListItemSerializer(props) {
9190
+ var children = !props.node.style || props.node.style === 'normal' ? // Don't wrap plain text in paragraphs inside of a list item
9191
+ props.children : // But wrap any other style in whatever the block serializer says to use
9192
+ h(props.serializers.types.block, props, props.children);
9193
+ return h('li', null, children);
9194
+ } // Renderer of an actual block of type `block`. Confusing, we know.
9195
+
9196
+
9197
+ function BlockTypeSerializer(props) {
9198
+ var style = props.node.style || 'normal';
9199
+
9200
+ if (/^h\d/.test(style)) {
9201
+ return h(style, null, props.children);
9202
+ }
9203
+
9204
+ return style === 'blockquote' ? h('blockquote', null, props.children) : h('p', null, props.children);
9205
+ } // Serializers for things that can be directly attributed to a tag without any props
9206
+ // We use partial application to do this, passing the tag name as the first argument
9207
+
9208
+
9209
+ function RawMarkSerializer(tag, props) {
9210
+ return h(tag, null, props.children);
9211
+ }
9212
+
9213
+ function UnderlineSerializer(props) {
9214
+ var style = serializeOptions.useDashedStyles ? {
9215
+ 'text-decoration': 'underline'
9216
+ } : {
9217
+ textDecoration: 'underline'
9218
+ };
9219
+ return h('span', {
9220
+ style: style
9221
+ }, props.children);
9222
+ }
9223
+
9224
+ function StrikeThroughSerializer(props) {
9225
+ return h('del', null, props.children);
9226
+ }
9227
+
9228
+ function LinkSerializer(props) {
9229
+ return h('a', {
9230
+ href: props.mark.href
9231
+ }, props.children);
9232
+ }
9233
+
9234
+ function ImageSerializer(props) {
9235
+ if (!props.node.asset) {
9236
+ return null;
9237
+ }
9238
+
9239
+ var img = h('img', {
9240
+ src: getImageUrl(props)
9241
+ });
9242
+ return props.isInline ? img : h('figure', null, img);
9243
+ } // Serializer that recursively calls itself, producing a hyperscript tree of spans
9244
+
9245
+
9246
+ function serializeSpan(span, serializers, index, options) {
9247
+ if (span === '\n' && serializers.hardBreak) {
9248
+ return h(serializers.hardBreak, {
9249
+ key: "hb-".concat(index)
9250
+ });
9251
+ }
9252
+
9253
+ if (typeof span === 'string') {
9254
+ return serializers.text ? h(serializers.text, {
9255
+ key: "text-".concat(index)
9256
+ }, span) : span;
9257
+ }
9258
+
9259
+ var children;
9260
+
9261
+ if (span.children) {
9262
+ children = {
9263
+ children: span.children.map(function (child, i) {
9264
+ return options.serializeNode(child, i, span.children, true);
9265
+ })
9266
+ };
9267
+ }
9268
+
9269
+ var serializedNode = objectAssign({}, span, children);
9270
+ return h(serializers.span, {
9271
+ key: span._key || "span-".concat(index),
9272
+ node: serializedNode,
9273
+ serializers: serializers
9274
+ });
9275
+ }
9276
+
9277
+ var HardBreakSerializer = function HardBreakSerializer() {
9278
+ return h('br');
9279
+ };
9280
+
9281
+ var defaultMarkSerializers = {
9282
+ strong: RawMarkSerializer.bind(null, 'strong'),
9283
+ em: RawMarkSerializer.bind(null, 'em'),
9284
+ code: RawMarkSerializer.bind(null, 'code'),
9285
+ underline: UnderlineSerializer,
9286
+ 'strike-through': StrikeThroughSerializer,
9287
+ link: LinkSerializer
9288
+ };
9289
+ var defaultSerializers = {
9290
+ // Common overrides
9291
+ types: {
9292
+ block: BlockTypeSerializer,
9293
+ image: ImageSerializer
9294
+ },
9295
+ marks: defaultMarkSerializers,
9296
+ // Less common overrides
9297
+ list: ListSerializer,
9298
+ listItem: ListItemSerializer,
9299
+ block: BlockSerializer,
9300
+ span: SpanSerializer,
9301
+ hardBreak: HardBreakSerializer,
9302
+ // Container element
9303
+ container: 'div',
9304
+ // When we can't resolve the mark properly, use this renderer as the container
9305
+ markFallback: 'span',
9306
+ // Allow overriding text renderer, but leave undefined to just use plain strings by default
9307
+ text: undefined,
9308
+ // Empty nodes (React uses null, hyperscript with empty strings)
9309
+ empty: ''
9310
+ };
9311
+ return {
9312
+ defaultSerializers: defaultSerializers,
9313
+ serializeSpan: serializeSpan
9314
+ };
9315
+ };
9316
+
9317
+ var defaultMarks = ['strong', 'em', 'code', 'underline', 'strike-through'];
9318
+
9319
+ var buildMarksTree = function buildMarksTree(block) {
9320
+ var children = block.children,
9321
+ markDefs = block.markDefs;
9322
+
9323
+ if (!children || !children.length) {
9324
+ return [];
9325
+ }
9326
+
9327
+ var sortedMarks = children.map(sortMarksByOccurences);
9328
+ var rootNode = {
9329
+ _type: 'span',
9330
+ children: []
9331
+ };
9332
+ var nodeStack = [rootNode];
9333
+ children.forEach(function (span, i) {
9334
+ var marksNeeded = sortedMarks[i];
9335
+
9336
+ if (!marksNeeded) {
9337
+ var lastNode = nodeStack[nodeStack.length - 1];
9338
+ lastNode.children.push(span);
9339
+ return;
9340
+ }
9341
+
9342
+ var pos = 1; // Start at position one. Root is always plain and should never be removed. (?)
9343
+
9344
+ if (nodeStack.length > 1) {
9345
+ for (pos; pos < nodeStack.length; pos++) {
9346
+ var mark = nodeStack[pos].markKey;
9347
+ var index = marksNeeded.indexOf(mark); // eslint-disable-next-line max-depth
9348
+
9349
+ if (index === -1) {
9350
+ break;
9351
+ }
9352
+
9353
+ marksNeeded.splice(index, 1);
9354
+ }
9355
+ } // Keep from beginning to first miss
9356
+
9357
+
9358
+ nodeStack = nodeStack.slice(0, pos); // Add needed nodes
9359
+
9360
+ var currentNode = findLastParentNode(nodeStack);
9361
+ marksNeeded.forEach(function (mark) {
9362
+ var node = {
9363
+ _type: 'span',
9364
+ _key: span._key,
9365
+ children: [],
9366
+ mark: markDefs.find(function (def) {
9367
+ return def._key === mark;
9368
+ }) || mark,
9369
+ markKey: mark
9370
+ };
9371
+ currentNode.children.push(node);
9372
+ nodeStack.push(node);
9373
+ currentNode = node;
9374
+ }); // Split at newlines to make individual line chunks, but keep newline
9375
+ // characters as individual elements in the array. We use these characters
9376
+ // in the span serializer to trigger hard-break rendering
9377
+
9378
+ if (isTextSpan(span)) {
9379
+ var lines = span.text.split('\n');
9380
+
9381
+ for (var line = lines.length; line-- > 1;) {
9382
+ lines.splice(line, 0, '\n');
9383
+ }
9384
+
9385
+ currentNode.children = currentNode.children.concat(lines);
9386
+ } else {
9387
+ currentNode.children = currentNode.children.concat(span);
9388
+ }
9389
+ });
9390
+ return rootNode.children;
9391
+ }; // We want to sort all the marks of all the spans in the following order:
9392
+ // 1. Marks that are shared amongst the most adjacent siblings
9393
+ // 2. Non-default marks (links, custom metadata)
9394
+ // 3. Built-in, plain marks (bold, emphasis, code etc)
9395
+
9396
+
9397
+ function sortMarksByOccurences(span, i, spans) {
9398
+ if (!span.marks || span.marks.length === 0) {
9399
+ return span.marks || [];
9400
+ }
9401
+
9402
+ var markOccurences = span.marks.reduce(function (occurences, mark) {
9403
+ occurences[mark] = occurences[mark] ? occurences[mark] + 1 : 1;
9404
+
9405
+ for (var siblingIndex = i + 1; siblingIndex < spans.length; siblingIndex++) {
9406
+ var sibling = spans[siblingIndex];
9407
+
9408
+ if (sibling.marks && Array.isArray(sibling.marks) && sibling.marks.indexOf(mark) !== -1) {
9409
+ occurences[mark]++;
9410
+ } else {
9411
+ break;
9412
+ }
9413
+ }
9414
+
9415
+ return occurences;
9416
+ }, {});
9417
+ var sortByOccurence = sortMarks.bind(null, markOccurences); // Slicing because sort() mutates the input
9418
+
9419
+ return span.marks.slice().sort(sortByOccurence);
9420
+ }
9421
+
9422
+ function sortMarks(occurences, markA, markB) {
9423
+ var aOccurences = occurences[markA] || 0;
9424
+ var bOccurences = occurences[markB] || 0;
9425
+
9426
+ if (aOccurences !== bOccurences) {
9427
+ return bOccurences - aOccurences;
9428
+ }
9429
+
9430
+ var aDefaultPos = defaultMarks.indexOf(markA);
9431
+ var bDefaultPos = defaultMarks.indexOf(markB); // Sort default marks last
9432
+
9433
+ if (aDefaultPos !== bDefaultPos) {
9434
+ return aDefaultPos - bDefaultPos;
9435
+ } // Sort other marks simply by key
9436
+
9437
+
9438
+ if (markA < markB) {
9439
+ return -1;
9440
+ } else if (markA > markB) {
9441
+ return 1;
9442
+ }
9443
+
9444
+ return 0;
9445
+ }
9446
+
9447
+ function isTextSpan(node) {
9448
+ return node._type === 'span' && typeof node.text === 'string' && (Array.isArray(node.marks) || typeof node.marks === 'undefined');
9449
+ }
9450
+
9451
+ function findLastParentNode(nodes) {
9452
+ for (var i = nodes.length - 1; i >= 0; i--) {
9453
+ var node = nodes[i];
9454
+
9455
+ if (node._type === 'span' && node.children) {
9456
+ return node;
9457
+ }
9458
+ }
9459
+
9460
+ return undefined;
9461
+ }
9462
+
9463
+ var buildMarksTree_1 = buildMarksTree;
9464
+
9465
+ /* eslint-disable max-depth, complexity */
9466
+
9467
+
9468
+ function nestLists(blocks) {
9469
+ var mode = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 'html';
9470
+ var tree = [];
9471
+ var currentList;
9472
+
9473
+ for (var i = 0; i < blocks.length; i++) {
9474
+ var block = blocks[i];
9475
+
9476
+ if (!isListBlock(block)) {
9477
+ tree.push(block);
9478
+ currentList = null;
9479
+ continue;
9480
+ } // Start of a new list?
9481
+
9482
+
9483
+ if (!currentList) {
9484
+ currentList = listFromBlock(block);
9485
+ tree.push(currentList);
9486
+ continue;
9487
+ } // New list item within same list?
9488
+
9489
+
9490
+ if (blockMatchesList(block, currentList)) {
9491
+ currentList.children.push(block);
9492
+ continue;
9493
+ } // Different list props, are we going deeper?
9494
+
9495
+
9496
+ if (block.level > currentList.level) {
9497
+ var newList = listFromBlock(block);
9498
+
9499
+ if (mode === 'html') {
9500
+ // Because HTML is kinda weird, nested lists needs to be nested within list items
9501
+ // So while you would think that we could populate the parent list with a new sub-list,
9502
+ // We actually have to target the last list element (child) of the parent.
9503
+ // However, at this point we need to be very careful - simply pushing to the list of children
9504
+ // will mutate the input, and we don't want to blindly clone the entire tree.
9505
+ // Clone the last child while adding our new list as the last child of it
9506
+ var lastListItem = lastChild(currentList);
9507
+ var newLastChild = objectAssign({}, lastListItem, {
9508
+ children: lastListItem.children.concat(newList)
9509
+ }); // Swap the last child
9510
+
9511
+ currentList.children[currentList.children.length - 1] = newLastChild;
9512
+ } else {
9513
+ currentList.children.push(newList);
9514
+ } // Set the newly created, deeper list as the current
9515
+
9516
+
9517
+ currentList = newList;
9518
+ continue;
9519
+ } // Different list props, are we going back up the tree?
9520
+
9521
+
9522
+ if (block.level < currentList.level) {
9523
+ // Current list has ended, and we need to hook up with a parent of the same level and type
9524
+ var match = findListMatching(tree[tree.length - 1], block);
9525
+
9526
+ if (match) {
9527
+ currentList = match;
9528
+ currentList.children.push(block);
9529
+ continue;
9530
+ } // Similar parent can't be found, assume new list
9531
+
9532
+
9533
+ currentList = listFromBlock(block);
9534
+ tree.push(currentList);
9535
+ continue;
9536
+ } // Different list props, different list style?
9537
+
9538
+
9539
+ if (block.listItem !== currentList.listItem) {
9540
+ var _match = findListMatching(tree[tree.length - 1], {
9541
+ level: block.level
9542
+ });
9543
+
9544
+ if (_match && _match.listItem === block.listItem) {
9545
+ currentList = _match;
9546
+ currentList.children.push(block);
9547
+ continue;
9548
+ } else {
9549
+ currentList = listFromBlock(block);
9550
+ tree.push(currentList);
9551
+ continue;
9552
+ }
9553
+ } // eslint-disable-next-line no-console
9554
+
9555
+
9556
+ console.warn('Unknown state encountered for block', block);
9557
+ tree.push(block);
9558
+ }
9559
+
9560
+ return tree;
9561
+ }
9562
+
9563
+ function isListBlock(block) {
9564
+ return Boolean(block.listItem);
9565
+ }
9566
+
9567
+ function blockMatchesList(block, list) {
9568
+ return block.level === list.level && block.listItem === list.listItem;
9569
+ }
9570
+
9571
+ function listFromBlock(block) {
9572
+ return {
9573
+ _type: 'list',
9574
+ _key: "".concat(block._key, "-parent"),
9575
+ level: block.level,
9576
+ listItem: block.listItem,
9577
+ children: [block]
9578
+ };
9579
+ }
9580
+
9581
+ function lastChild(block) {
9582
+ return block.children && block.children[block.children.length - 1];
9583
+ }
9584
+
9585
+ function findListMatching(rootNode, matching) {
9586
+ var filterOnType = typeof matching.listItem === 'string';
9587
+
9588
+ if (rootNode._type === 'list' && rootNode.level === matching.level && filterOnType && rootNode.listItem === matching.listItem) {
9589
+ return rootNode;
9590
+ }
9591
+
9592
+ var node = lastChild(rootNode);
9593
+
9594
+ if (!node) {
9595
+ return false;
9596
+ }
9597
+
9598
+ return findListMatching(node, matching);
9599
+ }
9600
+
9601
+ var nestLists_1 = nestLists;
9602
+
9603
+ var generateKeys = function (blocks) {
9604
+ return blocks.map(function (block) {
9605
+ if (block._key) {
9606
+ return block;
9607
+ }
9608
+
9609
+ return objectAssign({
9610
+ _key: getStaticKey(block)
9611
+ }, block);
9612
+ });
9613
+ };
9614
+
9615
+ function getStaticKey(item) {
9616
+ return checksum(JSON.stringify(item)).toString(36).replace(/[^A-Za-z0-9]/g, '');
9617
+ }
9618
+ /* eslint-disable no-bitwise */
9619
+
9620
+
9621
+ function checksum(str) {
9622
+ var hash = 0;
9623
+ var strlen = str.length;
9624
+
9625
+ if (strlen === 0) {
9626
+ return hash;
9627
+ }
9628
+
9629
+ for (var i = 0; i < strlen; i++) {
9630
+ hash = (hash << 5) - hash + str.charCodeAt(i);
9631
+ hash &= hash; // Convert to 32bit integer
9632
+ }
9633
+
9634
+ return hash;
9635
+ }
9636
+
9637
+ function _typeof$1(obj) { if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof$1 = function _typeof(obj) { return typeof obj; }; } else { _typeof$1 = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof$1(obj); }
9638
+
9639
+
9640
+
9641
+ var isDefined = function isDefined(val) {
9642
+ return typeof val !== 'undefined';
9643
+ }; // Recursively merge/replace default serializers with user-specified serializers
9644
+
9645
+
9646
+ var mergeSerializers = function mergeSerializers(defaultSerializers, userSerializers) {
9647
+ return Object.keys(defaultSerializers).reduce(function (acc, key) {
9648
+ var type = _typeof$1(defaultSerializers[key]);
9649
+
9650
+ if (type === 'function') {
9651
+ acc[key] = isDefined(userSerializers[key]) ? userSerializers[key] : defaultSerializers[key];
9652
+ } else if (type === 'object') {
9653
+ acc[key] = objectAssign({}, defaultSerializers[key], userSerializers[key]);
9654
+ } else {
9655
+ acc[key] = typeof userSerializers[key] === 'undefined' ? defaultSerializers[key] : userSerializers[key];
9656
+ }
9657
+
9658
+ return acc;
9659
+ }, {});
9660
+ };
9661
+
9662
+ // Properties to extract from props and pass to serializers as options
9663
+
9664
+
9665
+ var optionProps = ['projectId', 'dataset', 'imageOptions'];
9666
+
9667
+ var isDefined$1 = function isDefined(val) {
9668
+ return typeof val !== 'undefined';
9669
+ };
9670
+
9671
+ var defaults$1 = {
9672
+ imageOptions: {}
9673
+ };
9674
+
9675
+ function blocksToNodes(h, properties, defaultSerializers, serializeSpan) {
9676
+ var props = objectAssign({}, defaults$1, properties);
9677
+ var rawBlocks = Array.isArray(props.blocks) ? props.blocks : [props.blocks];
9678
+ var keyedBlocks = generateKeys(rawBlocks);
9679
+ var blocks = nestLists_1(keyedBlocks, props.listNestMode);
9680
+ var serializers = mergeSerializers(defaultSerializers, props.serializers || {});
9681
+ var options = optionProps.reduce(function (opts, key) {
9682
+ var value = props[key];
9683
+
9684
+ if (isDefined$1(value)) {
9685
+ opts[key] = value;
9686
+ }
9687
+
9688
+ return opts;
9689
+ }, {});
9690
+
9691
+ function serializeNode(node, index, siblings, isInline) {
9692
+ if (isList(node)) {
9693
+ return serializeList(node);
9694
+ }
9695
+
9696
+ if (isListItem(node)) {
9697
+ return serializeListItem(node, findListItemIndex(node, siblings));
9698
+ }
9699
+
9700
+ if (isSpan(node)) {
9701
+ return serializeSpan(node, serializers, index, {
9702
+ serializeNode: serializeNode
9703
+ });
9704
+ }
9705
+
9706
+ return serializeBlock(node, index, isInline);
9707
+ }
9708
+
9709
+ function findListItemIndex(node, siblings) {
9710
+ var index = 0;
9711
+
9712
+ for (var i = 0; i < siblings.length; i++) {
9713
+ if (siblings[i] === node) {
9714
+ return index;
9715
+ }
9716
+
9717
+ if (!isListItem(siblings[i])) {
9718
+ continue;
9719
+ }
9720
+
9721
+ index++;
9722
+ }
9723
+
9724
+ return index;
9725
+ }
9726
+
9727
+ function serializeBlock(block, index, isInline) {
9728
+ var tree = buildMarksTree_1(block);
9729
+ var children = tree.map(function (node, i, siblings) {
9730
+ return serializeNode(node, i, siblings, true);
9731
+ });
9732
+ var blockProps = {
9733
+ key: block._key || "block-".concat(index),
9734
+ node: block,
9735
+ isInline: isInline,
9736
+ serializers: serializers,
9737
+ options: options
9738
+ };
9739
+ return h(serializers.block, blockProps, children);
9740
+ }
9741
+
9742
+ function serializeListItem(block, index) {
9743
+ var key = block._key;
9744
+ var tree = buildMarksTree_1(block);
9745
+ var children = tree.map(serializeNode);
9746
+ return h(serializers.listItem, {
9747
+ node: block,
9748
+ serializers: serializers,
9749
+ index: index,
9750
+ key: key,
9751
+ options: options
9752
+ }, children);
9753
+ }
9754
+
9755
+ function serializeList(list) {
9756
+ var type = list.listItem;
9757
+ var level = list.level;
9758
+ var key = list._key;
9759
+ var children = list.children.map(serializeNode);
9760
+ return h(serializers.list, {
9761
+ key: key,
9762
+ level: level,
9763
+ type: type,
9764
+ options: options
9765
+ }, children);
9766
+ } // Default to false, so `undefined` will evaluate to the default here
9767
+
9768
+
9769
+ var renderContainerOnSingleChild = Boolean(props.renderContainerOnSingleChild);
9770
+ var nodes = blocks.map(serializeNode);
9771
+
9772
+ if (renderContainerOnSingleChild || nodes.length > 1) {
9773
+ var containerProps = props.className ? {
9774
+ className: props.className
9775
+ } : {};
9776
+ return h(serializers.container, containerProps, nodes);
9777
+ }
9778
+
9779
+ if (nodes[0]) {
9780
+ return nodes[0];
9781
+ }
9782
+
9783
+ return typeof serializers.empty === 'function' ? h(serializers.empty) : serializers.empty;
9784
+ }
9785
+
9786
+ function isList(block) {
9787
+ return block._type === 'list' && block.listItem;
9788
+ }
9789
+
9790
+ function isListItem(block) {
9791
+ return block._type === 'block' && block.listItem;
9792
+ }
9793
+
9794
+ function isSpan(block) {
9795
+ return typeof block === 'string' || block.marks || block._type === 'span';
9796
+ }
9797
+
9798
+ var blocksToNodes_1 = blocksToNodes;
9799
+
9800
+ var internals = {
9801
+ blocksToNodes: function blocksToNodes(renderNode, props, defaultSerializers, serializeSpan) {
9802
+ if (defaultSerializers) {
9803
+ return blocksToNodes_1(renderNode, props, defaultSerializers, serializeSpan);
9804
+ } // Backwards-compatibility
9805
+
9806
+
9807
+ var serializers$$1 = serializers(renderNode);
9808
+ return blocksToNodes_1(renderNode, props, serializers$$1.defaultSerializers, serializers$$1.serializeSpan);
9809
+ },
9810
+ getSerializers: serializers,
9811
+ getImageUrl: getImageUrl,
9812
+ mergeSerializers: mergeSerializers
9813
+ };
9814
+
9815
+ var internals$1 = internals;
9816
+
9817
+ var getSerializers = internals$1.getSerializers;
9818
+
9819
+ var renderNode = React__default.createElement;
9820
+
9821
+ var _getSerializers = getSerializers(renderNode),
9822
+ defaultSerializers = _getSerializers.defaultSerializers,
9823
+ serializeSpan = _getSerializers.serializeSpan;
9824
+
9825
+ var dom = {
9826
+ serializeSpan: serializeSpan,
9827
+ serializers: defaultSerializers,
9828
+ renderProps: { nestMarks: true }
9829
+ };
9830
+
9831
+ var serializers$1 = dom.serializers,
9832
+ serializeSpan$1 = dom.serializeSpan,
9833
+ renderProps = dom.renderProps;
9834
+
9835
+ var getImageUrl$1 = internals$1.getImageUrl,
9836
+ blocksToNodes$1 = internals$1.blocksToNodes,
9837
+ mergeSerializers$1 = internals$1.mergeSerializers;
9838
+
9839
+ var renderNode$1 = React__default.createElement;
9840
+
9841
+ var SanityBlockContent = function SanityBlockContent(props) {
9842
+ var customSerializers = mergeSerializers$1(SanityBlockContent.defaultSerializers, props.serializers);
9843
+
9844
+ var blockProps = Object.assign({}, renderProps, props, {
9845
+ serializers: customSerializers,
9846
+ blocks: props.blocks || []
9847
+ });
9848
+
9849
+ return blocksToNodes$1(renderNode$1, blockProps, serializers$1, serializeSpan$1);
9850
+ };
9851
+
9852
+ // Expose default serializers to the user
9853
+ SanityBlockContent.defaultSerializers = serializers$1;
9854
+
9855
+ // Expose logic for building image URLs from an image reference/node
9856
+ SanityBlockContent.getImageUrl = getImageUrl$1;
9857
+
9858
+ SanityBlockContent.propTypes = {
9859
+ className: PropTypes.string,
9860
+ renderContainerOnSingleChild: PropTypes.bool,
9861
+
9862
+ // When rendering images, we need project id and dataset, unless images are materialized
9863
+ projectId: PropTypes.string,
9864
+ dataset: PropTypes.string,
9865
+ imageOptions: PropTypes.object,
9866
+
9867
+ serializers: PropTypes.shape({
9868
+ // Common overrides
9869
+ types: PropTypes.object,
9870
+ marks: PropTypes.object,
9871
+
9872
+ // Less common overrides
9873
+ list: PropTypes.func,
9874
+ listItem: PropTypes.func,
9875
+
9876
+ // Low-level serializers
9877
+ block: PropTypes.func,
9878
+ span: PropTypes.func
9879
+ }),
9880
+
9881
+ blocks: PropTypes.oneOfType([PropTypes.arrayOf(PropTypes.shape({
9882
+ _type: PropTypes.string.isRequired
9883
+ })), PropTypes.shape({
9884
+ _type: PropTypes.string.isRequired
9885
+ })]).isRequired
9886
+ };
9887
+
9888
+ SanityBlockContent.defaultProps = {
9889
+ renderContainerOnSingleChild: false,
9890
+ serializers: {},
9891
+ imageOptions: {}
9892
+ };
9893
+
9894
+ var BlockContent = SanityBlockContent;
9895
+
8471
9896
  var Sidebar = function Sidebar(_ref) {
8472
9897
  var caption = _ref.caption,
8473
9898
  content = _ref.content;
@@ -8488,7 +9913,7 @@ var Sidebar = function Sidebar(_ref) {
8488
9913
  );
8489
9914
  };
8490
9915
 
8491
- var getSerializers = function getSerializers(client) {
9916
+ var getSerializers$1 = function getSerializers(client) {
8492
9917
  return {
8493
9918
  types: {
8494
9919
  youtube: function youtube(_ref) {
@@ -8539,6 +9964,6 @@ exports.TemplateNormal = TemplateNormal;
8539
9964
  exports.AD300x250 = AD300x250;
8540
9965
  exports.AD300x250x600 = AD300x250x600;
8541
9966
  exports.AD728x90 = AD728x90;
8542
- exports.getSerializers = getSerializers;
9967
+ exports.getSerializers = getSerializers$1;
8543
9968
  exports.Search = Search$1;
8544
9969
  //# sourceMappingURL=index.js.map