framer
Version:
The Framer library is the code that drives Framer projects and components. It helps you build from simple interactive components to whole apps.
1,357 lines (1,098 loc) • 3.16 MB
JavaScript
(function webpackUniversalModuleDefinition(root, factory) {
if(typeof exports === 'object' && typeof module === 'object')
module.exports = factory(require("react"));
else if(typeof define === 'function' && define.amd)
define(["react"], factory);
else if(typeof exports === 'object')
exports["Framer"] = factory(require("react"));
else
root["Framer"] = factory(root["React"]);
})(window, function(__WEBPACK_EXTERNAL_MODULE_react__) {
return /******/ (function(modules) { // webpackBootstrap
/******/ // The module cache
/******/ var installedModules = {};
/******/
/******/ // The require function
/******/ function __webpack_require__(moduleId) {
/******/
/******/ // Check if module is in cache
/******/ if(installedModules[moduleId]) {
/******/ return installedModules[moduleId].exports;
/******/ }
/******/ // Create a new module (and put it into the cache)
/******/ var module = installedModules[moduleId] = {
/******/ i: moduleId,
/******/ l: false,
/******/ exports: {}
/******/ };
/******/
/******/ // Execute the module function
/******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__);
/******/
/******/ // Flag the module as loaded
/******/ module.l = true;
/******/
/******/ // Return the exports of the module
/******/ return module.exports;
/******/ }
/******/
/******/
/******/ // expose the modules object (__webpack_modules__)
/******/ __webpack_require__.m = modules;
/******/
/******/ // expose the module cache
/******/ __webpack_require__.c = installedModules;
/******/
/******/ // define getter function for harmony exports
/******/ __webpack_require__.d = function(exports, name, getter) {
/******/ if(!__webpack_require__.o(exports, name)) {
/******/ Object.defineProperty(exports, name, { enumerable: true, get: getter });
/******/ }
/******/ };
/******/
/******/ // define __esModule on exports
/******/ __webpack_require__.r = function(exports) {
/******/ if(typeof Symbol !== 'undefined' && Symbol.toStringTag) {
/******/ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
/******/ }
/******/ Object.defineProperty(exports, '__esModule', { value: true });
/******/ };
/******/
/******/ // create a fake namespace object
/******/ // mode & 1: value is a module id, require it
/******/ // mode & 2: merge all properties of value into the ns
/******/ // mode & 4: return value when already ns object
/******/ // mode & 8|1: behave like require
/******/ __webpack_require__.t = function(value, mode) {
/******/ if(mode & 1) value = __webpack_require__(value);
/******/ if(mode & 8) return value;
/******/ if((mode & 4) && typeof value === 'object' && value && value.__esModule) return value;
/******/ var ns = Object.create(null);
/******/ __webpack_require__.r(ns);
/******/ Object.defineProperty(ns, 'default', { enumerable: true, value: value });
/******/ if(mode & 2 && typeof value != 'string') for(var key in value) __webpack_require__.d(ns, key, function(key) { return value[key]; }.bind(null, key));
/******/ return ns;
/******/ };
/******/
/******/ // getDefaultExport function for compatibility with non-harmony modules
/******/ __webpack_require__.n = function(module) {
/******/ var getter = module && module.__esModule ?
/******/ function getDefault() { return module['default']; } :
/******/ function getModuleExports() { return module; };
/******/ __webpack_require__.d(getter, 'a', getter);
/******/ return getter;
/******/ };
/******/
/******/ // Object.prototype.hasOwnProperty.call
/******/ __webpack_require__.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); };
/******/
/******/ // __webpack_public_path__
/******/ __webpack_require__.p = "";
/******/
/******/
/******/ // Load entry module and return exports
/******/ return __webpack_require__(__webpack_require__.s = 0);
/******/ })
/************************************************************************/
/******/ ({
/***/ "../../node_modules/@emotion/is-prop-valid/dist/is-prop-valid.browser.esm.js":
/*!**********************************************************************************************************!*\
!*** /Users/nvh/Code/FramerStudio/node_modules/@emotion/is-prop-valid/dist/is-prop-valid.browser.esm.js ***!
\**********************************************************************************************************/
/*! exports provided: default */
/***/ (function(module, __webpack_exports__, __webpack_require__) {
"use strict";
__webpack_require__.r(__webpack_exports__);
/* harmony import */ var _emotion_memoize__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! @emotion/memoize */ "../../node_modules/@emotion/memoize/dist/memoize.browser.esm.js");
var reactPropsRegex = /^((children|dangerouslySetInnerHTML|key|ref|autoFocus|defaultValue|defaultChecked|innerHTML|suppressContentEditableWarning|suppressHydrationWarning|valueLink|accept|acceptCharset|accessKey|action|allow|allowUserMedia|allowPaymentRequest|allowFullScreen|allowTransparency|alt|async|autoComplete|autoPlay|capture|cellPadding|cellSpacing|challenge|charSet|checked|cite|classID|className|cols|colSpan|content|contentEditable|contextMenu|controls|controlsList|coords|crossOrigin|data|dateTime|decoding|default|defer|dir|disabled|disablePictureInPicture|download|draggable|encType|form|formAction|formEncType|formMethod|formNoValidate|formTarget|frameBorder|headers|height|hidden|high|href|hrefLang|htmlFor|httpEquiv|id|inputMode|integrity|is|keyParams|keyType|kind|label|lang|list|loading|loop|low|marginHeight|marginWidth|max|maxLength|media|mediaGroup|method|min|minLength|multiple|muted|name|nonce|noValidate|open|optimum|pattern|placeholder|playsInline|poster|preload|profile|radioGroup|readOnly|referrerPolicy|rel|required|reversed|role|rows|rowSpan|sandbox|scope|scoped|scrolling|seamless|selected|shape|size|sizes|slot|span|spellCheck|src|srcDoc|srcLang|srcSet|start|step|style|summary|tabIndex|target|title|type|useMap|value|width|wmode|wrap|about|datatype|inlist|prefix|property|resource|typeof|vocab|autoCapitalize|autoCorrect|autoSave|color|inert|itemProp|itemScope|itemType|itemID|itemRef|on|results|security|unselectable|accentHeight|accumulate|additive|alignmentBaseline|allowReorder|alphabetic|amplitude|arabicForm|ascent|attributeName|attributeType|autoReverse|azimuth|baseFrequency|baselineShift|baseProfile|bbox|begin|bias|by|calcMode|capHeight|clip|clipPathUnits|clipPath|clipRule|colorInterpolation|colorInterpolationFilters|colorProfile|colorRendering|contentScriptType|contentStyleType|cursor|cx|cy|d|decelerate|descent|diffuseConstant|direction|display|divisor|dominantBaseline|dur|dx|dy|edgeMode|elevation|enableBackground|end|exponent|externalResourcesRequired|fill|fillOpacity|fillRule|filter|filterRes|filterUnits|floodColor|floodOpacity|focusable|fontFamily|fontSize|fontSizeAdjust|fontStretch|fontStyle|fontVariant|fontWeight|format|from|fr|fx|fy|g1|g2|glyphName|glyphOrientationHorizontal|glyphOrientationVertical|glyphRef|gradientTransform|gradientUnits|hanging|horizAdvX|horizOriginX|ideographic|imageRendering|in|in2|intercept|k|k1|k2|k3|k4|kernelMatrix|kernelUnitLength|kerning|keyPoints|keySplines|keyTimes|lengthAdjust|letterSpacing|lightingColor|limitingConeAngle|local|markerEnd|markerMid|markerStart|markerHeight|markerUnits|markerWidth|mask|maskContentUnits|maskUnits|mathematical|mode|numOctaves|offset|opacity|operator|order|orient|orientation|origin|overflow|overlinePosition|overlineThickness|panose1|paintOrder|pathLength|patternContentUnits|patternTransform|patternUnits|pointerEvents|points|pointsAtX|pointsAtY|pointsAtZ|preserveAlpha|preserveAspectRatio|primitiveUnits|r|radius|refX|refY|renderingIntent|repeatCount|repeatDur|requiredExtensions|requiredFeatures|restart|result|rotate|rx|ry|scale|seed|shapeRendering|slope|spacing|specularConstant|specularExponent|speed|spreadMethod|startOffset|stdDeviation|stemh|stemv|stitchTiles|stopColor|stopOpacity|strikethroughPosition|strikethroughThickness|string|stroke|strokeDasharray|strokeDashoffset|strokeLinecap|strokeLinejoin|strokeMiterlimit|strokeOpacity|strokeWidth|surfaceScale|systemLanguage|tableValues|targetX|targetY|textAnchor|textDecoration|textRendering|textLength|to|transform|u1|u2|underlinePosition|underlineThickness|unicode|unicodeBidi|unicodeRange|unitsPerEm|vAlphabetic|vHanging|vIdeographic|vMathematical|values|vectorEffect|version|vertAdvY|vertOriginX|vertOriginY|viewBox|viewTarget|visibility|widths|wordSpacing|writingMode|x|xHeight|x1|x2|xChannelSelector|xlinkActuate|xlinkArcrole|xlinkHref|xlinkRole|xlinkShow|xlinkTitle|xlinkType|xmlBase|xmlns|xmlnsXlink|xmlLang|xmlSpace|y|y1|y2|yChannelSelector|z|zoomAndPan|for|class|autofocus)|(([Dd][Aa][Tt][Aa]|[Aa][Rr][Ii][Aa]|x)-.*))$/; // https://esbench.com/bench/5bfee68a4cd7e6009ef61d23
var index = Object(_emotion_memoize__WEBPACK_IMPORTED_MODULE_0__["default"])(function (prop) {
return reactPropsRegex.test(prop) || prop.charCodeAt(0) === 111
/* o */
&& prop.charCodeAt(1) === 110
/* n */
&& prop.charCodeAt(2) < 91;
}
/* Z+1 */
);
/* harmony default export */ __webpack_exports__["default"] = (index);
/***/ }),
/***/ "../../node_modules/@emotion/memoize/dist/memoize.browser.esm.js":
/*!**********************************************************************************************!*\
!*** /Users/nvh/Code/FramerStudio/node_modules/@emotion/memoize/dist/memoize.browser.esm.js ***!
\**********************************************************************************************/
/*! exports provided: default */
/***/ (function(module, __webpack_exports__, __webpack_require__) {
"use strict";
__webpack_require__.r(__webpack_exports__);
function memoize(fn) {
var cache = {};
return function (arg) {
if (cache[arg] === undefined) cache[arg] = fn(arg);
return cache[arg];
};
}
/* harmony default export */ __webpack_exports__["default"] = (memoize);
/***/ }),
/***/ "../../node_modules/draft-js/lib/AtomicBlockUtils.js":
/*!**********************************************************************************!*\
!*** /Users/nvh/Code/FramerStudio/node_modules/draft-js/lib/AtomicBlockUtils.js ***!
\**********************************************************************************/
/*! no static exports found */
/***/ (function(module, exports, __webpack_require__) {
"use strict";
/**
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @format
*
* @emails oncall+draft_js
*/
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; var ownKeys = Object.keys(source); if (typeof Object.getOwnPropertySymbols === 'function') { ownKeys = ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function (sym) { return Object.getOwnPropertyDescriptor(source, sym).enumerable; })); } ownKeys.forEach(function (key) { _defineProperty(target, key, source[key]); }); } return target; }
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
var BlockMapBuilder = __webpack_require__(/*! ./BlockMapBuilder */ "../../node_modules/draft-js/lib/BlockMapBuilder.js");
var CharacterMetadata = __webpack_require__(/*! ./CharacterMetadata */ "../../node_modules/draft-js/lib/CharacterMetadata.js");
var ContentBlock = __webpack_require__(/*! ./ContentBlock */ "../../node_modules/draft-js/lib/ContentBlock.js");
var ContentBlockNode = __webpack_require__(/*! ./ContentBlockNode */ "../../node_modules/draft-js/lib/ContentBlockNode.js");
var DraftModifier = __webpack_require__(/*! ./DraftModifier */ "../../node_modules/draft-js/lib/DraftModifier.js");
var EditorState = __webpack_require__(/*! ./EditorState */ "../../node_modules/draft-js/lib/EditorState.js");
var generateRandomKey = __webpack_require__(/*! ./generateRandomKey */ "../../node_modules/draft-js/lib/generateRandomKey.js");
var gkx = __webpack_require__(/*! ./gkx */ "../../node_modules/draft-js/lib/gkx.js");
var Immutable = __webpack_require__(/*! immutable */ "../../node_modules/immutable/dist/immutable.js");
var moveBlockInContentState = __webpack_require__(/*! ./moveBlockInContentState */ "../../node_modules/draft-js/lib/moveBlockInContentState.js");
var experimentalTreeDataSupport = gkx('draft_tree_data_support');
var ContentBlockRecord = experimentalTreeDataSupport ? ContentBlockNode : ContentBlock;
var List = Immutable.List,
Repeat = Immutable.Repeat;
var AtomicBlockUtils = {
insertAtomicBlock: function insertAtomicBlock(editorState, entityKey, character) {
var contentState = editorState.getCurrentContent();
var selectionState = editorState.getSelection();
var afterRemoval = DraftModifier.removeRange(contentState, selectionState, 'backward');
var targetSelection = afterRemoval.getSelectionAfter();
var afterSplit = DraftModifier.splitBlock(afterRemoval, targetSelection);
var insertionTarget = afterSplit.getSelectionAfter();
var asAtomicBlock = DraftModifier.setBlockType(afterSplit, insertionTarget, 'atomic');
var charData = CharacterMetadata.create({
entity: entityKey
});
var atomicBlockConfig = {
key: generateRandomKey(),
type: 'atomic',
text: character,
characterList: List(Repeat(charData, character.length))
};
var atomicDividerBlockConfig = {
key: generateRandomKey(),
type: 'unstyled'
};
if (experimentalTreeDataSupport) {
atomicBlockConfig = _objectSpread({}, atomicBlockConfig, {
nextSibling: atomicDividerBlockConfig.key
});
atomicDividerBlockConfig = _objectSpread({}, atomicDividerBlockConfig, {
prevSibling: atomicBlockConfig.key
});
}
var fragmentArray = [new ContentBlockRecord(atomicBlockConfig), new ContentBlockRecord(atomicDividerBlockConfig)];
var fragment = BlockMapBuilder.createFromArray(fragmentArray);
var withAtomicBlock = DraftModifier.replaceWithFragment(asAtomicBlock, insertionTarget, fragment);
var newContent = withAtomicBlock.merge({
selectionBefore: selectionState,
selectionAfter: withAtomicBlock.getSelectionAfter().set('hasFocus', true)
});
return EditorState.push(editorState, newContent, 'insert-fragment');
},
moveAtomicBlock: function moveAtomicBlock(editorState, atomicBlock, targetRange, insertionMode) {
var contentState = editorState.getCurrentContent();
var selectionState = editorState.getSelection();
var withMovedAtomicBlock;
if (insertionMode === 'before' || insertionMode === 'after') {
var targetBlock = contentState.getBlockForKey(insertionMode === 'before' ? targetRange.getStartKey() : targetRange.getEndKey());
withMovedAtomicBlock = moveBlockInContentState(contentState, atomicBlock, targetBlock, insertionMode);
} else {
var afterRemoval = DraftModifier.removeRange(contentState, targetRange, 'backward');
var selectionAfterRemoval = afterRemoval.getSelectionAfter();
var _targetBlock = afterRemoval.getBlockForKey(selectionAfterRemoval.getFocusKey());
if (selectionAfterRemoval.getStartOffset() === 0) {
withMovedAtomicBlock = moveBlockInContentState(afterRemoval, atomicBlock, _targetBlock, 'before');
} else if (selectionAfterRemoval.getEndOffset() === _targetBlock.getLength()) {
withMovedAtomicBlock = moveBlockInContentState(afterRemoval, atomicBlock, _targetBlock, 'after');
} else {
var afterSplit = DraftModifier.splitBlock(afterRemoval, selectionAfterRemoval);
var selectionAfterSplit = afterSplit.getSelectionAfter();
var _targetBlock2 = afterSplit.getBlockForKey(selectionAfterSplit.getFocusKey());
withMovedAtomicBlock = moveBlockInContentState(afterSplit, atomicBlock, _targetBlock2, 'before');
}
}
var newContent = withMovedAtomicBlock.merge({
selectionBefore: selectionState,
selectionAfter: withMovedAtomicBlock.getSelectionAfter().set('hasFocus', true)
});
return EditorState.push(editorState, newContent, 'move-block');
}
};
module.exports = AtomicBlockUtils;
/***/ }),
/***/ "../../node_modules/draft-js/lib/BlockMapBuilder.js":
/*!*********************************************************************************!*\
!*** /Users/nvh/Code/FramerStudio/node_modules/draft-js/lib/BlockMapBuilder.js ***!
\*********************************************************************************/
/*! no static exports found */
/***/ (function(module, exports, __webpack_require__) {
"use strict";
/**
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @format
*
* @emails oncall+draft_js
*/
var Immutable = __webpack_require__(/*! immutable */ "../../node_modules/immutable/dist/immutable.js");
var OrderedMap = Immutable.OrderedMap;
var BlockMapBuilder = {
createFromArray: function createFromArray(blocks) {
return OrderedMap(blocks.map(function (block) {
return [block.getKey(), block];
}));
}
};
module.exports = BlockMapBuilder;
/***/ }),
/***/ "../../node_modules/draft-js/lib/BlockTree.js":
/*!***************************************************************************!*\
!*** /Users/nvh/Code/FramerStudio/node_modules/draft-js/lib/BlockTree.js ***!
\***************************************************************************/
/*! no static exports found */
/***/ (function(module, exports, __webpack_require__) {
"use strict";
/**
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @format
*
* @emails oncall+draft_js
*/
var findRangesImmutable = __webpack_require__(/*! ./findRangesImmutable */ "../../node_modules/draft-js/lib/findRangesImmutable.js");
var Immutable = __webpack_require__(/*! immutable */ "../../node_modules/immutable/dist/immutable.js");
var List = Immutable.List,
Repeat = Immutable.Repeat,
Record = Immutable.Record;
var returnTrue = function returnTrue() {
return true;
};
var defaultLeafRange = {
start: null,
end: null
};
var LeafRange = Record(defaultLeafRange);
var defaultDecoratorRange = {
start: null,
end: null,
decoratorKey: null,
leaves: null
};
var DecoratorRange = Record(defaultDecoratorRange);
var BlockTree = {
/**
* Generate a block tree for a given ContentBlock/decorator pair.
*/
generate: function generate(contentState, block, decorator) {
var textLength = block.getLength();
if (!textLength) {
return List.of(new DecoratorRange({
start: 0,
end: 0,
decoratorKey: null,
leaves: List.of(new LeafRange({
start: 0,
end: 0
}))
}));
}
var leafSets = [];
var decorations = decorator ? decorator.getDecorations(block, contentState) : List(Repeat(null, textLength));
var chars = block.getCharacterList();
findRangesImmutable(decorations, areEqual, returnTrue, function (start, end) {
leafSets.push(new DecoratorRange({
start: start,
end: end,
decoratorKey: decorations.get(start),
leaves: generateLeaves(chars.slice(start, end).toList(), start)
}));
});
return List(leafSets);
}
};
/**
* Generate LeafRange records for a given character list.
*/
function generateLeaves(characters, offset) {
var leaves = [];
var inlineStyles = characters.map(function (c) {
return c.getStyle();
}).toList();
findRangesImmutable(inlineStyles, areEqual, returnTrue, function (start, end) {
leaves.push(new LeafRange({
start: start + offset,
end: end + offset
}));
});
return List(leaves);
}
function areEqual(a, b) {
return a === b;
}
module.exports = BlockTree;
/***/ }),
/***/ "../../node_modules/draft-js/lib/CharacterMetadata.js":
/*!***********************************************************************************!*\
!*** /Users/nvh/Code/FramerStudio/node_modules/draft-js/lib/CharacterMetadata.js ***!
\***********************************************************************************/
/*! no static exports found */
/***/ (function(module, exports, __webpack_require__) {
"use strict";
/**
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @format
*
* @emails oncall+draft_js
*/
function _inheritsLoose(subClass, superClass) { subClass.prototype = Object.create(superClass.prototype); subClass.prototype.constructor = subClass; subClass.__proto__ = superClass; }
var _require = __webpack_require__(/*! immutable */ "../../node_modules/immutable/dist/immutable.js"),
Map = _require.Map,
OrderedSet = _require.OrderedSet,
Record = _require.Record; // Immutable.map is typed such that the value for every key in the map
// must be the same type
var EMPTY_SET = OrderedSet();
var defaultRecord = {
style: EMPTY_SET,
entity: null
};
var CharacterMetadataRecord = Record(defaultRecord);
var CharacterMetadata =
/*#__PURE__*/
function (_CharacterMetadataRec) {
_inheritsLoose(CharacterMetadata, _CharacterMetadataRec);
function CharacterMetadata() {
return _CharacterMetadataRec.apply(this, arguments) || this;
}
var _proto = CharacterMetadata.prototype;
_proto.getStyle = function getStyle() {
return this.get('style');
};
_proto.getEntity = function getEntity() {
return this.get('entity');
};
_proto.hasStyle = function hasStyle(style) {
return this.getStyle().includes(style);
};
CharacterMetadata.applyStyle = function applyStyle(record, style) {
var withStyle = record.set('style', record.getStyle().add(style));
return CharacterMetadata.create(withStyle);
};
CharacterMetadata.removeStyle = function removeStyle(record, style) {
var withoutStyle = record.set('style', record.getStyle().remove(style));
return CharacterMetadata.create(withoutStyle);
};
CharacterMetadata.applyEntity = function applyEntity(record, entityKey) {
var withEntity = record.getEntity() === entityKey ? record : record.set('entity', entityKey);
return CharacterMetadata.create(withEntity);
}
/**
* Use this function instead of the `CharacterMetadata` constructor.
* Since most content generally uses only a very small number of
* style/entity permutations, we can reuse these objects as often as
* possible.
*/
;
CharacterMetadata.create = function create(config) {
if (!config) {
return EMPTY;
}
var defaultConfig = {
style: EMPTY_SET,
entity: null
}; // Fill in unspecified properties, if necessary.
var configMap = Map(defaultConfig).merge(config);
var existing = pool.get(configMap);
if (existing) {
return existing;
}
var newCharacter = new CharacterMetadata(configMap);
pool = pool.set(configMap, newCharacter);
return newCharacter;
};
return CharacterMetadata;
}(CharacterMetadataRecord);
var EMPTY = new CharacterMetadata();
var pool = Map([[Map(defaultRecord), EMPTY]]);
CharacterMetadata.EMPTY = EMPTY;
module.exports = CharacterMetadata;
/***/ }),
/***/ "../../node_modules/draft-js/lib/CompositeDraftDecorator.js":
/*!*****************************************************************************************!*\
!*** /Users/nvh/Code/FramerStudio/node_modules/draft-js/lib/CompositeDraftDecorator.js ***!
\*****************************************************************************************/
/*! no static exports found */
/***/ (function(module, exports, __webpack_require__) {
"use strict";
/**
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @format
*
* @emails oncall+draft_js
*/
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
var Immutable = __webpack_require__(/*! immutable */ "../../node_modules/immutable/dist/immutable.js");
var List = Immutable.List;
var DELIMITER = '.';
/**
* A CompositeDraftDecorator traverses through a list of DraftDecorator
* instances to identify sections of a ContentBlock that should be rendered
* in a "decorated" manner. For example, hashtags, mentions, and links may
* be intended to stand out visually, be rendered as anchors, etc.
*
* The list of decorators supplied to the constructor will be used in the
* order they are provided. This allows the caller to specify a priority for
* string matching, in case of match collisions among decorators.
*
* For instance, I may have a link with a `#` in its text. Though this section
* of text may match our hashtag decorator, it should not be treated as a
* hashtag. I should therefore list my link DraftDecorator
* before my hashtag DraftDecorator when constructing this composite
* decorator instance.
*
* Thus, when a collision like this is encountered, the earlier match is
* preserved and the new match is discarded.
*/
var CompositeDraftDecorator =
/*#__PURE__*/
function () {
function CompositeDraftDecorator(decorators) {
_defineProperty(this, "_decorators", void 0);
// Copy the decorator array, since we use this array order to determine
// precedence of decoration matching. If the array is mutated externally,
// we don't want to be affected here.
this._decorators = decorators.slice();
}
var _proto = CompositeDraftDecorator.prototype;
_proto.getDecorations = function getDecorations(block, contentState) {
var decorations = Array(block.getText().length).fill(null);
this._decorators.forEach(function (
/*object*/
decorator,
/*number*/
ii) {
var counter = 0;
var strategy = decorator.strategy;
var callback = function callback(
/*number*/
start,
/*number*/
end) {
// Find out if any of our matching range is already occupied
// by another decorator. If so, discard the match. Otherwise, store
// the component key for rendering.
if (canOccupySlice(decorations, start, end)) {
occupySlice(decorations, start, end, ii + DELIMITER + counter);
counter++;
}
};
strategy(block, callback, contentState);
});
return List(decorations);
};
_proto.getComponentForKey = function getComponentForKey(key) {
var componentKey = parseInt(key.split(DELIMITER)[0], 10);
return this._decorators[componentKey].component;
};
_proto.getPropsForKey = function getPropsForKey(key) {
var componentKey = parseInt(key.split(DELIMITER)[0], 10);
return this._decorators[componentKey].props;
};
return CompositeDraftDecorator;
}();
/**
* Determine whether we can occupy the specified slice of the decorations
* array.
*/
function canOccupySlice(decorations, start, end) {
for (var ii = start; ii < end; ii++) {
if (decorations[ii] != null) {
return false;
}
}
return true;
}
/**
* Splice the specified component into our decoration array at the desired
* range.
*/
function occupySlice(targetArr, start, end, componentKey) {
for (var ii = start; ii < end; ii++) {
targetArr[ii] = componentKey;
}
}
module.exports = CompositeDraftDecorator;
/***/ }),
/***/ "../../node_modules/draft-js/lib/ContentBlock.js":
/*!******************************************************************************!*\
!*** /Users/nvh/Code/FramerStudio/node_modules/draft-js/lib/ContentBlock.js ***!
\******************************************************************************/
/*! no static exports found */
/***/ (function(module, exports, __webpack_require__) {
"use strict";
/**
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @format
*
* @emails oncall+draft_js
*/
function _inheritsLoose(subClass, superClass) { subClass.prototype = Object.create(superClass.prototype); subClass.prototype.constructor = subClass; subClass.__proto__ = superClass; }
var CharacterMetadata = __webpack_require__(/*! ./CharacterMetadata */ "../../node_modules/draft-js/lib/CharacterMetadata.js");
var findRangesImmutable = __webpack_require__(/*! ./findRangesImmutable */ "../../node_modules/draft-js/lib/findRangesImmutable.js");
var Immutable = __webpack_require__(/*! immutable */ "../../node_modules/immutable/dist/immutable.js");
var List = Immutable.List,
Map = Immutable.Map,
OrderedSet = Immutable.OrderedSet,
Record = Immutable.Record,
Repeat = Immutable.Repeat;
var EMPTY_SET = OrderedSet();
var defaultRecord = {
key: '',
type: 'unstyled',
text: '',
characterList: List(),
depth: 0,
data: Map()
};
var ContentBlockRecord = Record(defaultRecord);
var decorateCharacterList = function decorateCharacterList(config) {
if (!config) {
return config;
}
var characterList = config.characterList,
text = config.text;
if (text && !characterList) {
config.characterList = List(Repeat(CharacterMetadata.EMPTY, text.length));
}
return config;
};
var ContentBlock =
/*#__PURE__*/
function (_ContentBlockRecord) {
_inheritsLoose(ContentBlock, _ContentBlockRecord);
function ContentBlock(config) {
return _ContentBlockRecord.call(this, decorateCharacterList(config)) || this;
}
var _proto = ContentBlock.prototype;
_proto.getKey = function getKey() {
return this.get('key');
};
_proto.getType = function getType() {
return this.get('type');
};
_proto.getText = function getText() {
return this.get('text');
};
_proto.getCharacterList = function getCharacterList() {
return this.get('characterList');
};
_proto.getLength = function getLength() {
return this.getText().length;
};
_proto.getDepth = function getDepth() {
return this.get('depth');
};
_proto.getData = function getData() {
return this.get('data');
};
_proto.getInlineStyleAt = function getInlineStyleAt(offset) {
var character = this.getCharacterList().get(offset);
return character ? character.getStyle() : EMPTY_SET;
};
_proto.getEntityAt = function getEntityAt(offset) {
var character = this.getCharacterList().get(offset);
return character ? character.getEntity() : null;
}
/**
* Execute a callback for every contiguous range of styles within the block.
*/
;
_proto.findStyleRanges = function findStyleRanges(filterFn, callback) {
findRangesImmutable(this.getCharacterList(), haveEqualStyle, filterFn, callback);
}
/**
* Execute a callback for every contiguous range of entities within the block.
*/
;
_proto.findEntityRanges = function findEntityRanges(filterFn, callback) {
findRangesImmutable(this.getCharacterList(), haveEqualEntity, filterFn, callback);
};
return ContentBlock;
}(ContentBlockRecord);
function haveEqualStyle(charA, charB) {
return charA.getStyle() === charB.getStyle();
}
function haveEqualEntity(charA, charB) {
return charA.getEntity() === charB.getEntity();
}
module.exports = ContentBlock;
/***/ }),
/***/ "../../node_modules/draft-js/lib/ContentBlockNode.js":
/*!**********************************************************************************!*\
!*** /Users/nvh/Code/FramerStudio/node_modules/draft-js/lib/ContentBlockNode.js ***!
\**********************************************************************************/
/*! no static exports found */
/***/ (function(module, exports, __webpack_require__) {
"use strict";
/**
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @format
*
* @emails oncall+draft_js
*
* This file is a fork of ContentBlock adding support for nesting references by
* providing links to children, parent, prevSibling, and nextSibling.
*
* This is unstable and not part of the public API and should not be used by
* production systems. This file may be update/removed without notice.
*/
function _inheritsLoose(subClass, superClass) { subClass.prototype = Object.create(superClass.prototype); subClass.prototype.constructor = subClass; subClass.__proto__ = superClass; }
var CharacterMetadata = __webpack_require__(/*! ./CharacterMetadata */ "../../node_modules/draft-js/lib/CharacterMetadata.js");
var findRangesImmutable = __webpack_require__(/*! ./findRangesImmutable */ "../../node_modules/draft-js/lib/findRangesImmutable.js");
var Immutable = __webpack_require__(/*! immutable */ "../../node_modules/immutable/dist/immutable.js");
var List = Immutable.List,
Map = Immutable.Map,
OrderedSet = Immutable.OrderedSet,
Record = Immutable.Record,
Repeat = Immutable.Repeat;
var EMPTY_SET = OrderedSet();
var defaultRecord = {
parent: null,
characterList: List(),
data: Map(),
depth: 0,
key: '',
text: '',
type: 'unstyled',
children: List(),
prevSibling: null,
nextSibling: null
};
var haveEqualStyle = function haveEqualStyle(charA, charB) {
return charA.getStyle() === charB.getStyle();
};
var haveEqualEntity = function haveEqualEntity(charA, charB) {
return charA.getEntity() === charB.getEntity();
};
var decorateCharacterList = function decorateCharacterList(config) {
if (!config) {
return config;
}
var characterList = config.characterList,
text = config.text;
if (text && !characterList) {
config.characterList = List(Repeat(CharacterMetadata.EMPTY, text.length));
}
return config;
};
var ContentBlockNode =
/*#__PURE__*/
function (_ref) {
_inheritsLoose(ContentBlockNode, _ref);
function ContentBlockNode() {
var props = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : defaultRecord;
/* eslint-disable-next-line constructor-super */
return _ref.call(this, decorateCharacterList(props)) || this;
}
var _proto = ContentBlockNode.prototype;
_proto.getKey = function getKey() {
return this.get('key');
};
_proto.getType = function getType() {
return this.get('type');
};
_proto.getText = function getText() {
return this.get('text');
};
_proto.getCharacterList = function getCharacterList() {
return this.get('characterList');
};
_proto.getLength = function getLength() {
return this.getText().length;
};
_proto.getDepth = function getDepth() {
return this.get('depth');
};
_proto.getData = function getData() {
return this.get('data');
};
_proto.getInlineStyleAt = function getInlineStyleAt(offset) {
var character = this.getCharacterList().get(offset);
return character ? character.getStyle() : EMPTY_SET;
};
_proto.getEntityAt = function getEntityAt(offset) {
var character = this.getCharacterList().get(offset);
return character ? character.getEntity() : null;
};
_proto.getChildKeys = function getChildKeys() {
return this.get('children');
};
_proto.getParentKey = function getParentKey() {
return this.get('parent');
};
_proto.getPrevSiblingKey = function getPrevSiblingKey() {
return this.get('prevSibling');
};
_proto.getNextSiblingKey = function getNextSiblingKey() {
return this.get('nextSibling');
};
_proto.findStyleRanges = function findStyleRanges(filterFn, callback) {
findRangesImmutable(this.getCharacterList(), haveEqualStyle, filterFn, callback);
};
_proto.findEntityRanges = function findEntityRanges(filterFn, callback) {
findRangesImmutable(this.getCharacterList(), haveEqualEntity, filterFn, callback);
};
return ContentBlockNode;
}(Record(defaultRecord));
module.exports = ContentBlockNode;
/***/ }),
/***/ "../../node_modules/draft-js/lib/ContentState.js":
/*!******************************************************************************!*\
!*** /Users/nvh/Code/FramerStudio/node_modules/draft-js/lib/ContentState.js ***!
\******************************************************************************/
/*! no static exports found */
/***/ (function(module, exports, __webpack_require__) {
"use strict";
/**
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @format
*
* @emails oncall+draft_js
*/
function _inheritsLoose(subClass, superClass) { subClass.prototype = Object.create(superClass.prototype); subClass.prototype.constructor = subClass; subClass.__proto__ = superClass; }
var BlockMapBuilder = __webpack_require__(/*! ./BlockMapBuilder */ "../../node_modules/draft-js/lib/BlockMapBuilder.js");
var CharacterMetadata = __webpack_require__(/*! ./CharacterMetadata */ "../../node_modules/draft-js/lib/CharacterMetadata.js");
var ContentBlock = __webpack_require__(/*! ./ContentBlock */ "../../node_modules/draft-js/lib/ContentBlock.js");
var ContentBlockNode = __webpack_require__(/*! ./ContentBlockNode */ "../../node_modules/draft-js/lib/ContentBlockNode.js");
var DraftEntity = __webpack_require__(/*! ./DraftEntity */ "../../node_modules/draft-js/lib/DraftEntity.js");
var SelectionState = __webpack_require__(/*! ./SelectionState */ "../../node_modules/draft-js/lib/SelectionState.js");
var generateRandomKey = __webpack_require__(/*! ./generateRandomKey */ "../../node_modules/draft-js/lib/generateRandomKey.js");
var gkx = __webpack_require__(/*! ./gkx */ "../../node_modules/draft-js/lib/gkx.js");
var Immutable = __webpack_require__(/*! immutable */ "../../node_modules/immutable/dist/immutable.js");
var sanitizeDraftText = __webpack_require__(/*! ./sanitizeDraftText */ "../../node_modules/draft-js/lib/sanitizeDraftText.js");
var List = Immutable.List,
Record = Immutable.Record,
Repeat = Immutable.Repeat;
var defaultRecord = {
entityMap: null,
blockMap: null,
selectionBefore: null,
selectionAfter: null
};
var ContentStateRecord = Record(defaultRecord);
var ContentState =
/*#__PURE__*/
function (_ContentStateRecord) {
_inheritsLoose(ContentState, _ContentStateRecord);
function ContentState() {
return _ContentStateRecord.apply(this, arguments) || this;
}
var _proto = ContentState.prototype;
_proto.getEntityMap = function getEntityMap() {
// TODO: update this when we fully remove DraftEntity
return DraftEntity;
};
_proto.getBlockMap = function getBlockMap() {
return this.get('blockMap');
};
_proto.getSelectionBefore = function getSelectionBefore() {
return this.get('selectionBefore');
};
_proto.getSelectionAfter = function getSelectionAfter() {
return this.get('selectionAfter');
};
_proto.getBlockForKey = function getBlockForKey(key) {
var block = this.getBlockMap().get(key);
return block;
};
_proto.getKeyBefore = function getKeyBefore(key) {
return this.getBlockMap().reverse().keySeq().skipUntil(function (v) {
return v === key;
}).skip(1).first();
};
_proto.getKeyAfter = function getKeyAfter(key) {
return this.getBlockMap().keySeq().skipUntil(function (v) {
return v === key;
}).skip(1).first();
};
_proto.getBlockAfter = function getBlockAfter(key) {
return this.getBlockMap().skipUntil(function (_, k) {
return k === key;
}).skip(1).first();
};
_proto.getBlockBefore = function getBlockBefore(key) {
return this.getBlockMap().reverse().skipUntil(function (_, k) {
return k === key;
}).skip(1).first();
};
_proto.getBlocksAsArray = function getBlocksAsArray() {
return this.getBlockMap().toArray();
};
_proto.getFirstBlock = function getFirstBlock() {
return this.getBlockMap().first();
};
_proto.getLastBlock = function getLastBlock() {
return this.getBlockMap().last();
};
_proto.getPlainText = function getPlainText(delimiter) {
return this.getBlockMap().map(function (block) {
return block ? block.getText() : '';
}).join(delimiter || '\n');
};
_proto.getLastCreatedEntityKey = function getLastCreatedEntityKey() {
// TODO: update this when we fully remove DraftEntity
return DraftEntity.__getLastCreatedEntityKey();
};
_proto.hasText = function hasText() {
var blockMap = this.getBlockMap();
return blockMap.size > 1 || // make sure that there are no zero width space chars
escape(blockMap.first().getText()).replace(/%u200B/g, '').length > 0;
};
_proto.createEntity = function createEntity(type, mutability, data) {
// TODO: update this when we fully remove DraftEntity
DraftEntity.__create(type, mutability, data);
return this;
};
_proto.mergeEntityData = function mergeEntityData(key, toMerge) {
// TODO: update this when we fully remove DraftEntity
DraftEntity.__mergeData(key, toMerge);
return this;
};
_proto.replaceEntityData = function replaceEntityData(key, newData) {
// TODO: update this when we fully remove DraftEntity
DraftEntity.__replaceData(key, newData);
return this;
};
_proto.addEntity = function addEntity(instance) {
// TODO: update this when we fully remove DraftEntity
DraftEntity.__add(instance);
return this;
};
_proto.getEntity = function getEntity(key) {
// TODO: update this when we fully remove DraftEntity
return DraftEntity.__get(key);
};
ContentState.createFromBlockArray = function createFromBlockArray( // TODO: update flow type when we completely deprecate the old entity API
blocks, entityMap) {
// TODO: remove this when we completely deprecate the old entity API
var theBlocks = Array.isArray(blocks) ? blocks : blocks.contentBlocks;
var blockMap = BlockMapBuilder.createFromArray(theBlocks);
var selectionState = blockMap.isEmpty() ? new SelectionState() : SelectionState.createEmpty(blockMap.first().getKey());
return new ContentState({
blockMap: blockMap,
entityMap: entityMap || DraftEntity,
selectionBefore: selectionState,
selectionAfter: selectionState
});
};
ContentState.createFromText = function createFromText(text) {
var delimiter = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : /\r\n?|\n/g;
var strings = text.split(delimiter);
var blocks = strings.map(function (block) {
block = sanitizeDraftText(block);
var ContentBlockNodeRecord = gkx('draft_tree_data_support') ? ContentBlockNode : ContentBlock;
return new ContentBlockNodeRecord({
key: generateRandomKey(),
text: block,
type: 'unstyled',
characterList: List(Repeat(CharacterMetadata.EMPTY, block.length))
});
});
return ContentState.createFromBlockArray(blocks);
};
return ContentState;
}(ContentStateRecord);
module.exports = ContentState;
/***/ }),
/***/ "../../node_modules/draft-js/lib/ContentStateInlineStyle.js":
/*!*****************************************************************************************!*\
!*** /Users/nvh/Code/FramerStudio/node_modules/draft-js/lib/ContentStateInlineStyle.js ***!
\*****************************************************************************************/
/*! no static exports found */
/***/ (function(module, exports, __webpack_require__) {
"use strict";
/**
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @format
*
* @emails oncall+draft_js
*/
var CharacterMetadata = __webpack_require__(/*! ./CharacterMetadata */ "../../node_modules/draft-js/lib/CharacterMetadata.js");
var _require = __webpack_require__(/*! immutable */ "../../node_modules/immutable/dist/immutable.js"),
Map = _require.Map;
var ContentStateInlineStyle = {
add: function add(contentState, selectionState, inlineStyle) {
return modifyInlineStyle(contentState, selectionState, inlineStyle, true);
},
remove: function remove(contentState, selectionState, inlineStyle) {
return modifyInlineStyle(contentState, selectionState, inlineStyle, false);
}
};
function modifyInlineStyle(contentState, selectionState, inlineStyle, addOrRemove) {
var blockMap = contentState.getBlockMap();
var startKey = selectionState.getStartKey();
var startOffset = selectionState.getStartOffset();
var endKey = selectionState.getEndKey();
var endOffset = selectionState.getEndOffset();
var newBlocks = blockMap.skipUntil(function (_, k) {
return k === startKey;
}).takeUntil(function (_, k) {
return k === endKey;
}).concat(Map([[endKey, blockMap.get(endKey)]])).map(function (block, blockKey) {
var sliceStart;
var sliceEnd;
if (startKey === endKey) {
sliceStart = startOffset;
sliceEnd = endOffset;
} else {
sliceStart = blockKey === startKey ? startOffset : 0;
sliceEnd = blockKey === endKey ? endOffset : block.getLength();
}
var chars = block.getCharacterList();
var current;
while (sliceStart < sliceEnd) {
current = chars.get(sliceStart);
chars = chars.set(sliceStart, addOrRemove ? CharacterMetadata.applyStyle(current, inlineStyle) : CharacterMetadata.removeStyle(current, inlineStyle));
sliceStart++;
}
return block.set('characterList', chars);
});
return contentState.merge({
blockMap: blockMap.merge(newBlocks),
selectionBefore: selectionState,
selectionAfter: selectionState
});
}
module.exports = ContentStateInlineStyle;
/***/ }),
/***/ "../../node_modules/draft-js/lib/DOMObserver.js":
/*!*****************************************************************************!*\
!*** /Users/nvh/Code/FramerStudio/node_modules/draft-js/lib/DOMObserver.js ***!
\*****************************************************************************/
/*! no static exports found */
/***/ (function(module, exports, __webpack_require__) {
"use strict";
/**
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @format
*
* @emails oncall+draft_js
*/
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
var UserAgent = __webpack_require__(/*! fbjs/lib/UserAgent */ "../../node_modules/fbjs/lib/UserAgent.js");
var findAncestorOffsetKey = __webpack_require__(/*! ./findAncestorOffsetKey */ "../../node_modules/draft-js/lib/findAncestorOffsetKey.js");
var getWindowForNode = __webpack_require__(/*! ./getWindowForNode */ "../../node_modules/draft-js/lib/getWindowForNode.js");
var Immutable = __webpack_require__(/*! immutable */ "../../node_modules/immutable/dist/immutable.js");
var invariant = __webpack_require__(/*! fbjs/lib/invariant */ "../../node_modules/fbjs/lib/invariant.js");
var nullthrows = __webpack_require__(/*! fbjs/lib/nullthrows */ "../../node_modules/fbjs/lib/nullthrows.js");
var Map = Immutable.Map;
// Heavily based on Prosemirror's DOMObserver https://github.com/ProseMirror/prosemirror-view/blob/master/src/domobserver.js
var DOM_OBSERVER_OPTIONS = {
subtree: true,
characterData: true,
childList: true,
characterDataOldValue: false,
attributes: false
}; // IE11 has very broken mutation observers, so we also listen to DOMCharacterDataModified
var USE_CHAR_DATA = UserAgent.isBrowser('IE <= 11');
var DOMObserver =
/*#__PURE__*/
function () {
function DOMObserver(container) {
var _this = this;
_defineProperty(this, "observer", void 0);
_defineProperty(this, "container", void 0);
_defineProperty(this, "mutations", void 0);
_defineProperty(this, "onCharData", void 0);
this.container = container;
this.mutations = Map();
var containerWindow = getWindowForNode(container);
if (containerWindow.MutationObserver && !USE_CHAR_DATA) {
this.observer = new containerWindow.MutationObserver(function (mutations) {
return _this.registerMutations(mutations);
});
} else {
this.onCharData = function (e) {
!(e.target instanceof Node) ? true ? invariant(false, 'Expected target to be an instance of Node') : undefined : void 0;
_this.registerMutation({
type: 'characterData',
target: e.target
});
};
}
}
var _proto = DOMObserver.prototype;
_proto.start = function start() {
if (this.observer) {
this.observer.observe(this.container, DOM_OBSERVER_OPTIONS);
} else {
/* $FlowFixMe(>=0.68.0 site=www,mobile) This event type is not defined
* by Flow's standard library */
this.container.addEventListener('DOMCharacterDataModified', this.onCharData);
}
};
_proto.stopAndFlushMutations = function stopAndFlushMutations() {
var observer = this.observer;
if (observer) {
this.registerMutations(observer.takeRecords());
observer.disconnect();
} else {
/* $FlowFixMe(>=0.68.0 site=www,mobile) This event type is not defined
* by Flow's standard library */
this.container.removeEventListener('DOMCharacterDataModified', this.onCharData);
}
var mutations = this.mutations;
this.mutations = Map();
return mutations;
};
_proto.registerMutations = function registerMutations(mutations) {
for (var i = 0; i < mutations.length; i++)