@inscreen/rich-text
Advanced tools
Comparing version 0.1.10 to 0.1.11
@@ -17,2 +17,6 @@ import type { RichText, RichTextNode } from './types'; | ||
toZeroWidthRange(): RichTextRange; | ||
/** Always returns with offset=0 */ | ||
get nextNodeInParagraph(): RichTextPosition | undefined; | ||
/** Always returns with offset=0 */ | ||
get previousNodeInParagraph(): RichTextPosition | undefined; | ||
} | ||
@@ -19,0 +23,0 @@ export declare class RichTextRange { |
@@ -61,2 +61,14 @@ "use strict"; | ||
} | ||
/** Always returns with offset=0 */ | ||
get nextNodeInParagraph() { | ||
if (this.text.paragraphs[this.nodeId.paragraphIdx].nodes.length > this.nodeId.nodeIdx + 1) { | ||
return new RichTextPosition(this.text, { ...this.nodeId, nodeIdx: this.nodeId.nodeIdx + 1 }, 0); | ||
} | ||
} | ||
/** Always returns with offset=0 */ | ||
get previousNodeInParagraph() { | ||
if (this.nodeId.nodeIdx > 0) { | ||
return new RichTextPosition(this.text, { ...this.nodeId, nodeIdx: this.nodeId.nodeIdx - 1 }, 0); | ||
} | ||
} | ||
} | ||
@@ -63,0 +75,0 @@ exports.RichTextPosition = RichTextPosition; |
@@ -14,2 +14,3 @@ import { RichTextNodeId, RichTextRange } from './selection'; | ||
export declare type RichTextNodeReference = RichTextNodeId & { | ||
text: RichText; | ||
paragraph: RichTextParagraph; | ||
@@ -16,0 +17,0 @@ node: RichTextNode; |
@@ -15,2 +15,3 @@ "use strict"; | ||
nodeIdx, | ||
text, | ||
paragraph, | ||
@@ -29,2 +30,3 @@ node, | ||
nodeIdx, | ||
text, | ||
paragraph, | ||
@@ -39,3 +41,3 @@ node, | ||
else { | ||
process({ paragraphIdx, nodeIdx, paragraph, node, matched: false }); | ||
process({ paragraphIdx, nodeIdx, text, paragraph, node, matched: false }); | ||
} | ||
@@ -48,2 +50,3 @@ } | ||
nodeIdx, | ||
text, | ||
paragraph, | ||
@@ -59,2 +62,3 @@ node, | ||
nodeIdx, | ||
text, | ||
paragraph, | ||
@@ -66,3 +70,3 @@ node, | ||
else { | ||
process({ paragraphIdx, nodeIdx, paragraph, node, matched: false }); | ||
process({ paragraphIdx, nodeIdx, text, paragraph, node, matched: false }); | ||
} | ||
@@ -74,2 +78,3 @@ } | ||
nodeIdx, | ||
text, | ||
paragraph, | ||
@@ -187,6 +192,7 @@ node, | ||
walk(state.text, state.range, (ref) => { | ||
var _a, _b, _c; | ||
var _a, _b, _c, _d, _e; | ||
if (ref.paragraphIdx !== lastSeenParagraphIdx) { | ||
lastSeenParagraphIdx = ref.paragraphIdx; | ||
lastSeenIsText = false; | ||
// TODO: Do we need to add an empty text if the previous paragraph had zero nodes? | ||
result.addParagraph(); | ||
@@ -228,9 +234,15 @@ } | ||
else { | ||
// Remove empty text nodes, unless it needs to be kept | ||
const oneBeforeLastNodeInParagraph = ref.paragraph.nodes[ref.paragraph.nodes.length - 2]; | ||
// Remove empty text nodes, unless they need to be kept. | ||
const nodePosition = new selection_1.RichTextPosition(ref.text, ref, 0); | ||
if (ref.node.text === '' && | ||
!(ref.nodeIdx === 0 && | ||
(((_a = ref.paragraph.nodes[1]) === null || _a === void 0 ? void 0 : _a.type) !== 'text' || ((_b = ref.paragraph.nodes[1]) === null || _b === void 0 ? void 0 : _b.text) === '')) && | ||
!(ref.nodeIdx === ref.paragraph.nodes.length - 1 && | ||
((oneBeforeLastNodeInParagraph === null || oneBeforeLastNodeInParagraph === void 0 ? void 0 : oneBeforeLastNodeInParagraph.type) !== 'text' || (oneBeforeLastNodeInParagraph === null || oneBeforeLastNodeInParagraph === void 0 ? void 0 : oneBeforeLastNodeInParagraph.text) !== 'text'))) { | ||
!(nodePosition.previousNodeInParagraph === undefined && | ||
(((_a = nodePosition.nextNodeInParagraph) === null || _a === void 0 ? void 0 : _a.node.type) !== 'text' || | ||
((_b = nodePosition.nextNodeInParagraph) === null || _b === void 0 ? void 0 : _b.node.text) === '')) && | ||
!(nodePosition.nextNodeInParagraph === undefined && | ||
(((_c = nodePosition.previousNodeInParagraph) === null || _c === void 0 ? void 0 : _c.node.type) !== 'text' || | ||
((_d = nodePosition.previousNodeInParagraph) === null || _d === void 0 ? void 0 : _d.node.text) === '')) && | ||
!(nodePosition.previousNodeInParagraph && | ||
nodePosition.nextNodeInParagraph && | ||
nodePosition.previousNodeInParagraph.node.type !== 'text' && | ||
nodePosition.nextNodeInParagraph.node.type !== 'text')) { | ||
if (ref.startOffset !== undefined) { | ||
@@ -245,3 +257,3 @@ markNextNodeAsRangeStart = true; | ||
// Normalize the format, removing undefined and empty objects. | ||
const format = (_c = ref.node.format) !== null && _c !== void 0 ? _c : {}; | ||
const format = (_e = ref.node.format) !== null && _e !== void 0 ? _e : {}; | ||
let foundAnyFormat = false; | ||
@@ -248,0 +260,0 @@ for (const key of types_1.richTextFormatKeys) { |
{ | ||
"name": "@inscreen/rich-text", | ||
"version": "0.1.10", | ||
"version": "0.1.11", | ||
"description": "Lightweight rich-text functionality", | ||
@@ -5,0 +5,0 @@ "main": "dist/index.js", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
46181
1036