@prismicio/types-internal 2.4.0-alpha.4 → 2.4.0-alpha.6

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.
@@ -119,42 +119,39 @@ function traverseSharedSliceContent({ path, sliceKey, sliceName, model, content,
119
119
  const primary = Object.entries(content.widget.primary).reduce((acc, [fieldKey, fieldContent]) => {
120
120
  var _a, _b;
121
121
  const fieldDef = (_b = (_a = model === null || model === void 0 ? void 0 : model.fields) === null || _a === void 0 ? void 0 : _a.primary) === null || _b === void 0 ? void 0 : _b[fieldKey];
122
- if ((0, GroupContent_1.isGroupContent)(fieldContent) && (fieldDef === null || fieldDef === void 0 ? void 0 : fieldDef.type) === customtypes_1.GroupFieldType) {
123
- const transformedGroupField = (0, GroupContent_1.traverseGroupContent)({
124
- path: path.concat([
125
- { key: "primary", type: "primary" },
126
- { key: fieldKey, type: "Widget" },
127
- ]),
128
- key: fieldKey,
129
- apiId: sliceName,
130
- content: fieldContent,
131
- model: fieldDef,
132
- })(transformWidget);
133
- // Can happen if the transform function returns undefined to filter out a field
134
- if (!transformedGroupField)
135
- return acc;
136
- return {
137
- ...acc,
138
- [fieldKey]: transformedGroupField,
139
- };
140
- }
141
- const transformedField = transformWidget({
142
- path: path.concat([
143
- { key: "primary", type: "primary" },
144
- { key: fieldKey, type: "Widget" },
145
- ]),
146
- key: fieldKey,
147
- apiId: sliceName,
148
- model: fieldDef,
149
- content: fieldContent,
150
- });
122
+ const transformedField = (() => {
123
+ if ((0, GroupContent_1.isGroupContent)(fieldContent) && (fieldDef === null || fieldDef === void 0 ? void 0 : fieldDef.type) === customtypes_1.GroupFieldType) {
124
+ return (0, GroupContent_1.traverseGroupContent)({
125
+ path: path.concat([
126
+ { key: "primary", type: "primary" },
127
+ { key: fieldKey, type: "Widget" },
128
+ ]),
129
+ key: fieldKey,
130
+ apiId: fieldKey,
131
+ content: fieldContent,
132
+ model: fieldDef,
133
+ })(transformWidget);
134
+ }
135
+ else if ((0, nestable_1.isNestableContent)(fieldContent)) {
136
+ return transformWidget({
137
+ path: path.concat([
138
+ { key: "primary", type: "primary" },
139
+ { key: fieldKey, type: "Widget" },
140
+ ]),
141
+ key: fieldKey,
142
+ apiId: fieldKey,
143
+ model: fieldDef,
144
+ content: fieldContent,
145
+ });
146
+ }
147
+ else {
148
+ console.warn(`Warn: Non nestable content or group (content and model) with key [${fieldKey}] detected in a shared slice [${sliceName}] with key [${sliceKey}]`);
149
+ return;
150
+ }
151
+ })();
151
152
  // Can happen if the transform function returns undefined to filter out a field
152
153
  if (!transformedField)
153
154
  return acc;
154
- if (!(0, nestable_1.isNestableContent)(transformedField)) {
155
- console.warn(`Warn: Non nestable content with key [${fieldKey}] detected in a shared slice [${sliceName}] with key [${sliceKey}]`);
156
- return acc;
157
- }
158
155
  return {
159
156
  ...acc,
160
157
  [fieldKey]: transformedField,
@@ -1427,3 +1427,634 @@ export declare const SlicePrimaryLegacy: (ctx: LegacyContentCtx) => {
1427
1427
  }> | undefined;
1428
1428
  encode(value: SlicePrimaryContent): import("../../../LegacyContentCtx").WithTypes<unknown> | undefined;
1429
1429
  };
1430
+ export declare const isSlicePrimaryContent: (u: unknown) => u is {
1431
+ type: string;
1432
+ __TYPE__: "EmptyContent";
1433
+ } | {
1434
+ __TYPE__: "BooleanContent";
1435
+ value: boolean;
1436
+ } | ({
1437
+ embed_url: string;
1438
+ type: string;
1439
+ } & {
1440
+ version?: string | number | null;
1441
+ title?: string | null | undefined;
1442
+ author_name?: string | null | undefined;
1443
+ author_url?: string | null | undefined;
1444
+ provider_name?: string | null | undefined;
1445
+ provider_url?: string | null | undefined;
1446
+ cache_age?: string | number | null;
1447
+ thumbnail_url?: string | null | undefined;
1448
+ thumbnail_width?: number | null | undefined;
1449
+ thumbnail_height?: number | null | undefined;
1450
+ html?: string | null | undefined;
1451
+ } & {
1452
+ __TYPE__: "EmbedContent";
1453
+ all: unknown;
1454
+ }) | {
1455
+ type: "Color";
1456
+ value: string;
1457
+ __TYPE__: "FieldContent";
1458
+ } | {
1459
+ type: "Date";
1460
+ value: string;
1461
+ __TYPE__: "FieldContent";
1462
+ } | {
1463
+ type: "Number";
1464
+ value: string;
1465
+ __TYPE__: "FieldContent";
1466
+ } | {
1467
+ type: "Range";
1468
+ value: string;
1469
+ __TYPE__: "FieldContent";
1470
+ } | {
1471
+ type: "Select";
1472
+ value: string;
1473
+ __TYPE__: "FieldContent";
1474
+ } | {
1475
+ type: "Text";
1476
+ value: string;
1477
+ __TYPE__: "FieldContent";
1478
+ } | {
1479
+ type: "Timestamp";
1480
+ value: string;
1481
+ __TYPE__: "FieldContent";
1482
+ } | ({
1483
+ position: {
1484
+ lat: number;
1485
+ lng: number;
1486
+ };
1487
+ } & {
1488
+ __TYPE__: "GeoPointContent";
1489
+ }) | ({
1490
+ origin: {
1491
+ id: string;
1492
+ url: string;
1493
+ width: number;
1494
+ height: number;
1495
+ };
1496
+ width: number;
1497
+ height: number;
1498
+ edit: {
1499
+ zoom: number;
1500
+ crop: {
1501
+ x: number;
1502
+ y: number;
1503
+ };
1504
+ background: string;
1505
+ };
1506
+ } & {
1507
+ url?: string;
1508
+ credits?: string | null;
1509
+ alt?: string | null;
1510
+ provider?: string | null | undefined;
1511
+ } & {
1512
+ thumbnails?: {
1513
+ [x: string]: {
1514
+ origin: {
1515
+ id: string;
1516
+ url: string;
1517
+ width: number;
1518
+ height: number;
1519
+ };
1520
+ width: number;
1521
+ height: number;
1522
+ edit: {
1523
+ zoom: number;
1524
+ crop: {
1525
+ x: number;
1526
+ y: number;
1527
+ };
1528
+ background: string;
1529
+ };
1530
+ } & {
1531
+ url?: string;
1532
+ credits?: string | null;
1533
+ alt?: string | null;
1534
+ provider?: string | null | undefined;
1535
+ };
1536
+ };
1537
+ } & {
1538
+ __TYPE__: "ImageContent";
1539
+ }) | {
1540
+ __TYPE__: "IntegrationFieldsContent";
1541
+ value: string;
1542
+ } | {
1543
+ __TYPE__: "LinkContent";
1544
+ value: ({
1545
+ __TYPE__: "ImageLink";
1546
+ } & {
1547
+ id: string;
1548
+ url: string;
1549
+ height: string;
1550
+ width: string;
1551
+ size: string;
1552
+ name: string;
1553
+ kind: string;
1554
+ } & {
1555
+ date?: string | null | undefined;
1556
+ }) | ({
1557
+ id: string;
1558
+ url: string;
1559
+ name: string;
1560
+ kind: string;
1561
+ size: string;
1562
+ } & {
1563
+ date?: string | null | undefined;
1564
+ } & {
1565
+ __TYPE__: "FileLink";
1566
+ } & {
1567
+ size?: string;
1568
+ }) | ({
1569
+ __TYPE__: "DocumentLink";
1570
+ } & {
1571
+ id: string;
1572
+ }) | ({
1573
+ __TYPE__: "ExternalLink";
1574
+ } & {
1575
+ url: string;
1576
+ } & {
1577
+ kind?: "web";
1578
+ target?: string | null | undefined;
1579
+ preview?: {
1580
+ title?: string;
1581
+ } | null | undefined;
1582
+ });
1583
+ } | {
1584
+ __TYPE__: "StructuredTextContent";
1585
+ value: (({
1586
+ type: "image";
1587
+ data: {
1588
+ origin: {
1589
+ id: string;
1590
+ url: string;
1591
+ width: number;
1592
+ height: number;
1593
+ };
1594
+ width: number;
1595
+ height: number;
1596
+ edit: {
1597
+ zoom: number;
1598
+ crop: {
1599
+ x: number;
1600
+ y: number;
1601
+ };
1602
+ background: string;
1603
+ };
1604
+ } & {
1605
+ url?: string;
1606
+ credits?: string | null;
1607
+ alt?: string | null;
1608
+ provider?: string | null | undefined;
1609
+ } & {
1610
+ linkTo?: ({
1611
+ __TYPE__: "ImageLink";
1612
+ } & {
1613
+ id: string;
1614
+ url: string;
1615
+ height: string;
1616
+ width: string;
1617
+ size: string;
1618
+ name: string;
1619
+ kind: string;
1620
+ } & {
1621
+ date?: string | null | undefined;
1622
+ }) | ({
1623
+ id: string;
1624
+ url: string;
1625
+ name: string;
1626
+ kind: string;
1627
+ size: string;
1628
+ } & {
1629
+ date?: string | null | undefined;
1630
+ } & {
1631
+ __TYPE__: "FileLink";
1632
+ } & {
1633
+ size?: string;
1634
+ }) | ({
1635
+ __TYPE__: "DocumentLink";
1636
+ } & {
1637
+ id: string;
1638
+ }) | ({
1639
+ __TYPE__: "ExternalLink";
1640
+ } & {
1641
+ url: string;
1642
+ } & {
1643
+ kind?: "web";
1644
+ target?: string | null | undefined;
1645
+ preview?: {
1646
+ title?: string;
1647
+ } | null | undefined;
1648
+ }) | null | undefined;
1649
+ };
1650
+ } & {
1651
+ label?: string | null | undefined;
1652
+ direction?: string | null | undefined;
1653
+ }) | ({
1654
+ type: "embed";
1655
+ data: {
1656
+ embed_url: string;
1657
+ type: string;
1658
+ } & {
1659
+ version?: string | number | null;
1660
+ title?: string | null | undefined;
1661
+ author_name?: string | null | undefined;
1662
+ author_url?: string | null | undefined;
1663
+ provider_name?: string | null | undefined;
1664
+ provider_url?: string | null | undefined;
1665
+ cache_age?: string | number | null;
1666
+ thumbnail_url?: string | null | undefined;
1667
+ thumbnail_width?: number | null | undefined;
1668
+ thumbnail_height?: number | null | undefined;
1669
+ html?: string | null | undefined;
1670
+ } & {
1671
+ __TYPE__: "EmbedContent";
1672
+ all: unknown;
1673
+ };
1674
+ } & {
1675
+ label?: string | null | undefined;
1676
+ direction?: string | null | undefined;
1677
+ }) | ({
1678
+ type: "image" | "paragraph" | "heading1" | "heading2" | "heading3" | "heading4" | "heading5" | "heading6" | "strong" | "em" | "preformatted" | "hyperlink" | "embed" | "list-item" | "o-list-item" | "rtl";
1679
+ content: {
1680
+ text: string;
1681
+ } & {
1682
+ spans?: ({
1683
+ data: ({
1684
+ __TYPE__: "ImageLink";
1685
+ } & {
1686
+ id: string;
1687
+ url: string;
1688
+ height: string;
1689
+ width: string;
1690
+ size: string;
1691
+ name: string;
1692
+ kind: string;
1693
+ } & {
1694
+ date?: string | null | undefined;
1695
+ }) | ({
1696
+ id: string;
1697
+ url: string;
1698
+ name: string;
1699
+ kind: string;
1700
+ size: string;
1701
+ } & {
1702
+ date?: string | null | undefined;
1703
+ } & {
1704
+ __TYPE__: "FileLink";
1705
+ } & {
1706
+ size?: string;
1707
+ }) | ({
1708
+ __TYPE__: "DocumentLink";
1709
+ } & {
1710
+ id: string;
1711
+ }) | ({
1712
+ __TYPE__: "ExternalLink";
1713
+ } & {
1714
+ url: string;
1715
+ } & {
1716
+ kind?: "web";
1717
+ target?: string | null | undefined;
1718
+ preview?: {
1719
+ title?: string;
1720
+ } | null | undefined;
1721
+ });
1722
+ start: number;
1723
+ end: number;
1724
+ type: "hyperlink";
1725
+ } | {
1726
+ data: string;
1727
+ start: number;
1728
+ end: number;
1729
+ type: "label";
1730
+ } | {
1731
+ start: number;
1732
+ end: number;
1733
+ type: "strong" | "em" | "list-item";
1734
+ })[];
1735
+ };
1736
+ } & {
1737
+ label?: string;
1738
+ direction?: string;
1739
+ }))[];
1740
+ } | {
1741
+ __TYPE__: "SeparatorContent";
1742
+ } | {
1743
+ __TYPE__: "GroupContentType";
1744
+ value: {
1745
+ __TYPE__: "GroupItemContent";
1746
+ value: [string, {
1747
+ type: string;
1748
+ __TYPE__: "EmptyContent";
1749
+ } | {
1750
+ __TYPE__: "BooleanContent";
1751
+ value: boolean;
1752
+ } | ({
1753
+ embed_url: string;
1754
+ type: string;
1755
+ } & {
1756
+ version?: string | number | null;
1757
+ title?: string | null | undefined;
1758
+ author_name?: string | null | undefined;
1759
+ author_url?: string | null | undefined;
1760
+ provider_name?: string | null | undefined;
1761
+ provider_url?: string | null | undefined;
1762
+ cache_age?: string | number | null;
1763
+ thumbnail_url?: string | null | undefined;
1764
+ thumbnail_width?: number | null | undefined;
1765
+ thumbnail_height?: number | null | undefined;
1766
+ html?: string | null | undefined;
1767
+ } & {
1768
+ __TYPE__: "EmbedContent";
1769
+ all: unknown;
1770
+ }) | {
1771
+ type: "Color";
1772
+ value: string;
1773
+ __TYPE__: "FieldContent";
1774
+ } | {
1775
+ type: "Date";
1776
+ value: string;
1777
+ __TYPE__: "FieldContent";
1778
+ } | {
1779
+ type: "Number";
1780
+ value: string;
1781
+ __TYPE__: "FieldContent";
1782
+ } | {
1783
+ type: "Range";
1784
+ value: string;
1785
+ __TYPE__: "FieldContent";
1786
+ } | {
1787
+ type: "Select";
1788
+ value: string;
1789
+ __TYPE__: "FieldContent";
1790
+ } | {
1791
+ type: "Text";
1792
+ value: string;
1793
+ __TYPE__: "FieldContent";
1794
+ } | {
1795
+ type: "Timestamp";
1796
+ value: string;
1797
+ __TYPE__: "FieldContent";
1798
+ } | ({
1799
+ position: {
1800
+ lat: number;
1801
+ lng: number;
1802
+ };
1803
+ } & {
1804
+ __TYPE__: "GeoPointContent";
1805
+ }) | ({
1806
+ origin: {
1807
+ id: string;
1808
+ url: string;
1809
+ width: number;
1810
+ height: number;
1811
+ };
1812
+ width: number;
1813
+ height: number;
1814
+ edit: {
1815
+ zoom: number;
1816
+ crop: {
1817
+ x: number;
1818
+ y: number;
1819
+ };
1820
+ background: string;
1821
+ };
1822
+ } & {
1823
+ url?: string;
1824
+ credits?: string | null;
1825
+ alt?: string | null;
1826
+ provider?: string | null | undefined;
1827
+ } & {
1828
+ thumbnails?: {
1829
+ [x: string]: {
1830
+ origin: {
1831
+ id: string;
1832
+ url: string;
1833
+ width: number;
1834
+ height: number;
1835
+ };
1836
+ width: number;
1837
+ height: number;
1838
+ edit: {
1839
+ zoom: number;
1840
+ crop: {
1841
+ x: number;
1842
+ y: number;
1843
+ };
1844
+ background: string;
1845
+ };
1846
+ } & {
1847
+ url?: string;
1848
+ credits?: string | null;
1849
+ alt?: string | null;
1850
+ provider?: string | null | undefined;
1851
+ };
1852
+ };
1853
+ } & {
1854
+ __TYPE__: "ImageContent";
1855
+ }) | {
1856
+ __TYPE__: "IntegrationFieldsContent";
1857
+ value: string;
1858
+ } | {
1859
+ __TYPE__: "LinkContent";
1860
+ value: ({
1861
+ __TYPE__: "ImageLink";
1862
+ } & {
1863
+ id: string;
1864
+ url: string;
1865
+ height: string;
1866
+ width: string;
1867
+ size: string;
1868
+ name: string;
1869
+ kind: string;
1870
+ } & {
1871
+ date?: string | null | undefined;
1872
+ }) | ({
1873
+ id: string;
1874
+ url: string;
1875
+ name: string;
1876
+ kind: string;
1877
+ size: string;
1878
+ } & {
1879
+ date?: string | null | undefined;
1880
+ } & {
1881
+ __TYPE__: "FileLink";
1882
+ } & {
1883
+ size?: string;
1884
+ }) | ({
1885
+ __TYPE__: "DocumentLink";
1886
+ } & {
1887
+ id: string;
1888
+ }) | ({
1889
+ __TYPE__: "ExternalLink";
1890
+ } & {
1891
+ url: string;
1892
+ } & {
1893
+ kind?: "web";
1894
+ target?: string | null | undefined;
1895
+ preview?: {
1896
+ title?: string;
1897
+ } | null | undefined;
1898
+ });
1899
+ } | {
1900
+ __TYPE__: "StructuredTextContent";
1901
+ value: (({
1902
+ type: "image";
1903
+ data: {
1904
+ origin: {
1905
+ id: string;
1906
+ url: string;
1907
+ width: number;
1908
+ height: number;
1909
+ };
1910
+ width: number;
1911
+ height: number;
1912
+ edit: {
1913
+ zoom: number;
1914
+ crop: {
1915
+ x: number;
1916
+ y: number;
1917
+ };
1918
+ background: string;
1919
+ };
1920
+ } & {
1921
+ url?: string;
1922
+ credits?: string | null;
1923
+ alt?: string | null;
1924
+ provider?: string | null | undefined;
1925
+ } & {
1926
+ linkTo?: ({
1927
+ __TYPE__: "ImageLink";
1928
+ } & {
1929
+ id: string;
1930
+ url: string;
1931
+ height: string;
1932
+ width: string;
1933
+ size: string;
1934
+ name: string;
1935
+ kind: string;
1936
+ } & {
1937
+ date?: string | null | undefined;
1938
+ }) | ({
1939
+ id: string;
1940
+ url: string;
1941
+ name: string;
1942
+ kind: string;
1943
+ size: string;
1944
+ } & {
1945
+ date?: string | null | undefined;
1946
+ } & {
1947
+ __TYPE__: "FileLink";
1948
+ } & {
1949
+ size?: string;
1950
+ }) | ({
1951
+ __TYPE__: "DocumentLink";
1952
+ } & {
1953
+ id: string;
1954
+ }) | ({
1955
+ __TYPE__: "ExternalLink";
1956
+ } & {
1957
+ url: string;
1958
+ } & {
1959
+ kind?: "web";
1960
+ target?: string | null | undefined;
1961
+ preview?: {
1962
+ title?: string;
1963
+ } | null | undefined;
1964
+ }) | null | undefined;
1965
+ };
1966
+ } & {
1967
+ label?: string | null | undefined;
1968
+ direction?: string | null | undefined;
1969
+ }) | ({
1970
+ type: "embed";
1971
+ data: {
1972
+ embed_url: string;
1973
+ type: string;
1974
+ } & {
1975
+ version?: string | number | null;
1976
+ title?: string | null | undefined;
1977
+ author_name?: string | null | undefined;
1978
+ author_url?: string | null | undefined;
1979
+ provider_name?: string | null | undefined;
1980
+ provider_url?: string | null | undefined;
1981
+ cache_age?: string | number | null;
1982
+ thumbnail_url?: string | null | undefined;
1983
+ thumbnail_width?: number | null | undefined;
1984
+ thumbnail_height?: number | null | undefined;
1985
+ html?: string | null | undefined;
1986
+ } & {
1987
+ __TYPE__: "EmbedContent";
1988
+ all: unknown;
1989
+ };
1990
+ } & {
1991
+ label?: string | null | undefined;
1992
+ direction?: string | null | undefined;
1993
+ }) | ({
1994
+ type: "image" | "paragraph" | "heading1" | "heading2" | "heading3" | "heading4" | "heading5" | "heading6" | "strong" | "em" | "preformatted" | "hyperlink" | "embed" | "list-item" | "o-list-item" | "rtl";
1995
+ content: {
1996
+ text: string;
1997
+ } & {
1998
+ spans?: ({
1999
+ data: ({
2000
+ __TYPE__: "ImageLink";
2001
+ } & {
2002
+ id: string;
2003
+ url: string;
2004
+ height: string;
2005
+ width: string;
2006
+ size: string;
2007
+ name: string;
2008
+ kind: string;
2009
+ } & {
2010
+ date?: string | null | undefined;
2011
+ }) | ({
2012
+ id: string;
2013
+ url: string;
2014
+ name: string;
2015
+ kind: string;
2016
+ size: string;
2017
+ } & {
2018
+ date?: string | null | undefined;
2019
+ } & {
2020
+ __TYPE__: "FileLink";
2021
+ } & {
2022
+ size?: string;
2023
+ }) | ({
2024
+ __TYPE__: "DocumentLink";
2025
+ } & {
2026
+ id: string;
2027
+ }) | ({
2028
+ __TYPE__: "ExternalLink";
2029
+ } & {
2030
+ url: string;
2031
+ } & {
2032
+ kind?: "web";
2033
+ target?: string | null | undefined;
2034
+ preview?: {
2035
+ title?: string;
2036
+ } | null | undefined;
2037
+ });
2038
+ start: number;
2039
+ end: number;
2040
+ type: "hyperlink";
2041
+ } | {
2042
+ data: string;
2043
+ start: number;
2044
+ end: number;
2045
+ type: "label";
2046
+ } | {
2047
+ start: number;
2048
+ end: number;
2049
+ type: "strong" | "em" | "list-item";
2050
+ })[];
2051
+ };
2052
+ } & {
2053
+ label?: string;
2054
+ direction?: string;
2055
+ }))[];
2056
+ } | {
2057
+ __TYPE__: "SeparatorContent";
2058
+ }][];
2059
+ }[];
2060
+ };
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.SlicePrimaryLegacy = exports.SlicePrimaryContent = void 0;
3
+ exports.isSlicePrimaryContent = exports.SlicePrimaryLegacy = exports.SlicePrimaryContent = void 0;
4
4
  const tslib_1 = require("tslib");
5
5
  const t = (0, tslib_1.__importStar)(require("io-ts"));
6
6
  const customtypes_1 = require("../../../../customtypes");
@@ -26,3 +26,5 @@ const SlicePrimaryLegacy = (ctx) => {
26
26
  };
27
27
  };
28
28
  exports.SlicePrimaryLegacy = SlicePrimaryLegacy;
29
+ const isSlicePrimaryContent = (u) => (0, nestable_1.isNestableContent)(u) || (0, GroupContent_1.isGroupContent)(u);
30
+ exports.isSlicePrimaryContent = isSlicePrimaryContent;
@@ -4995,3 +4995,4 @@ export declare type SliceContent = t.TypeOf<typeof SliceContent>;
4995
4995
  export * from "./CompositeSliceContent";
4996
4996
  export * from "./SharedSliceContent";
4997
4997
  export * from "./SimpleSliceContent";
4998
+ export * from "./SlicePrimaryContent";
@@ -42,3 +42,4 @@ exports.SliceContent = t.union([
42
42
  (0, tslib_1.__exportStar)(require("./CompositeSliceContent"), exports);
43
43
  (0, tslib_1.__exportStar)(require("./SharedSliceContent"), exports);
44
44
  (0, tslib_1.__exportStar)(require("./SimpleSliceContent"), exports);
45
+ (0, tslib_1.__exportStar)(require("./SlicePrimaryContent"), exports);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@prismicio/types-internal",
3
- "version": "2.4.0-alpha.4",
3
+ "version": "2.4.0-alpha.6",
4
4
  "description": "Prismic types for Custom Types and Prismic Data",
5
5
  "keywords": [
6
6
  "typescript",
@@ -199,45 +199,40 @@ export function traverseSharedSliceContent({
199
199
  >((acc, [fieldKey, fieldContent]) => {
200
200
  const fieldDef = model?.fields?.primary?.[fieldKey]
201
201
 
202
- if (isGroupContent(fieldContent) && fieldDef?.type === GroupFieldType) {
203
- const transformedGroupField = traverseGroupContent({
204
- path: path.concat([
205
- { key: "primary", type: "primary" },
206
- { key: fieldKey, type: "Widget" },
207
- ]),
208
- key: fieldKey,
209
- apiId: sliceName,
210
- content: fieldContent,
211
- model: fieldDef,
212
- })(transformWidget)
213
-
214
- // Can happen if the transform function returns undefined to filter out a field
215
- if (!transformedGroupField) return acc
216
-
217
- return {
218
- ...acc,
219
- [fieldKey]: transformedGroupField,
202
+ const transformedField = (() => {
203
+ if (isGroupContent(fieldContent) && fieldDef?.type === GroupFieldType) {
204
+ return traverseGroupContent({
205
+ path: path.concat([
206
+ { key: "primary", type: "primary" },
207
+ { key: fieldKey, type: "Widget" },
208
+ ]),
209
+ key: fieldKey,
210
+ apiId: fieldKey,
211
+ content: fieldContent,
212
+ model: fieldDef,
213
+ })(transformWidget)
214
+ } else if (isNestableContent(fieldContent)) {
215
+ return transformWidget({
216
+ path: path.concat([
217
+ { key: "primary", type: "primary" },
218
+ { key: fieldKey, type: "Widget" },
219
+ ]),
220
+ key: fieldKey,
221
+ apiId: fieldKey,
222
+ model: fieldDef,
223
+ content: fieldContent,
224
+ })
225
+ } else {
226
+ console.warn(
227
+ `Warn: Non nestable content or group (content and model) with key [${fieldKey}] detected in a shared slice [${sliceName}] with key [${sliceKey}]`,
228
+ )
229
+ return
220
230
  }
221
- }
231
+ })()
222
232
 
223
- const transformedField = transformWidget({
224
- path: path.concat([
225
- { key: "primary", type: "primary" },
226
- { key: fieldKey, type: "Widget" },
227
- ]),
228
- key: fieldKey,
229
- apiId: sliceName,
230
- model: fieldDef,
231
- content: fieldContent,
232
- })
233
233
  // Can happen if the transform function returns undefined to filter out a field
234
234
  if (!transformedField) return acc
235
- if (!isNestableContent(transformedField)) {
236
- console.warn(
237
- `Warn: Non nestable content with key [${fieldKey}] detected in a shared slice [${sliceName}] with key [${sliceKey}]`,
238
- )
239
- return acc
240
- }
235
+
241
236
  return {
242
237
  ...acc,
243
238
  [fieldKey]: transformedField,
@@ -3,7 +3,11 @@ import * as t from "io-ts"
3
3
  import { GroupFieldType } from "../../../../customtypes"
4
4
  import type { LegacyContentCtx } from "../../../LegacyContentCtx"
5
5
  import { GroupContent, GroupLegacy, isGroupContent } from "../../GroupContent"
6
- import { NestableContent, NestableLegacy } from "../../nestable"
6
+ import {
7
+ isNestableContent,
8
+ NestableContent,
9
+ NestableLegacy,
10
+ } from "../../nestable"
7
11
 
8
12
  export const SlicePrimaryContent = t.union([NestableContent, GroupContent])
9
13
 
@@ -31,3 +35,6 @@ export const SlicePrimaryLegacy = (ctx: LegacyContentCtx) => {
31
35
  },
32
36
  }
33
37
  }
38
+
39
+ export const isSlicePrimaryContent = (u: unknown): u is SlicePrimaryContent =>
40
+ isNestableContent(u) || isGroupContent(u)
@@ -49,3 +49,4 @@ export type SliceContent = t.TypeOf<typeof SliceContent>
49
49
  export * from "./CompositeSliceContent"
50
50
  export * from "./SharedSliceContent"
51
51
  export * from "./SimpleSliceContent"
52
+ export * from "./SlicePrimaryContent"