@supernova-studio/client 0.0.11 → 0.0.12

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/index.js CHANGED
@@ -2058,7 +2058,7 @@ var CreateWorkspaceInput = _zod.z.object({
2058
2058
  product: ProductCodeSchema,
2059
2059
  priceId: _zod.z.string(),
2060
2060
  billingEmail: _zod.z.string().email().optional(),
2061
- handle: _zod.z.string().regex(slugRegex).min(HANDLE_MIN_LENGTH).max(HANDLE_MAX_LENGTH).refine((value) => _optionalChain([value, 'optionalAccess', _2 => _2.length]) > 0).optional(),
2061
+ handle: _zod.z.string().regex(slugRegex).min(HANDLE_MIN_LENGTH).max(HANDLE_MAX_LENGTH).refine((value) => _optionalChain([value, 'optionalAccess', _ => _.length]) > 0).optional(),
2062
2062
  invites: UserInvites.optional(),
2063
2063
  promoCode: _zod.z.string().optional()
2064
2064
  });
@@ -2596,2393 +2596,8 @@ var DocumentationPageEditorModel = _zod.z.object({
2596
2596
  blocks: _zod.z.array(PageBlockEditorModel)
2597
2597
  });
2598
2598
 
2599
- // ../../node_modules/orderedmap/dist/index.js
2600
- function OrderedMap(content) {
2601
- this.content = content;
2602
- }
2603
- OrderedMap.prototype = {
2604
- constructor: OrderedMap,
2605
- find: function(key) {
2606
- for (var i = 0; i < this.content.length; i += 2)
2607
- if (this.content[i] === key)
2608
- return i;
2609
- return -1;
2610
- },
2611
- // :: (string) → ?any
2612
- // Retrieve the value stored under `key`, or return undefined when
2613
- // no such key exists.
2614
- get: function(key) {
2615
- var found2 = this.find(key);
2616
- return found2 == -1 ? void 0 : this.content[found2 + 1];
2617
- },
2618
- // :: (string, any, ?string) → OrderedMap
2619
- // Create a new map by replacing the value of `key` with a new
2620
- // value, or adding a binding to the end of the map. If `newKey` is
2621
- // given, the key of the binding will be replaced with that key.
2622
- update: function(key, value, newKey) {
2623
- var self = newKey && newKey != key ? this.remove(newKey) : this;
2624
- var found2 = self.find(key), content = self.content.slice();
2625
- if (found2 == -1) {
2626
- content.push(newKey || key, value);
2627
- } else {
2628
- content[found2 + 1] = value;
2629
- if (newKey)
2630
- content[found2] = newKey;
2631
- }
2632
- return new OrderedMap(content);
2633
- },
2634
- // :: (string) → OrderedMap
2635
- // Return a map with the given key removed, if it existed.
2636
- remove: function(key) {
2637
- var found2 = this.find(key);
2638
- if (found2 == -1)
2639
- return this;
2640
- var content = this.content.slice();
2641
- content.splice(found2, 2);
2642
- return new OrderedMap(content);
2643
- },
2644
- // :: (string, any) → OrderedMap
2645
- // Add a new key to the start of the map.
2646
- addToStart: function(key, value) {
2647
- return new OrderedMap([key, value].concat(this.remove(key).content));
2648
- },
2649
- // :: (string, any) → OrderedMap
2650
- // Add a new key to the end of the map.
2651
- addToEnd: function(key, value) {
2652
- var content = this.remove(key).content.slice();
2653
- content.push(key, value);
2654
- return new OrderedMap(content);
2655
- },
2656
- // :: (string, string, any) → OrderedMap
2657
- // Add a key after the given key. If `place` is not found, the new
2658
- // key is added to the end.
2659
- addBefore: function(place, key, value) {
2660
- var without = this.remove(key), content = without.content.slice();
2661
- var found2 = without.find(place);
2662
- content.splice(found2 == -1 ? content.length : found2, 0, key, value);
2663
- return new OrderedMap(content);
2664
- },
2665
- // :: ((key: string, value: any))
2666
- // Call the given function for each key/value pair in the map, in
2667
- // order.
2668
- forEach: function(f) {
2669
- for (var i = 0; i < this.content.length; i += 2)
2670
- f(this.content[i], this.content[i + 1]);
2671
- },
2672
- // :: (union<Object, OrderedMap>) → OrderedMap
2673
- // Create a new map by prepending the keys in this map that don't
2674
- // appear in `map` before the keys in `map`.
2675
- prepend: function(map) {
2676
- map = OrderedMap.from(map);
2677
- if (!map.size)
2678
- return this;
2679
- return new OrderedMap(map.content.concat(this.subtract(map).content));
2680
- },
2681
- // :: (union<Object, OrderedMap>) → OrderedMap
2682
- // Create a new map by appending the keys in this map that don't
2683
- // appear in `map` after the keys in `map`.
2684
- append: function(map) {
2685
- map = OrderedMap.from(map);
2686
- if (!map.size)
2687
- return this;
2688
- return new OrderedMap(this.subtract(map).content.concat(map.content));
2689
- },
2690
- // :: (union<Object, OrderedMap>) → OrderedMap
2691
- // Create a map containing all the keys in this map that don't
2692
- // appear in `map`.
2693
- subtract: function(map) {
2694
- var result = this;
2695
- map = OrderedMap.from(map);
2696
- for (var i = 0; i < map.content.length; i += 2)
2697
- result = result.remove(map.content[i]);
2698
- return result;
2699
- },
2700
- // :: () → Object
2701
- // Turn ordered map into a plain object.
2702
- toObject: function() {
2703
- var result = {};
2704
- this.forEach(function(key, value) {
2705
- result[key] = value;
2706
- });
2707
- return result;
2708
- },
2709
- // :: number
2710
- // The amount of keys in this map.
2711
- get size() {
2712
- return this.content.length >> 1;
2713
- }
2714
- };
2715
- OrderedMap.from = function(value) {
2716
- if (value instanceof OrderedMap)
2717
- return value;
2718
- var content = [];
2719
- if (value)
2720
- for (var prop in value)
2721
- content.push(prop, value[prop]);
2722
- return new OrderedMap(content);
2723
- };
2724
- var dist_default = OrderedMap;
2725
-
2726
- // ../../node_modules/prosemirror-model/dist/index.js
2727
- function findDiffStart(a, b, pos) {
2728
- for (let i = 0; ; i++) {
2729
- if (i == a.childCount || i == b.childCount)
2730
- return a.childCount == b.childCount ? null : pos;
2731
- let childA = a.child(i), childB = b.child(i);
2732
- if (childA == childB) {
2733
- pos += childA.nodeSize;
2734
- continue;
2735
- }
2736
- if (!childA.sameMarkup(childB))
2737
- return pos;
2738
- if (childA.isText && childA.text != childB.text) {
2739
- for (let j = 0; childA.text[j] == childB.text[j]; j++)
2740
- pos++;
2741
- return pos;
2742
- }
2743
- if (childA.content.size || childB.content.size) {
2744
- let inner = findDiffStart(childA.content, childB.content, pos + 1);
2745
- if (inner != null)
2746
- return inner;
2747
- }
2748
- pos += childA.nodeSize;
2749
- }
2750
- }
2751
- function findDiffEnd(a, b, posA, posB) {
2752
- for (let iA = a.childCount, iB = b.childCount; ; ) {
2753
- if (iA == 0 || iB == 0)
2754
- return iA == iB ? null : { a: posA, b: posB };
2755
- let childA = a.child(--iA), childB = b.child(--iB), size = childA.nodeSize;
2756
- if (childA == childB) {
2757
- posA -= size;
2758
- posB -= size;
2759
- continue;
2760
- }
2761
- if (!childA.sameMarkup(childB))
2762
- return { a: posA, b: posB };
2763
- if (childA.isText && childA.text != childB.text) {
2764
- let same = 0, minSize = Math.min(childA.text.length, childB.text.length);
2765
- while (same < minSize && childA.text[childA.text.length - same - 1] == childB.text[childB.text.length - same - 1]) {
2766
- same++;
2767
- posA--;
2768
- posB--;
2769
- }
2770
- return { a: posA, b: posB };
2771
- }
2772
- if (childA.content.size || childB.content.size) {
2773
- let inner = findDiffEnd(childA.content, childB.content, posA - 1, posB - 1);
2774
- if (inner)
2775
- return inner;
2776
- }
2777
- posA -= size;
2778
- posB -= size;
2779
- }
2780
- }
2781
- var Fragment = class _Fragment {
2782
- /**
2783
- @internal
2784
- */
2785
- constructor(content, size) {
2786
- this.content = content;
2787
- this.size = size || 0;
2788
- if (size == null)
2789
- for (let i = 0; i < content.length; i++)
2790
- this.size += content[i].nodeSize;
2791
- }
2792
- /**
2793
- Invoke a callback for all descendant nodes between the given two
2794
- positions (relative to start of this fragment). Doesn't descend
2795
- into a node when the callback returns `false`.
2796
- */
2797
- nodesBetween(from, to, f, nodeStart = 0, parent) {
2798
- for (let i = 0, pos = 0; pos < to; i++) {
2799
- let child = this.content[i], end = pos + child.nodeSize;
2800
- if (end > from && f(child, nodeStart + pos, parent || null, i) !== false && child.content.size) {
2801
- let start = pos + 1;
2802
- child.nodesBetween(Math.max(0, from - start), Math.min(child.content.size, to - start), f, nodeStart + start);
2803
- }
2804
- pos = end;
2805
- }
2806
- }
2807
- /**
2808
- Call the given callback for every descendant node. `pos` will be
2809
- relative to the start of the fragment. The callback may return
2810
- `false` to prevent traversal of a given node's children.
2811
- */
2812
- descendants(f) {
2813
- this.nodesBetween(0, this.size, f);
2814
- }
2815
- /**
2816
- Extract the text between `from` and `to`. See the same method on
2817
- [`Node`](https://prosemirror.net/docs/ref/#model.Node.textBetween).
2818
- */
2819
- textBetween(from, to, blockSeparator, leafText) {
2820
- let text = "", first = true;
2821
- this.nodesBetween(from, to, (node, pos) => {
2822
- let nodeText = node.isText ? node.text.slice(Math.max(from, pos) - pos, to - pos) : !node.isLeaf ? "" : leafText ? typeof leafText === "function" ? leafText(node) : leafText : node.type.spec.leafText ? node.type.spec.leafText(node) : "";
2823
- if (node.isBlock && (node.isLeaf && nodeText || node.isTextblock) && blockSeparator) {
2824
- if (first)
2825
- first = false;
2826
- else
2827
- text += blockSeparator;
2828
- }
2829
- text += nodeText;
2830
- }, 0);
2831
- return text;
2832
- }
2833
- /**
2834
- Create a new fragment containing the combined content of this
2835
- fragment and the other.
2836
- */
2837
- append(other) {
2838
- if (!other.size)
2839
- return this;
2840
- if (!this.size)
2841
- return other;
2842
- let last = this.lastChild, first = other.firstChild, content = this.content.slice(), i = 0;
2843
- if (last.isText && last.sameMarkup(first)) {
2844
- content[content.length - 1] = last.withText(last.text + first.text);
2845
- i = 1;
2846
- }
2847
- for (; i < other.content.length; i++)
2848
- content.push(other.content[i]);
2849
- return new _Fragment(content, this.size + other.size);
2850
- }
2851
- /**
2852
- Cut out the sub-fragment between the two given positions.
2853
- */
2854
- cut(from, to = this.size) {
2855
- if (from == 0 && to == this.size)
2856
- return this;
2857
- let result = [], size = 0;
2858
- if (to > from)
2859
- for (let i = 0, pos = 0; pos < to; i++) {
2860
- let child = this.content[i], end = pos + child.nodeSize;
2861
- if (end > from) {
2862
- if (pos < from || end > to) {
2863
- if (child.isText)
2864
- child = child.cut(Math.max(0, from - pos), Math.min(child.text.length, to - pos));
2865
- else
2866
- child = child.cut(Math.max(0, from - pos - 1), Math.min(child.content.size, to - pos - 1));
2867
- }
2868
- result.push(child);
2869
- size += child.nodeSize;
2870
- }
2871
- pos = end;
2872
- }
2873
- return new _Fragment(result, size);
2874
- }
2875
- /**
2876
- @internal
2877
- */
2878
- cutByIndex(from, to) {
2879
- if (from == to)
2880
- return _Fragment.empty;
2881
- if (from == 0 && to == this.content.length)
2882
- return this;
2883
- return new _Fragment(this.content.slice(from, to));
2884
- }
2885
- /**
2886
- Create a new fragment in which the node at the given index is
2887
- replaced by the given node.
2888
- */
2889
- replaceChild(index, node) {
2890
- let current = this.content[index];
2891
- if (current == node)
2892
- return this;
2893
- let copy = this.content.slice();
2894
- let size = this.size + node.nodeSize - current.nodeSize;
2895
- copy[index] = node;
2896
- return new _Fragment(copy, size);
2897
- }
2898
- /**
2899
- Create a new fragment by prepending the given node to this
2900
- fragment.
2901
- */
2902
- addToStart(node) {
2903
- return new _Fragment([node].concat(this.content), this.size + node.nodeSize);
2904
- }
2905
- /**
2906
- Create a new fragment by appending the given node to this
2907
- fragment.
2908
- */
2909
- addToEnd(node) {
2910
- return new _Fragment(this.content.concat(node), this.size + node.nodeSize);
2911
- }
2912
- /**
2913
- Compare this fragment to another one.
2914
- */
2915
- eq(other) {
2916
- if (this.content.length != other.content.length)
2917
- return false;
2918
- for (let i = 0; i < this.content.length; i++)
2919
- if (!this.content[i].eq(other.content[i]))
2920
- return false;
2921
- return true;
2922
- }
2923
- /**
2924
- The first child of the fragment, or `null` if it is empty.
2925
- */
2926
- get firstChild() {
2927
- return this.content.length ? this.content[0] : null;
2928
- }
2929
- /**
2930
- The last child of the fragment, or `null` if it is empty.
2931
- */
2932
- get lastChild() {
2933
- return this.content.length ? this.content[this.content.length - 1] : null;
2934
- }
2935
- /**
2936
- The number of child nodes in this fragment.
2937
- */
2938
- get childCount() {
2939
- return this.content.length;
2940
- }
2941
- /**
2942
- Get the child node at the given index. Raise an error when the
2943
- index is out of range.
2944
- */
2945
- child(index) {
2946
- let found2 = this.content[index];
2947
- if (!found2)
2948
- throw new RangeError("Index " + index + " out of range for " + this);
2949
- return found2;
2950
- }
2951
- /**
2952
- Get the child node at the given index, if it exists.
2953
- */
2954
- maybeChild(index) {
2955
- return this.content[index] || null;
2956
- }
2957
- /**
2958
- Call `f` for every child node, passing the node, its offset
2959
- into this parent node, and its index.
2960
- */
2961
- forEach(f) {
2962
- for (let i = 0, p = 0; i < this.content.length; i++) {
2963
- let child = this.content[i];
2964
- f(child, p, i);
2965
- p += child.nodeSize;
2966
- }
2967
- }
2968
- /**
2969
- Find the first position at which this fragment and another
2970
- fragment differ, or `null` if they are the same.
2971
- */
2972
- findDiffStart(other, pos = 0) {
2973
- return findDiffStart(this, other, pos);
2974
- }
2975
- /**
2976
- Find the first position, searching from the end, at which this
2977
- fragment and the given fragment differ, or `null` if they are
2978
- the same. Since this position will not be the same in both
2979
- nodes, an object with two separate positions is returned.
2980
- */
2981
- findDiffEnd(other, pos = this.size, otherPos = other.size) {
2982
- return findDiffEnd(this, other, pos, otherPos);
2983
- }
2984
- /**
2985
- Find the index and inner offset corresponding to a given relative
2986
- position in this fragment. The result object will be reused
2987
- (overwritten) the next time the function is called. (Not public.)
2988
- */
2989
- findIndex(pos, round = -1) {
2990
- if (pos == 0)
2991
- return retIndex(0, pos);
2992
- if (pos == this.size)
2993
- return retIndex(this.content.length, pos);
2994
- if (pos > this.size || pos < 0)
2995
- throw new RangeError(`Position ${pos} outside of fragment (${this})`);
2996
- for (let i = 0, curPos = 0; ; i++) {
2997
- let cur = this.child(i), end = curPos + cur.nodeSize;
2998
- if (end >= pos) {
2999
- if (end == pos || round > 0)
3000
- return retIndex(i + 1, end);
3001
- return retIndex(i, curPos);
3002
- }
3003
- curPos = end;
3004
- }
3005
- }
3006
- /**
3007
- Return a debugging string that describes this fragment.
3008
- */
3009
- toString() {
3010
- return "<" + this.toStringInner() + ">";
3011
- }
3012
- /**
3013
- @internal
3014
- */
3015
- toStringInner() {
3016
- return this.content.join(", ");
3017
- }
3018
- /**
3019
- Create a JSON-serializeable representation of this fragment.
3020
- */
3021
- toJSON() {
3022
- return this.content.length ? this.content.map((n) => n.toJSON()) : null;
3023
- }
3024
- /**
3025
- Deserialize a fragment from its JSON representation.
3026
- */
3027
- static fromJSON(schema, value) {
3028
- if (!value)
3029
- return _Fragment.empty;
3030
- if (!Array.isArray(value))
3031
- throw new RangeError("Invalid input for Fragment.fromJSON");
3032
- return new _Fragment(value.map(schema.nodeFromJSON));
3033
- }
3034
- /**
3035
- Build a fragment from an array of nodes. Ensures that adjacent
3036
- text nodes with the same marks are joined together.
3037
- */
3038
- static fromArray(array) {
3039
- if (!array.length)
3040
- return _Fragment.empty;
3041
- let joined, size = 0;
3042
- for (let i = 0; i < array.length; i++) {
3043
- let node = array[i];
3044
- size += node.nodeSize;
3045
- if (i && node.isText && array[i - 1].sameMarkup(node)) {
3046
- if (!joined)
3047
- joined = array.slice(0, i);
3048
- joined[joined.length - 1] = node.withText(joined[joined.length - 1].text + node.text);
3049
- } else if (joined) {
3050
- joined.push(node);
3051
- }
3052
- }
3053
- return new _Fragment(joined || array, size);
3054
- }
3055
- /**
3056
- Create a fragment from something that can be interpreted as a
3057
- set of nodes. For `null`, it returns the empty fragment. For a
3058
- fragment, the fragment itself. For a node or array of nodes, a
3059
- fragment containing those nodes.
3060
- */
3061
- static from(nodes) {
3062
- if (!nodes)
3063
- return _Fragment.empty;
3064
- if (nodes instanceof _Fragment)
3065
- return nodes;
3066
- if (Array.isArray(nodes))
3067
- return this.fromArray(nodes);
3068
- if (nodes.attrs)
3069
- return new _Fragment([nodes], nodes.nodeSize);
3070
- throw new RangeError("Can not convert " + nodes + " to a Fragment" + (nodes.nodesBetween ? " (looks like multiple versions of prosemirror-model were loaded)" : ""));
3071
- }
3072
- };
3073
- Fragment.empty = new Fragment([], 0);
3074
- var found = { index: 0, offset: 0 };
3075
- function retIndex(index, offset) {
3076
- found.index = index;
3077
- found.offset = offset;
3078
- return found;
3079
- }
3080
- function compareDeep(a, b) {
3081
- if (a === b)
3082
- return true;
3083
- if (!(a && typeof a == "object") || !(b && typeof b == "object"))
3084
- return false;
3085
- let array = Array.isArray(a);
3086
- if (Array.isArray(b) != array)
3087
- return false;
3088
- if (array) {
3089
- if (a.length != b.length)
3090
- return false;
3091
- for (let i = 0; i < a.length; i++)
3092
- if (!compareDeep(a[i], b[i]))
3093
- return false;
3094
- } else {
3095
- for (let p in a)
3096
- if (!(p in b) || !compareDeep(a[p], b[p]))
3097
- return false;
3098
- for (let p in b)
3099
- if (!(p in a))
3100
- return false;
3101
- }
3102
- return true;
3103
- }
3104
- var Mark = class _Mark {
3105
- /**
3106
- @internal
3107
- */
3108
- constructor(type, attrs) {
3109
- this.type = type;
3110
- this.attrs = attrs;
3111
- }
3112
- /**
3113
- Given a set of marks, create a new set which contains this one as
3114
- well, in the right position. If this mark is already in the set,
3115
- the set itself is returned. If any marks that are set to be
3116
- [exclusive](https://prosemirror.net/docs/ref/#model.MarkSpec.excludes) with this mark are present,
3117
- those are replaced by this one.
3118
- */
3119
- addToSet(set) {
3120
- let copy, placed = false;
3121
- for (let i = 0; i < set.length; i++) {
3122
- let other = set[i];
3123
- if (this.eq(other))
3124
- return set;
3125
- if (this.type.excludes(other.type)) {
3126
- if (!copy)
3127
- copy = set.slice(0, i);
3128
- } else if (other.type.excludes(this.type)) {
3129
- return set;
3130
- } else {
3131
- if (!placed && other.type.rank > this.type.rank) {
3132
- if (!copy)
3133
- copy = set.slice(0, i);
3134
- copy.push(this);
3135
- placed = true;
3136
- }
3137
- if (copy)
3138
- copy.push(other);
3139
- }
3140
- }
3141
- if (!copy)
3142
- copy = set.slice();
3143
- if (!placed)
3144
- copy.push(this);
3145
- return copy;
3146
- }
3147
- /**
3148
- Remove this mark from the given set, returning a new set. If this
3149
- mark is not in the set, the set itself is returned.
3150
- */
3151
- removeFromSet(set) {
3152
- for (let i = 0; i < set.length; i++)
3153
- if (this.eq(set[i]))
3154
- return set.slice(0, i).concat(set.slice(i + 1));
3155
- return set;
3156
- }
3157
- /**
3158
- Test whether this mark is in the given set of marks.
3159
- */
3160
- isInSet(set) {
3161
- for (let i = 0; i < set.length; i++)
3162
- if (this.eq(set[i]))
3163
- return true;
3164
- return false;
3165
- }
3166
- /**
3167
- Test whether this mark has the same type and attributes as
3168
- another mark.
3169
- */
3170
- eq(other) {
3171
- return this == other || this.type == other.type && compareDeep(this.attrs, other.attrs);
3172
- }
3173
- /**
3174
- Convert this mark to a JSON-serializeable representation.
3175
- */
3176
- toJSON() {
3177
- let obj = { type: this.type.name };
3178
- for (let _ in this.attrs) {
3179
- obj.attrs = this.attrs;
3180
- break;
3181
- }
3182
- return obj;
3183
- }
3184
- /**
3185
- Deserialize a mark from JSON.
3186
- */
3187
- static fromJSON(schema, json) {
3188
- if (!json)
3189
- throw new RangeError("Invalid input for Mark.fromJSON");
3190
- let type = schema.marks[json.type];
3191
- if (!type)
3192
- throw new RangeError(`There is no mark type ${json.type} in this schema`);
3193
- return type.create(json.attrs);
3194
- }
3195
- /**
3196
- Test whether two sets of marks are identical.
3197
- */
3198
- static sameSet(a, b) {
3199
- if (a == b)
3200
- return true;
3201
- if (a.length != b.length)
3202
- return false;
3203
- for (let i = 0; i < a.length; i++)
3204
- if (!a[i].eq(b[i]))
3205
- return false;
3206
- return true;
3207
- }
3208
- /**
3209
- Create a properly sorted mark set from null, a single mark, or an
3210
- unsorted array of marks.
3211
- */
3212
- static setFrom(marks) {
3213
- if (!marks || Array.isArray(marks) && marks.length == 0)
3214
- return _Mark.none;
3215
- if (marks instanceof _Mark)
3216
- return [marks];
3217
- let copy = marks.slice();
3218
- copy.sort((a, b) => a.type.rank - b.type.rank);
3219
- return copy;
3220
- }
3221
- };
3222
- Mark.none = [];
3223
- var ReplaceError = class extends Error {
3224
- };
3225
- var Slice = class _Slice {
3226
- /**
3227
- Create a slice. When specifying a non-zero open depth, you must
3228
- make sure that there are nodes of at least that depth at the
3229
- appropriate side of the fragment—i.e. if the fragment is an
3230
- empty paragraph node, `openStart` and `openEnd` can't be greater
3231
- than 1.
3232
-
3233
- It is not necessary for the content of open nodes to conform to
3234
- the schema's content constraints, though it should be a valid
3235
- start/end/middle for such a node, depending on which sides are
3236
- open.
3237
- */
3238
- constructor(content, openStart, openEnd) {
3239
- this.content = content;
3240
- this.openStart = openStart;
3241
- this.openEnd = openEnd;
3242
- }
3243
- /**
3244
- The size this slice would add when inserted into a document.
3245
- */
3246
- get size() {
3247
- return this.content.size - this.openStart - this.openEnd;
3248
- }
3249
- /**
3250
- @internal
3251
- */
3252
- insertAt(pos, fragment) {
3253
- let content = insertInto(this.content, pos + this.openStart, fragment);
3254
- return content && new _Slice(content, this.openStart, this.openEnd);
3255
- }
3256
- /**
3257
- @internal
3258
- */
3259
- removeBetween(from, to) {
3260
- return new _Slice(removeRange(this.content, from + this.openStart, to + this.openStart), this.openStart, this.openEnd);
3261
- }
3262
- /**
3263
- Tests whether this slice is equal to another slice.
3264
- */
3265
- eq(other) {
3266
- return this.content.eq(other.content) && this.openStart == other.openStart && this.openEnd == other.openEnd;
3267
- }
3268
- /**
3269
- @internal
3270
- */
3271
- toString() {
3272
- return this.content + "(" + this.openStart + "," + this.openEnd + ")";
3273
- }
3274
- /**
3275
- Convert a slice to a JSON-serializable representation.
3276
- */
3277
- toJSON() {
3278
- if (!this.content.size)
3279
- return null;
3280
- let json = { content: this.content.toJSON() };
3281
- if (this.openStart > 0)
3282
- json.openStart = this.openStart;
3283
- if (this.openEnd > 0)
3284
- json.openEnd = this.openEnd;
3285
- return json;
3286
- }
3287
- /**
3288
- Deserialize a slice from its JSON representation.
3289
- */
3290
- static fromJSON(schema, json) {
3291
- if (!json)
3292
- return _Slice.empty;
3293
- let openStart = json.openStart || 0, openEnd = json.openEnd || 0;
3294
- if (typeof openStart != "number" || typeof openEnd != "number")
3295
- throw new RangeError("Invalid input for Slice.fromJSON");
3296
- return new _Slice(Fragment.fromJSON(schema, json.content), openStart, openEnd);
3297
- }
3298
- /**
3299
- Create a slice from a fragment by taking the maximum possible
3300
- open value on both side of the fragment.
3301
- */
3302
- static maxOpen(fragment, openIsolating = true) {
3303
- let openStart = 0, openEnd = 0;
3304
- for (let n = fragment.firstChild; n && !n.isLeaf && (openIsolating || !n.type.spec.isolating); n = n.firstChild)
3305
- openStart++;
3306
- for (let n = fragment.lastChild; n && !n.isLeaf && (openIsolating || !n.type.spec.isolating); n = n.lastChild)
3307
- openEnd++;
3308
- return new _Slice(fragment, openStart, openEnd);
3309
- }
3310
- };
3311
- Slice.empty = new Slice(Fragment.empty, 0, 0);
3312
- function removeRange(content, from, to) {
3313
- let { index, offset } = content.findIndex(from), child = content.maybeChild(index);
3314
- let { index: indexTo, offset: offsetTo } = content.findIndex(to);
3315
- if (offset == from || child.isText) {
3316
- if (offsetTo != to && !content.child(indexTo).isText)
3317
- throw new RangeError("Removing non-flat range");
3318
- return content.cut(0, from).append(content.cut(to));
3319
- }
3320
- if (index != indexTo)
3321
- throw new RangeError("Removing non-flat range");
3322
- return content.replaceChild(index, child.copy(removeRange(child.content, from - offset - 1, to - offset - 1)));
3323
- }
3324
- function insertInto(content, dist, insert, parent) {
3325
- let { index, offset } = content.findIndex(dist), child = content.maybeChild(index);
3326
- if (offset == dist || child.isText) {
3327
- if (parent && !parent.canReplace(index, index, insert))
3328
- return null;
3329
- return content.cut(0, dist).append(insert).append(content.cut(dist));
3330
- }
3331
- let inner = insertInto(child.content, dist - offset - 1, insert);
3332
- return inner && content.replaceChild(index, child.copy(inner));
3333
- }
3334
- function replace($from, $to, slice) {
3335
- if (slice.openStart > $from.depth)
3336
- throw new ReplaceError("Inserted content deeper than insertion position");
3337
- if ($from.depth - slice.openStart != $to.depth - slice.openEnd)
3338
- throw new ReplaceError("Inconsistent open depths");
3339
- return replaceOuter($from, $to, slice, 0);
3340
- }
3341
- function replaceOuter($from, $to, slice, depth) {
3342
- let index = $from.index(depth), node = $from.node(depth);
3343
- if (index == $to.index(depth) && depth < $from.depth - slice.openStart) {
3344
- let inner = replaceOuter($from, $to, slice, depth + 1);
3345
- return node.copy(node.content.replaceChild(index, inner));
3346
- } else if (!slice.content.size) {
3347
- return close(node, replaceTwoWay($from, $to, depth));
3348
- } else if (!slice.openStart && !slice.openEnd && $from.depth == depth && $to.depth == depth) {
3349
- let parent = $from.parent, content = parent.content;
3350
- return close(parent, content.cut(0, $from.parentOffset).append(slice.content).append(content.cut($to.parentOffset)));
3351
- } else {
3352
- let { start, end } = prepareSliceForReplace(slice, $from);
3353
- return close(node, replaceThreeWay($from, start, end, $to, depth));
3354
- }
3355
- }
3356
- function checkJoin(main, sub) {
3357
- if (!sub.type.compatibleContent(main.type))
3358
- throw new ReplaceError("Cannot join " + sub.type.name + " onto " + main.type.name);
3359
- }
3360
- function joinable($before, $after, depth) {
3361
- let node = $before.node(depth);
3362
- checkJoin(node, $after.node(depth));
3363
- return node;
3364
- }
3365
- function addNode(child, target) {
3366
- let last = target.length - 1;
3367
- if (last >= 0 && child.isText && child.sameMarkup(target[last]))
3368
- target[last] = child.withText(target[last].text + child.text);
3369
- else
3370
- target.push(child);
3371
- }
3372
- function addRange($start, $end, depth, target) {
3373
- let node = ($end || $start).node(depth);
3374
- let startIndex = 0, endIndex = $end ? $end.index(depth) : node.childCount;
3375
- if ($start) {
3376
- startIndex = $start.index(depth);
3377
- if ($start.depth > depth) {
3378
- startIndex++;
3379
- } else if ($start.textOffset) {
3380
- addNode($start.nodeAfter, target);
3381
- startIndex++;
3382
- }
3383
- }
3384
- for (let i = startIndex; i < endIndex; i++)
3385
- addNode(node.child(i), target);
3386
- if ($end && $end.depth == depth && $end.textOffset)
3387
- addNode($end.nodeBefore, target);
3388
- }
3389
- function close(node, content) {
3390
- node.type.checkContent(content);
3391
- return node.copy(content);
3392
- }
3393
- function replaceThreeWay($from, $start, $end, $to, depth) {
3394
- let openStart = $from.depth > depth && joinable($from, $start, depth + 1);
3395
- let openEnd = $to.depth > depth && joinable($end, $to, depth + 1);
3396
- let content = [];
3397
- addRange(null, $from, depth, content);
3398
- if (openStart && openEnd && $start.index(depth) == $end.index(depth)) {
3399
- checkJoin(openStart, openEnd);
3400
- addNode(close(openStart, replaceThreeWay($from, $start, $end, $to, depth + 1)), content);
3401
- } else {
3402
- if (openStart)
3403
- addNode(close(openStart, replaceTwoWay($from, $start, depth + 1)), content);
3404
- addRange($start, $end, depth, content);
3405
- if (openEnd)
3406
- addNode(close(openEnd, replaceTwoWay($end, $to, depth + 1)), content);
3407
- }
3408
- addRange($to, null, depth, content);
3409
- return new Fragment(content);
3410
- }
3411
- function replaceTwoWay($from, $to, depth) {
3412
- let content = [];
3413
- addRange(null, $from, depth, content);
3414
- if ($from.depth > depth) {
3415
- let type = joinable($from, $to, depth + 1);
3416
- addNode(close(type, replaceTwoWay($from, $to, depth + 1)), content);
3417
- }
3418
- addRange($to, null, depth, content);
3419
- return new Fragment(content);
3420
- }
3421
- function prepareSliceForReplace(slice, $along) {
3422
- let extra = $along.depth - slice.openStart, parent = $along.node(extra);
3423
- let node = parent.copy(slice.content);
3424
- for (let i = extra - 1; i >= 0; i--)
3425
- node = $along.node(i).copy(Fragment.from(node));
3426
- return {
3427
- start: node.resolveNoCache(slice.openStart + extra),
3428
- end: node.resolveNoCache(node.content.size - slice.openEnd - extra)
3429
- };
3430
- }
3431
- var ResolvedPos = class _ResolvedPos {
3432
- /**
3433
- @internal
3434
- */
3435
- constructor(pos, path, parentOffset) {
3436
- this.pos = pos;
3437
- this.path = path;
3438
- this.parentOffset = parentOffset;
3439
- this.depth = path.length / 3 - 1;
3440
- }
3441
- /**
3442
- @internal
3443
- */
3444
- resolveDepth(val) {
3445
- if (val == null)
3446
- return this.depth;
3447
- if (val < 0)
3448
- return this.depth + val;
3449
- return val;
3450
- }
3451
- /**
3452
- The parent node that the position points into. Note that even if
3453
- a position points into a text node, that node is not considered
3454
- the parent—text nodes are ‘flat’ in this model, and have no content.
3455
- */
3456
- get parent() {
3457
- return this.node(this.depth);
3458
- }
3459
- /**
3460
- The root node in which the position was resolved.
3461
- */
3462
- get doc() {
3463
- return this.node(0);
3464
- }
3465
- /**
3466
- The ancestor node at the given level. `p.node(p.depth)` is the
3467
- same as `p.parent`.
3468
- */
3469
- node(depth) {
3470
- return this.path[this.resolveDepth(depth) * 3];
3471
- }
3472
- /**
3473
- The index into the ancestor at the given level. If this points
3474
- at the 3rd node in the 2nd paragraph on the top level, for
3475
- example, `p.index(0)` is 1 and `p.index(1)` is 2.
3476
- */
3477
- index(depth) {
3478
- return this.path[this.resolveDepth(depth) * 3 + 1];
3479
- }
3480
- /**
3481
- The index pointing after this position into the ancestor at the
3482
- given level.
3483
- */
3484
- indexAfter(depth) {
3485
- depth = this.resolveDepth(depth);
3486
- return this.index(depth) + (depth == this.depth && !this.textOffset ? 0 : 1);
3487
- }
3488
- /**
3489
- The (absolute) position at the start of the node at the given
3490
- level.
3491
- */
3492
- start(depth) {
3493
- depth = this.resolveDepth(depth);
3494
- return depth == 0 ? 0 : this.path[depth * 3 - 1] + 1;
3495
- }
3496
- /**
3497
- The (absolute) position at the end of the node at the given
3498
- level.
3499
- */
3500
- end(depth) {
3501
- depth = this.resolveDepth(depth);
3502
- return this.start(depth) + this.node(depth).content.size;
3503
- }
3504
- /**
3505
- The (absolute) position directly before the wrapping node at the
3506
- given level, or, when `depth` is `this.depth + 1`, the original
3507
- position.
3508
- */
3509
- before(depth) {
3510
- depth = this.resolveDepth(depth);
3511
- if (!depth)
3512
- throw new RangeError("There is no position before the top-level node");
3513
- return depth == this.depth + 1 ? this.pos : this.path[depth * 3 - 1];
3514
- }
3515
- /**
3516
- The (absolute) position directly after the wrapping node at the
3517
- given level, or the original position when `depth` is `this.depth + 1`.
3518
- */
3519
- after(depth) {
3520
- depth = this.resolveDepth(depth);
3521
- if (!depth)
3522
- throw new RangeError("There is no position after the top-level node");
3523
- return depth == this.depth + 1 ? this.pos : this.path[depth * 3 - 1] + this.path[depth * 3].nodeSize;
3524
- }
3525
- /**
3526
- When this position points into a text node, this returns the
3527
- distance between the position and the start of the text node.
3528
- Will be zero for positions that point between nodes.
3529
- */
3530
- get textOffset() {
3531
- return this.pos - this.path[this.path.length - 1];
3532
- }
3533
- /**
3534
- Get the node directly after the position, if any. If the position
3535
- points into a text node, only the part of that node after the
3536
- position is returned.
3537
- */
3538
- get nodeAfter() {
3539
- let parent = this.parent, index = this.index(this.depth);
3540
- if (index == parent.childCount)
3541
- return null;
3542
- let dOff = this.pos - this.path[this.path.length - 1], child = parent.child(index);
3543
- return dOff ? parent.child(index).cut(dOff) : child;
3544
- }
3545
- /**
3546
- Get the node directly before the position, if any. If the
3547
- position points into a text node, only the part of that node
3548
- before the position is returned.
3549
- */
3550
- get nodeBefore() {
3551
- let index = this.index(this.depth);
3552
- let dOff = this.pos - this.path[this.path.length - 1];
3553
- if (dOff)
3554
- return this.parent.child(index).cut(0, dOff);
3555
- return index == 0 ? null : this.parent.child(index - 1);
3556
- }
3557
- /**
3558
- Get the position at the given index in the parent node at the
3559
- given depth (which defaults to `this.depth`).
3560
- */
3561
- posAtIndex(index, depth) {
3562
- depth = this.resolveDepth(depth);
3563
- let node = this.path[depth * 3], pos = depth == 0 ? 0 : this.path[depth * 3 - 1] + 1;
3564
- for (let i = 0; i < index; i++)
3565
- pos += node.child(i).nodeSize;
3566
- return pos;
3567
- }
3568
- /**
3569
- Get the marks at this position, factoring in the surrounding
3570
- marks' [`inclusive`](https://prosemirror.net/docs/ref/#model.MarkSpec.inclusive) property. If the
3571
- position is at the start of a non-empty node, the marks of the
3572
- node after it (if any) are returned.
3573
- */
3574
- marks() {
3575
- let parent = this.parent, index = this.index();
3576
- if (parent.content.size == 0)
3577
- return Mark.none;
3578
- if (this.textOffset)
3579
- return parent.child(index).marks;
3580
- let main = parent.maybeChild(index - 1), other = parent.maybeChild(index);
3581
- if (!main) {
3582
- let tmp = main;
3583
- main = other;
3584
- other = tmp;
3585
- }
3586
- let marks = main.marks;
3587
- for (var i = 0; i < marks.length; i++)
3588
- if (marks[i].type.spec.inclusive === false && (!other || !marks[i].isInSet(other.marks)))
3589
- marks = marks[i--].removeFromSet(marks);
3590
- return marks;
3591
- }
3592
- /**
3593
- Get the marks after the current position, if any, except those
3594
- that are non-inclusive and not present at position `$end`. This
3595
- is mostly useful for getting the set of marks to preserve after a
3596
- deletion. Will return `null` if this position is at the end of
3597
- its parent node or its parent node isn't a textblock (in which
3598
- case no marks should be preserved).
3599
- */
3600
- marksAcross($end) {
3601
- let after = this.parent.maybeChild(this.index());
3602
- if (!after || !after.isInline)
3603
- return null;
3604
- let marks = after.marks, next = $end.parent.maybeChild($end.index());
3605
- for (var i = 0; i < marks.length; i++)
3606
- if (marks[i].type.spec.inclusive === false && (!next || !marks[i].isInSet(next.marks)))
3607
- marks = marks[i--].removeFromSet(marks);
3608
- return marks;
3609
- }
3610
- /**
3611
- The depth up to which this position and the given (non-resolved)
3612
- position share the same parent nodes.
3613
- */
3614
- sharedDepth(pos) {
3615
- for (let depth = this.depth; depth > 0; depth--)
3616
- if (this.start(depth) <= pos && this.end(depth) >= pos)
3617
- return depth;
3618
- return 0;
3619
- }
3620
- /**
3621
- Returns a range based on the place where this position and the
3622
- given position diverge around block content. If both point into
3623
- the same textblock, for example, a range around that textblock
3624
- will be returned. If they point into different blocks, the range
3625
- around those blocks in their shared ancestor is returned. You can
3626
- pass in an optional predicate that will be called with a parent
3627
- node to see if a range into that parent is acceptable.
3628
- */
3629
- blockRange(other = this, pred) {
3630
- if (other.pos < this.pos)
3631
- return other.blockRange(this);
3632
- for (let d = this.depth - (this.parent.inlineContent || this.pos == other.pos ? 1 : 0); d >= 0; d--)
3633
- if (other.pos <= this.end(d) && (!pred || pred(this.node(d))))
3634
- return new NodeRange(this, other, d);
3635
- return null;
3636
- }
3637
- /**
3638
- Query whether the given position shares the same parent node.
3639
- */
3640
- sameParent(other) {
3641
- return this.pos - this.parentOffset == other.pos - other.parentOffset;
3642
- }
3643
- /**
3644
- Return the greater of this and the given position.
3645
- */
3646
- max(other) {
3647
- return other.pos > this.pos ? other : this;
3648
- }
3649
- /**
3650
- Return the smaller of this and the given position.
3651
- */
3652
- min(other) {
3653
- return other.pos < this.pos ? other : this;
3654
- }
3655
- /**
3656
- @internal
3657
- */
3658
- toString() {
3659
- let str = "";
3660
- for (let i = 1; i <= this.depth; i++)
3661
- str += (str ? "/" : "") + this.node(i).type.name + "_" + this.index(i - 1);
3662
- return str + ":" + this.parentOffset;
3663
- }
3664
- /**
3665
- @internal
3666
- */
3667
- static resolve(doc, pos) {
3668
- if (!(pos >= 0 && pos <= doc.content.size))
3669
- throw new RangeError("Position " + pos + " out of range");
3670
- let path = [];
3671
- let start = 0, parentOffset = pos;
3672
- for (let node = doc; ; ) {
3673
- let { index, offset } = node.content.findIndex(parentOffset);
3674
- let rem = parentOffset - offset;
3675
- path.push(node, index, start + offset);
3676
- if (!rem)
3677
- break;
3678
- node = node.child(index);
3679
- if (node.isText)
3680
- break;
3681
- parentOffset = rem - 1;
3682
- start += offset + 1;
3683
- }
3684
- return new _ResolvedPos(pos, path, parentOffset);
3685
- }
3686
- /**
3687
- @internal
3688
- */
3689
- static resolveCached(doc, pos) {
3690
- for (let i = 0; i < resolveCache.length; i++) {
3691
- let cached = resolveCache[i];
3692
- if (cached.pos == pos && cached.doc == doc)
3693
- return cached;
3694
- }
3695
- let result = resolveCache[resolveCachePos] = _ResolvedPos.resolve(doc, pos);
3696
- resolveCachePos = (resolveCachePos + 1) % resolveCacheSize;
3697
- return result;
3698
- }
3699
- };
3700
- var resolveCache = [];
3701
- var resolveCachePos = 0;
3702
- var resolveCacheSize = 12;
3703
- var NodeRange = class {
3704
- /**
3705
- Construct a node range. `$from` and `$to` should point into the
3706
- same node until at least the given `depth`, since a node range
3707
- denotes an adjacent set of nodes in a single parent node.
3708
- */
3709
- constructor($from, $to, depth) {
3710
- this.$from = $from;
3711
- this.$to = $to;
3712
- this.depth = depth;
3713
- }
3714
- /**
3715
- The position at the start of the range.
3716
- */
3717
- get start() {
3718
- return this.$from.before(this.depth + 1);
3719
- }
3720
- /**
3721
- The position at the end of the range.
3722
- */
3723
- get end() {
3724
- return this.$to.after(this.depth + 1);
3725
- }
3726
- /**
3727
- The parent node that the range points into.
3728
- */
3729
- get parent() {
3730
- return this.$from.node(this.depth);
3731
- }
3732
- /**
3733
- The start index of the range in the parent node.
3734
- */
3735
- get startIndex() {
3736
- return this.$from.index(this.depth);
3737
- }
3738
- /**
3739
- The end index of the range in the parent node.
3740
- */
3741
- get endIndex() {
3742
- return this.$to.indexAfter(this.depth);
3743
- }
3744
- };
3745
- var emptyAttrs = /* @__PURE__ */ Object.create(null);
3746
- var Node = class _Node {
3747
- /**
3748
- @internal
3749
- */
3750
- constructor(type, attrs, content, marks = Mark.none) {
3751
- this.type = type;
3752
- this.attrs = attrs;
3753
- this.marks = marks;
3754
- this.content = content || Fragment.empty;
3755
- }
3756
- /**
3757
- The size of this node, as defined by the integer-based [indexing
3758
- scheme](/docs/guide/#doc.indexing). For text nodes, this is the
3759
- amount of characters. For other leaf nodes, it is one. For
3760
- non-leaf nodes, it is the size of the content plus two (the
3761
- start and end token).
3762
- */
3763
- get nodeSize() {
3764
- return this.isLeaf ? 1 : 2 + this.content.size;
3765
- }
3766
- /**
3767
- The number of children that the node has.
3768
- */
3769
- get childCount() {
3770
- return this.content.childCount;
3771
- }
3772
- /**
3773
- Get the child node at the given index. Raises an error when the
3774
- index is out of range.
3775
- */
3776
- child(index) {
3777
- return this.content.child(index);
3778
- }
3779
- /**
3780
- Get the child node at the given index, if it exists.
3781
- */
3782
- maybeChild(index) {
3783
- return this.content.maybeChild(index);
3784
- }
3785
- /**
3786
- Call `f` for every child node, passing the node, its offset
3787
- into this parent node, and its index.
3788
- */
3789
- forEach(f) {
3790
- this.content.forEach(f);
3791
- }
3792
- /**
3793
- Invoke a callback for all descendant nodes recursively between
3794
- the given two positions that are relative to start of this
3795
- node's content. The callback is invoked with the node, its
3796
- position relative to the original node (method receiver),
3797
- its parent node, and its child index. When the callback returns
3798
- false for a given node, that node's children will not be
3799
- recursed over. The last parameter can be used to specify a
3800
- starting position to count from.
3801
- */
3802
- nodesBetween(from, to, f, startPos = 0) {
3803
- this.content.nodesBetween(from, to, f, startPos, this);
3804
- }
3805
- /**
3806
- Call the given callback for every descendant node. Doesn't
3807
- descend into a node when the callback returns `false`.
3808
- */
3809
- descendants(f) {
3810
- this.nodesBetween(0, this.content.size, f);
3811
- }
3812
- /**
3813
- Concatenates all the text nodes found in this fragment and its
3814
- children.
3815
- */
3816
- get textContent() {
3817
- return this.isLeaf && this.type.spec.leafText ? this.type.spec.leafText(this) : this.textBetween(0, this.content.size, "");
3818
- }
3819
- /**
3820
- Get all text between positions `from` and `to`. When
3821
- `blockSeparator` is given, it will be inserted to separate text
3822
- from different block nodes. If `leafText` is given, it'll be
3823
- inserted for every non-text leaf node encountered, otherwise
3824
- [`leafText`](https://prosemirror.net/docs/ref/#model.NodeSpec^leafText) will be used.
3825
- */
3826
- textBetween(from, to, blockSeparator, leafText) {
3827
- return this.content.textBetween(from, to, blockSeparator, leafText);
3828
- }
3829
- /**
3830
- Returns this node's first child, or `null` if there are no
3831
- children.
3832
- */
3833
- get firstChild() {
3834
- return this.content.firstChild;
3835
- }
3836
- /**
3837
- Returns this node's last child, or `null` if there are no
3838
- children.
3839
- */
3840
- get lastChild() {
3841
- return this.content.lastChild;
3842
- }
3843
- /**
3844
- Test whether two nodes represent the same piece of document.
3845
- */
3846
- eq(other) {
3847
- return this == other || this.sameMarkup(other) && this.content.eq(other.content);
3848
- }
3849
- /**
3850
- Compare the markup (type, attributes, and marks) of this node to
3851
- those of another. Returns `true` if both have the same markup.
3852
- */
3853
- sameMarkup(other) {
3854
- return this.hasMarkup(other.type, other.attrs, other.marks);
3855
- }
3856
- /**
3857
- Check whether this node's markup correspond to the given type,
3858
- attributes, and marks.
3859
- */
3860
- hasMarkup(type, attrs, marks) {
3861
- return this.type == type && compareDeep(this.attrs, attrs || type.defaultAttrs || emptyAttrs) && Mark.sameSet(this.marks, marks || Mark.none);
3862
- }
3863
- /**
3864
- Create a new node with the same markup as this node, containing
3865
- the given content (or empty, if no content is given).
3866
- */
3867
- copy(content = null) {
3868
- if (content == this.content)
3869
- return this;
3870
- return new _Node(this.type, this.attrs, content, this.marks);
3871
- }
3872
- /**
3873
- Create a copy of this node, with the given set of marks instead
3874
- of the node's own marks.
3875
- */
3876
- mark(marks) {
3877
- return marks == this.marks ? this : new _Node(this.type, this.attrs, this.content, marks);
3878
- }
3879
- /**
3880
- Create a copy of this node with only the content between the
3881
- given positions. If `to` is not given, it defaults to the end of
3882
- the node.
3883
- */
3884
- cut(from, to = this.content.size) {
3885
- if (from == 0 && to == this.content.size)
3886
- return this;
3887
- return this.copy(this.content.cut(from, to));
3888
- }
3889
- /**
3890
- Cut out the part of the document between the given positions, and
3891
- return it as a `Slice` object.
3892
- */
3893
- slice(from, to = this.content.size, includeParents = false) {
3894
- if (from == to)
3895
- return Slice.empty;
3896
- let $from = this.resolve(from), $to = this.resolve(to);
3897
- let depth = includeParents ? 0 : $from.sharedDepth(to);
3898
- let start = $from.start(depth), node = $from.node(depth);
3899
- let content = node.content.cut($from.pos - start, $to.pos - start);
3900
- return new Slice(content, $from.depth - depth, $to.depth - depth);
3901
- }
3902
- /**
3903
- Replace the part of the document between the given positions with
3904
- the given slice. The slice must 'fit', meaning its open sides
3905
- must be able to connect to the surrounding content, and its
3906
- content nodes must be valid children for the node they are placed
3907
- into. If any of this is violated, an error of type
3908
- [`ReplaceError`](https://prosemirror.net/docs/ref/#model.ReplaceError) is thrown.
3909
- */
3910
- replace(from, to, slice) {
3911
- return replace(this.resolve(from), this.resolve(to), slice);
3912
- }
3913
- /**
3914
- Find the node directly after the given position.
3915
- */
3916
- nodeAt(pos) {
3917
- for (let node = this; ; ) {
3918
- let { index, offset } = node.content.findIndex(pos);
3919
- node = node.maybeChild(index);
3920
- if (!node)
3921
- return null;
3922
- if (offset == pos || node.isText)
3923
- return node;
3924
- pos -= offset + 1;
3925
- }
3926
- }
3927
- /**
3928
- Find the (direct) child node after the given offset, if any,
3929
- and return it along with its index and offset relative to this
3930
- node.
3931
- */
3932
- childAfter(pos) {
3933
- let { index, offset } = this.content.findIndex(pos);
3934
- return { node: this.content.maybeChild(index), index, offset };
3935
- }
3936
- /**
3937
- Find the (direct) child node before the given offset, if any,
3938
- and return it along with its index and offset relative to this
3939
- node.
3940
- */
3941
- childBefore(pos) {
3942
- if (pos == 0)
3943
- return { node: null, index: 0, offset: 0 };
3944
- let { index, offset } = this.content.findIndex(pos);
3945
- if (offset < pos)
3946
- return { node: this.content.child(index), index, offset };
3947
- let node = this.content.child(index - 1);
3948
- return { node, index: index - 1, offset: offset - node.nodeSize };
3949
- }
3950
- /**
3951
- Resolve the given position in the document, returning an
3952
- [object](https://prosemirror.net/docs/ref/#model.ResolvedPos) with information about its context.
3953
- */
3954
- resolve(pos) {
3955
- return ResolvedPos.resolveCached(this, pos);
3956
- }
3957
- /**
3958
- @internal
3959
- */
3960
- resolveNoCache(pos) {
3961
- return ResolvedPos.resolve(this, pos);
3962
- }
3963
- /**
3964
- Test whether a given mark or mark type occurs in this document
3965
- between the two given positions.
3966
- */
3967
- rangeHasMark(from, to, type) {
3968
- let found2 = false;
3969
- if (to > from)
3970
- this.nodesBetween(from, to, (node) => {
3971
- if (type.isInSet(node.marks))
3972
- found2 = true;
3973
- return !found2;
3974
- });
3975
- return found2;
3976
- }
3977
- /**
3978
- True when this is a block (non-inline node)
3979
- */
3980
- get isBlock() {
3981
- return this.type.isBlock;
3982
- }
3983
- /**
3984
- True when this is a textblock node, a block node with inline
3985
- content.
3986
- */
3987
- get isTextblock() {
3988
- return this.type.isTextblock;
3989
- }
3990
- /**
3991
- True when this node allows inline content.
3992
- */
3993
- get inlineContent() {
3994
- return this.type.inlineContent;
3995
- }
3996
- /**
3997
- True when this is an inline node (a text node or a node that can
3998
- appear among text).
3999
- */
4000
- get isInline() {
4001
- return this.type.isInline;
4002
- }
4003
- /**
4004
- True when this is a text node.
4005
- */
4006
- get isText() {
4007
- return this.type.isText;
4008
- }
4009
- /**
4010
- True when this is a leaf node.
4011
- */
4012
- get isLeaf() {
4013
- return this.type.isLeaf;
4014
- }
4015
- /**
4016
- True when this is an atom, i.e. when it does not have directly
4017
- editable content. This is usually the same as `isLeaf`, but can
4018
- be configured with the [`atom` property](https://prosemirror.net/docs/ref/#model.NodeSpec.atom)
4019
- on a node's spec (typically used when the node is displayed as
4020
- an uneditable [node view](https://prosemirror.net/docs/ref/#view.NodeView)).
4021
- */
4022
- get isAtom() {
4023
- return this.type.isAtom;
4024
- }
4025
- /**
4026
- Return a string representation of this node for debugging
4027
- purposes.
4028
- */
4029
- toString() {
4030
- if (this.type.spec.toDebugString)
4031
- return this.type.spec.toDebugString(this);
4032
- let name = this.type.name;
4033
- if (this.content.size)
4034
- name += "(" + this.content.toStringInner() + ")";
4035
- return wrapMarks(this.marks, name);
4036
- }
4037
- /**
4038
- Get the content match in this node at the given index.
4039
- */
4040
- contentMatchAt(index) {
4041
- let match = this.type.contentMatch.matchFragment(this.content, 0, index);
4042
- if (!match)
4043
- throw new Error("Called contentMatchAt on a node with invalid content");
4044
- return match;
4045
- }
4046
- /**
4047
- Test whether replacing the range between `from` and `to` (by
4048
- child index) with the given replacement fragment (which defaults
4049
- to the empty fragment) would leave the node's content valid. You
4050
- can optionally pass `start` and `end` indices into the
4051
- replacement fragment.
4052
- */
4053
- canReplace(from, to, replacement = Fragment.empty, start = 0, end = replacement.childCount) {
4054
- let one = this.contentMatchAt(from).matchFragment(replacement, start, end);
4055
- let two = one && one.matchFragment(this.content, to);
4056
- if (!two || !two.validEnd)
4057
- return false;
4058
- for (let i = start; i < end; i++)
4059
- if (!this.type.allowsMarks(replacement.child(i).marks))
4060
- return false;
4061
- return true;
4062
- }
4063
- /**
4064
- Test whether replacing the range `from` to `to` (by index) with
4065
- a node of the given type would leave the node's content valid.
4066
- */
4067
- canReplaceWith(from, to, type, marks) {
4068
- if (marks && !this.type.allowsMarks(marks))
4069
- return false;
4070
- let start = this.contentMatchAt(from).matchType(type);
4071
- let end = start && start.matchFragment(this.content, to);
4072
- return end ? end.validEnd : false;
4073
- }
4074
- /**
4075
- Test whether the given node's content could be appended to this
4076
- node. If that node is empty, this will only return true if there
4077
- is at least one node type that can appear in both nodes (to avoid
4078
- merging completely incompatible nodes).
4079
- */
4080
- canAppend(other) {
4081
- if (other.content.size)
4082
- return this.canReplace(this.childCount, this.childCount, other.content);
4083
- else
4084
- return this.type.compatibleContent(other.type);
4085
- }
4086
- /**
4087
- Check whether this node and its descendants conform to the
4088
- schema, and raise error when they do not.
4089
- */
4090
- check() {
4091
- this.type.checkContent(this.content);
4092
- let copy = Mark.none;
4093
- for (let i = 0; i < this.marks.length; i++)
4094
- copy = this.marks[i].addToSet(copy);
4095
- if (!Mark.sameSet(copy, this.marks))
4096
- throw new RangeError(`Invalid collection of marks for node ${this.type.name}: ${this.marks.map((m) => m.type.name)}`);
4097
- this.content.forEach((node) => node.check());
4098
- }
4099
- /**
4100
- Return a JSON-serializeable representation of this node.
4101
- */
4102
- toJSON() {
4103
- let obj = { type: this.type.name };
4104
- for (let _ in this.attrs) {
4105
- obj.attrs = this.attrs;
4106
- break;
4107
- }
4108
- if (this.content.size)
4109
- obj.content = this.content.toJSON();
4110
- if (this.marks.length)
4111
- obj.marks = this.marks.map((n) => n.toJSON());
4112
- return obj;
4113
- }
4114
- /**
4115
- Deserialize a node from its JSON representation.
4116
- */
4117
- static fromJSON(schema, json) {
4118
- if (!json)
4119
- throw new RangeError("Invalid input for Node.fromJSON");
4120
- let marks = null;
4121
- if (json.marks) {
4122
- if (!Array.isArray(json.marks))
4123
- throw new RangeError("Invalid mark data for Node.fromJSON");
4124
- marks = json.marks.map(schema.markFromJSON);
4125
- }
4126
- if (json.type == "text") {
4127
- if (typeof json.text != "string")
4128
- throw new RangeError("Invalid text node in JSON");
4129
- return schema.text(json.text, marks);
4130
- }
4131
- let content = Fragment.fromJSON(schema, json.content);
4132
- return schema.nodeType(json.type).create(json.attrs, content, marks);
4133
- }
4134
- };
4135
- Node.prototype.text = void 0;
4136
- var TextNode = class _TextNode extends Node {
4137
- /**
4138
- @internal
4139
- */
4140
- constructor(type, attrs, content, marks) {
4141
- super(type, attrs, null, marks);
4142
- if (!content)
4143
- throw new RangeError("Empty text nodes are not allowed");
4144
- this.text = content;
4145
- }
4146
- toString() {
4147
- if (this.type.spec.toDebugString)
4148
- return this.type.spec.toDebugString(this);
4149
- return wrapMarks(this.marks, JSON.stringify(this.text));
4150
- }
4151
- get textContent() {
4152
- return this.text;
4153
- }
4154
- textBetween(from, to) {
4155
- return this.text.slice(from, to);
4156
- }
4157
- get nodeSize() {
4158
- return this.text.length;
4159
- }
4160
- mark(marks) {
4161
- return marks == this.marks ? this : new _TextNode(this.type, this.attrs, this.text, marks);
4162
- }
4163
- withText(text) {
4164
- if (text == this.text)
4165
- return this;
4166
- return new _TextNode(this.type, this.attrs, text, this.marks);
4167
- }
4168
- cut(from = 0, to = this.text.length) {
4169
- if (from == 0 && to == this.text.length)
4170
- return this;
4171
- return this.withText(this.text.slice(from, to));
4172
- }
4173
- eq(other) {
4174
- return this.sameMarkup(other) && this.text == other.text;
4175
- }
4176
- toJSON() {
4177
- let base = super.toJSON();
4178
- base.text = this.text;
4179
- return base;
4180
- }
4181
- };
4182
- function wrapMarks(marks, str) {
4183
- for (let i = marks.length - 1; i >= 0; i--)
4184
- str = marks[i].type.name + "(" + str + ")";
4185
- return str;
4186
- }
4187
- var ContentMatch = class _ContentMatch {
4188
- /**
4189
- @internal
4190
- */
4191
- constructor(validEnd) {
4192
- this.validEnd = validEnd;
4193
- this.next = [];
4194
- this.wrapCache = [];
4195
- }
4196
- /**
4197
- @internal
4198
- */
4199
- static parse(string, nodeTypes) {
4200
- let stream = new TokenStream(string, nodeTypes);
4201
- if (stream.next == null)
4202
- return _ContentMatch.empty;
4203
- let expr = parseExpr(stream);
4204
- if (stream.next)
4205
- stream.err("Unexpected trailing text");
4206
- let match = dfa(nfa(expr));
4207
- checkForDeadEnds(match, stream);
4208
- return match;
4209
- }
4210
- /**
4211
- Match a node type, returning a match after that node if
4212
- successful.
4213
- */
4214
- matchType(type) {
4215
- for (let i = 0; i < this.next.length; i++)
4216
- if (this.next[i].type == type)
4217
- return this.next[i].next;
4218
- return null;
4219
- }
4220
- /**
4221
- Try to match a fragment. Returns the resulting match when
4222
- successful.
4223
- */
4224
- matchFragment(frag, start = 0, end = frag.childCount) {
4225
- let cur = this;
4226
- for (let i = start; cur && i < end; i++)
4227
- cur = cur.matchType(frag.child(i).type);
4228
- return cur;
4229
- }
4230
- /**
4231
- @internal
4232
- */
4233
- get inlineContent() {
4234
- return this.next.length != 0 && this.next[0].type.isInline;
4235
- }
4236
- /**
4237
- Get the first matching node type at this match position that can
4238
- be generated.
4239
- */
4240
- get defaultType() {
4241
- for (let i = 0; i < this.next.length; i++) {
4242
- let { type } = this.next[i];
4243
- if (!(type.isText || type.hasRequiredAttrs()))
4244
- return type;
4245
- }
4246
- return null;
4247
- }
4248
- /**
4249
- @internal
4250
- */
4251
- compatible(other) {
4252
- for (let i = 0; i < this.next.length; i++)
4253
- for (let j = 0; j < other.next.length; j++)
4254
- if (this.next[i].type == other.next[j].type)
4255
- return true;
4256
- return false;
4257
- }
4258
- /**
4259
- Try to match the given fragment, and if that fails, see if it can
4260
- be made to match by inserting nodes in front of it. When
4261
- successful, return a fragment of inserted nodes (which may be
4262
- empty if nothing had to be inserted). When `toEnd` is true, only
4263
- return a fragment if the resulting match goes to the end of the
4264
- content expression.
4265
- */
4266
- fillBefore(after, toEnd = false, startIndex = 0) {
4267
- let seen = [this];
4268
- function search(match, types) {
4269
- let finished = match.matchFragment(after, startIndex);
4270
- if (finished && (!toEnd || finished.validEnd))
4271
- return Fragment.from(types.map((tp) => tp.createAndFill()));
4272
- for (let i = 0; i < match.next.length; i++) {
4273
- let { type, next } = match.next[i];
4274
- if (!(type.isText || type.hasRequiredAttrs()) && seen.indexOf(next) == -1) {
4275
- seen.push(next);
4276
- let found2 = search(next, types.concat(type));
4277
- if (found2)
4278
- return found2;
4279
- }
4280
- }
4281
- return null;
4282
- }
4283
- return search(this, []);
4284
- }
4285
- /**
4286
- Find a set of wrapping node types that would allow a node of the
4287
- given type to appear at this position. The result may be empty
4288
- (when it fits directly) and will be null when no such wrapping
4289
- exists.
4290
- */
4291
- findWrapping(target) {
4292
- for (let i = 0; i < this.wrapCache.length; i += 2)
4293
- if (this.wrapCache[i] == target)
4294
- return this.wrapCache[i + 1];
4295
- let computed = this.computeWrapping(target);
4296
- this.wrapCache.push(target, computed);
4297
- return computed;
4298
- }
4299
- /**
4300
- @internal
4301
- */
4302
- computeWrapping(target) {
4303
- let seen = /* @__PURE__ */ Object.create(null), active = [{ match: this, type: null, via: null }];
4304
- while (active.length) {
4305
- let current = active.shift(), match = current.match;
4306
- if (match.matchType(target)) {
4307
- let result = [];
4308
- for (let obj = current; obj.type; obj = obj.via)
4309
- result.push(obj.type);
4310
- return result.reverse();
4311
- }
4312
- for (let i = 0; i < match.next.length; i++) {
4313
- let { type, next } = match.next[i];
4314
- if (!type.isLeaf && !type.hasRequiredAttrs() && !(type.name in seen) && (!current.type || next.validEnd)) {
4315
- active.push({ match: type.contentMatch, type, via: current });
4316
- seen[type.name] = true;
4317
- }
4318
- }
4319
- }
4320
- return null;
4321
- }
4322
- /**
4323
- The number of outgoing edges this node has in the finite
4324
- automaton that describes the content expression.
4325
- */
4326
- get edgeCount() {
4327
- return this.next.length;
4328
- }
4329
- /**
4330
- Get the _n_​th outgoing edge from this node in the finite
4331
- automaton that describes the content expression.
4332
- */
4333
- edge(n) {
4334
- if (n >= this.next.length)
4335
- throw new RangeError(`There's no ${n}th edge in this content match`);
4336
- return this.next[n];
4337
- }
4338
- /**
4339
- @internal
4340
- */
4341
- toString() {
4342
- let seen = [];
4343
- function scan(m) {
4344
- seen.push(m);
4345
- for (let i = 0; i < m.next.length; i++)
4346
- if (seen.indexOf(m.next[i].next) == -1)
4347
- scan(m.next[i].next);
4348
- }
4349
- scan(this);
4350
- return seen.map((m, i) => {
4351
- let out = i + (m.validEnd ? "*" : " ") + " ";
4352
- for (let i2 = 0; i2 < m.next.length; i2++)
4353
- out += (i2 ? ", " : "") + m.next[i2].type.name + "->" + seen.indexOf(m.next[i2].next);
4354
- return out;
4355
- }).join("\n");
4356
- }
4357
- };
4358
- ContentMatch.empty = new ContentMatch(true);
4359
- var TokenStream = class {
4360
- constructor(string, nodeTypes) {
4361
- this.string = string;
4362
- this.nodeTypes = nodeTypes;
4363
- this.inline = null;
4364
- this.pos = 0;
4365
- this.tokens = string.split(/\s*(?=\b|\W|$)/);
4366
- if (this.tokens[this.tokens.length - 1] == "")
4367
- this.tokens.pop();
4368
- if (this.tokens[0] == "")
4369
- this.tokens.shift();
4370
- }
4371
- get next() {
4372
- return this.tokens[this.pos];
4373
- }
4374
- eat(tok) {
4375
- return this.next == tok && (this.pos++ || true);
4376
- }
4377
- err(str) {
4378
- throw new SyntaxError(str + " (in content expression '" + this.string + "')");
4379
- }
4380
- };
4381
- function parseExpr(stream) {
4382
- let exprs = [];
4383
- do {
4384
- exprs.push(parseExprSeq(stream));
4385
- } while (stream.eat("|"));
4386
- return exprs.length == 1 ? exprs[0] : { type: "choice", exprs };
4387
- }
4388
- function parseExprSeq(stream) {
4389
- let exprs = [];
4390
- do {
4391
- exprs.push(parseExprSubscript(stream));
4392
- } while (stream.next && stream.next != ")" && stream.next != "|");
4393
- return exprs.length == 1 ? exprs[0] : { type: "seq", exprs };
4394
- }
4395
- function parseExprSubscript(stream) {
4396
- let expr = parseExprAtom(stream);
4397
- for (; ; ) {
4398
- if (stream.eat("+"))
4399
- expr = { type: "plus", expr };
4400
- else if (stream.eat("*"))
4401
- expr = { type: "star", expr };
4402
- else if (stream.eat("?"))
4403
- expr = { type: "opt", expr };
4404
- else if (stream.eat("{"))
4405
- expr = parseExprRange(stream, expr);
4406
- else
4407
- break;
4408
- }
4409
- return expr;
4410
- }
4411
- function parseNum(stream) {
4412
- if (/\D/.test(stream.next))
4413
- stream.err("Expected number, got '" + stream.next + "'");
4414
- let result = Number(stream.next);
4415
- stream.pos++;
4416
- return result;
4417
- }
4418
- function parseExprRange(stream, expr) {
4419
- let min = parseNum(stream), max = min;
4420
- if (stream.eat(",")) {
4421
- if (stream.next != "}")
4422
- max = parseNum(stream);
4423
- else
4424
- max = -1;
4425
- }
4426
- if (!stream.eat("}"))
4427
- stream.err("Unclosed braced range");
4428
- return { type: "range", min, max, expr };
4429
- }
4430
- function resolveName(stream, name) {
4431
- let types = stream.nodeTypes, type = types[name];
4432
- if (type)
4433
- return [type];
4434
- let result = [];
4435
- for (let typeName in types) {
4436
- let type2 = types[typeName];
4437
- if (type2.groups.indexOf(name) > -1)
4438
- result.push(type2);
4439
- }
4440
- if (result.length == 0)
4441
- stream.err("No node type or group '" + name + "' found");
4442
- return result;
4443
- }
4444
- function parseExprAtom(stream) {
4445
- if (stream.eat("(")) {
4446
- let expr = parseExpr(stream);
4447
- if (!stream.eat(")"))
4448
- stream.err("Missing closing paren");
4449
- return expr;
4450
- } else if (!/\W/.test(stream.next)) {
4451
- let exprs = resolveName(stream, stream.next).map((type) => {
4452
- if (stream.inline == null)
4453
- stream.inline = type.isInline;
4454
- else if (stream.inline != type.isInline)
4455
- stream.err("Mixing inline and block content");
4456
- return { type: "name", value: type };
4457
- });
4458
- stream.pos++;
4459
- return exprs.length == 1 ? exprs[0] : { type: "choice", exprs };
4460
- } else {
4461
- stream.err("Unexpected token '" + stream.next + "'");
4462
- }
4463
- }
4464
- function nfa(expr) {
4465
- let nfa2 = [[]];
4466
- connect(compile(expr, 0), node());
4467
- return nfa2;
4468
- function node() {
4469
- return nfa2.push([]) - 1;
4470
- }
4471
- function edge(from, to, term) {
4472
- let edge2 = { term, to };
4473
- nfa2[from].push(edge2);
4474
- return edge2;
4475
- }
4476
- function connect(edges, to) {
4477
- edges.forEach((edge2) => edge2.to = to);
4478
- }
4479
- function compile(expr2, from) {
4480
- if (expr2.type == "choice") {
4481
- return expr2.exprs.reduce((out, expr3) => out.concat(compile(expr3, from)), []);
4482
- } else if (expr2.type == "seq") {
4483
- for (let i = 0; ; i++) {
4484
- let next = compile(expr2.exprs[i], from);
4485
- if (i == expr2.exprs.length - 1)
4486
- return next;
4487
- connect(next, from = node());
4488
- }
4489
- } else if (expr2.type == "star") {
4490
- let loop = node();
4491
- edge(from, loop);
4492
- connect(compile(expr2.expr, loop), loop);
4493
- return [edge(loop)];
4494
- } else if (expr2.type == "plus") {
4495
- let loop = node();
4496
- connect(compile(expr2.expr, from), loop);
4497
- connect(compile(expr2.expr, loop), loop);
4498
- return [edge(loop)];
4499
- } else if (expr2.type == "opt") {
4500
- return [edge(from)].concat(compile(expr2.expr, from));
4501
- } else if (expr2.type == "range") {
4502
- let cur = from;
4503
- for (let i = 0; i < expr2.min; i++) {
4504
- let next = node();
4505
- connect(compile(expr2.expr, cur), next);
4506
- cur = next;
4507
- }
4508
- if (expr2.max == -1) {
4509
- connect(compile(expr2.expr, cur), cur);
4510
- } else {
4511
- for (let i = expr2.min; i < expr2.max; i++) {
4512
- let next = node();
4513
- edge(cur, next);
4514
- connect(compile(expr2.expr, cur), next);
4515
- cur = next;
4516
- }
4517
- }
4518
- return [edge(cur)];
4519
- } else if (expr2.type == "name") {
4520
- return [edge(from, void 0, expr2.value)];
4521
- } else {
4522
- throw new Error("Unknown expr type");
4523
- }
4524
- }
4525
- }
4526
- function cmp(a, b) {
4527
- return b - a;
4528
- }
4529
- function nullFrom(nfa2, node) {
4530
- let result = [];
4531
- scan(node);
4532
- return result.sort(cmp);
4533
- function scan(node2) {
4534
- let edges = nfa2[node2];
4535
- if (edges.length == 1 && !edges[0].term)
4536
- return scan(edges[0].to);
4537
- result.push(node2);
4538
- for (let i = 0; i < edges.length; i++) {
4539
- let { term, to } = edges[i];
4540
- if (!term && result.indexOf(to) == -1)
4541
- scan(to);
4542
- }
4543
- }
4544
- }
4545
- function dfa(nfa2) {
4546
- let labeled = /* @__PURE__ */ Object.create(null);
4547
- return explore(nullFrom(nfa2, 0));
4548
- function explore(states) {
4549
- let out = [];
4550
- states.forEach((node) => {
4551
- nfa2[node].forEach(({ term, to }) => {
4552
- if (!term)
4553
- return;
4554
- let set;
4555
- for (let i = 0; i < out.length; i++)
4556
- if (out[i][0] == term)
4557
- set = out[i][1];
4558
- nullFrom(nfa2, to).forEach((node2) => {
4559
- if (!set)
4560
- out.push([term, set = []]);
4561
- if (set.indexOf(node2) == -1)
4562
- set.push(node2);
4563
- });
4564
- });
4565
- });
4566
- let state = labeled[states.join(",")] = new ContentMatch(states.indexOf(nfa2.length - 1) > -1);
4567
- for (let i = 0; i < out.length; i++) {
4568
- let states2 = out[i][1].sort(cmp);
4569
- state.next.push({ type: out[i][0], next: labeled[states2.join(",")] || explore(states2) });
4570
- }
4571
- return state;
4572
- }
4573
- }
4574
- function checkForDeadEnds(match, stream) {
4575
- for (let i = 0, work = [match]; i < work.length; i++) {
4576
- let state = work[i], dead = !state.validEnd, nodes = [];
4577
- for (let j = 0; j < state.next.length; j++) {
4578
- let { type, next } = state.next[j];
4579
- nodes.push(type.name);
4580
- if (dead && !(type.isText || type.hasRequiredAttrs()))
4581
- dead = false;
4582
- if (work.indexOf(next) == -1)
4583
- work.push(next);
4584
- }
4585
- if (dead)
4586
- stream.err("Only non-generatable nodes (" + nodes.join(", ") + ") in a required position (see https://prosemirror.net/docs/guide/#generatable)");
4587
- }
4588
- }
4589
- function defaultAttrs(attrs) {
4590
- let defaults = /* @__PURE__ */ Object.create(null);
4591
- for (let attrName in attrs) {
4592
- let attr = attrs[attrName];
4593
- if (!attr.hasDefault)
4594
- return null;
4595
- defaults[attrName] = attr.default;
4596
- }
4597
- return defaults;
4598
- }
4599
- function computeAttrs(attrs, value) {
4600
- let built = /* @__PURE__ */ Object.create(null);
4601
- for (let name in attrs) {
4602
- let given = value && value[name];
4603
- if (given === void 0) {
4604
- let attr = attrs[name];
4605
- if (attr.hasDefault)
4606
- given = attr.default;
4607
- else
4608
- throw new RangeError("No value supplied for attribute " + name);
4609
- }
4610
- built[name] = given;
4611
- }
4612
- return built;
4613
- }
4614
- function initAttrs(attrs) {
4615
- let result = /* @__PURE__ */ Object.create(null);
4616
- if (attrs)
4617
- for (let name in attrs)
4618
- result[name] = new Attribute(attrs[name]);
4619
- return result;
4620
- }
4621
- var NodeType = class _NodeType {
4622
- /**
4623
- @internal
4624
- */
4625
- constructor(name, schema, spec) {
4626
- this.name = name;
4627
- this.schema = schema;
4628
- this.spec = spec;
4629
- this.markSet = null;
4630
- this.groups = spec.group ? spec.group.split(" ") : [];
4631
- this.attrs = initAttrs(spec.attrs);
4632
- this.defaultAttrs = defaultAttrs(this.attrs);
4633
- this.contentMatch = null;
4634
- this.inlineContent = null;
4635
- this.isBlock = !(spec.inline || name == "text");
4636
- this.isText = name == "text";
4637
- }
4638
- /**
4639
- True if this is an inline type.
4640
- */
4641
- get isInline() {
4642
- return !this.isBlock;
4643
- }
4644
- /**
4645
- True if this is a textblock type, a block that contains inline
4646
- content.
4647
- */
4648
- get isTextblock() {
4649
- return this.isBlock && this.inlineContent;
4650
- }
4651
- /**
4652
- True for node types that allow no content.
4653
- */
4654
- get isLeaf() {
4655
- return this.contentMatch == ContentMatch.empty;
4656
- }
4657
- /**
4658
- True when this node is an atom, i.e. when it does not have
4659
- directly editable content.
4660
- */
4661
- get isAtom() {
4662
- return this.isLeaf || !!this.spec.atom;
4663
- }
4664
- /**
4665
- The node type's [whitespace](https://prosemirror.net/docs/ref/#model.NodeSpec.whitespace) option.
4666
- */
4667
- get whitespace() {
4668
- return this.spec.whitespace || (this.spec.code ? "pre" : "normal");
4669
- }
4670
- /**
4671
- Tells you whether this node type has any required attributes.
4672
- */
4673
- hasRequiredAttrs() {
4674
- for (let n in this.attrs)
4675
- if (this.attrs[n].isRequired)
4676
- return true;
4677
- return false;
4678
- }
4679
- /**
4680
- Indicates whether this node allows some of the same content as
4681
- the given node type.
4682
- */
4683
- compatibleContent(other) {
4684
- return this == other || this.contentMatch.compatible(other.contentMatch);
4685
- }
4686
- /**
4687
- @internal
4688
- */
4689
- computeAttrs(attrs) {
4690
- if (!attrs && this.defaultAttrs)
4691
- return this.defaultAttrs;
4692
- else
4693
- return computeAttrs(this.attrs, attrs);
4694
- }
4695
- /**
4696
- Create a `Node` of this type. The given attributes are
4697
- checked and defaulted (you can pass `null` to use the type's
4698
- defaults entirely, if no required attributes exist). `content`
4699
- may be a `Fragment`, a node, an array of nodes, or
4700
- `null`. Similarly `marks` may be `null` to default to the empty
4701
- set of marks.
4702
- */
4703
- create(attrs = null, content, marks) {
4704
- if (this.isText)
4705
- throw new Error("NodeType.create can't construct text nodes");
4706
- return new Node(this, this.computeAttrs(attrs), Fragment.from(content), Mark.setFrom(marks));
4707
- }
4708
- /**
4709
- Like [`create`](https://prosemirror.net/docs/ref/#model.NodeType.create), but check the given content
4710
- against the node type's content restrictions, and throw an error
4711
- if it doesn't match.
4712
- */
4713
- createChecked(attrs = null, content, marks) {
4714
- content = Fragment.from(content);
4715
- this.checkContent(content);
4716
- return new Node(this, this.computeAttrs(attrs), content, Mark.setFrom(marks));
4717
- }
4718
- /**
4719
- Like [`create`](https://prosemirror.net/docs/ref/#model.NodeType.create), but see if it is
4720
- necessary to add nodes to the start or end of the given fragment
4721
- to make it fit the node. If no fitting wrapping can be found,
4722
- return null. Note that, due to the fact that required nodes can
4723
- always be created, this will always succeed if you pass null or
4724
- `Fragment.empty` as content.
4725
- */
4726
- createAndFill(attrs = null, content, marks) {
4727
- attrs = this.computeAttrs(attrs);
4728
- content = Fragment.from(content);
4729
- if (content.size) {
4730
- let before = this.contentMatch.fillBefore(content);
4731
- if (!before)
4732
- return null;
4733
- content = before.append(content);
4734
- }
4735
- let matched = this.contentMatch.matchFragment(content);
4736
- let after = matched && matched.fillBefore(Fragment.empty, true);
4737
- if (!after)
4738
- return null;
4739
- return new Node(this, attrs, content.append(after), Mark.setFrom(marks));
4740
- }
4741
- /**
4742
- Returns true if the given fragment is valid content for this node
4743
- type with the given attributes.
4744
- */
4745
- validContent(content) {
4746
- let result = this.contentMatch.matchFragment(content);
4747
- if (!result || !result.validEnd)
4748
- return false;
4749
- for (let i = 0; i < content.childCount; i++)
4750
- if (!this.allowsMarks(content.child(i).marks))
4751
- return false;
4752
- return true;
4753
- }
4754
- /**
4755
- Throws a RangeError if the given fragment is not valid content for this
4756
- node type.
4757
- @internal
4758
- */
4759
- checkContent(content) {
4760
- if (!this.validContent(content))
4761
- throw new RangeError(`Invalid content for node ${this.name}: ${content.toString().slice(0, 50)}`);
4762
- }
4763
- /**
4764
- Check whether the given mark type is allowed in this node.
4765
- */
4766
- allowsMarkType(markType) {
4767
- return this.markSet == null || this.markSet.indexOf(markType) > -1;
4768
- }
4769
- /**
4770
- Test whether the given set of marks are allowed in this node.
4771
- */
4772
- allowsMarks(marks) {
4773
- if (this.markSet == null)
4774
- return true;
4775
- for (let i = 0; i < marks.length; i++)
4776
- if (!this.allowsMarkType(marks[i].type))
4777
- return false;
4778
- return true;
4779
- }
4780
- /**
4781
- Removes the marks that are not allowed in this node from the given set.
4782
- */
4783
- allowedMarks(marks) {
4784
- if (this.markSet == null)
4785
- return marks;
4786
- let copy;
4787
- for (let i = 0; i < marks.length; i++) {
4788
- if (!this.allowsMarkType(marks[i].type)) {
4789
- if (!copy)
4790
- copy = marks.slice(0, i);
4791
- } else if (copy) {
4792
- copy.push(marks[i]);
4793
- }
4794
- }
4795
- return !copy ? marks : copy.length ? copy : Mark.none;
4796
- }
4797
- /**
4798
- @internal
4799
- */
4800
- static compile(nodes, schema) {
4801
- let result = /* @__PURE__ */ Object.create(null);
4802
- nodes.forEach((name, spec) => result[name] = new _NodeType(name, schema, spec));
4803
- let topType = schema.spec.topNode || "doc";
4804
- if (!result[topType])
4805
- throw new RangeError("Schema is missing its top node type ('" + topType + "')");
4806
- if (!result.text)
4807
- throw new RangeError("Every schema needs a 'text' type");
4808
- for (let _ in result.text.attrs)
4809
- throw new RangeError("The text node type should not have attributes");
4810
- return result;
4811
- }
4812
- };
4813
- var Attribute = class {
4814
- constructor(options) {
4815
- this.hasDefault = Object.prototype.hasOwnProperty.call(options, "default");
4816
- this.default = options.default;
4817
- }
4818
- get isRequired() {
4819
- return !this.hasDefault;
4820
- }
4821
- };
4822
- var MarkType = class _MarkType {
4823
- /**
4824
- @internal
4825
- */
4826
- constructor(name, rank, schema, spec) {
4827
- this.name = name;
4828
- this.rank = rank;
4829
- this.schema = schema;
4830
- this.spec = spec;
4831
- this.attrs = initAttrs(spec.attrs);
4832
- this.excluded = null;
4833
- let defaults = defaultAttrs(this.attrs);
4834
- this.instance = defaults ? new Mark(this, defaults) : null;
4835
- }
4836
- /**
4837
- Create a mark of this type. `attrs` may be `null` or an object
4838
- containing only some of the mark's attributes. The others, if
4839
- they have defaults, will be added.
4840
- */
4841
- create(attrs = null) {
4842
- if (!attrs && this.instance)
4843
- return this.instance;
4844
- return new Mark(this, computeAttrs(this.attrs, attrs));
4845
- }
4846
- /**
4847
- @internal
4848
- */
4849
- static compile(marks, schema) {
4850
- let result = /* @__PURE__ */ Object.create(null), rank = 0;
4851
- marks.forEach((name, spec) => result[name] = new _MarkType(name, rank++, schema, spec));
4852
- return result;
4853
- }
4854
- /**
4855
- When there is a mark of this type in the given set, a new set
4856
- without it is returned. Otherwise, the input set is returned.
4857
- */
4858
- removeFromSet(set) {
4859
- for (var i = 0; i < set.length; i++)
4860
- if (set[i].type == this) {
4861
- set = set.slice(0, i).concat(set.slice(i + 1));
4862
- i--;
4863
- }
4864
- return set;
4865
- }
4866
- /**
4867
- Tests whether there is a mark of this type in the given set.
4868
- */
4869
- isInSet(set) {
4870
- for (let i = 0; i < set.length; i++)
4871
- if (set[i].type == this)
4872
- return set[i];
4873
- }
4874
- /**
4875
- Queries whether a given mark type is
4876
- [excluded](https://prosemirror.net/docs/ref/#model.MarkSpec.excludes) by this one.
4877
- */
4878
- excludes(other) {
4879
- return this.excluded.indexOf(other) > -1;
4880
- }
4881
- };
4882
- var Schema = class {
4883
- /**
4884
- Construct a schema from a schema [specification](https://prosemirror.net/docs/ref/#model.SchemaSpec).
4885
- */
4886
- constructor(spec) {
4887
- this.cached = /* @__PURE__ */ Object.create(null);
4888
- let instanceSpec = this.spec = {};
4889
- for (let prop in spec)
4890
- instanceSpec[prop] = spec[prop];
4891
- instanceSpec.nodes = dist_default.from(spec.nodes), instanceSpec.marks = dist_default.from(spec.marks || {}), this.nodes = NodeType.compile(this.spec.nodes, this);
4892
- this.marks = MarkType.compile(this.spec.marks, this);
4893
- let contentExprCache = /* @__PURE__ */ Object.create(null);
4894
- for (let prop in this.nodes) {
4895
- if (prop in this.marks)
4896
- throw new RangeError(prop + " can not be both a node and a mark");
4897
- let type = this.nodes[prop], contentExpr = type.spec.content || "", markExpr = type.spec.marks;
4898
- type.contentMatch = contentExprCache[contentExpr] || (contentExprCache[contentExpr] = ContentMatch.parse(contentExpr, this.nodes));
4899
- type.inlineContent = type.contentMatch.inlineContent;
4900
- type.markSet = markExpr == "_" ? null : markExpr ? gatherMarks(this, markExpr.split(" ")) : markExpr == "" || !type.inlineContent ? [] : null;
4901
- }
4902
- for (let prop in this.marks) {
4903
- let type = this.marks[prop], excl = type.spec.excludes;
4904
- type.excluded = excl == null ? [type] : excl == "" ? [] : gatherMarks(this, excl.split(" "));
4905
- }
4906
- this.nodeFromJSON = this.nodeFromJSON.bind(this);
4907
- this.markFromJSON = this.markFromJSON.bind(this);
4908
- this.topNodeType = this.nodes[this.spec.topNode || "doc"];
4909
- this.cached.wrappings = /* @__PURE__ */ Object.create(null);
4910
- }
4911
- /**
4912
- Create a node in this schema. The `type` may be a string or a
4913
- `NodeType` instance. Attributes will be extended with defaults,
4914
- `content` may be a `Fragment`, `null`, a `Node`, or an array of
4915
- nodes.
4916
- */
4917
- node(type, attrs = null, content, marks) {
4918
- if (typeof type == "string")
4919
- type = this.nodeType(type);
4920
- else if (!(type instanceof NodeType))
4921
- throw new RangeError("Invalid node type: " + type);
4922
- else if (type.schema != this)
4923
- throw new RangeError("Node type from different schema used (" + type.name + ")");
4924
- return type.createChecked(attrs, content, marks);
4925
- }
4926
- /**
4927
- Create a text node in the schema. Empty text nodes are not
4928
- allowed.
4929
- */
4930
- text(text, marks) {
4931
- let type = this.nodes.text;
4932
- return new TextNode(type, type.defaultAttrs, text, Mark.setFrom(marks));
4933
- }
4934
- /**
4935
- Create a mark with the given type and attributes.
4936
- */
4937
- mark(type, attrs) {
4938
- if (typeof type == "string")
4939
- type = this.marks[type];
4940
- return type.create(attrs);
4941
- }
4942
- /**
4943
- Deserialize a node from its JSON representation. This method is
4944
- bound.
4945
- */
4946
- nodeFromJSON(json) {
4947
- return Node.fromJSON(this, json);
4948
- }
4949
- /**
4950
- Deserialize a mark from its JSON representation. This method is
4951
- bound.
4952
- */
4953
- markFromJSON(json) {
4954
- return Mark.fromJSON(this, json);
4955
- }
4956
- /**
4957
- @internal
4958
- */
4959
- nodeType(name) {
4960
- let found2 = this.nodes[name];
4961
- if (!found2)
4962
- throw new RangeError("Unknown node type: " + name);
4963
- return found2;
4964
- }
4965
- };
4966
- function gatherMarks(schema, marks) {
4967
- let found2 = [];
4968
- for (let i = 0; i < marks.length; i++) {
4969
- let name = marks[i], mark = schema.marks[name], ok = mark;
4970
- if (mark) {
4971
- found2.push(mark);
4972
- } else {
4973
- for (let prop in schema.marks) {
4974
- let mark2 = schema.marks[prop];
4975
- if (name == "_" || mark2.spec.group && mark2.spec.group.split(" ").indexOf(name) > -1)
4976
- found2.push(ok = mark2);
4977
- }
4978
- }
4979
- if (!ok)
4980
- throw new SyntaxError("Unknown mark type: '" + marks[i] + "'");
4981
- }
4982
- return found2;
4983
- }
4984
-
4985
2599
  // src/docs-editor/prosemirror/schema.ts
2600
+ var _prosemirrormodel = require('prosemirror-model');
4986
2601
  var newSchema = {
4987
2602
  nodes: {
4988
2603
  paragraph: {
@@ -6232,7 +3847,7 @@ var newSchema = {
6232
3847
  }
6233
3848
  }
6234
3849
  };
6235
- var pmSchema = new Schema(newSchema);
3850
+ var pmSchema = new (0, _prosemirrormodel.Schema)(newSchema);
6236
3851
 
6237
3852
  // src/docs-editor/utils.ts
6238
3853
  var BlockParsingUtils = {
@@ -6332,7 +3947,7 @@ function serializeAsRichTextBlock(input) {
6332
3947
  const blockItem = BlockParsingUtils.singleBlockItem(block);
6333
3948
  const textPropertyValue = BlockParsingUtils.richTextPropertyValue(blockItem, richTextProperty.id);
6334
3949
  const enrichedInput = { ...input, richTextPropertyValue: textPropertyValue };
6335
- const style = _nullishCoalesce(_optionalChain([richTextProperty, 'access', _3 => _3.options, 'optionalAccess', _4 => _4.richTextStyle]), () => ( "Default"));
3950
+ const style = _nullishCoalesce(_optionalChain([richTextProperty, 'access', _2 => _2.options, 'optionalAccess', _3 => _3.richTextStyle]), () => ( "Default"));
6336
3951
  switch (style) {
6337
3952
  case "Callout":
6338
3953
  return serializeAsCallout(enrichedInput);
@@ -6395,7 +4010,7 @@ function serializeBlockNodeAttributes(input) {
6395
4010
  };
6396
4011
  }
6397
4012
  function richTextHeadingLevel(property) {
6398
- const style = _optionalChain([property, 'access', _5 => _5.options, 'optionalAccess', _6 => _6.style]);
4013
+ const style = _optionalChain([property, 'access', _4 => _4.options, 'optionalAccess', _5 => _5.style]);
6399
4014
  if (!style)
6400
4015
  return void 0;
6401
4016
  switch (style) {
@@ -6519,7 +4134,7 @@ function prosemirrorDocToPage(prosemirrorDoc, definitions) {
6519
4134
  const definitionsById = mapByUnique(definitions, (d) => d.id);
6520
4135
  return {
6521
4136
  blocks: (_nullishCoalesce(prosemirrorDoc.content, () => ( []))).map((prosemirrorNode) => {
6522
- const definitionId = _optionalChain([prosemirrorNode, 'access', _7 => _7.attrs, 'optionalAccess', _8 => _8.definitionId]);
4137
+ const definitionId = _optionalChain([prosemirrorNode, 'access', _6 => _6.attrs, 'optionalAccess', _7 => _7.definitionId]);
6523
4138
  if (!definitionId)
6524
4139
  throw new Error(`Node is missing defintion id`);
6525
4140
  if (typeof definitionId !== "string")
@@ -6586,11 +4201,11 @@ function parseRichTextAttribute(mark) {
6586
4201
  case "code":
6587
4202
  return { type: "Code" };
6588
4203
  case "link":
6589
- const itemId = _optionalChain([mark, 'access', _9 => _9.attrs, 'optionalAccess', _10 => _10.itemId]);
6590
- const href = _optionalChain([mark, 'access', _11 => _11.attrs, 'optionalAccess', _12 => _12.href]);
4204
+ const itemId = _optionalChain([mark, 'access', _8 => _8.attrs, 'optionalAccess', _9 => _9.itemId]);
4205
+ const href = _optionalChain([mark, 'access', _10 => _10.attrs, 'optionalAccess', _11 => _11.href]);
6591
4206
  return {
6592
4207
  type: "Link",
6593
- openInNewWindow: _optionalChain([mark, 'access', _13 => _13.attrs, 'optionalAccess', _14 => _14.target]) !== "_self",
4208
+ openInNewWindow: _optionalChain([mark, 'access', _12 => _12.attrs, 'optionalAccess', _13 => _13.target]) !== "_self",
6594
4209
  documentationItemId: itemId,
6595
4210
  link: href
6596
4211
  };
@@ -6608,7 +4223,7 @@ function parseProsemirrorBlockAttribute(prosemirrorNode, attributeName) {
6608
4223
  return attributeValue;
6609
4224
  }
6610
4225
  function parseProsemirrorOptionalBlockAttribute(prosemirrorNode, attributeName) {
6611
- return _nullishCoalesce(_optionalChain([prosemirrorNode, 'access', _15 => _15.attrs, 'optionalAccess', _16 => _16[attributeName]]), () => ( void 0));
4226
+ return _nullishCoalesce(_optionalChain([prosemirrorNode, 'access', _14 => _14.attrs, 'optionalAccess', _15 => _15[attributeName]]), () => ( void 0));
6612
4227
  }
6613
4228
  function nonNullFilter2(item) {
6614
4229
  return item !== null;