slate-hyperscript
Advanced tools
Comparing version 0.7.4 to 0.8.0
@@ -7,2 +7,10 @@ # Changelog | ||
### `0.8.0` — August 15, 2018 | ||
###### BREAKING | ||
**The `decorators` option was renamed to `decorations`.** This was previously incorrectly named, and renaming it is just an attempt to keep the API consistent with how Slate describes the concept everywhere else. | ||
--- | ||
### `0.7.0` — August 3, 2018 | ||
@@ -9,0 +17,0 @@ |
@@ -561,4 +561,4 @@ (function (global, factory) { | ||
marks = _options$marks === undefined ? {} : _options$marks, | ||
_options$decorators = options.decorators, | ||
decorators = _options$decorators === undefined ? {} : _options$decorators; | ||
_options$decorations = options.decorations, | ||
decorations = _options$decorations === undefined ? {} : _options$decorations; | ||
@@ -580,4 +580,4 @@ | ||
Object.keys(decorators).map(function (key) { | ||
creators[key] = normalizeNode(key, decorators[key], 'decoration'); | ||
Object.keys(decorations).map(function (key) { | ||
creators[key] = normalizeNode(key, decorations[key], 'decoration'); | ||
}); | ||
@@ -584,0 +584,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=function(e){return null!=e&&"object"==typeof e&&!1===Array.isArray(e)};function o(e){return!0===n(e)&&"[object Object]"===Object.prototype.toString.call(e)}var r=function(e){var t,n;return!1!==o(e)&&("function"==typeof(t=e.constructor)&&(!1!==o(n=t.prototype)&&!1!==n.hasOwnProperty("isPrototypeOf")))},i=function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")},s=Object.assign||function(e){for(var t=1;t<arguments.length;t++){var n=arguments[t];for(var o in n)Object.prototype.hasOwnProperty.call(n,o)&&(e[o]=n[o])}return e},a=function(e,t){var n={};for(var o in e)t.indexOf(o)>=0||Object.prototype.hasOwnProperty.call(e,o)&&(n[o]=e[o]);return n},c=function e(){i(this,e),this.offset=null},f=function e(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};i(this,e);var n=t.key,o=void 0===n?null:n,r=t.offset,s=void 0===r?null:r,a=t.path,c=void 0===a?null:a;this.key=o,this.offset=s,this.path=c},u=function e(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};i(this,e);var n=t.key,o=void 0===n?null:n,r=t.offset,s=void 0===r?null:r,a=t.path,c=void 0===a?null:a;this.key=o,this.offset=s,this.path=c},l=function e(n){var o=this;i(this,e),this.combine=function(n){if(!(n instanceof e))throw new Error("misaligned decorations");return t.Range.create(s({anchor:{key:o.key,offset:o.offset},focus:{key:n.key,offset:n.offset},marks:o.marks,isAtomic:o.isAtomic},o.attribs))};var r=n.key,a=void 0===r?null:r,c=n.data,f=void 0===c?{}:c,u=n.marks;return this.id=a,this.offset=0,this.marks=u,this.attribs=f||{},this.isAtomic=!!this.attribs.atomic,delete this.attribs.atomic,this},d={anchor:function(e,t,n){return new f(t)},block:function(e,n,o){return t.Block.create(s({},n,{nodes:y(o)}))},cursor:function(e,t,n){return new c},document:function(e,n,o){return t.Document.create(s({},n,{nodes:y(o)}))},focus:function(e,t,n){return new u(t)},inline:function(e,n,o){return t.Inline.create(s({},n,{nodes:y(o)}))},mark:function(e,n,o){return y(o,{marks:t.Mark.createSet([n])})},decoration:function(e,t,n){if(t.key)return new l(s({},t,{marks:[{type:e}]}));var o=y(n),r=o[0],i=r.__decorations,a=void 0===i?[]:i,c={anchorOffset:0,focusOffset:o.reduce(function(e,t){return e+t.text.length},0),marks:[{type:e}],isAtomic:!!t.data.atomic};return a.push(c),r.__decorations=a,o},selection:function(e,n,o){var r=o.find(function(e){return e instanceof f}),i=o.find(function(e){return e instanceof u}),a=t.Range.create(s({},n,{anchor:r&&{key:r.key,offset:r.offset,path:r.path},focus:i&&{key:i.key,offset:i.offset,path:i.path}}));return a},value:function(e,n,o){var r=n.data,i=n.normalize,s=void 0===i||i,a=o.find(t.Document.isDocument),c=o.find(t.Range.isRange)||t.Range.create(),f=void 0,u=void 0,l=[],d={};if(a&&a.getTexts().forEach(function(e){null!=e.__anchor&&(f=t.Point.create({key:e.key,offset:e.__anchor.offset})),null!=e.__focus&&(u=t.Point.create({key:e.key,offset:e.__focus.offset})),null!=e.__decorations&&e.__decorations.forEach(function(n){var o=n.id,r=void 0;if(o)if(d[o]){var i=d[o];delete d[o],r=t.Range.create({anchor:{key:i.key,offset:i.offset},focus:{key:e.key,offset:n.offset},marks:i.marks,isAtomic:i.isAtomic})}else n.key=e.key,d[o]=n;else r=t.Range.create({anchor:{key:e.key,offset:n.anchorOffset},focus:{key:e.key,offset:n.focusOffset},marks:n.marks,isAtomic:n.isAtomic});r&&l.push(r)})}),Object.keys(d).length>0)throw new Error("Slate hyperscript must have both a start and an end defined for each decoration using the `key=` prop.");if(f&&!u)throw new Error("Slate hyperscript ranges must have both `<anchor />` and `<focus />` defined if one is defined, but you only defined `<anchor />`. For collapsed selections, use `<cursor />` instead.");if(!f&&u)throw new Error("Slate hyperscript ranges must have both `<anchor />` and `<focus />` defined if one is defined, but you only defined `<focus />`. For collapsed selections, use `<cursor />` instead.");var h=t.Value.fromJSON({data:r,document:a,selection:c},{normalize:s});return(f||u)&&(c=(c=(c=c.setPoints([f,u])).merge({isFocused:!0})).normalize(h.document),h=h.set("selection",c)),l.length>0&&(l=l.map(function(e){return e.normalize(h.document)}),l=t.Range.createList(l),h=h.set("decorations",l)),h},text:function(e,t,n){return y(n,{key:t.key})}};function h(){var e=function(e){var t=e.blocks,n=void 0===t?{}:t,o=e.inlines,i=void 0===o?{}:o,a=e.marks,c=void 0===a?{}:a,f=e.decorators,u=void 0===f?{}:f,l=s({},d,e.creators||{});return Object.keys(n).map(function(e){l[e]=k(e,n[e],"block")}),Object.keys(i).map(function(e){l[e]=k(e,i[e],"inline")}),Object.keys(c).map(function(e){l[e]=function(e,t){if("function"==typeof t)return t;if("string"==typeof t&&(t={type:t}),r(t))return function(e,n,o){var r=s({},t,{data:s({},t.data||{},n)});return d.mark(e,r,o)};throw new Error("Slate hyperscript mark creators can be either functions, objects or strings, but you passed: "+t)}(0,c[e])}),Object.keys(u).map(function(e){l[e]=k(e,u[e],"decoration")}),l}(arguments.length>0&&void 0!==arguments[0]?arguments[0]:{});return function(t,n){for(var o=arguments.length,i=Array(o>2?o-2:0),s=2;s<o;s++)i[s-2]=arguments[s];var a=e[t];if(!a)throw new Error('No hyperscript creator found for tag: "'+t+'"');return null==n&&(n={}),r(n)||(i=[n].concat(i),n={}),a(t,n,i=i.filter(function(e){return Boolean(e)}).reduce(function(e,t){return e.concat(t)},[]))}}function y(e){var n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},o=[],r=0,i=e.find(function(e){return"string"!=typeof e}),s=t.Text.isText(i)?i:null,a=n.key?n.key:s?s.key:void 0,d=t.Text.create({key:a,leaves:[{text:"",marks:n.marks}]});function h(e){var t=d,n=t.__anchor,o=t.__focus,r=t.__decorations;null!=n&&(e.__anchor=n),null!=o&&(e.__focus=o),null!=r&&(e.__decorations=r),d=e}return e.forEach(function(i,s){var a=s===e.length-1;if(t.Node.isNode(i)&&!t.Text.isText(i)&&((d.text.length||null!=d.__anchor||null!=d.__focus||d.getMarksAtIndex(0).size)&&o.push(d),o.push(i),d=a?null:t.Text.create({leaves:[{text:"",marks:n.marks}]}),r=0),"string"==typeof i&&(h(d.insertText(d.text.length,i,n.marks)),r+=i.length),t.Text.isText(i)){var y=i.__anchor,k=i.__focus,p=i.__decorations,_=d.text.length;n.key||0!=d.text.length||h(d.set("key",i.key)),i.getLeaves().forEach(function(e){var t=e.marks;n.marks&&(t=t.union(n.marks)),h(d.insertText(_,e.text,t)),_+=e.text.length}),null!=y&&(d.__anchor=new f,d.__anchor.offset=y.offset+r),null!=k&&(d.__focus=new u,d.__focus.offset=k.offset+r),null!=p&&(p.forEach(function(e){e instanceof l?e.offset+=r:(e.anchorOffset+=r,e.focusOffset+=r)}),d.__decorations=d.__decorations||[],d.__decorations=d.__decorations.concat(p)),r+=i.text.length}(i instanceof f||i instanceof c)&&(i.offset=r,d.__anchor=i),(i instanceof u||i instanceof c)&&(i.offset=r,d.__focus=i),i instanceof l&&(i.offset=r,d.__decorations=d.__decorations||[],d.__decorations=d.__decorations.concat(i))}),null!=d&&o.push(d),o}function k(e,t,n){if("function"==typeof t)return t;if("string"==typeof t&&(t={type:t}),r(t))return function(e,o,r){var i=o.key,c=a(o,["key"]),f=s({},t,{object:n,key:i,data:s({},t.data||{},c)});return d[n](e,f,r)};throw new Error("Slate hyperscript "+n+" creators can be either functions, objects or strings, but you passed: "+t)}var p=h();e.default=p,e.createHyperscript=h,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=function(e){return null!=e&&"object"==typeof e&&!1===Array.isArray(e)};function o(e){return!0===n(e)&&"[object Object]"===Object.prototype.toString.call(e)}var r=function(e){var t,n;return!1!==o(e)&&("function"==typeof(t=e.constructor)&&(!1!==o(n=t.prototype)&&!1!==n.hasOwnProperty("isPrototypeOf")))},i=function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")},s=Object.assign||function(e){for(var t=1;t<arguments.length;t++){var n=arguments[t];for(var o in n)Object.prototype.hasOwnProperty.call(n,o)&&(e[o]=n[o])}return e},a=function(e,t){var n={};for(var o in e)t.indexOf(o)>=0||Object.prototype.hasOwnProperty.call(e,o)&&(n[o]=e[o]);return n},c=function e(){i(this,e),this.offset=null},f=function e(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};i(this,e);var n=t.key,o=void 0===n?null:n,r=t.offset,s=void 0===r?null:r,a=t.path,c=void 0===a?null:a;this.key=o,this.offset=s,this.path=c},u=function e(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};i(this,e);var n=t.key,o=void 0===n?null:n,r=t.offset,s=void 0===r?null:r,a=t.path,c=void 0===a?null:a;this.key=o,this.offset=s,this.path=c},l=function e(n){var o=this;i(this,e),this.combine=function(n){if(!(n instanceof e))throw new Error("misaligned decorations");return t.Range.create(s({anchor:{key:o.key,offset:o.offset},focus:{key:n.key,offset:n.offset},marks:o.marks,isAtomic:o.isAtomic},o.attribs))};var r=n.key,a=void 0===r?null:r,c=n.data,f=void 0===c?{}:c,u=n.marks;return this.id=a,this.offset=0,this.marks=u,this.attribs=f||{},this.isAtomic=!!this.attribs.atomic,delete this.attribs.atomic,this},d={anchor:function(e,t,n){return new f(t)},block:function(e,n,o){return t.Block.create(s({},n,{nodes:y(o)}))},cursor:function(e,t,n){return new c},document:function(e,n,o){return t.Document.create(s({},n,{nodes:y(o)}))},focus:function(e,t,n){return new u(t)},inline:function(e,n,o){return t.Inline.create(s({},n,{nodes:y(o)}))},mark:function(e,n,o){return y(o,{marks:t.Mark.createSet([n])})},decoration:function(e,t,n){if(t.key)return new l(s({},t,{marks:[{type:e}]}));var o=y(n),r=o[0],i=r.__decorations,a=void 0===i?[]:i,c={anchorOffset:0,focusOffset:o.reduce(function(e,t){return e+t.text.length},0),marks:[{type:e}],isAtomic:!!t.data.atomic};return a.push(c),r.__decorations=a,o},selection:function(e,n,o){var r=o.find(function(e){return e instanceof f}),i=o.find(function(e){return e instanceof u}),a=t.Range.create(s({},n,{anchor:r&&{key:r.key,offset:r.offset,path:r.path},focus:i&&{key:i.key,offset:i.offset,path:i.path}}));return a},value:function(e,n,o){var r=n.data,i=n.normalize,s=void 0===i||i,a=o.find(t.Document.isDocument),c=o.find(t.Range.isRange)||t.Range.create(),f=void 0,u=void 0,l=[],d={};if(a&&a.getTexts().forEach(function(e){null!=e.__anchor&&(f=t.Point.create({key:e.key,offset:e.__anchor.offset})),null!=e.__focus&&(u=t.Point.create({key:e.key,offset:e.__focus.offset})),null!=e.__decorations&&e.__decorations.forEach(function(n){var o=n.id,r=void 0;if(o)if(d[o]){var i=d[o];delete d[o],r=t.Range.create({anchor:{key:i.key,offset:i.offset},focus:{key:e.key,offset:n.offset},marks:i.marks,isAtomic:i.isAtomic})}else n.key=e.key,d[o]=n;else r=t.Range.create({anchor:{key:e.key,offset:n.anchorOffset},focus:{key:e.key,offset:n.focusOffset},marks:n.marks,isAtomic:n.isAtomic});r&&l.push(r)})}),Object.keys(d).length>0)throw new Error("Slate hyperscript must have both a start and an end defined for each decoration using the `key=` prop.");if(f&&!u)throw new Error("Slate hyperscript ranges must have both `<anchor />` and `<focus />` defined if one is defined, but you only defined `<anchor />`. For collapsed selections, use `<cursor />` instead.");if(!f&&u)throw new Error("Slate hyperscript ranges must have both `<anchor />` and `<focus />` defined if one is defined, but you only defined `<focus />`. For collapsed selections, use `<cursor />` instead.");var h=t.Value.fromJSON({data:r,document:a,selection:c},{normalize:s});return(f||u)&&(c=(c=(c=c.setPoints([f,u])).merge({isFocused:!0})).normalize(h.document),h=h.set("selection",c)),l.length>0&&(l=l.map(function(e){return e.normalize(h.document)}),l=t.Range.createList(l),h=h.set("decorations",l)),h},text:function(e,t,n){return y(n,{key:t.key})}};function h(){var e=function(e){var t=e.blocks,n=void 0===t?{}:t,o=e.inlines,i=void 0===o?{}:o,a=e.marks,c=void 0===a?{}:a,f=e.decorations,u=void 0===f?{}:f,l=s({},d,e.creators||{});return Object.keys(n).map(function(e){l[e]=k(e,n[e],"block")}),Object.keys(i).map(function(e){l[e]=k(e,i[e],"inline")}),Object.keys(c).map(function(e){l[e]=function(e,t){if("function"==typeof t)return t;if("string"==typeof t&&(t={type:t}),r(t))return function(e,n,o){var r=s({},t,{data:s({},t.data||{},n)});return d.mark(e,r,o)};throw new Error("Slate hyperscript mark creators can be either functions, objects or strings, but you passed: "+t)}(0,c[e])}),Object.keys(u).map(function(e){l[e]=k(e,u[e],"decoration")}),l}(arguments.length>0&&void 0!==arguments[0]?arguments[0]:{});return function(t,n){for(var o=arguments.length,i=Array(o>2?o-2:0),s=2;s<o;s++)i[s-2]=arguments[s];var a=e[t];if(!a)throw new Error('No hyperscript creator found for tag: "'+t+'"');return null==n&&(n={}),r(n)||(i=[n].concat(i),n={}),a(t,n,i=i.filter(function(e){return Boolean(e)}).reduce(function(e,t){return e.concat(t)},[]))}}function y(e){var n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},o=[],r=0,i=e.find(function(e){return"string"!=typeof e}),s=t.Text.isText(i)?i:null,a=n.key?n.key:s?s.key:void 0,d=t.Text.create({key:a,leaves:[{text:"",marks:n.marks}]});function h(e){var t=d,n=t.__anchor,o=t.__focus,r=t.__decorations;null!=n&&(e.__anchor=n),null!=o&&(e.__focus=o),null!=r&&(e.__decorations=r),d=e}return e.forEach(function(i,s){var a=s===e.length-1;if(t.Node.isNode(i)&&!t.Text.isText(i)&&((d.text.length||null!=d.__anchor||null!=d.__focus||d.getMarksAtIndex(0).size)&&o.push(d),o.push(i),d=a?null:t.Text.create({leaves:[{text:"",marks:n.marks}]}),r=0),"string"==typeof i&&(h(d.insertText(d.text.length,i,n.marks)),r+=i.length),t.Text.isText(i)){var y=i.__anchor,k=i.__focus,p=i.__decorations,_=d.text.length;n.key||0!=d.text.length||h(d.set("key",i.key)),i.getLeaves().forEach(function(e){var t=e.marks;n.marks&&(t=t.union(n.marks)),h(d.insertText(_,e.text,t)),_+=e.text.length}),null!=y&&(d.__anchor=new f,d.__anchor.offset=y.offset+r),null!=k&&(d.__focus=new u,d.__focus.offset=k.offset+r),null!=p&&(p.forEach(function(e){e instanceof l?e.offset+=r:(e.anchorOffset+=r,e.focusOffset+=r)}),d.__decorations=d.__decorations||[],d.__decorations=d.__decorations.concat(p)),r+=i.text.length}(i instanceof f||i instanceof c)&&(i.offset=r,d.__anchor=i),(i instanceof u||i instanceof c)&&(i.offset=r,d.__focus=i),i instanceof l&&(i.offset=r,d.__decorations=d.__decorations||[],d.__decorations=d.__decorations.concat(i))}),null!=d&&o.push(d),o}function k(e,t,n){if("function"==typeof t)return t;if("string"==typeof t&&(t={type:t}),r(t))return function(e,o,r){var i=o.key,c=a(o,["key"]),f=s({},t,{object:n,key:i,data:s({},t.data||{},c)});return d[n](e,f,r)};throw new Error("Slate hyperscript "+n+" creators can be either functions, objects or strings, but you passed: "+t)}var p=h();e.default=p,e.createHyperscript=h,Object.defineProperty(e,"__esModule",{value:!0})}); |
@@ -520,4 +520,4 @@ import isPlainObject from 'is-plain-object'; | ||
marks = _options$marks === undefined ? {} : _options$marks, | ||
_options$decorators = options.decorators, | ||
decorators = _options$decorators === undefined ? {} : _options$decorators; | ||
_options$decorations = options.decorations, | ||
decorations = _options$decorations === undefined ? {} : _options$decorations; | ||
@@ -539,4 +539,4 @@ | ||
Object.keys(decorators).map(function (key) { | ||
creators[key] = normalizeNode(key, decorators[key], 'decoration'); | ||
Object.keys(decorations).map(function (key) { | ||
creators[key] = normalizeNode(key, decorations[key], 'decoration'); | ||
}); | ||
@@ -543,0 +543,0 @@ |
@@ -526,4 +526,4 @@ 'use strict'; | ||
marks = _options$marks === undefined ? {} : _options$marks, | ||
_options$decorators = options.decorators, | ||
decorators = _options$decorators === undefined ? {} : _options$decorators; | ||
_options$decorations = options.decorations, | ||
decorations = _options$decorations === undefined ? {} : _options$decorations; | ||
@@ -545,4 +545,4 @@ | ||
Object.keys(decorators).map(function (key) { | ||
creators[key] = normalizeNode(key, decorators[key], 'decoration'); | ||
Object.keys(decorations).map(function (key) { | ||
creators[key] = normalizeNode(key, decorations[key], 'decoration'); | ||
}); | ||
@@ -549,0 +549,0 @@ |
{ | ||
"name": "slate-hyperscript", | ||
"description": "A hyperscript helper for creating Slate documents.", | ||
"version": "0.7.4", | ||
"version": "0.8.0", | ||
"license": "MIT", | ||
@@ -25,3 +25,3 @@ "repository": "git://github.com/ianstormtaylor/slate.git", | ||
"mocha": "^2.5.3", | ||
"slate": "^0.37.4" | ||
"slate": "^0.37.5" | ||
}, | ||
@@ -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
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
116727
128256