Repository URL to install this package:
|
Version:
0.58.2 ▾
|
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports,require("slate")):"function"==typeof define&&define.amd?define(["exports","slate"],e):e((t=t||self).SlateHyperscript={},t.Slate)}(this,(function(t,e){"use strict";function r(t,e){return t(e={exports:{}},e.exports),e.exports}var n=r((function(t){function e(t){return(e="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t})(t)}function r(n){return"function"==typeof Symbol&&"symbol"===e(Symbol.iterator)?t.exports=r=function(t){return e(t)}:t.exports=r=function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":e(t)},r(n)}t.exports=r}));var o=function(t,e,r){return e in t?Object.defineProperty(t,e,{value:r,enumerable:!0,configurable:!0,writable:!0}):t[e]=r,t};
/*!
* isobject <https://github.com/jonschlinkert/isobject>
*
* Copyright (c) 2014-2017, Jon Schlinkert.
* Released under the MIT License.
*/
/*!
* is-plain-object <https://github.com/jonschlinkert/is-plain-object>
*
* Copyright (c) 2014-2017, Jon Schlinkert.
* Released under the MIT License.
*/
function i(t){return!0==(null!=(e=t)&&"object"==typeof e&&!1===Array.isArray(e))&&"[object Object]"===Object.prototype.toString.call(t);var e}function c(t){var e,r;return!1!==i(t)&&("function"==typeof(e=t.constructor)&&(!1!==i(r=e.prototype)&&!1!==r.hasOwnProperty("isPrototypeOf")))}var a=function(t){if(Array.isArray(t))return t};var f=function(t,e){if(Symbol.iterator in Object(t)||"[object Arguments]"===Object.prototype.toString.call(t)){var r=[],n=!0,o=!1,i=void 0;try{for(var c,a=t[Symbol.iterator]();!(n=(c=a.next()).done)&&(r.push(c.value),!e||r.length!==e);n=!0);}catch(t){o=!0,i=t}finally{try{n||null==a.return||a.return()}finally{if(o)throw i}}return r}};var u=function(){throw new TypeError("Invalid attempt to destructure non-iterable instance")};var s=function(t,e){return a(t)||f(t,e)||u()};var l=function(t){if(void 0===t)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return t};var p=function(t,e){return!e||"object"!==n(e)&&"function"!=typeof e?l(t):e},h=r((function(t){function e(r){return t.exports=e=Object.setPrototypeOf?Object.getPrototypeOf:function(t){return t.__proto__||Object.getPrototypeOf(t)},e(r)}t.exports=e})),y=r((function(t){function e(r,n){return t.exports=e=Object.setPrototypeOf||function(t,e){return t.__proto__=e,t},e(r,n)}t.exports=e}));var b=function(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Super expression must either be null or a function");t.prototype=Object.create(e&&e.prototype,{constructor:{value:t,writable:!0,configurable:!0}}),e&&y(t,e)};var d=function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")},v=new WeakMap,w=new WeakMap,g=function t(){d(this,t)},O=function(t){function e(){var t,r=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};d(this,e),t=p(this,h(e).call(this));var n=r.offset,o=r.path;return t.offset=n,t.path=o,t}return b(e,t),e}(g),j=function(t){function e(){var t,r=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};d(this,e),t=p(this,h(e).call(this));var n=r.offset,o=r.path;return t.offset=n,t.path=o,t}return b(e,t),e}(g),m=function(t){return v.get(t)},x=function(t){return w.get(t)};function S(t,e){var r=Object.keys(t);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(t);e&&(n=n.filter((function(e){return Object.getOwnPropertyDescriptor(t,e).enumerable}))),r.push.apply(r,n)}return r}function P(t){for(var e=1;e<arguments.length;e++){var r=null!=arguments[e]?arguments[e]:{};e%2?S(Object(r),!0).forEach((function(e){o(t,e,r[e])})):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(r)):S(Object(r)).forEach((function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(r,e))}))}return t}var E=new WeakSet,T=function(t){var r=[],n=function t(n){if(null!=n){var o=r[r.length-1];if("string"==typeof n){var i={text:n};E.add(i),n=i}if(e.Text.isText(n)){var c=n;e.Text.isText(o)&&E.has(o)&&E.has(c)&&e.Text.equals(o,c,{loose:!0})?o.text+=c.text:r.push(c)}else if(e.Element.isElement(n))r.push(n);else{if(!(n instanceof g))throw new Error("Unexpected hyperscript child object: ".concat(n));var a=r[r.length-1];e.Text.isText(a)||(t(""),a=r[r.length-1]),n instanceof O?function(t,e){var r=t.text.length;v.set(t,[r,e])}(a,n):n instanceof j&&function(t,e){var r=t.text.length;w.set(t,[r,e])}(a,n)}}},o=!0,i=!1,c=void 0;try{for(var a,f=t.flat(1/0)[Symbol.iterator]();!(o=(a=f.next()).done);o=!0){n(a.value)}}catch(t){i=!0,c=t}finally{try{o||null==f.return||f.return()}finally{if(i)throw c}}return r};function _(t,e,r){return P({},e,{children:T(r)})}function D(t,e){var r=Object.keys(t);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(t);e&&(n=n.filter((function(e){return Object.getOwnPropertyDescriptor(t,e).enumerable}))),r.push.apply(r,n)}return r}function A(t){for(var e=1;e<arguments.length;e++){var r=null!=arguments[e]?arguments[e]:{};e%2?D(Object(r),!0).forEach((function(e){o(t,e,r[e])})):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(r)):D(Object(r)).forEach((function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(r,e))}))}return t}var k={anchor:function(t,e,r){return new O(e)},cursor:function(t,e,r){return[new O(e),new j(e)]},editor:function(t,r,n){var o,i=[],c=!0,a=!1,f=void 0;try{for(var u,l=n[Symbol.iterator]();!(c=(u=l.next()).done);c=!0){var p=u.value;e.Range.isRange(p)?o=p:i.push(p)}}catch(t){a=!0,f=t}finally{try{c||null==l.return||l.return()}finally{if(a)throw f}}var h=T(i),y={},b=e.createEditor();Object.assign(b,r),b.children=h;var d=!0,v=!1,w=void 0;try{for(var g,O=e.Node.texts(b)[Symbol.iterator]();!(d=(g=O.next()).done);d=!0){var j=s(g.value,2),S=j[0],P=j[1],E=m(S),_=x(S);if(null!=E){var D=s(E,1)[0];y.anchor={path:P,offset:D}}if(null!=_){var A=s(_,1)[0];y.focus={path:P,offset:A}}}}catch(t){v=!0,w=t}finally{try{d||null==O.return||O.return()}finally{if(v)throw w}}if(y.anchor&&!y.focus)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(!y.anchor&&y.focus)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.");return null!=o?b.selection=o:e.Range.isRange(y)&&(b.selection=y),b},element:_,focus:function(t,e,r){return new j(e)},fragment:function(t,e,r){return T(r)},selection:function(t,e,r){var n=r.find((function(t){return t instanceof O})),o=r.find((function(t){return t instanceof j}));if(!n||null==n.offset||null==n.path)throw new Error("The <selection> hyperscript tag must have an <anchor> tag as a child with `path` and `offset` attributes defined.");if(!o||null==o.offset||null==o.path)throw new Error("The <selection> hyperscript tag must have a <focus> tag as a child with `path` and `offset` attributes defined.");return P({anchor:{offset:n.offset,path:n.path},focus:{offset:o.offset,path:o.path}},e)},text:function(t,r,n){var o=T(n);if(o.length>1)throw new Error("The <text> hyperscript tag must only contain a single node's worth of children.");var i=s(o,1)[0];if(null==i&&(i={text:""}),!e.Text.isText(i))throw new Error("\n The <text> hyperscript tag can only contain text content as children.");return E.delete(i),Object.assign(i,r),i}},R=function(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},e=t.elements,r=void 0===e?{}:e,n=W(r),o=A({},k,{},n,{},t.creators),i=M(o);return i},M=function(t){return function(e,r){for(var n=arguments.length,o=new Array(n>2?n-2:0),i=2;i<n;i++)o[i-2]=arguments[i];var a=t[e];if(!a)throw new Error("No hyperscript creator found for tag: <".concat(e,">"));null==r&&(r={}),c(r)||(o=[r].concat(o),r={});var f=a(e,r,o=o.filter((function(t){return Boolean(t)})).flat());return f}},W=function(t){var e={},r=function(r){var o=t[r];if("object"!==n(o))throw new Error("Properties specified for a hyperscript shorthand should be an object, but for the custom element <".concat(r,"> tag you passed: ").concat(o));e[r]=function(t,e,r){return _(0,A({},o,{},e),r)}};for(var o in t)r(o);return e},q=R();t.createHyperscript=R,t.jsx=q,Object.defineProperty(t,"__esModule",{value:!0})}));