@valbuild/shared 0.62.6 → 0.63.1

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.
@@ -3,30 +3,9 @@
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
5
  var core = require('@valbuild/core');
6
- var marked = require('marked');
7
6
  var zod = require('zod');
8
7
  var fp = require('@valbuild/core/fp');
9
8
 
10
- function _interopNamespace(e) {
11
- if (e && e.__esModule) return e;
12
- var n = Object.create(null);
13
- if (e) {
14
- Object.keys(e).forEach(function (k) {
15
- if (k !== 'default') {
16
- var d = Object.getOwnPropertyDescriptor(e, k);
17
- Object.defineProperty(n, k, d.get ? d : {
18
- enumerable: true,
19
- get: function () { return e[k]; }
20
- });
21
- }
22
- });
23
- }
24
- n["default"] = e;
25
- return Object.freeze(n);
26
- }
27
-
28
- var marked__namespace = /*#__PURE__*/_interopNamespace(marked);
29
-
30
9
  function toPrimitive(t, r) {
31
10
  if ("object" != typeof t || !t) return t;
32
11
  var e = t[Symbol.toPrimitive];
@@ -58,6 +37,28 @@ function _defineProperty(obj, key, value) {
58
37
  return obj;
59
38
  }
60
39
 
40
+ function ownKeys(e, r) {
41
+ var t = Object.keys(e);
42
+ if (Object.getOwnPropertySymbols) {
43
+ var o = Object.getOwnPropertySymbols(e);
44
+ r && (o = o.filter(function (r) {
45
+ return Object.getOwnPropertyDescriptor(e, r).enumerable;
46
+ })), t.push.apply(t, o);
47
+ }
48
+ return t;
49
+ }
50
+ function _objectSpread2(e) {
51
+ for (var r = 1; r < arguments.length; r++) {
52
+ var t = null != arguments[r] ? arguments[r] : {};
53
+ r % 2 ? ownKeys(Object(t), !0).forEach(function (r) {
54
+ _defineProperty(e, r, t[r]);
55
+ }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) {
56
+ Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r));
57
+ });
58
+ }
59
+ return e;
60
+ }
61
+
61
62
  function _arrayLikeToArray(arr, len) {
62
63
  if (len == null || len > arr.length) len = arr.length;
63
64
  for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i];
@@ -125,22 +126,6 @@ function _createForOfIteratorHelper(o, allowArrayLike) {
125
126
  };
126
127
  }
127
128
 
128
- function _arrayWithoutHoles(arr) {
129
- if (Array.isArray(arr)) return _arrayLikeToArray(arr);
130
- }
131
-
132
- function _iterableToArray(iter) {
133
- if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter);
134
- }
135
-
136
- function _nonIterableSpread() {
137
- throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
138
- }
139
-
140
- function _toConsumableArray(arr) {
141
- return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread();
142
- }
143
-
144
129
  function _arrayWithHoles(arr) {
145
130
  if (Array.isArray(arr)) return arr;
146
131
  }
@@ -905,184 +890,183 @@ function filenameToMimeType(filename) {
905
890
 
906
891
  function remirrorToRichTextSource(node) {
907
892
  var files = {};
908
- var markdownIRBlocks = node.content.map(function (child) {
909
- return createBlock(child, files);
910
- });
911
- return fromIRToRichTextSource(markdownIRBlocks, files);
893
+ var blocks = [];
894
+ var i = 0;
895
+ var _iterator = _createForOfIteratorHelper(node.content),
896
+ _step;
897
+ try {
898
+ for (_iterator.s(); !(_step = _iterator.n()).done;) {
899
+ var child = _step.value;
900
+ var block = convertBlock([(i++).toString()], child, files);
901
+ blocks.push(block);
902
+ }
903
+ } catch (err) {
904
+ _iterator.e(err);
905
+ } finally {
906
+ _iterator.f();
907
+ }
908
+ return {
909
+ blocks: blocks,
910
+ files: files
911
+ };
912
912
  }
913
- function createBlock(node, files) {
913
+ function convertBlock(path, node, files) {
914
914
  if (node.type === "heading") {
915
915
  var _node$attrs, _node$content;
916
- var headingTag = "";
917
916
  var depth = ((_node$attrs = node.attrs) === null || _node$attrs === void 0 ? void 0 : _node$attrs.level) || 1;
918
917
  if (Number.isNaN(depth)) {
919
918
  throw new Error("Invalid header depth");
920
919
  }
921
- for (var i = 0; i < Number(depth); i++) {
922
- headingTag += "#";
923
- }
924
- var headingText = ["".concat(headingTag, " ")];
925
920
  return {
926
- type: "block",
927
- children: headingText.concat.apply(headingText, _toConsumableArray(((_node$content = node.content) === null || _node$content === void 0 ? void 0 : _node$content.map(function (child) {
928
- return transformLeafNode(child, files);
929
- })) || []))
930
- };
931
- } else if (node.type === "paragraph") {
932
- var _node$content2;
933
- if (!node.content || ((_node$content2 = node.content) === null || _node$content2 === void 0 ? void 0 : _node$content2.length) === 0) {
934
- return {
935
- type: "block",
936
- children: ["<br />"]
937
- };
938
- }
939
- return {
940
- type: "block",
941
- children: node.content.map(function (child) {
942
- return transformLeafNode(child, files);
943
- })
944
- };
945
- } else if (node.type === "bulletList" || node.type === "orderedList") {
946
- var _node$content3;
947
- return {
948
- type: "block",
949
- children: ((_node$content3 = node.content) === null || _node$content3 === void 0 ? void 0 : _node$content3.flatMap(function (child, i) {
950
- return formatListItemNode(getListPrefix(node), child, 0, files, i === 0);
921
+ tag: "h".concat(depth),
922
+ children: ((_node$content = node.content) === null || _node$content === void 0 ? void 0 : _node$content.map(function (child, i) {
923
+ return convertHeadingChild(path.concat("children", i.toString()), child, files);
951
924
  })) || []
952
925
  };
926
+ } else if (node.type === "paragraph") {
927
+ return convertParagraph(path, node, files);
928
+ } else if (node.type === "bulletList") {
929
+ return convertBulletList(path, node, files);
930
+ } else if (node.type === "orderedList") {
931
+ return convertOrderedList(path, node, files);
953
932
  } else {
954
933
  var exhaustiveCheck = node;
955
934
  throw new Error("Unhandled node type: ".concat("type" in exhaustiveCheck ? "exhaustiveCheck.type" : "unknown"));
956
935
  }
957
936
  }
958
- function fromIRToRichTextSource(markdownIRBlocks, files) {
959
- var templateStrings = ["\n"];
960
- var exprs = [];
961
- for (var blockIdx = 0; blockIdx < markdownIRBlocks.length; blockIdx++) {
962
- var block = markdownIRBlocks[blockIdx];
963
- var _iterator = _createForOfIteratorHelper(block.children),
964
- _step;
965
- try {
966
- for (_iterator.s(); !(_step = _iterator.n()).done;) {
967
- var child = _step.value;
968
- if (typeof child === "string") {
969
- templateStrings[templateStrings.length - 1] += child;
970
- } else {
971
- if (child._type === "file") {
972
- exprs.push(child);
973
- } else if (child._type === "link") {
974
- exprs.push(child);
975
- } else {
976
- var exhaustiveCheck = child;
977
- throw new Error("Unexpected node type: ".concat(JSON.stringify(exhaustiveCheck, null, 2)));
978
- }
979
- templateStrings.push("");
980
- }
981
- }
982
- } catch (err) {
983
- _iterator.e(err);
984
- } finally {
985
- _iterator.f();
986
- }
987
- if (blockIdx === markdownIRBlocks.length - 1) {
988
- templateStrings[templateStrings.length - 1] += "\n";
989
- } else {
990
- templateStrings[templateStrings.length - 1] += "\n\n";
991
- }
937
+ function convertHeadingChild(path, node, files) {
938
+ if (node.type === "text") {
939
+ return convertTextNode(node);
940
+ } else if (node.type === "hardBreak") {
941
+ return {
942
+ tag: "br"
943
+ };
944
+ } else if (node.type === "image") {
945
+ return convertImageNode(path, node, files);
946
+ } else {
947
+ var exhaustiveCheck = node;
948
+ throw new Error("Unexpected heading child type: ".concat(JSON.stringify(exhaustiveCheck, null, 2)));
992
949
  }
993
- return _defineProperty(_defineProperty(_defineProperty(_defineProperty({}, core.VAL_EXTENSION, "richtext"), "templateStrings", templateStrings), "exprs", exprs), "files", files);
994
950
  }
995
- function formatText(node) {
996
- var _node$marks;
997
- var classes = ((_node$marks = node.marks) === null || _node$marks === void 0 ? void 0 : _node$marks.flatMap(function (mark) {
998
- if (mark.type === "bold") {
999
- return ["bold"];
1000
- } else if (mark.type === "italic") {
1001
- return ["italic"];
1002
- } else if (mark.type === "strike") {
1003
- return ["line-through"];
1004
- }
1005
- return [];
1006
- })) || [];
1007
- var text = node.text.trimStart();
1008
- var prefixWS = node.text.length - text.length;
1009
- text = text.trimEnd();
1010
- var suffixWS = node.text.length - text.length - prefixWS;
1011
- if (classes.includes("bold") && classes.includes("italic")) {
1012
- text = "***".concat(text, "***");
1013
- } else if (classes.includes("bold")) {
1014
- text = "**".concat(text, "**");
1015
- } else if (classes.includes("italic")) {
1016
- text = "_".concat(text, "_");
1017
- }
1018
- if (classes.includes("line-through")) {
1019
- text = "~~".concat(text, "~~");
1020
- }
1021
- // TODO:
1022
- // text = splitIntoChunks(text);
1023
- return "".concat(" ".repeat(prefixWS)).concat(text).concat(" ".repeat(suffixWS));
951
+ function convertParagraph(path, child, files) {
952
+ var _child$content;
953
+ return {
954
+ tag: "p",
955
+ children: ((_child$content = child.content) === null || _child$content === void 0 ? void 0 : _child$content.map(function (child, i) {
956
+ if (child.type === "text") {
957
+ return convertTextNode(child);
958
+ } else if (child.type === "hardBreak") {
959
+ return {
960
+ tag: "br"
961
+ };
962
+ } else if (child.type === "image") {
963
+ return convertImageNode(path.concat("children", i.toString()), child, files);
964
+ }
965
+ var exhaustiveCheck = child;
966
+ throw new Error("Unexpected paragraph child type: ".concat(JSON.stringify(exhaustiveCheck, null, 2)));
967
+ })) || []
968
+ };
1024
969
  }
1025
- function transformLeafNode(node, files) {
970
+ function convertTextNode(node) {
1026
971
  if (node.type === "text") {
1027
- var _node$marks2;
1028
- var linkMark = (_node$marks2 = node.marks) === null || _node$marks2 === void 0 ? void 0 : _node$marks2.find(function (mark) {
972
+ var _node$marks, _node$marks2;
973
+ var styles = ((_node$marks = node.marks) === null || _node$marks === void 0 ? void 0 : _node$marks.flatMap(function (mark) {
974
+ if (mark.type !== "link") {
975
+ if (mark.type === "strike") {
976
+ return ["line-through"];
977
+ }
978
+ return [mark.type];
979
+ } else {
980
+ return [];
981
+ }
982
+ })) || [];
983
+ if ((_node$marks2 = node.marks) !== null && _node$marks2 !== void 0 && _node$marks2.some(function (mark) {
1029
984
  return mark.type === "link";
1030
- });
1031
- if ((linkMark === null || linkMark === void 0 ? void 0 : linkMark.type) === "link") {
985
+ })) {
986
+ var _node$marks$find2;
987
+ if (styles.length > 0) {
988
+ var _node$marks$find;
989
+ return {
990
+ tag: "a",
991
+ href: ((_node$marks$find = node.marks.find(function (mark) {
992
+ return mark.type === "link";
993
+ })) === null || _node$marks$find === void 0 ? void 0 : _node$marks$find.attrs.href) || "",
994
+ children: [{
995
+ tag: "span",
996
+ styles: styles,
997
+ children: [node.text]
998
+ }]
999
+ };
1000
+ }
1032
1001
  return {
1033
- _type: "link",
1034
- href: linkMark.attrs.href,
1035
- children: [formatText(node)]
1002
+ tag: "a",
1003
+ href: ((_node$marks$find2 = node.marks.find(function (mark) {
1004
+ return mark.type === "link";
1005
+ })) === null || _node$marks$find2 === void 0 ? void 0 : _node$marks$find2.attrs.href) || "",
1006
+ children: [node.text]
1036
1007
  };
1037
1008
  }
1038
- return formatText(node);
1039
- } else if (node.type === "hardBreak") {
1040
- return "<br />";
1041
- } else if (node.type === "image") {
1042
- return fromRemirrorImageNode(node, files);
1009
+ if (styles.length > 0) {
1010
+ return {
1011
+ tag: "span",
1012
+ styles: styles,
1013
+ children: [node.text]
1014
+ };
1015
+ }
1016
+ return node.text;
1043
1017
  } else {
1044
- var exhaustiveCheck = node;
1045
- throw new Error("Unexpected node type: ".concat(JSON.stringify(exhaustiveCheck)));
1018
+ var exhaustiveCheck = node.type;
1019
+ throw new Error("Unexpected node type: ".concat(exhaustiveCheck));
1046
1020
  }
1047
1021
  }
1048
- function formatListItemNode(listPrefix, node, indent, files) {
1049
- var _node$content4, _node$content5;
1050
- var isFirstTopLevelListItem = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : false;
1051
- var newLine = isFirstTopLevelListItem ? "" : "\n";
1052
- var prefix = ["".concat(newLine).concat(" ".repeat(indent)).concat(listPrefix)];
1053
- if (!(((_node$content4 = node.content) === null || _node$content4 === void 0 || (_node$content4 = _node$content4[0]) === null || _node$content4 === void 0 ? void 0 : _node$content4.type) === "bulletList" || ((_node$content5 = node.content) === null || _node$content5 === void 0 || (_node$content5 = _node$content5[0]) === null || _node$content5 === void 0 ? void 0 : _node$content5.type) === "orderedList")) {
1054
- prefix.push(" ");
1055
- }
1056
- return prefix.concat((node.content || []).flatMap(function (child, i) {
1057
- if (child.type === "bulletList" || child.type === "orderedList") {
1058
- return (child.content || []).flatMap(function (subChild) {
1059
- return formatListItemNode(getListPrefix(child), subChild, indent + 4, files);
1060
- });
1061
- } else {
1062
- return (child.content || []).flatMap(function (subChild) {
1063
- var _child$content, _child$content2;
1064
- var res = [];
1065
- if ((_child$content = child.content) !== null && _child$content !== void 0 && _child$content.length && ((_child$content2 = child.content) === null || _child$content2 === void 0 ? void 0 : _child$content2.length) > 0 && i > 0) {
1066
- res.push("<br />\n");
1067
- }
1068
- res.push(transformLeafNode(subChild, files));
1069
- return res;
1070
- });
1071
- }
1072
- }));
1022
+ function convertListItem(path, child, files) {
1023
+ var _child$content2;
1024
+ return {
1025
+ tag: "li",
1026
+ children: ((_child$content2 = child.content) === null || _child$content2 === void 0 ? void 0 : _child$content2.map(function (child, i) {
1027
+ if (child.type === "paragraph") {
1028
+ return convertParagraph(path.concat("children", i.toString()), child, files);
1029
+ } else if (child.type === "bulletList") {
1030
+ return convertBulletList(path.concat("children", i.toString()), child, files);
1031
+ } else if (child.type === "orderedList") {
1032
+ return convertOrderedList(path.concat("children", i.toString()), child, files);
1033
+ } else {
1034
+ var exhaustiveCheck = child;
1035
+ throw new Error("Unexpected list child type: ".concat(exhaustiveCheck));
1036
+ }
1037
+ })) || []
1038
+ };
1073
1039
  }
1074
- function getListPrefix(node) {
1075
- if (node.type === "bulletList") {
1076
- return "-";
1077
- } else if (node.type === "orderedList") {
1078
- return "1.";
1079
- } else {
1080
- var exhaustiveCheck = node;
1081
- throw new Error("Unhandled list node: ".concat(JSON.stringify(exhaustiveCheck)));
1082
- }
1040
+ function convertBulletList(path, node, files) {
1041
+ var _node$content2;
1042
+ return {
1043
+ tag: "ul",
1044
+ children: ((_node$content2 = node.content) === null || _node$content2 === void 0 ? void 0 : _node$content2.map(function (child, i) {
1045
+ if (child.type === "listItem") {
1046
+ return convertListItem(path.concat("children", i.toString()), child, files);
1047
+ } else {
1048
+ var exhaustiveCheck = child.type;
1049
+ throw new Error("Unexpected bullet list child type: ".concat(exhaustiveCheck));
1050
+ }
1051
+ })) || []
1052
+ };
1053
+ }
1054
+ function convertOrderedList(path, node, files) {
1055
+ var _node$content3;
1056
+ return {
1057
+ tag: "ol",
1058
+ children: ((_node$content3 = node.content) === null || _node$content3 === void 0 ? void 0 : _node$content3.map(function (child, i) {
1059
+ if (child.type === "listItem") {
1060
+ return convertListItem(path.concat("children", i.toString()), child, files);
1061
+ } else {
1062
+ var exhaustiveCheck = child.type;
1063
+ throw new Error("Unexpected ordered list child type: ".concat(exhaustiveCheck));
1064
+ }
1065
+ })) || []
1066
+ };
1083
1067
  }
1084
1068
  var textEncoder = new TextEncoder();
1085
- function fromRemirrorImageNode(node, files) {
1069
+ function convertImageNode(path, node, files) {
1086
1070
  if (node.attrs && node.attrs.src.startsWith("data:")) {
1087
1071
  var sha256 = core.Internal.getSHA256Hash(textEncoder.encode(node.attrs.src));
1088
1072
  var mimeType = getMimeType(node.attrs.src);
@@ -1092,22 +1076,43 @@ function fromRemirrorImageNode(node, files) {
1092
1076
  var fileExt = mimeTypeToFileExt(mimeType);
1093
1077
  var fileName = node.attrs.fileName || "".concat(sha256, ".").concat(fileExt);
1094
1078
  var filePath = "/public/".concat(fileName);
1095
- files[filePath] = node.attrs.src;
1096
- return _defineProperty(_defineProperty(_defineProperty(_defineProperty({}, core.VAL_EXTENSION, "file"), core.FILE_REF_PROP, filePath), core.FILE_REF_SUBTYPE_TAG, core.RT_IMAGE_TAG), "metadata", {
1097
- width: typeof node.attrs.width === "number" ? node.attrs.width : 0,
1098
- height: typeof node.attrs.height === "number" ? node.attrs.height : 0,
1099
- sha256: sha256 || "",
1100
- mimeType: mimeType
1101
- });
1079
+ var existingFilesEntry = files[filePath];
1080
+ var thisPath = path
1081
+ // file is added as src (see below):
1082
+ .concat("src");
1083
+ if (existingFilesEntry) {
1084
+ existingFilesEntry.patchPaths.push(thisPath);
1085
+ } else {
1086
+ files[filePath] = {
1087
+ value: node.attrs.src,
1088
+ patchPaths: [thisPath]
1089
+ };
1090
+ }
1091
+ return {
1092
+ tag: "img",
1093
+ src: _defineProperty(_defineProperty(_defineProperty({}, core.VAL_EXTENSION, "file"), core.FILE_REF_PROP, filePath), "metadata", {
1094
+ width: typeof node.attrs.width === "number" ? node.attrs.width : 0,
1095
+ height: typeof node.attrs.height === "number" ? node.attrs.height : 0,
1096
+ sha256: sha256 || "",
1097
+ mimeType: mimeType
1098
+ })
1099
+ };
1102
1100
  } else if (node.attrs) {
1103
1101
  var _sha = getParam("sha256", node.attrs.src);
1102
+ var patchId = getParam("patch_id", node.attrs.src);
1104
1103
  var noParamsSrc = node.attrs.src.split("?")[0];
1105
- return _defineProperty(_defineProperty(_defineProperty(_defineProperty({}, core.VAL_EXTENSION, "file"), core.FILE_REF_PROP, "/public".concat(node.attrs.src.split("?")[0])), core.FILE_REF_SUBTYPE_TAG, core.RT_IMAGE_TAG), "metadata", {
1106
- width: typeof node.attrs.width === "number" ? node.attrs.width : 0,
1107
- height: typeof node.attrs.height === "number" ? node.attrs.height : 0,
1108
- sha256: _sha || "",
1109
- mimeType: noParamsSrc && filenameToMimeType(noParamsSrc) || ""
1110
- });
1104
+ var tag = {
1105
+ tag: "img",
1106
+ src: _objectSpread2(_defineProperty(_defineProperty(_defineProperty({}, core.VAL_EXTENSION, "file"), core.FILE_REF_PROP, "/public".concat(node.attrs.src.split("?")[0])), "metadata", {
1107
+ width: typeof node.attrs.width === "number" ? node.attrs.width : 0,
1108
+ height: typeof node.attrs.height === "number" ? node.attrs.height : 0,
1109
+ sha256: _sha || "",
1110
+ mimeType: noParamsSrc && filenameToMimeType(noParamsSrc) || ""
1111
+ }), patchId ? {
1112
+ patch_id: patchId
1113
+ } : {})
1114
+ };
1115
+ return tag;
1111
1116
  } else {
1112
1117
  throw new Error("Invalid image node (no attrs): " + JSON.stringify(node));
1113
1118
  }
@@ -1125,188 +1130,6 @@ function getParam(param, url) {
1125
1130
  return undefined;
1126
1131
  }
1127
1132
 
1128
- var VAL_START_TAG_PREFIX = '<val value="';
1129
- var VAL_START_TAG_SUFFIX = '">';
1130
- var VAL_END_TAG = "</val>";
1131
- function parseTokens(tokens, sourceNodes, cursor) {
1132
- var insideList = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : false;
1133
- var children = [];
1134
- function merge(token, clazz) {
1135
- var parsedTokens = parseTokens(token.tokens ? token.tokens : [], sourceNodes, 0);
1136
- children.push({
1137
- tag: "span",
1138
- classes: [clazz].concat(parsedTokens.children.flatMap(function (child) {
1139
- return typeof child === "string" ? [] : child.classes;
1140
- })),
1141
- children: parsedTokens.children.flatMap(function (child) {
1142
- return typeof child === "string" ? child : child.children;
1143
- })
1144
- });
1145
- }
1146
- var _loop = function _loop() {
1147
- var token = tokens[cursor];
1148
- if (token.type === "heading") {
1149
- children.push({
1150
- tag: "h".concat(token.depth),
1151
- children: parseTokens(token.tokens ? token.tokens : [], sourceNodes, 0).children
1152
- });
1153
- } else if (token.type === "paragraph") {
1154
- children.push({
1155
- tag: "p",
1156
- children: parseTokens(token.tokens ? token.tokens : [], sourceNodes, 0).children
1157
- });
1158
- } else if (token.type === "strong") {
1159
- merge(token, "bold");
1160
- } else if (token.type === "em") {
1161
- merge(token, "italic");
1162
- } else if (token.type === "del") {
1163
- merge(token, "line-through");
1164
- } else if (token.type === "text") {
1165
- if ("tokens" in token && Array.isArray(token.tokens)) {
1166
- children.push.apply(children, _toConsumableArray(parseTokens(token.tokens, sourceNodes, cursor, insideList).children));
1167
- } else {
1168
- if (insideList && typeof token.raw === "string") {
1169
- var lines = token.raw.split("\n");
1170
- var tags = lines.flatMap(function (line, i) {
1171
- if (i === lines.length - 1) return [line];
1172
- if (i === lines.length - 1 && line === "") return [];
1173
- if (line === "") return {
1174
- tag: "br"
1175
- };
1176
- return [line, {
1177
- tag: "br"
1178
- }];
1179
- });
1180
- children.push.apply(children, _toConsumableArray(tags));
1181
- } else {
1182
- children.push(token.raw);
1183
- }
1184
- }
1185
- } else if (token.type === "list") {
1186
- children.push({
1187
- tag: token.ordered ? "ol" : "ul",
1188
- children: parseTokens(token.items, sourceNodes, 0).children
1189
- });
1190
- } else if (token.type === "list_item") {
1191
- children.push({
1192
- tag: "li",
1193
- children: parseTokens(token.tokens ? token.tokens : [], sourceNodes, 0, true).children
1194
- });
1195
- } else if (token.type === "space") ; else if (token.type === "html") {
1196
- if (token.text === VAL_END_TAG) {
1197
- return {
1198
- v: {
1199
- children: children,
1200
- cursor: cursor
1201
- }
1202
- };
1203
- }
1204
- var suffixIndex = token.text.indexOf(VAL_START_TAG_SUFFIX);
1205
- if (token.text.startsWith(VAL_START_TAG_PREFIX) && suffixIndex > -1) {
1206
- var number = Number(token.text.slice(VAL_START_TAG_PREFIX.length, suffixIndex));
1207
- if (Number.isNaN(number)) {
1208
- throw Error("Illegal val intermediate node: ".concat(JSON.stringify(token)));
1209
- }
1210
- var _parseTokens = parseTokens(tokens.map(function (token) {
1211
- if (token.type === "link" || token.type === "list") {
1212
- return {
1213
- type: "text",
1214
- raw: token.raw,
1215
- text: token.raw
1216
- };
1217
- }
1218
- return token;
1219
- }), sourceNodes, cursor + 1),
1220
- subChildren = _parseTokens.children,
1221
- subCursor = _parseTokens.cursor;
1222
- var sourceNode = sourceNodes[number];
1223
- if (sourceNode._type === "link") {
1224
- children.push({
1225
- tag: "a",
1226
- href: sourceNode.href,
1227
- children: subChildren
1228
- });
1229
- } else if (sourceNode._type === "file") {
1230
- var _sourceNode$metadata, _sourceNode$metadata2, _sourceNode$metadata3;
1231
- children.push({
1232
- tag: "img",
1233
- src: core.Internal.convertFileSource(sourceNode).url,
1234
- width: (_sourceNode$metadata = sourceNode.metadata) === null || _sourceNode$metadata === void 0 ? void 0 : _sourceNode$metadata.width,
1235
- height: (_sourceNode$metadata2 = sourceNode.metadata) === null || _sourceNode$metadata2 === void 0 ? void 0 : _sourceNode$metadata2.height,
1236
- mimeType: (_sourceNode$metadata3 = sourceNode.metadata) === null || _sourceNode$metadata3 === void 0 ? void 0 : _sourceNode$metadata3.mimeType
1237
- });
1238
- }
1239
- cursor = subCursor;
1240
- }
1241
- var br_html_regex = /<br\s*\/?>/gi; // matches <br>, <br/>, <br />; case insensitive
1242
- if (token.text.trim().match(br_html_regex)) {
1243
- var _tokens;
1244
- children.push({
1245
- tag: "br"
1246
- });
1247
- if (((_tokens = tokens[cursor + 1]) === null || _tokens === void 0 ? void 0 : _tokens.raw.trim()) === "") {
1248
- // if next token is a new line or white-spaces, skip it
1249
- // this typically means we have a <br> AND a new line, which, semantically, is just a <br>
1250
- cursor++;
1251
- }
1252
- }
1253
- } else if (token.type === "link") {
1254
- if (token.raw === token.href) {
1255
- // avoid auto-linking (provided by github flavoured markdown, but we want strikethrough so keep it enabled)
1256
- children.push(token.raw);
1257
- } else {
1258
- children.push({
1259
- tag: "a",
1260
- href: token.href,
1261
- children: parseTokens(token.tokens ? token.tokens : [], sourceNodes, 0).children
1262
- });
1263
- }
1264
- } else if (token.type === "br") {
1265
- children.push({
1266
- tag: "br"
1267
- });
1268
- } else {
1269
- console.error("Could not parse markdown: unsupported token type: ".concat(token.type, ". Found: ").concat(token.raw));
1270
- }
1271
- cursor++;
1272
- },
1273
- _ret;
1274
- while (cursor < tokens.length) {
1275
- _ret = _loop();
1276
- if (_ret) return _ret.v;
1277
- }
1278
- return {
1279
- children: children,
1280
- cursor: cursor
1281
- };
1282
- }
1283
- function parseRichTextSource(_ref) {
1284
- var templateStrings = _ref.templateStrings,
1285
- nodes = _ref.exprs;
1286
- // TODO: validate that templateStrings does not contain VAL_NODE_PREFIX
1287
- var inputText = templateStrings.flatMap(function (templateString, i) {
1288
- var node = nodes[i];
1289
- if (node) {
1290
- if (node[core.VAL_EXTENSION] === "link") {
1291
- return templateString.concat("".concat(VAL_START_TAG_PREFIX).concat(i).concat(VAL_START_TAG_SUFFIX).concat(node.children[0]).concat(VAL_END_TAG));
1292
- } else {
1293
- return templateString.concat("".concat(VAL_START_TAG_PREFIX).concat(i).concat(VAL_START_TAG_SUFFIX).concat(VAL_END_TAG));
1294
- }
1295
- }
1296
- return templateString;
1297
- }).join("");
1298
- var tokenList = marked__namespace.lexer(inputText, {
1299
- gfm: true
1300
- });
1301
- var _parseTokens2 = parseTokens(tokenList, nodes, 0),
1302
- children = _parseTokens2.children,
1303
- cursor = _parseTokens2.cursor;
1304
- if (cursor !== tokenList.length) {
1305
- throw Error("Unexpectedly terminated markdown parsing. Possible reason: unclosed html tag?");
1306
- }
1307
- return _defineProperty(_defineProperty({}, core.VAL_EXTENSION, "richtext"), "children", children);
1308
- }
1309
-
1310
1133
  var RemirrorTextMark = zod.z.object({
1311
1134
  type: zod.z.union([zod.z.literal("bold"), zod.z.literal("strike"), zod.z.literal("italic")])
1312
1135
  });
@@ -1350,7 +1173,7 @@ var RemirrorHeading = zod.z.intersection(zod.z.object({
1350
1173
  attrs: zod.z.object({
1351
1174
  level: zod.z.number()
1352
1175
  }),
1353
- content: zod.z.array(zod.z.union([RemirrorText, RemirrorBr]))
1176
+ content: zod.z.array(zod.z.union([RemirrorText, RemirrorImage, RemirrorBr]))
1354
1177
  }).partial());
1355
1178
  var RemirrorBulletList = zod.z.lazy(function () {
1356
1179
  return zod.z.intersection(zod.z.object({
@@ -1370,45 +1193,45 @@ var RemirrorListItem = zod.z.lazy(function () {
1370
1193
  return zod.z.intersection(zod.z.object({
1371
1194
  type: zod.z.literal("listItem")
1372
1195
  }), zod.z.object({
1196
+ attrs: zod.z.object({
1197
+ closed: zod.z["boolean"](),
1198
+ nested: zod.z["boolean"]()
1199
+ }).partial().optional(),
1373
1200
  content: zod.z.array(zod.z.union([RemirrorParagraph, RemirrorBulletList, RemirrorOrderedList]))
1374
1201
  }).partial());
1375
1202
  });
1376
- var RemirrorParagraph = zod.z.intersection(zod.z.object({
1377
- type: zod.z.literal("paragraph")
1378
- }), zod.z.object({
1379
- content: zod.z.array(zod.z.union([RemirrorText, RemirrorImage, RemirrorBr]))
1380
- }).partial());
1203
+ var RemirrorParagraph = zod.z.lazy(function () {
1204
+ return zod.z.intersection(zod.z.object({
1205
+ type: zod.z.literal("paragraph")
1206
+ }), zod.z.object({
1207
+ content: zod.z.array(zod.z.union([RemirrorText, RemirrorImage, RemirrorBr]))
1208
+ }).partial());
1209
+ });
1381
1210
  var RemirrorJSON = zod.z.object({
1382
1211
  type: zod.z.literal("doc"),
1383
1212
  content: zod.z.array(zod.z.union([RemirrorParagraph, RemirrorHeading, RemirrorBulletList, RemirrorOrderedList]))
1384
1213
  });
1385
1214
 
1386
- function ownKeys(e, r) {
1387
- var t = Object.keys(e);
1388
- if (Object.getOwnPropertySymbols) {
1389
- var o = Object.getOwnPropertySymbols(e);
1390
- r && (o = o.filter(function (r) {
1391
- return Object.getOwnPropertyDescriptor(e, r).enumerable;
1392
- })), t.push.apply(t, o);
1393
- }
1394
- return t;
1215
+ function _arrayWithoutHoles(arr) {
1216
+ if (Array.isArray(arr)) return _arrayLikeToArray(arr);
1395
1217
  }
1396
- function _objectSpread2(e) {
1397
- for (var r = 1; r < arguments.length; r++) {
1398
- var t = null != arguments[r] ? arguments[r] : {};
1399
- r % 2 ? ownKeys(Object(t), !0).forEach(function (r) {
1400
- _defineProperty(e, r, t[r]);
1401
- }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) {
1402
- Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r));
1403
- });
1404
- }
1405
- return e;
1218
+
1219
+ function _iterableToArray(iter) {
1220
+ if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter);
1221
+ }
1222
+
1223
+ function _nonIterableSpread() {
1224
+ throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
1225
+ }
1226
+
1227
+ function _toConsumableArray(arr) {
1228
+ return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread();
1406
1229
  }
1407
1230
 
1408
1231
  function richTextToRemirror(richtext) {
1409
1232
  return {
1410
1233
  type: "doc",
1411
- content: richtext.children.map(function (child) {
1234
+ content: richtext.map(function (child) {
1412
1235
  return toRemirrorNode(child);
1413
1236
  })
1414
1237
  };
@@ -1433,8 +1256,6 @@ function toRemirrorNode(child) {
1433
1256
  return convertUlToRemirror(child);
1434
1257
  case "ol":
1435
1258
  return convertOlToRemirror(child);
1436
- case "br":
1437
- return convertParagraphToRemirror([child]);
1438
1259
  default:
1439
1260
  {
1440
1261
  var _exhaustiveCheck = child;
@@ -1448,7 +1269,7 @@ function convertHeadingToRemirror(level, children) {
1448
1269
  attrs: {
1449
1270
  level: level
1450
1271
  },
1451
- content: children.flatMap(convertStringOrSpanNodeToRemirror)
1272
+ content: children.flatMap(convertInlineToRemirror)
1452
1273
  };
1453
1274
  }
1454
1275
  function convertStringToRemirror(child) {
@@ -1457,14 +1278,23 @@ function convertStringToRemirror(child) {
1457
1278
  text: child
1458
1279
  };
1459
1280
  }
1460
- function convertStringOrSpanNodeToRemirror(child) {
1281
+ function convertInlineToRemirror(child) {
1461
1282
  if (typeof child === "string") {
1462
1283
  return [convertStringToRemirror(child)];
1463
1284
  }
1285
+ if (child.tag === "img") {
1286
+ return [convertImageNodeToRemirror(child)];
1287
+ }
1288
+ if (child.tag === "br") {
1289
+ return [createRemirrorBr()];
1290
+ }
1291
+ if (child.tag === "a") {
1292
+ return convertLinkNodeToRemirror(child);
1293
+ }
1464
1294
  return convertSpanNodeToRemirror(child);
1465
1295
  }
1466
1296
  function convertSpanNodeToRemirror(spanNode) {
1467
- if (spanNode.classes.length === 0 && spanNode.children.length === 1) {
1297
+ if (spanNode.styles.length === 0 && spanNode.children.length === 1) {
1468
1298
  if (typeof spanNode.children[0] === "string") {
1469
1299
  return [convertStringToRemirror(spanNode.children[0])];
1470
1300
  } else {
@@ -1472,12 +1302,13 @@ function convertSpanNodeToRemirror(spanNode) {
1472
1302
  throw Error("Unexpected amount of children in span node: " + JSON.stringify(spanNode, null, 2));
1473
1303
  }
1474
1304
  }
1305
+ var uniqueStyles = Array.from(new Set(spanNode.styles));
1475
1306
  return spanNode.children.map(function (child) {
1476
1307
  return {
1477
1308
  type: "text",
1478
1309
  text: child,
1479
- marks: spanNode.classes.map(function (className) {
1480
- switch (className) {
1310
+ marks: uniqueStyles.map(function (style) {
1311
+ switch (style) {
1481
1312
  case "bold":
1482
1313
  return {
1483
1314
  type: "bold"
@@ -1492,7 +1323,7 @@ function convertSpanNodeToRemirror(spanNode) {
1492
1323
  };
1493
1324
  default:
1494
1325
  {
1495
- var _exhaustiveCheck = className;
1326
+ var _exhaustiveCheck = style;
1496
1327
  throw Error("Unexpected span class: " + _exhaustiveCheck);
1497
1328
  }
1498
1329
  }
@@ -1532,9 +1363,12 @@ function createRemirrorBr() {
1532
1363
  };
1533
1364
  }
1534
1365
  function convertLinkNodeToRemirror(linkNode) {
1535
- return linkNode.children.flatMap(convertStringOrSpanNodeToRemirror).map(function (remirrorText) {
1536
- return _objectSpread2(_objectSpread2({}, remirrorText), {}, {
1537
- marks: (remirrorText.marks || []).concat({
1366
+ return linkNode.children.flatMap(convertInlineToRemirror).map(function (remirrorNode) {
1367
+ if (remirrorNode.type !== "text") {
1368
+ return remirrorNode;
1369
+ }
1370
+ return _objectSpread2(_objectSpread2({}, remirrorNode), {}, {
1371
+ marks: (remirrorNode.marks || []).concat({
1538
1372
  type: "link",
1539
1373
  attrs: {
1540
1374
  href: linkNode.href,
@@ -1546,12 +1380,18 @@ function convertLinkNodeToRemirror(linkNode) {
1546
1380
  });
1547
1381
  }
1548
1382
  function convertImageNodeToRemirror(imageNode) {
1383
+ var _fileSource$metadata, _fileSource$metadata2;
1384
+ var fileSource = imageNode.src;
1385
+ if (!(core.VAL_EXTENSION in fileSource) || fileSource[core.VAL_EXTENSION] !== "file") {
1386
+ throw Error("Expected file source in image node");
1387
+ }
1388
+ var fileVal = core.Internal.convertFileSource(fileSource);
1549
1389
  return {
1550
1390
  type: "image",
1551
1391
  attrs: {
1552
- height: imageNode.height,
1553
- width: imageNode.width,
1554
- src: imageNode.src // at time of writing we are not sure if src as href or data url works, also: how to keep mimeType etc?
1392
+ height: (_fileSource$metadata = fileSource.metadata) === null || _fileSource$metadata === void 0 ? void 0 : _fileSource$metadata.height,
1393
+ width: (_fileSource$metadata2 = fileSource.metadata) === null || _fileSource$metadata2 === void 0 ? void 0 : _fileSource$metadata2.width,
1394
+ src: fileVal.url
1555
1395
  }
1556
1396
  };
1557
1397
  }
@@ -1593,24 +1433,6 @@ function convertListItemToRemirrorParagraph(rtChildren) {
1593
1433
  lastChildContent.push(convertStringToRemirror(child));
1594
1434
  } else {
1595
1435
  switch (child.tag) {
1596
- case "a":
1597
- {
1598
- lastChildContent.push.apply(lastChildContent, _toConsumableArray(convertLinkNodeToRemirror(child)));
1599
- break;
1600
- }
1601
- case "br":
1602
- {
1603
- children.push({
1604
- type: "paragraph",
1605
- content: [] // create new paragraph
1606
- });
1607
- break;
1608
- }
1609
- case "span":
1610
- {
1611
- lastChildContent.push.apply(lastChildContent, _toConsumableArray(convertSpanNodeToRemirror(child)));
1612
- break;
1613
- }
1614
1436
  case "ol":
1615
1437
  {
1616
1438
  children.push(convertOlToRemirror(child));
@@ -1621,6 +1443,20 @@ function convertListItemToRemirrorParagraph(rtChildren) {
1621
1443
  children.push(convertUlToRemirror(child));
1622
1444
  break;
1623
1445
  }
1446
+ case "p":
1447
+ {
1448
+ var newChild = convertParagraphToRemirror(child.children);
1449
+ if (lastChild.type === "paragraph" && newChild.type === "paragraph") {
1450
+ if (newChild.content) {
1451
+ lastChildContent.push.apply(lastChildContent, _toConsumableArray(newChild.content));
1452
+ } else {
1453
+ // no content - skip
1454
+ }
1455
+ } else {
1456
+ children.push(newChild);
1457
+ }
1458
+ break;
1459
+ }
1624
1460
  default:
1625
1461
  {
1626
1462
  var _exhaustiveCheck = child;
@@ -2038,10 +1874,10 @@ var ValStore = /*#__PURE__*/function () {
2038
1874
  this.schema = {};
2039
1875
  }
2040
1876
  _createClass(ValStore, [{
2041
- key: "reset",
1877
+ key: "reloadPaths",
2042
1878
  value: function () {
2043
- var _reset = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee() {
2044
- var patches, allPatches, data, _i, _Object$keys, pathS, path, _i2, _Array$from, _Array$from$_i, subscriberId, subscriberModules;
1879
+ var _reloadPaths = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(paths) {
1880
+ var patches, filteredPatches, data, _i, _Object$keys, pathS, path, _i2, _Array$from, _Array$from$_i, subscriberId, subscriberModules;
2045
1881
  return _regeneratorRuntime().wrap(function _callee$(_context) {
2046
1882
  while (1) switch (_context.prev = _context.next) {
2047
1883
  case 0:
@@ -2056,14 +1892,21 @@ var ValStore = /*#__PURE__*/function () {
2056
1892
  console.error("Val: failed to get patches", patches.error);
2057
1893
  return _context.abrupt("return");
2058
1894
  case 6:
2059
- allPatches = Object.values(patches.value).flatMap(function (mp) {
2060
- return mp.map(function (p) {
2061
- return p.patch_id;
2062
- });
1895
+ filteredPatches = Object.entries(patches.value).flatMap(function (_ref) {
1896
+ var _ref2 = _slicedToArray(_ref, 2),
1897
+ patchModuleFilePath = _ref2[0],
1898
+ mp = _ref2[1];
1899
+ if (paths.includes(patchModuleFilePath)) {
1900
+ return mp.map(function (p) {
1901
+ return p.patch_id;
1902
+ });
1903
+ } else {
1904
+ return [];
1905
+ }
2063
1906
  });
2064
1907
  _context.next = 9;
2065
1908
  return this.api.putTree({
2066
- patchIds: allPatches
1909
+ patchIds: filteredPatches
2067
1910
  });
2068
1911
  case 9:
2069
1912
  data = _context.sent;
@@ -2085,7 +1928,7 @@ var ValStore = /*#__PURE__*/function () {
2085
1928
  }
2086
1929
  }
2087
1930
  } else {
2088
- console.error("Val: failed to reset", data.error);
1931
+ console.error("Val: failed to reload paths", paths, data.error);
2089
1932
  }
2090
1933
  case 13:
2091
1934
  case "end":
@@ -2093,6 +1936,67 @@ var ValStore = /*#__PURE__*/function () {
2093
1936
  }
2094
1937
  }, _callee, this);
2095
1938
  }));
1939
+ function reloadPaths(_x) {
1940
+ return _reloadPaths.apply(this, arguments);
1941
+ }
1942
+ return reloadPaths;
1943
+ }()
1944
+ }, {
1945
+ key: "reset",
1946
+ value: function () {
1947
+ var _reset = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2() {
1948
+ var patches, allPatches, data, _i3, _Object$keys2, pathS, path, _i4, _Array$from2, _Array$from2$_i, subscriberId, subscriberModules;
1949
+ return _regeneratorRuntime().wrap(function _callee2$(_context2) {
1950
+ while (1) switch (_context2.prev = _context2.next) {
1951
+ case 0:
1952
+ _context2.next = 2;
1953
+ return this.api.getPatches();
1954
+ case 2:
1955
+ patches = _context2.sent;
1956
+ if (!fp.result.isErr(patches)) {
1957
+ _context2.next = 6;
1958
+ break;
1959
+ }
1960
+ console.error("Val: failed to get patches", patches.error);
1961
+ return _context2.abrupt("return");
1962
+ case 6:
1963
+ allPatches = Object.values(patches.value).flatMap(function (mp) {
1964
+ return mp.map(function (p) {
1965
+ return p.patch_id;
1966
+ });
1967
+ });
1968
+ _context2.next = 9;
1969
+ return this.api.putTree({
1970
+ patchIds: allPatches
1971
+ });
1972
+ case 9:
1973
+ data = _context2.sent;
1974
+ _context2.next = 12;
1975
+ return this.initialize();
1976
+ case 12:
1977
+ if (fp.result.isOk(data)) {
1978
+ for (_i3 = 0, _Object$keys2 = Object.keys(data.value.modules); _i3 < _Object$keys2.length; _i3++) {
1979
+ pathS = _Object$keys2[_i3];
1980
+ path = pathS;
1981
+ this.drafts[path] = data.value.modules[path].source;
1982
+ this.emitEvent(path, this.drafts[path]);
1983
+ for (_i4 = 0, _Array$from2 = Array.from(this.subscribers.entries()); _i4 < _Array$from2.length; _i4++) {
1984
+ _Array$from2$_i = _slicedToArray(_Array$from2[_i4], 2), subscriberId = _Array$from2$_i[0], subscriberModules = _Array$from2$_i[1];
1985
+ if (subscriberModules[path]) {
1986
+ this.subscribers.set(subscriberId, _objectSpread2(_objectSpread2({}, subscriberModules), {}, _defineProperty({}, path, this.drafts[path])));
1987
+ this.emitChange(subscriberId);
1988
+ }
1989
+ }
1990
+ }
1991
+ } else {
1992
+ console.error("Val: failed to reset", data.error);
1993
+ }
1994
+ case 13:
1995
+ case "end":
1996
+ return _context2.stop();
1997
+ }
1998
+ }, _callee2, this);
1999
+ }));
2096
2000
  function reset() {
2097
2001
  return _reset.apply(this, arguments);
2098
2002
  }
@@ -2101,37 +2005,37 @@ var ValStore = /*#__PURE__*/function () {
2101
2005
  }, {
2102
2006
  key: "getModule",
2103
2007
  value: function () {
2104
- var _getModule = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2(path) {
2008
+ var _getModule = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee3(path) {
2105
2009
  var refetch,
2106
2010
  data,
2107
2011
  fetchedSource,
2108
2012
  schema,
2109
- _args2 = arguments;
2110
- return _regeneratorRuntime().wrap(function _callee2$(_context2) {
2111
- while (1) switch (_context2.prev = _context2.next) {
2013
+ _args3 = arguments;
2014
+ return _regeneratorRuntime().wrap(function _callee3$(_context3) {
2015
+ while (1) switch (_context3.prev = _context3.next) {
2112
2016
  case 0:
2113
- refetch = _args2.length > 1 && _args2[1] !== undefined ? _args2[1] : false;
2017
+ refetch = _args3.length > 1 && _args3[1] !== undefined ? _args3[1] : false;
2114
2018
  if (!(!refetch && this.drafts[path] && this.schema[path])) {
2115
- _context2.next = 3;
2019
+ _context3.next = 3;
2116
2020
  break;
2117
2021
  }
2118
- return _context2.abrupt("return", fp.result.ok({
2022
+ return _context3.abrupt("return", fp.result.ok({
2119
2023
  source: this.drafts[path],
2120
2024
  schema: this.schema[path]
2121
2025
  }));
2122
2026
  case 3:
2123
- _context2.next = 5;
2027
+ _context3.next = 5;
2124
2028
  return this.api.putTree({
2125
2029
  treePath: path
2126
2030
  });
2127
2031
  case 5:
2128
- data = _context2.sent;
2032
+ data = _context3.sent;
2129
2033
  if (!fp.result.isOk(data)) {
2130
- _context2.next = 26;
2034
+ _context3.next = 26;
2131
2035
  break;
2132
2036
  }
2133
2037
  if (data.value.modules[path]) {
2134
- _context2.next = 10;
2038
+ _context3.next = 10;
2135
2039
  break;
2136
2040
  }
2137
2041
  console.error("Val: could not find the module", {
@@ -2139,65 +2043,65 @@ var ValStore = /*#__PURE__*/function () {
2139
2043
  moduleId: path,
2140
2044
  data: data
2141
2045
  });
2142
- return _context2.abrupt("return", fp.result.err({
2046
+ return _context3.abrupt("return", fp.result.err({
2143
2047
  message: "Could not fetch data.\nCould not find the module:\n" + path + "\n\nVerify that the val.modules file includes this module."
2144
2048
  }));
2145
2049
  case 10:
2146
2050
  fetchedSource = data.value.modules[path].source;
2147
2051
  schema = this.schema[path];
2148
2052
  if (this.schema[path]) {
2149
- _context2.next = 17;
2053
+ _context3.next = 17;
2150
2054
  break;
2151
2055
  }
2152
- _context2.next = 15;
2056
+ _context3.next = 15;
2153
2057
  return this.initialize();
2154
2058
  case 15:
2155
2059
  if (this.schema[path]) {
2156
- _context2.next = 17;
2060
+ _context3.next = 17;
2157
2061
  break;
2158
2062
  }
2159
- return _context2.abrupt("return", fp.result.err({
2063
+ return _context3.abrupt("return", fp.result.err({
2160
2064
  message: "Path not found in schema. Verify that the module exists."
2161
2065
  }));
2162
2066
  case 17:
2163
2067
  if (!(fetchedSource !== undefined)) {
2164
- _context2.next = 22;
2068
+ _context3.next = 22;
2165
2069
  break;
2166
2070
  }
2167
2071
  this.drafts[path] = fetchedSource;
2168
- return _context2.abrupt("return", fp.result.ok({
2072
+ return _context3.abrupt("return", fp.result.ok({
2169
2073
  source: fetchedSource,
2170
2074
  schema: schema
2171
2075
  }));
2172
2076
  case 22:
2173
2077
  console.error("Val: could not find the module source");
2174
- return _context2.abrupt("return", fp.result.err({
2078
+ return _context3.abrupt("return", fp.result.err({
2175
2079
  message: "Could not fetch data. Verify that the module exists."
2176
2080
  }));
2177
2081
  case 24:
2178
- _context2.next = 33;
2082
+ _context3.next = 33;
2179
2083
  break;
2180
2084
  case 26:
2181
2085
  if (!(data.error.statusCode === 504)) {
2182
- _context2.next = 31;
2086
+ _context3.next = 31;
2183
2087
  break;
2184
2088
  }
2185
2089
  console.error("Val: timeout", data.error);
2186
- return _context2.abrupt("return", fp.result.err({
2090
+ return _context3.abrupt("return", fp.result.err({
2187
2091
  message: "Timed out while fetching data. Try again later."
2188
2092
  }));
2189
2093
  case 31:
2190
2094
  console.error("Val: failed to get module", data.error);
2191
- return _context2.abrupt("return", fp.result.err({
2095
+ return _context3.abrupt("return", fp.result.err({
2192
2096
  message: "Could not fetch data. Verify that Val is correctly configured."
2193
2097
  }));
2194
2098
  case 33:
2195
2099
  case "end":
2196
- return _context2.stop();
2100
+ return _context3.stop();
2197
2101
  }
2198
- }, _callee2, this);
2102
+ }, _callee3, this);
2199
2103
  }));
2200
- function getModule(_x) {
2104
+ function getModule(_x2) {
2201
2105
  return _getModule.apply(this, arguments);
2202
2106
  }
2203
2107
  return getModule;
@@ -2205,12 +2109,12 @@ var ValStore = /*#__PURE__*/function () {
2205
2109
  }, {
2206
2110
  key: "applyPatch",
2207
2111
  value: function () {
2208
- var _applyPatch = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee3(path, patchIds, patch) {
2209
- var data, fetchedSource, _data$value$modules$p, _i3, _Array$from2, _Array$from2$_i, subscriberId, subscriberModules;
2210
- return _regeneratorRuntime().wrap(function _callee3$(_context3) {
2211
- while (1) switch (_context3.prev = _context3.next) {
2112
+ var _applyPatch = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee4(path, patchIds, patch) {
2113
+ var data, fetchedSource, _data$value$modules$p, _i5, _Array$from3, _Array$from3$_i, subscriberId, subscriberModules;
2114
+ return _regeneratorRuntime().wrap(function _callee4$(_context4) {
2115
+ while (1) switch (_context4.prev = _context4.next) {
2212
2116
  case 0:
2213
- _context3.next = 2;
2117
+ _context4.next = 2;
2214
2118
  return this.api.putTree({
2215
2119
  treePath: path,
2216
2120
  patchIds: patchIds,
@@ -2220,48 +2124,48 @@ var ValStore = /*#__PURE__*/function () {
2220
2124
  }
2221
2125
  });
2222
2126
  case 2:
2223
- data = _context3.sent;
2127
+ data = _context4.sent;
2224
2128
  if (!fp.result.isOk(data)) {
2225
- _context3.next = 16;
2129
+ _context4.next = 16;
2226
2130
  break;
2227
2131
  }
2228
2132
  fetchedSource = data.value.modules[path].source;
2229
2133
  if (!(fetchedSource !== undefined)) {
2230
- _context3.next = 12;
2134
+ _context4.next = 12;
2231
2135
  break;
2232
2136
  }
2233
2137
  this.drafts[path] = fetchedSource;
2234
2138
  this.emitEvent(path, fetchedSource);
2235
- for (_i3 = 0, _Array$from2 = Array.from(this.subscribers.entries()); _i3 < _Array$from2.length; _i3++) {
2236
- _Array$from2$_i = _slicedToArray(_Array$from2[_i3], 2), subscriberId = _Array$from2$_i[0], subscriberModules = _Array$from2$_i[1];
2139
+ for (_i5 = 0, _Array$from3 = Array.from(this.subscribers.entries()); _i5 < _Array$from3.length; _i5++) {
2140
+ _Array$from3$_i = _slicedToArray(_Array$from3[_i5], 2), subscriberId = _Array$from3$_i[0], subscriberModules = _Array$from3$_i[1];
2237
2141
  if (subscriberModules[path]) {
2238
2142
  this.subscribers.set(subscriberId, _objectSpread2(_objectSpread2({}, subscriberModules), {}, _defineProperty({}, path, this.drafts[path])));
2239
2143
  this.emitChange(subscriberId);
2240
2144
  }
2241
2145
  }
2242
- return _context3.abrupt("return", fp.result.ok(_defineProperty({}, path, {
2146
+ return _context4.abrupt("return", fp.result.ok(_defineProperty({}, path, {
2243
2147
  patchIds: ((_data$value$modules$p = data.value.modules[path].patches) === null || _data$value$modules$p === void 0 ? void 0 : _data$value$modules$p.applied) || []
2244
2148
  })));
2245
2149
  case 12:
2246
2150
  console.error("Val: could not patch");
2247
- return _context3.abrupt("return", fp.result.err({
2151
+ return _context4.abrupt("return", fp.result.err({
2248
2152
  message: "Val: could not fetch data. Verify that the module exists."
2249
2153
  }));
2250
2154
  case 14:
2251
- _context3.next = 18;
2155
+ _context4.next = 18;
2252
2156
  break;
2253
2157
  case 16:
2254
2158
  console.error("Val: failed to get module", data.error);
2255
- return _context3.abrupt("return", fp.result.err({
2159
+ return _context4.abrupt("return", fp.result.err({
2256
2160
  message: "Val: could not fetch data. Verify that Val is correctly configured."
2257
2161
  }));
2258
2162
  case 18:
2259
2163
  case "end":
2260
- return _context3.stop();
2164
+ return _context4.stop();
2261
2165
  }
2262
- }, _callee3, this);
2166
+ }, _callee4, this);
2263
2167
  }));
2264
- function applyPatch(_x2, _x3, _x4) {
2168
+ function applyPatch(_x3, _x4, _x5) {
2265
2169
  return _applyPatch.apply(this, arguments);
2266
2170
  }
2267
2171
  return applyPatch;
@@ -2281,29 +2185,29 @@ var ValStore = /*#__PURE__*/function () {
2281
2185
  }, {
2282
2186
  key: "initialize",
2283
2187
  value: function () {
2284
- var _initialize = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee4() {
2285
- var data, paths, _i4, _arr, moduleId, schema, msg;
2286
- return _regeneratorRuntime().wrap(function _callee4$(_context4) {
2287
- while (1) switch (_context4.prev = _context4.next) {
2188
+ var _initialize = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee5() {
2189
+ var data, paths, _i6, _arr, moduleId, schema, msg;
2190
+ return _regeneratorRuntime().wrap(function _callee5$(_context5) {
2191
+ while (1) switch (_context5.prev = _context5.next) {
2288
2192
  case 0:
2289
- _context4.next = 2;
2193
+ _context5.next = 2;
2290
2194
  return this.api.getSchema({});
2291
2195
  case 2:
2292
- data = _context4.sent;
2196
+ data = _context5.sent;
2293
2197
  if (!fp.result.isOk(data)) {
2294
- _context4.next = 9;
2198
+ _context5.next = 9;
2295
2199
  break;
2296
2200
  }
2297
2201
  paths = [];
2298
- for (_i4 = 0, _arr = Object.keys(data.value.schemas); _i4 < _arr.length; _i4++) {
2299
- moduleId = _arr[_i4];
2202
+ for (_i6 = 0, _arr = Object.keys(data.value.schemas); _i6 < _arr.length; _i6++) {
2203
+ moduleId = _arr[_i6];
2300
2204
  schema = data.value.schemas[moduleId];
2301
2205
  if (schema) {
2302
2206
  paths.push(moduleId);
2303
2207
  this.schema[moduleId] = schema;
2304
2208
  }
2305
2209
  }
2306
- return _context4.abrupt("return", fp.result.ok(paths));
2210
+ return _context5.abrupt("return", fp.result.ok(paths));
2307
2211
  case 9:
2308
2212
  msg = "Failed to fetch content. ";
2309
2213
  if (data.error.statusCode === 401) {
@@ -2311,7 +2215,7 @@ var ValStore = /*#__PURE__*/function () {
2311
2215
  } else {
2312
2216
  msg += "Get a developer to verify that Val is correctly setup.";
2313
2217
  }
2314
- return _context4.abrupt("return", fp.result.err({
2218
+ return _context5.abrupt("return", fp.result.err({
2315
2219
  message: msg,
2316
2220
  details: {
2317
2221
  fetchError: data.error
@@ -2319,9 +2223,9 @@ var ValStore = /*#__PURE__*/function () {
2319
2223
  }));
2320
2224
  case 12:
2321
2225
  case "end":
2322
- return _context4.stop();
2226
+ return _context5.stop();
2323
2227
  }
2324
- }, _callee4, this);
2228
+ }, _callee5, this);
2325
2229
  }));
2326
2230
  function initialize() {
2327
2231
  return _initialize.apply(this, arguments);
@@ -2371,6 +2275,5 @@ exports.ValStore = ValStore;
2371
2275
  exports.filenameToMimeType = filenameToMimeType;
2372
2276
  exports.getMimeType = getMimeType;
2373
2277
  exports.mimeTypeToFileExt = mimeTypeToFileExt;
2374
- exports.parseRichTextSource = parseRichTextSource;
2375
2278
  exports.remirrorToRichTextSource = remirrorToRichTextSource;
2376
2279
  exports.richTextToRemirror = richTextToRemirror;