Skip to content

Commit

Permalink
Merge branch 'master' into feature/7583-carry-forward-unarranged-beha…
Browse files Browse the repository at this point in the history
…vior
  • Loading branch information
dmitry-kurmanov committed Jan 19, 2024
2 parents 4c5f191 + 6be9ad5 commit 1477411
Show file tree
Hide file tree
Showing 15 changed files with 283 additions and 80 deletions.
11 changes: 9 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,18 +61,25 @@ Make sure that you have Node.js v14 or later and a compatible npm version instal
npm install
```
1. **Build the [platform-independent part](https://github.com/surveyjs/survey-library/blob/master/build-scripts/survey-core/README.md#survey-model-platform-independent-part) and plugins**
```
npm run build_core
npm run build-plugins
```
1. **Build the library**
```
npm run build_prod
npm run build
```
You can find the built scripts and style sheets in folders under the `build` directory.
1. **Run test examples**
```
npm start
npm run serve
```
This command runs a local HTTP server at http://localhost:7777/.
Expand Down
1 change: 1 addition & 0 deletions src/defaultCss/defaultV2Css.ts
Original file line number Diff line number Diff line change
Expand Up @@ -323,6 +323,7 @@ export var defaultV2Css = {
small: "sd-row__question--small",
controlDisabled: "sd-input--disabled",
constrolWithCharacterCounter: "sd-text__character-counter",
characterCounterBig: "sd-text__character-counter--big",
content: "sd-text__content sd-question__content",
remainingCharacterCounter: "sd-remaining-character-counter",
onError: "sd-input--error"
Expand Down
4 changes: 4 additions & 0 deletions src/defaultV2-theme/blocks/sd-input.scss
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,10 @@ textarea {
padding-inline-end: calcSize(8);
}

.sd-text__character-counter.sd-text__character-counter--big:focus-within {
padding-inline-end: calcSize(11);
}

.sd-remaining-character-counter {
display: none;
flex-direction: row;
Expand Down
93 changes: 52 additions & 41 deletions src/jsonobject.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1051,42 +1051,58 @@ export class JsonMetadata {
}
public getPropertiesByObj(obj: any): Array<JsonObjectProperty> {
if (!obj || !obj.getType) return [];
var res: any = {};
var props = this.getProperties(obj.getType());
for (var i = 0; i < props.length; i++) {
res[props[i].name] = props[i];
}
var dynamicProps = !!obj.getDynamicType
? this.getProperties(obj.getDynamicType())
: null;
if (dynamicProps && dynamicProps.length > 0) {
for (var i = 0; i < dynamicProps.length; i++) {
let dProp = dynamicProps[i];
if (!!res[dProp.name]) continue;
res[dProp.name] = dProp;
const props = this.getProperties(obj.getType());
const dynamicProps = this.getDynamicPropertiesByObj(obj);
return [].concat(props).concat(dynamicProps);
}
public addDynamicPropertiesIntoObj(dest: any, src: any, props: Array<JsonObjectProperty>): void {
props.forEach(prop => {
this.addDynamicPropertyIntoObj(dest, src, prop.name, false);
if (prop.serializationProperty) {
this.addDynamicPropertyIntoObj(dest, src, prop.serializationProperty, true);
}
if (prop.alternativeName) {
this.addDynamicPropertyIntoObj(dest, src, prop.alternativeName, false);
}
});
}
private addDynamicPropertyIntoObj(dest: any, src: any, propName: string, isReadOnly: boolean): void {
var desc = {
configurable: true,
get: function () {
return src[propName];
},
};
if (!isReadOnly) {
(<any>desc)["set"] = function (v: any) {
src[propName] = v;
};
}
return Object.keys(res).map((key) => res[key]);
Object.defineProperty(dest, propName, desc);
}
public getDynamicPropertiesByObj(obj: any, dynamicType: string = null): Array<JsonObjectProperty> {
if (!obj || !obj.getType || (!obj.getDynamicType && !dynamicType))
return [];
const objType = obj.getType();
if (!obj || !obj.getType) return [];
if(!!obj.getDynamicProperties) return obj.getDynamicProperties();
if(!obj.getDynamicType && !dynamicType) return [];
const dType = !!dynamicType ? dynamicType : obj.getDynamicType();
if (!dType) return [];
const cacheType = dType + "-" + objType;
return this.getDynamicPropertiesByTypes(obj.getType(), dType);
}
public getDynamicPropertiesByTypes(objType: string, dynamicType: string, invalidNames?: Array<string>): Array<JsonObjectProperty> {
if (!dynamicType) return [];
const cacheType = dynamicType + "-" + objType;
if(this.dynamicPropsCache[cacheType]) return this.dynamicPropsCache[cacheType];
var dynamicProps = this.getProperties(dType);
var dynamicProps = this.getProperties(dynamicType);
if (!dynamicProps || dynamicProps.length == 0) return [];
var hash: any = {};
var props = this.getProperties(objType);
const hash: any = {};
const props = this.getProperties(objType);
for (var i = 0; i < props.length; i++) {
hash[props[i].name] = props[i];
}
var res = [];
for (var i = 0; i < dynamicProps.length; i++) {
let dProp = dynamicProps[i];
if (!hash[dProp.name]) {
const res = [];
if(!invalidNames) invalidNames = [];
for (let i = 0; i < dynamicProps.length; i++) {
const dProp = dynamicProps[i];
if (!hash[dProp.name] && invalidNames.indexOf(dProp.name) < 0) {
res.push(dProp);
}
}
Expand Down Expand Up @@ -1630,23 +1646,18 @@ export class JsonObject {
private addDynamicProperties(
obj: any,
jsonObj: any,
properties: Array<JsonObjectProperty>
props: Array<JsonObjectProperty>
): Array<JsonObjectProperty> {
if (!obj.getDynamicPropertyName) return properties;
var dynamicPropName = obj.getDynamicPropertyName();
if (!dynamicPropName) return properties;
if (jsonObj[dynamicPropName]) {
obj[dynamicPropName] = jsonObj[dynamicPropName];
}
var dynamicProperties = this.getDynamicProperties(obj);
var res = [];
for (var i = 0; i < properties.length; i++) {
res.push(properties[i]);
}
for (var i = 0; i < dynamicProperties.length; i++) {
res.push(dynamicProperties[i]);
if (!obj.getDynamicPropertyName && !obj.getDynamicProperties) return props;
if(obj.getDynamicPropertyName) {
const dynamicPropName = obj.getDynamicPropertyName();
if (!dynamicPropName) return props;
if (dynamicPropName && jsonObj[dynamicPropName]) {
obj[dynamicPropName] = jsonObj[dynamicPropName];
}
}
return res;
const dynamicProps = this.getDynamicProperties(obj);
return dynamicProps.length === 0 ? props : [].concat(props).concat(dynamicProps);
}
private propertiesToJson(
obj: any,
Expand Down
48 changes: 46 additions & 2 deletions src/question_custom.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Question, IConditionObject } from "./question";
import { Serializer, CustomPropertiesCollection } from "./jsonobject";
import { Serializer, CustomPropertiesCollection, JsonObjectProperty } from "./jsonobject";
import {
ISurveyImpl,
ISurveyData,
Expand Down Expand Up @@ -82,6 +82,7 @@ export interface ICustomQuestionTypeConfiguration {
* ```
*/
defaultQuestionTitle?: any;
inheritBaseProps?: false | true | Array<string>;
/**
* A function that is called when the custom question is created. Use it to access questions nested within a [composite question type](https://surveyjs.io/form-library/documentation/customize-question-types/create-composite-question-types).
*
Expand Down Expand Up @@ -239,6 +240,7 @@ export interface ICustomQuestionTypeConfiguration {
}

export class ComponentQuestionJSON {
private dynamicProperties: Array<JsonObjectProperty>;
public constructor(public name: string, public json: ICustomQuestionTypeConfiguration) {
var self = this;
Serializer.addClass(
Expand Down Expand Up @@ -331,6 +333,34 @@ export class ComponentQuestionJSON {
public get isComposite(): boolean {
return !!this.json.elementsJSON || !!this.json.createElements;
}
public getDynamicProperties(): Array<JsonObjectProperty> {
if(!Array.isArray(this.dynamicProperties)) {

}
this.dynamicProperties = this.calcDynamicProperties();
return this.dynamicProperties;
}
private calcDynamicProperties(): Array<JsonObjectProperty> {
const baseProps = this.json.inheritBaseProps;
if(!baseProps || !this.json.questionJSON) return [];
const type = this.json.questionJSON.type;
if(!type) return [];
if(Array.isArray(baseProps)) {
const props: Array<JsonObjectProperty> = [];
baseProps.forEach(name => {
const prop = Serializer.findProperty(type, name);
if(prop) {
props.push(prop);
}
});
return props;
}
const invalidNames = [];
for(let key in this.json.questionJSON) {
invalidNames.push(key);
}
return Serializer.getDynamicPropertiesByTypes(this.name, type, invalidNames);
}
}

export class ComponentCollection {
Expand Down Expand Up @@ -681,8 +711,15 @@ export class QuestionCustomModel extends QuestionCustomModelBase {
public getTemplate(): string {
return "custom";
}
protected createWrapper() {
public getDynamicProperties(): Array<JsonObjectProperty> {
return this.customQuestion.getDynamicProperties() || [];
}
public getDynamicType(): string {
return this.questionWrapper ? this.questionWrapper.getType() : "question";
}
protected createWrapper(): void {
this.questionWrapper = this.createQuestion();
this.createDynamicProperties(this.questionWrapper);
}
protected getElement(): SurveyElement {
return this.contentQuestion;
Expand Down Expand Up @@ -842,6 +879,13 @@ export class QuestionCustomModel extends QuestionCustomModelBase {
}
this.isSettingValueChanged = false;
}
private createDynamicProperties(el: SurveyElement): void {
if(!el) return;
const props = this.getDynamicProperties();
if(Array.isArray(props)) {
Serializer.addDynamicPropertiesIntoObj(this, el, props);
}
}
protected initElement(el: SurveyElement): void {
super.initElement(el);
if (!!el) {
Expand Down
32 changes: 2 additions & 30 deletions src/question_matrixdropdowncolumn.ts
Original file line number Diff line number Diff line change
Expand Up @@ -838,36 +838,8 @@ export class MatrixDropdownColumn extends Base
}
}
private addProperties(curCellType: string) {
var question = this.templateQuestion;
var properties = this.getProperties(curCellType);
for (var i = 0; i < properties.length; i++) {
var prop = properties[i];
this.addProperty(question, prop.name, false);
if (prop.serializationProperty) {
this.addProperty(question, prop.serializationProperty, true);
}
if (prop.alternativeName) {
this.addProperty(question, prop.alternativeName, false);
}
}
}
private addProperty(
question: Question,
propName: string,
isReadOnly: boolean
) {
var desc = {
configurable: true,
get: function () {
return (<any>question)[propName];
},
};
if (!isReadOnly) {
(<any>desc)["set"] = function (v: any) {
(<any>question)[propName] = v;
};
}
Object.defineProperty(this, propName, desc);
const props = this.getProperties(curCellType);
Serializer.addDynamicPropertiesIntoObj(this, this.templateQuestion, props);
}
}

Expand Down
5 changes: 2 additions & 3 deletions src/question_paneldynamic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -808,9 +808,8 @@ export class QuestionPanelDynamicModel extends Question
}
}
}
let removedPanels:Array<PanelModel> = [];
if (val < this.panelCount) {
removedPanels = this.panelsCore.splice(val, this.panelCount - val);
this.panelsCore.splice(val, this.panelCount - val);
}
this.setValueAfterPanelsCreating();
this.setValueBasedOnPanelCount();
Expand Down Expand Up @@ -1409,7 +1408,7 @@ export class QuestionPanelDynamicModel extends Question
}
}
public getQuestionFromArray(name: string, index: number): IQuestion {
if (index >= this.panelCount) return null;
if (index < 0 || index >= this.panelsCore.length) return null;
return this.panelsCore[index].getQuestionByName(name);
}
private clearIncorrectValuesInPanel(index: number) {
Expand Down
4 changes: 3 additions & 1 deletion src/question_text.ts
Original file line number Diff line number Diff line change
Expand Up @@ -400,8 +400,10 @@ export class QuestionTextModel extends QuestionTextBase {
return !this.isReadOnly && this.inputType !== "range";
}
protected getControlCssClassBuilder(): CssClassBuilder {
const maxLength = this.getMaxLength();
return super.getControlCssClassBuilder()
.append(this.cssClasses.constrolWithCharacterCounter, !!this.getMaxLength());
.append(this.cssClasses.constrolWithCharacterCounter, !!maxLength)
.append(this.cssClasses.characterCounterBig, maxLength > 99);
}
public isReadOnlyRenderDiv(): boolean {
return this.isReadOnly && settings.readOnly.textRenderMode === "div";
Expand Down
4 changes: 4 additions & 0 deletions src/trigger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,10 @@ export class Trigger extends Base {
}
return res;
}
public isGhost: boolean;
protected get isInternal(): boolean {
return this.isGhost === true;
}
public get operator(): string {
return this.getPropertyValue("operator", "equal");
}
Expand Down
Loading

0 comments on commit 1477411

Please sign in to comment.