survey-creator-core
Version:
A framework-independent core package of the SurveyJS Survey Creator component. With Survey Creator, you can visually design complex, interactive JSON forms and surveys in a drag-and-drop interface.
918 lines (905 loc) • 263 kB
JavaScript
/*!
* SurveyJS Creator v2.5.21
* (c) 2015-2026 Devsoft Baltic OÜ - http://surveyjs.io/
* Github: https://github.com/surveyjs/survey-creator
* License: https://surveyjs.io/Licenses#SurveyCreator
*/
(function (global, factory) {
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('survey-core'), require('survey-creator-core')) :
typeof define === 'function' && define.amd ? define(['exports', 'survey-core', 'survey-creator-core'], factory) :
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.SurveyCreatorUIPresetEditorCore = {}, global.Survey, global.SurveyCreatorCore));
})(this, (function (exports, surveyCore, surveyCreatorCore) { 'use strict';
function showConfirmDialog(creator, options) {
var locStrTitle = new surveyCore.LocalizableString(undefined, false);
locStrTitle.defaultValue = options.title;
var locStrMessage = new surveyCore.LocalizableString(undefined, false);
locStrMessage.defaultValue = options.message;
var titleContainer = new surveyCreatorCore.ComponentContainerModel();
titleContainer.elements = [
{ componentName: "sv-string-viewer", componentData: {
locStr: locStrTitle,
locString: locStrTitle,
model: locStrTitle,
textClass: "svc-creator-confirm-dialog__title"
}
},
{ componentName: "sv-string-viewer", componentData: {
locStr: locStrMessage,
locString: locStrMessage,
model: locStrMessage,
textClass: "svc-creator-confirm-dialog__message"
} }
];
titleContainer.cssClass = "svc-creator-confirm-dialog__title-container";
var className = "svc-creator-confirm-dialog__icon" + (options.category === "danger" ? " svc-creator-confirm-dialog__icon--danger" : "");
var contentModelElements = [
{ componentName: "sv-svg-icon", componentData: {
iconName: options.iconName,
size: "auto",
className: className, // TODO: rework in library
class: className, // TODO: rework in library
partCss: className, // TODO: rework in library
} },
{ componentName: "svc-component-container", componentData: { model: titleContainer } },
];
var contentModel = new surveyCreatorCore.ComponentContainerModel();
contentModel.elements = contentModelElements;
contentModel.cssClass = "svc-creator-confirm-dialog__content-container";
var dialogModel = surveyCore.settings.showDialog({
componentName: "svc-component-container",
data: { model: contentModel },
onApply: function () { return options.onApply(); },
onCancel: function () { return options.onCancel(); },
cssClass: "sps-popup svc-creator-popup svc-creator-confirm-dialog",
displayMode: "popup",
showCloseButton: options.showCloseButton,
}, creator.rootElement);
var defaultActionBarCss = dialogModel.footerToolbar.cssClasses;
defaultActionBarCss.item = "sps-btn";
dialogModel.footerToolbar.cssClasses = defaultActionBarCss;
var applyAction = dialogModel.footerToolbar.getActionById("apply");
var cancelAction = dialogModel.footerToolbar.getActionById("cancel");
applyAction.title = options.applyText;
applyAction.innerCss = options.category === "danger" ? "sps-btn--secondary-alert" : "sps-btn--primary-neutral";
cancelAction.title = options.cancelText;
cancelAction.innerCss = "sps-btn--secondary-neutral";
return dialogModel;
}
/******************************************************************************
Copyright (c) Microsoft Corporation.
Permission to use, copy, modify, and/or distribute this software for any
purpose with or without fee is hereby granted.
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
PERFORMANCE OF THIS SOFTWARE.
***************************************************************************** */
/* global Reflect, Promise, SuppressedError, Symbol, Iterator */
var extendStatics = function(d, b) {
extendStatics = Object.setPrototypeOf ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
return extendStatics(d, b);
};
function __extends(d, b) {
if (typeof b !== "function" && b !== null)
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
extendStatics(d, b);
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
}
var __assign = function() {
__assign = Object.assign || function __assign(t) {
for (var s, i = 1, n = arguments.length; i < n; i++) {
s = arguments[i];
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p];
}
return t;
};
return __assign.apply(this, arguments);
};
function __spreadArray(to, from, pack) {
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
if (ar || !(i in from)) {
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
ar[i] = from[i];
}
}
return to.concat(ar || Array.prototype.slice.call(from));
}
typeof SuppressedError === "function" ? SuppressedError : function (error, suppressed, message) {
var e = new Error(message);
return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
};
var CreatorPresetEditableBase = /** @class */ (function () {
function CreatorPresetEditableBase(preset) {
this.preset = preset;
this.children = [];
this.notifyCallback = function (message) { };
}
Object.defineProperty(CreatorPresetEditableBase.prototype, "navigationPanelName", {
get: function () { return this.path + "_navigation"; },
enumerable: false,
configurable: true
});
Object.defineProperty(CreatorPresetEditableBase.prototype, "isSettingUp", {
get: function () { return false; },
enumerable: false,
configurable: true
});
Object.defineProperty(CreatorPresetEditableBase.prototype, "path", {
get: function () { return this.preset.getPath(); },
enumerable: false,
configurable: true
});
CreatorPresetEditableBase.prototype.getJsonPath = function (model) { return this.path; };
Object.defineProperty(CreatorPresetEditableBase.prototype, "fullPath", {
get: function () {
var prefix = this.parent ? this.parent.fullPath : "";
if (this.path && prefix) {
prefix += "_";
}
return prefix + this.path;
},
enumerable: false,
configurable: true
});
Object.defineProperty(CreatorPresetEditableBase.prototype, "pageName", {
get: function () { return "page_" + this.fullPath; },
enumerable: false,
configurable: true
});
CreatorPresetEditableBase.prototype.getPageTitle = function (model) { return model.getPageByName(this.pageName).title; };
CreatorPresetEditableBase.prototype.getPageShortTitle = function (model) { return model.getPageByName(this.pageName).navigationTitle; };
Object.defineProperty(CreatorPresetEditableBase.prototype, "mainPanelName", {
get: function () { return this.path + "_mainPanel"; },
enumerable: false,
configurable: true
});
CreatorPresetEditableBase.prototype.getMainElementNames = function () { return [this.mainPanelName]; };
CreatorPresetEditableBase.prototype.getMainPanelName = function () { return this.mainPanelName; };
CreatorPresetEditableBase.prototype.getCustomQuestionCssSuffix = function (question) { return ""; };
CreatorPresetEditableBase.prototype.createPages = function () {
var res = [];
var mainPage = this.createMainPage();
if (mainPage) {
res.push(mainPage);
}
this.children.forEach(function (item) {
var pages = item.createPages();
if (Array.isArray(pages)) {
pages.forEach(function (page) { return res.push(page); });
}
});
return res;
};
Object.defineProperty(CreatorPresetEditableBase.prototype, "questionNames", {
get: function () { return []; },
enumerable: false,
configurable: true
});
CreatorPresetEditableBase.prototype.validate = function (model) {
if (!this.validateCore(model))
return false;
for (var i = 0; i < this.children.length; i++) {
if (!this.children[i].validate(model))
return false;
}
return true;
};
CreatorPresetEditableBase.prototype.validateCore = function (model) {
return true;
};
CreatorPresetEditableBase.prototype.createMainPage = function () {
var res = this.createMainPageCore();
if (res) {
res.name = this.pageName;
}
return res;
};
CreatorPresetEditableBase.prototype.getBoolVisibleIf = function (name, isTrue) {
if (isTrue === void 0) { isTrue = true; }
return "{" + name + "}=" + (isTrue ? "true" : "false");
};
CreatorPresetEditableBase.prototype.getTextVisibleIf = function (name, val) { return "{" + name + "}='" + val + "'"; };
CreatorPresetEditableBase.prototype.getNotEmptyVisibleIf = function (name) { return "{" + name + "} notempty"; };
CreatorPresetEditableBase.prototype.createMainPageCore = function () { return undefined; };
CreatorPresetEditableBase.prototype.getNavigationElementName = function () { return this.navigationPanelName; };
CreatorPresetEditableBase.prototype.getJsonValue = function (model, creator, defaultJson) {
var page = model.getPageByName(this.pageName);
var core = page && page.isVisible ? this.getJsonValueCore(model, creator, defaultJson) : undefined;
var hasValue = !!core;
var res = hasValue ? core : {};
this.children.forEach(function (item) {
var val = item.getJsonValue(model, creator);
if (!!val) {
hasValue = true;
res[item.getJsonPath(model)] = val;
}
});
return hasValue ? res : undefined;
};
CreatorPresetEditableBase.prototype.getDefaultJsonValue = function (creator) {
var json = this.getDefaultJsonValueCore(creator);
this.children.forEach(function (item) { return json[item.path] = item.getDefaultJsonValueCore(creator); });
return json;
};
CreatorPresetEditableBase.prototype.setJsonLocalizationStrings = function (model, locStrs) {
this.setJsonLocalizationStringsCore(model, locStrs);
this.children.forEach(function (item) { return item.setJsonLocalizationStrings(model, locStrs); });
};
CreatorPresetEditableBase.prototype.updateJsonLocalizationStrings = function (locStrs) {
this.updateJsonLocalizationStringsCore(locStrs);
this.children.forEach(function (item) { return item.updateJsonLocalizationStrings(locStrs); });
};
CreatorPresetEditableBase.prototype.dispose = function () {
this.disposeCore();
this.children.forEach(function (item) { return item.dispose(); });
};
CreatorPresetEditableBase.prototype.setupQuestions = function (model, creatorSetup) {
this.setupQuestionsCore(model, creatorSetup);
this.children.forEach(function (item) {
item.setupQuestions(model, creatorSetup);
});
};
CreatorPresetEditableBase.prototype.resetToDefaults = function (model, notify) {
if (notify === void 0) { notify = true; }
this.restoreValuesFromDefault(model);
this.notifyCallback(this.getPageTitle(model) + " " + surveyCreatorCore.getLocString("presets.editor.resoredToDefault"));
this.children.forEach(function (item) {
item.resetToDefaults(model, notify);
});
};
CreatorPresetEditableBase.prototype.setupOnCurrentPage = function (model, creator, active) {
this.setupOnCurrentPageCore(model, creator, active);
this.children.forEach(function (item) {
item.setupOnCurrentPage(model, creator, active);
});
};
CreatorPresetEditableBase.prototype.updateOnValueChanged = function (model, name) {
this.updateOnValueChangedCore(model, name);
this.children.forEach(function (item) {
item.updateOnValueChanged(model, name);
});
};
CreatorPresetEditableBase.prototype.updateOnMatrixDetailPanelVisibleChanged = function (model, creator, options) {
this.updateOnMatrixDetailPanelVisibleChangedCore(model, creator, options);
this.children.forEach(function (item) {
item.updateOnMatrixDetailPanelVisibleChanged(model, creator, options);
});
};
CreatorPresetEditableBase.prototype.onGetMatrixRowActions = function (model, creator, options) {
this.onGetMatrixRowActionsCore(model, creator, options);
this.children.forEach(function (item) {
item.onGetMatrixRowActions(model, creator, options);
});
};
CreatorPresetEditableBase.prototype.onGetQuestionTitleActions = function (model, creator, options) { };
CreatorPresetEditableBase.prototype.onGetPanelTitleActions = function (model, creator, options) { };
CreatorPresetEditableBase.prototype.onMatrixRowDragOver = function (model, creator, options) { };
CreatorPresetEditableBase.prototype.onMatrixRowRemoving = function (model, creator, options) { };
CreatorPresetEditableBase.prototype.onMatrixRowAdded = function (model, creator, options) { };
CreatorPresetEditableBase.prototype.onMatrixCellValueChanged = function (model, creator, options) { };
CreatorPresetEditableBase.prototype.setupQuestionsValue = function (model, json, creator) {
this.setupQuestionsValueCore(model, json, creator);
this.saveValuesAsDefault(model);
this.children.forEach(function (item) {
item.setupQuestionsValue(model, !!json ? json[item.path] : undefined, creator);
});
};
CreatorPresetEditableBase.prototype.onLocaleChanged = function (model, json, creator) {
this.onLocaleChangedCore(model, json, creator);
this.children.forEach(function (item) {
item.setupQuestionsValue(model, !!json ? json[item.path] : undefined, creator);
});
};
CreatorPresetEditableBase.prototype.saveValuesAsDefault = function (model) {
this.questionNames.forEach(function (name) { return model.getQuestionByName(name).defaultValue = model.getValue(name) && JSON.parse(JSON.stringify(model.getValue(name))); });
};
CreatorPresetEditableBase.prototype.restoreValuesFromDefault = function (model) {
this.questionNames.forEach(function (name) { return model.getQuestionByName(name).value = model.getQuestionByName(name).defaultValue && JSON.parse(JSON.stringify(model.getQuestionByName(name).defaultValue)); });
};
CreatorPresetEditableBase.prototype.setupQuestionsCore = function (model, creatorSetup) { };
CreatorPresetEditableBase.prototype.resetToDefaultsCore = function (model) { };
CreatorPresetEditableBase.prototype.setupQuestionsValueCore = function (model, json, creator) { };
CreatorPresetEditableBase.prototype.onLocaleChangedCore = function (model, json, creator) { };
CreatorPresetEditableBase.prototype.getJsonValueCore = function (model, creator, defaultJson) { return undefined; };
CreatorPresetEditableBase.prototype.getDefaultJsonValueCore = function (creator) { return {}; };
CreatorPresetEditableBase.prototype.setJsonLocalizationStringsCore = function (model, locStrs) { };
CreatorPresetEditableBase.prototype.updateJsonLocalizationStringsCore = function (locStrs) { };
CreatorPresetEditableBase.prototype.disposeCore = function () { };
CreatorPresetEditableBase.prototype.setupOnCurrentPageCore = function (model, creator, active) { };
CreatorPresetEditableBase.prototype.updateOnValueChangedCore = function (model, name) { };
CreatorPresetEditableBase.prototype.updateOnMatrixDetailPanelVisibleChangedCore = function (model, creator, options) { };
CreatorPresetEditableBase.prototype.onGetMatrixRowActionsCore = function (model, creator, options) { };
CreatorPresetEditableBase.prototype.copyJson = function (json) {
return surveyCore.Helpers.getUnbindValue(json);
};
CreatorPresetEditableBase.updateModifiedText = function (locStrs, text, localizationName) {
if (!localizationName)
return undefined;
if (!text)
return;
var presetStrs = surveyCreatorCore.editorLocalization.presetStrings;
surveyCreatorCore.editorLocalization.presetStrings = undefined;
if (text !== surveyCreatorCore.editorLocalization.getString(localizationName)) {
CreatorPresetEditableBase.saveTextInLocStrs(locStrs, text, localizationName);
}
surveyCreatorCore.editorLocalization.presetStrings = presetStrs;
};
CreatorPresetEditableBase.saveTextInLocStrs = function (locStrs, text, localizationName) {
var paths = localizationName.split(".");
for (var i = 0; i < paths.length - 1; i++) {
var path = paths[i];
if (!locStrs[path]) {
locStrs[path] = {};
}
locStrs = locStrs[path];
}
locStrs[paths[paths.length - 1]] = text;
};
return CreatorPresetEditableBase;
}());
var presetsCss = {
root: "sps-root-modern",
container: "sps-container-modern",
header: "sps-title sps-container-modern__title",
body: "sps-body",
bodyEmpty: "sps-body sps-body--empty",
footer: "sps-footer sps-body__footer sps-clearfix",
title: "",
description: "",
logo: "sps-logo",
logoImage: "sps-logo__image",
headerText: "sps-header__text",
navigationButton: "",
bodyNavigationButton: "",
completedPage: "sps-completedpage",
navigation: {
complete: "sps-btn sps-btn--primary-brand sps-footer__complete-btn",
prev: "sps-btn sps-btn--secondary-brand sps-footer__prev-btn",
next: "sps-btn sps-btn--primary-brand sps-footer__next-btn",
start: "sps-btn sps-footer__start-btn",
preview: "sps-btn sps-footer__preview-btn",
edit: "sps-btn sps-footer__edit-btn"
},
list: JSON.parse(JSON.stringify(surveyCreatorCore.listComponentCss)),
panel: {
withFrame: "sps-panel--with-frame",
nested: "sps-panel--nested",
expandableAnimating: "",
header: "sps-panel__header",
title: "sps-title sps-panel__title",
titleBar: "sd-action-title-bar sps-action-title-bar",
contentEnter: "sps-panel__content--enter",
contentLeave: "sps-panel__content--leave",
titleExpandable: "sps-panel__title--expandable",
titleExpanded: "sps-panel__title--expanded",
titleCollapsed: "sps-panel__title--collapsed",
titleOnError: "sps-panel__title--error",
description: "sps-description sps-panel__description",
container: "sps-panel sps-row__panel",
content: "sps-panel__content",
icon: "sps-panel__icon",
iconExpanded: "sps-panel__icon--expanded",
footer: "sps-panel__footer",
requiredMark: "sps-panel__required-text",
collapsed: "sps-panel--collapsed",
expanded: "sps-panel--expanded",
},
paneldynamic: {
nested: "",
mainRoot: "sps-question sps-row__question",
root: "sps-paneldynamic",
navigation: "sps-paneldynamic__navigation",
title: "sps-title sps-question__title",
button: "sps-action-button sps-action-button--text",
buttonRemove: "sps-action-button--danger",
buttonAdd: "sps-paneldynamic__add-btn",
panelsContainer: "",
panelWrapper: "sps-paneldynamic__panel-wrapper",
panelWrapperList: "",
progressTop: "sps-paneldynamic__progress sps-paneldynamic__progress--top",
progressBottom: "sps-paneldynamic__progress sps-paneldynamic__progress--bottom",
buttonPrev: "sps-paneldynamic__prev-btn",
buttonNext: "sps-paneldynamic__next-btn",
progressContainer: "sps-paneldynamic__progress-container",
progress: "sps-progress",
progressBar: "sps-progress__bar",
progressText: "sps-paneldynamic__progress-text",
panelFooter: "sps-panel__footer",
separator: "sps-paneldynamic__separator",
footer: "sps-paneldynamic__footer",
footerButtonsContainer: "sps-paneldynamic__buttons-container",
},
progress: "sps-progress sps-body__progress",
progressBar: "sps-progress__bar",
progressText: "sps-progress__text",
progressTextInBar: "sps-hidden",
page: {
root: "sps-page sps-body__page",
title: "sps-title sps-page__title",
description: "sps-description sps-page__description"
},
pageTitle: "sps-title sps-page__title",
pageDescription: "sps-description sps-page__description",
row: "sps-row sps-clearfix",
rowEnter: "sps-row--enter",
rowLeave: "sps-row--leave",
rowDelayedEnter: "sps-row--delayed-fade-in",
rowMultiple: "sps-row--multiple",
question: {
withFrame: "sps-question--with-frame",
nested: "sps-question--nested",
mainRoot: "sps-question sps-row__question",
flowRoot: "sps-question sps-row__question sps-row__question--flow",
asCell: "sps-table__cell",
header: "sps-question__header",
headerLeft: "sps-question__header--location--left",
headerTop: "sps-question__header--location--top",
headerBottom: "sps-question__header--location--bottom",
content: "sps-question__content",
contentLeft: "sps-question__content--left",
titleLeftRoot: "sps-question--location--left",
titleOnAnswer: "sps-question__title--answer",
titleOnError: "sps-question__title--error",
title: "sps-title sps-question__title",
titleBar: "sd-action-title-bar sps-action-title-bar",
requiredMark: "sps-question__required-text",
number: "sps-question__num",
description: "sps-description sps-question__description",
descriptionUnderInput: "sps-question__description--under",
comment: "sps-comment",
required: "sps-question--required",
titleRequired: "sps-question__title--required",
indent: 0,
footer: "sps-question__footer",
formGroup: "sps-question__form-group",
hasError: "",
readOnly: "sd-question--readonly sps-question--disabled",
confirmDialog: "sps-popup--confirm sv-popup--confirm svc-creator-popup",
errorsContainerBottom: "sps-question__erbox--below-question",
},
checkbox: {
root: "sps-selectbase",
item: "sps-item sps-checkbox sps-selectbase__item",
itemSelectAll: "sps-checkbox--selectall",
itemNone: "sps-checkbox--none",
itemReadOnly: "sps-item--disabled sps-checkbox--disabled",
itemChecked: "sps-checkbox--checked",
itemHover: "sps-checkbox--allowhover",
itemInline: "sps-selectbase__item--inline",
label: "sps-selectbase__label",
// label: "sps-checkbox",
itemSvgIconId: "#icon-check-16x16",
labelChecked: "",
//itemControl: "sps-visuallyhidden sps-item__control",
itemControl: "sps-checkbox__control",
itemDecorator: "sps-checkbox__svg",
//itemDecorator: "sps-checkbox__hidden",
//controlLabel: "sps-item__control-label",
controlLabel: "sps-checkbox__caption",
materialDecorator: "sps-checkbox__rectangle",
//materialDecorator: "sps-item__decorator sps-checkbox__decorator",
other: "sps-comment sps-question__other",
column: "sps-selectbase__column"
},
radiogroup: {
root: "sps-selectbase",
item: "sps-item sps-radio sps-selectbase__item",
itemInline: "sps-selectbase__item--inline",
label: "sps-selectbase__label",
labelChecked: "",
itemReadOnly: "sps-item--disabled sps-radio--disabled",
itemChecked: "sps-radio--checked",
itemHover: "sps-radio--allowhover",
itemControl: "sps-visuallyhidden sps-item__control",
itemDecorator: "sps-item__svg sps-radio__svg",
controlLabel: "sps-item__control-label",
materialDecorator: "sps-item__decorator sps-radio__decorator",
other: "sps-comment sps-question__other",
clearButton: "sps-btn sps-selectbase__clear-btn",
column: "sps-selectbase__column"
},
boolean: {
mainRoot: "sps-question sps-row__question sps-question--boolean",
rootCheckbox: "sps-selectbase",
checkboxItem: "sps-checkbox",
checkboxItemChecked: "sps-checkbox--checked",
checkboxitemIndeterminate: "sps-checkbox--indeterminate",
checkboxItemReadOnly: "sps-checkbox--disabled",
svgIconId: "#icon-v2check",
checkboxLabel: "sps-selectbase__label",
controlCheckbox: "sps-checkbox__control",
checkboxControlLabel: "sps-checkbox__caption",
checkboxItemDecorator: "sps-checkbox__svg",
checkboxMaterialDecorator: "sps-checkbox__rectangle"
},
text: {
root: "sps-input sps-text",
controlReadOnly: "sps-input--readonly",
small: "sps-row__question--small",
content: "sps-question__content sps-text__content",
remainingCharacterCounter: "sps-remaining-character-counter",
onError: "sps-input--error"
},
comment: {
root: "sps-input sps-comment",
content: "sps-question__content sps-comment__content",
remainingCharacterCounter: "sps-remaining-character-counter",
small: "sps-row__question--small",
onError: "sps-input--error"
},
dropdown: {
root: "sps-selectbase",
popup: "sps-dropdown-popup svc-creator-popup",
small: "sps-row__question--small sd-row__question--small",
control: "sps-input sps-dropdown",
controlEmpty: "sps-dropdown--empty sd-dropdown--empty",
controlValue: "sps-dropdown__value",
filterStringInput: "sd-dropdown__filter-string-input sps-dropdown__filter-string-input",
other: "sps-comment sps-question__other",
onError: "sps-input--error",
selectWrapper: "sv-dropdown_select-wrapper sps-dropdown_select-wrapper",
chevronButtonIconId: "icon-chevron",
cleanButton: "sps-dropdown__clean-button sps-input__edit-button",
controlReadOnly: "sps-input--readonly sd-input--disabled sd-input--readonly",
hintPrefix: "sps-dropdown__hint-prefix sd-dropdown__hint-prefix",
hintSuffix: "sps-dropdown__hint-suffix sd-dropdown__hint-suffix"
},
tagbox: {
cleanItemButton: "sd-tagbox-item_clean-button sps-tagbox-item_clean-button",
cleanItemButtonSvg: "sd-tagbox-item_clean-button-svg sps-tagbox-item_clean-button-svg",
control: "sd-input sd-tagbox sd-dropdown sps-tagbox sps-dropdown",
controlValue: "sd-tagbox__value sd-dropdown__value sps-tagbox__value",
filterStringInput: "sd-dropdown__filter-string-input sps-dropdown__filter-string-input",
},
matrix: {
tableWrapper: "sps-matrix sps-table-wrapper",
root: "sps-table",
rowError: "sps-matrix__row--error",
cell: "sps-table__cell sps-matrix__cell",
headerCell: "sps-table__cell sps-table__cell--header",
label: "sps-item sps-radio sps-matrix__label",
itemValue: "sps-visuallyhidden sps-item__control sps-radio__control",
itemChecked: "sps-radio--checked",
itemReadOnly: "sps-item--disabled sps-radio--disabled",
itemHover: "sps-radio--allowhover",
materialDecorator: "sps-item__decorator sps-radio__decorator",
itemDecorator: "sps-item__svg sps-radio__svg",
cellText: "sps-matrix__text",
cellTextSelected: "sps-matrix__text--checked",
cellTextReadOnly: "sps-matrix__text--disabled",
},
matrixdropdown: {
tableWrapper: "sps-table-wrapper",
root: "sps-table",
cell: "sps-table__cell",
headerCell: "sps-table__cell sps-table__cell--header",
emptyCell: "sps-table__cell--empty",
rowEnter: "sps-table__row--enter",
rowLeave: "sps-table__row--leave",
},
matrixdynamic: {
mainRoot: "sps-question sps-question--matrixdynamic sd-element sd-question sd-row__question sd-element--complex sd-question--complex sd-question--table",
tableWrapper: "sps-table-wrapper",
root: "sps-table sps-matrixdynamic",
content: "sps-matrixdynamic__content sps-text__content",
cell: "sps-table__cell",
row: "sps-table__row",
rowDisabled: "sps-table__row-disabled",
rowReadOnly: "sps-table__row-readonly",
headerCell: "sps-table__cell sps-table__cell--header",
button: "sps-btn",
detailRow: "sps-table__row sps-table__row--detail",
detailButton: "sps-table__cell--detail-button sps-action-button sps-action-button--icon",
detailButtonExpanded: "sps-table__cell--detail-button--expanded",
detailIcon: "sps-detail-panel__icon sps-action-button__icon",
detailIconExpanded: "sps-detail-panel__icon--expanded",
detailIconExpandedId: "icon-collapse-24x24",
detailIconId: "icon-expand-24x24",
detailPanelCell: "sps-table__cell sps-table__cell--detail-panel",
actionsCell: "sps-table__cell sps-table__cell--actions",
buttonAdd: "sps-matrixdynamic__add-btn sps-action-button sps-action-button--large",
buttonRemove: "",
iconAdd: "",
iconRemove: "#icon-delete-24x24",
dragElementDecorator: "sps-drag-element__svg",
iconDragElement: "#icon-drag-24x24",
iconDrag: "sps-matrixdynamic__drag-element",
footer: "sps-matrixdynamic__footer",
dragDropGhostPositionTop: "sps-matrixdynamic__drag-drop-ghost-position-top",
dragDropGhostPositionBottom: "sps-matrixdynamic__drag-drop-ghost-position-bottom",
noRowsSection: "sps-matrixdynamic__placeholder",
noRowsText: "sps-matrixdynamic__placeholder-text",
cellQuestionWrapper: "sps-table__question-wrapper",
draggedRow: "sps-matrixdynamic__dragged-row",
emptyCell: "sps-table__cell--empty",
rowEmpty: "sps-table__row--empty",
rowEnter: "sps-table__row--enter",
rowLeave: "sps-table__row--leave",
},
actionBar: {
root: "sps-action-bar",
item: "sps-action-button",
itemPressed: "sps-action-button--pressed",
itemAsIcon: "sps-action-button--icon",
itemIcon: "sps-action-button__icon",
itemTitle: "sps-action-button__title",
}
};
var CreatorPresetEditableList = /** @class */ (function (_super) {
__extends(CreatorPresetEditableList, _super);
function CreatorPresetEditableList() {
var _this = _super !== null && _super.apply(this, arguments) || this;
//private replaceNonLettersWithDash(inputString) {
// return inputString?.replace(/[^a-zA-Z0-9]/g, "-");
//}
_this.defaultIcon = "square-dashed-24x24";
return _this;
}
Object.defineProperty(CreatorPresetEditableList.prototype, "nameItems", {
get: function () { return this.path + "_items"; },
enumerable: false,
configurable: true
});
Object.defineProperty(CreatorPresetEditableList.prototype, "nameMatrix", {
get: function () { return this.fullPath + "_matrix"; },
enumerable: false,
configurable: true
});
CreatorPresetEditableList.prototype.hasIcon = function (_) { return false; };
CreatorPresetEditableList.prototype.getMainElementNames = function () { return [this.nameItems]; };
Object.defineProperty(CreatorPresetEditableList.prototype, "iconList", {
get: function () { return Object.keys(surveyCore.SvgRegistry.icons).map(function (name) { return "icon-" + name; }); },
enumerable: false,
configurable: true
});
CreatorPresetEditableList.prototype.getMatrixKeyColumnName = function (question) { return "name"; };
CreatorPresetEditableList.prototype.getDefaultItems = function (question) {
return this.defaultItems;
};
CreatorPresetEditableList.prototype.getDefaultItem = function (question, key) {
var keyColumn = this.getMatrixKeyColumnName(question);
return this.getDefaultItems(question).filter(function (i) { return i[keyColumn] == key; })[0];
};
//private fillAutoName(question: QuestionMatrixDynamicModel, propName: string) {
// question.value?.filter(v =>v.isDefault === false && !v[propName]).forEach(v => v[propName] = this.replaceNonLettersWithDash(v.title));
//}
CreatorPresetEditableList.prototype.updateOnValueChangedCore = function (model, name) {
if (this.needToSetActions(name)) {
var matrix = model.getQuestionByName(name);
this.updateMatrixRowActions(model, matrix);
}
};
CreatorPresetEditableList.prototype.updateMatrixRowActions = function (model, matrix) {
var _this = this;
matrix.renderedTable.rows.forEach(function (r) {
var _a, _b, _c;
if (!r.row)
return;
var iconActions = (_b = (_a = r.cells[1]) === null || _a === void 0 ? void 0 : _a.item) === null || _b === void 0 ? void 0 : _b.value.actions;
_this.updateRowActions(matrix, r.row, iconActions);
var actions = (_c = r.cells[r.cells.length - 1].item) === null || _c === void 0 ? void 0 : _c.value.actions;
_this.updateRowActions(matrix, r.row, actions);
});
};
CreatorPresetEditableList.prototype.updateRowActions = function (question, row, actions) {
var _this = this;
if (!actions)
return;
var keyColumn = this.getMatrixKeyColumnName(question);
if (!question.value)
return;
var rowData = question.value.filter(function (r) { var _a; return ((_a = row.value) === null || _a === void 0 ? void 0 : _a[keyColumn]) == (r === null || r === void 0 ? void 0 : r[keyColumn]); })[0];
if (!rowData)
return;
actions.forEach(function (a) { return _this.updateRowAction(question, row, rowData, keyColumn, a); });
};
CreatorPresetEditableList.prototype.updateRowAction = function (question, row, rowData, keyColumn, action) {
if (action.id == "icon-action") {
action.iconName = rowData.iconName || this.defaultIcon;
}
if (action.id == "reset-to-default") {
var defaultItem_1 = this.getDefaultItem(question, rowData[keyColumn]);
if (!defaultItem_1)
return;
var defaultData_1 = {};
Object.keys(rowData).forEach(function (key) { return defaultData_1[key] = defaultItem_1[key]; });
action.enabled = !surveyCore.Helpers.isTwoValueEquals(rowData, defaultData_1);
}
};
CreatorPresetEditableList.prototype.createResetAction = function (model, row, action) {
return {
id: "reset-to-default",
iconName: "icon-reset",
tooltip: surveyCreatorCore.getLocString("presets.items.restoreToDefault"),
location: "end",
visibleIndex: 15,
action: action
};
};
CreatorPresetEditableList.prototype.createEditAction = function (model, creator, question, row) {
var _this = this;
return {
id: "edit-item",
iconName: "icon-edit",
tooltip: surveyCreatorCore.getLocString("presets.items.edit"),
location: "end",
visibleIndex: 13,
action: function () { _this.editItem(model, creator, question, row); }
};
};
CreatorPresetEditableList.prototype.createIconAction = function (iconName, cssClass) {
if (cssClass === void 0) { cssClass = "sps-matrixdynamic__row-icon"; }
return {
id: "icon-action",
iconName: iconName,
innerCss: cssClass,
location: "start",
enabled: false
};
};
CreatorPresetEditableList.prototype.setupStandardActions = function (actions, question, row, allowExpand, isItemsMatrix) {
actions.forEach(function (a) {
if (a.id == "show-detail") {
a.location = "end";
a.iconName = "icon-expand-24x24";
a.title = new surveyCore.ComputedUpdater(function () { return row.isDetailPanelShowing ? surveyCreatorCore.getLocString("presets.items.collapse") : surveyCreatorCore.getLocString("presets.items.expand"); });
a.tooltip = surveyCreatorCore.getLocString("presets.items.expand");
a.visibleIndex = 10;
a.visible = allowExpand;
}
if (a.id == "remove-row") {
a.visibleIndex = 20;
a.component = "sv-action-bar-item";
a.action = function () { return question.removeRowUI(row); };
a.iconName = isItemsMatrix ? "icon-add_24x24" : "icon-remove_24x24";
a.tooltip = isItemsMatrix ? surveyCreatorCore.getLocString("presets.items.add") : surveyCreatorCore.getLocString("presets.items.delete");
}
});
};
CreatorPresetEditableList.prototype.editItem = function (model, creator, question, row, options) {
var _this = this;
var survey;
var resetAction;
var itemKey = this.getMatrixKeyColumnName(question);
var resetActionParams = {
id: "reset-to-default",
title: surveyCreatorCore.getLocString("presets.editor.resetToDefault"),
css: "sps-action--grow",
innerCss: "sps-btn sps-btn--secondary-alert",
visibleIndex: 15,
action: function (a) {
var defaultItem = _this.getDefaultItem(question, survey.getValue(itemKey));
survey.data = defaultItem;
resetAction.enabled = false;
_this.notifyCallback(surveyCreatorCore.getLocString("presets.editor.itemRestoredToDefault"));
}
};
resetAction = new surveyCore.Action(resetActionParams);
survey = this.showDetailPanelInPopup(question, row, model.rootElement, { actions: [resetAction], title: options === null || options === void 0 ? void 0 : options.description, removeOnCancel: options === null || options === void 0 ? void 0 : options.isNew });
resetAction.enabled = !surveyCore.Helpers.isTwoValueEquals(survey.data, this.getDefaultItem(question, survey.getValue(itemKey)));
survey.onValueChanged.add(function () { return resetAction.enabled = true; });
var keyQuestion = survey.getQuestionByName(itemKey);
if (this.getDefaultItem(question, keyQuestion.value)) {
keyQuestion.readOnly = true;
}
};
CreatorPresetEditableList.prototype.resetItem = function (model, question, row) {
var name = row.getValue("name");
var defaultItems = this.getDefaultItem(question, name);
if (defaultItems) {
var value = question.value;
var itemRow_1 = value.filter(function (v) { return v.name == name; })[0];
Object.keys(itemRow_1).forEach(function (key) {
itemRow_1[key] = defaultItems[key];
});
question.value = value;
}
this.notifyCallback(surveyCreatorCore.getLocString("presets.editor.itemRestoredToDefault"));
};
CreatorPresetEditableList.prototype.restoreItems = function (questionItems, questionHiddenItems, rowIndex) {
var rowData = questionHiddenItems.value[rowIndex];
var value = questionItems.value ? __spreadArray([], questionItems.value, true) : [];
value.push(rowData);
questionItems.value = value;
};
CreatorPresetEditableList.prototype.getMatrix = function (model) {
return model.getQuestionByName(this.nameMatrix);
};
CreatorPresetEditableList.prototype.isItemsMatrix = function (name) {
return name === this.nameMatrix;
};
CreatorPresetEditableList.prototype.needToSetActions = function (name) {
return this.isItemsMatrix(name);
};
CreatorPresetEditableList.prototype.onGetMatrixRowActionsCore = function (model, creator, options) {
var _this = this;
var _a, _b;
if (this.needToSetActions(options.question.name)) {
var question_1 = options.question;
var allowExpand = question_1.detailElements.filter(function (e) { return e.visible; }).length > 0;
if (this.hasIcon(options.question.name)) {
var keyColumn_1 = this.getMatrixKeyColumnName(options.question);
var iconName = ((_b = (_a = question_1.value) === null || _a === void 0 ? void 0 : _a.filter(function (v) { return v[keyColumn_1] == options.row.getValue(keyColumn_1); })[0]) === null || _b === void 0 ? void 0 : _b.iconName) || this.defaultIcon;
options.actions.push(this.createIconAction(iconName));
}
var resetAction = this.createResetAction(model, options.row, function (action) {
_this.resetItem(model, question_1, options.row);
action.enabled = false;
});
options.actions.push(resetAction);
options.actions.push(this.createEditAction(model, creator, question_1, options.row));
this.setupStandardActions(options.actions, question_1, options.row, allowExpand, question_1.name == this.nameMatrix);
this.updateRowActions(question_1, options.row, options.actions);
}
};
CreatorPresetEditableList.prototype.onMatrixRowDragOver = function (model, creator, options) {
if (this.isItemsMatrix(options.fromMatrix.name) && this.isItemsMatrix(options.toMatrix.name)) {
options.allow = true;
}
};
CreatorPresetEditableList.prototype.onMatrixRowRemoving = function (model, creator, options) {
if (this.isItemsMatrix(options.question.name) && options.question.name != this.nameMatrix) {
var rowData = options.question.value[options.rowIndex];
var hiddenItems = this.getMatrix(model);
var value = hiddenItems.value ? __spreadArray([], hiddenItems.value, true) : [];
value.push(rowData);
hiddenItems.value = value;
}
};
CreatorPresetEditableList.prototype.getExistingKeys = function (model, key) {
var items = model.getQuestionByName(this.nameItems).value || [];
var unsorted = model.getQuestionByName(this.nameMatrix).value || [];
return __spreadArray(__spreadArray([], items, true), unsorted, true);
};
CreatorPresetEditableList.prototype.getDefaultValueForRow = function (model, question, key) {
return surveyCreatorCore.SurveyHelper.getNewName(this.getExistingKeys(model, key).map(function (i) { return i[key]; }).filter(function (v) { return !!v; }).map(function (r) { return ({ name: r }); }), key);
};
CreatorPresetEditableList.prototype.setDefaultValueForRow = function (model, question, row) {
var key = this.getMatrixKeyColumnName(question);
var value = this.getDefaultValueForRow(model, question, key);
row.getQuestionByName(key).value = value;
row.getQuestionByName("title").value = value;
};
CreatorPresetEditableList.prototype.onMatrixRowAdded = function (model, creator, options) {
var _a, _b;
if (this.isItemsMatrix(options.question.name)) {
this.setDefaultValueForRow(model, options.question, options.row);
this.editItem(model, creator, options.question, options.row, {
description: surveyCreatorCore.getLocString("presets.items.newItem") + " " + (((_b = (_a = options.question.data) === null || _a === void 0 ? void 0 : _a.value) === null || _b === void 0 ? void 0 : _b.title) || this.getPageShortTitle(model)),
isNew: true
});
}
};
CreatorPresetEditableList.prototype.onMatrixCellValueChanged = function (model, creator, options) {
if (this.needToSetActions(options.question.name)) {
var renderedRow = options.question.renderedTable.rows.find(function (r) { return r.row == options.row; });
if (!renderedRow)
return;
var actions = renderedRow.cells[renderedRow.cells.length - 1].item.value.actions;
if (!actions)
return;
this.updateRowActions(options.question, options.row, actions);
}
};
CreatorPresetEditableList.prototype.onDetailPanelInPopupApply = function (data, matrix, row) { return true; };
CreatorPresetEditableList.prototype.applyDetailPanelInPopup = function (survey, matrix, row, index) {
if (survey.validate()) {
var newData_1 = {};
survey.getAllQuestions().forEach(function (q) {
if (q.visible) {
newData_1[q.name] = q.isEmpty() && q.isDescendantOf("checkbox") ? [] : q.value;
}
});
var newValue = __spreadArray([], matrix.value, true);
var newRowValue = __assign(__assign({}, matrix.value[index]), newData_1);
newValue[index] = newRowValue;
if (this.onDetailPanelInPopupApply(newData_1, matrix, row)) {
matrix.value = newValue;
}
this.updateMatrixRowActions(mat