MCPcopy Create free account
hub / github.com/microsoft/SandDance / customizable

Function customizable

docs/app/js/sanddance-app.js:24365–24414  ·  view source on GitHub ↗
(scope, fields, concatStyles)

Source from the content-addressed store, hash-verified

24363var _customizerContext = require("./CustomizerContext");
24364var _mergeStyles = require("@uifabric/merge-styles");
24365function customizable(scope, fields, concatStyles) {
24366 // eslint-disable-next-line @typescript-eslint/no-explicit-any
24367 return function customizableFactory(ComposedComponent) {
24368 var _a;
24369 var resultClass = (_a = /** @class */ function(_super) {
24370 (0, _tslib.__extends)(ComponentWithInjectedProps, _super);
24371 function ComponentWithInjectedProps(props) {
24372 var _this = _super.call(this, props) || this;
24373 // eslint-disable-next-line @typescript-eslint/no-explicit-any
24374 _this._styleCache = {};
24375 _this._onSettingChanged = _this._onSettingChanged.bind(_this);
24376 return _this;
24377 }
24378 ComponentWithInjectedProps.prototype.componentDidMount = function() {
24379 (0, _customizations.Customizations).observe(this._onSettingChanged);
24380 };
24381 ComponentWithInjectedProps.prototype.componentWillUnmount = function() {
24382 (0, _customizations.Customizations).unobserve(this._onSettingChanged);
24383 };
24384 ComponentWithInjectedProps.prototype.render = function() {
24385 var _this = this;
24386 return _react.createElement((0, _customizerContext.CustomizerContext).Consumer, null, function(context) {
24387 var defaultProps = (0, _customizations.Customizations).getSettings(fields, scope, context.customizations);
24388 // eslint-disable-next-line @typescript-eslint/no-explicit-any
24389 var componentProps = _this.props;
24390 // If defaultProps.styles is a function, evaluate it before calling concatStyleSets
24391 if (defaultProps.styles && typeof defaultProps.styles === "function") defaultProps.styles = defaultProps.styles((0, _tslib.__assign)((0, _tslib.__assign)({}, defaultProps), componentProps));
24392 // If concatStyles is true and custom styles have been defined compute those styles
24393 if (concatStyles && defaultProps.styles) {
24394 if (_this._styleCache.default !== defaultProps.styles || _this._styleCache.component !== componentProps.styles) {
24395 var mergedStyles = (0, _mergeStyles.concatStyleSets)(defaultProps.styles, componentProps.styles);
24396 _this._styleCache.default = defaultProps.styles;
24397 _this._styleCache.component = componentProps.styles;
24398 _this._styleCache.merged = mergedStyles;
24399 }
24400 return _react.createElement(ComposedComponent, (0, _tslib.__assign)({}, defaultProps, componentProps, {
24401 styles: _this._styleCache.merged
24402 }));
24403 }
24404 return _react.createElement(ComposedComponent, (0, _tslib.__assign)({}, defaultProps, componentProps));
24405 });
24406 };
24407 ComponentWithInjectedProps.prototype._onSettingChanged = function() {
24408 this.forceUpdate();
24409 };
24410 return ComponentWithInjectedProps;
24411 }(_react.Component), _a.displayName = "Customized" + scope, _a);
24412 return (0, _hoistStatics.hoistStatics)(ComposedComponent, resultClass);
24413 };
24414}
24415
24416},{"tslib":"01Tx1","react":"8ePka","./Customizations":"cQrva","../hoistStatics":"eOXQy","./CustomizerContext":"lvXOl","@uifabric/merge-styles":"7c43M","@parcel/transformer-js/src/esmodule-helpers.js":"jA2du"}],"eOXQy":[function(require,module,exports) {
24417var parcelHelpers = require("@parcel/transformer-js/src/esmodule-helpers.js");

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected