@remirror/extension-events
Advanced tools
Comparing version 3.0.0-beta.1 to 3.0.0-beta.2
@@ -1,2 +0,5 @@ | ||
var _initClass, _EventsExtension, _dec, _dec2, _initProto; | ||
var _initClass, _EventsExtension, _dec, _dec2, _initProto, _class; | ||
function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; } | ||
function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return typeof key === "symbol" ? key : String(key); } | ||
function _toPrimitive(input, hint) { if (typeof input !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (typeof res !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); } | ||
function createAddInitializerMethod(e, t) { return function (r) { assertNotFinished(t, "addInitializer"), assertCallable(r, "An initializer"), e.push(r); }; } | ||
@@ -96,11 +99,76 @@ function assertInstanceIfPrivate(e, t) { if (!e(t)) throw new TypeError("Attempted to access private element on non-instance"); } | ||
defaultPriority: ExtensionPriority.High | ||
}), _dec2 = helper(), class EventsExtension extends PlainExtension { | ||
static { | ||
({ | ||
e: [_initProto], | ||
c: [_EventsExtension, _initClass] | ||
} = _applyDecs(this, [[_dec2, 2, "isInteracting"]], [_dec])); | ||
} | ||
}), _dec2 = helper(), (_class = class EventsExtension extends PlainExtension { | ||
constructor(...args) { | ||
super(...args); | ||
/** | ||
* Indicates whether the user is currently interacting with the editor. | ||
*/ | ||
_defineProperty(this, "mousedown", false); | ||
/** | ||
* True when the mouse is within the bounds of the editor. | ||
*/ | ||
_defineProperty(this, "mouseover", false); | ||
_defineProperty(this, "createMouseEventHandler", fn => (view, mouseEvent) => { | ||
const event = mouseEvent; | ||
const eventPosition = getPositionFromEvent(view, event); | ||
if (!eventPosition) { | ||
return false; | ||
} | ||
const nodes = []; | ||
const marks = []; | ||
const { | ||
inside, | ||
pos | ||
} = eventPosition; | ||
if (inside === -1) { | ||
return false; | ||
} | ||
const $pos = view.state.doc.resolve(pos); | ||
const currentNodeDepth = $pos.depth + 1; | ||
for (const index of range(currentNodeDepth, 1)) { | ||
nodes.push({ | ||
node: index > $pos.depth && $pos.nodeAfter ? $pos.nodeAfter : $pos.node(index), | ||
pos: $pos.before(index) | ||
}); | ||
} | ||
for (const { | ||
type | ||
} of $pos.marksAcross($pos) ?? []) { | ||
const range2 = getMarkRange($pos, type); | ||
if (range2) { | ||
marks.push(range2); | ||
} | ||
} | ||
return fn(event, { | ||
view, | ||
nodes, | ||
marks, | ||
getMark: markType => { | ||
const type = isString(markType) ? view.state.schema.marks[markType] : markType; | ||
invariant(type, { | ||
code: ErrorConstant.EXTENSION, | ||
message: `The mark ${markType} being checked does not exist within the editor schema.` | ||
}); | ||
return marks.find(range2 => range2.mark.type === type); | ||
}, | ||
getNode: nodeType => { | ||
var _nodes$; | ||
const type = isString(nodeType) ? view.state.schema.nodes[nodeType] : nodeType; | ||
invariant(type, { | ||
code: ErrorConstant.EXTENSION, | ||
message: "The node being checked does not exist" | ||
}); | ||
const nodeWithPos = nodes.find(({ | ||
node | ||
}) => node.type === type); | ||
if (!nodeWithPos) { | ||
return; | ||
} | ||
return { | ||
...nodeWithPos, | ||
isRoot: !!((_nodes$ = nodes[0]) !== null && _nodes$ !== void 0 && _nodes$.node.eq(nodeWithPos.node)) | ||
}; | ||
} | ||
}); | ||
}); | ||
_initProto(this); | ||
@@ -112,10 +180,2 @@ } | ||
/** | ||
* Indicates whether the user is currently interacting with the editor. | ||
*/ | ||
mousedown = false; | ||
/** | ||
* True when the mouse is within the bounds of the editor. | ||
*/ | ||
mouseover = false; | ||
/** | ||
* Add a new lifecycle method which is available to all extensions for adding | ||
@@ -125,13 +185,13 @@ * a click handler to the node or mark. | ||
onView() { | ||
if ( | ||
// managerSettings excluded this from running | ||
this.store.managerSettings.exclude?.clickHandler) { | ||
var _this$store$managerSe; | ||
if ( // managerSettings excluded this from running | ||
(_this$store$managerSe = this.store.managerSettings.exclude) !== null && _this$store$managerSe !== void 0 && _this$store$managerSe.clickHandler) { | ||
return; | ||
} | ||
for (const extension2 of this.store.extensions) { | ||
var _extension2$options$e; | ||
if ( | ||
// Method doesn't exist | ||
!extension2.createEventHandlers || | ||
// Extension settings exclude it | ||
extension2.options.exclude?.clickHandler) { | ||
!extension2.createEventHandlers || // Extension settings exclude it | ||
(_extension2$options$e = extension2.options.exclude) !== null && _extension2$options$e !== void 0 && _extension2$options$e.clickHandler) { | ||
continue; | ||
@@ -282,68 +342,6 @@ } | ||
} | ||
createMouseEventHandler = fn => (view, mouseEvent) => { | ||
const event = mouseEvent; | ||
const eventPosition = getPositionFromEvent(view, event); | ||
if (!eventPosition) { | ||
return false; | ||
} | ||
const nodes = []; | ||
const marks = []; | ||
const { | ||
inside, | ||
pos | ||
} = eventPosition; | ||
if (inside === -1) { | ||
return false; | ||
} | ||
const $pos = view.state.doc.resolve(pos); | ||
const currentNodeDepth = $pos.depth + 1; | ||
for (const index of range(currentNodeDepth, 1)) { | ||
nodes.push({ | ||
node: index > $pos.depth && $pos.nodeAfter ? $pos.nodeAfter : $pos.node(index), | ||
pos: $pos.before(index) | ||
}); | ||
} | ||
for (const { | ||
type | ||
} of $pos.marksAcross($pos) ?? []) { | ||
const range2 = getMarkRange($pos, type); | ||
if (range2) { | ||
marks.push(range2); | ||
} | ||
} | ||
return fn(event, { | ||
view, | ||
nodes, | ||
marks, | ||
getMark: markType => { | ||
const type = isString(markType) ? view.state.schema.marks[markType] : markType; | ||
invariant(type, { | ||
code: ErrorConstant.EXTENSION, | ||
message: `The mark ${markType} being checked does not exist within the editor schema.` | ||
}); | ||
return marks.find(range2 => range2.mark.type === type); | ||
}, | ||
getNode: nodeType => { | ||
const type = isString(nodeType) ? view.state.schema.nodes[nodeType] : nodeType; | ||
invariant(type, { | ||
code: ErrorConstant.EXTENSION, | ||
message: "The node being checked does not exist" | ||
}); | ||
const nodeWithPos = nodes.find(({ | ||
node | ||
}) => node.type === type); | ||
if (!nodeWithPos) { | ||
return; | ||
} | ||
return { | ||
...nodeWithPos, | ||
isRoot: !!nodes[0]?.node.eq(nodeWithPos.node) | ||
}; | ||
} | ||
}); | ||
}; | ||
static { | ||
_initClass(); | ||
} | ||
}), _EventsExtension); | ||
}, ({ | ||
e: [_initProto], | ||
c: [_EventsExtension, _initClass] | ||
} = _applyDecs(_class, [[_dec2, 2, "isInteracting"]], [_dec])), _initClass())), _EventsExtension); | ||
function createClickMarkState(props) { | ||
@@ -350,0 +348,0 @@ const { |
{ | ||
"name": "@remirror/extension-events", | ||
"version": "3.0.0-beta.1", | ||
"version": "3.0.0-beta.2", | ||
"description": "Manage your remirror editor dom events.", | ||
@@ -38,3 +38,3 @@ "keywords": [ | ||
"@babel/runtime": "^7.22.3", | ||
"@remirror/core": "3.0.0-beta.1", | ||
"@remirror/core": "3.0.0-beta.2", | ||
"@remirror/messages": "3.0.0-beta.1" | ||
@@ -41,0 +41,0 @@ }, |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
151302
1936
+ Added@remirror/core@3.0.0-beta.2(transitive)
- Removed@remirror/core@3.0.0-beta.1(transitive)
Updated@remirror/core@3.0.0-beta.2