@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.
- package/dist/declarations/src/internal/ValStore.d.ts +1 -0
- package/dist/declarations/src/internal/richtext/conversion/index.d.ts +0 -1
- package/dist/declarations/src/internal/richtext/conversion/remirrorToRichTextSource.d.ts +7 -3
- package/dist/declarations/src/internal/richtext/conversion/remirrorTypes.d.ts +212 -934
- package/dist/declarations/src/internal/richtext/conversion/richTextToRemirror.d.ts +2 -2
- package/internal/dist/valbuild-shared-internal.cjs.dev.js +408 -505
- package/internal/dist/valbuild-shared-internal.cjs.prod.js +408 -505
- package/internal/dist/valbuild-shared-internal.esm.js +410 -486
- package/package.json +2 -2
- package/dist/declarations/src/internal/richtext/conversion/parseRichTextSource.d.ts +0 -2
@@ -1,5 +1,4 @@
|
|
1
|
-
import {
|
2
|
-
import * as marked from 'marked';
|
1
|
+
import { Internal, VAL_EXTENSION, FILE_REF_PROP } from '@valbuild/core';
|
3
2
|
import { z } from 'zod';
|
4
3
|
import { result } from '@valbuild/core/fp';
|
5
4
|
|
@@ -34,6 +33,28 @@ function _defineProperty(obj, key, value) {
|
|
34
33
|
return obj;
|
35
34
|
}
|
36
35
|
|
36
|
+
function ownKeys(e, r) {
|
37
|
+
var t = Object.keys(e);
|
38
|
+
if (Object.getOwnPropertySymbols) {
|
39
|
+
var o = Object.getOwnPropertySymbols(e);
|
40
|
+
r && (o = o.filter(function (r) {
|
41
|
+
return Object.getOwnPropertyDescriptor(e, r).enumerable;
|
42
|
+
})), t.push.apply(t, o);
|
43
|
+
}
|
44
|
+
return t;
|
45
|
+
}
|
46
|
+
function _objectSpread2(e) {
|
47
|
+
for (var r = 1; r < arguments.length; r++) {
|
48
|
+
var t = null != arguments[r] ? arguments[r] : {};
|
49
|
+
r % 2 ? ownKeys(Object(t), !0).forEach(function (r) {
|
50
|
+
_defineProperty(e, r, t[r]);
|
51
|
+
}) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) {
|
52
|
+
Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r));
|
53
|
+
});
|
54
|
+
}
|
55
|
+
return e;
|
56
|
+
}
|
57
|
+
|
37
58
|
function _arrayLikeToArray(arr, len) {
|
38
59
|
if (len == null || len > arr.length) len = arr.length;
|
39
60
|
for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i];
|
@@ -101,22 +122,6 @@ function _createForOfIteratorHelper(o, allowArrayLike) {
|
|
101
122
|
};
|
102
123
|
}
|
103
124
|
|
104
|
-
function _arrayWithoutHoles(arr) {
|
105
|
-
if (Array.isArray(arr)) return _arrayLikeToArray(arr);
|
106
|
-
}
|
107
|
-
|
108
|
-
function _iterableToArray(iter) {
|
109
|
-
if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter);
|
110
|
-
}
|
111
|
-
|
112
|
-
function _nonIterableSpread() {
|
113
|
-
throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
|
114
|
-
}
|
115
|
-
|
116
|
-
function _toConsumableArray(arr) {
|
117
|
-
return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread();
|
118
|
-
}
|
119
|
-
|
120
125
|
function _arrayWithHoles(arr) {
|
121
126
|
if (Array.isArray(arr)) return arr;
|
122
127
|
}
|
@@ -881,184 +886,183 @@ function filenameToMimeType(filename) {
|
|
881
886
|
|
882
887
|
function remirrorToRichTextSource(node) {
|
883
888
|
var files = {};
|
884
|
-
var
|
885
|
-
|
886
|
-
|
887
|
-
|
889
|
+
var blocks = [];
|
890
|
+
var i = 0;
|
891
|
+
var _iterator = _createForOfIteratorHelper(node.content),
|
892
|
+
_step;
|
893
|
+
try {
|
894
|
+
for (_iterator.s(); !(_step = _iterator.n()).done;) {
|
895
|
+
var child = _step.value;
|
896
|
+
var block = convertBlock([(i++).toString()], child, files);
|
897
|
+
blocks.push(block);
|
898
|
+
}
|
899
|
+
} catch (err) {
|
900
|
+
_iterator.e(err);
|
901
|
+
} finally {
|
902
|
+
_iterator.f();
|
903
|
+
}
|
904
|
+
return {
|
905
|
+
blocks: blocks,
|
906
|
+
files: files
|
907
|
+
};
|
888
908
|
}
|
889
|
-
function
|
909
|
+
function convertBlock(path, node, files) {
|
890
910
|
if (node.type === "heading") {
|
891
911
|
var _node$attrs, _node$content;
|
892
|
-
var headingTag = "";
|
893
912
|
var depth = ((_node$attrs = node.attrs) === null || _node$attrs === void 0 ? void 0 : _node$attrs.level) || 1;
|
894
913
|
if (Number.isNaN(depth)) {
|
895
914
|
throw new Error("Invalid header depth");
|
896
915
|
}
|
897
|
-
for (var i = 0; i < Number(depth); i++) {
|
898
|
-
headingTag += "#";
|
899
|
-
}
|
900
|
-
var headingText = ["".concat(headingTag, " ")];
|
901
916
|
return {
|
902
|
-
|
903
|
-
children:
|
904
|
-
return
|
905
|
-
})) || []))
|
906
|
-
};
|
907
|
-
} else if (node.type === "paragraph") {
|
908
|
-
var _node$content2;
|
909
|
-
if (!node.content || ((_node$content2 = node.content) === null || _node$content2 === void 0 ? void 0 : _node$content2.length) === 0) {
|
910
|
-
return {
|
911
|
-
type: "block",
|
912
|
-
children: ["<br />"]
|
913
|
-
};
|
914
|
-
}
|
915
|
-
return {
|
916
|
-
type: "block",
|
917
|
-
children: node.content.map(function (child) {
|
918
|
-
return transformLeafNode(child, files);
|
919
|
-
})
|
920
|
-
};
|
921
|
-
} else if (node.type === "bulletList" || node.type === "orderedList") {
|
922
|
-
var _node$content3;
|
923
|
-
return {
|
924
|
-
type: "block",
|
925
|
-
children: ((_node$content3 = node.content) === null || _node$content3 === void 0 ? void 0 : _node$content3.flatMap(function (child, i) {
|
926
|
-
return formatListItemNode(getListPrefix(node), child, 0, files, i === 0);
|
917
|
+
tag: "h".concat(depth),
|
918
|
+
children: ((_node$content = node.content) === null || _node$content === void 0 ? void 0 : _node$content.map(function (child, i) {
|
919
|
+
return convertHeadingChild(path.concat("children", i.toString()), child, files);
|
927
920
|
})) || []
|
928
921
|
};
|
922
|
+
} else if (node.type === "paragraph") {
|
923
|
+
return convertParagraph(path, node, files);
|
924
|
+
} else if (node.type === "bulletList") {
|
925
|
+
return convertBulletList(path, node, files);
|
926
|
+
} else if (node.type === "orderedList") {
|
927
|
+
return convertOrderedList(path, node, files);
|
929
928
|
} else {
|
930
929
|
var exhaustiveCheck = node;
|
931
930
|
throw new Error("Unhandled node type: ".concat("type" in exhaustiveCheck ? "exhaustiveCheck.type" : "unknown"));
|
932
931
|
}
|
933
932
|
}
|
934
|
-
function
|
935
|
-
|
936
|
-
|
937
|
-
|
938
|
-
|
939
|
-
|
940
|
-
|
941
|
-
|
942
|
-
|
943
|
-
|
944
|
-
|
945
|
-
|
946
|
-
} else {
|
947
|
-
if (child._type === "file") {
|
948
|
-
exprs.push(child);
|
949
|
-
} else if (child._type === "link") {
|
950
|
-
exprs.push(child);
|
951
|
-
} else {
|
952
|
-
var exhaustiveCheck = child;
|
953
|
-
throw new Error("Unexpected node type: ".concat(JSON.stringify(exhaustiveCheck, null, 2)));
|
954
|
-
}
|
955
|
-
templateStrings.push("");
|
956
|
-
}
|
957
|
-
}
|
958
|
-
} catch (err) {
|
959
|
-
_iterator.e(err);
|
960
|
-
} finally {
|
961
|
-
_iterator.f();
|
962
|
-
}
|
963
|
-
if (blockIdx === markdownIRBlocks.length - 1) {
|
964
|
-
templateStrings[templateStrings.length - 1] += "\n";
|
965
|
-
} else {
|
966
|
-
templateStrings[templateStrings.length - 1] += "\n\n";
|
967
|
-
}
|
933
|
+
function convertHeadingChild(path, node, files) {
|
934
|
+
if (node.type === "text") {
|
935
|
+
return convertTextNode(node);
|
936
|
+
} else if (node.type === "hardBreak") {
|
937
|
+
return {
|
938
|
+
tag: "br"
|
939
|
+
};
|
940
|
+
} else if (node.type === "image") {
|
941
|
+
return convertImageNode(path, node, files);
|
942
|
+
} else {
|
943
|
+
var exhaustiveCheck = node;
|
944
|
+
throw new Error("Unexpected heading child type: ".concat(JSON.stringify(exhaustiveCheck, null, 2)));
|
968
945
|
}
|
969
|
-
return _defineProperty(_defineProperty(_defineProperty(_defineProperty({}, VAL_EXTENSION, "richtext"), "templateStrings", templateStrings), "exprs", exprs), "files", files);
|
970
946
|
}
|
971
|
-
function
|
972
|
-
var
|
973
|
-
|
974
|
-
|
975
|
-
|
976
|
-
|
977
|
-
|
978
|
-
|
979
|
-
|
980
|
-
|
981
|
-
|
982
|
-
|
983
|
-
|
984
|
-
|
985
|
-
|
986
|
-
|
987
|
-
|
988
|
-
|
989
|
-
} else if (classes.includes("bold")) {
|
990
|
-
text = "**".concat(text, "**");
|
991
|
-
} else if (classes.includes("italic")) {
|
992
|
-
text = "_".concat(text, "_");
|
993
|
-
}
|
994
|
-
if (classes.includes("line-through")) {
|
995
|
-
text = "~~".concat(text, "~~");
|
996
|
-
}
|
997
|
-
// TODO:
|
998
|
-
// text = splitIntoChunks(text);
|
999
|
-
return "".concat(" ".repeat(prefixWS)).concat(text).concat(" ".repeat(suffixWS));
|
947
|
+
function convertParagraph(path, child, files) {
|
948
|
+
var _child$content;
|
949
|
+
return {
|
950
|
+
tag: "p",
|
951
|
+
children: ((_child$content = child.content) === null || _child$content === void 0 ? void 0 : _child$content.map(function (child, i) {
|
952
|
+
if (child.type === "text") {
|
953
|
+
return convertTextNode(child);
|
954
|
+
} else if (child.type === "hardBreak") {
|
955
|
+
return {
|
956
|
+
tag: "br"
|
957
|
+
};
|
958
|
+
} else if (child.type === "image") {
|
959
|
+
return convertImageNode(path.concat("children", i.toString()), child, files);
|
960
|
+
}
|
961
|
+
var exhaustiveCheck = child;
|
962
|
+
throw new Error("Unexpected paragraph child type: ".concat(JSON.stringify(exhaustiveCheck, null, 2)));
|
963
|
+
})) || []
|
964
|
+
};
|
1000
965
|
}
|
1001
|
-
function
|
966
|
+
function convertTextNode(node) {
|
1002
967
|
if (node.type === "text") {
|
1003
|
-
var _node$marks2;
|
1004
|
-
var
|
968
|
+
var _node$marks, _node$marks2;
|
969
|
+
var styles = ((_node$marks = node.marks) === null || _node$marks === void 0 ? void 0 : _node$marks.flatMap(function (mark) {
|
970
|
+
if (mark.type !== "link") {
|
971
|
+
if (mark.type === "strike") {
|
972
|
+
return ["line-through"];
|
973
|
+
}
|
974
|
+
return [mark.type];
|
975
|
+
} else {
|
976
|
+
return [];
|
977
|
+
}
|
978
|
+
})) || [];
|
979
|
+
if ((_node$marks2 = node.marks) !== null && _node$marks2 !== void 0 && _node$marks2.some(function (mark) {
|
1005
980
|
return mark.type === "link";
|
1006
|
-
})
|
1007
|
-
|
981
|
+
})) {
|
982
|
+
var _node$marks$find2;
|
983
|
+
if (styles.length > 0) {
|
984
|
+
var _node$marks$find;
|
985
|
+
return {
|
986
|
+
tag: "a",
|
987
|
+
href: ((_node$marks$find = node.marks.find(function (mark) {
|
988
|
+
return mark.type === "link";
|
989
|
+
})) === null || _node$marks$find === void 0 ? void 0 : _node$marks$find.attrs.href) || "",
|
990
|
+
children: [{
|
991
|
+
tag: "span",
|
992
|
+
styles: styles,
|
993
|
+
children: [node.text]
|
994
|
+
}]
|
995
|
+
};
|
996
|
+
}
|
1008
997
|
return {
|
1009
|
-
|
1010
|
-
href:
|
1011
|
-
|
998
|
+
tag: "a",
|
999
|
+
href: ((_node$marks$find2 = node.marks.find(function (mark) {
|
1000
|
+
return mark.type === "link";
|
1001
|
+
})) === null || _node$marks$find2 === void 0 ? void 0 : _node$marks$find2.attrs.href) || "",
|
1002
|
+
children: [node.text]
|
1012
1003
|
};
|
1013
1004
|
}
|
1014
|
-
|
1015
|
-
|
1016
|
-
|
1017
|
-
|
1018
|
-
|
1005
|
+
if (styles.length > 0) {
|
1006
|
+
return {
|
1007
|
+
tag: "span",
|
1008
|
+
styles: styles,
|
1009
|
+
children: [node.text]
|
1010
|
+
};
|
1011
|
+
}
|
1012
|
+
return node.text;
|
1019
1013
|
} else {
|
1020
|
-
var exhaustiveCheck = node;
|
1021
|
-
throw new Error("Unexpected node type: ".concat(
|
1014
|
+
var exhaustiveCheck = node.type;
|
1015
|
+
throw new Error("Unexpected node type: ".concat(exhaustiveCheck));
|
1022
1016
|
}
|
1023
1017
|
}
|
1024
|
-
function
|
1025
|
-
var
|
1026
|
-
|
1027
|
-
|
1028
|
-
|
1029
|
-
|
1030
|
-
|
1031
|
-
|
1032
|
-
|
1033
|
-
|
1034
|
-
|
1035
|
-
|
1036
|
-
|
1037
|
-
|
1038
|
-
|
1039
|
-
|
1040
|
-
|
1041
|
-
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) {
|
1042
|
-
res.push("<br />\n");
|
1043
|
-
}
|
1044
|
-
res.push(transformLeafNode(subChild, files));
|
1045
|
-
return res;
|
1046
|
-
});
|
1047
|
-
}
|
1048
|
-
}));
|
1018
|
+
function convertListItem(path, child, files) {
|
1019
|
+
var _child$content2;
|
1020
|
+
return {
|
1021
|
+
tag: "li",
|
1022
|
+
children: ((_child$content2 = child.content) === null || _child$content2 === void 0 ? void 0 : _child$content2.map(function (child, i) {
|
1023
|
+
if (child.type === "paragraph") {
|
1024
|
+
return convertParagraph(path.concat("children", i.toString()), child, files);
|
1025
|
+
} else if (child.type === "bulletList") {
|
1026
|
+
return convertBulletList(path.concat("children", i.toString()), child, files);
|
1027
|
+
} else if (child.type === "orderedList") {
|
1028
|
+
return convertOrderedList(path.concat("children", i.toString()), child, files);
|
1029
|
+
} else {
|
1030
|
+
var exhaustiveCheck = child;
|
1031
|
+
throw new Error("Unexpected list child type: ".concat(exhaustiveCheck));
|
1032
|
+
}
|
1033
|
+
})) || []
|
1034
|
+
};
|
1049
1035
|
}
|
1050
|
-
function
|
1051
|
-
|
1052
|
-
|
1053
|
-
|
1054
|
-
|
1055
|
-
|
1056
|
-
|
1057
|
-
|
1058
|
-
|
1036
|
+
function convertBulletList(path, node, files) {
|
1037
|
+
var _node$content2;
|
1038
|
+
return {
|
1039
|
+
tag: "ul",
|
1040
|
+
children: ((_node$content2 = node.content) === null || _node$content2 === void 0 ? void 0 : _node$content2.map(function (child, i) {
|
1041
|
+
if (child.type === "listItem") {
|
1042
|
+
return convertListItem(path.concat("children", i.toString()), child, files);
|
1043
|
+
} else {
|
1044
|
+
var exhaustiveCheck = child.type;
|
1045
|
+
throw new Error("Unexpected bullet list child type: ".concat(exhaustiveCheck));
|
1046
|
+
}
|
1047
|
+
})) || []
|
1048
|
+
};
|
1049
|
+
}
|
1050
|
+
function convertOrderedList(path, node, files) {
|
1051
|
+
var _node$content3;
|
1052
|
+
return {
|
1053
|
+
tag: "ol",
|
1054
|
+
children: ((_node$content3 = node.content) === null || _node$content3 === void 0 ? void 0 : _node$content3.map(function (child, i) {
|
1055
|
+
if (child.type === "listItem") {
|
1056
|
+
return convertListItem(path.concat("children", i.toString()), child, files);
|
1057
|
+
} else {
|
1058
|
+
var exhaustiveCheck = child.type;
|
1059
|
+
throw new Error("Unexpected ordered list child type: ".concat(exhaustiveCheck));
|
1060
|
+
}
|
1061
|
+
})) || []
|
1062
|
+
};
|
1059
1063
|
}
|
1060
1064
|
var textEncoder = new TextEncoder();
|
1061
|
-
function
|
1065
|
+
function convertImageNode(path, node, files) {
|
1062
1066
|
if (node.attrs && node.attrs.src.startsWith("data:")) {
|
1063
1067
|
var sha256 = Internal.getSHA256Hash(textEncoder.encode(node.attrs.src));
|
1064
1068
|
var mimeType = getMimeType(node.attrs.src);
|
@@ -1068,22 +1072,43 @@ function fromRemirrorImageNode(node, files) {
|
|
1068
1072
|
var fileExt = mimeTypeToFileExt(mimeType);
|
1069
1073
|
var fileName = node.attrs.fileName || "".concat(sha256, ".").concat(fileExt);
|
1070
1074
|
var filePath = "/public/".concat(fileName);
|
1071
|
-
files[filePath]
|
1072
|
-
|
1073
|
-
|
1074
|
-
|
1075
|
-
|
1076
|
-
|
1077
|
-
}
|
1075
|
+
var existingFilesEntry = files[filePath];
|
1076
|
+
var thisPath = path
|
1077
|
+
// file is added as src (see below):
|
1078
|
+
.concat("src");
|
1079
|
+
if (existingFilesEntry) {
|
1080
|
+
existingFilesEntry.patchPaths.push(thisPath);
|
1081
|
+
} else {
|
1082
|
+
files[filePath] = {
|
1083
|
+
value: node.attrs.src,
|
1084
|
+
patchPaths: [thisPath]
|
1085
|
+
};
|
1086
|
+
}
|
1087
|
+
return {
|
1088
|
+
tag: "img",
|
1089
|
+
src: _defineProperty(_defineProperty(_defineProperty({}, VAL_EXTENSION, "file"), FILE_REF_PROP, filePath), "metadata", {
|
1090
|
+
width: typeof node.attrs.width === "number" ? node.attrs.width : 0,
|
1091
|
+
height: typeof node.attrs.height === "number" ? node.attrs.height : 0,
|
1092
|
+
sha256: sha256 || "",
|
1093
|
+
mimeType: mimeType
|
1094
|
+
})
|
1095
|
+
};
|
1078
1096
|
} else if (node.attrs) {
|
1079
1097
|
var _sha = getParam("sha256", node.attrs.src);
|
1098
|
+
var patchId = getParam("patch_id", node.attrs.src);
|
1080
1099
|
var noParamsSrc = node.attrs.src.split("?")[0];
|
1081
|
-
|
1082
|
-
|
1083
|
-
|
1084
|
-
|
1085
|
-
|
1086
|
-
|
1100
|
+
var tag = {
|
1101
|
+
tag: "img",
|
1102
|
+
src: _objectSpread2(_defineProperty(_defineProperty(_defineProperty({}, VAL_EXTENSION, "file"), FILE_REF_PROP, "/public".concat(node.attrs.src.split("?")[0])), "metadata", {
|
1103
|
+
width: typeof node.attrs.width === "number" ? node.attrs.width : 0,
|
1104
|
+
height: typeof node.attrs.height === "number" ? node.attrs.height : 0,
|
1105
|
+
sha256: _sha || "",
|
1106
|
+
mimeType: noParamsSrc && filenameToMimeType(noParamsSrc) || ""
|
1107
|
+
}), patchId ? {
|
1108
|
+
patch_id: patchId
|
1109
|
+
} : {})
|
1110
|
+
};
|
1111
|
+
return tag;
|
1087
1112
|
} else {
|
1088
1113
|
throw new Error("Invalid image node (no attrs): " + JSON.stringify(node));
|
1089
1114
|
}
|
@@ -1101,188 +1126,6 @@ function getParam(param, url) {
|
|
1101
1126
|
return undefined;
|
1102
1127
|
}
|
1103
1128
|
|
1104
|
-
var VAL_START_TAG_PREFIX = '<val value="';
|
1105
|
-
var VAL_START_TAG_SUFFIX = '">';
|
1106
|
-
var VAL_END_TAG = "</val>";
|
1107
|
-
function parseTokens(tokens, sourceNodes, cursor) {
|
1108
|
-
var insideList = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : false;
|
1109
|
-
var children = [];
|
1110
|
-
function merge(token, clazz) {
|
1111
|
-
var parsedTokens = parseTokens(token.tokens ? token.tokens : [], sourceNodes, 0);
|
1112
|
-
children.push({
|
1113
|
-
tag: "span",
|
1114
|
-
classes: [clazz].concat(parsedTokens.children.flatMap(function (child) {
|
1115
|
-
return typeof child === "string" ? [] : child.classes;
|
1116
|
-
})),
|
1117
|
-
children: parsedTokens.children.flatMap(function (child) {
|
1118
|
-
return typeof child === "string" ? child : child.children;
|
1119
|
-
})
|
1120
|
-
});
|
1121
|
-
}
|
1122
|
-
var _loop = function _loop() {
|
1123
|
-
var token = tokens[cursor];
|
1124
|
-
if (token.type === "heading") {
|
1125
|
-
children.push({
|
1126
|
-
tag: "h".concat(token.depth),
|
1127
|
-
children: parseTokens(token.tokens ? token.tokens : [], sourceNodes, 0).children
|
1128
|
-
});
|
1129
|
-
} else if (token.type === "paragraph") {
|
1130
|
-
children.push({
|
1131
|
-
tag: "p",
|
1132
|
-
children: parseTokens(token.tokens ? token.tokens : [], sourceNodes, 0).children
|
1133
|
-
});
|
1134
|
-
} else if (token.type === "strong") {
|
1135
|
-
merge(token, "bold");
|
1136
|
-
} else if (token.type === "em") {
|
1137
|
-
merge(token, "italic");
|
1138
|
-
} else if (token.type === "del") {
|
1139
|
-
merge(token, "line-through");
|
1140
|
-
} else if (token.type === "text") {
|
1141
|
-
if ("tokens" in token && Array.isArray(token.tokens)) {
|
1142
|
-
children.push.apply(children, _toConsumableArray(parseTokens(token.tokens, sourceNodes, cursor, insideList).children));
|
1143
|
-
} else {
|
1144
|
-
if (insideList && typeof token.raw === "string") {
|
1145
|
-
var lines = token.raw.split("\n");
|
1146
|
-
var tags = lines.flatMap(function (line, i) {
|
1147
|
-
if (i === lines.length - 1) return [line];
|
1148
|
-
if (i === lines.length - 1 && line === "") return [];
|
1149
|
-
if (line === "") return {
|
1150
|
-
tag: "br"
|
1151
|
-
};
|
1152
|
-
return [line, {
|
1153
|
-
tag: "br"
|
1154
|
-
}];
|
1155
|
-
});
|
1156
|
-
children.push.apply(children, _toConsumableArray(tags));
|
1157
|
-
} else {
|
1158
|
-
children.push(token.raw);
|
1159
|
-
}
|
1160
|
-
}
|
1161
|
-
} else if (token.type === "list") {
|
1162
|
-
children.push({
|
1163
|
-
tag: token.ordered ? "ol" : "ul",
|
1164
|
-
children: parseTokens(token.items, sourceNodes, 0).children
|
1165
|
-
});
|
1166
|
-
} else if (token.type === "list_item") {
|
1167
|
-
children.push({
|
1168
|
-
tag: "li",
|
1169
|
-
children: parseTokens(token.tokens ? token.tokens : [], sourceNodes, 0, true).children
|
1170
|
-
});
|
1171
|
-
} else if (token.type === "space") ; else if (token.type === "html") {
|
1172
|
-
if (token.text === VAL_END_TAG) {
|
1173
|
-
return {
|
1174
|
-
v: {
|
1175
|
-
children: children,
|
1176
|
-
cursor: cursor
|
1177
|
-
}
|
1178
|
-
};
|
1179
|
-
}
|
1180
|
-
var suffixIndex = token.text.indexOf(VAL_START_TAG_SUFFIX);
|
1181
|
-
if (token.text.startsWith(VAL_START_TAG_PREFIX) && suffixIndex > -1) {
|
1182
|
-
var number = Number(token.text.slice(VAL_START_TAG_PREFIX.length, suffixIndex));
|
1183
|
-
if (Number.isNaN(number)) {
|
1184
|
-
throw Error("Illegal val intermediate node: ".concat(JSON.stringify(token)));
|
1185
|
-
}
|
1186
|
-
var _parseTokens = parseTokens(tokens.map(function (token) {
|
1187
|
-
if (token.type === "link" || token.type === "list") {
|
1188
|
-
return {
|
1189
|
-
type: "text",
|
1190
|
-
raw: token.raw,
|
1191
|
-
text: token.raw
|
1192
|
-
};
|
1193
|
-
}
|
1194
|
-
return token;
|
1195
|
-
}), sourceNodes, cursor + 1),
|
1196
|
-
subChildren = _parseTokens.children,
|
1197
|
-
subCursor = _parseTokens.cursor;
|
1198
|
-
var sourceNode = sourceNodes[number];
|
1199
|
-
if (sourceNode._type === "link") {
|
1200
|
-
children.push({
|
1201
|
-
tag: "a",
|
1202
|
-
href: sourceNode.href,
|
1203
|
-
children: subChildren
|
1204
|
-
});
|
1205
|
-
} else if (sourceNode._type === "file") {
|
1206
|
-
var _sourceNode$metadata, _sourceNode$metadata2, _sourceNode$metadata3;
|
1207
|
-
children.push({
|
1208
|
-
tag: "img",
|
1209
|
-
src: Internal.convertFileSource(sourceNode).url,
|
1210
|
-
width: (_sourceNode$metadata = sourceNode.metadata) === null || _sourceNode$metadata === void 0 ? void 0 : _sourceNode$metadata.width,
|
1211
|
-
height: (_sourceNode$metadata2 = sourceNode.metadata) === null || _sourceNode$metadata2 === void 0 ? void 0 : _sourceNode$metadata2.height,
|
1212
|
-
mimeType: (_sourceNode$metadata3 = sourceNode.metadata) === null || _sourceNode$metadata3 === void 0 ? void 0 : _sourceNode$metadata3.mimeType
|
1213
|
-
});
|
1214
|
-
}
|
1215
|
-
cursor = subCursor;
|
1216
|
-
}
|
1217
|
-
var br_html_regex = /<br\s*\/?>/gi; // matches <br>, <br/>, <br />; case insensitive
|
1218
|
-
if (token.text.trim().match(br_html_regex)) {
|
1219
|
-
var _tokens;
|
1220
|
-
children.push({
|
1221
|
-
tag: "br"
|
1222
|
-
});
|
1223
|
-
if (((_tokens = tokens[cursor + 1]) === null || _tokens === void 0 ? void 0 : _tokens.raw.trim()) === "") {
|
1224
|
-
// if next token is a new line or white-spaces, skip it
|
1225
|
-
// this typically means we have a <br> AND a new line, which, semantically, is just a <br>
|
1226
|
-
cursor++;
|
1227
|
-
}
|
1228
|
-
}
|
1229
|
-
} else if (token.type === "link") {
|
1230
|
-
if (token.raw === token.href) {
|
1231
|
-
// avoid auto-linking (provided by github flavoured markdown, but we want strikethrough so keep it enabled)
|
1232
|
-
children.push(token.raw);
|
1233
|
-
} else {
|
1234
|
-
children.push({
|
1235
|
-
tag: "a",
|
1236
|
-
href: token.href,
|
1237
|
-
children: parseTokens(token.tokens ? token.tokens : [], sourceNodes, 0).children
|
1238
|
-
});
|
1239
|
-
}
|
1240
|
-
} else if (token.type === "br") {
|
1241
|
-
children.push({
|
1242
|
-
tag: "br"
|
1243
|
-
});
|
1244
|
-
} else {
|
1245
|
-
console.error("Could not parse markdown: unsupported token type: ".concat(token.type, ". Found: ").concat(token.raw));
|
1246
|
-
}
|
1247
|
-
cursor++;
|
1248
|
-
},
|
1249
|
-
_ret;
|
1250
|
-
while (cursor < tokens.length) {
|
1251
|
-
_ret = _loop();
|
1252
|
-
if (_ret) return _ret.v;
|
1253
|
-
}
|
1254
|
-
return {
|
1255
|
-
children: children,
|
1256
|
-
cursor: cursor
|
1257
|
-
};
|
1258
|
-
}
|
1259
|
-
function parseRichTextSource(_ref) {
|
1260
|
-
var templateStrings = _ref.templateStrings,
|
1261
|
-
nodes = _ref.exprs;
|
1262
|
-
// TODO: validate that templateStrings does not contain VAL_NODE_PREFIX
|
1263
|
-
var inputText = templateStrings.flatMap(function (templateString, i) {
|
1264
|
-
var node = nodes[i];
|
1265
|
-
if (node) {
|
1266
|
-
if (node[VAL_EXTENSION] === "link") {
|
1267
|
-
return templateString.concat("".concat(VAL_START_TAG_PREFIX).concat(i).concat(VAL_START_TAG_SUFFIX).concat(node.children[0]).concat(VAL_END_TAG));
|
1268
|
-
} else {
|
1269
|
-
return templateString.concat("".concat(VAL_START_TAG_PREFIX).concat(i).concat(VAL_START_TAG_SUFFIX).concat(VAL_END_TAG));
|
1270
|
-
}
|
1271
|
-
}
|
1272
|
-
return templateString;
|
1273
|
-
}).join("");
|
1274
|
-
var tokenList = marked.lexer(inputText, {
|
1275
|
-
gfm: true
|
1276
|
-
});
|
1277
|
-
var _parseTokens2 = parseTokens(tokenList, nodes, 0),
|
1278
|
-
children = _parseTokens2.children,
|
1279
|
-
cursor = _parseTokens2.cursor;
|
1280
|
-
if (cursor !== tokenList.length) {
|
1281
|
-
throw Error("Unexpectedly terminated markdown parsing. Possible reason: unclosed html tag?");
|
1282
|
-
}
|
1283
|
-
return _defineProperty(_defineProperty({}, VAL_EXTENSION, "richtext"), "children", children);
|
1284
|
-
}
|
1285
|
-
|
1286
1129
|
var RemirrorTextMark = z.object({
|
1287
1130
|
type: z.union([z.literal("bold"), z.literal("strike"), z.literal("italic")])
|
1288
1131
|
});
|
@@ -1326,7 +1169,7 @@ var RemirrorHeading = z.intersection(z.object({
|
|
1326
1169
|
attrs: z.object({
|
1327
1170
|
level: z.number()
|
1328
1171
|
}),
|
1329
|
-
content: z.array(z.union([RemirrorText, RemirrorBr]))
|
1172
|
+
content: z.array(z.union([RemirrorText, RemirrorImage, RemirrorBr]))
|
1330
1173
|
}).partial());
|
1331
1174
|
var RemirrorBulletList = z.lazy(function () {
|
1332
1175
|
return z.intersection(z.object({
|
@@ -1346,45 +1189,45 @@ var RemirrorListItem = z.lazy(function () {
|
|
1346
1189
|
return z.intersection(z.object({
|
1347
1190
|
type: z.literal("listItem")
|
1348
1191
|
}), z.object({
|
1192
|
+
attrs: z.object({
|
1193
|
+
closed: z["boolean"](),
|
1194
|
+
nested: z["boolean"]()
|
1195
|
+
}).partial().optional(),
|
1349
1196
|
content: z.array(z.union([RemirrorParagraph, RemirrorBulletList, RemirrorOrderedList]))
|
1350
1197
|
}).partial());
|
1351
1198
|
});
|
1352
|
-
var RemirrorParagraph = z.
|
1353
|
-
|
1354
|
-
|
1355
|
-
|
1356
|
-
|
1199
|
+
var RemirrorParagraph = z.lazy(function () {
|
1200
|
+
return z.intersection(z.object({
|
1201
|
+
type: z.literal("paragraph")
|
1202
|
+
}), z.object({
|
1203
|
+
content: z.array(z.union([RemirrorText, RemirrorImage, RemirrorBr]))
|
1204
|
+
}).partial());
|
1205
|
+
});
|
1357
1206
|
var RemirrorJSON = z.object({
|
1358
1207
|
type: z.literal("doc"),
|
1359
1208
|
content: z.array(z.union([RemirrorParagraph, RemirrorHeading, RemirrorBulletList, RemirrorOrderedList]))
|
1360
1209
|
});
|
1361
1210
|
|
1362
|
-
function
|
1363
|
-
|
1364
|
-
if (Object.getOwnPropertySymbols) {
|
1365
|
-
var o = Object.getOwnPropertySymbols(e);
|
1366
|
-
r && (o = o.filter(function (r) {
|
1367
|
-
return Object.getOwnPropertyDescriptor(e, r).enumerable;
|
1368
|
-
})), t.push.apply(t, o);
|
1369
|
-
}
|
1370
|
-
return t;
|
1211
|
+
function _arrayWithoutHoles(arr) {
|
1212
|
+
if (Array.isArray(arr)) return _arrayLikeToArray(arr);
|
1371
1213
|
}
|
1372
|
-
|
1373
|
-
|
1374
|
-
|
1375
|
-
|
1376
|
-
|
1377
|
-
|
1378
|
-
|
1379
|
-
|
1380
|
-
|
1381
|
-
|
1214
|
+
|
1215
|
+
function _iterableToArray(iter) {
|
1216
|
+
if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter);
|
1217
|
+
}
|
1218
|
+
|
1219
|
+
function _nonIterableSpread() {
|
1220
|
+
throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
|
1221
|
+
}
|
1222
|
+
|
1223
|
+
function _toConsumableArray(arr) {
|
1224
|
+
return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread();
|
1382
1225
|
}
|
1383
1226
|
|
1384
1227
|
function richTextToRemirror(richtext) {
|
1385
1228
|
return {
|
1386
1229
|
type: "doc",
|
1387
|
-
content: richtext.
|
1230
|
+
content: richtext.map(function (child) {
|
1388
1231
|
return toRemirrorNode(child);
|
1389
1232
|
})
|
1390
1233
|
};
|
@@ -1409,8 +1252,6 @@ function toRemirrorNode(child) {
|
|
1409
1252
|
return convertUlToRemirror(child);
|
1410
1253
|
case "ol":
|
1411
1254
|
return convertOlToRemirror(child);
|
1412
|
-
case "br":
|
1413
|
-
return convertParagraphToRemirror([child]);
|
1414
1255
|
default:
|
1415
1256
|
{
|
1416
1257
|
var _exhaustiveCheck = child;
|
@@ -1424,7 +1265,7 @@ function convertHeadingToRemirror(level, children) {
|
|
1424
1265
|
attrs: {
|
1425
1266
|
level: level
|
1426
1267
|
},
|
1427
|
-
content: children.flatMap(
|
1268
|
+
content: children.flatMap(convertInlineToRemirror)
|
1428
1269
|
};
|
1429
1270
|
}
|
1430
1271
|
function convertStringToRemirror(child) {
|
@@ -1433,14 +1274,23 @@ function convertStringToRemirror(child) {
|
|
1433
1274
|
text: child
|
1434
1275
|
};
|
1435
1276
|
}
|
1436
|
-
function
|
1277
|
+
function convertInlineToRemirror(child) {
|
1437
1278
|
if (typeof child === "string") {
|
1438
1279
|
return [convertStringToRemirror(child)];
|
1439
1280
|
}
|
1281
|
+
if (child.tag === "img") {
|
1282
|
+
return [convertImageNodeToRemirror(child)];
|
1283
|
+
}
|
1284
|
+
if (child.tag === "br") {
|
1285
|
+
return [createRemirrorBr()];
|
1286
|
+
}
|
1287
|
+
if (child.tag === "a") {
|
1288
|
+
return convertLinkNodeToRemirror(child);
|
1289
|
+
}
|
1440
1290
|
return convertSpanNodeToRemirror(child);
|
1441
1291
|
}
|
1442
1292
|
function convertSpanNodeToRemirror(spanNode) {
|
1443
|
-
if (spanNode.
|
1293
|
+
if (spanNode.styles.length === 0 && spanNode.children.length === 1) {
|
1444
1294
|
if (typeof spanNode.children[0] === "string") {
|
1445
1295
|
return [convertStringToRemirror(spanNode.children[0])];
|
1446
1296
|
} else {
|
@@ -1448,12 +1298,13 @@ function convertSpanNodeToRemirror(spanNode) {
|
|
1448
1298
|
throw Error("Unexpected amount of children in span node: " + JSON.stringify(spanNode, null, 2));
|
1449
1299
|
}
|
1450
1300
|
}
|
1301
|
+
var uniqueStyles = Array.from(new Set(spanNode.styles));
|
1451
1302
|
return spanNode.children.map(function (child) {
|
1452
1303
|
return {
|
1453
1304
|
type: "text",
|
1454
1305
|
text: child,
|
1455
|
-
marks:
|
1456
|
-
switch (
|
1306
|
+
marks: uniqueStyles.map(function (style) {
|
1307
|
+
switch (style) {
|
1457
1308
|
case "bold":
|
1458
1309
|
return {
|
1459
1310
|
type: "bold"
|
@@ -1468,7 +1319,7 @@ function convertSpanNodeToRemirror(spanNode) {
|
|
1468
1319
|
};
|
1469
1320
|
default:
|
1470
1321
|
{
|
1471
|
-
var _exhaustiveCheck =
|
1322
|
+
var _exhaustiveCheck = style;
|
1472
1323
|
throw Error("Unexpected span class: " + _exhaustiveCheck);
|
1473
1324
|
}
|
1474
1325
|
}
|
@@ -1508,9 +1359,12 @@ function createRemirrorBr() {
|
|
1508
1359
|
};
|
1509
1360
|
}
|
1510
1361
|
function convertLinkNodeToRemirror(linkNode) {
|
1511
|
-
return linkNode.children.flatMap(
|
1512
|
-
|
1513
|
-
|
1362
|
+
return linkNode.children.flatMap(convertInlineToRemirror).map(function (remirrorNode) {
|
1363
|
+
if (remirrorNode.type !== "text") {
|
1364
|
+
return remirrorNode;
|
1365
|
+
}
|
1366
|
+
return _objectSpread2(_objectSpread2({}, remirrorNode), {}, {
|
1367
|
+
marks: (remirrorNode.marks || []).concat({
|
1514
1368
|
type: "link",
|
1515
1369
|
attrs: {
|
1516
1370
|
href: linkNode.href,
|
@@ -1522,12 +1376,18 @@ function convertLinkNodeToRemirror(linkNode) {
|
|
1522
1376
|
});
|
1523
1377
|
}
|
1524
1378
|
function convertImageNodeToRemirror(imageNode) {
|
1379
|
+
var _fileSource$metadata, _fileSource$metadata2;
|
1380
|
+
var fileSource = imageNode.src;
|
1381
|
+
if (!(VAL_EXTENSION in fileSource) || fileSource[VAL_EXTENSION] !== "file") {
|
1382
|
+
throw Error("Expected file source in image node");
|
1383
|
+
}
|
1384
|
+
var fileVal = Internal.convertFileSource(fileSource);
|
1525
1385
|
return {
|
1526
1386
|
type: "image",
|
1527
1387
|
attrs: {
|
1528
|
-
height:
|
1529
|
-
width:
|
1530
|
-
src:
|
1388
|
+
height: (_fileSource$metadata = fileSource.metadata) === null || _fileSource$metadata === void 0 ? void 0 : _fileSource$metadata.height,
|
1389
|
+
width: (_fileSource$metadata2 = fileSource.metadata) === null || _fileSource$metadata2 === void 0 ? void 0 : _fileSource$metadata2.width,
|
1390
|
+
src: fileVal.url
|
1531
1391
|
}
|
1532
1392
|
};
|
1533
1393
|
}
|
@@ -1569,24 +1429,6 @@ function convertListItemToRemirrorParagraph(rtChildren) {
|
|
1569
1429
|
lastChildContent.push(convertStringToRemirror(child));
|
1570
1430
|
} else {
|
1571
1431
|
switch (child.tag) {
|
1572
|
-
case "a":
|
1573
|
-
{
|
1574
|
-
lastChildContent.push.apply(lastChildContent, _toConsumableArray(convertLinkNodeToRemirror(child)));
|
1575
|
-
break;
|
1576
|
-
}
|
1577
|
-
case "br":
|
1578
|
-
{
|
1579
|
-
children.push({
|
1580
|
-
type: "paragraph",
|
1581
|
-
content: [] // create new paragraph
|
1582
|
-
});
|
1583
|
-
break;
|
1584
|
-
}
|
1585
|
-
case "span":
|
1586
|
-
{
|
1587
|
-
lastChildContent.push.apply(lastChildContent, _toConsumableArray(convertSpanNodeToRemirror(child)));
|
1588
|
-
break;
|
1589
|
-
}
|
1590
1432
|
case "ol":
|
1591
1433
|
{
|
1592
1434
|
children.push(convertOlToRemirror(child));
|
@@ -1597,6 +1439,20 @@ function convertListItemToRemirrorParagraph(rtChildren) {
|
|
1597
1439
|
children.push(convertUlToRemirror(child));
|
1598
1440
|
break;
|
1599
1441
|
}
|
1442
|
+
case "p":
|
1443
|
+
{
|
1444
|
+
var newChild = convertParagraphToRemirror(child.children);
|
1445
|
+
if (lastChild.type === "paragraph" && newChild.type === "paragraph") {
|
1446
|
+
if (newChild.content) {
|
1447
|
+
lastChildContent.push.apply(lastChildContent, _toConsumableArray(newChild.content));
|
1448
|
+
} else {
|
1449
|
+
// no content - skip
|
1450
|
+
}
|
1451
|
+
} else {
|
1452
|
+
children.push(newChild);
|
1453
|
+
}
|
1454
|
+
break;
|
1455
|
+
}
|
1600
1456
|
default:
|
1601
1457
|
{
|
1602
1458
|
var _exhaustiveCheck = child;
|
@@ -2014,10 +1870,10 @@ var ValStore = /*#__PURE__*/function () {
|
|
2014
1870
|
this.schema = {};
|
2015
1871
|
}
|
2016
1872
|
_createClass(ValStore, [{
|
2017
|
-
key: "
|
1873
|
+
key: "reloadPaths",
|
2018
1874
|
value: function () {
|
2019
|
-
var
|
2020
|
-
var patches,
|
1875
|
+
var _reloadPaths = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(paths) {
|
1876
|
+
var patches, filteredPatches, data, _i, _Object$keys, pathS, path, _i2, _Array$from, _Array$from$_i, subscriberId, subscriberModules;
|
2021
1877
|
return _regeneratorRuntime().wrap(function _callee$(_context) {
|
2022
1878
|
while (1) switch (_context.prev = _context.next) {
|
2023
1879
|
case 0:
|
@@ -2032,14 +1888,21 @@ var ValStore = /*#__PURE__*/function () {
|
|
2032
1888
|
console.error("Val: failed to get patches", patches.error);
|
2033
1889
|
return _context.abrupt("return");
|
2034
1890
|
case 6:
|
2035
|
-
|
2036
|
-
|
2037
|
-
|
2038
|
-
|
1891
|
+
filteredPatches = Object.entries(patches.value).flatMap(function (_ref) {
|
1892
|
+
var _ref2 = _slicedToArray(_ref, 2),
|
1893
|
+
patchModuleFilePath = _ref2[0],
|
1894
|
+
mp = _ref2[1];
|
1895
|
+
if (paths.includes(patchModuleFilePath)) {
|
1896
|
+
return mp.map(function (p) {
|
1897
|
+
return p.patch_id;
|
1898
|
+
});
|
1899
|
+
} else {
|
1900
|
+
return [];
|
1901
|
+
}
|
2039
1902
|
});
|
2040
1903
|
_context.next = 9;
|
2041
1904
|
return this.api.putTree({
|
2042
|
-
patchIds:
|
1905
|
+
patchIds: filteredPatches
|
2043
1906
|
});
|
2044
1907
|
case 9:
|
2045
1908
|
data = _context.sent;
|
@@ -2061,7 +1924,7 @@ var ValStore = /*#__PURE__*/function () {
|
|
2061
1924
|
}
|
2062
1925
|
}
|
2063
1926
|
} else {
|
2064
|
-
console.error("Val: failed to
|
1927
|
+
console.error("Val: failed to reload paths", paths, data.error);
|
2065
1928
|
}
|
2066
1929
|
case 13:
|
2067
1930
|
case "end":
|
@@ -2069,6 +1932,67 @@ var ValStore = /*#__PURE__*/function () {
|
|
2069
1932
|
}
|
2070
1933
|
}, _callee, this);
|
2071
1934
|
}));
|
1935
|
+
function reloadPaths(_x) {
|
1936
|
+
return _reloadPaths.apply(this, arguments);
|
1937
|
+
}
|
1938
|
+
return reloadPaths;
|
1939
|
+
}()
|
1940
|
+
}, {
|
1941
|
+
key: "reset",
|
1942
|
+
value: function () {
|
1943
|
+
var _reset = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2() {
|
1944
|
+
var patches, allPatches, data, _i3, _Object$keys2, pathS, path, _i4, _Array$from2, _Array$from2$_i, subscriberId, subscriberModules;
|
1945
|
+
return _regeneratorRuntime().wrap(function _callee2$(_context2) {
|
1946
|
+
while (1) switch (_context2.prev = _context2.next) {
|
1947
|
+
case 0:
|
1948
|
+
_context2.next = 2;
|
1949
|
+
return this.api.getPatches();
|
1950
|
+
case 2:
|
1951
|
+
patches = _context2.sent;
|
1952
|
+
if (!result.isErr(patches)) {
|
1953
|
+
_context2.next = 6;
|
1954
|
+
break;
|
1955
|
+
}
|
1956
|
+
console.error("Val: failed to get patches", patches.error);
|
1957
|
+
return _context2.abrupt("return");
|
1958
|
+
case 6:
|
1959
|
+
allPatches = Object.values(patches.value).flatMap(function (mp) {
|
1960
|
+
return mp.map(function (p) {
|
1961
|
+
return p.patch_id;
|
1962
|
+
});
|
1963
|
+
});
|
1964
|
+
_context2.next = 9;
|
1965
|
+
return this.api.putTree({
|
1966
|
+
patchIds: allPatches
|
1967
|
+
});
|
1968
|
+
case 9:
|
1969
|
+
data = _context2.sent;
|
1970
|
+
_context2.next = 12;
|
1971
|
+
return this.initialize();
|
1972
|
+
case 12:
|
1973
|
+
if (result.isOk(data)) {
|
1974
|
+
for (_i3 = 0, _Object$keys2 = Object.keys(data.value.modules); _i3 < _Object$keys2.length; _i3++) {
|
1975
|
+
pathS = _Object$keys2[_i3];
|
1976
|
+
path = pathS;
|
1977
|
+
this.drafts[path] = data.value.modules[path].source;
|
1978
|
+
this.emitEvent(path, this.drafts[path]);
|
1979
|
+
for (_i4 = 0, _Array$from2 = Array.from(this.subscribers.entries()); _i4 < _Array$from2.length; _i4++) {
|
1980
|
+
_Array$from2$_i = _slicedToArray(_Array$from2[_i4], 2), subscriberId = _Array$from2$_i[0], subscriberModules = _Array$from2$_i[1];
|
1981
|
+
if (subscriberModules[path]) {
|
1982
|
+
this.subscribers.set(subscriberId, _objectSpread2(_objectSpread2({}, subscriberModules), {}, _defineProperty({}, path, this.drafts[path])));
|
1983
|
+
this.emitChange(subscriberId);
|
1984
|
+
}
|
1985
|
+
}
|
1986
|
+
}
|
1987
|
+
} else {
|
1988
|
+
console.error("Val: failed to reset", data.error);
|
1989
|
+
}
|
1990
|
+
case 13:
|
1991
|
+
case "end":
|
1992
|
+
return _context2.stop();
|
1993
|
+
}
|
1994
|
+
}, _callee2, this);
|
1995
|
+
}));
|
2072
1996
|
function reset() {
|
2073
1997
|
return _reset.apply(this, arguments);
|
2074
1998
|
}
|
@@ -2077,37 +2001,37 @@ var ValStore = /*#__PURE__*/function () {
|
|
2077
2001
|
}, {
|
2078
2002
|
key: "getModule",
|
2079
2003
|
value: function () {
|
2080
|
-
var _getModule = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function
|
2004
|
+
var _getModule = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee3(path) {
|
2081
2005
|
var refetch,
|
2082
2006
|
data,
|
2083
2007
|
fetchedSource,
|
2084
2008
|
schema,
|
2085
|
-
|
2086
|
-
return _regeneratorRuntime().wrap(function
|
2087
|
-
while (1) switch (
|
2009
|
+
_args3 = arguments;
|
2010
|
+
return _regeneratorRuntime().wrap(function _callee3$(_context3) {
|
2011
|
+
while (1) switch (_context3.prev = _context3.next) {
|
2088
2012
|
case 0:
|
2089
|
-
refetch =
|
2013
|
+
refetch = _args3.length > 1 && _args3[1] !== undefined ? _args3[1] : false;
|
2090
2014
|
if (!(!refetch && this.drafts[path] && this.schema[path])) {
|
2091
|
-
|
2015
|
+
_context3.next = 3;
|
2092
2016
|
break;
|
2093
2017
|
}
|
2094
|
-
return
|
2018
|
+
return _context3.abrupt("return", result.ok({
|
2095
2019
|
source: this.drafts[path],
|
2096
2020
|
schema: this.schema[path]
|
2097
2021
|
}));
|
2098
2022
|
case 3:
|
2099
|
-
|
2023
|
+
_context3.next = 5;
|
2100
2024
|
return this.api.putTree({
|
2101
2025
|
treePath: path
|
2102
2026
|
});
|
2103
2027
|
case 5:
|
2104
|
-
data =
|
2028
|
+
data = _context3.sent;
|
2105
2029
|
if (!result.isOk(data)) {
|
2106
|
-
|
2030
|
+
_context3.next = 26;
|
2107
2031
|
break;
|
2108
2032
|
}
|
2109
2033
|
if (data.value.modules[path]) {
|
2110
|
-
|
2034
|
+
_context3.next = 10;
|
2111
2035
|
break;
|
2112
2036
|
}
|
2113
2037
|
console.error("Val: could not find the module", {
|
@@ -2115,65 +2039,65 @@ var ValStore = /*#__PURE__*/function () {
|
|
2115
2039
|
moduleId: path,
|
2116
2040
|
data: data
|
2117
2041
|
});
|
2118
|
-
return
|
2042
|
+
return _context3.abrupt("return", result.err({
|
2119
2043
|
message: "Could not fetch data.\nCould not find the module:\n" + path + "\n\nVerify that the val.modules file includes this module."
|
2120
2044
|
}));
|
2121
2045
|
case 10:
|
2122
2046
|
fetchedSource = data.value.modules[path].source;
|
2123
2047
|
schema = this.schema[path];
|
2124
2048
|
if (this.schema[path]) {
|
2125
|
-
|
2049
|
+
_context3.next = 17;
|
2126
2050
|
break;
|
2127
2051
|
}
|
2128
|
-
|
2052
|
+
_context3.next = 15;
|
2129
2053
|
return this.initialize();
|
2130
2054
|
case 15:
|
2131
2055
|
if (this.schema[path]) {
|
2132
|
-
|
2056
|
+
_context3.next = 17;
|
2133
2057
|
break;
|
2134
2058
|
}
|
2135
|
-
return
|
2059
|
+
return _context3.abrupt("return", result.err({
|
2136
2060
|
message: "Path not found in schema. Verify that the module exists."
|
2137
2061
|
}));
|
2138
2062
|
case 17:
|
2139
2063
|
if (!(fetchedSource !== undefined)) {
|
2140
|
-
|
2064
|
+
_context3.next = 22;
|
2141
2065
|
break;
|
2142
2066
|
}
|
2143
2067
|
this.drafts[path] = fetchedSource;
|
2144
|
-
return
|
2068
|
+
return _context3.abrupt("return", result.ok({
|
2145
2069
|
source: fetchedSource,
|
2146
2070
|
schema: schema
|
2147
2071
|
}));
|
2148
2072
|
case 22:
|
2149
2073
|
console.error("Val: could not find the module source");
|
2150
|
-
return
|
2074
|
+
return _context3.abrupt("return", result.err({
|
2151
2075
|
message: "Could not fetch data. Verify that the module exists."
|
2152
2076
|
}));
|
2153
2077
|
case 24:
|
2154
|
-
|
2078
|
+
_context3.next = 33;
|
2155
2079
|
break;
|
2156
2080
|
case 26:
|
2157
2081
|
if (!(data.error.statusCode === 504)) {
|
2158
|
-
|
2082
|
+
_context3.next = 31;
|
2159
2083
|
break;
|
2160
2084
|
}
|
2161
2085
|
console.error("Val: timeout", data.error);
|
2162
|
-
return
|
2086
|
+
return _context3.abrupt("return", result.err({
|
2163
2087
|
message: "Timed out while fetching data. Try again later."
|
2164
2088
|
}));
|
2165
2089
|
case 31:
|
2166
2090
|
console.error("Val: failed to get module", data.error);
|
2167
|
-
return
|
2091
|
+
return _context3.abrupt("return", result.err({
|
2168
2092
|
message: "Could not fetch data. Verify that Val is correctly configured."
|
2169
2093
|
}));
|
2170
2094
|
case 33:
|
2171
2095
|
case "end":
|
2172
|
-
return
|
2096
|
+
return _context3.stop();
|
2173
2097
|
}
|
2174
|
-
},
|
2098
|
+
}, _callee3, this);
|
2175
2099
|
}));
|
2176
|
-
function getModule(
|
2100
|
+
function getModule(_x2) {
|
2177
2101
|
return _getModule.apply(this, arguments);
|
2178
2102
|
}
|
2179
2103
|
return getModule;
|
@@ -2181,12 +2105,12 @@ var ValStore = /*#__PURE__*/function () {
|
|
2181
2105
|
}, {
|
2182
2106
|
key: "applyPatch",
|
2183
2107
|
value: function () {
|
2184
|
-
var _applyPatch = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function
|
2185
|
-
var data, fetchedSource, _data$value$modules$p,
|
2186
|
-
return _regeneratorRuntime().wrap(function
|
2187
|
-
while (1) switch (
|
2108
|
+
var _applyPatch = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee4(path, patchIds, patch) {
|
2109
|
+
var data, fetchedSource, _data$value$modules$p, _i5, _Array$from3, _Array$from3$_i, subscriberId, subscriberModules;
|
2110
|
+
return _regeneratorRuntime().wrap(function _callee4$(_context4) {
|
2111
|
+
while (1) switch (_context4.prev = _context4.next) {
|
2188
2112
|
case 0:
|
2189
|
-
|
2113
|
+
_context4.next = 2;
|
2190
2114
|
return this.api.putTree({
|
2191
2115
|
treePath: path,
|
2192
2116
|
patchIds: patchIds,
|
@@ -2196,48 +2120,48 @@ var ValStore = /*#__PURE__*/function () {
|
|
2196
2120
|
}
|
2197
2121
|
});
|
2198
2122
|
case 2:
|
2199
|
-
data =
|
2123
|
+
data = _context4.sent;
|
2200
2124
|
if (!result.isOk(data)) {
|
2201
|
-
|
2125
|
+
_context4.next = 16;
|
2202
2126
|
break;
|
2203
2127
|
}
|
2204
2128
|
fetchedSource = data.value.modules[path].source;
|
2205
2129
|
if (!(fetchedSource !== undefined)) {
|
2206
|
-
|
2130
|
+
_context4.next = 12;
|
2207
2131
|
break;
|
2208
2132
|
}
|
2209
2133
|
this.drafts[path] = fetchedSource;
|
2210
2134
|
this.emitEvent(path, fetchedSource);
|
2211
|
-
for (
|
2212
|
-
_Array$
|
2135
|
+
for (_i5 = 0, _Array$from3 = Array.from(this.subscribers.entries()); _i5 < _Array$from3.length; _i5++) {
|
2136
|
+
_Array$from3$_i = _slicedToArray(_Array$from3[_i5], 2), subscriberId = _Array$from3$_i[0], subscriberModules = _Array$from3$_i[1];
|
2213
2137
|
if (subscriberModules[path]) {
|
2214
2138
|
this.subscribers.set(subscriberId, _objectSpread2(_objectSpread2({}, subscriberModules), {}, _defineProperty({}, path, this.drafts[path])));
|
2215
2139
|
this.emitChange(subscriberId);
|
2216
2140
|
}
|
2217
2141
|
}
|
2218
|
-
return
|
2142
|
+
return _context4.abrupt("return", result.ok(_defineProperty({}, path, {
|
2219
2143
|
patchIds: ((_data$value$modules$p = data.value.modules[path].patches) === null || _data$value$modules$p === void 0 ? void 0 : _data$value$modules$p.applied) || []
|
2220
2144
|
})));
|
2221
2145
|
case 12:
|
2222
2146
|
console.error("Val: could not patch");
|
2223
|
-
return
|
2147
|
+
return _context4.abrupt("return", result.err({
|
2224
2148
|
message: "Val: could not fetch data. Verify that the module exists."
|
2225
2149
|
}));
|
2226
2150
|
case 14:
|
2227
|
-
|
2151
|
+
_context4.next = 18;
|
2228
2152
|
break;
|
2229
2153
|
case 16:
|
2230
2154
|
console.error("Val: failed to get module", data.error);
|
2231
|
-
return
|
2155
|
+
return _context4.abrupt("return", result.err({
|
2232
2156
|
message: "Val: could not fetch data. Verify that Val is correctly configured."
|
2233
2157
|
}));
|
2234
2158
|
case 18:
|
2235
2159
|
case "end":
|
2236
|
-
return
|
2160
|
+
return _context4.stop();
|
2237
2161
|
}
|
2238
|
-
},
|
2162
|
+
}, _callee4, this);
|
2239
2163
|
}));
|
2240
|
-
function applyPatch(
|
2164
|
+
function applyPatch(_x3, _x4, _x5) {
|
2241
2165
|
return _applyPatch.apply(this, arguments);
|
2242
2166
|
}
|
2243
2167
|
return applyPatch;
|
@@ -2257,29 +2181,29 @@ var ValStore = /*#__PURE__*/function () {
|
|
2257
2181
|
}, {
|
2258
2182
|
key: "initialize",
|
2259
2183
|
value: function () {
|
2260
|
-
var _initialize = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function
|
2261
|
-
var data, paths,
|
2262
|
-
return _regeneratorRuntime().wrap(function
|
2263
|
-
while (1) switch (
|
2184
|
+
var _initialize = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee5() {
|
2185
|
+
var data, paths, _i6, _arr, moduleId, schema, msg;
|
2186
|
+
return _regeneratorRuntime().wrap(function _callee5$(_context5) {
|
2187
|
+
while (1) switch (_context5.prev = _context5.next) {
|
2264
2188
|
case 0:
|
2265
|
-
|
2189
|
+
_context5.next = 2;
|
2266
2190
|
return this.api.getSchema({});
|
2267
2191
|
case 2:
|
2268
|
-
data =
|
2192
|
+
data = _context5.sent;
|
2269
2193
|
if (!result.isOk(data)) {
|
2270
|
-
|
2194
|
+
_context5.next = 9;
|
2271
2195
|
break;
|
2272
2196
|
}
|
2273
2197
|
paths = [];
|
2274
|
-
for (
|
2275
|
-
moduleId = _arr[
|
2198
|
+
for (_i6 = 0, _arr = Object.keys(data.value.schemas); _i6 < _arr.length; _i6++) {
|
2199
|
+
moduleId = _arr[_i6];
|
2276
2200
|
schema = data.value.schemas[moduleId];
|
2277
2201
|
if (schema) {
|
2278
2202
|
paths.push(moduleId);
|
2279
2203
|
this.schema[moduleId] = schema;
|
2280
2204
|
}
|
2281
2205
|
}
|
2282
|
-
return
|
2206
|
+
return _context5.abrupt("return", result.ok(paths));
|
2283
2207
|
case 9:
|
2284
2208
|
msg = "Failed to fetch content. ";
|
2285
2209
|
if (data.error.statusCode === 401) {
|
@@ -2287,7 +2211,7 @@ var ValStore = /*#__PURE__*/function () {
|
|
2287
2211
|
} else {
|
2288
2212
|
msg += "Get a developer to verify that Val is correctly setup.";
|
2289
2213
|
}
|
2290
|
-
return
|
2214
|
+
return _context5.abrupt("return", result.err({
|
2291
2215
|
message: msg,
|
2292
2216
|
details: {
|
2293
2217
|
fetchError: data.error
|
@@ -2295,9 +2219,9 @@ var ValStore = /*#__PURE__*/function () {
|
|
2295
2219
|
}));
|
2296
2220
|
case 12:
|
2297
2221
|
case "end":
|
2298
|
-
return
|
2222
|
+
return _context5.stop();
|
2299
2223
|
}
|
2300
|
-
},
|
2224
|
+
}, _callee5, this);
|
2301
2225
|
}));
|
2302
2226
|
function initialize() {
|
2303
2227
|
return _initialize.apply(this, arguments);
|
@@ -2327,4 +2251,4 @@ function createSubscriberId(paths) {
|
|
2327
2251
|
return paths.slice().sort().join("&");
|
2328
2252
|
}
|
2329
2253
|
|
2330
|
-
export { EXT_TO_MIME_TYPES, MIME_TYPES_TO_EXT, RemirrorBr, RemirrorBulletList, RemirrorHeading, RemirrorImage, RemirrorJSON, RemirrorLinkMark, RemirrorListItem, RemirrorOrderedList, RemirrorParagraph, RemirrorText, RemirrorTextMark, VAL_ENABLE_COOKIE_NAME, VAL_SESSION_COOKIE, VAL_STATE_COOKIE, ValStore, filenameToMimeType, getMimeType, mimeTypeToFileExt,
|
2254
|
+
export { EXT_TO_MIME_TYPES, MIME_TYPES_TO_EXT, RemirrorBr, RemirrorBulletList, RemirrorHeading, RemirrorImage, RemirrorJSON, RemirrorLinkMark, RemirrorListItem, RemirrorOrderedList, RemirrorParagraph, RemirrorText, RemirrorTextMark, VAL_ENABLE_COOKIE_NAME, VAL_SESSION_COOKIE, VAL_STATE_COOKIE, ValStore, filenameToMimeType, getMimeType, mimeTypeToFileExt, remirrorToRichTextSource, richTextToRemirror };
|