@makeswift/runtime 0.9.3 → 0.9.4

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 (115) hide show
  1. package/dist/Box.cjs.js +1 -1
  2. package/dist/Box.es.js +2 -2
  3. package/dist/Button.cjs.js +1 -1
  4. package/dist/Button.es.js +2 -2
  5. package/dist/Carousel.cjs.js +1 -1
  6. package/dist/Carousel.es.js +2 -2
  7. package/dist/Countdown.cjs.js +1 -1
  8. package/dist/Countdown.es.js +2 -2
  9. package/dist/Divider.cjs.js +1 -1
  10. package/dist/Divider.es.js +2 -2
  11. package/dist/Embed.es.js +1 -1
  12. package/dist/Form.cjs.js +1 -1
  13. package/dist/Form.es.js +2 -2
  14. package/dist/Image.cjs.js +1 -1
  15. package/dist/Image.es.js +2 -2
  16. package/dist/LiveProvider.cjs.js +1 -1
  17. package/dist/LiveProvider.es.js +1 -1
  18. package/dist/Navigation.cjs.js +1 -1
  19. package/dist/Navigation.es.js +2 -2
  20. package/dist/PreviewProvider.cjs.js +1 -1
  21. package/dist/PreviewProvider.es.js +2 -2
  22. package/dist/ReadOnlyText.cjs.js +3 -4
  23. package/dist/ReadOnlyText.cjs.js.map +1 -1
  24. package/dist/ReadOnlyText.es.js +3 -4
  25. package/dist/ReadOnlyText.es.js.map +1 -1
  26. package/dist/ReadOnlyTextV2.cjs.js +10 -11
  27. package/dist/ReadOnlyTextV2.cjs.js.map +1 -1
  28. package/dist/ReadOnlyTextV2.es.js +9 -10
  29. package/dist/ReadOnlyTextV2.es.js.map +1 -1
  30. package/dist/Root.cjs.js +1 -1
  31. package/dist/Root.es.js +2 -2
  32. package/dist/SocialLinks.cjs.js +1 -1
  33. package/dist/SocialLinks.es.js +2 -2
  34. package/dist/Text.cjs.js +1 -1
  35. package/dist/Text.es.js +1 -1
  36. package/dist/Video.es.js +1 -1
  37. package/dist/components.cjs.js +1 -1
  38. package/dist/components.es.js +1 -1
  39. package/dist/control-serialization.es.js +1 -1
  40. package/dist/controls.cjs.js +18 -14
  41. package/dist/controls.cjs.js.map +1 -1
  42. package/dist/controls.es.js +2 -2
  43. package/dist/index.cjs.js +161 -49
  44. package/dist/index.cjs.js.map +1 -1
  45. package/dist/index.cjs10.js +22 -10
  46. package/dist/index.cjs10.js.map +1 -1
  47. package/dist/index.cjs5.js +99 -5
  48. package/dist/index.cjs5.js.map +1 -1
  49. package/dist/index.cjs8.js +1 -1
  50. package/dist/index.cjs9.js +1 -1
  51. package/dist/index.es.js +148 -37
  52. package/dist/index.es.js.map +1 -1
  53. package/dist/index.es10.js +23 -11
  54. package/dist/index.es10.js.map +1 -1
  55. package/dist/index.es2.js +1 -1
  56. package/dist/index.es4.js +1 -1
  57. package/dist/index.es5.js +91 -2
  58. package/dist/index.es5.js.map +1 -1
  59. package/dist/index.es6.js +1 -1
  60. package/dist/index.es8.js +1 -1
  61. package/dist/index.es9.js +2 -2
  62. package/dist/next.cjs.js +1 -1
  63. package/dist/next.es.js +2 -2
  64. package/dist/react-page.cjs.js +97 -8
  65. package/dist/react-page.cjs.js.map +1 -1
  66. package/dist/react-page.es.js +95 -8
  67. package/dist/react-page.es.js.map +1 -1
  68. package/dist/react.cjs.js +1 -1
  69. package/dist/react.es.js +1 -1
  70. package/dist/slate.cjs.js +17 -70
  71. package/dist/slate.cjs.js.map +1 -1
  72. package/dist/slate.es.js +20 -74
  73. package/dist/slate.es.js.map +1 -1
  74. package/dist/types/src/components/builtin/Button/Button.d.ts +1 -1
  75. package/dist/types/src/components/builtin/Form/components/Field/components/Checkbox/index.d.ts +1 -1
  76. package/dist/types/src/components/builtin/Text/ReadOnlyText.d.ts.map +1 -1
  77. package/dist/types/src/components/builtin/Text/components/Leaf/leaf.d.ts +0 -17
  78. package/dist/types/src/components/builtin/Text/components/Leaf/leaf.d.ts.map +1 -1
  79. package/dist/types/src/controls/control.d.ts +3 -2
  80. package/dist/types/src/controls/control.d.ts.map +1 -1
  81. package/dist/types/src/controls/index.d.ts +1 -0
  82. package/dist/types/src/controls/index.d.ts.map +1 -1
  83. package/dist/types/src/controls/list.d.ts +2 -0
  84. package/dist/types/src/controls/list.d.ts.map +1 -1
  85. package/dist/types/src/controls/shape.d.ts +2 -0
  86. package/dist/types/src/controls/shape.d.ts.map +1 -1
  87. package/dist/types/src/controls/typography.d.ts +31 -0
  88. package/dist/types/src/controls/typography.d.ts.map +1 -0
  89. package/dist/types/src/next/client.d.ts.map +1 -1
  90. package/dist/types/src/prop-controllers/descriptors.d.ts +6 -3
  91. package/dist/types/src/prop-controllers/descriptors.d.ts.map +1 -1
  92. package/dist/types/src/prop-controllers/introspection.d.ts +1 -1
  93. package/dist/types/src/prop-controllers/introspection.d.ts.map +1 -1
  94. package/dist/types/src/runtimes/react/controls/control.d.ts +3 -2
  95. package/dist/types/src/runtimes/react/controls/control.d.ts.map +1 -1
  96. package/dist/types/src/runtimes/react/controls/rich-text-v2/ReadOnlyTextV2.d.ts.map +1 -1
  97. package/dist/types/src/runtimes/react/controls/typography.d.ts +21 -0
  98. package/dist/types/src/runtimes/react/controls/typography.d.ts.map +1 -0
  99. package/dist/types/src/runtimes/react/controls.d.ts.map +1 -1
  100. package/dist/types/src/slate/TypographyPlugin/index.d.ts +9 -0
  101. package/dist/types/src/slate/TypographyPlugin/index.d.ts.map +1 -1
  102. package/dist/types.cjs2.js +5 -5
  103. package/dist/types.cjs2.js.map +1 -1
  104. package/dist/types.es2.js +2 -2
  105. package/dist/{text-input.cjs.js → typography.cjs.js} +9 -1
  106. package/dist/typography.cjs.js.map +1 -0
  107. package/dist/{text-input.es.js → typography.es.js} +8 -2
  108. package/dist/typography.es.js.map +1 -0
  109. package/package.json +1 -1
  110. package/dist/leaf.cjs.js +0 -182
  111. package/dist/leaf.cjs.js.map +0 -1
  112. package/dist/leaf.es.js +0 -179
  113. package/dist/leaf.es.js.map +0 -1
  114. package/dist/text-input.cjs.js.map +0 -1
  115. package/dist/text-input.es.js.map +0 -1
package/dist/index.cjs.js CHANGED
@@ -41,7 +41,7 @@ var dynamic = require("next/dynamic");
41
41
  var reactPage = require("./react-page.cjs.js");
42
42
  var actions = require("./actions.cjs.js");
43
43
  var jsxRuntime = require("react/jsx-runtime");
44
- var textInput = require("./text-input.cjs.js");
44
+ var typography = require("./typography.cjs.js");
45
45
  var combobox = require("./combobox.cjs.js");
46
46
  require("slate");
47
47
  var shim = require("use-sync-external-store/shim");
@@ -959,7 +959,7 @@ Received "${apiKey}" instead.`);
959
959
  while (current = remaining.pop()) {
960
960
  let getResourcesFromElementDescriptors = function(elementDescriptors2, props) {
961
961
  Object.entries(elementDescriptors2).forEach(([propName, descriptor]) => {
962
- reactPage.getElementSwatchIds(descriptor, props[propName]).forEach((swatchId) => {
962
+ reactPage.getSwatchIds(descriptor, props[propName]).forEach((swatchId) => {
963
963
  swatchIds.add(swatchId);
964
964
  });
965
965
  reactPage.getFileIds(descriptor, props[propName]).forEach((fileId) => fileIds.add(fileId));
@@ -972,34 +972,6 @@ Received "${apiKey}" instead.`);
972
972
  remaining.push(child);
973
973
  }
974
974
  });
975
- if (descriptor.type === reactPage.ShapeControlType) {
976
- const prop = props[propName];
977
- if (prop == null)
978
- return;
979
- getResourcesFromElementDescriptors(descriptor.config.type, prop);
980
- }
981
- if (descriptor.type === reactPage.ListControlType) {
982
- const prop = props[propName];
983
- if (prop == null)
984
- return;
985
- prop.forEach((item) => {
986
- getResourcesFromElementDescriptors({ propName: descriptor.config.type }, { propName: item.value });
987
- });
988
- }
989
- if (descriptor.type === reactPage.Types.Shape) {
990
- const prop = props[propName];
991
- if (prop == null)
992
- return;
993
- getResourcesFromElementDescriptors(descriptor.options.type, prop);
994
- }
995
- if (descriptor.type === reactPage.Types.List) {
996
- const prop = props[propName];
997
- if (prop == null)
998
- return;
999
- prop.forEach((item) => {
1000
- getResourcesFromElementDescriptors({ propName: descriptor.options.type }, { propName: item.value });
1001
- });
1002
- }
1003
975
  });
1004
976
  };
1005
977
  let element2;
@@ -1019,8 +991,8 @@ Received "${apiKey}" instead.`);
1019
991
  getResourcesFromElementDescriptors(elementDescriptors, element2.props);
1020
992
  }
1021
993
  const typographies = await this.getTypographies([...typographyIds]);
1022
- typographies.forEach((typography) => {
1023
- typography == null ? void 0 : typography.style.forEach((style) => {
994
+ typographies.forEach((typography2) => {
995
+ typography2 == null ? void 0 : typography2.style.forEach((style) => {
1024
996
  var _a;
1025
997
  const swatchId = (_a = style.value.color) == null ? void 0 : _a.swatchId;
1026
998
  if (swatchId != null)
@@ -1055,7 +1027,7 @@ Received "${apiKey}" instead.`);
1055
1027
  var _a;
1056
1028
  return {
1057
1029
  id,
1058
- value: (_a = typographies.find((typography) => (typography == null ? void 0 : typography.id) === id)) != null ? _a : null
1030
+ value: (_a = typographies.find((typography2) => (typography2 == null ? void 0 : typography2.id) === id)) != null ? _a : null
1059
1031
  };
1060
1032
  }),
1061
1033
  [types.APIResourceType.Table]: [...tableIds].map((id) => {
@@ -1182,7 +1154,7 @@ async function fonts(_req, res, { getFonts } = {}) {
1182
1154
  const fonts2 = (_a = await (getFonts == null ? void 0 : getFonts())) != null ? _a : [];
1183
1155
  return res.json(fonts2);
1184
1156
  }
1185
- const version = "0.9.3";
1157
+ const version = "0.9.4";
1186
1158
  async function handler(req, res, { apiKey, unstable_siteVersions }) {
1187
1159
  if (req.query.secret !== apiKey) {
1188
1160
  return res.status(401).json({ message: "Unauthorized" });
@@ -2586,12 +2558,12 @@ function useFiles(fileIds) {
2586
2558
  function useTypography(typographyId) {
2587
2559
  const client = useMakeswiftClient();
2588
2560
  const readTypography = () => typographyId == null ? null : client.readTypography(typographyId);
2589
- const typography = shim.useSyncExternalStore(client.subscribe, readTypography, readTypography);
2561
+ const typography2 = shim.useSyncExternalStore(client.subscribe, readTypography, readTypography);
2590
2562
  React.useEffect(() => {
2591
2563
  if (typographyId != null)
2592
2564
  client.fetchTypography(typographyId).catch(console.error);
2593
2565
  }, [client, typographyId]);
2594
- return typography;
2566
+ return typography2;
2595
2567
  }
2596
2568
  function useGlobalElement(globalElementId) {
2597
2569
  const client = useMakeswiftClient();
@@ -3412,6 +3384,138 @@ function useTextAreaValue(data, definition) {
3412
3384
  function useTextInputValue(data, definition) {
3413
3385
  return data != null ? data : definition.config.defaultValue;
3414
3386
  }
3387
+ function isNonNullable(value) {
3388
+ return value != null;
3389
+ }
3390
+ function typographyFragementToTypographyControlData(typography2) {
3391
+ if (typography2 == null)
3392
+ return void 0;
3393
+ return {
3394
+ id: typography2.id,
3395
+ style: typography2.style.map(({ deviceId, value }) => {
3396
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k;
3397
+ return {
3398
+ deviceId,
3399
+ value: {
3400
+ fontFamily: (_a = value.fontFamily) != null ? _a : void 0,
3401
+ lineHeight: (_b = value.lineHeight) != null ? _b : void 0,
3402
+ letterSpacing: (_c = value.letterSpacing) != null ? _c : void 0,
3403
+ fontWeight: (_d = value.fontWeight) != null ? _d : void 0,
3404
+ textAlign: (_e = value.textAlign) != null ? _e : void 0,
3405
+ uppercase: (_f = value.uppercase) != null ? _f : void 0,
3406
+ underline: (_g = value.underline) != null ? _g : void 0,
3407
+ strikethrough: (_h = value.strikethrough) != null ? _h : void 0,
3408
+ italic: (_i = value.italic) != null ? _i : void 0,
3409
+ fontSize: (_j = value.fontSize) != null ? _j : void 0,
3410
+ color: (_k = value.color) != null ? _k : void 0
3411
+ }
3412
+ };
3413
+ })
3414
+ };
3415
+ }
3416
+ function getTypographyStyleSwatchIds(style) {
3417
+ var _a;
3418
+ return (_a = style == null ? void 0 : style.map((override) => override.value).flatMap((typographyStyle) => {
3419
+ var _a2;
3420
+ return (_a2 = typographyStyle.color) == null ? void 0 : _a2.swatchId;
3421
+ }).filter(isNonNullable)) != null ? _a : [];
3422
+ }
3423
+ const withColor = (swatches) => (deviceRawTypographyValue) => {
3424
+ var _b, _c;
3425
+ const { value, deviceId } = deviceRawTypographyValue;
3426
+ if (value.color == null) {
3427
+ const _a = value, { color } = _a, nextValue = __objRest(_a, ["color"]);
3428
+ return {
3429
+ deviceId,
3430
+ value: nextValue
3431
+ };
3432
+ }
3433
+ return {
3434
+ deviceId,
3435
+ value: __spreadProps(__spreadValues({}, value), {
3436
+ color: {
3437
+ swatch: swatches.find((s) => {
3438
+ var _a2;
3439
+ return s && s.id === ((_a2 = value.color) == null ? void 0 : _a2.swatchId);
3440
+ }),
3441
+ alpha: (_c = (_b = value.color) == null ? void 0 : _b.alpha) != null ? _c : void 0
3442
+ }
3443
+ })
3444
+ };
3445
+ };
3446
+ const getDeviceId = ({ deviceId }) => deviceId;
3447
+ function useEnhancedTypography(value) {
3448
+ var _a, _b, _c;
3449
+ const typography2 = typographyFragementToTypographyControlData(useTypography((_a = value == null ? void 0 : value.id) != null ? _a : null));
3450
+ const source = (_b = typography2 == null ? void 0 : typography2.style) != null ? _b : [];
3451
+ const override = (_c = value == null ? void 0 : value.style) != null ? _c : [];
3452
+ const breakpoints = useBreakpoints();
3453
+ const swatchIds = [
3454
+ ...getTypographyStyleSwatchIds(value == null ? void 0 : value.style),
3455
+ ...getTypographyStyleSwatchIds(typography2 == null ? void 0 : typography2.style)
3456
+ ];
3457
+ const swatches = useSwatches(swatchIds).filter(isNonNullable);
3458
+ const enhancedSource = source.map(withColor(swatches));
3459
+ const enhancedOverride = override.map(withColor(swatches));
3460
+ const devices = [
3461
+ ...new Set(enhancedSource.map(getDeviceId).concat(enhancedOverride.map(getDeviceId)))
3462
+ ];
3463
+ return devices.map((deviceId) => {
3464
+ var _a2, _b2;
3465
+ const deviceSource = (_a2 = state_breakpoints.findBreakpointOverride(breakpoints, enhancedSource, deviceId)) == null ? void 0 : _a2.value;
3466
+ const deviceOverride = (_b2 = state_breakpoints.findBreakpointOverride(breakpoints, enhancedOverride, deviceId, (v) => v)) == null ? void 0 : _b2.value;
3467
+ if (deviceSource && deviceOverride) {
3468
+ return {
3469
+ deviceId,
3470
+ value: __spreadValues(__spreadValues({}, deviceSource), deviceOverride)
3471
+ };
3472
+ } else if (deviceOverride) {
3473
+ return {
3474
+ deviceId,
3475
+ value: deviceOverride
3476
+ };
3477
+ } else if (deviceSource) {
3478
+ return {
3479
+ deviceId,
3480
+ value: deviceSource
3481
+ };
3482
+ }
3483
+ return null;
3484
+ }).filter(isNonNullable);
3485
+ }
3486
+ function useTypographyClassName(value) {
3487
+ return reactPage.useStyle(useResponsiveStyle([value], ([value2]) => {
3488
+ if (value2 === void 0)
3489
+ return {};
3490
+ let styles = {};
3491
+ if (value2.color != null)
3492
+ styles.color = colorToString(value2.color);
3493
+ if (value2.fontFamily != null)
3494
+ styles.fontFamily = value2.fontFamily;
3495
+ if (value2.fontSize != null && value2.fontSize.value != null && value2.fontSize.unit != null)
3496
+ styles.fontSize = `${value2.fontSize.value}${value2.fontSize.unit}`;
3497
+ if (value2.fontWeight != null)
3498
+ styles.fontWeight = value2.fontWeight;
3499
+ if (value2.lineHeight != null)
3500
+ styles.lineHeight = value2.lineHeight;
3501
+ if (value2.letterSpacing != null)
3502
+ styles.letterSpacing = `${value2.letterSpacing / 10}em`;
3503
+ if (value2.uppercase != null)
3504
+ styles.textTransform = value2.uppercase === true ? "uppercase" : "initial";
3505
+ if (value2.underline != null || value2.strikethrough != null)
3506
+ styles.textDecoration = [
3507
+ Boolean(value2.underline) && "underline",
3508
+ Boolean(value2.strikethrough) && "line-through"
3509
+ ].filter(Boolean).join(" ");
3510
+ if (value2.italic != null)
3511
+ styles.fontStyle = value2.italic === true ? "italic" : "initial";
3512
+ return styles;
3513
+ }, state_breakpoints.shallowMergeFallbacks));
3514
+ }
3515
+ function useTypographyValue(data) {
3516
+ const enhancedTypography = useEnhancedTypography(data);
3517
+ return useTypographyClassName(enhancedTypography);
3518
+ }
3415
3519
  function ControlValue({
3416
3520
  data,
3417
3521
  definition,
@@ -3419,31 +3523,31 @@ function ControlValue({
3419
3523
  control
3420
3524
  }) {
3421
3525
  switch (definition.type) {
3422
- case textInput.CheckboxControlType:
3526
+ case typography.CheckboxControlType:
3423
3527
  return /* @__PURE__ */ jsxRuntime.jsx(RenderHook, {
3424
3528
  hook: useCheckboxControlValue,
3425
3529
  parameters: [data, definition],
3426
3530
  children: (value) => children(value)
3427
3531
  }, definition.type);
3428
- case textInput.NumberControlType:
3532
+ case typography.NumberControlType:
3429
3533
  return /* @__PURE__ */ jsxRuntime.jsx(RenderHook, {
3430
3534
  hook: useNumber,
3431
3535
  parameters: [data, definition],
3432
3536
  children: (value) => children(value)
3433
3537
  }, definition.type);
3434
- case textInput.TextInputControlType:
3538
+ case typography.TextInputControlType:
3435
3539
  return /* @__PURE__ */ jsxRuntime.jsx(RenderHook, {
3436
3540
  hook: useTextInputValue,
3437
3541
  parameters: [data, definition],
3438
3542
  children: (value) => children(value)
3439
3543
  }, definition.type);
3440
- case textInput.TextAreaControlType:
3544
+ case typography.TextAreaControlType:
3441
3545
  return /* @__PURE__ */ jsxRuntime.jsx(RenderHook, {
3442
3546
  hook: useTextAreaValue,
3443
3547
  parameters: [data, definition],
3444
3548
  children: (value) => children(value)
3445
3549
  }, definition.type);
3446
- case textInput.SelectControlType:
3550
+ case typography.SelectControlType:
3447
3551
  return /* @__PURE__ */ jsxRuntime.jsx(RenderHook, {
3448
3552
  hook: useSelectControlValue,
3449
3553
  parameters: [data, definition],
@@ -3455,7 +3559,7 @@ function ControlValue({
3455
3559
  parameters: [data, definition],
3456
3560
  children: (value) => children(value)
3457
3561
  }, definition.type);
3458
- case textInput.IconRadioGroupControlType:
3562
+ case typography.IconRadioGroupControlType:
3459
3563
  return /* @__PURE__ */ jsxRuntime.jsx(RenderHook, {
3460
3564
  hook: useIconRadioGroupValue,
3461
3565
  parameters: [data, definition],
@@ -3524,6 +3628,12 @@ function ControlValue({
3524
3628
  parameters: [data, definition, control],
3525
3629
  children: (value) => children(value)
3526
3630
  }, definition.type);
3631
+ case typography.TypographyControlType:
3632
+ return /* @__PURE__ */ jsxRuntime.jsx(RenderHook, {
3633
+ hook: useTypographyValue,
3634
+ parameters: [data],
3635
+ children: (value) => children(value)
3636
+ }, definition.type);
3527
3637
  default:
3528
3638
  return children(data);
3529
3639
  }
@@ -3565,19 +3675,20 @@ function PropsValue({
3565
3675
  return Object.entries(propControllerDescriptorsRef.current).reduceRight((renderFn, [propName, descriptor]) => (propsValue) => {
3566
3676
  var _a2, _b, _c, _d;
3567
3677
  switch (descriptor.type) {
3568
- case textInput.CheckboxControlType:
3569
- case textInput.NumberControlType:
3570
- case textInput.TextInputControlType:
3571
- case textInput.TextAreaControlType:
3572
- case textInput.SelectControlType:
3678
+ case typography.CheckboxControlType:
3679
+ case typography.NumberControlType:
3680
+ case typography.TextInputControlType:
3681
+ case typography.TextAreaControlType:
3682
+ case typography.SelectControlType:
3573
3683
  case reactPage.ColorControlType:
3574
- case textInput.IconRadioGroupControlType:
3684
+ case typography.IconRadioGroupControlType:
3575
3685
  case reactPage.ImageControlType:
3576
3686
  case combobox.ComboboxControlType:
3577
3687
  case reactPage.ShapeControlType:
3578
3688
  case reactPage.ListControlType:
3579
3689
  case reactPage.LinkControlType:
3580
3690
  case reactPage.StyleV2ControlType:
3691
+ case typography.TypographyControlType:
3581
3692
  return /* @__PURE__ */ jsxRuntime.jsx(ControlValue, {
3582
3693
  definition: descriptor,
3583
3694
  data: props[propName],
@@ -4114,6 +4225,7 @@ exports.useBoxShadow = useBoxShadow;
4114
4225
  exports.useBreakpoints = useBreakpoints;
4115
4226
  exports.useBuilderEditMode = useBuilderEditMode;
4116
4227
  exports.useElementId = useElementId;
4228
+ exports.useEnhancedTypography = useEnhancedTypography;
4117
4229
  exports.useFile = useFile;
4118
4230
  exports.useFiles = useFiles;
4119
4231
  exports.useFormContext = useFormContext;
@@ -4129,5 +4241,5 @@ exports.useResponsiveTextStyle = useResponsiveTextStyle;
4129
4241
  exports.useResponsiveWidth = useResponsiveWidth;
4130
4242
  exports.useSwatches = useSwatches;
4131
4243
  exports.useTable = useTable;
4132
- exports.useTypography = useTypography;
4244
+ exports.useTypographyClassName = useTypographyClassName;
4133
4245
  //# sourceMappingURL=index.cjs.js.map