@nectary/components 4.12.0 → 4.12.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/accordion/index.d.ts +22 -1
- package/accordion/index.js +39 -41
- package/accordion/types.d.ts +1 -21
- package/accordion/types.js +1 -1
- package/accordion-item/index.d.ts +22 -2
- package/accordion-item/index.js +49 -53
- package/accordion-item/types.d.ts +1 -21
- package/accordion-item/types.js +1 -1
- package/accordion-item/utils.js +1 -4
- package/action-menu/index.d.ts +22 -1
- package/action-menu/index.js +77 -62
- package/action-menu/types.d.ts +1 -21
- package/action-menu/types.js +1 -1
- package/action-menu-option/index.d.ts +22 -1
- package/action-menu-option/index.js +41 -39
- package/action-menu-option/types.d.ts +1 -21
- package/action-menu-option/types.js +1 -1
- package/action-menu-option/utils.js +3 -6
- package/alert/index.d.ts +22 -2
- package/alert/index.js +21 -24
- package/alert/types.d.ts +1 -21
- package/alert/types.js +1 -1
- package/alert/utils.js +1 -4
- package/avatar/colors.js +1 -1
- package/avatar/index.d.ts +22 -2
- package/avatar/index.js +41 -42
- package/avatar/types.d.ts +1 -21
- package/avatar/types.js +1 -1
- package/avatar/utils.js +4 -9
- package/badge/index.d.ts +22 -3
- package/badge/index.js +51 -52
- package/badge/types.d.ts +1 -21
- package/badge/types.js +1 -1
- package/badge/utils.js +1 -4
- package/button/index.d.ts +22 -2
- package/button/index.js +111 -101
- package/button/types.d.ts +1 -21
- package/button/types.js +1 -1
- package/button/utils.js +2 -18
- package/button-group/index.d.ts +22 -1
- package/button-group/index.js +18 -20
- package/button-group/types.d.ts +3 -22
- package/button-group/types.js +1 -1
- package/button-group-item/index.d.ts +22 -2
- package/button-group-item/index.js +42 -31
- package/button-group-item/types.d.ts +3 -22
- package/button-group-item/types.js +1 -1
- package/card/index.d.ts +40 -0
- package/card/index.js +134 -0
- package/card/types.d.ts +17 -0
- package/card/types.js +1 -0
- package/card-container/index.d.ts +21 -1
- package/card-container/index.js +5 -8
- package/card-container/types.d.ts +1 -21
- package/card-container/types.js +1 -1
- package/card-v2/index.d.ts +22 -1
- package/card-v2/index.js +57 -59
- package/card-v2/types.d.ts +1 -21
- package/card-v2/types.js +1 -1
- package/card-v2-title/index.d.ts +22 -2
- package/card-v2-title/index.js +26 -28
- package/card-v2-title/types.d.ts +1 -21
- package/card-v2-title/types.js +1 -1
- package/checkbox/index.d.ts +22 -1
- package/checkbox/index.js +81 -88
- package/checkbox/types.d.ts +1 -21
- package/checkbox/types.js +1 -1
- package/chip/colors.js +1 -1
- package/chip/index.d.ts +22 -1
- package/chip/index.js +75 -62
- package/chip/types.d.ts +1 -21
- package/chip/types.js +1 -1
- package/chip/utils.js +3 -7
- package/code-tag/index.d.ts +22 -1
- package/code-tag/index.js +14 -17
- package/code-tag/types.d.ts +1 -21
- package/code-tag/types.js +1 -1
- package/color-menu/index.d.ts +22 -2
- package/color-menu/index.js +115 -115
- package/color-menu/types.d.ts +1 -21
- package/color-menu/types.js +1 -1
- package/color-menu/utils.js +3 -6
- package/color-menu-option/index.d.ts +22 -1
- package/color-menu-option/index.js +26 -30
- package/color-menu-option/types.d.ts +1 -21
- package/color-menu-option/types.js +1 -1
- package/color-menu-option/utils.js +3 -6
- package/color-swatch/index.d.ts +22 -1
- package/color-swatch/index.js +20 -23
- package/color-swatch/types.d.ts +1 -21
- package/color-swatch/types.js +1 -1
- package/color-swatch/utils.js +3 -7
- package/date-picker/index.d.ts +22 -2
- package/date-picker/index.js +150 -157
- package/date-picker/types.d.ts +1 -21
- package/date-picker/types.js +1 -1
- package/date-picker/utils.js +42 -59
- package/dialog/index.d.ts +22 -1
- package/dialog/index.js +58 -71
- package/dialog/types.d.ts +1 -21
- package/dialog/types.js +1 -1
- package/dialog/utils.js +7 -11
- package/emoji/index.d.ts +22 -1
- package/emoji/index.js +16 -19
- package/emoji/types.d.ts +1 -21
- package/emoji/types.js +1 -1
- package/emoji/utils.js +17 -22
- package/emoji-picker/index.d.ts +22 -2
- package/emoji-picker/index.js +118 -138
- package/emoji-picker/types.d.ts +1 -21
- package/emoji-picker/types.js +1 -1
- package/field/index.d.ts +22 -1
- package/field/index.js +60 -63
- package/field/types.d.ts +1 -21
- package/field/types.js +1 -1
- package/file-drop/index.d.ts +22 -1
- package/file-drop/index.js +98 -103
- package/file-drop/types.d.ts +1 -21
- package/file-drop/types.js +1 -1
- package/file-drop/utils.js +22 -27
- package/file-picker/index.d.ts +22 -1
- package/file-picker/index.js +48 -53
- package/file-picker/types.d.ts +1 -21
- package/file-picker/types.js +1 -1
- package/file-picker/utils.js +3 -6
- package/file-status/index.d.ts +22 -2
- package/file-status/index.js +22 -33
- package/file-status/types.d.ts +1 -21
- package/file-status/types.js +1 -1
- package/file-status/utils.js +1 -4
- package/flag/index.d.ts +22 -1
- package/flag/index.js +16 -19
- package/flag/types.d.ts +1 -21
- package/flag/types.js +1 -1
- package/flag/utils.js +8 -11
- package/grid/index.d.ts +22 -1
- package/grid/index.js +5 -8
- package/grid/types.d.ts +1 -21
- package/grid/types.js +1 -1
- package/grid-item/index.d.ts +22 -1
- package/grid-item/index.js +13 -17
- package/grid-item/types.d.ts +1 -21
- package/grid-item/types.js +1 -1
- package/help-tooltip/index.d.ts +22 -1
- package/help-tooltip/index.js +26 -29
- package/help-tooltip/types.d.ts +1 -21
- package/help-tooltip/types.js +1 -1
- package/horizontal-stepper/index.d.ts +33 -0
- package/horizontal-stepper/index.js +62 -0
- package/horizontal-stepper/types.d.ts +42 -0
- package/horizontal-stepper/types.js +1 -0
- package/horizontal-stepper-item/index.d.ts +38 -0
- package/horizontal-stepper-item/index.js +62 -0
- package/horizontal-stepper-item/types.d.ts +38 -0
- package/horizontal-stepper-item/types.js +1 -0
- package/horizontal-stepper-item/utils.d.ts +2 -0
- package/horizontal-stepper-item/utils.js +1 -0
- package/icon/generated-icon-type.js +1 -1
- package/icon/index.d.ts +22 -1
- package/icon/index.js +28 -30
- package/icon/types.d.ts +1 -21
- package/icon/types.js +1 -1
- package/inline-alert/index.d.ts +22 -2
- package/inline-alert/index.js +39 -58
- package/inline-alert/types.d.ts +1 -21
- package/inline-alert/types.js +1 -1
- package/inline-alert/utils.js +1 -4
- package/input/index.d.ts +22 -2
- package/input/index.js +317 -295
- package/input/types.d.ts +1 -21
- package/input/types.js +1 -1
- package/input/utils.js +46 -56
- package/link/index.d.ts +22 -1
- package/link/index.js +79 -88
- package/link/types.d.ts +1 -21
- package/link/types.js +1 -1
- package/list/index.d.ts +21 -1
- package/list/index.js +6 -9
- package/list/types.d.ts +1 -21
- package/list/types.js +1 -1
- package/list-item/index.d.ts +22 -1
- package/list-item/index.js +6 -9
- package/list-item/types.d.ts +1 -21
- package/list-item/types.js +1 -1
- package/package.json +5 -11
- package/pagination/index.d.ts +22 -2
- package/pagination/index.js +46 -64
- package/pagination/types.d.ts +1 -21
- package/pagination/types.js +1 -1
- package/persistent-overlay/index.d.ts +22 -1
- package/persistent-overlay/index.js +44 -42
- package/persistent-overlay/types.d.ts +1 -21
- package/persistent-overlay/types.js +1 -1
- package/pop/index.d.ts +22 -3
- package/pop/index.js +150 -149
- package/pop/types.d.ts +1 -21
- package/pop/types.js +1 -1
- package/pop/utils.js +8 -24
- package/popover/index.d.ts +22 -2
- package/popover/index.js +68 -75
- package/popover/types.d.ts +1 -21
- package/popover/types.js +1 -1
- package/popover/utils.js +7 -18
- package/progress/index.d.ts +22 -1
- package/progress/index.js +33 -30
- package/progress/types.d.ts +1 -21
- package/progress/types.js +1 -1
- package/progress-stepper/index.d.ts +22 -2
- package/progress-stepper/index.js +66 -64
- package/progress-stepper/types.d.ts +1 -21
- package/progress-stepper/types.js +1 -1
- package/progress-stepper-item/index.d.ts +22 -1
- package/progress-stepper-item/index.js +50 -58
- package/progress-stepper-item/types.d.ts +1 -21
- package/progress-stepper-item/types.js +1 -1
- package/progress-stepper-item/utils.js +11 -22
- package/radio/index.d.ts +22 -1
- package/radio/index.js +83 -79
- package/radio/types.d.ts +1 -21
- package/radio/types.js +1 -1
- package/radio-option/index.d.ts +22 -1
- package/radio-option/index.js +41 -47
- package/radio-option/types.d.ts +1 -21
- package/radio-option/types.js +1 -1
- package/rich-text/index.d.ts +22 -1
- package/rich-text/index.js +46 -45
- package/rich-text/types.d.ts +1 -21
- package/rich-text/types.js +1 -1
- package/rich-text/utils.js +33 -31
- package/rich-textarea/index.d.ts +22 -1
- package/rich-textarea/index.js +194 -201
- package/rich-textarea/types.d.ts +1 -21
- package/rich-textarea/types.js +1 -1
- package/rich-textarea/utils.js +340 -313
- package/segment/index.d.ts +40 -0
- package/segment/index.js +110 -0
- package/segment/types.d.ts +23 -0
- package/segment/types.js +1 -0
- package/segment/utils.d.ts +3 -0
- package/segment/utils.js +16 -0
- package/segment-collapse/index.d.ts +22 -1
- package/segment-collapse/index.js +25 -31
- package/segment-collapse/types.d.ts +1 -21
- package/segment-collapse/types.js +1 -1
- package/segmented-control/index.d.ts +22 -1
- package/segmented-control/index.js +45 -45
- package/segmented-control/types.d.ts +1 -21
- package/segmented-control/types.js +1 -1
- package/segmented-control-option/index.d.ts +22 -1
- package/segmented-control-option/index.js +46 -44
- package/segmented-control-option/types.d.ts +1 -21
- package/segmented-control-option/types.js +1 -1
- package/segmented-icon-control/index.d.ts +22 -1
- package/segmented-icon-control/index.js +50 -51
- package/segmented-icon-control/types.d.ts +1 -21
- package/segmented-icon-control/types.js +1 -1
- package/segmented-icon-control-option/index.d.ts +22 -1
- package/segmented-icon-control-option/index.js +37 -36
- package/segmented-icon-control-option/types.d.ts +1 -21
- package/segmented-icon-control-option/types.js +1 -1
- package/select-button/index.d.ts +26 -1
- package/select-button/index.js +112 -104
- package/select-button/types.d.ts +1 -25
- package/select-button/types.js +1 -1
- package/select-menu/index.d.ts +22 -1
- package/select-menu/index.js +164 -201
- package/select-menu/types.d.ts +1 -21
- package/select-menu/types.js +1 -1
- package/select-menu-option/index.d.ts +22 -1
- package/select-menu-option/index.js +33 -41
- package/select-menu-option/types.d.ts +1 -21
- package/select-menu-option/types.js +1 -1
- package/select-menu-option/utils.js +1 -4
- package/skeleton/index.d.ts +22 -1
- package/skeleton/index.js +38 -35
- package/skeleton/types.d.ts +1 -21
- package/skeleton/types.js +1 -1
- package/skeleton-item/index.d.ts +22 -1
- package/skeleton-item/index.js +5 -8
- package/skeleton-item/types.d.ts +1 -21
- package/skeleton-item/types.js +1 -1
- package/spinner/index.d.ts +22 -1
- package/spinner/index.js +29 -31
- package/spinner/types.d.ts +1 -21
- package/spinner/types.js +1 -1
- package/standalone.d.ts +8 -0
- package/standalone.js +87 -79
- package/standalone.ts +8 -0
- package/stop-events/index.js +12 -12
- package/table/index.d.ts +21 -1
- package/table/index.js +6 -9
- package/table/types.d.ts +1 -21
- package/table/types.js +1 -1
- package/table-body/index.d.ts +21 -1
- package/table-body/index.js +6 -9
- package/table-body/types.d.ts +1 -21
- package/table-body/types.js +1 -1
- package/table-cell/index.d.ts +22 -2
- package/table-cell/index.js +9 -13
- package/table-cell/types.d.ts +1 -21
- package/table-cell/types.js +1 -1
- package/table-cell/utils.js +1 -4
- package/table-head/index.d.ts +21 -1
- package/table-head/index.js +6 -9
- package/table-head/types.d.ts +1 -21
- package/table-head/types.js +1 -1
- package/table-head-cell/index.d.ts +22 -1
- package/table-head-cell/index.js +27 -29
- package/table-head-cell/types.d.ts +1 -21
- package/table-head-cell/types.js +1 -1
- package/table-row/index.d.ts +22 -1
- package/table-row/index.js +17 -20
- package/table-row/types.d.ts +1 -21
- package/table-row/types.js +1 -1
- package/tabs/index.d.ts +22 -2
- package/tabs/index.js +35 -32
- package/tabs/types.d.ts +1 -21
- package/tabs/types.js +1 -1
- package/tabs-icon-option/index.d.ts +22 -1
- package/tabs-icon-option/index.js +40 -38
- package/tabs-icon-option/types.d.ts +1 -21
- package/tabs-icon-option/types.js +1 -1
- package/tabs-option/index.d.ts +22 -1
- package/tabs-option/index.js +43 -41
- package/tabs-option/types.d.ts +1 -21
- package/tabs-option/types.js +1 -1
- package/tag/colors.js +1 -1
- package/tag/index.d.ts +22 -1
- package/tag/index.js +44 -45
- package/tag/types.d.ts +1 -21
- package/tag/types.js +1 -1
- package/tag/utils.js +3 -7
- package/text/index.d.ts +22 -2
- package/text/index.js +28 -33
- package/text/types.d.ts +1 -21
- package/text/types.js +1 -1
- package/text/utils.js +1 -4
- package/textarea/index.d.ts +22 -1
- package/textarea/index.js +152 -147
- package/textarea/types.d.ts +1 -21
- package/textarea/types.js +1 -1
- package/tile-control/index.d.ts +39 -0
- package/tile-control/index.js +111 -0
- package/tile-control/types.d.ts +29 -0
- package/tile-control/types.js +1 -0
- package/tile-control-option/index.d.ts +40 -0
- package/tile-control-option/index.js +99 -0
- package/tile-control-option/types.d.ts +52 -0
- package/tile-control-option/types.js +1 -0
- package/time-picker/index.d.ts +22 -2
- package/time-picker/index.js +123 -119
- package/time-picker/types.d.ts +1 -21
- package/time-picker/types.js +1 -1
- package/time-picker/utils.js +33 -31
- package/title/index.d.ts +22 -2
- package/title/index.js +31 -32
- package/title/types.d.ts +1 -21
- package/title/types.js +1 -1
- package/title/utils.js +14 -18
- package/toast/index.d.ts +22 -2
- package/toast/index.js +34 -37
- package/toast/types.d.ts +1 -21
- package/toast/types.js +1 -1
- package/toast/utils.js +1 -4
- package/toast-manager/index.d.ts +22 -3
- package/toast-manager/index.js +63 -77
- package/toast-manager/types.d.ts +1 -21
- package/toast-manager/types.js +1 -1
- package/toast-manager/utils.js +1 -4
- package/toggle/index.d.ts +22 -1
- package/toggle/index.js +75 -81
- package/toggle/types.d.ts +1 -21
- package/toggle/types.js +1 -1
- package/tooltip/index.d.ts +22 -3
- package/tooltip/index.js +93 -105
- package/tooltip/tooltip-state.js +64 -56
- package/tooltip/types.d.ts +1 -21
- package/tooltip/types.js +1 -1
- package/tooltip/utils.js +13 -32
- package/types.d.ts +29 -12
- package/utils/adapters.js +1 -1
- package/utils/context.js +42 -32
- package/utils/countries.js +2 -490
- package/utils/csv.js +6 -13
- package/utils/debounce.js +3 -10
- package/utils/dom.js +53 -60
- package/utils/element.d.ts +15 -107
- package/utils/element.js +19 -100
- package/utils/event-target.js +5 -11
- package/utils/form.js +12 -17
- package/utils/get-react-event-handler.js +3 -6
- package/utils/index.js +12 -65
- package/utils/markdown.js +43 -56
- package/utils/rect.js +18 -13
- package/utils/size.js +3 -8
- package/utils/slot.js +9 -13
- package/utils/throttle.js +2 -5
- package/utils/uid.js +2 -5
- package/vertical-stepper/index.d.ts +33 -0
- package/vertical-stepper/index.js +58 -0
- package/vertical-stepper/types.d.ts +34 -0
- package/vertical-stepper/types.js +1 -0
- package/vertical-stepper-item/index.d.ts +38 -0
- package/vertical-stepper-item/index.js +62 -0
- package/vertical-stepper-item/types.d.ts +42 -0
- package/vertical-stepper-item/types.js +1 -0
- package/vertical-stepper-item/utils.d.ts +2 -0
- package/vertical-stepper-item/utils.js +1 -0
- package/accordion/global/index.d.ts +0 -1
- package/accordion/global/index.js +0 -2
- package/accordion-item/global/index.d.ts +0 -1
- package/accordion-item/global/index.js +0 -2
- package/action-menu/global/index.d.ts +0 -1
- package/action-menu/global/index.js +0 -2
- package/action-menu-option/global/index.d.ts +0 -1
- package/action-menu-option/global/index.js +0 -2
- package/alert/global/index.d.ts +0 -1
- package/alert/global/index.js +0 -2
- package/avatar/global/index.d.ts +0 -1
- package/avatar/global/index.js +0 -2
- package/badge/global/index.d.ts +0 -1
- package/badge/global/index.js +0 -2
- package/bundle.d.ts +0 -78
- package/bundle.js +0 -13033
- package/bundle.ts +0 -80
- package/button/global/index.d.ts +0 -1
- package/button/global/index.js +0 -2
- package/button-group/global/index.d.ts +0 -1
- package/button-group/global/index.js +0 -2
- package/button-group-item/global/index.d.ts +0 -1
- package/button-group-item/global/index.js +0 -2
- package/card-container/global/index.d.ts +0 -1
- package/card-container/global/index.js +0 -2
- package/card-v2/global/index.d.ts +0 -1
- package/card-v2/global/index.js +0 -2
- package/card-v2-title/global/index.d.ts +0 -1
- package/card-v2-title/global/index.js +0 -2
- package/checkbox/global/index.d.ts +0 -1
- package/checkbox/global/index.js +0 -2
- package/chip/global/index.d.ts +0 -1
- package/chip/global/index.js +0 -2
- package/code-tag/global/index.d.ts +0 -1
- package/code-tag/global/index.js +0 -2
- package/color-menu/global/index.d.ts +0 -1
- package/color-menu/global/index.js +0 -2
- package/color-menu-option/global/index.d.ts +0 -1
- package/color-menu-option/global/index.js +0 -2
- package/color-swatch/global/index.d.ts +0 -1
- package/color-swatch/global/index.js +0 -2
- package/date-picker/global/index.d.ts +0 -1
- package/date-picker/global/index.js +0 -2
- package/dialog/global/index.d.ts +0 -1
- package/dialog/global/index.js +0 -2
- package/emoji/global/index.d.ts +0 -1
- package/emoji/global/index.js +0 -2
- package/emoji-picker/global/index.d.ts +0 -1
- package/emoji-picker/global/index.js +0 -2
- package/field/global/index.d.ts +0 -1
- package/field/global/index.js +0 -2
- package/file-drop/global/index.d.ts +0 -1
- package/file-drop/global/index.js +0 -2
- package/file-picker/global/index.d.ts +0 -1
- package/file-picker/global/index.js +0 -2
- package/file-status/global/index.d.ts +0 -1
- package/file-status/global/index.js +0 -2
- package/flag/global/index.d.ts +0 -1
- package/flag/global/index.js +0 -2
- package/grid/global/index.d.ts +0 -1
- package/grid/global/index.js +0 -2
- package/grid-item/global/index.d.ts +0 -1
- package/grid-item/global/index.js +0 -2
- package/help-tooltip/global/index.d.ts +0 -1
- package/help-tooltip/global/index.js +0 -2
- package/icon/global/index.d.ts +0 -1
- package/icon/global/index.js +0 -2
- package/inline-alert/global/index.d.ts +0 -1
- package/inline-alert/global/index.js +0 -2
- package/input/global/index.d.ts +0 -1
- package/input/global/index.js +0 -2
- package/link/global/index.d.ts +0 -1
- package/link/global/index.js +0 -2
- package/list/global/index.d.ts +0 -1
- package/list/global/index.js +0 -2
- package/list-item/global/index.d.ts +0 -1
- package/list-item/global/index.js +0 -2
- package/pagination/global/index.d.ts +0 -1
- package/pagination/global/index.js +0 -2
- package/persistent-overlay/global/index.d.ts +0 -1
- package/persistent-overlay/global/index.js +0 -2
- package/pop/global/index.d.ts +0 -1
- package/pop/global/index.js +0 -2
- package/popover/global/index.d.ts +0 -1
- package/popover/global/index.js +0 -2
- package/progress/global/index.d.ts +0 -1
- package/progress/global/index.js +0 -2
- package/progress-stepper/global/index.d.ts +0 -1
- package/progress-stepper/global/index.js +0 -2
- package/progress-stepper-item/global/index.d.ts +0 -1
- package/progress-stepper-item/global/index.js +0 -2
- package/radio/global/index.d.ts +0 -1
- package/radio/global/index.js +0 -2
- package/radio-option/global/index.d.ts +0 -1
- package/radio-option/global/index.js +0 -2
- package/rich-text/global/index.d.ts +0 -1
- package/rich-text/global/index.js +0 -2
- package/rich-textarea/global/index.d.ts +0 -1
- package/rich-textarea/global/index.js +0 -2
- package/segment-collapse/global/index.d.ts +0 -1
- package/segment-collapse/global/index.js +0 -2
- package/segmented-control/global/index.d.ts +0 -1
- package/segmented-control/global/index.js +0 -2
- package/segmented-control-option/global/index.d.ts +0 -1
- package/segmented-control-option/global/index.js +0 -2
- package/segmented-icon-control/global/index.d.ts +0 -1
- package/segmented-icon-control/global/index.js +0 -2
- package/segmented-icon-control-option/global/index.d.ts +0 -1
- package/segmented-icon-control-option/global/index.js +0 -2
- package/select-button/global/index.d.ts +0 -1
- package/select-button/global/index.js +0 -2
- package/select-menu/global/index.d.ts +0 -1
- package/select-menu/global/index.js +0 -2
- package/select-menu-option/global/index.d.ts +0 -1
- package/select-menu-option/global/index.js +0 -2
- package/skeleton/global/index.d.ts +0 -1
- package/skeleton/global/index.js +0 -2
- package/skeleton-item/global/index.d.ts +0 -1
- package/skeleton-item/global/index.js +0 -2
- package/spinner/global/index.d.ts +0 -1
- package/spinner/global/index.js +0 -2
- package/table/global/index.d.ts +0 -1
- package/table/global/index.js +0 -2
- package/table-body/global/index.d.ts +0 -1
- package/table-body/global/index.js +0 -2
- package/table-cell/global/index.d.ts +0 -1
- package/table-cell/global/index.js +0 -2
- package/table-head/global/index.d.ts +0 -1
- package/table-head/global/index.js +0 -2
- package/table-head-cell/global/index.d.ts +0 -1
- package/table-head-cell/global/index.js +0 -2
- package/table-row/global/index.d.ts +0 -1
- package/table-row/global/index.js +0 -2
- package/tabs/global/index.d.ts +0 -1
- package/tabs/global/index.js +0 -2
- package/tabs-icon-option/global/index.d.ts +0 -1
- package/tabs-icon-option/global/index.js +0 -2
- package/tabs-option/global/index.d.ts +0 -1
- package/tabs-option/global/index.js +0 -2
- package/tag/global/index.d.ts +0 -1
- package/tag/global/index.js +0 -2
- package/text/global/index.d.ts +0 -1
- package/text/global/index.js +0 -2
- package/textarea/global/index.d.ts +0 -1
- package/textarea/global/index.js +0 -2
- package/time-picker/global/index.d.ts +0 -1
- package/time-picker/global/index.js +0 -2
- package/title/global/index.d.ts +0 -1
- package/title/global/index.js +0 -2
- package/toast/global/index.d.ts +0 -1
- package/toast/global/index.js +0 -2
- package/toast-manager/global/index.d.ts +0 -1
- package/toast-manager/global/index.js +0 -2
- package/toggle/global/index.d.ts +0 -1
- package/toggle/global/index.js +0 -2
- package/tooltip/global/index.d.ts +0 -1
- package/tooltip/global/index.js +0 -2
- package/utils/component-names.d.ts +0 -3
- package/utils/component-names.js +0 -85
- package/utils/global-components-constants.d.ts +0 -3
- package/utils/global-components-constants.js +0 -8
- package/utils/global-components-manager.d.ts +0 -71
- package/utils/global-components-manager.js +0 -24
- package/utils/shared/global-elements-manager.d.js +0 -1
- package/utils/shared/global-elements-manager.d.ts +0 -62
- package/utils/shared/global-elements-manager.js +0 -163
- package/utils/shared/global-elements-store.d.js +0 -1
- package/utils/shared/global-elements-store.d.ts +0 -12
- package/utils/shared/global-elements-store.js +0 -31
- package/utils/shared/index.d.js +0 -11
- package/utils/shared/index.d.ts +0 -3
- package/utils/shared/index.js +0 -11
- package/utils/shared/nectary-element-base.d.js +0 -1
- package/utils/shared/nectary-element-base.d.ts +0 -9
- package/utils/shared/nectary-element-base.js +0 -25
- package/utils/shared/package.json +0 -9
- package/utils/shared/tsconfig.json +0 -20
package/rich-textarea/utils.js
CHANGED
|
@@ -1,32 +1,32 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { isEmojiString, parseMarkdown } from
|
|
3
|
-
const TEXT_EMPTY_DATA =
|
|
4
|
-
const TEXT_WHITESPACE =
|
|
5
|
-
const isTextNode =
|
|
6
|
-
const isEmptyText =
|
|
7
|
-
const isEmptyTextNode =
|
|
8
|
-
const getTextValue =
|
|
9
|
-
const isParagraph =
|
|
10
|
-
return $n !== null && $n.nodeType === Node.ELEMENT_NODE && $n.classList.contains(
|
|
11
|
-
};
|
|
12
|
-
const isListItem =
|
|
1
|
+
import { getEmojiBaseUrl, getEmojiUrl } from '../emoji/utils';
|
|
2
|
+
import { isEmojiString, parseMarkdown } from '../utils';
|
|
3
|
+
const TEXT_EMPTY_DATA = '';
|
|
4
|
+
const TEXT_WHITESPACE = ' ';
|
|
5
|
+
const isTextNode = $n => $n !== null && $n.nodeType === Node.TEXT_NODE;
|
|
6
|
+
const isEmptyText = value => value === null || value.length === 0 || value === TEXT_EMPTY_DATA;
|
|
7
|
+
const isEmptyTextNode = $n => isTextNode($n) && isEmptyText($n.nodeValue);
|
|
8
|
+
const getTextValue = $n => isEmptyText($n.nodeValue) ? TEXT_EMPTY_DATA : $n.nodeValue;
|
|
9
|
+
const isParagraph = $n => {
|
|
10
|
+
return $n !== null && $n.nodeType === Node.ELEMENT_NODE && $n.classList.contains('p');
|
|
11
|
+
};
|
|
12
|
+
const isListItem = $n => {
|
|
13
13
|
return isUnorderedListItem($n) || isOrderedListItem($n);
|
|
14
14
|
};
|
|
15
|
-
const isUnorderedListItem =
|
|
16
|
-
return $n !== null && $n.nodeType === Node.ELEMENT_NODE && $n.classList.contains(
|
|
15
|
+
const isUnorderedListItem = $n => {
|
|
16
|
+
return $n !== null && $n.nodeType === Node.ELEMENT_NODE && $n.classList.contains('uli');
|
|
17
17
|
};
|
|
18
|
-
const isOrderedListItem =
|
|
19
|
-
return $n !== null && $n.nodeType === Node.ELEMENT_NODE && $n.classList.contains(
|
|
18
|
+
const isOrderedListItem = $n => {
|
|
19
|
+
return $n !== null && $n.nodeType === Node.ELEMENT_NODE && $n.classList.contains('oli');
|
|
20
20
|
};
|
|
21
|
-
const isTextBlock =
|
|
22
|
-
const isEmoji =
|
|
23
|
-
return $n !== null && $n.nodeName ===
|
|
21
|
+
const isTextBlock = $n => isParagraph($n) || isListItem($n);
|
|
22
|
+
const isEmoji = $n => {
|
|
23
|
+
return $n !== null && $n.nodeName === 'IMG';
|
|
24
24
|
};
|
|
25
|
-
const isInline =
|
|
26
|
-
const isRoot =
|
|
27
|
-
const assertNonNull =
|
|
25
|
+
const isInline = $n => $n !== null && $n.nodeName === 'SPAN';
|
|
26
|
+
const isRoot = $n => $n !== null && $n.nodeName === 'DIV';
|
|
27
|
+
const assertNonNull = $n => {
|
|
28
28
|
if ($n === null) {
|
|
29
|
-
throw new Error(
|
|
29
|
+
throw new Error('Node is NULL');
|
|
30
30
|
}
|
|
31
31
|
};
|
|
32
32
|
const assertEquals = (a, b) => {
|
|
@@ -34,64 +34,64 @@ const assertEquals = (a, b) => {
|
|
|
34
34
|
throw new Error(`"${a}" not equals "${b}"`);
|
|
35
35
|
}
|
|
36
36
|
};
|
|
37
|
-
const assertTextNode =
|
|
37
|
+
const assertTextNode = $n => {
|
|
38
38
|
assertNonNull($n);
|
|
39
39
|
if (!isTextNode($n)) {
|
|
40
40
|
throw new Error(`Node is not a TextNode: ${$n?.nodeName}`);
|
|
41
41
|
}
|
|
42
42
|
};
|
|
43
|
-
const assertTextBlock =
|
|
43
|
+
const assertTextBlock = $n => {
|
|
44
44
|
assertNonNull($n);
|
|
45
45
|
if (!isTextBlock($n)) {
|
|
46
46
|
throw new Error(`Node is not a TextBlock: ${$n?.nodeName}`);
|
|
47
47
|
}
|
|
48
48
|
};
|
|
49
|
-
const assertListItem =
|
|
49
|
+
const assertListItem = $n => {
|
|
50
50
|
assertNonNull($n);
|
|
51
51
|
if (!isListItem($n)) {
|
|
52
52
|
throw new Error(`Node is not a ListItem: ${$n?.nodeName}`);
|
|
53
53
|
}
|
|
54
54
|
};
|
|
55
|
-
const markListItemAsBlock =
|
|
56
|
-
$li.classList.add(
|
|
55
|
+
const markListItemAsBlock = $li => {
|
|
56
|
+
$li.classList.add('block');
|
|
57
57
|
};
|
|
58
|
-
const isListItemMarkedArBlock =
|
|
59
|
-
return $li.classList.contains(
|
|
58
|
+
const isListItemMarkedArBlock = $li => {
|
|
59
|
+
return $li.classList.contains('block');
|
|
60
60
|
};
|
|
61
61
|
const MAX_LISTITEM_LEVEL = 4;
|
|
62
|
-
const removeListItemLevel =
|
|
63
|
-
$li.classList.remove(
|
|
62
|
+
const removeListItemLevel = $li => {
|
|
63
|
+
$li.classList.remove('l0', 'l1', 'l2', 'l3', 'l4');
|
|
64
64
|
};
|
|
65
65
|
const setListItemLevel = ($li, level) => {
|
|
66
66
|
removeListItemLevel($li);
|
|
67
67
|
const clampedLevel = Math.max(0, Math.min(level, MAX_LISTITEM_LEVEL));
|
|
68
68
|
$li.classList.add(`l${clampedLevel}`);
|
|
69
69
|
};
|
|
70
|
-
const getListItemLevel =
|
|
71
|
-
if ($li.classList.contains(
|
|
70
|
+
const getListItemLevel = $li => {
|
|
71
|
+
if ($li.classList.contains('l1')) {
|
|
72
72
|
return 1;
|
|
73
73
|
}
|
|
74
|
-
if ($li.classList.contains(
|
|
74
|
+
if ($li.classList.contains('l2')) {
|
|
75
75
|
return 2;
|
|
76
76
|
}
|
|
77
|
-
if ($li.classList.contains(
|
|
77
|
+
if ($li.classList.contains('l3')) {
|
|
78
78
|
return 3;
|
|
79
79
|
}
|
|
80
|
-
if ($li.classList.contains(
|
|
80
|
+
if ($li.classList.contains('l4')) {
|
|
81
81
|
return 4;
|
|
82
82
|
}
|
|
83
83
|
return 0;
|
|
84
84
|
};
|
|
85
|
-
const assertInline =
|
|
85
|
+
const assertInline = $n => {
|
|
86
86
|
assertNonNull($n);
|
|
87
87
|
if (!isInline($n)) {
|
|
88
88
|
throw new Error(`Node is not an Inline: ${$n?.nodeName}`);
|
|
89
89
|
}
|
|
90
90
|
};
|
|
91
|
-
const isTextContent =
|
|
91
|
+
const isTextContent = $n => {
|
|
92
92
|
return $n !== null && $n.nodeType === Node.ELEMENT_NODE && (isInline($n) || isEmoji($n));
|
|
93
93
|
};
|
|
94
|
-
const assertTextContent =
|
|
94
|
+
const assertTextContent = $n => {
|
|
95
95
|
assertNonNull($n);
|
|
96
96
|
if (!isTextContent($n)) {
|
|
97
97
|
throw new Error(`Node is not TextContent: ${$n?.nodeName}`);
|
|
@@ -100,15 +100,15 @@ const assertTextContent = ($n) => {
|
|
|
100
100
|
const createTextNode = (data, doc) => {
|
|
101
101
|
return doc.createTextNode(data);
|
|
102
102
|
};
|
|
103
|
-
const createEmptyTextNode =
|
|
103
|
+
const createEmptyTextNode = doc => {
|
|
104
104
|
return createTextNode(TEXT_EMPTY_DATA, doc);
|
|
105
105
|
};
|
|
106
|
-
const createEmptyInline =
|
|
107
|
-
const res = doc.createElement(
|
|
106
|
+
const createEmptyInline = doc => {
|
|
107
|
+
const res = doc.createElement('SPAN');
|
|
108
108
|
res.append(createEmptyTextNode(doc));
|
|
109
109
|
return res;
|
|
110
110
|
};
|
|
111
|
-
const getParentInline =
|
|
111
|
+
const getParentInline = $n => {
|
|
112
112
|
const $p = $n.parentNode;
|
|
113
113
|
assertInline($p);
|
|
114
114
|
return $p;
|
|
@@ -118,26 +118,22 @@ const isInsideList = (isOrdered, $n) => {
|
|
|
118
118
|
return isOrdered ? isOrderedListItem($block) : isUnorderedListItem($block);
|
|
119
119
|
};
|
|
120
120
|
const isAllInsideList = (isOrdered, $a, $b) => {
|
|
121
|
-
return allSiblingsIncludingSatisfy(
|
|
122
|
-
getParentTextBlock($a),
|
|
123
|
-
getParentTextBlock($b),
|
|
124
|
-
isOrdered ? isOrderedListItem : isUnorderedListItem
|
|
125
|
-
);
|
|
121
|
+
return allSiblingsIncludingSatisfy(getParentTextBlock($a), getParentTextBlock($b), isOrdered ? isOrderedListItem : isUnorderedListItem);
|
|
126
122
|
};
|
|
127
123
|
const FORMAT_TYPE_TO_NAME = {
|
|
128
|
-
formatBold:
|
|
129
|
-
formatCodeTag:
|
|
130
|
-
formatItalic:
|
|
131
|
-
formatStrikeThrough:
|
|
124
|
+
formatBold: 'b',
|
|
125
|
+
formatCodeTag: 'c',
|
|
126
|
+
formatItalic: 'i',
|
|
127
|
+
formatStrikeThrough: 's'
|
|
132
128
|
};
|
|
133
129
|
const isFormatName = ($n, inlineName) => {
|
|
134
130
|
return $n.classList.contains(inlineName);
|
|
135
131
|
};
|
|
136
|
-
const isFormatBold =
|
|
137
|
-
const isFormatItalic =
|
|
138
|
-
const isFormatStrikethrough =
|
|
139
|
-
const isFormatCodetag =
|
|
140
|
-
const isFormatLink =
|
|
132
|
+
const isFormatBold = $n => isFormatName($n, 'b');
|
|
133
|
+
const isFormatItalic = $n => isFormatName($n, 'i');
|
|
134
|
+
const isFormatStrikethrough = $n => isFormatName($n, 's');
|
|
135
|
+
const isFormatCodetag = $n => isFormatName($n, 'c');
|
|
136
|
+
const isFormatLink = $n => isFormatName($n, 'l');
|
|
141
137
|
const isAllInsideFormatName = ($a, $b, formatName) => {
|
|
142
138
|
const aBlock = getParentTextBlock($a);
|
|
143
139
|
const bBlock = getParentTextBlock($b);
|
|
@@ -162,31 +158,31 @@ const isAllInsideFormatName = ($a, $b, formatName) => {
|
|
|
162
158
|
} while ($currentBlock !== null && $prevBlock !== bBlock);
|
|
163
159
|
return hasTextNodes;
|
|
164
160
|
};
|
|
165
|
-
const isAllInsideBold = ($a, $b) => isAllInsideFormatName($a, $b,
|
|
166
|
-
const isAllInsideItalic = ($a, $b) => isAllInsideFormatName($a, $b,
|
|
167
|
-
const isAllInsideStrikethrough = ($a, $b) => isAllInsideFormatName($a, $b,
|
|
168
|
-
const isAllInsideCodetag = ($a, $b) => isAllInsideFormatName($a, $b,
|
|
169
|
-
const isAllInsideLink = ($a, $b) => isAllInsideFormatName($a, $b,
|
|
170
|
-
const LINK_HREF_ATTR_NAME =
|
|
161
|
+
const isAllInsideBold = ($a, $b) => isAllInsideFormatName($a, $b, 'b');
|
|
162
|
+
const isAllInsideItalic = ($a, $b) => isAllInsideFormatName($a, $b, 'i');
|
|
163
|
+
const isAllInsideStrikethrough = ($a, $b) => isAllInsideFormatName($a, $b, 's');
|
|
164
|
+
const isAllInsideCodetag = ($a, $b) => isAllInsideFormatName($a, $b, 'c');
|
|
165
|
+
const isAllInsideLink = ($a, $b) => isAllInsideFormatName($a, $b, 'l');
|
|
166
|
+
const LINK_HREF_ATTR_NAME = 'data-href';
|
|
171
167
|
const copyFormatName = ($source, $target) => {
|
|
172
168
|
const $inline = isTextNode($source) ? getParentInline($source) : $source;
|
|
173
169
|
$target.className = $inline.className;
|
|
174
170
|
if (isFormatLink($inline)) {
|
|
175
|
-
$target.setAttribute(LINK_HREF_ATTR_NAME, $inline.getAttribute(LINK_HREF_ATTR_NAME) ??
|
|
171
|
+
$target.setAttribute(LINK_HREF_ATTR_NAME, $inline.getAttribute(LINK_HREF_ATTR_NAME) ?? '');
|
|
176
172
|
}
|
|
177
173
|
};
|
|
178
174
|
const setInlineFormat = ($n, formatName, shouldEnable) => {
|
|
179
175
|
if (shouldEnable) {
|
|
180
|
-
if (formatName ===
|
|
181
|
-
$n.className =
|
|
176
|
+
if (formatName === 'c' || isFormatName($n, 'c')) {
|
|
177
|
+
$n.className = '';
|
|
182
178
|
}
|
|
183
|
-
if (formatName ===
|
|
184
|
-
$n.className =
|
|
179
|
+
if (formatName === 'l' || isFormatName($n, 'l')) {
|
|
180
|
+
$n.className = '';
|
|
185
181
|
$n.removeAttribute(LINK_HREF_ATTR_NAME);
|
|
186
182
|
}
|
|
187
183
|
$n.classList.add(formatName);
|
|
188
184
|
} else {
|
|
189
|
-
if (formatName ===
|
|
185
|
+
if (formatName === 'l') {
|
|
190
186
|
$n.removeAttribute(LINK_HREF_ATTR_NAME);
|
|
191
187
|
}
|
|
192
188
|
$n.classList.remove(formatName);
|
|
@@ -221,8 +217,8 @@ const areSameInlineFormat = ($a, $b) => {
|
|
|
221
217
|
if ($a.classList.length !== $b.classList.length) {
|
|
222
218
|
return false;
|
|
223
219
|
}
|
|
224
|
-
if ($a.className ===
|
|
225
|
-
return $b.className ===
|
|
220
|
+
if ($a.className === 'l') {
|
|
221
|
+
return $b.className === 'l' && $a.getAttribute(LINK_HREF_ATTR_NAME) === $b.getAttribute(LINK_HREF_ATTR_NAME);
|
|
226
222
|
}
|
|
227
223
|
for (let i = 0; i < $a.classList.length; i++) {
|
|
228
224
|
if (!$b.classList.contains($a.classList[i])) {
|
|
@@ -232,7 +228,7 @@ const areSameInlineFormat = ($a, $b) => {
|
|
|
232
228
|
return true;
|
|
233
229
|
};
|
|
234
230
|
const createInlineWithText = (data, doc) => {
|
|
235
|
-
const $res = doc.createElement(
|
|
231
|
+
const $res = doc.createElement('SPAN');
|
|
236
232
|
$res.append(createTextNode(data, doc));
|
|
237
233
|
return $res;
|
|
238
234
|
};
|
|
@@ -244,25 +240,25 @@ const createInlineWithTextOfType = ($text, $source) => {
|
|
|
244
240
|
};
|
|
245
241
|
const createLink = (text, href, doc) => {
|
|
246
242
|
const $link = createInlineWithText(text, doc);
|
|
247
|
-
setInlineFormat($link,
|
|
243
|
+
setInlineFormat($link, 'l', true);
|
|
248
244
|
$link.setAttribute(LINK_HREF_ATTR_NAME, href);
|
|
249
245
|
return $link;
|
|
250
246
|
};
|
|
251
|
-
const EMOJI_CHAR_ATTR_NAME =
|
|
247
|
+
const EMOJI_CHAR_ATTR_NAME = 'data-char';
|
|
252
248
|
const createEmoji = (emojiChar, baseUrl, doc) => {
|
|
253
|
-
const $emoji = doc.createElement(
|
|
249
|
+
const $emoji = doc.createElement('img');
|
|
254
250
|
$emoji.setAttribute(EMOJI_CHAR_ATTR_NAME, emojiChar);
|
|
255
|
-
$emoji.setAttribute(
|
|
256
|
-
$emoji.classList.add(
|
|
251
|
+
$emoji.setAttribute('src', getEmojiUrl(baseUrl, emojiChar));
|
|
252
|
+
$emoji.classList.add('e');
|
|
257
253
|
return $emoji;
|
|
258
254
|
};
|
|
259
|
-
const PARAGRAPH_CLASSNAME =
|
|
260
|
-
const createActuallyEmptyParagraph =
|
|
261
|
-
const $p = doc.createElement(
|
|
255
|
+
const PARAGRAPH_CLASSNAME = 'p';
|
|
256
|
+
const createActuallyEmptyParagraph = doc => {
|
|
257
|
+
const $p = doc.createElement('p');
|
|
262
258
|
$p.classList.add(PARAGRAPH_CLASSNAME);
|
|
263
259
|
return $p;
|
|
264
260
|
};
|
|
265
|
-
const createEmptyParagraph =
|
|
261
|
+
const createEmptyParagraph = doc => {
|
|
266
262
|
const res = createActuallyEmptyParagraph(doc);
|
|
267
263
|
res.append(createEmptyInline(doc));
|
|
268
264
|
return res;
|
|
@@ -275,19 +271,17 @@ const createParagraphWithChildren = (children, doc) => {
|
|
|
275
271
|
$p.append(...children);
|
|
276
272
|
return $p;
|
|
277
273
|
};
|
|
278
|
-
const ULI_CLASSNAME =
|
|
279
|
-
const OLI_CLASSNAME =
|
|
274
|
+
const ULI_CLASSNAME = 'uli';
|
|
275
|
+
const OLI_CLASSNAME = 'oli';
|
|
280
276
|
const createActuallyEmptyListItem = (isOrdered, listLevel, doc) => {
|
|
281
|
-
const $li = doc.createElement(
|
|
277
|
+
const $li = doc.createElement('p');
|
|
282
278
|
$li.className = isOrdered ? OLI_CLASSNAME : ULI_CLASSNAME;
|
|
283
279
|
setListItemLevel($li, listLevel);
|
|
284
280
|
return $li;
|
|
285
281
|
};
|
|
286
282
|
const createEmptyListItem = (isOrdered, listLevel, doc) => {
|
|
287
283
|
const $li = createActuallyEmptyListItem(isOrdered, listLevel, doc);
|
|
288
|
-
$li.append(
|
|
289
|
-
createEmptyInline(doc)
|
|
290
|
-
);
|
|
284
|
+
$li.append(createEmptyInline(doc));
|
|
291
285
|
return $li;
|
|
292
286
|
};
|
|
293
287
|
const setListItemOrderedType = ($li, isOrdered) => {
|
|
@@ -310,7 +304,7 @@ const convertToListItem = ($p, isOrdered) => {
|
|
|
310
304
|
setListItemLevel($li, 0);
|
|
311
305
|
return $li;
|
|
312
306
|
};
|
|
313
|
-
const convertToParagraph =
|
|
307
|
+
const convertToParagraph = $li => {
|
|
314
308
|
removeListItemLevel($li);
|
|
315
309
|
$li.classList.remove(ULI_CLASSNAME, OLI_CLASSNAME);
|
|
316
310
|
$li.classList.add(PARAGRAPH_CLASSNAME);
|
|
@@ -325,7 +319,7 @@ const createListItemWithChildren = (children, isOrdered, listLevel, doc) => {
|
|
|
325
319
|
$li.append(...children);
|
|
326
320
|
return $li;
|
|
327
321
|
};
|
|
328
|
-
const getParentTextBlock =
|
|
322
|
+
const getParentTextBlock = $node => {
|
|
329
323
|
const $inline = isTextNode($node) ? getParentInline($node) : $node;
|
|
330
324
|
const $p = $inline.parentNode;
|
|
331
325
|
assertTextBlock($p);
|
|
@@ -337,22 +331,22 @@ const childIndexOf = ($parent, $child) => {
|
|
|
337
331
|
const getChildByIndex = ($parent, index) => {
|
|
338
332
|
const children = $parent.childNodes;
|
|
339
333
|
if (index < 0 || index >= children.length) {
|
|
340
|
-
throw new Error(
|
|
334
|
+
throw new Error('Invalid index');
|
|
341
335
|
}
|
|
342
336
|
const $ch = index >= children.length ? children[children.length - 1] : children[index];
|
|
343
337
|
return $ch;
|
|
344
338
|
};
|
|
345
|
-
const afterLastChildIndex =
|
|
339
|
+
const afterLastChildIndex = $parent => {
|
|
346
340
|
return $parent.childNodes.length;
|
|
347
341
|
};
|
|
348
342
|
const isAfterLastChildIndex = ($parent, index) => {
|
|
349
343
|
return index >= $parent.childNodes.length;
|
|
350
344
|
};
|
|
351
|
-
const getLastChild =
|
|
352
|
-
const getFirstChild =
|
|
353
|
-
const getPrevSibling =
|
|
354
|
-
const getNextSibling =
|
|
355
|
-
const getSiblingTextBlock =
|
|
345
|
+
const getLastChild = n => n.lastChild;
|
|
346
|
+
const getFirstChild = n => n.firstChild;
|
|
347
|
+
const getPrevSibling = n => n.previousSibling;
|
|
348
|
+
const getNextSibling = n => n.nextSibling;
|
|
349
|
+
const getSiblingTextBlock = getSibling => $node => {
|
|
356
350
|
const $sib = getSibling($node);
|
|
357
351
|
if ($sib !== null) {
|
|
358
352
|
assertTextBlock($sib);
|
|
@@ -364,6 +358,15 @@ const getPrevSiblingTextBlock = getSiblingTextBlock(getPrevSibling);
|
|
|
364
358
|
const getNextSiblingTextBlock = getSiblingTextBlock(getNextSibling);
|
|
365
359
|
const getPrevSiblingTextContent = ($node, ensureValid) => {
|
|
366
360
|
const $sib = $node.previousSibling;
|
|
361
|
+
if ($sib === null && ensureValid === true) {
|
|
362
|
+
const $currentBlock = getParentTextBlock($node);
|
|
363
|
+
const $prevBlock = getPrevSiblingTextBlock($currentBlock);
|
|
364
|
+
if ($prevBlock === null) {
|
|
365
|
+
$currentBlock.prepend(createEmptyInline($node.ownerDocument));
|
|
366
|
+
return getFirstTextContent($currentBlock);
|
|
367
|
+
}
|
|
368
|
+
return getLastTextContent($prevBlock);
|
|
369
|
+
}
|
|
367
370
|
if ($sib !== null) {
|
|
368
371
|
assertTextContent($sib);
|
|
369
372
|
}
|
|
@@ -371,13 +374,25 @@ const getPrevSiblingTextContent = ($node, ensureValid) => {
|
|
|
371
374
|
};
|
|
372
375
|
const getNextSiblingTextContent = ($node, ensureValid) => {
|
|
373
376
|
const $sib = $node.nextSibling;
|
|
377
|
+
if ($sib === null && ensureValid === true) {
|
|
378
|
+
const $currentBlock = getParentTextBlock($node);
|
|
379
|
+
const $nextBlock = getNextSiblingTextBlock($currentBlock);
|
|
380
|
+
if ($nextBlock === null) {
|
|
381
|
+
$currentBlock.append(createEmptyInline($node.ownerDocument));
|
|
382
|
+
return getLastTextContent($currentBlock);
|
|
383
|
+
}
|
|
384
|
+
return getFirstTextContent($nextBlock);
|
|
385
|
+
}
|
|
374
386
|
if ($sib !== null) {
|
|
375
387
|
assertTextContent($sib);
|
|
376
388
|
}
|
|
377
389
|
return $sib;
|
|
378
390
|
};
|
|
379
|
-
const createCollapsedRange =
|
|
380
|
-
const {
|
|
391
|
+
const createCollapsedRange = cursor => {
|
|
392
|
+
const {
|
|
393
|
+
node,
|
|
394
|
+
offset
|
|
395
|
+
} = cursorToNodeWithOffset(cursor);
|
|
381
396
|
return {
|
|
382
397
|
startContainer: node,
|
|
383
398
|
startOffset: offset,
|
|
@@ -386,8 +401,14 @@ const createCollapsedRange = (cursor) => {
|
|
|
386
401
|
};
|
|
387
402
|
};
|
|
388
403
|
const createSpanningRange = (aCursor, bCursor) => {
|
|
389
|
-
const {
|
|
390
|
-
|
|
404
|
+
const {
|
|
405
|
+
node: startContainer,
|
|
406
|
+
offset: startOffset
|
|
407
|
+
} = cursorToNodeWithOffset(aCursor);
|
|
408
|
+
const {
|
|
409
|
+
node: endContainer,
|
|
410
|
+
offset: endOffset
|
|
411
|
+
} = cursorToNodeWithOffset(bCursor);
|
|
391
412
|
return {
|
|
392
413
|
startContainer,
|
|
393
414
|
startOffset,
|
|
@@ -395,13 +416,13 @@ const createSpanningRange = (aCursor, bCursor) => {
|
|
|
395
416
|
endOffset
|
|
396
417
|
};
|
|
397
418
|
};
|
|
398
|
-
const removePrevSiblings =
|
|
419
|
+
const removePrevSiblings = $node => {
|
|
399
420
|
let $n;
|
|
400
421
|
while (($n = $node.previousSibling) !== null) {
|
|
401
422
|
$n.remove();
|
|
402
423
|
}
|
|
403
424
|
};
|
|
404
|
-
const removeNextSiblings =
|
|
425
|
+
const removeNextSiblings = $node => {
|
|
405
426
|
let $n;
|
|
406
427
|
while (($n = $node.nextSibling) !== null) {
|
|
407
428
|
$n.remove();
|
|
@@ -438,11 +459,9 @@ const removeNodesBetween = (aCursor, bCursor) => {
|
|
|
438
459
|
}
|
|
439
460
|
removeSiblingsBetween($cpChildA, $cpChildB);
|
|
440
461
|
};
|
|
441
|
-
const ensureCorrectTextBlockIfEmpty =
|
|
462
|
+
const ensureCorrectTextBlockIfEmpty = $node => {
|
|
442
463
|
if (!$node.hasChildNodes()) {
|
|
443
|
-
$node.append(
|
|
444
|
-
createEmptyInline($node.ownerDocument)
|
|
445
|
-
);
|
|
464
|
+
$node.append(createEmptyInline($node.ownerDocument));
|
|
446
465
|
return;
|
|
447
466
|
}
|
|
448
467
|
const children = $node.childNodes;
|
|
@@ -456,15 +475,15 @@ const ensureCorrectTextBlockIfEmpty = ($node) => {
|
|
|
456
475
|
}
|
|
457
476
|
}
|
|
458
477
|
};
|
|
459
|
-
const getChildText =
|
|
478
|
+
const getChildText = $node => {
|
|
460
479
|
if ($node.childNodes.length !== 1) {
|
|
461
|
-
throw new Error(
|
|
480
|
+
throw new Error('Should have exact 1 child');
|
|
462
481
|
}
|
|
463
482
|
const $child = $node.firstChild;
|
|
464
483
|
assertTextNode($child);
|
|
465
484
|
return $child;
|
|
466
485
|
};
|
|
467
|
-
const getChildTextContent =
|
|
486
|
+
const getChildTextContent = getFirstOrLastChild => $node => {
|
|
468
487
|
ensureCorrectTextBlockIfEmpty($node);
|
|
469
488
|
const $child = getFirstOrLastChild($node);
|
|
470
489
|
assertTextContent($child);
|
|
@@ -472,7 +491,7 @@ const getChildTextContent = (getFirstOrLastChild) => ($node) => {
|
|
|
472
491
|
};
|
|
473
492
|
const getLastTextContent = getChildTextContent(getLastChild);
|
|
474
493
|
const getFirstTextContent = getChildTextContent(getFirstChild);
|
|
475
|
-
const getFirstOrLastTextBlock =
|
|
494
|
+
const getFirstOrLastTextBlock = getFirstOrLastChild => $root => {
|
|
476
495
|
let $lc = getFirstOrLastChild($root);
|
|
477
496
|
if ($lc === null) {
|
|
478
497
|
$lc = createEmptyParagraph($root.ownerDocument);
|
|
@@ -493,7 +512,7 @@ const mergeSiblingTextNodes = ($a, aCursor, bCursor) => {
|
|
|
493
512
|
const bContent = getTextValue($b);
|
|
494
513
|
const aContentLength = isEmptyText(aContent) ? 0 : aContent.length;
|
|
495
514
|
const bContentLength = isEmptyText(bContent) ? 0 : bContent.length;
|
|
496
|
-
let resultText = (isEmptyText(aContent) ?
|
|
515
|
+
let resultText = (isEmptyText(aContent) ? '' : aContent) + (isEmptyText(bContent) ? '' : bContent);
|
|
497
516
|
const isEmptyResultText = resultText.length === 0;
|
|
498
517
|
if (aCursor.$text === $a) {
|
|
499
518
|
aCursor.offset = isEmptyResultText ? 1 : aCursor.offset;
|
|
@@ -589,7 +608,7 @@ const mergeNextTextBlock = ($a, aCursor, bCursor) => {
|
|
|
589
608
|
};
|
|
590
609
|
const sliceChildren = ($parent, index) => {
|
|
591
610
|
if (index < 0) {
|
|
592
|
-
throw new Error(
|
|
611
|
+
throw new Error('Not found');
|
|
593
612
|
}
|
|
594
613
|
const children = Array.from($parent.childNodes);
|
|
595
614
|
if (index === 0) {
|
|
@@ -603,10 +622,7 @@ const splitTextBlock = ($a, childIndex) => {
|
|
|
603
622
|
ensureCorrectTextBlockIfEmpty($a);
|
|
604
623
|
ensureCorrectTextBlockIfEmpty($b);
|
|
605
624
|
$a.after($b);
|
|
606
|
-
return [
|
|
607
|
-
$a,
|
|
608
|
-
$b
|
|
609
|
-
];
|
|
625
|
+
return [$a, $b];
|
|
610
626
|
};
|
|
611
627
|
const splitTextNode = ($aText, offset) => {
|
|
612
628
|
const content = getTextValue($aText);
|
|
@@ -646,42 +662,44 @@ const splitTextNodeAndInsertEmptyInline = ($n, offset) => {
|
|
|
646
662
|
}
|
|
647
663
|
return $inline;
|
|
648
664
|
};
|
|
649
|
-
const formatInline = (formatType, range) => {
|
|
665
|
+
export const formatInline = (formatType, range) => {
|
|
650
666
|
const aCursor = createIncomingCursorFromNodeWithOffset(range.startContainer, range.startOffset);
|
|
651
667
|
const bCursor = createIncomingCursorFromNodeWithOffset(range.endContainer, range.endOffset);
|
|
652
668
|
const formatName = FORMAT_TYPE_TO_NAME[formatType];
|
|
653
669
|
if (aCursor.$inline === bCursor.$inline && isTextNode(aCursor.$text)) {
|
|
654
|
-
const {
|
|
655
|
-
|
|
670
|
+
const {
|
|
671
|
+
$text,
|
|
672
|
+
$inline,
|
|
673
|
+
offset: startOffset
|
|
674
|
+
} = aCursor;
|
|
675
|
+
const {
|
|
676
|
+
offset: endOffset
|
|
677
|
+
} = bCursor;
|
|
656
678
|
if (isEmptyText($text.nodeValue)) {
|
|
657
679
|
assertInline($inline);
|
|
658
680
|
toggleInlineFormat($inline, formatName);
|
|
659
681
|
return {
|
|
660
682
|
prevent: true,
|
|
661
|
-
range: createCollapsedRange(
|
|
662
|
-
createEndCursorFromTextContent($inline)
|
|
663
|
-
)
|
|
683
|
+
range: createCollapsedRange(createEndCursorFromTextContent($inline))
|
|
664
684
|
};
|
|
665
685
|
}
|
|
666
686
|
if (startOffset === endOffset) {
|
|
667
|
-
const $
|
|
668
|
-
toggleInlineFormat($
|
|
687
|
+
const $newinline = splitTextNodeAndInsertEmptyInline($text, startOffset);
|
|
688
|
+
toggleInlineFormat($newinline, formatName);
|
|
669
689
|
return {
|
|
670
690
|
prevent: true,
|
|
671
|
-
range: createCollapsedRange(
|
|
672
|
-
createEndCursorFromTextContent($newinline2)
|
|
673
|
-
)
|
|
691
|
+
range: createCollapsedRange(createEndCursorFromTextContent($newinline))
|
|
674
692
|
};
|
|
675
693
|
}
|
|
676
694
|
const $newinline = sliceTextNode($text, startOffset, endOffset);
|
|
677
695
|
toggleInlineFormat($newinline, formatName);
|
|
678
|
-
const
|
|
679
|
-
const
|
|
680
|
-
mergeNextTextContentSibling($newinline,
|
|
681
|
-
mergePrevTextContentSibling($newinline,
|
|
696
|
+
const aTrackingCursor = createBeginCursorFromTextContent($newinline);
|
|
697
|
+
const bTrackingCursor = createEndCursorFromTextContent($newinline);
|
|
698
|
+
mergeNextTextContentSibling($newinline, aTrackingCursor, bTrackingCursor);
|
|
699
|
+
mergePrevTextContentSibling($newinline, aTrackingCursor, bTrackingCursor);
|
|
682
700
|
return {
|
|
683
701
|
prevent: true,
|
|
684
|
-
range: createSpanningRange(
|
|
702
|
+
range: createSpanningRange(aTrackingCursor, bTrackingCursor)
|
|
685
703
|
};
|
|
686
704
|
}
|
|
687
705
|
const areAllInline = isAllInsideFormatName(aCursor.$inline, bCursor.$inline, formatName);
|
|
@@ -724,7 +742,7 @@ const allSiblingsIncludingSatisfy = (aNode, bNode, func) => {
|
|
|
724
742
|
}
|
|
725
743
|
return true;
|
|
726
744
|
};
|
|
727
|
-
const formatIndent =
|
|
745
|
+
export const formatIndent = range => {
|
|
728
746
|
if (range.startContainer === range.endContainer && range.startOffset === range.endOffset && range.startOffset !== 0) {
|
|
729
747
|
return {
|
|
730
748
|
prevent: false
|
|
@@ -753,7 +771,7 @@ const formatIndent = (range) => {
|
|
|
753
771
|
range
|
|
754
772
|
};
|
|
755
773
|
};
|
|
756
|
-
const ensureListItemLevelsAreCorrect =
|
|
774
|
+
const ensureListItemLevelsAreCorrect = $li => {
|
|
757
775
|
if ($li === null) {
|
|
758
776
|
return;
|
|
759
777
|
}
|
|
@@ -770,7 +788,7 @@ const ensureListItemLevelsAreCorrect = ($li) => {
|
|
|
770
788
|
$block = getNextSiblingTextBlock($block);
|
|
771
789
|
}
|
|
772
790
|
};
|
|
773
|
-
const formatOutdent =
|
|
791
|
+
export const formatOutdent = range => {
|
|
774
792
|
if (range.startContainer === range.endContainer && range.startOffset === range.endOffset && range.startOffset !== 0) {
|
|
775
793
|
return {
|
|
776
794
|
prevent: false
|
|
@@ -798,7 +816,7 @@ const formatOutdent = (range) => {
|
|
|
798
816
|
range
|
|
799
817
|
};
|
|
800
818
|
};
|
|
801
|
-
const formatList = (isOrdered, range) => {
|
|
819
|
+
export const formatList = (isOrdered, range) => {
|
|
802
820
|
const aCursor = createIncomingCursorFromNodeWithOffset(range.startContainer, range.startOffset);
|
|
803
821
|
const bCursor = createIncomingCursorFromNodeWithOffset(range.endContainer, range.endOffset);
|
|
804
822
|
const aBlock = getParentTextBlock(aCursor.$inline);
|
|
@@ -807,11 +825,11 @@ const formatList = (isOrdered, range) => {
|
|
|
807
825
|
if (isInsideSameListType) {
|
|
808
826
|
assertListItem(aBlock);
|
|
809
827
|
assertListItem(bBlock);
|
|
810
|
-
const $
|
|
811
|
-
let $
|
|
812
|
-
while ($
|
|
813
|
-
convertToParagraph($
|
|
814
|
-
$
|
|
828
|
+
const $iterateUpToNode = getNextSiblingTextBlock(bBlock);
|
|
829
|
+
let $block = aBlock;
|
|
830
|
+
while ($block !== null && $block !== $iterateUpToNode) {
|
|
831
|
+
convertToParagraph($block);
|
|
832
|
+
$block = getNextSiblingTextBlock($block);
|
|
815
833
|
}
|
|
816
834
|
return {
|
|
817
835
|
prevent: true,
|
|
@@ -841,7 +859,7 @@ const createCursorFromTextNode = (node, offset) => {
|
|
|
841
859
|
offset: Math.min(node.length, offset)
|
|
842
860
|
};
|
|
843
861
|
};
|
|
844
|
-
const createBeginCursorFromTextContent =
|
|
862
|
+
const createBeginCursorFromTextContent = node => {
|
|
845
863
|
if (isInline(node)) {
|
|
846
864
|
const $text = getChildText(node);
|
|
847
865
|
const content = getTextValue($text);
|
|
@@ -857,7 +875,7 @@ const createBeginCursorFromTextContent = (node) => {
|
|
|
857
875
|
offset: 0
|
|
858
876
|
};
|
|
859
877
|
};
|
|
860
|
-
const createEndCursorFromTextContent =
|
|
878
|
+
const createEndCursorFromTextContent = node => {
|
|
861
879
|
if (isInline(node)) {
|
|
862
880
|
const $text = getChildText(node);
|
|
863
881
|
return {
|
|
@@ -886,9 +904,7 @@ const createIncomingCursorFromNodeWithOffset = (node, offset) => {
|
|
|
886
904
|
}
|
|
887
905
|
if (isTextBlock(node)) {
|
|
888
906
|
if (isAfterLastChildIndex(node, offset)) {
|
|
889
|
-
return createEndCursorFromTextContent(
|
|
890
|
-
getLastTextContent(node)
|
|
891
|
-
);
|
|
907
|
+
return createEndCursorFromTextContent(getLastTextContent(node));
|
|
892
908
|
}
|
|
893
909
|
return createIncomingCursorFromNodeWithOffset(getChildByIndex(node, offset), 0);
|
|
894
910
|
}
|
|
@@ -906,9 +922,15 @@ const createIncomingCursorFromNodeWithOffset = (node, offset) => {
|
|
|
906
922
|
}
|
|
907
923
|
return createIncomingCursorFromNodeWithOffset(getChildByIndex(node, offset), 0);
|
|
908
924
|
}
|
|
909
|
-
throw new Error(
|
|
925
|
+
throw new Error('Should not happen');
|
|
910
926
|
};
|
|
911
|
-
const cursorToNodeWithOffset =
|
|
927
|
+
const cursorToNodeWithOffset = _ref => {
|
|
928
|
+
let {
|
|
929
|
+
$text,
|
|
930
|
+
$inline,
|
|
931
|
+
offset,
|
|
932
|
+
isAfterInline
|
|
933
|
+
} = _ref;
|
|
912
934
|
if (isTextNode($text)) {
|
|
913
935
|
return {
|
|
914
936
|
node: $text,
|
|
@@ -922,15 +944,21 @@ const cursorToNodeWithOffset = ({ $text, $inline, offset, isAfterInline }) => {
|
|
|
922
944
|
offset: childIndex
|
|
923
945
|
};
|
|
924
946
|
};
|
|
925
|
-
const removeContentInRange =
|
|
947
|
+
const removeContentInRange = range => {
|
|
926
948
|
const aCursor = createIncomingCursorFromNodeWithOffset(range.startContainer, range.startOffset);
|
|
927
949
|
const bCursor = createIncomingCursorFromNodeWithOffset(range.endContainer, range.endOffset);
|
|
928
950
|
if (aCursor.$inline === bCursor.$inline && aCursor.offset === bCursor.offset && aCursor.isAfterInline === bCursor.isAfterInline) {
|
|
929
951
|
return aCursor;
|
|
930
952
|
}
|
|
931
953
|
if (aCursor.$text === bCursor.$text && isTextNode(aCursor.$text)) {
|
|
932
|
-
const {
|
|
933
|
-
|
|
954
|
+
const {
|
|
955
|
+
$text,
|
|
956
|
+
$inline,
|
|
957
|
+
offset: startOffset
|
|
958
|
+
} = aCursor;
|
|
959
|
+
const {
|
|
960
|
+
offset: endOffset
|
|
961
|
+
} = bCursor;
|
|
934
962
|
const content = getTextValue($text);
|
|
935
963
|
const nextContent = content.substring(0, startOffset) + content.substring(endOffset);
|
|
936
964
|
$text.nodeValue = nextContent;
|
|
@@ -982,8 +1010,13 @@ const removeContentInRange = (range) => {
|
|
|
982
1010
|
}
|
|
983
1011
|
return trackingCursor;
|
|
984
1012
|
};
|
|
985
|
-
const deleteContentBackward = ($root, range) => {
|
|
986
|
-
const {
|
|
1013
|
+
export const deleteContentBackward = ($root, range) => {
|
|
1014
|
+
const {
|
|
1015
|
+
startContainer,
|
|
1016
|
+
endContainer,
|
|
1017
|
+
startOffset,
|
|
1018
|
+
endOffset
|
|
1019
|
+
} = range;
|
|
987
1020
|
if (startContainer === endContainer && startOffset + 1 === endOffset && isTextNode(startContainer)) {
|
|
988
1021
|
if (startContainer.length > 1) {
|
|
989
1022
|
return DEFAULT_ACTION_RESULT;
|
|
@@ -1033,14 +1066,17 @@ const deleteContentBackward = ($root, range) => {
|
|
|
1033
1066
|
}
|
|
1034
1067
|
return {
|
|
1035
1068
|
prevent: true,
|
|
1036
|
-
range: createCollapsedRange(
|
|
1037
|
-
removeContentInRange(range)
|
|
1038
|
-
)
|
|
1069
|
+
range: createCollapsedRange(removeContentInRange(range))
|
|
1039
1070
|
};
|
|
1040
1071
|
};
|
|
1041
|
-
const insertLink = ($root, text, href, range) => {
|
|
1072
|
+
export const insertLink = ($root, text, href, range) => {
|
|
1042
1073
|
const cursor = removeContentInRange(range);
|
|
1043
|
-
const {
|
|
1074
|
+
const {
|
|
1075
|
+
$text,
|
|
1076
|
+
$inline,
|
|
1077
|
+
offset,
|
|
1078
|
+
isAfterInline: isAfterLastChild
|
|
1079
|
+
} = cursor;
|
|
1044
1080
|
const $link = createLink(text, href, $root.ownerDocument);
|
|
1045
1081
|
if (isTextNode($text)) {
|
|
1046
1082
|
if (isEmptyText($text.nodeValue)) {
|
|
@@ -1061,23 +1097,24 @@ const insertLink = ($root, text, href, range) => {
|
|
|
1061
1097
|
}
|
|
1062
1098
|
return {
|
|
1063
1099
|
prevent: true,
|
|
1064
|
-
range: createCollapsedRange(
|
|
1065
|
-
createEndCursorFromTextContent($link)
|
|
1066
|
-
)
|
|
1100
|
+
range: createCollapsedRange(createEndCursorFromTextContent($link))
|
|
1067
1101
|
};
|
|
1068
1102
|
};
|
|
1069
|
-
const insertLineBreak =
|
|
1103
|
+
export const insertLineBreak = range => {
|
|
1070
1104
|
const cursor = removeContentInRange(range);
|
|
1071
|
-
const {
|
|
1105
|
+
const {
|
|
1106
|
+
$text,
|
|
1107
|
+
$inline,
|
|
1108
|
+
offset,
|
|
1109
|
+
isAfterInline: isAfterLastChild
|
|
1110
|
+
} = cursor;
|
|
1072
1111
|
const $block = getParentTextBlock($inline);
|
|
1073
1112
|
if (isListItem($block)) {
|
|
1074
1113
|
if (isEmptyTextBlock($block)) {
|
|
1075
1114
|
convertToParagraph($block);
|
|
1076
1115
|
return {
|
|
1077
1116
|
prevent: true,
|
|
1078
|
-
range: createCollapsedRange(
|
|
1079
|
-
createEndCursorFromTextContent(getLastTextContent($block))
|
|
1080
|
-
)
|
|
1117
|
+
range: createCollapsedRange(createEndCursorFromTextContent(getLastTextContent($block)))
|
|
1081
1118
|
};
|
|
1082
1119
|
}
|
|
1083
1120
|
}
|
|
@@ -1091,14 +1128,17 @@ const insertLineBreak = (range) => {
|
|
|
1091
1128
|
const [_, $bBlock] = splitTextBlock($block, splitIndex);
|
|
1092
1129
|
return {
|
|
1093
1130
|
prevent: true,
|
|
1094
|
-
range: createCollapsedRange(
|
|
1095
|
-
createBeginCursorFromTextContent(getFirstTextContent($bBlock))
|
|
1096
|
-
)
|
|
1131
|
+
range: createCollapsedRange(createBeginCursorFromTextContent(getFirstTextContent($bBlock)))
|
|
1097
1132
|
};
|
|
1098
1133
|
};
|
|
1099
1134
|
const insertEmoji = ($root, emojiChar, range) => {
|
|
1100
1135
|
const cursor = removeContentInRange(range);
|
|
1101
|
-
const {
|
|
1136
|
+
const {
|
|
1137
|
+
$text,
|
|
1138
|
+
$inline,
|
|
1139
|
+
offset,
|
|
1140
|
+
isAfterInline
|
|
1141
|
+
} = cursor;
|
|
1102
1142
|
const baseUrl = getEmojiBaseUrl($root);
|
|
1103
1143
|
const $emoji = createEmoji(emojiChar, baseUrl, $root.ownerDocument);
|
|
1104
1144
|
if (isTextNode($text)) {
|
|
@@ -1120,22 +1160,16 @@ const insertEmoji = ($root, emojiChar, range) => {
|
|
|
1120
1160
|
}
|
|
1121
1161
|
return {
|
|
1122
1162
|
prevent: true,
|
|
1123
|
-
range: createCollapsedRange(
|
|
1124
|
-
createEndCursorFromTextContent($emoji)
|
|
1125
|
-
)
|
|
1163
|
+
range: createCollapsedRange(createEndCursorFromTextContent($emoji))
|
|
1126
1164
|
};
|
|
1127
1165
|
};
|
|
1128
|
-
const insertText = ($root, data, range) => {
|
|
1166
|
+
export const insertText = ($root, data, range) => {
|
|
1129
1167
|
if (data !== null && isEmojiString(data)) {
|
|
1130
1168
|
return insertEmoji($root, data, range);
|
|
1131
1169
|
}
|
|
1132
|
-
if (
|
|
1133
|
-
|
|
1134
|
-
range.
|
|
1135
|
-
isTextNode(range.startContainer) && !isEmptyText(range.startContainer.nodeValue)
|
|
1136
|
-
) {
|
|
1137
|
-
const $inline2 = getParentInline(range.startContainer);
|
|
1138
|
-
const isHotTextWhitespace = range.startOffset === range.startContainer.length && data === TEXT_WHITESPACE && (isFormatCodetag($inline2) || isFormatLink($inline2));
|
|
1170
|
+
if (range.startContainer === range.endContainer && range.startOffset === range.endOffset && isTextNode(range.startContainer) && !isEmptyText(range.startContainer.nodeValue)) {
|
|
1171
|
+
const $inline = getParentInline(range.startContainer);
|
|
1172
|
+
const isHotTextWhitespace = range.startOffset === range.startContainer.length && data === TEXT_WHITESPACE && (isFormatCodetag($inline) || isFormatLink($inline));
|
|
1139
1173
|
if (!isHotTextWhitespace) {
|
|
1140
1174
|
return DEFAULT_ACTION_RESULT;
|
|
1141
1175
|
}
|
|
@@ -1147,7 +1181,12 @@ const insertText = ($root, data, range) => {
|
|
|
1147
1181
|
range: createCollapsedRange(cursor)
|
|
1148
1182
|
};
|
|
1149
1183
|
}
|
|
1150
|
-
const {
|
|
1184
|
+
const {
|
|
1185
|
+
$text,
|
|
1186
|
+
$inline,
|
|
1187
|
+
offset,
|
|
1188
|
+
isAfterInline
|
|
1189
|
+
} = cursor;
|
|
1151
1190
|
if ($text === null && isEmoji($inline)) {
|
|
1152
1191
|
const $newInline = createInlineWithText(data, $root.ownerDocument);
|
|
1153
1192
|
if (isAfterInline === true) {
|
|
@@ -1157,9 +1196,7 @@ const insertText = ($root, data, range) => {
|
|
|
1157
1196
|
}
|
|
1158
1197
|
return {
|
|
1159
1198
|
prevent: true,
|
|
1160
|
-
range: createCollapsedRange(
|
|
1161
|
-
createEndCursorFromTextContent($newInline)
|
|
1162
|
-
)
|
|
1199
|
+
range: createCollapsedRange(createEndCursorFromTextContent($newInline))
|
|
1163
1200
|
};
|
|
1164
1201
|
}
|
|
1165
1202
|
if (isTextNode($text)) {
|
|
@@ -1168,9 +1205,7 @@ const insertText = ($root, data, range) => {
|
|
|
1168
1205
|
$text.nodeValue = data;
|
|
1169
1206
|
return {
|
|
1170
1207
|
prevent: true,
|
|
1171
|
-
range: createCollapsedRange(
|
|
1172
|
-
createCursorFromTextNode($text, data.length)
|
|
1173
|
-
)
|
|
1208
|
+
range: createCollapsedRange(createCursorFromTextNode($text, data.length))
|
|
1174
1209
|
};
|
|
1175
1210
|
}
|
|
1176
1211
|
if (offset === $text.length && data === TEXT_WHITESPACE) {
|
|
@@ -1179,9 +1214,7 @@ const insertText = ($root, data, range) => {
|
|
|
1179
1214
|
$inline.after($newinline);
|
|
1180
1215
|
return {
|
|
1181
1216
|
prevent: true,
|
|
1182
|
-
range: createCollapsedRange(
|
|
1183
|
-
createEndCursorFromTextContent($newinline)
|
|
1184
|
-
)
|
|
1217
|
+
range: createCollapsedRange(createEndCursorFromTextContent($newinline))
|
|
1185
1218
|
};
|
|
1186
1219
|
}
|
|
1187
1220
|
}
|
|
@@ -1189,9 +1222,7 @@ const insertText = ($root, data, range) => {
|
|
|
1189
1222
|
$text.nodeValue = content.substring(0, offset) + data + content.substring(offset);
|
|
1190
1223
|
return {
|
|
1191
1224
|
prevent: true,
|
|
1192
|
-
range: createCollapsedRange(
|
|
1193
|
-
createCursorFromTextNode($text, offset + data.length)
|
|
1194
|
-
)
|
|
1225
|
+
range: createCollapsedRange(createCursorFromTextNode($text, offset + data.length))
|
|
1195
1226
|
};
|
|
1196
1227
|
}
|
|
1197
1228
|
return {
|
|
@@ -1199,9 +1230,14 @@ const insertText = ($root, data, range) => {
|
|
|
1199
1230
|
range: createCollapsedRange(cursor)
|
|
1200
1231
|
};
|
|
1201
1232
|
};
|
|
1202
|
-
const insertFromPaste = (data, range, visitor) => {
|
|
1233
|
+
export const insertFromPaste = (data, range, visitor) => {
|
|
1203
1234
|
const cursor = removeContentInRange(range);
|
|
1204
|
-
const {
|
|
1235
|
+
const {
|
|
1236
|
+
$text,
|
|
1237
|
+
$inline,
|
|
1238
|
+
offset,
|
|
1239
|
+
isAfterInline
|
|
1240
|
+
} = cursor;
|
|
1205
1241
|
const $mdFragment = parseMarkdown(data, visitor);
|
|
1206
1242
|
if ($mdFragment.childNodes.length === 0) {
|
|
1207
1243
|
return {
|
|
@@ -1211,7 +1247,7 @@ const insertFromPaste = (data, range, visitor) => {
|
|
|
1211
1247
|
}
|
|
1212
1248
|
const shouldSpreadNodesIntoBlock = $mdFragment.childNodes.length === 1;
|
|
1213
1249
|
if (shouldSpreadNodesIntoBlock) {
|
|
1214
|
-
const $
|
|
1250
|
+
const $block = getParentTextBlock($inline);
|
|
1215
1251
|
const $fragment = document.createDocumentFragment();
|
|
1216
1252
|
$fragment.append(...Array.from($mdFragment.childNodes[0].childNodes));
|
|
1217
1253
|
const $pasteLastChild = $fragment.lastChild;
|
|
@@ -1220,7 +1256,7 @@ const insertFromPaste = (data, range, visitor) => {
|
|
|
1220
1256
|
}
|
|
1221
1257
|
if (isTextNode($text)) {
|
|
1222
1258
|
if (isEmptyText($text.nodeValue)) {
|
|
1223
|
-
$
|
|
1259
|
+
$block.replaceChild($fragment, $inline);
|
|
1224
1260
|
} else {
|
|
1225
1261
|
const [$before, $after] = splitTextNode($text, offset);
|
|
1226
1262
|
if ($before === null) {
|
|
@@ -1237,9 +1273,7 @@ const insertFromPaste = (data, range, visitor) => {
|
|
|
1237
1273
|
}
|
|
1238
1274
|
return {
|
|
1239
1275
|
prevent: true,
|
|
1240
|
-
range: createCollapsedRange(
|
|
1241
|
-
createEndCursorFromTextContent($pasteLastChild ?? getLastTextContent($block2))
|
|
1242
|
-
)
|
|
1276
|
+
range: createCollapsedRange(createEndCursorFromTextContent($pasteLastChild ?? getLastTextContent($block)))
|
|
1243
1277
|
};
|
|
1244
1278
|
}
|
|
1245
1279
|
const $block = getParentTextBlock($inline);
|
|
@@ -1270,46 +1304,39 @@ const insertFromPaste = (data, range, visitor) => {
|
|
|
1270
1304
|
}
|
|
1271
1305
|
return {
|
|
1272
1306
|
prevent: true,
|
|
1273
|
-
range: createCollapsedRange(
|
|
1274
|
-
createEndCursorFromTextContent(
|
|
1275
|
-
getLastTextContent($lastBlock)
|
|
1276
|
-
)
|
|
1277
|
-
)
|
|
1307
|
+
range: createCollapsedRange(createEndCursorFromTextContent(getLastTextContent($lastBlock)))
|
|
1278
1308
|
};
|
|
1279
1309
|
};
|
|
1280
1310
|
const DEFAULT_ACTION_RESULT = {
|
|
1281
1311
|
prevent: false
|
|
1282
1312
|
};
|
|
1283
|
-
const handleEmojiMousedown =
|
|
1313
|
+
export const handleEmojiMousedown = $n => {
|
|
1284
1314
|
if (isEmoji($n)) {
|
|
1285
1315
|
return {
|
|
1286
1316
|
prevent: true,
|
|
1287
|
-
range: createCollapsedRange(
|
|
1288
|
-
createEndCursorFromTextContent($n)
|
|
1289
|
-
)
|
|
1317
|
+
range: createCollapsedRange(createEndCursorFromTextContent($n))
|
|
1290
1318
|
};
|
|
1291
1319
|
}
|
|
1292
1320
|
return DEFAULT_ACTION_RESULT;
|
|
1293
1321
|
};
|
|
1294
|
-
const getBeginRange =
|
|
1322
|
+
export const getBeginRange = $root => {
|
|
1295
1323
|
const $block = getFirstTextBlock($root);
|
|
1296
1324
|
const $inline = getFirstTextContent($block);
|
|
1297
|
-
return createCollapsedRange(
|
|
1298
|
-
createBeginCursorFromTextContent($inline)
|
|
1299
|
-
);
|
|
1325
|
+
return createCollapsedRange(createBeginCursorFromTextContent($inline));
|
|
1300
1326
|
};
|
|
1301
|
-
const getEndRange =
|
|
1327
|
+
export const getEndRange = $root => {
|
|
1302
1328
|
const $block = getLastTextBlock($root);
|
|
1303
1329
|
const $inline = getLastTextContent($block);
|
|
1304
|
-
return createCollapsedRange(
|
|
1305
|
-
createEndCursorFromTextContent($inline)
|
|
1306
|
-
);
|
|
1330
|
+
return createCollapsedRange(createEndCursorFromTextContent($inline));
|
|
1307
1331
|
};
|
|
1308
|
-
const getSelectionInfo =
|
|
1332
|
+
export const getSelectionInfo = range => {
|
|
1309
1333
|
const aCursor = createIncomingCursorFromNodeWithOffset(range.startContainer, range.startOffset);
|
|
1310
1334
|
const bCursor = createIncomingCursorFromNodeWithOffset(range.endContainer, range.endOffset);
|
|
1311
1335
|
if (aCursor.$inline === bCursor.$inline) {
|
|
1312
|
-
const {
|
|
1336
|
+
const {
|
|
1337
|
+
$text,
|
|
1338
|
+
$inline
|
|
1339
|
+
} = aCursor;
|
|
1313
1340
|
if ($text !== null || isInline($inline)) {
|
|
1314
1341
|
assertInline($inline);
|
|
1315
1342
|
return {
|
|
@@ -1342,19 +1369,19 @@ const getSelectionInfo = (range) => {
|
|
|
1342
1369
|
ulist: isAllInsideList(false, aCursor.$inline, bCursor.$inline)
|
|
1343
1370
|
};
|
|
1344
1371
|
};
|
|
1345
|
-
const isSelectionEqual = (a, b) => {
|
|
1372
|
+
export const isSelectionEqual = (a, b) => {
|
|
1346
1373
|
return a === b || a !== null && b !== null && a.bold === b.bold && a.codetag === b.codetag && a.italic === b.italic && a.link === b.link && a.strikethrough === b.strikethrough && a.olist === b.olist && a.ulist === b.ulist;
|
|
1347
1374
|
};
|
|
1348
|
-
const isEmptyTextBlock =
|
|
1375
|
+
const isEmptyTextBlock = $block => {
|
|
1349
1376
|
const blockChildren = $block.childNodes;
|
|
1350
1377
|
if (blockChildren.length > 1) {
|
|
1351
1378
|
return false;
|
|
1352
1379
|
}
|
|
1353
1380
|
const $inline = blockChildren[0];
|
|
1354
|
-
const
|
|
1355
|
-
return
|
|
1381
|
+
const isEmptyText = isInline($inline) && !isFormatCodetag($inline) && isEmptyTextNode(getChildText($inline));
|
|
1382
|
+
return isEmptyText;
|
|
1356
1383
|
};
|
|
1357
|
-
const isEditorEmpty =
|
|
1384
|
+
export const isEditorEmpty = $root => {
|
|
1358
1385
|
const rootChildren = $root.childNodes;
|
|
1359
1386
|
if (rootChildren.length > 1) {
|
|
1360
1387
|
return false;
|
|
@@ -1363,16 +1390,19 @@ const isEditorEmpty = ($root) => {
|
|
|
1363
1390
|
assertTextBlock($block);
|
|
1364
1391
|
return isEmptyTextBlock($block);
|
|
1365
1392
|
};
|
|
1366
|
-
const serializeDescriptorReducer =
|
|
1393
|
+
const serializeDescriptorReducer = range => (state, $n) => {
|
|
1367
1394
|
if (isEmoji($n)) {
|
|
1368
|
-
const
|
|
1369
|
-
if (
|
|
1370
|
-
state.push({
|
|
1395
|
+
const text = $n.getAttribute(EMOJI_CHAR_ATTR_NAME) ?? '';
|
|
1396
|
+
if (text.length > 0) {
|
|
1397
|
+
state.push({
|
|
1398
|
+
isEmoji: true,
|
|
1399
|
+
text
|
|
1400
|
+
});
|
|
1371
1401
|
}
|
|
1372
1402
|
return state;
|
|
1373
1403
|
}
|
|
1374
1404
|
let text = getTextValue(getChildText($n));
|
|
1375
|
-
let trailingSpaces =
|
|
1405
|
+
let trailingSpaces = '';
|
|
1376
1406
|
if (range !== null) {
|
|
1377
1407
|
const [aCursor, bCursor] = range;
|
|
1378
1408
|
const isACursorPointingHere = aCursor.$inline === $n;
|
|
@@ -1389,21 +1419,34 @@ const serializeDescriptorReducer = (range) => (state, $n) => {
|
|
|
1389
1419
|
return state;
|
|
1390
1420
|
}
|
|
1391
1421
|
if (isFormatCodetag($n)) {
|
|
1392
|
-
state.push({
|
|
1422
|
+
state.push({
|
|
1423
|
+
isCodetag: true,
|
|
1424
|
+
text
|
|
1425
|
+
});
|
|
1393
1426
|
return state;
|
|
1394
1427
|
}
|
|
1395
1428
|
if (isFormatLink($n)) {
|
|
1396
|
-
const href = $n.getAttribute(LINK_HREF_ATTR_NAME) ??
|
|
1397
|
-
state.push({
|
|
1429
|
+
const href = $n.getAttribute(LINK_HREF_ATTR_NAME) ?? '#';
|
|
1430
|
+
state.push({
|
|
1431
|
+
isLink: true,
|
|
1432
|
+
text,
|
|
1433
|
+
href
|
|
1434
|
+
});
|
|
1398
1435
|
return state;
|
|
1399
1436
|
}
|
|
1400
1437
|
const leadingNonSpaceIndex = text.search(/\S/);
|
|
1401
1438
|
if (leadingNonSpaceIndex < 0) {
|
|
1402
|
-
state.push({
|
|
1439
|
+
state.push({
|
|
1440
|
+
isWhitespace: true,
|
|
1441
|
+
text
|
|
1442
|
+
});
|
|
1403
1443
|
return state;
|
|
1404
1444
|
}
|
|
1405
1445
|
if (leadingNonSpaceIndex > 0) {
|
|
1406
|
-
state.push({
|
|
1446
|
+
state.push({
|
|
1447
|
+
isWhitespace: true,
|
|
1448
|
+
text: text.substring(0, leadingNonSpaceIndex)
|
|
1449
|
+
});
|
|
1407
1450
|
text = text.substring(leadingNonSpaceIndex);
|
|
1408
1451
|
}
|
|
1409
1452
|
const trailingSpaceIndex = text.search(/\s+$/);
|
|
@@ -1418,25 +1461,30 @@ const serializeDescriptorReducer = (range) => (state, $n) => {
|
|
|
1418
1461
|
text
|
|
1419
1462
|
});
|
|
1420
1463
|
if (trailingSpaces.length > 0) {
|
|
1421
|
-
state.push({
|
|
1464
|
+
state.push({
|
|
1465
|
+
isWhitespace: true,
|
|
1466
|
+
text: trailingSpaces
|
|
1467
|
+
});
|
|
1422
1468
|
}
|
|
1423
1469
|
return state;
|
|
1424
1470
|
};
|
|
1425
|
-
const MD_STRIKE_TOKEN =
|
|
1426
|
-
const MD_EM3_STAR_TOKEN =
|
|
1427
|
-
const MD_EM2_STAR_TOKEN =
|
|
1428
|
-
const MD_EM1_STAR_TOKEN =
|
|
1429
|
-
const MD_EM3_UNDERSCORE_TOKEN =
|
|
1430
|
-
const MD_EM2_UNDERSCORE_TOKEN =
|
|
1431
|
-
const MD_EM1_UNDERSCORE_TOKEN =
|
|
1432
|
-
const MD_LINEBREAK_TOKEN =
|
|
1433
|
-
const MD_CODETAG_TOKEN =
|
|
1434
|
-
const MD_ULISTITEM_TOKEN =
|
|
1435
|
-
const MD_OLISTITEM_TOKEN =
|
|
1436
|
-
const MD_LISTITEM_JOIN =
|
|
1437
|
-
const MD_PARAGRAPH_JOIN =
|
|
1471
|
+
const MD_STRIKE_TOKEN = '~~';
|
|
1472
|
+
const MD_EM3_STAR_TOKEN = '***';
|
|
1473
|
+
const MD_EM2_STAR_TOKEN = '**';
|
|
1474
|
+
const MD_EM1_STAR_TOKEN = '*';
|
|
1475
|
+
const MD_EM3_UNDERSCORE_TOKEN = '___';
|
|
1476
|
+
const MD_EM2_UNDERSCORE_TOKEN = '__';
|
|
1477
|
+
const MD_EM1_UNDERSCORE_TOKEN = '_';
|
|
1478
|
+
const MD_LINEBREAK_TOKEN = ' \n';
|
|
1479
|
+
const MD_CODETAG_TOKEN = '`';
|
|
1480
|
+
const MD_ULISTITEM_TOKEN = '*';
|
|
1481
|
+
const MD_OLISTITEM_TOKEN = '1.';
|
|
1482
|
+
const MD_LISTITEM_JOIN = '\n';
|
|
1483
|
+
const MD_PARAGRAPH_JOIN = '\n\n';
|
|
1438
1484
|
const serializeTextReducer = (state, desc, i, descArray) => {
|
|
1439
|
-
const {
|
|
1485
|
+
const {
|
|
1486
|
+
chunks
|
|
1487
|
+
} = state;
|
|
1440
1488
|
if (desc.isLink === true) {
|
|
1441
1489
|
chunks.push(`[${desc.text}](${desc.href})`);
|
|
1442
1490
|
return state;
|
|
@@ -1456,7 +1504,11 @@ const serializeTextReducer = (state, desc, i, descArray) => {
|
|
|
1456
1504
|
const prev = i === 0 ? null : descArray[i - 1];
|
|
1457
1505
|
const next = i >= descArray.length - 1 ? null : descArray[i + 1];
|
|
1458
1506
|
const shouldUseUnderscores = (i - state.lastUnderscoreIndex) % 2 === 0 && (prev === null || prev.isBold === true || prev.isItalic === true || prev.isWhitespace === true || prev.isCodetag === true) && (next === null || next.isBold === true || next.isItalic === true || next.isWhitespace === true || next.isCodetag === true);
|
|
1459
|
-
const {
|
|
1507
|
+
const {
|
|
1508
|
+
isBold,
|
|
1509
|
+
isItalic,
|
|
1510
|
+
isStrikethrough
|
|
1511
|
+
} = desc;
|
|
1460
1512
|
if (shouldUseUnderscores) {
|
|
1461
1513
|
state.lastUnderscoreIndex = i;
|
|
1462
1514
|
}
|
|
@@ -1495,26 +1547,16 @@ const serializeTextBlock = ($n, range) => {
|
|
|
1495
1547
|
} else {
|
|
1496
1548
|
children = Array.from($n.childNodes);
|
|
1497
1549
|
}
|
|
1498
|
-
const result = children.reduce(
|
|
1499
|
-
|
|
1500
|
-
[]
|
|
1501
|
-
)
|
|
1502
|
-
|
|
1503
|
-
{
|
|
1504
|
-
lastUnderscoreIndex: 0,
|
|
1505
|
-
chunks: []
|
|
1506
|
-
}
|
|
1507
|
-
);
|
|
1508
|
-
return result.chunks.join("");
|
|
1550
|
+
const result = children.reduce(serializeDescriptorReducer(range), []).reduce(serializeTextReducer, {
|
|
1551
|
+
lastUnderscoreIndex: 0,
|
|
1552
|
+
chunks: []
|
|
1553
|
+
});
|
|
1554
|
+
return result.chunks.join('');
|
|
1509
1555
|
};
|
|
1510
1556
|
const serializeListItemIndent = (level, isOrderedStack) => {
|
|
1511
|
-
let res =
|
|
1557
|
+
let res = '';
|
|
1512
1558
|
for (let i = 0; i < level; i++) {
|
|
1513
|
-
res = res.concat(
|
|
1514
|
-
isOrderedStack[i] ? " " : " ",
|
|
1515
|
-
// MD_ULISTITEM_TOKEN.length
|
|
1516
|
-
" "
|
|
1517
|
-
);
|
|
1559
|
+
res = res.concat(isOrderedStack[i] ? ' ' : ' ', ' ');
|
|
1518
1560
|
}
|
|
1519
1561
|
return res;
|
|
1520
1562
|
};
|
|
@@ -1543,19 +1585,15 @@ const serializeRoot = ($root, range) => {
|
|
|
1543
1585
|
const paragraphChunks = [];
|
|
1544
1586
|
const flushListChunks = () => {
|
|
1545
1587
|
if (listChunks.length > 0) {
|
|
1546
|
-
chunks.push(
|
|
1547
|
-
listChunks.join(MD_LISTITEM_JOIN)
|
|
1548
|
-
);
|
|
1588
|
+
chunks.push(listChunks.join(MD_LISTITEM_JOIN));
|
|
1549
1589
|
listChunks.length = 0;
|
|
1550
1590
|
}
|
|
1551
1591
|
};
|
|
1552
1592
|
const flushParagraphChunks = () => {
|
|
1553
1593
|
if (paragraphChunks.length > 0) {
|
|
1554
|
-
chunks.push(
|
|
1555
|
-
|
|
1556
|
-
|
|
1557
|
-
})
|
|
1558
|
-
);
|
|
1594
|
+
chunks.push(paragraphChunks.reduce((a, b) => {
|
|
1595
|
+
return b.length > 0 ? a.concat(MD_LINEBREAK_TOKEN, b) : a.concat('<br>');
|
|
1596
|
+
}));
|
|
1559
1597
|
paragraphChunks.length = 0;
|
|
1560
1598
|
}
|
|
1561
1599
|
};
|
|
@@ -1567,22 +1605,18 @@ const serializeRoot = ($root, range) => {
|
|
|
1567
1605
|
if (isMainList) {
|
|
1568
1606
|
flushListChunks();
|
|
1569
1607
|
}
|
|
1570
|
-
listChunks.push(
|
|
1571
|
-
serializeListItem($child, listIsOrderedStack, range)
|
|
1572
|
-
);
|
|
1608
|
+
listChunks.push(serializeListItem($child, listIsOrderedStack, range));
|
|
1573
1609
|
} else {
|
|
1574
1610
|
assertTextBlock($child);
|
|
1575
1611
|
flushListChunks();
|
|
1576
|
-
paragraphChunks.push(
|
|
1577
|
-
serializeTextBlock($child, range)
|
|
1578
|
-
);
|
|
1612
|
+
paragraphChunks.push(serializeTextBlock($child, range));
|
|
1579
1613
|
}
|
|
1580
1614
|
}
|
|
1581
1615
|
flushListChunks();
|
|
1582
1616
|
flushParagraphChunks();
|
|
1583
1617
|
return chunks.join(MD_PARAGRAPH_JOIN);
|
|
1584
1618
|
};
|
|
1585
|
-
const serializeMarkdown = ($root, range) => {
|
|
1619
|
+
export const serializeMarkdown = ($root, range) => {
|
|
1586
1620
|
if (range !== null) {
|
|
1587
1621
|
const aCursor = createIncomingCursorFromNodeWithOffset(range.startContainer, range.startOffset);
|
|
1588
1622
|
const bCursor = createIncomingCursorFromNodeWithOffset(range.endContainer, range.endOffset);
|
|
@@ -1590,7 +1624,7 @@ const serializeMarkdown = ($root, range) => {
|
|
|
1590
1624
|
}
|
|
1591
1625
|
return serializeRoot($root, null);
|
|
1592
1626
|
};
|
|
1593
|
-
const createParseVisitor =
|
|
1627
|
+
export const createParseVisitor = doc => {
|
|
1594
1628
|
let emojiBaseUrl = null;
|
|
1595
1629
|
return {
|
|
1596
1630
|
updateEmojiBaseUrl(url) {
|
|
@@ -1617,14 +1651,19 @@ const createParseVisitor = (doc) => {
|
|
|
1617
1651
|
},
|
|
1618
1652
|
codetag(text) {
|
|
1619
1653
|
const $inline = createInlineWithText(text, doc);
|
|
1620
|
-
setInlineFormat($inline,
|
|
1654
|
+
setInlineFormat($inline, 'c', true);
|
|
1621
1655
|
$currentBlock.appendChild($inline);
|
|
1622
1656
|
},
|
|
1623
|
-
inline(text,
|
|
1657
|
+
inline(text, _ref2) {
|
|
1658
|
+
let {
|
|
1659
|
+
isBold,
|
|
1660
|
+
isItalic,
|
|
1661
|
+
isStrikethrough
|
|
1662
|
+
} = _ref2;
|
|
1624
1663
|
const $inline = createInlineWithText(text, doc);
|
|
1625
|
-
setInlineFormat($inline,
|
|
1626
|
-
setInlineFormat($inline,
|
|
1627
|
-
setInlineFormat($inline,
|
|
1664
|
+
setInlineFormat($inline, 'b', isBold === true);
|
|
1665
|
+
setInlineFormat($inline, 'i', isItalic === true);
|
|
1666
|
+
setInlineFormat($inline, 's', isStrikethrough === true);
|
|
1628
1667
|
$currentBlock.appendChild($inline);
|
|
1629
1668
|
},
|
|
1630
1669
|
linebreak() {
|
|
@@ -1651,7 +1690,9 @@ const createParseVisitor = (doc) => {
|
|
|
1651
1690
|
},
|
|
1652
1691
|
listItem() {
|
|
1653
1692
|
const listLevel = listsStack.length - 1;
|
|
1654
|
-
const {
|
|
1693
|
+
const {
|
|
1694
|
+
isOrdered
|
|
1695
|
+
} = listsStack.at(-1);
|
|
1655
1696
|
const $li = createActuallyEmptyListItem(isOrdered, listLevel, doc);
|
|
1656
1697
|
if (listsStack.length === 1 && isFirstListItem) {
|
|
1657
1698
|
markListItemAsBlock($li);
|
|
@@ -1679,7 +1720,13 @@ const createParseVisitor = (doc) => {
|
|
|
1679
1720
|
}
|
|
1680
1721
|
};
|
|
1681
1722
|
};
|
|
1682
|
-
const setBrowserCaret =
|
|
1723
|
+
export const setBrowserCaret = _ref3 => {
|
|
1724
|
+
let {
|
|
1725
|
+
startContainer,
|
|
1726
|
+
startOffset,
|
|
1727
|
+
endContainer,
|
|
1728
|
+
endOffset
|
|
1729
|
+
} = _ref3;
|
|
1683
1730
|
const selection = document.getSelection();
|
|
1684
1731
|
if (selection === null) {
|
|
1685
1732
|
return;
|
|
@@ -1689,24 +1736,4 @@ const setBrowserCaret = ({ startContainer, startOffset, endContainer, endOffset
|
|
|
1689
1736
|
range.setStart(startContainer, startOffset);
|
|
1690
1737
|
range.setEnd(endContainer, endOffset);
|
|
1691
1738
|
selection.addRange(range);
|
|
1692
|
-
};
|
|
1693
|
-
export {
|
|
1694
|
-
createParseVisitor,
|
|
1695
|
-
deleteContentBackward,
|
|
1696
|
-
formatIndent,
|
|
1697
|
-
formatInline,
|
|
1698
|
-
formatList,
|
|
1699
|
-
formatOutdent,
|
|
1700
|
-
getBeginRange,
|
|
1701
|
-
getEndRange,
|
|
1702
|
-
getSelectionInfo,
|
|
1703
|
-
handleEmojiMousedown,
|
|
1704
|
-
insertFromPaste,
|
|
1705
|
-
insertLineBreak,
|
|
1706
|
-
insertLink,
|
|
1707
|
-
insertText,
|
|
1708
|
-
isEditorEmpty,
|
|
1709
|
-
isSelectionEqual,
|
|
1710
|
-
serializeMarkdown,
|
|
1711
|
-
setBrowserCaret
|
|
1712
|
-
};
|
|
1739
|
+
};
|