@makeswift/runtime 0.11.9 → 0.11.11

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.
Files changed (198) hide show
  1. package/LICENSE +21 -0
  2. package/dist/Box.cjs.js +1 -1
  3. package/dist/Box.cjs.js.map +1 -1
  4. package/dist/Box.es.js +1 -1
  5. package/dist/Box.es.js.map +1 -1
  6. package/dist/Button.cjs.js +1 -1
  7. package/dist/Button.cjs.js.map +1 -1
  8. package/dist/Button.es.js +1 -1
  9. package/dist/Button.es.js.map +1 -1
  10. package/dist/Carousel.cjs.js +1 -1
  11. package/dist/Carousel.cjs.js.map +1 -1
  12. package/dist/Carousel.es.js +1 -1
  13. package/dist/Carousel.es.js.map +1 -1
  14. package/dist/Countdown.cjs.js +1 -1
  15. package/dist/Countdown.cjs.js.map +1 -1
  16. package/dist/Countdown.es.js +1 -1
  17. package/dist/Countdown.es.js.map +1 -1
  18. package/dist/Divider.cjs.js +1 -1
  19. package/dist/Divider.cjs.js.map +1 -1
  20. package/dist/Divider.es.js +1 -1
  21. package/dist/Divider.es.js.map +1 -1
  22. package/dist/Embed.cjs.js +1 -1
  23. package/dist/Embed.cjs.js.map +1 -1
  24. package/dist/Embed.es.js +1 -1
  25. package/dist/Embed.es.js.map +1 -1
  26. package/dist/Form.cjs.js +3 -3
  27. package/dist/Form.cjs.js.map +1 -1
  28. package/dist/Form.es.js +3 -3
  29. package/dist/Form.es.js.map +1 -1
  30. package/dist/Image.cjs.js +1 -1
  31. package/dist/Image.cjs.js.map +1 -1
  32. package/dist/Image.es.js +1 -1
  33. package/dist/Image.es.js.map +1 -1
  34. package/dist/LiveProvider.cjs.js +1 -1
  35. package/dist/LiveProvider.cjs.js.map +1 -1
  36. package/dist/LiveProvider.es.js +1 -1
  37. package/dist/LiveProvider.es.js.map +1 -1
  38. package/dist/Navigation.cjs.js +7 -7
  39. package/dist/Navigation.cjs.js.map +1 -1
  40. package/dist/Navigation.es.js +7 -7
  41. package/dist/Navigation.es.js.map +1 -1
  42. package/dist/PreviewProvider.cjs.js +1 -1
  43. package/dist/PreviewProvider.cjs.js.map +1 -1
  44. package/dist/PreviewProvider.es.js +1 -1
  45. package/dist/PreviewProvider.es.js.map +1 -1
  46. package/dist/ReadOnlyText.cjs.js +1 -1
  47. package/dist/ReadOnlyText.cjs.js.map +1 -1
  48. package/dist/ReadOnlyText.es.js +1 -1
  49. package/dist/ReadOnlyText.es.js.map +1 -1
  50. package/dist/ReadOnlyTextV2.cjs.js +2 -2
  51. package/dist/ReadOnlyTextV2.cjs.js.map +1 -1
  52. package/dist/ReadOnlyTextV2.es.js +2 -2
  53. package/dist/ReadOnlyTextV2.es.js.map +1 -1
  54. package/dist/Root.cjs.js +1 -1
  55. package/dist/Root.cjs.js.map +1 -1
  56. package/dist/Root.es.js +1 -1
  57. package/dist/Root.es.js.map +1 -1
  58. package/dist/SocialLinks.cjs.js +132 -74
  59. package/dist/SocialLinks.cjs.js.map +1 -1
  60. package/dist/SocialLinks.es.js +132 -74
  61. package/dist/SocialLinks.es.js.map +1 -1
  62. package/dist/Text.cjs.js.map +1 -1
  63. package/dist/Text.es.js.map +1 -1
  64. package/dist/Video.cjs.js +1 -1
  65. package/dist/Video.cjs.js.map +1 -1
  66. package/dist/Video.es.js +1 -1
  67. package/dist/Video.es.js.map +1 -1
  68. package/dist/breakpoints.cjs.js +223 -0
  69. package/dist/breakpoints.cjs.js.map +1 -0
  70. package/dist/breakpoints.es.js +206 -0
  71. package/dist/breakpoints.es.js.map +1 -0
  72. package/dist/builder.cjs.js +1 -1
  73. package/dist/builder.es.js +1 -1
  74. package/dist/components.cjs.js +1 -1
  75. package/dist/components.es.js +1 -1
  76. package/dist/control-serialization.cjs.js +1 -1
  77. package/dist/control-serialization.es.js +1 -1
  78. package/dist/controls.cjs.js +1 -1
  79. package/dist/controls.es.js +1 -1
  80. package/dist/index.cjs.js +15 -5
  81. package/dist/index.cjs.js.map +1 -1
  82. package/dist/index.cjs2.js +1 -1
  83. package/dist/index.cjs2.js.map +1 -1
  84. package/dist/index.cjs3.js.map +1 -1
  85. package/dist/index.cjs6.js.map +1 -1
  86. package/dist/index.cjs7.js.map +1 -1
  87. package/dist/index.cjs8.js +1 -1
  88. package/dist/index.cjs8.js.map +1 -1
  89. package/dist/index.cjs9.js +1 -1
  90. package/dist/index.cjs9.js.map +1 -1
  91. package/dist/index.es.js +15 -5
  92. package/dist/index.es.js.map +1 -1
  93. package/dist/index.es2.js +1 -1
  94. package/dist/index.es2.js.map +1 -1
  95. package/dist/index.es3.js.map +1 -1
  96. package/dist/index.es6.js.map +1 -1
  97. package/dist/index.es7.js.map +1 -1
  98. package/dist/index.es8.js +1 -1
  99. package/dist/index.es8.js.map +1 -1
  100. package/dist/index.es9.js +1 -1
  101. package/dist/index.es9.js.map +1 -1
  102. package/dist/main.cjs.js +1 -1
  103. package/dist/main.es.js +1 -1
  104. package/dist/next.cjs.js +1 -1
  105. package/dist/next.es.js +1 -1
  106. package/dist/prop-controllers.cjs.js +1 -1
  107. package/dist/prop-controllers.es.js +1 -1
  108. package/dist/react-page.cjs.js +192 -6
  109. package/dist/react-page.cjs.js.map +1 -1
  110. package/dist/react-page.es.js +198 -12
  111. package/dist/react-page.es.js.map +1 -1
  112. package/dist/react.cjs.js +1 -1
  113. package/dist/react.es.js +1 -1
  114. package/dist/slate.cjs.js +1 -1
  115. package/dist/slate.es.js +1 -1
  116. package/dist/state/breakpoints.cjs.js +17 -219
  117. package/dist/state/breakpoints.cjs.js.map +1 -1
  118. package/dist/state/breakpoints.es.js +2 -205
  119. package/dist/state/breakpoints.es.js.map +1 -1
  120. package/dist/toText.cjs.js +1 -1
  121. package/dist/toText.es.js +1 -1
  122. package/dist/types/src/components/builtin/Form/components/Field/components/PlaceholderTableField/index.d.ts +1 -0
  123. package/dist/types/src/components/builtin/Form/components/Field/components/PlaceholderTableField/index.d.ts.map +1 -1
  124. package/dist/types/src/components/builtin/Form/components/Field/index.d.ts +1 -0
  125. package/dist/types/src/components/builtin/Form/components/Field/index.d.ts.map +1 -1
  126. package/dist/types/src/components/builtin/Form/components/Spinner/index.d.ts +1 -0
  127. package/dist/types/src/components/builtin/Form/components/Spinner/index.d.ts.map +1 -1
  128. package/dist/types/src/components/builtin/Navigation/components/LinksPlaceholder/index.d.ts +1 -0
  129. package/dist/types/src/components/builtin/Navigation/components/LinksPlaceholder/index.d.ts.map +1 -1
  130. package/dist/types/src/components/builtin/Navigation/components/MobileMenu/index.d.ts +1 -0
  131. package/dist/types/src/components/builtin/Navigation/components/MobileMenu/index.d.ts.map +1 -1
  132. package/dist/types/src/components/builtin/SocialLinks/components/SocialLinksPlaceholder/index.d.ts +1 -0
  133. package/dist/types/src/components/builtin/SocialLinks/components/SocialLinksPlaceholder/index.d.ts.map +1 -1
  134. package/dist/types/src/components/builtin/SocialLinks/options.d.ts +10 -0
  135. package/dist/types/src/components/builtin/SocialLinks/options.d.ts.map +1 -1
  136. package/dist/types/src/components/page/Page.d.ts +1 -0
  137. package/dist/types/src/components/page/Page.d.ts.map +1 -1
  138. package/dist/types/src/components/shared/BackgroundsContainer/components/BackgroundVideo/index.d.ts +1 -0
  139. package/dist/types/src/components/shared/BackgroundsContainer/components/BackgroundVideo/index.d.ts.map +1 -1
  140. package/dist/types/src/components/shared/BackgroundsContainer/components/Backgrounds/index.d.ts +1 -0
  141. package/dist/types/src/components/shared/BackgroundsContainer/components/Backgrounds/index.d.ts.map +1 -1
  142. package/dist/types/src/controls/control.d.ts.map +1 -1
  143. package/dist/types/src/controls/rich-text/__tests__/copy.test.d.ts.map +1 -0
  144. package/dist/types/src/controls/rich-text/__tests__/dto.test.d.ts.map +1 -0
  145. package/dist/types/src/controls/rich-text/__tests__/introspection.test.d.ts.map +1 -0
  146. package/dist/types/src/controls/rich-text-v2/__tests__/copy.test.d.ts.map +1 -0
  147. package/dist/types/src/controls/rich-text-v2/__tests__/fixtures/rearranged.d.ts.map +1 -0
  148. package/dist/types/src/controls/rich-text-v2/__tests__/fixtures/simple.d.ts.map +1 -0
  149. package/dist/types/src/controls/rich-text-v2/__tests__/introspection.test.d.ts.map +1 -0
  150. package/dist/types/src/controls/rich-text-v2/__tests__/translation.test.d.ts.map +1 -0
  151. package/dist/types/src/controls/rich-text-v2/translation.d.ts +1 -1
  152. package/dist/types/src/controls/rich-text-v2/translation.d.ts.map +1 -1
  153. package/dist/types/src/next/client.d.ts.map +1 -1
  154. package/dist/types/src/prop-controllers/descriptors.d.ts +1 -1
  155. package/dist/types/src/prop-controllers/descriptors.d.ts.map +1 -1
  156. package/dist/types/src/runtimes/react/components/render-hook.d.ts +1 -0
  157. package/dist/types/src/runtimes/react/components/render-hook.d.ts.map +1 -1
  158. package/dist/types/src/runtimes/react/controls/control.d.ts +1 -0
  159. package/dist/types/src/runtimes/react/controls/control.d.ts.map +1 -1
  160. package/dist/types/src/runtimes/react/controls/list.d.ts +1 -0
  161. package/dist/types/src/runtimes/react/controls/list.d.ts.map +1 -1
  162. package/dist/types/src/runtimes/react/controls/shape.d.ts +1 -0
  163. package/dist/types/src/runtimes/react/controls/shape.d.ts.map +1 -1
  164. package/dist/types/src/runtimes/react/controls/style-v2.d.ts +1 -0
  165. package/dist/types/src/runtimes/react/controls/style-v2.d.ts.map +1 -1
  166. package/dist/types/src/runtimes/react/controls.d.ts +1 -0
  167. package/dist/types/src/runtimes/react/controls.d.ts.map +1 -1
  168. package/dist/types/src/runtimes/react/find-dom-node.d.ts.map +1 -1
  169. package/dist/types/src/slate/TypographyPlugin/index.d.ts +4 -1
  170. package/dist/types/src/slate/TypographyPlugin/index.d.ts.map +1 -1
  171. package/dist/types/src/slate/TypographyPlugin/normalizeSimilarText.d.ts +10 -0
  172. package/dist/types/src/slate/TypographyPlugin/normalizeSimilarText.d.ts.map +1 -0
  173. package/dist/types/src/slate/TypographyPlugin/normalizeTypographyDown.d.ts +29 -0
  174. package/dist/types/src/slate/TypographyPlugin/normalizeTypographyDown.d.ts.map +1 -0
  175. package/dist/types/src/slate/TypographyPlugin/normalizeTypographyUp.d.ts +4 -0
  176. package/dist/types/src/slate/TypographyPlugin/normalizeTypographyUp.d.ts.map +1 -0
  177. package/dist/types/src/slate/types.d.ts +19 -2
  178. package/dist/types/src/slate/types.d.ts.map +1 -1
  179. package/dist/types/src/state/makeswift-api-client.d.ts.map +1 -1
  180. package/dist/useMediaQuery.cjs.js +1 -1
  181. package/dist/useMediaQuery.es.js +1 -1
  182. package/package.json +12 -13
  183. package/dist/types/src/controls/rich-text/__test__/copy.test.d.ts.map +0 -1
  184. package/dist/types/src/controls/rich-text/__test__/dto.test.d.ts.map +0 -1
  185. package/dist/types/src/controls/rich-text/__test__/introspection.test.d.ts.map +0 -1
  186. package/dist/types/src/controls/rich-text-v2/__test__/copy.test.d.ts.map +0 -1
  187. package/dist/types/src/controls/rich-text-v2/__test__/fixtures/rearranged.d.ts.map +0 -1
  188. package/dist/types/src/controls/rich-text-v2/__test__/fixtures/simple.d.ts.map +0 -1
  189. package/dist/types/src/controls/rich-text-v2/__test__/introspection.test.d.ts.map +0 -1
  190. package/dist/types/src/controls/rich-text-v2/__test__/translation.test.d.ts.map +0 -1
  191. /package/dist/types/src/controls/rich-text/{__test__ → __tests__}/copy.test.d.ts +0 -0
  192. /package/dist/types/src/controls/rich-text/{__test__ → __tests__}/dto.test.d.ts +0 -0
  193. /package/dist/types/src/controls/rich-text/{__test__ → __tests__}/introspection.test.d.ts +0 -0
  194. /package/dist/types/src/controls/rich-text-v2/{__test__ → __tests__}/copy.test.d.ts +0 -0
  195. /package/dist/types/src/controls/rich-text-v2/{__test__ → __tests__}/fixtures/rearranged.d.ts +0 -0
  196. /package/dist/types/src/controls/rich-text-v2/{__test__ → __tests__}/fixtures/simple.d.ts +0 -0
  197. /package/dist/types/src/controls/rich-text-v2/{__test__ → __tests__}/introspection.test.d.ts +0 -0
  198. /package/dist/types/src/controls/rich-text-v2/{__test__ → __tests__}/translation.test.d.ts +0 -0
@@ -0,0 +1,223 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __defProps = Object.defineProperties;
4
+ var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
5
+ var __getOwnPropSymbols = Object.getOwnPropertySymbols;
6
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
7
+ var __propIsEnum = Object.prototype.propertyIsEnumerable;
8
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
9
+ var __spreadValues = (a, b) => {
10
+ for (var prop in b || (b = {}))
11
+ if (__hasOwnProp.call(b, prop))
12
+ __defNormalProp(a, prop, b[prop]);
13
+ if (__getOwnPropSymbols)
14
+ for (var prop of __getOwnPropSymbols(b)) {
15
+ if (__propIsEnum.call(b, prop))
16
+ __defNormalProp(a, prop, b[prop]);
17
+ }
18
+ return a;
19
+ };
20
+ var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
21
+ var actions = require("./actions.cjs.js");
22
+ const keys = (o) => Object.keys(o);
23
+ const coalesce = (...args) => {
24
+ let i;
25
+ for (i = 0; i < args.length - 1; i += 1) {
26
+ if (args[i] != null)
27
+ return args[i];
28
+ }
29
+ return args[i];
30
+ };
31
+ function shallowMerge(a, b) {
32
+ const bKeys = keys(b);
33
+ const merged = __spreadValues({}, a);
34
+ bKeys.forEach((key) => {
35
+ merged[key] = coalesce(merged[key], b[key]);
36
+ });
37
+ return merged;
38
+ }
39
+ const DefaultBreakpointID = {
40
+ Desktop: "desktop",
41
+ Tablet: "tablet",
42
+ Mobile: "mobile"
43
+ };
44
+ const DEFAULT_BREAKPOINTS = [
45
+ {
46
+ id: DefaultBreakpointID.Desktop,
47
+ label: "Desktop",
48
+ minWidth: 769
49
+ },
50
+ {
51
+ id: DefaultBreakpointID.Tablet,
52
+ label: "Tablet",
53
+ minWidth: 576,
54
+ maxWidth: 768,
55
+ viewportWidth: 760
56
+ },
57
+ {
58
+ id: DefaultBreakpointID.Mobile,
59
+ label: "Mobile",
60
+ maxWidth: 575,
61
+ viewportWidth: 390
62
+ }
63
+ ];
64
+ function getInitialState(breakpoints = DEFAULT_BREAKPOINTS) {
65
+ return breakpoints;
66
+ }
67
+ function reducer(state = getInitialState(), action) {
68
+ switch (action.type) {
69
+ case actions.ActionTypes.SET_BREAKPOINTS: {
70
+ const breakpoints = action.payload.breakpoints;
71
+ if (breakpoints.length === 0)
72
+ throw new Error("Breakpoints cannot be empty.");
73
+ return breakpoints;
74
+ }
75
+ default:
76
+ return state;
77
+ }
78
+ }
79
+ function parseBreakpointsInput(input) {
80
+ validateBreakpointsInput(input);
81
+ const sorted = Object.entries(input).map(([id, value]) => __spreadProps(__spreadValues({}, value), { id })).sort((a, b) => b.width - a.width);
82
+ const transformed = sorted.reduce((prev, curr, index, array) => {
83
+ const { width, viewport, id, label } = curr;
84
+ const next = array[index + 1];
85
+ const breakpoint = __spreadProps(__spreadValues(__spreadValues({
86
+ id
87
+ }, label && { label }), next && { minWidth: next.width + 1 }), {
88
+ maxWidth: width,
89
+ viewportWidth: viewport != null ? viewport : width
90
+ });
91
+ return [...prev, breakpoint];
92
+ }, [
93
+ { id: DefaultBreakpointID.Desktop, label: "Desktop", minWidth: sorted[0].width + 1 }
94
+ ]);
95
+ return transformed;
96
+ }
97
+ function validateBreakpointsInput(input) {
98
+ if (DefaultBreakpointID.Desktop in input) {
99
+ throw new Error(`Cannot change the base breakpoint. "${DefaultBreakpointID.Desktop}" is reserved as the base breakpoint.`);
100
+ }
101
+ if (Object.keys(input).length === 0) {
102
+ throw new Error(`Breakpoints cannot be empty. You must provide at least one breakpoint.`);
103
+ }
104
+ const sorted = Object.entries(input).map(([id, value]) => __spreadProps(__spreadValues({}, value), { id })).sort((a, b) => b.width - a.width);
105
+ sorted.forEach(({ id, width, viewport }, index, array) => {
106
+ if (viewport && viewport > width) {
107
+ throw new Error(`Error on breakpoint "${id}". Viewport cannot be greater than its width.
108
+ "${id}" has a viewport of ${viewport}px and a width of ${width}px.`);
109
+ }
110
+ const next = array[index + 1];
111
+ if (viewport && next && viewport < next.width) {
112
+ throw new Error(`Error on breakpoint "${id}". Viewport cannot be smaller than the next breakpoint's width.
113
+ "${id}" has a viewport of ${viewport}px and the next breakpoint "${next.id}" has a width of ${next.width}px.`);
114
+ }
115
+ if (next && width === next.width) {
116
+ throw new Error(`Breakpoints cannot have the same width. "${id}" and "${next.id}" have the same width`);
117
+ }
118
+ });
119
+ }
120
+ function sortBreakpoints(breakpoints) {
121
+ return breakpoints.sort((a, b) => {
122
+ var _a, _b;
123
+ return ((_a = b == null ? void 0 : b.minWidth) != null ? _a : 0) - ((_b = a == null ? void 0 : a.minWidth) != null ? _b : 0);
124
+ });
125
+ }
126
+ const getBreakpoint = (state, breakpointId) => {
127
+ const breakpoint = state.find(({ id }) => id === breakpointId);
128
+ if (breakpoint == null)
129
+ throw new Error(`Unrecognized breakpoint ID: "${breakpointId}".`);
130
+ return breakpoint;
131
+ };
132
+ const getBaseBreakpoint = (breakpoints) => {
133
+ const breakpoint = sortBreakpoints(breakpoints)[0];
134
+ if (breakpoint == null)
135
+ throw new Error(`Cannot get base breakpoint.`);
136
+ return breakpoint;
137
+ };
138
+ function findBreakpointOverride(breakpoints, values = [], deviceId, strategy = defaultStrategy) {
139
+ const value = values.find(({ deviceId: d }) => d === deviceId);
140
+ const fallbacks = breakpoints.slice(0, breakpoints.findIndex((d) => d.id === deviceId) + 1).reverse().map((d) => values.find((v) => v.deviceId === d.id)).filter((override) => Boolean(override));
141
+ return value != null || fallbacks.length > 0 ? strategy(value, fallbacks) : void 0;
142
+ }
143
+ function defaultStrategy(value, fallbacks) {
144
+ return value || fallbacks[0];
145
+ }
146
+ function shallowMergeFallbacks(value, fallbacks) {
147
+ return [value, ...fallbacks].filter((override) => Boolean(override)).reduce((a, b) => ({
148
+ deviceId: a.deviceId || b.deviceId,
149
+ value: shallowMerge(a.value, b.value)
150
+ }));
151
+ }
152
+ function mergeOrCoalesce(a, b) {
153
+ if (typeof a === "object" && a !== null && !Array.isArray(a) && typeof b === "object" && b !== null && !Array.isArray(b)) {
154
+ return shallowMerge(a, b);
155
+ }
156
+ return coalesce(a, b);
157
+ }
158
+ function mergeOrCoalesceFallbacks(value, fallbacks) {
159
+ return [value, ...fallbacks].filter((override) => Boolean(override)).reduce((a, b) => ({
160
+ deviceId: a.deviceId || b.deviceId,
161
+ value: mergeOrCoalesce(a.value, b.value)
162
+ }));
163
+ }
164
+ function join(breakpoints, responsiveValues, joinFn, strategy) {
165
+ return breakpoints.map(({ id }) => id).map((deviceId) => {
166
+ const value = joinFn(responsiveValues.map((responsiveValue) => {
167
+ const deviceValue = responsiveValue && findBreakpointOverride(breakpoints, responsiveValue, deviceId, strategy);
168
+ return deviceValue == null ? void 0 : deviceValue.value;
169
+ }));
170
+ if (value == null)
171
+ return null;
172
+ return { deviceId, value };
173
+ }).filter((override) => Boolean(override));
174
+ }
175
+ const getBreakpointMediaQuery = (breakpoint) => {
176
+ const parts = ["@media only screen"];
177
+ if (breakpoint.minWidth != null) {
178
+ parts.push(`(min-width: ${breakpoint.minWidth}px)`);
179
+ }
180
+ if (breakpoint.maxWidth != null) {
181
+ parts.push(`(max-width: ${breakpoint.maxWidth}px)`);
182
+ }
183
+ return parts.join(" and ");
184
+ };
185
+ const getViewportStyle = (state, deviceId) => {
186
+ const device = getBreakpoint(state, deviceId);
187
+ return device && {
188
+ width: device.viewportWidth != null ? device.viewportWidth : "100%",
189
+ minWidth: device.minWidth
190
+ };
191
+ };
192
+ function findNextFallback(breakpoints, value, deviceId, activeDeviceId, fallbackStrategy) {
193
+ var _a;
194
+ const deviceOverride = findBreakpointOverride(breakpoints, value.filter((v) => v.deviceId !== activeDeviceId), deviceId, fallbackStrategy);
195
+ return (_a = deviceOverride && getBreakpoint(breakpoints, deviceOverride.deviceId)) != null ? _a : null;
196
+ }
197
+ const mergeResponsiveValues = (breakpoints, source, override) => {
198
+ const devices = [
199
+ ...new Set(source.map(({ deviceId }) => deviceId).concat(override.map(({ deviceId }) => deviceId)))
200
+ ];
201
+ return devices.map((deviceId) => ({
202
+ deviceId,
203
+ value: __spreadValues(__spreadValues({}, (findBreakpointOverride(breakpoints, source, deviceId) || { value: {} }).value), (findBreakpointOverride(breakpoints, override, deviceId, (v) => v) || { value: {} }).value)
204
+ }));
205
+ };
206
+ exports.DEFAULT_BREAKPOINTS = DEFAULT_BREAKPOINTS;
207
+ exports.DefaultBreakpointID = DefaultBreakpointID;
208
+ exports.findBreakpointOverride = findBreakpointOverride;
209
+ exports.findNextFallback = findNextFallback;
210
+ exports.getBaseBreakpoint = getBaseBreakpoint;
211
+ exports.getBreakpoint = getBreakpoint;
212
+ exports.getBreakpointMediaQuery = getBreakpointMediaQuery;
213
+ exports.getInitialState = getInitialState;
214
+ exports.getViewportStyle = getViewportStyle;
215
+ exports.join = join;
216
+ exports.keys = keys;
217
+ exports.mergeOrCoalesceFallbacks = mergeOrCoalesceFallbacks;
218
+ exports.mergeResponsiveValues = mergeResponsiveValues;
219
+ exports.parseBreakpointsInput = parseBreakpointsInput;
220
+ exports.reducer = reducer;
221
+ exports.shallowMerge = shallowMerge;
222
+ exports.shallowMergeFallbacks = shallowMergeFallbacks;
223
+ //# sourceMappingURL=breakpoints.cjs.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"breakpoints.cjs.js","sources":["../src/utils/keys.ts","../src/utils/coalesce.ts","../src/utils/shallowMerge.ts","../src/state/modules/breakpoints.ts"],"sourcesContent":["const keys = <O extends { [key: string]: unknown }>(o: O): (keyof O)[] => Object.keys(o)\n\nexport default keys\n","const coalesce = <T>(...args: Array<T>): T => {\n let i: number\n\n for (i = 0; i < args.length - 1; i += 1) {\n if (args[i] != null) return args[i]\n }\n\n return args[i]\n}\n\nexport default coalesce\n","import keys from './keys'\nimport coalesce from './coalesce'\n\nexport default function shallowMerge<\n A extends Record<string, unknown>,\n B extends Record<string, unknown>,\n>(a: A, b: B): A & B {\n const bKeys = keys(b)\n const merged = { ...a } as A & B\n\n bKeys.forEach(key => {\n // @ts-expect-error: `coalesce` returns `null | undefined` regardless of input guarantees.\n merged[key] = coalesce(merged[key], b[key])\n })\n\n return merged\n}\n","import { Viewport } from 'csstype'\n\nimport {\n ResponsiveValue as PropControllerResponsiveValue,\n DeviceOverride as PropControllerDeviceOverride,\n Device as DeviceId,\n} from '../../prop-controllers'\nimport shallowMerge from '../../utils/shallowMerge'\nimport { Action, ActionTypes } from '../actions'\nimport coalesce from '../../utils/coalesce'\nimport { Data } from '../../controls/types'\n\nexport type DeviceOverride<T> = PropControllerDeviceOverride<T>\nexport type ResponsiveValue<T> = PropControllerResponsiveValue<T>\nexport type BreakpointId = DeviceId\n\nexport type Breakpoint = {\n id: BreakpointId\n label?: string\n viewportWidth?: number\n minWidth?: number\n maxWidth?: number\n}\n\nexport type Breakpoints = Breakpoint[]\n\nexport type State = Breakpoints\n\nexport const DefaultBreakpointID = {\n Desktop: 'desktop',\n Tablet: 'tablet',\n Mobile: 'mobile',\n} as const\n\ntype DefaultBreakpointID = typeof DefaultBreakpointID[keyof typeof DefaultBreakpointID]\n\nexport const DEFAULT_BREAKPOINTS: Breakpoints = [\n {\n id: DefaultBreakpointID.Desktop,\n label: 'Desktop',\n minWidth: 769,\n },\n {\n id: DefaultBreakpointID.Tablet,\n label: 'Tablet',\n minWidth: 576,\n maxWidth: 768,\n viewportWidth: 760,\n },\n {\n id: DefaultBreakpointID.Mobile,\n label: 'Mobile',\n maxWidth: 575,\n viewportWidth: 390,\n },\n]\n\nexport function getInitialState(breakpoints = DEFAULT_BREAKPOINTS): State {\n return breakpoints\n}\n\nexport function reducer(state: State = getInitialState(), action: Action): State {\n switch (action.type) {\n case ActionTypes.SET_BREAKPOINTS: {\n const breakpoints = action.payload.breakpoints\n\n if (breakpoints.length === 0) throw new Error('Breakpoints cannot be empty.')\n\n return breakpoints\n }\n\n default:\n return state\n }\n}\n\nexport type BreakpointsInput = Record<string, { width: number; label?: string; viewport?: number }>\n\nexport function parseBreakpointsInput(input: BreakpointsInput): Breakpoints {\n validateBreakpointsInput(input)\n\n const sorted = Object.entries(input)\n .map(([id, value]) => ({ ...value, id }))\n .sort((a, b) => b.width - a.width) // Sort by width in descending order\n\n const transformed = sorted.reduce(\n (prev, curr, index, array) => {\n const { width, viewport, id, label } = curr\n const next = array[index + 1]\n\n const breakpoint: Breakpoint = {\n id,\n ...(label && { label }),\n ...(next && { minWidth: next.width + 1 }),\n maxWidth: width,\n viewportWidth: viewport ?? width,\n }\n\n return [...prev, breakpoint]\n },\n [\n { id: DefaultBreakpointID.Desktop, label: 'Desktop', minWidth: sorted[0].width + 1 },\n ] as Breakpoints,\n )\n\n return transformed\n}\n\nfunction validateBreakpointsInput(input: BreakpointsInput) {\n if (DefaultBreakpointID.Desktop in input) {\n throw new Error(\n `Cannot change the base breakpoint. \"${DefaultBreakpointID.Desktop}\" is reserved as the base breakpoint.`,\n )\n }\n\n if (Object.keys(input).length === 0) {\n throw new Error(`Breakpoints cannot be empty. You must provide at least one breakpoint.`)\n }\n\n const sorted = Object.entries(input)\n .map(([id, value]) => ({ ...value, id }))\n .sort((a, b) => b.width - a.width) // Sort by width in descending order\n\n sorted.forEach(({ id, width, viewport }, index, array) => {\n // This is only valid for desktop-first. We need to check the inverse for mobile-first.\n if (viewport && viewport > width) {\n throw new Error(\n `Error on breakpoint \"${id}\". Viewport cannot be greater than its width.\n \"${id}\" has a viewport of ${viewport}px and a width of ${width}px.`,\n )\n }\n\n const next = array[index + 1]\n\n if (viewport && next && viewport < next.width) {\n throw new Error(\n `Error on breakpoint \"${id}\". Viewport cannot be smaller than the next breakpoint's width. \n \"${id}\" has a viewport of ${viewport}px and the next breakpoint \"${next.id}\" has a width of ${next.width}px.`,\n )\n }\n\n if (next && width === next.width) {\n throw new Error(\n `Breakpoints cannot have the same width. \"${id}\" and \"${next.id}\" have the same width`,\n )\n }\n })\n}\n\n// Sort breakpoints by minWidth in descending order\nfunction sortBreakpoints(breakpoints: Breakpoints): Breakpoints {\n return breakpoints.sort((a, b) => (b?.minWidth ?? 0) - (a?.minWidth ?? 0))\n}\n\nexport const getBreakpoint = (state: State, breakpointId: Breakpoint['id']): Breakpoint => {\n const breakpoint = state.find(({ id }) => id === breakpointId)\n\n if (breakpoint == null) throw new Error(`Unrecognized breakpoint ID: \"${breakpointId}\".`)\n\n return breakpoint\n}\n\nexport const getBaseBreakpoint = (breakpoints: Breakpoints): Breakpoint => {\n const breakpoint = sortBreakpoints(breakpoints)[0]\n\n if (breakpoint == null) throw new Error(`Cannot get base breakpoint.`)\n\n return breakpoint\n}\n\nexport function findBreakpointOverride<S>(\n breakpoints: Breakpoints,\n values: ResponsiveValue<S> = [],\n deviceId: string,\n strategy: FallbackStrategy<S> = defaultStrategy,\n): DeviceOverride<S> | undefined {\n const value = values.find(({ deviceId: d }) => d === deviceId)\n const fallbacks = breakpoints\n .slice(0, breakpoints.findIndex(d => d.id === deviceId) + 1)\n .reverse()\n .map(d => values.find(v => v.deviceId === d.id))\n .filter((override): override is DeviceOverride<S> => Boolean(override))\n\n return value != null || fallbacks.length > 0 ? strategy(value, fallbacks) : undefined\n}\n\nexport type FallbackStrategy<V> = (\n arg0: DeviceOverride<V> | undefined,\n arg1: ResponsiveValue<V>,\n) => DeviceOverride<V> | undefined\n\nfunction defaultStrategy<V>(\n value: DeviceOverride<V> | undefined,\n fallbacks: ResponsiveValue<V>,\n): DeviceOverride<V> | undefined {\n return value || fallbacks[0]\n}\n\nexport function shallowMergeFallbacks<V extends Record<string, unknown>>(\n value: DeviceOverride<V> | undefined,\n fallbacks: ResponsiveValue<V>,\n): DeviceOverride<V> | undefined {\n return [value, ...fallbacks]\n .filter((override): override is DeviceOverride<V> => Boolean(override))\n .reduce((a, b) => ({\n deviceId: a.deviceId || b.deviceId,\n value: shallowMerge(a.value, b.value),\n }))\n}\n\nfunction mergeOrCoalesce<A extends Data>(a: A, b: A): A {\n if (\n typeof a === 'object' &&\n a !== null &&\n !Array.isArray(a) &&\n typeof b === 'object' &&\n b !== null &&\n !Array.isArray(b)\n ) {\n return shallowMerge(a, b) as A\n }\n return coalesce(a, b)\n}\n\nexport function mergeOrCoalesceFallbacks<V extends Data>(\n value: DeviceOverride<V> | undefined,\n fallbacks: ResponsiveValue<V>,\n): DeviceOverride<V> | undefined {\n return [value, ...fallbacks]\n .filter((override): override is DeviceOverride<V> => Boolean(override))\n .reduce((a, b) => ({\n deviceId: a.deviceId || b.deviceId,\n value: mergeOrCoalesce(a.value, b.value),\n }))\n}\n\nexport type ExtractResponsiveValue<T> = T extends ResponsiveValue<infer V> ? V : never\n\nexport function join<V, A extends ReadonlyArray<ResponsiveValue<V> | null | undefined>, R>(\n breakpoints: Breakpoints,\n responsiveValues: A,\n joinFn: (values: { [I in keyof A]: ExtractResponsiveValue<A[I]> | undefined }) => R,\n strategy?: FallbackStrategy<V>,\n): ResponsiveValue<R> {\n return breakpoints\n .map(({ id }) => id)\n .map(deviceId => {\n const value = joinFn(\n responsiveValues.map(responsiveValue => {\n const deviceValue =\n responsiveValue &&\n findBreakpointOverride(breakpoints, responsiveValue, deviceId, strategy)\n\n return deviceValue == null ? undefined : deviceValue.value\n }) as unknown as { [I in keyof A]: ExtractResponsiveValue<A[I] | undefined> },\n )\n\n if (value == null) return null\n\n return { deviceId, value }\n })\n .filter((override): override is NonNullable<typeof override> => Boolean(override))\n}\n\nexport const getBreakpointMediaQuery = (breakpoint: Breakpoint): string => {\n const parts = ['@media only screen']\n\n if (breakpoint.minWidth != null) {\n parts.push(`(min-width: ${breakpoint.minWidth}px)`)\n }\n\n if (breakpoint.maxWidth != null) {\n parts.push(`(max-width: ${breakpoint.maxWidth}px)`)\n }\n\n return parts.join(' and ')\n}\n\nexport const getViewportStyle = (\n state: State,\n deviceId: string,\n): Viewport<string | number> | null | undefined => {\n const device = getBreakpoint(state, deviceId)\n\n return (\n device && {\n width: device.viewportWidth != null ? device.viewportWidth : '100%',\n minWidth: device.minWidth,\n }\n )\n}\n\nexport function findNextFallback<V>(\n breakpoints: Breakpoints,\n value: ResponsiveValue<V>,\n deviceId: BreakpointId,\n activeDeviceId: BreakpointId,\n fallbackStrategy?: FallbackStrategy<V>,\n): Breakpoint | null {\n const deviceOverride = findBreakpointOverride(\n breakpoints,\n value.filter(v => v.deviceId !== activeDeviceId),\n deviceId,\n fallbackStrategy,\n )\n\n return (deviceOverride && getBreakpoint(breakpoints, deviceOverride.deviceId)) ?? null\n}\n\nexport const mergeResponsiveValues = <A>(\n breakpoints: Breakpoints,\n source: DeviceOverride<A>[],\n override: DeviceOverride<A>[],\n): DeviceOverride<A>[] => {\n const devices = [\n ...new Set(\n source.map(({ deviceId }) => deviceId).concat(override.map(({ deviceId }) => deviceId)),\n ),\n ]\n\n return devices.map(deviceId => ({\n deviceId,\n value: {\n ...(findBreakpointOverride(breakpoints, source, deviceId) || { value: {} }).value,\n ...(findBreakpointOverride(breakpoints, override, deviceId, v => v) || { value: {} }).value,\n },\n })) as DeviceOverride<A>[]\n}\n"],"names":["ActionTypes"],"mappings":";;;;;;;;;;;;;;;;;;;;;AAAA,MAAM,OAAO,CAAuC,MAAsB,OAAO,KAAK,CAAC;ACAvF,MAAM,WAAW,IAAO,SAAsB;AACxC,MAAA;AAEJ,OAAK,IAAI,GAAG,IAAI,KAAK,SAAS,GAAG,KAAK,GAAG;AACvC,QAAI,KAAK,MAAM;AAAM,aAAO,KAAK;AAAA,EACnC;AAEA,SAAO,KAAK;AACd;ACLA,sBAGE,GAAM,GAAa;AACb,QAAA,QAAQ,KAAK,CAAC;AACd,QAAA,SAAS,mBAAK;AAEpB,QAAM,QAAQ,CAAO,QAAA;AAEnB,WAAO,OAAO,SAAS,OAAO,MAAM,EAAE,IAAI;AAAA,EAAA,CAC3C;AAEM,SAAA;AACT;ACYO,MAAM,sBAAsB;AAAA,EACjC,SAAS;AAAA,EACT,QAAQ;AAAA,EACR,QAAQ;AACV;AAIO,MAAM,sBAAmC;AAAA,EAC9C;AAAA,IACE,IAAI,oBAAoB;AAAA,IACxB,OAAO;AAAA,IACP,UAAU;AAAA,EACZ;A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QAAQ,IAAI,CAAa,aAAA;AAAA,IAC9B;AAAA,IACA,OAAO,kCACD,wBAAuB,aAAa,QAAQ,QAAQ,KAAK,EAAE,OAAO,CAAC,EAAA,GAAK,QACxE,wBAAuB,aAAa,UAAU,UAAU,CAAA,MAAK,CAAC,KAAK,EAAE,OAAO,CAAA,EAAM,GAAA;AAAA,EAExF,EAAA;AACJ;;;;;;;;;;;;;;;;;;"}
@@ -0,0 +1,206 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __defProps = Object.defineProperties;
3
+ var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
4
+ var __getOwnPropSymbols = Object.getOwnPropertySymbols;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __propIsEnum = Object.prototype.propertyIsEnumerable;
7
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
8
+ var __spreadValues = (a, b) => {
9
+ for (var prop in b || (b = {}))
10
+ if (__hasOwnProp.call(b, prop))
11
+ __defNormalProp(a, prop, b[prop]);
12
+ if (__getOwnPropSymbols)
13
+ for (var prop of __getOwnPropSymbols(b)) {
14
+ if (__propIsEnum.call(b, prop))
15
+ __defNormalProp(a, prop, b[prop]);
16
+ }
17
+ return a;
18
+ };
19
+ var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
20
+ import { A as ActionTypes } from "./actions.es.js";
21
+ const keys = (o) => Object.keys(o);
22
+ const coalesce = (...args) => {
23
+ let i;
24
+ for (i = 0; i < args.length - 1; i += 1) {
25
+ if (args[i] != null)
26
+ return args[i];
27
+ }
28
+ return args[i];
29
+ };
30
+ function shallowMerge(a, b) {
31
+ const bKeys = keys(b);
32
+ const merged = __spreadValues({}, a);
33
+ bKeys.forEach((key) => {
34
+ merged[key] = coalesce(merged[key], b[key]);
35
+ });
36
+ return merged;
37
+ }
38
+ const DefaultBreakpointID = {
39
+ Desktop: "desktop",
40
+ Tablet: "tablet",
41
+ Mobile: "mobile"
42
+ };
43
+ const DEFAULT_BREAKPOINTS = [
44
+ {
45
+ id: DefaultBreakpointID.Desktop,
46
+ label: "Desktop",
47
+ minWidth: 769
48
+ },
49
+ {
50
+ id: DefaultBreakpointID.Tablet,
51
+ label: "Tablet",
52
+ minWidth: 576,
53
+ maxWidth: 768,
54
+ viewportWidth: 760
55
+ },
56
+ {
57
+ id: DefaultBreakpointID.Mobile,
58
+ label: "Mobile",
59
+ maxWidth: 575,
60
+ viewportWidth: 390
61
+ }
62
+ ];
63
+ function getInitialState(breakpoints = DEFAULT_BREAKPOINTS) {
64
+ return breakpoints;
65
+ }
66
+ function reducer(state = getInitialState(), action) {
67
+ switch (action.type) {
68
+ case ActionTypes.SET_BREAKPOINTS: {
69
+ const breakpoints = action.payload.breakpoints;
70
+ if (breakpoints.length === 0)
71
+ throw new Error("Breakpoints cannot be empty.");
72
+ return breakpoints;
73
+ }
74
+ default:
75
+ return state;
76
+ }
77
+ }
78
+ function parseBreakpointsInput(input) {
79
+ validateBreakpointsInput(input);
80
+ const sorted = Object.entries(input).map(([id, value]) => __spreadProps(__spreadValues({}, value), { id })).sort((a, b) => b.width - a.width);
81
+ const transformed = sorted.reduce((prev, curr, index, array) => {
82
+ const { width, viewport, id, label } = curr;
83
+ const next = array[index + 1];
84
+ const breakpoint = __spreadProps(__spreadValues(__spreadValues({
85
+ id
86
+ }, label && { label }), next && { minWidth: next.width + 1 }), {
87
+ maxWidth: width,
88
+ viewportWidth: viewport != null ? viewport : width
89
+ });
90
+ return [...prev, breakpoint];
91
+ }, [
92
+ { id: DefaultBreakpointID.Desktop, label: "Desktop", minWidth: sorted[0].width + 1 }
93
+ ]);
94
+ return transformed;
95
+ }
96
+ function validateBreakpointsInput(input) {
97
+ if (DefaultBreakpointID.Desktop in input) {
98
+ throw new Error(`Cannot change the base breakpoint. "${DefaultBreakpointID.Desktop}" is reserved as the base breakpoint.`);
99
+ }
100
+ if (Object.keys(input).length === 0) {
101
+ throw new Error(`Breakpoints cannot be empty. You must provide at least one breakpoint.`);
102
+ }
103
+ const sorted = Object.entries(input).map(([id, value]) => __spreadProps(__spreadValues({}, value), { id })).sort((a, b) => b.width - a.width);
104
+ sorted.forEach(({ id, width, viewport }, index, array) => {
105
+ if (viewport && viewport > width) {
106
+ throw new Error(`Error on breakpoint "${id}". Viewport cannot be greater than its width.
107
+ "${id}" has a viewport of ${viewport}px and a width of ${width}px.`);
108
+ }
109
+ const next = array[index + 1];
110
+ if (viewport && next && viewport < next.width) {
111
+ throw new Error(`Error on breakpoint "${id}". Viewport cannot be smaller than the next breakpoint's width.
112
+ "${id}" has a viewport of ${viewport}px and the next breakpoint "${next.id}" has a width of ${next.width}px.`);
113
+ }
114
+ if (next && width === next.width) {
115
+ throw new Error(`Breakpoints cannot have the same width. "${id}" and "${next.id}" have the same width`);
116
+ }
117
+ });
118
+ }
119
+ function sortBreakpoints(breakpoints) {
120
+ return breakpoints.sort((a, b) => {
121
+ var _a, _b;
122
+ return ((_a = b == null ? void 0 : b.minWidth) != null ? _a : 0) - ((_b = a == null ? void 0 : a.minWidth) != null ? _b : 0);
123
+ });
124
+ }
125
+ const getBreakpoint = (state, breakpointId) => {
126
+ const breakpoint = state.find(({ id }) => id === breakpointId);
127
+ if (breakpoint == null)
128
+ throw new Error(`Unrecognized breakpoint ID: "${breakpointId}".`);
129
+ return breakpoint;
130
+ };
131
+ const getBaseBreakpoint = (breakpoints) => {
132
+ const breakpoint = sortBreakpoints(breakpoints)[0];
133
+ if (breakpoint == null)
134
+ throw new Error(`Cannot get base breakpoint.`);
135
+ return breakpoint;
136
+ };
137
+ function findBreakpointOverride(breakpoints, values = [], deviceId, strategy = defaultStrategy) {
138
+ const value = values.find(({ deviceId: d }) => d === deviceId);
139
+ const fallbacks = breakpoints.slice(0, breakpoints.findIndex((d) => d.id === deviceId) + 1).reverse().map((d) => values.find((v) => v.deviceId === d.id)).filter((override) => Boolean(override));
140
+ return value != null || fallbacks.length > 0 ? strategy(value, fallbacks) : void 0;
141
+ }
142
+ function defaultStrategy(value, fallbacks) {
143
+ return value || fallbacks[0];
144
+ }
145
+ function shallowMergeFallbacks(value, fallbacks) {
146
+ return [value, ...fallbacks].filter((override) => Boolean(override)).reduce((a, b) => ({
147
+ deviceId: a.deviceId || b.deviceId,
148
+ value: shallowMerge(a.value, b.value)
149
+ }));
150
+ }
151
+ function mergeOrCoalesce(a, b) {
152
+ if (typeof a === "object" && a !== null && !Array.isArray(a) && typeof b === "object" && b !== null && !Array.isArray(b)) {
153
+ return shallowMerge(a, b);
154
+ }
155
+ return coalesce(a, b);
156
+ }
157
+ function mergeOrCoalesceFallbacks(value, fallbacks) {
158
+ return [value, ...fallbacks].filter((override) => Boolean(override)).reduce((a, b) => ({
159
+ deviceId: a.deviceId || b.deviceId,
160
+ value: mergeOrCoalesce(a.value, b.value)
161
+ }));
162
+ }
163
+ function join(breakpoints, responsiveValues, joinFn, strategy) {
164
+ return breakpoints.map(({ id }) => id).map((deviceId) => {
165
+ const value = joinFn(responsiveValues.map((responsiveValue) => {
166
+ const deviceValue = responsiveValue && findBreakpointOverride(breakpoints, responsiveValue, deviceId, strategy);
167
+ return deviceValue == null ? void 0 : deviceValue.value;
168
+ }));
169
+ if (value == null)
170
+ return null;
171
+ return { deviceId, value };
172
+ }).filter((override) => Boolean(override));
173
+ }
174
+ const getBreakpointMediaQuery = (breakpoint) => {
175
+ const parts = ["@media only screen"];
176
+ if (breakpoint.minWidth != null) {
177
+ parts.push(`(min-width: ${breakpoint.minWidth}px)`);
178
+ }
179
+ if (breakpoint.maxWidth != null) {
180
+ parts.push(`(max-width: ${breakpoint.maxWidth}px)`);
181
+ }
182
+ return parts.join(" and ");
183
+ };
184
+ const getViewportStyle = (state, deviceId) => {
185
+ const device = getBreakpoint(state, deviceId);
186
+ return device && {
187
+ width: device.viewportWidth != null ? device.viewportWidth : "100%",
188
+ minWidth: device.minWidth
189
+ };
190
+ };
191
+ function findNextFallback(breakpoints, value, deviceId, activeDeviceId, fallbackStrategy) {
192
+ var _a;
193
+ const deviceOverride = findBreakpointOverride(breakpoints, value.filter((v) => v.deviceId !== activeDeviceId), deviceId, fallbackStrategy);
194
+ return (_a = deviceOverride && getBreakpoint(breakpoints, deviceOverride.deviceId)) != null ? _a : null;
195
+ }
196
+ const mergeResponsiveValues = (breakpoints, source, override) => {
197
+ const devices = [
198
+ ...new Set(source.map(({ deviceId }) => deviceId).concat(override.map(({ deviceId }) => deviceId)))
199
+ ];
200
+ return devices.map((deviceId) => ({
201
+ deviceId,
202
+ value: __spreadValues(__spreadValues({}, (findBreakpointOverride(breakpoints, source, deviceId) || { value: {} }).value), (findBreakpointOverride(breakpoints, override, deviceId, (v) => v) || { value: {} }).value)
203
+ }));
204
+ };
205
+ export { DefaultBreakpointID as D, getBaseBreakpoint as a, getBreakpoint as b, getBreakpointMediaQuery as c, shallowMergeFallbacks as d, DEFAULT_BREAKPOINTS as e, findBreakpointOverride as f, getInitialState as g, getViewportStyle as h, findNextFallback as i, join as j, keys as k, mergeResponsiveValues as l, mergeOrCoalesceFallbacks as m, parseBreakpointsInput as p, reducer as r, shallowMerge as s };
206
+ //# sourceMappingURL=breakpoints.es.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"breakpoints.es.js","sources":["../src/utils/keys.ts","../src/utils/coalesce.ts","../src/utils/shallowMerge.ts","../src/state/modules/breakpoints.ts"],"sourcesContent":["const keys = <O extends { [key: string]: unknown }>(o: O): (keyof O)[] => Object.keys(o)\n\nexport default keys\n","const coalesce = <T>(...args: Array<T>): T => {\n let i: number\n\n for (i = 0; i < args.length - 1; i += 1) {\n if (args[i] != null) return args[i]\n }\n\n return args[i]\n}\n\nexport default coalesce\n","import keys from './keys'\nimport coalesce from './coalesce'\n\nexport default function shallowMerge<\n A extends Record<string, unknown>,\n B extends Record<string, unknown>,\n>(a: A, b: B): A & B {\n const bKeys = keys(b)\n const merged = { ...a } as A & B\n\n bKeys.forEach(key => {\n // @ts-expect-error: `coalesce` returns `null | undefined` regardless of input guarantees.\n merged[key] = coalesce(merged[key], b[key])\n })\n\n return merged\n}\n","import { Viewport } from 'csstype'\n\nimport {\n ResponsiveValue as PropControllerResponsiveValue,\n DeviceOverride as PropControllerDeviceOverride,\n Device as DeviceId,\n} from '../../prop-controllers'\nimport shallowMerge from '../../utils/shallowMerge'\nimport { Action, ActionTypes } from '../actions'\nimport coalesce from '../../utils/coalesce'\nimport { Data } from '../../controls/types'\n\nexport type DeviceOverride<T> = PropControllerDeviceOverride<T>\nexport type ResponsiveValue<T> = PropControllerResponsiveValue<T>\nexport type BreakpointId = DeviceId\n\nexport type Breakpoint = {\n id: BreakpointId\n label?: string\n viewportWidth?: number\n minWidth?: number\n maxWidth?: number\n}\n\nexport type Breakpoints = Breakpoint[]\n\nexport type State = Breakpoints\n\nexport const DefaultBreakpointID = {\n Desktop: 'desktop',\n Tablet: 'tablet',\n Mobile: 'mobile',\n} as const\n\ntype DefaultBreakpointID = typeof DefaultBreakpointID[keyof typeof DefaultBreakpointID]\n\nexport const DEFAULT_BREAKPOINTS: Breakpoints = [\n {\n id: DefaultBreakpointID.Desktop,\n label: 'Desktop',\n minWidth: 769,\n },\n {\n id: DefaultBreakpointID.Tablet,\n label: 'Tablet',\n minWidth: 576,\n maxWidth: 768,\n viewportWidth: 760,\n },\n {\n id: DefaultBreakpointID.Mobile,\n label: 'Mobile',\n maxWidth: 575,\n viewportWidth: 390,\n },\n]\n\nexport function getInitialState(breakpoints = DEFAULT_BREAKPOINTS): State {\n return breakpoints\n}\n\nexport function reducer(state: State = getInitialState(), action: Action): State {\n switch (action.type) {\n case ActionTypes.SET_BREAKPOINTS: {\n const breakpoints = action.payload.breakpoints\n\n if (breakpoints.length === 0) throw new Error('Breakpoints cannot be empty.')\n\n return breakpoints\n }\n\n default:\n return state\n }\n}\n\nexport type BreakpointsInput = Record<string, { width: number; label?: string; viewport?: number }>\n\nexport function parseBreakpointsInput(input: BreakpointsInput): Breakpoints {\n validateBreakpointsInput(input)\n\n const sorted = Object.entries(input)\n .map(([id, value]) => ({ ...value, id }))\n .sort((a, b) => b.width - a.width) // Sort by width in descending order\n\n const transformed = sorted.reduce(\n (prev, curr, index, array) => {\n const { width, viewport, id, label } = curr\n const next = array[index + 1]\n\n const breakpoint: Breakpoint = {\n id,\n ...(label && { label }),\n ...(next && { minWidth: next.width + 1 }),\n maxWidth: width,\n viewportWidth: viewport ?? width,\n }\n\n return [...prev, breakpoint]\n },\n [\n { id: DefaultBreakpointID.Desktop, label: 'Desktop', minWidth: sorted[0].width + 1 },\n ] as Breakpoints,\n )\n\n return transformed\n}\n\nfunction validateBreakpointsInput(input: BreakpointsInput) {\n if (DefaultBreakpointID.Desktop in input) {\n throw new Error(\n `Cannot change the base breakpoint. \"${DefaultBreakpointID.Desktop}\" is reserved as the base breakpoint.`,\n )\n }\n\n if (Object.keys(input).length === 0) {\n throw new Error(`Breakpoints cannot be empty. You must provide at least one breakpoint.`)\n }\n\n const sorted = Object.entries(input)\n .map(([id, value]) => ({ ...value, id }))\n .sort((a, b) => b.width - a.width) // Sort by width in descending order\n\n sorted.forEach(({ id, width, viewport }, index, array) => {\n // This is only valid for desktop-first. We need to check the inverse for mobile-first.\n if (viewport && viewport > width) {\n throw new Error(\n `Error on breakpoint \"${id}\". Viewport cannot be greater than its width.\n \"${id}\" has a viewport of ${viewport}px and a width of ${width}px.`,\n )\n }\n\n const next = array[index + 1]\n\n if (viewport && next && viewport < next.width) {\n throw new Error(\n `Error on breakpoint \"${id}\". Viewport cannot be smaller than the next breakpoint's width. \n \"${id}\" has a viewport of ${viewport}px and the next breakpoint \"${next.id}\" has a width of ${next.width}px.`,\n )\n }\n\n if (next && width === next.width) {\n throw new Error(\n `Breakpoints cannot have the same width. \"${id}\" and \"${next.id}\" have the same width`,\n )\n }\n })\n}\n\n// Sort breakpoints by minWidth in descending order\nfunction sortBreakpoints(breakpoints: Breakpoints): Breakpoints {\n return breakpoints.sort((a, b) => (b?.minWidth ?? 0) - (a?.minWidth ?? 0))\n}\n\nexport const getBreakpoint = (state: State, breakpointId: Breakpoint['id']): Breakpoint => {\n const breakpoint = state.find(({ id }) => id === breakpointId)\n\n if (breakpoint == null) throw new Error(`Unrecognized breakpoint ID: \"${breakpointId}\".`)\n\n return breakpoint\n}\n\nexport const getBaseBreakpoint = (breakpoints: Breakpoints): Breakpoint => {\n const breakpoint = sortBreakpoints(breakpoints)[0]\n\n if (breakpoint == null) throw new Error(`Cannot get base breakpoint.`)\n\n return breakpoint\n}\n\nexport function findBreakpointOverride<S>(\n breakpoints: Breakpoints,\n values: ResponsiveValue<S> = [],\n deviceId: string,\n strategy: FallbackStrategy<S> = defaultStrategy,\n): DeviceOverride<S> | undefined {\n const value = values.find(({ deviceId: d }) => d === deviceId)\n const fallbacks = breakpoints\n .slice(0, breakpoints.findIndex(d => d.id === deviceId) + 1)\n .reverse()\n .map(d => values.find(v => v.deviceId === d.id))\n .filter((override): override is DeviceOverride<S> => Boolean(override))\n\n return value != null || fallbacks.length > 0 ? strategy(value, fallbacks) : undefined\n}\n\nexport type FallbackStrategy<V> = (\n arg0: DeviceOverride<V> | undefined,\n arg1: ResponsiveValue<V>,\n) => DeviceOverride<V> | undefined\n\nfunction defaultStrategy<V>(\n value: DeviceOverride<V> | undefined,\n fallbacks: ResponsiveValue<V>,\n): DeviceOverride<V> | undefined {\n return value || fallbacks[0]\n}\n\nexport function shallowMergeFallbacks<V extends Record<string, unknown>>(\n value: DeviceOverride<V> | undefined,\n fallbacks: ResponsiveValue<V>,\n): DeviceOverride<V> | undefined {\n return [value, ...fallbacks]\n .filter((override): override is DeviceOverride<V> => Boolean(override))\n .reduce((a, b) => ({\n deviceId: a.deviceId || b.deviceId,\n value: shallowMerge(a.value, b.value),\n }))\n}\n\nfunction mergeOrCoalesce<A extends Data>(a: A, b: A): A {\n if (\n typeof a === 'object' &&\n a !== null &&\n !Array.isArray(a) &&\n typeof b === 'object' &&\n b !== null &&\n !Array.isArray(b)\n ) {\n return shallowMerge(a, b) as A\n }\n return coalesce(a, b)\n}\n\nexport function mergeOrCoalesceFallbacks<V extends Data>(\n value: DeviceOverride<V> | undefined,\n fallbacks: ResponsiveValue<V>,\n): DeviceOverride<V> | undefined {\n return [value, ...fallbacks]\n .filter((override): override is DeviceOverride<V> => Boolean(override))\n .reduce((a, b) => ({\n deviceId: a.deviceId || b.deviceId,\n value: mergeOrCoalesce(a.value, b.value),\n }))\n}\n\nexport type ExtractResponsiveValue<T> = T extends ResponsiveValue<infer V> ? V : never\n\nexport function join<V, A extends ReadonlyArray<ResponsiveValue<V> | null | undefined>, R>(\n breakpoints: Breakpoints,\n responsiveValues: A,\n joinFn: (values: { [I in keyof A]: ExtractResponsiveValue<A[I]> | undefined }) => R,\n strategy?: FallbackStrategy<V>,\n): ResponsiveValue<R> {\n return breakpoints\n .map(({ id }) => id)\n .map(deviceId => {\n const value = joinFn(\n responsiveValues.map(responsiveValue => {\n const deviceValue =\n responsiveValue &&\n findBreakpointOverride(breakpoints, responsiveValue, deviceId, strategy)\n\n return deviceValue == null ? undefined : deviceValue.value\n }) as unknown as { [I in keyof A]: ExtractResponsiveValue<A[I] | undefined> },\n )\n\n if (value == null) return null\n\n return { deviceId, value }\n })\n .filter((override): override is NonNullable<typeof override> => Boolean(override))\n}\n\nexport const getBreakpointMediaQuery = (breakpoint: Breakpoint): string => {\n const parts = ['@media only screen']\n\n if (breakpoint.minWidth != null) {\n parts.push(`(min-width: ${breakpoint.minWidth}px)`)\n }\n\n if (breakpoint.maxWidth != null) {\n parts.push(`(max-width: ${breakpoint.maxWidth}px)`)\n }\n\n return parts.join(' and ')\n}\n\nexport const getViewportStyle = (\n state: State,\n deviceId: string,\n): Viewport<string | number> | null | undefined => {\n const device = getBreakpoint(state, deviceId)\n\n return (\n device && {\n width: device.viewportWidth != null ? device.viewportWidth : '100%',\n minWidth: device.minWidth,\n }\n )\n}\n\nexport function findNextFallback<V>(\n breakpoints: Breakpoints,\n value: ResponsiveValue<V>,\n deviceId: BreakpointId,\n activeDeviceId: BreakpointId,\n fallbackStrategy?: FallbackStrategy<V>,\n): Breakpoint | null {\n const deviceOverride = findBreakpointOverride(\n breakpoints,\n value.filter(v => v.deviceId !== activeDeviceId),\n deviceId,\n fallbackStrategy,\n )\n\n return (deviceOverride && getBreakpoint(breakpoints, deviceOverride.deviceId)) ?? null\n}\n\nexport const mergeResponsiveValues = <A>(\n breakpoints: Breakpoints,\n source: DeviceOverride<A>[],\n override: DeviceOverride<A>[],\n): DeviceOverride<A>[] => {\n const devices = [\n ...new Set(\n source.map(({ deviceId }) => deviceId).concat(override.map(({ deviceId }) => deviceId)),\n ),\n ]\n\n return devices.map(deviceId => ({\n deviceId,\n value: {\n ...(findBreakpointOverride(breakpoints, source, deviceId) || { value: {} }).value,\n ...(findBreakpointOverride(breakpoints, override, deviceId, v => v) || { value: {} }).value,\n },\n })) as DeviceOverride<A>[]\n}\n"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA,MAAM,OAAO,CAAuC,MAAsB,OAAO,KAAK,CAAC;ACAvF,MAAM,WAAW,IAAO,SAAsB;AACxC,MAAA;AAEJ,OAAK,IAAI,GAAG,IAAI,KAAK,SAAS,GAAG,KAAK,GAAG;AACvC,QAAI,KAAK,MAAM;AAAM,aAAO,KAAK;AAAA,EACnC;AAEA,SAAO,KAAK;AACd;ACLA,sBAGE,GAAM,GAAa;AACb,QAAA,QAAQ,KAAK,CAAC;AACd,QAAA,SAAS,mBAAK;AAEpB,QAAM,QAAQ,CAAO,QAAA;AAEnB,WAAO,OAAO,SAAS,OAAO,MAAM,EAAE,IAAI;AAAA,EAAA,CAC3C;AAEM,SAAA;AACT;ACYO,MAAM,sBAAsB;AAAA,EACjC,SAAS;AAAA,EACT,QAAQ;AAAA,EACR,QAAQ;AACV;AAIO,MAAM,sBAAmC;AAAA,EAC9C;AAAA,IACE,IAAI,oBAAoB;AAAA,IACxB,OAAO;AAAA,IACP,UAAU;AAAA,EACZ;AAAA,EACA;AAAA,IACE,IAAI,oBAA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AAA,IACA,OAAO,kCACD,wBAAuB,aAAa,QAAQ,QAAQ,KAAK,EAAE,OAAO,CAAC,EAAA,GAAK,QACxE,wBAAuB,aAAa,UAAU,UAAU,CAAA,MAAK,CAAC,KAAK,EAAE,OAAO,CAAA,EAAM,GAAA;AAAA,EAExF,EAAA;AACJ;;"}
@@ -7,7 +7,7 @@ require("redux");
7
7
  require("redux-thunk");
8
8
  require("./actions.cjs.js");
9
9
  require("zod");
10
- require("./state/breakpoints.cjs.js");
10
+ require("./breakpoints.cjs.js");
11
11
  require("ts-pattern");
12
12
  require("corporate-ipsum");
13
13
  require("slate");
@@ -5,7 +5,7 @@ import "redux";
5
5
  import "redux-thunk";
6
6
  import "./actions.es.js";
7
7
  import "zod";
8
- import "./state/breakpoints.es.js";
8
+ import "./breakpoints.es.js";
9
9
  import "ts-pattern";
10
10
  import "corporate-ipsum";
11
11
  import "slate";
@@ -25,7 +25,7 @@ require("redux");
25
25
  require("redux-thunk");
26
26
  require("./actions.cjs.js");
27
27
  require("zod");
28
- require("./state/breakpoints.cjs.js");
28
+ require("./breakpoints.cjs.js");
29
29
  require("ts-pattern");
30
30
  require("corporate-ipsum");
31
31
  require("slate");
@@ -23,7 +23,7 @@ import "redux";
23
23
  import "redux-thunk";
24
24
  import "./actions.es.js";
25
25
  import "zod";
26
- import "./state/breakpoints.es.js";
26
+ import "./breakpoints.es.js";
27
27
  import "ts-pattern";
28
28
  import "corporate-ipsum";
29
29
  import "slate";
@@ -41,7 +41,7 @@ require("slate-hyperscript");
41
41
  require("parse5");
42
42
  require("is-hotkey");
43
43
  require("react/jsx-runtime");
44
- require("./state/breakpoints.cjs.js");
44
+ require("./breakpoints.cjs.js");
45
45
  function isSerializedFunction(value) {
46
46
  return value instanceof MessagePort;
47
47
  }
@@ -41,7 +41,7 @@ import "slate-hyperscript";
41
41
  import "parse5";
42
42
  import "is-hotkey";
43
43
  import "react/jsx-runtime";
44
- import "./state/breakpoints.es.js";
44
+ import "./breakpoints.es.js";
45
45
  function isSerializedFunction(value) {
46
46
  return value instanceof MessagePort;
47
47
  }
@@ -7,7 +7,7 @@ require("redux");
7
7
  require("redux-thunk");
8
8
  require("./actions.cjs.js");
9
9
  require("zod");
10
- require("./state/breakpoints.cjs.js");
10
+ require("./breakpoints.cjs.js");
11
11
  require("ts-pattern");
12
12
  require("corporate-ipsum");
13
13
  require("slate");
@@ -5,7 +5,7 @@ import "redux";
5
5
  import "redux-thunk";
6
6
  import "./actions.es.js";
7
7
  import "zod";
8
- import "./state/breakpoints.es.js";
8
+ import "./breakpoints.es.js";
9
9
  import "ts-pattern";
10
10
  import "corporate-ipsum";
11
11
  import "slate";
package/dist/index.cjs.js CHANGED
@@ -50,7 +50,7 @@ require("escape-html");
50
50
  require("slate-hyperscript");
51
51
  require("parse5");
52
52
  require("is-hotkey");
53
- var state_breakpoints = require("./state/breakpoints.cjs.js");
53
+ var state_breakpoints = require("./breakpoints.cjs.js");
54
54
  var shim = require("use-sync-external-store/shim");
55
55
  var redux = require("redux");
56
56
  var thunk = require("redux-thunk");
@@ -245,9 +245,13 @@ function fetchAPIResource(resourceType, resourceId, locale) {
245
245
  resource = await fetchJson(`/api/makeswift/localized-global-elements/${resourceId}/${locale}`);
246
246
  break;
247
247
  }
248
- case types.APIResourceType.PagePathnameSlice:
249
- resource = await fetchJson(`/api/makeswift/page-pathname-slices/${resourceId}?locale=${locale}`);
248
+ case types.APIResourceType.PagePathnameSlice: {
249
+ const url = new URL(`/api/makeswift/page-pathname-slices/${resourceId}`, "http://n");
250
+ if (locale != null)
251
+ url.searchParams.set("locale", locale.toString());
252
+ resource = await fetchJson(url.pathname + url.search);
250
253
  break;
254
+ }
251
255
  case types.APIResourceType.Table:
252
256
  resource = await fetchJson(`/api/makeswift/tables/${resourceId}`);
253
257
  break;
@@ -879,6 +883,8 @@ Received "${apiKey}" instead.`);
879
883
  }
880
884
  async getTypographies(typographyIds, preview) {
881
885
  var _a;
886
+ if (typographyIds.length === 0)
887
+ return [];
882
888
  const url = new URL(`${this.siteVersion == null ? "v1" : "v2"}/typographies/bulk`, this.apiOrigin);
883
889
  typographyIds.forEach((id) => {
884
890
  url.searchParams.append("ids", id);
@@ -897,6 +903,8 @@ Received "${apiKey}" instead.`);
897
903
  }
898
904
  async getSwatches(ids, preview) {
899
905
  var _a;
906
+ if (ids.length === 0)
907
+ return [];
900
908
  const url = new URL(`${this.siteVersion == null ? "v1" : "v2"}/swatches/bulk`, this.apiOrigin);
901
909
  ids.forEach((id) => {
902
910
  url.searchParams.append("ids", id);
@@ -1122,6 +1130,8 @@ Received "${apiKey}" instead.`);
1122
1130
  }
1123
1131
  async getPagePathnameSlices(pageIds, { preview: previewOverride = false, locale } = {}) {
1124
1132
  var _a;
1133
+ if (pageIds.length === 0)
1134
+ return [];
1125
1135
  const url = new URL(`${this.siteVersion == null ? "v1" : "v2"}/page-pathname-slices/bulk`, this.apiOrigin);
1126
1136
  pageIds.forEach((id) => url.searchParams.append("ids", id));
1127
1137
  if (locale != null)
@@ -1239,7 +1249,7 @@ async function fonts(_req, res, { getFonts } = {}) {
1239
1249
  const fonts2 = (_a = await (getFonts == null ? void 0 : getFonts())) != null ? _a : [];
1240
1250
  return res.json(fonts2);
1241
1251
  }
1242
- const version = "0.11.9";
1252
+ const version = "0.11.11";
1243
1253
  async function handler(req, res, { apiKey, siteVersions }) {
1244
1254
  if (req.query.secret !== apiKey) {
1245
1255
  return res.status(401).json({ message: "Unauthorized" });
@@ -2549,7 +2559,7 @@ function registerBuiltinComponents(runtime) {
2549
2559
  }
2550
2560
  var _path;
2551
2561
  function _extends() {
2552
- _extends = Object.assign || function(target) {
2562
+ _extends = Object.assign ? Object.assign.bind() : function(target) {
2553
2563
  for (var i = 1; i < arguments.length; i++) {
2554
2564
  var source = arguments[i];
2555
2565
  for (var key in source) {