@fewangsit/wangsvue 1.5.219-alpha.0 → 1.5.219-alpha.2
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/animation/index.es.js +54 -37
- package/assets/lottiejs/loading-page.es.js +14 -9
- package/assets/lottiejs/loading-plane.es.js +2 -2
- package/assets/lottiejs/loading-table.es.js +14 -9
- package/assets/lottiejs/no-data.es.js +14 -9
- package/backgroundimagecropper/index.es.js +61 -37
- package/badge/index.es.js +77 -67
- package/badgegroup/index.es.js +62 -50
- package/basecalendar/index.es.js +1258 -735
- package/basetree/index.es.js +213 -113
- package/breadcrumb/index.es.js +46 -38
- package/button/index.es.js +60 -54
- package/buttonbulkaction/index.es.js +168 -117
- package/buttoncopy/index.es.js +25 -22
- package/buttondownload/index.es.js +125 -76
- package/buttonfilter/index.es.js +21 -15
- package/buttonradio/index.es.js +91 -67
- package/buttonsearch/index.es.js +62 -46
- package/buttonselecttree/index.es.js +233 -172
- package/buttontoggle/index.es.js +8 -6
- package/calendar/index.es.js +113 -58
- package/card/index.es.js +44 -42
- package/checkbox/index.es.js +105 -74
- package/codesnippet/index.es.js +91 -71
- package/codesnippetadapter/index.es.js +25 -21
- package/columnlist/index.es.js +249 -171
- package/components.d.ts +0 -21
- package/config/defaultProps.es.js +9 -9
- package/config/index.es.js +11 -10
- package/config/locale.es.js +2 -2
- package/customcolumn/index.es.js +95 -78
- package/datatable/index.es.js +1071 -732
- package/dialog/index.es.js +54 -54
- package/dialogconfirm/index.es.js +90 -75
- package/dialogform/index.es.js +170 -133
- package/dialogselecttree/index.es.js +242 -194
- package/directives/focus.es.js +13 -8
- package/dropdown/index.es.js +250 -196
- package/editor/index.es.js +694 -498
- package/editorbutton/index.es.js +21 -19
- package/event-bus/index.es.js +3 -3
- package/event-bus/mitt.es.js +37 -20
- package/fieldwrapper/index.es.js +30 -25
- package/fileupload/index.es.js +230 -140
- package/filtercontainer/index.es.js +299 -222
- package/form/index.es.js +176 -126
- package/gallerypreview/index.es.js +138 -101
- package/icon/index.es.js +38 -36
- package/image/index.es.js +161 -108
- package/imagecompressor/index.es.js +616 -449
- package/imageinputinfo/index.es.js +26 -22
- package/inlinemessage/index.es.js +77 -65
- package/inputbadge/index.es.js +230 -156
- package/inputcurrency/index.es.js +146 -109
- package/inputemail/index.es.js +18 -16
- package/inputgroup/index.es.js +19 -16
- package/inputnumber/index.es.js +252 -182
- package/inputpassword/index.es.js +120 -94
- package/inputphonenumber/index.es.js +1017 -550
- package/inputrangenumber/index.es.js +129 -98
- package/inputtext/index.es.js +264 -189
- package/inputurl/index.es.js +31 -29
- package/invisiblefield/index.es.js +24 -16
- package/litedropdown/index.es.js +87 -81
- package/loading/index.es.js +21 -19
- package/loading-page-BXZ4fLOS.js +8 -0
- package/loading-page-BuLpsb_1.js +8 -0
- package/loading-page-CNqVBg__.js +4 -0
- package/loading-page-DbhhZih2.js +4 -0
- package/loading-page-DjfWXoOy.js +8 -0
- package/loading-page-S-KRY5zm.js +4 -0
- package/loading-plane-C1mi7Whv.js +4 -0
- package/loading-plane-CWq1hz_l.js +8 -0
- package/loading-table-B7LAXzAp.js +4 -0
- package/loading-table-BLmgKUsR.js +4 -0
- package/loading-table-CG7-cuhv.js +8 -0
- package/loading-table-CUPS49ta.js +4 -0
- package/loading-table-CuWWrTbv.js +8 -0
- package/loading-table-DbBzVwaZ.js +8 -0
- package/mentionlist/index.es.js +77 -44
- package/mentionsection/index.es.js +53 -43
- package/menu/index.es.js +65 -51
- package/menuitem/index.es.js +39 -37
- package/multirow/index.es.js +29 -28
- package/multiselect/index.es.js +184 -152
- package/no-data-B781skt3.js +4 -0
- package/no-data-CAksOnDl.js +4 -0
- package/no-data-DCsjBXQR.js +4 -0
- package/no-data-Dz0QOe7Q.js +8 -0
- package/no-data-_Huxiv9q.js +8 -0
- package/no-data-ybRQontJ.js +8 -0
- package/overlaypanel/index.es.js +49 -36
- package/package.json +1 -1
- package/paginator/index.es.js +36 -33
- package/plugins/WangsVue.es.js +63 -45
- package/plugins/formValidation.es.js +15 -11
- package/progressbar/index.es.js +39 -32
- package/quickfilter/index.es.js +94 -81
- package/stats.html +1 -1
- package/style.css +2 -2
- package/tabmenu/index.es.js +18 -16
- package/textarea/index.es.js +94 -72
- package/timeline/index.es.js +124 -102
- package/timelinecontentbytype/index.es.js +114 -92
- package/toast/index.es.js +67 -54
- package/toggleswitch/index.es.js +83 -66
- package/tree/index.es.js +306 -198
- package/treenode/index.es.js +464 -339
- package/treesearchinput/index.es.js +32 -26
- package/usergroup/index.es.js +83 -67
- package/username/index.es.js +99 -85
- package/utils/addAttachment.util.es.js +47 -21
- package/utils/baseToast.util.es.js +41 -33
- package/utils/convertJsonImage.util.es.js +24 -24
- package/utils/date.util.es.js +131 -106
- package/utils/exportToExcel.util.es.js +81 -47
- package/utils/filterOptions.util.es.js +8 -2
- package/utils/genPlaceholder.util.es.js +30 -16
- package/utils/getProjectPermission.util.es.js +15 -12
- package/utils/getSalesRole.util.es.js +4 -4
- package/utils/getUser.util.es.js +2 -2
- package/utils/getUserType.util.es.js +13 -8
- package/utils/isIntersect.es.js +4 -2
- package/utils/mergePropsWithDefaults.util.es.js +7 -6
- package/utils/object.util.es.js +88 -54
- package/utils/queryParamsStringfy.util.es.js +19 -11
- package/utils/role.util.es.js +5 -4
- package/utils/statusSeverity.util.es.js +20 -5
- package/utils/textFormatter.util.es.js +28 -50
- package/utils/toast.util.es.js +8 -5
- package/utils/xlsx.util.es.js +12 -6
- package/validatormessage/index.es.js +9 -9
- package/vendor/@popperjs/core/lib/createPopper.es.js +110 -83
- package/vendor/@popperjs/core/lib/dom-utils/contains.es.js +14 -13
- package/vendor/@popperjs/core/lib/dom-utils/getBoundingClientRect.es.js +33 -18
- package/vendor/@popperjs/core/lib/dom-utils/getClippingRect.es.js +55 -31
- package/vendor/@popperjs/core/lib/dom-utils/getCompositeRect.es.js +43 -22
- package/vendor/@popperjs/core/lib/dom-utils/getComputedStyle.es.js +4 -4
- package/vendor/@popperjs/core/lib/dom-utils/getDocumentElement.es.js +5 -5
- package/vendor/@popperjs/core/lib/dom-utils/getDocumentRect.es.js +23 -13
- package/vendor/@popperjs/core/lib/dom-utils/getHTMLElementScroll.es.js +4 -4
- package/vendor/@popperjs/core/lib/dom-utils/getLayoutRect.es.js +17 -9
- package/vendor/@popperjs/core/lib/dom-utils/getNodeName.es.js +3 -3
- package/vendor/@popperjs/core/lib/dom-utils/getNodeScroll.es.js +11 -7
- package/vendor/@popperjs/core/lib/dom-utils/getOffsetParent.es.js +42 -26
- package/vendor/@popperjs/core/lib/dom-utils/getParentNode.es.js +13 -10
- package/vendor/@popperjs/core/lib/dom-utils/getScrollParent.es.js +13 -7
- package/vendor/@popperjs/core/lib/dom-utils/getViewportRect.es.js +25 -15
- package/vendor/@popperjs/core/lib/dom-utils/getWindow.es.js +8 -7
- package/vendor/@popperjs/core/lib/dom-utils/getWindowScroll.es.js +8 -6
- package/vendor/@popperjs/core/lib/dom-utils/getWindowScrollBarX.es.js +6 -6
- package/vendor/@popperjs/core/lib/dom-utils/instanceOf.es.js +16 -15
- package/vendor/@popperjs/core/lib/dom-utils/isLayoutViewport.es.js +4 -4
- package/vendor/@popperjs/core/lib/dom-utils/isScrollParent.es.js +5 -5
- package/vendor/@popperjs/core/lib/dom-utils/isTableElement.es.js +4 -4
- package/vendor/@popperjs/core/lib/dom-utils/listScrollParents.es.js +17 -11
- package/vendor/@popperjs/core/lib/enums.es.js +43 -20
- package/vendor/@popperjs/core/lib/modifiers/applyStyles.es.js +49 -25
- package/vendor/@popperjs/core/lib/modifiers/arrow.es.js +61 -26
- package/vendor/@popperjs/core/lib/modifiers/computeStyles.es.js +101 -69
- package/vendor/@popperjs/core/lib/modifiers/eventListeners.es.js +30 -16
- package/vendor/@popperjs/core/lib/modifiers/flip.es.js +99 -60
- package/vendor/@popperjs/core/lib/modifiers/hide.es.js +44 -31
- package/vendor/@popperjs/core/lib/modifiers/offset.es.js +32 -20
- package/vendor/@popperjs/core/lib/modifiers/popperOffsets.es.js +11 -11
- package/vendor/@popperjs/core/lib/modifiers/preventOverflow.es.js +91 -40
- package/vendor/@popperjs/core/lib/popper.es.js +14 -13
- package/vendor/@popperjs/core/lib/utils/computeAutoPlacement.es.js +29 -21
- package/vendor/@popperjs/core/lib/utils/computeOffsets.es.js +41 -36
- package/vendor/@popperjs/core/lib/utils/debounce.es.js +11 -7
- package/vendor/@popperjs/core/lib/utils/detectOverflow.es.js +42 -28
- package/vendor/@popperjs/core/lib/utils/expandToHashMap.es.js +5 -4
- package/vendor/@popperjs/core/lib/utils/getAltAxis.es.js +3 -3
- package/vendor/@popperjs/core/lib/utils/getBasePlacement.es.js +3 -3
- package/vendor/@popperjs/core/lib/utils/getFreshSideObject.es.js +2 -2
- package/vendor/@popperjs/core/lib/utils/getMainAxisFromPlacement.es.js +3 -3
- package/vendor/@popperjs/core/lib/utils/getOppositePlacement.es.js +5 -5
- package/vendor/@popperjs/core/lib/utils/getOppositeVariationPlacement.es.js +5 -5
- package/vendor/@popperjs/core/lib/utils/getVariation.es.js +3 -3
- package/vendor/@popperjs/core/lib/utils/math.es.js +6 -4
- package/vendor/@popperjs/core/lib/utils/mergeByName.es.js +11 -10
- package/vendor/@popperjs/core/lib/utils/mergePaddingObject.es.js +4 -4
- package/vendor/@popperjs/core/lib/utils/orderModifiers.es.js +30 -22
- package/vendor/@popperjs/core/lib/utils/rectToClientRect.es.js +7 -7
- package/vendor/@popperjs/core/lib/utils/userAgent.es.js +9 -6
- package/vendor/@popperjs/core/lib/utils/within.es.js +8 -8
- package/vendor/@tiptap/core/dist/index.es.js +3494 -2000
- package/vendor/@tiptap/extension-bold/dist/index.es.js +29 -19
- package/vendor/@tiptap/extension-bubble-menu/dist/index.es.js +145 -71
- package/vendor/@tiptap/extension-bullet-list/dist/index.es.js +32 -19
- package/vendor/@tiptap/extension-code/dist/index.es.js +22 -14
- package/vendor/@tiptap/extension-document/dist/index.es.js +4 -4
- package/vendor/@tiptap/extension-floating-menu/dist/index.es.js +106 -51
- package/vendor/@tiptap/extension-heading/dist/index.es.js +38 -22
- package/vendor/@tiptap/extension-history/dist/index.es.js +11 -7
- package/vendor/@tiptap/extension-image/dist/index.es.js +20 -17
- package/vendor/@tiptap/extension-italic/dist/index.es.js +28 -18
- package/vendor/@tiptap/extension-link/dist/index.es.js +236 -147
- package/vendor/@tiptap/extension-list-item/dist/index.es.js +6 -6
- package/vendor/@tiptap/extension-mention/dist/index.es.js +98 -63
- package/vendor/@tiptap/extension-ordered-list/dist/index.es.js +38 -25
- package/vendor/@tiptap/extension-paragraph/dist/index.es.js +8 -6
- package/vendor/@tiptap/extension-placeholder/dist/index.es.js +34 -27
- package/vendor/@tiptap/extension-text/dist/index.es.js +3 -3
- package/vendor/@tiptap/extension-underline/dist/index.es.js +16 -10
- package/vendor/@tiptap/suggestion/dist/index.es.js +174 -90
- package/vendor/@tiptap/vue-3/dist/index.es.js +287 -188
- package/vendor/@wangs-ui/core/components/p-BU8h34na.es.js +17 -14
- package/vendor/@wangs-ui/core/components/p-C5lMEBcj.es.js +69 -55
- package/vendor/@wangs-ui/core/components/p-CKYwZoTo.es.js +26 -22
- package/vendor/@wangs-ui/core/components/p-CsoK-EWG.es.js +147 -102
- package/vendor/@wangs-ui/core/components/p-DPHEi31J.es.js +102 -77
- package/vendor/@wangs-ui/core/components/p-DTTCzifR.es.js +1298 -551
- package/vendor/@wangs-ui/core/components/p-Duri5p90.es.js +60 -49
- package/vendor/@wangs-ui/core/components/wangs-button.es.js +19 -15
- package/vendor/@wangs-ui/core/components/wangs-icon.es.js +3 -3
- package/vendor/@wangs-ui/core/components/wangs-input-otp.es.js +3 -3
- package/vendor/@wangs-ui/core/components/wangs-tab-menu.es.js +3 -3
- package/vendor/@wangs-ui/core/dist/esm/index-DCkh3cGv.es.js +116 -102
- package/vendor/@wangs-ui/vue/dist/index.es.js +77 -77
- package/vendor/base64toblob/base64toblob.es.js +31 -15
- package/vendor/highlight.js/es/core.es.js +5 -5
- package/vendor/highlight.js/es/languages/javascript.es.js +237 -193
- package/vendor/highlight.js/es/languages/json.es.js +18 -15
- package/vendor/highlight.js/es/languages/typescript.es.js +288 -228
- package/vendor/highlight.js/es/languages/vbscript-html.es.js +2 -2
- package/vendor/highlight.js/lib/core.es.js +1144 -666
- package/vendor/linkifyjs/dist/linkify.es.es.js +858 -405
- package/vendor/lodash/_Symbol.es.js +11 -8
- package/vendor/lodash/_baseGetTag.es.js +19 -12
- package/vendor/lodash/_baseTrim.es.js +13 -10
- package/vendor/lodash/_freeGlobal.es.js +10 -8
- package/vendor/lodash/_getRawTag.es.js +28 -15
- package/vendor/lodash/_objectToString.es.js +12 -9
- package/vendor/lodash/_root.es.js +12 -8
- package/vendor/lodash/_trimmedEndIndex.es.js +14 -11
- package/vendor/lodash/debounce.es.js +92 -54
- package/vendor/lodash/isObject.es.js +11 -9
- package/vendor/lodash/isObjectLike.es.js +10 -8
- package/vendor/lodash/isSymbol.es.js +14 -11
- package/vendor/lodash/now.es.js +12 -9
- package/vendor/lodash/throttle.es.js +25 -17
- package/vendor/lodash/toNumber.es.js +33 -23
- package/vendor/lodash-es/_DataView.es.js +4 -4
- package/vendor/lodash-es/_Hash.es.js +17 -16
- package/vendor/lodash-es/_ListCache.es.js +17 -16
- package/vendor/lodash-es/_Map.es.js +4 -4
- package/vendor/lodash-es/_MapCache.es.js +17 -16
- package/vendor/lodash-es/_Promise.es.js +4 -4
- package/vendor/lodash-es/_Set.es.js +4 -4
- package/vendor/lodash-es/_SetCache.es.js +12 -10
- package/vendor/lodash-es/_Stack.es.js +15 -15
- package/vendor/lodash-es/_Symbol.es.js +3 -3
- package/vendor/lodash-es/_Uint8Array.es.js +3 -3
- package/vendor/lodash-es/_WeakMap.es.js +4 -4
- package/vendor/lodash-es/_arrayEach.es.js +9 -5
- package/vendor/lodash-es/_arrayFilter.es.js +9 -6
- package/vendor/lodash-es/_arrayLikeKeys.es.js +21 -17
- package/vendor/lodash-es/_arrayPush.es.js +7 -5
- package/vendor/lodash-es/_arraySome.es.js +9 -6
- package/vendor/lodash-es/_assignValue.es.js +10 -7
- package/vendor/lodash-es/_assocIndexOf.es.js +9 -6
- package/vendor/lodash-es/_baseAssignValue.es.js +13 -9
- package/vendor/lodash-es/_baseClone.es.js +67 -49
- package/vendor/lodash-es/_baseCreate.es.js +15 -11
- package/vendor/lodash-es/_baseGetAllKeys.es.js +6 -6
- package/vendor/lodash-es/_baseGetTag.es.js +11 -7
- package/vendor/lodash-es/_baseIsArguments.es.js +6 -6
- package/vendor/lodash-es/_baseIsEqual.es.js +11 -5
- package/vendor/lodash-es/_baseIsEqualDeep.es.js +39 -26
- package/vendor/lodash-es/_baseIsMap.es.js +6 -6
- package/vendor/lodash-es/_baseIsNative.es.js +18 -12
- package/vendor/lodash-es/_baseIsSet.es.js +6 -6
- package/vendor/lodash-es/_baseIsTypedArray.es.js +11 -9
- package/vendor/lodash-es/_baseKeys.es.js +16 -11
- package/vendor/lodash-es/_baseTimes.es.js +7 -5
- package/vendor/lodash-es/_baseTrim.es.js +5 -5
- package/vendor/lodash-es/_baseUnary.es.js +4 -4
- package/vendor/lodash-es/_cacheHas.es.js +3 -3
- package/vendor/lodash-es/_cloneArrayBuffer.es.js +6 -5
- package/vendor/lodash-es/_cloneBuffer.es.js +11 -6
- package/vendor/lodash-es/_cloneDataView.es.js +5 -5
- package/vendor/lodash-es/_cloneRegExp.es.js +6 -5
- package/vendor/lodash-es/_cloneSymbol.es.js +5 -5
- package/vendor/lodash-es/_cloneTypedArray.es.js +5 -5
- package/vendor/lodash-es/_coreJsData.es.js +3 -3
- package/vendor/lodash-es/_defineProperty.es.js +7 -6
- package/vendor/lodash-es/_equalArrays.es.js +38 -28
- package/vendor/lodash-es/_equalByTag.es.js +55 -41
- package/vendor/lodash-es/_equalObjects.es.js +42 -28
- package/vendor/lodash-es/_freeGlobal.es.js +2 -2
- package/vendor/lodash-es/_getAllKeys.es.js +6 -6
- package/vendor/lodash-es/_getMapData.es.js +5 -5
- package/vendor/lodash-es/_getNative.es.js +6 -6
- package/vendor/lodash-es/_getPrototype.es.js +3 -3
- package/vendor/lodash-es/_getRawTag.es.js +20 -10
- package/vendor/lodash-es/_getSymbols.es.js +15 -8
- package/vendor/lodash-es/_getTag.es.js +31 -25
- package/vendor/lodash-es/_getValue.es.js +3 -3
- package/vendor/lodash-es/_hashClear.es.js +5 -4
- package/vendor/lodash-es/_hashDelete.es.js +5 -4
- package/vendor/lodash-es/_hashGet.es.js +11 -9
- package/vendor/lodash-es/_hashHas.es.js +7 -6
- package/vendor/lodash-es/_hashSet.es.js +8 -6
- package/vendor/lodash-es/_initCloneArray.es.js +10 -5
- package/vendor/lodash-es/_initCloneByTag.es.js +39 -38
- package/vendor/lodash-es/_initCloneObject.es.js +6 -6
- package/vendor/lodash-es/_isIndex.es.js +7 -5
- package/vendor/lodash-es/_isKeyable.es.js +4 -4
- package/vendor/lodash-es/_isMasked.es.js +7 -7
- package/vendor/lodash-es/_isPrototype.es.js +5 -5
- package/vendor/lodash-es/_listCacheClear.es.js +4 -3
- package/vendor/lodash-es/_listCacheDelete.es.js +17 -9
- package/vendor/lodash-es/_listCacheGet.es.js +5 -5
- package/vendor/lodash-es/_listCacheHas.es.js +4 -4
- package/vendor/lodash-es/_listCacheSet.es.js +11 -5
- package/vendor/lodash-es/_mapCacheClear.es.js +10 -9
- package/vendor/lodash-es/_mapCacheDelete.es.js +6 -5
- package/vendor/lodash-es/_mapCacheGet.es.js +4 -4
- package/vendor/lodash-es/_mapCacheHas.es.js +4 -4
- package/vendor/lodash-es/_mapCacheSet.es.js +7 -5
- package/vendor/lodash-es/_mapToArray.es.js +7 -6
- package/vendor/lodash-es/_nativeCreate.es.js +3 -3
- package/vendor/lodash-es/_nativeKeys.es.js +3 -3
- package/vendor/lodash-es/_nodeUtil.es.js +13 -6
- package/vendor/lodash-es/_objectToString.es.js +5 -4
- package/vendor/lodash-es/_overArg.es.js +4 -4
- package/vendor/lodash-es/_root.es.js +4 -3
- package/vendor/lodash-es/_setCacheAdd.es.js +5 -4
- package/vendor/lodash-es/_setCacheHas.es.js +3 -3
- package/vendor/lodash-es/_setToArray.es.js +7 -6
- package/vendor/lodash-es/_stackClear.es.js +5 -4
- package/vendor/lodash-es/_stackDelete.es.js +5 -4
- package/vendor/lodash-es/_stackGet.es.js +3 -3
- package/vendor/lodash-es/_stackHas.es.js +3 -3
- package/vendor/lodash-es/_stackSet.es.js +18 -13
- package/vendor/lodash-es/_toSource.es.js +9 -8
- package/vendor/lodash-es/_trimmedEndIndex.es.js +7 -6
- package/vendor/lodash-es/cloneDeep.es.js +5 -5
- package/vendor/lodash-es/debounce.es.js +84 -49
- package/vendor/lodash-es/eq.es.js +3 -3
- package/vendor/lodash-es/isArguments.es.js +9 -6
- package/vendor/lodash-es/isArray.es.js +2 -2
- package/vendor/lodash-es/isArrayLike.es.js +5 -5
- package/vendor/lodash-es/isBuffer.es.js +9 -4
- package/vendor/lodash-es/isEqual.es.js +4 -4
- package/vendor/lodash-es/isFunction.es.js +10 -9
- package/vendor/lodash-es/isLength.es.js +4 -4
- package/vendor/lodash-es/isMap.es.js +6 -5
- package/vendor/lodash-es/isObject.es.js +4 -4
- package/vendor/lodash-es/isObjectLike.es.js +3 -3
- package/vendor/lodash-es/isSet.es.js +6 -5
- package/vendor/lodash-es/isSymbol.es.js +6 -6
- package/vendor/lodash-es/isTypedArray.es.js +6 -5
- package/vendor/lodash-es/keys.es.js +6 -6
- package/vendor/lodash-es/now.es.js +4 -4
- package/vendor/lodash-es/stubArray.es.js +2 -2
- package/vendor/lodash-es/stubFalse.es.js +3 -3
- package/vendor/lodash-es/toNumber.es.js +25 -18
- package/vendor/lodash-es/toString.es.js +2 -2
- package/vendor/lodash-es/uniqueId.es.js +6 -6
- package/vendor/orderedmap/dist/index.es.js +65 -49
- package/vendor/primevue/api/api.esm.es.js +214 -121
- package/vendor/primevue/avatar/avatar.esm.es.js +44 -41
- package/vendor/primevue/avatar/style/avatarstyle.esm.es.js +12 -11
- package/vendor/primevue/avatargroup/avatargroup.esm.es.js +17 -16
- package/vendor/primevue/avatargroup/style/avatargroupstyle.esm.es.js +6 -5
- package/vendor/primevue/badge/badge.esm.es.js +21 -20
- package/vendor/primevue/badge/style/badgestyle.esm.es.js +19 -18
- package/vendor/primevue/base/style/basestyle.esm.es.js +88 -99
- package/vendor/primevue/basecomponent/basecomponent.esm.es.js +327 -261
- package/vendor/primevue/basedirective/basedirective.esm.es.js +257 -186
- package/vendor/primevue/baseicon/baseicon.esm.es.js +55 -49
- package/vendor/primevue/baseicon/style/baseiconstyle.esm.es.js +5 -35
- package/vendor/primevue/button/button.esm.es.js +76 -72
- package/vendor/primevue/button/style/buttonstyle.esm.es.js +46 -39
- package/vendor/primevue/card/card.esm.es.js +30 -29
- package/vendor/primevue/card/style/cardstyle.esm.es.js +6 -5
- package/vendor/primevue/checkbox/checkbox.esm.es.js +109 -101
- package/vendor/primevue/checkbox/style/checkboxstyle.esm.es.js +12 -11
- package/vendor/primevue/config/config.esm.es.js +76 -58
- package/vendor/primevue/dialog/dialog.esm.es.js +421 -281
- package/vendor/primevue/dialog/style/dialogstyle.esm.es.js +26 -22
- package/vendor/primevue/dropdown/dropdown.esm.es.js +956 -742
- package/vendor/primevue/dropdown/style/dropdownstyle.esm.es.js +33 -31
- package/vendor/primevue/fileupload/fileupload.esm.es.js +559 -450
- package/vendor/primevue/fileupload/style/fileuploadstyle.esm.es.js +14 -13
- package/vendor/primevue/focustrap/focustrap.esm.es.js +128 -90
- package/vendor/primevue/focustrap/style/focustrapstyle.esm.es.js +2 -2
- package/vendor/primevue/icons/angledoubleleft/index.esm.es.js +13 -11
- package/vendor/primevue/icons/angledoubleright/index.esm.es.js +13 -11
- package/vendor/primevue/icons/angledown/index.esm.es.js +13 -11
- package/vendor/primevue/icons/angleleft/index.esm.es.js +13 -11
- package/vendor/primevue/icons/angleright/index.esm.es.js +13 -11
- package/vendor/primevue/icons/angleup/index.esm.es.js +13 -11
- package/vendor/primevue/icons/blank/index.esm.es.js +13 -11
- package/vendor/primevue/icons/check/index.esm.es.js +13 -11
- package/vendor/primevue/icons/chevrondown/index.esm.es.js +13 -11
- package/vendor/primevue/icons/exclamationtriangle/index.esm.es.js +17 -13
- package/vendor/primevue/icons/eye/index.esm.es.js +13 -11
- package/vendor/primevue/icons/eyeslash/index.esm.es.js +13 -11
- package/vendor/primevue/icons/infocircle/index.esm.es.js +13 -11
- package/vendor/primevue/icons/plus/index.esm.es.js +13 -11
- package/vendor/primevue/icons/refresh/index.esm.es.js +13 -11
- package/vendor/primevue/icons/search/index.esm.es.js +13 -11
- package/vendor/primevue/icons/searchminus/index.esm.es.js +13 -11
- package/vendor/primevue/icons/searchplus/index.esm.es.js +13 -11
- package/vendor/primevue/icons/spinner/index.esm.es.js +13 -11
- package/vendor/primevue/icons/times/index.esm.es.js +13 -11
- package/vendor/primevue/icons/timescircle/index.esm.es.js +13 -11
- package/vendor/primevue/icons/undo/index.esm.es.js +13 -11
- package/vendor/primevue/icons/upload/index.esm.es.js +13 -11
- package/vendor/primevue/icons/windowmaximize/index.esm.es.js +13 -11
- package/vendor/primevue/icons/windowminimize/index.esm.es.js +13 -11
- package/vendor/primevue/image/image.esm.es.js +280 -235
- package/vendor/primevue/image/style/imagestyle.esm.es.js +18 -17
- package/vendor/primevue/inputgroup/inputgroup.esm.es.js +17 -16
- package/vendor/primevue/inputgroup/style/inputgroupstyle.esm.es.js +6 -5
- package/vendor/primevue/inputgroupaddon/inputgroupaddon.esm.es.js +17 -16
- package/vendor/primevue/inputgroupaddon/style/inputgroupaddonstyle.esm.es.js +6 -5
- package/vendor/primevue/inputnumber/inputnumber.esm.es.js +834 -566
- package/vendor/primevue/inputnumber/style/inputnumberstyle.esm.es.js +23 -22
- package/vendor/primevue/inputtext/inputtext.esm.es.js +32 -30
- package/vendor/primevue/inputtext/style/inputtextstyle.esm.es.js +13 -12
- package/vendor/primevue/menu/menu.esm.es.js +402 -304
- package/vendor/primevue/menu/style/menustyle.esm.es.js +14 -13
- package/vendor/primevue/message/message.esm.es.js +126 -112
- package/vendor/primevue/message/style/messagestyle.esm.es.js +9 -8
- package/vendor/primevue/multiselect/multiselect.esm.es.js +1083 -835
- package/vendor/primevue/multiselect/style/multiselectstyle.esm.es.js +38 -36
- package/vendor/primevue/overlayeventbus/overlayeventbus.esm.es.js +3 -3
- package/vendor/primevue/overlaypanel/overlaypanel.esm.es.js +275 -169
- package/vendor/primevue/overlaypanel/style/overlaypanelstyle.esm.es.js +9 -8
- package/vendor/primevue/paginator/paginator.esm.es.js +513 -469
- package/vendor/primevue/paginator/style/paginatorstyle.esm.es.js +50 -43
- package/vendor/primevue/password/password.esm.es.js +306 -233
- package/vendor/primevue/password/style/passwordstyle.esm.es.js +26 -24
- package/vendor/primevue/portal/portal.esm.es.js +17 -17
- package/vendor/primevue/progressbar/progressbar.esm.es.js +37 -35
- package/vendor/primevue/progressbar/style/progressbarstyle.esm.es.js +10 -9
- package/vendor/primevue/ripple/ripple.esm.es.js +90 -62
- package/vendor/primevue/ripple/style/ripplestyle.esm.es.js +6 -5
- package/vendor/primevue/selectbutton/selectbutton.esm.es.js +213 -167
- package/vendor/primevue/selectbutton/style/selectbuttonstyle.esm.es.js +14 -13
- package/vendor/primevue/skeleton/skeleton.esm.es.js +28 -26
- package/vendor/primevue/skeleton/style/skeletonstyle.esm.es.js +13 -11
- package/vendor/primevue/textarea/style/textareastyle.esm.es.js +12 -11
- package/vendor/primevue/textarea/textarea.esm.es.js +49 -33
- package/vendor/primevue/timeline/style/timelinestyle.esm.es.js +9 -8
- package/vendor/primevue/timeline/timeline.esm.es.js +53 -52
- package/vendor/primevue/toast/style/toaststyle.esm.es.js +54 -46
- package/vendor/primevue/toast/toast.esm.es.js +309 -260
- package/vendor/primevue/toasteventbus/toasteventbus.esm.es.js +3 -3
- package/vendor/primevue/toastservice/toastservice.esm.es.js +16 -15
- package/vendor/primevue/tooltip/style/tooltipstyle.esm.es.js +6 -5
- package/vendor/primevue/tooltip/tooltip.esm.es.js +383 -186
- package/vendor/primevue/usestyle/usestyle.esm.es.js +94 -64
- package/vendor/primevue/usetoast/usetoast.esm.es.js +9 -8
- package/vendor/primevue/utils/utils.esm.es.js +1078 -772
- package/vendor/primevue/virtualscroller/style/virtualscrollerstyle.esm.es.js +5 -67
- package/vendor/primevue/virtualscroller/virtualscroller.esm.es.js +655 -428
- package/vendor/prosemirror-commands/dist/index.es.js +454 -316
- package/vendor/prosemirror-history/dist/index.es.js +286 -178
- package/vendor/prosemirror-keymap/dist/index.es.js +68 -48
- package/vendor/prosemirror-model/dist/index.es.js +1905 -1436
- package/vendor/prosemirror-schema-list/dist/index.es.js +115 -73
- package/vendor/prosemirror-state/dist/index.es.js +467 -353
- package/vendor/prosemirror-transform/dist/index.es.js +1146 -829
- package/vendor/prosemirror-view/dist/index.es.js +4127 -2719
- package/vendor/rope-sequence/dist/index.es.js +165 -82
- package/vendor/simplebar-core/dist/index.es.js +670 -242
- package/vendor/simplebar-vue/dist/simplebar-vue.esm.es.js +73 -60
- package/vendor/single-spa/lib/es2015/esm/single-spa.min.es.js +511 -510
- package/vendor/tippy.js/dist/tippy.esm.es.js +971 -525
- package/vendor/vee-validate/dist/vee-validate.esm.es.js +1830 -1097
- package/vendor/vue-advanced-cropper/dist/index.esm-bundler.es.js +740 -738
- package/vendor/w3c-keyname/index.es.js +25 -13
- package/wangsvue.es.js +167 -208
- package/wangsvue.esm.browser.js +49417 -48026
- package/wangsvue.system.js +67600 -234
- package/api/index.es.js +0 -149
- package/apiitem/index.es.js +0 -611
- package/assignmember/index.es.js +0 -434
- package/attachment/index.es.js +0 -118
- package/attachmentchangelog/index.es.js +0 -79
- package/attachmentitem/index.es.js +0 -231
- package/attachmentthumbnail/index.es.js +0 -83
- package/changelog/index.d.ts +0 -164
- package/changelog/index.es.js +0 -85
- package/changelogfilter/index.es.js +0 -113
- package/changelogpage/index.d.ts +0 -184
- package/changelogpage/index.es.js +0 -176
- package/checklist/index.es.js +0 -571
- package/checklistchangelog/index.es.js +0 -85
- package/comment/index.d.ts +0 -187
- package/comment/index.es.js +0 -267
- package/commentblock/index.es.js +0 -337
- package/confirmdeploy/index.es.js +0 -64
- package/dependencycol/index.es.js +0 -32
- package/description/index.es.js +0 -135
- package/descriptiontab/index.es.js +0 -30
- package/detailmember/index.d.ts +0 -77
- package/detailmember/index.es.js +0 -32
- package/detailmemberadmin/index.es.js +0 -210
- package/detailmemberleader/index.es.js +0 -164
- package/detailmemberlog/index.es.js +0 -117
- package/detailsprint/index.d.ts +0 -86
- package/detailsprint/index.es.js +0 -414
- package/dialogaddattachment/index.es.js +0 -273
- package/dialogaddchecklist/index.es.js +0 -120
- package/dialogaddeditapi/index.es.js +0 -87
- package/dialogaddpbi/index.es.js +0 -197
- package/dialogadjustmenttask/index.es.js +0 -484
- package/dialogadjustmenttaskheader/index.es.js +0 -193
- package/dialogapichangelog/index.es.js +0 -83
- package/dialogassignmember/index.es.js +0 -171
- package/dialogconfirmapproval/index.es.js +0 -54
- package/dialogconfirmchecklist/index.es.js +0 -189
- package/dialogconfirmdeletetask/index.es.js +0 -70
- package/dialogconfirmdeletetaskpermanently/index.es.js +0 -50
- package/dialogconfirmedit/index.es.js +0 -50
- package/dialogconfirmfinishtask/index.es.js +0 -50
- package/dialogconfirmrestoretask/index.es.js +0 -46
- package/dialogconfirmsprint/index.es.js +0 -42
- package/dialogcopyapi/index.es.js +0 -130
- package/dialogcustomdependency/index.es.js +0 -55
- package/dialogdetailchecklisttemplate/index.es.js +0 -214
- package/dialogdetailcomponent/index.es.js +0 -121
- package/dialogdetailpbi/index.es.js +0 -192
- package/dialogfinishreview/index.es.js +0 -126
- package/dialogimprovementtask/index.es.js +0 -191
- package/dialogmemberadmin/index.es.js +0 -93
- package/dialogpreparepbi/index.es.js +0 -93
- package/dialogpriorityvalue/index.es.js +0 -85
- package/dialogreportbug/index.es.js +0 -207
- package/dialogreviewleader/index.es.js +0 -280
- package/dialogsavechecklisttemplate/index.es.js +0 -127
- package/dialogselectproject/index.es.js +0 -69
- package/dialogsetduration/index.es.js +0 -109
- package/dialogsettasklink/index.es.js +0 -153
- package/dialogtestapi/index.es.js +0 -389
- package/eventlogtab/index.es.js +0 -50
- package/infotasktab/index.es.js +0 -186
- package/inputadditional/index.es.js +0 -62
- package/inputinitialname/index.d.ts +0 -118
- package/inputinitialname/index.es.js +0 -95
- package/inputrepositoryname/index.d.ts +0 -86
- package/inputrepositoryname/index.es.js +0 -41
- package/isrequiredtext/index.es.js +0 -16
- package/legend/index.es.js +0 -727
- package/legendlist/index.es.js +0 -33
- package/loading-page-BrQattYE.js +0 -1
- package/loading-page-CgfbWppy.js +0 -1
- package/loading-page-CoC9UhfC.js +0 -4
- package/loading-page-CoXtqoc9.js +0 -4
- package/loading-page-DbLuqCHa.js +0 -1
- package/loading-page-f8D03l3G.js +0 -4
- package/loading-plane-CgfbWppy.js +0 -1
- package/loading-plane-CoXtqoc9.js +0 -4
- package/loading-table-Bdr9ZhtP.js +0 -1
- package/loading-table-ByUoWqUo.js +0 -4
- package/loading-table-BygEMzFM.js +0 -4
- package/loading-table-BzrSQlA0.js +0 -1
- package/loading-table-D9bw9OcI.js +0 -4
- package/loading-table-chOgXi94.js +0 -1
- package/no-data-CTKux8RI.js +0 -4
- package/no-data-Cgze_Rvp.js +0 -1
- package/no-data-DLHO1L_u.js +0 -4
- package/no-data-Dep79CBh.js +0 -1
- package/no-data-g0dJCy2p.js +0 -4
- package/no-data-y1X5WtcQ.js +0 -1
- package/notificationitem/index.d.ts +0 -107
- package/notificationitem/index.es.js +0 -333
- package/reviewitem/index.es.js +0 -65
- package/reviewtab/index.es.js +0 -44
- package/services/calendar.service.es.js +0 -32
- package/sonarqubesummary/index.es.js +0 -234
- package/sprintsummary/index.es.js +0 -73
- package/summaryaccordion/index.d.ts +0 -121
- package/summaryaccordion/index.es.js +0 -365
- package/taskdependency/index.es.js +0 -686
- package/taskdetail/index.d.ts +0 -82
- package/taskdetail/index.es.js +0 -491
- package/taskdetailpbi/index.d.ts +0 -35
- package/taskdetailpbi/index.es.js +0 -172
- package/taskdetailunassignedpbi/index.es.js +0 -261
- package/tasklink/index.es.js +0 -257
- package/tasklinkchangelog/index.es.js +0 -93
- package/tasklist/index.es.js +0 -92
- package/taskmore/index.es.js +0 -52
- package/taskstatusbadge/index.es.js +0 -18
- package/tasktable/index.d.ts +0 -87
- package/tasktable/index.es.js +0 -832
- package/ticket/index.es.js +0 -151
- package/tooltipspan/index.es.js +0 -30
- package/utils/updateSprintStatus.util.es.js +0 -17
- package/valueformdatainput/index.es.js +0 -70
- package/workcalendar/index.es.js +0 -351
|
@@ -1,75 +1,82 @@
|
|
|
1
|
-
import { O as
|
|
2
|
-
function
|
|
3
|
-
for (let
|
|
4
|
-
if (
|
|
5
|
-
return
|
|
6
|
-
let
|
|
7
|
-
if (
|
|
8
|
-
|
|
1
|
+
import { O as OrderedMap } from "../../orderedmap/dist/index.es.js";
|
|
2
|
+
function findDiffStart(a, b, pos) {
|
|
3
|
+
for (let i = 0; ; i++) {
|
|
4
|
+
if (i == a.childCount || i == b.childCount)
|
|
5
|
+
return a.childCount == b.childCount ? null : pos;
|
|
6
|
+
let childA = a.child(i), childB = b.child(i);
|
|
7
|
+
if (childA == childB) {
|
|
8
|
+
pos += childA.nodeSize;
|
|
9
9
|
continue;
|
|
10
10
|
}
|
|
11
|
-
if (!
|
|
12
|
-
return
|
|
13
|
-
if (
|
|
14
|
-
for (let
|
|
15
|
-
|
|
16
|
-
return
|
|
11
|
+
if (!childA.sameMarkup(childB))
|
|
12
|
+
return pos;
|
|
13
|
+
if (childA.isText && childA.text != childB.text) {
|
|
14
|
+
for (let j = 0; childA.text[j] == childB.text[j]; j++)
|
|
15
|
+
pos++;
|
|
16
|
+
return pos;
|
|
17
17
|
}
|
|
18
|
-
if (
|
|
19
|
-
let
|
|
20
|
-
if (
|
|
21
|
-
return
|
|
18
|
+
if (childA.content.size || childB.content.size) {
|
|
19
|
+
let inner = findDiffStart(childA.content, childB.content, pos + 1);
|
|
20
|
+
if (inner != null)
|
|
21
|
+
return inner;
|
|
22
22
|
}
|
|
23
|
-
|
|
23
|
+
pos += childA.nodeSize;
|
|
24
24
|
}
|
|
25
25
|
}
|
|
26
|
-
function
|
|
27
|
-
for (let
|
|
28
|
-
if (
|
|
29
|
-
return
|
|
30
|
-
let
|
|
31
|
-
if (
|
|
32
|
-
|
|
26
|
+
function findDiffEnd(a, b, posA, posB) {
|
|
27
|
+
for (let iA = a.childCount, iB = b.childCount; ; ) {
|
|
28
|
+
if (iA == 0 || iB == 0)
|
|
29
|
+
return iA == iB ? null : { a: posA, b: posB };
|
|
30
|
+
let childA = a.child(--iA), childB = b.child(--iB), size = childA.nodeSize;
|
|
31
|
+
if (childA == childB) {
|
|
32
|
+
posA -= size;
|
|
33
|
+
posB -= size;
|
|
33
34
|
continue;
|
|
34
35
|
}
|
|
35
|
-
if (!
|
|
36
|
-
return { a:
|
|
37
|
-
if (
|
|
38
|
-
let
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
36
|
+
if (!childA.sameMarkup(childB))
|
|
37
|
+
return { a: posA, b: posB };
|
|
38
|
+
if (childA.isText && childA.text != childB.text) {
|
|
39
|
+
let same = 0, minSize = Math.min(childA.text.length, childB.text.length);
|
|
40
|
+
while (same < minSize && childA.text[childA.text.length - same - 1] == childB.text[childB.text.length - same - 1]) {
|
|
41
|
+
same++;
|
|
42
|
+
posA--;
|
|
43
|
+
posB--;
|
|
44
|
+
}
|
|
45
|
+
return { a: posA, b: posB };
|
|
42
46
|
}
|
|
43
|
-
if (
|
|
44
|
-
let
|
|
45
|
-
if (
|
|
46
|
-
return
|
|
47
|
+
if (childA.content.size || childB.content.size) {
|
|
48
|
+
let inner = findDiffEnd(childA.content, childB.content, posA - 1, posB - 1);
|
|
49
|
+
if (inner)
|
|
50
|
+
return inner;
|
|
47
51
|
}
|
|
48
|
-
|
|
52
|
+
posA -= size;
|
|
53
|
+
posB -= size;
|
|
49
54
|
}
|
|
50
55
|
}
|
|
51
|
-
class
|
|
56
|
+
class Fragment {
|
|
52
57
|
/**
|
|
53
58
|
@internal
|
|
54
59
|
*/
|
|
55
|
-
constructor(
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
60
|
+
constructor(content, size) {
|
|
61
|
+
this.content = content;
|
|
62
|
+
this.size = size || 0;
|
|
63
|
+
if (size == null)
|
|
64
|
+
for (let i = 0; i < content.length; i++)
|
|
65
|
+
this.size += content[i].nodeSize;
|
|
59
66
|
}
|
|
60
67
|
/**
|
|
61
68
|
Invoke a callback for all descendant nodes between the given two
|
|
62
69
|
positions (relative to start of this fragment). Doesn't descend
|
|
63
70
|
into a node when the callback returns `false`.
|
|
64
71
|
*/
|
|
65
|
-
nodesBetween(
|
|
66
|
-
for (let
|
|
67
|
-
let
|
|
68
|
-
if (
|
|
69
|
-
let
|
|
70
|
-
|
|
72
|
+
nodesBetween(from, to, f, nodeStart = 0, parent) {
|
|
73
|
+
for (let i = 0, pos = 0; pos < to; i++) {
|
|
74
|
+
let child = this.content[i], end = pos + child.nodeSize;
|
|
75
|
+
if (end > from && f(child, nodeStart + pos, parent || null, i) !== false && child.content.size) {
|
|
76
|
+
let start = pos + 1;
|
|
77
|
+
child.nodesBetween(Math.max(0, from - start), Math.min(child.content.size, to - start), f, nodeStart + start);
|
|
71
78
|
}
|
|
72
|
-
|
|
79
|
+
pos = end;
|
|
73
80
|
}
|
|
74
81
|
}
|
|
75
82
|
/**
|
|
@@ -77,89 +84,116 @@ class c {
|
|
|
77
84
|
relative to the start of the fragment. The callback may return
|
|
78
85
|
`false` to prevent traversal of a given node's children.
|
|
79
86
|
*/
|
|
80
|
-
descendants(
|
|
81
|
-
this.nodesBetween(0, this.size,
|
|
87
|
+
descendants(f) {
|
|
88
|
+
this.nodesBetween(0, this.size, f);
|
|
82
89
|
}
|
|
83
90
|
/**
|
|
84
91
|
Extract the text between `from` and `to`. See the same method on
|
|
85
92
|
[`Node`](https://prosemirror.net/docs/ref/#model.Node.textBetween).
|
|
86
93
|
*/
|
|
87
|
-
textBetween(
|
|
88
|
-
let
|
|
89
|
-
|
|
90
|
-
let
|
|
91
|
-
|
|
92
|
-
|
|
94
|
+
textBetween(from, to, blockSeparator, leafText) {
|
|
95
|
+
let text = "", first = true;
|
|
96
|
+
this.nodesBetween(from, to, (node, pos) => {
|
|
97
|
+
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) : "";
|
|
98
|
+
if (node.isBlock && (node.isLeaf && nodeText || node.isTextblock) && blockSeparator) {
|
|
99
|
+
if (first)
|
|
100
|
+
first = false;
|
|
101
|
+
else
|
|
102
|
+
text += blockSeparator;
|
|
103
|
+
}
|
|
104
|
+
text += nodeText;
|
|
105
|
+
}, 0);
|
|
106
|
+
return text;
|
|
93
107
|
}
|
|
94
108
|
/**
|
|
95
109
|
Create a new fragment containing the combined content of this
|
|
96
110
|
fragment and the other.
|
|
97
111
|
*/
|
|
98
|
-
append(
|
|
99
|
-
if (!
|
|
112
|
+
append(other) {
|
|
113
|
+
if (!other.size)
|
|
100
114
|
return this;
|
|
101
115
|
if (!this.size)
|
|
102
|
-
return
|
|
103
|
-
let
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
116
|
+
return other;
|
|
117
|
+
let last = this.lastChild, first = other.firstChild, content = this.content.slice(), i = 0;
|
|
118
|
+
if (last.isText && last.sameMarkup(first)) {
|
|
119
|
+
content[content.length - 1] = last.withText(last.text + first.text);
|
|
120
|
+
i = 1;
|
|
121
|
+
}
|
|
122
|
+
for (; i < other.content.length; i++)
|
|
123
|
+
content.push(other.content[i]);
|
|
124
|
+
return new Fragment(content, this.size + other.size);
|
|
107
125
|
}
|
|
108
126
|
/**
|
|
109
127
|
Cut out the sub-fragment between the two given positions.
|
|
110
128
|
*/
|
|
111
|
-
cut(
|
|
112
|
-
if (
|
|
129
|
+
cut(from, to = this.size) {
|
|
130
|
+
if (from == 0 && to == this.size)
|
|
113
131
|
return this;
|
|
114
|
-
let
|
|
115
|
-
if (
|
|
116
|
-
for (let
|
|
117
|
-
let
|
|
118
|
-
|
|
132
|
+
let result = [], size = 0;
|
|
133
|
+
if (to > from)
|
|
134
|
+
for (let i = 0, pos = 0; pos < to; i++) {
|
|
135
|
+
let child = this.content[i], end = pos + child.nodeSize;
|
|
136
|
+
if (end > from) {
|
|
137
|
+
if (pos < from || end > to) {
|
|
138
|
+
if (child.isText)
|
|
139
|
+
child = child.cut(Math.max(0, from - pos), Math.min(child.text.length, to - pos));
|
|
140
|
+
else
|
|
141
|
+
child = child.cut(Math.max(0, from - pos - 1), Math.min(child.content.size, to - pos - 1));
|
|
142
|
+
}
|
|
143
|
+
result.push(child);
|
|
144
|
+
size += child.nodeSize;
|
|
145
|
+
}
|
|
146
|
+
pos = end;
|
|
119
147
|
}
|
|
120
|
-
return new
|
|
148
|
+
return new Fragment(result, size);
|
|
121
149
|
}
|
|
122
150
|
/**
|
|
123
151
|
@internal
|
|
124
152
|
*/
|
|
125
|
-
cutByIndex(
|
|
126
|
-
|
|
153
|
+
cutByIndex(from, to) {
|
|
154
|
+
if (from == to)
|
|
155
|
+
return Fragment.empty;
|
|
156
|
+
if (from == 0 && to == this.content.length)
|
|
157
|
+
return this;
|
|
158
|
+
return new Fragment(this.content.slice(from, to));
|
|
127
159
|
}
|
|
128
160
|
/**
|
|
129
161
|
Create a new fragment in which the node at the given index is
|
|
130
162
|
replaced by the given node.
|
|
131
163
|
*/
|
|
132
|
-
replaceChild(
|
|
133
|
-
let
|
|
134
|
-
if (
|
|
164
|
+
replaceChild(index, node) {
|
|
165
|
+
let current = this.content[index];
|
|
166
|
+
if (current == node)
|
|
135
167
|
return this;
|
|
136
|
-
let
|
|
137
|
-
|
|
168
|
+
let copy2 = this.content.slice();
|
|
169
|
+
let size = this.size + node.nodeSize - current.nodeSize;
|
|
170
|
+
copy2[index] = node;
|
|
171
|
+
return new Fragment(copy2, size);
|
|
138
172
|
}
|
|
139
173
|
/**
|
|
140
174
|
Create a new fragment by prepending the given node to this
|
|
141
175
|
fragment.
|
|
142
176
|
*/
|
|
143
|
-
addToStart(
|
|
144
|
-
return new
|
|
177
|
+
addToStart(node) {
|
|
178
|
+
return new Fragment([node].concat(this.content), this.size + node.nodeSize);
|
|
145
179
|
}
|
|
146
180
|
/**
|
|
147
181
|
Create a new fragment by appending the given node to this
|
|
148
182
|
fragment.
|
|
149
183
|
*/
|
|
150
|
-
addToEnd(
|
|
151
|
-
return new
|
|
184
|
+
addToEnd(node) {
|
|
185
|
+
return new Fragment(this.content.concat(node), this.size + node.nodeSize);
|
|
152
186
|
}
|
|
153
187
|
/**
|
|
154
188
|
Compare this fragment to another one.
|
|
155
189
|
*/
|
|
156
|
-
eq(
|
|
157
|
-
if (this.content.length !=
|
|
158
|
-
return
|
|
159
|
-
for (let
|
|
160
|
-
if (!this.content[
|
|
161
|
-
return
|
|
162
|
-
return
|
|
190
|
+
eq(other) {
|
|
191
|
+
if (this.content.length != other.content.length)
|
|
192
|
+
return false;
|
|
193
|
+
for (let i = 0; i < this.content.length; i++)
|
|
194
|
+
if (!this.content[i].eq(other.content[i]))
|
|
195
|
+
return false;
|
|
196
|
+
return true;
|
|
163
197
|
}
|
|
164
198
|
/**
|
|
165
199
|
The first child of the fragment, or `null` if it is empty.
|
|
@@ -183,34 +217,35 @@ class c {
|
|
|
183
217
|
Get the child node at the given index. Raise an error when the
|
|
184
218
|
index is out of range.
|
|
185
219
|
*/
|
|
186
|
-
child(
|
|
187
|
-
let
|
|
188
|
-
if (!
|
|
189
|
-
throw new RangeError("Index " +
|
|
190
|
-
return
|
|
220
|
+
child(index) {
|
|
221
|
+
let found2 = this.content[index];
|
|
222
|
+
if (!found2)
|
|
223
|
+
throw new RangeError("Index " + index + " out of range for " + this);
|
|
224
|
+
return found2;
|
|
191
225
|
}
|
|
192
226
|
/**
|
|
193
227
|
Get the child node at the given index, if it exists.
|
|
194
228
|
*/
|
|
195
|
-
maybeChild(
|
|
196
|
-
return this.content[
|
|
229
|
+
maybeChild(index) {
|
|
230
|
+
return this.content[index] || null;
|
|
197
231
|
}
|
|
198
232
|
/**
|
|
199
233
|
Call `f` for every child node, passing the node, its offset
|
|
200
234
|
into this parent node, and its index.
|
|
201
235
|
*/
|
|
202
|
-
forEach(
|
|
203
|
-
for (let
|
|
204
|
-
let
|
|
205
|
-
|
|
236
|
+
forEach(f) {
|
|
237
|
+
for (let i = 0, p = 0; i < this.content.length; i++) {
|
|
238
|
+
let child = this.content[i];
|
|
239
|
+
f(child, p, i);
|
|
240
|
+
p += child.nodeSize;
|
|
206
241
|
}
|
|
207
242
|
}
|
|
208
243
|
/**
|
|
209
244
|
Find the first position at which this fragment and another
|
|
210
245
|
fragment differ, or `null` if they are the same.
|
|
211
246
|
*/
|
|
212
|
-
findDiffStart(
|
|
213
|
-
return
|
|
247
|
+
findDiffStart(other, pos = 0) {
|
|
248
|
+
return findDiffStart(this, other, pos);
|
|
214
249
|
}
|
|
215
250
|
/**
|
|
216
251
|
Find the first position, searching from the end, at which this
|
|
@@ -218,26 +253,29 @@ class c {
|
|
|
218
253
|
the same. Since this position will not be the same in both
|
|
219
254
|
nodes, an object with two separate positions is returned.
|
|
220
255
|
*/
|
|
221
|
-
findDiffEnd(
|
|
222
|
-
return
|
|
256
|
+
findDiffEnd(other, pos = this.size, otherPos = other.size) {
|
|
257
|
+
return findDiffEnd(this, other, pos, otherPos);
|
|
223
258
|
}
|
|
224
259
|
/**
|
|
225
260
|
Find the index and inner offset corresponding to a given relative
|
|
226
261
|
position in this fragment. The result object will be reused
|
|
227
262
|
(overwritten) the next time the function is called. @internal
|
|
228
263
|
*/
|
|
229
|
-
findIndex(
|
|
230
|
-
if (
|
|
231
|
-
return
|
|
232
|
-
if (
|
|
233
|
-
return
|
|
234
|
-
if (
|
|
235
|
-
throw new RangeError(`Position ${
|
|
236
|
-
for (let
|
|
237
|
-
let
|
|
238
|
-
if (
|
|
239
|
-
|
|
240
|
-
|
|
264
|
+
findIndex(pos, round = -1) {
|
|
265
|
+
if (pos == 0)
|
|
266
|
+
return retIndex(0, pos);
|
|
267
|
+
if (pos == this.size)
|
|
268
|
+
return retIndex(this.content.length, pos);
|
|
269
|
+
if (pos > this.size || pos < 0)
|
|
270
|
+
throw new RangeError(`Position ${pos} outside of fragment (${this})`);
|
|
271
|
+
for (let i = 0, curPos = 0; ; i++) {
|
|
272
|
+
let cur = this.child(i), end = curPos + cur.nodeSize;
|
|
273
|
+
if (end >= pos) {
|
|
274
|
+
if (end == pos || round > 0)
|
|
275
|
+
return retIndex(i + 1, end);
|
|
276
|
+
return retIndex(i, curPos);
|
|
277
|
+
}
|
|
278
|
+
curPos = end;
|
|
241
279
|
}
|
|
242
280
|
}
|
|
243
281
|
/**
|
|
@@ -256,31 +294,38 @@ class c {
|
|
|
256
294
|
Create a JSON-serializeable representation of this fragment.
|
|
257
295
|
*/
|
|
258
296
|
toJSON() {
|
|
259
|
-
return this.content.length ? this.content.map((
|
|
297
|
+
return this.content.length ? this.content.map((n) => n.toJSON()) : null;
|
|
260
298
|
}
|
|
261
299
|
/**
|
|
262
300
|
Deserialize a fragment from its JSON representation.
|
|
263
301
|
*/
|
|
264
|
-
static fromJSON(
|
|
265
|
-
if (!
|
|
266
|
-
return
|
|
267
|
-
if (!Array.isArray(
|
|
302
|
+
static fromJSON(schema, value) {
|
|
303
|
+
if (!value)
|
|
304
|
+
return Fragment.empty;
|
|
305
|
+
if (!Array.isArray(value))
|
|
268
306
|
throw new RangeError("Invalid input for Fragment.fromJSON");
|
|
269
|
-
return new
|
|
307
|
+
return new Fragment(value.map(schema.nodeFromJSON));
|
|
270
308
|
}
|
|
271
309
|
/**
|
|
272
310
|
Build a fragment from an array of nodes. Ensures that adjacent
|
|
273
311
|
text nodes with the same marks are joined together.
|
|
274
312
|
*/
|
|
275
|
-
static fromArray(
|
|
276
|
-
if (!
|
|
277
|
-
return
|
|
278
|
-
let
|
|
279
|
-
for (let i = 0; i <
|
|
280
|
-
let
|
|
281
|
-
|
|
313
|
+
static fromArray(array) {
|
|
314
|
+
if (!array.length)
|
|
315
|
+
return Fragment.empty;
|
|
316
|
+
let joined, size = 0;
|
|
317
|
+
for (let i = 0; i < array.length; i++) {
|
|
318
|
+
let node = array[i];
|
|
319
|
+
size += node.nodeSize;
|
|
320
|
+
if (i && node.isText && array[i - 1].sameMarkup(node)) {
|
|
321
|
+
if (!joined)
|
|
322
|
+
joined = array.slice(0, i);
|
|
323
|
+
joined[joined.length - 1] = node.withText(joined[joined.length - 1].text + node.text);
|
|
324
|
+
} else if (joined) {
|
|
325
|
+
joined.push(node);
|
|
326
|
+
}
|
|
282
327
|
}
|
|
283
|
-
return new
|
|
328
|
+
return new Fragment(joined || array, size);
|
|
284
329
|
}
|
|
285
330
|
/**
|
|
286
331
|
Create a fragment from something that can be interpreted as a
|
|
@@ -288,53 +333,56 @@ class c {
|
|
|
288
333
|
fragment, the fragment itself. For a node or array of nodes, a
|
|
289
334
|
fragment containing those nodes.
|
|
290
335
|
*/
|
|
291
|
-
static from(
|
|
292
|
-
if (!
|
|
293
|
-
return
|
|
294
|
-
if (
|
|
295
|
-
return
|
|
296
|
-
if (Array.isArray(
|
|
297
|
-
return this.fromArray(
|
|
298
|
-
if (
|
|
299
|
-
return new
|
|
300
|
-
throw new RangeError("Can not convert " +
|
|
301
|
-
}
|
|
302
|
-
}
|
|
303
|
-
|
|
304
|
-
const
|
|
305
|
-
function
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
if (
|
|
312
|
-
return
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
if (
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
336
|
+
static from(nodes) {
|
|
337
|
+
if (!nodes)
|
|
338
|
+
return Fragment.empty;
|
|
339
|
+
if (nodes instanceof Fragment)
|
|
340
|
+
return nodes;
|
|
341
|
+
if (Array.isArray(nodes))
|
|
342
|
+
return this.fromArray(nodes);
|
|
343
|
+
if (nodes.attrs)
|
|
344
|
+
return new Fragment([nodes], nodes.nodeSize);
|
|
345
|
+
throw new RangeError("Can not convert " + nodes + " to a Fragment" + (nodes.nodesBetween ? " (looks like multiple versions of prosemirror-model were loaded)" : ""));
|
|
346
|
+
}
|
|
347
|
+
}
|
|
348
|
+
Fragment.empty = new Fragment([], 0);
|
|
349
|
+
const found = { index: 0, offset: 0 };
|
|
350
|
+
function retIndex(index, offset) {
|
|
351
|
+
found.index = index;
|
|
352
|
+
found.offset = offset;
|
|
353
|
+
return found;
|
|
354
|
+
}
|
|
355
|
+
function compareDeep(a, b) {
|
|
356
|
+
if (a === b)
|
|
357
|
+
return true;
|
|
358
|
+
if (!(a && typeof a == "object") || !(b && typeof b == "object"))
|
|
359
|
+
return false;
|
|
360
|
+
let array = Array.isArray(a);
|
|
361
|
+
if (Array.isArray(b) != array)
|
|
362
|
+
return false;
|
|
363
|
+
if (array) {
|
|
364
|
+
if (a.length != b.length)
|
|
365
|
+
return false;
|
|
366
|
+
for (let i = 0; i < a.length; i++)
|
|
367
|
+
if (!compareDeep(a[i], b[i]))
|
|
368
|
+
return false;
|
|
322
369
|
} else {
|
|
323
|
-
for (let
|
|
324
|
-
if (!(
|
|
325
|
-
return
|
|
326
|
-
for (let
|
|
327
|
-
if (!(
|
|
328
|
-
return
|
|
370
|
+
for (let p in a)
|
|
371
|
+
if (!(p in b) || !compareDeep(a[p], b[p]))
|
|
372
|
+
return false;
|
|
373
|
+
for (let p in b)
|
|
374
|
+
if (!(p in a))
|
|
375
|
+
return false;
|
|
329
376
|
}
|
|
330
|
-
return
|
|
377
|
+
return true;
|
|
331
378
|
}
|
|
332
|
-
class
|
|
379
|
+
class Mark {
|
|
333
380
|
/**
|
|
334
381
|
@internal
|
|
335
382
|
*/
|
|
336
|
-
constructor(
|
|
337
|
-
this.type =
|
|
383
|
+
constructor(type, attrs) {
|
|
384
|
+
this.type = type;
|
|
385
|
+
this.attrs = attrs;
|
|
338
386
|
}
|
|
339
387
|
/**
|
|
340
388
|
Given a set of marks, create a new set which contains this one as
|
|
@@ -343,101 +391,115 @@ class u {
|
|
|
343
391
|
[exclusive](https://prosemirror.net/docs/ref/#model.MarkSpec.excludes) with this mark are present,
|
|
344
392
|
those are replaced by this one.
|
|
345
393
|
*/
|
|
346
|
-
addToSet(
|
|
347
|
-
let
|
|
348
|
-
for (let i = 0; i <
|
|
349
|
-
let
|
|
350
|
-
if (this.eq(
|
|
351
|
-
return
|
|
352
|
-
if (this.type.excludes(
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
394
|
+
addToSet(set) {
|
|
395
|
+
let copy2, placed = false;
|
|
396
|
+
for (let i = 0; i < set.length; i++) {
|
|
397
|
+
let other = set[i];
|
|
398
|
+
if (this.eq(other))
|
|
399
|
+
return set;
|
|
400
|
+
if (this.type.excludes(other.type)) {
|
|
401
|
+
if (!copy2)
|
|
402
|
+
copy2 = set.slice(0, i);
|
|
403
|
+
} else if (other.type.excludes(this.type)) {
|
|
404
|
+
return set;
|
|
405
|
+
} else {
|
|
406
|
+
if (!placed && other.type.rank > this.type.rank) {
|
|
407
|
+
if (!copy2)
|
|
408
|
+
copy2 = set.slice(0, i);
|
|
409
|
+
copy2.push(this);
|
|
410
|
+
placed = true;
|
|
411
|
+
}
|
|
412
|
+
if (copy2)
|
|
413
|
+
copy2.push(other);
|
|
358
414
|
}
|
|
359
415
|
}
|
|
360
|
-
|
|
416
|
+
if (!copy2)
|
|
417
|
+
copy2 = set.slice();
|
|
418
|
+
if (!placed)
|
|
419
|
+
copy2.push(this);
|
|
420
|
+
return copy2;
|
|
361
421
|
}
|
|
362
422
|
/**
|
|
363
423
|
Remove this mark from the given set, returning a new set. If this
|
|
364
424
|
mark is not in the set, the set itself is returned.
|
|
365
425
|
*/
|
|
366
|
-
removeFromSet(
|
|
367
|
-
for (let
|
|
368
|
-
if (this.eq(
|
|
369
|
-
return
|
|
370
|
-
return
|
|
426
|
+
removeFromSet(set) {
|
|
427
|
+
for (let i = 0; i < set.length; i++)
|
|
428
|
+
if (this.eq(set[i]))
|
|
429
|
+
return set.slice(0, i).concat(set.slice(i + 1));
|
|
430
|
+
return set;
|
|
371
431
|
}
|
|
372
432
|
/**
|
|
373
433
|
Test whether this mark is in the given set of marks.
|
|
374
434
|
*/
|
|
375
|
-
isInSet(
|
|
376
|
-
for (let
|
|
377
|
-
if (this.eq(
|
|
378
|
-
return
|
|
379
|
-
return
|
|
435
|
+
isInSet(set) {
|
|
436
|
+
for (let i = 0; i < set.length; i++)
|
|
437
|
+
if (this.eq(set[i]))
|
|
438
|
+
return true;
|
|
439
|
+
return false;
|
|
380
440
|
}
|
|
381
441
|
/**
|
|
382
442
|
Test whether this mark has the same type and attributes as
|
|
383
443
|
another mark.
|
|
384
444
|
*/
|
|
385
|
-
eq(
|
|
386
|
-
return this ==
|
|
445
|
+
eq(other) {
|
|
446
|
+
return this == other || this.type == other.type && compareDeep(this.attrs, other.attrs);
|
|
387
447
|
}
|
|
388
448
|
/**
|
|
389
449
|
Convert this mark to a JSON-serializeable representation.
|
|
390
450
|
*/
|
|
391
451
|
toJSON() {
|
|
392
|
-
let
|
|
393
|
-
for (let
|
|
394
|
-
|
|
452
|
+
let obj = { type: this.type.name };
|
|
453
|
+
for (let _ in this.attrs) {
|
|
454
|
+
obj.attrs = this.attrs;
|
|
395
455
|
break;
|
|
396
456
|
}
|
|
397
|
-
return
|
|
457
|
+
return obj;
|
|
398
458
|
}
|
|
399
459
|
/**
|
|
400
460
|
Deserialize a mark from JSON.
|
|
401
461
|
*/
|
|
402
|
-
static fromJSON(
|
|
403
|
-
if (!
|
|
462
|
+
static fromJSON(schema, json) {
|
|
463
|
+
if (!json)
|
|
404
464
|
throw new RangeError("Invalid input for Mark.fromJSON");
|
|
405
|
-
let
|
|
406
|
-
if (!
|
|
407
|
-
throw new RangeError(`There is no mark type ${
|
|
408
|
-
let
|
|
409
|
-
|
|
465
|
+
let type = schema.marks[json.type];
|
|
466
|
+
if (!type)
|
|
467
|
+
throw new RangeError(`There is no mark type ${json.type} in this schema`);
|
|
468
|
+
let mark = type.create(json.attrs);
|
|
469
|
+
type.checkAttrs(mark.attrs);
|
|
470
|
+
return mark;
|
|
410
471
|
}
|
|
411
472
|
/**
|
|
412
473
|
Test whether two sets of marks are identical.
|
|
413
474
|
*/
|
|
414
|
-
static sameSet(
|
|
415
|
-
if (
|
|
416
|
-
return
|
|
417
|
-
if (
|
|
418
|
-
return
|
|
419
|
-
for (let
|
|
420
|
-
if (!
|
|
421
|
-
return
|
|
422
|
-
return
|
|
475
|
+
static sameSet(a, b) {
|
|
476
|
+
if (a == b)
|
|
477
|
+
return true;
|
|
478
|
+
if (a.length != b.length)
|
|
479
|
+
return false;
|
|
480
|
+
for (let i = 0; i < a.length; i++)
|
|
481
|
+
if (!a[i].eq(b[i]))
|
|
482
|
+
return false;
|
|
483
|
+
return true;
|
|
423
484
|
}
|
|
424
485
|
/**
|
|
425
486
|
Create a properly sorted mark set from null, a single mark, or an
|
|
426
487
|
unsorted array of marks.
|
|
427
488
|
*/
|
|
428
|
-
static setFrom(
|
|
429
|
-
if (!
|
|
430
|
-
return
|
|
431
|
-
if (
|
|
432
|
-
return [
|
|
433
|
-
let
|
|
434
|
-
|
|
489
|
+
static setFrom(marks) {
|
|
490
|
+
if (!marks || Array.isArray(marks) && marks.length == 0)
|
|
491
|
+
return Mark.none;
|
|
492
|
+
if (marks instanceof Mark)
|
|
493
|
+
return [marks];
|
|
494
|
+
let copy2 = marks.slice();
|
|
495
|
+
copy2.sort((a, b) => a.type.rank - b.type.rank);
|
|
496
|
+
return copy2;
|
|
435
497
|
}
|
|
436
498
|
}
|
|
437
|
-
|
|
438
|
-
class
|
|
499
|
+
Mark.none = [];
|
|
500
|
+
class ReplaceError extends Error {
|
|
439
501
|
}
|
|
440
|
-
class
|
|
502
|
+
class Slice {
|
|
441
503
|
/**
|
|
442
504
|
Create a slice. When specifying a non-zero open depth, you must
|
|
443
505
|
make sure that there are nodes of at least that depth at the
|
|
@@ -450,8 +512,10 @@ class d {
|
|
|
450
512
|
start/end/middle for such a node, depending on which sides are
|
|
451
513
|
open.
|
|
452
514
|
*/
|
|
453
|
-
constructor(
|
|
454
|
-
this.content =
|
|
515
|
+
constructor(content, openStart, openEnd) {
|
|
516
|
+
this.content = content;
|
|
517
|
+
this.openStart = openStart;
|
|
518
|
+
this.openEnd = openEnd;
|
|
455
519
|
}
|
|
456
520
|
/**
|
|
457
521
|
The size this slice would add when inserted into a document.
|
|
@@ -462,21 +526,21 @@ class d {
|
|
|
462
526
|
/**
|
|
463
527
|
@internal
|
|
464
528
|
*/
|
|
465
|
-
insertAt(
|
|
466
|
-
let
|
|
467
|
-
return
|
|
529
|
+
insertAt(pos, fragment) {
|
|
530
|
+
let content = insertInto(this.content, pos + this.openStart, fragment);
|
|
531
|
+
return content && new Slice(content, this.openStart, this.openEnd);
|
|
468
532
|
}
|
|
469
533
|
/**
|
|
470
534
|
@internal
|
|
471
535
|
*/
|
|
472
|
-
removeBetween(
|
|
473
|
-
return new
|
|
536
|
+
removeBetween(from, to) {
|
|
537
|
+
return new Slice(removeRange(this.content, from + this.openStart, to + this.openStart), this.openStart, this.openEnd);
|
|
474
538
|
}
|
|
475
539
|
/**
|
|
476
540
|
Tests whether this slice is equal to another slice.
|
|
477
541
|
*/
|
|
478
|
-
eq(
|
|
479
|
-
return this.content.eq(
|
|
542
|
+
eq(other) {
|
|
543
|
+
return this.content.eq(other.content) && this.openStart == other.openStart && this.openEnd == other.openEnd;
|
|
480
544
|
}
|
|
481
545
|
/**
|
|
482
546
|
@internal
|
|
@@ -490,129 +554,174 @@ class d {
|
|
|
490
554
|
toJSON() {
|
|
491
555
|
if (!this.content.size)
|
|
492
556
|
return null;
|
|
493
|
-
let
|
|
494
|
-
|
|
557
|
+
let json = { content: this.content.toJSON() };
|
|
558
|
+
if (this.openStart > 0)
|
|
559
|
+
json.openStart = this.openStart;
|
|
560
|
+
if (this.openEnd > 0)
|
|
561
|
+
json.openEnd = this.openEnd;
|
|
562
|
+
return json;
|
|
495
563
|
}
|
|
496
564
|
/**
|
|
497
565
|
Deserialize a slice from its JSON representation.
|
|
498
566
|
*/
|
|
499
|
-
static fromJSON(
|
|
500
|
-
if (!
|
|
501
|
-
return
|
|
502
|
-
let
|
|
503
|
-
if (typeof
|
|
567
|
+
static fromJSON(schema, json) {
|
|
568
|
+
if (!json)
|
|
569
|
+
return Slice.empty;
|
|
570
|
+
let openStart = json.openStart || 0, openEnd = json.openEnd || 0;
|
|
571
|
+
if (typeof openStart != "number" || typeof openEnd != "number")
|
|
504
572
|
throw new RangeError("Invalid input for Slice.fromJSON");
|
|
505
|
-
return new
|
|
573
|
+
return new Slice(Fragment.fromJSON(schema, json.content), openStart, openEnd);
|
|
506
574
|
}
|
|
507
575
|
/**
|
|
508
576
|
Create a slice from a fragment by taking the maximum possible
|
|
509
577
|
open value on both side of the fragment.
|
|
510
578
|
*/
|
|
511
|
-
static maxOpen(
|
|
512
|
-
let
|
|
513
|
-
for (let
|
|
514
|
-
|
|
515
|
-
for (let
|
|
516
|
-
|
|
517
|
-
return new
|
|
518
|
-
}
|
|
519
|
-
}
|
|
520
|
-
|
|
521
|
-
function
|
|
522
|
-
let { index
|
|
523
|
-
|
|
524
|
-
|
|
579
|
+
static maxOpen(fragment, openIsolating = true) {
|
|
580
|
+
let openStart = 0, openEnd = 0;
|
|
581
|
+
for (let n = fragment.firstChild; n && !n.isLeaf && (openIsolating || !n.type.spec.isolating); n = n.firstChild)
|
|
582
|
+
openStart++;
|
|
583
|
+
for (let n = fragment.lastChild; n && !n.isLeaf && (openIsolating || !n.type.spec.isolating); n = n.lastChild)
|
|
584
|
+
openEnd++;
|
|
585
|
+
return new Slice(fragment, openStart, openEnd);
|
|
586
|
+
}
|
|
587
|
+
}
|
|
588
|
+
Slice.empty = new Slice(Fragment.empty, 0, 0);
|
|
589
|
+
function removeRange(content, from, to) {
|
|
590
|
+
let { index, offset } = content.findIndex(from), child = content.maybeChild(index);
|
|
591
|
+
let { index: indexTo, offset: offsetTo } = content.findIndex(to);
|
|
592
|
+
if (offset == from || child.isText) {
|
|
593
|
+
if (offsetTo != to && !content.child(indexTo).isText)
|
|
525
594
|
throw new RangeError("Removing non-flat range");
|
|
526
|
-
return
|
|
595
|
+
return content.cut(0, from).append(content.cut(to));
|
|
527
596
|
}
|
|
528
|
-
if (
|
|
597
|
+
if (index != indexTo)
|
|
529
598
|
throw new RangeError("Removing non-flat range");
|
|
530
|
-
return
|
|
531
|
-
}
|
|
532
|
-
function
|
|
533
|
-
let { index
|
|
534
|
-
if (
|
|
535
|
-
return
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
599
|
+
return content.replaceChild(index, child.copy(removeRange(child.content, from - offset - 1, to - offset - 1)));
|
|
600
|
+
}
|
|
601
|
+
function insertInto(content, dist, insert, parent) {
|
|
602
|
+
let { index, offset } = content.findIndex(dist), child = content.maybeChild(index);
|
|
603
|
+
if (offset == dist || child.isText) {
|
|
604
|
+
return content.cut(0, dist).append(insert).append(content.cut(dist));
|
|
605
|
+
}
|
|
606
|
+
let inner = insertInto(child.content, dist - offset - 1, insert);
|
|
607
|
+
return inner && content.replaceChild(index, child.copy(inner));
|
|
608
|
+
}
|
|
609
|
+
function replace($from, $to, slice) {
|
|
610
|
+
if (slice.openStart > $from.depth)
|
|
611
|
+
throw new ReplaceError("Inserted content deeper than insertion position");
|
|
612
|
+
if ($from.depth - slice.openStart != $to.depth - slice.openEnd)
|
|
613
|
+
throw new ReplaceError("Inconsistent open depths");
|
|
614
|
+
return replaceOuter($from, $to, slice, 0);
|
|
615
|
+
}
|
|
616
|
+
function replaceOuter($from, $to, slice, depth) {
|
|
617
|
+
let index = $from.index(depth), node = $from.node(depth);
|
|
618
|
+
if (index == $to.index(depth) && depth < $from.depth - slice.openStart) {
|
|
619
|
+
let inner = replaceOuter($from, $to, slice, depth + 1);
|
|
620
|
+
return node.copy(node.content.replaceChild(index, inner));
|
|
621
|
+
} else if (!slice.content.size) {
|
|
622
|
+
return close(node, replaceTwoWay($from, $to, depth));
|
|
623
|
+
} else if (!slice.openStart && !slice.openEnd && $from.depth == depth && $to.depth == depth) {
|
|
624
|
+
let parent = $from.parent, content = parent.content;
|
|
625
|
+
return close(parent, content.cut(0, $from.parentOffset).append(slice.content).append(content.cut($to.parentOffset)));
|
|
626
|
+
} else {
|
|
627
|
+
let { start, end } = prepareSliceForReplace(slice, $from);
|
|
628
|
+
return close(node, replaceThreeWay($from, start, end, $to, depth));
|
|
629
|
+
}
|
|
630
|
+
}
|
|
631
|
+
function checkJoin(main, sub) {
|
|
632
|
+
if (!sub.type.compatibleContent(main.type))
|
|
633
|
+
throw new ReplaceError("Cannot join " + sub.type.name + " onto " + main.type.name);
|
|
634
|
+
}
|
|
635
|
+
function joinable($before, $after, depth) {
|
|
636
|
+
let node = $before.node(depth);
|
|
637
|
+
checkJoin(node, $after.node(depth));
|
|
638
|
+
return node;
|
|
639
|
+
}
|
|
640
|
+
function addNode(child, target) {
|
|
641
|
+
let last = target.length - 1;
|
|
642
|
+
if (last >= 0 && child.isText && child.sameMarkup(target[last]))
|
|
643
|
+
target[last] = child.withText(target[last].text + child.text);
|
|
644
|
+
else
|
|
645
|
+
target.push(child);
|
|
646
|
+
}
|
|
647
|
+
function addRange($start, $end, depth, target) {
|
|
648
|
+
let node = ($end || $start).node(depth);
|
|
649
|
+
let startIndex = 0, endIndex = $end ? $end.index(depth) : node.childCount;
|
|
650
|
+
if ($start) {
|
|
651
|
+
startIndex = $start.index(depth);
|
|
652
|
+
if ($start.depth > depth) {
|
|
653
|
+
startIndex++;
|
|
654
|
+
} else if ($start.textOffset) {
|
|
655
|
+
addNode($start.nodeAfter, target);
|
|
656
|
+
startIndex++;
|
|
558
657
|
}
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
if (
|
|
563
|
-
|
|
564
|
-
}
|
|
565
|
-
function
|
|
566
|
-
|
|
567
|
-
return
|
|
568
|
-
}
|
|
569
|
-
function
|
|
570
|
-
let
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
return
|
|
586
|
-
}
|
|
587
|
-
function
|
|
588
|
-
let
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
658
|
+
}
|
|
659
|
+
for (let i = startIndex; i < endIndex; i++)
|
|
660
|
+
addNode(node.child(i), target);
|
|
661
|
+
if ($end && $end.depth == depth && $end.textOffset)
|
|
662
|
+
addNode($end.nodeBefore, target);
|
|
663
|
+
}
|
|
664
|
+
function close(node, content) {
|
|
665
|
+
node.type.checkContent(content);
|
|
666
|
+
return node.copy(content);
|
|
667
|
+
}
|
|
668
|
+
function replaceThreeWay($from, $start, $end, $to, depth) {
|
|
669
|
+
let openStart = $from.depth > depth && joinable($from, $start, depth + 1);
|
|
670
|
+
let openEnd = $to.depth > depth && joinable($end, $to, depth + 1);
|
|
671
|
+
let content = [];
|
|
672
|
+
addRange(null, $from, depth, content);
|
|
673
|
+
if (openStart && openEnd && $start.index(depth) == $end.index(depth)) {
|
|
674
|
+
checkJoin(openStart, openEnd);
|
|
675
|
+
addNode(close(openStart, replaceThreeWay($from, $start, $end, $to, depth + 1)), content);
|
|
676
|
+
} else {
|
|
677
|
+
if (openStart)
|
|
678
|
+
addNode(close(openStart, replaceTwoWay($from, $start, depth + 1)), content);
|
|
679
|
+
addRange($start, $end, depth, content);
|
|
680
|
+
if (openEnd)
|
|
681
|
+
addNode(close(openEnd, replaceTwoWay($end, $to, depth + 1)), content);
|
|
682
|
+
}
|
|
683
|
+
addRange($to, null, depth, content);
|
|
684
|
+
return new Fragment(content);
|
|
685
|
+
}
|
|
686
|
+
function replaceTwoWay($from, $to, depth) {
|
|
687
|
+
let content = [];
|
|
688
|
+
addRange(null, $from, depth, content);
|
|
689
|
+
if ($from.depth > depth) {
|
|
690
|
+
let type = joinable($from, $to, depth + 1);
|
|
691
|
+
addNode(close(type, replaceTwoWay($from, $to, depth + 1)), content);
|
|
692
|
+
}
|
|
693
|
+
addRange($to, null, depth, content);
|
|
694
|
+
return new Fragment(content);
|
|
695
|
+
}
|
|
696
|
+
function prepareSliceForReplace(slice, $along) {
|
|
697
|
+
let extra = $along.depth - slice.openStart, parent = $along.node(extra);
|
|
698
|
+
let node = parent.copy(slice.content);
|
|
699
|
+
for (let i = extra - 1; i >= 0; i--)
|
|
700
|
+
node = $along.node(i).copy(Fragment.from(node));
|
|
599
701
|
return {
|
|
600
|
-
start:
|
|
601
|
-
end:
|
|
702
|
+
start: node.resolveNoCache(slice.openStart + extra),
|
|
703
|
+
end: node.resolveNoCache(node.content.size - slice.openEnd - extra)
|
|
602
704
|
};
|
|
603
705
|
}
|
|
604
|
-
class
|
|
706
|
+
class ResolvedPos {
|
|
605
707
|
/**
|
|
606
708
|
@internal
|
|
607
709
|
*/
|
|
608
|
-
constructor(
|
|
609
|
-
this.pos =
|
|
710
|
+
constructor(pos, path, parentOffset) {
|
|
711
|
+
this.pos = pos;
|
|
712
|
+
this.path = path;
|
|
713
|
+
this.parentOffset = parentOffset;
|
|
714
|
+
this.depth = path.length / 3 - 1;
|
|
610
715
|
}
|
|
611
716
|
/**
|
|
612
717
|
@internal
|
|
613
718
|
*/
|
|
614
|
-
resolveDepth(
|
|
615
|
-
|
|
719
|
+
resolveDepth(val) {
|
|
720
|
+
if (val == null)
|
|
721
|
+
return this.depth;
|
|
722
|
+
if (val < 0)
|
|
723
|
+
return this.depth + val;
|
|
724
|
+
return val;
|
|
616
725
|
}
|
|
617
726
|
/**
|
|
618
727
|
The parent node that the position points into. Note that even if
|
|
@@ -632,56 +741,61 @@ class S {
|
|
|
632
741
|
The ancestor node at the given level. `p.node(p.depth)` is the
|
|
633
742
|
same as `p.parent`.
|
|
634
743
|
*/
|
|
635
|
-
node(
|
|
636
|
-
return this.path[this.resolveDepth(
|
|
744
|
+
node(depth) {
|
|
745
|
+
return this.path[this.resolveDepth(depth) * 3];
|
|
637
746
|
}
|
|
638
747
|
/**
|
|
639
748
|
The index into the ancestor at the given level. If this points
|
|
640
749
|
at the 3rd node in the 2nd paragraph on the top level, for
|
|
641
750
|
example, `p.index(0)` is 1 and `p.index(1)` is 2.
|
|
642
751
|
*/
|
|
643
|
-
index(
|
|
644
|
-
return this.path[this.resolveDepth(
|
|
752
|
+
index(depth) {
|
|
753
|
+
return this.path[this.resolveDepth(depth) * 3 + 1];
|
|
645
754
|
}
|
|
646
755
|
/**
|
|
647
756
|
The index pointing after this position into the ancestor at the
|
|
648
757
|
given level.
|
|
649
758
|
*/
|
|
650
|
-
indexAfter(
|
|
651
|
-
|
|
759
|
+
indexAfter(depth) {
|
|
760
|
+
depth = this.resolveDepth(depth);
|
|
761
|
+
return this.index(depth) + (depth == this.depth && !this.textOffset ? 0 : 1);
|
|
652
762
|
}
|
|
653
763
|
/**
|
|
654
764
|
The (absolute) position at the start of the node at the given
|
|
655
765
|
level.
|
|
656
766
|
*/
|
|
657
|
-
start(
|
|
658
|
-
|
|
767
|
+
start(depth) {
|
|
768
|
+
depth = this.resolveDepth(depth);
|
|
769
|
+
return depth == 0 ? 0 : this.path[depth * 3 - 1] + 1;
|
|
659
770
|
}
|
|
660
771
|
/**
|
|
661
772
|
The (absolute) position at the end of the node at the given
|
|
662
773
|
level.
|
|
663
774
|
*/
|
|
664
|
-
end(
|
|
665
|
-
|
|
775
|
+
end(depth) {
|
|
776
|
+
depth = this.resolveDepth(depth);
|
|
777
|
+
return this.start(depth) + this.node(depth).content.size;
|
|
666
778
|
}
|
|
667
779
|
/**
|
|
668
780
|
The (absolute) position directly before the wrapping node at the
|
|
669
781
|
given level, or, when `depth` is `this.depth + 1`, the original
|
|
670
782
|
position.
|
|
671
783
|
*/
|
|
672
|
-
before(
|
|
673
|
-
|
|
784
|
+
before(depth) {
|
|
785
|
+
depth = this.resolveDepth(depth);
|
|
786
|
+
if (!depth)
|
|
674
787
|
throw new RangeError("There is no position before the top-level node");
|
|
675
|
-
return
|
|
788
|
+
return depth == this.depth + 1 ? this.pos : this.path[depth * 3 - 1];
|
|
676
789
|
}
|
|
677
790
|
/**
|
|
678
791
|
The (absolute) position directly after the wrapping node at the
|
|
679
792
|
given level, or the original position when `depth` is `this.depth + 1`.
|
|
680
793
|
*/
|
|
681
|
-
after(
|
|
682
|
-
|
|
794
|
+
after(depth) {
|
|
795
|
+
depth = this.resolveDepth(depth);
|
|
796
|
+
if (!depth)
|
|
683
797
|
throw new RangeError("There is no position after the top-level node");
|
|
684
|
-
return
|
|
798
|
+
return depth == this.depth + 1 ? this.pos : this.path[depth * 3 - 1] + this.path[depth * 3].nodeSize;
|
|
685
799
|
}
|
|
686
800
|
/**
|
|
687
801
|
When this position points into a text node, this returns the
|
|
@@ -697,11 +811,11 @@ class S {
|
|
|
697
811
|
position is returned.
|
|
698
812
|
*/
|
|
699
813
|
get nodeAfter() {
|
|
700
|
-
let
|
|
701
|
-
if (
|
|
814
|
+
let parent = this.parent, index = this.index(this.depth);
|
|
815
|
+
if (index == parent.childCount)
|
|
702
816
|
return null;
|
|
703
|
-
let
|
|
704
|
-
return
|
|
817
|
+
let dOff = this.pos - this.path[this.path.length - 1], child = parent.child(index);
|
|
818
|
+
return dOff ? parent.child(index).cut(dOff) : child;
|
|
705
819
|
}
|
|
706
820
|
/**
|
|
707
821
|
Get the node directly before the position, if any. If the
|
|
@@ -709,19 +823,22 @@ class S {
|
|
|
709
823
|
before the position is returned.
|
|
710
824
|
*/
|
|
711
825
|
get nodeBefore() {
|
|
712
|
-
let
|
|
713
|
-
|
|
826
|
+
let index = this.index(this.depth);
|
|
827
|
+
let dOff = this.pos - this.path[this.path.length - 1];
|
|
828
|
+
if (dOff)
|
|
829
|
+
return this.parent.child(index).cut(0, dOff);
|
|
830
|
+
return index == 0 ? null : this.parent.child(index - 1);
|
|
714
831
|
}
|
|
715
832
|
/**
|
|
716
833
|
Get the position at the given index in the parent node at the
|
|
717
834
|
given depth (which defaults to `this.depth`).
|
|
718
835
|
*/
|
|
719
|
-
posAtIndex(
|
|
720
|
-
|
|
721
|
-
let
|
|
722
|
-
for (let
|
|
723
|
-
|
|
724
|
-
return
|
|
836
|
+
posAtIndex(index, depth) {
|
|
837
|
+
depth = this.resolveDepth(depth);
|
|
838
|
+
let node = this.path[depth * 3], pos = depth == 0 ? 0 : this.path[depth * 3 - 1] + 1;
|
|
839
|
+
for (let i = 0; i < index; i++)
|
|
840
|
+
pos += node.child(i).nodeSize;
|
|
841
|
+
return pos;
|
|
725
842
|
}
|
|
726
843
|
/**
|
|
727
844
|
Get the marks at this position, factoring in the surrounding
|
|
@@ -730,20 +847,22 @@ class S {
|
|
|
730
847
|
node after it (if any) are returned.
|
|
731
848
|
*/
|
|
732
849
|
marks() {
|
|
733
|
-
let
|
|
734
|
-
if (
|
|
735
|
-
return
|
|
850
|
+
let parent = this.parent, index = this.index();
|
|
851
|
+
if (parent.content.size == 0)
|
|
852
|
+
return Mark.none;
|
|
736
853
|
if (this.textOffset)
|
|
737
|
-
return
|
|
738
|
-
let
|
|
739
|
-
if (!
|
|
740
|
-
let
|
|
741
|
-
|
|
854
|
+
return parent.child(index).marks;
|
|
855
|
+
let main = parent.maybeChild(index - 1), other = parent.maybeChild(index);
|
|
856
|
+
if (!main) {
|
|
857
|
+
let tmp = main;
|
|
858
|
+
main = other;
|
|
859
|
+
other = tmp;
|
|
742
860
|
}
|
|
743
|
-
let
|
|
744
|
-
for (var
|
|
745
|
-
|
|
746
|
-
|
|
861
|
+
let marks = main.marks;
|
|
862
|
+
for (var i = 0; i < marks.length; i++)
|
|
863
|
+
if (marks[i].type.spec.inclusive === false && (!other || !marks[i].isInSet(other.marks)))
|
|
864
|
+
marks = marks[i--].removeFromSet(marks);
|
|
865
|
+
return marks;
|
|
747
866
|
}
|
|
748
867
|
/**
|
|
749
868
|
Get the marks after the current position, if any, except those
|
|
@@ -753,23 +872,24 @@ class S {
|
|
|
753
872
|
its parent node or its parent node isn't a textblock (in which
|
|
754
873
|
case no marks should be preserved).
|
|
755
874
|
*/
|
|
756
|
-
marksAcross(
|
|
757
|
-
let
|
|
758
|
-
if (!
|
|
875
|
+
marksAcross($end) {
|
|
876
|
+
let after = this.parent.maybeChild(this.index());
|
|
877
|
+
if (!after || !after.isInline)
|
|
759
878
|
return null;
|
|
760
|
-
let
|
|
761
|
-
for (var
|
|
762
|
-
|
|
763
|
-
|
|
879
|
+
let marks = after.marks, next = $end.parent.maybeChild($end.index());
|
|
880
|
+
for (var i = 0; i < marks.length; i++)
|
|
881
|
+
if (marks[i].type.spec.inclusive === false && (!next || !marks[i].isInSet(next.marks)))
|
|
882
|
+
marks = marks[i--].removeFromSet(marks);
|
|
883
|
+
return marks;
|
|
764
884
|
}
|
|
765
885
|
/**
|
|
766
886
|
The depth up to which this position and the given (non-resolved)
|
|
767
887
|
position share the same parent nodes.
|
|
768
888
|
*/
|
|
769
|
-
sharedDepth(
|
|
770
|
-
for (let
|
|
771
|
-
if (this.start(
|
|
772
|
-
return
|
|
889
|
+
sharedDepth(pos) {
|
|
890
|
+
for (let depth = this.depth; depth > 0; depth--)
|
|
891
|
+
if (this.start(depth) <= pos && this.end(depth) >= pos)
|
|
892
|
+
return depth;
|
|
773
893
|
return 0;
|
|
774
894
|
}
|
|
775
895
|
/**
|
|
@@ -781,87 +901,99 @@ class S {
|
|
|
781
901
|
pass in an optional predicate that will be called with a parent
|
|
782
902
|
node to see if a range into that parent is acceptable.
|
|
783
903
|
*/
|
|
784
|
-
blockRange(
|
|
785
|
-
if (
|
|
786
|
-
return
|
|
787
|
-
for (let
|
|
788
|
-
if (
|
|
789
|
-
return new
|
|
904
|
+
blockRange(other = this, pred) {
|
|
905
|
+
if (other.pos < this.pos)
|
|
906
|
+
return other.blockRange(this);
|
|
907
|
+
for (let d = this.depth - (this.parent.inlineContent || this.pos == other.pos ? 1 : 0); d >= 0; d--)
|
|
908
|
+
if (other.pos <= this.end(d) && (!pred || pred(this.node(d))))
|
|
909
|
+
return new NodeRange(this, other, d);
|
|
790
910
|
return null;
|
|
791
911
|
}
|
|
792
912
|
/**
|
|
793
913
|
Query whether the given position shares the same parent node.
|
|
794
914
|
*/
|
|
795
|
-
sameParent(
|
|
796
|
-
return this.pos - this.parentOffset ==
|
|
915
|
+
sameParent(other) {
|
|
916
|
+
return this.pos - this.parentOffset == other.pos - other.parentOffset;
|
|
797
917
|
}
|
|
798
918
|
/**
|
|
799
919
|
Return the greater of this and the given position.
|
|
800
920
|
*/
|
|
801
|
-
max(
|
|
802
|
-
return
|
|
921
|
+
max(other) {
|
|
922
|
+
return other.pos > this.pos ? other : this;
|
|
803
923
|
}
|
|
804
924
|
/**
|
|
805
925
|
Return the smaller of this and the given position.
|
|
806
926
|
*/
|
|
807
|
-
min(
|
|
808
|
-
return
|
|
927
|
+
min(other) {
|
|
928
|
+
return other.pos < this.pos ? other : this;
|
|
809
929
|
}
|
|
810
930
|
/**
|
|
811
931
|
@internal
|
|
812
932
|
*/
|
|
813
933
|
toString() {
|
|
814
|
-
let
|
|
815
|
-
for (let
|
|
816
|
-
|
|
817
|
-
return
|
|
934
|
+
let str = "";
|
|
935
|
+
for (let i = 1; i <= this.depth; i++)
|
|
936
|
+
str += (str ? "/" : "") + this.node(i).type.name + "_" + this.index(i - 1);
|
|
937
|
+
return str + ":" + this.parentOffset;
|
|
818
938
|
}
|
|
819
939
|
/**
|
|
820
940
|
@internal
|
|
821
941
|
*/
|
|
822
|
-
static resolve(
|
|
823
|
-
if (!(
|
|
824
|
-
throw new RangeError("Position " +
|
|
825
|
-
let
|
|
826
|
-
|
|
827
|
-
|
|
828
|
-
|
|
942
|
+
static resolve(doc2, pos) {
|
|
943
|
+
if (!(pos >= 0 && pos <= doc2.content.size))
|
|
944
|
+
throw new RangeError("Position " + pos + " out of range");
|
|
945
|
+
let path = [];
|
|
946
|
+
let start = 0, parentOffset = pos;
|
|
947
|
+
for (let node = doc2; ; ) {
|
|
948
|
+
let { index, offset } = node.content.findIndex(parentOffset);
|
|
949
|
+
let rem = parentOffset - offset;
|
|
950
|
+
path.push(node, index, start + offset);
|
|
951
|
+
if (!rem)
|
|
829
952
|
break;
|
|
830
|
-
|
|
953
|
+
node = node.child(index);
|
|
954
|
+
if (node.isText)
|
|
955
|
+
break;
|
|
956
|
+
parentOffset = rem - 1;
|
|
957
|
+
start += offset + 1;
|
|
831
958
|
}
|
|
832
|
-
return new
|
|
959
|
+
return new ResolvedPos(pos, path, parentOffset);
|
|
833
960
|
}
|
|
834
961
|
/**
|
|
835
962
|
@internal
|
|
836
963
|
*/
|
|
837
|
-
static resolveCached(
|
|
838
|
-
let
|
|
839
|
-
if (
|
|
840
|
-
for (let
|
|
841
|
-
let
|
|
842
|
-
if (
|
|
843
|
-
return
|
|
964
|
+
static resolveCached(doc2, pos) {
|
|
965
|
+
let cache = resolveCache.get(doc2);
|
|
966
|
+
if (cache) {
|
|
967
|
+
for (let i = 0; i < cache.elts.length; i++) {
|
|
968
|
+
let elt = cache.elts[i];
|
|
969
|
+
if (elt.pos == pos)
|
|
970
|
+
return elt;
|
|
844
971
|
}
|
|
845
|
-
else
|
|
846
|
-
|
|
847
|
-
|
|
848
|
-
|
|
972
|
+
} else {
|
|
973
|
+
resolveCache.set(doc2, cache = new ResolveCache());
|
|
974
|
+
}
|
|
975
|
+
let result = cache.elts[cache.i] = ResolvedPos.resolve(doc2, pos);
|
|
976
|
+
cache.i = (cache.i + 1) % resolveCacheSize;
|
|
977
|
+
return result;
|
|
849
978
|
}
|
|
850
979
|
}
|
|
851
|
-
class
|
|
980
|
+
class ResolveCache {
|
|
852
981
|
constructor() {
|
|
853
|
-
this.elts = []
|
|
982
|
+
this.elts = [];
|
|
983
|
+
this.i = 0;
|
|
854
984
|
}
|
|
855
985
|
}
|
|
856
|
-
const
|
|
857
|
-
class
|
|
986
|
+
const resolveCacheSize = 12, resolveCache = /* @__PURE__ */ new WeakMap();
|
|
987
|
+
class NodeRange {
|
|
858
988
|
/**
|
|
859
989
|
Construct a node range. `$from` and `$to` should point into the
|
|
860
990
|
same node until at least the given `depth`, since a node range
|
|
861
991
|
denotes an adjacent set of nodes in a single parent node.
|
|
862
992
|
*/
|
|
863
|
-
constructor(
|
|
864
|
-
this.$from =
|
|
993
|
+
constructor($from, $to, depth) {
|
|
994
|
+
this.$from = $from;
|
|
995
|
+
this.$to = $to;
|
|
996
|
+
this.depth = depth;
|
|
865
997
|
}
|
|
866
998
|
/**
|
|
867
999
|
The position at the start of the range.
|
|
@@ -894,13 +1026,16 @@ class mt {
|
|
|
894
1026
|
return this.$to.indexAfter(this.depth);
|
|
895
1027
|
}
|
|
896
1028
|
}
|
|
897
|
-
const
|
|
898
|
-
class
|
|
1029
|
+
const emptyAttrs = /* @__PURE__ */ Object.create(null);
|
|
1030
|
+
class Node {
|
|
899
1031
|
/**
|
|
900
1032
|
@internal
|
|
901
1033
|
*/
|
|
902
|
-
constructor(
|
|
903
|
-
this.type =
|
|
1034
|
+
constructor(type, attrs, content, marks = Mark.none) {
|
|
1035
|
+
this.type = type;
|
|
1036
|
+
this.attrs = attrs;
|
|
1037
|
+
this.marks = marks;
|
|
1038
|
+
this.content = content || Fragment.empty;
|
|
904
1039
|
}
|
|
905
1040
|
/**
|
|
906
1041
|
The array of this node's child nodes.
|
|
@@ -928,21 +1063,21 @@ class y {
|
|
|
928
1063
|
Get the child node at the given index. Raises an error when the
|
|
929
1064
|
index is out of range.
|
|
930
1065
|
*/
|
|
931
|
-
child(
|
|
932
|
-
return this.content.child(
|
|
1066
|
+
child(index) {
|
|
1067
|
+
return this.content.child(index);
|
|
933
1068
|
}
|
|
934
1069
|
/**
|
|
935
1070
|
Get the child node at the given index, if it exists.
|
|
936
1071
|
*/
|
|
937
|
-
maybeChild(
|
|
938
|
-
return this.content.maybeChild(
|
|
1072
|
+
maybeChild(index) {
|
|
1073
|
+
return this.content.maybeChild(index);
|
|
939
1074
|
}
|
|
940
1075
|
/**
|
|
941
1076
|
Call `f` for every child node, passing the node, its offset
|
|
942
1077
|
into this parent node, and its index.
|
|
943
1078
|
*/
|
|
944
|
-
forEach(
|
|
945
|
-
this.content.forEach(
|
|
1079
|
+
forEach(f) {
|
|
1080
|
+
this.content.forEach(f);
|
|
946
1081
|
}
|
|
947
1082
|
/**
|
|
948
1083
|
Invoke a callback for all descendant nodes recursively between
|
|
@@ -954,15 +1089,15 @@ class y {
|
|
|
954
1089
|
recursed over. The last parameter can be used to specify a
|
|
955
1090
|
starting position to count from.
|
|
956
1091
|
*/
|
|
957
|
-
nodesBetween(
|
|
958
|
-
this.content.nodesBetween(
|
|
1092
|
+
nodesBetween(from, to, f, startPos = 0) {
|
|
1093
|
+
this.content.nodesBetween(from, to, f, startPos, this);
|
|
959
1094
|
}
|
|
960
1095
|
/**
|
|
961
1096
|
Call the given callback for every descendant node. Doesn't
|
|
962
1097
|
descend into a node when the callback returns `false`.
|
|
963
1098
|
*/
|
|
964
|
-
descendants(
|
|
965
|
-
this.nodesBetween(0, this.content.size,
|
|
1099
|
+
descendants(f) {
|
|
1100
|
+
this.nodesBetween(0, this.content.size, f);
|
|
966
1101
|
}
|
|
967
1102
|
/**
|
|
968
1103
|
Concatenates all the text nodes found in this fragment and its
|
|
@@ -978,8 +1113,8 @@ class y {
|
|
|
978
1113
|
inserted for every non-text leaf node encountered, otherwise
|
|
979
1114
|
[`leafText`](https://prosemirror.net/docs/ref/#model.NodeSpec^leafText) will be used.
|
|
980
1115
|
*/
|
|
981
|
-
textBetween(
|
|
982
|
-
return this.content.textBetween(
|
|
1116
|
+
textBetween(from, to, blockSeparator, leafText) {
|
|
1117
|
+
return this.content.textBetween(from, to, blockSeparator, leafText);
|
|
983
1118
|
}
|
|
984
1119
|
/**
|
|
985
1120
|
Returns this node's first child, or `null` if there are no
|
|
@@ -998,54 +1133,61 @@ class y {
|
|
|
998
1133
|
/**
|
|
999
1134
|
Test whether two nodes represent the same piece of document.
|
|
1000
1135
|
*/
|
|
1001
|
-
eq(
|
|
1002
|
-
return this ==
|
|
1136
|
+
eq(other) {
|
|
1137
|
+
return this == other || this.sameMarkup(other) && this.content.eq(other.content);
|
|
1003
1138
|
}
|
|
1004
1139
|
/**
|
|
1005
1140
|
Compare the markup (type, attributes, and marks) of this node to
|
|
1006
1141
|
those of another. Returns `true` if both have the same markup.
|
|
1007
1142
|
*/
|
|
1008
|
-
sameMarkup(
|
|
1009
|
-
return this.hasMarkup(
|
|
1143
|
+
sameMarkup(other) {
|
|
1144
|
+
return this.hasMarkup(other.type, other.attrs, other.marks);
|
|
1010
1145
|
}
|
|
1011
1146
|
/**
|
|
1012
1147
|
Check whether this node's markup correspond to the given type,
|
|
1013
1148
|
attributes, and marks.
|
|
1014
1149
|
*/
|
|
1015
|
-
hasMarkup(
|
|
1016
|
-
return this.type ==
|
|
1150
|
+
hasMarkup(type, attrs, marks) {
|
|
1151
|
+
return this.type == type && compareDeep(this.attrs, attrs || type.defaultAttrs || emptyAttrs) && Mark.sameSet(this.marks, marks || Mark.none);
|
|
1017
1152
|
}
|
|
1018
1153
|
/**
|
|
1019
1154
|
Create a new node with the same markup as this node, containing
|
|
1020
1155
|
the given content (or empty, if no content is given).
|
|
1021
1156
|
*/
|
|
1022
|
-
copy(
|
|
1023
|
-
|
|
1157
|
+
copy(content = null) {
|
|
1158
|
+
if (content == this.content)
|
|
1159
|
+
return this;
|
|
1160
|
+
return new Node(this.type, this.attrs, content, this.marks);
|
|
1024
1161
|
}
|
|
1025
1162
|
/**
|
|
1026
1163
|
Create a copy of this node, with the given set of marks instead
|
|
1027
1164
|
of the node's own marks.
|
|
1028
1165
|
*/
|
|
1029
|
-
mark(
|
|
1030
|
-
return
|
|
1166
|
+
mark(marks) {
|
|
1167
|
+
return marks == this.marks ? this : new Node(this.type, this.attrs, this.content, marks);
|
|
1031
1168
|
}
|
|
1032
1169
|
/**
|
|
1033
1170
|
Create a copy of this node with only the content between the
|
|
1034
1171
|
given positions. If `to` is not given, it defaults to the end of
|
|
1035
1172
|
the node.
|
|
1036
1173
|
*/
|
|
1037
|
-
cut(
|
|
1038
|
-
|
|
1174
|
+
cut(from, to = this.content.size) {
|
|
1175
|
+
if (from == 0 && to == this.content.size)
|
|
1176
|
+
return this;
|
|
1177
|
+
return this.copy(this.content.cut(from, to));
|
|
1039
1178
|
}
|
|
1040
1179
|
/**
|
|
1041
1180
|
Cut out the part of the document between the given positions, and
|
|
1042
1181
|
return it as a `Slice` object.
|
|
1043
1182
|
*/
|
|
1044
|
-
slice(
|
|
1045
|
-
if (
|
|
1046
|
-
return
|
|
1047
|
-
let
|
|
1048
|
-
|
|
1183
|
+
slice(from, to = this.content.size, includeParents = false) {
|
|
1184
|
+
if (from == to)
|
|
1185
|
+
return Slice.empty;
|
|
1186
|
+
let $from = this.resolve(from), $to = this.resolve(to);
|
|
1187
|
+
let depth = includeParents ? 0 : $from.sharedDepth(to);
|
|
1188
|
+
let start = $from.start(depth), node = $from.node(depth);
|
|
1189
|
+
let content = node.content.cut($from.pos - start, $to.pos - start);
|
|
1190
|
+
return new Slice(content, $from.depth - depth, $to.depth - depth);
|
|
1049
1191
|
}
|
|
1050
1192
|
/**
|
|
1051
1193
|
Replace the part of the document between the given positions with
|
|
@@ -1055,20 +1197,21 @@ class y {
|
|
|
1055
1197
|
into. If any of this is violated, an error of type
|
|
1056
1198
|
[`ReplaceError`](https://prosemirror.net/docs/ref/#model.ReplaceError) is thrown.
|
|
1057
1199
|
*/
|
|
1058
|
-
replace(
|
|
1059
|
-
return
|
|
1200
|
+
replace(from, to, slice) {
|
|
1201
|
+
return replace(this.resolve(from), this.resolve(to), slice);
|
|
1060
1202
|
}
|
|
1061
1203
|
/**
|
|
1062
1204
|
Find the node directly after the given position.
|
|
1063
1205
|
*/
|
|
1064
|
-
nodeAt(
|
|
1065
|
-
for (let
|
|
1066
|
-
let { index
|
|
1067
|
-
|
|
1206
|
+
nodeAt(pos) {
|
|
1207
|
+
for (let node = this; ; ) {
|
|
1208
|
+
let { index, offset } = node.content.findIndex(pos);
|
|
1209
|
+
node = node.maybeChild(index);
|
|
1210
|
+
if (!node)
|
|
1068
1211
|
return null;
|
|
1069
|
-
if (
|
|
1070
|
-
return
|
|
1071
|
-
|
|
1212
|
+
if (offset == pos || node.isText)
|
|
1213
|
+
return node;
|
|
1214
|
+
pos -= offset + 1;
|
|
1072
1215
|
}
|
|
1073
1216
|
}
|
|
1074
1217
|
/**
|
|
@@ -1076,44 +1219,50 @@ class y {
|
|
|
1076
1219
|
and return it along with its index and offset relative to this
|
|
1077
1220
|
node.
|
|
1078
1221
|
*/
|
|
1079
|
-
childAfter(
|
|
1080
|
-
let { index
|
|
1081
|
-
return { node: this.content.maybeChild(
|
|
1222
|
+
childAfter(pos) {
|
|
1223
|
+
let { index, offset } = this.content.findIndex(pos);
|
|
1224
|
+
return { node: this.content.maybeChild(index), index, offset };
|
|
1082
1225
|
}
|
|
1083
1226
|
/**
|
|
1084
1227
|
Find the (direct) child node before the given offset, if any,
|
|
1085
1228
|
and return it along with its index and offset relative to this
|
|
1086
1229
|
node.
|
|
1087
1230
|
*/
|
|
1088
|
-
childBefore(
|
|
1089
|
-
if (
|
|
1231
|
+
childBefore(pos) {
|
|
1232
|
+
if (pos == 0)
|
|
1090
1233
|
return { node: null, index: 0, offset: 0 };
|
|
1091
|
-
let { index
|
|
1092
|
-
if (
|
|
1093
|
-
return { node: this.content.child(
|
|
1094
|
-
let
|
|
1095
|
-
return { node
|
|
1234
|
+
let { index, offset } = this.content.findIndex(pos);
|
|
1235
|
+
if (offset < pos)
|
|
1236
|
+
return { node: this.content.child(index), index, offset };
|
|
1237
|
+
let node = this.content.child(index - 1);
|
|
1238
|
+
return { node, index: index - 1, offset: offset - node.nodeSize };
|
|
1096
1239
|
}
|
|
1097
1240
|
/**
|
|
1098
1241
|
Resolve the given position in the document, returning an
|
|
1099
1242
|
[object](https://prosemirror.net/docs/ref/#model.ResolvedPos) with information about its context.
|
|
1100
1243
|
*/
|
|
1101
|
-
resolve(
|
|
1102
|
-
return
|
|
1244
|
+
resolve(pos) {
|
|
1245
|
+
return ResolvedPos.resolveCached(this, pos);
|
|
1103
1246
|
}
|
|
1104
1247
|
/**
|
|
1105
1248
|
@internal
|
|
1106
1249
|
*/
|
|
1107
|
-
resolveNoCache(
|
|
1108
|
-
return
|
|
1250
|
+
resolveNoCache(pos) {
|
|
1251
|
+
return ResolvedPos.resolve(this, pos);
|
|
1109
1252
|
}
|
|
1110
1253
|
/**
|
|
1111
1254
|
Test whether a given mark or mark type occurs in this document
|
|
1112
1255
|
between the two given positions.
|
|
1113
1256
|
*/
|
|
1114
|
-
rangeHasMark(
|
|
1115
|
-
let
|
|
1116
|
-
|
|
1257
|
+
rangeHasMark(from, to, type) {
|
|
1258
|
+
let found2 = false;
|
|
1259
|
+
if (to > from)
|
|
1260
|
+
this.nodesBetween(from, to, (node) => {
|
|
1261
|
+
if (type.isInSet(node.marks))
|
|
1262
|
+
found2 = true;
|
|
1263
|
+
return !found2;
|
|
1264
|
+
});
|
|
1265
|
+
return found2;
|
|
1117
1266
|
}
|
|
1118
1267
|
/**
|
|
1119
1268
|
True when this is a block (non-inline node)
|
|
@@ -1170,17 +1319,19 @@ class y {
|
|
|
1170
1319
|
toString() {
|
|
1171
1320
|
if (this.type.spec.toDebugString)
|
|
1172
1321
|
return this.type.spec.toDebugString(this);
|
|
1173
|
-
let
|
|
1174
|
-
|
|
1322
|
+
let name = this.type.name;
|
|
1323
|
+
if (this.content.size)
|
|
1324
|
+
name += "(" + this.content.toStringInner() + ")";
|
|
1325
|
+
return wrapMarks(this.marks, name);
|
|
1175
1326
|
}
|
|
1176
1327
|
/**
|
|
1177
1328
|
Get the content match in this node at the given index.
|
|
1178
1329
|
*/
|
|
1179
|
-
contentMatchAt(
|
|
1180
|
-
let
|
|
1181
|
-
if (!
|
|
1330
|
+
contentMatchAt(index) {
|
|
1331
|
+
let match = this.type.contentMatch.matchFragment(this.content, 0, index);
|
|
1332
|
+
if (!match)
|
|
1182
1333
|
throw new Error("Called contentMatchAt on a node with invalid content");
|
|
1183
|
-
return
|
|
1334
|
+
return match;
|
|
1184
1335
|
}
|
|
1185
1336
|
/**
|
|
1186
1337
|
Test whether replacing the range between `from` and `to` (by
|
|
@@ -1189,24 +1340,26 @@ class y {
|
|
|
1189
1340
|
can optionally pass `start` and `end` indices into the
|
|
1190
1341
|
replacement fragment.
|
|
1191
1342
|
*/
|
|
1192
|
-
canReplace(
|
|
1193
|
-
let
|
|
1194
|
-
|
|
1195
|
-
|
|
1196
|
-
|
|
1197
|
-
|
|
1198
|
-
|
|
1199
|
-
|
|
1343
|
+
canReplace(from, to, replacement = Fragment.empty, start = 0, end = replacement.childCount) {
|
|
1344
|
+
let one = this.contentMatchAt(from).matchFragment(replacement, start, end);
|
|
1345
|
+
let two = one && one.matchFragment(this.content, to);
|
|
1346
|
+
if (!two || !two.validEnd)
|
|
1347
|
+
return false;
|
|
1348
|
+
for (let i = start; i < end; i++)
|
|
1349
|
+
if (!this.type.allowsMarks(replacement.child(i).marks))
|
|
1350
|
+
return false;
|
|
1351
|
+
return true;
|
|
1200
1352
|
}
|
|
1201
1353
|
/**
|
|
1202
1354
|
Test whether replacing the range `from` to `to` (by index) with
|
|
1203
1355
|
a node of the given type would leave the node's content valid.
|
|
1204
1356
|
*/
|
|
1205
|
-
canReplaceWith(
|
|
1206
|
-
if (
|
|
1207
|
-
return
|
|
1208
|
-
let
|
|
1209
|
-
|
|
1357
|
+
canReplaceWith(from, to, type, marks) {
|
|
1358
|
+
if (marks && !this.type.allowsMarks(marks))
|
|
1359
|
+
return false;
|
|
1360
|
+
let start = this.contentMatchAt(from).matchType(type);
|
|
1361
|
+
let end = start && start.matchFragment(this.content, to);
|
|
1362
|
+
return end ? end.validEnd : false;
|
|
1210
1363
|
}
|
|
1211
1364
|
/**
|
|
1212
1365
|
Test whether the given node's content could be appended to this
|
|
@@ -1214,138 +1367,161 @@ class y {
|
|
|
1214
1367
|
is at least one node type that can appear in both nodes (to avoid
|
|
1215
1368
|
merging completely incompatible nodes).
|
|
1216
1369
|
*/
|
|
1217
|
-
canAppend(
|
|
1218
|
-
|
|
1370
|
+
canAppend(other) {
|
|
1371
|
+
if (other.content.size)
|
|
1372
|
+
return this.canReplace(this.childCount, this.childCount, other.content);
|
|
1373
|
+
else
|
|
1374
|
+
return this.type.compatibleContent(other.type);
|
|
1219
1375
|
}
|
|
1220
1376
|
/**
|
|
1221
1377
|
Check whether this node and its descendants conform to the
|
|
1222
1378
|
schema, and raise an exception when they do not.
|
|
1223
1379
|
*/
|
|
1224
1380
|
check() {
|
|
1225
|
-
this.type.checkContent(this.content)
|
|
1226
|
-
|
|
1227
|
-
|
|
1228
|
-
|
|
1229
|
-
|
|
1381
|
+
this.type.checkContent(this.content);
|
|
1382
|
+
this.type.checkAttrs(this.attrs);
|
|
1383
|
+
let copy2 = Mark.none;
|
|
1384
|
+
for (let i = 0; i < this.marks.length; i++) {
|
|
1385
|
+
let mark = this.marks[i];
|
|
1386
|
+
mark.type.checkAttrs(mark.attrs);
|
|
1387
|
+
copy2 = mark.addToSet(copy2);
|
|
1230
1388
|
}
|
|
1231
|
-
if (!
|
|
1232
|
-
throw new RangeError(`Invalid collection of marks for node ${this.type.name}: ${this.marks.map((
|
|
1233
|
-
this.content.forEach((
|
|
1389
|
+
if (!Mark.sameSet(copy2, this.marks))
|
|
1390
|
+
throw new RangeError(`Invalid collection of marks for node ${this.type.name}: ${this.marks.map((m) => m.type.name)}`);
|
|
1391
|
+
this.content.forEach((node) => node.check());
|
|
1234
1392
|
}
|
|
1235
1393
|
/**
|
|
1236
1394
|
Return a JSON-serializeable representation of this node.
|
|
1237
1395
|
*/
|
|
1238
1396
|
toJSON() {
|
|
1239
|
-
let
|
|
1240
|
-
for (let
|
|
1241
|
-
|
|
1397
|
+
let obj = { type: this.type.name };
|
|
1398
|
+
for (let _ in this.attrs) {
|
|
1399
|
+
obj.attrs = this.attrs;
|
|
1242
1400
|
break;
|
|
1243
1401
|
}
|
|
1244
|
-
|
|
1402
|
+
if (this.content.size)
|
|
1403
|
+
obj.content = this.content.toJSON();
|
|
1404
|
+
if (this.marks.length)
|
|
1405
|
+
obj.marks = this.marks.map((n) => n.toJSON());
|
|
1406
|
+
return obj;
|
|
1245
1407
|
}
|
|
1246
1408
|
/**
|
|
1247
1409
|
Deserialize a node from its JSON representation.
|
|
1248
1410
|
*/
|
|
1249
|
-
static fromJSON(
|
|
1250
|
-
if (!
|
|
1411
|
+
static fromJSON(schema, json) {
|
|
1412
|
+
if (!json)
|
|
1251
1413
|
throw new RangeError("Invalid input for Node.fromJSON");
|
|
1252
|
-
let
|
|
1253
|
-
if (
|
|
1254
|
-
if (!Array.isArray(
|
|
1414
|
+
let marks = void 0;
|
|
1415
|
+
if (json.marks) {
|
|
1416
|
+
if (!Array.isArray(json.marks))
|
|
1255
1417
|
throw new RangeError("Invalid mark data for Node.fromJSON");
|
|
1256
|
-
|
|
1418
|
+
marks = json.marks.map(schema.markFromJSON);
|
|
1257
1419
|
}
|
|
1258
|
-
if (
|
|
1259
|
-
if (typeof
|
|
1420
|
+
if (json.type == "text") {
|
|
1421
|
+
if (typeof json.text != "string")
|
|
1260
1422
|
throw new RangeError("Invalid text node in JSON");
|
|
1261
|
-
return
|
|
1423
|
+
return schema.text(json.text, marks);
|
|
1262
1424
|
}
|
|
1263
|
-
let
|
|
1264
|
-
|
|
1425
|
+
let content = Fragment.fromJSON(schema, json.content);
|
|
1426
|
+
let node = schema.nodeType(json.type).create(json.attrs, content, marks);
|
|
1427
|
+
node.type.checkAttrs(node.attrs);
|
|
1428
|
+
return node;
|
|
1265
1429
|
}
|
|
1266
1430
|
}
|
|
1267
|
-
|
|
1268
|
-
class
|
|
1431
|
+
Node.prototype.text = void 0;
|
|
1432
|
+
class TextNode extends Node {
|
|
1269
1433
|
/**
|
|
1270
1434
|
@internal
|
|
1271
1435
|
*/
|
|
1272
|
-
constructor(
|
|
1273
|
-
|
|
1436
|
+
constructor(type, attrs, content, marks) {
|
|
1437
|
+
super(type, attrs, null, marks);
|
|
1438
|
+
if (!content)
|
|
1274
1439
|
throw new RangeError("Empty text nodes are not allowed");
|
|
1275
|
-
this.text =
|
|
1440
|
+
this.text = content;
|
|
1276
1441
|
}
|
|
1277
1442
|
toString() {
|
|
1278
|
-
|
|
1443
|
+
if (this.type.spec.toDebugString)
|
|
1444
|
+
return this.type.spec.toDebugString(this);
|
|
1445
|
+
return wrapMarks(this.marks, JSON.stringify(this.text));
|
|
1279
1446
|
}
|
|
1280
1447
|
get textContent() {
|
|
1281
1448
|
return this.text;
|
|
1282
1449
|
}
|
|
1283
|
-
textBetween(
|
|
1284
|
-
return this.text.slice(
|
|
1450
|
+
textBetween(from, to) {
|
|
1451
|
+
return this.text.slice(from, to);
|
|
1285
1452
|
}
|
|
1286
1453
|
get nodeSize() {
|
|
1287
1454
|
return this.text.length;
|
|
1288
1455
|
}
|
|
1289
|
-
mark(
|
|
1290
|
-
return
|
|
1456
|
+
mark(marks) {
|
|
1457
|
+
return marks == this.marks ? this : new TextNode(this.type, this.attrs, this.text, marks);
|
|
1291
1458
|
}
|
|
1292
|
-
withText(
|
|
1293
|
-
|
|
1459
|
+
withText(text) {
|
|
1460
|
+
if (text == this.text)
|
|
1461
|
+
return this;
|
|
1462
|
+
return new TextNode(this.type, this.attrs, text, this.marks);
|
|
1294
1463
|
}
|
|
1295
|
-
cut(
|
|
1296
|
-
|
|
1464
|
+
cut(from = 0, to = this.text.length) {
|
|
1465
|
+
if (from == 0 && to == this.text.length)
|
|
1466
|
+
return this;
|
|
1467
|
+
return this.withText(this.text.slice(from, to));
|
|
1297
1468
|
}
|
|
1298
|
-
eq(
|
|
1299
|
-
return this.sameMarkup(
|
|
1469
|
+
eq(other) {
|
|
1470
|
+
return this.sameMarkup(other) && this.text == other.text;
|
|
1300
1471
|
}
|
|
1301
1472
|
toJSON() {
|
|
1302
|
-
let
|
|
1303
|
-
|
|
1473
|
+
let base = super.toJSON();
|
|
1474
|
+
base.text = this.text;
|
|
1475
|
+
return base;
|
|
1304
1476
|
}
|
|
1305
1477
|
}
|
|
1306
|
-
function
|
|
1307
|
-
for (let
|
|
1308
|
-
|
|
1309
|
-
return
|
|
1478
|
+
function wrapMarks(marks, str) {
|
|
1479
|
+
for (let i = marks.length - 1; i >= 0; i--)
|
|
1480
|
+
str = marks[i].type.name + "(" + str + ")";
|
|
1481
|
+
return str;
|
|
1310
1482
|
}
|
|
1311
|
-
class
|
|
1483
|
+
class ContentMatch {
|
|
1312
1484
|
/**
|
|
1313
1485
|
@internal
|
|
1314
1486
|
*/
|
|
1315
|
-
constructor(
|
|
1316
|
-
this.validEnd =
|
|
1487
|
+
constructor(validEnd) {
|
|
1488
|
+
this.validEnd = validEnd;
|
|
1489
|
+
this.next = [];
|
|
1490
|
+
this.wrapCache = [];
|
|
1317
1491
|
}
|
|
1318
1492
|
/**
|
|
1319
1493
|
@internal
|
|
1320
1494
|
*/
|
|
1321
|
-
static parse(
|
|
1322
|
-
let
|
|
1323
|
-
if (
|
|
1324
|
-
return
|
|
1325
|
-
let
|
|
1326
|
-
|
|
1327
|
-
|
|
1328
|
-
|
|
1495
|
+
static parse(string, nodeTypes) {
|
|
1496
|
+
let stream = new TokenStream(string, nodeTypes);
|
|
1497
|
+
if (stream.next == null)
|
|
1498
|
+
return ContentMatch.empty;
|
|
1499
|
+
let expr = parseExpr(stream);
|
|
1500
|
+
if (stream.next)
|
|
1501
|
+
stream.err("Unexpected trailing text");
|
|
1502
|
+
let match = dfa(nfa(expr));
|
|
1503
|
+
checkForDeadEnds(match, stream);
|
|
1504
|
+
return match;
|
|
1329
1505
|
}
|
|
1330
1506
|
/**
|
|
1331
1507
|
Match a node type, returning a match after that node if
|
|
1332
1508
|
successful.
|
|
1333
1509
|
*/
|
|
1334
|
-
matchType(
|
|
1335
|
-
for (let
|
|
1336
|
-
if (this.next[
|
|
1337
|
-
return this.next[
|
|
1510
|
+
matchType(type) {
|
|
1511
|
+
for (let i = 0; i < this.next.length; i++)
|
|
1512
|
+
if (this.next[i].type == type)
|
|
1513
|
+
return this.next[i].next;
|
|
1338
1514
|
return null;
|
|
1339
1515
|
}
|
|
1340
1516
|
/**
|
|
1341
1517
|
Try to match a fragment. Returns the resulting match when
|
|
1342
1518
|
successful.
|
|
1343
1519
|
*/
|
|
1344
|
-
matchFragment(
|
|
1345
|
-
let
|
|
1346
|
-
for (let
|
|
1347
|
-
|
|
1348
|
-
return
|
|
1520
|
+
matchFragment(frag, start = 0, end = frag.childCount) {
|
|
1521
|
+
let cur = this;
|
|
1522
|
+
for (let i = start; cur && i < end; i++)
|
|
1523
|
+
cur = cur.matchType(frag.child(i).type);
|
|
1524
|
+
return cur;
|
|
1349
1525
|
}
|
|
1350
1526
|
/**
|
|
1351
1527
|
@internal
|
|
@@ -1358,22 +1534,22 @@ class w {
|
|
|
1358
1534
|
be generated.
|
|
1359
1535
|
*/
|
|
1360
1536
|
get defaultType() {
|
|
1361
|
-
for (let
|
|
1362
|
-
let { type
|
|
1363
|
-
if (!(
|
|
1364
|
-
return
|
|
1537
|
+
for (let i = 0; i < this.next.length; i++) {
|
|
1538
|
+
let { type } = this.next[i];
|
|
1539
|
+
if (!(type.isText || type.hasRequiredAttrs()))
|
|
1540
|
+
return type;
|
|
1365
1541
|
}
|
|
1366
1542
|
return null;
|
|
1367
1543
|
}
|
|
1368
1544
|
/**
|
|
1369
1545
|
@internal
|
|
1370
1546
|
*/
|
|
1371
|
-
compatible(
|
|
1372
|
-
for (let
|
|
1373
|
-
for (let
|
|
1374
|
-
if (this.next[
|
|
1375
|
-
return
|
|
1376
|
-
return
|
|
1547
|
+
compatible(other) {
|
|
1548
|
+
for (let i = 0; i < this.next.length; i++)
|
|
1549
|
+
for (let j = 0; j < other.next.length; j++)
|
|
1550
|
+
if (this.next[i].type == other.next[j].type)
|
|
1551
|
+
return true;
|
|
1552
|
+
return false;
|
|
1377
1553
|
}
|
|
1378
1554
|
/**
|
|
1379
1555
|
Try to match the given fragment, and if that fails, see if it can
|
|
@@ -1383,24 +1559,24 @@ class w {
|
|
|
1383
1559
|
return a fragment if the resulting match goes to the end of the
|
|
1384
1560
|
content expression.
|
|
1385
1561
|
*/
|
|
1386
|
-
fillBefore(
|
|
1387
|
-
let
|
|
1388
|
-
function
|
|
1389
|
-
let
|
|
1390
|
-
if (
|
|
1391
|
-
return
|
|
1392
|
-
for (let
|
|
1393
|
-
let { type
|
|
1394
|
-
if (!(
|
|
1395
|
-
|
|
1396
|
-
let
|
|
1397
|
-
if (
|
|
1398
|
-
return
|
|
1562
|
+
fillBefore(after, toEnd = false, startIndex = 0) {
|
|
1563
|
+
let seen = [this];
|
|
1564
|
+
function search(match, types) {
|
|
1565
|
+
let finished = match.matchFragment(after, startIndex);
|
|
1566
|
+
if (finished && (!toEnd || finished.validEnd))
|
|
1567
|
+
return Fragment.from(types.map((tp) => tp.createAndFill()));
|
|
1568
|
+
for (let i = 0; i < match.next.length; i++) {
|
|
1569
|
+
let { type, next } = match.next[i];
|
|
1570
|
+
if (!(type.isText || type.hasRequiredAttrs()) && seen.indexOf(next) == -1) {
|
|
1571
|
+
seen.push(next);
|
|
1572
|
+
let found2 = search(next, types.concat(type));
|
|
1573
|
+
if (found2)
|
|
1574
|
+
return found2;
|
|
1399
1575
|
}
|
|
1400
1576
|
}
|
|
1401
1577
|
return null;
|
|
1402
1578
|
}
|
|
1403
|
-
return
|
|
1579
|
+
return search(this, []);
|
|
1404
1580
|
}
|
|
1405
1581
|
/**
|
|
1406
1582
|
Find a set of wrapping node types that would allow a node of the
|
|
@@ -1408,29 +1584,33 @@ class w {
|
|
|
1408
1584
|
(when it fits directly) and will be null when no such wrapping
|
|
1409
1585
|
exists.
|
|
1410
1586
|
*/
|
|
1411
|
-
findWrapping(
|
|
1412
|
-
for (let
|
|
1413
|
-
if (this.wrapCache[
|
|
1414
|
-
return this.wrapCache[
|
|
1415
|
-
let
|
|
1416
|
-
|
|
1587
|
+
findWrapping(target) {
|
|
1588
|
+
for (let i = 0; i < this.wrapCache.length; i += 2)
|
|
1589
|
+
if (this.wrapCache[i] == target)
|
|
1590
|
+
return this.wrapCache[i + 1];
|
|
1591
|
+
let computed = this.computeWrapping(target);
|
|
1592
|
+
this.wrapCache.push(target, computed);
|
|
1593
|
+
return computed;
|
|
1417
1594
|
}
|
|
1418
1595
|
/**
|
|
1419
1596
|
@internal
|
|
1420
1597
|
*/
|
|
1421
|
-
computeWrapping(
|
|
1422
|
-
let
|
|
1423
|
-
|
|
1424
|
-
let
|
|
1425
|
-
if (
|
|
1426
|
-
let
|
|
1427
|
-
for (let
|
|
1428
|
-
|
|
1429
|
-
return
|
|
1598
|
+
computeWrapping(target) {
|
|
1599
|
+
let seen = /* @__PURE__ */ Object.create(null), active = [{ match: this, type: null, via: null }];
|
|
1600
|
+
while (active.length) {
|
|
1601
|
+
let current = active.shift(), match = current.match;
|
|
1602
|
+
if (match.matchType(target)) {
|
|
1603
|
+
let result = [];
|
|
1604
|
+
for (let obj = current; obj.type; obj = obj.via)
|
|
1605
|
+
result.push(obj.type);
|
|
1606
|
+
return result.reverse();
|
|
1430
1607
|
}
|
|
1431
|
-
for (let
|
|
1432
|
-
let { type
|
|
1433
|
-
!
|
|
1608
|
+
for (let i = 0; i < match.next.length; i++) {
|
|
1609
|
+
let { type, next } = match.next[i];
|
|
1610
|
+
if (!type.isLeaf && !type.hasRequiredAttrs() && !(type.name in seen) && (!current.type || next.validEnd)) {
|
|
1611
|
+
active.push({ match: type.contentMatch, type, via: current });
|
|
1612
|
+
seen[type.name] = true;
|
|
1613
|
+
}
|
|
1434
1614
|
}
|
|
1435
1615
|
}
|
|
1436
1616
|
return null;
|
|
@@ -1446,258 +1626,320 @@ class w {
|
|
|
1446
1626
|
Get the _n_th outgoing edge from this node in the finite
|
|
1447
1627
|
automaton that describes the content expression.
|
|
1448
1628
|
*/
|
|
1449
|
-
edge(
|
|
1450
|
-
if (
|
|
1451
|
-
throw new RangeError(`There's no ${
|
|
1452
|
-
return this.next[
|
|
1629
|
+
edge(n) {
|
|
1630
|
+
if (n >= this.next.length)
|
|
1631
|
+
throw new RangeError(`There's no ${n}th edge in this content match`);
|
|
1632
|
+
return this.next[n];
|
|
1453
1633
|
}
|
|
1454
1634
|
/**
|
|
1455
1635
|
@internal
|
|
1456
1636
|
*/
|
|
1457
1637
|
toString() {
|
|
1458
|
-
let
|
|
1459
|
-
function
|
|
1460
|
-
|
|
1461
|
-
for (let i = 0; i <
|
|
1462
|
-
|
|
1638
|
+
let seen = [];
|
|
1639
|
+
function scan(m) {
|
|
1640
|
+
seen.push(m);
|
|
1641
|
+
for (let i = 0; i < m.next.length; i++)
|
|
1642
|
+
if (seen.indexOf(m.next[i].next) == -1)
|
|
1643
|
+
scan(m.next[i].next);
|
|
1463
1644
|
}
|
|
1464
|
-
|
|
1465
|
-
|
|
1466
|
-
|
|
1467
|
-
|
|
1468
|
-
|
|
1469
|
-
|
|
1470
|
-
|
|
1471
|
-
}
|
|
1472
|
-
}
|
|
1473
|
-
|
|
1474
|
-
class
|
|
1475
|
-
constructor(
|
|
1476
|
-
this.string =
|
|
1645
|
+
scan(this);
|
|
1646
|
+
return seen.map((m, i) => {
|
|
1647
|
+
let out = i + (m.validEnd ? "*" : " ") + " ";
|
|
1648
|
+
for (let i2 = 0; i2 < m.next.length; i2++)
|
|
1649
|
+
out += (i2 ? ", " : "") + m.next[i2].type.name + "->" + seen.indexOf(m.next[i2].next);
|
|
1650
|
+
return out;
|
|
1651
|
+
}).join("\n");
|
|
1652
|
+
}
|
|
1653
|
+
}
|
|
1654
|
+
ContentMatch.empty = new ContentMatch(true);
|
|
1655
|
+
class TokenStream {
|
|
1656
|
+
constructor(string, nodeTypes) {
|
|
1657
|
+
this.string = string;
|
|
1658
|
+
this.nodeTypes = nodeTypes;
|
|
1659
|
+
this.inline = null;
|
|
1660
|
+
this.pos = 0;
|
|
1661
|
+
this.tokens = string.split(/\s*(?=\b|\W|$)/);
|
|
1662
|
+
if (this.tokens[this.tokens.length - 1] == "")
|
|
1663
|
+
this.tokens.pop();
|
|
1664
|
+
if (this.tokens[0] == "")
|
|
1665
|
+
this.tokens.shift();
|
|
1477
1666
|
}
|
|
1478
1667
|
get next() {
|
|
1479
1668
|
return this.tokens[this.pos];
|
|
1480
1669
|
}
|
|
1481
|
-
eat(
|
|
1482
|
-
return this.next ==
|
|
1483
|
-
}
|
|
1484
|
-
err(
|
|
1485
|
-
throw new SyntaxError(
|
|
1486
|
-
}
|
|
1487
|
-
}
|
|
1488
|
-
function
|
|
1489
|
-
let
|
|
1490
|
-
do
|
|
1491
|
-
|
|
1492
|
-
while (
|
|
1493
|
-
return
|
|
1494
|
-
}
|
|
1495
|
-
function
|
|
1496
|
-
let
|
|
1497
|
-
do
|
|
1498
|
-
|
|
1499
|
-
while (
|
|
1500
|
-
return
|
|
1501
|
-
}
|
|
1502
|
-
function
|
|
1503
|
-
let
|
|
1504
|
-
for (; ; )
|
|
1505
|
-
if (
|
|
1506
|
-
|
|
1507
|
-
else if (
|
|
1508
|
-
|
|
1509
|
-
else if (
|
|
1510
|
-
|
|
1511
|
-
else if (
|
|
1512
|
-
|
|
1670
|
+
eat(tok) {
|
|
1671
|
+
return this.next == tok && (this.pos++ || true);
|
|
1672
|
+
}
|
|
1673
|
+
err(str) {
|
|
1674
|
+
throw new SyntaxError(str + " (in content expression '" + this.string + "')");
|
|
1675
|
+
}
|
|
1676
|
+
}
|
|
1677
|
+
function parseExpr(stream) {
|
|
1678
|
+
let exprs = [];
|
|
1679
|
+
do {
|
|
1680
|
+
exprs.push(parseExprSeq(stream));
|
|
1681
|
+
} while (stream.eat("|"));
|
|
1682
|
+
return exprs.length == 1 ? exprs[0] : { type: "choice", exprs };
|
|
1683
|
+
}
|
|
1684
|
+
function parseExprSeq(stream) {
|
|
1685
|
+
let exprs = [];
|
|
1686
|
+
do {
|
|
1687
|
+
exprs.push(parseExprSubscript(stream));
|
|
1688
|
+
} while (stream.next && stream.next != ")" && stream.next != "|");
|
|
1689
|
+
return exprs.length == 1 ? exprs[0] : { type: "seq", exprs };
|
|
1690
|
+
}
|
|
1691
|
+
function parseExprSubscript(stream) {
|
|
1692
|
+
let expr = parseExprAtom(stream);
|
|
1693
|
+
for (; ; ) {
|
|
1694
|
+
if (stream.eat("+"))
|
|
1695
|
+
expr = { type: "plus", expr };
|
|
1696
|
+
else if (stream.eat("*"))
|
|
1697
|
+
expr = { type: "star", expr };
|
|
1698
|
+
else if (stream.eat("?"))
|
|
1699
|
+
expr = { type: "opt", expr };
|
|
1700
|
+
else if (stream.eat("{"))
|
|
1701
|
+
expr = parseExprRange(stream, expr);
|
|
1513
1702
|
else
|
|
1514
1703
|
break;
|
|
1515
|
-
|
|
1516
|
-
|
|
1517
|
-
|
|
1518
|
-
|
|
1519
|
-
|
|
1520
|
-
|
|
1521
|
-
|
|
1522
|
-
|
|
1523
|
-
|
|
1524
|
-
|
|
1525
|
-
|
|
1526
|
-
|
|
1527
|
-
|
|
1528
|
-
|
|
1529
|
-
|
|
1530
|
-
|
|
1531
|
-
|
|
1532
|
-
|
|
1533
|
-
|
|
1534
|
-
|
|
1535
|
-
return
|
|
1536
|
-
}
|
|
1537
|
-
function
|
|
1538
|
-
|
|
1539
|
-
|
|
1540
|
-
return
|
|
1541
|
-
|
|
1542
|
-
|
|
1543
|
-
|
|
1544
|
-
|
|
1545
|
-
|
|
1546
|
-
}
|
|
1547
|
-
|
|
1548
|
-
|
|
1549
|
-
|
|
1550
|
-
|
|
1551
|
-
|
|
1552
|
-
|
|
1553
|
-
|
|
1554
|
-
|
|
1555
|
-
|
|
1556
|
-
return
|
|
1557
|
-
}
|
|
1558
|
-
|
|
1559
|
-
|
|
1560
|
-
|
|
1561
|
-
|
|
1562
|
-
|
|
1563
|
-
return
|
|
1564
|
-
|
|
1565
|
-
|
|
1566
|
-
|
|
1567
|
-
|
|
1568
|
-
|
|
1569
|
-
|
|
1704
|
+
}
|
|
1705
|
+
return expr;
|
|
1706
|
+
}
|
|
1707
|
+
function parseNum(stream) {
|
|
1708
|
+
if (/\D/.test(stream.next))
|
|
1709
|
+
stream.err("Expected number, got '" + stream.next + "'");
|
|
1710
|
+
let result = Number(stream.next);
|
|
1711
|
+
stream.pos++;
|
|
1712
|
+
return result;
|
|
1713
|
+
}
|
|
1714
|
+
function parseExprRange(stream, expr) {
|
|
1715
|
+
let min = parseNum(stream), max = min;
|
|
1716
|
+
if (stream.eat(",")) {
|
|
1717
|
+
if (stream.next != "}")
|
|
1718
|
+
max = parseNum(stream);
|
|
1719
|
+
else
|
|
1720
|
+
max = -1;
|
|
1721
|
+
}
|
|
1722
|
+
if (!stream.eat("}"))
|
|
1723
|
+
stream.err("Unclosed braced range");
|
|
1724
|
+
return { type: "range", min, max, expr };
|
|
1725
|
+
}
|
|
1726
|
+
function resolveName(stream, name) {
|
|
1727
|
+
let types = stream.nodeTypes, type = types[name];
|
|
1728
|
+
if (type)
|
|
1729
|
+
return [type];
|
|
1730
|
+
let result = [];
|
|
1731
|
+
for (let typeName in types) {
|
|
1732
|
+
let type2 = types[typeName];
|
|
1733
|
+
if (type2.isInGroup(name))
|
|
1734
|
+
result.push(type2);
|
|
1735
|
+
}
|
|
1736
|
+
if (result.length == 0)
|
|
1737
|
+
stream.err("No node type or group '" + name + "' found");
|
|
1738
|
+
return result;
|
|
1739
|
+
}
|
|
1740
|
+
function parseExprAtom(stream) {
|
|
1741
|
+
if (stream.eat("(")) {
|
|
1742
|
+
let expr = parseExpr(stream);
|
|
1743
|
+
if (!stream.eat(")"))
|
|
1744
|
+
stream.err("Missing closing paren");
|
|
1745
|
+
return expr;
|
|
1746
|
+
} else if (!/\W/.test(stream.next)) {
|
|
1747
|
+
let exprs = resolveName(stream, stream.next).map((type) => {
|
|
1748
|
+
if (stream.inline == null)
|
|
1749
|
+
stream.inline = type.isInline;
|
|
1750
|
+
else if (stream.inline != type.isInline)
|
|
1751
|
+
stream.err("Mixing inline and block content");
|
|
1752
|
+
return { type: "name", value: type };
|
|
1753
|
+
});
|
|
1754
|
+
stream.pos++;
|
|
1755
|
+
return exprs.length == 1 ? exprs[0] : { type: "choice", exprs };
|
|
1756
|
+
} else {
|
|
1757
|
+
stream.err("Unexpected token '" + stream.next + "'");
|
|
1758
|
+
}
|
|
1759
|
+
}
|
|
1760
|
+
function nfa(expr) {
|
|
1761
|
+
let nfa2 = [[]];
|
|
1762
|
+
connect(compile(expr, 0), node());
|
|
1763
|
+
return nfa2;
|
|
1764
|
+
function node() {
|
|
1765
|
+
return nfa2.push([]) - 1;
|
|
1766
|
+
}
|
|
1767
|
+
function edge(from, to, term) {
|
|
1768
|
+
let edge2 = { term, to };
|
|
1769
|
+
nfa2[from].push(edge2);
|
|
1770
|
+
return edge2;
|
|
1771
|
+
}
|
|
1772
|
+
function connect(edges, to) {
|
|
1773
|
+
edges.forEach((edge2) => edge2.to = to);
|
|
1774
|
+
}
|
|
1775
|
+
function compile(expr2, from) {
|
|
1776
|
+
if (expr2.type == "choice") {
|
|
1777
|
+
return expr2.exprs.reduce((out, expr3) => out.concat(compile(expr3, from)), []);
|
|
1778
|
+
} else if (expr2.type == "seq") {
|
|
1779
|
+
for (let i = 0; ; i++) {
|
|
1780
|
+
let next = compile(expr2.exprs[i], from);
|
|
1781
|
+
if (i == expr2.exprs.length - 1)
|
|
1782
|
+
return next;
|
|
1783
|
+
connect(next, from = node());
|
|
1570
1784
|
}
|
|
1571
|
-
else if (
|
|
1572
|
-
let
|
|
1573
|
-
|
|
1574
|
-
|
|
1575
|
-
|
|
1576
|
-
|
|
1577
|
-
|
|
1578
|
-
|
|
1579
|
-
|
|
1580
|
-
|
|
1581
|
-
|
|
1582
|
-
|
|
1583
|
-
|
|
1584
|
-
|
|
1585
|
-
|
|
1586
|
-
|
|
1587
|
-
|
|
1588
|
-
|
|
1589
|
-
|
|
1590
|
-
|
|
1591
|
-
|
|
1592
|
-
}
|
|
1593
|
-
return [n(h)];
|
|
1785
|
+
} else if (expr2.type == "star") {
|
|
1786
|
+
let loop = node();
|
|
1787
|
+
edge(from, loop);
|
|
1788
|
+
connect(compile(expr2.expr, loop), loop);
|
|
1789
|
+
return [edge(loop)];
|
|
1790
|
+
} else if (expr2.type == "plus") {
|
|
1791
|
+
let loop = node();
|
|
1792
|
+
connect(compile(expr2.expr, from), loop);
|
|
1793
|
+
connect(compile(expr2.expr, loop), loop);
|
|
1794
|
+
return [edge(loop)];
|
|
1795
|
+
} else if (expr2.type == "opt") {
|
|
1796
|
+
return [edge(from)].concat(compile(expr2.expr, from));
|
|
1797
|
+
} else if (expr2.type == "range") {
|
|
1798
|
+
let cur = from;
|
|
1799
|
+
for (let i = 0; i < expr2.min; i++) {
|
|
1800
|
+
let next = node();
|
|
1801
|
+
connect(compile(expr2.expr, cur), next);
|
|
1802
|
+
cur = next;
|
|
1803
|
+
}
|
|
1804
|
+
if (expr2.max == -1) {
|
|
1805
|
+
connect(compile(expr2.expr, cur), cur);
|
|
1594
1806
|
} else {
|
|
1595
|
-
|
|
1596
|
-
|
|
1597
|
-
|
|
1807
|
+
for (let i = expr2.min; i < expr2.max; i++) {
|
|
1808
|
+
let next = node();
|
|
1809
|
+
edge(cur, next);
|
|
1810
|
+
connect(compile(expr2.expr, cur), next);
|
|
1811
|
+
cur = next;
|
|
1812
|
+
}
|
|
1598
1813
|
}
|
|
1814
|
+
return [edge(cur)];
|
|
1815
|
+
} else if (expr2.type == "name") {
|
|
1816
|
+
return [edge(from, void 0, expr2.value)];
|
|
1817
|
+
} else {
|
|
1818
|
+
throw new Error("Unknown expr type");
|
|
1599
1819
|
}
|
|
1600
1820
|
}
|
|
1601
1821
|
}
|
|
1602
|
-
function
|
|
1603
|
-
return
|
|
1604
|
-
}
|
|
1605
|
-
function
|
|
1606
|
-
let
|
|
1607
|
-
|
|
1608
|
-
|
|
1609
|
-
|
|
1610
|
-
|
|
1611
|
-
|
|
1612
|
-
|
|
1613
|
-
|
|
1614
|
-
|
|
1615
|
-
|
|
1822
|
+
function cmp(a, b) {
|
|
1823
|
+
return b - a;
|
|
1824
|
+
}
|
|
1825
|
+
function nullFrom(nfa2, node) {
|
|
1826
|
+
let result = [];
|
|
1827
|
+
scan(node);
|
|
1828
|
+
return result.sort(cmp);
|
|
1829
|
+
function scan(node2) {
|
|
1830
|
+
let edges = nfa2[node2];
|
|
1831
|
+
if (edges.length == 1 && !edges[0].term)
|
|
1832
|
+
return scan(edges[0].to);
|
|
1833
|
+
result.push(node2);
|
|
1834
|
+
for (let i = 0; i < edges.length; i++) {
|
|
1835
|
+
let { term, to } = edges[i];
|
|
1836
|
+
if (!term && result.indexOf(to) == -1)
|
|
1837
|
+
scan(to);
|
|
1616
1838
|
}
|
|
1617
1839
|
}
|
|
1618
1840
|
}
|
|
1619
|
-
function
|
|
1620
|
-
let
|
|
1621
|
-
return
|
|
1622
|
-
function
|
|
1623
|
-
let
|
|
1624
|
-
|
|
1625
|
-
|
|
1626
|
-
if (!
|
|
1841
|
+
function dfa(nfa2) {
|
|
1842
|
+
let labeled = /* @__PURE__ */ Object.create(null);
|
|
1843
|
+
return explore(nullFrom(nfa2, 0));
|
|
1844
|
+
function explore(states) {
|
|
1845
|
+
let out = [];
|
|
1846
|
+
states.forEach((node) => {
|
|
1847
|
+
nfa2[node].forEach(({ term, to }) => {
|
|
1848
|
+
if (!term)
|
|
1627
1849
|
return;
|
|
1628
|
-
let
|
|
1629
|
-
for (let
|
|
1630
|
-
i
|
|
1631
|
-
|
|
1632
|
-
|
|
1850
|
+
let set;
|
|
1851
|
+
for (let i = 0; i < out.length; i++)
|
|
1852
|
+
if (out[i][0] == term)
|
|
1853
|
+
set = out[i][1];
|
|
1854
|
+
nullFrom(nfa2, to).forEach((node2) => {
|
|
1855
|
+
if (!set)
|
|
1856
|
+
out.push([term, set = []]);
|
|
1857
|
+
if (set.indexOf(node2) == -1)
|
|
1858
|
+
set.push(node2);
|
|
1633
1859
|
});
|
|
1634
1860
|
});
|
|
1635
1861
|
});
|
|
1636
|
-
let
|
|
1637
|
-
for (let
|
|
1638
|
-
let
|
|
1639
|
-
|
|
1862
|
+
let state = labeled[states.join(",")] = new ContentMatch(states.indexOf(nfa2.length - 1) > -1);
|
|
1863
|
+
for (let i = 0; i < out.length; i++) {
|
|
1864
|
+
let states2 = out[i][1].sort(cmp);
|
|
1865
|
+
state.next.push({ type: out[i][0], next: labeled[states2.join(",")] || explore(states2) });
|
|
1640
1866
|
}
|
|
1641
|
-
return
|
|
1642
|
-
}
|
|
1643
|
-
}
|
|
1644
|
-
function
|
|
1645
|
-
for (let
|
|
1646
|
-
let
|
|
1647
|
-
for (let
|
|
1648
|
-
let { type
|
|
1649
|
-
|
|
1867
|
+
return state;
|
|
1868
|
+
}
|
|
1869
|
+
}
|
|
1870
|
+
function checkForDeadEnds(match, stream) {
|
|
1871
|
+
for (let i = 0, work = [match]; i < work.length; i++) {
|
|
1872
|
+
let state = work[i], dead = !state.validEnd, nodes = [];
|
|
1873
|
+
for (let j = 0; j < state.next.length; j++) {
|
|
1874
|
+
let { type, next } = state.next[j];
|
|
1875
|
+
nodes.push(type.name);
|
|
1876
|
+
if (dead && !(type.isText || type.hasRequiredAttrs()))
|
|
1877
|
+
dead = false;
|
|
1878
|
+
if (work.indexOf(next) == -1)
|
|
1879
|
+
work.push(next);
|
|
1650
1880
|
}
|
|
1651
|
-
|
|
1881
|
+
if (dead)
|
|
1882
|
+
stream.err("Only non-generatable nodes (" + nodes.join(", ") + ") in a required position (see https://prosemirror.net/docs/guide/#generatable)");
|
|
1652
1883
|
}
|
|
1653
1884
|
}
|
|
1654
|
-
function
|
|
1655
|
-
let
|
|
1656
|
-
for (let
|
|
1657
|
-
let
|
|
1658
|
-
if (!
|
|
1885
|
+
function defaultAttrs(attrs) {
|
|
1886
|
+
let defaults = /* @__PURE__ */ Object.create(null);
|
|
1887
|
+
for (let attrName in attrs) {
|
|
1888
|
+
let attr = attrs[attrName];
|
|
1889
|
+
if (!attr.hasDefault)
|
|
1659
1890
|
return null;
|
|
1660
|
-
|
|
1661
|
-
}
|
|
1662
|
-
return
|
|
1663
|
-
}
|
|
1664
|
-
function
|
|
1665
|
-
let
|
|
1666
|
-
for (let
|
|
1667
|
-
let
|
|
1668
|
-
if (
|
|
1669
|
-
let
|
|
1670
|
-
if (
|
|
1671
|
-
|
|
1891
|
+
defaults[attrName] = attr.default;
|
|
1892
|
+
}
|
|
1893
|
+
return defaults;
|
|
1894
|
+
}
|
|
1895
|
+
function computeAttrs(attrs, value) {
|
|
1896
|
+
let built = /* @__PURE__ */ Object.create(null);
|
|
1897
|
+
for (let name in attrs) {
|
|
1898
|
+
let given = value && value[name];
|
|
1899
|
+
if (given === void 0) {
|
|
1900
|
+
let attr = attrs[name];
|
|
1901
|
+
if (attr.hasDefault)
|
|
1902
|
+
given = attr.default;
|
|
1672
1903
|
else
|
|
1673
|
-
throw new RangeError("No value supplied for attribute " +
|
|
1904
|
+
throw new RangeError("No value supplied for attribute " + name);
|
|
1674
1905
|
}
|
|
1675
|
-
|
|
1906
|
+
built[name] = given;
|
|
1676
1907
|
}
|
|
1677
|
-
return
|
|
1908
|
+
return built;
|
|
1678
1909
|
}
|
|
1679
|
-
function
|
|
1680
|
-
for (let
|
|
1681
|
-
if (!(
|
|
1682
|
-
throw new RangeError(`Unsupported attribute ${
|
|
1683
|
-
for (let
|
|
1684
|
-
let
|
|
1685
|
-
|
|
1910
|
+
function checkAttrs(attrs, values, type, name) {
|
|
1911
|
+
for (let name2 in values)
|
|
1912
|
+
if (!(name2 in attrs))
|
|
1913
|
+
throw new RangeError(`Unsupported attribute ${name2} for ${type} of type ${name2}`);
|
|
1914
|
+
for (let name2 in attrs) {
|
|
1915
|
+
let attr = attrs[name2];
|
|
1916
|
+
if (attr.validate)
|
|
1917
|
+
attr.validate(values[name2]);
|
|
1686
1918
|
}
|
|
1687
1919
|
}
|
|
1688
|
-
function
|
|
1689
|
-
let
|
|
1690
|
-
if (
|
|
1691
|
-
for (let
|
|
1692
|
-
|
|
1693
|
-
return
|
|
1920
|
+
function initAttrs(typeName, attrs) {
|
|
1921
|
+
let result = /* @__PURE__ */ Object.create(null);
|
|
1922
|
+
if (attrs)
|
|
1923
|
+
for (let name in attrs)
|
|
1924
|
+
result[name] = new Attribute(typeName, name, attrs[name]);
|
|
1925
|
+
return result;
|
|
1694
1926
|
}
|
|
1695
|
-
class
|
|
1927
|
+
class NodeType {
|
|
1696
1928
|
/**
|
|
1697
1929
|
@internal
|
|
1698
1930
|
*/
|
|
1699
|
-
constructor(
|
|
1700
|
-
this.name =
|
|
1931
|
+
constructor(name, schema, spec) {
|
|
1932
|
+
this.name = name;
|
|
1933
|
+
this.schema = schema;
|
|
1934
|
+
this.spec = spec;
|
|
1935
|
+
this.markSet = null;
|
|
1936
|
+
this.groups = spec.group ? spec.group.split(" ") : [];
|
|
1937
|
+
this.attrs = initAttrs(name, spec.attrs);
|
|
1938
|
+
this.defaultAttrs = defaultAttrs(this.attrs);
|
|
1939
|
+
this.contentMatch = null;
|
|
1940
|
+
this.inlineContent = null;
|
|
1941
|
+
this.isBlock = !(spec.inline || name == "text");
|
|
1942
|
+
this.isText = name == "text";
|
|
1701
1943
|
}
|
|
1702
1944
|
/**
|
|
1703
1945
|
True if this is an inline type.
|
|
@@ -1716,7 +1958,7 @@ class z {
|
|
|
1716
1958
|
True for node types that allow no content.
|
|
1717
1959
|
*/
|
|
1718
1960
|
get isLeaf() {
|
|
1719
|
-
return this.contentMatch ==
|
|
1961
|
+
return this.contentMatch == ContentMatch.empty;
|
|
1720
1962
|
}
|
|
1721
1963
|
/**
|
|
1722
1964
|
True when this node is an atom, i.e. when it does not have
|
|
@@ -1729,8 +1971,8 @@ class z {
|
|
|
1729
1971
|
Return true when this node type is part of the given
|
|
1730
1972
|
[group](https://prosemirror.net/docs/ref/#model.NodeSpec.group).
|
|
1731
1973
|
*/
|
|
1732
|
-
isInGroup(
|
|
1733
|
-
return this.groups.indexOf(
|
|
1974
|
+
isInGroup(group) {
|
|
1975
|
+
return this.groups.indexOf(group) > -1;
|
|
1734
1976
|
}
|
|
1735
1977
|
/**
|
|
1736
1978
|
The node type's [whitespace](https://prosemirror.net/docs/ref/#model.NodeSpec.whitespace) option.
|
|
@@ -1742,23 +1984,26 @@ class z {
|
|
|
1742
1984
|
Tells you whether this node type has any required attributes.
|
|
1743
1985
|
*/
|
|
1744
1986
|
hasRequiredAttrs() {
|
|
1745
|
-
for (let
|
|
1746
|
-
if (this.attrs[
|
|
1747
|
-
return
|
|
1748
|
-
return
|
|
1987
|
+
for (let n in this.attrs)
|
|
1988
|
+
if (this.attrs[n].isRequired)
|
|
1989
|
+
return true;
|
|
1990
|
+
return false;
|
|
1749
1991
|
}
|
|
1750
1992
|
/**
|
|
1751
1993
|
Indicates whether this node allows some of the same content as
|
|
1752
1994
|
the given node type.
|
|
1753
1995
|
*/
|
|
1754
|
-
compatibleContent(
|
|
1755
|
-
return this ==
|
|
1996
|
+
compatibleContent(other) {
|
|
1997
|
+
return this == other || this.contentMatch.compatible(other.contentMatch);
|
|
1756
1998
|
}
|
|
1757
1999
|
/**
|
|
1758
2000
|
@internal
|
|
1759
2001
|
*/
|
|
1760
|
-
computeAttrs(
|
|
1761
|
-
|
|
2002
|
+
computeAttrs(attrs) {
|
|
2003
|
+
if (!attrs && this.defaultAttrs)
|
|
2004
|
+
return this.defaultAttrs;
|
|
2005
|
+
else
|
|
2006
|
+
return computeAttrs(this.attrs, attrs);
|
|
1762
2007
|
}
|
|
1763
2008
|
/**
|
|
1764
2009
|
Create a `Node` of this type. The given attributes are
|
|
@@ -1768,18 +2013,20 @@ class z {
|
|
|
1768
2013
|
`null`. Similarly `marks` may be `null` to default to the empty
|
|
1769
2014
|
set of marks.
|
|
1770
2015
|
*/
|
|
1771
|
-
create(
|
|
2016
|
+
create(attrs = null, content, marks) {
|
|
1772
2017
|
if (this.isText)
|
|
1773
2018
|
throw new Error("NodeType.create can't construct text nodes");
|
|
1774
|
-
return new
|
|
2019
|
+
return new Node(this, this.computeAttrs(attrs), Fragment.from(content), Mark.setFrom(marks));
|
|
1775
2020
|
}
|
|
1776
2021
|
/**
|
|
1777
2022
|
Like [`create`](https://prosemirror.net/docs/ref/#model.NodeType.create), but check the given content
|
|
1778
2023
|
against the node type's content restrictions, and throw an error
|
|
1779
2024
|
if it doesn't match.
|
|
1780
2025
|
*/
|
|
1781
|
-
createChecked(
|
|
1782
|
-
|
|
2026
|
+
createChecked(attrs = null, content, marks) {
|
|
2027
|
+
content = Fragment.from(content);
|
|
2028
|
+
this.checkContent(content);
|
|
2029
|
+
return new Node(this, this.computeAttrs(attrs), content, Mark.setFrom(marks));
|
|
1783
2030
|
}
|
|
1784
2031
|
/**
|
|
1785
2032
|
Like [`create`](https://prosemirror.net/docs/ref/#model.NodeType.create), but see if it is
|
|
@@ -1789,188 +2036,219 @@ class z {
|
|
|
1789
2036
|
always be created, this will always succeed if you pass null or
|
|
1790
2037
|
`Fragment.empty` as content.
|
|
1791
2038
|
*/
|
|
1792
|
-
createAndFill(
|
|
1793
|
-
|
|
1794
|
-
|
|
1795
|
-
|
|
2039
|
+
createAndFill(attrs = null, content, marks) {
|
|
2040
|
+
attrs = this.computeAttrs(attrs);
|
|
2041
|
+
content = Fragment.from(content);
|
|
2042
|
+
if (content.size) {
|
|
2043
|
+
let before = this.contentMatch.fillBefore(content);
|
|
2044
|
+
if (!before)
|
|
1796
2045
|
return null;
|
|
1797
|
-
|
|
2046
|
+
content = before.append(content);
|
|
1798
2047
|
}
|
|
1799
|
-
let
|
|
1800
|
-
|
|
2048
|
+
let matched = this.contentMatch.matchFragment(content);
|
|
2049
|
+
let after = matched && matched.fillBefore(Fragment.empty, true);
|
|
2050
|
+
if (!after)
|
|
2051
|
+
return null;
|
|
2052
|
+
return new Node(this, attrs, content.append(after), Mark.setFrom(marks));
|
|
1801
2053
|
}
|
|
1802
2054
|
/**
|
|
1803
2055
|
Returns true if the given fragment is valid content for this node
|
|
1804
2056
|
type.
|
|
1805
2057
|
*/
|
|
1806
|
-
validContent(
|
|
1807
|
-
let
|
|
1808
|
-
if (!
|
|
1809
|
-
return
|
|
1810
|
-
for (let
|
|
1811
|
-
if (!this.allowsMarks(
|
|
1812
|
-
return
|
|
1813
|
-
return
|
|
2058
|
+
validContent(content) {
|
|
2059
|
+
let result = this.contentMatch.matchFragment(content);
|
|
2060
|
+
if (!result || !result.validEnd)
|
|
2061
|
+
return false;
|
|
2062
|
+
for (let i = 0; i < content.childCount; i++)
|
|
2063
|
+
if (!this.allowsMarks(content.child(i).marks))
|
|
2064
|
+
return false;
|
|
2065
|
+
return true;
|
|
1814
2066
|
}
|
|
1815
2067
|
/**
|
|
1816
2068
|
Throws a RangeError if the given fragment is not valid content for this
|
|
1817
2069
|
node type.
|
|
1818
2070
|
@internal
|
|
1819
2071
|
*/
|
|
1820
|
-
checkContent(
|
|
1821
|
-
if (!this.validContent(
|
|
1822
|
-
throw new RangeError(`Invalid content for node ${this.name}: ${
|
|
2072
|
+
checkContent(content) {
|
|
2073
|
+
if (!this.validContent(content))
|
|
2074
|
+
throw new RangeError(`Invalid content for node ${this.name}: ${content.toString().slice(0, 50)}`);
|
|
1823
2075
|
}
|
|
1824
2076
|
/**
|
|
1825
2077
|
@internal
|
|
1826
2078
|
*/
|
|
1827
|
-
checkAttrs(
|
|
1828
|
-
|
|
2079
|
+
checkAttrs(attrs) {
|
|
2080
|
+
checkAttrs(this.attrs, attrs, "node", this.name);
|
|
1829
2081
|
}
|
|
1830
2082
|
/**
|
|
1831
2083
|
Check whether the given mark type is allowed in this node.
|
|
1832
2084
|
*/
|
|
1833
|
-
allowsMarkType(
|
|
1834
|
-
return this.markSet == null || this.markSet.indexOf(
|
|
2085
|
+
allowsMarkType(markType) {
|
|
2086
|
+
return this.markSet == null || this.markSet.indexOf(markType) > -1;
|
|
1835
2087
|
}
|
|
1836
2088
|
/**
|
|
1837
2089
|
Test whether the given set of marks are allowed in this node.
|
|
1838
2090
|
*/
|
|
1839
|
-
allowsMarks(
|
|
2091
|
+
allowsMarks(marks) {
|
|
1840
2092
|
if (this.markSet == null)
|
|
1841
|
-
return
|
|
1842
|
-
for (let
|
|
1843
|
-
if (!this.allowsMarkType(
|
|
1844
|
-
return
|
|
1845
|
-
return
|
|
2093
|
+
return true;
|
|
2094
|
+
for (let i = 0; i < marks.length; i++)
|
|
2095
|
+
if (!this.allowsMarkType(marks[i].type))
|
|
2096
|
+
return false;
|
|
2097
|
+
return true;
|
|
1846
2098
|
}
|
|
1847
2099
|
/**
|
|
1848
2100
|
Removes the marks that are not allowed in this node from the given set.
|
|
1849
2101
|
*/
|
|
1850
|
-
allowedMarks(
|
|
2102
|
+
allowedMarks(marks) {
|
|
1851
2103
|
if (this.markSet == null)
|
|
1852
|
-
return
|
|
1853
|
-
let
|
|
1854
|
-
for (let
|
|
1855
|
-
this.allowsMarkType(
|
|
1856
|
-
|
|
2104
|
+
return marks;
|
|
2105
|
+
let copy2;
|
|
2106
|
+
for (let i = 0; i < marks.length; i++) {
|
|
2107
|
+
if (!this.allowsMarkType(marks[i].type)) {
|
|
2108
|
+
if (!copy2)
|
|
2109
|
+
copy2 = marks.slice(0, i);
|
|
2110
|
+
} else if (copy2) {
|
|
2111
|
+
copy2.push(marks[i]);
|
|
2112
|
+
}
|
|
2113
|
+
}
|
|
2114
|
+
return !copy2 ? marks : copy2.length ? copy2 : Mark.none;
|
|
1857
2115
|
}
|
|
1858
2116
|
/**
|
|
1859
2117
|
@internal
|
|
1860
2118
|
*/
|
|
1861
|
-
static compile(
|
|
1862
|
-
let
|
|
1863
|
-
|
|
1864
|
-
let
|
|
1865
|
-
if (!
|
|
1866
|
-
throw new RangeError("Schema is missing its top node type ('" +
|
|
1867
|
-
if (!
|
|
2119
|
+
static compile(nodes, schema) {
|
|
2120
|
+
let result = /* @__PURE__ */ Object.create(null);
|
|
2121
|
+
nodes.forEach((name, spec) => result[name] = new NodeType(name, schema, spec));
|
|
2122
|
+
let topType = schema.spec.topNode || "doc";
|
|
2123
|
+
if (!result[topType])
|
|
2124
|
+
throw new RangeError("Schema is missing its top node type ('" + topType + "')");
|
|
2125
|
+
if (!result.text)
|
|
1868
2126
|
throw new RangeError("Every schema needs a 'text' type");
|
|
1869
|
-
for (let
|
|
2127
|
+
for (let _ in result.text.attrs)
|
|
1870
2128
|
throw new RangeError("The text node type should not have attributes");
|
|
1871
|
-
return
|
|
2129
|
+
return result;
|
|
1872
2130
|
}
|
|
1873
2131
|
}
|
|
1874
|
-
function
|
|
1875
|
-
let
|
|
1876
|
-
return (
|
|
1877
|
-
let
|
|
1878
|
-
if (
|
|
1879
|
-
throw new RangeError(`Expected value of type ${
|
|
2132
|
+
function validateType(typeName, attrName, type) {
|
|
2133
|
+
let types = type.split("|");
|
|
2134
|
+
return (value) => {
|
|
2135
|
+
let name = value === null ? "null" : typeof value;
|
|
2136
|
+
if (types.indexOf(name) < 0)
|
|
2137
|
+
throw new RangeError(`Expected value of type ${types} for attribute ${attrName} on type ${typeName}, got ${name}`);
|
|
1880
2138
|
};
|
|
1881
2139
|
}
|
|
1882
|
-
class
|
|
1883
|
-
constructor(
|
|
1884
|
-
this.hasDefault = Object.prototype.hasOwnProperty.call(
|
|
2140
|
+
class Attribute {
|
|
2141
|
+
constructor(typeName, attrName, options) {
|
|
2142
|
+
this.hasDefault = Object.prototype.hasOwnProperty.call(options, "default");
|
|
2143
|
+
this.default = options.default;
|
|
2144
|
+
this.validate = typeof options.validate == "string" ? validateType(typeName, attrName, options.validate) : options.validate;
|
|
1885
2145
|
}
|
|
1886
2146
|
get isRequired() {
|
|
1887
2147
|
return !this.hasDefault;
|
|
1888
2148
|
}
|
|
1889
2149
|
}
|
|
1890
|
-
class
|
|
2150
|
+
class MarkType {
|
|
1891
2151
|
/**
|
|
1892
2152
|
@internal
|
|
1893
2153
|
*/
|
|
1894
|
-
constructor(
|
|
1895
|
-
this.name =
|
|
1896
|
-
|
|
1897
|
-
this.
|
|
2154
|
+
constructor(name, rank, schema, spec) {
|
|
2155
|
+
this.name = name;
|
|
2156
|
+
this.rank = rank;
|
|
2157
|
+
this.schema = schema;
|
|
2158
|
+
this.spec = spec;
|
|
2159
|
+
this.attrs = initAttrs(name, spec.attrs);
|
|
2160
|
+
this.excluded = null;
|
|
2161
|
+
let defaults = defaultAttrs(this.attrs);
|
|
2162
|
+
this.instance = defaults ? new Mark(this, defaults) : null;
|
|
1898
2163
|
}
|
|
1899
2164
|
/**
|
|
1900
2165
|
Create a mark of this type. `attrs` may be `null` or an object
|
|
1901
2166
|
containing only some of the mark's attributes. The others, if
|
|
1902
2167
|
they have defaults, will be added.
|
|
1903
2168
|
*/
|
|
1904
|
-
create(
|
|
1905
|
-
|
|
2169
|
+
create(attrs = null) {
|
|
2170
|
+
if (!attrs && this.instance)
|
|
2171
|
+
return this.instance;
|
|
2172
|
+
return new Mark(this, computeAttrs(this.attrs, attrs));
|
|
1906
2173
|
}
|
|
1907
2174
|
/**
|
|
1908
2175
|
@internal
|
|
1909
2176
|
*/
|
|
1910
|
-
static compile(
|
|
1911
|
-
let
|
|
1912
|
-
|
|
2177
|
+
static compile(marks, schema) {
|
|
2178
|
+
let result = /* @__PURE__ */ Object.create(null), rank = 0;
|
|
2179
|
+
marks.forEach((name, spec) => result[name] = new MarkType(name, rank++, schema, spec));
|
|
2180
|
+
return result;
|
|
1913
2181
|
}
|
|
1914
2182
|
/**
|
|
1915
2183
|
When there is a mark of this type in the given set, a new set
|
|
1916
2184
|
without it is returned. Otherwise, the input set is returned.
|
|
1917
2185
|
*/
|
|
1918
|
-
removeFromSet(
|
|
1919
|
-
for (var
|
|
1920
|
-
|
|
1921
|
-
|
|
2186
|
+
removeFromSet(set) {
|
|
2187
|
+
for (var i = 0; i < set.length; i++)
|
|
2188
|
+
if (set[i].type == this) {
|
|
2189
|
+
set = set.slice(0, i).concat(set.slice(i + 1));
|
|
2190
|
+
i--;
|
|
2191
|
+
}
|
|
2192
|
+
return set;
|
|
1922
2193
|
}
|
|
1923
2194
|
/**
|
|
1924
2195
|
Tests whether there is a mark of this type in the given set.
|
|
1925
2196
|
*/
|
|
1926
|
-
isInSet(
|
|
1927
|
-
for (let
|
|
1928
|
-
if (
|
|
1929
|
-
return
|
|
2197
|
+
isInSet(set) {
|
|
2198
|
+
for (let i = 0; i < set.length; i++)
|
|
2199
|
+
if (set[i].type == this)
|
|
2200
|
+
return set[i];
|
|
1930
2201
|
}
|
|
1931
2202
|
/**
|
|
1932
2203
|
@internal
|
|
1933
2204
|
*/
|
|
1934
|
-
checkAttrs(
|
|
1935
|
-
|
|
2205
|
+
checkAttrs(attrs) {
|
|
2206
|
+
checkAttrs(this.attrs, attrs, "mark", this.name);
|
|
1936
2207
|
}
|
|
1937
2208
|
/**
|
|
1938
2209
|
Queries whether a given mark type is
|
|
1939
2210
|
[excluded](https://prosemirror.net/docs/ref/#model.MarkSpec.excludes) by this one.
|
|
1940
2211
|
*/
|
|
1941
|
-
excludes(
|
|
1942
|
-
return this.excluded.indexOf(
|
|
2212
|
+
excludes(other) {
|
|
2213
|
+
return this.excluded.indexOf(other) > -1;
|
|
1943
2214
|
}
|
|
1944
2215
|
}
|
|
1945
|
-
class
|
|
2216
|
+
class Schema {
|
|
1946
2217
|
/**
|
|
1947
2218
|
Construct a schema from a schema [specification](https://prosemirror.net/docs/ref/#model.SchemaSpec).
|
|
1948
2219
|
*/
|
|
1949
|
-
constructor(
|
|
1950
|
-
this.linebreakReplacement = null
|
|
1951
|
-
|
|
1952
|
-
|
|
1953
|
-
|
|
1954
|
-
|
|
1955
|
-
|
|
1956
|
-
|
|
1957
|
-
|
|
1958
|
-
|
|
1959
|
-
|
|
1960
|
-
|
|
2220
|
+
constructor(spec) {
|
|
2221
|
+
this.linebreakReplacement = null;
|
|
2222
|
+
this.cached = /* @__PURE__ */ Object.create(null);
|
|
2223
|
+
let instanceSpec = this.spec = {};
|
|
2224
|
+
for (let prop in spec)
|
|
2225
|
+
instanceSpec[prop] = spec[prop];
|
|
2226
|
+
instanceSpec.nodes = OrderedMap.from(spec.nodes), instanceSpec.marks = OrderedMap.from(spec.marks || {}), this.nodes = NodeType.compile(this.spec.nodes, this);
|
|
2227
|
+
this.marks = MarkType.compile(this.spec.marks, this);
|
|
2228
|
+
let contentExprCache = /* @__PURE__ */ Object.create(null);
|
|
2229
|
+
for (let prop in this.nodes) {
|
|
2230
|
+
if (prop in this.marks)
|
|
2231
|
+
throw new RangeError(prop + " can not be both a node and a mark");
|
|
2232
|
+
let type = this.nodes[prop], contentExpr = type.spec.content || "", markExpr = type.spec.marks;
|
|
2233
|
+
type.contentMatch = contentExprCache[contentExpr] || (contentExprCache[contentExpr] = ContentMatch.parse(contentExpr, this.nodes));
|
|
2234
|
+
type.inlineContent = type.contentMatch.inlineContent;
|
|
2235
|
+
if (type.spec.linebreakReplacement) {
|
|
1961
2236
|
if (this.linebreakReplacement)
|
|
1962
2237
|
throw new RangeError("Multiple linebreak nodes defined");
|
|
1963
|
-
if (!
|
|
2238
|
+
if (!type.isInline || !type.isLeaf)
|
|
1964
2239
|
throw new RangeError("Linebreak replacement nodes must be inline leaf nodes");
|
|
1965
|
-
this.linebreakReplacement =
|
|
2240
|
+
this.linebreakReplacement = type;
|
|
1966
2241
|
}
|
|
1967
|
-
|
|
2242
|
+
type.markSet = markExpr == "_" ? null : markExpr ? gatherMarks(this, markExpr.split(" ")) : markExpr == "" || !type.inlineContent ? [] : null;
|
|
1968
2243
|
}
|
|
1969
|
-
for (let
|
|
1970
|
-
let
|
|
1971
|
-
|
|
2244
|
+
for (let prop in this.marks) {
|
|
2245
|
+
let type = this.marks[prop], excl = type.spec.excludes;
|
|
2246
|
+
type.excluded = excl == null ? [type] : excl == "" ? [] : gatherMarks(this, excl.split(" "));
|
|
1972
2247
|
}
|
|
1973
|
-
this.nodeFromJSON = this.nodeFromJSON.bind(this)
|
|
2248
|
+
this.nodeFromJSON = this.nodeFromJSON.bind(this);
|
|
2249
|
+
this.markFromJSON = this.markFromJSON.bind(this);
|
|
2250
|
+
this.topNodeType = this.nodes[this.spec.topNode || "doc"];
|
|
2251
|
+
this.cached.wrappings = /* @__PURE__ */ Object.create(null);
|
|
1974
2252
|
}
|
|
1975
2253
|
/**
|
|
1976
2254
|
Create a node in this schema. The `type` may be a string or a
|
|
@@ -1978,103 +2256,114 @@ class qt {
|
|
|
1978
2256
|
`content` may be a `Fragment`, `null`, a `Node`, or an array of
|
|
1979
2257
|
nodes.
|
|
1980
2258
|
*/
|
|
1981
|
-
node(
|
|
1982
|
-
if (typeof
|
|
1983
|
-
|
|
1984
|
-
else if (
|
|
1985
|
-
|
|
1986
|
-
|
|
1987
|
-
|
|
1988
|
-
return
|
|
2259
|
+
node(type, attrs = null, content, marks) {
|
|
2260
|
+
if (typeof type == "string")
|
|
2261
|
+
type = this.nodeType(type);
|
|
2262
|
+
else if (!(type instanceof NodeType))
|
|
2263
|
+
throw new RangeError("Invalid node type: " + type);
|
|
2264
|
+
else if (type.schema != this)
|
|
2265
|
+
throw new RangeError("Node type from different schema used (" + type.name + ")");
|
|
2266
|
+
return type.createChecked(attrs, content, marks);
|
|
1989
2267
|
}
|
|
1990
2268
|
/**
|
|
1991
2269
|
Create a text node in the schema. Empty text nodes are not
|
|
1992
2270
|
allowed.
|
|
1993
2271
|
*/
|
|
1994
|
-
text(
|
|
1995
|
-
let
|
|
1996
|
-
return new
|
|
2272
|
+
text(text, marks) {
|
|
2273
|
+
let type = this.nodes.text;
|
|
2274
|
+
return new TextNode(type, type.defaultAttrs, text, Mark.setFrom(marks));
|
|
1997
2275
|
}
|
|
1998
2276
|
/**
|
|
1999
2277
|
Create a mark with the given type and attributes.
|
|
2000
2278
|
*/
|
|
2001
|
-
mark(
|
|
2002
|
-
|
|
2279
|
+
mark(type, attrs) {
|
|
2280
|
+
if (typeof type == "string")
|
|
2281
|
+
type = this.marks[type];
|
|
2282
|
+
return type.create(attrs);
|
|
2003
2283
|
}
|
|
2004
2284
|
/**
|
|
2005
2285
|
Deserialize a node from its JSON representation. This method is
|
|
2006
2286
|
bound.
|
|
2007
2287
|
*/
|
|
2008
|
-
nodeFromJSON(
|
|
2009
|
-
return
|
|
2288
|
+
nodeFromJSON(json) {
|
|
2289
|
+
return Node.fromJSON(this, json);
|
|
2010
2290
|
}
|
|
2011
2291
|
/**
|
|
2012
2292
|
Deserialize a mark from its JSON representation. This method is
|
|
2013
2293
|
bound.
|
|
2014
2294
|
*/
|
|
2015
|
-
markFromJSON(
|
|
2016
|
-
return
|
|
2295
|
+
markFromJSON(json) {
|
|
2296
|
+
return Mark.fromJSON(this, json);
|
|
2017
2297
|
}
|
|
2018
2298
|
/**
|
|
2019
2299
|
@internal
|
|
2020
2300
|
*/
|
|
2021
|
-
nodeType(
|
|
2022
|
-
let
|
|
2023
|
-
if (!
|
|
2024
|
-
throw new RangeError("Unknown node type: " +
|
|
2025
|
-
return
|
|
2301
|
+
nodeType(name) {
|
|
2302
|
+
let found2 = this.nodes[name];
|
|
2303
|
+
if (!found2)
|
|
2304
|
+
throw new RangeError("Unknown node type: " + name);
|
|
2305
|
+
return found2;
|
|
2026
2306
|
}
|
|
2027
2307
|
}
|
|
2028
|
-
function
|
|
2029
|
-
let
|
|
2030
|
-
for (let
|
|
2031
|
-
let
|
|
2032
|
-
if (
|
|
2033
|
-
|
|
2034
|
-
else
|
|
2035
|
-
for (let
|
|
2036
|
-
let
|
|
2037
|
-
(
|
|
2308
|
+
function gatherMarks(schema, marks) {
|
|
2309
|
+
let found2 = [];
|
|
2310
|
+
for (let i = 0; i < marks.length; i++) {
|
|
2311
|
+
let name = marks[i], mark = schema.marks[name], ok = mark;
|
|
2312
|
+
if (mark) {
|
|
2313
|
+
found2.push(mark);
|
|
2314
|
+
} else {
|
|
2315
|
+
for (let prop in schema.marks) {
|
|
2316
|
+
let mark2 = schema.marks[prop];
|
|
2317
|
+
if (name == "_" || mark2.spec.group && mark2.spec.group.split(" ").indexOf(name) > -1)
|
|
2318
|
+
found2.push(ok = mark2);
|
|
2038
2319
|
}
|
|
2039
|
-
|
|
2040
|
-
|
|
2320
|
+
}
|
|
2321
|
+
if (!ok)
|
|
2322
|
+
throw new SyntaxError("Unknown mark type: '" + marks[i] + "'");
|
|
2041
2323
|
}
|
|
2042
|
-
return
|
|
2324
|
+
return found2;
|
|
2043
2325
|
}
|
|
2044
|
-
function
|
|
2045
|
-
return
|
|
2326
|
+
function isTagRule(rule) {
|
|
2327
|
+
return rule.tag != null;
|
|
2046
2328
|
}
|
|
2047
|
-
function
|
|
2048
|
-
return
|
|
2329
|
+
function isStyleRule(rule) {
|
|
2330
|
+
return rule.style != null;
|
|
2049
2331
|
}
|
|
2050
|
-
class
|
|
2332
|
+
class DOMParser {
|
|
2051
2333
|
/**
|
|
2052
2334
|
Create a parser that targets the given schema, using the given
|
|
2053
2335
|
parsing rules.
|
|
2054
2336
|
*/
|
|
2055
|
-
constructor(
|
|
2056
|
-
this.schema =
|
|
2057
|
-
|
|
2058
|
-
|
|
2059
|
-
|
|
2060
|
-
|
|
2061
|
-
|
|
2062
|
-
|
|
2063
|
-
|
|
2337
|
+
constructor(schema, rules) {
|
|
2338
|
+
this.schema = schema;
|
|
2339
|
+
this.rules = rules;
|
|
2340
|
+
this.tags = [];
|
|
2341
|
+
this.styles = [];
|
|
2342
|
+
let matchedStyles = this.matchedStyles = [];
|
|
2343
|
+
rules.forEach((rule) => {
|
|
2344
|
+
if (isTagRule(rule)) {
|
|
2345
|
+
this.tags.push(rule);
|
|
2346
|
+
} else if (isStyleRule(rule)) {
|
|
2347
|
+
let prop = /[^=]*/.exec(rule.style)[0];
|
|
2348
|
+
if (matchedStyles.indexOf(prop) < 0)
|
|
2349
|
+
matchedStyles.push(prop);
|
|
2350
|
+
this.styles.push(rule);
|
|
2064
2351
|
}
|
|
2065
|
-
})
|
|
2066
|
-
|
|
2067
|
-
|
|
2068
|
-
|
|
2069
|
-
|
|
2352
|
+
});
|
|
2353
|
+
this.normalizeLists = !this.tags.some((r) => {
|
|
2354
|
+
if (!/^(ul|ol)\b/.test(r.tag) || !r.node)
|
|
2355
|
+
return false;
|
|
2356
|
+
let node = schema.nodes[r.node];
|
|
2357
|
+
return node.contentMatch.matchType(node);
|
|
2070
2358
|
});
|
|
2071
2359
|
}
|
|
2072
2360
|
/**
|
|
2073
2361
|
Parse a document from the content of a DOM node.
|
|
2074
2362
|
*/
|
|
2075
|
-
parse(
|
|
2076
|
-
let
|
|
2077
|
-
|
|
2363
|
+
parse(dom, options = {}) {
|
|
2364
|
+
let context = new ParseContext(this, options, false);
|
|
2365
|
+
context.addAll(dom, Mark.none, options.from, options.to);
|
|
2366
|
+
return context.finish();
|
|
2078
2367
|
}
|
|
2079
2368
|
/**
|
|
2080
2369
|
Parses the content of the given DOM node, like
|
|
@@ -2084,166 +2373,212 @@ class P {
|
|
|
2084
2373
|
the schema constraints aren't applied to the start of nodes to
|
|
2085
2374
|
the left of the input and the end of nodes at the end.
|
|
2086
2375
|
*/
|
|
2087
|
-
parseSlice(
|
|
2088
|
-
let
|
|
2089
|
-
|
|
2376
|
+
parseSlice(dom, options = {}) {
|
|
2377
|
+
let context = new ParseContext(this, options, true);
|
|
2378
|
+
context.addAll(dom, Mark.none, options.from, options.to);
|
|
2379
|
+
return Slice.maxOpen(context.finish());
|
|
2090
2380
|
}
|
|
2091
2381
|
/**
|
|
2092
2382
|
@internal
|
|
2093
2383
|
*/
|
|
2094
|
-
matchTag(
|
|
2095
|
-
for (let i =
|
|
2096
|
-
let
|
|
2097
|
-
if (
|
|
2098
|
-
if (
|
|
2099
|
-
let
|
|
2100
|
-
if (
|
|
2384
|
+
matchTag(dom, context, after) {
|
|
2385
|
+
for (let i = after ? this.tags.indexOf(after) + 1 : 0; i < this.tags.length; i++) {
|
|
2386
|
+
let rule = this.tags[i];
|
|
2387
|
+
if (matches(dom, rule.tag) && (rule.namespace === void 0 || dom.namespaceURI == rule.namespace) && (!rule.context || context.matchesContext(rule.context))) {
|
|
2388
|
+
if (rule.getAttrs) {
|
|
2389
|
+
let result = rule.getAttrs(dom);
|
|
2390
|
+
if (result === false)
|
|
2101
2391
|
continue;
|
|
2102
|
-
|
|
2392
|
+
rule.attrs = result || void 0;
|
|
2103
2393
|
}
|
|
2104
|
-
return
|
|
2394
|
+
return rule;
|
|
2105
2395
|
}
|
|
2106
2396
|
}
|
|
2107
2397
|
}
|
|
2108
2398
|
/**
|
|
2109
2399
|
@internal
|
|
2110
2400
|
*/
|
|
2111
|
-
matchStyle(
|
|
2112
|
-
for (let
|
|
2113
|
-
let
|
|
2114
|
-
if (
|
|
2401
|
+
matchStyle(prop, value, context, after) {
|
|
2402
|
+
for (let i = after ? this.styles.indexOf(after) + 1 : 0; i < this.styles.length; i++) {
|
|
2403
|
+
let rule = this.styles[i], style = rule.style;
|
|
2404
|
+
if (style.indexOf(prop) != 0 || rule.context && !context.matchesContext(rule.context) || // Test that the style string either precisely matches the prop,
|
|
2115
2405
|
// or has an '=' sign after the prop, followed by the given
|
|
2116
2406
|
// value.
|
|
2117
|
-
|
|
2118
|
-
|
|
2119
|
-
|
|
2120
|
-
|
|
2121
|
-
|
|
2122
|
-
|
|
2123
|
-
|
|
2124
|
-
return s;
|
|
2407
|
+
style.length > prop.length && (style.charCodeAt(prop.length) != 61 || style.slice(prop.length + 1) != value))
|
|
2408
|
+
continue;
|
|
2409
|
+
if (rule.getAttrs) {
|
|
2410
|
+
let result = rule.getAttrs(value);
|
|
2411
|
+
if (result === false)
|
|
2412
|
+
continue;
|
|
2413
|
+
rule.attrs = result || void 0;
|
|
2125
2414
|
}
|
|
2415
|
+
return rule;
|
|
2126
2416
|
}
|
|
2127
2417
|
}
|
|
2128
2418
|
/**
|
|
2129
2419
|
@internal
|
|
2130
2420
|
*/
|
|
2131
|
-
static schemaRules(
|
|
2132
|
-
let
|
|
2133
|
-
function
|
|
2134
|
-
let
|
|
2135
|
-
for (;
|
|
2136
|
-
let
|
|
2137
|
-
if (
|
|
2421
|
+
static schemaRules(schema) {
|
|
2422
|
+
let result = [];
|
|
2423
|
+
function insert(rule) {
|
|
2424
|
+
let priority = rule.priority == null ? 50 : rule.priority, i = 0;
|
|
2425
|
+
for (; i < result.length; i++) {
|
|
2426
|
+
let next = result[i], nextPriority = next.priority == null ? 50 : next.priority;
|
|
2427
|
+
if (nextPriority < priority)
|
|
2138
2428
|
break;
|
|
2139
2429
|
}
|
|
2140
|
-
|
|
2430
|
+
result.splice(i, 0, rule);
|
|
2141
2431
|
}
|
|
2142
|
-
for (let
|
|
2143
|
-
let
|
|
2144
|
-
|
|
2145
|
-
|
|
2146
|
-
|
|
2432
|
+
for (let name in schema.marks) {
|
|
2433
|
+
let rules = schema.marks[name].spec.parseDOM;
|
|
2434
|
+
if (rules)
|
|
2435
|
+
rules.forEach((rule) => {
|
|
2436
|
+
insert(rule = copy(rule));
|
|
2437
|
+
if (!(rule.mark || rule.ignore || rule.clearMark))
|
|
2438
|
+
rule.mark = name;
|
|
2439
|
+
});
|
|
2147
2440
|
}
|
|
2148
|
-
for (let
|
|
2149
|
-
let
|
|
2150
|
-
|
|
2151
|
-
|
|
2152
|
-
|
|
2441
|
+
for (let name in schema.nodes) {
|
|
2442
|
+
let rules = schema.nodes[name].spec.parseDOM;
|
|
2443
|
+
if (rules)
|
|
2444
|
+
rules.forEach((rule) => {
|
|
2445
|
+
insert(rule = copy(rule));
|
|
2446
|
+
if (!(rule.node || rule.ignore || rule.mark))
|
|
2447
|
+
rule.node = name;
|
|
2448
|
+
});
|
|
2153
2449
|
}
|
|
2154
|
-
return
|
|
2450
|
+
return result;
|
|
2155
2451
|
}
|
|
2156
2452
|
/**
|
|
2157
2453
|
Construct a DOM parser using the parsing rules listed in a
|
|
2158
2454
|
schema's [node specs](https://prosemirror.net/docs/ref/#model.NodeSpec.parseDOM), reordered by
|
|
2159
2455
|
[priority](https://prosemirror.net/docs/ref/#model.ParseRule.priority).
|
|
2160
2456
|
*/
|
|
2161
|
-
static fromSchema(
|
|
2162
|
-
return
|
|
2163
|
-
}
|
|
2164
|
-
}
|
|
2165
|
-
const
|
|
2166
|
-
address:
|
|
2167
|
-
article:
|
|
2168
|
-
aside:
|
|
2169
|
-
blockquote:
|
|
2170
|
-
canvas:
|
|
2171
|
-
dd:
|
|
2172
|
-
div:
|
|
2173
|
-
dl:
|
|
2174
|
-
fieldset:
|
|
2175
|
-
figcaption:
|
|
2176
|
-
figure:
|
|
2177
|
-
footer:
|
|
2178
|
-
form:
|
|
2179
|
-
h1:
|
|
2180
|
-
h2:
|
|
2181
|
-
h3:
|
|
2182
|
-
h4:
|
|
2183
|
-
h5:
|
|
2184
|
-
h6:
|
|
2185
|
-
header:
|
|
2186
|
-
hgroup:
|
|
2187
|
-
hr:
|
|
2188
|
-
li:
|
|
2189
|
-
noscript:
|
|
2190
|
-
ol:
|
|
2191
|
-
output:
|
|
2192
|
-
p:
|
|
2193
|
-
pre:
|
|
2194
|
-
section:
|
|
2195
|
-
table:
|
|
2196
|
-
tfoot:
|
|
2197
|
-
ul:
|
|
2198
|
-
}
|
|
2199
|
-
|
|
2200
|
-
|
|
2201
|
-
|
|
2202
|
-
|
|
2203
|
-
|
|
2204
|
-
|
|
2205
|
-
|
|
2206
|
-
|
|
2207
|
-
|
|
2208
|
-
|
|
2209
|
-
|
|
2210
|
-
|
|
2211
|
-
|
|
2212
|
-
|
|
2213
|
-
|
|
2457
|
+
static fromSchema(schema) {
|
|
2458
|
+
return schema.cached.domParser || (schema.cached.domParser = new DOMParser(schema, DOMParser.schemaRules(schema)));
|
|
2459
|
+
}
|
|
2460
|
+
}
|
|
2461
|
+
const blockTags = {
|
|
2462
|
+
address: true,
|
|
2463
|
+
article: true,
|
|
2464
|
+
aside: true,
|
|
2465
|
+
blockquote: true,
|
|
2466
|
+
canvas: true,
|
|
2467
|
+
dd: true,
|
|
2468
|
+
div: true,
|
|
2469
|
+
dl: true,
|
|
2470
|
+
fieldset: true,
|
|
2471
|
+
figcaption: true,
|
|
2472
|
+
figure: true,
|
|
2473
|
+
footer: true,
|
|
2474
|
+
form: true,
|
|
2475
|
+
h1: true,
|
|
2476
|
+
h2: true,
|
|
2477
|
+
h3: true,
|
|
2478
|
+
h4: true,
|
|
2479
|
+
h5: true,
|
|
2480
|
+
h6: true,
|
|
2481
|
+
header: true,
|
|
2482
|
+
hgroup: true,
|
|
2483
|
+
hr: true,
|
|
2484
|
+
li: true,
|
|
2485
|
+
noscript: true,
|
|
2486
|
+
ol: true,
|
|
2487
|
+
output: true,
|
|
2488
|
+
p: true,
|
|
2489
|
+
pre: true,
|
|
2490
|
+
section: true,
|
|
2491
|
+
table: true,
|
|
2492
|
+
tfoot: true,
|
|
2493
|
+
ul: true
|
|
2494
|
+
};
|
|
2495
|
+
const ignoreTags = {
|
|
2496
|
+
head: true,
|
|
2497
|
+
noscript: true,
|
|
2498
|
+
object: true,
|
|
2499
|
+
script: true,
|
|
2500
|
+
style: true,
|
|
2501
|
+
title: true
|
|
2502
|
+
};
|
|
2503
|
+
const listTags = { ol: true, ul: true };
|
|
2504
|
+
const OPT_PRESERVE_WS = 1, OPT_PRESERVE_WS_FULL = 2, OPT_OPEN_LEFT = 4;
|
|
2505
|
+
function wsOptionsFor(type, preserveWhitespace, base) {
|
|
2506
|
+
if (preserveWhitespace != null)
|
|
2507
|
+
return (preserveWhitespace ? OPT_PRESERVE_WS : 0) | (preserveWhitespace === "full" ? OPT_PRESERVE_WS_FULL : 0);
|
|
2508
|
+
return type && type.whitespace == "pre" ? OPT_PRESERVE_WS | OPT_PRESERVE_WS_FULL : base & -5;
|
|
2509
|
+
}
|
|
2510
|
+
class NodeContext {
|
|
2511
|
+
constructor(type, attrs, marks, solid, match, options) {
|
|
2512
|
+
this.type = type;
|
|
2513
|
+
this.attrs = attrs;
|
|
2514
|
+
this.marks = marks;
|
|
2515
|
+
this.solid = solid;
|
|
2516
|
+
this.options = options;
|
|
2517
|
+
this.content = [];
|
|
2518
|
+
this.activeMarks = Mark.none;
|
|
2519
|
+
this.match = match || (options & OPT_OPEN_LEFT ? null : type.contentMatch);
|
|
2520
|
+
}
|
|
2521
|
+
findWrapping(node) {
|
|
2214
2522
|
if (!this.match) {
|
|
2215
2523
|
if (!this.type)
|
|
2216
2524
|
return [];
|
|
2217
|
-
let
|
|
2218
|
-
if (
|
|
2219
|
-
this.match = this.type.contentMatch.matchFragment(
|
|
2220
|
-
else {
|
|
2221
|
-
let
|
|
2222
|
-
|
|
2525
|
+
let fill = this.type.contentMatch.fillBefore(Fragment.from(node));
|
|
2526
|
+
if (fill) {
|
|
2527
|
+
this.match = this.type.contentMatch.matchFragment(fill);
|
|
2528
|
+
} else {
|
|
2529
|
+
let start = this.type.contentMatch, wrap;
|
|
2530
|
+
if (wrap = start.findWrapping(node.type)) {
|
|
2531
|
+
this.match = start;
|
|
2532
|
+
return wrap;
|
|
2533
|
+
} else {
|
|
2534
|
+
return null;
|
|
2535
|
+
}
|
|
2223
2536
|
}
|
|
2224
2537
|
}
|
|
2225
|
-
return this.match.findWrapping(
|
|
2226
|
-
}
|
|
2227
|
-
finish(
|
|
2228
|
-
if (!(this.options &
|
|
2229
|
-
let
|
|
2230
|
-
if (
|
|
2231
|
-
let
|
|
2232
|
-
|
|
2538
|
+
return this.match.findWrapping(node.type);
|
|
2539
|
+
}
|
|
2540
|
+
finish(openEnd) {
|
|
2541
|
+
if (!(this.options & OPT_PRESERVE_WS)) {
|
|
2542
|
+
let last = this.content[this.content.length - 1], m;
|
|
2543
|
+
if (last && last.isText && (m = /[ \t\r\n\u000c]+$/.exec(last.text))) {
|
|
2544
|
+
let text = last;
|
|
2545
|
+
if (last.text.length == m[0].length)
|
|
2546
|
+
this.content.pop();
|
|
2547
|
+
else
|
|
2548
|
+
this.content[this.content.length - 1] = text.withText(text.text.slice(0, text.text.length - m[0].length));
|
|
2233
2549
|
}
|
|
2234
2550
|
}
|
|
2235
|
-
let
|
|
2236
|
-
|
|
2237
|
-
|
|
2238
|
-
|
|
2239
|
-
|
|
2240
|
-
|
|
2241
|
-
|
|
2242
|
-
|
|
2243
|
-
|
|
2244
|
-
|
|
2245
|
-
|
|
2246
|
-
|
|
2551
|
+
let content = Fragment.from(this.content);
|
|
2552
|
+
if (!openEnd && this.match)
|
|
2553
|
+
content = content.append(this.match.fillBefore(Fragment.empty, true));
|
|
2554
|
+
return this.type ? this.type.create(this.attrs, content, this.marks) : content;
|
|
2555
|
+
}
|
|
2556
|
+
inlineContext(node) {
|
|
2557
|
+
if (this.type)
|
|
2558
|
+
return this.type.inlineContent;
|
|
2559
|
+
if (this.content.length)
|
|
2560
|
+
return this.content[0].isInline;
|
|
2561
|
+
return node.parentNode && !blockTags.hasOwnProperty(node.parentNode.nodeName.toLowerCase());
|
|
2562
|
+
}
|
|
2563
|
+
}
|
|
2564
|
+
class ParseContext {
|
|
2565
|
+
constructor(parser, options, isOpen) {
|
|
2566
|
+
this.parser = parser;
|
|
2567
|
+
this.options = options;
|
|
2568
|
+
this.isOpen = isOpen;
|
|
2569
|
+
this.open = 0;
|
|
2570
|
+
this.localPreserveWS = false;
|
|
2571
|
+
let topNode = options.topNode, topContext;
|
|
2572
|
+
let topOptions = wsOptionsFor(null, options.preserveWhitespace, 0) | (isOpen ? OPT_OPEN_LEFT : 0);
|
|
2573
|
+
if (topNode)
|
|
2574
|
+
topContext = new NodeContext(topNode.type, topNode.attrs, Mark.none, true, options.topMatch || topNode.type.contentMatch, topOptions);
|
|
2575
|
+
else if (isOpen)
|
|
2576
|
+
topContext = new NodeContext(null, null, Mark.none, true, null, topOptions);
|
|
2577
|
+
else
|
|
2578
|
+
topContext = new NodeContext(parser.schema.topNodeType, null, Mark.none, true, null, topOptions);
|
|
2579
|
+
this.nodes = [topContext];
|
|
2580
|
+
this.find = options.findPositions;
|
|
2581
|
+
this.needsBlock = false;
|
|
2247
2582
|
}
|
|
2248
2583
|
get top() {
|
|
2249
2584
|
return this.nodes[this.open];
|
|
@@ -2251,302 +2586,404 @@ class G {
|
|
|
2251
2586
|
// Add a DOM node to the content. Text is inserted as text node,
|
|
2252
2587
|
// otherwise, the node is passed to `addElement` or, if it has a
|
|
2253
2588
|
// `style` attribute, `addElementWithStyles`.
|
|
2254
|
-
addDOM(
|
|
2255
|
-
|
|
2256
|
-
|
|
2257
|
-
|
|
2258
|
-
|
|
2259
|
-
|
|
2260
|
-
|
|
2261
|
-
|
|
2262
|
-
|
|
2263
|
-
|
|
2264
|
-
|
|
2265
|
-
|
|
2589
|
+
addDOM(dom, marks) {
|
|
2590
|
+
if (dom.nodeType == 3)
|
|
2591
|
+
this.addTextNode(dom, marks);
|
|
2592
|
+
else if (dom.nodeType == 1)
|
|
2593
|
+
this.addElement(dom, marks);
|
|
2594
|
+
}
|
|
2595
|
+
addTextNode(dom, marks) {
|
|
2596
|
+
let value = dom.nodeValue;
|
|
2597
|
+
let top = this.top, preserveWS = top.options & OPT_PRESERVE_WS_FULL ? "full" : this.localPreserveWS || (top.options & OPT_PRESERVE_WS) > 0;
|
|
2598
|
+
if (preserveWS === "full" || top.inlineContext(dom) || /[^ \t\r\n\u000c]/.test(value)) {
|
|
2599
|
+
if (!preserveWS) {
|
|
2600
|
+
value = value.replace(/[ \t\r\n\u000c]+/g, " ");
|
|
2601
|
+
if (/^[ \t\r\n\u000c]/.test(value) && this.open == this.nodes.length - 1) {
|
|
2602
|
+
let nodeBefore = top.content[top.content.length - 1];
|
|
2603
|
+
let domNodeBefore = dom.previousSibling;
|
|
2604
|
+
if (!nodeBefore || domNodeBefore && domNodeBefore.nodeName == "BR" || nodeBefore.isText && /[ \t\r\n\u000c]$/.test(nodeBefore.text))
|
|
2605
|
+
value = value.slice(1);
|
|
2606
|
+
}
|
|
2607
|
+
} else if (preserveWS !== "full") {
|
|
2608
|
+
value = value.replace(/\r?\n|\r/g, " ");
|
|
2609
|
+
} else {
|
|
2610
|
+
value = value.replace(/\r\n?/g, "\n");
|
|
2266
2611
|
}
|
|
2267
|
-
|
|
2268
|
-
|
|
2269
|
-
this.
|
|
2612
|
+
if (value)
|
|
2613
|
+
this.insertNode(this.parser.schema.text(value), marks, !/\S/.test(value));
|
|
2614
|
+
this.findInText(dom);
|
|
2615
|
+
} else {
|
|
2616
|
+
this.findInside(dom);
|
|
2617
|
+
}
|
|
2270
2618
|
}
|
|
2271
2619
|
// Try to find a handler for the given tag and use that to parse. If
|
|
2272
2620
|
// none is found, the element's content nodes are added directly.
|
|
2273
|
-
addElement(
|
|
2274
|
-
let
|
|
2275
|
-
(
|
|
2276
|
-
|
|
2277
|
-
|
|
2278
|
-
|
|
2279
|
-
|
|
2280
|
-
|
|
2281
|
-
|
|
2282
|
-
|
|
2283
|
-
|
|
2284
|
-
|
|
2285
|
-
|
|
2286
|
-
|
|
2287
|
-
|
|
2288
|
-
|
|
2621
|
+
addElement(dom, marks, matchAfter) {
|
|
2622
|
+
let outerWS = this.localPreserveWS, top = this.top;
|
|
2623
|
+
if (dom.tagName == "PRE" || /pre/.test(dom.style && dom.style.whiteSpace))
|
|
2624
|
+
this.localPreserveWS = true;
|
|
2625
|
+
let name = dom.nodeName.toLowerCase(), ruleID;
|
|
2626
|
+
if (listTags.hasOwnProperty(name) && this.parser.normalizeLists)
|
|
2627
|
+
normalizeList(dom);
|
|
2628
|
+
let rule = this.options.ruleFromNode && this.options.ruleFromNode(dom) || (ruleID = this.parser.matchTag(dom, this, matchAfter));
|
|
2629
|
+
out: if (rule ? rule.ignore : ignoreTags.hasOwnProperty(name)) {
|
|
2630
|
+
this.findInside(dom);
|
|
2631
|
+
this.ignoreFallback(dom, marks);
|
|
2632
|
+
} else if (!rule || rule.skip || rule.closeParent) {
|
|
2633
|
+
if (rule && rule.closeParent)
|
|
2634
|
+
this.open = Math.max(0, this.open - 1);
|
|
2635
|
+
else if (rule && rule.skip.nodeType)
|
|
2636
|
+
dom = rule.skip;
|
|
2637
|
+
let sync, oldNeedsBlock = this.needsBlock;
|
|
2638
|
+
if (blockTags.hasOwnProperty(name)) {
|
|
2639
|
+
if (top.content.length && top.content[0].isInline && this.open) {
|
|
2640
|
+
this.open--;
|
|
2641
|
+
top = this.top;
|
|
2642
|
+
}
|
|
2643
|
+
sync = true;
|
|
2644
|
+
if (!top.type)
|
|
2645
|
+
this.needsBlock = true;
|
|
2646
|
+
} else if (!dom.firstChild) {
|
|
2647
|
+
this.leafFallback(dom, marks);
|
|
2648
|
+
break out;
|
|
2289
2649
|
}
|
|
2290
|
-
let
|
|
2291
|
-
|
|
2650
|
+
let innerMarks = rule && rule.skip ? marks : this.readStyles(dom, marks);
|
|
2651
|
+
if (innerMarks)
|
|
2652
|
+
this.addAll(dom, innerMarks);
|
|
2653
|
+
if (sync)
|
|
2654
|
+
this.sync(top);
|
|
2655
|
+
this.needsBlock = oldNeedsBlock;
|
|
2292
2656
|
} else {
|
|
2293
|
-
let
|
|
2294
|
-
|
|
2657
|
+
let innerMarks = this.readStyles(dom, marks);
|
|
2658
|
+
if (innerMarks)
|
|
2659
|
+
this.addElementByRule(dom, rule, innerMarks, rule.consuming === false ? ruleID : void 0);
|
|
2295
2660
|
}
|
|
2296
|
-
this.localPreserveWS =
|
|
2661
|
+
this.localPreserveWS = outerWS;
|
|
2297
2662
|
}
|
|
2298
2663
|
// Called for leaf DOM nodes that would otherwise be ignored
|
|
2299
|
-
leafFallback(
|
|
2300
|
-
|
|
2301
|
-
|
|
2664
|
+
leafFallback(dom, marks) {
|
|
2665
|
+
if (dom.nodeName == "BR" && this.top.type && this.top.type.inlineContent)
|
|
2666
|
+
this.addTextNode(dom.ownerDocument.createTextNode("\n"), marks);
|
|
2302
2667
|
}
|
|
2303
2668
|
// Called for ignored nodes
|
|
2304
|
-
ignoreFallback(
|
|
2305
|
-
|
|
2669
|
+
ignoreFallback(dom, marks) {
|
|
2670
|
+
if (dom.nodeName == "BR" && (!this.top.type || !this.top.type.inlineContent))
|
|
2671
|
+
this.findPlace(this.parser.schema.text("-"), marks, true);
|
|
2306
2672
|
}
|
|
2307
2673
|
// Run any style parser associated with the node's styles. Either
|
|
2308
2674
|
// return an updated array of marks, or null to indicate some of the
|
|
2309
2675
|
// styles had a rule with `ignore` set.
|
|
2310
|
-
readStyles(
|
|
2311
|
-
let
|
|
2312
|
-
if (
|
|
2676
|
+
readStyles(dom, marks) {
|
|
2677
|
+
let styles = dom.style;
|
|
2678
|
+
if (styles && styles.length)
|
|
2313
2679
|
for (let i = 0; i < this.parser.matchedStyles.length; i++) {
|
|
2314
|
-
let
|
|
2315
|
-
if (
|
|
2316
|
-
for (let
|
|
2317
|
-
let
|
|
2318
|
-
if (!
|
|
2680
|
+
let name = this.parser.matchedStyles[i], value = styles.getPropertyValue(name);
|
|
2681
|
+
if (value)
|
|
2682
|
+
for (let after = void 0; ; ) {
|
|
2683
|
+
let rule = this.parser.matchStyle(name, value, this, after);
|
|
2684
|
+
if (!rule)
|
|
2319
2685
|
break;
|
|
2320
|
-
if (
|
|
2686
|
+
if (rule.ignore)
|
|
2321
2687
|
return null;
|
|
2322
|
-
if (
|
|
2323
|
-
|
|
2688
|
+
if (rule.clearMark)
|
|
2689
|
+
marks = marks.filter((m) => !rule.clearMark(m));
|
|
2690
|
+
else
|
|
2691
|
+
marks = marks.concat(this.parser.schema.marks[rule.mark].create(rule.attrs));
|
|
2692
|
+
if (rule.consuming === false)
|
|
2693
|
+
after = rule;
|
|
2324
2694
|
else
|
|
2325
2695
|
break;
|
|
2326
2696
|
}
|
|
2327
2697
|
}
|
|
2328
|
-
return
|
|
2698
|
+
return marks;
|
|
2329
2699
|
}
|
|
2330
2700
|
// Look up a handler for the given node. If none are found, return
|
|
2331
2701
|
// false. Otherwise, apply it, use its return value to drive the way
|
|
2332
2702
|
// the node's content is wrapped, and return true.
|
|
2333
|
-
addElementByRule(
|
|
2334
|
-
let
|
|
2335
|
-
if (
|
|
2336
|
-
|
|
2337
|
-
|
|
2338
|
-
|
|
2339
|
-
|
|
2340
|
-
|
|
2703
|
+
addElementByRule(dom, rule, marks, continueAfter) {
|
|
2704
|
+
let sync, nodeType;
|
|
2705
|
+
if (rule.node) {
|
|
2706
|
+
nodeType = this.parser.schema.nodes[rule.node];
|
|
2707
|
+
if (!nodeType.isLeaf) {
|
|
2708
|
+
let inner = this.enter(nodeType, rule.attrs || null, marks, rule.preserveWhitespace);
|
|
2709
|
+
if (inner) {
|
|
2710
|
+
sync = true;
|
|
2711
|
+
marks = inner;
|
|
2712
|
+
}
|
|
2713
|
+
} else if (!this.insertNode(nodeType.create(rule.attrs), marks, dom.nodeName == "BR")) {
|
|
2714
|
+
this.leafFallback(dom, marks);
|
|
2341
2715
|
}
|
|
2342
|
-
else {
|
|
2343
|
-
let
|
|
2344
|
-
|
|
2716
|
+
} else {
|
|
2717
|
+
let markType = this.parser.schema.marks[rule.mark];
|
|
2718
|
+
marks = marks.concat(markType.create(rule.attrs));
|
|
2345
2719
|
}
|
|
2346
|
-
let
|
|
2347
|
-
if (
|
|
2348
|
-
this.findInside(
|
|
2349
|
-
else if (
|
|
2350
|
-
this.addElement(
|
|
2351
|
-
else if (
|
|
2352
|
-
this.findInside(
|
|
2353
|
-
|
|
2354
|
-
|
|
2355
|
-
|
|
2720
|
+
let startIn = this.top;
|
|
2721
|
+
if (nodeType && nodeType.isLeaf) {
|
|
2722
|
+
this.findInside(dom);
|
|
2723
|
+
} else if (continueAfter) {
|
|
2724
|
+
this.addElement(dom, marks, continueAfter);
|
|
2725
|
+
} else if (rule.getContent) {
|
|
2726
|
+
this.findInside(dom);
|
|
2727
|
+
rule.getContent(dom, this.parser.schema).forEach((node) => this.insertNode(node, marks, false));
|
|
2728
|
+
} else {
|
|
2729
|
+
let contentDOM = dom;
|
|
2730
|
+
if (typeof rule.contentElement == "string")
|
|
2731
|
+
contentDOM = dom.querySelector(rule.contentElement);
|
|
2732
|
+
else if (typeof rule.contentElement == "function")
|
|
2733
|
+
contentDOM = rule.contentElement(dom);
|
|
2734
|
+
else if (rule.contentElement)
|
|
2735
|
+
contentDOM = rule.contentElement;
|
|
2736
|
+
this.findAround(dom, contentDOM, true);
|
|
2737
|
+
this.addAll(contentDOM, marks);
|
|
2738
|
+
this.findAround(dom, contentDOM, false);
|
|
2356
2739
|
}
|
|
2357
|
-
|
|
2740
|
+
if (sync && this.sync(startIn))
|
|
2741
|
+
this.open--;
|
|
2358
2742
|
}
|
|
2359
2743
|
// Add all child nodes between `startIndex` and `endIndex` (or the
|
|
2360
2744
|
// whole node, if not given). If `sync` is passed, use it to
|
|
2361
2745
|
// synchronize after every block element.
|
|
2362
|
-
addAll(
|
|
2363
|
-
let
|
|
2364
|
-
for (let
|
|
2365
|
-
this.findAtPoint(
|
|
2366
|
-
|
|
2746
|
+
addAll(parent, marks, startIndex, endIndex) {
|
|
2747
|
+
let index = startIndex || 0;
|
|
2748
|
+
for (let dom = startIndex ? parent.childNodes[startIndex] : parent.firstChild, end = endIndex == null ? null : parent.childNodes[endIndex]; dom != end; dom = dom.nextSibling, ++index) {
|
|
2749
|
+
this.findAtPoint(parent, index);
|
|
2750
|
+
this.addDOM(dom, marks);
|
|
2751
|
+
}
|
|
2752
|
+
this.findAtPoint(parent, index);
|
|
2367
2753
|
}
|
|
2368
2754
|
// Try to find a way to fit the given node type into the current
|
|
2369
2755
|
// context. May add intermediate wrappers and/or leave non-solid
|
|
2370
2756
|
// nodes that we're in.
|
|
2371
|
-
findPlace(
|
|
2372
|
-
let
|
|
2373
|
-
for (let
|
|
2374
|
-
let
|
|
2375
|
-
|
|
2376
|
-
|
|
2377
|
-
|
|
2378
|
-
|
|
2757
|
+
findPlace(node, marks, cautious) {
|
|
2758
|
+
let route, sync;
|
|
2759
|
+
for (let depth = this.open, penalty = 0; depth >= 0; depth--) {
|
|
2760
|
+
let cx = this.nodes[depth];
|
|
2761
|
+
let found2 = cx.findWrapping(node);
|
|
2762
|
+
if (found2 && (!route || route.length > found2.length + penalty)) {
|
|
2763
|
+
route = found2;
|
|
2764
|
+
sync = cx;
|
|
2765
|
+
if (!found2.length)
|
|
2379
2766
|
break;
|
|
2380
|
-
|
|
2767
|
+
}
|
|
2768
|
+
if (cx.solid) {
|
|
2769
|
+
if (cautious)
|
|
2770
|
+
break;
|
|
2771
|
+
penalty += 2;
|
|
2381
2772
|
}
|
|
2382
2773
|
}
|
|
2383
|
-
if (!
|
|
2774
|
+
if (!route)
|
|
2384
2775
|
return null;
|
|
2385
|
-
this.sync(
|
|
2386
|
-
for (let
|
|
2387
|
-
|
|
2388
|
-
return
|
|
2776
|
+
this.sync(sync);
|
|
2777
|
+
for (let i = 0; i < route.length; i++)
|
|
2778
|
+
marks = this.enterInner(route[i], null, marks, false);
|
|
2779
|
+
return marks;
|
|
2389
2780
|
}
|
|
2390
2781
|
// Try to insert the given node, adjusting the context when needed.
|
|
2391
|
-
insertNode(
|
|
2392
|
-
if (
|
|
2393
|
-
let
|
|
2394
|
-
|
|
2782
|
+
insertNode(node, marks, cautious) {
|
|
2783
|
+
if (node.isInline && this.needsBlock && !this.top.type) {
|
|
2784
|
+
let block = this.textblockFromContext();
|
|
2785
|
+
if (block)
|
|
2786
|
+
marks = this.enterInner(block, null, marks);
|
|
2395
2787
|
}
|
|
2396
|
-
let
|
|
2397
|
-
if (
|
|
2788
|
+
let innerMarks = this.findPlace(node, marks, cautious);
|
|
2789
|
+
if (innerMarks) {
|
|
2398
2790
|
this.closeExtra();
|
|
2399
|
-
let
|
|
2400
|
-
|
|
2401
|
-
|
|
2402
|
-
|
|
2403
|
-
|
|
2404
|
-
|
|
2791
|
+
let top = this.top;
|
|
2792
|
+
if (top.match)
|
|
2793
|
+
top.match = top.match.matchType(node.type);
|
|
2794
|
+
let nodeMarks = Mark.none;
|
|
2795
|
+
for (let m of innerMarks.concat(node.marks))
|
|
2796
|
+
if (top.type ? top.type.allowsMarkType(m.type) : markMayApply(m.type, node.type))
|
|
2797
|
+
nodeMarks = m.addToSet(nodeMarks);
|
|
2798
|
+
top.content.push(node.mark(nodeMarks));
|
|
2799
|
+
return true;
|
|
2405
2800
|
}
|
|
2406
|
-
return
|
|
2801
|
+
return false;
|
|
2407
2802
|
}
|
|
2408
2803
|
// Try to start a node of the given type, adjusting the context when
|
|
2409
2804
|
// necessary.
|
|
2410
|
-
enter(
|
|
2411
|
-
let
|
|
2412
|
-
|
|
2805
|
+
enter(type, attrs, marks, preserveWS) {
|
|
2806
|
+
let innerMarks = this.findPlace(type.create(attrs), marks, false);
|
|
2807
|
+
if (innerMarks)
|
|
2808
|
+
innerMarks = this.enterInner(type, attrs, marks, true, preserveWS);
|
|
2809
|
+
return innerMarks;
|
|
2413
2810
|
}
|
|
2414
2811
|
// Open a node of the given type
|
|
2415
|
-
enterInner(
|
|
2812
|
+
enterInner(type, attrs, marks, solid = false, preserveWS) {
|
|
2416
2813
|
this.closeExtra();
|
|
2417
|
-
let
|
|
2418
|
-
|
|
2419
|
-
let
|
|
2420
|
-
|
|
2421
|
-
|
|
2422
|
-
|
|
2814
|
+
let top = this.top;
|
|
2815
|
+
top.match = top.match && top.match.matchType(type);
|
|
2816
|
+
let options = wsOptionsFor(type, preserveWS, top.options);
|
|
2817
|
+
if (top.options & OPT_OPEN_LEFT && top.content.length == 0)
|
|
2818
|
+
options |= OPT_OPEN_LEFT;
|
|
2819
|
+
let applyMarks = Mark.none;
|
|
2820
|
+
marks = marks.filter((m) => {
|
|
2821
|
+
if (top.type ? top.type.allowsMarkType(m.type) : markMayApply(m.type, type)) {
|
|
2822
|
+
applyMarks = m.addToSet(applyMarks);
|
|
2823
|
+
return false;
|
|
2824
|
+
}
|
|
2825
|
+
return true;
|
|
2826
|
+
});
|
|
2827
|
+
this.nodes.push(new NodeContext(type, attrs, applyMarks, solid, null, options));
|
|
2828
|
+
this.open++;
|
|
2829
|
+
return marks;
|
|
2423
2830
|
}
|
|
2424
2831
|
// Make sure all nodes above this.open are finished and added to
|
|
2425
2832
|
// their parents
|
|
2426
|
-
closeExtra(
|
|
2427
|
-
let
|
|
2428
|
-
if (
|
|
2429
|
-
for (;
|
|
2430
|
-
this.nodes[
|
|
2833
|
+
closeExtra(openEnd = false) {
|
|
2834
|
+
let i = this.nodes.length - 1;
|
|
2835
|
+
if (i > this.open) {
|
|
2836
|
+
for (; i > this.open; i--)
|
|
2837
|
+
this.nodes[i - 1].content.push(this.nodes[i].finish(openEnd));
|
|
2431
2838
|
this.nodes.length = this.open + 1;
|
|
2432
2839
|
}
|
|
2433
2840
|
}
|
|
2434
2841
|
finish() {
|
|
2435
|
-
|
|
2436
|
-
|
|
2437
|
-
|
|
2438
|
-
|
|
2439
|
-
|
|
2440
|
-
|
|
2441
|
-
|
|
2842
|
+
this.open = 0;
|
|
2843
|
+
this.closeExtra(this.isOpen);
|
|
2844
|
+
return this.nodes[0].finish(!!(this.isOpen || this.options.topOpen));
|
|
2845
|
+
}
|
|
2846
|
+
sync(to) {
|
|
2847
|
+
for (let i = this.open; i >= 0; i--) {
|
|
2848
|
+
if (this.nodes[i] == to) {
|
|
2849
|
+
this.open = i;
|
|
2850
|
+
return true;
|
|
2851
|
+
} else if (this.localPreserveWS) {
|
|
2852
|
+
this.nodes[i].options |= OPT_PRESERVE_WS;
|
|
2853
|
+
}
|
|
2442
2854
|
}
|
|
2443
|
-
return
|
|
2855
|
+
return false;
|
|
2444
2856
|
}
|
|
2445
2857
|
get currentPos() {
|
|
2446
2858
|
this.closeExtra();
|
|
2447
|
-
let
|
|
2448
|
-
for (let
|
|
2449
|
-
let
|
|
2450
|
-
for (let
|
|
2451
|
-
|
|
2452
|
-
|
|
2859
|
+
let pos = 0;
|
|
2860
|
+
for (let i = this.open; i >= 0; i--) {
|
|
2861
|
+
let content = this.nodes[i].content;
|
|
2862
|
+
for (let j = content.length - 1; j >= 0; j--)
|
|
2863
|
+
pos += content[j].nodeSize;
|
|
2864
|
+
if (i)
|
|
2865
|
+
pos++;
|
|
2453
2866
|
}
|
|
2454
|
-
return
|
|
2867
|
+
return pos;
|
|
2455
2868
|
}
|
|
2456
|
-
findAtPoint(
|
|
2869
|
+
findAtPoint(parent, offset) {
|
|
2457
2870
|
if (this.find)
|
|
2458
|
-
for (let
|
|
2459
|
-
this.find[
|
|
2871
|
+
for (let i = 0; i < this.find.length; i++) {
|
|
2872
|
+
if (this.find[i].node == parent && this.find[i].offset == offset)
|
|
2873
|
+
this.find[i].pos = this.currentPos;
|
|
2874
|
+
}
|
|
2460
2875
|
}
|
|
2461
|
-
findInside(
|
|
2876
|
+
findInside(parent) {
|
|
2462
2877
|
if (this.find)
|
|
2463
|
-
for (let
|
|
2464
|
-
this.find[
|
|
2878
|
+
for (let i = 0; i < this.find.length; i++) {
|
|
2879
|
+
if (this.find[i].pos == null && parent.nodeType == 1 && parent.contains(this.find[i].node))
|
|
2880
|
+
this.find[i].pos = this.currentPos;
|
|
2881
|
+
}
|
|
2465
2882
|
}
|
|
2466
|
-
findAround(
|
|
2467
|
-
if (
|
|
2468
|
-
for (let i = 0; i < this.find.length; i++)
|
|
2469
|
-
this.find[i].pos == null &&
|
|
2883
|
+
findAround(parent, content, before) {
|
|
2884
|
+
if (parent != content && this.find)
|
|
2885
|
+
for (let i = 0; i < this.find.length; i++) {
|
|
2886
|
+
if (this.find[i].pos == null && parent.nodeType == 1 && parent.contains(this.find[i].node)) {
|
|
2887
|
+
let pos = content.compareDocumentPosition(this.find[i].node);
|
|
2888
|
+
if (pos & (before ? 2 : 4))
|
|
2889
|
+
this.find[i].pos = this.currentPos;
|
|
2890
|
+
}
|
|
2891
|
+
}
|
|
2470
2892
|
}
|
|
2471
|
-
findInText(
|
|
2893
|
+
findInText(textNode) {
|
|
2472
2894
|
if (this.find)
|
|
2473
|
-
for (let
|
|
2474
|
-
this.find[
|
|
2895
|
+
for (let i = 0; i < this.find.length; i++) {
|
|
2896
|
+
if (this.find[i].node == textNode)
|
|
2897
|
+
this.find[i].pos = this.currentPos - (textNode.nodeValue.length - this.find[i].offset);
|
|
2898
|
+
}
|
|
2475
2899
|
}
|
|
2476
2900
|
// Determines whether the given context string matches this context.
|
|
2477
|
-
matchesContext(
|
|
2478
|
-
if (
|
|
2479
|
-
return
|
|
2480
|
-
let
|
|
2481
|
-
|
|
2482
|
-
|
|
2483
|
-
|
|
2484
|
-
|
|
2901
|
+
matchesContext(context) {
|
|
2902
|
+
if (context.indexOf("|") > -1)
|
|
2903
|
+
return context.split(/\s*\|\s*/).some(this.matchesContext, this);
|
|
2904
|
+
let parts = context.split("/");
|
|
2905
|
+
let option = this.options.context;
|
|
2906
|
+
let useRoot = !this.isOpen && (!option || option.parent.type == this.nodes[0].type);
|
|
2907
|
+
let minDepth = -(option ? option.depth + 1 : 0) + (useRoot ? 0 : 1);
|
|
2908
|
+
let match = (i, depth) => {
|
|
2909
|
+
for (; i >= 0; i--) {
|
|
2910
|
+
let part = parts[i];
|
|
2911
|
+
if (part == "") {
|
|
2912
|
+
if (i == parts.length - 1 || i == 0)
|
|
2485
2913
|
continue;
|
|
2486
|
-
for (;
|
|
2487
|
-
if (
|
|
2488
|
-
return
|
|
2489
|
-
return
|
|
2914
|
+
for (; depth >= minDepth; depth--)
|
|
2915
|
+
if (match(i - 1, depth))
|
|
2916
|
+
return true;
|
|
2917
|
+
return false;
|
|
2490
2918
|
} else {
|
|
2491
|
-
let
|
|
2492
|
-
if (!
|
|
2493
|
-
return
|
|
2494
|
-
|
|
2919
|
+
let next = depth > 0 || depth == 0 && useRoot ? this.nodes[depth].type : option && depth >= minDepth ? option.node(depth - minDepth).type : null;
|
|
2920
|
+
if (!next || next.name != part && !next.isInGroup(part))
|
|
2921
|
+
return false;
|
|
2922
|
+
depth--;
|
|
2495
2923
|
}
|
|
2496
2924
|
}
|
|
2497
|
-
return
|
|
2925
|
+
return true;
|
|
2498
2926
|
};
|
|
2499
|
-
return
|
|
2927
|
+
return match(parts.length - 1, this.open);
|
|
2500
2928
|
}
|
|
2501
2929
|
textblockFromContext() {
|
|
2502
|
-
let
|
|
2503
|
-
if (
|
|
2504
|
-
for (let
|
|
2505
|
-
let
|
|
2506
|
-
if (
|
|
2507
|
-
return
|
|
2930
|
+
let $context = this.options.context;
|
|
2931
|
+
if ($context)
|
|
2932
|
+
for (let d = $context.depth; d >= 0; d--) {
|
|
2933
|
+
let deflt = $context.node(d).contentMatchAt($context.indexAfter(d)).defaultType;
|
|
2934
|
+
if (deflt && deflt.isTextblock && deflt.defaultAttrs)
|
|
2935
|
+
return deflt;
|
|
2508
2936
|
}
|
|
2509
|
-
for (let
|
|
2510
|
-
let
|
|
2511
|
-
if (
|
|
2512
|
-
return
|
|
2937
|
+
for (let name in this.parser.schema.nodes) {
|
|
2938
|
+
let type = this.parser.schema.nodes[name];
|
|
2939
|
+
if (type.isTextblock && type.defaultAttrs)
|
|
2940
|
+
return type;
|
|
2513
2941
|
}
|
|
2514
2942
|
}
|
|
2515
2943
|
}
|
|
2516
|
-
function
|
|
2517
|
-
for (let
|
|
2518
|
-
let
|
|
2519
|
-
|
|
2944
|
+
function normalizeList(dom) {
|
|
2945
|
+
for (let child = dom.firstChild, prevItem = null; child; child = child.nextSibling) {
|
|
2946
|
+
let name = child.nodeType == 1 ? child.nodeName.toLowerCase() : null;
|
|
2947
|
+
if (name && listTags.hasOwnProperty(name) && prevItem) {
|
|
2948
|
+
prevItem.appendChild(child);
|
|
2949
|
+
child = prevItem;
|
|
2950
|
+
} else if (name == "li") {
|
|
2951
|
+
prevItem = child;
|
|
2952
|
+
} else if (name) {
|
|
2953
|
+
prevItem = null;
|
|
2954
|
+
}
|
|
2520
2955
|
}
|
|
2521
2956
|
}
|
|
2522
|
-
function
|
|
2523
|
-
return (
|
|
2957
|
+
function matches(dom, selector) {
|
|
2958
|
+
return (dom.matches || dom.msMatchesSelector || dom.webkitMatchesSelector || dom.mozMatchesSelector).call(dom, selector);
|
|
2524
2959
|
}
|
|
2525
|
-
function
|
|
2526
|
-
let
|
|
2527
|
-
for (let
|
|
2528
|
-
|
|
2529
|
-
return
|
|
2960
|
+
function copy(obj) {
|
|
2961
|
+
let copy2 = {};
|
|
2962
|
+
for (let prop in obj)
|
|
2963
|
+
copy2[prop] = obj[prop];
|
|
2964
|
+
return copy2;
|
|
2530
2965
|
}
|
|
2531
|
-
function
|
|
2532
|
-
let
|
|
2533
|
-
for (let
|
|
2534
|
-
let
|
|
2535
|
-
if (!
|
|
2966
|
+
function markMayApply(markType, nodeType) {
|
|
2967
|
+
let nodes = nodeType.schema.nodes;
|
|
2968
|
+
for (let name in nodes) {
|
|
2969
|
+
let parent = nodes[name];
|
|
2970
|
+
if (!parent.allowsMarkType(markType))
|
|
2536
2971
|
continue;
|
|
2537
|
-
let
|
|
2538
|
-
|
|
2539
|
-
for (let
|
|
2540
|
-
let { type
|
|
2541
|
-
if (
|
|
2542
|
-
return
|
|
2972
|
+
let seen = [], scan = (match) => {
|
|
2973
|
+
seen.push(match);
|
|
2974
|
+
for (let i = 0; i < match.edgeCount; i++) {
|
|
2975
|
+
let { type, next } = match.edge(i);
|
|
2976
|
+
if (type == nodeType)
|
|
2977
|
+
return true;
|
|
2978
|
+
if (seen.indexOf(next) < 0 && scan(next))
|
|
2979
|
+
return true;
|
|
2543
2980
|
}
|
|
2544
2981
|
};
|
|
2545
|
-
if (
|
|
2546
|
-
return
|
|
2982
|
+
if (scan(parent.contentMatch))
|
|
2983
|
+
return true;
|
|
2547
2984
|
}
|
|
2548
2985
|
}
|
|
2549
|
-
class
|
|
2986
|
+
class DOMSerializer {
|
|
2550
2987
|
/**
|
|
2551
2988
|
Create a serializer. `nodes` should map node names to functions
|
|
2552
2989
|
that take a node and return a description of the corresponding
|
|
@@ -2556,8 +2993,9 @@ class ut {
|
|
|
2556
2993
|
serializer may be `null` to indicate that marks of that type
|
|
2557
2994
|
should not be serialized.
|
|
2558
2995
|
*/
|
|
2559
|
-
constructor(
|
|
2560
|
-
this.nodes =
|
|
2996
|
+
constructor(nodes, marks) {
|
|
2997
|
+
this.nodes = nodes;
|
|
2998
|
+
this.marks = marks;
|
|
2561
2999
|
}
|
|
2562
3000
|
/**
|
|
2563
3001
|
Serialize the content of this fragment to a DOM fragment. When
|
|
@@ -2565,43 +3003,51 @@ class ut {
|
|
|
2565
3003
|
document, should be passed so that the serializer can create
|
|
2566
3004
|
nodes.
|
|
2567
3005
|
*/
|
|
2568
|
-
serializeFragment(
|
|
2569
|
-
|
|
2570
|
-
|
|
2571
|
-
|
|
2572
|
-
|
|
2573
|
-
|
|
2574
|
-
|
|
2575
|
-
|
|
2576
|
-
|
|
2577
|
-
|
|
3006
|
+
serializeFragment(fragment, options = {}, target) {
|
|
3007
|
+
if (!target)
|
|
3008
|
+
target = doc(options).createDocumentFragment();
|
|
3009
|
+
let top = target, active = [];
|
|
3010
|
+
fragment.forEach((node) => {
|
|
3011
|
+
if (active.length || node.marks.length) {
|
|
3012
|
+
let keep = 0, rendered = 0;
|
|
3013
|
+
while (keep < active.length && rendered < node.marks.length) {
|
|
3014
|
+
let next = node.marks[rendered];
|
|
3015
|
+
if (!this.marks[next.type.name]) {
|
|
3016
|
+
rendered++;
|
|
2578
3017
|
continue;
|
|
2579
3018
|
}
|
|
2580
|
-
if (!
|
|
3019
|
+
if (!next.eq(active[keep][0]) || next.type.spec.spanning === false)
|
|
2581
3020
|
break;
|
|
2582
|
-
|
|
3021
|
+
keep++;
|
|
3022
|
+
rendered++;
|
|
2583
3023
|
}
|
|
2584
|
-
|
|
2585
|
-
|
|
2586
|
-
|
|
2587
|
-
let
|
|
2588
|
-
|
|
3024
|
+
while (keep < active.length)
|
|
3025
|
+
top = active.pop()[1];
|
|
3026
|
+
while (rendered < node.marks.length) {
|
|
3027
|
+
let add = node.marks[rendered++];
|
|
3028
|
+
let markDOM = this.serializeMark(add, node.isInline, options);
|
|
3029
|
+
if (markDOM) {
|
|
3030
|
+
active.push([add, top]);
|
|
3031
|
+
top.appendChild(markDOM.dom);
|
|
3032
|
+
top = markDOM.contentDOM || markDOM.dom;
|
|
3033
|
+
}
|
|
2589
3034
|
}
|
|
2590
3035
|
}
|
|
2591
|
-
|
|
2592
|
-
})
|
|
3036
|
+
top.appendChild(this.serializeNodeInner(node, options));
|
|
3037
|
+
});
|
|
3038
|
+
return target;
|
|
2593
3039
|
}
|
|
2594
3040
|
/**
|
|
2595
3041
|
@internal
|
|
2596
3042
|
*/
|
|
2597
|
-
serializeNodeInner(
|
|
2598
|
-
let { dom
|
|
2599
|
-
if (
|
|
2600
|
-
if (
|
|
3043
|
+
serializeNodeInner(node, options) {
|
|
3044
|
+
let { dom, contentDOM } = renderSpec(doc(options), this.nodes[node.type.name](node), null, node.attrs);
|
|
3045
|
+
if (contentDOM) {
|
|
3046
|
+
if (node.isLeaf)
|
|
2601
3047
|
throw new RangeError("Content hole not allowed in a leaf node spec");
|
|
2602
|
-
this.serializeFragment(
|
|
3048
|
+
this.serializeFragment(node.content, options, contentDOM);
|
|
2603
3049
|
}
|
|
2604
|
-
return
|
|
3050
|
+
return dom;
|
|
2605
3051
|
}
|
|
2606
3052
|
/**
|
|
2607
3053
|
Serialize this node to a DOM node. This can be useful when you
|
|
@@ -2610,127 +3056,150 @@ class ut {
|
|
|
2610
3056
|
[`serializeFragment`](https://prosemirror.net/docs/ref/#model.DOMSerializer.serializeFragment) on
|
|
2611
3057
|
its [content](https://prosemirror.net/docs/ref/#model.Node.content).
|
|
2612
3058
|
*/
|
|
2613
|
-
serializeNode(
|
|
2614
|
-
let
|
|
2615
|
-
for (let i =
|
|
2616
|
-
let
|
|
2617
|
-
|
|
3059
|
+
serializeNode(node, options = {}) {
|
|
3060
|
+
let dom = this.serializeNodeInner(node, options);
|
|
3061
|
+
for (let i = node.marks.length - 1; i >= 0; i--) {
|
|
3062
|
+
let wrap = this.serializeMark(node.marks[i], node.isInline, options);
|
|
3063
|
+
if (wrap) {
|
|
3064
|
+
(wrap.contentDOM || wrap.dom).appendChild(dom);
|
|
3065
|
+
dom = wrap.dom;
|
|
3066
|
+
}
|
|
2618
3067
|
}
|
|
2619
|
-
return
|
|
3068
|
+
return dom;
|
|
2620
3069
|
}
|
|
2621
3070
|
/**
|
|
2622
3071
|
@internal
|
|
2623
3072
|
*/
|
|
2624
|
-
serializeMark(
|
|
2625
|
-
let
|
|
2626
|
-
return
|
|
3073
|
+
serializeMark(mark, inline, options = {}) {
|
|
3074
|
+
let toDOM = this.marks[mark.type.name];
|
|
3075
|
+
return toDOM && renderSpec(doc(options), toDOM(mark, inline), null, mark.attrs);
|
|
2627
3076
|
}
|
|
2628
|
-
static renderSpec(
|
|
2629
|
-
return
|
|
3077
|
+
static renderSpec(doc2, structure, xmlNS = null, blockArraysIn) {
|
|
3078
|
+
return renderSpec(doc2, structure, xmlNS, blockArraysIn);
|
|
2630
3079
|
}
|
|
2631
3080
|
/**
|
|
2632
3081
|
Build a serializer using the [`toDOM`](https://prosemirror.net/docs/ref/#model.NodeSpec.toDOM)
|
|
2633
3082
|
properties in a schema's node and mark specs.
|
|
2634
3083
|
*/
|
|
2635
|
-
static fromSchema(
|
|
2636
|
-
return
|
|
3084
|
+
static fromSchema(schema) {
|
|
3085
|
+
return schema.cached.domSerializer || (schema.cached.domSerializer = new DOMSerializer(this.nodesFromSchema(schema), this.marksFromSchema(schema)));
|
|
2637
3086
|
}
|
|
2638
3087
|
/**
|
|
2639
3088
|
Gather the serializers in a schema's node specs into an object.
|
|
2640
3089
|
This can be useful as a base to build a custom serializer from.
|
|
2641
3090
|
*/
|
|
2642
|
-
static nodesFromSchema(
|
|
2643
|
-
let
|
|
2644
|
-
|
|
3091
|
+
static nodesFromSchema(schema) {
|
|
3092
|
+
let result = gatherToDOM(schema.nodes);
|
|
3093
|
+
if (!result.text)
|
|
3094
|
+
result.text = (node) => node.text;
|
|
3095
|
+
return result;
|
|
2645
3096
|
}
|
|
2646
3097
|
/**
|
|
2647
3098
|
Gather the serializers in a schema's mark specs into an object.
|
|
2648
3099
|
*/
|
|
2649
|
-
static marksFromSchema(
|
|
2650
|
-
return
|
|
2651
|
-
}
|
|
2652
|
-
}
|
|
2653
|
-
function
|
|
2654
|
-
let
|
|
2655
|
-
for (let
|
|
2656
|
-
let
|
|
2657
|
-
|
|
3100
|
+
static marksFromSchema(schema) {
|
|
3101
|
+
return gatherToDOM(schema.marks);
|
|
3102
|
+
}
|
|
3103
|
+
}
|
|
3104
|
+
function gatherToDOM(obj) {
|
|
3105
|
+
let result = {};
|
|
3106
|
+
for (let name in obj) {
|
|
3107
|
+
let toDOM = obj[name].spec.toDOM;
|
|
3108
|
+
if (toDOM)
|
|
3109
|
+
result[name] = toDOM;
|
|
3110
|
+
}
|
|
3111
|
+
return result;
|
|
3112
|
+
}
|
|
3113
|
+
function doc(options) {
|
|
3114
|
+
return options.document || window.document;
|
|
3115
|
+
}
|
|
3116
|
+
const suspiciousAttributeCache = /* @__PURE__ */ new WeakMap();
|
|
3117
|
+
function suspiciousAttributes(attrs) {
|
|
3118
|
+
let value = suspiciousAttributeCache.get(attrs);
|
|
3119
|
+
if (value === void 0)
|
|
3120
|
+
suspiciousAttributeCache.set(attrs, value = suspiciousAttributesInner(attrs));
|
|
3121
|
+
return value;
|
|
3122
|
+
}
|
|
3123
|
+
function suspiciousAttributesInner(attrs) {
|
|
3124
|
+
let result = null;
|
|
3125
|
+
function scan(value) {
|
|
3126
|
+
if (value && typeof value == "object") {
|
|
3127
|
+
if (Array.isArray(value)) {
|
|
3128
|
+
if (typeof value[0] == "string") {
|
|
3129
|
+
if (!result)
|
|
3130
|
+
result = [];
|
|
3131
|
+
result.push(value);
|
|
3132
|
+
} else {
|
|
3133
|
+
for (let i = 0; i < value.length; i++)
|
|
3134
|
+
scan(value[i]);
|
|
3135
|
+
}
|
|
3136
|
+
} else {
|
|
3137
|
+
for (let prop in value)
|
|
3138
|
+
scan(value[prop]);
|
|
3139
|
+
}
|
|
3140
|
+
}
|
|
2658
3141
|
}
|
|
2659
|
-
|
|
2660
|
-
|
|
2661
|
-
|
|
2662
|
-
|
|
2663
|
-
|
|
2664
|
-
|
|
2665
|
-
|
|
2666
|
-
|
|
2667
|
-
|
|
2668
|
-
|
|
2669
|
-
|
|
2670
|
-
|
|
2671
|
-
function e(n) {
|
|
2672
|
-
if (n && typeof n == "object")
|
|
2673
|
-
if (Array.isArray(n))
|
|
2674
|
-
if (typeof n[0] == "string")
|
|
2675
|
-
t || (t = []), t.push(n);
|
|
2676
|
-
else
|
|
2677
|
-
for (let i = 0; i < n.length; i++)
|
|
2678
|
-
e(n[i]);
|
|
2679
|
-
else
|
|
2680
|
-
for (let i in n)
|
|
2681
|
-
e(n[i]);
|
|
2682
|
-
}
|
|
2683
|
-
return e(l), t;
|
|
2684
|
-
}
|
|
2685
|
-
function T(l, t, e, n) {
|
|
2686
|
-
if (typeof t == "string")
|
|
2687
|
-
return { dom: l.createTextNode(t) };
|
|
2688
|
-
if (t.nodeType != null)
|
|
2689
|
-
return { dom: t };
|
|
2690
|
-
if (t.dom && t.dom.nodeType != null)
|
|
2691
|
-
return t;
|
|
2692
|
-
let i = t[0], r;
|
|
2693
|
-
if (typeof i != "string")
|
|
3142
|
+
scan(attrs);
|
|
3143
|
+
return result;
|
|
3144
|
+
}
|
|
3145
|
+
function renderSpec(doc2, structure, xmlNS, blockArraysIn) {
|
|
3146
|
+
if (typeof structure == "string")
|
|
3147
|
+
return { dom: doc2.createTextNode(structure) };
|
|
3148
|
+
if (structure.nodeType != null)
|
|
3149
|
+
return { dom: structure };
|
|
3150
|
+
if (structure.dom && structure.dom.nodeType != null)
|
|
3151
|
+
return structure;
|
|
3152
|
+
let tagName = structure[0], suspicious;
|
|
3153
|
+
if (typeof tagName != "string")
|
|
2694
3154
|
throw new RangeError("Invalid array passed to renderSpec");
|
|
2695
|
-
if (
|
|
3155
|
+
if (blockArraysIn && (suspicious = suspiciousAttributes(blockArraysIn)) && suspicious.indexOf(structure) > -1)
|
|
2696
3156
|
throw new RangeError("Using an array from an attribute object as a DOM spec. This may be an attempted cross site scripting attack.");
|
|
2697
|
-
let
|
|
2698
|
-
|
|
2699
|
-
|
|
2700
|
-
|
|
2701
|
-
|
|
2702
|
-
|
|
2703
|
-
|
|
2704
|
-
|
|
2705
|
-
|
|
3157
|
+
let space = tagName.indexOf(" ");
|
|
3158
|
+
if (space > 0) {
|
|
3159
|
+
xmlNS = tagName.slice(0, space);
|
|
3160
|
+
tagName = tagName.slice(space + 1);
|
|
3161
|
+
}
|
|
3162
|
+
let contentDOM;
|
|
3163
|
+
let dom = xmlNS ? doc2.createElementNS(xmlNS, tagName) : doc2.createElement(tagName);
|
|
3164
|
+
let attrs = structure[1], start = 1;
|
|
3165
|
+
if (attrs && typeof attrs == "object" && attrs.nodeType == null && !Array.isArray(attrs)) {
|
|
3166
|
+
start = 2;
|
|
3167
|
+
for (let name in attrs)
|
|
3168
|
+
if (attrs[name] != null) {
|
|
3169
|
+
let space2 = name.indexOf(" ");
|
|
3170
|
+
if (space2 > 0)
|
|
3171
|
+
dom.setAttributeNS(name.slice(0, space2), name.slice(space2 + 1), attrs[name]);
|
|
3172
|
+
else
|
|
3173
|
+
dom.setAttribute(name, attrs[name]);
|
|
2706
3174
|
}
|
|
2707
3175
|
}
|
|
2708
|
-
for (let
|
|
2709
|
-
let
|
|
2710
|
-
if (
|
|
2711
|
-
if (
|
|
3176
|
+
for (let i = start; i < structure.length; i++) {
|
|
3177
|
+
let child = structure[i];
|
|
3178
|
+
if (child === 0) {
|
|
3179
|
+
if (i < structure.length - 1 || i > start)
|
|
2712
3180
|
throw new RangeError("Content hole must be the only child of its parent node");
|
|
2713
|
-
return { dom
|
|
3181
|
+
return { dom, contentDOM: dom };
|
|
2714
3182
|
} else {
|
|
2715
|
-
let { dom:
|
|
2716
|
-
|
|
2717
|
-
|
|
3183
|
+
let { dom: inner, contentDOM: innerContent } = renderSpec(doc2, child, xmlNS, blockArraysIn);
|
|
3184
|
+
dom.appendChild(inner);
|
|
3185
|
+
if (innerContent) {
|
|
3186
|
+
if (contentDOM)
|
|
2718
3187
|
throw new RangeError("Multiple content holes");
|
|
2719
|
-
|
|
3188
|
+
contentDOM = innerContent;
|
|
2720
3189
|
}
|
|
2721
3190
|
}
|
|
2722
3191
|
}
|
|
2723
|
-
return { dom
|
|
3192
|
+
return { dom, contentDOM };
|
|
2724
3193
|
}
|
|
2725
3194
|
export {
|
|
2726
|
-
|
|
2727
|
-
|
|
2728
|
-
|
|
2729
|
-
|
|
2730
|
-
|
|
2731
|
-
|
|
2732
|
-
|
|
2733
|
-
|
|
2734
|
-
|
|
2735
|
-
|
|
3195
|
+
DOMSerializer as D,
|
|
3196
|
+
Fragment as F,
|
|
3197
|
+
Mark as M,
|
|
3198
|
+
Node as N,
|
|
3199
|
+
ReplaceError as R,
|
|
3200
|
+
Schema as S,
|
|
3201
|
+
DOMParser as a,
|
|
3202
|
+
Slice as b,
|
|
3203
|
+
NodeRange as c,
|
|
3204
|
+
MarkType as d
|
|
2736
3205
|
};
|