Comparing version 1.1.1 to 1.1.2
@@ -0,1 +1,14 @@ | ||
## [1.1.2](https://github.com/jquense/jarle/compare/v1.1.0...v1.1.2) (2021-02-02) | ||
### Bug Fixes | ||
* @4c/tsconfig to dev dependencies ([#8](https://github.com/jquense/jarle/issues/8)) ([55582c8](https://github.com/jquense/jarle/commit/55582c842a8a77c9caa9c5526ff9345f87181916)) | ||
* default import ([a63fad9](https://github.com/jquense/jarle/commit/a63fad971261c40b09bde999cd0c917056e63e54)) | ||
* **Preview:** allow props to override defaults ([#5](https://github.com/jquense/jarle/issues/5)) ([3e3e3a7](https://github.com/jquense/jarle/commit/3e3e3a77b6611d0b7c759199833bc9a26c939f51)), closes [#4](https://github.com/jquense/jarle/issues/4) | ||
## [1.1.1](https://github.com/jquense/jarle/compare/v1.1.0...v1.1.1) (2021-02-01) | ||
@@ -2,0 +15,0 @@ |
@@ -1,20 +0,1 @@ | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
exports.default = exports.mapTokens = void 0; | ||
var _classnames = _interopRequireDefault(require("classnames")); | ||
var _prismReactRenderer = _interopRequireWildcard(require("prism-react-renderer")); | ||
var _react = _interopRequireDefault(require("react")); | ||
function _getRequireWildcardCache() { if (typeof WeakMap !== "function") return null; var cache = new WeakMap(); _getRequireWildcardCache = function () { return cache; }; return cache; } | ||
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; } | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
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; } | ||
@@ -32,5 +13,9 @@ | ||
import cn from 'classnames'; | ||
import Highlight, { Prism } from 'prism-react-renderer'; | ||
import React from 'react'; | ||
function addErrorHighlight(props, index, errorLocation) { | ||
if (errorLocation && index === errorLocation.line) { | ||
props.className = (0, _classnames.default)(props.className, 'token-line-error'); | ||
props.className = cn(props.className, 'token-line-error'); | ||
} | ||
@@ -41,3 +26,3 @@ | ||
const mapTokens = ({ | ||
export const mapTokens = ({ | ||
tokens, | ||
@@ -47,6 +32,6 @@ getLineProps, | ||
errorLocation | ||
}) => /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null, tokens.map((line, i) => | ||
}) => /*#__PURE__*/React.createElement(React.Fragment, null, tokens.map((line, i) => | ||
/*#__PURE__*/ | ||
// eslint-disable-next-line react/no-array-index-key | ||
_react.default.createElement("div", addErrorHighlight(getLineProps({ | ||
React.createElement("div", addErrorHighlight(getLineProps({ | ||
line, | ||
@@ -57,3 +42,3 @@ key: String(i) | ||
// eslint-disable-next-line react/no-array-index-key | ||
_react.default.createElement("span", _extends({ | ||
React.createElement("span", _extends({ | ||
key: ii | ||
@@ -65,4 +50,2 @@ }, getTokenProps({ | ||
exports.mapTokens = mapTokens; | ||
function CodeBlock(_ref) { | ||
@@ -78,11 +61,11 @@ let { | ||
const style = typeof (theme === null || theme === void 0 ? void 0 : theme.plain) === 'object' ? theme.plain : {}; | ||
return /*#__PURE__*/_react.default.createElement(_prismReactRenderer.default, { | ||
return /*#__PURE__*/React.createElement(Highlight, { | ||
theme: theme, | ||
Prism: _prismReactRenderer.Prism, | ||
Prism: Prism, | ||
code: code.trim(), | ||
language: language | ||
}, hl => /*#__PURE__*/_react.default.createElement("pre", { | ||
className: (0, _classnames.default)(props.className, hl.className), | ||
}, hl => /*#__PURE__*/React.createElement("pre", { | ||
className: cn(props.className, hl.className), | ||
style: _objectSpread(_objectSpread(_objectSpread({}, props.style), style), hl.style) | ||
}, /*#__PURE__*/_react.default.createElement("code", null, mapTokens(_objectSpread(_objectSpread({}, hl), {}, { | ||
}, /*#__PURE__*/React.createElement("code", null, mapTokens(_objectSpread(_objectSpread({}, hl), {}, { | ||
lineNumbers, | ||
@@ -93,3 +76,2 @@ hasTheme: !!theme | ||
var _default = CodeBlock; | ||
exports.default = _default; | ||
export default CodeBlock; |
@@ -1,32 +0,1 @@ | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
exports.default = void 0; | ||
var _prismReactRenderer = _interopRequireWildcard(require("prism-react-renderer")); | ||
var _useMergeState = _interopRequireDefault(require("@restart/hooks/useMergeState")); | ||
var _useStableMemo = _interopRequireDefault(require("@restart/hooks/useStableMemo")); | ||
var _react = _interopRequireWildcard(require("react")); | ||
var _reactSimpleCodeEditor = _interopRequireDefault(require("react-simple-code-editor")); | ||
var _CodeBlock = require("./CodeBlock"); | ||
var _InfoMessage = _interopRequireDefault(require("./InfoMessage")); | ||
var _Provider = require("./Provider"); | ||
var _LineNumber = _interopRequireDefault(require("./LineNumber")); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
function _getRequireWildcardCache() { if (typeof WeakMap !== "function") return null; var cache = new WeakMap(); _getRequireWildcardCache = function () { return cache; }; return cache; } | ||
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; } | ||
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; } | ||
@@ -38,8 +7,17 @@ | ||
import Highlight, { Prism } from 'prism-react-renderer'; | ||
import useMergeState from '@restart/hooks/useMergeState'; | ||
import useStableMemo from '@restart/hooks/useStableMemo'; | ||
import React, { useCallback, useLayoutEffect, useMemo, useRef, useState } from 'react'; | ||
import SimpleCodeEditor from 'react-simple-code-editor'; | ||
import { mapTokens } from './CodeBlock'; | ||
import InfoMessage from './InfoMessage'; | ||
import { useLiveContext } from './Provider'; | ||
import LineNumber from './LineNumber'; | ||
let uid = 0; | ||
function useStateFromProp(prop) { | ||
const state = (0, _react.useState)(prop); | ||
const firstRef = (0, _react.useRef)(true); | ||
(0, _useStableMemo.default)(() => { | ||
const state = useState(prop); | ||
const firstRef = useRef(true); | ||
useStableMemo(() => { | ||
if (firstRef.current) { | ||
@@ -59,7 +37,7 @@ firstRef.current = false; | ||
*/ | ||
const Editor = /*#__PURE__*/_react.default.forwardRef(({ | ||
const Editor = /*#__PURE__*/React.forwardRef(({ | ||
style, | ||
className, | ||
theme, | ||
infoComponent: Info = _InfoMessage.default, | ||
infoComponent: Info = InfoMessage, | ||
lineNumbers, | ||
@@ -74,7 +52,7 @@ infoSrOnly: _infoSrOnly = false | ||
error | ||
} = (0, _Provider.useLiveContext)(); | ||
} = useLiveContext(); | ||
const userTheme = theme || contextTheme; | ||
const [code, setCode] = useStateFromProp(contextCode); | ||
const mouseDown = (0, _react.useRef)(false); | ||
(0, _react.useLayoutEffect)(() => { | ||
const mouseDown = useRef(false); | ||
useLayoutEffect(() => { | ||
onChange(code || ''); | ||
@@ -86,3 +64,3 @@ }, [code, onChange]); | ||
keyboardFocused | ||
}, setState] = (0, _useMergeState.default)({ | ||
}, setState] = useMergeState({ | ||
visible: false, | ||
@@ -92,3 +70,3 @@ ignoreTab: false, | ||
}); | ||
const id = (0, _react.useMemo)(() => `described-by-${++uid}`, []); | ||
const id = useMemo(() => `described-by-${++uid}`, []); | ||
@@ -137,8 +115,8 @@ const handleKeyDown = event => { | ||
const highlight = (0, _react.useCallback)(value => /*#__PURE__*/_react.default.createElement(_prismReactRenderer.default, { | ||
const highlight = useCallback(value => /*#__PURE__*/React.createElement(Highlight, { | ||
theme: userTheme, | ||
Prism: _prismReactRenderer.Prism, | ||
Prism: Prism, | ||
code: value, | ||
language: language | ||
}, hl => (0, _CodeBlock.mapTokens)(_objectSpread(_objectSpread({}, hl), {}, { | ||
}, hl => mapTokens(_objectSpread(_objectSpread({}, hl), {}, { | ||
hasTheme: !!userTheme, | ||
@@ -153,3 +131,3 @@ errorLocation: error === null || error === void 0 ? void 0 : error.location | ||
return /*#__PURE__*/_react.default.createElement("div", { | ||
return /*#__PURE__*/React.createElement("div", { | ||
ref: ref, | ||
@@ -162,7 +140,7 @@ className: className, | ||
}) | ||
}, /*#__PURE__*/_react.default.createElement("div", { | ||
}, /*#__PURE__*/React.createElement("div", { | ||
className: "line-numbers" | ||
}, lineNumbers && (code || '').split(/\n/g).map((_, i) => /*#__PURE__*/_react.default.createElement(_LineNumber.default, { | ||
}, lineNumbers && (code || '').split(/\n/g).map((_, i) => /*#__PURE__*/React.createElement(LineNumber, { | ||
theme: userTheme | ||
}, i + 1))), /*#__PURE__*/_react.default.createElement(_reactSimpleCodeEditor.default, { | ||
}, i + 1))), /*#__PURE__*/React.createElement(SimpleCodeEditor, { | ||
value: code || '', | ||
@@ -178,10 +156,8 @@ onFocus: handleFocus, | ||
"aria-label": "Example code editor" | ||
}), visible && (keyboardFocused || !ignoreTab) && /*#__PURE__*/_react.default.createElement(Info, { | ||
}), visible && (keyboardFocused || !ignoreTab) && /*#__PURE__*/React.createElement(Info, { | ||
id: id, | ||
"aria-live": "polite", | ||
srOnly: _infoSrOnly | ||
}, ignoreTab ? /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null, "Press ", /*#__PURE__*/_react.default.createElement("kbd", null, "enter"), " or type a key to enable tab-to-indent") : /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null, "Press ", /*#__PURE__*/_react.default.createElement("kbd", null, "esc"), " to disable tab-to-indent"))); | ||
}, ignoreTab ? /*#__PURE__*/React.createElement(React.Fragment, null, "Press ", /*#__PURE__*/React.createElement("kbd", null, "enter"), " or type a key to enable tab-to-indent") : /*#__PURE__*/React.createElement(React.Fragment, null, "Press ", /*#__PURE__*/React.createElement("kbd", null, "esc"), " to disable tab-to-indent"))); | ||
}); | ||
var _default = Editor; | ||
exports.default = _default; | ||
export default Editor; |
@@ -1,14 +0,3 @@ | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
exports.default = Error; | ||
var _react = _interopRequireDefault(require("react")); | ||
var _Provider = require("./Provider"); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
import React from 'react'; | ||
import { useError } from './Provider'; | ||
/** | ||
@@ -18,5 +7,6 @@ * Displays an sytax or runtime error that occured when rendering the code | ||
*/ | ||
function Error(props) { | ||
const error = (0, _Provider.useError)(); | ||
return error ? /*#__PURE__*/_react.default.createElement("pre", props, error.toString()) : null; | ||
export default function Error(props) { | ||
const error = useError(); | ||
return error ? /*#__PURE__*/React.createElement("pre", props, error.toString()) : null; | ||
} |
@@ -1,15 +0,5 @@ | ||
"use strict"; | ||
import React from 'react'; | ||
import { Context } from './Provider'; | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
exports.default = void 0; | ||
var _react = _interopRequireDefault(require("react")); | ||
var _Provider = require("./Provider"); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
class CodeLiveErrorBoundary extends _react.default.Component { | ||
class CodeLiveErrorBoundary extends React.Component { | ||
componentDidCatch(error) { | ||
@@ -23,3 +13,3 @@ this.context.onError(error); | ||
} = this.props; | ||
return typeof Element === 'function' ? /*#__PURE__*/_react.default.createElement(Element, null) : Element; | ||
return typeof Element === 'function' ? /*#__PURE__*/React.createElement(Element, null) : Element; | ||
} | ||
@@ -29,4 +19,3 @@ | ||
CodeLiveErrorBoundary.contextType = _Provider.Context; | ||
var _default = CodeLiveErrorBoundary; | ||
exports.default = _default; | ||
CodeLiveErrorBoundary.contextType = Context; | ||
export default CodeLiveErrorBoundary; |
@@ -1,15 +0,5 @@ | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
exports.default = void 0; | ||
var _prismReactRenderer = require("prism-react-renderer"); | ||
var _default = (code, language) => { | ||
const grammar = language && _prismReactRenderer.Prism.languages[language]; | ||
return grammar ? _prismReactRenderer.Prism.highlight(code, grammar, language) : code; | ||
}; | ||
exports.default = _default; | ||
import { Prism } from 'prism-react-renderer'; | ||
export default ((code, language) => { | ||
const grammar = language && Prism.languages[language]; | ||
return grammar ? Prism.highlight(code, grammar, language) : code; | ||
}); |
@@ -1,71 +0,9 @@ | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
Object.defineProperty(exports, "Prism", { | ||
enumerable: true, | ||
get: function () { | ||
return _prismReactRenderer.Prism; | ||
} | ||
}); | ||
Object.defineProperty(exports, "CodeBlock", { | ||
enumerable: true, | ||
get: function () { | ||
return _CodeBlock.default; | ||
} | ||
}); | ||
Object.defineProperty(exports, "Editor", { | ||
enumerable: true, | ||
get: function () { | ||
return _Editor.default; | ||
} | ||
}); | ||
Object.defineProperty(exports, "Error", { | ||
enumerable: true, | ||
get: function () { | ||
return _Error.default; | ||
} | ||
}); | ||
Object.defineProperty(exports, "InfoMessage", { | ||
enumerable: true, | ||
get: function () { | ||
return _InfoMessage.default; | ||
} | ||
}); | ||
Object.defineProperty(exports, "Preview", { | ||
enumerable: true, | ||
get: function () { | ||
return _Preview.default; | ||
} | ||
}); | ||
Object.defineProperty(exports, "Provider", { | ||
enumerable: true, | ||
get: function () { | ||
return _Provider.default; | ||
} | ||
}); | ||
Object.defineProperty(exports, "highlight", { | ||
enumerable: true, | ||
get: function () { | ||
return _highlight.default; | ||
} | ||
}); | ||
var _prismReactRenderer = require("prism-react-renderer"); | ||
var _CodeBlock = _interopRequireDefault(require("./CodeBlock")); | ||
var _Editor = _interopRequireDefault(require("./Editor")); | ||
var _Error = _interopRequireDefault(require("./Error")); | ||
var _InfoMessage = _interopRequireDefault(require("./InfoMessage")); | ||
var _Preview = _interopRequireDefault(require("./Preview")); | ||
var _Provider = _interopRequireDefault(require("./Provider")); | ||
var _highlight = _interopRequireDefault(require("./highlight")); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
import { Prism } from 'prism-react-renderer'; | ||
import CodeBlock from './CodeBlock'; | ||
import Editor from './Editor'; | ||
import Error from './Error'; | ||
import InfoMessage from './InfoMessage'; | ||
import Preview from './Preview'; | ||
import Provider from './Provider'; | ||
import highlight from './highlight'; | ||
export { Prism, CodeBlock, Error, Editor, Preview, Provider, InfoMessage, highlight }; |
@@ -1,12 +0,1 @@ | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
exports.default = InfoMessage; | ||
var _react = _interopRequireDefault(require("react")); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
function _extends() { _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); } | ||
@@ -24,2 +13,3 @@ | ||
import React from 'react'; | ||
const srOnlyStyle = { | ||
@@ -34,4 +24,3 @@ clip: 'rect(1px, 1px, 1px, 1px)', | ||
}; | ||
function InfoMessage(_ref) { | ||
export default function InfoMessage(_ref) { | ||
let { | ||
@@ -42,3 +31,3 @@ srOnly = false | ||
return /*#__PURE__*/_react.default.createElement("div", _extends({}, props, { | ||
return /*#__PURE__*/React.createElement("div", _extends({}, props, { | ||
style: _objectSpread({ | ||
@@ -45,0 +34,0 @@ pointerEvents: 'none', |
@@ -1,12 +0,1 @@ | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
exports.default = void 0; | ||
var _react = _interopRequireDefault(require("react")); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
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; } | ||
@@ -18,2 +7,3 @@ | ||
import React from 'react'; | ||
const lineNumberStyle = { | ||
@@ -30,3 +20,3 @@ textAlign: 'right', | ||
}) { | ||
return /*#__PURE__*/_react.default.createElement("div", { | ||
return /*#__PURE__*/React.createElement("div", { | ||
"aria-hidden": true, | ||
@@ -38,3 +28,2 @@ className: "line-number", | ||
var _default = LineNumber; | ||
exports.default = _default; | ||
export default LineNumber; |
@@ -1,22 +0,1 @@ | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
exports.default = void 0; | ||
var _useCallbackRef = _interopRequireDefault(require("@restart/hooks/useCallbackRef")); | ||
var _react = _interopRequireWildcard(require("react")); | ||
var _ErrorBoundary = _interopRequireDefault(require("./ErrorBoundary")); | ||
var _Provider = require("./Provider"); | ||
function _getRequireWildcardCache() { if (typeof WeakMap !== "function") return null; var cache = new WeakMap(); _getRequireWildcardCache = function () { return cache; }; return cache; } | ||
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; } | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
function _extends() { _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); } | ||
@@ -34,2 +13,6 @@ | ||
import useCallbackRef from '@restart/hooks/useCallbackRef'; | ||
import React, { useEffect } from 'react'; | ||
import ErrorBoundary from './ErrorBoundary'; | ||
import { useElement, useError } from './Provider'; | ||
let holderjs; | ||
@@ -56,10 +39,10 @@ | ||
const [example, attachRef] = (0, _useCallbackRef.default)(); | ||
const [example, attachRef] = useCallbackRef(); | ||
const hasTheme = !!holderTheme && holderjs; | ||
const element = (0, _Provider.useElement)(); | ||
const error = (0, _Provider.useError)(); | ||
(0, _react.useEffect)(() => { | ||
const element = useElement(); | ||
const error = useError(); | ||
useEffect(() => { | ||
if (hasTheme) holderjs.addTheme('userTheme', holderTheme); // eslint-disable-next-line react-hooks/exhaustive-deps | ||
}, [hasTheme]); | ||
(0, _react.useEffect)(() => { | ||
useEffect(() => { | ||
if (!example || !holderjs) return; | ||
@@ -84,7 +67,7 @@ holderjs.run({ | ||
// eslint-disable-next-line jsx-a11y/no-noninteractive-element-interactions, jsx-a11y/click-events-have-key-events | ||
_react.default.createElement("div", _extends({ | ||
React.createElement("div", _extends({ | ||
ref: attachRef, | ||
className: className, | ||
onClick: handleClick | ||
}, previewProps), /*#__PURE__*/_react.default.createElement(_ErrorBoundary.default, { | ||
}, previewProps), /*#__PURE__*/React.createElement(ErrorBoundary, { | ||
element: element | ||
@@ -94,3 +77,2 @@ })); | ||
var _default = Preview; | ||
exports.default = _default; | ||
export default Preview; |
@@ -1,28 +0,1 @@ | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
exports.useLiveContext = useLiveContext; | ||
exports.useElement = useElement; | ||
exports.useError = useError; | ||
exports.default = Provider; | ||
exports.objectZip = exports.Context = void 0; | ||
var _useEventCallback = _interopRequireDefault(require("@restart/hooks/useEventCallback")); | ||
var _react = _interopRequireWildcard(require("react")); | ||
var _reactIs = require("react-is"); | ||
var _sourcemapCodec = require("sourcemap-codec"); | ||
var _transpile = _interopRequireWildcard(require("./transpile")); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
function _getRequireWildcardCache() { if (typeof WeakMap !== "function") return null; var cache = new WeakMap(); _getRequireWildcardCache = function () { return cache; }; return cache; } | ||
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; } | ||
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; } | ||
@@ -34,12 +7,14 @@ | ||
import useEventCallback from '@restart/hooks/useEventCallback'; | ||
import React, { useContext, useEffect, useMemo, useState, isValidElement, createElement } from 'react'; | ||
import { isValidElementType } from 'react-is'; | ||
import { decode } from 'sourcemap-codec'; | ||
import transpile, { parseImports } from './transpile'; | ||
const prettierComment = /(\{\s*\/\*\s+prettier-ignore\s+\*\/\s*\})|(\/\/\s+prettier-ignore)/gim; | ||
const hooks = {}; | ||
Object.entries(_react.default).forEach(([key, value]) => { | ||
Object.entries(React).forEach(([key, value]) => { | ||
if (key.startsWith('use')) hooks[key] = value; | ||
}); | ||
export const Context = /*#__PURE__*/React.createContext({}); | ||
const Context = /*#__PURE__*/_react.default.createContext({}); | ||
exports.Context = Context; | ||
const getRequire = imports => function require(request) { | ||
@@ -85,3 +60,3 @@ if (!imports) throw new Error('no imports'); | ||
if (!pos) return err; | ||
const decoded = (0, _sourcemapCodec.decode)((_result$map = result.map) === null || _result$map === void 0 ? void 0 : _result$map.mappings); | ||
const decoded = decode((_result$map = result.map) === null || _result$map === void 0 ? void 0 : _result$map.mappings); | ||
const line = pos.line - offset; | ||
@@ -113,3 +88,3 @@ const mapping = (_decoded$line = decoded[line]) === null || _decoded$line === void 0 ? void 0 : _decoded$line.find(([col]) => col === pos.column); | ||
const result = (0, _transpile.default)(ast || code, { | ||
const result = transpile(ast || code, { | ||
inline: isInline, | ||
@@ -133,3 +108,3 @@ wrapper: renderAsComponent ? wrapAsComponent : undefined | ||
const args = ['React', 'render'].concat(Object.keys(finalScope)); | ||
const values = [_react.default, render].concat(Object.values(finalScope)); | ||
const values = [React, render].concat(Object.values(finalScope)); | ||
let body = result.code; | ||
@@ -155,5 +130,5 @@ if (preample) body = `${preample}\n\n${body}`; // eslint-disable-next-line no-new-func | ||
if (! /*#__PURE__*/(0, _react.isValidElement)(element)) { | ||
if ((0, _reactIs.isValidElementType)(element)) { | ||
element = /*#__PURE__*/(0, _react.createElement)(element); | ||
if (! /*#__PURE__*/isValidElement(element)) { | ||
if (isValidElementType(element)) { | ||
element = /*#__PURE__*/createElement(element); | ||
} else { | ||
@@ -168,26 +143,20 @@ reject(new SyntaxError('The code did not return a valid React element or element type')); | ||
function useLiveContext() { | ||
return (0, _react.useContext)(Context); | ||
export function useLiveContext() { | ||
return useContext(Context); | ||
} | ||
function useElement() { | ||
export function useElement() { | ||
return useLiveContext().element; | ||
} | ||
function useError() { | ||
export function useError() { | ||
return useLiveContext().error; | ||
} | ||
export const objectZip = (arr, arr2) => Object.fromEntries(arr.map((v, i) => [v, arr2[i]])); | ||
const objectZip = (arr, arr2) => Object.fromEntries(arr.map((v, i) => [v, arr2[i]])); | ||
exports.objectZip = objectZip; | ||
function defaultResolveImports(sources) { | ||
return Promise.all(sources.map(s => Promise.resolve(`${ | ||
/* webpackIgnore: true */ | ||
s}`).then(s => _interopRequireWildcard(require(s))))); | ||
// @ts-ignore | ||
return Promise.all(sources.map((s) => import(/* webpackIgnore: true */ s))); | ||
} | ||
function useNormalizedCode(code, showImports, setError) { | ||
return (0, _react.useMemo)(() => { | ||
return useMemo(() => { | ||
const nextCode = code.replace(prettierComment, '').trim(); | ||
@@ -197,3 +166,3 @@ if (showImports) return [nextCode, [], '']; | ||
try { | ||
const result = (0, _transpile.parseImports)(nextCode, true); | ||
const result = parseImports(nextCode, true); | ||
return [result.code, result.imports, result.imports.map(i => i.code).join('\n').trimStart()]; | ||
@@ -212,3 +181,3 @@ } catch (err) { | ||
function Provider({ | ||
export default function Provider({ | ||
scope, | ||
@@ -223,10 +192,10 @@ children, | ||
}) { | ||
const [error, setError] = (0, _react.useState)(null); | ||
const [error, setError] = useState(null); | ||
const [{ | ||
element | ||
}, setState] = (0, _react.useState)({ | ||
}, setState] = useState({ | ||
element: null | ||
}); | ||
const [cleanCode, ogImports, ogImportBlock] = useNormalizedCode(rawCode, showImports, setError); | ||
const handleChange = (0, _useEventCallback.default)(nextCode => { | ||
const handleChange = useEventCallback(nextCode => { | ||
try { | ||
@@ -236,3 +205,3 @@ const { | ||
imports | ||
} = (0, _transpile.parseImports)(nextCode, false); | ||
} = parseImports(nextCode, false); | ||
const sources = Array.from(new Set([...ogImports, ...imports].map(i => i.source))); | ||
@@ -257,6 +226,6 @@ Promise.resolve(resolveImports(sources)).then(results => Array.isArray(results) ? objectZip(sources, results) : results).then(fetchedImports => codeToComponent(nextCode, { | ||
}); | ||
(0, _react.useEffect)(() => { | ||
useEffect(() => { | ||
handleChange(cleanCode); | ||
}, [cleanCode, scope, handleChange]); | ||
const context = (0, _react.useMemo)(() => ({ | ||
const context = useMemo(() => ({ | ||
theme, | ||
@@ -270,5 +239,5 @@ error, | ||
}), [cleanCode, element, error, handleChange, language, theme]); | ||
return /*#__PURE__*/_react.default.createElement(Context.Provider, { | ||
return /*#__PURE__*/React.createElement(Context.Provider, { | ||
value: context | ||
}, children); | ||
} |
@@ -1,9 +0,2 @@ | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
exports.default = createTimers; | ||
function createTimers() { | ||
export default function createTimers() { | ||
let handles = new Map(); | ||
@@ -10,0 +3,0 @@ |
@@ -1,18 +0,6 @@ | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
exports.transform = transform; | ||
var _acorn = require("acorn"); | ||
var _acornJsx = _interopRequireDefault(require("acorn-jsx")); | ||
var _magicString = _interopRequireDefault(require("magic-string")); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
/* eslint-disable no-restricted-syntax */ | ||
const parser = _acorn.Parser.extend((0, _acornJsx.default)()); | ||
import { Parser } from 'acorn'; | ||
import acornJsx from 'acorn-jsx'; | ||
import MagicString from 'magic-string'; | ||
const parser = Parser.extend(acornJsx()); | ||
@@ -86,3 +74,3 @@ const isNode = n => n !== null && typeof n.type === 'string'; | ||
function transform(source, options = { | ||
export function transform(source, options = { | ||
plugins: [] | ||
@@ -97,3 +85,3 @@ }) { | ||
if (typeof source === 'string') { | ||
code = new _magicString.default(source); | ||
code = new MagicString(source); | ||
ast = parser.parse(source, { | ||
@@ -100,0 +88,0 @@ ecmaVersion: 10, |
@@ -1,8 +0,1 @@ | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
exports.default = jsxPlugin; | ||
const hasDashes = val => /-/.test(val); | ||
@@ -27,3 +20,3 @@ | ||
function jsxPlugin(options = {}) { | ||
export default function jsxPlugin(options = {}) { | ||
let pragmaJsx = null; | ||
@@ -30,0 +23,0 @@ let pragmaJsxFrag = null; |
@@ -1,10 +0,3 @@ | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
exports.default = void 0; | ||
/* eslint-disable no-param-reassign */ | ||
var _default = ({ | ||
export default (({ | ||
remove, | ||
@@ -82,4 +75,2 @@ fn: _fn = 'require', | ||
}; | ||
}; | ||
exports.default = _default; | ||
}); |
@@ -1,9 +0,2 @@ | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
exports.default = void 0; | ||
var _default = ({ | ||
export default (({ | ||
wrapper | ||
@@ -19,4 +12,2 @@ }) => ({ | ||
} | ||
}); | ||
exports.default = _default; | ||
})); |
@@ -1,9 +0,2 @@ | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
exports.default = void 0; | ||
var _default = () => ({ | ||
export default (() => ({ | ||
visitor: { | ||
@@ -47,4 +40,2 @@ Program: { | ||
} | ||
}); | ||
exports.default = _default; | ||
})); |
@@ -1,24 +0,10 @@ | ||
"use strict"; | ||
import { transform } from './transform'; | ||
import jsx from './transform/jsx'; | ||
import modules from './transform/modules'; | ||
import wrapContent from './transform/wrapContent'; | ||
import wrapLastExpression from './transform/wrapLastExpression'; | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
exports.parseImports = parseImports; | ||
exports.default = void 0; | ||
var _transform = require("./transform"); | ||
var _jsx = _interopRequireDefault(require("./transform/jsx")); | ||
var _modules = _interopRequireDefault(require("./transform/modules")); | ||
var _wrapContent = _interopRequireDefault(require("./transform/wrapContent")); | ||
var _wrapLastExpression = _interopRequireDefault(require("./transform/wrapLastExpression")); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
const truthy = value => !!value; | ||
function parseImports(input, remove) { | ||
export function parseImports(input, remove) { | ||
const imports = []; | ||
@@ -29,6 +15,6 @@ const { | ||
ast | ||
} = (0, _transform.transform)(input, { | ||
} = transform(input, { | ||
file: 'compiled.js', | ||
source: 'example.js', | ||
plugins: [(0, _modules.default)({ | ||
plugins: [modules({ | ||
remove, | ||
@@ -45,4 +31,3 @@ imports | ||
} | ||
var _default = (input, { | ||
export default ((input, { | ||
inline: _inline = false, | ||
@@ -56,6 +41,6 @@ wrapper | ||
map | ||
} = (0, _transform.transform)(input, { | ||
} = transform(input, { | ||
file: 'compiled.js', | ||
source: 'example.js', | ||
plugins: [(0, _jsx.default)(), (0, _modules.default)(), _inline && (0, _wrapLastExpression.default)(), wrapper && (0, _wrapContent.default)({ | ||
plugins: [jsx(), modules(), _inline && wrapLastExpression(), wrapper && wrapContent({ | ||
wrapper | ||
@@ -70,4 +55,2 @@ })].filter(truthy) | ||
}; | ||
}; | ||
exports.default = _default; | ||
}); |
@@ -1,20 +0,17 @@ | ||
"use strict"; | ||
import { useEffect } from 'react'; | ||
import useCommittedRef from '@restart/hooks/useCommittedRef'; | ||
/** | ||
* Creates a `setInterval` that is properly cleaned up when a component unmounted | ||
* | ||
* @public | ||
* @param fn an function run on each interval | ||
* @param ms The milliseconds duration of the interval | ||
*/ | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
exports.default = void 0; | ||
var _react = require("react"); | ||
var _useCommittedRef = _interopRequireDefault(require("@restart/hooks/useCommittedRef")); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
function useInterval(fn, ms, paused = false, runImmediately = false) { | ||
let handle; | ||
const fnRef = (0, _useCommittedRef.default)(fn); // this ref is necessary b/c useEffect will sometimes miss a paused toggle | ||
const fnRef = useCommittedRef(fn); // this ref is necessary b/c useEffect will sometimes miss a paused toggle | ||
// orphaning a setTimeout chain in the aether, so relying on it's refresh logic is not reliable. | ||
const pausedRef = (0, _useCommittedRef.default)(paused); | ||
const pausedRef = useCommittedRef(paused); | ||
@@ -32,3 +29,3 @@ const tick = () => { | ||
(0, _react.useEffect)(() => { | ||
useEffect(() => { | ||
if (runImmediately) { | ||
@@ -44,3 +41,2 @@ tick(); | ||
var _default = useInterval; | ||
exports.default = _default; | ||
export default useInterval; |
@@ -22,4 +22,2 @@ "use strict"; | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
function _getRequireWildcardCache() { if (typeof WeakMap !== "function") return null; var cache = new WeakMap(); _getRequireWildcardCache = function () { return cache; }; return cache; } | ||
@@ -29,2 +27,4 @@ | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
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; } | ||
@@ -182,5 +182,4 @@ | ||
function defaultResolveImports(sources) { | ||
return Promise.all(sources.map(s => Promise.resolve(`${ | ||
/* webpackIgnore: true */ | ||
s}`).then(s => _interopRequireWildcard(require(s))))); | ||
// @ts-ignore | ||
return Promise.all(sources.map((s) => import(/* webpackIgnore: true */ s))); | ||
} | ||
@@ -187,0 +186,0 @@ |
{ | ||
"name": "jarle", | ||
"version": "1.1.1", | ||
"version": "1.1.2", | ||
"main": "lib/index.js", | ||
@@ -13,3 +13,4 @@ "module": "esm/index.js", | ||
"scripts": { | ||
"build": "4c build src && node ./build-themes.js", | ||
"add-import": "sed -i '' 's/__IMPORT__/(s) => import(\\/\\* webpackIgnore: true \\*\\/ s)/' ./{lib,esm}/Provider.js", | ||
"build": "4c build src && yarn add-import && node ./build-themes.js", | ||
"prepublishOnly": "yarn run build", | ||
@@ -16,0 +17,0 @@ "tdd": "jest --watch", |
Dynamic require
Supply chain riskDynamic require can indicate the package is performing dangerous or unsafe dynamic code execution.
Found 1 instance in 1 package
0
164166
4816