Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@formsort/custom-question-api

Package Overview
Dependencies
Maintainers
2
Versions
30
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@formsort/custom-question-api - npm Package Compare versions

Comparing version 0.0.10 to 0.0.11

2

lib/index.d.ts

@@ -0,1 +1,2 @@

import { AnswerSemanticType } from '@formsort/constants';
declare type AnswerPrimitiveType = number | string | boolean;

@@ -5,2 +6,3 @@ declare type AnswerType = AnswerPrimitiveType | AnswerPrimitiveType[];

export declare const getAnswerValue: () => Promise<AnswerType>;
export declare const getSemanticAnswerValue: (semanticType: AnswerSemanticType) => Promise<AnswerType>;
export declare const getAllAnswerValues: () => Promise<{

@@ -7,0 +9,0 @@ [key: string]: AnswerType;

@@ -14,2 +14,5 @@ "use strict";

};
exports.getSemanticAnswerValue = function (semanticType) {
return utils_1.getValueFromWindowParent(constants_1.CustomQuestionMessage.REQUEST_SEMANTIC_ANSWER_VALUE_MSG, constants_1.CustomQuestionMessage.SET_SEMANTIC_ANSWER_VALUE_MSG, semanticType);
};
exports.getAllAnswerValues = function () {

@@ -16,0 +19,0 @@ return utils_1.getValueFromWindowParent(constants_1.CustomQuestionMessage.REQUEST_ANSWERS_MSG, constants_1.CustomQuestionMessage.SET_ANSWERS_MSG);

2

lib/utils.d.ts
import WindowMessageEventsEmitter from './WindowMessageEmitter';
export declare const getEmitter: () => WindowMessageEventsEmitter;
export declare const sendMessageToWindowParent: (type: string, payload?: any) => void;
export declare const getValueFromWindowParent: <T>(requestEventType: string, responseEventType: string) => Promise<T>;
export declare const getValueFromWindowParent: <T>(requestEventType: string, responseEventType: string, requestPayload?: any) => Promise<T>;

@@ -20,3 +20,3 @@ "use strict";

};
exports.getValueFromWindowParent = function (requestEventType, responseEventType) {
exports.getValueFromWindowParent = function (requestEventType, responseEventType, requestPayload) {
return new Promise(function (resolve) {

@@ -26,4 +26,4 @@ exports.getEmitter().once(responseEventType, function (res) {

});
exports.sendMessageToWindowParent(requestEventType);
exports.sendMessageToWindowParent(requestEventType, requestPayload);
});
};
{
"name": "@formsort/custom-question-api",
"version": "0.0.10",
"version": "0.0.11",
"description": "Helpers for implementing custom questions in Formsort",

@@ -37,12 +37,12 @@ "main": "lib/index.js",

"@types/events": "^3.0.0",
"prettier": "^1.18.2",
"tslint": "^5.18.0",
"prettier": "^2.0.1",
"tslint": "^6.1.0",
"tslint-config-prettier": "^1.18.0",
"tslint-plugin-prettier": "^2.0.1",
"typescript": "^3.5.3"
"tslint-plugin-prettier": "^2.2.0",
"typescript": "^3.8.3"
},
"dependencies": {
"@formsort/constants": "0.0.12",
"events": "^3.0.0"
"@formsort/constants": "^0.0.14",
"events": "^3.1.0"
}
}

@@ -28,8 +28,9 @@ # @formsort/custom-question-api

getAnswerValue,
setAnswerValue,
clearAnswerValue,
getSemanticAnswerValue,
getAllAnswerValues,
getResponderUuid,
setAnswerValue,
clearAnswerValue,
setQuestionSize,
} from '@formsort/custom-question-api'
setQuestionSize
} from "@formsort/custom-question-api";
```

@@ -45,2 +46,10 @@

### `setAnswerValue(value: number | string | boolean) => void`
Sets the value for this question's answer. If you have `Can autoadvance` checked within the Formsort studio settings for this question and this is the last remaining question within the step, the flow will advance to the next step.
### `clearAnswerValue() => void`
Resets the answer for this particular question's answer.
### `getAllAnswerValues() => Promise<{ [key: string]: any}>`

@@ -50,2 +59,6 @@

### `getSemanticAnswerValue(semanticType: AnswerSemanticType) => Promise<any>`
Returns a promise for the value of a specific _semantic_ answer value, such as `responder_email`. This is useful to make your custom questions more modular. Depending on an answer variable name being `email` or `userEmail` is not reliable, but using semantic meaning, answers can be looked up by what they represent, even if a particular flow or variant references them differently.
### `getResponderUuid() => Promise<string>`

@@ -55,10 +68,2 @@

### `setAnswerValue(value: number | string | boolean) => void`
Sets the value for this question's answer. If you have `Can autoadvance` checked within the Formsort studio settings for this question and this is the last remaining question within the step, the flow will advance to the next step.
### `clearAnswerValue() => void`
Resets the answer for this particular question's answer.
### `setQuestionSize(width?: number, height?: number) => void`

@@ -73,7 +78,30 @@

```tsx
import * as React from 'react';
import {
setQuestionSize
} from '@formsort/custom-question-api';
import React, { useEffect, useRef } from "react";
import { setQuestionSize } from "@formsort/custom-question-api";
const MyCustomComponent = () => {
const containerElRef = useRef<HTMLDivElement>();
useEffect(() => {
const containerEl = this.containerElRef.current;
if (!containerEl) {
return;
}
setQuestionSize(containerEl.offsetWidth, containerEl.offsetHeight);
}, []);
return (
<div ref={containerElRef}>
<h1>My custom component</h1>
</div>
);
};
```
Alternatively, written as a class component:
```tsx
import * as React from "react";
import { setQuestionSize } from "@formsort/custom-question-api";
class MyCustomComponent extends React.Component {

@@ -96,5 +124,5 @@ private containerElRef: React.RefObject<HTMLDivElement>;

</div>
)
);
}
}
```
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc