@webstudio-is/sdk-components-react 0.151.0 → 0.163.0

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.
package/lib/components.js CHANGED
@@ -201,7 +201,7 @@ var ServerEmbed = (props) => {
201
201
  var ClientEmbedWithNonExecutableScripts = ServerEmbed;
202
202
  var HtmlEmbed = forwardRef3(
203
203
  (props, ref) => {
204
- const { code, executeScriptOnCanvas, clientOnly, ...rest } = props;
204
+ const { code, executeScriptOnCanvas, clientOnly, children, ...rest } = props;
205
205
  const { renderer } = useContext(ReactSdkContext);
206
206
  const isServer = useIsServer();
207
207
  const [ssrRendered] = useState(isServer);
@@ -385,33 +385,34 @@ var imagePlaceholderSvg = `data:image/svg+xml;base64,${btoa(`<svg
385
385
  </svg>`)}`;
386
386
  var Image = forwardRef19(
387
387
  ({ loading = "lazy", ...props }, ref) => {
388
+ const src = String(props.src ?? "");
388
389
  const { imageLoader, renderer, assetBaseUrl } = useContext2(ReactSdkContext2);
389
390
  if (renderer === "canvas") {
390
391
  loading = "eager";
391
392
  }
392
- if (props.src === void 0 || props.src.startsWith(assetBaseUrl) === false) {
393
+ if (src.startsWith(assetBaseUrl) === false) {
393
394
  return /* @__PURE__ */ jsx18(
394
395
  "img",
395
396
  {
396
397
  loading,
397
398
  ...props,
398
- src: props.src || imagePlaceholderSvg,
399
+ src: src || imagePlaceholderSvg,
399
400
  ref
400
401
  },
401
- props.src
402
+ src
402
403
  );
403
404
  }
404
- const src = props.src.slice(assetBaseUrl.length);
405
+ const assetName = src.slice(assetBaseUrl.length);
405
406
  return /* @__PURE__ */ jsx18(
406
407
  WebstudioImage,
407
408
  {
408
409
  loading,
409
410
  ...props,
410
411
  loader: imageLoader,
411
- src,
412
+ src: assetName,
412
413
  ref
413
414
  },
414
- src
415
+ assetName
415
416
  );
416
417
  }
417
418
  );
@@ -852,18 +853,37 @@ var VimeoSpinner = forwardRef32(
852
853
  VimeoSpinner.displayName = "VimeoSpinner";
853
854
 
854
855
  // src/xml-node.tsx
855
- import { Children, forwardRef as forwardRef33 } from "react";
856
+ import {
857
+ ReactSdkContext as ReactSdkContext4
858
+ } from "@webstudio-is/react-sdk";
859
+ import {
860
+ Children,
861
+ createElement as createElement4,
862
+ forwardRef as forwardRef33,
863
+ useContext as useContext7
864
+ } from "react";
856
865
  import { jsx as jsx30, jsxs as jsxs2 } from "react/jsx-runtime";
857
866
  var XmlNode = forwardRef33(
858
867
  ({ tag = "", children, ...props }, ref) => {
868
+ const { renderer } = useContext7(ReactSdkContext4);
869
+ const attributeEntries = Object.entries(props).filter(
870
+ ([key]) => key.startsWith("data-") === false && key.startsWith("aria-") === false
871
+ ).filter(([key]) => key !== "tabIndex").filter(([, value]) => typeof value !== "function");
872
+ if (renderer === void 0) {
873
+ const attrProps = Object.fromEntries(attributeEntries);
874
+ return createElement4(tag, attrProps, children);
875
+ }
859
876
  const isTextChild = Children.toArray(children).every(
860
877
  (child) => typeof child === "string"
861
878
  );
862
879
  const elementName = tag.replace(/^[^\p{L}_]+/u, "").replaceAll(/[^\p{L}\p{N}\-._]+/gu, "");
880
+ const attributes = attributeEntries.map(
881
+ ([key, value]) => `${key}=${JSON.stringify(value)}`
882
+ );
863
883
  return /* @__PURE__ */ jsxs2("div", { style: { display: isTextChild ? "flex" : "contents" }, ...props, children: [
864
884
  /* @__PURE__ */ jsxs2("div", { style: { color: "rgb(16, 23, 233)" }, children: [
865
885
  "<",
866
- elementName,
886
+ [elementName, ...attributes].join(" "),
867
887
  ">"
868
888
  ] }),
869
889
  /* @__PURE__ */ jsx30("div", { ref, style: { marginLeft: isTextChild ? 0 : "1rem" }, children }),
@@ -876,6 +896,337 @@ var XmlNode = forwardRef33(
876
896
  }
877
897
  );
878
898
  XmlNode.displayName = "XmlNode";
899
+
900
+ // src/time.tsx
901
+ import * as React from "react";
902
+ import { jsx as jsx31 } from "react/jsx-runtime";
903
+ var languages = [
904
+ "af",
905
+ "am",
906
+ "ar",
907
+ "az",
908
+ "be",
909
+ "bg",
910
+ "bn",
911
+ "bs",
912
+ "ca",
913
+ "cs",
914
+ "cy",
915
+ "da",
916
+ "de",
917
+ "el",
918
+ "en",
919
+ "es",
920
+ "et",
921
+ "eu",
922
+ "fa",
923
+ "fi",
924
+ "fr",
925
+ "ga",
926
+ "gl",
927
+ "gu",
928
+ "he",
929
+ "hi",
930
+ "hr",
931
+ "hu",
932
+ "hy",
933
+ "id",
934
+ "is",
935
+ "it",
936
+ "ja",
937
+ "ka",
938
+ "kk",
939
+ "km",
940
+ "kn",
941
+ "ko",
942
+ "ky",
943
+ "lb",
944
+ "lt",
945
+ "lv",
946
+ "mk",
947
+ "ml",
948
+ "mn",
949
+ "mr",
950
+ "ms",
951
+ "mt",
952
+ "nb",
953
+ "nl",
954
+ "nn",
955
+ "pl",
956
+ "pt",
957
+ "ro",
958
+ "ru",
959
+ "si",
960
+ "sk",
961
+ "sl",
962
+ "sq",
963
+ "sr",
964
+ "sv",
965
+ "sw",
966
+ "ta",
967
+ "te",
968
+ "th",
969
+ "tr",
970
+ "uk",
971
+ "ur",
972
+ "uz",
973
+ "vi",
974
+ "zh"
975
+ ];
976
+ var countries = [
977
+ "AF",
978
+ "AL",
979
+ "DZ",
980
+ "AS",
981
+ "AD",
982
+ "AO",
983
+ "AI",
984
+ "AQ",
985
+ "AG",
986
+ "AR",
987
+ "AM",
988
+ "AW",
989
+ "AU",
990
+ "AT",
991
+ "AZ",
992
+ "BS",
993
+ "BH",
994
+ "BD",
995
+ "BB",
996
+ "BY",
997
+ "BE",
998
+ "BZ",
999
+ "BJ",
1000
+ "BM",
1001
+ "BT",
1002
+ "BO",
1003
+ "BA",
1004
+ "BW",
1005
+ "BR",
1006
+ "BN",
1007
+ "BG",
1008
+ "BF",
1009
+ "BI",
1010
+ "CV",
1011
+ "KH",
1012
+ "CM",
1013
+ "CA",
1014
+ "KY",
1015
+ "CF",
1016
+ "TD",
1017
+ "CL",
1018
+ "CN",
1019
+ "CO",
1020
+ "KM",
1021
+ "CG",
1022
+ "CD",
1023
+ "CR",
1024
+ "HR",
1025
+ "CU",
1026
+ "CY",
1027
+ "CZ",
1028
+ "DK",
1029
+ "DJ",
1030
+ "DM",
1031
+ "DO",
1032
+ "EC",
1033
+ "EG",
1034
+ "SV",
1035
+ "GQ",
1036
+ "ER",
1037
+ "EE",
1038
+ "SZ",
1039
+ "ET",
1040
+ "FJ",
1041
+ "FI",
1042
+ "FR",
1043
+ "GA",
1044
+ "GM",
1045
+ "GE",
1046
+ "DE",
1047
+ "GH",
1048
+ "GR",
1049
+ "GD",
1050
+ "GT",
1051
+ "GN",
1052
+ "GW",
1053
+ "GY",
1054
+ "HT",
1055
+ "HN",
1056
+ "HU",
1057
+ "IS",
1058
+ "IN",
1059
+ "ID",
1060
+ "IR",
1061
+ "IQ",
1062
+ "IE",
1063
+ "IL",
1064
+ "IT",
1065
+ "JM",
1066
+ "JP",
1067
+ "JO",
1068
+ "KZ",
1069
+ "KE",
1070
+ "KI",
1071
+ "KP",
1072
+ "KR",
1073
+ "KW",
1074
+ "KG",
1075
+ "LA",
1076
+ "LV",
1077
+ "LB",
1078
+ "LS",
1079
+ "LR",
1080
+ "LY",
1081
+ "LI",
1082
+ "LT",
1083
+ "LU",
1084
+ "MG",
1085
+ "MW",
1086
+ "MY",
1087
+ "MV",
1088
+ "ML",
1089
+ "MT",
1090
+ "MH",
1091
+ "MR",
1092
+ "MU",
1093
+ "MX",
1094
+ "FM",
1095
+ "MD",
1096
+ "MC",
1097
+ "MN",
1098
+ "ME",
1099
+ "MA",
1100
+ "MZ",
1101
+ "MM",
1102
+ "NA",
1103
+ "NR",
1104
+ "NP",
1105
+ "NL",
1106
+ "NZ",
1107
+ "NI",
1108
+ "NE",
1109
+ "NG",
1110
+ "NO",
1111
+ "OM",
1112
+ "PK",
1113
+ "PW",
1114
+ "PA",
1115
+ "PG",
1116
+ "PY",
1117
+ "PE",
1118
+ "PH",
1119
+ "PL",
1120
+ "PT",
1121
+ "QA",
1122
+ "RO",
1123
+ "RU",
1124
+ "RW",
1125
+ "KN",
1126
+ "LC",
1127
+ "VC",
1128
+ "WS",
1129
+ "SM",
1130
+ "ST",
1131
+ "SA",
1132
+ "SN",
1133
+ "RS",
1134
+ "SC",
1135
+ "SL",
1136
+ "SG",
1137
+ "SK",
1138
+ "SI",
1139
+ "SB",
1140
+ "SO",
1141
+ "ZA",
1142
+ "SS",
1143
+ "ES",
1144
+ "LK",
1145
+ "SD",
1146
+ "SR",
1147
+ "SE",
1148
+ "CH",
1149
+ "SY",
1150
+ "TW",
1151
+ "TJ",
1152
+ "TZ",
1153
+ "TH",
1154
+ "TL",
1155
+ "TG",
1156
+ "TO",
1157
+ "TT",
1158
+ "TN",
1159
+ "TR",
1160
+ "TM",
1161
+ "TV",
1162
+ "UG",
1163
+ "UA",
1164
+ "AE",
1165
+ "GB",
1166
+ "US",
1167
+ "UY",
1168
+ "UZ",
1169
+ "VU",
1170
+ "VA",
1171
+ "VE",
1172
+ "VN",
1173
+ "YE",
1174
+ "ZM",
1175
+ "ZW"
1176
+ ];
1177
+ var INITIAL_DATE_STRING = "dateTime attribute is not set";
1178
+ var INVALID_DATE_STRING = "";
1179
+ var DEFAULT_LANGUAGE = "en";
1180
+ var DEFAULT_COUNTRY = "GB";
1181
+ var DEFAULT_DATE_STYLE = "medium";
1182
+ var DEFAULT_TIME_STYLE = "none";
1183
+ var languageOrDefault = (language) => {
1184
+ return languages.includes(language) ? language : DEFAULT_LANGUAGE;
1185
+ };
1186
+ var countryOrDefault = (country) => {
1187
+ return countries.includes(country) ? country : DEFAULT_COUNTRY;
1188
+ };
1189
+ var dateStyleOrUndefined = (value) => {
1190
+ if (["full", "long", "medium", "short"].includes(value)) {
1191
+ return value;
1192
+ }
1193
+ return void 0;
1194
+ };
1195
+ var timeStyleOrUndefined = (value) => {
1196
+ if (["full", "long", "medium", "short"].includes(value)) {
1197
+ return value;
1198
+ }
1199
+ return void 0;
1200
+ };
1201
+ var Time = React.forwardRef(
1202
+ ({
1203
+ language = DEFAULT_LANGUAGE,
1204
+ country = DEFAULT_COUNTRY,
1205
+ dateStyle = DEFAULT_DATE_STYLE,
1206
+ timeStyle = DEFAULT_TIME_STYLE,
1207
+ datetime = INITIAL_DATE_STRING,
1208
+ ...props
1209
+ }, ref) => {
1210
+ const locale = `${languageOrDefault(language)}-${countryOrDefault(
1211
+ country
1212
+ )}`;
1213
+ const options = {
1214
+ dateStyle: dateStyleOrUndefined(dateStyle),
1215
+ timeStyle: timeStyleOrUndefined(timeStyle)
1216
+ };
1217
+ const datetimeString = datetime === null ? INVALID_DATE_STRING : datetime.toString();
1218
+ const date = new Date(datetimeString);
1219
+ const isValidDate = false === Number.isNaN(date.getTime());
1220
+ let formattedDate = datetimeString;
1221
+ if (isValidDate) {
1222
+ try {
1223
+ formattedDate = new Intl.DateTimeFormat(locale, options).format(date);
1224
+ } catch {
1225
+ }
1226
+ }
1227
+ return /* @__PURE__ */ jsx31("time", { ref, dateTime: datetimeString, ...props, children: formattedDate });
1228
+ }
1229
+ );
879
1230
  export {
880
1231
  Blockquote,
881
1232
  Body,
@@ -905,6 +1256,7 @@ export {
905
1256
  Superscript,
906
1257
  Text,
907
1258
  Textarea,
1259
+ Time,
908
1260
  Vimeo,
909
1261
  VimeoPlayButton,
910
1262
  VimeoPreviewImage,