Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@remirror/core-utils

Package Overview
Dependencies
Maintainers
1
Versions
287
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@remirror/core-utils - npm Package Compare versions

Comparing version 1.0.0-next.32 to 1.0.0-next.33

50

CHANGELOG.md
# @remirror/core-utils
## 1.0.0-next.33
> 2020-09-07
### Minor Changes
- 7a34e15d: Update return signature of `getMarkRange` from `@remirror/core-utils` to also include the `mark` found. Additionally, to better support optional chaining it now returns `undefined` instead of `false` when no range can be found.
- 7a34e15d: Add `invalidMarks` support.
- Add the ability to disable all input rules if a certain mark is active.
- Fix the `ItalicExtension` regex which was over eager.
- Expose `decorationSet` for the `prosemirror-suggest` state.
- Export `markActiveInRange`, `rangeHasMarks`, `positionHasMarks` from `prosemirror-suggest`.
- Add helpers `getMarksByTags` and `getNodesByTags` to the `TagsExtension`.
- 7a34e15d: Enable disabling input rules with a `shouldSkip` method. This is now available as a handler for the `InputRulesExtension` via `shouldSkipInputRule`.
Consuming this API looks something like this.
```ts
import { PlainExtension, Dispose } from 'remirror/core';
class CoolExtension extends PlainExtension {
get name() {
return 'cool';
}
onCreate(): Dispose {
// Add the `shouldSkip` predicate check to this extension.
return this.store.getExtension(InputRulesExtension).addHandler('shouldSkipInputRule', () => {
if (something) {
return true;
}
return false;
});
}
}
```
### Patch Changes
- 92ed4135: Fix editable mentions support for exiting when text is selected. Also update `getSelection` to support `anchor` and `head` selections.
- Updated dependencies [7a34e15d]
- Updated dependencies [525ac3d8]
- Updated dependencies [92ed4135]
- @remirror/core-constants@1.0.0-next.33
- @remirror/core-types@1.0.0-next.33
- @remirror/core-helpers@1.0.0-next.33
## 1.0.0-next.32

@@ -4,0 +54,0 @@

107

dist/core-utils.cjs.prod.js

@@ -11,3 +11,3 @@ "use strict";

var coreHelpers = require("@remirror/core-helpers"), schemaList = require("@remirror/pm/schema-list"), state = require("@remirror/pm/state"), transform = require("@remirror/pm/transform"), _slicedToArray = _interopDefault(require("@babel/runtime/helpers/slicedToArray")), _objectWithoutProperties = _interopDefault(require("@babel/runtime/helpers/objectWithoutProperties")), _defineProperty = _interopDefault(require("@babel/runtime/helpers/defineProperty")), coreConstants = require("@remirror/core-constants"), model = require("@remirror/pm/model"), inputrules = require("@remirror/pm/inputrules"), environment = {
var coreHelpers = require("@remirror/core-helpers"), schemaList = require("@remirror/pm/schema-list"), state = require("@remirror/pm/state"), transform = require("@remirror/pm/transform"), _slicedToArray = _interopDefault(require("@babel/runtime/helpers/slicedToArray")), _objectWithoutProperties = _interopDefault(require("@babel/runtime/helpers/objectWithoutProperties")), _defineProperty = _interopDefault(require("@babel/runtime/helpers/defineProperty")), coreConstants = require("@remirror/core-constants"), model = require("@remirror/pm/model"), inputrules = require("@remirror/pm/inputrules"), suggest = require("@remirror/pm/suggest"), environment = {
get isBrowser() {

@@ -171,3 +171,3 @@ return coreHelpers.bool("undefined" != typeof window && void 0 !== window.document && window.navigator && window.navigator.userAgent);

function isMarkActive(parameter) {
var stateOrTransaction = parameter.trState, type = parameter.type, from = parameter.from, to = parameter.to, selection = stateOrTransaction.selection, doc = stateOrTransaction.doc, storedMarks = stateOrTransaction.storedMarks, $from = selection.$from, empty = selection.empty;
var trState = parameter.trState, type = parameter.type, from = parameter.from, to = parameter.to, selection = trState.selection, doc = trState.doc, storedMarks = trState.storedMarks, $from = selection.$from, empty = selection.empty;
if (from && to) try {

@@ -212,13 +212,17 @@ return Math.max(from, to) < doc.nodeSize && doc.rangeHasMark(from, to, type);

function getMarkRange($pos, type) {
if (!$pos || !type) return !1;
var start = $pos.parent.childAfter($pos.parentOffset);
if (!start.node) return !1;
var mark = start.node.marks.find(_ref => _ref.type === type);
if (!mark) return !1;
for (var startIndex = $pos.index(), startPos = $pos.start() + start.offset; startIndex > 0 && mark.isInSet($pos.parent.child(startIndex - 1).marks); ) startIndex -= 1,
startPos -= $pos.parent.child(startIndex).nodeSize;
return {
from: startPos,
to: startPos + start.node.nodeSize
};
if ($pos && type) {
var start = $pos.parent.childAfter($pos.parentOffset);
if (start.node) {
var mark = start.node.marks.find(_ref => _ref.type === type);
if (mark) {
for (var startIndex = $pos.index(), startPos = $pos.start() + start.offset; startIndex > 0 && mark.isInSet($pos.parent.child(startIndex - 1).marks); ) startIndex -= 1,
startPos -= $pos.parent.child(startIndex).nodeSize;
return {
from: startPos,
to: startPos + start.node.nodeSize,
mark: mark
};
}
}
}
}

@@ -306,2 +310,6 @@

function isAnchorHeadObject(value) {
return coreHelpers.isObject(value) && coreHelpers.isNumber(value.anchor) && coreHelpers.isNumber(value.head);
}
function getTextSelection(selection, doc) {

@@ -317,4 +325,8 @@ var pos, max = doc.nodeSize - 2, clampToDocument = value => coreHelpers.clamp({

state.TextSelection.near(doc.resolve(pos));
var start = clampToDocument(pos.from), end = clampToDocument(pos.to);
return state.TextSelection.create(doc, start, end);
if (isAnchorHeadObject(pos)) {
var _anchor = clampToDocument(pos.anchor), _head = clampToDocument(pos.head);
return state.TextSelection.create(doc, _anchor, _head);
}
var anchor = clampToDocument(pos.from), head = clampToDocument(pos.to);
return state.TextSelection.create(doc, anchor, head);
}

@@ -1043,6 +1055,6 @@

function preserveSelection(state$1, tr) {
var _step, anchor = state$1.selection.anchor, _iterator = _createForOfIteratorHelper$2(tr.steps);
var _step, head = state$1.selection.head, _iterator = _createForOfIteratorHelper$2(tr.steps);
try {
for (_iterator.s(); !(_step = _iterator.n()).done; ) {
anchor = _step.value.getMap().map(anchor);
head = _step.value.getMap().map(head);
}

@@ -1054,3 +1066,3 @@ } catch (err) {

}
tr.setSelection(new state.TextSelection(tr.doc.resolve(anchor)));
state$1.selection.empty ? tr.setSelection(state.TextSelection.create(tr.doc, head)) : tr.setSelection(state.TextSelection.create(tr.doc, state$1.selection.anchor, head));
}

@@ -1082,6 +1094,6 @@

if (expand) {
var _ref10 = range ? getMarkRange(tr.doc.resolve(range.from), type) || coreHelpers.isNumber(range.to) && getMarkRange(tr.doc.resolve(range.to), type) || {
var _getMarkRange, _ref10 = range ? getMarkRange(tr.doc.resolve(range.from), type) || coreHelpers.isNumber(range.to) && getMarkRange(tr.doc.resolve(range.to), type) || {
from: from,
to: to
} : isSelectionEmpty(tr) && getMarkRange(selection.$anchor, type) || {
} : isSelectionEmpty(tr) && null !== (_getMarkRange = getMarkRange(selection.$anchor, type)) && void 0 !== _getMarkRange ? _getMarkRange : {
from: from,

@@ -1262,5 +1274,9 @@ to: to

function markInputRule(parameter) {
var regexp = parameter.regexp, type = parameter.type, getAttributes = parameter.getAttributes, _parameter$ignoreWhit = parameter.ignoreWhitespace, ignoreWhitespace = void 0 !== _parameter$ignoreWhit && _parameter$ignoreWhit, beforeDispatch = parameter.beforeDispatch, updateCaptured = parameter.updateCaptured;
return new inputrules.InputRule(regexp, (state, match, start, end) => {
var _updateCaptured, _details$captureGroup, _details$fullMatch, _details$start, _details$end, tr = state.tr, attributes = coreHelpers.isFunction(getAttributes) ? getAttributes(match) : getAttributes, details = null !== (_updateCaptured = null == updateCaptured ? void 0 : updateCaptured({
var regexp = parameter.regexp, type = parameter.type, getAttributes = parameter.getAttributes, _parameter$ignoreWhit = parameter.ignoreWhitespace, ignoreWhitespace = void 0 !== _parameter$ignoreWhit && _parameter$ignoreWhit, beforeDispatch = parameter.beforeDispatch, updateCaptured = parameter.updateCaptured, rule = new inputrules.InputRule(regexp, (state, match, start, end) => {
var _updateCaptured, _details$captureGroup, _details$fullMatch, _details$start, _details$end, _rule$shouldSkip, tr = state.tr, attributes = coreHelpers.isFunction(getAttributes) ? getAttributes(match) : getAttributes, $from = state.doc.resolve(start), $to = state.doc.resolve(end);
if (rule.invalidMarks && suggest.markActiveInRange({
$from: $from,
$to: $to
}, rule.invalidMarks)) return null;
var details = null !== (_updateCaptured = null == updateCaptured ? void 0 : updateCaptured({
captureGroup: match[1],

@@ -1274,2 +1290,10 @@ fullMatch: match[0],

if (ignoreWhitespace && "" === (null == captureGroup ? void 0 : captureGroup.trim())) return null;
if (null === (_rule$shouldSkip = rule.shouldSkip) || void 0 === _rule$shouldSkip ? void 0 : _rule$shouldSkip.call(rule, {
state: state,
captureGroup: captureGroup,
fullMatch: fullMatch,
start: start,
end: end,
ruleType: "mark"
})) return null;
if (captureGroup) {

@@ -1289,9 +1313,16 @@ var _tr$storedMarks, startSpaces = fullMatch.search(/\S/), textStart = start + fullMatch.indexOf(captureGroup), textEnd = textStart + captureGroup.length;

});
return rule;
}
function nodeInputRule(parameter) {
var regexp = parameter.regexp, type = parameter.type, getAttributes = parameter.getAttributes, beforeDispatch = parameter.beforeDispatch;
return new inputrules.InputRule(regexp, (state, match, start, end) => {
var attributes = coreHelpers.isFunction(getAttributes) ? getAttributes(match) : getAttributes, tr = state.tr;
return tr.replaceWith(start - 1, end, type.create(attributes)), null == beforeDispatch || beforeDispatch({
var regexp = parameter.regexp, type = parameter.type, getAttributes = parameter.getAttributes, beforeDispatch = parameter.beforeDispatch, rule = new inputrules.InputRule(regexp, (state, match, start, end) => {
var _rule$shouldSkip2, attributes = coreHelpers.isFunction(getAttributes) ? getAttributes(match) : getAttributes, tr = state.tr, captureGroup = match[1], fullMatch = match[0];
return (null === (_rule$shouldSkip2 = rule.shouldSkip) || void 0 === _rule$shouldSkip2 ? void 0 : _rule$shouldSkip2.call(rule, {
state: state,
captureGroup: captureGroup,
fullMatch: fullMatch,
start: start,
end: end,
ruleType: "plain"
})) ? null : (tr.replaceWith(start - 1, end, type.create(attributes)), null == beforeDispatch || beforeDispatch({
tr: tr,

@@ -1301,13 +1332,20 @@ match: match,

end: end
}), tr;
}), tr);
});
return rule;
}
function plainInputRule(parameter) {
var regexp = parameter.regexp, transformMatch = parameter.transformMatch, beforeDispatch = parameter.beforeDispatch;
return new inputrules.InputRule(regexp, (state, match, start, end) => {
var value = transformMatch(match);
var regexp = parameter.regexp, transformMatch = parameter.transformMatch, beforeDispatch = parameter.beforeDispatch, rule = new inputrules.InputRule(regexp, (state, match, start, end) => {
var _rule$shouldSkip3, value = transformMatch(match);
if (coreHelpers.isNullOrUndefined(value)) return null;
var tr = state.tr;
return "" === value ? tr.delete(start, end) : tr.replaceWith(start, end, state.schema.text(value)),
var tr = state.tr, captureGroup = match[1], fullMatch = match[0];
return (null === (_rule$shouldSkip3 = rule.shouldSkip) || void 0 === _rule$shouldSkip3 ? void 0 : _rule$shouldSkip3.call(rule, {
state: state,
captureGroup: captureGroup,
fullMatch: fullMatch,
start: start,
end: end,
ruleType: "plain"
})) ? null : ("" === value ? tr.delete(start, end) : tr.replaceWith(start, end, state.schema.text(value)),
null == beforeDispatch || beforeDispatch({

@@ -1318,4 +1356,5 @@ tr: tr,

end: end
}), tr;
}), tr);
});
return rule;
}

@@ -1322,0 +1361,0 @@

@@ -99,3 +99,3 @@ import type { AttributesParameter, CommandFunction, CommandFunctionParameter, MarkType, MarkTypeParameter, NodeType, NodeTypeParameter, ProsemirrorAttributes, ProsemirrorCommandFunction, RangeParameter } from '@remirror/core-types';

/**
* Replaces text with an optional appended string at the end
* Replaces text with an optional appended string at the end.
*

@@ -102,0 +102,0 @@ * @param params - the destructured params

@@ -1,2 +0,2 @@

import type { EditorSchema, EditorState, FromToParameter, MarkAttributes, MarkTypeParameter, PrimitiveSelection, ProsemirrorNode, ProsemirrorNodeParameter, RemirrorContentType, RemirrorJSON, RenderEnvironment, ResolvedPos, SchemaParameter, Selection, Transaction, TrStateParameter } from '@remirror/core-types';
import type { AnchorHeadParameter, EditorSchema, EditorState, FromToParameter, MarkAttributes, MarkTypeParameter, PrimitiveSelection, ProsemirrorNode, ProsemirrorNodeParameter, RemirrorContentType, RemirrorJSON, RenderEnvironment, ResolvedPos, SchemaParameter, Selection, Transaction, TrStateParameter } from '@remirror/core-types';
import { Mark, MarkType, NodeType, ResolvedPos as PMResolvedPos, Slice } from '@remirror/pm/model';

@@ -111,2 +111,8 @@ import { AllSelection, EditorState as PMEditorState, NodeSelection, Selection as PMSelection, TextSelection, Transaction as PMTransaction } from '@remirror/pm/state';

export declare function getMarkAttributes(trState: EditorState | Transaction, type: MarkType): MarkAttributes | false;
interface GetMarkRangeParameter extends FromToParameter {
/**
* The mark that was found within the active range.
*/
mark: Mark;
}
/**

@@ -121,3 +127,3 @@ * Retrieve the `start` and `end` position of a mark. The `$pos` value should be

*/
export declare function getMarkRange($pos: ResolvedPos, type: MarkType): FromToParameter | false;
export declare function getMarkRange($pos: ResolvedPos, type: MarkType): GetMarkRangeParameter | undefined;
/**

@@ -276,2 +282,6 @@ * Retrieves the text content from a slice

/**
* Return true when the provided value is an anchor / head selection property
*/
export declare function isAnchorHeadObject(value: unknown): value is AnchorHeadParameter;
/**
* Get a valid selection from the primitive selection.

@@ -468,3 +478,4 @@ */

* @param json - the content as a json object.
* @param invalidContent - the list of invalid items as passed to the error handler.
* @param invalidContent - the list of invalid items as passed to the error
* handler.
*/

@@ -471,0 +482,0 @@ remove(json: RemirrorJSON, invalidContent: InvalidContentBlock[]): RemirrorJSON;

@@ -9,4 +9,5 @@ export { emptyCommandFunction, isChrome, lift, removeMark, replaceText, setBlockType, toggleBlockItem, toggleList, toggleWrap, updateMark, wrapIn, } from './command-utils';

export { containsNodesOfType, findBlockNodes, findChildren, findChildrenByAttribute, findChildrenByMark, findChildrenByNode, findInlineNodes, findTextNodes, flattenNodeDescendants as flatten, } from './prosemirror-node-utils';
export type { ShouldSkipFunction, SkippableInputRule, ShouldSkipParameter, } from './prosemirror-rules';
export { markInputRule, markPasteRule, nodeInputRule, plainInputRule } from './prosemirror-rules';
export type { FindProsemirrorNodeResult, FindSelectedNodeOfType, NonChainableCommandFunction, SchemaJSON, } from './prosemirror-utils';
export { applyClonedTransaction, chainCommands, chainKeyBindingCommands, cloneTransaction, convertCommand, findElementAtPosition, findNodeAtPosition, findNodeAtSelection, findParentNode, findParentNodeOfType, findPositionOfNodeAfter, findPositionOfNodeBefore, findSelectedNodeOfType, hasTransactionChanged, isNodeActive, isNodeOfType, isSelectionEmpty, markEqualsType, mergeKeyBindings, mergeProsemirrorKeyBindings, nonChainable, removeNodeAfter, removeNodeAtPosition, removeNodeBefore, replaceNodeAtPosition, schemaToJSON, } from './prosemirror-utils';

@@ -1,2 +0,2 @@

import type { GetAttributesParameter, MarkTypeParameter, NodeTypeParameter, ProsemirrorPlugin, RegExpParameter, TransactionParameter } from '@remirror/core-types';
import type { EditorStateParameter, GetAttributesParameter, MarkTypeParameter, NodeTypeParameter, ProsemirrorPlugin, RegExpParameter, TransactionParameter } from '@remirror/core-types';
import { InputRule } from '@remirror/pm/inputrules';

@@ -108,3 +108,3 @@ export interface BeforeDispatchParameter extends TransactionParameter {

*/
export declare function markInputRule(parameter: MarkInputRuleParameter): InputRule;
export declare function markInputRule(parameter: MarkInputRuleParameter): SkippableInputRule;
/**

@@ -117,3 +117,3 @@ * Creates a node input rule based on the provided regex for the provided node

*/
export declare function nodeInputRule(parameter: NodeInputRuleParameter): InputRule;
export declare function nodeInputRule(parameter: NodeInputRuleParameter): SkippableInputRule;
/**

@@ -123,3 +123,38 @@ * Creates a plain rule based on the provided regex. You can see this being used

*/
export declare function plainInputRule(parameter: PlainInputRuleParameter): InputRule;
export declare function plainInputRule(parameter: PlainInputRuleParameter): SkippableInputRule;
export interface ShouldSkipParameter extends EditorStateParameter, UpdateCaptureTextParameter {
/** The type of input rule that has been activated */
ruleType: 'mark' | 'node' | 'plain';
}
interface ShouldSkip {
/**
* Every input rule calls this function before deciding whether or not to run.
*
* This is run for every successful input rule match to check if there are any
* reasons to prevent it from running.
*
* In particular it is so that the input rule only runs when there are no
* active checks that prevent it from doing so.
*
* - Other extension can register a `shouldSkip` handler
* - Every time in input rule is running it makes sure it isn't blocked is run it makes sure it can run
*/
shouldSkip?: ShouldSkipFunction;
/**
* A list of marks which if existing in the provided range should invalidate the range.
*/
invalidMarks?: string[];
}
/**
* A function which is called to check whether an input rule should be skipped.
*
* - When it returns false then it won't be skipped.
* - When it returns true then it will be skipped.
*/
export declare type ShouldSkipFunction = (parameter: ShouldSkipParameter) => boolean;
/**
* An input rule which can have a `shouldSkip` property that returns true when
* the input rule should be skipped.
*/
export declare type SkippableInputRule = ShouldSkip & InputRule;
export {};
{
"name": "@remirror/core-utils",
"version": "1.0.0-next.32",
"version": "1.0.0-next.33",
"description": "Core utilities for dealing with the dom and prosemirror within remirror",

@@ -24,5 +24,5 @@ "homepage": "https://github.com/remirror/remirror/tree/HEAD/packages/@remirror/core-utils",

"@babel/runtime": "^7.11.0",
"@remirror/core-constants": "1.0.0-next.32",
"@remirror/core-helpers": "1.0.0-next.32",
"@remirror/core-types": "1.0.0-next.32",
"@remirror/core-constants": "1.0.0-next.33",
"@remirror/core-helpers": "1.0.0-next.33",
"@remirror/core-types": "1.0.0-next.33",
"@types/min-document": "^2.19.0",

@@ -29,0 +29,0 @@ "min-document": "^2.19.0"

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is too big to display

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc