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