UNPKG

@pnp/spfx-controls-react

Version:

Reusable React controls for SharePoint Framework solutions

59 lines 3.33 kB
"use strict"; /* This file contains reusable functions useful for managing designer functionality */ Object.defineProperty(exports, "__esModule", { value: true }); exports.convertNullToEmptyString = exports.addToolbarChoicePicker = exports.addToolboxSnippet = exports.addToolbarButton = exports.hideToolbarElement = void 0; var sp_core_library_1 = require("@microsoft/sp-core-library"); var adaptivecards_designer_1 = require("adaptivecards-designer"); // Given the instance of a "CardDesigner", it allows you to hide an element of the toolbar given its id. var hideToolbarElement = function (cardDesigner, elementId) { cardDesigner.toolbar.getElementById(elementId).isVisible = false; }; exports.hideToolbarElement = hideToolbarElement; // Given the instance of a "CardDesigner", it allows you to add an element in the toolbar. var addToolbarButton = function (cardDesigner, caption, iconClass, positionElementId, isAfter, hideElementId, onClick) { var id = "__".concat(sp_core_library_1.Guid.newGuid().toString(), "_ToolbarButton"); var newToolbarButton = new adaptivecards_designer_1.ToolbarButton(id, caption, iconClass, onClick); newToolbarButton.separator = true; if (isAfter) cardDesigner.toolbar.insertElementAfter(newToolbarButton, positionElementId); else cardDesigner.toolbar.insertElementBefore(newToolbarButton, positionElementId); if (hideElementId) (0, exports.hideToolbarElement)(cardDesigner, hideElementId); return id; }; exports.addToolbarButton = addToolbarButton; // Given the instance of a "CarDesigner", it allows you to add a snippets to the toolbox. var addToolboxSnippet = function (cardDesigner, category, name, payload) { var newSnippet = new adaptivecards_designer_1.SnippetPaletteItem(category, name); newSnippet.snippet = payload; if (!cardDesigner.customPaletteItems) cardDesigner.customPaletteItems = []; cardDesigner.customPaletteItems.push(newSnippet); }; exports.addToolboxSnippet = addToolboxSnippet; // Given the instance of a "CarDesigner", it allows to add a "Choice Picker" to the toolbar var addToolbarChoicePicker = function (cardDesigner, afterElementId, separator, label, choices, onChanged) { var id = "__".concat(sp_core_library_1.Guid.newGuid().toString(), "_ChoicePicker"); var breakpointsChoicePicker = new adaptivecards_designer_1.ToolbarChoicePicker(id); breakpointsChoicePicker.label = label; breakpointsChoicePicker.choices = choices; breakpointsChoicePicker.onChanged = onChanged; breakpointsChoicePicker.separator = separator; cardDesigner.toolbar.insertElementAfter(breakpointsChoicePicker, afterElementId); return id; }; exports.addToolbarChoicePicker = addToolbarChoicePicker; // Convert nulls to empty strings, used for binding with Adaptive Card Template var convertNullToEmptyString = function (object) { for (var key in object) { if (Object.prototype.hasOwnProperty.call(object, key)) { if (null === object[key] || undefined === object[key]) object[key] = ''; if (typeof object[key] === 'object') (0, exports.convertNullToEmptyString)(object[key]); } } }; exports.convertNullToEmptyString = convertNullToEmptyString; //# sourceMappingURL=AdaptiveCardDesigner.Helpers.js.map