UNPKG

@blinkk/selective-edit

Version:
51 lines 1.98 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.CheckboxMultiField = void 0; const field_1 = require("../field"); const option_1 = require("../../mixins/option"); const lit_html_1 = require("lit-html"); const dataType_1 = require("../../utility/dataType"); const dom_1 = require("../../utility/dom"); class CheckboxMultiField extends (0, option_1.OptionMixin)(field_1.Field) { constructor(types, config, globalConfig, fieldType = 'checkboxMulti') { super(types, config, globalConfig, fieldType); this.config = config; } handleInput(evt) { const target = (0, dom_1.findParentByClassname)(evt.target, 'selective__options__option'); if (!target) { return; } this.currentValue = this.currentValue || []; const value = target.dataset.value; if (this.currentValue.includes(value)) { this.currentValue = this.currentValue.filter((item) => item !== value); } else { this.currentValue.push(value); } this.render(); } /** * Check if the data format is invalid for what the field expects to edit. */ get isDataFormatValid() { if (this.originalValue === undefined || this.originalValue === null) { return true; } return dataType_1.DataType.isArray(this.originalValue); } templateInput(editor, data) { const value = this.currentValue || []; return (0, lit_html_1.html) `${this.templateHelp(editor, data)} ${this.templateOptions(editor, data, { handleBlur: this.handleBlur.bind(this), handleInput: this.handleInput.bind(this), isMulti: true, isOptionSelected: (option) => value.includes(option.value), }, this.config.options)} ${this.templateErrors(editor, data)}`; } } exports.CheckboxMultiField = CheckboxMultiField; //# sourceMappingURL=checkboxMulti.js.map