@valbuild/core 0.62.6 → 0.63.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,6 +1,28 @@
1
1
  'use strict';
2
2
 
3
3
  var result = require('./result-48320acd.cjs.dev.js');
4
+ var marked = require('marked');
5
+ var core = require('@valbuild/core');
6
+
7
+ function _interopNamespace(e) {
8
+ if (e && e.__esModule) return e;
9
+ var n = Object.create(null);
10
+ if (e) {
11
+ Object.keys(e).forEach(function (k) {
12
+ if (k !== 'default') {
13
+ var d = Object.getOwnPropertyDescriptor(e, k);
14
+ Object.defineProperty(n, k, d.get ? d : {
15
+ enumerable: true,
16
+ get: function () { return e[k]; }
17
+ });
18
+ }
19
+ });
20
+ }
21
+ n["default"] = e;
22
+ return Object.freeze(n);
23
+ }
24
+
25
+ var marked__namespace = /*#__PURE__*/_interopNamespace(marked);
4
26
 
5
27
  function _arrayWithoutHoles(arr) {
6
28
  if (Array.isArray(arr)) return result._arrayLikeToArray(arr);
@@ -397,7 +419,7 @@ var VAL_EXTENSION = "_type";
397
419
  **/
398
420
 
399
421
  var FILE_REF_PROP = "_ref";
400
- var FILE_REF_SUBTYPE_TAG = "_tag";
422
+ var FILE_REF_SUBTYPE_TAG = "_tag"; // TODO: used earlier by c.rt.image, when we remove c.rt we can remove this
401
423
 
402
424
  /**
403
425
  * A file source represents the path to a (local) file.
@@ -904,7 +926,7 @@ var ParserError = /*#__PURE__*/_createClass(function ParserError(message, span)
904
926
  this.message = message;
905
927
  this.span = span;
906
928
  });
907
- function parseTokens(inputTokens) {
929
+ function parseTokens$1(inputTokens) {
908
930
  var tokens = inputTokens.slice();
909
931
  function slurpCall(first, isAnon) {
910
932
  var _tokens$, _tokens$2, _tokens$3, _tokens$7, _tokens$8, _args$slice$0$span;
@@ -1040,7 +1062,7 @@ function parse$1(input) {
1040
1062
  _tokenize2 = _slicedToArray(_tokenize, 2),
1041
1063
  tokens = _tokenize2[0];
1042
1064
  _tokenize2[1]; // TODO: we can use cursor to improve error messages / spans
1043
- return parseTokens(tokens);
1065
+ return parseTokens$1(tokens);
1044
1066
  }
1045
1067
 
1046
1068
  /* eslint-disable @typescript-eslint/no-unused-vars */
@@ -1769,6 +1791,14 @@ var RichTextSchema = /*#__PURE__*/function (_Schema) {
1769
1791
  _createClass(RichTextSchema, [{
1770
1792
  key: "validate",
1771
1793
  value: function validate(path, src) {
1794
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
1795
+ if (src !== null && src !== void 0 && src.markdownish) {
1796
+ return _defineProperty({}, path, [{
1797
+ message: "Replace markdown with structured format",
1798
+ value: src,
1799
+ fixes: ["fix:deprecated-richtext"]
1800
+ }]);
1801
+ }
1772
1802
  return false; //TODO
1773
1803
  }
1774
1804
  }, {
@@ -2584,40 +2614,247 @@ function initSchema() {
2584
2614
  };
2585
2615
  }
2586
2616
 
2587
- // Classes
2617
+ var VAL_START_TAG_PREFIX = '<val value="';
2618
+ var VAL_START_TAG_SUFFIX = '">';
2619
+ var VAL_END_TAG = "</val>";
2620
+ function parseTokens(tokens, sourceNodes, cursor) {
2621
+ var insideList = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : false;
2622
+ var children = [];
2623
+ function merge(token, clazz) {
2624
+ var parsedTokens = parseTokens(token.tokens ? token.tokens : [], sourceNodes, 0);
2625
+ children.push({
2626
+ tag: "span",
2627
+ styles: [clazz].concat(parsedTokens.children.flatMap(function (child) {
2628
+ return typeof child === "string" ? [] : child.styles;
2629
+ })),
2630
+ children: parsedTokens.children.flatMap(function (child) {
2631
+ return typeof child === "string" ? child : child.children;
2632
+ })
2633
+ });
2634
+ }
2635
+ var _loop = function _loop() {
2636
+ var token = tokens[cursor];
2637
+ if (token.type === "heading") {
2638
+ children.push({
2639
+ tag: "h".concat(token.depth),
2640
+ children: parseTokens(token.tokens ? token.tokens : [], sourceNodes, 0).children
2641
+ });
2642
+ } else if (token.type === "paragraph") {
2643
+ children.push({
2644
+ tag: "p",
2645
+ children: parseTokens(token.tokens ? token.tokens : [], sourceNodes, 0).children
2646
+ });
2647
+ } else if (token.type === "strong") {
2648
+ merge(token, "bold");
2649
+ } else if (token.type === "em") {
2650
+ merge(token, "italic");
2651
+ } else if (token.type === "del") {
2652
+ merge(token, "line-through");
2653
+ } else if (token.type === "text") {
2654
+ if ("tokens" in token && Array.isArray(token.tokens)) {
2655
+ children.push.apply(children, _toConsumableArray(parseTokens(token.tokens, sourceNodes, cursor, insideList).children));
2656
+ } else {
2657
+ if (insideList && typeof token.raw === "string") {
2658
+ var lines = token.raw.split("\n");
2659
+ var tags = lines.flatMap(function (line, i) {
2660
+ if (i === lines.length - 1) return [line];
2661
+ if (i === lines.length - 1 && line === "") return [];
2662
+ if (line === "") return [{
2663
+ tag: "p",
2664
+ children: [{
2665
+ tag: "br"
2666
+ }]
2667
+ }];
2668
+ return [line, {
2669
+ tag: "p",
2670
+ children: [{
2671
+ tag: "br"
2672
+ }]
2673
+ }];
2674
+ });
2675
+ children.push.apply(children, _toConsumableArray(tags));
2676
+ } else {
2677
+ children.push(token.raw);
2678
+ }
2679
+ }
2680
+ } else if (token.type === "list") {
2681
+ children.push({
2682
+ tag: token.ordered ? "ol" : "ul",
2683
+ children: parseTokens(token.items, sourceNodes, 0).children
2684
+ });
2685
+ } else if (token.type === "list_item") {
2686
+ children.push({
2687
+ tag: "li",
2688
+ children: [{
2689
+ tag: "p",
2690
+ children: parseTokens(token.tokens ? token.tokens : [], sourceNodes, 0, true).children
2691
+ }]
2692
+ });
2693
+ } else if (token.type === "space") ; else if (token.type === "html") {
2694
+ if (token.text === VAL_END_TAG) {
2695
+ return {
2696
+ v: {
2697
+ children: children,
2698
+ cursor: cursor
2699
+ }
2700
+ };
2701
+ }
2702
+ var suffixIndex = token.text.indexOf(VAL_START_TAG_SUFFIX);
2703
+ if (token.text.startsWith(VAL_START_TAG_PREFIX) && suffixIndex > -1) {
2704
+ var number = Number(token.text.slice(VAL_START_TAG_PREFIX.length, suffixIndex));
2705
+ if (Number.isNaN(number)) {
2706
+ throw Error("Illegal val intermediate node: ".concat(JSON.stringify(token)));
2707
+ }
2708
+ var _parseTokens = parseTokens(tokens.map(function (token) {
2709
+ if (token.type === "link" || token.type === "list") {
2710
+ return {
2711
+ type: "text",
2712
+ raw: token.raw,
2713
+ text: token.raw
2714
+ };
2715
+ }
2716
+ return token;
2717
+ }), sourceNodes, cursor + 1),
2718
+ subChildren = _parseTokens.children,
2719
+ subCursor = _parseTokens.cursor;
2720
+ var sourceNode = sourceNodes[number];
2721
+ if (sourceNode._type === "link") {
2722
+ children.push({
2723
+ tag: "a",
2724
+ href: sourceNode.href,
2725
+ children: subChildren
2726
+ });
2727
+ } else if (sourceNode._type === "file") {
2728
+ // @ts-expect-error We are transitioning from markdown to structured objects, with structured objects we no longer want c.rt.image
2729
+ delete sourceNode[core.FILE_REF_SUBTYPE_TAG];
2730
+ children.push({
2731
+ tag: "img",
2732
+ src: sourceNode
2733
+ });
2734
+ }
2735
+ cursor = subCursor;
2736
+ }
2737
+ var br_html_regex = /<br\s*\/?>/gi; // matches <br>, <br/>, <br />; case insensitive
2738
+ if (token.text.trim().match(br_html_regex)) {
2739
+ var _tokens;
2740
+ children.push({
2741
+ tag: "p",
2742
+ children: [{
2743
+ tag: "br"
2744
+ }]
2745
+ });
2746
+ if (((_tokens = tokens[cursor + 1]) === null || _tokens === void 0 ? void 0 : _tokens.raw.trim()) === "") {
2747
+ // if next token is a new line or white-spaces, skip it
2748
+ // this typically means we have a <br> AND a new line, which, semantically, is just a <br>
2749
+ cursor++;
2750
+ }
2751
+ }
2752
+ } else if (token.type === "link") {
2753
+ if (token.raw === token.href) {
2754
+ // avoid auto-linking (provided by github flavoured markdown, but we want strikethrough so keep it enabled)
2755
+ children.push(token.raw);
2756
+ } else {
2757
+ children.push({
2758
+ tag: "a",
2759
+ href: token.href,
2760
+ children: parseTokens(token.tokens ? token.tokens : [], sourceNodes, 0).children
2761
+ });
2762
+ }
2763
+ } else if (token.type === "br") {
2764
+ children.push({
2765
+ tag: "p",
2766
+ children: [{
2767
+ tag: "br"
2768
+ }]
2769
+ });
2770
+ } else {
2771
+ console.error("Could not parse markdown: unsupported token type: ".concat(token.type, ". Found: ").concat(token.raw));
2772
+ }
2773
+ cursor++;
2774
+ },
2775
+ _ret;
2776
+ while (cursor < tokens.length) {
2777
+ _ret = _loop();
2778
+ if (_ret) return _ret.v;
2779
+ }
2780
+ return {
2781
+ children: children,
2782
+ cursor: cursor
2783
+ };
2784
+ }
2785
+ function parseRichTextSource(_ref) {
2786
+ var templateStrings = _ref.templateStrings,
2787
+ nodes = _ref.exprs;
2788
+ // TODO: validate that templateStrings does not contain VAL_NODE_PREFIX
2789
+ var inputText = templateStrings.flatMap(function (templateString, i) {
2790
+ var node = nodes[i];
2791
+ if (node) {
2792
+ if (node[core.VAL_EXTENSION] === "link") {
2793
+ return templateString.concat("".concat(VAL_START_TAG_PREFIX).concat(i).concat(VAL_START_TAG_SUFFIX).concat(node.children[0]).concat(VAL_END_TAG));
2794
+ } else {
2795
+ return templateString.concat("".concat(VAL_START_TAG_PREFIX).concat(i).concat(VAL_START_TAG_SUFFIX).concat(VAL_END_TAG));
2796
+ }
2797
+ }
2798
+ return templateString;
2799
+ }).join("");
2800
+ var tokenList = marked__namespace.lexer(inputText, {
2801
+ gfm: true
2802
+ });
2803
+ var _parseTokens2 = parseTokens(tokenList, nodes, 0),
2804
+ children = _parseTokens2.children,
2805
+ cursor = _parseTokens2.cursor;
2806
+ if (cursor !== tokenList.length) {
2807
+ throw Error("Unexpectedly terminated markdown parsing. Possible reason: unclosed html tag?");
2808
+ }
2809
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
2810
+ children.markdownish = true; // Markdown is an intermediate format - we are planning on replacing it with a structured object format
2811
+ return children;
2812
+ }
2813
+
2814
+ //#region Classes
2588
2815
 
2589
- /// Paragraph
2816
+ //#region Paragraph
2590
2817
 
2591
- /// Break
2818
+ //#region Break
2592
2819
 
2593
- /// Span
2820
+ //#region Span
2594
2821
 
2595
- /// Image
2822
+ //#region Image
2596
2823
 
2597
- /// Link
2824
+ //#region Link
2598
2825
 
2599
- /// List
2826
+ //#region List
2600
2827
 
2601
- /// Heading
2828
+ //#region Heading
2829
+
2830
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
2602
2831
 
2603
- /// Root and nodes
2832
+ // export type CustomInlineNode<O extends RichTextOptions> = NonNullable<
2833
+ // NonNullable<O["inline"]>["custom"]
2834
+ // >[keyof NonNullable<NonNullable<O["inline"]>["custom"]>] extends Schema<
2835
+ // infer Src
2836
+ // >
2837
+ // ? ReplaceRawStringWithString<Src>
2838
+ // : never;
2839
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
2604
2840
 
2605
- /// Main types
2841
+ //#region Block and Inline nodes:
2606
2842
 
2607
- /**
2608
- * RichTextSource is defined in ValModules
2609
- **/
2843
+ //#region Main types
2610
2844
 
2611
2845
  /**
2612
- * RichText is accessible by users (after conversion via useVal / fetchVal)
2613
- * Internally it is a Selector
2846
+ * RichText as defined in a ValModule
2614
2847
  **/
2615
2848
 
2616
2849
  function richtext(templateStrings) {
2617
2850
  for (var _len = arguments.length, nodes = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
2618
2851
  nodes[_key - 1] = arguments[_key];
2619
2852
  }
2620
- return _defineProperty(_defineProperty(_defineProperty({}, VAL_EXTENSION, "richtext"), "templateStrings", templateStrings), "exprs", nodes);
2853
+ return parseRichTextSource({
2854
+ templateStrings: templateStrings,
2855
+ exprs: nodes
2856
+ // eslint-disable-next-line @typescript-eslint/ban-types
2857
+ });
2621
2858
  }
2622
2859
  var RT_IMAGE_TAG = "rt_image";
2623
2860
  function image(ref, metadata) {
@@ -2,8 +2,10 @@
2
2
 
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
- var expr_dist_valbuildCoreExpr = require('./index-3193efd5.cjs.dev.js');
5
+ var expr_dist_valbuildCoreExpr = require('./index-796c5d0d.cjs.dev.js');
6
6
  require('./result-48320acd.cjs.dev.js');
7
+ require('marked');
8
+ require('@valbuild/core');
7
9
 
8
10
 
9
11
 
@@ -2,8 +2,10 @@
2
2
 
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
- var expr_dist_valbuildCoreExpr = require('./index-596f28bb.cjs.prod.js');
5
+ var expr_dist_valbuildCoreExpr = require('./index-00decfd4.cjs.prod.js');
6
6
  require('./result-26f67b40.cjs.prod.js');
7
+ require('marked');
8
+ require('@valbuild/core');
7
9
 
8
10
 
9
11
 
@@ -1,2 +1,4 @@
1
- export { A as ArraySchema, B as BooleanSchema, F as FATAL_ERROR_TYPES, k as FILE_REF_PROP, l as FILE_REF_SUBTYPE_TAG, u as FileSchema, G as GenericSelector, t as ImageSchema, I as Internal, L as LiteralSchema, r as NumberSchema, O as ObjectSchema, R as RT_IMAGE_TAG, o as RecordSchema, v as RichTextSchema, j as Schema, q as StringSchema, U as UnionSchema, V as VAL_EXTENSION, x as ValApi, n as derefPatch, w as deserializeSchema, i as expr, h as initVal, m as modules } from './index-316f5dd8.esm.js';
1
+ export { A as ArraySchema, B as BooleanSchema, F as FATAL_ERROR_TYPES, k as FILE_REF_PROP, l as FILE_REF_SUBTYPE_TAG, u as FileSchema, G as GenericSelector, t as ImageSchema, I as Internal, L as LiteralSchema, r as NumberSchema, O as ObjectSchema, R as RT_IMAGE_TAG, o as RecordSchema, v as RichTextSchema, j as Schema, q as StringSchema, U as UnionSchema, V as VAL_EXTENSION, x as ValApi, n as derefPatch, w as deserializeSchema, i as expr, h as initVal, m as modules } from './index-370592bb.esm.js';
2
2
  import './result-a8316efa.esm.js';
3
+ import 'marked';
4
+ import '@valbuild/core';
@@ -2,8 +2,10 @@
2
2
 
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
- var expr_dist_valbuildCoreExpr = require('../../dist/index-3193efd5.cjs.dev.js');
5
+ var expr_dist_valbuildCoreExpr = require('../../dist/index-796c5d0d.cjs.dev.js');
6
6
  require('../../dist/result-48320acd.cjs.dev.js');
7
+ require('marked');
8
+ require('@valbuild/core');
7
9
 
8
10
 
9
11
 
@@ -2,8 +2,10 @@
2
2
 
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
- var expr_dist_valbuildCoreExpr = require('../../dist/index-596f28bb.cjs.prod.js');
5
+ var expr_dist_valbuildCoreExpr = require('../../dist/index-00decfd4.cjs.prod.js');
6
6
  require('../../dist/result-26f67b40.cjs.prod.js');
7
+ require('marked');
8
+ require('@valbuild/core');
7
9
 
8
10
 
9
11
 
@@ -1,2 +1,4 @@
1
- export { C as Call, E as Expr, N as NilSym, S as StringLiteral, e as StringTemplate, f as Sym, g as evaluate, p as parse } from '../../dist/index-316f5dd8.esm.js';
1
+ export { C as Call, E as Expr, N as NilSym, S as StringLiteral, e as StringTemplate, f as Sym, g as evaluate, p as parse } from '../../dist/index-370592bb.esm.js';
2
2
  import '../../dist/result-a8316efa.esm.js';
3
+ import 'marked';
4
+ import '@valbuild/core';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@valbuild/core",
3
- "version": "0.62.6",
3
+ "version": "0.63.0",
4
4
  "private": false,
5
5
  "description": "Val - supercharged hard-coded content",
6
6
  "scripts": {
@@ -41,6 +41,7 @@
41
41
  },
42
42
  "devDependencies": {},
43
43
  "dependencies": {
44
+ "marked": "^9.0.3",
44
45
  "ts-toolbelt": "^9.6.0"
45
46
  },
46
47
  "files": [
@@ -2,9 +2,11 @@
2
2
 
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
- var expr_dist_valbuildCoreExpr = require('../../dist/index-3193efd5.cjs.dev.js');
5
+ var expr_dist_valbuildCoreExpr = require('../../dist/index-796c5d0d.cjs.dev.js');
6
6
  var result = require('../../dist/result-48320acd.cjs.dev.js');
7
7
  var util = require('../../dist/util-b213092b.cjs.dev.js');
8
+ require('marked');
9
+ require('@valbuild/core');
8
10
 
9
11
  function isNotRoot(path) {
10
12
  return result.isNonEmpty(path);
@@ -2,9 +2,11 @@
2
2
 
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
- var expr_dist_valbuildCoreExpr = require('../../dist/index-596f28bb.cjs.prod.js');
5
+ var expr_dist_valbuildCoreExpr = require('../../dist/index-00decfd4.cjs.prod.js');
6
6
  var result = require('../../dist/result-26f67b40.cjs.prod.js');
7
7
  var util = require('../../dist/util-030d8a1f.cjs.prod.js');
8
+ require('marked');
9
+ require('@valbuild/core');
8
10
 
9
11
  function isNotRoot(path) {
10
12
  return result.isNonEmpty(path);
@@ -1,7 +1,9 @@
1
- import { _ as _typeof, a as _slicedToArray, P as PatchError, s as splitModuleFilePathAndModulePath, b as _createClass, c as _classCallCheck, d as _toConsumableArray } from '../../dist/index-316f5dd8.esm.js';
2
- export { P as PatchError } from '../../dist/index-316f5dd8.esm.js';
1
+ import { _ as _typeof, a as _slicedToArray, P as PatchError, s as splitModuleFilePathAndModulePath, b as _createClass, c as _classCallCheck, d as _toConsumableArray } from '../../dist/index-370592bb.esm.js';
2
+ export { P as PatchError } from '../../dist/index-370592bb.esm.js';
3
3
  import { f as isNonEmpty, e as err, o as ok, m as map, g as flatMap, i as isErr, h as flatMapReduce, j as filterOrElse, k as mapErr, l as map$1, n as all, p as flatten, q as allT } from '../../dist/result-a8316efa.esm.js';
4
4
  import { p as pipe } from '../../dist/util-18613e99.esm.js';
5
+ import 'marked';
6
+ import '@valbuild/core';
5
7
 
6
8
  function isNotRoot(path) {
7
9
  return isNonEmpty(path);