lakelib 0.3.3 → 0.3.5
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/README.md +30 -24
- package/dist/lake.min.css +15 -15
- package/dist/lake.min.js +22 -22
- package/dist/lake.min.js.map +1 -1
- package/lib/lake.css +267 -39
- package/lib/lake.d.ts +2148 -0
- package/lib/lake.js +1323 -759
- package/lib/lake.js.map +1 -1
- package/package.json +31 -34
- package/lib/config/element-rules.d.ts +0 -1
- package/lib/config/menu-items.d.ts +0 -9
- package/lib/config/tag-names.d.ts +0 -6
- package/lib/config/toolbar-items.d.ts +0 -2
- package/lib/css/index.d.ts +0 -17
- package/lib/editor.d.ts +0 -93
- package/lib/elements/bookmark.d.ts +0 -2
- package/lib/elements/box.d.ts +0 -2
- package/lib/i18n/en-US/index.d.ts +0 -169
- package/lib/i18n/index.d.ts +0 -2
- package/lib/i18n/ja/index.d.ts +0 -169
- package/lib/i18n/ko/index.d.ts +0 -169
- package/lib/i18n/types.d.ts +0 -1233
- package/lib/i18n/zh-CN/index.d.ts +0 -169
- package/lib/icons/index.d.ts +0 -1
- package/lib/index.d.ts +0 -35
- package/lib/managers/box-manager.d.ts +0 -6
- package/lib/managers/command.d.ts +0 -23
- package/lib/managers/history.d.ts +0 -32
- package/lib/managers/keystroke.d.ts +0 -11
- package/lib/managers/plugin.d.ts +0 -7
- package/lib/managers/selection.d.ts +0 -40
- package/lib/models/box.d.ts +0 -25
- package/lib/models/fragment.d.ts +0 -8
- package/lib/models/nodes.d.ts +0 -98
- package/lib/models/range.d.ts +0 -56
- package/lib/operations/add-mark.d.ts +0 -3
- package/lib/operations/delete-contents.d.ts +0 -2
- package/lib/operations/insert-block.d.ts +0 -3
- package/lib/operations/insert-bookmark.d.ts +0 -6
- package/lib/operations/insert-box.d.ts +0 -4
- package/lib/operations/insert-contents.d.ts +0 -4
- package/lib/operations/remove-box.d.ts +0 -3
- package/lib/operations/remove-mark.d.ts +0 -2
- package/lib/operations/set-blocks.d.ts +0 -3
- package/lib/operations/split-block.d.ts +0 -3
- package/lib/operations/split-marks.d.ts +0 -3
- package/lib/operations/to-bookmark.d.ts +0 -6
- package/lib/parsers/html-parser.d.ts +0 -13
- package/lib/parsers/text-parser.d.ts +0 -6
- package/lib/plugins/align.d.ts +0 -3
- package/lib/plugins/arrow-keys.d.ts +0 -3
- package/lib/plugins/backspace-key.d.ts +0 -3
- package/lib/plugins/block-quote.d.ts +0 -3
- package/lib/plugins/bold.d.ts +0 -3
- package/lib/plugins/code-block/code-block-box.d.ts +0 -4
- package/lib/plugins/code-block/index.d.ts +0 -5
- package/lib/plugins/code.d.ts +0 -3
- package/lib/plugins/copy.d.ts +0 -3
- package/lib/plugins/cut.d.ts +0 -3
- package/lib/plugins/delete-key.d.ts +0 -3
- package/lib/plugins/drop.d.ts +0 -3
- package/lib/plugins/emoji/emoji-box.d.ts +0 -4
- package/lib/plugins/emoji/index.d.ts +0 -5
- package/lib/plugins/enter-key.d.ts +0 -3
- package/lib/plugins/equation/equation-box.d.ts +0 -4
- package/lib/plugins/equation/index.d.ts +0 -5
- package/lib/plugins/escape-key.d.ts +0 -3
- package/lib/plugins/file/file-box.d.ts +0 -4
- package/lib/plugins/file/index.d.ts +0 -5
- package/lib/plugins/font-color.d.ts +0 -3
- package/lib/plugins/font-family.d.ts +0 -3
- package/lib/plugins/font-size.d.ts +0 -3
- package/lib/plugins/format-painter.d.ts +0 -3
- package/lib/plugins/heading.d.ts +0 -3
- package/lib/plugins/highlight.d.ts +0 -3
- package/lib/plugins/hr/hr-box.d.ts +0 -4
- package/lib/plugins/hr/index.d.ts +0 -5
- package/lib/plugins/image/image-box.d.ts +0 -5
- package/lib/plugins/image/index.d.ts +0 -5
- package/lib/plugins/indent.d.ts +0 -3
- package/lib/plugins/italic.d.ts +0 -3
- package/lib/plugins/link/index.d.ts +0 -3
- package/lib/plugins/link/insert-link.d.ts +0 -3
- package/lib/plugins/link/link-popup.d.ts +0 -32
- package/lib/plugins/list.d.ts +0 -3
- package/lib/plugins/markdown.d.ts +0 -3
- package/lib/plugins/mention/index.d.ts +0 -5
- package/lib/plugins/mention/mention-box.d.ts +0 -4
- package/lib/plugins/mention/mention-menu.d.ts +0 -15
- package/lib/plugins/mention/types.d.ts +0 -6
- package/lib/plugins/paste.d.ts +0 -3
- package/lib/plugins/redo.d.ts +0 -3
- package/lib/plugins/remove-format.d.ts +0 -3
- package/lib/plugins/select-all.d.ts +0 -3
- package/lib/plugins/shift-enter-key.d.ts +0 -3
- package/lib/plugins/slash/index.d.ts +0 -3
- package/lib/plugins/slash/slash-items.d.ts +0 -2
- package/lib/plugins/slash/slash-menu.d.ts +0 -19
- package/lib/plugins/slash/types.d.ts +0 -20
- package/lib/plugins/special-character.d.ts +0 -3
- package/lib/plugins/strikethrough.d.ts +0 -3
- package/lib/plugins/subscript.d.ts +0 -3
- package/lib/plugins/superscript.d.ts +0 -3
- package/lib/plugins/tab-key.d.ts +0 -3
- package/lib/plugins/table/delete-column.d.ts +0 -2
- package/lib/plugins/table/delete-row.d.ts +0 -2
- package/lib/plugins/table/delete-table.d.ts +0 -2
- package/lib/plugins/table/index.d.ts +0 -4
- package/lib/plugins/table/insert-column.d.ts +0 -4
- package/lib/plugins/table/insert-row.d.ts +0 -4
- package/lib/plugins/table/insert-table.d.ts +0 -3
- package/lib/plugins/table/merge-cells.d.ts +0 -3
- package/lib/plugins/table/split-cell.d.ts +0 -3
- package/lib/plugins/table/utils.d.ts +0 -6
- package/lib/plugins/underline.d.ts +0 -3
- package/lib/plugins/undo.d.ts +0 -3
- package/lib/plugins/unlink.d.ts +0 -3
- package/lib/plugins/video/index.d.ts +0 -5
- package/lib/plugins/video/video-box.d.ts +0 -4
- package/lib/storage/box-instances.d.ts +0 -2
- package/lib/storage/boxes.d.ts +0 -2
- package/lib/storage/editors.d.ts +0 -2
- package/lib/types/box.d.ts +0 -15
- package/lib/types/corner-toolbar.d.ts +0 -7
- package/lib/types/dropdown.d.ts +0 -23
- package/lib/types/native.d.ts +0 -2
- package/lib/types/node.d.ts +0 -13
- package/lib/types/object.d.ts +0 -3
- package/lib/types/plugin.d.ts +0 -3
- package/lib/types/request.d.ts +0 -20
- package/lib/types/selection.d.ts +0 -14
- package/lib/types/toolbar.d.ts +0 -29
- package/lib/ui/button.d.ts +0 -19
- package/lib/ui/corner-toolbar.d.ts +0 -18
- package/lib/ui/dropdown.d.ts +0 -36
- package/lib/ui/floating-toolbar.d.ts +0 -16
- package/lib/ui/menu.d.ts +0 -33
- package/lib/ui/resizer.d.ts +0 -17
- package/lib/ui/toolbar.d.ts +0 -29
- package/lib/utils/append-break.d.ts +0 -2
- package/lib/utils/camel-case.d.ts +0 -1
- package/lib/utils/change-tag-name.d.ts +0 -2
- package/lib/utils/debug.d.ts +0 -1
- package/lib/utils/denormalize-value.d.ts +0 -1
- package/lib/utils/encode.d.ts +0 -1
- package/lib/utils/file-size.d.ts +0 -1
- package/lib/utils/fix-numbered-list.d.ts +0 -2
- package/lib/utils/from-base64.d.ts +0 -1
- package/lib/utils/get-box.d.ts +0 -3
- package/lib/utils/get-css.d.ts +0 -1
- package/lib/utils/get-deep-element.d.ts +0 -2
- package/lib/utils/in-string.d.ts +0 -1
- package/lib/utils/indent-block.d.ts +0 -2
- package/lib/utils/merge-nodes.d.ts +0 -5
- package/lib/utils/modifier-text.d.ts +0 -1
- package/lib/utils/morph.d.ts +0 -56
- package/lib/utils/normalize-value.d.ts +0 -1
- package/lib/utils/parse-style.d.ts +0 -2
- package/lib/utils/query.d.ts +0 -2
- package/lib/utils/remove-break.d.ts +0 -2
- package/lib/utils/remove-empty-marks.d.ts +0 -2
- package/lib/utils/remove-zws.d.ts +0 -2
- package/lib/utils/request.d.ts +0 -27
- package/lib/utils/scroll-to-node.d.ts +0 -2
- package/lib/utils/split-nodes.d.ts +0 -5
- package/lib/utils/template.d.ts +0 -1
- package/lib/utils/to-base64.d.ts +0 -1
- package/lib/utils/to-hex.d.ts +0 -1
- package/lib/utils/to-node-list.d.ts +0 -1
- package/lib/utils/unsafe-template.d.ts +0 -1
- package/lib/utils/upload-file.d.ts +0 -11
- package/lib/utils/visible-info.d.ts +0 -10
- package/lib/utils/wrap-node-list.d.ts +0 -2
package/lib/lake.js
CHANGED
|
@@ -37,7 +37,7 @@ var checkCircle = "<svg xmlns=\"http://www.w3.org/2000/svg\" width=\"32\" height
|
|
|
37
37
|
|
|
38
38
|
var warningCircle = "<svg xmlns=\"http://www.w3.org/2000/svg\" width=\"32\" height=\"32\" fill=\"#000000\" viewBox=\"0 0 256 256\"><path d=\"M128,24A104,104,0,1,0,232,128,104.11,104.11,0,0,0,128,24Zm0,192a88,88,0,1,1,88-88A88.1,88.1,0,0,1,128,216Zm-8-80V80a8,8,0,0,1,16,0v56a8,8,0,0,1-16,0Zm20,36a12,12,0,1,1-12-12A12,12,0,0,1,140,172Z\"></path></svg>";
|
|
39
39
|
|
|
40
|
-
var open = "<svg width=\"24\" height=\"24\" fill=\"
|
|
40
|
+
var open = "<svg width=\"24\" height=\"24\" fill=\"#000000\" viewBox=\"0 0 24 24\" xmlns=\"http://www.w3.org/2000/svg\"><path d=\"M6.25 4.5A1.75 1.75 0 0 0 4.5 6.25v11.5c0 .966.783 1.75 1.75 1.75h11.5a1.75 1.75 0 0 0 1.75-1.75v-4a.75.75 0 0 1 1.5 0v4A3.25 3.25 0 0 1 17.75 21H6.25A3.25 3.25 0 0 1 3 17.75V6.25A3.25 3.25 0 0 1 6.25 3h4a.75.75 0 0 1 0 1.5h-4ZM13 3.75a.75.75 0 0 1 .75-.75h6.5a.75.75 0 0 1 .75.75v6.5a.75.75 0 0 1-1.5 0V5.56l-5.22 5.22a.75.75 0 0 1-1.06-1.06l5.22-5.22h-4.69a.75.75 0 0 1-.75-.75Z\"/></svg>";
|
|
41
41
|
|
|
42
42
|
var download = "<svg xmlns=\"http://www.w3.org/2000/svg\" width=\"32\" height=\"32\" fill=\"#000000\" viewBox=\"0 0 256 256\"><path d=\"M224,144v64a8,8,0,0,1-8,8H40a8,8,0,0,1-8-8V144a8,8,0,0,1,16,0v56H208V144a8,8,0,0,1,16,0Zm-101.66,5.66a8,8,0,0,0,11.32,0l40-40a8,8,0,0,0-11.32-11.32L136,124.69V32a8,8,0,0,0-16,0v92.69L93.66,98.34a8,8,0,0,0-11.32,11.32Z\"></path></svg>";
|
|
43
43
|
|
|
@@ -109,9 +109,9 @@ var underline$1 = "<svg xmlns=\"http://www.w3.org/2000/svg\" width=\"32\" height
|
|
|
109
109
|
|
|
110
110
|
var strikethrough$1 = "<svg xmlns=\"http://www.w3.org/2000/svg\" width=\"32\" height=\"32\" fill=\"#000000\" viewBox=\"0 0 256 256\"><path d=\"M224,128a8,8,0,0,1-8,8H175.93c9.19,7.11,16.07,17.2,16.07,32,0,13.34-7,25.7-19.75,34.79C160.33,211.31,144.61,216,128,216s-32.33-4.69-44.25-13.21C71,193.7,64,181.34,64,168a8,8,0,0,1,16,0c0,17.35,22,32,48,32s48-14.65,48-32c0-14.85-10.54-23.58-38.77-32H40a8,8,0,0,1,0-16H216A8,8,0,0,1,224,128ZM76.33,104a8,8,0,0,0,7.61-10.49A17.3,17.3,0,0,1,83.11,88c0-18.24,19.3-32,44.89-32,18.84,0,34.16,7.42,41,19.85a8,8,0,0,0,14-7.7C173.33,50.52,152.77,40,128,40,93.29,40,67.11,60.63,67.11,88a33.73,33.73,0,0,0,1.62,10.49A8,8,0,0,0,76.33,104Z\"></path></svg>";
|
|
111
111
|
|
|
112
|
-
var superscript$1 = "<svg width=\"24\" height=\"24\" fill=\"
|
|
112
|
+
var superscript$1 = "<svg width=\"24\" height=\"24\" fill=\"#000000\" viewBox=\"0 0 24 24\" xmlns=\"http://www.w3.org/2000/svg\"><path d=\"M18.736 3.5c-.543 0-.986.495-.986 1.023a.75.75 0 0 1-1.5 0C16.25 3.278 17.258 2 18.736 2c.855 0 1.684.4 2.15 1.117.49.751.5 1.724-.057 2.672-.285.484-.673.847-1.045 1.141-.187.148-.379.284-.557.41l-.078.056a17.45 17.45 0 0 0-.432.311c-.356.268-.619.511-.78.793h2.514a.75.75 0 0 1 0 1.5H17a.75.75 0 0 1-.75-.75c0-1.396.821-2.182 1.565-2.741.157-.119.32-.234.472-.341l.074-.052c.177-.126.34-.243.493-.363.306-.242.532-.47.682-.724.31-.53.229-.886.093-1.094-.158-.244-.486-.435-.893-.435Z\"/><path d=\"M15.26 4.71c.06.562.385 1.043.847 1.318L10.987 12l5.583 6.512a.75.75 0 1 1-1.14.976L10 13.152l-5.43 6.336a.75.75 0 0 1-1.14-.976L9.013 12 3.431 5.488a.75.75 0 1 1 1.139-.976L10 10.848l5.26-6.137Z\"/></svg>";
|
|
113
113
|
|
|
114
|
-
var subscript$1 = "<svg width=\"24\" height=\"24\" fill=\"
|
|
114
|
+
var subscript$1 = "<svg width=\"24\" height=\"24\" fill=\"#000000\" viewBox=\"0 0 24 24\" xmlns=\"http://www.w3.org/2000/svg\"><path d=\"M16.488 4.43a.75.75 0 0 1 .082 1.058L10.988 12l5.032 5.871c-.302.41-.555.906-.682 1.51L10 13.151l-5.43 6.336a.75.75 0 0 1-1.14-.976L9.013 12 3.431 5.488a.75.75 0 0 1 1.139-.976L10 10.848l5.43-6.336a.75.75 0 0 1 1.058-.081ZM17.75 15.523c0-.528.444-1.023.986-1.023.407 0 .735.19.893.434.136.21.218.566-.093 1.095-.15.255-.376.482-.682.724-.152.12-.316.237-.493.363l-.074.052c-.152.107-.315.222-.472.34-.744.56-1.565 1.346-1.565 2.742 0 .414.336.75.75.75h3.451a.75.75 0 0 0 0-1.5h-2.513c.16-.282.423-.525.779-.793.137-.103.279-.203.432-.312l.078-.054c.178-.127.37-.264.557-.41.372-.295.76-.658 1.045-1.142.557-.948.546-1.921.058-2.672C20.42 13.4 19.59 13 18.736 13c-1.478 0-2.486 1.278-2.486 2.523a.75.75 0 0 0 1.5 0Z\"/></svg>";
|
|
115
115
|
|
|
116
116
|
var code$1 = "<svg xmlns=\"http://www.w3.org/2000/svg\" width=\"32\" height=\"32\" fill=\"#000000\" viewBox=\"0 0 256 256\"><path d=\"M93.31,70,28,128l65.27,58a8,8,0,1,1-10.62,12l-72-64a8,8,0,0,1,0-12l72-64A8,8,0,1,1,93.31,70Zm152,52-72-64a8,8,0,0,0-10.62,12L228,128l-65.27,58a8,8,0,1,0,10.62,12l72-64a8,8,0,0,0,0-12Z\"></path></svg>";
|
|
117
117
|
|
|
@@ -123,13 +123,13 @@ var fontColor$1 = "<svg xmlns=\"http://www.w3.org/2000/svg\" viewBox=\"0 0 256 2
|
|
|
123
123
|
|
|
124
124
|
var fontColorAccent = "<svg xmlns=\"http://www.w3.org/2000/svg\" viewBox=\"0 0 256 256\"><rect width=\"256\" height=\"256\" fill=\"none\"/><line x1=\"40\" y1=\"216\" x2=\"216\" y2=\"216\" fill=\"none\" stroke=\"currentColor\" stroke-linecap=\"round\" stroke-linejoin=\"round\" stroke-width=\"16\"/></svg>";
|
|
125
125
|
|
|
126
|
-
var highlight$1 = "<svg width=\"24\" height=\"24\" fill=\"
|
|
126
|
+
var highlight$1 = "<svg width=\"24\" height=\"24\" fill=\"#000000\" viewBox=\"0 0 24 24\" xmlns=\"http://www.w3.org/2000/svg\"><path d=\"M4.38 14.003A2.5 2.5 0 0 0 2 16.5v3A2.5 2.5 0 0 0 4.5 22h15a2.5 2.5 0 0 0 2.5-2.5v-3a2.5 2.5 0 0 0-2.5-2.5h-5.954l-1.316 1.314a3.237 3.237 0 0 1-.203.186H19.5a1 1 0 0 1 1 1v3a1 1 0 0 1-1 1h-15a1 1 0 0 1-1-1v-3a1 1 0 0 1 .504-.869 2 2 0 0 1 .092-.744l.285-.884Z\"/><path d=\"M18.648 2.944a3.218 3.218 0 0 1-.002 4.551l-7.123 7.111a2.25 2.25 0 0 1-.942.563l-4.294 1.289a1 1 0 0 1-1.239-1.265l1.362-4.228c.11-.34.298-.65.552-.902l7.132-7.122a3.22 3.22 0 0 1 4.554.003Zm-3.494 1.059-7.133 7.121a.75.75 0 0 0-.184.301l-1.07 3.322 3.382-1.015a.75.75 0 0 0 .315-.187l7.121-7.11a1.718 1.718 0 1 0-2.43-2.432Z\"/></svg>";
|
|
127
127
|
|
|
128
|
-
var highlightAccent = "<svg width=\"24\" height=\"24\" fill=\"
|
|
128
|
+
var highlightAccent = "<svg width=\"24\" height=\"24\" fill=\"#000000\" viewBox=\"0 0 24 24\" xmlns=\"http://www.w3.org/2000/svg\"><path d=\"M4.004 15.631a2 2 0 0 0 2.571 1.784l4.293-1.288a3.25 3.25 0 0 0 1.159-.627H19.5a1 1 0 0 1 1 1v3a1 1 0 0 1-1 1h-15a1 1 0 0 1-1-1v-3a1 1 0 0 1 .504-.869Z\"/></svg>";
|
|
129
129
|
|
|
130
|
-
var backgroundColor = "<svg width=\"24\" height=\"24\" fill=\"
|
|
130
|
+
var backgroundColor = "<svg width=\"24\" height=\"24\" fill=\"#000000\" viewBox=\"0 0 24 24\" xmlns=\"http://www.w3.org/2000/svg\"><path d=\"M2 12.414V17.5A2.5 2.5 0 0 0 4.5 20h15a2.5 2.5 0 0 0 2.5-2.5v-11A2.5 2.5 0 0 0 19.5 4h-8.944l1.5 1.5H19.5a1 1 0 0 1 1 1v11a1 1 0 0 1-1 1h-15a1 1 0 0 1-1-1v-3.586l-1.5-1.5Z\"/><path d=\"M6 1.75a.75.75 0 1 1 1.5 0v1.265c.45.04.89.233 1.235.578l3.536 3.536a2 2 0 0 1 0 2.828L8.027 14.2a2 2 0 0 1-2.829 0l-3.535-3.536a2 2 0 0 1 0-2.828l4.243-4.243c.03-.03.061-.06.093-.087V1.75Zm0 4.5v-.629l-2.89 2.89h8.245a.498.498 0 0 0-.145-.322L7.674 4.654A.498.498 0 0 0 7.5 4.54v1.71a.75.75 0 0 1-1.5 0Zm-2.868 3.76 3.128 3.13a.5.5 0 0 0 .707 0l3.129-3.13H3.132ZM11 13.375c0-.493.154-.972.342-1.381.19-.416.438-.806.673-1.134.238-.331.474-.613.65-.812.085-.097.24-.261.299-.323l.005-.005a.75.75 0 0 1 1.061 0l.305.328c.176.199.412.48.649.812.236.328.483.718.674 1.134.188.409.342.888.342 1.381C16 14.765 14.97 16 13.5 16c-1.471 0-2.5-1.235-2.5-2.625Zm2.234-1.64c-.202.28-.392.585-.53.885-.14.305-.204.56-.204.755 0 .691.48 1.125 1 1.125.519 0 1-.434 1-1.125 0-.194-.065-.45-.205-.755a5.494 5.494 0 0 0-.53-.886 8.417 8.417 0 0 0-.265-.35 8.33 8.33 0 0 0-.266.35Z\"/></svg>";
|
|
131
131
|
|
|
132
|
-
var backgroundColorAccent = "<svg width=\"24\" height=\"24\" fill=\"
|
|
132
|
+
var backgroundColorAccent = "<svg width=\"24\" height=\"24\" fill=\"#000000\" viewBox=\"0 0 24 24\" xmlns=\"http://www.w3.org/2000/svg\"><path d=\"M12.978 6.422a2.99 2.99 0 0 1 .878 2.115c.323.066.63.225.881.476l.013.013.326.35.008.01c.192.216.45.525.712.89.26.36.545.808.77 1.3.22.478.434 1.106.434 1.799C17 15.232 15.606 17 13.5 17c-2.008 0-3.37-1.608-3.491-3.367l-1.274 1.274a3 3 0 0 1-4.243 0L3 13.415V17.5A1.5 1.5 0 0 0 4.5 19h15a1.5 1.5 0 0 0 1.5-1.5v-11A1.5 1.5 0 0 0 19.5 5h-7.944l1.422 1.422Z\"/></svg>";
|
|
133
133
|
|
|
134
134
|
var link$1 = "<svg xmlns=\"http://www.w3.org/2000/svg\" width=\"32\" height=\"32\" fill=\"#000000\" viewBox=\"0 0 256 256\"><path d=\"M165.66,90.34a8,8,0,0,1,0,11.32l-64,64a8,8,0,0,1-11.32-11.32l64-64A8,8,0,0,1,165.66,90.34ZM215.6,40.4a56,56,0,0,0-79.2,0L106.34,70.45a8,8,0,0,0,11.32,11.32l30.06-30a40,40,0,0,1,56.57,56.56l-30.07,30.06a8,8,0,0,0,11.31,11.32L215.6,119.6a56,56,0,0,0,0-79.2ZM138.34,174.22l-30.06,30.06a40,40,0,1,1-56.56-56.57l30.05-30.05a8,8,0,0,0-11.32-11.32L40.4,136.4a56,56,0,0,0,79.2,79.2l30.06-30.07a8,8,0,0,0-11.32-11.31Z\"></path></svg>";
|
|
135
135
|
|
|
@@ -167,9 +167,9 @@ var tableColumn = "<svg xmlns=\"http://www.w3.org/2000/svg\" width=\"32\" height
|
|
|
167
167
|
|
|
168
168
|
var tableRow = "<svg xmlns=\"http://www.w3.org/2000/svg\" width=\"32\" height=\"32\" fill=\"#000000\" viewBox=\"0 0 256 256\"><path d=\"M208,136H48a16,16,0,0,0-16,16v40a16,16,0,0,0,16,16H208a16,16,0,0,0,16-16V152A16,16,0,0,0,208,136Zm0,56H48V152H208v40Zm0-144H48A16,16,0,0,0,32,64v40a16,16,0,0,0,16,16H208a16,16,0,0,0,16-16V64A16,16,0,0,0,208,48Zm0,56H48V64H208v40Z\"></path></svg>";
|
|
169
169
|
|
|
170
|
-
var tableMerge = "<svg width=\"24\" height=\"24\" fill=\"
|
|
170
|
+
var tableMerge = "<svg width=\"24\" height=\"24\" fill=\"#000000\" viewBox=\"0 0 24 24\" xmlns=\"http://www.w3.org/2000/svg\"><path d=\"M6.25 3A3.25 3.25 0 0 0 3 6.25v11.5A3.25 3.25 0 0 0 6.25 21h11.5A3.25 3.25 0 0 0 21 17.75V6.25A3.25 3.25 0 0 0 17.75 3H6.25ZM4.5 6.25c0-.966.784-1.75 1.75-1.75H11v3H4.5V6.25Zm8 10.25h7v1.25a1.75 1.75 0 0 1-1.75 1.75H12.5v-3Zm7-9h-7v-3h5.25c.966 0 1.75.784 1.75 1.75V7.5Zm-8.5 9v3H6.25a1.75 1.75 0 0 1-1.75-1.75V16.5H11ZM4.5 9h15v6h-15V9Z\"/></svg>";
|
|
171
171
|
|
|
172
|
-
var tableSplit = "<svg width=\"24\" height=\"24\" fill=\"
|
|
172
|
+
var tableSplit = "<svg width=\"24\" height=\"24\" fill=\"#000000\" viewBox=\"0 0 24 24\" xmlns=\"http://www.w3.org/2000/svg\"><path d=\"M12.5 10H11v4h1.5v-4Z\" fill=\"#212121\"/><path d=\"M3 6.25A3.25 3.25 0 0 1 6.25 3h11.5A3.25 3.25 0 0 1 21 6.25v11.5A3.25 3.25 0 0 1 17.75 21H6.25A3.25 3.25 0 0 1 3 17.75V6.25ZM6.25 4.5A1.75 1.75 0 0 0 4.5 6.25V7.5H11v-3H6.25Zm13.25 12h-7v3h5.25a1.75 1.75 0 0 0 1.75-1.75V16.5Zm0-10.25a1.75 1.75 0 0 0-1.75-1.75H12.5v3h7V6.25ZM4.5 16.5v1.25c0 .966.784 1.75 1.75 1.75H11v-3H4.5Zm0-1.5h15V9h-15v6Z\"/></svg>";
|
|
173
173
|
|
|
174
174
|
var info = "<svg xmlns=\"http://www.w3.org/2000/svg\" width=\"32\" height=\"32\" fill=\"#000000\" viewBox=\"0 0 256 256\"><path d=\"M128,24A104,104,0,1,0,232,128,104.11,104.11,0,0,0,128,24Zm0,192a88,88,0,1,1,88-88A88.1,88.1,0,0,1,128,216Zm16-40a8,8,0,0,1-8,8,16,16,0,0,1-16-16V128a8,8,0,0,1,0-16,16,16,0,0,1,16,16v40A8,8,0,0,1,144,176ZM112,84a12,12,0,1,1,12,12A12,12,0,0,1,112,84Z\"></path></svg>";
|
|
175
175
|
|
|
@@ -194,8 +194,6 @@ var danger = "<svg xmlns=\"http://www.w3.org/2000/svg\" width=\"32\" height=\"32
|
|
|
194
194
|
//
|
|
195
195
|
// Phosphor Icons (https://phosphoricons.com/).
|
|
196
196
|
// - other icons
|
|
197
|
-
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
198
|
-
// @ts-nocheck
|
|
199
197
|
// common
|
|
200
198
|
const icons = new Map([
|
|
201
199
|
// common
|
|
@@ -280,7 +278,7 @@ const icons = new Map([
|
|
|
280
278
|
['tableRow', tableRow],
|
|
281
279
|
['tableMerge', tableMerge],
|
|
282
280
|
['tableSplit', tableSplit],
|
|
283
|
-
//
|
|
281
|
+
// alert
|
|
284
282
|
['info', info],
|
|
285
283
|
['tip', tip],
|
|
286
284
|
['warning', warning],
|
|
@@ -397,19 +395,25 @@ function camelCase(value) {
|
|
|
397
395
|
return camelString;
|
|
398
396
|
}
|
|
399
397
|
|
|
400
|
-
|
|
398
|
+
/**
|
|
399
|
+
* Converts an alpha value to a hex value.
|
|
400
|
+
*/
|
|
401
401
|
function alphaToHex(value) {
|
|
402
402
|
const hexString = Math.round(Number.parseFloat(value) * 255).toString(16);
|
|
403
403
|
return hexString.length > 1 ? hexString : `0${hexString}`;
|
|
404
404
|
}
|
|
405
|
-
|
|
405
|
+
/**
|
|
406
|
+
* Converts a decimal to a hex value.
|
|
407
|
+
*/
|
|
406
408
|
function hex(value) {
|
|
407
409
|
const hexString = Number.parseInt(value, 10).toString(16).toLowerCase();
|
|
408
410
|
return hexString.length > 1 ? hexString : `0${hexString}`;
|
|
409
411
|
}
|
|
410
|
-
|
|
412
|
+
/**
|
|
413
|
+
* Converts a color in RGB or RGBA format to hex format.
|
|
414
|
+
*/
|
|
411
415
|
function toHex(value) {
|
|
412
|
-
return value.replace(/rgba?\s*\(\s*(\d+)\s*,\s*(\d+)\s*,\s*(\d+)\s*(?:,\s*([\d.]+)\s*)?\)/
|
|
416
|
+
return value.replace(/rgba?\s*\(\s*(\d+)\s*,\s*(\d+)\s*,\s*(\d+)\s*(?:,\s*([\d.]+)\s*)?\)/gi, (match, p1, p2, p3, p4) => {
|
|
413
417
|
if (p4 === undefined) {
|
|
414
418
|
return `#${hex(p1)}${hex(p2)}${hex(p3)}`;
|
|
415
419
|
}
|
|
@@ -433,14 +437,20 @@ function debug(...data) {
|
|
|
433
437
|
}
|
|
434
438
|
}
|
|
435
439
|
|
|
436
|
-
|
|
437
|
-
|
|
440
|
+
/**
|
|
441
|
+
* A key-value object for storing all events.
|
|
442
|
+
* The value is an array which include types and listeners.
|
|
443
|
+
*/
|
|
438
444
|
const eventData = {};
|
|
439
445
|
let lastNodeId = 0;
|
|
440
|
-
|
|
446
|
+
/**
|
|
447
|
+
* The Nodes interface represents a collection of the nodes.
|
|
448
|
+
* It is similar to jQuery, but its implementation is much simpler.
|
|
449
|
+
* Its methods can be considered aliases of native DOM interfaces, designed to simplify DOM manipulation.
|
|
450
|
+
*/
|
|
441
451
|
class Nodes {
|
|
442
452
|
constructor(node) {
|
|
443
|
-
node = node !== null && node !==
|
|
453
|
+
node = node !== null && node !== void 0 ? node : [];
|
|
444
454
|
this.nodeList = Array.isArray(node) ? node : [node];
|
|
445
455
|
for (let i = 0; i < this.nodeList.length; i++) {
|
|
446
456
|
// lakeId is an expando for preserving node ID.
|
|
@@ -451,12 +461,16 @@ class Nodes {
|
|
|
451
461
|
}
|
|
452
462
|
this.length = this.nodeList.length;
|
|
453
463
|
}
|
|
454
|
-
|
|
464
|
+
/**
|
|
465
|
+
* The unique ID of the first node.
|
|
466
|
+
*/
|
|
455
467
|
get id() {
|
|
456
468
|
const node = this.get(0);
|
|
457
469
|
return node.lakeId;
|
|
458
470
|
}
|
|
459
|
-
|
|
471
|
+
/**
|
|
472
|
+
* The name of the first node.
|
|
473
|
+
*/
|
|
460
474
|
get name() {
|
|
461
475
|
if (this.length === 0) {
|
|
462
476
|
return '';
|
|
@@ -464,7 +478,9 @@ class Nodes {
|
|
|
464
478
|
const node = this.get(0);
|
|
465
479
|
return node.nodeName.toLowerCase();
|
|
466
480
|
}
|
|
467
|
-
|
|
481
|
+
/**
|
|
482
|
+
* A boolean value indicating whether the first node is an element.
|
|
483
|
+
*/
|
|
468
484
|
get isElement() {
|
|
469
485
|
if (this.length === 0) {
|
|
470
486
|
return false;
|
|
@@ -472,7 +488,9 @@ class Nodes {
|
|
|
472
488
|
const node = this.get(0);
|
|
473
489
|
return node.nodeType === Node.ELEMENT_NODE;
|
|
474
490
|
}
|
|
475
|
-
|
|
491
|
+
/**
|
|
492
|
+
* A boolean value indicating whether the first node is a text.
|
|
493
|
+
*/
|
|
476
494
|
get isText() {
|
|
477
495
|
if (this.length === 0) {
|
|
478
496
|
return false;
|
|
@@ -480,65 +498,87 @@ class Nodes {
|
|
|
480
498
|
const node = this.get(0);
|
|
481
499
|
return node.nodeType === Node.TEXT_NODE;
|
|
482
500
|
}
|
|
483
|
-
|
|
501
|
+
/**
|
|
502
|
+
* A boolean value indicating whether the first node is a block.
|
|
503
|
+
*/
|
|
484
504
|
get isBlock() {
|
|
485
505
|
if (this.length === 0) {
|
|
486
506
|
return false;
|
|
487
507
|
}
|
|
488
508
|
return blockTagNames.has(this.name);
|
|
489
509
|
}
|
|
490
|
-
|
|
510
|
+
/**
|
|
511
|
+
* A boolean value indicating whether the first node is a mark.
|
|
512
|
+
*/
|
|
491
513
|
get isMark() {
|
|
492
514
|
if (this.length === 0) {
|
|
493
515
|
return false;
|
|
494
516
|
}
|
|
495
517
|
return markTagNames.has(this.name);
|
|
496
518
|
}
|
|
497
|
-
|
|
519
|
+
/**
|
|
520
|
+
* A boolean value indicating whether the first node is a void element that cannot have any child nodes.
|
|
521
|
+
*/
|
|
498
522
|
get isVoid() {
|
|
499
523
|
if (this.length === 0) {
|
|
500
524
|
return false;
|
|
501
525
|
}
|
|
502
526
|
return voidTagNames.has(this.name);
|
|
503
527
|
}
|
|
504
|
-
|
|
528
|
+
/**
|
|
529
|
+
* A boolean value indicating whether the first node is a heading.
|
|
530
|
+
*/
|
|
505
531
|
get isHeading() {
|
|
506
532
|
if (this.length === 0) {
|
|
507
533
|
return false;
|
|
508
534
|
}
|
|
509
535
|
return headingTagNames.has(this.name);
|
|
510
536
|
}
|
|
511
|
-
|
|
537
|
+
/**
|
|
538
|
+
* A boolean value indicating whether the first node is a list.
|
|
539
|
+
*/
|
|
512
540
|
get isList() {
|
|
513
541
|
if (this.length === 0) {
|
|
514
542
|
return false;
|
|
515
543
|
}
|
|
516
544
|
return listTagNames.has(this.name);
|
|
517
545
|
}
|
|
518
|
-
|
|
546
|
+
/**
|
|
547
|
+
* A boolean value indicating whether the first node is a table.
|
|
548
|
+
*/
|
|
519
549
|
get isTable() {
|
|
520
550
|
if (this.length === 0) {
|
|
521
551
|
return false;
|
|
522
552
|
}
|
|
523
553
|
return tableTagNames.has(this.name);
|
|
524
554
|
}
|
|
525
|
-
|
|
555
|
+
/**
|
|
556
|
+
* A boolean value indicating whether the first node is a bookmark element.
|
|
557
|
+
*/
|
|
526
558
|
get isBookmark() {
|
|
527
559
|
return this.name === 'lake-bookmark';
|
|
528
560
|
}
|
|
529
|
-
|
|
561
|
+
/**
|
|
562
|
+
* A boolean value indicating whether the first node is a box element.
|
|
563
|
+
*/
|
|
530
564
|
get isBox() {
|
|
531
565
|
return this.name === 'lake-box';
|
|
532
566
|
}
|
|
533
|
-
|
|
567
|
+
/**
|
|
568
|
+
* A boolean value indicating whether the first node is an inline box element.
|
|
569
|
+
*/
|
|
534
570
|
get isInlineBox() {
|
|
535
571
|
return this.isBox && this.attr('type') === 'inline';
|
|
536
572
|
}
|
|
537
|
-
|
|
573
|
+
/**
|
|
574
|
+
* A boolean value indicating whether the first node is a block box element.
|
|
575
|
+
*/
|
|
538
576
|
get isBlockBox() {
|
|
539
577
|
return this.isBox && this.attr('type') === 'block';
|
|
540
578
|
}
|
|
541
|
-
|
|
579
|
+
/**
|
|
580
|
+
* A boolean value indicating whether the first node is a contenteditable element where users can edit the content.
|
|
581
|
+
*/
|
|
542
582
|
get isContainer() {
|
|
543
583
|
if (this.length === 0) {
|
|
544
584
|
return false;
|
|
@@ -546,15 +586,21 @@ class Nodes {
|
|
|
546
586
|
const node = this.get(0);
|
|
547
587
|
return this.isElement && node.getAttribute('contenteditable') === 'true';
|
|
548
588
|
}
|
|
549
|
-
|
|
589
|
+
/**
|
|
590
|
+
* A boolean value indicating whether the first node does not have an ancestor element which contenteditable attribute is true.
|
|
591
|
+
*/
|
|
550
592
|
get isOutside() {
|
|
551
593
|
return this.closest('[contenteditable="true"]').length === 0;
|
|
552
594
|
}
|
|
553
|
-
|
|
595
|
+
/**
|
|
596
|
+
* A boolean value indicating whether the first node has an ancestor element which contenteditable attribute is true.
|
|
597
|
+
*/
|
|
554
598
|
get isInside() {
|
|
555
599
|
return !this.isOutside && !this.isContainer;
|
|
556
600
|
}
|
|
557
|
-
|
|
601
|
+
/**
|
|
602
|
+
* A boolean value indicating whether the first node's parent element is an element which contenteditable attribute is true.
|
|
603
|
+
*/
|
|
558
604
|
get isTopInside() {
|
|
559
605
|
if (this.length === 0) {
|
|
560
606
|
return false;
|
|
@@ -565,7 +611,9 @@ class Nodes {
|
|
|
565
611
|
}
|
|
566
612
|
return this.isInside && parentNode.isContainer;
|
|
567
613
|
}
|
|
568
|
-
|
|
614
|
+
/**
|
|
615
|
+
* A boolean value indicating whether the first node is editable.
|
|
616
|
+
*/
|
|
569
617
|
get isContentEditable() {
|
|
570
618
|
if (this.length === 0) {
|
|
571
619
|
return false;
|
|
@@ -583,11 +631,15 @@ class Nodes {
|
|
|
583
631
|
const element = this.get(0);
|
|
584
632
|
return element.isContentEditable;
|
|
585
633
|
}
|
|
586
|
-
|
|
634
|
+
/**
|
|
635
|
+
* A boolean value indicating whether the first node is indivisible.
|
|
636
|
+
*/
|
|
587
637
|
get isIndivisible() {
|
|
588
638
|
return this.isContainer || this.isTable;
|
|
589
639
|
}
|
|
590
|
-
|
|
640
|
+
/**
|
|
641
|
+
* A boolean value indicating whether the first node is empty.
|
|
642
|
+
*/
|
|
591
643
|
get isEmpty() {
|
|
592
644
|
if (this.isBox) {
|
|
593
645
|
return false;
|
|
@@ -607,20 +659,28 @@ class Nodes {
|
|
|
607
659
|
}
|
|
608
660
|
return true;
|
|
609
661
|
}
|
|
610
|
-
|
|
662
|
+
/**
|
|
663
|
+
* Returns a native node at the specified index.
|
|
664
|
+
*/
|
|
611
665
|
get(index) {
|
|
612
666
|
return this.nodeList[index];
|
|
613
667
|
}
|
|
614
|
-
|
|
668
|
+
/**
|
|
669
|
+
* Returns all native nodes.
|
|
670
|
+
*/
|
|
615
671
|
getAll() {
|
|
616
672
|
return this.nodeList;
|
|
617
673
|
}
|
|
618
|
-
|
|
674
|
+
/**
|
|
675
|
+
* Returns a new Nodes object that includes only the node at the specified index.
|
|
676
|
+
*/
|
|
619
677
|
eq(index) {
|
|
620
678
|
const node = this.get(index);
|
|
621
679
|
return new Nodes(node);
|
|
622
680
|
}
|
|
623
|
-
|
|
681
|
+
/**
|
|
682
|
+
* Executes a provided function once for each node.
|
|
683
|
+
*/
|
|
624
684
|
each(callback) {
|
|
625
685
|
const nodes = this.getAll();
|
|
626
686
|
for (let i = 0; i < nodes.length; i++) {
|
|
@@ -630,7 +690,9 @@ class Nodes {
|
|
|
630
690
|
}
|
|
631
691
|
return this;
|
|
632
692
|
}
|
|
633
|
-
|
|
693
|
+
/**
|
|
694
|
+
* Executes a provided function once for each element.
|
|
695
|
+
*/
|
|
634
696
|
eachElement(callback) {
|
|
635
697
|
const nodes = this.getAll();
|
|
636
698
|
for (let i = 0; i < nodes.length; i++) {
|
|
@@ -642,12 +704,16 @@ class Nodes {
|
|
|
642
704
|
}
|
|
643
705
|
return this;
|
|
644
706
|
}
|
|
645
|
-
|
|
707
|
+
/**
|
|
708
|
+
* Returns a new Nodes object with the nodes in reversed order.
|
|
709
|
+
*/
|
|
646
710
|
reverse() {
|
|
647
711
|
const nodes = this.getAll().reverse();
|
|
648
712
|
return new Nodes(nodes);
|
|
649
713
|
}
|
|
650
|
-
|
|
714
|
+
/**
|
|
715
|
+
* Tests whether the first node would be selected by the specified CSS selector.
|
|
716
|
+
*/
|
|
651
717
|
matches(selector) {
|
|
652
718
|
if (!this.isElement) {
|
|
653
719
|
return false;
|
|
@@ -655,13 +721,17 @@ class Nodes {
|
|
|
655
721
|
const element = this.get(0);
|
|
656
722
|
return element.matches(selector);
|
|
657
723
|
}
|
|
658
|
-
|
|
659
|
-
|
|
724
|
+
/**
|
|
725
|
+
* Returns a boolean value indicating whether the given node is a descendant of the first node,
|
|
726
|
+
* that is the node itself, one of its direct children (childNodes), one of the children's direct children, and so on.
|
|
727
|
+
*/
|
|
660
728
|
contains(otherNode) {
|
|
661
729
|
const element = this.get(0);
|
|
662
730
|
return element.contains(otherNode.get(0));
|
|
663
731
|
}
|
|
664
|
-
|
|
732
|
+
/**
|
|
733
|
+
* Returns a boolean value indicating whether the first node and a given node are siblings.
|
|
734
|
+
*/
|
|
665
735
|
isSibling(otherNode) {
|
|
666
736
|
if (this.length === 0) {
|
|
667
737
|
return false;
|
|
@@ -669,7 +739,9 @@ class Nodes {
|
|
|
669
739
|
const parent = this.get(0).parentNode;
|
|
670
740
|
return parent && parent === otherNode.parent().get(0);
|
|
671
741
|
}
|
|
672
|
-
|
|
742
|
+
/**
|
|
743
|
+
* Returns the descendants of the first node that match the specified CSS selector or node path.
|
|
744
|
+
*/
|
|
673
745
|
find(selector) {
|
|
674
746
|
if (typeof selector === 'string') {
|
|
675
747
|
const element = this.get(0);
|
|
@@ -685,7 +757,9 @@ class Nodes {
|
|
|
685
757
|
}
|
|
686
758
|
return node;
|
|
687
759
|
}
|
|
688
|
-
|
|
760
|
+
/**
|
|
761
|
+
* Traverses the first node and its parents (heading toward the document root) until it finds an element that matches the specified CSS selector.
|
|
762
|
+
*/
|
|
689
763
|
closest(selector) {
|
|
690
764
|
if (this.isText) {
|
|
691
765
|
const element = this.get(0).parentNode;
|
|
@@ -700,7 +774,9 @@ class Nodes {
|
|
|
700
774
|
const element = this.get(0);
|
|
701
775
|
return new Nodes(element.closest(selector));
|
|
702
776
|
}
|
|
703
|
-
|
|
777
|
+
/**
|
|
778
|
+
* Traverses the first node and its parents until it finds a block element.
|
|
779
|
+
*/
|
|
704
780
|
closestBlock() {
|
|
705
781
|
let node = this.eq(0);
|
|
706
782
|
while (node.length > 0) {
|
|
@@ -714,7 +790,9 @@ class Nodes {
|
|
|
714
790
|
}
|
|
715
791
|
return node;
|
|
716
792
|
}
|
|
717
|
-
|
|
793
|
+
/**
|
|
794
|
+
* Traverses the first node and its parents until it finds an operable block.
|
|
795
|
+
*/
|
|
718
796
|
closestOperableBlock() {
|
|
719
797
|
const boxNode = this.closest('lake-box');
|
|
720
798
|
const block = boxNode.length > 0 ? boxNode.closestBlock() : this.closestBlock();
|
|
@@ -730,11 +808,15 @@ class Nodes {
|
|
|
730
808
|
}
|
|
731
809
|
return block;
|
|
732
810
|
}
|
|
733
|
-
|
|
811
|
+
/**
|
|
812
|
+
* Traverses the first node and its parents until it finds a div element which contenteditable attribute is true.
|
|
813
|
+
*/
|
|
734
814
|
closestContainer() {
|
|
735
815
|
return this.closest('div[contenteditable="true"]');
|
|
736
816
|
}
|
|
737
|
-
|
|
817
|
+
/**
|
|
818
|
+
* Traverses the first node and its parents until it finds an element which can scroll.
|
|
819
|
+
*/
|
|
738
820
|
closestScroller() {
|
|
739
821
|
let parent = this.eq(0);
|
|
740
822
|
while (parent.length > 0) {
|
|
@@ -745,32 +827,44 @@ class Nodes {
|
|
|
745
827
|
}
|
|
746
828
|
return new Nodes();
|
|
747
829
|
}
|
|
748
|
-
|
|
830
|
+
/**
|
|
831
|
+
* Returns the parent of the first node.
|
|
832
|
+
*/
|
|
749
833
|
parent() {
|
|
750
834
|
const node = this.get(0);
|
|
751
835
|
return new Nodes(node.parentNode);
|
|
752
836
|
}
|
|
753
|
-
|
|
837
|
+
/**
|
|
838
|
+
* Returns the immediately preceding sibling of the first node.
|
|
839
|
+
*/
|
|
754
840
|
prev() {
|
|
755
841
|
const node = this.get(0);
|
|
756
842
|
return new Nodes(node.previousSibling);
|
|
757
843
|
}
|
|
758
|
-
|
|
844
|
+
/**
|
|
845
|
+
* Returns the immediately following sibling of the first node.
|
|
846
|
+
*/
|
|
759
847
|
next() {
|
|
760
848
|
const node = this.get(0);
|
|
761
849
|
return new Nodes(node.nextSibling);
|
|
762
850
|
}
|
|
763
|
-
|
|
851
|
+
/**
|
|
852
|
+
* Returns the first child of the first node.
|
|
853
|
+
*/
|
|
764
854
|
first() {
|
|
765
855
|
const element = this.get(0);
|
|
766
856
|
return new Nodes(element.firstChild);
|
|
767
857
|
}
|
|
768
|
-
|
|
858
|
+
/**
|
|
859
|
+
* Returns the last child of the first node.
|
|
860
|
+
*/
|
|
769
861
|
last() {
|
|
770
862
|
const element = this.get(0);
|
|
771
863
|
return new Nodes(element.lastChild);
|
|
772
864
|
}
|
|
773
|
-
|
|
865
|
+
/**
|
|
866
|
+
* Returns a number indicating the position of the first node relative to its sibling nodes.
|
|
867
|
+
*/
|
|
774
868
|
index() {
|
|
775
869
|
let i = -1;
|
|
776
870
|
let sibling = this.get(0);
|
|
@@ -780,7 +874,9 @@ class Nodes {
|
|
|
780
874
|
}
|
|
781
875
|
return i;
|
|
782
876
|
}
|
|
783
|
-
|
|
877
|
+
/**
|
|
878
|
+
* Returns the path of the first node.
|
|
879
|
+
*/
|
|
784
880
|
path() {
|
|
785
881
|
const path = [];
|
|
786
882
|
let node = this.eq(0);
|
|
@@ -800,7 +896,9 @@ class Nodes {
|
|
|
800
896
|
}
|
|
801
897
|
return path.reverse();
|
|
802
898
|
}
|
|
803
|
-
|
|
899
|
+
/**
|
|
900
|
+
* Returns a list which contains all of the child nodes of the first node.
|
|
901
|
+
*/
|
|
804
902
|
children() {
|
|
805
903
|
const childList = [];
|
|
806
904
|
let child = this.first();
|
|
@@ -810,7 +908,9 @@ class Nodes {
|
|
|
810
908
|
}
|
|
811
909
|
return childList;
|
|
812
910
|
}
|
|
813
|
-
|
|
911
|
+
/**
|
|
912
|
+
* Returns a generator that iterates over the descendants of the first node.
|
|
913
|
+
*/
|
|
814
914
|
*getWalker() {
|
|
815
915
|
function* iterate(node) {
|
|
816
916
|
if (node.isBox) {
|
|
@@ -828,7 +928,9 @@ class Nodes {
|
|
|
828
928
|
yield node;
|
|
829
929
|
}
|
|
830
930
|
}
|
|
831
|
-
|
|
931
|
+
/**
|
|
932
|
+
* Sets up an event listener for each element.
|
|
933
|
+
*/
|
|
832
934
|
on(type, listener) {
|
|
833
935
|
return this.eachElement(element => {
|
|
834
936
|
element.addEventListener(type, listener, false);
|
|
@@ -842,15 +944,17 @@ class Nodes {
|
|
|
842
944
|
});
|
|
843
945
|
});
|
|
844
946
|
}
|
|
845
|
-
|
|
947
|
+
/**
|
|
948
|
+
* Removes event listeners previously registered with on() method.
|
|
949
|
+
*/
|
|
846
950
|
off(type, listener) {
|
|
847
951
|
return this.eachElement(element => {
|
|
848
952
|
var _a;
|
|
849
953
|
const elementId = element.lakeId;
|
|
850
|
-
const eventItems = (_a = eventData[elementId]) !== null && _a !==
|
|
954
|
+
const eventItems = (_a = eventData[elementId]) !== null && _a !== void 0 ? _a : [];
|
|
851
955
|
for (let i = 0; i < eventItems.length; i++) {
|
|
852
956
|
const item = eventItems[i];
|
|
853
|
-
if (!type || type === item.type && (!listener || listener === item.listener)) {
|
|
957
|
+
if (!type || (type === item.type && (!listener || listener === item.listener))) {
|
|
854
958
|
element.removeEventListener(item.type, item.listener, false);
|
|
855
959
|
eventItems[i] = {
|
|
856
960
|
type: '',
|
|
@@ -861,41 +965,53 @@ class Nodes {
|
|
|
861
965
|
eventData[elementId] = eventItems.filter((item) => item.type !== '');
|
|
862
966
|
});
|
|
863
967
|
}
|
|
864
|
-
|
|
968
|
+
/**
|
|
969
|
+
* Executes all event listeners attached to all nodes for the given event type.
|
|
970
|
+
*/
|
|
865
971
|
emit(type, event) {
|
|
866
972
|
return this.eachElement(element => {
|
|
867
973
|
const elementId = element.lakeId;
|
|
868
974
|
const eventItems = eventData[elementId];
|
|
869
975
|
for (const item of eventItems) {
|
|
870
976
|
if (item.type === type) {
|
|
871
|
-
item.listener(event !== null && event !==
|
|
977
|
+
item.listener(event !== null && event !== void 0 ? event : new Event(type));
|
|
872
978
|
}
|
|
873
979
|
}
|
|
874
980
|
});
|
|
875
981
|
}
|
|
876
|
-
|
|
982
|
+
/**
|
|
983
|
+
* Returns all event listeners attached to the node at the specified index.
|
|
984
|
+
*/
|
|
877
985
|
getEventListeners(index) {
|
|
878
986
|
const elementId = this.get(index).lakeId;
|
|
879
987
|
return eventData[elementId];
|
|
880
988
|
}
|
|
881
|
-
|
|
989
|
+
/**
|
|
990
|
+
* Sets focus on the specified node, if it can be focused.
|
|
991
|
+
*/
|
|
882
992
|
focus() {
|
|
883
993
|
const element = this.get(0);
|
|
884
994
|
element.focus();
|
|
885
995
|
return this;
|
|
886
996
|
}
|
|
887
|
-
|
|
997
|
+
/**
|
|
998
|
+
* Removes focus from the specified node.
|
|
999
|
+
*/
|
|
888
1000
|
blur() {
|
|
889
1001
|
const element = this.get(0);
|
|
890
1002
|
element.blur();
|
|
891
1003
|
return this;
|
|
892
1004
|
}
|
|
893
|
-
|
|
1005
|
+
/**
|
|
1006
|
+
* Returns a copy of the first node. If deep is true, the copy also includes the node's descendants.
|
|
1007
|
+
*/
|
|
894
1008
|
clone(deep = false) {
|
|
895
1009
|
const node = this.get(0);
|
|
896
1010
|
return new Nodes(node.cloneNode(deep));
|
|
897
1011
|
}
|
|
898
|
-
|
|
1012
|
+
/**
|
|
1013
|
+
* Returns a boolean value indicating whether the first node has the specified attribute or not.
|
|
1014
|
+
*/
|
|
899
1015
|
hasAttr(attributeName) {
|
|
900
1016
|
const element = this.get(0);
|
|
901
1017
|
return element.hasAttribute(attributeName);
|
|
@@ -910,24 +1026,30 @@ class Nodes {
|
|
|
910
1026
|
}
|
|
911
1027
|
if (value === undefined) {
|
|
912
1028
|
const element = this.get(0);
|
|
913
|
-
return (_a = element.getAttribute(attributeName)) !== null && _a !==
|
|
1029
|
+
return (_a = element.getAttribute(attributeName)) !== null && _a !== void 0 ? _a : '';
|
|
914
1030
|
}
|
|
915
1031
|
return this.eachElement(element => {
|
|
916
1032
|
element.setAttribute(attributeName, value);
|
|
917
1033
|
});
|
|
918
1034
|
}
|
|
919
|
-
|
|
1035
|
+
/**
|
|
1036
|
+
* Removes the attribute with the specified name from every element.
|
|
1037
|
+
*/
|
|
920
1038
|
removeAttr(attributeName) {
|
|
921
1039
|
return this.eachElement(element => {
|
|
922
1040
|
element.removeAttribute(attributeName);
|
|
923
1041
|
});
|
|
924
1042
|
}
|
|
925
|
-
|
|
1043
|
+
/**
|
|
1044
|
+
* Returns a boolean value indicating whether the first node has the specified class or not.
|
|
1045
|
+
*/
|
|
926
1046
|
hasClass(className) {
|
|
927
1047
|
const element = this.get(0);
|
|
928
1048
|
return inString(element.className, className, ' ');
|
|
929
1049
|
}
|
|
930
|
-
|
|
1050
|
+
/**
|
|
1051
|
+
* Adds the given class to every element.
|
|
1052
|
+
*/
|
|
931
1053
|
addClass(className) {
|
|
932
1054
|
if (Array.isArray(className)) {
|
|
933
1055
|
for (const name of className) {
|
|
@@ -942,7 +1064,9 @@ class Nodes {
|
|
|
942
1064
|
element.classList.add(className);
|
|
943
1065
|
});
|
|
944
1066
|
}
|
|
945
|
-
|
|
1067
|
+
/**
|
|
1068
|
+
* Removes the given class from every element.
|
|
1069
|
+
*/
|
|
946
1070
|
removeClass(className) {
|
|
947
1071
|
if (Array.isArray(className)) {
|
|
948
1072
|
for (const name of className) {
|
|
@@ -960,8 +1084,10 @@ class Nodes {
|
|
|
960
1084
|
}
|
|
961
1085
|
});
|
|
962
1086
|
}
|
|
963
|
-
|
|
964
|
-
|
|
1087
|
+
/**
|
|
1088
|
+
* Returns the value of the given CSS property of the first node,
|
|
1089
|
+
* after applying active stylesheets and resolving any basic computation this value may contain.
|
|
1090
|
+
*/
|
|
965
1091
|
computedCSS(propertyName) {
|
|
966
1092
|
const element = this.get(0);
|
|
967
1093
|
return getCSS(element, propertyName);
|
|
@@ -984,28 +1110,38 @@ class Nodes {
|
|
|
984
1110
|
}
|
|
985
1111
|
});
|
|
986
1112
|
}
|
|
987
|
-
|
|
1113
|
+
/**
|
|
1114
|
+
* Returns the width of of the first node.
|
|
1115
|
+
*/
|
|
988
1116
|
width() {
|
|
989
1117
|
const element = this.get(0);
|
|
990
1118
|
return element.offsetWidth;
|
|
991
1119
|
}
|
|
992
|
-
|
|
1120
|
+
/**
|
|
1121
|
+
* Returns the interior width of the first node, which does not include padding.
|
|
1122
|
+
*/
|
|
993
1123
|
innerWidth() {
|
|
994
1124
|
const paddingLeft = Number.parseInt(this.computedCSS('padding-left'), 10) || 0;
|
|
995
1125
|
const paddingRight = Number.parseInt(this.computedCSS('padding-right'), 10) || 0;
|
|
996
1126
|
return this.width() - paddingLeft - paddingRight;
|
|
997
1127
|
}
|
|
998
|
-
|
|
1128
|
+
/**
|
|
1129
|
+
* Returns the height of of the first node.
|
|
1130
|
+
*/
|
|
999
1131
|
height() {
|
|
1000
1132
|
const element = this.get(0);
|
|
1001
1133
|
return element.offsetHeight;
|
|
1002
1134
|
}
|
|
1003
|
-
|
|
1135
|
+
/**
|
|
1136
|
+
* Displays all nodes.
|
|
1137
|
+
*/
|
|
1004
1138
|
show(displayType = 'block') {
|
|
1005
1139
|
this.css('display', displayType);
|
|
1006
1140
|
return this;
|
|
1007
1141
|
}
|
|
1008
|
-
|
|
1142
|
+
/**
|
|
1143
|
+
* Hides all nodes.
|
|
1144
|
+
*/
|
|
1009
1145
|
hide() {
|
|
1010
1146
|
this.css('display', 'none');
|
|
1011
1147
|
return this;
|
|
@@ -1024,7 +1160,7 @@ class Nodes {
|
|
|
1024
1160
|
if (value === undefined) {
|
|
1025
1161
|
const node = this.get(0);
|
|
1026
1162
|
if (this.isText) {
|
|
1027
|
-
return (_a = node.nodeValue) !== null && _a !==
|
|
1163
|
+
return (_a = node.nodeValue) !== null && _a !== void 0 ? _a : '';
|
|
1028
1164
|
}
|
|
1029
1165
|
const element = node;
|
|
1030
1166
|
// https://developer.mozilla.org/en-US/docs/Web/API/HTMLElement/innerText
|
|
@@ -1043,17 +1179,23 @@ class Nodes {
|
|
|
1043
1179
|
element.value = value;
|
|
1044
1180
|
});
|
|
1045
1181
|
}
|
|
1046
|
-
|
|
1182
|
+
/**
|
|
1183
|
+
* Returns the HTML string describing the first node including its descendants.
|
|
1184
|
+
*/
|
|
1047
1185
|
outerHTML() {
|
|
1048
1186
|
const element = this.get(0);
|
|
1049
1187
|
return element.outerHTML;
|
|
1050
1188
|
}
|
|
1051
|
-
|
|
1189
|
+
/**
|
|
1190
|
+
* Removes all child nodes for each element.
|
|
1191
|
+
*/
|
|
1052
1192
|
empty() {
|
|
1053
1193
|
this.html('');
|
|
1054
1194
|
return this;
|
|
1055
1195
|
}
|
|
1056
|
-
|
|
1196
|
+
/**
|
|
1197
|
+
* Inserts the specified content just inside the first node, before its first child.
|
|
1198
|
+
*/
|
|
1057
1199
|
prepend(content) {
|
|
1058
1200
|
const element = this.get(0);
|
|
1059
1201
|
if (typeof content === 'string') {
|
|
@@ -1079,7 +1221,9 @@ class Nodes {
|
|
|
1079
1221
|
}
|
|
1080
1222
|
return this;
|
|
1081
1223
|
}
|
|
1082
|
-
|
|
1224
|
+
/**
|
|
1225
|
+
* Inserts the specified content just inside the first node, after its last child.
|
|
1226
|
+
*/
|
|
1083
1227
|
append(content) {
|
|
1084
1228
|
const element = this.get(0);
|
|
1085
1229
|
if (typeof content === 'string') {
|
|
@@ -1095,7 +1239,9 @@ class Nodes {
|
|
|
1095
1239
|
element.appendChild(content);
|
|
1096
1240
|
return this;
|
|
1097
1241
|
}
|
|
1098
|
-
|
|
1242
|
+
/**
|
|
1243
|
+
* Inserts the specified content before the first node.
|
|
1244
|
+
*/
|
|
1099
1245
|
before(content) {
|
|
1100
1246
|
const node = this.get(0);
|
|
1101
1247
|
if (!node.parentNode) {
|
|
@@ -1114,7 +1260,9 @@ class Nodes {
|
|
|
1114
1260
|
node.parentNode.insertBefore(content, node);
|
|
1115
1261
|
return this;
|
|
1116
1262
|
}
|
|
1117
|
-
|
|
1263
|
+
/**
|
|
1264
|
+
* Inserts the specified content after the first node.
|
|
1265
|
+
*/
|
|
1118
1266
|
after(content) {
|
|
1119
1267
|
const node = this.get(0);
|
|
1120
1268
|
if (!node.parentNode) {
|
|
@@ -1143,7 +1291,9 @@ class Nodes {
|
|
|
1143
1291
|
}
|
|
1144
1292
|
return this;
|
|
1145
1293
|
}
|
|
1146
|
-
|
|
1294
|
+
/**
|
|
1295
|
+
* Replaces the first node with the given new content.
|
|
1296
|
+
*/
|
|
1147
1297
|
replaceWith(newContent) {
|
|
1148
1298
|
const node = this.get(0);
|
|
1149
1299
|
if (!node.parentNode) {
|
|
@@ -1159,7 +1309,9 @@ class Nodes {
|
|
|
1159
1309
|
node.parentNode.replaceChild(target, node);
|
|
1160
1310
|
return this;
|
|
1161
1311
|
}
|
|
1162
|
-
|
|
1312
|
+
/**
|
|
1313
|
+
* Removes all nodes from the DOM.
|
|
1314
|
+
*/
|
|
1163
1315
|
remove(keepChildren = false) {
|
|
1164
1316
|
this.each(node => {
|
|
1165
1317
|
if (!node.parentNode) {
|
|
@@ -1177,7 +1329,9 @@ class Nodes {
|
|
|
1177
1329
|
});
|
|
1178
1330
|
return this;
|
|
1179
1331
|
}
|
|
1180
|
-
|
|
1332
|
+
/**
|
|
1333
|
+
* Splits the first node, which must be a text node, into two nodes at the specified offset, keeping both as siblings in the tree.
|
|
1334
|
+
*/
|
|
1181
1335
|
splitText(offset) {
|
|
1182
1336
|
if (!this.isText) {
|
|
1183
1337
|
return new Nodes();
|
|
@@ -1186,7 +1340,9 @@ class Nodes {
|
|
|
1186
1340
|
const newNode = node.splitText(offset);
|
|
1187
1341
|
return new Nodes(newNode);
|
|
1188
1342
|
}
|
|
1189
|
-
|
|
1343
|
+
/**
|
|
1344
|
+
* Returns information about the first node, which is used for debugging.
|
|
1345
|
+
*/
|
|
1190
1346
|
toString() {
|
|
1191
1347
|
if (this.length === 0) {
|
|
1192
1348
|
return '';
|
|
@@ -1198,13 +1354,19 @@ class Nodes {
|
|
|
1198
1354
|
}
|
|
1199
1355
|
return `node (${node.lakeId}): ${nodeValue}`;
|
|
1200
1356
|
}
|
|
1201
|
-
|
|
1357
|
+
/**
|
|
1358
|
+
* Prints information about the first node, which is used for debugging.
|
|
1359
|
+
*/
|
|
1202
1360
|
info() {
|
|
1203
1361
|
debug(this.toString());
|
|
1204
1362
|
}
|
|
1205
1363
|
}
|
|
1206
1364
|
|
|
1207
|
-
|
|
1365
|
+
/**
|
|
1366
|
+
* Returns a Nodes object representing a collection of the nodes.
|
|
1367
|
+
* This function is similar to jQuery, but its implementation is very simple.
|
|
1368
|
+
* It is designed for simplifying DOM manipulation.
|
|
1369
|
+
*/
|
|
1208
1370
|
function query(content) {
|
|
1209
1371
|
if (content instanceof Nodes) {
|
|
1210
1372
|
return content;
|
|
@@ -1222,10 +1384,13 @@ const characterMap = new Map([
|
|
|
1222
1384
|
]);
|
|
1223
1385
|
// Converts all of the reserved characters in the specified string to HTML entities.
|
|
1224
1386
|
function encode(value) {
|
|
1225
|
-
return value.replace(/[&<>"\xA0]/g, match => { var _a; return (_a = characterMap.get(match)) !== null && _a !==
|
|
1387
|
+
return value.replace(/[&<>"\xA0]/g, match => { var _a; return (_a = characterMap.get(match)) !== null && _a !== void 0 ? _a : ''; });
|
|
1226
1388
|
}
|
|
1227
1389
|
|
|
1228
|
-
|
|
1390
|
+
/**
|
|
1391
|
+
* A tag function that converts all of the reserved characters in the specified string to HTML entities.
|
|
1392
|
+
* It also removes empty spaces at the beginning and end of lines.
|
|
1393
|
+
*/
|
|
1229
1394
|
function template(strings, ...keys) {
|
|
1230
1395
|
let content = strings[0];
|
|
1231
1396
|
for (let i = 0; i < keys.length; i++) {
|
|
@@ -1235,82 +1400,170 @@ function template(strings, ...keys) {
|
|
|
1235
1400
|
// Don't escape special characters in the template.
|
|
1236
1401
|
content += strings[i + 1];
|
|
1237
1402
|
}
|
|
1238
|
-
content = content
|
|
1239
|
-
replace(/^\s+/gm, '')
|
|
1240
|
-
replace(/\s+$/gm, '')
|
|
1241
|
-
replace(/[\r\n]/g, '');
|
|
1403
|
+
content = content
|
|
1404
|
+
.replace(/^\s+/gm, '')
|
|
1405
|
+
.replace(/\s+$/gm, '')
|
|
1406
|
+
.replace(/[\r\n]/g, '');
|
|
1242
1407
|
return content;
|
|
1243
1408
|
}
|
|
1244
1409
|
|
|
1245
|
-
|
|
1246
|
-
|
|
1247
|
-
|
|
1248
|
-
|
|
1410
|
+
const boxInstances = new Map();
|
|
1411
|
+
function getInstanceMap(id) {
|
|
1412
|
+
let instanceMap = boxInstances.get(id);
|
|
1413
|
+
if (!instanceMap) {
|
|
1414
|
+
instanceMap = new Map();
|
|
1415
|
+
boxInstances.set(id, instanceMap);
|
|
1416
|
+
return instanceMap;
|
|
1249
1417
|
}
|
|
1250
|
-
|
|
1251
|
-
|
|
1252
|
-
|
|
1418
|
+
return instanceMap;
|
|
1419
|
+
}
|
|
1420
|
+
|
|
1421
|
+
const boxes = new Map();
|
|
1422
|
+
|
|
1423
|
+
const editors = new Map();
|
|
1424
|
+
|
|
1425
|
+
// Creates a Base64-encoded ASCII string from a string.
|
|
1426
|
+
function toBase64(value) {
|
|
1427
|
+
const encoder = new TextEncoder();
|
|
1428
|
+
const byteArray = encoder.encode(value);
|
|
1429
|
+
let binaryString = '';
|
|
1430
|
+
byteArray.forEach(byte => {
|
|
1431
|
+
binaryString += String.fromCharCode(byte);
|
|
1432
|
+
});
|
|
1433
|
+
return window.btoa(binaryString);
|
|
1434
|
+
}
|
|
1435
|
+
|
|
1436
|
+
// Decodes a string of data which has been encoded using Base64 encoding.
|
|
1437
|
+
function fromBase64(value) {
|
|
1438
|
+
const binaryString = window.atob(value);
|
|
1439
|
+
const byteArray = new Uint8Array(binaryString.length);
|
|
1440
|
+
for (let i = 0; i < binaryString.length; i++) {
|
|
1441
|
+
byteArray[i] = binaryString.charCodeAt(i);
|
|
1253
1442
|
}
|
|
1254
|
-
|
|
1255
|
-
|
|
1256
|
-
|
|
1257
|
-
|
|
1258
|
-
|
|
1259
|
-
|
|
1260
|
-
|
|
1261
|
-
|
|
1262
|
-
|
|
1263
|
-
|
|
1264
|
-
|
|
1265
|
-
});
|
|
1266
|
-
}
|
|
1267
|
-
child = child.next();
|
|
1268
|
-
}
|
|
1269
|
-
return new Nodes(nodeList);
|
|
1443
|
+
const decoder = new TextDecoder();
|
|
1444
|
+
return decoder.decode(byteArray);
|
|
1445
|
+
}
|
|
1446
|
+
|
|
1447
|
+
function visibleInfo(target) {
|
|
1448
|
+
let rect;
|
|
1449
|
+
let viewport;
|
|
1450
|
+
if (target instanceof Nodes) {
|
|
1451
|
+
const nativeNode = target.get(0);
|
|
1452
|
+
rect = nativeNode.getBoundingClientRect();
|
|
1453
|
+
viewport = target.closestScroller();
|
|
1270
1454
|
}
|
|
1271
|
-
|
|
1272
|
-
|
|
1273
|
-
|
|
1274
|
-
|
|
1275
|
-
|
|
1455
|
+
else {
|
|
1456
|
+
rect = target.get().getBoundingClientRect();
|
|
1457
|
+
viewport = target.commonAncestor.closestScroller();
|
|
1458
|
+
}
|
|
1459
|
+
let left = rect.left;
|
|
1460
|
+
let right = rect.right;
|
|
1461
|
+
let top = rect.top;
|
|
1462
|
+
let bottom = rect.bottom;
|
|
1463
|
+
let viewportWidth = window.innerWidth;
|
|
1464
|
+
let viewportHeight = window.innerHeight;
|
|
1465
|
+
if (viewport.length > 0) {
|
|
1466
|
+
const nativeViewport = viewport.get(0);
|
|
1467
|
+
const viewportRect = nativeViewport.getBoundingClientRect();
|
|
1468
|
+
const offsetLeft = viewportRect.x;
|
|
1469
|
+
const offsetTop = viewportRect.y;
|
|
1470
|
+
left -= offsetLeft;
|
|
1471
|
+
right -= offsetLeft;
|
|
1472
|
+
top -= offsetTop;
|
|
1473
|
+
bottom -= offsetTop;
|
|
1474
|
+
viewportWidth = viewportRect.width;
|
|
1475
|
+
viewportHeight = viewportRect.height;
|
|
1476
|
+
}
|
|
1477
|
+
let leftEdge = 0;
|
|
1478
|
+
if (left < 0) {
|
|
1479
|
+
leftEdge = -1;
|
|
1480
|
+
}
|
|
1481
|
+
else if (viewportWidth - left < 0) {
|
|
1482
|
+
leftEdge = 1;
|
|
1483
|
+
}
|
|
1484
|
+
let rightEdge = 0;
|
|
1485
|
+
if (right < 0) {
|
|
1486
|
+
rightEdge = -1;
|
|
1487
|
+
}
|
|
1488
|
+
else if (viewportWidth - right < 0) {
|
|
1489
|
+
rightEdge = 1;
|
|
1490
|
+
}
|
|
1491
|
+
let topEdge = 0;
|
|
1492
|
+
if (top < 0) {
|
|
1493
|
+
topEdge = -1;
|
|
1494
|
+
}
|
|
1495
|
+
else if (viewportHeight - top < 0) {
|
|
1496
|
+
topEdge = 1;
|
|
1497
|
+
}
|
|
1498
|
+
let bottomEdge = 0;
|
|
1499
|
+
if (bottom < 0) {
|
|
1500
|
+
bottomEdge = -1;
|
|
1501
|
+
}
|
|
1502
|
+
else if (viewportHeight - bottom < 0) {
|
|
1503
|
+
bottomEdge = 1;
|
|
1276
1504
|
}
|
|
1505
|
+
return {
|
|
1506
|
+
left: leftEdge,
|
|
1507
|
+
right: rightEdge,
|
|
1508
|
+
top: topEdge,
|
|
1509
|
+
bottom: bottomEdge,
|
|
1510
|
+
};
|
|
1277
1511
|
}
|
|
1278
1512
|
|
|
1279
|
-
|
|
1513
|
+
/**
|
|
1514
|
+
* The Range interface represents a fragment of a document that can contain nodes and parts of text nodes.
|
|
1515
|
+
* Its interface is similar to the native Range, with some additional properties and methods specifically designed for more efficient manipulation.
|
|
1516
|
+
*/
|
|
1280
1517
|
class Range {
|
|
1281
1518
|
constructor(range) {
|
|
1282
|
-
this.range = range !== null && range !==
|
|
1519
|
+
this.range = range !== null && range !== void 0 ? range : document.createRange();
|
|
1283
1520
|
}
|
|
1284
|
-
|
|
1521
|
+
/**
|
|
1522
|
+
* A node within which the range starts.
|
|
1523
|
+
*/
|
|
1285
1524
|
get startNode() {
|
|
1286
1525
|
return new Nodes(this.range.startContainer);
|
|
1287
1526
|
}
|
|
1288
|
-
|
|
1527
|
+
/**
|
|
1528
|
+
* A number representing where in the startNode the range starts.
|
|
1529
|
+
*/
|
|
1289
1530
|
get startOffset() {
|
|
1290
1531
|
return this.range.startOffset;
|
|
1291
1532
|
}
|
|
1292
|
-
|
|
1533
|
+
/**
|
|
1534
|
+
* A node within which the range ends.
|
|
1535
|
+
*/
|
|
1293
1536
|
get endNode() {
|
|
1294
1537
|
return new Nodes(this.range.endContainer);
|
|
1295
1538
|
}
|
|
1296
|
-
|
|
1539
|
+
/**
|
|
1540
|
+
* A number representing where in the endNode the range ends.
|
|
1541
|
+
*/
|
|
1297
1542
|
get endOffset() {
|
|
1298
1543
|
return this.range.endOffset;
|
|
1299
1544
|
}
|
|
1300
|
-
|
|
1545
|
+
/**
|
|
1546
|
+
* The deepest — or furthest down the document tree — node that contains both boundary points of the range.
|
|
1547
|
+
*/
|
|
1301
1548
|
get commonAncestor() {
|
|
1302
1549
|
return new Nodes(this.range.commonAncestorContainer);
|
|
1303
1550
|
}
|
|
1304
|
-
|
|
1551
|
+
/**
|
|
1552
|
+
* A boolean value indicating whether the range's start and end points are at the same position.
|
|
1553
|
+
*/
|
|
1305
1554
|
get isCollapsed() {
|
|
1306
1555
|
return this.range.collapsed;
|
|
1307
1556
|
}
|
|
1308
|
-
|
|
1557
|
+
/**
|
|
1558
|
+
* A boolean value indicating whether the range's start point is in a box.
|
|
1559
|
+
*/
|
|
1309
1560
|
get isBox() {
|
|
1310
1561
|
const boxNode = this.commonAncestor.closest('lake-box');
|
|
1311
1562
|
return boxNode.length > 0;
|
|
1312
1563
|
}
|
|
1313
|
-
|
|
1564
|
+
/**
|
|
1565
|
+
* A boolean value indicating whether the commonAncestor is in the start position of a box.
|
|
1566
|
+
*/
|
|
1314
1567
|
// case 1: <lake-box><span class="lake-box-strip">|</span><div class="lake-box-container"></div> ...
|
|
1315
1568
|
// case 2: <lake-box><span class="lake-box-strip"></span>|<div class="lake-box-container"></div> ...
|
|
1316
1569
|
// case 3: <lake-box>|<span class="lake-box-strip"></span><div class="lake-box-container"></div> ...
|
|
@@ -1322,7 +1575,9 @@ class Range {
|
|
|
1322
1575
|
const boxContainer = boxNode.find('.lake-box-container');
|
|
1323
1576
|
return this.compareBeforeNode(boxContainer) >= 0;
|
|
1324
1577
|
}
|
|
1325
|
-
|
|
1578
|
+
/**
|
|
1579
|
+
* A boolean value indicating whether the commonAncestor is in the center position of a box.
|
|
1580
|
+
*/
|
|
1326
1581
|
// case 1: ... <div class="lake-box-container"><div>|</div></div> ...
|
|
1327
1582
|
// case 2: ... <div class="lake-box-container"><div></div>|</div> ...
|
|
1328
1583
|
get isBoxCenter() {
|
|
@@ -1335,7 +1590,9 @@ class Range {
|
|
|
1335
1590
|
// case: ... <div class="lake-box-container">|<div></div></div> ...
|
|
1336
1591
|
return this.isCollapsed && this.startNode.get(0) === boxContainer.get(0) && this.startOffset === 0;
|
|
1337
1592
|
}
|
|
1338
|
-
|
|
1593
|
+
/**
|
|
1594
|
+
* A boolean value indicating whether commonAncestor is in the end position of a box.
|
|
1595
|
+
*/
|
|
1339
1596
|
// case 1: ... <div class="lake-box-container"></div><span class="lake-box-strip">|</span></lake-box>
|
|
1340
1597
|
// case 2: ... <div class="lake-box-container"></div>|<span class="lake-box-strip"></span></lake-box>
|
|
1341
1598
|
// case 3: ... <div class="lake-box-container"></div><span class="lake-box-strip"></span>|</lake-box>
|
|
@@ -1347,7 +1604,9 @@ class Range {
|
|
|
1347
1604
|
const boxContainer = boxNode.find('.lake-box-container');
|
|
1348
1605
|
return this.compareAfterNode(boxContainer) <= 0;
|
|
1349
1606
|
}
|
|
1350
|
-
|
|
1607
|
+
/**
|
|
1608
|
+
* A boolean value indicating whether commonAncestor is inside the container of a box.
|
|
1609
|
+
*/
|
|
1351
1610
|
// case 1: ... <div class="lake-box-container"><div>|</div></div> ...
|
|
1352
1611
|
// case 2: ... <div class="lake-box-container"><div></div>|</div> ...
|
|
1353
1612
|
get isInsideBox() {
|
|
@@ -1358,32 +1617,38 @@ class Range {
|
|
|
1358
1617
|
const boxContainer = boxNode.find('.lake-box-container');
|
|
1359
1618
|
// Returns false when the box was selected.
|
|
1360
1619
|
// case: ... <div class="lake-box-container">|<div></div></div> ...
|
|
1361
|
-
if (this.isCollapsed
|
|
1362
|
-
this.startNode.get(0) === boxContainer.get(0)
|
|
1363
|
-
this.startOffset === 0) {
|
|
1620
|
+
if (this.isCollapsed
|
|
1621
|
+
&& this.startNode.get(0) === boxContainer.get(0)
|
|
1622
|
+
&& this.startOffset === 0) {
|
|
1364
1623
|
return false;
|
|
1365
1624
|
}
|
|
1366
1625
|
return this.compareBeforeNode(boxContainer) < 0 && this.compareAfterNode(boxContainer) > 0;
|
|
1367
1626
|
}
|
|
1368
|
-
|
|
1627
|
+
/**
|
|
1628
|
+
* A boolean value indicating whether the range is inoperative.
|
|
1629
|
+
*/
|
|
1369
1630
|
get isInoperative() {
|
|
1370
1631
|
if (this.commonAncestor.isOutside) {
|
|
1371
1632
|
return true;
|
|
1372
1633
|
}
|
|
1373
1634
|
const startBlock = this.startNode.closest('td');
|
|
1374
1635
|
const endBlock = this.endNode.closest('td');
|
|
1375
|
-
if (startBlock.length > 0
|
|
1376
|
-
endBlock.length > 0
|
|
1377
|
-
startBlock.get(0) !== endBlock.get(0)) {
|
|
1636
|
+
if (startBlock.length > 0
|
|
1637
|
+
&& endBlock.length > 0
|
|
1638
|
+
&& startBlock.get(0) !== endBlock.get(0)) {
|
|
1378
1639
|
return true;
|
|
1379
1640
|
}
|
|
1380
1641
|
return false;
|
|
1381
1642
|
}
|
|
1382
|
-
|
|
1643
|
+
/**
|
|
1644
|
+
* Returns a native Range object from the range.
|
|
1645
|
+
*/
|
|
1383
1646
|
get() {
|
|
1384
1647
|
return this.range;
|
|
1385
1648
|
}
|
|
1386
|
-
|
|
1649
|
+
/**
|
|
1650
|
+
* Returns the size and position of the range.
|
|
1651
|
+
*/
|
|
1387
1652
|
getRect() {
|
|
1388
1653
|
const range = this.clone();
|
|
1389
1654
|
let rect;
|
|
@@ -1436,13 +1701,17 @@ class Range {
|
|
|
1436
1701
|
height: height > 0 ? height : 1,
|
|
1437
1702
|
});
|
|
1438
1703
|
}
|
|
1439
|
-
|
|
1440
|
-
|
|
1704
|
+
/**
|
|
1705
|
+
* Returns -1, 0, or 1 depending on whether the specified node is before, the same as, or after the range.
|
|
1706
|
+
* −1 if the point is before the range. 0 if the point is in the range. 1 if the point is after the range.
|
|
1707
|
+
*/
|
|
1441
1708
|
comparePoint(node, offset) {
|
|
1442
1709
|
return this.range.comparePoint(node.get(0), offset);
|
|
1443
1710
|
}
|
|
1444
|
-
|
|
1445
|
-
|
|
1711
|
+
/**
|
|
1712
|
+
* Returns -1, 0, or 1 depending on whether the beginning of the specified node is before, the same as, or after the range.
|
|
1713
|
+
* −1 if the beginning of the node is before the range. 0 if the beginning of the node is in the range. 1 if the beginning of the node is after the range.
|
|
1714
|
+
*/
|
|
1446
1715
|
compareBeforeNode(node) {
|
|
1447
1716
|
const targetRange = new Range();
|
|
1448
1717
|
if (node.isText) {
|
|
@@ -1454,13 +1723,15 @@ class Range {
|
|
|
1454
1723
|
targetRange.collapseToStart();
|
|
1455
1724
|
return this.comparePoint(targetRange.startNode, targetRange.startOffset);
|
|
1456
1725
|
}
|
|
1457
|
-
|
|
1458
|
-
|
|
1726
|
+
/**
|
|
1727
|
+
* Returns -1, 0, or 1 depending on whether the end of the specified node is before, the same as, or after the range.
|
|
1728
|
+
* −1 if the end of the node is before the range. 0 if the end of the node is in the range. 1 if the end of the node is after the range.
|
|
1729
|
+
*/
|
|
1459
1730
|
compareAfterNode(node) {
|
|
1460
1731
|
var _a;
|
|
1461
1732
|
const targetRange = new Range();
|
|
1462
1733
|
if (node.isText) {
|
|
1463
|
-
const nodeValue = (_a = node.get(0).nodeValue) !== null && _a !==
|
|
1734
|
+
const nodeValue = (_a = node.get(0).nodeValue) !== null && _a !== void 0 ? _a : '';
|
|
1464
1735
|
targetRange.setStart(node, nodeValue.length);
|
|
1465
1736
|
}
|
|
1466
1737
|
else {
|
|
@@ -1469,51 +1740,75 @@ class Range {
|
|
|
1469
1740
|
targetRange.collapseToStart();
|
|
1470
1741
|
return this.comparePoint(targetRange.startNode, targetRange.startOffset);
|
|
1471
1742
|
}
|
|
1472
|
-
|
|
1743
|
+
/**
|
|
1744
|
+
* Returns a boolean value indicating whether the specified node is part of the range or intersects the range.
|
|
1745
|
+
*/
|
|
1473
1746
|
intersectsNode(node) {
|
|
1474
1747
|
return this.range.intersectsNode(node.get(0));
|
|
1475
1748
|
}
|
|
1476
|
-
|
|
1749
|
+
/**
|
|
1750
|
+
* Sets the start position of the range.
|
|
1751
|
+
*/
|
|
1477
1752
|
setStart(node, offset) {
|
|
1478
1753
|
this.range.setStart(node.get(0), offset);
|
|
1479
1754
|
}
|
|
1480
|
-
|
|
1755
|
+
/**
|
|
1756
|
+
* Sets the start position of the range to the beginning of the specified node.
|
|
1757
|
+
*/
|
|
1481
1758
|
setStartBefore(node) {
|
|
1482
1759
|
this.range.setStartBefore(node.get(0));
|
|
1483
1760
|
}
|
|
1484
|
-
|
|
1761
|
+
/**
|
|
1762
|
+
* Sets the start position of the range to the end of the specified node.
|
|
1763
|
+
*/
|
|
1485
1764
|
setStartAfter(node) {
|
|
1486
1765
|
this.range.setStartAfter(node.get(0));
|
|
1487
1766
|
}
|
|
1488
|
-
|
|
1767
|
+
/**
|
|
1768
|
+
* Sets the end position of the range.
|
|
1769
|
+
*/
|
|
1489
1770
|
setEnd(node, offset) {
|
|
1490
1771
|
this.range.setEnd(node.get(0), offset);
|
|
1491
1772
|
}
|
|
1492
|
-
|
|
1773
|
+
/**
|
|
1774
|
+
* Sets the end position of the range to the beginning of the specified node.
|
|
1775
|
+
*/
|
|
1493
1776
|
setEndBefore(node) {
|
|
1494
1777
|
this.range.setEndBefore(node.get(0));
|
|
1495
1778
|
}
|
|
1496
|
-
|
|
1779
|
+
/**
|
|
1780
|
+
* Sets the end position of the range to the end of the specified node.
|
|
1781
|
+
*/
|
|
1497
1782
|
setEndAfter(node) {
|
|
1498
1783
|
this.range.setEndAfter(node.get(0));
|
|
1499
1784
|
}
|
|
1500
|
-
|
|
1785
|
+
/**
|
|
1786
|
+
* Collapses the range to its start.
|
|
1787
|
+
*/
|
|
1501
1788
|
collapseToStart() {
|
|
1502
1789
|
this.range.collapse(true);
|
|
1503
1790
|
}
|
|
1504
|
-
|
|
1791
|
+
/**
|
|
1792
|
+
* Collapses the range to its end.
|
|
1793
|
+
*/
|
|
1505
1794
|
collapseToEnd() {
|
|
1506
1795
|
this.range.collapse(false);
|
|
1507
1796
|
}
|
|
1508
|
-
|
|
1797
|
+
/**
|
|
1798
|
+
* Sets the range to contain the specified node and its contents.
|
|
1799
|
+
*/
|
|
1509
1800
|
selectNode(node) {
|
|
1510
1801
|
this.range.selectNode(node.get(0));
|
|
1511
1802
|
}
|
|
1512
|
-
|
|
1803
|
+
/**
|
|
1804
|
+
* Sets the range to contain the contents of the specified node.
|
|
1805
|
+
*/
|
|
1513
1806
|
selectNodeContents(node) {
|
|
1514
1807
|
this.range.selectNodeContents(node.get(0));
|
|
1515
1808
|
}
|
|
1516
|
-
|
|
1809
|
+
/**
|
|
1810
|
+
* Collapses the range to the center position of the specified box.
|
|
1811
|
+
*/
|
|
1517
1812
|
selectBox(boxNode) {
|
|
1518
1813
|
const boxContainer = boxNode.find('.lake-box-container');
|
|
1519
1814
|
if (boxContainer.length === 0) {
|
|
@@ -1522,7 +1817,9 @@ class Range {
|
|
|
1522
1817
|
this.setStart(boxContainer, 0);
|
|
1523
1818
|
this.collapseToStart();
|
|
1524
1819
|
}
|
|
1525
|
-
|
|
1820
|
+
/**
|
|
1821
|
+
* Collapses the range to the start position of the specified box.
|
|
1822
|
+
*/
|
|
1526
1823
|
selectBoxStart(boxNode) {
|
|
1527
1824
|
const boxStrip = boxNode.find('.lake-box-strip');
|
|
1528
1825
|
if (boxStrip.length === 0) {
|
|
@@ -1531,7 +1828,9 @@ class Range {
|
|
|
1531
1828
|
this.selectNodeContents(boxStrip.eq(0));
|
|
1532
1829
|
this.collapseToStart();
|
|
1533
1830
|
}
|
|
1534
|
-
|
|
1831
|
+
/**
|
|
1832
|
+
* Collapses the range to the end position of the specified box.
|
|
1833
|
+
*/
|
|
1535
1834
|
selectBoxEnd(boxNode) {
|
|
1536
1835
|
const boxStrip = boxNode.find('.lake-box-strip');
|
|
1537
1836
|
if (boxStrip.length === 0) {
|
|
@@ -1540,7 +1839,9 @@ class Range {
|
|
|
1540
1839
|
this.selectNodeContents(boxStrip.eq(1));
|
|
1541
1840
|
this.collapseToStart();
|
|
1542
1841
|
}
|
|
1543
|
-
|
|
1842
|
+
/**
|
|
1843
|
+
* Collapses the range to the deepest point at the beginning of the contents of the specified node.
|
|
1844
|
+
*/
|
|
1544
1845
|
shrinkBefore(node) {
|
|
1545
1846
|
if (node.isBox) {
|
|
1546
1847
|
this.selectBoxStart(node);
|
|
@@ -1553,9 +1854,9 @@ class Range {
|
|
|
1553
1854
|
}
|
|
1554
1855
|
this.setStart(node, 0);
|
|
1555
1856
|
let child;
|
|
1556
|
-
while (this.startNode.isElement
|
|
1557
|
-
(child = this.startNode.children()[0])
|
|
1558
|
-
child.isElement && !child.isVoid) {
|
|
1857
|
+
while (this.startNode.isElement
|
|
1858
|
+
&& (child = this.startNode.children()[0])
|
|
1859
|
+
&& child.isElement && !child.isVoid) {
|
|
1559
1860
|
if (child.isBox) {
|
|
1560
1861
|
this.selectBoxStart(child);
|
|
1561
1862
|
return;
|
|
@@ -1564,7 +1865,9 @@ class Range {
|
|
|
1564
1865
|
}
|
|
1565
1866
|
this.collapseToStart();
|
|
1566
1867
|
}
|
|
1567
|
-
|
|
1868
|
+
/**
|
|
1869
|
+
* Collapses the range to the deepest point at the end of the contents of the specified node.
|
|
1870
|
+
*/
|
|
1568
1871
|
shrinkAfter(node) {
|
|
1569
1872
|
if (node.isBox) {
|
|
1570
1873
|
this.selectBoxEnd(node);
|
|
@@ -1577,10 +1880,10 @@ class Range {
|
|
|
1577
1880
|
}
|
|
1578
1881
|
this.setEnd(node, node.children().length);
|
|
1579
1882
|
let child;
|
|
1580
|
-
while (this.endNode.isElement
|
|
1581
|
-
this.endOffset > 0
|
|
1582
|
-
(child = this.endNode.children()[this.endOffset - 1])
|
|
1583
|
-
child.isElement && !child.isVoid) {
|
|
1883
|
+
while (this.endNode.isElement
|
|
1884
|
+
&& this.endOffset > 0
|
|
1885
|
+
&& (child = this.endNode.children()[this.endOffset - 1])
|
|
1886
|
+
&& child.isElement && !child.isVoid) {
|
|
1584
1887
|
if (child.isBox) {
|
|
1585
1888
|
this.selectBoxEnd(child);
|
|
1586
1889
|
return;
|
|
@@ -1590,30 +1893,34 @@ class Range {
|
|
|
1590
1893
|
this.collapseToEnd();
|
|
1591
1894
|
this.adjustBr();
|
|
1592
1895
|
}
|
|
1593
|
-
|
|
1896
|
+
/**
|
|
1897
|
+
* Sets the start and end positions of the range to the deepest start position and end position of the contents of the specified node.
|
|
1898
|
+
*/
|
|
1594
1899
|
// <div>[<p><strong>foo</strong></p>]</div>
|
|
1595
1900
|
// to
|
|
1596
1901
|
// <div><p><strong>[foo]</strong></p></div>
|
|
1597
1902
|
shrink() {
|
|
1598
1903
|
const isCollapsed = this.isCollapsed;
|
|
1599
1904
|
let child;
|
|
1600
|
-
while (this.startNode.isElement
|
|
1601
|
-
(child = this.startNode.children()[this.startOffset])
|
|
1602
|
-
child.isElement && !child.isVoid && !child.isBox) {
|
|
1905
|
+
while (this.startNode.isElement
|
|
1906
|
+
&& (child = this.startNode.children()[this.startOffset])
|
|
1907
|
+
&& child.isElement && !child.isVoid && !child.isBox) {
|
|
1603
1908
|
this.setStart(child, 0);
|
|
1604
1909
|
}
|
|
1605
1910
|
if (isCollapsed) {
|
|
1606
1911
|
this.collapseToStart();
|
|
1607
1912
|
return;
|
|
1608
1913
|
}
|
|
1609
|
-
while (this.endNode.isElement
|
|
1610
|
-
this.endOffset > 0
|
|
1611
|
-
(child = this.endNode.children()[this.endOffset - 1])
|
|
1612
|
-
child.isElement && !child.isVoid && !child.isBox) {
|
|
1914
|
+
while (this.endNode.isElement
|
|
1915
|
+
&& this.endOffset > 0
|
|
1916
|
+
&& (child = this.endNode.children()[this.endOffset - 1])
|
|
1917
|
+
&& child.isElement && !child.isVoid && !child.isBox) {
|
|
1613
1918
|
this.setEnd(child, child.children().length);
|
|
1614
1919
|
}
|
|
1615
1920
|
}
|
|
1616
|
-
|
|
1921
|
+
/**
|
|
1922
|
+
* Relocates the start and end positions of the range for boxes.
|
|
1923
|
+
*/
|
|
1617
1924
|
adjustBox() {
|
|
1618
1925
|
const startBoxNode = this.startNode.closest('lake-box');
|
|
1619
1926
|
if (startBoxNode.length > 0) {
|
|
@@ -1638,7 +1945,9 @@ class Range {
|
|
|
1638
1945
|
}
|
|
1639
1946
|
}
|
|
1640
1947
|
}
|
|
1641
|
-
|
|
1948
|
+
/**
|
|
1949
|
+
* Relocates the start and end positions of the range for tables.
|
|
1950
|
+
*/
|
|
1642
1951
|
adjustTable() {
|
|
1643
1952
|
const startTable = this.startNode.closest('table');
|
|
1644
1953
|
const endTable = this.endNode.closest('table');
|
|
@@ -1652,7 +1961,9 @@ class Range {
|
|
|
1652
1961
|
this.shrink();
|
|
1653
1962
|
}
|
|
1654
1963
|
}
|
|
1655
|
-
|
|
1964
|
+
/**
|
|
1965
|
+
* Relocates the start and end positions of the range for blocks.
|
|
1966
|
+
*/
|
|
1656
1967
|
// case 1:
|
|
1657
1968
|
// <p>foo</p>|<p>bar</p>
|
|
1658
1969
|
// to
|
|
@@ -1686,13 +1997,17 @@ class Range {
|
|
|
1686
1997
|
this.shrinkBefore(nextBlock);
|
|
1687
1998
|
}
|
|
1688
1999
|
}
|
|
1689
|
-
|
|
2000
|
+
/**
|
|
2001
|
+
* Relocates the start and end positions of the range for boxes, tables, and blocks.
|
|
2002
|
+
*/
|
|
1690
2003
|
adjust() {
|
|
1691
2004
|
this.adjustBox();
|
|
1692
2005
|
this.adjustTable();
|
|
1693
2006
|
this.adjustBlock();
|
|
1694
2007
|
}
|
|
1695
|
-
|
|
2008
|
+
/**
|
|
2009
|
+
* Relocates the start and end positions of the range for <br /> elements.
|
|
2010
|
+
*/
|
|
1696
2011
|
// In composition mode (e.g., when a user starts entering a Chinese character using a Pinyin IME),
|
|
1697
2012
|
// uncompleted text is inserted if the cursor is positioned behind a <br> tag.
|
|
1698
2013
|
// To fix this bug, the cursor needs to be moved to the front of the <br> tag.
|
|
@@ -1707,7 +2022,9 @@ class Range {
|
|
|
1707
2022
|
this.collapseToStart();
|
|
1708
2023
|
}
|
|
1709
2024
|
}
|
|
1710
|
-
|
|
2025
|
+
/**
|
|
2026
|
+
* Returns the node immediately preceding the start position of the range.
|
|
2027
|
+
*/
|
|
1711
2028
|
getPrevNode() {
|
|
1712
2029
|
let prevNode;
|
|
1713
2030
|
if (this.startNode.isText) {
|
|
@@ -1721,9 +2038,11 @@ class Range {
|
|
|
1721
2038
|
else {
|
|
1722
2039
|
prevNode = this.startNode.children()[this.startOffset - 1];
|
|
1723
2040
|
}
|
|
1724
|
-
return prevNode !== null && prevNode !==
|
|
2041
|
+
return prevNode !== null && prevNode !== void 0 ? prevNode : new Nodes();
|
|
1725
2042
|
}
|
|
1726
|
-
|
|
2043
|
+
/**
|
|
2044
|
+
* Returns the node immediately following the end position of the range.
|
|
2045
|
+
*/
|
|
1727
2046
|
getNextNode() {
|
|
1728
2047
|
let nextNode;
|
|
1729
2048
|
if (this.endNode.isText) {
|
|
@@ -1737,9 +2056,11 @@ class Range {
|
|
|
1737
2056
|
else {
|
|
1738
2057
|
nextNode = this.endNode.children()[this.endOffset];
|
|
1739
2058
|
}
|
|
1740
|
-
return nextNode !== null && nextNode !==
|
|
2059
|
+
return nextNode !== null && nextNode !== void 0 ? nextNode : new Nodes();
|
|
1741
2060
|
}
|
|
1742
|
-
|
|
2061
|
+
/**
|
|
2062
|
+
* Returns the boxes contained within or intersected by the range.
|
|
2063
|
+
*/
|
|
1743
2064
|
getBoxes() {
|
|
1744
2065
|
if (this.isCollapsed) {
|
|
1745
2066
|
const startBox = this.startNode.closest('lake-box');
|
|
@@ -1755,7 +2076,9 @@ class Range {
|
|
|
1755
2076
|
}
|
|
1756
2077
|
return nodeList;
|
|
1757
2078
|
}
|
|
1758
|
-
|
|
2079
|
+
/**
|
|
2080
|
+
* Returns the blocks contained within or intersected by the range.
|
|
2081
|
+
*/
|
|
1759
2082
|
getBlocks() {
|
|
1760
2083
|
if (this.isCollapsed) {
|
|
1761
2084
|
const startBlock = this.startNode.closestOperableBlock();
|
|
@@ -1766,19 +2089,19 @@ class Range {
|
|
|
1766
2089
|
}
|
|
1767
2090
|
const startBlock = this.startNode.closestOperableBlock();
|
|
1768
2091
|
const endBlock = this.endNode.closestOperableBlock();
|
|
1769
|
-
if (startBlock.isInside
|
|
1770
|
-
startBlock.get(0)
|
|
1771
|
-
startBlock.get(0) === endBlock.get(0)) {
|
|
2092
|
+
if (startBlock.isInside
|
|
2093
|
+
&& startBlock.get(0)
|
|
2094
|
+
&& startBlock.get(0) === endBlock.get(0)) {
|
|
1772
2095
|
return startBlock.isTable ? [] : [startBlock];
|
|
1773
2096
|
}
|
|
1774
2097
|
const blocks = [];
|
|
1775
2098
|
const clonedRange = this.clone();
|
|
1776
2099
|
clonedRange.collapseToEnd();
|
|
1777
2100
|
for (const child of this.commonAncestor.getWalker()) {
|
|
1778
|
-
if (child.isBlock && !child.isTable && child.isTopInside
|
|
1779
|
-
//
|
|
1780
|
-
clonedRange.comparePoint(child, 0) !== 0
|
|
1781
|
-
this.intersectsNode(child)) {
|
|
2101
|
+
if (child.isBlock && !child.isTable && child.isTopInside
|
|
2102
|
+
// The range doesn't end at the start of a block.
|
|
2103
|
+
&& clonedRange.comparePoint(child, 0) !== 0
|
|
2104
|
+
&& this.intersectsNode(child)) {
|
|
1782
2105
|
blocks.push(child);
|
|
1783
2106
|
}
|
|
1784
2107
|
}
|
|
@@ -1786,20 +2109,22 @@ class Range {
|
|
|
1786
2109
|
return blocks;
|
|
1787
2110
|
}
|
|
1788
2111
|
for (const child of this.commonAncestor.getWalker()) {
|
|
1789
|
-
if (child.isBlock && !child.isTable
|
|
1790
|
-
(startBlock.isSibling(child) || endBlock.isSibling(child))
|
|
1791
|
-
this.intersectsNode(child)) {
|
|
2112
|
+
if (child.isBlock && !child.isTable
|
|
2113
|
+
&& (startBlock.isSibling(child) || endBlock.isSibling(child))
|
|
2114
|
+
&& this.intersectsNode(child)) {
|
|
1792
2115
|
blocks.push(child);
|
|
1793
2116
|
}
|
|
1794
2117
|
}
|
|
1795
2118
|
return blocks;
|
|
1796
2119
|
}
|
|
1797
|
-
|
|
2120
|
+
/**
|
|
2121
|
+
* Returns the marks and text nodes contained within or intersected by the range.
|
|
2122
|
+
*/
|
|
1798
2123
|
getMarks(hasText = false) {
|
|
1799
2124
|
const marks = [];
|
|
1800
2125
|
if (this.commonAncestor.isText && hasText) {
|
|
1801
|
-
if (this.startOffset === 0
|
|
1802
|
-
this.endOffset === this.commonAncestor.text().length) {
|
|
2126
|
+
if (this.startOffset === 0
|
|
2127
|
+
&& this.endOffset === this.commonAncestor.text().length) {
|
|
1803
2128
|
marks.push(this.commonAncestor);
|
|
1804
2129
|
return marks;
|
|
1805
2130
|
}
|
|
@@ -1826,7 +2151,9 @@ class Range {
|
|
|
1826
2151
|
}
|
|
1827
2152
|
return marks;
|
|
1828
2153
|
}
|
|
1829
|
-
|
|
2154
|
+
/**
|
|
2155
|
+
* Returns the text from the start position of the closest block to the start position of the range.
|
|
2156
|
+
*/
|
|
1830
2157
|
// "<p>one<anchor />two<focus />three</p>" returns "one".
|
|
1831
2158
|
getStartText() {
|
|
1832
2159
|
const node = this.startNode;
|
|
@@ -1849,7 +2176,9 @@ class Range {
|
|
|
1849
2176
|
}
|
|
1850
2177
|
return text;
|
|
1851
2178
|
}
|
|
1852
|
-
|
|
2179
|
+
/**
|
|
2180
|
+
* Returns the text from the end position of the range to the end position of the closest block.
|
|
2181
|
+
*/
|
|
1853
2182
|
// "<p>one<anchor />two<focus />three</p>" returns "three".
|
|
1854
2183
|
getEndText() {
|
|
1855
2184
|
const node = this.endNode;
|
|
@@ -1872,9 +2201,11 @@ class Range {
|
|
|
1872
2201
|
}
|
|
1873
2202
|
return text;
|
|
1874
2203
|
}
|
|
1875
|
-
|
|
1876
|
-
|
|
1877
|
-
|
|
2204
|
+
/**
|
|
2205
|
+
* Returns a new range from the specified character to the start position of the range.
|
|
2206
|
+
* The specified character must be preceded by a whitespace or be at the beginning of a paragraph,
|
|
2207
|
+
* without being adjacent to other characters. It will return null if not.
|
|
2208
|
+
*/
|
|
1878
2209
|
getCharacterRange(character) {
|
|
1879
2210
|
const newRange = this.clone();
|
|
1880
2211
|
newRange.shrink();
|
|
@@ -1911,15 +2242,21 @@ class Range {
|
|
|
1911
2242
|
}
|
|
1912
2243
|
return newRange;
|
|
1913
2244
|
}
|
|
1914
|
-
|
|
2245
|
+
/**
|
|
2246
|
+
* Returns a copy of the range.
|
|
2247
|
+
*/
|
|
1915
2248
|
clone() {
|
|
1916
2249
|
return new Range(this.range.cloneRange());
|
|
1917
2250
|
}
|
|
1918
|
-
|
|
2251
|
+
/**
|
|
2252
|
+
* Returns a DocumentFragment object copying the nodes included in the range.
|
|
2253
|
+
*/
|
|
1919
2254
|
cloneContents() {
|
|
1920
2255
|
return this.range.cloneContents();
|
|
1921
2256
|
}
|
|
1922
|
-
|
|
2257
|
+
/**
|
|
2258
|
+
* Prints information about the range, which is used for debugging.
|
|
2259
|
+
*/
|
|
1923
2260
|
info() {
|
|
1924
2261
|
debug('--- range information ---');
|
|
1925
2262
|
debug('start node:', this.startNode.toString(), ', offset:', this.startOffset);
|
|
@@ -1927,98 +2264,6 @@ class Range {
|
|
|
1927
2264
|
}
|
|
1928
2265
|
}
|
|
1929
2266
|
|
|
1930
|
-
const boxes = new Map();
|
|
1931
|
-
|
|
1932
|
-
const editors = new Map();
|
|
1933
|
-
|
|
1934
|
-
// Creates a Base64-encoded ASCII string from a string.
|
|
1935
|
-
function toBase64(value) {
|
|
1936
|
-
const encoder = new TextEncoder();
|
|
1937
|
-
const byteArray = encoder.encode(value);
|
|
1938
|
-
let binaryString = '';
|
|
1939
|
-
byteArray.forEach(byte => {
|
|
1940
|
-
binaryString += String.fromCharCode(byte);
|
|
1941
|
-
});
|
|
1942
|
-
return window.btoa(binaryString);
|
|
1943
|
-
}
|
|
1944
|
-
|
|
1945
|
-
// Decodes a string of data which has been encoded using Base64 encoding.
|
|
1946
|
-
function fromBase64(value) {
|
|
1947
|
-
const binaryString = window.atob(value);
|
|
1948
|
-
const byteArray = new Uint8Array(binaryString.length);
|
|
1949
|
-
for (let i = 0; i < binaryString.length; i++) {
|
|
1950
|
-
byteArray[i] = binaryString.charCodeAt(i);
|
|
1951
|
-
}
|
|
1952
|
-
const decoder = new TextDecoder();
|
|
1953
|
-
return decoder.decode(byteArray);
|
|
1954
|
-
}
|
|
1955
|
-
|
|
1956
|
-
function visibleInfo(target) {
|
|
1957
|
-
let rect;
|
|
1958
|
-
let viewport;
|
|
1959
|
-
if (target instanceof Nodes) {
|
|
1960
|
-
const nativeNode = target.get(0);
|
|
1961
|
-
rect = nativeNode.getBoundingClientRect();
|
|
1962
|
-
viewport = target.closestScroller();
|
|
1963
|
-
}
|
|
1964
|
-
else {
|
|
1965
|
-
rect = target.get().getBoundingClientRect();
|
|
1966
|
-
viewport = target.commonAncestor.closestScroller();
|
|
1967
|
-
}
|
|
1968
|
-
let left = rect.left;
|
|
1969
|
-
let right = rect.right;
|
|
1970
|
-
let top = rect.top;
|
|
1971
|
-
let bottom = rect.bottom;
|
|
1972
|
-
let viewportWidth = window.innerWidth;
|
|
1973
|
-
let viewportHeight = window.innerHeight;
|
|
1974
|
-
if (viewport.length > 0) {
|
|
1975
|
-
const nativeViewport = viewport.get(0);
|
|
1976
|
-
const viewportRect = nativeViewport.getBoundingClientRect();
|
|
1977
|
-
const offsetLeft = viewportRect.x;
|
|
1978
|
-
const offsetTop = viewportRect.y;
|
|
1979
|
-
left -= offsetLeft;
|
|
1980
|
-
right -= offsetLeft;
|
|
1981
|
-
top -= offsetTop;
|
|
1982
|
-
bottom -= offsetTop;
|
|
1983
|
-
viewportWidth = viewportRect.width;
|
|
1984
|
-
viewportHeight = viewportRect.height;
|
|
1985
|
-
}
|
|
1986
|
-
let leftEdge = 0;
|
|
1987
|
-
if (left < 0) {
|
|
1988
|
-
leftEdge = -1;
|
|
1989
|
-
}
|
|
1990
|
-
else if (viewportWidth - left < 0) {
|
|
1991
|
-
leftEdge = 1;
|
|
1992
|
-
}
|
|
1993
|
-
let rightEdge = 0;
|
|
1994
|
-
if (right < 0) {
|
|
1995
|
-
rightEdge = -1;
|
|
1996
|
-
}
|
|
1997
|
-
else if (viewportWidth - right < 0) {
|
|
1998
|
-
rightEdge = 1;
|
|
1999
|
-
}
|
|
2000
|
-
let topEdge = 0;
|
|
2001
|
-
if (top < 0) {
|
|
2002
|
-
topEdge = -1;
|
|
2003
|
-
}
|
|
2004
|
-
else if (viewportHeight - top < 0) {
|
|
2005
|
-
topEdge = 1;
|
|
2006
|
-
}
|
|
2007
|
-
let bottomEdge = 0;
|
|
2008
|
-
if (bottom < 0) {
|
|
2009
|
-
bottomEdge = -1;
|
|
2010
|
-
}
|
|
2011
|
-
else if (viewportHeight - bottom < 0) {
|
|
2012
|
-
bottomEdge = 1;
|
|
2013
|
-
}
|
|
2014
|
-
return {
|
|
2015
|
-
left: leftEdge,
|
|
2016
|
-
right: rightEdge,
|
|
2017
|
-
top: topEdge,
|
|
2018
|
-
bottom: bottomEdge,
|
|
2019
|
-
};
|
|
2020
|
-
}
|
|
2021
|
-
|
|
2022
2267
|
const headingMenuItems = [
|
|
2023
2268
|
{
|
|
2024
2269
|
value: 'h1',
|
|
@@ -2213,7 +2458,7 @@ const moreStyleMenuItems = [
|
|
|
2213
2458
|
},
|
|
2214
2459
|
];
|
|
2215
2460
|
// These colors are sourced from Ant Design (https://ant.design/docs/spec/colors)
|
|
2216
|
-
const colors = [
|
|
2461
|
+
const colors$1 = [
|
|
2217
2462
|
// Dust Red, Volcano, Sunset Orange, Calendula Gold, Sunrise Yellow, Lime, Polar Green, Cyan, Daybreak Blue, Geek Blue, Golden Purple, Magenta
|
|
2218
2463
|
'#f5222d', '#fa541c', '#fa8c16', '#faad14', '#fadb14', '#a0d911', '#52c41a', '#13c2c2', '#1677ff', '#2f54eb', '#722ed1', '#eb2f96', // color 6
|
|
2219
2464
|
'#fff1f0', '#fff2e8', '#fff7e6', '#fffbe6', '#feffe6', '#fcffe6', '#f6ffed', '#e6fffb', '#e6f4ff', '#f0f5ff', '#f9f0ff', '#fff0f6', // color 1
|
|
@@ -2235,7 +2480,7 @@ const colorMenuItems = [
|
|
|
2235
2480
|
text: locale => locale.toolbar.removeColor(),
|
|
2236
2481
|
},
|
|
2237
2482
|
];
|
|
2238
|
-
for (const color of colors) {
|
|
2483
|
+
for (const color of colors$1) {
|
|
2239
2484
|
colorMenuItems.push({
|
|
2240
2485
|
value: color.toLowerCase(),
|
|
2241
2486
|
text: color.toUpperCase(),
|
|
@@ -2609,7 +2854,7 @@ const toolbarItems = [
|
|
|
2609
2854
|
const currentValues = [];
|
|
2610
2855
|
for (const item of activeItems) {
|
|
2611
2856
|
if (item.node.isMark) {
|
|
2612
|
-
const name = (_a = tagPluginNameMap.get(item.name)) !== null && _a !==
|
|
2857
|
+
const name = (_a = tagPluginNameMap.get(item.name)) !== null && _a !== void 0 ? _a : item.name;
|
|
2613
2858
|
currentValues.push(name);
|
|
2614
2859
|
}
|
|
2615
2860
|
}
|
|
@@ -2667,7 +2912,7 @@ const toolbarItems = [
|
|
|
2667
2912
|
},
|
|
2668
2913
|
];
|
|
2669
2914
|
|
|
2670
|
-
|
|
2915
|
+
/*
|
|
2671
2916
|
The MIT License (MIT)
|
|
2672
2917
|
|
|
2673
2918
|
Copyright (c) 2016-present react-component
|
|
@@ -2716,7 +2961,7 @@ function getBody(xhr) {
|
|
|
2716
2961
|
function request(option) {
|
|
2717
2962
|
const xhr = new XMLHttpRequest();
|
|
2718
2963
|
if (option.onProgress && xhr.upload) {
|
|
2719
|
-
xhr.upload.onprogress =
|
|
2964
|
+
xhr.upload.onprogress = e => {
|
|
2720
2965
|
if (e.total > 0) {
|
|
2721
2966
|
e.percent = (e.loaded / e.total) * 100;
|
|
2722
2967
|
}
|
|
@@ -2749,7 +2994,7 @@ function request(option) {
|
|
|
2749
2994
|
formData.append(filename, option.file);
|
|
2750
2995
|
}
|
|
2751
2996
|
}
|
|
2752
|
-
xhr.onerror =
|
|
2997
|
+
xhr.onerror = e => {
|
|
2753
2998
|
if (option.onError) {
|
|
2754
2999
|
option.onError(e);
|
|
2755
3000
|
}
|
|
@@ -2854,11 +3099,13 @@ function uploadFile(config) {
|
|
|
2854
3099
|
return box;
|
|
2855
3100
|
}
|
|
2856
3101
|
|
|
2857
|
-
|
|
3102
|
+
/**
|
|
3103
|
+
* The Button interface represents a clickable UI component. When a user clicks the button, a specified action is executed.
|
|
3104
|
+
*/
|
|
2858
3105
|
class Button {
|
|
2859
3106
|
constructor(config) {
|
|
2860
3107
|
this.config = config;
|
|
2861
|
-
this.root = config.root;
|
|
3108
|
+
this.root = query(config.root);
|
|
2862
3109
|
this.node = query(template `
|
|
2863
3110
|
<button type="button" name="${config.name}" class="lake-button" />
|
|
2864
3111
|
`);
|
|
@@ -2869,7 +3116,9 @@ class Button {
|
|
|
2869
3116
|
this.node.attr('tabindex', config.tabIndex.toString());
|
|
2870
3117
|
}
|
|
2871
3118
|
}
|
|
2872
|
-
|
|
3119
|
+
/**
|
|
3120
|
+
* Renders the button to the DOM.
|
|
3121
|
+
*/
|
|
2873
3122
|
render() {
|
|
2874
3123
|
const config = this.config;
|
|
2875
3124
|
const buttonNode = this.node;
|
|
@@ -2884,6 +3133,7 @@ class Button {
|
|
|
2884
3133
|
buttonNode.append(`<span>${config.text}</span>`);
|
|
2885
3134
|
}
|
|
2886
3135
|
this.root.append(buttonNode);
|
|
3136
|
+
this.root.get(0).appendChild(buttonNode.get(0));
|
|
2887
3137
|
buttonNode.on('mouseenter', () => {
|
|
2888
3138
|
if (buttonNode.attr('disabled')) {
|
|
2889
3139
|
return;
|
|
@@ -2914,10 +3164,10 @@ function unsafeTemplate(strings, ...keys) {
|
|
|
2914
3164
|
content += key;
|
|
2915
3165
|
content += strings[i + 1];
|
|
2916
3166
|
}
|
|
2917
|
-
content = content
|
|
2918
|
-
replace(/^\s+/gm, '')
|
|
2919
|
-
replace(/\s+$/gm, '')
|
|
2920
|
-
replace(/[\r\n]/g, '');
|
|
3167
|
+
content = content
|
|
3168
|
+
.replace(/^\s+/gm, '')
|
|
3169
|
+
.replace(/\s+$/gm, '')
|
|
3170
|
+
.replace(/[\r\n]/g, '');
|
|
2921
3171
|
return content;
|
|
2922
3172
|
}
|
|
2923
3173
|
|
|
@@ -2929,7 +3179,7 @@ function modifierText(value, userAgent) {
|
|
|
2929
3179
|
if (typeof window === 'undefined') {
|
|
2930
3180
|
return value;
|
|
2931
3181
|
}
|
|
2932
|
-
userAgent = userAgent !== null && userAgent !==
|
|
3182
|
+
userAgent = userAgent !== null && userAgent !== void 0 ? userAgent : navigator.userAgent;
|
|
2933
3183
|
const isMac = userAgent.indexOf('Mac OS X') >= 0;
|
|
2934
3184
|
const modText = isMac ? '⌘' : 'Ctrl';
|
|
2935
3185
|
return value.replace(/(^|\+|\s)mod(\+|\s|$)/g, `$1${modText}$2`);
|
|
@@ -3626,21 +3876,25 @@ const initFormatters = () => {
|
|
|
3626
3876
|
};
|
|
3627
3877
|
return formatters;
|
|
3628
3878
|
};
|
|
3629
|
-
|
|
3879
|
+
function loadFormatters(locale) {
|
|
3630
3880
|
loadedFormatters[locale] = initFormatters();
|
|
3631
|
-
}
|
|
3632
|
-
|
|
3881
|
+
}
|
|
3882
|
+
function loadLocale(locale) {
|
|
3633
3883
|
if (loadedLocales[locale]) {
|
|
3634
3884
|
return;
|
|
3635
3885
|
}
|
|
3636
3886
|
loadedLocales[locale] = localeTranslations[locale];
|
|
3637
3887
|
loadFormatters(locale);
|
|
3638
|
-
}
|
|
3888
|
+
}
|
|
3639
3889
|
const loadAllLocales = () => locales.forEach(loadLocale);
|
|
3640
|
-
|
|
3890
|
+
function i18nObject(locale) {
|
|
3891
|
+
return i18nObject$1(locale, loadedLocales[locale], loadedFormatters[locale]);
|
|
3892
|
+
}
|
|
3641
3893
|
loadAllLocales();
|
|
3642
3894
|
|
|
3643
|
-
|
|
3895
|
+
/**
|
|
3896
|
+
* The Dropdown component provides a user-friendly menu with selectable options. Use it to allow users to pick from a list of predefined choices.
|
|
3897
|
+
*/
|
|
3644
3898
|
class Dropdown {
|
|
3645
3899
|
constructor(config) {
|
|
3646
3900
|
this.clickListener = (event) => {
|
|
@@ -3654,7 +3908,7 @@ class Dropdown {
|
|
|
3654
3908
|
this.scrollListener = () => this.updatePosition();
|
|
3655
3909
|
this.resizeListener = () => this.updatePosition();
|
|
3656
3910
|
this.config = config;
|
|
3657
|
-
this.root = config.root;
|
|
3911
|
+
this.root = query(config.root);
|
|
3658
3912
|
this.locale = config.locale || i18nObject('en-US');
|
|
3659
3913
|
this.location = config.location || 'local';
|
|
3660
3914
|
this.direction = config.direction || 'auto';
|
|
@@ -3672,7 +3926,9 @@ class Dropdown {
|
|
|
3672
3926
|
titleNode.attr('tabindex', config.tabIndex.toString());
|
|
3673
3927
|
}
|
|
3674
3928
|
}
|
|
3675
|
-
|
|
3929
|
+
/**
|
|
3930
|
+
* Returns the value of the node.
|
|
3931
|
+
*/
|
|
3676
3932
|
static getValue(node) {
|
|
3677
3933
|
const value = node.attr('value');
|
|
3678
3934
|
if (value === '') {
|
|
@@ -3680,7 +3936,9 @@ class Dropdown {
|
|
|
3680
3936
|
}
|
|
3681
3937
|
return JSON.parse(fromBase64(value));
|
|
3682
3938
|
}
|
|
3683
|
-
|
|
3939
|
+
/**
|
|
3940
|
+
* Updates the value of the node.
|
|
3941
|
+
*/
|
|
3684
3942
|
static setValue(node, value) {
|
|
3685
3943
|
node.attr('value', toBase64(JSON.stringify(value)));
|
|
3686
3944
|
}
|
|
@@ -3865,11 +4123,13 @@ class Dropdown {
|
|
|
3865
4123
|
document.removeEventListener('click', this.clickListener);
|
|
3866
4124
|
window.removeEventListener('resize', this.resizeListener);
|
|
3867
4125
|
}
|
|
3868
|
-
|
|
4126
|
+
/**
|
|
4127
|
+
* Renders the dropdown to the DOM.
|
|
4128
|
+
*/
|
|
3869
4129
|
render() {
|
|
3870
4130
|
var _a, _b;
|
|
3871
4131
|
const config = this.config;
|
|
3872
|
-
const defaultValue = (_a = config.defaultValue) !== null && _a !==
|
|
4132
|
+
const defaultValue = (_a = config.defaultValue) !== null && _a !== void 0 ? _a : '';
|
|
3873
4133
|
const titleNode = this.node.find('.lake-dropdown-title');
|
|
3874
4134
|
if (!config.downIcon) {
|
|
3875
4135
|
titleNode.addClass('lake-dropdown-title-no-down');
|
|
@@ -3894,7 +4154,7 @@ class Dropdown {
|
|
|
3894
4154
|
Dropdown.setValue(this.node, [defaultValue]);
|
|
3895
4155
|
if (textNode.length > 0) {
|
|
3896
4156
|
const menuMap = Dropdown.getMenuMap(config.menuItems, this.locale);
|
|
3897
|
-
textNode.text((_b = menuMap.get(defaultValue)) !== null && _b !==
|
|
4157
|
+
textNode.text((_b = menuMap.get(defaultValue)) !== null && _b !== void 0 ? _b : defaultValue);
|
|
3898
4158
|
}
|
|
3899
4159
|
if (config.menuType === 'color') {
|
|
3900
4160
|
this.updateColorAccent(titleNode, defaultValue);
|
|
@@ -3948,7 +4208,9 @@ class Dropdown {
|
|
|
3948
4208
|
this.showMenu();
|
|
3949
4209
|
});
|
|
3950
4210
|
}
|
|
3951
|
-
|
|
4211
|
+
/**
|
|
4212
|
+
* Removes the dropdown from the DOM and cleans up resources.
|
|
4213
|
+
*/
|
|
3952
4214
|
unmount() {
|
|
3953
4215
|
this.hideMenu();
|
|
3954
4216
|
this.menuNode.remove();
|
|
@@ -3981,7 +4243,9 @@ const toolbarItemMap = new Map();
|
|
|
3981
4243
|
for (const item of toolbarItems) {
|
|
3982
4244
|
toolbarItemMap.set(item.name, item);
|
|
3983
4245
|
}
|
|
3984
|
-
|
|
4246
|
+
/**
|
|
4247
|
+
* The Toolbar interface provides properties and methods for rendering and manipulating the toolbar.
|
|
4248
|
+
*/
|
|
3985
4249
|
class Toolbar {
|
|
3986
4250
|
constructor(config) {
|
|
3987
4251
|
this.placement = 'top';
|
|
@@ -4087,7 +4351,9 @@ class Toolbar {
|
|
|
4087
4351
|
}
|
|
4088
4352
|
});
|
|
4089
4353
|
}
|
|
4090
|
-
|
|
4354
|
+
/**
|
|
4355
|
+
* Updates the state of each toolbar item, such as whether it is selected or disabled.
|
|
4356
|
+
*/
|
|
4091
4357
|
updateState(state = {
|
|
4092
4358
|
activeItems: [],
|
|
4093
4359
|
}) {
|
|
@@ -4148,13 +4414,15 @@ class Toolbar {
|
|
|
4148
4414
|
if (textNode.length > 0) {
|
|
4149
4415
|
const key = selectedValues[0] || item.defaultValue || '';
|
|
4150
4416
|
const menuMap = this.allMenuMap.get(item.name);
|
|
4151
|
-
const text = (_a = (menuMap && menuMap.get(key))) !== null && _a !==
|
|
4417
|
+
const text = (_a = (menuMap && menuMap.get(key))) !== null && _a !== void 0 ? _a : key;
|
|
4152
4418
|
textNode.text(text);
|
|
4153
4419
|
}
|
|
4154
4420
|
}
|
|
4155
4421
|
}
|
|
4156
4422
|
}
|
|
4157
|
-
|
|
4423
|
+
/**
|
|
4424
|
+
* Renders the toolbar for the specified editor.
|
|
4425
|
+
*/
|
|
4158
4426
|
render(editor) {
|
|
4159
4427
|
this.root.append(this.container);
|
|
4160
4428
|
for (const name of this.items) {
|
|
@@ -4187,7 +4455,9 @@ class Toolbar {
|
|
|
4187
4455
|
}
|
|
4188
4456
|
}
|
|
4189
4457
|
}
|
|
4190
|
-
|
|
4458
|
+
/**
|
|
4459
|
+
* Destroys the toolbar instance, removing it from the DOM.
|
|
4460
|
+
*/
|
|
4191
4461
|
unmount() {
|
|
4192
4462
|
for (const dropdown of this.dropdownList) {
|
|
4193
4463
|
dropdown.unmount();
|
|
@@ -4216,8 +4486,8 @@ class FloatingToolbar extends Toolbar {
|
|
|
4216
4486
|
}
|
|
4217
4487
|
updatePosition() {
|
|
4218
4488
|
const visible = visibleInfo(this.range);
|
|
4219
|
-
if ((visible.top === -1 && visible.bottom === -1)
|
|
4220
|
-
(visible.top === 1 && visible.bottom === 1)) {
|
|
4489
|
+
if ((visible.top === -1 && visible.bottom === -1)
|
|
4490
|
+
|| (visible.top === 1 && visible.bottom === 1)) {
|
|
4221
4491
|
this.container.css('visibility', 'hidden');
|
|
4222
4492
|
return;
|
|
4223
4493
|
}
|
|
@@ -4293,12 +4563,18 @@ class FloatingToolbar extends Toolbar {
|
|
|
4293
4563
|
}
|
|
4294
4564
|
}
|
|
4295
4565
|
|
|
4296
|
-
|
|
4566
|
+
/**
|
|
4567
|
+
* The Box interface represents an embedded content designed to enhance editing capability.
|
|
4568
|
+
*/
|
|
4297
4569
|
class Box {
|
|
4298
4570
|
constructor(node) {
|
|
4299
|
-
|
|
4571
|
+
/**
|
|
4572
|
+
* An EventEmitter object for handling events. See the Instance events for details.
|
|
4573
|
+
*/
|
|
4300
4574
|
this.event = new EventEmitter();
|
|
4301
|
-
|
|
4575
|
+
/**
|
|
4576
|
+
* A floating toolbar attached to the box.
|
|
4577
|
+
*/
|
|
4302
4578
|
this.toolbar = null;
|
|
4303
4579
|
if (typeof node === 'string') {
|
|
4304
4580
|
const component = boxes.get(node);
|
|
@@ -4339,9 +4615,9 @@ class Box {
|
|
|
4339
4615
|
container.off('click');
|
|
4340
4616
|
}
|
|
4341
4617
|
container.on('mouseenter', () => {
|
|
4342
|
-
if (container.hasClass('lake-box-selected')
|
|
4343
|
-
container.hasClass('lake-box-focused')
|
|
4344
|
-
container.hasClass('lake-box-activated')) {
|
|
4618
|
+
if (container.hasClass('lake-box-selected')
|
|
4619
|
+
|| container.hasClass('lake-box-focused')
|
|
4620
|
+
|| container.hasClass('lake-box-activated')) {
|
|
4345
4621
|
return;
|
|
4346
4622
|
}
|
|
4347
4623
|
container.addClass('lake-box-hovered');
|
|
@@ -4357,15 +4633,21 @@ class Box {
|
|
|
4357
4633
|
container.attr('draggable', 'true');
|
|
4358
4634
|
}
|
|
4359
4635
|
}
|
|
4360
|
-
|
|
4636
|
+
/**
|
|
4637
|
+
* Indicates the type of the box.
|
|
4638
|
+
*/
|
|
4361
4639
|
get type() {
|
|
4362
4640
|
return this.node.attr('type');
|
|
4363
4641
|
}
|
|
4364
|
-
|
|
4642
|
+
/**
|
|
4643
|
+
* Returns the name of the box.
|
|
4644
|
+
*/
|
|
4365
4645
|
get name() {
|
|
4366
4646
|
return this.node.attr('name');
|
|
4367
4647
|
}
|
|
4368
|
-
|
|
4648
|
+
/**
|
|
4649
|
+
* Gets or sets the value of the box.
|
|
4650
|
+
*/
|
|
4369
4651
|
get value() {
|
|
4370
4652
|
const value = this.node.attr('value');
|
|
4371
4653
|
if (value === '') {
|
|
@@ -4373,7 +4655,6 @@ class Box {
|
|
|
4373
4655
|
}
|
|
4374
4656
|
return JSON.parse(fromBase64(value));
|
|
4375
4657
|
}
|
|
4376
|
-
// Sets the value of the box.
|
|
4377
4658
|
set value(value) {
|
|
4378
4659
|
this.node.attr('value', toBase64(JSON.stringify(value)));
|
|
4379
4660
|
}
|
|
@@ -4389,7 +4670,9 @@ class Box {
|
|
|
4389
4670
|
}
|
|
4390
4671
|
this.value = value;
|
|
4391
4672
|
}
|
|
4392
|
-
|
|
4673
|
+
/**
|
|
4674
|
+
* Returns the Editor object that contains the box.
|
|
4675
|
+
*/
|
|
4393
4676
|
getEditor() {
|
|
4394
4677
|
const container = this.node.closest('div[contenteditable]');
|
|
4395
4678
|
const editor = container.length > 0 ? editors.get(container.id) : undefined;
|
|
@@ -4398,11 +4681,15 @@ class Box {
|
|
|
4398
4681
|
}
|
|
4399
4682
|
return editor;
|
|
4400
4683
|
}
|
|
4401
|
-
|
|
4684
|
+
/**
|
|
4685
|
+
* Returns the container element of the box.
|
|
4686
|
+
*/
|
|
4402
4687
|
getContainer() {
|
|
4403
4688
|
return this.node.find('.lake-box-container');
|
|
4404
4689
|
}
|
|
4405
|
-
|
|
4690
|
+
/**
|
|
4691
|
+
* Returns the HTML content inside the box.
|
|
4692
|
+
*/
|
|
4406
4693
|
getHTML() {
|
|
4407
4694
|
const component = boxes.get(this.name);
|
|
4408
4695
|
if (component === undefined) {
|
|
@@ -4413,7 +4700,9 @@ class Box {
|
|
|
4413
4700
|
}
|
|
4414
4701
|
return component.html(this);
|
|
4415
4702
|
}
|
|
4416
|
-
|
|
4703
|
+
/**
|
|
4704
|
+
* Adds a floating toolbar to the box.
|
|
4705
|
+
*/
|
|
4417
4706
|
setToolbar(items) {
|
|
4418
4707
|
const editor = this.getEditor();
|
|
4419
4708
|
this.event.on('focus', () => {
|
|
@@ -4438,7 +4727,9 @@ class Box {
|
|
|
4438
4727
|
}
|
|
4439
4728
|
});
|
|
4440
4729
|
}
|
|
4441
|
-
|
|
4730
|
+
/**
|
|
4731
|
+
* Renders the content inside the box.
|
|
4732
|
+
*/
|
|
4442
4733
|
render() {
|
|
4443
4734
|
const component = boxes.get(this.name);
|
|
4444
4735
|
if (component === undefined) {
|
|
@@ -4455,7 +4746,9 @@ class Box {
|
|
|
4455
4746
|
}
|
|
4456
4747
|
debug(`Box "${this.name}" (id: ${this.node.id}) rendered`);
|
|
4457
4748
|
}
|
|
4458
|
-
|
|
4749
|
+
/**
|
|
4750
|
+
* Destroys the box instance.
|
|
4751
|
+
*/
|
|
4459
4752
|
unmount() {
|
|
4460
4753
|
this.event.emit('blur');
|
|
4461
4754
|
this.event.emit('beforeunmount');
|
|
@@ -4465,9 +4758,94 @@ class Box {
|
|
|
4465
4758
|
}
|
|
4466
4759
|
}
|
|
4467
4760
|
|
|
4761
|
+
/**
|
|
4762
|
+
* Returns an existing Box instance associated with the provided boxNode or generates a new one if none exists.
|
|
4763
|
+
* The function handles the creation and storage of Box instances, storing them either in a temporary or
|
|
4764
|
+
* permanentmap based on whether the boxNode is contained within a container.
|
|
4765
|
+
*/
|
|
4766
|
+
function getBox(boxNode) {
|
|
4767
|
+
const tempInstanceMap = getInstanceMap(0);
|
|
4768
|
+
// boxNode is a name
|
|
4769
|
+
if (typeof boxNode === 'string') {
|
|
4770
|
+
const box = new Box(boxNode);
|
|
4771
|
+
tempInstanceMap.set(box.node.id, box);
|
|
4772
|
+
return box;
|
|
4773
|
+
}
|
|
4774
|
+
// boxNode is a node
|
|
4775
|
+
boxNode = query(boxNode);
|
|
4776
|
+
const container = boxNode.closestContainer();
|
|
4777
|
+
if (container.length === 0) {
|
|
4778
|
+
let box = tempInstanceMap.get(boxNode.id);
|
|
4779
|
+
if (box) {
|
|
4780
|
+
return box;
|
|
4781
|
+
}
|
|
4782
|
+
box = new Box(boxNode);
|
|
4783
|
+
tempInstanceMap.set(boxNode.id, box);
|
|
4784
|
+
return box;
|
|
4785
|
+
}
|
|
4786
|
+
const instanceMap = getInstanceMap(container.id);
|
|
4787
|
+
let box = tempInstanceMap.get(boxNode.id);
|
|
4788
|
+
if (box) {
|
|
4789
|
+
// move the box instance from temporary map to permanent map
|
|
4790
|
+
instanceMap.set(boxNode.id, box);
|
|
4791
|
+
tempInstanceMap.delete(boxNode.id);
|
|
4792
|
+
return box;
|
|
4793
|
+
}
|
|
4794
|
+
box = instanceMap.get(boxNode.id);
|
|
4795
|
+
if (box) {
|
|
4796
|
+
return box;
|
|
4797
|
+
}
|
|
4798
|
+
box = new Box(boxNode);
|
|
4799
|
+
instanceMap.set(boxNode.id, box);
|
|
4800
|
+
return box;
|
|
4801
|
+
}
|
|
4802
|
+
|
|
4803
|
+
/**
|
|
4804
|
+
* The Fragment interface represents a lightweight document object that has no parent.
|
|
4805
|
+
* It is designed for efficient manipulation of document structures without affecting the main DOM.
|
|
4806
|
+
*/
|
|
4807
|
+
class Fragment {
|
|
4808
|
+
constructor(fragment) {
|
|
4809
|
+
this.fragment = fragment !== null && fragment !== void 0 ? fragment : document.createDocumentFragment();
|
|
4810
|
+
}
|
|
4811
|
+
/**
|
|
4812
|
+
* Returns a native DocumentFragment object from the fragment.
|
|
4813
|
+
*/
|
|
4814
|
+
get() {
|
|
4815
|
+
return this.fragment;
|
|
4816
|
+
}
|
|
4817
|
+
/**
|
|
4818
|
+
* Finds and returns descendants of the fragment that match the specified CSS selector.
|
|
4819
|
+
*/
|
|
4820
|
+
find(selector) {
|
|
4821
|
+
const nodeList = [];
|
|
4822
|
+
let child = new Nodes(this.fragment.firstChild);
|
|
4823
|
+
while (child.length > 0) {
|
|
4824
|
+
if (child.matches(selector)) {
|
|
4825
|
+
nodeList.push(child.get(0));
|
|
4826
|
+
}
|
|
4827
|
+
else if (child.isElement) {
|
|
4828
|
+
child.find(selector).each(node => {
|
|
4829
|
+
nodeList.push(node);
|
|
4830
|
+
});
|
|
4831
|
+
}
|
|
4832
|
+
child = child.next();
|
|
4833
|
+
}
|
|
4834
|
+
return new Nodes(nodeList);
|
|
4835
|
+
}
|
|
4836
|
+
/**
|
|
4837
|
+
* Inserts the specified content just inside the fragment, after its last child.
|
|
4838
|
+
*/
|
|
4839
|
+
append(content) {
|
|
4840
|
+
query(content).each(nativeNode => {
|
|
4841
|
+
this.fragment.appendChild(nativeNode);
|
|
4842
|
+
});
|
|
4843
|
+
}
|
|
4844
|
+
}
|
|
4845
|
+
|
|
4468
4846
|
const blockAttributeRules = {
|
|
4469
4847
|
id: /^[\w-]+$/,
|
|
4470
|
-
class: /^[\w
|
|
4848
|
+
class: /^[\w\- ]+$/,
|
|
4471
4849
|
style: {
|
|
4472
4850
|
'text-align': ['left', 'center', 'right', 'justify', 'start', 'end'],
|
|
4473
4851
|
'margin-left': /^-?\d+px$/i,
|
|
@@ -4540,7 +4918,7 @@ function getElementRules() {
|
|
|
4540
4918
|
},
|
|
4541
4919
|
},
|
|
4542
4920
|
span: {
|
|
4543
|
-
class: /^[\w
|
|
4921
|
+
class: /^[\w\- ]+$/,
|
|
4544
4922
|
style: {
|
|
4545
4923
|
color: /^[^"]+$/,
|
|
4546
4924
|
'background-color': /^[^"]+$/,
|
|
@@ -4558,7 +4936,7 @@ function getElementRules() {
|
|
|
4558
4936
|
sup: {},
|
|
4559
4937
|
code: {},
|
|
4560
4938
|
a: {
|
|
4561
|
-
class: /^[\w
|
|
4939
|
+
class: /^[\w\- ]+$/,
|
|
4562
4940
|
name: /^[\w-]+$/,
|
|
4563
4941
|
href: /^[^"]+$/,
|
|
4564
4942
|
target: /^[\w-]+$/,
|
|
@@ -4573,9 +4951,9 @@ function getElementRules() {
|
|
|
4573
4951
|
|
|
4574
4952
|
// Converts a string from style property of element to a key-value object that contains a list of all styles properties.
|
|
4575
4953
|
function parseStyle(styleValue) {
|
|
4576
|
-
styleValue = styleValue.replace(/"/
|
|
4954
|
+
styleValue = styleValue.replace(/"/gi, '"');
|
|
4577
4955
|
const properties = {};
|
|
4578
|
-
const re = /\s*([\w-]+)\s*:([^;]*)(
|
|
4956
|
+
const re = /\s*([\w-]+)\s*:([^;]*)(?:;|$)/g;
|
|
4579
4957
|
let result;
|
|
4580
4958
|
while ((result = re.exec(styleValue)) !== null) {
|
|
4581
4959
|
const key = result[1].toLowerCase().trim();
|
|
@@ -4585,7 +4963,9 @@ function parseStyle(styleValue) {
|
|
|
4585
4963
|
return properties;
|
|
4586
4964
|
}
|
|
4587
4965
|
|
|
4588
|
-
|
|
4966
|
+
/**
|
|
4967
|
+
* The HTMLParser interface provides the ability to parse an HTML string according to specified rules.
|
|
4968
|
+
*/
|
|
4589
4969
|
class HTMLParser {
|
|
4590
4970
|
constructor(content, rules = getElementRules()) {
|
|
4591
4971
|
this.rules = rules;
|
|
@@ -4596,13 +4976,17 @@ class HTMLParser {
|
|
|
4596
4976
|
this.source = content;
|
|
4597
4977
|
}
|
|
4598
4978
|
}
|
|
4599
|
-
|
|
4979
|
+
/**
|
|
4980
|
+
* Parses the given HTML string and returns the body element from the result.
|
|
4981
|
+
*/
|
|
4600
4982
|
parseHTML(html) {
|
|
4601
4983
|
const parser = new DOMParser();
|
|
4602
4984
|
const doc = parser.parseFromString(html, 'text/html');
|
|
4603
4985
|
return new Nodes(doc.querySelector('body'));
|
|
4604
4986
|
}
|
|
4605
|
-
|
|
4987
|
+
/**
|
|
4988
|
+
* Returns a boolean value indicating whether the given value matches the given rule.
|
|
4989
|
+
*/
|
|
4606
4990
|
static matchRule(rule, value) {
|
|
4607
4991
|
if (typeof rule === 'string') {
|
|
4608
4992
|
return rule === value;
|
|
@@ -4615,7 +4999,9 @@ class HTMLParser {
|
|
|
4615
4999
|
}
|
|
4616
5000
|
return false;
|
|
4617
5001
|
}
|
|
4618
|
-
|
|
5002
|
+
/**
|
|
5003
|
+
* Returns an open tag string from the specified element.
|
|
5004
|
+
*/
|
|
4619
5005
|
static getOpenTagString(element, rules) {
|
|
4620
5006
|
let tagName = element.name;
|
|
4621
5007
|
let attributeRules = rules[tagName];
|
|
@@ -4667,7 +5053,9 @@ class HTMLParser {
|
|
|
4667
5053
|
}
|
|
4668
5054
|
return openTag;
|
|
4669
5055
|
}
|
|
4670
|
-
|
|
5056
|
+
/**
|
|
5057
|
+
* Returns a closed tag string from the specified element.
|
|
5058
|
+
*/
|
|
4671
5059
|
static getClosedTagString(element, rules) {
|
|
4672
5060
|
let tagName = element.name;
|
|
4673
5061
|
const attributeRules = rules[tagName];
|
|
@@ -4679,7 +5067,9 @@ class HTMLParser {
|
|
|
4679
5067
|
}
|
|
4680
5068
|
return tagName;
|
|
4681
5069
|
}
|
|
4682
|
-
|
|
5070
|
+
/**
|
|
5071
|
+
* Returns the value of the text node with trimming invisible whitespace.
|
|
5072
|
+
*/
|
|
4683
5073
|
// <p>foo</p>\n<p>bar</p>
|
|
4684
5074
|
// or
|
|
4685
5075
|
// <p>\nfoo\n</p>
|
|
@@ -4688,22 +5078,23 @@ class HTMLParser {
|
|
|
4688
5078
|
const prevSibling = textNode.prev();
|
|
4689
5079
|
const nextSibling = textNode.next();
|
|
4690
5080
|
let nodeValue = textNode.text();
|
|
4691
|
-
if ((prevSibling.isBlock || prevSibling.isBlockBox) &&
|
|
4692
|
-
(
|
|
4693
|
-
prevSibling.length === 0 && nextSibling.length === 0 && parentNode.isBlock) {
|
|
5081
|
+
if (((prevSibling.isBlock || prevSibling.isBlockBox) && (nextSibling.isBlock || nextSibling.isBlockBox))
|
|
5082
|
+
|| (prevSibling.length === 0 && nextSibling.length === 0 && parentNode.isBlock)) {
|
|
4694
5083
|
nodeValue = nodeValue.replace(/^[\u0020\t\r\n]+|[\u0020\t\r\n]+$/g, '');
|
|
4695
5084
|
}
|
|
4696
|
-
else if ((prevSibling.isBlock || prevSibling.isBlockBox)
|
|
4697
|
-
prevSibling.length === 0 && parentNode.isBlock) {
|
|
5085
|
+
else if ((prevSibling.isBlock || prevSibling.isBlockBox)
|
|
5086
|
+
|| (prevSibling.length === 0 && parentNode.isBlock)) {
|
|
4698
5087
|
nodeValue = nodeValue.replace(/^[\u0020\t\r\n]+/, '');
|
|
4699
5088
|
}
|
|
4700
|
-
else if ((nextSibling.isBlock || nextSibling.isBlockBox)
|
|
4701
|
-
nextSibling.length === 0 && parentNode.isBlock) {
|
|
5089
|
+
else if ((nextSibling.isBlock || nextSibling.isBlockBox)
|
|
5090
|
+
|| (nextSibling.length === 0 && parentNode.isBlock)) {
|
|
4702
5091
|
nodeValue = nodeValue.replace(/[\u0020\t\r\n]+$/, '');
|
|
4703
5092
|
}
|
|
4704
5093
|
return nodeValue;
|
|
4705
5094
|
}
|
|
4706
|
-
|
|
5095
|
+
/**
|
|
5096
|
+
* Returns the parsed HTML as a string.
|
|
5097
|
+
*/
|
|
4707
5098
|
getHTML() {
|
|
4708
5099
|
const rules = this.rules;
|
|
4709
5100
|
function* iterate(node) {
|
|
@@ -4741,7 +5132,9 @@ class HTMLParser {
|
|
|
4741
5132
|
}
|
|
4742
5133
|
return html.trim();
|
|
4743
5134
|
}
|
|
4744
|
-
|
|
5135
|
+
/**
|
|
5136
|
+
* Returns the parsed content as a DocumentFragment object.
|
|
5137
|
+
*/
|
|
4745
5138
|
getFragment() {
|
|
4746
5139
|
const html = this.getHTML();
|
|
4747
5140
|
const body = this.parseHTML(html);
|
|
@@ -4756,12 +5149,16 @@ class HTMLParser {
|
|
|
4756
5149
|
}
|
|
4757
5150
|
}
|
|
4758
5151
|
|
|
4759
|
-
|
|
5152
|
+
/**
|
|
5153
|
+
* The TextParser interface enables parsing of text into structured HTML.
|
|
5154
|
+
*/
|
|
4760
5155
|
class TextParser {
|
|
4761
5156
|
constructor(content) {
|
|
4762
5157
|
this.content = content;
|
|
4763
5158
|
}
|
|
4764
|
-
|
|
5159
|
+
/**
|
|
5160
|
+
* Converts the parsed text into an HTML string.
|
|
5161
|
+
*/
|
|
4765
5162
|
getHTML() {
|
|
4766
5163
|
let html = this.content;
|
|
4767
5164
|
html = html.replace(/ {2}/g, ' \xA0');
|
|
@@ -4773,7 +5170,9 @@ class TextParser {
|
|
|
4773
5170
|
html = html.replace(/[\r\n]/g, '</p><p>');
|
|
4774
5171
|
return html;
|
|
4775
5172
|
}
|
|
4776
|
-
|
|
5173
|
+
/**
|
|
5174
|
+
* Generates a DocumentFragment object that represents the parsed text.
|
|
5175
|
+
*/
|
|
4777
5176
|
getFragment() {
|
|
4778
5177
|
const htmlParser = new HTMLParser(this.getHTML());
|
|
4779
5178
|
return htmlParser.getFragment();
|
|
@@ -4787,7 +5186,9 @@ function insertNode(range, node) {
|
|
|
4787
5186
|
nativeRange.setEndAfter(nativeNode);
|
|
4788
5187
|
nativeRange.collapse(false);
|
|
4789
5188
|
}
|
|
4790
|
-
|
|
5189
|
+
/**
|
|
5190
|
+
* Inserts a bookmark at the cursor position or a pair of bookmarks at the beginning and end of the range.
|
|
5191
|
+
*/
|
|
4791
5192
|
// case 1: foo<lake-bookmark type="focus" />bar
|
|
4792
5193
|
// case 2: <lake-bookmark type="anchor" />foo<lake-bookmark type="focus" />
|
|
4793
5194
|
// case 3: foo<lake-box type="inline" name="image" focus="start"></lake-box>bar
|
|
@@ -4843,55 +5244,6 @@ function insertBookmark(range) {
|
|
|
4843
5244
|
};
|
|
4844
5245
|
}
|
|
4845
5246
|
|
|
4846
|
-
const boxInstances = new Map();
|
|
4847
|
-
function getInstanceMap(id) {
|
|
4848
|
-
let instanceMap = boxInstances.get(id);
|
|
4849
|
-
if (!instanceMap) {
|
|
4850
|
-
instanceMap = new Map();
|
|
4851
|
-
boxInstances.set(id, instanceMap);
|
|
4852
|
-
return instanceMap;
|
|
4853
|
-
}
|
|
4854
|
-
return instanceMap;
|
|
4855
|
-
}
|
|
4856
|
-
|
|
4857
|
-
// Returns an already generated box instance or generates a new instance if it does not exist.
|
|
4858
|
-
function getBox(boxNode) {
|
|
4859
|
-
const tempInstanceMap = getInstanceMap(0);
|
|
4860
|
-
// boxNode is a name
|
|
4861
|
-
if (typeof boxNode === 'string') {
|
|
4862
|
-
const box = new Box(boxNode);
|
|
4863
|
-
tempInstanceMap.set(box.node.id, box);
|
|
4864
|
-
return box;
|
|
4865
|
-
}
|
|
4866
|
-
// boxNode is node
|
|
4867
|
-
boxNode = query(boxNode);
|
|
4868
|
-
const container = boxNode.closestContainer();
|
|
4869
|
-
if (container.length === 0) {
|
|
4870
|
-
let box = tempInstanceMap.get(boxNode.id);
|
|
4871
|
-
if (box) {
|
|
4872
|
-
return box;
|
|
4873
|
-
}
|
|
4874
|
-
box = new Box(boxNode);
|
|
4875
|
-
tempInstanceMap.set(boxNode.id, box);
|
|
4876
|
-
return box;
|
|
4877
|
-
}
|
|
4878
|
-
const instanceMap = getInstanceMap(container.id);
|
|
4879
|
-
let box = tempInstanceMap.get(boxNode.id);
|
|
4880
|
-
if (box) {
|
|
4881
|
-
// move the box instance from temporary map to permanent map
|
|
4882
|
-
instanceMap.set(boxNode.id, box);
|
|
4883
|
-
tempInstanceMap.delete(boxNode.id);
|
|
4884
|
-
return box;
|
|
4885
|
-
}
|
|
4886
|
-
box = instanceMap.get(boxNode.id);
|
|
4887
|
-
if (box) {
|
|
4888
|
-
return box;
|
|
4889
|
-
}
|
|
4890
|
-
box = new Box(boxNode);
|
|
4891
|
-
instanceMap.set(boxNode.id, box);
|
|
4892
|
-
return box;
|
|
4893
|
-
}
|
|
4894
|
-
|
|
4895
5247
|
function removeAndNormalizeNode(node, range) {
|
|
4896
5248
|
const previousNode = node.prev();
|
|
4897
5249
|
const nextNode = node.next();
|
|
@@ -4913,7 +5265,9 @@ function removeAndNormalizeNode(node, range) {
|
|
|
4913
5265
|
node.remove();
|
|
4914
5266
|
}
|
|
4915
5267
|
}
|
|
4916
|
-
|
|
5268
|
+
/**
|
|
5269
|
+
* Changes the specified range to a range represented by the provided bookmark.
|
|
5270
|
+
*/
|
|
4917
5271
|
function toBookmark(range, bookmark) {
|
|
4918
5272
|
const anchor = bookmark.anchor;
|
|
4919
5273
|
const focus = bookmark.focus;
|
|
@@ -4984,8 +5338,8 @@ function removeBreak(block) {
|
|
|
4984
5338
|
}
|
|
4985
5339
|
child = nextNode;
|
|
4986
5340
|
}
|
|
4987
|
-
if (nodeList.length === 1 && nodeList[0].name === 'br'
|
|
4988
|
-
nodeList.length === 2 && nodeList[0].name === 'br' && nodeList[1].isBookmark) {
|
|
5341
|
+
if ((nodeList.length === 1 && nodeList[0].name === 'br')
|
|
5342
|
+
|| (nodeList.length === 2 && nodeList[0].name === 'br' && nodeList[1].isBookmark)) {
|
|
4989
5343
|
nodeList[0].remove();
|
|
4990
5344
|
}
|
|
4991
5345
|
if (nodeList.length === 2 && nodeList[0].isBookmark && nodeList[1].name === 'br') {
|
|
@@ -5071,11 +5425,11 @@ function mergeNodes(node, otherNode) {
|
|
|
5071
5425
|
child = next;
|
|
5072
5426
|
}
|
|
5073
5427
|
originalOtherNode.remove();
|
|
5074
|
-
if (nextNode.length > 0
|
|
5075
|
-
nextOtherNode.length > 0
|
|
5076
|
-
nextNode.isElement
|
|
5077
|
-
!nextNode.isBox
|
|
5078
|
-
nextNode.clone(false).get(0).isEqualNode(nextOtherNode.clone(false).get(0))) {
|
|
5428
|
+
if (nextNode.length > 0
|
|
5429
|
+
&& nextOtherNode.length > 0
|
|
5430
|
+
&& nextNode.isElement
|
|
5431
|
+
&& !nextNode.isBox
|
|
5432
|
+
&& nextNode.clone(false).get(0).isEqualNode(nextOtherNode.clone(false).get(0))) {
|
|
5079
5433
|
return mergeNodes(nextNode, nextOtherNode);
|
|
5080
5434
|
}
|
|
5081
5435
|
if (nextNode.length === 0) {
|
|
@@ -5136,7 +5490,9 @@ function fixNumberedList(blocks) {
|
|
|
5136
5490
|
}
|
|
5137
5491
|
}
|
|
5138
5492
|
|
|
5139
|
-
|
|
5493
|
+
/**
|
|
5494
|
+
* Removes the contents of the specified range.
|
|
5495
|
+
*/
|
|
5140
5496
|
function deleteContents(range) {
|
|
5141
5497
|
if (range.isCollapsed) {
|
|
5142
5498
|
return;
|
|
@@ -5175,7 +5531,9 @@ function deleteContents(range) {
|
|
|
5175
5531
|
toBookmark(range, bookmark);
|
|
5176
5532
|
}
|
|
5177
5533
|
|
|
5178
|
-
|
|
5534
|
+
/**
|
|
5535
|
+
* Inserts the specified contents into the range.
|
|
5536
|
+
*/
|
|
5179
5537
|
function insertContents(range, contents) {
|
|
5180
5538
|
if (range.commonAncestor.isOutside) {
|
|
5181
5539
|
return;
|
|
@@ -5223,7 +5581,7 @@ function getDeepElement(element) {
|
|
|
5223
5581
|
|
|
5224
5582
|
// Appends a list of nodes to the specified element.
|
|
5225
5583
|
function wrapNodeList(nodeList, wrapper) {
|
|
5226
|
-
wrapper = wrapper !== null && wrapper !==
|
|
5584
|
+
wrapper = wrapper !== null && wrapper !== void 0 ? wrapper : query('<p />');
|
|
5227
5585
|
if (nodeList.length === 0) {
|
|
5228
5586
|
return wrapper;
|
|
5229
5587
|
}
|
|
@@ -5261,7 +5619,9 @@ function getTopNonBlockNodes(range) {
|
|
|
5261
5619
|
}
|
|
5262
5620
|
return nodeList;
|
|
5263
5621
|
}
|
|
5264
|
-
|
|
5622
|
+
/**
|
|
5623
|
+
* Adds new blocks or changes the target blocks in the specified range.
|
|
5624
|
+
*/
|
|
5265
5625
|
function setBlocks(range, value) {
|
|
5266
5626
|
if (range.commonAncestor.isOutside) {
|
|
5267
5627
|
return;
|
|
@@ -5414,7 +5774,9 @@ function removeEmptyMarks(node) {
|
|
|
5414
5774
|
}
|
|
5415
5775
|
}
|
|
5416
5776
|
|
|
5417
|
-
|
|
5777
|
+
/**
|
|
5778
|
+
* Removes the contents of the specified range and then splits the block node at the point of the collapsed range.
|
|
5779
|
+
*/
|
|
5418
5780
|
// <p>one<anchor />two<focus />three</p>
|
|
5419
5781
|
// to
|
|
5420
5782
|
// <p>one</p>
|
|
@@ -5478,7 +5840,9 @@ function splitBlock$1(range) {
|
|
|
5478
5840
|
};
|
|
5479
5841
|
}
|
|
5480
5842
|
|
|
5481
|
-
|
|
5843
|
+
/**
|
|
5844
|
+
* Inserts a block into the specified range.
|
|
5845
|
+
*/
|
|
5482
5846
|
function insertBlock(range, value) {
|
|
5483
5847
|
if (range.commonAncestor.isOutside) {
|
|
5484
5848
|
return null;
|
|
@@ -5506,7 +5870,9 @@ function insertBlock(range, value) {
|
|
|
5506
5870
|
return block;
|
|
5507
5871
|
}
|
|
5508
5872
|
|
|
5509
|
-
|
|
5873
|
+
/**
|
|
5874
|
+
* Splits text nodes or mark nodes.
|
|
5875
|
+
*/
|
|
5510
5876
|
function splitMarksAtPoint(node, offset, removeEmptyMark) {
|
|
5511
5877
|
let start = null;
|
|
5512
5878
|
let end = null;
|
|
@@ -5586,7 +5952,9 @@ function splitMarks(range, removeEmptyMark = true) {
|
|
|
5586
5952
|
};
|
|
5587
5953
|
}
|
|
5588
5954
|
|
|
5589
|
-
|
|
5955
|
+
/**
|
|
5956
|
+
* Removes zero-width space at the beginning or end of the specified node.
|
|
5957
|
+
*/
|
|
5590
5958
|
function removePreviousOrNextZWS(node) {
|
|
5591
5959
|
const prevNode = node.prev();
|
|
5592
5960
|
if (prevNode.length > 0 && prevNode.isText && prevNode.isEmpty) {
|
|
@@ -5597,7 +5965,9 @@ function removePreviousOrNextZWS(node) {
|
|
|
5597
5965
|
nextNode.remove();
|
|
5598
5966
|
}
|
|
5599
5967
|
}
|
|
5600
|
-
|
|
5968
|
+
/**
|
|
5969
|
+
* Returns a nested mark copied from ancestors of the specified node.
|
|
5970
|
+
*/
|
|
5601
5971
|
function getNestedMark$1(node) {
|
|
5602
5972
|
let parent = node;
|
|
5603
5973
|
if (parent.isText) {
|
|
@@ -5620,22 +5990,26 @@ function getNestedMark$1(node) {
|
|
|
5620
5990
|
}
|
|
5621
5991
|
return mark;
|
|
5622
5992
|
}
|
|
5623
|
-
|
|
5993
|
+
/**
|
|
5994
|
+
* Returns the topmost mark element or the closest element with the same tag name as the specified node.
|
|
5995
|
+
*/
|
|
5624
5996
|
function getUpperMark(node, tagName) {
|
|
5625
5997
|
const nodeText = node.text();
|
|
5626
5998
|
let parent = node;
|
|
5627
5999
|
while (parent.length > 0) {
|
|
5628
6000
|
const nextParent = parent.parent();
|
|
5629
|
-
if (!nextParent.isMark
|
|
5630
|
-
nodeText !== nextParent.text()
|
|
5631
|
-
!parent.isText && parent.name === tagName && parent.attr('style') !== '') {
|
|
6001
|
+
if (!nextParent.isMark
|
|
6002
|
+
|| nodeText !== nextParent.text()
|
|
6003
|
+
|| (!parent.isText && parent.name === tagName && parent.attr('style') !== '')) {
|
|
5632
6004
|
break;
|
|
5633
6005
|
}
|
|
5634
6006
|
parent = nextParent;
|
|
5635
6007
|
}
|
|
5636
6008
|
return parent;
|
|
5637
6009
|
}
|
|
5638
|
-
|
|
6010
|
+
/**
|
|
6011
|
+
* Adds the specified mark to the texts of the range.
|
|
6012
|
+
*/
|
|
5639
6013
|
function addMark(range, value) {
|
|
5640
6014
|
if (range.commonAncestor.isOutside) {
|
|
5641
6015
|
return;
|
|
@@ -5730,7 +6104,9 @@ function removeZWS(node) {
|
|
|
5730
6104
|
}
|
|
5731
6105
|
}
|
|
5732
6106
|
|
|
5733
|
-
|
|
6107
|
+
/**
|
|
6108
|
+
* Returns a nested mark copied from each last child of the descendants of the specified node.
|
|
6109
|
+
*/
|
|
5734
6110
|
function getNestedMark(node, tagName) {
|
|
5735
6111
|
if (!node.isMark || !tagName) {
|
|
5736
6112
|
return null;
|
|
@@ -5757,7 +6133,9 @@ function getNestedMark(node, tagName) {
|
|
|
5757
6133
|
}
|
|
5758
6134
|
return mark;
|
|
5759
6135
|
}
|
|
5760
|
-
|
|
6136
|
+
/**
|
|
6137
|
+
* Removes the specified marks in the range.
|
|
6138
|
+
*/
|
|
5761
6139
|
function removeMark(range, value) {
|
|
5762
6140
|
if (range.commonAncestor.isOutside) {
|
|
5763
6141
|
return;
|
|
@@ -5819,7 +6197,9 @@ function removeMark(range, value) {
|
|
|
5819
6197
|
toBookmark(range, bookmark);
|
|
5820
6198
|
}
|
|
5821
6199
|
|
|
5822
|
-
|
|
6200
|
+
/**
|
|
6201
|
+
* Inserts a box into the specified range.
|
|
6202
|
+
*/
|
|
5823
6203
|
function insertBox(range, boxName, boxValue) {
|
|
5824
6204
|
if (range.commonAncestor.isOutside) {
|
|
5825
6205
|
return null;
|
|
@@ -5863,7 +6243,9 @@ function unmountBox(box) {
|
|
|
5863
6243
|
}
|
|
5864
6244
|
return box;
|
|
5865
6245
|
}
|
|
5866
|
-
|
|
6246
|
+
/**
|
|
6247
|
+
* Removes a box that contains the specified range.
|
|
6248
|
+
*/
|
|
5867
6249
|
function removeBox(range) {
|
|
5868
6250
|
if (range.commonAncestor.isOutside) {
|
|
5869
6251
|
return null;
|
|
@@ -5891,36 +6273,38 @@ function removeBox(range) {
|
|
|
5891
6273
|
return box;
|
|
5892
6274
|
}
|
|
5893
6275
|
|
|
5894
|
-
var version = "0.3.
|
|
6276
|
+
var version = "0.3.5";
|
|
5895
6277
|
|
|
5896
6278
|
// Converts the custom HTML tags to the special tags that can not be parsed by browser.
|
|
5897
6279
|
function denormalizeValue(value) {
|
|
5898
|
-
return value
|
|
5899
|
-
replace(/(<lake-box[^>]+>)[\s\S]*?(<\/lake-box>)/
|
|
5900
|
-
replace(/<lake-bookmark\s+type="anchor">\s*<\/lake-bookmark>/
|
|
5901
|
-
replace(/<lake-bookmark\s+type="focus">\s*<\/lake-bookmark>/
|
|
6280
|
+
return value
|
|
6281
|
+
.replace(/(<lake-box[^>]+>)[\s\S]*?(<\/lake-box>)/gi, '$1$2')
|
|
6282
|
+
.replace(/<lake-bookmark\s+type="anchor">\s*<\/lake-bookmark>/gi, '<anchor />')
|
|
6283
|
+
.replace(/<lake-bookmark\s+type="focus">\s*<\/lake-bookmark>/gi, '<focus />');
|
|
5902
6284
|
}
|
|
5903
6285
|
|
|
5904
6286
|
// Converts the special tags to ordinary HTML tags that can be parsed by browser.
|
|
5905
6287
|
function normalizeValue(value) {
|
|
5906
|
-
return value
|
|
5907
|
-
replace(/(<lake-box[^>]+>)[\s\S]*?(<\/lake-box>|$)/
|
|
5908
|
-
replace(/<anchor\s*\/>/
|
|
5909
|
-
replace(/<focus\s*\/>/
|
|
6288
|
+
return value
|
|
6289
|
+
.replace(/(<lake-box[^>]+>)[\s\S]*?(<\/lake-box>|$)/gi, '$1</lake-box>')
|
|
6290
|
+
.replace(/<anchor\s*\/>/gi, '<lake-bookmark type="anchor"></lake-bookmark>')
|
|
6291
|
+
.replace(/<focus\s*\/>/gi, '<lake-bookmark type="focus"></lake-bookmark>');
|
|
5910
6292
|
}
|
|
5911
6293
|
|
|
5912
6294
|
// If the specified node is not visible, scrolls the container that contains the node to its position to make it visible.
|
|
5913
6295
|
function scrollToNode(node, options) {
|
|
5914
6296
|
const visible = visibleInfo(node);
|
|
5915
|
-
if (visible.left !== 0
|
|
5916
|
-
visible.right !== 0
|
|
5917
|
-
visible.top !== 0
|
|
5918
|
-
visible.bottom !== 0) {
|
|
6297
|
+
if (visible.left !== 0
|
|
6298
|
+
|| visible.right !== 0
|
|
6299
|
+
|| visible.top !== 0
|
|
6300
|
+
|| visible.bottom !== 0) {
|
|
5919
6301
|
node.get(0).scrollIntoView(options);
|
|
5920
6302
|
}
|
|
5921
6303
|
}
|
|
5922
6304
|
|
|
5923
|
-
|
|
6305
|
+
/**
|
|
6306
|
+
* Returns a key-value object of all attributes of the specified element.
|
|
6307
|
+
*/
|
|
5924
6308
|
function getAttributes(element) {
|
|
5925
6309
|
const nativeElement = element.get(0);
|
|
5926
6310
|
const attributes = {};
|
|
@@ -5982,6 +6366,9 @@ function appendNextNestedNodes(activeItems, range) {
|
|
|
5982
6366
|
}
|
|
5983
6367
|
}
|
|
5984
6368
|
}
|
|
6369
|
+
/**
|
|
6370
|
+
* The Selection interface represents the range of content selected by the user or the current cursor position.
|
|
6371
|
+
*/
|
|
5985
6372
|
class Selection {
|
|
5986
6373
|
constructor(container) {
|
|
5987
6374
|
const selection = window.getSelection();
|
|
@@ -5994,7 +6381,9 @@ class Selection {
|
|
|
5994
6381
|
this.container = container;
|
|
5995
6382
|
this.range = this.getCurrentRange();
|
|
5996
6383
|
}
|
|
5997
|
-
|
|
6384
|
+
/**
|
|
6385
|
+
* Returns a Range object that is currently selected.
|
|
6386
|
+
*/
|
|
5998
6387
|
getCurrentRange() {
|
|
5999
6388
|
if (this.selection.rangeCount > 0) {
|
|
6000
6389
|
const range = this.selection.getRangeAt(0);
|
|
@@ -6002,7 +6391,9 @@ class Selection {
|
|
|
6002
6391
|
}
|
|
6003
6392
|
return new Range();
|
|
6004
6393
|
}
|
|
6005
|
-
|
|
6394
|
+
/**
|
|
6395
|
+
* Adds the selection.range to the native selection.
|
|
6396
|
+
*/
|
|
6006
6397
|
sync() {
|
|
6007
6398
|
if (!this.container.contains(this.range.commonAncestor)) {
|
|
6008
6399
|
return;
|
|
@@ -6010,21 +6401,25 @@ class Selection {
|
|
|
6010
6401
|
this.selection.removeAllRanges();
|
|
6011
6402
|
this.selection.addRange(this.range.get());
|
|
6012
6403
|
}
|
|
6013
|
-
|
|
6404
|
+
/**
|
|
6405
|
+
* Replaces the selection.range with the range of the native selection.
|
|
6406
|
+
*/
|
|
6014
6407
|
updateByRange() {
|
|
6015
6408
|
const newRange = this.getCurrentRange();
|
|
6016
6409
|
if (!this.container.contains(newRange.commonAncestor)) {
|
|
6017
6410
|
return;
|
|
6018
6411
|
}
|
|
6019
|
-
if (this.range.startNode.get(0) === newRange.startNode.get(0)
|
|
6020
|
-
this.range.startOffset === newRange.startOffset
|
|
6021
|
-
this.range.endNode.get(0) === newRange.endNode.get(0)
|
|
6022
|
-
this.range.endOffset === newRange.endOffset) {
|
|
6412
|
+
if (this.range.startNode.get(0) === newRange.startNode.get(0)
|
|
6413
|
+
&& this.range.startOffset === newRange.startOffset
|
|
6414
|
+
&& this.range.endNode.get(0) === newRange.endNode.get(0)
|
|
6415
|
+
&& this.range.endOffset === newRange.endOffset) {
|
|
6023
6416
|
return;
|
|
6024
6417
|
}
|
|
6025
6418
|
this.range = newRange;
|
|
6026
6419
|
}
|
|
6027
|
-
|
|
6420
|
+
/**
|
|
6421
|
+
* Replaces the selection.range with the range represented by the bookmark.
|
|
6422
|
+
*/
|
|
6028
6423
|
updateByBookmark() {
|
|
6029
6424
|
const range = this.range;
|
|
6030
6425
|
const container = this.container;
|
|
@@ -6045,43 +6440,78 @@ class Selection {
|
|
|
6045
6440
|
});
|
|
6046
6441
|
this.sync();
|
|
6047
6442
|
}
|
|
6443
|
+
/**
|
|
6444
|
+
* Returns a list of items related to the current selection.
|
|
6445
|
+
*/
|
|
6048
6446
|
getActiveItems() {
|
|
6049
6447
|
const activeItems = [];
|
|
6050
6448
|
appendAncestralNodes(activeItems, this.range);
|
|
6051
6449
|
appendNextNestedNodes(activeItems, this.range);
|
|
6052
6450
|
return activeItems;
|
|
6053
6451
|
}
|
|
6452
|
+
/**
|
|
6453
|
+
* Inserts a bookmark at the cursor position or a pair of bookmarks at the selection boundaries.
|
|
6454
|
+
*/
|
|
6054
6455
|
insertBookmark() {
|
|
6055
6456
|
return insertBookmark(this.range);
|
|
6056
6457
|
}
|
|
6458
|
+
/**
|
|
6459
|
+
* Changes selection.range to the range represented by the provided bookmark.
|
|
6460
|
+
*/
|
|
6057
6461
|
toBookmark(bookmark) {
|
|
6058
6462
|
return toBookmark(this.range, bookmark);
|
|
6059
6463
|
}
|
|
6464
|
+
/**
|
|
6465
|
+
* Inserts the specified content into the selection.
|
|
6466
|
+
*/
|
|
6060
6467
|
insertContents(contents) {
|
|
6061
6468
|
return insertContents(this.range, contents);
|
|
6062
6469
|
}
|
|
6470
|
+
/**
|
|
6471
|
+
* Removes the contents of the selection.
|
|
6472
|
+
*/
|
|
6063
6473
|
deleteContents() {
|
|
6064
6474
|
return deleteContents(this.range);
|
|
6065
6475
|
}
|
|
6476
|
+
/**
|
|
6477
|
+
* Adds new blocks or changes the target blocks in the selection.
|
|
6478
|
+
*/
|
|
6066
6479
|
setBlocks(value) {
|
|
6067
6480
|
return setBlocks(this.range, value);
|
|
6068
6481
|
}
|
|
6482
|
+
/**
|
|
6483
|
+
* Removes the contents of the selection and splits the block node at the cursor position.
|
|
6484
|
+
*/
|
|
6069
6485
|
splitBlock() {
|
|
6070
6486
|
return splitBlock$1(this.range);
|
|
6071
6487
|
}
|
|
6488
|
+
/**
|
|
6489
|
+
* Inserts a block into the selection.
|
|
6490
|
+
*/
|
|
6072
6491
|
insertBlock(value) {
|
|
6073
6492
|
return insertBlock(this.range, value);
|
|
6074
6493
|
}
|
|
6494
|
+
/**
|
|
6495
|
+
* Splits text nodes or mark nodes.
|
|
6496
|
+
*/
|
|
6075
6497
|
splitMarks(removeEmptyMark) {
|
|
6076
6498
|
return splitMarks(this.range, removeEmptyMark);
|
|
6077
6499
|
}
|
|
6500
|
+
/**
|
|
6501
|
+
* Adds the specified mark to the selected text.
|
|
6502
|
+
*/
|
|
6078
6503
|
addMark(value) {
|
|
6079
6504
|
return addMark(this.range, value);
|
|
6080
6505
|
}
|
|
6506
|
+
/**
|
|
6507
|
+
* Removes specified marks from the selection.
|
|
6508
|
+
*/
|
|
6081
6509
|
removeMark(value) {
|
|
6082
6510
|
return removeMark(this.range, value);
|
|
6083
6511
|
}
|
|
6084
|
-
|
|
6512
|
+
/**
|
|
6513
|
+
* Collapses the selection to the center position of the specified box.
|
|
6514
|
+
*/
|
|
6085
6515
|
selectBox(box) {
|
|
6086
6516
|
let boxNode = box;
|
|
6087
6517
|
if (box instanceof Box) {
|
|
@@ -6093,7 +6523,9 @@ class Selection {
|
|
|
6093
6523
|
this.range.selectBox(boxNode);
|
|
6094
6524
|
this.sync();
|
|
6095
6525
|
}
|
|
6096
|
-
|
|
6526
|
+
/**
|
|
6527
|
+
* Inserts a box into the selection.
|
|
6528
|
+
*/
|
|
6097
6529
|
insertBox(boxName, boxValue) {
|
|
6098
6530
|
const box = insertBox(this.range, boxName, boxValue);
|
|
6099
6531
|
if (!box) {
|
|
@@ -6101,7 +6533,9 @@ class Selection {
|
|
|
6101
6533
|
}
|
|
6102
6534
|
return box;
|
|
6103
6535
|
}
|
|
6104
|
-
|
|
6536
|
+
/**
|
|
6537
|
+
* Removes the specified box. If no parameter is given, the selected box is removed.
|
|
6538
|
+
*/
|
|
6105
6539
|
removeBox(box = null) {
|
|
6106
6540
|
if (box) {
|
|
6107
6541
|
this.selectBox(box);
|
|
@@ -6110,23 +6544,41 @@ class Selection {
|
|
|
6110
6544
|
}
|
|
6111
6545
|
}
|
|
6112
6546
|
|
|
6547
|
+
/**
|
|
6548
|
+
* The Command interface manages a collection of commands.
|
|
6549
|
+
*/
|
|
6113
6550
|
class Command {
|
|
6114
6551
|
constructor(selection) {
|
|
6115
6552
|
this.commandMap = new Map();
|
|
6116
6553
|
this.selection = selection;
|
|
6117
6554
|
}
|
|
6555
|
+
/**
|
|
6556
|
+
* Adds a new command to the collection.
|
|
6557
|
+
*/
|
|
6118
6558
|
add(name, commandItem) {
|
|
6119
6559
|
this.commandMap.set(name, commandItem);
|
|
6120
6560
|
}
|
|
6561
|
+
/**
|
|
6562
|
+
* Removes a command from the collection by its name.
|
|
6563
|
+
*/
|
|
6121
6564
|
delete(name) {
|
|
6122
6565
|
this.commandMap.delete(name);
|
|
6123
6566
|
}
|
|
6567
|
+
/**
|
|
6568
|
+
* Returns the names of all registered commands.
|
|
6569
|
+
*/
|
|
6124
6570
|
getNames() {
|
|
6125
6571
|
return Array.from(this.commandMap.keys());
|
|
6126
6572
|
}
|
|
6573
|
+
/**
|
|
6574
|
+
* Checks whether the specified command exists.
|
|
6575
|
+
*/
|
|
6127
6576
|
has(name) {
|
|
6128
6577
|
return this.commandMap.get(name) !== undefined;
|
|
6129
6578
|
}
|
|
6579
|
+
/**
|
|
6580
|
+
* Returns a command item by its name.
|
|
6581
|
+
*/
|
|
6130
6582
|
getItem(name) {
|
|
6131
6583
|
const commandItem = this.commandMap.get(name);
|
|
6132
6584
|
if (commandItem === undefined) {
|
|
@@ -6134,6 +6586,9 @@ class Command {
|
|
|
6134
6586
|
}
|
|
6135
6587
|
return commandItem;
|
|
6136
6588
|
}
|
|
6589
|
+
/**
|
|
6590
|
+
* Checks if the specified command is disabled.
|
|
6591
|
+
*/
|
|
6137
6592
|
isDisabled(name) {
|
|
6138
6593
|
const commandItem = this.getItem(name);
|
|
6139
6594
|
if (!commandItem.isDisabled) {
|
|
@@ -6142,6 +6597,9 @@ class Command {
|
|
|
6142
6597
|
const activeItems = this.selection.getActiveItems();
|
|
6143
6598
|
return commandItem.isDisabled(activeItems);
|
|
6144
6599
|
}
|
|
6600
|
+
/**
|
|
6601
|
+
* Checks if the specified command is selected.
|
|
6602
|
+
*/
|
|
6145
6603
|
isSelected(name) {
|
|
6146
6604
|
const commandItem = this.getItem(name);
|
|
6147
6605
|
if (!commandItem.isSelected) {
|
|
@@ -6150,6 +6608,9 @@ class Command {
|
|
|
6150
6608
|
const activeItems = this.selection.getActiveItems();
|
|
6151
6609
|
return commandItem.isSelected(activeItems);
|
|
6152
6610
|
}
|
|
6611
|
+
/**
|
|
6612
|
+
* Returns the selected values for the specified command.
|
|
6613
|
+
*/
|
|
6153
6614
|
selectedValues(name) {
|
|
6154
6615
|
const commandItem = this.getItem(name);
|
|
6155
6616
|
if (!commandItem.selectedValues) {
|
|
@@ -6158,6 +6619,9 @@ class Command {
|
|
|
6158
6619
|
const activeItems = this.selection.getActiveItems();
|
|
6159
6620
|
return commandItem.selectedValues(activeItems);
|
|
6160
6621
|
}
|
|
6622
|
+
/**
|
|
6623
|
+
* Executes the specified command.
|
|
6624
|
+
*/
|
|
6161
6625
|
execute(name, ...data) {
|
|
6162
6626
|
const container = this.selection.container;
|
|
6163
6627
|
const range = this.selection.range;
|
|
@@ -6170,7 +6634,7 @@ class Command {
|
|
|
6170
6634
|
}
|
|
6171
6635
|
}
|
|
6172
6636
|
|
|
6173
|
-
|
|
6637
|
+
/*
|
|
6174
6638
|
BSD 2-Clause License
|
|
6175
6639
|
|
|
6176
6640
|
Copyright (c) 2022, Big Sky Software
|
|
@@ -6201,7 +6665,7 @@ Repository: https://github.com/bigskysoftware/idiomorph
|
|
|
6201
6665
|
*/
|
|
6202
6666
|
const EMPTY_SET = new Set();
|
|
6203
6667
|
function noOp() { }
|
|
6204
|
-
//
|
|
6668
|
+
// Default configuration values, updatable by users now.
|
|
6205
6669
|
const defaults = {
|
|
6206
6670
|
morphStyle: 'outerHTML',
|
|
6207
6671
|
callbacks: {
|
|
@@ -6223,9 +6687,9 @@ const defaults = {
|
|
|
6223
6687
|
afterHeadMorphed: noOp,
|
|
6224
6688
|
},
|
|
6225
6689
|
};
|
|
6226
|
-
|
|
6690
|
+
/**
|
|
6227
6691
|
Deep merges the config object and the Idiomoroph.defaults object to
|
|
6228
|
-
produce a final configuration object
|
|
6692
|
+
produce a final configuration object.
|
|
6229
6693
|
*/
|
|
6230
6694
|
function mergeDefaults(config) {
|
|
6231
6695
|
const finalConfig = {};
|
|
@@ -6262,8 +6726,8 @@ function getIdIntersectionCount(ctx, node1, node2) {
|
|
|
6262
6726
|
const sourceSet = ctx.idMap.get(node1) || EMPTY_SET;
|
|
6263
6727
|
let matchCount = 0;
|
|
6264
6728
|
for (const id of sourceSet) {
|
|
6265
|
-
//
|
|
6266
|
-
// that has not already been merged into the DOM
|
|
6729
|
+
// A potential match is an id in the source and potentialIdsSet, but
|
|
6730
|
+
// that has not already been merged into the DOM.
|
|
6267
6731
|
if (isIdInConsideration(ctx, id) && idIsWithinNode(ctx, id, node2)) {
|
|
6268
6732
|
++matchCount;
|
|
6269
6733
|
}
|
|
@@ -6273,10 +6737,7 @@ function getIdIntersectionCount(ctx, node1, node2) {
|
|
|
6273
6737
|
/**
|
|
6274
6738
|
* A bottom up algorithm that finds all elements with ids inside of the node
|
|
6275
6739
|
* argument and populates id sets for those nodes and all their parents, generating
|
|
6276
|
-
* a set of ids contained within all nodes for the entire hierarchy in the DOM
|
|
6277
|
-
*
|
|
6278
|
-
* @param node {Element}
|
|
6279
|
-
* @param {Map<Node, Set<String>>} idMap
|
|
6740
|
+
* a set of ids contained within all nodes for the entire hierarchy in the DOM.
|
|
6280
6741
|
*/
|
|
6281
6742
|
function populateIdMapForNode(node, idMap) {
|
|
6282
6743
|
const nodeParent = node.parentElement;
|
|
@@ -6304,9 +6765,9 @@ function populateIdMapForNode(node, idMap) {
|
|
|
6304
6765
|
* for a looser definition of "matching" than tradition id matching, and allows child nodes
|
|
6305
6766
|
* to contribute to a parent nodes matching.
|
|
6306
6767
|
*
|
|
6307
|
-
* @param
|
|
6308
|
-
* @param
|
|
6309
|
-
* @returns
|
|
6768
|
+
* @param oldContent The old content that will be morphed.
|
|
6769
|
+
* @param newContent The new content to morph to.
|
|
6770
|
+
* @returns A map of nodes to id sets.
|
|
6310
6771
|
*/
|
|
6311
6772
|
function createIdMap(oldContent, newContent) {
|
|
6312
6773
|
const idMap = new Map();
|
|
@@ -6349,8 +6810,9 @@ function isSoftMatch(node1, node2) {
|
|
|
6349
6810
|
}
|
|
6350
6811
|
function removeNode(tempNode, ctx) {
|
|
6351
6812
|
removeIdsFromConsideration(ctx, tempNode);
|
|
6352
|
-
if (ctx.callbacks.beforeNodeRemoved(tempNode) === false)
|
|
6813
|
+
if (ctx.callbacks.beforeNodeRemoved(tempNode) === false) {
|
|
6353
6814
|
return;
|
|
6815
|
+
}
|
|
6354
6816
|
tempNode.remove();
|
|
6355
6817
|
ctx.callbacks.afterNodeRemoved(tempNode);
|
|
6356
6818
|
}
|
|
@@ -6364,12 +6826,12 @@ function removeNodesBetween(startInclusive, endExclusive, ctx) {
|
|
|
6364
6826
|
removeIdsFromConsideration(ctx, endExclusive);
|
|
6365
6827
|
return endExclusive.nextSibling;
|
|
6366
6828
|
}
|
|
6367
|
-
|
|
6368
|
-
|
|
6369
|
-
|
|
6370
|
-
|
|
6371
|
-
|
|
6372
|
-
|
|
6829
|
+
/**
|
|
6830
|
+
* Scans forward from the insertionPoint in the old parent looking for a potential id match
|
|
6831
|
+
* for the newChild. We stop if we find a potential id match for the new child OR
|
|
6832
|
+
* if the number of potential id matches we are discarding is greater than the
|
|
6833
|
+
* potential id matches for the new child.
|
|
6834
|
+
*/
|
|
6373
6835
|
function findIdSetMatch(newContent, oldParent, newChild, insertionPoint, ctx) {
|
|
6374
6836
|
// max id matches we are willing to discard in our search
|
|
6375
6837
|
const newChildPotentialIdCount = getIdIntersectionCount(ctx, newChild, oldParent);
|
|
@@ -6400,12 +6862,12 @@ function findIdSetMatch(newContent, oldParent, newChild, insertionPoint, ctx) {
|
|
|
6400
6862
|
}
|
|
6401
6863
|
return potentialMatch;
|
|
6402
6864
|
}
|
|
6403
|
-
|
|
6404
|
-
|
|
6405
|
-
|
|
6406
|
-
|
|
6407
|
-
|
|
6408
|
-
|
|
6865
|
+
/**
|
|
6866
|
+
* Scans forward from the insertionPoint in the old parent looking for a potential soft match
|
|
6867
|
+
* for the newChild. We stop if we find a potential soft match for the new child OR
|
|
6868
|
+
* if we find a potential id match in the old parents children OR if we find two
|
|
6869
|
+
* potential soft matches for the next two pieces of new content.
|
|
6870
|
+
*/
|
|
6409
6871
|
function findSoftMatch(newContent, oldParent, newChild, insertionPoint, ctx) {
|
|
6410
6872
|
let potentialSoftMatch = insertionPoint;
|
|
6411
6873
|
let nextSibling = newChild.nextSibling;
|
|
@@ -6473,7 +6935,7 @@ function insertSiblings(previousSibling, morphedNode, nextSibling) {
|
|
|
6473
6935
|
const node = stack.pop();
|
|
6474
6936
|
added.push(node); // push added preceding siblings on in order and insert
|
|
6475
6937
|
if (node) {
|
|
6476
|
-
(_a = morphedNode.parentElement) === null || _a ===
|
|
6938
|
+
(_a = morphedNode.parentElement) === null || _a === void 0 ? void 0 : _a.insertBefore(node, morphedNode);
|
|
6477
6939
|
}
|
|
6478
6940
|
}
|
|
6479
6941
|
added.push(morphedNode);
|
|
@@ -6486,14 +6948,14 @@ function insertSiblings(previousSibling, morphedNode, nextSibling) {
|
|
|
6486
6948
|
while (stack.length > 0) {
|
|
6487
6949
|
const node = stack.pop();
|
|
6488
6950
|
if (node) {
|
|
6489
|
-
(_b = morphedNode.parentElement) === null || _b ===
|
|
6951
|
+
(_b = morphedNode.parentElement) === null || _b === void 0 ? void 0 : _b.insertBefore(node, morphedNode.nextSibling);
|
|
6490
6952
|
}
|
|
6491
6953
|
}
|
|
6492
6954
|
return added;
|
|
6493
6955
|
}
|
|
6494
6956
|
function scoreElement(node1, node2, ctx) {
|
|
6495
6957
|
if (isSoftMatch(node1, node2)) {
|
|
6496
|
-
return .5 + getIdIntersectionCount(ctx, node1, node2);
|
|
6958
|
+
return 0.5 + getIdIntersectionCount(ctx, node1, node2);
|
|
6497
6959
|
}
|
|
6498
6960
|
return 0;
|
|
6499
6961
|
}
|
|
@@ -6515,12 +6977,12 @@ function findBestNodeMatch(newContent, oldNode, ctx) {
|
|
|
6515
6977
|
// =============================================================================
|
|
6516
6978
|
// Attribute Syncing Code
|
|
6517
6979
|
// =============================================================================
|
|
6518
|
-
|
|
6519
|
-
* @param attr
|
|
6520
|
-
* @param to
|
|
6521
|
-
* @param updateType
|
|
6522
|
-
* @param ctx
|
|
6523
|
-
* @returns
|
|
6980
|
+
/**
|
|
6981
|
+
* @param attr The attribute to be mutated.
|
|
6982
|
+
* @param to The element that is going to be updated.
|
|
6983
|
+
* @param updateType 'update' or 'remove'
|
|
6984
|
+
* @param ctx The merge context.
|
|
6985
|
+
* @returns True if the attribute should be ignored, false otherwise.
|
|
6524
6986
|
*/
|
|
6525
6987
|
function ignoreAttribute(attr, to, updateType, ctx) {
|
|
6526
6988
|
if (attr === 'value' && ctx.ignoreActiveValue && to === document.activeElement) {
|
|
@@ -6531,18 +6993,17 @@ function ignoreAttribute(attr, to, updateType, ctx) {
|
|
|
6531
6993
|
/**
|
|
6532
6994
|
* @param possibleActiveElement
|
|
6533
6995
|
* @param ctx
|
|
6534
|
-
* @returns {boolean}
|
|
6535
6996
|
*/
|
|
6536
6997
|
function ignoreValueOfActiveElement(possibleActiveElement, ctx) {
|
|
6537
6998
|
return ctx.ignoreActiveValue && possibleActiveElement === document.activeElement;
|
|
6538
6999
|
}
|
|
6539
7000
|
/**
|
|
6540
|
-
*
|
|
6541
|
-
* inner element state from the 'from' node to the 'to' node
|
|
7001
|
+
* Syncs a given node with another node, copying over all attributes and
|
|
7002
|
+
* inner element state from the 'from' node to the 'to' node.
|
|
6542
7003
|
*
|
|
6543
|
-
* @param
|
|
6544
|
-
* @param
|
|
6545
|
-
* @param ctx
|
|
7004
|
+
* @param from The element to copy attributes & state from.
|
|
7005
|
+
* @param to The element to copy attributes & state to.
|
|
7006
|
+
* @param ctx The merge context.
|
|
6546
7007
|
*/
|
|
6547
7008
|
function syncNodeFrom(from, to, ctx) {
|
|
6548
7009
|
const type = from.nodeType;
|
|
@@ -6580,10 +7041,10 @@ function syncNodeFrom(from, to, ctx) {
|
|
|
6580
7041
|
}
|
|
6581
7042
|
}
|
|
6582
7043
|
/**
|
|
6583
|
-
* @param oldNode
|
|
6584
|
-
* @param newContent
|
|
6585
|
-
* @param ctx
|
|
6586
|
-
* @returns
|
|
7044
|
+
* @param oldNode Root node to merge content into.
|
|
7045
|
+
* @param newContent New content to merge.
|
|
7046
|
+
* @param ctx The merge context.
|
|
7047
|
+
* @returns The element that ended up in the DOM.
|
|
6587
7048
|
*/
|
|
6588
7049
|
function morphOldNodeTo(oldNode, newContent, ctx) {
|
|
6589
7050
|
var _a;
|
|
@@ -6600,7 +7061,7 @@ function morphOldNodeTo(oldNode, newContent, ctx) {
|
|
|
6600
7061
|
return oldNode;
|
|
6601
7062
|
if (ctx.callbacks.beforeNodeAdded(newContent) === false)
|
|
6602
7063
|
return oldNode;
|
|
6603
|
-
(_a = oldNode.parentElement) === null || _a ===
|
|
7064
|
+
(_a = oldNode.parentElement) === null || _a === void 0 ? void 0 : _a.replaceChild(newContent, oldNode);
|
|
6604
7065
|
ctx.callbacks.afterNodeAdded(newContent);
|
|
6605
7066
|
ctx.callbacks.afterNodeRemoved(oldNode);
|
|
6606
7067
|
return newContent;
|
|
@@ -6617,26 +7078,26 @@ function morphOldNodeTo(oldNode, newContent, ctx) {
|
|
|
6617
7078
|
}
|
|
6618
7079
|
}
|
|
6619
7080
|
/**
|
|
6620
|
-
* This is the core algorithm for matching up children.
|
|
6621
|
-
* nodes as faithfully as possible.
|
|
7081
|
+
* This is the core algorithm for matching up children. The idea is to use id sets to try to match up
|
|
7082
|
+
* nodes as faithfully as possible. We greedily match, which allows us to keep the algorithm fast, but
|
|
6622
7083
|
* by using id sets, we are able to better match up with content deeper in the DOM.
|
|
6623
7084
|
*
|
|
6624
7085
|
* Basic algorithm is, for each node in the new content:
|
|
6625
7086
|
*
|
|
6626
|
-
* -
|
|
6627
|
-
* -
|
|
6628
|
-
* -
|
|
6629
|
-
* -
|
|
6630
|
-
* -
|
|
6631
|
-
* -
|
|
6632
|
-
* -
|
|
7087
|
+
* - If we have reached the end of the old parent, append the new content.
|
|
7088
|
+
* - If the new content has an id set match with the current insertion point, morph.
|
|
7089
|
+
* - Search for an id set match.
|
|
7090
|
+
* - If id set match found, morph.
|
|
7091
|
+
* - Otherwise search for a "soft" match.
|
|
7092
|
+
* - If a soft match is found, morph.
|
|
7093
|
+
* - Otherwise, prepend the new node before the current insertion point.
|
|
6633
7094
|
*
|
|
6634
7095
|
* The two search algorithms terminate if competing node matches appear to outweigh what can be achieved
|
|
6635
|
-
* with the current node.
|
|
7096
|
+
* with the current node. See findIdSetMatch() and findSoftMatch() for details.
|
|
6636
7097
|
*
|
|
6637
|
-
* @param
|
|
6638
|
-
* @param
|
|
6639
|
-
* @param ctx
|
|
7098
|
+
* @param newParent The parent element of the new content.
|
|
7099
|
+
* @param oldParent The old content that we are merging the new content into.
|
|
7100
|
+
* @param ctx The merge context.
|
|
6640
7101
|
*/
|
|
6641
7102
|
function morphChildren(newParent, oldParent, ctx) {
|
|
6642
7103
|
let nextNewChild = newParent.firstChild;
|
|
@@ -6701,35 +7162,35 @@ function morphNormalizedContent(oldNode, normalizedNewContent, ctx) {
|
|
|
6701
7162
|
morphChildren(normalizedNewContent, oldNode, ctx);
|
|
6702
7163
|
return oldNode.children;
|
|
6703
7164
|
}
|
|
6704
|
-
|
|
6705
|
-
|
|
6706
|
-
|
|
6707
|
-
|
|
6708
|
-
|
|
6709
|
-
|
|
6710
|
-
|
|
6711
|
-
|
|
6712
|
-
|
|
6713
|
-
if
|
|
6714
|
-
|
|
6715
|
-
|
|
6716
|
-
|
|
6717
|
-
|
|
6718
|
-
|
|
6719
|
-
return [];
|
|
6720
|
-
}
|
|
6721
|
-
throw `Do not understand how to morph style ${ctx.morphStyle}`;
|
|
7165
|
+
// otherwise find the best element match in the new content, morph that, and merge its siblings
|
|
7166
|
+
// into either side of the best match
|
|
7167
|
+
const bestMatch = findBestNodeMatch(normalizedNewContent, oldNode, ctx);
|
|
7168
|
+
// stash the siblings that will need to be inserted on either side of the best match
|
|
7169
|
+
const previousSibling = bestMatch === null || bestMatch === void 0 ? void 0 : bestMatch.previousSibling;
|
|
7170
|
+
const nextSibling = bestMatch === null || bestMatch === void 0 ? void 0 : bestMatch.nextSibling;
|
|
7171
|
+
// morph it
|
|
7172
|
+
const morphedNode = morphOldNodeTo(oldNode, bestMatch, ctx);
|
|
7173
|
+
if (bestMatch) {
|
|
7174
|
+
// if there was a best match, merge the siblings in too and return the
|
|
7175
|
+
// whole bunch
|
|
7176
|
+
return insertSiblings(previousSibling, morphedNode, nextSibling);
|
|
7177
|
+
}
|
|
7178
|
+
// otherwise nothing was added to the DOM
|
|
7179
|
+
return [];
|
|
6722
7180
|
}
|
|
6723
|
-
|
|
6724
|
-
|
|
6725
|
-
|
|
7181
|
+
/**
|
|
7182
|
+
* Morphs one DOM tree to another.
|
|
7183
|
+
*/
|
|
6726
7184
|
function morph(node, otherNode, config = {}) {
|
|
6727
7185
|
const normalizedContent = normalizeContent(otherNode.get(0));
|
|
6728
7186
|
const ctx = createMorphContext(node.get(0), normalizedContent, config);
|
|
6729
7187
|
morphNormalizedContent(node.get(0), normalizedContent, ctx);
|
|
6730
7188
|
}
|
|
6731
7189
|
|
|
6732
|
-
|
|
7190
|
+
/**
|
|
7191
|
+
* The History interface manages undo and redo functionality for a container that holds some editable content.
|
|
7192
|
+
* It emits events when actions like save, undo, or redo are performed.
|
|
7193
|
+
*/
|
|
6733
7194
|
//
|
|
6734
7195
|
// Example:
|
|
6735
7196
|
//
|
|
@@ -6746,19 +7207,29 @@ function morph(node, otherNode, config = {}) {
|
|
|
6746
7207
|
class History {
|
|
6747
7208
|
constructor(selection) {
|
|
6748
7209
|
this.canSave = true;
|
|
6749
|
-
|
|
7210
|
+
/**
|
|
7211
|
+
* A list in which the current and previous contents are stored.
|
|
7212
|
+
*/
|
|
6750
7213
|
this.list = [];
|
|
6751
|
-
|
|
7214
|
+
/**
|
|
7215
|
+
* An index that always indicates the position at which new content is stored.
|
|
7216
|
+
*/
|
|
6752
7217
|
this.index = 0;
|
|
7218
|
+
/**
|
|
7219
|
+
* The maximum length of the history. Once this limit is reached, the earliest item in the list will be removed.
|
|
7220
|
+
*/
|
|
6753
7221
|
this.limit = 100;
|
|
7222
|
+
/**
|
|
7223
|
+
* An EventEmitter object used to set up events.
|
|
7224
|
+
*/
|
|
6754
7225
|
this.event = new EventEmitter();
|
|
6755
7226
|
this.selection = selection;
|
|
6756
7227
|
this.container = selection.container;
|
|
6757
7228
|
}
|
|
6758
7229
|
removeBookmark(value) {
|
|
6759
|
-
return value.replace(/(<lake-box[^>]+)\
|
|
6760
|
-
replace(/<lake-bookmark\s+type="anchor">\s*<\/lake-bookmark>/
|
|
6761
|
-
replace(/<lake-bookmark\s+type="focus">\s*<\/lake-bookmark>/
|
|
7230
|
+
return value.replace(/(<lake-box[^>]+)\sfocus="\w+"([^>]*>)/gi, '$1$2')
|
|
7231
|
+
.replace(/<lake-bookmark\s+type="anchor">\s*<\/lake-bookmark>/gi, '')
|
|
7232
|
+
.replace(/<lake-bookmark\s+type="focus">\s*<\/lake-bookmark>/gi, '');
|
|
6762
7233
|
}
|
|
6763
7234
|
getValue(container) {
|
|
6764
7235
|
return new HTMLParser(container).getHTML();
|
|
@@ -6802,12 +7273,22 @@ class History {
|
|
|
6802
7273
|
this.removeIdfromBoxes(container);
|
|
6803
7274
|
this.removeIdfromBoxes(otherContainer);
|
|
6804
7275
|
}
|
|
7276
|
+
/**
|
|
7277
|
+
* A boolean value indicating whether the history can be undone.
|
|
7278
|
+
*/
|
|
6805
7279
|
get canUndo() {
|
|
6806
7280
|
return this.index > 1 && !!this.list[this.index - 2];
|
|
6807
7281
|
}
|
|
7282
|
+
/**
|
|
7283
|
+
* A boolean value indicating whether the history can be redone.
|
|
7284
|
+
*/
|
|
6808
7285
|
get canRedo() {
|
|
6809
7286
|
return !!this.list[this.index];
|
|
6810
7287
|
}
|
|
7288
|
+
/**
|
|
7289
|
+
* Creates a deep clone of the current container with its content.
|
|
7290
|
+
* If there is a selection within the container, it ensures the selection is also preserved in the cloned container.
|
|
7291
|
+
*/
|
|
6811
7292
|
cloneContainer() {
|
|
6812
7293
|
const range = this.selection.range;
|
|
6813
7294
|
const newContainer = this.container.clone(true);
|
|
@@ -6837,6 +7318,9 @@ class History {
|
|
|
6837
7318
|
insertBookmark(newRange);
|
|
6838
7319
|
return newContainer;
|
|
6839
7320
|
}
|
|
7321
|
+
/**
|
|
7322
|
+
* Undoes to the previous saved content.
|
|
7323
|
+
*/
|
|
6840
7324
|
undo() {
|
|
6841
7325
|
if (!this.list[this.index - 2]) {
|
|
6842
7326
|
return;
|
|
@@ -6859,6 +7343,9 @@ class History {
|
|
|
6859
7343
|
this.selection.updateByBookmark();
|
|
6860
7344
|
debug(`History undone (index: ${this.index})`);
|
|
6861
7345
|
}
|
|
7346
|
+
/**
|
|
7347
|
+
* Redoes to the next saved content.
|
|
7348
|
+
*/
|
|
6862
7349
|
redo() {
|
|
6863
7350
|
if (!this.list[this.index]) {
|
|
6864
7351
|
return;
|
|
@@ -6881,24 +7368,36 @@ class History {
|
|
|
6881
7368
|
this.selection.updateByBookmark();
|
|
6882
7369
|
debug(`History redone (index: ${this.index})`);
|
|
6883
7370
|
}
|
|
7371
|
+
/**
|
|
7372
|
+
* Resumes the ability to save history.
|
|
7373
|
+
* This method re-enables saving after the pause method has been called.
|
|
7374
|
+
*/
|
|
6884
7375
|
continue() {
|
|
6885
7376
|
this.canSave = true;
|
|
6886
7377
|
}
|
|
7378
|
+
/**
|
|
7379
|
+
* Pauses the ability to save history.
|
|
7380
|
+
* This method temporarily disables saving history, which can be resumed later by calling the continue method.
|
|
7381
|
+
*/
|
|
6887
7382
|
pause() {
|
|
6888
7383
|
this.canSave = false;
|
|
6889
7384
|
}
|
|
7385
|
+
/**
|
|
7386
|
+
* Saves the current content to the history.
|
|
7387
|
+
* The content is saved only if it is different from the previous content.
|
|
7388
|
+
*/
|
|
6890
7389
|
save(options = {}) {
|
|
6891
7390
|
var _a, _b, _c;
|
|
6892
|
-
const inputType = (_a = options.inputType) !== null && _a !==
|
|
6893
|
-
const update = (_b = options.update) !== null && _b !==
|
|
6894
|
-
const emitEvent = (_c = options.emitEvent) !== null && _c !==
|
|
7391
|
+
const inputType = (_a = options.inputType) !== null && _a !== void 0 ? _a : '';
|
|
7392
|
+
const update = (_b = options.update) !== null && _b !== void 0 ? _b : false;
|
|
7393
|
+
const emitEvent = (_c = options.emitEvent) !== null && _c !== void 0 ? _c : true;
|
|
6895
7394
|
if (!this.canSave) {
|
|
6896
7395
|
return;
|
|
6897
7396
|
}
|
|
6898
7397
|
const item = this.cloneContainer();
|
|
6899
7398
|
const value = this.getValue(item);
|
|
6900
|
-
if (this.list[this.index - 1]
|
|
6901
|
-
this.removeBookmark(this.getValue(this.list[this.index - 1])) === this.removeBookmark(value)) {
|
|
7399
|
+
if (this.list[this.index - 1]
|
|
7400
|
+
&& this.removeBookmark(this.getValue(this.list[this.index - 1])) === this.removeBookmark(value)) {
|
|
6902
7401
|
return;
|
|
6903
7402
|
}
|
|
6904
7403
|
if (update) {
|
|
@@ -6923,6 +7422,10 @@ class History {
|
|
|
6923
7422
|
}
|
|
6924
7423
|
}
|
|
6925
7424
|
|
|
7425
|
+
/**
|
|
7426
|
+
* The Keystroke interface provides a way to handle keyboard events and define custom shortcuts for a given container.
|
|
7427
|
+
* It allows you to register hotkeys, bind specific actions to them, and handle their execution.
|
|
7428
|
+
*/
|
|
6926
7429
|
class Keystroke {
|
|
6927
7430
|
constructor(container) {
|
|
6928
7431
|
this.keydownEventList = [];
|
|
@@ -6961,21 +7464,29 @@ class Keystroke {
|
|
|
6961
7464
|
}
|
|
6962
7465
|
});
|
|
6963
7466
|
}
|
|
6964
|
-
|
|
7467
|
+
/**
|
|
7468
|
+
* Registers a keydown event listener for the specified key combination.
|
|
7469
|
+
* The listener will be triggered when the key combination is pressed.
|
|
7470
|
+
*/
|
|
6965
7471
|
setKeydown(type, listener) {
|
|
6966
7472
|
this.keydownEventList.push({
|
|
6967
7473
|
type,
|
|
6968
7474
|
listener,
|
|
6969
7475
|
});
|
|
6970
7476
|
}
|
|
6971
|
-
|
|
7477
|
+
/**
|
|
7478
|
+
* Registers a keyup event listener for the specified key combination.
|
|
7479
|
+
* The listener will be triggered when the key combination is released.
|
|
7480
|
+
*/
|
|
6972
7481
|
setKeyup(type, listener) {
|
|
6973
7482
|
this.keyupEventList.push({
|
|
6974
7483
|
type,
|
|
6975
7484
|
listener,
|
|
6976
7485
|
});
|
|
6977
7486
|
}
|
|
6978
|
-
|
|
7487
|
+
/**
|
|
7488
|
+
* Triggers all keydown event listeners associated with the specified key combination.
|
|
7489
|
+
*/
|
|
6979
7490
|
keydown(type) {
|
|
6980
7491
|
for (const item of this.keydownEventList) {
|
|
6981
7492
|
if (item.type === type) {
|
|
@@ -6985,7 +7496,9 @@ class Keystroke {
|
|
|
6985
7496
|
}
|
|
6986
7497
|
}
|
|
6987
7498
|
}
|
|
6988
|
-
|
|
7499
|
+
/**
|
|
7500
|
+
* Triggers all keyup event listeners associated with the specified key combination.
|
|
7501
|
+
*/
|
|
6989
7502
|
keyup(type) {
|
|
6990
7503
|
for (const item of this.keyupEventList) {
|
|
6991
7504
|
if (item.type === type) {
|
|
@@ -6997,25 +7510,48 @@ class Keystroke {
|
|
|
6997
7510
|
}
|
|
6998
7511
|
}
|
|
6999
7512
|
|
|
7513
|
+
/**
|
|
7514
|
+
* The BoxManager interface manages a collection of BoxComponent objects.
|
|
7515
|
+
* It allows you to add, remove, and retrieve the names of components.
|
|
7516
|
+
*/
|
|
7000
7517
|
class BoxManager {
|
|
7518
|
+
/**
|
|
7519
|
+
* Adds a BoxComponent to the collection.
|
|
7520
|
+
*/
|
|
7001
7521
|
add(component) {
|
|
7002
7522
|
boxes.set(component.name, component);
|
|
7003
7523
|
}
|
|
7524
|
+
/**
|
|
7525
|
+
* Removes a box component from the collection by its name.
|
|
7526
|
+
*/
|
|
7004
7527
|
remove(name) {
|
|
7005
7528
|
boxes.delete(name);
|
|
7006
7529
|
}
|
|
7530
|
+
/**
|
|
7531
|
+
* Returns a list of all box component names in the collection.
|
|
7532
|
+
*/
|
|
7007
7533
|
getNames() {
|
|
7008
7534
|
return Array.from(boxes.keys());
|
|
7009
7535
|
}
|
|
7010
7536
|
}
|
|
7011
7537
|
|
|
7538
|
+
/**
|
|
7539
|
+
* The Plugin interface manages a collection of plugins.
|
|
7540
|
+
* It allows plugins to be added and loaded into an Editor instance, and it handles the initialization and unmounting of those plugins.
|
|
7541
|
+
*/
|
|
7012
7542
|
class Plugin {
|
|
7013
7543
|
constructor() {
|
|
7014
7544
|
this.pluginMap = new Map();
|
|
7015
7545
|
}
|
|
7546
|
+
/**
|
|
7547
|
+
* Registers a plugin using a name as the key.
|
|
7548
|
+
*/
|
|
7016
7549
|
add(name, plugin) {
|
|
7017
7550
|
this.pluginMap.set(name, plugin);
|
|
7018
7551
|
}
|
|
7552
|
+
/**
|
|
7553
|
+
* Loads all registered plugins.
|
|
7554
|
+
*/
|
|
7019
7555
|
loadAll(editor) {
|
|
7020
7556
|
const unmountPluginMap = new Map();
|
|
7021
7557
|
for (const name of this.pluginMap.keys()) {
|
|
@@ -7048,41 +7584,53 @@ const defaultConfig = {
|
|
|
7048
7584
|
return;
|
|
7049
7585
|
}
|
|
7050
7586
|
if (type === 'warning') {
|
|
7051
|
-
// eslint-disable-next-line no-console
|
|
7052
7587
|
console.warn(message);
|
|
7053
7588
|
return;
|
|
7054
7589
|
}
|
|
7055
7590
|
if (type === 'error') {
|
|
7056
|
-
// eslint-disable-next-line no-console
|
|
7057
7591
|
console.error(message);
|
|
7058
7592
|
}
|
|
7059
7593
|
},
|
|
7060
7594
|
slash: false,
|
|
7061
7595
|
mention: false,
|
|
7062
7596
|
};
|
|
7063
|
-
|
|
7597
|
+
/**
|
|
7598
|
+
* The Editor interface provides properties and methods for rendering and manipulating the editor.
|
|
7599
|
+
*/
|
|
7064
7600
|
class Editor {
|
|
7065
7601
|
constructor(config) {
|
|
7066
|
-
|
|
7602
|
+
/**
|
|
7603
|
+
* A string that has not yet been saved to the history.
|
|
7604
|
+
*/
|
|
7067
7605
|
this.unsavedInputData = '';
|
|
7068
|
-
|
|
7606
|
+
/**
|
|
7607
|
+
* The number of input event calls before saving to the history.
|
|
7608
|
+
*/
|
|
7069
7609
|
this.unsavedInputCount = 0;
|
|
7070
|
-
|
|
7610
|
+
/**
|
|
7611
|
+
* The state of the current selection.
|
|
7612
|
+
*/
|
|
7071
7613
|
this.state = {
|
|
7072
7614
|
activeItems: [],
|
|
7073
7615
|
disabledNameMap: new Map(),
|
|
7074
7616
|
selectedNameMap: new Map(),
|
|
7075
7617
|
selectedValuesMap: new Map(),
|
|
7076
7618
|
};
|
|
7077
|
-
|
|
7619
|
+
/**
|
|
7620
|
+
* The functions for unmounting plugins.
|
|
7621
|
+
*/
|
|
7078
7622
|
this.unmountPluginMap = new Map();
|
|
7079
|
-
|
|
7623
|
+
/**
|
|
7624
|
+
* An EventEmitter object used to set up events.
|
|
7625
|
+
*/
|
|
7080
7626
|
this.event = new EventEmitter();
|
|
7081
|
-
|
|
7082
|
-
|
|
7083
|
-
|
|
7627
|
+
/**
|
|
7628
|
+
* A boolean value indicating whether a user is entering a character using a text composition system such as an Input Method Editor (IME).
|
|
7629
|
+
*/
|
|
7084
7630
|
this.isComposing = false;
|
|
7085
|
-
|
|
7631
|
+
/**
|
|
7632
|
+
* A pop-up component which is currently displayed, such as LinkPopup, MentionMenu, and SlashMenu.
|
|
7633
|
+
*/
|
|
7086
7634
|
this.popup = null;
|
|
7087
7635
|
this.copyListener = event => {
|
|
7088
7636
|
const range = this.selection.getCurrentRange();
|
|
@@ -7122,7 +7670,9 @@ class Editor {
|
|
|
7122
7670
|
}, 1, {
|
|
7123
7671
|
immediate: true,
|
|
7124
7672
|
});
|
|
7125
|
-
|
|
7673
|
+
/**
|
|
7674
|
+
* Updates the classes of all boxes when the current selection is changed.
|
|
7675
|
+
*/
|
|
7126
7676
|
this.updateBoxSelectionStyle = debounce(() => {
|
|
7127
7677
|
// The editor has been unmounted.
|
|
7128
7678
|
if (this.root.first().length === 0) {
|
|
@@ -7170,7 +7720,9 @@ class Editor {
|
|
|
7170
7720
|
}, 50, {
|
|
7171
7721
|
immediate: true,
|
|
7172
7722
|
});
|
|
7173
|
-
|
|
7723
|
+
/**
|
|
7724
|
+
* Triggers the statechange event when the current selection is changed.
|
|
7725
|
+
*/
|
|
7174
7726
|
this.emitStateChangeEvent = debounce(() => {
|
|
7175
7727
|
const commandNames = this.command.getNames();
|
|
7176
7728
|
let activeItems = this.selection.getActiveItems();
|
|
@@ -7243,7 +7795,9 @@ class Editor {
|
|
|
7243
7795
|
this.keystroke = new Keystroke(this.container);
|
|
7244
7796
|
editors.set(this.container.id, this);
|
|
7245
7797
|
}
|
|
7246
|
-
|
|
7798
|
+
/**
|
|
7799
|
+
* Adds or Removes a placeholder class.
|
|
7800
|
+
*/
|
|
7247
7801
|
togglePlaceholderClass(value) {
|
|
7248
7802
|
value = denormalizeValue(value);
|
|
7249
7803
|
const className = 'lake-placeholder';
|
|
@@ -7254,7 +7808,9 @@ class Editor {
|
|
|
7254
7808
|
this.container.removeClass(className);
|
|
7255
7809
|
}
|
|
7256
7810
|
}
|
|
7257
|
-
|
|
7811
|
+
/**
|
|
7812
|
+
* Moves the input text from box strip to normal position.
|
|
7813
|
+
*/
|
|
7258
7814
|
moveBoxStripText() {
|
|
7259
7815
|
const selection = this.selection;
|
|
7260
7816
|
const range = selection.range;
|
|
@@ -7286,12 +7842,16 @@ class Editor {
|
|
|
7286
7842
|
stripNode.html('<br />');
|
|
7287
7843
|
selection.insertContents(document.createTextNode(text));
|
|
7288
7844
|
}
|
|
7289
|
-
|
|
7845
|
+
/**
|
|
7846
|
+
* Resets the value of "unsavedInputData" property.
|
|
7847
|
+
*/
|
|
7290
7848
|
resetUnsavedInputData() {
|
|
7291
7849
|
this.unsavedInputData = '';
|
|
7292
7850
|
this.unsavedInputCount = 0;
|
|
7293
7851
|
}
|
|
7294
|
-
|
|
7852
|
+
/**
|
|
7853
|
+
* Handles input event.
|
|
7854
|
+
*/
|
|
7295
7855
|
handleInputEvent(event) {
|
|
7296
7856
|
var _a;
|
|
7297
7857
|
this.selection.updateByRange();
|
|
@@ -7306,7 +7866,7 @@ class Editor {
|
|
|
7306
7866
|
}
|
|
7307
7867
|
const inputType = event instanceof CompositionEvent ? 'insertText' : event.inputType;
|
|
7308
7868
|
if (inputType === 'insertText') {
|
|
7309
|
-
const inputData = (_a = event.data) !== null && _a !==
|
|
7869
|
+
const inputData = (_a = event.data) !== null && _a !== void 0 ? _a : '';
|
|
7310
7870
|
if (inputData.length > 1) {
|
|
7311
7871
|
this.history.save({
|
|
7312
7872
|
inputType: 'insertText',
|
|
@@ -7333,7 +7893,9 @@ class Editor {
|
|
|
7333
7893
|
}
|
|
7334
7894
|
this.history.save();
|
|
7335
7895
|
}
|
|
7336
|
-
|
|
7896
|
+
/**
|
|
7897
|
+
* Binds events for inputting text.
|
|
7898
|
+
*/
|
|
7337
7899
|
bindInputEvents() {
|
|
7338
7900
|
this.container.on('compositionstart', () => {
|
|
7339
7901
|
this.isComposing = true;
|
|
@@ -7352,7 +7914,9 @@ class Editor {
|
|
|
7352
7914
|
this.handleInputEvent(event);
|
|
7353
7915
|
});
|
|
7354
7916
|
}
|
|
7355
|
-
|
|
7917
|
+
/**
|
|
7918
|
+
* Removes all unused box instances.
|
|
7919
|
+
*/
|
|
7356
7920
|
removeBoxGarbage() {
|
|
7357
7921
|
const instanceMap = getInstanceMap(this.container.id);
|
|
7358
7922
|
for (const box of instanceMap.values()) {
|
|
@@ -7362,7 +7926,9 @@ class Editor {
|
|
|
7362
7926
|
}
|
|
7363
7927
|
}
|
|
7364
7928
|
}
|
|
7365
|
-
|
|
7929
|
+
/**
|
|
7930
|
+
* Binds events for history.
|
|
7931
|
+
*/
|
|
7366
7932
|
bindHistoryEvents() {
|
|
7367
7933
|
const executeCommonMethods = (value) => {
|
|
7368
7934
|
if (this.fixContent()) {
|
|
@@ -7396,11 +7962,15 @@ class Editor {
|
|
|
7396
7962
|
}
|
|
7397
7963
|
});
|
|
7398
7964
|
}
|
|
7399
|
-
|
|
7965
|
+
/**
|
|
7966
|
+
* Returns translation functions for the specified language.
|
|
7967
|
+
*/
|
|
7400
7968
|
get locale() {
|
|
7401
7969
|
return i18nObject(this.config.lang);
|
|
7402
7970
|
}
|
|
7403
|
-
|
|
7971
|
+
/**
|
|
7972
|
+
* Sets the default config for the specified plugin.
|
|
7973
|
+
*/
|
|
7404
7974
|
setPluginConfig(name, config) {
|
|
7405
7975
|
if (typeof this.config[name] !== 'object') {
|
|
7406
7976
|
this.config[name] = {};
|
|
@@ -7411,7 +7981,9 @@ class Editor {
|
|
|
7411
7981
|
}
|
|
7412
7982
|
}
|
|
7413
7983
|
}
|
|
7414
|
-
|
|
7984
|
+
/**
|
|
7985
|
+
* Fixes incorrect content, such as adding paragraphs for void elements or removing empty tags.
|
|
7986
|
+
*/
|
|
7415
7987
|
fixContent() {
|
|
7416
7988
|
const range = this.selection.range;
|
|
7417
7989
|
const cellNode = range.commonAncestor.closest('td');
|
|
@@ -7446,7 +8018,9 @@ class Editor {
|
|
|
7446
8018
|
range.adjustBr();
|
|
7447
8019
|
return changed;
|
|
7448
8020
|
}
|
|
7449
|
-
|
|
8021
|
+
/**
|
|
8022
|
+
* Renders all boxes that haven't been rendered yet.
|
|
8023
|
+
*/
|
|
7450
8024
|
renderBoxes() {
|
|
7451
8025
|
this.removeBoxGarbage();
|
|
7452
8026
|
const container = this.container;
|
|
@@ -7460,7 +8034,9 @@ class Editor {
|
|
|
7460
8034
|
box.render();
|
|
7461
8035
|
});
|
|
7462
8036
|
}
|
|
7463
|
-
|
|
8037
|
+
/**
|
|
8038
|
+
* Scrolls to the cursor.
|
|
8039
|
+
*/
|
|
7464
8040
|
scrollToCursor() {
|
|
7465
8041
|
const range = this.selection.range;
|
|
7466
8042
|
if (range.isBox) {
|
|
@@ -7493,7 +8069,9 @@ class Editor {
|
|
|
7493
8069
|
});
|
|
7494
8070
|
artificialCursor.remove();
|
|
7495
8071
|
}
|
|
7496
|
-
|
|
8072
|
+
/**
|
|
8073
|
+
* Checks whether the editor has focus.
|
|
8074
|
+
*/
|
|
7497
8075
|
hasFocus() {
|
|
7498
8076
|
const activeElement = document.activeElement;
|
|
7499
8077
|
if (!activeElement) {
|
|
@@ -7501,7 +8079,9 @@ class Editor {
|
|
|
7501
8079
|
}
|
|
7502
8080
|
return query(activeElement).closest('.lake-container').get(0) === this.container.get(0);
|
|
7503
8081
|
}
|
|
7504
|
-
|
|
8082
|
+
/**
|
|
8083
|
+
* Sets focus on the editor.
|
|
8084
|
+
*/
|
|
7505
8085
|
focus() {
|
|
7506
8086
|
const range = this.selection.range;
|
|
7507
8087
|
if (this.container.contains(range.commonAncestor) && range.isBox) {
|
|
@@ -7509,11 +8089,15 @@ class Editor {
|
|
|
7509
8089
|
}
|
|
7510
8090
|
this.container.focus();
|
|
7511
8091
|
}
|
|
7512
|
-
|
|
8092
|
+
/**
|
|
8093
|
+
* Removes focus from the editor.
|
|
8094
|
+
*/
|
|
7513
8095
|
blur() {
|
|
7514
8096
|
this.container.blur();
|
|
7515
8097
|
}
|
|
7516
|
-
|
|
8098
|
+
/**
|
|
8099
|
+
* Sets the specified content to the editor.
|
|
8100
|
+
*/
|
|
7517
8101
|
setValue(value) {
|
|
7518
8102
|
value = normalizeValue(value);
|
|
7519
8103
|
const htmlParser = new HTMLParser(value);
|
|
@@ -7524,14 +8108,18 @@ class Editor {
|
|
|
7524
8108
|
this.renderBoxes();
|
|
7525
8109
|
this.selection.updateByBookmark();
|
|
7526
8110
|
}
|
|
7527
|
-
|
|
8111
|
+
/**
|
|
8112
|
+
* Returns the editor's content.
|
|
8113
|
+
*/
|
|
7528
8114
|
getValue() {
|
|
7529
8115
|
const item = this.history.cloneContainer();
|
|
7530
8116
|
let value = new HTMLParser(item).getHTML();
|
|
7531
8117
|
value = denormalizeValue(value);
|
|
7532
8118
|
return value;
|
|
7533
8119
|
}
|
|
7534
|
-
|
|
8120
|
+
/**
|
|
8121
|
+
* Renders an editing area and sets default content to it.
|
|
8122
|
+
*/
|
|
7535
8123
|
render() {
|
|
7536
8124
|
const value = normalizeValue(this.config.value);
|
|
7537
8125
|
const htmlParser = new HTMLParser(value);
|
|
@@ -7563,7 +8151,9 @@ class Editor {
|
|
|
7563
8151
|
this.bindHistoryEvents();
|
|
7564
8152
|
}
|
|
7565
8153
|
}
|
|
7566
|
-
|
|
8154
|
+
/**
|
|
8155
|
+
* Destroys the editor.
|
|
8156
|
+
*/
|
|
7567
8157
|
unmount() {
|
|
7568
8158
|
// Executes delayed executions immediately.
|
|
7569
8159
|
this.updateSelectionRange.flush();
|
|
@@ -7598,11 +8188,17 @@ class Editor {
|
|
|
7598
8188
|
}
|
|
7599
8189
|
}
|
|
7600
8190
|
}
|
|
7601
|
-
|
|
8191
|
+
/**
|
|
8192
|
+
* The current version of Lake.
|
|
8193
|
+
*/
|
|
7602
8194
|
Editor.version = version;
|
|
7603
|
-
|
|
8195
|
+
/**
|
|
8196
|
+
* A BoxManager object that manages the box components.
|
|
8197
|
+
*/
|
|
7604
8198
|
Editor.box = new BoxManager();
|
|
7605
|
-
|
|
8199
|
+
/**
|
|
8200
|
+
* A Plugin object that manages a collection of plugins.
|
|
8201
|
+
*/
|
|
7606
8202
|
Editor.plugin = new Plugin();
|
|
7607
8203
|
|
|
7608
8204
|
var copy = (editor) => {
|
|
@@ -7975,18 +8571,18 @@ var drop = (editor) => {
|
|
|
7975
8571
|
let targetBlcokRect = targetBlock.get(0).getBoundingClientRect();
|
|
7976
8572
|
dropPosition = 'bottom';
|
|
7977
8573
|
let left = targetBlcokRect.x - containerRect.x;
|
|
7978
|
-
let top = targetBlcokRect.y + targetBlcokRect.height - containerRect.y + (parseInt(targetBlock.computedCSS('margin-bottom'), 10) / 2);
|
|
8574
|
+
let top = targetBlcokRect.y + targetBlcokRect.height - containerRect.y + (Number.parseInt(targetBlock.computedCSS('margin-bottom'), 10) / 2);
|
|
7979
8575
|
if (dragEvent.clientY < targetBlcokRect.y + (targetBlcokRect.height / 2)) {
|
|
7980
8576
|
const prevBlock = targetBlock.prev();
|
|
7981
|
-
if (prevBlock.length > 0 && prevBlock.isBlock || prevBlock.isBlockBox) {
|
|
8577
|
+
if ((prevBlock.length > 0 && prevBlock.isBlock) || prevBlock.isBlockBox) {
|
|
7982
8578
|
targetBlock = prevBlock;
|
|
7983
8579
|
targetBlcokRect = targetBlock.get(0).getBoundingClientRect();
|
|
7984
8580
|
left = targetBlcokRect.x - containerRect.x;
|
|
7985
|
-
top = targetBlcokRect.y + targetBlcokRect.height - containerRect.y + (parseInt(targetBlock.computedCSS('margin-bottom'), 10) / 2);
|
|
8581
|
+
top = targetBlcokRect.y + targetBlcokRect.height - containerRect.y + (Number.parseInt(targetBlock.computedCSS('margin-bottom'), 10) / 2);
|
|
7986
8582
|
}
|
|
7987
8583
|
else {
|
|
7988
8584
|
dropPosition = 'top';
|
|
7989
|
-
top = targetBlcokRect.y - containerRect.y - (parseInt(editor.container.computedCSS('padding-top'), 10) / 2);
|
|
8585
|
+
top = targetBlcokRect.y - containerRect.y - (Number.parseInt(editor.container.computedCSS('padding-top'), 10) / 2);
|
|
7990
8586
|
}
|
|
7991
8587
|
}
|
|
7992
8588
|
dropIndication.css({
|
|
@@ -8384,8 +8980,10 @@ function insertColumn(range, direction) {
|
|
|
8384
8980
|
if (direction === 'right') {
|
|
8385
8981
|
const currentRowCells = tableMap[currentRowIndex];
|
|
8386
8982
|
columnIndex++;
|
|
8387
|
-
|
|
8388
|
-
columnIndex
|
|
8983
|
+
if (currentRowCells) {
|
|
8984
|
+
while (currentCell === currentRowCells[columnIndex]) {
|
|
8985
|
+
columnIndex++;
|
|
8986
|
+
}
|
|
8389
8987
|
}
|
|
8390
8988
|
}
|
|
8391
8989
|
debug(`insertColumn: rows ${table.rows.length}, column ${columnIndex}, ${direction}`);
|
|
@@ -9470,7 +10068,7 @@ class LinkPopup {
|
|
|
9470
10068
|
}
|
|
9471
10069
|
// Writes the specified text to the system clipboard
|
|
9472
10070
|
writeClipboardText(text) {
|
|
9473
|
-
return __awaiter(this,
|
|
10071
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
9474
10072
|
let error = false;
|
|
9475
10073
|
try {
|
|
9476
10074
|
if (window.LAKE_TEST) {
|
|
@@ -9792,9 +10390,9 @@ var link = (editor) => {
|
|
|
9792
10390
|
return;
|
|
9793
10391
|
}
|
|
9794
10392
|
const linkNode = targetNode.closest('a');
|
|
9795
|
-
if (linkNode.length === 0
|
|
9796
|
-
!editor.container.contains(linkNode)
|
|
9797
|
-
linkNode.closest('lake-box').length > 0) {
|
|
10393
|
+
if (linkNode.length === 0
|
|
10394
|
+
|| !editor.container.contains(linkNode)
|
|
10395
|
+
|| linkNode.closest('lake-box').length > 0) {
|
|
9798
10396
|
if (!popup.visible) {
|
|
9799
10397
|
return;
|
|
9800
10398
|
}
|
|
@@ -9854,81 +10452,27 @@ var hr = (editor) => {
|
|
|
9854
10452
|
});
|
|
9855
10453
|
};
|
|
9856
10454
|
|
|
9857
|
-
const config = {
|
|
9858
|
-
comment: '#57606a',
|
|
9859
|
-
name: '#444d56',
|
|
9860
|
-
variableName: '#953800',
|
|
9861
|
-
typeName: '#0550ae',
|
|
9862
|
-
propertyName: '#444d56',
|
|
9863
|
-
className: '#24292e',
|
|
9864
|
-
labelName: '#005cc5',
|
|
9865
|
-
namespace: '#0550ae',
|
|
9866
|
-
macroName: '#444d56',
|
|
9867
|
-
literal: '#444d56',
|
|
9868
|
-
string: '#0a3069',
|
|
9869
|
-
number: '#0550ae',
|
|
9870
|
-
bool: '#0550ae',
|
|
9871
|
-
regexp: '#116329',
|
|
9872
|
-
color: '#0550ae',
|
|
9873
|
-
keyword: '#cf222e',
|
|
9874
|
-
modifier: '#24292f',
|
|
9875
|
-
operator: '#cf222e',
|
|
9876
|
-
bracket: '#57606a',
|
|
9877
|
-
content: '#57606a',
|
|
9878
|
-
meta: '#8250df',
|
|
9879
|
-
heading: '#0550ae',
|
|
9880
|
-
invalid: '#f6f8fa',
|
|
9881
|
-
definition: '#cf222e',
|
|
9882
|
-
constant: '#0550ae',
|
|
9883
|
-
function: '#005cc5',
|
|
9884
|
-
standard: '#444d56',
|
|
9885
|
-
special: '#444d56',
|
|
9886
|
-
};
|
|
9887
10455
|
// https://lezer.codemirror.net/docs/ref/#highlight.tags
|
|
9888
|
-
function getHighlightStyle(CodeMirror) {
|
|
10456
|
+
function getHighlightStyle(CodeMirror, colors) {
|
|
9889
10457
|
const { HighlightStyle, tags } = CodeMirror;
|
|
9890
10458
|
return HighlightStyle.define([
|
|
9891
|
-
{ tag: [tags.
|
|
9892
|
-
{ tag: [tags.name], color:
|
|
9893
|
-
{ tag: [tags.variableName, tags.
|
|
9894
|
-
{ tag: [tags.
|
|
9895
|
-
{ tag: [tags.
|
|
9896
|
-
{ tag: [tags.className], color:
|
|
9897
|
-
{ tag: [tags.
|
|
9898
|
-
{ tag: [tags.
|
|
9899
|
-
{ tag: [tags.
|
|
9900
|
-
{ tag: [tags.
|
|
9901
|
-
{ tag: [tags.
|
|
9902
|
-
{ tag: [tags.
|
|
9903
|
-
{ tag: [tags.
|
|
9904
|
-
{ tag: [tags.
|
|
9905
|
-
{ tag: [tags.
|
|
9906
|
-
{ tag: [
|
|
9907
|
-
|
|
9908
|
-
tags.definitionKeyword, tags.moduleKeyword,
|
|
9909
|
-
], color: config.keyword },
|
|
9910
|
-
{ tag: [tags.modifier], color: config.modifier },
|
|
9911
|
-
{ tag: [
|
|
9912
|
-
tags.operator, tags.derefOperator, tags.arithmeticOperator, tags.logicOperator, tags.bitwiseOperator,
|
|
9913
|
-
tags.compareOperator, tags.updateOperator, tags.definitionOperator, tags.typeOperator, tags.controlOperator,
|
|
9914
|
-
], color: config.operator },
|
|
9915
|
-
{ tag: [
|
|
9916
|
-
tags.punctuation, tags.separator, tags.bracket, tags.angleBracket, tags.squareBracket,
|
|
9917
|
-
tags.paren, tags.brace, tags.contentSeparator,
|
|
9918
|
-
], color: config.bracket },
|
|
9919
|
-
{ tag: [tags.content], color: config.content },
|
|
9920
|
-
{ tag: [tags.meta, tags.documentMeta, tags.annotation, tags.processingInstruction], color: config.meta },
|
|
9921
|
-
{ tag: tags.heading, fontWeight: 'bold', color: config.heading },
|
|
9922
|
-
{ tag: tags.strong, fontWeight: 'bold' },
|
|
9923
|
-
{ tag: tags.emphasis, fontStyle: 'italic' },
|
|
9924
|
-
{ tag: tags.link, textDecoration: 'underline' },
|
|
9925
|
-
{ tag: tags.strikethrough, textDecoration: 'line-through' },
|
|
9926
|
-
{ tag: [tags.invalid, tags.inserted, tags.deleted, tags.changed], color: config.invalid },
|
|
9927
|
-
{ tag: [tags.definition(tags.name)], color: config.definition },
|
|
9928
|
-
{ tag: [tags.constant(tags.name)], color: config.constant },
|
|
9929
|
-
{ tag: [tags.function(tags.variableName)], color: config.function },
|
|
9930
|
-
{ tag: [tags.standard(tags.name)], color: config.standard },
|
|
9931
|
-
{ tag: [tags.special(tags.variableName)], color: config.special },
|
|
10459
|
+
{ tag: [tags.keyword], color: colors.keyword },
|
|
10460
|
+
{ tag: [tags.name, tags.deleted, tags.character, tags.propertyName, tags.macroName], color: colors.name },
|
|
10461
|
+
{ tag: [tags.function(tags.variableName), tags.labelName], color: colors.function },
|
|
10462
|
+
{ tag: [tags.constant(tags.name), tags.color, tags.standard(tags.name)], color: colors.constant },
|
|
10463
|
+
{ tag: [tags.definition(tags.name), tags.separator], color: colors.definition },
|
|
10464
|
+
{ tag: [tags.typeName, tags.className, tags.changed, tags.annotation, tags.modifier, tags.self, tags.namespace], color: colors.type },
|
|
10465
|
+
{ tag: [tags.operator, tags.operatorKeyword, tags.url, tags.escape, tags.regexp, tags.link, tags.special(tags.string)], color: colors.operator },
|
|
10466
|
+
{ tag: [tags.comment, tags.meta], color: colors.comment },
|
|
10467
|
+
{ tag: [tags.strong], fontWeight: 'bold' },
|
|
10468
|
+
{ tag: [tags.emphasis], fontStyle: 'italic' },
|
|
10469
|
+
{ tag: [tags.strikethrough], textDecoration: 'line-through' },
|
|
10470
|
+
{ tag: [tags.link], textDecoration: 'underline' },
|
|
10471
|
+
{ tag: [tags.heading], fontWeight: 'bold', color: colors.heading },
|
|
10472
|
+
{ tag: [tags.bool, tags.atom, tags.special(tags.variableName)], color: colors.boolean },
|
|
10473
|
+
{ tag: [tags.string, tags.processingInstruction, tags.inserted], color: colors.string },
|
|
10474
|
+
{ tag: [tags.number], color: colors.number },
|
|
10475
|
+
{ tag: [tags.invalid], color: colors.invalid },
|
|
9932
10476
|
]);
|
|
9933
10477
|
}
|
|
9934
10478
|
var codeBlockBox = {
|
|
@@ -9964,8 +10508,8 @@ var codeBlockBox = {
|
|
|
9964
10508
|
}
|
|
9965
10509
|
const { EditorState, Compartment, EditorView, keymap, history, defaultKeymap, historyKeymap, indentWithTab, syntaxHighlighting, } = CodeMirror;
|
|
9966
10510
|
const defaultLangItems = CodeMirror.langItems;
|
|
9967
|
-
const
|
|
9968
|
-
const langItems = defaultLangItems.filter((item) =>
|
|
10511
|
+
const { langList, defaultLang, colors } = editor.config.codeBlock;
|
|
10512
|
+
const langItems = defaultLangItems.filter((item) => langList.indexOf(item.value) >= 0);
|
|
9969
10513
|
// language menu items
|
|
9970
10514
|
const langItemMap = new Map();
|
|
9971
10515
|
for (const item of langItems) {
|
|
@@ -9992,7 +10536,7 @@ var codeBlockBox = {
|
|
|
9992
10536
|
});
|
|
9993
10537
|
const codeEditor = new EditorView({
|
|
9994
10538
|
parent: codeBlockNativeNode,
|
|
9995
|
-
doc: (_a = boxValue.code) !== null && _a !==
|
|
10539
|
+
doc: (_a = boxValue.code) !== null && _a !== void 0 ? _a : '',
|
|
9996
10540
|
extensions: [
|
|
9997
10541
|
EditorState.readOnly.of(editor.readonly),
|
|
9998
10542
|
EditorView.editable.of(!editor.readonly),
|
|
@@ -10002,7 +10546,7 @@ var codeBlockBox = {
|
|
|
10002
10546
|
...historyKeymap,
|
|
10003
10547
|
indentWithTab,
|
|
10004
10548
|
]),
|
|
10005
|
-
syntaxHighlighting(getHighlightStyle(CodeMirror)),
|
|
10549
|
+
syntaxHighlighting(getHighlightStyle(CodeMirror, colors)),
|
|
10006
10550
|
language.of(langItem && langItem.component ? langItem.component() : []),
|
|
10007
10551
|
updateListener,
|
|
10008
10552
|
],
|
|
@@ -10012,7 +10556,7 @@ var codeBlockBox = {
|
|
|
10012
10556
|
root: rootNode,
|
|
10013
10557
|
name: 'langType',
|
|
10014
10558
|
downIcon: icons.get('down'),
|
|
10015
|
-
defaultValue: langItem ? boxValue.lang :
|
|
10559
|
+
defaultValue: langItem ? boxValue.lang : defaultLang,
|
|
10016
10560
|
tooltip: editor.locale.codeBlock.langType(),
|
|
10017
10561
|
location: 'global',
|
|
10018
10562
|
menuType: 'list',
|
|
@@ -10066,6 +10610,21 @@ const langList = [
|
|
|
10066
10610
|
'xml',
|
|
10067
10611
|
'yaml',
|
|
10068
10612
|
];
|
|
10613
|
+
const colors = {
|
|
10614
|
+
keyword: 'var(--lake-code-highlight-keyword)',
|
|
10615
|
+
name: 'var(--lake-code-highlight-name)',
|
|
10616
|
+
function: 'var(--lake-code-highlight-function)',
|
|
10617
|
+
constant: 'var(--lake-code-highlight-constant)',
|
|
10618
|
+
definition: 'var(--lake-code-highlight-definition)',
|
|
10619
|
+
type: 'var(--lake-code-highlight-type)',
|
|
10620
|
+
operator: 'var(--lake-code-highlight-operator)',
|
|
10621
|
+
comment: 'var(--lake-code-highlight-comment)',
|
|
10622
|
+
heading: 'var(--lake-code-highlight-heading)',
|
|
10623
|
+
boolean: 'var(--lake-code-highlight-boolean)',
|
|
10624
|
+
string: 'var(--lake-code-highlight-string)',
|
|
10625
|
+
number: 'var(--lake-code-highlight-number)',
|
|
10626
|
+
invalid: 'var(--lake-code-highlight-invalid)',
|
|
10627
|
+
};
|
|
10069
10628
|
var codeBlock = (editor) => {
|
|
10070
10629
|
if (!window.LakeCodeMirror) {
|
|
10071
10630
|
return;
|
|
@@ -10073,6 +10632,7 @@ var codeBlock = (editor) => {
|
|
|
10073
10632
|
editor.setPluginConfig('codeBlock', {
|
|
10074
10633
|
langList,
|
|
10075
10634
|
defaultLang: 'text',
|
|
10635
|
+
colors,
|
|
10076
10636
|
});
|
|
10077
10637
|
if (editor.readonly) {
|
|
10078
10638
|
return;
|
|
@@ -10091,7 +10651,7 @@ class CornerToolbar {
|
|
|
10091
10651
|
constructor(config) {
|
|
10092
10652
|
this.config = config;
|
|
10093
10653
|
this.locale = this.config.locale || i18nObject('en-US');
|
|
10094
|
-
this.root = config.root;
|
|
10654
|
+
this.root = query(config.root);
|
|
10095
10655
|
this.container = query('<div class="lake-corner-toolbar" />');
|
|
10096
10656
|
}
|
|
10097
10657
|
appendButton(item) {
|
|
@@ -10125,8 +10685,8 @@ class CornerToolbar {
|
|
|
10125
10685
|
class Resizer {
|
|
10126
10686
|
constructor(config) {
|
|
10127
10687
|
this.config = config;
|
|
10128
|
-
this.root = config.root;
|
|
10129
|
-
this.target = config.target;
|
|
10688
|
+
this.root = query(config.root);
|
|
10689
|
+
this.target = query(config.target);
|
|
10130
10690
|
this.container = query(template `
|
|
10131
10691
|
<div class="lake-resizer">
|
|
10132
10692
|
<div class="lake-resizer-top-left"></div>
|
|
@@ -10344,7 +10904,7 @@ function renderFloatingToolbar(box) {
|
|
|
10344
10904
|
}
|
|
10345
10905
|
// Loads an image and get its width and height.
|
|
10346
10906
|
function getImageInfo(url) {
|
|
10347
|
-
return __awaiter(this,
|
|
10907
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
10348
10908
|
const node = query('<img />');
|
|
10349
10909
|
node.css({
|
|
10350
10910
|
position: 'absolute',
|
|
@@ -10534,7 +11094,7 @@ function renderCaption(box) {
|
|
|
10534
11094
|
}
|
|
10535
11095
|
// Displays error icon and filename.
|
|
10536
11096
|
function renderError$1(box) {
|
|
10537
|
-
return __awaiter(this,
|
|
11097
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
10538
11098
|
const editor = box.getEditor();
|
|
10539
11099
|
const boxContainer = box.getContainer();
|
|
10540
11100
|
const value = box.value;
|
|
@@ -10577,7 +11137,7 @@ function renderError$1(box) {
|
|
|
10577
11137
|
}
|
|
10578
11138
|
// Displays an image with uplaoding progress.
|
|
10579
11139
|
function renderUploading(box) {
|
|
10580
|
-
return __awaiter(this,
|
|
11140
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
10581
11141
|
const editor = box.getEditor();
|
|
10582
11142
|
const boxContainer = box.getContainer();
|
|
10583
11143
|
const value = box.value;
|
|
@@ -10647,7 +11207,7 @@ function renderUploading(box) {
|
|
|
10647
11207
|
}
|
|
10648
11208
|
// Displays an image that can be previewed or removed.
|
|
10649
11209
|
function renderDone(box) {
|
|
10650
|
-
return __awaiter(this,
|
|
11210
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
10651
11211
|
const editor = box.getEditor();
|
|
10652
11212
|
const boxContainer = box.getContainer();
|
|
10653
11213
|
const value = box.value;
|
|
@@ -10801,7 +11361,7 @@ var imageBox = {
|
|
|
10801
11361
|
var image = (editor) => {
|
|
10802
11362
|
editor.setPluginConfig('image', {
|
|
10803
11363
|
requestMethod: 'POST',
|
|
10804
|
-
requestTypes: ['image/gif', 'image/jpeg', 'image/png', 'image/svg+xml'],
|
|
11364
|
+
requestTypes: ['image/gif', 'image/jpeg', 'image/png', 'image/svg+xml', 'image/webp'],
|
|
10805
11365
|
});
|
|
10806
11366
|
if (editor.readonly) {
|
|
10807
11367
|
return;
|
|
@@ -10833,7 +11393,7 @@ var image = (editor) => {
|
|
|
10833
11393
|
};
|
|
10834
11394
|
|
|
10835
11395
|
function getVideoId(url) {
|
|
10836
|
-
const result = /\w
|
|
11396
|
+
const result = /\w+$/.exec(url || '');
|
|
10837
11397
|
return result ? result[0] : '';
|
|
10838
11398
|
}
|
|
10839
11399
|
function appendButtonGroup(box) {
|
|
@@ -11040,7 +11600,7 @@ function setFloatingToolbar(box) {
|
|
|
11040
11600
|
box.setToolbar(items);
|
|
11041
11601
|
}
|
|
11042
11602
|
function appendContent(rootNode, box) {
|
|
11043
|
-
return __awaiter(this,
|
|
11603
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
11044
11604
|
const value = box.value;
|
|
11045
11605
|
const infoNode = query(template `
|
|
11046
11606
|
<div class="lake-file-info">
|
|
@@ -11112,6 +11672,7 @@ var file = (editor) => {
|
|
|
11112
11672
|
'image/jpeg',
|
|
11113
11673
|
'image/png',
|
|
11114
11674
|
'image/svg+xml',
|
|
11675
|
+
'image/webp',
|
|
11115
11676
|
'text/plain',
|
|
11116
11677
|
'text/html',
|
|
11117
11678
|
'application/pdf',
|
|
@@ -11283,7 +11844,7 @@ var specialCharacter = (editor) => {
|
|
|
11283
11844
|
});
|
|
11284
11845
|
};
|
|
11285
11846
|
|
|
11286
|
-
|
|
11847
|
+
function emptyCallback$2() { }
|
|
11287
11848
|
// The Menu class represents a list of options for selecting an item.
|
|
11288
11849
|
class Menu {
|
|
11289
11850
|
constructor(config) {
|
|
@@ -11303,27 +11864,29 @@ class Menu {
|
|
|
11303
11864
|
if (!isDownKey && !isUpKey && !isEnterKey) {
|
|
11304
11865
|
return;
|
|
11305
11866
|
}
|
|
11867
|
+
const nativeContainer = this.container.get(0);
|
|
11306
11868
|
const selectedItemNode = this.container.find('.lake-menu-item-selected');
|
|
11307
11869
|
if (selectedItemNode.length === 0) {
|
|
11870
|
+
event.preventDefault();
|
|
11308
11871
|
const firstItem = this.container.find('.lake-menu-item').eq(0);
|
|
11309
|
-
scrollToNode(firstItem, {
|
|
11310
|
-
behavior: 'instant',
|
|
11311
|
-
block: 'start',
|
|
11312
|
-
});
|
|
11313
11872
|
firstItem.addClass('lake-menu-item-selected');
|
|
11873
|
+
nativeContainer.scrollTop = 0;
|
|
11314
11874
|
return;
|
|
11315
11875
|
}
|
|
11316
11876
|
this.noMouseEvent = true;
|
|
11877
|
+
const paddingTop = Number.parseInt(this.container.computedCSS('padding-top'), 10) || 0;
|
|
11878
|
+
const paddingBottom = Number.parseInt(this.container.computedCSS('padding-bottom'), 10) || 0;
|
|
11317
11879
|
if (isDownKey) {
|
|
11318
11880
|
event.preventDefault();
|
|
11319
11881
|
let nextItemNode = selectedItemNode.next();
|
|
11320
11882
|
if (nextItemNode.length === 0) {
|
|
11321
11883
|
nextItemNode = this.container.find('.lake-menu-item').eq(0);
|
|
11322
11884
|
}
|
|
11323
|
-
|
|
11324
|
-
|
|
11325
|
-
|
|
11326
|
-
|
|
11885
|
+
const nextItemNativeNode = nextItemNode.get(0);
|
|
11886
|
+
const visible = visibleInfo(nextItemNode);
|
|
11887
|
+
if (visible.top !== 0 || visible.bottom !== 0) {
|
|
11888
|
+
nativeContainer.scrollTop = nextItemNativeNode.offsetTop - this.container.height() + nextItemNode.height() + paddingBottom;
|
|
11889
|
+
}
|
|
11327
11890
|
this.container.find('.lake-menu-item').removeClass('lake-menu-item-selected');
|
|
11328
11891
|
nextItemNode.addClass('lake-menu-item-selected');
|
|
11329
11892
|
}
|
|
@@ -11334,10 +11897,11 @@ class Menu {
|
|
|
11334
11897
|
const itemNode = this.container.find('.lake-menu-item');
|
|
11335
11898
|
prevItemNode = itemNode.eq(itemNode.length - 1);
|
|
11336
11899
|
}
|
|
11337
|
-
|
|
11338
|
-
|
|
11339
|
-
|
|
11340
|
-
|
|
11900
|
+
const prevItemNativeNode = prevItemNode.get(0);
|
|
11901
|
+
const visible = visibleInfo(prevItemNode);
|
|
11902
|
+
if (visible.top !== 0 || visible.bottom !== 0) {
|
|
11903
|
+
nativeContainer.scrollTop = prevItemNativeNode.offsetTop - paddingTop;
|
|
11904
|
+
}
|
|
11341
11905
|
this.container.find('.lake-menu-item').removeClass('lake-menu-item-selected');
|
|
11342
11906
|
prevItemNode.addClass('lake-menu-item-selected');
|
|
11343
11907
|
}
|
|
@@ -11516,7 +12080,7 @@ class Menu {
|
|
|
11516
12080
|
}
|
|
11517
12081
|
}
|
|
11518
12082
|
|
|
11519
|
-
|
|
12083
|
+
function emptyCallback$1() { }
|
|
11520
12084
|
// The MentionMenu class, inheriting from the Menu class, represents a list of users for selecting a user.
|
|
11521
12085
|
class MentionMenu extends Menu {
|
|
11522
12086
|
constructor(config) {
|
|
@@ -11529,7 +12093,7 @@ class MentionMenu extends Menu {
|
|
|
11529
12093
|
const itemNode = query(template `
|
|
11530
12094
|
<li>
|
|
11531
12095
|
<div class="lake-mention-avatar"></div>
|
|
11532
|
-
<div class="lake-mention-nickname">${(_a = item.nickname) !== null && _a !==
|
|
12096
|
+
<div class="lake-mention-nickname">${(_a = item.nickname) !== null && _a !== void 0 ? _a : item.name}</div>
|
|
11533
12097
|
<div class="lake-mention-name">(${item.name})</div>
|
|
11534
12098
|
</li>
|
|
11535
12099
|
`);
|
|
@@ -11551,10 +12115,10 @@ class MentionMenu extends Menu {
|
|
|
11551
12115
|
keyword = keyword.toLowerCase();
|
|
11552
12116
|
const items = [];
|
|
11553
12117
|
for (const item of this.items) {
|
|
11554
|
-
const nickname = (_a = item.nickname) !== null && _a !==
|
|
11555
|
-
if (item.name.toLowerCase().indexOf(keyword) >= 0
|
|
11556
|
-
nickname.toLowerCase().indexOf(keyword) >= 0
|
|
11557
|
-
nickname.replace(/\s+/g, '').indexOf(keyword) >= 0) {
|
|
12118
|
+
const nickname = (_a = item.nickname) !== null && _a !== void 0 ? _a : item.name;
|
|
12119
|
+
if (item.name.toLowerCase().indexOf(keyword) >= 0
|
|
12120
|
+
|| nickname.toLowerCase().indexOf(keyword) >= 0
|
|
12121
|
+
|| nickname.replace(/\s+/g, '').indexOf(keyword) >= 0) {
|
|
11558
12122
|
items.push(item);
|
|
11559
12123
|
}
|
|
11560
12124
|
}
|
|
@@ -11573,7 +12137,7 @@ var mentionBox = {
|
|
|
11573
12137
|
const url = getProfileUrl ? getProfileUrl(value) : '#';
|
|
11574
12138
|
const boxContainer = box.getContainer();
|
|
11575
12139
|
const rootNode = query(template `
|
|
11576
|
-
<div class="lake-mention"><a href="${url}">@${(_a = value.nickname) !== null && _a !==
|
|
12140
|
+
<div class="lake-mention"><a href="${url}">@${(_a = value.nickname) !== null && _a !== void 0 ? _a : value.name}</a></div>
|
|
11577
12141
|
`);
|
|
11578
12142
|
boxContainer.empty();
|
|
11579
12143
|
boxContainer.append(rootNode);
|
|
@@ -11776,7 +12340,7 @@ const blockItemListForSpaceKey = [
|
|
|
11776
12340
|
var _a;
|
|
11777
12341
|
return [
|
|
11778
12342
|
'heading',
|
|
11779
|
-
(_a = headingTypeMap.get(results[0])) !== null && _a !==
|
|
12343
|
+
(_a = headingTypeMap.get(results[0])) !== null && _a !== void 0 ? _a : 'h6',
|
|
11780
12344
|
];
|
|
11781
12345
|
},
|
|
11782
12346
|
},
|
|
@@ -11851,7 +12415,7 @@ const blockItemListForEnterKey = [
|
|
|
11851
12415
|
return [
|
|
11852
12416
|
'codeBlock',
|
|
11853
12417
|
{
|
|
11854
|
-
lang: (_a = shortLangTypeMap.get(results[1])) !== null && _a !==
|
|
12418
|
+
lang: (_a = shortLangTypeMap.get(results[1])) !== null && _a !== void 0 ? _a : results[1],
|
|
11855
12419
|
},
|
|
11856
12420
|
];
|
|
11857
12421
|
},
|
|
@@ -12272,8 +12836,8 @@ var backspaceKey = (editor) => {
|
|
|
12272
12836
|
const boxNode = range.commonAncestor.closest('lake-box');
|
|
12273
12837
|
const box = getBox(boxNode);
|
|
12274
12838
|
const boxValue = box.value;
|
|
12275
|
-
if (range.isCollapsed && box.name === 'codeBlock'
|
|
12276
|
-
(boxValue.code === undefined || boxValue.code === '')) {
|
|
12839
|
+
if (range.isCollapsed && box.name === 'codeBlock'
|
|
12840
|
+
&& (boxValue.code === undefined || boxValue.code === '')) {
|
|
12277
12841
|
event.preventDefault();
|
|
12278
12842
|
editor.selection.removeBox(box);
|
|
12279
12843
|
editor.history.save();
|
|
@@ -12391,9 +12955,9 @@ var backspaceKey = (editor) => {
|
|
|
12391
12955
|
editor.selection.setBlocks('<p />');
|
|
12392
12956
|
block = range.getBlocks()[0];
|
|
12393
12957
|
}
|
|
12394
|
-
if (block.css('margin-left') !== ''
|
|
12395
|
-
block.css('text-indent') !== ''
|
|
12396
|
-
block.attr('indent') !== '') {
|
|
12958
|
+
if (block.css('margin-left') !== ''
|
|
12959
|
+
|| block.css('text-indent') !== ''
|
|
12960
|
+
|| block.attr('indent') !== '') {
|
|
12397
12961
|
indentBlock(block, 'decrease');
|
|
12398
12962
|
editor.history.save();
|
|
12399
12963
|
return;
|
|
@@ -12922,7 +13486,7 @@ const slashItems = [
|
|
|
12922
13486
|
},
|
|
12923
13487
|
];
|
|
12924
13488
|
|
|
12925
|
-
|
|
13489
|
+
function emptyCallback() { }
|
|
12926
13490
|
const slashItemMap = new Map();
|
|
12927
13491
|
for (const item of slashItems) {
|
|
12928
13492
|
slashItemMap.set(item.name, item);
|
|
@@ -12991,10 +13555,10 @@ class SlashMenu extends Menu {
|
|
|
12991
13555
|
itemTitle = itemTitle.toLowerCase();
|
|
12992
13556
|
let itemTitleEnglish = typeof item.title === 'string' ? item.title : item.title(localeEnglish);
|
|
12993
13557
|
itemTitleEnglish = itemTitleEnglish.toLowerCase();
|
|
12994
|
-
if (itemTitle.indexOf(keyword) >= 0
|
|
12995
|
-
itemTitle.replace(/\s+/g, '').indexOf(keyword) >= 0
|
|
12996
|
-
itemTitleEnglish.indexOf(keyword) >= 0
|
|
12997
|
-
itemTitleEnglish.replace(/\s+/g, '').indexOf(keyword) >= 0) {
|
|
13558
|
+
if (itemTitle.indexOf(keyword) >= 0
|
|
13559
|
+
|| itemTitle.replace(/\s+/g, '').indexOf(keyword) >= 0
|
|
13560
|
+
|| itemTitleEnglish.indexOf(keyword) >= 0
|
|
13561
|
+
|| itemTitleEnglish.replace(/\s+/g, '').indexOf(keyword) >= 0) {
|
|
12998
13562
|
items.push(typeof name === 'string' ? item.name : name);
|
|
12999
13563
|
}
|
|
13000
13564
|
}
|
|
@@ -13091,9 +13655,9 @@ var slash = (editor) => {
|
|
|
13091
13655
|
return;
|
|
13092
13656
|
}
|
|
13093
13657
|
const block = range.getBlocks()[0];
|
|
13094
|
-
if (!block
|
|
13095
|
-
block.find('lake-box').length > 0
|
|
13096
|
-
block.closest('table').length > 0) {
|
|
13658
|
+
if (!block
|
|
13659
|
+
|| block.find('lake-box').length > 0
|
|
13660
|
+
|| block.closest('table').length > 0) {
|
|
13097
13661
|
return;
|
|
13098
13662
|
}
|
|
13099
13663
|
const keyword = getKeyword(block);
|
|
@@ -13195,5 +13759,5 @@ Editor.plugin.add('arrowKeys', arrowKeys);
|
|
|
13195
13759
|
Editor.plugin.add('escapeKey', escapeKey);
|
|
13196
13760
|
Editor.plugin.add('slash', slash);
|
|
13197
13761
|
|
|
13198
|
-
export { Box, Button, Dropdown, Editor, Fragment, HTMLParser, Nodes, Range, TextParser, Toolbar, addMark, deleteContents, icons, insertBlock, insertBookmark, insertBox, insertContents, query, removeBox, removeMark, setBlocks, splitBlock$1 as splitBlock, splitMarks, template, toBookmark, toHex };
|
|
13762
|
+
export { Box, Button, Dropdown, Editor, Fragment, HTMLParser, Nodes, Range, TextParser, Toolbar, addMark, deleteContents, getBox, icons, insertBlock, insertBookmark, insertBox, insertContents, query, removeBox, removeMark, setBlocks, splitBlock$1 as splitBlock, splitMarks, template, toBookmark, toHex };
|
|
13199
13763
|
//# sourceMappingURL=lake.js.map
|