@valbuild/shared 0.33.0 → 0.35.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,2 +1,3 @@
1
1
  export * from "./richtext/conversion/index.js";
2
2
  export * from "./mimeType/index.js";
3
+ export * from "./server/types.js";
@@ -0,0 +1,62 @@
1
+ import { ApiTreeResponse, Json } from "@valbuild/core";
2
+ export declare const VAL_SESSION_COOKIE: "val_session";
3
+ export declare const VAL_STATE_COOKIE: "val_state";
4
+ export declare const VAL_ENABLE_COOKIE_NAME: "val_enable";
5
+ export type VAL_SESSION_COOKIE = typeof VAL_SESSION_COOKIE;
6
+ export type VAL_STATE_COOKIE = typeof VAL_STATE_COOKIE;
7
+ export type VAL_ENABLE_COOKIE_NAME = typeof VAL_ENABLE_COOKIE_NAME;
8
+ type ValCookiesNames = VAL_SESSION_COOKIE | VAL_STATE_COOKIE | VAL_ENABLE_COOKIE_NAME;
9
+ export type ValCookies<Names extends ValCookiesNames> = Partial<Record<Names, string>>;
10
+ export type ValServerResultCookies<Names extends ValCookiesNames> = Partial<Record<Names, {
11
+ value: string | null;
12
+ options?: {
13
+ path?: string;
14
+ httpOnly?: boolean;
15
+ secure?: boolean;
16
+ sameSite?: "lax" | "strict" | "none";
17
+ expires?: Date;
18
+ };
19
+ }> | null>;
20
+ export type ValServerErrorStatus = 400 | 401 | 403 | 404 | 500 | 501;
21
+ export type ValServerError = {
22
+ status: ValServerErrorStatus;
23
+ headers?: Record<string, string>;
24
+ json?: {
25
+ message: string;
26
+ details?: unknown;
27
+ };
28
+ };
29
+ export type ValServerRedirectResult<Names extends ValCookiesNames> = {
30
+ status: 302;
31
+ cookies?: ValServerResultCookies<Names>;
32
+ redirectTo: string;
33
+ headers?: Record<string, string>;
34
+ } | ValServerError;
35
+ export type ValServerResult<Names extends ValCookiesNames, Body extends string | ReadableStream<Uint8Array> | never = never> = {
36
+ status: 200 | 201;
37
+ headers?: Record<string, string>;
38
+ cookies?: ValServerResultCookies<Names>;
39
+ body?: Body;
40
+ } | ValServerError;
41
+ export type ValServerJsonResult<Body extends Json | ApiTreeResponse | never = never> = {
42
+ status: 200 | 201;
43
+ json: Body;
44
+ } | ValServerError;
45
+ export type ValServerGenericResult = ValServerJsonResult<Json> | ValServerError | ValServerRedirectResult<ValCookiesNames> | ValServerResult<ValCookiesNames, string | ReadableStream<Uint8Array>>;
46
+ export type ValUIRequestHandler = (url: string) => Promise<ValServerGenericResult>;
47
+ export type ValSession = {
48
+ mode: "unauthorized";
49
+ enabled?: boolean;
50
+ } | {
51
+ mode: "local";
52
+ enabled?: boolean;
53
+ } | {
54
+ mode: "proxy";
55
+ member_role?: "owner" | "developer" | "editor";
56
+ enabled?: boolean;
57
+ id: string;
58
+ full_name?: string;
59
+ username?: string;
60
+ avatar_url?: string;
61
+ };
62
+ export {};
@@ -584,7 +584,6 @@ function fromIRToRichTextSource(_x) {
584
584
  }
585
585
  function _fromIRToRichTextSource() {
586
586
  _fromIRToRichTextSource = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(markdownIRBlocks) {
587
- var _ref4;
588
587
  var templateStrings, exprs, files, blockIdx, block, _iterator, _step, child, exhaustiveCheck;
589
588
  return _regeneratorRuntime().wrap(function _callee$(_context) {
590
589
  while (1) switch (_context.prev = _context.next) {
@@ -666,7 +665,7 @@ function _fromIRToRichTextSource() {
666
665
  _context.next = 4;
667
666
  break;
668
667
  case 44:
669
- return _context.abrupt("return", (_ref4 = {}, _defineProperty(_ref4, core.VAL_EXTENSION, "richtext"), _defineProperty(_ref4, "templateStrings", templateStrings), _defineProperty(_ref4, "exprs", exprs), _defineProperty(_ref4, "files", files), _ref4));
668
+ return _context.abrupt("return", _defineProperty(_defineProperty(_defineProperty(_defineProperty({}, core.VAL_EXTENSION, "richtext"), "templateStrings", templateStrings), "exprs", exprs), "files", files));
670
669
  case 45:
671
670
  case "end":
672
671
  return _context.stop();
@@ -705,11 +704,11 @@ function transformLeafNode(node) {
705
704
  }
706
705
  }
707
706
  function formatListItemNode(listPrefix, node, indent) {
708
- var _node$children, _node$children$;
707
+ var _node$children;
709
708
  var isFirstTopLevelListItem = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : false;
710
709
  var newLine = isFirstTopLevelListItem ? "" : "\n";
711
710
  var prefix = ["".concat(newLine).concat(" ".repeat(indent)).concat(listPrefix)];
712
- if (((_node$children = node.children) === null || _node$children === void 0 ? void 0 : (_node$children$ = _node$children[0]) === null || _node$children$ === void 0 ? void 0 : _node$children$.type) !== "list") {
711
+ if (((_node$children = node.children) === null || _node$children === void 0 || (_node$children = _node$children[0]) === null || _node$children === void 0 ? void 0 : _node$children.type) !== "list") {
713
712
  prefix.push(" ");
714
713
  }
715
714
  return prefix.concat(node.children.flatMap(function (child) {
@@ -757,7 +756,7 @@ function fromLexicalImageNode(_x2, _x3) {
757
756
  }
758
757
  function _fromLexicalImageNode() {
759
758
  _fromLexicalImageNode = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2(node, files) {
760
- var _ref5, sha256, mimeType, fileExt, filePath, _ref6, _sha;
759
+ var sha256, mimeType, fileExt, filePath, _sha;
761
760
  return _regeneratorRuntime().wrap(function _callee2$(_context2) {
762
761
  while (1) switch (_context2.prev = _context2.next) {
763
762
  case 0:
@@ -779,18 +778,18 @@ function _fromLexicalImageNode() {
779
778
  fileExt = mimeTypeToFileExt(mimeType);
780
779
  filePath = "/public/".concat(sha256, ".").concat(fileExt);
781
780
  files[filePath] = node.src;
782
- return _context2.abrupt("return", (_ref5 = {}, _defineProperty(_ref5, core.VAL_EXTENSION, "file"), _defineProperty(_ref5, core.FILE_REF_PROP, filePath), _defineProperty(_ref5, "metadata", {
781
+ return _context2.abrupt("return", _defineProperty(_defineProperty(_defineProperty({}, core.VAL_EXTENSION, "file"), core.FILE_REF_PROP, filePath), "metadata", {
783
782
  width: node.width || 0,
784
783
  height: node.height || 0,
785
784
  sha256: sha256 || ""
786
- }), _ref5));
785
+ }));
787
786
  case 13:
788
787
  _sha = getParam("sha256", node.src);
789
- return _context2.abrupt("return", (_ref6 = {}, _defineProperty(_ref6, core.VAL_EXTENSION, "file"), _defineProperty(_ref6, core.FILE_REF_PROP, "/public".concat(node.src.split("?")[0])), _defineProperty(_ref6, "metadata", {
788
+ return _context2.abrupt("return", _defineProperty(_defineProperty(_defineProperty({}, core.VAL_EXTENSION, "file"), core.FILE_REF_PROP, "/public".concat(node.src.split("?")[0])), "metadata", {
790
789
  width: node.width || 0,
791
790
  height: node.height || 0,
792
791
  sha256: _sha || ""
793
- }), _ref6));
792
+ }));
794
793
  case 15:
795
794
  case "end":
796
795
  return _context2.stop();
@@ -812,8 +811,7 @@ function getParam(param, url) {
812
811
  return undefined;
813
812
  }
814
813
  function fromLexicalLinkNode(node) {
815
- var _ref3;
816
- return _ref3 = {}, _defineProperty(_ref3, core.VAL_EXTENSION, "link"), _defineProperty(_ref3, "href", node.url), _defineProperty(_ref3, "children", node.children.map(formatText)), _ref3;
814
+ return _defineProperty(_defineProperty(_defineProperty({}, core.VAL_EXTENSION, "link"), "href", node.url), "children", node.children.map(formatText));
817
815
  }
818
816
 
819
817
  function ownKeys(e, r) {
@@ -1002,16 +1000,6 @@ function toLexicalTextNode(spanNode) {
1002
1000
  }
1003
1001
  }
1004
1002
 
1005
- function _typeof(o) {
1006
- "@babel/helpers - typeof";
1007
-
1008
- return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) {
1009
- return typeof o;
1010
- } : function (o) {
1011
- return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o;
1012
- }, _typeof(o);
1013
- }
1014
-
1015
1003
  var VAL_START_TAG_PREFIX = '<val value="';
1016
1004
  var VAL_START_TAG_SUFFIX = '">';
1017
1005
  var VAL_END_TAG = "</val>";
@@ -1019,140 +1007,141 @@ function parseTokens(tokens, sourceNodes, cursor) {
1019
1007
  var insideList = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : false;
1020
1008
  var children = [];
1021
1009
  var _loop = function _loop() {
1022
- var token = tokens[cursor];
1023
- if (token.type === "heading") {
1024
- children.push({
1025
- tag: "h".concat(token.depth),
1026
- children: parseTokens(token.tokens ? token.tokens : [], sourceNodes, 0).children
1027
- });
1028
- } else if (token.type === "paragraph") {
1029
- children.push({
1030
- tag: "p",
1031
- children: parseTokens(token.tokens ? token.tokens : [], sourceNodes, 0).children
1032
- });
1033
- } else if (token.type === "strong") {
1034
- children.push({
1035
- tag: "span",
1036
- classes: ["bold"],
1037
- children: parseTokens(token.tokens ? token.tokens : [], sourceNodes, 0).children
1038
- });
1039
- } else if (token.type === "em") {
1040
- children.push({
1041
- tag: "span",
1042
- classes: ["italic"],
1043
- children: parseTokens(token.tokens ? token.tokens : [], sourceNodes, 0).children
1044
- });
1045
- } else if (token.type === "del") {
1046
- children.push({
1047
- tag: "span",
1048
- classes: ["line-through"],
1049
- children: parseTokens(token.tokens ? token.tokens : [], sourceNodes, 0).children
1050
- });
1051
- } else if (token.type === "text") {
1052
- if ("tokens" in token && Array.isArray(token.tokens)) {
1053
- children.push.apply(children, _toConsumableArray(parseTokens(token.tokens, sourceNodes, cursor, insideList).children));
1054
- } else {
1055
- if (insideList && typeof token.raw === "string") {
1056
- var lines = token.raw.split("\n");
1057
- var tags = lines.flatMap(function (line, i) {
1058
- if (i === lines.length - 1) return [line];
1059
- return [line, {
1060
- tag: "br",
1061
- children: []
1062
- }];
1063
- });
1064
- children.push.apply(children, _toConsumableArray(tags));
1010
+ var token = tokens[cursor];
1011
+ if (token.type === "heading") {
1012
+ children.push({
1013
+ tag: "h".concat(token.depth),
1014
+ children: parseTokens(token.tokens ? token.tokens : [], sourceNodes, 0).children
1015
+ });
1016
+ } else if (token.type === "paragraph") {
1017
+ children.push({
1018
+ tag: "p",
1019
+ children: parseTokens(token.tokens ? token.tokens : [], sourceNodes, 0).children
1020
+ });
1021
+ } else if (token.type === "strong") {
1022
+ children.push({
1023
+ tag: "span",
1024
+ classes: ["bold"],
1025
+ children: parseTokens(token.tokens ? token.tokens : [], sourceNodes, 0).children
1026
+ });
1027
+ } else if (token.type === "em") {
1028
+ children.push({
1029
+ tag: "span",
1030
+ classes: ["italic"],
1031
+ children: parseTokens(token.tokens ? token.tokens : [], sourceNodes, 0).children
1032
+ });
1033
+ } else if (token.type === "del") {
1034
+ children.push({
1035
+ tag: "span",
1036
+ classes: ["line-through"],
1037
+ children: parseTokens(token.tokens ? token.tokens : [], sourceNodes, 0).children
1038
+ });
1039
+ } else if (token.type === "text") {
1040
+ if ("tokens" in token && Array.isArray(token.tokens)) {
1041
+ children.push.apply(children, _toConsumableArray(parseTokens(token.tokens, sourceNodes, cursor, insideList).children));
1065
1042
  } else {
1066
- children.push(token.raw);
1067
- }
1068
- }
1069
- } else if (token.type === "list") {
1070
- children.push({
1071
- tag: token.ordered ? "ol" : "ul",
1072
- children: parseTokens(token.items, sourceNodes, 0).children
1073
- });
1074
- } else if (token.type === "list_item") {
1075
- children.push({
1076
- tag: "li",
1077
- children: parseTokens(token.tokens ? token.tokens : [], sourceNodes, 0, true).children
1078
- });
1079
- } else if (token.type === "space") ; else if (token.type === "html") {
1080
- if (token.text === VAL_END_TAG) {
1081
- return {
1082
- v: {
1083
- children: children,
1084
- cursor: cursor
1043
+ if (insideList && typeof token.raw === "string") {
1044
+ var lines = token.raw.split("\n");
1045
+ var tags = lines.flatMap(function (line, i) {
1046
+ if (i === lines.length - 1) return [line];
1047
+ return [line, {
1048
+ tag: "br",
1049
+ children: []
1050
+ }];
1051
+ });
1052
+ children.push.apply(children, _toConsumableArray(tags));
1053
+ } else {
1054
+ children.push(token.raw);
1085
1055
  }
1086
- };
1087
- }
1088
- var suffixIndex = token.text.indexOf(VAL_START_TAG_SUFFIX);
1089
- if (token.text.startsWith(VAL_START_TAG_PREFIX) && suffixIndex > -1) {
1090
- var number = Number(token.text.slice(VAL_START_TAG_PREFIX.length, suffixIndex));
1091
- if (Number.isNaN(number)) {
1092
- throw Error("Illegal val intermediate node: ".concat(JSON.stringify(token)));
1093
1056
  }
1094
- var _parseTokens = parseTokens(tokens.map(function (token) {
1095
- if (token.type === "link" || token.type === "list") {
1096
- return {
1097
- type: "text",
1098
- raw: token.raw,
1099
- text: token.raw
1100
- };
1057
+ } else if (token.type === "list") {
1058
+ children.push({
1059
+ tag: token.ordered ? "ol" : "ul",
1060
+ children: parseTokens(token.items, sourceNodes, 0).children
1061
+ });
1062
+ } else if (token.type === "list_item") {
1063
+ children.push({
1064
+ tag: "li",
1065
+ children: parseTokens(token.tokens ? token.tokens : [], sourceNodes, 0, true).children
1066
+ });
1067
+ } else if (token.type === "space") ; else if (token.type === "html") {
1068
+ if (token.text === VAL_END_TAG) {
1069
+ return {
1070
+ v: {
1071
+ children: children,
1072
+ cursor: cursor
1101
1073
  }
1102
- return token;
1103
- }), sourceNodes, cursor + 1),
1104
- subChildren = _parseTokens.children,
1105
- subCursor = _parseTokens.cursor;
1106
- var sourceNode = sourceNodes[number];
1107
- if (sourceNode._type === "link") {
1074
+ };
1075
+ }
1076
+ var suffixIndex = token.text.indexOf(VAL_START_TAG_SUFFIX);
1077
+ if (token.text.startsWith(VAL_START_TAG_PREFIX) && suffixIndex > -1) {
1078
+ var number = Number(token.text.slice(VAL_START_TAG_PREFIX.length, suffixIndex));
1079
+ if (Number.isNaN(number)) {
1080
+ throw Error("Illegal val intermediate node: ".concat(JSON.stringify(token)));
1081
+ }
1082
+ var _parseTokens = parseTokens(tokens.map(function (token) {
1083
+ if (token.type === "link" || token.type === "list") {
1084
+ return {
1085
+ type: "text",
1086
+ raw: token.raw,
1087
+ text: token.raw
1088
+ };
1089
+ }
1090
+ return token;
1091
+ }), sourceNodes, cursor + 1),
1092
+ subChildren = _parseTokens.children,
1093
+ subCursor = _parseTokens.cursor;
1094
+ var sourceNode = sourceNodes[number];
1095
+ if (sourceNode._type === "link") {
1096
+ children.push({
1097
+ tag: "a",
1098
+ href: sourceNode.href,
1099
+ children: subChildren
1100
+ });
1101
+ } else if (sourceNode._type === "file") {
1102
+ var _sourceNode$metadata, _sourceNode$metadata2;
1103
+ children.push({
1104
+ tag: "img",
1105
+ src: core.Internal.convertFileSource(sourceNode).url,
1106
+ width: (_sourceNode$metadata = sourceNode.metadata) === null || _sourceNode$metadata === void 0 ? void 0 : _sourceNode$metadata.width,
1107
+ height: (_sourceNode$metadata2 = sourceNode.metadata) === null || _sourceNode$metadata2 === void 0 ? void 0 : _sourceNode$metadata2.height,
1108
+ children: []
1109
+ });
1110
+ }
1111
+ cursor = subCursor;
1112
+ }
1113
+ var br_html_regex = /<br\s*\/?>/gi; // matches <br>, <br/>, <br />; case insensitive
1114
+ if (token.text.trim().match(br_html_regex)) {
1108
1115
  children.push({
1109
- tag: "a",
1110
- href: sourceNode.href,
1111
- children: subChildren
1116
+ tag: "br",
1117
+ children: []
1112
1118
  });
1113
- } else if (sourceNode._type === "file") {
1114
- var _sourceNode$metadata, _sourceNode$metadata2;
1119
+ }
1120
+ } else if (token.type === "link") {
1121
+ if (token.raw === token.href) {
1122
+ // avoid auto-linking (provided by github flavoured markdown, but we want strikethrough so keep it enabled)
1123
+ children.push(token.raw);
1124
+ } else {
1115
1125
  children.push({
1116
- tag: "img",
1117
- src: core.Internal.convertFileSource(sourceNode).url,
1118
- width: (_sourceNode$metadata = sourceNode.metadata) === null || _sourceNode$metadata === void 0 ? void 0 : _sourceNode$metadata.width,
1119
- height: (_sourceNode$metadata2 = sourceNode.metadata) === null || _sourceNode$metadata2 === void 0 ? void 0 : _sourceNode$metadata2.height,
1120
- children: []
1126
+ tag: "a",
1127
+ href: token.href,
1128
+ children: parseTokens(token.tokens ? token.tokens : [], sourceNodes, 0).children
1121
1129
  });
1122
1130
  }
1123
- cursor = subCursor;
1124
- }
1125
- var br_html_regex = /<br\s*\/?>/gi; // matches <br>, <br/>, <br />; case insensitive
1126
- if (token.text.trim().match(br_html_regex)) {
1131
+ } else if (token.type === "br") {
1127
1132
  children.push({
1128
1133
  tag: "br",
1129
1134
  children: []
1130
1135
  });
1131
- }
1132
- } else if (token.type === "link") {
1133
- if (token.raw === token.href) {
1134
- // avoid auto-linking (provided by github flavoured markdown, but we want strikethrough so keep it enabled)
1135
- children.push(token.raw);
1136
1136
  } else {
1137
- children.push({
1138
- tag: "a",
1139
- href: token.href,
1140
- children: parseTokens(token.tokens ? token.tokens : [], sourceNodes, 0).children
1141
- });
1137
+ console.error("Could not parse markdown: unsupported token type: ".concat(token.type, ". Found: ").concat(token.raw));
1142
1138
  }
1143
- } else if (token.type === "br") {
1144
- children.push({
1145
- tag: "br",
1146
- children: []
1147
- });
1148
- } else {
1149
- console.error("Could not parse markdown: unsupported token type: ".concat(token.type, ". Found: ").concat(token.raw));
1150
- }
1151
- cursor++;
1152
- };
1139
+ cursor++;
1140
+ },
1141
+ _ret;
1153
1142
  while (cursor < tokens.length) {
1154
- var _ret = _loop();
1155
- if (_typeof(_ret) === "object") return _ret.v;
1143
+ _ret = _loop();
1144
+ if (_ret) return _ret.v;
1156
1145
  }
1157
1146
  return {
1158
1147
  children: children,
@@ -1160,7 +1149,6 @@ function parseTokens(tokens, sourceNodes, cursor) {
1160
1149
  };
1161
1150
  }
1162
1151
  function parseRichTextSource(_ref) {
1163
- var _ref2;
1164
1152
  var templateStrings = _ref.templateStrings,
1165
1153
  nodes = _ref.exprs;
1166
1154
  // TODO: validate that templateStrings does not contain VAL_NODE_PREFIX
@@ -1184,10 +1172,17 @@ function parseRichTextSource(_ref) {
1184
1172
  if (cursor !== tokenList.length) {
1185
1173
  throw Error("Unexpectedly terminated markdown parsing. Possible reason: unclosed html tag?");
1186
1174
  }
1187
- return _ref2 = {}, _defineProperty(_ref2, core.VAL_EXTENSION, "richtext"), _defineProperty(_ref2, "children", children), _ref2;
1175
+ return _defineProperty(_defineProperty({}, core.VAL_EXTENSION, "richtext"), "children", children);
1188
1176
  }
1189
1177
 
1178
+ var VAL_SESSION_COOKIE = core.Internal.VAL_SESSION_COOKIE;
1179
+ var VAL_STATE_COOKIE = core.Internal.VAL_STATE_COOKIE;
1180
+ var VAL_ENABLE_COOKIE_NAME = core.Internal.VAL_ENABLE_COOKIE_NAME;
1181
+
1190
1182
  exports.COMMON_LEXICAL_PROPS = COMMON_LEXICAL_PROPS;
1183
+ exports.VAL_ENABLE_COOKIE_NAME = VAL_ENABLE_COOKIE_NAME;
1184
+ exports.VAL_SESSION_COOKIE = VAL_SESSION_COOKIE;
1185
+ exports.VAL_STATE_COOKIE = VAL_STATE_COOKIE;
1191
1186
  exports.fromLexicalFormat = fromLexicalFormat;
1192
1187
  exports.getMimeType = getMimeType;
1193
1188
  exports.lexicalToRichTextSource = lexicalToRichTextSource;
@@ -584,7 +584,6 @@ function fromIRToRichTextSource(_x) {
584
584
  }
585
585
  function _fromIRToRichTextSource() {
586
586
  _fromIRToRichTextSource = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(markdownIRBlocks) {
587
- var _ref4;
588
587
  var templateStrings, exprs, files, blockIdx, block, _iterator, _step, child, exhaustiveCheck;
589
588
  return _regeneratorRuntime().wrap(function _callee$(_context) {
590
589
  while (1) switch (_context.prev = _context.next) {
@@ -666,7 +665,7 @@ function _fromIRToRichTextSource() {
666
665
  _context.next = 4;
667
666
  break;
668
667
  case 44:
669
- return _context.abrupt("return", (_ref4 = {}, _defineProperty(_ref4, core.VAL_EXTENSION, "richtext"), _defineProperty(_ref4, "templateStrings", templateStrings), _defineProperty(_ref4, "exprs", exprs), _defineProperty(_ref4, "files", files), _ref4));
668
+ return _context.abrupt("return", _defineProperty(_defineProperty(_defineProperty(_defineProperty({}, core.VAL_EXTENSION, "richtext"), "templateStrings", templateStrings), "exprs", exprs), "files", files));
670
669
  case 45:
671
670
  case "end":
672
671
  return _context.stop();
@@ -705,11 +704,11 @@ function transformLeafNode(node) {
705
704
  }
706
705
  }
707
706
  function formatListItemNode(listPrefix, node, indent) {
708
- var _node$children, _node$children$;
707
+ var _node$children;
709
708
  var isFirstTopLevelListItem = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : false;
710
709
  var newLine = isFirstTopLevelListItem ? "" : "\n";
711
710
  var prefix = ["".concat(newLine).concat(" ".repeat(indent)).concat(listPrefix)];
712
- if (((_node$children = node.children) === null || _node$children === void 0 ? void 0 : (_node$children$ = _node$children[0]) === null || _node$children$ === void 0 ? void 0 : _node$children$.type) !== "list") {
711
+ if (((_node$children = node.children) === null || _node$children === void 0 || (_node$children = _node$children[0]) === null || _node$children === void 0 ? void 0 : _node$children.type) !== "list") {
713
712
  prefix.push(" ");
714
713
  }
715
714
  return prefix.concat(node.children.flatMap(function (child) {
@@ -757,7 +756,7 @@ function fromLexicalImageNode(_x2, _x3) {
757
756
  }
758
757
  function _fromLexicalImageNode() {
759
758
  _fromLexicalImageNode = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2(node, files) {
760
- var _ref5, sha256, mimeType, fileExt, filePath, _ref6, _sha;
759
+ var sha256, mimeType, fileExt, filePath, _sha;
761
760
  return _regeneratorRuntime().wrap(function _callee2$(_context2) {
762
761
  while (1) switch (_context2.prev = _context2.next) {
763
762
  case 0:
@@ -779,18 +778,18 @@ function _fromLexicalImageNode() {
779
778
  fileExt = mimeTypeToFileExt(mimeType);
780
779
  filePath = "/public/".concat(sha256, ".").concat(fileExt);
781
780
  files[filePath] = node.src;
782
- return _context2.abrupt("return", (_ref5 = {}, _defineProperty(_ref5, core.VAL_EXTENSION, "file"), _defineProperty(_ref5, core.FILE_REF_PROP, filePath), _defineProperty(_ref5, "metadata", {
781
+ return _context2.abrupt("return", _defineProperty(_defineProperty(_defineProperty({}, core.VAL_EXTENSION, "file"), core.FILE_REF_PROP, filePath), "metadata", {
783
782
  width: node.width || 0,
784
783
  height: node.height || 0,
785
784
  sha256: sha256 || ""
786
- }), _ref5));
785
+ }));
787
786
  case 13:
788
787
  _sha = getParam("sha256", node.src);
789
- return _context2.abrupt("return", (_ref6 = {}, _defineProperty(_ref6, core.VAL_EXTENSION, "file"), _defineProperty(_ref6, core.FILE_REF_PROP, "/public".concat(node.src.split("?")[0])), _defineProperty(_ref6, "metadata", {
788
+ return _context2.abrupt("return", _defineProperty(_defineProperty(_defineProperty({}, core.VAL_EXTENSION, "file"), core.FILE_REF_PROP, "/public".concat(node.src.split("?")[0])), "metadata", {
790
789
  width: node.width || 0,
791
790
  height: node.height || 0,
792
791
  sha256: _sha || ""
793
- }), _ref6));
792
+ }));
794
793
  case 15:
795
794
  case "end":
796
795
  return _context2.stop();
@@ -812,8 +811,7 @@ function getParam(param, url) {
812
811
  return undefined;
813
812
  }
814
813
  function fromLexicalLinkNode(node) {
815
- var _ref3;
816
- return _ref3 = {}, _defineProperty(_ref3, core.VAL_EXTENSION, "link"), _defineProperty(_ref3, "href", node.url), _defineProperty(_ref3, "children", node.children.map(formatText)), _ref3;
814
+ return _defineProperty(_defineProperty(_defineProperty({}, core.VAL_EXTENSION, "link"), "href", node.url), "children", node.children.map(formatText));
817
815
  }
818
816
 
819
817
  function ownKeys(e, r) {
@@ -1002,16 +1000,6 @@ function toLexicalTextNode(spanNode) {
1002
1000
  }
1003
1001
  }
1004
1002
 
1005
- function _typeof(o) {
1006
- "@babel/helpers - typeof";
1007
-
1008
- return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) {
1009
- return typeof o;
1010
- } : function (o) {
1011
- return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o;
1012
- }, _typeof(o);
1013
- }
1014
-
1015
1003
  var VAL_START_TAG_PREFIX = '<val value="';
1016
1004
  var VAL_START_TAG_SUFFIX = '">';
1017
1005
  var VAL_END_TAG = "</val>";
@@ -1019,140 +1007,141 @@ function parseTokens(tokens, sourceNodes, cursor) {
1019
1007
  var insideList = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : false;
1020
1008
  var children = [];
1021
1009
  var _loop = function _loop() {
1022
- var token = tokens[cursor];
1023
- if (token.type === "heading") {
1024
- children.push({
1025
- tag: "h".concat(token.depth),
1026
- children: parseTokens(token.tokens ? token.tokens : [], sourceNodes, 0).children
1027
- });
1028
- } else if (token.type === "paragraph") {
1029
- children.push({
1030
- tag: "p",
1031
- children: parseTokens(token.tokens ? token.tokens : [], sourceNodes, 0).children
1032
- });
1033
- } else if (token.type === "strong") {
1034
- children.push({
1035
- tag: "span",
1036
- classes: ["bold"],
1037
- children: parseTokens(token.tokens ? token.tokens : [], sourceNodes, 0).children
1038
- });
1039
- } else if (token.type === "em") {
1040
- children.push({
1041
- tag: "span",
1042
- classes: ["italic"],
1043
- children: parseTokens(token.tokens ? token.tokens : [], sourceNodes, 0).children
1044
- });
1045
- } else if (token.type === "del") {
1046
- children.push({
1047
- tag: "span",
1048
- classes: ["line-through"],
1049
- children: parseTokens(token.tokens ? token.tokens : [], sourceNodes, 0).children
1050
- });
1051
- } else if (token.type === "text") {
1052
- if ("tokens" in token && Array.isArray(token.tokens)) {
1053
- children.push.apply(children, _toConsumableArray(parseTokens(token.tokens, sourceNodes, cursor, insideList).children));
1054
- } else {
1055
- if (insideList && typeof token.raw === "string") {
1056
- var lines = token.raw.split("\n");
1057
- var tags = lines.flatMap(function (line, i) {
1058
- if (i === lines.length - 1) return [line];
1059
- return [line, {
1060
- tag: "br",
1061
- children: []
1062
- }];
1063
- });
1064
- children.push.apply(children, _toConsumableArray(tags));
1010
+ var token = tokens[cursor];
1011
+ if (token.type === "heading") {
1012
+ children.push({
1013
+ tag: "h".concat(token.depth),
1014
+ children: parseTokens(token.tokens ? token.tokens : [], sourceNodes, 0).children
1015
+ });
1016
+ } else if (token.type === "paragraph") {
1017
+ children.push({
1018
+ tag: "p",
1019
+ children: parseTokens(token.tokens ? token.tokens : [], sourceNodes, 0).children
1020
+ });
1021
+ } else if (token.type === "strong") {
1022
+ children.push({
1023
+ tag: "span",
1024
+ classes: ["bold"],
1025
+ children: parseTokens(token.tokens ? token.tokens : [], sourceNodes, 0).children
1026
+ });
1027
+ } else if (token.type === "em") {
1028
+ children.push({
1029
+ tag: "span",
1030
+ classes: ["italic"],
1031
+ children: parseTokens(token.tokens ? token.tokens : [], sourceNodes, 0).children
1032
+ });
1033
+ } else if (token.type === "del") {
1034
+ children.push({
1035
+ tag: "span",
1036
+ classes: ["line-through"],
1037
+ children: parseTokens(token.tokens ? token.tokens : [], sourceNodes, 0).children
1038
+ });
1039
+ } else if (token.type === "text") {
1040
+ if ("tokens" in token && Array.isArray(token.tokens)) {
1041
+ children.push.apply(children, _toConsumableArray(parseTokens(token.tokens, sourceNodes, cursor, insideList).children));
1065
1042
  } else {
1066
- children.push(token.raw);
1067
- }
1068
- }
1069
- } else if (token.type === "list") {
1070
- children.push({
1071
- tag: token.ordered ? "ol" : "ul",
1072
- children: parseTokens(token.items, sourceNodes, 0).children
1073
- });
1074
- } else if (token.type === "list_item") {
1075
- children.push({
1076
- tag: "li",
1077
- children: parseTokens(token.tokens ? token.tokens : [], sourceNodes, 0, true).children
1078
- });
1079
- } else if (token.type === "space") ; else if (token.type === "html") {
1080
- if (token.text === VAL_END_TAG) {
1081
- return {
1082
- v: {
1083
- children: children,
1084
- cursor: cursor
1043
+ if (insideList && typeof token.raw === "string") {
1044
+ var lines = token.raw.split("\n");
1045
+ var tags = lines.flatMap(function (line, i) {
1046
+ if (i === lines.length - 1) return [line];
1047
+ return [line, {
1048
+ tag: "br",
1049
+ children: []
1050
+ }];
1051
+ });
1052
+ children.push.apply(children, _toConsumableArray(tags));
1053
+ } else {
1054
+ children.push(token.raw);
1085
1055
  }
1086
- };
1087
- }
1088
- var suffixIndex = token.text.indexOf(VAL_START_TAG_SUFFIX);
1089
- if (token.text.startsWith(VAL_START_TAG_PREFIX) && suffixIndex > -1) {
1090
- var number = Number(token.text.slice(VAL_START_TAG_PREFIX.length, suffixIndex));
1091
- if (Number.isNaN(number)) {
1092
- throw Error("Illegal val intermediate node: ".concat(JSON.stringify(token)));
1093
1056
  }
1094
- var _parseTokens = parseTokens(tokens.map(function (token) {
1095
- if (token.type === "link" || token.type === "list") {
1096
- return {
1097
- type: "text",
1098
- raw: token.raw,
1099
- text: token.raw
1100
- };
1057
+ } else if (token.type === "list") {
1058
+ children.push({
1059
+ tag: token.ordered ? "ol" : "ul",
1060
+ children: parseTokens(token.items, sourceNodes, 0).children
1061
+ });
1062
+ } else if (token.type === "list_item") {
1063
+ children.push({
1064
+ tag: "li",
1065
+ children: parseTokens(token.tokens ? token.tokens : [], sourceNodes, 0, true).children
1066
+ });
1067
+ } else if (token.type === "space") ; else if (token.type === "html") {
1068
+ if (token.text === VAL_END_TAG) {
1069
+ return {
1070
+ v: {
1071
+ children: children,
1072
+ cursor: cursor
1101
1073
  }
1102
- return token;
1103
- }), sourceNodes, cursor + 1),
1104
- subChildren = _parseTokens.children,
1105
- subCursor = _parseTokens.cursor;
1106
- var sourceNode = sourceNodes[number];
1107
- if (sourceNode._type === "link") {
1074
+ };
1075
+ }
1076
+ var suffixIndex = token.text.indexOf(VAL_START_TAG_SUFFIX);
1077
+ if (token.text.startsWith(VAL_START_TAG_PREFIX) && suffixIndex > -1) {
1078
+ var number = Number(token.text.slice(VAL_START_TAG_PREFIX.length, suffixIndex));
1079
+ if (Number.isNaN(number)) {
1080
+ throw Error("Illegal val intermediate node: ".concat(JSON.stringify(token)));
1081
+ }
1082
+ var _parseTokens = parseTokens(tokens.map(function (token) {
1083
+ if (token.type === "link" || token.type === "list") {
1084
+ return {
1085
+ type: "text",
1086
+ raw: token.raw,
1087
+ text: token.raw
1088
+ };
1089
+ }
1090
+ return token;
1091
+ }), sourceNodes, cursor + 1),
1092
+ subChildren = _parseTokens.children,
1093
+ subCursor = _parseTokens.cursor;
1094
+ var sourceNode = sourceNodes[number];
1095
+ if (sourceNode._type === "link") {
1096
+ children.push({
1097
+ tag: "a",
1098
+ href: sourceNode.href,
1099
+ children: subChildren
1100
+ });
1101
+ } else if (sourceNode._type === "file") {
1102
+ var _sourceNode$metadata, _sourceNode$metadata2;
1103
+ children.push({
1104
+ tag: "img",
1105
+ src: core.Internal.convertFileSource(sourceNode).url,
1106
+ width: (_sourceNode$metadata = sourceNode.metadata) === null || _sourceNode$metadata === void 0 ? void 0 : _sourceNode$metadata.width,
1107
+ height: (_sourceNode$metadata2 = sourceNode.metadata) === null || _sourceNode$metadata2 === void 0 ? void 0 : _sourceNode$metadata2.height,
1108
+ children: []
1109
+ });
1110
+ }
1111
+ cursor = subCursor;
1112
+ }
1113
+ var br_html_regex = /<br\s*\/?>/gi; // matches <br>, <br/>, <br />; case insensitive
1114
+ if (token.text.trim().match(br_html_regex)) {
1108
1115
  children.push({
1109
- tag: "a",
1110
- href: sourceNode.href,
1111
- children: subChildren
1116
+ tag: "br",
1117
+ children: []
1112
1118
  });
1113
- } else if (sourceNode._type === "file") {
1114
- var _sourceNode$metadata, _sourceNode$metadata2;
1119
+ }
1120
+ } else if (token.type === "link") {
1121
+ if (token.raw === token.href) {
1122
+ // avoid auto-linking (provided by github flavoured markdown, but we want strikethrough so keep it enabled)
1123
+ children.push(token.raw);
1124
+ } else {
1115
1125
  children.push({
1116
- tag: "img",
1117
- src: core.Internal.convertFileSource(sourceNode).url,
1118
- width: (_sourceNode$metadata = sourceNode.metadata) === null || _sourceNode$metadata === void 0 ? void 0 : _sourceNode$metadata.width,
1119
- height: (_sourceNode$metadata2 = sourceNode.metadata) === null || _sourceNode$metadata2 === void 0 ? void 0 : _sourceNode$metadata2.height,
1120
- children: []
1126
+ tag: "a",
1127
+ href: token.href,
1128
+ children: parseTokens(token.tokens ? token.tokens : [], sourceNodes, 0).children
1121
1129
  });
1122
1130
  }
1123
- cursor = subCursor;
1124
- }
1125
- var br_html_regex = /<br\s*\/?>/gi; // matches <br>, <br/>, <br />; case insensitive
1126
- if (token.text.trim().match(br_html_regex)) {
1131
+ } else if (token.type === "br") {
1127
1132
  children.push({
1128
1133
  tag: "br",
1129
1134
  children: []
1130
1135
  });
1131
- }
1132
- } else if (token.type === "link") {
1133
- if (token.raw === token.href) {
1134
- // avoid auto-linking (provided by github flavoured markdown, but we want strikethrough so keep it enabled)
1135
- children.push(token.raw);
1136
1136
  } else {
1137
- children.push({
1138
- tag: "a",
1139
- href: token.href,
1140
- children: parseTokens(token.tokens ? token.tokens : [], sourceNodes, 0).children
1141
- });
1137
+ console.error("Could not parse markdown: unsupported token type: ".concat(token.type, ". Found: ").concat(token.raw));
1142
1138
  }
1143
- } else if (token.type === "br") {
1144
- children.push({
1145
- tag: "br",
1146
- children: []
1147
- });
1148
- } else {
1149
- console.error("Could not parse markdown: unsupported token type: ".concat(token.type, ". Found: ").concat(token.raw));
1150
- }
1151
- cursor++;
1152
- };
1139
+ cursor++;
1140
+ },
1141
+ _ret;
1153
1142
  while (cursor < tokens.length) {
1154
- var _ret = _loop();
1155
- if (_typeof(_ret) === "object") return _ret.v;
1143
+ _ret = _loop();
1144
+ if (_ret) return _ret.v;
1156
1145
  }
1157
1146
  return {
1158
1147
  children: children,
@@ -1160,7 +1149,6 @@ function parseTokens(tokens, sourceNodes, cursor) {
1160
1149
  };
1161
1150
  }
1162
1151
  function parseRichTextSource(_ref) {
1163
- var _ref2;
1164
1152
  var templateStrings = _ref.templateStrings,
1165
1153
  nodes = _ref.exprs;
1166
1154
  // TODO: validate that templateStrings does not contain VAL_NODE_PREFIX
@@ -1184,10 +1172,17 @@ function parseRichTextSource(_ref) {
1184
1172
  if (cursor !== tokenList.length) {
1185
1173
  throw Error("Unexpectedly terminated markdown parsing. Possible reason: unclosed html tag?");
1186
1174
  }
1187
- return _ref2 = {}, _defineProperty(_ref2, core.VAL_EXTENSION, "richtext"), _defineProperty(_ref2, "children", children), _ref2;
1175
+ return _defineProperty(_defineProperty({}, core.VAL_EXTENSION, "richtext"), "children", children);
1188
1176
  }
1189
1177
 
1178
+ var VAL_SESSION_COOKIE = core.Internal.VAL_SESSION_COOKIE;
1179
+ var VAL_STATE_COOKIE = core.Internal.VAL_STATE_COOKIE;
1180
+ var VAL_ENABLE_COOKIE_NAME = core.Internal.VAL_ENABLE_COOKIE_NAME;
1181
+
1190
1182
  exports.COMMON_LEXICAL_PROPS = COMMON_LEXICAL_PROPS;
1183
+ exports.VAL_ENABLE_COOKIE_NAME = VAL_ENABLE_COOKIE_NAME;
1184
+ exports.VAL_SESSION_COOKIE = VAL_SESSION_COOKIE;
1185
+ exports.VAL_STATE_COOKIE = VAL_STATE_COOKIE;
1191
1186
  exports.fromLexicalFormat = fromLexicalFormat;
1192
1187
  exports.getMimeType = getMimeType;
1193
1188
  exports.lexicalToRichTextSource = lexicalToRichTextSource;
@@ -560,7 +560,6 @@ function fromIRToRichTextSource(_x) {
560
560
  }
561
561
  function _fromIRToRichTextSource() {
562
562
  _fromIRToRichTextSource = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(markdownIRBlocks) {
563
- var _ref4;
564
563
  var templateStrings, exprs, files, blockIdx, block, _iterator, _step, child, exhaustiveCheck;
565
564
  return _regeneratorRuntime().wrap(function _callee$(_context) {
566
565
  while (1) switch (_context.prev = _context.next) {
@@ -642,7 +641,7 @@ function _fromIRToRichTextSource() {
642
641
  _context.next = 4;
643
642
  break;
644
643
  case 44:
645
- return _context.abrupt("return", (_ref4 = {}, _defineProperty(_ref4, VAL_EXTENSION, "richtext"), _defineProperty(_ref4, "templateStrings", templateStrings), _defineProperty(_ref4, "exprs", exprs), _defineProperty(_ref4, "files", files), _ref4));
644
+ return _context.abrupt("return", _defineProperty(_defineProperty(_defineProperty(_defineProperty({}, VAL_EXTENSION, "richtext"), "templateStrings", templateStrings), "exprs", exprs), "files", files));
646
645
  case 45:
647
646
  case "end":
648
647
  return _context.stop();
@@ -681,11 +680,11 @@ function transformLeafNode(node) {
681
680
  }
682
681
  }
683
682
  function formatListItemNode(listPrefix, node, indent) {
684
- var _node$children, _node$children$;
683
+ var _node$children;
685
684
  var isFirstTopLevelListItem = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : false;
686
685
  var newLine = isFirstTopLevelListItem ? "" : "\n";
687
686
  var prefix = ["".concat(newLine).concat(" ".repeat(indent)).concat(listPrefix)];
688
- if (((_node$children = node.children) === null || _node$children === void 0 ? void 0 : (_node$children$ = _node$children[0]) === null || _node$children$ === void 0 ? void 0 : _node$children$.type) !== "list") {
687
+ if (((_node$children = node.children) === null || _node$children === void 0 || (_node$children = _node$children[0]) === null || _node$children === void 0 ? void 0 : _node$children.type) !== "list") {
689
688
  prefix.push(" ");
690
689
  }
691
690
  return prefix.concat(node.children.flatMap(function (child) {
@@ -733,7 +732,7 @@ function fromLexicalImageNode(_x2, _x3) {
733
732
  }
734
733
  function _fromLexicalImageNode() {
735
734
  _fromLexicalImageNode = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2(node, files) {
736
- var _ref5, sha256, mimeType, fileExt, filePath, _ref6, _sha;
735
+ var sha256, mimeType, fileExt, filePath, _sha;
737
736
  return _regeneratorRuntime().wrap(function _callee2$(_context2) {
738
737
  while (1) switch (_context2.prev = _context2.next) {
739
738
  case 0:
@@ -755,18 +754,18 @@ function _fromLexicalImageNode() {
755
754
  fileExt = mimeTypeToFileExt(mimeType);
756
755
  filePath = "/public/".concat(sha256, ".").concat(fileExt);
757
756
  files[filePath] = node.src;
758
- return _context2.abrupt("return", (_ref5 = {}, _defineProperty(_ref5, VAL_EXTENSION, "file"), _defineProperty(_ref5, FILE_REF_PROP, filePath), _defineProperty(_ref5, "metadata", {
757
+ return _context2.abrupt("return", _defineProperty(_defineProperty(_defineProperty({}, VAL_EXTENSION, "file"), FILE_REF_PROP, filePath), "metadata", {
759
758
  width: node.width || 0,
760
759
  height: node.height || 0,
761
760
  sha256: sha256 || ""
762
- }), _ref5));
761
+ }));
763
762
  case 13:
764
763
  _sha = getParam("sha256", node.src);
765
- return _context2.abrupt("return", (_ref6 = {}, _defineProperty(_ref6, VAL_EXTENSION, "file"), _defineProperty(_ref6, FILE_REF_PROP, "/public".concat(node.src.split("?")[0])), _defineProperty(_ref6, "metadata", {
764
+ return _context2.abrupt("return", _defineProperty(_defineProperty(_defineProperty({}, VAL_EXTENSION, "file"), FILE_REF_PROP, "/public".concat(node.src.split("?")[0])), "metadata", {
766
765
  width: node.width || 0,
767
766
  height: node.height || 0,
768
767
  sha256: _sha || ""
769
- }), _ref6));
768
+ }));
770
769
  case 15:
771
770
  case "end":
772
771
  return _context2.stop();
@@ -788,8 +787,7 @@ function getParam(param, url) {
788
787
  return undefined;
789
788
  }
790
789
  function fromLexicalLinkNode(node) {
791
- var _ref3;
792
- return _ref3 = {}, _defineProperty(_ref3, VAL_EXTENSION, "link"), _defineProperty(_ref3, "href", node.url), _defineProperty(_ref3, "children", node.children.map(formatText)), _ref3;
790
+ return _defineProperty(_defineProperty(_defineProperty({}, VAL_EXTENSION, "link"), "href", node.url), "children", node.children.map(formatText));
793
791
  }
794
792
 
795
793
  function ownKeys(e, r) {
@@ -978,16 +976,6 @@ function toLexicalTextNode(spanNode) {
978
976
  }
979
977
  }
980
978
 
981
- function _typeof(o) {
982
- "@babel/helpers - typeof";
983
-
984
- return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) {
985
- return typeof o;
986
- } : function (o) {
987
- return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o;
988
- }, _typeof(o);
989
- }
990
-
991
979
  var VAL_START_TAG_PREFIX = '<val value="';
992
980
  var VAL_START_TAG_SUFFIX = '">';
993
981
  var VAL_END_TAG = "</val>";
@@ -995,140 +983,141 @@ function parseTokens(tokens, sourceNodes, cursor) {
995
983
  var insideList = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : false;
996
984
  var children = [];
997
985
  var _loop = function _loop() {
998
- var token = tokens[cursor];
999
- if (token.type === "heading") {
1000
- children.push({
1001
- tag: "h".concat(token.depth),
1002
- children: parseTokens(token.tokens ? token.tokens : [], sourceNodes, 0).children
1003
- });
1004
- } else if (token.type === "paragraph") {
1005
- children.push({
1006
- tag: "p",
1007
- children: parseTokens(token.tokens ? token.tokens : [], sourceNodes, 0).children
1008
- });
1009
- } else if (token.type === "strong") {
1010
- children.push({
1011
- tag: "span",
1012
- classes: ["bold"],
1013
- children: parseTokens(token.tokens ? token.tokens : [], sourceNodes, 0).children
1014
- });
1015
- } else if (token.type === "em") {
1016
- children.push({
1017
- tag: "span",
1018
- classes: ["italic"],
1019
- children: parseTokens(token.tokens ? token.tokens : [], sourceNodes, 0).children
1020
- });
1021
- } else if (token.type === "del") {
1022
- children.push({
1023
- tag: "span",
1024
- classes: ["line-through"],
1025
- children: parseTokens(token.tokens ? token.tokens : [], sourceNodes, 0).children
1026
- });
1027
- } else if (token.type === "text") {
1028
- if ("tokens" in token && Array.isArray(token.tokens)) {
1029
- children.push.apply(children, _toConsumableArray(parseTokens(token.tokens, sourceNodes, cursor, insideList).children));
1030
- } else {
1031
- if (insideList && typeof token.raw === "string") {
1032
- var lines = token.raw.split("\n");
1033
- var tags = lines.flatMap(function (line, i) {
1034
- if (i === lines.length - 1) return [line];
1035
- return [line, {
1036
- tag: "br",
1037
- children: []
1038
- }];
1039
- });
1040
- children.push.apply(children, _toConsumableArray(tags));
986
+ var token = tokens[cursor];
987
+ if (token.type === "heading") {
988
+ children.push({
989
+ tag: "h".concat(token.depth),
990
+ children: parseTokens(token.tokens ? token.tokens : [], sourceNodes, 0).children
991
+ });
992
+ } else if (token.type === "paragraph") {
993
+ children.push({
994
+ tag: "p",
995
+ children: parseTokens(token.tokens ? token.tokens : [], sourceNodes, 0).children
996
+ });
997
+ } else if (token.type === "strong") {
998
+ children.push({
999
+ tag: "span",
1000
+ classes: ["bold"],
1001
+ children: parseTokens(token.tokens ? token.tokens : [], sourceNodes, 0).children
1002
+ });
1003
+ } else if (token.type === "em") {
1004
+ children.push({
1005
+ tag: "span",
1006
+ classes: ["italic"],
1007
+ children: parseTokens(token.tokens ? token.tokens : [], sourceNodes, 0).children
1008
+ });
1009
+ } else if (token.type === "del") {
1010
+ children.push({
1011
+ tag: "span",
1012
+ classes: ["line-through"],
1013
+ children: parseTokens(token.tokens ? token.tokens : [], sourceNodes, 0).children
1014
+ });
1015
+ } else if (token.type === "text") {
1016
+ if ("tokens" in token && Array.isArray(token.tokens)) {
1017
+ children.push.apply(children, _toConsumableArray(parseTokens(token.tokens, sourceNodes, cursor, insideList).children));
1041
1018
  } else {
1042
- children.push(token.raw);
1043
- }
1044
- }
1045
- } else if (token.type === "list") {
1046
- children.push({
1047
- tag: token.ordered ? "ol" : "ul",
1048
- children: parseTokens(token.items, sourceNodes, 0).children
1049
- });
1050
- } else if (token.type === "list_item") {
1051
- children.push({
1052
- tag: "li",
1053
- children: parseTokens(token.tokens ? token.tokens : [], sourceNodes, 0, true).children
1054
- });
1055
- } else if (token.type === "space") ; else if (token.type === "html") {
1056
- if (token.text === VAL_END_TAG) {
1057
- return {
1058
- v: {
1059
- children: children,
1060
- cursor: cursor
1019
+ if (insideList && typeof token.raw === "string") {
1020
+ var lines = token.raw.split("\n");
1021
+ var tags = lines.flatMap(function (line, i) {
1022
+ if (i === lines.length - 1) return [line];
1023
+ return [line, {
1024
+ tag: "br",
1025
+ children: []
1026
+ }];
1027
+ });
1028
+ children.push.apply(children, _toConsumableArray(tags));
1029
+ } else {
1030
+ children.push(token.raw);
1061
1031
  }
1062
- };
1063
- }
1064
- var suffixIndex = token.text.indexOf(VAL_START_TAG_SUFFIX);
1065
- if (token.text.startsWith(VAL_START_TAG_PREFIX) && suffixIndex > -1) {
1066
- var number = Number(token.text.slice(VAL_START_TAG_PREFIX.length, suffixIndex));
1067
- if (Number.isNaN(number)) {
1068
- throw Error("Illegal val intermediate node: ".concat(JSON.stringify(token)));
1069
1032
  }
1070
- var _parseTokens = parseTokens(tokens.map(function (token) {
1071
- if (token.type === "link" || token.type === "list") {
1072
- return {
1073
- type: "text",
1074
- raw: token.raw,
1075
- text: token.raw
1076
- };
1033
+ } else if (token.type === "list") {
1034
+ children.push({
1035
+ tag: token.ordered ? "ol" : "ul",
1036
+ children: parseTokens(token.items, sourceNodes, 0).children
1037
+ });
1038
+ } else if (token.type === "list_item") {
1039
+ children.push({
1040
+ tag: "li",
1041
+ children: parseTokens(token.tokens ? token.tokens : [], sourceNodes, 0, true).children
1042
+ });
1043
+ } else if (token.type === "space") ; else if (token.type === "html") {
1044
+ if (token.text === VAL_END_TAG) {
1045
+ return {
1046
+ v: {
1047
+ children: children,
1048
+ cursor: cursor
1077
1049
  }
1078
- return token;
1079
- }), sourceNodes, cursor + 1),
1080
- subChildren = _parseTokens.children,
1081
- subCursor = _parseTokens.cursor;
1082
- var sourceNode = sourceNodes[number];
1083
- if (sourceNode._type === "link") {
1050
+ };
1051
+ }
1052
+ var suffixIndex = token.text.indexOf(VAL_START_TAG_SUFFIX);
1053
+ if (token.text.startsWith(VAL_START_TAG_PREFIX) && suffixIndex > -1) {
1054
+ var number = Number(token.text.slice(VAL_START_TAG_PREFIX.length, suffixIndex));
1055
+ if (Number.isNaN(number)) {
1056
+ throw Error("Illegal val intermediate node: ".concat(JSON.stringify(token)));
1057
+ }
1058
+ var _parseTokens = parseTokens(tokens.map(function (token) {
1059
+ if (token.type === "link" || token.type === "list") {
1060
+ return {
1061
+ type: "text",
1062
+ raw: token.raw,
1063
+ text: token.raw
1064
+ };
1065
+ }
1066
+ return token;
1067
+ }), sourceNodes, cursor + 1),
1068
+ subChildren = _parseTokens.children,
1069
+ subCursor = _parseTokens.cursor;
1070
+ var sourceNode = sourceNodes[number];
1071
+ if (sourceNode._type === "link") {
1072
+ children.push({
1073
+ tag: "a",
1074
+ href: sourceNode.href,
1075
+ children: subChildren
1076
+ });
1077
+ } else if (sourceNode._type === "file") {
1078
+ var _sourceNode$metadata, _sourceNode$metadata2;
1079
+ children.push({
1080
+ tag: "img",
1081
+ src: Internal.convertFileSource(sourceNode).url,
1082
+ width: (_sourceNode$metadata = sourceNode.metadata) === null || _sourceNode$metadata === void 0 ? void 0 : _sourceNode$metadata.width,
1083
+ height: (_sourceNode$metadata2 = sourceNode.metadata) === null || _sourceNode$metadata2 === void 0 ? void 0 : _sourceNode$metadata2.height,
1084
+ children: []
1085
+ });
1086
+ }
1087
+ cursor = subCursor;
1088
+ }
1089
+ var br_html_regex = /<br\s*\/?>/gi; // matches <br>, <br/>, <br />; case insensitive
1090
+ if (token.text.trim().match(br_html_regex)) {
1084
1091
  children.push({
1085
- tag: "a",
1086
- href: sourceNode.href,
1087
- children: subChildren
1092
+ tag: "br",
1093
+ children: []
1088
1094
  });
1089
- } else if (sourceNode._type === "file") {
1090
- var _sourceNode$metadata, _sourceNode$metadata2;
1095
+ }
1096
+ } else if (token.type === "link") {
1097
+ if (token.raw === token.href) {
1098
+ // avoid auto-linking (provided by github flavoured markdown, but we want strikethrough so keep it enabled)
1099
+ children.push(token.raw);
1100
+ } else {
1091
1101
  children.push({
1092
- tag: "img",
1093
- src: Internal.convertFileSource(sourceNode).url,
1094
- width: (_sourceNode$metadata = sourceNode.metadata) === null || _sourceNode$metadata === void 0 ? void 0 : _sourceNode$metadata.width,
1095
- height: (_sourceNode$metadata2 = sourceNode.metadata) === null || _sourceNode$metadata2 === void 0 ? void 0 : _sourceNode$metadata2.height,
1096
- children: []
1102
+ tag: "a",
1103
+ href: token.href,
1104
+ children: parseTokens(token.tokens ? token.tokens : [], sourceNodes, 0).children
1097
1105
  });
1098
1106
  }
1099
- cursor = subCursor;
1100
- }
1101
- var br_html_regex = /<br\s*\/?>/gi; // matches <br>, <br/>, <br />; case insensitive
1102
- if (token.text.trim().match(br_html_regex)) {
1107
+ } else if (token.type === "br") {
1103
1108
  children.push({
1104
1109
  tag: "br",
1105
1110
  children: []
1106
1111
  });
1107
- }
1108
- } else if (token.type === "link") {
1109
- if (token.raw === token.href) {
1110
- // avoid auto-linking (provided by github flavoured markdown, but we want strikethrough so keep it enabled)
1111
- children.push(token.raw);
1112
1112
  } else {
1113
- children.push({
1114
- tag: "a",
1115
- href: token.href,
1116
- children: parseTokens(token.tokens ? token.tokens : [], sourceNodes, 0).children
1117
- });
1113
+ console.error("Could not parse markdown: unsupported token type: ".concat(token.type, ". Found: ").concat(token.raw));
1118
1114
  }
1119
- } else if (token.type === "br") {
1120
- children.push({
1121
- tag: "br",
1122
- children: []
1123
- });
1124
- } else {
1125
- console.error("Could not parse markdown: unsupported token type: ".concat(token.type, ". Found: ").concat(token.raw));
1126
- }
1127
- cursor++;
1128
- };
1115
+ cursor++;
1116
+ },
1117
+ _ret;
1129
1118
  while (cursor < tokens.length) {
1130
- var _ret = _loop();
1131
- if (_typeof(_ret) === "object") return _ret.v;
1119
+ _ret = _loop();
1120
+ if (_ret) return _ret.v;
1132
1121
  }
1133
1122
  return {
1134
1123
  children: children,
@@ -1136,7 +1125,6 @@ function parseTokens(tokens, sourceNodes, cursor) {
1136
1125
  };
1137
1126
  }
1138
1127
  function parseRichTextSource(_ref) {
1139
- var _ref2;
1140
1128
  var templateStrings = _ref.templateStrings,
1141
1129
  nodes = _ref.exprs;
1142
1130
  // TODO: validate that templateStrings does not contain VAL_NODE_PREFIX
@@ -1160,7 +1148,11 @@ function parseRichTextSource(_ref) {
1160
1148
  if (cursor !== tokenList.length) {
1161
1149
  throw Error("Unexpectedly terminated markdown parsing. Possible reason: unclosed html tag?");
1162
1150
  }
1163
- return _ref2 = {}, _defineProperty(_ref2, VAL_EXTENSION, "richtext"), _defineProperty(_ref2, "children", children), _ref2;
1151
+ return _defineProperty(_defineProperty({}, VAL_EXTENSION, "richtext"), "children", children);
1164
1152
  }
1165
1153
 
1166
- export { COMMON_LEXICAL_PROPS, fromLexicalFormat, getMimeType, lexicalToRichTextSource, mimeTypeToFileExt, parseRichTextSource, richTextSourceToLexical, toLexicalFormat, toLexicalNode };
1154
+ var VAL_SESSION_COOKIE = Internal.VAL_SESSION_COOKIE;
1155
+ var VAL_STATE_COOKIE = Internal.VAL_STATE_COOKIE;
1156
+ var VAL_ENABLE_COOKIE_NAME = Internal.VAL_ENABLE_COOKIE_NAME;
1157
+
1158
+ export { COMMON_LEXICAL_PROPS, VAL_ENABLE_COOKIE_NAME, VAL_SESSION_COOKIE, VAL_STATE_COOKIE, fromLexicalFormat, getMimeType, lexicalToRichTextSource, mimeTypeToFileExt, parseRichTextSource, richTextSourceToLexical, toLexicalFormat, toLexicalNode };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@valbuild/shared",
3
- "version": "0.33.0",
3
+ "version": "0.35.0",
4
4
  "private": false,
5
5
  "description": "Val shared types and utilities",
6
6
  "scripts": {
@@ -30,7 +30,7 @@
30
30
  },
31
31
  "devDependencies": {},
32
32
  "dependencies": {
33
- "@valbuild/core": "~0.33.0",
33
+ "@valbuild/core": "~0.35.0",
34
34
  "marked": "^9.0.3"
35
35
  },
36
36
  "files": [