@tinacms/mdx 1.3.15 → 1.3.16

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.
@@ -45363,6 +45363,14 @@ var extractKeyValue = (property, parentField) => {
45363
45363
  const value = extractObjectExpression(property.value, field);
45364
45364
  return { key, value };
45365
45365
  }
45366
+ } else if (field?.list) {
45367
+ assertType(property.value, "ArrayExpression");
45368
+ const value = property.value.elements.map((element2) => {
45369
+ assertHasType(element2);
45370
+ assertType(element2, "Literal");
45371
+ return element2.value;
45372
+ });
45373
+ return { key, value };
45366
45374
  } else {
45367
45375
  assertType(property.value, "Literal");
45368
45376
  return { key, value: property.value.value };
@@ -45735,7 +45743,7 @@ var remarkToSlate = (root3, field, imageCallback, raw, skipMDXProcess) => {
45735
45743
  const link2 = (content5) => {
45736
45744
  return {
45737
45745
  type: "a",
45738
- url: content5.url,
45746
+ url: sanitizeUrl(content5.url),
45739
45747
  title: content5.title,
45740
45748
  children: flatten_default(
45741
45749
  content5.children.map((child) => staticPhrasingContent(child))
@@ -45849,7 +45857,12 @@ var remarkToSlate = (root3, field, imageCallback, raw, skipMDXProcess) => {
45849
45857
  const children = flatten_default(
45850
45858
  node.children.map((child) => phrashingMark(child, marks))
45851
45859
  );
45852
- accum.push({ type: "a", url: node.url, title: node.title, children });
45860
+ accum.push({
45861
+ type: "a",
45862
+ url: sanitizeUrl(node.url),
45863
+ title: node.title,
45864
+ children
45865
+ });
45853
45866
  break;
45854
45867
  }
45855
45868
  case "text":
@@ -45931,6 +45944,30 @@ var RichTextParseError = class extends Error {
45931
45944
  this.position = position2;
45932
45945
  }
45933
45946
  };
45947
+ var sanitizeUrl = (url) => {
45948
+ const allowedSchemes = ["http", "https", "mailto", "tel"];
45949
+ if (!url)
45950
+ return "";
45951
+ let parsedUrl = null;
45952
+ try {
45953
+ parsedUrl = new URL(url);
45954
+ } catch (error) {
45955
+ return url;
45956
+ }
45957
+ const scheme = parsedUrl.protocol.slice(0, -1);
45958
+ if (allowedSchemes && !allowedSchemes.includes(scheme)) {
45959
+ console.warn(`Invalid URL scheme detected ${scheme}`);
45960
+ return "";
45961
+ }
45962
+ if (parsedUrl.pathname === "/") {
45963
+ if (url.endsWith("/")) {
45964
+ return parsedUrl.href;
45965
+ }
45966
+ return parsedUrl.origin;
45967
+ } else {
45968
+ return parsedUrl.href;
45969
+ }
45970
+ };
45934
45971
 
45935
45972
  // src/next/parse/post-processing.ts
45936
45973
  var postProcessor = (tree, field, imageCallback) => {
package/dist/index.js CHANGED
@@ -47259,6 +47259,14 @@ var extractKeyValue = (property, parentField) => {
47259
47259
  const value = extractObjectExpression(property.value, field);
47260
47260
  return { key, value };
47261
47261
  }
47262
+ } else if (field == null ? void 0 : field.list) {
47263
+ assertType(property.value, "ArrayExpression");
47264
+ const value = property.value.elements.map((element) => {
47265
+ assertHasType(element);
47266
+ assertType(element, "Literal");
47267
+ return element.value;
47268
+ });
47269
+ return { key, value };
47262
47270
  } else {
47263
47271
  assertType(property.value, "Literal");
47264
47272
  return { key, value: property.value.value };
@@ -47635,7 +47643,7 @@ var remarkToSlate = (root3, field, imageCallback, raw, skipMDXProcess) => {
47635
47643
  const link2 = (content5) => {
47636
47644
  return {
47637
47645
  type: "a",
47638
- url: content5.url,
47646
+ url: sanitizeUrl(content5.url),
47639
47647
  title: content5.title,
47640
47648
  children: flatten_default(
47641
47649
  content5.children.map((child) => staticPhrasingContent(child))
@@ -47749,7 +47757,12 @@ var remarkToSlate = (root3, field, imageCallback, raw, skipMDXProcess) => {
47749
47757
  const children = flatten_default(
47750
47758
  node.children.map((child) => phrashingMark(child, marks))
47751
47759
  );
47752
- accum.push({ type: "a", url: node.url, title: node.title, children });
47760
+ accum.push({
47761
+ type: "a",
47762
+ url: sanitizeUrl(node.url),
47763
+ title: node.title,
47764
+ children
47765
+ });
47753
47766
  break;
47754
47767
  }
47755
47768
  case "text":
@@ -47831,6 +47844,30 @@ var RichTextParseError = class extends Error {
47831
47844
  this.position = position2;
47832
47845
  }
47833
47846
  };
47847
+ var sanitizeUrl = (url) => {
47848
+ const allowedSchemes = ["http", "https", "mailto", "tel"];
47849
+ if (!url)
47850
+ return "";
47851
+ let parsedUrl = null;
47852
+ try {
47853
+ parsedUrl = new URL(url);
47854
+ } catch (error) {
47855
+ return url;
47856
+ }
47857
+ const scheme = parsedUrl.protocol.slice(0, -1);
47858
+ if (allowedSchemes && !allowedSchemes.includes(scheme)) {
47859
+ console.warn(`Invalid URL scheme detected ${scheme}`);
47860
+ return "";
47861
+ }
47862
+ if (parsedUrl.pathname === "/") {
47863
+ if (url.endsWith("/")) {
47864
+ return parsedUrl.href;
47865
+ }
47866
+ return parsedUrl.origin;
47867
+ } else {
47868
+ return parsedUrl.href;
47869
+ }
47870
+ };
47834
47871
 
47835
47872
  // src/next/parse/post-processing.ts
47836
47873
  var postProcessor = (tree, field, imageCallback) => {
package/dist/index.mjs CHANGED
@@ -47235,6 +47235,14 @@ var extractKeyValue = (property, parentField) => {
47235
47235
  const value = extractObjectExpression(property.value, field);
47236
47236
  return { key, value };
47237
47237
  }
47238
+ } else if (field?.list) {
47239
+ assertType(property.value, "ArrayExpression");
47240
+ const value = property.value.elements.map((element) => {
47241
+ assertHasType(element);
47242
+ assertType(element, "Literal");
47243
+ return element.value;
47244
+ });
47245
+ return { key, value };
47238
47246
  } else {
47239
47247
  assertType(property.value, "Literal");
47240
47248
  return { key, value: property.value.value };
@@ -47607,7 +47615,7 @@ var remarkToSlate = (root3, field, imageCallback, raw, skipMDXProcess) => {
47607
47615
  const link2 = (content5) => {
47608
47616
  return {
47609
47617
  type: "a",
47610
- url: content5.url,
47618
+ url: sanitizeUrl(content5.url),
47611
47619
  title: content5.title,
47612
47620
  children: flatten_default(
47613
47621
  content5.children.map((child) => staticPhrasingContent(child))
@@ -47721,7 +47729,12 @@ var remarkToSlate = (root3, field, imageCallback, raw, skipMDXProcess) => {
47721
47729
  const children = flatten_default(
47722
47730
  node.children.map((child) => phrashingMark(child, marks))
47723
47731
  );
47724
- accum.push({ type: "a", url: node.url, title: node.title, children });
47732
+ accum.push({
47733
+ type: "a",
47734
+ url: sanitizeUrl(node.url),
47735
+ title: node.title,
47736
+ children
47737
+ });
47725
47738
  break;
47726
47739
  }
47727
47740
  case "text":
@@ -47803,6 +47816,30 @@ var RichTextParseError = class extends Error {
47803
47816
  this.position = position2;
47804
47817
  }
47805
47818
  };
47819
+ var sanitizeUrl = (url) => {
47820
+ const allowedSchemes = ["http", "https", "mailto", "tel"];
47821
+ if (!url)
47822
+ return "";
47823
+ let parsedUrl = null;
47824
+ try {
47825
+ parsedUrl = new URL(url);
47826
+ } catch (error) {
47827
+ return url;
47828
+ }
47829
+ const scheme = parsedUrl.protocol.slice(0, -1);
47830
+ if (allowedSchemes && !allowedSchemes.includes(scheme)) {
47831
+ console.warn(`Invalid URL scheme detected ${scheme}`);
47832
+ return "";
47833
+ }
47834
+ if (parsedUrl.pathname === "/") {
47835
+ if (url.endsWith("/")) {
47836
+ return parsedUrl.href;
47837
+ }
47838
+ return parsedUrl.origin;
47839
+ } else {
47840
+ return parsedUrl.href;
47841
+ }
47842
+ };
47806
47843
 
47807
47844
  // src/next/parse/post-processing.ts
47808
47845
  var postProcessor = (tree, field, imageCallback) => {
@@ -0,0 +1,2 @@
1
+ import { RichTextField } from '@tinacms/schema-tools';
2
+ export declare const field: RichTextField;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tinacms/mdx",
3
- "version": "1.3.15",
3
+ "version": "1.3.16",
4
4
  "typings": "dist/index.d.ts",
5
5
  "main": "dist/index.js",
6
6
  "browser": "dist/index.browser.mjs",
@@ -27,7 +27,7 @@
27
27
  ]
28
28
  },
29
29
  "dependencies": {
30
- "@tinacms/schema-tools": "1.4.9",
30
+ "@tinacms/schema-tools": "1.4.10",
31
31
  "acorn": "8.8.2",
32
32
  "ccount": "2.0.1",
33
33
  "estree-util-is-identifier-name": "2.1.0",
@@ -63,7 +63,7 @@
63
63
  "directory": "packages/tina-graphql"
64
64
  },
65
65
  "devDependencies": {
66
- "@tinacms/scripts": "1.1.1",
66
+ "@tinacms/scripts": "1.1.2",
67
67
  "@types/mdast": "^3.0.10",
68
68
  "@types/unist": "^2.0.6",
69
69
  "@types/estree": "1.0.0",