...
 
Commits (5)
......@@ -31,8 +31,8 @@ The API documentation, which is generated using [typedoc](https://typedoc.org/)
```js
import cfEditorState from 'this-package';
const state = cfEditorState();
state.addConditional({ type: 'disable', id: 'c1' });
state.updateConditonal({ type: 'enable', id: 'c1' });
state.addConditional({ type: 'disable', ID: 'c1' });
state.updateConditonal({ type: 'enable', ID: 'c1' });
state.removeConditonal('c1');
```
......@@ -44,7 +44,7 @@ const state = cfEditorState();
//Add one field
state.addField({
id: 'fld3',
ID: 'fld3',
tag: '3',
slug: 'three',
label: 'Three',
......@@ -55,7 +55,7 @@ console.log(state.getAllFields());
//Change the field
state.updateField({
id: 'fld3',
ID: 'fld3',
tag: 'three',
slug: 'three',
label: 'Option Three',
......
{
"name": "@calderajs/cf-editor-state",
"version": "0.2.0",
"version": "0.2.1",
"private": false,
"license": "MIT",
"main": "dist/index.js",
......
......@@ -108,6 +108,19 @@ describe('fieldsState', () => {
expect(state.getField(field.ID)?.label).toBe('Smells');
});
it('Adds options to a field', () => {
const state = fieldState();
state.addField(field);
state.updateField({
...field,
label: 'Smells',
type: 'checkbox',
options: [{ value: '1', calcValue: 1, label: 'One' }],
});
//@ts-ignore
expect(state.getField(field.ID)?.options[0].label).toBe('One');
});
it('Emits add field event', () => {
const callback = jest.fn();
const state = fieldState();
......
......@@ -5,6 +5,20 @@ import { EventEmitter } from 'tsee';
*/
export type fieldId = string;
/**
* One option of a field
*/
export type fieldOption = {
label: string;
value?: string | number;
calcValue?: number;
};
/**
* A collection of field options
*/
export type fieldOptions = Array<fieldOption>;
/**
* The data for a field
*
......@@ -16,6 +30,7 @@ export type field = {
slug: string;
label: string;
type: string;
options?: fieldOptions;
};
/**
......