slate-hyperscript
Advanced tools
Comparing version 0.66.0 to 0.66.8-202191204027
# slate-hyperscript | ||
## 0.66.8-202191204027 | ||
### Patch Changes | ||
- [#4555](https://github.com/ianstormtaylor/slate/pull/4555) [`c29eea02`](https://github.com/ianstormtaylor/slate/commit/c29eea022ec943f0c63278e9058fe1267f7dff01) Thanks [@bryanph](https://github.com/bryanph)! - createEditor is now exported from slate-hyperscript, making it easier to set up custom editor tests | ||
For example: | ||
``` | ||
const jsx = createHyperscript({ | ||
creators: { | ||
editor: createEditor(aFunctionThatReturnsAnEditorObject) | ||
}, | ||
elements: { | ||
block: { type: 'block' }, | ||
inline: { type: 'inline' } | ||
} | ||
}) | ||
``` | ||
## 0.66.0 | ||
@@ -4,0 +24,0 @@ |
@@ -48,5 +48,5 @@ import { Element, Descendant, Range, Text, Editor } from 'slate'; | ||
*/ | ||
export declare function createEditor(tagName: string, attributes: { | ||
export declare const createEditor: (makeEditor: () => Editor) => (tagName: string, attributes: { | ||
[key: string]: any; | ||
}, children: any[]): Editor; | ||
}, children: any[]) => Editor; | ||
//# sourceMappingURL=creators.d.ts.map |
@@ -1,2 +0,2 @@ | ||
import { createAnchor, createCursor, createEditor, createElement, createFocus, createFragment, createSelection, createText } from './creators'; | ||
import { createAnchor, createCursor, createElement, createFocus, createFragment, createSelection, createText } from './creators'; | ||
/** | ||
@@ -24,3 +24,5 @@ * `HyperscriptCreators` are dictionaries of `HyperscriptCreator` functions | ||
cursor: typeof createCursor; | ||
editor: typeof createEditor; | ||
editor: (tagName: string, attributes: { | ||
[key: string]: any; | ||
}, children: any[]) => import("slate").BaseEditor; | ||
element: typeof createElement; | ||
@@ -34,3 +36,5 @@ focus: typeof createFocus; | ||
cursor: typeof createCursor; | ||
editor: typeof createEditor; | ||
editor: (tagName: string, attributes: { | ||
[key: string]: any; | ||
}, children: any[]) => import("slate").BaseEditor; | ||
element: typeof createElement; | ||
@@ -37,0 +41,0 @@ focus: typeof createFocus; |
import { createHyperscript, HyperscriptCreators, HyperscriptShorthands } from './hyperscript'; | ||
import { createEditor } from './creators'; | ||
/** | ||
@@ -8,3 +9,5 @@ * The default hyperscript factory that ships with Slate, without custom tags. | ||
cursor: typeof import("./creators").createCursor; | ||
editor: typeof import("./creators").createEditor; | ||
editor: (tagName: string, attributes: { | ||
[key: string]: any; | ||
}, children: any[]) => import("slate").BaseEditor; | ||
element: typeof import("./creators").createElement; | ||
@@ -18,3 +21,5 @@ focus: typeof import("./creators").createFocus; | ||
cursor: typeof import("./creators").createCursor; | ||
editor: typeof import("./creators").createEditor; | ||
editor: (tagName: string, attributes: { | ||
[key: string]: any; | ||
}, children: any[]) => import("slate").BaseEditor; | ||
element: typeof import("./creators").createElement; | ||
@@ -26,3 +31,3 @@ focus: typeof import("./creators").createFocus; | ||
})[S]>; | ||
export { jsx, createHyperscript, HyperscriptCreators, HyperscriptShorthands }; | ||
export { jsx, createHyperscript, createEditor, HyperscriptCreators, HyperscriptShorthands, }; | ||
//# sourceMappingURL=index.d.ts.map |
import { isPlainObject } from 'is-plain-object'; | ||
import { Text, Range, createEditor as createEditor$1, Node, Element } from 'slate'; | ||
import { Range, Node, Text, Element, createEditor as createEditor$1 } from 'slate'; | ||
@@ -260,3 +260,3 @@ function _defineProperty(obj, key, value) { | ||
function createEditor(tagName, attributes, children) { | ||
var createEditor = makeEditor => (tagName, attributes, children) => { | ||
var otherChildren = []; | ||
@@ -275,3 +275,3 @@ var selectionChild; | ||
var selection = {}; | ||
var editor = createEditor$1(); | ||
var editor = makeEditor(); | ||
Object.assign(editor, attributes); | ||
@@ -317,3 +317,3 @@ editor.children = descendants; // Search the document's texts to see if any of them have tokens associated | ||
return editor; | ||
} | ||
}; | ||
@@ -330,3 +330,3 @@ function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) { symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); } keys.push.apply(keys, symbols); } return keys; } | ||
cursor: createCursor, | ||
editor: createEditor, | ||
editor: createEditor(createEditor$1), | ||
element: createElement, | ||
@@ -420,3 +420,3 @@ focus: createFocus, | ||
export { createHyperscript, jsx }; | ||
export { createEditor, createHyperscript, jsx }; | ||
//# sourceMappingURL=index.es.js.map |
@@ -557,86 +557,88 @@ 'use strict'; | ||
function createEditor(tagName, attributes, children) { | ||
var otherChildren = []; | ||
var selectionChild; | ||
var createEditor = function createEditor(makeEditor) { | ||
return function (tagName, attributes, children) { | ||
var otherChildren = []; | ||
var selectionChild; | ||
var _iterator2 = _createForOfIteratorHelper(children), | ||
_step2; | ||
var _iterator2 = _createForOfIteratorHelper(children), | ||
_step2; | ||
try { | ||
for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) { | ||
var child = _step2.value; | ||
try { | ||
for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) { | ||
var child = _step2.value; | ||
if (slate.Range.isRange(child)) { | ||
selectionChild = child; | ||
} else { | ||
otherChildren.push(child); | ||
if (slate.Range.isRange(child)) { | ||
selectionChild = child; | ||
} else { | ||
otherChildren.push(child); | ||
} | ||
} | ||
} catch (err) { | ||
_iterator2.e(err); | ||
} finally { | ||
_iterator2.f(); | ||
} | ||
} catch (err) { | ||
_iterator2.e(err); | ||
} finally { | ||
_iterator2.f(); | ||
} | ||
var descendants = resolveDescendants(otherChildren); | ||
var selection = {}; | ||
var editor = slate.createEditor(); | ||
Object.assign(editor, attributes); | ||
editor.children = descendants; // Search the document's texts to see if any of them have tokens associated | ||
// that need incorporated into the selection. | ||
var descendants = resolveDescendants(otherChildren); | ||
var selection = {}; | ||
var editor = makeEditor(); | ||
Object.assign(editor, attributes); | ||
editor.children = descendants; // Search the document's texts to see if any of them have tokens associated | ||
// that need incorporated into the selection. | ||
var _iterator3 = _createForOfIteratorHelper(slate.Node.texts(editor)), | ||
_step3; | ||
var _iterator3 = _createForOfIteratorHelper(slate.Node.texts(editor)), | ||
_step3; | ||
try { | ||
for (_iterator3.s(); !(_step3 = _iterator3.n()).done;) { | ||
var _step3$value = _slicedToArray(_step3.value, 2), | ||
node = _step3$value[0], | ||
path = _step3$value[1]; | ||
try { | ||
for (_iterator3.s(); !(_step3 = _iterator3.n()).done;) { | ||
var _step3$value = _slicedToArray(_step3.value, 2), | ||
node = _step3$value[0], | ||
path = _step3$value[1]; | ||
var anchor = getAnchorOffset(node); | ||
var focus = getFocusOffset(node); | ||
var anchor = getAnchorOffset(node); | ||
var focus = getFocusOffset(node); | ||
if (anchor != null) { | ||
var _anchor = _slicedToArray(anchor, 1), | ||
offset = _anchor[0]; | ||
if (anchor != null) { | ||
var _anchor = _slicedToArray(anchor, 1), | ||
offset = _anchor[0]; | ||
selection.anchor = { | ||
path: path, | ||
offset: offset | ||
}; | ||
} | ||
selection.anchor = { | ||
path: path, | ||
offset: offset | ||
}; | ||
} | ||
if (focus != null) { | ||
var _focus = _slicedToArray(focus, 1), | ||
_offset = _focus[0]; | ||
if (focus != null) { | ||
var _focus = _slicedToArray(focus, 1), | ||
_offset = _focus[0]; | ||
selection.focus = { | ||
path: path, | ||
offset: _offset | ||
}; | ||
selection.focus = { | ||
path: path, | ||
offset: _offset | ||
}; | ||
} | ||
} | ||
} catch (err) { | ||
_iterator3.e(err); | ||
} finally { | ||
_iterator3.f(); | ||
} | ||
} catch (err) { | ||
_iterator3.e(err); | ||
} finally { | ||
_iterator3.f(); | ||
} | ||
if (selection.anchor && !selection.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 (selection.anchor && !selection.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 (!selection.anchor && selection.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."); | ||
} | ||
if (!selection.anchor && selection.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."); | ||
} | ||
if (selectionChild != null) { | ||
editor.selection = selectionChild; | ||
} else if (slate.Range.isRange(selection)) { | ||
editor.selection = selection; | ||
} | ||
if (selectionChild != null) { | ||
editor.selection = selectionChild; | ||
} else if (slate.Range.isRange(selection)) { | ||
editor.selection = selection; | ||
} | ||
return editor; | ||
} | ||
return editor; | ||
}; | ||
}; | ||
@@ -653,3 +655,3 @@ function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) { symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); } keys.push.apply(keys, symbols); } return keys; } | ||
cursor: createCursor, | ||
editor: createEditor, | ||
editor: createEditor(slate.createEditor), | ||
element: createElement, | ||
@@ -744,4 +746,5 @@ focus: createFocus, | ||
exports.createEditor = createEditor; | ||
exports.createHyperscript = createHyperscript; | ||
exports.jsx = jsx; | ||
//# sourceMappingURL=index.js.map |
@@ -589,86 +589,88 @@ (function (global, factory) { | ||
function createEditor(tagName, attributes, children) { | ||
var otherChildren = []; | ||
var selectionChild; | ||
var createEditor = function createEditor(makeEditor) { | ||
return function (tagName, attributes, children) { | ||
var otherChildren = []; | ||
var selectionChild; | ||
var _iterator2 = _createForOfIteratorHelper(children), | ||
_step2; | ||
var _iterator2 = _createForOfIteratorHelper(children), | ||
_step2; | ||
try { | ||
for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) { | ||
var child = _step2.value; | ||
try { | ||
for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) { | ||
var child = _step2.value; | ||
if (slate.Range.isRange(child)) { | ||
selectionChild = child; | ||
} else { | ||
otherChildren.push(child); | ||
if (slate.Range.isRange(child)) { | ||
selectionChild = child; | ||
} else { | ||
otherChildren.push(child); | ||
} | ||
} | ||
} catch (err) { | ||
_iterator2.e(err); | ||
} finally { | ||
_iterator2.f(); | ||
} | ||
} catch (err) { | ||
_iterator2.e(err); | ||
} finally { | ||
_iterator2.f(); | ||
} | ||
var descendants = resolveDescendants(otherChildren); | ||
var selection = {}; | ||
var editor = slate.createEditor(); | ||
Object.assign(editor, attributes); | ||
editor.children = descendants; // Search the document's texts to see if any of them have tokens associated | ||
// that need incorporated into the selection. | ||
var descendants = resolveDescendants(otherChildren); | ||
var selection = {}; | ||
var editor = makeEditor(); | ||
Object.assign(editor, attributes); | ||
editor.children = descendants; // Search the document's texts to see if any of them have tokens associated | ||
// that need incorporated into the selection. | ||
var _iterator3 = _createForOfIteratorHelper(slate.Node.texts(editor)), | ||
_step3; | ||
var _iterator3 = _createForOfIteratorHelper(slate.Node.texts(editor)), | ||
_step3; | ||
try { | ||
for (_iterator3.s(); !(_step3 = _iterator3.n()).done;) { | ||
var _step3$value = _slicedToArray(_step3.value, 2), | ||
node = _step3$value[0], | ||
path = _step3$value[1]; | ||
try { | ||
for (_iterator3.s(); !(_step3 = _iterator3.n()).done;) { | ||
var _step3$value = _slicedToArray(_step3.value, 2), | ||
node = _step3$value[0], | ||
path = _step3$value[1]; | ||
var anchor = getAnchorOffset(node); | ||
var focus = getFocusOffset(node); | ||
var anchor = getAnchorOffset(node); | ||
var focus = getFocusOffset(node); | ||
if (anchor != null) { | ||
var _anchor = _slicedToArray(anchor, 1), | ||
offset = _anchor[0]; | ||
if (anchor != null) { | ||
var _anchor = _slicedToArray(anchor, 1), | ||
offset = _anchor[0]; | ||
selection.anchor = { | ||
path: path, | ||
offset: offset | ||
}; | ||
} | ||
selection.anchor = { | ||
path: path, | ||
offset: offset | ||
}; | ||
} | ||
if (focus != null) { | ||
var _focus = _slicedToArray(focus, 1), | ||
_offset = _focus[0]; | ||
if (focus != null) { | ||
var _focus = _slicedToArray(focus, 1), | ||
_offset = _focus[0]; | ||
selection.focus = { | ||
path: path, | ||
offset: _offset | ||
}; | ||
selection.focus = { | ||
path: path, | ||
offset: _offset | ||
}; | ||
} | ||
} | ||
} catch (err) { | ||
_iterator3.e(err); | ||
} finally { | ||
_iterator3.f(); | ||
} | ||
} catch (err) { | ||
_iterator3.e(err); | ||
} finally { | ||
_iterator3.f(); | ||
} | ||
if (selection.anchor && !selection.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 (selection.anchor && !selection.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 (!selection.anchor && selection.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."); | ||
} | ||
if (!selection.anchor && selection.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."); | ||
} | ||
if (selectionChild != null) { | ||
editor.selection = selectionChild; | ||
} else if (slate.Range.isRange(selection)) { | ||
editor.selection = selection; | ||
} | ||
if (selectionChild != null) { | ||
editor.selection = selectionChild; | ||
} else if (slate.Range.isRange(selection)) { | ||
editor.selection = selection; | ||
} | ||
return editor; | ||
} | ||
return editor; | ||
}; | ||
}; | ||
@@ -685,3 +687,3 @@ function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) { symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); } keys.push.apply(keys, symbols); } return keys; } | ||
cursor: createCursor, | ||
editor: createEditor, | ||
editor: createEditor(slate.createEditor), | ||
element: createElement, | ||
@@ -776,2 +778,3 @@ focus: createFocus, | ||
exports.createEditor = createEditor; | ||
exports.createHyperscript = createHyperscript; | ||
@@ -778,0 +781,0 @@ exports.jsx = jsx; |
@@ -8,2 +8,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="undefined"!=typeof globalThis?globalThis:t||self).SlateHyperscript={},t.Slate)}(this,(function(t,e){"use strict";function r(t){return t&&t.__esModule&&Object.prototype.hasOwnProperty.call(t,"default")?t.default:t}function n(t,e){return t(e={exports:{}},e.exports),e.exports}var o=n((function(t){function e(r){return"function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?(t.exports=e=function(t){return typeof t},t.exports.default=t.exports,t.exports.__esModule=!0):(t.exports=e=function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},t.exports.default=t.exports,t.exports.__esModule=!0),e(r)}t.exports=e,t.exports.default=t.exports,t.exports.__esModule=!0})),u=r(o),i=r(n((function(t){t.exports=function(t,e,r){return e in t?Object.defineProperty(t,e,{value:r,enumerable:!0,configurable:!0,writable:!0}):t[e]=r,t},t.exports.default=t.exports,t.exports.__esModule=!0}))); | ||
*/ | ||
function s(t){return"[object Object]"===Object.prototype.toString.call(t)}function f(t){var e,r;return!1!==s(t)&&(void 0===(e=t.constructor)||!1!==s(r=e.prototype)&&!1!==r.hasOwnProperty("isPrototypeOf"))}var a=n((function(t){t.exports=function(t){if(Array.isArray(t))return t},t.exports.default=t.exports,t.exports.__esModule=!0}));r(a);var c=n((function(t){t.exports=function(t,e){var r=null==t?null:"undefined"!=typeof Symbol&&t[Symbol.iterator]||t["@@iterator"];if(null!=r){var n,o,u=[],i=!0,s=!1;try{for(r=r.call(t);!(i=(n=r.next()).done)&&(u.push(n.value),!e||u.length!==e);i=!0);}catch(t){s=!0,o=t}finally{try{i||null==r.return||r.return()}finally{if(s)throw o}}return u}},t.exports.default=t.exports,t.exports.__esModule=!0}));r(c);var l=n((function(t){t.exports=function(t,e){(null==e||e>t.length)&&(e=t.length);for(var r=0,n=new Array(e);r<e;r++)n[r]=t[r];return n},t.exports.default=t.exports,t.exports.__esModule=!0}));r(l);var p=n((function(t){t.exports=function(t,e){if(t){if("string"==typeof t)return l(t,e);var r=Object.prototype.toString.call(t).slice(8,-1);return"Object"===r&&t.constructor&&(r=t.constructor.name),"Map"===r||"Set"===r?Array.from(t):"Arguments"===r||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r)?l(t,e):void 0}},t.exports.default=t.exports,t.exports.__esModule=!0}));r(p);var d=n((function(t){t.exports=function(){throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")},t.exports.default=t.exports,t.exports.__esModule=!0}));r(d);var h=r(n((function(t){t.exports=function(t,e){return a(t)||c(t,e)||p(t,e)||d()},t.exports.default=t.exports,t.exports.__esModule=!0}))),y=n((function(t){function e(r,n){return t.exports=e=Object.setPrototypeOf||function(t,e){return t.__proto__=e,t},t.exports.default=t.exports,t.exports.__esModule=!0,e(r,n)}t.exports=e,t.exports.default=t.exports,t.exports.__esModule=!0}));r(y);var x=r(n((function(t){t.exports=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)},t.exports.default=t.exports,t.exports.__esModule=!0}))),b=n((function(t){t.exports=function(t){if(void 0===t)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return t},t.exports.default=t.exports,t.exports.__esModule=!0}));r(b);var v=r(n((function(t){var e=o.default;t.exports=function(t,r){if(r&&("object"===e(r)||"function"==typeof r))return r;if(void 0!==r)throw new TypeError("Derived constructors may only return object or undefined");return b(t)},t.exports.default=t.exports,t.exports.__esModule=!0}))),g=r(n((function(t){function e(r){return t.exports=e=Object.setPrototypeOf?Object.getPrototypeOf:function(t){return t.__proto__||Object.getPrototypeOf(t)},t.exports.default=t.exports,t.exports.__esModule=!0,e(r)}t.exports=e,t.exports.default=t.exports,t.exports.__esModule=!0}))),w=r(n((function(t){t.exports=function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")},t.exports.default=t.exports,t.exports.__esModule=!0})));function O(t){var e=function(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){}))),!0}catch(t){return!1}}();return function(){var r,n=g(t);if(e){var o=g(this).constructor;r=Reflect.construct(n,arguments,o)}else r=n.apply(this,arguments);return v(this,r)}}var m=new WeakMap,j=new WeakMap,_=function t(){w(this,t)},P=function(t){x(r,t);var e=O(r);function r(){var t,n=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};w(this,r),t=e.call(this);var o=n.offset,u=n.path;return t.offset=o,t.path=u,t}return r}(_),S=function(t){x(r,t);var e=O(r);function r(){var t,n=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};w(this,r),t=e.call(this);var o=n.offset,u=n.path;return t.offset=o,t.path=u,t}return r}(_),M=function(t){return j.get(t)};function E(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 T(t){for(var e=1;e<arguments.length;e++){var r=null!=arguments[e]?arguments[e]:{};e%2?E(Object(r),!0).forEach((function(e){i(t,e,r[e])})):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(r)):E(Object(r)).forEach((function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(r,e))}))}return t}function A(t,e){var r="undefined"!=typeof Symbol&&t[Symbol.iterator]||t["@@iterator"];if(!r){if(Array.isArray(t)||(r=function(t,e){if(!t)return;if("string"==typeof t)return R(t,e);var r=Object.prototype.toString.call(t).slice(8,-1);"Object"===r&&t.constructor&&(r=t.constructor.name);if("Map"===r||"Set"===r)return Array.from(t);if("Arguments"===r||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r))return R(t,e)}(t))||e&&t&&"number"==typeof t.length){r&&(t=r);var n=0,o=function(){};return{s:o,n:function(){return n>=t.length?{done:!0}:{done:!1,value:t[n++]}},e:function(t){throw t},f:o}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var u,i=!0,s=!1;return{s:function(){r=r.call(t)},n:function(){var t=r.next();return i=t.done,t},e:function(t){s=!0,u=t},f:function(){try{i||null==r.return||r.return()}finally{if(s)throw u}}}}function R(t,e){(null==e||e>t.length)&&(e=t.length);for(var r=0,n=new Array(e);r<e;r++)n[r]=t[r];return n}var D=new WeakSet,I=function(t){var r,n=[],o=function t(r){if(null!=r){var o=n[n.length-1];if("string"==typeof r){var u={text:r};D.add(u),r=u}if(e.Text.isText(r)){var i=r;e.Text.isText(o)&&D.has(o)&&D.has(i)&&e.Text.equals(o,i,{loose:!0})?o.text+=i.text:n.push(i)}else if(e.Element.isElement(r))n.push(r);else{if(!(r instanceof _))throw new Error("Unexpected hyperscript child object: ".concat(r));var s=n[n.length-1];e.Text.isText(s)||(t(""),s=n[n.length-1]),r instanceof P?function(t,e){var r=t.text.length;m.set(t,[r,e])}(s,r):r instanceof S&&function(t,e){var r=t.text.length;j.set(t,[r,e])}(s,r)}}},u=A(t.flat(1/0));try{for(u.s();!(r=u.n()).done;){o(r.value)}}catch(t){u.e(t)}finally{u.f()}return n};function k(t,e,r){return T(T({},e),{},{children:I(r)})}function B(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 C(t){for(var e=1;e<arguments.length;e++){var r=null!=arguments[e]?arguments[e]:{};e%2?B(Object(r),!0).forEach((function(e){i(t,e,r[e])})):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(r)):B(Object(r)).forEach((function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(r,e))}))}return t}var U={anchor:function(t,e,r){return new P(e)},cursor:function(t,e,r){return[new P(e),new S(e)]},editor:function(t,r,n){var o,u,i=[],s=A(n);try{for(s.s();!(u=s.n()).done;){var f=u.value;e.Range.isRange(f)?o=f:i.push(f)}}catch(t){s.e(t)}finally{s.f()}var a=I(i),c={},l=e.createEditor();Object.assign(l,r),l.children=a;var p,d,y=A(e.Node.texts(l));try{for(y.s();!(p=y.n()).done;){var x=h(p.value,2),b=x[0],v=x[1],g=(d=b,m.get(d)),w=M(b);if(null!=g){var O=h(g,1)[0];c.anchor={path:v,offset:O}}if(null!=w){var j=h(w,1)[0];c.focus={path:v,offset:j}}}}catch(t){y.e(t)}finally{y.f()}if(c.anchor&&!c.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(!c.anchor&&c.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?l.selection=o:e.Range.isRange(c)&&(l.selection=c),l},element:k,focus:function(t,e,r){return new S(e)},fragment:function(t,e,r){return I(r)},selection:function(t,e,r){var n=r.find((function(t){return t instanceof P})),o=r.find((function(t){return t instanceof S}));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 T({anchor:{offset:n.offset,path:n.path},focus:{offset:o.offset,path:o.path}},e)},text:function(t,r,n){var o=I(n);if(o.length>1)throw new Error("The <text> hyperscript tag must only contain a single node's worth of children.");var u=h(o,1)[0];if(null==u&&(u={text:""}),!e.Text.isText(u))throw new Error("\n The <text> hyperscript tag can only contain text content as children.");return D.delete(u),Object.assign(u,r),u}},W=function(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},e=t.elements,r=void 0===e?{}:e,n=F(r),o=C(C(C({},U),n),t.creators),u=q(o);return u},q=function(t){return function(e,r){for(var n=arguments.length,o=new Array(n>2?n-2:0),u=2;u<n;u++)o[u-2]=arguments[u];var i=t[e];if(!i)throw new Error("No hyperscript creator found for tag: <".concat(e,">"));null==r&&(r={}),f(r)||(o=[r].concat(o),r={});var s=i(e,r,o=o.filter((function(t){return Boolean(t)})).flat());return s}},F=function(t){var e={},r=function(r){var n=t[r];if("object"!==u(n))throw new Error("Properties specified for a hyperscript shorthand should be an object, but for the custom element <".concat(r,"> tag you passed: ").concat(n));e[r]=function(t,e,r){return k(0,C(C({},n),e),r)}};for(var n in t)r(n);return e},H=W();t.createHyperscript=W,t.jsx=H,Object.defineProperty(t,"__esModule",{value:!0})})); | ||
function s(t){return"[object Object]"===Object.prototype.toString.call(t)}function f(t){var e,r;return!1!==s(t)&&(void 0===(e=t.constructor)||!1!==s(r=e.prototype)&&!1!==r.hasOwnProperty("isPrototypeOf"))}var a=n((function(t){t.exports=function(t){if(Array.isArray(t))return t},t.exports.default=t.exports,t.exports.__esModule=!0}));r(a);var c=n((function(t){t.exports=function(t,e){var r=null==t?null:"undefined"!=typeof Symbol&&t[Symbol.iterator]||t["@@iterator"];if(null!=r){var n,o,u=[],i=!0,s=!1;try{for(r=r.call(t);!(i=(n=r.next()).done)&&(u.push(n.value),!e||u.length!==e);i=!0);}catch(t){s=!0,o=t}finally{try{i||null==r.return||r.return()}finally{if(s)throw o}}return u}},t.exports.default=t.exports,t.exports.__esModule=!0}));r(c);var l=n((function(t){t.exports=function(t,e){(null==e||e>t.length)&&(e=t.length);for(var r=0,n=new Array(e);r<e;r++)n[r]=t[r];return n},t.exports.default=t.exports,t.exports.__esModule=!0}));r(l);var p=n((function(t){t.exports=function(t,e){if(t){if("string"==typeof t)return l(t,e);var r=Object.prototype.toString.call(t).slice(8,-1);return"Object"===r&&t.constructor&&(r=t.constructor.name),"Map"===r||"Set"===r?Array.from(t):"Arguments"===r||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r)?l(t,e):void 0}},t.exports.default=t.exports,t.exports.__esModule=!0}));r(p);var d=n((function(t){t.exports=function(){throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")},t.exports.default=t.exports,t.exports.__esModule=!0}));r(d);var h=r(n((function(t){t.exports=function(t,e){return a(t)||c(t,e)||p(t,e)||d()},t.exports.default=t.exports,t.exports.__esModule=!0}))),y=n((function(t){function e(r,n){return t.exports=e=Object.setPrototypeOf||function(t,e){return t.__proto__=e,t},t.exports.default=t.exports,t.exports.__esModule=!0,e(r,n)}t.exports=e,t.exports.default=t.exports,t.exports.__esModule=!0}));r(y);var x=r(n((function(t){t.exports=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)},t.exports.default=t.exports,t.exports.__esModule=!0}))),v=n((function(t){t.exports=function(t){if(void 0===t)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return t},t.exports.default=t.exports,t.exports.__esModule=!0}));r(v);var b=r(n((function(t){var e=o.default;t.exports=function(t,r){if(r&&("object"===e(r)||"function"==typeof r))return r;if(void 0!==r)throw new TypeError("Derived constructors may only return object or undefined");return v(t)},t.exports.default=t.exports,t.exports.__esModule=!0}))),g=r(n((function(t){function e(r){return t.exports=e=Object.setPrototypeOf?Object.getPrototypeOf:function(t){return t.__proto__||Object.getPrototypeOf(t)},t.exports.default=t.exports,t.exports.__esModule=!0,e(r)}t.exports=e,t.exports.default=t.exports,t.exports.__esModule=!0}))),w=r(n((function(t){t.exports=function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")},t.exports.default=t.exports,t.exports.__esModule=!0})));function O(t){var e=function(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){}))),!0}catch(t){return!1}}();return function(){var r,n=g(t);if(e){var o=g(this).constructor;r=Reflect.construct(n,arguments,o)}else r=n.apply(this,arguments);return b(this,r)}}var m=new WeakMap,j=new WeakMap,_=function t(){w(this,t)},P=function(t){x(r,t);var e=O(r);function r(){var t,n=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};w(this,r),t=e.call(this);var o=n.offset,u=n.path;return t.offset=o,t.path=u,t}return r}(_),S=function(t){x(r,t);var e=O(r);function r(){var t,n=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};w(this,r),t=e.call(this);var o=n.offset,u=n.path;return t.offset=o,t.path=u,t}return r}(_),M=function(t){return j.get(t)};function E(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 T(t){for(var e=1;e<arguments.length;e++){var r=null!=arguments[e]?arguments[e]:{};e%2?E(Object(r),!0).forEach((function(e){i(t,e,r[e])})):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(r)):E(Object(r)).forEach((function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(r,e))}))}return t}function A(t,e){var r="undefined"!=typeof Symbol&&t[Symbol.iterator]||t["@@iterator"];if(!r){if(Array.isArray(t)||(r=function(t,e){if(!t)return;if("string"==typeof t)return R(t,e);var r=Object.prototype.toString.call(t).slice(8,-1);"Object"===r&&t.constructor&&(r=t.constructor.name);if("Map"===r||"Set"===r)return Array.from(t);if("Arguments"===r||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r))return R(t,e)}(t))||e&&t&&"number"==typeof t.length){r&&(t=r);var n=0,o=function(){};return{s:o,n:function(){return n>=t.length?{done:!0}:{done:!1,value:t[n++]}},e:function(t){throw t},f:o}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var u,i=!0,s=!1;return{s:function(){r=r.call(t)},n:function(){var t=r.next();return i=t.done,t},e:function(t){s=!0,u=t},f:function(){try{i||null==r.return||r.return()}finally{if(s)throw u}}}}function R(t,e){(null==e||e>t.length)&&(e=t.length);for(var r=0,n=new Array(e);r<e;r++)n[r]=t[r];return n}var D=new WeakSet,I=function(t){var r,n=[],o=function t(r){if(null!=r){var o=n[n.length-1];if("string"==typeof r){var u={text:r};D.add(u),r=u}if(e.Text.isText(r)){var i=r;e.Text.isText(o)&&D.has(o)&&D.has(i)&&e.Text.equals(o,i,{loose:!0})?o.text+=i.text:n.push(i)}else if(e.Element.isElement(r))n.push(r);else{if(!(r instanceof _))throw new Error("Unexpected hyperscript child object: ".concat(r));var s=n[n.length-1];e.Text.isText(s)||(t(""),s=n[n.length-1]),r instanceof P?function(t,e){var r=t.text.length;m.set(t,[r,e])}(s,r):r instanceof S&&function(t,e){var r=t.text.length;j.set(t,[r,e])}(s,r)}}},u=A(t.flat(1/0));try{for(u.s();!(r=u.n()).done;){o(r.value)}}catch(t){u.e(t)}finally{u.f()}return n};function k(t,e,r){return T(T({},e),{},{children:I(r)})}var B=function(t){return function(r,n,o){var u,i,s=[],f=A(o);try{for(f.s();!(i=f.n()).done;){var a=i.value;e.Range.isRange(a)?u=a:s.push(a)}}catch(t){f.e(t)}finally{f.f()}var c=I(s),l={},p=t();Object.assign(p,n),p.children=c;var d,y,x=A(e.Node.texts(p));try{for(x.s();!(d=x.n()).done;){var v=h(d.value,2),b=v[0],g=v[1],w=(y=b,m.get(y)),O=M(b);if(null!=w){var j=h(w,1)[0];l.anchor={path:g,offset:j}}if(null!=O){var _=h(O,1)[0];l.focus={path:g,offset:_}}}}catch(t){x.e(t)}finally{x.f()}if(l.anchor&&!l.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(!l.anchor&&l.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!=u?p.selection=u:e.Range.isRange(l)&&(p.selection=l),p}};function C(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 U(t){for(var e=1;e<arguments.length;e++){var r=null!=arguments[e]?arguments[e]:{};e%2?C(Object(r),!0).forEach((function(e){i(t,e,r[e])})):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(r)):C(Object(r)).forEach((function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(r,e))}))}return t}var W={anchor:function(t,e,r){return new P(e)},cursor:function(t,e,r){return[new P(e),new S(e)]},editor:B(e.createEditor),element:k,focus:function(t,e,r){return new S(e)},fragment:function(t,e,r){return I(r)},selection:function(t,e,r){var n=r.find((function(t){return t instanceof P})),o=r.find((function(t){return t instanceof S}));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 T({anchor:{offset:n.offset,path:n.path},focus:{offset:o.offset,path:o.path}},e)},text:function(t,r,n){var o=I(n);if(o.length>1)throw new Error("The <text> hyperscript tag must only contain a single node's worth of children.");var u=h(o,1)[0];if(null==u&&(u={text:""}),!e.Text.isText(u))throw new Error("\n The <text> hyperscript tag can only contain text content as children.");return D.delete(u),Object.assign(u,r),u}},q=function(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},e=t.elements,r=void 0===e?{}:e,n=H(r),o=U(U(U({},W),n),t.creators),u=F(o);return u},F=function(t){return function(e,r){for(var n=arguments.length,o=new Array(n>2?n-2:0),u=2;u<n;u++)o[u-2]=arguments[u];var i=t[e];if(!i)throw new Error("No hyperscript creator found for tag: <".concat(e,">"));null==r&&(r={}),f(r)||(o=[r].concat(o),r={});var s=i(e,r,o=o.filter((function(t){return Boolean(t)})).flat());return s}},H=function(t){var e={},r=function(r){var n=t[r];if("object"!==u(n))throw new Error("Properties specified for a hyperscript shorthand should be an object, but for the custom element <".concat(r,"> tag you passed: ").concat(n));e[r]=function(t,e,r){return k(0,U(U({},n),e),r)}};for(var n in t)r(n);return e},N=q();t.createEditor=B,t.createHyperscript=q,t.jsx=N,Object.defineProperty(t,"__esModule",{value:!0})})); |
{ | ||
"name": "slate-hyperscript", | ||
"description": "A hyperscript helper for creating Slate documents.", | ||
"version": "0.66.0", | ||
"version": "0.66.8-202191204027", | ||
"license": "MIT", | ||
@@ -6,0 +6,0 @@ "repository": "git://github.com/ianstormtaylor/slate.git", |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
141379
1777