@makeswift/runtime 0.8.5 → 0.8.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.
Files changed (193) hide show
  1. package/dist/Box.cjs.js +11 -11
  2. package/dist/Box.cjs.js.map +1 -1
  3. package/dist/Box.es.js +9 -9
  4. package/dist/Box.es.js.map +1 -1
  5. package/dist/Button.cjs.js +36 -37
  6. package/dist/Button.cjs.js.map +1 -1
  7. package/dist/Button.es.js +13 -14
  8. package/dist/Button.es.js.map +1 -1
  9. package/dist/Carousel.cjs.js +38 -37
  10. package/dist/Carousel.cjs.js.map +1 -1
  11. package/dist/Carousel.es.js +19 -18
  12. package/dist/Carousel.es.js.map +1 -1
  13. package/dist/Countdown.cjs.js +55 -29
  14. package/dist/Countdown.cjs.js.map +1 -1
  15. package/dist/Countdown.es.js +35 -9
  16. package/dist/Countdown.es.js.map +1 -1
  17. package/dist/Divider.cjs.js +36 -10
  18. package/dist/Divider.cjs.js.map +1 -1
  19. package/dist/Divider.es.js +31 -5
  20. package/dist/Divider.es.js.map +1 -1
  21. package/dist/Embed.cjs.js +31 -5
  22. package/dist/Embed.cjs.js.map +1 -1
  23. package/dist/Embed.es.js +30 -4
  24. package/dist/Embed.es.js.map +1 -1
  25. package/dist/Form.cjs.js +72 -73
  26. package/dist/Form.cjs.js.map +1 -1
  27. package/dist/Form.es.js +32 -33
  28. package/dist/Form.es.js.map +1 -1
  29. package/dist/Image.cjs.js +22 -21
  30. package/dist/Image.cjs.js.map +1 -1
  31. package/dist/Image.es.js +20 -19
  32. package/dist/Image.es.js.map +1 -1
  33. package/dist/LiveProvider.cjs.js +8 -9
  34. package/dist/LiveProvider.cjs.js.map +1 -1
  35. package/dist/LiveProvider.es.js +8 -9
  36. package/dist/LiveProvider.es.js.map +1 -1
  37. package/dist/Navigation.cjs.js +33 -34
  38. package/dist/Navigation.cjs.js.map +1 -1
  39. package/dist/Navigation.es.js +14 -15
  40. package/dist/Navigation.es.js.map +1 -1
  41. package/dist/PreviewProvider.cjs.js +12 -10
  42. package/dist/PreviewProvider.cjs.js.map +1 -1
  43. package/dist/PreviewProvider.es.js +12 -10
  44. package/dist/PreviewProvider.es.js.map +1 -1
  45. package/dist/ReadOnlyText.cjs.js +15 -16
  46. package/dist/ReadOnlyText.cjs.js.map +1 -1
  47. package/dist/ReadOnlyText.es.js +11 -12
  48. package/dist/ReadOnlyText.es.js.map +1 -1
  49. package/dist/Root.cjs.js +10 -10
  50. package/dist/Root.cjs.js.map +1 -1
  51. package/dist/Root.es.js +8 -8
  52. package/dist/SocialLinks.cjs.js +12 -13
  53. package/dist/SocialLinks.cjs.js.map +1 -1
  54. package/dist/SocialLinks.es.js +7 -8
  55. package/dist/SocialLinks.es.js.map +1 -1
  56. package/dist/Text.cjs.js +3 -4
  57. package/dist/Text.cjs.js.map +1 -1
  58. package/dist/Text.es.js +4 -5
  59. package/dist/Text.es.js.map +1 -1
  60. package/dist/Video.cjs.js +31 -5
  61. package/dist/Video.cjs.js.map +1 -1
  62. package/dist/Video.es.js +30 -4
  63. package/dist/Video.es.js.map +1 -1
  64. package/dist/actions.cjs.js +6 -1
  65. package/dist/actions.cjs.js.map +1 -1
  66. package/dist/actions.es.js +6 -2
  67. package/dist/actions.es.js.map +1 -1
  68. package/dist/components.cjs.js +10 -10
  69. package/dist/components.es.js +10 -10
  70. package/dist/constants.cjs.js +7 -1
  71. package/dist/constants.cjs.js.map +1 -1
  72. package/dist/constants.es.js +7 -2
  73. package/dist/constants.es.js.map +1 -1
  74. package/dist/descriptors.cjs.js.map +1 -1
  75. package/dist/descriptors.es.js.map +1 -1
  76. package/dist/index.cjs.js +934 -120
  77. package/dist/index.cjs.js.map +1 -1
  78. package/dist/index.cjs2.js +29 -29
  79. package/dist/index.cjs2.js.map +1 -1
  80. package/dist/index.cjs3.js +1 -2
  81. package/dist/index.cjs3.js.map +1 -1
  82. package/dist/index.cjs4.js +2 -2
  83. package/dist/index.cjs4.js.map +1 -1
  84. package/dist/index.cjs5.js +6 -7
  85. package/dist/index.cjs5.js.map +1 -1
  86. package/dist/index.cjs6.js +3 -4
  87. package/dist/index.cjs6.js.map +1 -1
  88. package/dist/index.cjs7.js +16 -17
  89. package/dist/index.cjs7.js.map +1 -1
  90. package/dist/index.es.js +890 -92
  91. package/dist/index.es.js.map +1 -1
  92. package/dist/index.es2.js +6 -6
  93. package/dist/index.es2.js.map +1 -1
  94. package/dist/index.es3.js +1 -2
  95. package/dist/index.es3.js.map +1 -1
  96. package/dist/index.es4.js +2 -2
  97. package/dist/index.es4.js.map +1 -1
  98. package/dist/index.es5.js +6 -7
  99. package/dist/index.es5.js.map +1 -1
  100. package/dist/index.es6.js +3 -4
  101. package/dist/index.es6.js.map +1 -1
  102. package/dist/index.es7.js +12 -13
  103. package/dist/index.es7.js.map +1 -1
  104. package/dist/introspection.cjs.js +5 -2
  105. package/dist/introspection.cjs.js.map +1 -1
  106. package/dist/introspection.es.js +4 -2
  107. package/dist/introspection.es.js.map +1 -1
  108. package/dist/leaf.cjs.js +15 -17
  109. package/dist/leaf.cjs.js.map +1 -1
  110. package/dist/leaf.es.js +10 -11
  111. package/dist/leaf.es.js.map +1 -1
  112. package/dist/main.cjs.js +2 -1
  113. package/dist/main.cjs.js.map +1 -1
  114. package/dist/main.es.js +2 -2
  115. package/dist/next.cjs.js +5 -6
  116. package/dist/next.cjs.js.map +1 -1
  117. package/dist/next.es.js +6 -7
  118. package/dist/next.es.js.map +1 -1
  119. package/dist/prop-controllers.cjs.js +0 -1
  120. package/dist/prop-controllers.cjs.js.map +1 -1
  121. package/dist/prop-controllers.es.js +0 -1
  122. package/dist/prop-controllers.es.js.map +1 -1
  123. package/dist/react.cjs.js +3 -4
  124. package/dist/react.cjs.js.map +1 -1
  125. package/dist/react.es.js +3 -4
  126. package/dist/react.es.js.map +1 -1
  127. package/dist/slate.cjs.js +1 -12
  128. package/dist/slate.cjs.js.map +1 -1
  129. package/dist/slate.es.js +1 -12
  130. package/dist/slate.es.js.map +1 -1
  131. package/dist/state/breakpoints.cjs.js +175 -0
  132. package/dist/state/breakpoints.cjs.js.map +1 -0
  133. package/dist/state/breakpoints.es.js +160 -0
  134. package/dist/state/breakpoints.es.js.map +1 -0
  135. package/dist/types/src/components/builtin/Box/Box.d.ts.map +1 -1
  136. package/dist/types/src/components/builtin/Box/register.d.ts.map +1 -1
  137. package/dist/types/src/components/builtin/Button/Button.d.ts.map +1 -1
  138. package/dist/types/src/components/builtin/Button/register.d.ts.map +1 -1
  139. package/dist/types/src/components/builtin/Carousel/Carousel.d.ts.map +1 -1
  140. package/dist/types/src/components/builtin/Carousel/register.d.ts.map +1 -1
  141. package/dist/types/src/components/builtin/Countdown/register.d.ts.map +1 -1
  142. package/dist/types/src/components/builtin/Form/components/Field/components/Checkbox/index.d.ts +1 -1
  143. package/dist/types/src/components/builtin/Form/components/Field/components/Label/index.d.ts.map +1 -1
  144. package/dist/types/src/components/builtin/Form/register.d.ts.map +1 -1
  145. package/dist/types/src/components/builtin/Image/Image.d.ts.map +1 -1
  146. package/dist/types/src/components/builtin/Navigation/components/MobileMenu/components/MobileDropDownButton/index.d.ts.map +1 -1
  147. package/dist/types/src/components/builtin/Navigation/components/MobileMenu/index.d.ts.map +1 -1
  148. package/dist/types/src/components/builtin/Navigation/register.d.ts.map +1 -1
  149. package/dist/types/src/components/builtin/SocialLinks/register.d.ts.map +1 -1
  150. package/dist/types/src/components/builtin/Text/components/Leaf/leaf.d.ts +0 -4
  151. package/dist/types/src/components/builtin/Text/components/Leaf/leaf.d.ts.map +1 -1
  152. package/dist/types/src/components/builtin/Text/register.d.ts.map +1 -1
  153. package/dist/types/src/components/hooks/useMediaQuery.d.ts.map +1 -1
  154. package/dist/types/src/components/utils/drop-first.d.ts +2 -0
  155. package/dist/types/src/components/utils/drop-first.d.ts.map +1 -0
  156. package/dist/types/src/components/utils/responsive-style.d.ts +21 -10
  157. package/dist/types/src/components/utils/responsive-style.d.ts.map +1 -1
  158. package/dist/types/src/controls/types.d.ts +1 -1
  159. package/dist/types/src/controls/types.d.ts.map +1 -1
  160. package/dist/types/src/index.d.ts +2 -2
  161. package/dist/types/src/index.d.ts.map +1 -1
  162. package/dist/types/src/prop-controllers/descriptors.d.ts +1 -1
  163. package/dist/types/src/prop-controllers/descriptors.d.ts.map +1 -1
  164. package/dist/types/src/runtimes/react/index.d.ts +4 -0
  165. package/dist/types/src/runtimes/react/index.d.ts.map +1 -1
  166. package/dist/types/src/slate/BlockPlugin/setBlockKeyForDevice.d.ts +2 -1
  167. package/dist/types/src/slate/BlockPlugin/setBlockKeyForDevice.d.ts.map +1 -1
  168. package/dist/types/src/slate/TypographyPlugin/setActiveTypographyStyle.d.ts +2 -1
  169. package/dist/types/src/slate/TypographyPlugin/setActiveTypographyStyle.d.ts.map +1 -1
  170. package/dist/types/src/state/actions.d.ts +10 -1
  171. package/dist/types/src/state/actions.d.ts.map +1 -1
  172. package/dist/types/src/state/modules/breakpoints.d.ts +44 -0
  173. package/dist/types/src/state/modules/breakpoints.d.ts.map +1 -0
  174. package/dist/types/src/state/react-builder-preview.d.ts +2 -0
  175. package/dist/types/src/state/react-builder-preview.d.ts.map +1 -1
  176. package/dist/types/src/state/react-page.d.ts +3 -0
  177. package/dist/types/src/state/react-page.d.ts.map +1 -1
  178. package/dist/useMediaQuery.cjs.js +38 -0
  179. package/dist/useMediaQuery.cjs.js.map +1 -0
  180. package/dist/useMediaQuery.es.js +37 -0
  181. package/dist/useMediaQuery.es.js.map +1 -0
  182. package/package.json +10 -2
  183. package/state/breakpoints.js +1 -0
  184. package/dist/isNonNullable.cjs.js +0 -6
  185. package/dist/isNonNullable.cjs.js.map +0 -1
  186. package/dist/isNonNullable.es.js +0 -5
  187. package/dist/isNonNullable.es.js.map +0 -1
  188. package/dist/responsive-style.cjs.js +0 -917
  189. package/dist/responsive-style.cjs.js.map +0 -1
  190. package/dist/responsive-style.es.js +0 -853
  191. package/dist/responsive-style.es.js.map +0 -1
  192. package/dist/types/src/components/utils/devices.d.ts +0 -17
  193. package/dist/types/src/components/utils/devices.d.ts.map +0 -1
@@ -1,853 +0,0 @@
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
- var __publicField = (obj, key, value) => {
21
- __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
22
- return value;
23
- };
24
- var _a;
25
- import * as React from "react";
26
- import { createContext, useContext, useEffect, useRef } from "react";
27
- import { cache } from "@emotion/css";
28
- import { serializeStyles } from "@emotion/serialize";
29
- import { registerStyles, insertStyles } from "@emotion/utils";
30
- import { useSyncExternalStore } from "use-sync-external-store/shim";
31
- import { createStore, applyMiddleware } from "redux";
32
- import thunk from "redux-thunk";
33
- import { A as APIResourceType } from "./types.es.js";
34
- import { A as ActionTypes, o as apiResourceFulfilled } from "./actions.es.js";
35
- import { jsx } from "react/jsx-runtime";
36
- function is(x, y) {
37
- if (x === y)
38
- return x !== 0 || y !== 0 || 1 / x === 1 / y;
39
- return x !== x && y !== y;
40
- }
41
- const { hasOwnProperty: hasOwnProperty$1 } = Object.prototype;
42
- const shallowEqual = (a, b) => {
43
- if (is(a, b))
44
- return true;
45
- if (typeof a !== "object" || a === null || typeof b !== "object" || b === null)
46
- return false;
47
- const keysA = Object.keys(a);
48
- const keysB = Object.keys(b);
49
- if (keysA.length !== keysB.length)
50
- return false;
51
- for (let i = 0; i < keysA.length; i += 1) {
52
- if (!hasOwnProperty$1.call(b, keysA[i]) || !is(a[keysA[i]], b[keysA[i]]))
53
- return false;
54
- }
55
- return true;
56
- };
57
- const { hasOwnProperty } = Object.prototype;
58
- const deepEqual = (a, b) => {
59
- if (shallowEqual(a, b))
60
- return true;
61
- if (typeof a !== "object" || a === null || typeof b !== "object" || b === null)
62
- return false;
63
- const keysA = Object.keys(a);
64
- const keysB = Object.keys(b);
65
- if (keysA.length !== keysB.length)
66
- return false;
67
- for (let i = 0; i < keysA.length; i += 1) {
68
- if (!hasOwnProperty.call(b, keysA[i]) || !deepEqual(a[keysA[i]], b[keysA[i]]))
69
- return false;
70
- }
71
- return true;
72
- };
73
- function getInitialState(serializedState = {
74
- Swatch: [],
75
- File: [],
76
- Typography: [],
77
- PagePathnameSlice: [],
78
- GlobalElement: [],
79
- Table: [],
80
- Snippet: [],
81
- Page: [],
82
- Site: []
83
- }) {
84
- return new Map(Object.entries(serializedState).map(([apiResourceType, resources]) => [
85
- apiResourceType,
86
- new Map(resources.map(({ id, value }) => [id, value]))
87
- ]));
88
- }
89
- function getHasAPIResource$1(state, resourceType, resourceId) {
90
- var _a2, _b;
91
- return (_b = (_a2 = state.get(resourceType)) == null ? void 0 : _a2.has(resourceId)) != null ? _b : false;
92
- }
93
- function getAPIResource$1(state, resourceType, resourceId) {
94
- var _a2;
95
- const resource = (_a2 = state.get(resourceType)) == null ? void 0 : _a2.get(resourceId);
96
- return (resource == null ? void 0 : resource.__typename) === resourceType ? resource : null;
97
- }
98
- function reducer$1(state = getInitialState(), action) {
99
- switch (action.type) {
100
- case ActionTypes.API_RESOURCE_FULFILLED: {
101
- const { resourceType, resourceId, resource } = action.payload;
102
- return new Map(state).set(resourceType, new Map(state.get(resourceType)).set(resourceId, resource));
103
- }
104
- case ActionTypes.CHANGE_API_RESOURCE: {
105
- const existingApiResource = getAPIResource$1(state, action.payload.resource.__typename, action.payload.resource.id);
106
- if (deepEqual(existingApiResource, action.payload.resource))
107
- return state;
108
- return new Map(state).set(action.payload.resource.__typename, new Map(state.get(action.payload.resource.__typename)).set(action.payload.resource.id, action.payload.resource));
109
- }
110
- case ActionTypes.EVICT_API_RESOURCE: {
111
- const [resourceType, resourceId] = action.payload.id.split(":");
112
- if (!(resourceType in APIResourceType))
113
- return state;
114
- const resources = new Map(state.get(resourceType));
115
- const deleted = resources.delete(resourceId);
116
- return deleted ? new Map(state).set(resourceType, resources) : state;
117
- }
118
- default:
119
- return state;
120
- }
121
- }
122
- const reducer = reducer$1;
123
- function getHasAPIResource(state, resourceType, resourceId) {
124
- return getHasAPIResource$1(state, resourceType, resourceId);
125
- }
126
- function getAPIResource(state, resourceType, resourceId) {
127
- return getAPIResource$1(state, resourceType, resourceId);
128
- }
129
- async function fetchJson(url) {
130
- var _a2;
131
- const response = await fetch(url, {
132
- headers: { "Content-Type": "application/json" }
133
- });
134
- if (response.status === 404)
135
- return null;
136
- if (!response.ok)
137
- throw new Error(response.statusText);
138
- if (((_a2 = response.headers.get("content-type")) == null ? void 0 : _a2.includes("application/json")) !== true) {
139
- throw new Error(`Expected JSON response from "${url}" but got "${response.headers.get("content-type")}"`);
140
- }
141
- return response.json();
142
- }
143
- function fetchAPIResource(resourceType, resourceId) {
144
- return async (dispatch, getState) => {
145
- const state = getState();
146
- if (getHasAPIResource(state, resourceType, resourceId)) {
147
- return getAPIResource(state, resourceType, resourceId);
148
- }
149
- let resource;
150
- switch (resourceType) {
151
- case APIResourceType.Swatch:
152
- resource = await fetchJson(`/api/makeswift/swatches/${resourceId}`);
153
- break;
154
- case APIResourceType.File:
155
- resource = await fetchJson(`/api/makeswift/files/${resourceId}`);
156
- break;
157
- case APIResourceType.Typography:
158
- resource = await fetchJson(`/api/makeswift/typographies/${resourceId}`);
159
- break;
160
- case APIResourceType.GlobalElement:
161
- resource = await fetchJson(`/api/makeswift/global-elements/${resourceId}`);
162
- break;
163
- case APIResourceType.PagePathnameSlice:
164
- resource = await fetchJson(`/api/makeswift/page-pathname-slices/${resourceId}`);
165
- break;
166
- case APIResourceType.Table:
167
- resource = await fetchJson(`/api/makeswift/tables/${resourceId}`);
168
- break;
169
- default:
170
- resource = null;
171
- }
172
- dispatch(apiResourceFulfilled(resourceType, resourceId, resource));
173
- return resource;
174
- };
175
- }
176
- function configureStore({ serializedState }) {
177
- return createStore(reducer, getInitialState(serializedState), applyMiddleware(thunk));
178
- }
179
- class GraphQLClient {
180
- constructor(endpoint) {
181
- __publicField(this, "endpoint");
182
- this.endpoint = endpoint;
183
- }
184
- async request(query, variables = {}) {
185
- const response = await fetch(this.endpoint, {
186
- method: "POST",
187
- headers: { "Content-Type": "application/json" },
188
- body: JSON.stringify({ query, variables })
189
- });
190
- if (!response.ok && response.status !== 400) {
191
- throw new Error(`${response.status} ${response.statusText}`);
192
- }
193
- const body = await response.json();
194
- if (body.errors != null) {
195
- console.error(body);
196
- throw new Error("GraphQL response contains errors, check the console.");
197
- }
198
- return body.data;
199
- }
200
- }
201
- const SwatchFragment = `
202
- fragment Swatch on Swatch {
203
- __typename
204
- id
205
- hue
206
- saturation
207
- lightness
208
- }
209
- `;
210
- const FileFragment = `
211
- fragment File on File {
212
- __typename
213
- id
214
- name
215
- publicUrl: publicUrlV2
216
- extension
217
- dimensions {
218
- width
219
- height
220
- }
221
- }
222
- `;
223
- const TypographyFragment = `
224
- fragment Typography on Typography {
225
- __typename
226
- id
227
- name
228
- style {
229
- deviceId
230
- value {
231
- fontFamily
232
- fontSize {
233
- value
234
- unit
235
- }
236
- color {
237
- swatchId
238
- alpha
239
- }
240
- lineHeight
241
- letterSpacing
242
- fontWeight
243
- textAlign
244
- uppercase
245
- underline
246
- strikethrough
247
- italic
248
- }
249
- }
250
- }
251
- `;
252
- const PagePathnameSliceFragment = `
253
- fragment PagePathnameSlice on PagePathnameSlice {
254
- __typename
255
- id
256
- pathname
257
- }
258
- `;
259
- const GlobalElementFragment = `
260
- fragment GlobalElement on GlobalElement {
261
- __typename
262
- id
263
- data
264
- }
265
- `;
266
- const TableFragment = `
267
- fragment Table on Table {
268
- __typename
269
- id
270
- name
271
- columns {
272
- __typename
273
- id
274
- name
275
-
276
- ... on MultipleSelectTableColumn {
277
- options {
278
- id
279
- name
280
- }
281
- }
282
-
283
- ... on SingleSelectTableColumn {
284
- options {
285
- id
286
- name
287
- }
288
- }
289
- }
290
- }
291
- `;
292
- const IntrospectedResourcesQuery = `
293
- query IntrospectedResources(
294
- $swatchIds: [ID!]!
295
- $fileIds: [ID!]!
296
- $pageIds: [ID!]!
297
- $tableIds: [ID!]!
298
- ) {
299
- swatches(ids: $swatchIds) {
300
- ...Swatch
301
- }
302
-
303
- files(ids: $fileIds) {
304
- ...File
305
- }
306
-
307
- pagePathnamesById(ids: $pageIds) {
308
- ...PagePathnameSlice
309
- }
310
-
311
- tables(ids: $tableIds) {
312
- ...Table
313
- }
314
- }
315
-
316
- ${SwatchFragment}
317
- ${FileFragment}
318
- ${PagePathnameSliceFragment}
319
- ${TableFragment}
320
- `;
321
- const SwatchQuery = `
322
- query Swatch($swatchId: ID!) {
323
- swatch(id: $swatchId) {
324
- ...Swatch
325
- }
326
- }
327
-
328
- ${SwatchFragment}
329
- `;
330
- const FileQuery = `
331
- query File($fileId: ID!) {
332
- file(id: $fileId) {
333
- ...File
334
- }
335
- }
336
-
337
- ${FileFragment}
338
- `;
339
- const TypographyQuery = `
340
- query Typography($typographyId: ID!) {
341
- typography(id: $typographyId) {
342
- ...Typography
343
- }
344
- }
345
-
346
- ${TypographyFragment}
347
- `;
348
- const PagePathnamesByIdQuery = `
349
- query PagePathnamesById($pageIds: [ID!]!) {
350
- pagePathnamesById(ids: $pageIds) {
351
- ...PagePathnameSlice
352
- }
353
- }
354
-
355
- ${PagePathnameSliceFragment}
356
- `;
357
- const TableQuery = `
358
- query Table($tableId: ID!) {
359
- table(id: $tableId) {
360
- ...Table
361
- }
362
- }
363
-
364
- ${TableFragment}
365
- `;
366
- const TypographiesQuery = `
367
- query Typographies($typographyIds: [ID!]!) {
368
- typographies(ids: $typographyIds) {
369
- ...Typography
370
- }
371
- }
372
-
373
- ${TypographyFragment}
374
- `;
375
- const GlobalElementQuery = `
376
- query GlobalElement($globalElementId: ID!) {
377
- globalElement(id: $globalElementId) {
378
- ...GlobalElement
379
- }
380
- }
381
-
382
- ${GlobalElementFragment}
383
- `;
384
- const CreateTableRecordMutation = `
385
- mutation CreateTableRecord($input: CreateTableRecordInput!) {
386
- createTableRecord(input: $input) {
387
- tableRecord {
388
- id
389
- }
390
- }
391
- }
392
- `;
393
- class MakeswiftClient {
394
- constructor({
395
- uri,
396
- cacheData
397
- }) {
398
- __publicField(this, "graphqlClient");
399
- __publicField(this, "makeswiftApiClient");
400
- __publicField(this, "subscribe");
401
- this.graphqlClient = new GraphQLClient(uri);
402
- this.makeswiftApiClient = configureStore({
403
- serializedState: cacheData
404
- });
405
- this.subscribe = this.makeswiftApiClient.subscribe;
406
- }
407
- readSwatch(swatchId) {
408
- return getAPIResource(this.makeswiftApiClient.getState(), APIResourceType.Swatch, swatchId);
409
- }
410
- async fetchSwatch(swatchId) {
411
- return await this.makeswiftApiClient.dispatch(fetchAPIResource(APIResourceType.Swatch, swatchId));
412
- }
413
- readFile(fileId) {
414
- return getAPIResource(this.makeswiftApiClient.getState(), APIResourceType.File, fileId);
415
- }
416
- async fetchFile(fileId) {
417
- return await this.makeswiftApiClient.dispatch(fetchAPIResource(APIResourceType.File, fileId));
418
- }
419
- readTypography(typographyId) {
420
- return getAPIResource(this.makeswiftApiClient.getState(), APIResourceType.Typography, typographyId);
421
- }
422
- async fetchTypography(typographyId) {
423
- return await this.makeswiftApiClient.dispatch(fetchAPIResource(APIResourceType.Typography, typographyId));
424
- }
425
- readGlobalElement(globalElementId) {
426
- return getAPIResource(this.makeswiftApiClient.getState(), APIResourceType.GlobalElement, globalElementId);
427
- }
428
- async fetchGlobalElement(globalElementId) {
429
- return await this.makeswiftApiClient.dispatch(fetchAPIResource(APIResourceType.GlobalElement, globalElementId));
430
- }
431
- readPagePathnameSlice(pageId) {
432
- return getAPIResource(this.makeswiftApiClient.getState(), APIResourceType.PagePathnameSlice, pageId);
433
- }
434
- async fetchPagePathnameSlice(pageId) {
435
- return await this.makeswiftApiClient.dispatch(fetchAPIResource(APIResourceType.PagePathnameSlice, pageId));
436
- }
437
- readTable(tableId) {
438
- return getAPIResource(this.makeswiftApiClient.getState(), APIResourceType.Table, tableId);
439
- }
440
- async fetchTable(tableId) {
441
- return await this.makeswiftApiClient.dispatch(fetchAPIResource(APIResourceType.Table, tableId));
442
- }
443
- async createTableRecord(tableId, columns) {
444
- await this.graphqlClient.request(CreateTableRecordMutation, {
445
- input: {
446
- data: {
447
- tableId,
448
- columns
449
- }
450
- }
451
- });
452
- }
453
- readSite(siteId) {
454
- return getAPIResource(this.makeswiftApiClient.getState(), APIResourceType.Site, siteId);
455
- }
456
- readPage(pageId) {
457
- return getAPIResource(this.makeswiftApiClient.getState(), APIResourceType.Page, pageId);
458
- }
459
- readSnippet(snippetId) {
460
- return getAPIResource(this.makeswiftApiClient.getState(), APIResourceType.Snippet, snippetId);
461
- }
462
- }
463
- const Context = createContext(new MakeswiftClient({
464
- uri: "https://api.makeswift.com/graphql"
465
- }));
466
- function useMakeswiftClient() {
467
- return useContext(Context);
468
- }
469
- function MakeswiftProvider({
470
- client,
471
- children
472
- }) {
473
- return /* @__PURE__ */ jsx(Context.Provider, {
474
- value: client,
475
- children
476
- });
477
- }
478
- const keys = (o) => Object.keys(o);
479
- const coalesce = (...args) => {
480
- let i;
481
- for (i = 0; i < args.length - 1; i += 1) {
482
- if (args[i] != null)
483
- return args[i];
484
- }
485
- return args[i];
486
- };
487
- function shallowMerge(a, b) {
488
- const bKeys = keys(b);
489
- const merged = __spreadValues({}, a);
490
- bKeys.forEach((key) => {
491
- merged[key] = coalesce(merged[key], b[key]);
492
- });
493
- return merged;
494
- }
495
- const DEVICES = [
496
- { id: "desktop", minWidth: 769 },
497
- { id: "tablet", minWidth: 576, maxWidth: 768 },
498
- { id: "mobile", maxWidth: 575 }
499
- ];
500
- const getDevice = (deviceId) => {
501
- const device = DEVICES.find(({ id }) => id === deviceId);
502
- if (device == null)
503
- throw new Error(`Unrecognized device ID: "${deviceId}".`);
504
- return device;
505
- };
506
- function defaultStrategy(value, fallbacks) {
507
- return value || fallbacks[0];
508
- }
509
- function shallowMergeFallbacks(value, fallbacks) {
510
- return [value, ...fallbacks].filter((override) => Boolean(override)).reduce((a, b) => ({
511
- deviceId: a.deviceId || b.deviceId,
512
- value: shallowMerge(a.value, b.value)
513
- }));
514
- }
515
- function findDeviceOverride(values = [], deviceId, strategy = defaultStrategy) {
516
- const value = values.find(({ deviceId: d }) => d === deviceId);
517
- const fallbacks = DEVICES.slice(0, DEVICES.findIndex((d) => d.id === deviceId) + 1).reverse().map((d) => values.find((v) => v.deviceId === d.id)).filter((override) => Boolean(override));
518
- return value != null || fallbacks.length > 0 ? strategy(value, fallbacks) : void 0;
519
- }
520
- function join(responsiveValues, joinFn, strategy) {
521
- return DEVICES.map(({ id }) => id).map((deviceId) => {
522
- const value = joinFn(responsiveValues.map((responsiveValue) => {
523
- const deviceValue = responsiveValue && findDeviceOverride(responsiveValue, deviceId, strategy);
524
- return deviceValue == null ? void 0 : deviceValue.value;
525
- }));
526
- if (value == null)
527
- return null;
528
- return { deviceId, value };
529
- }).filter((override) => Boolean(override));
530
- }
531
- const getDeviceMediaQuery = (device) => {
532
- const parts = ["@media only screen"];
533
- if (device.minWidth != null) {
534
- parts.push(`(min-width: ${device.minWidth}px)`);
535
- }
536
- if (device.maxWidth != null) {
537
- parts.push(`(max-width: ${device.maxWidth}px)`);
538
- }
539
- return parts.join(" and ");
540
- };
541
- const isServer = typeof window === "undefined";
542
- const useInsertionEffectSpecifier = "useInsertionEffect";
543
- const useInsertionEffect = (_a = React[useInsertionEffectSpecifier]) != null ? _a : React.useLayoutEffect;
544
- function useStyle(style) {
545
- const serialized = serializeStyles([style], cache.registered);
546
- registerStyles(cache, serialized, false);
547
- useInsertionEffect(() => {
548
- insertStyles(cache, serialized, false);
549
- });
550
- if (isServer)
551
- insertStyles(cache, serialized, false);
552
- return `${cache.key}-${serialized.name}`;
553
- }
554
- function useSwatch(swatchId) {
555
- const client = useMakeswiftClient();
556
- const readSwatch = () => swatchId == null ? null : client.readSwatch(swatchId);
557
- const swatch = useSyncExternalStore(client.subscribe, readSwatch, readSwatch);
558
- useEffect(() => {
559
- if (swatchId != null)
560
- client.fetchSwatch(swatchId).catch(console.error);
561
- }, [client, swatchId]);
562
- return swatch;
563
- }
564
- function useSwatches(swatchIds) {
565
- const client = useMakeswiftClient();
566
- const lastSnapshot = useRef();
567
- function getSnapshot() {
568
- const swatches2 = swatchIds.map((swatchId) => client.readSwatch(swatchId));
569
- if (lastSnapshot.current != null && lastSnapshot.current.length === swatches2.length && lastSnapshot.current.every((swatch, idx) => swatches2[idx] === swatch)) {
570
- return lastSnapshot.current;
571
- }
572
- return lastSnapshot.current = swatches2;
573
- }
574
- const swatches = useSyncExternalStore(client.subscribe, getSnapshot, getSnapshot);
575
- useEffect(() => {
576
- Promise.all(swatchIds.map((swatchId) => client.fetchSwatch(swatchId))).catch(console.error);
577
- }, [client, swatchIds]);
578
- return swatches;
579
- }
580
- function useFile(fileId) {
581
- const client = useMakeswiftClient();
582
- const readFile = () => fileId == null ? null : client.readFile(fileId);
583
- const file = useSyncExternalStore(client.subscribe, readFile, readFile);
584
- useEffect(() => {
585
- if (fileId != null)
586
- client.fetchFile(fileId);
587
- }, [client, fileId]);
588
- return file;
589
- }
590
- function useFiles(fileIds) {
591
- const client = useMakeswiftClient();
592
- const lastSnapshot = useRef();
593
- function getSnapshot() {
594
- const files2 = fileIds.map((fileId) => client.readFile(fileId));
595
- if (lastSnapshot.current != null && lastSnapshot.current.length === files2.length && lastSnapshot.current.every((file, idx) => files2[idx] === file)) {
596
- return lastSnapshot.current;
597
- }
598
- return lastSnapshot.current = files2;
599
- }
600
- const files = useSyncExternalStore(client.subscribe, getSnapshot, getSnapshot);
601
- useEffect(() => {
602
- Promise.all(fileIds.map((fileId) => client.fetchFile(fileId))).catch(console.error);
603
- }, [client, fileIds]);
604
- return files;
605
- }
606
- function useTypography(typographyId) {
607
- const client = useMakeswiftClient();
608
- const readTypography = () => typographyId == null ? null : client.readTypography(typographyId);
609
- const typography = useSyncExternalStore(client.subscribe, readTypography, readTypography);
610
- useEffect(() => {
611
- if (typographyId != null)
612
- client.fetchTypography(typographyId).catch(console.error);
613
- }, [client, typographyId]);
614
- return typography;
615
- }
616
- function useGlobalElement(globalElementId) {
617
- const client = useMakeswiftClient();
618
- const readGlobalElement = () => globalElementId == null ? null : client.readGlobalElement(globalElementId);
619
- const globalElement = useSyncExternalStore(client.subscribe, readGlobalElement, readGlobalElement);
620
- useEffect(() => {
621
- if (globalElementId != null)
622
- client.fetchGlobalElement(globalElementId).catch(console.error);
623
- }, [client, globalElementId]);
624
- return globalElement;
625
- }
626
- function usePagePathnameSlice(pageId) {
627
- const client = useMakeswiftClient();
628
- const readPagePathnameSlice = () => pageId == null ? null : client.readPagePathnameSlice(pageId);
629
- const pagePathnameSlice = useSyncExternalStore(client.subscribe, readPagePathnameSlice, readPagePathnameSlice);
630
- useEffect(() => {
631
- if (pageId != null)
632
- client.fetchPagePathnameSlice(pageId).catch(console.error);
633
- }, [client, pageId]);
634
- return pagePathnameSlice;
635
- }
636
- function useTable(tableId) {
637
- const client = useMakeswiftClient();
638
- const readTable = () => tableId == null ? null : client.readTable(tableId);
639
- const table = useSyncExternalStore(client.subscribe, readTable, readTable);
640
- useEffect(() => {
641
- if (tableId != null)
642
- client.fetchTable(tableId).catch(console.error);
643
- }, [client, tableId]);
644
- return table;
645
- }
646
- const getIndexes = (spans, index) => {
647
- const flattened = spans.reduce((a, s) => a.concat(s), []);
648
- if (index < 0 || index > flattened.length)
649
- throw new RangeError();
650
- let remainder = index;
651
- let rowIndex = 0;
652
- while (rowIndex < spans.length - 1 && remainder >= spans[rowIndex].length) {
653
- remainder -= spans[rowIndex].length;
654
- rowIndex += 1;
655
- }
656
- return [rowIndex, remainder];
657
- };
658
- function lengthDataToString(data) {
659
- if (typeof data === "object")
660
- return `${data.value}${data.unit}`;
661
- if (typeof data === "number")
662
- return `${data}px`;
663
- return data;
664
- }
665
- function paddingPropertyDataToStyle(data, defaultValue = {}) {
666
- var _a2, _b, _c, _d;
667
- const paddingTop = (_a2 = data.paddingTop) != null ? _a2 : defaultValue.paddingTop;
668
- const paddingRight = (_b = data.paddingRight) != null ? _b : defaultValue.paddingRight;
669
- const paddingBottom = (_c = data.paddingBottom) != null ? _c : defaultValue.paddingBottom;
670
- const paddingLeft = (_d = data.paddingLeft) != null ? _d : defaultValue.paddingLeft;
671
- const style = {};
672
- if (paddingTop != null)
673
- style.paddingTop = lengthDataToString(paddingTop);
674
- if (paddingRight != null)
675
- style.paddingRight = lengthDataToString(paddingRight);
676
- if (paddingBottom != null)
677
- style.paddingBottom = lengthDataToString(paddingBottom);
678
- if (paddingLeft != null)
679
- style.paddingLeft = lengthDataToString(paddingLeft);
680
- return style;
681
- }
682
- function marginPropertyDataToStyle(data, defaultValue = {}) {
683
- var _a2, _b, _c, _d;
684
- const marginTop = (_a2 = data.marginTop) != null ? _a2 : defaultValue.marginTop;
685
- const marginRight = (_b = data.marginRight) != null ? _b : defaultValue.marginRight;
686
- const marginBottom = (_c = data.marginBottom) != null ? _c : defaultValue.marginBottom;
687
- const marginLeft = (_d = data.marginLeft) != null ? _d : defaultValue.marginLeft;
688
- const style = {};
689
- if (marginTop != null)
690
- style.marginTop = lengthDataToString(marginTop);
691
- if (marginRight != null)
692
- style.marginRight = lengthDataToString(marginRight);
693
- if (marginBottom != null)
694
- style.marginBottom = lengthDataToString(marginBottom);
695
- if (marginLeft != null)
696
- style.marginLeft = lengthDataToString(marginLeft);
697
- return style;
698
- }
699
- function lengthPercentageDataToString(data) {
700
- if (typeof data === "object")
701
- return `${data.value}${data.unit}`;
702
- if (typeof data === "number")
703
- return `${data}px`;
704
- return data;
705
- }
706
- function borderRadiusPropertyDataToStyle(data, defaultValue = {}) {
707
- var _a2, _b, _c, _d;
708
- const borderTopLeftRadius = (_a2 = data.borderTopLeftRadius) != null ? _a2 : defaultValue.borderTopLeftRadius;
709
- const borderTopRightRadius = (_b = data.borderTopRightRadius) != null ? _b : defaultValue.borderTopRightRadius;
710
- const borderBottomRightRadius = (_c = data.borderBottomRightRadius) != null ? _c : defaultValue.borderBottomRightRadius;
711
- const borderBottomLeftRadius = (_d = data.borderBottomLeftRadius) != null ? _d : defaultValue.borderBottomLeftRadius;
712
- const style = {};
713
- if (borderTopLeftRadius != null) {
714
- style.borderTopLeftRadius = lengthPercentageDataToString(borderTopLeftRadius);
715
- }
716
- if (borderTopRightRadius != null) {
717
- style.borderTopRightRadius = lengthPercentageDataToString(borderTopRightRadius);
718
- }
719
- if (borderBottomRightRadius != null) {
720
- style.borderBottomRightRadius = lengthPercentageDataToString(borderBottomRightRadius);
721
- }
722
- if (borderBottomLeftRadius != null) {
723
- style.borderBottomLeftRadius = lengthPercentageDataToString(borderBottomLeftRadius);
724
- }
725
- return style;
726
- }
727
- function colorToString(color) {
728
- return color && color.swatch ? `hsla(${color.swatch.hue},${color.swatch.saturation}%,${color.swatch.lightness}%,${color.alpha})` : "";
729
- }
730
- function borderPropertyDataToStyle(data, defaultValue = {}) {
731
- var _a2, _b, _c, _d;
732
- const borderTop = (_a2 = data.borderTop) != null ? _a2 : defaultValue.borderTop;
733
- const borderRight = (_b = data.borderRight) != null ? _b : defaultValue.borderRight;
734
- const borderBottom = (_c = data.borderBottom) != null ? _c : defaultValue.borderBottom;
735
- const borderLeft = (_d = data.borderLeft) != null ? _d : defaultValue.borderLeft;
736
- const style = {};
737
- if (borderTop != null)
738
- style.borderTop = borderSideToString(borderTop);
739
- if (borderRight != null)
740
- style.borderRight = borderSideToString(borderRight);
741
- if (borderBottom != null)
742
- style.borderBottom = borderSideToString(borderBottom);
743
- if (borderLeft != null)
744
- style.borderLeft = borderSideToString(borderLeft);
745
- return style;
746
- }
747
- function borderSideToString(borderSide) {
748
- if (typeof borderSide === "string")
749
- return borderSide;
750
- if (typeof borderSide === "number")
751
- return `${borderSide}px`;
752
- const { width, color, style } = borderSide;
753
- return `${width != null ? width : 0}px ${style} ${color != null ? colorToString(color) : "black"}`;
754
- }
755
- function responsiveStyle(responsiveValues, join$1, strategy) {
756
- return join(responsiveValues, join$1, strategy).reduce((acc, { deviceId, value }) => {
757
- const device = getDevice(deviceId);
758
- const mediaQuery = getDeviceMediaQuery(device);
759
- return __spreadProps(__spreadValues({}, acc), {
760
- [mediaQuery]: __spreadValues(__spreadValues({}, acc[mediaQuery]), value)
761
- });
762
- }, {});
763
- }
764
- function responsiveWidth(widthData, defaultValue = "100%") {
765
- return __spreadValues({
766
- maxWidth: "100%"
767
- }, responsiveStyle([widthData], ([width = defaultValue]) => ({
768
- width: typeof width === "object" ? `${width.value}${width.unit}` : width
769
- })));
770
- }
771
- function responsivePadding(paddingData, defaultValue = {}) {
772
- return responsiveStyle([paddingData], ([padding = {}]) => paddingPropertyDataToStyle(padding, Object.assign({ paddingTop: 0, paddingRight: 0, paddingBottom: 0, paddingLeft: 0 }, defaultValue)));
773
- }
774
- function responsiveMargin(marginData, defaultValue = {}) {
775
- return responsiveStyle([marginData], ([margin = {}]) => marginPropertyDataToStyle(margin, Object.assign({ marginTop: 0, marginRight: "auto", marginBottom: 0, marginLeft: "auto" }, defaultValue)));
776
- }
777
- function responsiveBorderRadius(borderRadiusData, defaultValue = {}) {
778
- return responsiveStyle([borderRadiusData], ([borderRadius = {}]) => borderRadiusPropertyDataToStyle(borderRadius, Object.assign({
779
- borderTopLeftRadius: 0,
780
- borderTopRightRadius: 0,
781
- borderBottomRightRadius: 0,
782
- borderBottomLeftRadius: 0
783
- }, defaultValue)));
784
- }
785
- function responsiveBorder(borderData, defaultValue = {}) {
786
- return responsiveStyle([borderData], ([border = {}]) => borderPropertyDataToStyle(border, Object.assign({
787
- borderTop: "0px solid black",
788
- borderRight: "0px solid black",
789
- borderBottom: "0px solid black",
790
- borderLeft: "0px solid black"
791
- }, defaultValue)));
792
- }
793
- const floor = (d) => (v) => Math.floor(10 ** d * v) / 10 ** d;
794
- function responsiveGridItem(props) {
795
- return __spreadValues({
796
- display: "flex"
797
- }, responsiveStyle([props.grid, props.columnGap, props.rowGap], ([
798
- { spans, count } = { spans: [[12]], count: 12 },
799
- columnGap = { value: 0, unit: "px" },
800
- rowGap = { value: 0, unit: "px" }
801
- ]) => {
802
- const [rowIndex, columnIndex] = getIndexes(spans, props.index);
803
- const firstCol = columnIndex === 0;
804
- const lastCol = columnIndex === spans[rowIndex].length - 1;
805
- const span = spans[rowIndex][columnIndex];
806
- const fraction = floor(5)(span / count);
807
- const width = `${fraction} * (100% + ${columnGap.value}${columnGap.unit})`;
808
- const excessWidth = `${Number(firstCol) + Number(lastCol)} * ${columnGap.value}${columnGap.unit} / 2`;
809
- const iePrecisionError = "0.01px";
810
- const flexBasis = `calc(${width} - ${excessWidth} - ${iePrecisionError})`;
811
- const firstRow = rowIndex === 0;
812
- const lastRow = rowIndex === spans.length - 1;
813
- return span === 0 ? { display: "none" } : {
814
- flexBasis,
815
- minWidth: flexBasis,
816
- maxWidth: flexBasis,
817
- paddingLeft: firstCol ? 0 : `${columnGap.value / 2}${columnGap.unit}`,
818
- paddingRight: lastCol ? 0 : `${columnGap.value / 2}${columnGap.unit}`,
819
- paddingTop: firstRow ? 0 : `${rowGap.value / 2}${rowGap.unit}`,
820
- paddingBottom: lastRow ? 0 : `${rowGap.value / 2}${rowGap.unit}`
821
- };
822
- }));
823
- }
824
- const getBoxShadow = (shadows) => shadows.map(({ payload: { inset, offsetX, offsetY, blurRadius, spreadRadius, color } }) => `${inset ? "inset " : ""}${offsetX.toFixed(1)}px ${offsetY.toFixed(1)}px ${blurRadius}px ${spreadRadius}px ${color != null ? colorToString(color) : "rgba(0,0,0,0.2)"}`).filter(Boolean).join();
825
- function responsiveShadow(value) {
826
- return responsiveStyle([value], ([shadow = []]) => ({
827
- boxShadow: getBoxShadow(shadow)
828
- }));
829
- }
830
- function responsiveTextStyle(value) {
831
- return responsiveStyle([value], ([
832
- textStyle = {
833
- fontFamily: null,
834
- letterSpacing: null,
835
- fontSize: null,
836
- fontWeight: null,
837
- textTransform: [],
838
- fontStyle: []
839
- }
840
- ]) => {
841
- const {
842
- fontSize,
843
- fontWeight,
844
- fontStyle = [],
845
- textTransform = [],
846
- letterSpacing,
847
- fontFamily
848
- } = textStyle;
849
- return __spreadValues(__spreadValues(__spreadValues(__spreadValues(__spreadValues(__spreadValues({}, fontFamily == null ? {} : { fontFamily: `"${fontFamily}"` }), fontWeight == null ? {} : { fontWeight }), letterSpacing == null ? {} : { letterSpacing }), fontSize == null ? {} : { fontSize: `${fontSize.value}${fontSize.unit}` }), textTransform.includes("uppercase") ? { textTransform: "uppercase" } : {}), fontStyle.includes("italic") ? { fontStyle: "italic" } : {});
850
- });
851
- }
852
- export { responsiveGridItem as A, useTable as B, useFiles as C, DEVICES as D, useTypography as E, FileQuery as F, GraphQLClient as G, shallowMergeFallbacks as H, IntrospectedResourcesQuery as I, MakeswiftProvider as J, MakeswiftClient as M, PagePathnamesByIdQuery as P, SwatchQuery as S, TypographiesQuery as T, TypographyQuery as a, GlobalElementQuery as b, TableQuery as c, deepEqual as d, useStyle as e, findDeviceOverride as f, useSwatches as g, getDeviceMediaQuery as h, colorToString as i, useSwatch as j, useFile as k, lengthPercentageDataToString as l, marginPropertyDataToStyle as m, usePagePathnameSlice as n, getIndexes as o, paddingPropertyDataToStyle as p, responsiveWidth as q, responsiveStyle as r, responsivePadding as s, responsiveMargin as t, useMakeswiftClient as u, responsiveBorderRadius as v, responsiveShadow as w, responsiveBorder as x, useGlobalElement as y, responsiveTextStyle as z };
853
- //# sourceMappingURL=responsive-style.es.js.map