@tinacms/mdx 1.3.15 → 1.3.17

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.
@@ -52,7 +52,7 @@ var require_extend = __commonJS({
52
52
  }
53
53
  return toStr.call(arr) === "[object Array]";
54
54
  };
55
- var isPlainObject2 = function isPlainObject3(obj) {
55
+ var isPlainObject3 = function isPlainObject4(obj) {
56
56
  if (!obj || toStr.call(obj) !== "[object Object]") {
57
57
  return false;
58
58
  }
@@ -109,12 +109,12 @@ var require_extend = __commonJS({
109
109
  src = getProperty(target, name2);
110
110
  copy = getProperty(options, name2);
111
111
  if (target !== copy) {
112
- if (deep && copy && (isPlainObject2(copy) || (copyIsArray = isArray4(copy)))) {
112
+ if (deep && copy && (isPlainObject3(copy) || (copyIsArray = isArray4(copy)))) {
113
113
  if (copyIsArray) {
114
114
  copyIsArray = false;
115
115
  clone = src && isArray4(src) ? src : [];
116
116
  } else {
117
- clone = src && isPlainObject2(src) ? src : {};
117
+ clone = src && isPlainObject3(src) ? src : {};
118
118
  }
119
119
  setProperty(target, { name: name2, newValue: extend4(deep, clone, copy) });
120
120
  } else if (typeof copy !== "undefined") {
@@ -35419,6 +35419,9 @@ function stringifyProps(element2, parentField, flatten2, imageCallback) {
35419
35419
  } else {
35420
35420
  const joiner = flatten2 ? " " : "\n";
35421
35421
  let val = "";
35422
+ if (isPlainObject2(value) && Object.keys(value).length === 0) {
35423
+ return;
35424
+ }
35422
35425
  assertShape(
35423
35426
  value,
35424
35427
  (value2) => value2.type === "root" && Array.isArray(value2.children),
@@ -35504,6 +35507,9 @@ function assertShape(value, callback, errorMessage) {
35504
35507
  throw new Error(errorMessage || `Failed to assert shape`);
35505
35508
  }
35506
35509
  }
35510
+ function isPlainObject2(value) {
35511
+ return typeof value === "object" && value !== null && !Array.isArray(value);
35512
+ }
35507
35513
 
35508
35514
  // src/stringify/marks.ts
35509
35515
  var matches = (a, b) => {
@@ -45363,6 +45369,14 @@ var extractKeyValue = (property, parentField) => {
45363
45369
  const value = extractObjectExpression(property.value, field);
45364
45370
  return { key, value };
45365
45371
  }
45372
+ } else if (field?.list) {
45373
+ assertType(property.value, "ArrayExpression");
45374
+ const value = property.value.elements.map((element2) => {
45375
+ assertHasType(element2);
45376
+ assertType(element2, "Literal");
45377
+ return element2.value;
45378
+ });
45379
+ return { key, value };
45366
45380
  } else {
45367
45381
  assertType(property.value, "Literal");
45368
45382
  return { key, value: property.value.value };
@@ -45735,7 +45749,7 @@ var remarkToSlate = (root3, field, imageCallback, raw, skipMDXProcess) => {
45735
45749
  const link2 = (content5) => {
45736
45750
  return {
45737
45751
  type: "a",
45738
- url: content5.url,
45752
+ url: sanitizeUrl(content5.url),
45739
45753
  title: content5.title,
45740
45754
  children: flatten_default(
45741
45755
  content5.children.map((child) => staticPhrasingContent(child))
@@ -45849,7 +45863,12 @@ var remarkToSlate = (root3, field, imageCallback, raw, skipMDXProcess) => {
45849
45863
  const children = flatten_default(
45850
45864
  node.children.map((child) => phrashingMark(child, marks))
45851
45865
  );
45852
- accum.push({ type: "a", url: node.url, title: node.title, children });
45866
+ accum.push({
45867
+ type: "a",
45868
+ url: sanitizeUrl(node.url),
45869
+ title: node.title,
45870
+ children
45871
+ });
45853
45872
  break;
45854
45873
  }
45855
45874
  case "text":
@@ -45931,6 +45950,30 @@ var RichTextParseError = class extends Error {
45931
45950
  this.position = position2;
45932
45951
  }
45933
45952
  };
45953
+ var sanitizeUrl = (url) => {
45954
+ const allowedSchemes = ["http", "https", "mailto", "tel"];
45955
+ if (!url)
45956
+ return "";
45957
+ let parsedUrl = null;
45958
+ try {
45959
+ parsedUrl = new URL(url);
45960
+ } catch (error) {
45961
+ return url;
45962
+ }
45963
+ const scheme = parsedUrl.protocol.slice(0, -1);
45964
+ if (allowedSchemes && !allowedSchemes.includes(scheme)) {
45965
+ console.warn(`Invalid URL scheme detected ${scheme}`);
45966
+ return "";
45967
+ }
45968
+ if (parsedUrl.pathname === "/") {
45969
+ if (url.endsWith("/")) {
45970
+ return parsedUrl.href;
45971
+ }
45972
+ return parsedUrl.origin;
45973
+ } else {
45974
+ return parsedUrl.href;
45975
+ }
45976
+ };
45934
45977
 
45935
45978
  // src/next/parse/post-processing.ts
45936
45979
  var postProcessor = (tree, field, imageCallback) => {
package/dist/index.js CHANGED
@@ -49,7 +49,7 @@ var require_extend = __commonJS({
49
49
  }
50
50
  return toStr.call(arr) === "[object Array]";
51
51
  };
52
- var isPlainObject2 = function isPlainObject3(obj) {
52
+ var isPlainObject3 = function isPlainObject4(obj) {
53
53
  if (!obj || toStr.call(obj) !== "[object Object]") {
54
54
  return false;
55
55
  }
@@ -106,12 +106,12 @@ var require_extend = __commonJS({
106
106
  src = getProperty(target, name2);
107
107
  copy = getProperty(options, name2);
108
108
  if (target !== copy) {
109
- if (deep && copy && (isPlainObject2(copy) || (copyIsArray = isArray4(copy)))) {
109
+ if (deep && copy && (isPlainObject3(copy) || (copyIsArray = isArray4(copy)))) {
110
110
  if (copyIsArray) {
111
111
  copyIsArray = false;
112
112
  clone = src && isArray4(src) ? src : [];
113
113
  } else {
114
- clone = src && isPlainObject2(src) ? src : {};
114
+ clone = src && isPlainObject3(src) ? src : {};
115
115
  }
116
116
  setProperty(target, { name: name2, newValue: extend4(deep, clone, copy) });
117
117
  } else if (typeof copy !== "undefined") {
@@ -37303,6 +37303,9 @@ function stringifyProps(element, parentField, flatten2, imageCallback) {
37303
37303
  } else {
37304
37304
  const joiner = flatten2 ? " " : "\n";
37305
37305
  let val = "";
37306
+ if (isPlainObject2(value) && Object.keys(value).length === 0) {
37307
+ return;
37308
+ }
37306
37309
  assertShape(
37307
37310
  value,
37308
37311
  (value2) => value2.type === "root" && Array.isArray(value2.children),
@@ -37388,6 +37391,9 @@ function assertShape(value, callback, errorMessage) {
37388
37391
  throw new Error(errorMessage || `Failed to assert shape`);
37389
37392
  }
37390
37393
  }
37394
+ function isPlainObject2(value) {
37395
+ return typeof value === "object" && value !== null && !Array.isArray(value);
37396
+ }
37391
37397
 
37392
37398
  // src/stringify/marks.ts
37393
37399
  var matches = (a, b) => {
@@ -47259,6 +47265,14 @@ var extractKeyValue = (property, parentField) => {
47259
47265
  const value = extractObjectExpression(property.value, field);
47260
47266
  return { key, value };
47261
47267
  }
47268
+ } else if (field == null ? void 0 : field.list) {
47269
+ assertType(property.value, "ArrayExpression");
47270
+ const value = property.value.elements.map((element) => {
47271
+ assertHasType(element);
47272
+ assertType(element, "Literal");
47273
+ return element.value;
47274
+ });
47275
+ return { key, value };
47262
47276
  } else {
47263
47277
  assertType(property.value, "Literal");
47264
47278
  return { key, value: property.value.value };
@@ -47635,7 +47649,7 @@ var remarkToSlate = (root3, field, imageCallback, raw, skipMDXProcess) => {
47635
47649
  const link2 = (content5) => {
47636
47650
  return {
47637
47651
  type: "a",
47638
- url: content5.url,
47652
+ url: sanitizeUrl(content5.url),
47639
47653
  title: content5.title,
47640
47654
  children: flatten_default(
47641
47655
  content5.children.map((child) => staticPhrasingContent(child))
@@ -47749,7 +47763,12 @@ var remarkToSlate = (root3, field, imageCallback, raw, skipMDXProcess) => {
47749
47763
  const children = flatten_default(
47750
47764
  node.children.map((child) => phrashingMark(child, marks))
47751
47765
  );
47752
- accum.push({ type: "a", url: node.url, title: node.title, children });
47766
+ accum.push({
47767
+ type: "a",
47768
+ url: sanitizeUrl(node.url),
47769
+ title: node.title,
47770
+ children
47771
+ });
47753
47772
  break;
47754
47773
  }
47755
47774
  case "text":
@@ -47831,6 +47850,30 @@ var RichTextParseError = class extends Error {
47831
47850
  this.position = position2;
47832
47851
  }
47833
47852
  };
47853
+ var sanitizeUrl = (url) => {
47854
+ const allowedSchemes = ["http", "https", "mailto", "tel"];
47855
+ if (!url)
47856
+ return "";
47857
+ let parsedUrl = null;
47858
+ try {
47859
+ parsedUrl = new URL(url);
47860
+ } catch (error) {
47861
+ return url;
47862
+ }
47863
+ const scheme = parsedUrl.protocol.slice(0, -1);
47864
+ if (allowedSchemes && !allowedSchemes.includes(scheme)) {
47865
+ console.warn(`Invalid URL scheme detected ${scheme}`);
47866
+ return "";
47867
+ }
47868
+ if (parsedUrl.pathname === "/") {
47869
+ if (url.endsWith("/")) {
47870
+ return parsedUrl.href;
47871
+ }
47872
+ return parsedUrl.origin;
47873
+ } else {
47874
+ return parsedUrl.href;
47875
+ }
47876
+ };
47834
47877
 
47835
47878
  // src/next/parse/post-processing.ts
47836
47879
  var postProcessor = (tree, field, imageCallback) => {
package/dist/index.mjs CHANGED
@@ -52,7 +52,7 @@ var require_extend = __commonJS({
52
52
  }
53
53
  return toStr.call(arr) === "[object Array]";
54
54
  };
55
- var isPlainObject2 = function isPlainObject3(obj) {
55
+ var isPlainObject3 = function isPlainObject4(obj) {
56
56
  if (!obj || toStr.call(obj) !== "[object Object]") {
57
57
  return false;
58
58
  }
@@ -109,12 +109,12 @@ var require_extend = __commonJS({
109
109
  src = getProperty(target, name2);
110
110
  copy = getProperty(options, name2);
111
111
  if (target !== copy) {
112
- if (deep && copy && (isPlainObject2(copy) || (copyIsArray = isArray4(copy)))) {
112
+ if (deep && copy && (isPlainObject3(copy) || (copyIsArray = isArray4(copy)))) {
113
113
  if (copyIsArray) {
114
114
  copyIsArray = false;
115
115
  clone = src && isArray4(src) ? src : [];
116
116
  } else {
117
- clone = src && isPlainObject2(src) ? src : {};
117
+ clone = src && isPlainObject3(src) ? src : {};
118
118
  }
119
119
  setProperty(target, { name: name2, newValue: extend4(deep, clone, copy) });
120
120
  } else if (typeof copy !== "undefined") {
@@ -37291,6 +37291,9 @@ function stringifyProps(element, parentField, flatten2, imageCallback) {
37291
37291
  } else {
37292
37292
  const joiner = flatten2 ? " " : "\n";
37293
37293
  let val = "";
37294
+ if (isPlainObject2(value) && Object.keys(value).length === 0) {
37295
+ return;
37296
+ }
37294
37297
  assertShape(
37295
37298
  value,
37296
37299
  (value2) => value2.type === "root" && Array.isArray(value2.children),
@@ -37376,6 +37379,9 @@ function assertShape(value, callback, errorMessage) {
37376
37379
  throw new Error(errorMessage || `Failed to assert shape`);
37377
37380
  }
37378
37381
  }
37382
+ function isPlainObject2(value) {
37383
+ return typeof value === "object" && value !== null && !Array.isArray(value);
37384
+ }
37379
37385
 
37380
37386
  // src/stringify/marks.ts
37381
37387
  var matches = (a, b) => {
@@ -47235,6 +47241,14 @@ var extractKeyValue = (property, parentField) => {
47235
47241
  const value = extractObjectExpression(property.value, field);
47236
47242
  return { key, value };
47237
47243
  }
47244
+ } else if (field?.list) {
47245
+ assertType(property.value, "ArrayExpression");
47246
+ const value = property.value.elements.map((element) => {
47247
+ assertHasType(element);
47248
+ assertType(element, "Literal");
47249
+ return element.value;
47250
+ });
47251
+ return { key, value };
47238
47252
  } else {
47239
47253
  assertType(property.value, "Literal");
47240
47254
  return { key, value: property.value.value };
@@ -47607,7 +47621,7 @@ var remarkToSlate = (root3, field, imageCallback, raw, skipMDXProcess) => {
47607
47621
  const link2 = (content5) => {
47608
47622
  return {
47609
47623
  type: "a",
47610
- url: content5.url,
47624
+ url: sanitizeUrl(content5.url),
47611
47625
  title: content5.title,
47612
47626
  children: flatten_default(
47613
47627
  content5.children.map((child) => staticPhrasingContent(child))
@@ -47721,7 +47735,12 @@ var remarkToSlate = (root3, field, imageCallback, raw, skipMDXProcess) => {
47721
47735
  const children = flatten_default(
47722
47736
  node.children.map((child) => phrashingMark(child, marks))
47723
47737
  );
47724
- accum.push({ type: "a", url: node.url, title: node.title, children });
47738
+ accum.push({
47739
+ type: "a",
47740
+ url: sanitizeUrl(node.url),
47741
+ title: node.title,
47742
+ children
47743
+ });
47725
47744
  break;
47726
47745
  }
47727
47746
  case "text":
@@ -47803,6 +47822,30 @@ var RichTextParseError = class extends Error {
47803
47822
  this.position = position2;
47804
47823
  }
47805
47824
  };
47825
+ var sanitizeUrl = (url) => {
47826
+ const allowedSchemes = ["http", "https", "mailto", "tel"];
47827
+ if (!url)
47828
+ return "";
47829
+ let parsedUrl = null;
47830
+ try {
47831
+ parsedUrl = new URL(url);
47832
+ } catch (error) {
47833
+ return url;
47834
+ }
47835
+ const scheme = parsedUrl.protocol.slice(0, -1);
47836
+ if (allowedSchemes && !allowedSchemes.includes(scheme)) {
47837
+ console.warn(`Invalid URL scheme detected ${scheme}`);
47838
+ return "";
47839
+ }
47840
+ if (parsedUrl.pathname === "/") {
47841
+ if (url.endsWith("/")) {
47842
+ return parsedUrl.href;
47843
+ }
47844
+ return parsedUrl.origin;
47845
+ } else {
47846
+ return parsedUrl.href;
47847
+ }
47848
+ };
47806
47849
 
47807
47850
  // src/next/parse/post-processing.ts
47808
47851
  var postProcessor = (tree, field, imageCallback) => {
@@ -0,0 +1,2 @@
1
+ import { RichTextField } from '@tinacms/schema-tools';
2
+ export declare const field: RichTextField;
@@ -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.17",
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.11",
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",