@makeswift/runtime 0.28.8-canary.1 → 0.28.8-canary.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 (208) hide show
  1. package/dist/cjs/api/graphql-api-client.js +1 -1
  2. package/dist/cjs/api/rest-api-client.js +1 -1
  3. package/dist/cjs/api-handler/handlers/manifest.js +1 -1
  4. package/dist/cjs/client/index.js +1 -1
  5. package/dist/cjs/components/builtin/Embed/Embed.js +2 -1
  6. package/dist/cjs/components/builtin/Embed/Embed.js.map +1 -1
  7. package/dist/cjs/components/builtin/Navigation/components/DropDownButton/index.js.map +1 -1
  8. package/dist/cjs/components/builtin/Root/index.js.map +0 -1
  9. package/dist/cjs/components/builtin/Root/register.js.map +0 -1
  10. package/dist/cjs/components/shared/BackgroundsContainer/components/BackgroundVideo/index.js.map +1 -1
  11. package/dist/cjs/controls/index.js +4 -0
  12. package/dist/cjs/controls/index.js.map +1 -1
  13. package/dist/cjs/controls/link.js.map +1 -1
  14. package/dist/cjs/controls/rich-text/control.js +3 -0
  15. package/dist/cjs/controls/rich-text/control.js.map +1 -1
  16. package/dist/cjs/controls/rich-text/rich-text.js +2 -2
  17. package/dist/cjs/controls/rich-text/rich-text.js.map +1 -1
  18. package/dist/cjs/controls/rich-text-v2/control.js +5 -2
  19. package/dist/cjs/controls/rich-text-v2/control.js.map +1 -1
  20. package/dist/cjs/controls/rich-text-v2/rich-text-v2.js +2 -2
  21. package/dist/cjs/controls/rich-text-v2/rich-text-v2.js.map +1 -1
  22. package/dist/cjs/controls/serialization/base/index.js +1 -0
  23. package/dist/cjs/controls/serialization/base/index.js.map +1 -1
  24. package/dist/cjs/next/components/framework-provider/app-router/index.js +0 -2
  25. package/dist/cjs/next/components/framework-provider/app-router/index.js.map +1 -1
  26. package/dist/cjs/next/components/framework-provider/index.js +1 -1
  27. package/dist/cjs/next/components/framework-provider/index.js.map +1 -1
  28. package/dist/cjs/prop-controllers/instances.js +10 -4
  29. package/dist/cjs/prop-controllers/instances.js.map +1 -1
  30. package/dist/cjs/runtimes/react/components/framework-context.js +18 -12
  31. package/dist/cjs/runtimes/react/components/framework-context.js.map +1 -1
  32. package/dist/cjs/runtimes/react/components/hooks/use-framework-context.js +1 -5
  33. package/dist/cjs/runtimes/react/components/hooks/use-framework-context.js.map +1 -1
  34. package/dist/cjs/runtimes/react/components/resolve-props.js +8 -1
  35. package/dist/cjs/runtimes/react/components/resolve-props.js.map +1 -1
  36. package/dist/cjs/runtimes/react/controls/rich-text/EditableText/useSyncWithBuilder.js +4 -2
  37. package/dist/cjs/runtimes/react/controls/rich-text/EditableText/useSyncWithBuilder.js.map +1 -1
  38. package/dist/cjs/runtimes/react/controls/style.js.map +1 -1
  39. package/dist/cjs/runtimes/react/hooks/use-control-instances.js +39 -0
  40. package/dist/cjs/runtimes/react/hooks/use-control-instances.js.map +1 -0
  41. package/dist/cjs/runtimes/react/hooks/use-resolved-props.js +11 -28
  42. package/dist/cjs/runtimes/react/hooks/use-resolved-props.js.map +0 -1
  43. package/dist/cjs/runtimes/react/hooks/use-stylesheet-factory.js +3 -3
  44. package/dist/cjs/runtimes/react/hooks/use-stylesheet-factory.js.map +1 -1
  45. package/dist/cjs/runtimes/react/react-runtime-core.js +2 -1
  46. package/dist/cjs/runtimes/react/react-runtime-core.js.map +1 -1
  47. package/dist/cjs/runtimes/react/stylesheet-factory.js +17 -0
  48. package/dist/cjs/runtimes/react/stylesheet-factory.js.map +1 -0
  49. package/dist/cjs/slate/TypographyPlugin/normalizeTypographyUp.js.map +1 -1
  50. package/dist/cjs/slate/selectors.js.map +1 -1
  51. package/dist/cjs/slate/utils/toText.js.map +1 -1
  52. package/dist/cjs/state/middleware/read-write/prop-controller-handles.js +4 -3
  53. package/dist/cjs/state/middleware/read-write/prop-controller-handles.js.map +1 -1
  54. package/dist/cjs/state/modules/components-meta.js.map +1 -1
  55. package/dist/cjs/state/modules/element-trees.js +48 -20
  56. package/dist/cjs/state/modules/element-trees.js.map +1 -1
  57. package/dist/cjs/state/modules/is-in-builder.js.map +0 -1
  58. package/dist/cjs/state/translations/get.js +1 -4
  59. package/dist/cjs/state/translations/get.js.map +1 -1
  60. package/dist/cjs/testing/fixtures/index.js +4 -2
  61. package/dist/cjs/testing/fixtures/index.js.map +1 -1
  62. package/dist/cjs/{utils/is.js → testing/fixtures/snippet.js} +17 -7
  63. package/dist/cjs/testing/fixtures/snippet.js.map +1 -0
  64. package/dist/cjs/translations/index.js.map +1 -1
  65. package/dist/cjs/unstable-framework-support/index.js +2 -8
  66. package/dist/cjs/unstable-framework-support/index.js.map +1 -1
  67. package/dist/cjs/utils/intersection.js.map +1 -1
  68. package/dist/esm/api/graphql-api-client.js +1 -1
  69. package/dist/esm/api/rest-api-client.js +1 -1
  70. package/dist/esm/api-handler/handlers/manifest.js +1 -1
  71. package/dist/esm/client/index.js +1 -1
  72. package/dist/esm/components/builtin/Embed/Embed.js +3 -2
  73. package/dist/esm/components/builtin/Embed/Embed.js.map +1 -1
  74. package/dist/esm/components/builtin/Navigation/components/DropDownButton/index.js +5 -1
  75. package/dist/esm/components/builtin/Navigation/components/DropDownButton/index.js.map +1 -1
  76. package/dist/esm/components/shared/BackgroundsContainer/components/BackgroundVideo/index.js +5 -1
  77. package/dist/esm/components/shared/BackgroundsContainer/components/BackgroundVideo/index.js.map +1 -1
  78. package/dist/esm/controls/index.js +4 -0
  79. package/dist/esm/controls/index.js.map +1 -1
  80. package/dist/esm/controls/link.js.map +1 -1
  81. package/dist/esm/controls/rich-text/control.js +3 -0
  82. package/dist/esm/controls/rich-text/control.js.map +1 -1
  83. package/dist/esm/controls/rich-text/rich-text.js +2 -2
  84. package/dist/esm/controls/rich-text/rich-text.js.map +1 -1
  85. package/dist/esm/controls/rich-text-v2/control.js +5 -2
  86. package/dist/esm/controls/rich-text-v2/control.js.map +1 -1
  87. package/dist/esm/controls/rich-text-v2/rich-text-v2.js +2 -2
  88. package/dist/esm/controls/rich-text-v2/rich-text-v2.js.map +1 -1
  89. package/dist/esm/controls/serialization/base/index.js +2 -0
  90. package/dist/esm/controls/serialization/base/index.js.map +1 -1
  91. package/dist/esm/next/components/framework-provider/app-router/index.js +0 -4
  92. package/dist/esm/next/components/framework-provider/app-router/index.js.map +1 -1
  93. package/dist/esm/next/components/framework-provider/index.js +4 -2
  94. package/dist/esm/next/components/framework-provider/index.js.map +1 -1
  95. package/dist/esm/prop-controllers/instances.js +10 -4
  96. package/dist/esm/prop-controllers/instances.js.map +1 -1
  97. package/dist/esm/runtimes/react/components/framework-context.js +19 -8
  98. package/dist/esm/runtimes/react/components/framework-context.js.map +1 -1
  99. package/dist/esm/runtimes/react/components/hooks/use-framework-context.js +1 -5
  100. package/dist/esm/runtimes/react/components/hooks/use-framework-context.js.map +1 -1
  101. package/dist/esm/runtimes/react/components/resolve-props.js +8 -1
  102. package/dist/esm/runtimes/react/components/resolve-props.js.map +1 -1
  103. package/dist/esm/runtimes/react/controls/rich-text/EditableText/useSyncWithBuilder.js +4 -2
  104. package/dist/esm/runtimes/react/controls/rich-text/EditableText/useSyncWithBuilder.js.map +1 -1
  105. package/dist/esm/runtimes/react/controls/style.js.map +1 -1
  106. package/dist/esm/runtimes/react/hooks/use-control-instances.js +15 -0
  107. package/dist/esm/runtimes/react/hooks/use-control-instances.js.map +1 -0
  108. package/dist/esm/runtimes/react/hooks/use-resolved-props.js +10 -17
  109. package/dist/esm/runtimes/react/hooks/use-resolved-props.js.map +1 -1
  110. package/dist/esm/runtimes/react/hooks/use-stylesheet-factory.js +3 -3
  111. package/dist/esm/runtimes/react/hooks/use-stylesheet-factory.js.map +1 -1
  112. package/dist/esm/runtimes/react/react-runtime-core.js +2 -1
  113. package/dist/esm/runtimes/react/react-runtime-core.js.map +1 -1
  114. package/dist/esm/runtimes/react/stylesheet-factory.js +1 -0
  115. package/dist/esm/runtimes/react/stylesheet-factory.js.map +1 -0
  116. package/dist/esm/slate/TypographyPlugin/normalizeTypographyUp.js.map +1 -1
  117. package/dist/esm/slate/selectors.js.map +1 -1
  118. package/dist/esm/slate/utils/toText.js.map +1 -1
  119. package/dist/esm/state/middleware/read-write/prop-controller-handles.js +4 -3
  120. package/dist/esm/state/middleware/read-write/prop-controller-handles.js.map +1 -1
  121. package/dist/esm/state/modules/components-meta.js.map +1 -1
  122. package/dist/esm/state/modules/element-trees.js +48 -20
  123. package/dist/esm/state/modules/element-trees.js.map +1 -1
  124. package/dist/esm/state/translations/get.js +1 -4
  125. package/dist/esm/state/translations/get.js.map +1 -1
  126. package/dist/esm/testing/fixtures/index.js +2 -1
  127. package/dist/esm/testing/fixtures/index.js.map +1 -1
  128. package/dist/esm/testing/fixtures/snippet.js +12 -0
  129. package/dist/esm/testing/fixtures/snippet.js.map +1 -0
  130. package/dist/esm/translations/index.js.map +1 -1
  131. package/dist/esm/unstable-framework-support/index.js +2 -8
  132. package/dist/esm/unstable-framework-support/index.js.map +1 -1
  133. package/dist/esm/utils/intersection.js.map +1 -1
  134. package/dist/types/components/builtin/Embed/Embed.d.ts.map +1 -1
  135. package/dist/types/components/builtin/Navigation/components/DropDownButton/index.d.ts.map +1 -1
  136. package/dist/types/components/shared/BackgroundsContainer/components/BackgroundVideo/index.d.ts.map +1 -1
  137. package/dist/types/controls/index.d.ts +1 -1
  138. package/dist/types/controls/index.d.ts.map +1 -1
  139. package/dist/types/controls/rich-text/control.d.ts +1 -0
  140. package/dist/types/controls/rich-text/control.d.ts.map +1 -1
  141. package/dist/types/controls/rich-text/rich-text.d.ts +2 -2
  142. package/dist/types/controls/rich-text/rich-text.d.ts.map +1 -1
  143. package/dist/types/controls/rich-text-v2/control.d.ts +3 -2
  144. package/dist/types/controls/rich-text-v2/control.d.ts.map +1 -1
  145. package/dist/types/controls/rich-text-v2/rich-text-v2.d.ts +2 -2
  146. package/dist/types/controls/rich-text-v2/rich-text-v2.d.ts.map +1 -1
  147. package/dist/types/controls/serialization/base/index.d.ts.map +1 -1
  148. package/dist/types/next/components/framework-provider/app-router/index.d.ts +1 -1
  149. package/dist/types/next/components/framework-provider/app-router/index.d.ts.map +1 -1
  150. package/dist/types/next/components/framework-provider/index.d.ts.map +1 -1
  151. package/dist/types/prop-controllers/instances.d.ts +5 -2
  152. package/dist/types/prop-controllers/instances.d.ts.map +1 -1
  153. package/dist/types/runtimes/react/components/__tests__/framework-context.test.d.ts +3 -0
  154. package/dist/types/runtimes/react/components/__tests__/framework-context.test.d.ts.map +1 -0
  155. package/dist/types/runtimes/react/components/framework-context.d.ts +4 -6
  156. package/dist/types/runtimes/react/components/framework-context.d.ts.map +1 -1
  157. package/dist/types/runtimes/react/components/hooks/use-framework-context.d.ts +1 -2
  158. package/dist/types/runtimes/react/components/hooks/use-framework-context.d.ts.map +1 -1
  159. package/dist/types/runtimes/react/components/resolve-props.d.ts.map +1 -1
  160. package/dist/types/runtimes/react/controls/rich-text/EditableText/useSyncWithBuilder.d.ts.map +1 -1
  161. package/dist/types/runtimes/react/hooks/use-control-instances.d.ts +3 -0
  162. package/dist/types/runtimes/react/hooks/use-control-instances.d.ts.map +1 -0
  163. package/dist/types/runtimes/react/hooks/use-resolved-props.d.ts +7 -1
  164. package/dist/types/runtimes/react/hooks/use-resolved-props.d.ts.map +1 -1
  165. package/dist/types/runtimes/react/hooks/use-stylesheet-factory.d.ts +1 -5
  166. package/dist/types/runtimes/react/hooks/use-stylesheet-factory.d.ts.map +1 -1
  167. package/dist/types/runtimes/react/react-runtime-core.d.ts +9 -1
  168. package/dist/types/runtimes/react/react-runtime-core.d.ts.map +1 -1
  169. package/dist/types/runtimes/react/stylesheet-factory.d.ts +6 -0
  170. package/dist/types/runtimes/react/stylesheet-factory.d.ts.map +1 -0
  171. package/dist/types/slate/LinkPlugin/getValue.d.ts.map +1 -1
  172. package/dist/types/slate/LinkPlugin/index.d.ts.map +1 -1
  173. package/dist/types/slate/TypographyPlugin/getValue.d.ts.map +1 -1
  174. package/dist/types/slate/TypographyPlugin/index.d.ts.map +1 -1
  175. package/dist/types/slate/selectors.d.ts +2 -2
  176. package/dist/types/slate/selectors.d.ts.map +1 -1
  177. package/dist/types/slate/utils/toText.d.ts.map +1 -1
  178. package/dist/types/state/__tests__/fixtures/serialized-descriptors-from-builder.d.ts.map +1 -1
  179. package/dist/types/state/__tests__/fixtures/translatable-content-sample.d.ts.map +1 -1
  180. package/dist/types/state/middleware/read-write/prop-controller-handles.d.ts.map +1 -1
  181. package/dist/types/state/modules/__tests__/fixtures/element-trees.d.ts +737 -0
  182. package/dist/types/state/modules/__tests__/fixtures/element-trees.d.ts.map +1 -1
  183. package/dist/types/state/modules/components-meta.d.ts +3 -0
  184. package/dist/types/state/modules/components-meta.d.ts.map +1 -1
  185. package/dist/types/state/translations/get.d.ts.map +1 -1
  186. package/dist/types/testing/fixtures/index.d.ts +2 -1
  187. package/dist/types/testing/fixtures/index.d.ts.map +1 -1
  188. package/dist/types/testing/fixtures/snippet.d.ts +6 -0
  189. package/dist/types/testing/fixtures/snippet.d.ts.map +1 -0
  190. package/dist/types/translations/index.d.ts +1 -1
  191. package/dist/types/translations/index.d.ts.map +1 -1
  192. package/dist/types/unstable-framework-support/index.d.ts +1 -1
  193. package/dist/types/unstable-framework-support/index.d.ts.map +1 -1
  194. package/dist/types/utils/intersection.d.ts +2 -1
  195. package/dist/types/utils/intersection.d.ts.map +1 -1
  196. package/package.json +8 -5
  197. package/react/builtins/package.json +1 -1
  198. package/dist/cjs/runtimes/react/controls/group.js +0 -45
  199. package/dist/cjs/runtimes/react/controls/group.js.map +0 -1
  200. package/dist/cjs/utils/is.js.map +0 -1
  201. package/dist/esm/runtimes/react/controls/group.js +0 -23
  202. package/dist/esm/runtimes/react/controls/group.js.map +0 -1
  203. package/dist/esm/utils/is.js +0 -6
  204. package/dist/esm/utils/is.js.map +0 -1
  205. package/dist/types/runtimes/react/controls/group.d.ts +0 -11
  206. package/dist/types/runtimes/react/controls/group.d.ts.map +0 -1
  207. package/dist/types/utils/is.d.ts +0 -3
  208. package/dist/types/utils/is.d.ts.map +0 -1
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../src/state/modules/components-meta.ts"],"sourcesContent":["import { type Action, type UnknownAction, isKnownAction } from '../actions'\nimport { ReadOnlyActionTypes } from '../actions/internal/read-only-actions'\n\nexport const ComponentIcon = {\n Accordion: 'accordion',\n Audio: 'audio',\n Billing: 'billing',\n Bolt: 'bolt',\n Button: 'button',\n Card: 'card',\n Cards: 'cards',\n Carousel: 'carousel',\n Chats: 'chats',\n Code: 'code',\n Countdown: 'countdown',\n Cube: 'cube',\n Database: 'database',\n Divider: 'divider',\n Form: 'form',\n Gallery: 'gallery',\n Grid: 'grid',\n Help: 'help',\n Image: 'image',\n Layout: 'layout',\n Lock: 'lock',\n Marker: 'marker',\n Navigation: 'navigation',\n Palette: 'palette',\n SocialLinks: 'social-links',\n Star: 'star',\n Table: 'table',\n Tabs: 'tabs',\n Text: 'text',\n Users: 'users',\n Video: 'video',\n} as const\n\nexport type ComponentIcon = (typeof ComponentIcon)[keyof typeof ComponentIcon]\n\nexport type ComponentMeta = {\n label: string\n icon: ComponentIcon\n hidden: boolean\n description?: string\n builtinSuspense?: boolean\n}\n\nexport type State = Map<string, ComponentMeta>\n\nexport function getInitialState({\n componentsMeta = new Map(),\n}: { componentsMeta?: Map<string, ComponentMeta> } = {}): State {\n return componentsMeta\n}\n\nexport function getComponentsMeta(state: State): Map<string, ComponentMeta> {\n return state\n}\n\nexport function getComponentMeta(state: State, type: string): ComponentMeta | null {\n return getComponentsMeta(state).get(type) ?? null\n}\n\nexport function reducer(state: State = getInitialState(), action: Action | UnknownAction): State {\n if (!isKnownAction(action)) return state\n\n switch (action.type) {\n case ReadOnlyActionTypes.REGISTER_COMPONENT:\n return new Map(state).set(action.payload.type, action.payload.meta)\n\n case ReadOnlyActionTypes.UNREGISTER_COMPONENT: {\n const nextState = new Map(state)\n\n const deleted = nextState.delete(action.payload.type)\n\n return deleted ? nextState : state\n }\n\n default:\n return state\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;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,YAAY;AAAA,IAC/B;AAAA,IAEA;AACE,aAAO;AAAA,EACX;AACF;","names":[]}
1
+ {"version":3,"sources":["../../../../src/state/modules/components-meta.ts"],"sourcesContent":["import { type Action, type UnknownAction, isKnownAction } from '../actions'\nimport { ReadOnlyActionTypes } from '../actions/internal/read-only-actions'\n\nexport const ComponentIcon = {\n Accordion: 'accordion',\n Audio: 'audio',\n Billing: 'billing',\n Bolt: 'bolt',\n Button: 'button',\n Card: 'card',\n Cards: 'cards',\n Carousel: 'carousel',\n Chats: 'chats',\n Code: 'code',\n Countdown: 'countdown',\n Cube: 'cube',\n Database: 'database',\n Divider: 'divider',\n Form: 'form',\n Gallery: 'gallery',\n Grid: 'grid',\n Help: 'help',\n Image: 'image',\n Layout: 'layout',\n Lock: 'lock',\n Marker: 'marker',\n Navigation: 'navigation',\n Palette: 'palette',\n SocialLinks: 'social-links',\n Star: 'star',\n Table: 'table',\n Tabs: 'tabs',\n Text: 'text',\n Users: 'users',\n Video: 'video',\n} as const\n\nexport type ComponentIcon = (typeof ComponentIcon)[keyof typeof ComponentIcon]\n\nexport type ComponentMeta = {\n label: string\n icon: ComponentIcon\n hidden: boolean\n description?: string\n builtinSuspense?: boolean\n unstable_migration?: {\n replacementType: string\n }\n}\n\nexport type State = Map<string, ComponentMeta>\n\nexport function getInitialState({\n componentsMeta = new Map(),\n}: { componentsMeta?: Map<string, ComponentMeta> } = {}): State {\n return componentsMeta\n}\n\nexport function getComponentsMeta(state: State): Map<string, ComponentMeta> {\n return state\n}\n\nexport function getComponentMeta(state: State, type: string): ComponentMeta | null {\n return getComponentsMeta(state).get(type) ?? null\n}\n\nexport function reducer(state: State = getInitialState(), action: Action | UnknownAction): State {\n if (!isKnownAction(action)) return state\n\n switch (action.type) {\n case ReadOnlyActionTypes.REGISTER_COMPONENT:\n return new Map(state).set(action.payload.type, action.payload.meta)\n\n case ReadOnlyActionTypes.UNREGISTER_COMPONENT: {\n const nextState = new Map(state)\n\n const deleted = nextState.delete(action.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YAAY,IAAI,IAAI,KAAK;AAE/B,YAAM,UAAU,UAAU,OAAO,OAAO,QAAQ,IAAI;AAEpD,aAAO,UAAU,YAAY;AAAA,IAC/B;AAAA,IAEA;AACE,aAAO;AAAA,EACX;AACF;","names":[]}
@@ -199,32 +199,60 @@ function updateParentElements(elements, elementPaths, rootElement) {
199
199
  elements.set(element.key, element);
200
200
  });
201
201
  }
202
- function hasChildren(element, propName, descriptors) {
202
+ function getPropChildren(element, propName, descriptors) {
203
203
  if ((0, import_controls.isElementReference)(element))
204
- return false;
204
+ return null;
205
205
  const propDescriptor = descriptors.get(element.type)?.[propName];
206
206
  if (propDescriptor == null)
207
- return false;
208
- const children = Introspection.getElementChildren(propDescriptor, element.props[propName]);
209
- return children.length > 0;
207
+ return null;
208
+ return Introspection.getElementChildren(propDescriptor, element.props[propName]);
210
209
  }
211
- function deleteElement({ elements, elementIds }, deletedElement, propName, descriptors) {
212
- if (propName == null || hasChildren(deletedElement, propName, descriptors)) {
213
- for (const element of traverseElementTree(deletedElement, descriptors)) {
214
- elements.delete(element.key);
215
- elementIds.delete(element.key);
216
- }
217
- } else {
218
- elements.delete(deletedElement.key);
219
- elementIds.delete(deletedElement.key);
210
+ function isChildrenProp(element, propName, descriptors) {
211
+ const children = getPropChildren(element, propName, descriptors);
212
+ return children != null;
213
+ }
214
+ function deleteElement({ elements, elementIds }, elementToDelete, descriptors) {
215
+ for (const element of traverseElementTree(elementToDelete, descriptors)) {
216
+ elements.delete(element.key);
217
+ elementIds.delete(element.key);
218
+ }
219
+ }
220
+ function deleteChildrenInProp(elementTree, parentElement, propName, descriptors) {
221
+ const childrenInProp = getPropChildren(parentElement, propName, descriptors);
222
+ if (childrenInProp == null) {
223
+ return;
224
+ }
225
+ for (const child of childrenInProp) {
226
+ deleteElement(elementTree, child, descriptors);
227
+ }
228
+ }
229
+ function deleteElementOrProp({ elements, elementIds }, targetElement, propName, descriptors) {
230
+ if (propName == null) {
231
+ deleteElement({ elements, elementIds }, targetElement, descriptors);
232
+ return;
233
+ }
234
+ if (isChildrenProp(targetElement, propName, descriptors)) {
235
+ deleteChildrenInProp({ elements, elementIds }, targetElement, propName, descriptors);
236
+ }
237
+ const elementInTree = elements.get(targetElement.key);
238
+ if (!elementInTree) {
239
+ console.error(
240
+ `Attempting to remove prop ${propName} from element ${targetElement.key} not found in tree`
241
+ );
242
+ return;
243
+ }
244
+ if (!(0, import_controls.isElementReference)(elementInTree)) {
245
+ const newProps = { ...elementInTree.props };
246
+ delete newProps[propName];
247
+ elements.set(targetElement.key, { ...elementInTree, props: newProps });
220
248
  }
221
249
  }
222
250
  function applyDelete(elementTree, descriptors, rootElements, path) {
223
- const [deleteElementPath, ...parentElementPaths] = getChangedElementsPaths(path);
224
- const [deletedElement, propName] = getElementAndPropName(rootElements.before, deleteElementPath);
251
+ const [targetElementPath, ...parentElementPaths] = getChangedElementsPaths(path);
252
+ const [targetElement, propName] = getElementAndPropName(rootElements.before, targetElementPath);
225
253
  const elements = new Map(elementTree.elements);
226
254
  const elementIds = new Map(elementTree.elementIds);
227
- deleteElement({ elements, elementIds }, deletedElement, propName, descriptors);
255
+ deleteElementOrProp({ elements, elementIds }, targetElement, propName, descriptors);
228
256
  updateParentElements(elements, parentElementPaths, rootElements.after);
229
257
  return {
230
258
  elements,
@@ -232,7 +260,7 @@ function applyDelete(elementTree, descriptors, rootElements, path) {
232
260
  };
233
261
  }
234
262
  function insertElement({ elements, elementIds }, insertedElement, propName, descriptors) {
235
- if (propName == null || hasChildren(insertedElement, propName, descriptors)) {
263
+ if (propName == null || isChildrenProp(insertedElement, propName, descriptors)) {
236
264
  for (const element of traverseElementTree(insertedElement, descriptors)) {
237
265
  elements.set(element.key, element);
238
266
  if (!(0, import_controls.isElementReference)(element)) {
@@ -264,11 +292,11 @@ function applyInsert(elementTree, descriptors, rootElements, path) {
264
292
  }
265
293
  function applyUpdate(elementTree, descriptors, rootElements, path) {
266
294
  const [updateElementPath, ...parentElementPaths] = getChangedElementsPaths(path);
267
- const [deletedElement, propName] = getElementAndPropName(rootElements.before, updateElementPath);
295
+ const [targetElement, propName] = getElementAndPropName(rootElements.before, updateElementPath);
268
296
  const [insertedElement, _] = getElementAndPropName(rootElements.after, updateElementPath);
269
297
  const elements = new Map(elementTree.elements);
270
298
  const elementIds = new Map(elementTree.elementIds);
271
- deleteElement({ elements, elementIds }, deletedElement, propName, descriptors);
299
+ deleteElementOrProp({ elements, elementIds }, targetElement, propName, descriptors);
272
300
  insertElement({ elements, elementIds }, insertedElement, propName, descriptors);
273
301
  updateParentElements(elements, parentElementPaths, rootElements.after);
274
302
  return {
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../src/state/modules/element-trees.ts"],"sourcesContent":["import { type Operation } from 'ot-json0'\nimport { getIn, removeIn, setIn } from 'immutable'\n\nimport { type Element, type ElementData, isElementReference } from '@makeswift/controls'\n\nimport * as Introspection from '../../prop-controllers/introspection'\n\nimport { type Action, type UnknownAction, isKnownAction } from '../actions'\n\nimport { ReadOnlyActionTypes } from '../actions/internal/read-only-actions'\nimport { ReadWriteActionTypes } from '../actions/internal/read-write-actions'\n\nimport { getRootElement, type Document } from './read-only-documents'\nimport { type DescriptorsByComponentType } from './prop-controllers'\n\nexport type ElementTree = {\n elements: Map<string, Element>\n elementIds: Map<string, string>\n}\n\nexport type State = Map<string, ElementTree>\n\nexport function getInitialState(\n documents?: Map<string, Document>,\n descriptors?: DescriptorsByComponentType,\n): State {\n const state = new Map<string, ElementTree>()\n if (documents == null || descriptors == null) return state\n\n for (const [documentKey, document] of documents) {\n state.set(documentKey, buildElementTree(getRootElement(document), descriptors))\n }\n\n return state\n}\n\nfunction getElementTree(state: State, documentKey: string): ElementTree | null {\n return state.get(documentKey) ?? null\n}\n\nexport function getElements(state: State, documentKey: string): Map<string, Element> {\n return getElementTree(state, documentKey)?.elements ?? new Map()\n}\n\nexport function getElementIds(state: State, documentKey: string): Map<string, string> {\n return getElementTree(state, documentKey)?.elementIds ?? new Map()\n}\n\nexport function getElement(state: State, documentKey: string, elementKey: string): Element | null {\n return getElements(state, documentKey).get(elementKey) ?? null\n}\n\nexport function getElementId(state: State, documentKey: string, elementKey: string): string | null {\n return getElementIds(state, documentKey).get(elementKey) ?? null\n}\n\nexport function reducer(state: State = getInitialState(), action: Action | UnknownAction): State {\n if (!isKnownAction(action)) return state\n\n switch (action.type) {\n case ReadOnlyActionTypes.CREATE_ELEMENT_TREE: {\n const { document, descriptors } = action.payload\n return new Map(state).set(\n document.key,\n buildElementTree(getRootElement(document), descriptors),\n )\n }\n\n case ReadOnlyActionTypes.DELETE_ELEMENT_TREE: {\n const nextState = new Map(state)\n const deleted = nextState.delete(action.payload.documentKey)\n return deleted ? nextState : state\n }\n\n case ReadWriteActionTypes.CHANGE_ELEMENT_TREE: {\n const { oldDocument, newDocument, descriptors, operation } = action.payload\n const documentKey = oldDocument.key\n console.assert(\n documentKey === newDocument.key,\n `Mismatching document keys ${documentKey} !== ${newDocument.key}`,\n )\n\n const elementTree = state.get(documentKey)\n if (elementTree == null) return state\n\n const updatedElementTree = applyChanges(\n elementTree,\n descriptors,\n {\n old: getRootElement(oldDocument),\n new: getRootElement(newDocument),\n },\n operation,\n )\n\n return new Map(state).set(documentKey, updatedElementTree)\n }\n\n default:\n return state\n }\n}\n\nexport function* traverseElementTree(\n element: Element,\n descriptors: DescriptorsByComponentType,\n): Generator<Element> {\n yield element\n if (isElementReference(element)) return\n\n const elementDescriptors = descriptors.get(element.type)\n if (elementDescriptors == null) return\n\n for (const [propKey, descriptor] of Object.entries(elementDescriptors)) {\n const children = Introspection.getElementChildren(descriptor, element.props[propKey])\n for (const child of children) {\n yield* traverseElementTree(child, descriptors)\n }\n }\n}\n\nfunction getElementIdProp(\n element: ElementData,\n descriptors: DescriptorsByComponentType,\n): string | null {\n const elementDescriptors = descriptors.get(element.type)\n if (elementDescriptors == null) return null\n\n for (const [propName, descriptor] of Object.entries(elementDescriptors)) {\n const elementId = Introspection.getElementId(descriptor, element.props[propName])\n if (elementId != null) return elementId\n }\n\n return null\n}\n\nexport function buildElementTree(\n rootElement: Element,\n descriptors: DescriptorsByComponentType,\n): ElementTree {\n const elements = new Map<string, Element>()\n const elementIds = new Map<string, string>()\n\n for (const element of traverseElementTree(rootElement, descriptors)) {\n elements.set(element.key, element)\n if (!isElementReference(element)) {\n const elementId = getElementIdProp(element, descriptors)\n if (elementId != null) elementIds.set(element.key, elementId)\n }\n }\n\n return {\n elements,\n elementIds,\n }\n}\n\ntype OperationPath = Operation[number]['p']\n\n// performance-sensitive function, intentionally not using `elementData` schema here\nfunction isElement(item: unknown): item is Element {\n return (\n typeof item === 'object' &&\n item != null &&\n 'key' in item &&\n 'type' in item &&\n typeof item.key === 'string' &&\n typeof item.type === 'string'\n )\n}\n\ntype ElementOperationPath = { elementPath: OperationPath; propName: string | null }\n\nfunction getElementOperationPath(path: OperationPath): ElementOperationPath {\n if (path.length === 0) {\n return { elementPath: [], propName: null }\n }\n\n const i = path.findLastIndex(\n (fragment, i) =>\n typeof fragment === 'number' && (i === path.length - 1 || path[i + 1] === 'props'),\n )\n\n if ((i === -1 && path[0] !== 'props') || path.length - i < 3) {\n console.error('Operation path does not point to an element property', { path })\n return { elementPath: [], propName: null }\n }\n\n return { elementPath: path.slice(0, i + 1), propName: `${path.slice(i + 1).at(1)}` }\n}\n\nexport function getChangedElementsPaths(\n path: OperationPath,\n): [ElementOperationPath, ...ElementOperationPath[]] {\n let elementOp = getElementOperationPath(path)\n const result: [ElementOperationPath, ...ElementOperationPath[]] = [elementOp]\n while (elementOp.elementPath.length > 0) {\n elementOp = getElementOperationPath(elementOp.elementPath.slice(0, -1))\n result.push(elementOp)\n }\n\n return result\n}\n\nfunction getElementByPath(rootElement: Element, elementPath: OperationPath): Element | null {\n const item = getIn(rootElement, elementPath)\n if (!isElement(item)) {\n console.error('Expected an element, got', item, {\n rootElement,\n elementPath,\n })\n\n return null\n }\n\n return item\n}\n\nfunction getElementAndPropName(\n rootElement: Element,\n { elementPath, propName }: ElementOperationPath,\n): [Element, string | null] {\n const element = getElementByPath(rootElement, elementPath)\n return element != null ? [element, propName] : [rootElement, null]\n}\n\nfunction updateParentElements(\n elements: ElementTree['elements'],\n elementPaths: ElementOperationPath[],\n rootElement: Element,\n): void {\n elementPaths.forEach(({ elementPath }) => {\n const element = getElementByPath(rootElement, elementPath)\n if (element != null) elements.set(element.key, element)\n })\n}\n\nfunction hasChildren(\n element: Element,\n propName: string,\n descriptors: DescriptorsByComponentType,\n): boolean {\n if (isElementReference(element)) return false\n\n const propDescriptor = descriptors.get(element.type)?.[propName]\n if (propDescriptor == null) return false\n\n const children = Introspection.getElementChildren(propDescriptor, element.props[propName])\n return children.length > 0\n}\n\nfunction deleteElement(\n { elements, elementIds }: ElementTree,\n deletedElement: Element,\n propName: string | null,\n descriptors: DescriptorsByComponentType,\n) {\n if (propName == null || hasChildren(deletedElement, propName, descriptors)) {\n for (const element of traverseElementTree(deletedElement, descriptors)) {\n elements.delete(element.key)\n elementIds.delete(element.key)\n }\n } else {\n elements.delete(deletedElement.key)\n elementIds.delete(deletedElement.key)\n }\n}\n\nfunction applyDelete(\n elementTree: ElementTree,\n descriptors: DescriptorsByComponentType,\n rootElements: { before: Element; after: Element },\n path: OperationPath,\n): ElementTree {\n const [deleteElementPath, ...parentElementPaths] = getChangedElementsPaths(path)\n const [deletedElement, propName] = getElementAndPropName(rootElements.before, deleteElementPath)\n\n const elements = new Map(elementTree.elements)\n const elementIds = new Map(elementTree.elementIds)\n\n deleteElement({ elements, elementIds }, deletedElement, propName, descriptors)\n\n // Use the \"after\" state to efficiently update all of parent subtrees in the state\n updateParentElements(elements, parentElementPaths, rootElements.after)\n\n return {\n elements,\n elementIds,\n }\n}\n\nfunction insertElement(\n { elements, elementIds }: ElementTree,\n insertedElement: Element,\n propName: string | null,\n descriptors: DescriptorsByComponentType,\n) {\n if (propName == null || hasChildren(insertedElement, propName, descriptors)) {\n for (const element of traverseElementTree(insertedElement, descriptors)) {\n elements.set(element.key, element)\n if (!isElementReference(element)) {\n const elementId = getElementIdProp(element, descriptors)\n if (elementId != null) elementIds.set(element.key, elementId)\n }\n }\n } else {\n elements.set(insertedElement.key, insertedElement)\n if (!isElementReference(insertedElement)) {\n const elementId = getElementIdProp(insertedElement, descriptors)\n if (elementId != null) elementIds.set(insertedElement.key, elementId)\n }\n }\n}\n\nfunction applyInsert(\n elementTree: ElementTree,\n descriptors: DescriptorsByComponentType,\n rootElements: { before: Element; after: Element },\n path: OperationPath,\n): ElementTree {\n const [insertedElementPath, ...parentElementPaths] = getChangedElementsPaths(path)\n const [insertedElement, propName] = getElementAndPropName(rootElements.after, insertedElementPath)\n\n const elements = new Map(elementTree.elements)\n const elementIds = new Map(elementTree.elementIds)\n\n insertElement({ elements, elementIds }, insertedElement, propName, descriptors)\n\n // Use the \"after\" state to efficiently update all of parent subtrees in the state\n updateParentElements(elements, parentElementPaths, rootElements.after)\n\n return {\n elements,\n elementIds,\n }\n}\n\nfunction applyUpdate(\n elementTree: ElementTree,\n descriptors: DescriptorsByComponentType,\n rootElements: { before: Element; after: Element },\n path: OperationPath,\n): ElementTree {\n const [updateElementPath, ...parentElementPaths] = getChangedElementsPaths(path)\n const [deletedElement, propName] = getElementAndPropName(rootElements.before, updateElementPath)\n const [insertedElement, _] = getElementAndPropName(rootElements.after, updateElementPath)\n\n const elements = new Map(elementTree.elements)\n const elementIds = new Map(elementTree.elementIds)\n\n deleteElement({ elements, elementIds }, deletedElement, propName, descriptors)\n insertElement({ elements, elementIds }, insertedElement, propName, descriptors)\n\n // Use the \"after\" state to efficiently update all of parent subtrees in the state\n updateParentElements(elements, parentElementPaths, rootElements.after)\n\n return {\n elements,\n elementIds,\n }\n}\n\nfunction applyOpComponent(root: Element, component: Operation[number]): Element {\n let applied: Element = root\n\n if ('ld' in component || 'od' in component) {\n applied = removeIn(applied, component.p)\n }\n\n if ('li' in component) {\n applied = setIn(applied, component.p, component.li)\n }\n\n if ('oi' in component) {\n applied = setIn(applied, component.p, component.oi)\n }\n\n return applied\n}\n\nfunction selectTreeTransform(op: Operation[number]): typeof applyUpdate {\n const hasDelete = 'ld' in op || 'od' in op\n const hasInsert = 'li' in op || 'oi' in op\n\n if (hasDelete && hasInsert) return applyUpdate\n if (hasDelete) return applyDelete\n if (hasInsert) return applyInsert\n\n return elementTree => elementTree\n}\n\nfunction applyChanges(\n elementTree: ElementTree,\n descriptors: DescriptorsByComponentType,\n rootElements: { old: Element; new: Element },\n operation: Operation,\n): ElementTree {\n // Updates the element tree \"cache\" based on the provided operation, which can\n // be composed of 1-n component ops. We apply each component op sequentially\n // to the 'old' root element to determine the changed elements and update the\n // cache accordingly at each intermediate step.\n const result = operation.reduce(\n (acc, op) => {\n const rootBefore = acc.rootBefore\n\n // If there's only one component op, we can skip the application of the op\n // and assume that the result will be the 'new' root element provided to\n // us by the builder.\n const rootAfter = operation.length > 1 ? applyOpComponent(rootBefore, op) : rootElements.new\n\n const roots = { before: rootBefore, after: rootAfter }\n const applyChange = selectTreeTransform(op)\n\n return {\n elementTree: applyChange(acc.elementTree, descriptors, roots, op.p),\n rootBefore: rootAfter,\n }\n },\n { elementTree, rootBefore: rootElements.old },\n )\n\n return result.elementTree\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AACA,uBAAuC;AAEvC,sBAAmE;AAEnE,oBAA+B;AAE/B,qBAA+D;AAE/D,+BAAoC;AACpC,gCAAqC;AAErC,iCAA8C;AAUvC,SAAS,gBACd,WACA,aACO;AACP,QAAM,QAAQ,oBAAI,IAAyB;AAC3C,MAAI,aAAa,QAAQ,eAAe;AAAM,WAAO;AAErD,aAAW,CAAC,aAAa,QAAQ,KAAK,WAAW;AAC/C,UAAM,IAAI,aAAa,qBAAiB,2CAAe,QAAQ,GAAG,WAAW,CAAC;AAAA,EAChF;AAEA,SAAO;AACT;AAEA,SAAS,eAAe,OAAc,aAAyC;A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C;AAAA,QAClE,YAAY;AAAA,MACd;AAAA,IACF;AAAA,IACA,EAAE,aAAa,YAAY,aAAa,IAAI;AAAA,EAC9C;AAEA,SAAO,OAAO;AAChB;","names":["i"]}
1
+ {"version":3,"sources":["../../../../src/state/modules/element-trees.ts"],"sourcesContent":["import { type Operation } from 'ot-json0'\nimport { getIn, removeIn, setIn } from 'immutable'\n\nimport { type Element, type ElementData, isElementReference } from '@makeswift/controls'\n\nimport * as Introspection from '../../prop-controllers/introspection'\n\nimport { type Action, type UnknownAction, isKnownAction } from '../actions'\n\nimport { ReadOnlyActionTypes } from '../actions/internal/read-only-actions'\nimport { ReadWriteActionTypes } from '../actions/internal/read-write-actions'\n\nimport { getRootElement, type Document } from './read-only-documents'\nimport { type DescriptorsByComponentType } from './prop-controllers'\n\nexport type ElementTree = {\n elements: Map<string, Element>\n elementIds: Map<string, string>\n}\n\nexport type State = Map<string, ElementTree>\n\nexport function getInitialState(\n documents?: Map<string, Document>,\n descriptors?: DescriptorsByComponentType,\n): State {\n const state = new Map<string, ElementTree>()\n if (documents == null || descriptors == null) return state\n\n for (const [documentKey, document] of documents) {\n state.set(documentKey, buildElementTree(getRootElement(document), descriptors))\n }\n\n return state\n}\n\nfunction getElementTree(state: State, documentKey: string): ElementTree | null {\n return state.get(documentKey) ?? null\n}\n\nexport function getElements(state: State, documentKey: string): Map<string, Element> {\n return getElementTree(state, documentKey)?.elements ?? new Map()\n}\n\nexport function getElementIds(state: State, documentKey: string): Map<string, string> {\n return getElementTree(state, documentKey)?.elementIds ?? new Map()\n}\n\nexport function getElement(state: State, documentKey: string, elementKey: string): Element | null {\n return getElements(state, documentKey).get(elementKey) ?? null\n}\n\nexport function getElementId(state: State, documentKey: string, elementKey: string): string | null {\n return getElementIds(state, documentKey).get(elementKey) ?? null\n}\n\nexport function reducer(state: State = getInitialState(), action: Action | UnknownAction): State {\n if (!isKnownAction(action)) return state\n\n switch (action.type) {\n case ReadOnlyActionTypes.CREATE_ELEMENT_TREE: {\n const { document, descriptors } = action.payload\n return new Map(state).set(\n document.key,\n buildElementTree(getRootElement(document), descriptors),\n )\n }\n\n case ReadOnlyActionTypes.DELETE_ELEMENT_TREE: {\n const nextState = new Map(state)\n const deleted = nextState.delete(action.payload.documentKey)\n return deleted ? nextState : state\n }\n\n case ReadWriteActionTypes.CHANGE_ELEMENT_TREE: {\n const { oldDocument, newDocument, descriptors, operation } = action.payload\n const documentKey = oldDocument.key\n console.assert(\n documentKey === newDocument.key,\n `Mismatching document keys ${documentKey} !== ${newDocument.key}`,\n )\n\n const elementTree = state.get(documentKey)\n if (elementTree == null) return state\n\n const updatedElementTree = applyChanges(\n elementTree,\n descriptors,\n {\n old: getRootElement(oldDocument),\n new: getRootElement(newDocument),\n },\n operation,\n )\n\n return new Map(state).set(documentKey, updatedElementTree)\n }\n\n default:\n return state\n }\n}\n\nexport function* traverseElementTree(\n element: Element,\n descriptors: DescriptorsByComponentType,\n): Generator<Element> {\n yield element\n if (isElementReference(element)) return\n\n const elementDescriptors = descriptors.get(element.type)\n if (elementDescriptors == null) return\n\n for (const [propKey, descriptor] of Object.entries(elementDescriptors)) {\n const children = Introspection.getElementChildren(descriptor, element.props[propKey])\n for (const child of children) {\n yield* traverseElementTree(child, descriptors)\n }\n }\n}\n\nfunction getElementIdProp(\n element: ElementData,\n descriptors: DescriptorsByComponentType,\n): string | null {\n const elementDescriptors = descriptors.get(element.type)\n if (elementDescriptors == null) return null\n\n for (const [propName, descriptor] of Object.entries(elementDescriptors)) {\n const elementId = Introspection.getElementId(descriptor, element.props[propName])\n if (elementId != null) return elementId\n }\n\n return null\n}\n\nexport function buildElementTree(\n rootElement: Element,\n descriptors: DescriptorsByComponentType,\n): ElementTree {\n const elements = new Map<string, Element>()\n const elementIds = new Map<string, string>()\n\n for (const element of traverseElementTree(rootElement, descriptors)) {\n elements.set(element.key, element)\n if (!isElementReference(element)) {\n const elementId = getElementIdProp(element, descriptors)\n if (elementId != null) elementIds.set(element.key, elementId)\n }\n }\n\n return {\n elements,\n elementIds,\n }\n}\n\ntype OperationPath = Operation[number]['p']\n\n// performance-sensitive function, intentionally not using `elementData` schema here\nfunction isElement(item: unknown): item is Element {\n return (\n typeof item === 'object' &&\n item != null &&\n 'key' in item &&\n 'type' in item &&\n typeof item.key === 'string' &&\n typeof item.type === 'string'\n )\n}\n\ntype ElementOperationPath = { elementPath: OperationPath; propName: string | null }\n\nfunction getElementOperationPath(path: OperationPath): ElementOperationPath {\n if (path.length === 0) {\n return { elementPath: [], propName: null }\n }\n\n const i = path.findLastIndex(\n (fragment, i) =>\n typeof fragment === 'number' && (i === path.length - 1 || path[i + 1] === 'props'),\n )\n\n if ((i === -1 && path[0] !== 'props') || path.length - i < 3) {\n console.error('Operation path does not point to an element property', { path })\n return { elementPath: [], propName: null }\n }\n\n return { elementPath: path.slice(0, i + 1), propName: `${path.slice(i + 1).at(1)}` }\n}\n\nexport function getChangedElementsPaths(\n path: OperationPath,\n): [ElementOperationPath, ...ElementOperationPath[]] {\n let elementOp = getElementOperationPath(path)\n const result: [ElementOperationPath, ...ElementOperationPath[]] = [elementOp]\n while (elementOp.elementPath.length > 0) {\n elementOp = getElementOperationPath(elementOp.elementPath.slice(0, -1))\n result.push(elementOp)\n }\n\n return result\n}\n\nfunction getElementByPath(rootElement: Element, elementPath: OperationPath): Element | null {\n const item = getIn(rootElement, elementPath)\n if (!isElement(item)) {\n console.error('Expected an element, got', item, {\n rootElement,\n elementPath,\n })\n\n return null\n }\n\n return item\n}\n\nfunction getElementAndPropName(\n rootElement: Element,\n { elementPath, propName }: ElementOperationPath,\n): [Element, string | null] {\n const element = getElementByPath(rootElement, elementPath)\n return element != null ? [element, propName] : [rootElement, null]\n}\n\nfunction updateParentElements(\n elements: ElementTree['elements'],\n elementPaths: ElementOperationPath[],\n rootElement: Element,\n): void {\n elementPaths.forEach(({ elementPath }) => {\n const element = getElementByPath(rootElement, elementPath)\n if (element != null) elements.set(element.key, element)\n })\n}\n\nfunction getPropChildren(\n element: Element,\n propName: string,\n descriptors: DescriptorsByComponentType,\n): Element[] | null {\n if (isElementReference(element)) return null\n\n const propDescriptor = descriptors.get(element.type)?.[propName]\n if (propDescriptor == null) return null\n\n return Introspection.getElementChildren(propDescriptor, element.props[propName])\n}\n\nfunction isChildrenProp(\n element: Element,\n propName: string,\n descriptors: DescriptorsByComponentType,\n): boolean {\n const children = getPropChildren(element, propName, descriptors)\n return children != null\n}\n\nfunction deleteElement(\n { elements, elementIds }: ElementTree,\n elementToDelete: Element,\n descriptors: DescriptorsByComponentType,\n) {\n for (const element of traverseElementTree(elementToDelete, descriptors)) {\n elements.delete(element.key)\n elementIds.delete(element.key)\n }\n}\n\nfunction deleteChildrenInProp(\n elementTree: ElementTree,\n parentElement: Element,\n propName: string,\n descriptors: DescriptorsByComponentType,\n) {\n const childrenInProp = getPropChildren(parentElement, propName, descriptors)\n\n if (childrenInProp == null) {\n return\n }\n\n for (const child of childrenInProp) {\n deleteElement(elementTree, child, descriptors)\n }\n}\n\nfunction deleteElementOrProp(\n { elements, elementIds }: ElementTree,\n targetElement: Element,\n propName: string | null,\n descriptors: DescriptorsByComponentType,\n) {\n if (propName == null) {\n deleteElement({ elements, elementIds }, targetElement, descriptors)\n return\n }\n\n if (isChildrenProp(targetElement, propName, descriptors)) {\n deleteChildrenInProp({ elements, elementIds }, targetElement, propName, descriptors)\n }\n\n // The provided targetElement might refer to an element from the before/after documents,\n // not the actual element object from the ElementTree\n const elementInTree = elements.get(targetElement.key)\n\n if (!elementInTree) {\n console.error(\n `Attempting to remove prop ${propName} from element ${targetElement.key} not found in tree`,\n )\n return\n }\n\n if (!isElementReference(elementInTree)) {\n const newProps = { ...elementInTree.props }\n delete newProps[propName]\n elements.set(targetElement.key, { ...elementInTree, props: newProps })\n }\n}\n\nfunction applyDelete(\n elementTree: ElementTree,\n descriptors: DescriptorsByComponentType,\n rootElements: { before: Element; after: Element },\n path: OperationPath,\n): ElementTree {\n const [targetElementPath, ...parentElementPaths] = getChangedElementsPaths(path)\n const [targetElement, propName] = getElementAndPropName(rootElements.before, targetElementPath)\n\n const elements = new Map(elementTree.elements)\n const elementIds = new Map(elementTree.elementIds)\n\n deleteElementOrProp({ elements, elementIds }, targetElement, propName, descriptors)\n\n // Use the \"after\" state to efficiently update all of parent subtrees in the state\n updateParentElements(elements, parentElementPaths, rootElements.after)\n\n return {\n elements,\n elementIds,\n }\n}\n\nfunction insertElement(\n { elements, elementIds }: ElementTree,\n insertedElement: Element,\n propName: string | null,\n descriptors: DescriptorsByComponentType,\n) {\n if (propName == null || isChildrenProp(insertedElement, propName, descriptors)) {\n for (const element of traverseElementTree(insertedElement, descriptors)) {\n elements.set(element.key, element)\n if (!isElementReference(element)) {\n const elementId = getElementIdProp(element, descriptors)\n if (elementId != null) elementIds.set(element.key, elementId)\n }\n }\n } else {\n elements.set(insertedElement.key, insertedElement)\n if (!isElementReference(insertedElement)) {\n const elementId = getElementIdProp(insertedElement, descriptors)\n if (elementId != null) elementIds.set(insertedElement.key, elementId)\n }\n }\n}\n\nfunction applyInsert(\n elementTree: ElementTree,\n descriptors: DescriptorsByComponentType,\n rootElements: { before: Element; after: Element },\n path: OperationPath,\n): ElementTree {\n const [insertedElementPath, ...parentElementPaths] = getChangedElementsPaths(path)\n const [insertedElement, propName] = getElementAndPropName(rootElements.after, insertedElementPath)\n\n const elements = new Map(elementTree.elements)\n const elementIds = new Map(elementTree.elementIds)\n\n insertElement({ elements, elementIds }, insertedElement, propName, descriptors)\n\n // Use the \"after\" state to efficiently update all of parent subtrees in the state\n updateParentElements(elements, parentElementPaths, rootElements.after)\n\n return {\n elements,\n elementIds,\n }\n}\n\nfunction applyUpdate(\n elementTree: ElementTree,\n descriptors: DescriptorsByComponentType,\n rootElements: { before: Element; after: Element },\n path: OperationPath,\n): ElementTree {\n const [updateElementPath, ...parentElementPaths] = getChangedElementsPaths(path)\n const [targetElement, propName] = getElementAndPropName(rootElements.before, updateElementPath)\n const [insertedElement, _] = getElementAndPropName(rootElements.after, updateElementPath)\n\n const elements = new Map(elementTree.elements)\n const elementIds = new Map(elementTree.elementIds)\n\n deleteElementOrProp({ elements, elementIds }, targetElement, propName, descriptors)\n\n insertElement({ elements, elementIds }, insertedElement, propName, descriptors)\n\n // Use the \"after\" state to efficiently update all of parent subtrees in the state\n updateParentElements(elements, parentElementPaths, rootElements.after)\n\n return {\n elements,\n elementIds,\n }\n}\n\nfunction applyOpComponent(root: Element, component: Operation[number]): Element {\n let applied: Element = root\n\n if ('ld' in component || 'od' in component) {\n applied = removeIn(applied, component.p)\n }\n\n if ('li' in component) {\n applied = setIn(applied, component.p, component.li)\n }\n\n if ('oi' in component) {\n applied = setIn(applied, component.p, component.oi)\n }\n\n return applied\n}\n\nfunction selectTreeTransform(op: Operation[number]): typeof applyUpdate {\n const hasDelete = 'ld' in op || 'od' in op\n const hasInsert = 'li' in op || 'oi' in op\n\n if (hasDelete && hasInsert) return applyUpdate\n if (hasDelete) return applyDelete\n if (hasInsert) return applyInsert\n\n return elementTree => elementTree\n}\n\nfunction applyChanges(\n elementTree: ElementTree,\n descriptors: DescriptorsByComponentType,\n rootElements: { old: Element; new: Element },\n operation: Operation,\n): ElementTree {\n // Updates the element tree \"cache\" based on the provided operation, which can\n // be composed of 1-n component ops. We apply each component op sequentially\n // to the 'old' root element to determine the changed elements and update the\n // cache accordingly at each intermediate step.\n const result = operation.reduce(\n (acc, op) => {\n const rootBefore = acc.rootBefore\n\n // If there's only one component op, we can skip the application of the op\n // and assume that the result will be the 'new' root element provided to\n // us by the builder.\n const rootAfter = operation.length > 1 ? applyOpComponent(rootBefore, op) : rootElements.new\n\n const roots = { before: rootBefore, after: rootAfter }\n const applyChange = selectTreeTransform(op)\n\n return {\n elementTree: applyChange(acc.elementTree, descriptors, roots, op.p),\n rootBefore: rootAfter,\n }\n },\n { elementTree, rootBefore: rootElements.old },\n )\n\n return result.elementTree\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA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;AAAA,EAC9C;AAEA,SAAO,OAAO;AAChB;","names":["i"]}
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../../../../src/state/modules/is-in-builder.ts"],"sourcesContent":["import { type Action, type UnknownAction, isKnownAction } from '../actions'\nimport { ReadOnlyActionTypes } from '../actions/internal/read-only-actions'\n\nexport type State = boolean\n\nexport function getInitialState(): State {\n return false\n}\n\nexport function getIsInBuilder(state: State): boolean {\n return state\n}\n\nexport function reducer(state: State = getInitialState(), action: Action | UnknownAction): State {\n if (!isKnownAction(action)) return state\n\n switch (action.type) {\n case ReadOnlyActionTypes.SET_IS_IN_BUILDER:\n return action.payload\n\n default:\n return state\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,qBAA+D;AAC/D,+BAAoC;AAI7B,SAAS,kBAAyB;AACvC,SAAO;AACT;AAEO,SAAS,eAAe,OAAuB;AACpD,SAAO;AACT;AAEO,SAAS,QAAQ,QAAe,gBAAgB,GAAG,QAAuC;AAC/F,MAAI,KAAC,8BAAc,MAAM;AAAG,WAAO;AAEnC,UAAQ,OAAO,MAAM;AAAA,IACnB,KAAK,6CAAoB;AACvB,aAAO,OAAO;AAAA,IAEhB;AACE,aAAO;AAAA,EACX;AACF;","names":[]}
@@ -36,10 +36,7 @@ var ElementTrees = __toESM(require("../modules/element-trees"));
36
36
  var import_control = require("../../controls/control");
37
37
  function getTranslatableContent(descriptors, elementTree) {
38
38
  const translatableData = {};
39
- for (const element of ElementTrees.traverseElementTree(
40
- elementTree,
41
- descriptors
42
- )) {
39
+ for (const element of ElementTrees.traverseElementTree(elementTree, descriptors)) {
43
40
  if (Documents.isElementReference(element))
44
41
  continue;
45
42
  const elementDescriptors = descriptors.get(element.type);
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../src/state/translations/get.ts"],"sourcesContent":["import * as Documents from '../modules/read-only-documents'\nimport * as ElementTrees from '../modules/element-trees'\nimport { getTranslatableData } from '../../controls/control'\nimport type {DescriptorsByComponentType} from '../modules/prop-controllers'\n\nexport function getTranslatableContent(\n descriptors: DescriptorsByComponentType,\n elementTree: Documents.ElementData,\n): Record<string, Documents.Data> {\n const translatableData: Record<string, Documents.Data> = {}\n\n for (const element of ElementTrees.traverseElementTree(\n elementTree,\n descriptors,\n )) {\n if (Documents.isElementReference(element)) continue\n\n const elementDescriptors = descriptors.get(element.type)\n if (elementDescriptors == null) continue\n\n Object.entries(elementDescriptors).forEach(([propName, descriptor]) => {\n const translatablePropData = getTranslatableData(descriptor, element.props[propName])\n\n if (translatablePropData != null) {\n translatableData[`${element.key}:${propName}`] = translatablePropData\n }\n })\n }\n\n return translatableData\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,gBAA2B;AAC3B,mBAA8B;AAC9B,qBAAoC;AAG7B,SAAS,uBACd,aACA,aACgC;AAChC,QAAM,mBAAmD,CAAC;AAE1D,aAAW,WAAW,aAAa;AAAA,IACjC;AAAA,IACA;AAAA,EACF,GAAG;AACD,QAAI,UAAU,mBAAmB,OAAO;AAAG;AAE3C,UAAM,qBAAqB,YAAY,IAAI,QAAQ,IAAI;AACvD,QAAI,sBAAsB;AAAM;AAEhC,WAAO,QAAQ,kBAAkB,EAAE,QAAQ,CAAC,CAAC,UAAU,UAAU,MAAM;AACrE,YAAM,2BAAuB,oCAAoB,YAAY,QAAQ,MAAM,QAAQ,CAAC;AAEpF,UAAI,wBAAwB,MAAM;AAChC,yBAAiB,GAAG,QAAQ,GAAG,IAAI,QAAQ,EAAE,IAAI;AAAA,MACnD;AAAA,IACF,CAAC;AAAA,EACH;AAEA,SAAO;AACT;","names":[]}
1
+ {"version":3,"sources":["../../../../src/state/translations/get.ts"],"sourcesContent":["import * as Documents from '../modules/read-only-documents'\nimport * as ElementTrees from '../modules/element-trees'\nimport { getTranslatableData } from '../../controls/control'\nimport type { DescriptorsByComponentType } from '../modules/prop-controllers'\n\nexport function getTranslatableContent(\n descriptors: DescriptorsByComponentType,\n elementTree: Documents.ElementData,\n): Record<string, Documents.Data> {\n const translatableData: Record<string, Documents.Data> = {}\n\n for (const element of ElementTrees.traverseElementTree(elementTree, descriptors)) {\n if (Documents.isElementReference(element)) continue\n\n const elementDescriptors = descriptors.get(element.type)\n if (elementDescriptors == null) continue\n\n Object.entries(elementDescriptors).forEach(([propName, descriptor]) => {\n const translatablePropData = getTranslatableData(descriptor, element.props[propName])\n\n if (translatablePropData != null) {\n translatableData[`${element.key}:${propName}`] = translatablePropData\n }\n })\n }\n\n return translatableData\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,gBAA2B;AAC3B,mBAA8B;AAC9B,qBAAoC;AAG7B,SAAS,uBACd,aACA,aACgC;AAChC,QAAM,mBAAmD,CAAC;AAE1D,aAAW,WAAW,aAAa,oBAAoB,aAAa,WAAW,GAAG;AAChF,QAAI,UAAU,mBAAmB,OAAO;AAAG;AAE3C,UAAM,qBAAqB,YAAY,IAAI,QAAQ,IAAI;AACvD,QAAI,sBAAsB;AAAM;AAEhC,WAAO,QAAQ,kBAAkB,EAAE,QAAQ,CAAC,CAAC,UAAU,UAAU,MAAM;AACrE,YAAM,2BAAuB,oCAAoB,YAAY,QAAQ,MAAM,QAAQ,CAAC;AAEpF,UAAI,wBAAwB,MAAM;AAChC,yBAAiB,GAAG,QAAQ,GAAG,IAAI,QAAQ,EAAE,IAAI;AAAA,MACnD;AAAA,IACF,CAAC;AAAA,EACH;AAEA,SAAO;AACT;","names":[]}
@@ -16,12 +16,14 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
16
16
  var fixtures_exports = {};
17
17
  module.exports = __toCommonJS(fixtures_exports);
18
18
  __reExport(fixtures_exports, require("./origins"), module.exports);
19
- __reExport(fixtures_exports, require("./site-version"), module.exports);
20
19
  __reExport(fixtures_exports, require("./resources"), module.exports);
20
+ __reExport(fixtures_exports, require("./site-version"), module.exports);
21
+ __reExport(fixtures_exports, require("./snippet"), module.exports);
21
22
  // Annotate the CommonJS export names for ESM import in node:
22
23
  0 && (module.exports = {
23
24
  ...require("./origins"),
25
+ ...require("./resources"),
24
26
  ...require("./site-version"),
25
- ...require("./resources")
27
+ ...require("./snippet")
26
28
  });
27
29
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../src/testing/fixtures/index.ts"],"sourcesContent":["export * from './origins'\nexport * from './site-version'\nexport * from './resources'\n"],"mappings":";;;;;;;;;;;;;;;AAAA;AAAA;AAAA,6BAAc,sBAAd;AACA,6BAAc,2BADd;AAEA,6BAAc,wBAFd;","names":[]}
1
+ {"version":3,"sources":["../../../../src/testing/fixtures/index.ts"],"sourcesContent":["export * from './origins'\nexport * from './resources'\nexport * from './site-version'\nexport * from './snippet'\n"],"mappings":";;;;;;;;;;;;;;;AAAA;AAAA;AAAA,6BAAc,sBAAd;AACA,6BAAc,wBADd;AAEA,6BAAc,2BAFd;AAGA,6BAAc,sBAHd;","names":[]}
@@ -16,11 +16,21 @@ var __copyProps = (to, from, except, desc) => {
16
16
  return to;
17
17
  };
18
18
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
- var is_exports = {};
20
- __export(is_exports, {
21
- default: () => is_default
19
+ var snippet_exports = {};
20
+ __export(snippet_exports, {
21
+ createSnippet: () => createSnippet
22
22
  });
23
- module.exports = __toCommonJS(is_exports);
24
- var import_controls = require("@makeswift/controls");
25
- var is_default = import_controls.is;
26
- //# sourceMappingURL=is.js.map
23
+ module.exports = __toCommonJS(snippet_exports);
24
+ const createSnippet = ({ id, code }) => ({
25
+ id,
26
+ code,
27
+ location: "HEAD",
28
+ liveEnabled: true,
29
+ builderEnabled: true,
30
+ cleanup: null
31
+ });
32
+ // Annotate the CommonJS export names for ESM import in node:
33
+ 0 && (module.exports = {
34
+ createSnippet
35
+ });
36
+ //# sourceMappingURL=snippet.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../../src/testing/fixtures/snippet.ts"],"sourcesContent":["import { type Snippet } from '../../client/page-snapshot'\n\nexport const createSnippet = ({ id, code }: { id: string; code: string }): Snippet => ({\n id,\n code,\n location: 'HEAD',\n liveEnabled: true,\n builderEnabled: true,\n cleanup: null,\n})\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAEO,MAAM,gBAAgB,CAAC,EAAE,IAAI,KAAK,OAA8C;AAAA,EACrF;AAAA,EACA;AAAA,EACA,UAAU;AAAA,EACV,aAAa;AAAA,EACb,gBAAgB;AAAA,EAChB,SAAS;AACX;","names":[]}
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/translations/index.ts"],"sourcesContent":["export { getTranslatableContent } from '../state/translations/get'\nexport { mergeTranslatedContent } from '../state/translations/merge'\nexport type { DescriptorsByComponentType, DescriptorsByProp } from '../state/modules/prop-controllers'\nexport type { ElementData, Data, Element } from '../state/read-only-state'\nexport type { TranslationDto } from '@makeswift/controls'\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,iBAAuC;AACvC,mBAAuC;","names":[]}
1
+ {"version":3,"sources":["../../../src/translations/index.ts"],"sourcesContent":["export { getTranslatableContent } from '../state/translations/get'\nexport { mergeTranslatedContent } from '../state/translations/merge'\nexport type {\n DescriptorsByComponentType,\n DescriptorsByProp,\n} from '../state/modules/prop-controllers'\nexport type { ElementData, Data, Element } from '../state/read-only-state'\nexport type { TranslationDto } from '@makeswift/controls'\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,iBAAuC;AACvC,mBAAuC;","names":[]}
@@ -18,11 +18,8 @@ var __copyProps = (to, from, except, desc) => {
18
18
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
19
  var unstable_framework_support_exports = {};
20
20
  __export(unstable_framework_support_exports, {
21
- DefaultHead: () => import_framework_context.DefaultHead,
22
- DefaultHeadSnippet: () => import_framework_context.DefaultHeadSnippet,
23
- DefaultImage: () => import_framework_context.DefaultImage,
24
21
  DefaultRootStyleRegistry: () => import_root_style_registry.DefaultRootStyleRegistry,
25
- FrameworkContext: () => import_framework_context.FrameworkContext,
22
+ FrameworkContextProvider: () => import_framework_context.FrameworkContextProvider,
26
23
  GoogleFontLink: () => import_GoogleFontLink.GoogleFontLink,
27
24
  MAKESWIFT_SITE_VERSION_COOKIE: () => import_preview.MAKESWIFT_SITE_VERSION_COOKIE,
28
25
  MakeswiftClient: () => import_client.MakeswiftClient,
@@ -67,11 +64,8 @@ var import_root_style_registry = require("../runtimes/react/root-style-registry"
67
64
  var import_react_runtime = require("../runtimes/react/react-runtime");
68
65
  // Annotate the CommonJS export names for ESM import in node:
69
66
  0 && (module.exports = {
70
- DefaultHead,
71
- DefaultHeadSnippet,
72
- DefaultImage,
73
67
  DefaultRootStyleRegistry,
74
- FrameworkContext,
68
+ FrameworkContextProvider,
75
69
  GoogleFontLink,
76
70
  MAKESWIFT_SITE_VERSION_COOKIE,
77
71
  MakeswiftClient,
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/unstable-framework-support/index.ts"],"sourcesContent":["export {\n type SiteVersion,\n serializeSiteVersion,\n deserializeSiteVersion,\n secondsUntilSiteVersionExpiration,\n} from '../api/site-version'\n\nexport {\n type ApiHandlerUserConfig,\n createApiHandler,\n type SitePublishedWebhookPayloadData,\n} from '../api-handler'\nexport { SET_COOKIE_HEADER, cookieSettingOptions } from '../api-handler/cookies'\nexport { REDIRECT_SEARCH_PARAM, redirectLiveHandler } from '../api-handler/handlers/redirect-live'\nexport { toApiRequest, pipeResponseTo } from '../api-handler/node-request-response'\nexport { MAKESWIFT_SITE_VERSION_COOKIE, SearchParams } from '../api-handler/preview'\n\nexport { MakeswiftClient } from '../client'\n\nexport { type BreakpointsInput as Breakpoints } from '../state/modules/breakpoints'\n\nexport {\n FrameworkContext,\n DefaultHead,\n DefaultHeadSnippet,\n DefaultImage,\n} from '../runtimes/react/components/framework-context'\n\nexport { MakeswiftComponent } from '../runtimes/react/components/MakeswiftComponent'\nexport { Page } from '../runtimes/react/components/page'\nexport { RuntimeProvider } from '../runtimes/react/components/RuntimeProvider'\nexport { Slot } from '../runtimes/react/components/Slot'\n\nexport { GoogleFontLink } from '../runtimes/react/components/GoogleFontLink'\nexport { MakeswiftFonts } from '../runtimes/react/components/MakeswiftFonts'\n\nexport {\n createRootStyleCache,\n RootStyleRegistry,\n DefaultRootStyleRegistry,\n styleTagHtml,\n StyleTagSSR,\n type RootStyleProps,\n} from '../runtimes/react/root-style-registry'\n\nexport { ReactRuntime, type StoreKey } from '../runtimes/react/react-runtime'\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,0BAKO;AAEP,yBAIO;AACP,qBAAwD;AACxD,2BAA2D;AAC3D,mCAA6C;AAC7C,qBAA4D;AAE5D,oBAAgC;AAIhC,+BAKO;AAEP,gCAAmC;AACnC,kBAAqB;AACrB,6BAAgC;AAChC,kBAAqB;AAErB,4BAA+B;AAC/B,4BAA+B;AAE/B,iCAOO;AAEP,2BAA4C;","names":[]}
1
+ {"version":3,"sources":["../../../src/unstable-framework-support/index.ts"],"sourcesContent":["export {\n type SiteVersion,\n serializeSiteVersion,\n deserializeSiteVersion,\n secondsUntilSiteVersionExpiration,\n} from '../api/site-version'\n\nexport {\n type ApiHandlerUserConfig,\n createApiHandler,\n type SitePublishedWebhookPayloadData,\n} from '../api-handler'\nexport { SET_COOKIE_HEADER, cookieSettingOptions } from '../api-handler/cookies'\nexport { REDIRECT_SEARCH_PARAM, redirectLiveHandler } from '../api-handler/handlers/redirect-live'\nexport { toApiRequest, pipeResponseTo } from '../api-handler/node-request-response'\nexport { MAKESWIFT_SITE_VERSION_COOKIE, SearchParams } from '../api-handler/preview'\n\nexport { MakeswiftClient } from '../client'\n\nexport { type BreakpointsInput as Breakpoints } from '../state/modules/breakpoints'\n\nexport {\n type FrameworkContext,\n FrameworkContextProvider,\n} from '../runtimes/react/components/framework-context'\n\nexport { MakeswiftComponent } from '../runtimes/react/components/MakeswiftComponent'\nexport { Page } from '../runtimes/react/components/page'\nexport { RuntimeProvider } from '../runtimes/react/components/RuntimeProvider'\nexport { Slot } from '../runtimes/react/components/Slot'\n\nexport { GoogleFontLink } from '../runtimes/react/components/GoogleFontLink'\nexport { MakeswiftFonts } from '../runtimes/react/components/MakeswiftFonts'\n\nexport {\n createRootStyleCache,\n RootStyleRegistry,\n DefaultRootStyleRegistry,\n styleTagHtml,\n StyleTagSSR,\n type RootStyleProps,\n} from '../runtimes/react/root-style-registry'\n\nexport { ReactRuntime, type StoreKey } from '../runtimes/react/react-runtime'\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,0BAKO;AAEP,yBAIO;AACP,qBAAwD;AACxD,2BAA2D;AAC3D,mCAA6C;AAC7C,qBAA4D;AAE5D,oBAAgC;AAIhC,+BAGO;AAEP,gCAAmC;AACnC,kBAAqB;AACrB,6BAAgC;AAChC,kBAAqB;AAErB,4BAA+B;AAC/B,4BAA+B;AAE/B,iCAOO;AAEP,2BAA4C;","names":[]}
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/utils/intersection.ts"],"sourcesContent":["import deepEqual from './deepEqual'\nimport keys from './keys'\n\nexport default function intersection<A extends Record<string, unknown>, B extends A>(\n a: A,\n b: B,\n isEqual: (a: unknown, b: unknown) => boolean = deepEqual,\n): { [K in keyof A]: A[K] | null } {\n const allKeys = [...new Set([...keys(a), ...keys(b)])] as (keyof A)[]\n\n return allKeys.reduce(\n (acc, k) => {\n if (isEqual(a[k], b[k])) acc[k] = a[k]\n else acc[k] = null\n\n return acc\n },\n {} as { [K in keyof A]: A[K] | null },\n )\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,uBAAsB;AACtB,kBAAiB;AAEF,SAAR,aACL,GACA,GACA,UAA+C,iBAAAA,SACd;AACjC,QAAM,UAAU,CAAC,GAAG,oBAAI,IAAI,CAAC,OAAG,YAAAC,SAAK,CAAC,GAAG,OAAG,YAAAA,SAAK,CAAC,CAAC,CAAC,CAAC;AAErD,SAAO,QAAQ;AAAA,IACb,CAAC,KAAK,MAAM;AACV,UAAI,QAAQ,EAAE,CAAC,GAAG,EAAE,CAAC,CAAC;AAAG,YAAI,CAAC,IAAI,EAAE,CAAC;AAAA;AAChC,YAAI,CAAC,IAAI;AAEd,aAAO;AAAA,IACT;AAAA,IACA,CAAC;AAAA,EACH;AACF;","names":["deepEqual","keys"]}
1
+ {"version":3,"sources":["../../../src/utils/intersection.ts"],"sourcesContent":["import { type Data } from '@makeswift/controls'\n\nimport deepEqual from './deepEqual'\nimport keys from './keys'\n\nexport default function intersection<A extends Record<string, Data>, B extends A>(\n a: A,\n b: B,\n isEqual: (a: Data, b: Data) => boolean = deepEqual,\n): { [K in keyof A]: A[K] | null } {\n const allKeys = [...new Set([...keys(a), ...keys(b)])] as (keyof A)[]\n\n return allKeys.reduce(\n (acc, k) => {\n if (isEqual(a[k], b[k])) acc[k] = a[k]\n else acc[k] = null\n\n return acc\n },\n {} as { [K in keyof A]: A[K] | null },\n )\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAEA,uBAAsB;AACtB,kBAAiB;AAEF,SAAR,aACL,GACA,GACA,UAAyC,iBAAAA,SACR;AACjC,QAAM,UAAU,CAAC,GAAG,oBAAI,IAAI,CAAC,OAAG,YAAAC,SAAK,CAAC,GAAG,OAAG,YAAAA,SAAK,CAAC,CAAC,CAAC,CAAC;AAErD,SAAO,QAAQ;AAAA,IACb,CAAC,KAAK,MAAM;AACV,UAAI,QAAQ,EAAE,CAAC,GAAG,EAAE,CAAC,CAAC;AAAG,YAAI,CAAC,IAAI,EAAE,CAAC;AAAA;AAChC,YAAI,CAAC,IAAI;AAEd,aAAO;AAAA,IACT;AAAA,IACA,CAAC;AAAA,EACH;AACF;","names":["deepEqual","keys"]}
@@ -9,7 +9,7 @@ class MakeswiftGraphQLApiClient {
9
9
  graphqlClient;
10
10
  constructor({ endpoint }) {
11
11
  this.graphqlClient = new GraphQLClient(endpoint, {
12
- "makeswift-runtime-version": "0.28.8-canary.1"
12
+ "makeswift-runtime-version": "0.28.8-canary.11"
13
13
  });
14
14
  }
15
15
  async createTableRecord(tableId, columns) {
@@ -113,7 +113,7 @@ class MakeswiftRestAPIClient {
113
113
  const requestHeaders = new Headers({
114
114
  "x-api-key": this.apiKey,
115
115
  "makeswift-site-api-key": this.apiKey,
116
- "makeswift-runtime-version": "0.28.8-canary.1"
116
+ "makeswift-runtime-version": "0.28.8-canary.11"
117
117
  });
118
118
  if (siteVersion?.token) {
119
119
  requestUrl.searchParams.set("version", siteVersion.version);
@@ -8,7 +8,7 @@ async function manifestHandler(req, { apiKey, manifest }) {
8
8
  return ApiResponse.json({ message: "Unauthorized" }, { status: 401 });
9
9
  }
10
10
  return ApiResponse.json({
11
- version: "0.28.8-canary.1",
11
+ version: "0.28.8-canary.11",
12
12
  interactionMode: true,
13
13
  clientSideNavigation: false,
14
14
  elementFromPoint: false,
@@ -669,7 +669,7 @@ Received "${apiKey}" instead.`
669
669
  headers: {
670
670
  "x-api-key": this.apiKey,
671
671
  "makeswift-site-api-key": this.apiKey,
672
- "makeswift-runtime-version": "0.28.8-canary.1",
672
+ "makeswift-runtime-version": "0.28.8-canary.11",
673
673
  "content-type": "application/json"
674
674
  },
675
675
  body: JSON.stringify({ token }),
@@ -1,6 +1,6 @@
1
1
  "use client";
2
2
  import { jsx } from "react/jsx-runtime";
3
- import { useState, useEffect, forwardRef, useImperativeHandle } from "react";
3
+ import { useState, useEffect, useMemo, forwardRef, useImperativeHandle } from "react";
4
4
  import { useIsomorphicLayoutEffect } from "../../hooks/useIsomorphicLayoutEffect";
5
5
  import { useStyle } from "../../../runtimes/react/use-style";
6
6
  import { cx } from "@emotion/css";
@@ -71,6 +71,7 @@ const Embed = forwardRef(function Embed2({ id, width, margin, html = defaultHtml
71
71
  });
72
72
  }, [container, html]);
73
73
  const className = useStyle({ minHeight: 15 });
74
+ const dangerouslySetInnerHTML = useMemo(() => ({ __html: html }), [html]);
74
75
  if (shouldRender === false)
75
76
  return null;
76
77
  return /* @__PURE__ */ jsx(
@@ -79,7 +80,7 @@ const Embed = forwardRef(function Embed2({ id, width, margin, html = defaultHtml
79
80
  ref: setContainer,
80
81
  id,
81
82
  className: cx(className, width, margin),
82
- dangerouslySetInnerHTML: { __html: html }
83
+ dangerouslySetInnerHTML
83
84
  }
84
85
  );
85
86
  });
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../../src/components/builtin/Embed/Embed.tsx"],"sourcesContent":["'use client'\n\n/* eslint-env browser */\n\nimport { useState, useEffect, forwardRef, Ref, useImperativeHandle } from 'react'\n\nimport { useIsomorphicLayoutEffect } from '../../hooks/useIsomorphicLayoutEffect'\nimport { useStyle } from '../../../runtimes/react/use-style'\nimport { cx } from '@emotion/css'\n\ntype Props = {\n id?: string\n html?: string\n width?: string\n margin?: string\n}\n\nconst defaultHtml = `<div style=\"padding: 24px; background-color: rgba(161, 168, 194, 0.18); overflow: hidden;\">\n<svg width=\"316\" height=\"168\" viewBox=\"0 0 316 168\" fill=\"none\" xmlns=\"http://www.w3.org/2000/svg\">\n<rect width=\"70\" height=\"8\" rx=\"2\" fill=\"#A1A8C2\" fill-opacity=\"0.5\"/>\n<rect x=\"78\" width=\"30\" height=\"8\" rx=\"2\" fill=\"#A1A8C2\" fill-opacity=\"0.25\"/>\n<rect x=\"116\" width=\"78\" height=\"8\" rx=\"2\" fill=\"#A1A8C2\" fill-opacity=\"0.25\"/>\n<rect y=\"20\" width=\"120\" height=\"8\" rx=\"2\" fill=\"#A1A8C2\" fill-opacity=\"0.5\"/>\n<rect x=\"128\" y=\"20\" width=\"30\" height=\"8\" rx=\"2\" fill=\"#A1A8C2\" fill-opacity=\"0.25\"/>\n<rect x=\"166\" y=\"20\" width=\"78\" height=\"8\" rx=\"2\" fill=\"#A1A8C2\" fill-opacity=\"0.25\"/>\n<rect y=\"60\" width=\"40\" height=\"8\" rx=\"2\" fill=\"#A1A8C2\" fill-opacity=\"0.5\"/>\n<rect x=\"20\" y=\"80\" width=\"40\" height=\"8\" rx=\"2\" fill=\"#A1A8C2\" fill-opacity=\"0.5\"/>\n<rect x=\"40\" y=\"100\" width=\"40\" height=\"8\" rx=\"2\" fill=\"#A1A8C2\" fill-opacity=\"0.5\"/>\n<rect x=\"88\" y=\"100\" width=\"110\" height=\"8\" rx=\"2\" fill=\"#A1A8C2\" fill-opacity=\"0.25\"/>\n<rect x=\"206\" y=\"100\" width=\"24\" height=\"8\" rx=\"2\" fill=\"#A1A8C2\" fill-opacity=\"0.25\"/>\n<rect x=\"238\" y=\"100\" width=\"40\" height=\"8\" rx=\"2\" fill=\"#A1A8C2\" fill-opacity=\"0.5\"/>\n<rect x=\"40\" y=\"120\" width=\"40\" height=\"8\" rx=\"2\" fill=\"#A1A8C2\" fill-opacity=\"0.5\"/>\n<rect x=\"88\" y=\"120\" width=\"50\" height=\"8\" rx=\"2\" fill=\"#A1A8C2\" fill-opacity=\"0.25\"/>\n<rect x=\"146\" y=\"120\" width=\"24\" height=\"8\" rx=\"2\" fill=\"#A1A8C2\" fill-opacity=\"0.25\"/>\n<rect x=\"178\" y=\"120\" width=\"90\" height=\"8\" rx=\"2\" fill=\"#A1A8C2\" fill-opacity=\"0.25\"/>\n<rect x=\"276\" y=\"120\" width=\"40\" height=\"8\" rx=\"2\" fill=\"#A1A8C2\" fill-opacity=\"0.5\"/>\n<rect x=\"20\" y=\"140\" width=\"40\" height=\"8\" rx=\"2\" fill=\"#A1A8C2\" fill-opacity=\"0.5\"/>\n<rect y=\"160\" width=\"40\" height=\"8\" rx=\"2\" fill=\"#A1A8C2\" fill-opacity=\"0.5\"/>\n</svg>\n</div>`\nconst SCRIPT_TAG = 'script'\n\nconst Embed = forwardRef(function Embed(\n { id, width, margin, html = defaultHtml }: Props,\n ref: Ref<HTMLDivElement | null>,\n) {\n const [container, setContainer] = useState<HTMLDivElement | null>(null)\n const [shouldRender, setShouldRender] = useState(false)\n\n useIsomorphicLayoutEffect(() => {\n setShouldRender(true)\n }, [])\n\n useImperativeHandle<HTMLDivElement | null, HTMLDivElement | null>(ref, () => container, [\n container,\n ])\n\n useEffect(() => {\n // TODO: When we SSR the editor, we can remove the editor check\n // and not run this effect on the first render.\n if (!container) return\n\n const walker = container.ownerDocument.createTreeWalker(container, NodeFilter.SHOW_ELEMENT, {\n acceptNode(node: Element) {\n return node.tagName.toLowerCase() === SCRIPT_TAG\n ? NodeFilter.FILTER_ACCEPT\n : NodeFilter.FILTER_REJECT\n },\n })\n\n const nodes: Element[] = []\n\n while (walker.nextNode()) nodes.push(walker.currentNode as Element)\n\n // By default scripts appended dynamically will execute asyncrhonously. Here we ensure that\n // scripts are loaded synchronously since that's what a user usually expects with scripts in\n // embedded in HTML which usually comes from the server.\n //\n // See: https://developer.mozilla.org/en-US/docs/Web/HTML/Element/script#notes\n async function executeScriptsInOrder() {\n for (let i = 0; i < nodes.length; i++) {\n await new Promise<void>(resolve => {\n const node = nodes[i]\n const script = node.ownerDocument.createElement(SCRIPT_TAG)\n\n script.textContent = node.textContent\n Array.from(node.attributes).forEach(({ name, value }) => {\n script.setAttribute(name, value)\n })\n\n script.onload = () => resolve()\n script.onerror = () => resolve()\n\n node.parentNode?.insertBefore(script, node)\n node.parentNode?.removeChild(node)\n\n if (!script.hasAttribute('src')) resolve()\n })\n }\n }\n\n executeScriptsInOrder().catch(error => {\n // Ignore errors from user-provided code\n console.error(error)\n })\n }, [container, html])\n\n const className = useStyle({ minHeight: 15 })\n\n if (shouldRender === false) return null\n\n return (\n <div\n ref={setContainer}\n id={id}\n className={cx(className, width, margin)}\n dangerouslySetInnerHTML={{ __html: html }}\n />\n )\n})\n\nexport default Embed\n"],"mappings":";AAgHI;AA5GJ,SAAS,UAAU,WAAW,YAAiB,2BAA2B;AAE1E,SAAS,iCAAiC;AAC1C,SAAS,gBAAgB;AACzB,SAAS,UAAU;AASnB,MAAM,cAAc;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAuBpB,MAAM,aAAa;AAEnB,MAAM,QAAQ,WAAW,SAASA,OAChC,EAAE,IAAI,OAAO,QAAQ,OAAO,YAAY,GACxC,KACA;AACA,QAAM,CAAC,WAAW,YAAY,IAAI,SAAgC,IAAI;AACtE,QAAM,CAAC,cAAc,eAAe,IAAI,SAAS,KAAK;AAEtD,4BAA0B,MAAM;AAC9B,oBAAgB,IAAI;AAAA,EACtB,GAAG,CAAC,CAAC;AAEL,sBAAkE,KAAK,MAAM,WAAW;AAAA,IACtF;AAAA,EACF,CAAC;AAED,YAAU,MAAM;AAGd,QAAI,CAAC;AAAW;AAEhB,UAAM,SAAS,UAAU,cAAc,iBAAiB,WAAW,WAAW,cAAc;AAAA,MAC1F,WAAW,MAAe;AACxB,eAAO,KAAK,QAAQ,YAAY,MAAM,aAClC,WAAW,gBACX,WAAW;AAAA,MACjB;AAAA,IACF,CAAC;AAED,UAAM,QAAmB,CAAC;AAE1B,WAAO,OAAO,SAAS;AAAG,YAAM,KAAK,OAAO,WAAsB;AAOlE,mBAAe,wBAAwB;AACrC,eAAS,IAAI,GAAG,IAAI,MAAM,QAAQ,KAAK;AACrC,cAAM,IAAI,QAAc,aAAW;AACjC,gBAAM,OAAO,MAAM,CAAC;AACpB,gBAAM,SAAS,KAAK,cAAc,cAAc,UAAU;AAE1D,iBAAO,cAAc,KAAK;AAC1B,gBAAM,KAAK,KAAK,UAAU,EAAE,QAAQ,CAAC,EAAE,MAAM,MAAM,MAAM;AACvD,mBAAO,aAAa,MAAM,KAAK;AAAA,UACjC,CAAC;AAED,iBAAO,SAAS,MAAM,QAAQ;AAC9B,iBAAO,UAAU,MAAM,QAAQ;AAE/B,eAAK,YAAY,aAAa,QAAQ,IAAI;AAC1C,eAAK,YAAY,YAAY,IAAI;AAEjC,cAAI,CAAC,OAAO,aAAa,KAAK;AAAG,oBAAQ;AAAA,QAC3C,CAAC;AAAA,MACH;AAAA,IACF;AAEA,0BAAsB,EAAE,MAAM,WAAS;AAErC,cAAQ,MAAM,KAAK;AAAA,IACrB,CAAC;AAAA,EACH,GAAG,CAAC,WAAW,IAAI,CAAC;AAEpB,QAAM,YAAY,SAAS,EAAE,WAAW,GAAG,CAAC;AAE5C,MAAI,iBAAiB;AAAO,WAAO;AAEnC,SACE;AAAA,IAAC;AAAA;AAAA,MACC,KAAK;AAAA,MACL;AAAA,MACA,WAAW,GAAG,WAAW,OAAO,MAAM;AAAA,MACtC,yBAAyB,EAAE,QAAQ,KAAK;AAAA;AAAA,EAC1C;AAEJ,CAAC;AAED,IAAO,gBAAQ;","names":["Embed"]}
1
+ {"version":3,"sources":["../../../../../src/components/builtin/Embed/Embed.tsx"],"sourcesContent":["'use client'\n\n/* eslint-env browser */\n\nimport { useState, useEffect, useMemo, forwardRef, Ref, useImperativeHandle } from 'react'\n\nimport { useIsomorphicLayoutEffect } from '../../hooks/useIsomorphicLayoutEffect'\nimport { useStyle } from '../../../runtimes/react/use-style'\nimport { cx } from '@emotion/css'\n\ntype Props = {\n id?: string\n html?: string\n width?: string\n margin?: string\n}\n\nconst defaultHtml = `<div style=\"padding: 24px; background-color: rgba(161, 168, 194, 0.18); overflow: hidden;\">\n<svg width=\"316\" height=\"168\" viewBox=\"0 0 316 168\" fill=\"none\" xmlns=\"http://www.w3.org/2000/svg\">\n<rect width=\"70\" height=\"8\" rx=\"2\" fill=\"#A1A8C2\" fill-opacity=\"0.5\"/>\n<rect x=\"78\" width=\"30\" height=\"8\" rx=\"2\" fill=\"#A1A8C2\" fill-opacity=\"0.25\"/>\n<rect x=\"116\" width=\"78\" height=\"8\" rx=\"2\" fill=\"#A1A8C2\" fill-opacity=\"0.25\"/>\n<rect y=\"20\" width=\"120\" height=\"8\" rx=\"2\" fill=\"#A1A8C2\" fill-opacity=\"0.5\"/>\n<rect x=\"128\" y=\"20\" width=\"30\" height=\"8\" rx=\"2\" fill=\"#A1A8C2\" fill-opacity=\"0.25\"/>\n<rect x=\"166\" y=\"20\" width=\"78\" height=\"8\" rx=\"2\" fill=\"#A1A8C2\" fill-opacity=\"0.25\"/>\n<rect y=\"60\" width=\"40\" height=\"8\" rx=\"2\" fill=\"#A1A8C2\" fill-opacity=\"0.5\"/>\n<rect x=\"20\" y=\"80\" width=\"40\" height=\"8\" rx=\"2\" fill=\"#A1A8C2\" fill-opacity=\"0.5\"/>\n<rect x=\"40\" y=\"100\" width=\"40\" height=\"8\" rx=\"2\" fill=\"#A1A8C2\" fill-opacity=\"0.5\"/>\n<rect x=\"88\" y=\"100\" width=\"110\" height=\"8\" rx=\"2\" fill=\"#A1A8C2\" fill-opacity=\"0.25\"/>\n<rect x=\"206\" y=\"100\" width=\"24\" height=\"8\" rx=\"2\" fill=\"#A1A8C2\" fill-opacity=\"0.25\"/>\n<rect x=\"238\" y=\"100\" width=\"40\" height=\"8\" rx=\"2\" fill=\"#A1A8C2\" fill-opacity=\"0.5\"/>\n<rect x=\"40\" y=\"120\" width=\"40\" height=\"8\" rx=\"2\" fill=\"#A1A8C2\" fill-opacity=\"0.5\"/>\n<rect x=\"88\" y=\"120\" width=\"50\" height=\"8\" rx=\"2\" fill=\"#A1A8C2\" fill-opacity=\"0.25\"/>\n<rect x=\"146\" y=\"120\" width=\"24\" height=\"8\" rx=\"2\" fill=\"#A1A8C2\" fill-opacity=\"0.25\"/>\n<rect x=\"178\" y=\"120\" width=\"90\" height=\"8\" rx=\"2\" fill=\"#A1A8C2\" fill-opacity=\"0.25\"/>\n<rect x=\"276\" y=\"120\" width=\"40\" height=\"8\" rx=\"2\" fill=\"#A1A8C2\" fill-opacity=\"0.5\"/>\n<rect x=\"20\" y=\"140\" width=\"40\" height=\"8\" rx=\"2\" fill=\"#A1A8C2\" fill-opacity=\"0.5\"/>\n<rect y=\"160\" width=\"40\" height=\"8\" rx=\"2\" fill=\"#A1A8C2\" fill-opacity=\"0.5\"/>\n</svg>\n</div>`\nconst SCRIPT_TAG = 'script'\n\nconst Embed = forwardRef(function Embed(\n { id, width, margin, html = defaultHtml }: Props,\n ref: Ref<HTMLDivElement | null>,\n) {\n const [container, setContainer] = useState<HTMLDivElement | null>(null)\n const [shouldRender, setShouldRender] = useState(false)\n\n useIsomorphicLayoutEffect(() => {\n setShouldRender(true)\n }, [])\n\n useImperativeHandle<HTMLDivElement | null, HTMLDivElement | null>(ref, () => container, [\n container,\n ])\n\n useEffect(() => {\n // TODO: When we SSR the editor, we can remove the editor check\n // and not run this effect on the first render.\n if (!container) return\n\n const walker = container.ownerDocument.createTreeWalker(container, NodeFilter.SHOW_ELEMENT, {\n acceptNode(node: Element) {\n return node.tagName.toLowerCase() === SCRIPT_TAG\n ? NodeFilter.FILTER_ACCEPT\n : NodeFilter.FILTER_REJECT\n },\n })\n\n const nodes: Element[] = []\n\n while (walker.nextNode()) nodes.push(walker.currentNode as Element)\n\n // By default scripts appended dynamically will execute asyncrhonously. Here we ensure that\n // scripts are loaded synchronously since that's what a user usually expects with scripts in\n // embedded in HTML which usually comes from the server.\n //\n // See: https://developer.mozilla.org/en-US/docs/Web/HTML/Element/script#notes\n async function executeScriptsInOrder() {\n for (let i = 0; i < nodes.length; i++) {\n await new Promise<void>(resolve => {\n const node = nodes[i]\n const script = node.ownerDocument.createElement(SCRIPT_TAG)\n\n script.textContent = node.textContent\n Array.from(node.attributes).forEach(({ name, value }) => {\n script.setAttribute(name, value)\n })\n\n script.onload = () => resolve()\n script.onerror = () => resolve()\n\n node.parentNode?.insertBefore(script, node)\n node.parentNode?.removeChild(node)\n\n if (!script.hasAttribute('src')) resolve()\n })\n }\n }\n\n executeScriptsInOrder().catch(error => {\n // Ignore errors from user-provided code\n console.error(error)\n })\n }, [container, html])\n\n const className = useStyle({ minHeight: 15 })\n\n // React 19+ resets `innerHTML` whenever the `dangerouslySetInnerHTML`\n // object's identity changes, even if `__html` is the same string. Memoize\n // the object so unrelated re-renders don't wipe out DOM produced by the\n // executed scripts above. See https://github.com/facebook/react/issues/31660\n // and https://github.com/react/react/issues/31600\n const dangerouslySetInnerHTML = useMemo(() => ({ __html: html }), [html])\n\n if (shouldRender === false) return null\n\n return (\n <div\n ref={setContainer}\n id={id}\n className={cx(className, width, margin)}\n dangerouslySetInnerHTML={dangerouslySetInnerHTML}\n />\n )\n})\n\nexport default Embed\n"],"mappings":";AAuHI;AAnHJ,SAAS,UAAU,WAAW,SAAS,YAAiB,2BAA2B;AAEnF,SAAS,iCAAiC;AAC1C,SAAS,gBAAgB;AACzB,SAAS,UAAU;AASnB,MAAM,cAAc;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAuBpB,MAAM,aAAa;AAEnB,MAAM,QAAQ,WAAW,SAASA,OAChC,EAAE,IAAI,OAAO,QAAQ,OAAO,YAAY,GACxC,KACA;AACA,QAAM,CAAC,WAAW,YAAY,IAAI,SAAgC,IAAI;AACtE,QAAM,CAAC,cA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,IAAI,CAAC,IAAI,CAAC;AAExE,MAAI,iBAAiB;AAAO,WAAO;AAEnC,SACE;AAAA,IAAC;AAAA;AAAA,MACC,KAAK;AAAA,MACL;AAAA,MACA,WAAW,GAAG,WAAW,OAAO,MAAM;AAAA,MACtC;AAAA;AAAA,EACF;AAEJ,CAAC;AAED,IAAO,gBAAQ;","names":["Embed"]}
@@ -1,6 +1,10 @@
1
1
  import { jsx, jsxs } from "react/jsx-runtime";
2
2
  import { createElement } from "react";
3
- import { forwardRef, useRef, useState } from "react";
3
+ import {
4
+ forwardRef,
5
+ useRef,
6
+ useState
7
+ } from "react";
4
8
  import { CaretDown8 } from "../../../../icons/CaretDown8";
5
9
  import { Plus8 } from "../../../../icons/Plus8";
6
10
  import { ArrowDown8 } from "../../../../icons/ArrowDown8";
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../../../../src/components/builtin/Navigation/components/DropDownButton/index.tsx"],"sourcesContent":["import { ComponentPropsWithoutRef, ForwardedRef, forwardRef, useRef, useState, ReactNode } from 'react'\n\nimport { CaretDown8 } from '../../../../icons/CaretDown8'\nimport { Plus8 } from '../../../../icons/Plus8'\nimport { ArrowDown8 } from '../../../../icons/ArrowDown8'\nimport { ChevronDown8 } from '../../../../icons/ChevronDown8'\nimport { colorToString } from '../../../../utils/colorToString'\nimport { useResponsiveColor } from '../../../../hooks'\n\nimport { Link } from '../../../../shared/Link'\nimport Button from '../../../Button'\nimport { useIsomorphicLayoutEffect } from '../../../../hooks/useIsomorphicLayoutEffect'\nimport { cx, keyframes } from '@emotion/css'\nimport { useStyle } from '../../../../../runtimes/react/use-style'\nimport { useResponsiveStyle, useResponsiveTextStyle } from '../../../../utils/responsive-style'\nimport { LinkData, ResponsiveColorData, ResponsiveTextStyleData } from '@makeswift/prop-controllers'\n\nconst DROP_DOWN_MENU_WIDTH = 200\n\ntype Position = 'left' | 'right'\n\nconst DROP_DOWN_MENU_CLASS_NAME = 'drop-down-menu'\n\ntype DropDownMenuBaseProps = {\n position: Position\n}\n\ntype DropDownMenuProps = DropDownMenuBaseProps &\n Omit<ComponentPropsWithoutRef<'div'>, keyof DropDownMenuBaseProps>\n\nfunction DropDownMenu({ className, position, ...restOfProps }: DropDownMenuProps) {\n return (\n <div\n {...restOfProps}\n className={cx(\n DROP_DOWN_MENU_CLASS_NAME,\n useStyle({\n position: 'absolute',\n top: '100%',\n left: position === 'left' ? 0 : 'auto',\n right: position === 'right' ? 0 : 'auto',\n background: '#fff',\n margin: 0,\n padding: '8px 0',\n borderRadius: 4,\n boxShadow: '0 3px 10px rgba(0, 0, 0, 0.15)',\n width: DROP_DOWN_MENU_WIDTH,\n zIndex: 99,\n listStyle: 'none',\n overflow: 'hidden',\n transformOrigin: '50% 0',\n willChange: 'transform, opacity',\n transformStyle: 'preserve-3d',\n display: 'none',\n }),\n className,\n )}\n />\n )\n}\n\nconst dropIn = keyframes`\n 0% {\n opacity: 0;\n transform: rotateX(-20deg);\n }\n 100% {\n opacity: 1;\n transform: none;\n }\n`\n\ntype DropDownContainerProps = ComponentPropsWithoutRef<'div'>\n\nconst DropDownContainer = forwardRef(function DropDownContainer(\n { className, ...restOfProps }: DropDownContainerProps,\n ref: ForwardedRef<HTMLDivElement>,\n) {\n return (\n <div\n {...restOfProps}\n ref={ref}\n className={cx(\n useStyle({\n position: 'relative',\n [`&:hover .${DROP_DOWN_MENU_CLASS_NAME}`]: {\n display: 'block',\n animation: `${dropIn} 0.25s`,\n },\n }),\n className,\n )}\n />\n )\n})\n\ntype BaseDropDownItemProps = {\n className?: string\n color?: ResponsiveColorData\n textStyle?: ResponsiveTextStyleData\n}\n\ntype DropDownItemProps = BaseDropDownItemProps &\n Omit<ComponentPropsWithoutRef<typeof Link>, keyof BaseDropDownItemProps>\n\nfunction DropDownItem({ className, color, textStyle, ...restOfProps }: DropDownItemProps) {\n const colorData = useResponsiveColor(color)\n\n return (\n <Link\n {...restOfProps}\n className={cx(\n useStyle({\n display: 'block',\n textDecoration: 'none',\n lineHeight: 1.4,\n padding: '8px 16px',\n color: 'black',\n backgroundColor: 'transparent',\n transition: 'background-color 0.2s',\n }),\n useStyle(useResponsiveTextStyle(textStyle)),\n useStyle(\n useResponsiveStyle([colorData, textStyle] as const, ([color, textStyle = {}]) => {\n const fontSize = textStyle.fontSize || { value: 14, unit: 'px' }\n const fontWeight = textStyle.fontWeight == null ? 'normal' : textStyle.fontWeight\n const fontStyle = textStyle.fontStyle || []\n const letterSpacing = textStyle.letterSpacing == null ? null : textStyle.letterSpacing\n const textTransform = textStyle.textTransform || []\n\n return {\n color: color == null ? 'black' : colorToString(color),\n fontSize: `${fontSize.value}${fontSize.unit}`,\n fontWeight,\n fontStyle: fontStyle.includes('italic') ? 'italic' : 'normal',\n letterSpacing: letterSpacing == null ? 'normal' : `${letterSpacing}px`,\n textTransform: textTransform.includes('uppercase') ? 'uppercase' : 'none',\n }\n }),\n ),\n useStyle({\n '&:hover': {\n backgroundColor: 'rgba(0, 0, 0, 0.04)',\n },\n }),\n className,\n )}\n />\n )\n}\n\ntype Props = Omit<ComponentPropsWithoutRef<typeof Button>, 'textColor' | 'color'> & {\n label: string\n caret?: 'caret' | 'plus' | 'arrow-down' | 'chevron-down'\n links?: Array<{\n id: string\n payload: ComponentPropsWithoutRef<typeof DropDownItem> & {\n link?: LinkData\n label: string\n }\n }>\n textColor?: ResponsiveColorData\n color?: ResponsiveColorData\n}\n\nexport default function DropDownButton({\n label,\n caret = 'caret',\n links = [],\n textColor,\n color,\n ...restOfProps\n}: Props): ReactNode {\n const container = useRef<HTMLDivElement>(null)\n const [position, setPosition] = useState<Position>('left')\n\n useIsomorphicLayoutEffect(() => {\n if (\n container.current &&\n container.current.ownerDocument.defaultView!.innerWidth <\n container.current.offsetLeft + DROP_DOWN_MENU_WIDTH\n ) {\n setPosition('right')\n } else {\n setPosition('left')\n }\n }, [setPosition])\n\n return (\n <DropDownContainer ref={container}>\n <Button\n {...restOfProps}\n textColor={useResponsiveColor(textColor)}\n color={useResponsiveColor(color)}\n >\n <div style={{ display: 'flex', alignItems: 'center' }}>\n <span style={{ marginRight: 6 }}>{label}</span>\n <span style={{ display: 'inline-flex', fill: 'currentColor' }}>\n {caret === 'caret' && <CaretDown8 />}\n {caret === 'plus' && <Plus8 />}\n {caret === 'arrow-down' && <ArrowDown8 />}\n {caret === 'chevron-down' && <ChevronDown8 />}\n </span>\n </div>\n </Button>\n <DropDownMenu position={position}>\n {links.map(({ id, payload }) => (\n <DropDownItem {...payload} key={id}>\n {payload.label}\n </DropDownItem>\n ))}\n </DropDownMenu>\n </DropDownContainer>\n )\n}\n"],"mappings":"AAgCI,cAqKM,YArKN;AA+KM;AA/MV,SAAiD,YAAY,QAAQ,gBAA2B;AAEhG,SAAS,kBAAkB;AAC3B,SAAS,aAAa;AACtB,SAAS,kBAAkB;AAC3B,SAAS,oBAAoB;AAC7B,SAAS,qBAAqB;AAC9B,SAAS,0BAA0B;AAEnC,SAAS,YAAY;AACrB,OAAO,YAAY;AACnB,SAAS,iCAAiC;AAC1C,SAAS,IAAI,iBAAiB;AAC9B,SAAS,gBAAgB;AACzB,SAAS,oBAAoB,8BAA8B;AAG3D,MAAM,uBAAuB;AAI7B,MAAM,4BAA4B;AASlC,SAAS,aAAa,EAAE,WAAW,UAAU,GAAG,YAAY,GAAsB;AAChF,SACE;AAAA,IAAC;AAAA;AAAA,MACE,GAAG;AAAA,MACJ,WAAW;AAAA,QACT;AAAA,QACA,SAAS;AAAA,UACP,UAAU;AAAA,UACV,KAAK;AAAA,UACL,MAAM,aAAa,SAAS,IAAI;AAAA,UAChC,OAAO,aAAa,UAAU,IAAI;AAAA,UAClC,YAAY;AAAA,UACZ,QAAQ;AAAA,UACR,SAAS;AAAA,UACT,cAAc;AAAA,UACd,WAAW;AAAA,UACX,OAAO;AAAA,UACP,QAAQ;AAAA,UACR,WAAW;AAAA,UACX,UAAU;AAAA,UACV,iBAAiB;AAAA,UACjB,YAAY;AAAA,UACZ,gBAAgB;AAAA,UAChB,SAAS;AAAA,QACX,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C3B,UAAU,gBAAgB,oBAAC,cAAW;AAAA,YACtC,UAAU,kBAAkB,oBAAC,gBAAa;AAAA,aAC7C;AAAA,WACF;AAAA;AAAA,IACF;AAAA,IACA,oBAAC,gBAAa,UACX,gBAAM,IAAI,CAAC,EAAE,IAAI,QAAQ,MACxB,8BAAC,gBAAc,GAAG,SAAS,KAAK,MAC7B,QAAQ,KACX,CACD,GACH;AAAA,KACF;AAEJ;","names":["DropDownContainer","color","textStyle"]}
1
+ {"version":3,"sources":["../../../../../../../src/components/builtin/Navigation/components/DropDownButton/index.tsx"],"sourcesContent":["import {\n ComponentPropsWithoutRef,\n ForwardedRef,\n forwardRef,\n useRef,\n useState,\n ReactNode,\n} from 'react'\n\nimport { CaretDown8 } from '../../../../icons/CaretDown8'\nimport { Plus8 } from '../../../../icons/Plus8'\nimport { ArrowDown8 } from '../../../../icons/ArrowDown8'\nimport { ChevronDown8 } from '../../../../icons/ChevronDown8'\nimport { colorToString } from '../../../../utils/colorToString'\nimport { useResponsiveColor } from '../../../../hooks'\n\nimport { Link } from '../../../../shared/Link'\nimport Button from '../../../Button'\nimport { useIsomorphicLayoutEffect } from '../../../../hooks/useIsomorphicLayoutEffect'\nimport { cx, keyframes } from '@emotion/css'\nimport { useStyle } from '../../../../../runtimes/react/use-style'\nimport { useResponsiveStyle, useResponsiveTextStyle } from '../../../../utils/responsive-style'\nimport { LinkData, ResponsiveColorData, ResponsiveTextStyleData } from '@makeswift/prop-controllers'\n\nconst DROP_DOWN_MENU_WIDTH = 200\n\ntype Position = 'left' | 'right'\n\nconst DROP_DOWN_MENU_CLASS_NAME = 'drop-down-menu'\n\ntype DropDownMenuBaseProps = {\n position: Position\n}\n\ntype DropDownMenuProps = DropDownMenuBaseProps &\n Omit<ComponentPropsWithoutRef<'div'>, keyof DropDownMenuBaseProps>\n\nfunction DropDownMenu({ className, position, ...restOfProps }: DropDownMenuProps) {\n return (\n <div\n {...restOfProps}\n className={cx(\n DROP_DOWN_MENU_CLASS_NAME,\n useStyle({\n position: 'absolute',\n top: '100%',\n left: position === 'left' ? 0 : 'auto',\n right: position === 'right' ? 0 : 'auto',\n background: '#fff',\n margin: 0,\n padding: '8px 0',\n borderRadius: 4,\n boxShadow: '0 3px 10px rgba(0, 0, 0, 0.15)',\n width: DROP_DOWN_MENU_WIDTH,\n zIndex: 99,\n listStyle: 'none',\n overflow: 'hidden',\n transformOrigin: '50% 0',\n willChange: 'transform, opacity',\n transformStyle: 'preserve-3d',\n display: 'none',\n }),\n className,\n )}\n />\n )\n}\n\nconst dropIn = keyframes`\n 0% {\n opacity: 0;\n transform: rotateX(-20deg);\n }\n 100% {\n opacity: 1;\n transform: none;\n }\n`\n\ntype DropDownContainerProps = ComponentPropsWithoutRef<'div'>\n\nconst DropDownContainer = forwardRef(function DropDownContainer(\n { className, ...restOfProps }: DropDownContainerProps,\n ref: ForwardedRef<HTMLDivElement>,\n) {\n return (\n <div\n {...restOfProps}\n ref={ref}\n className={cx(\n useStyle({\n position: 'relative',\n [`&:hover .${DROP_DOWN_MENU_CLASS_NAME}`]: {\n display: 'block',\n animation: `${dropIn} 0.25s`,\n },\n }),\n className,\n )}\n />\n )\n})\n\ntype BaseDropDownItemProps = {\n className?: string\n color?: ResponsiveColorData\n textStyle?: ResponsiveTextStyleData\n}\n\ntype DropDownItemProps = BaseDropDownItemProps &\n Omit<ComponentPropsWithoutRef<typeof Link>, keyof BaseDropDownItemProps>\n\nfunction DropDownItem({ className, color, textStyle, ...restOfProps }: DropDownItemProps) {\n const colorData = useResponsiveColor(color)\n\n return (\n <Link\n {...restOfProps}\n className={cx(\n useStyle({\n display: 'block',\n textDecoration: 'none',\n lineHeight: 1.4,\n padding: '8px 16px',\n color: 'black',\n backgroundColor: 'transparent',\n transition: 'background-color 0.2s',\n }),\n useStyle(useResponsiveTextStyle(textStyle)),\n useStyle(\n useResponsiveStyle([colorData, textStyle] as const, ([color, textStyle = {}]) => {\n const fontSize = textStyle.fontSize || { value: 14, unit: 'px' }\n const fontWeight = textStyle.fontWeight == null ? 'normal' : textStyle.fontWeight\n const fontStyle = textStyle.fontStyle || []\n const letterSpacing = textStyle.letterSpacing == null ? null : textStyle.letterSpacing\n const textTransform = textStyle.textTransform || []\n\n return {\n color: color == null ? 'black' : colorToString(color),\n fontSize: `${fontSize.value}${fontSize.unit}`,\n fontWeight,\n fontStyle: fontStyle.includes('italic') ? 'italic' : 'normal',\n letterSpacing: letterSpacing == null ? 'normal' : `${letterSpacing}px`,\n textTransform: textTransform.includes('uppercase') ? 'uppercase' : 'none',\n }\n }),\n ),\n useStyle({\n '&:hover': {\n backgroundColor: 'rgba(0, 0, 0, 0.04)',\n },\n }),\n className,\n )}\n />\n )\n}\n\ntype Props = Omit<ComponentPropsWithoutRef<typeof Button>, 'textColor' | 'color'> & {\n label: string\n caret?: 'caret' | 'plus' | 'arrow-down' | 'chevron-down'\n links?: Array<{\n id: string\n payload: ComponentPropsWithoutRef<typeof DropDownItem> & {\n link?: LinkData\n label: string\n }\n }>\n textColor?: ResponsiveColorData\n color?: ResponsiveColorData\n}\n\nexport default function DropDownButton({\n label,\n caret = 'caret',\n links = [],\n textColor,\n color,\n ...restOfProps\n}: Props): ReactNode {\n const container = useRef<HTMLDivElement>(null)\n const [position, setPosition] = useState<Position>('left')\n\n useIsomorphicLayoutEffect(() => {\n if (\n container.current &&\n container.current.ownerDocument.defaultView!.innerWidth <\n container.current.offsetLeft + DROP_DOWN_MENU_WIDTH\n ) {\n setPosition('right')\n } else {\n setPosition('left')\n }\n }, [setPosition])\n\n return (\n <DropDownContainer ref={container}>\n <Button\n {...restOfProps}\n textColor={useResponsiveColor(textColor)}\n color={useResponsiveColor(color)}\n >\n <div style={{ display: 'flex', alignItems: 'center' }}>\n <span style={{ marginRight: 6 }}>{label}</span>\n <span style={{ display: 'inline-flex', fill: 'currentColor' }}>\n {caret === 'caret' && <CaretDown8 />}\n {caret === 'plus' && <Plus8 />}\n {caret === 'arrow-down' && <ArrowDown8 />}\n {caret === 'chevron-down' && <ChevronDown8 />}\n </span>\n </div>\n </Button>\n <DropDownMenu position={position}>\n {links.map(({ id, payload }) => (\n <DropDownItem {...payload} key={id}>\n {payload.label}\n </DropDownItem>\n ))}\n </DropDownMenu>\n </DropDownContainer>\n )\n}\n"],"mappings":"AAuCI,cAqKM,YArKN;AA+KM;AAtNV;AAAA,EAGE;AAAA,EACA;AAAA,EACA;AAAA,OAEK;AAEP,SAAS,kBAAkB;AAC3B,SAAS,aAAa;AACtB,SAAS,kBAAkB;AAC3B,SAAS,oBAAoB;AAC7B,SAAS,qBAAqB;AAC9B,SAAS,0BAA0B;AAEnC,SAAS,YAAY;AACrB,OAAO,YAAY;AACnB,SAAS,iCAAiC;AAC1C,SAAS,IAAI,iBAAiB;AAC9B,SAAS,gBAAgB;AACzB,SAAS,oBAAoB,8BAA8B;AAG3D,MAAM,uBAAuB;AAI7B,MAAM,4BAA4B;AASlC,SAAS,aAAa,EAAE,WAAW,UAAU,GAAG,YAAY,GAAsB;AAChF,SACE;AAAA,IAAC;AAAA;AAAA,MACE,GAAG;AAAA,MACJ,WAAW;AAAA,QACT;AAAA,QACA,SAAS;AAAA,UACP,UAAU;AAAA,UACV,KAAK;AAAA,UACL,MAAM,aAAa,SAAS,IAAI;AAAA,UAChC,OAAO,aAAa,UAAU,IAAI;AAAA,UAClC,YAAY;AAAA,UACZ,QAAQ;AAAA,UACR,SAAS;AAAA,UACT,cAAc;AAAA,UACd,WAAW;AAAA,UACX,OAAO;AAAA,UACP,QAAQ;AAAA,UACR,WAAW;AAAA,UACX,UAAU;AAAA,UACV,iBAAiB;AAAA,UACjB,YAAY;AAAA,UACZ,gBAAgB;AAAA,UAChB,SAAS;AAAA,QACX,CAAC;AAAA,QACD;AAAA,MACF;AAAA;AAAA,EACF;AAEJ;AAEA,MAAM,SAAS;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAaf,MAAM,oBAAoB,WAAW,SAASA,mBAC5C,EAAE,WAAW,GAAG,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MACxB,8BAAC,gBAAc,GAAG,SAAS,KAAK,MAC7B,QAAQ,KACX,CACD,GACH;AAAA,KACF;AAEJ;","names":["DropDownContainer","color","textStyle"]}
@@ -1,6 +1,10 @@
1
1
  import { Fragment, jsx, jsxs } from "react/jsx-runtime";
2
2
  import { cx } from "@emotion/css";
3
- import { useState, useRef, forwardRef } from "react";
3
+ import {
4
+ useState,
5
+ useRef,
6
+ forwardRef
7
+ } from "react";
4
8
  import { ReactPlayer } from "../../../react-player";
5
9
  import { useStyle } from "../../../../../runtimes/react/use-style";
6
10
  import { useIsomorphicLayoutEffect } from "../../../../hooks/useIsomorphicLayoutEffect";
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../../../../src/components/shared/BackgroundsContainer/components/BackgroundVideo/index.tsx"],"sourcesContent":["import { cx } from '@emotion/css'\nimport { useState, useRef, ComponentPropsWithoutRef, ForwardedRef, forwardRef, ReactNode } from 'react'\n\nimport { ReactPlayer } from '../../../react-player'\nimport { useStyle } from '../../../../../runtimes/react/use-style'\n\nimport { useIsomorphicLayoutEffect } from '../../../../hooks/useIsomorphicLayoutEffect'\n\nconst Container = forwardRef(function Container(\n { className, ...restOfProps }: ComponentPropsWithoutRef<'div'>,\n ref: ForwardedRef<HTMLDivElement>,\n) {\n return (\n <div\n {...restOfProps}\n ref={ref}\n className={cx(\n useStyle({\n position: 'absolute',\n top: 0,\n left: 0,\n right: 0,\n bottom: 0,\n pointerEvents: 'none',\n overflow: 'hidden',\n }),\n className,\n )}\n />\n )\n})\n\nfunction Mask({\n backgroundColor,\n visible,\n}: {\n backgroundColor: string | undefined\n visible: boolean\n}) {\n return (\n <div\n className={useStyle({\n position: 'absolute',\n top: 0,\n left: 0,\n right: 0,\n bottom: 0,\n background: backgroundColor,\n opacity: visible ? 1 : 0,\n transition: 'opacity 1s',\n })}\n />\n )\n}\n\nconst getScale = (element: HTMLElement, aspectRatio: number, zoom: number) => {\n const { offsetWidth: width, offsetHeight: height } = element\n const computedAspectRatio = width / height\n\n return Math.max(aspectRatio / computedAspectRatio, computedAspectRatio / aspectRatio) * zoom\n}\n\ntype Props = {\n url?: string\n aspectRatio?: number\n zoom?: number\n opacity?: number\n maskColor?: string\n}\n\nexport default function BackgroundVideo({\n url = '',\n aspectRatio = 16 / 9,\n zoom = 1,\n maskColor,\n opacity,\n}: Props): ReactNode {\n const [ready, setReady] = useState(false)\n const [scale, setScale] = useState(1)\n const container = useRef<HTMLDivElement>(null)\n\n useIsomorphicLayoutEffect(() => {\n const { current: containerEl } = container\n\n if (!containerEl) return undefined\n\n const { defaultView } = containerEl.ownerDocument\n const handleResize = () => setScale(getScale(containerEl, aspectRatio, zoom))\n\n handleResize()\n\n defaultView!.addEventListener('resize', handleResize)\n\n return () => defaultView!.removeEventListener('resize', handleResize)\n }, [aspectRatio, zoom])\n\n if (!ReactPlayer.canPlay(url)) return <></>\n\n return (\n <Container ref={container}>\n {container.current && (\n <ReactPlayer\n url={url}\n config={{\n vimeo: { playerOptions: { background: true } },\n youtube: {\n playerVars: {\n origin: container.current.ownerDocument.defaultView?.location.origin,\n },\n },\n wistia: {\n options: {\n endVideoBehavior: 'loop',\n playbackRateControl: false,\n playbar: false,\n playButton: false,\n volumeControl: false,\n fullscreenButton: false,\n muted: true,\n },\n },\n }}\n playing\n loop\n muted\n playsinline={true}\n controls={false}\n onReady={() => setReady(true)}\n style={{\n transform: `scale3d(${scale}, ${scale}, 1)`,\n opacity,\n }}\n width=\"100%\"\n height=\"100%\"\n />\n )}\n <Mask backgroundColor={maskColor} visible={!ready} />\n </Container>\n )\n}\n"],"mappings":"AAaI,SAmFoC,UAnFpC,KAsFA,YAtFA;AAbJ,SAAS,UAAU;AACnB,SAAS,UAAU,QAAgD,kBAA6B;AAEhG,SAAS,mBAAmB;AAC5B,SAAS,gBAAgB;AAEzB,SAAS,iCAAiC;AAE1C,MAAM,YAAY,WAAW,SAASA,WACpC,EAAE,WAAW,GAAG,YAAY,GAC5B,KACA;AACA,SACE;AAAA,IAAC;A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MAAM,YAAa,oBAAoB,UAAU,YAAY;AAAA,EACtE,GAAG,CAAC,aAAa,IAAI,CAAC;AAEtB,MAAI,CAAC,YAAY,QAAQ,GAAG;AAAG,WAAO,gCAAE;AAExC,SACE,qBAAC,aAAU,KAAK,WACb;AAAA,cAAU,WACT;AAAA,MAAC;AAAA;AAAA,QACC;AAAA,QACA,QAAQ;AAAA,UACN,OAAO,EAAE,eAAe,EAAE,YAAY,KAAK,EAAE;AAAA,UAC7C,SAAS;AAAA,YACP,YAAY;AAAA,cACV,QAAQ,UAAU,QAAQ,cAAc,aAAa,SAAS;AAAA,YAChE;AAAA,UACF;AAAA,UACA,QAAQ;AAAA,YACN,SAAS;AAAA,cACP,kBAAkB;AAAA,cAClB,qBAAqB;AAAA,cACrB,SAAS;AAAA,cACT,YAAY;AAAA,cACZ,eAAe;AAAA,cACf,kBAAkB;AAAA,cAClB,OAAO;AAAA,YACT;AAAA,UACF;AAAA,QACF;AAAA,QACA,SAAO;AAAA,QACP,MAAI;AAAA,QACJ,OAAK;AAAA,QACL,aAAa;AAAA,QACb,UAAU;AAAA,QACV,SAAS,MAAM,SAAS,IAAI;AAAA,QAC5B,OAAO;AAAA,UACL,WAAW,WAAW,KAAK,KAAK,KAAK;AAAA,UACrC;AAAA,QACF;AAAA,QACA,OAAM;AAAA,QACN,QAAO;AAAA;AAAA,IACT;AAAA,IAEF,oBAAC,QAAK,iBAAiB,WAAW,SAAS,CAAC,OAAO;AAAA,KACrD;AAEJ;","names":["Container"]}
1
+ {"version":3,"sources":["../../../../../../../src/components/shared/BackgroundsContainer/components/BackgroundVideo/index.tsx"],"sourcesContent":["import { cx } from '@emotion/css'\nimport {\n useState,\n useRef,\n ComponentPropsWithoutRef,\n ForwardedRef,\n forwardRef,\n ReactNode,\n} from 'react'\n\nimport { ReactPlayer } from '../../../react-player'\nimport { useStyle } from '../../../../../runtimes/react/use-style'\n\nimport { useIsomorphicLayoutEffect } from '../../../../hooks/useIsomorphicLayoutEffect'\n\nconst Container = forwardRef(function Container(\n { className, ...restOfProps }: ComponentPropsWithoutRef<'div'>,\n ref: ForwardedRef<HTMLDivElement>,\n) {\n return (\n <div\n {...restOfProps}\n ref={ref}\n className={cx(\n useStyle({\n position: 'absolute',\n top: 0,\n left: 0,\n right: 0,\n bottom: 0,\n pointerEvents: 'none',\n overflow: 'hidden',\n }),\n className,\n )}\n />\n )\n})\n\nfunction Mask({\n backgroundColor,\n visible,\n}: {\n backgroundColor: string | undefined\n visible: boolean\n}) {\n return (\n <div\n className={useStyle({\n position: 'absolute',\n top: 0,\n left: 0,\n right: 0,\n bottom: 0,\n background: backgroundColor,\n opacity: visible ? 1 : 0,\n transition: 'opacity 1s',\n })}\n />\n )\n}\n\nconst getScale = (element: HTMLElement, aspectRatio: number, zoom: number) => {\n const { offsetWidth: width, offsetHeight: height } = element\n const computedAspectRatio = width / height\n\n return Math.max(aspectRatio / computedAspectRatio, computedAspectRatio / aspectRatio) * zoom\n}\n\ntype Props = {\n url?: string\n aspectRatio?: number\n zoom?: number\n opacity?: number\n maskColor?: string\n}\n\nexport default function BackgroundVideo({\n url = '',\n aspectRatio = 16 / 9,\n zoom = 1,\n maskColor,\n opacity,\n}: Props): ReactNode {\n const [ready, setReady] = useState(false)\n const [scale, setScale] = useState(1)\n const container = useRef<HTMLDivElement>(null)\n\n useIsomorphicLayoutEffect(() => {\n const { current: containerEl } = container\n\n if (!containerEl) return undefined\n\n const { defaultView } = containerEl.ownerDocument\n const handleResize = () => setScale(getScale(containerEl, aspectRatio, zoom))\n\n handleResize()\n\n defaultView!.addEventListener('resize', handleResize)\n\n return () => defaultView!.removeEventListener('resize', handleResize)\n }, [aspectRatio, zoom])\n\n if (!ReactPlayer.canPlay(url)) return <></>\n\n return (\n <Container ref={container}>\n {container.current && (\n <ReactPlayer\n url={url}\n config={{\n vimeo: { playerOptions: { background: true } },\n youtube: {\n playerVars: {\n origin: container.current.ownerDocument.defaultView?.location.origin,\n },\n },\n wistia: {\n options: {\n endVideoBehavior: 'loop',\n playbackRateControl: false,\n playbar: false,\n playButton: false,\n volumeControl: false,\n fullscreenButton: false,\n muted: true,\n },\n },\n }}\n playing\n loop\n muted\n playsinline={true}\n controls={false}\n onReady={() => setReady(true)}\n style={{\n transform: `scale3d(${scale}, ${scale}, 1)`,\n opacity,\n }}\n width=\"100%\"\n height=\"100%\"\n />\n )}\n <Mask backgroundColor={maskColor} visible={!ready} />\n </Container>\n )\n}\n"],"mappings":"AAoBI,SAmFoC,UAnFpC,KAsFA,YAtFA;AApBJ,SAAS,UAAU;AACnB;AAAA,EACE;AAAA,EACA;AAAA,EAGA;AAAA,OAEK;AAEP,SAAS,mBAAmB;AAC5B,SAAS,gBAAgB;AAEzB,SAAS,iCAAiC;AAE1C,MAAM,YAAY,WAAW,SAASA,WACpC,EAAE,WAAW,GAAG,YAAY,GAC5B,KACA;AACA,SACE;AAAA,IAAC;AAAA;AAAA,MACE,GAAG;AAAA,MACJ;AAAA,MACA,WAAW;AAAA,QACT,SAAS;AAAA,UACP,UAAU;AAAA,UACV,KAAK;AAAA,UACL,MAAM;AAAA,UACN,OAAO;AAAA,UACP,QAAQ;AAAA,UACR,eAAe;AAAA,UACf,UAAU;AAAA,QACZ,CAAC;AAAA,QACD;AAAA,MACF;AAAA;AAAA,EACF;AAEJ,CAAC;AAED,SAAS,KAAK;AAAA,EACZ;AAAA,EACA;AACF,GAGG;AACD,SACE;AAAA,IAAC;AAAA;AAAA,MACC,WAAW,SAAS;AAAA,QAClB,UAAU;AAAA,QACV,KAAK;AAAA,QACL,MAAM;AAAA,QACN,OAAO;AAAA,QACP,QAAQ;AAAA,QACR,YAAY;AAAA,QACZ,SAAS,UAAU,IAAI;AAAA,QACvB,YAAY;AAAA,MACd,CAAC;AAAA;AAAA,EACH;AAEJ;AAEA,MAAM,WAAW,CAAC,SAAsB,aAAqB,SAAiB;AAC5E,QAAM,EAAE,aAAa,OAAO,cAAc,OAAO,IAAI;AACrD,QAAM,sBAAsB,QAAQ;AAEpC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