slate-react-placeholder
Advanced tools
Comparing version
@@ -33,2 +33,8 @@ (function (global, factory) { | ||
/* | ||
* Instance counter to enable unique marks for multiple Placeholder instances. | ||
*/ | ||
var instanceCounter = 0; | ||
/** | ||
@@ -43,2 +49,9 @@ * A plugin that renders a React placeholder for a given Slate node. | ||
var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; | ||
var instanceId = instanceCounter++; | ||
var placeholderMark = { | ||
type: 'placeholder', | ||
data: { key: instanceId } | ||
}; | ||
var placeholder = options.placeholder, | ||
@@ -72,3 +85,3 @@ when = options.when; | ||
focus: { key: last.key, offset: last.text.length }, | ||
mark: { type: 'placeholder' } | ||
mark: placeholderMark | ||
}; | ||
@@ -93,3 +106,3 @@ | ||
if (mark.type === 'placeholder') { | ||
if (mark.type === 'placeholder' && mark.data.get('key') === instanceId) { | ||
var style = { | ||
@@ -96,0 +109,0 @@ pointerEvents: 'none', |
@@ -1,1 +0,1 @@ | ||
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("react")):"function"==typeof define&&define.amd?define(["exports","react"],t):t(e.SlateReactPlaceholder={},e.React)}(this,function(e,t){"use strict";t=t&&t.hasOwnProperty("default")?t.default:t;var r=function(e,t){if(!e)throw new Error("Invariant failed")},n=function(e){if(Array.isArray(e)){for(var t=0,r=Array(e.length);t<e.length;t++)r[t]=e[t];return r}return Array.from(e)};e.default=function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},a=e.placeholder,o=e.when;return r(a,"You must pass `SlateReactPlaceholder` an `options.placeholder` string."),r(o,"You must pass `SlateReactPlaceholder` an `options.when` query."),{decorateNode:function(e,t,r){if(!t.query(o,e))return r();var a=r(),l=e.getFirstText(),i=e.getLastText(),c={anchor:{key:l.key,offset:0},focus:{key:i.key,offset:i.text.length},mark:{type:"placeholder"}};return[].concat(n(a),[c])},renderMark:function(e,r,n){var o=e.children;return"placeholder"===e.mark.type?t.createElement("span",null,t.createElement("span",{contentEditable:!1,style:{pointerEvents:"none",display:"inline-block",width:"0",maxWidth:"100%",whiteSpace:"nowrap",opacity:"0.333"}},a),o):n()}}},Object.defineProperty(e,"__esModule",{value:!0})}); | ||
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("react")):"function"==typeof define&&define.amd?define(["exports","react"],t):t(e.SlateReactPlaceholder={},e.React)}(this,function(e,t){"use strict";t=t&&t.hasOwnProperty("default")?t.default:t;var r=function(e,t){if(!e)throw new Error("Invariant failed")},n=function(e){if(Array.isArray(e)){for(var t=0,r=Array(e.length);t<e.length;t++)r[t]=e[t];return r}return Array.from(e)},a=0;e.default=function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},o=a++,l={type:"placeholder",data:{key:o}},i=e.placeholder,c=e.when;return r(i,"You must pass `SlateReactPlaceholder` an `options.placeholder` string."),r(c,"You must pass `SlateReactPlaceholder` an `options.when` query."),{decorateNode:function(e,t,r){if(!t.query(c,e))return r();var a=r(),o=e.getFirstText(),i=e.getLastText(),d={anchor:{key:o.key,offset:0},focus:{key:i.key,offset:i.text.length},mark:l};return[].concat(n(a),[d])},renderMark:function(e,r,n){var a=e.children,l=e.mark;return"placeholder"===l.type&&l.data.get("key")===o?t.createElement("span",null,t.createElement("span",{contentEditable:!1,style:{pointerEvents:"none",display:"inline-block",width:"0",maxWidth:"100%",whiteSpace:"nowrap",opacity:"0.333"}},i),a):n()}}},Object.defineProperty(e,"__esModule",{value:!0})}); |
@@ -27,2 +27,8 @@ import React from 'react'; | ||
/* | ||
* Instance counter to enable unique marks for multiple Placeholder instances. | ||
*/ | ||
var instanceCounter = 0; | ||
/** | ||
@@ -37,2 +43,9 @@ * A plugin that renders a React placeholder for a given Slate node. | ||
var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; | ||
var instanceId = instanceCounter++; | ||
var placeholderMark = { | ||
type: 'placeholder', | ||
data: { key: instanceId } | ||
}; | ||
var placeholder = options.placeholder, | ||
@@ -66,3 +79,3 @@ when = options.when; | ||
focus: { key: last.key, offset: last.text.length }, | ||
mark: { type: 'placeholder' } | ||
mark: placeholderMark | ||
}; | ||
@@ -87,3 +100,3 @@ | ||
if (mark.type === 'placeholder') { | ||
if (mark.type === 'placeholder' && mark.data.get('key') === instanceId) { | ||
var style = { | ||
@@ -90,0 +103,0 @@ pointerEvents: 'none', |
@@ -33,2 +33,8 @@ 'use strict'; | ||
/* | ||
* Instance counter to enable unique marks for multiple Placeholder instances. | ||
*/ | ||
var instanceCounter = 0; | ||
/** | ||
@@ -43,2 +49,9 @@ * A plugin that renders a React placeholder for a given Slate node. | ||
var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; | ||
var instanceId = instanceCounter++; | ||
var placeholderMark = { | ||
type: 'placeholder', | ||
data: { key: instanceId } | ||
}; | ||
var placeholder = options.placeholder, | ||
@@ -72,3 +85,3 @@ when = options.when; | ||
focus: { key: last.key, offset: last.text.length }, | ||
mark: { type: 'placeholder' } | ||
mark: placeholderMark | ||
}; | ||
@@ -93,3 +106,3 @@ | ||
if (mark.type === 'placeholder') { | ||
if (mark.type === 'placeholder' && mark.data.get('key') === instanceId) { | ||
var style = { | ||
@@ -96,0 +109,0 @@ pointerEvents: 'none', |
{ | ||
"name": "slate-react-placeholder", | ||
"description": "A Slate plugin to render a placeholder with React.", | ||
"version": "0.1.12", | ||
"version": "0.1.13", | ||
"license": "MIT", | ||
@@ -21,3 +21,3 @@ "repository": "git://github.com/ianstormtaylor/slate.git", | ||
"mocha": "^2.5.3", | ||
"slate": "^0.44.9", | ||
"slate": "^0.44.10", | ||
"tiny-invariant": "^1.0.1" | ||
@@ -24,0 +24,0 @@ }, |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
41831
4.59%642
4.56%