@b9g/revise 0.1.1 → 0.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +67 -2
- package/_subseq.d.ts +18 -0
- package/contentarea.cjs +325 -412
- package/contentarea.cjs.map +1 -1
- package/contentarea.d.ts +29 -47
- package/contentarea.js +325 -412
- package/contentarea.js.map +1 -1
- package/edit.cjs +447 -187
- package/edit.cjs.map +1 -1
- package/edit.d.ts +71 -26
- package/edit.js +447 -187
- package/edit.js.map +1 -1
- package/history.cjs +3 -0
- package/history.cjs.map +1 -1
- package/history.d.ts +1 -1
- package/history.js +3 -0
- package/history.js.map +1 -1
- package/keyer.cjs +5 -7
- package/keyer.cjs.map +1 -1
- package/keyer.d.ts +1 -1
- package/keyer.js +5 -7
- package/keyer.js.map +1 -1
- package/package.json +16 -42
- package/subseq.cjs +0 -251
- package/subseq.cjs.map +0 -1
- package/subseq.d.ts +0 -62
- package/subseq.js +0 -248
- package/subseq.js.map +0 -1
package/contentarea.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"contentarea.cjs","sources":["../src/contentarea.ts"],"sourcesContent":["/// <reference lib=\"dom\" />\nimport {Edit} from \"./edit\";\n\nexport interface ContentEventDetail {\n\tedit: Edit;\n\tsource: string | null;\n\t// TODO: add information about changed ranges\n}\n\nexport interface ContentEventInit extends CustomEventInit<ContentEventDetail> {}\n\nexport class ContentEvent extends CustomEvent<ContentEventDetail> {\n\tconstructor(typeArg: string, eventInit: ContentEventInit) {\n\t\t// Maybe we should do some runtime eventInit validation.\n\t\tsuper(typeArg, {bubbles: true, ...eventInit});\n\t}\n}\n\n/** Whether the node’s info is up to date. */\nconst IS_VALID = 1 << 0;\n/** Whether the node is responsible for the newline before it. */\nconst PREPENDS_NEWLINE = 1 << 1;\n/** Whether the node is responsible for the newline after it. */\nconst APPENDS_NEWLINE = 1 << 2;\n\nclass NodeInfo {\n\t/** A bitmask (see flags above) */\n\tflags: number;\n\t/** The string length of this node’s contents. */\n\tsize: number;\n\t/** The start of this node’s contents relative to the start of the parent. */\n\toffset: number;\n\n\tconstructor(offset: number) {\n\t\tthis.flags = 0;\n\t\tthis.size = 0;\n\t\tthis.offset = offset;\n\t}\n}\n\ntype NodeInfoCache = Map<Node, NodeInfo>;\n\n/********************************************/\n/*** ContentAreaElement symbol properties ***/\n/********************************************/\nconst $slot = Symbol.for(\"revise$slot\");\nconst $cache = Symbol.for(\"revise$cache\");\nconst $value = Symbol.for(\"revise$value\");\nconst $observer = Symbol.for(\"revise$observer\");\nconst $selectionStart = Symbol.for(\"revise$selectionStart\");\nconst $onselectionchange = Symbol.for(\"revise$onselectionchange\");\n\nconst css = `:host {\n\tdisplay: contents;\n\twhite-space: pre-wrap;\n\twhite-space: break-spaces;\n\toverflow-wrap: break-word;\n}`;\n\nexport class ContentAreaElement extends HTMLElement implements SelectionRange {\n\t[$slot]: HTMLSlotElement;\n\t[$cache]: NodeInfoCache;\n\t[$value]: string;\n\t[$observer]: MutationObserver;\n\t// For the most part, we compute selection info on the fly, because of weird\n\t// race conditions. However, we need to retain the previous selectionStart\n\t// when building edits so that we can disambiguate edits to runs of\n\t// characters. See the Edit.diff call below.\n\t[$selectionStart]: number;\n\t[$onselectionchange]: () => void;\n\tconstructor() {\n\t\tsuper();\n\t\t{\n\t\t\t// Creating the shadow DOM.\n\t\t\tconst slot = document.createElement(\"slot\");\n\t\t\tconst shadow = this.attachShadow({mode: \"closed\"});\n\t\t\tconst style = document.createElement(\"style\");\n\t\t\tstyle.textContent = css;\n\t\t\tshadow.appendChild(style);\n\t\t\tslot.contentEditable = this.contentEditable;\n\t\t\tshadow.appendChild(slot);\n\t\t\tthis[$slot] = slot;\n\t\t}\n\n\t\tthis[$cache] = new Map();\n\t\tthis[$value] = \"\";\n\t\tthis[$observer] = new MutationObserver((records) => {\n\t\t\tvalidate(this, null, records);\n\t\t});\n\t\tthis[$selectionStart] = 0;\n\t\tthis[$onselectionchange] = () => {\n\t\t\tvalidate(this);\n\t\t\tthis[$selectionStart] = getSelectionRange(\n\t\t\t\tthis,\n\t\t\t\tthis[$cache],\n\t\t\t).selectionStart;\n\t\t};\n\t}\n\n\t/******************************/\n\t/*** Custom Element methods ***/\n\t/******************************/\n\tstatic get observedAttributes(): Array<string> {\n\t\treturn [\"contenteditable\"];\n\t}\n\n\tconnectedCallback() {\n\t\tthis[$observer].observe(this, {\n\t\t\tsubtree: true,\n\t\t\tchildList: true,\n\t\t\tcharacterData: true,\n\t\t\tattributes: true,\n\t\t\tattributeFilter: [\n\t\t\t\t\"data-content\",\n\t\t\t\t\"data-contentbefore\",\n\t\t\t\t\"data-contentafter\",\n\t\t\t],\n\t\t});\n\n\t\tthis[$value] = getValue(this, this[$cache], \"\");\n\t\tthis[$selectionStart] = getSelectionRange(\n\t\t\tthis,\n\t\t\tthis[$cache],\n\t\t).selectionStart;\n\t\tdocument.addEventListener(\n\t\t\t\"selectionchange\",\n\t\t\tthis[$onselectionchange],\n\t\t\t// We use capture in an attempt to run before other event listeners.\n\t\t\ttrue,\n\t\t);\n\t}\n\n\tdisconnectedCallback() {\n\t\tthis[$cache].clear();\n\t\tthis[$value] = \"\";\n\t\tthis[$observer].disconnect();\n\t\t// JSDOM-based environments like Jest will make the global document null\n\t\t// before calling the disconnectedCallback for some reason.\n\t\tif (document) {\n\t\t\tdocument.removeEventListener(\n\t\t\t\t\"selectionchange\",\n\t\t\t\tthis[$onselectionchange],\n\t\t\t\ttrue,\n\t\t\t);\n\t\t}\n\t}\n\n\tattributeChangedCallback(name: string) {\n\t\tswitch (name) {\n\t\t\tcase \"contenteditable\": {\n\t\t\t\tconst slot = this[$slot];\n\t\t\t\t// We have to set slot.contentEditable to this.contentEditable because\n\t\t\t\t// Chrome has trouble selecting elements across shadow DOM boundaries.\n\t\t\t\t// See https://bugs.chromium.org/p/chromium/issues/detail?id=1175930\n\n\t\t\t\t// Chrome has additional issues with using the host element as a\n\t\t\t\t// contenteditable element but this normalizes some of the behavior.\n\t\t\t\tslot.contentEditable = this.contentEditable;\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\t}\n\n\t/***********************/\n\t/*** Content methods ***/\n\t/***********************/\n\tget value(): string {\n\t\tvalidate(this);\n\t\treturn this[$value];\n\t}\n\n\tget selectionStart(): number {\n\t\tvalidate(this);\n\t\treturn getSelectionRange(this, this[$cache]).selectionStart;\n\t}\n\n\tset selectionStart(selectionStart: number) {\n\t\tvalidate(this);\n\n\t\tconst selectionRange = getSelectionRange(this, this[$cache]);\n\t\tsetSelectionRange(\n\t\t\tthis,\n\t\t\tthis[$cache],\n\t\t\tselectionStart,\n\t\t\tselectionRange.selectionEnd,\n\t\t\tselectionRange.selectionDirection,\n\t\t);\n\t}\n\n\tget selectionEnd(): number {\n\t\tvalidate(this);\n\t\treturn getSelectionRange(this, this[$cache]).selectionEnd;\n\t}\n\n\tset selectionEnd(selectionEnd: number) {\n\t\tvalidate(this);\n\t\tconst selectionRange = getSelectionRange(this, this[$cache]);\n\t\tsetSelectionRange(\n\t\t\tthis,\n\t\t\tthis[$cache],\n\t\t\tselectionRange.selectionStart,\n\t\t\tselectionEnd,\n\t\t\tselectionRange.selectionDirection,\n\t\t);\n\t}\n\n\tget selectionDirection(): SelectionDirection {\n\t\tvalidate(this);\n\t\treturn getSelectionRange(this, this[$cache]).selectionDirection;\n\t}\n\n\tset selectionDirection(selectionDirection: SelectionDirection) {\n\t\tvalidate(this);\n\t\tconst selectionRange = getSelectionRange(this, this[$cache]);\n\t\tsetSelectionRange(\n\t\t\tthis,\n\t\t\tthis[$cache],\n\t\t\tselectionRange.selectionStart,\n\t\t\tselectionRange.selectionEnd,\n\t\t\tselectionDirection,\n\t\t);\n\t}\n\n\tgetSelectionRange(): SelectionRange {\n\t\tvalidate(this);\n\t\treturn getSelectionRange(this, this[$cache]);\n\t}\n\n\tsetSelectionRange(\n\t\tselectionStart: number,\n\t\tselectionEnd: number,\n\t\tselectionDirection: SelectionDirection = \"none\",\n\t): void {\n\t\tvalidate(this);\n\t\tsetSelectionRange(\n\t\t\tthis,\n\t\t\tthis[$cache],\n\t\t\tselectionStart,\n\t\t\tselectionEnd,\n\t\t\tselectionDirection,\n\t\t);\n\t}\n\n\tindexAt(node: Node | null, offset: number): number {\n\t\tvalidate(this);\n\t\tconst cache = this[$cache];\n\t\treturn indexAt(this, cache, node, offset);\n\t}\n\n\tnodeOffsetAt(index: number): [Node | null, number] {\n\t\tvalidate(this);\n\t\tconst cache = this[$cache];\n\t\treturn nodeOffsetAt(this, cache, index);\n\t}\n\n\tsource(source: string): boolean {\n\t\treturn validate(this, source, this[$observer].takeRecords());\n\t}\n}\n\n// TODO: custom newlines?\nconst NEWLINE = \"\\n\";\n\n// TODO: Try using getComputedStyle\nconst BLOCKLIKE_ELEMENTS = new Set([\n\t\"ADDRESS\",\n\t\"ARTICLE\",\n\t\"ASIDE\",\n\t\"BLOCKQUOTE\",\n\t\"CAPTION\",\n\t\"DETAILS\",\n\t\"DIALOG\",\n\t\"DD\",\n\t\"DIV\",\n\t\"DL\",\n\t\"DT\",\n\t\"FIELDSET\",\n\t\"FIGCAPTION\",\n\t\"FIGURE\",\n\t\"FOOTER\",\n\t\"FORM\",\n\t\"H1\",\n\t\"H2\",\n\t\"H3\",\n\t\"H4\",\n\t\"H5\",\n\t\"H6\",\n\t\"HEADER\",\n\t\"HGROUP\",\n\t\"HR\",\n\t\"LI\",\n\t\"MAIN\",\n\t\"NAV\",\n\t\"OL\",\n\t\"P\",\n\t\"PRE\",\n\t\"SECTION\",\n\t\"TABLE\",\n\t\"TR\",\n\t\"UL\",\n]);\n\nfunction validate(\n\troot: ContentAreaElement,\n\tsource: string | null = null,\n\trecords?: Array<MutationRecord> | undefined,\n): boolean {\n\tconst cache = root[$cache];\n\t// We use the existence of records to determine whether\n\t// contentchange events should be fired synchronously.\n\tlet delay = false;\n\tif (records === undefined) {\n\t\tdelay = true;\n\t\trecords = root[$observer].takeRecords();\n\t}\n\n\tif (!invalidate(root, cache, records)) {\n\t\treturn false;\n\t}\n\n\tconst oldValue = root[$value];\n\tconst oldSelectionStart = root[$selectionStart];\n\tconst value = (root[$value] = getValue(root, cache, oldValue));\n\tconst selectionStart = getSelectionRange(root, cache).selectionStart;\n\n\tconst hint = Math.min(oldSelectionStart, selectionStart);\n\t// TODO: This call is expensive. If we have getValue return an edit instead\n\t// of a string, we might be able to save a lot in CPU time.\n\tconst edit = Edit.diff(oldValue, value, hint);\n\tconst ev = new ContentEvent(\"contentchange\", {detail: {edit, source}});\n\tif (delay) {\n\t\tPromise.resolve().then(() => root.dispatchEvent(ev));\n\t} else {\n\t\troot.dispatchEvent(ev);\n\t}\n\n\treturn true;\n}\n\nfunction invalidate(\n\troot: ContentAreaElement,\n\tcache: NodeInfoCache,\n\trecords: Array<MutationRecord>,\n): boolean {\n\tif (!cache.get(root)) {\n\t\treturn true;\n\t}\n\n\tlet invalid = false;\n\tfor (let i = 0; i < records.length; i++) {\n\t\tconst record = records[i];\n\t\t// We make sure all added and removed nodes are cleared from the cache just\n\t\t// in case of any MutationObserver weirdness.\n\t\tfor (let j = 0; j < record.addedNodes.length; j++) {\n\t\t\tclear(record.addedNodes[j], cache);\n\t\t}\n\n\t\tfor (let j = 0; j < record.removedNodes.length; j++) {\n\t\t\tclear(record.removedNodes[j], cache);\n\t\t}\n\n\t\t// TODO: invalidate data-content nodes correctly.\n\t\tlet node = record.target;\n\t\tif (node === root) {\n\t\t\tinvalid = true;\n\t\t\tcontinue;\n\t\t} else if (!root.contains(node)) {\n\t\t\tclear(node, cache);\n\t\t\tcontinue;\n\t\t}\n\n\t\tfor (; node !== root; node = node.parentNode!) {\n\t\t\tif (!cache.has(node)) {\n\t\t\t\tbreak;\n\t\t\t}\n\n\t\t\tconst info = cache.get(node);\n\t\t\tif (info) {\n\t\t\t\tinfo.flags &= ~IS_VALID;\n\t\t\t}\n\n\t\t\tinvalid = true;\n\t\t}\n\t}\n\n\tif (invalid) {\n\t\tconst info = cache.get(root)!;\n\t\tinfo.flags &= ~IS_VALID;\n\t}\n\n\treturn invalid;\n}\n\n// This is the single most complicated function in the library!!!\n/**\n * This function both returns the content of the root (always a content-area\n * element, and populates the cache with info about the contents of nodes for\n * future reads.\n * @param root - The root element (usually a content-area element)\n * @param cache - The nodeInfo cache associated with the root\n * @param oldContent - The previous content of the root.\n */\nfunction getValue(\n\troot: Element,\n\tcache: NodeInfoCache,\n\toldContent: string,\n): string {\n\tconst walker = document.createTreeWalker(\n\t\troot,\n\t\tNodeFilter.SHOW_TEXT | NodeFilter.SHOW_ELEMENT,\n\t);\n\n\t// TODO: It might be faster to construct and return a edit rather than\n\t// concatenating a giant string.\n\tlet content = \"\";\n\t// Because the content variable is a heavily concatenated string and likely\n\t// inferred by most engines as requiring a “rope-like” data structure for\n\t// performance, reading from the end of the string to detect newlines can be\n\t// a bottleneck. Therefore, we store that info in this boolean instead.\n\t/** A boolean which indicates whether content currently ends in a newline. */\n\tlet hasNewline = false;\n\t/** The start of the current node relative to its parent. */\n\tlet offset = 0;\n\t// The current index into oldContent. We use this to copy unchanged text over\n\t// and track deletions.\n\t// If there are nodes which have cached start and length information, we get\n\t// their contents from oldContent string using oldIndex so we don’t have to\n\t// read it from the DOM.\n\tlet oldIndex = 0;\n\t// The current index into oldContent of the current node’s parent. We can get\n\t// the expected start of a node if none of the nodes before it were deleted\n\t// by finding the difference between oldIndex and relativeOldIndex. We can\n\t// compare this difference to the cached start information to detect\n\t// deletions.\n\tlet relativeOldIndex = 0;\n\tlet info: NodeInfo = cache.get(root)!;\n\tif (info === undefined) {\n\t\tinfo = new NodeInfo(offset);\n\t\tcache.set(root, info);\n\t}\n\n\t// A stack to save some variables as we walk up and down the tree.\n\tconst stack: Array<{relativeOldIndex: number; info: NodeInfo}> = [];\n\tfor (let node: Node | null = root, descending = true; node !== null; ) {\n\t\t// A loop to descend into the DOM tree.\n\t\twhile (descending && !(info.flags & IS_VALID)) {\n\t\t\tif (\n\t\t\t\tnode.nodeType === Node.TEXT_NODE ||\n\t\t\t\t// We treat elements with data-content attributes as opaque.\n\t\t\t\t(node as Element).hasAttribute(\"data-content\")\n\t\t\t) {\n\t\t\t\tbreak;\n\t\t\t}\n\n\t\t\t// If the current node is a block-like element, and the previous\n\t\t\t// node/elements did not end with a newline, then the current element\n\t\t\t// would introduce a linebreak before its contents.\n\t\t\t// We check that the offset is non-zero so that the first child of a\n\t\t\t// parent does not introduce a newline before it.\n\t\t\tconst prependsNewline =\n\t\t\t\t!!offset && !hasNewline && isBlocklikeElement(node);\n\t\t\tif (prependsNewline) {\n\t\t\t\tcontent += NEWLINE;\n\t\t\t\thasNewline = true;\n\t\t\t\toffset += NEWLINE.length;\n\t\t\t\tinfo.offset += NEWLINE.length;\n\t\t\t\tinfo.flags |= PREPENDS_NEWLINE;\n\t\t\t} else {\n\t\t\t\tinfo.flags &= ~PREPENDS_NEWLINE;\n\t\t\t}\n\n\t\t\tif ((node = walker.firstChild())) {\n\t\t\t\tdescending = true;\n\t\t\t} else {\n\t\t\t\tnode = walker.currentNode;\n\t\t\t\tbreak;\n\t\t\t}\n\n\t\t\tstack.push({relativeOldIndex, info});\n\t\t\trelativeOldIndex = oldIndex;\n\t\t\toffset = 0;\n\t\t\t// getNodeInfo\n\t\t\tinfo = cache.get(node)!;\n\t\t\tif (info === undefined) {\n\t\t\t\tinfo = new NodeInfo(offset);\n\t\t\t\tcache.set(node, info);\n\t\t\t} else {\n\t\t\t\tif (info.offset > 0) {\n\t\t\t\t\t// deletion detected\n\t\t\t\t\toldIndex += info.offset;\n\t\t\t\t}\n\n\t\t\t\tinfo.offset = offset;\n\t\t\t}\n\t\t}\n\n\t\tif (info.flags & IS_VALID) {\n\t\t\t// The node has been seen before.\n\t\t\t// Reading from oldContent because length hasn’t been invalidated.\n\t\t\tconst length = info.size;\n\t\t\tif (oldIndex + info.size > oldContent.length) {\n\t\t\t\t// This should never happen\n\t\t\t\tthrow new Error(\"String length mismatch\");\n\t\t\t}\n\n\t\t\tconst prependsNewline =\n\t\t\t\t!!offset && !hasNewline && isBlocklikeElement(node);\n\t\t\tif (prependsNewline) {\n\t\t\t\tcontent += NEWLINE;\n\t\t\t\thasNewline = true;\n\t\t\t\toffset += NEWLINE.length;\n\t\t\t\tinfo.offset += NEWLINE.length;\n\t\t\t\tinfo.flags |= PREPENDS_NEWLINE;\n\t\t\t} else {\n\t\t\t\tinfo.flags &= ~PREPENDS_NEWLINE;\n\t\t\t}\n\n\t\t\tconst oldContent1 = oldContent.slice(oldIndex, oldIndex + length);\n\t\t\tcontent += oldContent1;\n\t\t\toffset += length;\n\t\t\toldIndex += length;\n\t\t\tif (oldContent1.length) {\n\t\t\t\thasNewline = oldContent1.endsWith(NEWLINE);\n\t\t\t}\n\t\t} else {\n\t\t\t// The node hasn’t been seen before.\n\t\t\tlet appendsNewline = false;\n\t\t\tif (node.nodeType === Node.TEXT_NODE) {\n\t\t\t\tconst content1 = (node as Text).data;\n\t\t\t\tcontent += content1;\n\t\t\t\toffset += content1.length;\n\t\t\t\tif (content1.length) {\n\t\t\t\t\thasNewline = content1.endsWith(NEWLINE);\n\t\t\t\t}\n\t\t\t} else if ((node as Element).hasAttribute(\"data-content\")) {\n\t\t\t\tconst content1 = (node as Element).getAttribute(\"data-content\") || \"\";\n\t\t\t\tcontent += content1;\n\t\t\t\toffset += content1.length;\n\t\t\t\tif (content1.length) {\n\t\t\t\t\thasNewline = content1.endsWith(NEWLINE);\n\t\t\t\t}\n\t\t\t} else if (!hasNewline && isBlocklikeElement(node)) {\n\t\t\t\tcontent += NEWLINE;\n\t\t\t\toffset += NEWLINE.length;\n\t\t\t\thasNewline = true;\n\t\t\t\tappendsNewline = true;\n\t\t\t} else if (node.nodeName === \"BR\") {\n\t\t\t\tcontent += NEWLINE;\n\t\t\t\toffset += NEWLINE.length;\n\t\t\t\thasNewline = true;\n\t\t\t}\n\n\t\t\tinfo.size = offset - info.offset;\n\t\t\tinfo.flags |= IS_VALID;\n\t\t\tinfo.flags = appendsNewline\n\t\t\t\t? info.flags | APPENDS_NEWLINE\n\t\t\t\t: info.flags & ~APPENDS_NEWLINE;\n\t\t}\n\n\t\tif ((node = walker.nextSibling())) {\n\t\t\tdescending = true;\n\t\t\t// getNodeInfo\n\t\t\tinfo = cache.get(node)!;\n\t\t\tif (info === undefined) {\n\t\t\t\tinfo = new NodeInfo(offset);\n\t\t\t\tcache.set(node, info);\n\t\t\t} else {\n\t\t\t\tconst oldOffset = oldIndex - relativeOldIndex;\n\t\t\t\tif (info.offset > oldOffset) {\n\t\t\t\t\t// deletion detected\n\t\t\t\t\toldIndex += info.offset - oldOffset;\n\t\t\t\t} else if (info.offset < oldOffset) {\n\t\t\t\t\t// This should never happen\n\t\t\t\t\tthrow new Error(\"Offset is before old offset\");\n\t\t\t\t}\n\n\t\t\t\tinfo.offset = offset;\n\t\t\t}\n\t\t} else {\n\t\t\tdescending = false;\n\t\t\tif (walker.currentNode !== root) {\n\t\t\t\tif (!stack.length) {\n\t\t\t\t\t// This should never happen\n\t\t\t\t\tthrow new Error(\"Stack is empty\");\n\t\t\t\t}\n\n\t\t\t\t({relativeOldIndex, info} = stack.pop()!);\n\t\t\t\toffset = info.offset + offset;\n\t\t\t\tnode = walker.parentNode();\n\t\t\t}\n\t\t}\n\t}\n\n\treturn content;\n}\n\nfunction isBlocklikeElement(node: Node): node is Element {\n\treturn (\n\t\tnode.nodeType === Node.ELEMENT_NODE && BLOCKLIKE_ELEMENTS.has(node.nodeName)\n\t);\n}\n\n/**\n * For a given parent node and node info cache, clear info for the node and all\n * child nodes from the cache.\n */\nfunction clear(parent: Node, cache: NodeInfoCache): void {\n\tconst walker = document.createTreeWalker(\n\t\tparent,\n\t\tNodeFilter.SHOW_TEXT | NodeFilter.SHOW_ELEMENT,\n\t);\n\n\tfor (\n\t\tlet node: Node | null = parent;\n\t\tnode !== null;\n\t\tnode = walker.nextNode()\n\t) {\n\t\tcache.delete(node);\n\t}\n}\n\n/***********************/\n/*** Selection Logic ***/\n/***********************/\nexport type SelectionDirection = \"forward\" | \"backward\" | \"none\";\n\n/**\n * Properties which mirror the API provided by HTMLInputElement and\n * HTMLTextAreaElement.\n */\nexport interface SelectionRange {\n\tselectionStart: number;\n\tselectionEnd: number;\n\tselectionDirection: SelectionDirection;\n}\n\n/**\n * Finds the string index of a node and offset pair provided by a browser API\n * like window.getSelection() for a given root and cache.\n */\nfunction indexAt(\n\troot: Element,\n\tcache: NodeInfoCache,\n\tnode: Node | null,\n\toffset: number,\n): number {\n\tif (node == null || !root.contains(node)) {\n\t\treturn -1;\n\t}\n\n\tif (!cache.has(node)) {\n\t\t// If the node is not found in the cache but is contained in the root,\n\t\t// then it is probably the child of an element with a data-content\n\t\t// attribute.\n\t\t// TODO: Maybe a non-zero offset should put the index at the end of\n\t\t// the data-content node.\n\t\toffset = 0;\n\t\twhile (!cache.has(node)) {\n\t\t\tnode = node.parentNode!;\n\t\t}\n\t}\n\n\tlet index: number;\n\tif (node.nodeType === Node.TEXT_NODE) {\n\t\tconst info = cache.get(node)!;\n\t\tindex = offset + info.offset;\n\t\tnode = node.parentNode!;\n\t} else {\n\t\tif (offset <= 0) {\n\t\t\tindex = 0;\n\t\t} else if (offset >= node.childNodes.length) {\n\t\t\tconst info = cache.get(node)!;\n\t\t\tindex = info.size;\n\t\t\tif (info.flags & APPENDS_NEWLINE) {\n\t\t\t\tindex -= NEWLINE.length;\n\t\t\t}\n\t\t} else {\n\t\t\tlet child: Node | null = node.childNodes[offset];\n\t\t\twhile (child !== null && !cache.has(child)) {\n\t\t\t\tchild = child.previousSibling;\n\t\t\t}\n\n\t\t\tif (child === null) {\n\t\t\t\tindex = 0;\n\t\t\t} else {\n\t\t\t\tnode = child;\n\t\t\t\tconst info = cache.get(node)!;\n\t\t\t\t// If the offset references an element which prepends a newline\n\t\t\t\t// (\"hello<div>world</div>\"), we have to start from -1 because the\n\t\t\t\t// element’s info.offset will not account for the newline.\n\t\t\t\tindex = info.flags & PREPENDS_NEWLINE ? -1 : 0;\n\t\t\t}\n\t\t}\n\t}\n\n\tfor (; node !== root; node = node.parentNode!) {\n\t\tconst info = cache.get(node)!;\n\t\tindex += info.offset;\n\t}\n\n\treturn index;\n}\n\n/**\n * Finds the node and offset pair to use with browser APIs like\n * selection.collapse() from a given string index.\n */\nfunction nodeOffsetAt(\n\troot: Element,\n\tcache: NodeInfoCache,\n\tindex: number,\n): [Node | null, number] {\n\tconst [node, offset] = findNodeOffset(root, cache, index);\n\tif (node && node.nodeName === \"BR\") {\n\t\t// Different browsers can have trouble when calling `selection.collapse()`\n\t\t// with a BR element, so we try to avoid returning them from this function.\n\t\treturn nodeOffsetFromChild(node);\n\t}\n\n\treturn [node, offset];\n}\n\nfunction findNodeOffset(\n\troot: Element,\n\tcache: NodeInfoCache,\n\tindex: number,\n): [Node | null, number] {\n\tif (index < 0) {\n\t\treturn [null, 0];\n\t}\n\n\tconst walker = document.createTreeWalker(\n\t\troot,\n\t\tNodeFilter.SHOW_TEXT | NodeFilter.SHOW_ELEMENT,\n\t);\n\n\tfor (let node: Node | null = root; node !== null; ) {\n\t\tconst info = cache.get(node);\n\t\tif (info == null) {\n\t\t\treturn nodeOffsetFromChild(node, index > 0);\n\t\t} else if (info.flags & PREPENDS_NEWLINE) {\n\t\t\tindex -= NEWLINE.length;\n\t\t}\n\n\t\tif (index < 0) {\n\t\t\t// This branch should only run when an element prepends an newline\n\t\t\tconst previousSibling = walker.previousSibling();\n\t\t\tif (!previousSibling) {\n\t\t\t\t// This should never happen\n\t\t\t\tthrow new Error(\"Previous sibling missing\");\n\t\t\t}\n\n\t\t\treturn [previousSibling, getNodeLength(previousSibling)];\n\t\t} else if (index === info.size && node.nodeType === Node.TEXT_NODE) {\n\t\t\treturn [node, (node as Text).data.length];\n\t\t} else if (index >= info.size) {\n\t\t\tindex -= info.size;\n\t\t\tconst nextSibling = walker.nextSibling();\n\t\t\tif (nextSibling === null) {\n\t\t\t\t// This branch seems necessary mainly when working with data-content\n\t\t\t\t// nodes.\n\t\t\t\tif (node === root) {\n\t\t\t\t\treturn [node, getNodeLength(node)];\n\t\t\t\t}\n\n\t\t\t\treturn nodeOffsetFromChild(walker.currentNode, true);\n\t\t\t}\n\n\t\t\tnode = nextSibling;\n\t\t} else {\n\t\t\tif (\n\t\t\t\tnode.nodeType === Node.ELEMENT_NODE &&\n\t\t\t\t(node as Element).hasAttribute(\"data-content\")\n\t\t\t) {\n\t\t\t\treturn nodeOffsetFromChild(node, index > 0);\n\t\t\t}\n\n\t\t\tconst firstChild = walker.firstChild();\n\t\t\tif (firstChild === null) {\n\t\t\t\tconst offset =\n\t\t\t\t\tnode.nodeType === Node.TEXT_NODE ? index : index > 0 ? 1 : 0;\n\t\t\t\treturn [node, offset];\n\t\t\t} else {\n\t\t\t\tnode = firstChild;\n\t\t\t}\n\t\t}\n\t}\n\n\tconst node = walker.currentNode;\n\treturn [node, getNodeLength(node)];\n}\n\nfunction getNodeLength(node: Node) {\n\tif (node.nodeType === Node.TEXT_NODE) {\n\t\treturn (node as Text).data.length;\n\t}\n\n\treturn node.childNodes.length;\n}\n\nfunction nodeOffsetFromChild(\n\tnode: Node,\n\tafter: boolean = false,\n): [Node | null, number] {\n\tconst parentNode = node.parentNode;\n\tif (parentNode === null) {\n\t\treturn [null, 0];\n\t}\n\n\tlet offset = Array.from(parentNode.childNodes).indexOf(node as ChildNode);\n\tif (after) {\n\t\toffset++;\n\t}\n\n\treturn [parentNode, offset];\n}\n\nfunction getSelectionRange(\n\troot: Element,\n\tcache: NodeInfoCache,\n): SelectionRange {\n\tconst selection = window.getSelection();\n\tif (!selection) {\n\t\treturn {selectionStart: 0, selectionEnd: 0, selectionDirection: \"none\"};\n\t}\n\n\tconst {\n\t\tfocusNode,\n\t\tfocusOffset,\n\t\tanchorNode,\n\t\tanchorOffset,\n\t\tisCollapsed,\n\t} = selection;\n\tconst focus = Math.max(0, indexAt(root, cache, focusNode, focusOffset));\n\tconst anchor = isCollapsed\n\t\t? focus\n\t\t: Math.max(0, indexAt(root, cache, anchorNode, anchorOffset));\n\treturn {\n\t\tselectionStart: Math.min(focus, anchor),\n\t\tselectionEnd: Math.max(focus, anchor),\n\t\tselectionDirection:\n\t\t\tfocus < anchor ? \"backward\" : focus > anchor ? \"forward\" : \"none\",\n\t};\n}\n\nfunction setSelectionRange(\n\troot: Element,\n\tcache: NodeInfoCache,\n\tselectionStart: number,\n\tselectionEnd: number,\n\tselectionDirection: SelectionDirection,\n): void {\n\tconst selection = window.getSelection();\n\tif (!selection) {\n\t\treturn;\n\t}\n\n\tselectionStart = Math.max(0, selectionStart || 0);\n\tselectionEnd = Math.max(0, selectionEnd || 0);\n\tif (selectionEnd < selectionStart) {\n\t\tselectionStart = selectionEnd;\n\t}\n\n\tconst [focusIndex, anchorIndex] =\n\t\tselectionDirection === \"backward\"\n\t\t\t? [selectionStart, selectionEnd]\n\t\t\t: [selectionEnd, selectionStart];\n\n\tif (focusIndex === anchorIndex) {\n\t\tconst [node, offset] = nodeOffsetAt(root, cache, focusIndex);\n\t\tselection.collapse(node, offset);\n\t} else {\n\t\tconst [anchorNode, anchorOffset] = nodeOffsetAt(root, cache, anchorIndex);\n\t\tconst [focusNode, focusOffset] = nodeOffsetAt(root, cache, focusIndex);\n\t\tif (anchorNode === null && focusNode === null) {\n\t\t\tselection.collapse(null);\n\t\t} else if (anchorNode === null) {\n\t\t\tselection.collapse(focusNode, focusOffset);\n\t\t} else if (focusNode === null) {\n\t\t\tselection.collapse(anchorNode, anchorOffset);\n\t\t} else {\n\t\t\t// This is not a method in IE. We don’t care.\n\t\t\tselection.setBaseAndExtent(\n\t\t\t\tanchorNode,\n\t\t\t\tanchorOffset,\n\t\t\t\tfocusNode,\n\t\t\t\tfocusOffset,\n\t\t\t);\n\t\t}\n\t}\n}\n"],"names":["edit","Edit"],"mappings":";;;;;;;AAAA;MAWa,YAAa,SAAQ,WAA+B;IAChE,YAAY,OAAe,EAAE,SAA2B;;QAEvD,KAAK,CAAC,OAAO,EAAE,EAAC,OAAO,EAAE,IAAI,EA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I,EAAE,KAAK,EAAE,WAAW,CAAC,CAAC;QAC1E,MAAM,CAAC,SAAS,EAAE,WAAW,CAAC,GAAG,YAAY,CAAC,IAAI,EAAE,KAAK,EAAE,UAAU,CAAC,CAAC;QACvE,IAAI,UAAU,KAAK,IAAI,IAAI,SAAS,KAAK,IAAI,EAAE;YAC9C,SAAS,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC;SACzB;aAAM,IAAI,UAAU,KAAK,IAAI,EAAE;YAC/B,SAAS,CAAC,QAAQ,CAAC,SAAS,EAAE,WAAW,CAAC,CAAC;SAC3C;aAAM,IAAI,SAAS,KAAK,IAAI,EAAE;YAC9B,SAAS,CAAC,QAAQ,CAAC,UAAU,EAAE,YAAY,CAAC,CAAC;SAC7C;aAAM;;YAEN,SAAS,CAAC,gBAAgB,CACzB,UAAU,EACV,YAAY,EACZ,SAAS,EACT,WAAW,CACX,CAAC;SACF;KACD;AACF;;;;;"}
|
|
1
|
+
{"version":3,"file":"contentarea.cjs","sources":["../src/contentarea.ts"],"sourcesContent":["/// <reference lib=\"dom\" />\nimport {Edit} from \"./edit.js\";\n\n// TODO: custom newlines?\nconst NEWLINE = \"\\n\";\n\nexport interface ContentEventDetail {\n\tedit: Edit;\n\tsource: string | null;\n}\n\nexport interface ContentEventInit extends CustomEventInit<ContentEventDetail> {}\n\nexport class ContentEvent extends CustomEvent<ContentEventDetail> {\n\tconstructor(typeArg: string, eventInit: ContentEventInit) {\n\t\t// Maybe we should do some runtime eventInit validation.\n\t\tsuper(typeArg, {bubbles: true, ...eventInit});\n\t}\n}\n\nexport type SelectionDirection = \"forward\" | \"backward\" | \"none\";\n\n/********************************************/\n/*** ContentAreaElement private property symbols ***/\n/********************************************/\nconst _cache = Symbol.for(\"ContentAreaElement._cache\");\nconst _value = Symbol.for(\"ContentAreaElement._value\");\nconst _observer = Symbol.for(\"ContentAreaElement._observer\");\nconst _onselectionchange = Symbol.for(\"ContentAreaElement._onselectionchange\");\nconst _selectionStart = Symbol.for(\"ContentAreaElement._selectionStart\");\n\nexport class ContentAreaElement extends HTMLElement {\n\tdeclare [_cache]: NodeInfoCache;\n\tdeclare [_value]: string;\n\tdeclare [_observer]: MutationObserver;\n\tdeclare [_onselectionchange]: () => void;\n\tdeclare [_selectionStart]: number;\n\tconstructor() {\n\t\tsuper();\n\n\t\tthis[_cache] = new Map();\n\t\tthis[_value] = \"\";\n\t\tthis[_observer] = new MutationObserver((records) => {\n\t\t\tvalidate(this, records);\n\t\t});\n\n\t\tthis[_selectionStart] = 0;\n\t\tthis[_onselectionchange] = () => {\n\t\t\t// We keep track of the starting node offset pair to accurately diff\n\t\t\t// edits to text nodes.\n\t\t\tvalidate(this);\n\t\t\tthis[_selectionStart] = getSelectionRange(this).start;\n\t\t};\n\n\t\tthis.addEventListener(\"input\", () => {\n\t\t\t// This is necessary for Safari bugs where fast-repeating edits which\n\t\t\t// cause >40ms of execution cause the selection to lag and make pending\n\t\t\t// edits appear elsewhere in the DOM.\n\t\t\tvalidate(this);\n\t\t});\n\t}\n\n\t/******************************/\n\t/*** Custom Element methods ***/\n\t/******************************/\n\tconnectedCallback() {\n\t\tthis[_observer].observe(this, {\n\t\t\tsubtree: true,\n\t\t\tchildList: true,\n\t\t\tcharacterData: true,\n\t\t\tattributes: true,\n\t\t\tattributeFilter: [\n\t\t\t\t\"data-content\",\n\t\t\t\t// TODO: implement these attributes\n\t\t\t\t//\"data-contentbefore\",\n\t\t\t\t//\"data-contentafter\",\n\t\t\t],\n\t\t});\n\n\t\tvalidate(this);\n\t\tdocument.addEventListener(\n\t\t\t\"selectionchange\",\n\t\t\tthis[_onselectionchange],\n\t\t\t// We use capture in an attempt to run before other event listeners.\n\t\t\ttrue,\n\t\t);\n\t}\n\n\tdisconnectedCallback() {\n\t\tthis[_cache].clear();\n\t\tthis[_value] = \"\";\n\t\tthis[_observer].disconnect();\n\t\t// JSDOM-based environments like Jest sometimes make the global document\n\t\t// null before calling the disconnectedCallback for some reason.\n\t\tif (document) {\n\t\t\tdocument.removeEventListener(\n\t\t\t\t\"selectionchange\",\n\t\t\t\tthis[_onselectionchange],\n\t\t\t\ttrue,\n\t\t\t);\n\t\t}\n\t}\n\n\tget value(): string {\n\t\tvalidate(this);\n\t\treturn this[_value];\n\t}\n\n\tget selectionStart(): number {\n\t\tvalidate(this);\n\t\treturn getSelectionRange(this).start;\n\t}\n\n\tset selectionStart(start: number) {\n\t\tvalidate(this);\n\n\t\tconst {end, direction} = getSelectionRange(this);\n\t\tsetSelectionRange(this, {start, end, direction});\n\t}\n\n\tget selectionEnd(): number {\n\t\tvalidate(this);\n\t\treturn getSelectionRange(this).end;\n\t}\n\n\tset selectionEnd(end: number) {\n\t\tvalidate(this);\n\t\tconst {start, direction} = getSelectionRange(this);\n\t\tsetSelectionRange(this, {start, end, direction});\n\t}\n\n\tget selectionDirection(): SelectionDirection {\n\t\tvalidate(this);\n\t\treturn getSelectionRange(this).direction;\n\t}\n\n\tset selectionDirection(direction: SelectionDirection) {\n\t\tvalidate(this);\n\t\tconst {start, end} = getSelectionRange(this);\n\t\tsetSelectionRange(this, {start, end, direction});\n\t}\n\n\tsetSelectionRange(\n\t\tstart: number,\n\t\tend: number,\n\t\tdirection: SelectionDirection = \"none\",\n\t): void {\n\t\tvalidate(this);\n\t\tsetSelectionRange(this, {start, end, direction});\n\t}\n\n\tindexAt(node: Node | null, offset: number): number {\n\t\tvalidate(this);\n\t\treturn indexAt(this, node, offset);\n\t}\n\n\tnodeOffsetAt(index: number): [Node | null, number] {\n\t\tvalidate(this);\n\t\treturn nodeOffsetAt(this, index);\n\t}\n\n\tsource(source: string): boolean {\n\t\treturn validate(this, this[_observer].takeRecords(), source);\n\t}\n}\n\n/*** NodeInfo.flags ***/\n/** Whether the node is old. */\nconst IS_OLD = 1 << 0;\n/** Whether the node’s info is still up-to-date. */\nconst IS_VALID = 1 << 1;\n/** Whether the node has a styling of type display: block or similar. */\nconst IS_BLOCKLIKE = 1 << 2;\n/** Whether the node is responsible for the newline before it. */\nconst PREPENDS_NEWLINE = 1 << 3;\n/** Whether the node is responsible for the newline after it. */\nconst APPENDS_NEWLINE = 1 << 4;\n\n/** Data associated with the child nodes of a ContentAreaElement. */\nclass NodeInfo {\n\t// TODO: explain the relationship of these numbers to newline stuff\n\t/** The start of this node’s contents relative to the start of the parent. */\n\tdeclare offset: number;\n\t/** The string length of this node’s contents. */\n\tdeclare length: number;\n\t/** A bitmask (see flags above) */\n\tdeclare flags: number;\n\n\tconstructor(offset: number) {\n\t\tthis.offset = offset;\n\t\tthis.length = 0;\n\t\tthis.flags = 0;\n\t}\n}\n\n/** Each ContentAreaElement is associated with its own private cache. */\ntype NodeInfoCache = Map<Node, NodeInfo>;\n\n/**\n * Should be called before calling any ContentAreaElement methods.\n *\n * This function ensures the cache is up to date.\n *\n * Dispatches \"contentchange\" events.\n *\n * @returns whether a change was detected\n */\nfunction validate(\n\t_this: ContentAreaElement,\n\trecords: Array<MutationRecord> = _this[_observer].takeRecords(),\n\tsource: string | null = null,\n): boolean {\n\tif (typeof _this !== \"object\" || _this[_cache] == null) {\n\t\tthrow new TypeError(\"this is not a ContentAreaElement\");\n\t}\n\n\tif (!invalidate(_this, records)) {\n\t\treturn false;\n\t}\n\n\tconst oldValue = _this[_value];\n\tconst edit = diff(_this, oldValue, _this[_selectionStart]);\n\t_this[_value] = edit.apply(oldValue);\n\tconst ev = new ContentEvent(\"contentchange\", {detail: {edit, source}});\n\tPromise.resolve().then(() => _this.dispatchEvent(ev));\n\treturn true;\n}\n\nfunction invalidate(\n\t_this: ContentAreaElement,\n\trecords: Array<MutationRecord>,\n): boolean {\n\tconst cache = _this[_cache];\n\tif (!cache.get(_this)) {\n\t\t// The root ContentAreaElement will not be deleted from the cache until the\n\t\t// element is removed from the DOM, so this is the first time the\n\t\t// ContentAreaElement is being validated.\n\t\treturn true;\n\t}\n\n\tlet invalid = false;\n\tfor (let i = 0; i < records.length; i++) {\n\t\tconst record = records[i];\n\t\t// We make sure all added and removed nodes and their children are deleted\n\t\t// from the cache in case of any weirdness where nodes have been moved.\n\t\tfor (let j = 0; j < record.addedNodes.length; j++) {\n\t\t\tclear(record.addedNodes[j], cache);\n\t\t}\n\n\t\tfor (let j = 0; j < record.removedNodes.length; j++) {\n\t\t\tclear(record.removedNodes[j], cache);\n\t\t}\n\n\t\tlet node = record.target;\n\t\tif (node === _this) {\n\t\t\tinvalid = true;\n\t\t\tcontinue;\n\t\t} else if (!_this.contains(node)) {\n\t\t\tclear(node, cache);\n\t\t\tcontinue;\n\t\t}\n\n\t\tfor (; node !== _this; node = node.parentNode!) {\n\t\t\tif (!cache.has(node)) {\n\t\t\t\tbreak;\n\t\t\t}\n\n\t\t\tconst nodeInfo = cache.get(node);\n\t\t\tif (nodeInfo) {\n\t\t\t\tnodeInfo.flags &= ~IS_VALID;\n\t\t\t}\n\n\t\t\tinvalid = true;\n\t\t}\n\t}\n\n\tif (invalid) {\n\t\tconst nodeInfo = cache.get(_this)!;\n\t\tnodeInfo.flags &= ~IS_VALID;\n\t}\n\n\treturn invalid;\n}\n\n/**\n * For a given parent node and node info cache, clear the info for the node and\n * all of its child nodes from the cache.\n */\nfunction clear(parent: Node, cache: NodeInfoCache): void {\n\tconst walker = document.createTreeWalker(\n\t\tparent,\n\t\tNodeFilter.SHOW_TEXT | NodeFilter.SHOW_ELEMENT,\n\t);\n\n\tfor (\n\t\tlet node: Node | null = parent;\n\t\tnode !== null;\n\t\tnode = walker.nextNode()\n\t) {\n\t\tcache.delete(node);\n\t}\n}\n\n// THIS IS THE MOST COMPLICATED FUNCTION IN THE LIBRARY!\n/**\n * This function both returns an edit which represents changes to the\n * ContentAreaElement, and populates the cache with info about nodes for future\n * reads.\n */\nfunction diff(\n\t_this: ContentAreaElement,\n\toldValue: string,\n\toldSelectionStart: number,\n): Edit {\n\tconst walker = document.createTreeWalker(\n\t\t_this,\n\t\tNodeFilter.SHOW_TEXT | NodeFilter.SHOW_ELEMENT,\n\t);\n\n\tconst cache = _this[_cache];\n\tconst stack: Array<{nodeInfo: NodeInfo; oldIndexRelative: number}> = [];\n\tlet nodeInfo: NodeInfo;\n\tlet value = \"\";\n\tfor (\n\t\tlet node: Node = _this,\n\t\t\tdescending = true,\n\t\t\t/** the current offset relative to the parent */\n\t\t\toffset = 0,\n\t\t\t/** the index into the old string */\n\t\t\toldIndex = 0,\n\t\t\t/** the index into the old string of the parent */\n\t\t\toldIndexRelative = 0,\n\t\t\t/** Whether or not the value being built currently ends with a newline */\n\t\t\thasNewline = false;\n\t\t;\n\t\tnode = walker.currentNode\n\t) {\n\t\tif (descending) {\n\t\t\t// PRE-ORDER LOGIC\n\t\t\tnodeInfo = cache.get(node)!;\n\t\t\tif (nodeInfo === undefined) {\n\t\t\t\tcache.set(node, (nodeInfo = new NodeInfo(offset)));\n\t\t\t\tif (isBlocklikeElement(node)) {\n\t\t\t\t\tnodeInfo.flags |= IS_BLOCKLIKE;\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\tconst expectedOffset = oldIndex - oldIndexRelative;\n\t\t\t\tconst deleteLength = nodeInfo.offset - expectedOffset;\n\t\t\t\tif (deleteLength < 0) {\n\t\t\t\t\t// this should never happen\n\t\t\t\t\tthrow new Error(\"cache offset error\");\n\t\t\t\t} else if (deleteLength > 0) {\n\t\t\t\t\t// deletion detected\n\t\t\t\t\toldIndex += deleteLength;\n\t\t\t\t}\n\n\t\t\t\tnodeInfo.offset = offset;\n\t\t\t}\n\n\t\t\tif (offset && !hasNewline && nodeInfo.flags & IS_BLOCKLIKE) {\n\t\t\t\t// Block-like elements prepend a newline when they appear after text or\n\t\t\t\t// inline elements.\n\t\t\t\thasNewline = true;\n\t\t\t\toffset += NEWLINE.length;\n\t\t\t\tvalue += NEWLINE;\n\t\t\t\tif (nodeInfo.flags & PREPENDS_NEWLINE) {\n\t\t\t\t\toldIndex += NEWLINE.length;\n\t\t\t\t}\n\n\t\t\t\tnodeInfo.flags |= PREPENDS_NEWLINE;\n\t\t\t} else {\n\t\t\t\tif (nodeInfo.flags & PREPENDS_NEWLINE) {\n\t\t\t\t\t// deletion detected\n\t\t\t\t\toldIndex += NEWLINE.length;\n\t\t\t\t}\n\n\t\t\t\tnodeInfo.flags &= ~PREPENDS_NEWLINE;\n\t\t\t}\n\n\t\t\tdescending = false;\n\t\t\tif (nodeInfo.flags & IS_VALID) {\n\t\t\t\t// The node and its children are unchanged, so we read from the length.\n\t\t\t\tif (nodeInfo.length) {\n\t\t\t\t\tvalue += oldValue.slice(oldIndex, oldIndex + nodeInfo.length);\n\t\t\t\t\toldIndex += nodeInfo.length;\n\t\t\t\t\toffset += nodeInfo.length;\n\t\t\t\t\thasNewline =\n\t\t\t\t\t\toldValue.slice(Math.max(0, oldIndex - NEWLINE.length), oldIndex) ===\n\t\t\t\t\t\tNEWLINE;\n\t\t\t\t}\n\t\t\t} else if (node.nodeType === Node.TEXT_NODE) {\n\t\t\t\tconst text = (node as Text).data;\n\t\t\t\tif (text.length) {\n\t\t\t\t\tvalue += text;\n\t\t\t\t\toffset += text.length;\n\t\t\t\t\thasNewline = text.endsWith(NEWLINE);\n\t\t\t\t}\n\n\t\t\t\tif (nodeInfo.flags & IS_OLD) {\n\t\t\t\t\toldIndex += nodeInfo.length;\n\t\t\t\t}\n\t\t\t} else if ((node as Element).hasAttribute(\"data-content\")) {\n\t\t\t\tconst text = (node as Element).getAttribute(\"data-content\") || \"\";\n\t\t\t\tif (text.length) {\n\t\t\t\t\tvalue += text;\n\t\t\t\t\toffset += text.length;\n\t\t\t\t\thasNewline = text.endsWith(NEWLINE);\n\t\t\t\t}\n\n\t\t\t\tif (nodeInfo.flags & IS_OLD) {\n\t\t\t\t\toldIndex += nodeInfo.length;\n\t\t\t\t}\n\t\t\t} else if (node.nodeName === \"BR\") {\n\t\t\t\tvalue += NEWLINE;\n\t\t\t\toffset += NEWLINE.length;\n\t\t\t\thasNewline = true;\n\t\t\t\tif (nodeInfo.flags & IS_OLD) {\n\t\t\t\t\toldIndex += nodeInfo.length;\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\tdescending = !!walker.firstChild();\n\t\t\t\tif (descending) {\n\t\t\t\t\tstack.push({nodeInfo, oldIndexRelative});\n\t\t\t\t\toffset = 0;\n\t\t\t\t\toldIndexRelative = oldIndex;\n\t\t\t\t}\n\t\t\t}\n\t\t} else {\n\t\t\tif (!stack.length) {\n\t\t\t\t// This should never happen.\n\t\t\t\tthrow new Error(\"Stack is empty\");\n\t\t\t}\n\n\t\t\t// If the child node prepends a newline, add to offset to increase the\n\t\t\t// length of the parent node.\n\t\t\tif (nodeInfo!.flags & PREPENDS_NEWLINE) {\n\t\t\t\toffset += NEWLINE.length;\n\t\t\t}\n\n\t\t\t({nodeInfo, oldIndexRelative} = stack.pop()!);\n\t\t\toffset = nodeInfo.offset + offset;\n\t\t}\n\n\t\tif (!descending) {\n\t\t\t// POST-ORDER LOGIC\n\t\t\tif (!(nodeInfo.flags & IS_VALID)) {\n\t\t\t\t// TODO: Figure out if we should always recalculate APPENDS_NEWLINE???\n\t\t\t\tif (!hasNewline && nodeInfo.flags & IS_BLOCKLIKE) {\n\t\t\t\t\tvalue += NEWLINE;\n\t\t\t\t\toffset += NEWLINE.length;\n\t\t\t\t\thasNewline = true;\n\t\t\t\t\tnodeInfo.flags |= APPENDS_NEWLINE;\n\t\t\t\t} else {\n\t\t\t\t\tnodeInfo.flags &= ~APPENDS_NEWLINE;\n\t\t\t\t}\n\n\t\t\t\tnodeInfo.length = offset - nodeInfo.offset;\n\t\t\t\tnodeInfo.flags |= IS_VALID;\n\t\t\t}\n\n\t\t\tnodeInfo.flags |= IS_OLD;\n\n\t\t\tdescending = !!walker.nextSibling();\n\t\t\tif (!descending) {\n\t\t\t\tif (walker.currentNode === _this) {\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\n\t\t\t\twalker.parentNode();\n\t\t\t}\n\t\t}\n\n\t\tif (oldIndex > oldValue.length) {\n\t\t\t// This should never happen.\n\t\t\tthrow new Error(\"cache length error\");\n\t\t}\n\t}\n\n\tconst selectionStart = getSelectionRange(_this).start;\n\t// TODO: Doing a diff over the entirety of both oldValue and value is a\n\t// performance bottleneck. Figure out how to reduce the search for changed\n\t// values.\n\treturn Edit.diff(\n\t\toldValue,\n\t\tvalue,\n\t\tMath.min(oldSelectionStart, selectionStart),\n\t);\n}\n\nfunction getStartNodeOffset(): [Node | null, number] {\n\tconst selection = document.getSelection();\n\tif (selection && selection.rangeCount) {\n\t\tconst range = selection.getRangeAt(0);\n\t\treturn [range.startContainer, range.startOffset];\n\t}\n\n\treturn [null, 0];\n}\n\nconst BLOCKLIKE_DISPLAYS = new Set([\n\t\"block\",\n\t\"flex\",\n\t\"grid\",\n\t\"flow-root\",\n\t\"list-item\",\n\t\"table\",\n\t\"table-row-group\",\n\t\"table-header-group\",\n\t\"table-footer-group\",\n\t\"table-row\",\n\t\"table-caption\",\n]);\n\nfunction isBlocklikeElement(node: Node): node is Element {\n\treturn (\n\t\tnode.nodeType === Node.ELEMENT_NODE &&\n\t\tBLOCKLIKE_DISPLAYS.has(\n\t\t\t// handle two-value display syntax like `display: block flex`\n\t\t\tgetComputedStyle(node as Element).display.split(\" \")[0],\n\t\t)\n\t);\n}\n\n/***********************/\n/*** Selection Logic ***/\n/***********************/\n/**\n * Finds the string index of a node and offset pair provided by a browser API\n * like document.getSelection() for a given root and cache.\n */\nfunction indexAt(\n\t_this: ContentAreaElement,\n\tnode: Node | null,\n\toffset: number,\n): number {\n\tconst cache = _this[_cache];\n\tif (node == null || !_this.contains(node)) {\n\t\treturn -1;\n\t}\n\n\tif (!cache.has(node)) {\n\t\t// If the node is not found in the cache but is contained in the root, then\n\t\t// it is the child of an element with a data-content attribute.\n\t\toffset = 0;\n\t\twhile (!cache.has(node)) {\n\t\t\tnode = node.parentNode!;\n\t\t}\n\t}\n\n\tlet index: number;\n\tif (node.nodeType === Node.TEXT_NODE) {\n\t\tconst nodeInfo = cache.get(node)!;\n\t\tindex = offset + nodeInfo.offset;\n\t\tnode = node.parentNode!;\n\t} else {\n\t\tif (offset <= 0) {\n\t\t\tindex = 0;\n\t\t} else if (offset >= node.childNodes.length) {\n\t\t\tconst nodeInfo = cache.get(node)!;\n\t\t\tindex =\n\t\t\t\tnodeInfo.flags & APPENDS_NEWLINE\n\t\t\t\t\t? nodeInfo.length - NEWLINE.length\n\t\t\t\t\t: nodeInfo.length;\n\t\t} else {\n\t\t\tlet child: Node | null = node.childNodes[offset];\n\t\t\twhile (child !== null && !cache.has(child)) {\n\t\t\t\tchild = child.previousSibling;\n\t\t\t}\n\n\t\t\tif (child === null) {\n\t\t\t\tindex = 0;\n\t\t\t} else {\n\t\t\t\tnode = child;\n\t\t\t\tconst nodeInfo = cache.get(node)!;\n\t\t\t\t// If the offset references an element which prepends a newline\n\t\t\t\t// (\"hello<div>world</div>\"), we have to start from -1 because the\n\t\t\t\t// element’s info.offset will not account for the newline.\n\t\t\t\tindex = nodeInfo.flags & PREPENDS_NEWLINE ? -1 : 0;\n\t\t\t}\n\t\t}\n\t}\n\n\tfor (; node !== _this; node = node.parentNode!) {\n\t\tconst nodeInfo = cache.get(node)!;\n\t\tindex += nodeInfo.offset;\n\t\tif (nodeInfo.flags & PREPENDS_NEWLINE) {\n\t\t\tindex += NEWLINE.length;\n\t\t}\n\t}\n\n\treturn index;\n}\n\n/**\n * Finds the node and offset pair to use with browser APIs like\n * selection.collapse() from a given string index.\n */\nfunction nodeOffsetAt(\n\t_this: ContentAreaElement,\n\tindex: number,\n): [Node | null, number] {\n\tif (index < 0) {\n\t\treturn [null, 0];\n\t}\n\n\tconst [node, offset] = findNodeOffset(_this, index);\n\tif (node && node.nodeName === \"BR\") {\n\t\t// Some browsers seem to have trouble when calling `selection.collapse()`\n\t\t// with a BR element, so we try to avoid returning them from this function.\n\t\treturn nodeOffsetFromChild(node);\n\t}\n\n\treturn [node, offset];\n}\n\n// TODO: Can this function be inlined?\nfunction findNodeOffset(\n\t_this: ContentAreaElement,\n\tindex: number,\n): [Node | null, number] {\n\tconst cache = _this[_cache];\n\tconst walker = document.createTreeWalker(\n\t\t_this,\n\t\tNodeFilter.SHOW_TEXT | NodeFilter.SHOW_ELEMENT,\n\t);\n\n\tfor (let node: Node | null = _this; node !== null; ) {\n\t\tconst nodeInfo = cache.get(node);\n\t\tif (nodeInfo == null) {\n\t\t\treturn nodeOffsetFromChild(node, index > 0);\n\t\t}\n\n\t\tif (nodeInfo.flags & PREPENDS_NEWLINE) {\n\t\t\tindex -= 1;\n\t\t}\n\n\t\tif (index === nodeInfo.length && node.nodeType === Node.TEXT_NODE) {\n\t\t\treturn [node, (node as Text).data.length];\n\t\t} else if (index >= nodeInfo.length) {\n\t\t\tindex -= nodeInfo.length;\n\t\t\tconst nextSibling = walker.nextSibling();\n\t\t\tif (nextSibling === null) {\n\t\t\t\t// This branch seems necessary mainly when working with data-content\n\t\t\t\t// nodes.\n\t\t\t\tif (node === _this) {\n\t\t\t\t\treturn [node, getNodeLength(node)];\n\t\t\t\t}\n\n\t\t\t\treturn nodeOffsetFromChild(walker.currentNode, true);\n\t\t\t}\n\n\t\t\tnode = nextSibling;\n\t\t} else {\n\t\t\tif (\n\t\t\t\tnode.nodeType === Node.ELEMENT_NODE &&\n\t\t\t\t(node as Element).hasAttribute(\"data-content\")\n\t\t\t) {\n\t\t\t\treturn nodeOffsetFromChild(node, index > 0);\n\t\t\t}\n\n\t\t\tconst firstChild = walker.firstChild();\n\t\t\tif (firstChild === null) {\n\t\t\t\tconst offset =\n\t\t\t\t\tnode.nodeType === Node.TEXT_NODE ? index : index > 0 ? 1 : 0;\n\t\t\t\treturn [node, offset];\n\t\t\t} else {\n\t\t\t\tnode = firstChild;\n\t\t\t}\n\t\t}\n\t}\n\n\tconst node = walker.currentNode;\n\treturn [node, getNodeLength(node)];\n}\n\nfunction getNodeLength(node: Node) {\n\tif (node.nodeType === Node.TEXT_NODE) {\n\t\treturn (node as Text).data.length;\n\t}\n\n\treturn node.childNodes.length;\n}\n\nfunction nodeOffsetFromChild(\n\tnode: Node,\n\tafter: boolean = false,\n): [Node | null, number] {\n\tconst parentNode = node.parentNode;\n\tif (parentNode === null) {\n\t\treturn [null, 0];\n\t}\n\n\tlet offset = Array.from(parentNode.childNodes).indexOf(node as ChildNode);\n\tif (after) {\n\t\toffset++;\n\t}\n\n\treturn [parentNode, offset];\n}\n\ninterface SelectionRange {\n\tstart: number;\n\tend: number;\n\tdirection: SelectionDirection;\n}\n\nfunction getSelectionRange(_this: ContentAreaElement): SelectionRange {\n\tconst selection = document.getSelection();\n\tif (!selection) {\n\t\treturn {start: 0, end: 0, direction: \"none\"};\n\t}\n\n\tconst {\n\t\tfocusNode,\n\t\tfocusOffset,\n\t\tanchorNode,\n\t\tanchorOffset,\n\t\tisCollapsed,\n\t} = selection;\n\tconst focus = Math.max(0, indexAt(_this, focusNode, focusOffset));\n\tconst anchor = isCollapsed\n\t\t? focus\n\t\t: Math.max(0, indexAt(_this, anchorNode, anchorOffset));\n\treturn {\n\t\tstart: Math.min(focus, anchor),\n\t\tend: Math.max(focus, anchor),\n\t\tdirection:\n\t\t\tfocus < anchor ? \"backward\" : focus > anchor ? \"forward\" : \"none\",\n\t};\n}\n\nfunction setSelectionRange(\n\t_this: ContentAreaElement,\n\t{start, end, direction}: SelectionRange,\n): void {\n\tconst selection = document.getSelection();\n\tif (!selection) {\n\t\treturn;\n\t}\n\n\tstart = Math.max(0, start || 0);\n\tend = Math.max(0, end || 0);\n\tif (end < start) {\n\t\tstart = end;\n\t}\n\n\t// Focus is the side of the selection where the pointer is released.\n\tconst [focus, anchor] =\n\t\tdirection === \"backward\" ? [start, end] : [end, start];\n\n\tif (focus === anchor) {\n\t\tconst [node, offset] = nodeOffsetAt(_this, focus);\n\t\tselection.collapse(node, offset);\n\t} else {\n\t\tconst [anchorNode, anchorOffset] = nodeOffsetAt(_this, anchor);\n\t\tconst [focusNode, focusOffset] = nodeOffsetAt(_this, focus);\n\t\tif (anchorNode === null && focusNode === null) {\n\t\t\tselection.collapse(null);\n\t\t} else if (anchorNode === null) {\n\t\t\tselection.collapse(focusNode, focusOffset);\n\t\t} else if (focusNode === null) {\n\t\t\tselection.collapse(anchorNode, anchorOffset);\n\t\t} else {\n\t\t\t// This method is not implemented in IE.\n\t\t\tselection.setBaseAndExtent(\n\t\t\t\tanchorNode,\n\t\t\t\tanchorOffset,\n\t\t\t\tfocusNode,\n\t\t\t\tfocusOffset,\n\t\t\t);\n\t\t}\n\t}\n}\n"],"names":["Edit"],"mappings":";;;;;;AAAA;AAGA;AACA,MAAM,OAAO,GAAG,IAAI,CAAC;AASf,MAAO,YAAa,SAAQ,WAA+B,CAAA;IAChE,WAAY,CAAA,OAAe,EAAE,SAA2B,EAAA;;AAEvD,QAAA,KAAK,CAAC,OAAO,EAAE,EAAC,OAAO,EAAE,IAAI,EAAE,GAAG,SAAS,EAAC,CAAC,CAAC;KAC9C;AACD,CAAA;AAID;AACA;AACA;AACA,MAAM,MAAM,GAAG,MAAM,CAAC,GAAG,CAAC,2BAA2B,CAAC,CAAC;AACvD,MAAM,MAAM,GAAG,MAAM,CAAC,GAAG,CAAC,2BAA2B,CAAC,CAAC;AACvD,MAAM,SAAS,GAAG,MAAM,CAAC,GAAG,CAAC,8BAA8B,CAAC,CAAC;AAC7D,MAAM,kBAAkB,GAAG,MAAM,CAAC,GAAG,CAAC,uCAAuC,CAAC,CAAC;AAC/E,MAAM,eAAe,GAAG,MAAM,CAAC,GAAG,CAAC,oCAAoC,CAAC,CAAC;AAEnE,MAAO,kBAAmB,SAAQ,WAAW,CAAA;AAMlD,IAAA,WAAA,GAAA;AACC,QAAA,KAAK,EAAE,CAAC;AAER,QAAA,IAAI,CAAC,MAAM,CAAC,GAAG,IAAI,GAAG,EAAE,CAAC;AACzB,QAAA,IAAI,CAAC,MAAM,CAAC,GAAG,EAAE,CAAC;QAClB,IAAI,CAAC,SAAS,CAAC,GAAG,IAAI,gBAAgB,CAAC,CAAC,OAAO,KAAI;AAClD,YAAA,QAAQ,CAAC,IAAI,EAAE,OAAO,CAAC,CAAC;AACzB,SAAC,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D,QAAA,IAAI,UAAU,KAAK,IAAI,IAAI,SAAS,KAAK,IAAI,EAAE;AAC9C,YAAA,SAAS,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC;AACzB,SAAA;aAAM,IAAI,UAAU,KAAK,IAAI,EAAE;AAC/B,YAAA,SAAS,CAAC,QAAQ,CAAC,SAAS,EAAE,WAAW,CAAC,CAAC;AAC3C,SAAA;aAAM,IAAI,SAAS,KAAK,IAAI,EAAE;AAC9B,YAAA,SAAS,CAAC,QAAQ,CAAC,UAAU,EAAE,YAAY,CAAC,CAAC;AAC7C,SAAA;AAAM,aAAA;;YAEN,SAAS,CAAC,gBAAgB,CACzB,UAAU,EACV,YAAY,EACZ,SAAS,EACT,WAAW,CACX,CAAC;AACF,SAAA;AACD,KAAA;AACF;;;;;"}
|
package/contentarea.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/// <reference lib="dom" />
|
|
2
|
-
import { Edit } from "./edit";
|
|
2
|
+
import { Edit } from "./edit.js";
|
|
3
3
|
export interface ContentEventDetail {
|
|
4
4
|
edit: Edit;
|
|
5
5
|
source: string | null;
|
|
@@ -9,67 +9,49 @@ export interface ContentEventInit extends CustomEventInit<ContentEventDetail> {
|
|
|
9
9
|
export declare class ContentEvent extends CustomEvent<ContentEventDetail> {
|
|
10
10
|
constructor(typeArg: string, eventInit: ContentEventInit);
|
|
11
11
|
}
|
|
12
|
-
|
|
13
|
-
/** A bitmask (see flags above) */
|
|
14
|
-
flags: number;
|
|
15
|
-
/** The string length of this node’s contents. */
|
|
16
|
-
size: number;
|
|
17
|
-
/** The start of this node’s contents relative to the start of the parent. */
|
|
18
|
-
offset: number;
|
|
19
|
-
constructor(offset: number);
|
|
20
|
-
}
|
|
21
|
-
declare type NodeInfoCache = Map<Node, NodeInfo>;
|
|
12
|
+
export type SelectionDirection = "forward" | "backward" | "none";
|
|
22
13
|
/********************************************/
|
|
23
|
-
/*** ContentAreaElement
|
|
14
|
+
/*** ContentAreaElement private property symbols ***/
|
|
24
15
|
/********************************************/
|
|
25
|
-
declare const
|
|
26
|
-
declare const
|
|
27
|
-
declare const
|
|
28
|
-
declare const
|
|
29
|
-
declare const
|
|
30
|
-
declare
|
|
31
|
-
|
|
32
|
-
[
|
|
33
|
-
[
|
|
34
|
-
[
|
|
35
|
-
[
|
|
36
|
-
[$selectionStart]: number;
|
|
37
|
-
[$onselectionchange]: () => void;
|
|
16
|
+
declare const _cache: unique symbol;
|
|
17
|
+
declare const _value: unique symbol;
|
|
18
|
+
declare const _observer: unique symbol;
|
|
19
|
+
declare const _onselectionchange: unique symbol;
|
|
20
|
+
declare const _selectionStart: unique symbol;
|
|
21
|
+
export declare class ContentAreaElement extends HTMLElement {
|
|
22
|
+
[_cache]: NodeInfoCache;
|
|
23
|
+
[_value]: string;
|
|
24
|
+
[_observer]: MutationObserver;
|
|
25
|
+
[_onselectionchange]: () => void;
|
|
26
|
+
[_selectionStart]: number;
|
|
38
27
|
constructor();
|
|
39
28
|
/******************************/
|
|
40
29
|
/*** Custom Element methods ***/
|
|
41
30
|
/******************************/
|
|
42
|
-
static get observedAttributes(): Array<string>;
|
|
43
31
|
connectedCallback(): void;
|
|
44
32
|
disconnectedCallback(): void;
|
|
45
|
-
attributeChangedCallback(name: string): void;
|
|
46
|
-
/***********************/
|
|
47
|
-
/*** Content methods ***/
|
|
48
|
-
/***********************/
|
|
49
33
|
get value(): string;
|
|
50
34
|
get selectionStart(): number;
|
|
51
|
-
set selectionStart(
|
|
35
|
+
set selectionStart(start: number);
|
|
52
36
|
get selectionEnd(): number;
|
|
53
|
-
set selectionEnd(
|
|
37
|
+
set selectionEnd(end: number);
|
|
54
38
|
get selectionDirection(): SelectionDirection;
|
|
55
|
-
set selectionDirection(
|
|
56
|
-
|
|
57
|
-
setSelectionRange(selectionStart: number, selectionEnd: number, selectionDirection?: SelectionDirection): void;
|
|
39
|
+
set selectionDirection(direction: SelectionDirection);
|
|
40
|
+
setSelectionRange(start: number, end: number, direction?: SelectionDirection): void;
|
|
58
41
|
indexAt(node: Node | null, offset: number): number;
|
|
59
42
|
nodeOffsetAt(index: number): [Node | null, number];
|
|
60
43
|
source(source: string): boolean;
|
|
61
44
|
}
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
/**
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
selectionStart: number;
|
|
72
|
-
selectionEnd: number;
|
|
73
|
-
selectionDirection: SelectionDirection;
|
|
45
|
+
/** Data associated with the child nodes of a ContentAreaElement. */
|
|
46
|
+
declare class NodeInfo {
|
|
47
|
+
/** The start of this node’s contents relative to the start of the parent. */
|
|
48
|
+
offset: number;
|
|
49
|
+
/** The string length of this node’s contents. */
|
|
50
|
+
length: number;
|
|
51
|
+
/** A bitmask (see flags above) */
|
|
52
|
+
flags: number;
|
|
53
|
+
constructor(offset: number);
|
|
74
54
|
}
|
|
55
|
+
/** Each ContentAreaElement is associated with its own private cache. */
|
|
56
|
+
type NodeInfoCache = Map<Node, NodeInfo>;
|
|
75
57
|
export {};
|