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

slate-hyperscript

Package Overview
Dependencies
Maintainers
1
Versions
393
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

slate-hyperscript - npm Package Compare versions

Comparing version 0.5.22 to 0.6.0

18

Changelog.md

@@ -7,2 +7,10 @@ # Changelog

### `0.6.0` — July 27, 2018
###### NEW
**Updated to work with the `slate@0.35.0` with paths.** The original logic for selections and decorations didn't account for paths properly. This isn't a breaking change, but to use this library with the latest Slate you'll need to upgrade.
---
### `0.5.0` — January 4, 2018

@@ -12,3 +20,3 @@

* **The `kind` property of Slate objects has been renamed to `object`.** This is to reduce the confusion over the difference between "kind" and "type" which are practically synonyms. The "object" name was chosen to match the Stripe API, since it seems like a sensible choice and reads much more nicely when looking through JSON.
**The `kind` property of Slate objects has been renamed to `object`.** This is to reduce the confusion over the difference between "kind" and "type" which are practically synonyms. The "object" name was chosen to match the Stripe API, since it seems like a sensible choice and reads much more nicely when looking through JSON.

@@ -21,3 +29,3 @@ ---

* **Remove all previously deprecated code paths.** This helps to reduce some of the complexity in Slate by not having to handle these code paths anymore. And it helps to reduce file size. When upgrading, it's _highly_ recommended that you upgrade to the previous version first and ensure there are no deprecation warnings being logged, then upgrade to this version.
**Remove all previously deprecated code paths.** This helps to reduce some of the complexity in Slate by not having to handle these code paths anymore. And it helps to reduce file size. When upgrading, it's _highly_ recommended that you upgrade to the previous version first and ensure there are no deprecation warnings being logged, then upgrade to this version.

@@ -30,7 +38,7 @@ ---

* **Updated to work with `slate@0.29.0`.** This is required because `slate-hyperscript` needs access to the new `Value` model.
**Updated to work with `slate@0.29.0`.** This is required because `slate-hyperscript` needs access to the new `Value` model.
###### DEPRECATED
* **The `<state>` tag has been renamed to `<value>`.** This is to stay in line with the newest version of Slate where the `State` object was renamed to `Value`.
**The `<state>` tag has been renamed to `<value>`.** This is to stay in line with the newest version of Slate where the `State` object was renamed to `Value`.

@@ -43,3 +51,3 @@ ---

* **Updated work with `slate@0.27.0`.** The new version of Slate renames the old `Range` model to `Leaf`, and the old `Selection` model to `Range`.
**Updated work with `slate@0.27.0`.** The new version of Slate renames the old `Range` model to `Leaf`, and the old `Selection` model to `Range`.

@@ -46,0 +54,0 @@ ---

@@ -364,13 +364,15 @@ (function (global, factory) {

var value = slate.Value.fromJSON({ data: data, document: document, selection: selection }, { normalize: normalize });
if (!lib(props)) {
selection = selection.merge(props).normalize(document);
selection = selection.merge(props).normalize(value.document);
value = value.set('selection', selection);
}
var value = slate.Value.fromJSON({ data: data, document: document, selection: selection }, { normalize: normalize });
// apply any decorations built
if (decorations.length > 0) {
value = value.change().setValue({ decorations: decorations.map(function (d) {
return d.normalize(document);
}) }).value;
decorations = decorations.map(function (d) {
return d.normalize(value.document);
});
decorations = slate.Range.createList(decorations);
value = value.set('decorations', decorations);
}

@@ -377,0 +379,0 @@

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

!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("slate")):"function"==typeof define&&define.amd?define(["exports","slate"],t):t(e.SlateHyperscript={},e.Slate)}(this,function(e,t){"use strict";var n=Object.prototype.hasOwnProperty,r=Object.prototype.toString;var o=function(e){if(null==e)return!0;if("boolean"==typeof e)return!1;if("number"==typeof e)return 0===e;if("string"==typeof e)return 0===e.length;if("function"==typeof e)return 0===e.length;if(Array.isArray(e))return 0===e.length;if(e instanceof Error)return""===e.message;if(e.toString==r)switch(e.toString()){case"[object File]":case"[object Map]":case"[object Set]":return 0===e.size;case"[object Object]":for(var t in e)if(n.call(e,t))return!1;return!0}return!1},c=function(e){return null!=e&&"object"==typeof e&&!1===Array.isArray(e)};function i(e){return!0===c(e)&&"[object Object]"===Object.prototype.toString.call(e)}var a=function(e){var t,n;return!1!==i(e)&&("function"==typeof(t=e.constructor)&&(!1!==i(n=t.prototype)&&!1!==n.hasOwnProperty("isPrototypeOf")))},s=Object.assign||function(e){for(var t=1;t<arguments.length;t++){var n=arguments[t];for(var r in n)Object.prototype.hasOwnProperty.call(n,r)&&(e[r]=n[r])}return e},u=function(e,t){var n={};for(var r in e)t.indexOf(r)>=0||Object.prototype.hasOwnProperty.call(e,r)&&(n[r]=e[r]);return n},f={},l={},y={},h=function e(t,n){var r=t.key,o=t.data;return function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,e),d.call(this),this._key=r,this.marks=n,this.attribs=o||{},this.isAtomic=!!this.attribs.atomic,delete this.attribs.atomic,this},d=function(){var e=this;this.withPosition=function(t){return e.offset=t,e},this.addOffset=function(t){return e.offset+=t,e},this.withKey=function(t){return e.key=t,e},this.combine=function(n){if(!(n instanceof h))throw new Error("misaligned decorations");return t.Range.create(s({anchorKey:e.key,focusKey:n.key,anchorOffset:e.offset,focusOffset:n.offset,marks:e.marks,isAtomic:e.isAtomic},e.attribs))}},p={anchor:function(e,t,n){return f},block:function(e,n,r){return t.Block.create(s({},n,{nodes:k(r)}))},cursor:function(e,t,n){return l},document:function(e,n,r){return t.Document.create(s({},n,{nodes:k(r)}))},focus:function(e,t,n){return y},inline:function(e,n,r){return t.Inline.create(s({},n,{nodes:k(r)}))},mark:function(e,n,r){return k(r,{marks:t.Mark.createSet([n])})},decoration:function(e,t,n){if(t.key)return new h(t,[{type:e}]);var r=k(n,{key:t.key});return r[0].__decorations=(r[0].__decorations||[]).concat([{anchorOffset:0,focusOffset:r.reduce(function(e,t){return e+t.text.length},0),marks:[{type:e}],isAtomic:!!t.data.atomic}]),r},selection:function(e,n,r){return t.Range.create(n)},value:function(e,n,r){var c=n.data,i=n.normalize,a=void 0===i||i,u=r.find(t.Document.isDocument),f=r.find(t.Range.isRange)||t.Range.create(),l={},y=[],h={};if(u&&(u.getTexts().forEach(function(e){null!=e.__anchor&&(l.anchorKey=e.key,l.anchorOffset=e.__anchor,l.isFocused=!0),null!=e.__focus&&(l.focusKey=e.key,l.focusOffset=e.__focus,l.isFocused=!0)}),u.getTexts().forEach(function(e){null!=e.__decorations&&(y=y.concat(e.__decorations.filter(function(e){return void 0===e._key}).map(function(n){return t.Range.create(s({},n,{anchorKey:e.key,focusKey:e.key}))})),e.__decorations.filter(function(e){return void 0!==e._key}).forEach(function(t){if(h[t._key])return y.push(h[t._key].combine(t.withKey(e.key))),void delete h[t._key];h[t._key]=t.withKey(e.key)}))})),Object.keys(h).length>0)throw new Error("Slate hyperscript must have both an anchor and focus defined for each keyed decorator.");if(l.anchorKey&&!l.focusKey)throw new Error("Slate hyperscript must have both `<anchor/>` and `<focus/>` defined if one is defined, but you only defined `<anchor/>`. For collapsed selections, use `<cursor/>`.");if(!l.anchorKey&&l.focusKey)throw new Error("Slate hyperscript must have both `<anchor/>` and `<focus/>` defined if one is defined, but you only defined `<focus/>`. For collapsed selections, use `<cursor/>`.");o(l)||(f=f.merge(l).normalize(u));var d=t.Value.fromJSON({data:c,document:u,selection:f},{normalize:a});return y.length>0&&(d=d.change().setValue({decorations:y.map(function(e){return e.normalize(u)})}).value),d},text:function(e,t,n){return k(n,{key:t.key})}};function _(){var e=function(e){var t=e.blocks,n=void 0===t?{}:t,r=e.inlines,o=void 0===r?{}:r,c=e.marks,i=void 0===c?{}:c,u=e.decorators,f=void 0===u?{}:u,l=s({},p,e.creators||{});return Object.keys(n).map(function(e){l[e]=m(e,n[e],"block")}),Object.keys(o).map(function(e){l[e]=m(e,o[e],"inline")}),Object.keys(i).map(function(e){l[e]=function(e,t){if("function"==typeof t)return t;if("string"==typeof t&&(t={type:t}),a(t))return function(e,n,r){var o=s({},t,{data:s({},t.data||{},n)});return p.mark(e,o,r)};throw new Error("Slate hyperscript mark creators can be either functions, objects or strings, but you passed: "+t)}(0,i[e])}),Object.keys(f).map(function(e){l[e]=m(e,f[e],"decoration")}),l}(arguments.length>0&&void 0!==arguments[0]?arguments[0]:{});return function(t,n){for(var r=arguments.length,o=Array(r>2?r-2:0),c=2;c<r;c++)o[c-2]=arguments[c];var i=e[t];if(!i)throw new Error('No hyperscript creator found for tag: "'+t+'"');return null==n&&(n={}),a(n)||(o=[n].concat(o),n={}),i(t,n,o=o.filter(function(e){return Boolean(e)}).reduce(function(e,t){return e.concat(t)},[]))}}function k(e){var n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},r=[],o=0,c=e.find(function(e){return"string"!=typeof e}),i=t.Text.isText(c)?c:null,a=n.key?n.key:i?i.key:void 0,u=t.Text.create({key:a,leaves:[{text:"",marks:n.marks}]});function d(e){var t=u,n=t.__anchor,r=t.__focus,o=t.__decorations;null!=n&&(e.__anchor=n),null!=r&&(e.__focus=r),null!=o&&(e.__decorations=o),u=e}return e.forEach(function(c,i){var a=i===e.length-1;if(t.Node.isNode(c)&&!t.Text.isText(c)&&((u.text.length||null!=u.__anchor||null!=u.__focus||u.getMarksAtIndex(0).size)&&r.push(u),r.push(c),u=a?null:t.Text.create({leaves:[{text:"",marks:n.marks}]}),o=0),"string"==typeof c&&(d(u.insertText(u.text.length,c,n.marks)),o+=c.length),t.Text.isText(c)){var p=c.__anchor,_=c.__focus,k=c.__decorations,m=u.text.length;n.key||0!=u.text.length||d(u.set("key",c.key)),c.getLeaves().forEach(function(e){var t=e.marks;n.marks&&(t=t.union(n.marks)),d(u.insertText(m,e.text,t)),m+=e.text.length}),null!=p&&(u.__anchor=p+o),null!=_&&(u.__focus=_+o),null!=k&&(u.__decorations=(u.__decorations||[]).concat(k.map(function(e){return e instanceof h?e.addOffset(o):s({},e,{anchorOffset:e.anchorOffset+o,focusOffset:e.focusOffset+o})}))),o+=c.text.length}c!=f&&c!=l||(u.__anchor=o),c!=y&&c!=l||(u.__focus=o),c instanceof h&&(u.__decorations=(u.__decorations||[]).concat([c.withPosition(o)]))}),null!=u&&r.push(u),r}function m(e,t,n){if("function"==typeof t)return t;if("string"==typeof t&&(t={type:t}),a(t))return function(e,r,o){var c=r.key,i=u(r,["key"]),a=s({},t,{object:n,key:c,data:s({},t.data||{},i)});return p[n](e,a,o)};throw new Error("Slate hyperscript "+n+" creators can be either functions, objects or strings, but you passed: "+t)}var v=_();e.default=v,e.createHyperscript=_,Object.defineProperty(e,"__esModule",{value:!0})});
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("slate")):"function"==typeof define&&define.amd?define(["exports","slate"],t):t(e.SlateHyperscript={},e.Slate)}(this,function(e,t){"use strict";var n=Object.prototype.hasOwnProperty,r=Object.prototype.toString;var o=function(e){if(null==e)return!0;if("boolean"==typeof e)return!1;if("number"==typeof e)return 0===e;if("string"==typeof e)return 0===e.length;if("function"==typeof e)return 0===e.length;if(Array.isArray(e))return 0===e.length;if(e instanceof Error)return""===e.message;if(e.toString==r)switch(e.toString()){case"[object File]":case"[object Map]":case"[object Set]":return 0===e.size;case"[object Object]":for(var t in e)if(n.call(e,t))return!1;return!0}return!1},c=function(e){return null!=e&&"object"==typeof e&&!1===Array.isArray(e)};function i(e){return!0===c(e)&&"[object Object]"===Object.prototype.toString.call(e)}var a=function(e){var t,n;return!1!==i(e)&&("function"==typeof(t=e.constructor)&&(!1!==i(n=t.prototype)&&!1!==n.hasOwnProperty("isPrototypeOf")))},s=Object.assign||function(e){for(var t=1;t<arguments.length;t++){var n=arguments[t];for(var r in n)Object.prototype.hasOwnProperty.call(n,r)&&(e[r]=n[r])}return e},u=function(e,t){var n={};for(var r in e)t.indexOf(r)>=0||Object.prototype.hasOwnProperty.call(e,r)&&(n[r]=e[r]);return n},f={},l={},y={},h=function e(t,n){var r=t.key,o=t.data;return function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,e),d.call(this),this._key=r,this.marks=n,this.attribs=o||{},this.isAtomic=!!this.attribs.atomic,delete this.attribs.atomic,this},d=function(){var e=this;this.withPosition=function(t){return e.offset=t,e},this.addOffset=function(t){return e.offset+=t,e},this.withKey=function(t){return e.key=t,e},this.combine=function(n){if(!(n instanceof h))throw new Error("misaligned decorations");return t.Range.create(s({anchorKey:e.key,focusKey:n.key,anchorOffset:e.offset,focusOffset:n.offset,marks:e.marks,isAtomic:e.isAtomic},e.attribs))}},p={anchor:function(e,t,n){return f},block:function(e,n,r){return t.Block.create(s({},n,{nodes:k(r)}))},cursor:function(e,t,n){return l},document:function(e,n,r){return t.Document.create(s({},n,{nodes:k(r)}))},focus:function(e,t,n){return y},inline:function(e,n,r){return t.Inline.create(s({},n,{nodes:k(r)}))},mark:function(e,n,r){return k(r,{marks:t.Mark.createSet([n])})},decoration:function(e,t,n){if(t.key)return new h(t,[{type:e}]);var r=k(n,{key:t.key});return r[0].__decorations=(r[0].__decorations||[]).concat([{anchorOffset:0,focusOffset:r.reduce(function(e,t){return e+t.text.length},0),marks:[{type:e}],isAtomic:!!t.data.atomic}]),r},selection:function(e,n,r){return t.Range.create(n)},value:function(e,n,r){var c=n.data,i=n.normalize,a=void 0===i||i,u=r.find(t.Document.isDocument),f=r.find(t.Range.isRange)||t.Range.create(),l={},y=[],h={};if(u&&(u.getTexts().forEach(function(e){null!=e.__anchor&&(l.anchorKey=e.key,l.anchorOffset=e.__anchor,l.isFocused=!0),null!=e.__focus&&(l.focusKey=e.key,l.focusOffset=e.__focus,l.isFocused=!0)}),u.getTexts().forEach(function(e){null!=e.__decorations&&(y=y.concat(e.__decorations.filter(function(e){return void 0===e._key}).map(function(n){return t.Range.create(s({},n,{anchorKey:e.key,focusKey:e.key}))})),e.__decorations.filter(function(e){return void 0!==e._key}).forEach(function(t){if(h[t._key])return y.push(h[t._key].combine(t.withKey(e.key))),void delete h[t._key];h[t._key]=t.withKey(e.key)}))})),Object.keys(h).length>0)throw new Error("Slate hyperscript must have both an anchor and focus defined for each keyed decorator.");if(l.anchorKey&&!l.focusKey)throw new Error("Slate hyperscript must have both `<anchor/>` and `<focus/>` defined if one is defined, but you only defined `<anchor/>`. For collapsed selections, use `<cursor/>`.");if(!l.anchorKey&&l.focusKey)throw new Error("Slate hyperscript must have both `<anchor/>` and `<focus/>` defined if one is defined, but you only defined `<focus/>`. For collapsed selections, use `<cursor/>`.");var d=t.Value.fromJSON({data:c,document:u,selection:f},{normalize:a});return o(l)||(f=f.merge(l).normalize(d.document),d=d.set("selection",f)),y.length>0&&(y=y.map(function(e){return e.normalize(d.document)}),y=t.Range.createList(y),d=d.set("decorations",y)),d},text:function(e,t,n){return k(n,{key:t.key})}};function _(){var e=function(e){var t=e.blocks,n=void 0===t?{}:t,r=e.inlines,o=void 0===r?{}:r,c=e.marks,i=void 0===c?{}:c,u=e.decorators,f=void 0===u?{}:u,l=s({},p,e.creators||{});return Object.keys(n).map(function(e){l[e]=m(e,n[e],"block")}),Object.keys(o).map(function(e){l[e]=m(e,o[e],"inline")}),Object.keys(i).map(function(e){l[e]=function(e,t){if("function"==typeof t)return t;if("string"==typeof t&&(t={type:t}),a(t))return function(e,n,r){var o=s({},t,{data:s({},t.data||{},n)});return p.mark(e,o,r)};throw new Error("Slate hyperscript mark creators can be either functions, objects or strings, but you passed: "+t)}(0,i[e])}),Object.keys(f).map(function(e){l[e]=m(e,f[e],"decoration")}),l}(arguments.length>0&&void 0!==arguments[0]?arguments[0]:{});return function(t,n){for(var r=arguments.length,o=Array(r>2?r-2:0),c=2;c<r;c++)o[c-2]=arguments[c];var i=e[t];if(!i)throw new Error('No hyperscript creator found for tag: "'+t+'"');return null==n&&(n={}),a(n)||(o=[n].concat(o),n={}),i(t,n,o=o.filter(function(e){return Boolean(e)}).reduce(function(e,t){return e.concat(t)},[]))}}function k(e){var n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},r=[],o=0,c=e.find(function(e){return"string"!=typeof e}),i=t.Text.isText(c)?c:null,a=n.key?n.key:i?i.key:void 0,u=t.Text.create({key:a,leaves:[{text:"",marks:n.marks}]});function d(e){var t=u,n=t.__anchor,r=t.__focus,o=t.__decorations;null!=n&&(e.__anchor=n),null!=r&&(e.__focus=r),null!=o&&(e.__decorations=o),u=e}return e.forEach(function(c,i){var a=i===e.length-1;if(t.Node.isNode(c)&&!t.Text.isText(c)&&((u.text.length||null!=u.__anchor||null!=u.__focus||u.getMarksAtIndex(0).size)&&r.push(u),r.push(c),u=a?null:t.Text.create({leaves:[{text:"",marks:n.marks}]}),o=0),"string"==typeof c&&(d(u.insertText(u.text.length,c,n.marks)),o+=c.length),t.Text.isText(c)){var p=c.__anchor,_=c.__focus,k=c.__decorations,m=u.text.length;n.key||0!=u.text.length||d(u.set("key",c.key)),c.getLeaves().forEach(function(e){var t=e.marks;n.marks&&(t=t.union(n.marks)),d(u.insertText(m,e.text,t)),m+=e.text.length}),null!=p&&(u.__anchor=p+o),null!=_&&(u.__focus=_+o),null!=k&&(u.__decorations=(u.__decorations||[]).concat(k.map(function(e){return e instanceof h?e.addOffset(o):s({},e,{anchorOffset:e.anchorOffset+o,focusOffset:e.focusOffset+o})}))),o+=c.text.length}c!=f&&c!=l||(u.__anchor=o),c!=y&&c!=l||(u.__focus=o),c instanceof h&&(u.__decorations=(u.__decorations||[]).concat([c.withPosition(o)]))}),null!=u&&r.push(u),r}function m(e,t,n){if("function"==typeof t)return t;if("string"==typeof t&&(t={type:t}),a(t))return function(e,r,o){var c=r.key,i=u(r,["key"]),a=s({},t,{object:n,key:c,data:s({},t.data||{},i)});return p[n](e,a,o)};throw new Error("Slate hyperscript "+n+" creators can be either functions, objects or strings, but you passed: "+t)}var v=_();e.default=v,e.createHyperscript=_,Object.defineProperty(e,"__esModule",{value:!0})});

@@ -245,13 +245,15 @@ import isEmpty from 'is-empty';

var value = Value.fromJSON({ data: data, document: document, selection: selection }, { normalize: normalize });
if (!isEmpty(props)) {
selection = selection.merge(props).normalize(document);
selection = selection.merge(props).normalize(value.document);
value = value.set('selection', selection);
}
var value = Value.fromJSON({ data: data, document: document, selection: selection }, { normalize: normalize });
// apply any decorations built
if (decorations.length > 0) {
value = value.change().setValue({ decorations: decorations.map(function (d) {
return d.normalize(document);
}) }).value;
decorations = decorations.map(function (d) {
return d.normalize(value.document);
});
decorations = Range.createList(decorations);
value = value.set('decorations', decorations);
}

@@ -258,0 +260,0 @@

@@ -251,13 +251,15 @@ 'use strict';

var value = slate.Value.fromJSON({ data: data, document: document, selection: selection }, { normalize: normalize });
if (!isEmpty(props)) {
selection = selection.merge(props).normalize(document);
selection = selection.merge(props).normalize(value.document);
value = value.set('selection', selection);
}
var value = slate.Value.fromJSON({ data: data, document: document, selection: selection }, { normalize: normalize });
// apply any decorations built
if (decorations.length > 0) {
value = value.change().setValue({ decorations: decorations.map(function (d) {
return d.normalize(document);
}) }).value;
decorations = decorations.map(function (d) {
return d.normalize(value.document);
});
decorations = slate.Range.createList(decorations);
value = value.set('decorations', decorations);
}

@@ -264,0 +266,0 @@

{
"name": "slate-hyperscript",
"description": "A hyperscript helper for creating Slate documents.",
"version": "0.5.22",
"version": "0.6.0",
"license": "MIT",

@@ -18,10 +18,10 @@ "repository": "git://github.com/ianstormtaylor/slate.git",

"is-plain-object": "^2.0.4",
"slate-dev-logger": "^0.1.39"
"slate-dev-logger": "^0.1.40"
},
"peerDependencies": {
"slate": ">=0.32.0"
"slate": ">=0.35.0"
},
"devDependencies": {
"mocha": "^2.5.3",
"slate": "^0.34.7"
"slate": "^0.35.0"
},

@@ -28,0 +28,0 @@ "scripts": {

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

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